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> 292f7ca802SSteve Glendinning #include <linux/crc32.h> 302f7ca802SSteve Glendinning #include <linux/usb/usbnet.h> 315a0e3ad6STejun Heo #include <linux/slab.h> 322f7ca802SSteve Glendinning #include "smsc95xx.h" 332f7ca802SSteve Glendinning 342f7ca802SSteve Glendinning #define SMSC_CHIPNAME "smsc95xx" 35f7b29271SSteve Glendinning #define SMSC_DRIVER_VERSION "1.0.4" 362f7ca802SSteve Glendinning #define HS_USB_PKT_SIZE (512) 372f7ca802SSteve Glendinning #define FS_USB_PKT_SIZE (64) 382f7ca802SSteve Glendinning #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) 392f7ca802SSteve Glendinning #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) 402f7ca802SSteve Glendinning #define DEFAULT_BULK_IN_DELAY (0x00002000) 412f7ca802SSteve Glendinning #define MAX_SINGLE_PACKET_SIZE (2048) 422f7ca802SSteve Glendinning #define LAN95XX_EEPROM_MAGIC (0x9500) 432f7ca802SSteve Glendinning #define EEPROM_MAC_OFFSET (0x01) 44f7b29271SSteve Glendinning #define DEFAULT_TX_CSUM_ENABLE (true) 452f7ca802SSteve Glendinning #define DEFAULT_RX_CSUM_ENABLE (true) 462f7ca802SSteve Glendinning #define SMSC95XX_INTERNAL_PHY_ID (1) 472f7ca802SSteve Glendinning #define SMSC95XX_TX_OVERHEAD (8) 48f7b29271SSteve Glendinning #define SMSC95XX_TX_OVERHEAD_CSUM (12) 49*e0e474a8SSteve Glendinning #define SUPPORTED_WAKE (WAKE_MAGIC) 502f7ca802SSteve Glendinning 51769ea6d8SSteve Glendinning #define check_warn(ret, fmt, args...) \ 52769ea6d8SSteve Glendinning ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); }) 53769ea6d8SSteve Glendinning 54769ea6d8SSteve Glendinning #define check_warn_return(ret, fmt, args...) \ 55769ea6d8SSteve Glendinning ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } }) 56769ea6d8SSteve Glendinning 57769ea6d8SSteve Glendinning #define check_warn_goto_done(ret, fmt, args...) \ 58769ea6d8SSteve Glendinning ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } }) 59769ea6d8SSteve Glendinning 602f7ca802SSteve Glendinning struct smsc95xx_priv { 612f7ca802SSteve Glendinning u32 mac_cr; 623c0f3c60SMarc Zyngier u32 hash_hi; 633c0f3c60SMarc Zyngier u32 hash_lo; 64*e0e474a8SSteve Glendinning u32 wolopts; 652f7ca802SSteve Glendinning spinlock_t mac_cr_lock; 662f7ca802SSteve Glendinning }; 672f7ca802SSteve Glendinning 682f7ca802SSteve Glendinning struct usb_context { 692f7ca802SSteve Glendinning struct usb_ctrlrequest req; 702f7ca802SSteve Glendinning struct usbnet *dev; 712f7ca802SSteve Glendinning }; 722f7ca802SSteve Glendinning 73eb939922SRusty Russell static bool turbo_mode = true; 742f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644); 752f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); 762f7ca802SSteve Glendinning 77769ea6d8SSteve Glendinning static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, 78769ea6d8SSteve Glendinning u32 *data) 792f7ca802SSteve Glendinning { 802f7ca802SSteve Glendinning u32 *buf = kmalloc(4, GFP_KERNEL); 812f7ca802SSteve Glendinning int ret; 822f7ca802SSteve Glendinning 832f7ca802SSteve Glendinning BUG_ON(!dev); 842f7ca802SSteve Glendinning 852f7ca802SSteve Glendinning if (!buf) 862f7ca802SSteve Glendinning return -ENOMEM; 872f7ca802SSteve Glendinning 882f7ca802SSteve Glendinning ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), 892f7ca802SSteve Glendinning USB_VENDOR_REQUEST_READ_REGISTER, 902f7ca802SSteve Glendinning USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 912f7ca802SSteve Glendinning 00, index, buf, 4, USB_CTRL_GET_TIMEOUT); 922f7ca802SSteve Glendinning 932f7ca802SSteve Glendinning if (unlikely(ret < 0)) 9460b86755SJoe Perches netdev_warn(dev->net, "Failed to read register index 0x%08x\n", index); 952f7ca802SSteve Glendinning 962f7ca802SSteve Glendinning le32_to_cpus(buf); 972f7ca802SSteve Glendinning *data = *buf; 982f7ca802SSteve Glendinning kfree(buf); 992f7ca802SSteve Glendinning 1002f7ca802SSteve Glendinning return ret; 1012f7ca802SSteve Glendinning } 1022f7ca802SSteve Glendinning 103769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, 104769ea6d8SSteve Glendinning u32 data) 1052f7ca802SSteve Glendinning { 1062f7ca802SSteve Glendinning u32 *buf = kmalloc(4, GFP_KERNEL); 1072f7ca802SSteve Glendinning int ret; 1082f7ca802SSteve Glendinning 1092f7ca802SSteve Glendinning BUG_ON(!dev); 1102f7ca802SSteve Glendinning 1112f7ca802SSteve Glendinning if (!buf) 1122f7ca802SSteve Glendinning return -ENOMEM; 1132f7ca802SSteve Glendinning 1142f7ca802SSteve Glendinning *buf = data; 1152f7ca802SSteve Glendinning cpu_to_le32s(buf); 1162f7ca802SSteve Glendinning 1172f7ca802SSteve Glendinning ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), 1182f7ca802SSteve Glendinning USB_VENDOR_REQUEST_WRITE_REGISTER, 1192f7ca802SSteve Glendinning USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1202f7ca802SSteve Glendinning 00, index, buf, 4, USB_CTRL_SET_TIMEOUT); 1212f7ca802SSteve Glendinning 1222f7ca802SSteve Glendinning if (unlikely(ret < 0)) 12360b86755SJoe Perches netdev_warn(dev->net, "Failed to write register index 0x%08x\n", index); 1242f7ca802SSteve Glendinning 1252f7ca802SSteve Glendinning kfree(buf); 1262f7ca802SSteve Glendinning 1272f7ca802SSteve Glendinning return ret; 1282f7ca802SSteve Glendinning } 1292f7ca802SSteve Glendinning 130*e0e474a8SSteve Glendinning static int smsc95xx_set_feature(struct usbnet *dev, u32 feature) 131*e0e474a8SSteve Glendinning { 132*e0e474a8SSteve Glendinning if (WARN_ON_ONCE(!dev)) 133*e0e474a8SSteve Glendinning return -EINVAL; 134*e0e474a8SSteve Glendinning 135*e0e474a8SSteve Glendinning cpu_to_le32s(&feature); 136*e0e474a8SSteve Glendinning 137*e0e474a8SSteve Glendinning return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), 138*e0e474a8SSteve Glendinning USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, feature, 0, NULL, 0, 139*e0e474a8SSteve Glendinning USB_CTRL_SET_TIMEOUT); 140*e0e474a8SSteve Glendinning } 141*e0e474a8SSteve Glendinning 142*e0e474a8SSteve Glendinning static int smsc95xx_clear_feature(struct usbnet *dev, u32 feature) 143*e0e474a8SSteve Glendinning { 144*e0e474a8SSteve Glendinning if (WARN_ON_ONCE(!dev)) 145*e0e474a8SSteve Glendinning return -EINVAL; 146*e0e474a8SSteve Glendinning 147*e0e474a8SSteve Glendinning cpu_to_le32s(&feature); 148*e0e474a8SSteve Glendinning 149*e0e474a8SSteve Glendinning return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), 150*e0e474a8SSteve Glendinning USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, feature, 0, NULL, 0, 151*e0e474a8SSteve Glendinning USB_CTRL_SET_TIMEOUT); 152*e0e474a8SSteve Glendinning } 153*e0e474a8SSteve Glendinning 1542f7ca802SSteve Glendinning /* Loop until the read is completed with timeout 1552f7ca802SSteve Glendinning * called with phy_mutex held */ 156769ea6d8SSteve Glendinning static int __must_check smsc95xx_phy_wait_not_busy(struct usbnet *dev) 1572f7ca802SSteve Glendinning { 1582f7ca802SSteve Glendinning unsigned long start_time = jiffies; 1592f7ca802SSteve Glendinning u32 val; 160769ea6d8SSteve Glendinning int ret; 1612f7ca802SSteve Glendinning 1622f7ca802SSteve Glendinning do { 163769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, MII_ADDR, &val); 164769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading MII_ACCESS"); 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 1722f7ca802SSteve Glendinning static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) 1732f7ca802SSteve Glendinning { 1742f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 1752f7ca802SSteve Glendinning u32 val, addr; 176769ea6d8SSteve Glendinning int ret; 1772f7ca802SSteve Glendinning 1782f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 1792f7ca802SSteve Glendinning 1802f7ca802SSteve Glendinning /* confirm MII not busy */ 181769ea6d8SSteve Glendinning ret = smsc95xx_phy_wait_not_busy(dev); 182769ea6d8SSteve Glendinning check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_read"); 1832f7ca802SSteve Glendinning 1842f7ca802SSteve Glendinning /* set the address, index & direction (read from PHY) */ 1852f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 1862f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 1872f7ca802SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_READ_; 188769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MII_ADDR, addr); 189769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error writing MII_ADDR"); 1902f7ca802SSteve Glendinning 191769ea6d8SSteve Glendinning ret = smsc95xx_phy_wait_not_busy(dev); 192769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Timed out reading MII reg %02X", idx); 193769ea6d8SSteve Glendinning 194769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, MII_DATA, &val); 195769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error reading MII_DATA"); 196769ea6d8SSteve Glendinning 197769ea6d8SSteve Glendinning ret = (u16)(val & 0xFFFF); 198769ea6d8SSteve Glendinning 199769ea6d8SSteve Glendinning done: 2002f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 201769ea6d8SSteve Glendinning return ret; 2022f7ca802SSteve Glendinning } 2032f7ca802SSteve Glendinning 2042f7ca802SSteve Glendinning static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, 2052f7ca802SSteve Glendinning int regval) 2062f7ca802SSteve Glendinning { 2072f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 2082f7ca802SSteve Glendinning u32 val, addr; 209769ea6d8SSteve Glendinning int ret; 2102f7ca802SSteve Glendinning 2112f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 2122f7ca802SSteve Glendinning 2132f7ca802SSteve Glendinning /* confirm MII not busy */ 214769ea6d8SSteve Glendinning ret = smsc95xx_phy_wait_not_busy(dev); 215769ea6d8SSteve Glendinning check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_write"); 2162f7ca802SSteve Glendinning 2172f7ca802SSteve Glendinning val = regval; 218769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MII_DATA, val); 219769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error writing MII_DATA"); 2202f7ca802SSteve Glendinning 2212f7ca802SSteve Glendinning /* set the address, index & direction (write to PHY) */ 2222f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 2232f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 2242f7ca802SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_WRITE_; 225769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MII_ADDR, addr); 226769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Error writing MII_ADDR"); 2272f7ca802SSteve Glendinning 228769ea6d8SSteve Glendinning ret = smsc95xx_phy_wait_not_busy(dev); 229769ea6d8SSteve Glendinning check_warn_goto_done(ret, "Timed out writing MII reg %02X", idx); 2302f7ca802SSteve Glendinning 231769ea6d8SSteve Glendinning done: 2322f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 2332f7ca802SSteve Glendinning } 2342f7ca802SSteve Glendinning 235769ea6d8SSteve Glendinning static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev) 2362f7ca802SSteve Glendinning { 2372f7ca802SSteve Glendinning unsigned long start_time = jiffies; 2382f7ca802SSteve Glendinning u32 val; 239769ea6d8SSteve Glendinning int ret; 2402f7ca802SSteve Glendinning 2412f7ca802SSteve Glendinning do { 242769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 243769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading E2P_CMD"); 2442f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) 2452f7ca802SSteve Glendinning break; 2462f7ca802SSteve Glendinning udelay(40); 2472f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 2482f7ca802SSteve Glendinning 2492f7ca802SSteve Glendinning if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { 25060b86755SJoe Perches netdev_warn(dev->net, "EEPROM read operation timeout\n"); 2512f7ca802SSteve Glendinning return -EIO; 2522f7ca802SSteve Glendinning } 2532f7ca802SSteve Glendinning 2542f7ca802SSteve Glendinning return 0; 2552f7ca802SSteve Glendinning } 2562f7ca802SSteve Glendinning 257769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) 2582f7ca802SSteve Glendinning { 2592f7ca802SSteve Glendinning unsigned long start_time = jiffies; 2602f7ca802SSteve Glendinning u32 val; 261769ea6d8SSteve Glendinning int ret; 2622f7ca802SSteve Glendinning 2632f7ca802SSteve Glendinning do { 264769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 265769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading E2P_CMD"); 2662f7ca802SSteve Glendinning 2672f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_)) 2682f7ca802SSteve Glendinning return 0; 2692f7ca802SSteve Glendinning 2702f7ca802SSteve Glendinning udelay(40); 2712f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 2722f7ca802SSteve Glendinning 27360b86755SJoe Perches netdev_warn(dev->net, "EEPROM is busy\n"); 2742f7ca802SSteve Glendinning return -EIO; 2752f7ca802SSteve Glendinning } 2762f7ca802SSteve Glendinning 2772f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, 2782f7ca802SSteve Glendinning u8 *data) 2792f7ca802SSteve Glendinning { 2802f7ca802SSteve Glendinning u32 val; 2812f7ca802SSteve Glendinning int i, ret; 2822f7ca802SSteve Glendinning 2832f7ca802SSteve Glendinning BUG_ON(!dev); 2842f7ca802SSteve Glendinning BUG_ON(!data); 2852f7ca802SSteve Glendinning 2862f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 2872f7ca802SSteve Glendinning if (ret) 2882f7ca802SSteve Glendinning return ret; 2892f7ca802SSteve Glendinning 2902f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 2912f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); 292769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 293769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_CMD"); 2942f7ca802SSteve Glendinning 2952f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 2962f7ca802SSteve Glendinning if (ret < 0) 2972f7ca802SSteve Glendinning return ret; 2982f7ca802SSteve Glendinning 299769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_DATA, &val); 300769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading E2P_DATA"); 3012f7ca802SSteve Glendinning 3022f7ca802SSteve Glendinning data[i] = val & 0xFF; 3032f7ca802SSteve Glendinning offset++; 3042f7ca802SSteve Glendinning } 3052f7ca802SSteve Glendinning 3062f7ca802SSteve Glendinning return 0; 3072f7ca802SSteve Glendinning } 3082f7ca802SSteve Glendinning 3092f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, 3102f7ca802SSteve Glendinning u8 *data) 3112f7ca802SSteve Glendinning { 3122f7ca802SSteve Glendinning u32 val; 3132f7ca802SSteve Glendinning int i, ret; 3142f7ca802SSteve Glendinning 3152f7ca802SSteve Glendinning BUG_ON(!dev); 3162f7ca802SSteve Glendinning BUG_ON(!data); 3172f7ca802SSteve Glendinning 3182f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3192f7ca802SSteve Glendinning if (ret) 3202f7ca802SSteve Glendinning return ret; 3212f7ca802SSteve Glendinning 3222f7ca802SSteve Glendinning /* Issue write/erase enable command */ 3232f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; 324769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 325769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_DATA"); 3262f7ca802SSteve Glendinning 3272f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3282f7ca802SSteve Glendinning if (ret < 0) 3292f7ca802SSteve Glendinning return ret; 3302f7ca802SSteve Glendinning 3312f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3322f7ca802SSteve Glendinning 3332f7ca802SSteve Glendinning /* Fill data register */ 3342f7ca802SSteve Glendinning val = data[i]; 335769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_DATA, val); 336769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_DATA"); 3372f7ca802SSteve Glendinning 3382f7ca802SSteve Glendinning /* Send "write" command */ 3392f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); 340769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 341769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing E2P_CMD"); 3422f7ca802SSteve Glendinning 3432f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3442f7ca802SSteve Glendinning if (ret < 0) 3452f7ca802SSteve Glendinning return ret; 3462f7ca802SSteve Glendinning 3472f7ca802SSteve Glendinning offset++; 3482f7ca802SSteve Glendinning } 3492f7ca802SSteve Glendinning 3502f7ca802SSteve Glendinning return 0; 3512f7ca802SSteve Glendinning } 3522f7ca802SSteve Glendinning 353150a7fccSSteve Glendinning static void smsc95xx_async_cmd_callback(struct urb *urb) 3542f7ca802SSteve Glendinning { 3552f7ca802SSteve Glendinning struct usb_context *usb_context = urb->context; 3562f7ca802SSteve Glendinning struct usbnet *dev = usb_context->dev; 357c94cb314SOliver Neukum int status = urb->status; 3582f7ca802SSteve Glendinning 359769ea6d8SSteve Glendinning check_warn(status, "async callback failed with %d\n", status); 3602f7ca802SSteve Glendinning 3612f7ca802SSteve Glendinning kfree(usb_context); 3622f7ca802SSteve Glendinning usb_free_urb(urb); 3632f7ca802SSteve Glendinning } 3642f7ca802SSteve Glendinning 365769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, 366769ea6d8SSteve Glendinning u32 *data) 3672f7ca802SSteve Glendinning { 3682f7ca802SSteve Glendinning struct usb_context *usb_context; 3692f7ca802SSteve Glendinning int status; 3702f7ca802SSteve Glendinning struct urb *urb; 3711d74a6bdSSteve Glendinning const u16 size = 4; 3722f7ca802SSteve Glendinning 3732f7ca802SSteve Glendinning urb = usb_alloc_urb(0, GFP_ATOMIC); 3742f7ca802SSteve Glendinning if (!urb) { 37560b86755SJoe Perches netdev_warn(dev->net, "Error allocating URB\n"); 3762f7ca802SSteve Glendinning return -ENOMEM; 3772f7ca802SSteve Glendinning } 3782f7ca802SSteve Glendinning 3792f7ca802SSteve Glendinning usb_context = kmalloc(sizeof(struct usb_context), GFP_ATOMIC); 3802f7ca802SSteve Glendinning if (usb_context == NULL) { 38160b86755SJoe Perches netdev_warn(dev->net, "Error allocating control msg\n"); 3822f7ca802SSteve Glendinning usb_free_urb(urb); 3832f7ca802SSteve Glendinning return -ENOMEM; 3842f7ca802SSteve Glendinning } 3852f7ca802SSteve Glendinning 3862f7ca802SSteve Glendinning usb_context->req.bRequestType = 3872f7ca802SSteve Glendinning USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; 3882f7ca802SSteve Glendinning usb_context->req.bRequest = USB_VENDOR_REQUEST_WRITE_REGISTER; 3892f7ca802SSteve Glendinning usb_context->req.wValue = 00; 3901d74a6bdSSteve Glendinning usb_context->req.wIndex = cpu_to_le16(index); 3911d74a6bdSSteve Glendinning usb_context->req.wLength = cpu_to_le16(size); 3922f7ca802SSteve Glendinning 3932f7ca802SSteve Glendinning usb_fill_control_urb(urb, dev->udev, usb_sndctrlpipe(dev->udev, 0), 3942f7ca802SSteve Glendinning (void *)&usb_context->req, data, size, 395150a7fccSSteve Glendinning smsc95xx_async_cmd_callback, 3962f7ca802SSteve Glendinning (void *)usb_context); 3972f7ca802SSteve Glendinning 3982f7ca802SSteve Glendinning status = usb_submit_urb(urb, GFP_ATOMIC); 3992f7ca802SSteve Glendinning if (status < 0) { 40060b86755SJoe Perches netdev_warn(dev->net, "Error submitting control msg, sts=%d\n", 40160b86755SJoe Perches status); 4022f7ca802SSteve Glendinning kfree(usb_context); 4032f7ca802SSteve Glendinning usb_free_urb(urb); 4042f7ca802SSteve Glendinning } 4052f7ca802SSteve Glendinning 4062f7ca802SSteve Glendinning return status; 4072f7ca802SSteve Glendinning } 4082f7ca802SSteve Glendinning 4092f7ca802SSteve Glendinning /* returns hash bit number for given MAC address 4102f7ca802SSteve Glendinning * example: 4112f7ca802SSteve Glendinning * 01 00 5E 00 00 01 -> returns bit number 31 */ 4122f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) 4132f7ca802SSteve Glendinning { 4142f7ca802SSteve Glendinning return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; 4152f7ca802SSteve Glendinning } 4162f7ca802SSteve Glendinning 4172f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev) 4182f7ca802SSteve Glendinning { 4192f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 4202f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 4212f7ca802SSteve Glendinning unsigned long flags; 422769ea6d8SSteve Glendinning int ret; 4232f7ca802SSteve Glendinning 4243c0f3c60SMarc Zyngier pdata->hash_hi = 0; 4253c0f3c60SMarc Zyngier pdata->hash_lo = 0; 4263c0f3c60SMarc Zyngier 4272f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 4282f7ca802SSteve Glendinning 4292f7ca802SSteve Glendinning if (dev->net->flags & IFF_PROMISC) { 430a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); 4312f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_PRMS_; 4322f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4332f7ca802SSteve Glendinning } else if (dev->net->flags & IFF_ALLMULTI) { 434a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); 4352f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_MCPAS_; 4362f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); 4374cd24eafSJiri Pirko } else if (!netdev_mc_empty(dev->net)) { 43822bedad3SJiri Pirko struct netdev_hw_addr *ha; 4392f7ca802SSteve Glendinning 4402f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_HPFILT_; 4412f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); 4422f7ca802SSteve Glendinning 44322bedad3SJiri Pirko netdev_for_each_mc_addr(ha, netdev) { 44422bedad3SJiri Pirko u32 bitnum = smsc95xx_hash(ha->addr); 4452f7ca802SSteve Glendinning u32 mask = 0x01 << (bitnum & 0x1F); 4462f7ca802SSteve Glendinning if (bitnum & 0x20) 4473c0f3c60SMarc Zyngier pdata->hash_hi |= mask; 4482f7ca802SSteve Glendinning else 4493c0f3c60SMarc Zyngier pdata->hash_lo |= mask; 4502f7ca802SSteve Glendinning } 4512f7ca802SSteve Glendinning 452a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", 4533c0f3c60SMarc Zyngier pdata->hash_hi, pdata->hash_lo); 4542f7ca802SSteve Glendinning } else { 455a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive own packets only\n"); 4562f7ca802SSteve Glendinning pdata->mac_cr &= 4572f7ca802SSteve Glendinning ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4582f7ca802SSteve Glendinning } 4592f7ca802SSteve Glendinning 4602f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 4612f7ca802SSteve Glendinning 4622f7ca802SSteve Glendinning /* Initiate async writes, as we can't wait for completion here */ 463769ea6d8SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi); 464769ea6d8SSteve Glendinning check_warn(ret, "failed to initiate async write to HASHH"); 465769ea6d8SSteve Glendinning 466769ea6d8SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo); 467769ea6d8SSteve Glendinning check_warn(ret, "failed to initiate async write to HASHL"); 468769ea6d8SSteve Glendinning 469769ea6d8SSteve Glendinning ret = smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr); 470769ea6d8SSteve Glendinning check_warn(ret, "failed to initiate async write to MAC_CR"); 4712f7ca802SSteve Glendinning } 4722f7ca802SSteve Glendinning 473769ea6d8SSteve Glendinning static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, 4742f7ca802SSteve Glendinning u16 lcladv, u16 rmtadv) 4752f7ca802SSteve Glendinning { 4762f7ca802SSteve Glendinning u32 flow, afc_cfg = 0; 4772f7ca802SSteve Glendinning 4782f7ca802SSteve Glendinning int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); 479769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading AFC_CFG"); 4802f7ca802SSteve Glendinning 4812f7ca802SSteve Glendinning if (duplex == DUPLEX_FULL) { 482bc02ff95SSteve Glendinning u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); 4832f7ca802SSteve Glendinning 4842f7ca802SSteve Glendinning if (cap & FLOW_CTRL_RX) 4852f7ca802SSteve Glendinning flow = 0xFFFF0002; 4862f7ca802SSteve Glendinning else 4872f7ca802SSteve Glendinning flow = 0; 4882f7ca802SSteve Glendinning 4892f7ca802SSteve Glendinning if (cap & FLOW_CTRL_TX) 4902f7ca802SSteve Glendinning afc_cfg |= 0xF; 4912f7ca802SSteve Glendinning else 4922f7ca802SSteve Glendinning afc_cfg &= ~0xF; 4932f7ca802SSteve Glendinning 494a475f603SJoe Perches netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", 49560b86755SJoe Perches cap & FLOW_CTRL_RX ? "enabled" : "disabled", 49660b86755SJoe Perches cap & FLOW_CTRL_TX ? "enabled" : "disabled"); 4972f7ca802SSteve Glendinning } else { 498a475f603SJoe Perches netif_dbg(dev, link, dev->net, "half duplex\n"); 4992f7ca802SSteve Glendinning flow = 0; 5002f7ca802SSteve Glendinning afc_cfg |= 0xF; 5012f7ca802SSteve Glendinning } 5022f7ca802SSteve Glendinning 503769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, flow); 504769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing FLOW"); 505769ea6d8SSteve Glendinning 506769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); 507769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing AFC_CFG"); 508769ea6d8SSteve Glendinning 509769ea6d8SSteve Glendinning return 0; 5102f7ca802SSteve Glendinning } 5112f7ca802SSteve Glendinning 5122f7ca802SSteve Glendinning static int smsc95xx_link_reset(struct usbnet *dev) 5132f7ca802SSteve Glendinning { 5142f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 5152f7ca802SSteve Glendinning struct mii_if_info *mii = &dev->mii; 5168ae6dacaSDavid Decotigny struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 5172f7ca802SSteve Glendinning unsigned long flags; 5182f7ca802SSteve Glendinning u16 lcladv, rmtadv; 519769ea6d8SSteve Glendinning int ret; 5202f7ca802SSteve Glendinning 5212f7ca802SSteve Glendinning /* clear interrupt status */ 522769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); 523769ea6d8SSteve Glendinning check_warn_return(ret, "Error reading PHY_INT_SRC"); 524769ea6d8SSteve Glendinning 525769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 526769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing INT_STS"); 5272f7ca802SSteve Glendinning 5282f7ca802SSteve Glendinning mii_check_media(mii, 1, 1); 5292f7ca802SSteve Glendinning mii_ethtool_gset(&dev->mii, &ecmd); 5302f7ca802SSteve Glendinning lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); 5312f7ca802SSteve Glendinning rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA); 5322f7ca802SSteve Glendinning 5338ae6dacaSDavid Decotigny netif_dbg(dev, link, dev->net, 5348ae6dacaSDavid Decotigny "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", 5358ae6dacaSDavid Decotigny ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); 5362f7ca802SSteve Glendinning 5372f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 5382f7ca802SSteve Glendinning if (ecmd.duplex != DUPLEX_FULL) { 5392f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_FDPX_; 5402f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RCVOWN_; 5412f7ca802SSteve Glendinning } else { 5422f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_RCVOWN_; 5432f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_FDPX_; 5442f7ca802SSteve Glendinning } 5452f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5462f7ca802SSteve Glendinning 547769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 548769ea6d8SSteve Glendinning check_warn_return(ret, "Error writing MAC_CR"); 5492f7ca802SSteve Glendinning 550769ea6d8SSteve Glendinning ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); 551769ea6d8SSteve Glendinning check_warn_return(ret, "Error updating PHY flow control"); 5522f7ca802SSteve Glendinning 5532f7ca802SSteve Glendinning return 0; 5542f7ca802SSteve Glendinning } 5552f7ca802SSteve Glendinning 5562f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb) 5572f7ca802SSteve Glendinning { 5582f7ca802SSteve Glendinning u32 intdata; 5592f7ca802SSteve Glendinning 5602f7ca802SSteve Glendinning if (urb->actual_length != 4) { 56160b86755SJoe Perches netdev_warn(dev->net, "unexpected urb length %d\n", 56260b86755SJoe Perches urb->actual_length); 5632f7ca802SSteve Glendinning return; 5642f7ca802SSteve Glendinning } 5652f7ca802SSteve Glendinning 5662f7ca802SSteve Glendinning memcpy(&intdata, urb->transfer_buffer, 4); 5671d74a6bdSSteve Glendinning le32_to_cpus(&intdata); 5682f7ca802SSteve Glendinning 569a475f603SJoe Perches netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); 5702f7ca802SSteve Glendinning 5712f7ca802SSteve Glendinning if (intdata & INT_ENP_PHY_INT_) 5722f7ca802SSteve Glendinning usbnet_defer_kevent(dev, EVENT_LINK_RESET); 5732f7ca802SSteve Glendinning else 57460b86755SJoe Perches netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", 57560b86755SJoe Perches intdata); 5762f7ca802SSteve Glendinning } 5772f7ca802SSteve Glendinning 578f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */ 579c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev, 580c8f44affSMichał Mirosław netdev_features_t features) 5812f7ca802SSteve Glendinning { 58278e47fe4SMichał Mirosław struct usbnet *dev = netdev_priv(netdev); 5832f7ca802SSteve Glendinning u32 read_buf; 58478e47fe4SMichał Mirosław int ret; 58578e47fe4SMichał Mirosław 58678e47fe4SMichał Mirosław ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); 587769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read COE_CR: %d\n", ret); 5882f7ca802SSteve Glendinning 58978e47fe4SMichał Mirosław if (features & NETIF_F_HW_CSUM) 590f7b29271SSteve Glendinning read_buf |= Tx_COE_EN_; 591f7b29271SSteve Glendinning else 592f7b29271SSteve Glendinning read_buf &= ~Tx_COE_EN_; 593f7b29271SSteve Glendinning 59478e47fe4SMichał Mirosław if (features & NETIF_F_RXCSUM) 5952f7ca802SSteve Glendinning read_buf |= Rx_COE_EN_; 5962f7ca802SSteve Glendinning else 5972f7ca802SSteve Glendinning read_buf &= ~Rx_COE_EN_; 5982f7ca802SSteve Glendinning 5992f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, COE_CR, read_buf); 600769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write COE_CR: %d\n", ret); 6012f7ca802SSteve Glendinning 602a475f603SJoe Perches netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); 6032f7ca802SSteve Glendinning return 0; 6042f7ca802SSteve Glendinning } 6052f7ca802SSteve Glendinning 6062f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) 6072f7ca802SSteve Glendinning { 6082f7ca802SSteve Glendinning return MAX_EEPROM_SIZE; 6092f7ca802SSteve Glendinning } 6102f7ca802SSteve Glendinning 6112f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, 6122f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6132f7ca802SSteve Glendinning { 6142f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6152f7ca802SSteve Glendinning 6162f7ca802SSteve Glendinning ee->magic = LAN95XX_EEPROM_MAGIC; 6172f7ca802SSteve Glendinning 6182f7ca802SSteve Glendinning return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); 6192f7ca802SSteve Glendinning } 6202f7ca802SSteve Glendinning 6212f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, 6222f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 6232f7ca802SSteve Glendinning { 6242f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 6252f7ca802SSteve Glendinning 6262f7ca802SSteve Glendinning if (ee->magic != LAN95XX_EEPROM_MAGIC) { 62760b86755SJoe Perches netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", 6282f7ca802SSteve Glendinning ee->magic); 6292f7ca802SSteve Glendinning return -EINVAL; 6302f7ca802SSteve Glendinning } 6312f7ca802SSteve Glendinning 6322f7ca802SSteve Glendinning return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); 6332f7ca802SSteve Glendinning } 6342f7ca802SSteve Glendinning 6359fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev) 6369fa32e94SEmeric Vigier { 6379fa32e94SEmeric Vigier /* all smsc95xx registers */ 6389fa32e94SEmeric Vigier return COE_CR - ID_REV + 1; 6399fa32e94SEmeric Vigier } 6409fa32e94SEmeric Vigier 6419fa32e94SEmeric Vigier static void 6429fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, 6439fa32e94SEmeric Vigier void *buf) 6449fa32e94SEmeric Vigier { 6459fa32e94SEmeric Vigier struct usbnet *dev = netdev_priv(netdev); 646d348446bSDan Carpenter unsigned int i, j; 647d348446bSDan Carpenter int retval; 6489fa32e94SEmeric Vigier u32 *data = buf; 6499fa32e94SEmeric Vigier 6509fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); 6519fa32e94SEmeric Vigier if (retval < 0) { 6529fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read ID_REV\n"); 6539fa32e94SEmeric Vigier return; 6549fa32e94SEmeric Vigier } 6559fa32e94SEmeric Vigier 6569fa32e94SEmeric Vigier for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { 6579fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, i, &data[j]); 6589fa32e94SEmeric Vigier if (retval < 0) { 6599fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); 6609fa32e94SEmeric Vigier return; 6619fa32e94SEmeric Vigier } 6629fa32e94SEmeric Vigier } 6639fa32e94SEmeric Vigier } 6649fa32e94SEmeric Vigier 665*e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net, 666*e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 667*e0e474a8SSteve Glendinning { 668*e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 669*e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 670*e0e474a8SSteve Glendinning 671*e0e474a8SSteve Glendinning wolinfo->supported = SUPPORTED_WAKE; 672*e0e474a8SSteve Glendinning wolinfo->wolopts = pdata->wolopts; 673*e0e474a8SSteve Glendinning } 674*e0e474a8SSteve Glendinning 675*e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net, 676*e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 677*e0e474a8SSteve Glendinning { 678*e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 679*e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 680*e0e474a8SSteve Glendinning 681*e0e474a8SSteve Glendinning pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; 682*e0e474a8SSteve Glendinning return 0; 683*e0e474a8SSteve Glendinning } 684*e0e474a8SSteve Glendinning 6850fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = { 6862f7ca802SSteve Glendinning .get_link = usbnet_get_link, 6872f7ca802SSteve Glendinning .nway_reset = usbnet_nway_reset, 6882f7ca802SSteve Glendinning .get_drvinfo = usbnet_get_drvinfo, 6892f7ca802SSteve Glendinning .get_msglevel = usbnet_get_msglevel, 6902f7ca802SSteve Glendinning .set_msglevel = usbnet_set_msglevel, 6912f7ca802SSteve Glendinning .get_settings = usbnet_get_settings, 6922f7ca802SSteve Glendinning .set_settings = usbnet_set_settings, 6932f7ca802SSteve Glendinning .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, 6942f7ca802SSteve Glendinning .get_eeprom = smsc95xx_ethtool_get_eeprom, 6952f7ca802SSteve Glendinning .set_eeprom = smsc95xx_ethtool_set_eeprom, 6969fa32e94SEmeric Vigier .get_regs_len = smsc95xx_ethtool_getregslen, 6979fa32e94SEmeric Vigier .get_regs = smsc95xx_ethtool_getregs, 698*e0e474a8SSteve Glendinning .get_wol = smsc95xx_ethtool_get_wol, 699*e0e474a8SSteve Glendinning .set_wol = smsc95xx_ethtool_set_wol, 7002f7ca802SSteve Glendinning }; 7012f7ca802SSteve Glendinning 7022f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 7032f7ca802SSteve Glendinning { 7042f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7052f7ca802SSteve Glendinning 7062f7ca802SSteve Glendinning if (!netif_running(netdev)) 7072f7ca802SSteve Glendinning return -EINVAL; 7082f7ca802SSteve Glendinning 7092f7ca802SSteve Glendinning return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 7102f7ca802SSteve Glendinning } 7112f7ca802SSteve Glendinning 7122f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev) 7132f7ca802SSteve Glendinning { 7142f7ca802SSteve Glendinning /* try reading mac address from EEPROM */ 7152f7ca802SSteve Glendinning if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, 7162f7ca802SSteve Glendinning dev->net->dev_addr) == 0) { 7172f7ca802SSteve Glendinning if (is_valid_ether_addr(dev->net->dev_addr)) { 7182f7ca802SSteve Glendinning /* eeprom values are valid so use them */ 719a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); 7202f7ca802SSteve Glendinning return; 7212f7ca802SSteve Glendinning } 7222f7ca802SSteve Glendinning } 7232f7ca802SSteve Glendinning 7242f7ca802SSteve Glendinning /* no eeprom, or eeprom values are invalid. generate random MAC */ 725f2cedb63SDanny Kukawka eth_hw_addr_random(dev->net); 726c7e12eadSJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); 7272f7ca802SSteve Glendinning } 7282f7ca802SSteve Glendinning 7292f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev) 7302f7ca802SSteve Glendinning { 7312f7ca802SSteve Glendinning u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | 7322f7ca802SSteve Glendinning dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; 7332f7ca802SSteve Glendinning u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; 7342f7ca802SSteve Glendinning int ret; 7352f7ca802SSteve Glendinning 7362f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); 737769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write ADDRL: %d\n", ret); 7382f7ca802SSteve Glendinning 7392f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRH, addr_hi); 740769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write ADDRH: %d\n", ret); 7412f7ca802SSteve Glendinning 7422f7ca802SSteve Glendinning return 0; 7432f7ca802SSteve Glendinning } 7442f7ca802SSteve Glendinning 7452f7ca802SSteve Glendinning /* starts the TX path */ 746769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev) 7472f7ca802SSteve Glendinning { 7482f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7492f7ca802SSteve Glendinning unsigned long flags; 750769ea6d8SSteve Glendinning int ret; 7512f7ca802SSteve Glendinning 7522f7ca802SSteve Glendinning /* Enable Tx at MAC */ 7532f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 7542f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_TXEN_; 7552f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 7562f7ca802SSteve Glendinning 757769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 758769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret); 7592f7ca802SSteve Glendinning 7602f7ca802SSteve Glendinning /* Enable Tx at SCSRs */ 761769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); 762769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write TX_CFG: %d\n", ret); 763769ea6d8SSteve Glendinning 764769ea6d8SSteve Glendinning return 0; 7652f7ca802SSteve Glendinning } 7662f7ca802SSteve Glendinning 7672f7ca802SSteve Glendinning /* Starts the Receive path */ 768769ea6d8SSteve Glendinning static int smsc95xx_start_rx_path(struct usbnet *dev) 7692f7ca802SSteve Glendinning { 7702f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7712f7ca802SSteve Glendinning unsigned long flags; 772769ea6d8SSteve Glendinning int ret; 7732f7ca802SSteve Glendinning 7742f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 7752f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RXEN_; 7762f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 7772f7ca802SSteve Glendinning 778769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 779769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret); 780769ea6d8SSteve Glendinning 781769ea6d8SSteve Glendinning return 0; 7822f7ca802SSteve Glendinning } 7832f7ca802SSteve Glendinning 7842f7ca802SSteve Glendinning static int smsc95xx_phy_initialize(struct usbnet *dev) 7852f7ca802SSteve Glendinning { 786769ea6d8SSteve Glendinning int bmcr, ret, timeout = 0; 787db443c44SSteve Glendinning 7882f7ca802SSteve Glendinning /* Initialize MII structure */ 7892f7ca802SSteve Glendinning dev->mii.dev = dev->net; 7902f7ca802SSteve Glendinning dev->mii.mdio_read = smsc95xx_mdio_read; 7912f7ca802SSteve Glendinning dev->mii.mdio_write = smsc95xx_mdio_write; 7922f7ca802SSteve Glendinning dev->mii.phy_id_mask = 0x1f; 7932f7ca802SSteve Glendinning dev->mii.reg_num_mask = 0x1f; 7942f7ca802SSteve Glendinning dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID; 7952f7ca802SSteve Glendinning 796db443c44SSteve Glendinning /* reset phy and wait for reset to complete */ 7972f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 798db443c44SSteve Glendinning 799db443c44SSteve Glendinning do { 800db443c44SSteve Glendinning msleep(10); 801db443c44SSteve Glendinning bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); 802db443c44SSteve Glendinning timeout++; 803d9460920SRabin Vincent } while ((bmcr & BMCR_RESET) && (timeout < 100)); 804db443c44SSteve Glendinning 805db443c44SSteve Glendinning if (timeout >= 100) { 806db443c44SSteve Glendinning netdev_warn(dev->net, "timeout on PHY Reset"); 807db443c44SSteve Glendinning return -EIO; 808db443c44SSteve Glendinning } 809db443c44SSteve Glendinning 8102f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, 8112f7ca802SSteve Glendinning ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | 8122f7ca802SSteve Glendinning ADVERTISE_PAUSE_ASYM); 8132f7ca802SSteve Glendinning 8142f7ca802SSteve Glendinning /* read to clear */ 815769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); 816769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read PHY_INT_SRC during init"); 8172f7ca802SSteve Glendinning 8182f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, 8192f7ca802SSteve Glendinning PHY_INT_MASK_DEFAULT_); 8202f7ca802SSteve Glendinning mii_nway_restart(&dev->mii); 8212f7ca802SSteve Glendinning 822a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); 8232f7ca802SSteve Glendinning return 0; 8242f7ca802SSteve Glendinning } 8252f7ca802SSteve Glendinning 8262f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev) 8272f7ca802SSteve Glendinning { 8282f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 8292f7ca802SSteve Glendinning u32 read_buf, write_buf, burst_cap; 8302f7ca802SSteve Glendinning int ret = 0, timeout; 8312f7ca802SSteve Glendinning 832a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); 8332f7ca802SSteve Glendinning 8344436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); 835769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write HW_CFG_LRST_ bit in HW_CFG\n"); 8362f7ca802SSteve Glendinning 8372f7ca802SSteve Glendinning timeout = 0; 8382f7ca802SSteve Glendinning do { 839cf2acec2SSteve Glendinning msleep(10); 8402f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 841769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 8422f7ca802SSteve Glendinning timeout++; 8432f7ca802SSteve Glendinning } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); 8442f7ca802SSteve Glendinning 8452f7ca802SSteve Glendinning if (timeout >= 100) { 84660b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); 8472f7ca802SSteve Glendinning return ret; 8482f7ca802SSteve Glendinning } 8492f7ca802SSteve Glendinning 8504436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); 851769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write PM_CTRL: %d\n", ret); 8522f7ca802SSteve Glendinning 8532f7ca802SSteve Glendinning timeout = 0; 8542f7ca802SSteve Glendinning do { 855cf2acec2SSteve Glendinning msleep(10); 8562f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); 857769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read PM_CTRL: %d\n", ret); 8582f7ca802SSteve Glendinning timeout++; 8592f7ca802SSteve Glendinning } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); 8602f7ca802SSteve Glendinning 8612f7ca802SSteve Glendinning if (timeout >= 100) { 86260b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); 8632f7ca802SSteve Glendinning return ret; 8642f7ca802SSteve Glendinning } 8652f7ca802SSteve Glendinning 8662f7ca802SSteve Glendinning ret = smsc95xx_set_mac_address(dev); 8672f7ca802SSteve Glendinning if (ret < 0) 8682f7ca802SSteve Glendinning return ret; 8692f7ca802SSteve Glendinning 870a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 871a475f603SJoe Perches "MAC Address: %pM\n", dev->net->dev_addr); 8722f7ca802SSteve Glendinning 8732f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 874769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 8752f7ca802SSteve Glendinning 876a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 877a475f603SJoe Perches "Read Value from HW_CFG : 0x%08x\n", read_buf); 8782f7ca802SSteve Glendinning 8792f7ca802SSteve Glendinning read_buf |= HW_CFG_BIR_; 8802f7ca802SSteve Glendinning 8812f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 882769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write HW_CFG_BIR_ bit in HW_CFG\n"); 8832f7ca802SSteve Glendinning 8842f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 885769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 886a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 887a475f603SJoe Perches "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", 88860b86755SJoe Perches read_buf); 8892f7ca802SSteve Glendinning 8902f7ca802SSteve Glendinning if (!turbo_mode) { 8912f7ca802SSteve Glendinning burst_cap = 0; 8922f7ca802SSteve Glendinning dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; 8932f7ca802SSteve Glendinning } else if (dev->udev->speed == USB_SPEED_HIGH) { 8942f7ca802SSteve Glendinning burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; 8952f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; 8962f7ca802SSteve Glendinning } else { 8972f7ca802SSteve Glendinning burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; 8982f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; 8992f7ca802SSteve Glendinning } 9002f7ca802SSteve Glendinning 901a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 902a475f603SJoe Perches "rx_urb_size=%ld\n", (ulong)dev->rx_urb_size); 9032f7ca802SSteve Glendinning 9042f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); 905769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret); 9062f7ca802SSteve Glendinning 9072f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); 908769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret); 909769ea6d8SSteve Glendinning 910a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 911a475f603SJoe Perches "Read Value from BURST_CAP after writing: 0x%08x\n", 9122f7ca802SSteve Glendinning read_buf); 9132f7ca802SSteve Glendinning 9144436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); 915769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret); 9162f7ca802SSteve Glendinning 9172f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); 918769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret); 919769ea6d8SSteve Glendinning 920a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 921a475f603SJoe Perches "Read Value from BULK_IN_DLY after writing: 0x%08x\n", 92260b86755SJoe Perches read_buf); 9232f7ca802SSteve Glendinning 9242f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 925769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 926769ea6d8SSteve Glendinning 927a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 928a475f603SJoe Perches "Read Value from HW_CFG: 0x%08x\n", read_buf); 9292f7ca802SSteve Glendinning 9302f7ca802SSteve Glendinning if (turbo_mode) 9312f7ca802SSteve Glendinning read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); 9322f7ca802SSteve Glendinning 9332f7ca802SSteve Glendinning read_buf &= ~HW_CFG_RXDOFF_; 9342f7ca802SSteve Glendinning 9352f7ca802SSteve Glendinning /* set Rx data offset=2, Make IP header aligns on word boundary. */ 9362f7ca802SSteve Glendinning read_buf |= NET_IP_ALIGN << 9; 9372f7ca802SSteve Glendinning 9382f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 939769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret); 9402f7ca802SSteve Glendinning 9412f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 942769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret); 943769ea6d8SSteve Glendinning 944a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 945a475f603SJoe Perches "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); 9462f7ca802SSteve Glendinning 9474436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 948769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write INT_STS: %d\n", ret); 9492f7ca802SSteve Glendinning 9502f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); 951769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read ID_REV: %d\n", ret); 952a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); 9532f7ca802SSteve Glendinning 954f293501cSSteve Glendinning /* Configure GPIO pins as LED outputs */ 955f293501cSSteve Glendinning write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | 956f293501cSSteve Glendinning LED_GPIO_CFG_FDX_LED; 957f293501cSSteve Glendinning ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); 958769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n", ret); 959f293501cSSteve Glendinning 9602f7ca802SSteve Glendinning /* Init Tx */ 9614436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, 0); 962769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write FLOW: %d\n", ret); 9632f7ca802SSteve Glendinning 9644436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); 965769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write AFC_CFG: %d\n", ret); 9662f7ca802SSteve Glendinning 9672f7ca802SSteve Glendinning /* Don't need mac_cr_lock during initialisation */ 9682f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); 969769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret); 9702f7ca802SSteve Glendinning 9712f7ca802SSteve Glendinning /* Init Rx */ 9722f7ca802SSteve Glendinning /* Set Vlan */ 9734436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); 974769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write VLAN1: %d\n", ret); 9752f7ca802SSteve Glendinning 976f7b29271SSteve Glendinning /* Enable or disable checksum offload engines */ 977769ea6d8SSteve Glendinning ret = smsc95xx_set_features(dev->net, dev->net->features); 978769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to set checksum offload features"); 9792f7ca802SSteve Glendinning 9802f7ca802SSteve Glendinning smsc95xx_set_multicast(dev->net); 9812f7ca802SSteve Glendinning 982769ea6d8SSteve Glendinning ret = smsc95xx_phy_initialize(dev); 983769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to init PHY"); 9842f7ca802SSteve Glendinning 9852f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); 986769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret); 9872f7ca802SSteve Glendinning 9882f7ca802SSteve Glendinning /* enable PHY interrupts */ 9892f7ca802SSteve Glendinning read_buf |= INT_EP_CTL_PHY_INT_; 9902f7ca802SSteve Glendinning 9912f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); 992769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret); 9932f7ca802SSteve Glendinning 994769ea6d8SSteve Glendinning ret = smsc95xx_start_tx_path(dev); 995769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to start TX path"); 996769ea6d8SSteve Glendinning 997769ea6d8SSteve Glendinning ret = smsc95xx_start_rx_path(dev); 998769ea6d8SSteve Glendinning check_warn_return(ret, "Failed to start RX path"); 9992f7ca802SSteve Glendinning 1000a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); 10012f7ca802SSteve Glendinning return 0; 10022f7ca802SSteve Glendinning } 10032f7ca802SSteve Glendinning 100463e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = { 100563e77b39SStephen Hemminger .ndo_open = usbnet_open, 100663e77b39SStephen Hemminger .ndo_stop = usbnet_stop, 100763e77b39SStephen Hemminger .ndo_start_xmit = usbnet_start_xmit, 100863e77b39SStephen Hemminger .ndo_tx_timeout = usbnet_tx_timeout, 100963e77b39SStephen Hemminger .ndo_change_mtu = usbnet_change_mtu, 101063e77b39SStephen Hemminger .ndo_set_mac_address = eth_mac_addr, 101163e77b39SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 101263e77b39SStephen Hemminger .ndo_do_ioctl = smsc95xx_ioctl, 1013afc4b13dSJiri Pirko .ndo_set_rx_mode = smsc95xx_set_multicast, 101478e47fe4SMichał Mirosław .ndo_set_features = smsc95xx_set_features, 101563e77b39SStephen Hemminger }; 101663e77b39SStephen Hemminger 10172f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) 10182f7ca802SSteve Glendinning { 10192f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = NULL; 10202f7ca802SSteve Glendinning int ret; 10212f7ca802SSteve Glendinning 10222f7ca802SSteve Glendinning printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); 10232f7ca802SSteve Glendinning 10242f7ca802SSteve Glendinning ret = usbnet_get_endpoints(dev, intf); 1025769ea6d8SSteve Glendinning check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret); 10262f7ca802SSteve Glendinning 10272f7ca802SSteve Glendinning dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), 10282f7ca802SSteve Glendinning GFP_KERNEL); 10292f7ca802SSteve Glendinning 10302f7ca802SSteve Glendinning pdata = (struct smsc95xx_priv *)(dev->data[0]); 10312f7ca802SSteve Glendinning if (!pdata) { 103260b86755SJoe Perches netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n"); 10332f7ca802SSteve Glendinning return -ENOMEM; 10342f7ca802SSteve Glendinning } 10352f7ca802SSteve Glendinning 10362f7ca802SSteve Glendinning spin_lock_init(&pdata->mac_cr_lock); 10372f7ca802SSteve Glendinning 103878e47fe4SMichał Mirosław if (DEFAULT_TX_CSUM_ENABLE) 103978e47fe4SMichał Mirosław dev->net->features |= NETIF_F_HW_CSUM; 104078e47fe4SMichał Mirosław if (DEFAULT_RX_CSUM_ENABLE) 104178e47fe4SMichał Mirosław dev->net->features |= NETIF_F_RXCSUM; 104278e47fe4SMichał Mirosław 104378e47fe4SMichał Mirosław dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM; 10442f7ca802SSteve Glendinning 1045f4e8ab7cSBernard Blackham smsc95xx_init_mac_address(dev); 1046f4e8ab7cSBernard Blackham 10472f7ca802SSteve Glendinning /* Init all registers */ 10482f7ca802SSteve Glendinning ret = smsc95xx_reset(dev); 10492f7ca802SSteve Glendinning 105063e77b39SStephen Hemminger dev->net->netdev_ops = &smsc95xx_netdev_ops; 10512f7ca802SSteve Glendinning dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 10522f7ca802SSteve Glendinning dev->net->flags |= IFF_MULTICAST; 105378e47fe4SMichał Mirosław dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 10549bbf5660SStephane Fillod dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; 10552f7ca802SSteve Glendinning return 0; 10562f7ca802SSteve Glendinning } 10572f7ca802SSteve Glendinning 10582f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) 10592f7ca802SSteve Glendinning { 10602f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 10612f7ca802SSteve Glendinning if (pdata) { 1062a475f603SJoe Perches netif_dbg(dev, ifdown, dev->net, "free pdata\n"); 10632f7ca802SSteve Glendinning kfree(pdata); 10642f7ca802SSteve Glendinning pdata = NULL; 10652f7ca802SSteve Glendinning dev->data[0] = 0; 10662f7ca802SSteve Glendinning } 10672f7ca802SSteve Glendinning } 10682f7ca802SSteve Glendinning 1069b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) 1070b5a04475SSteve Glendinning { 1071b5a04475SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1072*e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1073b5a04475SSteve Glendinning int ret; 1074b5a04475SSteve Glendinning u32 val; 1075b5a04475SSteve Glendinning 1076b5a04475SSteve Glendinning ret = usbnet_suspend(intf, message); 1077b5a04475SSteve Glendinning check_warn_return(ret, "usbnet_suspend error"); 1078b5a04475SSteve Glendinning 1079*e0e474a8SSteve Glendinning /* if no wol options set, enter lowest power SUSPEND2 mode */ 1080*e0e474a8SSteve Glendinning if (!(pdata->wolopts & SUPPORTED_WAKE)) { 1081b5a04475SSteve Glendinning netdev_info(dev->net, "entering SUSPEND2 mode"); 1082b5a04475SSteve Glendinning 1083*e0e474a8SSteve Glendinning /* disable energy detect (link up) & wake up events */ 1084*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, WUCSR, &val); 1085*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1086*e0e474a8SSteve Glendinning 1087*e0e474a8SSteve Glendinning val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); 1088*e0e474a8SSteve Glendinning 1089*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, WUCSR, val); 1090*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1091*e0e474a8SSteve Glendinning 1092*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1093*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1094*e0e474a8SSteve Glendinning 1095*e0e474a8SSteve Glendinning val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); 1096*e0e474a8SSteve Glendinning 1097*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1098*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1099*e0e474a8SSteve Glendinning 1100*e0e474a8SSteve Glendinning /* enter suspend2 mode */ 1101b5a04475SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1102b5a04475SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1103b5a04475SSteve Glendinning 1104b5a04475SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1105b5a04475SSteve Glendinning val |= PM_CTL_SUS_MODE_2; 1106b5a04475SSteve Glendinning 1107b5a04475SSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1108b5a04475SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1109b5a04475SSteve Glendinning 1110b5a04475SSteve Glendinning return 0; 1111b5a04475SSteve Glendinning } 1112b5a04475SSteve Glendinning 1113*e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1114*e0e474a8SSteve Glendinning /* clear any pending magic packet status */ 1115*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, WUCSR, &val); 1116*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1117*e0e474a8SSteve Glendinning 1118*e0e474a8SSteve Glendinning val |= WUCSR_MPR_; 1119*e0e474a8SSteve Glendinning 1120*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, WUCSR, val); 1121*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1122*e0e474a8SSteve Glendinning } 1123*e0e474a8SSteve Glendinning 1124*e0e474a8SSteve Glendinning /* enable/disable magic packup wake */ 1125*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, WUCSR, &val); 1126*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1127*e0e474a8SSteve Glendinning 1128*e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1129*e0e474a8SSteve Glendinning netdev_info(dev->net, "enabling magic packet wakeup"); 1130*e0e474a8SSteve Glendinning val |= WUCSR_MPEN_; 1131*e0e474a8SSteve Glendinning } else { 1132*e0e474a8SSteve Glendinning netdev_info(dev->net, "disabling magic packet wakeup"); 1133*e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1134*e0e474a8SSteve Glendinning } 1135*e0e474a8SSteve Glendinning 1136*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, WUCSR, val); 1137*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1138*e0e474a8SSteve Glendinning 1139*e0e474a8SSteve Glendinning /* enable wol wakeup source */ 1140*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1141*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1142*e0e474a8SSteve Glendinning 1143*e0e474a8SSteve Glendinning val |= PM_CTL_WOL_EN_; 1144*e0e474a8SSteve Glendinning 1145*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1146*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1147*e0e474a8SSteve Glendinning 1148*e0e474a8SSteve Glendinning /* enable receiver */ 1149*e0e474a8SSteve Glendinning smsc95xx_start_rx_path(dev); 1150*e0e474a8SSteve Glendinning 1151*e0e474a8SSteve Glendinning /* some wol options are enabled, so enter SUSPEND0 */ 1152*e0e474a8SSteve Glendinning netdev_info(dev->net, "entering SUSPEND0 mode"); 1153*e0e474a8SSteve Glendinning 1154*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1155*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1156*e0e474a8SSteve Glendinning 1157*e0e474a8SSteve Glendinning val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); 1158*e0e474a8SSteve Glendinning val |= PM_CTL_SUS_MODE_0; 1159*e0e474a8SSteve Glendinning 1160*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1161*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1162*e0e474a8SSteve Glendinning 1163*e0e474a8SSteve Glendinning /* clear wol status */ 1164*e0e474a8SSteve Glendinning val &= ~PM_CTL_WUPS_; 1165*e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1166*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1167*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1168*e0e474a8SSteve Glendinning 1169*e0e474a8SSteve Glendinning /* read back PM_CTRL */ 1170*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1171*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1172*e0e474a8SSteve Glendinning 1173*e0e474a8SSteve Glendinning smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP); 1174*e0e474a8SSteve Glendinning 1175*e0e474a8SSteve Glendinning return 0; 1176*e0e474a8SSteve Glendinning } 1177*e0e474a8SSteve Glendinning 1178*e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf) 1179*e0e474a8SSteve Glendinning { 1180*e0e474a8SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1181*e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1182*e0e474a8SSteve Glendinning int ret; 1183*e0e474a8SSteve Glendinning u32 val; 1184*e0e474a8SSteve Glendinning 1185*e0e474a8SSteve Glendinning BUG_ON(!dev); 1186*e0e474a8SSteve Glendinning 1187*e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1188*e0e474a8SSteve Glendinning smsc95xx_clear_feature(dev, USB_DEVICE_REMOTE_WAKEUP); 1189*e0e474a8SSteve Glendinning 1190*e0e474a8SSteve Glendinning /* Disable magic packup wake */ 1191*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, WUCSR, &val); 1192*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading WUCSR"); 1193*e0e474a8SSteve Glendinning 1194*e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1195*e0e474a8SSteve Glendinning 1196*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, WUCSR, val); 1197*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing WUCSR"); 1198*e0e474a8SSteve Glendinning 1199*e0e474a8SSteve Glendinning /* clear wake-up status */ 1200*e0e474a8SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &val); 1201*e0e474a8SSteve Glendinning check_warn_return(ret, "Error reading PM_CTRL"); 1202*e0e474a8SSteve Glendinning 1203*e0e474a8SSteve Glendinning val &= ~PM_CTL_WOL_EN_; 1204*e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_; 1205*e0e474a8SSteve Glendinning 1206*e0e474a8SSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, val); 1207*e0e474a8SSteve Glendinning check_warn_return(ret, "Error writing PM_CTRL"); 1208*e0e474a8SSteve Glendinning } 1209*e0e474a8SSteve Glendinning 1210*e0e474a8SSteve Glendinning return usbnet_resume(intf); 1211*e0e474a8SSteve Glendinning check_warn_return(ret, "usbnet_resume error"); 1212*e0e474a8SSteve Glendinning 1213*e0e474a8SSteve Glendinning return 0; 1214*e0e474a8SSteve Glendinning } 1215*e0e474a8SSteve Glendinning 12162f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb) 12172f7ca802SSteve Glendinning { 12182f7ca802SSteve Glendinning skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); 12192f7ca802SSteve Glendinning skb->ip_summed = CHECKSUM_COMPLETE; 12202f7ca802SSteve Glendinning skb_trim(skb, skb->len - 2); 12212f7ca802SSteve Glendinning } 12222f7ca802SSteve Glendinning 12232f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 12242f7ca802SSteve Glendinning { 12252f7ca802SSteve Glendinning while (skb->len > 0) { 12262f7ca802SSteve Glendinning u32 header, align_count; 12272f7ca802SSteve Glendinning struct sk_buff *ax_skb; 12282f7ca802SSteve Glendinning unsigned char *packet; 12292f7ca802SSteve Glendinning u16 size; 12302f7ca802SSteve Glendinning 12312f7ca802SSteve Glendinning memcpy(&header, skb->data, sizeof(header)); 12322f7ca802SSteve Glendinning le32_to_cpus(&header); 12332f7ca802SSteve Glendinning skb_pull(skb, 4 + NET_IP_ALIGN); 12342f7ca802SSteve Glendinning packet = skb->data; 12352f7ca802SSteve Glendinning 12362f7ca802SSteve Glendinning /* get the packet length */ 12372f7ca802SSteve Glendinning size = (u16)((header & RX_STS_FL_) >> 16); 12382f7ca802SSteve Glendinning align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 12392f7ca802SSteve Glendinning 12402f7ca802SSteve Glendinning if (unlikely(header & RX_STS_ES_)) { 1241a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1242a475f603SJoe Perches "Error header=0x%08x\n", header); 124380667ac1SHerbert Xu dev->net->stats.rx_errors++; 124480667ac1SHerbert Xu dev->net->stats.rx_dropped++; 12452f7ca802SSteve Glendinning 12462f7ca802SSteve Glendinning if (header & RX_STS_CRC_) { 124780667ac1SHerbert Xu dev->net->stats.rx_crc_errors++; 12482f7ca802SSteve Glendinning } else { 12492f7ca802SSteve Glendinning if (header & (RX_STS_TL_ | RX_STS_RF_)) 125080667ac1SHerbert Xu dev->net->stats.rx_frame_errors++; 12512f7ca802SSteve Glendinning 12522f7ca802SSteve Glendinning if ((header & RX_STS_LE_) && 12532f7ca802SSteve Glendinning (!(header & RX_STS_FT_))) 125480667ac1SHerbert Xu dev->net->stats.rx_length_errors++; 12552f7ca802SSteve Glendinning } 12562f7ca802SSteve Glendinning } else { 12572f7ca802SSteve Glendinning /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ 12582f7ca802SSteve Glendinning if (unlikely(size > (ETH_FRAME_LEN + 12))) { 1259a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1260a475f603SJoe Perches "size err header=0x%08x\n", header); 12612f7ca802SSteve Glendinning return 0; 12622f7ca802SSteve Glendinning } 12632f7ca802SSteve Glendinning 12642f7ca802SSteve Glendinning /* last frame in this batch */ 12652f7ca802SSteve Glendinning if (skb->len == size) { 126678e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 12672f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(skb); 1268df18accaSPeter Korsgaard skb_trim(skb, skb->len - 4); /* remove fcs */ 12692f7ca802SSteve Glendinning skb->truesize = size + sizeof(struct sk_buff); 12702f7ca802SSteve Glendinning 12712f7ca802SSteve Glendinning return 1; 12722f7ca802SSteve Glendinning } 12732f7ca802SSteve Glendinning 12742f7ca802SSteve Glendinning ax_skb = skb_clone(skb, GFP_ATOMIC); 12752f7ca802SSteve Glendinning if (unlikely(!ax_skb)) { 127660b86755SJoe Perches netdev_warn(dev->net, "Error allocating skb\n"); 12772f7ca802SSteve Glendinning return 0; 12782f7ca802SSteve Glendinning } 12792f7ca802SSteve Glendinning 12802f7ca802SSteve Glendinning ax_skb->len = size; 12812f7ca802SSteve Glendinning ax_skb->data = packet; 12822f7ca802SSteve Glendinning skb_set_tail_pointer(ax_skb, size); 12832f7ca802SSteve Glendinning 128478e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 12852f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(ax_skb); 1286df18accaSPeter Korsgaard skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 12872f7ca802SSteve Glendinning ax_skb->truesize = size + sizeof(struct sk_buff); 12882f7ca802SSteve Glendinning 12892f7ca802SSteve Glendinning usbnet_skb_return(dev, ax_skb); 12902f7ca802SSteve Glendinning } 12912f7ca802SSteve Glendinning 12922f7ca802SSteve Glendinning skb_pull(skb, size); 12932f7ca802SSteve Glendinning 12942f7ca802SSteve Glendinning /* padding bytes before the next frame starts */ 12952f7ca802SSteve Glendinning if (skb->len) 12962f7ca802SSteve Glendinning skb_pull(skb, align_count); 12972f7ca802SSteve Glendinning } 12982f7ca802SSteve Glendinning 12992f7ca802SSteve Glendinning if (unlikely(skb->len < 0)) { 130060b86755SJoe Perches netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len); 13012f7ca802SSteve Glendinning return 0; 13022f7ca802SSteve Glendinning } 13032f7ca802SSteve Glendinning 13042f7ca802SSteve Glendinning return 1; 13052f7ca802SSteve Glendinning } 13062f7ca802SSteve Glendinning 1307f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) 1308f7b29271SSteve Glendinning { 130955508d60SMichał Mirosław u16 low_16 = (u16)skb_checksum_start_offset(skb); 131055508d60SMichał Mirosław u16 high_16 = low_16 + skb->csum_offset; 1311f7b29271SSteve Glendinning return (high_16 << 16) | low_16; 1312f7b29271SSteve Glendinning } 1313f7b29271SSteve Glendinning 13142f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 13152f7ca802SSteve Glendinning struct sk_buff *skb, gfp_t flags) 13162f7ca802SSteve Glendinning { 131778e47fe4SMichał Mirosław bool csum = skb->ip_summed == CHECKSUM_PARTIAL; 1318f7b29271SSteve Glendinning int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; 13192f7ca802SSteve Glendinning u32 tx_cmd_a, tx_cmd_b; 13202f7ca802SSteve Glendinning 1321f7b29271SSteve Glendinning /* We do not advertise SG, so skbs should be already linearized */ 1322f7b29271SSteve Glendinning BUG_ON(skb_shinfo(skb)->nr_frags); 1323f7b29271SSteve Glendinning 1324f7b29271SSteve Glendinning if (skb_headroom(skb) < overhead) { 13252f7ca802SSteve Glendinning struct sk_buff *skb2 = skb_copy_expand(skb, 1326f7b29271SSteve Glendinning overhead, 0, flags); 13272f7ca802SSteve Glendinning dev_kfree_skb_any(skb); 13282f7ca802SSteve Glendinning skb = skb2; 13292f7ca802SSteve Glendinning if (!skb) 13302f7ca802SSteve Glendinning return NULL; 13312f7ca802SSteve Glendinning } 13322f7ca802SSteve Glendinning 1333f7b29271SSteve Glendinning if (csum) { 133411bc3088SSteve Glendinning if (skb->len <= 45) { 133511bc3088SSteve Glendinning /* workaround - hardware tx checksum does not work 133611bc3088SSteve Glendinning * properly with extremely small packets */ 133755508d60SMichał Mirosław long csstart = skb_checksum_start_offset(skb); 133811bc3088SSteve Glendinning __wsum calc = csum_partial(skb->data + csstart, 133911bc3088SSteve Glendinning skb->len - csstart, 0); 134011bc3088SSteve Glendinning *((__sum16 *)(skb->data + csstart 134111bc3088SSteve Glendinning + skb->csum_offset)) = csum_fold(calc); 134211bc3088SSteve Glendinning 134311bc3088SSteve Glendinning csum = false; 134411bc3088SSteve Glendinning } else { 1345f7b29271SSteve Glendinning u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); 1346f7b29271SSteve Glendinning skb_push(skb, 4); 1347f7b29271SSteve Glendinning memcpy(skb->data, &csum_preamble, 4); 1348f7b29271SSteve Glendinning } 134911bc3088SSteve Glendinning } 1350f7b29271SSteve Glendinning 13512f7ca802SSteve Glendinning skb_push(skb, 4); 13522f7ca802SSteve Glendinning tx_cmd_b = (u32)(skb->len - 4); 1353f7b29271SSteve Glendinning if (csum) 1354f7b29271SSteve Glendinning tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; 13552f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_b); 13562f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_b, 4); 13572f7ca802SSteve Glendinning 13582f7ca802SSteve Glendinning skb_push(skb, 4); 13592f7ca802SSteve Glendinning tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ | 13602f7ca802SSteve Glendinning TX_CMD_A_LAST_SEG_; 13612f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_a); 13622f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_a, 4); 13632f7ca802SSteve Glendinning 13642f7ca802SSteve Glendinning return skb; 13652f7ca802SSteve Glendinning } 13662f7ca802SSteve Glendinning 13672f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = { 13682f7ca802SSteve Glendinning .description = "smsc95xx USB 2.0 Ethernet", 13692f7ca802SSteve Glendinning .bind = smsc95xx_bind, 13702f7ca802SSteve Glendinning .unbind = smsc95xx_unbind, 13712f7ca802SSteve Glendinning .link_reset = smsc95xx_link_reset, 13722f7ca802SSteve Glendinning .reset = smsc95xx_reset, 13732f7ca802SSteve Glendinning .rx_fixup = smsc95xx_rx_fixup, 13742f7ca802SSteve Glendinning .tx_fixup = smsc95xx_tx_fixup, 13752f7ca802SSteve Glendinning .status = smsc95xx_status, 137607d69d42SPaolo Pisati .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, 13772f7ca802SSteve Glendinning }; 13782f7ca802SSteve Glendinning 13792f7ca802SSteve Glendinning static const struct usb_device_id products[] = { 13802f7ca802SSteve Glendinning { 13812f7ca802SSteve Glendinning /* SMSC9500 USB Ethernet Device */ 13822f7ca802SSteve Glendinning USB_DEVICE(0x0424, 0x9500), 13832f7ca802SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 13842f7ca802SSteve Glendinning }, 1385726474b8SSteve Glendinning { 13866f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device */ 13876f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9505), 13886f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 13896f41d12bSSteve Glendinning }, 13906f41d12bSSteve Glendinning { 13916f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device */ 13926f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E00), 13936f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 13946f41d12bSSteve Glendinning }, 13956f41d12bSSteve Glendinning { 13966f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device */ 13976f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E01), 13986f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 13996f41d12bSSteve Glendinning }, 14006f41d12bSSteve Glendinning { 1401726474b8SSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device */ 1402726474b8SSteve Glendinning USB_DEVICE(0x0424, 0xec00), 1403726474b8SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 1404726474b8SSteve Glendinning }, 14056f41d12bSSteve Glendinning { 14066f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (SAL10) */ 14076f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9900), 14086f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14096f41d12bSSteve Glendinning }, 14106f41d12bSSteve Glendinning { 14116f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device (SAL10) */ 14126f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9901), 14136f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14146f41d12bSSteve Glendinning }, 14156f41d12bSSteve Glendinning { 14166f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (SAL10) */ 14176f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9902), 14186f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14196f41d12bSSteve Glendinning }, 14206f41d12bSSteve Glendinning { 14216f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (SAL10) */ 14226f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9903), 14236f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14246f41d12bSSteve Glendinning }, 14256f41d12bSSteve Glendinning { 14266f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ 14276f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9904), 14286f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14296f41d12bSSteve Glendinning }, 14306f41d12bSSteve Glendinning { 14316f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (HAL) */ 14326f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9905), 14336f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14346f41d12bSSteve Glendinning }, 14356f41d12bSSteve Glendinning { 14366f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (HAL) */ 14376f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9906), 14386f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14396f41d12bSSteve Glendinning }, 14406f41d12bSSteve Glendinning { 14416f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (Alternate ID) */ 14426f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9907), 14436f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14446f41d12bSSteve Glendinning }, 14456f41d12bSSteve Glendinning { 14466f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (Alternate ID) */ 14476f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9908), 14486f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14496f41d12bSSteve Glendinning }, 14506f41d12bSSteve Glendinning { 14516f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ 14526f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9909), 14536f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 14546f41d12bSSteve Glendinning }, 145588edaa41SSteve Glendinning { 145688edaa41SSteve Glendinning /* SMSC LAN9530 USB Ethernet Device */ 145788edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9530), 145888edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 145988edaa41SSteve Glendinning }, 146088edaa41SSteve Glendinning { 146188edaa41SSteve Glendinning /* SMSC LAN9730 USB Ethernet Device */ 146288edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9730), 146388edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 146488edaa41SSteve Glendinning }, 146588edaa41SSteve Glendinning { 146688edaa41SSteve Glendinning /* SMSC LAN89530 USB Ethernet Device */ 146788edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9E08), 146888edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 146988edaa41SSteve Glendinning }, 14702f7ca802SSteve Glendinning { }, /* END */ 14712f7ca802SSteve Glendinning }; 14722f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products); 14732f7ca802SSteve Glendinning 14742f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = { 14752f7ca802SSteve Glendinning .name = "smsc95xx", 14762f7ca802SSteve Glendinning .id_table = products, 14772f7ca802SSteve Glendinning .probe = usbnet_probe, 1478b5a04475SSteve Glendinning .suspend = smsc95xx_suspend, 1479*e0e474a8SSteve Glendinning .resume = smsc95xx_resume, 1480*e0e474a8SSteve Glendinning .reset_resume = smsc95xx_resume, 14812f7ca802SSteve Glendinning .disconnect = usbnet_disconnect, 1482e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 14832f7ca802SSteve Glendinning }; 14842f7ca802SSteve Glendinning 1485d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver); 14862f7ca802SSteve Glendinning 14872f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin"); 148890b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); 14892f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); 14902f7ca802SSteve Glendinning MODULE_LICENSE("GPL"); 1491