12f7ca802SSteve Glendinning /*************************************************************************** 22f7ca802SSteve Glendinning * 32f7ca802SSteve Glendinning * Copyright (C) 2007-2008 SMSC 42f7ca802SSteve Glendinning * 52f7ca802SSteve Glendinning * This program is free software; you can redistribute it and/or 62f7ca802SSteve Glendinning * modify it under the terms of the GNU General Public License 72f7ca802SSteve Glendinning * as published by the Free Software Foundation; either version 2 82f7ca802SSteve Glendinning * of the License, or (at your option) any later version. 92f7ca802SSteve Glendinning * 102f7ca802SSteve Glendinning * This program is distributed in the hope that it will be useful, 112f7ca802SSteve Glendinning * but WITHOUT ANY WARRANTY; without even the implied warranty of 122f7ca802SSteve Glendinning * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 132f7ca802SSteve Glendinning * GNU General Public License for more details. 142f7ca802SSteve Glendinning * 152f7ca802SSteve Glendinning * You should have received a copy of the GNU General Public License 162f7ca802SSteve Glendinning * along with this program; if not, write to the Free Software 172f7ca802SSteve Glendinning * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 182f7ca802SSteve Glendinning * 192f7ca802SSteve Glendinning *****************************************************************************/ 202f7ca802SSteve Glendinning 212f7ca802SSteve Glendinning #include <linux/module.h> 222f7ca802SSteve Glendinning #include <linux/kmod.h> 232f7ca802SSteve Glendinning #include <linux/init.h> 242f7ca802SSteve Glendinning #include <linux/netdevice.h> 252f7ca802SSteve Glendinning #include <linux/etherdevice.h> 262f7ca802SSteve Glendinning #include <linux/ethtool.h> 272f7ca802SSteve Glendinning #include <linux/mii.h> 282f7ca802SSteve Glendinning #include <linux/usb.h> 29bbd9f9eeSSteve Glendinning #include <linux/bitrev.h> 30bbd9f9eeSSteve Glendinning #include <linux/crc16.h> 312f7ca802SSteve Glendinning #include <linux/crc32.h> 322f7ca802SSteve Glendinning #include <linux/usb/usbnet.h> 335a0e3ad6STejun Heo #include <linux/slab.h> 342f7ca802SSteve Glendinning #include "smsc95xx.h" 352f7ca802SSteve Glendinning 362f7ca802SSteve Glendinning #define SMSC_CHIPNAME "smsc95xx" 37f7b29271SSteve Glendinning #define SMSC_DRIVER_VERSION "1.0.4" 382f7ca802SSteve Glendinning #define HS_USB_PKT_SIZE (512) 392f7ca802SSteve Glendinning #define FS_USB_PKT_SIZE (64) 402f7ca802SSteve Glendinning #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) 412f7ca802SSteve Glendinning #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) 422f7ca802SSteve Glendinning #define DEFAULT_BULK_IN_DELAY (0x00002000) 432f7ca802SSteve Glendinning #define MAX_SINGLE_PACKET_SIZE (2048) 442f7ca802SSteve Glendinning #define LAN95XX_EEPROM_MAGIC (0x9500) 452f7ca802SSteve Glendinning #define EEPROM_MAC_OFFSET (0x01) 46f7b29271SSteve Glendinning #define DEFAULT_TX_CSUM_ENABLE (true) 472f7ca802SSteve Glendinning #define DEFAULT_RX_CSUM_ENABLE (true) 482f7ca802SSteve Glendinning #define SMSC95XX_INTERNAL_PHY_ID (1) 492f7ca802SSteve Glendinning #define SMSC95XX_TX_OVERHEAD (8) 50f7b29271SSteve Glendinning #define SMSC95XX_TX_OVERHEAD_CSUM (12) 51*e5e3af83SSteve Glendinning #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \ 52bbd9f9eeSSteve Glendinning WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) 532f7ca802SSteve Glendinning 549ebca507SSteve Glendinning #define FEATURE_8_WAKEUP_FILTERS (0x01) 559ebca507SSteve Glendinning #define FEATURE_PHY_NLP_CROSSOVER (0x02) 569ebca507SSteve Glendinning #define FEATURE_AUTOSUSPEND (0x04) 579ebca507SSteve Glendinning 58769ea6d8SSteve Glendinning #define check_warn(ret, fmt, args...) \ 59769ea6d8SSteve Glendinning ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); }) 60769ea6d8SSteve Glendinning 61769ea6d8SSteve Glendinning #define check_warn_return(ret, fmt, args...) \ 62769ea6d8SSteve Glendinning ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } }) 63769ea6d8SSteve Glendinning 64769ea6d8SSteve Glendinning #define check_warn_goto_done(ret, fmt, args...) \ 65769ea6d8SSteve Glendinning ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } }) 66769ea6d8SSteve Glendinning 672f7ca802SSteve Glendinning struct smsc95xx_priv { 682f7ca802SSteve Glendinning u32 mac_cr; 693c0f3c60SMarc Zyngier u32 hash_hi; 703c0f3c60SMarc Zyngier u32 hash_lo; 71e0e474a8SSteve Glendinning u32 wolopts; 722f7ca802SSteve Glendinning spinlock_t mac_cr_lock; 739ebca507SSteve Glendinning u8 features; 742f7ca802SSteve Glendinning }; 752f7ca802SSteve Glendinning 76eb939922SRusty Russell static bool turbo_mode = true; 772f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644); 782f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); 792f7ca802SSteve Glendinning 80ec32115dSMing Lei static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, 81ec32115dSMing Lei u32 *data, int in_pm) 822f7ca802SSteve Glendinning { 8372108fd2SMing Lei u32 buf; 842f7ca802SSteve Glendinning int ret; 85ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 862f7ca802SSteve Glendinning 872f7ca802SSteve Glendinning BUG_ON(!dev); 882f7ca802SSteve Glendinning 89ec32115dSMing Lei if (!in_pm) 90ec32115dSMing Lei fn = usbnet_read_cmd; 91ec32115dSMing Lei else 92ec32115dSMing Lei fn = usbnet_read_cmd_nopm; 93ec32115dSMing Lei 94ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN 95ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 9672108fd2SMing Lei 0, index, &buf, 4); 972f7ca802SSteve Glendinning if (unlikely(ret < 0)) 98ec32115dSMing Lei netdev_warn(dev->net, 99ec32115dSMing Lei "Failed to read reg index 0x%08x: %d", index, ret); 1002f7ca802SSteve Glendinning 10172108fd2SMing Lei le32_to_cpus(&buf); 10272108fd2SMing Lei *data = buf; 1032f7ca802SSteve Glendinning 1042f7ca802SSteve Glendinning return ret; 1052f7ca802SSteve Glendinning } 1062f7ca802SSteve Glendinning 107ec32115dSMing Lei static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index, 108ec32115dSMing Lei u32 data, int in_pm) 1092f7ca802SSteve Glendinning { 11072108fd2SMing Lei u32 buf; 1112f7ca802SSteve Glendinning int ret; 112ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 1132f7ca802SSteve Glendinning 1142f7ca802SSteve Glendinning BUG_ON(!dev); 1152f7ca802SSteve Glendinning 116ec32115dSMing Lei if (!in_pm) 117ec32115dSMing Lei fn = usbnet_write_cmd; 118ec32115dSMing Lei else 119ec32115dSMing Lei fn = usbnet_write_cmd_nopm; 120ec32115dSMing Lei 12172108fd2SMing Lei buf = data; 12272108fd2SMing Lei cpu_to_le32s(&buf); 1232f7ca802SSteve Glendinning 124ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT 125ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 12672108fd2SMing Lei 0, index, &buf, 4); 1272f7ca802SSteve Glendinning if (unlikely(ret < 0)) 128ec32115dSMing Lei netdev_warn(dev->net, 129ec32115dSMing Lei "Failed to write reg index 0x%08x: %d", index, ret); 1302f7ca802SSteve Glendinning 1312f7ca802SSteve Glendinning return ret; 1322f7ca802SSteve Glendinning } 1332f7ca802SSteve Glendinning 134ec32115dSMing Lei static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index, 135ec32115dSMing Lei u32 *data) 136ec32115dSMing Lei { 137ec32115dSMing Lei return __smsc95xx_read_reg(dev, index, data, 1); 138ec32115dSMing Lei } 139ec32115dSMing Lei 140ec32115dSMing Lei static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index, 141ec32115dSMing Lei u32 data) 142ec32115dSMing Lei { 143ec32115dSMing Lei return __smsc95xx_write_reg(dev, index, data, 1); 144ec32115dSMing Lei } 145ec32115dSMing Lei 146ec32115dSMing Lei static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, 147ec32115dSMing Lei u32 *data) 148ec32115dSMing Lei { 149ec32115dSMing Lei return __smsc95xx_read_reg(dev, index, data, 0); 150ec32115dSMing Lei } 151ec32115dSMing Lei 152ec32115dSMing Lei static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, 153ec32115dSMing Lei u32 data) 154ec32115dSMing Lei { 155ec32115dSMing Lei return __smsc95xx_write_reg(dev, index, data, 0); 156ec32115dSMing Lei } 157e0e474a8SSteve Glendinning static int smsc95xx_set_feature(struct usbnet *dev, u32 feature) 158e0e474a8SSteve Glendinning { 159e0e474a8SSteve Glendinning if (WARN_ON_ONCE(!dev)) 160e0e474a8SSteve Glendinning return -EINVAL; 161e0e474a8SSteve Glendinning 162ec32115dSMing Lei return usbnet_write_cmd_nopm(dev, USB_REQ_SET_FEATURE, 163ec32115dSMing Lei USB_RECIP_DEVICE, feature, 0, 164ec32115dSMing Lei NULL, 0); 165e0e474a8SSteve Glendinning } 166e0e474a8SSteve Glendinning 167e0e474a8SSteve Glendinning static int smsc95xx_clear_feature(struct usbnet *dev, u32 feature) 168e0e474a8SSteve Glendinning { 169e0e474a8SSteve Glendinning if (WARN_ON_ONCE(!dev)) 170e0e474a8SSteve Glendinning return -EINVAL; 171e0e474a8SSteve Glendinning 172ec32115dSMing Lei return usbnet_write_cmd_nopm(dev, USB_REQ_CLEAR_FEATURE, 173ec32115dSMing Lei USB_RECIP_DEVICE, feature, 174ec32115dSMing Lei 0, NULL, 0); 175e0e474a8SSteve Glendinning } 176e0e474a8SSteve Glendinning 1772f7ca802SSteve Glendinning /* Loop until the read is completed with timeout 1782f7ca802SSteve Glendinning * called with phy_mutex held */ 179*e5e3af83SSteve Glendinning static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev, 180*e5e3af83SSteve Glendinning int in_pm) 1812f7ca802SSteve Glendinning { 1822f7ca802SSteve Glendinning unsigned long start_time = jiffies; 1832f7ca802SSteve Glendinning u32 val; 184769ea6d8SSteve Glendinning int ret; 1852f7ca802SSteve Glendinning 1862f7ca802SSteve Glendinning do { 187*e5e3af83SSteve Glendinning ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm); 188769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading MII_ACCESS"); 1892f7ca802SSteve Glendinning if (!(val & MII_BUSY_)) 1902f7ca802SSteve Glendinning return 0; 1912f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 1922f7ca802SSteve Glendinning 1932f7ca802SSteve Glendinning return -EIO; 1942f7ca802SSteve Glendinning } 1952f7ca802SSteve Glendinning 196*e5e3af83SSteve Glendinning static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx, 197*e5e3af83SSteve Glendinning int in_pm) 1982f7ca802SSteve Glendinning { 1992f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 2002f7ca802SSteve Glendinning u32 val, addr; 201769ea6d8SSteve Glendinning int ret; 2022f7ca802SSteve Glendinning 2032f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 2042f7ca802SSteve Glendinning 2052f7ca802SSteve Glendinning /* confirm MII not busy */ 206*e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 207769ea6d8SSteve Glendinning check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_read"); 2082f7ca802SSteve Glendinning 2092f7ca802SSteve Glendinning /* set the address, index & direction (read from PHY) */ 2102f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 2112f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 21280928805SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_; 213*e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); 214769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error writing MII_ADDR"); 2152f7ca802SSteve Glendinning 216*e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 217769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Timed out reading MII reg %02X", idx); 218769ea6d8SSteve Glendinning 219*e5e3af83SSteve Glendinning ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm); 220769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error reading MII_DATA"); 221769ea6d8SSteve Glendinning 222769ea6d8SSteve Glendinning ret = (u16)(val & 0xFFFF); 223769ea6d8SSteve Glendinning 224769ea6d8SSteve Glendinning done: 2252f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 226769ea6d8SSteve Glendinning return ret; 2272f7ca802SSteve Glendinning } 2282f7ca802SSteve Glendinning 229*e5e3af83SSteve Glendinning static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, 230*e5e3af83SSteve Glendinning int idx, int regval, int in_pm) 2312f7ca802SSteve Glendinning { 2322f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 2332f7ca802SSteve Glendinning u32 val, addr; 234769ea6d8SSteve Glendinning int ret; 2352f7ca802SSteve Glendinning 2362f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 2372f7ca802SSteve Glendinning 2382f7ca802SSteve Glendinning /* confirm MII not busy */ 239*e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 240769ea6d8SSteve Glendinning check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_write"); 2412f7ca802SSteve Glendinning 2422f7ca802SSteve Glendinning val = regval; 243*e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm); 244769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error writing MII_DATA"); 2452f7ca802SSteve Glendinning 2462f7ca802SSteve Glendinning /* set the address, index & direction (write to PHY) */ 2472f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 2482f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 24980928805SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_; 250*e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); 251769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error writing MII_ADDR"); 2522f7ca802SSteve Glendinning 253*e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 254769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Timed out writing MII reg %02X", idx); 2552f7ca802SSteve Glendinning 256769ea6d8SSteve Glendinning done: 2572f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 2582f7ca802SSteve Glendinning } 2592f7ca802SSteve Glendinning 260*e5e3af83SSteve Glendinning static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id, 261*e5e3af83SSteve Glendinning int idx) 262*e5e3af83SSteve Glendinning { 263*e5e3af83SSteve Glendinning return __smsc95xx_mdio_read(netdev, phy_id, idx, 1); 264*e5e3af83SSteve Glendinning } 265*e5e3af83SSteve Glendinning 266*e5e3af83SSteve Glendinning static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id, 267*e5e3af83SSteve Glendinning int idx, int regval) 268*e5e3af83SSteve Glendinning { 269*e5e3af83SSteve Glendinning __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1); 270*e5e3af83SSteve Glendinning } 271*e5e3af83SSteve Glendinning 272*e5e3af83SSteve Glendinning static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) 273*e5e3af83SSteve Glendinning { 274*e5e3af83SSteve Glendinning return __smsc95xx_mdio_read(netdev, phy_id, idx, 0); 275*e5e3af83SSteve Glendinning } 276*e5e3af83SSteve Glendinning 277*e5e3af83SSteve Glendinning static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, 278*e5e3af83SSteve Glendinning int regval) 279*e5e3af83SSteve Glendinning { 280*e5e3af83SSteve Glendinning __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0); 281*e5e3af83SSteve Glendinning } 282*e5e3af83SSteve Glendinning 283769ea6d8SSteve Glendinning static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev) 2842f7ca802SSteve Glendinning { 2852f7ca802SSteve Glendinning unsigned long start_time = jiffies; 2862f7ca802SSteve Glendinning u32 val; 287769ea6d8SSteve Glendinning int ret; 2882f7ca802SSteve Glendinning 2892f7ca802SSteve Glendinning do { 290769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 291769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading E2P_CMD"); 2922f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) 2932f7ca802SSteve Glendinning break; 2942f7ca802SSteve Glendinning udelay(40); 2952f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 2962f7ca802SSteve Glendinning 2972f7ca802SSteve Glendinning if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { 29860b86755SJoe Perches netdev_warn(dev->net, "EEPROM read operation timeout\n"); 2992f7ca802SSteve Glendinning return -EIO; 3002f7ca802SSteve Glendinning } 3012f7ca802SSteve Glendinning 3022f7ca802SSteve Glendinning return 0; 3032f7ca802SSteve Glendinning } 3042f7ca802SSteve Glendinning 305769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) 3062f7ca802SSteve Glendinning { 3072f7ca802SSteve Glendinning unsigned long start_time = jiffies; 3082f7ca802SSteve Glendinning u32 val; 309769ea6d8SSteve Glendinning int ret; 3102f7ca802SSteve Glendinning 3112f7ca802SSteve Glendinning do { 312769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 313769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading E2P_CMD"); 3142f7ca802SSteve Glendinning 3152f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_)) 3162f7ca802SSteve Glendinning return 0; 3172f7ca802SSteve Glendinning 3182f7ca802SSteve Glendinning udelay(40); 3192f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3202f7ca802SSteve Glendinning 32160b86755SJoe Perches netdev_warn(dev->net, "EEPROM is busy\n"); 3222f7ca802SSteve Glendinning return -EIO; 3232f7ca802SSteve Glendinning } 3242f7ca802SSteve Glendinning 3252f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, 3262f7ca802SSteve Glendinning u8 *data) 3272f7ca802SSteve Glendinning { 3282f7ca802SSteve Glendinning u32 val; 3292f7ca802SSteve Glendinning int i, ret; 3302f7ca802SSteve Glendinning 3312f7ca802SSteve Glendinning BUG_ON(!dev); 3322f7ca802SSteve Glendinning BUG_ON(!data); 3332f7ca802SSteve Glendinning 3342f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3352f7ca802SSteve Glendinning if (ret) 3362f7ca802SSteve Glendinning return ret; 3372f7ca802SSteve Glendinning 3382f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3392f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); 340769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 341769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_CMD"); 3422f7ca802SSteve Glendinning 3432f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3442f7ca802SSteve Glendinning if (ret < 0) 3452f7ca802SSteve Glendinning return ret; 3462f7ca802SSteve Glendinning 347769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_DATA, &val); 348769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading E2P_DATA"); 3492f7ca802SSteve Glendinning 3502f7ca802SSteve Glendinning data[i] = val & 0xFF; 3512f7ca802SSteve Glendinning offset++; 3522f7ca802SSteve Glendinning } 3532f7ca802SSteve Glendinning 3542f7ca802SSteve Glendinning return 0; 3552f7ca802SSteve Glendinning } 3562f7ca802SSteve Glendinning 3572f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, 3582f7ca802SSteve Glendinning u8 *data) 3592f7ca802SSteve Glendinning { 3602f7ca802SSteve Glendinning u32 val; 3612f7ca802SSteve Glendinning int i, ret; 3622f7ca802SSteve Glendinning 3632f7ca802SSteve Glendinning BUG_ON(!dev); 3642f7ca802SSteve Glendinning BUG_ON(!data); 3652f7ca802SSteve Glendinning 3662f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3672f7ca802SSteve Glendinning if (ret) 3682f7ca802SSteve Glendinning return ret; 3692f7ca802SSteve Glendinning 3702f7ca802SSteve Glendinning /* Issue write/erase enable command */ 3712f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; 372769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 373769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_DATA"); 3742f7ca802SSteve Glendinning 3752f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3762f7ca802SSteve Glendinning if (ret < 0) 3772f7ca802SSteve Glendinning return ret; 3782f7ca802SSteve Glendinning 3792f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3802f7ca802SSteve Glendinning 3812f7ca802SSteve Glendinning /* Fill data register */ 3822f7ca802SSteve Glendinning val = data[i]; 383769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_DATA, val); 384769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_DATA"); 3852f7ca802SSteve Glendinning 3862f7ca802SSteve Glendinning /* Send "write" command */ 3872f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); 388769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 389769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_CMD"); 3902f7ca802SSteve Glendinning 3912f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3922f7ca802SSteve Glendinning if (ret < 0) 3932f7ca802SSteve Glendinning return ret; 3942f7ca802SSteve Glendinning 3952f7ca802SSteve Glendinning offset++; 3962f7ca802SSteve Glendinning } 3972f7ca802SSteve Glendinning 3982f7ca802SSteve Glendinning return 0; 3992f7ca802SSteve Glendinning } 4002f7ca802SSteve Glendinning 401769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, 402769ea6d8SSteve Glendinning u32 *data) 4032f7ca802SSteve Glendinning { 4041d74a6bdSSteve Glendinning const u16 size = 4; 40572108fd2SMing Lei int ret; 4062f7ca802SSteve Glendinning 40772108fd2SMing Lei ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, 40872108fd2SMing Lei USB_DIR_OUT | USB_TYPE_VENDOR | 40972108fd2SMing Lei USB_RECIP_DEVICE, 41072108fd2SMing Lei 0, index, data, size); 41172108fd2SMing Lei if (ret < 0) 41272108fd2SMing Lei netdev_warn(dev->net, "Error write async cmd, sts=%d\n", 41372108fd2SMing Lei ret); 41472108fd2SMing Lei return ret; 4152f7ca802SSteve Glendinning } 4162f7ca802SSteve Glendinning 4172f7ca802SSteve Glendinning /* returns hash bit number for given MAC address 4182f7ca802SSteve Glendinning * example: 4192f7ca802SSteve Glendinning * 01 00 5E 00 00 01 -> returns bit number 31 */ 4202f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) 4212f7ca802SSteve Glendinning { 4222f7ca802SSteve Glendinning return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; 4232f7ca802SSteve Glendinning } 4242f7ca802SSteve Glendinning 4252f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev) 4262f7ca802SSteve Glendinning { 4272f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 4282f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 4292f7ca802SSteve Glendinning unsigned long flags; 430769ea6d8SSteve Glendinning int ret; 4312f7ca802SSteve Glendinning 4323c0f3c60SMarc Zyngier pdata->hash_hi = 0; 4333c0f3c60SMarc Zyngier pdata->hash_lo = 0; 4343c0f3c60SMarc Zyngier 4352f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 4362f7ca802SSteve Glendinning 4372f7ca802SSteve Glendinning if (dev->net->flags & IFF_PROMISC) { 438a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); 4392f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_PRMS_; 4402f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4412f7ca802SSteve Glendinning } else if (dev->net->flags & IFF_ALLMULTI) { 442a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); 4432f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_MCPAS_; 4442f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); 4454cd24eafSJiri Pirko } else if (!netdev_mc_empty(dev->net)) { 44622bedad3SJiri Pirko struct netdev_hw_addr *ha; 4472f7ca802SSteve Glendinning 4482f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_HPFILT_; 4492f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); 4502f7ca802SSteve Glendinning 45122bedad3SJiri Pirko netdev_for_each_mc_addr(ha, netdev) { 45222bedad3SJiri Pirko u32 bitnum = smsc95xx_hash(ha->addr); 4532f7ca802SSteve Glendinning u32 mask = 0x01 << (bitnum & 0x1F); 4542f7ca802SSteve Glendinning if (bitnum & 0x20) 4553c0f3c60SMarc Zyngier pdata->hash_hi |= mask; 4562f7ca802SSteve Glendinning else 4573c0f3c60SMarc Zyngier pdata->hash_lo |= mask; 4582f7ca802SSteve Glendinning } 4592f7ca802SSteve Glendinning 460a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", 4613c0f3c60SMarc Zyngier pdata->hash_hi, pdata->hash_lo); 4622f7ca802SSteve Glendinning } else { 463a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive own packets only\n"); 4642f7ca802SSteve Glendinning pdata->mac_cr &= 4652f7ca802SSteve Glendinning ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4662f7ca802SSteve Glendinning } 4672f7ca802SSteve Glendinning 4682f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 4692f7ca802SSteve Glendinning 4702f7ca802SSteve Glendinning /* Initiate async writes, as we can't wait for completion here */ 471769ea6d8SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi); 472769ea6d8SSteve Glendinning check_warn(ret, "failed to initiate async write to HASHH"); 473769ea6d8SSteve Glendinning 474769ea6d8SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo); 475769ea6d8SSteve Glendinning check_warn(ret, "failed to initiate async write to HASHL"); 476769ea6d8SSteve Glendinning 477769ea6d8SSteve Glendinning ret = smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr); 478769ea6d8SSteve Glendinning check_warn(ret, "failed to initiate async write to MAC_CR"); 4792f7ca802SSteve Glendinning } 4802f7ca802SSteve Glendinning 481769ea6d8SSteve Glendinning static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, 4822f7ca802SSteve Glendinning u16 lcladv, u16 rmtadv) 4832f7ca802SSteve Glendinning { 4842f7ca802SSteve Glendinning u32 flow, afc_cfg = 0; 4852f7ca802SSteve Glendinning 4862f7ca802SSteve Glendinning int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); 487769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading AFC_CFG"); 4882f7ca802SSteve Glendinning 4892f7ca802SSteve Glendinning if (duplex == DUPLEX_FULL) { 490bc02ff95SSteve Glendinning u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); 4912f7ca802SSteve Glendinning 4922f7ca802SSteve Glendinning if (cap & FLOW_CTRL_RX) 4932f7ca802SSteve Glendinning flow = 0xFFFF0002; 4942f7ca802SSteve Glendinning else 4952f7ca802SSteve Glendinning flow = 0; 4962f7ca802SSteve Glendinning 4972f7ca802SSteve Glendinning if (cap & FLOW_CTRL_TX) 4982f7ca802SSteve Glendinning afc_cfg |= 0xF; 4992f7ca802SSteve Glendinning else 5002f7ca802SSteve Glendinning afc_cfg &= ~0xF; 5012f7ca802SSteve Glendinning 502a475f603SJoe Perches netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", 50360b86755SJoe Perches cap & FLOW_CTRL_RX ? "enabled" : "disabled", 50460b86755SJoe Perches cap & FLOW_CTRL_TX ? "enabled" : "disabled"); 5052f7ca802SSteve Glendinning } else { 506a475f603SJoe Perches netif_dbg(dev, link, dev->net, "half duplex\n"); 5072f7ca802SSteve Glendinning flow = 0; 5082f7ca802SSteve Glendinning afc_cfg |= 0xF; 5092f7ca802SSteve Glendinning } 5102f7ca802SSteve Glendinning 511769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, flow); 512769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing FLOW"); 513769ea6d8SSteve Glendinning 514769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); 515769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing AFC_CFG"); 516769ea6d8SSteve Glendinning 517769ea6d8SSteve Glendinning return 0; 5182f7ca802SSteve Glendinning } 5192f7ca802SSteve Glendinning 5202f7ca802SSteve Glendinning static int smsc95xx_link_reset(struct usbnet *dev) 5212f7ca802SSteve Glendinning { 5222f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 5232f7ca802SSteve Glendinning struct mii_if_info *mii = &dev->mii; 5248ae6dacaSDavid Decotigny struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 5252f7ca802SSteve Glendinning unsigned long flags; 5262f7ca802SSteve Glendinning u16 lcladv, rmtadv; 527769ea6d8SSteve Glendinning int ret; 5282f7ca802SSteve Glendinning 5292f7ca802SSteve Glendinning /* clear interrupt status */ 530769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); 531769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading PHY_INT_SRC"); 532769ea6d8SSteve Glendinning 533769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 534769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing INT_STS"); 5352f7ca802SSteve Glendinning 5362f7ca802SSteve Glendinning mii_check_media(mii, 1, 1); 5372f7ca802SSteve Glendinning mii_ethtool_gset(&dev->mii, &ecmd); 5382f7ca802SSteve Glendinning lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); 5392f7ca802SSteve Glendinning rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA); 5402f7ca802SSteve Glendinning 5418ae6dacaSDavid Decotigny netif_dbg(dev, link, dev->net, 5428ae6dacaSDavid Decotigny "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", 5438ae6dacaSDavid Decotigny ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); 5442f7ca802SSteve Glendinning 5452f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 5462f7ca802SSteve Glendinning if (ecmd.duplex != DUPLEX_FULL) { 5472f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_FDPX_; 5482f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RCVOWN_; 5492f7ca802SSteve Glendinning } else { 5502f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_RCVOWN_; 5512f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_FDPX_; 5522f7ca802SSteve Glendinning } 5532f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5542f7ca802SSteve Glendinning 555769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 556769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing MAC_CR"); 5572f7ca802SSteve Glendinning 558769ea6d8SSteve Glendinning ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); 559769ea6d8SSteve Glendinning check_warn_return(ret, "Error updating PHY flow control"); 5602f7ca802SSteve Glendinning 5612f7ca802SSteve Glendinning return 0; 5622f7ca802SSteve Glendinning } 5632f7ca802SSteve Glendinning 5642f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb) 5652f7ca802SSteve Glendinning { 5662f7ca802SSteve Glendinning u32 intdata; 5672f7ca802SSteve Glendinning 5682f7ca802SSteve Glendinning if (urb->actual_length != 4) { 56960b86755SJoe Perches netdev_warn(dev->net, "unexpected urb length %d\n", 57060b86755SJoe Perches urb->actual_length); 5712f7ca802SSteve Glendinning return; 5722f7ca802SSteve Glendinning } 5732f7ca802SSteve Glendinning 5742f7ca802SSteve Glendinning memcpy(&intdata, urb->transfer_buffer, 4); 5751d74a6bdSSteve Glendinning le32_to_cpus(&intdata); 5762f7ca802SSteve Glendinning 577a475f603SJoe Perches netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); 5782f7ca802SSteve Glendinning 5792f7ca802SSteve Glendinning if (intdata & INT_ENP_PHY_INT_) 5802f7ca802SSteve Glendinning usbnet_defer_kevent(dev, EVENT_LINK_RESET); 5812f7ca802SSteve Glendinning else 58260b86755SJoe Perches netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", 58360b86755SJoe Perches intdata); 5842f7ca802SSteve Glendinning } 5852f7ca802SSteve Glendinning 586f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */ 587c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev, 588c8f44affSMichał Mirosław netdev_features_t features) 5892f7ca802SSteve Glendinning { 59078e47fe4SMichał Mirosław struct usbnet *dev = netdev_priv(netdev); 5912f7ca802SSteve Glendinning u32 read_buf; 59278e47fe4SMichał Mirosław int ret; 59378e47fe4SMichał Mirosław 59478e47fe4SMichał Mirosław ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); 595769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read COE_CR: %d\n", ret); 5962f7ca802SSteve Glendinning 59778e47fe4SMichał Mirosław if (features & NETIF_F_HW_CSUM) 598f7b29271SSteve Glendinning read_buf |= Tx_COE_EN_; 599f7b29271SSteve Glendinning else 600f7b29271SSteve Glendinning read_buf &= ~Tx_COE_EN_; 601f7b29271SSteve Glendinning 60278e47fe4SMichał Mirosław if (features & NETIF_F_RXCSUM) 6032f7ca802SSteve Glendinning read_buf |= Rx_COE_EN_; 6042f7ca802SSteve Glendinning else 6052f7ca802SSteve Glendinning read_buf &= ~Rx_COE_EN_; 6062f7ca802SSteve Glendinning 6072f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, COE_CR, read_buf); 608769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write COE_CR: %d\n", ret); 6092f7ca802SSteve Glendinning 610a475f603SJoe Perches netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); 6112f7ca802SSteve Glendinning return 0; 6122f7ca802SSteve Glendinning } 6132f7ca802SSteve Glendinning 6142f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) 6152f7ca802SSteve Glendinning { 6162f7ca802SSteve Glendinning return MAX_EEPROM_SIZE; 6172f7ca802SSteve Glendinning } 6182f7ca802SSteve Glendinning 6192f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, 6202f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6212f7ca802SSteve Glendinning { 6222f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6232f7ca802SSteve Glendinning 6242f7ca802SSteve Glendinning ee->magic = LAN95XX_EEPROM_MAGIC; 6252f7ca802SSteve Glendinning 6262f7ca802SSteve Glendinning return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); 6272f7ca802SSteve Glendinning } 6282f7ca802SSteve Glendinning 6292f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, 6302f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6312f7ca802SSteve Glendinning { 6322f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6332f7ca802SSteve Glendinning 6342f7ca802SSteve Glendinning if (ee->magic != LAN95XX_EEPROM_MAGIC) { 63560b86755SJoe Perches netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", 6362f7ca802SSteve Glendinning ee->magic); 6372f7ca802SSteve Glendinning return -EINVAL; 6382f7ca802SSteve Glendinning } 6392f7ca802SSteve Glendinning 6402f7ca802SSteve Glendinning return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); 6412f7ca802SSteve Glendinning } 6422f7ca802SSteve Glendinning 6439fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev) 6449fa32e94SEmeric Vigier { 6459fa32e94SEmeric Vigier /* all smsc95xx registers */ 6469fa32e94SEmeric Vigier return COE_CR - ID_REV + 1; 6479fa32e94SEmeric Vigier } 6489fa32e94SEmeric Vigier 6499fa32e94SEmeric Vigier static void 6509fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, 6519fa32e94SEmeric Vigier void *buf) 6529fa32e94SEmeric Vigier { 6539fa32e94SEmeric Vigier struct usbnet *dev = netdev_priv(netdev); 654d348446bSDan Carpenter unsigned int i, j; 655d348446bSDan Carpenter int retval; 6569fa32e94SEmeric Vigier u32 *data = buf; 6579fa32e94SEmeric Vigier 6589fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); 6599fa32e94SEmeric Vigier if (retval < 0) { 6609fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read ID_REV\n"); 6619fa32e94SEmeric Vigier return; 6629fa32e94SEmeric Vigier } 6639fa32e94SEmeric Vigier 6649fa32e94SEmeric Vigier for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { 6659fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, i, &data[j]); 6669fa32e94SEmeric Vigier if (retval < 0) { 6679fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); 6689fa32e94SEmeric Vigier return; 6699fa32e94SEmeric Vigier } 6709fa32e94SEmeric Vigier } 6719fa32e94SEmeric Vigier } 6729fa32e94SEmeric Vigier 673e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net, 674e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 675e0e474a8SSteve Glendinning { 676e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 677e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 678e0e474a8SSteve Glendinning 679e0e474a8SSteve Glendinning wolinfo->supported = SUPPORTED_WAKE; 680e0e474a8SSteve Glendinning wolinfo->wolopts = pdata->wolopts; 681e0e474a8SSteve Glendinning } 682e0e474a8SSteve Glendinning 683e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net, 684e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 685e0e474a8SSteve Glendinning { 686e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 687e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 688e0e474a8SSteve Glendinning 689e0e474a8SSteve Glendinning pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; 690e0e474a8SSteve Glendinning return 0; 691e0e474a8SSteve Glendinning } 692e0e474a8SSteve Glendinning 6930fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = { 6942f7ca802SSteve Glendinning .get_link = usbnet_get_link, 6952f7ca802SSteve Glendinning .nway_reset = usbnet_nway_reset, 6962f7ca802SSteve Glendinning .get_drvinfo = usbnet_get_drvinfo, 6972f7ca802SSteve Glendinning .get_msglevel = usbnet_get_msglevel, 6982f7ca802SSteve Glendinning .set_msglevel = usbnet_set_msglevel, 6992f7ca802SSteve Glendinning .get_settings = usbnet_get_settings, 7002f7ca802SSteve Glendinning .set_settings = usbnet_set_settings, 7012f7ca802SSteve Glendinning .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, 7022f7ca802SSteve Glendinning .get_eeprom = smsc95xx_ethtool_get_eeprom, 7032f7ca802SSteve Glendinning .set_eeprom = smsc95xx_ethtool_set_eeprom, 7049fa32e94SEmeric Vigier .get_regs_len = smsc95xx_ethtool_getregslen, 7059fa32e94SEmeric Vigier .get_regs = smsc95xx_ethtool_getregs, 706e0e474a8SSteve Glendinning .get_wol = smsc95xx_ethtool_get_wol, 707e0e474a8SSteve Glendinning .set_wol = smsc95xx_ethtool_set_wol, 7082f7ca802SSteve Glendinning }; 7092f7ca802SSteve Glendinning 7102f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 7112f7ca802SSteve Glendinning { 7122f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7132f7ca802SSteve Glendinning 7142f7ca802SSteve Glendinning if (!netif_running(netdev)) 7152f7ca802SSteve Glendinning return -EINVAL; 7162f7ca802SSteve Glendinning 7172f7ca802SSteve Glendinning return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 7182f7ca802SSteve Glendinning } 7192f7ca802SSteve Glendinning 7202f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev) 7212f7ca802SSteve Glendinning { 7222f7ca802SSteve Glendinning /* try reading mac address from EEPROM */ 7232f7ca802SSteve Glendinning if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, 7242f7ca802SSteve Glendinning dev->net->dev_addr) == 0) { 7252f7ca802SSteve Glendinning if (is_valid_ether_addr(dev->net->dev_addr)) { 7262f7ca802SSteve Glendinning /* eeprom values are valid so use them */ 727a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); 7282f7ca802SSteve Glendinning return; 7292f7ca802SSteve Glendinning } 7302f7ca802SSteve Glendinning } 7312f7ca802SSteve Glendinning 7322f7ca802SSteve Glendinning /* no eeprom, or eeprom values are invalid. generate random MAC */ 733f2cedb63SDanny Kukawka eth_hw_addr_random(dev->net); 734c7e12eadSJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); 7352f7ca802SSteve Glendinning } 7362f7ca802SSteve Glendinning 7372f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev) 7382f7ca802SSteve Glendinning { 7392f7ca802SSteve Glendinning u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | 7402f7ca802SSteve Glendinning dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; 7412f7ca802SSteve Glendinning u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; 7422f7ca802SSteve Glendinning int ret; 7432f7ca802SSteve Glendinning 7442f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); 745769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write ADDRL: %d\n", ret); 7462f7ca802SSteve Glendinning 7472f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRH, addr_hi); 748769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write ADDRH: %d\n", ret); 7492f7ca802SSteve Glendinning 7502f7ca802SSteve Glendinning return 0; 7512f7ca802SSteve Glendinning } 7522f7ca802SSteve Glendinning 7532f7ca802SSteve Glendinning /* starts the TX path */ 754769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev) 7552f7ca802SSteve Glendinning { 7562f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7572f7ca802SSteve Glendinning unsigned long flags; 758769ea6d8SSteve Glendinning int ret; 7592f7ca802SSteve Glendinning 7602f7ca802SSteve Glendinning /* Enable Tx at MAC */ 7612f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 7622f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_TXEN_; 7632f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 7642f7ca802SSteve Glendinning 765769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 766769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret); 7672f7ca802SSteve Glendinning 7682f7ca802SSteve Glendinning /* Enable Tx at SCSRs */ 769769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); 770769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write TX_CFG: %d\n", ret); 771769ea6d8SSteve Glendinning 772769ea6d8SSteve Glendinning return 0; 7732f7ca802SSteve Glendinning } 7742f7ca802SSteve Glendinning 7752f7ca802SSteve Glendinning /* Starts the Receive path */ 776ec32115dSMing Lei static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) 7772f7ca802SSteve Glendinning { 7782f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7792f7ca802SSteve Glendinning unsigned long flags; 780769ea6d8SSteve Glendinning int ret; 7812f7ca802SSteve Glendinning 7822f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 7832f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RXEN_; 7842f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 7852f7ca802SSteve Glendinning 786ec32115dSMing Lei ret = __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm); 787769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret); 788769ea6d8SSteve Glendinning 789769ea6d8SSteve Glendinning return 0; 7902f7ca802SSteve Glendinning } 7912f7ca802SSteve Glendinning 7922f7ca802SSteve Glendinning static int smsc95xx_phy_initialize(struct usbnet *dev) 7932f7ca802SSteve Glendinning { 794769ea6d8SSteve Glendinning int bmcr, ret, timeout = 0; 795db443c44SSteve Glendinning 7962f7ca802SSteve Glendinning /* Initialize MII structure */ 7972f7ca802SSteve Glendinning dev->mii.dev = dev->net; 7982f7ca802SSteve Glendinning dev->mii.mdio_read = smsc95xx_mdio_read; 7992f7ca802SSteve Glendinning dev->mii.mdio_write = smsc95xx_mdio_write; 8002f7ca802SSteve Glendinning dev->mii.phy_id_mask = 0x1f; 8012f7ca802SSteve Glendinning dev->mii.reg_num_mask = 0x1f; 8022f7ca802SSteve Glendinning dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID; 8032f7ca802SSteve Glendinning 804db443c44SSteve Glendinning /* reset phy and wait for reset to complete */ 8052f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 806db443c44SSteve Glendinning 807db443c44SSteve Glendinning do { 808db443c44SSteve Glendinning msleep(10); 809db443c44SSteve Glendinning bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); 810db443c44SSteve Glendinning timeout++; 811d9460920SRabin Vincent } while ((bmcr & BMCR_RESET) && (timeout < 100)); 812db443c44SSteve Glendinning 813db443c44SSteve Glendinning if (timeout >= 100) { 814db443c44SSteve Glendinning netdev_warn(dev->net, "timeout on PHY Reset"); 815db443c44SSteve Glendinning return -EIO; 816db443c44SSteve Glendinning } 817db443c44SSteve Glendinning 8182f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, 8192f7ca802SSteve Glendinning ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | 8202f7ca802SSteve Glendinning ADVERTISE_PAUSE_ASYM); 8212f7ca802SSteve Glendinning 8222f7ca802SSteve Glendinning /* read to clear */ 823769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); 824769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read PHY_INT_SRC during init"); 8252f7ca802SSteve Glendinning 8262f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, 8272f7ca802SSteve Glendinning PHY_INT_MASK_DEFAULT_); 8282f7ca802SSteve Glendinning mii_nway_restart(&dev->mii); 8292f7ca802SSteve Glendinning 830a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); 8312f7ca802SSteve Glendinning return 0; 8322f7ca802SSteve Glendinning } 8332f7ca802SSteve Glendinning 8342f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev) 8352f7ca802SSteve Glendinning { 8362f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 8372f7ca802SSteve Glendinning u32 read_buf, write_buf, burst_cap; 8382f7ca802SSteve Glendinning int ret = 0, timeout; 8392f7ca802SSteve Glendinning 840a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); 8412f7ca802SSteve Glendinning 8424436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); 843769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write HW_CFG_LRST_ bit in HW_CFG\n"); 8442f7ca802SSteve Glendinning 8452f7ca802SSteve Glendinning timeout = 0; 8462f7ca802SSteve Glendinning do { 847cf2acec2SSteve Glendinning msleep(10); 8482f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 849769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 8502f7ca802SSteve Glendinning timeout++; 8512f7ca802SSteve Glendinning } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); 8522f7ca802SSteve Glendinning 8532f7ca802SSteve Glendinning if (timeout >= 100) { 85460b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); 8552f7ca802SSteve Glendinning return ret; 8562f7ca802SSteve Glendinning } 8572f7ca802SSteve Glendinning 8584436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); 859769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write PM_CTRL: %d\n", ret); 8602f7ca802SSteve Glendinning 8612f7ca802SSteve Glendinning timeout = 0; 8622f7ca802SSteve Glendinning do { 863cf2acec2SSteve Glendinning msleep(10); 8642f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); 865769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read PM_CTRL: %d\n", ret); 8662f7ca802SSteve Glendinning timeout++; 8672f7ca802SSteve Glendinning } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); 8682f7ca802SSteve Glendinning 8692f7ca802SSteve Glendinning if (timeout >= 100) { 87060b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); 8712f7ca802SSteve Glendinning return ret; 8722f7ca802SSteve Glendinning } 8732f7ca802SSteve Glendinning 8742f7ca802SSteve Glendinning ret = smsc95xx_set_mac_address(dev); 8752f7ca802SSteve Glendinning if (ret < 0) 8762f7ca802SSteve Glendinning return ret; 8772f7ca802SSteve Glendinning 878a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 879a475f603SJoe Perches "MAC Address: %pM\n", dev->net->dev_addr); 8802f7ca802SSteve Glendinning 8812f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 882769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 8832f7ca802SSteve Glendinning 884a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 885a475f603SJoe Perches "Read Value from HW_CFG : 0x%08x\n", read_buf); 8862f7ca802SSteve Glendinning 8872f7ca802SSteve Glendinning read_buf |= HW_CFG_BIR_; 8882f7ca802SSteve Glendinning 8892f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 890769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write HW_CFG_BIR_ bit in HW_CFG\n"); 8912f7ca802SSteve Glendinning 8922f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 893769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 894a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 895a475f603SJoe Perches "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", 89660b86755SJoe Perches read_buf); 8972f7ca802SSteve Glendinning 8982f7ca802SSteve Glendinning if (!turbo_mode) { 8992f7ca802SSteve Glendinning burst_cap = 0; 9002f7ca802SSteve Glendinning dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; 9012f7ca802SSteve Glendinning } else if (dev->udev->speed == USB_SPEED_HIGH) { 9022f7ca802SSteve Glendinning burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; 9032f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; 9042f7ca802SSteve Glendinning } else { 9052f7ca802SSteve Glendinning burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; 9062f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; 9072f7ca802SSteve Glendinning } 9082f7ca802SSteve Glendinning 909a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 910a475f603SJoe Perches "rx_urb_size=%ld\n", (ulong)dev->rx_urb_size); 9112f7ca802SSteve Glendinning 9122f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); 913769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret); 9142f7ca802SSteve Glendinning 9152f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); 916769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret); 917769ea6d8SSteve Glendinning 918a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 919a475f603SJoe Perches "Read Value from BURST_CAP after writing: 0x%08x\n", 9202f7ca802SSteve Glendinning read_buf); 9212f7ca802SSteve Glendinning 9224436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); 923769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret); 9242f7ca802SSteve Glendinning 9252f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); 926769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret); 927769ea6d8SSteve Glendinning 928a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 929a475f603SJoe Perches "Read Value from BULK_IN_DLY after writing: 0x%08x\n", 93060b86755SJoe Perches read_buf); 9312f7ca802SSteve Glendinning 9322f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 933769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 934769ea6d8SSteve Glendinning 935a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 936a475f603SJoe Perches "Read Value from HW_CFG: 0x%08x\n", read_buf); 9372f7ca802SSteve Glendinning 9382f7ca802SSteve Glendinning if (turbo_mode) 9392f7ca802SSteve Glendinning read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); 9402f7ca802SSteve Glendinning 9412f7ca802SSteve Glendinning read_buf &= ~HW_CFG_RXDOFF_; 9422f7ca802SSteve Glendinning 9432f7ca802SSteve Glendinning /* set Rx data offset=2, Make IP header aligns on word boundary. */ 9442f7ca802SSteve Glendinning read_buf |= NET_IP_ALIGN << 9; 9452f7ca802SSteve Glendinning 9462f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 947769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret); 9482f7ca802SSteve Glendinning 9492f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 950769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 951769ea6d8SSteve Glendinning 952a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 953a475f603SJoe Perches "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); 9542f7ca802SSteve Glendinning 9554436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 956769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write INT_STS: %d\n", ret); 9572f7ca802SSteve Glendinning 9582f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); 959769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read ID_REV: %d\n", ret); 960a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); 9612f7ca802SSteve Glendinning 962f293501cSSteve Glendinning /* Configure GPIO pins as LED outputs */ 963f293501cSSteve Glendinning write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | 964f293501cSSteve Glendinning LED_GPIO_CFG_FDX_LED; 965f293501cSSteve Glendinning ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); 966769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n", ret); 967f293501cSSteve Glendinning 9682f7ca802SSteve Glendinning /* Init Tx */ 9694436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, 0); 970769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write FLOW: %d\n", ret); 9712f7ca802SSteve Glendinning 9724436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); 973769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write AFC_CFG: %d\n", ret); 9742f7ca802SSteve Glendinning 9752f7ca802SSteve Glendinning /* Don't need mac_cr_lock during initialisation */ 9762f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); 977769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret); 9782f7ca802SSteve Glendinning 9792f7ca802SSteve Glendinning /* Init Rx */ 9802f7ca802SSteve Glendinning /* Set Vlan */ 9814436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); 982769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write VLAN1: %d\n", ret); 9832f7ca802SSteve Glendinning 984f7b29271SSteve Glendinning /* Enable or disable checksum offload engines */ 985769ea6d8SSteve Glendinning ret = smsc95xx_set_features(dev->net, dev->net->features); 986769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to set checksum offload features"); 9872f7ca802SSteve Glendinning 9882f7ca802SSteve Glendinning smsc95xx_set_multicast(dev->net); 9892f7ca802SSteve Glendinning 990769ea6d8SSteve Glendinning ret = smsc95xx_phy_initialize(dev); 991769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to init PHY"); 9922f7ca802SSteve Glendinning 9932f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); 994769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret); 9952f7ca802SSteve Glendinning 9962f7ca802SSteve Glendinning /* enable PHY interrupts */ 9972f7ca802SSteve Glendinning read_buf |= INT_EP_CTL_PHY_INT_; 9982f7ca802SSteve Glendinning 9992f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); 1000769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret); 10012f7ca802SSteve Glendinning 1002769ea6d8SSteve Glendinning ret = smsc95xx_start_tx_path(dev); 1003769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to start TX path"); 1004769ea6d8SSteve Glendinning 1005ec32115dSMing Lei ret = smsc95xx_start_rx_path(dev, 0); 1006769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to start RX path"); 10072f7ca802SSteve Glendinning 1008a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); 10092f7ca802SSteve Glendinning return 0; 10102f7ca802SSteve Glendinning } 10112f7ca802SSteve Glendinning 101263e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = { 101363e77b39SStephen Hemminger .ndo_open = usbnet_open, 101463e77b39SStephen Hemminger .ndo_stop = usbnet_stop, 101563e77b39SStephen Hemminger .ndo_start_xmit = usbnet_start_xmit, 101663e77b39SStephen Hemminger .ndo_tx_timeout = usbnet_tx_timeout, 101763e77b39SStephen Hemminger .ndo_change_mtu = usbnet_change_mtu, 101863e77b39SStephen Hemminger .ndo_set_mac_address = eth_mac_addr, 101963e77b39SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 102063e77b39SStephen Hemminger .ndo_do_ioctl = smsc95xx_ioctl, 1021afc4b13dSJiri Pirko .ndo_set_rx_mode = smsc95xx_set_multicast, 102278e47fe4SMichał Mirosław .ndo_set_features = smsc95xx_set_features, 102363e77b39SStephen Hemminger }; 102463e77b39SStephen Hemminger 10252f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) 10262f7ca802SSteve Glendinning { 10272f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = NULL; 1028bbd9f9eeSSteve Glendinning u32 val; 10292f7ca802SSteve Glendinning int ret; 10302f7ca802SSteve Glendinning 10312f7ca802SSteve Glendinning printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); 10322f7ca802SSteve Glendinning 10332f7ca802SSteve Glendinning ret = usbnet_get_endpoints(dev, intf); 1034769ea6d8SSteve Glendinning check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret); 10352f7ca802SSteve Glendinning 10362f7ca802SSteve Glendinning dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), 10372f7ca802SSteve Glendinning GFP_KERNEL); 10382f7ca802SSteve Glendinning 10392f7ca802SSteve Glendinning pdata = (struct smsc95xx_priv *)(dev->data[0]); 10402f7ca802SSteve Glendinning if (!pdata) { 104160b86755SJoe Perches netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n"); 10422f7ca802SSteve Glendinning return -ENOMEM; 10432f7ca802SSteve Glendinning } 10442f7ca802SSteve Glendinning 10452f7ca802SSteve Glendinning spin_lock_init(&pdata->mac_cr_lock); 10462f7ca802SSteve Glendinning 104778e47fe4SMichał Mirosław if (DEFAULT_TX_CSUM_ENABLE) 104878e47fe4SMichał Mirosław dev->net->features |= NETIF_F_HW_CSUM; 104978e47fe4SMichał Mirosław if (DEFAULT_RX_CSUM_ENABLE) 105078e47fe4SMichał Mirosław dev->net->features |= NETIF_F_RXCSUM; 105178e47fe4SMichał Mirosław 105278e47fe4SMichał Mirosław dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM; 10532f7ca802SSteve Glendinning 1054f4e8ab7cSBernard Blackham smsc95xx_init_mac_address(dev); 1055f4e8ab7cSBernard Blackham 10562f7ca802SSteve Glendinning /* Init all registers */ 10572f7ca802SSteve Glendinning ret = smsc95xx_reset(dev); 10582f7ca802SSteve Glendinning 1059bbd9f9eeSSteve Glendinning /* detect device revision as different features may be available */ 1060bbd9f9eeSSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &val); 1061bbd9f9eeSSteve Glendinning check_warn_return(ret, "Failed to read ID_REV: %d\n", ret); 1062bbd9f9eeSSteve Glendinning val >>= 16; 10639ebca507SSteve Glendinning 10649ebca507SSteve Glendinning if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || 10659ebca507SSteve Glendinning (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) 10669ebca507SSteve Glendinning pdata->features = (FEATURE_8_WAKEUP_FILTERS | 10679ebca507SSteve Glendinning FEATURE_PHY_NLP_CROSSOVER | 10689ebca507SSteve Glendinning FEATURE_AUTOSUSPEND); 10699ebca507SSteve Glendinning else if (val == ID_REV_CHIP_ID_9512_) 10709ebca507SSteve Glendinning pdata->features = FEATURE_8_WAKEUP_FILTERS; 1071bbd9f9eeSSteve Glendinning 107263e77b39SStephen Hemminger dev->net->netdev_ops = &smsc95xx_netdev_ops; 10732f7ca802SSteve Glendinning dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 10742f7ca802SSteve Glendinning dev->net->flags |= IFF_MULTICAST; 107578e47fe4SMichał Mirosław dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 10769bbf5660SStephane Fillod dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; 10772f7ca802SSteve Glendinning return 0; 10782f7ca802SSteve Glendinning } 10792f7ca802SSteve Glendinning 10802f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) 10812f7ca802SSteve Glendinning { 10822f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 10832f7ca802SSteve Glendinning if (pdata) { 1084a475f603SJoe Perches netif_dbg(dev, ifdown, dev->net, "free pdata\n"); 10852f7ca802SSteve Glendinning kfree(pdata); 10862f7ca802SSteve Glendinning pdata = NULL; 10872f7ca802SSteve Glendinning dev->data[0] = 0; 10882f7ca802SSteve Glendinning } 10892f7ca802SSteve Glendinning } 10902f7ca802SSteve Glendinning 1091bbd9f9eeSSteve Glendinning static u16 smsc_crc(const u8 *buffer, size_t len, int filter) 1092bbd9f9eeSSteve Glendinning { 1093bbd9f9eeSSteve Glendinning return bitrev16(crc16(0xFFFF, buffer, len)) << ((filter % 2) * 16); 1094bbd9f9eeSSteve Glendinning } 1095bbd9f9eeSSteve Glendinning 1096*e5e3af83SSteve Glendinning static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) 1097*e5e3af83SSteve Glendinning { 1098*e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1099*e5e3af83SSteve Glendinning int ret; 1100*e5e3af83SSteve Glendinning 1101*e5e3af83SSteve Glendinning netdev_dbg(dev->net, "enabling PHY wakeup interrupts"); 1102*e5e3af83SSteve Glendinning 1103*e5e3af83SSteve Glendinning /* read to clear */ 1104*e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC); 1105*e5e3af83SSteve Glendinning check_warn_return(ret, "Error reading PHY_INT_SRC"); 1106*e5e3af83SSteve Glendinning 1107*e5e3af83SSteve Glendinning /* enable interrupt source */ 1108*e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK); 1109*e5e3af83SSteve Glendinning check_warn_return(ret, "Error reading PHY_INT_MASK"); 1110*e5e3af83SSteve Glendinning 1111*e5e3af83SSteve Glendinning ret |= mask; 1112*e5e3af83SSteve Glendinning 1113*e5e3af83SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret); 1114*e5e3af83SSteve Glendinning 1115*e5e3af83SSteve Glendinning return 0; 1116*e5e3af83SSteve Glendinning } 1117*e5e3af83SSteve Glendinning 1118*e5e3af83SSteve Glendinning static int smsc95xx_link_ok_nopm(struct usbnet *dev) 1119*e5e3af83SSteve Glendinning { 1120*e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1121*e5e3af83SSteve Glendinning int ret; 1122*e5e3af83SSteve Glendinning 1123*e5e3af83SSteve Glendinning /* first, a dummy read, needed to latch some MII phys */ 1124*e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1125*e5e3af83SSteve Glendinning check_warn_return(ret, "Error reading MII_BMSR"); 1126*e5e3af83SSteve Glendinning 1127*e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1128*e5e3af83SSteve Glendinning check_warn_return(ret, "Error reading MII_BMSR"); 1129*e5e3af83SSteve Glendinning 1130*e5e3af83SSteve Glendinning return !!(ret & BMSR_LSTATUS); 1131*e5e3af83SSteve Glendinning } 1132*e5e3af83SSteve Glendinning 1133b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) 1134b5a04475SSteve Glendinning { 1135b5a04475SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1136e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1137*e5e3af83SSteve Glendinning u32 val, link_up; 1138b5a04475SSteve Glendinning int ret; 1139b5a04475SSteve Glendinning 1140b5a04475SSteve Glendinning ret = usbnet_suspend(intf, message); 1141b5a04475SSteve Glendinning check_warn_return(ret, "usbnet_suspend error"); 1142b5a04475SSteve Glendinning 1143*e5e3af83SSteve Glendinning /* determine if link is up using only _nopm functions */ 1144*e5e3af83SSteve Glendinning link_up = smsc95xx_link_ok_nopm(dev); 1145*e5e3af83SSteve Glendinning 1146*e5e3af83SSteve Glendinning /* if no wol options set, or if link is down and we're not waking on 1147*e5e3af83SSteve Glendinning * PHY activity, enter lowest power SUSPEND2 mode 1148*e5e3af83SSteve Glendinning */ 1149*e5e3af83SSteve Glendinning if (!(pdata->wolopts & SUPPORTED_WAKE) || 1150*e5e3af83SSteve Glendinning !(link_up || (pdata->wolopts & WAKE_PHY))) { 1151b5a04475SSteve Glendinning netdev_info(dev->net, "entering SUSPEND2 mode"); 1152b5a04475SSteve Glendinning 1153e0e474a8SSteve Glendinning /* disable energy detect (link up) & wake up events */ 1154ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1155e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1156e0e474a8SSteve Glendinning 1157e0e474a8SSteve Glendinning val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); 1158e0e474a8SSteve Glendinning 1159ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1160e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1161e0e474a8SSteve Glendinning 1162ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1163e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1164e0e474a8SSteve Glendinning 1165e0e474a8SSteve Glendinning val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); 1166e0e474a8SSteve Glendinning 1167ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1168e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1169e0e474a8SSteve Glendinning 1170e0e474a8SSteve Glendinning /* enter suspend2 mode */ 1171ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1172b5a04475SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1173b5a04475SSteve Glendinning 1174b5a04475SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1175b5a04475SSteve Glendinning val |= PM_CTL_SUS_MODE_2; 1176b5a04475SSteve Glendinning 1177ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1178b5a04475SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1179b5a04475SSteve Glendinning 1180b5a04475SSteve Glendinning return 0; 1181b5a04475SSteve Glendinning } 1182b5a04475SSteve Glendinning 1183*e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) { 1184*e5e3af83SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1185*e5e3af83SSteve Glendinning (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_)); 1186*e5e3af83SSteve Glendinning check_warn_return(ret, "error enabling PHY wakeup ints"); 1187*e5e3af83SSteve Glendinning 1188*e5e3af83SSteve Glendinning /* if link is down then configure EDPD and enter SUSPEND1, 1189*e5e3af83SSteve Glendinning * otherwise enter SUSPEND0 below 1190*e5e3af83SSteve Glendinning */ 1191*e5e3af83SSteve Glendinning if (!link_up) { 1192*e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1193*e5e3af83SSteve Glendinning netdev_info(dev->net, "entering SUSPEND1 mode"); 1194*e5e3af83SSteve Glendinning 1195*e5e3af83SSteve Glendinning /* reconfigure link pulse detection timing for 1196*e5e3af83SSteve Glendinning * compatibility with non-standard link partners 1197*e5e3af83SSteve Glendinning */ 1198*e5e3af83SSteve Glendinning if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) 1199*e5e3af83SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, 1200*e5e3af83SSteve Glendinning PHY_EDPD_CONFIG, 1201*e5e3af83SSteve Glendinning PHY_EDPD_CONFIG_DEFAULT); 1202*e5e3af83SSteve Glendinning 1203*e5e3af83SSteve Glendinning /* enable energy detect power-down mode */ 1204*e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, 1205*e5e3af83SSteve Glendinning PHY_MODE_CTRL_STS); 1206*e5e3af83SSteve Glendinning check_warn_return(ret, "Error reading PHY_MODE_CTRL_STS"); 1207*e5e3af83SSteve Glendinning 1208*e5e3af83SSteve Glendinning ret |= MODE_CTRL_STS_EDPWRDOWN_; 1209*e5e3af83SSteve Glendinning 1210*e5e3af83SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, 1211*e5e3af83SSteve Glendinning PHY_MODE_CTRL_STS, ret); 1212*e5e3af83SSteve Glendinning 1213*e5e3af83SSteve Glendinning /* enter SUSPEND1 mode */ 1214*e5e3af83SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1215*e5e3af83SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1216*e5e3af83SSteve Glendinning 1217*e5e3af83SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1218*e5e3af83SSteve Glendinning val |= PM_CTL_SUS_MODE_1; 1219*e5e3af83SSteve Glendinning 1220*e5e3af83SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1221*e5e3af83SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1222*e5e3af83SSteve Glendinning 1223*e5e3af83SSteve Glendinning /* clear wol status, enable energy detection */ 1224*e5e3af83SSteve Glendinning val &= ~PM_CTL_WUPS_; 1225*e5e3af83SSteve Glendinning val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); 1226*e5e3af83SSteve Glendinning 1227*e5e3af83SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1228*e5e3af83SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1229*e5e3af83SSteve Glendinning 1230*e5e3af83SSteve Glendinning smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); 1231*e5e3af83SSteve Glendinning 1232*e5e3af83SSteve Glendinning return 0; 1233*e5e3af83SSteve Glendinning } 1234*e5e3af83SSteve Glendinning } 1235*e5e3af83SSteve Glendinning 1236bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 1237bbd9f9eeSSteve Glendinning u32 *filter_mask = kzalloc(32, GFP_KERNEL); 123806a221beSMing Lei u32 command[2]; 123906a221beSMing Lei u32 offset[2]; 124006a221beSMing Lei u32 crc[4]; 12419ebca507SSteve Glendinning int wuff_filter_count = 12429ebca507SSteve Glendinning (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? 12439ebca507SSteve Glendinning LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; 1244bbd9f9eeSSteve Glendinning int i, filter = 0; 1245bbd9f9eeSSteve Glendinning 124606a221beSMing Lei memset(command, 0, sizeof(command)); 124706a221beSMing Lei memset(offset, 0, sizeof(offset)); 124806a221beSMing Lei memset(crc, 0, sizeof(crc)); 124906a221beSMing Lei 1250bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_BCAST) { 1251bbd9f9eeSSteve Glendinning const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 1252bbd9f9eeSSteve Glendinning netdev_info(dev->net, "enabling broadcast detection"); 1253bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1254bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1255bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1256bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1257bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1258bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1259bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(bcast, 6, filter); 1260bbd9f9eeSSteve Glendinning filter++; 1261bbd9f9eeSSteve Glendinning } 1262bbd9f9eeSSteve Glendinning 1263bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_MCAST) { 1264bbd9f9eeSSteve Glendinning const u8 mcast[] = {0x01, 0x00, 0x5E}; 1265bbd9f9eeSSteve Glendinning netdev_info(dev->net, "enabling multicast detection"); 1266bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0007; 1267bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1268bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1269bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1270bbd9f9eeSSteve Glendinning command[filter/4] |= 0x09UL << ((filter % 4) * 8); 1271bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1272bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(mcast, 3, filter); 1273bbd9f9eeSSteve Glendinning filter++; 1274bbd9f9eeSSteve Glendinning } 1275bbd9f9eeSSteve Glendinning 1276bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_ARP) { 1277bbd9f9eeSSteve Glendinning const u8 arp[] = {0x08, 0x06}; 1278bbd9f9eeSSteve Glendinning netdev_info(dev->net, "enabling ARP detection"); 1279bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0003; 1280bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1281bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1282bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1283bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1284bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x0C << ((filter % 4) * 8); 1285bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(arp, 2, filter); 1286bbd9f9eeSSteve Glendinning filter++; 1287bbd9f9eeSSteve Glendinning } 1288bbd9f9eeSSteve Glendinning 1289bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_UCAST) { 1290bbd9f9eeSSteve Glendinning netdev_info(dev->net, "enabling unicast detection"); 1291bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1292bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1293bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1294bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1295bbd9f9eeSSteve Glendinning command[filter/4] |= 0x01UL << ((filter % 4) * 8); 1296bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1297bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); 1298bbd9f9eeSSteve Glendinning filter++; 1299bbd9f9eeSSteve Glendinning } 1300bbd9f9eeSSteve Glendinning 13019ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count * 4); i++) { 1302ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]); 130306a221beSMing Lei if (ret < 0) 130406a221beSMing Lei kfree(filter_mask); 1305bbd9f9eeSSteve Glendinning check_warn_return(ret, "Error writing WUFF"); 1306bbd9f9eeSSteve Glendinning } 130706a221beSMing Lei kfree(filter_mask); 1308bbd9f9eeSSteve Glendinning 13099ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1310ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]); 1311bbd9f9eeSSteve Glendinning check_warn_return(ret, "Error writing WUFF"); 1312bbd9f9eeSSteve Glendinning } 1313bbd9f9eeSSteve Glendinning 13149ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1315ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]); 1316bbd9f9eeSSteve Glendinning check_warn_return(ret, "Error writing WUFF"); 1317bbd9f9eeSSteve Glendinning } 1318bbd9f9eeSSteve Glendinning 13199ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 2); i++) { 1320ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]); 1321bbd9f9eeSSteve Glendinning check_warn_return(ret, "Error writing WUFF"); 1322bbd9f9eeSSteve Glendinning } 1323bbd9f9eeSSteve Glendinning 1324bbd9f9eeSSteve Glendinning /* clear any pending pattern match packet status */ 1325ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1326bbd9f9eeSSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1327bbd9f9eeSSteve Glendinning 1328bbd9f9eeSSteve Glendinning val |= WUCSR_WUFR_; 1329bbd9f9eeSSteve Glendinning 1330ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1331bbd9f9eeSSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1332bbd9f9eeSSteve Glendinning } 1333bbd9f9eeSSteve Glendinning 1334e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1335e0e474a8SSteve Glendinning /* clear any pending magic packet status */ 1336ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1337e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1338e0e474a8SSteve Glendinning 1339e0e474a8SSteve Glendinning val |= WUCSR_MPR_; 1340e0e474a8SSteve Glendinning 1341ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1342e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1343e0e474a8SSteve Glendinning } 1344e0e474a8SSteve Glendinning 1345bbd9f9eeSSteve Glendinning /* enable/disable wakeup sources */ 1346ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1347e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1348e0e474a8SSteve Glendinning 1349bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 1350bbd9f9eeSSteve Glendinning netdev_info(dev->net, "enabling pattern match wakeup"); 1351bbd9f9eeSSteve Glendinning val |= WUCSR_WAKE_EN_; 1352bbd9f9eeSSteve Glendinning } else { 1353bbd9f9eeSSteve Glendinning netdev_info(dev->net, "disabling pattern match wakeup"); 1354bbd9f9eeSSteve Glendinning val &= ~WUCSR_WAKE_EN_; 1355bbd9f9eeSSteve Glendinning } 1356bbd9f9eeSSteve Glendinning 1357e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1358e0e474a8SSteve Glendinning netdev_info(dev->net, "enabling magic packet wakeup"); 1359e0e474a8SSteve Glendinning val |= WUCSR_MPEN_; 1360e0e474a8SSteve Glendinning } else { 1361e0e474a8SSteve Glendinning netdev_info(dev->net, "disabling magic packet wakeup"); 1362e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1363e0e474a8SSteve Glendinning } 1364e0e474a8SSteve Glendinning 1365ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1366e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1367e0e474a8SSteve Glendinning 1368e0e474a8SSteve Glendinning /* enable wol wakeup source */ 1369ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1370e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1371e0e474a8SSteve Glendinning 1372e0e474a8SSteve Glendinning val |= PM_CTL_WOL_EN_; 1373e0e474a8SSteve Glendinning 1374*e5e3af83SSteve Glendinning /* phy energy detect wakeup source */ 1375*e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1376*e5e3af83SSteve Glendinning val |= PM_CTL_ED_EN_; 1377*e5e3af83SSteve Glendinning 1378ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1379e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1380e0e474a8SSteve Glendinning 1381bbd9f9eeSSteve Glendinning /* enable receiver to enable frame reception */ 1382ec32115dSMing Lei smsc95xx_start_rx_path(dev, 1); 1383e0e474a8SSteve Glendinning 1384e0e474a8SSteve Glendinning /* some wol options are enabled, so enter SUSPEND0 */ 1385e0e474a8SSteve Glendinning netdev_info(dev->net, "entering SUSPEND0 mode"); 1386e0e474a8SSteve Glendinning 1387ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1388e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1389e0e474a8SSteve Glendinning 1390e0e474a8SSteve Glendinning val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); 1391e0e474a8SSteve Glendinning val |= PM_CTL_SUS_MODE_0; 1392e0e474a8SSteve Glendinning 1393ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1394e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1395e0e474a8SSteve Glendinning 1396e0e474a8SSteve Glendinning /* clear wol status */ 1397e0e474a8SSteve Glendinning val &= ~PM_CTL_WUPS_; 1398e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1399*e5e3af83SSteve Glendinning 1400*e5e3af83SSteve Glendinning /* enable energy detection */ 1401*e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1402*e5e3af83SSteve Glendinning val |= PM_CTL_WUPS_ED_; 1403*e5e3af83SSteve Glendinning 1404ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1405e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1406e0e474a8SSteve Glendinning 1407e0e474a8SSteve Glendinning /* read back PM_CTRL */ 1408ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1409e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1410e0e474a8SSteve Glendinning 1411e0e474a8SSteve Glendinning smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); 1412e0e474a8SSteve Glendinning 1413e0e474a8SSteve Glendinning return 0; 1414e0e474a8SSteve Glendinning } 1415e0e474a8SSteve Glendinning 1416e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf) 1417e0e474a8SSteve Glendinning { 1418e0e474a8SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1419e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1420e0e474a8SSteve Glendinning int ret; 1421e0e474a8SSteve Glendinning u32 val; 1422e0e474a8SSteve Glendinning 1423e0e474a8SSteve Glendinning BUG_ON(!dev); 1424e0e474a8SSteve Glendinning 1425bbd9f9eeSSteve Glendinning if (pdata->wolopts) { 1426e0e474a8SSteve Glendinning smsc95xx_clear_feature(dev, USB_DEVICE_REMOTE_WAKEUP); 1427e0e474a8SSteve Glendinning 1428bbd9f9eeSSteve Glendinning /* clear wake-up sources */ 1429ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1430e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1431e0e474a8SSteve Glendinning 1432bbd9f9eeSSteve Glendinning val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); 1433e0e474a8SSteve Glendinning 1434ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1435e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1436e0e474a8SSteve Glendinning 1437e0e474a8SSteve Glendinning /* clear wake-up status */ 1438ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1439e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1440e0e474a8SSteve Glendinning 1441e0e474a8SSteve Glendinning val &= ~PM_CTL_WOL_EN_; 1442e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_; 1443e0e474a8SSteve Glendinning 1444ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1445e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1446e0e474a8SSteve Glendinning } 1447e0e474a8SSteve Glendinning 1448af3d7c1eSSteve Glendinning ret = usbnet_resume(intf); 1449e0e474a8SSteve Glendinning check_warn_return(ret, "usbnet_resume error"); 1450e0e474a8SSteve Glendinning 1451e0e474a8SSteve Glendinning return 0; 1452e0e474a8SSteve Glendinning } 1453e0e474a8SSteve Glendinning 14542f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb) 14552f7ca802SSteve Glendinning { 14562f7ca802SSteve Glendinning skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); 14572f7ca802SSteve Glendinning skb->ip_summed = CHECKSUM_COMPLETE; 14582f7ca802SSteve Glendinning skb_trim(skb, skb->len - 2); 14592f7ca802SSteve Glendinning } 14602f7ca802SSteve Glendinning 14612f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 14622f7ca802SSteve Glendinning { 14632f7ca802SSteve Glendinning while (skb->len > 0) { 14642f7ca802SSteve Glendinning u32 header, align_count; 14652f7ca802SSteve Glendinning struct sk_buff *ax_skb; 14662f7ca802SSteve Glendinning unsigned char *packet; 14672f7ca802SSteve Glendinning u16 size; 14682f7ca802SSteve Glendinning 14692f7ca802SSteve Glendinning memcpy(&header, skb->data, sizeof(header)); 14702f7ca802SSteve Glendinning le32_to_cpus(&header); 14712f7ca802SSteve Glendinning skb_pull(skb, 4 + NET_IP_ALIGN); 14722f7ca802SSteve Glendinning packet = skb->data; 14732f7ca802SSteve Glendinning 14742f7ca802SSteve Glendinning /* get the packet length */ 14752f7ca802SSteve Glendinning size = (u16)((header & RX_STS_FL_) >> 16); 14762f7ca802SSteve Glendinning align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 14772f7ca802SSteve Glendinning 14782f7ca802SSteve Glendinning if (unlikely(header & RX_STS_ES_)) { 1479a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1480a475f603SJoe Perches "Error header=0x%08x\n", header); 148180667ac1SHerbert Xu dev->net->stats.rx_errors++; 148280667ac1SHerbert Xu dev->net->stats.rx_dropped++; 14832f7ca802SSteve Glendinning 14842f7ca802SSteve Glendinning if (header & RX_STS_CRC_) { 148580667ac1SHerbert Xu dev->net->stats.rx_crc_errors++; 14862f7ca802SSteve Glendinning } else { 14872f7ca802SSteve Glendinning if (header & (RX_STS_TL_ | RX_STS_RF_)) 148880667ac1SHerbert Xu dev->net->stats.rx_frame_errors++; 14892f7ca802SSteve Glendinning 14902f7ca802SSteve Glendinning if ((header & RX_STS_LE_) && 14912f7ca802SSteve Glendinning (!(header & RX_STS_FT_))) 149280667ac1SHerbert Xu dev->net->stats.rx_length_errors++; 14932f7ca802SSteve Glendinning } 14942f7ca802SSteve Glendinning } else { 14952f7ca802SSteve Glendinning /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ 14962f7ca802SSteve Glendinning if (unlikely(size > (ETH_FRAME_LEN + 12))) { 1497a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1498a475f603SJoe Perches "size err header=0x%08x\n", header); 14992f7ca802SSteve Glendinning return 0; 15002f7ca802SSteve Glendinning } 15012f7ca802SSteve Glendinning 15022f7ca802SSteve Glendinning /* last frame in this batch */ 15032f7ca802SSteve Glendinning if (skb->len == size) { 150478e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 15052f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(skb); 1506df18accaSPeter Korsgaard skb_trim(skb, skb->len - 4); /* remove fcs */ 15072f7ca802SSteve Glendinning skb->truesize = size + sizeof(struct sk_buff); 15082f7ca802SSteve Glendinning 15092f7ca802SSteve Glendinning return 1; 15102f7ca802SSteve Glendinning } 15112f7ca802SSteve Glendinning 15122f7ca802SSteve Glendinning ax_skb = skb_clone(skb, GFP_ATOMIC); 15132f7ca802SSteve Glendinning if (unlikely(!ax_skb)) { 151460b86755SJoe Perches netdev_warn(dev->net, "Error allocating skb\n"); 15152f7ca802SSteve Glendinning return 0; 15162f7ca802SSteve Glendinning } 15172f7ca802SSteve Glendinning 15182f7ca802SSteve Glendinning ax_skb->len = size; 15192f7ca802SSteve Glendinning ax_skb->data = packet; 15202f7ca802SSteve Glendinning skb_set_tail_pointer(ax_skb, size); 15212f7ca802SSteve Glendinning 152278e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 15232f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(ax_skb); 1524df18accaSPeter Korsgaard skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 15252f7ca802SSteve Glendinning ax_skb->truesize = size + sizeof(struct sk_buff); 15262f7ca802SSteve Glendinning 15272f7ca802SSteve Glendinning usbnet_skb_return(dev, ax_skb); 15282f7ca802SSteve Glendinning } 15292f7ca802SSteve Glendinning 15302f7ca802SSteve Glendinning skb_pull(skb, size); 15312f7ca802SSteve Glendinning 15322f7ca802SSteve Glendinning /* padding bytes before the next frame starts */ 15332f7ca802SSteve Glendinning if (skb->len) 15342f7ca802SSteve Glendinning skb_pull(skb, align_count); 15352f7ca802SSteve Glendinning } 15362f7ca802SSteve Glendinning 15372f7ca802SSteve Glendinning if (unlikely(skb->len < 0)) { 153860b86755SJoe Perches netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len); 15392f7ca802SSteve Glendinning return 0; 15402f7ca802SSteve Glendinning } 15412f7ca802SSteve Glendinning 15422f7ca802SSteve Glendinning return 1; 15432f7ca802SSteve Glendinning } 15442f7ca802SSteve Glendinning 1545f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) 1546f7b29271SSteve Glendinning { 154755508d60SMichał Mirosław u16 low_16 = (u16)skb_checksum_start_offset(skb); 154855508d60SMichał Mirosław u16 high_16 = low_16 + skb->csum_offset; 1549f7b29271SSteve Glendinning return (high_16 << 16) | low_16; 1550f7b29271SSteve Glendinning } 1551f7b29271SSteve Glendinning 15522f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 15532f7ca802SSteve Glendinning struct sk_buff *skb, gfp_t flags) 15542f7ca802SSteve Glendinning { 155578e47fe4SMichał Mirosław bool csum = skb->ip_summed == CHECKSUM_PARTIAL; 1556f7b29271SSteve Glendinning int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; 15572f7ca802SSteve Glendinning u32 tx_cmd_a, tx_cmd_b; 15582f7ca802SSteve Glendinning 1559f7b29271SSteve Glendinning /* We do not advertise SG, so skbs should be already linearized */ 1560f7b29271SSteve Glendinning BUG_ON(skb_shinfo(skb)->nr_frags); 1561f7b29271SSteve Glendinning 1562f7b29271SSteve Glendinning if (skb_headroom(skb) < overhead) { 15632f7ca802SSteve Glendinning struct sk_buff *skb2 = skb_copy_expand(skb, 1564f7b29271SSteve Glendinning overhead, 0, flags); 15652f7ca802SSteve Glendinning dev_kfree_skb_any(skb); 15662f7ca802SSteve Glendinning skb = skb2; 15672f7ca802SSteve Glendinning if (!skb) 15682f7ca802SSteve Glendinning return NULL; 15692f7ca802SSteve Glendinning } 15702f7ca802SSteve Glendinning 1571f7b29271SSteve Glendinning if (csum) { 157211bc3088SSteve Glendinning if (skb->len <= 45) { 157311bc3088SSteve Glendinning /* workaround - hardware tx checksum does not work 157411bc3088SSteve Glendinning * properly with extremely small packets */ 157555508d60SMichał Mirosław long csstart = skb_checksum_start_offset(skb); 157611bc3088SSteve Glendinning __wsum calc = csum_partial(skb->data + csstart, 157711bc3088SSteve Glendinning skb->len - csstart, 0); 157811bc3088SSteve Glendinning *((__sum16 *)(skb->data + csstart 157911bc3088SSteve Glendinning + skb->csum_offset)) = csum_fold(calc); 158011bc3088SSteve Glendinning 158111bc3088SSteve Glendinning csum = false; 158211bc3088SSteve Glendinning } else { 1583f7b29271SSteve Glendinning u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); 1584f7b29271SSteve Glendinning skb_push(skb, 4); 158500acda68SSteve Glendinning cpu_to_le32s(&csum_preamble); 1586f7b29271SSteve Glendinning memcpy(skb->data, &csum_preamble, 4); 1587f7b29271SSteve Glendinning } 158811bc3088SSteve Glendinning } 1589f7b29271SSteve Glendinning 15902f7ca802SSteve Glendinning skb_push(skb, 4); 15912f7ca802SSteve Glendinning tx_cmd_b = (u32)(skb->len - 4); 1592f7b29271SSteve Glendinning if (csum) 1593f7b29271SSteve Glendinning tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; 15942f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_b); 15952f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_b, 4); 15962f7ca802SSteve Glendinning 15972f7ca802SSteve Glendinning skb_push(skb, 4); 15982f7ca802SSteve Glendinning tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ | 15992f7ca802SSteve Glendinning TX_CMD_A_LAST_SEG_; 16002f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_a); 16012f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_a, 4); 16022f7ca802SSteve Glendinning 16032f7ca802SSteve Glendinning return skb; 16042f7ca802SSteve Glendinning } 16052f7ca802SSteve Glendinning 16062f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = { 16072f7ca802SSteve Glendinning .description = "smsc95xx USB 2.0 Ethernet", 16082f7ca802SSteve Glendinning .bind = smsc95xx_bind, 16092f7ca802SSteve Glendinning .unbind = smsc95xx_unbind, 16102f7ca802SSteve Glendinning .link_reset = smsc95xx_link_reset, 16112f7ca802SSteve Glendinning .reset = smsc95xx_reset, 16122f7ca802SSteve Glendinning .rx_fixup = smsc95xx_rx_fixup, 16132f7ca802SSteve Glendinning .tx_fixup = smsc95xx_tx_fixup, 16142f7ca802SSteve Glendinning .status = smsc95xx_status, 161507d69d42SPaolo Pisati .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, 16162f7ca802SSteve Glendinning }; 16172f7ca802SSteve Glendinning 16182f7ca802SSteve Glendinning static const struct usb_device_id products[] = { 16192f7ca802SSteve Glendinning { 16202f7ca802SSteve Glendinning /* SMSC9500 USB Ethernet Device */ 16212f7ca802SSteve Glendinning USB_DEVICE(0x0424, 0x9500), 16222f7ca802SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16232f7ca802SSteve Glendinning }, 1624726474b8SSteve Glendinning { 16256f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device */ 16266f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9505), 16276f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16286f41d12bSSteve Glendinning }, 16296f41d12bSSteve Glendinning { 16306f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device */ 16316f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E00), 16326f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16336f41d12bSSteve Glendinning }, 16346f41d12bSSteve Glendinning { 16356f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device */ 16366f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E01), 16376f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16386f41d12bSSteve Glendinning }, 16396f41d12bSSteve Glendinning { 1640726474b8SSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device */ 1641726474b8SSteve Glendinning USB_DEVICE(0x0424, 0xec00), 1642726474b8SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 1643726474b8SSteve Glendinning }, 16446f41d12bSSteve Glendinning { 16456f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (SAL10) */ 16466f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9900), 16476f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16486f41d12bSSteve Glendinning }, 16496f41d12bSSteve Glendinning { 16506f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device (SAL10) */ 16516f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9901), 16526f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16536f41d12bSSteve Glendinning }, 16546f41d12bSSteve Glendinning { 16556f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (SAL10) */ 16566f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9902), 16576f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16586f41d12bSSteve Glendinning }, 16596f41d12bSSteve Glendinning { 16606f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (SAL10) */ 16616f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9903), 16626f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16636f41d12bSSteve Glendinning }, 16646f41d12bSSteve Glendinning { 16656f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ 16666f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9904), 16676f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16686f41d12bSSteve Glendinning }, 16696f41d12bSSteve Glendinning { 16706f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (HAL) */ 16716f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9905), 16726f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16736f41d12bSSteve Glendinning }, 16746f41d12bSSteve Glendinning { 16756f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (HAL) */ 16766f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9906), 16776f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16786f41d12bSSteve Glendinning }, 16796f41d12bSSteve Glendinning { 16806f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (Alternate ID) */ 16816f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9907), 16826f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16836f41d12bSSteve Glendinning }, 16846f41d12bSSteve Glendinning { 16856f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (Alternate ID) */ 16866f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9908), 16876f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16886f41d12bSSteve Glendinning }, 16896f41d12bSSteve Glendinning { 16906f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ 16916f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9909), 16926f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 16936f41d12bSSteve Glendinning }, 169488edaa41SSteve Glendinning { 169588edaa41SSteve Glendinning /* SMSC LAN9530 USB Ethernet Device */ 169688edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9530), 169788edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 169888edaa41SSteve Glendinning }, 169988edaa41SSteve Glendinning { 170088edaa41SSteve Glendinning /* SMSC LAN9730 USB Ethernet Device */ 170188edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9730), 170288edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 170388edaa41SSteve Glendinning }, 170488edaa41SSteve Glendinning { 170588edaa41SSteve Glendinning /* SMSC LAN89530 USB Ethernet Device */ 170688edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9E08), 170788edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 170888edaa41SSteve Glendinning }, 17092f7ca802SSteve Glendinning { }, /* END */ 17102f7ca802SSteve Glendinning }; 17112f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products); 17122f7ca802SSteve Glendinning 17132f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = { 17142f7ca802SSteve Glendinning .name = "smsc95xx", 17152f7ca802SSteve Glendinning .id_table = products, 17162f7ca802SSteve Glendinning .probe = usbnet_probe, 1717b5a04475SSteve Glendinning .suspend = smsc95xx_suspend, 1718e0e474a8SSteve Glendinning .resume = smsc95xx_resume, 1719e0e474a8SSteve Glendinning .reset_resume = smsc95xx_resume, 17202f7ca802SSteve Glendinning .disconnect = usbnet_disconnect, 1721e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 17222f7ca802SSteve Glendinning }; 17232f7ca802SSteve Glendinning 1724d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver); 17252f7ca802SSteve Glendinning 17262f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin"); 172790b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); 17282f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); 17292f7ca802SSteve Glendinning MODULE_LICENSE("GPL"); 1730