Skip to contentSkip to conversation

cpsw_mdio.c: Use correct reg in cpsw_mdio_get_alive

PATCH In review Ulf Samuelsson 4 participants 5 messages Feb 7, 2023 – Feb 17, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpsw_mdio.c: Use correct reg in cpsw_mdio_get_alive

cpsw_mdio_get_alive reads the wrong register. See page 2316 in SPRUH73Q AM335x TRM

Cc Joe Hershberger <[email protected]>
Cc Ramon Fried <[email protected]>
---
 drivers/net/ti/cpsw_mdio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ti/cpsw_mdio.c +3 -3
index a5ba73b739..ac791faa81 100644
@@ -51,7 +51,7 @@ struct cpsw_mdio_regs {
 #define USERACCESS_PHY_REG_SHIFT	(21)
 #define USERACCESS_PHY_ADDR_SHIFT	(16)
 #define USERACCESS_DATA		GENMASK(15, 0)
-	} user[0];
+	} user[2];
 };
 
 #define CPSW_MDIO_DIV_DEF	0xff
@@ -366,8 +366,8 @@ u32 cpsw_mdio_get_alive(struct mii_dev *bus)
 	struct cpsw_mdio *mdio = bus->priv;
 	u32 val;
 
-	val = readl(&mdio->regs->control);
-	return val & GENMASK(15, 0);
+	val = readl(&mdio->regs->alive);
+	return val & GENMASK(7, 0);
 }
 
 struct mii_dev *cpsw_mdio_init(const char *name, phys_addr_t mdio_base,
Signature · 1 line
2.17.1
#1 lore raw

Hello Ulf,

Quoted 24 lines · Ulf Samuelsson

cpsw_mdio_get_alive reads the wrong register. See page 2316 in SPRUH73Q AM335x TRM

Cc Joe Hershberger <[email protected]>
Cc Ramon Fried <[email protected]>
---
 drivers/net/ti/cpsw_mdio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ti/cpsw_mdio.c +1 -1
index a5ba73b739..ac791faa81 100644
@@ -51,7 +51,7 @@ struct cpsw_mdio_regs {
 #define USERACCESS_PHY_REG_SHIFT	(21)
 #define USERACCESS_PHY_ADDR_SHIFT	(16)
 #define USERACCESS_DATA		GENMASK(15, 0)
-	} user[0];
+	} user[2];
 };
 
 #define CPSW_MDIO_DIV_DEF	0xff

drivers/net/ti/cpsw_mdio.c u32 cpsw_mdio_get_alive(struct mii_dev *bus) · line 370

Quoted 7 lines
drivers/net/ti/cpsw_mdio.c +2 -2
@@ -366,8 +366,8 @@ u32 cpsw_mdio_get_alive(struct mii_dev *bus)
 	struct cpsw_mdio *mdio = bus->priv;
 	u32 val;
 
-	val = readl(&mdio->regs->control);
-	return val & GENMASK(15, 0);
+	val = readl(&mdio->regs->alive);
+	return val & GENMASK(7, 0);

Referring to the TRM for AM335x at [0], on page 2401, the MDIOALIVE register reports the presence of Ethernet PHYs up to ADDR 31. Also, the cpsw driver:
drivers/net/ti/cpsw.c which uses the cpsw_mdio_get_alive() function, expects the return value to be a 16 bit value. Therefore, I believe that the GENMASK should retain the previous value of "GENMASK(15, 0)", while only the register being read needs to be changed from "control" to "alive". Please let me know if I misunderstood something regarding your implementation.

[0] https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf

Regards,
Siddharth.

Quoted 3 lines
drivers/net/ti/cpsw_mdio.c +0 -0
 }
 
 struct mii_dev *cpsw_mdio_init(const char *name, phys_addr_t mdio_base,
#2 lore raw

Den 2023-02-09 kl. 08:29, skrev Siddharth Vadapalli:

Quoted 30 lines

Hello Ulf,

Quoted 27 lines · Ulf Samuelsson

cpsw_mdio_get_alive reads the wrong register. See page 2316 in SPRUH73Q AM335x TRM

Cc Joe Hershberger <[email protected]>
Cc Ramon Fried <[email protected]>
---
  drivers/net/ti/cpsw_mdio.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ti/cpsw_mdio.c +1 -1
index a5ba73b739..ac791faa81 100644
@@ -51,7 +51,7 @@ struct cpsw_mdio_regs {
  #define USERACCESS_PHY_REG_SHIFT	(21)
  #define USERACCESS_PHY_ADDR_SHIFT	(16)
  #define USERACCESS_DATA		GENMASK(15, 0)
-	} user[0];
+	} user[2];
  };
 
  #define CPSW_MDIO_DIV_DEF	0xff
@@ -366,8 +366,8 @@ u32 cpsw_mdio_get_alive(struct mii_dev *bus)
  	struct cpsw_mdio *mdio = bus->priv;
  	u32 val;
 
Quoted 13 lines

drivers/net/ti/cpsw_mdio.c u32 cpsw_mdio_get_alive(struct mii_dev *bus) · line 370

Quoted 4 lines
drivers/net/ti/cpsw_mdio.c +2 -2
-	val = readl(&mdio->regs->control);
-	return val & GENMASK(15, 0);
+	val = readl(&mdio->regs->alive);
+	return val & GENMASK(7, 0);

Referring to the TRM for AM335x at [0], on page 2401, the MDIOALIVE register reports the presence of Ethernet PHYs up to ADDR 31. Also, the cpsw driver:
drivers/net/ti/cpsw.c which uses the cpsw_mdio_get_alive() function, expects the return value to be a 16 bit value. Therefore, I believe that the GENMASK should retain the previous value of "GENMASK(15, 0)", while only the register being read needs to be changed from "control" to "alive". Please let me know if I misunderstood something regarding your implementation.

We had an unusual H/W where the PHY (actually a switch) was connected to the second Ethernet port. All boards I have seen have the PHY connected to the first port or have both ports connected.

IIRC correctly (this patch is > 2 years old),
we had bad data in the bits (15:8) and this is why only the 8 bits. Only bits [1:0] are used anyway.

Quoted 8 lines

[0] https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf

Regards,
Siddharth.

Quoted 3 lines
drivers/net/ti/cpsw_mdio.c +0 -0
  }
 
  struct mii_dev *cpsw_mdio_init(const char *name, phys_addr_t mdio_base,

Best Regards
Ulf Samuelsson

#3 lore raw
Quoted 43 lines · Ulf Samuelsson

Den 2023-02-09 kl. 08:29, skrev Siddharth Vadapalli:

Quoted 33 lines

Hello Ulf,

Quoted 23 lines · Ulf Samuelsson

cpsw_mdio_get_alive reads the wrong register. See page 2316 in SPRUH73Q AM335x TRM

Cc Joe Hershberger <[email protected]>
Cc Ramon Fried <[email protected]>

---
  drivers/net/ti/cpsw_mdio.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ti/cpsw_mdio.c +1 -1
index a5ba73b739..ac791faa81 100644
@@ -51,7 +51,7 @@ struct cpsw_mdio_regs {
   #define USERACCESS_PHY_REG_SHIFT    (21)
   #define USERACCESS_PHY_ADDR_SHIFT    (16)
   #define USERACCESS_DATA        GENMASK(15, 0)
-    } user[0];
+    } user[2];
   };
     #define CPSW_MDIO_DIV_DEF    0xff

drivers/net/ti/cpsw_mdio.c u32 cpsw_mdio_get_alive(struct mii_dev *bus) · line 370

Quoted 6 lines
drivers/net/ti/cpsw_mdio.c +2 -1
@@ -366,8 +366,8 @@ u32 cpsw_mdio_get_alive(struct mii_dev *bus)
       struct cpsw_mdio *mdio = bus->priv;
       u32 val;
   -    val = readl(&mdio->regs->control);
-    return val & GENMASK(15, 0);
+    val = readl(&mdio->regs->alive);
+    return val & GENMASK(7, 0);
Quoted 8 lines

Referring to the TRM for AM335x at [0], on page 2401, the MDIOALIVE register reports the presence of Ethernet PHYs up to ADDR 31. Also, the cpsw driver:
drivers/net/ti/cpsw.c which uses the cpsw_mdio_get_alive() function, expects the return value to be a 16 bit value. Therefore, I believe that the GENMASK should retain the previous value of "GENMASK(15, 0)", while only the register being read needs to be changed from "control" to "alive". Please let me know if I misunderstood something regarding your implementation.

Quoted 7 lines

We had an unusual H/W where the PHY (actually a switch) was connected to the second Ethernet port. All boards I have seen have the PHY connected to the first port or have both ports connected.

IIRC correctly (this patch is > 2 years old),
we had bad data in the bits (15:8) and this is why only the 8 bits. Only bits [1:0] are used anyway.

Thank you for clarifying.

Regards,
Siddharth.