blob: d0ff01ee0b620a4574446ee2504d9355372cc73a [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>
29#include <linux/crc32.h>
30#include <linux/usb/usbnet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Steve Glendinning2f7ca802008-10-02 05:27:57 +000032#include "smsc95xx.h"
33
34#define SMSC_CHIPNAME "smsc95xx"
Steve Glendinningf7b29272008-11-20 04:19:21 -080035#define SMSC_DRIVER_VERSION "1.0.4"
Steve Glendinning2f7ca802008-10-02 05:27:57 +000036#define HS_USB_PKT_SIZE (512)
37#define FS_USB_PKT_SIZE (64)
38#define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
39#define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
40#define DEFAULT_BULK_IN_DELAY (0x00002000)
41#define MAX_SINGLE_PACKET_SIZE (2048)
42#define LAN95XX_EEPROM_MAGIC (0x9500)
43#define EEPROM_MAC_OFFSET (0x01)
Steve Glendinningf7b29272008-11-20 04:19:21 -080044#define DEFAULT_TX_CSUM_ENABLE (true)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000045#define DEFAULT_RX_CSUM_ENABLE (true)
46#define SMSC95XX_INTERNAL_PHY_ID (1)
47#define SMSC95XX_TX_OVERHEAD (8)
Steve Glendinningf7b29272008-11-20 04:19:21 -080048#define SMSC95XX_TX_OVERHEAD_CSUM (12)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000049
Steve Glendinning769ea6d2012-09-28 00:07:09 +000050#define check_warn(ret, fmt, args...) \
51 ({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); })
52
53#define check_warn_return(ret, fmt, args...) \
54 ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } })
55
56#define check_warn_goto_done(ret, fmt, args...) \
57 ({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } })
58
Steve Glendinning2f7ca802008-10-02 05:27:57 +000059struct smsc95xx_priv {
60 u32 mac_cr;
Marc Zyngier3c0f3c62011-03-18 03:53:58 +000061 u32 hash_hi;
62 u32 hash_lo;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000063 spinlock_t mac_cr_lock;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000064};
65
66struct usb_context {
67 struct usb_ctrlrequest req;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000068 struct usbnet *dev;
69};
70
Rusty Russelleb939922011-12-19 14:08:01 +000071static bool turbo_mode = true;
Steve Glendinning2f7ca802008-10-02 05:27:57 +000072module_param(turbo_mode, bool, 0644);
73MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
74
Steve Glendinning769ea6d2012-09-28 00:07:09 +000075static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
76 u32 *data)
Steve Glendinning2f7ca802008-10-02 05:27:57 +000077{
78 u32 *buf = kmalloc(4, GFP_KERNEL);
79 int ret;
80
81 BUG_ON(!dev);
82
83 if (!buf)
84 return -ENOMEM;
85
86 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
87 USB_VENDOR_REQUEST_READ_REGISTER,
88 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
89 00, index, buf, 4, USB_CTRL_GET_TIMEOUT);
90
91 if (unlikely(ret < 0))
Joe Perches60b86752010-02-17 10:30:23 +000092 netdev_warn(dev->net, "Failed to read register index 0x%08x\n", index);
Steve Glendinning2f7ca802008-10-02 05:27:57 +000093
94 le32_to_cpus(buf);
95 *data = *buf;
96 kfree(buf);
97
98 return ret;
99}
100
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000101static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
102 u32 data)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000103{
104 u32 *buf = kmalloc(4, GFP_KERNEL);
105 int ret;
106
107 BUG_ON(!dev);
108
109 if (!buf)
110 return -ENOMEM;
111
112 *buf = data;
113 cpu_to_le32s(buf);
114
115 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
116 USB_VENDOR_REQUEST_WRITE_REGISTER,
117 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
118 00, index, buf, 4, USB_CTRL_SET_TIMEOUT);
119
120 if (unlikely(ret < 0))
Joe Perches60b86752010-02-17 10:30:23 +0000121 netdev_warn(dev->net, "Failed to write register index 0x%08x\n", index);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000122
123 kfree(buf);
124
125 return ret;
126}
127
128/* Loop until the read is completed with timeout
129 * called with phy_mutex held */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000130static int __must_check smsc95xx_phy_wait_not_busy(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000131{
132 unsigned long start_time = jiffies;
133 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000134 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000135
136 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000137 ret = smsc95xx_read_reg(dev, MII_ADDR, &val);
138 check_warn_return(ret, "Error reading MII_ACCESS");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000139 if (!(val & MII_BUSY_))
140 return 0;
141 } while (!time_after(jiffies, start_time + HZ));
142
143 return -EIO;
144}
145
146static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
147{
148 struct usbnet *dev = netdev_priv(netdev);
149 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000150 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000151
152 mutex_lock(&dev->phy_mutex);
153
154 /* confirm MII not busy */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000155 ret = smsc95xx_phy_wait_not_busy(dev);
156 check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_read");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000157
158 /* set the address, index & direction (read from PHY) */
159 phy_id &= dev->mii.phy_id_mask;
160 idx &= dev->mii.reg_num_mask;
161 addr = (phy_id << 11) | (idx << 6) | MII_READ_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000162 ret = smsc95xx_write_reg(dev, MII_ADDR, addr);
163 check_warn_goto_done(ret, "Error writing MII_ADDR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000164
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000165 ret = smsc95xx_phy_wait_not_busy(dev);
166 check_warn_goto_done(ret, "Timed out reading MII reg %02X", idx);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000167
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000168 ret = smsc95xx_read_reg(dev, MII_DATA, &val);
169 check_warn_goto_done(ret, "Error reading MII_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000170
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000171 ret = (u16)(val & 0xFFFF);
172
173done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000174 mutex_unlock(&dev->phy_mutex);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000175 return ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000176}
177
178static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
179 int regval)
180{
181 struct usbnet *dev = netdev_priv(netdev);
182 u32 val, addr;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000183 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000184
185 mutex_lock(&dev->phy_mutex);
186
187 /* confirm MII not busy */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000188 ret = smsc95xx_phy_wait_not_busy(dev);
189 check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_write");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000190
191 val = regval;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000192 ret = smsc95xx_write_reg(dev, MII_DATA, val);
193 check_warn_goto_done(ret, "Error writing MII_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000194
195 /* set the address, index & direction (write to PHY) */
196 phy_id &= dev->mii.phy_id_mask;
197 idx &= dev->mii.reg_num_mask;
198 addr = (phy_id << 11) | (idx << 6) | MII_WRITE_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000199 ret = smsc95xx_write_reg(dev, MII_ADDR, addr);
200 check_warn_goto_done(ret, "Error writing MII_ADDR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000201
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000202 ret = smsc95xx_phy_wait_not_busy(dev);
203 check_warn_goto_done(ret, "Timed out writing MII reg %02X", idx);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000204
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000205done:
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000206 mutex_unlock(&dev->phy_mutex);
207}
208
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000209static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000210{
211 unsigned long start_time = jiffies;
212 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000213 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000214
215 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000216 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
217 check_warn_return(ret, "Error reading E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000218 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
219 break;
220 udelay(40);
221 } while (!time_after(jiffies, start_time + HZ));
222
223 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
Joe Perches60b86752010-02-17 10:30:23 +0000224 netdev_warn(dev->net, "EEPROM read operation timeout\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000225 return -EIO;
226 }
227
228 return 0;
229}
230
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000231static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000232{
233 unsigned long start_time = jiffies;
234 u32 val;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000235 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000236
237 do {
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000238 ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
239 check_warn_return(ret, "Error reading E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000240
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000241 if (!(val & E2P_CMD_BUSY_))
242 return 0;
243
244 udelay(40);
245 } while (!time_after(jiffies, start_time + HZ));
246
Joe Perches60b86752010-02-17 10:30:23 +0000247 netdev_warn(dev->net, "EEPROM is busy\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000248 return -EIO;
249}
250
251static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
252 u8 *data)
253{
254 u32 val;
255 int i, ret;
256
257 BUG_ON(!dev);
258 BUG_ON(!data);
259
260 ret = smsc95xx_eeprom_confirm_not_busy(dev);
261 if (ret)
262 return ret;
263
264 for (i = 0; i < length; i++) {
265 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000266 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
267 check_warn_return(ret, "Error writing E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000268
269 ret = smsc95xx_wait_eeprom(dev);
270 if (ret < 0)
271 return ret;
272
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000273 ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
274 check_warn_return(ret, "Error reading E2P_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000275
276 data[i] = val & 0xFF;
277 offset++;
278 }
279
280 return 0;
281}
282
283static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
284 u8 *data)
285{
286 u32 val;
287 int i, ret;
288
289 BUG_ON(!dev);
290 BUG_ON(!data);
291
292 ret = smsc95xx_eeprom_confirm_not_busy(dev);
293 if (ret)
294 return ret;
295
296 /* Issue write/erase enable command */
297 val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000298 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
299 check_warn_return(ret, "Error writing E2P_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000300
301 ret = smsc95xx_wait_eeprom(dev);
302 if (ret < 0)
303 return ret;
304
305 for (i = 0; i < length; i++) {
306
307 /* Fill data register */
308 val = data[i];
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000309 ret = smsc95xx_write_reg(dev, E2P_DATA, val);
310 check_warn_return(ret, "Error writing E2P_DATA");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000311
312 /* Send "write" command */
313 val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000314 ret = smsc95xx_write_reg(dev, E2P_CMD, val);
315 check_warn_return(ret, "Error writing E2P_CMD");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000316
317 ret = smsc95xx_wait_eeprom(dev);
318 if (ret < 0)
319 return ret;
320
321 offset++;
322 }
323
324 return 0;
325}
326
Steve Glendinning150a7fc2009-01-25 17:54:46 -0800327static void smsc95xx_async_cmd_callback(struct urb *urb)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000328{
329 struct usb_context *usb_context = urb->context;
330 struct usbnet *dev = usb_context->dev;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800331 int status = urb->status;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000332
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000333 check_warn(status, "async callback failed with %d\n", status);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000334
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000335 kfree(usb_context);
336 usb_free_urb(urb);
337}
338
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000339static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
340 u32 *data)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000341{
342 struct usb_context *usb_context;
343 int status;
344 struct urb *urb;
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700345 const u16 size = 4;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000346
347 urb = usb_alloc_urb(0, GFP_ATOMIC);
348 if (!urb) {
Joe Perches60b86752010-02-17 10:30:23 +0000349 netdev_warn(dev->net, "Error allocating URB\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000350 return -ENOMEM;
351 }
352
353 usb_context = kmalloc(sizeof(struct usb_context), GFP_ATOMIC);
354 if (usb_context == NULL) {
Joe Perches60b86752010-02-17 10:30:23 +0000355 netdev_warn(dev->net, "Error allocating control msg\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000356 usb_free_urb(urb);
357 return -ENOMEM;
358 }
359
360 usb_context->req.bRequestType =
361 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
362 usb_context->req.bRequest = USB_VENDOR_REQUEST_WRITE_REGISTER;
363 usb_context->req.wValue = 00;
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700364 usb_context->req.wIndex = cpu_to_le16(index);
365 usb_context->req.wLength = cpu_to_le16(size);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000366
367 usb_fill_control_urb(urb, dev->udev, usb_sndctrlpipe(dev->udev, 0),
368 (void *)&usb_context->req, data, size,
Steve Glendinning150a7fc2009-01-25 17:54:46 -0800369 smsc95xx_async_cmd_callback,
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000370 (void *)usb_context);
371
372 status = usb_submit_urb(urb, GFP_ATOMIC);
373 if (status < 0) {
Joe Perches60b86752010-02-17 10:30:23 +0000374 netdev_warn(dev->net, "Error submitting control msg, sts=%d\n",
375 status);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000376 kfree(usb_context);
377 usb_free_urb(urb);
378 }
379
380 return status;
381}
382
383/* returns hash bit number for given MAC address
384 * example:
385 * 01 00 5E 00 00 01 -> returns bit number 31 */
386static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
387{
388 return (ether_crc(ETH_ALEN, addr) >> 26) & 0x3f;
389}
390
391static void smsc95xx_set_multicast(struct net_device *netdev)
392{
393 struct usbnet *dev = netdev_priv(netdev);
394 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000395 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000396 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000397
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000398 pdata->hash_hi = 0;
399 pdata->hash_lo = 0;
400
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000401 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
402
403 if (dev->net->flags & IFF_PROMISC) {
Joe Perchesa475f602010-02-17 10:30:24 +0000404 netif_dbg(dev, drv, dev->net, "promiscuous mode enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000405 pdata->mac_cr |= MAC_CR_PRMS_;
406 pdata->mac_cr &= ~(MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
407 } else if (dev->net->flags & IFF_ALLMULTI) {
Joe Perchesa475f602010-02-17 10:30:24 +0000408 netif_dbg(dev, drv, dev->net, "receive all multicast enabled\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000409 pdata->mac_cr |= MAC_CR_MCPAS_;
410 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000411 } else if (!netdev_mc_empty(dev->net)) {
Jiri Pirko22bedad32010-04-01 21:22:57 +0000412 struct netdev_hw_addr *ha;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000413
414 pdata->mac_cr |= MAC_CR_HPFILT_;
415 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
416
Jiri Pirko22bedad32010-04-01 21:22:57 +0000417 netdev_for_each_mc_addr(ha, netdev) {
418 u32 bitnum = smsc95xx_hash(ha->addr);
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000419 u32 mask = 0x01 << (bitnum & 0x1F);
420 if (bitnum & 0x20)
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000421 pdata->hash_hi |= mask;
Jiri Pirkoa92635d2010-02-18 04:02:26 +0000422 else
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000423 pdata->hash_lo |= mask;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000424 }
425
Joe Perchesa475f602010-02-17 10:30:24 +0000426 netif_dbg(dev, drv, dev->net, "HASHH=0x%08X, HASHL=0x%08X\n",
Marc Zyngier3c0f3c62011-03-18 03:53:58 +0000427 pdata->hash_hi, pdata->hash_lo);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000428 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000429 netif_dbg(dev, drv, dev->net, "receive own packets only\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000430 pdata->mac_cr &=
431 ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
432 }
433
434 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
435
436 /* Initiate async writes, as we can't wait for completion here */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000437 ret = smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi);
438 check_warn(ret, "failed to initiate async write to HASHH");
439
440 ret = smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo);
441 check_warn(ret, "failed to initiate async write to HASHL");
442
443 ret = smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr);
444 check_warn(ret, "failed to initiate async write to MAC_CR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000445}
446
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000447static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
448 u16 lcladv, u16 rmtadv)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000449{
450 u32 flow, afc_cfg = 0;
451
452 int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000453 check_warn_return(ret, "Error reading AFC_CFG");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000454
455 if (duplex == DUPLEX_FULL) {
Steve Glendinningbc02ff92008-12-16 02:00:48 -0800456 u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000457
458 if (cap & FLOW_CTRL_RX)
459 flow = 0xFFFF0002;
460 else
461 flow = 0;
462
463 if (cap & FLOW_CTRL_TX)
464 afc_cfg |= 0xF;
465 else
466 afc_cfg &= ~0xF;
467
Joe Perchesa475f602010-02-17 10:30:24 +0000468 netif_dbg(dev, link, dev->net, "rx pause %s, tx pause %s\n",
Joe Perches60b86752010-02-17 10:30:23 +0000469 cap & FLOW_CTRL_RX ? "enabled" : "disabled",
470 cap & FLOW_CTRL_TX ? "enabled" : "disabled");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000471 } else {
Joe Perchesa475f602010-02-17 10:30:24 +0000472 netif_dbg(dev, link, dev->net, "half duplex\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000473 flow = 0;
474 afc_cfg |= 0xF;
475 }
476
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000477 ret = smsc95xx_write_reg(dev, FLOW, flow);
478 check_warn_return(ret, "Error writing FLOW");
479
480 ret = smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
481 check_warn_return(ret, "Error writing AFC_CFG");
482
483 return 0;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000484}
485
486static int smsc95xx_link_reset(struct usbnet *dev)
487{
488 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
489 struct mii_if_info *mii = &dev->mii;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000490 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000491 unsigned long flags;
492 u16 lcladv, rmtadv;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000493 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000494
495 /* clear interrupt status */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000496 ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
497 check_warn_return(ret, "Error reading PHY_INT_SRC");
498
499 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
500 check_warn_return(ret, "Error writing INT_STS");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000501
502 mii_check_media(mii, 1, 1);
503 mii_ethtool_gset(&dev->mii, &ecmd);
504 lcladv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_ADVERTISE);
505 rmtadv = smsc95xx_mdio_read(dev->net, mii->phy_id, MII_LPA);
506
David Decotigny8ae6daca2011-04-27 18:32:38 +0000507 netif_dbg(dev, link, dev->net,
508 "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
509 ethtool_cmd_speed(&ecmd), ecmd.duplex, lcladv, rmtadv);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000510
511 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
512 if (ecmd.duplex != DUPLEX_FULL) {
513 pdata->mac_cr &= ~MAC_CR_FDPX_;
514 pdata->mac_cr |= MAC_CR_RCVOWN_;
515 } else {
516 pdata->mac_cr &= ~MAC_CR_RCVOWN_;
517 pdata->mac_cr |= MAC_CR_FDPX_;
518 }
519 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
520
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000521 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
522 check_warn_return(ret, "Error writing MAC_CR");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000523
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000524 ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
525 check_warn_return(ret, "Error updating PHY flow control");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000526
527 return 0;
528}
529
530static void smsc95xx_status(struct usbnet *dev, struct urb *urb)
531{
532 u32 intdata;
533
534 if (urb->actual_length != 4) {
Joe Perches60b86752010-02-17 10:30:23 +0000535 netdev_warn(dev->net, "unexpected urb length %d\n",
536 urb->actual_length);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000537 return;
538 }
539
540 memcpy(&intdata, urb->transfer_buffer, 4);
Steve Glendinning1d74a6b2008-10-09 14:34:47 -0700541 le32_to_cpus(&intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000542
Joe Perchesa475f602010-02-17 10:30:24 +0000543 netif_dbg(dev, link, dev->net, "intdata: 0x%08X\n", intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000544
545 if (intdata & INT_ENP_PHY_INT_)
546 usbnet_defer_kevent(dev, EVENT_LINK_RESET);
547 else
Joe Perches60b86752010-02-17 10:30:23 +0000548 netdev_warn(dev->net, "unexpected interrupt, intdata=0x%08X\n",
549 intdata);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000550}
551
Steve Glendinningf7b29272008-11-20 04:19:21 -0800552/* Enable or disable Tx & Rx checksum offload engines */
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000553static int smsc95xx_set_features(struct net_device *netdev,
554 netdev_features_t features)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000555{
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700556 struct usbnet *dev = netdev_priv(netdev);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000557 u32 read_buf;
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700558 int ret;
559
560 ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000561 check_warn_return(ret, "Failed to read COE_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000562
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700563 if (features & NETIF_F_HW_CSUM)
Steve Glendinningf7b29272008-11-20 04:19:21 -0800564 read_buf |= Tx_COE_EN_;
565 else
566 read_buf &= ~Tx_COE_EN_;
567
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700568 if (features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000569 read_buf |= Rx_COE_EN_;
570 else
571 read_buf &= ~Rx_COE_EN_;
572
573 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000574 check_warn_return(ret, "Failed to write COE_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000575
Joe Perchesa475f602010-02-17 10:30:24 +0000576 netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000577 return 0;
578}
579
580static int smsc95xx_ethtool_get_eeprom_len(struct net_device *net)
581{
582 return MAX_EEPROM_SIZE;
583}
584
585static int smsc95xx_ethtool_get_eeprom(struct net_device *netdev,
586 struct ethtool_eeprom *ee, u8 *data)
587{
588 struct usbnet *dev = netdev_priv(netdev);
589
590 ee->magic = LAN95XX_EEPROM_MAGIC;
591
592 return smsc95xx_read_eeprom(dev, ee->offset, ee->len, data);
593}
594
595static int smsc95xx_ethtool_set_eeprom(struct net_device *netdev,
596 struct ethtool_eeprom *ee, u8 *data)
597{
598 struct usbnet *dev = netdev_priv(netdev);
599
600 if (ee->magic != LAN95XX_EEPROM_MAGIC) {
Joe Perches60b86752010-02-17 10:30:23 +0000601 netdev_warn(dev->net, "EEPROM: magic value mismatch, magic = 0x%x\n",
602 ee->magic);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000603 return -EINVAL;
604 }
605
606 return smsc95xx_write_eeprom(dev, ee->offset, ee->len, data);
607}
608
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400609static int smsc95xx_ethtool_getregslen(struct net_device *netdev)
610{
611 /* all smsc95xx registers */
612 return COE_CR - ID_REV + 1;
613}
614
615static void
616smsc95xx_ethtool_getregs(struct net_device *netdev, struct ethtool_regs *regs,
617 void *buf)
618{
619 struct usbnet *dev = netdev_priv(netdev);
Dan Carpenterd3484462012-07-10 20:32:51 +0000620 unsigned int i, j;
621 int retval;
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400622 u32 *data = buf;
623
624 retval = smsc95xx_read_reg(dev, ID_REV, &regs->version);
625 if (retval < 0) {
626 netdev_warn(netdev, "REGS: cannot read ID_REV\n");
627 return;
628 }
629
630 for (i = ID_REV, j = 0; i <= COE_CR; i += (sizeof(u32)), j++) {
631 retval = smsc95xx_read_reg(dev, i, &data[j]);
632 if (retval < 0) {
633 netdev_warn(netdev, "REGS: cannot read reg[%x]\n", i);
634 return;
635 }
636 }
637}
638
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700639static const struct ethtool_ops smsc95xx_ethtool_ops = {
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000640 .get_link = usbnet_get_link,
641 .nway_reset = usbnet_nway_reset,
642 .get_drvinfo = usbnet_get_drvinfo,
643 .get_msglevel = usbnet_get_msglevel,
644 .set_msglevel = usbnet_set_msglevel,
645 .get_settings = usbnet_get_settings,
646 .set_settings = usbnet_set_settings,
647 .get_eeprom_len = smsc95xx_ethtool_get_eeprom_len,
648 .get_eeprom = smsc95xx_ethtool_get_eeprom,
649 .set_eeprom = smsc95xx_ethtool_set_eeprom,
Emeric Vigier9fa32e92012-07-09 17:44:45 -0400650 .get_regs_len = smsc95xx_ethtool_getregslen,
651 .get_regs = smsc95xx_ethtool_getregs,
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000652};
653
654static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
655{
656 struct usbnet *dev = netdev_priv(netdev);
657
658 if (!netif_running(netdev))
659 return -EINVAL;
660
661 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
662}
663
664static void smsc95xx_init_mac_address(struct usbnet *dev)
665{
666 /* try reading mac address from EEPROM */
667 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
668 dev->net->dev_addr) == 0) {
669 if (is_valid_ether_addr(dev->net->dev_addr)) {
670 /* eeprom values are valid so use them */
Joe Perchesa475f602010-02-17 10:30:24 +0000671 netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000672 return;
673 }
674 }
675
676 /* no eeprom, or eeprom values are invalid. generate random MAC */
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000677 eth_hw_addr_random(dev->net);
Joe Perchesc7e12ea2012-07-12 19:33:07 +0000678 netif_dbg(dev, ifup, dev->net, "MAC address set to eth_random_addr\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000679}
680
681static int smsc95xx_set_mac_address(struct usbnet *dev)
682{
683 u32 addr_lo = dev->net->dev_addr[0] | dev->net->dev_addr[1] << 8 |
684 dev->net->dev_addr[2] << 16 | dev->net->dev_addr[3] << 24;
685 u32 addr_hi = dev->net->dev_addr[4] | dev->net->dev_addr[5] << 8;
686 int ret;
687
688 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000689 check_warn_return(ret, "Failed to write ADDRL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000690
691 ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000692 check_warn_return(ret, "Failed to write ADDRH: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000693
694 return 0;
695}
696
697/* starts the TX path */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000698static int smsc95xx_start_tx_path(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000699{
700 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
701 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000702 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000703
704 /* Enable Tx at MAC */
705 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
706 pdata->mac_cr |= MAC_CR_TXEN_;
707 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
708
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000709 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
710 check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000711
712 /* Enable Tx at SCSRs */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000713 ret = smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
714 check_warn_return(ret, "Failed to write TX_CFG: %d\n", ret);
715
716 return 0;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000717}
718
719/* Starts the Receive path */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000720static int smsc95xx_start_rx_path(struct usbnet *dev)
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000721{
722 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
723 unsigned long flags;
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000724 int ret;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000725
726 spin_lock_irqsave(&pdata->mac_cr_lock, flags);
727 pdata->mac_cr |= MAC_CR_RXEN_;
728 spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
729
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000730 ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
731 check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
732
733 return 0;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000734}
735
736static int smsc95xx_phy_initialize(struct usbnet *dev)
737{
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000738 int bmcr, ret, timeout = 0;
Steve Glendinningdb443c42010-03-16 09:03:06 +0000739
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000740 /* Initialize MII structure */
741 dev->mii.dev = dev->net;
742 dev->mii.mdio_read = smsc95xx_mdio_read;
743 dev->mii.mdio_write = smsc95xx_mdio_write;
744 dev->mii.phy_id_mask = 0x1f;
745 dev->mii.reg_num_mask = 0x1f;
746 dev->mii.phy_id = SMSC95XX_INTERNAL_PHY_ID;
747
Steve Glendinningdb443c42010-03-16 09:03:06 +0000748 /* reset phy and wait for reset to complete */
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000749 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
Steve Glendinningdb443c42010-03-16 09:03:06 +0000750
751 do {
752 msleep(10);
753 bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR);
754 timeout++;
Rabin Vincentd9460922011-04-30 08:29:27 +0000755 } while ((bmcr & BMCR_RESET) && (timeout < 100));
Steve Glendinningdb443c42010-03-16 09:03:06 +0000756
757 if (timeout >= 100) {
758 netdev_warn(dev->net, "timeout on PHY Reset");
759 return -EIO;
760 }
761
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000762 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
763 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
764 ADVERTISE_PAUSE_ASYM);
765
766 /* read to clear */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000767 ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
768 check_warn_return(ret, "Failed to read PHY_INT_SRC during init");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000769
770 smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
771 PHY_INT_MASK_DEFAULT_);
772 mii_nway_restart(&dev->mii);
773
Joe Perchesa475f602010-02-17 10:30:24 +0000774 netif_dbg(dev, ifup, dev->net, "phy initialised successfully\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000775 return 0;
776}
777
778static int smsc95xx_reset(struct usbnet *dev)
779{
780 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
781 u32 read_buf, write_buf, burst_cap;
782 int ret = 0, timeout;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000783
Joe Perchesa475f602010-02-17 10:30:24 +0000784 netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000785
Steve Glendinning44367612012-09-28 00:07:08 +0000786 ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000787 check_warn_return(ret, "Failed to write HW_CFG_LRST_ bit in HW_CFG\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000788
789 timeout = 0;
790 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000791 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000792 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000793 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000794 timeout++;
795 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
796
797 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000798 netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000799 return ret;
800 }
801
Steve Glendinning44367612012-09-28 00:07:08 +0000802 ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000803 check_warn_return(ret, "Failed to write PM_CTRL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000804
805 timeout = 0;
806 do {
Steve Glendinningcf2acec2012-09-28 00:07:07 +0000807 msleep(10);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000808 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000809 check_warn_return(ret, "Failed to read PM_CTRL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000810 timeout++;
811 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
812
813 if (timeout >= 100) {
Joe Perches60b86752010-02-17 10:30:23 +0000814 netdev_warn(dev->net, "timeout waiting for PHY Reset\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000815 return ret;
816 }
817
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000818 ret = smsc95xx_set_mac_address(dev);
819 if (ret < 0)
820 return ret;
821
Joe Perchesa475f602010-02-17 10:30:24 +0000822 netif_dbg(dev, ifup, dev->net,
823 "MAC Address: %pM\n", dev->net->dev_addr);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000824
825 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000826 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000827
Joe Perchesa475f602010-02-17 10:30:24 +0000828 netif_dbg(dev, ifup, dev->net,
829 "Read Value from HW_CFG : 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000830
831 read_buf |= HW_CFG_BIR_;
832
833 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000834 check_warn_return(ret, "Failed to write HW_CFG_BIR_ bit in HW_CFG\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000835
836 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000837 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
Joe Perchesa475f602010-02-17 10:30:24 +0000838 netif_dbg(dev, ifup, dev->net,
839 "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
840 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000841
842 if (!turbo_mode) {
843 burst_cap = 0;
844 dev->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
845 } else if (dev->udev->speed == USB_SPEED_HIGH) {
846 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
847 dev->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
848 } else {
849 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
850 dev->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
851 }
852
Joe Perchesa475f602010-02-17 10:30:24 +0000853 netif_dbg(dev, ifup, dev->net,
854 "rx_urb_size=%ld\n", (ulong)dev->rx_urb_size);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000855
856 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000857 check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000858
859 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000860 check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret);
861
Joe Perchesa475f602010-02-17 10:30:24 +0000862 netif_dbg(dev, ifup, dev->net,
863 "Read Value from BURST_CAP after writing: 0x%08x\n",
864 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000865
Steve Glendinning44367612012-09-28 00:07:08 +0000866 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000867 check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000868
869 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000870 check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret);
871
Joe Perchesa475f602010-02-17 10:30:24 +0000872 netif_dbg(dev, ifup, dev->net,
873 "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
874 read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000875
876 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000877 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
878
Joe Perchesa475f602010-02-17 10:30:24 +0000879 netif_dbg(dev, ifup, dev->net,
880 "Read Value from HW_CFG: 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000881
882 if (turbo_mode)
883 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
884
885 read_buf &= ~HW_CFG_RXDOFF_;
886
887 /* set Rx data offset=2, Make IP header aligns on word boundary. */
888 read_buf |= NET_IP_ALIGN << 9;
889
890 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000891 check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000892
893 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000894 check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
895
Joe Perchesa475f602010-02-17 10:30:24 +0000896 netif_dbg(dev, ifup, dev->net,
897 "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000898
Steve Glendinning44367612012-09-28 00:07:08 +0000899 ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000900 check_warn_return(ret, "Failed to write INT_STS: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000901
902 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000903 check_warn_return(ret, "Failed to read ID_REV: %d\n", ret);
Joe Perchesa475f602010-02-17 10:30:24 +0000904 netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000905
Steve Glendinningf2935012009-05-01 05:46:51 +0000906 /* Configure GPIO pins as LED outputs */
907 write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
908 LED_GPIO_CFG_FDX_LED;
909 ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000910 check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n", ret);
Steve Glendinningf2935012009-05-01 05:46:51 +0000911
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000912 /* Init Tx */
Steve Glendinning44367612012-09-28 00:07:08 +0000913 ret = smsc95xx_write_reg(dev, FLOW, 0);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000914 check_warn_return(ret, "Failed to write FLOW: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000915
Steve Glendinning44367612012-09-28 00:07:08 +0000916 ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000917 check_warn_return(ret, "Failed to write AFC_CFG: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000918
919 /* Don't need mac_cr_lock during initialisation */
920 ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000921 check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000922
923 /* Init Rx */
924 /* Set Vlan */
Steve Glendinning44367612012-09-28 00:07:08 +0000925 ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000926 check_warn_return(ret, "Failed to write VLAN1: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000927
Steve Glendinningf7b29272008-11-20 04:19:21 -0800928 /* Enable or disable checksum offload engines */
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000929 ret = smsc95xx_set_features(dev->net, dev->net->features);
930 check_warn_return(ret, "Failed to set checksum offload features");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000931
932 smsc95xx_set_multicast(dev->net);
933
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000934 ret = smsc95xx_phy_initialize(dev);
935 check_warn_return(ret, "Failed to init PHY");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000936
937 ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000938 check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000939
940 /* enable PHY interrupts */
941 read_buf |= INT_EP_CTL_PHY_INT_;
942
943 ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000944 check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000945
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000946 ret = smsc95xx_start_tx_path(dev);
947 check_warn_return(ret, "Failed to start TX path");
948
949 ret = smsc95xx_start_rx_path(dev);
950 check_warn_return(ret, "Failed to start RX path");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000951
Joe Perchesa475f602010-02-17 10:30:24 +0000952 netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000953 return 0;
954}
955
Stephen Hemminger63e77b32009-03-20 19:35:58 +0000956static const struct net_device_ops smsc95xx_netdev_ops = {
957 .ndo_open = usbnet_open,
958 .ndo_stop = usbnet_stop,
959 .ndo_start_xmit = usbnet_start_xmit,
960 .ndo_tx_timeout = usbnet_tx_timeout,
961 .ndo_change_mtu = usbnet_change_mtu,
962 .ndo_set_mac_address = eth_mac_addr,
963 .ndo_validate_addr = eth_validate_addr,
964 .ndo_do_ioctl = smsc95xx_ioctl,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000965 .ndo_set_rx_mode = smsc95xx_set_multicast,
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700966 .ndo_set_features = smsc95xx_set_features,
Stephen Hemminger63e77b32009-03-20 19:35:58 +0000967};
968
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000969static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
970{
971 struct smsc95xx_priv *pdata = NULL;
972 int ret;
973
974 printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
975
976 ret = usbnet_get_endpoints(dev, intf);
Steve Glendinning769ea6d2012-09-28 00:07:09 +0000977 check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret);
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000978
979 dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
980 GFP_KERNEL);
981
982 pdata = (struct smsc95xx_priv *)(dev->data[0]);
983 if (!pdata) {
Joe Perches60b86752010-02-17 10:30:23 +0000984 netdev_warn(dev->net, "Unable to allocate struct smsc95xx_priv\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000985 return -ENOMEM;
986 }
987
988 spin_lock_init(&pdata->mac_cr_lock);
989
Michał Mirosław78e47fe2011-04-01 20:56:23 -0700990 if (DEFAULT_TX_CSUM_ENABLE)
991 dev->net->features |= NETIF_F_HW_CSUM;
992 if (DEFAULT_RX_CSUM_ENABLE)
993 dev->net->features |= NETIF_F_RXCSUM;
994
995 dev->net->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000996
Bernard Blackhamf4e8ab72010-10-18 13:16:39 +0000997 smsc95xx_init_mac_address(dev);
998
Steve Glendinning2f7ca802008-10-02 05:27:57 +0000999 /* Init all registers */
1000 ret = smsc95xx_reset(dev);
1001
Stephen Hemminger63e77b32009-03-20 19:35:58 +00001002 dev->net->netdev_ops = &smsc95xx_netdev_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001003 dev->net->ethtool_ops = &smsc95xx_ethtool_ops;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001004 dev->net->flags |= IFF_MULTICAST;
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001005 dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
Stephane Fillod9bbf5662012-04-20 09:39:23 +00001006 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001007 return 0;
1008}
1009
1010static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
1011{
1012 struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
1013 if (pdata) {
Joe Perchesa475f602010-02-17 10:30:24 +00001014 netif_dbg(dev, ifdown, dev->net, "free pdata\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001015 kfree(pdata);
1016 pdata = NULL;
1017 dev->data[0] = 0;
1018 }
1019}
1020
1021static void smsc95xx_rx_csum_offload(struct sk_buff *skb)
1022{
1023 skb->csum = *(u16 *)(skb_tail_pointer(skb) - 2);
1024 skb->ip_summed = CHECKSUM_COMPLETE;
1025 skb_trim(skb, skb->len - 2);
1026}
1027
1028static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1029{
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001030 while (skb->len > 0) {
1031 u32 header, align_count;
1032 struct sk_buff *ax_skb;
1033 unsigned char *packet;
1034 u16 size;
1035
1036 memcpy(&header, skb->data, sizeof(header));
1037 le32_to_cpus(&header);
1038 skb_pull(skb, 4 + NET_IP_ALIGN);
1039 packet = skb->data;
1040
1041 /* get the packet length */
1042 size = (u16)((header & RX_STS_FL_) >> 16);
1043 align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
1044
1045 if (unlikely(header & RX_STS_ES_)) {
Joe Perchesa475f602010-02-17 10:30:24 +00001046 netif_dbg(dev, rx_err, dev->net,
1047 "Error header=0x%08x\n", header);
Herbert Xu80667ac2009-06-29 16:53:00 +00001048 dev->net->stats.rx_errors++;
1049 dev->net->stats.rx_dropped++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001050
1051 if (header & RX_STS_CRC_) {
Herbert Xu80667ac2009-06-29 16:53:00 +00001052 dev->net->stats.rx_crc_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001053 } else {
1054 if (header & (RX_STS_TL_ | RX_STS_RF_))
Herbert Xu80667ac2009-06-29 16:53:00 +00001055 dev->net->stats.rx_frame_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001056
1057 if ((header & RX_STS_LE_) &&
1058 (!(header & RX_STS_FT_)))
Herbert Xu80667ac2009-06-29 16:53:00 +00001059 dev->net->stats.rx_length_errors++;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001060 }
1061 } else {
1062 /* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
1063 if (unlikely(size > (ETH_FRAME_LEN + 12))) {
Joe Perchesa475f602010-02-17 10:30:24 +00001064 netif_dbg(dev, rx_err, dev->net,
1065 "size err header=0x%08x\n", header);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001066 return 0;
1067 }
1068
1069 /* last frame in this batch */
1070 if (skb->len == size) {
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001071 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001072 smsc95xx_rx_csum_offload(skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001073 skb_trim(skb, skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001074 skb->truesize = size + sizeof(struct sk_buff);
1075
1076 return 1;
1077 }
1078
1079 ax_skb = skb_clone(skb, GFP_ATOMIC);
1080 if (unlikely(!ax_skb)) {
Joe Perches60b86752010-02-17 10:30:23 +00001081 netdev_warn(dev->net, "Error allocating skb\n");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001082 return 0;
1083 }
1084
1085 ax_skb->len = size;
1086 ax_skb->data = packet;
1087 skb_set_tail_pointer(ax_skb, size);
1088
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001089 if (dev->net->features & NETIF_F_RXCSUM)
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001090 smsc95xx_rx_csum_offload(ax_skb);
Peter Korsgaarddf18acc2009-05-13 10:10:41 +00001091 skb_trim(ax_skb, ax_skb->len - 4); /* remove fcs */
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001092 ax_skb->truesize = size + sizeof(struct sk_buff);
1093
1094 usbnet_skb_return(dev, ax_skb);
1095 }
1096
1097 skb_pull(skb, size);
1098
1099 /* padding bytes before the next frame starts */
1100 if (skb->len)
1101 skb_pull(skb, align_count);
1102 }
1103
1104 if (unlikely(skb->len < 0)) {
Joe Perches60b86752010-02-17 10:30:23 +00001105 netdev_warn(dev->net, "invalid rx length<0 %d\n", skb->len);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001106 return 0;
1107 }
1108
1109 return 1;
1110}
1111
Steve Glendinningf7b29272008-11-20 04:19:21 -08001112static u32 smsc95xx_calc_csum_preamble(struct sk_buff *skb)
1113{
Michał Mirosław55508d62010-12-14 15:24:08 +00001114 u16 low_16 = (u16)skb_checksum_start_offset(skb);
1115 u16 high_16 = low_16 + skb->csum_offset;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001116 return (high_16 << 16) | low_16;
1117}
1118
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001119static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,
1120 struct sk_buff *skb, gfp_t flags)
1121{
Michał Mirosław78e47fe2011-04-01 20:56:23 -07001122 bool csum = skb->ip_summed == CHECKSUM_PARTIAL;
Steve Glendinningf7b29272008-11-20 04:19:21 -08001123 int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001124 u32 tx_cmd_a, tx_cmd_b;
1125
Steve Glendinningf7b29272008-11-20 04:19:21 -08001126 /* We do not advertise SG, so skbs should be already linearized */
1127 BUG_ON(skb_shinfo(skb)->nr_frags);
1128
1129 if (skb_headroom(skb) < overhead) {
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001130 struct sk_buff *skb2 = skb_copy_expand(skb,
Steve Glendinningf7b29272008-11-20 04:19:21 -08001131 overhead, 0, flags);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001132 dev_kfree_skb_any(skb);
1133 skb = skb2;
1134 if (!skb)
1135 return NULL;
1136 }
1137
Steve Glendinningf7b29272008-11-20 04:19:21 -08001138 if (csum) {
Steve Glendinning11bc3082010-03-18 22:18:41 -07001139 if (skb->len <= 45) {
1140 /* workaround - hardware tx checksum does not work
1141 * properly with extremely small packets */
Michał Mirosław55508d62010-12-14 15:24:08 +00001142 long csstart = skb_checksum_start_offset(skb);
Steve Glendinning11bc3082010-03-18 22:18:41 -07001143 __wsum calc = csum_partial(skb->data + csstart,
1144 skb->len - csstart, 0);
1145 *((__sum16 *)(skb->data + csstart
1146 + skb->csum_offset)) = csum_fold(calc);
1147
1148 csum = false;
1149 } else {
1150 u32 csum_preamble = smsc95xx_calc_csum_preamble(skb);
1151 skb_push(skb, 4);
1152 memcpy(skb->data, &csum_preamble, 4);
1153 }
Steve Glendinningf7b29272008-11-20 04:19:21 -08001154 }
1155
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001156 skb_push(skb, 4);
1157 tx_cmd_b = (u32)(skb->len - 4);
Steve Glendinningf7b29272008-11-20 04:19:21 -08001158 if (csum)
1159 tx_cmd_b |= TX_CMD_B_CSUM_ENABLE;
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001160 cpu_to_le32s(&tx_cmd_b);
1161 memcpy(skb->data, &tx_cmd_b, 4);
1162
1163 skb_push(skb, 4);
1164 tx_cmd_a = (u32)(skb->len - 8) | TX_CMD_A_FIRST_SEG_ |
1165 TX_CMD_A_LAST_SEG_;
1166 cpu_to_le32s(&tx_cmd_a);
1167 memcpy(skb->data, &tx_cmd_a, 4);
1168
1169 return skb;
1170}
1171
1172static const struct driver_info smsc95xx_info = {
1173 .description = "smsc95xx USB 2.0 Ethernet",
1174 .bind = smsc95xx_bind,
1175 .unbind = smsc95xx_unbind,
1176 .link_reset = smsc95xx_link_reset,
1177 .reset = smsc95xx_reset,
1178 .rx_fixup = smsc95xx_rx_fixup,
1179 .tx_fixup = smsc95xx_tx_fixup,
1180 .status = smsc95xx_status,
Paolo Pisati07d69d42012-04-23 04:05:20 +00001181 .flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001182};
1183
1184static const struct usb_device_id products[] = {
1185 {
1186 /* SMSC9500 USB Ethernet Device */
1187 USB_DEVICE(0x0424, 0x9500),
1188 .driver_info = (unsigned long) &smsc95xx_info,
1189 },
Steve Glendinning726474b2009-05-01 06:07:22 +00001190 {
Steve Glendinning6f41d122009-09-22 05:13:02 +00001191 /* SMSC9505 USB Ethernet Device */
1192 USB_DEVICE(0x0424, 0x9505),
1193 .driver_info = (unsigned long) &smsc95xx_info,
1194 },
1195 {
1196 /* SMSC9500A USB Ethernet Device */
1197 USB_DEVICE(0x0424, 0x9E00),
1198 .driver_info = (unsigned long) &smsc95xx_info,
1199 },
1200 {
1201 /* SMSC9505A USB Ethernet Device */
1202 USB_DEVICE(0x0424, 0x9E01),
1203 .driver_info = (unsigned long) &smsc95xx_info,
1204 },
1205 {
Steve Glendinning726474b2009-05-01 06:07:22 +00001206 /* SMSC9512/9514 USB Hub & Ethernet Device */
1207 USB_DEVICE(0x0424, 0xec00),
1208 .driver_info = (unsigned long) &smsc95xx_info,
1209 },
Steve Glendinning6f41d122009-09-22 05:13:02 +00001210 {
1211 /* SMSC9500 USB Ethernet Device (SAL10) */
1212 USB_DEVICE(0x0424, 0x9900),
1213 .driver_info = (unsigned long) &smsc95xx_info,
1214 },
1215 {
1216 /* SMSC9505 USB Ethernet Device (SAL10) */
1217 USB_DEVICE(0x0424, 0x9901),
1218 .driver_info = (unsigned long) &smsc95xx_info,
1219 },
1220 {
1221 /* SMSC9500A USB Ethernet Device (SAL10) */
1222 USB_DEVICE(0x0424, 0x9902),
1223 .driver_info = (unsigned long) &smsc95xx_info,
1224 },
1225 {
1226 /* SMSC9505A USB Ethernet Device (SAL10) */
1227 USB_DEVICE(0x0424, 0x9903),
1228 .driver_info = (unsigned long) &smsc95xx_info,
1229 },
1230 {
1231 /* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
1232 USB_DEVICE(0x0424, 0x9904),
1233 .driver_info = (unsigned long) &smsc95xx_info,
1234 },
1235 {
1236 /* SMSC9500A USB Ethernet Device (HAL) */
1237 USB_DEVICE(0x0424, 0x9905),
1238 .driver_info = (unsigned long) &smsc95xx_info,
1239 },
1240 {
1241 /* SMSC9505A USB Ethernet Device (HAL) */
1242 USB_DEVICE(0x0424, 0x9906),
1243 .driver_info = (unsigned long) &smsc95xx_info,
1244 },
1245 {
1246 /* SMSC9500 USB Ethernet Device (Alternate ID) */
1247 USB_DEVICE(0x0424, 0x9907),
1248 .driver_info = (unsigned long) &smsc95xx_info,
1249 },
1250 {
1251 /* SMSC9500A USB Ethernet Device (Alternate ID) */
1252 USB_DEVICE(0x0424, 0x9908),
1253 .driver_info = (unsigned long) &smsc95xx_info,
1254 },
1255 {
1256 /* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
1257 USB_DEVICE(0x0424, 0x9909),
1258 .driver_info = (unsigned long) &smsc95xx_info,
1259 },
Steve Glendinning88edaa42011-04-10 18:59:27 -07001260 {
1261 /* SMSC LAN9530 USB Ethernet Device */
1262 USB_DEVICE(0x0424, 0x9530),
1263 .driver_info = (unsigned long) &smsc95xx_info,
1264 },
1265 {
1266 /* SMSC LAN9730 USB Ethernet Device */
1267 USB_DEVICE(0x0424, 0x9730),
1268 .driver_info = (unsigned long) &smsc95xx_info,
1269 },
1270 {
1271 /* SMSC LAN89530 USB Ethernet Device */
1272 USB_DEVICE(0x0424, 0x9E08),
1273 .driver_info = (unsigned long) &smsc95xx_info,
1274 },
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001275 { }, /* END */
1276};
1277MODULE_DEVICE_TABLE(usb, products);
1278
1279static struct usb_driver smsc95xx_driver = {
1280 .name = "smsc95xx",
1281 .id_table = products,
1282 .probe = usbnet_probe,
1283 .suspend = usbnet_suspend,
1284 .resume = usbnet_resume,
1285 .disconnect = usbnet_disconnect,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -07001286 .disable_hub_initiated_lpm = 1,
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001287};
1288
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08001289module_usb_driver(smsc95xx_driver);
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001290
1291MODULE_AUTHOR("Nancy Lin");
Steve Glendinning90b24cf2012-04-16 12:13:29 +01001292MODULE_AUTHOR("Steve Glendinning <steve.glendinning@shawell.net>");
Steve Glendinning2f7ca802008-10-02 05:27:57 +00001293MODULE_DESCRIPTION("SMSC95XX USB 2.0 Ethernet Devices");
1294MODULE_LICENSE("GPL");