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" 36*13722bbeSWoojung Huh #define SMSC_DRIVER_VERSION "1.0.5" 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 { 67*13722bbeSWoojung 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; 75*13722bbeSWoojung 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 { 5292f7ca802SSteve Glendinning u32 flow, afc_cfg = 0; 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 else 5412f7ca802SSteve Glendinning flow = 0; 5422f7ca802SSteve Glendinning 5432f7ca802SSteve Glendinning if (cap & FLOW_CTRL_TX) 5442f7ca802SSteve Glendinning afc_cfg |= 0xF; 5452f7ca802SSteve Glendinning else 5462f7ca802SSteve Glendinning afc_cfg &= ~0xF; 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 flow = 0; 5542f7ca802SSteve Glendinning afc_cfg |= 0xF; 5552f7ca802SSteve Glendinning } 5562f7ca802SSteve Glendinning 557769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, flow); 558b052e073SSteve Glendinning if (ret < 0) 559b052e073SSteve Glendinning return ret; 560e360a8b4SSteve Glendinning 561e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); 5622f7ca802SSteve Glendinning } 5632f7ca802SSteve Glendinning 5642f7ca802SSteve Glendinning static int smsc95xx_link_reset(struct usbnet *dev) 5652f7ca802SSteve Glendinning { 5662f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 5672f7ca802SSteve Glendinning struct mii_if_info *mii = &dev->mii; 5688ae6dacaSDavid Decotigny struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; 5692f7ca802SSteve Glendinning unsigned long flags; 5702f7ca802SSteve Glendinning u16 lcladv, rmtadv; 571769ea6d8SSteve Glendinning int ret; 5722f7ca802SSteve Glendinning 5732f7ca802SSteve Glendinning /* clear interrupt status */ 574769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); 575e360a8b4SSteve Glendinning if (ret < 0) 576b052e073SSteve Glendinning return ret; 577769ea6d8SSteve Glendinning 578769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 579e360a8b4SSteve Glendinning if (ret < 0) 580b052e073SSteve Glendinning return ret; 5812f7ca802SSteve Glendinning 5822f7ca802SSteve Glendinning mii_check_media(mii, 1, 1); 5832f7ca802SSteve Glendinning mii_ethtool_gset(&dev->mii, &ecmd); 5842f7ca802SSteve Glendinning lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); 5852f7ca802SSteve Glendinning rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA); 5862f7ca802SSteve Glendinning 5878ae6dacaSDavid Decotigny netif_dbg(dev, link, dev->net, 5888ae6dacaSDavid Decotigny "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", 5898ae6dacaSDavid Decotigny ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); 5902f7ca802SSteve Glendinning 5912f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 5922f7ca802SSteve Glendinning if (ecmd.duplex != DUPLEX_FULL) { 5932f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_FDPX_; 5942f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RCVOWN_; 5952f7ca802SSteve Glendinning } else { 5962f7ca802SSteve Glendinning pdata->mac_cr &= ~MAC_CR_RCVOWN_; 5972f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_FDPX_; 5982f7ca802SSteve Glendinning } 5992f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 6002f7ca802SSteve Glendinning 601769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 602e360a8b4SSteve Glendinning if (ret < 0) 603b052e073SSteve Glendinning return ret; 6042f7ca802SSteve Glendinning 605769ea6d8SSteve Glendinning ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); 606b052e073SSteve Glendinning if (ret < 0) 607b052e073SSteve Glendinning netdev_warn(dev->net, "Error updating PHY flow control\n"); 6082f7ca802SSteve Glendinning 609b052e073SSteve Glendinning return ret; 6102f7ca802SSteve Glendinning } 6112f7ca802SSteve Glendinning 6122f7ca802SSteve Glendinning static void smsc95xx_status(struct usbnet *dev, struct urb *urb) 6132f7ca802SSteve Glendinning { 6142f7ca802SSteve Glendinning u32 intdata; 6152f7ca802SSteve Glendinning 6162f7ca802SSteve Glendinning if (urb->actual_length != 4) { 61760b86755SJoe Perches netdev_warn(dev->net, "unexpected urb length %d\n", 61860b86755SJoe Perches urb->actual_length); 6192f7ca802SSteve Glendinning return; 6202f7ca802SSteve Glendinning } 6212f7ca802SSteve Glendinning 6222f7ca802SSteve Glendinning memcpy(&intdata, urb->transfer_buffer, 4); 6231d74a6bdSSteve Glendinning le32_to_cpus(&intdata); 6242f7ca802SSteve Glendinning 625a475f603SJoe Perches netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); 6262f7ca802SSteve Glendinning 6272f7ca802SSteve Glendinning if (intdata & INT_ENP_PHY_INT_) 6282f7ca802SSteve Glendinning usbnet_defer_kevent(dev, EVENT_LINK_RESET); 6292f7ca802SSteve Glendinning else 63060b86755SJoe Perches netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", 63160b86755SJoe Perches intdata); 6322f7ca802SSteve Glendinning } 6332f7ca802SSteve Glendinning 634d69d1694SChristoph Fritz static void set_carrier(struct usbnet *dev, bool link) 635d69d1694SChristoph Fritz { 636d69d1694SChristoph Fritz struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 637d69d1694SChristoph Fritz 638d69d1694SChristoph Fritz if (pdata->link_ok == link) 639d69d1694SChristoph Fritz return; 640d69d1694SChristoph Fritz 641d69d1694SChristoph Fritz pdata->link_ok = link; 642d69d1694SChristoph Fritz 643d69d1694SChristoph Fritz if (link) 644d69d1694SChristoph Fritz usbnet_link_change(dev, 1, 0); 645d69d1694SChristoph Fritz else 646d69d1694SChristoph Fritz usbnet_link_change(dev, 0, 0); 647d69d1694SChristoph Fritz } 648d69d1694SChristoph Fritz 649d69d1694SChristoph Fritz static void check_carrier(struct work_struct *work) 650d69d1694SChristoph Fritz { 651d69d1694SChristoph Fritz struct smsc95xx_priv *pdata = container_of(work, struct smsc95xx_priv, 652d69d1694SChristoph Fritz carrier_check.work); 653d69d1694SChristoph Fritz struct usbnet *dev = pdata->dev; 654d69d1694SChristoph Fritz int ret; 655d69d1694SChristoph Fritz 656d69d1694SChristoph Fritz if (pdata->suspend_flags != 0) 657d69d1694SChristoph Fritz return; 658d69d1694SChristoph Fritz 659d69d1694SChristoph Fritz ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMSR); 660d69d1694SChristoph Fritz if (ret < 0) { 661d69d1694SChristoph Fritz netdev_warn(dev->net, "Failed to read MII_BMSR\n"); 662d69d1694SChristoph Fritz return; 663d69d1694SChristoph Fritz } 664d69d1694SChristoph Fritz if (ret & BMSR_LSTATUS) 665d69d1694SChristoph Fritz set_carrier(dev, 1); 666d69d1694SChristoph Fritz else 667d69d1694SChristoph Fritz set_carrier(dev, 0); 668d69d1694SChristoph Fritz 669d69d1694SChristoph Fritz schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); 670d69d1694SChristoph Fritz } 671d69d1694SChristoph Fritz 672f7b29271SSteve Glendinning /* Enable or disable Tx & Rx checksum offload engines */ 673c8f44affSMichał Mirosław static int smsc95xx_set_features(struct net_device *netdev, 674c8f44affSMichał Mirosław netdev_features_t features) 6752f7ca802SSteve Glendinning { 67678e47fe4SMichał Mirosław struct usbnet *dev = netdev_priv(netdev); 6772f7ca802SSteve Glendinning u32 read_buf; 67878e47fe4SMichał Mirosław int ret; 67978e47fe4SMichał Mirosław 68078e47fe4SMichał Mirosław ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); 681e360a8b4SSteve Glendinning if (ret < 0) 682b052e073SSteve Glendinning return ret; 6832f7ca802SSteve Glendinning 68478e47fe4SMichał Mirosław if (features & NETIF_F_HW_CSUM) 685f7b29271SSteve Glendinning read_buf |= Tx_COE_EN_; 686f7b29271SSteve Glendinning else 687f7b29271SSteve Glendinning read_buf &= ~Tx_COE_EN_; 688f7b29271SSteve Glendinning 68978e47fe4SMichał Mirosław if (features & NETIF_F_RXCSUM) 6902f7ca802SSteve Glendinning read_buf |= Rx_COE_EN_; 6912f7ca802SSteve Glendinning else 6922f7ca802SSteve Glendinning read_buf &= ~Rx_COE_EN_; 6932f7ca802SSteve Glendinning 6942f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, COE_CR, read_buf); 695e360a8b4SSteve Glendinning if (ret < 0) 696b052e073SSteve Glendinning return ret; 6972f7ca802SSteve Glendinning 698a475f603SJoe Perches netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); 6992f7ca802SSteve Glendinning return 0; 7002f7ca802SSteve Glendinning } 7012f7ca802SSteve Glendinning 7022f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) 7032f7ca802SSteve Glendinning { 7042f7ca802SSteve Glendinning return MAX_EEPROM_SIZE; 7052f7ca802SSteve Glendinning } 7062f7ca802SSteve Glendinning 7072f7ca802SSteve Glendinning static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, 7082f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 7092f7ca802SSteve Glendinning { 7102f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7112f7ca802SSteve Glendinning 7122f7ca802SSteve Glendinning ee->magic = LAN95XX_EEPROM_MAGIC; 7132f7ca802SSteve Glendinning 7142f7ca802SSteve Glendinning return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); 7152f7ca802SSteve Glendinning } 7162f7ca802SSteve Glendinning 7172f7ca802SSteve Glendinning static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, 7182f7ca802SSteve Glendinning struct ethtool_eeprom *ee, u8 *data) 7192f7ca802SSteve Glendinning { 7202f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 7212f7ca802SSteve Glendinning 7222f7ca802SSteve Glendinning if (ee->magic != LAN95XX_EEPROM_MAGIC) { 72360b86755SJoe Perches netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", 7242f7ca802SSteve Glendinning ee->magic); 7252f7ca802SSteve Glendinning return -EINVAL; 7262f7ca802SSteve Glendinning } 7272f7ca802SSteve Glendinning 7282f7ca802SSteve Glendinning return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); 7292f7ca802SSteve Glendinning } 7302f7ca802SSteve Glendinning 7319fa32e94SEmeric Vigier static int smsc95xx_ethtool_getregslen(struct net_device *netdev) 7329fa32e94SEmeric Vigier { 7339fa32e94SEmeric Vigier /* all smsc95xx registers */ 73496245317SSteve Glendinning return COE_CR - ID_REV + sizeof(u32); 7359fa32e94SEmeric Vigier } 7369fa32e94SEmeric Vigier 7379fa32e94SEmeric Vigier static void 7389fa32e94SEmeric Vigier smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, 7399fa32e94SEmeric Vigier void *buf) 7409fa32e94SEmeric Vigier { 7419fa32e94SEmeric Vigier struct usbnet *dev = netdev_priv(netdev); 742d348446bSDan Carpenter unsigned int i, j; 743d348446bSDan Carpenter int retval; 7449fa32e94SEmeric Vigier u32 *data = buf; 7459fa32e94SEmeric Vigier 7469fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); 7479fa32e94SEmeric Vigier if (retval < 0) { 7489fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read ID_REV\n"); 7499fa32e94SEmeric Vigier return; 7509fa32e94SEmeric Vigier } 7519fa32e94SEmeric Vigier 7529fa32e94SEmeric Vigier for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { 7539fa32e94SEmeric Vigier retval = smsc95xx_read_reg(dev, i, &data[j]); 7549fa32e94SEmeric Vigier if (retval < 0) { 7559fa32e94SEmeric Vigier netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); 7569fa32e94SEmeric Vigier return; 7579fa32e94SEmeric Vigier } 7589fa32e94SEmeric Vigier } 7599fa32e94SEmeric Vigier } 7609fa32e94SEmeric Vigier 761e0e474a8SSteve Glendinning static void smsc95xx_ethtool_get_wol(struct net_device *net, 762e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 763e0e474a8SSteve Glendinning { 764e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 765e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 766e0e474a8SSteve Glendinning 767e0e474a8SSteve Glendinning wolinfo->supported = SUPPORTED_WAKE; 768e0e474a8SSteve Glendinning wolinfo->wolopts = pdata->wolopts; 769e0e474a8SSteve Glendinning } 770e0e474a8SSteve Glendinning 771e0e474a8SSteve Glendinning static int smsc95xx_ethtool_set_wol(struct net_device *net, 772e0e474a8SSteve Glendinning struct ethtool_wolinfo *wolinfo) 773e0e474a8SSteve Glendinning { 774e0e474a8SSteve Glendinning struct usbnet *dev = netdev_priv(net); 775e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 7763b14692cSSteve Glendinning int ret; 777e0e474a8SSteve Glendinning 778e0e474a8SSteve Glendinning pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; 7793b14692cSSteve Glendinning 7803b14692cSSteve Glendinning ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); 781b052e073SSteve Glendinning if (ret < 0) 782b052e073SSteve Glendinning netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); 7833b14692cSSteve Glendinning 784b052e073SSteve Glendinning return ret; 785e0e474a8SSteve Glendinning } 786e0e474a8SSteve Glendinning 787*13722bbeSWoojung Huh static int get_mdix_status(struct net_device *net) 788*13722bbeSWoojung Huh { 789*13722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 790*13722bbeSWoojung Huh u32 val; 791*13722bbeSWoojung Huh int buf; 792*13722bbeSWoojung Huh 793*13722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, SPECIAL_CTRL_STS); 794*13722bbeSWoojung Huh if (buf & SPECIAL_CTRL_STS_OVRRD_AMDIX_) { 795*13722bbeSWoojung Huh if (buf & SPECIAL_CTRL_STS_AMDIX_ENABLE_) 796*13722bbeSWoojung Huh return ETH_TP_MDI_AUTO; 797*13722bbeSWoojung Huh else if (buf & SPECIAL_CTRL_STS_AMDIX_STATE_) 798*13722bbeSWoojung Huh return ETH_TP_MDI_X; 799*13722bbeSWoojung Huh } else { 800*13722bbeSWoojung Huh buf = smsc95xx_read_reg(dev, STRAP_STATUS, &val); 801*13722bbeSWoojung Huh if (val & STRAP_STATUS_AMDIX_EN_) 802*13722bbeSWoojung Huh return ETH_TP_MDI_AUTO; 803*13722bbeSWoojung Huh } 804*13722bbeSWoojung Huh 805*13722bbeSWoojung Huh return ETH_TP_MDI; 806*13722bbeSWoojung Huh } 807*13722bbeSWoojung Huh 808*13722bbeSWoojung Huh static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) 809*13722bbeSWoojung Huh { 810*13722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 811*13722bbeSWoojung Huh struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 812*13722bbeSWoojung Huh int buf; 813*13722bbeSWoojung Huh 814*13722bbeSWoojung Huh if ((pdata->chip_id == ID_REV_CHIP_ID_9500A_) || 815*13722bbeSWoojung Huh (pdata->chip_id == ID_REV_CHIP_ID_9530_) || 816*13722bbeSWoojung Huh (pdata->chip_id == ID_REV_CHIP_ID_89530_) || 817*13722bbeSWoojung Huh (pdata->chip_id == ID_REV_CHIP_ID_9730_)) { 818*13722bbeSWoojung Huh /* Extend Manual AutoMDIX timer for 9500A/9500Ai */ 819*13722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 820*13722bbeSWoojung Huh PHY_EDPD_CONFIG); 821*13722bbeSWoojung Huh buf |= PHY_EDPD_CONFIG_EXT_CROSSOVER_; 822*13722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 823*13722bbeSWoojung Huh PHY_EDPD_CONFIG, buf); 824*13722bbeSWoojung Huh } 825*13722bbeSWoojung Huh 826*13722bbeSWoojung Huh if (mdix_ctrl == ETH_TP_MDI) { 827*13722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 828*13722bbeSWoojung Huh SPECIAL_CTRL_STS); 829*13722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_OVRRD_AMDIX_; 830*13722bbeSWoojung Huh buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | 831*13722bbeSWoojung Huh SPECIAL_CTRL_STS_AMDIX_STATE_); 832*13722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 833*13722bbeSWoojung Huh SPECIAL_CTRL_STS, buf); 834*13722bbeSWoojung Huh } else if (mdix_ctrl == ETH_TP_MDI_X) { 835*13722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 836*13722bbeSWoojung Huh SPECIAL_CTRL_STS); 837*13722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_OVRRD_AMDIX_; 838*13722bbeSWoojung Huh buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | 839*13722bbeSWoojung Huh SPECIAL_CTRL_STS_AMDIX_STATE_); 840*13722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_AMDIX_STATE_; 841*13722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 842*13722bbeSWoojung Huh SPECIAL_CTRL_STS, buf); 843*13722bbeSWoojung Huh } else if (mdix_ctrl == ETH_TP_MDI_AUTO) { 844*13722bbeSWoojung Huh buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, 845*13722bbeSWoojung Huh SPECIAL_CTRL_STS); 846*13722bbeSWoojung Huh buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_; 847*13722bbeSWoojung Huh buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | 848*13722bbeSWoojung Huh SPECIAL_CTRL_STS_AMDIX_STATE_); 849*13722bbeSWoojung Huh buf |= SPECIAL_CTRL_STS_AMDIX_ENABLE_; 850*13722bbeSWoojung Huh smsc95xx_mdio_write(dev->net, dev->mii.phy_id, 851*13722bbeSWoojung Huh SPECIAL_CTRL_STS, buf); 852*13722bbeSWoojung Huh } 853*13722bbeSWoojung Huh pdata->mdix_ctrl = mdix_ctrl; 854*13722bbeSWoojung Huh } 855*13722bbeSWoojung Huh 856*13722bbeSWoojung Huh static int smsc95xx_get_settings(struct net_device *net, 857*13722bbeSWoojung Huh struct ethtool_cmd *cmd) 858*13722bbeSWoojung Huh { 859*13722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 860*13722bbeSWoojung Huh struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 861*13722bbeSWoojung Huh int retval; 862*13722bbeSWoojung Huh 863*13722bbeSWoojung Huh retval = usbnet_get_settings(net, cmd); 864*13722bbeSWoojung Huh 865*13722bbeSWoojung Huh cmd->eth_tp_mdix = pdata->mdix_ctrl; 866*13722bbeSWoojung Huh cmd->eth_tp_mdix_ctrl = pdata->mdix_ctrl; 867*13722bbeSWoojung Huh 868*13722bbeSWoojung Huh return retval; 869*13722bbeSWoojung Huh } 870*13722bbeSWoojung Huh 871*13722bbeSWoojung Huh static int smsc95xx_set_settings(struct net_device *net, 872*13722bbeSWoojung Huh struct ethtool_cmd *cmd) 873*13722bbeSWoojung Huh { 874*13722bbeSWoojung Huh struct usbnet *dev = netdev_priv(net); 875*13722bbeSWoojung Huh struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 876*13722bbeSWoojung Huh int retval; 877*13722bbeSWoojung Huh 878*13722bbeSWoojung Huh if (pdata->mdix_ctrl != cmd->eth_tp_mdix_ctrl) 879*13722bbeSWoojung Huh set_mdix_status(net, cmd->eth_tp_mdix_ctrl); 880*13722bbeSWoojung Huh 881*13722bbeSWoojung Huh retval = usbnet_set_settings(net, cmd); 882*13722bbeSWoojung Huh 883*13722bbeSWoojung Huh return retval; 884*13722bbeSWoojung Huh } 885*13722bbeSWoojung Huh 8860fc0b732SStephen Hemminger static const struct ethtool_ops smsc95xx_ethtool_ops = { 8872f7ca802SSteve Glendinning .get_link = usbnet_get_link, 8882f7ca802SSteve Glendinning .nway_reset = usbnet_nway_reset, 8892f7ca802SSteve Glendinning .get_drvinfo = usbnet_get_drvinfo, 8902f7ca802SSteve Glendinning .get_msglevel = usbnet_get_msglevel, 8912f7ca802SSteve Glendinning .set_msglevel = usbnet_set_msglevel, 892*13722bbeSWoojung Huh .get_settings = smsc95xx_get_settings, 893*13722bbeSWoojung Huh .set_settings = smsc95xx_set_settings, 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, 9012f7ca802SSteve Glendinning }; 9022f7ca802SSteve Glendinning 9032f7ca802SSteve Glendinning static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) 9042f7ca802SSteve Glendinning { 9052f7ca802SSteve Glendinning struct usbnet *dev = netdev_priv(netdev); 9062f7ca802SSteve Glendinning 9072f7ca802SSteve Glendinning if (!netif_running(netdev)) 9082f7ca802SSteve Glendinning return -EINVAL; 9092f7ca802SSteve Glendinning 9102f7ca802SSteve Glendinning return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 9112f7ca802SSteve Glendinning } 9122f7ca802SSteve Glendinning 9132f7ca802SSteve Glendinning static void smsc95xx_init_mac_address(struct usbnet *dev) 9142f7ca802SSteve Glendinning { 915c489565bSArnd Bergmann const u8 *mac_addr; 916c489565bSArnd Bergmann 917c489565bSArnd Bergmann /* maybe the boot loader passed the MAC address in devicetree */ 918c489565bSArnd Bergmann mac_addr = of_get_mac_address(dev->udev->dev.of_node); 919c489565bSArnd Bergmann if (mac_addr) { 920c489565bSArnd Bergmann memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN); 921c489565bSArnd Bergmann return; 922c489565bSArnd Bergmann } 923c489565bSArnd Bergmann 9242f7ca802SSteve Glendinning /* try reading mac address from EEPROM */ 9252f7ca802SSteve Glendinning if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, 9262f7ca802SSteve Glendinning dev->net->dev_addr) == 0) { 9272f7ca802SSteve Glendinning if (is_valid_ether_addr(dev->net->dev_addr)) { 9282f7ca802SSteve Glendinning /* eeprom values are valid so use them */ 929a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); 9302f7ca802SSteve Glendinning return; 9312f7ca802SSteve Glendinning } 9322f7ca802SSteve Glendinning } 9332f7ca802SSteve Glendinning 934c489565bSArnd Bergmann /* no useful static MAC address found. generate a random one */ 935f2cedb63SDanny Kukawka eth_hw_addr_random(dev->net); 936c7e12eadSJoe Perches netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); 9372f7ca802SSteve Glendinning } 9382f7ca802SSteve Glendinning 9392f7ca802SSteve Glendinning static int smsc95xx_set_mac_address(struct usbnet *dev) 9402f7ca802SSteve Glendinning { 9412f7ca802SSteve Glendinning u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | 9422f7ca802SSteve Glendinning dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; 9432f7ca802SSteve Glendinning u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; 9442f7ca802SSteve Glendinning int ret; 9452f7ca802SSteve Glendinning 9462f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); 947b052e073SSteve Glendinning if (ret < 0) 948b052e073SSteve Glendinning return ret; 949e360a8b4SSteve Glendinning 950e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, ADDRH, addr_hi); 9512f7ca802SSteve Glendinning } 9522f7ca802SSteve Glendinning 9532f7ca802SSteve Glendinning /* starts the TX path */ 954769ea6d8SSteve Glendinning static int smsc95xx_start_tx_path(struct usbnet *dev) 9552f7ca802SSteve Glendinning { 9562f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 9572f7ca802SSteve Glendinning unsigned long flags; 958769ea6d8SSteve Glendinning int ret; 9592f7ca802SSteve Glendinning 9602f7ca802SSteve Glendinning /* Enable Tx at MAC */ 9612f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 9622f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_TXEN_; 9632f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 9642f7ca802SSteve Glendinning 965769ea6d8SSteve Glendinning ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); 966e360a8b4SSteve Glendinning if (ret < 0) 967b052e073SSteve Glendinning return ret; 9682f7ca802SSteve Glendinning 9692f7ca802SSteve Glendinning /* Enable Tx at SCSRs */ 970e360a8b4SSteve Glendinning return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); 9712f7ca802SSteve Glendinning } 9722f7ca802SSteve Glendinning 9732f7ca802SSteve Glendinning /* Starts the Receive path */ 974ec32115dSMing Lei static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) 9752f7ca802SSteve Glendinning { 9762f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 9772f7ca802SSteve Glendinning unsigned long flags; 9782f7ca802SSteve Glendinning 9792f7ca802SSteve Glendinning spin_lock_irqsave(&pdata->mac_cr_lock, flags); 9802f7ca802SSteve Glendinning pdata->mac_cr |= MAC_CR_RXEN_; 9812f7ca802SSteve Glendinning spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); 9822f7ca802SSteve Glendinning 983e360a8b4SSteve Glendinning return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm); 9842f7ca802SSteve Glendinning } 9852f7ca802SSteve Glendinning 9862f7ca802SSteve Glendinning static int smsc95xx_phy_initialize(struct usbnet *dev) 9872f7ca802SSteve Glendinning { 988769ea6d8SSteve Glendinning int bmcr, ret, timeout = 0; 989db443c44SSteve Glendinning 9902f7ca802SSteve Glendinning /* Initialize MII structure */ 9912f7ca802SSteve Glendinning dev->mii.dev = dev->net; 9922f7ca802SSteve Glendinning dev->mii.mdio_read = smsc95xx_mdio_read; 9932f7ca802SSteve Glendinning dev->mii.mdio_write = smsc95xx_mdio_write; 9942f7ca802SSteve Glendinning dev->mii.phy_id_mask = 0x1f; 9952f7ca802SSteve Glendinning dev->mii.reg_num_mask = 0x1f; 9962f7ca802SSteve Glendinning dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID; 9972f7ca802SSteve Glendinning 998db443c44SSteve Glendinning /* reset phy and wait for reset to complete */ 9992f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 1000db443c44SSteve Glendinning 1001db443c44SSteve Glendinning do { 1002db443c44SSteve Glendinning msleep(10); 1003db443c44SSteve Glendinning bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); 1004db443c44SSteve Glendinning timeout++; 1005d9460920SRabin Vincent } while ((bmcr & BMCR_RESET) && (timeout < 100)); 1006db443c44SSteve Glendinning 1007db443c44SSteve Glendinning if (timeout >= 100) { 1008db443c44SSteve Glendinning netdev_warn(dev->net, "timeout on PHY Reset"); 1009db443c44SSteve Glendinning return -EIO; 1010db443c44SSteve Glendinning } 1011db443c44SSteve Glendinning 10122f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, 10132f7ca802SSteve Glendinning ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | 10142f7ca802SSteve Glendinning ADVERTISE_PAUSE_ASYM); 10152f7ca802SSteve Glendinning 10162f7ca802SSteve Glendinning /* read to clear */ 1017769ea6d8SSteve Glendinning ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); 1018b052e073SSteve Glendinning if (ret < 0) { 1019b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n"); 1020b052e073SSteve Glendinning return ret; 1021b052e073SSteve Glendinning } 10222f7ca802SSteve Glendinning 10232f7ca802SSteve Glendinning smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, 10242f7ca802SSteve Glendinning PHY_INT_MASK_DEFAULT_); 10252f7ca802SSteve Glendinning mii_nway_restart(&dev->mii); 10262f7ca802SSteve Glendinning 1027a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); 10282f7ca802SSteve Glendinning return 0; 10292f7ca802SSteve Glendinning } 10302f7ca802SSteve Glendinning 10312f7ca802SSteve Glendinning static int smsc95xx_reset(struct usbnet *dev) 10322f7ca802SSteve Glendinning { 10332f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 10342f7ca802SSteve Glendinning u32 read_buf, write_buf, burst_cap; 10352f7ca802SSteve Glendinning int ret = 0, timeout; 10362f7ca802SSteve Glendinning 1037a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); 10382f7ca802SSteve Glendinning 10394436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); 1040e360a8b4SSteve Glendinning if (ret < 0) 1041b052e073SSteve Glendinning return ret; 10422f7ca802SSteve Glendinning 10432f7ca802SSteve Glendinning timeout = 0; 10442f7ca802SSteve Glendinning do { 1045cf2acec2SSteve Glendinning msleep(10); 10462f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1047e360a8b4SSteve Glendinning if (ret < 0) 1048b052e073SSteve Glendinning return ret; 10492f7ca802SSteve Glendinning timeout++; 10502f7ca802SSteve Glendinning } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); 10512f7ca802SSteve Glendinning 10522f7ca802SSteve Glendinning if (timeout >= 100) { 105360b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); 10542f7ca802SSteve Glendinning return ret; 10552f7ca802SSteve Glendinning } 10562f7ca802SSteve Glendinning 10574436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); 1058e360a8b4SSteve Glendinning if (ret < 0) 1059b052e073SSteve Glendinning return ret; 10602f7ca802SSteve Glendinning 10612f7ca802SSteve Glendinning timeout = 0; 10622f7ca802SSteve Glendinning do { 1063cf2acec2SSteve Glendinning msleep(10); 10642f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); 1065e360a8b4SSteve Glendinning if (ret < 0) 1066b052e073SSteve Glendinning return ret; 10672f7ca802SSteve Glendinning timeout++; 10682f7ca802SSteve Glendinning } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); 10692f7ca802SSteve Glendinning 10702f7ca802SSteve Glendinning if (timeout >= 100) { 107160b86755SJoe Perches netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); 10722f7ca802SSteve Glendinning return ret; 10732f7ca802SSteve Glendinning } 10742f7ca802SSteve Glendinning 10752f7ca802SSteve Glendinning ret = smsc95xx_set_mac_address(dev); 10762f7ca802SSteve Glendinning if (ret < 0) 10772f7ca802SSteve Glendinning return ret; 10782f7ca802SSteve Glendinning 10791e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", 10801e1d7412SJoe Perches dev->net->dev_addr); 10812f7ca802SSteve Glendinning 10822f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1083e360a8b4SSteve Glendinning if (ret < 0) 1084b052e073SSteve Glendinning return ret; 10852f7ca802SSteve Glendinning 10861e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", 10871e1d7412SJoe Perches read_buf); 10882f7ca802SSteve Glendinning 10892f7ca802SSteve Glendinning read_buf |= HW_CFG_BIR_; 10902f7ca802SSteve Glendinning 10912f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 1092e360a8b4SSteve Glendinning if (ret < 0) 1093b052e073SSteve Glendinning return ret; 10942f7ca802SSteve Glendinning 10952f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1096e360a8b4SSteve Glendinning if (ret < 0) 1097b052e073SSteve Glendinning return ret; 1098b052e073SSteve Glendinning 1099a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1100a475f603SJoe Perches "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", 110160b86755SJoe Perches read_buf); 11022f7ca802SSteve Glendinning 11032f7ca802SSteve Glendinning if (!turbo_mode) { 11042f7ca802SSteve Glendinning burst_cap = 0; 11052f7ca802SSteve Glendinning dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; 11062f7ca802SSteve Glendinning } else if (dev->udev->speed == USB_SPEED_HIGH) { 11072f7ca802SSteve Glendinning burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; 11082f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; 11092f7ca802SSteve Glendinning } else { 11102f7ca802SSteve Glendinning burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; 11112f7ca802SSteve Glendinning dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; 11122f7ca802SSteve Glendinning } 11132f7ca802SSteve Glendinning 11141e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", 11151e1d7412SJoe Perches (ulong)dev->rx_urb_size); 11162f7ca802SSteve Glendinning 11172f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); 1118e360a8b4SSteve Glendinning if (ret < 0) 1119b052e073SSteve Glendinning return ret; 11202f7ca802SSteve Glendinning 11212f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); 1122e360a8b4SSteve Glendinning if (ret < 0) 1123b052e073SSteve Glendinning return ret; 1124769ea6d8SSteve Glendinning 1125a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1126a475f603SJoe Perches "Read Value from BURST_CAP after writing: 0x%08x\n", 11272f7ca802SSteve Glendinning read_buf); 11282f7ca802SSteve Glendinning 11294436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); 1130e360a8b4SSteve Glendinning if (ret < 0) 1131b052e073SSteve Glendinning return ret; 11322f7ca802SSteve Glendinning 11332f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); 1134e360a8b4SSteve Glendinning if (ret < 0) 1135b052e073SSteve Glendinning return ret; 1136769ea6d8SSteve Glendinning 1137a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1138a475f603SJoe Perches "Read Value from BULK_IN_DLY after writing: 0x%08x\n", 113960b86755SJoe Perches read_buf); 11402f7ca802SSteve Glendinning 11412f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1142e360a8b4SSteve Glendinning if (ret < 0) 1143b052e073SSteve Glendinning return ret; 1144769ea6d8SSteve Glendinning 11451e1d7412SJoe Perches netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n", 11461e1d7412SJoe Perches read_buf); 11472f7ca802SSteve Glendinning 11482f7ca802SSteve Glendinning if (turbo_mode) 11492f7ca802SSteve Glendinning read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); 11502f7ca802SSteve Glendinning 11512f7ca802SSteve Glendinning read_buf &= ~HW_CFG_RXDOFF_; 11522f7ca802SSteve Glendinning 11532f7ca802SSteve Glendinning /* set Rx data offset=2, Make IP header aligns on word boundary. */ 11542f7ca802SSteve Glendinning read_buf |= NET_IP_ALIGN << 9; 11552f7ca802SSteve Glendinning 11562f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); 1157e360a8b4SSteve Glendinning if (ret < 0) 1158b052e073SSteve Glendinning return ret; 11592f7ca802SSteve Glendinning 11602f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); 1161e360a8b4SSteve Glendinning if (ret < 0) 1162b052e073SSteve Glendinning return ret; 1163769ea6d8SSteve Glendinning 1164a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, 1165a475f603SJoe Perches "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); 11662f7ca802SSteve Glendinning 11674436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); 1168e360a8b4SSteve Glendinning if (ret < 0) 1169b052e073SSteve Glendinning return ret; 11702f7ca802SSteve Glendinning 11712f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); 1172e360a8b4SSteve Glendinning if (ret < 0) 1173b052e073SSteve Glendinning return ret; 1174a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); 11752f7ca802SSteve Glendinning 1176f293501cSSteve Glendinning /* Configure GPIO pins as LED outputs */ 1177f293501cSSteve Glendinning write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | 1178f293501cSSteve Glendinning LED_GPIO_CFG_FDX_LED; 1179f293501cSSteve Glendinning ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); 1180e360a8b4SSteve Glendinning if (ret < 0) 1181b052e073SSteve Glendinning return ret; 1182f293501cSSteve Glendinning 11832f7ca802SSteve Glendinning /* Init Tx */ 11844436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, FLOW, 0); 1185e360a8b4SSteve Glendinning if (ret < 0) 1186b052e073SSteve Glendinning return ret; 11872f7ca802SSteve Glendinning 11884436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); 1189e360a8b4SSteve Glendinning if (ret < 0) 1190b052e073SSteve Glendinning return ret; 11912f7ca802SSteve Glendinning 11922f7ca802SSteve Glendinning /* Don't need mac_cr_lock during initialisation */ 11932f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); 1194e360a8b4SSteve Glendinning if (ret < 0) 1195b052e073SSteve Glendinning return ret; 11962f7ca802SSteve Glendinning 11972f7ca802SSteve Glendinning /* Init Rx */ 11982f7ca802SSteve Glendinning /* Set Vlan */ 11994436761bSSteve Glendinning ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); 1200e360a8b4SSteve Glendinning if (ret < 0) 1201b052e073SSteve Glendinning return ret; 12022f7ca802SSteve Glendinning 1203f7b29271SSteve Glendinning /* Enable or disable checksum offload engines */ 1204769ea6d8SSteve Glendinning ret = smsc95xx_set_features(dev->net, dev->net->features); 1205b052e073SSteve Glendinning if (ret < 0) { 1206b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to set checksum offload features\n"); 1207b052e073SSteve Glendinning return ret; 1208b052e073SSteve Glendinning } 12092f7ca802SSteve Glendinning 12102f7ca802SSteve Glendinning smsc95xx_set_multicast(dev->net); 12112f7ca802SSteve Glendinning 1212769ea6d8SSteve Glendinning ret = smsc95xx_phy_initialize(dev); 1213b052e073SSteve Glendinning if (ret < 0) { 1214b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to init PHY\n"); 1215b052e073SSteve Glendinning return ret; 1216b052e073SSteve Glendinning } 12172f7ca802SSteve Glendinning 12182f7ca802SSteve Glendinning ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); 1219e360a8b4SSteve Glendinning if (ret < 0) 1220b052e073SSteve Glendinning return ret; 12212f7ca802SSteve Glendinning 12222f7ca802SSteve Glendinning /* enable PHY interrupts */ 12232f7ca802SSteve Glendinning read_buf |= INT_EP_CTL_PHY_INT_; 12242f7ca802SSteve Glendinning 12252f7ca802SSteve Glendinning ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); 1226e360a8b4SSteve Glendinning if (ret < 0) 1227b052e073SSteve Glendinning return ret; 12282f7ca802SSteve Glendinning 1229769ea6d8SSteve Glendinning ret = smsc95xx_start_tx_path(dev); 1230b052e073SSteve Glendinning if (ret < 0) { 1231b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start TX path\n"); 1232b052e073SSteve Glendinning return ret; 1233b052e073SSteve Glendinning } 1234769ea6d8SSteve Glendinning 1235ec32115dSMing Lei ret = smsc95xx_start_rx_path(dev, 0); 1236b052e073SSteve Glendinning if (ret < 0) { 1237b052e073SSteve Glendinning netdev_warn(dev->net, "Failed to start RX path\n"); 1238b052e073SSteve Glendinning return ret; 1239b052e073SSteve Glendinning } 12402f7ca802SSteve Glendinning 1241a475f603SJoe Perches netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); 12422f7ca802SSteve Glendinning return 0; 12432f7ca802SSteve Glendinning } 12442f7ca802SSteve Glendinning 124563e77b39SStephen Hemminger static const struct net_device_ops smsc95xx_netdev_ops = { 124663e77b39SStephen Hemminger .ndo_open = usbnet_open, 124763e77b39SStephen Hemminger .ndo_stop = usbnet_stop, 124863e77b39SStephen Hemminger .ndo_start_xmit = usbnet_start_xmit, 124963e77b39SStephen Hemminger .ndo_tx_timeout = usbnet_tx_timeout, 125063e77b39SStephen Hemminger .ndo_change_mtu = usbnet_change_mtu, 125163e77b39SStephen Hemminger .ndo_set_mac_address = eth_mac_addr, 125263e77b39SStephen Hemminger .ndo_validate_addr = eth_validate_addr, 125363e77b39SStephen Hemminger .ndo_do_ioctl = smsc95xx_ioctl, 1254afc4b13dSJiri Pirko .ndo_set_rx_mode = smsc95xx_set_multicast, 125578e47fe4SMichał Mirosław .ndo_set_features = smsc95xx_set_features, 125663e77b39SStephen Hemminger }; 125763e77b39SStephen Hemminger 12582f7ca802SSteve Glendinning static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) 12592f7ca802SSteve Glendinning { 12602f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = NULL; 1261bbd9f9eeSSteve Glendinning u32 val; 12622f7ca802SSteve Glendinning int ret; 12632f7ca802SSteve Glendinning 12642f7ca802SSteve Glendinning printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); 12652f7ca802SSteve Glendinning 12662f7ca802SSteve Glendinning ret = usbnet_get_endpoints(dev, intf); 1267b052e073SSteve Glendinning if (ret < 0) { 1268b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); 1269b052e073SSteve Glendinning return ret; 1270b052e073SSteve Glendinning } 12712f7ca802SSteve Glendinning 12722f7ca802SSteve Glendinning dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), 12732f7ca802SSteve Glendinning GFP_KERNEL); 12742f7ca802SSteve Glendinning 12752f7ca802SSteve Glendinning pdata = (struct smsc95xx_priv *)(dev->data[0]); 127638673c82SJoe Perches if (!pdata) 12772f7ca802SSteve Glendinning return -ENOMEM; 12782f7ca802SSteve Glendinning 12792f7ca802SSteve Glendinning spin_lock_init(&pdata->mac_cr_lock); 12802f7ca802SSteve Glendinning 128178e47fe4SMichał Mirosław if (DEFAULT_TX_CSUM_ENABLE) 128278e47fe4SMichał Mirosław dev->net->features |= NETIF_F_HW_CSUM; 128378e47fe4SMichał Mirosław if (DEFAULT_RX_CSUM_ENABLE) 128478e47fe4SMichał Mirosław dev->net->features |= NETIF_F_RXCSUM; 128578e47fe4SMichał Mirosław 128678e47fe4SMichał Mirosław dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM; 12872f7ca802SSteve Glendinning 1288f4e8ab7cSBernard Blackham smsc95xx_init_mac_address(dev); 1289f4e8ab7cSBernard Blackham 12902f7ca802SSteve Glendinning /* Init all registers */ 12912f7ca802SSteve Glendinning ret = smsc95xx_reset(dev); 12922f7ca802SSteve Glendinning 1293bbd9f9eeSSteve Glendinning /* detect device revision as different features may be available */ 1294bbd9f9eeSSteve Glendinning ret = smsc95xx_read_reg(dev, ID_REV, &val); 1295e360a8b4SSteve Glendinning if (ret < 0) 1296b052e073SSteve Glendinning return ret; 1297bbd9f9eeSSteve Glendinning val >>= 16; 1298*13722bbeSWoojung Huh pdata->chip_id = val; 1299*13722bbeSWoojung Huh pdata->mdix_ctrl = get_mdix_status(dev->net); 13009ebca507SSteve Glendinning 13019ebca507SSteve Glendinning if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || 13029ebca507SSteve Glendinning (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) 13039ebca507SSteve Glendinning pdata->features = (FEATURE_8_WAKEUP_FILTERS | 13049ebca507SSteve Glendinning FEATURE_PHY_NLP_CROSSOVER | 1305eb970ff0SMing Lei FEATURE_REMOTE_WAKEUP); 13069ebca507SSteve Glendinning else if (val == ID_REV_CHIP_ID_9512_) 13079ebca507SSteve Glendinning pdata->features = FEATURE_8_WAKEUP_FILTERS; 1308bbd9f9eeSSteve Glendinning 130963e77b39SStephen Hemminger dev->net->netdev_ops = &smsc95xx_netdev_ops; 13102f7ca802SSteve Glendinning dev->net->ethtool_ops = &smsc95xx_ethtool_ops; 13112f7ca802SSteve Glendinning dev->net->flags |= IFF_MULTICAST; 131278e47fe4SMichał Mirosław dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; 13139bbf5660SStephane Fillod dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; 1314d69d1694SChristoph Fritz 1315d69d1694SChristoph Fritz pdata->dev = dev; 1316d69d1694SChristoph Fritz INIT_DELAYED_WORK(&pdata->carrier_check, check_carrier); 1317d69d1694SChristoph Fritz schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); 1318d69d1694SChristoph Fritz 13192f7ca802SSteve Glendinning return 0; 13202f7ca802SSteve Glendinning } 13212f7ca802SSteve Glendinning 13222f7ca802SSteve Glendinning static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) 13232f7ca802SSteve Glendinning { 13242f7ca802SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1325d69d1694SChristoph Fritz 13262f7ca802SSteve Glendinning if (pdata) { 1327d69d1694SChristoph Fritz cancel_delayed_work(&pdata->carrier_check); 1328a475f603SJoe Perches netif_dbg(dev, ifdown, dev->net, "free pdata\n"); 13292f7ca802SSteve Glendinning kfree(pdata); 13302f7ca802SSteve Glendinning pdata = NULL; 13312f7ca802SSteve Glendinning dev->data[0] = 0; 13322f7ca802SSteve Glendinning } 13332f7ca802SSteve Glendinning } 13342f7ca802SSteve Glendinning 1335068bb1a7SSteve Glendinning static u32 smsc_crc(const u8 *buffer, size_t len, int filter) 1336bbd9f9eeSSteve Glendinning { 1337068bb1a7SSteve Glendinning u32 crc = bitrev16(crc16(0xFFFF, buffer, len)); 1338068bb1a7SSteve Glendinning return crc << ((filter % 2) * 16); 1339bbd9f9eeSSteve Glendinning } 1340bbd9f9eeSSteve Glendinning 1341e5e3af83SSteve Glendinning static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) 1342e5e3af83SSteve Glendinning { 1343e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1344e5e3af83SSteve Glendinning int ret; 1345e5e3af83SSteve Glendinning 13461e1d7412SJoe Perches netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n"); 1347e5e3af83SSteve Glendinning 1348e5e3af83SSteve Glendinning /* read to clear */ 1349e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC); 1350e360a8b4SSteve Glendinning if (ret < 0) 1351b052e073SSteve Glendinning return ret; 1352e5e3af83SSteve Glendinning 1353e5e3af83SSteve Glendinning /* enable interrupt source */ 1354e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK); 1355e360a8b4SSteve Glendinning if (ret < 0) 1356b052e073SSteve Glendinning return ret; 1357e5e3af83SSteve Glendinning 1358e5e3af83SSteve Glendinning ret |= mask; 1359e5e3af83SSteve Glendinning 1360e5e3af83SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret); 1361e5e3af83SSteve Glendinning 1362e5e3af83SSteve Glendinning return 0; 1363e5e3af83SSteve Glendinning } 1364e5e3af83SSteve Glendinning 1365e5e3af83SSteve Glendinning static int smsc95xx_link_ok_nopm(struct usbnet *dev) 1366e5e3af83SSteve Glendinning { 1367e5e3af83SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1368e5e3af83SSteve Glendinning int ret; 1369e5e3af83SSteve Glendinning 1370e5e3af83SSteve Glendinning /* first, a dummy read, needed to latch some MII phys */ 1371e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1372e360a8b4SSteve Glendinning if (ret < 0) 1373b052e073SSteve Glendinning return ret; 1374e5e3af83SSteve Glendinning 1375e5e3af83SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); 1376e360a8b4SSteve Glendinning if (ret < 0) 1377b052e073SSteve Glendinning return ret; 1378e5e3af83SSteve Glendinning 1379e5e3af83SSteve Glendinning return !!(ret & BMSR_LSTATUS); 1380e5e3af83SSteve Glendinning } 1381e5e3af83SSteve Glendinning 1382319b95b5SSteve Glendinning static int smsc95xx_enter_suspend0(struct usbnet *dev) 1383319b95b5SSteve Glendinning { 1384319b95b5SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1385319b95b5SSteve Glendinning u32 val; 1386319b95b5SSteve Glendinning int ret; 1387319b95b5SSteve Glendinning 1388319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1389e360a8b4SSteve Glendinning if (ret < 0) 1390b052e073SSteve Glendinning return ret; 1391319b95b5SSteve Glendinning 1392319b95b5SSteve Glendinning val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); 1393319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_0; 1394319b95b5SSteve Glendinning 1395319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1396e360a8b4SSteve Glendinning if (ret < 0) 1397b052e073SSteve Glendinning return ret; 1398319b95b5SSteve Glendinning 1399319b95b5SSteve Glendinning /* clear wol status */ 1400319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1401319b95b5SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1402319b95b5SSteve Glendinning 1403319b95b5SSteve Glendinning /* enable energy detection */ 1404319b95b5SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1405319b95b5SSteve Glendinning val |= PM_CTL_WUPS_ED_; 1406319b95b5SSteve Glendinning 1407319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1408e360a8b4SSteve Glendinning if (ret < 0) 1409b052e073SSteve Glendinning return ret; 1410319b95b5SSteve Glendinning 1411319b95b5SSteve Glendinning /* read back PM_CTRL */ 1412319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 141376437214SMing Lei if (ret < 0) 141476437214SMing Lei return ret; 1415319b95b5SSteve Glendinning 1416b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND0; 1417b2d4b150SSteve Glendinning 141876437214SMing Lei return 0; 1419319b95b5SSteve Glendinning } 1420319b95b5SSteve Glendinning 1421319b95b5SSteve Glendinning static int smsc95xx_enter_suspend1(struct usbnet *dev) 1422319b95b5SSteve Glendinning { 1423319b95b5SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1424319b95b5SSteve Glendinning struct mii_if_info *mii = &dev->mii; 1425319b95b5SSteve Glendinning u32 val; 1426319b95b5SSteve Glendinning int ret; 1427319b95b5SSteve Glendinning 1428319b95b5SSteve Glendinning /* reconfigure link pulse detection timing for 1429319b95b5SSteve Glendinning * compatibility with non-standard link partners 1430319b95b5SSteve Glendinning */ 1431319b95b5SSteve Glendinning if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) 1432319b95b5SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG, 1433319b95b5SSteve Glendinning PHY_EDPD_CONFIG_DEFAULT); 1434319b95b5SSteve Glendinning 1435319b95b5SSteve Glendinning /* enable energy detect power-down mode */ 1436319b95b5SSteve Glendinning ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS); 1437e360a8b4SSteve Glendinning if (ret < 0) 1438b052e073SSteve Glendinning return ret; 1439319b95b5SSteve Glendinning 1440319b95b5SSteve Glendinning ret |= MODE_CTRL_STS_EDPWRDOWN_; 1441319b95b5SSteve Glendinning 1442319b95b5SSteve Glendinning smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret); 1443319b95b5SSteve Glendinning 1444319b95b5SSteve Glendinning /* enter SUSPEND1 mode */ 1445319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1446e360a8b4SSteve Glendinning if (ret < 0) 1447b052e073SSteve Glendinning return ret; 1448319b95b5SSteve Glendinning 1449319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1450319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_1; 1451319b95b5SSteve Glendinning 1452319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1453e360a8b4SSteve Glendinning if (ret < 0) 1454b052e073SSteve Glendinning return ret; 1455319b95b5SSteve Glendinning 1456319b95b5SSteve Glendinning /* clear wol status, enable energy detection */ 1457319b95b5SSteve Glendinning val &= ~PM_CTL_WUPS_; 1458319b95b5SSteve Glendinning val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); 1459319b95b5SSteve Glendinning 1460319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 146176437214SMing Lei if (ret < 0) 146276437214SMing Lei return ret; 1463319b95b5SSteve Glendinning 1464b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND1; 1465b2d4b150SSteve Glendinning 146676437214SMing Lei return 0; 1467319b95b5SSteve Glendinning } 1468319b95b5SSteve Glendinning 1469319b95b5SSteve Glendinning static int smsc95xx_enter_suspend2(struct usbnet *dev) 1470319b95b5SSteve Glendinning { 1471b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1472319b95b5SSteve Glendinning u32 val; 1473319b95b5SSteve Glendinning int ret; 1474319b95b5SSteve Glendinning 1475319b95b5SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1476e360a8b4SSteve Glendinning if (ret < 0) 1477b052e073SSteve Glendinning return ret; 1478319b95b5SSteve Glendinning 1479319b95b5SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1480319b95b5SSteve Glendinning val |= PM_CTL_SUS_MODE_2; 1481319b95b5SSteve Glendinning 1482319b95b5SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 148376437214SMing Lei if (ret < 0) 148476437214SMing Lei return ret; 1485319b95b5SSteve Glendinning 1486b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND2; 1487b2d4b150SSteve Glendinning 148876437214SMing Lei return 0; 1489319b95b5SSteve Glendinning } 1490319b95b5SSteve Glendinning 1491b2d4b150SSteve Glendinning static int smsc95xx_enter_suspend3(struct usbnet *dev) 1492b2d4b150SSteve Glendinning { 1493b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1494b2d4b150SSteve Glendinning u32 val; 1495b2d4b150SSteve Glendinning int ret; 1496b2d4b150SSteve Glendinning 1497b2d4b150SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val); 1498b2d4b150SSteve Glendinning if (ret < 0) 1499b2d4b150SSteve Glendinning return ret; 1500b2d4b150SSteve Glendinning 1501b2d4b150SSteve Glendinning if (val & 0xFFFF) { 1502b2d4b150SSteve Glendinning netdev_info(dev->net, "rx fifo not empty in autosuspend\n"); 1503b2d4b150SSteve Glendinning return -EBUSY; 1504b2d4b150SSteve Glendinning } 1505b2d4b150SSteve Glendinning 1506b2d4b150SSteve Glendinning ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1507b2d4b150SSteve Glendinning if (ret < 0) 1508b2d4b150SSteve Glendinning return ret; 1509b2d4b150SSteve Glendinning 1510b2d4b150SSteve Glendinning val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); 1511b2d4b150SSteve Glendinning val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS; 1512b2d4b150SSteve Glendinning 1513b2d4b150SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1514b2d4b150SSteve Glendinning if (ret < 0) 1515b2d4b150SSteve Glendinning return ret; 1516b2d4b150SSteve Glendinning 1517b2d4b150SSteve Glendinning /* clear wol status */ 1518b2d4b150SSteve Glendinning val &= ~PM_CTL_WUPS_; 1519b2d4b150SSteve Glendinning val |= PM_CTL_WUPS_WOL_; 1520b2d4b150SSteve Glendinning 1521b2d4b150SSteve Glendinning ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1522b2d4b150SSteve Glendinning if (ret < 0) 1523b2d4b150SSteve Glendinning return ret; 1524b2d4b150SSteve Glendinning 1525b2d4b150SSteve Glendinning pdata->suspend_flags |= SUSPEND_SUSPEND3; 1526b2d4b150SSteve Glendinning 1527b2d4b150SSteve Glendinning return 0; 1528b2d4b150SSteve Glendinning } 1529b2d4b150SSteve Glendinning 1530b2d4b150SSteve Glendinning static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up) 1531b2d4b150SSteve Glendinning { 1532b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1533b2d4b150SSteve Glendinning int ret; 1534b2d4b150SSteve Glendinning 1535b2d4b150SSteve Glendinning if (!netif_running(dev->net)) { 1536b2d4b150SSteve Glendinning /* interface is ifconfig down so fully power down hw */ 1537b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n"); 1538b2d4b150SSteve Glendinning return smsc95xx_enter_suspend2(dev); 1539b2d4b150SSteve Glendinning } 1540b2d4b150SSteve Glendinning 1541b2d4b150SSteve Glendinning if (!link_up) { 1542b2d4b150SSteve Glendinning /* link is down so enter EDPD mode, but only if device can 1543b2d4b150SSteve Glendinning * reliably resume from it. This check should be redundant 1544eb970ff0SMing Lei * as current FEATURE_REMOTE_WAKEUP parts also support 1545b2d4b150SSteve Glendinning * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */ 1546b2d4b150SSteve Glendinning if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) { 1547b2d4b150SSteve Glendinning netdev_warn(dev->net, "EDPD not supported\n"); 1548b2d4b150SSteve Glendinning return -EBUSY; 1549b2d4b150SSteve Glendinning } 1550b2d4b150SSteve Glendinning 1551b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n"); 1552b2d4b150SSteve Glendinning 1553b2d4b150SSteve Glendinning /* enable PHY wakeup events for if cable is attached */ 1554b2d4b150SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1555b2d4b150SSteve Glendinning PHY_INT_MASK_ANEG_COMP_); 1556b2d4b150SSteve Glendinning if (ret < 0) { 1557b2d4b150SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1558b2d4b150SSteve Glendinning return ret; 1559b2d4b150SSteve Glendinning } 1560b2d4b150SSteve Glendinning 1561b2d4b150SSteve Glendinning netdev_info(dev->net, "entering SUSPEND1 mode\n"); 1562b2d4b150SSteve Glendinning return smsc95xx_enter_suspend1(dev); 1563b2d4b150SSteve Glendinning } 1564b2d4b150SSteve Glendinning 1565b2d4b150SSteve Glendinning /* enable PHY wakeup events so we remote wakeup if cable is pulled */ 1566b2d4b150SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1567b2d4b150SSteve Glendinning PHY_INT_MASK_LINK_DOWN_); 1568b2d4b150SSteve Glendinning if (ret < 0) { 1569b2d4b150SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1570b2d4b150SSteve Glendinning return ret; 1571b2d4b150SSteve Glendinning } 1572b2d4b150SSteve Glendinning 1573b2d4b150SSteve Glendinning netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n"); 1574b2d4b150SSteve Glendinning return smsc95xx_enter_suspend3(dev); 1575b2d4b150SSteve Glendinning } 1576b2d4b150SSteve Glendinning 1577b5a04475SSteve Glendinning static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) 1578b5a04475SSteve Glendinning { 1579b5a04475SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 1580e0e474a8SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 1581e5e3af83SSteve Glendinning u32 val, link_up; 1582b5a04475SSteve Glendinning int ret; 1583b5a04475SSteve Glendinning 1584b5a04475SSteve Glendinning ret = usbnet_suspend(intf, message); 1585b052e073SSteve Glendinning if (ret < 0) { 1586b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_suspend error\n"); 1587b052e073SSteve Glendinning return ret; 1588b052e073SSteve Glendinning } 1589b5a04475SSteve Glendinning 1590b2d4b150SSteve Glendinning if (pdata->suspend_flags) { 1591b2d4b150SSteve Glendinning netdev_warn(dev->net, "error during last resume\n"); 1592b2d4b150SSteve Glendinning pdata->suspend_flags = 0; 1593b2d4b150SSteve Glendinning } 1594b2d4b150SSteve Glendinning 1595e5e3af83SSteve Glendinning /* determine if link is up using only _nopm functions */ 1596e5e3af83SSteve Glendinning link_up = smsc95xx_link_ok_nopm(dev); 1597e5e3af83SSteve Glendinning 159842e21c01SMing Lei if (message.event == PM_EVENT_AUTO_SUSPEND && 1599eb970ff0SMing Lei (pdata->features & FEATURE_REMOTE_WAKEUP)) { 1600b2d4b150SSteve Glendinning ret = smsc95xx_autosuspend(dev, link_up); 1601b2d4b150SSteve Glendinning goto done; 1602b2d4b150SSteve Glendinning } 1603b2d4b150SSteve Glendinning 1604b2d4b150SSteve Glendinning /* if we get this far we're not autosuspending */ 1605e5e3af83SSteve Glendinning /* if no wol options set, or if link is down and we're not waking on 1606e5e3af83SSteve Glendinning * PHY activity, enter lowest power SUSPEND2 mode 1607e5e3af83SSteve Glendinning */ 1608e5e3af83SSteve Glendinning if (!(pdata->wolopts & SUPPORTED_WAKE) || 1609e5e3af83SSteve Glendinning !(link_up || (pdata->wolopts & WAKE_PHY))) { 16101e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND2 mode\n"); 1611b5a04475SSteve Glendinning 1612e0e474a8SSteve Glendinning /* disable energy detect (link up) & wake up events */ 1613ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1614e360a8b4SSteve Glendinning if (ret < 0) 1615b052e073SSteve Glendinning goto done; 1616e0e474a8SSteve Glendinning 1617e0e474a8SSteve Glendinning val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); 1618e0e474a8SSteve Glendinning 1619ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1620e360a8b4SSteve Glendinning if (ret < 0) 1621b052e073SSteve Glendinning goto done; 1622e0e474a8SSteve Glendinning 1623ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1624e360a8b4SSteve Glendinning if (ret < 0) 1625b052e073SSteve Glendinning goto done; 1626e0e474a8SSteve Glendinning 1627e0e474a8SSteve Glendinning val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); 1628e0e474a8SSteve Glendinning 1629ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1630e360a8b4SSteve Glendinning if (ret < 0) 1631b052e073SSteve Glendinning goto done; 1632e0e474a8SSteve Glendinning 16333b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend2(dev); 16343b9f7d8cSSteve Glendinning goto done; 1635b5a04475SSteve Glendinning } 1636b5a04475SSteve Glendinning 1637e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) { 1638e5e3af83SSteve Glendinning ret = smsc95xx_enable_phy_wakeup_interrupts(dev, 1639e5e3af83SSteve Glendinning (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_)); 1640b052e073SSteve Glendinning if (ret < 0) { 1641b052e073SSteve Glendinning netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); 1642b052e073SSteve Glendinning goto done; 1643b052e073SSteve Glendinning } 1644e5e3af83SSteve Glendinning 1645e5e3af83SSteve Glendinning /* if link is down then configure EDPD and enter SUSPEND1, 1646e5e3af83SSteve Glendinning * otherwise enter SUSPEND0 below 1647e5e3af83SSteve Glendinning */ 1648e5e3af83SSteve Glendinning if (!link_up) { 16491e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND1 mode\n"); 16503b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend1(dev); 16513b9f7d8cSSteve Glendinning goto done; 1652e5e3af83SSteve Glendinning } 1653e5e3af83SSteve Glendinning } 1654e5e3af83SSteve Glendinning 1655bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 1656eed9a729SSteve Glendinning u32 *filter_mask = kzalloc(sizeof(u32) * 32, GFP_KERNEL); 165706a221beSMing Lei u32 command[2]; 165806a221beSMing Lei u32 offset[2]; 165906a221beSMing Lei u32 crc[4]; 16609ebca507SSteve Glendinning int wuff_filter_count = 16619ebca507SSteve Glendinning (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? 16629ebca507SSteve Glendinning LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; 1663bbd9f9eeSSteve Glendinning int i, filter = 0; 1664bbd9f9eeSSteve Glendinning 1665eed9a729SSteve Glendinning if (!filter_mask) { 1666eed9a729SSteve Glendinning netdev_warn(dev->net, "Unable to allocate filter_mask\n"); 16673b9f7d8cSSteve Glendinning ret = -ENOMEM; 16683b9f7d8cSSteve Glendinning goto done; 1669eed9a729SSteve Glendinning } 1670eed9a729SSteve Glendinning 167106a221beSMing Lei memset(command, 0, sizeof(command)); 167206a221beSMing Lei memset(offset, 0, sizeof(offset)); 167306a221beSMing Lei memset(crc, 0, sizeof(crc)); 167406a221beSMing Lei 1675bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_BCAST) { 1676bbd9f9eeSSteve Glendinning const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 16771e1d7412SJoe Perches netdev_info(dev->net, "enabling broadcast detection\n"); 1678bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1679bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1680bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1681bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1682bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1683bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1684bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(bcast, 6, filter); 1685bbd9f9eeSSteve Glendinning filter++; 1686bbd9f9eeSSteve Glendinning } 1687bbd9f9eeSSteve Glendinning 1688bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_MCAST) { 1689bbd9f9eeSSteve Glendinning const u8 mcast[] = {0x01, 0x00, 0x5E}; 16901e1d7412SJoe Perches netdev_info(dev->net, "enabling multicast detection\n"); 1691bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0007; 1692bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1693bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1694bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1695bbd9f9eeSSteve Glendinning command[filter/4] |= 0x09UL << ((filter % 4) * 8); 1696bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1697bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(mcast, 3, filter); 1698bbd9f9eeSSteve Glendinning filter++; 1699bbd9f9eeSSteve Glendinning } 1700bbd9f9eeSSteve Glendinning 1701bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_ARP) { 1702bbd9f9eeSSteve Glendinning const u8 arp[] = {0x08, 0x06}; 17031e1d7412SJoe Perches netdev_info(dev->net, "enabling ARP detection\n"); 1704bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x0003; 1705bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1706bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1707bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1708bbd9f9eeSSteve Glendinning command[filter/4] |= 0x05UL << ((filter % 4) * 8); 1709bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x0C << ((filter % 4) * 8); 1710bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(arp, 2, filter); 1711bbd9f9eeSSteve Glendinning filter++; 1712bbd9f9eeSSteve Glendinning } 1713bbd9f9eeSSteve Glendinning 1714bbd9f9eeSSteve Glendinning if (pdata->wolopts & WAKE_UCAST) { 17151e1d7412SJoe Perches netdev_info(dev->net, "enabling unicast detection\n"); 1716bbd9f9eeSSteve Glendinning filter_mask[filter * 4] = 0x003F; 1717bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 1] = 0x00; 1718bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 2] = 0x00; 1719bbd9f9eeSSteve Glendinning filter_mask[filter * 4 + 3] = 0x00; 1720bbd9f9eeSSteve Glendinning command[filter/4] |= 0x01UL << ((filter % 4) * 8); 1721bbd9f9eeSSteve Glendinning offset[filter/4] |= 0x00 << ((filter % 4) * 8); 1722bbd9f9eeSSteve Glendinning crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); 1723bbd9f9eeSSteve Glendinning filter++; 1724bbd9f9eeSSteve Glendinning } 1725bbd9f9eeSSteve Glendinning 17269ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count * 4); i++) { 1727ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]); 1728b052e073SSteve Glendinning if (ret < 0) { 172906a221beSMing Lei kfree(filter_mask); 1730b052e073SSteve Glendinning goto done; 1731b052e073SSteve Glendinning } 1732bbd9f9eeSSteve Glendinning } 173306a221beSMing Lei kfree(filter_mask); 1734bbd9f9eeSSteve Glendinning 17359ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1736ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]); 1737e360a8b4SSteve Glendinning if (ret < 0) 1738b052e073SSteve Glendinning goto done; 1739b052e073SSteve Glendinning } 1740bbd9f9eeSSteve Glendinning 17419ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 4); i++) { 1742ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]); 1743e360a8b4SSteve Glendinning if (ret < 0) 1744b052e073SSteve Glendinning goto done; 1745b052e073SSteve Glendinning } 1746bbd9f9eeSSteve Glendinning 17479ebca507SSteve Glendinning for (i = 0; i < (wuff_filter_count / 2); i++) { 1748ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]); 1749e360a8b4SSteve Glendinning if (ret < 0) 1750b052e073SSteve Glendinning goto done; 1751b052e073SSteve Glendinning } 1752bbd9f9eeSSteve Glendinning 1753bbd9f9eeSSteve Glendinning /* clear any pending pattern match packet status */ 1754ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1755e360a8b4SSteve Glendinning if (ret < 0) 1756b052e073SSteve Glendinning goto done; 1757bbd9f9eeSSteve Glendinning 1758bbd9f9eeSSteve Glendinning val |= WUCSR_WUFR_; 1759bbd9f9eeSSteve Glendinning 1760ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1761e360a8b4SSteve Glendinning if (ret < 0) 1762b052e073SSteve Glendinning goto done; 1763b052e073SSteve Glendinning } 1764bbd9f9eeSSteve Glendinning 1765e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 1766e0e474a8SSteve Glendinning /* clear any pending magic packet status */ 1767ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1768e360a8b4SSteve Glendinning if (ret < 0) 1769b052e073SSteve Glendinning goto done; 1770e0e474a8SSteve Glendinning 1771e0e474a8SSteve Glendinning val |= WUCSR_MPR_; 1772e0e474a8SSteve Glendinning 1773ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1774e360a8b4SSteve Glendinning if (ret < 0) 1775b052e073SSteve Glendinning goto done; 1776b052e073SSteve Glendinning } 1777e0e474a8SSteve Glendinning 1778bbd9f9eeSSteve Glendinning /* enable/disable wakeup sources */ 1779ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1780e360a8b4SSteve Glendinning if (ret < 0) 1781b052e073SSteve Glendinning goto done; 1782e0e474a8SSteve Glendinning 1783bbd9f9eeSSteve Glendinning if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { 17841e1d7412SJoe Perches netdev_info(dev->net, "enabling pattern match wakeup\n"); 1785bbd9f9eeSSteve Glendinning val |= WUCSR_WAKE_EN_; 1786bbd9f9eeSSteve Glendinning } else { 17871e1d7412SJoe Perches netdev_info(dev->net, "disabling pattern match wakeup\n"); 1788bbd9f9eeSSteve Glendinning val &= ~WUCSR_WAKE_EN_; 1789bbd9f9eeSSteve Glendinning } 1790bbd9f9eeSSteve Glendinning 1791e0e474a8SSteve Glendinning if (pdata->wolopts & WAKE_MAGIC) { 17921e1d7412SJoe Perches netdev_info(dev->net, "enabling magic packet wakeup\n"); 1793e0e474a8SSteve Glendinning val |= WUCSR_MPEN_; 1794e0e474a8SSteve Glendinning } else { 17951e1d7412SJoe Perches netdev_info(dev->net, "disabling magic packet wakeup\n"); 1796e0e474a8SSteve Glendinning val &= ~WUCSR_MPEN_; 1797e0e474a8SSteve Glendinning } 1798e0e474a8SSteve Glendinning 1799ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1800e360a8b4SSteve Glendinning if (ret < 0) 1801b052e073SSteve Glendinning goto done; 1802e0e474a8SSteve Glendinning 1803e0e474a8SSteve Glendinning /* enable wol wakeup source */ 1804ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1805e360a8b4SSteve Glendinning if (ret < 0) 1806b052e073SSteve Glendinning goto done; 1807e0e474a8SSteve Glendinning 1808e0e474a8SSteve Glendinning val |= PM_CTL_WOL_EN_; 1809e0e474a8SSteve Glendinning 1810e5e3af83SSteve Glendinning /* phy energy detect wakeup source */ 1811e5e3af83SSteve Glendinning if (pdata->wolopts & WAKE_PHY) 1812e5e3af83SSteve Glendinning val |= PM_CTL_ED_EN_; 1813e5e3af83SSteve Glendinning 1814ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1815e360a8b4SSteve Glendinning if (ret < 0) 1816b052e073SSteve Glendinning goto done; 1817e0e474a8SSteve Glendinning 1818bbd9f9eeSSteve Glendinning /* enable receiver to enable frame reception */ 1819ec32115dSMing Lei smsc95xx_start_rx_path(dev, 1); 1820e0e474a8SSteve Glendinning 1821e0e474a8SSteve Glendinning /* some wol options are enabled, so enter SUSPEND0 */ 18221e1d7412SJoe Perches netdev_info(dev->net, "entering SUSPEND0 mode\n"); 18233b9f7d8cSSteve Glendinning ret = smsc95xx_enter_suspend0(dev); 18243b9f7d8cSSteve Glendinning 18253b9f7d8cSSteve Glendinning done: 18260d41be53SMing Lei /* 18270d41be53SMing Lei * TODO: resume() might need to handle the suspend failure 18280d41be53SMing Lei * in system sleep 18290d41be53SMing Lei */ 18300d41be53SMing Lei if (ret && PMSG_IS_AUTO(message)) 18313b9f7d8cSSteve Glendinning usbnet_resume(intf); 18323b9f7d8cSSteve Glendinning return ret; 1833e0e474a8SSteve Glendinning } 1834e0e474a8SSteve Glendinning 1835e0e474a8SSteve Glendinning static int smsc95xx_resume(struct usb_interface *intf) 1836e0e474a8SSteve Glendinning { 1837e0e474a8SSteve Glendinning struct usbnet *dev = usb_get_intfdata(intf); 18388bca81d9SSudip Mukherjee struct smsc95xx_priv *pdata; 18398bca81d9SSudip Mukherjee u8 suspend_flags; 1840e0e474a8SSteve Glendinning int ret; 1841e0e474a8SSteve Glendinning u32 val; 1842e0e474a8SSteve Glendinning 1843e0e474a8SSteve Glendinning BUG_ON(!dev); 18448bca81d9SSudip Mukherjee pdata = (struct smsc95xx_priv *)(dev->data[0]); 18458bca81d9SSudip Mukherjee suspend_flags = pdata->suspend_flags; 1846e0e474a8SSteve Glendinning 1847b2d4b150SSteve Glendinning netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags); 1848b2d4b150SSteve Glendinning 1849b2d4b150SSteve Glendinning /* do this first to ensure it's cleared even in error case */ 1850b2d4b150SSteve Glendinning pdata->suspend_flags = 0; 1851d69d1694SChristoph Fritz schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); 1852b2d4b150SSteve Glendinning 1853b2d4b150SSteve Glendinning if (suspend_flags & SUSPEND_ALLMODES) { 1854bbd9f9eeSSteve Glendinning /* clear wake-up sources */ 1855ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); 1856e360a8b4SSteve Glendinning if (ret < 0) 1857b052e073SSteve Glendinning return ret; 1858e0e474a8SSteve Glendinning 1859bbd9f9eeSSteve Glendinning val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); 1860e0e474a8SSteve Glendinning 1861ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); 1862e360a8b4SSteve Glendinning if (ret < 0) 1863b052e073SSteve Glendinning return ret; 1864e0e474a8SSteve Glendinning 1865e0e474a8SSteve Glendinning /* clear wake-up status */ 1866ec32115dSMing Lei ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); 1867e360a8b4SSteve Glendinning if (ret < 0) 1868b052e073SSteve Glendinning return ret; 1869e0e474a8SSteve Glendinning 1870e0e474a8SSteve Glendinning val &= ~PM_CTL_WOL_EN_; 1871e0e474a8SSteve Glendinning val |= PM_CTL_WUPS_; 1872e0e474a8SSteve Glendinning 1873ec32115dSMing Lei ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); 1874e360a8b4SSteve Glendinning if (ret < 0) 1875b052e073SSteve Glendinning return ret; 1876b052e073SSteve Glendinning } 1877e0e474a8SSteve Glendinning 1878af3d7c1eSSteve Glendinning ret = usbnet_resume(intf); 1879b052e073SSteve Glendinning if (ret < 0) 1880b052e073SSteve Glendinning netdev_warn(dev->net, "usbnet_resume error\n"); 1881e0e474a8SSteve Glendinning 1882b052e073SSteve Glendinning return ret; 1883e0e474a8SSteve Glendinning } 1884e0e474a8SSteve Glendinning 1885b4df480fSJoonyoung Shim static int smsc95xx_reset_resume(struct usb_interface *intf) 1886b4df480fSJoonyoung Shim { 1887b4df480fSJoonyoung Shim struct usbnet *dev = usb_get_intfdata(intf); 1888b4df480fSJoonyoung Shim int ret; 1889b4df480fSJoonyoung Shim 1890b4df480fSJoonyoung Shim ret = smsc95xx_reset(dev); 1891b4df480fSJoonyoung Shim if (ret < 0) 1892b4df480fSJoonyoung Shim return ret; 1893b4df480fSJoonyoung Shim 1894b4df480fSJoonyoung Shim return smsc95xx_resume(intf); 1895b4df480fSJoonyoung Shim } 1896b4df480fSJoonyoung Shim 18972f7ca802SSteve Glendinning static void smsc95xx_rx_csum_offload(struct sk_buff *skb) 18982f7ca802SSteve Glendinning { 18992f7ca802SSteve Glendinning skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); 19002f7ca802SSteve Glendinning skb->ip_summed = CHECKSUM_COMPLETE; 19012f7ca802SSteve Glendinning skb_trim(skb, skb->len - 2); 19022f7ca802SSteve Glendinning } 19032f7ca802SSteve Glendinning 19042f7ca802SSteve Glendinning static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 19052f7ca802SSteve Glendinning { 1906eb85569fSEmil Goode /* This check is no longer done by usbnet */ 1907eb85569fSEmil Goode if (skb->len < dev->net->hard_header_len) 1908eb85569fSEmil Goode return 0; 1909eb85569fSEmil Goode 19102f7ca802SSteve Glendinning while (skb->len > 0) { 19112f7ca802SSteve Glendinning u32 header, align_count; 19122f7ca802SSteve Glendinning struct sk_buff *ax_skb; 19132f7ca802SSteve Glendinning unsigned char *packet; 19142f7ca802SSteve Glendinning u16 size; 19152f7ca802SSteve Glendinning 19162f7ca802SSteve Glendinning memcpy(&header, skb->data, sizeof(header)); 19172f7ca802SSteve Glendinning le32_to_cpus(&header); 19182f7ca802SSteve Glendinning skb_pull(skb, 4 + NET_IP_ALIGN); 19192f7ca802SSteve Glendinning packet = skb->data; 19202f7ca802SSteve Glendinning 19212f7ca802SSteve Glendinning /* get the packet length */ 19222f7ca802SSteve Glendinning size = (u16)((header & RX_STS_FL_) >> 16); 19232f7ca802SSteve Glendinning align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; 19242f7ca802SSteve Glendinning 19252f7ca802SSteve Glendinning if (unlikely(header & RX_STS_ES_)) { 1926a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1927a475f603SJoe Perches "Error header=0x%08x\n", header); 192880667ac1SHerbert Xu dev->net->stats.rx_errors++; 192980667ac1SHerbert Xu dev->net->stats.rx_dropped++; 19302f7ca802SSteve Glendinning 19312f7ca802SSteve Glendinning if (header & RX_STS_CRC_) { 193280667ac1SHerbert Xu dev->net->stats.rx_crc_errors++; 19332f7ca802SSteve Glendinning } else { 19342f7ca802SSteve Glendinning if (header & (RX_STS_TL_ | RX_STS_RF_)) 193580667ac1SHerbert Xu dev->net->stats.rx_frame_errors++; 19362f7ca802SSteve Glendinning 19372f7ca802SSteve Glendinning if ((header & RX_STS_LE_) && 19382f7ca802SSteve Glendinning (!(header & RX_STS_FT_))) 193980667ac1SHerbert Xu dev->net->stats.rx_length_errors++; 19402f7ca802SSteve Glendinning } 19412f7ca802SSteve Glendinning } else { 19422f7ca802SSteve Glendinning /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ 19432f7ca802SSteve Glendinning if (unlikely(size > (ETH_FRAME_LEN + 12))) { 1944a475f603SJoe Perches netif_dbg(dev, rx_err, dev->net, 1945a475f603SJoe Perches "size err header=0x%08x\n", header); 19462f7ca802SSteve Glendinning return 0; 19472f7ca802SSteve Glendinning } 19482f7ca802SSteve Glendinning 19492f7ca802SSteve Glendinning /* last frame in this batch */ 19502f7ca802SSteve Glendinning if (skb->len == size) { 195178e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 19522f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(skb); 1953df18accaSPeter Korsgaard skb_trim(skb, skb->len - 4); /* remove fcs */ 19542f7ca802SSteve Glendinning skb->truesize = size + sizeof(struct sk_buff); 19552f7ca802SSteve Glendinning 19562f7ca802SSteve Glendinning return 1; 19572f7ca802SSteve Glendinning } 19582f7ca802SSteve Glendinning 19592f7ca802SSteve Glendinning ax_skb = skb_clone(skb, GFP_ATOMIC); 19602f7ca802SSteve Glendinning if (unlikely(!ax_skb)) { 196160b86755SJoe Perches netdev_warn(dev->net, "Error allocating skb\n"); 19622f7ca802SSteve Glendinning return 0; 19632f7ca802SSteve Glendinning } 19642f7ca802SSteve Glendinning 19652f7ca802SSteve Glendinning ax_skb->len = size; 19662f7ca802SSteve Glendinning ax_skb->data = packet; 19672f7ca802SSteve Glendinning skb_set_tail_pointer(ax_skb, size); 19682f7ca802SSteve Glendinning 196978e47fe4SMichał Mirosław if (dev->net->features & NETIF_F_RXCSUM) 19702f7ca802SSteve Glendinning smsc95xx_rx_csum_offload(ax_skb); 1971df18accaSPeter Korsgaard skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ 19722f7ca802SSteve Glendinning ax_skb->truesize = size + sizeof(struct sk_buff); 19732f7ca802SSteve Glendinning 19742f7ca802SSteve Glendinning usbnet_skb_return(dev, ax_skb); 19752f7ca802SSteve Glendinning } 19762f7ca802SSteve Glendinning 19772f7ca802SSteve Glendinning skb_pull(skb, size); 19782f7ca802SSteve Glendinning 19792f7ca802SSteve Glendinning /* padding bytes before the next frame starts */ 19802f7ca802SSteve Glendinning if (skb->len) 19812f7ca802SSteve Glendinning skb_pull(skb, align_count); 19822f7ca802SSteve Glendinning } 19832f7ca802SSteve Glendinning 19842f7ca802SSteve Glendinning return 1; 19852f7ca802SSteve Glendinning } 19862f7ca802SSteve Glendinning 1987f7b29271SSteve Glendinning static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) 1988f7b29271SSteve Glendinning { 198955508d60SMichał Mirosław u16 low_16 = (u16)skb_checksum_start_offset(skb); 199055508d60SMichał Mirosław u16 high_16 = low_16 + skb->csum_offset; 1991f7b29271SSteve Glendinning return (high_16 << 16) | low_16; 1992f7b29271SSteve Glendinning } 1993f7b29271SSteve Glendinning 19942f7ca802SSteve Glendinning static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, 19952f7ca802SSteve Glendinning struct sk_buff *skb, gfp_t flags) 19962f7ca802SSteve Glendinning { 199778e47fe4SMichał Mirosław bool csum = skb->ip_summed == CHECKSUM_PARTIAL; 1998f7b29271SSteve Glendinning int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; 19992f7ca802SSteve Glendinning u32 tx_cmd_a, tx_cmd_b; 20002f7ca802SSteve Glendinning 2001f7b29271SSteve Glendinning /* We do not advertise SG, so skbs should be already linearized */ 2002f7b29271SSteve Glendinning BUG_ON(skb_shinfo(skb)->nr_frags); 2003f7b29271SSteve Glendinning 2004f7b29271SSteve Glendinning if (skb_headroom(skb) < overhead) { 20052f7ca802SSteve Glendinning struct sk_buff *skb2 = skb_copy_expand(skb, 2006f7b29271SSteve Glendinning overhead, 0, flags); 20072f7ca802SSteve Glendinning dev_kfree_skb_any(skb); 20082f7ca802SSteve Glendinning skb = skb2; 20092f7ca802SSteve Glendinning if (!skb) 20102f7ca802SSteve Glendinning return NULL; 20112f7ca802SSteve Glendinning } 20122f7ca802SSteve Glendinning 2013f7b29271SSteve Glendinning if (csum) { 201411bc3088SSteve Glendinning if (skb->len <= 45) { 201511bc3088SSteve Glendinning /* workaround - hardware tx checksum does not work 201611bc3088SSteve Glendinning * properly with extremely small packets */ 201755508d60SMichał Mirosław long csstart = skb_checksum_start_offset(skb); 201811bc3088SSteve Glendinning __wsum calc = csum_partial(skb->data + csstart, 201911bc3088SSteve Glendinning skb->len - csstart, 0); 202011bc3088SSteve Glendinning *((__sum16 *)(skb->data + csstart 202111bc3088SSteve Glendinning + skb->csum_offset)) = csum_fold(calc); 202211bc3088SSteve Glendinning 202311bc3088SSteve Glendinning csum = false; 202411bc3088SSteve Glendinning } else { 2025f7b29271SSteve Glendinning u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); 2026f7b29271SSteve Glendinning skb_push(skb, 4); 202700acda68SSteve Glendinning cpu_to_le32s(&csum_preamble); 2028f7b29271SSteve Glendinning memcpy(skb->data, &csum_preamble, 4); 2029f7b29271SSteve Glendinning } 203011bc3088SSteve Glendinning } 2031f7b29271SSteve Glendinning 20322f7ca802SSteve Glendinning skb_push(skb, 4); 20332f7ca802SSteve Glendinning tx_cmd_b = (u32)(skb->len - 4); 2034f7b29271SSteve Glendinning if (csum) 2035f7b29271SSteve Glendinning tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; 20362f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_b); 20372f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_b, 4); 20382f7ca802SSteve Glendinning 20392f7ca802SSteve Glendinning skb_push(skb, 4); 20402f7ca802SSteve Glendinning tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ | 20412f7ca802SSteve Glendinning TX_CMD_A_LAST_SEG_; 20422f7ca802SSteve Glendinning cpu_to_le32s(&tx_cmd_a); 20432f7ca802SSteve Glendinning memcpy(skb->data, &tx_cmd_a, 4); 20442f7ca802SSteve Glendinning 20452f7ca802SSteve Glendinning return skb; 20462f7ca802SSteve Glendinning } 20472f7ca802SSteve Glendinning 2048b2d4b150SSteve Glendinning static int smsc95xx_manage_power(struct usbnet *dev, int on) 2049b2d4b150SSteve Glendinning { 2050b2d4b150SSteve Glendinning struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); 2051b2d4b150SSteve Glendinning 2052b2d4b150SSteve Glendinning dev->intf->needs_remote_wakeup = on; 2053b2d4b150SSteve Glendinning 2054eb970ff0SMing Lei if (pdata->features & FEATURE_REMOTE_WAKEUP) 2055b2d4b150SSteve Glendinning return 0; 2056b2d4b150SSteve Glendinning 2057eb970ff0SMing Lei /* this chip revision isn't capable of remote wakeup */ 2058eb970ff0SMing Lei netdev_info(dev->net, "hardware isn't capable of remote wakeup\n"); 2059b2d4b150SSteve Glendinning 2060b2d4b150SSteve Glendinning if (on) 2061b2d4b150SSteve Glendinning usb_autopm_get_interface_no_resume(dev->intf); 2062b2d4b150SSteve Glendinning else 2063b2d4b150SSteve Glendinning usb_autopm_put_interface(dev->intf); 2064b2d4b150SSteve Glendinning 2065b2d4b150SSteve Glendinning return 0; 2066b2d4b150SSteve Glendinning } 2067b2d4b150SSteve Glendinning 20682f7ca802SSteve Glendinning static const struct driver_info smsc95xx_info = { 20692f7ca802SSteve Glendinning .description = "smsc95xx USB 2.0 Ethernet", 20702f7ca802SSteve Glendinning .bind = smsc95xx_bind, 20712f7ca802SSteve Glendinning .unbind = smsc95xx_unbind, 20722f7ca802SSteve Glendinning .link_reset = smsc95xx_link_reset, 20732f7ca802SSteve Glendinning .reset = smsc95xx_reset, 20742f7ca802SSteve Glendinning .rx_fixup = smsc95xx_rx_fixup, 20752f7ca802SSteve Glendinning .tx_fixup = smsc95xx_tx_fixup, 20762f7ca802SSteve Glendinning .status = smsc95xx_status, 2077b2d4b150SSteve Glendinning .manage_power = smsc95xx_manage_power, 207807d69d42SPaolo Pisati .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, 20792f7ca802SSteve Glendinning }; 20802f7ca802SSteve Glendinning 20812f7ca802SSteve Glendinning static const struct usb_device_id products[] = { 20822f7ca802SSteve Glendinning { 20832f7ca802SSteve Glendinning /* SMSC9500 USB Ethernet Device */ 20842f7ca802SSteve Glendinning USB_DEVICE(0x0424, 0x9500), 20852f7ca802SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20862f7ca802SSteve Glendinning }, 2087726474b8SSteve Glendinning { 20886f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device */ 20896f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9505), 20906f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20916f41d12bSSteve Glendinning }, 20926f41d12bSSteve Glendinning { 20936f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device */ 20946f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E00), 20956f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 20966f41d12bSSteve Glendinning }, 20976f41d12bSSteve Glendinning { 20986f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device */ 20996f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9E01), 21006f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21016f41d12bSSteve Glendinning }, 21026f41d12bSSteve Glendinning { 2103726474b8SSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device */ 2104726474b8SSteve Glendinning USB_DEVICE(0x0424, 0xec00), 2105726474b8SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 2106726474b8SSteve Glendinning }, 21076f41d12bSSteve Glendinning { 21086f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (SAL10) */ 21096f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9900), 21106f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21116f41d12bSSteve Glendinning }, 21126f41d12bSSteve Glendinning { 21136f41d12bSSteve Glendinning /* SMSC9505 USB Ethernet Device (SAL10) */ 21146f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9901), 21156f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21166f41d12bSSteve Glendinning }, 21176f41d12bSSteve Glendinning { 21186f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (SAL10) */ 21196f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9902), 21206f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21216f41d12bSSteve Glendinning }, 21226f41d12bSSteve Glendinning { 21236f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (SAL10) */ 21246f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9903), 21256f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21266f41d12bSSteve Glendinning }, 21276f41d12bSSteve Glendinning { 21286f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ 21296f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9904), 21306f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21316f41d12bSSteve Glendinning }, 21326f41d12bSSteve Glendinning { 21336f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (HAL) */ 21346f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9905), 21356f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21366f41d12bSSteve Glendinning }, 21376f41d12bSSteve Glendinning { 21386f41d12bSSteve Glendinning /* SMSC9505A USB Ethernet Device (HAL) */ 21396f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9906), 21406f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21416f41d12bSSteve Glendinning }, 21426f41d12bSSteve Glendinning { 21436f41d12bSSteve Glendinning /* SMSC9500 USB Ethernet Device (Alternate ID) */ 21446f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9907), 21456f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21466f41d12bSSteve Glendinning }, 21476f41d12bSSteve Glendinning { 21486f41d12bSSteve Glendinning /* SMSC9500A USB Ethernet Device (Alternate ID) */ 21496f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9908), 21506f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21516f41d12bSSteve Glendinning }, 21526f41d12bSSteve Glendinning { 21536f41d12bSSteve Glendinning /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ 21546f41d12bSSteve Glendinning USB_DEVICE(0x0424, 0x9909), 21556f41d12bSSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 21566f41d12bSSteve Glendinning }, 215788edaa41SSteve Glendinning { 215888edaa41SSteve Glendinning /* SMSC LAN9530 USB Ethernet Device */ 215988edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9530), 216088edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 216188edaa41SSteve Glendinning }, 216288edaa41SSteve Glendinning { 216388edaa41SSteve Glendinning /* SMSC LAN9730 USB Ethernet Device */ 216488edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9730), 216588edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 216688edaa41SSteve Glendinning }, 216788edaa41SSteve Glendinning { 216888edaa41SSteve Glendinning /* SMSC LAN89530 USB Ethernet Device */ 216988edaa41SSteve Glendinning USB_DEVICE(0x0424, 0x9E08), 217088edaa41SSteve Glendinning .driver_info = (unsigned long) &smsc95xx_info, 217188edaa41SSteve Glendinning }, 21722f7ca802SSteve Glendinning { }, /* END */ 21732f7ca802SSteve Glendinning }; 21742f7ca802SSteve Glendinning MODULE_DEVICE_TABLE(usb, products); 21752f7ca802SSteve Glendinning 21762f7ca802SSteve Glendinning static struct usb_driver smsc95xx_driver = { 21772f7ca802SSteve Glendinning .name = "smsc95xx", 21782f7ca802SSteve Glendinning .id_table = products, 21792f7ca802SSteve Glendinning .probe = usbnet_probe, 2180b5a04475SSteve Glendinning .suspend = smsc95xx_suspend, 2181e0e474a8SSteve Glendinning .resume = smsc95xx_resume, 2182b4df480fSJoonyoung Shim .reset_resume = smsc95xx_reset_resume, 21832f7ca802SSteve Glendinning .disconnect = usbnet_disconnect, 2184e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 2185b2d4b150SSteve Glendinning .supports_autosuspend = 1, 21862f7ca802SSteve Glendinning }; 21872f7ca802SSteve Glendinning 2188d632eb1bSGreg Kroah-Hartman module_usb_driver(smsc95xx_driver); 21892f7ca802SSteve Glendinning 21902f7ca802SSteve Glendinning MODULE_AUTHOR("Nancy Lin"); 219190b24cfbSSteve Glendinning MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); 21922f7ca802SSteve Glendinning MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); 21932f7ca802SSteve Glendinning MODULE_LICENSE("GPL"); 2194