Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2 | /*************************************************************************** |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 SMSC |
| 5 | * |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 6 | *****************************************************************************/ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/kmod.h> |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
| 11 | #include <linux/etherdevice.h> |
| 12 | #include <linux/ethtool.h> |
| 13 | #include <linux/mii.h> |
| 14 | #include <linux/usb.h> |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 15 | #include <linux/bitrev.h> |
| 16 | #include <linux/crc16.h> |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 17 | #include <linux/crc32.h> |
| 18 | #include <linux/usb/usbnet.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 20 | #include <linux/of_net.h> |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 21 | #include "smsc95xx.h" |
| 22 | |
| 23 | #define SMSC_CHIPNAME "smsc95xx" |
Martin Wetterwald | 53a759c | 2017-04-13 10:08:44 +0200 | [diff] [blame] | 24 | #define SMSC_DRIVER_VERSION "1.0.6" |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 25 | #define HS_USB_PKT_SIZE (512) |
| 26 | #define FS_USB_PKT_SIZE (64) |
| 27 | #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE) |
| 28 | #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE) |
| 29 | #define DEFAULT_BULK_IN_DELAY (0x00002000) |
| 30 | #define MAX_SINGLE_PACKET_SIZE (2048) |
| 31 | #define LAN95XX_EEPROM_MAGIC (0x9500) |
| 32 | #define EEPROM_MAC_OFFSET (0x01) |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 33 | #define DEFAULT_TX_CSUM_ENABLE (true) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 34 | #define DEFAULT_RX_CSUM_ENABLE (true) |
| 35 | #define SMSC95XX_INTERNAL_PHY_ID (1) |
| 36 | #define SMSC95XX_TX_OVERHEAD (8) |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 37 | #define SMSC95XX_TX_OVERHEAD_CSUM (12) |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 38 | #define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \ |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 39 | WAKE_MCAST | WAKE_ARP | WAKE_MAGIC) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 40 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 41 | #define FEATURE_8_WAKEUP_FILTERS (0x01) |
| 42 | #define FEATURE_PHY_NLP_CROSSOVER (0x02) |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 43 | #define FEATURE_REMOTE_WAKEUP (0x04) |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 44 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 45 | #define SUSPEND_SUSPEND0 (0x01) |
| 46 | #define SUSPEND_SUSPEND1 (0x02) |
| 47 | #define SUSPEND_SUSPEND2 (0x04) |
| 48 | #define SUSPEND_SUSPEND3 (0x08) |
| 49 | #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \ |
| 50 | SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3) |
| 51 | |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 52 | #define CARRIER_CHECK_DELAY (2 * HZ) |
| 53 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 54 | struct smsc95xx_priv { |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 55 | u32 chip_id; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 56 | u32 mac_cr; |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 57 | u32 hash_hi; |
| 58 | u32 hash_lo; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 59 | u32 wolopts; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 60 | spinlock_t mac_cr_lock; |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 61 | u8 features; |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 62 | u8 suspend_flags; |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 63 | u8 mdix_ctrl; |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 64 | bool link_ok; |
| 65 | struct delayed_work carrier_check; |
| 66 | struct usbnet *dev; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
Rusty Russell | eb93992 | 2011-12-19 14:08:01 +0000 | [diff] [blame] | 69 | static bool turbo_mode = true; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 70 | module_param(turbo_mode, bool, 0644); |
| 71 | MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); |
| 72 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 73 | static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, |
| 74 | u32 *data, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 75 | { |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 76 | u32 buf; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 77 | int ret; |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 78 | int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 79 | |
| 80 | BUG_ON(!dev); |
| 81 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 82 | if (!in_pm) |
| 83 | fn = usbnet_read_cmd; |
| 84 | else |
| 85 | fn = usbnet_read_cmd_nopm; |
| 86 | |
| 87 | ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN |
| 88 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 89 | 0, index, &buf, 4); |
Dan Carpenter | 5a36b68 | 2016-05-04 09:22:01 +0300 | [diff] [blame] | 90 | if (unlikely(ret < 0)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 91 | netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n", |
| 92 | index, ret); |
Dan Carpenter | 5a36b68 | 2016-05-04 09:22:01 +0300 | [diff] [blame] | 93 | return ret; |
| 94 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 95 | |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 96 | le32_to_cpus(&buf); |
| 97 | *data = buf; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 102 | static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index, |
| 103 | u32 data, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 104 | { |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 105 | u32 buf; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 106 | int ret; |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 107 | int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 108 | |
| 109 | BUG_ON(!dev); |
| 110 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 111 | if (!in_pm) |
| 112 | fn = usbnet_write_cmd; |
| 113 | else |
| 114 | fn = usbnet_write_cmd_nopm; |
| 115 | |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 116 | buf = data; |
| 117 | cpu_to_le32s(&buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 118 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 119 | ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT |
| 120 | | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 121 | 0, index, &buf, 4); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 122 | if (unlikely(ret < 0)) |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 123 | netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n", |
| 124 | index, ret); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 125 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 126 | return ret; |
| 127 | } |
| 128 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 129 | static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index, |
| 130 | u32 *data) |
| 131 | { |
| 132 | return __smsc95xx_read_reg(dev, index, data, 1); |
| 133 | } |
| 134 | |
| 135 | static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index, |
| 136 | u32 data) |
| 137 | { |
| 138 | return __smsc95xx_write_reg(dev, index, data, 1); |
| 139 | } |
| 140 | |
| 141 | static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index, |
| 142 | u32 *data) |
| 143 | { |
| 144 | return __smsc95xx_read_reg(dev, index, data, 0); |
| 145 | } |
| 146 | |
| 147 | static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index, |
| 148 | u32 data) |
| 149 | { |
| 150 | return __smsc95xx_write_reg(dev, index, data, 0); |
| 151 | } |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 152 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 153 | /* Loop until the read is completed with timeout |
| 154 | * called with phy_mutex held */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 155 | static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev, |
| 156 | int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 157 | { |
| 158 | unsigned long start_time = jiffies; |
| 159 | u32 val; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 160 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 161 | |
| 162 | do { |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 163 | ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 164 | if (ret < 0) { |
| 165 | netdev_warn(dev->net, "Error reading MII_ACCESS\n"); |
| 166 | return ret; |
| 167 | } |
| 168 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 169 | if (!(val & MII_BUSY_)) |
| 170 | return 0; |
| 171 | } while (!time_after(jiffies, start_time + HZ)); |
| 172 | |
| 173 | return -EIO; |
| 174 | } |
| 175 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 176 | static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx, |
| 177 | int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 178 | { |
| 179 | struct usbnet *dev = netdev_priv(netdev); |
| 180 | u32 val, addr; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 181 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 182 | |
| 183 | mutex_lock(&dev->phy_mutex); |
| 184 | |
| 185 | /* confirm MII not busy */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 186 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 187 | if (ret < 0) { |
| 188 | netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n"); |
| 189 | goto done; |
| 190 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 191 | |
| 192 | /* set the address, index & direction (read from PHY) */ |
| 193 | phy_id &= dev->mii.phy_id_mask; |
| 194 | idx &= dev->mii.reg_num_mask; |
Steve Glendinning | 8092880 | 2012-11-06 00:08:53 +0000 | [diff] [blame] | 195 | addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 196 | ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 197 | if (ret < 0) { |
| 198 | netdev_warn(dev->net, "Error writing MII_ADDR\n"); |
| 199 | goto done; |
| 200 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 201 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 202 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 203 | if (ret < 0) { |
| 204 | netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); |
| 205 | goto done; |
| 206 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 207 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 208 | ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 209 | if (ret < 0) { |
| 210 | netdev_warn(dev->net, "Error reading MII_DATA\n"); |
| 211 | goto done; |
| 212 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 213 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 214 | ret = (u16)(val & 0xFFFF); |
| 215 | |
| 216 | done: |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 217 | mutex_unlock(&dev->phy_mutex); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 218 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 221 | static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, |
| 222 | int idx, int regval, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 223 | { |
| 224 | struct usbnet *dev = netdev_priv(netdev); |
| 225 | u32 val, addr; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 226 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 227 | |
| 228 | mutex_lock(&dev->phy_mutex); |
| 229 | |
| 230 | /* confirm MII not busy */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 231 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 232 | if (ret < 0) { |
| 233 | netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n"); |
| 234 | goto done; |
| 235 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 236 | |
| 237 | val = regval; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 238 | ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 239 | if (ret < 0) { |
| 240 | netdev_warn(dev->net, "Error writing MII_DATA\n"); |
| 241 | goto done; |
| 242 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 243 | |
| 244 | /* set the address, index & direction (write to PHY) */ |
| 245 | phy_id &= dev->mii.phy_id_mask; |
| 246 | idx &= dev->mii.reg_num_mask; |
Steve Glendinning | 8092880 | 2012-11-06 00:08:53 +0000 | [diff] [blame] | 247 | addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 248 | ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 249 | if (ret < 0) { |
| 250 | netdev_warn(dev->net, "Error writing MII_ADDR\n"); |
| 251 | goto done; |
| 252 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 253 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 254 | ret = __smsc95xx_phy_wait_not_busy(dev, in_pm); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 255 | if (ret < 0) { |
| 256 | netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); |
| 257 | goto done; |
| 258 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 259 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 260 | done: |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 261 | mutex_unlock(&dev->phy_mutex); |
| 262 | } |
| 263 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 264 | static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id, |
| 265 | int idx) |
| 266 | { |
| 267 | return __smsc95xx_mdio_read(netdev, phy_id, idx, 1); |
| 268 | } |
| 269 | |
| 270 | static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id, |
| 271 | int idx, int regval) |
| 272 | { |
| 273 | __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1); |
| 274 | } |
| 275 | |
| 276 | static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) |
| 277 | { |
| 278 | return __smsc95xx_mdio_read(netdev, phy_id, idx, 0); |
| 279 | } |
| 280 | |
| 281 | static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, |
| 282 | int regval) |
| 283 | { |
| 284 | __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0); |
| 285 | } |
| 286 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 287 | static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 288 | { |
| 289 | unsigned long start_time = jiffies; |
| 290 | u32 val; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 291 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 292 | |
| 293 | do { |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 294 | ret = smsc95xx_read_reg(dev, E2P_CMD, &val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 295 | if (ret < 0) { |
| 296 | netdev_warn(dev->net, "Error reading E2P_CMD\n"); |
| 297 | return ret; |
| 298 | } |
| 299 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 300 | if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) |
| 301 | break; |
| 302 | udelay(40); |
| 303 | } while (!time_after(jiffies, start_time + HZ)); |
| 304 | |
| 305 | if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 306 | netdev_warn(dev->net, "EEPROM read operation timeout\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 307 | return -EIO; |
| 308 | } |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 313 | static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 314 | { |
| 315 | unsigned long start_time = jiffies; |
| 316 | u32 val; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 317 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 318 | |
| 319 | do { |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 320 | ret = smsc95xx_read_reg(dev, E2P_CMD, &val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 321 | if (ret < 0) { |
| 322 | netdev_warn(dev->net, "Error reading E2P_CMD\n"); |
| 323 | return ret; |
| 324 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 325 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 326 | if (!(val & E2P_CMD_BUSY_)) |
| 327 | return 0; |
| 328 | |
| 329 | udelay(40); |
| 330 | } while (!time_after(jiffies, start_time + HZ)); |
| 331 | |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 332 | netdev_warn(dev->net, "EEPROM is busy\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 333 | return -EIO; |
| 334 | } |
| 335 | |
| 336 | static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 337 | u8 *data) |
| 338 | { |
| 339 | u32 val; |
| 340 | int i, ret; |
| 341 | |
| 342 | BUG_ON(!dev); |
| 343 | BUG_ON(!data); |
| 344 | |
| 345 | ret = smsc95xx_eeprom_confirm_not_busy(dev); |
| 346 | if (ret) |
| 347 | return ret; |
| 348 | |
| 349 | for (i = 0; i < length; i++) { |
| 350 | val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 351 | ret = smsc95xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 352 | if (ret < 0) { |
| 353 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 354 | return ret; |
| 355 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 356 | |
| 357 | ret = smsc95xx_wait_eeprom(dev); |
| 358 | if (ret < 0) |
| 359 | return ret; |
| 360 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 361 | ret = smsc95xx_read_reg(dev, E2P_DATA, &val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 362 | if (ret < 0) { |
| 363 | netdev_warn(dev->net, "Error reading E2P_DATA\n"); |
| 364 | return ret; |
| 365 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 366 | |
| 367 | data[i] = val & 0xFF; |
| 368 | offset++; |
| 369 | } |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, |
| 375 | u8 *data) |
| 376 | { |
| 377 | u32 val; |
| 378 | int i, ret; |
| 379 | |
| 380 | BUG_ON(!dev); |
| 381 | BUG_ON(!data); |
| 382 | |
| 383 | ret = smsc95xx_eeprom_confirm_not_busy(dev); |
| 384 | if (ret) |
| 385 | return ret; |
| 386 | |
| 387 | /* Issue write/erase enable command */ |
| 388 | val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 389 | ret = smsc95xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 390 | if (ret < 0) { |
| 391 | netdev_warn(dev->net, "Error writing E2P_DATA\n"); |
| 392 | return ret; |
| 393 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 394 | |
| 395 | ret = smsc95xx_wait_eeprom(dev); |
| 396 | if (ret < 0) |
| 397 | return ret; |
| 398 | |
| 399 | for (i = 0; i < length; i++) { |
| 400 | |
| 401 | /* Fill data register */ |
| 402 | val = data[i]; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 403 | ret = smsc95xx_write_reg(dev, E2P_DATA, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 404 | if (ret < 0) { |
| 405 | netdev_warn(dev->net, "Error writing E2P_DATA\n"); |
| 406 | return ret; |
| 407 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 408 | |
| 409 | /* Send "write" command */ |
| 410 | val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 411 | ret = smsc95xx_write_reg(dev, E2P_CMD, val); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 412 | if (ret < 0) { |
| 413 | netdev_warn(dev->net, "Error writing E2P_CMD\n"); |
| 414 | return ret; |
| 415 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 416 | |
| 417 | ret = smsc95xx_wait_eeprom(dev); |
| 418 | if (ret < 0) |
| 419 | return ret; |
| 420 | |
| 421 | offset++; |
| 422 | } |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 427 | static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index, |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 428 | u32 data) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 429 | { |
Steve Glendinning | 1d74a6b | 2008-10-09 14:34:47 -0700 | [diff] [blame] | 430 | const u16 size = 4; |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 431 | u32 buf; |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 432 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 433 | |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 434 | buf = data; |
| 435 | cpu_to_le32s(&buf); |
| 436 | |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 437 | ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, |
| 438 | USB_DIR_OUT | USB_TYPE_VENDOR | |
| 439 | USB_RECIP_DEVICE, |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 440 | 0, index, &buf, size); |
Ming Lei | 72108fd | 2012-10-24 19:47:04 +0000 | [diff] [blame] | 441 | if (ret < 0) |
| 442 | netdev_warn(dev->net, "Error write async cmd, sts=%d\n", |
| 443 | ret); |
| 444 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* returns hash bit number for given MAC address |
| 448 | * example: |
| 449 | * 01 00 5E 00 00 01 -> returns bit number 31 */ |
| 450 | static unsigned int smsc95xx_hash(char addr[ETH_ALEN]) |
| 451 | { |
| 452 | return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f; |
| 453 | } |
| 454 | |
| 455 | static void smsc95xx_set_multicast(struct net_device *netdev) |
| 456 | { |
| 457 | struct usbnet *dev = netdev_priv(netdev); |
| 458 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 459 | unsigned long flags; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 460 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 461 | |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 462 | pdata->hash_hi = 0; |
| 463 | pdata->hash_lo = 0; |
| 464 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 465 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 466 | |
| 467 | if (dev->net->flags & IFF_PROMISC) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 468 | netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 469 | pdata->mac_cr |= MAC_CR_PRMS_; |
| 470 | pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_); |
| 471 | } else if (dev->net->flags & IFF_ALLMULTI) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 472 | netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 473 | pdata->mac_cr |= MAC_CR_MCPAS_; |
| 474 | pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 475 | } else if (!netdev_mc_empty(dev->net)) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 476 | struct netdev_hw_addr *ha; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 477 | |
| 478 | pdata->mac_cr |= MAC_CR_HPFILT_; |
| 479 | pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); |
| 480 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 481 | netdev_for_each_mc_addr(ha, netdev) { |
| 482 | u32 bitnum = smsc95xx_hash(ha->addr); |
Jiri Pirko | a92635d | 2010-02-18 04:02:26 +0000 | [diff] [blame] | 483 | u32 mask = 0x01 << (bitnum & 0x1F); |
| 484 | if (bitnum & 0x20) |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 485 | pdata->hash_hi |= mask; |
Jiri Pirko | a92635d | 2010-02-18 04:02:26 +0000 | [diff] [blame] | 486 | else |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 487 | pdata->hash_lo |= mask; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 490 | netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n", |
Marc Zyngier | 3c0f3c6 | 2011-03-18 03:53:58 +0000 | [diff] [blame] | 491 | pdata->hash_hi, pdata->hash_lo); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 492 | } else { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 493 | netif_dbg(dev, drv, dev->net, "receive own packets only\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 494 | pdata->mac_cr &= |
| 495 | ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_); |
| 496 | } |
| 497 | |
| 498 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 499 | |
| 500 | /* Initiate async writes, as we can't wait for completion here */ |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 501 | ret = smsc95xx_write_reg_async(dev, HASHH, pdata->hash_hi); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 502 | if (ret < 0) |
| 503 | netdev_warn(dev->net, "failed to initiate async write to HASHH\n"); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 504 | |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 505 | ret = smsc95xx_write_reg_async(dev, HASHL, pdata->hash_lo); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 506 | if (ret < 0) |
| 507 | netdev_warn(dev->net, "failed to initiate async write to HASHL\n"); |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 508 | |
Steve Glendinning | 7b9e758 | 2012-12-10 01:03:08 +0000 | [diff] [blame] | 509 | ret = smsc95xx_write_reg_async(dev, MAC_CR, pdata->mac_cr); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 510 | if (ret < 0) |
| 511 | netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 514 | static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, |
| 515 | u16 lcladv, u16 rmtadv) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 516 | { |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 517 | u32 flow = 0, afc_cfg; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 518 | |
| 519 | int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 520 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 521 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 522 | |
| 523 | if (duplex == DUPLEX_FULL) { |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 524 | u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 525 | |
| 526 | if (cap & FLOW_CTRL_RX) |
| 527 | flow = 0xFFFF0002; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 528 | |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 529 | if (cap & FLOW_CTRL_TX) { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 530 | afc_cfg |= 0xF; |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 531 | flow |= 0xFFFF0000; |
| 532 | } else { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 533 | afc_cfg &= ~0xF; |
Nisar Sayed | 9c08273 | 2017-09-11 17:43:11 +0000 | [diff] [blame] | 534 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 535 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 536 | netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n", |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 537 | cap & FLOW_CTRL_RX ? "enabled" : "disabled", |
| 538 | cap & FLOW_CTRL_TX ? "enabled" : "disabled"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 539 | } else { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 540 | netif_dbg(dev, link, dev->net, "half duplex\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 541 | afc_cfg |= 0xF; |
| 542 | } |
| 543 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 544 | ret = smsc95xx_write_reg(dev, FLOW, flow); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 545 | if (ret < 0) |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 546 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 547 | |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 548 | return smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static int smsc95xx_link_reset(struct usbnet *dev) |
| 552 | { |
| 553 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 554 | struct mii_if_info *mii = &dev->mii; |
David Decotigny | 8ae6daca | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 555 | struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 556 | unsigned long flags; |
| 557 | u16 lcladv, rmtadv; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 558 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 559 | |
| 560 | /* clear interrupt status */ |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 561 | ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 562 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 563 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 564 | |
| 565 | ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 566 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 567 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 568 | |
| 569 | mii_check_media(mii, 1, 1); |
| 570 | mii_ethtool_gset(&dev->mii, &ecmd); |
| 571 | lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE); |
| 572 | rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA); |
| 573 | |
David Decotigny | 8ae6daca | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 574 | netif_dbg(dev, link, dev->net, |
| 575 | "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n", |
| 576 | ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 577 | |
| 578 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 579 | if (ecmd.duplex != DUPLEX_FULL) { |
| 580 | pdata->mac_cr &= ~MAC_CR_FDPX_; |
| 581 | pdata->mac_cr |= MAC_CR_RCVOWN_; |
| 582 | } else { |
| 583 | pdata->mac_cr &= ~MAC_CR_RCVOWN_; |
| 584 | pdata->mac_cr |= MAC_CR_FDPX_; |
| 585 | } |
| 586 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 587 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 588 | ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 589 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 590 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 591 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 592 | ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 593 | if (ret < 0) |
| 594 | netdev_warn(dev->net, "Error updating PHY flow control\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 595 | |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 596 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static void smsc95xx_status(struct usbnet *dev, struct urb *urb) |
| 600 | { |
| 601 | u32 intdata; |
| 602 | |
| 603 | if (urb->actual_length != 4) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 604 | netdev_warn(dev->net, "unexpected urb length %d\n", |
| 605 | urb->actual_length); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 606 | return; |
| 607 | } |
| 608 | |
Ben Dooks | 6809d21 | 2018-11-14 11:50:21 +0000 | [diff] [blame] | 609 | intdata = get_unaligned_le32(urb->transfer_buffer); |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 610 | netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 611 | |
| 612 | if (intdata & INT_ENP_PHY_INT_) |
| 613 | usbnet_defer_kevent(dev, EVENT_LINK_RESET); |
| 614 | else |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 615 | netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n", |
| 616 | intdata); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 619 | static void set_carrier(struct usbnet *dev, bool link) |
| 620 | { |
| 621 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 622 | |
| 623 | if (pdata->link_ok == link) |
| 624 | return; |
| 625 | |
| 626 | pdata->link_ok = link; |
| 627 | |
| 628 | if (link) |
| 629 | usbnet_link_change(dev, 1, 0); |
| 630 | else |
| 631 | usbnet_link_change(dev, 0, 0); |
| 632 | } |
| 633 | |
| 634 | static void check_carrier(struct work_struct *work) |
| 635 | { |
| 636 | struct smsc95xx_priv *pdata = container_of(work, struct smsc95xx_priv, |
| 637 | carrier_check.work); |
| 638 | struct usbnet *dev = pdata->dev; |
| 639 | int ret; |
| 640 | |
| 641 | if (pdata->suspend_flags != 0) |
| 642 | return; |
| 643 | |
| 644 | ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMSR); |
| 645 | if (ret < 0) { |
| 646 | netdev_warn(dev->net, "Failed to read MII_BMSR\n"); |
| 647 | return; |
| 648 | } |
| 649 | if (ret & BMSR_LSTATUS) |
| 650 | set_carrier(dev, 1); |
| 651 | else |
| 652 | set_carrier(dev, 0); |
| 653 | |
| 654 | schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); |
| 655 | } |
| 656 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 657 | /* Enable or disable Tx & Rx checksum offload engines */ |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 658 | static int smsc95xx_set_features(struct net_device *netdev, |
| 659 | netdev_features_t features) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 660 | { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 661 | struct usbnet *dev = netdev_priv(netdev); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 662 | u32 read_buf; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 663 | int ret; |
| 664 | |
| 665 | ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 666 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 667 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 668 | |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 669 | if (features & NETIF_F_IP_CSUM) |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 670 | read_buf |= Tx_COE_EN_; |
| 671 | else |
| 672 | read_buf &= ~Tx_COE_EN_; |
| 673 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 674 | if (features & NETIF_F_RXCSUM) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 675 | read_buf |= Rx_COE_EN_; |
| 676 | else |
| 677 | read_buf &= ~Rx_COE_EN_; |
| 678 | |
| 679 | ret = smsc95xx_write_reg(dev, COE_CR, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 680 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 681 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 682 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 683 | netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net) |
| 688 | { |
| 689 | return MAX_EEPROM_SIZE; |
| 690 | } |
| 691 | |
| 692 | static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev, |
| 693 | struct ethtool_eeprom *ee, u8 *data) |
| 694 | { |
| 695 | struct usbnet *dev = netdev_priv(netdev); |
| 696 | |
| 697 | ee->magic = LAN95XX_EEPROM_MAGIC; |
| 698 | |
| 699 | return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data); |
| 700 | } |
| 701 | |
| 702 | static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev, |
| 703 | struct ethtool_eeprom *ee, u8 *data) |
| 704 | { |
| 705 | struct usbnet *dev = netdev_priv(netdev); |
| 706 | |
| 707 | if (ee->magic != LAN95XX_EEPROM_MAGIC) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 708 | netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n", |
| 709 | ee->magic); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 710 | return -EINVAL; |
| 711 | } |
| 712 | |
| 713 | return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data); |
| 714 | } |
| 715 | |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 716 | static int smsc95xx_ethtool_getregslen(struct net_device *netdev) |
| 717 | { |
| 718 | /* all smsc95xx registers */ |
Steve Glendinning | 9624531 | 2012-12-10 01:03:07 +0000 | [diff] [blame] | 719 | return COE_CR - ID_REV + sizeof(u32); |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static void |
| 723 | smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs, |
| 724 | void *buf) |
| 725 | { |
| 726 | struct usbnet *dev = netdev_priv(netdev); |
Dan Carpenter | d348446 | 2012-07-10 20:32:51 +0000 | [diff] [blame] | 727 | unsigned int i, j; |
| 728 | int retval; |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 729 | u32 *data = buf; |
| 730 | |
| 731 | retval = smsc95xx_read_reg(dev, ID_REV, ®s->version); |
| 732 | if (retval < 0) { |
| 733 | netdev_warn(netdev, "REGS: cannot read ID_REV\n"); |
| 734 | return; |
| 735 | } |
| 736 | |
| 737 | for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) { |
| 738 | retval = smsc95xx_read_reg(dev, i, &data[j]); |
| 739 | if (retval < 0) { |
| 740 | netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i); |
| 741 | return; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 746 | static void smsc95xx_ethtool_get_wol(struct net_device *net, |
| 747 | struct ethtool_wolinfo *wolinfo) |
| 748 | { |
| 749 | struct usbnet *dev = netdev_priv(net); |
| 750 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 751 | |
| 752 | wolinfo->supported = SUPPORTED_WAKE; |
| 753 | wolinfo->wolopts = pdata->wolopts; |
| 754 | } |
| 755 | |
| 756 | static int smsc95xx_ethtool_set_wol(struct net_device *net, |
| 757 | struct ethtool_wolinfo *wolinfo) |
| 758 | { |
| 759 | struct usbnet *dev = netdev_priv(net); |
| 760 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
Steve Glendinning | 3b14692 | 2012-11-30 05:55:50 +0000 | [diff] [blame] | 761 | int ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 762 | |
Florian Fainelli | c530c47 | 2018-09-28 16:18:56 -0700 | [diff] [blame] | 763 | if (wolinfo->wolopts & ~SUPPORTED_WAKE) |
| 764 | return -EINVAL; |
| 765 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 766 | pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE; |
Steve Glendinning | 3b14692 | 2012-11-30 05:55:50 +0000 | [diff] [blame] | 767 | |
| 768 | ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 769 | if (ret < 0) |
| 770 | netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret); |
Steve Glendinning | 3b14692 | 2012-11-30 05:55:50 +0000 | [diff] [blame] | 771 | |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 772 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 775 | static int get_mdix_status(struct net_device *net) |
| 776 | { |
| 777 | struct usbnet *dev = netdev_priv(net); |
| 778 | u32 val; |
| 779 | int buf; |
| 780 | |
| 781 | buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, SPECIAL_CTRL_STS); |
| 782 | if (buf & SPECIAL_CTRL_STS_OVRRD_AMDIX_) { |
| 783 | if (buf & SPECIAL_CTRL_STS_AMDIX_ENABLE_) |
| 784 | return ETH_TP_MDI_AUTO; |
| 785 | else if (buf & SPECIAL_CTRL_STS_AMDIX_STATE_) |
| 786 | return ETH_TP_MDI_X; |
| 787 | } else { |
| 788 | buf = smsc95xx_read_reg(dev, STRAP_STATUS, &val); |
| 789 | if (val & STRAP_STATUS_AMDIX_EN_) |
| 790 | return ETH_TP_MDI_AUTO; |
| 791 | } |
| 792 | |
| 793 | return ETH_TP_MDI; |
| 794 | } |
| 795 | |
| 796 | static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) |
| 797 | { |
| 798 | struct usbnet *dev = netdev_priv(net); |
| 799 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 800 | int buf; |
| 801 | |
| 802 | if ((pdata->chip_id == ID_REV_CHIP_ID_9500A_) || |
| 803 | (pdata->chip_id == ID_REV_CHIP_ID_9530_) || |
| 804 | (pdata->chip_id == ID_REV_CHIP_ID_89530_) || |
| 805 | (pdata->chip_id == ID_REV_CHIP_ID_9730_)) { |
| 806 | /* Extend Manual AutoMDIX timer for 9500A/9500Ai */ |
| 807 | buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, |
| 808 | PHY_EDPD_CONFIG); |
| 809 | buf |= PHY_EDPD_CONFIG_EXT_CROSSOVER_; |
| 810 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, |
| 811 | PHY_EDPD_CONFIG, buf); |
| 812 | } |
| 813 | |
| 814 | if (mdix_ctrl == ETH_TP_MDI) { |
| 815 | buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, |
| 816 | SPECIAL_CTRL_STS); |
| 817 | buf |= SPECIAL_CTRL_STS_OVRRD_AMDIX_; |
| 818 | buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | |
| 819 | SPECIAL_CTRL_STS_AMDIX_STATE_); |
| 820 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, |
| 821 | SPECIAL_CTRL_STS, buf); |
| 822 | } else if (mdix_ctrl == ETH_TP_MDI_X) { |
| 823 | buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, |
| 824 | SPECIAL_CTRL_STS); |
| 825 | buf |= SPECIAL_CTRL_STS_OVRRD_AMDIX_; |
| 826 | buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | |
| 827 | SPECIAL_CTRL_STS_AMDIX_STATE_); |
| 828 | buf |= SPECIAL_CTRL_STS_AMDIX_STATE_; |
| 829 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, |
| 830 | SPECIAL_CTRL_STS, buf); |
| 831 | } else if (mdix_ctrl == ETH_TP_MDI_AUTO) { |
| 832 | buf = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, |
| 833 | SPECIAL_CTRL_STS); |
| 834 | buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_; |
| 835 | buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | |
| 836 | SPECIAL_CTRL_STS_AMDIX_STATE_); |
| 837 | buf |= SPECIAL_CTRL_STS_AMDIX_ENABLE_; |
| 838 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, |
| 839 | SPECIAL_CTRL_STS, buf); |
| 840 | } |
| 841 | pdata->mdix_ctrl = mdix_ctrl; |
| 842 | } |
| 843 | |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 844 | static int smsc95xx_get_link_ksettings(struct net_device *net, |
| 845 | struct ethtool_link_ksettings *cmd) |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 846 | { |
| 847 | struct usbnet *dev = netdev_priv(net); |
| 848 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 849 | int retval; |
| 850 | |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 851 | retval = usbnet_get_link_ksettings(net, cmd); |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 852 | |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 853 | cmd->base.eth_tp_mdix = pdata->mdix_ctrl; |
| 854 | cmd->base.eth_tp_mdix_ctrl = pdata->mdix_ctrl; |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 855 | |
| 856 | return retval; |
| 857 | } |
| 858 | |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 859 | static int smsc95xx_set_link_ksettings(struct net_device *net, |
| 860 | const struct ethtool_link_ksettings *cmd) |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 861 | { |
| 862 | struct usbnet *dev = netdev_priv(net); |
| 863 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 864 | int retval; |
| 865 | |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 866 | if (pdata->mdix_ctrl != cmd->base.eth_tp_mdix_ctrl) |
| 867 | set_mdix_status(net, cmd->base.eth_tp_mdix_ctrl); |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 868 | |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 869 | retval = usbnet_set_link_ksettings(net, cmd); |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 870 | |
| 871 | return retval; |
| 872 | } |
| 873 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 874 | static const struct ethtool_ops smsc95xx_ethtool_ops = { |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 875 | .get_link = usbnet_get_link, |
| 876 | .nway_reset = usbnet_nway_reset, |
| 877 | .get_drvinfo = usbnet_get_drvinfo, |
| 878 | .get_msglevel = usbnet_get_msglevel, |
| 879 | .set_msglevel = usbnet_set_msglevel, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 880 | .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len, |
| 881 | .get_eeprom = smsc95xx_ethtool_get_eeprom, |
| 882 | .set_eeprom = smsc95xx_ethtool_set_eeprom, |
Emeric Vigier | 9fa32e9 | 2012-07-09 17:44:45 -0400 | [diff] [blame] | 883 | .get_regs_len = smsc95xx_ethtool_getregslen, |
| 884 | .get_regs = smsc95xx_ethtool_getregs, |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 885 | .get_wol = smsc95xx_ethtool_get_wol, |
| 886 | .set_wol = smsc95xx_ethtool_set_wol, |
Philippe Reynes | eaf9a32 | 2017-03-16 23:18:48 +0100 | [diff] [blame] | 887 | .get_link_ksettings = smsc95xx_get_link_ksettings, |
| 888 | .set_link_ksettings = smsc95xx_set_link_ksettings, |
Petr Kulhavy | a8f5cb9 | 2017-07-13 19:40:57 +0200 | [diff] [blame] | 889 | .get_ts_info = ethtool_op_get_ts_info, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 890 | }; |
| 891 | |
| 892 | static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) |
| 893 | { |
| 894 | struct usbnet *dev = netdev_priv(netdev); |
| 895 | |
| 896 | if (!netif_running(netdev)) |
| 897 | return -EINVAL; |
| 898 | |
| 899 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); |
| 900 | } |
| 901 | |
| 902 | static void smsc95xx_init_mac_address(struct usbnet *dev) |
| 903 | { |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 904 | const u8 *mac_addr; |
| 905 | |
| 906 | /* maybe the boot loader passed the MAC address in devicetree */ |
| 907 | mac_addr = of_get_mac_address(dev->udev->dev.of_node); |
Petr Å tetiar | adfb3cb | 2019-05-03 16:27:11 +0200 | [diff] [blame] | 908 | if (!IS_ERR(mac_addr)) { |
Petr Å tetiar | 5503a68 | 2019-05-06 23:24:47 +0200 | [diff] [blame] | 909 | ether_addr_copy(dev->net->dev_addr, mac_addr); |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 913 | /* try reading mac address from EEPROM */ |
| 914 | if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, |
| 915 | dev->net->dev_addr) == 0) { |
| 916 | if (is_valid_ether_addr(dev->net->dev_addr)) { |
| 917 | /* eeprom values are valid so use them */ |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 918 | netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 919 | return; |
| 920 | } |
| 921 | } |
| 922 | |
Arnd Bergmann | c489565 | 2016-04-29 09:05:59 +0200 | [diff] [blame] | 923 | /* no useful static MAC address found. generate a random one */ |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 924 | eth_hw_addr_random(dev->net); |
Joe Perches | c7e12ea | 2012-07-12 19:33:07 +0000 | [diff] [blame] | 925 | netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static int smsc95xx_set_mac_address(struct usbnet *dev) |
| 929 | { |
| 930 | u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 | |
| 931 | dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24; |
| 932 | u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8; |
| 933 | int ret; |
| 934 | |
| 935 | ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 936 | if (ret < 0) |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 937 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 938 | |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 939 | return smsc95xx_write_reg(dev, ADDRH, addr_hi); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /* starts the TX path */ |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 943 | static int smsc95xx_start_tx_path(struct usbnet *dev) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 944 | { |
| 945 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 946 | unsigned long flags; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 947 | int ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 948 | |
| 949 | /* Enable Tx at MAC */ |
| 950 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 951 | pdata->mac_cr |= MAC_CR_TXEN_; |
| 952 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 953 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 954 | ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 955 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 956 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 957 | |
| 958 | /* Enable Tx at SCSRs */ |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 959 | return smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* Starts the Receive path */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 963 | static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 964 | { |
| 965 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 966 | unsigned long flags; |
| 967 | |
| 968 | spin_lock_irqsave(&pdata->mac_cr_lock, flags); |
| 969 | pdata->mac_cr |= MAC_CR_RXEN_; |
| 970 | spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); |
| 971 | |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 972 | return __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | static int smsc95xx_phy_initialize(struct usbnet *dev) |
| 976 | { |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 977 | int bmcr, ret, timeout = 0; |
Steve Glendinning | db443c4 | 2010-03-16 09:03:06 +0000 | [diff] [blame] | 978 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 979 | /* Initialize MII structure */ |
| 980 | dev->mii.dev = dev->net; |
| 981 | dev->mii.mdio_read = smsc95xx_mdio_read; |
| 982 | dev->mii.mdio_write = smsc95xx_mdio_write; |
| 983 | dev->mii.phy_id_mask = 0x1f; |
| 984 | dev->mii.reg_num_mask = 0x1f; |
| 985 | dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID; |
| 986 | |
Steve Glendinning | db443c4 | 2010-03-16 09:03:06 +0000 | [diff] [blame] | 987 | /* reset phy and wait for reset to complete */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 988 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); |
Steve Glendinning | db443c4 | 2010-03-16 09:03:06 +0000 | [diff] [blame] | 989 | |
| 990 | do { |
| 991 | msleep(10); |
| 992 | bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); |
| 993 | timeout++; |
Rabin Vincent | d946092 | 2011-04-30 08:29:27 +0000 | [diff] [blame] | 994 | } while ((bmcr & BMCR_RESET) && (timeout < 100)); |
Steve Glendinning | db443c4 | 2010-03-16 09:03:06 +0000 | [diff] [blame] | 995 | |
| 996 | if (timeout >= 100) { |
| 997 | netdev_warn(dev->net, "timeout on PHY Reset"); |
| 998 | return -EIO; |
| 999 | } |
| 1000 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1001 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, |
| 1002 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP | |
| 1003 | ADVERTISE_PAUSE_ASYM); |
| 1004 | |
| 1005 | /* read to clear */ |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1006 | ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1007 | if (ret < 0) { |
| 1008 | netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n"); |
| 1009 | return ret; |
| 1010 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1011 | |
| 1012 | smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, |
| 1013 | PHY_INT_MASK_DEFAULT_); |
| 1014 | mii_nway_restart(&dev->mii); |
| 1015 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1016 | netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | static int smsc95xx_reset(struct usbnet *dev) |
| 1021 | { |
| 1022 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 1023 | u32 read_buf, write_buf, burst_cap; |
| 1024 | int ret = 0, timeout; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1025 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1026 | netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1027 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1028 | ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1029 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1030 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1031 | |
| 1032 | timeout = 0; |
| 1033 | do { |
Steve Glendinning | cf2acec | 2012-09-28 00:07:07 +0000 | [diff] [blame] | 1034 | msleep(10); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1035 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1036 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1037 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1038 | timeout++; |
| 1039 | } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); |
| 1040 | |
| 1041 | if (timeout >= 100) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 1042 | netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1043 | return ret; |
| 1044 | } |
| 1045 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1046 | ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1047 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1048 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1049 | |
| 1050 | timeout = 0; |
| 1051 | do { |
Steve Glendinning | cf2acec | 2012-09-28 00:07:07 +0000 | [diff] [blame] | 1052 | msleep(10); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1053 | ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1054 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1055 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1056 | timeout++; |
| 1057 | } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); |
| 1058 | |
| 1059 | if (timeout >= 100) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 1060 | netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1061 | return ret; |
| 1062 | } |
| 1063 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1064 | ret = smsc95xx_set_mac_address(dev); |
| 1065 | if (ret < 0) |
| 1066 | return ret; |
| 1067 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1068 | netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n", |
| 1069 | dev->net->dev_addr); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1070 | |
| 1071 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1072 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1073 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1074 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1075 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n", |
| 1076 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1077 | |
| 1078 | read_buf |= HW_CFG_BIR_; |
| 1079 | |
| 1080 | ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1081 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1082 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1083 | |
| 1084 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1085 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1086 | return ret; |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1087 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1088 | netif_dbg(dev, ifup, dev->net, |
| 1089 | "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", |
| 1090 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1091 | |
| 1092 | if (!turbo_mode) { |
| 1093 | burst_cap = 0; |
| 1094 | dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE; |
| 1095 | } else if (dev->udev->speed == USB_SPEED_HIGH) { |
| 1096 | burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE; |
| 1097 | dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE; |
| 1098 | } else { |
| 1099 | burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE; |
| 1100 | dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE; |
| 1101 | } |
| 1102 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1103 | netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n", |
| 1104 | (ulong)dev->rx_urb_size); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1105 | |
| 1106 | ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1107 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1108 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1109 | |
| 1110 | ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1111 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1112 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1113 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1114 | netif_dbg(dev, ifup, dev->net, |
| 1115 | "Read Value from BURST_CAP after writing: 0x%08x\n", |
| 1116 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1117 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1118 | ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1119 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1120 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1121 | |
| 1122 | ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1123 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1124 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1125 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1126 | netif_dbg(dev, ifup, dev->net, |
| 1127 | "Read Value from BULK_IN_DLY after writing: 0x%08x\n", |
| 1128 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1129 | |
| 1130 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1131 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1132 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1133 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1134 | netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n", |
| 1135 | read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1136 | |
| 1137 | if (turbo_mode) |
| 1138 | read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_); |
| 1139 | |
| 1140 | read_buf &= ~HW_CFG_RXDOFF_; |
| 1141 | |
| 1142 | /* set Rx data offset=2, Make IP header aligns on word boundary. */ |
| 1143 | read_buf |= NET_IP_ALIGN << 9; |
| 1144 | |
| 1145 | ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1146 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1147 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1148 | |
| 1149 | ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1150 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1151 | return ret; |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1152 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1153 | netif_dbg(dev, ifup, dev->net, |
| 1154 | "Read Value from HW_CFG after writing: 0x%08x\n", read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1155 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1156 | ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1157 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1158 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1159 | |
| 1160 | ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1161 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1162 | return ret; |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1163 | netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1164 | |
Steve Glendinning | f293501 | 2009-05-01 05:46:51 +0000 | [diff] [blame] | 1165 | /* Configure GPIO pins as LED outputs */ |
| 1166 | write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | |
| 1167 | LED_GPIO_CFG_FDX_LED; |
| 1168 | ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1169 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1170 | return ret; |
Steve Glendinning | f293501 | 2009-05-01 05:46:51 +0000 | [diff] [blame] | 1171 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1172 | /* Init Tx */ |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1173 | ret = smsc95xx_write_reg(dev, FLOW, 0); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1174 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1175 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1176 | |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1177 | ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1178 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1179 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1180 | |
| 1181 | /* Don't need mac_cr_lock during initialisation */ |
| 1182 | ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1183 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1184 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1185 | |
| 1186 | /* Init Rx */ |
| 1187 | /* Set Vlan */ |
Steve Glendinning | 4436761 | 2012-09-28 00:07:08 +0000 | [diff] [blame] | 1188 | ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1189 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1190 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1191 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1192 | /* Enable or disable checksum offload engines */ |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1193 | ret = smsc95xx_set_features(dev->net, dev->net->features); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1194 | if (ret < 0) { |
| 1195 | netdev_warn(dev->net, "Failed to set checksum offload features\n"); |
| 1196 | return ret; |
| 1197 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1198 | |
| 1199 | smsc95xx_set_multicast(dev->net); |
| 1200 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1201 | ret = smsc95xx_phy_initialize(dev); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1202 | if (ret < 0) { |
| 1203 | netdev_warn(dev->net, "Failed to init PHY\n"); |
| 1204 | return ret; |
| 1205 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1206 | |
| 1207 | ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1208 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1209 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1210 | |
| 1211 | /* enable PHY interrupts */ |
| 1212 | read_buf |= INT_EP_CTL_PHY_INT_; |
| 1213 | |
| 1214 | ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1215 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1216 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1217 | |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1218 | ret = smsc95xx_start_tx_path(dev); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1219 | if (ret < 0) { |
| 1220 | netdev_warn(dev->net, "Failed to start TX path\n"); |
| 1221 | return ret; |
| 1222 | } |
Steve Glendinning | 769ea6d | 2012-09-28 00:07:09 +0000 | [diff] [blame] | 1223 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1224 | ret = smsc95xx_start_rx_path(dev, 0); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1225 | if (ret < 0) { |
| 1226 | netdev_warn(dev->net, "Failed to start RX path\n"); |
| 1227 | return ret; |
| 1228 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1229 | |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1230 | netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1231 | return 0; |
| 1232 | } |
| 1233 | |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1234 | static const struct net_device_ops smsc95xx_netdev_ops = { |
| 1235 | .ndo_open = usbnet_open, |
| 1236 | .ndo_stop = usbnet_stop, |
| 1237 | .ndo_start_xmit = usbnet_start_xmit, |
| 1238 | .ndo_tx_timeout = usbnet_tx_timeout, |
| 1239 | .ndo_change_mtu = usbnet_change_mtu, |
Greg Ungerer | c8b5d12 | 2017-04-03 15:50:03 +1000 | [diff] [blame] | 1240 | .ndo_get_stats64 = usbnet_get_stats64, |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1241 | .ndo_set_mac_address = eth_mac_addr, |
| 1242 | .ndo_validate_addr = eth_validate_addr, |
| 1243 | .ndo_do_ioctl = smsc95xx_ioctl, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1244 | .ndo_set_rx_mode = smsc95xx_set_multicast, |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1245 | .ndo_set_features = smsc95xx_set_features, |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1246 | }; |
| 1247 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1248 | static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) |
| 1249 | { |
| 1250 | struct smsc95xx_priv *pdata = NULL; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1251 | u32 val; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1252 | int ret; |
| 1253 | |
| 1254 | printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); |
| 1255 | |
| 1256 | ret = usbnet_get_endpoints(dev, intf); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1257 | if (ret < 0) { |
| 1258 | netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret); |
| 1259 | return ret; |
| 1260 | } |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1261 | |
| 1262 | dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), |
Joe Perches | 38673c8 | 2013-02-03 17:28:11 +0000 | [diff] [blame] | 1263 | GFP_KERNEL); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1264 | |
| 1265 | pdata = (struct smsc95xx_priv *)(dev->data[0]); |
Joe Perches | 38673c8 | 2013-02-03 17:28:11 +0000 | [diff] [blame] | 1266 | if (!pdata) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1267 | return -ENOMEM; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1268 | |
| 1269 | spin_lock_init(&pdata->mac_cr_lock); |
| 1270 | |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 1271 | /* LAN95xx devices do not alter the computed checksum of 0 to 0xffff. |
| 1272 | * RFC 2460, ipv6 UDP calculated checksum yields a result of zero must |
| 1273 | * be changed to 0xffff. RFC 768, ipv4 UDP computed checksum is zero, |
| 1274 | * it is transmitted as all ones. The zero transmitted checksum means |
| 1275 | * transmitter generated no checksum. Hence, enable csum offload only |
| 1276 | * for ipv4 packets. |
| 1277 | */ |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1278 | if (DEFAULT_TX_CSUM_ENABLE) |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 1279 | dev->net->features |= NETIF_F_IP_CSUM; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1280 | if (DEFAULT_RX_CSUM_ENABLE) |
| 1281 | dev->net->features |= NETIF_F_RXCSUM; |
| 1282 | |
Nisar Sayed | fe0cd8c | 2017-05-19 14:00:25 +0000 | [diff] [blame] | 1283 | dev->net->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
Ben Dooks | 810eeb1 | 2018-11-14 11:50:19 +0000 | [diff] [blame] | 1284 | set_bit(EVENT_NO_IP_ALIGN, &dev->flags); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1285 | |
Bernard Blackham | f4e8ab7 | 2010-10-18 13:16:39 +0000 | [diff] [blame] | 1286 | smsc95xx_init_mac_address(dev); |
| 1287 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1288 | /* Init all registers */ |
| 1289 | ret = smsc95xx_reset(dev); |
Andre Edich | 7c8b1e8 | 2020-07-06 10:39:34 +0200 | [diff] [blame^] | 1290 | if (ret) |
| 1291 | goto free_pdata; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1292 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1293 | /* detect device revision as different features may be available */ |
| 1294 | ret = smsc95xx_read_reg(dev, ID_REV, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1295 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1296 | return ret; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1297 | val >>= 16; |
Woojung Huh | 13722bb | 2016-09-02 20:34:22 +0000 | [diff] [blame] | 1298 | pdata->chip_id = val; |
| 1299 | pdata->mdix_ctrl = get_mdix_status(dev->net); |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1300 | |
| 1301 | if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) || |
| 1302 | (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_)) |
| 1303 | pdata->features = (FEATURE_8_WAKEUP_FILTERS | |
| 1304 | FEATURE_PHY_NLP_CROSSOVER | |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1305 | FEATURE_REMOTE_WAKEUP); |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1306 | else if (val == ID_REV_CHIP_ID_9512_) |
| 1307 | pdata->features = FEATURE_8_WAKEUP_FILTERS; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1308 | |
Stephen Hemminger | 63e77b3 | 2009-03-20 19:35:58 +0000 | [diff] [blame] | 1309 | dev->net->netdev_ops = &smsc95xx_netdev_ops; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1310 | dev->net->ethtool_ops = &smsc95xx_ethtool_ops; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1311 | dev->net->flags |= IFF_MULTICAST; |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1312 | dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM; |
Stefan Wahren | 85b18b0 | 2018-11-08 20:38:26 +0100 | [diff] [blame] | 1313 | dev->net->min_mtu = ETH_MIN_MTU; |
| 1314 | dev->net->max_mtu = ETH_DATA_LEN; |
Stephane Fillod | 9bbf566 | 2012-04-20 09:39:23 +0000 | [diff] [blame] | 1315 | dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 1316 | |
| 1317 | pdata->dev = dev; |
| 1318 | INIT_DELAYED_WORK(&pdata->carrier_check, check_carrier); |
| 1319 | schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); |
| 1320 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1321 | return 0; |
Andre Edich | 7c8b1e8 | 2020-07-06 10:39:34 +0200 | [diff] [blame^] | 1322 | |
| 1323 | free_pdata: |
| 1324 | kfree(pdata); |
| 1325 | return ret; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf) |
| 1329 | { |
| 1330 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 1331 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1332 | if (pdata) { |
Tuomas Tynkkynen | b835a71 | 2020-06-21 13:43:26 +0300 | [diff] [blame] | 1333 | cancel_delayed_work_sync(&pdata->carrier_check); |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1334 | netif_dbg(dev, ifdown, dev->net, "free pdata\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1335 | kfree(pdata); |
| 1336 | pdata = NULL; |
| 1337 | dev->data[0] = 0; |
| 1338 | } |
| 1339 | } |
| 1340 | |
Steve Glendinning | 068bb1a | 2012-11-30 05:55:51 +0000 | [diff] [blame] | 1341 | static u32 smsc_crc(const u8 *buffer, size_t len, int filter) |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1342 | { |
Steve Glendinning | 068bb1a | 2012-11-30 05:55:51 +0000 | [diff] [blame] | 1343 | u32 crc = bitrev16(crc16(0xFFFF, buffer, len)); |
| 1344 | return crc << ((filter % 2) * 16); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1347 | static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) |
| 1348 | { |
| 1349 | struct mii_if_info *mii = &dev->mii; |
| 1350 | int ret; |
| 1351 | |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1352 | netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n"); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1353 | |
| 1354 | /* read to clear */ |
| 1355 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1356 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1357 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1358 | |
| 1359 | /* enable interrupt source */ |
| 1360 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1361 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1362 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1363 | |
| 1364 | ret |= mask; |
| 1365 | |
| 1366 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret); |
| 1367 | |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | static int smsc95xx_link_ok_nopm(struct usbnet *dev) |
| 1372 | { |
| 1373 | struct mii_if_info *mii = &dev->mii; |
| 1374 | int ret; |
| 1375 | |
| 1376 | /* first, a dummy read, needed to latch some MII phys */ |
| 1377 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1378 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1379 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1380 | |
| 1381 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1382 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1383 | return ret; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1384 | |
| 1385 | return !!(ret & BMSR_LSTATUS); |
| 1386 | } |
| 1387 | |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1388 | static int smsc95xx_enter_suspend0(struct usbnet *dev) |
| 1389 | { |
| 1390 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 1391 | u32 val; |
| 1392 | int ret; |
| 1393 | |
| 1394 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1395 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1396 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1397 | |
| 1398 | val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_)); |
| 1399 | val |= PM_CTL_SUS_MODE_0; |
| 1400 | |
| 1401 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1402 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1403 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1404 | |
| 1405 | /* clear wol status */ |
| 1406 | val &= ~PM_CTL_WUPS_; |
| 1407 | val |= PM_CTL_WUPS_WOL_; |
| 1408 | |
| 1409 | /* enable energy detection */ |
| 1410 | if (pdata->wolopts & WAKE_PHY) |
| 1411 | val |= PM_CTL_WUPS_ED_; |
| 1412 | |
| 1413 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1414 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1415 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1416 | |
| 1417 | /* read back PM_CTRL */ |
| 1418 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1419 | if (ret < 0) |
| 1420 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1421 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1422 | pdata->suspend_flags |= SUSPEND_SUSPEND0; |
| 1423 | |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1424 | return 0; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | static int smsc95xx_enter_suspend1(struct usbnet *dev) |
| 1428 | { |
| 1429 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 1430 | struct mii_if_info *mii = &dev->mii; |
| 1431 | u32 val; |
| 1432 | int ret; |
| 1433 | |
| 1434 | /* reconfigure link pulse detection timing for |
| 1435 | * compatibility with non-standard link partners |
| 1436 | */ |
| 1437 | if (pdata->features & FEATURE_PHY_NLP_CROSSOVER) |
| 1438 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG, |
| 1439 | PHY_EDPD_CONFIG_DEFAULT); |
| 1440 | |
| 1441 | /* enable energy detect power-down mode */ |
| 1442 | ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1443 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1444 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1445 | |
| 1446 | ret |= MODE_CTRL_STS_EDPWRDOWN_; |
| 1447 | |
| 1448 | smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret); |
| 1449 | |
| 1450 | /* enter SUSPEND1 mode */ |
| 1451 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1452 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1453 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1454 | |
| 1455 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); |
| 1456 | val |= PM_CTL_SUS_MODE_1; |
| 1457 | |
| 1458 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1459 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1460 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1461 | |
| 1462 | /* clear wol status, enable energy detection */ |
| 1463 | val &= ~PM_CTL_WUPS_; |
| 1464 | val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_); |
| 1465 | |
| 1466 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1467 | if (ret < 0) |
| 1468 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1469 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1470 | pdata->suspend_flags |= SUSPEND_SUSPEND1; |
| 1471 | |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1472 | return 0; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | static int smsc95xx_enter_suspend2(struct usbnet *dev) |
| 1476 | { |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1477 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1478 | u32 val; |
| 1479 | int ret; |
| 1480 | |
| 1481 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1482 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1483 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1484 | |
| 1485 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); |
| 1486 | val |= PM_CTL_SUS_MODE_2; |
| 1487 | |
| 1488 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1489 | if (ret < 0) |
| 1490 | return ret; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1491 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1492 | pdata->suspend_flags |= SUSPEND_SUSPEND2; |
| 1493 | |
Ming Lei | 7643721 | 2013-02-22 03:05:03 +0000 | [diff] [blame] | 1494 | return 0; |
Steve Glendinning | 319b95b | 2012-11-22 08:05:25 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1497 | static int smsc95xx_enter_suspend3(struct usbnet *dev) |
| 1498 | { |
| 1499 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 1500 | u32 val; |
| 1501 | int ret; |
| 1502 | |
| 1503 | ret = smsc95xx_read_reg_nopm(dev, RX_FIFO_INF, &val); |
| 1504 | if (ret < 0) |
| 1505 | return ret; |
| 1506 | |
Martin Wetterwald | 53a759c | 2017-04-13 10:08:44 +0200 | [diff] [blame] | 1507 | if (val & RX_FIFO_INF_USED_) { |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1508 | netdev_info(dev->net, "rx fifo not empty in autosuspend\n"); |
| 1509 | return -EBUSY; |
| 1510 | } |
| 1511 | |
| 1512 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
| 1513 | if (ret < 0) |
| 1514 | return ret; |
| 1515 | |
| 1516 | val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_); |
| 1517 | val |= PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS; |
| 1518 | |
| 1519 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
| 1520 | if (ret < 0) |
| 1521 | return ret; |
| 1522 | |
| 1523 | /* clear wol status */ |
| 1524 | val &= ~PM_CTL_WUPS_; |
| 1525 | val |= PM_CTL_WUPS_WOL_; |
| 1526 | |
| 1527 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
| 1528 | if (ret < 0) |
| 1529 | return ret; |
| 1530 | |
| 1531 | pdata->suspend_flags |= SUSPEND_SUSPEND3; |
| 1532 | |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up) |
| 1537 | { |
| 1538 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 1539 | int ret; |
| 1540 | |
| 1541 | if (!netif_running(dev->net)) { |
| 1542 | /* interface is ifconfig down so fully power down hw */ |
| 1543 | netdev_dbg(dev->net, "autosuspend entering SUSPEND2\n"); |
| 1544 | return smsc95xx_enter_suspend2(dev); |
| 1545 | } |
| 1546 | |
| 1547 | if (!link_up) { |
| 1548 | /* link is down so enter EDPD mode, but only if device can |
| 1549 | * reliably resume from it. This check should be redundant |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1550 | * as current FEATURE_REMOTE_WAKEUP parts also support |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1551 | * FEATURE_PHY_NLP_CROSSOVER but it's included for clarity */ |
| 1552 | if (!(pdata->features & FEATURE_PHY_NLP_CROSSOVER)) { |
| 1553 | netdev_warn(dev->net, "EDPD not supported\n"); |
| 1554 | return -EBUSY; |
| 1555 | } |
| 1556 | |
| 1557 | netdev_dbg(dev->net, "autosuspend entering SUSPEND1\n"); |
| 1558 | |
| 1559 | /* enable PHY wakeup events for if cable is attached */ |
| 1560 | ret = smsc95xx_enable_phy_wakeup_interrupts(dev, |
| 1561 | PHY_INT_MASK_ANEG_COMP_); |
| 1562 | if (ret < 0) { |
| 1563 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1564 | return ret; |
| 1565 | } |
| 1566 | |
| 1567 | netdev_info(dev->net, "entering SUSPEND1 mode\n"); |
| 1568 | return smsc95xx_enter_suspend1(dev); |
| 1569 | } |
| 1570 | |
| 1571 | /* enable PHY wakeup events so we remote wakeup if cable is pulled */ |
| 1572 | ret = smsc95xx_enable_phy_wakeup_interrupts(dev, |
| 1573 | PHY_INT_MASK_LINK_DOWN_); |
| 1574 | if (ret < 0) { |
| 1575 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1576 | return ret; |
| 1577 | } |
| 1578 | |
| 1579 | netdev_dbg(dev->net, "autosuspend entering SUSPEND3\n"); |
| 1580 | return smsc95xx_enter_suspend3(dev); |
| 1581 | } |
| 1582 | |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1583 | static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) |
| 1584 | { |
| 1585 | struct usbnet *dev = usb_get_intfdata(intf); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1586 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1587 | u32 val, link_up; |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1588 | int ret; |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1589 | |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1590 | ret = usbnet_suspend(intf, message); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1591 | if (ret < 0) { |
| 1592 | netdev_warn(dev->net, "usbnet_suspend error\n"); |
| 1593 | return ret; |
| 1594 | } |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1595 | |
Frieder Schrempf | 7b900ea | 2018-10-31 22:52:19 +0100 | [diff] [blame] | 1596 | cancel_delayed_work_sync(&pdata->carrier_check); |
| 1597 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1598 | if (pdata->suspend_flags) { |
| 1599 | netdev_warn(dev->net, "error during last resume\n"); |
| 1600 | pdata->suspend_flags = 0; |
| 1601 | } |
| 1602 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1603 | /* determine if link is up using only _nopm functions */ |
| 1604 | link_up = smsc95xx_link_ok_nopm(dev); |
| 1605 | |
Ming Lei | 42e21c0 | 2013-02-22 03:05:04 +0000 | [diff] [blame] | 1606 | if (message.event == PM_EVENT_AUTO_SUSPEND && |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 1607 | (pdata->features & FEATURE_REMOTE_WAKEUP)) { |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1608 | ret = smsc95xx_autosuspend(dev, link_up); |
| 1609 | goto done; |
| 1610 | } |
| 1611 | |
| 1612 | /* if we get this far we're not autosuspending */ |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1613 | /* if no wol options set, or if link is down and we're not waking on |
| 1614 | * PHY activity, enter lowest power SUSPEND2 mode |
| 1615 | */ |
| 1616 | if (!(pdata->wolopts & SUPPORTED_WAKE) || |
| 1617 | !(link_up || (pdata->wolopts & WAKE_PHY))) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1618 | netdev_info(dev->net, "entering SUSPEND2 mode\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1619 | |
| 1620 | /* disable energy detect (link up) & wake up events */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1621 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1622 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1623 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1624 | |
| 1625 | val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_); |
| 1626 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1627 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1628 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1629 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1630 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1631 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1632 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1633 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1634 | |
| 1635 | val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_); |
| 1636 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1637 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1638 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1639 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1640 | |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1641 | ret = smsc95xx_enter_suspend2(dev); |
| 1642 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1645 | if (pdata->wolopts & WAKE_PHY) { |
| 1646 | ret = smsc95xx_enable_phy_wakeup_interrupts(dev, |
| 1647 | (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_)); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1648 | if (ret < 0) { |
| 1649 | netdev_warn(dev->net, "error enabling PHY wakeup ints\n"); |
| 1650 | goto done; |
| 1651 | } |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1652 | |
| 1653 | /* if link is down then configure EDPD and enter SUSPEND1, |
| 1654 | * otherwise enter SUSPEND0 below |
| 1655 | */ |
| 1656 | if (!link_up) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1657 | netdev_info(dev->net, "entering SUSPEND1 mode\n"); |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1658 | ret = smsc95xx_enter_suspend1(dev); |
| 1659 | goto done; |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1660 | } |
| 1661 | } |
| 1662 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1663 | if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1664 | u32 *filter_mask = kcalloc(32, sizeof(u32), GFP_KERNEL); |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1665 | u32 command[2]; |
| 1666 | u32 offset[2]; |
| 1667 | u32 crc[4]; |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1668 | int wuff_filter_count = |
| 1669 | (pdata->features & FEATURE_8_WAKEUP_FILTERS) ? |
| 1670 | LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1671 | int i, filter = 0; |
| 1672 | |
Steve Glendinning | eed9a72 | 2012-11-30 05:55:48 +0000 | [diff] [blame] | 1673 | if (!filter_mask) { |
| 1674 | netdev_warn(dev->net, "Unable to allocate filter_mask\n"); |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1675 | ret = -ENOMEM; |
| 1676 | goto done; |
Steve Glendinning | eed9a72 | 2012-11-30 05:55:48 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1679 | memset(command, 0, sizeof(command)); |
| 1680 | memset(offset, 0, sizeof(offset)); |
| 1681 | memset(crc, 0, sizeof(crc)); |
| 1682 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1683 | if (pdata->wolopts & WAKE_BCAST) { |
| 1684 | const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1685 | netdev_info(dev->net, "enabling broadcast detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1686 | filter_mask[filter * 4] = 0x003F; |
| 1687 | filter_mask[filter * 4 + 1] = 0x00; |
| 1688 | filter_mask[filter * 4 + 2] = 0x00; |
| 1689 | filter_mask[filter * 4 + 3] = 0x00; |
| 1690 | command[filter/4] |= 0x05UL << ((filter % 4) * 8); |
| 1691 | offset[filter/4] |= 0x00 << ((filter % 4) * 8); |
| 1692 | crc[filter/2] |= smsc_crc(bcast, 6, filter); |
| 1693 | filter++; |
| 1694 | } |
| 1695 | |
| 1696 | if (pdata->wolopts & WAKE_MCAST) { |
| 1697 | const u8 mcast[] = {0x01, 0x00, 0x5E}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1698 | netdev_info(dev->net, "enabling multicast detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1699 | filter_mask[filter * 4] = 0x0007; |
| 1700 | filter_mask[filter * 4 + 1] = 0x00; |
| 1701 | filter_mask[filter * 4 + 2] = 0x00; |
| 1702 | filter_mask[filter * 4 + 3] = 0x00; |
| 1703 | command[filter/4] |= 0x09UL << ((filter % 4) * 8); |
| 1704 | offset[filter/4] |= 0x00 << ((filter % 4) * 8); |
| 1705 | crc[filter/2] |= smsc_crc(mcast, 3, filter); |
| 1706 | filter++; |
| 1707 | } |
| 1708 | |
| 1709 | if (pdata->wolopts & WAKE_ARP) { |
| 1710 | const u8 arp[] = {0x08, 0x06}; |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1711 | netdev_info(dev->net, "enabling ARP detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1712 | filter_mask[filter * 4] = 0x0003; |
| 1713 | filter_mask[filter * 4 + 1] = 0x00; |
| 1714 | filter_mask[filter * 4 + 2] = 0x00; |
| 1715 | filter_mask[filter * 4 + 3] = 0x00; |
| 1716 | command[filter/4] |= 0x05UL << ((filter % 4) * 8); |
| 1717 | offset[filter/4] |= 0x0C << ((filter % 4) * 8); |
| 1718 | crc[filter/2] |= smsc_crc(arp, 2, filter); |
| 1719 | filter++; |
| 1720 | } |
| 1721 | |
| 1722 | if (pdata->wolopts & WAKE_UCAST) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1723 | netdev_info(dev->net, "enabling unicast detection\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1724 | filter_mask[filter * 4] = 0x003F; |
| 1725 | filter_mask[filter * 4 + 1] = 0x00; |
| 1726 | filter_mask[filter * 4 + 2] = 0x00; |
| 1727 | filter_mask[filter * 4 + 3] = 0x00; |
| 1728 | command[filter/4] |= 0x01UL << ((filter % 4) * 8); |
| 1729 | offset[filter/4] |= 0x00 << ((filter % 4) * 8); |
| 1730 | crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter); |
| 1731 | filter++; |
| 1732 | } |
| 1733 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1734 | for (i = 0; i < (wuff_filter_count * 4); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1735 | ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1736 | if (ret < 0) { |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1737 | kfree(filter_mask); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1738 | goto done; |
| 1739 | } |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1740 | } |
Ming Lei | 06a221b | 2012-11-06 04:53:06 +0000 | [diff] [blame] | 1741 | kfree(filter_mask); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1742 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1743 | for (i = 0; i < (wuff_filter_count / 4); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1744 | ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1745 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1746 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1749 | for (i = 0; i < (wuff_filter_count / 4); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1750 | ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1751 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1752 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Steve Glendinning | 9ebca50 | 2012-11-22 08:05:23 +0000 | [diff] [blame] | 1755 | for (i = 0; i < (wuff_filter_count / 2); i++) { |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1756 | ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1757 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1758 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | /* clear any pending pattern match packet status */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1762 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1763 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1764 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1765 | |
| 1766 | val |= WUCSR_WUFR_; |
| 1767 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1768 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1769 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1770 | goto done; |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1773 | if (pdata->wolopts & WAKE_MAGIC) { |
| 1774 | /* clear any pending magic packet status */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1775 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1776 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1777 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1778 | |
| 1779 | val |= WUCSR_MPR_; |
| 1780 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1781 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1782 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1783 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1786 | /* enable/disable wakeup sources */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1787 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1788 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1789 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1790 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1791 | if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1792 | netdev_info(dev->net, "enabling pattern match wakeup\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1793 | val |= WUCSR_WAKE_EN_; |
| 1794 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1795 | netdev_info(dev->net, "disabling pattern match wakeup\n"); |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1796 | val &= ~WUCSR_WAKE_EN_; |
| 1797 | } |
| 1798 | |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1799 | if (pdata->wolopts & WAKE_MAGIC) { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1800 | netdev_info(dev->net, "enabling magic packet wakeup\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1801 | val |= WUCSR_MPEN_; |
| 1802 | } else { |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1803 | netdev_info(dev->net, "disabling magic packet wakeup\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1804 | val &= ~WUCSR_MPEN_; |
| 1805 | } |
| 1806 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1807 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1808 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1809 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1810 | |
| 1811 | /* enable wol wakeup source */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1812 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1813 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1814 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1815 | |
| 1816 | val |= PM_CTL_WOL_EN_; |
| 1817 | |
Steve Glendinning | e5e3af8 | 2012-11-22 08:05:24 +0000 | [diff] [blame] | 1818 | /* phy energy detect wakeup source */ |
| 1819 | if (pdata->wolopts & WAKE_PHY) |
| 1820 | val |= PM_CTL_ED_EN_; |
| 1821 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1822 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1823 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1824 | goto done; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1825 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1826 | /* enable receiver to enable frame reception */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1827 | smsc95xx_start_rx_path(dev, 1); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1828 | |
| 1829 | /* some wol options are enabled, so enter SUSPEND0 */ |
Joe Perches | 1e1d741 | 2012-11-24 01:27:49 +0000 | [diff] [blame] | 1830 | netdev_info(dev->net, "entering SUSPEND0 mode\n"); |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1831 | ret = smsc95xx_enter_suspend0(dev); |
| 1832 | |
| 1833 | done: |
Ming Lei | 0d41be5 | 2013-03-15 12:08:58 +0800 | [diff] [blame] | 1834 | /* |
| 1835 | * TODO: resume() might need to handle the suspend failure |
| 1836 | * in system sleep |
| 1837 | */ |
| 1838 | if (ret && PMSG_IS_AUTO(message)) |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1839 | usbnet_resume(intf); |
Frieder Schrempf | 7b900ea | 2018-10-31 22:52:19 +0100 | [diff] [blame] | 1840 | |
| 1841 | if (ret) |
| 1842 | schedule_delayed_work(&pdata->carrier_check, |
| 1843 | CARRIER_CHECK_DELAY); |
| 1844 | |
Steve Glendinning | 3b9f7d8 | 2012-11-30 05:55:49 +0000 | [diff] [blame] | 1845 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | static int smsc95xx_resume(struct usb_interface *intf) |
| 1849 | { |
| 1850 | struct usbnet *dev = usb_get_intfdata(intf); |
Sudip Mukherjee | 8bca81d | 2014-11-11 14:10:47 +0530 | [diff] [blame] | 1851 | struct smsc95xx_priv *pdata; |
| 1852 | u8 suspend_flags; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1853 | int ret; |
| 1854 | u32 val; |
| 1855 | |
| 1856 | BUG_ON(!dev); |
Sudip Mukherjee | 8bca81d | 2014-11-11 14:10:47 +0530 | [diff] [blame] | 1857 | pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 1858 | suspend_flags = pdata->suspend_flags; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1859 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1860 | netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags); |
| 1861 | |
| 1862 | /* do this first to ensure it's cleared even in error case */ |
| 1863 | pdata->suspend_flags = 0; |
Christoph Fritz | d69d169 | 2016-05-26 04:06:47 +0200 | [diff] [blame] | 1864 | schedule_delayed_work(&pdata->carrier_check, CARRIER_CHECK_DELAY); |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 1865 | |
| 1866 | if (suspend_flags & SUSPEND_ALLMODES) { |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1867 | /* clear wake-up sources */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1868 | ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1869 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1870 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1871 | |
Steve Glendinning | bbd9f9e | 2012-10-26 03:43:56 +0000 | [diff] [blame] | 1872 | val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1873 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1874 | ret = smsc95xx_write_reg_nopm(dev, WUCSR, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1875 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1876 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1877 | |
| 1878 | /* clear wake-up status */ |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1879 | ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1880 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1881 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1882 | |
| 1883 | val &= ~PM_CTL_WOL_EN_; |
| 1884 | val |= PM_CTL_WUPS_; |
| 1885 | |
Ming Lei | ec32115 | 2012-11-06 04:53:07 +0000 | [diff] [blame] | 1886 | ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val); |
Steve Glendinning | e360a8b | 2013-01-03 03:00:15 +0000 | [diff] [blame] | 1887 | if (ret < 0) |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1888 | return ret; |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Steve Glendinning | af3d7c1 | 2012-11-22 08:05:22 +0000 | [diff] [blame] | 1891 | ret = usbnet_resume(intf); |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1892 | if (ret < 0) |
| 1893 | netdev_warn(dev->net, "usbnet_resume error\n"); |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 1894 | |
Steve Glendinning | b052e07 | 2012-11-30 05:55:52 +0000 | [diff] [blame] | 1895 | return ret; |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
Joonyoung Shim | b4df480 | 2014-07-10 11:49:42 +0900 | [diff] [blame] | 1898 | static int smsc95xx_reset_resume(struct usb_interface *intf) |
| 1899 | { |
| 1900 | struct usbnet *dev = usb_get_intfdata(intf); |
| 1901 | int ret; |
| 1902 | |
| 1903 | ret = smsc95xx_reset(dev); |
| 1904 | if (ret < 0) |
| 1905 | return ret; |
| 1906 | |
| 1907 | return smsc95xx_resume(intf); |
| 1908 | } |
| 1909 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1910 | static void smsc95xx_rx_csum_offload(struct sk_buff *skb) |
| 1911 | { |
| 1912 | skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2); |
| 1913 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1914 | skb_trim(skb, skb->len - 2); |
| 1915 | } |
| 1916 | |
| 1917 | static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb) |
| 1918 | { |
Emil Goode | eb85569 | 2014-02-13 17:50:19 +0100 | [diff] [blame] | 1919 | /* This check is no longer done by usbnet */ |
| 1920 | if (skb->len < dev->net->hard_header_len) |
| 1921 | return 0; |
| 1922 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1923 | while (skb->len > 0) { |
| 1924 | u32 header, align_count; |
| 1925 | struct sk_buff *ax_skb; |
| 1926 | unsigned char *packet; |
| 1927 | u16 size; |
| 1928 | |
Ben Dooks | 6809d21 | 2018-11-14 11:50:21 +0000 | [diff] [blame] | 1929 | header = get_unaligned_le32(skb->data); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1930 | skb_pull(skb, 4 + NET_IP_ALIGN); |
| 1931 | packet = skb->data; |
| 1932 | |
| 1933 | /* get the packet length */ |
| 1934 | size = (u16)((header & RX_STS_FL_) >> 16); |
| 1935 | align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4; |
| 1936 | |
| 1937 | if (unlikely(header & RX_STS_ES_)) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1938 | netif_dbg(dev, rx_err, dev->net, |
| 1939 | "Error header=0x%08x\n", header); |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1940 | dev->net->stats.rx_errors++; |
| 1941 | dev->net->stats.rx_dropped++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1942 | |
| 1943 | if (header & RX_STS_CRC_) { |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1944 | dev->net->stats.rx_crc_errors++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1945 | } else { |
| 1946 | if (header & (RX_STS_TL_ | RX_STS_RF_)) |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1947 | dev->net->stats.rx_frame_errors++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1948 | |
| 1949 | if ((header & RX_STS_LE_) && |
| 1950 | (!(header & RX_STS_FT_))) |
Herbert Xu | 80667ac | 2009-06-29 16:53:00 +0000 | [diff] [blame] | 1951 | dev->net->stats.rx_length_errors++; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1952 | } |
| 1953 | } else { |
| 1954 | /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */ |
| 1955 | if (unlikely(size > (ETH_FRAME_LEN + 12))) { |
Joe Perches | a475f60 | 2010-02-17 10:30:24 +0000 | [diff] [blame] | 1956 | netif_dbg(dev, rx_err, dev->net, |
| 1957 | "size err header=0x%08x\n", header); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1958 | return 0; |
| 1959 | } |
| 1960 | |
| 1961 | /* last frame in this batch */ |
| 1962 | if (skb->len == size) { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1963 | if (dev->net->features & NETIF_F_RXCSUM) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1964 | smsc95xx_rx_csum_offload(skb); |
Peter Korsgaard | df18acc | 2009-05-13 10:10:41 +0000 | [diff] [blame] | 1965 | skb_trim(skb, skb->len - 4); /* remove fcs */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1966 | skb->truesize = size + sizeof(struct sk_buff); |
| 1967 | |
| 1968 | return 1; |
| 1969 | } |
| 1970 | |
| 1971 | ax_skb = skb_clone(skb, GFP_ATOMIC); |
| 1972 | if (unlikely(!ax_skb)) { |
Joe Perches | 60b8675 | 2010-02-17 10:30:23 +0000 | [diff] [blame] | 1973 | netdev_warn(dev->net, "Error allocating skb\n"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1974 | return 0; |
| 1975 | } |
| 1976 | |
| 1977 | ax_skb->len = size; |
| 1978 | ax_skb->data = packet; |
| 1979 | skb_set_tail_pointer(ax_skb, size); |
| 1980 | |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 1981 | if (dev->net->features & NETIF_F_RXCSUM) |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1982 | smsc95xx_rx_csum_offload(ax_skb); |
Peter Korsgaard | df18acc | 2009-05-13 10:10:41 +0000 | [diff] [blame] | 1983 | skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1984 | ax_skb->truesize = size + sizeof(struct sk_buff); |
| 1985 | |
| 1986 | usbnet_skb_return(dev, ax_skb); |
| 1987 | } |
| 1988 | |
| 1989 | skb_pull(skb, size); |
| 1990 | |
| 1991 | /* padding bytes before the next frame starts */ |
| 1992 | if (skb->len) |
| 1993 | skb_pull(skb, align_count); |
| 1994 | } |
| 1995 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 1996 | return 1; |
| 1997 | } |
| 1998 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 1999 | static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb) |
| 2000 | { |
Michał Mirosław | 55508d6 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 2001 | u16 low_16 = (u16)skb_checksum_start_offset(skb); |
| 2002 | u16 high_16 = low_16 + skb->csum_offset; |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 2003 | return (high_16 << 16) | low_16; |
| 2004 | } |
| 2005 | |
Ben Dooks | 75938f7 | 2018-11-14 11:50:22 +0000 | [diff] [blame] | 2006 | /* The TX CSUM won't work if the checksum lies in the last 4 bytes of the |
| 2007 | * transmission. This is fairly unlikely, only seems to trigger with some |
| 2008 | * short TCP ACK packets sent. |
| 2009 | * |
| 2010 | * Note, this calculation should probably check for the alignment of the |
| 2011 | * data as well, but a straight check for csum being in the last four bytes |
| 2012 | * of the packet should be ok for now. |
| 2013 | */ |
| 2014 | static bool smsc95xx_can_tx_checksum(struct sk_buff *skb) |
| 2015 | { |
| 2016 | unsigned int len = skb->len - skb_checksum_start_offset(skb); |
| 2017 | |
| 2018 | if (skb->len <= 45) |
| 2019 | return false; |
| 2020 | return skb->csum_offset < (len - (4 + 1)); |
| 2021 | } |
| 2022 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2023 | static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev, |
| 2024 | struct sk_buff *skb, gfp_t flags) |
| 2025 | { |
Michał Mirosław | 78e47fe | 2011-04-01 20:56:23 -0700 | [diff] [blame] | 2026 | bool csum = skb->ip_summed == CHECKSUM_PARTIAL; |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 2027 | int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2028 | u32 tx_cmd_a, tx_cmd_b; |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 2029 | void *ptr; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2030 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 2031 | /* We do not advertise SG, so skbs should be already linearized */ |
| 2032 | BUG_ON(skb_shinfo(skb)->nr_frags); |
| 2033 | |
James Hughes | e9156cd | 2017-04-19 11:13:40 +0100 | [diff] [blame] | 2034 | /* Make writable and expand header space by overhead if required */ |
| 2035 | if (skb_cow_head(skb, overhead)) { |
| 2036 | /* Must deallocate here as returning NULL to indicate error |
| 2037 | * means the skb won't be deallocated in the caller. |
| 2038 | */ |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2039 | dev_kfree_skb_any(skb); |
James Hughes | e9156cd | 2017-04-19 11:13:40 +0100 | [diff] [blame] | 2040 | return NULL; |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 2043 | tx_cmd_b = (u32)skb->len; |
| 2044 | tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_; |
| 2045 | |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 2046 | if (csum) { |
Ben Dooks | 75938f7 | 2018-11-14 11:50:22 +0000 | [diff] [blame] | 2047 | if (!smsc95xx_can_tx_checksum(skb)) { |
Steve Glendinning | 11bc308 | 2010-03-18 22:18:41 -0700 | [diff] [blame] | 2048 | /* workaround - hardware tx checksum does not work |
| 2049 | * properly with extremely small packets */ |
Michał Mirosław | 55508d6 | 2010-12-14 15:24:08 +0000 | [diff] [blame] | 2050 | long csstart = skb_checksum_start_offset(skb); |
Steve Glendinning | 11bc308 | 2010-03-18 22:18:41 -0700 | [diff] [blame] | 2051 | __wsum calc = csum_partial(skb->data + csstart, |
| 2052 | skb->len - csstart, 0); |
| 2053 | *((__sum16 *)(skb->data + csstart |
| 2054 | + skb->csum_offset)) = csum_fold(calc); |
| 2055 | |
| 2056 | csum = false; |
| 2057 | } else { |
| 2058 | u32 csum_preamble = smsc95xx_calc_csum_preamble(skb); |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 2059 | ptr = skb_push(skb, 4); |
| 2060 | put_unaligned_le32(csum_preamble, ptr); |
| 2061 | |
| 2062 | tx_cmd_a += 4; |
| 2063 | tx_cmd_b += 4; |
| 2064 | tx_cmd_b |= TX_CMD_B_CSUM_ENABLE; |
Steve Glendinning | 11bc308 | 2010-03-18 22:18:41 -0700 | [diff] [blame] | 2065 | } |
Steve Glendinning | f7b2927 | 2008-11-20 04:19:21 -0800 | [diff] [blame] | 2066 | } |
| 2067 | |
Ben Dooks | 0c8b265 | 2018-11-14 11:50:20 +0000 | [diff] [blame] | 2068 | ptr = skb_push(skb, 8); |
| 2069 | put_unaligned_le32(tx_cmd_a, ptr); |
| 2070 | put_unaligned_le32(tx_cmd_b, ptr+4); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2071 | |
| 2072 | return skb; |
| 2073 | } |
| 2074 | |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 2075 | static int smsc95xx_manage_power(struct usbnet *dev, int on) |
| 2076 | { |
| 2077 | struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); |
| 2078 | |
| 2079 | dev->intf->needs_remote_wakeup = on; |
| 2080 | |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 2081 | if (pdata->features & FEATURE_REMOTE_WAKEUP) |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 2082 | return 0; |
| 2083 | |
Ming Lei | eb970ff | 2013-02-22 03:05:05 +0000 | [diff] [blame] | 2084 | /* this chip revision isn't capable of remote wakeup */ |
| 2085 | netdev_info(dev->net, "hardware isn't capable of remote wakeup\n"); |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 2086 | |
| 2087 | if (on) |
| 2088 | usb_autopm_get_interface_no_resume(dev->intf); |
| 2089 | else |
| 2090 | usb_autopm_put_interface(dev->intf); |
| 2091 | |
| 2092 | return 0; |
| 2093 | } |
| 2094 | |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2095 | static const struct driver_info smsc95xx_info = { |
| 2096 | .description = "smsc95xx USB 2.0 Ethernet", |
| 2097 | .bind = smsc95xx_bind, |
| 2098 | .unbind = smsc95xx_unbind, |
| 2099 | .link_reset = smsc95xx_link_reset, |
| 2100 | .reset = smsc95xx_reset, |
| 2101 | .rx_fixup = smsc95xx_rx_fixup, |
| 2102 | .tx_fixup = smsc95xx_tx_fixup, |
| 2103 | .status = smsc95xx_status, |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 2104 | .manage_power = smsc95xx_manage_power, |
Paolo Pisati | 07d69d4 | 2012-04-23 04:05:20 +0000 | [diff] [blame] | 2105 | .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2106 | }; |
| 2107 | |
| 2108 | static const struct usb_device_id products[] = { |
| 2109 | { |
| 2110 | /* SMSC9500 USB Ethernet Device */ |
| 2111 | USB_DEVICE(0x0424, 0x9500), |
| 2112 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2113 | }, |
Steve Glendinning | 726474b | 2009-05-01 06:07:22 +0000 | [diff] [blame] | 2114 | { |
Steve Glendinning | 6f41d12 | 2009-09-22 05:13:02 +0000 | [diff] [blame] | 2115 | /* SMSC9505 USB Ethernet Device */ |
| 2116 | USB_DEVICE(0x0424, 0x9505), |
| 2117 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2118 | }, |
| 2119 | { |
| 2120 | /* SMSC9500A USB Ethernet Device */ |
| 2121 | USB_DEVICE(0x0424, 0x9E00), |
| 2122 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2123 | }, |
| 2124 | { |
| 2125 | /* SMSC9505A USB Ethernet Device */ |
| 2126 | USB_DEVICE(0x0424, 0x9E01), |
| 2127 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2128 | }, |
| 2129 | { |
Steve Glendinning | 726474b | 2009-05-01 06:07:22 +0000 | [diff] [blame] | 2130 | /* SMSC9512/9514 USB Hub & Ethernet Device */ |
| 2131 | USB_DEVICE(0x0424, 0xec00), |
| 2132 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2133 | }, |
Steve Glendinning | 6f41d12 | 2009-09-22 05:13:02 +0000 | [diff] [blame] | 2134 | { |
| 2135 | /* SMSC9500 USB Ethernet Device (SAL10) */ |
| 2136 | USB_DEVICE(0x0424, 0x9900), |
| 2137 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2138 | }, |
| 2139 | { |
| 2140 | /* SMSC9505 USB Ethernet Device (SAL10) */ |
| 2141 | USB_DEVICE(0x0424, 0x9901), |
| 2142 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2143 | }, |
| 2144 | { |
| 2145 | /* SMSC9500A USB Ethernet Device (SAL10) */ |
| 2146 | USB_DEVICE(0x0424, 0x9902), |
| 2147 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2148 | }, |
| 2149 | { |
| 2150 | /* SMSC9505A USB Ethernet Device (SAL10) */ |
| 2151 | USB_DEVICE(0x0424, 0x9903), |
| 2152 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2153 | }, |
| 2154 | { |
| 2155 | /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */ |
| 2156 | USB_DEVICE(0x0424, 0x9904), |
| 2157 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2158 | }, |
| 2159 | { |
| 2160 | /* SMSC9500A USB Ethernet Device (HAL) */ |
| 2161 | USB_DEVICE(0x0424, 0x9905), |
| 2162 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2163 | }, |
| 2164 | { |
| 2165 | /* SMSC9505A USB Ethernet Device (HAL) */ |
| 2166 | USB_DEVICE(0x0424, 0x9906), |
| 2167 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2168 | }, |
| 2169 | { |
| 2170 | /* SMSC9500 USB Ethernet Device (Alternate ID) */ |
| 2171 | USB_DEVICE(0x0424, 0x9907), |
| 2172 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2173 | }, |
| 2174 | { |
| 2175 | /* SMSC9500A USB Ethernet Device (Alternate ID) */ |
| 2176 | USB_DEVICE(0x0424, 0x9908), |
| 2177 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2178 | }, |
| 2179 | { |
| 2180 | /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */ |
| 2181 | USB_DEVICE(0x0424, 0x9909), |
| 2182 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2183 | }, |
Steve Glendinning | 88edaa4 | 2011-04-10 18:59:27 -0700 | [diff] [blame] | 2184 | { |
| 2185 | /* SMSC LAN9530 USB Ethernet Device */ |
| 2186 | USB_DEVICE(0x0424, 0x9530), |
| 2187 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2188 | }, |
| 2189 | { |
| 2190 | /* SMSC LAN9730 USB Ethernet Device */ |
| 2191 | USB_DEVICE(0x0424, 0x9730), |
| 2192 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2193 | }, |
| 2194 | { |
| 2195 | /* SMSC LAN89530 USB Ethernet Device */ |
| 2196 | USB_DEVICE(0x0424, 0x9E08), |
| 2197 | .driver_info = (unsigned long) &smsc95xx_info, |
| 2198 | }, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2199 | { }, /* END */ |
| 2200 | }; |
| 2201 | MODULE_DEVICE_TABLE(usb, products); |
| 2202 | |
| 2203 | static struct usb_driver smsc95xx_driver = { |
| 2204 | .name = "smsc95xx", |
| 2205 | .id_table = products, |
| 2206 | .probe = usbnet_probe, |
Steve Glendinning | b5a0447 | 2012-09-28 00:07:11 +0000 | [diff] [blame] | 2207 | .suspend = smsc95xx_suspend, |
Steve Glendinning | e0e474a | 2012-09-28 00:07:12 +0000 | [diff] [blame] | 2208 | .resume = smsc95xx_resume, |
Joonyoung Shim | b4df480 | 2014-07-10 11:49:42 +0900 | [diff] [blame] | 2209 | .reset_resume = smsc95xx_reset_resume, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2210 | .disconnect = usbnet_disconnect, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 2211 | .disable_hub_initiated_lpm = 1, |
Steve Glendinning | b2d4b15 | 2013-01-03 03:00:16 +0000 | [diff] [blame] | 2212 | .supports_autosuspend = 1, |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2213 | }; |
| 2214 | |
Greg Kroah-Hartman | d632eb1 | 2011-11-18 09:44:20 -0800 | [diff] [blame] | 2215 | module_usb_driver(smsc95xx_driver); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2216 | |
| 2217 | MODULE_AUTHOR("Nancy Lin"); |
Steve Glendinning | 90b24cf | 2012-04-16 12:13:29 +0100 | [diff] [blame] | 2218 | MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>"); |
Steve Glendinning | 2f7ca80 | 2008-10-02 05:27:57 +0000 | [diff] [blame] | 2219 | MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices"); |
| 2220 | MODULE_LICENSE("GPL"); |