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) 51e5e3af83SSteve 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 582f7ca802SSteve Glendinning struct smsc95xx_priv { 592f7ca802SSteve Glendinning u32 mac_cr; 603c0f3c60SMarc Zyngier u32 hash_hi; 613c0f3c60SMarc Zyngier u32 hash_lo; 62e0e474a8SSteve Glendinning u32 wolopts; 632f7ca802SSteve Glendinning spinlock_t mac_cr_lock; 649ebca507SSteve Glendinning u8 features; 652f7ca802SSteve Glendinning }; 662f7ca802SSteve Glendinning 67eb939922SRusty Russell static bool turbo_mode = true; 682f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644); 692f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); 702f7ca802SSteve Glendinning 71ec32115dSMing Lei static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, 72ec32115dSMing Lei u32 *data, int in_pm) 732f7ca802SSteve Glendinning { 7472108fd2SMing Lei u32 buf; 752f7ca802SSteve Glendinning int ret; 76ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 772f7ca802SSteve Glendinning 782f7ca802SSteve Glendinning BUG_ON(!dev); 792f7ca802SSteve Glendinning 80ec32115dSMing Lei if (!in_pm) 81ec32115dSMing Lei fn = usbnet_read_cmd; 82ec32115dSMing Lei else 83ec32115dSMing Lei fn = usbnet_read_cmd_nopm; 84ec32115dSMing Lei 85ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN 86ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 8772108fd2SMing Lei 0, index, &buf, 4); 882f7ca802SSteve Glendinning if (unlikely(ret < 0)) 891e1d7412SJoe Perches netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", 901e1d7412SJoe Perches index, ret); 912f7ca802SSteve Glendinning 9272108fd2SMing Lei le32_to_cpus(&buf); 9372108fd2SMing Lei *data = buf; 942f7ca802SSteve Glendinning 952f7ca802SSteve Glendinning return ret; 962f7ca802SSteve Glendinning } 972f7ca802SSteve Glendinning 98ec32115dSMing Lei static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index, 99ec32115dSMing Lei u32 data, int in_pm) 1002f7ca802SSteve Glendinning { 10172108fd2SMing Lei u32 buf; 1022f7ca802SSteve Glendinning int ret; 103ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 1042f7ca802SSteve Glendinning 1052f7ca802SSteve Glendinning BUG_ON(!dev); 1062f7ca802SSteve Glendinning 107ec32115dSMing Lei if (!in_pm) 108ec32115dSMing Lei fn = usbnet_write_cmd; 109ec32115dSMing Lei else 110ec32115dSMing Lei fn = usbnet_write_cmd_nopm; 111ec32115dSMing Lei 11272108fd2SMing Lei buf = data; 11372108fd2SMing Lei cpu_to_le32s(&buf); 1142f7ca802SSteve Glendinning 115ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT 116ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 11772108fd2SMing Lei 0, index, &buf, 4); 1182f7ca802SSteve Glendinning if (unlikely(ret < 0)) 1191e1d7412SJoe Perches netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n", 1201e1d7412SJoe Perches index, ret); 1212f7ca802SSteve Glendinning 1222f7ca802SSteve Glendinning return ret; 1232f7ca802SSteve Glendinning } 1242f7ca802SSteve Glendinning 125ec32115dSMing Lei static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index, 126ec32115dSMing Lei u32 *data) 127ec32115dSMing Lei { 128ec32115dSMing Lei return __smsc95xx_read_reg(dev, index, data, 1); 129ec32115dSMing Lei } 130ec32115dSMing Lei 131ec32115dSMing Lei static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index, 132ec32115dSMing Lei u32 data) 133ec32115dSMing Lei { 134ec32115dSMing Lei return __smsc95xx_write_reg(dev, index, data, 1); 135ec32115dSMing Lei } 136ec32115dSMing Lei 137ec32115dSMing Lei static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, 138ec32115dSMing Lei u32 *data) 139ec32115dSMing Lei { 140ec32115dSMing Lei return __smsc95xx_read_reg(dev, index, data, 0); 141ec32115dSMing Lei } 142ec32115dSMing Lei 143ec32115dSMing Lei static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, 144ec32115dSMing Lei u32 data) 145ec32115dSMing Lei { 146ec32115dSMing Lei return __smsc95xx_write_reg(dev, index, data, 0); 147ec32115dSMing Lei } 148e0e474a8SSteve Glendinning 1492f7ca802SSteve Glendinning /* Loop until the read is completed with timeout 1502f7ca802SSteve Glendinning * called with phy_mutex held */ 151e5e3af83SSteve Glendinning static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev, 152e5e3af83SSteve Glendinning int in_pm) 1532f7ca802SSteve Glendinning { 1542f7ca802SSteve Glendinning unsigned long start_time = jiffies; 1552f7ca802SSteve Glendinning u32 val; 156769ea6d8SSteve Glendinning int ret; 1572f7ca802SSteve Glendinning 1582f7ca802SSteve Glendinning do { 159e5e3af83SSteve Glendinning ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm); 160b052e073SSteve Glendinning if (ret < 0) { 161b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading MII_ACCESS\n"); 162b052e073SSteve Glendinning return ret; 163b052e073SSteve Glendinning } 164b052e073SSteve Glendinning 1652f7ca802SSteve Glendinning if (!(val & MII_BUSY_)) 1662f7ca802SSteve Glendinning return 0; 1672f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 1682f7ca802SSteve Glendinning 1692f7ca802SSteve Glendinning return -EIO; 1702f7ca802SSteve Glendinning } 1712f7ca802SSteve Glendinning 172e5e3af83SSteve Glendinning static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx, 173e5e3af83SSteve Glendinning int in_pm) 1742f7ca802SSteve Glendinning { 1752f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 1762f7ca802SSteve Glendinning u32 val, addr; 177769ea6d8SSteve Glendinning int ret; 1782f7ca802SSteve Glendinning 1792f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 1802f7ca802SSteve Glendinning 1812f7ca802SSteve Glendinning /* confirm MII not busy */ 182e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 183b052e073SSteve Glendinning if (ret < 0) { 184b052e073SSteve Glendinning netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n"); 185b052e073SSteve Glendinning goto done; 186b052e073SSteve Glendinning } 1872f7ca802SSteve Glendinning 1882f7ca802SSteve Glendinning /* set the address, index & direction (read from PHY) */ 1892f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 1902f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 19180928805SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_; 192e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); 193b052e073SSteve Glendinning if (ret < 0) { 194b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_ADDR\n"); 195b052e073SSteve Glendinning goto done; 196b052e073SSteve Glendinning } 1972f7ca802SSteve Glendinning 198e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 199b052e073SSteve Glendinning if (ret < 0) { 200b052e073SSteve Glendinning netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); 201b052e073SSteve Glendinning goto done; 202b052e073SSteve Glendinning } 203769ea6d8SSteve Glendinning 204e5e3af83SSteve Glendinning ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm); 205b052e073SSteve Glendinning if (ret < 0) { 206b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading MII_DATA\n"); 207b052e073SSteve Glendinning goto done; 208b052e073SSteve Glendinning } 209769ea6d8SSteve Glendinning 210769ea6d8SSteve Glendinning ret = (u16)(val & 0xFFFF); 211769ea6d8SSteve Glendinning 212769ea6d8SSteve Glendinning done: 2132f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 214769ea6d8SSteve Glendinning return ret; 2152f7ca802SSteve Glendinning } 2162f7ca802SSteve Glendinning 217e5e3af83SSteve Glendinning static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, 218e5e3af83SSteve Glendinning int idx, int regval, int in_pm) 2192f7ca802SSteve Glendinning { 2202f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 2212f7ca802SSteve Glendinning u32 val, addr; 222769ea6d8SSteve Glendinning int ret; 2232f7ca802SSteve Glendinning 2242f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 2252f7ca802SSteve Glendinning 2262f7ca802SSteve Glendinning /* confirm MII not busy */ 227e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 228b052e073SSteve Glendinning if (ret < 0) { 229b052e073SSteve Glendinning netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n"); 230b052e073SSteve Glendinning goto done; 231b052e073SSteve Glendinning } 2322f7ca802SSteve Glendinning 2332f7ca802SSteve Glendinning val = regval; 234e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm); 235b052e073SSteve Glendinning if (ret < 0) { 236b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_DATA\n"); 237b052e073SSteve Glendinning goto done; 238b052e073SSteve Glendinning } 2392f7ca802SSteve Glendinning 2402f7ca802SSteve Glendinning /* set the address, index & direction (write to PHY) */ 2412f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 2422f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 24380928805SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_; 244e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); 245b052e073SSteve Glendinning if (ret < 0) { 246b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_ADDR\n"); 247b052e073SSteve Glendinning goto done; 248b052e073SSteve Glendinning } 2492f7ca802SSteve Glendinning 250e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 251b052e073SSteve Glendinning if (ret < 0) { 252b052e073SSteve Glendinning netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); 253b052e073SSteve Glendinning goto done; 254b052e073SSteve Glendinning } 2552f7ca802SSteve Glendinning 256769ea6d8SSteve Glendinning done: 2572f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 2582f7ca802SSteve Glendinning } 2592f7ca802SSteve Glendinning 260e5e3af83SSteve Glendinning static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id, 261e5e3af83SSteve Glendinning int idx) 262e5e3af83SSteve Glendinning { 263e5e3af83SSteve Glendinning return __smsc95xx_mdio_read(netdev, phy_id, idx, 1); 264e5e3af83SSteve Glendinning } 265e5e3af83SSteve Glendinning 266e5e3af83SSteve Glendinning static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id, 267e5e3af83SSteve Glendinning int idx, int regval) 268e5e3af83SSteve Glendinning { 269e5e3af83SSteve Glendinning __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1); 270e5e3af83SSteve Glendinning } 271e5e3af83SSteve Glendinning 272e5e3af83SSteve Glendinning static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) 273e5e3af83SSteve Glendinning { 274e5e3af83SSteve Glendinning return __smsc95xx_mdio_read(netdev, phy_id, idx, 0); 275e5e3af83SSteve Glendinning } 276e5e3af83SSteve Glendinning 277e5e3af83SSteve Glendinning static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, 278e5e3af83SSteve Glendinning int regval) 279e5e3af83SSteve Glendinning { 280e5e3af83SSteve Glendinning __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0); 281e5e3af83SSteve Glendinning } 282e5e3af83SSteve 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); 291b052e073SSteve Glendinning if (ret < 0) { 292b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_CMD\n"); 293b052e073SSteve Glendinning return ret; 294b052e073SSteve Glendinning } 295b052e073SSteve Glendinning 2962f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) 2972f7ca802SSteve Glendinning break; 2982f7ca802SSteve Glendinning udelay(40); 2992f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3002f7ca802SSteve Glendinning 3012f7ca802SSteve Glendinning if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { 30260b86755SJoe Perches netdev_warn(dev->net, "EEPROM read operation timeout\n"); 3032f7ca802SSteve Glendinning return -EIO; 3042f7ca802SSteve Glendinning } 3052f7ca802SSteve Glendinning 3062f7ca802SSteve Glendinning return 0; 3072f7ca802SSteve Glendinning } 3082f7ca802SSteve Glendinning 309769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) 3102f7ca802SSteve Glendinning { 3112f7ca802SSteve Glendinning unsigned long start_time = jiffies; 3122f7ca802SSteve Glendinning u32 val; 313769ea6d8SSteve Glendinning int ret; 3142f7ca802SSteve Glendinning 3152f7ca802SSteve Glendinning do { 316769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 317b052e073SSteve Glendinning if (ret < 0) { 318b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_CMD\n"); 319b052e073SSteve Glendinning return ret; 320b052e073SSteve Glendinning } 3212f7ca802SSteve Glendinning 3222f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_)) 3232f7ca802SSteve Glendinning return 0; 3242f7ca802SSteve Glendinning 3252f7ca802SSteve Glendinning udelay(40); 3262f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3272f7ca802SSteve Glendinning 32860b86755SJoe Perches netdev_warn(dev->net, "EEPROM is busy\n"); 3292f7ca802SSteve Glendinning return -EIO; 3302f7ca802SSteve Glendinning } 3312f7ca802SSteve Glendinning 3322f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, 3332f7ca802SSteve Glendinning u8 *data) 3342f7ca802SSteve Glendinning { 3352f7ca802SSteve Glendinning u32 val; 3362f7ca802SSteve Glendinning int i, ret; 3372f7ca802SSteve Glendinning 3382f7ca802SSteve Glendinning BUG_ON(!dev); 3392f7ca802SSteve Glendinning BUG_ON(!data); 3402f7ca802SSteve Glendinning 3412f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3422f7ca802SSteve Glendinning if (ret) 3432f7ca802SSteve Glendinning return ret; 3442f7ca802SSteve Glendinning 3452f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3462f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); 347769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 348b052e073SSteve Glendinning if (ret < 0) { 349b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_CMD\n"); 350b052e073SSteve Glendinning return ret; 351b052e073SSteve Glendinning } 3522f7ca802SSteve Glendinning 3532f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3542f7ca802SSteve Glendinning if (ret < 0) 3552f7ca802SSteve Glendinning return ret; 3562f7ca802SSteve Glendinning 357769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_DATA, &val); 358b052e073SSteve Glendinning if (ret < 0) { 359b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_DATA\n"); 360b052e073SSteve Glendinning return ret; 361b052e073SSteve Glendinning } 3622f7ca802SSteve Glendinning 3632f7ca802SSteve Glendinning data[i] = val & 0xFF; 3642f7ca802SSteve Glendinning offset++; 3652f7ca802SSteve Glendinning } 3662f7ca802SSteve Glendinning 3672f7ca802SSteve Glendinning return 0; 3682f7ca802SSteve Glendinning } 3692f7ca802SSteve Glendinning 3702f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, 3712f7ca802SSteve Glendinning u8 *data) 3722f7ca802SSteve Glendinning { 3732f7ca802SSteve Glendinning u32 val; 3742f7ca802SSteve Glendinning int i, ret; 3752f7ca802SSteve Glendinning 3762f7ca802SSteve Glendinning BUG_ON(!dev); 3772f7ca802SSteve Glendinning BUG_ON(!data); 3782f7ca802SSteve Glendinning 3792f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3802f7ca802SSteve Glendinning if (ret) 3812f7ca802SSteve Glendinning return ret; 3822f7ca802SSteve Glendinning 3832f7ca802SSteve Glendinning /* Issue write/erase enable command */ 3842f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; 385769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 386b052e073SSteve Glendinning if (ret < 0) { 387b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_DATA\n"); 388b052e073SSteve Glendinning return ret; 389b052e073SSteve Glendinning } 3902f7ca802SSteve Glendinning 3912f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3922f7ca802SSteve Glendinning if (ret < 0) 3932f7ca802SSteve Glendinning return ret; 3942f7ca802SSteve Glendinning 3952f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3962f7ca802SSteve Glendinning 3972f7ca802SSteve Glendinning /* Fill data register */ 3982f7ca802SSteve Glendinning val = data[i]; 399769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_DATA, val); 400b052e073SSteve Glendinning if (ret < 0) { 401b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_DATA\n"); 402b052e073SSteve Glendinning return ret; 403b052e073SSteve Glendinning } 4042f7ca802SSteve Glendinning 4052f7ca802SSteve Glendinning /* Send "write" command */ 4062f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); 407769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 408b052e073SSteve Glendinning if (ret < 0) { 409b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_CMD\n"); 410b052e073SSteve Glendinning return ret; 411b052e073SSteve Glendinning } 4122f7ca802SSteve Glendinning 4132f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 4142f7ca802SSteve Glendinning if (ret < 0) 4152f7ca802SSteve Glendinning return ret; 4162f7ca802SSteve Glendinning 4172f7ca802SSteve Glendinning offset++; 4182f7ca802SSteve Glendinning } 4192f7ca802SSteve Glendinning 4202f7ca802SSteve Glendinning return 0; 4212f7ca802SSteve Glendinning } 4222f7ca802SSteve Glendinning 423769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, 4247b9e7580SSteve Glendinning u32 data) 4252f7ca802SSteve Glendinning { 4261d74a6bdSSteve Glendinning const u16 size = 4; 4277b9e7580SSteve Glendinning u32 buf; 42872108fd2SMing Lei int ret; 4292f7ca802SSteve Glendinning 4307b9e7580SSteve Glendinning buf = data; 4317b9e7580SSteve Glendinning cpu_to_le32s(&buf); 4327b9e7580SSteve Glendinning 43372108fd2SMing Lei ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, 43472108fd2SMing Lei USB_DIR_OUT | USB_TYPE_VENDOR | 43572108fd2SMing Lei USB_RECIP_DEVICE, 4367b9e7580SSteve Glendinning 0, index, &buf, size); 43772108fd2SMing Lei if (ret < 0) 43872108fd2SMing Lei netdev_warn(dev->net, "Error write async cmd, sts=%d\n", 43972108fd2SMing Lei ret); 44072108fd2SMing Lei return ret; 4412f7ca802SSteve Glendinning } 4422f7ca802SSteve Glendinning 4432f7ca802SSteve Glendinning /* returns hash bit number for given MAC address 4442f7ca802SSteve Glendinning * example: 4452f7ca802SSteve Glendinning * 01 00 5E 00 00 01 -> returns bit number 31 */ 4462f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) 4472f7ca802SSteve Glendinning { 4482f7ca802SSteve Glendinning return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; 4492f7ca802SSteve Glendinning } 4502f7ca802SSteve Glendinning 4512f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev) 4522f7ca802SSteve Glendinning { 4532f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 4542f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 4552f7ca802SSteve Glendinning unsigned long flags; 456769ea6d8SSteve Glendinning int ret; 4572f7ca802SSteve Glendinning 4583c0f3c60SMarc Zyngier pdata->hash_hi = 0; 4593c0f3c60SMarc Zyngier pdata->hash_lo = 0; 4603c0f3c60SMarc Zyngier 4612f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 4622f7ca802SSteve Glendinning 4632f7ca802SSteve Glendinning if (dev->net->flags & IFF_PROMISC) { 464a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); 4652f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_PRMS_; 4662f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4672f7ca802SSteve Glendinning } else if (dev->net->flags & IFF_ALLMULTI) { 468a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); 4692f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_MCPAS_; 4702f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); 4714cd24eafSJiri Pirko } else if (!netdev_mc_empty(dev->net)) { 47222bedad3SJiri Pirko struct netdev_hw_addr *ha; 4732f7ca802SSteve Glendinning 4742f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_HPFILT_; 4752f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); 4762f7ca802SSteve Glendinning 47722bedad3SJiri Pirko netdev_for_each_mc_addr(ha, netdev) { 47822bedad3SJiri Pirko u32 bitnum = smsc95xx_hash(ha->addr); 4792f7ca802SSteve Glendinning u32 mask = 0x01 << (bitnum & 0x1F); 4802f7ca802SSteve Glendinning if (bitnum & 0x20) 4813c0f3c60SMarc Zyngier pdata->hash_hi |= mask; 4822f7ca802SSteve Glendinning else 4833c0f3c60SMarc Zyngier pdata->hash_lo |= mask; 4842f7ca802SSteve Glendinning } 4852f7ca802SSteve Glendinning 486a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", 4873c0f3c60SMarc Zyngier pdata->hash_hi, pdata->hash_lo); 4882f7ca802SSteve Glendinning } else { 489a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive own packets only\n"); 4902f7ca802SSteve Glendinning pdata->mac_cr &= 4912f7ca802SSteve Glendinning ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4922f7ca802SSteve Glendinning } 4932f7ca802SSteve Glendinning 4942f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 4952f7ca802SSteve Glendinning 4962f7ca802SSteve Glendinning /* Initiate async writes, as we can't wait for completion here */ 4977b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi); 498b052e073SSteve Glendinning if (ret < 0) 499b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to HASHH\n"); 500769ea6d8SSteve Glendinning 5017b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo); 502b052e073SSteve Glendinning if (ret < 0) 503b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to HASHL\n"); 504769ea6d8SSteve Glendinning 5057b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr); 506b052e073SSteve Glendinning if (ret < 0) 507b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n"); 5082f7ca802SSteve Glendinning } 5092f7ca802SSteve Glendinning 510769ea6d8SSteve Glendinning static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, 5112f7ca802SSteve Glendinning u16 lcladv, u16 rmtadv) 5122f7ca802SSteve Glendinning { 5132f7ca802SSteve Glendinning u32 flow, afc_cfg = 0; 5142f7ca802SSteve Glendinning 5152f7ca802SSteve Glendinning int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); 516*e360a8b4SSteve Glendinning if (ret < 0) 517b052e073SSteve Glendinning return ret; 5182f7ca802SSteve Glendinning 5192f7ca802SSteve Glendinning if (duplex == DUPLEX_FULL) { 520bc02ff95SSteve Glendinning u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); 5212f7ca802SSteve Glendinning 5222f7ca802SSteve Glendinning if (cap & FLOW_CTRL_RX) 5232f7ca802SSteve Glendinning flow = 0xFFFF0002; 5242f7ca802SSteve Glendinning else 5252f7ca802SSteve Glendinning flow = 0; 5262f7ca802SSteve Glendinning 5272f7ca802SSteve Glendinning if (cap & FLOW_CTRL_TX) 5282f7ca802SSteve Glendinning afc_cfg |= 0xF; 5292f7ca802SSteve Glendinning else 5302f7ca802SSteve Glendinning afc_cfg &= ~0xF; 5312f7ca802SSteve Glendinning 532a475f603SJoe Perches netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", 53360b86755SJoe Perches cap & FLOW_CTRL_RX ? "enabled" : "disabled", 53460b86755SJoe Perches cap & FLOW_CTRL_TX ? "enabled" : "disabled"); 5352f7ca802SSteve Glendinning } else { 536a475f603SJoe Perches netif_dbg(dev, link, dev->net, "half duplex\n"); 5372f7ca802SSteve Glendinning flow = 0; 5382f7ca802SSteve Glendinning afc_cfg |= 0xF; 5392f7ca802SSteve Glendinning } 5402f7ca802SSteve Glendinning 541769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, flow); 542b052e073SSteve Glendinning if (ret < 0) 543b052e073SSteve Glendinning return ret; 544*e360a8b4SSteve Glendinning 545*e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); 5462f7ca802SSteve Glendinning } 5472f7ca802SSteve Glendinning 5482f7ca802SSteve Glendinning static int smsc95xx_link_reset(struct usbnet *dev) 5492f7ca802SSteve Glendinning { 5502f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 5512f7ca802SSteve Glendinning struct mii_if_info *mii = &dev->mii; 5528ae6dacaSDavid Decotigny struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 5532f7ca802SSteve Glendinning unsigned long flags; 5542f7ca802SSteve Glendinning u16 lcladv, rmtadv; 555769ea6d8SSteve Glendinning int ret; 5562f7ca802SSteve Glendinning 5572f7ca802SSteve Glendinning /* clear interrupt status */ 558769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); 559*e360a8b4SSteve Glendinning if (ret < 0) 560b052e073SSteve Glendinning return ret; 561769ea6d8SSteve Glendinning 562769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 563*e360a8b4SSteve Glendinning if (ret < 0) 564b052e073SSteve Glendinning return ret; 5652f7ca802SSteve Glendinning 5662f7ca802SSteve Glendinning mii_check_media(mii, 1, 1); 5672f7ca802SSteve Glendinning mii_ethtool_gset(&dev->mii, &ecmd); 5682f7ca802SSteve Glendinning lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); 5692f7ca802SSteve Glendinning rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA); 5702f7ca802SSteve Glendinning 5718ae6dacaSDavid Decotigny netif_dbg(dev, link, dev->net, 5728ae6dacaSDavid Decotigny "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", 5738ae6dacaSDavid Decotigny ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); 5742f7ca802SSteve Glendinning 5752f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 5762f7ca802SSteve Glendinning if (ecmd.duplex != DUPLEX_FULL) { 5772f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_FDPX_; 5782f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RCVOWN_; 5792f7ca802SSteve Glendinning } else { 5802f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_RCVOWN_; 5812f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_FDPX_; 5822f7ca802SSteve Glendinning } 5832f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5842f7ca802SSteve Glendinning 585769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 586*e360a8b4SSteve Glendinning if (ret < 0) 587b052e073SSteve Glendinning return ret; 5882f7ca802SSteve Glendinning 589769ea6d8SSteve Glendinning ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); 590b052e073SSteve Glendinning if (ret < 0) 591b052e073SSteve Glendinning netdev_warn(dev->net, "Error updating PHY flow control\n"); 5922f7ca802SSteve Glendinning 593b052e073SSteve Glendinning return ret; 5942f7ca802SSteve Glendinning } 5952f7ca802SSteve Glendinning 5962f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb) 5972f7ca802SSteve Glendinning { 5982f7ca802SSteve Glendinning u32 intdata; 5992f7ca802SSteve Glendinning 6002f7ca802SSteve Glendinning if (urb->actual_length != 4) { 60160b86755SJoe Perches netdev_warn(dev->net, "unexpected urb length %d\n", 60260b86755SJoe Perches urb->actual_length); 6032f7ca802SSteve Glendinning return; 6042f7ca802SSteve Glendinning } 6052f7ca802SSteve Glendinning 6062f7ca802SSteve Glendinning memcpy(&intdata, urb->transfer_buffer, 4); 6071d74a6bdSSteve Glendinning le32_to_cpus(&intdata); 6082f7ca802SSteve Glendinning 609a475f603SJoe Perches netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); 6102f7ca802SSteve Glendinning 6112f7ca802SSteve Glendinning if (intdata & INT_ENP_PHY_INT_) 6122f7ca802SSteve Glendinning usbnet_defer_kevent(dev, EVENT_LINK_RESET); 6132f7ca802SSteve Glendinning else 61460b86755SJoe Perches netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", 61560b86755SJoe Perches intdata); 6162f7ca802SSteve Glendinning } 6172f7ca802SSteve Glendinning 618f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */ 619c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev, 620c8f44affSMichał Mirosław netdev_features_t features) 6212f7ca802SSteve Glendinning { 62278e47fe4SMichał Mirosław struct usbnet *dev = netdev_priv(netdev); 6232f7ca802SSteve Glendinning u32 read_buf; 62478e47fe4SMichał Mirosław int ret; 62578e47fe4SMichał Mirosław 62678e47fe4SMichał Mirosław ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); 627*e360a8b4SSteve Glendinning if (ret < 0) 628b052e073SSteve Glendinning return ret; 6292f7ca802SSteve Glendinning 63078e47fe4SMichał Mirosław if (features & NETIF_F_HW_CSUM) 631f7b29271SSteve Glendinning read_buf |= Tx_COE_EN_; 632f7b29271SSteve Glendinning else 633f7b29271SSteve Glendinning read_buf &= ~Tx_COE_EN_; 634f7b29271SSteve Glendinning 63578e47fe4SMichał Mirosław if (features & NETIF_F_RXCSUM) 6362f7ca802SSteve Glendinning read_buf |= Rx_COE_EN_; 6372f7ca802SSteve Glendinning else 6382f7ca802SSteve Glendinning read_buf &= ~Rx_COE_EN_; 6392f7ca802SSteve Glendinning 6402f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, COE_CR, read_buf); 641*e360a8b4SSteve Glendinning if (ret < 0) 642b052e073SSteve Glendinning return ret; 6432f7ca802SSteve Glendinning 644a475f603SJoe Perches netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); 6452f7ca802SSteve Glendinning return 0; 6462f7ca802SSteve Glendinning } 6472f7ca802SSteve Glendinning 6482f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) 6492f7ca802SSteve Glendinning { 6502f7ca802SSteve Glendinning return MAX_EEPROM_SIZE; 6512f7ca802SSteve Glendinning } 6522f7ca802SSteve Glendinning 6532f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, 6542f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6552f7ca802SSteve Glendinning { 6562f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6572f7ca802SSteve Glendinning 6582f7ca802SSteve Glendinning ee->magic = LAN95XX_EEPROM_MAGIC; 6592f7ca802SSteve Glendinning 6602f7ca802SSteve Glendinning return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); 6612f7ca802SSteve Glendinning } 6622f7ca802SSteve Glendinning 6632f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, 6642f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6652f7ca802SSteve Glendinning { 6662f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6672f7ca802SSteve Glendinning 6682f7ca802SSteve Glendinning if (ee->magic != LAN95XX_EEPROM_MAGIC) { 66960b86755SJoe Perches netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", 6702f7ca802SSteve Glendinning ee->magic); 6712f7ca802SSteve Glendinning return -EINVAL; 6722f7ca802SSteve Glendinning } 6732f7ca802SSteve Glendinning 6742f7ca802SSteve Glendinning return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); 6752f7ca802SSteve Glendinning } 6762f7ca802SSteve Glendinning 6779fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev) 6789fa32e94SEmeric Vigier { 6799fa32e94SEmeric Vigier /* all smsc95xx registers */ 68096245317SSteve Glendinning return COE_CR - ID_REV + sizeof(u32); 6819fa32e94SEmeric Vigier } 6829fa32e94SEmeric Vigier 6839fa32e94SEmeric Vigier static void 6849fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, 6859fa32e94SEmeric Vigier void *buf) 6869fa32e94SEmeric Vigier { 6879fa32e94SEmeric Vigier struct usbnet *dev = netdev_priv(netdev); 688d348446bSDan Carpenter unsigned int i, j; 689d348446bSDan Carpenter int retval; 6909fa32e94SEmeric Vigier u32 *data = buf; 6919fa32e94SEmeric Vigier 6929fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); 6939fa32e94SEmeric Vigier if (retval < 0) { 6949fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read ID_REV\n"); 6959fa32e94SEmeric Vigier return; 6969fa32e94SEmeric Vigier } 6979fa32e94SEmeric Vigier 6989fa32e94SEmeric Vigier for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { 6999fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, i, &data[j]); 7009fa32e94SEmeric Vigier if (retval < 0) { 7019fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); 7029fa32e94SEmeric Vigier return; 7039fa32e94SEmeric Vigier } 7049fa32e94SEmeric Vigier } 7059fa32e94SEmeric Vigier } 7069fa32e94SEmeric Vigier 707e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net, 708e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 709e0e474a8SSteve Glendinning { 710e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 711e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 712e0e474a8SSteve Glendinning 713e0e474a8SSteve Glendinning wolinfo->supported = SUPPORTED_WAKE; 714e0e474a8SSteve Glendinning wolinfo->wolopts = pdata->wolopts; 715e0e474a8SSteve Glendinning } 716e0e474a8SSteve Glendinning 717e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net, 718e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 719e0e474a8SSteve Glendinning { 720e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 721e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7223b14692cSSteve Glendinning int ret; 723e0e474a8SSteve Glendinning 724e0e474a8SSteve Glendinning pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; 7253b14692cSSteve Glendinning 7263b14692cSSteve Glendinning ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); 727b052e073SSteve Glendinning if (ret < 0) 728b052e073SSteve Glendinning netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); 7293b14692cSSteve Glendinning 730b052e073SSteve Glendinning return ret; 731e0e474a8SSteve Glendinning } 732e0e474a8SSteve Glendinning 7330fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = { 7342f7ca802SSteve Glendinning .get_link = usbnet_get_link, 7352f7ca802SSteve Glendinning .nway_reset = usbnet_nway_reset, 7362f7ca802SSteve Glendinning .get_drvinfo = usbnet_get_drvinfo, 7372f7ca802SSteve Glendinning .get_msglevel = usbnet_get_msglevel, 7382f7ca802SSteve Glendinning .set_msglevel = usbnet_set_msglevel, 7392f7ca802SSteve Glendinning .get_settings = usbnet_get_settings, 7402f7ca802SSteve Glendinning .set_settings = usbnet_set_settings, 7412f7ca802SSteve Glendinning .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, 7422f7ca802SSteve Glendinning .get_eeprom = smsc95xx_ethtool_get_eeprom, 7432f7ca802SSteve Glendinning .set_eeprom = smsc95xx_ethtool_set_eeprom, 7449fa32e94SEmeric Vigier .get_regs_len = smsc95xx_ethtool_getregslen, 7459fa32e94SEmeric Vigier .get_regs = smsc95xx_ethtool_getregs, 746e0e474a8SSteve Glendinning .get_wol = smsc95xx_ethtool_get_wol, 747e0e474a8SSteve Glendinning .set_wol = smsc95xx_ethtool_set_wol, 7482f7ca802SSteve Glendinning }; 7492f7ca802SSteve Glendinning 7502f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 7512f7ca802SSteve Glendinning { 7522f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7532f7ca802SSteve Glendinning 7542f7ca802SSteve Glendinning if (!netif_running(netdev)) 7552f7ca802SSteve Glendinning return -EINVAL; 7562f7ca802SSteve Glendinning 7572f7ca802SSteve Glendinning return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 7582f7ca802SSteve Glendinning } 7592f7ca802SSteve Glendinning 7602f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev) 7612f7ca802SSteve Glendinning { 7622f7ca802SSteve Glendinning /* try reading mac address from EEPROM */ 7632f7ca802SSteve Glendinning if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, 7642f7ca802SSteve Glendinning dev->net->dev_addr) == 0) { 7652f7ca802SSteve Glendinning if (is_valid_ether_addr(dev->net->dev_addr)) { 7662f7ca802SSteve Glendinning /* eeprom values are valid so use them */ 767a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); 7682f7ca802SSteve Glendinning return; 7692f7ca802SSteve Glendinning } 7702f7ca802SSteve Glendinning } 7712f7ca802SSteve Glendinning 7722f7ca802SSteve Glendinning /* no eeprom, or eeprom values are invalid. generate random MAC */ 773f2cedb63SDanny Kukawka eth_hw_addr_random(dev->net); 774c7e12eadSJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); 7752f7ca802SSteve Glendinning } 7762f7ca802SSteve Glendinning 7772f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev) 7782f7ca802SSteve Glendinning { 7792f7ca802SSteve Glendinning u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | 7802f7ca802SSteve Glendinning dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; 7812f7ca802SSteve Glendinning u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; 7822f7ca802SSteve Glendinning int ret; 7832f7ca802SSteve Glendinning 7842f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); 785b052e073SSteve Glendinning if (ret < 0) 786b052e073SSteve Glendinning return ret; 787*e360a8b4SSteve Glendinning 788*e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, ADDRH, addr_hi); 7892f7ca802SSteve Glendinning } 7902f7ca802SSteve Glendinning 7912f7ca802SSteve Glendinning /* starts the TX path */ 792769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev) 7932f7ca802SSteve Glendinning { 7942f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7952f7ca802SSteve Glendinning unsigned long flags; 796769ea6d8SSteve Glendinning int ret; 7972f7ca802SSteve Glendinning 7982f7ca802SSteve Glendinning /* Enable Tx at MAC */ 7992f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 8002f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_TXEN_; 8012f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 8022f7ca802SSteve Glendinning 803769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 804*e360a8b4SSteve Glendinning if (ret < 0) 805b052e073SSteve Glendinning return ret; 8062f7ca802SSteve Glendinning 8072f7ca802SSteve Glendinning /* Enable Tx at SCSRs */ 808*e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); 8092f7ca802SSteve Glendinning } 8102f7ca802SSteve Glendinning 8112f7ca802SSteve Glendinning /* Starts the Receive path */ 812ec32115dSMing Lei static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) 8132f7ca802SSteve Glendinning { 8142f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 8152f7ca802SSteve Glendinning unsigned long flags; 8162f7ca802SSteve Glendinning 8172f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 8182f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RXEN_; 8192f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 8202f7ca802SSteve Glendinning 821*e360a8b4SSteve Glendinning return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm); 8222f7ca802SSteve Glendinning } 8232f7ca802SSteve Glendinning 8242f7ca802SSteve Glendinning static int smsc95xx_phy_initialize(struct usbnet *dev) 8252f7ca802SSteve Glendinning { 826769ea6d8SSteve Glendinning int bmcr, ret, timeout = 0; 827db443c44SSteve Glendinning 8282f7ca802SSteve Glendinning /* Initialize MII structure */ 8292f7ca802SSteve Glendinning dev->mii.dev = dev->net; 8302f7ca802SSteve Glendinning dev->mii.mdio_read = smsc95xx_mdio_read; 8312f7ca802SSteve Glendinning dev->mii.mdio_write = smsc95xx_mdio_write; 8322f7ca802SSteve Glendinning dev->mii.phy_id_mask = 0x1f; 8332f7ca802SSteve Glendinning dev->mii.reg_num_mask = 0x1f; 8342f7ca802SSteve Glendinning dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID; 8352f7ca802SSteve Glendinning 836db443c44SSteve Glendinning /* reset phy and wait for reset to complete */ 8372f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 838db443c44SSteve Glendinning 839db443c44SSteve Glendinning do { 840db443c44SSteve Glendinning msleep(10); 841db443c44SSteve Glendinning bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); 842db443c44SSteve Glendinning timeout++; 843d9460920SRabin Vincent } while ((bmcr & BMCR_RESET) && (timeout < 100)); 844db443c44SSteve Glendinning 845db443c44SSteve Glendinning if (timeout >= 100) { 846db443c44SSteve Glendinning netdev_warn(dev->net, "timeout on PHY Reset"); 847db443c44SSteve Glendinning return -EIO; 848db443c44SSteve Glendinning } 849db443c44SSteve Glendinning 8502f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, 8512f7ca802SSteve Glendinning ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | 8522f7ca802SSteve Glendinning ADVERTISE_PAUSE_ASYM); 8532f7ca802SSteve Glendinning 8542f7ca802SSteve Glendinning /* read to clear */ 855769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); 856b052e073SSteve Glendinning if (ret < 0) { 857b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n"); 858b052e073SSteve Glendinning return ret; 859b052e073SSteve Glendinning } 8602f7ca802SSteve Glendinning 8612f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, 8622f7ca802SSteve Glendinning PHY_INT_MASK_DEFAULT_); 8632f7ca802SSteve Glendinning mii_nway_restart(&dev->mii); 8642f7ca802SSteve Glendinning 865a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); 8662f7ca802SSteve Glendinning return 0; 8672f7ca802SSteve Glendinning } 8682f7ca802SSteve Glendinning 8692f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev) 8702f7ca802SSteve Glendinning { 8712f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 8722f7ca802SSteve Glendinning u32 read_buf, write_buf, burst_cap; 8732f7ca802SSteve Glendinning int ret = 0, timeout; 8742f7ca802SSteve Glendinning 875a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); 8762f7ca802SSteve Glendinning 8774436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); 878*e360a8b4SSteve Glendinning if (ret < 0) 879b052e073SSteve Glendinning return ret; 8802f7ca802SSteve Glendinning 8812f7ca802SSteve Glendinning timeout = 0; 8822f7ca802SSteve Glendinning do { 883cf2acec2SSteve Glendinning msleep(10); 8842f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 885*e360a8b4SSteve Glendinning if (ret < 0) 886b052e073SSteve Glendinning return ret; 8872f7ca802SSteve Glendinning timeout++; 8882f7ca802SSteve Glendinning } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); 8892f7ca802SSteve Glendinning 8902f7ca802SSteve Glendinning if (timeout >= 100) { 89160b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); 8922f7ca802SSteve Glendinning return ret; 8932f7ca802SSteve Glendinning } 8942f7ca802SSteve Glendinning 8954436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); 896*e360a8b4SSteve Glendinning if (ret < 0) 897b052e073SSteve Glendinning return ret; 8982f7ca802SSteve Glendinning 8992f7ca802SSteve Glendinning timeout = 0; 9002f7ca802SSteve Glendinning do { 901cf2acec2SSteve Glendinning msleep(10); 9022f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); 903*e360a8b4SSteve Glendinning if (ret < 0) 904b052e073SSteve Glendinning return ret; 9052f7ca802SSteve Glendinning timeout++; 9062f7ca802SSteve Glendinning } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); 9072f7ca802SSteve Glendinning 9082f7ca802SSteve Glendinning if (timeout >= 100) { 90960b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); 9102f7ca802SSteve Glendinning return ret; 9112f7ca802SSteve Glendinning } 9122f7ca802SSteve Glendinning 9132f7ca802SSteve Glendinning ret = smsc95xx_set_mac_address(dev); 9142f7ca802SSteve Glendinning if (ret < 0) 9152f7ca802SSteve Glendinning return ret; 9162f7ca802SSteve Glendinning 9171e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", 9181e1d7412SJoe Perches dev->net->dev_addr); 9192f7ca802SSteve Glendinning 9202f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 921*e360a8b4SSteve Glendinning if (ret < 0) 922b052e073SSteve Glendinning return ret; 9232f7ca802SSteve Glendinning 9241e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", 9251e1d7412SJoe Perches read_buf); 9262f7ca802SSteve Glendinning 9272f7ca802SSteve Glendinning read_buf |= HW_CFG_BIR_; 9282f7ca802SSteve Glendinning 9292f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 930*e360a8b4SSteve Glendinning if (ret < 0) 931b052e073SSteve Glendinning return ret; 9322f7ca802SSteve Glendinning 9332f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 934*e360a8b4SSteve Glendinning if (ret < 0) 935b052e073SSteve Glendinning return ret; 936b052e073SSteve Glendinning 937a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 938a475f603SJoe Perches "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", 93960b86755SJoe Perches read_buf); 9402f7ca802SSteve Glendinning 9412f7ca802SSteve Glendinning if (!turbo_mode) { 9422f7ca802SSteve Glendinning burst_cap = 0; 9432f7ca802SSteve Glendinning dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; 9442f7ca802SSteve Glendinning } else if (dev->udev->speed == USB_SPEED_HIGH) { 9452f7ca802SSteve Glendinning burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; 9462f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; 9472f7ca802SSteve Glendinning } else { 9482f7ca802SSteve Glendinning burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; 9492f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; 9502f7ca802SSteve Glendinning } 9512f7ca802SSteve Glendinning 9521e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", 9531e1d7412SJoe Perches (ulong)dev->rx_urb_size); 9542f7ca802SSteve Glendinning 9552f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); 956*e360a8b4SSteve Glendinning if (ret < 0) 957b052e073SSteve Glendinning return ret; 9582f7ca802SSteve Glendinning 9592f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); 960*e360a8b4SSteve Glendinning if (ret < 0) 961b052e073SSteve Glendinning return ret; 962769ea6d8SSteve Glendinning 963a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 964a475f603SJoe Perches "Read Value from BURST_CAP after writing: 0x%08x\n", 9652f7ca802SSteve Glendinning read_buf); 9662f7ca802SSteve Glendinning 9674436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); 968*e360a8b4SSteve Glendinning if (ret < 0) 969b052e073SSteve Glendinning return ret; 9702f7ca802SSteve Glendinning 9712f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); 972*e360a8b4SSteve Glendinning if (ret < 0) 973b052e073SSteve Glendinning return ret; 974769ea6d8SSteve Glendinning 975a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 976a475f603SJoe Perches "Read Value from BULK_IN_DLY after writing: 0x%08x\n", 97760b86755SJoe Perches read_buf); 9782f7ca802SSteve Glendinning 9792f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 980*e360a8b4SSteve Glendinning if (ret < 0) 981b052e073SSteve Glendinning return ret; 982769ea6d8SSteve Glendinning 9831e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n", 9841e1d7412SJoe Perches read_buf); 9852f7ca802SSteve Glendinning 9862f7ca802SSteve Glendinning if (turbo_mode) 9872f7ca802SSteve Glendinning read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); 9882f7ca802SSteve Glendinning 9892f7ca802SSteve Glendinning read_buf &= ~HW_CFG_RXDOFF_; 9902f7ca802SSteve Glendinning 9912f7ca802SSteve Glendinning /* set Rx data offset=2, Make IP header aligns on word boundary. */ 9922f7ca802SSteve Glendinning read_buf |= NET_IP_ALIGN << 9; 9932f7ca802SSteve Glendinning 9942f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 995*e360a8b4SSteve Glendinning if (ret < 0) 996b052e073SSteve Glendinning return ret; 9972f7ca802SSteve Glendinning 9982f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 999*e360a8b4SSteve Glendinning if (ret < 0) 1000b052e073SSteve Glendinning return ret; 1001769ea6d8SSteve Glendinning 1002a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1003a475f603SJoe Perches "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); 10042f7ca802SSteve Glendinning 10054436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 1006*e360a8b4SSteve Glendinning if (ret < 0) 1007b052e073SSteve Glendinning return ret; 10082f7ca802SSteve Glendinning 10092f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); 1010*e360a8b4SSteve Glendinning if (ret < 0) 1011b052e073SSteve Glendinning return ret; 1012a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); 10132f7ca802SSteve Glendinning 1014f293501cSSteve Glendinning /* Configure GPIO pins as LED outputs */ 1015f293501cSSteve Glendinning write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | 1016f293501cSSteve Glendinning LED_GPIO_CFG_FDX_LED; 1017f293501cSSteve Glendinning ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); 1018*e360a8b4SSteve Glendinning if (ret < 0) 1019b052e073SSteve Glendinning return ret; 1020f293501cSSteve Glendinning 10212f7ca802SSteve Glendinning /* Init Tx */ 10224436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, 0); 1023*e360a8b4SSteve Glendinning if (ret < 0) 1024b052e073SSteve Glendinning return ret; 10252f7ca802SSteve Glendinning 10264436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); 1027*e360a8b4SSteve Glendinning if (ret < 0) 1028b052e073SSteve Glendinning return ret; 10292f7ca802SSteve Glendinning 10302f7ca802SSteve Glendinning /* Don't need mac_cr_lock during initialisation */ 10312f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); 1032*e360a8b4SSteve Glendinning if (ret < 0) 1033b052e073SSteve Glendinning return ret; 10342f7ca802SSteve Glendinning 10352f7ca802SSteve Glendinning /* Init Rx */ 10362f7ca802SSteve Glendinning /* Set Vlan */ 10374436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); 1038*e360a8b4SSteve Glendinning if (ret < 0) 1039b052e073SSteve Glendinning return ret; 10402f7ca802SSteve Glendinning 1041f7b29271SSteve Glendinning /* Enable or disable checksum offload engines */ 1042769ea6d8SSteve Glendinning ret = smsc95xx_set_features(dev->net, dev->net->features); 1043b052e073SSteve Glendinning if (ret < 0) { 1044b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to set checksum offload features\n"); 1045b052e073SSteve Glendinning return ret; 1046b052e073SSteve Glendinning } 10472f7ca802SSteve Glendinning 10482f7ca802SSteve Glendinning smsc95xx_set_multicast(dev->net); 10492f7ca802SSteve Glendinning 1050769ea6d8SSteve Glendinning ret = smsc95xx_phy_initialize(dev); 1051b052e073SSteve Glendinning if (ret < 0) { 1052b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to init PHY\n"); 1053b052e073SSteve Glendinning return ret; 1054b052e073SSteve Glendinning } 10552f7ca802SSteve Glendinning 10562f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); 1057*e360a8b4SSteve Glendinning if (ret < 0) 1058b052e073SSteve Glendinning return ret; 10592f7ca802SSteve Glendinning 10602f7ca802SSteve Glendinning /* enable PHY interrupts */ 10612f7ca802SSteve Glendinning read_buf |= INT_EP_CTL_PHY_INT_; 10622f7ca802SSteve Glendinning 10632f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); 1064*e360a8b4SSteve Glendinning if (ret < 0) 1065b052e073SSteve Glendinning return ret; 10662f7ca802SSteve Glendinning 1067769ea6d8SSteve Glendinning ret = smsc95xx_start_tx_path(dev); 1068b052e073SSteve Glendinning if (ret < 0) { 1069b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start TX path\n"); 1070b052e073SSteve Glendinning return ret; 1071b052e073SSteve Glendinning } 1072769ea6d8SSteve Glendinning 1073ec32115dSMing Lei ret = smsc95xx_start_rx_path(dev, 0); 1074b052e073SSteve Glendinning if (ret < 0) { 1075b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start RX path\n"); 1076b052e073SSteve Glendinning return ret; 1077b052e073SSteve Glendinning } 10782f7ca802SSteve Glendinning 1079a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); 10802f7ca802SSteve Glendinning return 0; 10812f7ca802SSteve Glendinning } 10822f7ca802SSteve Glendinning 108363e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = { 108463e77b39SStephen Hemminger .ndo_open = usbnet_open, 108563e77b39SStephen Hemminger .ndo_stop = usbnet_stop, 108663e77b39SStephen Hemminger .ndo_start_xmit = usbnet_start_xmit, 108763e77b39SStephen Hemminger .ndo_tx_timeout = usbnet_tx_timeout, 108863e77b39SStephen Hemminger .ndo_change_mtu = usbnet_change_mtu, 108963e77b39SStephen Hemminger .ndo_set_mac_address = eth_mac_addr, 109063e77b39SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 109163e77b39SStephen Hemminger .ndo_do_ioctl = smsc95xx_ioctl, 1092afc4b13dSJiri Pirko .ndo_set_rx_mode = smsc95xx_set_multicast, 109378e47fe4SMichał Mirosław .ndo_set_features = smsc95xx_set_features, 109463e77b39SStephen Hemminger }; 109563e77b39SStephen Hemminger 10962f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) 10972f7ca802SSteve Glendinning { 10982f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = NULL; 1099bbd9f9eeSSteve Glendinning u32 val; 11002f7ca802SSteve Glendinning int ret; 11012f7ca802SSteve Glendinning 11022f7ca802SSteve Glendinning printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); 11032f7ca802SSteve Glendinning 11042f7ca802SSteve Glendinning ret = usbnet_get_endpoints(dev, intf); 1105b052e073SSteve Glendinning if (ret < 0) { 1106b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); 1107b052e073SSteve Glendinning return ret; 1108b052e073SSteve Glendinning } 11092f7ca802SSteve Glendinning 11102f7ca802SSteve Glendinning dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), 11112f7ca802SSteve Glendinning GFP_KERNEL); 11122f7ca802SSteve Glendinning 11132f7ca802SSteve Glendinning pdata = (struct smsc95xx_priv *)(dev->data[0]); 11142f7ca802SSteve Glendinning if (!pdata) { 111560b86755SJoe Perches netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n"); 11162f7ca802SSteve Glendinning return -ENOMEM; 11172f7ca802SSteve Glendinning } 11182f7ca802SSteve Glendinning 11192f7ca802SSteve Glendinning spin_lock_init(&pdata->mac_cr_lock); 11202f7ca802SSteve Glendinning 112178e47fe4SMichał Mirosław if (DEFAULT_TX_CSUM_ENABLE) 112278e47fe4SMichał Mirosław dev->net->features |= NETIF_F_HW_CSUM; 112378e47fe4SMichał Mirosław if (DEFAULT_RX_CSUM_ENABLE) 112478e47fe4SMichał Mirosław dev->net->features |= NETIF_F_RXCSUM; 112578e47fe4SMichał Mirosław 112678e47fe4SMichał Mirosław dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM; 11272f7ca802SSteve Glendinning 1128f4e8ab7cSBernard Blackham smsc95xx_init_mac_address(dev); 1129f4e8ab7cSBernard Blackham 11302f7ca802SSteve Glendinning /* Init all registers */ 11312f7ca802SSteve Glendinning ret = smsc95xx_reset(dev); 11322f7ca802SSteve Glendinning 1133bbd9f9eeSSteve Glendinning /* detect device revision as different features may be available */ 1134bbd9f9eeSSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &val); 1135*e360a8b4SSteve Glendinning if (ret < 0) 1136b052e073SSteve Glendinning return ret; 1137bbd9f9eeSSteve Glendinning val >>= 16; 11389ebca507SSteve Glendinning 11399ebca507SSteve Glendinning if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || 11409ebca507SSteve Glendinning (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) 11419ebca507SSteve Glendinning pdata->features = (FEATURE_8_WAKEUP_FILTERS | 11429ebca507SSteve Glendinning FEATURE_PHY_NLP_CROSSOVER | 11439ebca507SSteve Glendinning FEATURE_AUTOSUSPEND); 11449ebca507SSteve Glendinning else if (val == ID_REV_CHIP_ID_9512_) 11459ebca507SSteve Glendinning pdata->features = FEATURE_8_WAKEUP_FILTERS; 1146bbd9f9eeSSteve Glendinning 114763e77b39SStephen Hemminger dev->net->netdev_ops = &smsc95xx_netdev_ops; 11482f7ca802SSteve Glendinning dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 11492f7ca802SSteve Glendinning dev->net->flags |= IFF_MULTICAST; 115078e47fe4SMichał Mirosław dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 11519bbf5660SStephane Fillod dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; 11522f7ca802SSteve Glendinning return 0; 11532f7ca802SSteve Glendinning } 11542f7ca802SSteve Glendinning 11552f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) 11562f7ca802SSteve Glendinning { 11572f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 11582f7ca802SSteve Glendinning if (pdata) { 1159a475f603SJoe Perches netif_dbg(dev, ifdown, dev->net, "free pdata\n"); 11602f7ca802SSteve Glendinning kfree(pdata); 11612f7ca802SSteve Glendinning pdata = NULL; 11622f7ca802SSteve Glendinning dev->data[0] = 0; 11632f7ca802SSteve Glendinning } 11642f7ca802SSteve Glendinning } 11652f7ca802SSteve Glendinning 1166068bb1a7SSteve Glendinning static u32 smsc_crc(const u8 *buffer, size_t len, int filter) 1167bbd9f9eeSSteve Glendinning { 1168068bb1a7SSteve Glendinning u32 crc = bitrev16(crc16(0xFFFF, buffer, len)); 1169068bb1a7SSteve Glendinning return crc << ((filter % 2) * 16); 1170bbd9f9eeSSteve Glendinning } 1171bbd9f9eeSSteve Glendinning 1172e5e3af83SSteve Glendinning static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) 1173e5e3af83SSteve Glendinning { 1174e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1175e5e3af83SSteve Glendinning int ret; 1176e5e3af83SSteve Glendinning 11771e1d7412SJoe Perches netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n"); 1178e5e3af83SSteve Glendinning 1179e5e3af83SSteve Glendinning /* read to clear */ 1180e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC); 1181*e360a8b4SSteve Glendinning if (ret < 0) 1182b052e073SSteve Glendinning return ret; 1183e5e3af83SSteve Glendinning 1184e5e3af83SSteve Glendinning /* enable interrupt source */ 1185e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK); 1186*e360a8b4SSteve Glendinning if (ret < 0) 1187b052e073SSteve Glendinning return ret; 1188e5e3af83SSteve Glendinning 1189e5e3af83SSteve Glendinning ret |= mask; 1190e5e3af83SSteve Glendinning 1191e5e3af83SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret); 1192e5e3af83SSteve Glendinning 1193e5e3af83SSteve Glendinning return 0; 1194e5e3af83SSteve Glendinning } 1195e5e3af83SSteve Glendinning 1196e5e3af83SSteve Glendinning static int smsc95xx_link_ok_nopm(struct usbnet *dev) 1197e5e3af83SSteve Glendinning { 1198e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1199e5e3af83SSteve Glendinning int ret; 1200e5e3af83SSteve Glendinning 1201e5e3af83SSteve Glendinning /* first, a dummy read, needed to latch some MII phys */ 1202e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1203*e360a8b4SSteve Glendinning if (ret < 0) 1204b052e073SSteve Glendinning return ret; 1205e5e3af83SSteve Glendinning 1206e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1207*e360a8b4SSteve Glendinning if (ret < 0) 1208b052e073SSteve Glendinning return ret; 1209e5e3af83SSteve Glendinning 1210e5e3af83SSteve Glendinning return !!(ret & BMSR_LSTATUS); 1211e5e3af83SSteve Glendinning } 1212e5e3af83SSteve Glendinning 1213319b95b5SSteve Glendinning static int smsc95xx_enter_suspend0(struct usbnet *dev) 1214319b95b5SSteve Glendinning { 1215319b95b5SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1216319b95b5SSteve Glendinning u32 val; 1217319b95b5SSteve Glendinning int ret; 1218319b95b5SSteve Glendinning 1219319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1220*e360a8b4SSteve Glendinning if (ret < 0) 1221b052e073SSteve Glendinning return ret; 1222319b95b5SSteve Glendinning 1223319b95b5SSteve Glendinning val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); 1224319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_0; 1225319b95b5SSteve Glendinning 1226319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1227*e360a8b4SSteve Glendinning if (ret < 0) 1228b052e073SSteve Glendinning return ret; 1229319b95b5SSteve Glendinning 1230319b95b5SSteve Glendinning /* clear wol status */ 1231319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1232319b95b5SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1233319b95b5SSteve Glendinning 1234319b95b5SSteve Glendinning /* enable energy detection */ 1235319b95b5SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1236319b95b5SSteve Glendinning val |= PM_CTL_WUPS_ED_; 1237319b95b5SSteve Glendinning 1238319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1239*e360a8b4SSteve Glendinning if (ret < 0) 1240b052e073SSteve Glendinning return ret; 1241319b95b5SSteve Glendinning 1242319b95b5SSteve Glendinning /* read back PM_CTRL */ 1243319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1244319b95b5SSteve Glendinning 1245b052e073SSteve Glendinning return ret; 1246319b95b5SSteve Glendinning } 1247319b95b5SSteve Glendinning 1248319b95b5SSteve Glendinning static int smsc95xx_enter_suspend1(struct usbnet *dev) 1249319b95b5SSteve Glendinning { 1250319b95b5SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1251319b95b5SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1252319b95b5SSteve Glendinning u32 val; 1253319b95b5SSteve Glendinning int ret; 1254319b95b5SSteve Glendinning 1255319b95b5SSteve Glendinning /* reconfigure link pulse detection timing for 1256319b95b5SSteve Glendinning * compatibility with non-standard link partners 1257319b95b5SSteve Glendinning */ 1258319b95b5SSteve Glendinning if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) 1259319b95b5SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG, 1260319b95b5SSteve Glendinning PHY_EDPD_CONFIG_DEFAULT); 1261319b95b5SSteve Glendinning 1262319b95b5SSteve Glendinning /* enable energy detect power-down mode */ 1263319b95b5SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS); 1264*e360a8b4SSteve Glendinning if (ret < 0) 1265b052e073SSteve Glendinning return ret; 1266319b95b5SSteve Glendinning 1267319b95b5SSteve Glendinning ret |= MODE_CTRL_STS_EDPWRDOWN_; 1268319b95b5SSteve Glendinning 1269319b95b5SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret); 1270319b95b5SSteve Glendinning 1271319b95b5SSteve Glendinning /* enter SUSPEND1 mode */ 1272319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1273*e360a8b4SSteve Glendinning if (ret < 0) 1274b052e073SSteve Glendinning return ret; 1275319b95b5SSteve Glendinning 1276319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1277319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_1; 1278319b95b5SSteve Glendinning 1279319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1280*e360a8b4SSteve Glendinning if (ret < 0) 1281b052e073SSteve Glendinning return ret; 1282319b95b5SSteve Glendinning 1283319b95b5SSteve Glendinning /* clear wol status, enable energy detection */ 1284319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1285319b95b5SSteve Glendinning val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); 1286319b95b5SSteve Glendinning 1287319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1288319b95b5SSteve Glendinning 1289b052e073SSteve Glendinning return ret; 1290319b95b5SSteve Glendinning } 1291319b95b5SSteve Glendinning 1292319b95b5SSteve Glendinning static int smsc95xx_enter_suspend2(struct usbnet *dev) 1293319b95b5SSteve Glendinning { 1294319b95b5SSteve Glendinning u32 val; 1295319b95b5SSteve Glendinning int ret; 1296319b95b5SSteve Glendinning 1297319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1298*e360a8b4SSteve Glendinning if (ret < 0) 1299b052e073SSteve Glendinning return ret; 1300319b95b5SSteve Glendinning 1301319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1302319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_2; 1303319b95b5SSteve Glendinning 1304319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1305319b95b5SSteve Glendinning 1306b052e073SSteve Glendinning return ret; 1307319b95b5SSteve Glendinning } 1308319b95b5SSteve Glendinning 1309b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) 1310b5a04475SSteve Glendinning { 1311b5a04475SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1312e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1313e5e3af83SSteve Glendinning u32 val, link_up; 1314b5a04475SSteve Glendinning int ret; 1315b5a04475SSteve Glendinning 1316b5a04475SSteve Glendinning ret = usbnet_suspend(intf, message); 1317b052e073SSteve Glendinning if (ret < 0) { 1318b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_suspend error\n"); 1319b052e073SSteve Glendinning return ret; 1320b052e073SSteve Glendinning } 1321b5a04475SSteve Glendinning 1322e5e3af83SSteve Glendinning /* determine if link is up using only _nopm functions */ 1323e5e3af83SSteve Glendinning link_up = smsc95xx_link_ok_nopm(dev); 1324e5e3af83SSteve Glendinning 1325e5e3af83SSteve Glendinning /* if no wol options set, or if link is down and we're not waking on 1326e5e3af83SSteve Glendinning * PHY activity, enter lowest power SUSPEND2 mode 1327e5e3af83SSteve Glendinning */ 1328e5e3af83SSteve Glendinning if (!(pdata->wolopts & SUPPORTED_WAKE) || 1329e5e3af83SSteve Glendinning !(link_up || (pdata->wolopts & WAKE_PHY))) { 13301e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND2 mode\n"); 1331b5a04475SSteve Glendinning 1332e0e474a8SSteve Glendinning /* disable energy detect (link up) & wake up events */ 1333ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1334*e360a8b4SSteve Glendinning if (ret < 0) 1335b052e073SSteve Glendinning goto done; 1336e0e474a8SSteve Glendinning 1337e0e474a8SSteve Glendinning val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); 1338e0e474a8SSteve Glendinning 1339ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1340*e360a8b4SSteve Glendinning if (ret < 0) 1341b052e073SSteve Glendinning goto done; 1342e0e474a8SSteve Glendinning 1343ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1344*e360a8b4SSteve Glendinning if (ret < 0) 1345b052e073SSteve Glendinning goto done; 1346e0e474a8SSteve Glendinning 1347e0e474a8SSteve Glendinning val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); 1348e0e474a8SSteve Glendinning 1349ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1350*e360a8b4SSteve Glendinning if (ret < 0) 1351b052e073SSteve Glendinning goto done; 1352e0e474a8SSteve Glendinning 13533b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend2(dev); 13543b9f7d8cSSteve Glendinning goto done; 1355b5a04475SSteve Glendinning } 1356b5a04475SSteve Glendinning 1357e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) { 1358e5e3af83SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1359e5e3af83SSteve Glendinning (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_)); 1360b052e073SSteve Glendinning if (ret < 0) { 1361b052e073SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1362b052e073SSteve Glendinning goto done; 1363b052e073SSteve Glendinning } 1364e5e3af83SSteve Glendinning 1365e5e3af83SSteve Glendinning /* if link is down then configure EDPD and enter SUSPEND1, 1366e5e3af83SSteve Glendinning * otherwise enter SUSPEND0 below 1367e5e3af83SSteve Glendinning */ 1368e5e3af83SSteve Glendinning if (!link_up) { 13691e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND1 mode\n"); 13703b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend1(dev); 13713b9f7d8cSSteve Glendinning goto done; 1372e5e3af83SSteve Glendinning } 1373e5e3af83SSteve Glendinning } 1374e5e3af83SSteve Glendinning 1375bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 1376eed9a729SSteve Glendinning u32 *filter_mask = kzalloc(sizeof(u32) * 32, GFP_KERNEL); 137706a221beSMing Lei u32 command[2]; 137806a221beSMing Lei u32 offset[2]; 137906a221beSMing Lei u32 crc[4]; 13809ebca507SSteve Glendinning int wuff_filter_count = 13819ebca507SSteve Glendinning (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? 13829ebca507SSteve Glendinning LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; 1383bbd9f9eeSSteve Glendinning int i, filter = 0; 1384bbd9f9eeSSteve Glendinning 1385eed9a729SSteve Glendinning if (!filter_mask) { 1386eed9a729SSteve Glendinning netdev_warn(dev->net, "Unable to allocate filter_mask\n"); 13873b9f7d8cSSteve Glendinning ret = -ENOMEM; 13883b9f7d8cSSteve Glendinning goto done; 1389eed9a729SSteve Glendinning } 1390eed9a729SSteve Glendinning 139106a221beSMing Lei memset(command, 0, sizeof(command)); 139206a221beSMing Lei memset(offset, 0, sizeof(offset)); 139306a221beSMing Lei memset(crc, 0, sizeof(crc)); 139406a221beSMing Lei 1395bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_BCAST) { 1396bbd9f9eeSSteve Glendinning const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 13971e1d7412SJoe Perches netdev_info(dev->net, "enabling broadcast detection\n"); 1398bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1399bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1400bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1401bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1402bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1403bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1404bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(bcast, 6, filter); 1405bbd9f9eeSSteve Glendinning filter++; 1406bbd9f9eeSSteve Glendinning } 1407bbd9f9eeSSteve Glendinning 1408bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_MCAST) { 1409bbd9f9eeSSteve Glendinning const u8 mcast[] = {0x01, 0x00, 0x5E}; 14101e1d7412SJoe Perches netdev_info(dev->net, "enabling multicast detection\n"); 1411bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0007; 1412bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1413bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1414bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1415bbd9f9eeSSteve Glendinning command[filter/4] |= 0x09UL << ((filter % 4) * 8); 1416bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1417bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(mcast, 3, filter); 1418bbd9f9eeSSteve Glendinning filter++; 1419bbd9f9eeSSteve Glendinning } 1420bbd9f9eeSSteve Glendinning 1421bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_ARP) { 1422bbd9f9eeSSteve Glendinning const u8 arp[] = {0x08, 0x06}; 14231e1d7412SJoe Perches netdev_info(dev->net, "enabling ARP detection\n"); 1424bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0003; 1425bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1426bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1427bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1428bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1429bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x0C << ((filter % 4) * 8); 1430bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(arp, 2, filter); 1431bbd9f9eeSSteve Glendinning filter++; 1432bbd9f9eeSSteve Glendinning } 1433bbd9f9eeSSteve Glendinning 1434bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_UCAST) { 14351e1d7412SJoe Perches netdev_info(dev->net, "enabling unicast detection\n"); 1436bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1437bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1438bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1439bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1440bbd9f9eeSSteve Glendinning command[filter/4] |= 0x01UL << ((filter % 4) * 8); 1441bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1442bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); 1443bbd9f9eeSSteve Glendinning filter++; 1444bbd9f9eeSSteve Glendinning } 1445bbd9f9eeSSteve Glendinning 14469ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count * 4); i++) { 1447ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]); 1448b052e073SSteve Glendinning if (ret < 0) { 144906a221beSMing Lei kfree(filter_mask); 1450b052e073SSteve Glendinning goto done; 1451b052e073SSteve Glendinning } 1452bbd9f9eeSSteve Glendinning } 145306a221beSMing Lei kfree(filter_mask); 1454bbd9f9eeSSteve Glendinning 14559ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1456ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]); 1457*e360a8b4SSteve Glendinning if (ret < 0) 1458b052e073SSteve Glendinning goto done; 1459b052e073SSteve Glendinning } 1460bbd9f9eeSSteve Glendinning 14619ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1462ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]); 1463*e360a8b4SSteve Glendinning if (ret < 0) 1464b052e073SSteve Glendinning goto done; 1465b052e073SSteve Glendinning } 1466bbd9f9eeSSteve Glendinning 14679ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 2); i++) { 1468ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]); 1469*e360a8b4SSteve Glendinning if (ret < 0) 1470b052e073SSteve Glendinning goto done; 1471b052e073SSteve Glendinning } 1472bbd9f9eeSSteve Glendinning 1473bbd9f9eeSSteve Glendinning /* clear any pending pattern match packet status */ 1474ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1475*e360a8b4SSteve Glendinning if (ret < 0) 1476b052e073SSteve Glendinning goto done; 1477bbd9f9eeSSteve Glendinning 1478bbd9f9eeSSteve Glendinning val |= WUCSR_WUFR_; 1479bbd9f9eeSSteve Glendinning 1480ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1481*e360a8b4SSteve Glendinning if (ret < 0) 1482b052e073SSteve Glendinning goto done; 1483b052e073SSteve Glendinning } 1484bbd9f9eeSSteve Glendinning 1485e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1486e0e474a8SSteve Glendinning /* clear any pending magic packet status */ 1487ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1488*e360a8b4SSteve Glendinning if (ret < 0) 1489b052e073SSteve Glendinning goto done; 1490e0e474a8SSteve Glendinning 1491e0e474a8SSteve Glendinning val |= WUCSR_MPR_; 1492e0e474a8SSteve Glendinning 1493ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1494*e360a8b4SSteve Glendinning if (ret < 0) 1495b052e073SSteve Glendinning goto done; 1496b052e073SSteve Glendinning } 1497e0e474a8SSteve Glendinning 1498bbd9f9eeSSteve Glendinning /* enable/disable wakeup sources */ 1499ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1500*e360a8b4SSteve Glendinning if (ret < 0) 1501b052e073SSteve Glendinning goto done; 1502e0e474a8SSteve Glendinning 1503bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 15041e1d7412SJoe Perches netdev_info(dev->net, "enabling pattern match wakeup\n"); 1505bbd9f9eeSSteve Glendinning val |= WUCSR_WAKE_EN_; 1506bbd9f9eeSSteve Glendinning } else { 15071e1d7412SJoe Perches netdev_info(dev->net, "disabling pattern match wakeup\n"); 1508bbd9f9eeSSteve Glendinning val &= ~WUCSR_WAKE_EN_; 1509bbd9f9eeSSteve Glendinning } 1510bbd9f9eeSSteve Glendinning 1511e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 15121e1d7412SJoe Perches netdev_info(dev->net, "enabling magic packet wakeup\n"); 1513e0e474a8SSteve Glendinning val |= WUCSR_MPEN_; 1514e0e474a8SSteve Glendinning } else { 15151e1d7412SJoe Perches netdev_info(dev->net, "disabling magic packet wakeup\n"); 1516e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1517e0e474a8SSteve Glendinning } 1518e0e474a8SSteve Glendinning 1519ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1520*e360a8b4SSteve Glendinning if (ret < 0) 1521b052e073SSteve Glendinning goto done; 1522e0e474a8SSteve Glendinning 1523e0e474a8SSteve Glendinning /* enable wol wakeup source */ 1524ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1525*e360a8b4SSteve Glendinning if (ret < 0) 1526b052e073SSteve Glendinning goto done; 1527e0e474a8SSteve Glendinning 1528e0e474a8SSteve Glendinning val |= PM_CTL_WOL_EN_; 1529e0e474a8SSteve Glendinning 1530e5e3af83SSteve Glendinning /* phy energy detect wakeup source */ 1531e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1532e5e3af83SSteve Glendinning val |= PM_CTL_ED_EN_; 1533e5e3af83SSteve Glendinning 1534ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1535*e360a8b4SSteve Glendinning if (ret < 0) 1536b052e073SSteve Glendinning goto done; 1537e0e474a8SSteve Glendinning 1538bbd9f9eeSSteve Glendinning /* enable receiver to enable frame reception */ 1539ec32115dSMing Lei smsc95xx_start_rx_path(dev, 1); 1540e0e474a8SSteve Glendinning 1541e0e474a8SSteve Glendinning /* some wol options are enabled, so enter SUSPEND0 */ 15421e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND0 mode\n"); 15433b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend0(dev); 15443b9f7d8cSSteve Glendinning 15453b9f7d8cSSteve Glendinning done: 15463b9f7d8cSSteve Glendinning if (ret) 15473b9f7d8cSSteve Glendinning usbnet_resume(intf); 15483b9f7d8cSSteve Glendinning return ret; 1549e0e474a8SSteve Glendinning } 1550e0e474a8SSteve Glendinning 1551e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf) 1552e0e474a8SSteve Glendinning { 1553e0e474a8SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1554e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1555e0e474a8SSteve Glendinning int ret; 1556e0e474a8SSteve Glendinning u32 val; 1557e0e474a8SSteve Glendinning 1558e0e474a8SSteve Glendinning BUG_ON(!dev); 1559e0e474a8SSteve Glendinning 1560bbd9f9eeSSteve Glendinning if (pdata->wolopts) { 1561bbd9f9eeSSteve Glendinning /* clear wake-up sources */ 1562ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1563*e360a8b4SSteve Glendinning if (ret < 0) 1564b052e073SSteve Glendinning return ret; 1565e0e474a8SSteve Glendinning 1566bbd9f9eeSSteve Glendinning val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); 1567e0e474a8SSteve Glendinning 1568ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1569*e360a8b4SSteve Glendinning if (ret < 0) 1570b052e073SSteve Glendinning return ret; 1571e0e474a8SSteve Glendinning 1572e0e474a8SSteve Glendinning /* clear wake-up status */ 1573ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1574*e360a8b4SSteve Glendinning if (ret < 0) 1575b052e073SSteve Glendinning return ret; 1576e0e474a8SSteve Glendinning 1577e0e474a8SSteve Glendinning val &= ~PM_CTL_WOL_EN_; 1578e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_; 1579e0e474a8SSteve Glendinning 1580ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1581*e360a8b4SSteve Glendinning if (ret < 0) 1582b052e073SSteve Glendinning return ret; 1583b052e073SSteve Glendinning } 1584e0e474a8SSteve Glendinning 1585af3d7c1eSSteve Glendinning ret = usbnet_resume(intf); 1586b052e073SSteve Glendinning if (ret < 0) 1587b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_resume error\n"); 1588e0e474a8SSteve Glendinning 1589b052e073SSteve Glendinning return ret; 1590e0e474a8SSteve Glendinning } 1591e0e474a8SSteve Glendinning 15922f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb) 15932f7ca802SSteve Glendinning { 15942f7ca802SSteve Glendinning skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); 15952f7ca802SSteve Glendinning skb->ip_summed = CHECKSUM_COMPLETE; 15962f7ca802SSteve Glendinning skb_trim(skb, skb->len - 2); 15972f7ca802SSteve Glendinning } 15982f7ca802SSteve Glendinning 15992f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 16002f7ca802SSteve Glendinning { 16012f7ca802SSteve Glendinning while (skb->len > 0) { 16022f7ca802SSteve Glendinning u32 header, align_count; 16032f7ca802SSteve Glendinning struct sk_buff *ax_skb; 16042f7ca802SSteve Glendinning unsigned char *packet; 16052f7ca802SSteve Glendinning u16 size; 16062f7ca802SSteve Glendinning 16072f7ca802SSteve Glendinning memcpy(&header, skb->data, sizeof(header)); 16082f7ca802SSteve Glendinning le32_to_cpus(&header); 16092f7ca802SSteve Glendinning skb_pull(skb, 4 + NET_IP_ALIGN); 16102f7ca802SSteve Glendinning packet = skb->data; 16112f7ca802SSteve Glendinning 16122f7ca802SSteve Glendinning /* get the packet length */ 16132f7ca802SSteve Glendinning size = (u16)((header & RX_STS_FL_) >> 16); 16142f7ca802SSteve Glendinning align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 16152f7ca802SSteve Glendinning 16162f7ca802SSteve Glendinning if (unlikely(header & RX_STS_ES_)) { 1617a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1618a475f603SJoe Perches "Error header=0x%08x\n", header); 161980667ac1SHerbert Xu dev->net->stats.rx_errors++; 162080667ac1SHerbert Xu dev->net->stats.rx_dropped++; 16212f7ca802SSteve Glendinning 16222f7ca802SSteve Glendinning if (header & RX_STS_CRC_) { 162380667ac1SHerbert Xu dev->net->stats.rx_crc_errors++; 16242f7ca802SSteve Glendinning } else { 16252f7ca802SSteve Glendinning if (header & (RX_STS_TL_ | RX_STS_RF_)) 162680667ac1SHerbert Xu dev->net->stats.rx_frame_errors++; 16272f7ca802SSteve Glendinning 16282f7ca802SSteve Glendinning if ((header & RX_STS_LE_) && 16292f7ca802SSteve Glendinning (!(header & RX_STS_FT_))) 163080667ac1SHerbert Xu dev->net->stats.rx_length_errors++; 16312f7ca802SSteve Glendinning } 16322f7ca802SSteve Glendinning } else { 16332f7ca802SSteve Glendinning /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ 16342f7ca802SSteve Glendinning if (unlikely(size > (ETH_FRAME_LEN + 12))) { 1635a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1636a475f603SJoe Perches "size err header=0x%08x\n", header); 16372f7ca802SSteve Glendinning return 0; 16382f7ca802SSteve Glendinning } 16392f7ca802SSteve Glendinning 16402f7ca802SSteve Glendinning /* last frame in this batch */ 16412f7ca802SSteve Glendinning if (skb->len == size) { 164278e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 16432f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(skb); 1644df18accaSPeter Korsgaard skb_trim(skb, skb->len - 4); /* remove fcs */ 16452f7ca802SSteve Glendinning skb->truesize = size + sizeof(struct sk_buff); 16462f7ca802SSteve Glendinning 16472f7ca802SSteve Glendinning return 1; 16482f7ca802SSteve Glendinning } 16492f7ca802SSteve Glendinning 16502f7ca802SSteve Glendinning ax_skb = skb_clone(skb, GFP_ATOMIC); 16512f7ca802SSteve Glendinning if (unlikely(!ax_skb)) { 165260b86755SJoe Perches netdev_warn(dev->net, "Error allocating skb\n"); 16532f7ca802SSteve Glendinning return 0; 16542f7ca802SSteve Glendinning } 16552f7ca802SSteve Glendinning 16562f7ca802SSteve Glendinning ax_skb->len = size; 16572f7ca802SSteve Glendinning ax_skb->data = packet; 16582f7ca802SSteve Glendinning skb_set_tail_pointer(ax_skb, size); 16592f7ca802SSteve Glendinning 166078e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 16612f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(ax_skb); 1662df18accaSPeter Korsgaard skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 16632f7ca802SSteve Glendinning ax_skb->truesize = size + sizeof(struct sk_buff); 16642f7ca802SSteve Glendinning 16652f7ca802SSteve Glendinning usbnet_skb_return(dev, ax_skb); 16662f7ca802SSteve Glendinning } 16672f7ca802SSteve Glendinning 16682f7ca802SSteve Glendinning skb_pull(skb, size); 16692f7ca802SSteve Glendinning 16702f7ca802SSteve Glendinning /* padding bytes before the next frame starts */ 16712f7ca802SSteve Glendinning if (skb->len) 16722f7ca802SSteve Glendinning skb_pull(skb, align_count); 16732f7ca802SSteve Glendinning } 16742f7ca802SSteve Glendinning 16752f7ca802SSteve Glendinning if (unlikely(skb->len < 0)) { 167660b86755SJoe Perches netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len); 16772f7ca802SSteve Glendinning return 0; 16782f7ca802SSteve Glendinning } 16792f7ca802SSteve Glendinning 16802f7ca802SSteve Glendinning return 1; 16812f7ca802SSteve Glendinning } 16822f7ca802SSteve Glendinning 1683f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) 1684f7b29271SSteve Glendinning { 168555508d60SMichał Mirosław u16 low_16 = (u16)skb_checksum_start_offset(skb); 168655508d60SMichał Mirosław u16 high_16 = low_16 + skb->csum_offset; 1687f7b29271SSteve Glendinning return (high_16 << 16) | low_16; 1688f7b29271SSteve Glendinning } 1689f7b29271SSteve Glendinning 16902f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 16912f7ca802SSteve Glendinning struct sk_buff *skb, gfp_t flags) 16922f7ca802SSteve Glendinning { 169378e47fe4SMichał Mirosław bool csum = skb->ip_summed == CHECKSUM_PARTIAL; 1694f7b29271SSteve Glendinning int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; 16952f7ca802SSteve Glendinning u32 tx_cmd_a, tx_cmd_b; 16962f7ca802SSteve Glendinning 1697f7b29271SSteve Glendinning /* We do not advertise SG, so skbs should be already linearized */ 1698f7b29271SSteve Glendinning BUG_ON(skb_shinfo(skb)->nr_frags); 1699f7b29271SSteve Glendinning 1700f7b29271SSteve Glendinning if (skb_headroom(skb) < overhead) { 17012f7ca802SSteve Glendinning struct sk_buff *skb2 = skb_copy_expand(skb, 1702f7b29271SSteve Glendinning overhead, 0, flags); 17032f7ca802SSteve Glendinning dev_kfree_skb_any(skb); 17042f7ca802SSteve Glendinning skb = skb2; 17052f7ca802SSteve Glendinning if (!skb) 17062f7ca802SSteve Glendinning return NULL; 17072f7ca802SSteve Glendinning } 17082f7ca802SSteve Glendinning 1709f7b29271SSteve Glendinning if (csum) { 171011bc3088SSteve Glendinning if (skb->len <= 45) { 171111bc3088SSteve Glendinning /* workaround - hardware tx checksum does not work 171211bc3088SSteve Glendinning * properly with extremely small packets */ 171355508d60SMichał Mirosław long csstart = skb_checksum_start_offset(skb); 171411bc3088SSteve Glendinning __wsum calc = csum_partial(skb->data + csstart, 171511bc3088SSteve Glendinning skb->len - csstart, 0); 171611bc3088SSteve Glendinning *((__sum16 *)(skb->data + csstart 171711bc3088SSteve Glendinning + skb->csum_offset)) = csum_fold(calc); 171811bc3088SSteve Glendinning 171911bc3088SSteve Glendinning csum = false; 172011bc3088SSteve Glendinning } else { 1721f7b29271SSteve Glendinning u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); 1722f7b29271SSteve Glendinning skb_push(skb, 4); 172300acda68SSteve Glendinning cpu_to_le32s(&csum_preamble); 1724f7b29271SSteve Glendinning memcpy(skb->data, &csum_preamble, 4); 1725f7b29271SSteve Glendinning } 172611bc3088SSteve Glendinning } 1727f7b29271SSteve Glendinning 17282f7ca802SSteve Glendinning skb_push(skb, 4); 17292f7ca802SSteve Glendinning tx_cmd_b = (u32)(skb->len - 4); 1730f7b29271SSteve Glendinning if (csum) 1731f7b29271SSteve Glendinning tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; 17322f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_b); 17332f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_b, 4); 17342f7ca802SSteve Glendinning 17352f7ca802SSteve Glendinning skb_push(skb, 4); 17362f7ca802SSteve Glendinning tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ | 17372f7ca802SSteve Glendinning TX_CMD_A_LAST_SEG_; 17382f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_a); 17392f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_a, 4); 17402f7ca802SSteve Glendinning 17412f7ca802SSteve Glendinning return skb; 17422f7ca802SSteve Glendinning } 17432f7ca802SSteve Glendinning 17442f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = { 17452f7ca802SSteve Glendinning .description = "smsc95xx USB 2.0 Ethernet", 17462f7ca802SSteve Glendinning .bind = smsc95xx_bind, 17472f7ca802SSteve Glendinning .unbind = smsc95xx_unbind, 17482f7ca802SSteve Glendinning .link_reset = smsc95xx_link_reset, 17492f7ca802SSteve Glendinning .reset = smsc95xx_reset, 17502f7ca802SSteve Glendinning .rx_fixup = smsc95xx_rx_fixup, 17512f7ca802SSteve Glendinning .tx_fixup = smsc95xx_tx_fixup, 17522f7ca802SSteve Glendinning .status = smsc95xx_status, 175307d69d42SPaolo Pisati .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, 17542f7ca802SSteve Glendinning }; 17552f7ca802SSteve Glendinning 17562f7ca802SSteve Glendinning static const struct usb_device_id products[] = { 17572f7ca802SSteve Glendinning { 17582f7ca802SSteve Glendinning /* SMSC9500 USB Ethernet Device */ 17592f7ca802SSteve Glendinning USB_DEVICE(0x0424, 0x9500), 17602f7ca802SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17612f7ca802SSteve Glendinning }, 1762726474b8SSteve Glendinning { 17636f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device */ 17646f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9505), 17656f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17666f41d12bSSteve Glendinning }, 17676f41d12bSSteve Glendinning { 17686f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device */ 17696f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E00), 17706f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17716f41d12bSSteve Glendinning }, 17726f41d12bSSteve Glendinning { 17736f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device */ 17746f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E01), 17756f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17766f41d12bSSteve Glendinning }, 17776f41d12bSSteve Glendinning { 1778726474b8SSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device */ 1779726474b8SSteve Glendinning USB_DEVICE(0x0424, 0xec00), 1780726474b8SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 1781726474b8SSteve Glendinning }, 17826f41d12bSSteve Glendinning { 17836f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (SAL10) */ 17846f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9900), 17856f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17866f41d12bSSteve Glendinning }, 17876f41d12bSSteve Glendinning { 17886f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device (SAL10) */ 17896f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9901), 17906f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17916f41d12bSSteve Glendinning }, 17926f41d12bSSteve Glendinning { 17936f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (SAL10) */ 17946f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9902), 17956f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 17966f41d12bSSteve Glendinning }, 17976f41d12bSSteve Glendinning { 17986f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (SAL10) */ 17996f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9903), 18006f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18016f41d12bSSteve Glendinning }, 18026f41d12bSSteve Glendinning { 18036f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ 18046f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9904), 18056f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18066f41d12bSSteve Glendinning }, 18076f41d12bSSteve Glendinning { 18086f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (HAL) */ 18096f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9905), 18106f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18116f41d12bSSteve Glendinning }, 18126f41d12bSSteve Glendinning { 18136f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (HAL) */ 18146f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9906), 18156f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18166f41d12bSSteve Glendinning }, 18176f41d12bSSteve Glendinning { 18186f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (Alternate ID) */ 18196f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9907), 18206f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18216f41d12bSSteve Glendinning }, 18226f41d12bSSteve Glendinning { 18236f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (Alternate ID) */ 18246f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9908), 18256f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18266f41d12bSSteve Glendinning }, 18276f41d12bSSteve Glendinning { 18286f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ 18296f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9909), 18306f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 18316f41d12bSSteve Glendinning }, 183288edaa41SSteve Glendinning { 183388edaa41SSteve Glendinning /* SMSC LAN9530 USB Ethernet Device */ 183488edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9530), 183588edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 183688edaa41SSteve Glendinning }, 183788edaa41SSteve Glendinning { 183888edaa41SSteve Glendinning /* SMSC LAN9730 USB Ethernet Device */ 183988edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9730), 184088edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 184188edaa41SSteve Glendinning }, 184288edaa41SSteve Glendinning { 184388edaa41SSteve Glendinning /* SMSC LAN89530 USB Ethernet Device */ 184488edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9E08), 184588edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 184688edaa41SSteve Glendinning }, 18472f7ca802SSteve Glendinning { }, /* END */ 18482f7ca802SSteve Glendinning }; 18492f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products); 18502f7ca802SSteve Glendinning 18512f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = { 18522f7ca802SSteve Glendinning .name = "smsc95xx", 18532f7ca802SSteve Glendinning .id_table = products, 18542f7ca802SSteve Glendinning .probe = usbnet_probe, 1855b5a04475SSteve Glendinning .suspend = smsc95xx_suspend, 1856e0e474a8SSteve Glendinning .resume = smsc95xx_resume, 1857e0e474a8SSteve Glendinning .reset_resume = smsc95xx_resume, 18582f7ca802SSteve Glendinning .disconnect = usbnet_disconnect, 1859e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 18602f7ca802SSteve Glendinning }; 18612f7ca802SSteve Glendinning 1862d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver); 18632f7ca802SSteve Glendinning 18642f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin"); 186590b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); 18662f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); 18672f7ca802SSteve Glendinning MODULE_LICENSE("GPL"); 1868