1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
6 #include <linux/signal.h>
7 #include <linux/slab.h>
8 #include <linux/module.h>
9 #include <linux/netdevice.h>
10 #include <linux/etherdevice.h>
11 #include <linux/mii.h>
12 #include <linux/ethtool.h>
13 #include <linux/usb.h>
14 #include <linux/uaccess.h>
16 /* Version Information */
17 #define DRIVER_VERSION "v0.6.2 (2004/08/27)"
18 #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
19 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
40 #define CSCR 0x014C /* This one has the link status */
41 #define CSCR_LINK_STATUS (1 << 3)
43 #define IDR_EEPROM 0x1202
46 #define PHY_WRITE 0x20
49 #define MII_TIMEOUT 10
52 #define RTL8150_REQT_READ 0xc0
53 #define RTL8150_REQT_WRITE 0x40
54 #define RTL8150_REQ_GET_REGS 0x05
55 #define RTL8150_REQ_SET_REGS 0x05
58 /* Transmit status register errors */
59 #define TSR_ECOL (1<<5)
60 #define TSR_LCOL (1<<4)
61 #define TSR_LOSS_CRS (1<<3)
62 #define TSR_JBR (1<<2)
63 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
64 /* Receive status register errors */
65 #define RSR_CRC (1<<2)
66 #define RSR_FAE (1<<1)
67 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
69 /* Media status register definitions */
70 #define MSR_DUPLEX (1<<4)
71 #define MSR_SPEED (1<<3)
72 #define MSR_LINK (1<<2)
74 /* Interrupt pipe data */
78 #define INT_WAKSR 0x03
79 #define INT_TXOK_CNT 0x04
80 #define INT_RXLOST_CNT 0x05
81 #define INT_CRERR_CNT 0x06
82 #define INT_COL_CNT 0x07
85 #define RTL8150_MTU 1540
86 #define RTL8150_TX_TIMEOUT (HZ)
87 #define RX_SKB_POOL_SIZE 4
90 #define RTL8150_HW_CRC 0
92 #define RTL8150_UNPLUG 2
95 /* Define these values to match your device */
96 #define VENDOR_ID_REALTEK 0x0bda
97 #define VENDOR_ID_MELCO 0x0411
98 #define VENDOR_ID_MICRONET 0x3980
99 #define VENDOR_ID_LONGSHINE 0x07b8
100 #define VENDOR_ID_OQO 0x1557
101 #define VENDOR_ID_ZYXEL 0x0586
103 #define PRODUCT_ID_RTL8150 0x8150
104 #define PRODUCT_ID_LUAKTX 0x0012
105 #define PRODUCT_ID_LCS8138TX 0x401a
106 #define PRODUCT_ID_SP128AR 0x0003
107 #define PRODUCT_ID_PRESTIGE 0x401a
111 /* table of devices that work with this driver */
112 static const struct usb_device_id rtl8150_table[] = {
113 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
114 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
115 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
116 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
117 {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
118 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
122 MODULE_DEVICE_TABLE(usb, rtl8150_table);
126 struct usb_device *udev;
127 struct tasklet_struct tl;
128 struct net_device *netdev;
129 struct urb *rx_urb, *tx_urb, *intr_urb;
130 struct sk_buff *tx_skb, *rx_skb;
131 struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
132 spinlock_t rx_pool_lock;
133 struct usb_ctrlrequest dr;
139 typedef struct rtl8150 rtl8150_t;
142 struct usb_ctrlrequest dr;
146 static const char driver_name [] = "rtl8150";
150 ** device related part of the code
153 static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
158 buf = kmalloc(size, GFP_NOIO);
162 ret = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
163 RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
164 indx, 0, buf, size, 500);
165 if (ret > 0 && ret <= size)
166 memcpy(data, buf, ret);
171 static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data)
176 buf = kmemdup(data, size, GFP_NOIO);
180 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
181 RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
182 indx, 0, buf, size, 500);
187 static void async_set_reg_cb(struct urb *urb)
189 struct async_req *req = (struct async_req *)urb->context;
190 int status = urb->status;
193 dev_dbg(&urb->dev->dev, "%s failed with %d", __func__, status);
198 static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
201 struct urb *async_urb;
202 struct async_req *req;
204 req = kmalloc(sizeof(struct async_req), GFP_ATOMIC);
207 async_urb = usb_alloc_urb(0, GFP_ATOMIC);
208 if (async_urb == NULL) {
212 req->rx_creg = cpu_to_le16(reg);
213 req->dr.bRequestType = RTL8150_REQT_WRITE;
214 req->dr.bRequest = RTL8150_REQ_SET_REGS;
216 req->dr.wValue = cpu_to_le16(indx);
217 req->dr.wLength = cpu_to_le16(size);
218 usb_fill_control_urb(async_urb, dev->udev,
219 usb_sndctrlpipe(dev->udev, 0), (void *)&req->dr,
220 &req->rx_creg, size, async_set_reg_cb, req);
221 res = usb_submit_urb(async_urb, GFP_ATOMIC);
224 netif_device_detach(dev->netdev);
225 dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
230 static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
236 data[1] = data[2] = 0;
237 tmp = indx | PHY_READ | PHY_GO;
240 set_registers(dev, PHYADD, sizeof(data), data);
241 set_registers(dev, PHYCNT, 1, &tmp);
243 get_registers(dev, PHYCNT, 1, data);
244 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
246 if (i <= MII_TIMEOUT) {
247 get_registers(dev, PHYDAT, 2, data);
248 *reg = data[0] | (data[1] << 8);
254 static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
260 data[1] = reg & 0xff;
261 data[2] = (reg >> 8) & 0xff;
262 tmp = indx | PHY_WRITE | PHY_GO;
265 set_registers(dev, PHYADD, sizeof(data), data);
266 set_registers(dev, PHYCNT, 1, &tmp);
268 get_registers(dev, PHYCNT, 1, data);
269 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
271 if (i <= MII_TIMEOUT)
277 static inline void set_ethernet_addr(rtl8150_t * dev)
281 get_registers(dev, IDR, sizeof(node_id), node_id);
282 memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
285 static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
287 struct sockaddr *addr = p;
288 rtl8150_t *dev = netdev_priv(netdev);
290 if (netif_running(netdev))
293 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
294 netdev_dbg(netdev, "Setting MAC address to %pM\n", netdev->dev_addr);
295 /* Set the IDR registers. */
296 set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr);
301 /* Get the CR contents. */
302 get_registers(dev, CR, 1, &cr);
303 /* Set the WEPROM bit (eeprom write enable). */
305 set_registers(dev, CR, 1, &cr);
306 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
307 so we need to split them up. */
308 for (i = 0; i * 2 < netdev->addr_len; i++) {
309 set_registers(dev, IDR_EEPROM + (i * 2), 2,
310 netdev->dev_addr + (i * 2));
312 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
314 set_registers(dev, CR, 1, &cr);
320 static int rtl8150_reset(rtl8150_t * dev)
325 set_registers(dev, CR, 1, &data);
327 get_registers(dev, CR, 1, &data);
328 } while ((data & 0x10) && --i);
330 return (i > 0) ? 1 : 0;
333 static int alloc_all_urbs(rtl8150_t * dev)
335 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
338 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
340 usb_free_urb(dev->rx_urb);
343 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
344 if (!dev->intr_urb) {
345 usb_free_urb(dev->rx_urb);
346 usb_free_urb(dev->tx_urb);
353 static void free_all_urbs(rtl8150_t * dev)
355 usb_free_urb(dev->rx_urb);
356 usb_free_urb(dev->tx_urb);
357 usb_free_urb(dev->intr_urb);
360 static void unlink_all_urbs(rtl8150_t * dev)
362 usb_kill_urb(dev->rx_urb);
363 usb_kill_urb(dev->tx_urb);
364 usb_kill_urb(dev->intr_urb);
367 static inline struct sk_buff *pull_skb(rtl8150_t *dev)
372 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
373 if (dev->rx_skb_pool[i]) {
374 skb = dev->rx_skb_pool[i];
375 dev->rx_skb_pool[i] = NULL;
382 static void read_bulk_callback(struct urb *urb)
385 unsigned pkt_len, res;
387 struct net_device *netdev;
388 int status = urb->status;
395 if (test_bit(RTL8150_UNPLUG, &dev->flags))
397 netdev = dev->netdev;
398 if (!netif_device_present(netdev))
405 return; /* the urb is in unlink state */
407 if (printk_ratelimit())
408 dev_warn(&urb->dev->dev, "may be reset is needed?..\n");
411 if (printk_ratelimit())
412 dev_warn(&urb->dev->dev, "Rx status %d\n", status);
418 /* protect against short packets (tell me why we got some?!?) */
419 if (urb->actual_length < 4)
422 res = urb->actual_length;
425 skb_put(dev->rx_skb, pkt_len);
426 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
427 netif_rx(dev->rx_skb);
428 netdev->stats.rx_packets++;
429 netdev->stats.rx_bytes += pkt_len;
431 spin_lock_irqsave(&dev->rx_pool_lock, flags);
433 spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
439 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
440 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
441 result = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
442 if (result == -ENODEV)
443 netif_device_detach(dev->netdev);
445 set_bit(RX_URB_FAIL, &dev->flags);
448 clear_bit(RX_URB_FAIL, &dev->flags);
453 tasklet_schedule(&dev->tl);
456 static void write_bulk_callback(struct urb *urb)
459 int status = urb->status;
464 dev_kfree_skb_irq(dev->tx_skb);
465 if (!netif_device_present(dev->netdev))
468 dev_info(&urb->dev->dev, "%s: Tx status %d\n",
469 dev->netdev->name, status);
470 netif_trans_update(dev->netdev);
471 netif_wake_queue(dev->netdev);
474 static void intr_callback(struct urb *urb)
478 int status = urb->status;
485 case 0: /* success */
487 case -ECONNRESET: /* unlink */
491 /* -EPIPE: should clear the halt */
493 dev_info(&urb->dev->dev, "%s: intr status %d\n",
494 dev->netdev->name, status);
498 d = urb->transfer_buffer;
499 if (d[0] & TSR_ERRORS) {
500 dev->netdev->stats.tx_errors++;
501 if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
502 dev->netdev->stats.tx_aborted_errors++;
503 if (d[INT_TSR] & TSR_LCOL)
504 dev->netdev->stats.tx_window_errors++;
505 if (d[INT_TSR] & TSR_LOSS_CRS)
506 dev->netdev->stats.tx_carrier_errors++;
508 /* Report link status changes to the network stack */
509 if ((d[INT_MSR] & MSR_LINK) == 0) {
510 if (netif_carrier_ok(dev->netdev)) {
511 netif_carrier_off(dev->netdev);
512 netdev_dbg(dev->netdev, "%s: LINK LOST\n", __func__);
515 if (!netif_carrier_ok(dev->netdev)) {
516 netif_carrier_on(dev->netdev);
517 netdev_dbg(dev->netdev, "%s: LINK CAME BACK\n", __func__);
522 res = usb_submit_urb (urb, GFP_ATOMIC);
524 netif_device_detach(dev->netdev);
526 dev_err(&dev->udev->dev,
527 "can't resubmit intr, %s-%s/input0, status %d\n",
528 dev->udev->bus->bus_name, dev->udev->devpath, res);
531 static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
533 rtl8150_t *dev = usb_get_intfdata(intf);
535 netif_device_detach(dev->netdev);
537 if (netif_running(dev->netdev)) {
538 usb_kill_urb(dev->rx_urb);
539 usb_kill_urb(dev->intr_urb);
544 static int rtl8150_resume(struct usb_interface *intf)
546 rtl8150_t *dev = usb_get_intfdata(intf);
548 netif_device_attach(dev->netdev);
549 if (netif_running(dev->netdev)) {
550 dev->rx_urb->status = 0;
551 dev->rx_urb->actual_length = 0;
552 read_bulk_callback(dev->rx_urb);
554 dev->intr_urb->status = 0;
555 dev->intr_urb->actual_length = 0;
556 intr_callback(dev->intr_urb);
563 ** network related part of the code
567 static void fill_skb_pool(rtl8150_t *dev)
572 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
573 if (dev->rx_skb_pool[i])
575 skb = dev_alloc_skb(RTL8150_MTU + 2);
580 dev->rx_skb_pool[i] = skb;
584 static void free_skb_pool(rtl8150_t *dev)
588 for (i = 0; i < RX_SKB_POOL_SIZE; i++)
589 if (dev->rx_skb_pool[i])
590 dev_kfree_skb(dev->rx_skb_pool[i]);
593 static void rx_fixup(unsigned long data)
595 struct rtl8150 *dev = (struct rtl8150 *)data;
599 spin_lock_irq(&dev->rx_pool_lock);
601 spin_unlock_irq(&dev->rx_pool_lock);
602 if (test_bit(RX_URB_FAIL, &dev->flags))
605 spin_lock_irq(&dev->rx_pool_lock);
607 spin_unlock_irq(&dev->rx_pool_lock);
611 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
612 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
614 status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
615 if (status == -ENODEV) {
616 netif_device_detach(dev->netdev);
618 set_bit(RX_URB_FAIL, &dev->flags);
621 clear_bit(RX_URB_FAIL, &dev->flags);
626 tasklet_schedule(&dev->tl);
629 static int enable_net_traffic(rtl8150_t * dev)
631 u8 cr, tcr, rcr, msr;
633 if (!rtl8150_reset(dev)) {
634 dev_warn(&dev->udev->dev, "device reset failed\n");
636 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
641 set_bit(RTL8150_HW_CRC, &dev->flags);
642 set_registers(dev, RCR, 1, &rcr);
643 set_registers(dev, TCR, 1, &tcr);
644 set_registers(dev, CR, 1, &cr);
645 get_registers(dev, MSR, 1, &msr);
650 static void disable_net_traffic(rtl8150_t * dev)
654 get_registers(dev, CR, 1, &cr);
656 set_registers(dev, CR, 1, &cr);
659 static void rtl8150_tx_timeout(struct net_device *netdev)
661 rtl8150_t *dev = netdev_priv(netdev);
662 dev_warn(&netdev->dev, "Tx timeout.\n");
663 usb_unlink_urb(dev->tx_urb);
664 netdev->stats.tx_errors++;
667 static void rtl8150_set_multicast(struct net_device *netdev)
669 rtl8150_t *dev = netdev_priv(netdev);
672 netif_stop_queue(netdev);
673 if (netdev->flags & IFF_PROMISC) {
675 dev_info(&netdev->dev, "%s: promiscuous mode\n", netdev->name);
676 } else if (!netdev_mc_empty(netdev) ||
677 (netdev->flags & IFF_ALLMULTI)) {
680 dev_dbg(&netdev->dev, "%s: allmulti set\n", netdev->name);
682 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
685 async_set_registers(dev, RCR, sizeof(rx_creg), rx_creg);
686 netif_wake_queue(netdev);
689 static netdev_tx_t rtl8150_start_xmit(struct sk_buff *skb,
690 struct net_device *netdev)
692 rtl8150_t *dev = netdev_priv(netdev);
695 netif_stop_queue(netdev);
696 count = (skb->len < 60) ? 60 : skb->len;
697 count = (count & 0x3f) ? count : count + 1;
699 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
700 skb->data, count, write_bulk_callback, dev);
701 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
702 /* Can we get/handle EPIPE here? */
704 netif_device_detach(dev->netdev);
706 dev_warn(&netdev->dev, "failed tx_urb %d\n", res);
707 netdev->stats.tx_errors++;
708 netif_start_queue(netdev);
711 netdev->stats.tx_packets++;
712 netdev->stats.tx_bytes += skb->len;
713 netif_trans_update(netdev);
720 static void set_carrier(struct net_device *netdev)
722 rtl8150_t *dev = netdev_priv(netdev);
725 get_registers(dev, CSCR, 2, &tmp);
726 if (tmp & CSCR_LINK_STATUS)
727 netif_carrier_on(netdev);
729 netif_carrier_off(netdev);
732 static int rtl8150_open(struct net_device *netdev)
734 rtl8150_t *dev = netdev_priv(netdev);
737 if (dev->rx_skb == NULL)
738 dev->rx_skb = pull_skb(dev);
742 set_registers(dev, IDR, 6, netdev->dev_addr);
744 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
745 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
746 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
748 netif_device_detach(dev->netdev);
749 dev_warn(&netdev->dev, "rx_urb submit failed: %d\n", res);
752 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
753 dev->intr_buff, INTBUFSIZE, intr_callback,
754 dev, dev->intr_interval);
755 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
757 netif_device_detach(dev->netdev);
758 dev_warn(&netdev->dev, "intr_urb submit failed: %d\n", res);
759 usb_kill_urb(dev->rx_urb);
762 enable_net_traffic(dev);
764 netif_start_queue(netdev);
769 static int rtl8150_close(struct net_device *netdev)
771 rtl8150_t *dev = netdev_priv(netdev);
773 netif_stop_queue(netdev);
774 if (!test_bit(RTL8150_UNPLUG, &dev->flags))
775 disable_net_traffic(dev);
776 unlink_all_urbs(dev);
781 static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
783 rtl8150_t *dev = netdev_priv(netdev);
785 strlcpy(info->driver, driver_name, sizeof(info->driver));
786 strlcpy(info->version, DRIVER_VERSION, sizeof(info->version));
787 usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
790 static int rtl8150_get_link_ksettings(struct net_device *netdev,
791 struct ethtool_link_ksettings *ecmd)
793 rtl8150_t *dev = netdev_priv(netdev);
797 supported = (SUPPORTED_10baseT_Half |
798 SUPPORTED_10baseT_Full |
799 SUPPORTED_100baseT_Half |
800 SUPPORTED_100baseT_Full |
802 SUPPORTED_TP | SUPPORTED_MII);
803 ecmd->base.port = PORT_TP;
804 ecmd->base.phy_address = dev->phy;
805 get_registers(dev, BMCR, 2, &bmcr);
806 get_registers(dev, ANLP, 2, &lpa);
807 if (bmcr & BMCR_ANENABLE) {
808 u32 speed = ((lpa & (LPA_100HALF | LPA_100FULL)) ?
809 SPEED_100 : SPEED_10);
810 ecmd->base.speed = speed;
811 ecmd->base.autoneg = AUTONEG_ENABLE;
812 if (speed == SPEED_100)
813 ecmd->base.duplex = (lpa & LPA_100FULL) ?
814 DUPLEX_FULL : DUPLEX_HALF;
816 ecmd->base.duplex = (lpa & LPA_10FULL) ?
817 DUPLEX_FULL : DUPLEX_HALF;
819 ecmd->base.autoneg = AUTONEG_DISABLE;
820 ecmd->base.speed = ((bmcr & BMCR_SPEED100) ?
821 SPEED_100 : SPEED_10);
822 ecmd->base.duplex = (bmcr & BMCR_FULLDPLX) ?
823 DUPLEX_FULL : DUPLEX_HALF;
826 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported,
832 static const struct ethtool_ops ops = {
833 .get_drvinfo = rtl8150_get_drvinfo,
834 .get_link = ethtool_op_get_link,
835 .get_link_ksettings = rtl8150_get_link_ksettings,
838 static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
840 rtl8150_t *dev = netdev_priv(netdev);
841 u16 *data = (u16 *) & rq->ifr_ifru;
848 case SIOCDEVPRIVATE + 1:
849 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
851 case SIOCDEVPRIVATE + 2:
852 if (!capable(CAP_NET_ADMIN))
854 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
863 static const struct net_device_ops rtl8150_netdev_ops = {
864 .ndo_open = rtl8150_open,
865 .ndo_stop = rtl8150_close,
866 .ndo_do_ioctl = rtl8150_ioctl,
867 .ndo_start_xmit = rtl8150_start_xmit,
868 .ndo_tx_timeout = rtl8150_tx_timeout,
869 .ndo_set_rx_mode = rtl8150_set_multicast,
870 .ndo_set_mac_address = rtl8150_set_mac_address,
872 .ndo_validate_addr = eth_validate_addr,
875 static int rtl8150_probe(struct usb_interface *intf,
876 const struct usb_device_id *id)
878 struct usb_device *udev = interface_to_usbdev(intf);
880 struct net_device *netdev;
882 netdev = alloc_etherdev(sizeof(rtl8150_t));
886 dev = netdev_priv(netdev);
888 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
889 if (!dev->intr_buff) {
894 tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
895 spin_lock_init(&dev->rx_pool_lock);
898 dev->netdev = netdev;
899 netdev->netdev_ops = &rtl8150_netdev_ops;
900 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
901 netdev->ethtool_ops = &ops;
902 dev->intr_interval = 100; /* 100ms */
904 if (!alloc_all_urbs(dev)) {
905 dev_err(&intf->dev, "out of memory\n");
908 if (!rtl8150_reset(dev)) {
909 dev_err(&intf->dev, "couldn't reset the device\n");
913 set_ethernet_addr(dev);
915 usb_set_intfdata(intf, dev);
916 SET_NETDEV_DEV(netdev, &intf->dev);
917 if (register_netdev(netdev) != 0) {
918 dev_err(&intf->dev, "couldn't register the device\n");
922 dev_info(&intf->dev, "%s: rtl8150 is detected\n", netdev->name);
927 usb_set_intfdata(intf, NULL);
932 kfree(dev->intr_buff);
937 static void rtl8150_disconnect(struct usb_interface *intf)
939 rtl8150_t *dev = usb_get_intfdata(intf);
941 usb_set_intfdata(intf, NULL);
943 set_bit(RTL8150_UNPLUG, &dev->flags);
944 tasklet_kill(&dev->tl);
945 unregister_netdev(dev->netdev);
946 unlink_all_urbs(dev);
950 dev_kfree_skb(dev->rx_skb);
951 kfree(dev->intr_buff);
952 free_netdev(dev->netdev);
956 static struct usb_driver rtl8150_driver = {
958 .probe = rtl8150_probe,
959 .disconnect = rtl8150_disconnect,
960 .id_table = rtl8150_table,
961 .suspend = rtl8150_suspend,
962 .resume = rtl8150_resume,
963 .disable_hub_initiated_lpm = 1,
966 module_usb_driver(rtl8150_driver);
968 MODULE_AUTHOR(DRIVER_AUTHOR);
969 MODULE_DESCRIPTION(DRIVER_DESC);
970 MODULE_LICENSE("GPL");