1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2002 Petko Manolov (petkan@users.sourceforge.net)
6 #include <linux/signal.h>
7 #include <linux/slab.h>
8 #include <linux/module.h>
9 #include <linux/netdevice.h>
10 #include <linux/etherdevice.h>
11 #include <linux/mii.h>
12 #include <linux/ethtool.h>
13 #include <linux/usb.h>
14 #include <linux/uaccess.h>
16 /* Version Information */
17 #define DRIVER_VERSION "v0.6.2 (2004/08/27)"
18 #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
19 #define DRIVER_DESC "rtl8150 based usb-ethernet driver"
40 #define CSCR 0x014C /* This one has the link status */
41 #define CSCR_LINK_STATUS (1 << 3)
43 #define IDR_EEPROM 0x1202
46 #define PHY_WRITE 0x20
49 #define MII_TIMEOUT 10
52 #define RTL8150_REQT_READ 0xc0
53 #define RTL8150_REQT_WRITE 0x40
54 #define RTL8150_REQ_GET_REGS 0x05
55 #define RTL8150_REQ_SET_REGS 0x05
58 /* Transmit status register errors */
59 #define TSR_ECOL (1<<5)
60 #define TSR_LCOL (1<<4)
61 #define TSR_LOSS_CRS (1<<3)
62 #define TSR_JBR (1<<2)
63 #define TSR_ERRORS (TSR_ECOL | TSR_LCOL | TSR_LOSS_CRS | TSR_JBR)
64 /* Receive status register errors */
65 #define RSR_CRC (1<<2)
66 #define RSR_FAE (1<<1)
67 #define RSR_ERRORS (RSR_CRC | RSR_FAE)
69 /* Media status register definitions */
70 #define MSR_DUPLEX (1<<4)
71 #define MSR_SPEED (1<<3)
72 #define MSR_LINK (1<<2)
74 /* Interrupt pipe data */
78 #define INT_WAKSR 0x03
79 #define INT_TXOK_CNT 0x04
80 #define INT_RXLOST_CNT 0x05
81 #define INT_CRERR_CNT 0x06
82 #define INT_COL_CNT 0x07
85 #define RTL8150_MTU 1540
86 #define RTL8150_TX_TIMEOUT (HZ)
87 #define RX_SKB_POOL_SIZE 4
90 #define RTL8150_HW_CRC 0
92 #define RTL8150_UNPLUG 2
95 /* Define these values to match your device */
96 #define VENDOR_ID_REALTEK 0x0bda
97 #define VENDOR_ID_MELCO 0x0411
98 #define VENDOR_ID_MICRONET 0x3980
99 #define VENDOR_ID_LONGSHINE 0x07b8
100 #define VENDOR_ID_OQO 0x1557
101 #define VENDOR_ID_ZYXEL 0x0586
103 #define PRODUCT_ID_RTL8150 0x8150
104 #define PRODUCT_ID_LUAKTX 0x0012
105 #define PRODUCT_ID_LCS8138TX 0x401a
106 #define PRODUCT_ID_SP128AR 0x0003
107 #define PRODUCT_ID_PRESTIGE 0x401a
111 /* table of devices that work with this driver */
112 static const struct usb_device_id rtl8150_table
[] = {
113 {USB_DEVICE(VENDOR_ID_REALTEK
, PRODUCT_ID_RTL8150
)},
114 {USB_DEVICE(VENDOR_ID_MELCO
, PRODUCT_ID_LUAKTX
)},
115 {USB_DEVICE(VENDOR_ID_MICRONET
, PRODUCT_ID_SP128AR
)},
116 {USB_DEVICE(VENDOR_ID_LONGSHINE
, PRODUCT_ID_LCS8138TX
)},
117 {USB_DEVICE(VENDOR_ID_OQO
, PRODUCT_ID_RTL8150
)},
118 {USB_DEVICE(VENDOR_ID_ZYXEL
, PRODUCT_ID_PRESTIGE
)},
122 MODULE_DEVICE_TABLE(usb
, rtl8150_table
);
126 struct usb_device
*udev
;
127 struct tasklet_struct tl
;
128 struct net_device
*netdev
;
129 struct urb
*rx_urb
, *tx_urb
, *intr_urb
;
130 struct sk_buff
*tx_skb
, *rx_skb
;
131 struct sk_buff
*rx_skb_pool
[RX_SKB_POOL_SIZE
];
132 spinlock_t rx_pool_lock
;
133 struct usb_ctrlrequest dr
;
139 typedef struct rtl8150 rtl8150_t
;
142 struct usb_ctrlrequest dr
;
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_recv(dev
->udev
, 0, RTL8150_REQ_GET_REGS
,
156 RTL8150_REQT_READ
, indx
, 0, data
, size
,
160 static int set_registers(rtl8150_t
* dev
, u16 indx
, u16 size
, const void *data
)
162 return usb_control_msg_send(dev
->udev
, 0, RTL8150_REQ_SET_REGS
,
163 RTL8150_REQT_WRITE
, indx
, 0, data
, size
,
167 static void async_set_reg_cb(struct urb
*urb
)
169 struct async_req
*req
= (struct async_req
*)urb
->context
;
170 int status
= urb
->status
;
173 dev_dbg(&urb
->dev
->dev
, "%s failed with %d", __func__
, status
);
178 static int async_set_registers(rtl8150_t
*dev
, u16 indx
, u16 size
, u16 reg
)
181 struct urb
*async_urb
;
182 struct async_req
*req
;
184 req
= kmalloc(sizeof(struct async_req
), GFP_ATOMIC
);
187 async_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
188 if (async_urb
== NULL
) {
192 req
->rx_creg
= cpu_to_le16(reg
);
193 req
->dr
.bRequestType
= RTL8150_REQT_WRITE
;
194 req
->dr
.bRequest
= RTL8150_REQ_SET_REGS
;
196 req
->dr
.wValue
= cpu_to_le16(indx
);
197 req
->dr
.wLength
= cpu_to_le16(size
);
198 usb_fill_control_urb(async_urb
, dev
->udev
,
199 usb_sndctrlpipe(dev
->udev
, 0), (void *)&req
->dr
,
200 &req
->rx_creg
, size
, async_set_reg_cb
, req
);
201 res
= usb_submit_urb(async_urb
, GFP_ATOMIC
);
204 netif_device_detach(dev
->netdev
);
205 dev_err(&dev
->udev
->dev
, "%s failed with %d\n", __func__
, res
);
210 static int read_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16
* reg
)
216 data
[1] = data
[2] = 0;
217 tmp
= indx
| PHY_READ
| PHY_GO
;
220 set_registers(dev
, PHYADD
, sizeof(data
), data
);
221 set_registers(dev
, PHYCNT
, 1, &tmp
);
223 get_registers(dev
, PHYCNT
, 1, data
);
224 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
226 if (i
<= MII_TIMEOUT
) {
227 get_registers(dev
, PHYDAT
, 2, data
);
228 *reg
= data
[0] | (data
[1] << 8);
234 static int write_mii_word(rtl8150_t
* dev
, u8 phy
, __u8 indx
, u16 reg
)
240 data
[1] = reg
& 0xff;
241 data
[2] = (reg
>> 8) & 0xff;
242 tmp
= indx
| PHY_WRITE
| PHY_GO
;
245 set_registers(dev
, PHYADD
, sizeof(data
), data
);
246 set_registers(dev
, PHYCNT
, 1, &tmp
);
248 get_registers(dev
, PHYCNT
, 1, data
);
249 } while ((data
[0] & PHY_GO
) && (i
++ < MII_TIMEOUT
));
251 if (i
<= MII_TIMEOUT
)
257 static void set_ethernet_addr(rtl8150_t
*dev
)
259 u8 node_id
[ETH_ALEN
];
262 ret
= get_registers(dev
, IDR
, sizeof(node_id
), node_id
);
265 eth_hw_addr_set(dev
->netdev
, node_id
);
267 eth_hw_addr_random(dev
->netdev
);
268 netdev_notice(dev
->netdev
, "Assigned a random MAC address: %pM\n",
269 dev
->netdev
->dev_addr
);
273 static int rtl8150_set_mac_address(struct net_device
*netdev
, void *p
)
275 struct sockaddr
*addr
= p
;
276 rtl8150_t
*dev
= netdev_priv(netdev
);
278 if (netif_running(netdev
))
281 eth_hw_addr_set(netdev
, addr
->sa_data
);
282 netdev_dbg(netdev
, "Setting MAC address to %pM\n", netdev
->dev_addr
);
283 /* Set the IDR registers. */
284 set_registers(dev
, IDR
, netdev
->addr_len
, netdev
->dev_addr
);
289 /* Get the CR contents. */
290 get_registers(dev
, CR
, 1, &cr
);
291 /* Set the WEPROM bit (eeprom write enable). */
293 set_registers(dev
, CR
, 1, &cr
);
294 /* Write the MAC address into eeprom. Eeprom writes must be word-sized,
295 so we need to split them up. */
296 for (i
= 0; i
* 2 < netdev
->addr_len
; i
++) {
297 set_registers(dev
, IDR_EEPROM
+ (i
* 2), 2,
298 netdev
->dev_addr
+ (i
* 2));
300 /* Clear the WEPROM bit (preventing accidental eeprom writes). */
302 set_registers(dev
, CR
, 1, &cr
);
308 static int rtl8150_reset(rtl8150_t
* dev
)
313 set_registers(dev
, CR
, 1, &data
);
315 get_registers(dev
, CR
, 1, &data
);
316 } while ((data
& 0x10) && --i
);
318 return (i
> 0) ? 1 : 0;
321 static int alloc_all_urbs(rtl8150_t
* dev
)
323 dev
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
326 dev
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
328 usb_free_urb(dev
->rx_urb
);
331 dev
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
332 if (!dev
->intr_urb
) {
333 usb_free_urb(dev
->rx_urb
);
334 usb_free_urb(dev
->tx_urb
);
341 static void free_all_urbs(rtl8150_t
* dev
)
343 usb_free_urb(dev
->rx_urb
);
344 usb_free_urb(dev
->tx_urb
);
345 usb_free_urb(dev
->intr_urb
);
348 static void unlink_all_urbs(rtl8150_t
* dev
)
350 usb_kill_urb(dev
->rx_urb
);
351 usb_kill_urb(dev
->tx_urb
);
352 usb_kill_urb(dev
->intr_urb
);
355 static inline struct sk_buff
*pull_skb(rtl8150_t
*dev
)
360 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
361 if (dev
->rx_skb_pool
[i
]) {
362 skb
= dev
->rx_skb_pool
[i
];
363 dev
->rx_skb_pool
[i
] = NULL
;
370 static void read_bulk_callback(struct urb
*urb
)
373 unsigned pkt_len
, res
;
375 struct net_device
*netdev
;
376 int status
= urb
->status
;
383 if (test_bit(RTL8150_UNPLUG
, &dev
->flags
))
385 netdev
= dev
->netdev
;
386 if (!netif_device_present(netdev
))
393 return; /* the urb is in unlink state */
395 if (printk_ratelimit())
396 dev_warn(&urb
->dev
->dev
, "may be reset is needed?..\n");
399 if (printk_ratelimit())
400 dev_warn(&urb
->dev
->dev
, "Rx status %d\n", status
);
406 /* protect against short packets (tell me why we got some?!?) */
407 if (urb
->actual_length
< 4)
410 res
= urb
->actual_length
;
413 skb_put(dev
->rx_skb
, pkt_len
);
414 dev
->rx_skb
->protocol
= eth_type_trans(dev
->rx_skb
, netdev
);
415 netif_rx(dev
->rx_skb
);
416 netdev
->stats
.rx_packets
++;
417 netdev
->stats
.rx_bytes
+= pkt_len
;
419 spin_lock_irqsave(&dev
->rx_pool_lock
, flags
);
421 spin_unlock_irqrestore(&dev
->rx_pool_lock
, flags
);
427 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
428 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
429 result
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
430 if (result
== -ENODEV
)
431 netif_device_detach(dev
->netdev
);
433 set_bit(RX_URB_FAIL
, &dev
->flags
);
436 clear_bit(RX_URB_FAIL
, &dev
->flags
);
441 tasklet_schedule(&dev
->tl
);
444 static void write_bulk_callback(struct urb
*urb
)
447 int status
= urb
->status
;
452 dev_kfree_skb_irq(dev
->tx_skb
);
453 if (!netif_device_present(dev
->netdev
))
456 dev_info(&urb
->dev
->dev
, "%s: Tx status %d\n",
457 dev
->netdev
->name
, status
);
458 netif_trans_update(dev
->netdev
);
459 netif_wake_queue(dev
->netdev
);
462 static void intr_callback(struct urb
*urb
)
466 int status
= urb
->status
;
473 case 0: /* success */
475 case -ECONNRESET
: /* unlink */
479 /* -EPIPE: should clear the halt */
481 dev_info(&urb
->dev
->dev
, "%s: intr status %d\n",
482 dev
->netdev
->name
, status
);
486 d
= urb
->transfer_buffer
;
487 if (d
[0] & TSR_ERRORS
) {
488 dev
->netdev
->stats
.tx_errors
++;
489 if (d
[INT_TSR
] & (TSR_ECOL
| TSR_JBR
))
490 dev
->netdev
->stats
.tx_aborted_errors
++;
491 if (d
[INT_TSR
] & TSR_LCOL
)
492 dev
->netdev
->stats
.tx_window_errors
++;
493 if (d
[INT_TSR
] & TSR_LOSS_CRS
)
494 dev
->netdev
->stats
.tx_carrier_errors
++;
496 /* Report link status changes to the network stack */
497 if ((d
[INT_MSR
] & MSR_LINK
) == 0) {
498 if (netif_carrier_ok(dev
->netdev
)) {
499 netif_carrier_off(dev
->netdev
);
500 netdev_dbg(dev
->netdev
, "%s: LINK LOST\n", __func__
);
503 if (!netif_carrier_ok(dev
->netdev
)) {
504 netif_carrier_on(dev
->netdev
);
505 netdev_dbg(dev
->netdev
, "%s: LINK CAME BACK\n", __func__
);
510 res
= usb_submit_urb (urb
, GFP_ATOMIC
);
512 netif_device_detach(dev
->netdev
);
514 dev_err(&dev
->udev
->dev
,
515 "can't resubmit intr, %s-%s/input0, status %d\n",
516 dev
->udev
->bus
->bus_name
, dev
->udev
->devpath
, res
);
519 static int rtl8150_suspend(struct usb_interface
*intf
, pm_message_t message
)
521 rtl8150_t
*dev
= usb_get_intfdata(intf
);
523 netif_device_detach(dev
->netdev
);
525 if (netif_running(dev
->netdev
)) {
526 usb_kill_urb(dev
->rx_urb
);
527 usb_kill_urb(dev
->intr_urb
);
532 static int rtl8150_resume(struct usb_interface
*intf
)
534 rtl8150_t
*dev
= usb_get_intfdata(intf
);
536 netif_device_attach(dev
->netdev
);
537 if (netif_running(dev
->netdev
)) {
538 dev
->rx_urb
->status
= 0;
539 dev
->rx_urb
->actual_length
= 0;
540 read_bulk_callback(dev
->rx_urb
);
542 dev
->intr_urb
->status
= 0;
543 dev
->intr_urb
->actual_length
= 0;
544 intr_callback(dev
->intr_urb
);
551 ** network related part of the code
555 static void fill_skb_pool(rtl8150_t
*dev
)
560 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++) {
561 if (dev
->rx_skb_pool
[i
])
563 skb
= dev_alloc_skb(RTL8150_MTU
+ 2);
568 dev
->rx_skb_pool
[i
] = skb
;
572 static void free_skb_pool(rtl8150_t
*dev
)
576 for (i
= 0; i
< RX_SKB_POOL_SIZE
; i
++)
577 dev_kfree_skb(dev
->rx_skb_pool
[i
]);
580 static void rx_fixup(struct tasklet_struct
*t
)
582 struct rtl8150
*dev
= from_tasklet(dev
, t
, tl
);
586 spin_lock_irq(&dev
->rx_pool_lock
);
588 spin_unlock_irq(&dev
->rx_pool_lock
);
589 if (test_bit(RX_URB_FAIL
, &dev
->flags
))
592 spin_lock_irq(&dev
->rx_pool_lock
);
594 spin_unlock_irq(&dev
->rx_pool_lock
);
598 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
599 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
601 status
= usb_submit_urb(dev
->rx_urb
, GFP_ATOMIC
);
602 if (status
== -ENODEV
) {
603 netif_device_detach(dev
->netdev
);
605 set_bit(RX_URB_FAIL
, &dev
->flags
);
608 clear_bit(RX_URB_FAIL
, &dev
->flags
);
613 tasklet_schedule(&dev
->tl
);
616 static int enable_net_traffic(rtl8150_t
* dev
)
618 u8 cr
, tcr
, rcr
, msr
;
620 if (!rtl8150_reset(dev
)) {
621 dev_warn(&dev
->udev
->dev
, "device reset failed\n");
623 /* RCR bit7=1 attach Rx info at the end; =0 HW CRC (which is broken) */
628 set_bit(RTL8150_HW_CRC
, &dev
->flags
);
629 set_registers(dev
, RCR
, 1, &rcr
);
630 set_registers(dev
, TCR
, 1, &tcr
);
631 set_registers(dev
, CR
, 1, &cr
);
632 get_registers(dev
, MSR
, 1, &msr
);
637 static void disable_net_traffic(rtl8150_t
* dev
)
641 get_registers(dev
, CR
, 1, &cr
);
643 set_registers(dev
, CR
, 1, &cr
);
646 static void rtl8150_tx_timeout(struct net_device
*netdev
, unsigned int txqueue
)
648 rtl8150_t
*dev
= netdev_priv(netdev
);
649 dev_warn(&netdev
->dev
, "Tx timeout.\n");
650 usb_unlink_urb(dev
->tx_urb
);
651 netdev
->stats
.tx_errors
++;
654 static void rtl8150_set_multicast(struct net_device
*netdev
)
656 rtl8150_t
*dev
= netdev_priv(netdev
);
659 netif_stop_queue(netdev
);
660 if (netdev
->flags
& IFF_PROMISC
) {
662 dev_info(&netdev
->dev
, "%s: promiscuous mode\n", netdev
->name
);
663 } else if (!netdev_mc_empty(netdev
) ||
664 (netdev
->flags
& IFF_ALLMULTI
)) {
667 dev_dbg(&netdev
->dev
, "%s: allmulti set\n", netdev
->name
);
669 /* ~RX_MULTICAST, ~RX_PROMISCUOUS */
672 async_set_registers(dev
, RCR
, sizeof(rx_creg
), rx_creg
);
673 netif_wake_queue(netdev
);
676 static netdev_tx_t
rtl8150_start_xmit(struct sk_buff
*skb
,
677 struct net_device
*netdev
)
679 rtl8150_t
*dev
= netdev_priv(netdev
);
682 netif_stop_queue(netdev
);
683 count
= (skb
->len
< 60) ? 60 : skb
->len
;
684 count
= (count
& 0x3f) ? count
: count
+ 1;
686 usb_fill_bulk_urb(dev
->tx_urb
, dev
->udev
, usb_sndbulkpipe(dev
->udev
, 2),
687 skb
->data
, count
, write_bulk_callback
, dev
);
688 if ((res
= usb_submit_urb(dev
->tx_urb
, GFP_ATOMIC
))) {
689 /* Can we get/handle EPIPE here? */
691 netif_device_detach(dev
->netdev
);
693 dev_warn(&netdev
->dev
, "failed tx_urb %d\n", res
);
694 netdev
->stats
.tx_errors
++;
695 netif_start_queue(netdev
);
698 netdev
->stats
.tx_packets
++;
699 netdev
->stats
.tx_bytes
+= skb
->len
;
700 netif_trans_update(netdev
);
707 static void set_carrier(struct net_device
*netdev
)
709 rtl8150_t
*dev
= netdev_priv(netdev
);
712 get_registers(dev
, CSCR
, 2, &tmp
);
713 if (tmp
& CSCR_LINK_STATUS
)
714 netif_carrier_on(netdev
);
716 netif_carrier_off(netdev
);
719 static int rtl8150_open(struct net_device
*netdev
)
721 rtl8150_t
*dev
= netdev_priv(netdev
);
724 if (dev
->rx_skb
== NULL
)
725 dev
->rx_skb
= pull_skb(dev
);
729 set_registers(dev
, IDR
, 6, netdev
->dev_addr
);
731 usb_fill_bulk_urb(dev
->rx_urb
, dev
->udev
, usb_rcvbulkpipe(dev
->udev
, 1),
732 dev
->rx_skb
->data
, RTL8150_MTU
, read_bulk_callback
, dev
);
733 if ((res
= usb_submit_urb(dev
->rx_urb
, GFP_KERNEL
))) {
735 netif_device_detach(dev
->netdev
);
736 dev_warn(&netdev
->dev
, "rx_urb submit failed: %d\n", res
);
739 usb_fill_int_urb(dev
->intr_urb
, dev
->udev
, usb_rcvintpipe(dev
->udev
, 3),
740 dev
->intr_buff
, INTBUFSIZE
, intr_callback
,
741 dev
, dev
->intr_interval
);
742 if ((res
= usb_submit_urb(dev
->intr_urb
, GFP_KERNEL
))) {
744 netif_device_detach(dev
->netdev
);
745 dev_warn(&netdev
->dev
, "intr_urb submit failed: %d\n", res
);
746 usb_kill_urb(dev
->rx_urb
);
749 enable_net_traffic(dev
);
751 netif_start_queue(netdev
);
756 static int rtl8150_close(struct net_device
*netdev
)
758 rtl8150_t
*dev
= netdev_priv(netdev
);
760 netif_stop_queue(netdev
);
761 if (!test_bit(RTL8150_UNPLUG
, &dev
->flags
))
762 disable_net_traffic(dev
);
763 unlink_all_urbs(dev
);
768 static void rtl8150_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*info
)
770 rtl8150_t
*dev
= netdev_priv(netdev
);
772 strscpy(info
->driver
, driver_name
, sizeof(info
->driver
));
773 strscpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
774 usb_make_path(dev
->udev
, info
->bus_info
, sizeof(info
->bus_info
));
777 static int rtl8150_get_link_ksettings(struct net_device
*netdev
,
778 struct ethtool_link_ksettings
*ecmd
)
780 rtl8150_t
*dev
= netdev_priv(netdev
);
785 supported
= (SUPPORTED_10baseT_Half
|
786 SUPPORTED_10baseT_Full
|
787 SUPPORTED_100baseT_Half
|
788 SUPPORTED_100baseT_Full
|
790 SUPPORTED_TP
| SUPPORTED_MII
);
791 ecmd
->base
.port
= PORT_TP
;
792 ecmd
->base
.phy_address
= dev
->phy
;
793 get_registers(dev
, BMCR
, 2, &bmcr
);
794 get_registers(dev
, ANLP
, 2, &lpa
);
795 if (bmcr
& BMCR_ANENABLE
) {
796 u32 speed
= ((lpa
& (LPA_100HALF
| LPA_100FULL
)) ?
797 SPEED_100
: SPEED_10
);
798 ecmd
->base
.speed
= speed
;
799 ecmd
->base
.autoneg
= AUTONEG_ENABLE
;
800 if (speed
== SPEED_100
)
801 ecmd
->base
.duplex
= (lpa
& LPA_100FULL
) ?
802 DUPLEX_FULL
: DUPLEX_HALF
;
804 ecmd
->base
.duplex
= (lpa
& LPA_10FULL
) ?
805 DUPLEX_FULL
: DUPLEX_HALF
;
807 ecmd
->base
.autoneg
= AUTONEG_DISABLE
;
808 ecmd
->base
.speed
= ((bmcr
& BMCR_SPEED100
) ?
809 SPEED_100
: SPEED_10
);
810 ecmd
->base
.duplex
= (bmcr
& BMCR_FULLDPLX
) ?
811 DUPLEX_FULL
: DUPLEX_HALF
;
814 ethtool_convert_legacy_u32_to_link_mode(ecmd
->link_modes
.supported
,
820 static const struct ethtool_ops ops
= {
821 .get_drvinfo
= rtl8150_get_drvinfo
,
822 .get_link
= ethtool_op_get_link
,
823 .get_link_ksettings
= rtl8150_get_link_ksettings
,
826 static int rtl8150_siocdevprivate(struct net_device
*netdev
, struct ifreq
*rq
,
827 void __user
*udata
, int cmd
)
829 rtl8150_t
*dev
= netdev_priv(netdev
);
830 u16
*data
= (u16
*) & rq
->ifr_ifru
;
837 case SIOCDEVPRIVATE
+ 1:
838 read_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), &data
[3]);
840 case SIOCDEVPRIVATE
+ 2:
841 if (!capable(CAP_NET_ADMIN
))
843 write_mii_word(dev
, dev
->phy
, (data
[1] & 0x1f), data
[2]);
852 static const struct net_device_ops rtl8150_netdev_ops
= {
853 .ndo_open
= rtl8150_open
,
854 .ndo_stop
= rtl8150_close
,
855 .ndo_siocdevprivate
= rtl8150_siocdevprivate
,
856 .ndo_start_xmit
= rtl8150_start_xmit
,
857 .ndo_tx_timeout
= rtl8150_tx_timeout
,
858 .ndo_set_rx_mode
= rtl8150_set_multicast
,
859 .ndo_set_mac_address
= rtl8150_set_mac_address
,
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_setup(&dev
->tl
, rx_fixup
);
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 netdev
->ethtool_ops
= &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
);
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
,
951 .disable_hub_initiated_lpm
= 1,
954 module_usb_driver(rtl8150_driver
);
956 MODULE_AUTHOR(DRIVER_AUTHOR
);
957 MODULE_DESCRIPTION(DRIVER_DESC
);
958 MODULE_LICENSE("GPL");