An skb allocation failure retries the same completed descriptor forever in hard IRQ context. Return the buffer to DMA and advance the ring even when the packet must be dropped. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index 8682323d693f..cd25248f4e3a 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -788,7 +788,7 @@ static int au1000_rx(struct net_device *dev) skb = netdev_alloc_skb(dev, frmlen + 2); if (!skb) { dev->stats.rx_dropped++; - continue; + goto next; } skb_reserve(skb, 2); /* 16 byte IP header align */ skb_copy_to_linear_data(skb, @@ -820,6 +820,7 @@ static int au1000_rx(struct net_device *dev) pr_cont("\n"); } } +next: prxd->buff_stat = lower_32_bits(pDB->dma_addr) | RX_DMA_ENABLE; aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1); wmb(); /* drain writebuffer */ -- 2.53.0 MAC_PASS_ALL_MULTI remains set after IFF_ALLMULTI is cleared or the multicast list shrinks below the filter limit. Clear it when programming the selective multicast hash so unwanted multicast traffic is filtered again. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index cd25248f4e3a..58bc8e1b539d 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -1042,7 +1042,7 @@ static void au1000_multicast_list(struct net_device *dev) (long *)mc_filter); writel(mc_filter[1], &aup->mac->multi_hash_high); writel(mc_filter[0], &aup->mac->multi_hash_low); - reg &= ~MAC_PROMISCUOUS; + reg &= ~(MAC_PROMISCUOUS | MAC_PASS_ALL_MULTI); reg |= MAC_HASH_MODE; } writel(reg, &aup->mac->control); -- 2.53.0 Balance phy_connect() on probe failure and removal. Otherwise PHY interrupts, device references and the attachment to the freed netdev survive teardown. Disconnect before unregistering the bus while its MDIO callbacks and MAC registers remain usable. Fixes: 0638dec01e89 ("[PATCH] net: au1000_eth: PHY framework conversion") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index 58bc8e1b539d..70319b432182 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -1287,6 +1287,8 @@ static int au1000_probe(struct platform_device *pdev) return 0; err_out: + if (dev->phydev) + phy_disconnect(dev->phydev); if (aup->mii_bus) mdiobus_unregister(aup->mii_bus); @@ -1334,6 +1336,8 @@ static void au1000_remove(struct platform_device *pdev) struct resource *base, *macen; unregister_netdev(dev); + if (dev->phydev) + phy_disconnect(dev->phydev); mdiobus_unregister(aup->mii_bus); mdiobus_free(aup->mii_bus); -- 2.53.0 The MDIO write callback reports success even if the controller stays busy and no write is issued. Propagate timeout errors and wait for write completion so failure of the final transaction is reported to phylib as well. Return ETIMEDOUT for read timeouts too. Fixes: 0638dec01e89 ("[PATCH] net: au1000_eth: PHY framework conversion") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index 70319b432182..a507a524370f 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -278,7 +278,7 @@ static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg) mdelay(1); if (--timedout == 0) { netdev_err(dev, "read_MII busy timeout!!\n"); - return -1; + return -ETIMEDOUT; } } @@ -292,14 +292,14 @@ static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg) mdelay(1); if (--timedout == 0) { netdev_err(dev, "mdio_read busy timeout!!\n"); - return -1; + return -ETIMEDOUT; } } return readl(mii_data_reg); } -static void au1000_mdio_write(struct net_device *dev, int phy_addr, - int reg, u16 value) +static int au1000_mdio_write(struct net_device *dev, int phy_addr, + int reg, u16 value) { struct au1000_private *aup = netdev_priv(dev); u32 *const mii_control_reg = &aup->mac->mii_control; @@ -311,7 +311,7 @@ static void au1000_mdio_write(struct net_device *dev, int phy_addr, mdelay(1); if (--timedout == 0) { netdev_err(dev, "mdio_write busy timeout!!\n"); - return; + return -ETIMEDOUT; } } @@ -320,6 +320,17 @@ static void au1000_mdio_write(struct net_device *dev, int phy_addr, writel(value, mii_data_reg); writel(mii_control, mii_control_reg); + + timedout = 20; + while (readl(mii_control_reg) & MAC_MII_BUSY) { + mdelay(1); + if (--timedout == 0) { + netdev_err(dev, "mdio_write busy timeout!!\n"); + return -ETIMEDOUT; + } + } + + return 0; } static int au1000_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) @@ -344,8 +355,7 @@ static int au1000_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, */ au1000_enable_mac(dev, 0); - au1000_mdio_write(dev, phy_addr, regnum, value); - return 0; + return au1000_mdio_write(dev, phy_addr, regnum, value); } static int au1000_mdiobus_reset(struct mii_bus *bus) -- 2.53.0 TX completion runs in hard IRQ context while ndo_start_xmit updates the same descriptors and ring state without locking. In particular, an interrupt between netif_stop_queue() and setting tx_full can miss the wakeup and leave the queue stopped until the watchdog runs. Use the existing IRQ-safe device lock in both paths to serialize descriptor reclamation and queue state changes. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index a507a524370f..90887dac26bc 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -873,7 +873,9 @@ static void au1000_tx_ack(struct net_device *dev) { struct au1000_private *aup = netdev_priv(dev); struct tx_dma *ptxd; + unsigned long flags; + spin_lock_irqsave(&aup->lock, flags); ptxd = aup->tx_dma_ring[aup->tx_tail]; while (ptxd->buff_stat & TX_T_DONE) { @@ -890,6 +892,8 @@ static void au1000_tx_ack(struct net_device *dev) netif_wake_queue(dev); } } + + spin_unlock_irqrestore(&aup->lock, flags); } /* @@ -973,17 +977,20 @@ static netdev_tx_t au1000_tx(struct sk_buff *skb, struct net_device *dev) u32 buff_stat; struct db_dest *pDB; int i; + unsigned long flags; netif_dbg(aup, tx_queued, dev, "tx: aup %x len=%d, data=%p, head %d\n", (unsigned)aup, skb->len, skb->data, aup->tx_head); + spin_lock_irqsave(&aup->lock, flags); ptxd = aup->tx_dma_ring[aup->tx_head]; buff_stat = ptxd->buff_stat; if (buff_stat & TX_DMA_ENABLE) { /* We've wrapped around and the transmitter is still busy */ netif_stop_queue(dev); aup->tx_full = 1; + spin_unlock_irqrestore(&aup->lock, flags); return NETDEV_TX_BUSY; } else if (buff_stat & TX_T_DONE) { au1000_update_tx_stats(dev, ptxd->status); @@ -1012,6 +1019,7 @@ static netdev_tx_t au1000_tx(struct sk_buff *skb, struct net_device *dev) wmb(); /* drain writebuffer */ dev_kfree_skb(skb); aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1); + spin_unlock_irqrestore(&aup->lock, flags); return NETDEV_TX_OK; } -- 2.53.0 The supported no-platform-data path leaves dev_addr as all zeroes. The device can register but eth_validate_addr() prevents it from opening. Generate a random address just as for platform data containing an invalid address. Fixes: 7718f2c27dbd ("au1000_eth: use eth_hw_addr_random() instead of random_ether_addr()") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index 90887dac26bc..c0e38a507f89 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -1196,6 +1196,7 @@ static int au1000_probe(struct platform_device *pdev) dev_info(&pdev->dev, "no platform_data passed," " PHY search on MAC0\n"); aup->phy1_search_mac0 = 1; + eth_hw_addr_random(dev); } else { if (is_valid_ether_addr(pd->mac)) { eth_hw_addr_set(dev, pd->mac); -- 2.53.0 ReleaseDB links the old head to the returned descriptor and makes the returned descriptor the new head without updating its stale next pointer. This loses free descriptors and can create cycles. Link the returned descriptor to the old head instead, matching GetFreeDB and the list initialization. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index c0e38a507f89..f8976e324f0e 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -583,9 +583,7 @@ static struct db_dest *au1000_GetFreeDB(struct au1000_private *aup) static void au1000_ReleaseDB(struct au1000_private *aup, struct db_dest *pDB) { - struct db_dest *pDBfree = aup->pDBfree; - if (pDBfree) - pDBfree->pnext = pDB; + pDB->pnext = aup->pDBfree; aup->pDBfree = pDB; } -- 2.53.0 MAC initialization overwrites the receive mode, dropping promiscuous and multicast settings after a watchdog reset without notifying the network stack. Reapply the current netdev receive mode after initialization. Protect the control register read-modify-write with the device lock so it cannot overwrite a concurrent link adjustment or MAC stop. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index f8976e324f0e..6b817d18329b 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -684,6 +684,8 @@ static const struct ethtool_ops au1000_ethtool_ops = { .set_link_ksettings = phy_ethtool_set_link_ksettings, }; +static void au1000_multicast_list(struct net_device *dev); + /* * Initialize the interface. * @@ -742,6 +744,9 @@ static int au1000_init(struct net_device *dev) wmb(); /* drain writebuffer */ spin_unlock_irqrestore(&aup->lock, flags); + netif_addr_lock_bh(dev); + au1000_multicast_list(dev); + netif_addr_unlock_bh(dev); return 0; } @@ -1038,8 +1043,10 @@ static void au1000_multicast_list(struct net_device *dev) { struct au1000_private *aup = netdev_priv(dev); u32 reg; + unsigned long flags; netif_dbg(aup, drv, dev, "%s: flags=%x\n", __func__, dev->flags); + spin_lock_irqsave(&aup->lock, flags); reg = readl(&aup->mac->control); if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ reg |= MAC_PROMISCUOUS; @@ -1062,6 +1069,7 @@ static void au1000_multicast_list(struct net_device *dev) reg |= MAC_HASH_MODE; } writel(reg, &aup->mac->control); + spin_unlock_irqrestore(&aup->lock, flags); } static const struct net_device_ops au1000_netdev_ops = { -- 2.53.0 The MAC DMA engine updates each receive descriptor's address as it transfers data. Clearing the descriptor control bits during reset does not restore the buffer's starting address. au1000_init() only set RX_DMA_ENABLE on the address left in the descriptor. After closing and reopening the interface, a receive could therefore start partway through its buffer and overwrite memory beyond the allocation. Reload each RX descriptor from rx_db_inuse before enabling it, as the receive completion path already does. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index 6b817d18329b..8c2dbf72652e 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -722,7 +722,8 @@ static int au1000_init(struct net_device *dev) for (i = 0; i < NUM_RX_DMA; i++) - aup->rx_dma_ring[i]->buff_stat |= RX_DMA_ENABLE; + writel(lower_32_bits(aup->rx_db_inuse[i]->dma_addr) | + RX_DMA_ENABLE, &aup->rx_dma_ring[i]->buff_stat); wmb(); /* drain writebuffer */ -- 2.53.0 phy_stop() powers down the PHY when the interface is closed. The driver leaves MAC receive/transmit enabled on link-down and enables them again during initialization before resuming the PHY. The MTX-1 can hang when the MAC runs while its MII clocks are absent or still recovering. Start the PHY before initializing the MAC, but leave receive/transmit stopped while the PHY reports no link. The duplex update enables them when the link comes up. Stop the MAC in the link-down callback before phylib suspends the PHY, and stop the PHY if MAC initialization fails. Fixes: be9dad1f9f26 ("net: phy: suspend phydev when going to HALTED") Signed-off-by: Florian Fainelli --- drivers/net/ethernet/amd/au1000_eth.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c index 8c2dbf72652e..c616ce616541 100644 --- a/drivers/net/ethernet/amd/au1000_eth.c +++ b/drivers/net/ethernet/amd/au1000_eth.c @@ -458,7 +458,8 @@ au1000_adjust_link(struct net_device *dev) /* link state changed */ if (!phydev->link) { - /* link went down */ + /* Stop the MAC before the PHY can remove its clocks. */ + au1000_hard_stop(dev); aup->old_speed = 0; aup->old_duplex = -1; } @@ -727,7 +728,7 @@ static int au1000_init(struct net_device *dev) wmb(); /* drain writebuffer */ - control = MAC_RX_ENABLE | MAC_TX_ENABLE; + control = 0; #ifndef CONFIG_CPU_LITTLE_ENDIAN control |= MAC_BIG_ENDIAN; #endif @@ -740,6 +741,10 @@ static int au1000_init(struct net_device *dev) control |= MAC_FULL_DUPLEX; } + /* The PHY may still be restoring its MII clocks after resume. */ + if (!dev->phydev || dev->phydev->link) + control |= MAC_RX_ENABLE | MAC_TX_ENABLE; + writel(control, &aup->mac->control); writel(0x8100, &aup->mac->vlan1_tag); /* activate vlan support */ wmb(); /* drain writebuffer */ @@ -928,16 +933,18 @@ static int au1000_open(struct net_device *dev) return retval; } + if (dev->phydev) + phy_start(dev->phydev); + retval = au1000_init(dev); if (retval) { netdev_err(dev, "error in au1000_init\n"); + if (dev->phydev) + phy_stop(dev->phydev); free_irq(dev->irq, dev); return retval; } - if (dev->phydev) - phy_start(dev->phydev); - netif_start_queue(dev); netif_dbg(aup, drv, dev, "open: Initialization done.\n"); -- 2.53.0 The LAN83C183 uses the generic PHY driver, which returns immediately after clearing BMCR_PDOWN. Section 1.11 of the datasheet allows 500 ms before normal operation is restored. Starting the Au1000 MAC before the MII clocks recover can hang the MTX-1 when reopening its interface. Add a LAN83C183 driver entry and resume callback. Wait for recovery only when BMCR_PDOWN was actually cleared, and propagate MDIO errors without waiting. Resuming an already awake PHY does not incur the delay. Fixes: be9dad1f9f26 ("net: phy: suspend phydev when going to HALTED") Link: https://pdf.dzsc.com/LAN/LAN83C183.pdf#page=44 Signed-off-by: Florian Fainelli --- drivers/net/phy/Kconfig | 2 +- drivers/net/phy/smsc.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 30e9d22c8d1a..10466b2574eb 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -421,7 +421,7 @@ config SMSC_PHY tristate "SMSC PHYs" select CRC16 help - Currently supports the LAN83C185, LAN8187 and LAN8700 PHYs + Currently supports the LAN83C183, LAN83C185, LAN8187 and LAN8700 PHYs config STE10XP tristate "STMicroelectronics STe10Xp PHYs" diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c index 48487149c225..c3b51afd4b1e 100644 --- a/drivers/net/phy/smsc.c +++ b/drivers/net/phy/smsc.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -684,8 +685,32 @@ int smsc_phy_probe(struct phy_device *phydev) } EXPORT_SYMBOL_GPL(smsc_phy_probe); +static int lan83c183_resume(struct phy_device *phydev) +{ + int ret; + + ret = phy_modify_changed(phydev, MII_BMCR, BMCR_PDOWN, 0); + if (ret < 0) + return ret; + + /* The PHY needs up to 500 ms to restore operation after power-down. */ + if (ret) + msleep(500); + + return 0; +} + static struct phy_driver smsc_phy_driver[] = { { + .phy_id = 0x0016f840, + .phy_id_mask = 0xfffffff0, + .name = "SMSC LAN83C183", + + .get_features = genphy_read_abilities, + .suspend = genphy_suspend, + .resume = lan83c183_resume, + .set_loopback = genphy_loopback, +}, { .phy_id = 0x0007c0a0, /* OUI=0x00800f, Model#=0x0a */ .phy_id_mask = 0xfffffff0, .name = "SMSC LAN83C185", @@ -887,6 +912,7 @@ MODULE_AUTHOR("Herbert Valerio Riedel"); MODULE_LICENSE("GPL"); static const struct mdio_device_id __maybe_unused smsc_tbl[] = { + { 0x0016f840, 0xfffffff0 }, { 0x0007c0a0, 0xfffffff0 }, { 0x0007c0b0, 0xfffffff0 }, { 0x0007c0c0, 0xfffffff0 }, -- 2.53.0