2 * ASIX AX8817X based USB 2.0 Ethernet Devices
3 * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
4 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
5 * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
6 * Copyright (c) 2002-2003 TiVo Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 // #define DEBUG // error path messages, extra info
24 // #define VERBOSE // more; success messages
26 #include <linux/module.h>
27 #include <linux/kmod.h>
28 #include <linux/init.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/ethtool.h>
32 #include <linux/workqueue.h>
33 #include <linux/mii.h>
34 #include <linux/usb.h>
35 #include <linux/crc32.h>
36 #include <linux/usb/usbnet.h>
37 #include <linux/slab.h>
38 #include <linux/if_vlan.h>
40 #define DRIVER_VERSION "22-Dec-2011"
41 #define DRIVER_NAME "asix"
43 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
45 #define AX_CMD_SET_SW_MII 0x06
46 #define AX_CMD_READ_MII_REG 0x07
47 #define AX_CMD_WRITE_MII_REG 0x08
48 #define AX_CMD_SET_HW_MII 0x0a
49 #define AX_CMD_READ_EEPROM 0x0b
50 #define AX_CMD_WRITE_EEPROM 0x0c
51 #define AX_CMD_WRITE_ENABLE 0x0d
52 #define AX_CMD_WRITE_DISABLE 0x0e
53 #define AX_CMD_READ_RX_CTL 0x0f
54 #define AX_CMD_WRITE_RX_CTL 0x10
55 #define AX_CMD_READ_IPG012 0x11
56 #define AX_CMD_WRITE_IPG0 0x12
57 #define AX_CMD_WRITE_IPG1 0x13
58 #define AX_CMD_READ_NODE_ID 0x13
59 #define AX_CMD_WRITE_NODE_ID 0x14
60 #define AX_CMD_WRITE_IPG2 0x14
61 #define AX_CMD_WRITE_MULTI_FILTER 0x16
62 #define AX88172_CMD_READ_NODE_ID 0x17
63 #define AX_CMD_READ_PHY_ID 0x19
64 #define AX_CMD_READ_MEDIUM_STATUS 0x1a
65 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
66 #define AX_CMD_READ_MONITOR_MODE 0x1c
67 #define AX_CMD_WRITE_MONITOR_MODE 0x1d
68 #define AX_CMD_READ_GPIOS 0x1e
69 #define AX_CMD_WRITE_GPIOS 0x1f
70 #define AX_CMD_SW_RESET 0x20
71 #define AX_CMD_SW_PHY_STATUS 0x21
72 #define AX_CMD_SW_PHY_SELECT 0x22
74 #define AX_MONITOR_MODE 0x01
75 #define AX_MONITOR_LINK 0x02
76 #define AX_MONITOR_MAGIC 0x04
77 #define AX_MONITOR_HSFS 0x10
79 /* AX88172 Medium Status Register values */
80 #define AX88172_MEDIUM_FD 0x02
81 #define AX88172_MEDIUM_TX 0x04
82 #define AX88172_MEDIUM_FC 0x10
83 #define AX88172_MEDIUM_DEFAULT \
84 ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
86 #define AX_MCAST_FILTER_SIZE 8
87 #define AX_MAX_MCAST 64
89 #define AX_SWRESET_CLEAR 0x00
90 #define AX_SWRESET_RR 0x01
91 #define AX_SWRESET_RT 0x02
92 #define AX_SWRESET_PRTE 0x04
93 #define AX_SWRESET_PRL 0x08
94 #define AX_SWRESET_BZ 0x10
95 #define AX_SWRESET_IPRL 0x20
96 #define AX_SWRESET_IPPD 0x40
98 #define AX88772_IPG0_DEFAULT 0x15
99 #define AX88772_IPG1_DEFAULT 0x0c
100 #define AX88772_IPG2_DEFAULT 0x12
102 /* AX88772 & AX88178 Medium Mode Register */
103 #define AX_MEDIUM_PF 0x0080
104 #define AX_MEDIUM_JFE 0x0040
105 #define AX_MEDIUM_TFC 0x0020
106 #define AX_MEDIUM_RFC 0x0010
107 #define AX_MEDIUM_ENCK 0x0008
108 #define AX_MEDIUM_AC 0x0004
109 #define AX_MEDIUM_FD 0x0002
110 #define AX_MEDIUM_GM 0x0001
111 #define AX_MEDIUM_SM 0x1000
112 #define AX_MEDIUM_SBP 0x0800
113 #define AX_MEDIUM_PS 0x0200
114 #define AX_MEDIUM_RE 0x0100
116 #define AX88178_MEDIUM_DEFAULT \
117 (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
118 AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
121 #define AX88772_MEDIUM_DEFAULT \
122 (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
123 AX_MEDIUM_TFC | AX_MEDIUM_PS | \
124 AX_MEDIUM_AC | AX_MEDIUM_RE)
126 /* AX88772 & AX88178 RX_CTL values */
127 #define AX_RX_CTL_SO 0x0080
128 #define AX_RX_CTL_AP 0x0020
129 #define AX_RX_CTL_AM 0x0010
130 #define AX_RX_CTL_AB 0x0008
131 #define AX_RX_CTL_SEP 0x0004
132 #define AX_RX_CTL_AMALL 0x0002
133 #define AX_RX_CTL_PRO 0x0001
134 #define AX_RX_CTL_MFB_2048 0x0000
135 #define AX_RX_CTL_MFB_4096 0x0100
136 #define AX_RX_CTL_MFB_8192 0x0200
137 #define AX_RX_CTL_MFB_16384 0x0300
139 #define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
141 /* GPIO 0 .. 2 toggles */
142 #define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
143 #define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
144 #define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
145 #define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
146 #define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
147 #define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
148 #define AX_GPIO_RESERVED 0x40 /* Reserved */
149 #define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
151 #define AX_EEPROM_MAGIC 0xdeadbeef
152 #define AX88172_EEPROM_LEN 0x40
153 #define AX88772_EEPROM_LEN 0xff
155 #define PHY_MODE_MARVELL 0x0000
156 #define MII_MARVELL_LED_CTRL 0x0018
157 #define MII_MARVELL_STATUS 0x001b
158 #define MII_MARVELL_CTRL 0x0014
160 #define MARVELL_LED_MANUAL 0x0019
162 #define MARVELL_STATUS_HWCFG 0x0004
164 #define MARVELL_CTRL_TXDELAY 0x0002
165 #define MARVELL_CTRL_RXDELAY 0x0080
167 #define PHY_MODE_RTL8211CL 0x000C
169 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
171 u8 multi_filter
[AX_MCAST_FILTER_SIZE
];
172 u8 mac_addr
[ETH_ALEN
];
178 struct ax88172_int_data
{
186 struct asix_rx_fixup_info
{
187 struct sk_buff
*ax_skb
;
193 struct asix_common_private
{
194 struct asix_rx_fixup_info rx_fixup_info
;
197 static int asix_read_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
198 u16 size
, void *data
)
203 netdev_dbg(dev
->net
, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
204 cmd
, value
, index
, size
);
206 buf
= kmalloc(size
, GFP_KERNEL
);
210 err
= usb_control_msg(
212 usb_rcvctrlpipe(dev
->udev
, 0),
214 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
219 USB_CTRL_GET_TIMEOUT
);
221 memcpy(data
, buf
, size
);
230 static int asix_write_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
231 u16 size
, void *data
)
236 netdev_dbg(dev
->net
, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
237 cmd
, value
, index
, size
);
240 buf
= kmemdup(data
, size
, GFP_KERNEL
);
245 err
= usb_control_msg(
247 usb_sndctrlpipe(dev
->udev
, 0),
249 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
254 USB_CTRL_SET_TIMEOUT
);
261 static void asix_async_cmd_callback(struct urb
*urb
)
263 struct usb_ctrlrequest
*req
= (struct usb_ctrlrequest
*)urb
->context
;
264 int status
= urb
->status
;
267 printk(KERN_DEBUG
"asix_async_cmd_callback() failed with %d",
275 asix_write_cmd_async(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
276 u16 size
, void *data
)
278 struct usb_ctrlrequest
*req
;
282 netdev_dbg(dev
->net
, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
283 cmd
, value
, index
, size
);
285 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
287 netdev_err(dev
->net
, "Error allocating URB in write_cmd_async!\n");
291 req
= kmalloc(sizeof(struct usb_ctrlrequest
), GFP_ATOMIC
);
293 netdev_err(dev
->net
, "Failed to allocate memory for control request\n");
298 req
->bRequestType
= USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
;
300 req
->wValue
= cpu_to_le16(value
);
301 req
->wIndex
= cpu_to_le16(index
);
302 req
->wLength
= cpu_to_le16(size
);
304 usb_fill_control_urb(urb
, dev
->udev
,
305 usb_sndctrlpipe(dev
->udev
, 0),
306 (void *)req
, data
, size
,
307 asix_async_cmd_callback
, req
);
309 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
311 netdev_err(dev
->net
, "Error submitting the control message: status=%d\n",
318 static int asix_rx_fixup_internal(struct usbnet
*dev
, struct sk_buff
*skb
,
319 struct asix_rx_fixup_info
*rx
)
323 while (offset
+ sizeof(u16
) <= skb
->len
) {
328 if ((skb
->len
- offset
== sizeof(u16
)) ||
330 if (!rx
->split_head
) {
331 rx
->header
= get_unaligned_le16(
333 rx
->split_head
= true;
334 offset
+= sizeof(u16
);
337 rx
->header
|= (get_unaligned_le16(
340 rx
->split_head
= false;
341 offset
+= sizeof(u16
);
344 rx
->header
= get_unaligned_le32(skb
->data
+
346 offset
+= sizeof(u32
);
349 /* get the packet length */
350 rx
->size
= (u16
) (rx
->header
& 0x7ff);
351 if (rx
->size
!= ((~rx
->header
>> 16) & 0x7ff)) {
352 netdev_err(dev
->net
, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n",
357 rx
->ax_skb
= netdev_alloc_skb_ip_align(dev
->net
,
363 if (rx
->size
> dev
->net
->mtu
+ ETH_HLEN
+ VLAN_HLEN
) {
364 netdev_err(dev
->net
, "asix_rx_fixup() Bad RX Length %d\n",
366 kfree_skb(rx
->ax_skb
);
370 if (rx
->size
> skb
->len
- offset
) {
371 remaining
= rx
->size
- (skb
->len
- offset
);
372 rx
->size
= skb
->len
- offset
;
375 data
= skb_put(rx
->ax_skb
, rx
->size
);
376 memcpy(data
, skb
->data
+ offset
, rx
->size
);
378 usbnet_skb_return(dev
, rx
->ax_skb
);
380 offset
+= (rx
->size
+ 1) & 0xfffe;
381 rx
->size
= remaining
;
384 if (skb
->len
!= offset
) {
385 netdev_err(dev
->net
, "asix_rx_fixup() Bad SKB Length %d, %d\n",
393 static int asix_rx_fixup_common(struct usbnet
*dev
, struct sk_buff
*skb
)
395 struct asix_common_private
*dp
= dev
->driver_priv
;
396 struct asix_rx_fixup_info
*rx
= &dp
->rx_fixup_info
;
398 return asix_rx_fixup_internal(dev
, skb
, rx
);
401 static struct sk_buff
*asix_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
,
405 int headroom
= skb_headroom(skb
);
406 int tailroom
= skb_tailroom(skb
);
408 u32 padbytes
= 0xffff0000;
410 padlen
= ((skb
->len
+ 4) & (dev
->maxpacket
- 1)) ? 0 : 4;
412 if ((!skb_cloned(skb
)) &&
413 ((headroom
+ tailroom
) >= (4 + padlen
))) {
414 if ((headroom
< 4) || (tailroom
< padlen
)) {
415 skb
->data
= memmove(skb
->head
+ 4, skb
->data
, skb
->len
);
416 skb_set_tail_pointer(skb
, skb
->len
);
419 struct sk_buff
*skb2
;
420 skb2
= skb_copy_expand(skb
, 4, padlen
, flags
);
421 dev_kfree_skb_any(skb
);
428 packet_len
= (((skb
->len
- 4) ^ 0x0000ffff) << 16) + (skb
->len
- 4);
429 cpu_to_le32s(&packet_len
);
430 skb_copy_to_linear_data(skb
, &packet_len
, sizeof(packet_len
));
433 cpu_to_le32s(&padbytes
);
434 memcpy(skb_tail_pointer(skb
), &padbytes
, sizeof(padbytes
));
435 skb_put(skb
, sizeof(padbytes
));
440 static void asix_status(struct usbnet
*dev
, struct urb
*urb
)
442 struct ax88172_int_data
*event
;
445 if (urb
->actual_length
< 8)
448 event
= urb
->transfer_buffer
;
449 link
= event
->link
& 0x01;
450 if (netif_carrier_ok(dev
->net
) != link
) {
452 netif_carrier_on(dev
->net
);
453 usbnet_defer_kevent (dev
, EVENT_LINK_RESET
);
455 netif_carrier_off(dev
->net
);
456 netdev_dbg(dev
->net
, "Link Status is: %d\n", link
);
460 static inline int asix_set_sw_mii(struct usbnet
*dev
)
463 ret
= asix_write_cmd(dev
, AX_CMD_SET_SW_MII
, 0x0000, 0, 0, NULL
);
465 netdev_err(dev
->net
, "Failed to enable software MII access\n");
469 static inline int asix_set_hw_mii(struct usbnet
*dev
)
472 ret
= asix_write_cmd(dev
, AX_CMD_SET_HW_MII
, 0x0000, 0, 0, NULL
);
474 netdev_err(dev
->net
, "Failed to enable hardware MII access\n");
478 static inline int asix_get_phy_addr(struct usbnet
*dev
)
481 int ret
= asix_read_cmd(dev
, AX_CMD_READ_PHY_ID
, 0, 0, 2, buf
);
483 netdev_dbg(dev
->net
, "asix_get_phy_addr()\n");
486 netdev_err(dev
->net
, "Error reading PHYID register: %02x\n", ret
);
489 netdev_dbg(dev
->net
, "asix_get_phy_addr() returning 0x%04x\n",
497 static int asix_sw_reset(struct usbnet
*dev
, u8 flags
)
501 ret
= asix_write_cmd(dev
, AX_CMD_SW_RESET
, flags
, 0, 0, NULL
);
503 netdev_err(dev
->net
, "Failed to send software reset: %02x\n", ret
);
508 static u16
asix_read_rx_ctl(struct usbnet
*dev
)
511 int ret
= asix_read_cmd(dev
, AX_CMD_READ_RX_CTL
, 0, 0, 2, &v
);
514 netdev_err(dev
->net
, "Error reading RX_CTL register: %02x\n", ret
);
517 ret
= le16_to_cpu(v
);
522 static int asix_write_rx_ctl(struct usbnet
*dev
, u16 mode
)
526 netdev_dbg(dev
->net
, "asix_write_rx_ctl() - mode = 0x%04x\n", mode
);
527 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_RX_CTL
, mode
, 0, 0, NULL
);
529 netdev_err(dev
->net
, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
535 static u16
asix_read_medium_status(struct usbnet
*dev
)
538 int ret
= asix_read_cmd(dev
, AX_CMD_READ_MEDIUM_STATUS
, 0, 0, 2, &v
);
541 netdev_err(dev
->net
, "Error reading Medium Status register: %02x\n",
543 return ret
; /* TODO: callers not checking for error ret */
546 return le16_to_cpu(v
);
550 static int asix_write_medium_mode(struct usbnet
*dev
, u16 mode
)
554 netdev_dbg(dev
->net
, "asix_write_medium_mode() - mode = 0x%04x\n", mode
);
555 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_MEDIUM_MODE
, mode
, 0, 0, NULL
);
557 netdev_err(dev
->net
, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
563 static int asix_write_gpio(struct usbnet
*dev
, u16 value
, int sleep
)
567 netdev_dbg(dev
->net
, "asix_write_gpio() - value = 0x%04x\n", value
);
568 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_GPIOS
, value
, 0, 0, NULL
);
570 netdev_err(dev
->net
, "Failed to write GPIO value 0x%04x: %02x\n",
580 * AX88772 & AX88178 have a 16-bit RX_CTL value
582 static void asix_set_multicast(struct net_device
*net
)
584 struct usbnet
*dev
= netdev_priv(net
);
585 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
586 u16 rx_ctl
= AX_DEFAULT_RX_CTL
;
588 if (net
->flags
& IFF_PROMISC
) {
589 rx_ctl
|= AX_RX_CTL_PRO
;
590 } else if (net
->flags
& IFF_ALLMULTI
||
591 netdev_mc_count(net
) > AX_MAX_MCAST
) {
592 rx_ctl
|= AX_RX_CTL_AMALL
;
593 } else if (netdev_mc_empty(net
)) {
594 /* just broadcast and directed */
596 /* We use the 20 byte dev->data
597 * for our 8 byte filter buffer
598 * to avoid allocating memory that
599 * is tricky to free later */
600 struct netdev_hw_addr
*ha
;
603 memset(data
->multi_filter
, 0, AX_MCAST_FILTER_SIZE
);
605 /* Build the multicast hash filter. */
606 netdev_for_each_mc_addr(ha
, net
) {
607 crc_bits
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
608 data
->multi_filter
[crc_bits
>> 3] |=
612 asix_write_cmd_async(dev
, AX_CMD_WRITE_MULTI_FILTER
, 0, 0,
613 AX_MCAST_FILTER_SIZE
, data
->multi_filter
);
615 rx_ctl
|= AX_RX_CTL_AM
;
618 asix_write_cmd_async(dev
, AX_CMD_WRITE_RX_CTL
, rx_ctl
, 0, 0, NULL
);
621 static int asix_mdio_read(struct net_device
*netdev
, int phy_id
, int loc
)
623 struct usbnet
*dev
= netdev_priv(netdev
);
626 mutex_lock(&dev
->phy_mutex
);
627 asix_set_sw_mii(dev
);
628 asix_read_cmd(dev
, AX_CMD_READ_MII_REG
, phy_id
,
629 (__u16
)loc
, 2, &res
);
630 asix_set_hw_mii(dev
);
631 mutex_unlock(&dev
->phy_mutex
);
633 netdev_dbg(dev
->net
, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
634 phy_id
, loc
, le16_to_cpu(res
));
636 return le16_to_cpu(res
);
640 asix_mdio_write(struct net_device
*netdev
, int phy_id
, int loc
, int val
)
642 struct usbnet
*dev
= netdev_priv(netdev
);
643 __le16 res
= cpu_to_le16(val
);
645 netdev_dbg(dev
->net
, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
647 mutex_lock(&dev
->phy_mutex
);
648 asix_set_sw_mii(dev
);
649 asix_write_cmd(dev
, AX_CMD_WRITE_MII_REG
, phy_id
, (__u16
)loc
, 2, &res
);
650 asix_set_hw_mii(dev
);
651 mutex_unlock(&dev
->phy_mutex
);
654 /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
655 static u32
asix_get_phyid(struct usbnet
*dev
)
661 /* Poll for the rare case the FW or phy isn't ready yet. */
662 for (i
= 0; i
< 100; i
++) {
663 phy_reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID1
);
664 if (phy_reg
!= 0 && phy_reg
!= 0xFFFF)
669 if (phy_reg
<= 0 || phy_reg
== 0xFFFF)
672 phy_id
= (phy_reg
& 0xffff) << 16;
674 phy_reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID2
);
678 phy_id
|= (phy_reg
& 0xffff);
684 asix_get_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
686 struct usbnet
*dev
= netdev_priv(net
);
689 if (asix_read_cmd(dev
, AX_CMD_READ_MONITOR_MODE
, 0, 0, 1, &opt
) < 0) {
690 wolinfo
->supported
= 0;
691 wolinfo
->wolopts
= 0;
694 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
;
695 wolinfo
->wolopts
= 0;
696 if (opt
& AX_MONITOR_LINK
)
697 wolinfo
->wolopts
|= WAKE_PHY
;
698 if (opt
& AX_MONITOR_MAGIC
)
699 wolinfo
->wolopts
|= WAKE_MAGIC
;
703 asix_set_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
705 struct usbnet
*dev
= netdev_priv(net
);
708 if (wolinfo
->wolopts
& WAKE_PHY
)
709 opt
|= AX_MONITOR_LINK
;
710 if (wolinfo
->wolopts
& WAKE_MAGIC
)
711 opt
|= AX_MONITOR_MAGIC
;
713 if (asix_write_cmd(dev
, AX_CMD_WRITE_MONITOR_MODE
,
714 opt
, 0, 0, NULL
) < 0)
720 static int asix_get_eeprom_len(struct net_device
*net
)
722 struct usbnet
*dev
= netdev_priv(net
);
723 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
725 return data
->eeprom_len
;
728 static int asix_get_eeprom(struct net_device
*net
,
729 struct ethtool_eeprom
*eeprom
, u8
*data
)
731 struct usbnet
*dev
= netdev_priv(net
);
732 __le16
*ebuf
= (__le16
*)data
;
735 /* Crude hack to ensure that we don't overwrite memory
736 * if an odd length is supplied
741 eeprom
->magic
= AX_EEPROM_MAGIC
;
743 /* ax8817x returns 2 bytes from eeprom on read */
744 for (i
=0; i
< eeprom
->len
/ 2; i
++) {
745 if (asix_read_cmd(dev
, AX_CMD_READ_EEPROM
,
746 eeprom
->offset
+ i
, 0, 2, &ebuf
[i
]) < 0)
752 static void asix_get_drvinfo (struct net_device
*net
,
753 struct ethtool_drvinfo
*info
)
755 struct usbnet
*dev
= netdev_priv(net
);
756 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
758 /* Inherit standard device info */
759 usbnet_get_drvinfo(net
, info
);
760 strncpy (info
->driver
, DRIVER_NAME
, sizeof info
->driver
);
761 strncpy (info
->version
, DRIVER_VERSION
, sizeof info
->version
);
762 info
->eedump_len
= data
->eeprom_len
;
765 static u32
asix_get_link(struct net_device
*net
)
767 struct usbnet
*dev
= netdev_priv(net
);
769 return mii_link_ok(&dev
->mii
);
772 static int asix_ioctl (struct net_device
*net
, struct ifreq
*rq
, int cmd
)
774 struct usbnet
*dev
= netdev_priv(net
);
776 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
779 static int asix_set_mac_address(struct net_device
*net
, void *p
)
781 struct usbnet
*dev
= netdev_priv(net
);
782 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
783 struct sockaddr
*addr
= p
;
785 if (netif_running(net
))
787 if (!is_valid_ether_addr(addr
->sa_data
))
788 return -EADDRNOTAVAIL
;
790 memcpy(net
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
792 /* We use the 20 byte dev->data
793 * for our 6 byte mac buffer
794 * to avoid allocating memory that
795 * is tricky to free later */
796 memcpy(data
->mac_addr
, addr
->sa_data
, ETH_ALEN
);
797 asix_write_cmd_async(dev
, AX_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
803 /* We need to override some ethtool_ops so we require our
804 own structure so we don't interfere with other usbnet
805 devices that may be connected at the same time. */
806 static const struct ethtool_ops ax88172_ethtool_ops
= {
807 .get_drvinfo
= asix_get_drvinfo
,
808 .get_link
= asix_get_link
,
809 .get_msglevel
= usbnet_get_msglevel
,
810 .set_msglevel
= usbnet_set_msglevel
,
811 .get_wol
= asix_get_wol
,
812 .set_wol
= asix_set_wol
,
813 .get_eeprom_len
= asix_get_eeprom_len
,
814 .get_eeprom
= asix_get_eeprom
,
815 .get_settings
= usbnet_get_settings
,
816 .set_settings
= usbnet_set_settings
,
817 .nway_reset
= usbnet_nway_reset
,
820 static void ax88172_set_multicast(struct net_device
*net
)
822 struct usbnet
*dev
= netdev_priv(net
);
823 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
826 if (net
->flags
& IFF_PROMISC
) {
828 } else if (net
->flags
& IFF_ALLMULTI
||
829 netdev_mc_count(net
) > AX_MAX_MCAST
) {
831 } else if (netdev_mc_empty(net
)) {
832 /* just broadcast and directed */
834 /* We use the 20 byte dev->data
835 * for our 8 byte filter buffer
836 * to avoid allocating memory that
837 * is tricky to free later */
838 struct netdev_hw_addr
*ha
;
841 memset(data
->multi_filter
, 0, AX_MCAST_FILTER_SIZE
);
843 /* Build the multicast hash filter. */
844 netdev_for_each_mc_addr(ha
, net
) {
845 crc_bits
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
846 data
->multi_filter
[crc_bits
>> 3] |=
850 asix_write_cmd_async(dev
, AX_CMD_WRITE_MULTI_FILTER
, 0, 0,
851 AX_MCAST_FILTER_SIZE
, data
->multi_filter
);
856 asix_write_cmd_async(dev
, AX_CMD_WRITE_RX_CTL
, rx_ctl
, 0, 0, NULL
);
859 static int ax88172_link_reset(struct usbnet
*dev
)
862 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
864 mii_check_media(&dev
->mii
, 1, 1);
865 mii_ethtool_gset(&dev
->mii
, &ecmd
);
866 mode
= AX88172_MEDIUM_DEFAULT
;
868 if (ecmd
.duplex
!= DUPLEX_FULL
)
869 mode
|= ~AX88172_MEDIUM_FD
;
871 netdev_dbg(dev
->net
, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
872 ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, mode
);
874 asix_write_medium_mode(dev
, mode
);
879 static const struct net_device_ops ax88172_netdev_ops
= {
880 .ndo_open
= usbnet_open
,
881 .ndo_stop
= usbnet_stop
,
882 .ndo_start_xmit
= usbnet_start_xmit
,
883 .ndo_tx_timeout
= usbnet_tx_timeout
,
884 .ndo_change_mtu
= usbnet_change_mtu
,
885 .ndo_set_mac_address
= eth_mac_addr
,
886 .ndo_validate_addr
= eth_validate_addr
,
887 .ndo_do_ioctl
= asix_ioctl
,
888 .ndo_set_rx_mode
= ax88172_set_multicast
,
891 static int ax88172_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
896 unsigned long gpio_bits
= dev
->driver_info
->data
;
897 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
899 data
->eeprom_len
= AX88172_EEPROM_LEN
;
901 usbnet_get_endpoints(dev
,intf
);
903 /* Toggle the GPIOs in a manufacturer/model specific way */
904 for (i
= 2; i
>= 0; i
--) {
905 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_GPIOS
,
906 (gpio_bits
>> (i
* 8)) & 0xff, 0, 0, NULL
);
912 ret
= asix_write_rx_ctl(dev
, 0x80);
916 /* Get the MAC address */
917 ret
= asix_read_cmd(dev
, AX88172_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
, buf
);
919 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret
);
922 memcpy(dev
->net
->dev_addr
, buf
, ETH_ALEN
);
924 /* Initialize MII structure */
925 dev
->mii
.dev
= dev
->net
;
926 dev
->mii
.mdio_read
= asix_mdio_read
;
927 dev
->mii
.mdio_write
= asix_mdio_write
;
928 dev
->mii
.phy_id_mask
= 0x3f;
929 dev
->mii
.reg_num_mask
= 0x1f;
930 dev
->mii
.phy_id
= asix_get_phy_addr(dev
);
932 dev
->net
->netdev_ops
= &ax88172_netdev_ops
;
933 dev
->net
->ethtool_ops
= &ax88172_ethtool_ops
;
935 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
936 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
937 ADVERTISE_ALL
| ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
);
938 mii_nway_restart(&dev
->mii
);
946 static const struct ethtool_ops ax88772_ethtool_ops
= {
947 .get_drvinfo
= asix_get_drvinfo
,
948 .get_link
= asix_get_link
,
949 .get_msglevel
= usbnet_get_msglevel
,
950 .set_msglevel
= usbnet_set_msglevel
,
951 .get_wol
= asix_get_wol
,
952 .set_wol
= asix_set_wol
,
953 .get_eeprom_len
= asix_get_eeprom_len
,
954 .get_eeprom
= asix_get_eeprom
,
955 .get_settings
= usbnet_get_settings
,
956 .set_settings
= usbnet_set_settings
,
957 .nway_reset
= usbnet_nway_reset
,
960 static int ax88772_link_reset(struct usbnet
*dev
)
963 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
965 mii_check_media(&dev
->mii
, 1, 1);
966 mii_ethtool_gset(&dev
->mii
, &ecmd
);
967 mode
= AX88772_MEDIUM_DEFAULT
;
969 if (ethtool_cmd_speed(&ecmd
) != SPEED_100
)
970 mode
&= ~AX_MEDIUM_PS
;
972 if (ecmd
.duplex
!= DUPLEX_FULL
)
973 mode
&= ~AX_MEDIUM_FD
;
975 netdev_dbg(dev
->net
, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
976 ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, mode
);
978 asix_write_medium_mode(dev
, mode
);
983 static int ax88772_reset(struct usbnet
*dev
)
985 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
989 ret
= asix_write_gpio(dev
,
990 AX_GPIO_RSE
| AX_GPIO_GPO_2
| AX_GPIO_GPO2EN
, 5);
994 embd_phy
= ((asix_get_phy_addr(dev
) & 0x1f) == 0x10 ? 1 : 0);
996 ret
= asix_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
998 dbg("Select PHY #1 failed: %d", ret
);
1002 ret
= asix_sw_reset(dev
, AX_SWRESET_IPPD
| AX_SWRESET_PRL
);
1008 ret
= asix_sw_reset(dev
, AX_SWRESET_CLEAR
);
1015 ret
= asix_sw_reset(dev
, AX_SWRESET_IPRL
);
1019 ret
= asix_sw_reset(dev
, AX_SWRESET_PRTE
);
1025 rx_ctl
= asix_read_rx_ctl(dev
);
1026 dbg("RX_CTL is 0x%04x after software reset", rx_ctl
);
1027 ret
= asix_write_rx_ctl(dev
, 0x0000);
1031 rx_ctl
= asix_read_rx_ctl(dev
);
1032 dbg("RX_CTL is 0x%04x setting to 0x0000", rx_ctl
);
1034 ret
= asix_sw_reset(dev
, AX_SWRESET_PRL
);
1040 ret
= asix_sw_reset(dev
, AX_SWRESET_IPRL
| AX_SWRESET_PRL
);
1046 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
1047 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
1048 ADVERTISE_ALL
| ADVERTISE_CSMA
);
1049 mii_nway_restart(&dev
->mii
);
1051 ret
= asix_write_medium_mode(dev
, AX88772_MEDIUM_DEFAULT
);
1055 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_IPG0
,
1056 AX88772_IPG0_DEFAULT
| AX88772_IPG1_DEFAULT
,
1057 AX88772_IPG2_DEFAULT
, 0, NULL
);
1059 dbg("Write IPG,IPG1,IPG2 failed: %d", ret
);
1063 /* Rewrite MAC address */
1064 memcpy(data
->mac_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
1065 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
1070 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
1071 ret
= asix_write_rx_ctl(dev
, AX_DEFAULT_RX_CTL
);
1075 rx_ctl
= asix_read_rx_ctl(dev
);
1076 dbg("RX_CTL is 0x%04x after all initializations", rx_ctl
);
1078 rx_ctl
= asix_read_medium_status(dev
);
1079 dbg("Medium Status is 0x%04x after all initializations", rx_ctl
);
1088 static const struct net_device_ops ax88772_netdev_ops
= {
1089 .ndo_open
= usbnet_open
,
1090 .ndo_stop
= usbnet_stop
,
1091 .ndo_start_xmit
= usbnet_start_xmit
,
1092 .ndo_tx_timeout
= usbnet_tx_timeout
,
1093 .ndo_change_mtu
= usbnet_change_mtu
,
1094 .ndo_set_mac_address
= asix_set_mac_address
,
1095 .ndo_validate_addr
= eth_validate_addr
,
1096 .ndo_do_ioctl
= asix_ioctl
,
1097 .ndo_set_rx_mode
= asix_set_multicast
,
1100 static int ax88772_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
1103 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
1107 data
->eeprom_len
= AX88772_EEPROM_LEN
;
1109 usbnet_get_endpoints(dev
,intf
);
1111 /* Get the MAC address */
1112 ret
= asix_read_cmd(dev
, AX_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
, buf
);
1114 dbg("Failed to read MAC address: %d", ret
);
1117 memcpy(dev
->net
->dev_addr
, buf
, ETH_ALEN
);
1119 /* Initialize MII structure */
1120 dev
->mii
.dev
= dev
->net
;
1121 dev
->mii
.mdio_read
= asix_mdio_read
;
1122 dev
->mii
.mdio_write
= asix_mdio_write
;
1123 dev
->mii
.phy_id_mask
= 0x1f;
1124 dev
->mii
.reg_num_mask
= 0x1f;
1125 dev
->mii
.phy_id
= asix_get_phy_addr(dev
);
1127 dev
->net
->netdev_ops
= &ax88772_netdev_ops
;
1128 dev
->net
->ethtool_ops
= &ax88772_ethtool_ops
;
1130 embd_phy
= ((dev
->mii
.phy_id
& 0x1f) == 0x10 ? 1 : 0);
1132 /* Reset the PHY to normal operation mode */
1133 ret
= asix_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
1135 dbg("Select PHY #1 failed: %d", ret
);
1139 ret
= asix_sw_reset(dev
, AX_SWRESET_IPPD
| AX_SWRESET_PRL
);
1145 ret
= asix_sw_reset(dev
, AX_SWRESET_CLEAR
);
1151 ret
= asix_sw_reset(dev
, embd_phy
? AX_SWRESET_IPRL
: AX_SWRESET_PRTE
);
1153 /* Read PHYID register *AFTER* the PHY was reset properly */
1154 phyid
= asix_get_phyid(dev
);
1155 dbg("PHYID=0x%08x", phyid
);
1157 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1158 if (dev
->driver_info
->flags
& FLAG_FRAMING_AX
) {
1159 /* hard_mtu is still the default - the device does not support
1161 dev
->rx_urb_size
= 2048;
1164 dev
->driver_priv
= kzalloc(sizeof(struct asix_common_private
),
1166 if (!dev
->driver_priv
)
1172 static void ax88772_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
1174 kfree(dev
->driver_priv
);
1177 static const struct ethtool_ops ax88178_ethtool_ops
= {
1178 .get_drvinfo
= asix_get_drvinfo
,
1179 .get_link
= asix_get_link
,
1180 .get_msglevel
= usbnet_get_msglevel
,
1181 .set_msglevel
= usbnet_set_msglevel
,
1182 .get_wol
= asix_get_wol
,
1183 .set_wol
= asix_set_wol
,
1184 .get_eeprom_len
= asix_get_eeprom_len
,
1185 .get_eeprom
= asix_get_eeprom
,
1186 .get_settings
= usbnet_get_settings
,
1187 .set_settings
= usbnet_set_settings
,
1188 .nway_reset
= usbnet_nway_reset
,
1191 static int marvell_phy_init(struct usbnet
*dev
)
1193 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
1196 netdev_dbg(dev
->net
, "marvell_phy_init()\n");
1198 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_MARVELL_STATUS
);
1199 netdev_dbg(dev
->net
, "MII_MARVELL_STATUS = 0x%04x\n", reg
);
1201 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_MARVELL_CTRL
,
1202 MARVELL_CTRL_RXDELAY
| MARVELL_CTRL_TXDELAY
);
1204 if (data
->ledmode
) {
1205 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
,
1206 MII_MARVELL_LED_CTRL
);
1207 netdev_dbg(dev
->net
, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg
);
1210 reg
|= (1 + 0x0100);
1211 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
,
1212 MII_MARVELL_LED_CTRL
, reg
);
1214 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
,
1215 MII_MARVELL_LED_CTRL
);
1216 netdev_dbg(dev
->net
, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg
);
1223 static int rtl8211cl_phy_init(struct usbnet
*dev
)
1225 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
1227 netdev_dbg(dev
->net
, "rtl8211cl_phy_init()\n");
1229 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0x0005);
1230 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x0c, 0);
1231 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x01,
1232 asix_mdio_read (dev
->net
, dev
->mii
.phy_id
, 0x01) | 0x0080);
1233 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0);
1235 if (data
->ledmode
== 12) {
1236 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0x0002);
1237 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1a, 0x00cb);
1238 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0);
1244 static int marvell_led_status(struct usbnet
*dev
, u16 speed
)
1246 u16 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MARVELL_LED_MANUAL
);
1248 netdev_dbg(dev
->net
, "marvell_led_status() read 0x%04x\n", reg
);
1250 /* Clear out the center LED bits - 0x03F0 */
1264 netdev_dbg(dev
->net
, "marvell_led_status() writing 0x%04x\n", reg
);
1265 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MARVELL_LED_MANUAL
, reg
);
1270 static int ax88178_reset(struct usbnet
*dev
)
1272 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
1279 asix_read_cmd(dev
, AX_CMD_READ_GPIOS
, 0, 0, 1, &status
);
1280 dbg("GPIO Status: 0x%04x", status
);
1282 asix_write_cmd(dev
, AX_CMD_WRITE_ENABLE
, 0, 0, 0, NULL
);
1283 asix_read_cmd(dev
, AX_CMD_READ_EEPROM
, 0x0017, 0, 2, &eeprom
);
1284 asix_write_cmd(dev
, AX_CMD_WRITE_DISABLE
, 0, 0, 0, NULL
);
1286 dbg("EEPROM index 0x17 is 0x%04x", eeprom
);
1288 if (eeprom
== cpu_to_le16(0xffff)) {
1289 data
->phymode
= PHY_MODE_MARVELL
;
1293 data
->phymode
= le16_to_cpu(eeprom
) & 0x7F;
1294 data
->ledmode
= le16_to_cpu(eeprom
) >> 8;
1295 gpio0
= (le16_to_cpu(eeprom
) & 0x80) ? 0 : 1;
1297 dbg("GPIO0: %d, PhyMode: %d", gpio0
, data
->phymode
);
1299 /* Power up external GigaPHY through AX88178 GPIO pin */
1300 asix_write_gpio(dev
, AX_GPIO_RSE
| AX_GPIO_GPO_1
| AX_GPIO_GPO1EN
, 40);
1301 if ((le16_to_cpu(eeprom
) >> 8) != 1) {
1302 asix_write_gpio(dev
, 0x003c, 30);
1303 asix_write_gpio(dev
, 0x001c, 300);
1304 asix_write_gpio(dev
, 0x003c, 30);
1306 dbg("gpio phymode == 1 path");
1307 asix_write_gpio(dev
, AX_GPIO_GPO1EN
, 30);
1308 asix_write_gpio(dev
, AX_GPIO_GPO1EN
| AX_GPIO_GPO_1
, 30);
1311 /* Read PHYID register *AFTER* powering up PHY */
1312 phyid
= asix_get_phyid(dev
);
1313 dbg("PHYID=0x%08x", phyid
);
1315 /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
1316 asix_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, 0, 0, 0, NULL
);
1318 asix_sw_reset(dev
, 0);
1321 asix_sw_reset(dev
, AX_SWRESET_PRL
| AX_SWRESET_IPPD
);
1324 asix_write_rx_ctl(dev
, 0);
1326 if (data
->phymode
== PHY_MODE_MARVELL
) {
1327 marvell_phy_init(dev
);
1329 } else if (data
->phymode
== PHY_MODE_RTL8211CL
)
1330 rtl8211cl_phy_init(dev
);
1332 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
,
1333 BMCR_RESET
| BMCR_ANENABLE
);
1334 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
1335 ADVERTISE_ALL
| ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
);
1336 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_CTRL1000
,
1337 ADVERTISE_1000FULL
);
1339 mii_nway_restart(&dev
->mii
);
1341 ret
= asix_write_medium_mode(dev
, AX88178_MEDIUM_DEFAULT
);
1345 /* Rewrite MAC address */
1346 memcpy(data
->mac_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
1347 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
1352 ret
= asix_write_rx_ctl(dev
, AX_DEFAULT_RX_CTL
);
1359 static int ax88178_link_reset(struct usbnet
*dev
)
1362 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
1363 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
1366 netdev_dbg(dev
->net
, "ax88178_link_reset()\n");
1368 mii_check_media(&dev
->mii
, 1, 1);
1369 mii_ethtool_gset(&dev
->mii
, &ecmd
);
1370 mode
= AX88178_MEDIUM_DEFAULT
;
1371 speed
= ethtool_cmd_speed(&ecmd
);
1373 if (speed
== SPEED_1000
)
1374 mode
|= AX_MEDIUM_GM
;
1375 else if (speed
== SPEED_100
)
1376 mode
|= AX_MEDIUM_PS
;
1378 mode
&= ~(AX_MEDIUM_PS
| AX_MEDIUM_GM
);
1380 mode
|= AX_MEDIUM_ENCK
;
1382 if (ecmd
.duplex
== DUPLEX_FULL
)
1383 mode
|= AX_MEDIUM_FD
;
1385 mode
&= ~AX_MEDIUM_FD
;
1387 netdev_dbg(dev
->net
, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
1388 speed
, ecmd
.duplex
, mode
);
1390 asix_write_medium_mode(dev
, mode
);
1392 if (data
->phymode
== PHY_MODE_MARVELL
&& data
->ledmode
)
1393 marvell_led_status(dev
, speed
);
1398 static void ax88178_set_mfb(struct usbnet
*dev
)
1400 u16 mfb
= AX_RX_CTL_MFB_16384
;
1403 int old_rx_urb_size
= dev
->rx_urb_size
;
1405 if (dev
->hard_mtu
< 2048) {
1406 dev
->rx_urb_size
= 2048;
1407 mfb
= AX_RX_CTL_MFB_2048
;
1408 } else if (dev
->hard_mtu
< 4096) {
1409 dev
->rx_urb_size
= 4096;
1410 mfb
= AX_RX_CTL_MFB_4096
;
1411 } else if (dev
->hard_mtu
< 8192) {
1412 dev
->rx_urb_size
= 8192;
1413 mfb
= AX_RX_CTL_MFB_8192
;
1414 } else if (dev
->hard_mtu
< 16384) {
1415 dev
->rx_urb_size
= 16384;
1416 mfb
= AX_RX_CTL_MFB_16384
;
1419 rxctl
= asix_read_rx_ctl(dev
);
1420 asix_write_rx_ctl(dev
, (rxctl
& ~AX_RX_CTL_MFB_16384
) | mfb
);
1422 medium
= asix_read_medium_status(dev
);
1423 if (dev
->net
->mtu
> 1500)
1424 medium
|= AX_MEDIUM_JFE
;
1426 medium
&= ~AX_MEDIUM_JFE
;
1427 asix_write_medium_mode(dev
, medium
);
1429 if (dev
->rx_urb_size
> old_rx_urb_size
)
1430 usbnet_unlink_rx_urbs(dev
);
1433 static int ax88178_change_mtu(struct net_device
*net
, int new_mtu
)
1435 struct usbnet
*dev
= netdev_priv(net
);
1436 int ll_mtu
= new_mtu
+ net
->hard_header_len
+ 4;
1438 netdev_dbg(dev
->net
, "ax88178_change_mtu() new_mtu=%d\n", new_mtu
);
1440 if (new_mtu
<= 0 || ll_mtu
> 16384)
1443 if ((ll_mtu
% dev
->maxpacket
) == 0)
1447 dev
->hard_mtu
= net
->mtu
+ net
->hard_header_len
;
1448 ax88178_set_mfb(dev
);
1453 static const struct net_device_ops ax88178_netdev_ops
= {
1454 .ndo_open
= usbnet_open
,
1455 .ndo_stop
= usbnet_stop
,
1456 .ndo_start_xmit
= usbnet_start_xmit
,
1457 .ndo_tx_timeout
= usbnet_tx_timeout
,
1458 .ndo_set_mac_address
= asix_set_mac_address
,
1459 .ndo_validate_addr
= eth_validate_addr
,
1460 .ndo_set_rx_mode
= asix_set_multicast
,
1461 .ndo_do_ioctl
= asix_ioctl
,
1462 .ndo_change_mtu
= ax88178_change_mtu
,
1465 static int ax88178_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
1469 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
1471 data
->eeprom_len
= AX88772_EEPROM_LEN
;
1473 usbnet_get_endpoints(dev
,intf
);
1475 /* Get the MAC address */
1476 ret
= asix_read_cmd(dev
, AX_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
, buf
);
1478 dbg("Failed to read MAC address: %d", ret
);
1481 memcpy(dev
->net
->dev_addr
, buf
, ETH_ALEN
);
1483 /* Initialize MII structure */
1484 dev
->mii
.dev
= dev
->net
;
1485 dev
->mii
.mdio_read
= asix_mdio_read
;
1486 dev
->mii
.mdio_write
= asix_mdio_write
;
1487 dev
->mii
.phy_id_mask
= 0x1f;
1488 dev
->mii
.reg_num_mask
= 0xff;
1489 dev
->mii
.supports_gmii
= 1;
1490 dev
->mii
.phy_id
= asix_get_phy_addr(dev
);
1492 dev
->net
->netdev_ops
= &ax88178_netdev_ops
;
1493 dev
->net
->ethtool_ops
= &ax88178_ethtool_ops
;
1495 /* Blink LEDS so users know driver saw dongle */
1496 asix_sw_reset(dev
, 0);
1499 asix_sw_reset(dev
, AX_SWRESET_PRL
| AX_SWRESET_IPPD
);
1502 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1503 if (dev
->driver_info
->flags
& FLAG_FRAMING_AX
) {
1504 /* hard_mtu is still the default - the device does not support
1506 dev
->rx_urb_size
= 2048;
1509 dev
->driver_priv
= kzalloc(sizeof(struct asix_common_private
),
1511 if (!dev
->driver_priv
)
1517 static const struct driver_info ax8817x_info
= {
1518 .description
= "ASIX AX8817x USB 2.0 Ethernet",
1519 .bind
= ax88172_bind
,
1520 .status
= asix_status
,
1521 .link_reset
= ax88172_link_reset
,
1522 .reset
= ax88172_link_reset
,
1523 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
1527 static const struct driver_info dlink_dub_e100_info
= {
1528 .description
= "DLink DUB-E100 USB Ethernet",
1529 .bind
= ax88172_bind
,
1530 .status
= asix_status
,
1531 .link_reset
= ax88172_link_reset
,
1532 .reset
= ax88172_link_reset
,
1533 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
1537 static const struct driver_info netgear_fa120_info
= {
1538 .description
= "Netgear FA-120 USB Ethernet",
1539 .bind
= ax88172_bind
,
1540 .status
= asix_status
,
1541 .link_reset
= ax88172_link_reset
,
1542 .reset
= ax88172_link_reset
,
1543 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
1547 static const struct driver_info hawking_uf200_info
= {
1548 .description
= "Hawking UF200 USB Ethernet",
1549 .bind
= ax88172_bind
,
1550 .status
= asix_status
,
1551 .link_reset
= ax88172_link_reset
,
1552 .reset
= ax88172_link_reset
,
1553 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
1557 static const struct driver_info ax88772_info
= {
1558 .description
= "ASIX AX88772 USB 2.0 Ethernet",
1559 .bind
= ax88772_bind
,
1560 .unbind
= ax88772_unbind
,
1561 .status
= asix_status
,
1562 .link_reset
= ax88772_link_reset
,
1563 .reset
= ax88772_reset
,
1564 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
| FLAG_LINK_INTR
|
1566 .rx_fixup
= asix_rx_fixup_common
,
1567 .tx_fixup
= asix_tx_fixup
,
1570 static const struct driver_info ax88178_info
= {
1571 .description
= "ASIX AX88178 USB 2.0 Ethernet",
1572 .bind
= ax88178_bind
,
1573 .unbind
= ax88772_unbind
,
1574 .status
= asix_status
,
1575 .link_reset
= ax88178_link_reset
,
1576 .reset
= ax88178_reset
,
1577 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
| FLAG_LINK_INTR
|
1579 .rx_fixup
= asix_rx_fixup_common
,
1580 .tx_fixup
= asix_tx_fixup
,
1583 static const struct usb_device_id products
[] = {
1586 USB_DEVICE (0x077b, 0x2226),
1587 .driver_info
= (unsigned long) &ax8817x_info
,
1590 USB_DEVICE (0x0846, 0x1040),
1591 .driver_info
= (unsigned long) &netgear_fa120_info
,
1594 USB_DEVICE (0x2001, 0x1a00),
1595 .driver_info
= (unsigned long) &dlink_dub_e100_info
,
1597 // Intellinet, ST Lab USB Ethernet
1598 USB_DEVICE (0x0b95, 0x1720),
1599 .driver_info
= (unsigned long) &ax8817x_info
,
1601 // Hawking UF200, TrendNet TU2-ET100
1602 USB_DEVICE (0x07b8, 0x420a),
1603 .driver_info
= (unsigned long) &hawking_uf200_info
,
1605 // Billionton Systems, USB2AR
1606 USB_DEVICE (0x08dd, 0x90ff),
1607 .driver_info
= (unsigned long) &ax8817x_info
,
1610 USB_DEVICE (0x0557, 0x2009),
1611 .driver_info
= (unsigned long) &ax8817x_info
,
1613 // Buffalo LUA-U2-KTX
1614 USB_DEVICE (0x0411, 0x003d),
1615 .driver_info
= (unsigned long) &ax8817x_info
,
1617 // Buffalo LUA-U2-GT 10/100/1000
1618 USB_DEVICE (0x0411, 0x006e),
1619 .driver_info
= (unsigned long) &ax88178_info
,
1621 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
1622 USB_DEVICE (0x6189, 0x182d),
1623 .driver_info
= (unsigned long) &ax8817x_info
,
1625 // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
1626 USB_DEVICE (0x0df6, 0x0056),
1627 .driver_info
= (unsigned long) &ax88178_info
,
1629 // corega FEther USB2-TX
1630 USB_DEVICE (0x07aa, 0x0017),
1631 .driver_info
= (unsigned long) &ax8817x_info
,
1633 // Surecom EP-1427X-2
1634 USB_DEVICE (0x1189, 0x0893),
1635 .driver_info
= (unsigned long) &ax8817x_info
,
1637 // goodway corp usb gwusb2e
1638 USB_DEVICE (0x1631, 0x6200),
1639 .driver_info
= (unsigned long) &ax8817x_info
,
1641 // JVC MP-PRX1 Port Replicator
1642 USB_DEVICE (0x04f1, 0x3008),
1643 .driver_info
= (unsigned long) &ax8817x_info
,
1645 // ASIX AX88772B 10/100
1646 USB_DEVICE (0x0b95, 0x772b),
1647 .driver_info
= (unsigned long) &ax88772_info
,
1649 // ASIX AX88772 10/100
1650 USB_DEVICE (0x0b95, 0x7720),
1651 .driver_info
= (unsigned long) &ax88772_info
,
1653 // ASIX AX88178 10/100/1000
1654 USB_DEVICE (0x0b95, 0x1780),
1655 .driver_info
= (unsigned long) &ax88178_info
,
1657 // Logitec LAN-GTJ/U2A
1658 USB_DEVICE (0x0789, 0x0160),
1659 .driver_info
= (unsigned long) &ax88178_info
,
1661 // Linksys USB200M Rev 2
1662 USB_DEVICE (0x13b1, 0x0018),
1663 .driver_info
= (unsigned long) &ax88772_info
,
1665 // 0Q0 cable ethernet
1666 USB_DEVICE (0x1557, 0x7720),
1667 .driver_info
= (unsigned long) &ax88772_info
,
1669 // DLink DUB-E100 H/W Ver B1
1670 USB_DEVICE (0x07d1, 0x3c05),
1671 .driver_info
= (unsigned long) &ax88772_info
,
1673 // DLink DUB-E100 H/W Ver B1 Alternate
1674 USB_DEVICE (0x2001, 0x3c05),
1675 .driver_info
= (unsigned long) &ax88772_info
,
1677 // DLink DUB-E100 H/W Ver C1
1678 USB_DEVICE (0x2001, 0x1a02),
1679 .driver_info
= (unsigned long) &ax88772_info
,
1682 USB_DEVICE (0x1737, 0x0039),
1683 .driver_info
= (unsigned long) &ax88178_info
,
1686 USB_DEVICE (0x04bb, 0x0930),
1687 .driver_info
= (unsigned long) &ax88178_info
,
1690 USB_DEVICE(0x050d, 0x5055),
1691 .driver_info
= (unsigned long) &ax88178_info
,
1693 // Apple USB Ethernet Adapter
1694 USB_DEVICE(0x05ac, 0x1402),
1695 .driver_info
= (unsigned long) &ax88772_info
,
1697 // Cables-to-Go USB Ethernet Adapter
1698 USB_DEVICE(0x0b95, 0x772a),
1699 .driver_info
= (unsigned long) &ax88772_info
,
1702 USB_DEVICE(0x14ea, 0xab11),
1703 .driver_info
= (unsigned long) &ax88178_info
,
1706 USB_DEVICE(0x0db0, 0xa877),
1707 .driver_info
= (unsigned long) &ax88772_info
,
1709 // Asus USB Ethernet Adapter
1710 USB_DEVICE (0x0b95, 0x7e2b),
1711 .driver_info
= (unsigned long) &ax88772_info
,
1715 MODULE_DEVICE_TABLE(usb
, products
);
1717 static struct usb_driver asix_driver
= {
1718 .name
= DRIVER_NAME
,
1719 .id_table
= products
,
1720 .probe
= usbnet_probe
,
1721 .suspend
= usbnet_suspend
,
1722 .resume
= usbnet_resume
,
1723 .disconnect
= usbnet_disconnect
,
1724 .supports_autosuspend
= 1,
1727 module_usb_driver(asix_driver
);
1729 MODULE_AUTHOR("David Hollis");
1730 MODULE_VERSION(DRIVER_VERSION
);
1731 MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
1732 MODULE_LICENSE("GPL");