blob: 690022afaf9b7a87b853c7092a5a3371da9c0c16 [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 Glendinningbbd9f9e2012-10-26 03:43:56 +000051#define SUPPORTED_WAKE (WAKE_UCAST | WAKE_BCAST | \
52 WAKE_MCAST | WAKE_ARP | WAKE_MAGIC)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000053
Steve Glendinning769ea6d2012-09-28 00:07:09 +000054#define check_warn(ret, fmt, args...) \
55 ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); })
56
57#define check_warn_return(ret, fmt, args...) \
58 ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } })
59
60#define check_warn_goto_done(ret, fmt, args...) \
61 ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } })
62
Steve Glendinning2f7ca802008-10-02 05:27:57 +000063struct smsc95xx_priv {
64 u32 mac_cr;
Marc Zyngier3c0f3c62011-03-18 03:53:58 +000065 u32 hash_hi;
66 u32 hash_lo;
Steve Glendinninge0e474a82012-09-28 00:07:12 +000067 u32 wolopts;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000068 spinlock_t mac_cr_lock;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +000069 int wuff_filter_count;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000070};
71
Rusty Russelleb939922011-12-19 14:08:01 +000072static bool turbo_mode = true;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000073module_param(turbo_mode, bool, 0644);
74MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
75
Ming Leiec321152012-11-06 04:53:07 +000076static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
77 u32 *data, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000078{
Ming Lei72108fd2012-10-24 19:47:04 +000079 u32 buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000080 int ret;
Ming Leiec321152012-11-06 04:53:07 +000081 int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000082
83 BUG_ON(!dev);
84
Ming Leiec321152012-11-06 04:53:07 +000085 if (!in_pm)
86 fn = usbnet_read_cmd;
87 else
88 fn = usbnet_read_cmd_nopm;
89
90 ret = fn(dev, USB_VENDOR_REQUEST_READ_REGISTER, USB_DIR_IN
91 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
92 0, index, &buf, 4);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000093 if (unlikely(ret < 0))
Ming Leiec321152012-11-06 04:53:07 +000094 netdev_warn(dev->net,
95 "Failed to read reg index 0x%08x: %d", index, ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000096
Ming Lei72108fd2012-10-24 19:47:04 +000097 le32_to_cpus(&buf);
98 *data = buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000099
100 return ret;
101}
102
Ming Leiec321152012-11-06 04:53:07 +0000103static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,
104 u32 data, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000105{
Ming Lei72108fd2012-10-24 19:47:04 +0000106 u32 buf;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000107 int ret;
Ming Leiec321152012-11-06 04:53:07 +0000108 int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000109
110 BUG_ON(!dev);
111
Ming Leiec321152012-11-06 04:53:07 +0000112 if (!in_pm)
113 fn = usbnet_write_cmd;
114 else
115 fn = usbnet_write_cmd_nopm;
116
Ming Lei72108fd2012-10-24 19:47:04 +0000117 buf = data;
118 cpu_to_le32s(&buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000119
Ming Leiec321152012-11-06 04:53:07 +0000120 ret = fn(dev, USB_VENDOR_REQUEST_WRITE_REGISTER, USB_DIR_OUT
121 | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
122 0, index, &buf, 4);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000123 if (unlikely(ret < 0))
Ming Leiec321152012-11-06 04:53:07 +0000124 netdev_warn(dev->net,
125 "Failed to write reg index 0x%08x: %d", index, ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000126
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000127 return ret;
128}
129
Ming Leiec321152012-11-06 04:53:07 +0000130static int __must_check smsc95xx_read_reg_nopm(struct usbnet *dev, u32 index,
131 u32 *data)
132{
133 return __smsc95xx_read_reg(dev, index, data, 1);
134}
135
136static int __must_check smsc95xx_write_reg_nopm(struct usbnet *dev, u32 index,
137 u32 data)
138{
139 return __smsc95xx_write_reg(dev, index, data, 1);
140}
141
142static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
143 u32 *data)
144{
145 return __smsc95xx_read_reg(dev, index, data, 0);
146}
147
148static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
149 u32 data)
150{
151 return __smsc95xx_write_reg(dev, index, data, 0);
152}
Steve Glendinninge0e474a82012-09-28 00:07:12 +0000153static int smsc95xx_set_feature(struct usbnet *dev, u32 feature)
154{
155 if (WARN_ON_ONCE(!dev))
156 return -EINVAL;
157
Ming Leiec321152012-11-06 04:53:07 +0000158 return usbnet_write_cmd_nopm(dev, USB_REQ_SET_FEATURE,
159 USB_RECIP_DEVICE, feature, 0,
160 NULL, 0);
Steve Glendinninge0e474a82012-09-28 00:07:12 +0000161}
162
163static int smsc95xx_clear_feature(struct usbnet *dev, u32 feature)
164{
165 if (WARN_ON_ONCE(!dev))
166 return -EINVAL;
167
Ming Leiec321152012-11-06 04:53:07 +0000168 return usbnet_write_cmd_nopm(dev, USB_REQ_CLEAR_FEATURE,
169 USB_RECIP_DEVICE, feature,
170 0, NULL, 0);
Steve Glendinninge0e474a82012-09-28 00:07:12 +0000171}
172
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000173/* Loop until the read is completed with timeout
174 * called with phy_mutex held */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000175static int __must_check smsc95xx_phy_wait_not_busy(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000176{
177 unsigned long start_time = jiffies;
178 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000179 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000180
181 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000182 ret = smsc95xx_read_reg(dev, MII_ADDR, &val);
183 check_warn_return(ret, "Error reading MII_ACCESS");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000184 if (!(val & MII_BUSY_))
185 return 0;
186 } while (!time_after(jiffies, start_time + HZ));
187
188 return -EIO;
189}
190
191static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
192{
193 struct usbnet *dev = netdev_priv(netdev);
194 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000195 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000196
197 mutex_lock(&dev->phy_mutex);
198
199 /* confirm MII not busy */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000200 ret = smsc95xx_phy_wait_not_busy(dev);
201 check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_read");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000202
203 /* set the address, index & direction (read from PHY) */
204 phy_id &= dev->mii.phy_id_mask;
205 idx &= dev->mii.reg_num_mask;
206 addr = (phy_id << 11) | (idx << 6) | MII_READ_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000207 ret = smsc95xx_write_reg(dev, MII_ADDR, addr);
208 check_warn_goto_done(ret, "Error writing MII_ADDR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000209
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000210 ret = smsc95xx_phy_wait_not_busy(dev);
211 check_warn_goto_done(ret, "Timed out reading MII reg %02X", idx);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000212
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000213 ret = smsc95xx_read_reg(dev, MII_DATA, &val);
214 check_warn_goto_done(ret, "Error reading MII_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000215
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000216 ret = (u16)(val & 0xFFFF);
217
218done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000219 mutex_unlock(&dev->phy_mutex);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000220 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000221}
222
223static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
224 int regval)
225{
226 struct usbnet *dev = netdev_priv(netdev);
227 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000228 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000229
230 mutex_lock(&dev->phy_mutex);
231
232 /* confirm MII not busy */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000233 ret = smsc95xx_phy_wait_not_busy(dev);
234 check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_write");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000235
236 val = regval;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000237 ret = smsc95xx_write_reg(dev, MII_DATA, val);
238 check_warn_goto_done(ret, "Error writing MII_DATA");
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;
243 addr = (phy_id << 11) | (idx << 6) | MII_WRITE_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000244 ret = smsc95xx_write_reg(dev, MII_ADDR, addr);
245 check_warn_goto_done(ret, "Error writing MII_ADDR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000246
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000247 ret = smsc95xx_phy_wait_not_busy(dev);
248 check_warn_goto_done(ret, "Timed out writing MII reg %02X", idx);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000249
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000250done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000251 mutex_unlock(&dev->phy_mutex);
252}
253
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000254static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000255{
256 unsigned long start_time = jiffies;
257 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000258 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000259
260 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000261 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
262 check_warn_return(ret, "Error reading E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000263 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
264 break;
265 udelay(40);
266 } while (!time_after(jiffies, start_time + HZ));
267
268 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
Joe Perches60b86752010-02-17 10:30:23 +0000269 netdev_warn(dev->net, "EEPROM read operation timeout\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000270 return -EIO;
271 }
272
273 return 0;
274}
275
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000276static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000277{
278 unsigned long start_time = jiffies;
279 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000280 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000281
282 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000283 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
284 check_warn_return(ret, "Error reading E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000285
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000286 if (!(val & E2P_CMD_BUSY_))
287 return 0;
288
289 udelay(40);
290 } while (!time_after(jiffies, start_time + HZ));
291
Joe Perches60b86752010-02-17 10:30:23 +0000292 netdev_warn(dev->net, "EEPROM is busy\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000293 return -EIO;
294}
295
296static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
297 u8 *data)
298{
299 u32 val;
300 int i, ret;
301
302 BUG_ON(!dev);
303 BUG_ON(!data);
304
305 ret = smsc95xx_eeprom_confirm_not_busy(dev);
306 if (ret)
307 return ret;
308
309 for (i = 0; i < length; i++) {
310 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000311 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
312 check_warn_return(ret, "Error writing E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000313
314 ret = smsc95xx_wait_eeprom(dev);
315 if (ret < 0)
316 return ret;
317
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000318 ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
319 check_warn_return(ret, "Error reading E2P_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000320
321 data[i] = val & 0xFF;
322 offset++;
323 }
324
325 return 0;
326}
327
328static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
329 u8 *data)
330{
331 u32 val;
332 int i, ret;
333
334 BUG_ON(!dev);
335 BUG_ON(!data);
336
337 ret = smsc95xx_eeprom_confirm_not_busy(dev);
338 if (ret)
339 return ret;
340
341 /* Issue write/erase enable command */
342 val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000343 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
344 check_warn_return(ret, "Error writing E2P_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000345
346 ret = smsc95xx_wait_eeprom(dev);
347 if (ret < 0)
348 return ret;
349
350 for (i = 0; i < length; i++) {
351
352 /* Fill data register */
353 val = data[i];
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000354 ret = smsc95xx_write_reg(dev, E2P_DATA, val);
355 check_warn_return(ret, "Error writing E2P_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000356
357 /* Send "write" command */
358 val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000359 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
360 check_warn_return(ret, "Error writing E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000361
362 ret = smsc95xx_wait_eeprom(dev);
363 if (ret < 0)
364 return ret;
365
366 offset++;
367 }
368
369 return 0;
370}
371
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000372static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
373 u32 *data)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000374{
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700375 const u16 size = 4;
Ming Lei72108fd2012-10-24 19:47:04 +0000376 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000377
Ming Lei72108fd2012-10-24 19:47:04 +0000378 ret = usbnet_write_cmd_async(dev, USB_VENDOR_REQUEST_WRITE_REGISTER,
379 USB_DIR_OUT | USB_TYPE_VENDOR |
380 USB_RECIP_DEVICE,
381 0, index, data, size);
382 if (ret < 0)
383 netdev_warn(dev->net, "Error write async cmd, sts=%d\n",
384 ret);
385 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000386}
387
388/* returns hash bit number for given MAC address
389 * example:
390 * 01 00 5E 00 00 01 -> returns bit number 31 */
391static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
392{
393 return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
394}
395
396static void smsc95xx_set_multicast(struct net_device *netdev)
397{
398 struct usbnet *dev = netdev_priv(netdev);
399 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000400 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000401 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000402
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000403 pdata->hash_hi = 0;
404 pdata->hash_lo = 0;
405
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000406 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
407
408 if (dev->net->flags & IFF_PROMISC) {
Joe Perchesa475f602010-02-17 10:30:24 +0000409 netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000410 pdata->mac_cr |= MAC_CR_PRMS_;
411 pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
412 } else if (dev->net->flags & IFF_ALLMULTI) {
Joe Perchesa475f602010-02-17 10:30:24 +0000413 netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000414 pdata->mac_cr |= MAC_CR_MCPAS_;
415 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000416 } else if (!netdev_mc_empty(dev->net)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +0000417 struct netdev_hw_addr *ha;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000418
419 pdata->mac_cr |= MAC_CR_HPFILT_;
420 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
421
Jiri Pirko22bedad32010-04-01 21:22:57 +0000422 netdev_for_each_mc_addr(ha, netdev) {
423 u32 bitnum = smsc95xx_hash(ha->addr);
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000424 u32 mask = 0x01 << (bitnum & 0x1F);
425 if (bitnum & 0x20)
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000426 pdata->hash_hi |= mask;
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000427 else
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000428 pdata->hash_lo |= mask;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000429 }
430
Joe Perchesa475f602010-02-17 10:30:24 +0000431 netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000432 pdata->hash_hi, pdata->hash_lo);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000433 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000434 netif_dbg(dev, drv, dev->net, "receive own packets only\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000435 pdata->mac_cr &=
436 ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
437 }
438
439 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
440
441 /* Initiate async writes, as we can't wait for completion here */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000442 ret = smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi);
443 check_warn(ret, "failed to initiate async write to HASHH");
444
445 ret = smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo);
446 check_warn(ret, "failed to initiate async write to HASHL");
447
448 ret = smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr);
449 check_warn(ret, "failed to initiate async write to MAC_CR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000450}
451
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000452static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
453 u16 lcladv, u16 rmtadv)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000454{
455 u32 flow, afc_cfg = 0;
456
457 int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000458 check_warn_return(ret, "Error reading AFC_CFG");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000459
460 if (duplex == DUPLEX_FULL) {
Steve Glendinningbc02ff92008-12-16 02:00:48 -0800461 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000462
463 if (cap & FLOW_CTRL_RX)
464 flow = 0xFFFF0002;
465 else
466 flow = 0;
467
468 if (cap & FLOW_CTRL_TX)
469 afc_cfg |= 0xF;
470 else
471 afc_cfg &= ~0xF;
472
Joe Perchesa475f602010-02-17 10:30:24 +0000473 netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
Joe Perches60b86752010-02-17 10:30:23 +0000474 cap & FLOW_CTRL_RX ? "enabled" : "disabled",
475 cap & FLOW_CTRL_TX ? "enabled" : "disabled");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000476 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000477 netif_dbg(dev, link, dev->net, "half duplex\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000478 flow = 0;
479 afc_cfg |= 0xF;
480 }
481
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000482 ret = smsc95xx_write_reg(dev, FLOW, flow);
483 check_warn_return(ret, "Error writing FLOW");
484
485 ret = smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
486 check_warn_return(ret, "Error writing AFC_CFG");
487
488 return 0;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000489}
490
491static int smsc95xx_link_reset(struct usbnet *dev)
492{
493 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
494 struct mii_if_info *mii = &dev->mii;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000495 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000496 unsigned long flags;
497 u16 lcladv, rmtadv;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000498 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000499
500 /* clear interrupt status */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000501 ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
502 check_warn_return(ret, "Error reading PHY_INT_SRC");
503
504 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
505 check_warn_return(ret, "Error writing INT_STS");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000506
507 mii_check_media(mii, 1, 1);
508 mii_ethtool_gset(&dev->mii, &ecmd);
509 lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
510 rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
511
David Decotigny8ae6daca2011-04-27 18:32:38 +0000512 netif_dbg(dev, link, dev->net,
513 "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
514 ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000515
516 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
517 if (ecmd.duplex != DUPLEX_FULL) {
518 pdata->mac_cr &= ~MAC_CR_FDPX_;
519 pdata->mac_cr |= MAC_CR_RCVOWN_;
520 } else {
521 pdata->mac_cr &= ~MAC_CR_RCVOWN_;
522 pdata->mac_cr |= MAC_CR_FDPX_;
523 }
524 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
525
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000526 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
527 check_warn_return(ret, "Error writing MAC_CR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000528
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000529 ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
530 check_warn_return(ret, "Error updating PHY flow control");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000531
532 return 0;
533}
534
535static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
536{
537 u32 intdata;
538
539 if (urb->actual_length != 4) {
Joe Perches60b86752010-02-17 10:30:23 +0000540 netdev_warn(dev->net, "unexpected urb length %d\n",
541 urb->actual_length);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000542 return;
543 }
544
545 memcpy(&intdata, urb->transfer_buffer, 4);
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700546 le32_to_cpus(&intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000547
Joe Perchesa475f602010-02-17 10:30:24 +0000548 netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000549
550 if (intdata & INT_ENP_PHY_INT_)
551 usbnet_defer_kevent(dev, EVENT_LINK_RESET);
552 else
Joe Perches60b86752010-02-17 10:30:23 +0000553 netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
554 intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000555}
556
Steve Glendinningf7b29272008-11-20 04:19:21 -0800557/* Enable or disable Tx & Rx checksum offload engines */
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000558static int smsc95xx_set_features(struct net_device *netdev,
559 netdev_features_t features)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000560{
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700561 struct usbnet *dev = netdev_priv(netdev);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000562 u32 read_buf;
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700563 int ret;
564
565 ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000566 check_warn_return(ret, "Failed to read COE_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000567
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700568 if (features & NETIF_F_HW_CSUM)
Steve Glendinningf7b29272008-11-20 04:19:21 -0800569 read_buf |= Tx_COE_EN_;
570 else
571 read_buf &= ~Tx_COE_EN_;
572
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700573 if (features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000574 read_buf |= Rx_COE_EN_;
575 else
576 read_buf &= ~Rx_COE_EN_;
577
578 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000579 check_warn_return(ret, "Failed to write COE_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000580
Joe Perchesa475f602010-02-17 10:30:24 +0000581 netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000582 return 0;
583}
584
585static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
586{
587 return MAX_EEPROM_SIZE;
588}
589
590static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
591 struct ethtool_eeprom *ee, u8 *data)
592{
593 struct usbnet *dev = netdev_priv(netdev);
594
595 ee->magic = LAN95XX_EEPROM_MAGIC;
596
597 return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
598}
599
600static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
601 struct ethtool_eeprom *ee, u8 *data)
602{
603 struct usbnet *dev = netdev_priv(netdev);
604
605 if (ee->magic != LAN95XX_EEPROM_MAGIC) {
Joe Perches60b86752010-02-17 10:30:23 +0000606 netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
607 ee->magic);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000608 return -EINVAL;
609 }
610
611 return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
612}
613
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400614static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
615{
616 /* all smsc95xx registers */
617 return COE_CR - ID_REV + 1;
618}
619
620static void
621smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
622 void *buf)
623{
624 struct usbnet *dev = netdev_priv(netdev);
Dan Carpenterd3484462012-07-10 20:32:51 +0000625 unsigned int i, j;
626 int retval;
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400627 u32 *data = buf;
628
629 retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
630 if (retval < 0) {
631 netdev_warn(netdev, "REGS: cannot read ID_REV\n");
632 return;
633 }
634
635 for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
636 retval = smsc95xx_read_reg(dev, i, &data[j]);
637 if (retval < 0) {
638 netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
639 return;
640 }
641 }
642}
643
Steve Glendinninge0e474a82012-09-28 00:07:12 +0000644static void smsc95xx_ethtool_get_wol(struct net_device *net,
645 struct ethtool_wolinfo *wolinfo)
646{
647 struct usbnet *dev = netdev_priv(net);
648 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
649
650 wolinfo->supported = SUPPORTED_WAKE;
651 wolinfo->wolopts = pdata->wolopts;
652}
653
654static int smsc95xx_ethtool_set_wol(struct net_device *net,
655 struct ethtool_wolinfo *wolinfo)
656{
657 struct usbnet *dev = netdev_priv(net);
658 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
659
660 pdata->wolopts = wolinfo->wolopts & SUPPORTED_WAKE;
661 return 0;
662}
663
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700664static const struct ethtool_ops smsc95xx_ethtool_ops = {
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000665 .get_link = usbnet_get_link,
666 .nway_reset = usbnet_nway_reset,
667 .get_drvinfo = usbnet_get_drvinfo,
668 .get_msglevel = usbnet_get_msglevel,
669 .set_msglevel = usbnet_set_msglevel,
670 .get_settings = usbnet_get_settings,
671 .set_settings = usbnet_set_settings,
672 .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
673 .get_eeprom = smsc95xx_ethtool_get_eeprom,
674 .set_eeprom = smsc95xx_ethtool_set_eeprom,
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400675 .get_regs_len = smsc95xx_ethtool_getregslen,
676 .get_regs = smsc95xx_ethtool_getregs,
Steve Glendinninge0e474a82012-09-28 00:07:12 +0000677 .get_wol = smsc95xx_ethtool_get_wol,
678 .set_wol = smsc95xx_ethtool_set_wol,
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000679};
680
681static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
682{
683 struct usbnet *dev = netdev_priv(netdev);
684
685 if (!netif_running(netdev))
686 return -EINVAL;
687
688 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
689}
690
691static void smsc95xx_init_mac_address(struct usbnet *dev)
692{
693 /* try reading mac address from EEPROM */
694 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
695 dev->net->dev_addr) == 0) {
696 if (is_valid_ether_addr(dev->net->dev_addr)) {
697 /* eeprom values are valid so use them */
Joe Perchesa475f602010-02-17 10:30:24 +0000698 netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000699 return;
700 }
701 }
702
703 /* no eeprom, or eeprom values are invalid. generate random MAC */
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000704 eth_hw_addr_random(dev->net);
Joe Perchesc7e12ea2012-07-12 19:33:07 +0000705 netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000706}
707
708static int smsc95xx_set_mac_address(struct usbnet *dev)
709{
710 u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
711 dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
712 u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
713 int ret;
714
715 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000716 check_warn_return(ret, "Failed to write ADDRL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000717
718 ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000719 check_warn_return(ret, "Failed to write ADDRH: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000720
721 return 0;
722}
723
724/* starts the TX path */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000725static int smsc95xx_start_tx_path(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000726{
727 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
728 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000729 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000730
731 /* Enable Tx at MAC */
732 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
733 pdata->mac_cr |= MAC_CR_TXEN_;
734 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
735
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000736 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
737 check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000738
739 /* Enable Tx at SCSRs */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000740 ret = smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
741 check_warn_return(ret, "Failed to write TX_CFG: %d\n", ret);
742
743 return 0;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000744}
745
746/* Starts the Receive path */
Ming Leiec321152012-11-06 04:53:07 +0000747static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000748{
749 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
750 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000751 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000752
753 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
754 pdata->mac_cr |= MAC_CR_RXEN_;
755 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
756
Ming Leiec321152012-11-06 04:53:07 +0000757 ret = __smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr, in_pm);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000758 check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
759
760 return 0;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000761}
762
763static int smsc95xx_phy_initialize(struct usbnet *dev)
764{
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000765 int bmcr, ret, timeout = 0;
Steve Glendinningdb443c42010-03-16 09:03:06 +0000766
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000767 /* Initialize MII structure */
768 dev->mii.dev = dev->net;
769 dev->mii.mdio_read = smsc95xx_mdio_read;
770 dev->mii.mdio_write = smsc95xx_mdio_write;
771 dev->mii.phy_id_mask = 0x1f;
772 dev->mii.reg_num_mask = 0x1f;
773 dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
774
Steve Glendinningdb443c42010-03-16 09:03:06 +0000775 /* reset phy and wait for reset to complete */
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000776 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
Steve Glendinningdb443c42010-03-16 09:03:06 +0000777
778 do {
779 msleep(10);
780 bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
781 timeout++;
Rabin Vincentd9460922011-04-30 08:29:27 +0000782 } while ((bmcr & BMCR_RESET) && (timeout < 100));
Steve Glendinningdb443c42010-03-16 09:03:06 +0000783
784 if (timeout >= 100) {
785 netdev_warn(dev->net, "timeout on PHY Reset");
786 return -EIO;
787 }
788
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000789 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
790 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
791 ADVERTISE_PAUSE_ASYM);
792
793 /* read to clear */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000794 ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
795 check_warn_return(ret, "Failed to read PHY_INT_SRC during init");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000796
797 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
798 PHY_INT_MASK_DEFAULT_);
799 mii_nway_restart(&dev->mii);
800
Joe Perchesa475f602010-02-17 10:30:24 +0000801 netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000802 return 0;
803}
804
805static int smsc95xx_reset(struct usbnet *dev)
806{
807 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
808 u32 read_buf, write_buf, burst_cap;
809 int ret = 0, timeout;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000810
Joe Perchesa475f602010-02-17 10:30:24 +0000811 netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000812
Steve Glendinning44367612012-09-28 00:07:08 +0000813 ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000814 check_warn_return(ret, "Failed to write HW_CFG_LRST_ bit in HW_CFG\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000815
816 timeout = 0;
817 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000818 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000819 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000820 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000821 timeout++;
822 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
823
824 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000825 netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000826 return ret;
827 }
828
Steve Glendinning44367612012-09-28 00:07:08 +0000829 ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000830 check_warn_return(ret, "Failed to write PM_CTRL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000831
832 timeout = 0;
833 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000834 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000835 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000836 check_warn_return(ret, "Failed to read PM_CTRL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000837 timeout++;
838 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
839
840 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000841 netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000842 return ret;
843 }
844
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000845 ret = smsc95xx_set_mac_address(dev);
846 if (ret < 0)
847 return ret;
848
Joe Perchesa475f602010-02-17 10:30:24 +0000849 netif_dbg(dev, ifup, dev->net,
850 "MAC Address: %pM\n", dev->net->dev_addr);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000851
852 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000853 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000854
Joe Perchesa475f602010-02-17 10:30:24 +0000855 netif_dbg(dev, ifup, dev->net,
856 "Read Value from HW_CFG : 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000857
858 read_buf |= HW_CFG_BIR_;
859
860 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000861 check_warn_return(ret, "Failed to write HW_CFG_BIR_ bit in HW_CFG\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000862
863 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000864 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
Joe Perchesa475f602010-02-17 10:30:24 +0000865 netif_dbg(dev, ifup, dev->net,
866 "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
867 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000868
869 if (!turbo_mode) {
870 burst_cap = 0;
871 dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
872 } else if (dev->udev->speed == USB_SPEED_HIGH) {
873 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
874 dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
875 } else {
876 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
877 dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
878 }
879
Joe Perchesa475f602010-02-17 10:30:24 +0000880 netif_dbg(dev, ifup, dev->net,
881 "rx_urb_size=%ld\n", (ulong)dev->rx_urb_size);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000882
883 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000884 check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000885
886 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000887 check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret);
888
Joe Perchesa475f602010-02-17 10:30:24 +0000889 netif_dbg(dev, ifup, dev->net,
890 "Read Value from BURST_CAP after writing: 0x%08x\n",
891 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000892
Steve Glendinning44367612012-09-28 00:07:08 +0000893 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000894 check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000895
896 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000897 check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret);
898
Joe Perchesa475f602010-02-17 10:30:24 +0000899 netif_dbg(dev, ifup, dev->net,
900 "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
901 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000902
903 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000904 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
905
Joe Perchesa475f602010-02-17 10:30:24 +0000906 netif_dbg(dev, ifup, dev->net,
907 "Read Value from HW_CFG: 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000908
909 if (turbo_mode)
910 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
911
912 read_buf &= ~HW_CFG_RXDOFF_;
913
914 /* set Rx data offset=2, Make IP header aligns on word boundary. */
915 read_buf |= NET_IP_ALIGN << 9;
916
917 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000918 check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000919
920 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000921 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
922
Joe Perchesa475f602010-02-17 10:30:24 +0000923 netif_dbg(dev, ifup, dev->net,
924 "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000925
Steve Glendinning44367612012-09-28 00:07:08 +0000926 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000927 check_warn_return(ret, "Failed to write INT_STS: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000928
929 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000930 check_warn_return(ret, "Failed to read ID_REV: %d\n", ret);
Joe Perchesa475f602010-02-17 10:30:24 +0000931 netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000932
Steve Glendinningf2935012009-05-01 05:46:51 +0000933 /* Configure GPIO pins as LED outputs */
934 write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
935 LED_GPIO_CFG_FDX_LED;
936 ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000937 check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n", ret);
Steve Glendinningf2935012009-05-01 05:46:51 +0000938
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000939 /* Init Tx */
Steve Glendinning44367612012-09-28 00:07:08 +0000940 ret = smsc95xx_write_reg(dev, FLOW, 0);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000941 check_warn_return(ret, "Failed to write FLOW: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000942
Steve Glendinning44367612012-09-28 00:07:08 +0000943 ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000944 check_warn_return(ret, "Failed to write AFC_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000945
946 /* Don't need mac_cr_lock during initialisation */
947 ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000948 check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000949
950 /* Init Rx */
951 /* Set Vlan */
Steve Glendinning44367612012-09-28 00:07:08 +0000952 ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000953 check_warn_return(ret, "Failed to write VLAN1: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000954
Steve Glendinningf7b29272008-11-20 04:19:21 -0800955 /* Enable or disable checksum offload engines */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000956 ret = smsc95xx_set_features(dev->net, dev->net->features);
957 check_warn_return(ret, "Failed to set checksum offload features");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000958
959 smsc95xx_set_multicast(dev->net);
960
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000961 ret = smsc95xx_phy_initialize(dev);
962 check_warn_return(ret, "Failed to init PHY");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000963
964 ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000965 check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000966
967 /* enable PHY interrupts */
968 read_buf |= INT_EP_CTL_PHY_INT_;
969
970 ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000971 check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000972
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000973 ret = smsc95xx_start_tx_path(dev);
974 check_warn_return(ret, "Failed to start TX path");
975
Ming Leiec321152012-11-06 04:53:07 +0000976 ret = smsc95xx_start_rx_path(dev, 0);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000977 check_warn_return(ret, "Failed to start RX path");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000978
Joe Perchesa475f602010-02-17 10:30:24 +0000979 netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000980 return 0;
981}
982
Stephen Hemminger63e77b32009-03-20 19:35:58 +0000983static const struct net_device_ops smsc95xx_netdev_ops = {
984 .ndo_open = usbnet_open,
985 .ndo_stop = usbnet_stop,
986 .ndo_start_xmit = usbnet_start_xmit,
987 .ndo_tx_timeout = usbnet_tx_timeout,
988 .ndo_change_mtu = usbnet_change_mtu,
989 .ndo_set_mac_address = eth_mac_addr,
990 .ndo_validate_addr = eth_validate_addr,
991 .ndo_do_ioctl = smsc95xx_ioctl,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000992 .ndo_set_rx_mode = smsc95xx_set_multicast,
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700993 .ndo_set_features = smsc95xx_set_features,
Stephen Hemminger63e77b32009-03-20 19:35:58 +0000994};
995
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000996static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
997{
998 struct smsc95xx_priv *pdata = NULL;
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +0000999 u32 val;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001000 int ret;
1001
1002 printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
1003
1004 ret = usbnet_get_endpoints(dev, intf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +00001005 check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001006
1007 dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
1008 GFP_KERNEL);
1009
1010 pdata = (struct smsc95xx_priv *)(dev->data[0]);
1011 if (!pdata) {
Joe Perches60b86752010-02-17 10:30:23 +00001012 netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001013 return -ENOMEM;
1014 }
1015
1016 spin_lock_init(&pdata->mac_cr_lock);
1017
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001018 if (DEFAULT_TX_CSUM_ENABLE)
1019 dev->net->features |= NETIF_F_HW_CSUM;
1020 if (DEFAULT_RX_CSUM_ENABLE)
1021 dev->net->features |= NETIF_F_RXCSUM;
1022
1023 dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001024
Bernard Blackhamf4e8ab72010-10-18 13:16:39 +00001025 smsc95xx_init_mac_address(dev);
1026
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001027 /* Init all registers */
1028 ret = smsc95xx_reset(dev);
1029
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001030 /* detect device revision as different features may be available */
1031 ret = smsc95xx_read_reg(dev, ID_REV, &val);
1032 check_warn_return(ret, "Failed to read ID_REV: %d\n", ret);
1033 val >>= 16;
1034 if ((val == ID_REV_CHIP_ID_9500A_) || (val == ID_REV_CHIP_ID_9512_))
1035 pdata->wuff_filter_count = LAN9500A_WUFF_NUM;
1036 else
1037 pdata->wuff_filter_count = LAN9500_WUFF_NUM;
1038
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001039 dev->net->netdev_ops = &smsc95xx_netdev_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001040 dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001041 dev->net->flags |= IFF_MULTICAST;
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001042 dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
Stephane Fillod9bbf5662012-04-20 09:39:23 +00001043 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001044 return 0;
1045}
1046
1047static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
1048{
1049 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1050 if (pdata) {
Joe Perchesa475f602010-02-17 10:30:24 +00001051 netif_dbg(dev, ifdown, dev->net, "free pdata\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001052 kfree(pdata);
1053 pdata = NULL;
1054 dev->data[0] = 0;
1055 }
1056}
1057
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001058static u16 smsc_crc(const u8 *buffer, size_t len, int filter)
1059{
1060 return bitrev16(crc16(0xFFFF, buffer, len)) << ((filter % 2) * 16);
1061}
1062
Steve Glendinningb5a04472012-09-28 00:07:11 +00001063static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1064{
1065 struct usbnet *dev = usb_get_intfdata(intf);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001066 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinningb5a04472012-09-28 00:07:11 +00001067 int ret;
1068 u32 val;
1069
Steve Glendinningb5a04472012-09-28 00:07:11 +00001070 ret = usbnet_suspend(intf, message);
1071 check_warn_return(ret, "usbnet_suspend error");
1072
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001073 /* if no wol options set, enter lowest power SUSPEND2 mode */
1074 if (!(pdata->wolopts & SUPPORTED_WAKE)) {
1075 netdev_info(dev->net, "entering SUSPEND2 mode");
1076
1077 /* disable energy detect (link up) & wake up events */
Ming Leiec321152012-11-06 04:53:07 +00001078 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001079 check_warn_return(ret, "Error reading WUCSR");
1080
1081 val &= ~(WUCSR_MPEN_ | WUCSR_WAKE_EN_);
1082
Ming Leiec321152012-11-06 04:53:07 +00001083 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001084 check_warn_return(ret, "Error writing WUCSR");
1085
Ming Leiec321152012-11-06 04:53:07 +00001086 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001087 check_warn_return(ret, "Error reading PM_CTRL");
1088
1089 val &= ~(PM_CTL_ED_EN_ | PM_CTL_WOL_EN_);
1090
Ming Leiec321152012-11-06 04:53:07 +00001091 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001092 check_warn_return(ret, "Error writing PM_CTRL");
1093
1094 /* enter suspend2 mode */
Ming Leiec321152012-11-06 04:53:07 +00001095 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001096 check_warn_return(ret, "Error reading PM_CTRL");
1097
1098 val &= ~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_);
1099 val |= PM_CTL_SUS_MODE_2;
1100
Ming Leiec321152012-11-06 04:53:07 +00001101 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001102 check_warn_return(ret, "Error writing PM_CTRL");
1103
1104 return 0;
1105 }
1106
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001107 if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
1108 u32 *filter_mask = kzalloc(32, GFP_KERNEL);
Ming Lei06a221b2012-11-06 04:53:06 +00001109 u32 command[2];
1110 u32 offset[2];
1111 u32 crc[4];
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001112 int i, filter = 0;
1113
Ming Lei06a221b2012-11-06 04:53:06 +00001114 memset(command, 0, sizeof(command));
1115 memset(offset, 0, sizeof(offset));
1116 memset(crc, 0, sizeof(crc));
1117
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001118 if (pdata->wolopts & WAKE_BCAST) {
1119 const u8 bcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1120 netdev_info(dev->net, "enabling broadcast detection");
1121 filter_mask[filter * 4] = 0x003F;
1122 filter_mask[filter * 4 + 1] = 0x00;
1123 filter_mask[filter * 4 + 2] = 0x00;
1124 filter_mask[filter * 4 + 3] = 0x00;
1125 command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1126 offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1127 crc[filter/2] |= smsc_crc(bcast, 6, filter);
1128 filter++;
1129 }
1130
1131 if (pdata->wolopts & WAKE_MCAST) {
1132 const u8 mcast[] = {0x01, 0x00, 0x5E};
1133 netdev_info(dev->net, "enabling multicast detection");
1134 filter_mask[filter * 4] = 0x0007;
1135 filter_mask[filter * 4 + 1] = 0x00;
1136 filter_mask[filter * 4 + 2] = 0x00;
1137 filter_mask[filter * 4 + 3] = 0x00;
1138 command[filter/4] |= 0x09UL << ((filter % 4) * 8);
1139 offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1140 crc[filter/2] |= smsc_crc(mcast, 3, filter);
1141 filter++;
1142 }
1143
1144 if (pdata->wolopts & WAKE_ARP) {
1145 const u8 arp[] = {0x08, 0x06};
1146 netdev_info(dev->net, "enabling ARP detection");
1147 filter_mask[filter * 4] = 0x0003;
1148 filter_mask[filter * 4 + 1] = 0x00;
1149 filter_mask[filter * 4 + 2] = 0x00;
1150 filter_mask[filter * 4 + 3] = 0x00;
1151 command[filter/4] |= 0x05UL << ((filter % 4) * 8);
1152 offset[filter/4] |= 0x0C << ((filter % 4) * 8);
1153 crc[filter/2] |= smsc_crc(arp, 2, filter);
1154 filter++;
1155 }
1156
1157 if (pdata->wolopts & WAKE_UCAST) {
1158 netdev_info(dev->net, "enabling unicast detection");
1159 filter_mask[filter * 4] = 0x003F;
1160 filter_mask[filter * 4 + 1] = 0x00;
1161 filter_mask[filter * 4 + 2] = 0x00;
1162 filter_mask[filter * 4 + 3] = 0x00;
1163 command[filter/4] |= 0x01UL << ((filter % 4) * 8);
1164 offset[filter/4] |= 0x00 << ((filter % 4) * 8);
1165 crc[filter/2] |= smsc_crc(dev->net->dev_addr, ETH_ALEN, filter);
1166 filter++;
1167 }
1168
1169 for (i = 0; i < (pdata->wuff_filter_count * 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001170 ret = smsc95xx_write_reg_nopm(dev, WUFF, filter_mask[i]);
Ming Lei06a221b2012-11-06 04:53:06 +00001171 if (ret < 0)
1172 kfree(filter_mask);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001173 check_warn_return(ret, "Error writing WUFF");
1174 }
Ming Lei06a221b2012-11-06 04:53:06 +00001175 kfree(filter_mask);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001176
1177 for (i = 0; i < (pdata->wuff_filter_count / 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001178 ret = smsc95xx_write_reg_nopm(dev, WUFF, command[i]);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001179 check_warn_return(ret, "Error writing WUFF");
1180 }
1181
1182 for (i = 0; i < (pdata->wuff_filter_count / 4); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001183 ret = smsc95xx_write_reg_nopm(dev, WUFF, offset[i]);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001184 check_warn_return(ret, "Error writing WUFF");
1185 }
1186
1187 for (i = 0; i < (pdata->wuff_filter_count / 2); i++) {
Ming Leiec321152012-11-06 04:53:07 +00001188 ret = smsc95xx_write_reg_nopm(dev, WUFF, crc[i]);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001189 check_warn_return(ret, "Error writing WUFF");
1190 }
1191
1192 /* clear any pending pattern match packet status */
Ming Leiec321152012-11-06 04:53:07 +00001193 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001194 check_warn_return(ret, "Error reading WUCSR");
1195
1196 val |= WUCSR_WUFR_;
1197
Ming Leiec321152012-11-06 04:53:07 +00001198 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001199 check_warn_return(ret, "Error writing WUCSR");
1200 }
1201
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001202 if (pdata->wolopts & WAKE_MAGIC) {
1203 /* clear any pending magic packet status */
Ming Leiec321152012-11-06 04:53:07 +00001204 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001205 check_warn_return(ret, "Error reading WUCSR");
1206
1207 val |= WUCSR_MPR_;
1208
Ming Leiec321152012-11-06 04:53:07 +00001209 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001210 check_warn_return(ret, "Error writing WUCSR");
1211 }
1212
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001213 /* enable/disable wakeup sources */
Ming Leiec321152012-11-06 04:53:07 +00001214 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001215 check_warn_return(ret, "Error reading WUCSR");
1216
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001217 if (pdata->wolopts & (WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST)) {
1218 netdev_info(dev->net, "enabling pattern match wakeup");
1219 val |= WUCSR_WAKE_EN_;
1220 } else {
1221 netdev_info(dev->net, "disabling pattern match wakeup");
1222 val &= ~WUCSR_WAKE_EN_;
1223 }
1224
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001225 if (pdata->wolopts & WAKE_MAGIC) {
1226 netdev_info(dev->net, "enabling magic packet wakeup");
1227 val |= WUCSR_MPEN_;
1228 } else {
1229 netdev_info(dev->net, "disabling magic packet wakeup");
1230 val &= ~WUCSR_MPEN_;
1231 }
1232
Ming Leiec321152012-11-06 04:53:07 +00001233 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001234 check_warn_return(ret, "Error writing WUCSR");
1235
1236 /* enable wol wakeup source */
Ming Leiec321152012-11-06 04:53:07 +00001237 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001238 check_warn_return(ret, "Error reading PM_CTRL");
1239
1240 val |= PM_CTL_WOL_EN_;
1241
Ming Leiec321152012-11-06 04:53:07 +00001242 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001243 check_warn_return(ret, "Error writing PM_CTRL");
1244
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001245 /* enable receiver to enable frame reception */
Ming Leiec321152012-11-06 04:53:07 +00001246 smsc95xx_start_rx_path(dev, 1);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001247
1248 /* some wol options are enabled, so enter SUSPEND0 */
1249 netdev_info(dev->net, "entering SUSPEND0 mode");
Steve Glendinningb5a04472012-09-28 00:07:11 +00001250
Ming Leiec321152012-11-06 04:53:07 +00001251 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinningb5a04472012-09-28 00:07:11 +00001252 check_warn_return(ret, "Error reading PM_CTRL");
1253
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001254 val &= (~(PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_));
1255 val |= PM_CTL_SUS_MODE_0;
Steve Glendinningb5a04472012-09-28 00:07:11 +00001256
Ming Leiec321152012-11-06 04:53:07 +00001257 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinningb5a04472012-09-28 00:07:11 +00001258 check_warn_return(ret, "Error writing PM_CTRL");
1259
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001260 /* clear wol status */
1261 val &= ~PM_CTL_WUPS_;
1262 val |= PM_CTL_WUPS_WOL_;
Ming Leiec321152012-11-06 04:53:07 +00001263 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001264 check_warn_return(ret, "Error writing PM_CTRL");
1265
1266 /* read back PM_CTRL */
Ming Leiec321152012-11-06 04:53:07 +00001267 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001268 check_warn_return(ret, "Error reading PM_CTRL");
1269
1270 smsc95xx_set_feature(dev, USB_DEVICE_REMOTE_WAKEUP);
1271
1272 return 0;
1273}
1274
1275static int smsc95xx_resume(struct usb_interface *intf)
1276{
1277 struct usbnet *dev = usb_get_intfdata(intf);
1278 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1279 int ret;
1280 u32 val;
1281
1282 BUG_ON(!dev);
1283
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001284 if (pdata->wolopts) {
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001285 smsc95xx_clear_feature(dev, USB_DEVICE_REMOTE_WAKEUP);
1286
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001287 /* clear wake-up sources */
Ming Leiec321152012-11-06 04:53:07 +00001288 ret = smsc95xx_read_reg_nopm(dev, WUCSR, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001289 check_warn_return(ret, "Error reading WUCSR");
1290
Steve Glendinningbbd9f9e2012-10-26 03:43:56 +00001291 val &= ~(WUCSR_WAKE_EN_ | WUCSR_MPEN_);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001292
Ming Leiec321152012-11-06 04:53:07 +00001293 ret = smsc95xx_write_reg_nopm(dev, WUCSR, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001294 check_warn_return(ret, "Error writing WUCSR");
1295
1296 /* clear wake-up status */
Ming Leiec321152012-11-06 04:53:07 +00001297 ret = smsc95xx_read_reg_nopm(dev, PM_CTRL, &val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001298 check_warn_return(ret, "Error reading PM_CTRL");
1299
1300 val &= ~PM_CTL_WOL_EN_;
1301 val |= PM_CTL_WUPS_;
1302
Ming Leiec321152012-11-06 04:53:07 +00001303 ret = smsc95xx_write_reg_nopm(dev, PM_CTRL, val);
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001304 check_warn_return(ret, "Error writing PM_CTRL");
1305 }
1306
1307 return usbnet_resume(intf);
1308 check_warn_return(ret, "usbnet_resume error");
1309
Steve Glendinningb5a04472012-09-28 00:07:11 +00001310 return 0;
1311}
1312
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001313static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
1314{
1315 skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
1316 skb->ip_summed = CHECKSUM_COMPLETE;
1317 skb_trim(skb, skb->len - 2);
1318}
1319
1320static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1321{
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001322 while (skb->len > 0) {
1323 u32 header, align_count;
1324 struct sk_buff *ax_skb;
1325 unsigned char *packet;
1326 u16 size;
1327
1328 memcpy(&header, skb->data, sizeof(header));
1329 le32_to_cpus(&header);
1330 skb_pull(skb, 4 + NET_IP_ALIGN);
1331 packet = skb->data;
1332
1333 /* get the packet length */
1334 size = (u16)((header & RX_STS_FL_) >> 16);
1335 align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
1336
1337 if (unlikely(header & RX_STS_ES_)) {
Joe Perchesa475f602010-02-17 10:30:24 +00001338 netif_dbg(dev, rx_err, dev->net,
1339 "Error header=0x%08x\n", header);
Herbert Xu80667ac2009-06-29 16:53:00 +00001340 dev->net->stats.rx_errors++;
1341 dev->net->stats.rx_dropped++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001342
1343 if (header & RX_STS_CRC_) {
Herbert Xu80667ac2009-06-29 16:53:00 +00001344 dev->net->stats.rx_crc_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001345 } else {
1346 if (header & (RX_STS_TL_ | RX_STS_RF_))
Herbert Xu80667ac2009-06-29 16:53:00 +00001347 dev->net->stats.rx_frame_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001348
1349 if ((header & RX_STS_LE_) &&
1350 (!(header & RX_STS_FT_)))
Herbert Xu80667ac2009-06-29 16:53:00 +00001351 dev->net->stats.rx_length_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001352 }
1353 } else {
1354 /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
1355 if (unlikely(size > (ETH_FRAME_LEN + 12))) {
Joe Perchesa475f602010-02-17 10:30:24 +00001356 netif_dbg(dev, rx_err, dev->net,
1357 "size err header=0x%08x\n", header);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001358 return 0;
1359 }
1360
1361 /* last frame in this batch */
1362 if (skb->len == size) {
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001363 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001364 smsc95xx_rx_csum_offload(skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001365 skb_trim(skb, skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001366 skb->truesize = size + sizeof(struct sk_buff);
1367
1368 return 1;
1369 }
1370
1371 ax_skb = skb_clone(skb, GFP_ATOMIC);
1372 if (unlikely(!ax_skb)) {
Joe Perches60b86752010-02-17 10:30:23 +00001373 netdev_warn(dev->net, "Error allocating skb\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001374 return 0;
1375 }
1376
1377 ax_skb->len = size;
1378 ax_skb->data = packet;
1379 skb_set_tail_pointer(ax_skb, size);
1380
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001381 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001382 smsc95xx_rx_csum_offload(ax_skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001383 skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001384 ax_skb->truesize = size + sizeof(struct sk_buff);
1385
1386 usbnet_skb_return(dev, ax_skb);
1387 }
1388
1389 skb_pull(skb, size);
1390
1391 /* padding bytes before the next frame starts */
1392 if (skb->len)
1393 skb_pull(skb, align_count);
1394 }
1395
1396 if (unlikely(skb->len < 0)) {
Joe Perches60b86752010-02-17 10:30:23 +00001397 netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001398 return 0;
1399 }
1400
1401 return 1;
1402}
1403
Steve Glendinningf7b29272008-11-20 04:19:21 -08001404static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
1405{
Michał Mirosław55508d62010-12-14 15:24:08 +00001406 u16 low_16 = (u16)skb_checksum_start_offset(skb);
1407 u16 high_16 = low_16 + skb->csum_offset;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001408 return (high_16 << 16) | low_16;
1409}
1410
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001411static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
1412 struct sk_buff *skb, gfp_t flags)
1413{
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001414 bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001415 int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001416 u32 tx_cmd_a, tx_cmd_b;
1417
Steve Glendinningf7b29272008-11-20 04:19:21 -08001418 /* We do not advertise SG, so skbs should be already linearized */
1419 BUG_ON(skb_shinfo(skb)->nr_frags);
1420
1421 if (skb_headroom(skb) < overhead) {
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001422 struct sk_buff *skb2 = skb_copy_expand(skb,
Steve Glendinningf7b29272008-11-20 04:19:21 -08001423 overhead, 0, flags);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001424 dev_kfree_skb_any(skb);
1425 skb = skb2;
1426 if (!skb)
1427 return NULL;
1428 }
1429
Steve Glendinningf7b29272008-11-20 04:19:21 -08001430 if (csum) {
Steve Glendinning11bc3082010-03-18 22:18:41 -07001431 if (skb->len <= 45) {
1432 /* workaround - hardware tx checksum does not work
1433 * properly with extremely small packets */
Michał Mirosław55508d62010-12-14 15:24:08 +00001434 long csstart = skb_checksum_start_offset(skb);
Steve Glendinning11bc3082010-03-18 22:18:41 -07001435 __wsum calc = csum_partial(skb->data + csstart,
1436 skb->len - csstart, 0);
1437 *((__sum16 *)(skb->data + csstart
1438 + skb->csum_offset)) = csum_fold(calc);
1439
1440 csum = false;
1441 } else {
1442 u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
1443 skb_push(skb, 4);
1444 memcpy(skb->data, &csum_preamble, 4);
1445 }
Steve Glendinningf7b29272008-11-20 04:19:21 -08001446 }
1447
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001448 skb_push(skb, 4);
1449 tx_cmd_b = (u32)(skb->len - 4);
Steve Glendinningf7b29272008-11-20 04:19:21 -08001450 if (csum)
1451 tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001452 cpu_to_le32s(&tx_cmd_b);
1453 memcpy(skb->data, &tx_cmd_b, 4);
1454
1455 skb_push(skb, 4);
1456 tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
1457 TX_CMD_A_LAST_SEG_;
1458 cpu_to_le32s(&tx_cmd_a);
1459 memcpy(skb->data, &tx_cmd_a, 4);
1460
1461 return skb;
1462}
1463
1464static const struct driver_info smsc95xx_info = {
1465 .description = "smsc95xx USB 2.0 Ethernet",
1466 .bind = smsc95xx_bind,
1467 .unbind = smsc95xx_unbind,
1468 .link_reset = smsc95xx_link_reset,
1469 .reset = smsc95xx_reset,
1470 .rx_fixup = smsc95xx_rx_fixup,
1471 .tx_fixup = smsc95xx_tx_fixup,
1472 .status = smsc95xx_status,
Paolo Pisati07d69d42012-04-23 04:05:20 +00001473 .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001474};
1475
1476static const struct usb_device_id products[] = {
1477 {
1478 /* SMSC9500 USB Ethernet Device */
1479 USB_DEVICE(0x0424, 0x9500),
1480 .driver_info = (unsigned long) &smsc95xx_info,
1481 },
Steve Glendinning726474b2009-05-01 06:07:22 +00001482 {
Steve Glendinning6f41d122009-09-22 05:13:02 +00001483 /* SMSC9505 USB Ethernet Device */
1484 USB_DEVICE(0x0424, 0x9505),
1485 .driver_info = (unsigned long) &smsc95xx_info,
1486 },
1487 {
1488 /* SMSC9500A USB Ethernet Device */
1489 USB_DEVICE(0x0424, 0x9E00),
1490 .driver_info = (unsigned long) &smsc95xx_info,
1491 },
1492 {
1493 /* SMSC9505A USB Ethernet Device */
1494 USB_DEVICE(0x0424, 0x9E01),
1495 .driver_info = (unsigned long) &smsc95xx_info,
1496 },
1497 {
Steve Glendinning726474b2009-05-01 06:07:22 +00001498 /* SMSC9512/9514 USB Hub & Ethernet Device */
1499 USB_DEVICE(0x0424, 0xec00),
1500 .driver_info = (unsigned long) &smsc95xx_info,
1501 },
Steve Glendinning6f41d122009-09-22 05:13:02 +00001502 {
1503 /* SMSC9500 USB Ethernet Device (SAL10) */
1504 USB_DEVICE(0x0424, 0x9900),
1505 .driver_info = (unsigned long) &smsc95xx_info,
1506 },
1507 {
1508 /* SMSC9505 USB Ethernet Device (SAL10) */
1509 USB_DEVICE(0x0424, 0x9901),
1510 .driver_info = (unsigned long) &smsc95xx_info,
1511 },
1512 {
1513 /* SMSC9500A USB Ethernet Device (SAL10) */
1514 USB_DEVICE(0x0424, 0x9902),
1515 .driver_info = (unsigned long) &smsc95xx_info,
1516 },
1517 {
1518 /* SMSC9505A USB Ethernet Device (SAL10) */
1519 USB_DEVICE(0x0424, 0x9903),
1520 .driver_info = (unsigned long) &smsc95xx_info,
1521 },
1522 {
1523 /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
1524 USB_DEVICE(0x0424, 0x9904),
1525 .driver_info = (unsigned long) &smsc95xx_info,
1526 },
1527 {
1528 /* SMSC9500A USB Ethernet Device (HAL) */
1529 USB_DEVICE(0x0424, 0x9905),
1530 .driver_info = (unsigned long) &smsc95xx_info,
1531 },
1532 {
1533 /* SMSC9505A USB Ethernet Device (HAL) */
1534 USB_DEVICE(0x0424, 0x9906),
1535 .driver_info = (unsigned long) &smsc95xx_info,
1536 },
1537 {
1538 /* SMSC9500 USB Ethernet Device (Alternate ID) */
1539 USB_DEVICE(0x0424, 0x9907),
1540 .driver_info = (unsigned long) &smsc95xx_info,
1541 },
1542 {
1543 /* SMSC9500A USB Ethernet Device (Alternate ID) */
1544 USB_DEVICE(0x0424, 0x9908),
1545 .driver_info = (unsigned long) &smsc95xx_info,
1546 },
1547 {
1548 /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
1549 USB_DEVICE(0x0424, 0x9909),
1550 .driver_info = (unsigned long) &smsc95xx_info,
1551 },
Steve Glendinning88edaa42011-04-10 18:59:27 -07001552 {
1553 /* SMSC LAN9530 USB Ethernet Device */
1554 USB_DEVICE(0x0424, 0x9530),
1555 .driver_info = (unsigned long) &smsc95xx_info,
1556 },
1557 {
1558 /* SMSC LAN9730 USB Ethernet Device */
1559 USB_DEVICE(0x0424, 0x9730),
1560 .driver_info = (unsigned long) &smsc95xx_info,
1561 },
1562 {
1563 /* SMSC LAN89530 USB Ethernet Device */
1564 USB_DEVICE(0x0424, 0x9E08),
1565 .driver_info = (unsigned long) &smsc95xx_info,
1566 },
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001567 { }, /* END */
1568};
1569MODULE_DEVICE_TABLE(usb, products);
1570
1571static struct usb_driver smsc95xx_driver = {
1572 .name = "smsc95xx",
1573 .id_table = products,
1574 .probe = usbnet_probe,
Steve Glendinningb5a04472012-09-28 00:07:11 +00001575 .suspend = smsc95xx_suspend,
Steve Glendinninge0e474a82012-09-28 00:07:12 +00001576 .resume = smsc95xx_resume,
1577 .reset_resume = smsc95xx_resume,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001578 .disconnect = usbnet_disconnect,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -07001579 .disable_hub_initiated_lpm = 1,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001580};
1581
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08001582module_usb_driver(smsc95xx_driver);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001583
1584MODULE_AUTHOR("Nancy Lin");
Steve Glendinning90b24cf2012-04-16 12:13:29 +01001585MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001586MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
1587MODULE_LICENSE("GPL");