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
25 #define PHY_MODE_MARVELL 0x0000
26 #define MII_MARVELL_LED_CTRL 0x0018
27 #define MII_MARVELL_STATUS 0x001b
28 #define MII_MARVELL_CTRL 0x0014
30 #define MARVELL_LED_MANUAL 0x0019
32 #define MARVELL_STATUS_HWCFG 0x0004
34 #define MARVELL_CTRL_TXDELAY 0x0002
35 #define MARVELL_CTRL_RXDELAY 0x0080
37 #define PHY_MODE_RTL8211CL 0x000C
39 struct ax88172_int_data
{
47 static void asix_status(struct usbnet
*dev
, struct urb
*urb
)
49 struct ax88172_int_data
*event
;
52 if (urb
->actual_length
< 8)
55 event
= urb
->transfer_buffer
;
56 link
= event
->link
& 0x01;
57 if (netif_carrier_ok(dev
->net
) != link
) {
58 usbnet_link_change(dev
, link
, 1);
59 netdev_dbg(dev
->net
, "Link Status is: %d\n", link
);
63 static void asix_set_netdev_dev_addr(struct usbnet
*dev
, u8
*addr
)
65 if (is_valid_ether_addr(addr
)) {
66 memcpy(dev
->net
->dev_addr
, addr
, ETH_ALEN
);
68 netdev_info(dev
->net
, "invalid hw address, using random\n");
69 eth_hw_addr_random(dev
->net
);
73 /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
74 static u32
asix_get_phyid(struct usbnet
*dev
)
80 /* Poll for the rare case the FW or phy isn't ready yet. */
81 for (i
= 0; i
< 100; i
++) {
82 phy_reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID1
);
83 if (phy_reg
!= 0 && phy_reg
!= 0xFFFF)
88 if (phy_reg
<= 0 || phy_reg
== 0xFFFF)
91 phy_id
= (phy_reg
& 0xffff) << 16;
93 phy_reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_PHYSID2
);
97 phy_id
|= (phy_reg
& 0xffff);
102 static u32
asix_get_link(struct net_device
*net
)
104 struct usbnet
*dev
= netdev_priv(net
);
106 return mii_link_ok(&dev
->mii
);
109 static int asix_ioctl (struct net_device
*net
, struct ifreq
*rq
, int cmd
)
111 struct usbnet
*dev
= netdev_priv(net
);
113 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
116 /* We need to override some ethtool_ops so we require our
117 own structure so we don't interfere with other usbnet
118 devices that may be connected at the same time. */
119 static const struct ethtool_ops ax88172_ethtool_ops
= {
120 .get_drvinfo
= asix_get_drvinfo
,
121 .get_link
= asix_get_link
,
122 .get_msglevel
= usbnet_get_msglevel
,
123 .set_msglevel
= usbnet_set_msglevel
,
124 .get_wol
= asix_get_wol
,
125 .set_wol
= asix_set_wol
,
126 .get_eeprom_len
= asix_get_eeprom_len
,
127 .get_eeprom
= asix_get_eeprom
,
128 .set_eeprom
= asix_set_eeprom
,
129 .get_settings
= usbnet_get_settings
,
130 .set_settings
= usbnet_set_settings
,
131 .nway_reset
= usbnet_nway_reset
,
134 static void ax88172_set_multicast(struct net_device
*net
)
136 struct usbnet
*dev
= netdev_priv(net
);
137 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
140 if (net
->flags
& IFF_PROMISC
) {
142 } else if (net
->flags
& IFF_ALLMULTI
||
143 netdev_mc_count(net
) > AX_MAX_MCAST
) {
145 } else if (netdev_mc_empty(net
)) {
146 /* just broadcast and directed */
148 /* We use the 20 byte dev->data
149 * for our 8 byte filter buffer
150 * to avoid allocating memory that
151 * is tricky to free later */
152 struct netdev_hw_addr
*ha
;
155 memset(data
->multi_filter
, 0, AX_MCAST_FILTER_SIZE
);
157 /* Build the multicast hash filter. */
158 netdev_for_each_mc_addr(ha
, net
) {
159 crc_bits
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
160 data
->multi_filter
[crc_bits
>> 3] |=
164 asix_write_cmd_async(dev
, AX_CMD_WRITE_MULTI_FILTER
, 0, 0,
165 AX_MCAST_FILTER_SIZE
, data
->multi_filter
);
170 asix_write_cmd_async(dev
, AX_CMD_WRITE_RX_CTL
, rx_ctl
, 0, 0, NULL
);
173 static int ax88172_link_reset(struct usbnet
*dev
)
176 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
178 mii_check_media(&dev
->mii
, 1, 1);
179 mii_ethtool_gset(&dev
->mii
, &ecmd
);
180 mode
= AX88172_MEDIUM_DEFAULT
;
182 if (ecmd
.duplex
!= DUPLEX_FULL
)
183 mode
|= ~AX88172_MEDIUM_FD
;
185 netdev_dbg(dev
->net
, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
186 ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, mode
);
188 asix_write_medium_mode(dev
, mode
);
193 static const struct net_device_ops ax88172_netdev_ops
= {
194 .ndo_open
= usbnet_open
,
195 .ndo_stop
= usbnet_stop
,
196 .ndo_start_xmit
= usbnet_start_xmit
,
197 .ndo_tx_timeout
= usbnet_tx_timeout
,
198 .ndo_change_mtu
= usbnet_change_mtu
,
199 .ndo_set_mac_address
= eth_mac_addr
,
200 .ndo_validate_addr
= eth_validate_addr
,
201 .ndo_do_ioctl
= asix_ioctl
,
202 .ndo_set_rx_mode
= ax88172_set_multicast
,
205 static int ax88172_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
210 unsigned long gpio_bits
= dev
->driver_info
->data
;
212 usbnet_get_endpoints(dev
,intf
);
214 /* Toggle the GPIOs in a manufacturer/model specific way */
215 for (i
= 2; i
>= 0; i
--) {
216 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_GPIOS
,
217 (gpio_bits
>> (i
* 8)) & 0xff, 0, 0, NULL
);
223 ret
= asix_write_rx_ctl(dev
, 0x80);
227 /* Get the MAC address */
228 ret
= asix_read_cmd(dev
, AX88172_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
, buf
);
230 netdev_dbg(dev
->net
, "read AX_CMD_READ_NODE_ID failed: %d\n",
235 asix_set_netdev_dev_addr(dev
, buf
);
237 /* Initialize MII structure */
238 dev
->mii
.dev
= dev
->net
;
239 dev
->mii
.mdio_read
= asix_mdio_read
;
240 dev
->mii
.mdio_write
= asix_mdio_write
;
241 dev
->mii
.phy_id_mask
= 0x3f;
242 dev
->mii
.reg_num_mask
= 0x1f;
243 dev
->mii
.phy_id
= asix_get_phy_addr(dev
);
245 dev
->net
->netdev_ops
= &ax88172_netdev_ops
;
246 dev
->net
->ethtool_ops
= &ax88172_ethtool_ops
;
247 dev
->net
->needed_headroom
= 4; /* cf asix_tx_fixup() */
248 dev
->net
->needed_tailroom
= 4; /* cf asix_tx_fixup() */
250 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
251 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
252 ADVERTISE_ALL
| ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
);
253 mii_nway_restart(&dev
->mii
);
261 static const struct ethtool_ops ax88772_ethtool_ops
= {
262 .get_drvinfo
= asix_get_drvinfo
,
263 .get_link
= asix_get_link
,
264 .get_msglevel
= usbnet_get_msglevel
,
265 .set_msglevel
= usbnet_set_msglevel
,
266 .get_wol
= asix_get_wol
,
267 .set_wol
= asix_set_wol
,
268 .get_eeprom_len
= asix_get_eeprom_len
,
269 .get_eeprom
= asix_get_eeprom
,
270 .set_eeprom
= asix_set_eeprom
,
271 .get_settings
= usbnet_get_settings
,
272 .set_settings
= usbnet_set_settings
,
273 .nway_reset
= usbnet_nway_reset
,
276 static int ax88772_link_reset(struct usbnet
*dev
)
279 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
281 mii_check_media(&dev
->mii
, 1, 1);
282 mii_ethtool_gset(&dev
->mii
, &ecmd
);
283 mode
= AX88772_MEDIUM_DEFAULT
;
285 if (ethtool_cmd_speed(&ecmd
) != SPEED_100
)
286 mode
&= ~AX_MEDIUM_PS
;
288 if (ecmd
.duplex
!= DUPLEX_FULL
)
289 mode
&= ~AX_MEDIUM_FD
;
291 netdev_dbg(dev
->net
, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
292 ethtool_cmd_speed(&ecmd
), ecmd
.duplex
, mode
);
294 asix_write_medium_mode(dev
, mode
);
299 static int ax88772_reset(struct usbnet
*dev
)
301 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
305 ret
= asix_write_gpio(dev
,
306 AX_GPIO_RSE
| AX_GPIO_GPO_2
| AX_GPIO_GPO2EN
, 5);
310 embd_phy
= ((asix_get_phy_addr(dev
) & 0x1f) == 0x10 ? 1 : 0);
312 ret
= asix_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
314 netdev_dbg(dev
->net
, "Select PHY #1 failed: %d\n", ret
);
318 ret
= asix_sw_reset(dev
, AX_SWRESET_IPPD
| AX_SWRESET_PRL
);
324 ret
= asix_sw_reset(dev
, AX_SWRESET_CLEAR
);
331 ret
= asix_sw_reset(dev
, AX_SWRESET_IPRL
);
335 ret
= asix_sw_reset(dev
, AX_SWRESET_PRTE
);
341 rx_ctl
= asix_read_rx_ctl(dev
);
342 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after software reset\n", rx_ctl
);
343 ret
= asix_write_rx_ctl(dev
, 0x0000);
347 rx_ctl
= asix_read_rx_ctl(dev
);
348 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl
);
350 ret
= asix_sw_reset(dev
, AX_SWRESET_PRL
);
356 ret
= asix_sw_reset(dev
, AX_SWRESET_IPRL
| AX_SWRESET_PRL
);
362 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
, BMCR_RESET
);
363 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
364 ADVERTISE_ALL
| ADVERTISE_CSMA
);
365 mii_nway_restart(&dev
->mii
);
367 ret
= asix_write_medium_mode(dev
, AX88772_MEDIUM_DEFAULT
);
371 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_IPG0
,
372 AX88772_IPG0_DEFAULT
| AX88772_IPG1_DEFAULT
,
373 AX88772_IPG2_DEFAULT
, 0, NULL
);
375 netdev_dbg(dev
->net
, "Write IPG,IPG1,IPG2 failed: %d\n", ret
);
379 /* Rewrite MAC address */
380 memcpy(data
->mac_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
381 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
386 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
387 ret
= asix_write_rx_ctl(dev
, AX_DEFAULT_RX_CTL
);
391 rx_ctl
= asix_read_rx_ctl(dev
);
392 netdev_dbg(dev
->net
, "RX_CTL is 0x%04x after all initializations\n",
395 rx_ctl
= asix_read_medium_status(dev
);
397 "Medium Status is 0x%04x after all initializations\n",
407 static const struct net_device_ops ax88772_netdev_ops
= {
408 .ndo_open
= usbnet_open
,
409 .ndo_stop
= usbnet_stop
,
410 .ndo_start_xmit
= usbnet_start_xmit
,
411 .ndo_tx_timeout
= usbnet_tx_timeout
,
412 .ndo_change_mtu
= usbnet_change_mtu
,
413 .ndo_set_mac_address
= asix_set_mac_address
,
414 .ndo_validate_addr
= eth_validate_addr
,
415 .ndo_do_ioctl
= asix_ioctl
,
416 .ndo_set_rx_mode
= asix_set_multicast
,
419 static int ax88772_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
421 int ret
, embd_phy
, i
;
425 usbnet_get_endpoints(dev
,intf
);
427 /* Get the MAC address */
428 if (dev
->driver_info
->data
& FLAG_EEPROM_MAC
) {
429 for (i
= 0; i
< (ETH_ALEN
>> 1); i
++) {
430 ret
= asix_read_cmd(dev
, AX_CMD_READ_EEPROM
, 0x04 + i
,
436 ret
= asix_read_cmd(dev
, AX_CMD_READ_NODE_ID
,
437 0, 0, ETH_ALEN
, buf
);
441 netdev_dbg(dev
->net
, "Failed to read MAC address: %d\n", ret
);
445 asix_set_netdev_dev_addr(dev
, buf
);
447 /* Initialize MII structure */
448 dev
->mii
.dev
= dev
->net
;
449 dev
->mii
.mdio_read
= asix_mdio_read
;
450 dev
->mii
.mdio_write
= asix_mdio_write
;
451 dev
->mii
.phy_id_mask
= 0x1f;
452 dev
->mii
.reg_num_mask
= 0x1f;
453 dev
->mii
.phy_id
= asix_get_phy_addr(dev
);
455 dev
->net
->netdev_ops
= &ax88772_netdev_ops
;
456 dev
->net
->ethtool_ops
= &ax88772_ethtool_ops
;
457 dev
->net
->needed_headroom
= 4; /* cf asix_tx_fixup() */
458 dev
->net
->needed_tailroom
= 4; /* cf asix_tx_fixup() */
460 embd_phy
= ((dev
->mii
.phy_id
& 0x1f) == 0x10 ? 1 : 0);
462 /* Reset the PHY to normal operation mode */
463 ret
= asix_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, embd_phy
, 0, 0, NULL
);
465 netdev_dbg(dev
->net
, "Select PHY #1 failed: %d\n", ret
);
471 /* Read PHYID register *AFTER* the PHY was reset properly */
472 phyid
= asix_get_phyid(dev
);
473 netdev_dbg(dev
->net
, "PHYID=0x%08x\n", phyid
);
475 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
476 if (dev
->driver_info
->flags
& FLAG_FRAMING_AX
) {
477 /* hard_mtu is still the default - the device does not support
479 dev
->rx_urb_size
= 2048;
482 dev
->driver_priv
= kzalloc(sizeof(struct asix_common_private
), GFP_KERNEL
);
483 if (!dev
->driver_priv
)
489 static void ax88772_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
491 if (dev
->driver_priv
)
492 kfree(dev
->driver_priv
);
495 static const struct ethtool_ops ax88178_ethtool_ops
= {
496 .get_drvinfo
= asix_get_drvinfo
,
497 .get_link
= asix_get_link
,
498 .get_msglevel
= usbnet_get_msglevel
,
499 .set_msglevel
= usbnet_set_msglevel
,
500 .get_wol
= asix_get_wol
,
501 .set_wol
= asix_set_wol
,
502 .get_eeprom_len
= asix_get_eeprom_len
,
503 .get_eeprom
= asix_get_eeprom
,
504 .set_eeprom
= asix_set_eeprom
,
505 .get_settings
= usbnet_get_settings
,
506 .set_settings
= usbnet_set_settings
,
507 .nway_reset
= usbnet_nway_reset
,
510 static int marvell_phy_init(struct usbnet
*dev
)
512 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
515 netdev_dbg(dev
->net
, "marvell_phy_init()\n");
517 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MII_MARVELL_STATUS
);
518 netdev_dbg(dev
->net
, "MII_MARVELL_STATUS = 0x%04x\n", reg
);
520 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_MARVELL_CTRL
,
521 MARVELL_CTRL_RXDELAY
| MARVELL_CTRL_TXDELAY
);
524 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
,
525 MII_MARVELL_LED_CTRL
);
526 netdev_dbg(dev
->net
, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg
);
530 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
,
531 MII_MARVELL_LED_CTRL
, reg
);
533 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
,
534 MII_MARVELL_LED_CTRL
);
535 netdev_dbg(dev
->net
, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg
);
542 static int rtl8211cl_phy_init(struct usbnet
*dev
)
544 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
546 netdev_dbg(dev
->net
, "rtl8211cl_phy_init()\n");
548 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0x0005);
549 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x0c, 0);
550 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x01,
551 asix_mdio_read (dev
->net
, dev
->mii
.phy_id
, 0x01) | 0x0080);
552 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0);
554 if (data
->ledmode
== 12) {
555 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0x0002);
556 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1a, 0x00cb);
557 asix_mdio_write (dev
->net
, dev
->mii
.phy_id
, 0x1f, 0);
563 static int marvell_led_status(struct usbnet
*dev
, u16 speed
)
565 u16 reg
= asix_mdio_read(dev
->net
, dev
->mii
.phy_id
, MARVELL_LED_MANUAL
);
567 netdev_dbg(dev
->net
, "marvell_led_status() read 0x%04x\n", reg
);
569 /* Clear out the center LED bits - 0x03F0 */
583 netdev_dbg(dev
->net
, "marvell_led_status() writing 0x%04x\n", reg
);
584 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MARVELL_LED_MANUAL
, reg
);
589 static int ax88178_reset(struct usbnet
*dev
)
591 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
598 asix_read_cmd(dev
, AX_CMD_READ_GPIOS
, 0, 0, 1, &status
);
599 netdev_dbg(dev
->net
, "GPIO Status: 0x%04x\n", status
);
601 asix_write_cmd(dev
, AX_CMD_WRITE_ENABLE
, 0, 0, 0, NULL
);
602 asix_read_cmd(dev
, AX_CMD_READ_EEPROM
, 0x0017, 0, 2, &eeprom
);
603 asix_write_cmd(dev
, AX_CMD_WRITE_DISABLE
, 0, 0, 0, NULL
);
605 netdev_dbg(dev
->net
, "EEPROM index 0x17 is 0x%04x\n", eeprom
);
607 if (eeprom
== cpu_to_le16(0xffff)) {
608 data
->phymode
= PHY_MODE_MARVELL
;
612 data
->phymode
= le16_to_cpu(eeprom
) & 0x7F;
613 data
->ledmode
= le16_to_cpu(eeprom
) >> 8;
614 gpio0
= (le16_to_cpu(eeprom
) & 0x80) ? 0 : 1;
616 netdev_dbg(dev
->net
, "GPIO0: %d, PhyMode: %d\n", gpio0
, data
->phymode
);
618 /* Power up external GigaPHY through AX88178 GPIO pin */
619 asix_write_gpio(dev
, AX_GPIO_RSE
| AX_GPIO_GPO_1
| AX_GPIO_GPO1EN
, 40);
620 if ((le16_to_cpu(eeprom
) >> 8) != 1) {
621 asix_write_gpio(dev
, 0x003c, 30);
622 asix_write_gpio(dev
, 0x001c, 300);
623 asix_write_gpio(dev
, 0x003c, 30);
625 netdev_dbg(dev
->net
, "gpio phymode == 1 path\n");
626 asix_write_gpio(dev
, AX_GPIO_GPO1EN
, 30);
627 asix_write_gpio(dev
, AX_GPIO_GPO1EN
| AX_GPIO_GPO_1
, 30);
630 /* Read PHYID register *AFTER* powering up PHY */
631 phyid
= asix_get_phyid(dev
);
632 netdev_dbg(dev
->net
, "PHYID=0x%08x\n", phyid
);
634 /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
635 asix_write_cmd(dev
, AX_CMD_SW_PHY_SELECT
, 0, 0, 0, NULL
);
637 asix_sw_reset(dev
, 0);
640 asix_sw_reset(dev
, AX_SWRESET_PRL
| AX_SWRESET_IPPD
);
643 asix_write_rx_ctl(dev
, 0);
645 if (data
->phymode
== PHY_MODE_MARVELL
) {
646 marvell_phy_init(dev
);
648 } else if (data
->phymode
== PHY_MODE_RTL8211CL
)
649 rtl8211cl_phy_init(dev
);
651 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_BMCR
,
652 BMCR_RESET
| BMCR_ANENABLE
);
653 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_ADVERTISE
,
654 ADVERTISE_ALL
| ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
);
655 asix_mdio_write(dev
->net
, dev
->mii
.phy_id
, MII_CTRL1000
,
658 mii_nway_restart(&dev
->mii
);
660 ret
= asix_write_medium_mode(dev
, AX88178_MEDIUM_DEFAULT
);
664 /* Rewrite MAC address */
665 memcpy(data
->mac_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
666 ret
= asix_write_cmd(dev
, AX_CMD_WRITE_NODE_ID
, 0, 0, ETH_ALEN
,
671 ret
= asix_write_rx_ctl(dev
, AX_DEFAULT_RX_CTL
);
678 static int ax88178_link_reset(struct usbnet
*dev
)
681 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
682 struct asix_data
*data
= (struct asix_data
*)&dev
->data
;
685 netdev_dbg(dev
->net
, "ax88178_link_reset()\n");
687 mii_check_media(&dev
->mii
, 1, 1);
688 mii_ethtool_gset(&dev
->mii
, &ecmd
);
689 mode
= AX88178_MEDIUM_DEFAULT
;
690 speed
= ethtool_cmd_speed(&ecmd
);
692 if (speed
== SPEED_1000
)
693 mode
|= AX_MEDIUM_GM
;
694 else if (speed
== SPEED_100
)
695 mode
|= AX_MEDIUM_PS
;
697 mode
&= ~(AX_MEDIUM_PS
| AX_MEDIUM_GM
);
699 mode
|= AX_MEDIUM_ENCK
;
701 if (ecmd
.duplex
== DUPLEX_FULL
)
702 mode
|= AX_MEDIUM_FD
;
704 mode
&= ~AX_MEDIUM_FD
;
706 netdev_dbg(dev
->net
, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
707 speed
, ecmd
.duplex
, mode
);
709 asix_write_medium_mode(dev
, mode
);
711 if (data
->phymode
== PHY_MODE_MARVELL
&& data
->ledmode
)
712 marvell_led_status(dev
, speed
);
717 static void ax88178_set_mfb(struct usbnet
*dev
)
719 u16 mfb
= AX_RX_CTL_MFB_16384
;
722 int old_rx_urb_size
= dev
->rx_urb_size
;
724 if (dev
->hard_mtu
< 2048) {
725 dev
->rx_urb_size
= 2048;
726 mfb
= AX_RX_CTL_MFB_2048
;
727 } else if (dev
->hard_mtu
< 4096) {
728 dev
->rx_urb_size
= 4096;
729 mfb
= AX_RX_CTL_MFB_4096
;
730 } else if (dev
->hard_mtu
< 8192) {
731 dev
->rx_urb_size
= 8192;
732 mfb
= AX_RX_CTL_MFB_8192
;
733 } else if (dev
->hard_mtu
< 16384) {
734 dev
->rx_urb_size
= 16384;
735 mfb
= AX_RX_CTL_MFB_16384
;
738 rxctl
= asix_read_rx_ctl(dev
);
739 asix_write_rx_ctl(dev
, (rxctl
& ~AX_RX_CTL_MFB_16384
) | mfb
);
741 medium
= asix_read_medium_status(dev
);
742 if (dev
->net
->mtu
> 1500)
743 medium
|= AX_MEDIUM_JFE
;
745 medium
&= ~AX_MEDIUM_JFE
;
746 asix_write_medium_mode(dev
, medium
);
748 if (dev
->rx_urb_size
> old_rx_urb_size
)
749 usbnet_unlink_rx_urbs(dev
);
752 static int ax88178_change_mtu(struct net_device
*net
, int new_mtu
)
754 struct usbnet
*dev
= netdev_priv(net
);
755 int ll_mtu
= new_mtu
+ net
->hard_header_len
+ 4;
757 netdev_dbg(dev
->net
, "ax88178_change_mtu() new_mtu=%d\n", new_mtu
);
759 if (new_mtu
<= 0 || ll_mtu
> 16384)
762 if ((ll_mtu
% dev
->maxpacket
) == 0)
766 dev
->hard_mtu
= net
->mtu
+ net
->hard_header_len
;
767 ax88178_set_mfb(dev
);
769 /* max qlen depend on hard_mtu and rx_urb_size */
770 usbnet_update_max_qlen(dev
);
775 static const struct net_device_ops ax88178_netdev_ops
= {
776 .ndo_open
= usbnet_open
,
777 .ndo_stop
= usbnet_stop
,
778 .ndo_start_xmit
= usbnet_start_xmit
,
779 .ndo_tx_timeout
= usbnet_tx_timeout
,
780 .ndo_set_mac_address
= asix_set_mac_address
,
781 .ndo_validate_addr
= eth_validate_addr
,
782 .ndo_set_rx_mode
= asix_set_multicast
,
783 .ndo_do_ioctl
= asix_ioctl
,
784 .ndo_change_mtu
= ax88178_change_mtu
,
787 static int ax88178_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
792 usbnet_get_endpoints(dev
,intf
);
794 /* Get the MAC address */
795 ret
= asix_read_cmd(dev
, AX_CMD_READ_NODE_ID
, 0, 0, ETH_ALEN
, buf
);
797 netdev_dbg(dev
->net
, "Failed to read MAC address: %d\n", ret
);
801 asix_set_netdev_dev_addr(dev
, buf
);
803 /* Initialize MII structure */
804 dev
->mii
.dev
= dev
->net
;
805 dev
->mii
.mdio_read
= asix_mdio_read
;
806 dev
->mii
.mdio_write
= asix_mdio_write
;
807 dev
->mii
.phy_id_mask
= 0x1f;
808 dev
->mii
.reg_num_mask
= 0xff;
809 dev
->mii
.supports_gmii
= 1;
810 dev
->mii
.phy_id
= asix_get_phy_addr(dev
);
812 dev
->net
->netdev_ops
= &ax88178_netdev_ops
;
813 dev
->net
->ethtool_ops
= &ax88178_ethtool_ops
;
815 /* Blink LEDS so users know driver saw dongle */
816 asix_sw_reset(dev
, 0);
819 asix_sw_reset(dev
, AX_SWRESET_PRL
| AX_SWRESET_IPPD
);
822 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
823 if (dev
->driver_info
->flags
& FLAG_FRAMING_AX
) {
824 /* hard_mtu is still the default - the device does not support
826 dev
->rx_urb_size
= 2048;
829 dev
->driver_priv
= kzalloc(sizeof(struct asix_common_private
), GFP_KERNEL
);
830 if (!dev
->driver_priv
)
836 static const struct driver_info ax8817x_info
= {
837 .description
= "ASIX AX8817x USB 2.0 Ethernet",
838 .bind
= ax88172_bind
,
839 .status
= asix_status
,
840 .link_reset
= ax88172_link_reset
,
841 .reset
= ax88172_link_reset
,
842 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
846 static const struct driver_info dlink_dub_e100_info
= {
847 .description
= "DLink DUB-E100 USB Ethernet",
848 .bind
= ax88172_bind
,
849 .status
= asix_status
,
850 .link_reset
= ax88172_link_reset
,
851 .reset
= ax88172_link_reset
,
852 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
856 static const struct driver_info netgear_fa120_info
= {
857 .description
= "Netgear FA-120 USB Ethernet",
858 .bind
= ax88172_bind
,
859 .status
= asix_status
,
860 .link_reset
= ax88172_link_reset
,
861 .reset
= ax88172_link_reset
,
862 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
866 static const struct driver_info hawking_uf200_info
= {
867 .description
= "Hawking UF200 USB Ethernet",
868 .bind
= ax88172_bind
,
869 .status
= asix_status
,
870 .link_reset
= ax88172_link_reset
,
871 .reset
= ax88172_link_reset
,
872 .flags
= FLAG_ETHER
| FLAG_LINK_INTR
,
876 static const struct driver_info ax88772_info
= {
877 .description
= "ASIX AX88772 USB 2.0 Ethernet",
878 .bind
= ax88772_bind
,
879 .unbind
= ax88772_unbind
,
880 .status
= asix_status
,
881 .link_reset
= ax88772_link_reset
,
882 .reset
= ax88772_link_reset
,
883 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
| FLAG_LINK_INTR
| FLAG_MULTI_PACKET
,
884 .rx_fixup
= asix_rx_fixup_common
,
885 .tx_fixup
= asix_tx_fixup
,
888 static const struct driver_info ax88772b_info
= {
889 .description
= "ASIX AX88772B USB 2.0 Ethernet",
890 .bind
= ax88772_bind
,
891 .unbind
= ax88772_unbind
,
892 .status
= asix_status
,
893 .link_reset
= ax88772_link_reset
,
894 .reset
= ax88772_reset
,
895 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
| FLAG_LINK_INTR
|
897 .rx_fixup
= asix_rx_fixup_common
,
898 .tx_fixup
= asix_tx_fixup
,
899 .data
= FLAG_EEPROM_MAC
,
902 static const struct driver_info ax88178_info
= {
903 .description
= "ASIX AX88178 USB 2.0 Ethernet",
904 .bind
= ax88178_bind
,
905 .unbind
= ax88772_unbind
,
906 .status
= asix_status
,
907 .link_reset
= ax88178_link_reset
,
908 .reset
= ax88178_reset
,
909 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
| FLAG_LINK_INTR
|
911 .rx_fixup
= asix_rx_fixup_common
,
912 .tx_fixup
= asix_tx_fixup
,
916 * USBLINK 20F9 "USB 2.0 LAN" USB ethernet adapter, typically found in
918 * USB device strings are:
919 * 1: Manufacturer: USBLINK
920 * 2: Product: HG20F9 USB2.0
922 * Appears to be compatible with Asix 88772B.
924 static const struct driver_info hg20f9_info
= {
925 .description
= "HG20F9 USB 2.0 Ethernet",
926 .bind
= ax88772_bind
,
927 .unbind
= ax88772_unbind
,
928 .status
= asix_status
,
929 .link_reset
= ax88772_link_reset
,
930 .reset
= ax88772_reset
,
931 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
| FLAG_LINK_INTR
|
933 .rx_fixup
= asix_rx_fixup_common
,
934 .tx_fixup
= asix_tx_fixup
,
935 .data
= FLAG_EEPROM_MAC
,
938 static const struct usb_device_id products
[] = {
941 USB_DEVICE (0x077b, 0x2226),
942 .driver_info
= (unsigned long) &ax8817x_info
,
945 USB_DEVICE (0x0846, 0x1040),
946 .driver_info
= (unsigned long) &netgear_fa120_info
,
949 USB_DEVICE (0x2001, 0x1a00),
950 .driver_info
= (unsigned long) &dlink_dub_e100_info
,
952 // Intellinet, ST Lab USB Ethernet
953 USB_DEVICE (0x0b95, 0x1720),
954 .driver_info
= (unsigned long) &ax8817x_info
,
956 // Hawking UF200, TrendNet TU2-ET100
957 USB_DEVICE (0x07b8, 0x420a),
958 .driver_info
= (unsigned long) &hawking_uf200_info
,
960 // Billionton Systems, USB2AR
961 USB_DEVICE (0x08dd, 0x90ff),
962 .driver_info
= (unsigned long) &ax8817x_info
,
965 USB_DEVICE (0x0557, 0x2009),
966 .driver_info
= (unsigned long) &ax8817x_info
,
968 // Buffalo LUA-U2-KTX
969 USB_DEVICE (0x0411, 0x003d),
970 .driver_info
= (unsigned long) &ax8817x_info
,
972 // Buffalo LUA-U2-GT 10/100/1000
973 USB_DEVICE (0x0411, 0x006e),
974 .driver_info
= (unsigned long) &ax88178_info
,
976 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
977 USB_DEVICE (0x6189, 0x182d),
978 .driver_info
= (unsigned long) &ax8817x_info
,
980 // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
981 USB_DEVICE (0x0df6, 0x0056),
982 .driver_info
= (unsigned long) &ax88178_info
,
984 // corega FEther USB2-TX
985 USB_DEVICE (0x07aa, 0x0017),
986 .driver_info
= (unsigned long) &ax8817x_info
,
988 // Surecom EP-1427X-2
989 USB_DEVICE (0x1189, 0x0893),
990 .driver_info
= (unsigned long) &ax8817x_info
,
992 // goodway corp usb gwusb2e
993 USB_DEVICE (0x1631, 0x6200),
994 .driver_info
= (unsigned long) &ax8817x_info
,
996 // JVC MP-PRX1 Port Replicator
997 USB_DEVICE (0x04f1, 0x3008),
998 .driver_info
= (unsigned long) &ax8817x_info
,
1000 // Lenovo U2L100P 10/100
1001 USB_DEVICE (0x17ef, 0x7203),
1002 .driver_info
= (unsigned long) &ax88772_info
,
1004 // ASIX AX88772B 10/100
1005 USB_DEVICE (0x0b95, 0x772b),
1006 .driver_info
= (unsigned long) &ax88772b_info
,
1008 // ASIX AX88772 10/100
1009 USB_DEVICE (0x0b95, 0x7720),
1010 .driver_info
= (unsigned long) &ax88772_info
,
1012 // ASIX AX88178 10/100/1000
1013 USB_DEVICE (0x0b95, 0x1780),
1014 .driver_info
= (unsigned long) &ax88178_info
,
1016 // Logitec LAN-GTJ/U2A
1017 USB_DEVICE (0x0789, 0x0160),
1018 .driver_info
= (unsigned long) &ax88178_info
,
1020 // Linksys USB200M Rev 2
1021 USB_DEVICE (0x13b1, 0x0018),
1022 .driver_info
= (unsigned long) &ax88772_info
,
1024 // 0Q0 cable ethernet
1025 USB_DEVICE (0x1557, 0x7720),
1026 .driver_info
= (unsigned long) &ax88772_info
,
1028 // DLink DUB-E100 H/W Ver B1
1029 USB_DEVICE (0x07d1, 0x3c05),
1030 .driver_info
= (unsigned long) &ax88772_info
,
1032 // DLink DUB-E100 H/W Ver B1 Alternate
1033 USB_DEVICE (0x2001, 0x3c05),
1034 .driver_info
= (unsigned long) &ax88772_info
,
1036 // DLink DUB-E100 H/W Ver C1
1037 USB_DEVICE (0x2001, 0x1a02),
1038 .driver_info
= (unsigned long) &ax88772_info
,
1041 USB_DEVICE (0x1737, 0x0039),
1042 .driver_info
= (unsigned long) &ax88178_info
,
1045 USB_DEVICE (0x04bb, 0x0930),
1046 .driver_info
= (unsigned long) &ax88178_info
,
1049 USB_DEVICE(0x050d, 0x5055),
1050 .driver_info
= (unsigned long) &ax88178_info
,
1052 // Apple USB Ethernet Adapter
1053 USB_DEVICE(0x05ac, 0x1402),
1054 .driver_info
= (unsigned long) &ax88772_info
,
1056 // Cables-to-Go USB Ethernet Adapter
1057 USB_DEVICE(0x0b95, 0x772a),
1058 .driver_info
= (unsigned long) &ax88772_info
,
1061 USB_DEVICE(0x14ea, 0xab11),
1062 .driver_info
= (unsigned long) &ax88178_info
,
1065 USB_DEVICE(0x0db0, 0xa877),
1066 .driver_info
= (unsigned long) &ax88772_info
,
1068 // Asus USB Ethernet Adapter
1069 USB_DEVICE (0x0b95, 0x7e2b),
1070 .driver_info
= (unsigned long) &ax88772_info
,
1072 /* ASIX 88172a demo board */
1073 USB_DEVICE(0x0b95, 0x172a),
1074 .driver_info
= (unsigned long) &ax88172a_info
,
1077 * USBLINK HG20F9 "USB 2.0 LAN"
1078 * Appears to have gazumped Linksys's manufacturer ID but
1079 * doesn't (yet) conflict with any known Linksys product.
1081 USB_DEVICE(0x066b, 0x20f9),
1082 .driver_info
= (unsigned long) &hg20f9_info
,
1086 MODULE_DEVICE_TABLE(usb
, products
);
1088 static struct usb_driver asix_driver
= {
1089 .name
= DRIVER_NAME
,
1090 .id_table
= products
,
1091 .probe
= usbnet_probe
,
1092 .suspend
= usbnet_suspend
,
1093 .resume
= usbnet_resume
,
1094 .disconnect
= usbnet_disconnect
,
1095 .supports_autosuspend
= 1,
1096 .disable_hub_initiated_lpm
= 1,
1099 module_usb_driver(asix_driver
);
1101 MODULE_AUTHOR("David Hollis");
1102 MODULE_VERSION(DRIVER_VERSION
);
1103 MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
1104 MODULE_LICENSE("GPL");