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 dev_err(&dev
->udev
->dev
,
207 "control request submission failed: %d\n", ret
);
209 set_bit(RX_REG_SET
, &dev
->flags
);
214 static int read_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16
* reg
)
220 data
[1] = data
[2] = 0;
221 tmp
= indx
| PHY_READ
| PHY_GO
;
224 set_registers(dev
, PHYADD
, sizeof(data
), data
);
225 set_registers(dev
, PHYCNT
, 1, &tmp
);
227 get_registers(dev
, PHYCNT
, 1, data
);
228 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
230 if (i
<= MII_TIMEOUT
) {
231 get_registers(dev
, PHYDAT
, 2, data
);
232 *reg
= data
[0] | (data
[1] << 8);
238 static int write_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16 reg
)
244 data
[1] = reg
& 0xff;
245 data
[2] = (reg
>> 8) & 0xff;
246 tmp
= indx
| PHY_WRITE
| PHY_GO
;
249 set_registers(dev
, PHYADD
, sizeof(data
), data
);
250 set_registers(dev
, PHYCNT
, 1, &tmp
);
252 get_registers(dev
, PHYCNT
, 1, data
);
253 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
255 if (i
<= MII_TIMEOUT
)
261 static inline void set_ethernet_addr(rtl8150_t
* dev
)
265 get_registers(dev
, IDR
, sizeof(node_id
), node_id
);
266 memcpy(dev
->netdev
->dev_addr
, node_id
, sizeof(node_id
));
269 static int rtl8150_set_mac_address(struct net_device
*netdev
, void *p
)
271 struct sockaddr
*addr
= p
;
272 rtl8150_t
*dev
= netdev_priv(netdev
);
274 if (netif_running(netdev
))
277 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
278 netdev_dbg(netdev
, "Setting MAC address to %pM\n", netdev
->dev_addr
);
279 /* Set the IDR registers. */
280 set_registers(dev
, IDR
, netdev
->addr_len
, netdev
->dev_addr
);
285 /* Get the CR contents. */
286 get_registers(dev
, CR
, 1, &cr
);
287 /* Set the WEPROM bit (eeprom write enable). */
289 set_registers(dev
, CR
, 1, &cr
);
290 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
291 so we need to split them up. */
292 for (i
= 0; i
* 2 < netdev
->addr_len
; i
++) {
293 set_registers(dev
, IDR_EEPROM
+ (i
* 2), 2,
294 netdev
->dev_addr
+ (i
* 2));
296 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
298 set_registers(dev
, CR
, 1, &cr
);
304 static int rtl8150_reset(rtl8150_t
* dev
)
309 set_registers(dev
, CR
, 1, &data
);
311 get_registers(dev
, CR
, 1, &data
);
312 } while ((data
& 0x10) && --i
);
314 return (i
> 0) ? 1 : 0;
317 static int alloc_all_urbs(rtl8150_t
* dev
)
319 dev
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
322 dev
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
324 usb_free_urb(dev
->rx_urb
);
327 dev
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
328 if (!dev
->intr_urb
) {
329 usb_free_urb(dev
->rx_urb
);
330 usb_free_urb(dev
->tx_urb
);
333 dev
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
334 if (!dev
->ctrl_urb
) {
335 usb_free_urb(dev
->rx_urb
);
336 usb_free_urb(dev
->tx_urb
);
337 usb_free_urb(dev
->intr_urb
);
344 static void free_all_urbs(rtl8150_t
* dev
)
346 usb_free_urb(dev
->rx_urb
);
347 usb_free_urb(dev
->tx_urb
);
348 usb_free_urb(dev
->intr_urb
);
349 usb_free_urb(dev
->ctrl_urb
);
352 static void unlink_all_urbs(rtl8150_t
* dev
)
354 usb_kill_urb(dev
->rx_urb
);
355 usb_kill_urb(dev
->tx_urb
);
356 usb_kill_urb(dev
->intr_urb
);
357 usb_kill_urb(dev
->ctrl_urb
);
360 static inline struct sk_buff
*pull_skb(rtl8150_t
*dev
)
365 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
366 if (dev
->rx_skb_pool
[i
]) {
367 skb
= dev
->rx_skb_pool
[i
];
368 dev
->rx_skb_pool
[i
] = NULL
;
375 static void read_bulk_callback(struct urb
*urb
)
378 unsigned pkt_len
, res
;
380 struct net_device
*netdev
;
382 int status
= urb
->status
;
388 if (test_bit(RTL8150_UNPLUG
, &dev
->flags
))
390 netdev
= dev
->netdev
;
391 if (!netif_device_present(netdev
))
398 return; /* the urb is in unlink state */
400 if (printk_ratelimit())
401 dev_warn(&urb
->dev
->dev
, "may be reset is needed?..\n");
404 if (printk_ratelimit())
405 dev_warn(&urb
->dev
->dev
, "Rx status %d\n", status
);
411 /* protect against short packets (tell me why we got some?!?) */
412 if (urb
->actual_length
< 4)
415 res
= urb
->actual_length
;
416 rx_stat
= le16_to_cpu(*(__le16
*)(urb
->transfer_buffer
+ res
- 4));
419 skb_put(dev
->rx_skb
, pkt_len
);
420 dev
->rx_skb
->protocol
= eth_type_trans(dev
->rx_skb
, netdev
);
421 netif_rx(dev
->rx_skb
);
422 netdev
->stats
.rx_packets
++;
423 netdev
->stats
.rx_bytes
+= pkt_len
;
425 spin_lock(&dev
->rx_pool_lock
);
427 spin_unlock(&dev
->rx_pool_lock
);
433 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
434 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
435 result
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
436 if (result
== -ENODEV
)
437 netif_device_detach(dev
->netdev
);
439 set_bit(RX_URB_FAIL
, &dev
->flags
);
442 clear_bit(RX_URB_FAIL
, &dev
->flags
);
447 tasklet_schedule(&dev
->tl
);
450 static void write_bulk_callback(struct urb
*urb
)
453 int status
= urb
->status
;
458 dev_kfree_skb_irq(dev
->tx_skb
);
459 if (!netif_device_present(dev
->netdev
))
462 dev_info(&urb
->dev
->dev
, "%s: Tx status %d\n",
463 dev
->netdev
->name
, status
);
464 dev
->netdev
->trans_start
= jiffies
;
465 netif_wake_queue(dev
->netdev
);
468 static void intr_callback(struct urb
*urb
)
472 int status
= urb
->status
;
479 case 0: /* success */
481 case -ECONNRESET
: /* unlink */
485 /* -EPIPE: should clear the halt */
487 dev_info(&urb
->dev
->dev
, "%s: intr status %d\n",
488 dev
->netdev
->name
, status
);
492 d
= urb
->transfer_buffer
;
493 if (d
[0] & TSR_ERRORS
) {
494 dev
->netdev
->stats
.tx_errors
++;
495 if (d
[INT_TSR
] & (TSR_ECOL
| TSR_JBR
))
496 dev
->netdev
->stats
.tx_aborted_errors
++;
497 if (d
[INT_TSR
] & TSR_LCOL
)
498 dev
->netdev
->stats
.tx_window_errors
++;
499 if (d
[INT_TSR
] & TSR_LOSS_CRS
)
500 dev
->netdev
->stats
.tx_carrier_errors
++;
502 /* Report link status changes to the network stack */
503 if ((d
[INT_MSR
] & MSR_LINK
) == 0) {
504 if (netif_carrier_ok(dev
->netdev
)) {
505 netif_carrier_off(dev
->netdev
);
506 netdev_dbg(dev
->netdev
, "%s: LINK LOST\n", __func__
);
509 if (!netif_carrier_ok(dev
->netdev
)) {
510 netif_carrier_on(dev
->netdev
);
511 netdev_dbg(dev
->netdev
, "%s: LINK CAME BACK\n", __func__
);
516 res
= usb_submit_urb (urb
, GFP_ATOMIC
);
518 netif_device_detach(dev
->netdev
);
520 dev_err(&dev
->udev
->dev
,
521 "can't resubmit intr, %s-%s/input0, status %d\n",
522 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
, res
);
525 static int rtl8150_suspend(struct usb_interface
*intf
, pm_message_t message
)
527 rtl8150_t
*dev
= usb_get_intfdata(intf
);
529 netif_device_detach(dev
->netdev
);
531 if (netif_running(dev
->netdev
)) {
532 usb_kill_urb(dev
->rx_urb
);
533 usb_kill_urb(dev
->intr_urb
);
538 static int rtl8150_resume(struct usb_interface
*intf
)
540 rtl8150_t
*dev
= usb_get_intfdata(intf
);
542 netif_device_attach(dev
->netdev
);
543 if (netif_running(dev
->netdev
)) {
544 dev
->rx_urb
->status
= 0;
545 dev
->rx_urb
->actual_length
= 0;
546 read_bulk_callback(dev
->rx_urb
);
548 dev
->intr_urb
->status
= 0;
549 dev
->intr_urb
->actual_length
= 0;
550 intr_callback(dev
->intr_urb
);
557 ** network related part of the code
561 static void fill_skb_pool(rtl8150_t
*dev
)
566 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
567 if (dev
->rx_skb_pool
[i
])
569 skb
= dev_alloc_skb(RTL8150_MTU
+ 2);
574 dev
->rx_skb_pool
[i
] = skb
;
578 static void free_skb_pool(rtl8150_t
*dev
)
582 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++)
583 if (dev
->rx_skb_pool
[i
])
584 dev_kfree_skb(dev
->rx_skb_pool
[i
]);
587 static void rx_fixup(unsigned long data
)
589 struct rtl8150
*dev
= (struct rtl8150
*)data
;
593 spin_lock_irq(&dev
->rx_pool_lock
);
595 spin_unlock_irq(&dev
->rx_pool_lock
);
596 if (test_bit(RX_URB_FAIL
, &dev
->flags
))
599 spin_lock_irq(&dev
->rx_pool_lock
);
601 spin_unlock_irq(&dev
->rx_pool_lock
);
605 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
606 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
608 status
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
609 if (status
== -ENODEV
) {
610 netif_device_detach(dev
->netdev
);
612 set_bit(RX_URB_FAIL
, &dev
->flags
);
615 clear_bit(RX_URB_FAIL
, &dev
->flags
);
620 tasklet_schedule(&dev
->tl
);
623 static int enable_net_traffic(rtl8150_t
* dev
)
625 u8 cr
, tcr
, rcr
, msr
;
627 if (!rtl8150_reset(dev
)) {
628 dev_warn(&dev
->udev
->dev
, "device reset failed\n");
630 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
632 dev
->rx_creg
= cpu_to_le16(rcr
);
636 set_bit(RTL8150_HW_CRC
, &dev
->flags
);
637 set_registers(dev
, RCR
, 1, &rcr
);
638 set_registers(dev
, TCR
, 1, &tcr
);
639 set_registers(dev
, CR
, 1, &cr
);
640 get_registers(dev
, MSR
, 1, &msr
);
645 static void disable_net_traffic(rtl8150_t
* dev
)
649 get_registers(dev
, CR
, 1, &cr
);
651 set_registers(dev
, CR
, 1, &cr
);
654 static void rtl8150_tx_timeout(struct net_device
*netdev
)
656 rtl8150_t
*dev
= netdev_priv(netdev
);
657 dev_warn(&netdev
->dev
, "Tx timeout.\n");
658 usb_unlink_urb(dev
->tx_urb
);
659 netdev
->stats
.tx_errors
++;
662 static void rtl8150_set_multicast(struct net_device
*netdev
)
664 rtl8150_t
*dev
= netdev_priv(netdev
);
665 netif_stop_queue(netdev
);
666 if (netdev
->flags
& IFF_PROMISC
) {
667 dev
->rx_creg
|= cpu_to_le16(0x0001);
668 dev_info(&netdev
->dev
, "%s: promiscuous mode\n", netdev
->name
);
669 } else if (!netdev_mc_empty(netdev
) ||
670 (netdev
->flags
& IFF_ALLMULTI
)) {
671 dev
->rx_creg
&= cpu_to_le16(0xfffe);
672 dev
->rx_creg
|= cpu_to_le16(0x0002);
673 dev_info(&netdev
->dev
, "%s: allmulti set\n", netdev
->name
);
675 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
676 dev
->rx_creg
&= cpu_to_le16(0x00fc);
678 async_set_registers(dev
, RCR
, 2);
679 netif_wake_queue(netdev
);
682 static netdev_tx_t
rtl8150_start_xmit(struct sk_buff
*skb
,
683 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 /* Can we get/handle EPIPE here? */
697 netif_device_detach(dev
->netdev
);
699 dev_warn(&netdev
->dev
, "failed tx_urb %d\n", res
);
700 netdev
->stats
.tx_errors
++;
701 netif_start_queue(netdev
);
704 netdev
->stats
.tx_packets
++;
705 netdev
->stats
.tx_bytes
+= skb
->len
;
706 netdev
->trans_start
= jiffies
;
713 static void set_carrier(struct net_device
*netdev
)
715 rtl8150_t
*dev
= netdev_priv(netdev
);
718 get_registers(dev
, CSCR
, 2, &tmp
);
719 if (tmp
& CSCR_LINK_STATUS
)
720 netif_carrier_on(netdev
);
722 netif_carrier_off(netdev
);
725 static int rtl8150_open(struct net_device
*netdev
)
727 rtl8150_t
*dev
= netdev_priv(netdev
);
730 if (dev
->rx_skb
== NULL
)
731 dev
->rx_skb
= pull_skb(dev
);
735 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
737 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
738 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
739 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
))) {
741 netif_device_detach(dev
->netdev
);
742 dev_warn(&netdev
->dev
, "rx_urb submit failed: %d\n", res
);
745 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
746 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
747 dev
, dev
->intr_interval
);
748 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
))) {
750 netif_device_detach(dev
->netdev
);
751 dev_warn(&netdev
->dev
, "intr_urb submit failed: %d\n", res
);
752 usb_kill_urb(dev
->rx_urb
);
755 enable_net_traffic(dev
);
757 netif_start_queue(netdev
);
762 static int rtl8150_close(struct net_device
*netdev
)
764 rtl8150_t
*dev
= netdev_priv(netdev
);
767 netif_stop_queue(netdev
);
768 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
769 disable_net_traffic(dev
);
770 unlink_all_urbs(dev
);
775 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
777 rtl8150_t
*dev
= netdev_priv(netdev
);
779 strlcpy(info
->driver
, driver_name
, sizeof(info
->driver
));
780 strlcpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
781 usb_make_path(dev
->udev
, info
->bus_info
, sizeof(info
->bus_info
));
784 static int rtl8150_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
786 rtl8150_t
*dev
= netdev_priv(netdev
);
789 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
790 SUPPORTED_10baseT_Full
|
791 SUPPORTED_100baseT_Half
|
792 SUPPORTED_100baseT_Full
|
794 SUPPORTED_TP
| SUPPORTED_MII
);
795 ecmd
->port
= PORT_TP
;
796 ecmd
->transceiver
= XCVR_INTERNAL
;
797 ecmd
->phy_address
= dev
->phy
;
798 get_registers(dev
, BMCR
, 2, &bmcr
);
799 get_registers(dev
, ANLP
, 2, &lpa
);
800 if (bmcr
& BMCR_ANENABLE
) {
801 u32 speed
= ((lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
802 SPEED_100
: SPEED_10
);
803 ethtool_cmd_speed_set(ecmd
, speed
);
804 ecmd
->autoneg
= AUTONEG_ENABLE
;
805 if (speed
== SPEED_100
)
806 ecmd
->duplex
= (lpa
& LPA_100FULL
) ?
807 DUPLEX_FULL
: DUPLEX_HALF
;
809 ecmd
->duplex
= (lpa
& LPA_10FULL
) ?
810 DUPLEX_FULL
: DUPLEX_HALF
;
812 ecmd
->autoneg
= AUTONEG_DISABLE
;
813 ethtool_cmd_speed_set(ecmd
, ((bmcr
& BMCR_SPEED100
) ?
814 SPEED_100
: SPEED_10
));
815 ecmd
->duplex
= (bmcr
& BMCR_FULLDPLX
) ?
816 DUPLEX_FULL
: DUPLEX_HALF
;
821 static const struct ethtool_ops ops
= {
822 .get_drvinfo
= rtl8150_get_drvinfo
,
823 .get_settings
= rtl8150_get_settings
,
824 .get_link
= ethtool_op_get_link
827 static int rtl8150_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
829 rtl8150_t
*dev
= netdev_priv(netdev
);
830 u16
*data
= (u16
*) & rq
->ifr_ifru
;
836 case SIOCDEVPRIVATE
+ 1:
837 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
839 case SIOCDEVPRIVATE
+ 2:
840 if (!capable(CAP_NET_ADMIN
))
842 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
851 static const struct net_device_ops rtl8150_netdev_ops
= {
852 .ndo_open
= rtl8150_open
,
853 .ndo_stop
= rtl8150_close
,
854 .ndo_do_ioctl
= rtl8150_ioctl
,
855 .ndo_start_xmit
= rtl8150_start_xmit
,
856 .ndo_tx_timeout
= rtl8150_tx_timeout
,
857 .ndo_set_rx_mode
= rtl8150_set_multicast
,
858 .ndo_set_mac_address
= rtl8150_set_mac_address
,
860 .ndo_change_mtu
= eth_change_mtu
,
861 .ndo_validate_addr
= eth_validate_addr
,
864 static int rtl8150_probe(struct usb_interface
*intf
,
865 const struct usb_device_id
*id
)
867 struct usb_device
*udev
= interface_to_usbdev(intf
);
869 struct net_device
*netdev
;
871 netdev
= alloc_etherdev(sizeof(rtl8150_t
));
875 dev
= netdev_priv(netdev
);
877 dev
->intr_buff
= kmalloc(INTBUFSIZE
, GFP_KERNEL
);
878 if (!dev
->intr_buff
) {
883 tasklet_init(&dev
->tl
, rx_fixup
, (unsigned long)dev
);
884 spin_lock_init(&dev
->rx_pool_lock
);
887 dev
->netdev
= netdev
;
888 netdev
->netdev_ops
= &rtl8150_netdev_ops
;
889 netdev
->watchdog_timeo
= RTL8150_TX_TIMEOUT
;
890 SET_ETHTOOL_OPS(netdev
, &ops
);
891 dev
->intr_interval
= 100; /* 100ms */
893 if (!alloc_all_urbs(dev
)) {
894 dev_err(&intf
->dev
, "out of memory\n");
897 if (!rtl8150_reset(dev
)) {
898 dev_err(&intf
->dev
, "couldn't reset the device\n");
902 set_ethernet_addr(dev
);
904 usb_set_intfdata(intf
, dev
);
905 SET_NETDEV_DEV(netdev
, &intf
->dev
);
906 if (register_netdev(netdev
) != 0) {
907 dev_err(&intf
->dev
, "couldn't register the device\n");
911 dev_info(&intf
->dev
, "%s: rtl8150 is detected\n", netdev
->name
);
916 usb_set_intfdata(intf
, NULL
);
921 kfree(dev
->intr_buff
);
926 static void rtl8150_disconnect(struct usb_interface
*intf
)
928 rtl8150_t
*dev
= usb_get_intfdata(intf
);
930 usb_set_intfdata(intf
, NULL
);
932 set_bit(RTL8150_UNPLUG
, &dev
->flags
);
933 tasklet_kill(&dev
->tl
);
934 unregister_netdev(dev
->netdev
);
935 unlink_all_urbs(dev
);
939 dev_kfree_skb(dev
->rx_skb
);
940 kfree(dev
->intr_buff
);
941 free_netdev(dev
->netdev
);
945 static struct usb_driver rtl8150_driver
= {
947 .probe
= rtl8150_probe
,
948 .disconnect
= rtl8150_disconnect
,
949 .id_table
= rtl8150_table
,
950 .suspend
= rtl8150_suspend
,
951 .resume
= rtl8150_resume
,
952 .disable_hub_initiated_lpm
= 1,
955 module_usb_driver(rtl8150_driver
);
957 MODULE_AUTHOR(DRIVER_AUTHOR
);
958 MODULE_DESCRIPTION(DRIVER_DESC
);
959 MODULE_LICENSE("GPL");