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 unsigned long multicast_filter_limit
= 32;
172 static void fill_skb_pool(rtl8150_t
*);
173 static void free_skb_pool(rtl8150_t
*);
174 static inline struct sk_buff
*pull_skb(rtl8150_t
*);
175 static void rtl8150_disconnect(struct usb_interface
*intf
);
176 static int rtl8150_probe(struct usb_interface
*intf
,
177 const struct usb_device_id
*id
);
179 static const char driver_name
[] = "rtl8150";
181 static struct usb_driver rtl8150_driver
= {
182 .owner
= THIS_MODULE
,
184 .probe
= rtl8150_probe
,
185 .disconnect
= rtl8150_disconnect
,
186 .id_table
= rtl8150_table
,
191 ** device related part of the code
194 static int get_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
196 return usb_control_msg(dev
->udev
, usb_rcvctrlpipe(dev
->udev
, 0),
197 RTL8150_REQ_GET_REGS
, RTL8150_REQT_READ
,
198 indx
, 0, data
, size
, 500);
201 static int set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
203 return usb_control_msg(dev
->udev
, usb_sndctrlpipe(dev
->udev
, 0),
204 RTL8150_REQ_SET_REGS
, RTL8150_REQT_WRITE
,
205 indx
, 0, data
, size
, 500);
208 static void ctrl_callback(struct urb
*urb
, struct pt_regs
*regs
)
212 switch (urb
->status
) {
220 warn("ctrl urb status %d", urb
->status
);
223 clear_bit(RX_REG_SET
, &dev
->flags
);
226 static int async_set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
)
230 if (test_bit(RX_REG_SET
, &dev
->flags
))
233 dev
->dr
.bRequestType
= RTL8150_REQT_WRITE
;
234 dev
->dr
.bRequest
= RTL8150_REQ_SET_REGS
;
235 dev
->dr
.wValue
= cpu_to_le16(indx
);
237 dev
->dr
.wLength
= cpu_to_le16(size
);
238 dev
->ctrl_urb
->transfer_buffer_length
= size
;
239 usb_fill_control_urb(dev
->ctrl_urb
, dev
->udev
,
240 usb_sndctrlpipe(dev
->udev
, 0), (char *) &dev
->dr
,
241 &dev
->rx_creg
, size
, ctrl_callback
, dev
);
242 if ((ret
= usb_submit_urb(dev
->ctrl_urb
, GFP_ATOMIC
)))
243 err("control request submission failed: %d", ret
);
245 set_bit(RX_REG_SET
, &dev
->flags
);
250 static int read_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16
* reg
)
256 data
[1] = data
[2] = 0;
257 tmp
= indx
| PHY_READ
| PHY_GO
;
260 set_registers(dev
, PHYADD
, sizeof(data
), data
);
261 set_registers(dev
, PHYCNT
, 1, &tmp
);
263 get_registers(dev
, PHYCNT
, 1, data
);
264 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
266 if (i
< MII_TIMEOUT
) {
267 get_registers(dev
, PHYDAT
, 2, data
);
268 *reg
= data
[0] | (data
[1] << 8);
274 static int write_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16 reg
)
280 *(data
+ 1) = cpu_to_le16p(®
);
281 tmp
= indx
| PHY_WRITE
| PHY_GO
;
284 set_registers(dev
, PHYADD
, sizeof(data
), data
);
285 set_registers(dev
, PHYCNT
, 1, &tmp
);
287 get_registers(dev
, PHYCNT
, 1, data
);
288 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
296 static inline void set_ethernet_addr(rtl8150_t
* dev
)
300 get_registers(dev
, IDR
, sizeof(node_id
), node_id
);
301 memcpy(dev
->netdev
->dev_addr
, node_id
, sizeof(node_id
));
304 static int rtl8150_set_mac_address(struct net_device
*netdev
, void *p
)
306 struct sockaddr
*addr
= p
;
307 rtl8150_t
*dev
= netdev_priv(netdev
);
310 if (netif_running(netdev
))
313 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
314 dbg("%s: Setting MAC address to ", netdev
->name
);
315 for (i
= 0; i
< 5; i
++)
316 dbg("%02X:", netdev
->dev_addr
[i
]);
317 dbg("%02X\n", netdev
->dev_addr
[i
]);
318 /* Set the IDR registers. */
319 set_registers(dev
, IDR
, sizeof(netdev
->dev_addr
), netdev
->dev_addr
);
323 /* Get the CR contents. */
324 get_registers(dev
, CR
, 1, &cr
);
325 /* Set the WEPROM bit (eeprom write enable). */
327 set_registers(dev
, CR
, 1, &cr
);
328 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
329 so we need to split them up. */
330 for (i
= 0; i
* 2 < netdev
->addr_len
; i
++) {
331 set_registers(dev
, IDR_EEPROM
+ (i
* 2), 2,
332 netdev
->dev_addr
+ (i
* 2));
334 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
336 set_registers(dev
, CR
, 1, &cr
);
342 static int rtl8150_reset(rtl8150_t
* dev
)
347 set_registers(dev
, CR
, 1, &data
);
349 get_registers(dev
, CR
, 1, &data
);
350 } while ((data
& 0x10) && --i
);
352 return (i
> 0) ? 1 : 0;
355 static int alloc_all_urbs(rtl8150_t
* dev
)
357 dev
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
360 dev
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
362 usb_free_urb(dev
->rx_urb
);
365 dev
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
366 if (!dev
->intr_urb
) {
367 usb_free_urb(dev
->rx_urb
);
368 usb_free_urb(dev
->tx_urb
);
371 dev
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
372 if (!dev
->intr_urb
) {
373 usb_free_urb(dev
->rx_urb
);
374 usb_free_urb(dev
->tx_urb
);
375 usb_free_urb(dev
->intr_urb
);
382 static void free_all_urbs(rtl8150_t
* dev
)
384 usb_free_urb(dev
->rx_urb
);
385 usb_free_urb(dev
->tx_urb
);
386 usb_free_urb(dev
->intr_urb
);
387 usb_free_urb(dev
->ctrl_urb
);
390 static void unlink_all_urbs(rtl8150_t
* dev
)
392 usb_kill_urb(dev
->rx_urb
);
393 usb_kill_urb(dev
->tx_urb
);
394 usb_kill_urb(dev
->intr_urb
);
395 usb_kill_urb(dev
->ctrl_urb
);
398 static inline struct sk_buff
*pull_skb(rtl8150_t
*dev
)
403 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
404 if (dev
->rx_skb_pool
[i
]) {
405 skb
= dev
->rx_skb_pool
[i
];
406 dev
->rx_skb_pool
[i
] = NULL
;
413 static void read_bulk_callback(struct urb
*urb
, struct pt_regs
*regs
)
416 unsigned pkt_len
, res
;
418 struct net_device
*netdev
;
424 if (test_bit(RTL8150_UNPLUG
, &dev
->flags
))
426 netdev
= dev
->netdev
;
427 if (!netif_device_present(netdev
))
430 switch (urb
->status
) {
434 return; /* the urb is in unlink state */
436 warn("may be reset is needed?..");
439 warn("Rx status %d", urb
->status
);
445 /* protect against short packets (tell me why we got some?!?) */
446 if (urb
->actual_length
< 4)
449 res
= urb
->actual_length
;
450 rx_stat
= le16_to_cpu(*(__le16
*)(urb
->transfer_buffer
+ res
- 4));
453 skb_put(dev
->rx_skb
, pkt_len
);
454 dev
->rx_skb
->protocol
= eth_type_trans(dev
->rx_skb
, netdev
);
455 netif_rx(dev
->rx_skb
);
456 dev
->stats
.rx_packets
++;
457 dev
->stats
.rx_bytes
+= pkt_len
;
459 spin_lock(&dev
->rx_pool_lock
);
461 spin_unlock(&dev
->rx_pool_lock
);
467 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
468 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
469 if (usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
)) {
470 set_bit(RX_URB_FAIL
, &dev
->flags
);
473 clear_bit(RX_URB_FAIL
, &dev
->flags
);
478 tasklet_schedule(&dev
->tl
);
481 static void rx_fixup(unsigned long data
)
486 dev
= (rtl8150_t
*)data
;
488 spin_lock_irq(&dev
->rx_pool_lock
);
490 spin_unlock_irq(&dev
->rx_pool_lock
);
491 if (test_bit(RX_URB_FAIL
, &dev
->flags
))
494 spin_lock_irq(&dev
->rx_pool_lock
);
496 spin_unlock_irq(&dev
->rx_pool_lock
);
500 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
501 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
503 if (usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
)) {
504 set_bit(RX_URB_FAIL
, &dev
->flags
);
507 clear_bit(RX_URB_FAIL
, &dev
->flags
);
512 tasklet_schedule(&dev
->tl
);
515 static void write_bulk_callback(struct urb
*urb
, struct pt_regs
*regs
)
522 dev_kfree_skb_irq(dev
->tx_skb
);
523 if (!netif_device_present(dev
->netdev
))
526 info("%s: Tx status %d", dev
->netdev
->name
, urb
->status
);
527 dev
->netdev
->trans_start
= jiffies
;
528 netif_wake_queue(dev
->netdev
);
531 static void intr_callback(struct urb
*urb
, struct pt_regs
*regs
)
540 switch (urb
->status
) {
541 case 0: /* success */
543 case -ECONNRESET
: /* unlink */
547 /* -EPIPE: should clear the halt */
549 info("%s: intr status %d", dev
->netdev
->name
, urb
->status
);
553 d
= urb
->transfer_buffer
;
554 if (d
[0] & TSR_ERRORS
) {
555 dev
->stats
.tx_errors
++;
556 if (d
[INT_TSR
] & (TSR_ECOL
| TSR_JBR
))
557 dev
->stats
.tx_aborted_errors
++;
558 if (d
[INT_TSR
] & TSR_LCOL
)
559 dev
->stats
.tx_window_errors
++;
560 if (d
[INT_TSR
] & TSR_LOSS_CRS
)
561 dev
->stats
.tx_carrier_errors
++;
563 /* Report link status changes to the network stack */
564 if ((d
[INT_MSR
] & MSR_LINK
) == 0) {
565 if (netif_carrier_ok(dev
->netdev
)) {
566 netif_carrier_off(dev
->netdev
);
567 dbg("%s: LINK LOST\n", __func__
);
570 if (!netif_carrier_ok(dev
->netdev
)) {
571 netif_carrier_on(dev
->netdev
);
572 dbg("%s: LINK CAME BACK\n", __func__
);
577 status
= usb_submit_urb (urb
, SLAB_ATOMIC
);
579 err ("can't resubmit intr, %s-%s/input0, status %d",
580 dev
->udev
->bus
->bus_name
,
581 dev
->udev
->devpath
, status
);
587 ** network related part of the code
591 static void fill_skb_pool(rtl8150_t
*dev
)
596 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
597 if (dev
->rx_skb_pool
[i
])
599 skb
= dev_alloc_skb(RTL8150_MTU
+ 2);
603 skb
->dev
= dev
->netdev
;
605 dev
->rx_skb_pool
[i
] = skb
;
609 static void free_skb_pool(rtl8150_t
*dev
)
613 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++)
614 if (dev
->rx_skb_pool
[i
])
615 dev_kfree_skb(dev
->rx_skb_pool
[i
]);
618 static int enable_net_traffic(rtl8150_t
* dev
)
620 u8 cr
, tcr
, rcr
, msr
;
622 if (!rtl8150_reset(dev
)) {
623 warn("%s - device reset failed", __FUNCTION__
);
625 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
627 dev
->rx_creg
= cpu_to_le16(rcr
);
631 set_bit(RTL8150_HW_CRC
, &dev
->flags
);
632 set_registers(dev
, RCR
, 1, &rcr
);
633 set_registers(dev
, TCR
, 1, &tcr
);
634 set_registers(dev
, CR
, 1, &cr
);
635 get_registers(dev
, MSR
, 1, &msr
);
640 static void disable_net_traffic(rtl8150_t
* dev
)
644 get_registers(dev
, CR
, 1, &cr
);
646 set_registers(dev
, CR
, 1, &cr
);
649 static struct net_device_stats
*rtl8150_netdev_stats(struct net_device
*dev
)
651 return &((rtl8150_t
*)netdev_priv(dev
))->stats
;
654 static void rtl8150_tx_timeout(struct net_device
*netdev
)
656 rtl8150_t
*dev
= netdev_priv(netdev
);
657 warn("%s: Tx timeout.", netdev
->name
);
658 dev
->tx_urb
->transfer_flags
|= URB_ASYNC_UNLINK
;
659 usb_unlink_urb(dev
->tx_urb
);
660 dev
->stats
.tx_errors
++;
663 static void rtl8150_set_multicast(struct net_device
*netdev
)
665 rtl8150_t
*dev
= netdev_priv(netdev
);
666 netif_stop_queue(netdev
);
667 if (netdev
->flags
& IFF_PROMISC
) {
668 dev
->rx_creg
|= cpu_to_le16(0x0001);
669 info("%s: promiscuous mode", netdev
->name
);
670 } else if ((netdev
->mc_count
> multicast_filter_limit
) ||
671 (netdev
->flags
& IFF_ALLMULTI
)) {
672 dev
->rx_creg
&= cpu_to_le16(0xfffe);
673 dev
->rx_creg
|= cpu_to_le16(0x0002);
674 info("%s: allmulti set", netdev
->name
);
676 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
677 dev
->rx_creg
&= cpu_to_le16(0x00fc);
679 async_set_registers(dev
, RCR
, 2);
680 netif_wake_queue(netdev
);
683 static int rtl8150_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
685 rtl8150_t
*dev
= netdev_priv(netdev
);
688 netif_stop_queue(netdev
);
689 count
= (skb
->len
< 60) ? 60 : skb
->len
;
690 count
= (count
& 0x3f) ? count
: count
+ 1;
692 usb_fill_bulk_urb(dev
->tx_urb
, dev
->udev
, usb_sndbulkpipe(dev
->udev
, 2),
693 skb
->data
, count
, write_bulk_callback
, dev
);
694 if ((res
= usb_submit_urb(dev
->tx_urb
, GFP_ATOMIC
))) {
695 warn("failed tx_urb %d\n", res
);
696 dev
->stats
.tx_errors
++;
697 netif_start_queue(netdev
);
699 dev
->stats
.tx_packets
++;
700 dev
->stats
.tx_bytes
+= skb
->len
;
701 netdev
->trans_start
= jiffies
;
708 static void set_carrier(struct net_device
*netdev
)
710 rtl8150_t
*dev
= netdev_priv(netdev
);
713 get_registers(dev
, CSCR
, 2, &tmp
);
714 if (tmp
& CSCR_LINK_STATUS
)
715 netif_carrier_on(netdev
);
717 netif_carrier_off(netdev
);
720 static int rtl8150_open(struct net_device
*netdev
)
722 rtl8150_t
*dev
= netdev_priv(netdev
);
725 if (dev
->rx_skb
== NULL
)
726 dev
->rx_skb
= pull_skb(dev
);
730 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
732 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
733 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
734 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
)))
735 warn("%s: rx_urb submit failed: %d", __FUNCTION__
, res
);
736 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
737 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
738 dev
, dev
->intr_interval
);
739 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
)))
740 warn("%s: intr_urb submit failed: %d", __FUNCTION__
, res
);
741 netif_start_queue(netdev
);
742 enable_net_traffic(dev
);
748 static int rtl8150_close(struct net_device
*netdev
)
750 rtl8150_t
*dev
= netdev_priv(netdev
);
753 netif_stop_queue(netdev
);
754 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
755 disable_net_traffic(dev
);
756 unlink_all_urbs(dev
);
761 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
763 rtl8150_t
*dev
= netdev_priv(netdev
);
765 strncpy(info
->driver
, driver_name
, ETHTOOL_BUSINFO_LEN
);
766 strncpy(info
->version
, DRIVER_VERSION
, ETHTOOL_BUSINFO_LEN
);
767 usb_make_path(dev
->udev
, info
->bus_info
, sizeof info
->bus_info
);
770 static int rtl8150_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
772 rtl8150_t
*dev
= netdev_priv(netdev
);
775 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
776 SUPPORTED_10baseT_Full
|
777 SUPPORTED_100baseT_Half
|
778 SUPPORTED_100baseT_Full
|
780 SUPPORTED_TP
| SUPPORTED_MII
);
781 ecmd
->port
= PORT_TP
;
782 ecmd
->transceiver
= XCVR_INTERNAL
;
783 ecmd
->phy_address
= dev
->phy
;
784 get_registers(dev
, BMCR
, 2, &bmcr
);
785 get_registers(dev
, ANLP
, 2, &lpa
);
786 if (bmcr
& BMCR_ANENABLE
) {
787 ecmd
->autoneg
= AUTONEG_ENABLE
;
788 ecmd
->speed
= (lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
789 SPEED_100
: SPEED_10
;
790 if (ecmd
->speed
== SPEED_100
)
791 ecmd
->duplex
= (lpa
& LPA_100FULL
) ?
792 DUPLEX_FULL
: DUPLEX_HALF
;
794 ecmd
->duplex
= (lpa
& LPA_10FULL
) ?
795 DUPLEX_FULL
: DUPLEX_HALF
;
797 ecmd
->autoneg
= AUTONEG_DISABLE
;
798 ecmd
->speed
= (bmcr
& BMCR_SPEED100
) ?
799 SPEED_100
: SPEED_10
;
800 ecmd
->duplex
= (bmcr
& BMCR_FULLDPLX
) ?
801 DUPLEX_FULL
: DUPLEX_HALF
;
806 static struct ethtool_ops ops
= {
807 .get_drvinfo
= rtl8150_get_drvinfo
,
808 .get_settings
= rtl8150_get_settings
,
809 .get_link
= ethtool_op_get_link
812 static int rtl8150_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
814 rtl8150_t
*dev
= netdev_priv(netdev
);
815 u16
*data
= (u16
*) & rq
->ifr_ifru
;
821 case SIOCDEVPRIVATE
+ 1:
822 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
824 case SIOCDEVPRIVATE
+ 2:
825 if (!capable(CAP_NET_ADMIN
))
827 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
836 static int rtl8150_probe(struct usb_interface
*intf
,
837 const struct usb_device_id
*id
)
839 struct usb_device
*udev
= interface_to_usbdev(intf
);
841 struct net_device
*netdev
;
843 netdev
= alloc_etherdev(sizeof(rtl8150_t
));
845 err("Out of memory");
849 dev
= netdev_priv(netdev
);
850 memset(dev
, 0, sizeof(rtl8150_t
));
852 dev
->intr_buff
= kmalloc(INTBUFSIZE
, GFP_KERNEL
);
853 if (!dev
->intr_buff
) {
858 tasklet_init(&dev
->tl
, rx_fixup
, (unsigned long)dev
);
859 spin_lock_init(&dev
->rx_pool_lock
);
862 dev
->netdev
= netdev
;
863 SET_MODULE_OWNER(netdev
);
864 netdev
->open
= rtl8150_open
;
865 netdev
->stop
= rtl8150_close
;
866 netdev
->do_ioctl
= rtl8150_ioctl
;
867 netdev
->watchdog_timeo
= RTL8150_TX_TIMEOUT
;
868 netdev
->tx_timeout
= rtl8150_tx_timeout
;
869 netdev
->hard_start_xmit
= rtl8150_start_xmit
;
870 netdev
->set_multicast_list
= rtl8150_set_multicast
;
871 netdev
->set_mac_address
= rtl8150_set_mac_address
;
872 netdev
->get_stats
= rtl8150_netdev_stats
;
873 netdev
->mtu
= RTL8150_MTU
;
874 SET_ETHTOOL_OPS(netdev
, &ops
);
875 dev
->intr_interval
= 100; /* 100ms */
877 if (!alloc_all_urbs(dev
)) {
878 err("out of memory");
881 if (!rtl8150_reset(dev
)) {
882 err("couldn't reset the device");
886 set_ethernet_addr(dev
);
887 info("%s: rtl8150 is detected", netdev
->name
);
889 usb_set_intfdata(intf
, dev
);
890 SET_NETDEV_DEV(netdev
, &intf
->dev
);
891 if (register_netdev(netdev
) != 0) {
892 err("couldn't register the device");
898 usb_set_intfdata(intf
, NULL
);
903 kfree(dev
->intr_buff
);
908 static void rtl8150_disconnect(struct usb_interface
*intf
)
910 rtl8150_t
*dev
= usb_get_intfdata(intf
);
912 usb_set_intfdata(intf
, NULL
);
914 set_bit(RTL8150_UNPLUG
, &dev
->flags
);
915 unregister_netdev(dev
->netdev
);
916 unlink_all_urbs(dev
);
920 dev_kfree_skb(dev
->rx_skb
);
921 kfree(dev
->intr_buff
);
922 free_netdev(dev
->netdev
);
926 static int __init
usb_rtl8150_init(void)
928 info(DRIVER_DESC
" " DRIVER_VERSION
);
929 return usb_register(&rtl8150_driver
);
932 static void __exit
usb_rtl8150_exit(void)
934 usb_deregister(&rtl8150_driver
);
937 module_init(usb_rtl8150_init
);
938 module_exit(usb_rtl8150_exit
);
940 MODULE_AUTHOR(DRIVER_AUTHOR
);
941 MODULE_DESCRIPTION(DRIVER_DESC
);
942 MODULE_LICENSE("GPL");