Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'lan78xx-preparations-for-phylink'

Oleksij Rempel says:

====================
lan78xx: Preparations for PHYlink

This patch set is a third part of the preparatory work for migrating
the lan78xx USB Ethernet driver to the PHYlink framework. During
extensive testing, I observed that resetting the USB adapter can lead to
various read/write errors. While the errors themselves are acceptable,
they generate excessive log messages, resulting in significant log spam.
This set improves error handling to reduce logging noise by addressing
errors directly and returning early when necessary.
====================

Link: https://patch.msgid.link/20241216120941.1690908-1-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+40 -33
+40 -33
drivers/net/usb/lan78xx.c
··· 439 439 struct usb_anchor deferred; 440 440 441 441 struct mutex dev_mutex; /* serialise open/stop wrt suspend/resume */ 442 - struct mutex phy_mutex; /* for phy access */ 442 + struct mutex mdiobus_mutex; /* for MDIO bus access */ 443 443 unsigned int pipe_in, pipe_out, pipe_intr; 444 444 445 445 unsigned int bulk_in_delay; ··· 844 844 } while (!stopped && !time_after(jiffies, timeout)); 845 845 } 846 846 847 - ret = stopped ? 0 : -ETIME; 848 - 849 - return ret; 847 + return stopped ? 0 : -ETIMEDOUT; 850 848 } 851 849 852 850 static int lan78xx_flush_fifo(struct lan78xx_net *dev, u32 reg, u32 fifo_flush) ··· 952 954 return lan78xx_flush_fifo(dev, FCT_RX_CTL, FCT_RX_CTL_RST_); 953 955 } 954 956 955 - /* Loop until the read is completed with timeout called with phy_mutex held */ 957 + /* Loop until the read is completed with timeout called with mdiobus_mutex held */ 956 958 static int lan78xx_mdiobus_wait_not_busy(struct lan78xx_net *dev) 957 959 { 958 960 unsigned long start_time = jiffies; ··· 1596 1598 u32 val; 1597 1599 int ret; 1598 1600 1599 - mutex_lock(&dev->phy_mutex); 1601 + mutex_lock(&dev->mdiobus_mutex); 1600 1602 1601 1603 /* Resetting the device while there is activity on the MDIO 1602 1604 * bus can result in the MAC interface locking up and not ··· 1604 1606 */ 1605 1607 ret = lan78xx_mdiobus_wait_not_busy(dev); 1606 1608 if (ret < 0) 1607 - goto done; 1609 + goto exit_unlock; 1608 1610 1609 1611 ret = lan78xx_read_reg(dev, MAC_CR, &val); 1610 1612 if (ret < 0) 1611 - goto done; 1613 + goto exit_unlock; 1612 1614 1613 1615 val |= MAC_CR_RST_; 1614 1616 ret = lan78xx_write_reg(dev, MAC_CR, val); 1615 1617 if (ret < 0) 1616 - goto done; 1618 + goto exit_unlock; 1617 1619 1618 1620 /* Wait for the reset to complete before allowing any further 1619 1621 * MAC register accesses otherwise the MAC may lock up. ··· 1621 1623 do { 1622 1624 ret = lan78xx_read_reg(dev, MAC_CR, &val); 1623 1625 if (ret < 0) 1624 - goto done; 1626 + goto exit_unlock; 1625 1627 1626 1628 if (!(val & MAC_CR_RST_)) { 1627 1629 ret = 0; 1628 - goto done; 1630 + goto exit_unlock; 1629 1631 } 1630 1632 } while (!time_after(jiffies, start_time + HZ)); 1631 1633 1632 1634 ret = -ETIMEDOUT; 1633 - done: 1634 - mutex_unlock(&dev->phy_mutex); 1635 + exit_unlock: 1636 + mutex_unlock(&dev->mdiobus_mutex); 1635 1637 1636 1638 return ret; 1637 1639 } ··· 1857 1859 1858 1860 ret = lan78xx_read_reg(dev, USB_CFG0, &buf); 1859 1861 if (unlikely(ret < 0)) { 1862 + netdev_warn(dev->net, "failed to get WoL %pe", ERR_PTR(ret)); 1860 1863 wol->supported = 0; 1861 1864 wol->wolopts = 0; 1862 1865 } else { ··· 1889 1890 1890 1891 pdata->wol = wol->wolopts; 1891 1892 1892 - device_set_wakeup_enable(&dev->udev->dev, (bool)wol->wolopts); 1893 + ret = device_set_wakeup_enable(&dev->udev->dev, (bool)wol->wolopts); 1894 + if (ret < 0) 1895 + goto exit_pm_put; 1893 1896 1894 - phy_ethtool_set_wol(netdev->phydev, wol); 1897 + ret = phy_ethtool_set_wol(netdev->phydev, wol); 1895 1898 1899 + exit_pm_put: 1896 1900 usb_autopm_put_interface(dev->intf); 1897 1901 1898 1902 return ret; ··· 2100 2098 2101 2099 static int lan78xx_get_regs_len(struct net_device *netdev) 2102 2100 { 2103 - if (!netdev->phydev) 2104 - return (sizeof(lan78xx_regs)); 2105 - else 2106 - return (sizeof(lan78xx_regs) + PHY_REG_SIZE); 2101 + return sizeof(lan78xx_regs); 2107 2102 } 2108 2103 2109 2104 static void 2110 2105 lan78xx_get_regs(struct net_device *netdev, struct ethtool_regs *regs, 2111 2106 void *buf) 2112 2107 { 2113 - u32 *data = buf; 2114 - int i, j; 2115 2108 struct lan78xx_net *dev = netdev_priv(netdev); 2109 + unsigned int data_count = 0; 2110 + u32 *data = buf; 2111 + int i, ret; 2116 2112 2117 2113 /* Read Device/MAC registers */ 2118 - for (i = 0; i < ARRAY_SIZE(lan78xx_regs); i++) 2119 - lan78xx_read_reg(dev, lan78xx_regs[i], &data[i]); 2114 + for (i = 0; i < ARRAY_SIZE(lan78xx_regs); i++) { 2115 + ret = lan78xx_read_reg(dev, lan78xx_regs[i], &data[i]); 2116 + if (ret < 0) { 2117 + netdev_warn(dev->net, 2118 + "failed to read register 0x%08x\n", 2119 + lan78xx_regs[i]); 2120 + goto clean_data; 2121 + } 2120 2122 2121 - if (!netdev->phydev) 2122 - return; 2123 + data_count++; 2124 + } 2123 2125 2124 - /* Read PHY registers */ 2125 - for (j = 0; j < 32; i++, j++) 2126 - data[i] = phy_read(netdev->phydev, j); 2126 + return; 2127 + 2128 + clean_data: 2129 + memset(data, 0, data_count * sizeof(u32)); 2127 2130 } 2128 2131 2129 2132 static const struct ethtool_ops lan78xx_ethtool_ops = { ··· 2234 2227 if (ret < 0) 2235 2228 return ret; 2236 2229 2237 - mutex_lock(&dev->phy_mutex); 2230 + mutex_lock(&dev->mdiobus_mutex); 2238 2231 2239 2232 /* confirm MII not busy */ 2240 2233 ret = lan78xx_mdiobus_wait_not_busy(dev); ··· 2258 2251 ret = (int)(val & 0xFFFF); 2259 2252 2260 2253 done: 2261 - mutex_unlock(&dev->phy_mutex); 2254 + mutex_unlock(&dev->mdiobus_mutex); 2262 2255 usb_autopm_put_interface(dev->intf); 2263 2256 2264 2257 return ret; ··· 2275 2268 if (ret < 0) 2276 2269 return ret; 2277 2270 2278 - mutex_lock(&dev->phy_mutex); 2271 + mutex_lock(&dev->mdiobus_mutex); 2279 2272 2280 2273 /* confirm MII not busy */ 2281 2274 ret = lan78xx_mdiobus_wait_not_busy(dev); ··· 2298 2291 goto done; 2299 2292 2300 2293 done: 2301 - mutex_unlock(&dev->phy_mutex); 2294 + mutex_unlock(&dev->mdiobus_mutex); 2302 2295 usb_autopm_put_interface(dev->intf); 2303 2296 return ret; 2304 2297 } ··· 4461 4454 skb_queue_head_init(&dev->rxq_done); 4462 4455 skb_queue_head_init(&dev->txq_pend); 4463 4456 skb_queue_head_init(&dev->rxq_overflow); 4464 - mutex_init(&dev->phy_mutex); 4457 + mutex_init(&dev->mdiobus_mutex); 4465 4458 mutex_init(&dev->dev_mutex); 4466 4459 4467 4460 ret = lan78xx_urb_config_init(dev);