Skip to contentSkip to conversation

net: ethernet: bgmac: bug fixes

PATCH Superseded Jon Mason 2 participants 6 messages Feb 28, 2017 – Mar 3, 2017

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jon Mason

author
#0 lore raw

v4 cover net: ethernet: bgmac: bug fixes

Changes in v4:
* Added the udelays from the previous code (per David Miller)

Changes in v3:
* Reworked the init sequence patch to only remove the device reset if the device is actually in reset. Given that this code doesn't bear much resemblance to the original code, I'm changing the author of the patch. This was tested on NS2 SVK.

Changes in v2:
* Reworked the first match to make it more obvious what portions of the register were being preserved (Per Rafal Mileki)
* Style change to reorder the function variables in patch 2 (per Sergei Shtylyov)

Bug fixes for bgmac driver

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

Jon Mason (1):
net: ethernet: bgmac: init sequence bug

 drivers/net/ethernet/broadcom/bgmac-platform.c | 27 +++++++++++++++++---------
 drivers/net/ethernet/broadcom/bgmac.c          |  6 +++++-
 drivers/net/ethernet/broadcom/bgmac.h          | 16 +++++++++++++++
 3 files changed, 39 insertions(+), 10 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

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

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.

The code now checks to see if the adapter needs to be brought out of reset (where as before it was doing an IDM write to bring it out of reset regardless of whether it was in reset or not). Also, removed unnecessary usleeps (as there is already a read present to flush the IDM writes).

Fixes f6a95a24957 ("net: ethernet: bgmac: Add platform device support")
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 27 +++++++++++++++++---------
 drivers/net/ethernet/broadcom/bgmac.h          | 16 +++++++++++++++
 2 files changed, 34 insertions(+), 9 deletions(-)
drivers/net/ethernet/broadcom/bgmac-platform.c +18 -9
index 7b1af95..da1b8b2 100644
@@ -51,8 +51,7 @@ static void platform_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
 
 static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
 {
-	if ((bgmac_idm_read(bgmac, BCMA_IOCTL) &
-	     (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC)) != BCMA_IOCTL_CLK)
+	if ((bgmac_idm_read(bgmac, BCMA_IOCTL) & BGMAC_CLK_EN) != BGMAC_CLK_EN)
 		return false;
 	if (bgmac_idm_read(bgmac, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
 		return false;
@@ -61,15 +60,25 @@ 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));
-	bgmac_idm_read(bgmac, BCMA_IOCTL);
+	u32 val;
 
-	bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
-	bgmac_idm_read(bgmac, BCMA_RESET_CTL);
-	udelay(1);
+	/* The Reset Control register only contains a single bit to show if the
+	 * controller is currently in reset.  Do a sanity check here, just in
+	 * case the bootloader happened to leave the device in reset.
+	 */
+	val = bgmac_idm_read(bgmac, BCMA_RESET_CTL);
+	if (val) {
+		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));
+	val = bgmac_idm_read(bgmac, BCMA_IOCTL);
+	/* Some bits of BCMA_IOCTL set by HW/ATF and should not change */
+	val |= flags & ~(BGMAC_AWCACHE | BGMAC_ARCACHE | BGMAC_AWUSER |
+			 BGMAC_ARUSER);
+	val |= BGMAC_CLK_EN;
+	bgmac_idm_write(bgmac, BCMA_IOCTL, val);
 	bgmac_idm_read(bgmac, BCMA_IOCTL);
 	udelay(1);
 }
drivers/net/ethernet/broadcom/bgmac.h +16 -0
index 248727d..6d1c6ff 100644
@@ -213,6 +213,22 @@
 /* BCMA GMAC core specific IO Control (BCMA_IOCTL) flags */
 #define BGMAC_BCMA_IOCTL_SW_CLKEN		0x00000004	/* PHY Clock Enable */
 #define BGMAC_BCMA_IOCTL_SW_RESET		0x00000008	/* PHY Reset */
+/* The IOCTL values appear to be different in NS, NSP, and NS2, and do not match
+ * the values directly above
+ */
+#define BGMAC_CLK_EN				BIT(0)
+#define BGMAC_RESERVED_0			BIT(1)
+#define BGMAC_SOURCE_SYNC_MODE_EN		BIT(2)
+#define BGMAC_DEST_SYNC_MODE_EN			BIT(3)
+#define BGMAC_TX_CLK_OUT_INVERT_EN		BIT(4)
+#define BGMAC_DIRECT_GMII_MODE			BIT(5)
+#define BGMAC_CLK_250_SEL			BIT(6)
+#define BGMAC_AWCACHE				(0xf << 7)
+#define BGMAC_RESERVED_1			(0x1f << 11)
+#define BGMAC_ARCACHE				(0xf << 16)
+#define BGMAC_AWUSER				(0x3f << 20)
+#define BGMAC_ARUSER				(0x3f << 26)
+#define BGMAC_RESERVED				BIT(31)
 
 /* BCMA GMAC core specific IO status (BCMA_IOST) flags */
 #define BGMAC_BCMA_IOST_ATTACHED		0x00000800
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v4 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 4150467..6b7782f 100644
@@ -1223,12 +1223,16 @@ static netdev_tx_t bgmac_start_xmit(struct sk_buff *skb,
 static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
 {
 	struct bgmac *bgmac = netdev_priv(net_dev);
+	struct sockaddr *sa = addr;
 	int ret;
 
 	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
#3 lore raw
In reply to Jon Mason

From: Jon Mason <[email protected]>
Date: Tue, 28 Feb 2017 13:41:49 -0500

Quoted 9 lines

Changes in v4:
* Added the udelays from the previous code (per David Miller)

Changes in v3:
* Reworked the init sequence patch to only remove the device reset if the device is actually in reset. Given that this code doesn't bear much resemblance to the original code, I'm changing the author of the patch. This was tested on NS2 SVK.

Quoted 7 lines

Changes in v2:
* Reworked the first match to make it more obvious what portions of the register were being preserved (Per Rafal Mileki)
* Style change to reorder the function variables in patch 2 (per Sergei Shtylyov)

Bug fixes for bgmac driver

Series applied.

maintainer
#4 lore raw

From: David Miller <[email protected]>
Date: Thu, 02 Mar 2017 12:50:15 -0800 (PST)

Quoted 18 lines

From: Jon Mason <[email protected]>
Date: Tue, 28 Feb 2017 13:41:49 -0500

Quoted 15 lines

Changes in v4:
* Added the udelays from the previous code (per David Miller)

Changes in v3:
* Reworked the init sequence patch to only remove the device reset if the device is actually in reset. Given that this code doesn't bear much resemblance to the original code, I'm changing the author of the patch. This was tested on NS2 SVK.

Changes in v2:
* Reworked the first match to make it more obvious what portions of the register were being preserved (Per Rafal Mileki)
* Style change to reorder the function variables in patch 2 (per Sergei Shtylyov)

Quoted 3 lines
Quoted 1 line

Bug fixes for bgmac driver

Series applied.

Actually, this doesn't even compile. Reverted...

[davem@kkuri net]$ make -s -j4
drivers/net/ethernet/broadcom/bgmac.c: In function ‘bgmac_set_mac_address’:
drivers/net/ethernet/broadcom/bgmac.c:1233:23: error: ‘struct bgmac’ has no member named ‘mac_addr’; did you mean ‘phyaddr’?

  ether_addr_copy(bgmac->mac_addr, sa->sa_data);
                       ^~
drivers/net/ethernet/broadcom/bgmac.c:1234:38: error: ‘struct bgmac’ has no member named ‘mac_addr’; did you mean ‘phyaddr’?
  bgmac_write_mac_address(bgmac, bgmac->mac_addr);
                                      ^~
author
#5 lore raw
Quoted 27 lines · David Miller

From: David Miller <[email protected]>
Date: Thu, 02 Mar 2017 12:50:15 -0800 (PST)

Quoted 18 lines

From: Jon Mason <[email protected]>
Date: Tue, 28 Feb 2017 13:41:49 -0500

Quoted 15 lines

Changes in v4:
* Added the udelays from the previous code (per David Miller)

Changes in v3:
* Reworked the init sequence patch to only remove the device reset if the device is actually in reset. Given that this code doesn't bear much resemblance to the original code, I'm changing the author of the patch. This was tested on NS2 SVK.

Changes in v2:
* Reworked the first match to make it more obvious what portions of the register were being preserved (Per Rafal Mileki)
* Style change to reorder the function variables in patch 2 (per Sergei Shtylyov)

Quoted 3 lines
Quoted 1 line

Bug fixes for bgmac driver

Series applied.

Actually, this doesn't even compile. Reverted...

Quoted 8 lines

[davem@kkuri net]$ make -s -j4
drivers/net/ethernet/broadcom/bgmac.c: In function ‘bgmac_set_mac_address’:
drivers/net/ethernet/broadcom/bgmac.c:1233:23: error: ‘struct bgmac’ has no member named ‘mac_addr’; did you mean ‘phyaddr’?

  ether_addr_copy(bgmac->mac_addr, sa->sa_data);
                       ^~
drivers/net/ethernet/broadcom/bgmac.c:1234:38: error: ‘struct bgmac’ has no member named ‘mac_addr’; did you mean ‘phyaddr’?
  bgmac_write_mac_address(bgmac, bgmac->mac_addr);
                                      ^~

Well this is embarrassing. I didn't rebase, even though I acked the patch which changed it out from under me. Sorry, I should've known better.

Rebased, compiled, and tested patch coming shortly. I appreciate your patience.

Thanks,
Jon