2 * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
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.
9 #include <linux/config.h>
10 #include <linux/sched.h>
11 #include <linux/init.h>
12 #include <linux/signal.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/mii.h>
18 #include <linux/ethtool.h>
19 #include <linux/usb.h>
20 #include <asm/uaccess.h>
22 /* Version Information */
23 #define DRIVER_VERSION "v0.6.2 (2004/08/27)"
24 #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
25 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
46 #define CSCR 0x014C /* This one has the link status */
47 #define CSCR_LINK_STATUS (1 << 3)
49 #define IDR_EEPROM 0x1202
52 #define PHY_WRITE 0x20
55 #define MII_TIMEOUT 10
58 #define RTL8150_REQT_READ 0xc0
59 #define RTL8150_REQT_WRITE 0x40
60 #define RTL8150_REQ_GET_REGS 0x05
61 #define RTL8150_REQ_SET_REGS 0x05
64 /* Transmit status register errors */
65 #define TSR_ECOL (1<<5)
66 #define TSR_LCOL (1<<4)
67 #define TSR_LOSS_CRS (1<<3)
68 #define TSR_JBR (1<<2)
69 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
70 /* Receive status register errors */
71 #define RSR_CRC (1<<2)
72 #define RSR_FAE (1<<1)
73 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
75 /* Media status register definitions */
76 #define MSR_DUPLEX (1<<4)
77 #define MSR_SPEED (1<<3)
78 #define MSR_LINK (1<<2)
80 /* Interrupt pipe data */
84 #define INT_WAKSR 0x03
85 #define INT_TXOK_CNT 0x04
86 #define INT_RXLOST_CNT 0x05
87 #define INT_CRERR_CNT 0x06
88 #define INT_COL_CNT 0x07
90 /* Transmit status register errors */
91 #define TSR_ECOL (1<<5)
92 #define TSR_LCOL (1<<4)
93 #define TSR_LOSS_CRS (1<<3)
94 #define TSR_JBR (1<<2)
95 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
96 /* Receive status register errors */
97 #define RSR_CRC (1<<2)
98 #define RSR_FAE (1<<1)
99 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
101 /* Media status register definitions */
102 #define MSR_DUPLEX (1<<4)
103 #define MSR_SPEED (1<<3)
104 #define MSR_LINK (1<<2)
106 /* Interrupt pipe data */
110 #define INT_WAKSR 0x03
111 #define INT_TXOK_CNT 0x04
112 #define INT_RXLOST_CNT 0x05
113 #define INT_CRERR_CNT 0x06
114 #define INT_COL_CNT 0x07
117 #define RTL8150_MTU 1540
118 #define RTL8150_TX_TIMEOUT (HZ)
119 #define RX_SKB_POOL_SIZE 4
122 #define RTL8150_HW_CRC 0
124 #define RTL8150_UNPLUG 2
125 #define RX_URB_FAIL 3
127 /* Define these values to match your device */
128 #define VENDOR_ID_REALTEK 0x0bda
129 #define VENDOR_ID_MELCO 0x0411
130 #define VENDOR_ID_MICRONET 0x3980
131 #define VENDOR_ID_LONGSHINE 0x07b8
133 #define PRODUCT_ID_RTL8150 0x8150
134 #define PRODUCT_ID_LUAKTX 0x0012
135 #define PRODUCT_ID_LCS8138TX 0x401a
136 #define PRODUCT_ID_SP128AR 0x0003
140 /* table of devices that work with this driver */
141 static struct usb_device_id rtl8150_table[] = {
142 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8150)},
143 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
144 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
145 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
149 MODULE_DEVICE_TABLE(usb, rtl8150_table);
153 struct usb_device *udev;
154 struct tasklet_struct tl;
155 struct net_device_stats stats;
156 struct net_device *netdev;
157 struct urb *rx_urb, *tx_urb, *intr_urb, *ctrl_urb;
158 struct sk_buff *tx_skb, *rx_skb;
159 struct sk_buff *rx_skb_pool[RX_SKB_POOL_SIZE];
160 spinlock_t rx_pool_lock;
161 struct usb_ctrlrequest dr;
168 typedef struct rtl8150 rtl8150_t;
170 static void fill_skb_pool(rtl8150_t *);
171 static void free_skb_pool(rtl8150_t *);
172 static inline struct sk_buff *pull_skb(rtl8150_t *);
173 static void rtl8150_disconnect(struct usb_interface *intf);
174 static int rtl8150_probe(struct usb_interface *intf,
175 const struct usb_device_id *id);
177 static const char driver_name [] = "rtl8150";
179 static struct usb_driver rtl8150_driver = {
180 .owner = THIS_MODULE,
182 .probe = rtl8150_probe,
183 .disconnect = rtl8150_disconnect,
184 .id_table = rtl8150_table,
189 ** device related part of the code
192 static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
194 return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
195 RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
196 indx, 0, data, size, 500);
199 static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
201 return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
202 RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
203 indx, 0, data, size, 500);
206 static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
210 switch (urb->status) {
218 warn("ctrl urb status %d", urb->status);
221 clear_bit(RX_REG_SET, &dev->flags);
224 static int async_set_registers(rtl8150_t * dev, u16 indx, u16 size)
228 if (test_bit(RX_REG_SET, &dev->flags))
231 dev->dr.bRequestType = RTL8150_REQT_WRITE;
232 dev->dr.bRequest = RTL8150_REQ_SET_REGS;
233 dev->dr.wValue = cpu_to_le16(indx);
235 dev->dr.wLength = cpu_to_le16(size);
236 dev->ctrl_urb->transfer_buffer_length = size;
237 usb_fill_control_urb(dev->ctrl_urb, dev->udev,
238 usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr,
239 &dev->rx_creg, size, ctrl_callback, dev);
240 if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC)))
241 err("control request submission failed: %d", ret);
243 set_bit(RX_REG_SET, &dev->flags);
248 static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
254 data[1] = data[2] = 0;
255 tmp = indx | PHY_READ | PHY_GO;
258 set_registers(dev, PHYADD, sizeof(data), data);
259 set_registers(dev, PHYCNT, 1, &tmp);
261 get_registers(dev, PHYCNT, 1, data);
262 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
264 if (i < MII_TIMEOUT) {
265 get_registers(dev, PHYDAT, 2, data);
266 *reg = data[0] | (data[1] << 8);
272 static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
278 *(data + 1) = cpu_to_le16p(®);
279 tmp = indx | PHY_WRITE | PHY_GO;
282 set_registers(dev, PHYADD, sizeof(data), data);
283 set_registers(dev, PHYCNT, 1, &tmp);
285 get_registers(dev, PHYCNT, 1, data);
286 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
294 static inline void set_ethernet_addr(rtl8150_t * dev)
298 get_registers(dev, IDR, sizeof(node_id), node_id);
299 memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
302 static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
304 struct sockaddr *addr = p;
305 rtl8150_t *dev = netdev_priv(netdev);
308 if (netif_running(netdev))
311 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
312 dbg("%s: Setting MAC address to ", netdev->name);
313 for (i = 0; i < 5; i++)
314 dbg("%02X:", netdev->dev_addr[i]);
315 dbg("%02X\n", netdev->dev_addr[i]);
316 /* Set the IDR registers. */
317 set_registers(dev, IDR, sizeof(netdev->dev_addr), netdev->dev_addr);
321 /* Get the CR contents. */
322 get_registers(dev, CR, 1, &cr);
323 /* Set the WEPROM bit (eeprom write enable). */
325 set_registers(dev, CR, 1, &cr);
326 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
327 so we need to split them up. */
328 for (i = 0; i * 2 < netdev->addr_len; i++) {
329 set_registers(dev, IDR_EEPROM + (i * 2), 2,
330 netdev->dev_addr + (i * 2));
332 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
334 set_registers(dev, CR, 1, &cr);
340 static int rtl8150_reset(rtl8150_t * dev)
345 set_registers(dev, CR, 1, &data);
347 get_registers(dev, CR, 1, &data);
348 } while ((data & 0x10) && --i);
350 return (i > 0) ? 1 : 0;
353 static int alloc_all_urbs(rtl8150_t * dev)
355 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
358 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
360 usb_free_urb(dev->rx_urb);
363 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
364 if (!dev->intr_urb) {
365 usb_free_urb(dev->rx_urb);
366 usb_free_urb(dev->tx_urb);
369 dev->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
370 if (!dev->intr_urb) {
371 usb_free_urb(dev->rx_urb);
372 usb_free_urb(dev->tx_urb);
373 usb_free_urb(dev->intr_urb);
380 static void free_all_urbs(rtl8150_t * dev)
382 usb_free_urb(dev->rx_urb);
383 usb_free_urb(dev->tx_urb);
384 usb_free_urb(dev->intr_urb);
385 usb_free_urb(dev->ctrl_urb);
388 static void unlink_all_urbs(rtl8150_t * dev)
390 usb_kill_urb(dev->rx_urb);
391 usb_kill_urb(dev->tx_urb);
392 usb_kill_urb(dev->intr_urb);
393 usb_kill_urb(dev->ctrl_urb);
396 static inline struct sk_buff *pull_skb(rtl8150_t *dev)
401 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
402 if (dev->rx_skb_pool[i]) {
403 skb = dev->rx_skb_pool[i];
404 dev->rx_skb_pool[i] = NULL;
411 static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
414 unsigned pkt_len, res;
416 struct net_device *netdev;
422 if (test_bit(RTL8150_UNPLUG, &dev->flags))
424 netdev = dev->netdev;
425 if (!netif_device_present(netdev))
428 switch (urb->status) {
432 return; /* the urb is in unlink state */
434 warn("may be reset is needed?..");
437 warn("Rx status %d", urb->status);
443 /* protect against short packets (tell me why we got some?!?) */
444 if (urb->actual_length < 4)
447 res = urb->actual_length;
448 rx_stat = le16_to_cpu(*(__le16 *)(urb->transfer_buffer + res - 4));
451 skb_put(dev->rx_skb, pkt_len);
452 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
453 netif_rx(dev->rx_skb);
454 dev->stats.rx_packets++;
455 dev->stats.rx_bytes += pkt_len;
457 spin_lock(&dev->rx_pool_lock);
459 spin_unlock(&dev->rx_pool_lock);
465 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
466 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
467 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
468 set_bit(RX_URB_FAIL, &dev->flags);
471 clear_bit(RX_URB_FAIL, &dev->flags);
476 tasklet_schedule(&dev->tl);
479 static void rx_fixup(unsigned long data)
484 dev = (rtl8150_t *)data;
486 spin_lock_irq(&dev->rx_pool_lock);
488 spin_unlock_irq(&dev->rx_pool_lock);
489 if (test_bit(RX_URB_FAIL, &dev->flags))
492 spin_lock_irq(&dev->rx_pool_lock);
494 spin_unlock_irq(&dev->rx_pool_lock);
498 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
499 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
501 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
502 set_bit(RX_URB_FAIL, &dev->flags);
505 clear_bit(RX_URB_FAIL, &dev->flags);
510 tasklet_schedule(&dev->tl);
513 static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
520 dev_kfree_skb_irq(dev->tx_skb);
521 if (!netif_device_present(dev->netdev))
524 info("%s: Tx status %d", dev->netdev->name, urb->status);
525 dev->netdev->trans_start = jiffies;
526 netif_wake_queue(dev->netdev);
529 static void intr_callback(struct urb *urb, struct pt_regs *regs)
538 switch (urb->status) {
539 case 0: /* success */
541 case -ECONNRESET: /* unlink */
545 /* -EPIPE: should clear the halt */
547 info("%s: intr status %d", dev->netdev->name, urb->status);
551 d = urb->transfer_buffer;
552 if (d[0] & TSR_ERRORS) {
553 dev->stats.tx_errors++;
554 if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
555 dev->stats.tx_aborted_errors++;
556 if (d[INT_TSR] & TSR_LCOL)
557 dev->stats.tx_window_errors++;
558 if (d[INT_TSR] & TSR_LOSS_CRS)
559 dev->stats.tx_carrier_errors++;
561 /* Report link status changes to the network stack */
562 if ((d[INT_MSR] & MSR_LINK) == 0) {
563 if (netif_carrier_ok(dev->netdev)) {
564 netif_carrier_off(dev->netdev);
565 dbg("%s: LINK LOST\n", __func__);
568 if (!netif_carrier_ok(dev->netdev)) {
569 netif_carrier_on(dev->netdev);
570 dbg("%s: LINK CAME BACK\n", __func__);
575 status = usb_submit_urb (urb, SLAB_ATOMIC);
577 err ("can't resubmit intr, %s-%s/input0, status %d",
578 dev->udev->bus->bus_name,
579 dev->udev->devpath, status);
585 ** network related part of the code
589 static void fill_skb_pool(rtl8150_t *dev)
594 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
595 if (dev->rx_skb_pool[i])
597 skb = dev_alloc_skb(RTL8150_MTU + 2);
601 skb->dev = dev->netdev;
603 dev->rx_skb_pool[i] = skb;
607 static void free_skb_pool(rtl8150_t *dev)
611 for (i = 0; i < RX_SKB_POOL_SIZE; i++)
612 if (dev->rx_skb_pool[i])
613 dev_kfree_skb(dev->rx_skb_pool[i]);
616 static int enable_net_traffic(rtl8150_t * dev)
618 u8 cr, tcr, rcr, msr;
620 if (!rtl8150_reset(dev)) {
621 warn("%s - device reset failed", __FUNCTION__);
623 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
625 dev->rx_creg = cpu_to_le16(rcr);
629 set_bit(RTL8150_HW_CRC, &dev->flags);
630 set_registers(dev, RCR, 1, &rcr);
631 set_registers(dev, TCR, 1, &tcr);
632 set_registers(dev, CR, 1, &cr);
633 get_registers(dev, MSR, 1, &msr);
638 static void disable_net_traffic(rtl8150_t * dev)
642 get_registers(dev, CR, 1, &cr);
644 set_registers(dev, CR, 1, &cr);
647 static struct net_device_stats *rtl8150_netdev_stats(struct net_device *dev)
649 return &((rtl8150_t *)netdev_priv(dev))->stats;
652 static void rtl8150_tx_timeout(struct net_device *netdev)
654 rtl8150_t *dev = netdev_priv(netdev);
655 warn("%s: Tx timeout.", netdev->name);
656 usb_unlink_urb(dev->tx_urb);
657 dev->stats.tx_errors++;
660 static void rtl8150_set_multicast(struct net_device *netdev)
662 rtl8150_t *dev = netdev_priv(netdev);
663 netif_stop_queue(netdev);
664 if (netdev->flags & IFF_PROMISC) {
665 dev->rx_creg |= cpu_to_le16(0x0001);
666 info("%s: promiscuous mode", netdev->name);
667 } else if (netdev->mc_count ||
668 (netdev->flags & IFF_ALLMULTI)) {
669 dev->rx_creg &= cpu_to_le16(0xfffe);
670 dev->rx_creg |= cpu_to_le16(0x0002);
671 info("%s: allmulti set", netdev->name);
673 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
674 dev->rx_creg &= cpu_to_le16(0x00fc);
676 async_set_registers(dev, RCR, 2);
677 netif_wake_queue(netdev);
680 static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
682 rtl8150_t *dev = netdev_priv(netdev);
685 netif_stop_queue(netdev);
686 count = (skb->len < 60) ? 60 : skb->len;
687 count = (count & 0x3f) ? count : count + 1;
689 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
690 skb->data, count, write_bulk_callback, dev);
691 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
692 warn("failed tx_urb %d\n", res);
693 dev->stats.tx_errors++;
694 netif_start_queue(netdev);
696 dev->stats.tx_packets++;
697 dev->stats.tx_bytes += skb->len;
698 netdev->trans_start = jiffies;
705 static void set_carrier(struct net_device *netdev)
707 rtl8150_t *dev = netdev_priv(netdev);
710 get_registers(dev, CSCR, 2, &tmp);
711 if (tmp & CSCR_LINK_STATUS)
712 netif_carrier_on(netdev);
714 netif_carrier_off(netdev);
717 static int rtl8150_open(struct net_device *netdev)
719 rtl8150_t *dev = netdev_priv(netdev);
722 if (dev->rx_skb == NULL)
723 dev->rx_skb = pull_skb(dev);
727 set_registers(dev, IDR, 6, netdev->dev_addr);
729 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
730 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
731 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL)))
732 warn("%s: rx_urb submit failed: %d", __FUNCTION__, res);
733 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
734 dev->intr_buff, INTBUFSIZE, intr_callback,
735 dev, dev->intr_interval);
736 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL)))
737 warn("%s: intr_urb submit failed: %d", __FUNCTION__, res);
738 netif_start_queue(netdev);
739 enable_net_traffic(dev);
745 static int rtl8150_close(struct net_device *netdev)
747 rtl8150_t *dev = netdev_priv(netdev);
750 netif_stop_queue(netdev);
751 if (!test_bit(RTL8150_UNPLUG, &dev->flags))
752 disable_net_traffic(dev);
753 unlink_all_urbs(dev);
758 static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
760 rtl8150_t *dev = netdev_priv(netdev);
762 strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN);
763 strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
764 usb_make_path(dev->udev, info->bus_info, sizeof info->bus_info);
767 static int rtl8150_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
769 rtl8150_t *dev = netdev_priv(netdev);
772 ecmd->supported = (SUPPORTED_10baseT_Half |
773 SUPPORTED_10baseT_Full |
774 SUPPORTED_100baseT_Half |
775 SUPPORTED_100baseT_Full |
777 SUPPORTED_TP | SUPPORTED_MII);
778 ecmd->port = PORT_TP;
779 ecmd->transceiver = XCVR_INTERNAL;
780 ecmd->phy_address = dev->phy;
781 get_registers(dev, BMCR, 2, &bmcr);
782 get_registers(dev, ANLP, 2, &lpa);
783 if (bmcr & BMCR_ANENABLE) {
784 ecmd->autoneg = AUTONEG_ENABLE;
785 ecmd->speed = (lpa & (LPA_100HALF | LPA_100FULL)) ?
786 SPEED_100 : SPEED_10;
787 if (ecmd->speed == SPEED_100)
788 ecmd->duplex = (lpa & LPA_100FULL) ?
789 DUPLEX_FULL : DUPLEX_HALF;
791 ecmd->duplex = (lpa & LPA_10FULL) ?
792 DUPLEX_FULL : DUPLEX_HALF;
794 ecmd->autoneg = AUTONEG_DISABLE;
795 ecmd->speed = (bmcr & BMCR_SPEED100) ?
796 SPEED_100 : SPEED_10;
797 ecmd->duplex = (bmcr & BMCR_FULLDPLX) ?
798 DUPLEX_FULL : DUPLEX_HALF;
803 static struct ethtool_ops ops = {
804 .get_drvinfo = rtl8150_get_drvinfo,
805 .get_settings = rtl8150_get_settings,
806 .get_link = ethtool_op_get_link
809 static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
811 rtl8150_t *dev = netdev_priv(netdev);
812 u16 *data = (u16 *) & rq->ifr_ifru;
818 case SIOCDEVPRIVATE + 1:
819 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
821 case SIOCDEVPRIVATE + 2:
822 if (!capable(CAP_NET_ADMIN))
824 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
833 static int rtl8150_probe(struct usb_interface *intf,
834 const struct usb_device_id *id)
836 struct usb_device *udev = interface_to_usbdev(intf);
838 struct net_device *netdev;
840 netdev = alloc_etherdev(sizeof(rtl8150_t));
842 err("Out of memory");
846 dev = netdev_priv(netdev);
847 memset(dev, 0, sizeof(rtl8150_t));
849 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
850 if (!dev->intr_buff) {
855 tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
856 spin_lock_init(&dev->rx_pool_lock);
859 dev->netdev = netdev;
860 SET_MODULE_OWNER(netdev);
861 netdev->open = rtl8150_open;
862 netdev->stop = rtl8150_close;
863 netdev->do_ioctl = rtl8150_ioctl;
864 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
865 netdev->tx_timeout = rtl8150_tx_timeout;
866 netdev->hard_start_xmit = rtl8150_start_xmit;
867 netdev->set_multicast_list = rtl8150_set_multicast;
868 netdev->set_mac_address = rtl8150_set_mac_address;
869 netdev->get_stats = rtl8150_netdev_stats;
870 netdev->mtu = RTL8150_MTU;
871 SET_ETHTOOL_OPS(netdev, &ops);
872 dev->intr_interval = 100; /* 100ms */
874 if (!alloc_all_urbs(dev)) {
875 err("out of memory");
878 if (!rtl8150_reset(dev)) {
879 err("couldn't reset the device");
883 set_ethernet_addr(dev);
884 info("%s: rtl8150 is detected", netdev->name);
886 usb_set_intfdata(intf, dev);
887 SET_NETDEV_DEV(netdev, &intf->dev);
888 if (register_netdev(netdev) != 0) {
889 err("couldn't register the device");
895 usb_set_intfdata(intf, NULL);
900 kfree(dev->intr_buff);
905 static void rtl8150_disconnect(struct usb_interface *intf)
907 rtl8150_t *dev = usb_get_intfdata(intf);
909 usb_set_intfdata(intf, NULL);
911 set_bit(RTL8150_UNPLUG, &dev->flags);
912 tasklet_disable(&dev->tl);
913 unregister_netdev(dev->netdev);
914 unlink_all_urbs(dev);
918 dev_kfree_skb(dev->rx_skb);
919 kfree(dev->intr_buff);
920 free_netdev(dev->netdev);
924 static int __init usb_rtl8150_init(void)
926 info(DRIVER_DESC " " DRIVER_VERSION);
927 return usb_register(&rtl8150_driver);
930 static void __exit usb_rtl8150_exit(void)
932 usb_deregister(&rtl8150_driver);
935 module_init(usb_rtl8150_init);
936 module_exit(usb_rtl8150_exit);
938 MODULE_AUTHOR(DRIVER_AUTHOR);
939 MODULE_DESCRIPTION(DRIVER_DESC);
940 MODULE_LICENSE("GPL");