Re: [PATCH] net: macb: Add support for fixed link
On Tue, Feb 06, 2024 at 08:04:02PM +0100, belouargamoha...@gmail.com wrote: > From: BELOUARGA Mohamed > > The actual driver does not work when there is no linked PHY. These > changes add support for fixed-link feature in the device tree. > > Signed-off-by: BELOUARGA Mohamed Applied to u-boot/next, thanks! -- Tom signature.asc Description: PGP signature
[PATCH] net: macb: Add support for fixed link
From: BELOUARGA Mohamed The actual driver does not work when there is no linked PHY. These changes add support for fixed-link feature in the device tree. Signed-off-by: BELOUARGA Mohamed --- drivers/net/macb.c | 189 - 1 file changed, 117 insertions(+), 72 deletions(-) diff --git a/drivers/net/macb.c b/drivers/net/macb.c index bfc48dac07..05d638cd77 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -128,6 +128,8 @@ struct macb_device { unsigned long dummy_desc_dma; const struct device *dev; + unsigned intduplex; + unsigned intspeed; unsigned short phy_addr; struct mii_dev *bus; #ifdef CONFIG_PHYLIB @@ -178,6 +180,12 @@ static int gem_is_gigabit_capable(struct macb_device *macb) return macb_is_gem(macb) && !cpu_is_sama5d2() && !cpu_is_sama5d4(); } +/* Is the port a fixed link */ +static int macb_port_is_fixed_link(struct macb_device *macb) +{ + return macb->phy_addr > PHY_MAX_ADDR; +} + static void macb_mdio_write(struct macb_device *macb, u8 phy_adr, u8 reg, u16 value) { @@ -666,97 +674,110 @@ static int macb_phy_init(struct udevice *dev, const char *name) int i; arch_get_mdio_control(name); - /* Auto-detect phy_addr */ - ret = macb_phy_find(macb, name); - if (ret) - return ret; + /* If port is not fixed -> setup PHY */ + if (!macb_port_is_fixed_link(macb)) { + /* Auto-detect phy_addr */ + ret = macb_phy_find(macb, name); + if (ret) + return ret; - /* Check if the PHY is up to snuff... */ - phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); - if (phy_id == 0x) { - printf("%s: No PHY present\n", name); - return -ENODEV; - } + /* Check if the PHY is up to snuff... */ + phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); + if (phy_id == 0x) { + printf("%s: No PHY present\n", name); + return -ENODEV; + } #ifdef CONFIG_PHYLIB - macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev, -macb->phy_interface); - if (!macb->phydev) { - printf("phy_connect failed\n"); - return -ENODEV; - } + macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev, +macb->phy_interface); + if (!macb->phydev) { + printf("phy_connect failed\n"); + return -ENODEV; + } - phy_config(macb->phydev); + phy_config(macb->phydev); #endif - 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, macb->phy_addr, MII_BMSR); - if (status & BMSR_LSTATUS) { - /* -* Delay a bit after the link is established, -* so that the next xfer does not fail -*/ - mdelay(10); - break; + 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, macb->phy_addr, MII_BMSR); + if (status & BMSR_LSTATUS) { + /* +* Delay a bit after the link is established, +* so that the next xfer does not fail +*/ + mdelay(10); + break; + } + udelay(100); } - udelay(100); } - } - if (!(status & BMSR_LSTATUS)) { - printf("%s: link down (status: 0x%04x)\n", - name, status); - return -ENETDOWN; - } + if (!(status & BMSR_LSTATUS)) { + printf("%s: link down (status: 0x%04x)\n", + name, status); + return -ENETDOWN;
Re: [PATCH] net: macb: Add support for fixed link
On Sat, Feb 03, 2024 at 07:06:52PM +0100, belouargamoha...@gmail.com wrote: > @@ -1276,6 +1297,30 @@ int __weak macb_late_eth_of_to_plat(struct udevice > *dev) > static int macb_eth_of_to_plat(struct udevice *dev) > { > struct eth_pdata *pdata = dev_get_plat(dev); > + struct macb_device *macb = dev_get_priv(dev); > + void *blob = (void *)gd->fdt_blob; > + int node = dev_of_offset(dev); > + int fl_node, speed_fdt; > + > + /* fetch 'fixed-link' property */ > + fl_node = fdt_subnode_offset(blob, node, "fixed-link"); > + if (fl_node != -FDT_ERR_NOTFOUND) { Why not check for if (fl_node >= 0)? The fdt_subnode_offset() function can return a variety of error codes. regards, dan carpenter > + /* set phy_addr to invalid value for fixed link */ > + macb->phy_addr = PHY_MAX_ADDR + 1; > + macb->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex"); > + speed_fdt = fdtdec_get_int(blob, fl_node, "speed", 0); > + if (speed_fdt == 100) { > + macb->speed = 1; > + } > + else if (speed_fdt == 10) { > + macb->speed = 0; > + } > + else { > + printf("%s: The given speed %d of ethernet in the DT is > not supported\n", > + __func__, speed_fdt); > + return -EINVAL; > + } > + } >
[PATCH] net: macb: Add support for fixed link
From: BELOUARGA Mohamed The actual driver does not work when there is no linked PHY. These changes add support for fixed-link feature in the device tree. Signed-off-by: BELOUARGA Mohamed --- drivers/net/macb.c | 189 - 1 file changed, 117 insertions(+), 72 deletions(-) diff --git a/drivers/net/macb.c b/drivers/net/macb.c index bfc48dac07..53f0189153 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -128,6 +128,8 @@ struct macb_device { unsigned long dummy_desc_dma; const struct device *dev; + unsigned intduplex; + unsigned intspeed; unsigned short phy_addr; struct mii_dev *bus; #ifdef CONFIG_PHYLIB @@ -178,6 +180,12 @@ static int gem_is_gigabit_capable(struct macb_device *macb) return macb_is_gem(macb) && !cpu_is_sama5d2() && !cpu_is_sama5d4(); } +/* Is the port a fixed link */ +static int macb_port_is_fixed_link(struct macb_device *macb) +{ + return macb->phy_addr > PHY_MAX_ADDR; +} + static void macb_mdio_write(struct macb_device *macb, u8 phy_adr, u8 reg, u16 value) { @@ -666,97 +674,110 @@ static int macb_phy_init(struct udevice *dev, const char *name) int i; arch_get_mdio_control(name); - /* Auto-detect phy_addr */ - ret = macb_phy_find(macb, name); - if (ret) - return ret; + /* If port is not fixed -> setup PHY */ + if (!macb_port_is_fixed_link(macb)) { + /* Auto-detect phy_addr */ + ret = macb_phy_find(macb, name); + if (ret) + return ret; - /* Check if the PHY is up to snuff... */ - phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); - if (phy_id == 0x) { - printf("%s: No PHY present\n", name); - return -ENODEV; - } + /* Check if the PHY is up to snuff... */ + phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); + if (phy_id == 0x) { + printf("%s: No PHY present\n", name); + return -ENODEV; + } #ifdef CONFIG_PHYLIB - macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev, -macb->phy_interface); - if (!macb->phydev) { - printf("phy_connect failed\n"); - return -ENODEV; - } + macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev, +macb->phy_interface); + if (!macb->phydev) { + printf("phy_connect failed\n"); + return -ENODEV; + } - phy_config(macb->phydev); + phy_config(macb->phydev); #endif - 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, macb->phy_addr, MII_BMSR); - if (status & BMSR_LSTATUS) { - /* -* Delay a bit after the link is established, -* so that the next xfer does not fail -*/ - mdelay(10); - break; + 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, macb->phy_addr, MII_BMSR); + if (status & BMSR_LSTATUS) { + /* +* Delay a bit after the link is established, +* so that the next xfer does not fail +*/ + mdelay(10); + break; + } + udelay(100); } - udelay(100); } - } - if (!(status & BMSR_LSTATUS)) { - printf("%s: link down (status: 0x%04x)\n", - name, status); - return -ENETDOWN; - } + if (!(status & BMSR_LSTATUS)) { + printf("%s: link down (status: 0x%04x)\n", + name, status); + return -ENETDOWN;