2 * Copyright (c) 2011 The Chromium OS Authors.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/mii.h>
12 #include "usb_ether.h"
14 /* ASIX AX8817X based USB 2.0 Ethernet Devices */
16 #define AX_CMD_SET_SW_MII 0x06
17 #define AX_CMD_READ_MII_REG 0x07
18 #define AX_CMD_WRITE_MII_REG 0x08
19 #define AX_CMD_SET_HW_MII 0x0a
20 #define AX_CMD_READ_EEPROM 0x0b
21 #define AX_CMD_READ_RX_CTL 0x0f
22 #define AX_CMD_WRITE_RX_CTL 0x10
23 #define AX_CMD_WRITE_IPG0 0x12
24 #define AX_CMD_READ_NODE_ID 0x13
25 #define AX_CMD_WRITE_NODE_ID 0x14
26 #define AX_CMD_READ_PHY_ID 0x19
27 #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
28 #define AX_CMD_WRITE_GPIOS 0x1f
29 #define AX_CMD_SW_RESET 0x20
30 #define AX_CMD_SW_PHY_SELECT 0x22
32 #define AX_SWRESET_CLEAR 0x00
33 #define AX_SWRESET_PRTE 0x04
34 #define AX_SWRESET_PRL 0x08
35 #define AX_SWRESET_IPRL 0x20
36 #define AX_SWRESET_IPPD 0x40
38 #define AX88772_IPG0_DEFAULT 0x15
39 #define AX88772_IPG1_DEFAULT 0x0c
40 #define AX88772_IPG2_DEFAULT 0x12
42 /* AX88772 & AX88178 Medium Mode Register */
43 #define AX_MEDIUM_PF 0x0080
44 #define AX_MEDIUM_JFE 0x0040
45 #define AX_MEDIUM_TFC 0x0020
46 #define AX_MEDIUM_RFC 0x0010
47 #define AX_MEDIUM_ENCK 0x0008
48 #define AX_MEDIUM_AC 0x0004
49 #define AX_MEDIUM_FD 0x0002
50 #define AX_MEDIUM_GM 0x0001
51 #define AX_MEDIUM_SM 0x1000
52 #define AX_MEDIUM_SBP 0x0800
53 #define AX_MEDIUM_PS 0x0200
54 #define AX_MEDIUM_RE 0x0100
56 #define AX88178_MEDIUM_DEFAULT \
57 (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
58 AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
61 #define AX88772_MEDIUM_DEFAULT \
62 (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
63 AX_MEDIUM_TFC | AX_MEDIUM_PS | \
64 AX_MEDIUM_AC | AX_MEDIUM_RE)
66 /* AX88772 & AX88178 RX_CTL values */
67 #define AX_RX_CTL_SO 0x0080
68 #define AX_RX_CTL_AB 0x0008
70 #define AX_DEFAULT_RX_CTL \
71 (AX_RX_CTL_SO | AX_RX_CTL_AB)
74 #define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
75 #define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
76 #define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
79 #define ASIX_BASE_NAME "asx"
80 #define USB_CTRL_SET_TIMEOUT 5000
81 #define USB_CTRL_GET_TIMEOUT 5000
82 #define USB_BULK_SEND_TIMEOUT 5000
83 #define USB_BULK_RECV_TIMEOUT 5000
85 #define AX_RX_URB_SIZE 2048
86 #define PHY_CONNECT_TIMEOUT 5000
88 /* asix_flags defines */
90 #define FLAG_TYPE_AX88172 (1U << 0)
91 #define FLAG_TYPE_AX88772 (1U << 1)
92 #define FLAG_TYPE_AX88772B (1U << 2)
93 #define FLAG_EEPROM_MAC (1U << 3) /* initial mac address in eeprom */
100 struct ueth_data ueth;
104 #ifndef CONFIG_DM_ETH
106 static int curr_eth_dev; /* index for name of next device detected */
110 * Asix infrastructure commands
112 static int asix_write_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,
113 u16 size, void *data)
117 debug("asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x "
118 "size=%d\n", cmd, value, index, size);
120 len = usb_control_msg(
122 usb_sndctrlpipe(dev->pusb_dev, 0),
124 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
129 USB_CTRL_SET_TIMEOUT);
131 return len == size ? 0 : -1;
134 static int asix_read_cmd(struct ueth_data *dev, u8 cmd, u16 value, u16 index,
135 u16 size, void *data)
139 debug("asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
140 cmd, value, index, size);
142 len = usb_control_msg(
144 usb_rcvctrlpipe(dev->pusb_dev, 0),
146 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
151 USB_CTRL_GET_TIMEOUT);
152 return len == size ? 0 : -1;
155 static inline int asix_set_sw_mii(struct ueth_data *dev)
159 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
161 debug("Failed to enable software MII access\n");
165 static inline int asix_set_hw_mii(struct ueth_data *dev)
169 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
171 debug("Failed to enable hardware MII access\n");
175 static int asix_mdio_read(struct ueth_data *dev, int phy_id, int loc)
177 ALLOC_CACHE_ALIGN_BUFFER(__le16, res, 1);
179 asix_set_sw_mii(dev);
180 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, res);
181 asix_set_hw_mii(dev);
183 debug("asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
184 phy_id, loc, le16_to_cpu(*res));
186 return le16_to_cpu(*res);
190 asix_mdio_write(struct ueth_data *dev, int phy_id, int loc, int val)
192 ALLOC_CACHE_ALIGN_BUFFER(__le16, res, 1);
193 *res = cpu_to_le16(val);
195 debug("asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
197 asix_set_sw_mii(dev);
198 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, res);
199 asix_set_hw_mii(dev);
203 * Asix "high level" commands
205 static int asix_sw_reset(struct ueth_data *dev, u8 flags)
209 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
211 debug("Failed to send software reset: %02x\n", ret);
218 static inline int asix_get_phy_addr(struct ueth_data *dev)
220 ALLOC_CACHE_ALIGN_BUFFER(u8, buf, 2);
222 int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
224 debug("asix_get_phy_addr()\n");
227 debug("Error reading PHYID register: %02x\n", ret);
230 debug("asix_get_phy_addr() returning 0x%02x%02x\n", buf[0], buf[1]);
237 static int asix_write_medium_mode(struct ueth_data *dev, u16 mode)
241 debug("asix_write_medium_mode() - mode = 0x%04x\n", mode);
242 ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode,
245 debug("Failed to write Medium Mode mode to 0x%04x: %02x\n",
251 static u16 asix_read_rx_ctl(struct ueth_data *dev)
253 ALLOC_CACHE_ALIGN_BUFFER(__le16, v, 1);
255 int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, v);
258 debug("Error reading RX_CTL register: %02x\n", ret);
260 ret = le16_to_cpu(*v);
264 static int asix_write_rx_ctl(struct ueth_data *dev, u16 mode)
268 debug("asix_write_rx_ctl() - mode = 0x%04x\n", mode);
269 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
271 debug("Failed to write RX_CTL mode to 0x%04x: %02x\n",
277 static int asix_write_gpio(struct ueth_data *dev, u16 value, int sleep)
281 debug("asix_write_gpio() - value = 0x%04x\n", value);
282 ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
284 debug("Failed to write GPIO value 0x%04x: %02x\n",
288 udelay(sleep * 1000);
293 static int asix_write_hwaddr_common(struct ueth_data *dev, uint8_t *enetaddr)
296 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
298 memcpy(buf, enetaddr, ETH_ALEN);
300 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN, buf);
302 debug("Failed to set MAC address: %02x\n", ret);
312 * mii_nway_restart - restart NWay (autonegotiation) for this interface
314 * Returns 0 on success, negative on error.
316 static int mii_nway_restart(struct ueth_data *dev)
321 /* if autoneg is off, it's an error */
322 bmcr = asix_mdio_read(dev, dev->phy_id, MII_BMCR);
324 if (bmcr & BMCR_ANENABLE) {
325 bmcr |= BMCR_ANRESTART;
326 asix_mdio_write(dev, dev->phy_id, MII_BMCR, bmcr);
333 static int asix_read_mac_common(struct ueth_data *dev,
334 struct asix_private *priv, uint8_t *enetaddr)
336 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buf, ETH_ALEN);
339 if (priv->flags & FLAG_EEPROM_MAC) {
340 for (i = 0; i < (ETH_ALEN >> 1); i++) {
341 if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
342 0x04 + i, 0, 2, buf) < 0) {
343 debug("Failed to read SROM address 04h.\n");
346 memcpy(enetaddr + i * 2, buf, 2);
349 if (asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)
351 debug("Failed to read MAC address.\n");
354 memcpy(enetaddr, buf, ETH_ALEN);
360 static int asix_basic_reset(struct ueth_data *dev)
365 if (asix_write_gpio(dev,
366 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5) < 0)
369 /* 0x10 is the phy id of the embedded 10/100 ethernet phy */
370 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
371 if (asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
372 embd_phy, 0, 0, NULL) < 0) {
373 debug("Select PHY #1 failed\n");
377 if (asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL) < 0)
380 if (asix_sw_reset(dev, AX_SWRESET_CLEAR) < 0)
384 if (asix_sw_reset(dev, AX_SWRESET_IPRL) < 0)
387 if (asix_sw_reset(dev, AX_SWRESET_PRTE) < 0)
391 rx_ctl = asix_read_rx_ctl(dev);
392 debug("RX_CTL is 0x%04x after software reset\n", rx_ctl);
393 if (asix_write_rx_ctl(dev, 0x0000) < 0)
396 rx_ctl = asix_read_rx_ctl(dev);
397 debug("RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
399 dev->phy_id = asix_get_phy_addr(dev);
401 debug("Failed to read phy id\n");
403 asix_mdio_write(dev, dev->phy_id, MII_BMCR, BMCR_RESET);
404 asix_mdio_write(dev, dev->phy_id, MII_ADVERTISE,
405 ADVERTISE_ALL | ADVERTISE_CSMA);
406 mii_nway_restart(dev);
408 if (asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT) < 0)
411 if (asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
412 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
413 AX88772_IPG2_DEFAULT, 0, NULL) < 0) {
414 debug("Write IPG,IPG1,IPG2 failed\n");
421 static int asix_init_common(struct ueth_data *dev)
424 #define TIMEOUT_RESOLUTION 50 /* ms */
427 debug("** %s()\n", __func__);
429 if (asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL) < 0)
433 link_detected = asix_mdio_read(dev, dev->phy_id, MII_BMSR) &
435 if (!link_detected) {
437 printf("Waiting for Ethernet connection... ");
438 udelay(TIMEOUT_RESOLUTION * 1000);
439 timeout += TIMEOUT_RESOLUTION;
441 } while (!link_detected && timeout < PHY_CONNECT_TIMEOUT);
446 printf("unable to connect.\n");
455 static int asix_send_common(struct ueth_data *dev, void *packet, int length)
460 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg,
461 PKTSIZE + sizeof(packet_len));
463 debug("** %s(), len %d\n", __func__, length);
465 packet_len = (((length) ^ 0x0000ffff) << 16) + (length);
466 cpu_to_le32s(&packet_len);
468 memcpy(msg, &packet_len, sizeof(packet_len));
469 memcpy(msg + sizeof(packet_len), (void *)packet, length);
471 err = usb_bulk_msg(dev->pusb_dev,
472 usb_sndbulkpipe(dev->pusb_dev, dev->ep_out),
474 length + sizeof(packet_len),
476 USB_BULK_SEND_TIMEOUT);
477 debug("Tx: len = %zu, actual = %u, err = %d\n",
478 length + sizeof(packet_len), actual_len, err);
483 #ifndef CONFIG_DM_ETH
487 static int asix_init(struct eth_device *eth, bd_t *bd)
489 struct ueth_data *dev = (struct ueth_data *)eth->priv;
491 return asix_init_common(dev);
494 static int asix_send(struct eth_device *eth, void *packet, int length)
496 struct ueth_data *dev = (struct ueth_data *)eth->priv;
498 return asix_send_common(dev, packet, length);
501 static int asix_recv(struct eth_device *eth)
503 struct ueth_data *dev = (struct ueth_data *)eth->priv;
504 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, recv_buf, AX_RX_URB_SIZE);
505 unsigned char *buf_ptr;
510 debug("** %s()\n", __func__);
512 err = usb_bulk_msg(dev->pusb_dev,
513 usb_rcvbulkpipe(dev->pusb_dev, dev->ep_in),
517 USB_BULK_RECV_TIMEOUT);
518 debug("Rx: len = %u, actual = %u, err = %d\n", AX_RX_URB_SIZE,
521 debug("Rx: failed to receive\n");
524 if (actual_len > AX_RX_URB_SIZE) {
525 debug("Rx: received too many bytes %d\n", actual_len);
530 while (actual_len > 0) {
532 * 1st 4 bytes contain the length of the actual data as two
533 * complementary 16-bit words. Extract the length of the data.
535 if (actual_len < sizeof(packet_len)) {
536 debug("Rx: incomplete packet length\n");
539 memcpy(&packet_len, buf_ptr, sizeof(packet_len));
540 le32_to_cpus(&packet_len);
541 if (((~packet_len >> 16) & 0x7ff) != (packet_len & 0x7ff)) {
542 debug("Rx: malformed packet length: %#x (%#x:%#x)\n",
543 packet_len, (~packet_len >> 16) & 0x7ff,
547 packet_len = packet_len & 0x7ff;
548 if (packet_len > actual_len - sizeof(packet_len)) {
549 debug("Rx: too large packet: %d\n", packet_len);
553 /* Notify net stack */
554 net_process_received_packet(buf_ptr + sizeof(packet_len),
557 /* Adjust for next iteration. Packets are padded to 16-bits */
560 actual_len -= sizeof(packet_len) + packet_len;
561 buf_ptr += sizeof(packet_len) + packet_len;
567 static void asix_halt(struct eth_device *eth)
569 debug("** %s()\n", __func__);
572 static int asix_write_hwaddr(struct eth_device *eth)
574 struct ueth_data *dev = (struct ueth_data *)eth->priv;
576 return asix_write_hwaddr_common(dev, eth->enetaddr);
580 * Asix probing functions
582 void asix_eth_before_probe(void)
588 unsigned short vendor;
589 unsigned short product;
593 static const struct asix_dongle asix_dongles[] = {
594 { 0x05ac, 0x1402, FLAG_TYPE_AX88772 }, /* Apple USB Ethernet Adapter */
595 { 0x07d1, 0x3c05, FLAG_TYPE_AX88772 }, /* D-Link DUB-E100 H/W Ver B1 */
596 { 0x2001, 0x1a02, FLAG_TYPE_AX88772 }, /* D-Link DUB-E100 H/W Ver C1 */
597 /* Cables-to-Go USB Ethernet Adapter */
598 { 0x0b95, 0x772a, FLAG_TYPE_AX88772 },
599 { 0x0b95, 0x7720, FLAG_TYPE_AX88772 }, /* Trendnet TU2-ET100 V3.0R */
600 { 0x0b95, 0x1720, FLAG_TYPE_AX88172 }, /* SMC */
601 { 0x0db0, 0xa877, FLAG_TYPE_AX88772 }, /* MSI - ASIX 88772a */
602 { 0x13b1, 0x0018, FLAG_TYPE_AX88172 }, /* Linksys 200M v2.1 */
603 { 0x1557, 0x7720, FLAG_TYPE_AX88772 }, /* 0Q0 cable ethernet */
604 /* DLink DUB-E100 H/W Ver B1 Alternate */
605 { 0x2001, 0x3c05, FLAG_TYPE_AX88772 },
607 { 0x0b95, 0x772b, FLAG_TYPE_AX88772B | FLAG_EEPROM_MAC },
608 { 0x0b95, 0x7e2b, FLAG_TYPE_AX88772B },
609 { 0x0000, 0x0000, FLAG_NONE } /* END - Do not remove */
612 /* Probe to see if a new device is actually an asix device */
613 int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
614 struct ueth_data *ss)
616 struct usb_interface *iface;
617 struct usb_interface_descriptor *iface_desc;
618 int ep_in_found = 0, ep_out_found = 0;
621 /* let's examine the device now */
622 iface = &dev->config.if_desc[ifnum];
623 iface_desc = &dev->config.if_desc[ifnum].desc;
625 for (i = 0; asix_dongles[i].vendor != 0; i++) {
626 if (dev->descriptor.idVendor == asix_dongles[i].vendor &&
627 dev->descriptor.idProduct == asix_dongles[i].product)
628 /* Found a supported dongle */
632 if (asix_dongles[i].vendor == 0)
635 memset(ss, 0, sizeof(struct ueth_data));
637 /* At this point, we know we've got a live one */
638 debug("\n\nUSB Ethernet device detected: %#04x:%#04x\n",
639 dev->descriptor.idVendor, dev->descriptor.idProduct);
641 /* Initialize the ueth_data structure with some useful info */
644 ss->subclass = iface_desc->bInterfaceSubClass;
645 ss->protocol = iface_desc->bInterfaceProtocol;
647 /* alloc driver private */
648 ss->dev_priv = calloc(1, sizeof(struct asix_private));
652 ((struct asix_private *)ss->dev_priv)->flags = asix_dongles[i].flags;
655 * We are expecting a minimum of 3 endpoints - in, out (bulk), and
656 * int. We will ignore any others.
658 for (i = 0; i < iface_desc->bNumEndpoints; i++) {
659 /* is it an BULK endpoint? */
660 if ((iface->ep_desc[i].bmAttributes &
661 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
662 u8 ep_addr = iface->ep_desc[i].bEndpointAddress;
663 if (ep_addr & USB_DIR_IN) {
665 ss->ep_in = ep_addr &
666 USB_ENDPOINT_NUMBER_MASK;
671 ss->ep_out = ep_addr &
672 USB_ENDPOINT_NUMBER_MASK;
678 /* is it an interrupt endpoint? */
679 if ((iface->ep_desc[i].bmAttributes &
680 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
681 ss->ep_int = iface->ep_desc[i].bEndpointAddress &
682 USB_ENDPOINT_NUMBER_MASK;
683 ss->irqinterval = iface->ep_desc[i].bInterval;
686 debug("Endpoints In %d Out %d Int %d\n",
687 ss->ep_in, ss->ep_out, ss->ep_int);
689 /* Do some basic sanity checks, and bail if we find a problem */
690 if (usb_set_interface(dev, iface_desc->bInterfaceNumber, 0) ||
691 !ss->ep_in || !ss->ep_out || !ss->ep_int) {
692 debug("Problems with device\n");
695 dev->privptr = (void *)ss;
699 int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
700 struct eth_device *eth)
702 struct asix_private *priv = (struct asix_private *)ss->dev_priv;
705 debug("%s: missing parameter.\n", __func__);
708 sprintf(eth->name, "%s%d", ASIX_BASE_NAME, curr_eth_dev++);
709 eth->init = asix_init;
710 eth->send = asix_send;
711 eth->recv = asix_recv;
712 eth->halt = asix_halt;
713 if (!(priv->flags & FLAG_TYPE_AX88172))
714 eth->write_hwaddr = asix_write_hwaddr;
717 if (asix_basic_reset(ss))
720 /* Get the MAC address */
721 if (asix_read_mac_common(ss, priv, eth->enetaddr))
723 debug("MAC %pM\n", eth->enetaddr);
730 static int asix_eth_start(struct udevice *dev)
732 struct asix_private *priv = dev_get_priv(dev);
734 return asix_init_common(&priv->ueth);
737 void asix_eth_stop(struct udevice *dev)
739 debug("** %s()\n", __func__);
742 int asix_eth_send(struct udevice *dev, void *packet, int length)
744 struct asix_private *priv = dev_get_priv(dev);
746 return asix_send_common(&priv->ueth, packet, length);
749 int asix_eth_recv(struct udevice *dev, int flags, uchar **packetp)
751 struct asix_private *priv = dev_get_priv(dev);
752 struct ueth_data *ueth = &priv->ueth;
757 len = usb_ether_get_rx_bytes(ueth, &ptr);
758 debug("%s: first try, len=%d\n", __func__, len);
760 if (!(flags & ETH_RECV_CHECK_DEVICE))
762 ret = usb_ether_receive(ueth, AX_RX_URB_SIZE);
766 len = usb_ether_get_rx_bytes(ueth, &ptr);
767 debug("%s: second try, len=%d\n", __func__, len);
771 * 1st 4 bytes contain the length of the actual data as two
772 * complementary 16-bit words. Extract the length of the data.
774 if (len < sizeof(packet_len)) {
775 debug("Rx: incomplete packet length\n");
778 memcpy(&packet_len, ptr, sizeof(packet_len));
779 le32_to_cpus(&packet_len);
780 if (((~packet_len >> 16) & 0x7ff) != (packet_len & 0x7ff)) {
781 debug("Rx: malformed packet length: %#x (%#x:%#x)\n",
782 packet_len, (~packet_len >> 16) & 0x7ff,
786 packet_len = packet_len & 0x7ff;
787 if (packet_len > len - sizeof(packet_len)) {
788 debug("Rx: too large packet: %d\n", packet_len);
792 *packetp = ptr + sizeof(packet_len);
796 usb_ether_advance_rxbuf(ueth, -1);
800 static int asix_free_pkt(struct udevice *dev, uchar *packet, int packet_len)
802 struct asix_private *priv = dev_get_priv(dev);
806 usb_ether_advance_rxbuf(&priv->ueth, sizeof(u32) + packet_len);
811 int asix_write_hwaddr(struct udevice *dev)
813 struct eth_pdata *pdata = dev_get_platdata(dev);
814 struct asix_private *priv = dev_get_priv(dev);
816 if (priv->flags & FLAG_TYPE_AX88172)
819 return asix_write_hwaddr_common(&priv->ueth, pdata->enetaddr);
822 static int asix_eth_probe(struct udevice *dev)
824 struct eth_pdata *pdata = dev_get_platdata(dev);
825 struct asix_private *priv = dev_get_priv(dev);
826 struct ueth_data *ss = &priv->ueth;
829 priv->flags = dev->driver_data;
830 ret = usb_ether_register(dev, ss, AX_RX_URB_SIZE);
834 ret = asix_basic_reset(ss);
838 /* Get the MAC address */
839 ret = asix_read_mac_common(ss, priv, pdata->enetaddr);
842 debug("MAC %pM\n", pdata->enetaddr);
847 return usb_ether_deregister(ss);
850 static const struct eth_ops asix_eth_ops = {
851 .start = asix_eth_start,
852 .send = asix_eth_send,
853 .recv = asix_eth_recv,
854 .free_pkt = asix_free_pkt,
855 .stop = asix_eth_stop,
856 .write_hwaddr = asix_write_hwaddr,
859 U_BOOT_DRIVER(asix_eth) = {
862 .probe = asix_eth_probe,
863 .ops = &asix_eth_ops,
864 .priv_auto_alloc_size = sizeof(struct asix_private),
865 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
868 static const struct usb_device_id asix_eth_id_table[] = {
869 /* Apple USB Ethernet Adapter */
870 { USB_DEVICE(0x05ac, 0x1402), .driver_info = FLAG_TYPE_AX88772 },
871 /* D-Link DUB-E100 H/W Ver B1 */
872 { USB_DEVICE(0x07d1, 0x3c05), .driver_info = FLAG_TYPE_AX88772 },
873 /* D-Link DUB-E100 H/W Ver C1 */
874 { USB_DEVICE(0x2001, 0x1a02), .driver_info = FLAG_TYPE_AX88772 },
875 /* Cables-to-Go USB Ethernet Adapter */
876 { USB_DEVICE(0x0b95, 0x772a), .driver_info = FLAG_TYPE_AX88772 },
877 /* Trendnet TU2-ET100 V3.0R */
878 { USB_DEVICE(0x0b95, 0x7720), .driver_info = FLAG_TYPE_AX88772 },
880 { USB_DEVICE(0x0b95, 0x1720), .driver_info = FLAG_TYPE_AX88172 },
881 /* MSI - ASIX 88772a */
882 { USB_DEVICE(0x0db0, 0xa877), .driver_info = FLAG_TYPE_AX88772 },
883 /* Linksys 200M v2.1 */
884 { USB_DEVICE(0x13b1, 0x0018), .driver_info = FLAG_TYPE_AX88172 },
885 /* 0Q0 cable ethernet */
886 { USB_DEVICE(0x1557, 0x7720), .driver_info = FLAG_TYPE_AX88772 },
887 /* DLink DUB-E100 H/W Ver B1 Alternate */
888 { USB_DEVICE(0x2001, 0x3c05), .driver_info = FLAG_TYPE_AX88772 },
890 { USB_DEVICE(0x0b95, 0x772b),
891 .driver_info = FLAG_TYPE_AX88772B | FLAG_EEPROM_MAC },
892 { USB_DEVICE(0x0b95, 0x7e2b), .driver_info = FLAG_TYPE_AX88772B },
893 { } /* Terminating entry */
896 U_BOOT_USB_DEVICE(asix_eth, asix_eth_id_table);