Skip to contentSkip to conversation

net: ethernet: bgmac: bug fixes

PATCH Superseded Jon Mason 4 participants 12 messages Feb 1, 2017 – Feb 2, 2017

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

cover net: ethernet: bgmac: bug fixes

Bug fixes for bgmac driver

Hari Vyas (1):
net: ethernet: bgmac: mac address change bug

Zac Schroff (1):
net: ethernet: bgmac: init sequence bug

 drivers/net/ethernet/broadcom/bgmac-platform.c | 10 +++++++---
 drivers/net/ethernet/broadcom/bgmac.c          |  6 +++++-
 include/linux/bcma/bcma_regs.h                 |  1 +
 3 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/2 net: ethernet: bgmac: init sequence bug

From: Zac Schroff <[email protected]>

Fix a bug in the 'bgmac' driver init sequence that blind writes for init sequence where it should preserve most bits other than the ones it is deliberately manipulating.

Fixes f6a95a24957 ("net: ethernet: bgmac: Add platform device support")
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 10 +++++++---
 include/linux/bcma/bcma_regs.h                 |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +7 -3
index 6f736c1..9bbe05c 100644
@@ -61,15 +61,19 @@ static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
 
 static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
 {
-	bgmac_idm_write(bgmac, BCMA_IOCTL,
-			(BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
+	u32 regval;
+
+	/* Some bits of BCMA_IOCTL set by HW/ATF & should not change */
+	regval = bgmac_idm_read(bgmac, BCMA_IOCTL) & BCMA_IOCTL_DO_NOT_MODIFY;
+	regval |= ((flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) | BCMA_IOCTL_CLK);
+	bgmac_idm_write(bgmac, BCMA_IOCTL, regval | BCMA_IOCTL_FGC);
 	bgmac_idm_read(bgmac, BCMA_IOCTL);
 
 	bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
 	bgmac_idm_read(bgmac, BCMA_RESET_CTL);
 	udelay(1);
 
-	bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
+	bgmac_idm_write(bgmac, BCMA_IOCTL, regval);
 	bgmac_idm_read(bgmac, BCMA_IOCTL);
 	udelay(1);
 }
include/linux/bcma/bcma_regs.h +1 -0
index 9986f82..41d7404 100644
@@ -31,6 +31,7 @@
 #define  BCMA_IOCTL_CORE_BITS		0x3FFC
 #define  BCMA_IOCTL_PME_EN		0x4000
 #define  BCMA_IOCTL_BIST_EN		0x8000
+#define  BCMA_IOCTL_DO_NOT_MODIFY	0x7FFFFF80
 #define BCMA_IOST			0x0500 /* IO status */
 #define  BCMA_IOST_CORE_BITS		0x0FFF
 #define  BCMA_IOST_DMA64		0x1000
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH 2/2 net: ethernet: bgmac: mac address change bug

In reply to Jon Mason

From: Hari Vyas <[email protected]>

ndo_set_mac_address() passes struct sockaddr * as 2nd parameter to bgmac_set_mac_address() but code assumed u8 *. This caused two bytes chopping and the wrong mac address was configured.

Fixes 4e209001b86 ("bgmac: write mac address to hardware in ndo_set_mac_address")
---
 drivers/net/ethernet/broadcom/bgmac.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bgmac.c +5 -1
index 0e066dc6..ea24072 100644
@@ -1222,11 +1222,15 @@ static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
 {
 	struct bgmac *bgmac = netdev_priv(net_dev);
 	int ret;
+	struct sockaddr *sa = addr;
 
 	ret = eth_prepare_mac_addr_change(net_dev, addr);
 	if (ret < 0)
 		return ret;
-	bgmac_write_mac_address(bgmac, (u8 *)addr);
+
+	ether_addr_copy(bgmac->mac_addr, sa->sa_data);
+	bgmac_write_mac_address(bgmac, bgmac->mac_addr);
+
 	eth_commit_mac_addr_change(net_dev, addr);
 	return 0;
 }
Signature · 1 line
2.7.4
maintainer
#9 lore raw

Re: [PATCH 2/2] net: ethernet: bgmac: mac address change bug

Quoted 9 lines · Jon Mason

From: Hari Vyas <[email protected]>

ndo_set_mac_address() passes struct sockaddr * as 2nd parameter to bgmac_set_mac_address() but code assumed u8 *. This caused two bytes chopping and the wrong mac address was configured.

Fixes 4e209001b86 ("bgmac: write mac address to hardware in ndo_set_mac_address")

Sounds OK, would it make sense to Cc stable?

maintainer
#2 lore raw

Re: [PATCH 1/2] net: ethernet: bgmac: init sequence bug

In reply to Jon Mason
Quoted 19 lines · Jon Mason

From: Zac Schroff <[email protected]>

Fix a bug in the 'bgmac' driver init sequence that blind writes for init sequence where it should preserve most bits other than the ones it is deliberately manipulating.

Fixes f6a95a24957 ("net: ethernet: bgmac: Add platform device support")
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 10 +++++++---
 include/linux/bcma/bcma_regs.h                 |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +0 -0
index 6f736c1..9bbe05c 100644

drivers/net/ethernet/broadcom/bgmac-platform.c static bool platform_bgmac_clk_enabled(struct bgmac *bgmac) · line 68

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +5 -2
@@ -61,15 +61,19 @@ static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
 
 static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
 {
-	bgmac_idm_write(bgmac, BCMA_IOCTL,
-			(BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
+	u32 regval;
+
+	/* Some bits of BCMA_IOCTL set by HW/ATF & should not change */
+	regval = bgmac_idm_read(bgmac, BCMA_IOCTL) & BCMA_IOCTL_DO_NOT_MODIFY;
+	regval |= ((flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) | BCMA_IOCTL_CLK);

You don't need these braces around whole calculation. This should work the same:
(flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) | BCMA_IOCTL_CLK

Quoted 17 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +2 -1
+	bgmac_idm_write(bgmac, BCMA_IOCTL, regval | BCMA_IOCTL_FGC);
 	bgmac_idm_read(bgmac, BCMA_IOCTL);
 
 	bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
 	bgmac_idm_read(bgmac, BCMA_RESET_CTL);
 	udelay(1);
 
-	bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
+	bgmac_idm_write(bgmac, BCMA_IOCTL, regval);
 	bgmac_idm_read(bgmac, BCMA_IOCTL);
 	udelay(1);
 }
include/linux/bcma/bcma_regs.h +0 -0
index 9986f82..41d7404 100644

include/linux/bcma/bcma_regs.h line 34

Quoted 4 lines
include/linux/bcma/bcma_regs.h +1 -0
@@ -31,6 +31,7 @@
 #define  BCMA_IOCTL_CORE_BITS		0x3FFC
 #define  BCMA_IOCTL_PME_EN		0x4000
 #define  BCMA_IOCTL_BIST_EN		0x8000
+#define  BCMA_IOCTL_DO_NOT_MODIFY	0x7FFFFF80

This sounds like a pretty bad name.

Take a look at brcmsmac and SICF_*:
http://lxr.free-electrons.com/source/drivers/net/wireless/broadcom/brcm80211/brcmsmac/d11.h?v=4.9#L1737

Or b43 and B43_BCMA_IOCTL_*:
http://lxr.free-electrons.com/source/drivers/net/wireless/broadcom/b43/b43.h?v=4.9#L494

Both drives modify bits you marked as DO_NOT_MODIFY and they are OK.

#3 lore raw

Re: [PATCH 1/2] net: ethernet: bgmac: init sequence bug

How about BCMA_IOCTL_PRESERVE_ACROSS_INIT?

Quoted 75 lines · Rafał Miłecki
Quoted 24 lines · Jon Mason

From: Zac Schroff <[email protected]>

Fix a bug in the 'bgmac' driver init sequence that blind writes for init sequence where it should preserve most bits other than the ones it is deliberately manipulating.

Fixes f6a95a24957 ("net: ethernet: bgmac: Add platform device support")
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 10 +++++++---
 include/linux/bcma/bcma_regs.h                 |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +0 -0
index 6f736c1..9bbe05c 100644
@@ -61,15 +61,19 @@ static bool platform_bgmac_clk_enabled(struct bgmac
 *bgmac)
 
 static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)

drivers/net/ethernet/broadcom/bgmac-platform.c static bool platform_bgmac_clk_enabled(struct bgmac · line 71

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +5 -2
 {
-       bgmac_idm_write(bgmac, BCMA_IOCTL,
-                       (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
+       u32 regval;
+
+       /* Some bits of BCMA_IOCTL set by HW/ATF & should not change */
+       regval = bgmac_idm_read(bgmac, BCMA_IOCTL) &
 BCMA_IOCTL_DO_NOT_MODIFY;
+       regval |= ((flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) |
 BCMA_IOCTL_CLK);

You don't need these braces around whole calculation. This should work the same:
(flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) | BCMA_IOCTL_CLK

Quoted 18 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +2 -1
+       bgmac_idm_write(bgmac, BCMA_IOCTL, regval | BCMA_IOCTL_FGC);
        bgmac_idm_read(bgmac, BCMA_IOCTL);
 
        bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
        bgmac_idm_read(bgmac, BCMA_RESET_CTL);
        udelay(1);
 
-       bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
+       bgmac_idm_write(bgmac, BCMA_IOCTL, regval);
        bgmac_idm_read(bgmac, BCMA_IOCTL);
        udelay(1);

}

include/linux/bcma/bcma_regs.h +0 -0
index 9986f82..41d7404 100644

include/linux/bcma/bcma_regs.h line 34

Quoted 4 lines
include/linux/bcma/bcma_regs.h +1 -0
@@ -31,6 +31,7 @@
 #define  BCMA_IOCTL_CORE_BITS          0x3FFC
 #define  BCMA_IOCTL_PME_EN             0x4000
 #define  BCMA_IOCTL_BIST_EN            0x8000
+#define  BCMA_IOCTL_DO_NOT_MODIFY      0x7FFFFF80

This sounds like a pretty bad name.

Take a look at brcmsmac and SICF_*:
http://lxr.free-electrons.com/source/drivers/net/wireless/broadcom/brcm80211/brcmsmac/d11.h?v=4.9#L1737

Or b43 and B43_BCMA_IOCTL_*:
http://lxr.free-electrons.com/source/drivers/net/wireless/broadcom/b43/b43.h?v=4.9#L494

Both drives modify bits you marked as DO_NOT_MODIFY and they are OK.

#7 lore raw

Re: [PATCH 1/2] net: ethernet: bgmac: init sequence bug

In reply to Jon Mason

Hello!

Quoted 19 lines · Jon Mason

From: Zac Schroff <[email protected]>

Fix a bug in the 'bgmac' driver init sequence that blind writes for init sequence where it should preserve most bits other than the ones it is deliberately manipulating.

Fixes f6a95a24957 ("net: ethernet: bgmac: Add platform device support")
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 10 +++++++---
 include/linux/bcma/bcma_regs.h                 |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +0 -0
index 6f736c1..9bbe05c 100644

drivers/net/ethernet/broadcom/bgmac-platform.c static bool platform_bgmac_clk_enabled(struct bgmac *bgmac) · line 68

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +5 -2
@@ -61,15 +61,19 @@ static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
 
 static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
 {
-	bgmac_idm_write(bgmac, BCMA_IOCTL,
-			(BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
+	u32 regval;
+
+	/* Some bits of BCMA_IOCTL set by HW/ATF & should not change */
+	regval = bgmac_idm_read(bgmac, BCMA_IOCTL) & BCMA_IOCTL_DO_NOT_MODIFY;
+	regval |= ((flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) | BCMA_IOCTL_CLK);

The innermost parens aren't necessary. And the outermost as well.

[...]

MBR, Sergei

#11 lore raw

Re: [PATCH 2/2] net: ethernet: bgmac: mac address change bug

In reply to Jon Mason
Quoted 18 lines · Jon Mason

From: Hari Vyas <[email protected]>

ndo_set_mac_address() passes struct sockaddr * as 2nd parameter to bgmac_set_mac_address() but code assumed u8 *. This caused two bytes chopping and the wrong mac address was configured.

Fixes 4e209001b86 ("bgmac: write mac address to hardware in ndo_set_mac_address")
---
 drivers/net/ethernet/broadcom/bgmac.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bgmac.c +0 -0
index 0e066dc6..ea24072 100644

drivers/net/ethernet/broadcom/bgmac.c static int bgmac_set_mac_address(struct net_device *net_dev, void *addr) · line 1225

Quoted 4 lines
drivers/net/ethernet/broadcom/bgmac.c +1 -0
@@ -1222,11 +1222,15 @@ static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
 {
 	struct bgmac *bgmac = netdev_priv(net_dev);
 	int ret;
+	struct sockaddr *sa = addr;

DaveM prefers the declarations to be arranged from longest to shortest.

[...]

MBR, Sergei

author
#10 lore raw

Re: [PATCH 2/2] net: ethernet: bgmac: mac address change bug

In reply to Rafał Miłecki
Quoted 8 lines · Rafał Miłecki
Quoted 7 lines · Jon Mason

From: Hari Vyas <[email protected]>

ndo_set_mac_address() passes struct sockaddr * as 2nd parameter to bgmac_set_mac_address() but code assumed u8 *. This caused two bytes chopping and the wrong mac address was configured.

Quoted 7 lines
Quoted 4 lines
Fixes 4e209001b86 ("bgmac: write mac address to hardware in

ndo_set_mac_address")

Sounds OK, would it make sense to Cc stable?

Sure, I'll add Sergei's mods and do a v2 with stable on the Cc list

author
#6 lore raw

Re: [PATCH 1/2] net: ethernet: bgmac: init sequence bug

In reply to Rafał Miłecki
Quoted 24 lines · Rafał Miłecki
Quoted 23 lines · Jon Mason

From: Zac Schroff <[email protected]>

Fix a bug in the 'bgmac' driver init sequence that blind writes for init sequence where it should preserve most bits other than the ones it is deliberately manipulating.

Fixes f6a95a24957 ("net: ethernet: bgmac: Add platform device support")
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 10 +++++++---
 include/linux/bcma/bcma_regs.h                 |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +0 -0
index 6f736c1..9bbe05c 100644
@@ -61,15 +61,19 @@ static bool platform_bgmac_clk_enabled(struct bgmac
 *bgmac)
 
Quoted 16 lines

drivers/net/ethernet/broadcom/bgmac-platform.c static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)

Quoted 11 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +5 -2
 static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
 {
-       bgmac_idm_write(bgmac, BCMA_IOCTL,
-                       (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
+       u32 regval;
+
+       /* Some bits of BCMA_IOCTL set by HW/ATF & should not change */
+       regval = bgmac_idm_read(bgmac, BCMA_IOCTL) &
 BCMA_IOCTL_DO_NOT_MODIFY;
+       regval |= ((flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) |
 BCMA_IOCTL_CLK);

You don't need these braces around whole calculation. This should work the same:
(flags & (~BCMA_IOCTL_DO_NOT_MODIFY)) | BCMA_IOCTL_CLK

Fair enough

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/broadcom/bgmac-platform.c +2 -1
+       bgmac_idm_write(bgmac, BCMA_IOCTL, regval | BCMA_IOCTL_FGC);
        bgmac_idm_read(bgmac, BCMA_IOCTL);
 
        bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
        bgmac_idm_read(bgmac, BCMA_RESET_CTL);
        udelay(1);
 
-       bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
+       bgmac_idm_write(bgmac, BCMA_IOCTL, regval);
        bgmac_idm_read(bgmac, BCMA_IOCTL);
        udelay(1);

}

include/linux/bcma/bcma_regs.h +0 -0
index 9986f82..41d7404 100644
Quoted 8 lines

include/linux/bcma/bcma_regs.h line 34

Quoted 5 lines
include/linux/bcma/bcma_regs.h +1 -0
@@ -31,6 +31,7 @@
 #define  BCMA_IOCTL_CORE_BITS          0x3FFC
 #define  BCMA_IOCTL_PME_EN             0x4000
 #define  BCMA_IOCTL_BIST_EN            0x8000
+#define  BCMA_IOCTL_DO_NOT_MODIFY      0x7FFFFF80

This sounds like a pretty bad name.

Name change coming

Quoted 7 lines

Take a look at brcmsmac and SICF_*:
http://lxr.free-electrons.com/source/drivers/net/wireless/broadcom/brcm80211/brcmsmac/d11.h?v=4.9#L1737

Or b43 and B43_BCMA_IOCTL_*:
http://lxr.free-electrons.com/source/drivers/net/wireless/broadcom/b43/b43.h?v=4.9#L494

Both drives modify bits you marked as DO_NOT_MODIFY and they are OK.

I think the point Zac was trying to make is that this is changing bits that aren't meaning to be modified. We should only be flipping the bits necessary to enable the clocks, etc. Bootloaders, etc might be setting bits (and in our case they are) which are being removed forcing it to a predefined value.

Thanks,
Jon

author
#5 lore raw

Re: [PATCH 1/2] net: ethernet: bgmac: init sequence bug

In reply to Rafał Miłecki
Quoted 11 lines · Rafał Miłecki
Quoted 2 lines · Zac Schroff

How about BCMA_IOCTL_PRESERVE_ACROSS_INIT?

I think wireless drivers may still set some these bits during init.

I've a simpler idea: make it bgmac specific. Call it sth like BGMAC_BCMA_IOCTL_PRESERVE
BGMAC_BCMA_IOCTL_RESERVED BGMAC_BCMA_IOCTL_DONT_TOUCH

Yes, I am listing out all of the fields in that register. We can be intelligent about what we mask off :)

maintainer
#4 lore raw

Re: [PATCH 1/2] net: ethernet: bgmac: init sequence bug

In reply to Zac Schroff
Quoted 1 line · Zac Schroff

How about BCMA_IOCTL_PRESERVE_ACROSS_INIT?

I think wireless drivers may still set some these bits during init.

I've a simpler idea: make it bgmac specific. Call it sth like BGMAC_BCMA_IOCTL_PRESERVE
BGMAC_BCMA_IOCTL_RESERVED BGMAC_BCMA_IOCTL_DONT_TOUCH