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 dev
->tx_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
657 usb_unlink_urb(dev
->tx_urb
);
658 dev
->stats
.tx_errors
++;
661 static void rtl8150_set_multicast(struct net_device
*netdev
)
663 rtl8150_t
*dev
= netdev_priv(netdev
);
664 netif_stop_queue(netdev
);
665 if (netdev
->flags
& IFF_PROMISC
) {
666 dev
->rx_creg
|= cpu_to_le16(0x0001);
667 info("%s: promiscuous mode", netdev
->name
);
668 } else if (netdev
->mc_count
||
669 (netdev
->flags
& IFF_ALLMULTI
)) {
670 dev
->rx_creg
&= cpu_to_le16(0xfffe);
671 dev
->rx_creg
|= cpu_to_le16(0x0002);
672 info("%s: allmulti set", netdev
->name
);
674 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
675 dev
->rx_creg
&= cpu_to_le16(0x00fc);
677 async_set_registers(dev
, RCR
, 2);
678 netif_wake_queue(netdev
);
681 static int rtl8150_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
683 rtl8150_t
*dev
= netdev_priv(netdev
);
686 netif_stop_queue(netdev
);
687 count
= (skb
->len
< 60) ? 60 : skb
->len
;
688 count
= (count
& 0x3f) ? count
: count
+ 1;
690 usb_fill_bulk_urb(dev
->tx_urb
, dev
->udev
, usb_sndbulkpipe(dev
->udev
, 2),
691 skb
->data
, count
, write_bulk_callback
, dev
);
692 if ((res
= usb_submit_urb(dev
->tx_urb
, GFP_ATOMIC
))) {
693 warn("failed tx_urb %d\n", res
);
694 dev
->stats
.tx_errors
++;
695 netif_start_queue(netdev
);
697 dev
->stats
.tx_packets
++;
698 dev
->stats
.tx_bytes
+= skb
->len
;
699 netdev
->trans_start
= jiffies
;
706 static void set_carrier(struct net_device
*netdev
)
708 rtl8150_t
*dev
= netdev_priv(netdev
);
711 get_registers(dev
, CSCR
, 2, &tmp
);
712 if (tmp
& CSCR_LINK_STATUS
)
713 netif_carrier_on(netdev
);
715 netif_carrier_off(netdev
);
718 static int rtl8150_open(struct net_device
*netdev
)
720 rtl8150_t
*dev
= netdev_priv(netdev
);
723 if (dev
->rx_skb
== NULL
)
724 dev
->rx_skb
= pull_skb(dev
);
728 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
730 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
731 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
732 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
)))
733 warn("%s: rx_urb submit failed: %d", __FUNCTION__
, res
);
734 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
735 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
736 dev
, dev
->intr_interval
);
737 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
)))
738 warn("%s: intr_urb submit failed: %d", __FUNCTION__
, res
);
739 netif_start_queue(netdev
);
740 enable_net_traffic(dev
);
746 static int rtl8150_close(struct net_device
*netdev
)
748 rtl8150_t
*dev
= netdev_priv(netdev
);
751 netif_stop_queue(netdev
);
752 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
753 disable_net_traffic(dev
);
754 unlink_all_urbs(dev
);
759 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
761 rtl8150_t
*dev
= netdev_priv(netdev
);
763 strncpy(info
->driver
, driver_name
, ETHTOOL_BUSINFO_LEN
);
764 strncpy(info
->version
, DRIVER_VERSION
, ETHTOOL_BUSINFO_LEN
);
765 usb_make_path(dev
->udev
, info
->bus_info
, sizeof info
->bus_info
);
768 static int rtl8150_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
770 rtl8150_t
*dev
= netdev_priv(netdev
);
773 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
774 SUPPORTED_10baseT_Full
|
775 SUPPORTED_100baseT_Half
|
776 SUPPORTED_100baseT_Full
|
778 SUPPORTED_TP
| SUPPORTED_MII
);
779 ecmd
->port
= PORT_TP
;
780 ecmd
->transceiver
= XCVR_INTERNAL
;
781 ecmd
->phy_address
= dev
->phy
;
782 get_registers(dev
, BMCR
, 2, &bmcr
);
783 get_registers(dev
, ANLP
, 2, &lpa
);
784 if (bmcr
& BMCR_ANENABLE
) {
785 ecmd
->autoneg
= AUTONEG_ENABLE
;
786 ecmd
->speed
= (lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
787 SPEED_100
: SPEED_10
;
788 if (ecmd
->speed
== SPEED_100
)
789 ecmd
->duplex
= (lpa
& LPA_100FULL
) ?
790 DUPLEX_FULL
: DUPLEX_HALF
;
792 ecmd
->duplex
= (lpa
& LPA_10FULL
) ?
793 DUPLEX_FULL
: DUPLEX_HALF
;
795 ecmd
->autoneg
= AUTONEG_DISABLE
;
796 ecmd
->speed
= (bmcr
& BMCR_SPEED100
) ?
797 SPEED_100
: SPEED_10
;
798 ecmd
->duplex
= (bmcr
& BMCR_FULLDPLX
) ?
799 DUPLEX_FULL
: DUPLEX_HALF
;
804 static struct ethtool_ops ops
= {
805 .get_drvinfo
= rtl8150_get_drvinfo
,
806 .get_settings
= rtl8150_get_settings
,
807 .get_link
= ethtool_op_get_link
810 static int rtl8150_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
812 rtl8150_t
*dev
= netdev_priv(netdev
);
813 u16
*data
= (u16
*) & rq
->ifr_ifru
;
819 case SIOCDEVPRIVATE
+ 1:
820 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
822 case SIOCDEVPRIVATE
+ 2:
823 if (!capable(CAP_NET_ADMIN
))
825 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
834 static int rtl8150_probe(struct usb_interface
*intf
,
835 const struct usb_device_id
*id
)
837 struct usb_device
*udev
= interface_to_usbdev(intf
);
839 struct net_device
*netdev
;
841 netdev
= alloc_etherdev(sizeof(rtl8150_t
));
843 err("Out of memory");
847 dev
= netdev_priv(netdev
);
848 memset(dev
, 0, sizeof(rtl8150_t
));
850 dev
->intr_buff
= kmalloc(INTBUFSIZE
, GFP_KERNEL
);
851 if (!dev
->intr_buff
) {
856 tasklet_init(&dev
->tl
, rx_fixup
, (unsigned long)dev
);
857 spin_lock_init(&dev
->rx_pool_lock
);
860 dev
->netdev
= netdev
;
861 SET_MODULE_OWNER(netdev
);
862 netdev
->open
= rtl8150_open
;
863 netdev
->stop
= rtl8150_close
;
864 netdev
->do_ioctl
= rtl8150_ioctl
;
865 netdev
->watchdog_timeo
= RTL8150_TX_TIMEOUT
;
866 netdev
->tx_timeout
= rtl8150_tx_timeout
;
867 netdev
->hard_start_xmit
= rtl8150_start_xmit
;
868 netdev
->set_multicast_list
= rtl8150_set_multicast
;
869 netdev
->set_mac_address
= rtl8150_set_mac_address
;
870 netdev
->get_stats
= rtl8150_netdev_stats
;
871 netdev
->mtu
= RTL8150_MTU
;
872 SET_ETHTOOL_OPS(netdev
, &ops
);
873 dev
->intr_interval
= 100; /* 100ms */
875 if (!alloc_all_urbs(dev
)) {
876 err("out of memory");
879 if (!rtl8150_reset(dev
)) {
880 err("couldn't reset the device");
884 set_ethernet_addr(dev
);
885 info("%s: rtl8150 is detected", netdev
->name
);
887 usb_set_intfdata(intf
, dev
);
888 SET_NETDEV_DEV(netdev
, &intf
->dev
);
889 if (register_netdev(netdev
) != 0) {
890 err("couldn't register the device");
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 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");