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