2 * Copyright (c) 2011 The Chromium OS Authors.
3 * Copyright (C) 2009 NVIDIA, Corporation
4 * Copyright (C) 2007-2008 SMSC (Steve Glendinning)
6 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/unaligned.h>
12 #include <linux/mii.h>
13 #include "usb_ether.h"
16 /* SMSC LAN95xx based USB 2.0 Ethernet Devices */
19 #define LED_GPIO_CFG (0x24)
20 #define LED_GPIO_CFG_SPD_LED (0x01000000)
21 #define LED_GPIO_CFG_LNK_LED (0x00100000)
22 #define LED_GPIO_CFG_FDX_LED (0x00010000)
24 /* Tx command words */
25 #define TX_CMD_A_FIRST_SEG_ 0x00002000
26 #define TX_CMD_A_LAST_SEG_ 0x00001000
29 #define RX_STS_FL_ 0x3FFF0000 /* Frame Length */
30 #define RX_STS_ES_ 0x00008000 /* Error Summary */
38 #define TX_CFG_ON_ 0x00000004
41 #define HW_CFG_BIR_ 0x00001000
42 #define HW_CFG_RXDOFF_ 0x00000600
43 #define HW_CFG_MEF_ 0x00000020
44 #define HW_CFG_BCE_ 0x00000002
45 #define HW_CFG_LRST_ 0x00000008
48 #define PM_CTL_PHY_RST_ 0x00000010
53 * Hi watermark = 15.5Kb (~10 mtu pkts)
54 * low watermark = 3k (~2 mtu pkts)
55 * backpressure duration = ~ 350us
56 * Apply FC on any frame.
58 #define AFC_CFG_DEFAULT 0x00F830A1
61 #define E2P_CMD_BUSY_ 0x80000000
62 #define E2P_CMD_READ_ 0x00000000
63 #define E2P_CMD_TIMEOUT_ 0x00000400
64 #define E2P_CMD_LOADED_ 0x00000200
65 #define E2P_CMD_ADDR_ 0x000001FF
69 #define BURST_CAP 0x38
71 #define INT_EP_CTL 0x68
72 #define INT_EP_CTL_PHY_INT_ 0x00008000
74 #define BULK_IN_DLY 0x6C
78 #define MAC_CR_MCPAS_ 0x00080000
79 #define MAC_CR_PRMS_ 0x00040000
80 #define MAC_CR_HPFILT_ 0x00002000
81 #define MAC_CR_TXEN_ 0x00000008
82 #define MAC_CR_RXEN_ 0x00000004
88 #define MII_ADDR 0x114
89 #define MII_WRITE_ 0x02
90 #define MII_BUSY_ 0x01
91 #define MII_READ_ 0x00 /* ~of MII Write bit */
93 #define MII_DATA 0x118
100 #define Tx_COE_EN_ 0x00010000
101 #define Rx_COE_EN_ 0x00000001
103 /* Vendor-specific PHY Definitions */
104 #define PHY_INT_SRC 29
106 #define PHY_INT_MASK 30
107 #define PHY_INT_MASK_ANEG_COMP_ ((u16)0x0040)
108 #define PHY_INT_MASK_LINK_DOWN_ ((u16)0x0010)
109 #define PHY_INT_MASK_DEFAULT_ (PHY_INT_MASK_ANEG_COMP_ | \
110 PHY_INT_MASK_LINK_DOWN_)
112 /* USB Vendor Requests */
113 #define USB_VENDOR_REQUEST_WRITE_REGISTER 0xA0
114 #define USB_VENDOR_REQUEST_READ_REGISTER 0xA1
116 /* Some extra defines */
117 #define HS_USB_PKT_SIZE 512
118 #define FS_USB_PKT_SIZE 64
119 #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
120 #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
121 #define DEFAULT_BULK_IN_DELAY 0x00002000
122 #define MAX_SINGLE_PACKET_SIZE 2048
123 #define EEPROM_MAC_OFFSET 0x01
124 #define SMSC95XX_INTERNAL_PHY_ID 1
125 #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
128 #define SMSC95XX_BASE_NAME "sms"
129 #define USB_CTRL_SET_TIMEOUT 5000
130 #define USB_CTRL_GET_TIMEOUT 5000
131 #define USB_BULK_SEND_TIMEOUT 5000
132 #define USB_BULK_RECV_TIMEOUT 5000
134 #define AX_RX_URB_SIZE 2048
135 #define PHY_CONNECT_TIMEOUT 5000
140 static int curr_eth_dev; /* index for name of next device detected */
143 struct smsc95xx_private {
144 size_t rx_urb_size; /* maximum USB URB size */
145 u32 mac_cr; /* MAC control register value */
146 int have_hwaddr; /* 1 if we have a hardware MAC address */
150 * Smsc95xx infrastructure commands
152 static int smsc95xx_write_reg(struct ueth_data *dev, u32 index, u32 data)
155 ALLOC_CACHE_ALIGN_BUFFER(u32, tmpbuf, 1);
160 len = usb_control_msg(dev->pusb_dev, usb_sndctrlpipe(dev->pusb_dev, 0),
161 USB_VENDOR_REQUEST_WRITE_REGISTER,
162 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
163 00, index, tmpbuf, sizeof(data), USB_CTRL_SET_TIMEOUT);
164 if (len != sizeof(data)) {
165 debug("smsc95xx_write_reg failed: index=%d, data=%d, len=%d",
172 static int smsc95xx_read_reg(struct ueth_data *dev, u32 index, u32 *data)
175 ALLOC_CACHE_ALIGN_BUFFER(u32, tmpbuf, 1);
177 len = usb_control_msg(dev->pusb_dev, usb_rcvctrlpipe(dev->pusb_dev, 0),
178 USB_VENDOR_REQUEST_READ_REGISTER,
179 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
180 00, index, tmpbuf, sizeof(data), USB_CTRL_GET_TIMEOUT);
182 if (len != sizeof(data)) {
183 debug("smsc95xx_read_reg failed: index=%d, len=%d",
192 /* Loop until the read is completed with timeout */
193 static int smsc95xx_phy_wait_not_busy(struct ueth_data *dev)
195 unsigned long start_time = get_timer(0);
199 smsc95xx_read_reg(dev, MII_ADDR, &val);
200 if (!(val & MII_BUSY_))
202 } while (get_timer(start_time) < 1 * 1000 * 1000);
207 static int smsc95xx_mdio_read(struct ueth_data *dev, int phy_id, int idx)
211 /* confirm MII not busy */
212 if (smsc95xx_phy_wait_not_busy(dev)) {
213 debug("MII is busy in smsc95xx_mdio_read\n");
217 /* set the address, index & direction (read from PHY) */
218 addr = (phy_id << 11) | (idx << 6) | MII_READ_;
219 smsc95xx_write_reg(dev, MII_ADDR, addr);
221 if (smsc95xx_phy_wait_not_busy(dev)) {
222 debug("Timed out reading MII reg %02X\n", idx);
226 smsc95xx_read_reg(dev, MII_DATA, &val);
228 return (u16)(val & 0xFFFF);
231 static void smsc95xx_mdio_write(struct ueth_data *dev, int phy_id, int idx,
236 /* confirm MII not busy */
237 if (smsc95xx_phy_wait_not_busy(dev)) {
238 debug("MII is busy in smsc95xx_mdio_write\n");
243 smsc95xx_write_reg(dev, MII_DATA, val);
245 /* set the address, index & direction (write to PHY) */
246 addr = (phy_id << 11) | (idx << 6) | MII_WRITE_;
247 smsc95xx_write_reg(dev, MII_ADDR, addr);
249 if (smsc95xx_phy_wait_not_busy(dev))
250 debug("Timed out writing MII reg %02X\n", idx);
253 static int smsc95xx_eeprom_confirm_not_busy(struct ueth_data *dev)
255 unsigned long start_time = get_timer(0);
259 smsc95xx_read_reg(dev, E2P_CMD, &val);
260 if (!(val & E2P_CMD_BUSY_))
263 } while (get_timer(start_time) < 1 * 1000 * 1000);
265 debug("EEPROM is busy\n");
269 static int smsc95xx_wait_eeprom(struct ueth_data *dev)
271 unsigned long start_time = get_timer(0);
275 smsc95xx_read_reg(dev, E2P_CMD, &val);
276 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
279 } while (get_timer(start_time) < 1 * 1000 * 1000);
281 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
282 debug("EEPROM read operation timeout\n");
288 static int smsc95xx_read_eeprom(struct ueth_data *dev, u32 offset, u32 length,
294 ret = smsc95xx_eeprom_confirm_not_busy(dev);
298 for (i = 0; i < length; i++) {
299 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
300 smsc95xx_write_reg(dev, E2P_CMD, val);
302 ret = smsc95xx_wait_eeprom(dev);
306 smsc95xx_read_reg(dev, E2P_DATA, &val);
307 data[i] = val & 0xFF;
314 * mii_nway_restart - restart NWay (autonegotiation) for this interface
316 * Returns 0 on success, negative on error.
318 static int mii_nway_restart(struct ueth_data *dev)
323 /* if autoneg is off, it's an error */
324 bmcr = smsc95xx_mdio_read(dev, dev->phy_id, MII_BMCR);
326 if (bmcr & BMCR_ANENABLE) {
327 bmcr |= BMCR_ANRESTART;
328 smsc95xx_mdio_write(dev, dev->phy_id, MII_BMCR, bmcr);
334 static int smsc95xx_phy_initialize(struct ueth_data *dev)
336 smsc95xx_mdio_write(dev, dev->phy_id, MII_BMCR, BMCR_RESET);
337 smsc95xx_mdio_write(dev, dev->phy_id, MII_ADVERTISE,
338 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
339 ADVERTISE_PAUSE_ASYM);
342 smsc95xx_mdio_read(dev, dev->phy_id, PHY_INT_SRC);
344 smsc95xx_mdio_write(dev, dev->phy_id, PHY_INT_MASK,
345 PHY_INT_MASK_DEFAULT_);
346 mii_nway_restart(dev);
348 debug("phy initialised succesfully\n");
352 static int smsc95xx_init_mac_address(struct eth_device *eth,
353 struct ueth_data *dev)
355 /* try reading mac address from EEPROM */
356 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
357 eth->enetaddr) == 0) {
358 if (is_valid_ethaddr(eth->enetaddr)) {
359 /* eeprom values are valid so use them */
360 debug("MAC address read from EEPROM\n");
366 * No eeprom, or eeprom values are invalid. Generating a random MAC
367 * address is not safe. Just return an error.
372 static int smsc95xx_write_hwaddr(struct eth_device *eth)
374 struct ueth_data *dev = (struct ueth_data *)eth->priv;
375 struct smsc95xx_private *priv = dev->dev_priv;
376 u32 addr_lo = __get_unaligned_le32(ð->enetaddr[0]);
377 u32 addr_hi = __get_unaligned_le16(ð->enetaddr[4]);
380 /* set hardware address */
381 debug("** %s()\n", __func__);
382 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
386 ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
390 debug("MAC %pM\n", eth->enetaddr);
391 priv->have_hwaddr = 1;
395 /* Enable or disable Tx & Rx checksum offload engines */
396 static int smsc95xx_set_csums(struct ueth_data *dev,
397 int use_tx_csum, int use_rx_csum)
400 int ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
405 read_buf |= Tx_COE_EN_;
407 read_buf &= ~Tx_COE_EN_;
410 read_buf |= Rx_COE_EN_;
412 read_buf &= ~Rx_COE_EN_;
414 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
418 debug("COE_CR = 0x%08x\n", read_buf);
422 static void smsc95xx_set_multicast(struct ueth_data *dev)
424 struct smsc95xx_private *priv = dev->dev_priv;
426 /* No multicast in u-boot */
427 priv->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
430 /* starts the TX path */
431 static void smsc95xx_start_tx_path(struct ueth_data *dev)
433 struct smsc95xx_private *priv = dev->dev_priv;
436 /* Enable Tx at MAC */
437 priv->mac_cr |= MAC_CR_TXEN_;
439 smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
441 /* Enable Tx at SCSRs */
442 reg_val = TX_CFG_ON_;
443 smsc95xx_write_reg(dev, TX_CFG, reg_val);
446 /* Starts the Receive path */
447 static void smsc95xx_start_rx_path(struct ueth_data *dev)
449 struct smsc95xx_private *priv = dev->dev_priv;
451 priv->mac_cr |= MAC_CR_RXEN_;
452 smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
458 static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
465 struct ueth_data *dev = (struct ueth_data *)eth->priv;
466 struct smsc95xx_private *priv =
467 (struct smsc95xx_private *)dev->dev_priv;
468 #define TIMEOUT_RESOLUTION 50 /* ms */
471 debug("** %s()\n", __func__);
472 dev->phy_id = SMSC95XX_INTERNAL_PHY_ID; /* fixed phy id */
474 write_buf = HW_CFG_LRST_;
475 ret = smsc95xx_write_reg(dev, HW_CFG, write_buf);
481 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
486 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
488 if (timeout >= 100) {
489 debug("timeout waiting for completion of Lite Reset\n");
493 write_buf = PM_CTL_PHY_RST_;
494 ret = smsc95xx_write_reg(dev, PM_CTRL, write_buf);
500 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
505 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
506 if (timeout >= 100) {
507 debug("timeout waiting for PHY Reset\n");
510 if (!priv->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
511 priv->have_hwaddr = 1;
512 if (!priv->have_hwaddr) {
513 puts("Error: SMSC95xx: No MAC address set - set usbethaddr\n");
516 if (smsc95xx_write_hwaddr(eth) < 0)
519 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
522 debug("Read Value from HW_CFG : 0x%08x\n", read_buf);
524 read_buf |= HW_CFG_BIR_;
525 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
529 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
532 debug("Read Value from HW_CFG after writing "
533 "HW_CFG_BIR_: 0x%08x\n", read_buf);
536 if (dev->pusb_dev->speed == USB_SPEED_HIGH) {
537 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
538 priv->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
540 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
541 priv->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
545 priv->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
547 debug("rx_urb_size=%ld\n", (ulong)priv->rx_urb_size);
549 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
553 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
556 debug("Read Value from BURST_CAP after writing: 0x%08x\n", read_buf);
558 read_buf = DEFAULT_BULK_IN_DELAY;
559 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, read_buf);
563 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
566 debug("Read Value from BULK_IN_DLY after writing: "
567 "0x%08x\n", read_buf);
569 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
572 debug("Read Value from HW_CFG: 0x%08x\n", read_buf);
575 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
577 read_buf &= ~HW_CFG_RXDOFF_;
579 #define NET_IP_ALIGN 0
580 read_buf |= NET_IP_ALIGN << 9;
582 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
586 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
589 debug("Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
591 write_buf = 0xFFFFFFFF;
592 ret = smsc95xx_write_reg(dev, INT_STS, write_buf);
596 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
599 debug("ID_REV = 0x%08x\n", read_buf);
601 /* Configure GPIO pins as LED outputs */
602 write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
603 LED_GPIO_CFG_FDX_LED;
604 ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
607 debug("LED_GPIO_CFG set\n");
611 ret = smsc95xx_write_reg(dev, FLOW, write_buf);
615 read_buf = AFC_CFG_DEFAULT;
616 ret = smsc95xx_write_reg(dev, AFC_CFG, read_buf);
620 ret = smsc95xx_read_reg(dev, MAC_CR, &priv->mac_cr);
624 /* Init Rx. Set Vlan */
625 write_buf = (u32)ETH_P_8021Q;
626 ret = smsc95xx_write_reg(dev, VLAN1, write_buf);
630 /* Disable checksum offload engines */
631 ret = smsc95xx_set_csums(dev, 0, 0);
633 debug("Failed to set csum offload: %d\n", ret);
636 smsc95xx_set_multicast(dev);
638 if (smsc95xx_phy_initialize(dev) < 0)
640 ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
644 /* enable PHY interrupts */
645 read_buf |= INT_EP_CTL_PHY_INT_;
647 ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
651 smsc95xx_start_tx_path(dev);
652 smsc95xx_start_rx_path(dev);
656 link_detected = smsc95xx_mdio_read(dev, dev->phy_id, MII_BMSR)
658 if (!link_detected) {
660 printf("Waiting for Ethernet connection... ");
661 udelay(TIMEOUT_RESOLUTION * 1000);
662 timeout += TIMEOUT_RESOLUTION;
664 } while (!link_detected && timeout < PHY_CONNECT_TIMEOUT);
669 printf("unable to connect.\n");
675 static int smsc95xx_send(struct eth_device *eth, void* packet, int length)
677 struct ueth_data *dev = (struct ueth_data *)eth->priv;
682 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg,
683 PKTSIZE + sizeof(tx_cmd_a) + sizeof(tx_cmd_b));
685 debug("** %s(), len %d, buf %#x\n", __func__, length, (int)msg);
686 if (length > PKTSIZE)
689 tx_cmd_a = (u32)length | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
690 tx_cmd_b = (u32)length;
691 cpu_to_le32s(&tx_cmd_a);
692 cpu_to_le32s(&tx_cmd_b);
694 /* prepend cmd_a and cmd_b */
695 memcpy(msg, &tx_cmd_a, sizeof(tx_cmd_a));
696 memcpy(msg + sizeof(tx_cmd_a), &tx_cmd_b, sizeof(tx_cmd_b));
697 memcpy(msg + sizeof(tx_cmd_a) + sizeof(tx_cmd_b), (void *)packet,
699 err = usb_bulk_msg(dev->pusb_dev,
700 usb_sndbulkpipe(dev->pusb_dev, dev->ep_out),
702 length + sizeof(tx_cmd_a) + sizeof(tx_cmd_b),
704 USB_BULK_SEND_TIMEOUT);
705 debug("Tx: len = %u, actual = %u, err = %d\n",
706 length + sizeof(tx_cmd_a) + sizeof(tx_cmd_b),
711 static int smsc95xx_recv(struct eth_device *eth)
713 struct ueth_data *dev = (struct ueth_data *)eth->priv;
714 DEFINE_CACHE_ALIGN_BUFFER(unsigned char, recv_buf, AX_RX_URB_SIZE);
715 unsigned char *buf_ptr;
721 debug("** %s()\n", __func__);
722 err = usb_bulk_msg(dev->pusb_dev,
723 usb_rcvbulkpipe(dev->pusb_dev, dev->ep_in),
727 USB_BULK_RECV_TIMEOUT);
728 debug("Rx: len = %u, actual = %u, err = %d\n", AX_RX_URB_SIZE,
731 debug("Rx: failed to receive\n");
734 if (actual_len > AX_RX_URB_SIZE) {
735 debug("Rx: received too many bytes %d\n", actual_len);
740 while (actual_len > 0) {
742 * 1st 4 bytes contain the length of the actual data plus error
743 * info. Extract data length.
745 if (actual_len < sizeof(packet_len)) {
746 debug("Rx: incomplete packet length\n");
749 memcpy(&packet_len, buf_ptr, sizeof(packet_len));
750 le32_to_cpus(&packet_len);
751 if (packet_len & RX_STS_ES_) {
752 debug("Rx: Error header=%#x", packet_len);
755 packet_len = ((packet_len & RX_STS_FL_) >> 16);
757 if (packet_len > actual_len - sizeof(packet_len)) {
758 debug("Rx: too large packet: %d\n", packet_len);
762 /* Notify net stack */
763 net_process_received_packet(buf_ptr + sizeof(packet_len),
766 /* Adjust for next iteration */
767 actual_len -= sizeof(packet_len) + packet_len;
768 buf_ptr += sizeof(packet_len) + packet_len;
769 cur_buf_align = (int)buf_ptr - (int)recv_buf;
771 if (cur_buf_align & 0x03) {
772 int align = 4 - (cur_buf_align & 0x03);
781 static void smsc95xx_halt(struct eth_device *eth)
783 debug("** %s()\n", __func__);
787 * SMSC probing functions
789 void smsc95xx_eth_before_probe(void)
794 struct smsc95xx_dongle {
795 unsigned short vendor;
796 unsigned short product;
799 static const struct smsc95xx_dongle smsc95xx_dongles[] = {
800 { 0x0424, 0xec00 }, /* LAN9512/LAN9514 Ethernet */
801 { 0x0424, 0x9500 }, /* LAN9500 Ethernet */
802 { 0x0424, 0x9730 }, /* LAN9730 Ethernet (HSIC) */
803 { 0x0424, 0x9900 }, /* SMSC9500 USB Ethernet Device (SAL10) */
804 { 0x0424, 0x9e00 }, /* LAN9500A Ethernet */
805 { 0x0000, 0x0000 } /* END - Do not remove */
808 /* Probe to see if a new device is actually an SMSC device */
809 int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
810 struct ueth_data *ss)
812 struct usb_interface *iface;
813 struct usb_interface_descriptor *iface_desc;
816 /* let's examine the device now */
817 iface = &dev->config.if_desc[ifnum];
818 iface_desc = &dev->config.if_desc[ifnum].desc;
820 for (i = 0; smsc95xx_dongles[i].vendor != 0; i++) {
821 if (dev->descriptor.idVendor == smsc95xx_dongles[i].vendor &&
822 dev->descriptor.idProduct == smsc95xx_dongles[i].product)
823 /* Found a supported dongle */
826 if (smsc95xx_dongles[i].vendor == 0)
829 /* At this point, we know we've got a live one */
830 debug("\n\nUSB Ethernet device detected\n");
831 memset(ss, '\0', sizeof(struct ueth_data));
833 /* Initialize the ueth_data structure with some useful info */
836 ss->subclass = iface_desc->bInterfaceSubClass;
837 ss->protocol = iface_desc->bInterfaceProtocol;
840 * We are expecting a minimum of 3 endpoints - in, out (bulk), and int.
841 * We will ignore any others.
843 for (i = 0; i < iface_desc->bNumEndpoints; i++) {
844 /* is it an BULK endpoint? */
845 if ((iface->ep_desc[i].bmAttributes &
846 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
847 if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN)
849 iface->ep_desc[i].bEndpointAddress &
850 USB_ENDPOINT_NUMBER_MASK;
853 iface->ep_desc[i].bEndpointAddress &
854 USB_ENDPOINT_NUMBER_MASK;
857 /* is it an interrupt endpoint? */
858 if ((iface->ep_desc[i].bmAttributes &
859 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
860 ss->ep_int = iface->ep_desc[i].bEndpointAddress &
861 USB_ENDPOINT_NUMBER_MASK;
862 ss->irqinterval = iface->ep_desc[i].bInterval;
865 debug("Endpoints In %d Out %d Int %d\n",
866 ss->ep_in, ss->ep_out, ss->ep_int);
868 /* Do some basic sanity checks, and bail if we find a problem */
869 if (usb_set_interface(dev, iface_desc->bInterfaceNumber, 0) ||
870 !ss->ep_in || !ss->ep_out || !ss->ep_int) {
871 debug("Problems with device\n");
874 dev->privptr = (void *)ss;
876 /* alloc driver private */
877 ss->dev_priv = calloc(1, sizeof(struct smsc95xx_private));
884 int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
885 struct eth_device *eth)
887 debug("** %s()\n", __func__);
889 debug("%s: missing parameter.\n", __func__);
892 sprintf(eth->name, "%s%d", SMSC95XX_BASE_NAME, curr_eth_dev++);
893 eth->init = smsc95xx_init;
894 eth->send = smsc95xx_send;
895 eth->recv = smsc95xx_recv;
896 eth->halt = smsc95xx_halt;
897 eth->write_hwaddr = smsc95xx_write_hwaddr;