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