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/sched.h>
10 #include <linux/init.h>
11 #include <linux/signal.h>
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/mii.h>
17 #include <linux/ethtool.h>
18 #include <linux/usb.h>
19 #include <asm/uaccess.h>
21 /* Version Information */
22 #define DRIVER_VERSION "v0.6.2 (2004/08/27)"
23 #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
24 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
45 #define CSCR 0x014C /* This one has the link status */
46 #define CSCR_LINK_STATUS (1 << 3)
48 #define IDR_EEPROM 0x1202
51 #define PHY_WRITE 0x20
54 #define MII_TIMEOUT 10
57 #define RTL8150_REQT_READ 0xc0
58 #define RTL8150_REQT_WRITE 0x40
59 #define RTL8150_REQ_GET_REGS 0x05
60 #define RTL8150_REQ_SET_REGS 0x05
63 /* Transmit status register errors */
64 #define TSR_ECOL (1<<5)
65 #define TSR_LCOL (1<<4)
66 #define TSR_LOSS_CRS (1<<3)
67 #define TSR_JBR (1<<2)
68 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
69 /* Receive status register errors */
70 #define RSR_CRC (1<<2)
71 #define RSR_FAE (1<<1)
72 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
74 /* Media status register definitions */
75 #define MSR_DUPLEX (1<<4)
76 #define MSR_SPEED (1<<3)
77 #define MSR_LINK (1<<2)
79 /* Interrupt pipe data */
83 #define INT_WAKSR 0x03
84 #define INT_TXOK_CNT 0x04
85 #define INT_RXLOST_CNT 0x05
86 #define INT_CRERR_CNT 0x06
87 #define INT_COL_CNT 0x07
89 /* Transmit status register errors */
90 #define TSR_ECOL (1<<5)
91 #define TSR_LCOL (1<<4)
92 #define TSR_LOSS_CRS (1<<3)
93 #define TSR_JBR (1<<2)
94 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
95 /* Receive status register errors */
96 #define RSR_CRC (1<<2)
97 #define RSR_FAE (1<<1)
98 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
100 /* Media status register definitions */
101 #define MSR_DUPLEX (1<<4)
102 #define MSR_SPEED (1<<3)
103 #define MSR_LINK (1<<2)
105 /* Interrupt pipe data */
109 #define INT_WAKSR 0x03
110 #define INT_TXOK_CNT 0x04
111 #define INT_RXLOST_CNT 0x05
112 #define INT_CRERR_CNT 0x06
113 #define INT_COL_CNT 0x07
116 #define RTL8150_MTU 1540
117 #define RTL8150_TX_TIMEOUT (HZ)
118 #define RX_SKB_POOL_SIZE 4
121 #define RTL8150_HW_CRC 0
123 #define RTL8150_UNPLUG 2
124 #define RX_URB_FAIL 3
126 /* Define these values to match your device */
127 #define VENDOR_ID_REALTEK 0x0bda
128 #define VENDOR_ID_MELCO 0x0411
129 #define VENDOR_ID_MICRONET 0x3980
130 #define VENDOR_ID_LONGSHINE 0x07b8
132 #define PRODUCT_ID_RTL8150 0x8150
133 #define PRODUCT_ID_LUAKTX 0x0012
134 #define PRODUCT_ID_LCS8138TX 0x401a
135 #define PRODUCT_ID_SP128AR 0x0003
139 /* table of devices that work with this driver */
140 static struct usb_device_id rtl8150_table
[] = {
141 {USB_DEVICE(VENDOR_ID_REALTEK
, PRODUCT_ID_RTL8150
)},
142 {USB_DEVICE(VENDOR_ID_MELCO
, PRODUCT_ID_LUAKTX
)},
143 {USB_DEVICE(VENDOR_ID_MICRONET
, PRODUCT_ID_SP128AR
)},
144 {USB_DEVICE(VENDOR_ID_LONGSHINE
, PRODUCT_ID_LCS8138TX
)},
148 MODULE_DEVICE_TABLE(usb
, rtl8150_table
);
152 struct usb_device
*udev
;
153 struct tasklet_struct tl
;
154 struct net_device_stats stats
;
155 struct net_device
*netdev
;
156 struct urb
*rx_urb
, *tx_urb
, *intr_urb
, *ctrl_urb
;
157 struct sk_buff
*tx_skb
, *rx_skb
;
158 struct sk_buff
*rx_skb_pool
[RX_SKB_POOL_SIZE
];
159 spinlock_t rx_pool_lock
;
160 struct usb_ctrlrequest dr
;
167 typedef struct rtl8150 rtl8150_t
;
169 static void fill_skb_pool(rtl8150_t
*);
170 static void free_skb_pool(rtl8150_t
*);
171 static inline struct sk_buff
*pull_skb(rtl8150_t
*);
172 static void rtl8150_disconnect(struct usb_interface
*intf
);
173 static int rtl8150_probe(struct usb_interface
*intf
,
174 const struct usb_device_id
*id
);
176 static const char driver_name
[] = "rtl8150";
178 static struct usb_driver rtl8150_driver
= {
180 .probe
= rtl8150_probe
,
181 .disconnect
= rtl8150_disconnect
,
182 .id_table
= rtl8150_table
,
187 ** device related part of the code
190 static int get_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
192 return usb_control_msg(dev
->udev
, usb_rcvctrlpipe(dev
->udev
, 0),
193 RTL8150_REQ_GET_REGS
, RTL8150_REQT_READ
,
194 indx
, 0, data
, size
, 500);
197 static int set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
199 return usb_control_msg(dev
->udev
, usb_sndctrlpipe(dev
->udev
, 0),
200 RTL8150_REQ_SET_REGS
, RTL8150_REQT_WRITE
,
201 indx
, 0, data
, size
, 500);
204 static void ctrl_callback(struct urb
*urb
, struct pt_regs
*regs
)
208 switch (urb
->status
) {
216 warn("ctrl urb status %d", urb
->status
);
219 clear_bit(RX_REG_SET
, &dev
->flags
);
222 static int async_set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
)
226 if (test_bit(RX_REG_SET
, &dev
->flags
))
229 dev
->dr
.bRequestType
= RTL8150_REQT_WRITE
;
230 dev
->dr
.bRequest
= RTL8150_REQ_SET_REGS
;
231 dev
->dr
.wValue
= cpu_to_le16(indx
);
233 dev
->dr
.wLength
= cpu_to_le16(size
);
234 dev
->ctrl_urb
->transfer_buffer_length
= size
;
235 usb_fill_control_urb(dev
->ctrl_urb
, dev
->udev
,
236 usb_sndctrlpipe(dev
->udev
, 0), (char *) &dev
->dr
,
237 &dev
->rx_creg
, size
, ctrl_callback
, dev
);
238 if ((ret
= usb_submit_urb(dev
->ctrl_urb
, GFP_ATOMIC
)))
239 err("control request submission failed: %d", ret
);
241 set_bit(RX_REG_SET
, &dev
->flags
);
246 static int read_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16
* reg
)
252 data
[1] = data
[2] = 0;
253 tmp
= indx
| PHY_READ
| PHY_GO
;
256 set_registers(dev
, PHYADD
, sizeof(data
), data
);
257 set_registers(dev
, PHYCNT
, 1, &tmp
);
259 get_registers(dev
, PHYCNT
, 1, data
);
260 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
262 if (i
< MII_TIMEOUT
) {
263 get_registers(dev
, PHYDAT
, 2, data
);
264 *reg
= data
[0] | (data
[1] << 8);
270 static int write_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16 reg
)
276 *(data
+ 1) = cpu_to_le16p(®
);
277 tmp
= indx
| PHY_WRITE
| PHY_GO
;
280 set_registers(dev
, PHYADD
, sizeof(data
), data
);
281 set_registers(dev
, PHYCNT
, 1, &tmp
);
283 get_registers(dev
, PHYCNT
, 1, data
);
284 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
292 static inline void set_ethernet_addr(rtl8150_t
* dev
)
296 get_registers(dev
, IDR
, sizeof(node_id
), node_id
);
297 memcpy(dev
->netdev
->dev_addr
, node_id
, sizeof(node_id
));
300 static int rtl8150_set_mac_address(struct net_device
*netdev
, void *p
)
302 struct sockaddr
*addr
= p
;
303 rtl8150_t
*dev
= netdev_priv(netdev
);
306 if (netif_running(netdev
))
309 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
310 dbg("%s: Setting MAC address to ", netdev
->name
);
311 for (i
= 0; i
< 5; i
++)
312 dbg("%02X:", netdev
->dev_addr
[i
]);
313 dbg("%02X\n", netdev
->dev_addr
[i
]);
314 /* Set the IDR registers. */
315 set_registers(dev
, IDR
, sizeof(netdev
->dev_addr
), netdev
->dev_addr
);
319 /* Get the CR contents. */
320 get_registers(dev
, CR
, 1, &cr
);
321 /* Set the WEPROM bit (eeprom write enable). */
323 set_registers(dev
, CR
, 1, &cr
);
324 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
325 so we need to split them up. */
326 for (i
= 0; i
* 2 < netdev
->addr_len
; i
++) {
327 set_registers(dev
, IDR_EEPROM
+ (i
* 2), 2,
328 netdev
->dev_addr
+ (i
* 2));
330 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
332 set_registers(dev
, CR
, 1, &cr
);
338 static int rtl8150_reset(rtl8150_t
* dev
)
343 set_registers(dev
, CR
, 1, &data
);
345 get_registers(dev
, CR
, 1, &data
);
346 } while ((data
& 0x10) && --i
);
348 return (i
> 0) ? 1 : 0;
351 static int alloc_all_urbs(rtl8150_t
* dev
)
353 dev
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
356 dev
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
358 usb_free_urb(dev
->rx_urb
);
361 dev
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
362 if (!dev
->intr_urb
) {
363 usb_free_urb(dev
->rx_urb
);
364 usb_free_urb(dev
->tx_urb
);
367 dev
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
368 if (!dev
->intr_urb
) {
369 usb_free_urb(dev
->rx_urb
);
370 usb_free_urb(dev
->tx_urb
);
371 usb_free_urb(dev
->intr_urb
);
378 static void free_all_urbs(rtl8150_t
* dev
)
380 usb_free_urb(dev
->rx_urb
);
381 usb_free_urb(dev
->tx_urb
);
382 usb_free_urb(dev
->intr_urb
);
383 usb_free_urb(dev
->ctrl_urb
);
386 static void unlink_all_urbs(rtl8150_t
* dev
)
388 usb_kill_urb(dev
->rx_urb
);
389 usb_kill_urb(dev
->tx_urb
);
390 usb_kill_urb(dev
->intr_urb
);
391 usb_kill_urb(dev
->ctrl_urb
);
394 static inline struct sk_buff
*pull_skb(rtl8150_t
*dev
)
399 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
400 if (dev
->rx_skb_pool
[i
]) {
401 skb
= dev
->rx_skb_pool
[i
];
402 dev
->rx_skb_pool
[i
] = NULL
;
409 static void read_bulk_callback(struct urb
*urb
, struct pt_regs
*regs
)
412 unsigned pkt_len
, res
;
414 struct net_device
*netdev
;
420 if (test_bit(RTL8150_UNPLUG
, &dev
->flags
))
422 netdev
= dev
->netdev
;
423 if (!netif_device_present(netdev
))
426 switch (urb
->status
) {
430 return; /* the urb is in unlink state */
432 warn("may be reset is needed?..");
435 warn("Rx status %d", urb
->status
);
441 /* protect against short packets (tell me why we got some?!?) */
442 if (urb
->actual_length
< 4)
445 res
= urb
->actual_length
;
446 rx_stat
= le16_to_cpu(*(__le16
*)(urb
->transfer_buffer
+ res
- 4));
449 skb_put(dev
->rx_skb
, pkt_len
);
450 dev
->rx_skb
->protocol
= eth_type_trans(dev
->rx_skb
, netdev
);
451 netif_rx(dev
->rx_skb
);
452 dev
->stats
.rx_packets
++;
453 dev
->stats
.rx_bytes
+= pkt_len
;
455 spin_lock(&dev
->rx_pool_lock
);
457 spin_unlock(&dev
->rx_pool_lock
);
463 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
464 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
465 if (usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
)) {
466 set_bit(RX_URB_FAIL
, &dev
->flags
);
469 clear_bit(RX_URB_FAIL
, &dev
->flags
);
474 tasklet_schedule(&dev
->tl
);
477 static void rx_fixup(unsigned long data
)
482 dev
= (rtl8150_t
*)data
;
484 spin_lock_irq(&dev
->rx_pool_lock
);
486 spin_unlock_irq(&dev
->rx_pool_lock
);
487 if (test_bit(RX_URB_FAIL
, &dev
->flags
))
490 spin_lock_irq(&dev
->rx_pool_lock
);
492 spin_unlock_irq(&dev
->rx_pool_lock
);
496 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
497 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
499 if (usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
)) {
500 set_bit(RX_URB_FAIL
, &dev
->flags
);
503 clear_bit(RX_URB_FAIL
, &dev
->flags
);
508 tasklet_schedule(&dev
->tl
);
511 static void write_bulk_callback(struct urb
*urb
, struct pt_regs
*regs
)
518 dev_kfree_skb_irq(dev
->tx_skb
);
519 if (!netif_device_present(dev
->netdev
))
522 info("%s: Tx status %d", dev
->netdev
->name
, urb
->status
);
523 dev
->netdev
->trans_start
= jiffies
;
524 netif_wake_queue(dev
->netdev
);
527 static void intr_callback(struct urb
*urb
, struct pt_regs
*regs
)
536 switch (urb
->status
) {
537 case 0: /* success */
539 case -ECONNRESET
: /* unlink */
543 /* -EPIPE: should clear the halt */
545 info("%s: intr status %d", dev
->netdev
->name
, urb
->status
);
549 d
= urb
->transfer_buffer
;
550 if (d
[0] & TSR_ERRORS
) {
551 dev
->stats
.tx_errors
++;
552 if (d
[INT_TSR
] & (TSR_ECOL
| TSR_JBR
))
553 dev
->stats
.tx_aborted_errors
++;
554 if (d
[INT_TSR
] & TSR_LCOL
)
555 dev
->stats
.tx_window_errors
++;
556 if (d
[INT_TSR
] & TSR_LOSS_CRS
)
557 dev
->stats
.tx_carrier_errors
++;
559 /* Report link status changes to the network stack */
560 if ((d
[INT_MSR
] & MSR_LINK
) == 0) {
561 if (netif_carrier_ok(dev
->netdev
)) {
562 netif_carrier_off(dev
->netdev
);
563 dbg("%s: LINK LOST\n", __func__
);
566 if (!netif_carrier_ok(dev
->netdev
)) {
567 netif_carrier_on(dev
->netdev
);
568 dbg("%s: LINK CAME BACK\n", __func__
);
573 status
= usb_submit_urb (urb
, SLAB_ATOMIC
);
575 err ("can't resubmit intr, %s-%s/input0, status %d",
576 dev
->udev
->bus
->bus_name
,
577 dev
->udev
->devpath
, status
);
583 ** network related part of the code
587 static void fill_skb_pool(rtl8150_t
*dev
)
592 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
593 if (dev
->rx_skb_pool
[i
])
595 skb
= dev_alloc_skb(RTL8150_MTU
+ 2);
599 skb
->dev
= dev
->netdev
;
601 dev
->rx_skb_pool
[i
] = skb
;
605 static void free_skb_pool(rtl8150_t
*dev
)
609 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++)
610 if (dev
->rx_skb_pool
[i
])
611 dev_kfree_skb(dev
->rx_skb_pool
[i
]);
614 static int enable_net_traffic(rtl8150_t
* dev
)
616 u8 cr
, tcr
, rcr
, msr
;
618 if (!rtl8150_reset(dev
)) {
619 warn("%s - device reset failed", __FUNCTION__
);
621 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
623 dev
->rx_creg
= cpu_to_le16(rcr
);
627 set_bit(RTL8150_HW_CRC
, &dev
->flags
);
628 set_registers(dev
, RCR
, 1, &rcr
);
629 set_registers(dev
, TCR
, 1, &tcr
);
630 set_registers(dev
, CR
, 1, &cr
);
631 get_registers(dev
, MSR
, 1, &msr
);
636 static void disable_net_traffic(rtl8150_t
* dev
)
640 get_registers(dev
, CR
, 1, &cr
);
642 set_registers(dev
, CR
, 1, &cr
);
645 static struct net_device_stats
*rtl8150_netdev_stats(struct net_device
*dev
)
647 return &((rtl8150_t
*)netdev_priv(dev
))->stats
;
650 static void rtl8150_tx_timeout(struct net_device
*netdev
)
652 rtl8150_t
*dev
= netdev_priv(netdev
);
653 warn("%s: Tx timeout.", netdev
->name
);
654 usb_unlink_urb(dev
->tx_urb
);
655 dev
->stats
.tx_errors
++;
658 static void rtl8150_set_multicast(struct net_device
*netdev
)
660 rtl8150_t
*dev
= netdev_priv(netdev
);
661 netif_stop_queue(netdev
);
662 if (netdev
->flags
& IFF_PROMISC
) {
663 dev
->rx_creg
|= cpu_to_le16(0x0001);
664 info("%s: promiscuous mode", netdev
->name
);
665 } else if (netdev
->mc_count
||
666 (netdev
->flags
& IFF_ALLMULTI
)) {
667 dev
->rx_creg
&= cpu_to_le16(0xfffe);
668 dev
->rx_creg
|= cpu_to_le16(0x0002);
669 info("%s: allmulti set", netdev
->name
);
671 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
672 dev
->rx_creg
&= cpu_to_le16(0x00fc);
674 async_set_registers(dev
, RCR
, 2);
675 netif_wake_queue(netdev
);
678 static int rtl8150_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
680 rtl8150_t
*dev
= netdev_priv(netdev
);
683 netif_stop_queue(netdev
);
684 count
= (skb
->len
< 60) ? 60 : skb
->len
;
685 count
= (count
& 0x3f) ? count
: count
+ 1;
687 usb_fill_bulk_urb(dev
->tx_urb
, dev
->udev
, usb_sndbulkpipe(dev
->udev
, 2),
688 skb
->data
, count
, write_bulk_callback
, dev
);
689 if ((res
= usb_submit_urb(dev
->tx_urb
, GFP_ATOMIC
))) {
690 warn("failed tx_urb %d\n", res
);
691 dev
->stats
.tx_errors
++;
692 netif_start_queue(netdev
);
694 dev
->stats
.tx_packets
++;
695 dev
->stats
.tx_bytes
+= skb
->len
;
696 netdev
->trans_start
= jiffies
;
703 static void set_carrier(struct net_device
*netdev
)
705 rtl8150_t
*dev
= netdev_priv(netdev
);
708 get_registers(dev
, CSCR
, 2, &tmp
);
709 if (tmp
& CSCR_LINK_STATUS
)
710 netif_carrier_on(netdev
);
712 netif_carrier_off(netdev
);
715 static int rtl8150_open(struct net_device
*netdev
)
717 rtl8150_t
*dev
= netdev_priv(netdev
);
720 if (dev
->rx_skb
== NULL
)
721 dev
->rx_skb
= pull_skb(dev
);
725 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
727 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
728 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
729 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
)))
730 warn("%s: rx_urb submit failed: %d", __FUNCTION__
, res
);
731 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
732 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
733 dev
, dev
->intr_interval
);
734 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
)))
735 warn("%s: intr_urb submit failed: %d", __FUNCTION__
, res
);
736 netif_start_queue(netdev
);
737 enable_net_traffic(dev
);
743 static int rtl8150_close(struct net_device
*netdev
)
745 rtl8150_t
*dev
= netdev_priv(netdev
);
748 netif_stop_queue(netdev
);
749 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
750 disable_net_traffic(dev
);
751 unlink_all_urbs(dev
);
756 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
758 rtl8150_t
*dev
= netdev_priv(netdev
);
760 strncpy(info
->driver
, driver_name
, ETHTOOL_BUSINFO_LEN
);
761 strncpy(info
->version
, DRIVER_VERSION
, ETHTOOL_BUSINFO_LEN
);
762 usb_make_path(dev
->udev
, info
->bus_info
, sizeof info
->bus_info
);
765 static int rtl8150_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
767 rtl8150_t
*dev
= netdev_priv(netdev
);
770 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
771 SUPPORTED_10baseT_Full
|
772 SUPPORTED_100baseT_Half
|
773 SUPPORTED_100baseT_Full
|
775 SUPPORTED_TP
| SUPPORTED_MII
);
776 ecmd
->port
= PORT_TP
;
777 ecmd
->transceiver
= XCVR_INTERNAL
;
778 ecmd
->phy_address
= dev
->phy
;
779 get_registers(dev
, BMCR
, 2, &bmcr
);
780 get_registers(dev
, ANLP
, 2, &lpa
);
781 if (bmcr
& BMCR_ANENABLE
) {
782 ecmd
->autoneg
= AUTONEG_ENABLE
;
783 ecmd
->speed
= (lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
784 SPEED_100
: SPEED_10
;
785 if (ecmd
->speed
== SPEED_100
)
786 ecmd
->duplex
= (lpa
& LPA_100FULL
) ?
787 DUPLEX_FULL
: DUPLEX_HALF
;
789 ecmd
->duplex
= (lpa
& LPA_10FULL
) ?
790 DUPLEX_FULL
: DUPLEX_HALF
;
792 ecmd
->autoneg
= AUTONEG_DISABLE
;
793 ecmd
->speed
= (bmcr
& BMCR_SPEED100
) ?
794 SPEED_100
: SPEED_10
;
795 ecmd
->duplex
= (bmcr
& BMCR_FULLDPLX
) ?
796 DUPLEX_FULL
: DUPLEX_HALF
;
801 static struct ethtool_ops ops
= {
802 .get_drvinfo
= rtl8150_get_drvinfo
,
803 .get_settings
= rtl8150_get_settings
,
804 .get_link
= ethtool_op_get_link
807 static int rtl8150_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
809 rtl8150_t
*dev
= netdev_priv(netdev
);
810 u16
*data
= (u16
*) & rq
->ifr_ifru
;
816 case SIOCDEVPRIVATE
+ 1:
817 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
819 case SIOCDEVPRIVATE
+ 2:
820 if (!capable(CAP_NET_ADMIN
))
822 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
831 static int rtl8150_probe(struct usb_interface
*intf
,
832 const struct usb_device_id
*id
)
834 struct usb_device
*udev
= interface_to_usbdev(intf
);
836 struct net_device
*netdev
;
838 netdev
= alloc_etherdev(sizeof(rtl8150_t
));
840 err("Out of memory");
844 dev
= netdev_priv(netdev
);
845 memset(dev
, 0, sizeof(rtl8150_t
));
847 dev
->intr_buff
= kmalloc(INTBUFSIZE
, GFP_KERNEL
);
848 if (!dev
->intr_buff
) {
853 tasklet_init(&dev
->tl
, rx_fixup
, (unsigned long)dev
);
854 spin_lock_init(&dev
->rx_pool_lock
);
857 dev
->netdev
= netdev
;
858 SET_MODULE_OWNER(netdev
);
859 netdev
->open
= rtl8150_open
;
860 netdev
->stop
= rtl8150_close
;
861 netdev
->do_ioctl
= rtl8150_ioctl
;
862 netdev
->watchdog_timeo
= RTL8150_TX_TIMEOUT
;
863 netdev
->tx_timeout
= rtl8150_tx_timeout
;
864 netdev
->hard_start_xmit
= rtl8150_start_xmit
;
865 netdev
->set_multicast_list
= rtl8150_set_multicast
;
866 netdev
->set_mac_address
= rtl8150_set_mac_address
;
867 netdev
->get_stats
= rtl8150_netdev_stats
;
868 netdev
->mtu
= RTL8150_MTU
;
869 SET_ETHTOOL_OPS(netdev
, &ops
);
870 dev
->intr_interval
= 100; /* 100ms */
872 if (!alloc_all_urbs(dev
)) {
873 err("out of memory");
876 if (!rtl8150_reset(dev
)) {
877 err("couldn't reset the device");
881 set_ethernet_addr(dev
);
883 usb_set_intfdata(intf
, dev
);
884 SET_NETDEV_DEV(netdev
, &intf
->dev
);
885 if (register_netdev(netdev
) != 0) {
886 err("couldn't register the device");
890 info("%s: rtl8150 is detected", netdev
->name
);
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");