blob: f7e1e189fa4a7efa904eee5b09f260cdfaf7ac00 [file] [log] [blame]
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001 /***************************************************************************
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 Glendinningbbd9f9e2012-10-26 03:43:56 +000029#include <linux/bitrev.h>
30#include <linux/crc16.h>
Steve Glendinning2f7ca802008-10-02 05:27:57 +000031#include <linux/crc32.h>
32#include <linux/usb/usbnet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Steve Glendinning2f7ca802008-10-02 05:27:57 +000034#include "smsc95xx.h"
35
36#define SMSC_CHIPNAME "smsc95xx"
Steve Glendinningf7b29272008-11-20 04:19:21 -080037#define SMSC_DRIVER_VERSION "1.0.4"
Steve Glendinning2f7ca802008-10-02 05:27:57 +000038#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 Glendinningf7b29272008-11-20 04:19:21 -080046#define DEFAULT_TX_CSUM_ENABLE (true)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000047#define DEFAULT_RX_CSUM_ENABLE (true)
48#define SMSC95XX_INTERNAL_PHY_ID (1)
49#define SMSC95XX_TX_OVERHEAD (8)
Steve Glendinningf7b29272008-11-20 04:19:21 -080050#define SMSC95XX_TX_OVERHEAD_CSUM (12)
Steve Glendinninge5e3af82012-11-22 08:05:24 +000051#define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +000052 WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000053
Steve Glendinning9ebca502012-11-22 08:05:23 +000054#define FEATURE_8_WAKEUP_FILTERS (0x01)
55#define FEATURE_PHY_NLP_CROSSOVER (0x02)
56#define FEATURE_AUTOSUSPEND (0x04)
57
Steve Glendinning2f7ca802008-10-02 05:27:57 +000058struct smsc95xx_priv {
59 u32 mac_cr;
Marc Zyngier3c0f3c62011-03-18 03:53:58 +000060 u32 hash_hi;
61 u32 hash_lo;
Steve Glendinninge0e474a2012-09-28 00:07:12 +000062 u32 wolopts;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000063 spinlock_t mac_cr_lock;
Steve Glendinning9ebca502012-11-22 08:05:23 +000064 u8 features;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000065};
66
Rusty Russelleb939922011-12-19 14:08:01 +000067static bool turbo_mode = true;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000068module_param(turbo_mode, bool, 0644);
69MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
70
Ming Leiec321152012-11-06 04:53:07 +000071static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
72 u32 *data, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000073{
Ming Lei72108fd2012-10-24 19:47:04 +000074 u32 buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000075 int ret;
Ming Leiec321152012-11-06 04:53:07 +000076 int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000077
78 BUG_ON(!dev);
79
Ming Leiec321152012-11-06 04:53:07 +000080 if (!in_pm)
81 fn = usbnet_read_cmd;
82 else
83 fn = usbnet_read_cmd_nopm;
84
85 ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
86 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
87 0, index, &buf, 4);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000088 if (unlikely(ret < 0))
Joe Perches1e1d7412012-11-24 01:27:49 +000089 netdev_warn(dev->net, "Failed to read reg index 0x%08x: %d\n",
90 index, ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000091
Ming Lei72108fd2012-10-24 19:47:04 +000092 le32_to_cpus(&buf);
93 *data = buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000094
95 return ret;
96}
97
Ming Leiec321152012-11-06 04:53:07 +000098static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
99 u32 data, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000100{
Ming Lei72108fd2012-10-24 19:47:04 +0000101 u32 buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000102 int ret;
Ming Leiec321152012-11-06 04:53:07 +0000103 int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000104
105 BUG_ON(!dev);
106
Ming Leiec321152012-11-06 04:53:07 +0000107 if (!in_pm)
108 fn = usbnet_write_cmd;
109 else
110 fn = usbnet_write_cmd_nopm;
111
Ming Lei72108fd2012-10-24 19:47:04 +0000112 buf = data;
113 cpu_to_le32s(&buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000114
Ming Leiec321152012-11-06 04:53:07 +0000115 ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
116 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
117 0, index, &buf, 4);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000118 if (unlikely(ret < 0))
Joe Perches1e1d7412012-11-24 01:27:49 +0000119 netdev_warn(dev->net, "Failed to write reg index 0x%08x: %d\n",
120 index, ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000121
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000122 return ret;
123}
124
Ming Leiec321152012-11-06 04:53:07 +0000125static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
126 u32 *data)
127{
128 return __smsc95xx_read_reg(dev, index, data, 1);
129}
130
131static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
132 u32 data)
133{
134 return __smsc95xx_write_reg(dev, index, data, 1);
135}
136
137static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
138 u32 *data)
139{
140 return __smsc95xx_read_reg(dev, index, data, 0);
141}
142
143static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
144 u32 data)
145{
146 return __smsc95xx_write_reg(dev, index, data, 0);
147}
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000148
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000149/* Loop until the read is completed with timeout
150 * called with phy_mutex held */
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000151static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,
152 int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000153{
154 unsigned long start_time = jiffies;
155 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000156 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000157
158 do {
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000159 ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000160 if (ret < 0) {
161 netdev_warn(dev->net, "Error reading MII_ACCESS\n");
162 return ret;
163 }
164
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000165 if (!(val & MII_BUSY_))
166 return 0;
167 } while (!time_after(jiffies, start_time + HZ));
168
169 return -EIO;
170}
171
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000172static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx,
173 int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000174{
175 struct usbnet *dev = netdev_priv(netdev);
176 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000177 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000178
179 mutex_lock(&dev->phy_mutex);
180
181 /* confirm MII not busy */
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000182 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000183 if (ret < 0) {
184 netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n");
185 goto done;
186 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000187
188 /* set the address, index & direction (read from PHY) */
189 phy_id &= dev->mii.phy_id_mask;
190 idx &= dev->mii.reg_num_mask;
Steve Glendinning80928802012-11-06 00:08:53 +0000191 addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_;
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000192 ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000193 if (ret < 0) {
194 netdev_warn(dev->net, "Error writing MII_ADDR\n");
195 goto done;
196 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000197
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000198 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000199 if (ret < 0) {
200 netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx);
201 goto done;
202 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000203
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000204 ret = __smsc95xx_read_reg(dev, MII_DATA, &val, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000205 if (ret < 0) {
206 netdev_warn(dev->net, "Error reading MII_DATA\n");
207 goto done;
208 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000209
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000210 ret = (u16)(val & 0xFFFF);
211
212done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000213 mutex_unlock(&dev->phy_mutex);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000214 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000215}
216
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000217static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,
218 int idx, int regval, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000219{
220 struct usbnet *dev = netdev_priv(netdev);
221 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000222 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000223
224 mutex_lock(&dev->phy_mutex);
225
226 /* confirm MII not busy */
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000227 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000228 if (ret < 0) {
229 netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n");
230 goto done;
231 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000232
233 val = regval;
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000234 ret = __smsc95xx_write_reg(dev, MII_DATA, val, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000235 if (ret < 0) {
236 netdev_warn(dev->net, "Error writing MII_DATA\n");
237 goto done;
238 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000239
240 /* set the address, index & direction (write to PHY) */
241 phy_id &= dev->mii.phy_id_mask;
242 idx &= dev->mii.reg_num_mask;
Steve Glendinning80928802012-11-06 00:08:53 +0000243 addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_;
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000244 ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000245 if (ret < 0) {
246 netdev_warn(dev->net, "Error writing MII_ADDR\n");
247 goto done;
248 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000249
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000250 ret = __smsc95xx_phy_wait_not_busy(dev, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000251 if (ret < 0) {
252 netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx);
253 goto done;
254 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000255
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000256done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000257 mutex_unlock(&dev->phy_mutex);
258}
259
Steve Glendinninge5e3af82012-11-22 08:05:24 +0000260static int smsc95xx_mdio_read_nopm(struct net_device *netdev, int phy_id,
261 int idx)
262{
263 return __smsc95xx_mdio_read(netdev, phy_id, idx, 1);
264}
265
266static void smsc95xx_mdio_write_nopm(struct net_device *netdev, int phy_id,
267 int idx, int regval)
268{
269 __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 1);
270}
271
272static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
273{
274 return __smsc95xx_mdio_read(netdev, phy_id, idx, 0);
275}
276
277static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
278 int regval)
279{
280 __smsc95xx_mdio_write(netdev, phy_id, idx, regval, 0);
281}
282
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000283static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000284{
285 unsigned long start_time = jiffies;
286 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000287 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000288
289 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000290 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000291 if (ret < 0) {
292 netdev_warn(dev->net, "Error reading E2P_CMD\n");
293 return ret;
294 }
295
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000296 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
297 break;
298 udelay(40);
299 } while (!time_after(jiffies, start_time + HZ));
300
301 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
Joe Perches60b86752010-02-17 10:30:23 +0000302 netdev_warn(dev->net, "EEPROM read operation timeout\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000303 return -EIO;
304 }
305
306 return 0;
307}
308
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000309static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000310{
311 unsigned long start_time = jiffies;
312 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000313 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000314
315 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000316 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000317 if (ret < 0) {
318 netdev_warn(dev->net, "Error reading E2P_CMD\n");
319 return ret;
320 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000321
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000322 if (!(val & E2P_CMD_BUSY_))
323 return 0;
324
325 udelay(40);
326 } while (!time_after(jiffies, start_time + HZ));
327
Joe Perches60b86752010-02-17 10:30:23 +0000328 netdev_warn(dev->net, "EEPROM is busy\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000329 return -EIO;
330}
331
332static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
333 u8 *data)
334{
335 u32 val;
336 int i, ret;
337
338 BUG_ON(!dev);
339 BUG_ON(!data);
340
341 ret = smsc95xx_eeprom_confirm_not_busy(dev);
342 if (ret)
343 return ret;
344
345 for (i = 0; i < length; i++) {
346 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000347 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000348 if (ret < 0) {
349 netdev_warn(dev->net, "Error writing E2P_CMD\n");
350 return ret;
351 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000352
353 ret = smsc95xx_wait_eeprom(dev);
354 if (ret < 0)
355 return ret;
356
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000357 ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000358 if (ret < 0) {
359 netdev_warn(dev->net, "Error reading E2P_DATA\n");
360 return ret;
361 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000362
363 data[i] = val & 0xFF;
364 offset++;
365 }
366
367 return 0;
368}
369
370static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
371 u8 *data)
372{
373 u32 val;
374 int i, ret;
375
376 BUG_ON(!dev);
377 BUG_ON(!data);
378
379 ret = smsc95xx_eeprom_confirm_not_busy(dev);
380 if (ret)
381 return ret;
382
383 /* Issue write/erase enable command */
384 val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000385 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000386 if (ret < 0) {
387 netdev_warn(dev->net, "Error writing E2P_DATA\n");
388 return ret;
389 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000390
391 ret = smsc95xx_wait_eeprom(dev);
392 if (ret < 0)
393 return ret;
394
395 for (i = 0; i < length; i++) {
396
397 /* Fill data register */
398 val = data[i];
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000399 ret = smsc95xx_write_reg(dev, E2P_DATA, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000400 if (ret < 0) {
401 netdev_warn(dev->net, "Error writing E2P_DATA\n");
402 return ret;
403 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000404
405 /* Send "write" command */
406 val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000407 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
Steve Glendinningb052e072012-11-30 05:55:52 +0000408 if (ret < 0) {
409 netdev_warn(dev->net, "Error writing E2P_CMD\n");
410 return ret;
411 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000412
413 ret = smsc95xx_wait_eeprom(dev);
414 if (ret < 0)
415 return ret;
416
417 offset++;
418 }
419
420 return 0;
421}
422
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000423static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
424 u32 *data)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000425{
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700426 const u16 size = 4;
Ming Lei72108fd2012-10-24 19:47:04 +0000427 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000428
Ming Lei72108fd2012-10-24 19:47:04 +0000429 ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
430 USB_DIR_OUT | USB_TYPE_VENDOR |
431 USB_RECIP_DEVICE,
432 0, index, data, size);
433 if (ret < 0)
434 netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
435 ret);
436 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000437}
438
439/* returns hash bit number for given MAC address
440 * example:
441 * 01 00 5E 00 00 01 -> returns bit number 31 */
442static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
443{
444 return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
445}
446
447static void smsc95xx_set_multicast(struct net_device *netdev)
448{
449 struct usbnet *dev = netdev_priv(netdev);
450 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000451 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000452 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000453
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000454 pdata->hash_hi = 0;
455 pdata->hash_lo = 0;
456
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000457 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
458
459 if (dev->net->flags & IFF_PROMISC) {
Joe Perchesa475f602010-02-17 10:30:24 +0000460 netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000461 pdata->mac_cr |= MAC_CR_PRMS_;
462 pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
463 } else if (dev->net->flags & IFF_ALLMULTI) {
Joe Perchesa475f602010-02-17 10:30:24 +0000464 netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000465 pdata->mac_cr |= MAC_CR_MCPAS_;
466 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000467 } else if (!netdev_mc_empty(dev->net)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +0000468 struct netdev_hw_addr *ha;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000469
470 pdata->mac_cr |= MAC_CR_HPFILT_;
471 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
472
Jiri Pirko22bedad32010-04-01 21:22:57 +0000473 netdev_for_each_mc_addr(ha, netdev) {
474 u32 bitnum = smsc95xx_hash(ha->addr);
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000475 u32 mask = 0x01 << (bitnum & 0x1F);
476 if (bitnum & 0x20)
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000477 pdata->hash_hi |= mask;
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000478 else
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000479 pdata->hash_lo |= mask;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000480 }
481
Joe Perchesa475f602010-02-17 10:30:24 +0000482 netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000483 pdata->hash_hi, pdata->hash_lo);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000484 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000485 netif_dbg(dev, drv, dev->net, "receive own packets only\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000486 pdata->mac_cr &=
487 ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
488 }
489
490 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
491
492 /* Initiate async writes, as we can't wait for completion here */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000493 ret = smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi);
Steve Glendinningb052e072012-11-30 05:55:52 +0000494 if (ret < 0)
495 netdev_warn(dev->net, "failed to initiate async write to HASHH\n");
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000496
497 ret = smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo);
Steve Glendinningb052e072012-11-30 05:55:52 +0000498 if (ret < 0)
499 netdev_warn(dev->net, "failed to initiate async write to HASHL\n");
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000500
501 ret = smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr);
Steve Glendinningb052e072012-11-30 05:55:52 +0000502 if (ret < 0)
503 netdev_warn(dev->net, "failed to initiate async write to MAC_CR\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000504}
505
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000506static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
507 u16 lcladv, u16 rmtadv)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000508{
509 u32 flow, afc_cfg = 0;
510
511 int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
Steve Glendinningb052e072012-11-30 05:55:52 +0000512 if (ret < 0) {
513 netdev_warn(dev->net, "Error reading AFC_CFG\n");
514 return ret;
515 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000516
517 if (duplex == DUPLEX_FULL) {
Steve Glendinningbc02ff92008-12-16 02:00:48 -0800518 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000519
520 if (cap & FLOW_CTRL_RX)
521 flow = 0xFFFF0002;
522 else
523 flow = 0;
524
525 if (cap & FLOW_CTRL_TX)
526 afc_cfg |= 0xF;
527 else
528 afc_cfg &= ~0xF;
529
Joe Perchesa475f602010-02-17 10:30:24 +0000530 netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
Joe Perches60b86752010-02-17 10:30:23 +0000531 cap & FLOW_CTRL_RX ? "enabled" : "disabled",
532 cap & FLOW_CTRL_TX ? "enabled" : "disabled");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000533 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000534 netif_dbg(dev, link, dev->net, "half duplex\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000535 flow = 0;
536 afc_cfg |= 0xF;
537 }
538
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000539 ret = smsc95xx_write_reg(dev, FLOW, flow);
Steve Glendinningb052e072012-11-30 05:55:52 +0000540 if (ret < 0) {
541 netdev_warn(dev->net, "Error writing FLOW\n");
542 return ret;
543 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000544
545 ret = smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
Steve Glendinningb052e072012-11-30 05:55:52 +0000546 if (ret < 0)
547 netdev_warn(dev->net, "Error writing AFC_CFG\n");
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000548
Steve Glendinningb052e072012-11-30 05:55:52 +0000549 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000550}
551
552static int smsc95xx_link_reset(struct usbnet *dev)
553{
554 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
555 struct mii_if_info *mii = &dev->mii;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000556 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000557 unsigned long flags;
558 u16 lcladv, rmtadv;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000559 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000560
561 /* clear interrupt status */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000562 ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
Steve Glendinningb052e072012-11-30 05:55:52 +0000563 if (ret < 0) {
564 netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
565 return ret;
566 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000567
568 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
Steve Glendinningb052e072012-11-30 05:55:52 +0000569 if (ret < 0) {
570 netdev_warn(dev->net, "Error writing INT_STS\n");
571 return ret;
572 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000573
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 Decotigny8ae6daca2011-04-27 18:32:38 +0000579 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 Glendinning2f7ca802008-10-02 05:27:57 +0000582
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 Glendinning769ea6d2012-09-28 00:07:09 +0000593 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
Steve Glendinningb052e072012-11-30 05:55:52 +0000594 if (ret < 0) {
595 netdev_warn(dev->net, "Error writing MAC_CR\n");
596 return ret;
597 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000598
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000599 ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
Steve Glendinningb052e072012-11-30 05:55:52 +0000600 if (ret < 0)
601 netdev_warn(dev->net, "Error updating PHY flow control\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000602
Steve Glendinningb052e072012-11-30 05:55:52 +0000603 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000604}
605
606static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
607{
608 u32 intdata;
609
610 if (urb->actual_length != 4) {
Joe Perches60b86752010-02-17 10:30:23 +0000611 netdev_warn(dev->net, "unexpected urb length %d\n",
612 urb->actual_length);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000613 return;
614 }
615
616 memcpy(&intdata, urb->transfer_buffer, 4);
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700617 le32_to_cpus(&intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000618
Joe Perchesa475f602010-02-17 10:30:24 +0000619 netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000620
621 if (intdata & INT_ENP_PHY_INT_)
622 usbnet_defer_kevent(dev, EVENT_LINK_RESET);
623 else
Joe Perches60b86752010-02-17 10:30:23 +0000624 netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
625 intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000626}
627
Steve Glendinningf7b29272008-11-20 04:19:21 -0800628/* Enable or disable Tx & Rx checksum offload engines */
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000629static int smsc95xx_set_features(struct net_device *netdev,
630 netdev_features_t features)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000631{
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700632 struct usbnet *dev = netdev_priv(netdev);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000633 u32 read_buf;
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700634 int ret;
635
636 ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000637 if (ret < 0) {
638 netdev_warn(dev->net, "Failed to read COE_CR: %d\n", ret);
639 return ret;
640 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000641
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700642 if (features & NETIF_F_HW_CSUM)
Steve Glendinningf7b29272008-11-20 04:19:21 -0800643 read_buf |= Tx_COE_EN_;
644 else
645 read_buf &= ~Tx_COE_EN_;
646
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700647 if (features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000648 read_buf |= Rx_COE_EN_;
649 else
650 read_buf &= ~Rx_COE_EN_;
651
652 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000653 if (ret < 0) {
654 netdev_warn(dev->net, "Failed to write COE_CR: %d\n", ret);
655 return ret;
656 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000657
Joe Perchesa475f602010-02-17 10:30:24 +0000658 netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000659 return 0;
660}
661
662static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
663{
664 return MAX_EEPROM_SIZE;
665}
666
667static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
668 struct ethtool_eeprom *ee, u8 *data)
669{
670 struct usbnet *dev = netdev_priv(netdev);
671
672 ee->magic = LAN95XX_EEPROM_MAGIC;
673
674 return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
675}
676
677static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
678 struct ethtool_eeprom *ee, u8 *data)
679{
680 struct usbnet *dev = netdev_priv(netdev);
681
682 if (ee->magic != LAN95XX_EEPROM_MAGIC) {
Joe Perches60b86752010-02-17 10:30:23 +0000683 netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
684 ee->magic);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000685 return -EINVAL;
686 }
687
688 return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
689}
690
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400691static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
692{
693 /* all smsc95xx registers */
694 return COE_CR - ID_REV + 1;
695}
696
697static void
698smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
699 void *buf)
700{
701 struct usbnet *dev = netdev_priv(netdev);
Dan Carpenterd3484462012-07-10 20:32:51 +0000702 unsigned int i, j;
703 int retval;
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400704 u32 *data = buf;
705
706 retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
707 if (retval < 0) {
708 netdev_warn(netdev, "REGS: cannot read ID_REV\n");
709 return;
710 }
711
712 for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
713 retval = smsc95xx_read_reg(dev, i, &data[j]);
714 if (retval < 0) {
715 netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
716 return;
717 }
718 }
719}
720
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000721static void smsc95xx_ethtool_get_wol(struct net_device *net,
722 struct ethtool_wolinfo *wolinfo)
723{
724 struct usbnet *dev = netdev_priv(net);
725 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
726
727 wolinfo->supported = SUPPORTED_WAKE;
728 wolinfo->wolopts = pdata->wolopts;
729}
730
731static int smsc95xx_ethtool_set_wol(struct net_device *net,
732 struct ethtool_wolinfo *wolinfo)
733{
734 struct usbnet *dev = netdev_priv(net);
735 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning3b146922012-11-30 05:55:50 +0000736 int ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000737
738 pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
Steve Glendinning3b146922012-11-30 05:55:50 +0000739
740 ret = device_set_wakeup_enable(&dev->udev->dev, pdata->wolopts);
Steve Glendinningb052e072012-11-30 05:55:52 +0000741 if (ret < 0)
742 netdev_warn(dev->net, "device_set_wakeup_enable error %d\n", ret);
Steve Glendinning3b146922012-11-30 05:55:50 +0000743
Steve Glendinningb052e072012-11-30 05:55:52 +0000744 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000745}
746
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700747static const struct ethtool_ops smsc95xx_ethtool_ops = {
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000748 .get_link = usbnet_get_link,
749 .nway_reset = usbnet_nway_reset,
750 .get_drvinfo = usbnet_get_drvinfo,
751 .get_msglevel = usbnet_get_msglevel,
752 .set_msglevel = usbnet_set_msglevel,
753 .get_settings = usbnet_get_settings,
754 .set_settings = usbnet_set_settings,
755 .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
756 .get_eeprom = smsc95xx_ethtool_get_eeprom,
757 .set_eeprom = smsc95xx_ethtool_set_eeprom,
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400758 .get_regs_len = smsc95xx_ethtool_getregslen,
759 .get_regs = smsc95xx_ethtool_getregs,
Steve Glendinninge0e474a2012-09-28 00:07:12 +0000760 .get_wol = smsc95xx_ethtool_get_wol,
761 .set_wol = smsc95xx_ethtool_set_wol,
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000762};
763
764static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
765{
766 struct usbnet *dev = netdev_priv(netdev);
767
768 if (!netif_running(netdev))
769 return -EINVAL;
770
771 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
772}
773
774static void smsc95xx_init_mac_address(struct usbnet *dev)
775{
776 /* try reading mac address from EEPROM */
777 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
778 dev->net->dev_addr) == 0) {
779 if (is_valid_ether_addr(dev->net->dev_addr)) {
780 /* eeprom values are valid so use them */
Joe Perchesa475f602010-02-17 10:30:24 +0000781 netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000782 return;
783 }
784 }
785
786 /* no eeprom, or eeprom values are invalid. generate random MAC */
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000787 eth_hw_addr_random(dev->net);
Joe Perchesc7e12ea2012-07-12 19:33:07 +0000788 netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000789}
790
791static int smsc95xx_set_mac_address(struct usbnet *dev)
792{
793 u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
794 dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
795 u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
796 int ret;
797
798 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
Steve Glendinningb052e072012-11-30 05:55:52 +0000799 if (ret < 0) {
800 netdev_warn(dev->net, "Failed to write ADDRL: %d\n", ret);
801 return ret;
802 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000803
804 ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
Steve Glendinningb052e072012-11-30 05:55:52 +0000805 if (ret < 0)
806 netdev_warn(dev->net, "Failed to write ADDRH: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000807
Steve Glendinningb052e072012-11-30 05:55:52 +0000808 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000809}
810
811/* starts the TX path */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000812static int smsc95xx_start_tx_path(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000813{
814 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
815 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000816 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000817
818 /* Enable Tx at MAC */
819 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
820 pdata->mac_cr |= MAC_CR_TXEN_;
821 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
822
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000823 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
Steve Glendinningb052e072012-11-30 05:55:52 +0000824 if (ret < 0) {
825 netdev_warn(dev->net, "Failed to write MAC_CR: %d\n", ret);
826 return ret;
827 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000828
829 /* Enable Tx at SCSRs */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000830 ret = smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
Steve Glendinningb052e072012-11-30 05:55:52 +0000831 if (ret < 0)
832 netdev_warn(dev->net, "Failed to write TX_CFG: %d\n", ret);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000833
Steve Glendinningb052e072012-11-30 05:55:52 +0000834 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000835}
836
837/* Starts the Receive path */
Ming Leiec321152012-11-06 04:53:07 +0000838static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000839{
840 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
841 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000842 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000843
844 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
845 pdata->mac_cr |= MAC_CR_RXEN_;
846 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
847
Ming Leiec321152012-11-06 04:53:07 +0000848 ret = __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
Steve Glendinningb052e072012-11-30 05:55:52 +0000849 if (ret < 0)
850 netdev_warn(dev->net, "Failed to write MAC_CR: %d\n", ret);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000851
Steve Glendinningb052e072012-11-30 05:55:52 +0000852 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000853}
854
855static int smsc95xx_phy_initialize(struct usbnet *dev)
856{
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000857 int bmcr, ret, timeout = 0;
Steve Glendinningdb443c42010-03-16 09:03:06 +0000858
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000859 /* Initialize MII structure */
860 dev->mii.dev = dev->net;
861 dev->mii.mdio_read = smsc95xx_mdio_read;
862 dev->mii.mdio_write = smsc95xx_mdio_write;
863 dev->mii.phy_id_mask = 0x1f;
864 dev->mii.reg_num_mask = 0x1f;
865 dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
866
Steve Glendinningdb443c42010-03-16 09:03:06 +0000867 /* reset phy and wait for reset to complete */
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000868 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
Steve Glendinningdb443c42010-03-16 09:03:06 +0000869
870 do {
871 msleep(10);
872 bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
873 timeout++;
Rabin Vincentd9460922011-04-30 08:29:27 +0000874 } while ((bmcr & BMCR_RESET) && (timeout < 100));
Steve Glendinningdb443c42010-03-16 09:03:06 +0000875
876 if (timeout >= 100) {
877 netdev_warn(dev->net, "timeout on PHY Reset");
878 return -EIO;
879 }
880
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000881 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
882 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
883 ADVERTISE_PAUSE_ASYM);
884
885 /* read to clear */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000886 ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
Steve Glendinningb052e072012-11-30 05:55:52 +0000887 if (ret < 0) {
888 netdev_warn(dev->net, "Failed to read PHY_INT_SRC during init\n");
889 return ret;
890 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000891
892 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
893 PHY_INT_MASK_DEFAULT_);
894 mii_nway_restart(&dev->mii);
895
Joe Perchesa475f602010-02-17 10:30:24 +0000896 netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000897 return 0;
898}
899
900static int smsc95xx_reset(struct usbnet *dev)
901{
902 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
903 u32 read_buf, write_buf, burst_cap;
904 int ret = 0, timeout;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000905
Joe Perchesa475f602010-02-17 10:30:24 +0000906 netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000907
Steve Glendinning44367612012-09-28 00:07:08 +0000908 ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
Steve Glendinningb052e072012-11-30 05:55:52 +0000909 if (ret < 0) {
910 netdev_warn(dev->net, "Failed to write HW_CFG_LRST_ bit in HW_CFG\n");
911 return ret;
912 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000913
914 timeout = 0;
915 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000916 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000917 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000918 if (ret < 0) {
919 netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
920 return ret;
921 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000922 timeout++;
923 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
924
925 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000926 netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000927 return ret;
928 }
929
Steve Glendinning44367612012-09-28 00:07:08 +0000930 ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
Steve Glendinningb052e072012-11-30 05:55:52 +0000931 if (ret < 0) {
932 netdev_warn(dev->net, "Failed to write PM_CTRL: %d\n", ret);
933 return ret;
934 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000935
936 timeout = 0;
937 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000938 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000939 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000940 if (ret < 0) {
941 netdev_warn(dev->net, "Failed to read PM_CTRL: %d\n", ret);
942 return ret;
943 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000944 timeout++;
945 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
946
947 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000948 netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000949 return ret;
950 }
951
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000952 ret = smsc95xx_set_mac_address(dev);
953 if (ret < 0)
954 return ret;
955
Joe Perches1e1d7412012-11-24 01:27:49 +0000956 netif_dbg(dev, ifup, dev->net, "MAC Address: %pM\n",
957 dev->net->dev_addr);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000958
959 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000960 if (ret < 0) {
961 netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
962 return ret;
963 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000964
Joe Perches1e1d7412012-11-24 01:27:49 +0000965 netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG : 0x%08x\n",
966 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000967
968 read_buf |= HW_CFG_BIR_;
969
970 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000971 if (ret < 0) {
972 netdev_warn(dev->net, "Failed to write HW_CFG_BIR_ bit in HW_CFG\n");
973 return ret;
974 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000975
976 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +0000977 if (ret < 0) {
978 netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
979 return ret;
980 }
981
Joe Perchesa475f602010-02-17 10:30:24 +0000982 netif_dbg(dev, ifup, dev->net,
983 "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
984 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000985
986 if (!turbo_mode) {
987 burst_cap = 0;
988 dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
989 } else if (dev->udev->speed == USB_SPEED_HIGH) {
990 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
991 dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
992 } else {
993 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
994 dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
995 }
996
Joe Perches1e1d7412012-11-24 01:27:49 +0000997 netif_dbg(dev, ifup, dev->net, "rx_urb_size=%ld\n",
998 (ulong)dev->rx_urb_size);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000999
1000 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
Steve Glendinningb052e072012-11-30 05:55:52 +00001001 if (ret < 0) {
1002 netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret);
1003 return ret;
1004 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001005
1006 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001007 if (ret < 0) {
1008 netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret);
1009 return ret;
1010 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001011
Joe Perchesa475f602010-02-17 10:30:24 +00001012 netif_dbg(dev, ifup, dev->net,
1013 "Read Value from BURST_CAP after writing: 0x%08x\n",
1014 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001015
Steve Glendinning44367612012-09-28 00:07:08 +00001016 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
Steve Glendinningb052e072012-11-30 05:55:52 +00001017 if (ret < 0) {
1018 netdev_warn(dev->net, "Failed to write BULK_IN_DLY: %d\n", ret);
1019 return ret;
1020 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001021
1022 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001023 if (ret < 0) {
1024 netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret);
1025 return ret;
1026 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001027
Joe Perchesa475f602010-02-17 10:30:24 +00001028 netif_dbg(dev, ifup, dev->net,
1029 "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
1030 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001031
1032 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001033 if (ret < 0) {
1034 netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
1035 return ret;
1036 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001037
Joe Perches1e1d7412012-11-24 01:27:49 +00001038 netif_dbg(dev, ifup, dev->net, "Read Value from HW_CFG: 0x%08x\n",
1039 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001040
1041 if (turbo_mode)
1042 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
1043
1044 read_buf &= ~HW_CFG_RXDOFF_;
1045
1046 /* set Rx data offset=2, Make IP header aligns on word boundary. */
1047 read_buf |= NET_IP_ALIGN << 9;
1048
1049 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001050 if (ret < 0) {
1051 netdev_warn(dev->net, "Failed to write HW_CFG: %d\n", ret);
1052 return ret;
1053 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001054
1055 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001056 if (ret < 0) {
1057 netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
1058 return ret;
1059 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001060
Joe Perchesa475f602010-02-17 10:30:24 +00001061 netif_dbg(dev, ifup, dev->net,
1062 "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001063
Steve Glendinning44367612012-09-28 00:07:08 +00001064 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
Steve Glendinningb052e072012-11-30 05:55:52 +00001065 if (ret < 0) {
1066 netdev_warn(dev->net, "Failed to write INT_STS: %d\n", ret);
1067 return ret;
1068 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001069
1070 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001071 if (ret < 0) {
1072 netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
1073 return ret;
1074 }
Joe Perchesa475f602010-02-17 10:30:24 +00001075 netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001076
Steve Glendinningf2935012009-05-01 05:46:51 +00001077 /* Configure GPIO pins as LED outputs */
1078 write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
1079 LED_GPIO_CFG_FDX_LED;
1080 ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001081 if (ret < 0) {
1082 netdev_warn(dev->net, "Failed to write LED_GPIO_CFG: %d\n", ret);
1083 return ret;
1084 }
Steve Glendinningf2935012009-05-01 05:46:51 +00001085
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001086 /* Init Tx */
Steve Glendinning44367612012-09-28 00:07:08 +00001087 ret = smsc95xx_write_reg(dev, FLOW, 0);
Steve Glendinningb052e072012-11-30 05:55:52 +00001088 if (ret < 0) {
1089 netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret);
1090 return ret;
1091 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001092
Steve Glendinning44367612012-09-28 00:07:08 +00001093 ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
Steve Glendinningb052e072012-11-30 05:55:52 +00001094 if (ret < 0) {
1095 netdev_warn(dev->net, "Failed to write AFC_CFG: %d\n", ret);
1096 return ret;
1097 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001098
1099 /* Don't need mac_cr_lock during initialisation */
1100 ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
Steve Glendinningb052e072012-11-30 05:55:52 +00001101 if (ret < 0) {
1102 netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret);
1103 return ret;
1104 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001105
1106 /* Init Rx */
1107 /* Set Vlan */
Steve Glendinning44367612012-09-28 00:07:08 +00001108 ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
Steve Glendinningb052e072012-11-30 05:55:52 +00001109 if (ret < 0) {
1110 netdev_warn(dev->net, "Failed to write VLAN1: %d\n", ret);
1111 return ret;
1112 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001113
Steve Glendinningf7b29272008-11-20 04:19:21 -08001114 /* Enable or disable checksum offload engines */
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001115 ret = smsc95xx_set_features(dev->net, dev->net->features);
Steve Glendinningb052e072012-11-30 05:55:52 +00001116 if (ret < 0) {
1117 netdev_warn(dev->net, "Failed to set checksum offload features\n");
1118 return ret;
1119 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001120
1121 smsc95xx_set_multicast(dev->net);
1122
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001123 ret = smsc95xx_phy_initialize(dev);
Steve Glendinningb052e072012-11-30 05:55:52 +00001124 if (ret < 0) {
1125 netdev_warn(dev->net, "Failed to init PHY\n");
1126 return ret;
1127 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001128
1129 ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001130 if (ret < 0) {
1131 netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret);
1132 return ret;
1133 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001134
1135 /* enable PHY interrupts */
1136 read_buf |= INT_EP_CTL_PHY_INT_;
1137
1138 ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001139 if (ret < 0) {
1140 netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret);
1141 return ret;
1142 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001143
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001144 ret = smsc95xx_start_tx_path(dev);
Steve Glendinningb052e072012-11-30 05:55:52 +00001145 if (ret < 0) {
1146 netdev_warn(dev->net, "Failed to start TX path\n");
1147 return ret;
1148 }
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001149
Ming Leiec321152012-11-06 04:53:07 +00001150 ret = smsc95xx_start_rx_path(dev, 0);
Steve Glendinningb052e072012-11-30 05:55:52 +00001151 if (ret < 0) {
1152 netdev_warn(dev->net, "Failed to start RX path\n");
1153 return ret;
1154 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001155
Joe Perchesa475f602010-02-17 10:30:24 +00001156 netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001157 return 0;
1158}
1159
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001160static const struct net_device_ops smsc95xx_netdev_ops = {
1161 .ndo_open = usbnet_open,
1162 .ndo_stop = usbnet_stop,
1163 .ndo_start_xmit = usbnet_start_xmit,
1164 .ndo_tx_timeout = usbnet_tx_timeout,
1165 .ndo_change_mtu = usbnet_change_mtu,
1166 .ndo_set_mac_address = eth_mac_addr,
1167 .ndo_validate_addr = eth_validate_addr,
1168 .ndo_do_ioctl = smsc95xx_ioctl,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001169 .ndo_set_rx_mode = smsc95xx_set_multicast,
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001170 .ndo_set_features = smsc95xx_set_features,
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001171};
1172
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001173static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
1174{
1175 struct smsc95xx_priv *pdata = NULL;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001176 u32 val;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001177 int ret;
1178
1179 printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
1180
1181 ret = usbnet_get_endpoints(dev, intf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001182 if (ret < 0) {
1183 netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
1184 return ret;
1185 }
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001186
1187 dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
1188 GFP_KERNEL);
1189
1190 pdata = (struct smsc95xx_priv *)(dev->data[0]);
1191 if (!pdata) {
Joe Perches60b86752010-02-17 10:30:23 +00001192 netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001193 return -ENOMEM;
1194 }
1195
1196 spin_lock_init(&pdata->mac_cr_lock);
1197
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001198 if (DEFAULT_TX_CSUM_ENABLE)
1199 dev->net->features |= NETIF_F_HW_CSUM;
1200 if (DEFAULT_RX_CSUM_ENABLE)
1201 dev->net->features |= NETIF_F_RXCSUM;
1202
1203 dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001204
Bernard Blackhamf4e8ab72010-10-18 13:16:39 +00001205 smsc95xx_init_mac_address(dev);
1206
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001207 /* Init all registers */
1208 ret = smsc95xx_reset(dev);
1209
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001210 /* detect device revision as different features may be available */
1211 ret = smsc95xx_read_reg(dev, ID_REV, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001212 if (ret < 0) {
1213 netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
1214 return ret;
1215 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001216 val >>= 16;
Steve Glendinning9ebca502012-11-22 08:05:23 +00001217
1218 if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9530_) ||
1219 (val == ID_REV_CHIP_ID_89530_) || (val == ID_REV_CHIP_ID_9730_))
1220 pdata->features = (FEATURE_8_WAKEUP_FILTERS |
1221 FEATURE_PHY_NLP_CROSSOVER |
1222 FEATURE_AUTOSUSPEND);
1223 else if (val == ID_REV_CHIP_ID_9512_)
1224 pdata->features = FEATURE_8_WAKEUP_FILTERS;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001225
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001226 dev->net->netdev_ops = &smsc95xx_netdev_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001227 dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001228 dev->net->flags |= IFF_MULTICAST;
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001229 dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
Stephane Fillod9bbf5662012-04-20 09:39:23 +00001230 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001231 return 0;
1232}
1233
1234static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
1235{
1236 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1237 if (pdata) {
Joe Perchesa475f602010-02-17 10:30:24 +00001238 netif_dbg(dev, ifdown, dev->net, "free pdata\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001239 kfree(pdata);
1240 pdata = NULL;
1241 dev->data[0] = 0;
1242 }
1243}
1244
Steve Glendinning068bb1a2012-11-30 05:55:51 +00001245static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001246{
Steve Glendinning068bb1a2012-11-30 05:55:51 +00001247 u32 crc = bitrev16(crc16(0xFFFF, buffer, len));
1248 return crc << ((filter % 2) * 16);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001249}
1250
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001251static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)
1252{
1253 struct mii_if_info *mii = &dev->mii;
1254 int ret;
1255
Joe Perches1e1d7412012-11-24 01:27:49 +00001256 netdev_dbg(dev->net, "enabling PHY wakeup interrupts\n");
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001257
1258 /* read to clear */
1259 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_SRC);
Steve Glendinningb052e072012-11-30 05:55:52 +00001260 if (ret < 0) {
1261 netdev_warn(dev->net, "Error reading PHY_INT_SRC\n");
1262 return ret;
1263 }
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001264
1265 /* enable interrupt source */
1266 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_INT_MASK);
Steve Glendinningb052e072012-11-30 05:55:52 +00001267 if (ret < 0) {
1268 netdev_warn(dev->net, "Error reading PHY_INT_MASK\n");
1269 return ret;
1270 }
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001271
1272 ret |= mask;
1273
1274 smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_INT_MASK, ret);
1275
1276 return 0;
1277}
1278
1279static int smsc95xx_link_ok_nopm(struct usbnet *dev)
1280{
1281 struct mii_if_info *mii = &dev->mii;
1282 int ret;
1283
1284 /* first, a dummy read, needed to latch some MII phys */
1285 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
Steve Glendinningb052e072012-11-30 05:55:52 +00001286 if (ret < 0) {
1287 netdev_warn(dev->net, "Error reading MII_BMSR\n");
1288 return ret;
1289 }
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001290
1291 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, MII_BMSR);
Steve Glendinningb052e072012-11-30 05:55:52 +00001292 if (ret < 0) {
1293 netdev_warn(dev->net, "Error reading MII_BMSR\n");
1294 return ret;
1295 }
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001296
1297 return !!(ret & BMSR_LSTATUS);
1298}
1299
Steve Glendinning319b95b2012-11-22 08:05:25 +00001300static int smsc95xx_enter_suspend0(struct usbnet *dev)
1301{
1302 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1303 u32 val;
1304 int ret;
1305
1306 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001307 if (ret < 0) {
1308 netdev_warn(dev->net, "Error reading PM_CTRL\n");
1309 return ret;
1310 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001311
1312 val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
1313 val |= PM_CTL_SUS_MODE_0;
1314
1315 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001316 if (ret < 0) {
1317 netdev_warn(dev->net, "Error writing PM_CTRL\n");
1318 return ret;
1319 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001320
1321 /* clear wol status */
1322 val &= ~PM_CTL_WUPS_;
1323 val |= PM_CTL_WUPS_WOL_;
1324
1325 /* enable energy detection */
1326 if (pdata->wolopts & WAKE_PHY)
1327 val |= PM_CTL_WUPS_ED_;
1328
1329 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001330 if (ret < 0) {
1331 netdev_warn(dev->net, "Error writing PM_CTRL\n");
1332 return ret;
1333 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001334
1335 /* read back PM_CTRL */
1336 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001337 if (ret < 0)
1338 netdev_warn(dev->net, "Error reading PM_CTRL\n");
Steve Glendinning319b95b2012-11-22 08:05:25 +00001339
Steve Glendinningb052e072012-11-30 05:55:52 +00001340 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001341}
1342
1343static int smsc95xx_enter_suspend1(struct usbnet *dev)
1344{
1345 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1346 struct mii_if_info *mii = &dev->mii;
1347 u32 val;
1348 int ret;
1349
1350 /* reconfigure link pulse detection timing for
1351 * compatibility with non-standard link partners
1352 */
1353 if (pdata->features & FEATURE_PHY_NLP_CROSSOVER)
1354 smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_EDPD_CONFIG,
1355 PHY_EDPD_CONFIG_DEFAULT);
1356
1357 /* enable energy detect power-down mode */
1358 ret = smsc95xx_mdio_read_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS);
Steve Glendinningb052e072012-11-30 05:55:52 +00001359 if (ret < 0) {
1360 netdev_warn(dev->net, "Error reading PHY_MODE_CTRL_STS\n");
1361 return ret;
1362 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001363
1364 ret |= MODE_CTRL_STS_EDPWRDOWN_;
1365
1366 smsc95xx_mdio_write_nopm(dev->net, mii->phy_id, PHY_MODE_CTRL_STS, ret);
1367
1368 /* enter SUSPEND1 mode */
1369 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001370 if (ret < 0) {
1371 netdev_warn(dev->net, "Error reading PM_CTRL\n");
1372 return ret;
1373 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001374
1375 val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1376 val |= PM_CTL_SUS_MODE_1;
1377
1378 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001379 if (ret < 0) {
1380 netdev_warn(dev->net, "Error writing PM_CTRL\n");
1381 return ret;
1382 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001383
1384 /* clear wol status, enable energy detection */
1385 val &= ~PM_CTL_WUPS_;
1386 val |= (PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_);
1387
1388 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001389 if (ret < 0)
1390 netdev_warn(dev->net, "Error writing PM_CTRL\n");
Steve Glendinning319b95b2012-11-22 08:05:25 +00001391
Steve Glendinningb052e072012-11-30 05:55:52 +00001392 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001393}
1394
1395static int smsc95xx_enter_suspend2(struct usbnet *dev)
1396{
1397 u32 val;
1398 int ret;
1399
1400 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001401 if (ret < 0) {
1402 netdev_warn(dev->net, "Error reading PM_CTRL\n");
1403 return ret;
1404 }
Steve Glendinning319b95b2012-11-22 08:05:25 +00001405
1406 val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1407 val |= PM_CTL_SUS_MODE_2;
1408
1409 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001410 if (ret < 0)
1411 netdev_warn(dev->net, "Error writing PM_CTRL\n");
Steve Glendinning319b95b2012-11-22 08:05:25 +00001412
Steve Glendinningb052e072012-11-30 05:55:52 +00001413 return ret;
Steve Glendinning319b95b2012-11-22 08:05:25 +00001414}
1415
Steve Glendinningb5a04472012-09-28 00:07:11 +00001416static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1417{
1418 struct usbnet *dev = usb_get_intfdata(intf);
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001419 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001420 u32 val, link_up;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001421 int ret;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001422
Steve Glendinningb5a04472012-09-28 00:07:11 +00001423 ret = usbnet_suspend(intf, message);
Steve Glendinningb052e072012-11-30 05:55:52 +00001424 if (ret < 0) {
1425 netdev_warn(dev->net, "usbnet_suspend error\n");
1426 return ret;
1427 }
Steve Glendinningb5a04472012-09-28 00:07:11 +00001428
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001429 /* determine if link is up using only _nopm functions */
1430 link_up = smsc95xx_link_ok_nopm(dev);
1431
1432 /* if no wol options set, or if link is down and we're not waking on
1433 * PHY activity, enter lowest power SUSPEND2 mode
1434 */
1435 if (!(pdata->wolopts & SUPPORTED_WAKE) ||
1436 !(link_up || (pdata->wolopts & WAKE_PHY))) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001437 netdev_info(dev->net, "entering SUSPEND2 mode\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001438
1439 /* disable energy detect (link up) & wake up events */
Ming Leiec321152012-11-06 04:53:07 +00001440 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001441 if (ret < 0) {
1442 netdev_warn(dev->net, "Error reading WUCSR\n");
1443 goto done;
1444 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001445
1446 val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
1447
Ming Leiec321152012-11-06 04:53:07 +00001448 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001449 if (ret < 0) {
1450 netdev_warn(dev->net, "Error writing WUCSR\n");
1451 goto done;
1452 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001453
Ming Leiec321152012-11-06 04:53:07 +00001454 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001455 if (ret < 0) {
1456 netdev_warn(dev->net, "Error reading PM_CTRL\n");
1457 goto done;
1458 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001459
1460 val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
1461
Ming Leiec321152012-11-06 04:53:07 +00001462 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001463 if (ret < 0) {
1464 netdev_warn(dev->net, "Error writing PM_CTRL\n");
1465 goto done;
1466 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001467
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001468 ret = smsc95xx_enter_suspend2(dev);
1469 goto done;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001470 }
1471
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001472 if (pdata->wolopts & WAKE_PHY) {
1473 ret = smsc95xx_enable_phy_wakeup_interrupts(dev,
1474 (PHY_INT_MASK_ANEG_COMP_ | PHY_INT_MASK_LINK_DOWN_));
Steve Glendinningb052e072012-11-30 05:55:52 +00001475 if (ret < 0) {
1476 netdev_warn(dev->net, "error enabling PHY wakeup ints\n");
1477 goto done;
1478 }
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001479
1480 /* if link is down then configure EDPD and enter SUSPEND1,
1481 * otherwise enter SUSPEND0 below
1482 */
1483 if (!link_up) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001484 netdev_info(dev->net, "entering SUSPEND1 mode\n");
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001485 ret = smsc95xx_enter_suspend1(dev);
1486 goto done;
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001487 }
1488 }
1489
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001490 if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
Steve Glendinningeed9a722012-11-30 05:55:48 +00001491 u32 *filter_mask = kzalloc(sizeof(u32) * 32, GFP_KERNEL);
Ming Lei06a221b2012-11-06 04:53:06 +00001492 u32 command[2];
1493 u32 offset[2];
1494 u32 crc[4];
Steve Glendinning9ebca502012-11-22 08:05:23 +00001495 int wuff_filter_count =
1496 (pdata->features & FEATURE_8_WAKEUP_FILTERS) ?
1497 LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001498 int i, filter = 0;
1499
Steve Glendinningeed9a722012-11-30 05:55:48 +00001500 if (!filter_mask) {
1501 netdev_warn(dev->net, "Unable to allocate filter_mask\n");
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001502 ret = -ENOMEM;
1503 goto done;
Steve Glendinningeed9a722012-11-30 05:55:48 +00001504 }
1505
Ming Lei06a221b2012-11-06 04:53:06 +00001506 memset(command, 0, sizeof(command));
1507 memset(offset, 0, sizeof(offset));
1508 memset(crc, 0, sizeof(crc));
1509
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001510 if (pdata->wolopts & WAKE_BCAST) {
1511 const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Joe Perches1e1d7412012-11-24 01:27:49 +00001512 netdev_info(dev->net, "enabling broadcast detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001513 filter_mask[filter * 4] = 0x003F;
1514 filter_mask[filter * 4 + 1] = 0x00;
1515 filter_mask[filter * 4 + 2] = 0x00;
1516 filter_mask[filter * 4 + 3] = 0x00;
1517 command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1518 offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1519 crc[filter/2] |= smsc_crc(bcast, 6, filter);
1520 filter++;
1521 }
1522
1523 if (pdata->wolopts & WAKE_MCAST) {
1524 const u8 mcast[] = {0x01, 0x00, 0x5E};
Joe Perches1e1d7412012-11-24 01:27:49 +00001525 netdev_info(dev->net, "enabling multicast detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001526 filter_mask[filter * 4] = 0x0007;
1527 filter_mask[filter * 4 + 1] = 0x00;
1528 filter_mask[filter * 4 + 2] = 0x00;
1529 filter_mask[filter * 4 + 3] = 0x00;
1530 command[filter/4] |= 0x09UL << ((filter % 4) * 8);
1531 offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1532 crc[filter/2] |= smsc_crc(mcast, 3, filter);
1533 filter++;
1534 }
1535
1536 if (pdata->wolopts & WAKE_ARP) {
1537 const u8 arp[] = {0x08, 0x06};
Joe Perches1e1d7412012-11-24 01:27:49 +00001538 netdev_info(dev->net, "enabling ARP detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001539 filter_mask[filter * 4] = 0x0003;
1540 filter_mask[filter * 4 + 1] = 0x00;
1541 filter_mask[filter * 4 + 2] = 0x00;
1542 filter_mask[filter * 4 + 3] = 0x00;
1543 command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1544 offset[filter/4] |= 0x0C << ((filter % 4) * 8);
1545 crc[filter/2] |= smsc_crc(arp, 2, filter);
1546 filter++;
1547 }
1548
1549 if (pdata->wolopts & WAKE_UCAST) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001550 netdev_info(dev->net, "enabling unicast detection\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001551 filter_mask[filter * 4] = 0x003F;
1552 filter_mask[filter * 4 + 1] = 0x00;
1553 filter_mask[filter * 4 + 2] = 0x00;
1554 filter_mask[filter * 4 + 3] = 0x00;
1555 command[filter/4] |= 0x01UL << ((filter % 4) * 8);
1556 offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1557 crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter);
1558 filter++;
1559 }
1560
Steve Glendinning9ebca502012-11-22 08:05:23 +00001561 for (i = 0; i < (wuff_filter_count * 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001562 ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
Steve Glendinningb052e072012-11-30 05:55:52 +00001563 if (ret < 0) {
1564 netdev_warn(dev->net, "Error writing WUFF\n");
Ming Lei06a221b2012-11-06 04:53:06 +00001565 kfree(filter_mask);
Steve Glendinningb052e072012-11-30 05:55:52 +00001566 goto done;
1567 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001568 }
Ming Lei06a221b2012-11-06 04:53:06 +00001569 kfree(filter_mask);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001570
Steve Glendinning9ebca502012-11-22 08:05:23 +00001571 for (i = 0; i < (wuff_filter_count / 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001572 ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
Steve Glendinningb052e072012-11-30 05:55:52 +00001573 if (ret < 0) {
1574 netdev_warn(dev->net, "Error writing WUFF\n");
1575 goto done;
1576 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001577 }
1578
Steve Glendinning9ebca502012-11-22 08:05:23 +00001579 for (i = 0; i < (wuff_filter_count / 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001580 ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
Steve Glendinningb052e072012-11-30 05:55:52 +00001581 if (ret < 0) {
1582 netdev_warn(dev->net, "Error writing WUFF\n");
1583 goto done;
1584 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001585 }
1586
Steve Glendinning9ebca502012-11-22 08:05:23 +00001587 for (i = 0; i < (wuff_filter_count / 2); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001588 ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
Steve Glendinningb052e072012-11-30 05:55:52 +00001589 if (ret < 0) {
1590 netdev_warn(dev->net, "Error writing WUFF\n");
1591 goto done;
1592 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001593 }
1594
1595 /* clear any pending pattern match packet status */
Ming Leiec321152012-11-06 04:53:07 +00001596 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001597 if (ret < 0) {
1598 netdev_warn(dev->net, "Error reading WUCSR\n");
1599 goto done;
1600 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001601
1602 val |= WUCSR_WUFR_;
1603
Ming Leiec321152012-11-06 04:53:07 +00001604 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001605 if (ret < 0) {
1606 netdev_warn(dev->net, "Error writing WUCSR\n");
1607 goto done;
1608 }
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001609 }
1610
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001611 if (pdata->wolopts & WAKE_MAGIC) {
1612 /* clear any pending magic packet status */
Ming Leiec321152012-11-06 04:53:07 +00001613 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001614 if (ret < 0) {
1615 netdev_warn(dev->net, "Error reading WUCSR\n");
1616 goto done;
1617 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001618
1619 val |= WUCSR_MPR_;
1620
Ming Leiec321152012-11-06 04:53:07 +00001621 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001622 if (ret < 0) {
1623 netdev_warn(dev->net, "Error writing WUCSR\n");
1624 goto done;
1625 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001626 }
1627
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001628 /* enable/disable wakeup sources */
Ming Leiec321152012-11-06 04:53:07 +00001629 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001630 if (ret < 0) {
1631 netdev_warn(dev->net, "Error reading WUCSR\n");
1632 goto done;
1633 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001634
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001635 if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001636 netdev_info(dev->net, "enabling pattern match wakeup\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001637 val |= WUCSR_WAKE_EN_;
1638 } else {
Joe Perches1e1d7412012-11-24 01:27:49 +00001639 netdev_info(dev->net, "disabling pattern match wakeup\n");
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001640 val &= ~WUCSR_WAKE_EN_;
1641 }
1642
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001643 if (pdata->wolopts & WAKE_MAGIC) {
Joe Perches1e1d7412012-11-24 01:27:49 +00001644 netdev_info(dev->net, "enabling magic packet wakeup\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001645 val |= WUCSR_MPEN_;
1646 } else {
Joe Perches1e1d7412012-11-24 01:27:49 +00001647 netdev_info(dev->net, "disabling magic packet wakeup\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001648 val &= ~WUCSR_MPEN_;
1649 }
1650
Ming Leiec321152012-11-06 04:53:07 +00001651 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001652 if (ret < 0) {
1653 netdev_warn(dev->net, "Error writing WUCSR\n");
1654 goto done;
1655 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001656
1657 /* enable wol wakeup source */
Ming Leiec321152012-11-06 04:53:07 +00001658 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001659 if (ret < 0) {
1660 netdev_warn(dev->net, "Error reading PM_CTRL\n");
1661 goto done;
1662 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001663
1664 val |= PM_CTL_WOL_EN_;
1665
Steve Glendinninge5e3af82012-11-22 08:05:24 +00001666 /* phy energy detect wakeup source */
1667 if (pdata->wolopts & WAKE_PHY)
1668 val |= PM_CTL_ED_EN_;
1669
Ming Leiec321152012-11-06 04:53:07 +00001670 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001671 if (ret < 0) {
1672 netdev_warn(dev->net, "Error writing PM_CTRL\n");
1673 goto done;
1674 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001675
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001676 /* enable receiver to enable frame reception */
Ming Leiec321152012-11-06 04:53:07 +00001677 smsc95xx_start_rx_path(dev, 1);
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001678
1679 /* some wol options are enabled, so enter SUSPEND0 */
Joe Perches1e1d7412012-11-24 01:27:49 +00001680 netdev_info(dev->net, "entering SUSPEND0 mode\n");
Steve Glendinning3b9f7d82012-11-30 05:55:49 +00001681 ret = smsc95xx_enter_suspend0(dev);
1682
1683done:
1684 if (ret)
1685 usbnet_resume(intf);
1686 return ret;
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001687}
1688
1689static int smsc95xx_resume(struct usb_interface *intf)
1690{
1691 struct usbnet *dev = usb_get_intfdata(intf);
1692 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1693 int ret;
1694 u32 val;
1695
1696 BUG_ON(!dev);
1697
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001698 if (pdata->wolopts) {
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001699 /* clear wake-up sources */
Ming Leiec321152012-11-06 04:53:07 +00001700 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001701 if (ret < 0) {
1702 netdev_warn(dev->net, "Error reading WUCSR\n");
1703 return ret;
1704 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001705
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001706 val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001707
Ming Leiec321152012-11-06 04:53:07 +00001708 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001709 if (ret < 0) {
1710 netdev_warn(dev->net, "Error writing WUCSR\n");
1711 return ret;
1712 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001713
1714 /* clear wake-up status */
Ming Leiec321152012-11-06 04:53:07 +00001715 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001716 if (ret < 0) {
1717 netdev_warn(dev->net, "Error reading PM_CTRL\n");
1718 return ret;
1719 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001720
1721 val &= ~PM_CTL_WOL_EN_;
1722 val |= PM_CTL_WUPS_;
1723
Ming Leiec321152012-11-06 04:53:07 +00001724 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb052e072012-11-30 05:55:52 +00001725 if (ret < 0) {
1726 netdev_warn(dev->net, "Error writing PM_CTRL\n");
1727 return ret;
1728 }
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001729 }
1730
Steve Glendinningaf3d7c12012-11-22 08:05:22 +00001731 ret = usbnet_resume(intf);
Steve Glendinningb052e072012-11-30 05:55:52 +00001732 if (ret < 0)
1733 netdev_warn(dev->net, "usbnet_resume error\n");
Steve Glendinninge0e474a2012-09-28 00:07:12 +00001734
Steve Glendinningb052e072012-11-30 05:55:52 +00001735 return ret;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001736}
1737
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001738static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
1739{
1740 skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
1741 skb->ip_summed = CHECKSUM_COMPLETE;
1742 skb_trim(skb, skb->len - 2);
1743}
1744
1745static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1746{
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001747 while (skb->len > 0) {
1748 u32 header, align_count;
1749 struct sk_buff *ax_skb;
1750 unsigned char *packet;
1751 u16 size;
1752
1753 memcpy(&header, skb->data, sizeof(header));
1754 le32_to_cpus(&header);
1755 skb_pull(skb, 4 + NET_IP_ALIGN);
1756 packet = skb->data;
1757
1758 /* get the packet length */
1759 size = (u16)((header & RX_STS_FL_) >> 16);
1760 align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
1761
1762 if (unlikely(header & RX_STS_ES_)) {
Joe Perchesa475f602010-02-17 10:30:24 +00001763 netif_dbg(dev, rx_err, dev->net,
1764 "Error header=0x%08x\n", header);
Herbert Xu80667ac2009-06-29 16:53:00 +00001765 dev->net->stats.rx_errors++;
1766 dev->net->stats.rx_dropped++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001767
1768 if (header & RX_STS_CRC_) {
Herbert Xu80667ac2009-06-29 16:53:00 +00001769 dev->net->stats.rx_crc_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001770 } else {
1771 if (header & (RX_STS_TL_ | RX_STS_RF_))
Herbert Xu80667ac2009-06-29 16:53:00 +00001772 dev->net->stats.rx_frame_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001773
1774 if ((header & RX_STS_LE_) &&
1775 (!(header & RX_STS_FT_)))
Herbert Xu80667ac2009-06-29 16:53:00 +00001776 dev->net->stats.rx_length_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001777 }
1778 } else {
1779 /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
1780 if (unlikely(size > (ETH_FRAME_LEN + 12))) {
Joe Perchesa475f602010-02-17 10:30:24 +00001781 netif_dbg(dev, rx_err, dev->net,
1782 "size err header=0x%08x\n", header);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001783 return 0;
1784 }
1785
1786 /* last frame in this batch */
1787 if (skb->len == size) {
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001788 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001789 smsc95xx_rx_csum_offload(skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001790 skb_trim(skb, skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001791 skb->truesize = size + sizeof(struct sk_buff);
1792
1793 return 1;
1794 }
1795
1796 ax_skb = skb_clone(skb, GFP_ATOMIC);
1797 if (unlikely(!ax_skb)) {
Joe Perches60b86752010-02-17 10:30:23 +00001798 netdev_warn(dev->net, "Error allocating skb\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001799 return 0;
1800 }
1801
1802 ax_skb->len = size;
1803 ax_skb->data = packet;
1804 skb_set_tail_pointer(ax_skb, size);
1805
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001806 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001807 smsc95xx_rx_csum_offload(ax_skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001808 skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001809 ax_skb->truesize = size + sizeof(struct sk_buff);
1810
1811 usbnet_skb_return(dev, ax_skb);
1812 }
1813
1814 skb_pull(skb, size);
1815
1816 /* padding bytes before the next frame starts */
1817 if (skb->len)
1818 skb_pull(skb, align_count);
1819 }
1820
1821 if (unlikely(skb->len < 0)) {
Joe Perches60b86752010-02-17 10:30:23 +00001822 netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001823 return 0;
1824 }
1825
1826 return 1;
1827}
1828
Steve Glendinningf7b29272008-11-20 04:19:21 -08001829static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
1830{
Michał Mirosław55508d62010-12-14 15:24:08 +00001831 u16 low_16 = (u16)skb_checksum_start_offset(skb);
1832 u16 high_16 = low_16 + skb->csum_offset;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001833 return (high_16 << 16) | low_16;
1834}
1835
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001836static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
1837 struct sk_buff *skb, gfp_t flags)
1838{
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001839 bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001840 int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001841 u32 tx_cmd_a, tx_cmd_b;
1842
Steve Glendinningf7b29272008-11-20 04:19:21 -08001843 /* We do not advertise SG, so skbs should be already linearized */
1844 BUG_ON(skb_shinfo(skb)->nr_frags);
1845
1846 if (skb_headroom(skb) < overhead) {
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001847 struct sk_buff *skb2 = skb_copy_expand(skb,
Steve Glendinningf7b29272008-11-20 04:19:21 -08001848 overhead, 0, flags);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001849 dev_kfree_skb_any(skb);
1850 skb = skb2;
1851 if (!skb)
1852 return NULL;
1853 }
1854
Steve Glendinningf7b29272008-11-20 04:19:21 -08001855 if (csum) {
Steve Glendinning11bc3082010-03-18 22:18:41 -07001856 if (skb->len <= 45) {
1857 /* workaround - hardware tx checksum does not work
1858 * properly with extremely small packets */
Michał Mirosław55508d62010-12-14 15:24:08 +00001859 long csstart = skb_checksum_start_offset(skb);
Steve Glendinning11bc3082010-03-18 22:18:41 -07001860 __wsum calc = csum_partial(skb->data + csstart,
1861 skb->len - csstart, 0);
1862 *((__sum16 *)(skb->data + csstart
1863 + skb->csum_offset)) = csum_fold(calc);
1864
1865 csum = false;
1866 } else {
1867 u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
1868 skb_push(skb, 4);
Steve Glendinning00acda62012-11-02 00:44:20 +00001869 cpu_to_le32s(&csum_preamble);
Steve Glendinning11bc3082010-03-18 22:18:41 -07001870 memcpy(skb->data, &csum_preamble, 4);
1871 }
Steve Glendinningf7b29272008-11-20 04:19:21 -08001872 }
1873
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001874 skb_push(skb, 4);
1875 tx_cmd_b = (u32)(skb->len - 4);
Steve Glendinningf7b29272008-11-20 04:19:21 -08001876 if (csum)
1877 tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001878 cpu_to_le32s(&tx_cmd_b);
1879 memcpy(skb->data, &tx_cmd_b, 4);
1880
1881 skb_push(skb, 4);
1882 tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
1883 TX_CMD_A_LAST_SEG_;
1884 cpu_to_le32s(&tx_cmd_a);
1885 memcpy(skb->data, &tx_cmd_a, 4);
1886
1887 return skb;
1888}
1889
1890static const struct driver_info smsc95xx_info = {
1891 .description = "smsc95xx USB 2.0 Ethernet",
1892 .bind = smsc95xx_bind,
1893 .unbind = smsc95xx_unbind,
1894 .link_reset = smsc95xx_link_reset,
1895 .reset = smsc95xx_reset,
1896 .rx_fixup = smsc95xx_rx_fixup,
1897 .tx_fixup = smsc95xx_tx_fixup,
1898 .status = smsc95xx_status,
Paolo Pisati07d69d42012-04-23 04:05:20 +00001899 .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001900};
1901
1902static const struct usb_device_id products[] = {
1903 {
1904 /* SMSC9500 USB Ethernet Device */
1905 USB_DEVICE(0x0424, 0x9500),
1906 .driver_info = (unsigned long) &smsc95xx_info,
1907 },
Steve Glendinning726474b2009-05-01 06:07:22 +00001908 {
Steve Glendinning6f41d122009-09-22 05:13:02 +00001909 /* SMSC9505 USB Ethernet Device */
1910 USB_DEVICE(0x0424, 0x9505),
1911 .driver_info = (unsigned long) &smsc95xx_info,
1912 },
1913 {
1914 /* SMSC9500A USB Ethernet Device */
1915 USB_DEVICE(0x0424, 0x9E00),
1916 .driver_info = (unsigned long) &smsc95xx_info,
1917 },
1918 {
1919 /* SMSC9505A USB Ethernet Device */
1920 USB_DEVICE(0x0424, 0x9E01),
1921 .driver_info = (unsigned long) &smsc95xx_info,
1922 },
1923 {
Steve Glendinning726474b2009-05-01 06:07:22 +00001924 /* SMSC9512/9514 USB Hub & Ethernet Device */
1925 USB_DEVICE(0x0424, 0xec00),
1926 .driver_info = (unsigned long) &smsc95xx_info,
1927 },
Steve Glendinning6f41d122009-09-22 05:13:02 +00001928 {
1929 /* SMSC9500 USB Ethernet Device (SAL10) */
1930 USB_DEVICE(0x0424, 0x9900),
1931 .driver_info = (unsigned long) &smsc95xx_info,
1932 },
1933 {
1934 /* SMSC9505 USB Ethernet Device (SAL10) */
1935 USB_DEVICE(0x0424, 0x9901),
1936 .driver_info = (unsigned long) &smsc95xx_info,
1937 },
1938 {
1939 /* SMSC9500A USB Ethernet Device (SAL10) */
1940 USB_DEVICE(0x0424, 0x9902),
1941 .driver_info = (unsigned long) &smsc95xx_info,
1942 },
1943 {
1944 /* SMSC9505A USB Ethernet Device (SAL10) */
1945 USB_DEVICE(0x0424, 0x9903),
1946 .driver_info = (unsigned long) &smsc95xx_info,
1947 },
1948 {
1949 /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
1950 USB_DEVICE(0x0424, 0x9904),
1951 .driver_info = (unsigned long) &smsc95xx_info,
1952 },
1953 {
1954 /* SMSC9500A USB Ethernet Device (HAL) */
1955 USB_DEVICE(0x0424, 0x9905),
1956 .driver_info = (unsigned long) &smsc95xx_info,
1957 },
1958 {
1959 /* SMSC9505A USB Ethernet Device (HAL) */
1960 USB_DEVICE(0x0424, 0x9906),
1961 .driver_info = (unsigned long) &smsc95xx_info,
1962 },
1963 {
1964 /* SMSC9500 USB Ethernet Device (Alternate ID) */
1965 USB_DEVICE(0x0424, 0x9907),
1966 .driver_info = (unsigned long) &smsc95xx_info,
1967 },
1968 {
1969 /* SMSC9500A USB Ethernet Device (Alternate ID) */
1970 USB_DEVICE(0x0424, 0x9908),
1971 .driver_info = (unsigned long) &smsc95xx_info,
1972 },
1973 {
1974 /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
1975 USB_DEVICE(0x0424, 0x9909),
1976 .driver_info = (unsigned long) &smsc95xx_info,
1977 },
Steve Glendinning88edaa42011-04-10 18:59:27 -07001978 {
1979 /* SMSC LAN9530 USB Ethernet Device */
1980 USB_DEVICE(0x0424, 0x9530),
1981 .driver_info = (unsigned long) &smsc95xx_info,
1982 },
1983 {
1984 /* SMSC LAN9730 USB Ethernet Device */
1985 USB_DEVICE(0x0424, 0x9730),
1986 .driver_info = (unsigned long) &smsc95xx_info,
1987 },
1988 {
1989 /* SMSC LAN89530 USB Ethernet Device */
1990 USB_DEVICE(0x0424, 0x9E08),
1991 .driver_info = (unsigned long) &smsc95xx_info,
1992 },
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001993 { }, /* END */
1994};
1995MODULE_DEVICE_TABLE(usb, products);
1996
1997static struct usb_driver smsc95xx_driver = {
1998 .name = "smsc95xx",
1999 .id_table = products,
2000 .probe = usbnet_probe,
Steve Glendinningb5a04472012-09-28 00:07:11 +00002001 .suspend = smsc95xx_suspend,
Steve Glendinninge0e474a2012-09-28 00:07:12 +00002002 .resume = smsc95xx_resume,
2003 .reset_resume = smsc95xx_resume,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002004 .disconnect = usbnet_disconnect,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -07002005 .disable_hub_initiated_lpm = 1,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002006};
2007
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08002008module_usb_driver(smsc95xx_driver);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002009
2010MODULE_AUTHOR("Nancy Lin");
Steve Glendinning90b24cf2012-04-16 12:13:29 +01002011MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00002012MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
2013MODULE_LICENSE("GPL");