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 169cb00073SJeff Kirsher * along with this program; if not, see <http://www.gnu.org/licenses/>. 172f7ca802SSteve Glendinning * 182f7ca802SSteve Glendinning *****************************************************************************/ 192f7ca802SSteve Glendinning 202f7ca802SSteve Glendinning #include <linux/module.h> 212f7ca802SSteve Glendinning #include <linux/kmod.h> 222f7ca802SSteve Glendinning #include <linux/netdevice.h> 232f7ca802SSteve Glendinning #include <linux/etherdevice.h> 242f7ca802SSteve Glendinning #include <linux/ethtool.h> 252f7ca802SSteve Glendinning #include <linux/mii.h> 262f7ca802SSteve Glendinning #include <linux/usb.h> 27bbd9f9eeSSteve Glendinning #include <linux/bitrev.h> 28bbd9f9eeSSteve Glendinning #include <linux/crc16.h> 292f7ca802SSteve Glendinning #include <linux/crc32.h> 302f7ca802SSteve Glendinning #include <linux/usb/usbnet.h> 315a0e3ad6STejun Heo #include <linux/slab.h> 32c489565bSArnd Bergmann #include <linux/of_net.h> 332f7ca802SSteve Glendinning #include "smsc95xx.h" 342f7ca802SSteve Glendinning 352f7ca802SSteve Glendinning #define SMSC_CHIPNAME "smsc95xx" 3653a759c8SMartin Wetterwald #define SMSC_DRIVER_VERSION "1.0.6" 372f7ca802SSteve Glendinning #define HS_USB_PKT_SIZE (512) 382f7ca802SSteve Glendinning #define FS_USB_PKT_SIZE (64) 392f7ca802SSteve Glendinning #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) 402f7ca802SSteve Glendinning #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) 412f7ca802SSteve Glendinning #define DEFAULT_BULK_IN_DELAY (0x00002000) 422f7ca802SSteve Glendinning #define MAX_SINGLE_PACKET_SIZE (2048) 432f7ca802SSteve Glendinning #define LAN95XX_EEPROM_MAGIC (0x9500) 442f7ca802SSteve Glendinning #define EEPROM_MAC_OFFSET (0x01) 45f7b29271SSteve Glendinning #define DEFAULT_TX_CSUM_ENABLE (true) 462f7ca802SSteve Glendinning #define DEFAULT_RX_CSUM_ENABLE (true) 472f7ca802SSteve Glendinning #define SMSC95XX_INTERNAL_PHY_ID (1) 482f7ca802SSteve Glendinning #define SMSC95XX_TX_OVERHEAD (8) 49f7b29271SSteve Glendinning #define SMSC95XX_TX_OVERHEAD_CSUM (12) 50e5e3af83SSteve Glendinning #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \ 51bbd9f9eeSSteve Glendinning WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) 522f7ca802SSteve Glendinning 539ebca507SSteve Glendinning #define FEATURE_8_WAKEUP_FILTERS (0x01) 549ebca507SSteve Glendinning #define FEATURE_PHY_NLP_CROSSOVER (0x02) 55eb970ff0SMing Lei #define FEATURE_REMOTE_WAKEUP (0x04) 569ebca507SSteve Glendinning 57b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND0 (0x01) 58b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND1 (0x02) 59b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND2 (0x04) 60b2d4b150SSteve Glendinning #define SUSPEND_SUSPEND3 (0x08) 61b2d4b150SSteve Glendinning #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ 62b2d4b150SSteve Glendinning SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) 63b2d4b150SSteve Glendinning 64d69d1694SChristoph Fritz #define CARRIER_CHECK_DELAY (2 * HZ) 65d69d1694SChristoph Fritz 662f7ca802SSteve Glendinning struct smsc95xx_priv { 6713722bbeSWoojung Huh u32 chip_id; 682f7ca802SSteve Glendinning u32 mac_cr; 693c0f3c60SMarc Zyngier u32 hash_hi; 703c0f3c60SMarc Zyngier u32 hash_lo; 71e0e474a8SSteve Glendinning u32 wolopts; 722f7ca802SSteve Glendinning spinlock_t mac_cr_lock; 739ebca507SSteve Glendinning u8 features; 74b2d4b150SSteve Glendinning u8 suspend_flags; 7513722bbeSWoojung Huh u8 mdix_ctrl; 76d69d1694SChristoph Fritz bool link_ok; 77d69d1694SChristoph Fritz struct delayed_work carrier_check; 78d69d1694SChristoph Fritz struct usbnet *dev; 792f7ca802SSteve Glendinning }; 802f7ca802SSteve Glendinning 81eb939922SRusty Russell static bool turbo_mode = true; 822f7ca802SSteve Glendinning module_param(turbo_mode, bool, 0644); 832f7ca802SSteve Glendinning MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); 842f7ca802SSteve Glendinning 85ec32115dSMing Lei static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, 86ec32115dSMing Lei u32 *data, int in_pm) 872f7ca802SSteve Glendinning { 8872108fd2SMing Lei u32 buf; 892f7ca802SSteve Glendinning int ret; 90ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); 912f7ca802SSteve Glendinning 922f7ca802SSteve Glendinning BUG_ON(!dev); 932f7ca802SSteve Glendinning 94ec32115dSMing Lei if (!in_pm) 95ec32115dSMing Lei fn = usbnet_read_cmd; 96ec32115dSMing Lei else 97ec32115dSMing Lei fn = usbnet_read_cmd_nopm; 98ec32115dSMing Lei 99ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN 100ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 10172108fd2SMing Lei 0, index, &buf, 4); 1025a36b68bSDan Carpenter if (unlikely(ret < 0)) { 1031e1d7412SJoe Perches netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", 1041e1d7412SJoe Perches index, ret); 1055a36b68bSDan Carpenter return ret; 1065a36b68bSDan Carpenter } 1072f7ca802SSteve Glendinning 10872108fd2SMing Lei le32_to_cpus(&buf); 10972108fd2SMing Lei *data = buf; 1102f7ca802SSteve Glendinning 1112f7ca802SSteve Glendinning return ret; 1122f7ca802SSteve Glendinning } 1132f7ca802SSteve Glendinning 114ec32115dSMing Lei static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index, 115ec32115dSMing Lei u32 data, int in_pm) 1162f7ca802SSteve Glendinning { 11772108fd2SMing Lei u32 buf; 1182f7ca802SSteve Glendinning int ret; 119ec32115dSMing Lei int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); 1202f7ca802SSteve Glendinning 1212f7ca802SSteve Glendinning BUG_ON(!dev); 1222f7ca802SSteve Glendinning 123ec32115dSMing Lei if (!in_pm) 124ec32115dSMing Lei fn = usbnet_write_cmd; 125ec32115dSMing Lei else 126ec32115dSMing Lei fn = usbnet_write_cmd_nopm; 127ec32115dSMing Lei 12872108fd2SMing Lei buf = data; 12972108fd2SMing Lei cpu_to_le32s(&buf); 1302f7ca802SSteve Glendinning 131ec32115dSMing Lei ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT 132ec32115dSMing Lei | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 13372108fd2SMing Lei 0, index, &buf, 4); 1342f7ca802SSteve Glendinning if (unlikely(ret < 0)) 1351e1d7412SJoe Perches netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n", 1361e1d7412SJoe Perches index, ret); 1372f7ca802SSteve Glendinning 1382f7ca802SSteve Glendinning return ret; 1392f7ca802SSteve Glendinning } 1402f7ca802SSteve Glendinning 141ec32115dSMing Lei static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index, 142ec32115dSMing Lei u32 *data) 143ec32115dSMing Lei { 144ec32115dSMing Lei return __smsc95xx_read_reg(dev, index, data, 1); 145ec32115dSMing Lei } 146ec32115dSMing Lei 147ec32115dSMing Lei static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index, 148ec32115dSMing Lei u32 data) 149ec32115dSMing Lei { 150ec32115dSMing Lei return __smsc95xx_write_reg(dev, index, data, 1); 151ec32115dSMing Lei } 152ec32115dSMing Lei 153ec32115dSMing Lei static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, 154ec32115dSMing Lei u32 *data) 155ec32115dSMing Lei { 156ec32115dSMing Lei return __smsc95xx_read_reg(dev, index, data, 0); 157ec32115dSMing Lei } 158ec32115dSMing Lei 159ec32115dSMing Lei static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, 160ec32115dSMing Lei u32 data) 161ec32115dSMing Lei { 162ec32115dSMing Lei return __smsc95xx_write_reg(dev, index, data, 0); 163ec32115dSMing Lei } 164e0e474a8SSteve Glendinning 1652f7ca802SSteve Glendinning /* Loop until the read is completed with timeout 1662f7ca802SSteve Glendinning * called with phy_mutex held */ 167e5e3af83SSteve Glendinning static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev, 168e5e3af83SSteve Glendinning int in_pm) 1692f7ca802SSteve Glendinning { 1702f7ca802SSteve Glendinning unsigned long start_time = jiffies; 1712f7ca802SSteve Glendinning u32 val; 172769ea6d8SSteve Glendinning int ret; 1732f7ca802SSteve Glendinning 1742f7ca802SSteve Glendinning do { 175e5e3af83SSteve Glendinning ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm); 176b052e073SSteve Glendinning if (ret < 0) { 177b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading MII_ACCESS\n"); 178b052e073SSteve Glendinning return ret; 179b052e073SSteve Glendinning } 180b052e073SSteve Glendinning 1812f7ca802SSteve Glendinning if (!(val & MII_BUSY_)) 1822f7ca802SSteve Glendinning return 0; 1832f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 1842f7ca802SSteve Glendinning 1852f7ca802SSteve Glendinning return -EIO; 1862f7ca802SSteve Glendinning } 1872f7ca802SSteve Glendinning 188e5e3af83SSteve Glendinning static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx, 189e5e3af83SSteve Glendinning int in_pm) 1902f7ca802SSteve Glendinning { 1912f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 1922f7ca802SSteve Glendinning u32 val, addr; 193769ea6d8SSteve Glendinning int ret; 1942f7ca802SSteve Glendinning 1952f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 1962f7ca802SSteve Glendinning 1972f7ca802SSteve Glendinning /* confirm MII not busy */ 198e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 199b052e073SSteve Glendinning if (ret < 0) { 200b052e073SSteve Glendinning netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n"); 201b052e073SSteve Glendinning goto done; 202b052e073SSteve Glendinning } 2032f7ca802SSteve Glendinning 2042f7ca802SSteve Glendinning /* set the address, index & direction (read from PHY) */ 2052f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 2062f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 20780928805SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_; 208e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); 209b052e073SSteve Glendinning if (ret < 0) { 210b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_ADDR\n"); 211b052e073SSteve Glendinning goto done; 212b052e073SSteve Glendinning } 2132f7ca802SSteve Glendinning 214e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 215b052e073SSteve Glendinning if (ret < 0) { 216b052e073SSteve Glendinning netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); 217b052e073SSteve Glendinning goto done; 218b052e073SSteve Glendinning } 219769ea6d8SSteve Glendinning 220e5e3af83SSteve Glendinning ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm); 221b052e073SSteve Glendinning if (ret < 0) { 222b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading MII_DATA\n"); 223b052e073SSteve Glendinning goto done; 224b052e073SSteve Glendinning } 225769ea6d8SSteve Glendinning 226769ea6d8SSteve Glendinning ret = (u16)(val & 0xFFFF); 227769ea6d8SSteve Glendinning 228769ea6d8SSteve Glendinning done: 2292f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 230769ea6d8SSteve Glendinning return ret; 2312f7ca802SSteve Glendinning } 2322f7ca802SSteve Glendinning 233e5e3af83SSteve Glendinning static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, 234e5e3af83SSteve Glendinning int idx, int regval, int in_pm) 2352f7ca802SSteve Glendinning { 2362f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 2372f7ca802SSteve Glendinning u32 val, addr; 238769ea6d8SSteve Glendinning int ret; 2392f7ca802SSteve Glendinning 2402f7ca802SSteve Glendinning mutex_lock(&dev->phy_mutex); 2412f7ca802SSteve Glendinning 2422f7ca802SSteve Glendinning /* confirm MII not busy */ 243e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 244b052e073SSteve Glendinning if (ret < 0) { 245b052e073SSteve Glendinning netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n"); 246b052e073SSteve Glendinning goto done; 247b052e073SSteve Glendinning } 2482f7ca802SSteve Glendinning 2492f7ca802SSteve Glendinning val = regval; 250e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm); 251b052e073SSteve Glendinning if (ret < 0) { 252b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_DATA\n"); 253b052e073SSteve Glendinning goto done; 254b052e073SSteve Glendinning } 2552f7ca802SSteve Glendinning 2562f7ca802SSteve Glendinning /* set the address, index & direction (write to PHY) */ 2572f7ca802SSteve Glendinning phy_id &= dev->mii.phy_id_mask; 2582f7ca802SSteve Glendinning idx &= dev->mii.reg_num_mask; 25980928805SSteve Glendinning addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_; 260e5e3af83SSteve Glendinning ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); 261b052e073SSteve Glendinning if (ret < 0) { 262b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing MII_ADDR\n"); 263b052e073SSteve Glendinning goto done; 264b052e073SSteve Glendinning } 2652f7ca802SSteve Glendinning 266e5e3af83SSteve Glendinning ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); 267b052e073SSteve Glendinning if (ret < 0) { 268b052e073SSteve Glendinning netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); 269b052e073SSteve Glendinning goto done; 270b052e073SSteve Glendinning } 2712f7ca802SSteve Glendinning 272769ea6d8SSteve Glendinning done: 2732f7ca802SSteve Glendinning mutex_unlock(&dev->phy_mutex); 2742f7ca802SSteve Glendinning } 2752f7ca802SSteve Glendinning 276e5e3af83SSteve Glendinning static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id, 277e5e3af83SSteve Glendinning int idx) 278e5e3af83SSteve Glendinning { 279e5e3af83SSteve Glendinning return __smsc95xx_mdio_read(netdev, phy_id, idx, 1); 280e5e3af83SSteve Glendinning } 281e5e3af83SSteve Glendinning 282e5e3af83SSteve Glendinning static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id, 283e5e3af83SSteve Glendinning int idx, int regval) 284e5e3af83SSteve Glendinning { 285e5e3af83SSteve Glendinning __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1); 286e5e3af83SSteve Glendinning } 287e5e3af83SSteve Glendinning 288e5e3af83SSteve Glendinning static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) 289e5e3af83SSteve Glendinning { 290e5e3af83SSteve Glendinning return __smsc95xx_mdio_read(netdev, phy_id, idx, 0); 291e5e3af83SSteve Glendinning } 292e5e3af83SSteve Glendinning 293e5e3af83SSteve Glendinning static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, 294e5e3af83SSteve Glendinning int regval) 295e5e3af83SSteve Glendinning { 296e5e3af83SSteve Glendinning __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0); 297e5e3af83SSteve Glendinning } 298e5e3af83SSteve Glendinning 299769ea6d8SSteve Glendinning static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev) 3002f7ca802SSteve Glendinning { 3012f7ca802SSteve Glendinning unsigned long start_time = jiffies; 3022f7ca802SSteve Glendinning u32 val; 303769ea6d8SSteve Glendinning int ret; 3042f7ca802SSteve Glendinning 3052f7ca802SSteve Glendinning do { 306769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 307b052e073SSteve Glendinning if (ret < 0) { 308b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_CMD\n"); 309b052e073SSteve Glendinning return ret; 310b052e073SSteve Glendinning } 311b052e073SSteve Glendinning 3122f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) 3132f7ca802SSteve Glendinning break; 3142f7ca802SSteve Glendinning udelay(40); 3152f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3162f7ca802SSteve Glendinning 3172f7ca802SSteve Glendinning if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { 31860b86755SJoe Perches netdev_warn(dev->net, "EEPROM read operation timeout\n"); 3192f7ca802SSteve Glendinning return -EIO; 3202f7ca802SSteve Glendinning } 3212f7ca802SSteve Glendinning 3222f7ca802SSteve Glendinning return 0; 3232f7ca802SSteve Glendinning } 3242f7ca802SSteve Glendinning 325769ea6d8SSteve Glendinning static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) 3262f7ca802SSteve Glendinning { 3272f7ca802SSteve Glendinning unsigned long start_time = jiffies; 3282f7ca802SSteve Glendinning u32 val; 329769ea6d8SSteve Glendinning int ret; 3302f7ca802SSteve Glendinning 3312f7ca802SSteve Glendinning do { 332769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_CMD, &val); 333b052e073SSteve Glendinning if (ret < 0) { 334b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_CMD\n"); 335b052e073SSteve Glendinning return ret; 336b052e073SSteve Glendinning } 3372f7ca802SSteve Glendinning 3382f7ca802SSteve Glendinning if (!(val & E2P_CMD_BUSY_)) 3392f7ca802SSteve Glendinning return 0; 3402f7ca802SSteve Glendinning 3412f7ca802SSteve Glendinning udelay(40); 3422f7ca802SSteve Glendinning } while (!time_after(jiffies, start_time + HZ)); 3432f7ca802SSteve Glendinning 34460b86755SJoe Perches netdev_warn(dev->net, "EEPROM is busy\n"); 3452f7ca802SSteve Glendinning return -EIO; 3462f7ca802SSteve Glendinning } 3472f7ca802SSteve Glendinning 3482f7ca802SSteve Glendinning static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, 3492f7ca802SSteve Glendinning u8 *data) 3502f7ca802SSteve Glendinning { 3512f7ca802SSteve Glendinning u32 val; 3522f7ca802SSteve Glendinning int i, ret; 3532f7ca802SSteve Glendinning 3542f7ca802SSteve Glendinning BUG_ON(!dev); 3552f7ca802SSteve Glendinning BUG_ON(!data); 3562f7ca802SSteve Glendinning 3572f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3582f7ca802SSteve Glendinning if (ret) 3592f7ca802SSteve Glendinning return ret; 3602f7ca802SSteve Glendinning 3612f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 3622f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); 363769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 364b052e073SSteve Glendinning if (ret < 0) { 365b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_CMD\n"); 366b052e073SSteve Glendinning return ret; 367b052e073SSteve Glendinning } 3682f7ca802SSteve Glendinning 3692f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 3702f7ca802SSteve Glendinning if (ret < 0) 3712f7ca802SSteve Glendinning return ret; 3722f7ca802SSteve Glendinning 373769ea6d8SSteve Glendinning ret = smsc95xx_read_reg(dev, E2P_DATA, &val); 374b052e073SSteve Glendinning if (ret < 0) { 375b052e073SSteve Glendinning netdev_warn(dev->net, "Error reading E2P_DATA\n"); 376b052e073SSteve Glendinning return ret; 377b052e073SSteve Glendinning } 3782f7ca802SSteve Glendinning 3792f7ca802SSteve Glendinning data[i] = val & 0xFF; 3802f7ca802SSteve Glendinning offset++; 3812f7ca802SSteve Glendinning } 3822f7ca802SSteve Glendinning 3832f7ca802SSteve Glendinning return 0; 3842f7ca802SSteve Glendinning } 3852f7ca802SSteve Glendinning 3862f7ca802SSteve Glendinning static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, 3872f7ca802SSteve Glendinning u8 *data) 3882f7ca802SSteve Glendinning { 3892f7ca802SSteve Glendinning u32 val; 3902f7ca802SSteve Glendinning int i, ret; 3912f7ca802SSteve Glendinning 3922f7ca802SSteve Glendinning BUG_ON(!dev); 3932f7ca802SSteve Glendinning BUG_ON(!data); 3942f7ca802SSteve Glendinning 3952f7ca802SSteve Glendinning ret = smsc95xx_eeprom_confirm_not_busy(dev); 3962f7ca802SSteve Glendinning if (ret) 3972f7ca802SSteve Glendinning return ret; 3982f7ca802SSteve Glendinning 3992f7ca802SSteve Glendinning /* Issue write/erase enable command */ 4002f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; 401769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 402b052e073SSteve Glendinning if (ret < 0) { 403b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_DATA\n"); 404b052e073SSteve Glendinning return ret; 405b052e073SSteve Glendinning } 4062f7ca802SSteve Glendinning 4072f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 4082f7ca802SSteve Glendinning if (ret < 0) 4092f7ca802SSteve Glendinning return ret; 4102f7ca802SSteve Glendinning 4112f7ca802SSteve Glendinning for (i = 0; i < length; i++) { 4122f7ca802SSteve Glendinning 4132f7ca802SSteve Glendinning /* Fill data register */ 4142f7ca802SSteve Glendinning val = data[i]; 415769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_DATA, val); 416b052e073SSteve Glendinning if (ret < 0) { 417b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_DATA\n"); 418b052e073SSteve Glendinning return ret; 419b052e073SSteve Glendinning } 4202f7ca802SSteve Glendinning 4212f7ca802SSteve Glendinning /* Send "write" command */ 4222f7ca802SSteve Glendinning val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); 423769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, E2P_CMD, val); 424b052e073SSteve Glendinning if (ret < 0) { 425b052e073SSteve Glendinning netdev_warn(dev->net, "Error writing E2P_CMD\n"); 426b052e073SSteve Glendinning return ret; 427b052e073SSteve Glendinning } 4282f7ca802SSteve Glendinning 4292f7ca802SSteve Glendinning ret = smsc95xx_wait_eeprom(dev); 4302f7ca802SSteve Glendinning if (ret < 0) 4312f7ca802SSteve Glendinning return ret; 4322f7ca802SSteve Glendinning 4332f7ca802SSteve Glendinning offset++; 4342f7ca802SSteve Glendinning } 4352f7ca802SSteve Glendinning 4362f7ca802SSteve Glendinning return 0; 4372f7ca802SSteve Glendinning } 4382f7ca802SSteve Glendinning 439769ea6d8SSteve Glendinning static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, 4407b9e7580SSteve Glendinning u32 data) 4412f7ca802SSteve Glendinning { 4421d74a6bdSSteve Glendinning const u16 size = 4; 4437b9e7580SSteve Glendinning u32 buf; 44472108fd2SMing Lei int ret; 4452f7ca802SSteve Glendinning 4467b9e7580SSteve Glendinning buf = data; 4477b9e7580SSteve Glendinning cpu_to_le32s(&buf); 4487b9e7580SSteve Glendinning 44972108fd2SMing Lei ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, 45072108fd2SMing Lei USB_DIR_OUT | USB_TYPE_VENDOR | 45172108fd2SMing Lei USB_RECIP_DEVICE, 4527b9e7580SSteve Glendinning 0, index, &buf, size); 45372108fd2SMing Lei if (ret < 0) 45472108fd2SMing Lei netdev_warn(dev->net, "Error write async cmd, sts=%d\n", 45572108fd2SMing Lei ret); 45672108fd2SMing Lei return ret; 4572f7ca802SSteve Glendinning } 4582f7ca802SSteve Glendinning 4592f7ca802SSteve Glendinning /* returns hash bit number for given MAC address 4602f7ca802SSteve Glendinning * example: 4612f7ca802SSteve Glendinning * 01 00 5E 00 00 01 -> returns bit number 31 */ 4622f7ca802SSteve Glendinning static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) 4632f7ca802SSteve Glendinning { 4642f7ca802SSteve Glendinning return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; 4652f7ca802SSteve Glendinning } 4662f7ca802SSteve Glendinning 4672f7ca802SSteve Glendinning static void smsc95xx_set_multicast(struct net_device *netdev) 4682f7ca802SSteve Glendinning { 4692f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 4702f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 4712f7ca802SSteve Glendinning unsigned long flags; 472769ea6d8SSteve Glendinning int ret; 4732f7ca802SSteve Glendinning 4743c0f3c60SMarc Zyngier pdata->hash_hi = 0; 4753c0f3c60SMarc Zyngier pdata->hash_lo = 0; 4763c0f3c60SMarc Zyngier 4772f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 4782f7ca802SSteve Glendinning 4792f7ca802SSteve Glendinning if (dev->net->flags & IFF_PROMISC) { 480a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); 4812f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_PRMS_; 4822f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 4832f7ca802SSteve Glendinning } else if (dev->net->flags & IFF_ALLMULTI) { 484a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); 4852f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_MCPAS_; 4862f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); 4874cd24eafSJiri Pirko } else if (!netdev_mc_empty(dev->net)) { 48822bedad3SJiri Pirko struct netdev_hw_addr *ha; 4892f7ca802SSteve Glendinning 4902f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_HPFILT_; 4912f7ca802SSteve Glendinning pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); 4922f7ca802SSteve Glendinning 49322bedad3SJiri Pirko netdev_for_each_mc_addr(ha, netdev) { 49422bedad3SJiri Pirko u32 bitnum = smsc95xx_hash(ha->addr); 4952f7ca802SSteve Glendinning u32 mask = 0x01 << (bitnum & 0x1F); 4962f7ca802SSteve Glendinning if (bitnum & 0x20) 4973c0f3c60SMarc Zyngier pdata->hash_hi |= mask; 4982f7ca802SSteve Glendinning else 4993c0f3c60SMarc Zyngier pdata->hash_lo |= mask; 5002f7ca802SSteve Glendinning } 5012f7ca802SSteve Glendinning 502a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", 5033c0f3c60SMarc Zyngier pdata->hash_hi, pdata->hash_lo); 5042f7ca802SSteve Glendinning } else { 505a475f603SJoe Perches netif_dbg(dev, drv, dev->net, "receive own packets only\n"); 5062f7ca802SSteve Glendinning pdata->mac_cr &= 5072f7ca802SSteve Glendinning ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); 5082f7ca802SSteve Glendinning } 5092f7ca802SSteve Glendinning 5102f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5112f7ca802SSteve Glendinning 5122f7ca802SSteve Glendinning /* Initiate async writes, as we can't wait for completion here */ 5137b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi); 514b052e073SSteve Glendinning if (ret < 0) 515b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to HASHH\n"); 516769ea6d8SSteve Glendinning 5177b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo); 518b052e073SSteve Glendinning if (ret < 0) 519b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to HASHL\n"); 520769ea6d8SSteve Glendinning 5217b9e7580SSteve Glendinning ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr); 522b052e073SSteve Glendinning if (ret < 0) 523b052e073SSteve Glendinning netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n"); 5242f7ca802SSteve Glendinning } 5252f7ca802SSteve Glendinning 526769ea6d8SSteve Glendinning static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, 5272f7ca802SSteve Glendinning u16 lcladv, u16 rmtadv) 5282f7ca802SSteve Glendinning { 5299c082731SNisar Sayed u32 flow = 0, afc_cfg; 5302f7ca802SSteve Glendinning 5312f7ca802SSteve Glendinning int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); 532e360a8b4SSteve Glendinning if (ret < 0) 533b052e073SSteve Glendinning return ret; 5342f7ca802SSteve Glendinning 5352f7ca802SSteve Glendinning if (duplex == DUPLEX_FULL) { 536bc02ff95SSteve Glendinning u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); 5372f7ca802SSteve Glendinning 5382f7ca802SSteve Glendinning if (cap & FLOW_CTRL_RX) 5392f7ca802SSteve Glendinning flow = 0xFFFF0002; 5402f7ca802SSteve Glendinning 5419c082731SNisar Sayed if (cap & FLOW_CTRL_TX) { 5422f7ca802SSteve Glendinning afc_cfg |= 0xF; 5439c082731SNisar Sayed flow |= 0xFFFF0000; 5449c082731SNisar Sayed } else { 5452f7ca802SSteve Glendinning afc_cfg &= ~0xF; 5469c082731SNisar Sayed } 5472f7ca802SSteve Glendinning 548a475f603SJoe Perches netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", 54960b86755SJoe Perches cap & FLOW_CTRL_RX ? "enabled" : "disabled", 55060b86755SJoe Perches cap & FLOW_CTRL_TX ? "enabled" : "disabled"); 5512f7ca802SSteve Glendinning } else { 552a475f603SJoe Perches netif_dbg(dev, link, dev->net, "half duplex\n"); 5532f7ca802SSteve Glendinning afc_cfg |= 0xF; 5542f7ca802SSteve Glendinning } 5552f7ca802SSteve Glendinning 556769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, flow); 557b052e073SSteve Glendinning if (ret < 0) 558b052e073SSteve Glendinning return ret; 559e360a8b4SSteve Glendinning 560e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); 5612f7ca802SSteve Glendinning } 5622f7ca802SSteve Glendinning 5632f7ca802SSteve Glendinning static int smsc95xx_link_reset(struct usbnet *dev) 5642f7ca802SSteve Glendinning { 5652f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 5662f7ca802SSteve Glendinning struct mii_if_info *mii = &dev->mii; 5678ae6dacaSDavid Decotigny struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 5682f7ca802SSteve Glendinning unsigned long flags; 5692f7ca802SSteve Glendinning u16 lcladv, rmtadv; 570769ea6d8SSteve Glendinning int ret; 5712f7ca802SSteve Glendinning 5722f7ca802SSteve Glendinning /* clear interrupt status */ 573769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); 574e360a8b4SSteve Glendinning if (ret < 0) 575b052e073SSteve Glendinning return ret; 576769ea6d8SSteve Glendinning 577769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 578e360a8b4SSteve Glendinning if (ret < 0) 579b052e073SSteve Glendinning return ret; 5802f7ca802SSteve Glendinning 5812f7ca802SSteve Glendinning mii_check_media(mii, 1, 1); 5822f7ca802SSteve Glendinning mii_ethtool_gset(&dev->mii, &ecmd); 5832f7ca802SSteve Glendinning lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); 5842f7ca802SSteve Glendinning rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA); 5852f7ca802SSteve Glendinning 5868ae6dacaSDavid Decotigny netif_dbg(dev, link, dev->net, 5878ae6dacaSDavid Decotigny "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", 5888ae6dacaSDavid Decotigny ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); 5892f7ca802SSteve Glendinning 5902f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 5912f7ca802SSteve Glendinning if (ecmd.duplex != DUPLEX_FULL) { 5922f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_FDPX_; 5932f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RCVOWN_; 5942f7ca802SSteve Glendinning } else { 5952f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_RCVOWN_; 5962f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_FDPX_; 5972f7ca802SSteve Glendinning } 5982f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 5992f7ca802SSteve Glendinning 600769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 601e360a8b4SSteve Glendinning if (ret < 0) 602b052e073SSteve Glendinning return ret; 6032f7ca802SSteve Glendinning 604769ea6d8SSteve Glendinning ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); 605b052e073SSteve Glendinning if (ret < 0) 606b052e073SSteve Glendinning netdev_warn(dev->net, "Error updating PHY flow control\n"); 6072f7ca802SSteve Glendinning 608b052e073SSteve Glendinning return ret; 6092f7ca802SSteve Glendinning } 6102f7ca802SSteve Glendinning 6112f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb) 6122f7ca802SSteve Glendinning { 6132f7ca802SSteve Glendinning u32 intdata; 6142f7ca802SSteve Glendinning 6152f7ca802SSteve Glendinning if (urb->actual_length != 4) { 61660b86755SJoe Perches netdev_warn(dev->net, "unexpected urb length %d\n", 61760b86755SJoe Perches urb->actual_length); 6182f7ca802SSteve Glendinning return; 6192f7ca802SSteve Glendinning } 6202f7ca802SSteve Glendinning 6212f7ca802SSteve Glendinning memcpy(&intdata, urb->transfer_buffer, 4); 6221d74a6bdSSteve Glendinning le32_to_cpus(&intdata); 6232f7ca802SSteve Glendinning 624a475f603SJoe Perches netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); 6252f7ca802SSteve Glendinning 6262f7ca802SSteve Glendinning if (intdata & INT_ENP_PHY_INT_) 6272f7ca802SSteve Glendinning usbnet_defer_kevent(dev, EVENT_LINK_RESET); 6282f7ca802SSteve Glendinning else 62960b86755SJoe Perches netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", 63060b86755SJoe Perches intdata); 6312f7ca802SSteve Glendinning } 6322f7ca802SSteve Glendinning 633d69d1694SChristoph Fritz static void set_carrier(struct usbnet *dev, bool link) 634d69d1694SChristoph Fritz { 635d69d1694SChristoph Fritz struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 636d69d1694SChristoph Fritz 637d69d1694SChristoph Fritz if (pdata->link_ok == link) 638d69d1694SChristoph Fritz return; 639d69d1694SChristoph Fritz 640d69d1694SChristoph Fritz pdata->link_ok = link; 641d69d1694SChristoph Fritz 642d69d1694SChristoph Fritz if (link) 643d69d1694SChristoph Fritz usbnet_link_change(dev, 1, 0); 644d69d1694SChristoph Fritz else 645d69d1694SChristoph Fritz usbnet_link_change(dev, 0, 0); 646d69d1694SChristoph Fritz } 647d69d1694SChristoph Fritz 648d69d1694SChristoph Fritz static void check_carrier(struct work_struct *work) 649d69d1694SChristoph Fritz { 650d69d1694SChristoph Fritz struct smsc95xx_priv *pdata = container_of(work, struct smsc95xx_priv, 651d69d1694SChristoph Fritz carrier_check.work); 652d69d1694SChristoph Fritz struct usbnet *dev = pdata->dev; 653d69d1694SChristoph Fritz int ret; 654d69d1694SChristoph Fritz 655d69d1694SChristoph Fritz if (pdata->suspend_flags != 0) 656d69d1694SChristoph Fritz return; 657d69d1694SChristoph Fritz 658d69d1694SChristoph Fritz ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMSR); 659d69d1694SChristoph Fritz if (ret < 0) { 660d69d1694SChristoph Fritz netdev_warn(dev->net, "Failed to read MII_BMSR\n"); 661d69d1694SChristoph Fritz return; 662d69d1694SChristoph Fritz } 663d69d1694SChristoph Fritz if (ret & BMSR_LSTATUS) 664d69d1694SChristoph Fritz set_carrier(dev, 1); 665d69d1694SChristoph Fritz else 666d69d1694SChristoph Fritz set_carrier(dev, 0); 667d69d1694SChristoph Fritz 668d69d1694SChristoph Fritz schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); 669d69d1694SChristoph Fritz } 670d69d1694SChristoph Fritz 671f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */ 672c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev, 673c8f44affSMichał Mirosław netdev_features_t features) 6742f7ca802SSteve Glendinning { 67578e47fe4SMichał Mirosław struct usbnet *dev = netdev_priv(netdev); 6762f7ca802SSteve Glendinning u32 read_buf; 67778e47fe4SMichał Mirosław int ret; 67878e47fe4SMichał Mirosław 67978e47fe4SMichał Mirosław ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); 680e360a8b4SSteve Glendinning if (ret < 0) 681b052e073SSteve Glendinning return ret; 6822f7ca802SSteve Glendinning 683fe0cd8caSNisar Sayed if (features & NETIF_F_IP_CSUM) 684f7b29271SSteve Glendinning read_buf |= Tx_COE_EN_; 685f7b29271SSteve Glendinning else 686f7b29271SSteve Glendinning read_buf &= ~Tx_COE_EN_; 687f7b29271SSteve Glendinning 68878e47fe4SMichał Mirosław if (features & NETIF_F_RXCSUM) 6892f7ca802SSteve Glendinning read_buf |= Rx_COE_EN_; 6902f7ca802SSteve Glendinning else 6912f7ca802SSteve Glendinning read_buf &= ~Rx_COE_EN_; 6922f7ca802SSteve Glendinning 6932f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, COE_CR, read_buf); 694e360a8b4SSteve Glendinning if (ret < 0) 695b052e073SSteve Glendinning return ret; 6962f7ca802SSteve Glendinning 697a475f603SJoe Perches netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); 6982f7ca802SSteve Glendinning return 0; 6992f7ca802SSteve Glendinning } 7002f7ca802SSteve Glendinning 7012f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) 7022f7ca802SSteve Glendinning { 7032f7ca802SSteve Glendinning return MAX_EEPROM_SIZE; 7042f7ca802SSteve Glendinning } 7052f7ca802SSteve Glendinning 7062f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, 7072f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 7082f7ca802SSteve Glendinning { 7092f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7102f7ca802SSteve Glendinning 7112f7ca802SSteve Glendinning ee->magic = LAN95XX_EEPROM_MAGIC; 7122f7ca802SSteve Glendinning 7132f7ca802SSteve Glendinning return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); 7142f7ca802SSteve Glendinning } 7152f7ca802SSteve Glendinning 7162f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, 7172f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 7182f7ca802SSteve Glendinning { 7192f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7202f7ca802SSteve Glendinning 7212f7ca802SSteve Glendinning if (ee->magic != LAN95XX_EEPROM_MAGIC) { 72260b86755SJoe Perches netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", 7232f7ca802SSteve Glendinning ee->magic); 7242f7ca802SSteve Glendinning return -EINVAL; 7252f7ca802SSteve Glendinning } 7262f7ca802SSteve Glendinning 7272f7ca802SSteve Glendinning return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); 7282f7ca802SSteve Glendinning } 7292f7ca802SSteve Glendinning 7309fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev) 7319fa32e94SEmeric Vigier { 7329fa32e94SEmeric Vigier /* all smsc95xx registers */ 73396245317SSteve Glendinning return COE_CR - ID_REV + sizeof(u32); 7349fa32e94SEmeric Vigier } 7359fa32e94SEmeric Vigier 7369fa32e94SEmeric Vigier static void 7379fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, 7389fa32e94SEmeric Vigier void *buf) 7399fa32e94SEmeric Vigier { 7409fa32e94SEmeric Vigier struct usbnet *dev = netdev_priv(netdev); 741d348446bSDan Carpenter unsigned int i, j; 742d348446bSDan Carpenter int retval; 7439fa32e94SEmeric Vigier u32 *data = buf; 7449fa32e94SEmeric Vigier 7459fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); 7469fa32e94SEmeric Vigier if (retval < 0) { 7479fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read ID_REV\n"); 7489fa32e94SEmeric Vigier return; 7499fa32e94SEmeric Vigier } 7509fa32e94SEmeric Vigier 7519fa32e94SEmeric Vigier for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { 7529fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, i, &data[j]); 7539fa32e94SEmeric Vigier if (retval < 0) { 7549fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); 7559fa32e94SEmeric Vigier return; 7569fa32e94SEmeric Vigier } 7579fa32e94SEmeric Vigier } 7589fa32e94SEmeric Vigier } 7599fa32e94SEmeric Vigier 760e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net, 761e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 762e0e474a8SSteve Glendinning { 763e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 764e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 765e0e474a8SSteve Glendinning 766e0e474a8SSteve Glendinning wolinfo->supported = SUPPORTED_WAKE; 767e0e474a8SSteve Glendinning wolinfo->wolopts = pdata->wolopts; 768e0e474a8SSteve Glendinning } 769e0e474a8SSteve Glendinning 770e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net, 771e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 772e0e474a8SSteve Glendinning { 773e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 774e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7753b14692cSSteve Glendinning int ret; 776e0e474a8SSteve Glendinning 777*c530c471SFlorian Fainelli if (wolinfo->wolopts & ~SUPPORTED_WAKE) 778*c530c471SFlorian Fainelli return -EINVAL; 779*c530c471SFlorian Fainelli 780e0e474a8SSteve Glendinning pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; 7813b14692cSSteve Glendinning 7823b14692cSSteve Glendinning ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); 783b052e073SSteve Glendinning if (ret < 0) 784b052e073SSteve Glendinning netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); 7853b14692cSSteve Glendinning 786b052e073SSteve Glendinning return ret; 787e0e474a8SSteve Glendinning } 788e0e474a8SSteve Glendinning 78913722bbeSWoojung Huh static int get_mdix_status(struct net_device *net) 79013722bbeSWoojung Huh { 79113722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 79213722bbeSWoojung Huh u32 val; 79313722bbeSWoojung Huh int buf; 79413722bbeSWoojung Huh 79513722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, SPECIAL_CTRL_STS); 79613722bbeSWoojung Huh if (buf & SPECIAL_CTRL_STS_OVRRD_AMDIX_) { 79713722bbeSWoojung Huh if (buf & SPECIAL_CTRL_STS_AMDIX_ENABLE_) 79813722bbeSWoojung Huh return ETH_TP_MDI_AUTO; 79913722bbeSWoojung Huh else if (buf & SPECIAL_CTRL_STS_AMDIX_STATE_) 80013722bbeSWoojung Huh return ETH_TP_MDI_X; 80113722bbeSWoojung Huh } else { 80213722bbeSWoojung Huh buf = smsc95xx_read_reg(dev, STRAP_STATUS, &val); 80313722bbeSWoojung Huh if (val & STRAP_STATUS_AMDIX_EN_) 80413722bbeSWoojung Huh return ETH_TP_MDI_AUTO; 80513722bbeSWoojung Huh } 80613722bbeSWoojung Huh 80713722bbeSWoojung Huh return ETH_TP_MDI; 80813722bbeSWoojung Huh } 80913722bbeSWoojung Huh 81013722bbeSWoojung Huh static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) 81113722bbeSWoojung Huh { 81213722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 81313722bbeSWoojung Huh struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 81413722bbeSWoojung Huh int buf; 81513722bbeSWoojung Huh 81613722bbeSWoojung Huh if ((pdata->chip_id == ID_REV_CHIP_ID_9500A_) || 81713722bbeSWoojung Huh (pdata->chip_id == ID_REV_CHIP_ID_9530_) || 81813722bbeSWoojung Huh (pdata->chip_id == ID_REV_CHIP_ID_89530_) || 81913722bbeSWoojung Huh (pdata->chip_id == ID_REV_CHIP_ID_9730_)) { 82013722bbeSWoojung Huh /* Extend Manual AutoMDIX timer for 9500A/9500Ai */ 82113722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 82213722bbeSWoojung Huh PHY_EDPD_CONFIG); 82313722bbeSWoojung Huh buf |= PHY_EDPD_CONFIG_EXT_CROSSOVER_; 82413722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 82513722bbeSWoojung Huh PHY_EDPD_CONFIG, buf); 82613722bbeSWoojung Huh } 82713722bbeSWoojung Huh 82813722bbeSWoojung Huh if (mdix_ctrl == ETH_TP_MDI) { 82913722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 83013722bbeSWoojung Huh SPECIAL_CTRL_STS); 83113722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_OVRRD_AMDIX_; 83213722bbeSWoojung Huh buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | 83313722bbeSWoojung Huh SPECIAL_CTRL_STS_AMDIX_STATE_); 83413722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 83513722bbeSWoojung Huh SPECIAL_CTRL_STS, buf); 83613722bbeSWoojung Huh } else if (mdix_ctrl == ETH_TP_MDI_X) { 83713722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 83813722bbeSWoojung Huh SPECIAL_CTRL_STS); 83913722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_OVRRD_AMDIX_; 84013722bbeSWoojung Huh buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | 84113722bbeSWoojung Huh SPECIAL_CTRL_STS_AMDIX_STATE_); 84213722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_AMDIX_STATE_; 84313722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 84413722bbeSWoojung Huh SPECIAL_CTRL_STS, buf); 84513722bbeSWoojung Huh } else if (mdix_ctrl == ETH_TP_MDI_AUTO) { 84613722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 84713722bbeSWoojung Huh SPECIAL_CTRL_STS); 84813722bbeSWoojung Huh buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_; 84913722bbeSWoojung Huh buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | 85013722bbeSWoojung Huh SPECIAL_CTRL_STS_AMDIX_STATE_); 85113722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_AMDIX_ENABLE_; 85213722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 85313722bbeSWoojung Huh SPECIAL_CTRL_STS, buf); 85413722bbeSWoojung Huh } 85513722bbeSWoojung Huh pdata->mdix_ctrl = mdix_ctrl; 85613722bbeSWoojung Huh } 85713722bbeSWoojung Huh 858eaf9a32aSPhilippe Reynes static int smsc95xx_get_link_ksettings(struct net_device *net, 859eaf9a32aSPhilippe Reynes struct ethtool_link_ksettings *cmd) 86013722bbeSWoojung Huh { 86113722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 86213722bbeSWoojung Huh struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 86313722bbeSWoojung Huh int retval; 86413722bbeSWoojung Huh 865eaf9a32aSPhilippe Reynes retval = usbnet_get_link_ksettings(net, cmd); 86613722bbeSWoojung Huh 867eaf9a32aSPhilippe Reynes cmd->base.eth_tp_mdix = pdata->mdix_ctrl; 868eaf9a32aSPhilippe Reynes cmd->base.eth_tp_mdix_ctrl = pdata->mdix_ctrl; 86913722bbeSWoojung Huh 87013722bbeSWoojung Huh return retval; 87113722bbeSWoojung Huh } 87213722bbeSWoojung Huh 873eaf9a32aSPhilippe Reynes static int smsc95xx_set_link_ksettings(struct net_device *net, 874eaf9a32aSPhilippe Reynes const struct ethtool_link_ksettings *cmd) 87513722bbeSWoojung Huh { 87613722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 87713722bbeSWoojung Huh struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 87813722bbeSWoojung Huh int retval; 87913722bbeSWoojung Huh 880eaf9a32aSPhilippe Reynes if (pdata->mdix_ctrl != cmd->base.eth_tp_mdix_ctrl) 881eaf9a32aSPhilippe Reynes set_mdix_status(net, cmd->base.eth_tp_mdix_ctrl); 88213722bbeSWoojung Huh 883eaf9a32aSPhilippe Reynes retval = usbnet_set_link_ksettings(net, cmd); 88413722bbeSWoojung Huh 88513722bbeSWoojung Huh return retval; 88613722bbeSWoojung Huh } 88713722bbeSWoojung Huh 8880fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = { 8892f7ca802SSteve Glendinning .get_link = usbnet_get_link, 8902f7ca802SSteve Glendinning .nway_reset = usbnet_nway_reset, 8912f7ca802SSteve Glendinning .get_drvinfo = usbnet_get_drvinfo, 8922f7ca802SSteve Glendinning .get_msglevel = usbnet_get_msglevel, 8932f7ca802SSteve Glendinning .set_msglevel = usbnet_set_msglevel, 8942f7ca802SSteve Glendinning .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, 8952f7ca802SSteve Glendinning .get_eeprom = smsc95xx_ethtool_get_eeprom, 8962f7ca802SSteve Glendinning .set_eeprom = smsc95xx_ethtool_set_eeprom, 8979fa32e94SEmeric Vigier .get_regs_len = smsc95xx_ethtool_getregslen, 8989fa32e94SEmeric Vigier .get_regs = smsc95xx_ethtool_getregs, 899e0e474a8SSteve Glendinning .get_wol = smsc95xx_ethtool_get_wol, 900e0e474a8SSteve Glendinning .set_wol = smsc95xx_ethtool_set_wol, 901eaf9a32aSPhilippe Reynes .get_link_ksettings = smsc95xx_get_link_ksettings, 902eaf9a32aSPhilippe Reynes .set_link_ksettings = smsc95xx_set_link_ksettings, 903a8f5cb9eSPetr Kulhavy .get_ts_info = ethtool_op_get_ts_info, 9042f7ca802SSteve Glendinning }; 9052f7ca802SSteve Glendinning 9062f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 9072f7ca802SSteve Glendinning { 9082f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 9092f7ca802SSteve Glendinning 9102f7ca802SSteve Glendinning if (!netif_running(netdev)) 9112f7ca802SSteve Glendinning return -EINVAL; 9122f7ca802SSteve Glendinning 9132f7ca802SSteve Glendinning return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 9142f7ca802SSteve Glendinning } 9152f7ca802SSteve Glendinning 9162f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev) 9172f7ca802SSteve Glendinning { 918c489565bSArnd Bergmann const u8 *mac_addr; 919c489565bSArnd Bergmann 920c489565bSArnd Bergmann /* maybe the boot loader passed the MAC address in devicetree */ 921c489565bSArnd Bergmann mac_addr = of_get_mac_address(dev->udev->dev.of_node); 922c489565bSArnd Bergmann if (mac_addr) { 923c489565bSArnd Bergmann memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN); 924c489565bSArnd Bergmann return; 925c489565bSArnd Bergmann } 926c489565bSArnd Bergmann 9272f7ca802SSteve Glendinning /* try reading mac address from EEPROM */ 9282f7ca802SSteve Glendinning if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, 9292f7ca802SSteve Glendinning dev->net->dev_addr) == 0) { 9302f7ca802SSteve Glendinning if (is_valid_ether_addr(dev->net->dev_addr)) { 9312f7ca802SSteve Glendinning /* eeprom values are valid so use them */ 932a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); 9332f7ca802SSteve Glendinning return; 9342f7ca802SSteve Glendinning } 9352f7ca802SSteve Glendinning } 9362f7ca802SSteve Glendinning 937c489565bSArnd Bergmann /* no useful static MAC address found. generate a random one */ 938f2cedb63SDanny Kukawka eth_hw_addr_random(dev->net); 939c7e12eadSJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); 9402f7ca802SSteve Glendinning } 9412f7ca802SSteve Glendinning 9422f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev) 9432f7ca802SSteve Glendinning { 9442f7ca802SSteve Glendinning u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | 9452f7ca802SSteve Glendinning dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; 9462f7ca802SSteve Glendinning u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; 9472f7ca802SSteve Glendinning int ret; 9482f7ca802SSteve Glendinning 9492f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); 950b052e073SSteve Glendinning if (ret < 0) 951b052e073SSteve Glendinning return ret; 952e360a8b4SSteve Glendinning 953e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, ADDRH, addr_hi); 9542f7ca802SSteve Glendinning } 9552f7ca802SSteve Glendinning 9562f7ca802SSteve Glendinning /* starts the TX path */ 957769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev) 9582f7ca802SSteve Glendinning { 9592f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 9602f7ca802SSteve Glendinning unsigned long flags; 961769ea6d8SSteve Glendinning int ret; 9622f7ca802SSteve Glendinning 9632f7ca802SSteve Glendinning /* Enable Tx at MAC */ 9642f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 9652f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_TXEN_; 9662f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 9672f7ca802SSteve Glendinning 968769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 969e360a8b4SSteve Glendinning if (ret < 0) 970b052e073SSteve Glendinning return ret; 9712f7ca802SSteve Glendinning 9722f7ca802SSteve Glendinning /* Enable Tx at SCSRs */ 973e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); 9742f7ca802SSteve Glendinning } 9752f7ca802SSteve Glendinning 9762f7ca802SSteve Glendinning /* Starts the Receive path */ 977ec32115dSMing Lei static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) 9782f7ca802SSteve Glendinning { 9792f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 9802f7ca802SSteve Glendinning unsigned long flags; 9812f7ca802SSteve Glendinning 9822f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 9832f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RXEN_; 9842f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 9852f7ca802SSteve Glendinning 986e360a8b4SSteve Glendinning return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm); 9872f7ca802SSteve Glendinning } 9882f7ca802SSteve Glendinning 9892f7ca802SSteve Glendinning static int smsc95xx_phy_initialize(struct usbnet *dev) 9902f7ca802SSteve Glendinning { 991769ea6d8SSteve Glendinning int bmcr, ret, timeout = 0; 992db443c44SSteve Glendinning 9932f7ca802SSteve Glendinning /* Initialize MII structure */ 9942f7ca802SSteve Glendinning dev->mii.dev = dev->net; 9952f7ca802SSteve Glendinning dev->mii.mdio_read = smsc95xx_mdio_read; 9962f7ca802SSteve Glendinning dev->mii.mdio_write = smsc95xx_mdio_write; 9972f7ca802SSteve Glendinning dev->mii.phy_id_mask = 0x1f; 9982f7ca802SSteve Glendinning dev->mii.reg_num_mask = 0x1f; 9992f7ca802SSteve Glendinning dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID; 10002f7ca802SSteve Glendinning 1001db443c44SSteve Glendinning /* reset phy and wait for reset to complete */ 10022f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 1003db443c44SSteve Glendinning 1004db443c44SSteve Glendinning do { 1005db443c44SSteve Glendinning msleep(10); 1006db443c44SSteve Glendinning bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); 1007db443c44SSteve Glendinning timeout++; 1008d9460920SRabin Vincent } while ((bmcr & BMCR_RESET) && (timeout < 100)); 1009db443c44SSteve Glendinning 1010db443c44SSteve Glendinning if (timeout >= 100) { 1011db443c44SSteve Glendinning netdev_warn(dev->net, "timeout on PHY Reset"); 1012db443c44SSteve Glendinning return -EIO; 1013db443c44SSteve Glendinning } 1014db443c44SSteve Glendinning 10152f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, 10162f7ca802SSteve Glendinning ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | 10172f7ca802SSteve Glendinning ADVERTISE_PAUSE_ASYM); 10182f7ca802SSteve Glendinning 10192f7ca802SSteve Glendinning /* read to clear */ 1020769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); 1021b052e073SSteve Glendinning if (ret < 0) { 1022b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n"); 1023b052e073SSteve Glendinning return ret; 1024b052e073SSteve Glendinning } 10252f7ca802SSteve Glendinning 10262f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, 10272f7ca802SSteve Glendinning PHY_INT_MASK_DEFAULT_); 10282f7ca802SSteve Glendinning mii_nway_restart(&dev->mii); 10292f7ca802SSteve Glendinning 1030a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); 10312f7ca802SSteve Glendinning return 0; 10322f7ca802SSteve Glendinning } 10332f7ca802SSteve Glendinning 10342f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev) 10352f7ca802SSteve Glendinning { 10362f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 10372f7ca802SSteve Glendinning u32 read_buf, write_buf, burst_cap; 10382f7ca802SSteve Glendinning int ret = 0, timeout; 10392f7ca802SSteve Glendinning 1040a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); 10412f7ca802SSteve Glendinning 10424436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); 1043e360a8b4SSteve Glendinning if (ret < 0) 1044b052e073SSteve Glendinning return ret; 10452f7ca802SSteve Glendinning 10462f7ca802SSteve Glendinning timeout = 0; 10472f7ca802SSteve Glendinning do { 1048cf2acec2SSteve Glendinning msleep(10); 10492f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1050e360a8b4SSteve Glendinning if (ret < 0) 1051b052e073SSteve Glendinning return ret; 10522f7ca802SSteve Glendinning timeout++; 10532f7ca802SSteve Glendinning } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); 10542f7ca802SSteve Glendinning 10552f7ca802SSteve Glendinning if (timeout >= 100) { 105660b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); 10572f7ca802SSteve Glendinning return ret; 10582f7ca802SSteve Glendinning } 10592f7ca802SSteve Glendinning 10604436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); 1061e360a8b4SSteve Glendinning if (ret < 0) 1062b052e073SSteve Glendinning return ret; 10632f7ca802SSteve Glendinning 10642f7ca802SSteve Glendinning timeout = 0; 10652f7ca802SSteve Glendinning do { 1066cf2acec2SSteve Glendinning msleep(10); 10672f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); 1068e360a8b4SSteve Glendinning if (ret < 0) 1069b052e073SSteve Glendinning return ret; 10702f7ca802SSteve Glendinning timeout++; 10712f7ca802SSteve Glendinning } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); 10722f7ca802SSteve Glendinning 10732f7ca802SSteve Glendinning if (timeout >= 100) { 107460b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); 10752f7ca802SSteve Glendinning return ret; 10762f7ca802SSteve Glendinning } 10772f7ca802SSteve Glendinning 10782f7ca802SSteve Glendinning ret = smsc95xx_set_mac_address(dev); 10792f7ca802SSteve Glendinning if (ret < 0) 10802f7ca802SSteve Glendinning return ret; 10812f7ca802SSteve Glendinning 10821e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", 10831e1d7412SJoe Perches dev->net->dev_addr); 10842f7ca802SSteve Glendinning 10852f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1086e360a8b4SSteve Glendinning if (ret < 0) 1087b052e073SSteve Glendinning return ret; 10882f7ca802SSteve Glendinning 10891e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", 10901e1d7412SJoe Perches read_buf); 10912f7ca802SSteve Glendinning 10922f7ca802SSteve Glendinning read_buf |= HW_CFG_BIR_; 10932f7ca802SSteve Glendinning 10942f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 1095e360a8b4SSteve Glendinning if (ret < 0) 1096b052e073SSteve Glendinning return ret; 10972f7ca802SSteve Glendinning 10982f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1099e360a8b4SSteve Glendinning if (ret < 0) 1100b052e073SSteve Glendinning return ret; 1101b052e073SSteve Glendinning 1102a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1103a475f603SJoe Perches "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", 110460b86755SJoe Perches read_buf); 11052f7ca802SSteve Glendinning 11062f7ca802SSteve Glendinning if (!turbo_mode) { 11072f7ca802SSteve Glendinning burst_cap = 0; 11082f7ca802SSteve Glendinning dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; 11092f7ca802SSteve Glendinning } else if (dev->udev->speed == USB_SPEED_HIGH) { 11102f7ca802SSteve Glendinning burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; 11112f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; 11122f7ca802SSteve Glendinning } else { 11132f7ca802SSteve Glendinning burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; 11142f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; 11152f7ca802SSteve Glendinning } 11162f7ca802SSteve Glendinning 11171e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", 11181e1d7412SJoe Perches (ulong)dev->rx_urb_size); 11192f7ca802SSteve Glendinning 11202f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); 1121e360a8b4SSteve Glendinning if (ret < 0) 1122b052e073SSteve Glendinning return ret; 11232f7ca802SSteve Glendinning 11242f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); 1125e360a8b4SSteve Glendinning if (ret < 0) 1126b052e073SSteve Glendinning return ret; 1127769ea6d8SSteve Glendinning 1128a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1129a475f603SJoe Perches "Read Value from BURST_CAP after writing: 0x%08x\n", 11302f7ca802SSteve Glendinning read_buf); 11312f7ca802SSteve Glendinning 11324436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); 1133e360a8b4SSteve Glendinning if (ret < 0) 1134b052e073SSteve Glendinning return ret; 11352f7ca802SSteve Glendinning 11362f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); 1137e360a8b4SSteve Glendinning if (ret < 0) 1138b052e073SSteve Glendinning return ret; 1139769ea6d8SSteve Glendinning 1140a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1141a475f603SJoe Perches "Read Value from BULK_IN_DLY after writing: 0x%08x\n", 114260b86755SJoe Perches read_buf); 11432f7ca802SSteve Glendinning 11442f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1145e360a8b4SSteve Glendinning if (ret < 0) 1146b052e073SSteve Glendinning return ret; 1147769ea6d8SSteve Glendinning 11481e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n", 11491e1d7412SJoe Perches read_buf); 11502f7ca802SSteve Glendinning 11512f7ca802SSteve Glendinning if (turbo_mode) 11522f7ca802SSteve Glendinning read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); 11532f7ca802SSteve Glendinning 11542f7ca802SSteve Glendinning read_buf &= ~HW_CFG_RXDOFF_; 11552f7ca802SSteve Glendinning 11562f7ca802SSteve Glendinning /* set Rx data offset=2, Make IP header aligns on word boundary. */ 11572f7ca802SSteve Glendinning read_buf |= NET_IP_ALIGN << 9; 11582f7ca802SSteve Glendinning 11592f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 1160e360a8b4SSteve Glendinning if (ret < 0) 1161b052e073SSteve Glendinning return ret; 11622f7ca802SSteve Glendinning 11632f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1164e360a8b4SSteve Glendinning if (ret < 0) 1165b052e073SSteve Glendinning return ret; 1166769ea6d8SSteve Glendinning 1167a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1168a475f603SJoe Perches "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); 11692f7ca802SSteve Glendinning 11704436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 1171e360a8b4SSteve Glendinning if (ret < 0) 1172b052e073SSteve Glendinning return ret; 11732f7ca802SSteve Glendinning 11742f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); 1175e360a8b4SSteve Glendinning if (ret < 0) 1176b052e073SSteve Glendinning return ret; 1177a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); 11782f7ca802SSteve Glendinning 1179f293501cSSteve Glendinning /* Configure GPIO pins as LED outputs */ 1180f293501cSSteve Glendinning write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | 1181f293501cSSteve Glendinning LED_GPIO_CFG_FDX_LED; 1182f293501cSSteve Glendinning ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); 1183e360a8b4SSteve Glendinning if (ret < 0) 1184b052e073SSteve Glendinning return ret; 1185f293501cSSteve Glendinning 11862f7ca802SSteve Glendinning /* Init Tx */ 11874436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, 0); 1188e360a8b4SSteve Glendinning if (ret < 0) 1189b052e073SSteve Glendinning return ret; 11902f7ca802SSteve Glendinning 11914436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); 1192e360a8b4SSteve Glendinning if (ret < 0) 1193b052e073SSteve Glendinning return ret; 11942f7ca802SSteve Glendinning 11952f7ca802SSteve Glendinning /* Don't need mac_cr_lock during initialisation */ 11962f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); 1197e360a8b4SSteve Glendinning if (ret < 0) 1198b052e073SSteve Glendinning return ret; 11992f7ca802SSteve Glendinning 12002f7ca802SSteve Glendinning /* Init Rx */ 12012f7ca802SSteve Glendinning /* Set Vlan */ 12024436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); 1203e360a8b4SSteve Glendinning if (ret < 0) 1204b052e073SSteve Glendinning return ret; 12052f7ca802SSteve Glendinning 1206f7b29271SSteve Glendinning /* Enable or disable checksum offload engines */ 1207769ea6d8SSteve Glendinning ret = smsc95xx_set_features(dev->net, dev->net->features); 1208b052e073SSteve Glendinning if (ret < 0) { 1209b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to set checksum offload features\n"); 1210b052e073SSteve Glendinning return ret; 1211b052e073SSteve Glendinning } 12122f7ca802SSteve Glendinning 12132f7ca802SSteve Glendinning smsc95xx_set_multicast(dev->net); 12142f7ca802SSteve Glendinning 1215769ea6d8SSteve Glendinning ret = smsc95xx_phy_initialize(dev); 1216b052e073SSteve Glendinning if (ret < 0) { 1217b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to init PHY\n"); 1218b052e073SSteve Glendinning return ret; 1219b052e073SSteve Glendinning } 12202f7ca802SSteve Glendinning 12212f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); 1222e360a8b4SSteve Glendinning if (ret < 0) 1223b052e073SSteve Glendinning return ret; 12242f7ca802SSteve Glendinning 12252f7ca802SSteve Glendinning /* enable PHY interrupts */ 12262f7ca802SSteve Glendinning read_buf |= INT_EP_CTL_PHY_INT_; 12272f7ca802SSteve Glendinning 12282f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); 1229e360a8b4SSteve Glendinning if (ret < 0) 1230b052e073SSteve Glendinning return ret; 12312f7ca802SSteve Glendinning 1232769ea6d8SSteve Glendinning ret = smsc95xx_start_tx_path(dev); 1233b052e073SSteve Glendinning if (ret < 0) { 1234b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start TX path\n"); 1235b052e073SSteve Glendinning return ret; 1236b052e073SSteve Glendinning } 1237769ea6d8SSteve Glendinning 1238ec32115dSMing Lei ret = smsc95xx_start_rx_path(dev, 0); 1239b052e073SSteve Glendinning if (ret < 0) { 1240b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start RX path\n"); 1241b052e073SSteve Glendinning return ret; 1242b052e073SSteve Glendinning } 12432f7ca802SSteve Glendinning 1244a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); 12452f7ca802SSteve Glendinning return 0; 12462f7ca802SSteve Glendinning } 12472f7ca802SSteve Glendinning 124863e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = { 124963e77b39SStephen Hemminger .ndo_open = usbnet_open, 125063e77b39SStephen Hemminger .ndo_stop = usbnet_stop, 125163e77b39SStephen Hemminger .ndo_start_xmit = usbnet_start_xmit, 125263e77b39SStephen Hemminger .ndo_tx_timeout = usbnet_tx_timeout, 125363e77b39SStephen Hemminger .ndo_change_mtu = usbnet_change_mtu, 1254c8b5d129SGreg Ungerer .ndo_get_stats64 = usbnet_get_stats64, 125563e77b39SStephen Hemminger .ndo_set_mac_address = eth_mac_addr, 125663e77b39SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 125763e77b39SStephen Hemminger .ndo_do_ioctl = smsc95xx_ioctl, 1258afc4b13dSJiri Pirko .ndo_set_rx_mode = smsc95xx_set_multicast, 125978e47fe4SMichał Mirosław .ndo_set_features = smsc95xx_set_features, 126063e77b39SStephen Hemminger }; 126163e77b39SStephen Hemminger 12622f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) 12632f7ca802SSteve Glendinning { 12642f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = NULL; 1265bbd9f9eeSSteve Glendinning u32 val; 12662f7ca802SSteve Glendinning int ret; 12672f7ca802SSteve Glendinning 12682f7ca802SSteve Glendinning printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); 12692f7ca802SSteve Glendinning 12702f7ca802SSteve Glendinning ret = usbnet_get_endpoints(dev, intf); 1271b052e073SSteve Glendinning if (ret < 0) { 1272b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); 1273b052e073SSteve Glendinning return ret; 1274b052e073SSteve Glendinning } 12752f7ca802SSteve Glendinning 12762f7ca802SSteve Glendinning dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), 12772f7ca802SSteve Glendinning GFP_KERNEL); 12782f7ca802SSteve Glendinning 12792f7ca802SSteve Glendinning pdata = (struct smsc95xx_priv *)(dev->data[0]); 128038673c82SJoe Perches if (!pdata) 12812f7ca802SSteve Glendinning return -ENOMEM; 12822f7ca802SSteve Glendinning 12832f7ca802SSteve Glendinning spin_lock_init(&pdata->mac_cr_lock); 12842f7ca802SSteve Glendinning 1285fe0cd8caSNisar Sayed /* LAN95xx devices do not alter the computed checksum of 0 to 0xffff. 1286fe0cd8caSNisar Sayed * RFC 2460, ipv6 UDP calculated checksum yields a result of zero must 1287fe0cd8caSNisar Sayed * be changed to 0xffff. RFC 768, ipv4 UDP computed checksum is zero, 1288fe0cd8caSNisar Sayed * it is transmitted as all ones. The zero transmitted checksum means 1289fe0cd8caSNisar Sayed * transmitter generated no checksum. Hence, enable csum offload only 1290fe0cd8caSNisar Sayed * for ipv4 packets. 1291fe0cd8caSNisar Sayed */ 129278e47fe4SMichał Mirosław if (DEFAULT_TX_CSUM_ENABLE) 1293fe0cd8caSNisar Sayed dev->net->features |= NETIF_F_IP_CSUM; 129478e47fe4SMichał Mirosław if (DEFAULT_RX_CSUM_ENABLE) 129578e47fe4SMichał Mirosław dev->net->features |= NETIF_F_RXCSUM; 129678e47fe4SMichał Mirosław 1297fe0cd8caSNisar Sayed dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM; 12982f7ca802SSteve Glendinning 1299f4e8ab7cSBernard Blackham smsc95xx_init_mac_address(dev); 1300f4e8ab7cSBernard Blackham 13012f7ca802SSteve Glendinning /* Init all registers */ 13022f7ca802SSteve Glendinning ret = smsc95xx_reset(dev); 13032f7ca802SSteve Glendinning 1304bbd9f9eeSSteve Glendinning /* detect device revision as different features may be available */ 1305bbd9f9eeSSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &val); 1306e360a8b4SSteve Glendinning if (ret < 0) 1307b052e073SSteve Glendinning return ret; 1308bbd9f9eeSSteve Glendinning val >>= 16; 130913722bbeSWoojung Huh pdata->chip_id = val; 131013722bbeSWoojung Huh pdata->mdix_ctrl = get_mdix_status(dev->net); 13119ebca507SSteve Glendinning 13129ebca507SSteve Glendinning if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || 13139ebca507SSteve Glendinning (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) 13149ebca507SSteve Glendinning pdata->features = (FEATURE_8_WAKEUP_FILTERS | 13159ebca507SSteve Glendinning FEATURE_PHY_NLP_CROSSOVER | 1316eb970ff0SMing Lei FEATURE_REMOTE_WAKEUP); 13179ebca507SSteve Glendinning else if (val == ID_REV_CHIP_ID_9512_) 13189ebca507SSteve Glendinning pdata->features = FEATURE_8_WAKEUP_FILTERS; 1319bbd9f9eeSSteve Glendinning 132063e77b39SStephen Hemminger dev->net->netdev_ops = &smsc95xx_netdev_ops; 13212f7ca802SSteve Glendinning dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 13222f7ca802SSteve Glendinning dev->net->flags |= IFF_MULTICAST; 132378e47fe4SMichał Mirosław dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 13249bbf5660SStephane Fillod dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; 1325d69d1694SChristoph Fritz 1326d69d1694SChristoph Fritz pdata->dev = dev; 1327d69d1694SChristoph Fritz INIT_DELAYED_WORK(&pdata->carrier_check, check_carrier); 1328d69d1694SChristoph Fritz schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); 1329d69d1694SChristoph Fritz 13302f7ca802SSteve Glendinning return 0; 13312f7ca802SSteve Glendinning } 13322f7ca802SSteve Glendinning 13332f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) 13342f7ca802SSteve Glendinning { 13352f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1336d69d1694SChristoph Fritz 13372f7ca802SSteve Glendinning if (pdata) { 1338d69d1694SChristoph Fritz cancel_delayed_work(&pdata->carrier_check); 1339a475f603SJoe Perches netif_dbg(dev, ifdown, dev->net, "free pdata\n"); 13402f7ca802SSteve Glendinning kfree(pdata); 13412f7ca802SSteve Glendinning pdata = NULL; 13422f7ca802SSteve Glendinning dev->data[0] = 0; 13432f7ca802SSteve Glendinning } 13442f7ca802SSteve Glendinning } 13452f7ca802SSteve Glendinning 1346068bb1a7SSteve Glendinning static u32 smsc_crc(const u8 *buffer, size_t len, int filter) 1347bbd9f9eeSSteve Glendinning { 1348068bb1a7SSteve Glendinning u32 crc = bitrev16(crc16(0xFFFF, buffer, len)); 1349068bb1a7SSteve Glendinning return crc << ((filter % 2) * 16); 1350bbd9f9eeSSteve Glendinning } 1351bbd9f9eeSSteve Glendinning 1352e5e3af83SSteve Glendinning static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) 1353e5e3af83SSteve Glendinning { 1354e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1355e5e3af83SSteve Glendinning int ret; 1356e5e3af83SSteve Glendinning 13571e1d7412SJoe Perches netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n"); 1358e5e3af83SSteve Glendinning 1359e5e3af83SSteve Glendinning /* read to clear */ 1360e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC); 1361e360a8b4SSteve Glendinning if (ret < 0) 1362b052e073SSteve Glendinning return ret; 1363e5e3af83SSteve Glendinning 1364e5e3af83SSteve Glendinning /* enable interrupt source */ 1365e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK); 1366e360a8b4SSteve Glendinning if (ret < 0) 1367b052e073SSteve Glendinning return ret; 1368e5e3af83SSteve Glendinning 1369e5e3af83SSteve Glendinning ret |= mask; 1370e5e3af83SSteve Glendinning 1371e5e3af83SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret); 1372e5e3af83SSteve Glendinning 1373e5e3af83SSteve Glendinning return 0; 1374e5e3af83SSteve Glendinning } 1375e5e3af83SSteve Glendinning 1376e5e3af83SSteve Glendinning static int smsc95xx_link_ok_nopm(struct usbnet *dev) 1377e5e3af83SSteve Glendinning { 1378e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1379e5e3af83SSteve Glendinning int ret; 1380e5e3af83SSteve Glendinning 1381e5e3af83SSteve Glendinning /* first, a dummy read, needed to latch some MII phys */ 1382e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1383e360a8b4SSteve Glendinning if (ret < 0) 1384b052e073SSteve Glendinning return ret; 1385e5e3af83SSteve Glendinning 1386e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1387e360a8b4SSteve Glendinning if (ret < 0) 1388b052e073SSteve Glendinning return ret; 1389e5e3af83SSteve Glendinning 1390e5e3af83SSteve Glendinning return !!(ret & BMSR_LSTATUS); 1391e5e3af83SSteve Glendinning } 1392e5e3af83SSteve Glendinning 1393319b95b5SSteve Glendinning static int smsc95xx_enter_suspend0(struct usbnet *dev) 1394319b95b5SSteve Glendinning { 1395319b95b5SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1396319b95b5SSteve Glendinning u32 val; 1397319b95b5SSteve Glendinning int ret; 1398319b95b5SSteve Glendinning 1399319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1400e360a8b4SSteve Glendinning if (ret < 0) 1401b052e073SSteve Glendinning return ret; 1402319b95b5SSteve Glendinning 1403319b95b5SSteve Glendinning val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); 1404319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_0; 1405319b95b5SSteve Glendinning 1406319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1407e360a8b4SSteve Glendinning if (ret < 0) 1408b052e073SSteve Glendinning return ret; 1409319b95b5SSteve Glendinning 1410319b95b5SSteve Glendinning /* clear wol status */ 1411319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1412319b95b5SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1413319b95b5SSteve Glendinning 1414319b95b5SSteve Glendinning /* enable energy detection */ 1415319b95b5SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1416319b95b5SSteve Glendinning val |= PM_CTL_WUPS_ED_; 1417319b95b5SSteve Glendinning 1418319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1419e360a8b4SSteve Glendinning if (ret < 0) 1420b052e073SSteve Glendinning return ret; 1421319b95b5SSteve Glendinning 1422319b95b5SSteve Glendinning /* read back PM_CTRL */ 1423319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 142476437214SMing Lei if (ret < 0) 142576437214SMing Lei return ret; 1426319b95b5SSteve Glendinning 1427b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND0; 1428b2d4b150SSteve Glendinning 142976437214SMing Lei return 0; 1430319b95b5SSteve Glendinning } 1431319b95b5SSteve Glendinning 1432319b95b5SSteve Glendinning static int smsc95xx_enter_suspend1(struct usbnet *dev) 1433319b95b5SSteve Glendinning { 1434319b95b5SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1435319b95b5SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1436319b95b5SSteve Glendinning u32 val; 1437319b95b5SSteve Glendinning int ret; 1438319b95b5SSteve Glendinning 1439319b95b5SSteve Glendinning /* reconfigure link pulse detection timing for 1440319b95b5SSteve Glendinning * compatibility with non-standard link partners 1441319b95b5SSteve Glendinning */ 1442319b95b5SSteve Glendinning if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) 1443319b95b5SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG, 1444319b95b5SSteve Glendinning PHY_EDPD_CONFIG_DEFAULT); 1445319b95b5SSteve Glendinning 1446319b95b5SSteve Glendinning /* enable energy detect power-down mode */ 1447319b95b5SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS); 1448e360a8b4SSteve Glendinning if (ret < 0) 1449b052e073SSteve Glendinning return ret; 1450319b95b5SSteve Glendinning 1451319b95b5SSteve Glendinning ret |= MODE_CTRL_STS_EDPWRDOWN_; 1452319b95b5SSteve Glendinning 1453319b95b5SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret); 1454319b95b5SSteve Glendinning 1455319b95b5SSteve Glendinning /* enter SUSPEND1 mode */ 1456319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1457e360a8b4SSteve Glendinning if (ret < 0) 1458b052e073SSteve Glendinning return ret; 1459319b95b5SSteve Glendinning 1460319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1461319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_1; 1462319b95b5SSteve Glendinning 1463319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1464e360a8b4SSteve Glendinning if (ret < 0) 1465b052e073SSteve Glendinning return ret; 1466319b95b5SSteve Glendinning 1467319b95b5SSteve Glendinning /* clear wol status, enable energy detection */ 1468319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1469319b95b5SSteve Glendinning val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); 1470319b95b5SSteve Glendinning 1471319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 147276437214SMing Lei if (ret < 0) 147376437214SMing Lei return ret; 1474319b95b5SSteve Glendinning 1475b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND1; 1476b2d4b150SSteve Glendinning 147776437214SMing Lei return 0; 1478319b95b5SSteve Glendinning } 1479319b95b5SSteve Glendinning 1480319b95b5SSteve Glendinning static int smsc95xx_enter_suspend2(struct usbnet *dev) 1481319b95b5SSteve Glendinning { 1482b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1483319b95b5SSteve Glendinning u32 val; 1484319b95b5SSteve Glendinning int ret; 1485319b95b5SSteve Glendinning 1486319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1487e360a8b4SSteve Glendinning if (ret < 0) 1488b052e073SSteve Glendinning return ret; 1489319b95b5SSteve Glendinning 1490319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1491319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_2; 1492319b95b5SSteve Glendinning 1493319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 149476437214SMing Lei if (ret < 0) 149576437214SMing Lei return ret; 1496319b95b5SSteve Glendinning 1497b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND2; 1498b2d4b150SSteve Glendinning 149976437214SMing Lei return 0; 1500319b95b5SSteve Glendinning } 1501319b95b5SSteve Glendinning 1502b2d4b150SSteve Glendinning static int smsc95xx_enter_suspend3(struct usbnet *dev) 1503b2d4b150SSteve Glendinning { 1504b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1505b2d4b150SSteve Glendinning u32 val; 1506b2d4b150SSteve Glendinning int ret; 1507b2d4b150SSteve Glendinning 1508b2d4b150SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val); 1509b2d4b150SSteve Glendinning if (ret < 0) 1510b2d4b150SSteve Glendinning return ret; 1511b2d4b150SSteve Glendinning 151253a759c8SMartin Wetterwald if (val & RX_FIFO_INF_USED_) { 1513b2d4b150SSteve Glendinning netdev_info(dev->net, "rx fifo not empty in autosuspend\n"); 1514b2d4b150SSteve Glendinning return -EBUSY; 1515b2d4b150SSteve Glendinning } 1516b2d4b150SSteve Glendinning 1517b2d4b150SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1518b2d4b150SSteve Glendinning if (ret < 0) 1519b2d4b150SSteve Glendinning return ret; 1520b2d4b150SSteve Glendinning 1521b2d4b150SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1522b2d4b150SSteve Glendinning val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS; 1523b2d4b150SSteve Glendinning 1524b2d4b150SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1525b2d4b150SSteve Glendinning if (ret < 0) 1526b2d4b150SSteve Glendinning return ret; 1527b2d4b150SSteve Glendinning 1528b2d4b150SSteve Glendinning /* clear wol status */ 1529b2d4b150SSteve Glendinning val &= ~PM_CTL_WUPS_; 1530b2d4b150SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1531b2d4b150SSteve Glendinning 1532b2d4b150SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1533b2d4b150SSteve Glendinning if (ret < 0) 1534b2d4b150SSteve Glendinning return ret; 1535b2d4b150SSteve Glendinning 1536b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND3; 1537b2d4b150SSteve Glendinning 1538b2d4b150SSteve Glendinning return 0; 1539b2d4b150SSteve Glendinning } 1540b2d4b150SSteve Glendinning 1541b2d4b150SSteve Glendinning static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up) 1542b2d4b150SSteve Glendinning { 1543b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1544b2d4b150SSteve Glendinning int ret; 1545b2d4b150SSteve Glendinning 1546b2d4b150SSteve Glendinning if (!netif_running(dev->net)) { 1547b2d4b150SSteve Glendinning /* interface is ifconfig down so fully power down hw */ 1548b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n"); 1549b2d4b150SSteve Glendinning return smsc95xx_enter_suspend2(dev); 1550b2d4b150SSteve Glendinning } 1551b2d4b150SSteve Glendinning 1552b2d4b150SSteve Glendinning if (!link_up) { 1553b2d4b150SSteve Glendinning /* link is down so enter EDPD mode, but only if device can 1554b2d4b150SSteve Glendinning * reliably resume from it. This check should be redundant 1555eb970ff0SMing Lei * as current FEATURE_REMOTE_WAKEUP parts also support 1556b2d4b150SSteve Glendinning * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */ 1557b2d4b150SSteve Glendinning if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) { 1558b2d4b150SSteve Glendinning netdev_warn(dev->net, "EDPD not supported\n"); 1559b2d4b150SSteve Glendinning return -EBUSY; 1560b2d4b150SSteve Glendinning } 1561b2d4b150SSteve Glendinning 1562b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n"); 1563b2d4b150SSteve Glendinning 1564b2d4b150SSteve Glendinning /* enable PHY wakeup events for if cable is attached */ 1565b2d4b150SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1566b2d4b150SSteve Glendinning PHY_INT_MASK_ANEG_COMP_); 1567b2d4b150SSteve Glendinning if (ret < 0) { 1568b2d4b150SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1569b2d4b150SSteve Glendinning return ret; 1570b2d4b150SSteve Glendinning } 1571b2d4b150SSteve Glendinning 1572b2d4b150SSteve Glendinning netdev_info(dev->net, "entering SUSPEND1 mode\n"); 1573b2d4b150SSteve Glendinning return smsc95xx_enter_suspend1(dev); 1574b2d4b150SSteve Glendinning } 1575b2d4b150SSteve Glendinning 1576b2d4b150SSteve Glendinning /* enable PHY wakeup events so we remote wakeup if cable is pulled */ 1577b2d4b150SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1578b2d4b150SSteve Glendinning PHY_INT_MASK_LINK_DOWN_); 1579b2d4b150SSteve Glendinning if (ret < 0) { 1580b2d4b150SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1581b2d4b150SSteve Glendinning return ret; 1582b2d4b150SSteve Glendinning } 1583b2d4b150SSteve Glendinning 1584b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n"); 1585b2d4b150SSteve Glendinning return smsc95xx_enter_suspend3(dev); 1586b2d4b150SSteve Glendinning } 1587b2d4b150SSteve Glendinning 1588b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) 1589b5a04475SSteve Glendinning { 1590b5a04475SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1591e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1592e5e3af83SSteve Glendinning u32 val, link_up; 1593b5a04475SSteve Glendinning int ret; 1594b5a04475SSteve Glendinning 1595b5a04475SSteve Glendinning ret = usbnet_suspend(intf, message); 1596b052e073SSteve Glendinning if (ret < 0) { 1597b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_suspend error\n"); 1598b052e073SSteve Glendinning return ret; 1599b052e073SSteve Glendinning } 1600b5a04475SSteve Glendinning 1601b2d4b150SSteve Glendinning if (pdata->suspend_flags) { 1602b2d4b150SSteve Glendinning netdev_warn(dev->net, "error during last resume\n"); 1603b2d4b150SSteve Glendinning pdata->suspend_flags = 0; 1604b2d4b150SSteve Glendinning } 1605b2d4b150SSteve Glendinning 1606e5e3af83SSteve Glendinning /* determine if link is up using only _nopm functions */ 1607e5e3af83SSteve Glendinning link_up = smsc95xx_link_ok_nopm(dev); 1608e5e3af83SSteve Glendinning 160942e21c01SMing Lei if (message.event == PM_EVENT_AUTO_SUSPEND && 1610eb970ff0SMing Lei (pdata->features & FEATURE_REMOTE_WAKEUP)) { 1611b2d4b150SSteve Glendinning ret = smsc95xx_autosuspend(dev, link_up); 1612b2d4b150SSteve Glendinning goto done; 1613b2d4b150SSteve Glendinning } 1614b2d4b150SSteve Glendinning 1615b2d4b150SSteve Glendinning /* if we get this far we're not autosuspending */ 1616e5e3af83SSteve Glendinning /* if no wol options set, or if link is down and we're not waking on 1617e5e3af83SSteve Glendinning * PHY activity, enter lowest power SUSPEND2 mode 1618e5e3af83SSteve Glendinning */ 1619e5e3af83SSteve Glendinning if (!(pdata->wolopts & SUPPORTED_WAKE) || 1620e5e3af83SSteve Glendinning !(link_up || (pdata->wolopts & WAKE_PHY))) { 16211e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND2 mode\n"); 1622b5a04475SSteve Glendinning 1623e0e474a8SSteve Glendinning /* disable energy detect (link up) & wake up events */ 1624ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1625e360a8b4SSteve Glendinning if (ret < 0) 1626b052e073SSteve Glendinning goto done; 1627e0e474a8SSteve Glendinning 1628e0e474a8SSteve Glendinning val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); 1629e0e474a8SSteve Glendinning 1630ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1631e360a8b4SSteve Glendinning if (ret < 0) 1632b052e073SSteve Glendinning goto done; 1633e0e474a8SSteve Glendinning 1634ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1635e360a8b4SSteve Glendinning if (ret < 0) 1636b052e073SSteve Glendinning goto done; 1637e0e474a8SSteve Glendinning 1638e0e474a8SSteve Glendinning val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); 1639e0e474a8SSteve Glendinning 1640ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1641e360a8b4SSteve Glendinning if (ret < 0) 1642b052e073SSteve Glendinning goto done; 1643e0e474a8SSteve Glendinning 16443b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend2(dev); 16453b9f7d8cSSteve Glendinning goto done; 1646b5a04475SSteve Glendinning } 1647b5a04475SSteve Glendinning 1648e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) { 1649e5e3af83SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1650e5e3af83SSteve Glendinning (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_)); 1651b052e073SSteve Glendinning if (ret < 0) { 1652b052e073SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1653b052e073SSteve Glendinning goto done; 1654b052e073SSteve Glendinning } 1655e5e3af83SSteve Glendinning 1656e5e3af83SSteve Glendinning /* if link is down then configure EDPD and enter SUSPEND1, 1657e5e3af83SSteve Glendinning * otherwise enter SUSPEND0 below 1658e5e3af83SSteve Glendinning */ 1659e5e3af83SSteve Glendinning if (!link_up) { 16601e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND1 mode\n"); 16613b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend1(dev); 16623b9f7d8cSSteve Glendinning goto done; 1663e5e3af83SSteve Glendinning } 1664e5e3af83SSteve Glendinning } 1665e5e3af83SSteve Glendinning 1666bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 16676396bb22SKees Cook u32 *filter_mask = kcalloc(32, sizeof(u32), GFP_KERNEL); 166806a221beSMing Lei u32 command[2]; 166906a221beSMing Lei u32 offset[2]; 167006a221beSMing Lei u32 crc[4]; 16719ebca507SSteve Glendinning int wuff_filter_count = 16729ebca507SSteve Glendinning (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? 16739ebca507SSteve Glendinning LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; 1674bbd9f9eeSSteve Glendinning int i, filter = 0; 1675bbd9f9eeSSteve Glendinning 1676eed9a729SSteve Glendinning if (!filter_mask) { 1677eed9a729SSteve Glendinning netdev_warn(dev->net, "Unable to allocate filter_mask\n"); 16783b9f7d8cSSteve Glendinning ret = -ENOMEM; 16793b9f7d8cSSteve Glendinning goto done; 1680eed9a729SSteve Glendinning } 1681eed9a729SSteve Glendinning 168206a221beSMing Lei memset(command, 0, sizeof(command)); 168306a221beSMing Lei memset(offset, 0, sizeof(offset)); 168406a221beSMing Lei memset(crc, 0, sizeof(crc)); 168506a221beSMing Lei 1686bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_BCAST) { 1687bbd9f9eeSSteve Glendinning const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 16881e1d7412SJoe Perches netdev_info(dev->net, "enabling broadcast detection\n"); 1689bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1690bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1691bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1692bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1693bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1694bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1695bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(bcast, 6, filter); 1696bbd9f9eeSSteve Glendinning filter++; 1697bbd9f9eeSSteve Glendinning } 1698bbd9f9eeSSteve Glendinning 1699bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_MCAST) { 1700bbd9f9eeSSteve Glendinning const u8 mcast[] = {0x01, 0x00, 0x5E}; 17011e1d7412SJoe Perches netdev_info(dev->net, "enabling multicast detection\n"); 1702bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0007; 1703bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1704bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1705bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1706bbd9f9eeSSteve Glendinning command[filter/4] |= 0x09UL << ((filter % 4) * 8); 1707bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1708bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(mcast, 3, filter); 1709bbd9f9eeSSteve Glendinning filter++; 1710bbd9f9eeSSteve Glendinning } 1711bbd9f9eeSSteve Glendinning 1712bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_ARP) { 1713bbd9f9eeSSteve Glendinning const u8 arp[] = {0x08, 0x06}; 17141e1d7412SJoe Perches netdev_info(dev->net, "enabling ARP detection\n"); 1715bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0003; 1716bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1717bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1718bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1719bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1720bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x0C << ((filter % 4) * 8); 1721bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(arp, 2, filter); 1722bbd9f9eeSSteve Glendinning filter++; 1723bbd9f9eeSSteve Glendinning } 1724bbd9f9eeSSteve Glendinning 1725bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_UCAST) { 17261e1d7412SJoe Perches netdev_info(dev->net, "enabling unicast detection\n"); 1727bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1728bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1729bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1730bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1731bbd9f9eeSSteve Glendinning command[filter/4] |= 0x01UL << ((filter % 4) * 8); 1732bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1733bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); 1734bbd9f9eeSSteve Glendinning filter++; 1735bbd9f9eeSSteve Glendinning } 1736bbd9f9eeSSteve Glendinning 17379ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count * 4); i++) { 1738ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]); 1739b052e073SSteve Glendinning if (ret < 0) { 174006a221beSMing Lei kfree(filter_mask); 1741b052e073SSteve Glendinning goto done; 1742b052e073SSteve Glendinning } 1743bbd9f9eeSSteve Glendinning } 174406a221beSMing Lei kfree(filter_mask); 1745bbd9f9eeSSteve Glendinning 17469ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1747ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]); 1748e360a8b4SSteve Glendinning if (ret < 0) 1749b052e073SSteve Glendinning goto done; 1750b052e073SSteve Glendinning } 1751bbd9f9eeSSteve Glendinning 17529ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1753ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]); 1754e360a8b4SSteve Glendinning if (ret < 0) 1755b052e073SSteve Glendinning goto done; 1756b052e073SSteve Glendinning } 1757bbd9f9eeSSteve Glendinning 17589ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 2); i++) { 1759ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]); 1760e360a8b4SSteve Glendinning if (ret < 0) 1761b052e073SSteve Glendinning goto done; 1762b052e073SSteve Glendinning } 1763bbd9f9eeSSteve Glendinning 1764bbd9f9eeSSteve Glendinning /* clear any pending pattern match packet status */ 1765ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1766e360a8b4SSteve Glendinning if (ret < 0) 1767b052e073SSteve Glendinning goto done; 1768bbd9f9eeSSteve Glendinning 1769bbd9f9eeSSteve Glendinning val |= WUCSR_WUFR_; 1770bbd9f9eeSSteve Glendinning 1771ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1772e360a8b4SSteve Glendinning if (ret < 0) 1773b052e073SSteve Glendinning goto done; 1774b052e073SSteve Glendinning } 1775bbd9f9eeSSteve Glendinning 1776e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1777e0e474a8SSteve Glendinning /* clear any pending magic packet status */ 1778ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1779e360a8b4SSteve Glendinning if (ret < 0) 1780b052e073SSteve Glendinning goto done; 1781e0e474a8SSteve Glendinning 1782e0e474a8SSteve Glendinning val |= WUCSR_MPR_; 1783e0e474a8SSteve Glendinning 1784ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1785e360a8b4SSteve Glendinning if (ret < 0) 1786b052e073SSteve Glendinning goto done; 1787b052e073SSteve Glendinning } 1788e0e474a8SSteve Glendinning 1789bbd9f9eeSSteve Glendinning /* enable/disable wakeup sources */ 1790ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1791e360a8b4SSteve Glendinning if (ret < 0) 1792b052e073SSteve Glendinning goto done; 1793e0e474a8SSteve Glendinning 1794bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 17951e1d7412SJoe Perches netdev_info(dev->net, "enabling pattern match wakeup\n"); 1796bbd9f9eeSSteve Glendinning val |= WUCSR_WAKE_EN_; 1797bbd9f9eeSSteve Glendinning } else { 17981e1d7412SJoe Perches netdev_info(dev->net, "disabling pattern match wakeup\n"); 1799bbd9f9eeSSteve Glendinning val &= ~WUCSR_WAKE_EN_; 1800bbd9f9eeSSteve Glendinning } 1801bbd9f9eeSSteve Glendinning 1802e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 18031e1d7412SJoe Perches netdev_info(dev->net, "enabling magic packet wakeup\n"); 1804e0e474a8SSteve Glendinning val |= WUCSR_MPEN_; 1805e0e474a8SSteve Glendinning } else { 18061e1d7412SJoe Perches netdev_info(dev->net, "disabling magic packet wakeup\n"); 1807e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1808e0e474a8SSteve Glendinning } 1809e0e474a8SSteve Glendinning 1810ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1811e360a8b4SSteve Glendinning if (ret < 0) 1812b052e073SSteve Glendinning goto done; 1813e0e474a8SSteve Glendinning 1814e0e474a8SSteve Glendinning /* enable wol wakeup source */ 1815ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1816e360a8b4SSteve Glendinning if (ret < 0) 1817b052e073SSteve Glendinning goto done; 1818e0e474a8SSteve Glendinning 1819e0e474a8SSteve Glendinning val |= PM_CTL_WOL_EN_; 1820e0e474a8SSteve Glendinning 1821e5e3af83SSteve Glendinning /* phy energy detect wakeup source */ 1822e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1823e5e3af83SSteve Glendinning val |= PM_CTL_ED_EN_; 1824e5e3af83SSteve Glendinning 1825ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1826e360a8b4SSteve Glendinning if (ret < 0) 1827b052e073SSteve Glendinning goto done; 1828e0e474a8SSteve Glendinning 1829bbd9f9eeSSteve Glendinning /* enable receiver to enable frame reception */ 1830ec32115dSMing Lei smsc95xx_start_rx_path(dev, 1); 1831e0e474a8SSteve Glendinning 1832e0e474a8SSteve Glendinning /* some wol options are enabled, so enter SUSPEND0 */ 18331e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND0 mode\n"); 18343b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend0(dev); 18353b9f7d8cSSteve Glendinning 18363b9f7d8cSSteve Glendinning done: 18370d41be53SMing Lei /* 18380d41be53SMing Lei * TODO: resume() might need to handle the suspend failure 18390d41be53SMing Lei * in system sleep 18400d41be53SMing Lei */ 18410d41be53SMing Lei if (ret && PMSG_IS_AUTO(message)) 18423b9f7d8cSSteve Glendinning usbnet_resume(intf); 18433b9f7d8cSSteve Glendinning return ret; 1844e0e474a8SSteve Glendinning } 1845e0e474a8SSteve Glendinning 1846e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf) 1847e0e474a8SSteve Glendinning { 1848e0e474a8SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 18498bca81d9SSudip Mukherjee struct smsc95xx_priv *pdata; 18508bca81d9SSudip Mukherjee u8 suspend_flags; 1851e0e474a8SSteve Glendinning int ret; 1852e0e474a8SSteve Glendinning u32 val; 1853e0e474a8SSteve Glendinning 1854e0e474a8SSteve Glendinning BUG_ON(!dev); 18558bca81d9SSudip Mukherjee pdata = (struct smsc95xx_priv *)(dev->data[0]); 18568bca81d9SSudip Mukherjee suspend_flags = pdata->suspend_flags; 1857e0e474a8SSteve Glendinning 1858b2d4b150SSteve Glendinning netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags); 1859b2d4b150SSteve Glendinning 1860b2d4b150SSteve Glendinning /* do this first to ensure it's cleared even in error case */ 1861b2d4b150SSteve Glendinning pdata->suspend_flags = 0; 1862d69d1694SChristoph Fritz schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); 1863b2d4b150SSteve Glendinning 1864b2d4b150SSteve Glendinning if (suspend_flags & SUSPEND_ALLMODES) { 1865bbd9f9eeSSteve Glendinning /* clear wake-up sources */ 1866ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1867e360a8b4SSteve Glendinning if (ret < 0) 1868b052e073SSteve Glendinning return ret; 1869e0e474a8SSteve Glendinning 1870bbd9f9eeSSteve Glendinning val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); 1871e0e474a8SSteve Glendinning 1872ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1873e360a8b4SSteve Glendinning if (ret < 0) 1874b052e073SSteve Glendinning return ret; 1875e0e474a8SSteve Glendinning 1876e0e474a8SSteve Glendinning /* clear wake-up status */ 1877ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1878e360a8b4SSteve Glendinning if (ret < 0) 1879b052e073SSteve Glendinning return ret; 1880e0e474a8SSteve Glendinning 1881e0e474a8SSteve Glendinning val &= ~PM_CTL_WOL_EN_; 1882e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_; 1883e0e474a8SSteve Glendinning 1884ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1885e360a8b4SSteve Glendinning if (ret < 0) 1886b052e073SSteve Glendinning return ret; 1887b052e073SSteve Glendinning } 1888e0e474a8SSteve Glendinning 1889af3d7c1eSSteve Glendinning ret = usbnet_resume(intf); 1890b052e073SSteve Glendinning if (ret < 0) 1891b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_resume error\n"); 1892e0e474a8SSteve Glendinning 1893b052e073SSteve Glendinning return ret; 1894e0e474a8SSteve Glendinning } 1895e0e474a8SSteve Glendinning 1896b4df480fSJoonyoung Shim static int smsc95xx_reset_resume(struct usb_interface *intf) 1897b4df480fSJoonyoung Shim { 1898b4df480fSJoonyoung Shim struct usbnet *dev = usb_get_intfdata(intf); 1899b4df480fSJoonyoung Shim int ret; 1900b4df480fSJoonyoung Shim 1901b4df480fSJoonyoung Shim ret = smsc95xx_reset(dev); 1902b4df480fSJoonyoung Shim if (ret < 0) 1903b4df480fSJoonyoung Shim return ret; 1904b4df480fSJoonyoung Shim 1905b4df480fSJoonyoung Shim return smsc95xx_resume(intf); 1906b4df480fSJoonyoung Shim } 1907b4df480fSJoonyoung Shim 19082f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb) 19092f7ca802SSteve Glendinning { 19102f7ca802SSteve Glendinning skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); 19112f7ca802SSteve Glendinning skb->ip_summed = CHECKSUM_COMPLETE; 19122f7ca802SSteve Glendinning skb_trim(skb, skb->len - 2); 19132f7ca802SSteve Glendinning } 19142f7ca802SSteve Glendinning 19152f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 19162f7ca802SSteve Glendinning { 1917eb85569fSEmil Goode /* This check is no longer done by usbnet */ 1918eb85569fSEmil Goode if (skb->len < dev->net->hard_header_len) 1919eb85569fSEmil Goode return 0; 1920eb85569fSEmil Goode 19212f7ca802SSteve Glendinning while (skb->len > 0) { 19222f7ca802SSteve Glendinning u32 header, align_count; 19232f7ca802SSteve Glendinning struct sk_buff *ax_skb; 19242f7ca802SSteve Glendinning unsigned char *packet; 19252f7ca802SSteve Glendinning u16 size; 19262f7ca802SSteve Glendinning 19272f7ca802SSteve Glendinning memcpy(&header, skb->data, sizeof(header)); 19282f7ca802SSteve Glendinning le32_to_cpus(&header); 19292f7ca802SSteve Glendinning skb_pull(skb, 4 + NET_IP_ALIGN); 19302f7ca802SSteve Glendinning packet = skb->data; 19312f7ca802SSteve Glendinning 19322f7ca802SSteve Glendinning /* get the packet length */ 19332f7ca802SSteve Glendinning size = (u16)((header & RX_STS_FL_) >> 16); 19342f7ca802SSteve Glendinning align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 19352f7ca802SSteve Glendinning 19362f7ca802SSteve Glendinning if (unlikely(header & RX_STS_ES_)) { 1937a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1938a475f603SJoe Perches "Error header=0x%08x\n", header); 193980667ac1SHerbert Xu dev->net->stats.rx_errors++; 194080667ac1SHerbert Xu dev->net->stats.rx_dropped++; 19412f7ca802SSteve Glendinning 19422f7ca802SSteve Glendinning if (header & RX_STS_CRC_) { 194380667ac1SHerbert Xu dev->net->stats.rx_crc_errors++; 19442f7ca802SSteve Glendinning } else { 19452f7ca802SSteve Glendinning if (header & (RX_STS_TL_ | RX_STS_RF_)) 194680667ac1SHerbert Xu dev->net->stats.rx_frame_errors++; 19472f7ca802SSteve Glendinning 19482f7ca802SSteve Glendinning if ((header & RX_STS_LE_) && 19492f7ca802SSteve Glendinning (!(header & RX_STS_FT_))) 195080667ac1SHerbert Xu dev->net->stats.rx_length_errors++; 19512f7ca802SSteve Glendinning } 19522f7ca802SSteve Glendinning } else { 19532f7ca802SSteve Glendinning /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ 19542f7ca802SSteve Glendinning if (unlikely(size > (ETH_FRAME_LEN + 12))) { 1955a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1956a475f603SJoe Perches "size err header=0x%08x\n", header); 19572f7ca802SSteve Glendinning return 0; 19582f7ca802SSteve Glendinning } 19592f7ca802SSteve Glendinning 19602f7ca802SSteve Glendinning /* last frame in this batch */ 19612f7ca802SSteve Glendinning if (skb->len == size) { 196278e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 19632f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(skb); 1964df18accaSPeter Korsgaard skb_trim(skb, skb->len - 4); /* remove fcs */ 19652f7ca802SSteve Glendinning skb->truesize = size + sizeof(struct sk_buff); 19662f7ca802SSteve Glendinning 19672f7ca802SSteve Glendinning return 1; 19682f7ca802SSteve Glendinning } 19692f7ca802SSteve Glendinning 19702f7ca802SSteve Glendinning ax_skb = skb_clone(skb, GFP_ATOMIC); 19712f7ca802SSteve Glendinning if (unlikely(!ax_skb)) { 197260b86755SJoe Perches netdev_warn(dev->net, "Error allocating skb\n"); 19732f7ca802SSteve Glendinning return 0; 19742f7ca802SSteve Glendinning } 19752f7ca802SSteve Glendinning 19762f7ca802SSteve Glendinning ax_skb->len = size; 19772f7ca802SSteve Glendinning ax_skb->data = packet; 19782f7ca802SSteve Glendinning skb_set_tail_pointer(ax_skb, size); 19792f7ca802SSteve Glendinning 198078e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 19812f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(ax_skb); 1982df18accaSPeter Korsgaard skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 19832f7ca802SSteve Glendinning ax_skb->truesize = size + sizeof(struct sk_buff); 19842f7ca802SSteve Glendinning 19852f7ca802SSteve Glendinning usbnet_skb_return(dev, ax_skb); 19862f7ca802SSteve Glendinning } 19872f7ca802SSteve Glendinning 19882f7ca802SSteve Glendinning skb_pull(skb, size); 19892f7ca802SSteve Glendinning 19902f7ca802SSteve Glendinning /* padding bytes before the next frame starts */ 19912f7ca802SSteve Glendinning if (skb->len) 19922f7ca802SSteve Glendinning skb_pull(skb, align_count); 19932f7ca802SSteve Glendinning } 19942f7ca802SSteve Glendinning 19952f7ca802SSteve Glendinning return 1; 19962f7ca802SSteve Glendinning } 19972f7ca802SSteve Glendinning 1998f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) 1999f7b29271SSteve Glendinning { 200055508d60SMichał Mirosław u16 low_16 = (u16)skb_checksum_start_offset(skb); 200155508d60SMichał Mirosław u16 high_16 = low_16 + skb->csum_offset; 2002f7b29271SSteve Glendinning return (high_16 << 16) | low_16; 2003f7b29271SSteve Glendinning } 2004f7b29271SSteve Glendinning 20052f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 20062f7ca802SSteve Glendinning struct sk_buff *skb, gfp_t flags) 20072f7ca802SSteve Glendinning { 200878e47fe4SMichał Mirosław bool csum = skb->ip_summed == CHECKSUM_PARTIAL; 2009f7b29271SSteve Glendinning int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; 20102f7ca802SSteve Glendinning u32 tx_cmd_a, tx_cmd_b; 20112f7ca802SSteve Glendinning 2012f7b29271SSteve Glendinning /* We do not advertise SG, so skbs should be already linearized */ 2013f7b29271SSteve Glendinning BUG_ON(skb_shinfo(skb)->nr_frags); 2014f7b29271SSteve Glendinning 2015e9156cd2SJames Hughes /* Make writable and expand header space by overhead if required */ 2016e9156cd2SJames Hughes if (skb_cow_head(skb, overhead)) { 2017e9156cd2SJames Hughes /* Must deallocate here as returning NULL to indicate error 2018e9156cd2SJames Hughes * means the skb won't be deallocated in the caller. 2019e9156cd2SJames Hughes */ 20202f7ca802SSteve Glendinning dev_kfree_skb_any(skb); 20212f7ca802SSteve Glendinning return NULL; 20222f7ca802SSteve Glendinning } 20232f7ca802SSteve Glendinning 2024f7b29271SSteve Glendinning if (csum) { 202511bc3088SSteve Glendinning if (skb->len <= 45) { 202611bc3088SSteve Glendinning /* workaround - hardware tx checksum does not work 202711bc3088SSteve Glendinning * properly with extremely small packets */ 202855508d60SMichał Mirosław long csstart = skb_checksum_start_offset(skb); 202911bc3088SSteve Glendinning __wsum calc = csum_partial(skb->data + csstart, 203011bc3088SSteve Glendinning skb->len - csstart, 0); 203111bc3088SSteve Glendinning *((__sum16 *)(skb->data + csstart 203211bc3088SSteve Glendinning + skb->csum_offset)) = csum_fold(calc); 203311bc3088SSteve Glendinning 203411bc3088SSteve Glendinning csum = false; 203511bc3088SSteve Glendinning } else { 2036f7b29271SSteve Glendinning u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); 2037f7b29271SSteve Glendinning skb_push(skb, 4); 203800acda68SSteve Glendinning cpu_to_le32s(&csum_preamble); 2039f7b29271SSteve Glendinning memcpy(skb->data, &csum_preamble, 4); 2040f7b29271SSteve Glendinning } 204111bc3088SSteve Glendinning } 2042f7b29271SSteve Glendinning 20432f7ca802SSteve Glendinning skb_push(skb, 4); 20442f7ca802SSteve Glendinning tx_cmd_b = (u32)(skb->len - 4); 2045f7b29271SSteve Glendinning if (csum) 2046f7b29271SSteve Glendinning tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; 20472f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_b); 20482f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_b, 4); 20492f7ca802SSteve Glendinning 20502f7ca802SSteve Glendinning skb_push(skb, 4); 20512f7ca802SSteve Glendinning tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ | 20522f7ca802SSteve Glendinning TX_CMD_A_LAST_SEG_; 20532f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_a); 20542f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_a, 4); 20552f7ca802SSteve Glendinning 20562f7ca802SSteve Glendinning return skb; 20572f7ca802SSteve Glendinning } 20582f7ca802SSteve Glendinning 2059b2d4b150SSteve Glendinning static int smsc95xx_manage_power(struct usbnet *dev, int on) 2060b2d4b150SSteve Glendinning { 2061b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 2062b2d4b150SSteve Glendinning 2063b2d4b150SSteve Glendinning dev->intf->needs_remote_wakeup = on; 2064b2d4b150SSteve Glendinning 2065eb970ff0SMing Lei if (pdata->features & FEATURE_REMOTE_WAKEUP) 2066b2d4b150SSteve Glendinning return 0; 2067b2d4b150SSteve Glendinning 2068eb970ff0SMing Lei /* this chip revision isn't capable of remote wakeup */ 2069eb970ff0SMing Lei netdev_info(dev->net, "hardware isn't capable of remote wakeup\n"); 2070b2d4b150SSteve Glendinning 2071b2d4b150SSteve Glendinning if (on) 2072b2d4b150SSteve Glendinning usb_autopm_get_interface_no_resume(dev->intf); 2073b2d4b150SSteve Glendinning else 2074b2d4b150SSteve Glendinning usb_autopm_put_interface(dev->intf); 2075b2d4b150SSteve Glendinning 2076b2d4b150SSteve Glendinning return 0; 2077b2d4b150SSteve Glendinning } 2078b2d4b150SSteve Glendinning 20792f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = { 20802f7ca802SSteve Glendinning .description = "smsc95xx USB 2.0 Ethernet", 20812f7ca802SSteve Glendinning .bind = smsc95xx_bind, 20822f7ca802SSteve Glendinning .unbind = smsc95xx_unbind, 20832f7ca802SSteve Glendinning .link_reset = smsc95xx_link_reset, 20842f7ca802SSteve Glendinning .reset = smsc95xx_reset, 20852f7ca802SSteve Glendinning .rx_fixup = smsc95xx_rx_fixup, 20862f7ca802SSteve Glendinning .tx_fixup = smsc95xx_tx_fixup, 20872f7ca802SSteve Glendinning .status = smsc95xx_status, 2088b2d4b150SSteve Glendinning .manage_power = smsc95xx_manage_power, 208907d69d42SPaolo Pisati .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, 20902f7ca802SSteve Glendinning }; 20912f7ca802SSteve Glendinning 20922f7ca802SSteve Glendinning static const struct usb_device_id products[] = { 20932f7ca802SSteve Glendinning { 20942f7ca802SSteve Glendinning /* SMSC9500 USB Ethernet Device */ 20952f7ca802SSteve Glendinning USB_DEVICE(0x0424, 0x9500), 20962f7ca802SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20972f7ca802SSteve Glendinning }, 2098726474b8SSteve Glendinning { 20996f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device */ 21006f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9505), 21016f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21026f41d12bSSteve Glendinning }, 21036f41d12bSSteve Glendinning { 21046f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device */ 21056f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E00), 21066f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21076f41d12bSSteve Glendinning }, 21086f41d12bSSteve Glendinning { 21096f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device */ 21106f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E01), 21116f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21126f41d12bSSteve Glendinning }, 21136f41d12bSSteve Glendinning { 2114726474b8SSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device */ 2115726474b8SSteve Glendinning USB_DEVICE(0x0424, 0xec00), 2116726474b8SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 2117726474b8SSteve Glendinning }, 21186f41d12bSSteve Glendinning { 21196f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (SAL10) */ 21206f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9900), 21216f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21226f41d12bSSteve Glendinning }, 21236f41d12bSSteve Glendinning { 21246f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device (SAL10) */ 21256f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9901), 21266f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21276f41d12bSSteve Glendinning }, 21286f41d12bSSteve Glendinning { 21296f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (SAL10) */ 21306f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9902), 21316f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21326f41d12bSSteve Glendinning }, 21336f41d12bSSteve Glendinning { 21346f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (SAL10) */ 21356f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9903), 21366f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21376f41d12bSSteve Glendinning }, 21386f41d12bSSteve Glendinning { 21396f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ 21406f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9904), 21416f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21426f41d12bSSteve Glendinning }, 21436f41d12bSSteve Glendinning { 21446f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (HAL) */ 21456f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9905), 21466f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21476f41d12bSSteve Glendinning }, 21486f41d12bSSteve Glendinning { 21496f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (HAL) */ 21506f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9906), 21516f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21526f41d12bSSteve Glendinning }, 21536f41d12bSSteve Glendinning { 21546f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (Alternate ID) */ 21556f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9907), 21566f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21576f41d12bSSteve Glendinning }, 21586f41d12bSSteve Glendinning { 21596f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (Alternate ID) */ 21606f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9908), 21616f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21626f41d12bSSteve Glendinning }, 21636f41d12bSSteve Glendinning { 21646f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ 21656f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9909), 21666f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21676f41d12bSSteve Glendinning }, 216888edaa41SSteve Glendinning { 216988edaa41SSteve Glendinning /* SMSC LAN9530 USB Ethernet Device */ 217088edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9530), 217188edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 217288edaa41SSteve Glendinning }, 217388edaa41SSteve Glendinning { 217488edaa41SSteve Glendinning /* SMSC LAN9730 USB Ethernet Device */ 217588edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9730), 217688edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 217788edaa41SSteve Glendinning }, 217888edaa41SSteve Glendinning { 217988edaa41SSteve Glendinning /* SMSC LAN89530 USB Ethernet Device */ 218088edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9E08), 218188edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 218288edaa41SSteve Glendinning }, 21832f7ca802SSteve Glendinning { }, /* END */ 21842f7ca802SSteve Glendinning }; 21852f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products); 21862f7ca802SSteve Glendinning 21872f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = { 21882f7ca802SSteve Glendinning .name = "smsc95xx", 21892f7ca802SSteve Glendinning .id_table = products, 21902f7ca802SSteve Glendinning .probe = usbnet_probe, 2191b5a04475SSteve Glendinning .suspend = smsc95xx_suspend, 2192e0e474a8SSteve Glendinning .resume = smsc95xx_resume, 2193b4df480fSJoonyoung Shim .reset_resume = smsc95xx_reset_resume, 21942f7ca802SSteve Glendinning .disconnect = usbnet_disconnect, 2195e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 2196b2d4b150SSteve Glendinning .supports_autosuspend = 1, 21972f7ca802SSteve Glendinning }; 21982f7ca802SSteve Glendinning 2199d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver); 22002f7ca802SSteve Glendinning 22012f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin"); 220290b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); 22032f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); 22042f7ca802SSteve Glendinning MODULE_LICENSE("GPL"); 2205