Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1483708 > unrolled thread

[RFC 0/3] Add support for led triggers on phy link state change

Started byZach Brown <zach.brown@ni.com>
First post2016-09-15 00:00 +0200
Last post2016-09-15 01:20 +0200
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [RFC 0/3] Add support for led triggers on phy link state change Zach Brown <zach.brown@ni.com> - 2016-09-15 00:00 +0200
    [RFC 1/3] skge: Change LED_OFF to LED_REG_OFF in marvel skge driver to avoid conflicts with leds namespace Zach Brown <zach.brown@ni.com> - 2016-09-15 00:00 +0200
    [RFC 2/3] staging: rtl8712: Change _LED_STATE enum in rtl871x driver to avoid conflicts with LED namespace Zach Brown <zach.brown@ni.com> - 2016-09-15 00:00 +0200
      Re: [RFC 2/3] staging: rtl8712: Change _LED_STATE enum in rtl871x  driver to avoid conflicts with LED namespace Larry Finger <Larry.Finger@lwfinger.net> - 2016-09-15 02:20 +0200
    [RFC 3/3] phy,leds: add support for led triggers on phy link state change Zach Brown <zach.brown@ni.com> - 2016-09-15 00:00 +0200
      Re: [RFC 3/3] phy,leds: add support for led triggers on phy link  state change Florian Fainelli <f.fainelli@gmail.com> - 2016-09-15 01:20 +0200

#1483708 — [RFC 0/3] Add support for led triggers on phy link state change

FromZach Brown <zach.brown@ni.com>
Date2016-09-15 00:00 +0200
Subject[RFC 0/3] Add support for led triggers on phy link state change
Message-ID<shqnL-6nQ-3@gated-at.bofh.it>
Some drivers that include phy.h defined LED_OFF which conflicts with
definition in leds.h. phy led support uses leds.h so the two namespaces are no
longer isolated.
The first two patches fix the two net drivers that declared enum constants that
conflict with enum constants in linux/leds.h.

The final patch adds support for led triggers on phy link state changes by
adding a config option. When set the config option will create a set of led
triggers for each phy device. Users can use the led triggers to represent link
state changes on the phy.
The changes assumes that there are 5 speed options
10Mb,100Mb,1Gb,2.5Gb,10Gb
The assumption makes mapping a phy_device's current speed to a trigger easy,
but means there are triggers made that aren't used if the phy doesn't support
the corresponding speeds.
Thoughts on how to better manage the triggers created would be appreciated
if is important to do so.

Josh Cartwright (1):
  phy,leds: add support for led triggers on phy link state change

Zach Brown (2):
  skge: Change LED_OFF to LED_REG_OFF in marvel skge driver to avoid
    conflicts with leds namespace
  staging: rtl8712: Change _LED_STATE enum in rtl871x driver to avoid
    conflicts with LED namespace

 drivers/net/ethernet/marvell/skge.c   |   4 +-
 drivers/net/ethernet/marvell/skge.h   |   2 +-
 drivers/net/phy/Kconfig               |  12 +++
 drivers/net/phy/Makefile              |   1 +
 drivers/net/phy/phy.c                 |   8 ++
 drivers/net/phy/phy_device.c          |   4 +
 drivers/net/phy/phy_led_triggers.c    | 109 +++++++++++++++++++
 drivers/staging/rtl8712/rtl8712_led.c | 192 +++++++++++++++++-----------------
 include/linux/phy.h                   |   9 ++
 include/linux/phy_led_triggers.h      |  42 ++++++++
 10 files changed, 284 insertions(+), 99 deletions(-)
 create mode 100644 drivers/net/phy/phy_led_triggers.c
 create mode 100644 include/linux/phy_led_triggers.h

--
2.7.4

[toc] | [next] | [standalone]


#1483709 — [RFC 1/3] skge: Change LED_OFF to LED_REG_OFF in marvel skge driver to avoid conflicts with leds namespace

FromZach Brown <zach.brown@ni.com>
Date2016-09-15 00:00 +0200
Subject[RFC 1/3] skge: Change LED_OFF to LED_REG_OFF in marvel skge driver to avoid conflicts with leds namespace
Message-ID<shqnM-6nQ-21@gated-at.bofh.it>
In reply to#1483708
Adding led support for phy causes namespace conflicts for some
phy drivers.

The marvel skge driver declared an enum for representing the states of
Link LED Register. The enum contained constant LED_OFF which conflicted
with declartation found in linux/leds.h.
LED_OFF changed to LED_REG_OFF

Signed-off-by: Zach Brown <zach.brown@ni.com>
---
 drivers/net/ethernet/marvell/skge.c | 4 ++--
 drivers/net/ethernet/marvell/skge.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/skge.c b/drivers/net/ethernet/marvell/skge.c
index 7173836..ff5a087 100644
--- a/drivers/net/ethernet/marvell/skge.c
+++ b/drivers/net/ethernet/marvell/skge.c
@@ -1062,7 +1062,7 @@ static void skge_link_up(struct skge_port *skge)
 
 static void skge_link_down(struct skge_port *skge)
 {
-	skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
+	skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_REG_OFF);
 	netif_carrier_off(skge->netdev);
 	netif_stop_queue(skge->netdev);
 
@@ -2668,7 +2668,7 @@ static int skge_down(struct net_device *dev)
 	if (hw->ports == 1)
 		free_irq(hw->pdev->irq, hw);
 
-	skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_OFF);
+	skge_write8(skge->hw, SK_REG(skge->port, LNK_LED_REG), LED_REG_OFF);
 	if (is_genesis(hw))
 		genesis_stop(skge);
 	else
diff --git a/drivers/net/ethernet/marvell/skge.h b/drivers/net/ethernet/marvell/skge.h
index a2eb341..ec054d3 100644
--- a/drivers/net/ethernet/marvell/skge.h
+++ b/drivers/net/ethernet/marvell/skge.h
@@ -663,7 +663,7 @@ enum {
 	LED_SYNC_ON	= 1<<3,	/* Use Sync Wire to switch LED */
 	LED_SYNC_OFF	= 1<<2,	/* Disable Sync Wire Input */
 	LED_ON	= 1<<1,	/* switch LED on */
-	LED_OFF	= 1<<0,	/* switch LED off */
+	LED_REG_OFF	= 1<<0,	/* switch LED off */
 };
 
 /* Receive GMAC FIFO (YUKON) */
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1483710 — [RFC 2/3] staging: rtl8712: Change _LED_STATE enum in rtl871x driver to avoid conflicts with LED namespace

FromZach Brown <zach.brown@ni.com>
Date2016-09-15 00:00 +0200
Subject[RFC 2/3] staging: rtl8712: Change _LED_STATE enum in rtl871x driver to avoid conflicts with LED namespace
Message-ID<shqnM-6nQ-7@gated-at.bofh.it>
In reply to#1483708
Adding led support for phy causes namespace conflicts for some
phy drivers.

The rtl871 driver declared an enum for representing LED states. The enum
contains constant LED_OFF which conflicted with declartation found in
linux/leds.h. LED_OFF changed to LED_STATE_OFF

Signed-off-by: Zach Brown <zach.brown@ni.com>
---
 drivers/staging/rtl8712/rtl8712_led.c | 192 +++++++++++++++++-----------------
 1 file changed, 96 insertions(+), 96 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl8712_led.c b/drivers/staging/rtl8712/rtl8712_led.c
index 9055827..d53ad76 100644
--- a/drivers/staging/rtl8712/rtl8712_led.c
+++ b/drivers/staging/rtl8712/rtl8712_led.c
@@ -52,7 +52,7 @@
 enum _LED_STATE_871x {
 	LED_UNKNOWN = 0,
 	LED_ON = 1,
-	LED_OFF = 2,
+	LED_STATE_OFF = 2,
 	LED_BLINK_NORMAL = 3,
 	LED_BLINK_SLOWLY = 4,
 	LED_POWER_ON_BLINK = 5,
@@ -92,7 +92,7 @@ static void InitLed871x(struct _adapter *padapter, struct LED_871x *pLed,
 	nic = padapter->pnetdev;
 	pLed->padapter = padapter;
 	pLed->LedPin = LedPin;
-	pLed->CurrLedState = LED_OFF;
+	pLed->CurrLedState = LED_STATE_OFF;
 	pLed->bLedOn = false;
 	pLed->bLedBlinkInProgress = false;
 	pLed->BlinkTimes = 0;
@@ -249,7 +249,7 @@ static void SwLedBlink(struct LED_871x *pLed)
 	} else {
 		/* Assign LED state to toggle. */
 		if (pLed->BlinkingLedState == LED_ON)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 
@@ -312,7 +312,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 	switch (pLed->CurrLedState) {
 	case LED_BLINK_SLOWLY:
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -320,7 +320,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_NORMAL:
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -335,7 +335,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 				pLed->bLedLinkBlinkInProgress = true;
 				pLed->CurrLedState = LED_BLINK_NORMAL;
 				if (pLed->bLedOn)
-					pLed->BlinkingLedState = LED_OFF;
+					pLed->BlinkingLedState = LED_STATE_OFF;
 				else
 					pLed->BlinkingLedState = LED_ON;
 				mod_timer(&pLed->BlinkTimer, jiffies +
@@ -344,7 +344,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 				pLed->bLedNoLinkBlinkInProgress = true;
 				pLed->CurrLedState = LED_BLINK_SLOWLY;
 				if (pLed->bLedOn)
-					pLed->BlinkingLedState = LED_OFF;
+					pLed->BlinkingLedState = LED_STATE_OFF;
 				else
 					pLed->BlinkingLedState = LED_ON;
 				mod_timer(&pLed->BlinkTimer, jiffies +
@@ -353,7 +353,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 			pLed->bLedScanBlinkInProgress = false;
 		} else {
 			 if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -369,7 +369,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 				pLed->bLedLinkBlinkInProgress = true;
 				pLed->CurrLedState = LED_BLINK_NORMAL;
 				if (pLed->bLedOn)
-					pLed->BlinkingLedState = LED_OFF;
+					pLed->BlinkingLedState = LED_STATE_OFF;
 				else
 					pLed->BlinkingLedState = LED_ON;
 				mod_timer(&pLed->BlinkTimer, jiffies +
@@ -378,7 +378,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 				pLed->bLedNoLinkBlinkInProgress = true;
 				pLed->CurrLedState = LED_BLINK_SLOWLY;
 				if (pLed->bLedOn)
-					pLed->BlinkingLedState = LED_OFF;
+					pLed->BlinkingLedState = LED_STATE_OFF;
 				else
 					pLed->BlinkingLedState = LED_ON;
 				mod_timer(&pLed->BlinkTimer, jiffies +
@@ -388,7 +388,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 			pLed->bLedBlinkInProgress = false;
 		} else {
 			 if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -397,7 +397,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS:
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -405,7 +405,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS_STOP:	/* WPS success */
 		if (pLed->BlinkingLedState == LED_ON) {
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer, jiffies +
 				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
 			bStopBlinking = false;
@@ -416,7 +416,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
 			pLed->bLedLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_NORMAL;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -451,14 +451,14 @@ static void SwLedBlink2(struct LED_871x *pLed)
 				pLed->BlinkingLedState = LED_ON;
 				SwLedOn(padapter, pLed);
 			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
-				pLed->CurrLedState = LED_OFF;
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->CurrLedState = LED_STATE_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 				SwLedOff(padapter, pLed);
 			}
 			pLed->bLedScanBlinkInProgress = false;
 		} else {
 			 if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -475,14 +475,14 @@ static void SwLedBlink2(struct LED_871x *pLed)
 				pLed->BlinkingLedState = LED_ON;
 				SwLedOn(padapter, pLed);
 			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
-				pLed->CurrLedState = LED_OFF;
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->CurrLedState = LED_STATE_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 				SwLedOff(padapter, pLed);
 			}
 			pLed->bLedBlinkInProgress = false;
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -518,15 +518,15 @@ static void SwLedBlink3(struct LED_871x *pLed)
 				if (!pLed->bLedOn)
 					SwLedOn(padapter, pLed);
 			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
-				pLed->CurrLedState = LED_OFF;
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->CurrLedState = LED_STATE_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 				if (pLed->bLedOn)
 					SwLedOff(padapter, pLed);
 			}
 			pLed->bLedScanBlinkInProgress = false;
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -544,15 +544,15 @@ static void SwLedBlink3(struct LED_871x *pLed)
 				if (!pLed->bLedOn)
 					SwLedOn(padapter, pLed);
 			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
-				pLed->CurrLedState = LED_OFF;
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->CurrLedState = LED_STATE_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 				if (pLed->bLedOn)
 					SwLedOff(padapter, pLed);
 			}
 			pLed->bLedBlinkInProgress = false;
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -561,7 +561,7 @@ static void SwLedBlink3(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS:
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -569,7 +569,7 @@ static void SwLedBlink3(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS_STOP:	/*WPS success*/
 		if (pLed->BlinkingLedState == LED_ON) {
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer, jiffies +
 				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
 			bStopBlinking = false;
@@ -602,14 +602,14 @@ static void SwLedBlink4(struct LED_871x *pLed)
 		SwLedOff(padapter, pLed);
 	if (!pLed1->bLedWPSBlinkInProgress &&
 	    pLed1->BlinkingLedState == LED_UNKNOWN) {
-		pLed1->BlinkingLedState = LED_OFF;
-		pLed1->CurrLedState = LED_OFF;
+		pLed1->BlinkingLedState = LED_STATE_OFF;
+		pLed1->CurrLedState = LED_STATE_OFF;
 		SwLedOff(padapter, pLed1);
 	}
 	switch (pLed->CurrLedState) {
 	case LED_BLINK_SLOWLY:
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -617,7 +617,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_StartToBlink:
 		if (pLed->bLedOn) {
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer, jiffies +
 				  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
 		} else {
@@ -634,7 +634,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 			pLed->bLedNoLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_SLOWLY;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -642,7 +642,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 			pLed->bLedScanBlinkInProgress = false;
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -657,7 +657,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 			pLed->bLedNoLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_SLOWLY;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -665,7 +665,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 			pLed->bLedBlinkInProgress = false;
 		} else {
 			 if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -674,7 +674,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS:
 		if (pLed->bLedOn) {
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer, jiffies +
 				  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
 		} else {
@@ -685,7 +685,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS_STOP:	/*WPS authentication fail*/
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -706,7 +706,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
 				  msecs_to_jiffies(LED_BLINK_LINK_INTERVAL_ALPHA));
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -742,7 +742,7 @@ static void SwLedBlink5(struct LED_871x *pLed)
 			pLed->bLedScanBlinkInProgress = false;
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -762,7 +762,7 @@ static void SwLedBlink5(struct LED_871x *pLed)
 			pLed->bLedBlinkInProgress = false;
 		} else {
 			 if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -797,7 +797,7 @@ static void SwLedBlink6(struct LED_871x *pLed)
 			pLed->bLedBlinkInProgress = false;
 		} else {
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -806,7 +806,7 @@ static void SwLedBlink6(struct LED_871x *pLed)
 		break;
 	case LED_BLINK_WPS:
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -908,7 +908,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
 			pLed->bLedNoLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_SLOWLY;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -931,7 +931,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
 			pLed->bLedLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_NORMAL;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -961,7 +961,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
 			pLed->CurrLedState = LED_SCAN_BLINK;
 			pLed->BlinkTimes = 24;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -986,7 +986,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
 			pLed->CurrLedState = LED_TXRX_BLINK;
 			pLed->BlinkTimes = 2;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1016,7 +1016,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
 			pLed->bLedWPSBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_WPS;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1046,7 +1046,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
 			pLed->bLedWPSBlinkInProgress = true;
 		pLed->CurrLedState = LED_BLINK_WPS_STOP;
 		if (pLed->bLedOn) {
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer, jiffies +
 				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
 		} else {
@@ -1063,15 +1063,15 @@ static void SwLedControlMode1(struct _adapter *padapter,
 		pLed->bLedNoLinkBlinkInProgress = true;
 		pLed->CurrLedState = LED_BLINK_SLOWLY;
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
 			  msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
 		break;
 	case LED_CTL_POWER_OFF:
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		if (pLed->bLedNoLinkBlinkInProgress) {
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedNoLinkBlinkInProgress = false;
@@ -1123,7 +1123,7 @@ static void SwLedControlMode2(struct _adapter *padapter,
 			pLed->CurrLedState = LED_SCAN_BLINK;
 			pLed->BlinkTimes = 24;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1142,7 +1142,7 @@ static void SwLedControlMode2(struct _adapter *padapter,
 			pLed->CurrLedState = LED_TXRX_BLINK;
 			pLed->BlinkTimes = 2;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1195,8 +1195,8 @@ static void SwLedControlMode2(struct _adapter *padapter,
 
 	case LED_CTL_STOP_WPS_FAIL:
 		pLed->bLedWPSBlinkInProgress = false;
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		mod_timer(&pLed->BlinkTimer,
 			  jiffies + msecs_to_jiffies(0));
 		break;
@@ -1204,15 +1204,15 @@ static void SwLedControlMode2(struct _adapter *padapter,
 	case LED_CTL_START_TO_LINK:
 	case LED_CTL_NO_LINK:
 		if (!IS_LED_BLINKING(pLed)) {
-			pLed->CurrLedState = LED_OFF;
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->CurrLedState = LED_STATE_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer,
 				  jiffies + msecs_to_jiffies(0));
 		}
 		break;
 	case LED_CTL_POWER_OFF:
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		if (pLed->bLedBlinkInProgress) {
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedBlinkInProgress = false;
@@ -1255,7 +1255,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
 			pLed->CurrLedState = LED_SCAN_BLINK;
 			pLed->BlinkTimes = 24;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1273,7 +1273,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
 			pLed->CurrLedState = LED_TXRX_BLINK;
 			pLed->BlinkTimes = 2;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1310,7 +1310,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
 			pLed->bLedWPSBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_WPS;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1326,7 +1326,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
 		}
 		pLed->CurrLedState = LED_BLINK_WPS_STOP;
 		if (pLed->bLedOn) {
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer, jiffies +
 				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
 		} else {
@@ -1340,23 +1340,23 @@ static void SwLedControlMode3(struct _adapter *padapter,
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedWPSBlinkInProgress = false;
 		}
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		mod_timer(&pLed->BlinkTimer,
 			  jiffies + msecs_to_jiffies(0));
 		break;
 	case LED_CTL_START_TO_LINK:
 	case LED_CTL_NO_LINK:
 		if (!IS_LED_BLINKING(pLed)) {
-			pLed->CurrLedState = LED_OFF;
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->CurrLedState = LED_STATE_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 			mod_timer(&pLed->BlinkTimer,
 				  jiffies + msecs_to_jiffies(0));
 		}
 		break;
 	case LED_CTL_POWER_OFF:
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		if (pLed->bLedBlinkInProgress) {
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedBlinkInProgress = false;
@@ -1390,8 +1390,8 @@ static void SwLedControlMode4(struct _adapter *padapter,
 		if (pLed1->bLedWPSBlinkInProgress) {
 			pLed1->bLedWPSBlinkInProgress = false;
 			del_timer(&pLed1->BlinkTimer);
-			pLed1->BlinkingLedState = LED_OFF;
-			pLed1->CurrLedState = LED_OFF;
+			pLed1->BlinkingLedState = LED_STATE_OFF;
+			pLed1->CurrLedState = LED_STATE_OFF;
 			if (pLed1->bLedOn)
 				mod_timer(&pLed->BlinkTimer,
 					  jiffies + msecs_to_jiffies(0));
@@ -1411,7 +1411,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			pLed->bLedStartToLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_StartToBlink;
 			if (pLed->bLedOn) {
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 				mod_timer(&pLed->BlinkTimer, jiffies +
 					  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
 			} else {
@@ -1428,8 +1428,8 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			if (pLed1->bLedWPSBlinkInProgress) {
 				pLed1->bLedWPSBlinkInProgress = false;
 				del_timer(&pLed1->BlinkTimer);
-				pLed1->BlinkingLedState = LED_OFF;
-				pLed1->CurrLedState = LED_OFF;
+				pLed1->BlinkingLedState = LED_STATE_OFF;
+				pLed1->CurrLedState = LED_STATE_OFF;
 				if (pLed1->bLedOn)
 					mod_timer(&pLed->BlinkTimer,
 						  jiffies + msecs_to_jiffies(0));
@@ -1446,7 +1446,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			pLed->bLedNoLinkBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_SLOWLY;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1472,7 +1472,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			pLed->CurrLedState = LED_SCAN_BLINK;
 			pLed->BlinkTimes = 24;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1493,7 +1493,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			pLed->CurrLedState = LED_TXRX_BLINK;
 			pLed->BlinkTimes = 2;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1505,8 +1505,8 @@ static void SwLedControlMode4(struct _adapter *padapter,
 		if (pLed1->bLedWPSBlinkInProgress) {
 			pLed1->bLedWPSBlinkInProgress = false;
 			del_timer(&pLed1->BlinkTimer);
-			pLed1->BlinkingLedState = LED_OFF;
-			pLed1->CurrLedState = LED_OFF;
+			pLed1->BlinkingLedState = LED_STATE_OFF;
+			pLed1->CurrLedState = LED_STATE_OFF;
 			if (pLed1->bLedOn)
 				mod_timer(&pLed->BlinkTimer,
 					  jiffies + msecs_to_jiffies(0));
@@ -1527,7 +1527,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			pLed->bLedWPSBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_WPS;
 			if (pLed->bLedOn) {
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 				mod_timer(&pLed->BlinkTimer, jiffies +
 					  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
 			} else {
@@ -1545,7 +1545,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 		pLed->bLedNoLinkBlinkInProgress = true;
 		pLed->CurrLedState = LED_BLINK_SLOWLY;
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1559,7 +1559,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 		pLed->bLedNoLinkBlinkInProgress = true;
 		pLed->CurrLedState = LED_BLINK_SLOWLY;
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1571,7 +1571,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 			pLed1->bLedWPSBlinkInProgress = true;
 		pLed1->CurrLedState = LED_BLINK_WPS_STOP;
 		if (pLed1->bLedOn)
-			pLed1->BlinkingLedState = LED_OFF;
+			pLed1->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed1->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1585,7 +1585,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
 		pLed->bLedNoLinkBlinkInProgress = true;
 		pLed->CurrLedState = LED_BLINK_SLOWLY;
 		if (pLed->bLedOn)
-			pLed->BlinkingLedState = LED_OFF;
+			pLed->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1598,15 +1598,15 @@ static void SwLedControlMode4(struct _adapter *padapter,
 		pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
 		pLed1->BlinkTimes = 10;
 		if (pLed1->bLedOn)
-			pLed1->BlinkingLedState = LED_OFF;
+			pLed1->BlinkingLedState = LED_STATE_OFF;
 		else
 			pLed1->BlinkingLedState = LED_ON;
 		mod_timer(&pLed->BlinkTimer, jiffies +
 			  msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
 		break;
 	case LED_CTL_POWER_OFF:
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		if (pLed->bLedNoLinkBlinkInProgress) {
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedNoLinkBlinkInProgress = false;
@@ -1679,7 +1679,7 @@ static void SwLedControlMode5(struct _adapter *padapter,
 			pLed->CurrLedState = LED_SCAN_BLINK;
 			pLed->BlinkTimes = 24;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1695,7 +1695,7 @@ static void SwLedControlMode5(struct _adapter *padapter,
 			pLed->CurrLedState = LED_TXRX_BLINK;
 			pLed->BlinkTimes = 2;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1703,8 +1703,8 @@ static void SwLedControlMode5(struct _adapter *padapter,
 		}
 		break;
 	case LED_CTL_POWER_OFF:
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		if (pLed->bLedBlinkInProgress) {
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedBlinkInProgress = false;
@@ -1746,7 +1746,7 @@ static void SwLedControlMode6(struct _adapter *padapter,
 			pLed->CurrLedState = LED_TXRX_BLINK;
 			pLed->BlinkTimes = 2;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1763,7 +1763,7 @@ static void SwLedControlMode6(struct _adapter *padapter,
 			pLed->bLedWPSBlinkInProgress = true;
 			pLed->CurrLedState = LED_BLINK_WPS;
 			if (pLed->bLedOn)
-				pLed->BlinkingLedState = LED_OFF;
+				pLed->BlinkingLedState = LED_STATE_OFF;
 			else
 				pLed->BlinkingLedState = LED_ON;
 			mod_timer(&pLed->BlinkTimer, jiffies +
@@ -1782,8 +1782,8 @@ static void SwLedControlMode6(struct _adapter *padapter,
 			  jiffies + msecs_to_jiffies(0));
 		break;
 	case LED_CTL_POWER_OFF:
-		pLed->CurrLedState = LED_OFF;
-		pLed->BlinkingLedState = LED_OFF;
+		pLed->CurrLedState = LED_STATE_OFF;
+		pLed->BlinkingLedState = LED_STATE_OFF;
 		if (pLed->bLedBlinkInProgress) {
 			del_timer(&pLed->BlinkTimer);
 			pLed->bLedBlinkInProgress = false;
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1483784 — Re: [RFC 2/3] staging: rtl8712: Change _LED_STATE enum in rtl871x driver to avoid conflicts with LED namespace

FromLarry Finger <Larry.Finger@lwfinger.net>
Date2016-09-15 02:20 +0200
SubjectRe: [RFC 2/3] staging: rtl8712: Change _LED_STATE enum in rtl871x driver to avoid conflicts with LED namespace
Message-ID<shszf-83M-7@gated-at.bofh.it>
In reply to#1483710
On 09/14/2016 04:55 PM, Zach Brown wrote:
> Adding led support for phy causes namespace conflicts for some
> phy drivers.
>
> The rtl871 driver declared an enum for representing LED states. The enum
> contains constant LED_OFF which conflicted with declartation found in
> linux/leds.h. LED_OFF changed to LED_STATE_OFF
>
> Signed-off-by: Zach Brown <zach.brown@ni.com>

I have no objection to this change. My only substantive comment is that LED_ON 
should also be changed to LED_STATE_ON, otherwise there might be another 
namespace collision later. There is also a typo in the commit message. In 
addition, staging driver patches should be sent to Greg KH.

Larry

> ---
>  drivers/staging/rtl8712/rtl8712_led.c | 192 +++++++++++++++++-----------------
>  1 file changed, 96 insertions(+), 96 deletions(-)
>
> diff --git a/drivers/staging/rtl8712/rtl8712_led.c b/drivers/staging/rtl8712/rtl8712_led.c
> index 9055827..d53ad76 100644
> --- a/drivers/staging/rtl8712/rtl8712_led.c
> +++ b/drivers/staging/rtl8712/rtl8712_led.c
> @@ -52,7 +52,7 @@
>  enum _LED_STATE_871x {
>  	LED_UNKNOWN = 0,
>  	LED_ON = 1,
> -	LED_OFF = 2,
> +	LED_STATE_OFF = 2,
>  	LED_BLINK_NORMAL = 3,
>  	LED_BLINK_SLOWLY = 4,
>  	LED_POWER_ON_BLINK = 5,
> @@ -92,7 +92,7 @@ static void InitLed871x(struct _adapter *padapter, struct LED_871x *pLed,
>  	nic = padapter->pnetdev;
>  	pLed->padapter = padapter;
>  	pLed->LedPin = LedPin;
> -	pLed->CurrLedState = LED_OFF;
> +	pLed->CurrLedState = LED_STATE_OFF;
>  	pLed->bLedOn = false;
>  	pLed->bLedBlinkInProgress = false;
>  	pLed->BlinkTimes = 0;
> @@ -249,7 +249,7 @@ static void SwLedBlink(struct LED_871x *pLed)
>  	} else {
>  		/* Assign LED state to toggle. */
>  		if (pLed->BlinkingLedState == LED_ON)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>
> @@ -312,7 +312,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  	switch (pLed->CurrLedState) {
>  	case LED_BLINK_SLOWLY:
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -320,7 +320,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_NORMAL:
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -335,7 +335,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  				pLed->bLedLinkBlinkInProgress = true;
>  				pLed->CurrLedState = LED_BLINK_NORMAL;
>  				if (pLed->bLedOn)
> -					pLed->BlinkingLedState = LED_OFF;
> +					pLed->BlinkingLedState = LED_STATE_OFF;
>  				else
>  					pLed->BlinkingLedState = LED_ON;
>  				mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -344,7 +344,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  				pLed->bLedNoLinkBlinkInProgress = true;
>  				pLed->CurrLedState = LED_BLINK_SLOWLY;
>  				if (pLed->bLedOn)
> -					pLed->BlinkingLedState = LED_OFF;
> +					pLed->BlinkingLedState = LED_STATE_OFF;
>  				else
>  					pLed->BlinkingLedState = LED_ON;
>  				mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -353,7 +353,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  			pLed->bLedScanBlinkInProgress = false;
>  		} else {
>  			 if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -369,7 +369,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  				pLed->bLedLinkBlinkInProgress = true;
>  				pLed->CurrLedState = LED_BLINK_NORMAL;
>  				if (pLed->bLedOn)
> -					pLed->BlinkingLedState = LED_OFF;
> +					pLed->BlinkingLedState = LED_STATE_OFF;
>  				else
>  					pLed->BlinkingLedState = LED_ON;
>  				mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -378,7 +378,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  				pLed->bLedNoLinkBlinkInProgress = true;
>  				pLed->CurrLedState = LED_BLINK_SLOWLY;
>  				if (pLed->bLedOn)
> -					pLed->BlinkingLedState = LED_OFF;
> +					pLed->BlinkingLedState = LED_STATE_OFF;
>  				else
>  					pLed->BlinkingLedState = LED_ON;
>  				mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -388,7 +388,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  			pLed->bLedBlinkInProgress = false;
>  		} else {
>  			 if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -397,7 +397,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS:
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -405,7 +405,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS_STOP:	/* WPS success */
>  		if (pLed->BlinkingLedState == LED_ON) {
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
>  				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
>  			bStopBlinking = false;
> @@ -416,7 +416,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
>  			pLed->bLedLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_NORMAL;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -451,14 +451,14 @@ static void SwLedBlink2(struct LED_871x *pLed)
>  				pLed->BlinkingLedState = LED_ON;
>  				SwLedOn(padapter, pLed);
>  			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
> -				pLed->CurrLedState = LED_OFF;
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->CurrLedState = LED_STATE_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  				SwLedOff(padapter, pLed);
>  			}
>  			pLed->bLedScanBlinkInProgress = false;
>  		} else {
>  			 if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -475,14 +475,14 @@ static void SwLedBlink2(struct LED_871x *pLed)
>  				pLed->BlinkingLedState = LED_ON;
>  				SwLedOn(padapter, pLed);
>  			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
> -				pLed->CurrLedState = LED_OFF;
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->CurrLedState = LED_STATE_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  				SwLedOff(padapter, pLed);
>  			}
>  			pLed->bLedBlinkInProgress = false;
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -518,15 +518,15 @@ static void SwLedBlink3(struct LED_871x *pLed)
>  				if (!pLed->bLedOn)
>  					SwLedOn(padapter, pLed);
>  			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
> -				pLed->CurrLedState = LED_OFF;
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->CurrLedState = LED_STATE_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  				if (pLed->bLedOn)
>  					SwLedOff(padapter, pLed);
>  			}
>  			pLed->bLedScanBlinkInProgress = false;
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -544,15 +544,15 @@ static void SwLedBlink3(struct LED_871x *pLed)
>  				if (!pLed->bLedOn)
>  					SwLedOn(padapter, pLed);
>  			} else if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
> -				pLed->CurrLedState = LED_OFF;
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->CurrLedState = LED_STATE_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  				if (pLed->bLedOn)
>  					SwLedOff(padapter, pLed);
>  			}
>  			pLed->bLedBlinkInProgress = false;
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -561,7 +561,7 @@ static void SwLedBlink3(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS:
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -569,7 +569,7 @@ static void SwLedBlink3(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS_STOP:	/*WPS success*/
>  		if (pLed->BlinkingLedState == LED_ON) {
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
>  				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
>  			bStopBlinking = false;
> @@ -602,14 +602,14 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  		SwLedOff(padapter, pLed);
>  	if (!pLed1->bLedWPSBlinkInProgress &&
>  	    pLed1->BlinkingLedState == LED_UNKNOWN) {
> -		pLed1->BlinkingLedState = LED_OFF;
> -		pLed1->CurrLedState = LED_OFF;
> +		pLed1->BlinkingLedState = LED_STATE_OFF;
> +		pLed1->CurrLedState = LED_STATE_OFF;
>  		SwLedOff(padapter, pLed1);
>  	}
>  	switch (pLed->CurrLedState) {
>  	case LED_BLINK_SLOWLY:
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -617,7 +617,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_StartToBlink:
>  		if (pLed->bLedOn) {
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
>  				  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
>  		} else {
> @@ -634,7 +634,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  			pLed->bLedNoLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_SLOWLY;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -642,7 +642,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  			pLed->bLedScanBlinkInProgress = false;
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -657,7 +657,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  			pLed->bLedNoLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_SLOWLY;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -665,7 +665,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  			pLed->bLedBlinkInProgress = false;
>  		} else {
>  			 if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -674,7 +674,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS:
>  		if (pLed->bLedOn) {
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
>  				  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
>  		} else {
> @@ -685,7 +685,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS_STOP:	/*WPS authentication fail*/
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -706,7 +706,7 @@ static void SwLedBlink4(struct LED_871x *pLed)
>  				  msecs_to_jiffies(LED_BLINK_LINK_INTERVAL_ALPHA));
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -742,7 +742,7 @@ static void SwLedBlink5(struct LED_871x *pLed)
>  			pLed->bLedScanBlinkInProgress = false;
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -762,7 +762,7 @@ static void SwLedBlink5(struct LED_871x *pLed)
>  			pLed->bLedBlinkInProgress = false;
>  		} else {
>  			 if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -797,7 +797,7 @@ static void SwLedBlink6(struct LED_871x *pLed)
>  			pLed->bLedBlinkInProgress = false;
>  		} else {
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -806,7 +806,7 @@ static void SwLedBlink6(struct LED_871x *pLed)
>  		break;
>  	case LED_BLINK_WPS:
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -908,7 +908,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  			pLed->bLedNoLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_SLOWLY;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -931,7 +931,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  			pLed->bLedLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_NORMAL;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -961,7 +961,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_SCAN_BLINK;
>  			pLed->BlinkTimes = 24;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -986,7 +986,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_TXRX_BLINK;
>  			pLed->BlinkTimes = 2;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1016,7 +1016,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  			pLed->bLedWPSBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_WPS;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1046,7 +1046,7 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  			pLed->bLedWPSBlinkInProgress = true;
>  		pLed->CurrLedState = LED_BLINK_WPS_STOP;
>  		if (pLed->bLedOn) {
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
>  				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
>  		} else {
> @@ -1063,15 +1063,15 @@ static void SwLedControlMode1(struct _adapter *padapter,
>  		pLed->bLedNoLinkBlinkInProgress = true;
>  		pLed->CurrLedState = LED_BLINK_SLOWLY;
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
>  			  msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
>  		break;
>  	case LED_CTL_POWER_OFF:
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		if (pLed->bLedNoLinkBlinkInProgress) {
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedNoLinkBlinkInProgress = false;
> @@ -1123,7 +1123,7 @@ static void SwLedControlMode2(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_SCAN_BLINK;
>  			pLed->BlinkTimes = 24;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1142,7 +1142,7 @@ static void SwLedControlMode2(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_TXRX_BLINK;
>  			pLed->BlinkTimes = 2;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1195,8 +1195,8 @@ static void SwLedControlMode2(struct _adapter *padapter,
>
>  	case LED_CTL_STOP_WPS_FAIL:
>  		pLed->bLedWPSBlinkInProgress = false;
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		mod_timer(&pLed->BlinkTimer,
>  			  jiffies + msecs_to_jiffies(0));
>  		break;
> @@ -1204,15 +1204,15 @@ static void SwLedControlMode2(struct _adapter *padapter,
>  	case LED_CTL_START_TO_LINK:
>  	case LED_CTL_NO_LINK:
>  		if (!IS_LED_BLINKING(pLed)) {
> -			pLed->CurrLedState = LED_OFF;
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->CurrLedState = LED_STATE_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer,
>  				  jiffies + msecs_to_jiffies(0));
>  		}
>  		break;
>  	case LED_CTL_POWER_OFF:
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		if (pLed->bLedBlinkInProgress) {
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedBlinkInProgress = false;
> @@ -1255,7 +1255,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_SCAN_BLINK;
>  			pLed->BlinkTimes = 24;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1273,7 +1273,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_TXRX_BLINK;
>  			pLed->BlinkTimes = 2;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1310,7 +1310,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
>  			pLed->bLedWPSBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_WPS;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1326,7 +1326,7 @@ static void SwLedControlMode3(struct _adapter *padapter,
>  		}
>  		pLed->CurrLedState = LED_BLINK_WPS_STOP;
>  		if (pLed->bLedOn) {
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
>  				  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
>  		} else {
> @@ -1340,23 +1340,23 @@ static void SwLedControlMode3(struct _adapter *padapter,
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedWPSBlinkInProgress = false;
>  		}
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		mod_timer(&pLed->BlinkTimer,
>  			  jiffies + msecs_to_jiffies(0));
>  		break;
>  	case LED_CTL_START_TO_LINK:
>  	case LED_CTL_NO_LINK:
>  		if (!IS_LED_BLINKING(pLed)) {
> -			pLed->CurrLedState = LED_OFF;
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->CurrLedState = LED_STATE_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  			mod_timer(&pLed->BlinkTimer,
>  				  jiffies + msecs_to_jiffies(0));
>  		}
>  		break;
>  	case LED_CTL_POWER_OFF:
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		if (pLed->bLedBlinkInProgress) {
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedBlinkInProgress = false;
> @@ -1390,8 +1390,8 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  		if (pLed1->bLedWPSBlinkInProgress) {
>  			pLed1->bLedWPSBlinkInProgress = false;
>  			del_timer(&pLed1->BlinkTimer);
> -			pLed1->BlinkingLedState = LED_OFF;
> -			pLed1->CurrLedState = LED_OFF;
> +			pLed1->BlinkingLedState = LED_STATE_OFF;
> +			pLed1->CurrLedState = LED_STATE_OFF;
>  			if (pLed1->bLedOn)
>  				mod_timer(&pLed->BlinkTimer,
>  					  jiffies + msecs_to_jiffies(0));
> @@ -1411,7 +1411,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			pLed->bLedStartToLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_StartToBlink;
>  			if (pLed->bLedOn) {
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  				mod_timer(&pLed->BlinkTimer, jiffies +
>  					  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
>  			} else {
> @@ -1428,8 +1428,8 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			if (pLed1->bLedWPSBlinkInProgress) {
>  				pLed1->bLedWPSBlinkInProgress = false;
>  				del_timer(&pLed1->BlinkTimer);
> -				pLed1->BlinkingLedState = LED_OFF;
> -				pLed1->CurrLedState = LED_OFF;
> +				pLed1->BlinkingLedState = LED_STATE_OFF;
> +				pLed1->CurrLedState = LED_STATE_OFF;
>  				if (pLed1->bLedOn)
>  					mod_timer(&pLed->BlinkTimer,
>  						  jiffies + msecs_to_jiffies(0));
> @@ -1446,7 +1446,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			pLed->bLedNoLinkBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_SLOWLY;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1472,7 +1472,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_SCAN_BLINK;
>  			pLed->BlinkTimes = 24;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1493,7 +1493,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_TXRX_BLINK;
>  			pLed->BlinkTimes = 2;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1505,8 +1505,8 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  		if (pLed1->bLedWPSBlinkInProgress) {
>  			pLed1->bLedWPSBlinkInProgress = false;
>  			del_timer(&pLed1->BlinkTimer);
> -			pLed1->BlinkingLedState = LED_OFF;
> -			pLed1->CurrLedState = LED_OFF;
> +			pLed1->BlinkingLedState = LED_STATE_OFF;
> +			pLed1->CurrLedState = LED_STATE_OFF;
>  			if (pLed1->bLedOn)
>  				mod_timer(&pLed->BlinkTimer,
>  					  jiffies + msecs_to_jiffies(0));
> @@ -1527,7 +1527,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			pLed->bLedWPSBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_WPS;
>  			if (pLed->bLedOn) {
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  				mod_timer(&pLed->BlinkTimer, jiffies +
>  					  msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
>  			} else {
> @@ -1545,7 +1545,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  		pLed->bLedNoLinkBlinkInProgress = true;
>  		pLed->CurrLedState = LED_BLINK_SLOWLY;
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1559,7 +1559,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  		pLed->bLedNoLinkBlinkInProgress = true;
>  		pLed->CurrLedState = LED_BLINK_SLOWLY;
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1571,7 +1571,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  			pLed1->bLedWPSBlinkInProgress = true;
>  		pLed1->CurrLedState = LED_BLINK_WPS_STOP;
>  		if (pLed1->bLedOn)
> -			pLed1->BlinkingLedState = LED_OFF;
> +			pLed1->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed1->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1585,7 +1585,7 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  		pLed->bLedNoLinkBlinkInProgress = true;
>  		pLed->CurrLedState = LED_BLINK_SLOWLY;
>  		if (pLed->bLedOn)
> -			pLed->BlinkingLedState = LED_OFF;
> +			pLed->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1598,15 +1598,15 @@ static void SwLedControlMode4(struct _adapter *padapter,
>  		pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
>  		pLed1->BlinkTimes = 10;
>  		if (pLed1->bLedOn)
> -			pLed1->BlinkingLedState = LED_OFF;
> +			pLed1->BlinkingLedState = LED_STATE_OFF;
>  		else
>  			pLed1->BlinkingLedState = LED_ON;
>  		mod_timer(&pLed->BlinkTimer, jiffies +
>  			  msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
>  		break;
>  	case LED_CTL_POWER_OFF:
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		if (pLed->bLedNoLinkBlinkInProgress) {
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedNoLinkBlinkInProgress = false;
> @@ -1679,7 +1679,7 @@ static void SwLedControlMode5(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_SCAN_BLINK;
>  			pLed->BlinkTimes = 24;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1695,7 +1695,7 @@ static void SwLedControlMode5(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_TXRX_BLINK;
>  			pLed->BlinkTimes = 2;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1703,8 +1703,8 @@ static void SwLedControlMode5(struct _adapter *padapter,
>  		}
>  		break;
>  	case LED_CTL_POWER_OFF:
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		if (pLed->bLedBlinkInProgress) {
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedBlinkInProgress = false;
> @@ -1746,7 +1746,7 @@ static void SwLedControlMode6(struct _adapter *padapter,
>  			pLed->CurrLedState = LED_TXRX_BLINK;
>  			pLed->BlinkTimes = 2;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1763,7 +1763,7 @@ static void SwLedControlMode6(struct _adapter *padapter,
>  			pLed->bLedWPSBlinkInProgress = true;
>  			pLed->CurrLedState = LED_BLINK_WPS;
>  			if (pLed->bLedOn)
> -				pLed->BlinkingLedState = LED_OFF;
> +				pLed->BlinkingLedState = LED_STATE_OFF;
>  			else
>  				pLed->BlinkingLedState = LED_ON;
>  			mod_timer(&pLed->BlinkTimer, jiffies +
> @@ -1782,8 +1782,8 @@ static void SwLedControlMode6(struct _adapter *padapter,
>  			  jiffies + msecs_to_jiffies(0));
>  		break;
>  	case LED_CTL_POWER_OFF:
> -		pLed->CurrLedState = LED_OFF;
> -		pLed->BlinkingLedState = LED_OFF;
> +		pLed->CurrLedState = LED_STATE_OFF;
> +		pLed->BlinkingLedState = LED_STATE_OFF;
>  		if (pLed->bLedBlinkInProgress) {
>  			del_timer(&pLed->BlinkTimer);
>  			pLed->bLedBlinkInProgress = false;
>

[toc] | [prev] | [next] | [standalone]


#1483714 — [RFC 3/3] phy,leds: add support for led triggers on phy link state change

FromZach Brown <zach.brown@ni.com>
Date2016-09-15 00:00 +0200
Subject[RFC 3/3] phy,leds: add support for led triggers on phy link state change
Message-ID<shqnM-6nQ-11@gated-at.bofh.it>
In reply to#1483708
From: Josh Cartwright <josh.cartwright@ni.com>

Create an option CONFIG_LED_TRIGGER_PHY (default n), which will
create a set of led triggers for each instantiated PHY device.  There is
one LED trigger per link-speed, per-phy.

This allows for a user to configure their system to allow a set of LEDs
to represent link state changes on the phy.

Signed-off-by: Josh Cartwright <josh.cartwright@ni.com>
Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
Signed-off-by: Zach Brown <zach.brown@ni.com>
---
 drivers/net/phy/Kconfig            |  12 ++++
 drivers/net/phy/Makefile           |   1 +
 drivers/net/phy/phy.c              |   8 +++
 drivers/net/phy/phy_device.c       |   4 ++
 drivers/net/phy/phy_led_triggers.c | 109 +++++++++++++++++++++++++++++++++++++
 include/linux/phy.h                |   9 +++
 include/linux/phy_led_triggers.h   |  42 ++++++++++++++
 7 files changed, 185 insertions(+)
 create mode 100644 drivers/net/phy/phy_led_triggers.c
 create mode 100644 include/linux/phy_led_triggers.h

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 1c3e07c..4aeaba4 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -15,6 +15,18 @@ if PHYLIB
 config SWPHY
 	bool
 
+config LED_TRIGGER_PHY
+	bool "Support LED triggers for tracking link state"
+	depends on LEDS_TRIGGERS
+	---help---
+	  Adds support for a set of LED trigger events per-PHY.  Link
+	  state change will trigger the events, for consumption by an
+	  LED class driver.  There are triggers for each link speed,
+	  and are of the form:
+	       <mii bus id>:<phy>:<speed>
+
+	  Where speed is one of: 10Mb, 100Mb, Gb, 2.5Gb, or 10GbE.
+
 comment "MDIO bus device drivers"
 
 config MDIO_BCM_IPROC
diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index e58667d..86d12cd 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -2,6 +2,7 @@
 
 libphy-y			:= phy.o phy_device.o mdio_bus.o mdio_device.o
 libphy-$(CONFIG_SWPHY)		+= swphy.o
+libphy-$(CONFIG_LED_TRIGGER_PHY)	+= phy_led_triggers.o
 
 obj-$(CONFIG_PHYLIB)		+= libphy.o
 
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index c6f6683..3345767 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -936,6 +936,7 @@ void phy_state_machine(struct work_struct *work)
 			phydev->state = PHY_NOLINK;
 			netif_carrier_off(phydev->attached_dev);
 			phydev->adjust_link(phydev->attached_dev);
+			phy_led_trigger_change_speed(phydev);
 			break;
 		}
 
@@ -949,6 +950,7 @@ void phy_state_machine(struct work_struct *work)
 			phydev->state = PHY_RUNNING;
 			netif_carrier_on(phydev->attached_dev);
 			phydev->adjust_link(phydev->attached_dev);
+			phy_led_trigger_change_speed(phydev);
 
 		} else if (0 == phydev->link_timeout--)
 			needs_aneg = true;
@@ -976,6 +978,7 @@ void phy_state_machine(struct work_struct *work)
 			phydev->state = PHY_RUNNING;
 			netif_carrier_on(phydev->attached_dev);
 			phydev->adjust_link(phydev->attached_dev);
+			phy_led_trigger_change_speed(phydev);
 		}
 		break;
 	case PHY_FORCING:
@@ -992,6 +995,7 @@ void phy_state_machine(struct work_struct *work)
 		}
 
 		phydev->adjust_link(phydev->attached_dev);
+		phy_led_trigger_change_speed(phydev);
 		break;
 	case PHY_RUNNING:
 		/* Only register a CHANGE if we are polling and link changed
@@ -1021,6 +1025,7 @@ void phy_state_machine(struct work_struct *work)
 		}
 
 		phydev->adjust_link(phydev->attached_dev);
+		phy_led_trigger_change_speed(phydev);
 
 		if (phy_interrupt_is_valid(phydev))
 			err = phy_config_interrupt(phydev,
@@ -1031,6 +1036,7 @@ void phy_state_machine(struct work_struct *work)
 			phydev->link = 0;
 			netif_carrier_off(phydev->attached_dev);
 			phydev->adjust_link(phydev->attached_dev);
+			phy_led_trigger_change_speed(phydev);
 			do_suspend = true;
 		}
 		break;
@@ -1055,6 +1061,7 @@ void phy_state_machine(struct work_struct *work)
 					phydev->state = PHY_NOLINK;
 				}
 				phydev->adjust_link(phydev->attached_dev);
+				phy_led_trigger_change_speed(phydev);
 			} else {
 				phydev->state = PHY_AN;
 				phydev->link_timeout = PHY_AN_TIMEOUT;
@@ -1071,6 +1078,7 @@ void phy_state_machine(struct work_struct *work)
 				phydev->state = PHY_NOLINK;
 			}
 			phydev->adjust_link(phydev->attached_dev);
+			phy_led_trigger_change_speed(phydev);
 		}
 		break;
 	}
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index e977ba9..4671c13 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -30,6 +30,7 @@
 #include <linux/mii.h>
 #include <linux/ethtool.h>
 #include <linux/phy.h>
+#include <linux/phy_led_triggers.h>
 #include <linux/mdio.h>
 #include <linux/io.h>
 #include <linux/uaccess.h>
@@ -57,6 +58,7 @@ static void phy_mdio_device_free(struct mdio_device *mdiodev)
 
 static void phy_device_release(struct device *dev)
 {
+	phy_led_triggers_unregister(to_phy_device(dev));
 	kfree(to_phy_device(dev));
 }
 
@@ -345,6 +347,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 
 	dev->state = PHY_DOWN;
 
+	phy_led_triggers_register(dev);
+
 	mutex_init(&dev->lock);
 	INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
 	INIT_WORK(&dev->phy_queue, phy_change);
diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c
new file mode 100644
index 0000000..6c40414
--- /dev/null
+++ b/drivers/net/phy/phy_led_triggers.c
@@ -0,0 +1,109 @@
+/* Copyright (C) 2016 National Instruments Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <linux/leds.h>
+#include <linux/phy.h>
+
+void phy_led_trigger_change_speed(struct phy_device *phy)
+{
+	struct phy_led_trigger *plt;
+
+	if (!phy->link) {
+		if (phy->last_triggered) {
+			led_trigger_event(&phy->last_triggered->trigger,
+					  LED_OFF);
+			phy->last_triggered = NULL;
+		}
+		return;
+	}
+
+	switch (phy->speed) {
+	case SPEED_10:
+		plt = &phy->phy_led_trigger[0];
+		break;
+	case SPEED_100:
+		plt = &phy->phy_led_trigger[1];
+		break;
+	case SPEED_1000:
+		plt = &phy->phy_led_trigger[2];
+		break;
+	case SPEED_2500:
+		plt = &phy->phy_led_trigger[3];
+		break;
+	case SPEED_10000:
+		plt = &phy->phy_led_trigger[4];
+		break;
+	default:
+		plt = NULL;
+		break;
+	}
+
+	if (plt != phy->last_triggered) {
+		led_trigger_event(&phy->last_triggered->trigger, LED_OFF);
+		led_trigger_event(&plt->trigger, LED_FULL);
+		phy->last_triggered = plt;
+	}
+}
+EXPORT_SYMBOL_GPL(phy_led_trigger_change_speed);
+
+static int phy_led_trigger_register(struct phy_device *phy,
+				    struct phy_led_trigger *plt, int i)
+{
+	static const char * const name_suffix[] = {
+		"10Mb",
+		"100Mb",
+		"Gb",
+		"2.5Gb",
+		"10GbE",
+	};
+	snprintf(plt->name, sizeof(plt->name), PHY_ID_FMT ":%s",
+		 phy->mdio.bus->id, phy->mdio.addr, name_suffix[i]);
+	plt->trigger.name = plt->name;
+	return led_trigger_register(&plt->trigger);
+}
+
+static void phy_led_trigger_unregister(struct phy_led_trigger *plt)
+{
+	led_trigger_unregister(&plt->trigger);
+}
+
+int phy_led_triggers_register(struct phy_device *phy)
+{
+	int i, err;
+
+	for (i = 0; i < ARRAY_SIZE(phy->phy_led_trigger); i++) {
+		err = phy_led_trigger_register(phy, &phy->phy_led_trigger[i],
+					       i);
+		if (err)
+			goto out_unreg;
+	}
+
+	phy->last_triggered = NULL;
+	phy_led_trigger_change_speed(phy);
+
+	return 0;
+
+out_unreg:
+	while (i--)
+		phy_led_trigger_unregister(&phy->phy_led_trigger[i]);
+	return err;
+}
+EXPORT_SYMBOL_GPL(phy_led_triggers_register);
+
+void phy_led_triggers_unregister(struct phy_device *phy)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(phy->phy_led_trigger); i++)
+		phy_led_trigger_unregister(&phy->phy_led_trigger[i]);
+}
+EXPORT_SYMBOL_GPL(phy_led_triggers_unregister);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 2d24b28..315dd06 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -25,6 +25,7 @@
 #include <linux/timer.h>
 #include <linux/workqueue.h>
 #include <linux/mod_devicetable.h>
+#include <linux/phy_led_triggers.h>
 
 #include <linux/atomic.h>
 
@@ -402,6 +403,14 @@ struct phy_device {
 
 	int link_timeout;
 
+#ifdef CONFIG_LED_TRIGGER_PHY
+	/*
+	 * A led_trigger per SPEED_*
+	 */
+	struct phy_led_trigger phy_led_trigger[5];
+	struct phy_led_trigger *last_triggered;
+#endif
+
 	/*
 	 * Interrupt number for this PHY
 	 * -1 means no interrupt
diff --git a/include/linux/phy_led_triggers.h b/include/linux/phy_led_triggers.h
new file mode 100644
index 0000000..1fb6506
--- /dev/null
+++ b/include/linux/phy_led_triggers.h
@@ -0,0 +1,42 @@
+/* Copyright (C) 2016 National Instruments Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#ifndef __PHY_LED_TRIGGERS
+#define __PHY_LED_TRIGGERS
+
+struct phy_device;
+
+#ifdef CONFIG_LED_TRIGGER_PHY
+
+#include <linux/leds.h>
+
+struct phy_led_trigger {
+	struct led_trigger trigger;
+	char name[64];
+};
+
+extern int phy_led_triggers_register(struct phy_device *phy);
+extern void phy_led_triggers_unregister(struct phy_device *phy);
+extern void phy_led_trigger_change_speed(struct phy_device *phy);
+
+#else
+
+static inline int phy_led_triggers_register(struct phy_device *phy)
+{
+	return 0;
+}
+static inline void phy_led_triggers_unregister(struct phy_device *phy) { }
+static inline void phy_led_trigger_change_speed(struct phy_device *phy) { }
+
+#endif
+
+#endif
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1483765 — Re: [RFC 3/3] phy,leds: add support for led triggers on phy link state change

FromFlorian Fainelli <f.fainelli@gmail.com>
Date2016-09-15 01:20 +0200
SubjectRe: [RFC 3/3] phy,leds: add support for led triggers on phy link state change
Message-ID<shrDb-7oF-5@gated-at.bofh.it>
In reply to#1483714
On 09/14/2016 02:55 PM, Zach Brown wrote:
> From: Josh Cartwright <josh.cartwright@ni.com>
> 
> Create an option CONFIG_LED_TRIGGER_PHY (default n), which will
> create a set of led triggers for each instantiated PHY device.  There is
> one LED trigger per link-speed, per-phy.
> 
> This allows for a user to configure their system to allow a set of LEDs
> to represent link state changes on the phy.

The part that seems to be missing from this changeset (not an issue) is
how you can "accelerate" the triggers, or rather make sure that the
trigger configuration potentially calls back into the PHY driver when
the requested trigger is actually supported by the on-PHY LEDs.

Other than that, just minor nits here and there.

> 
> Signed-off-by: Josh Cartwright <josh.cartwright@ni.com>
> Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
> Signed-off-by: Zach Brown <zach.brown@ni.com>
> ---

> +config LED_TRIGGER_PHY
> +	bool "Support LED triggers for tracking link state"
> +	depends on LEDS_TRIGGERS
> +	---help---
> +	  Adds support for a set of LED trigger events per-PHY.  Link
> +	  state change will trigger the events, for consumption by an
> +	  LED class driver.  There are triggers for each link speed,
> +	  and are of the form:
> +	       <mii bus id>:<phy>:<speed>
> +
> +	  Where speed is one of: 10Mb, 100Mb, Gb, 2.5Gb, or 10GbE.

I would do s/10GbE/10Gb/ just to be consistent with the other speeds, or
maybe, to avoid too much duplicationg of how we represent speeds, use
the same set of strings that drivers/net/phy/phy.c::phy_speed_to_str uses.


> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index c6f6683..3345767 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -936,6 +936,7 @@ void phy_state_machine(struct work_struct *work)
>  			phydev->state = PHY_NOLINK;
>  			netif_carrier_off(phydev->attached_dev);
>  			phydev->adjust_link(phydev->attached_dev);
> +			phy_led_trigger_change_speed(phydev);

Since we have essentially two actions to take when performing link state
changes:

- call the adjust_link callback
- call into the LED trigger

we might consider encapsulating this into a function that could be named
phy_adjust_link() and does both of these. That would be a preliminary
patch to this this one.

>  
> @@ -345,6 +347,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
>  
>  	dev->state = PHY_DOWN;
>  
> +	phy_led_triggers_register(dev);
> +
>  	mutex_init(&dev->lock);
>  	INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
>  	INIT_WORK(&dev->phy_queue, phy_change);

Humm, should it be before the PHY state machine workqueue creation or
after? Just wondering if there is a remote chance we could get an user
to immediately program a trigger and this could create a problem, maybe
not so much.

> diff --git a/drivers/net/phy/phy_led_triggers.c b/drivers/net/phy/phy_led_triggers.c
> new file mode 100644
> index 0000000..6c40414
> --- /dev/null
> +++ b/drivers/net/phy/phy_led_triggers.c
> @@ -0,0 +1,109 @@
> +/* Copyright (C) 2016 National Instruments Corp.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <linux/leds.h>
> +#include <linux/phy.h>
> +
> +void phy_led_trigger_change_speed(struct phy_device *phy)
> +{
> +	struct phy_led_trigger *plt;
> +
> +	if (!phy->link) {
> +		if (phy->last_triggered) {
> +			led_trigger_event(&phy->last_triggered->trigger,
> +					  LED_OFF);
> +			phy->last_triggered = NULL;
> +		}
> +		return;
> +	}
> +
> +	switch (phy->speed) {
> +	case SPEED_10:
> +		plt = &phy->phy_led_trigger[0];
> +		break;
> +	case SPEED_100:
> +		plt = &phy->phy_led_trigger[1];
> +		break;
> +	case SPEED_1000:
> +		plt = &phy->phy_led_trigger[2];
> +		break;
> +	case SPEED_2500:
> +		plt = &phy->phy_led_trigger[3];
> +		break;
> +	case SPEED_10000:
> +		plt = &phy->phy_led_trigger[4];
> +		break;

We could use a table here indexed by the speed, or have a function that
does phy_speed_to_led_trigger(unsigned int speed) for instance, which
would be more robust to adding other speeds in the future.

> +	default:
> +		plt = NULL;
> +		break;
> +	}
> +
> +	if (plt != phy->last_triggered) {
> +		led_trigger_event(&phy->last_triggered->trigger, LED_OFF);
> +		led_trigger_event(&plt->trigger, LED_FULL);
> +		phy->last_triggered = plt;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(phy_led_trigger_change_speed);
> +
> +static int phy_led_trigger_register(struct phy_device *phy,
> +				    struct phy_led_trigger *plt, int i)
> +{
> +	static const char * const name_suffix[] = {
> +		"10Mb",
> +		"100Mb",
> +		"Gb",
> +		"2.5Gb",
> +		"10GbE",

Same comment as initially, the 10GbE is slightly inconsistent here wrt
the other speed encodings.


>  
> @@ -402,6 +403,14 @@ struct phy_device {
>  
>  	int link_timeout;
>  
> +#ifdef CONFIG_LED_TRIGGER_PHY
> +	/*
> +	 * A led_trigger per SPEED_*
> +	 */
> +	struct phy_led_trigger phy_led_trigger[5];

Same comment, we would probably want to have a define/enum value for the
maximum number of speeds supported.


> +#include <linux/leds.h>
> +
> +struct phy_led_trigger {
> +	struct led_trigger trigger;
> +	char name[64];

Can we size this buffer based on MII_BUS_ID_SIZE, the amount of
characters needed to represent a PHY device, and the maximum trigger
name size?

> +#else
> +
> +static inline int phy_led_triggers_register(struct phy_device *phy)
> +{
> +	return 0;
> +}
> +static inline void phy_led_triggers_unregister(struct phy_device *phy) { }
> +static inline void phy_led_trigger_change_speed(struct phy_device *phy) { }

Kudos for adding stubs!
-- 
Florian

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web