Skip to contentSkip to conversation

b43: stop hardcoding LED behavior

RFC PATCH In review Lucas Stach 3 participants 4 messages Apr 25, 2016 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 b43: stop hardcoding LED behavior

The code to hardcode the LED behavior is basically unchanged from when it was first merged in 2007. It is likely wrong for many modern systems using the b43 driver.

On my system the SPROM correctly defines the only wired LED (radio) but skips all others, leading to the hardcode to register LEDs with RX and TX triggers. These triggers cause many uneccesary CPU wakeups to drive LEDs that aren't even present in the system, reducing battery runtime.

Remove the hardcode to stop it from doing any harm. If this code is useful for others it should probably be reworked as a quirk table triggering only for individual systems that need it.

---
 drivers/net/wireless/broadcom/b43/leds.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
drivers/net/wireless/broadcom/b43/leds.c +2 -24
index d79ab2a..77d2dad 100644
@@ -224,31 +224,9 @@ static void b43_led_get_sprominfo(struct b43_wldev *dev,
 
 	if (sprom[led_index] == 0xFF) {
 		/* There is no LED information in the SPROM
-		 * for this LED. Hardcode it here. */
+		 * for this LED. Keep it disabled. */
 		*activelow = false;
-		switch (led_index) {
-		case 0:
-			*behaviour = B43_LED_ACTIVITY;
-			*activelow = true;
-			if (dev->dev->board_vendor == PCI_VENDOR_ID_COMPAQ)
-				*behaviour = B43_LED_RADIO_ALL;
-			break;
-		case 1:
-			*behaviour = B43_LED_RADIO_B;
-			if (dev->dev->board_vendor == PCI_VENDOR_ID_ASUSTEK)
-				*behaviour = B43_LED_ASSOC;
-			break;
-		case 2:
-			*behaviour = B43_LED_RADIO_A;
-			break;
-		case 3:
-			*behaviour = B43_LED_OFF;
-			break;
-		default:
-			*behaviour = B43_LED_OFF;
-			B43_WARN_ON(1);
-			return;
-		}
+		*behaviour = B43_LED_OFF;
 	} else {
 		*behaviour = sprom[led_index] & B43_LED_BEHAVIOUR;
 		*activelow = !!(sprom[led_index] & B43_LED_ACTIVELOW);
Signature · 1 line
2.5.5

A message that is not in the archive (sent off-list or not yet received): 1461570051-3950-1-git-send-email-dev-8ppwABl0HbeELgA04lAiVw@public.gmane.org

#2 lore raw
Quoted 3 lines · On Mon, 25 Apr 2016 09:40:51 +0200 Lucas Stach <[email protected]> wrote:

On my system the SPROM correctly defines the only wired LED (radio) but skips all others, leading to the hardcode to register LEDs with RX and TX triggers.

Hm ok. It probably is a good idea to change the condition from

if (sprom[led_index] == 0xFF)

to

if ((sprom[0] & sprom[1] & sprom[2] & sprom[3]) == 0xFF)

So the hardcoding only happens if there is no LED configured in the SPROM. (I think my card does this (see below), but I can check that later)

Quoted 2 lines

These triggers cause many uneccesary CPU wakeups to drive LEDs that aren't even present in the system, reducing battery runtime.

Numbers please. Did you measure that is actually causes more _wakeups_? How many?
The led work is placed in the mac80211 workqueue and LED updates only happen on behalf of mac80211 activities (by default). It only causes additional wakeups, if there's nothing else scheduled on the workqueue anyways (which might well be the case. So we need numbers. :)

Quoted 3 lines

Remove the hardcode to stop it from doing any harm. If this code is useful for others it should probably be reworked as a quirk table triggering only for individual systems that need it.

There are cards that need it. I don't know how many that are, but I own an older 4306 PC-Card card that needs this.

So this effectively is a regression for this card.

So I don't think this is acceptable.
You should at least make this configurable via module parameter or such. Or maybe the change from above already is enough. It should work for your case.

Quoted 43 lines
---
 drivers/net/wireless/broadcom/b43/leds.c | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
drivers/net/wireless/broadcom/b43/leds.c +2 -24
index d79ab2a..77d2dad 100644
@@ -224,31 +224,9 @@ static void b43_led_get_sprominfo(struct b43_wldev *dev,
 
 	if (sprom[led_index] == 0xFF) {
 		/* There is no LED information in the SPROM
-		 * for this LED. Hardcode it here. */
+		 * for this LED. Keep it disabled. */
 		*activelow = false;
-		switch (led_index) {
-		case 0:
-			*behaviour = B43_LED_ACTIVITY;
-			*activelow = true;
-			if (dev->dev->board_vendor == PCI_VENDOR_ID_COMPAQ)
-				*behaviour = B43_LED_RADIO_ALL;
-			break;
-		case 1:
-			*behaviour = B43_LED_RADIO_B;
-			if (dev->dev->board_vendor == PCI_VENDOR_ID_ASUSTEK)
-				*behaviour = B43_LED_ASSOC;
-			break;
-		case 2:
-			*behaviour = B43_LED_RADIO_A;
-			break;
-		case 3:
-			*behaviour = B43_LED_OFF;
-			break;
-		default:
-			*behaviour = B43_LED_OFF;
-			B43_WARN_ON(1);
-			return;
-		}
+		*behaviour = B43_LED_OFF;
 	} else {
 		*behaviour = sprom[led_index] & B43_LED_BEHAVIOUR;
 		*activelow = !!(sprom[led_index] & B43_LED_ACTIVELOW);
Signature · 8 lines
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/b43-dev/attachments/20160425/4b48a6ba/attachment.sig>
#3 lore raw

Am Montag, den 25.04.2016, 17:53 +0200 schrieb Michael B?sch:

Quoted 26 lines
Quoted 6 lines · On Mon, 25 Apr 2016 09:40:51 +0200 Lucas Stach <[email protected]> wrote:

On my system the SPROM correctly defines the only wired LED (radio) but
skips all others, leading to the hardcode to register LEDs with RX and TX
triggers.

Hm ok. It probably is a good idea to change the condition from

if (sprom[led_index] == 0xFF)

to

if ((sprom[0] & sprom[1] & sprom[2] & sprom[3]) == 0xFF)

So the hardcoding only happens if there is no LED configured in the SPROM. (I think my card does this (see below), but I can check that later)

Quoted 3 lines

These triggers cause many uneccesary CPU wakeups to drive LEDs that aren't even present in the system, reducing battery runtime.

Quoted 9 lines

Numbers please. Did you measure that is actually causes more _wakeups_?
How many?
The led work is placed in the mac80211 workqueue and LED updates only happen on behalf of mac80211 activities (by default). It only causes additional wakeups, if there's nothing else scheduled on the workqueue
anyways (which might well be the case. So we need numbers. :)

The blinking LEDs use a timer to enforce a constant blink rate at a 50ms on/off interval. While they are only triggered if there is some RX/TX activity in the system, they cause up to 20 wakeups/second/led. As the timers used for LED activity aren't deferrable, this hardcode is causing 40 unnecessary CPU wakeups/s in my system.

Quoted 12 lines
Quoted 7 lines

Remove the hardcode to stop it from doing any harm. If this code is useful
for others it should probably be reworked as a quirk table triggering only
for individual systems that need it.

There are cards that need it. I don't know how many that are, but I own
an older 4306 PC-Card card that needs this.

Quoted 8 lines

So this effectively is a regression for this card.

So I don't think this is acceptable.
You should at least make this configurable via module parameter or such.
Or maybe the change from above already is enough. It should work for your case.

There are some people that find those kinds of blinking LEDs distracting, so a module parameter to disable them altogether might be a good thing to have. Causing CPU wakeups in a system where those LEDs aren't even physically populated is clearly undesired behavior.

If checking that the SPROM doesn't define any LED behavior is enough to not regress your use case, I would be glad to rework the patch accordingly.

Regards,
Lucas

Quoted 54 lines
Quoted 51 lines

---
?drivers/net/wireless/broadcom/b43/leds.c | 26 ++----------------
--------
?1 file changed, 2 insertions(+), 24 deletions(-)

drivers/net/wireless/broadcom/b43/leds.c +0 -0
index d79ab2a..77d2dad 100644
@@ -224,31 +224,9 @@ static void b43_led_get_sprominfo(struct
 b43_wldev *dev,

?
? if (sprom[led_index] == 0xFF) {
? /* There is no LED information in the SPROM

drivers/net/wireless/broadcom/b43/leds.c +1 -1
-		?* for this LED. Hardcode it here. */
+		?* for this LED. Keep it disabled. */

? *activelow = false;

drivers/net/wireless/broadcom/b43/leds.c +0 -5
-		switch (led_index) {
-		case 0:
-			*behaviour = B43_LED_ACTIVITY;
-			*activelow = true;
-			if (dev->dev->board_vendor ==

PCI_VENDOR_ID_COMPAQ)

drivers/net/wireless/broadcom/b43/leds.c +0 -5
-				*behaviour = B43_LED_RADIO_ALL;
-			break;
-		case 1:
-			*behaviour = B43_LED_RADIO_B;
-			if (dev->dev->board_vendor ==

PCI_VENDOR_ID_ASUSTEK)

drivers/net/wireless/broadcom/b43/leds.c +1 -13
-				*behaviour = B43_LED_ASSOC;
-			break;
-		case 2:
-			*behaviour = B43_LED_RADIO_A;
-			break;
-		case 3:
-			*behaviour = B43_LED_OFF;
-			break;
-		default:
-			*behaviour = B43_LED_OFF;
-			B43_WARN_ON(1);
-			return;
-		}
+		*behaviour = B43_LED_OFF;

? } else {
? *behaviour = sprom[led_index] & B43_LED_BEHAVIOUR;
? *activelow = !!(sprom[led_index] &
B43_LED_ACTIVELOW);

#4 lore raw
Quoted 9 lines · On Mon, 25 Apr 2016 20:21:36 +0200 Lucas Stach <[email protected]> wrote:
Quoted 9 lines

Numbers please. Did you measure that is actually causes more _wakeups_?
How many?
The led work is placed in the mac80211 workqueue and LED updates only happen on behalf of mac80211 activities (by default). It only causes additional wakeups, if there's nothing else scheduled on the workqueue
anyways (which might well be the case. So we need numbers. :)

Quoted 5 lines

The blinking LEDs use a timer to enforce a constant blink rate at a 50ms on/off interval. While they are only triggered if there is some RX/TX activity in the system, they cause up to 20 wakeups/second/led. As the timers used for LED activity aren't deferrable, this hardcode is causing 40 unnecessary CPU wakeups/s in my system.

Ok this is 40 to 40k for the interrupt requests?
We need real measured numbers and a percentage on how much the b43 LEDs increase the system wakeups in relation to all other wakeups.

Quoted 2 lines

There are some people that find those kinds of blinking LEDs distracting,

Those can already disable them via the standard LED framework.

Quoted 2 lines

so a module parameter to disable them altogether might be a good thing to have.

No. We have a standard API for this.

Quoted 2 lines

Causing CPU wakeups in a system where those LEDs aren't even physically populated is clearly undesired behavior.

Yes, but this is not going to be fixed via regressions.

Quoted 3 lines

If checking that the SPROM doesn't define any LED behavior is enough to not regress your use case, I would be glad to rework the patch accordingly.

As it turns out I don't have that card here and I don't have a dump of its SPROM as I expected. So I cannot really verify this. But I'm pretty sure that this card did not define any LEDs in its SPROM at all. I'm not aware of any card that only partially defines LEDs in the SPROM. So that fix would be OK.

Signature · 8 lines
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/b43-dev/attachments/20160425/041edf84/attachment.sig>