11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 22f7ca802SSteve Glendinning /*************************************************************************** 32f7ca802SSteve Glendinning * 42f7ca802SSteve Glendinning * Copyright (C) 2007-2008 SMSC 52f7ca802SSteve Glendinning * 62f7ca802SSteve Glendinning *****************************************************************************/ 72f7ca802SSteve Glendinning 82f7ca802SSteve Glendinning #include <linux/module.h> 92f7ca802SSteve Glendinning #include <linux/kmod.h> 102f7ca802SSteve Glendinning #include <linux/netdevice.h> 112f7ca802SSteve Glendinning #include <linux/etherdevice.h> 122f7ca802SSteve Glendinning #include <linux/ethtool.h> 132f7ca802SSteve Glendinning #include <linux/mii.h> 142f7ca802SSteve Glendinning #include <linux/usb.h> 15bbd9f9eeSSteve Glendinning #include <linux/bitrev.h> 16bbd9f9eeSSteve Glendinning #include <linux/crc16.h> 172f7ca802SSteve Glendinning #include <linux/crc32.h> 182f7ca802SSteve Glendinning #include <linux/usb/usbnet.h> 195a0e3ad6STejun Heo #include <linux/slab.h> 20c489565bSArnd Bergmann #include <linux/of_net.h> 211ce8b372SLukas Wunner #include <linux/irq.h> 221ce8b372SLukas Wunner #include <linux/irqdomain.h> 2305b35e7eSAndre Edich #include <linux/mdio.h> 2405b35e7eSAndre Edich #include <linux/phy.h> 251710b52dSOleksij Rempel #include <net/selftests.h> 261710b52dSOleksij Rempel 272f7ca802SSteve Glendinning #include "smsc95xx.h" 282f7ca802SSteve Glendinning 292f7ca802SSteve Glendinning #define SMSC_CHIPNAME "smsc95xx" 3005b35e7eSAndre Edich #define SMSC_DRIVER_VERSION "2.0.0" 312f7ca802SSteve Glendinning #define HS_USB_PKT_SIZE (512) 322f7ca802SSteve Glendinning #define FS_USB_PKT_SIZE (64) 332f7ca802SSteve Glendinning #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) 342f7ca802SSteve Glendinning #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) 352f7ca802SSteve Glendinning #define DEFAULT_BULK_IN_DELAY (0x00002000) 362f7ca802SSteve Glendinning #define MAX_SINGLE_PACKET_SIZE (2048) 372f7ca802SSteve Glendinning #define LAN95XX_EEPROM_MAGIC (0x9500) 382f7ca802SSteve Glendinning #define EEPROM_MAC_OFFSET (0x01) 39f7b29271SSteve Glendinning #define DEFAULT_TX_CSUM_ENABLE (true) 402f7ca802SSteve Glendinning #define DEFAULT_RX_CSUM_ENABLE (true) 412f7ca802SSteve Glendinning #define SMSC95XX_INTERNAL_PHY_ID (1) 422f7ca802SSteve Glendinning #define SMSC95XX_TX_OVERHEAD (8) 43f7b29271SSteve Glendinning #define SMSC95XX_TX_OVERHEAD_CSUM (12) 44e5e3af83SSteve Glendinning #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \ 45bbd9f9eeSSteve Glendinning WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) 462f7ca802SSteve Glendinning 479ebca507SSteve Glendinning #define FEATURE_8_WAKEUP_FILTERS (0x01) 489ebca507SSteve Glendinning #define FEATURE_PHY_NLP_CROSSOVER (0x02) 49eb970ff0SMing Lei #define FEATURE_REMOTE_WAKEUP (0x04) 509ebca507SSteve Glendinning 51b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND0 (0x01) 52b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND1 (0x02) 53b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND2 (0x04) 54b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND3 (0x08) 55b2d4b150SSteve Glendinning #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ 56b2d4b150SSteve Glendinning SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) 57b2d4b150SSteve Glendinning 581ce8b372SLukas Wunner #define SMSC95XX_NR_IRQS (1) /* raise to 12 for GPIOs */ 591ce8b372SLukas Wunner #define PHY_HWIRQ (SMSC95XX_NR_IRQS - 1) 601ce8b372SLukas Wunner 612f7ca802SSteve Glendinning struct smsc95xx_priv { 622f7ca802SSteve Glendinning u32 mac_cr; 633c0f3c60SMarc Zyngier u32 hash_hi; 643c0f3c60SMarc Zyngier u32 hash_lo; 65e0e474a8SSteve Glendinning u32 wolopts; 662f7ca802SSteve Glendinning spinlock_t mac_cr_lock; 679ebca507SSteve Glendinning u8 features; 68b2d4b150SSteve Glendinning u8 suspend_flags; 69809ff97aSAlexandru Tachici bool is_internal_phy; 701ce8b372SLukas Wunner struct irq_chip irqchip; 711ce8b372SLukas Wunner struct irq_domain *irqdomain; 721ce8b372SLukas Wunner struct fwnode_handle *irqfwnode; 7305b35e7eSAndre Edich struct mii_bus *mdiobus; 7405b35e7eSAndre Edich struct phy_device *phydev; 757b960c96SLukas Wunner struct task_struct *pm_task; 762f7ca802SSteve Glendinning }; 772f7ca802SSteve Glendinning 78eb939922SRusty Russell static bool turbo_mode = true; 792f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644); 802f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); 812f7ca802SSteve Glendinning 8231472429SLukas Wunner static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, 8331472429SLukas Wunner u32 *data) 842f7ca802SSteve Glendinning { 857b960c96SLukas Wunner struct smsc95xx_priv *pdata = dev->driver_priv; 8672108fd2SMing Lei u32 buf; 872f7ca802SSteve Glendinning int ret; 88ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 892f7ca802SSteve Glendinning 907b960c96SLukas Wunner if (current != pdata->pm_task) 91ec32115dSMing Lei fn = usbnet_read_cmd; 92ec32115dSMing Lei else 93ec32115dSMing Lei fn = usbnet_read_cmd_nopm; 94ec32115dSMing Lei 95ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN 96ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 9772108fd2SMing Lei 0, index, &buf, 4); 9851a32e82SShigeru Yoshida if (ret < 4) { 9951a32e82SShigeru Yoshida ret = ret < 0 ? ret : -ENODATA; 10051a32e82SShigeru Yoshida 101c70c453aSFabio Estevam if (ret != -ENODEV) 1021e1d7412SJoe Perches netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", 1031e1d7412SJoe Perches index, ret); 1045a36b68bSDan Carpenter return ret; 1055a36b68bSDan Carpenter } 1062f7ca802SSteve Glendinning 10772108fd2SMing Lei le32_to_cpus(&buf); 10872108fd2SMing Lei *data = buf; 1092f7ca802SSteve Glendinning 1102f7ca802SSteve Glendinning return ret; 1112f7ca802SSteve Glendinning } 1122f7ca802SSteve Glendinning 11331472429SLukas Wunner static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, 11431472429SLukas Wunner u32 data) 1152f7ca802SSteve Glendinning { 1167b960c96SLukas Wunner struct smsc95xx_priv *pdata = dev->driver_priv; 11772108fd2SMing Lei u32 buf; 1182f7ca802SSteve Glendinning int ret; 119ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 1202f7ca802SSteve Glendinning 1217b960c96SLukas Wunner if (current != pdata->pm_task) 122ec32115dSMing Lei fn = usbnet_write_cmd; 123ec32115dSMing Lei else 124ec32115dSMing Lei fn = usbnet_write_cmd_nopm; 125ec32115dSMing Lei 12672108fd2SMing Lei buf = data; 12772108fd2SMing Lei cpu_to_le32s(&buf); 1282f7ca802SSteve Glendinning 129ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT 130ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 13172108fd2SMing Lei 0, index, &buf, 4); 132c70c453aSFabio Estevam if (ret < 0 && ret != -ENODEV) 1331e1d7412SJoe Perches netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n", 1341e1d7412SJoe Perches index, ret); 1352f7ca802SSteve Glendinning 1362f7ca802SSteve Glendinning return ret; 1372f7ca802SSteve Glendinning } 1382f7ca802SSteve Glendinning 1392f7ca802SSteve Glendinning /* Loop until the read is completed with timeout 1402f7ca802SSteve Glendinning * called with phy_mutex held */ 14131472429SLukas Wunner static int __must_check smsc95xx_phy_wait_not_busy(struct usbnet *dev) 1422f7ca802SSteve Glendinning { 1432f7ca802SSteve Glendinning unsigned long start_time = jiffies; 1442f7ca802SSteve Glendinning u32 val; 145769ea6d8SSteve Glendinning int ret; 1462f7ca802SSteve Glendinning 1472f7ca802SSteve Glendinning do { 14831472429SLukas Wunner ret = smsc95xx_read_reg(dev, MII_ADDR, &val); 149b052e073SSteve Glendinning if (ret < 0) { 150c70c453aSFabio Estevam /* Ignore -ENODEV error during disconnect() */ 151c70c453aSFabio Estevam if (ret == -ENODEV) 152c70c453aSFabio Estevam return 0; 153b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading MII_ACCESS\n"); 154b052e073SSteve Glendinning return ret; 155b052e073SSteve Glendinning } 156b052e073SSteve Glendinning 1572f7ca802SSteve Glendinning if (!(val & MII_BUSY_)) 1582f7ca802SSteve Glendinning return 0; 1592f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 1602f7ca802SSteve Glendinning 1612f7ca802SSteve Glendinning return -EIO; 1622f7ca802SSteve Glendinning } 1632f7ca802SSteve Glendinning 16405b35e7eSAndre Edich static u32 mii_address_cmd(int phy_id, int idx, u16 op) 16505b35e7eSAndre Edich { 16605b35e7eSAndre Edich return (phy_id & 0x1f) << 11 | (idx & 0x1f) << 6 | op; 16705b35e7eSAndre Edich } 16805b35e7eSAndre Edich 16931472429SLukas Wunner static int smsc95xx_mdio_read(struct usbnet *dev, int phy_id, int idx) 1702f7ca802SSteve Glendinning { 1712f7ca802SSteve Glendinning u32 val, addr; 172769ea6d8SSteve Glendinning int ret; 1732f7ca802SSteve Glendinning 1742f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 1752f7ca802SSteve Glendinning 1762f7ca802SSteve Glendinning /* confirm MII not busy */ 17731472429SLukas Wunner ret = smsc95xx_phy_wait_not_busy(dev); 178b052e073SSteve Glendinning if (ret < 0) { 17905b35e7eSAndre Edich netdev_warn(dev->net, "%s: MII is busy\n", __func__); 180b052e073SSteve Glendinning goto done; 181b052e073SSteve Glendinning } 1822f7ca802SSteve Glendinning 1832f7ca802SSteve Glendinning /* set the address, index & direction (read from PHY) */ 18405b35e7eSAndre Edich addr = mii_address_cmd(phy_id, idx, MII_READ_ | MII_BUSY_); 18531472429SLukas Wunner ret = smsc95xx_write_reg(dev, MII_ADDR, addr); 186b052e073SSteve Glendinning if (ret < 0) { 187c70c453aSFabio Estevam if (ret != -ENODEV) 188b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_ADDR\n"); 189b052e073SSteve Glendinning goto done; 190b052e073SSteve Glendinning } 1912f7ca802SSteve Glendinning 19231472429SLukas Wunner ret = smsc95xx_phy_wait_not_busy(dev); 193b052e073SSteve Glendinning if (ret < 0) { 194b052e073SSteve Glendinning netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); 195b052e073SSteve Glendinning goto done; 196b052e073SSteve Glendinning } 197769ea6d8SSteve Glendinning 19831472429SLukas Wunner ret = smsc95xx_read_reg(dev, MII_DATA, &val); 199b052e073SSteve Glendinning if (ret < 0) { 200c70c453aSFabio Estevam if (ret != -ENODEV) 201b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading MII_DATA\n"); 202b052e073SSteve Glendinning goto done; 203b052e073SSteve Glendinning } 204769ea6d8SSteve Glendinning 205769ea6d8SSteve Glendinning ret = (u16)(val & 0xFFFF); 206769ea6d8SSteve Glendinning 207769ea6d8SSteve Glendinning done: 2082f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 209c70c453aSFabio Estevam 210c70c453aSFabio Estevam /* Ignore -ENODEV error during disconnect() */ 211c70c453aSFabio Estevam if (ret == -ENODEV) 212c70c453aSFabio Estevam return 0; 213769ea6d8SSteve Glendinning return ret; 2142f7ca802SSteve Glendinning } 2152f7ca802SSteve Glendinning 21631472429SLukas Wunner static void smsc95xx_mdio_write(struct usbnet *dev, int phy_id, int idx, 21731472429SLukas Wunner int regval) 2182f7ca802SSteve Glendinning { 2192f7ca802SSteve Glendinning u32 val, addr; 220769ea6d8SSteve Glendinning int ret; 2212f7ca802SSteve Glendinning 2222f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 2232f7ca802SSteve Glendinning 2242f7ca802SSteve Glendinning /* confirm MII not busy */ 22531472429SLukas Wunner ret = smsc95xx_phy_wait_not_busy(dev); 226b052e073SSteve Glendinning if (ret < 0) { 22705b35e7eSAndre Edich netdev_warn(dev->net, "%s: MII is busy\n", __func__); 228b052e073SSteve Glendinning goto done; 229b052e073SSteve Glendinning } 2302f7ca802SSteve Glendinning 2312f7ca802SSteve Glendinning val = regval; 23231472429SLukas Wunner ret = smsc95xx_write_reg(dev, MII_DATA, val); 233b052e073SSteve Glendinning if (ret < 0) { 234c70c453aSFabio Estevam if (ret != -ENODEV) 235b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_DATA\n"); 236b052e073SSteve Glendinning goto done; 237b052e073SSteve Glendinning } 2382f7ca802SSteve Glendinning 2392f7ca802SSteve Glendinning /* set the address, index & direction (write to PHY) */ 24005b35e7eSAndre Edich addr = mii_address_cmd(phy_id, idx, MII_WRITE_ | MII_BUSY_); 24131472429SLukas Wunner ret = smsc95xx_write_reg(dev, MII_ADDR, addr); 242b052e073SSteve Glendinning if (ret < 0) { 243c70c453aSFabio Estevam if (ret != -ENODEV) 244b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_ADDR\n"); 245b052e073SSteve Glendinning goto done; 246b052e073SSteve Glendinning } 2472f7ca802SSteve Glendinning 24831472429SLukas Wunner ret = smsc95xx_phy_wait_not_busy(dev); 249b052e073SSteve Glendinning if (ret < 0) { 250b052e073SSteve Glendinning netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); 251b052e073SSteve Glendinning goto done; 252b052e073SSteve Glendinning } 2532f7ca802SSteve Glendinning 254769ea6d8SSteve Glendinning done: 2552f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 2562f7ca802SSteve Glendinning } 2572f7ca802SSteve Glendinning 258809ff97aSAlexandru Tachici static int smsc95xx_mdiobus_reset(struct mii_bus *bus) 259809ff97aSAlexandru Tachici { 260809ff97aSAlexandru Tachici struct smsc95xx_priv *pdata; 261809ff97aSAlexandru Tachici struct usbnet *dev; 262809ff97aSAlexandru Tachici u32 val; 263809ff97aSAlexandru Tachici int ret; 264809ff97aSAlexandru Tachici 265809ff97aSAlexandru Tachici dev = bus->priv; 266809ff97aSAlexandru Tachici pdata = dev->driver_priv; 267809ff97aSAlexandru Tachici 268809ff97aSAlexandru Tachici if (pdata->is_internal_phy) 269809ff97aSAlexandru Tachici return 0; 270809ff97aSAlexandru Tachici 271809ff97aSAlexandru Tachici mutex_lock(&dev->phy_mutex); 272809ff97aSAlexandru Tachici 273809ff97aSAlexandru Tachici ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 274809ff97aSAlexandru Tachici if (ret < 0) 275809ff97aSAlexandru Tachici goto reset_out; 276809ff97aSAlexandru Tachici 277809ff97aSAlexandru Tachici val |= PM_CTL_PHY_RST_; 278809ff97aSAlexandru Tachici 279809ff97aSAlexandru Tachici ret = smsc95xx_write_reg(dev, PM_CTRL, val); 280809ff97aSAlexandru Tachici if (ret < 0) 281809ff97aSAlexandru Tachici goto reset_out; 282809ff97aSAlexandru Tachici 283809ff97aSAlexandru Tachici /* Driver has no knowledge at this point about the external PHY. 284809ff97aSAlexandru Tachici * The 802.3 specifies that the reset process shall 285809ff97aSAlexandru Tachici * be completed within 0.5 s. 286809ff97aSAlexandru Tachici */ 287809ff97aSAlexandru Tachici fsleep(500000); 288809ff97aSAlexandru Tachici 289809ff97aSAlexandru Tachici reset_out: 290809ff97aSAlexandru Tachici mutex_unlock(&dev->phy_mutex); 291809ff97aSAlexandru Tachici 292809ff97aSAlexandru Tachici return 0; 293809ff97aSAlexandru Tachici } 294809ff97aSAlexandru Tachici 29505b35e7eSAndre Edich static int smsc95xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx) 296e5e3af83SSteve Glendinning { 29705b35e7eSAndre Edich struct usbnet *dev = bus->priv; 29805b35e7eSAndre Edich 29931472429SLukas Wunner return smsc95xx_mdio_read(dev, phy_id, idx); 300e5e3af83SSteve Glendinning } 301e5e3af83SSteve Glendinning 30205b35e7eSAndre Edich static int smsc95xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx, 30305b35e7eSAndre Edich u16 regval) 304e5e3af83SSteve Glendinning { 30505b35e7eSAndre Edich struct usbnet *dev = bus->priv; 30605b35e7eSAndre Edich 30731472429SLukas Wunner smsc95xx_mdio_write(dev, phy_id, idx, regval); 30805b35e7eSAndre Edich return 0; 309e5e3af83SSteve Glendinning } 310e5e3af83SSteve Glendinning 311769ea6d8SSteve Glendinning static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev) 3122f7ca802SSteve Glendinning { 3132f7ca802SSteve Glendinning unsigned long start_time = jiffies; 3142f7ca802SSteve Glendinning u32 val; 315769ea6d8SSteve Glendinning int ret; 3162f7ca802SSteve Glendinning 3172f7ca802SSteve Glendinning do { 318769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 319b052e073SSteve Glendinning if (ret < 0) { 320b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_CMD\n"); 321b052e073SSteve Glendinning return ret; 322b052e073SSteve Glendinning } 323b052e073SSteve Glendinning 3242f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) 3252f7ca802SSteve Glendinning break; 3262f7ca802SSteve Glendinning udelay(40); 3272f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3282f7ca802SSteve Glendinning 3292f7ca802SSteve Glendinning if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { 33060b86755SJoe Perches netdev_warn(dev->net, "EEPROM read operation timeout\n"); 3312f7ca802SSteve Glendinning return -EIO; 3322f7ca802SSteve Glendinning } 3332f7ca802SSteve Glendinning 3342f7ca802SSteve Glendinning return 0; 3352f7ca802SSteve Glendinning } 3362f7ca802SSteve Glendinning 337769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) 3382f7ca802SSteve Glendinning { 3392f7ca802SSteve Glendinning unsigned long start_time = jiffies; 3402f7ca802SSteve Glendinning u32 val; 341769ea6d8SSteve Glendinning int ret; 3422f7ca802SSteve Glendinning 3432f7ca802SSteve Glendinning do { 344769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 345b052e073SSteve Glendinning if (ret < 0) { 346b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_CMD\n"); 347b052e073SSteve Glendinning return ret; 348b052e073SSteve Glendinning } 3492f7ca802SSteve Glendinning 3502f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_)) 3512f7ca802SSteve Glendinning return 0; 3522f7ca802SSteve Glendinning 3532f7ca802SSteve Glendinning udelay(40); 3542f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3552f7ca802SSteve Glendinning 35660b86755SJoe Perches netdev_warn(dev->net, "EEPROM is busy\n"); 3572f7ca802SSteve Glendinning return -EIO; 3582f7ca802SSteve Glendinning } 3592f7ca802SSteve Glendinning 3602f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, 3612f7ca802SSteve Glendinning u8 *data) 3622f7ca802SSteve Glendinning { 3632f7ca802SSteve Glendinning u32 val; 3642f7ca802SSteve Glendinning int i, ret; 3652f7ca802SSteve Glendinning 3662f7ca802SSteve Glendinning BUG_ON(!dev); 3672f7ca802SSteve Glendinning BUG_ON(!data); 3682f7ca802SSteve Glendinning 3692f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3702f7ca802SSteve Glendinning if (ret) 3712f7ca802SSteve Glendinning return ret; 3722f7ca802SSteve Glendinning 3732f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3742f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); 375769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 376b052e073SSteve Glendinning if (ret < 0) { 377b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_CMD\n"); 378b052e073SSteve Glendinning return ret; 379b052e073SSteve Glendinning } 3802f7ca802SSteve Glendinning 3812f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3822f7ca802SSteve Glendinning if (ret < 0) 3832f7ca802SSteve Glendinning return ret; 3842f7ca802SSteve Glendinning 385769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_DATA, &val); 386b052e073SSteve Glendinning if (ret < 0) { 387b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_DATA\n"); 388b052e073SSteve Glendinning return ret; 389b052e073SSteve Glendinning } 3902f7ca802SSteve Glendinning 3912f7ca802SSteve Glendinning data[i] = val & 0xFF; 3922f7ca802SSteve Glendinning offset++; 3932f7ca802SSteve Glendinning } 3942f7ca802SSteve Glendinning 3952f7ca802SSteve Glendinning return 0; 3962f7ca802SSteve Glendinning } 3972f7ca802SSteve Glendinning 3982f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, 3992f7ca802SSteve Glendinning u8 *data) 4002f7ca802SSteve Glendinning { 4012f7ca802SSteve Glendinning u32 val; 4022f7ca802SSteve Glendinning int i, ret; 4032f7ca802SSteve Glendinning 4042f7ca802SSteve Glendinning BUG_ON(!dev); 4052f7ca802SSteve Glendinning BUG_ON(!data); 4062f7ca802SSteve Glendinning 4072f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 4082f7ca802SSteve Glendinning if (ret) 4092f7ca802SSteve Glendinning return ret; 4102f7ca802SSteve Glendinning 4112f7ca802SSteve Glendinning /* Issue write/erase enable command */ 4122f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; 413769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 414b052e073SSteve Glendinning if (ret < 0) { 415b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_DATA\n"); 416b052e073SSteve Glendinning return ret; 417b052e073SSteve Glendinning } 4182f7ca802SSteve Glendinning 4192f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 4202f7ca802SSteve Glendinning if (ret < 0) 4212f7ca802SSteve Glendinning return ret; 4222f7ca802SSteve Glendinning 4232f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 4242f7ca802SSteve Glendinning 4252f7ca802SSteve Glendinning /* Fill data register */ 4262f7ca802SSteve Glendinning val = data[i]; 427769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_DATA, val); 428b052e073SSteve Glendinning if (ret < 0) { 429b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_DATA\n"); 430b052e073SSteve Glendinning return ret; 431b052e073SSteve Glendinning } 4322f7ca802SSteve Glendinning 4332f7ca802SSteve Glendinning /* Send "write" command */ 4342f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); 435769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 436b052e073SSteve Glendinning if (ret < 0) { 437b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_CMD\n"); 438b052e073SSteve Glendinning return ret; 439b052e073SSteve Glendinning } 4402f7ca802SSteve Glendinning 4412f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 4422f7ca802SSteve Glendinning if (ret < 0) 4432f7ca802SSteve Glendinning return ret; 4442f7ca802SSteve Glendinning 4452f7ca802SSteve Glendinning offset++; 4462f7ca802SSteve Glendinning } 4472f7ca802SSteve Glendinning 4482f7ca802SSteve Glendinning return 0; 4492f7ca802SSteve Glendinning } 4502f7ca802SSteve Glendinning 451769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, 4527b9e7580SSteve Glendinning u32 data) 4532f7ca802SSteve Glendinning { 4541d74a6bdSSteve Glendinning const u16 size = 4; 4557b9e7580SSteve Glendinning u32 buf; 45672108fd2SMing Lei int ret; 4572f7ca802SSteve Glendinning 4587b9e7580SSteve Glendinning buf = data; 4597b9e7580SSteve Glendinning cpu_to_le32s(&buf); 4607b9e7580SSteve Glendinning 46172108fd2SMing Lei ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, 46272108fd2SMing Lei USB_DIR_OUT | USB_TYPE_VENDOR | 46372108fd2SMing Lei USB_RECIP_DEVICE, 4647b9e7580SSteve Glendinning 0, index, &buf, size); 46572108fd2SMing Lei if (ret < 0) 46672108fd2SMing Lei netdev_warn(dev->net, "Error write async cmd, sts=%d\n", 46772108fd2SMing Lei ret); 46872108fd2SMing Lei return ret; 4692f7ca802SSteve Glendinning } 4702f7ca802SSteve Glendinning 4712f7ca802SSteve Glendinning /* returns hash bit number for given MAC address 4722f7ca802SSteve Glendinning * example: 4732f7ca802SSteve Glendinning * 01 00 5E 00 00 01 -> returns bit number 31 */ 4742f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) 4752f7ca802SSteve Glendinning { 4762f7ca802SSteve Glendinning return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; 4772f7ca802SSteve Glendinning } 4782f7ca802SSteve Glendinning 4792f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev) 4802f7ca802SSteve Glendinning { 4812f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 482ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 4832f7ca802SSteve Glendinning unsigned long flags; 484769ea6d8SSteve Glendinning int ret; 4852f7ca802SSteve Glendinning 4863c0f3c60SMarc Zyngier pdata->hash_hi = 0; 4873c0f3c60SMarc Zyngier pdata->hash_lo = 0; 4883c0f3c60SMarc Zyngier 4892f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 4902f7ca802SSteve Glendinning 4912f7ca802SSteve Glendinning if (dev->net->flags & IFF_PROMISC) { 492a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); 4932f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_PRMS_; 4942f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4952f7ca802SSteve Glendinning } else if (dev->net->flags & IFF_ALLMULTI) { 496a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); 4972f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_MCPAS_; 4982f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); 4994cd24eafSJiri Pirko } else if (!netdev_mc_empty(dev->net)) { 50022bedad3SJiri Pirko struct netdev_hw_addr *ha; 5012f7ca802SSteve Glendinning 5022f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_HPFILT_; 5032f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); 5042f7ca802SSteve Glendinning 50522bedad3SJiri Pirko netdev_for_each_mc_addr(ha, netdev) { 50622bedad3SJiri Pirko u32 bitnum = smsc95xx_hash(ha->addr); 5072f7ca802SSteve Glendinning u32 mask = 0x01 << (bitnum & 0x1F); 5082f7ca802SSteve Glendinning if (bitnum & 0x20) 5093c0f3c60SMarc Zyngier pdata->hash_hi |= mask; 5102f7ca802SSteve Glendinning else 5113c0f3c60SMarc Zyngier pdata->hash_lo |= mask; 5122f7ca802SSteve Glendinning } 5132f7ca802SSteve Glendinning 514a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", 5153c0f3c60SMarc Zyngier pdata->hash_hi, pdata->hash_lo); 5162f7ca802SSteve Glendinning } else { 517a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive own packets only\n"); 5182f7ca802SSteve Glendinning pdata->mac_cr &= 5192f7ca802SSteve Glendinning ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 5202f7ca802SSteve Glendinning } 5212f7ca802SSteve Glendinning 5222f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5232f7ca802SSteve Glendinning 5242f7ca802SSteve Glendinning /* Initiate async writes, as we can't wait for completion here */ 5257b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi); 526b052e073SSteve Glendinning if (ret < 0) 527b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to HASHH\n"); 528769ea6d8SSteve Glendinning 5297b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo); 530b052e073SSteve Glendinning if (ret < 0) 531b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to HASHL\n"); 532769ea6d8SSteve Glendinning 5337b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr); 534b052e073SSteve Glendinning if (ret < 0) 535b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n"); 5362f7ca802SSteve Glendinning } 5372f7ca802SSteve Glendinning 53805b35e7eSAndre Edich static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev) 5392f7ca802SSteve Glendinning { 5409c082731SNisar Sayed u32 flow = 0, afc_cfg; 54105b35e7eSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 54205b35e7eSAndre Edich bool tx_pause, rx_pause; 5432f7ca802SSteve Glendinning 5442f7ca802SSteve Glendinning int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); 545e360a8b4SSteve Glendinning if (ret < 0) 546b052e073SSteve Glendinning return ret; 5472f7ca802SSteve Glendinning 54805b35e7eSAndre Edich if (pdata->phydev->duplex == DUPLEX_FULL) { 54905b35e7eSAndre Edich phy_get_pause(pdata->phydev, &tx_pause, &rx_pause); 5502f7ca802SSteve Glendinning 55105b35e7eSAndre Edich if (rx_pause) 5522f7ca802SSteve Glendinning flow = 0xFFFF0002; 5532f7ca802SSteve Glendinning 55405b35e7eSAndre Edich if (tx_pause) { 5552f7ca802SSteve Glendinning afc_cfg |= 0xF; 5569c082731SNisar Sayed flow |= 0xFFFF0000; 5579c082731SNisar Sayed } else { 5582f7ca802SSteve Glendinning afc_cfg &= ~0xF; 5599c082731SNisar Sayed } 5602f7ca802SSteve Glendinning 561a475f603SJoe Perches netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", 56205b35e7eSAndre Edich rx_pause ? "enabled" : "disabled", 56305b35e7eSAndre Edich tx_pause ? "enabled" : "disabled"); 5642f7ca802SSteve Glendinning } else { 565a475f603SJoe Perches netif_dbg(dev, link, dev->net, "half duplex\n"); 5662f7ca802SSteve Glendinning afc_cfg |= 0xF; 5672f7ca802SSteve Glendinning } 5682f7ca802SSteve Glendinning 569769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, flow); 570b052e073SSteve Glendinning if (ret < 0) 571b052e073SSteve Glendinning return ret; 572e360a8b4SSteve Glendinning 573e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); 5742f7ca802SSteve Glendinning } 5752f7ca802SSteve Glendinning 5768960f878SLukas Wunner static void smsc95xx_mac_update_fullduplex(struct usbnet *dev) 5772f7ca802SSteve Glendinning { 578ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 5792f7ca802SSteve Glendinning unsigned long flags; 580769ea6d8SSteve Glendinning int ret; 5812f7ca802SSteve Glendinning 5822f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 58305b35e7eSAndre Edich if (pdata->phydev->duplex != DUPLEX_FULL) { 5842f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_FDPX_; 5852f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RCVOWN_; 5862f7ca802SSteve Glendinning } else { 5872f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_RCVOWN_; 5882f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_FDPX_; 5892f7ca802SSteve Glendinning } 5902f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5912f7ca802SSteve Glendinning 592769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 5938960f878SLukas Wunner if (ret < 0) { 5948960f878SLukas Wunner if (ret != -ENODEV) 5958960f878SLukas Wunner netdev_warn(dev->net, 5968960f878SLukas Wunner "Error updating MAC full duplex mode\n"); 5978960f878SLukas Wunner return; 5988960f878SLukas Wunner } 5992f7ca802SSteve Glendinning 60005b35e7eSAndre Edich ret = smsc95xx_phy_update_flowcontrol(dev); 601b052e073SSteve Glendinning if (ret < 0) 602b052e073SSteve Glendinning netdev_warn(dev->net, "Error updating PHY flow control\n"); 6032f7ca802SSteve Glendinning } 6042f7ca802SSteve Glendinning 6052f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb) 6062f7ca802SSteve Glendinning { 6071ce8b372SLukas Wunner struct smsc95xx_priv *pdata = dev->driver_priv; 6081ce8b372SLukas Wunner unsigned long flags; 6092f7ca802SSteve Glendinning u32 intdata; 6102f7ca802SSteve Glendinning 6112f7ca802SSteve Glendinning if (urb->actual_length != 4) { 61260b86755SJoe Perches netdev_warn(dev->net, "unexpected urb length %d\n", 61360b86755SJoe Perches urb->actual_length); 6142f7ca802SSteve Glendinning return; 6152f7ca802SSteve Glendinning } 6162f7ca802SSteve Glendinning 6176809d216SBen Dooks intdata = get_unaligned_le32(urb->transfer_buffer); 618a475f603SJoe Perches netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); 6192f7ca802SSteve Glendinning 6201ce8b372SLukas Wunner local_irq_save(flags); 6211ce8b372SLukas Wunner 6222f7ca802SSteve Glendinning if (intdata & INT_ENP_PHY_INT_) 6231ce8b372SLukas Wunner generic_handle_domain_irq(pdata->irqdomain, PHY_HWIRQ); 6242f7ca802SSteve Glendinning else 62560b86755SJoe Perches netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", 62660b86755SJoe Perches intdata); 6271ce8b372SLukas Wunner 6281ce8b372SLukas Wunner local_irq_restore(flags); 6292f7ca802SSteve Glendinning } 6302f7ca802SSteve Glendinning 631f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */ 632c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev, 633c8f44affSMichał Mirosław netdev_features_t features) 6342f7ca802SSteve Glendinning { 63578e47fe4SMichał Mirosław struct usbnet *dev = netdev_priv(netdev); 6362f7ca802SSteve Glendinning u32 read_buf; 63778e47fe4SMichał Mirosław int ret; 63878e47fe4SMichał Mirosław 63978e47fe4SMichał Mirosław ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); 640e360a8b4SSteve Glendinning if (ret < 0) 641b052e073SSteve Glendinning return ret; 6422f7ca802SSteve Glendinning 643fe0cd8caSNisar Sayed if (features & NETIF_F_IP_CSUM) 644f7b29271SSteve Glendinning read_buf |= Tx_COE_EN_; 645f7b29271SSteve Glendinning else 646f7b29271SSteve Glendinning read_buf &= ~Tx_COE_EN_; 647f7b29271SSteve Glendinning 64878e47fe4SMichał Mirosław if (features & NETIF_F_RXCSUM) 6492f7ca802SSteve Glendinning read_buf |= Rx_COE_EN_; 6502f7ca802SSteve Glendinning else 6512f7ca802SSteve Glendinning read_buf &= ~Rx_COE_EN_; 6522f7ca802SSteve Glendinning 6532f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, COE_CR, read_buf); 654e360a8b4SSteve Glendinning if (ret < 0) 655b052e073SSteve Glendinning return ret; 6562f7ca802SSteve Glendinning 657a475f603SJoe Perches netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); 6582f7ca802SSteve Glendinning return 0; 6592f7ca802SSteve Glendinning } 6602f7ca802SSteve Glendinning 6612f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) 6622f7ca802SSteve Glendinning { 6632f7ca802SSteve Glendinning return MAX_EEPROM_SIZE; 6642f7ca802SSteve Glendinning } 6652f7ca802SSteve Glendinning 6662f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, 6672f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6682f7ca802SSteve Glendinning { 6692f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6702f7ca802SSteve Glendinning 6712f7ca802SSteve Glendinning ee->magic = LAN95XX_EEPROM_MAGIC; 6722f7ca802SSteve Glendinning 6732f7ca802SSteve Glendinning return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); 6742f7ca802SSteve Glendinning } 6752f7ca802SSteve Glendinning 6762f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, 6772f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6782f7ca802SSteve Glendinning { 6792f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6802f7ca802SSteve Glendinning 6812f7ca802SSteve Glendinning if (ee->magic != LAN95XX_EEPROM_MAGIC) { 68260b86755SJoe Perches netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", 6832f7ca802SSteve Glendinning ee->magic); 6842f7ca802SSteve Glendinning return -EINVAL; 6852f7ca802SSteve Glendinning } 6862f7ca802SSteve Glendinning 6872f7ca802SSteve Glendinning return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); 6882f7ca802SSteve Glendinning } 6892f7ca802SSteve Glendinning 6909fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev) 6919fa32e94SEmeric Vigier { 6929fa32e94SEmeric Vigier /* all smsc95xx registers */ 69396245317SSteve Glendinning return COE_CR - ID_REV + sizeof(u32); 6949fa32e94SEmeric Vigier } 6959fa32e94SEmeric Vigier 6969fa32e94SEmeric Vigier static void 6979fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, 6989fa32e94SEmeric Vigier void *buf) 6999fa32e94SEmeric Vigier { 7009fa32e94SEmeric Vigier struct usbnet *dev = netdev_priv(netdev); 701d348446bSDan Carpenter unsigned int i, j; 702d348446bSDan Carpenter int retval; 7039fa32e94SEmeric Vigier u32 *data = buf; 7049fa32e94SEmeric Vigier 7059fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); 7069fa32e94SEmeric Vigier if (retval < 0) { 7079fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read ID_REV\n"); 7089fa32e94SEmeric Vigier return; 7099fa32e94SEmeric Vigier } 7109fa32e94SEmeric Vigier 7119fa32e94SEmeric Vigier for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { 7129fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, i, &data[j]); 7139fa32e94SEmeric Vigier if (retval < 0) { 7149fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); 7159fa32e94SEmeric Vigier return; 7169fa32e94SEmeric Vigier } 7179fa32e94SEmeric Vigier } 7189fa32e94SEmeric Vigier } 7199fa32e94SEmeric Vigier 720e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net, 721e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 722e0e474a8SSteve Glendinning { 723e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 724ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 725e0e474a8SSteve Glendinning 726e0e474a8SSteve Glendinning wolinfo->supported = SUPPORTED_WAKE; 727e0e474a8SSteve Glendinning wolinfo->wolopts = pdata->wolopts; 728e0e474a8SSteve Glendinning } 729e0e474a8SSteve Glendinning 730e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net, 731e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 732e0e474a8SSteve Glendinning { 733e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 734ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 7353b14692cSSteve Glendinning int ret; 736e0e474a8SSteve Glendinning 737c530c471SFlorian Fainelli if (wolinfo->wolopts & ~SUPPORTED_WAKE) 738c530c471SFlorian Fainelli return -EINVAL; 739c530c471SFlorian Fainelli 740e0e474a8SSteve Glendinning pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; 7413b14692cSSteve Glendinning 7423b14692cSSteve Glendinning ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); 743b052e073SSteve Glendinning if (ret < 0) 744b052e073SSteve Glendinning netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); 7453b14692cSSteve Glendinning 746b052e073SSteve Glendinning return ret; 747e0e474a8SSteve Glendinning } 748e0e474a8SSteve Glendinning 74905b35e7eSAndre Edich static u32 smsc95xx_get_link(struct net_device *net) 75013722bbeSWoojung Huh { 75105b35e7eSAndre Edich phy_read_status(net->phydev); 75205b35e7eSAndre Edich return net->phydev->link; 75313722bbeSWoojung Huh } 75413722bbeSWoojung Huh 7551710b52dSOleksij Rempel static void smsc95xx_ethtool_get_strings(struct net_device *netdev, u32 sset, 7561710b52dSOleksij Rempel u8 *data) 7571710b52dSOleksij Rempel { 7581710b52dSOleksij Rempel switch (sset) { 7591710b52dSOleksij Rempel case ETH_SS_TEST: 7601710b52dSOleksij Rempel net_selftest_get_strings(data); 7611710b52dSOleksij Rempel break; 7621710b52dSOleksij Rempel } 7631710b52dSOleksij Rempel } 7641710b52dSOleksij Rempel 7651710b52dSOleksij Rempel static int smsc95xx_ethtool_get_sset_count(struct net_device *ndev, int sset) 7661710b52dSOleksij Rempel { 7671710b52dSOleksij Rempel switch (sset) { 7681710b52dSOleksij Rempel case ETH_SS_TEST: 7691710b52dSOleksij Rempel return net_selftest_get_count(); 7701710b52dSOleksij Rempel default: 7711710b52dSOleksij Rempel return -EOPNOTSUPP; 7721710b52dSOleksij Rempel } 7731710b52dSOleksij Rempel } 7741710b52dSOleksij Rempel 7750fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = { 77605b35e7eSAndre Edich .get_link = smsc95xx_get_link, 77705b35e7eSAndre Edich .nway_reset = phy_ethtool_nway_reset, 7782f7ca802SSteve Glendinning .get_drvinfo = usbnet_get_drvinfo, 7792f7ca802SSteve Glendinning .get_msglevel = usbnet_get_msglevel, 7802f7ca802SSteve Glendinning .set_msglevel = usbnet_set_msglevel, 7812f7ca802SSteve Glendinning .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, 7822f7ca802SSteve Glendinning .get_eeprom = smsc95xx_ethtool_get_eeprom, 7832f7ca802SSteve Glendinning .set_eeprom = smsc95xx_ethtool_set_eeprom, 7849fa32e94SEmeric Vigier .get_regs_len = smsc95xx_ethtool_getregslen, 7859fa32e94SEmeric Vigier .get_regs = smsc95xx_ethtool_getregs, 786e0e474a8SSteve Glendinning .get_wol = smsc95xx_ethtool_get_wol, 787e0e474a8SSteve Glendinning .set_wol = smsc95xx_ethtool_set_wol, 78805b35e7eSAndre Edich .get_link_ksettings = phy_ethtool_get_link_ksettings, 78905b35e7eSAndre Edich .set_link_ksettings = phy_ethtool_set_link_ksettings, 790a8f5cb9eSPetr Kulhavy .get_ts_info = ethtool_op_get_ts_info, 7911710b52dSOleksij Rempel .self_test = net_selftest, 7921710b52dSOleksij Rempel .get_strings = smsc95xx_ethtool_get_strings, 7931710b52dSOleksij Rempel .get_sset_count = smsc95xx_ethtool_get_sset_count, 7942f7ca802SSteve Glendinning }; 7952f7ca802SSteve Glendinning 7962f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 7972f7ca802SSteve Glendinning { 7982f7ca802SSteve Glendinning if (!netif_running(netdev)) 7992f7ca802SSteve Glendinning return -EINVAL; 8002f7ca802SSteve Glendinning 80105b35e7eSAndre Edich return phy_mii_ioctl(netdev->phydev, rq, cmd); 8022f7ca802SSteve Glendinning } 8032f7ca802SSteve Glendinning 8042f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev) 8052f7ca802SSteve Glendinning { 806a7021af7SJakub Kicinski u8 addr[ETH_ALEN]; 807a7021af7SJakub Kicinski 808c489565bSArnd Bergmann /* maybe the boot loader passed the MAC address in devicetree */ 8094d04cdc5SJakub Kicinski if (!platform_get_ethdev_address(&dev->udev->dev, dev->net)) { 8104f359b65SŁukasz Stelmach if (is_valid_ether_addr(dev->net->dev_addr)) { 8114f359b65SŁukasz Stelmach /* device tree values are valid so use them */ 8124f359b65SŁukasz Stelmach netif_dbg(dev, ifup, dev->net, "MAC address read from the device tree\n"); 813c489565bSArnd Bergmann return; 814c489565bSArnd Bergmann } 8154f359b65SŁukasz Stelmach } 816c489565bSArnd Bergmann 8172f7ca802SSteve Glendinning /* try reading mac address from EEPROM */ 818a7021af7SJakub Kicinski if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, addr) == 0) { 819a7021af7SJakub Kicinski eth_hw_addr_set(dev->net, addr); 8202f7ca802SSteve Glendinning if (is_valid_ether_addr(dev->net->dev_addr)) { 8212f7ca802SSteve Glendinning /* eeprom values are valid so use them */ 822a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); 8232f7ca802SSteve Glendinning return; 8242f7ca802SSteve Glendinning } 8252f7ca802SSteve Glendinning } 8262f7ca802SSteve Glendinning 827c489565bSArnd Bergmann /* no useful static MAC address found. generate a random one */ 828f2cedb63SDanny Kukawka eth_hw_addr_random(dev->net); 829c7e12eadSJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); 8302f7ca802SSteve Glendinning } 8312f7ca802SSteve Glendinning 8322f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev) 8332f7ca802SSteve Glendinning { 8342f7ca802SSteve Glendinning u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | 8352f7ca802SSteve Glendinning dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; 8362f7ca802SSteve Glendinning u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; 8372f7ca802SSteve Glendinning int ret; 8382f7ca802SSteve Glendinning 8392f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); 840b052e073SSteve Glendinning if (ret < 0) 841b052e073SSteve Glendinning return ret; 842e360a8b4SSteve Glendinning 843e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, ADDRH, addr_hi); 8442f7ca802SSteve Glendinning } 8452f7ca802SSteve Glendinning 8462f7ca802SSteve Glendinning /* starts the TX path */ 847769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev) 8482f7ca802SSteve Glendinning { 849ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 8502f7ca802SSteve Glendinning unsigned long flags; 851769ea6d8SSteve Glendinning int ret; 8522f7ca802SSteve Glendinning 8532f7ca802SSteve Glendinning /* Enable Tx at MAC */ 8542f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 8552f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_TXEN_; 8562f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 8572f7ca802SSteve Glendinning 858769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 859e360a8b4SSteve Glendinning if (ret < 0) 860b052e073SSteve Glendinning return ret; 8612f7ca802SSteve Glendinning 8622f7ca802SSteve Glendinning /* Enable Tx at SCSRs */ 863e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); 8642f7ca802SSteve Glendinning } 8652f7ca802SSteve Glendinning 8662f7ca802SSteve Glendinning /* Starts the Receive path */ 86731472429SLukas Wunner static int smsc95xx_start_rx_path(struct usbnet *dev) 8682f7ca802SSteve Glendinning { 869ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 8702f7ca802SSteve Glendinning unsigned long flags; 8712f7ca802SSteve Glendinning 8722f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 8732f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RXEN_; 8742f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 8752f7ca802SSteve Glendinning 87631472429SLukas Wunner return smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 8772f7ca802SSteve Glendinning } 8782f7ca802SSteve Glendinning 8792f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev) 8802f7ca802SSteve Glendinning { 881ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 8822f7ca802SSteve Glendinning u32 read_buf, write_buf, burst_cap; 8832f7ca802SSteve Glendinning int ret = 0, timeout; 8842f7ca802SSteve Glendinning 885a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); 8862f7ca802SSteve Glendinning 8874436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); 888e360a8b4SSteve Glendinning if (ret < 0) 889b052e073SSteve Glendinning return ret; 8902f7ca802SSteve Glendinning 8912f7ca802SSteve Glendinning timeout = 0; 8922f7ca802SSteve Glendinning do { 893cf2acec2SSteve Glendinning msleep(10); 8942f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 895e360a8b4SSteve Glendinning if (ret < 0) 896b052e073SSteve Glendinning return ret; 8972f7ca802SSteve Glendinning timeout++; 8982f7ca802SSteve Glendinning } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); 8992f7ca802SSteve Glendinning 9002f7ca802SSteve Glendinning if (timeout >= 100) { 90160b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); 902c53647a5SDan Carpenter return -ETIMEDOUT; 9032f7ca802SSteve Glendinning } 9042f7ca802SSteve Glendinning 9052f7ca802SSteve Glendinning ret = smsc95xx_set_mac_address(dev); 9062f7ca802SSteve Glendinning if (ret < 0) 9072f7ca802SSteve Glendinning return ret; 9082f7ca802SSteve Glendinning 9091e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", 9101e1d7412SJoe Perches dev->net->dev_addr); 9112f7ca802SSteve Glendinning 9122f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 913e360a8b4SSteve Glendinning if (ret < 0) 914b052e073SSteve Glendinning return ret; 9152f7ca802SSteve Glendinning 9161e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", 9171e1d7412SJoe Perches read_buf); 9182f7ca802SSteve Glendinning 9192f7ca802SSteve Glendinning read_buf |= HW_CFG_BIR_; 9202f7ca802SSteve Glendinning 9212f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 922e360a8b4SSteve Glendinning if (ret < 0) 923b052e073SSteve Glendinning return ret; 9242f7ca802SSteve Glendinning 9252f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 926e360a8b4SSteve Glendinning if (ret < 0) 927b052e073SSteve Glendinning return ret; 928b052e073SSteve Glendinning 929a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 930a475f603SJoe Perches "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", 93160b86755SJoe Perches read_buf); 9322f7ca802SSteve Glendinning 9332f7ca802SSteve Glendinning if (!turbo_mode) { 9342f7ca802SSteve Glendinning burst_cap = 0; 9352f7ca802SSteve Glendinning dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; 9362f7ca802SSteve Glendinning } else if (dev->udev->speed == USB_SPEED_HIGH) { 9372f7ca802SSteve Glendinning burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; 9382f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; 9392f7ca802SSteve Glendinning } else { 9402f7ca802SSteve Glendinning burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; 9412f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; 9422f7ca802SSteve Glendinning } 9432f7ca802SSteve Glendinning 9441e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", 9451e1d7412SJoe Perches (ulong)dev->rx_urb_size); 9462f7ca802SSteve Glendinning 9472f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); 948e360a8b4SSteve Glendinning if (ret < 0) 949b052e073SSteve Glendinning return ret; 9502f7ca802SSteve Glendinning 9512f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); 952e360a8b4SSteve Glendinning if (ret < 0) 953b052e073SSteve Glendinning return ret; 954769ea6d8SSteve Glendinning 955a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 956a475f603SJoe Perches "Read Value from BURST_CAP after writing: 0x%08x\n", 9572f7ca802SSteve Glendinning read_buf); 9582f7ca802SSteve Glendinning 9594436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); 960e360a8b4SSteve Glendinning if (ret < 0) 961b052e073SSteve Glendinning return ret; 9622f7ca802SSteve Glendinning 9632f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); 964e360a8b4SSteve Glendinning if (ret < 0) 965b052e073SSteve Glendinning return ret; 966769ea6d8SSteve Glendinning 967a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 968a475f603SJoe Perches "Read Value from BULK_IN_DLY after writing: 0x%08x\n", 96960b86755SJoe Perches read_buf); 9702f7ca802SSteve Glendinning 9712f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 972e360a8b4SSteve Glendinning if (ret < 0) 973b052e073SSteve Glendinning return ret; 974769ea6d8SSteve Glendinning 9751e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n", 9761e1d7412SJoe Perches read_buf); 9772f7ca802SSteve Glendinning 9782f7ca802SSteve Glendinning if (turbo_mode) 9792f7ca802SSteve Glendinning read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); 9802f7ca802SSteve Glendinning 9812f7ca802SSteve Glendinning read_buf &= ~HW_CFG_RXDOFF_; 9822f7ca802SSteve Glendinning 9832f7ca802SSteve Glendinning /* set Rx data offset=2, Make IP header aligns on word boundary. */ 9842f7ca802SSteve Glendinning read_buf |= NET_IP_ALIGN << 9; 9852f7ca802SSteve Glendinning 9862f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 987e360a8b4SSteve Glendinning if (ret < 0) 988b052e073SSteve Glendinning return ret; 9892f7ca802SSteve Glendinning 9902f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 991e360a8b4SSteve Glendinning if (ret < 0) 992b052e073SSteve Glendinning return ret; 993769ea6d8SSteve Glendinning 994a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 995a475f603SJoe Perches "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); 9962f7ca802SSteve Glendinning 9974436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 998e360a8b4SSteve Glendinning if (ret < 0) 999b052e073SSteve Glendinning return ret; 10002f7ca802SSteve Glendinning 10012f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); 1002e360a8b4SSteve Glendinning if (ret < 0) 1003b052e073SSteve Glendinning return ret; 1004a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); 10052f7ca802SSteve Glendinning 1006f293501cSSteve Glendinning /* Configure GPIO pins as LED outputs */ 1007f293501cSSteve Glendinning write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | 1008f293501cSSteve Glendinning LED_GPIO_CFG_FDX_LED; 1009f293501cSSteve Glendinning ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); 1010e360a8b4SSteve Glendinning if (ret < 0) 1011b052e073SSteve Glendinning return ret; 1012f293501cSSteve Glendinning 10132f7ca802SSteve Glendinning /* Init Tx */ 10144436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, 0); 1015e360a8b4SSteve Glendinning if (ret < 0) 1016b052e073SSteve Glendinning return ret; 10172f7ca802SSteve Glendinning 10184436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); 1019e360a8b4SSteve Glendinning if (ret < 0) 1020b052e073SSteve Glendinning return ret; 10212f7ca802SSteve Glendinning 10222f7ca802SSteve Glendinning /* Don't need mac_cr_lock during initialisation */ 10232f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); 1024e360a8b4SSteve Glendinning if (ret < 0) 1025b052e073SSteve Glendinning return ret; 10262f7ca802SSteve Glendinning 10272f7ca802SSteve Glendinning /* Init Rx */ 10282f7ca802SSteve Glendinning /* Set Vlan */ 10294436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); 1030e360a8b4SSteve Glendinning if (ret < 0) 1031b052e073SSteve Glendinning return ret; 10322f7ca802SSteve Glendinning 1033f7b29271SSteve Glendinning /* Enable or disable checksum offload engines */ 1034769ea6d8SSteve Glendinning ret = smsc95xx_set_features(dev->net, dev->net->features); 1035b052e073SSteve Glendinning if (ret < 0) { 1036b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to set checksum offload features\n"); 1037b052e073SSteve Glendinning return ret; 1038b052e073SSteve Glendinning } 10392f7ca802SSteve Glendinning 10402f7ca802SSteve Glendinning smsc95xx_set_multicast(dev->net); 10412f7ca802SSteve Glendinning 10422f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); 1043e360a8b4SSteve Glendinning if (ret < 0) 1044b052e073SSteve Glendinning return ret; 10452f7ca802SSteve Glendinning 10462f7ca802SSteve Glendinning /* enable PHY interrupts */ 10472f7ca802SSteve Glendinning read_buf |= INT_EP_CTL_PHY_INT_; 10482f7ca802SSteve Glendinning 10492f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); 1050e360a8b4SSteve Glendinning if (ret < 0) 1051b052e073SSteve Glendinning return ret; 10522f7ca802SSteve Glendinning 1053769ea6d8SSteve Glendinning ret = smsc95xx_start_tx_path(dev); 1054b052e073SSteve Glendinning if (ret < 0) { 1055b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start TX path\n"); 1056b052e073SSteve Glendinning return ret; 1057b052e073SSteve Glendinning } 1058769ea6d8SSteve Glendinning 105931472429SLukas Wunner ret = smsc95xx_start_rx_path(dev); 1060b052e073SSteve Glendinning if (ret < 0) { 1061b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start RX path\n"); 1062b052e073SSteve Glendinning return ret; 1063b052e073SSteve Glendinning } 10642f7ca802SSteve Glendinning 1065a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); 10662f7ca802SSteve Glendinning return 0; 10672f7ca802SSteve Glendinning } 10682f7ca802SSteve Glendinning 106963e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = { 107063e77b39SStephen Hemminger .ndo_open = usbnet_open, 107163e77b39SStephen Hemminger .ndo_stop = usbnet_stop, 107263e77b39SStephen Hemminger .ndo_start_xmit = usbnet_start_xmit, 107363e77b39SStephen Hemminger .ndo_tx_timeout = usbnet_tx_timeout, 107463e77b39SStephen Hemminger .ndo_change_mtu = usbnet_change_mtu, 1075323955a0SHeiner Kallweit .ndo_get_stats64 = dev_get_tstats64, 107663e77b39SStephen Hemminger .ndo_set_mac_address = eth_mac_addr, 107763e77b39SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 1078a7605370SArnd Bergmann .ndo_eth_ioctl = smsc95xx_ioctl, 1079afc4b13dSJiri Pirko .ndo_set_rx_mode = smsc95xx_set_multicast, 108078e47fe4SMichał Mirosław .ndo_set_features = smsc95xx_set_features, 108163e77b39SStephen Hemminger }; 108263e77b39SStephen Hemminger 1083a049a30fSMartyn Welch static void smsc95xx_handle_link_change(struct net_device *net) 1084a049a30fSMartyn Welch { 1085a049a30fSMartyn Welch struct usbnet *dev = netdev_priv(net); 1086a049a30fSMartyn Welch 1087a049a30fSMartyn Welch phy_print_status(net->phydev); 10888960f878SLukas Wunner smsc95xx_mac_update_fullduplex(dev); 1089a049a30fSMartyn Welch usbnet_defer_kevent(dev, EVENT_LINK_CHANGE); 1090a049a30fSMartyn Welch } 1091a049a30fSMartyn Welch 10922f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) 10932f7ca802SSteve Glendinning { 1094ad90a73fSAndre Edich struct smsc95xx_priv *pdata; 10951ce8b372SLukas Wunner char usb_path[64]; 10961ce8b372SLukas Wunner int ret, phy_irq; 1097bbd9f9eeSSteve Glendinning u32 val; 10982f7ca802SSteve Glendinning 10992f7ca802SSteve Glendinning printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); 11002f7ca802SSteve Glendinning 11012f7ca802SSteve Glendinning ret = usbnet_get_endpoints(dev, intf); 1102b052e073SSteve Glendinning if (ret < 0) { 1103b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); 1104b052e073SSteve Glendinning return ret; 1105b052e073SSteve Glendinning } 11062f7ca802SSteve Glendinning 1107ad90a73fSAndre Edich pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 110838673c82SJoe Perches if (!pdata) 11092f7ca802SSteve Glendinning return -ENOMEM; 11102f7ca802SSteve Glendinning 1111ad90a73fSAndre Edich dev->driver_priv = pdata; 1112ad90a73fSAndre Edich 11132f7ca802SSteve Glendinning spin_lock_init(&pdata->mac_cr_lock); 11142f7ca802SSteve Glendinning 1115fe0cd8caSNisar Sayed /* LAN95xx devices do not alter the computed checksum of 0 to 0xffff. 1116fe0cd8caSNisar Sayed * RFC 2460, ipv6 UDP calculated checksum yields a result of zero must 1117fe0cd8caSNisar Sayed * be changed to 0xffff. RFC 768, ipv4 UDP computed checksum is zero, 1118fe0cd8caSNisar Sayed * it is transmitted as all ones. The zero transmitted checksum means 1119fe0cd8caSNisar Sayed * transmitter generated no checksum. Hence, enable csum offload only 1120fe0cd8caSNisar Sayed * for ipv4 packets. 1121fe0cd8caSNisar Sayed */ 112278e47fe4SMichał Mirosław if (DEFAULT_TX_CSUM_ENABLE) 1123fe0cd8caSNisar Sayed dev->net->features |= NETIF_F_IP_CSUM; 112478e47fe4SMichał Mirosław if (DEFAULT_RX_CSUM_ENABLE) 112578e47fe4SMichał Mirosław dev->net->features |= NETIF_F_RXCSUM; 112678e47fe4SMichał Mirosław 1127fe0cd8caSNisar Sayed dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM; 1128810eeb1fSBen Dooks set_bit(EVENT_NO_IP_ALIGN, &dev->flags); 11292f7ca802SSteve Glendinning 1130f4e8ab7cSBernard Blackham smsc95xx_init_mac_address(dev); 1131f4e8ab7cSBernard Blackham 11322f7ca802SSteve Glendinning /* Init all registers */ 11332f7ca802SSteve Glendinning ret = smsc95xx_reset(dev); 11347c8b1e85SAndre Edich if (ret) 11357c8b1e85SAndre Edich goto free_pdata; 11362f7ca802SSteve Glendinning 11371ce8b372SLukas Wunner /* create irq domain for use by PHY driver and GPIO consumers */ 11381ce8b372SLukas Wunner usb_make_path(dev->udev, usb_path, sizeof(usb_path)); 11391ce8b372SLukas Wunner pdata->irqfwnode = irq_domain_alloc_named_fwnode(usb_path); 11401ce8b372SLukas Wunner if (!pdata->irqfwnode) { 11411ce8b372SLukas Wunner ret = -ENOMEM; 11421ce8b372SLukas Wunner goto free_pdata; 11431ce8b372SLukas Wunner } 11441ce8b372SLukas Wunner 11451ce8b372SLukas Wunner pdata->irqdomain = irq_domain_create_linear(pdata->irqfwnode, 11461ce8b372SLukas Wunner SMSC95XX_NR_IRQS, 11471ce8b372SLukas Wunner &irq_domain_simple_ops, 11481ce8b372SLukas Wunner pdata); 11491ce8b372SLukas Wunner if (!pdata->irqdomain) { 11501ce8b372SLukas Wunner ret = -ENOMEM; 11511ce8b372SLukas Wunner goto free_irqfwnode; 11521ce8b372SLukas Wunner } 11531ce8b372SLukas Wunner 11541ce8b372SLukas Wunner phy_irq = irq_create_mapping(pdata->irqdomain, PHY_HWIRQ); 11551ce8b372SLukas Wunner if (!phy_irq) { 11561ce8b372SLukas Wunner ret = -ENOENT; 11571ce8b372SLukas Wunner goto remove_irqdomain; 11581ce8b372SLukas Wunner } 11591ce8b372SLukas Wunner 11601ce8b372SLukas Wunner pdata->irqchip = dummy_irq_chip; 11611ce8b372SLukas Wunner pdata->irqchip.name = SMSC_CHIPNAME; 11621ce8b372SLukas Wunner irq_set_chip_and_handler_name(phy_irq, &pdata->irqchip, 11631ce8b372SLukas Wunner handle_simple_irq, "phy"); 11641ce8b372SLukas Wunner 116505b35e7eSAndre Edich pdata->mdiobus = mdiobus_alloc(); 116605b35e7eSAndre Edich if (!pdata->mdiobus) { 116705b35e7eSAndre Edich ret = -ENOMEM; 11681ce8b372SLukas Wunner goto dispose_irq; 116905b35e7eSAndre Edich } 117005b35e7eSAndre Edich 117105b35e7eSAndre Edich ret = smsc95xx_read_reg(dev, HW_CFG, &val); 117205b35e7eSAndre Edich if (ret < 0) 117305b35e7eSAndre Edich goto free_mdio; 117405b35e7eSAndre Edich 1175809ff97aSAlexandru Tachici pdata->is_internal_phy = !(val & HW_CFG_PSEL_); 1176809ff97aSAlexandru Tachici if (pdata->is_internal_phy) 117705b35e7eSAndre Edich pdata->mdiobus->phy_mask = ~(1u << SMSC95XX_INTERNAL_PHY_ID); 117805b35e7eSAndre Edich 117905b35e7eSAndre Edich pdata->mdiobus->priv = dev; 118005b35e7eSAndre Edich pdata->mdiobus->read = smsc95xx_mdiobus_read; 118105b35e7eSAndre Edich pdata->mdiobus->write = smsc95xx_mdiobus_write; 1182809ff97aSAlexandru Tachici pdata->mdiobus->reset = smsc95xx_mdiobus_reset; 118305b35e7eSAndre Edich pdata->mdiobus->name = "smsc95xx-mdiobus"; 118405b35e7eSAndre Edich pdata->mdiobus->parent = &dev->udev->dev; 118505b35e7eSAndre Edich 118605b35e7eSAndre Edich snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id), 118705b35e7eSAndre Edich "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev->devnum); 118805b35e7eSAndre Edich 118905b35e7eSAndre Edich ret = mdiobus_register(pdata->mdiobus); 119005b35e7eSAndre Edich if (ret) { 119105b35e7eSAndre Edich netdev_err(dev->net, "Could not register MDIO bus\n"); 119205b35e7eSAndre Edich goto free_mdio; 119305b35e7eSAndre Edich } 119405b35e7eSAndre Edich 119505b35e7eSAndre Edich pdata->phydev = phy_find_first(pdata->mdiobus); 119605b35e7eSAndre Edich if (!pdata->phydev) { 119705b35e7eSAndre Edich netdev_err(dev->net, "no PHY found\n"); 119805b35e7eSAndre Edich ret = -ENODEV; 119905b35e7eSAndre Edich goto unregister_mdio; 120005b35e7eSAndre Edich } 120105b35e7eSAndre Edich 12021ce8b372SLukas Wunner pdata->phydev->irq = phy_irq; 1203809ff97aSAlexandru Tachici pdata->phydev->is_internal = pdata->is_internal_phy; 120405b35e7eSAndre Edich 1205bbd9f9eeSSteve Glendinning /* detect device revision as different features may be available */ 1206bbd9f9eeSSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &val); 1207e360a8b4SSteve Glendinning if (ret < 0) 120805b35e7eSAndre Edich goto unregister_mdio; 12093ed58f96SAndre Edich 1210bbd9f9eeSSteve Glendinning val >>= 16; 12119ebca507SSteve Glendinning if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || 12129ebca507SSteve Glendinning (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) 12139ebca507SSteve Glendinning pdata->features = (FEATURE_8_WAKEUP_FILTERS | 12149ebca507SSteve Glendinning FEATURE_PHY_NLP_CROSSOVER | 1215eb970ff0SMing Lei FEATURE_REMOTE_WAKEUP); 12169ebca507SSteve Glendinning else if (val == ID_REV_CHIP_ID_9512_) 12179ebca507SSteve Glendinning pdata->features = FEATURE_8_WAKEUP_FILTERS; 1218bbd9f9eeSSteve Glendinning 121963e77b39SStephen Hemminger dev->net->netdev_ops = &smsc95xx_netdev_ops; 12202f7ca802SSteve Glendinning dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 12212f7ca802SSteve Glendinning dev->net->flags |= IFF_MULTICAST; 122278e47fe4SMichał Mirosław dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 122385b18b02SStefan Wahren dev->net->min_mtu = ETH_MIN_MTU; 122485b18b02SStefan Wahren dev->net->max_mtu = ETH_DATA_LEN; 12259bbf5660SStephane Fillod dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; 1226a049a30fSMartyn Welch 1227a049a30fSMartyn Welch ret = phy_connect_direct(dev->net, pdata->phydev, 1228a049a30fSMartyn Welch &smsc95xx_handle_link_change, 1229a049a30fSMartyn Welch PHY_INTERFACE_MODE_MII); 1230a049a30fSMartyn Welch if (ret) { 1231a049a30fSMartyn Welch netdev_err(dev->net, "can't attach PHY to %s\n", pdata->mdiobus->id); 1232a049a30fSMartyn Welch goto unregister_mdio; 1233a049a30fSMartyn Welch } 1234a049a30fSMartyn Welch 1235a049a30fSMartyn Welch phy_attached_info(dev->net->phydev); 1236a049a30fSMartyn Welch 12372f7ca802SSteve Glendinning return 0; 12387c8b1e85SAndre Edich 123905b35e7eSAndre Edich unregister_mdio: 124005b35e7eSAndre Edich mdiobus_unregister(pdata->mdiobus); 124105b35e7eSAndre Edich 124205b35e7eSAndre Edich free_mdio: 124305b35e7eSAndre Edich mdiobus_free(pdata->mdiobus); 124405b35e7eSAndre Edich 12451ce8b372SLukas Wunner dispose_irq: 12461ce8b372SLukas Wunner irq_dispose_mapping(phy_irq); 12471ce8b372SLukas Wunner 12481ce8b372SLukas Wunner remove_irqdomain: 12491ce8b372SLukas Wunner irq_domain_remove(pdata->irqdomain); 12501ce8b372SLukas Wunner 12511ce8b372SLukas Wunner free_irqfwnode: 12521ce8b372SLukas Wunner irq_domain_free_fwnode(pdata->irqfwnode); 12531ce8b372SLukas Wunner 12547c8b1e85SAndre Edich free_pdata: 12557c8b1e85SAndre Edich kfree(pdata); 12567c8b1e85SAndre Edich return ret; 12572f7ca802SSteve Glendinning } 12582f7ca802SSteve Glendinning 12592f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) 12602f7ca802SSteve Glendinning { 1261ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1262d69d1694SChristoph Fritz 1263a049a30fSMartyn Welch phy_disconnect(dev->net->phydev); 126405b35e7eSAndre Edich mdiobus_unregister(pdata->mdiobus); 126505b35e7eSAndre Edich mdiobus_free(pdata->mdiobus); 12661ce8b372SLukas Wunner irq_dispose_mapping(irq_find_mapping(pdata->irqdomain, PHY_HWIRQ)); 12671ce8b372SLukas Wunner irq_domain_remove(pdata->irqdomain); 12681ce8b372SLukas Wunner irq_domain_free_fwnode(pdata->irqfwnode); 1269a475f603SJoe Perches netif_dbg(dev, ifdown, dev->net, "free pdata\n"); 12702f7ca802SSteve Glendinning kfree(pdata); 12712f7ca802SSteve Glendinning } 12722f7ca802SSteve Glendinning 127305b35e7eSAndre Edich static int smsc95xx_start_phy(struct usbnet *dev) 127405b35e7eSAndre Edich { 1275a049a30fSMartyn Welch phy_start(dev->net->phydev); 127605b35e7eSAndre Edich 127705b35e7eSAndre Edich return 0; 127805b35e7eSAndre Edich } 127905b35e7eSAndre Edich 1280a049a30fSMartyn Welch static int smsc95xx_stop(struct usbnet *dev) 128105b35e7eSAndre Edich { 128205b35e7eSAndre Edich phy_stop(dev->net->phydev); 1283a049a30fSMartyn Welch 128405b35e7eSAndre Edich return 0; 128505b35e7eSAndre Edich } 128605b35e7eSAndre Edich 1287068bb1a7SSteve Glendinning static u32 smsc_crc(const u8 *buffer, size_t len, int filter) 1288bbd9f9eeSSteve Glendinning { 1289068bb1a7SSteve Glendinning u32 crc = bitrev16(crc16(0xFFFF, buffer, len)); 1290068bb1a7SSteve Glendinning return crc << ((filter % 2) * 16); 1291bbd9f9eeSSteve Glendinning } 1292bbd9f9eeSSteve Glendinning 129331472429SLukas Wunner static int smsc95xx_link_ok(struct usbnet *dev) 1294e5e3af83SSteve Glendinning { 129531472429SLukas Wunner struct smsc95xx_priv *pdata = dev->driver_priv; 1296e5e3af83SSteve Glendinning int ret; 1297e5e3af83SSteve Glendinning 1298e5e3af83SSteve Glendinning /* first, a dummy read, needed to latch some MII phys */ 129931472429SLukas Wunner ret = smsc95xx_mdio_read(dev, pdata->phydev->mdio.addr, MII_BMSR); 1300e360a8b4SSteve Glendinning if (ret < 0) 1301b052e073SSteve Glendinning return ret; 1302e5e3af83SSteve Glendinning 130331472429SLukas Wunner ret = smsc95xx_mdio_read(dev, pdata->phydev->mdio.addr, MII_BMSR); 1304e360a8b4SSteve Glendinning if (ret < 0) 1305b052e073SSteve Glendinning return ret; 1306e5e3af83SSteve Glendinning 1307e5e3af83SSteve Glendinning return !!(ret & BMSR_LSTATUS); 1308e5e3af83SSteve Glendinning } 1309e5e3af83SSteve Glendinning 1310319b95b5SSteve Glendinning static int smsc95xx_enter_suspend0(struct usbnet *dev) 1311319b95b5SSteve Glendinning { 1312ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1313319b95b5SSteve Glendinning u32 val; 1314319b95b5SSteve Glendinning int ret; 1315319b95b5SSteve Glendinning 131631472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1317e360a8b4SSteve Glendinning if (ret < 0) 1318b052e073SSteve Glendinning return ret; 1319319b95b5SSteve Glendinning 1320319b95b5SSteve Glendinning val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); 1321319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_0; 1322319b95b5SSteve Glendinning 132331472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1324e360a8b4SSteve Glendinning if (ret < 0) 1325b052e073SSteve Glendinning return ret; 1326319b95b5SSteve Glendinning 1327319b95b5SSteve Glendinning /* clear wol status */ 1328319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1329319b95b5SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1330319b95b5SSteve Glendinning 1331319b95b5SSteve Glendinning /* enable energy detection */ 1332319b95b5SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1333319b95b5SSteve Glendinning val |= PM_CTL_WUPS_ED_; 1334319b95b5SSteve Glendinning 133531472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1336e360a8b4SSteve Glendinning if (ret < 0) 1337b052e073SSteve Glendinning return ret; 1338319b95b5SSteve Glendinning 1339319b95b5SSteve Glendinning /* read back PM_CTRL */ 134031472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 134176437214SMing Lei if (ret < 0) 134276437214SMing Lei return ret; 1343319b95b5SSteve Glendinning 1344b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND0; 1345b2d4b150SSteve Glendinning 134676437214SMing Lei return 0; 1347319b95b5SSteve Glendinning } 1348319b95b5SSteve Glendinning 1349319b95b5SSteve Glendinning static int smsc95xx_enter_suspend1(struct usbnet *dev) 1350319b95b5SSteve Glendinning { 1351ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 135231472429SLukas Wunner int ret, phy_id = pdata->phydev->mdio.addr; 1353319b95b5SSteve Glendinning u32 val; 1354319b95b5SSteve Glendinning 1355319b95b5SSteve Glendinning /* reconfigure link pulse detection timing for 1356319b95b5SSteve Glendinning * compatibility with non-standard link partners 1357319b95b5SSteve Glendinning */ 1358319b95b5SSteve Glendinning if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) 135931472429SLukas Wunner smsc95xx_mdio_write(dev, phy_id, PHY_EDPD_CONFIG, 1360319b95b5SSteve Glendinning PHY_EDPD_CONFIG_DEFAULT); 1361319b95b5SSteve Glendinning 1362319b95b5SSteve Glendinning /* enable energy detect power-down mode */ 136331472429SLukas Wunner ret = smsc95xx_mdio_read(dev, phy_id, PHY_MODE_CTRL_STS); 1364e360a8b4SSteve Glendinning if (ret < 0) 1365b052e073SSteve Glendinning return ret; 1366319b95b5SSteve Glendinning 1367319b95b5SSteve Glendinning ret |= MODE_CTRL_STS_EDPWRDOWN_; 1368319b95b5SSteve Glendinning 136931472429SLukas Wunner smsc95xx_mdio_write(dev, phy_id, PHY_MODE_CTRL_STS, ret); 1370319b95b5SSteve Glendinning 1371319b95b5SSteve Glendinning /* enter SUSPEND1 mode */ 137231472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1373e360a8b4SSteve Glendinning if (ret < 0) 1374b052e073SSteve Glendinning return ret; 1375319b95b5SSteve Glendinning 1376319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1377319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_1; 1378319b95b5SSteve Glendinning 137931472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1380e360a8b4SSteve Glendinning if (ret < 0) 1381b052e073SSteve Glendinning return ret; 1382319b95b5SSteve Glendinning 1383319b95b5SSteve Glendinning /* clear wol status, enable energy detection */ 1384319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1385319b95b5SSteve Glendinning val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); 1386319b95b5SSteve Glendinning 138731472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 138876437214SMing Lei if (ret < 0) 138976437214SMing Lei return ret; 1390319b95b5SSteve Glendinning 1391b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND1; 1392b2d4b150SSteve Glendinning 139376437214SMing Lei return 0; 1394319b95b5SSteve Glendinning } 1395319b95b5SSteve Glendinning 1396319b95b5SSteve Glendinning static int smsc95xx_enter_suspend2(struct usbnet *dev) 1397319b95b5SSteve Glendinning { 1398ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1399319b95b5SSteve Glendinning u32 val; 1400319b95b5SSteve Glendinning int ret; 1401319b95b5SSteve Glendinning 140231472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1403e360a8b4SSteve Glendinning if (ret < 0) 1404b052e073SSteve Glendinning return ret; 1405319b95b5SSteve Glendinning 1406319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1407319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_2; 1408319b95b5SSteve Glendinning 140931472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 141076437214SMing Lei if (ret < 0) 141176437214SMing Lei return ret; 1412319b95b5SSteve Glendinning 1413b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND2; 1414b2d4b150SSteve Glendinning 141576437214SMing Lei return 0; 1416319b95b5SSteve Glendinning } 1417319b95b5SSteve Glendinning 1418b2d4b150SSteve Glendinning static int smsc95xx_enter_suspend3(struct usbnet *dev) 1419b2d4b150SSteve Glendinning { 1420ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1421b2d4b150SSteve Glendinning u32 val; 1422b2d4b150SSteve Glendinning int ret; 1423b2d4b150SSteve Glendinning 142431472429SLukas Wunner ret = smsc95xx_read_reg(dev, RX_FIFO_INF, &val); 1425b2d4b150SSteve Glendinning if (ret < 0) 1426b2d4b150SSteve Glendinning return ret; 1427b2d4b150SSteve Glendinning 142853a759c8SMartin Wetterwald if (val & RX_FIFO_INF_USED_) { 1429b2d4b150SSteve Glendinning netdev_info(dev->net, "rx fifo not empty in autosuspend\n"); 1430b2d4b150SSteve Glendinning return -EBUSY; 1431b2d4b150SSteve Glendinning } 1432b2d4b150SSteve Glendinning 143331472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1434b2d4b150SSteve Glendinning if (ret < 0) 1435b2d4b150SSteve Glendinning return ret; 1436b2d4b150SSteve Glendinning 1437b2d4b150SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1438b2d4b150SSteve Glendinning val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS; 1439b2d4b150SSteve Glendinning 144031472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1441b2d4b150SSteve Glendinning if (ret < 0) 1442b2d4b150SSteve Glendinning return ret; 1443b2d4b150SSteve Glendinning 1444b2d4b150SSteve Glendinning /* clear wol status */ 1445b2d4b150SSteve Glendinning val &= ~PM_CTL_WUPS_; 1446b2d4b150SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1447b2d4b150SSteve Glendinning 144831472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1449b2d4b150SSteve Glendinning if (ret < 0) 1450b2d4b150SSteve Glendinning return ret; 1451b2d4b150SSteve Glendinning 1452b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND3; 1453b2d4b150SSteve Glendinning 1454b2d4b150SSteve Glendinning return 0; 1455b2d4b150SSteve Glendinning } 1456b2d4b150SSteve Glendinning 1457b2d4b150SSteve Glendinning static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up) 1458b2d4b150SSteve Glendinning { 1459ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1460b2d4b150SSteve Glendinning 1461b2d4b150SSteve Glendinning if (!netif_running(dev->net)) { 1462b2d4b150SSteve Glendinning /* interface is ifconfig down so fully power down hw */ 1463b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n"); 1464b2d4b150SSteve Glendinning return smsc95xx_enter_suspend2(dev); 1465b2d4b150SSteve Glendinning } 1466b2d4b150SSteve Glendinning 1467b2d4b150SSteve Glendinning if (!link_up) { 1468b2d4b150SSteve Glendinning /* link is down so enter EDPD mode, but only if device can 1469b2d4b150SSteve Glendinning * reliably resume from it. This check should be redundant 1470eb970ff0SMing Lei * as current FEATURE_REMOTE_WAKEUP parts also support 1471b2d4b150SSteve Glendinning * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */ 1472b2d4b150SSteve Glendinning if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) { 1473b2d4b150SSteve Glendinning netdev_warn(dev->net, "EDPD not supported\n"); 1474b2d4b150SSteve Glendinning return -EBUSY; 1475b2d4b150SSteve Glendinning } 1476b2d4b150SSteve Glendinning 1477b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n"); 1478b2d4b150SSteve Glendinning netdev_info(dev->net, "entering SUSPEND1 mode\n"); 1479b2d4b150SSteve Glendinning return smsc95xx_enter_suspend1(dev); 1480b2d4b150SSteve Glendinning } 1481b2d4b150SSteve Glendinning 1482b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n"); 1483b2d4b150SSteve Glendinning return smsc95xx_enter_suspend3(dev); 1484b2d4b150SSteve Glendinning } 1485b2d4b150SSteve Glendinning 1486b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) 1487b5a04475SSteve Glendinning { 1488b5a04475SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1489ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1490e5e3af83SSteve Glendinning u32 val, link_up; 1491b5a04475SSteve Glendinning int ret; 1492b5a04475SSteve Glendinning 14937b960c96SLukas Wunner pdata->pm_task = current; 14947b960c96SLukas Wunner 1495b5a04475SSteve Glendinning ret = usbnet_suspend(intf, message); 1496b052e073SSteve Glendinning if (ret < 0) { 1497b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_suspend error\n"); 14987b960c96SLukas Wunner pdata->pm_task = NULL; 1499b052e073SSteve Glendinning return ret; 1500b052e073SSteve Glendinning } 1501b5a04475SSteve Glendinning 1502b2d4b150SSteve Glendinning if (pdata->suspend_flags) { 1503b2d4b150SSteve Glendinning netdev_warn(dev->net, "error during last resume\n"); 1504b2d4b150SSteve Glendinning pdata->suspend_flags = 0; 1505b2d4b150SSteve Glendinning } 1506b2d4b150SSteve Glendinning 150731472429SLukas Wunner link_up = smsc95xx_link_ok(dev); 1508e5e3af83SSteve Glendinning 150942e21c01SMing Lei if (message.event == PM_EVENT_AUTO_SUSPEND && 1510eb970ff0SMing Lei (pdata->features & FEATURE_REMOTE_WAKEUP)) { 1511b2d4b150SSteve Glendinning ret = smsc95xx_autosuspend(dev, link_up); 1512b2d4b150SSteve Glendinning goto done; 1513b2d4b150SSteve Glendinning } 1514b2d4b150SSteve Glendinning 1515b2d4b150SSteve Glendinning /* if we get this far we're not autosuspending */ 1516e5e3af83SSteve Glendinning /* if no wol options set, or if link is down and we're not waking on 1517e5e3af83SSteve Glendinning * PHY activity, enter lowest power SUSPEND2 mode 1518e5e3af83SSteve Glendinning */ 1519e5e3af83SSteve Glendinning if (!(pdata->wolopts & SUPPORTED_WAKE) || 1520e5e3af83SSteve Glendinning !(link_up || (pdata->wolopts & WAKE_PHY))) { 15211e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND2 mode\n"); 1522b5a04475SSteve Glendinning 1523e0e474a8SSteve Glendinning /* disable energy detect (link up) & wake up events */ 152431472429SLukas Wunner ret = smsc95xx_read_reg(dev, WUCSR, &val); 1525e360a8b4SSteve Glendinning if (ret < 0) 1526b052e073SSteve Glendinning goto done; 1527e0e474a8SSteve Glendinning 1528e0e474a8SSteve Glendinning val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); 1529e0e474a8SSteve Glendinning 153031472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUCSR, val); 1531e360a8b4SSteve Glendinning if (ret < 0) 1532b052e073SSteve Glendinning goto done; 1533e0e474a8SSteve Glendinning 153431472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1535e360a8b4SSteve Glendinning if (ret < 0) 1536b052e073SSteve Glendinning goto done; 1537e0e474a8SSteve Glendinning 1538e0e474a8SSteve Glendinning val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); 1539e0e474a8SSteve Glendinning 154031472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1541e360a8b4SSteve Glendinning if (ret < 0) 1542b052e073SSteve Glendinning goto done; 1543e0e474a8SSteve Glendinning 15443b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend2(dev); 15453b9f7d8cSSteve Glendinning goto done; 1546b5a04475SSteve Glendinning } 1547b5a04475SSteve Glendinning 1548e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) { 1549e5e3af83SSteve Glendinning /* if link is down then configure EDPD and enter SUSPEND1, 1550e5e3af83SSteve Glendinning * otherwise enter SUSPEND0 below 1551e5e3af83SSteve Glendinning */ 1552e5e3af83SSteve Glendinning if (!link_up) { 15531e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND1 mode\n"); 15543b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend1(dev); 15553b9f7d8cSSteve Glendinning goto done; 1556e5e3af83SSteve Glendinning } 1557e5e3af83SSteve Glendinning } 1558e5e3af83SSteve Glendinning 1559bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 15606396bb22SKees Cook u32 *filter_mask = kcalloc(32, sizeof(u32), GFP_KERNEL); 156106a221beSMing Lei u32 command[2]; 156206a221beSMing Lei u32 offset[2]; 156306a221beSMing Lei u32 crc[4]; 15649ebca507SSteve Glendinning int wuff_filter_count = 15659ebca507SSteve Glendinning (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? 15669ebca507SSteve Glendinning LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; 1567bbd9f9eeSSteve Glendinning int i, filter = 0; 1568bbd9f9eeSSteve Glendinning 1569eed9a729SSteve Glendinning if (!filter_mask) { 1570eed9a729SSteve Glendinning netdev_warn(dev->net, "Unable to allocate filter_mask\n"); 15713b9f7d8cSSteve Glendinning ret = -ENOMEM; 15723b9f7d8cSSteve Glendinning goto done; 1573eed9a729SSteve Glendinning } 1574eed9a729SSteve Glendinning 157506a221beSMing Lei memset(command, 0, sizeof(command)); 157606a221beSMing Lei memset(offset, 0, sizeof(offset)); 157706a221beSMing Lei memset(crc, 0, sizeof(crc)); 157806a221beSMing Lei 1579bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_BCAST) { 1580bbd9f9eeSSteve Glendinning const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 15811e1d7412SJoe Perches netdev_info(dev->net, "enabling broadcast detection\n"); 1582bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1583bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1584bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1585bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1586bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1587bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1588bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(bcast, 6, filter); 1589bbd9f9eeSSteve Glendinning filter++; 1590bbd9f9eeSSteve Glendinning } 1591bbd9f9eeSSteve Glendinning 1592bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_MCAST) { 1593bbd9f9eeSSteve Glendinning const u8 mcast[] = {0x01, 0x00, 0x5E}; 15941e1d7412SJoe Perches netdev_info(dev->net, "enabling multicast detection\n"); 1595bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0007; 1596bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1597bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1598bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1599bbd9f9eeSSteve Glendinning command[filter/4] |= 0x09UL << ((filter % 4) * 8); 1600bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1601bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(mcast, 3, filter); 1602bbd9f9eeSSteve Glendinning filter++; 1603bbd9f9eeSSteve Glendinning } 1604bbd9f9eeSSteve Glendinning 1605bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_ARP) { 1606bbd9f9eeSSteve Glendinning const u8 arp[] = {0x08, 0x06}; 16071e1d7412SJoe Perches netdev_info(dev->net, "enabling ARP detection\n"); 1608bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0003; 1609bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1610bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1611bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1612bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1613bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x0C << ((filter % 4) * 8); 1614bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(arp, 2, filter); 1615bbd9f9eeSSteve Glendinning filter++; 1616bbd9f9eeSSteve Glendinning } 1617bbd9f9eeSSteve Glendinning 1618bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_UCAST) { 16191e1d7412SJoe Perches netdev_info(dev->net, "enabling unicast detection\n"); 1620bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1621bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1622bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1623bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1624bbd9f9eeSSteve Glendinning command[filter/4] |= 0x01UL << ((filter % 4) * 8); 1625bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1626bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); 1627bbd9f9eeSSteve Glendinning filter++; 1628bbd9f9eeSSteve Glendinning } 1629bbd9f9eeSSteve Glendinning 16309ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count * 4); i++) { 163131472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUFF, filter_mask[i]); 1632b052e073SSteve Glendinning if (ret < 0) { 163306a221beSMing Lei kfree(filter_mask); 1634b052e073SSteve Glendinning goto done; 1635b052e073SSteve Glendinning } 1636bbd9f9eeSSteve Glendinning } 163706a221beSMing Lei kfree(filter_mask); 1638bbd9f9eeSSteve Glendinning 16399ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 164031472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUFF, command[i]); 1641e360a8b4SSteve Glendinning if (ret < 0) 1642b052e073SSteve Glendinning goto done; 1643b052e073SSteve Glendinning } 1644bbd9f9eeSSteve Glendinning 16459ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 164631472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUFF, offset[i]); 1647e360a8b4SSteve Glendinning if (ret < 0) 1648b052e073SSteve Glendinning goto done; 1649b052e073SSteve Glendinning } 1650bbd9f9eeSSteve Glendinning 16519ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 2); i++) { 165231472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUFF, crc[i]); 1653e360a8b4SSteve Glendinning if (ret < 0) 1654b052e073SSteve Glendinning goto done; 1655b052e073SSteve Glendinning } 1656bbd9f9eeSSteve Glendinning 1657bbd9f9eeSSteve Glendinning /* clear any pending pattern match packet status */ 165831472429SLukas Wunner ret = smsc95xx_read_reg(dev, WUCSR, &val); 1659e360a8b4SSteve Glendinning if (ret < 0) 1660b052e073SSteve Glendinning goto done; 1661bbd9f9eeSSteve Glendinning 1662bbd9f9eeSSteve Glendinning val |= WUCSR_WUFR_; 1663bbd9f9eeSSteve Glendinning 166431472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUCSR, val); 1665e360a8b4SSteve Glendinning if (ret < 0) 1666b052e073SSteve Glendinning goto done; 1667b052e073SSteve Glendinning } 1668bbd9f9eeSSteve Glendinning 1669e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1670e0e474a8SSteve Glendinning /* clear any pending magic packet status */ 167131472429SLukas Wunner ret = smsc95xx_read_reg(dev, WUCSR, &val); 1672e360a8b4SSteve Glendinning if (ret < 0) 1673b052e073SSteve Glendinning goto done; 1674e0e474a8SSteve Glendinning 1675e0e474a8SSteve Glendinning val |= WUCSR_MPR_; 1676e0e474a8SSteve Glendinning 167731472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUCSR, val); 1678e360a8b4SSteve Glendinning if (ret < 0) 1679b052e073SSteve Glendinning goto done; 1680b052e073SSteve Glendinning } 1681e0e474a8SSteve Glendinning 1682bbd9f9eeSSteve Glendinning /* enable/disable wakeup sources */ 168331472429SLukas Wunner ret = smsc95xx_read_reg(dev, WUCSR, &val); 1684e360a8b4SSteve Glendinning if (ret < 0) 1685b052e073SSteve Glendinning goto done; 1686e0e474a8SSteve Glendinning 1687bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 16881e1d7412SJoe Perches netdev_info(dev->net, "enabling pattern match wakeup\n"); 1689bbd9f9eeSSteve Glendinning val |= WUCSR_WAKE_EN_; 1690bbd9f9eeSSteve Glendinning } else { 16911e1d7412SJoe Perches netdev_info(dev->net, "disabling pattern match wakeup\n"); 1692bbd9f9eeSSteve Glendinning val &= ~WUCSR_WAKE_EN_; 1693bbd9f9eeSSteve Glendinning } 1694bbd9f9eeSSteve Glendinning 1695e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 16961e1d7412SJoe Perches netdev_info(dev->net, "enabling magic packet wakeup\n"); 1697e0e474a8SSteve Glendinning val |= WUCSR_MPEN_; 1698e0e474a8SSteve Glendinning } else { 16991e1d7412SJoe Perches netdev_info(dev->net, "disabling magic packet wakeup\n"); 1700e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1701e0e474a8SSteve Glendinning } 1702e0e474a8SSteve Glendinning 170331472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUCSR, val); 1704e360a8b4SSteve Glendinning if (ret < 0) 1705b052e073SSteve Glendinning goto done; 1706e0e474a8SSteve Glendinning 1707e0e474a8SSteve Glendinning /* enable wol wakeup source */ 170831472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1709e360a8b4SSteve Glendinning if (ret < 0) 1710b052e073SSteve Glendinning goto done; 1711e0e474a8SSteve Glendinning 1712e0e474a8SSteve Glendinning val |= PM_CTL_WOL_EN_; 1713e0e474a8SSteve Glendinning 1714e5e3af83SSteve Glendinning /* phy energy detect wakeup source */ 1715e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1716e5e3af83SSteve Glendinning val |= PM_CTL_ED_EN_; 1717e5e3af83SSteve Glendinning 171831472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1719e360a8b4SSteve Glendinning if (ret < 0) 1720b052e073SSteve Glendinning goto done; 1721e0e474a8SSteve Glendinning 1722bbd9f9eeSSteve Glendinning /* enable receiver to enable frame reception */ 172331472429SLukas Wunner smsc95xx_start_rx_path(dev); 1724e0e474a8SSteve Glendinning 1725e0e474a8SSteve Glendinning /* some wol options are enabled, so enter SUSPEND0 */ 17261e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND0 mode\n"); 17273b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend0(dev); 17283b9f7d8cSSteve Glendinning 17293b9f7d8cSSteve Glendinning done: 17300d41be53SMing Lei /* 17310d41be53SMing Lei * TODO: resume() might need to handle the suspend failure 17320d41be53SMing Lei * in system sleep 17330d41be53SMing Lei */ 17340d41be53SMing Lei if (ret && PMSG_IS_AUTO(message)) 17353b9f7d8cSSteve Glendinning usbnet_resume(intf); 17367b900eadSFrieder Schrempf 17377b960c96SLukas Wunner pdata->pm_task = NULL; 17383b9f7d8cSSteve Glendinning return ret; 1739e0e474a8SSteve Glendinning } 1740e0e474a8SSteve Glendinning 1741e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf) 1742e0e474a8SSteve Glendinning { 1743e0e474a8SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 17448bca81d9SSudip Mukherjee struct smsc95xx_priv *pdata; 17458bca81d9SSudip Mukherjee u8 suspend_flags; 1746e0e474a8SSteve Glendinning int ret; 1747e0e474a8SSteve Glendinning u32 val; 1748e0e474a8SSteve Glendinning 1749e0e474a8SSteve Glendinning BUG_ON(!dev); 1750ad90a73fSAndre Edich pdata = dev->driver_priv; 17518bca81d9SSudip Mukherjee suspend_flags = pdata->suspend_flags; 1752e0e474a8SSteve Glendinning 1753b2d4b150SSteve Glendinning netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags); 1754b2d4b150SSteve Glendinning 1755b2d4b150SSteve Glendinning /* do this first to ensure it's cleared even in error case */ 1756b2d4b150SSteve Glendinning pdata->suspend_flags = 0; 1757b2d4b150SSteve Glendinning 17587b960c96SLukas Wunner pdata->pm_task = current; 17597b960c96SLukas Wunner 1760b2d4b150SSteve Glendinning if (suspend_flags & SUSPEND_ALLMODES) { 1761bbd9f9eeSSteve Glendinning /* clear wake-up sources */ 176231472429SLukas Wunner ret = smsc95xx_read_reg(dev, WUCSR, &val); 1763e360a8b4SSteve Glendinning if (ret < 0) 17647b960c96SLukas Wunner goto done; 1765e0e474a8SSteve Glendinning 1766bbd9f9eeSSteve Glendinning val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); 1767e0e474a8SSteve Glendinning 176831472429SLukas Wunner ret = smsc95xx_write_reg(dev, WUCSR, val); 1769e360a8b4SSteve Glendinning if (ret < 0) 17707b960c96SLukas Wunner goto done; 1771e0e474a8SSteve Glendinning 1772e0e474a8SSteve Glendinning /* clear wake-up status */ 177331472429SLukas Wunner ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1774e360a8b4SSteve Glendinning if (ret < 0) 17757b960c96SLukas Wunner goto done; 1776e0e474a8SSteve Glendinning 1777e0e474a8SSteve Glendinning val &= ~PM_CTL_WOL_EN_; 1778e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_; 1779e0e474a8SSteve Glendinning 178031472429SLukas Wunner ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1781e360a8b4SSteve Glendinning if (ret < 0) 17827b960c96SLukas Wunner goto done; 1783b052e073SSteve Glendinning } 1784e0e474a8SSteve Glendinning 17851ce8b372SLukas Wunner phy_init_hw(pdata->phydev); 17861ce8b372SLukas Wunner 1787af3d7c1eSSteve Glendinning ret = usbnet_resume(intf); 1788b052e073SSteve Glendinning if (ret < 0) 1789b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_resume error\n"); 1790e0e474a8SSteve Glendinning 17917b960c96SLukas Wunner done: 17927b960c96SLukas Wunner pdata->pm_task = NULL; 1793b052e073SSteve Glendinning return ret; 1794e0e474a8SSteve Glendinning } 1795e0e474a8SSteve Glendinning 1796b4df480fSJoonyoung Shim static int smsc95xx_reset_resume(struct usb_interface *intf) 1797b4df480fSJoonyoung Shim { 1798b4df480fSJoonyoung Shim struct usbnet *dev = usb_get_intfdata(intf); 17997b960c96SLukas Wunner struct smsc95xx_priv *pdata = dev->driver_priv; 1800b4df480fSJoonyoung Shim int ret; 1801b4df480fSJoonyoung Shim 18027b960c96SLukas Wunner pdata->pm_task = current; 1803b4df480fSJoonyoung Shim ret = smsc95xx_reset(dev); 18047b960c96SLukas Wunner pdata->pm_task = NULL; 1805b4df480fSJoonyoung Shim if (ret < 0) 1806b4df480fSJoonyoung Shim return ret; 1807b4df480fSJoonyoung Shim 1808b4df480fSJoonyoung Shim return smsc95xx_resume(intf); 1809b4df480fSJoonyoung Shim } 1810b4df480fSJoonyoung Shim 18112f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb) 18122f7ca802SSteve Glendinning { 1813*d50729f1SEric Dumazet u16 *csum_ptr = (u16 *)(skb_tail_pointer(skb) - 2); 1814*d50729f1SEric Dumazet 1815*d50729f1SEric Dumazet skb->csum = (__force __wsum)get_unaligned(csum_ptr); 18162f7ca802SSteve Glendinning skb->ip_summed = CHECKSUM_COMPLETE; 1817*d50729f1SEric Dumazet skb_trim(skb, skb->len - 2); /* remove csum */ 18182f7ca802SSteve Glendinning } 18192f7ca802SSteve Glendinning 18202f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 18212f7ca802SSteve Glendinning { 1822eb85569fSEmil Goode /* This check is no longer done by usbnet */ 1823eb85569fSEmil Goode if (skb->len < dev->net->hard_header_len) 1824eb85569fSEmil Goode return 0; 1825eb85569fSEmil Goode 18262f7ca802SSteve Glendinning while (skb->len > 0) { 18272f7ca802SSteve Glendinning u32 header, align_count; 18282f7ca802SSteve Glendinning struct sk_buff *ax_skb; 18292f7ca802SSteve Glendinning unsigned char *packet; 18302f7ca802SSteve Glendinning u16 size; 18312f7ca802SSteve Glendinning 18326809d216SBen Dooks header = get_unaligned_le32(skb->data); 18332f7ca802SSteve Glendinning skb_pull(skb, 4 + NET_IP_ALIGN); 18342f7ca802SSteve Glendinning packet = skb->data; 18352f7ca802SSteve Glendinning 18362f7ca802SSteve Glendinning /* get the packet length */ 18372f7ca802SSteve Glendinning size = (u16)((header & RX_STS_FL_) >> 16); 18382f7ca802SSteve Glendinning align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 18392f7ca802SSteve Glendinning 1840ff821092SSzymon Heidrich if (unlikely(size > skb->len)) { 1841ff821092SSzymon Heidrich netif_dbg(dev, rx_err, dev->net, 1842ff821092SSzymon Heidrich "size err header=0x%08x\n", header); 1843ff821092SSzymon Heidrich return 0; 1844ff821092SSzymon Heidrich } 1845ff821092SSzymon Heidrich 18462f7ca802SSteve Glendinning if (unlikely(header & RX_STS_ES_)) { 1847a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1848a475f603SJoe Perches "Error header=0x%08x\n", header); 184980667ac1SHerbert Xu dev->net->stats.rx_errors++; 185080667ac1SHerbert Xu dev->net->stats.rx_dropped++; 18512f7ca802SSteve Glendinning 18522f7ca802SSteve Glendinning if (header & RX_STS_CRC_) { 185380667ac1SHerbert Xu dev->net->stats.rx_crc_errors++; 18542f7ca802SSteve Glendinning } else { 18552f7ca802SSteve Glendinning if (header & (RX_STS_TL_ | RX_STS_RF_)) 185680667ac1SHerbert Xu dev->net->stats.rx_frame_errors++; 18572f7ca802SSteve Glendinning 18582f7ca802SSteve Glendinning if ((header & RX_STS_LE_) && 18592f7ca802SSteve Glendinning (!(header & RX_STS_FT_))) 186080667ac1SHerbert Xu dev->net->stats.rx_length_errors++; 18612f7ca802SSteve Glendinning } 18622f7ca802SSteve Glendinning } else { 18632f7ca802SSteve Glendinning /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ 18642f7ca802SSteve Glendinning if (unlikely(size > (ETH_FRAME_LEN + 12))) { 1865a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1866a475f603SJoe Perches "size err header=0x%08x\n", header); 18672f7ca802SSteve Glendinning return 0; 18682f7ca802SSteve Glendinning } 18692f7ca802SSteve Glendinning 18702f7ca802SSteve Glendinning /* last frame in this batch */ 18712f7ca802SSteve Glendinning if (skb->len == size) { 187278e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 18732f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(skb); 1874df18accaSPeter Korsgaard skb_trim(skb, skb->len - 4); /* remove fcs */ 18752f7ca802SSteve Glendinning 18762f7ca802SSteve Glendinning return 1; 18772f7ca802SSteve Glendinning } 18782f7ca802SSteve Glendinning 1879*d50729f1SEric Dumazet ax_skb = netdev_alloc_skb_ip_align(dev->net, size); 18802f7ca802SSteve Glendinning if (unlikely(!ax_skb)) { 188160b86755SJoe Perches netdev_warn(dev->net, "Error allocating skb\n"); 18822f7ca802SSteve Glendinning return 0; 18832f7ca802SSteve Glendinning } 18842f7ca802SSteve Glendinning 1885*d50729f1SEric Dumazet skb_put(ax_skb, size); 1886*d50729f1SEric Dumazet memcpy(ax_skb->data, packet, size); 18872f7ca802SSteve Glendinning 188878e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 18892f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(ax_skb); 1890df18accaSPeter Korsgaard skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 18912f7ca802SSteve Glendinning 18922f7ca802SSteve Glendinning usbnet_skb_return(dev, ax_skb); 18932f7ca802SSteve Glendinning } 18942f7ca802SSteve Glendinning 18952f7ca802SSteve Glendinning skb_pull(skb, size); 18962f7ca802SSteve Glendinning 18972f7ca802SSteve Glendinning /* padding bytes before the next frame starts */ 18982f7ca802SSteve Glendinning if (skb->len) 18992f7ca802SSteve Glendinning skb_pull(skb, align_count); 19002f7ca802SSteve Glendinning } 19012f7ca802SSteve Glendinning 19022f7ca802SSteve Glendinning return 1; 19032f7ca802SSteve Glendinning } 19042f7ca802SSteve Glendinning 1905f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) 1906f7b29271SSteve Glendinning { 190755508d60SMichał Mirosław u16 low_16 = (u16)skb_checksum_start_offset(skb); 190855508d60SMichał Mirosław u16 high_16 = low_16 + skb->csum_offset; 1909f7b29271SSteve Glendinning return (high_16 << 16) | low_16; 1910f7b29271SSteve Glendinning } 1911f7b29271SSteve Glendinning 191275938f77SBen Dooks /* The TX CSUM won't work if the checksum lies in the last 4 bytes of the 191375938f77SBen Dooks * transmission. This is fairly unlikely, only seems to trigger with some 191475938f77SBen Dooks * short TCP ACK packets sent. 191575938f77SBen Dooks * 191675938f77SBen Dooks * Note, this calculation should probably check for the alignment of the 191775938f77SBen Dooks * data as well, but a straight check for csum being in the last four bytes 191875938f77SBen Dooks * of the packet should be ok for now. 191975938f77SBen Dooks */ 192075938f77SBen Dooks static bool smsc95xx_can_tx_checksum(struct sk_buff *skb) 192175938f77SBen Dooks { 192275938f77SBen Dooks unsigned int len = skb->len - skb_checksum_start_offset(skb); 192375938f77SBen Dooks 192475938f77SBen Dooks if (skb->len <= 45) 192575938f77SBen Dooks return false; 192675938f77SBen Dooks return skb->csum_offset < (len - (4 + 1)); 192775938f77SBen Dooks } 192875938f77SBen Dooks 19292f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 19302f7ca802SSteve Glendinning struct sk_buff *skb, gfp_t flags) 19312f7ca802SSteve Glendinning { 193278e47fe4SMichał Mirosław bool csum = skb->ip_summed == CHECKSUM_PARTIAL; 1933f7b29271SSteve Glendinning int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; 19342f7ca802SSteve Glendinning u32 tx_cmd_a, tx_cmd_b; 19350c8b2655SBen Dooks void *ptr; 19362f7ca802SSteve Glendinning 1937f7b29271SSteve Glendinning /* We do not advertise SG, so skbs should be already linearized */ 1938f7b29271SSteve Glendinning BUG_ON(skb_shinfo(skb)->nr_frags); 1939f7b29271SSteve Glendinning 1940e9156cd2SJames Hughes /* Make writable and expand header space by overhead if required */ 1941e9156cd2SJames Hughes if (skb_cow_head(skb, overhead)) { 1942e9156cd2SJames Hughes /* Must deallocate here as returning NULL to indicate error 1943e9156cd2SJames Hughes * means the skb won't be deallocated in the caller. 1944e9156cd2SJames Hughes */ 19452f7ca802SSteve Glendinning dev_kfree_skb_any(skb); 19462f7ca802SSteve Glendinning return NULL; 19472f7ca802SSteve Glendinning } 19482f7ca802SSteve Glendinning 19490c8b2655SBen Dooks tx_cmd_b = (u32)skb->len; 19500c8b2655SBen Dooks tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_; 19510c8b2655SBen Dooks 1952f7b29271SSteve Glendinning if (csum) { 195375938f77SBen Dooks if (!smsc95xx_can_tx_checksum(skb)) { 195411bc3088SSteve Glendinning /* workaround - hardware tx checksum does not work 195511bc3088SSteve Glendinning * properly with extremely small packets */ 195655508d60SMichał Mirosław long csstart = skb_checksum_start_offset(skb); 195711bc3088SSteve Glendinning __wsum calc = csum_partial(skb->data + csstart, 195811bc3088SSteve Glendinning skb->len - csstart, 0); 195911bc3088SSteve Glendinning *((__sum16 *)(skb->data + csstart 196011bc3088SSteve Glendinning + skb->csum_offset)) = csum_fold(calc); 196111bc3088SSteve Glendinning 196211bc3088SSteve Glendinning csum = false; 196311bc3088SSteve Glendinning } else { 1964f7b29271SSteve Glendinning u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); 19650c8b2655SBen Dooks ptr = skb_push(skb, 4); 19660c8b2655SBen Dooks put_unaligned_le32(csum_preamble, ptr); 1967f7b29271SSteve Glendinning 19680c8b2655SBen Dooks tx_cmd_a += 4; 19690c8b2655SBen Dooks tx_cmd_b += 4; 1970f7b29271SSteve Glendinning tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; 19710c8b2655SBen Dooks } 19720c8b2655SBen Dooks } 19732f7ca802SSteve Glendinning 19740c8b2655SBen Dooks ptr = skb_push(skb, 8); 19750c8b2655SBen Dooks put_unaligned_le32(tx_cmd_a, ptr); 19760c8b2655SBen Dooks put_unaligned_le32(tx_cmd_b, ptr+4); 19772f7ca802SSteve Glendinning 19782f7ca802SSteve Glendinning return skb; 19792f7ca802SSteve Glendinning } 19802f7ca802SSteve Glendinning 1981b2d4b150SSteve Glendinning static int smsc95xx_manage_power(struct usbnet *dev, int on) 1982b2d4b150SSteve Glendinning { 1983ad90a73fSAndre Edich struct smsc95xx_priv *pdata = dev->driver_priv; 1984b2d4b150SSteve Glendinning 1985b2d4b150SSteve Glendinning dev->intf->needs_remote_wakeup = on; 1986b2d4b150SSteve Glendinning 1987eb970ff0SMing Lei if (pdata->features & FEATURE_REMOTE_WAKEUP) 1988b2d4b150SSteve Glendinning return 0; 1989b2d4b150SSteve Glendinning 1990eb970ff0SMing Lei /* this chip revision isn't capable of remote wakeup */ 1991eb970ff0SMing Lei netdev_info(dev->net, "hardware isn't capable of remote wakeup\n"); 1992b2d4b150SSteve Glendinning 1993b2d4b150SSteve Glendinning if (on) 1994b2d4b150SSteve Glendinning usb_autopm_get_interface_no_resume(dev->intf); 1995b2d4b150SSteve Glendinning else 1996b2d4b150SSteve Glendinning usb_autopm_put_interface(dev->intf); 1997b2d4b150SSteve Glendinning 1998b2d4b150SSteve Glendinning return 0; 1999b2d4b150SSteve Glendinning } 2000b2d4b150SSteve Glendinning 20012f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = { 20022f7ca802SSteve Glendinning .description = "smsc95xx USB 2.0 Ethernet", 20032f7ca802SSteve Glendinning .bind = smsc95xx_bind, 20042f7ca802SSteve Glendinning .unbind = smsc95xx_unbind, 20050bf38853SMarkus Reichl .reset = smsc95xx_reset, 20060bf38853SMarkus Reichl .check_connect = smsc95xx_start_phy, 2007a049a30fSMartyn Welch .stop = smsc95xx_stop, 20082f7ca802SSteve Glendinning .rx_fixup = smsc95xx_rx_fixup, 20092f7ca802SSteve Glendinning .tx_fixup = smsc95xx_tx_fixup, 20102f7ca802SSteve Glendinning .status = smsc95xx_status, 2011b2d4b150SSteve Glendinning .manage_power = smsc95xx_manage_power, 201207d69d42SPaolo Pisati .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, 20132f7ca802SSteve Glendinning }; 20142f7ca802SSteve Glendinning 20152f7ca802SSteve Glendinning static const struct usb_device_id products[] = { 20162f7ca802SSteve Glendinning { 20172f7ca802SSteve Glendinning /* SMSC9500 USB Ethernet Device */ 20182f7ca802SSteve Glendinning USB_DEVICE(0x0424, 0x9500), 20192f7ca802SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20202f7ca802SSteve Glendinning }, 2021726474b8SSteve Glendinning { 20226f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device */ 20236f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9505), 20246f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20256f41d12bSSteve Glendinning }, 20266f41d12bSSteve Glendinning { 20276f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device */ 20286f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E00), 20296f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20306f41d12bSSteve Glendinning }, 20316f41d12bSSteve Glendinning { 20326f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device */ 20336f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E01), 20346f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20356f41d12bSSteve Glendinning }, 20366f41d12bSSteve Glendinning { 2037726474b8SSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device */ 2038726474b8SSteve Glendinning USB_DEVICE(0x0424, 0xec00), 2039726474b8SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 2040726474b8SSteve Glendinning }, 20416f41d12bSSteve Glendinning { 20426f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (SAL10) */ 20436f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9900), 20446f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20456f41d12bSSteve Glendinning }, 20466f41d12bSSteve Glendinning { 20476f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device (SAL10) */ 20486f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9901), 20496f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20506f41d12bSSteve Glendinning }, 20516f41d12bSSteve Glendinning { 20526f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (SAL10) */ 20536f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9902), 20546f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20556f41d12bSSteve Glendinning }, 20566f41d12bSSteve Glendinning { 20576f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (SAL10) */ 20586f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9903), 20596f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20606f41d12bSSteve Glendinning }, 20616f41d12bSSteve Glendinning { 20626f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ 20636f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9904), 20646f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20656f41d12bSSteve Glendinning }, 20666f41d12bSSteve Glendinning { 20676f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (HAL) */ 20686f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9905), 20696f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20706f41d12bSSteve Glendinning }, 20716f41d12bSSteve Glendinning { 20726f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (HAL) */ 20736f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9906), 20746f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20756f41d12bSSteve Glendinning }, 20766f41d12bSSteve Glendinning { 20776f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (Alternate ID) */ 20786f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9907), 20796f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20806f41d12bSSteve Glendinning }, 20816f41d12bSSteve Glendinning { 20826f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (Alternate ID) */ 20836f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9908), 20846f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20856f41d12bSSteve Glendinning }, 20866f41d12bSSteve Glendinning { 20876f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ 20886f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9909), 20896f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20906f41d12bSSteve Glendinning }, 209188edaa41SSteve Glendinning { 209288edaa41SSteve Glendinning /* SMSC LAN9530 USB Ethernet Device */ 209388edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9530), 209488edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 209588edaa41SSteve Glendinning }, 209688edaa41SSteve Glendinning { 209788edaa41SSteve Glendinning /* SMSC LAN9730 USB Ethernet Device */ 209888edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9730), 209988edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 210088edaa41SSteve Glendinning }, 210188edaa41SSteve Glendinning { 210288edaa41SSteve Glendinning /* SMSC LAN89530 USB Ethernet Device */ 210388edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9E08), 210488edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 210588edaa41SSteve Glendinning }, 21064066bf4cSParthiban Veerasooran { 210745532b21SAndre Werner /* SYSTEC USB-SPEmodule1 10BASE-T1L Ethernet Device */ 210845532b21SAndre Werner USB_DEVICE(0x0878, 0x1400), 210945532b21SAndre Werner .driver_info = (unsigned long)&smsc95xx_info, 211045532b21SAndre Werner }, 211145532b21SAndre Werner { 21124066bf4cSParthiban Veerasooran /* Microchip's EVB-LAN8670-USB 10BASE-T1S Ethernet Device */ 21134066bf4cSParthiban Veerasooran USB_DEVICE(0x184F, 0x0051), 21144066bf4cSParthiban Veerasooran .driver_info = (unsigned long)&smsc95xx_info, 21154066bf4cSParthiban Veerasooran }, 21162f7ca802SSteve Glendinning { }, /* END */ 21172f7ca802SSteve Glendinning }; 21182f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products); 21192f7ca802SSteve Glendinning 21202f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = { 21212f7ca802SSteve Glendinning .name = "smsc95xx", 21222f7ca802SSteve Glendinning .id_table = products, 21232f7ca802SSteve Glendinning .probe = usbnet_probe, 2124b5a04475SSteve Glendinning .suspend = smsc95xx_suspend, 2125e0e474a8SSteve Glendinning .resume = smsc95xx_resume, 2126b4df480fSJoonyoung Shim .reset_resume = smsc95xx_reset_resume, 21272f7ca802SSteve Glendinning .disconnect = usbnet_disconnect, 2128e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 2129b2d4b150SSteve Glendinning .supports_autosuspend = 1, 21302f7ca802SSteve Glendinning }; 21312f7ca802SSteve Glendinning 2132d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver); 21332f7ca802SSteve Glendinning 21342f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin"); 213590b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); 21362f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); 21372f7ca802SSteve Glendinning MODULE_LICENSE("GPL"); 2138