--- zzzz-none-000/linux-3.10.107/drivers/net/ethernet/smsc/smsc9420.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/net/ethernet/smsc/smsc9420.c 2021-02-04 17:41:59.000000000 +0000 @@ -13,12 +13,13 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with this program; if not, see . * *************************************************************************** */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -33,7 +34,6 @@ #include "smsc9420.h" #define DRV_NAME "smsc9420" -#define PFX DRV_NAME ": " #define DRV_MDIONAME "smsc9420-mdio" #define DRV_DESCRIPTION "SMSC LAN9420 driver" #define DRV_VERSION "1.01" @@ -83,7 +83,7 @@ int last_carrier; }; -static DEFINE_PCI_DEVICE_TABLE(smsc9420_id_table) = { +static const struct pci_device_id smsc9420_id_table[] = { { PCI_VENDOR_ID_9420, PCI_DEVICE_ID_9420, PCI_ANY_ID, PCI_ANY_ID, }, { 0, } }; @@ -97,21 +97,6 @@ module_param(debug, uint, 0); MODULE_PARM_DESC(debug, "debug level"); -#define smsc_dbg(TYPE, f, a...) \ -do { if ((pd)->msg_enable & NETIF_MSG_##TYPE) \ - printk(KERN_DEBUG PFX f "\n", ## a); \ -} while (0) - -#define smsc_info(TYPE, f, a...) \ -do { if ((pd)->msg_enable & NETIF_MSG_##TYPE) \ - printk(KERN_INFO PFX f "\n", ## a); \ -} while (0) - -#define smsc_warn(TYPE, f, a...) \ -do { if ((pd)->msg_enable & NETIF_MSG_##TYPE) \ - printk(KERN_WARNING PFX f "\n", ## a); \ -} while (0) - static inline u32 smsc9420_reg_read(struct smsc9420_pdata *pd, u32 offset) { return ioread32(pd->ioaddr + offset); @@ -140,7 +125,7 @@ /* confirm MII not busy */ if ((smsc9420_reg_read(pd, MII_ACCESS) & MII_ACCESS_MII_BUSY_)) { - smsc_warn(DRV, "MII is busy???"); + netif_warn(pd, drv, pd->dev, "MII is busy???\n"); goto out; } @@ -159,7 +144,7 @@ udelay(10); } - smsc_warn(DRV, "MII busy timeout!"); + netif_warn(pd, drv, pd->dev, "MII busy timeout!\n"); out: spin_unlock_irqrestore(&pd->phy_lock, flags); @@ -178,7 +163,7 @@ /* confirm MII not busy */ if ((smsc9420_reg_read(pd, MII_ACCESS) & MII_ACCESS_MII_BUSY_)) { - smsc_warn(DRV, "MII is busy???"); + netif_warn(pd, drv, pd->dev, "MII is busy???\n"); goto out; } @@ -200,7 +185,7 @@ udelay(10); } - smsc_warn(DRV, "MII busy timeout!"); + netif_warn(pd, drv, pd->dev, "MII busy timeout!\n"); out: spin_unlock_irqrestore(&pd->phy_lock, flags); @@ -222,7 +207,7 @@ BUG_ON(!pd); if (smsc9420_reg_read(pd, E2P_CMD) & E2P_CMD_EPC_BUSY_) { - smsc_dbg(DRV, "smsc9420_eeprom_reload: Eeprom busy"); + netif_dbg(pd, drv, pd->dev, "%s: Eeprom busy\n", __func__); return -EIO; } @@ -235,7 +220,7 @@ return 0; } while (timeout--); - smsc_warn(DRV, "smsc9420_eeprom_reload: Eeprom timed out"); + netif_warn(pd, drv, pd->dev, "%s: Eeprom timed out\n", __func__); return -EIO; } @@ -347,9 +332,9 @@ int timeout = 100; u32 e2cmd; - smsc_dbg(HW, "op 0x%08x", op); + netif_dbg(pd, hw, pd->dev, "op 0x%08x\n", op); if (smsc9420_reg_read(pd, E2P_CMD) & E2P_CMD_EPC_BUSY_) { - smsc_warn(HW, "Busy at start"); + netif_warn(pd, hw, pd->dev, "Busy at start\n"); return -EBUSY; } @@ -362,12 +347,13 @@ } while ((e2cmd & E2P_CMD_EPC_BUSY_) && (--timeout)); if (!timeout) { - smsc_info(HW, "TIMED OUT"); + netif_info(pd, hw, pd->dev, "TIMED OUT\n"); return -EAGAIN; } if (e2cmd & E2P_CMD_EPC_TIMEOUT_) { - smsc_info(HW, "Error occurred during eeprom operation"); + netif_info(pd, hw, pd->dev, + "Error occurred during eeprom operation\n"); return -EINVAL; } @@ -380,7 +366,7 @@ u32 op = E2P_CMD_EPC_CMD_READ_ | address; int ret; - smsc_dbg(HW, "address 0x%x", address); + netif_dbg(pd, hw, pd->dev, "address 0x%x\n", address); ret = smsc9420_eeprom_send_cmd(pd, op); if (!ret) @@ -395,7 +381,7 @@ u32 op = E2P_CMD_EPC_CMD_ERASE_ | address; int ret; - smsc_dbg(HW, "address 0x%x, data 0x%x", address, data); + netif_dbg(pd, hw, pd->dev, "address 0x%x, data 0x%x\n", address, data); ret = smsc9420_eeprom_send_cmd(pd, op); if (!ret) { @@ -492,7 +478,8 @@ /* Check if mac address has been specified when bringing interface up */ if (is_valid_ether_addr(dev->dev_addr)) { smsc9420_set_mac_address(dev); - smsc_dbg(PROBE, "MAC Address is specified by configuration"); + netif_dbg(pd, probe, pd->dev, + "MAC Address is specified by configuration\n"); } else { /* Try reading mac address from device. if EEPROM is present * it will already have been set */ @@ -507,12 +494,14 @@ if (is_valid_ether_addr(dev->dev_addr)) { /* eeprom values are valid so use them */ - smsc_dbg(PROBE, "Mac Address is read from EEPROM"); + netif_dbg(pd, probe, pd->dev, + "Mac Address is read from EEPROM\n"); } else { /* eeprom values are invalid, generate random MAC */ eth_hw_addr_random(dev); smsc9420_set_mac_address(dev); - smsc_dbg(PROBE, "MAC Address is set to random"); + netif_dbg(pd, probe, pd->dev, + "MAC Address is set to random\n"); } } } @@ -535,7 +524,7 @@ } if (!timeout) - smsc_warn(IFDOWN, "TX DMAC failed to stop"); + netif_warn(pd, ifdown, pd->dev, "TX DMAC failed to stop\n"); /* ACK Tx DMAC stop bit */ smsc9420_reg_write(pd, DMAC_STATUS, DMAC_STS_TXPS_); @@ -646,7 +635,8 @@ } if (!timeout) - smsc_warn(IFDOWN, "RX DMAC did not stop! timeout."); + netif_warn(pd, ifdown, pd->dev, + "RX DMAC did not stop! timeout\n"); /* ACK the Rx DMAC stop bit */ smsc9420_reg_write(pd, DMAC_STATUS, DMAC_STS_RXPS_); @@ -736,7 +726,7 @@ smsc9420_reg_read(pd, BUS_MODE); udelay(2); if (smsc9420_reg_read(pd, BUS_MODE) & BUS_MODE_SWR_) - smsc_warn(DRV, "Software reset not cleared"); + netif_warn(pd, drv, pd->dev, "Software reset not cleared\n"); } static int smsc9420_stop(struct net_device *dev) @@ -855,7 +845,7 @@ PKT_BUF_SZ, PCI_DMA_FROMDEVICE); if (pci_dma_mapping_error(pd->pdev, mapping)) { dev_kfree_skb_any(skb); - smsc_warn(RX_ERR, "pci_map_single failed!"); + netif_warn(pd, rx_err, pd->dev, "pci_map_single failed!\n"); return -ENOMEM; } @@ -1004,7 +994,8 @@ mapping = pci_map_single(pd->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); if (pci_dma_mapping_error(pd->pdev, mapping)) { - smsc_warn(TX_ERR, "pci_map_single failed, dropping packet"); + netif_warn(pd, tx_err, pd->dev, + "pci_map_single failed, dropping packet\n"); return NETDEV_TX_BUSY; } @@ -1056,12 +1047,12 @@ u32 mac_cr = smsc9420_reg_read(pd, MAC_CR); if (dev->flags & IFF_PROMISC) { - smsc_dbg(HW, "Promiscuous Mode Enabled"); + netif_dbg(pd, hw, pd->dev, "Promiscuous Mode Enabled\n"); mac_cr |= MAC_CR_PRMS_; mac_cr &= (~MAC_CR_MCPAS_); mac_cr &= (~MAC_CR_HPFILT_); } else if (dev->flags & IFF_ALLMULTI) { - smsc_dbg(HW, "Receive all Multicast Enabled"); + netif_dbg(pd, hw, pd->dev, "Receive all Multicast Enabled\n"); mac_cr &= (~MAC_CR_PRMS_); mac_cr |= MAC_CR_MCPAS_; mac_cr &= (~MAC_CR_HPFILT_); @@ -1069,7 +1060,7 @@ struct netdev_hw_addr *ha; u32 hash_lo = 0, hash_hi = 0; - smsc_dbg(HW, "Multicast filter enabled"); + netif_dbg(pd, hw, pd->dev, "Multicast filter enabled\n"); netdev_for_each_mc_addr(ha, dev) { u32 bit_num = smsc9420_hash(ha->addr); u32 mask = 1 << (bit_num & 0x1F); @@ -1087,7 +1078,7 @@ mac_cr &= (~MAC_CR_MCPAS_); mac_cr |= MAC_CR_HPFILT_; } else { - smsc_dbg(HW, "Receive own packets only."); + netif_dbg(pd, hw, pd->dev, "Receive own packets only\n"); smsc9420_reg_write(pd, HASHH, 0); smsc9420_reg_write(pd, HASHL, 0); @@ -1115,11 +1106,11 @@ else flow = 0; - smsc_info(LINK, "rx pause %s, tx pause %s", - (cap & FLOW_CTRL_RX ? "enabled" : "disabled"), - (cap & FLOW_CTRL_TX ? "enabled" : "disabled")); + netif_info(pd, link, pd->dev, "rx pause %s, tx pause %s\n", + cap & FLOW_CTRL_RX ? "enabled" : "disabled", + cap & FLOW_CTRL_TX ? "enabled" : "disabled"); } else { - smsc_info(LINK, "half duplex"); + netif_info(pd, link, pd->dev, "half duplex\n"); flow = 0; } @@ -1137,10 +1128,10 @@ if (phy_dev->duplex != pd->last_duplex) { u32 mac_cr = smsc9420_reg_read(pd, MAC_CR); if (phy_dev->duplex) { - smsc_dbg(LINK, "full duplex mode"); + netif_dbg(pd, link, pd->dev, "full duplex mode\n"); mac_cr |= MAC_CR_FDPX_; } else { - smsc_dbg(LINK, "half duplex mode"); + netif_dbg(pd, link, pd->dev, "half duplex mode\n"); mac_cr &= ~MAC_CR_FDPX_; } smsc9420_reg_write(pd, MAC_CR, mac_cr); @@ -1152,9 +1143,9 @@ carrier = netif_carrier_ok(dev); if (carrier != pd->last_carrier) { if (carrier) - smsc_dbg(LINK, "carrier OK"); + netif_dbg(pd, link, pd->dev, "carrier OK\n"); else - smsc_dbg(LINK, "no carrier"); + netif_dbg(pd, link, pd->dev, "no carrier\n"); pd->last_carrier = carrier; } } @@ -1168,24 +1159,24 @@ /* Device only supports internal PHY at address 1 */ if (!pd->mii_bus->phy_map[1]) { - pr_err("%s: no PHY found at address 1\n", dev->name); + netdev_err(dev, "no PHY found at address 1\n"); return -ENODEV; } phydev = pd->mii_bus->phy_map[1]; - smsc_info(PROBE, "PHY addr %d, phy_id 0x%08X", phydev->addr, - phydev->phy_id); + netif_info(pd, probe, pd->dev, "PHY addr %d, phy_id 0x%08X\n", + phydev->addr, phydev->phy_id); phydev = phy_connect(dev, dev_name(&phydev->dev), smsc9420_phy_adjust_link, PHY_INTERFACE_MODE_MII); if (IS_ERR(phydev)) { - pr_err("%s: Could not attach to PHY\n", dev->name); + netdev_err(dev, "Could not attach to PHY\n"); return PTR_ERR(phydev); } - pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", - dev->name, phydev->drv->name, dev_name(&phydev->dev), phydev->irq); + netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", + phydev->drv->name, dev_name(&phydev->dev), phydev->irq); /* mask with MAC supported features */ phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause | @@ -1223,12 +1214,12 @@ pd->mii_bus->phy_mask = ~(1 << 1); if (mdiobus_register(pd->mii_bus)) { - smsc_warn(PROBE, "Error registering mii bus"); + netif_warn(pd, probe, pd->dev, "Error registering mii bus\n"); goto err_out_free_bus_2; } if (smsc9420_mii_probe(dev) < 0) { - smsc_warn(PROBE, "Error probing mii bus"); + netif_warn(pd, probe, pd->dev, "Error probing mii bus\n"); goto err_out_unregister_bus_3; } @@ -1281,12 +1272,11 @@ BUG_ON(!pd->rx_ring); - pd->rx_buffers = kmalloc((sizeof(struct smsc9420_ring_info) * - RX_RING_SIZE), GFP_KERNEL); - if (pd->rx_buffers == NULL) { - smsc_warn(IFUP, "Failed to allocated rx_buffers"); + pd->rx_buffers = kmalloc_array(RX_RING_SIZE, + sizeof(struct smsc9420_ring_info), + GFP_KERNEL); + if (pd->rx_buffers == NULL) goto out; - } /* initialize the rx ring */ for (i = 0; i < RX_RING_SIZE; i++) { @@ -1301,7 +1291,8 @@ /* now allocate the entire ring of skbs */ for (i = 0; i < RX_RING_SIZE; i++) { if (smsc9420_alloc_rx_buffer(pd, i)) { - smsc_warn(IFUP, "failed to allocate rx skb %d", i); + netif_warn(pd, ifup, pd->dev, + "failed to allocate rx skb %d\n", i); goto out_free_rx_skbs; } } @@ -1310,13 +1301,14 @@ pd->rx_ring_tail = 0; smsc9420_reg_write(pd, VLAN1, ETH_P_8021Q); - smsc_dbg(IFUP, "VLAN1 = 0x%08x", smsc9420_reg_read(pd, VLAN1)); + netif_dbg(pd, ifup, pd->dev, "VLAN1 = 0x%08x\n", + smsc9420_reg_read(pd, VLAN1)); if (pd->rx_csum) { /* Enable RX COE */ u32 coe = smsc9420_reg_read(pd, COE_CR) | RX_COE_EN; smsc9420_reg_write(pd, COE_CR, coe); - smsc_dbg(IFUP, "COE_CR = 0x%08x", coe); + netif_dbg(pd, ifup, pd->dev, "COE_CR = 0x%08x\n", coe); } smsc9420_reg_write(pd, RX_BASE_ADDR, pd->rx_dma_addr); @@ -1339,7 +1331,8 @@ int result = 0, timeout; if (!is_valid_ether_addr(dev->dev_addr)) { - smsc_warn(IFUP, "dev_addr is not a valid MAC address"); + netif_warn(pd, ifup, pd->dev, + "dev_addr is not a valid MAC address\n"); result = -EADDRNOTAVAIL; goto out_0; } @@ -1356,10 +1349,9 @@ smsc9420_reg_write(pd, INT_STAT, 0xFFFFFFFF); smsc9420_pci_flush_write(pd); - result = request_irq(irq, smsc9420_isr, IRQF_SHARED | IRQF_DISABLED, - DRV_NAME, pd); + result = request_irq(irq, smsc9420_isr, IRQF_SHARED, DRV_NAME, pd); if (result) { - smsc_warn(IFUP, "Unable to use IRQ = %d", irq); + netif_warn(pd, ifup, pd->dev, "Unable to use IRQ = %d\n", irq); result = -ENODEV; goto out_0; } @@ -1394,7 +1386,7 @@ smsc9420_pci_flush_write(pd); /* test the IRQ connection to the ISR */ - smsc_dbg(IFUP, "Testing ISR using IRQ %d", irq); + netif_dbg(pd, ifup, pd->dev, "Testing ISR using IRQ %d\n", irq); pd->software_irq_signal = false; spin_lock_irqsave(&pd->int_lock, flags); @@ -1424,30 +1416,32 @@ spin_unlock_irqrestore(&pd->int_lock, flags); if (!pd->software_irq_signal) { - smsc_warn(IFUP, "ISR failed signaling test"); + netif_warn(pd, ifup, pd->dev, "ISR failed signaling test\n"); result = -ENODEV; goto out_free_irq_1; } - smsc_dbg(IFUP, "ISR passed test using IRQ %d", irq); + netif_dbg(pd, ifup, pd->dev, "ISR passed test using IRQ %d\n", irq); result = smsc9420_alloc_tx_ring(pd); if (result) { - smsc_warn(IFUP, "Failed to Initialize tx dma ring"); + netif_warn(pd, ifup, pd->dev, + "Failed to Initialize tx dma ring\n"); result = -ENOMEM; goto out_free_irq_1; } result = smsc9420_alloc_rx_ring(pd); if (result) { - smsc_warn(IFUP, "Failed to Initialize rx dma ring"); + netif_warn(pd, ifup, pd->dev, + "Failed to Initialize rx dma ring\n"); result = -ENOMEM; goto out_free_tx_ring_2; } result = smsc9420_mii_init(dev); if (result) { - smsc_warn(IFUP, "Failed to initialize Phy"); + netif_warn(pd, ifup, pd->dev, "Failed to initialize Phy\n"); result = -ENODEV; goto out_free_rx_ring_3; } @@ -1546,9 +1540,10 @@ pci_set_master(pdev); - err = pci_enable_wake(pdev, 0, 0); + err = pci_enable_wake(pdev, PCI_D0, 0); if (err) - smsc_warn(IFUP, "pci_enable_wake failed: %d", err); + netif_warn(pd, ifup, pd->dev, "pci_enable_wake failed: %d\n", + err); if (netif_running(dev)) { /* FIXME: gross. It looks like ancient PM relic.*/ @@ -1583,12 +1578,12 @@ int result = 0; u32 id_rev; - printk(KERN_INFO DRV_DESCRIPTION " version " DRV_VERSION "\n"); + pr_info("%s version %s\n", DRV_DESCRIPTION, DRV_VERSION); /* First do the PCI initialisation */ result = pci_enable_device(pdev); if (unlikely(result)) { - printk(KERN_ERR "Cannot enable smsc9420\n"); + pr_err("Cannot enable smsc9420\n"); goto out_0; } @@ -1601,24 +1596,24 @@ SET_NETDEV_DEV(dev, &pdev->dev); if (!(pci_resource_flags(pdev, SMSC_BAR) & IORESOURCE_MEM)) { - printk(KERN_ERR "Cannot find PCI device base address\n"); + netdev_err(dev, "Cannot find PCI device base address\n"); goto out_free_netdev_2; } if ((pci_request_regions(pdev, DRV_NAME))) { - printk(KERN_ERR "Cannot obtain PCI resources, aborting.\n"); + netdev_err(dev, "Cannot obtain PCI resources, aborting\n"); goto out_free_netdev_2; } if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { - printk(KERN_ERR "No usable DMA configuration, aborting.\n"); + netdev_err(dev, "No usable DMA configuration, aborting\n"); goto out_free_regions_3; } virt_addr = ioremap(pci_resource_start(pdev, SMSC_BAR), pci_resource_len(pdev, SMSC_BAR)); if (!virt_addr) { - printk(KERN_ERR "Cannot map device registers, aborting.\n"); + netdev_err(dev, "Cannot map device registers, aborting\n"); goto out_free_regions_3; } @@ -1647,16 +1642,17 @@ pd->msg_enable = smsc_debug; pd->rx_csum = true; - smsc_dbg(PROBE, "lan_base=0x%08lx", (ulong)virt_addr); + netif_dbg(pd, probe, pd->dev, "lan_base=0x%08lx\n", (ulong)virt_addr); id_rev = smsc9420_reg_read(pd, ID_REV); switch (id_rev & 0xFFFF0000) { case 0x94200000: - smsc_info(PROBE, "LAN9420 identified, ID_REV=0x%08X", id_rev); + netif_info(pd, probe, pd->dev, + "LAN9420 identified, ID_REV=0x%08X\n", id_rev); break; default: - smsc_warn(PROBE, "LAN9420 NOT identified"); - smsc_warn(PROBE, "ID_REV=0x%08X", id_rev); + netif_warn(pd, probe, pd->dev, "LAN9420 NOT identified\n"); + netif_warn(pd, probe, pd->dev, "ID_REV=0x%08X\n", id_rev); goto out_free_dmadesc_5; } @@ -1671,7 +1667,8 @@ result = register_netdev(dev); if (result) { - smsc_warn(PROBE, "error %i registering device", result); + netif_warn(pd, probe, pd->dev, "error %i registering device\n", + result); goto out_free_dmadesc_5; } @@ -1708,8 +1705,6 @@ if (!dev) return; - pci_set_drvdata(pdev, NULL); - pd = netdev_priv(dev); unregister_netdev(dev);