[U-Boot] [PATCH 0/2] net: macb: support arbitrary mdio addresses

This patch mini-series enables the macb driver to access all addresses on the mdio bus instead of only the one of the connected phy. This is especially useful if you have a tagging switch connected to the macb.
Josef Holzmayr (2): net: macb: explicitly pass phy_adr to mdio read and write net: macb: let miiphy_read/_write pass arbitrary addresses
drivers/net/macb.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-)

To support accessing arbitrary addresses the mii/mdio bus it is neccesary that the macb_mdio_read and macb_mdio_write functions do not implicitly use the address of the connected phy.
The function signature is extended according to the Linux kernel equivalent.
Signed-off-by: Josef Holzmayr holzmayr@rsi-elektrotechnik.de --- drivers/net/macb.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 377188e361..5da490efb7 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -164,7 +164,8 @@ static int gem_is_gigabit_capable(struct macb_device *macb) return macb_is_gem(macb) && !cpu_is_sama5d2() && !cpu_is_sama5d4(); }
-static void macb_mdio_write(struct macb_device *macb, u8 reg, u16 value) +static void macb_mdio_write(struct macb_device *macb, u8 phy_adr, u8 reg, + u16 value) { unsigned long netctl; unsigned long netstat; @@ -176,7 +177,7 @@ static void macb_mdio_write(struct macb_device *macb, u8 reg, u16 value)
frame = (MACB_BF(SOF, 1) | MACB_BF(RW, 1) - | MACB_BF(PHYA, macb->phy_addr) + | MACB_BF(PHYA, phy_adr) | MACB_BF(REGA, reg) | MACB_BF(CODE, 2) | MACB_BF(DATA, value)); @@ -191,7 +192,7 @@ static void macb_mdio_write(struct macb_device *macb, u8 reg, u16 value) macb_writel(macb, NCR, netctl); }
-static u16 macb_mdio_read(struct macb_device *macb, u8 reg) +static u16 macb_mdio_read(struct macb_device *macb, u8 phy_adr, u8 reg) { unsigned long netctl; unsigned long netstat; @@ -203,7 +204,7 @@ static u16 macb_mdio_read(struct macb_device *macb, u8 reg)
frame = (MACB_BF(SOF, 1) | MACB_BF(RW, 2) - | MACB_BF(PHYA, macb->phy_addr) + | MACB_BF(PHYA, phy_adr) | MACB_BF(REGA, reg) | MACB_BF(CODE, 2)); macb_writel(macb, MAN, frame); @@ -243,7 +244,7 @@ int macb_miiphy_read(struct mii_dev *bus, int phy_adr, int devad, int reg) return -1;
arch_get_mdio_control(bus->name); - value = macb_mdio_read(macb, reg); + value = macb_mdio_read(macb, macb->phy_addr, reg);
return value; } @@ -263,7 +264,7 @@ int macb_miiphy_write(struct mii_dev *bus, int phy_adr, int devad, int reg, return -1;
arch_get_mdio_control(bus->name); - macb_mdio_write(macb, reg, value); + macb_mdio_write(macb, macb->phy_addr, reg, value);
return 0; } @@ -450,13 +451,13 @@ static void macb_phy_reset(struct macb_device *macb, const char *name) u16 status, adv;
adv = ADVERTISE_CSMA | ADVERTISE_ALL; - macb_mdio_write(macb, MII_ADVERTISE, adv); + macb_mdio_write(macb, macb->phy_addr, MII_ADVERTISE, adv); printf("%s: Starting autonegotiation...\n", name); - macb_mdio_write(macb, MII_BMCR, (BMCR_ANENABLE + macb_mdio_write(macb, macb->phy_addr, MII_BMCR, (BMCR_ANENABLE | BMCR_ANRESTART));
for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) { - status = macb_mdio_read(macb, MII_BMSR); + status = macb_mdio_read(macb, macb->phy_addr, MII_BMSR); if (status & BMSR_ANEGCOMPLETE) break; udelay(100); @@ -477,7 +478,7 @@ static int macb_phy_find(struct macb_device *macb, const char *name) /* Search for PHY... */ for (i = 0; i < 32; i++) { macb->phy_addr = i; - phy_id = macb_mdio_read(macb, MII_PHYSID1); + phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); if (phy_id != 0xffff) { printf("%s: PHY present at %d\n", name, i); return 0; @@ -595,7 +596,7 @@ static int macb_phy_init(struct macb_device *macb, const char *name) return ret;
/* Check if the PHY is up to snuff... */ - phy_id = macb_mdio_read(macb, MII_PHYSID1); + phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); if (phy_id == 0xffff) { printf("%s: No PHY present\n", name); return -ENODEV; @@ -618,13 +619,13 @@ static int macb_phy_init(struct macb_device *macb, const char *name) phy_config(macb->phydev); #endif
- status = macb_mdio_read(macb, MII_BMSR); + status = macb_mdio_read(macb, macb->phy_addr, MII_BMSR); if (!(status & BMSR_LSTATUS)) { /* Try to re-negotiate if we don't have link already. */ macb_phy_reset(macb, name);
for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) { - status = macb_mdio_read(macb, MII_BMSR); + status = macb_mdio_read(macb, macb->phy_addr, MII_BMSR); if (status & BMSR_LSTATUS) { /* * Delay a bit after the link is established, @@ -645,7 +646,7 @@ static int macb_phy_init(struct macb_device *macb, const char *name)
/* First check for GMAC and that it is GiB capable */ if (gem_is_gigabit_capable(macb)) { - lpa = macb_mdio_read(macb, MII_STAT1000); + lpa = macb_mdio_read(macb, macb->phy_addr, MII_STAT1000);
if (lpa & (LPA_1000FULL | LPA_1000HALF | LPA_1000XFULL | LPA_1000XHALF)) { @@ -679,8 +680,8 @@ static int macb_phy_init(struct macb_device *macb, const char *name) }
/* fall back for EMAC checking */ - adv = macb_mdio_read(macb, MII_ADVERTISE); - lpa = macb_mdio_read(macb, MII_LPA); + adv = macb_mdio_read(macb, macb->phy_addr, MII_ADVERTISE); + lpa = macb_mdio_read(macb, macb->phy_addr, MII_LPA); media = mii_nway_result(lpa & adv); speed = (media & (ADVERTISE_100FULL | ADVERTISE_100HALF) ? 1 : 0);

On Wed, Oct 2, 2019 at 2:47 PM Josef Holzmayr holzmayr@rsi-elektrotechnik.de wrote:
To support accessing arbitrary addresses the mii/mdio bus it is neccesary that the macb_mdio_read and macb_mdio_write functions do not implicitly use the address of the connected phy.
The function signature is extended according to the Linux kernel equivalent.
Signed-off-by: Josef Holzmayr holzmayr@rsi-elektrotechnik.de
Acked-by: Joe Hershberger joe.hershberger@ni.com

This allows passing arbitrary addresses through macb_miiphy_read and macb_miiphy_write, therefore enabling the mii command to access all mdio bus devices instead of only the defined phy.
Signed-off-by: Josef Holzmayr holzmayr@rsi-elektrotechnik.de --- drivers/net/macb.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 5da490efb7..e801d4c4ec 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -240,11 +240,8 @@ int macb_miiphy_read(struct mii_dev *bus, int phy_adr, int devad, int reg) struct macb_device *macb = to_macb(dev); #endif
- if (macb->phy_addr != phy_adr) - return -1; - arch_get_mdio_control(bus->name); - value = macb_mdio_read(macb, macb->phy_addr, reg); + value = macb_mdio_read(macb, phy_adr, reg);
return value; } @@ -260,11 +257,8 @@ int macb_miiphy_write(struct mii_dev *bus, int phy_adr, int devad, int reg, struct macb_device *macb = to_macb(dev); #endif
- if (macb->phy_addr != phy_adr) - return -1; - arch_get_mdio_control(bus->name); - macb_mdio_write(macb, macb->phy_addr, reg, value); + macb_mdio_write(macb, phy_adr, reg, value);
return 0; }

On Wed, Oct 2, 2019 at 2:46 PM Josef Holzmayr holzmayr@rsi-elektrotechnik.de wrote:
This allows passing arbitrary addresses through macb_miiphy_read and macb_miiphy_write, therefore enabling the mii command to access all mdio bus devices instead of only the defined phy.
Signed-off-by: Josef Holzmayr holzmayr@rsi-elektrotechnik.de
Acked-by: Joe Hershberger joe.hershberger@ni.com
participants (2)
-
Joe Hershberger
-
Josef Holzmayr