1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Gerhard Sittig <gsi@denx.de>
4 * based on the U-Boot Asix driver as well as information
5 * from the Linux Moschip driver
9 * MOSCHIP MCS7830 based (7730/7830/7832) USB 2.0 Ethernet Devices
17 #include <linux/delay.h>
18 #include <linux/mii.h>
23 #include "usb_ether.h"
25 #define MCS7830_BASE_NAME "mcs"
27 #define USBCALL_TIMEOUT 1000
28 #define LINKSTATUS_TIMEOUT 5000 /* link status, connect timeout */
29 #define LINKSTATUS_TIMEOUT_RES 50 /* link status, resolution in msec */
31 #define MCS7830_RX_URB_SIZE 2048
34 #define MCS7830_WR_BREQ 0x0d
35 #define MCS7830_RD_BREQ 0x0e
37 /* register layout, numerical offset specs for USB API calls */
39 uint8_t multicast_hashes[8];
40 uint8_t packet_gap[2];
42 uint8_t phy_command[2];
43 uint8_t configuration;
44 uint8_t ether_address[6];
45 uint8_t frame_drop_count;
46 uint8_t pause_threshold;
48 #define REG_MULTICAST_HASH offsetof(struct mcs7830_regs, multicast_hashes)
49 #define REG_PHY_DATA offsetof(struct mcs7830_regs, phy_data)
50 #define REG_PHY_CMD offsetof(struct mcs7830_regs, phy_command)
51 #define REG_CONFIG offsetof(struct mcs7830_regs, configuration)
52 #define REG_ETHER_ADDR offsetof(struct mcs7830_regs, ether_address)
53 #define REG_FRAME_DROP_COUNTER offsetof(struct mcs7830_regs, frame_drop_count)
54 #define REG_PAUSE_THRESHOLD offsetof(struct mcs7830_regs, pause_threshold)
56 /* bit masks and default values for the above registers */
57 #define PHY_CMD1_READ 0x40
58 #define PHY_CMD1_WRITE 0x20
59 #define PHY_CMD1_PHYADDR 0x01
61 #define PHY_CMD2_PEND 0x80
62 #define PHY_CMD2_READY 0x40
65 #define CONF_SPEED100 0x40
66 #define CONF_FDX_ENABLE 0x20
67 #define CONF_RXENABLE 0x10
68 #define CONF_TXENABLE 0x08
69 #define CONF_SLEEPMODE 0x04
70 #define CONF_ALLMULTICAST 0x02
71 #define CONF_PROMISCUOUS 0x01
73 #define PAUSE_THRESHOLD_DEFAULT 0
75 /* bit masks for the status byte which follows received ethernet frames */
76 #define STAT_RX_FRAME_CORRECT 0x20
77 #define STAT_RX_LARGE_FRAME 0x10
78 #define STAT_RX_CRC_ERROR 0x08
79 #define STAT_RX_ALIGNMENT_ERROR 0x04
80 #define STAT_RX_LENGTH_ERROR 0x02
81 #define STAT_RX_SHORT_FRAME 0x01
84 * struct mcs7830_private - private driver data for an individual adapter
85 * @config: shadow for the network adapter's configuration register
86 * @mchash: shadow for the network adapter's multicast hash registers
88 struct mcs7830_private {
90 uint8_t rx_buf[MCS7830_RX_URB_SIZE];
91 struct ueth_data ueth;
98 * mcs7830_read_reg() - read a register of the network adapter
99 * @udev: network device to read from
100 * @idx: index of the register to start reading from
101 * @size: number of bytes to read
102 * @data: buffer to read into
103 * Return: zero upon success, negative upon error
105 static int mcs7830_read_reg(struct usb_device *udev, uint8_t idx,
106 uint16_t size, void *data)
109 ALLOC_CACHE_ALIGN_BUFFER(uint8_t, buf, size);
111 debug("%s() idx=0x%04X sz=%d\n", __func__, idx, size);
113 len = usb_control_msg(udev,
114 usb_rcvctrlpipe(udev, 0),
116 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
120 debug("%s() len=%d != sz=%d\n", __func__, len, size);
123 memcpy(data, buf, size);
128 * mcs7830_write_reg() - write a register of the network adapter
129 * @udev: network device to write to
130 * @idx: index of the register to start writing to
131 * @size: number of bytes to write
132 * @data: buffer holding the data to write
133 * Return: zero upon success, negative upon error
135 static int mcs7830_write_reg(struct usb_device *udev, uint8_t idx,
136 uint16_t size, void *data)
139 ALLOC_CACHE_ALIGN_BUFFER(uint8_t, buf, size);
141 debug("%s() idx=0x%04X sz=%d\n", __func__, idx, size);
143 memcpy(buf, data, size);
144 len = usb_control_msg(udev,
145 usb_sndctrlpipe(udev, 0),
147 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
151 debug("%s() len=%d != sz=%d\n", __func__, len, size);
158 * mcs7830_phy_emit_wait() - emit PHY read/write access, wait for its execution
159 * @udev: network device to talk to
160 * @rwflag: PHY_CMD1_READ or PHY_CMD1_WRITE opcode
161 * @index: number of the PHY register to read or write
162 * Return: zero upon success, negative upon error
164 static int mcs7830_phy_emit_wait(struct usb_device *udev,
165 uint8_t rwflag, uint8_t index)
171 /* send the PHY read/write request */
172 cmd[0] = rwflag | PHY_CMD1_PHYADDR;
173 cmd[1] = PHY_CMD2_PEND | (index & 0x1f);
174 rc = mcs7830_write_reg(udev, REG_PHY_CMD, sizeof(cmd), cmd);
178 /* wait for the response to become available (usually < 1ms) */
181 rc = mcs7830_read_reg(udev, REG_PHY_CMD, sizeof(cmd), cmd);
184 if (cmd[1] & PHY_CMD2_READY)
194 * mcs7830_read_phy() - read a PHY register of the network adapter
195 * @udev: network device to read from
196 * @index: index of the PHY register to read from
197 * Return: non-negative 16bit register content, negative upon error
199 static int mcs7830_read_phy(struct usb_device *udev, uint8_t index)
204 /* issue the PHY read request and wait for its execution */
205 rc = mcs7830_phy_emit_wait(udev, PHY_CMD1_READ, index);
209 /* fetch the PHY data which was read */
210 rc = mcs7830_read_reg(udev, REG_PHY_DATA, sizeof(val), &val);
213 rc = le16_to_cpu(val);
214 debug("%s(%d) => 0x%04X\n", __func__, index, rc);
219 * mcs7830_write_phy() - write a PHY register of the network adapter
220 * @udev: network device to write to
221 * @index: index of the PHY register to write to
222 * @val: value to write to the PHY register
223 * Return: zero upon success, negative upon error
225 static int mcs7830_write_phy(struct usb_device *udev, uint8_t index,
230 debug("%s(%d, 0x%04X)\n", __func__, index, val);
232 /* setup the PHY data which is to get written */
233 val = cpu_to_le16(val);
234 rc = mcs7830_write_reg(udev, REG_PHY_DATA, sizeof(val), &val);
238 /* issue the PHY write request and wait for its execution */
239 rc = mcs7830_phy_emit_wait(udev, PHY_CMD1_WRITE, index);
247 * mcs7830_write_config() - write to the network adapter's config register
248 * @udev: network device to write to
249 * @priv: private data
250 * Return: zero upon success, negative upon error
252 * the data which gets written is taken from the shadow config register
253 * within the device driver's private data
255 static int mcs7830_write_config(struct usb_device *udev,
256 struct mcs7830_private *priv)
260 debug("%s()\n", __func__);
262 rc = mcs7830_write_reg(udev, REG_CONFIG,
263 sizeof(priv->config), &priv->config);
265 debug("writing config to adapter failed\n");
273 * mcs7830_write_mchash() - write the network adapter's multicast filter
274 * @udev: network device to write to
275 * @priv: private data
276 * Return: zero upon success, negative upon error
278 * the data which gets written is taken from the shadow multicast hashes
279 * within the device driver's private data
281 static int mcs7830_write_mchash(struct usb_device *udev,
282 struct mcs7830_private *priv)
286 debug("%s()\n", __func__);
288 rc = mcs7830_write_reg(udev, REG_MULTICAST_HASH,
289 sizeof(priv->mchash), &priv->mchash);
291 debug("writing multicast hash to adapter failed\n");
299 * mcs7830_set_autoneg() - setup and trigger ethernet link autonegotiation
300 * @udev: network device to run link negotiation on
301 * Return: zero upon success, negative upon error
303 * the routine advertises available media and starts autonegotiation
305 static int mcs7830_set_autoneg(struct usb_device *udev)
310 debug("%s()\n", __func__);
313 * algorithm taken from the Linux driver, which took it from
314 * "the original mcs7830 version 1.4 driver":
316 * enable all media, reset BMCR, enable auto neg, restart
317 * auto neg while keeping the enable auto neg flag set
320 adv = ADVERTISE_PAUSE_CAP | ADVERTISE_ALL | ADVERTISE_CSMA;
321 rc = mcs7830_write_phy(udev, MII_ADVERTISE, adv);
325 rc = mcs7830_write_phy(udev, MII_BMCR, flg);
327 flg |= BMCR_ANENABLE;
329 rc = mcs7830_write_phy(udev, MII_BMCR, flg);
331 flg |= BMCR_ANRESTART;
333 rc = mcs7830_write_phy(udev, MII_BMCR, flg);
339 * mcs7830_get_rev() - identify a network adapter's chip revision
340 * @udev: network device to identify
341 * Return: non-negative number, reflecting the revision number
343 * currently, only "rev C and higher" and "below rev C" are needed, so
344 * the return value is #1 for "below rev C", and #2 for "rev C and above"
346 static int mcs7830_get_rev(struct usb_device *udev)
352 /* register 22 is readable in rev C and higher */
353 rc = mcs7830_read_reg(udev, REG_FRAME_DROP_COUNTER, sizeof(buf), buf);
358 debug("%s() rc=%d, rev=%d\n", __func__, rc, rev);
363 * mcs7830_apply_fixup() - identify an adapter and potentially apply fixups
364 * @udev: network device to identify and apply fixups to
365 * Return: zero upon success (no errors emitted from here)
367 * this routine identifies the network adapter's chip revision, and applies
368 * fixups for known issues
370 static int mcs7830_apply_fixup(struct usb_device *udev)
376 rev = mcs7830_get_rev(udev);
377 debug("%s() rev=%d\n", __func__, rev);
380 * rev C requires setting the pause threshold (the Linux driver
381 * is inconsistent, the implementation does it for "rev C
382 * exactly", the introductory comment says "rev C and above")
385 debug("%s: applying rev C fixup\n", __func__);
386 thr = PAUSE_THRESHOLD_DEFAULT;
387 for (i = 0; i < 2; i++) {
388 (void)mcs7830_write_reg(udev, REG_PAUSE_THRESHOLD,
398 * mcs7830_basic_reset() - bring the network adapter into a known first state
399 * @eth: network device to act upon
400 * Return: zero upon success, negative upon error
402 * this routine initializes the network adapter such that subsequent invocations
403 * of the interface callbacks can exchange ethernet frames; link negotiation is
404 * triggered from here already and continues in background
406 static int mcs7830_basic_reset(struct usb_device *udev,
407 struct mcs7830_private *priv)
411 debug("%s()\n", __func__);
414 * comment from the respective Linux driver, which
415 * unconditionally sets the ALLMULTICAST flag as well:
416 * should not be needed, but does not work otherwise
418 priv->config = CONF_TXENABLE;
419 priv->config |= CONF_ALLMULTICAST;
421 rc = mcs7830_set_autoneg(udev);
423 pr_err("setting autoneg failed\n");
427 rc = mcs7830_write_mchash(udev, priv);
429 pr_err("failed to set multicast hash\n");
433 rc = mcs7830_write_config(udev, priv);
435 pr_err("failed to set configuration\n");
439 rc = mcs7830_apply_fixup(udev);
441 pr_err("fixup application failed\n");
449 * mcs7830_read_mac() - read an ethernet adapter's MAC address
450 * @udev: network device to read from
451 * @enetaddr: place to put ethernet MAC address
452 * Return: zero upon success, negative upon error
454 * this routine fetches the MAC address stored within the ethernet adapter,
455 * and stores it in the ethernet interface's data structure
457 static int mcs7830_read_mac(struct usb_device *udev, unsigned char enetaddr[])
460 uint8_t buf[ETH_ALEN];
462 debug("%s()\n", __func__);
464 rc = mcs7830_read_reg(udev, REG_ETHER_ADDR, ETH_ALEN, buf);
466 debug("reading MAC from adapter failed\n");
470 memcpy(enetaddr, buf, ETH_ALEN);
474 static int mcs7830_write_mac_common(struct usb_device *udev,
475 unsigned char enetaddr[])
479 debug("%s()\n", __func__);
481 rc = mcs7830_write_reg(udev, REG_ETHER_ADDR, ETH_ALEN, enetaddr);
483 debug("writing MAC to adapter failed\n");
489 static int mcs7830_init_common(struct usb_device *udev)
494 debug("%s()\n", __func__);
498 have_link = mcs7830_read_phy(udev, MII_BMSR) & BMSR_LSTATUS;
501 udelay(LINKSTATUS_TIMEOUT_RES * 1000);
502 timeout += LINKSTATUS_TIMEOUT_RES;
503 } while (timeout < LINKSTATUS_TIMEOUT);
505 debug("ethernet link is down\n");
511 static int mcs7830_send_common(struct ueth_data *ueth, void *packet,
514 struct usb_device *udev = ueth->pusb_dev;
517 /* there is a status byte after the ethernet frame */
518 ALLOC_CACHE_ALIGN_BUFFER(uint8_t, buf, PKTSIZE + sizeof(uint8_t));
520 memcpy(buf, packet, length);
521 rc = usb_bulk_msg(udev,
522 usb_sndbulkpipe(udev, ueth->ep_out),
523 &buf[0], length, &gotlen,
525 debug("%s() TX want len %d, got len %d, rc %d\n",
526 __func__, length, gotlen, rc);
530 static int mcs7830_recv_common(struct ueth_data *ueth, uint8_t *buf)
532 int rc, wantlen, gotlen;
535 debug("%s()\n", __func__);
537 /* fetch input data from the adapter */
538 wantlen = MCS7830_RX_URB_SIZE;
539 rc = usb_bulk_msg(ueth->pusb_dev,
540 usb_rcvbulkpipe(ueth->pusb_dev, ueth->ep_in),
541 &buf[0], wantlen, &gotlen,
543 debug("%s() RX want len %d, got len %d, rc %d\n",
544 __func__, wantlen, gotlen, rc);
546 pr_err("RX: failed to receive\n");
549 if (gotlen > wantlen) {
550 pr_err("RX: got too many bytes (%d)\n", gotlen);
555 * the bulk message that we received from USB contains exactly
556 * one ethernet frame and a trailing status byte
558 if (gotlen < sizeof(sts))
560 gotlen -= sizeof(sts);
563 if (sts == STAT_RX_FRAME_CORRECT) {
564 debug("%s() got a frame, len=%d\n", __func__, gotlen);
568 debug("RX: frame error (sts 0x%02X, %s %s %s %s %s)\n",
570 (sts & STAT_RX_LARGE_FRAME) ? "large" : "-",
571 (sts & STAT_RX_LENGTH_ERROR) ? "length" : "-",
572 (sts & STAT_RX_SHORT_FRAME) ? "short" : "-",
573 (sts & STAT_RX_CRC_ERROR) ? "crc" : "-",
574 (sts & STAT_RX_ALIGNMENT_ERROR) ? "align" : "-");
578 #ifndef CONFIG_DM_ETH
580 * mcs7830_init() - network interface's init callback
581 * @udev: network device to initialize
582 * @bd: board information
583 * Return: zero upon success, negative upon error
585 * after initial setup during probe() and get_info(), this init() callback
586 * ensures that the link is up and subsequent send() and recv() calls can
587 * exchange ethernet frames
589 static int mcs7830_init(struct eth_device *eth, struct bd_info *bd)
591 struct ueth_data *dev = eth->priv;
593 return mcs7830_init_common(dev->pusb_dev);
597 * mcs7830_send() - network interface's send callback
598 * @eth: network device to send the frame from
599 * @packet: ethernet frame content
600 * @length: ethernet frame length
601 * Return: zero upon success, negative upon error
603 * this routine send an ethernet frame out of the network interface
605 static int mcs7830_send(struct eth_device *eth, void *packet, int length)
607 struct ueth_data *dev = eth->priv;
609 return mcs7830_send_common(dev, packet, length);
613 * mcs7830_recv() - network interface's recv callback
614 * @eth: network device to receive frames from
615 * Return: zero upon success, negative upon error
617 * this routine checks for available ethernet frames that the network
618 * interface might have received, and notifies the network stack
620 static int mcs7830_recv(struct eth_device *eth)
622 ALLOC_CACHE_ALIGN_BUFFER(uint8_t, buf, MCS7830_RX_URB_SIZE);
623 struct ueth_data *ueth = eth->priv;
626 len = mcs7830_recv_common(ueth, buf);
628 net_process_received_packet(buf, len);
636 * mcs7830_halt() - network interface's halt callback
637 * @eth: network device to cease operation of
640 * this routine is supposed to undo the effect of previous initialization and
641 * ethernet frames exchange; in this implementation it's a NOP
643 static void mcs7830_halt(struct eth_device *eth)
645 debug("%s()\n", __func__);
649 * mcs7830_write_mac() - write an ethernet adapter's MAC address
650 * @eth: network device to write to
651 * Return: zero upon success, negative upon error
653 * this routine takes the MAC address from the ethernet interface's data
654 * structure, and writes it into the ethernet adapter such that subsequent
655 * exchange of ethernet frames uses this address
657 static int mcs7830_write_mac(struct eth_device *eth)
659 struct ueth_data *ueth = eth->priv;
661 return mcs7830_write_mac_common(ueth->pusb_dev, eth->enetaddr);
665 * mcs7830_iface_idx - index of detected network interfaces
667 * this counter keeps track of identified supported interfaces,
668 * to assign unique names as more interfaces are found
670 static int mcs7830_iface_idx;
673 * mcs7830_eth_before_probe() - network driver's before_probe callback
676 * this routine initializes driver's internal data in preparation of
677 * subsequent probe callbacks
679 void mcs7830_eth_before_probe(void)
681 mcs7830_iface_idx = 0;
685 * struct mcs7830_dongle - description of a supported Moschip ethernet dongle
686 * @vendor: 16bit USB vendor identification
687 * @product: 16bit USB product identification
689 * this structure describes a supported USB ethernet dongle by means of the
690 * vendor and product codes found during USB enumeration; no flags are held
691 * here since all supported dongles have identical behaviour, and required
692 * fixups get determined at runtime, such that no manual configuration is
695 struct mcs7830_dongle {
701 * mcs7830_dongles - the list of supported Moschip based USB ethernet dongles
703 static const struct mcs7830_dongle mcs7830_dongles[] = {
704 { 0x9710, 0x7832, }, /* Moschip 7832 */
705 { 0x9710, 0x7830, }, /* Moschip 7830 */
706 { 0x9710, 0x7730, }, /* Moschip 7730 */
707 { 0x0df6, 0x0021, }, /* Sitecom LN 30 */
711 * mcs7830_eth_probe() - network driver's probe callback
712 * @dev: detected USB device to check
713 * @ifnum: detected USB interface to check
714 * @ss: USB ethernet data structure to fill in upon match
715 * Return: #1 upon match, #0 upon mismatch or error
717 * this routine checks whether the found USB device is supported by
718 * this ethernet driver, and upon match fills in the USB ethernet
719 * data structure which later is passed to the get_info callback
721 int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
722 struct ueth_data *ss)
724 struct usb_interface *iface;
725 struct usb_interface_descriptor *iface_desc;
727 struct mcs7830_private *priv;
728 int ep_in_found, ep_out_found, ep_intr_found;
730 debug("%s()\n", __func__);
732 /* iterate the list of supported dongles */
733 iface = &dev->config.if_desc[ifnum];
734 iface_desc = &iface->desc;
735 for (i = 0; i < ARRAY_SIZE(mcs7830_dongles); i++) {
736 if (dev->descriptor.idVendor == mcs7830_dongles[i].vendor &&
737 dev->descriptor.idProduct == mcs7830_dongles[i].product)
740 if (i == ARRAY_SIZE(mcs7830_dongles))
742 debug("detected USB ethernet device: %04X:%04X\n",
743 dev->descriptor.idVendor, dev->descriptor.idProduct);
745 /* fill in driver private data */
746 priv = calloc(1, sizeof(*priv));
750 /* fill in the ueth_data structure, attach private data */
751 memset(ss, 0, sizeof(*ss));
754 ss->subclass = iface_desc->bInterfaceSubClass;
755 ss->protocol = iface_desc->bInterfaceProtocol;
759 * a minimum of three endpoints is expected: in (bulk),
760 * out (bulk), and interrupt; ignore all others
762 ep_in_found = ep_out_found = ep_intr_found = 0;
763 for (i = 0; i < iface_desc->bNumEndpoints; i++) {
764 uint8_t eptype, epaddr;
767 eptype = iface->ep_desc[i].bmAttributes;
768 eptype &= USB_ENDPOINT_XFERTYPE_MASK;
770 epaddr = iface->ep_desc[i].bEndpointAddress;
771 is_input = epaddr & USB_DIR_IN;
772 epaddr &= USB_ENDPOINT_NUMBER_MASK;
774 if (eptype == USB_ENDPOINT_XFER_BULK) {
775 if (is_input && !ep_in_found) {
779 if (!is_input && !ep_out_found) {
785 if (eptype == USB_ENDPOINT_XFER_INT) {
786 if (is_input && !ep_intr_found) {
788 ss->irqinterval = iface->ep_desc[i].bInterval;
793 debug("endpoints: in %d, out %d, intr %d\n",
794 ss->ep_in, ss->ep_out, ss->ep_int);
796 /* apply basic sanity checks */
797 if (usb_set_interface(dev, iface_desc->bInterfaceNumber, 0) ||
798 !ss->ep_in || !ss->ep_out || !ss->ep_int) {
799 debug("device probe incomplete\n");
808 * mcs7830_eth_get_info() - network driver's get_info callback
809 * @dev: detected USB device
810 * @ss: USB ethernet data structure filled in at probe()
811 * @eth: ethernet interface data structure to fill in
812 * Return: #1 upon success, #0 upon error
814 * this routine registers the mandatory init(), send(), recv(), and
815 * halt() callbacks with the ethernet interface, can register the
816 * optional write_hwaddr() callback with the ethernet interface,
817 * and initiates configuration of the interface such that subsequent
818 * calls to those callbacks results in network communication
820 int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
821 struct eth_device *eth)
823 debug("%s()\n", __func__);
825 debug("%s: missing parameter.\n", __func__);
829 snprintf(eth->name, sizeof(eth->name), "%s%d",
830 MCS7830_BASE_NAME, mcs7830_iface_idx++);
831 eth->init = mcs7830_init;
832 eth->send = mcs7830_send;
833 eth->recv = mcs7830_recv;
834 eth->halt = mcs7830_halt;
835 eth->write_hwaddr = mcs7830_write_mac;
838 if (mcs7830_basic_reset(ss->pusb_dev, ss->dev_priv))
841 if (mcs7830_read_mac(ss->pusb_dev, eth->enetaddr))
843 debug("MAC %pM\n", eth->enetaddr);
851 static int mcs7830_eth_start(struct udevice *dev)
853 struct usb_device *udev = dev_get_parent_priv(dev);
855 return mcs7830_init_common(udev);
858 void mcs7830_eth_stop(struct udevice *dev)
860 debug("** %s()\n", __func__);
863 int mcs7830_eth_send(struct udevice *dev, void *packet, int length)
865 struct mcs7830_private *priv = dev_get_priv(dev);
866 struct ueth_data *ueth = &priv->ueth;
868 return mcs7830_send_common(ueth, packet, length);
871 int mcs7830_eth_recv(struct udevice *dev, int flags, uchar **packetp)
873 struct mcs7830_private *priv = dev_get_priv(dev);
874 struct ueth_data *ueth = &priv->ueth;
877 len = mcs7830_recv_common(ueth, priv->rx_buf);
878 *packetp = priv->rx_buf;
883 static int mcs7830_free_pkt(struct udevice *dev, uchar *packet, int packet_len)
885 struct mcs7830_private *priv = dev_get_priv(dev);
887 packet_len = ALIGN(packet_len, 4);
888 usb_ether_advance_rxbuf(&priv->ueth, sizeof(u32) + packet_len);
893 int mcs7830_write_hwaddr(struct udevice *dev)
895 struct usb_device *udev = dev_get_parent_priv(dev);
896 struct eth_pdata *pdata = dev_get_platdata(dev);
898 return mcs7830_write_mac_common(udev, pdata->enetaddr);
901 static int mcs7830_eth_probe(struct udevice *dev)
903 struct usb_device *udev = dev_get_parent_priv(dev);
904 struct mcs7830_private *priv = dev_get_priv(dev);
905 struct eth_pdata *pdata = dev_get_platdata(dev);
906 struct ueth_data *ueth = &priv->ueth;
908 if (mcs7830_basic_reset(udev, priv))
911 if (mcs7830_read_mac(udev, pdata->enetaddr))
914 return usb_ether_register(dev, ueth, MCS7830_RX_URB_SIZE);
917 static const struct eth_ops mcs7830_eth_ops = {
918 .start = mcs7830_eth_start,
919 .send = mcs7830_eth_send,
920 .recv = mcs7830_eth_recv,
921 .free_pkt = mcs7830_free_pkt,
922 .stop = mcs7830_eth_stop,
923 .write_hwaddr = mcs7830_write_hwaddr,
926 U_BOOT_DRIVER(mcs7830_eth) = {
927 .name = "mcs7830_eth",
929 .probe = mcs7830_eth_probe,
930 .ops = &mcs7830_eth_ops,
931 .priv_auto = sizeof(struct mcs7830_private),
932 .platdata_auto = sizeof(struct eth_pdata),
933 .flags = DM_FLAG_ALLOC_PRIV_DMA,
936 static const struct usb_device_id mcs7830_eth_id_table[] = {
937 { USB_DEVICE(0x9710, 0x7832) }, /* Moschip 7832 */
938 { USB_DEVICE(0x9710, 0x7830), }, /* Moschip 7830 */
939 { USB_DEVICE(0x9710, 0x7730), }, /* Moschip 7730 */
940 { USB_DEVICE(0x0df6, 0x0021), }, /* Sitecom LN 30 */
941 { } /* Terminating entry */
944 U_BOOT_USB_DEVICE(mcs7830_eth, mcs7830_eth_id_table);