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 = {
181 .probe = rtl8150_probe,
182 .disconnect = rtl8150_disconnect,
183 .id_table = rtl8150_table,
188 ** device related part of the code
191 static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
193 return usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
194 RTL8150_REQ_GET_REGS, RTL8150_REQT_READ,
195 indx, 0, data, size, 500);
198 static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
200 return usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
201 RTL8150_REQ_SET_REGS, RTL8150_REQT_WRITE,
202 indx, 0, data, size, 500);
205 static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
209 switch (urb->status) {
217 warn("ctrl urb status %d", urb->status);
220 clear_bit(RX_REG_SET, &dev->flags);
223 static int async_set_registers(rtl8150_t * dev, u16 indx, u16 size)
227 if (test_bit(RX_REG_SET, &dev->flags))
230 dev->dr.bRequestType = RTL8150_REQT_WRITE;
231 dev->dr.bRequest = RTL8150_REQ_SET_REGS;
232 dev->dr.wValue = cpu_to_le16(indx);
234 dev->dr.wLength = cpu_to_le16(size);
235 dev->ctrl_urb->transfer_buffer_length = size;
236 usb_fill_control_urb(dev->ctrl_urb, dev->udev,
237 usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr,
238 &dev->rx_creg, size, ctrl_callback, dev);
239 if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC)))
240 err("control request submission failed: %d", ret);
242 set_bit(RX_REG_SET, &dev->flags);
247 static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)
253 data[1] = data[2] = 0;
254 tmp = indx | PHY_READ | PHY_GO;
257 set_registers(dev, PHYADD, sizeof(data), data);
258 set_registers(dev, PHYCNT, 1, &tmp);
260 get_registers(dev, PHYCNT, 1, data);
261 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
263 if (i < MII_TIMEOUT) {
264 get_registers(dev, PHYDAT, 2, data);
265 *reg = data[0] | (data[1] << 8);
271 static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
277 *(data + 1) = cpu_to_le16p(®);
278 tmp = indx | PHY_WRITE | PHY_GO;
281 set_registers(dev, PHYADD, sizeof(data), data);
282 set_registers(dev, PHYCNT, 1, &tmp);
284 get_registers(dev, PHYCNT, 1, data);
285 } while ((data[0] & PHY_GO) && (i++ < MII_TIMEOUT));
293 static inline void set_ethernet_addr(rtl8150_t * dev)
297 get_registers(dev, IDR, sizeof(node_id), node_id);
298 memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
301 static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
303 struct sockaddr *addr = p;
304 rtl8150_t *dev = netdev_priv(netdev);
307 if (netif_running(netdev))
310 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
311 dbg("%s: Setting MAC address to ", netdev->name);
312 for (i = 0; i < 5; i++)
313 dbg("%02X:", netdev->dev_addr[i]);
314 dbg("%02X\n", netdev->dev_addr[i]);
315 /* Set the IDR registers. */
316 set_registers(dev, IDR, sizeof(netdev->dev_addr), netdev->dev_addr);
320 /* Get the CR contents. */
321 get_registers(dev, CR, 1, &cr);
322 /* Set the WEPROM bit (eeprom write enable). */
324 set_registers(dev, CR, 1, &cr);
325 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
326 so we need to split them up. */
327 for (i = 0; i * 2 < netdev->addr_len; i++) {
328 set_registers(dev, IDR_EEPROM + (i * 2), 2,
329 netdev->dev_addr + (i * 2));
331 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
333 set_registers(dev, CR, 1, &cr);
339 static int rtl8150_reset(rtl8150_t * dev)
344 set_registers(dev, CR, 1, &data);
346 get_registers(dev, CR, 1, &data);
347 } while ((data & 0x10) && --i);
349 return (i > 0) ? 1 : 0;
352 static int alloc_all_urbs(rtl8150_t * dev)
354 dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
357 dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
359 usb_free_urb(dev->rx_urb);
362 dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
363 if (!dev->intr_urb) {
364 usb_free_urb(dev->rx_urb);
365 usb_free_urb(dev->tx_urb);
368 dev->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
369 if (!dev->intr_urb) {
370 usb_free_urb(dev->rx_urb);
371 usb_free_urb(dev->tx_urb);
372 usb_free_urb(dev->intr_urb);
379 static void free_all_urbs(rtl8150_t * dev)
381 usb_free_urb(dev->rx_urb);
382 usb_free_urb(dev->tx_urb);
383 usb_free_urb(dev->intr_urb);
384 usb_free_urb(dev->ctrl_urb);
387 static void unlink_all_urbs(rtl8150_t * dev)
389 usb_kill_urb(dev->rx_urb);
390 usb_kill_urb(dev->tx_urb);
391 usb_kill_urb(dev->intr_urb);
392 usb_kill_urb(dev->ctrl_urb);
395 static inline struct sk_buff *pull_skb(rtl8150_t *dev)
400 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
401 if (dev->rx_skb_pool[i]) {
402 skb = dev->rx_skb_pool[i];
403 dev->rx_skb_pool[i] = NULL;
410 static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
413 unsigned pkt_len, res;
415 struct net_device *netdev;
421 if (test_bit(RTL8150_UNPLUG, &dev->flags))
423 netdev = dev->netdev;
424 if (!netif_device_present(netdev))
427 switch (urb->status) {
431 return; /* the urb is in unlink state */
433 warn("may be reset is needed?..");
436 warn("Rx status %d", urb->status);
442 /* protect against short packets (tell me why we got some?!?) */
443 if (urb->actual_length < 4)
446 res = urb->actual_length;
447 rx_stat = le16_to_cpu(*(__le16 *)(urb->transfer_buffer + res - 4));
450 skb_put(dev->rx_skb, pkt_len);
451 dev->rx_skb->protocol = eth_type_trans(dev->rx_skb, netdev);
452 netif_rx(dev->rx_skb);
453 dev->stats.rx_packets++;
454 dev->stats.rx_bytes += pkt_len;
456 spin_lock(&dev->rx_pool_lock);
458 spin_unlock(&dev->rx_pool_lock);
464 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
465 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
466 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
467 set_bit(RX_URB_FAIL, &dev->flags);
470 clear_bit(RX_URB_FAIL, &dev->flags);
475 tasklet_schedule(&dev->tl);
478 static void rx_fixup(unsigned long data)
483 dev = (rtl8150_t *)data;
485 spin_lock_irq(&dev->rx_pool_lock);
487 spin_unlock_irq(&dev->rx_pool_lock);
488 if (test_bit(RX_URB_FAIL, &dev->flags))
491 spin_lock_irq(&dev->rx_pool_lock);
493 spin_unlock_irq(&dev->rx_pool_lock);
497 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
498 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
500 if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
501 set_bit(RX_URB_FAIL, &dev->flags);
504 clear_bit(RX_URB_FAIL, &dev->flags);
509 tasklet_schedule(&dev->tl);
512 static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
519 dev_kfree_skb_irq(dev->tx_skb);
520 if (!netif_device_present(dev->netdev))
523 info("%s: Tx status %d", dev->netdev->name, urb->status);
524 dev->netdev->trans_start = jiffies;
525 netif_wake_queue(dev->netdev);
528 static void intr_callback(struct urb *urb, struct pt_regs *regs)
537 switch (urb->status) {
538 case 0: /* success */
540 case -ECONNRESET: /* unlink */
544 /* -EPIPE: should clear the halt */
546 info("%s: intr status %d", dev->netdev->name, urb->status);
550 d = urb->transfer_buffer;
551 if (d[0] & TSR_ERRORS) {
552 dev->stats.tx_errors++;
553 if (d[INT_TSR] & (TSR_ECOL | TSR_JBR))
554 dev->stats.tx_aborted_errors++;
555 if (d[INT_TSR] & TSR_LCOL)
556 dev->stats.tx_window_errors++;
557 if (d[INT_TSR] & TSR_LOSS_CRS)
558 dev->stats.tx_carrier_errors++;
560 /* Report link status changes to the network stack */
561 if ((d[INT_MSR] & MSR_LINK) == 0) {
562 if (netif_carrier_ok(dev->netdev)) {
563 netif_carrier_off(dev->netdev);
564 dbg("%s: LINK LOST\n", __func__);
567 if (!netif_carrier_ok(dev->netdev)) {
568 netif_carrier_on(dev->netdev);
569 dbg("%s: LINK CAME BACK\n", __func__);
574 status = usb_submit_urb (urb, SLAB_ATOMIC);
576 err ("can't resubmit intr, %s-%s/input0, status %d",
577 dev->udev->bus->bus_name,
578 dev->udev->devpath, status);
584 ** network related part of the code
588 static void fill_skb_pool(rtl8150_t *dev)
593 for (i = 0; i < RX_SKB_POOL_SIZE; i++) {
594 if (dev->rx_skb_pool[i])
596 skb = dev_alloc_skb(RTL8150_MTU + 2);
600 skb->dev = dev->netdev;
602 dev->rx_skb_pool[i] = skb;
606 static void free_skb_pool(rtl8150_t *dev)
610 for (i = 0; i < RX_SKB_POOL_SIZE; i++)
611 if (dev->rx_skb_pool[i])
612 dev_kfree_skb(dev->rx_skb_pool[i]);
615 static int enable_net_traffic(rtl8150_t * dev)
617 u8 cr, tcr, rcr, msr;
619 if (!rtl8150_reset(dev)) {
620 warn("%s - device reset failed", __FUNCTION__);
622 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
624 dev->rx_creg = cpu_to_le16(rcr);
628 set_bit(RTL8150_HW_CRC, &dev->flags);
629 set_registers(dev, RCR, 1, &rcr);
630 set_registers(dev, TCR, 1, &tcr);
631 set_registers(dev, CR, 1, &cr);
632 get_registers(dev, MSR, 1, &msr);
637 static void disable_net_traffic(rtl8150_t * dev)
641 get_registers(dev, CR, 1, &cr);
643 set_registers(dev, CR, 1, &cr);
646 static struct net_device_stats *rtl8150_netdev_stats(struct net_device *dev)
648 return &((rtl8150_t *)netdev_priv(dev))->stats;
651 static void rtl8150_tx_timeout(struct net_device *netdev)
653 rtl8150_t *dev = netdev_priv(netdev);
654 warn("%s: Tx timeout.", netdev->name);
655 usb_unlink_urb(dev->tx_urb);
656 dev->stats.tx_errors++;
659 static void rtl8150_set_multicast(struct net_device *netdev)
661 rtl8150_t *dev = netdev_priv(netdev);
662 netif_stop_queue(netdev);
663 if (netdev->flags & IFF_PROMISC) {
664 dev->rx_creg |= cpu_to_le16(0x0001);
665 info("%s: promiscuous mode", netdev->name);
666 } else if (netdev->mc_count ||
667 (netdev->flags & IFF_ALLMULTI)) {
668 dev->rx_creg &= cpu_to_le16(0xfffe);
669 dev->rx_creg |= cpu_to_le16(0x0002);
670 info("%s: allmulti set", netdev->name);
672 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
673 dev->rx_creg &= cpu_to_le16(0x00fc);
675 async_set_registers(dev, RCR, 2);
676 netif_wake_queue(netdev);
679 static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
681 rtl8150_t *dev = netdev_priv(netdev);
684 netif_stop_queue(netdev);
685 count = (skb->len < 60) ? 60 : skb->len;
686 count = (count & 0x3f) ? count : count + 1;
688 usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
689 skb->data, count, write_bulk_callback, dev);
690 if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
691 warn("failed tx_urb %d\n", res);
692 dev->stats.tx_errors++;
693 netif_start_queue(netdev);
695 dev->stats.tx_packets++;
696 dev->stats.tx_bytes += skb->len;
697 netdev->trans_start = jiffies;
704 static void set_carrier(struct net_device *netdev)
706 rtl8150_t *dev = netdev_priv(netdev);
709 get_registers(dev, CSCR, 2, &tmp);
710 if (tmp & CSCR_LINK_STATUS)
711 netif_carrier_on(netdev);
713 netif_carrier_off(netdev);
716 static int rtl8150_open(struct net_device *netdev)
718 rtl8150_t *dev = netdev_priv(netdev);
721 if (dev->rx_skb == NULL)
722 dev->rx_skb = pull_skb(dev);
726 set_registers(dev, IDR, 6, netdev->dev_addr);
728 usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
729 dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
730 if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL)))
731 warn("%s: rx_urb submit failed: %d", __FUNCTION__, res);
732 usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
733 dev->intr_buff, INTBUFSIZE, intr_callback,
734 dev, dev->intr_interval);
735 if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL)))
736 warn("%s: intr_urb submit failed: %d", __FUNCTION__, res);
737 netif_start_queue(netdev);
738 enable_net_traffic(dev);
744 static int rtl8150_close(struct net_device *netdev)
746 rtl8150_t *dev = netdev_priv(netdev);
749 netif_stop_queue(netdev);
750 if (!test_bit(RTL8150_UNPLUG, &dev->flags))
751 disable_net_traffic(dev);
752 unlink_all_urbs(dev);
757 static void rtl8150_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
759 rtl8150_t *dev = netdev_priv(netdev);
761 strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN);
762 strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN);
763 usb_make_path(dev->udev, info->bus_info, sizeof info->bus_info);
766 static int rtl8150_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
768 rtl8150_t *dev = netdev_priv(netdev);
771 ecmd->supported = (SUPPORTED_10baseT_Half |
772 SUPPORTED_10baseT_Full |
773 SUPPORTED_100baseT_Half |
774 SUPPORTED_100baseT_Full |
776 SUPPORTED_TP | SUPPORTED_MII);
777 ecmd->port = PORT_TP;
778 ecmd->transceiver = XCVR_INTERNAL;
779 ecmd->phy_address = dev->phy;
780 get_registers(dev, BMCR, 2, &bmcr);
781 get_registers(dev, ANLP, 2, &lpa);
782 if (bmcr & BMCR_ANENABLE) {
783 ecmd->autoneg = AUTONEG_ENABLE;
784 ecmd->speed = (lpa & (LPA_100HALF | LPA_100FULL)) ?
785 SPEED_100 : SPEED_10;
786 if (ecmd->speed == SPEED_100)
787 ecmd->duplex = (lpa & LPA_100FULL) ?
788 DUPLEX_FULL : DUPLEX_HALF;
790 ecmd->duplex = (lpa & LPA_10FULL) ?
791 DUPLEX_FULL : DUPLEX_HALF;
793 ecmd->autoneg = AUTONEG_DISABLE;
794 ecmd->speed = (bmcr & BMCR_SPEED100) ?
795 SPEED_100 : SPEED_10;
796 ecmd->duplex = (bmcr & BMCR_FULLDPLX) ?
797 DUPLEX_FULL : DUPLEX_HALF;
802 static struct ethtool_ops ops = {
803 .get_drvinfo = rtl8150_get_drvinfo,
804 .get_settings = rtl8150_get_settings,
805 .get_link = ethtool_op_get_link
808 static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
810 rtl8150_t *dev = netdev_priv(netdev);
811 u16 *data = (u16 *) & rq->ifr_ifru;
817 case SIOCDEVPRIVATE + 1:
818 read_mii_word(dev, dev->phy, (data[1] & 0x1f), &data[3]);
820 case SIOCDEVPRIVATE + 2:
821 if (!capable(CAP_NET_ADMIN))
823 write_mii_word(dev, dev->phy, (data[1] & 0x1f), data[2]);
832 static int rtl8150_probe(struct usb_interface *intf,
833 const struct usb_device_id *id)
835 struct usb_device *udev = interface_to_usbdev(intf);
837 struct net_device *netdev;
839 netdev = alloc_etherdev(sizeof(rtl8150_t));
841 err("Out of memory");
845 dev = netdev_priv(netdev);
846 memset(dev, 0, sizeof(rtl8150_t));
848 dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
849 if (!dev->intr_buff) {
854 tasklet_init(&dev->tl, rx_fixup, (unsigned long)dev);
855 spin_lock_init(&dev->rx_pool_lock);
858 dev->netdev = netdev;
859 SET_MODULE_OWNER(netdev);
860 netdev->open = rtl8150_open;
861 netdev->stop = rtl8150_close;
862 netdev->do_ioctl = rtl8150_ioctl;
863 netdev->watchdog_timeo = RTL8150_TX_TIMEOUT;
864 netdev->tx_timeout = rtl8150_tx_timeout;
865 netdev->hard_start_xmit = rtl8150_start_xmit;
866 netdev->set_multicast_list = rtl8150_set_multicast;
867 netdev->set_mac_address = rtl8150_set_mac_address;
868 netdev->get_stats = rtl8150_netdev_stats;
869 netdev->mtu = RTL8150_MTU;
870 SET_ETHTOOL_OPS(netdev, &ops);
871 dev->intr_interval = 100; /* 100ms */
873 if (!alloc_all_urbs(dev)) {
874 err("out of memory");
877 if (!rtl8150_reset(dev)) {
878 err("couldn't reset the device");
882 set_ethernet_addr(dev);
884 usb_set_intfdata(intf, dev);
885 SET_NETDEV_DEV(netdev, &intf->dev);
886 if (register_netdev(netdev) != 0) {
887 err("couldn't register the device");
891 info("%s: rtl8150 is detected", netdev->name);
896 usb_set_intfdata(intf, NULL);
901 kfree(dev->intr_buff);
906 static void rtl8150_disconnect(struct usb_interface *intf)
908 rtl8150_t *dev = usb_get_intfdata(intf);
910 usb_set_intfdata(intf, NULL);
912 set_bit(RTL8150_UNPLUG, &dev->flags);
913 tasklet_disable(&dev->tl);
914 unregister_netdev(dev->netdev);
915 unlink_all_urbs(dev);
919 dev_kfree_skb(dev->rx_skb);
920 kfree(dev->intr_buff);
921 free_netdev(dev->netdev);
925 static int __init usb_rtl8150_init(void)
927 info(DRIVER_DESC " " DRIVER_VERSION);
928 return usb_register(&rtl8150_driver);
931 static void __exit usb_rtl8150_exit(void)
933 usb_deregister(&rtl8150_driver);
936 module_init(usb_rtl8150_init);
937 module_exit(usb_rtl8150_exit);
939 MODULE_AUTHOR(DRIVER_AUTHOR);
940 MODULE_DESCRIPTION(DRIVER_DESC);
941 MODULE_LICENSE("GPL");