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/init.h>
10 #include <linux/signal.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
15 #include <linux/mii.h>
16 #include <linux/ethtool.h>
17 #include <linux/usb.h>
18 #include <asm/uaccess.h>
20 /* Version Information */
21 #define DRIVER_VERSION "v0.6.2 (2004/08/27)"
22 #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
23 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
44 #define CSCR 0x014C /* This one has the link status */
45 #define CSCR_LINK_STATUS (1 << 3)
47 #define IDR_EEPROM 0x1202
50 #define PHY_WRITE 0x20
53 #define MII_TIMEOUT 10
56 #define RTL8150_REQT_READ 0xc0
57 #define RTL8150_REQT_WRITE 0x40
58 #define RTL8150_REQ_GET_REGS 0x05
59 #define RTL8150_REQ_SET_REGS 0x05
62 /* Transmit status register errors */
63 #define TSR_ECOL (1<<5)
64 #define TSR_LCOL (1<<4)
65 #define TSR_LOSS_CRS (1<<3)
66 #define TSR_JBR (1<<2)
67 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
68 /* Receive status register errors */
69 #define RSR_CRC (1<<2)
70 #define RSR_FAE (1<<1)
71 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
73 /* Media status register definitions */
74 #define MSR_DUPLEX (1<<4)
75 #define MSR_SPEED (1<<3)
76 #define MSR_LINK (1<<2)
78 /* Interrupt pipe data */
82 #define INT_WAKSR 0x03
83 #define INT_TXOK_CNT 0x04
84 #define INT_RXLOST_CNT 0x05
85 #define INT_CRERR_CNT 0x06
86 #define INT_COL_CNT 0x07
89 #define RTL8150_MTU 1540
90 #define RTL8150_TX_TIMEOUT (HZ)
91 #define RX_SKB_POOL_SIZE 4
94 #define RTL8150_HW_CRC 0
96 #define RTL8150_UNPLUG 2
99 /* Define these values to match your device */
100 #define VENDOR_ID_REALTEK 0x0bda
101 #define VENDOR_ID_MELCO 0x0411
102 #define VENDOR_ID_MICRONET 0x3980
103 #define VENDOR_ID_LONGSHINE 0x07b8
104 #define VENDOR_ID_OQO 0x1557
105 #define VENDOR_ID_ZYXEL 0x0586
107 #define PRODUCT_ID_RTL8150 0x8150
108 #define PRODUCT_ID_LUAKTX 0x0012
109 #define PRODUCT_ID_LCS8138TX 0x401a
110 #define PRODUCT_ID_SP128AR 0x0003
111 #define PRODUCT_ID_PRESTIGE 0x401a
115 /* table of devices that work with this driver */
116 static struct usb_device_id rtl8150_table
[] = {
117 {USB_DEVICE(VENDOR_ID_REALTEK
, PRODUCT_ID_RTL8150
)},
118 {USB_DEVICE(VENDOR_ID_MELCO
, PRODUCT_ID_LUAKTX
)},
119 {USB_DEVICE(VENDOR_ID_MICRONET
, PRODUCT_ID_SP128AR
)},
120 {USB_DEVICE(VENDOR_ID_LONGSHINE
, PRODUCT_ID_LCS8138TX
)},
121 {USB_DEVICE(VENDOR_ID_OQO
, PRODUCT_ID_RTL8150
)},
122 {USB_DEVICE(VENDOR_ID_ZYXEL
, PRODUCT_ID_PRESTIGE
)},
126 MODULE_DEVICE_TABLE(usb
, rtl8150_table
);
130 struct usb_device
*udev
;
131 struct tasklet_struct tl
;
132 struct net_device
*netdev
;
133 struct urb
*rx_urb
, *tx_urb
, *intr_urb
, *ctrl_urb
;
134 struct sk_buff
*tx_skb
, *rx_skb
;
135 struct sk_buff
*rx_skb_pool
[RX_SKB_POOL_SIZE
];
136 spinlock_t rx_pool_lock
;
137 struct usb_ctrlrequest dr
;
144 typedef struct rtl8150 rtl8150_t
;
146 static const char driver_name
[] = "rtl8150";
150 ** device related part of the code
153 static int get_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
155 return usb_control_msg(dev
->udev
, usb_rcvctrlpipe(dev
->udev
, 0),
156 RTL8150_REQ_GET_REGS
, RTL8150_REQT_READ
,
157 indx
, 0, data
, size
, 500);
160 static int set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
162 return usb_control_msg(dev
->udev
, usb_sndctrlpipe(dev
->udev
, 0),
163 RTL8150_REQ_SET_REGS
, RTL8150_REQT_WRITE
,
164 indx
, 0, data
, size
, 500);
167 static void ctrl_callback(struct urb
*urb
)
170 int status
= urb
->status
;
180 if (printk_ratelimit())
181 dev_warn(&urb
->dev
->dev
, "ctrl urb status %d\n", status
);
184 clear_bit(RX_REG_SET
, &dev
->flags
);
187 static int async_set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
)
191 if (test_bit(RX_REG_SET
, &dev
->flags
))
194 dev
->dr
.bRequestType
= RTL8150_REQT_WRITE
;
195 dev
->dr
.bRequest
= RTL8150_REQ_SET_REGS
;
196 dev
->dr
.wValue
= cpu_to_le16(indx
);
198 dev
->dr
.wLength
= cpu_to_le16(size
);
199 dev
->ctrl_urb
->transfer_buffer_length
= size
;
200 usb_fill_control_urb(dev
->ctrl_urb
, dev
->udev
,
201 usb_sndctrlpipe(dev
->udev
, 0), (char *) &dev
->dr
,
202 &dev
->rx_creg
, size
, ctrl_callback
, dev
);
203 if ((ret
= usb_submit_urb(dev
->ctrl_urb
, GFP_ATOMIC
))) {
205 netif_device_detach(dev
->netdev
);
206 err("control request submission failed: %d", ret
);
208 set_bit(RX_REG_SET
, &dev
->flags
);
213 static int read_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16
* reg
)
219 data
[1] = data
[2] = 0;
220 tmp
= indx
| PHY_READ
| PHY_GO
;
223 set_registers(dev
, PHYADD
, sizeof(data
), data
);
224 set_registers(dev
, PHYCNT
, 1, &tmp
);
226 get_registers(dev
, PHYCNT
, 1, data
);
227 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
229 if (i
<= MII_TIMEOUT
) {
230 get_registers(dev
, PHYDAT
, 2, data
);
231 *reg
= data
[0] | (data
[1] << 8);
237 static int write_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16 reg
)
243 data
[1] = reg
& 0xff;
244 data
[2] = (reg
>> 8) & 0xff;
245 tmp
= indx
| PHY_WRITE
| PHY_GO
;
248 set_registers(dev
, PHYADD
, sizeof(data
), data
);
249 set_registers(dev
, PHYCNT
, 1, &tmp
);
251 get_registers(dev
, PHYCNT
, 1, data
);
252 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
254 if (i
<= MII_TIMEOUT
)
260 static inline void set_ethernet_addr(rtl8150_t
* dev
)
264 get_registers(dev
, IDR
, sizeof(node_id
), node_id
);
265 memcpy(dev
->netdev
->dev_addr
, node_id
, sizeof(node_id
));
268 static int rtl8150_set_mac_address(struct net_device
*netdev
, void *p
)
270 struct sockaddr
*addr
= p
;
271 rtl8150_t
*dev
= netdev_priv(netdev
);
273 if (netif_running(netdev
))
276 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
277 dbg("%s: Setting MAC address to %pM\n", netdev
->name
, netdev
->dev_addr
);
278 /* Set the IDR registers. */
279 set_registers(dev
, IDR
, netdev
->addr_len
, netdev
->dev_addr
);
284 /* Get the CR contents. */
285 get_registers(dev
, CR
, 1, &cr
);
286 /* Set the WEPROM bit (eeprom write enable). */
288 set_registers(dev
, CR
, 1, &cr
);
289 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
290 so we need to split them up. */
291 for (i
= 0; i
* 2 < netdev
->addr_len
; i
++) {
292 set_registers(dev
, IDR_EEPROM
+ (i
* 2), 2,
293 netdev
->dev_addr
+ (i
* 2));
295 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
297 set_registers(dev
, CR
, 1, &cr
);
303 static int rtl8150_reset(rtl8150_t
* dev
)
308 set_registers(dev
, CR
, 1, &data
);
310 get_registers(dev
, CR
, 1, &data
);
311 } while ((data
& 0x10) && --i
);
313 return (i
> 0) ? 1 : 0;
316 static int alloc_all_urbs(rtl8150_t
* dev
)
318 dev
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
321 dev
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
323 usb_free_urb(dev
->rx_urb
);
326 dev
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
327 if (!dev
->intr_urb
) {
328 usb_free_urb(dev
->rx_urb
);
329 usb_free_urb(dev
->tx_urb
);
332 dev
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
333 if (!dev
->ctrl_urb
) {
334 usb_free_urb(dev
->rx_urb
);
335 usb_free_urb(dev
->tx_urb
);
336 usb_free_urb(dev
->intr_urb
);
343 static void free_all_urbs(rtl8150_t
* dev
)
345 usb_free_urb(dev
->rx_urb
);
346 usb_free_urb(dev
->tx_urb
);
347 usb_free_urb(dev
->intr_urb
);
348 usb_free_urb(dev
->ctrl_urb
);
351 static void unlink_all_urbs(rtl8150_t
* dev
)
353 usb_kill_urb(dev
->rx_urb
);
354 usb_kill_urb(dev
->tx_urb
);
355 usb_kill_urb(dev
->intr_urb
);
356 usb_kill_urb(dev
->ctrl_urb
);
359 static inline struct sk_buff
*pull_skb(rtl8150_t
*dev
)
364 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
365 if (dev
->rx_skb_pool
[i
]) {
366 skb
= dev
->rx_skb_pool
[i
];
367 dev
->rx_skb_pool
[i
] = NULL
;
374 static void read_bulk_callback(struct urb
*urb
)
377 unsigned pkt_len
, res
;
379 struct net_device
*netdev
;
381 int status
= urb
->status
;
387 if (test_bit(RTL8150_UNPLUG
, &dev
->flags
))
389 netdev
= dev
->netdev
;
390 if (!netif_device_present(netdev
))
397 return; /* the urb is in unlink state */
399 if (printk_ratelimit())
400 dev_warn(&urb
->dev
->dev
, "may be reset is needed?..\n");
403 if (printk_ratelimit())
404 dev_warn(&urb
->dev
->dev
, "Rx status %d\n", status
);
410 /* protect against short packets (tell me why we got some?!?) */
411 if (urb
->actual_length
< 4)
414 res
= urb
->actual_length
;
415 rx_stat
= le16_to_cpu(*(__le16
*)(urb
->transfer_buffer
+ res
- 4));
418 skb_put(dev
->rx_skb
, pkt_len
);
419 dev
->rx_skb
->protocol
= eth_type_trans(dev
->rx_skb
, netdev
);
420 netif_rx(dev
->rx_skb
);
421 netdev
->stats
.rx_packets
++;
422 netdev
->stats
.rx_bytes
+= pkt_len
;
424 spin_lock(&dev
->rx_pool_lock
);
426 spin_unlock(&dev
->rx_pool_lock
);
432 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
433 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
434 result
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
435 if (result
== -ENODEV
)
436 netif_device_detach(dev
->netdev
);
438 set_bit(RX_URB_FAIL
, &dev
->flags
);
441 clear_bit(RX_URB_FAIL
, &dev
->flags
);
446 tasklet_schedule(&dev
->tl
);
449 static void write_bulk_callback(struct urb
*urb
)
452 int status
= urb
->status
;
457 dev_kfree_skb_irq(dev
->tx_skb
);
458 if (!netif_device_present(dev
->netdev
))
461 dev_info(&urb
->dev
->dev
, "%s: Tx status %d\n",
462 dev
->netdev
->name
, status
);
463 dev
->netdev
->trans_start
= jiffies
;
464 netif_wake_queue(dev
->netdev
);
467 static void intr_callback(struct urb
*urb
)
471 int status
= urb
->status
;
478 case 0: /* success */
480 case -ECONNRESET
: /* unlink */
484 /* -EPIPE: should clear the halt */
486 dev_info(&urb
->dev
->dev
, "%s: intr status %d\n",
487 dev
->netdev
->name
, status
);
491 d
= urb
->transfer_buffer
;
492 if (d
[0] & TSR_ERRORS
) {
493 dev
->netdev
->stats
.tx_errors
++;
494 if (d
[INT_TSR
] & (TSR_ECOL
| TSR_JBR
))
495 dev
->netdev
->stats
.tx_aborted_errors
++;
496 if (d
[INT_TSR
] & TSR_LCOL
)
497 dev
->netdev
->stats
.tx_window_errors
++;
498 if (d
[INT_TSR
] & TSR_LOSS_CRS
)
499 dev
->netdev
->stats
.tx_carrier_errors
++;
501 /* Report link status changes to the network stack */
502 if ((d
[INT_MSR
] & MSR_LINK
) == 0) {
503 if (netif_carrier_ok(dev
->netdev
)) {
504 netif_carrier_off(dev
->netdev
);
505 dbg("%s: LINK LOST\n", __func__
);
508 if (!netif_carrier_ok(dev
->netdev
)) {
509 netif_carrier_on(dev
->netdev
);
510 dbg("%s: LINK CAME BACK\n", __func__
);
515 res
= usb_submit_urb (urb
, GFP_ATOMIC
);
517 netif_device_detach(dev
->netdev
);
519 err ("can't resubmit intr, %s-%s/input0, status %d",
520 dev
->udev
->bus
->bus_name
,
521 dev
->udev
->devpath
, res
);
524 static int rtl8150_suspend(struct usb_interface
*intf
, pm_message_t message
)
526 rtl8150_t
*dev
= usb_get_intfdata(intf
);
528 netif_device_detach(dev
->netdev
);
530 if (netif_running(dev
->netdev
)) {
531 usb_kill_urb(dev
->rx_urb
);
532 usb_kill_urb(dev
->intr_urb
);
537 static int rtl8150_resume(struct usb_interface
*intf
)
539 rtl8150_t
*dev
= usb_get_intfdata(intf
);
541 netif_device_attach(dev
->netdev
);
542 if (netif_running(dev
->netdev
)) {
543 dev
->rx_urb
->status
= 0;
544 dev
->rx_urb
->actual_length
= 0;
545 read_bulk_callback(dev
->rx_urb
);
547 dev
->intr_urb
->status
= 0;
548 dev
->intr_urb
->actual_length
= 0;
549 intr_callback(dev
->intr_urb
);
556 ** network related part of the code
560 static void fill_skb_pool(rtl8150_t
*dev
)
565 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
566 if (dev
->rx_skb_pool
[i
])
568 skb
= dev_alloc_skb(RTL8150_MTU
+ 2);
573 dev
->rx_skb_pool
[i
] = skb
;
577 static void free_skb_pool(rtl8150_t
*dev
)
581 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++)
582 if (dev
->rx_skb_pool
[i
])
583 dev_kfree_skb(dev
->rx_skb_pool
[i
]);
586 static void rx_fixup(unsigned long data
)
588 struct rtl8150
*dev
= (struct rtl8150
*)data
;
592 spin_lock_irq(&dev
->rx_pool_lock
);
594 spin_unlock_irq(&dev
->rx_pool_lock
);
595 if (test_bit(RX_URB_FAIL
, &dev
->flags
))
598 spin_lock_irq(&dev
->rx_pool_lock
);
600 spin_unlock_irq(&dev
->rx_pool_lock
);
604 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
605 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
607 status
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
608 if (status
== -ENODEV
) {
609 netif_device_detach(dev
->netdev
);
611 set_bit(RX_URB_FAIL
, &dev
->flags
);
614 clear_bit(RX_URB_FAIL
, &dev
->flags
);
619 tasklet_schedule(&dev
->tl
);
622 static int enable_net_traffic(rtl8150_t
* dev
)
624 u8 cr
, tcr
, rcr
, msr
;
626 if (!rtl8150_reset(dev
)) {
627 dev_warn(&dev
->udev
->dev
, "device reset failed\n");
629 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
631 dev
->rx_creg
= cpu_to_le16(rcr
);
635 set_bit(RTL8150_HW_CRC
, &dev
->flags
);
636 set_registers(dev
, RCR
, 1, &rcr
);
637 set_registers(dev
, TCR
, 1, &tcr
);
638 set_registers(dev
, CR
, 1, &cr
);
639 get_registers(dev
, MSR
, 1, &msr
);
644 static void disable_net_traffic(rtl8150_t
* dev
)
648 get_registers(dev
, CR
, 1, &cr
);
650 set_registers(dev
, CR
, 1, &cr
);
653 static void rtl8150_tx_timeout(struct net_device
*netdev
)
655 rtl8150_t
*dev
= netdev_priv(netdev
);
656 dev_warn(&netdev
->dev
, "Tx timeout.\n");
657 usb_unlink_urb(dev
->tx_urb
);
658 netdev
->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 dev_info(&netdev
->dev
, "%s: promiscuous mode\n", netdev
->name
);
668 } else if (!netdev_mc_empty(netdev
) ||
669 (netdev
->flags
& IFF_ALLMULTI
)) {
670 dev
->rx_creg
&= cpu_to_le16(0xfffe);
671 dev
->rx_creg
|= cpu_to_le16(0x0002);
672 dev_info(&netdev
->dev
, "%s: allmulti set\n", 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 netdev_tx_t
rtl8150_start_xmit(struct sk_buff
*skb
,
682 struct net_device
*netdev
)
684 rtl8150_t
*dev
= netdev_priv(netdev
);
687 netif_stop_queue(netdev
);
688 count
= (skb
->len
< 60) ? 60 : skb
->len
;
689 count
= (count
& 0x3f) ? count
: count
+ 1;
691 usb_fill_bulk_urb(dev
->tx_urb
, dev
->udev
, usb_sndbulkpipe(dev
->udev
, 2),
692 skb
->data
, count
, write_bulk_callback
, dev
);
693 if ((res
= usb_submit_urb(dev
->tx_urb
, GFP_ATOMIC
))) {
694 /* Can we get/handle EPIPE here? */
696 netif_device_detach(dev
->netdev
);
698 dev_warn(&netdev
->dev
, "failed tx_urb %d\n", res
);
699 netdev
->stats
.tx_errors
++;
700 netif_start_queue(netdev
);
703 netdev
->stats
.tx_packets
++;
704 netdev
->stats
.tx_bytes
+= skb
->len
;
705 netdev
->trans_start
= jiffies
;
712 static void set_carrier(struct net_device
*netdev
)
714 rtl8150_t
*dev
= netdev_priv(netdev
);
717 get_registers(dev
, CSCR
, 2, &tmp
);
718 if (tmp
& CSCR_LINK_STATUS
)
719 netif_carrier_on(netdev
);
721 netif_carrier_off(netdev
);
724 static int rtl8150_open(struct net_device
*netdev
)
726 rtl8150_t
*dev
= netdev_priv(netdev
);
729 if (dev
->rx_skb
== NULL
)
730 dev
->rx_skb
= pull_skb(dev
);
734 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
736 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
737 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
738 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
))) {
740 netif_device_detach(dev
->netdev
);
741 dev_warn(&netdev
->dev
, "rx_urb submit failed: %d\n", res
);
744 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
745 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
746 dev
, dev
->intr_interval
);
747 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
))) {
749 netif_device_detach(dev
->netdev
);
750 dev_warn(&netdev
->dev
, "intr_urb submit failed: %d\n", res
);
751 usb_kill_urb(dev
->rx_urb
);
754 enable_net_traffic(dev
);
756 netif_start_queue(netdev
);
761 static int rtl8150_close(struct net_device
*netdev
)
763 rtl8150_t
*dev
= netdev_priv(netdev
);
766 netif_stop_queue(netdev
);
767 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
768 disable_net_traffic(dev
);
769 unlink_all_urbs(dev
);
774 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
776 rtl8150_t
*dev
= netdev_priv(netdev
);
778 strncpy(info
->driver
, driver_name
, ETHTOOL_BUSINFO_LEN
);
779 strncpy(info
->version
, DRIVER_VERSION
, ETHTOOL_BUSINFO_LEN
);
780 usb_make_path(dev
->udev
, info
->bus_info
, sizeof info
->bus_info
);
783 static int rtl8150_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
785 rtl8150_t
*dev
= netdev_priv(netdev
);
788 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
789 SUPPORTED_10baseT_Full
|
790 SUPPORTED_100baseT_Half
|
791 SUPPORTED_100baseT_Full
|
793 SUPPORTED_TP
| SUPPORTED_MII
);
794 ecmd
->port
= PORT_TP
;
795 ecmd
->transceiver
= XCVR_INTERNAL
;
796 ecmd
->phy_address
= dev
->phy
;
797 get_registers(dev
, BMCR
, 2, &bmcr
);
798 get_registers(dev
, ANLP
, 2, &lpa
);
799 if (bmcr
& BMCR_ANENABLE
) {
800 u32 speed
= ((lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
801 SPEED_100
: SPEED_10
);
802 ethtool_cmd_speed_set(ecmd
, speed
);
803 ecmd
->autoneg
= AUTONEG_ENABLE
;
804 if (speed
== SPEED_100
)
805 ecmd
->duplex
= (lpa
& LPA_100FULL
) ?
806 DUPLEX_FULL
: DUPLEX_HALF
;
808 ecmd
->duplex
= (lpa
& LPA_10FULL
) ?
809 DUPLEX_FULL
: DUPLEX_HALF
;
811 ecmd
->autoneg
= AUTONEG_DISABLE
;
812 ethtool_cmd_speed_set(ecmd
, ((bmcr
& BMCR_SPEED100
) ?
813 SPEED_100
: SPEED_10
));
814 ecmd
->duplex
= (bmcr
& BMCR_FULLDPLX
) ?
815 DUPLEX_FULL
: DUPLEX_HALF
;
820 static const struct ethtool_ops ops
= {
821 .get_drvinfo
= rtl8150_get_drvinfo
,
822 .get_settings
= rtl8150_get_settings
,
823 .get_link
= ethtool_op_get_link
826 static int rtl8150_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
828 rtl8150_t
*dev
= netdev_priv(netdev
);
829 u16
*data
= (u16
*) & rq
->ifr_ifru
;
835 case SIOCDEVPRIVATE
+ 1:
836 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
838 case SIOCDEVPRIVATE
+ 2:
839 if (!capable(CAP_NET_ADMIN
))
841 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
850 static const struct net_device_ops rtl8150_netdev_ops
= {
851 .ndo_open
= rtl8150_open
,
852 .ndo_stop
= rtl8150_close
,
853 .ndo_do_ioctl
= rtl8150_ioctl
,
854 .ndo_start_xmit
= rtl8150_start_xmit
,
855 .ndo_tx_timeout
= rtl8150_tx_timeout
,
856 .ndo_set_rx_mode
= rtl8150_set_multicast
,
857 .ndo_set_mac_address
= rtl8150_set_mac_address
,
859 .ndo_change_mtu
= eth_change_mtu
,
860 .ndo_validate_addr
= eth_validate_addr
,
863 static int rtl8150_probe(struct usb_interface
*intf
,
864 const struct usb_device_id
*id
)
866 struct usb_device
*udev
= interface_to_usbdev(intf
);
868 struct net_device
*netdev
;
870 netdev
= alloc_etherdev(sizeof(rtl8150_t
));
874 dev
= netdev_priv(netdev
);
876 dev
->intr_buff
= kmalloc(INTBUFSIZE
, GFP_KERNEL
);
877 if (!dev
->intr_buff
) {
882 tasklet_init(&dev
->tl
, rx_fixup
, (unsigned long)dev
);
883 spin_lock_init(&dev
->rx_pool_lock
);
886 dev
->netdev
= netdev
;
887 netdev
->netdev_ops
= &rtl8150_netdev_ops
;
888 netdev
->watchdog_timeo
= RTL8150_TX_TIMEOUT
;
889 SET_ETHTOOL_OPS(netdev
, &ops
);
890 dev
->intr_interval
= 100; /* 100ms */
892 if (!alloc_all_urbs(dev
)) {
893 err("out of memory");
896 if (!rtl8150_reset(dev
)) {
897 err("couldn't reset the device");
901 set_ethernet_addr(dev
);
903 usb_set_intfdata(intf
, dev
);
904 SET_NETDEV_DEV(netdev
, &intf
->dev
);
905 if (register_netdev(netdev
) != 0) {
906 err("couldn't register the device");
910 dev_info(&intf
->dev
, "%s: rtl8150 is detected\n", netdev
->name
);
915 usb_set_intfdata(intf
, NULL
);
920 kfree(dev
->intr_buff
);
925 static void rtl8150_disconnect(struct usb_interface
*intf
)
927 rtl8150_t
*dev
= usb_get_intfdata(intf
);
929 usb_set_intfdata(intf
, NULL
);
931 set_bit(RTL8150_UNPLUG
, &dev
->flags
);
932 tasklet_kill(&dev
->tl
);
933 unregister_netdev(dev
->netdev
);
934 unlink_all_urbs(dev
);
938 dev_kfree_skb(dev
->rx_skb
);
939 kfree(dev
->intr_buff
);
940 free_netdev(dev
->netdev
);
944 static struct usb_driver rtl8150_driver
= {
946 .probe
= rtl8150_probe
,
947 .disconnect
= rtl8150_disconnect
,
948 .id_table
= rtl8150_table
,
949 .suspend
= rtl8150_suspend
,
950 .resume
= rtl8150_resume
953 module_usb_driver(rtl8150_driver
);
955 MODULE_AUTHOR(DRIVER_AUTHOR
);
956 MODULE_DESCRIPTION(DRIVER_DESC
);
957 MODULE_LICENSE("GPL");