blob: 59dbdbb5feff8573826fb7c78c5a8b229b7b699d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/signal.h>
10#include <linux/slab.h>
11#include <linux/module.h>
12#include <linux/netdevice.h>
13#include <linux/etherdevice.h>
14#include <linux/mii.h>
15#include <linux/ethtool.h>
16#include <linux/usb.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080017#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/* Version Information */
20#define DRIVER_VERSION "v0.6.2 (2004/08/27)"
21#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
22#define DRIVER_DESC "rtl8150 based usb-ethernet driver"
23
24#define IDR 0x0120
25#define MAR 0x0126
26#define CR 0x012e
27#define TCR 0x012f
28#define RCR 0x0130
29#define TSR 0x0132
30#define RSR 0x0133
31#define CON0 0x0135
32#define CON1 0x0136
33#define MSR 0x0137
34#define PHYADD 0x0138
35#define PHYDAT 0x0139
36#define PHYCNT 0x013b
37#define GPPC 0x013d
38#define BMCR 0x0140
39#define BMSR 0x0142
40#define ANAR 0x0144
41#define ANLP 0x0146
42#define AER 0x0148
43#define CSCR 0x014C /* This one has the link status */
44#define CSCR_LINK_STATUS (1 << 3)
45
46#define IDR_EEPROM 0x1202
47
48#define PHY_READ 0
49#define PHY_WRITE 0x20
50#define PHY_GO 0x40
51
52#define MII_TIMEOUT 10
53#define INTBUFSIZE 8
54
55#define RTL8150_REQT_READ 0xc0
56#define RTL8150_REQT_WRITE 0x40
57#define RTL8150_REQ_GET_REGS 0x05
58#define RTL8150_REQ_SET_REGS 0x05
59
60
61/* Transmit status register errors */
62#define TSR_ECOL (1<<5)
63#define TSR_LCOL (1<<4)
64#define TSR_LOSS_CRS (1<<3)
65#define TSR_JBR (1<<2)
66#define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
67/* Receive status register errors */
68#define RSR_CRC (1<<2)
69#define RSR_FAE (1<<1)
70#define RSR_ERRORS (RSR_CRC | RSR_FAE)
71
72/* Media status register definitions */
73#define MSR_DUPLEX (1<<4)
74#define MSR_SPEED (1<<3)
75#define MSR_LINK (1<<2)
76
77/* Interrupt pipe data */
78#define INT_TSR 0x00
79#define INT_RSR 0x01
80#define INT_MSR 0x02
81#define INT_WAKSR 0x03
82#define INT_TXOK_CNT 0x04
83#define INT_RXLOST_CNT 0x05
84#define INT_CRERR_CNT 0x06
85#define INT_COL_CNT 0x07
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88#define RTL8150_MTU 1540
89#define RTL8150_TX_TIMEOUT (HZ)
90#define RX_SKB_POOL_SIZE 4
91
92/* rtl8150 flags */
93#define RTL8150_HW_CRC 0
94#define RX_REG_SET 1
95#define RTL8150_UNPLUG 2
96#define RX_URB_FAIL 3
97
98/* Define these values to match your device */
Petko Manolov58592712006-12-04 14:27:36 +020099#define VENDOR_ID_REALTEK 0x0bda
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define VENDOR_ID_MELCO 0x0411
Petko Manolov58592712006-12-04 14:27:36 +0200101#define VENDOR_ID_MICRONET 0x3980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define VENDOR_ID_LONGSHINE 0x07b8
Petko Manolov58592712006-12-04 14:27:36 +0200103#define VENDOR_ID_OQO 0x1557
Dan Streetmanb6c27992006-07-05 19:17:27 -0400104#define VENDOR_ID_ZYXEL 0x0586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106#define PRODUCT_ID_RTL8150 0x8150
107#define PRODUCT_ID_LUAKTX 0x0012
108#define PRODUCT_ID_LCS8138TX 0x401a
109#define PRODUCT_ID_SP128AR 0x0003
Dan Streetmanb6c27992006-07-05 19:17:27 -0400110#define PRODUCT_ID_PRESTIGE 0x401a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112#undef EEPROM_WRITE
113
114/* table of devices that work with this driver */
Arvind Yadave1cb90f2017-08-08 21:28:41 +0530115static const struct usb_device_id rtl8150_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
117 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
118 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
119 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
Petko Manolov58592712006-12-04 14:27:36 +0200120 {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
Dan Streetmanb6c27992006-07-05 19:17:27 -0400121 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 {}
123};
124
125MODULE_DEVICE_TABLE(usb, rtl8150_table);
126
127struct rtl8150 {
128 unsigned long flags;
129 struct usb_device *udev;
130 struct tasklet_struct tl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 struct net_device *netdev;
Petko Manolov4d129972013-05-19 23:08:47 +0000132 struct urb *rx_urb, *tx_urb, *intr_urb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 struct sk_buff *tx_skb, *rx_skb;
134 struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
135 spinlock_t rx_pool_lock;
136 struct usb_ctrlrequest dr;
137 int intr_interval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 u8 *intr_buff;
139 u8 phy;
140};
141
142typedef struct rtl8150 rtl8150_t;
143
Petko Manolov4d129972013-05-19 23:08:47 +0000144struct async_req {
145 struct usb_ctrlrequest dr;
146 u16 rx_creg;
147};
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static const char driver_name [] = "rtl8150";
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/*
152**
153** device related part of the code
154**
155*/
156static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
157{
Ben Hutchings7926aff2017-02-04 16:56:32 +0000158 void *buf;
159 int ret;
160
161 buf = kmalloc(size, GFP_NOIO);
162 if (!buf)
163 return -ENOMEM;
164
165 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
166 RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
167 indx, 0, buf, size, 500);
168 if (ret > 0 && ret <= size)
169 memcpy(data, buf, ret);
170 kfree(buf);
171 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Ben Hutchings7926aff2017-02-04 16:56:32 +0000174static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Ben Hutchings7926aff2017-02-04 16:56:32 +0000176 void *buf;
177 int ret;
178
179 buf = kmemdup(data, size, GFP_NOIO);
180 if (!buf)
181 return -ENOMEM;
182
183 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
184 RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
185 indx, 0, buf, size, 500);
186 kfree(buf);
187 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
Petko Manolov4d129972013-05-19 23:08:47 +0000190static void async_set_reg_cb(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Petko Manolov4d129972013-05-19 23:08:47 +0000192 struct async_req *req = (struct async_req *)urb->context;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800193 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Petko Manolov4d129972013-05-19 23:08:47 +0000195 if (status < 0)
196 dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
197 kfree(req);
198 usb_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
Petko Manolov4d129972013-05-19 23:08:47 +0000201static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Petko Manolov4d129972013-05-19 23:08:47 +0000203 int res = -ENOMEM;
204 struct urb *async_urb;
205 struct async_req *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Petko Manolov4d129972013-05-19 23:08:47 +0000207 req = kmalloc(sizeof(struct async_req), GFP_ATOMIC);
208 if (req == NULL)
209 return res;
210 async_urb = usb_alloc_urb(0, GFP_ATOMIC);
211 if (async_urb == NULL) {
212 kfree(req);
213 return res;
214 }
215 req->rx_creg = cpu_to_le16(reg);
216 req->dr.bRequestType = RTL8150_REQT_WRITE;
217 req->dr.bRequest = RTL8150_REQ_SET_REGS;
218 req->dr.wIndex = 0;
219 req->dr.wValue = cpu_to_le16(indx);
220 req->dr.wLength = cpu_to_le16(size);
221 usb_fill_control_urb(async_urb, dev->udev,
222 usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr,
223 &req->rx_creg, size, async_set_reg_cb, req);
224 res = usb_submit_urb(async_urb, GFP_ATOMIC);
225 if (res) {
226 if (res == -ENODEV)
Peter Chubb23219c12006-07-25 20:39:14 +1000227 netif_device_detach(dev->netdev);
Petko Manolov4d129972013-05-19 23:08:47 +0000228 dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
229 }
230 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
234{
235 int i;
236 u8 data[3], tmp;
237
238 data[0] = phy;
239 data[1] = data[2] = 0;
240 tmp = indx | PHY_READ | PHY_GO;
241 i = 0;
242
243 set_registers(dev, PHYADD, sizeof(data), data);
244 set_registers(dev, PHYCNT, 1, &tmp);
245 do {
246 get_registers(dev, PHYCNT, 1, data);
247 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
248
roel kluinc064efc2009-12-27 11:22:08 +0000249 if (i <= MII_TIMEOUT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 get_registers(dev, PHYDAT, 2, data);
251 *reg = data[0] | (data[1] << 8);
252 return 0;
253 } else
254 return 1;
255}
256
257static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
258{
259 int i;
260 u8 data[3], tmp;
261
262 data[0] = phy;
Al Viro886ae1f2007-02-04 03:02:17 +0000263 data[1] = reg & 0xff;
264 data[2] = (reg >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 tmp = indx | PHY_WRITE | PHY_GO;
266 i = 0;
267
268 set_registers(dev, PHYADD, sizeof(data), data);
269 set_registers(dev, PHYCNT, 1, &tmp);
270 do {
271 get_registers(dev, PHYCNT, 1, data);
272 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
273
roel kluinc064efc2009-12-27 11:22:08 +0000274 if (i <= MII_TIMEOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return 0;
276 else
277 return 1;
278}
279
280static inline void set_ethernet_addr(rtl8150_t * dev)
281{
282 u8 node_id[6];
283
284 get_registers(dev, IDR, sizeof(node_id), node_id);
285 memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
286}
287
288static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
289{
290 struct sockaddr *addr = p;
291 rtl8150_t *dev = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 if (netif_running(netdev))
294 return -EBUSY;
295
296 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000297 netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 /* Set the IDR registers. */
Julia Lawall60579122009-12-13 05:47:04 +0000299 set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#ifdef EEPROM_WRITE
301 {
H Hartley Sweetend649a282009-12-29 20:03:28 -0800302 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 u8 cr;
304 /* Get the CR contents. */
305 get_registers(dev, CR, 1, &cr);
306 /* Set the WEPROM bit (eeprom write enable). */
307 cr |= 0x20;
308 set_registers(dev, CR, 1, &cr);
309 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
310 so we need to split them up. */
311 for (i = 0; i * 2 < netdev->addr_len; i++) {
françois romieu141b9e62011-09-30 00:38:29 +0000312 set_registers(dev, IDR_EEPROM + (i * 2), 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 netdev->dev_addr + (i * 2));
314 }
315 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
316 cr &= 0xdf;
317 set_registers(dev, CR, 1, &cr);
318 }
319#endif
320 return 0;
321}
322
323static int rtl8150_reset(rtl8150_t * dev)
324{
325 u8 data = 0x10;
326 int i = HZ;
327
328 set_registers(dev, CR, 1, &data);
329 do {
330 get_registers(dev, CR, 1, &data);
331 } while ((data & 0x10) && --i);
332
333 return (i > 0) ? 1 : 0;
334}
335
336static int alloc_all_urbs(rtl8150_t * dev)
337{
338 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
339 if (!dev->rx_urb)
340 return 0;
341 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
342 if (!dev->tx_urb) {
343 usb_free_urb(dev->rx_urb);
344 return 0;
345 }
346 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
347 if (!dev->intr_urb) {
348 usb_free_urb(dev->rx_urb);
349 usb_free_urb(dev->tx_urb);
350 return 0;
351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 return 1;
354}
355
356static void free_all_urbs(rtl8150_t * dev)
357{
358 usb_free_urb(dev->rx_urb);
359 usb_free_urb(dev->tx_urb);
360 usb_free_urb(dev->intr_urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
363static void unlink_all_urbs(rtl8150_t * dev)
364{
365 usb_kill_urb(dev->rx_urb);
366 usb_kill_urb(dev->tx_urb);
367 usb_kill_urb(dev->intr_urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370static inline struct sk_buff *pull_skb(rtl8150_t *dev)
371{
372 struct sk_buff *skb;
373 int i;
374
375 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
376 if (dev->rx_skb_pool[i]) {
377 skb = dev->rx_skb_pool[i];
378 dev->rx_skb_pool[i] = NULL;
379 return skb;
380 }
381 }
382 return NULL;
383}
384
David Howells7d12e782006-10-05 14:55:46 +0100385static void read_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
387 rtl8150_t *dev;
388 unsigned pkt_len, res;
389 struct sk_buff *skb;
390 struct net_device *netdev;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800391 int status = urb->status;
392 int result;
Sebastian Andrzej Siewiorfeae6412018-06-20 21:31:21 +0200393 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 dev = urb->context;
396 if (!dev)
397 return;
398 if (test_bit(RTL8150_UNPLUG, &dev->flags))
399 return;
400 netdev = dev->netdev;
401 if (!netif_device_present(netdev))
402 return;
403
Oliver Neukumc94cb312008-12-18 23:00:59 -0800404 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 case 0:
406 break;
407 case -ENOENT:
408 return; /* the urb is in unlink state */
Pete Zaitcev38e2bfc2006-09-18 22:49:02 -0700409 case -ETIME:
André Goddard Rosa342a4372009-05-29 22:13:58 -0700410 if (printk_ratelimit())
411 dev_warn(&urb->dev->dev, "may be reset is needed?..\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 goto goon;
413 default:
André Goddard Rosa342a4372009-05-29 22:13:58 -0700414 if (printk_ratelimit())
415 dev_warn(&urb->dev->dev, "Rx status %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 goto goon;
417 }
418
419 if (!dev->rx_skb)
420 goto resched;
421 /* protect against short packets (tell me why we got some?!?) */
422 if (urb->actual_length < 4)
423 goto goon;
424
425 res = urb->actual_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 pkt_len = res - 4;
427
428 skb_put(dev->rx_skb, pkt_len);
429 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
430 netif_rx(dev->rx_skb);
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000431 netdev->stats.rx_packets++;
432 netdev->stats.rx_bytes += pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Sebastian Andrzej Siewiorfeae6412018-06-20 21:31:21 +0200434 spin_lock_irqsave(&dev->rx_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 skb = pull_skb(dev);
Sebastian Andrzej Siewiorfeae6412018-06-20 21:31:21 +0200436 spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (!skb)
438 goto resched;
439
440 dev->rx_skb = skb;
441goon:
442 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
443 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
Oliver Neukumc94cb312008-12-18 23:00:59 -0800444 result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
445 if (result == -ENODEV)
Peter Chubb23219c12006-07-25 20:39:14 +1000446 netif_device_detach(dev->netdev);
Oliver Neukumc94cb312008-12-18 23:00:59 -0800447 else if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 set_bit(RX_URB_FAIL, &dev->flags);
449 goto resched;
450 } else {
451 clear_bit(RX_URB_FAIL, &dev->flags);
452 }
453
454 return;
455resched:
456 tasklet_schedule(&dev->tl);
457}
458
David Howells7d12e782006-10-05 14:55:46 +0100459static void write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
461 rtl8150_t *dev;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800462 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 dev = urb->context;
465 if (!dev)
466 return;
467 dev_kfree_skb_irq(dev->tx_skb);
468 if (!netif_device_present(dev->netdev))
469 return;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800470 if (status)
Greg Kroah-Hartman880c9c62008-08-18 13:21:04 -0700471 dev_info(&urb->dev->dev, "%s: Tx status %d\n",
Oliver Neukumc94cb312008-12-18 23:00:59 -0800472 dev->netdev->name, status);
Florian Westphal860e9532016-05-03 16:33:13 +0200473 netif_trans_update(dev->netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 netif_wake_queue(dev->netdev);
475}
476
David Howells7d12e782006-10-05 14:55:46 +0100477static void intr_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
479 rtl8150_t *dev;
480 __u8 *d;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800481 int status = urb->status;
482 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 dev = urb->context;
485 if (!dev)
486 return;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800487 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 case 0: /* success */
489 break;
490 case -ECONNRESET: /* unlink */
491 case -ENOENT:
492 case -ESHUTDOWN:
493 return;
494 /* -EPIPE: should clear the halt */
495 default:
Greg Kroah-Hartman880c9c62008-08-18 13:21:04 -0700496 dev_info(&urb->dev->dev, "%s: intr status %d\n",
Oliver Neukumc94cb312008-12-18 23:00:59 -0800497 dev->netdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 goto resubmit;
499 }
500
501 d = urb->transfer_buffer;
502 if (d[0] & TSR_ERRORS) {
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000503 dev->netdev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000505 dev->netdev->stats.tx_aborted_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (d[INT_TSR] & TSR_LCOL)
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000507 dev->netdev->stats.tx_window_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (d[INT_TSR] & TSR_LOSS_CRS)
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000509 dev->netdev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511 /* Report link status changes to the network stack */
512 if ((d[INT_MSR] & MSR_LINK) == 0) {
513 if (netif_carrier_ok(dev->netdev)) {
514 netif_carrier_off(dev->netdev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000515 netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517 } else {
518 if (!netif_carrier_ok(dev->netdev)) {
519 netif_carrier_on(dev->netdev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000520 netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522 }
523
524resubmit:
Oliver Neukumc94cb312008-12-18 23:00:59 -0800525 res = usb_submit_urb (urb, GFP_ATOMIC);
526 if (res == -ENODEV)
Peter Chubb23219c12006-07-25 20:39:14 +1000527 netif_device_detach(dev->netdev);
Oliver Neukumc94cb312008-12-18 23:00:59 -0800528 else if (res)
Greg Kroah-Hartman21f52432012-04-25 12:37:49 -0700529 dev_err(&dev->udev->dev,
530 "can't resubmit intr, %s-%s/input0, status %d\n",
531 dev->udev->bus->bus_name, dev->udev->devpath, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Peter Chubb23219c12006-07-25 20:39:14 +1000534static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
535{
536 rtl8150_t *dev = usb_get_intfdata(intf);
537
538 netif_device_detach(dev->netdev);
539
540 if (netif_running(dev->netdev)) {
541 usb_kill_urb(dev->rx_urb);
542 usb_kill_urb(dev->intr_urb);
543 }
544 return 0;
545}
546
547static int rtl8150_resume(struct usb_interface *intf)
548{
549 rtl8150_t *dev = usb_get_intfdata(intf);
550
551 netif_device_attach(dev->netdev);
552 if (netif_running(dev->netdev)) {
553 dev->rx_urb->status = 0;
554 dev->rx_urb->actual_length = 0;
David Howells7d12e782006-10-05 14:55:46 +0100555 read_bulk_callback(dev->rx_urb);
Peter Chubb23219c12006-07-25 20:39:14 +1000556
557 dev->intr_urb->status = 0;
558 dev->intr_urb->actual_length = 0;
David Howells7d12e782006-10-05 14:55:46 +0100559 intr_callback(dev->intr_urb);
Peter Chubb23219c12006-07-25 20:39:14 +1000560 }
561 return 0;
562}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564/*
565**
566** network related part of the code
567**
568*/
569
570static void fill_skb_pool(rtl8150_t *dev)
571{
572 struct sk_buff *skb;
573 int i;
574
575 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
576 if (dev->rx_skb_pool[i])
577 continue;
578 skb = dev_alloc_skb(RTL8150_MTU + 2);
579 if (!skb) {
580 return;
581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 skb_reserve(skb, 2);
583 dev->rx_skb_pool[i] = skb;
584 }
585}
586
587static void free_skb_pool(rtl8150_t *dev)
588{
589 int i;
590
591 for (i = 0; i < RX_SKB_POOL_SIZE; i++)
592 if (dev->rx_skb_pool[i])
593 dev_kfree_skb(dev->rx_skb_pool[i]);
594}
595
françois romieu141b9e62011-09-30 00:38:29 +0000596static void rx_fixup(unsigned long data)
597{
598 struct rtl8150 *dev = (struct rtl8150 *)data;
599 struct sk_buff *skb;
600 int status;
601
602 spin_lock_irq(&dev->rx_pool_lock);
603 fill_skb_pool(dev);
604 spin_unlock_irq(&dev->rx_pool_lock);
605 if (test_bit(RX_URB_FAIL, &dev->flags))
606 if (dev->rx_skb)
607 goto try_again;
608 spin_lock_irq(&dev->rx_pool_lock);
609 skb = pull_skb(dev);
610 spin_unlock_irq(&dev->rx_pool_lock);
611 if (skb == NULL)
612 goto tlsched;
613 dev->rx_skb = skb;
614 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
615 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
616try_again:
617 status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
618 if (status == -ENODEV) {
619 netif_device_detach(dev->netdev);
620 } else if (status) {
621 set_bit(RX_URB_FAIL, &dev->flags);
622 goto tlsched;
623 } else {
624 clear_bit(RX_URB_FAIL, &dev->flags);
625 }
626
627 return;
628tlsched:
629 tasklet_schedule(&dev->tl);
630}
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632static int enable_net_traffic(rtl8150_t * dev)
633{
634 u8 cr, tcr, rcr, msr;
635
636 if (!rtl8150_reset(dev)) {
Greg Kroah-Hartman4dc89942008-08-14 09:37:34 -0700637 dev_warn(&dev->udev->dev, "device reset failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
640 rcr = 0x9e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 tcr = 0xd8;
642 cr = 0x0c;
643 if (!(rcr & 0x80))
644 set_bit(RTL8150_HW_CRC, &dev->flags);
645 set_registers(dev, RCR, 1, &rcr);
646 set_registers(dev, TCR, 1, &tcr);
647 set_registers(dev, CR, 1, &cr);
648 get_registers(dev, MSR, 1, &msr);
649
650 return 0;
651}
652
653static void disable_net_traffic(rtl8150_t * dev)
654{
655 u8 cr;
656
657 get_registers(dev, CR, 1, &cr);
658 cr &= 0xf3;
659 set_registers(dev, CR, 1, &cr);
660}
661
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662static void rtl8150_tx_timeout(struct net_device *netdev)
663{
664 rtl8150_t *dev = netdev_priv(netdev);
Greg Kroah-Hartman4dc89942008-08-14 09:37:34 -0700665 dev_warn(&netdev->dev, "Tx timeout.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 usb_unlink_urb(dev->tx_urb);
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000667 netdev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670static void rtl8150_set_multicast(struct net_device *netdev)
671{
672 rtl8150_t *dev = netdev_priv(netdev);
Petko Manolov4d129972013-05-19 23:08:47 +0000673 u16 rx_creg = 0x9e;
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 netif_stop_queue(netdev);
676 if (netdev->flags & IFF_PROMISC) {
Petko Manolov4d129972013-05-19 23:08:47 +0000677 rx_creg |= 0x0001;
Greg Kroah-Hartman880c9c62008-08-18 13:21:04 -0700678 dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name);
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000679 } else if (!netdev_mc_empty(netdev) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 (netdev->flags & IFF_ALLMULTI)) {
Petko Manolov4d129972013-05-19 23:08:47 +0000681 rx_creg &= 0xfffe;
682 rx_creg |= 0x0002;
David Lechner3a9b0452018-07-16 17:58:10 -0500683 dev_dbg(&netdev->dev, "%s: allmulti set\n", netdev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 } else {
685 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
Petko Manolov4d129972013-05-19 23:08:47 +0000686 rx_creg &= 0x00fc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
Petko Manolov4d129972013-05-19 23:08:47 +0000688 async_set_registers(dev, RCR, sizeof(rx_creg), rx_creg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 netif_wake_queue(netdev);
690}
691
Stephen Hemminger25a79c42009-08-31 19:50:45 +0000692static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,
693 struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
695 rtl8150_t *dev = netdev_priv(netdev);
696 int count, res;
697
698 netif_stop_queue(netdev);
699 count = (skb->len < 60) ? 60 : skb->len;
700 count = (count & 0x3f) ? count : count + 1;
701 dev->tx_skb = skb;
702 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
703 skb->data, count, write_bulk_callback, dev);
704 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
Peter Chubb23219c12006-07-25 20:39:14 +1000705 /* Can we get/handle EPIPE here? */
706 if (res == -ENODEV)
707 netif_device_detach(dev->netdev);
708 else {
Greg Kroah-Hartman4dc89942008-08-14 09:37:34 -0700709 dev_warn(&netdev->dev, "failed tx_urb %d\n", res);
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000710 netdev->stats.tx_errors++;
Peter Chubb23219c12006-07-25 20:39:14 +1000711 netif_start_queue(netdev);
712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 } else {
Stephen Hemmingerb7e41e22009-03-20 19:35:50 +0000714 netdev->stats.tx_packets++;
715 netdev->stats.tx_bytes += skb->len;
Florian Westphal860e9532016-05-03 16:33:13 +0200716 netif_trans_update(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
Patrick McHardy6ed10652009-06-23 06:03:08 +0000719 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
721
722
723static void set_carrier(struct net_device *netdev)
724{
725 rtl8150_t *dev = netdev_priv(netdev);
726 short tmp;
727
728 get_registers(dev, CSCR, 2, &tmp);
729 if (tmp & CSCR_LINK_STATUS)
730 netif_carrier_on(netdev);
731 else
732 netif_carrier_off(netdev);
733}
734
735static int rtl8150_open(struct net_device *netdev)
736{
737 rtl8150_t *dev = netdev_priv(netdev);
738 int res;
739
740 if (dev->rx_skb == NULL)
741 dev->rx_skb = pull_skb(dev);
742 if (!dev->rx_skb)
743 return -ENOMEM;
744
745 set_registers(dev, IDR, 6, netdev->dev_addr);
françois romieu141b9e62011-09-30 00:38:29 +0000746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
748 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
Peter Chubb23219c12006-07-25 20:39:14 +1000749 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
750 if (res == -ENODEV)
751 netif_device_detach(dev->netdev);
Greg Kroah-Hartman4dc89942008-08-14 09:37:34 -0700752 dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res);
Peter Chubb23219c12006-07-25 20:39:14 +1000753 return res;
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
756 dev->intr_buff, INTBUFSIZE, intr_callback,
757 dev, dev->intr_interval);
Peter Chubb23219c12006-07-25 20:39:14 +1000758 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
759 if (res == -ENODEV)
760 netif_device_detach(dev->netdev);
Greg Kroah-Hartman4dc89942008-08-14 09:37:34 -0700761 dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res);
Peter Chubb23219c12006-07-25 20:39:14 +1000762 usb_kill_urb(dev->rx_urb);
763 return res;
764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 enable_net_traffic(dev);
766 set_carrier(netdev);
Peter Chubb23219c12006-07-25 20:39:14 +1000767 netif_start_queue(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 return res;
770}
771
772static int rtl8150_close(struct net_device *netdev)
773{
774 rtl8150_t *dev = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 netif_stop_queue(netdev);
777 if (!test_bit(RTL8150_UNPLUG, &dev->flags))
778 disable_net_traffic(dev);
779 unlink_all_urbs(dev);
780
Sudip Mukherjee1abe7cd2014-11-18 21:55:21 +0530781 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
784static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
785{
786 rtl8150_t *dev = netdev_priv(netdev);
787
Jiri Pirko7826d432013-01-06 00:44:26 +0000788 strlcpy(info->driver, driver_name, sizeof(info->driver));
789 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
790 usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
792
Philippe Reynesb66239b2017-03-12 23:16:25 +0100793static int rtl8150_get_link_ksettings(struct net_device *netdev,
794 struct ethtool_link_ksettings *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
796 rtl8150_t *dev = netdev_priv(netdev);
797 short lpa, bmcr;
Philippe Reynesb66239b2017-03-12 23:16:25 +0100798 u32 supported;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Philippe Reynesb66239b2017-03-12 23:16:25 +0100800 supported = (SUPPORTED_10baseT_Half |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 SUPPORTED_10baseT_Full |
802 SUPPORTED_100baseT_Half |
803 SUPPORTED_100baseT_Full |
804 SUPPORTED_Autoneg |
805 SUPPORTED_TP | SUPPORTED_MII);
Philippe Reynesb66239b2017-03-12 23:16:25 +0100806 ecmd->base.port = PORT_TP;
807 ecmd->base.phy_address = dev->phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 get_registers(dev, BMCR, 2, &bmcr);
809 get_registers(dev, ANLP, 2, &lpa);
810 if (bmcr & BMCR_ANENABLE) {
David Decotigny70739492011-04-27 18:32:40 +0000811 u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ?
812 SPEED_100 : SPEED_10);
Philippe Reynesb66239b2017-03-12 23:16:25 +0100813 ecmd->base.speed = speed;
814 ecmd->base.autoneg = AUTONEG_ENABLE;
David Decotigny70739492011-04-27 18:32:40 +0000815 if (speed == SPEED_100)
Philippe Reynesb66239b2017-03-12 23:16:25 +0100816 ecmd->base.duplex = (lpa & LPA_100FULL) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 DUPLEX_FULL : DUPLEX_HALF;
818 else
Philippe Reynesb66239b2017-03-12 23:16:25 +0100819 ecmd->base.duplex = (lpa & LPA_10FULL) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 DUPLEX_FULL : DUPLEX_HALF;
821 } else {
Philippe Reynesb66239b2017-03-12 23:16:25 +0100822 ecmd->base.autoneg = AUTONEG_DISABLE;
823 ecmd->base.speed = ((bmcr & BMCR_SPEED100) ?
824 SPEED_100 : SPEED_10);
825 ecmd->base.duplex = (bmcr & BMCR_FULLDPLX) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 DUPLEX_FULL : DUPLEX_HALF;
827 }
Philippe Reynesb66239b2017-03-12 23:16:25 +0100828
829 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported,
830 supported);
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 return 0;
833}
834
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700835static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 .get_drvinfo = rtl8150_get_drvinfo,
Philippe Reynesb66239b2017-03-12 23:16:25 +0100837 .get_link = ethtool_op_get_link,
838 .get_link_ksettings = rtl8150_get_link_ksettings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839};
840
841static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
842{
843 rtl8150_t *dev = netdev_priv(netdev);
844 u16 *data = (u16 *) & rq->ifr_ifru;
845 int res = 0;
846
847 switch (cmd) {
848 case SIOCDEVPRIVATE:
849 data[0] = dev->phy;
Gustavo A. R. Silva0d156a32019-02-08 13:09:06 -0600850 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 case SIOCDEVPRIVATE + 1:
852 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
853 break;
854 case SIOCDEVPRIVATE + 2:
855 if (!capable(CAP_NET_ADMIN))
856 return -EPERM;
857 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
858 break;
859 default:
860 res = -EOPNOTSUPP;
861 }
862
863 return res;
864}
865
Stephen Hemmingerd79f7ef2009-03-20 19:35:51 +0000866static const struct net_device_ops rtl8150_netdev_ops = {
867 .ndo_open = rtl8150_open,
868 .ndo_stop = rtl8150_close,
869 .ndo_do_ioctl = rtl8150_ioctl,
870 .ndo_start_xmit = rtl8150_start_xmit,
françois romieu141b9e62011-09-30 00:38:29 +0000871 .ndo_tx_timeout = rtl8150_tx_timeout,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000872 .ndo_set_rx_mode = rtl8150_set_multicast,
Stephen Hemmingerd79f7ef2009-03-20 19:35:51 +0000873 .ndo_set_mac_address = rtl8150_set_mac_address,
874
Stephen Hemmingerd79f7ef2009-03-20 19:35:51 +0000875 .ndo_validate_addr = eth_validate_addr,
876};
877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878static int rtl8150_probe(struct usb_interface *intf,
879 const struct usb_device_id *id)
880{
881 struct usb_device *udev = interface_to_usbdev(intf);
882 rtl8150_t *dev;
883 struct net_device *netdev;
884
885 netdev = alloc_etherdev(sizeof(rtl8150_t));
Joe Perches41de8d42012-01-29 13:47:52 +0000886 if (!netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 dev = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
892 if (!dev->intr_buff) {
893 free_netdev(netdev);
894 return -ENOMEM;
895 }
896
897 tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
898 spin_lock_init(&dev->rx_pool_lock);
françois romieu141b9e62011-09-30 00:38:29 +0000899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 dev->udev = udev;
901 dev->netdev = netdev;
Stephen Hemmingerd79f7ef2009-03-20 19:35:51 +0000902 netdev->netdev_ops = &rtl8150_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000904 netdev->ethtool_ops = &ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 dev->intr_interval = 100; /* 100ms */
906
907 if (!alloc_all_urbs(dev)) {
Greg Kroah-Hartman21f52432012-04-25 12:37:49 -0700908 dev_err(&intf->dev, "out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 goto out;
910 }
911 if (!rtl8150_reset(dev)) {
Greg Kroah-Hartman21f52432012-04-25 12:37:49 -0700912 dev_err(&intf->dev, "couldn't reset the device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 goto out1;
914 }
915 fill_skb_pool(dev);
916 set_ethernet_addr(dev);
françois romieu141b9e62011-09-30 00:38:29 +0000917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 usb_set_intfdata(intf, dev);
919 SET_NETDEV_DEV(netdev, &intf->dev);
920 if (register_netdev(netdev) != 0) {
Greg Kroah-Hartman21f52432012-04-25 12:37:49 -0700921 dev_err(&intf->dev, "couldn't register the device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 goto out2;
923 }
Petko Manolov09abfa82006-03-15 16:29:38 +0200924
Greg Kroah-Hartman880c9c62008-08-18 13:21:04 -0700925 dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name);
Petko Manolov09abfa82006-03-15 16:29:38 +0200926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 return 0;
928
929out2:
930 usb_set_intfdata(intf, NULL);
931 free_skb_pool(dev);
932out1:
933 free_all_urbs(dev);
934out:
935 kfree(dev->intr_buff);
936 free_netdev(netdev);
937 return -EIO;
938}
939
940static void rtl8150_disconnect(struct usb_interface *intf)
941{
942 rtl8150_t *dev = usb_get_intfdata(intf);
943
944 usb_set_intfdata(intf, NULL);
945 if (dev) {
946 set_bit(RTL8150_UNPLUG, &dev->flags);
Andrew Mortoneff674a2006-08-14 23:11:09 -0700947 tasklet_kill(&dev->tl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 unregister_netdev(dev->netdev);
949 unlink_all_urbs(dev);
950 free_all_urbs(dev);
951 free_skb_pool(dev);
952 if (dev->rx_skb)
953 dev_kfree_skb(dev->rx_skb);
954 kfree(dev->intr_buff);
955 free_netdev(dev->netdev);
956 }
957}
958
françois romieu141b9e62011-09-30 00:38:29 +0000959static struct usb_driver rtl8150_driver = {
960 .name = driver_name,
961 .probe = rtl8150_probe,
962 .disconnect = rtl8150_disconnect,
963 .id_table = rtl8150_table,
964 .suspend = rtl8150_suspend,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -0700965 .resume = rtl8150_resume,
966 .disable_hub_initiated_lpm = 1,
françois romieu141b9e62011-09-30 00:38:29 +0000967};
968
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -0800969module_usb_driver(rtl8150_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971MODULE_AUTHOR(DRIVER_AUTHOR);
972MODULE_DESCRIPTION(DRIVER_DESC);
973MODULE_LICENSE("GPL");