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
;
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
;
143 typedef struct rtl8150 rtl8150_t
;
146 struct usb_ctrlrequest dr
;
150 static const char driver_name
[] = "rtl8150";
154 ** device related part of the code
157 static int get_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
159 return usb_control_msg(dev
->udev
, usb_rcvctrlpipe(dev
->udev
, 0),
160 RTL8150_REQ_GET_REGS
, RTL8150_REQT_READ
,
161 indx
, 0, data
, size
, 500);
164 static int set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, void *data
)
166 return usb_control_msg(dev
->udev
, usb_sndctrlpipe(dev
->udev
, 0),
167 RTL8150_REQ_SET_REGS
, RTL8150_REQT_WRITE
,
168 indx
, 0, data
, size
, 500);
171 static void async_set_reg_cb(struct urb
*urb
)
173 struct async_req
*req
= (struct async_req
*)urb
->context
;
174 int status
= urb
->status
;
177 dev_dbg(&urb
->dev
->dev
, "%s failed with %d", __func__
, status
);
182 static int async_set_registers(rtl8150_t
*dev
, u16 indx
, u16 size
, u16 reg
)
185 struct urb
*async_urb
;
186 struct async_req
*req
;
188 req
= kmalloc(sizeof(struct async_req
), GFP_ATOMIC
);
191 async_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
192 if (async_urb
== NULL
) {
196 req
->rx_creg
= cpu_to_le16(reg
);
197 req
->dr
.bRequestType
= RTL8150_REQT_WRITE
;
198 req
->dr
.bRequest
= RTL8150_REQ_SET_REGS
;
200 req
->dr
.wValue
= cpu_to_le16(indx
);
201 req
->dr
.wLength
= cpu_to_le16(size
);
202 usb_fill_control_urb(async_urb
, dev
->udev
,
203 usb_sndctrlpipe(dev
->udev
, 0), (void *)&req
->dr
,
204 &req
->rx_creg
, size
, async_set_reg_cb
, req
);
205 res
= usb_submit_urb(async_urb
, GFP_ATOMIC
);
208 netif_device_detach(dev
->netdev
);
209 dev_err(&dev
->udev
->dev
, "%s failed with %d\n", __func__
, res
);
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
);
337 static void free_all_urbs(rtl8150_t
* dev
)
339 usb_free_urb(dev
->rx_urb
);
340 usb_free_urb(dev
->tx_urb
);
341 usb_free_urb(dev
->intr_urb
);
344 static void unlink_all_urbs(rtl8150_t
* dev
)
346 usb_kill_urb(dev
->rx_urb
);
347 usb_kill_urb(dev
->tx_urb
);
348 usb_kill_urb(dev
->intr_urb
);
351 static inline struct sk_buff
*pull_skb(rtl8150_t
*dev
)
356 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
357 if (dev
->rx_skb_pool
[i
]) {
358 skb
= dev
->rx_skb_pool
[i
];
359 dev
->rx_skb_pool
[i
] = NULL
;
366 static void read_bulk_callback(struct urb
*urb
)
369 unsigned pkt_len
, res
;
371 struct net_device
*netdev
;
373 int status
= urb
->status
;
379 if (test_bit(RTL8150_UNPLUG
, &dev
->flags
))
381 netdev
= dev
->netdev
;
382 if (!netif_device_present(netdev
))
389 return; /* the urb is in unlink state */
391 if (printk_ratelimit())
392 dev_warn(&urb
->dev
->dev
, "may be reset is needed?..\n");
395 if (printk_ratelimit())
396 dev_warn(&urb
->dev
->dev
, "Rx status %d\n", status
);
402 /* protect against short packets (tell me why we got some?!?) */
403 if (urb
->actual_length
< 4)
406 res
= urb
->actual_length
;
407 rx_stat
= le16_to_cpu(*(__le16
*)(urb
->transfer_buffer
+ res
- 4));
410 skb_put(dev
->rx_skb
, pkt_len
);
411 dev
->rx_skb
->protocol
= eth_type_trans(dev
->rx_skb
, netdev
);
412 netif_rx(dev
->rx_skb
);
413 netdev
->stats
.rx_packets
++;
414 netdev
->stats
.rx_bytes
+= pkt_len
;
416 spin_lock(&dev
->rx_pool_lock
);
418 spin_unlock(&dev
->rx_pool_lock
);
424 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
425 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
426 result
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
427 if (result
== -ENODEV
)
428 netif_device_detach(dev
->netdev
);
430 set_bit(RX_URB_FAIL
, &dev
->flags
);
433 clear_bit(RX_URB_FAIL
, &dev
->flags
);
438 tasklet_schedule(&dev
->tl
);
441 static void write_bulk_callback(struct urb
*urb
)
444 int status
= urb
->status
;
449 dev_kfree_skb_irq(dev
->tx_skb
);
450 if (!netif_device_present(dev
->netdev
))
453 dev_info(&urb
->dev
->dev
, "%s: Tx status %d\n",
454 dev
->netdev
->name
, status
);
455 dev
->netdev
->trans_start
= jiffies
;
456 netif_wake_queue(dev
->netdev
);
459 static void intr_callback(struct urb
*urb
)
463 int status
= urb
->status
;
470 case 0: /* success */
472 case -ECONNRESET
: /* unlink */
476 /* -EPIPE: should clear the halt */
478 dev_info(&urb
->dev
->dev
, "%s: intr status %d\n",
479 dev
->netdev
->name
, status
);
483 d
= urb
->transfer_buffer
;
484 if (d
[0] & TSR_ERRORS
) {
485 dev
->netdev
->stats
.tx_errors
++;
486 if (d
[INT_TSR
] & (TSR_ECOL
| TSR_JBR
))
487 dev
->netdev
->stats
.tx_aborted_errors
++;
488 if (d
[INT_TSR
] & TSR_LCOL
)
489 dev
->netdev
->stats
.tx_window_errors
++;
490 if (d
[INT_TSR
] & TSR_LOSS_CRS
)
491 dev
->netdev
->stats
.tx_carrier_errors
++;
493 /* Report link status changes to the network stack */
494 if ((d
[INT_MSR
] & MSR_LINK
) == 0) {
495 if (netif_carrier_ok(dev
->netdev
)) {
496 netif_carrier_off(dev
->netdev
);
497 netdev_dbg(dev
->netdev
, "%s: LINK LOST\n", __func__
);
500 if (!netif_carrier_ok(dev
->netdev
)) {
501 netif_carrier_on(dev
->netdev
);
502 netdev_dbg(dev
->netdev
, "%s: LINK CAME BACK\n", __func__
);
507 res
= usb_submit_urb (urb
, GFP_ATOMIC
);
509 netif_device_detach(dev
->netdev
);
511 dev_err(&dev
->udev
->dev
,
512 "can't resubmit intr, %s-%s/input0, status %d\n",
513 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
, res
);
516 static int rtl8150_suspend(struct usb_interface
*intf
, pm_message_t message
)
518 rtl8150_t
*dev
= usb_get_intfdata(intf
);
520 netif_device_detach(dev
->netdev
);
522 if (netif_running(dev
->netdev
)) {
523 usb_kill_urb(dev
->rx_urb
);
524 usb_kill_urb(dev
->intr_urb
);
529 static int rtl8150_resume(struct usb_interface
*intf
)
531 rtl8150_t
*dev
= usb_get_intfdata(intf
);
533 netif_device_attach(dev
->netdev
);
534 if (netif_running(dev
->netdev
)) {
535 dev
->rx_urb
->status
= 0;
536 dev
->rx_urb
->actual_length
= 0;
537 read_bulk_callback(dev
->rx_urb
);
539 dev
->intr_urb
->status
= 0;
540 dev
->intr_urb
->actual_length
= 0;
541 intr_callback(dev
->intr_urb
);
548 ** network related part of the code
552 static void fill_skb_pool(rtl8150_t
*dev
)
557 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
558 if (dev
->rx_skb_pool
[i
])
560 skb
= dev_alloc_skb(RTL8150_MTU
+ 2);
565 dev
->rx_skb_pool
[i
] = skb
;
569 static void free_skb_pool(rtl8150_t
*dev
)
573 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++)
574 if (dev
->rx_skb_pool
[i
])
575 dev_kfree_skb(dev
->rx_skb_pool
[i
]);
578 static void rx_fixup(unsigned long data
)
580 struct rtl8150
*dev
= (struct rtl8150
*)data
;
584 spin_lock_irq(&dev
->rx_pool_lock
);
586 spin_unlock_irq(&dev
->rx_pool_lock
);
587 if (test_bit(RX_URB_FAIL
, &dev
->flags
))
590 spin_lock_irq(&dev
->rx_pool_lock
);
592 spin_unlock_irq(&dev
->rx_pool_lock
);
596 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
597 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
599 status
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
600 if (status
== -ENODEV
) {
601 netif_device_detach(dev
->netdev
);
603 set_bit(RX_URB_FAIL
, &dev
->flags
);
606 clear_bit(RX_URB_FAIL
, &dev
->flags
);
611 tasklet_schedule(&dev
->tl
);
614 static int enable_net_traffic(rtl8150_t
* dev
)
616 u8 cr
, tcr
, rcr
, msr
;
618 if (!rtl8150_reset(dev
)) {
619 dev_warn(&dev
->udev
->dev
, "device reset failed\n");
621 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
626 set_bit(RTL8150_HW_CRC
, &dev
->flags
);
627 set_registers(dev
, RCR
, 1, &rcr
);
628 set_registers(dev
, TCR
, 1, &tcr
);
629 set_registers(dev
, CR
, 1, &cr
);
630 get_registers(dev
, MSR
, 1, &msr
);
635 static void disable_net_traffic(rtl8150_t
* dev
)
639 get_registers(dev
, CR
, 1, &cr
);
641 set_registers(dev
, CR
, 1, &cr
);
644 static void rtl8150_tx_timeout(struct net_device
*netdev
)
646 rtl8150_t
*dev
= netdev_priv(netdev
);
647 dev_warn(&netdev
->dev
, "Tx timeout.\n");
648 usb_unlink_urb(dev
->tx_urb
);
649 netdev
->stats
.tx_errors
++;
652 static void rtl8150_set_multicast(struct net_device
*netdev
)
654 rtl8150_t
*dev
= netdev_priv(netdev
);
657 netif_stop_queue(netdev
);
658 if (netdev
->flags
& IFF_PROMISC
) {
660 dev_info(&netdev
->dev
, "%s: promiscuous mode\n", netdev
->name
);
661 } else if (!netdev_mc_empty(netdev
) ||
662 (netdev
->flags
& IFF_ALLMULTI
)) {
665 dev_info(&netdev
->dev
, "%s: allmulti set\n", netdev
->name
);
667 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
670 async_set_registers(dev
, RCR
, sizeof(rx_creg
), rx_creg
);
671 netif_wake_queue(netdev
);
674 static netdev_tx_t
rtl8150_start_xmit(struct sk_buff
*skb
,
675 struct net_device
*netdev
)
677 rtl8150_t
*dev
= netdev_priv(netdev
);
680 netif_stop_queue(netdev
);
681 count
= (skb
->len
< 60) ? 60 : skb
->len
;
682 count
= (count
& 0x3f) ? count
: count
+ 1;
684 usb_fill_bulk_urb(dev
->tx_urb
, dev
->udev
, usb_sndbulkpipe(dev
->udev
, 2),
685 skb
->data
, count
, write_bulk_callback
, dev
);
686 if ((res
= usb_submit_urb(dev
->tx_urb
, GFP_ATOMIC
))) {
687 /* Can we get/handle EPIPE here? */
689 netif_device_detach(dev
->netdev
);
691 dev_warn(&netdev
->dev
, "failed tx_urb %d\n", res
);
692 netdev
->stats
.tx_errors
++;
693 netif_start_queue(netdev
);
696 netdev
->stats
.tx_packets
++;
697 netdev
->stats
.tx_bytes
+= skb
->len
;
698 netdev
->trans_start
= jiffies
;
705 static void set_carrier(struct net_device
*netdev
)
707 rtl8150_t
*dev
= netdev_priv(netdev
);
710 get_registers(dev
, CSCR
, 2, &tmp
);
711 if (tmp
& CSCR_LINK_STATUS
)
712 netif_carrier_on(netdev
);
714 netif_carrier_off(netdev
);
717 static int rtl8150_open(struct net_device
*netdev
)
719 rtl8150_t
*dev
= netdev_priv(netdev
);
722 if (dev
->rx_skb
== NULL
)
723 dev
->rx_skb
= pull_skb(dev
);
727 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
729 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
730 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
731 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
))) {
733 netif_device_detach(dev
->netdev
);
734 dev_warn(&netdev
->dev
, "rx_urb submit failed: %d\n", res
);
737 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
738 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
739 dev
, dev
->intr_interval
);
740 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
))) {
742 netif_device_detach(dev
->netdev
);
743 dev_warn(&netdev
->dev
, "intr_urb submit failed: %d\n", res
);
744 usb_kill_urb(dev
->rx_urb
);
747 enable_net_traffic(dev
);
749 netif_start_queue(netdev
);
754 static int rtl8150_close(struct net_device
*netdev
)
756 rtl8150_t
*dev
= netdev_priv(netdev
);
759 netif_stop_queue(netdev
);
760 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
761 disable_net_traffic(dev
);
762 unlink_all_urbs(dev
);
767 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
769 rtl8150_t
*dev
= netdev_priv(netdev
);
771 strlcpy(info
->driver
, driver_name
, sizeof(info
->driver
));
772 strlcpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
773 usb_make_path(dev
->udev
, info
->bus_info
, sizeof(info
->bus_info
));
776 static int rtl8150_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
778 rtl8150_t
*dev
= netdev_priv(netdev
);
781 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
782 SUPPORTED_10baseT_Full
|
783 SUPPORTED_100baseT_Half
|
784 SUPPORTED_100baseT_Full
|
786 SUPPORTED_TP
| SUPPORTED_MII
);
787 ecmd
->port
= PORT_TP
;
788 ecmd
->transceiver
= XCVR_INTERNAL
;
789 ecmd
->phy_address
= dev
->phy
;
790 get_registers(dev
, BMCR
, 2, &bmcr
);
791 get_registers(dev
, ANLP
, 2, &lpa
);
792 if (bmcr
& BMCR_ANENABLE
) {
793 u32 speed
= ((lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
794 SPEED_100
: SPEED_10
);
795 ethtool_cmd_speed_set(ecmd
, speed
);
796 ecmd
->autoneg
= AUTONEG_ENABLE
;
797 if (speed
== SPEED_100
)
798 ecmd
->duplex
= (lpa
& LPA_100FULL
) ?
799 DUPLEX_FULL
: DUPLEX_HALF
;
801 ecmd
->duplex
= (lpa
& LPA_10FULL
) ?
802 DUPLEX_FULL
: DUPLEX_HALF
;
804 ecmd
->autoneg
= AUTONEG_DISABLE
;
805 ethtool_cmd_speed_set(ecmd
, ((bmcr
& BMCR_SPEED100
) ?
806 SPEED_100
: SPEED_10
));
807 ecmd
->duplex
= (bmcr
& BMCR_FULLDPLX
) ?
808 DUPLEX_FULL
: DUPLEX_HALF
;
813 static const struct ethtool_ops ops
= {
814 .get_drvinfo
= rtl8150_get_drvinfo
,
815 .get_settings
= rtl8150_get_settings
,
816 .get_link
= ethtool_op_get_link
819 static int rtl8150_ioctl(struct net_device
*netdev
, struct ifreq
*rq
, int cmd
)
821 rtl8150_t
*dev
= netdev_priv(netdev
);
822 u16
*data
= (u16
*) & rq
->ifr_ifru
;
828 case SIOCDEVPRIVATE
+ 1:
829 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
831 case SIOCDEVPRIVATE
+ 2:
832 if (!capable(CAP_NET_ADMIN
))
834 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
843 static const struct net_device_ops rtl8150_netdev_ops
= {
844 .ndo_open
= rtl8150_open
,
845 .ndo_stop
= rtl8150_close
,
846 .ndo_do_ioctl
= rtl8150_ioctl
,
847 .ndo_start_xmit
= rtl8150_start_xmit
,
848 .ndo_tx_timeout
= rtl8150_tx_timeout
,
849 .ndo_set_rx_mode
= rtl8150_set_multicast
,
850 .ndo_set_mac_address
= rtl8150_set_mac_address
,
852 .ndo_change_mtu
= eth_change_mtu
,
853 .ndo_validate_addr
= eth_validate_addr
,
856 static int rtl8150_probe(struct usb_interface
*intf
,
857 const struct usb_device_id
*id
)
859 struct usb_device
*udev
= interface_to_usbdev(intf
);
861 struct net_device
*netdev
;
863 netdev
= alloc_etherdev(sizeof(rtl8150_t
));
867 dev
= netdev_priv(netdev
);
869 dev
->intr_buff
= kmalloc(INTBUFSIZE
, GFP_KERNEL
);
870 if (!dev
->intr_buff
) {
875 tasklet_init(&dev
->tl
, rx_fixup
, (unsigned long)dev
);
876 spin_lock_init(&dev
->rx_pool_lock
);
879 dev
->netdev
= netdev
;
880 netdev
->netdev_ops
= &rtl8150_netdev_ops
;
881 netdev
->watchdog_timeo
= RTL8150_TX_TIMEOUT
;
882 SET_ETHTOOL_OPS(netdev
, &ops
);
883 dev
->intr_interval
= 100; /* 100ms */
885 if (!alloc_all_urbs(dev
)) {
886 dev_err(&intf
->dev
, "out of memory\n");
889 if (!rtl8150_reset(dev
)) {
890 dev_err(&intf
->dev
, "couldn't reset the device\n");
894 set_ethernet_addr(dev
);
896 usb_set_intfdata(intf
, dev
);
897 SET_NETDEV_DEV(netdev
, &intf
->dev
);
898 if (register_netdev(netdev
) != 0) {
899 dev_err(&intf
->dev
, "couldn't register the device\n");
903 dev_info(&intf
->dev
, "%s: rtl8150 is detected\n", netdev
->name
);
908 usb_set_intfdata(intf
, NULL
);
913 kfree(dev
->intr_buff
);
918 static void rtl8150_disconnect(struct usb_interface
*intf
)
920 rtl8150_t
*dev
= usb_get_intfdata(intf
);
922 usb_set_intfdata(intf
, NULL
);
924 set_bit(RTL8150_UNPLUG
, &dev
->flags
);
925 tasklet_kill(&dev
->tl
);
926 unregister_netdev(dev
->netdev
);
927 unlink_all_urbs(dev
);
931 dev_kfree_skb(dev
->rx_skb
);
932 kfree(dev
->intr_buff
);
933 free_netdev(dev
->netdev
);
937 static struct usb_driver rtl8150_driver
= {
939 .probe
= rtl8150_probe
,
940 .disconnect
= rtl8150_disconnect
,
941 .id_table
= rtl8150_table
,
942 .suspend
= rtl8150_suspend
,
943 .resume
= rtl8150_resume
,
944 .disable_hub_initiated_lpm
= 1,
947 module_usb_driver(rtl8150_driver
);
949 MODULE_AUTHOR(DRIVER_AUTHOR
);
950 MODULE_DESCRIPTION(DRIVER_DESC
);
951 MODULE_LICENSE("GPL");