2 * Copyright (c) 2011 The Chromium OS Authors.
3 * Copyright (C) 2009 NVIDIA, Corporation
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include <asm/unaligned.h>
26 #include <linux/mii.h>
27 #include "usb_ether.h"
30 /* SMSC LAN95xx based USB 2.0 Ethernet Devices */
32 /* Tx command words */
33 #define TX_CMD_A_FIRST_SEG_ 0x00002000
34 #define TX_CMD_A_LAST_SEG_ 0x00001000
37 #define RX_STS_FL_ 0x3FFF0000 /* Frame Length */
38 #define RX_STS_ES_ 0x00008000 /* Error Summary */
46 #define TX_CFG_ON_ 0x00000004
49 #define HW_CFG_BIR_ 0x00001000
50 #define HW_CFG_RXDOFF_ 0x00000600
51 #define HW_CFG_MEF_ 0x00000020
52 #define HW_CFG_BCE_ 0x00000002
53 #define HW_CFG_LRST_ 0x00000008
56 #define PM_CTL_PHY_RST_ 0x00000010
61 * Hi watermark = 15.5Kb (~10 mtu pkts)
62 * low watermark = 3k (~2 mtu pkts)
63 * backpressure duration = ~ 350us
64 * Apply FC on any frame.
66 #define AFC_CFG_DEFAULT 0x00F830A1
69 #define E2P_CMD_BUSY_ 0x80000000
70 #define E2P_CMD_READ_ 0x00000000
71 #define E2P_CMD_TIMEOUT_ 0x00000400
72 #define E2P_CMD_LOADED_ 0x00000200
73 #define E2P_CMD_ADDR_ 0x000001FF
77 #define BURST_CAP 0x38
79 #define INT_EP_CTL 0x68
80 #define INT_EP_CTL_PHY_INT_ 0x00008000
82 #define BULK_IN_DLY 0x6C
86 #define MAC_CR_MCPAS_ 0x00080000
87 #define MAC_CR_PRMS_ 0x00040000
88 #define MAC_CR_HPFILT_ 0x00002000
89 #define MAC_CR_TXEN_ 0x00000008
90 #define MAC_CR_RXEN_ 0x00000004
96 #define MII_ADDR 0x114
97 #define MII_WRITE_ 0x02
98 #define MII_BUSY_ 0x01
99 #define MII_READ_ 0x00 /* ~of MII Write bit */
101 #define MII_DATA 0x118
108 #define Tx_COE_EN_ 0x00010000
109 #define Rx_COE_EN_ 0x00000001
111 /* Vendor-specific PHY Definitions */
112 #define PHY_INT_SRC 29
114 #define PHY_INT_MASK 30
115 #define PHY_INT_MASK_ANEG_COMP_ ((u16)0x0040)
116 #define PHY_INT_MASK_LINK_DOWN_ ((u16)0x0010)
117 #define PHY_INT_MASK_DEFAULT_ (PHY_INT_MASK_ANEG_COMP_ | \
118 PHY_INT_MASK_LINK_DOWN_)
120 /* USB Vendor Requests */
121 #define USB_VENDOR_REQUEST_WRITE_REGISTER 0xA0
122 #define USB_VENDOR_REQUEST_READ_REGISTER 0xA1
124 /* Some extra defines */
125 #define HS_USB_PKT_SIZE 512
126 #define FS_USB_PKT_SIZE 64
127 #define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
128 #define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
129 #define DEFAULT_BULK_IN_DELAY 0x00002000
130 #define MAX_SINGLE_PACKET_SIZE 2048
131 #define EEPROM_MAC_OFFSET 0x01
132 #define SMSC95XX_INTERNAL_PHY_ID 1
133 #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
136 #define SMSC95XX_BASE_NAME "sms"
137 #define USB_CTRL_SET_TIMEOUT 5000
138 #define USB_CTRL_GET_TIMEOUT 5000
139 #define USB_BULK_SEND_TIMEOUT 5000
140 #define USB_BULK_RECV_TIMEOUT 5000
142 #define AX_RX_URB_SIZE 2048
143 #define PHY_CONNECT_TIMEOUT 5000
148 static int curr_eth_dev; /* index for name of next device detected */
151 struct smsc95xx_private {
152 size_t rx_urb_size; /* maximum USB URB size */
153 u32 mac_cr; /* MAC control register value */
154 int have_hwaddr; /* 1 if we have a hardware MAC address */
158 * Smsc95xx infrastructure commands
160 static int smsc95xx_write_reg(struct ueth_data *dev, u32 index, u32 data)
163 ALLOC_CACHE_ALIGN_BUFFER(u32, tmpbuf, 1);
168 len = usb_control_msg(dev->pusb_dev, usb_sndctrlpipe(dev->pusb_dev, 0),
169 USB_VENDOR_REQUEST_WRITE_REGISTER,
170 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
171 00, index, tmpbuf, sizeof(data), USB_CTRL_SET_TIMEOUT);
172 if (len != sizeof(data)) {
173 debug("smsc95xx_write_reg failed: index=%d, data=%d, len=%d",
180 static int smsc95xx_read_reg(struct ueth_data *dev, u32 index, u32 *data)
183 ALLOC_CACHE_ALIGN_BUFFER(u32, tmpbuf, 1);
185 len = usb_control_msg(dev->pusb_dev, usb_rcvctrlpipe(dev->pusb_dev, 0),
186 USB_VENDOR_REQUEST_READ_REGISTER,
187 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
188 00, index, tmpbuf, sizeof(data), USB_CTRL_GET_TIMEOUT);
190 if (len != sizeof(data)) {
191 debug("smsc95xx_read_reg failed: index=%d, len=%d",
200 /* Loop until the read is completed with timeout */
201 static int smsc95xx_phy_wait_not_busy(struct ueth_data *dev)
203 unsigned long start_time = get_timer(0);
207 smsc95xx_read_reg(dev, MII_ADDR, &val);
208 if (!(val & MII_BUSY_))
210 } while (get_timer(start_time) < 1 * 1000 * 1000);
215 static int smsc95xx_mdio_read(struct ueth_data *dev, int phy_id, int idx)
219 /* confirm MII not busy */
220 if (smsc95xx_phy_wait_not_busy(dev)) {
221 debug("MII is busy in smsc95xx_mdio_read\n");
225 /* set the address, index & direction (read from PHY) */
226 addr = (phy_id << 11) | (idx << 6) | MII_READ_;
227 smsc95xx_write_reg(dev, MII_ADDR, addr);
229 if (smsc95xx_phy_wait_not_busy(dev)) {
230 debug("Timed out reading MII reg %02X\n", idx);
234 smsc95xx_read_reg(dev, MII_DATA, &val);
236 return (u16)(val & 0xFFFF);
239 static void smsc95xx_mdio_write(struct ueth_data *dev, int phy_id, int idx,
244 /* confirm MII not busy */
245 if (smsc95xx_phy_wait_not_busy(dev)) {
246 debug("MII is busy in smsc95xx_mdio_write\n");
251 smsc95xx_write_reg(dev, MII_DATA, val);
253 /* set the address, index & direction (write to PHY) */
254 addr = (phy_id << 11) | (idx << 6) | MII_WRITE_;
255 smsc95xx_write_reg(dev, MII_ADDR, addr);
257 if (smsc95xx_phy_wait_not_busy(dev))
258 debug("Timed out writing MII reg %02X\n", idx);
261 static int smsc95xx_eeprom_confirm_not_busy(struct ueth_data *dev)
263 unsigned long start_time = get_timer(0);
267 smsc95xx_read_reg(dev, E2P_CMD, &val);
268 if (!(val & E2P_CMD_LOADED_)) {
269 debug("No EEPROM present\n");
272 if (!(val & E2P_CMD_BUSY_))
275 } while (get_timer(start_time) < 1 * 1000 * 1000);
277 debug("EEPROM is busy\n");
281 static int smsc95xx_wait_eeprom(struct ueth_data *dev)
283 unsigned long start_time = get_timer(0);
287 smsc95xx_read_reg(dev, E2P_CMD, &val);
288 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
291 } while (get_timer(start_time) < 1 * 1000 * 1000);
293 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
294 debug("EEPROM read operation timeout\n");
300 static int smsc95xx_read_eeprom(struct ueth_data *dev, u32 offset, u32 length,
306 ret = smsc95xx_eeprom_confirm_not_busy(dev);
310 for (i = 0; i < length; i++) {
311 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
312 smsc95xx_write_reg(dev, E2P_CMD, val);
314 ret = smsc95xx_wait_eeprom(dev);
318 smsc95xx_read_reg(dev, E2P_DATA, &val);
319 data[i] = val & 0xFF;
326 * mii_nway_restart - restart NWay (autonegotiation) for this interface
328 * Returns 0 on success, negative on error.
330 static int mii_nway_restart(struct ueth_data *dev)
335 /* if autoneg is off, it's an error */
336 bmcr = smsc95xx_mdio_read(dev, dev->phy_id, MII_BMCR);
338 if (bmcr & BMCR_ANENABLE) {
339 bmcr |= BMCR_ANRESTART;
340 smsc95xx_mdio_write(dev, dev->phy_id, MII_BMCR, bmcr);
346 static int smsc95xx_phy_initialize(struct ueth_data *dev)
348 smsc95xx_mdio_write(dev, dev->phy_id, MII_BMCR, BMCR_RESET);
349 smsc95xx_mdio_write(dev, dev->phy_id, MII_ADVERTISE,
350 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
351 ADVERTISE_PAUSE_ASYM);
354 smsc95xx_mdio_read(dev, dev->phy_id, PHY_INT_SRC);
356 smsc95xx_mdio_write(dev, dev->phy_id, PHY_INT_MASK,
357 PHY_INT_MASK_DEFAULT_);
358 mii_nway_restart(dev);
360 debug("phy initialised succesfully\n");
364 static int smsc95xx_init_mac_address(struct eth_device *eth,
365 struct ueth_data *dev)
367 /* try reading mac address from EEPROM */
368 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
369 eth->enetaddr) == 0) {
370 if (is_valid_ether_addr(eth->enetaddr)) {
371 /* eeprom values are valid so use them */
372 debug("MAC address read from EEPROM\n");
378 * No eeprom, or eeprom values are invalid. Generating a random MAC
379 * address is not safe. Just return an error.
384 static int smsc95xx_write_hwaddr(struct eth_device *eth)
386 struct ueth_data *dev = (struct ueth_data *)eth->priv;
387 struct smsc95xx_private *priv = dev->dev_priv;
388 u32 addr_lo = __get_unaligned_le32(ð->enetaddr[0]);
389 u32 addr_hi = __get_unaligned_le16(ð->enetaddr[4]);
392 /* set hardware address */
393 debug("** %s()\n", __func__);
394 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
398 ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
402 debug("MAC %pM\n", eth->enetaddr);
403 priv->have_hwaddr = 1;
407 /* Enable or disable Tx & Rx checksum offload engines */
408 static int smsc95xx_set_csums(struct ueth_data *dev,
409 int use_tx_csum, int use_rx_csum)
412 int ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
417 read_buf |= Tx_COE_EN_;
419 read_buf &= ~Tx_COE_EN_;
422 read_buf |= Rx_COE_EN_;
424 read_buf &= ~Rx_COE_EN_;
426 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
430 debug("COE_CR = 0x%08x\n", read_buf);
434 static void smsc95xx_set_multicast(struct ueth_data *dev)
436 struct smsc95xx_private *priv = dev->dev_priv;
438 /* No multicast in u-boot */
439 priv->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
442 /* starts the TX path */
443 static void smsc95xx_start_tx_path(struct ueth_data *dev)
445 struct smsc95xx_private *priv = dev->dev_priv;
448 /* Enable Tx at MAC */
449 priv->mac_cr |= MAC_CR_TXEN_;
451 smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
453 /* Enable Tx at SCSRs */
454 reg_val = TX_CFG_ON_;
455 smsc95xx_write_reg(dev, TX_CFG, reg_val);
458 /* Starts the Receive path */
459 static void smsc95xx_start_rx_path(struct ueth_data *dev)
461 struct smsc95xx_private *priv = dev->dev_priv;
463 priv->mac_cr |= MAC_CR_RXEN_;
464 smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
470 static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
477 struct ueth_data *dev = (struct ueth_data *)eth->priv;
478 struct smsc95xx_private *priv =
479 (struct smsc95xx_private *)dev->dev_priv;
480 #define TIMEOUT_RESOLUTION 50 /* ms */
483 debug("** %s()\n", __func__);
484 dev->phy_id = SMSC95XX_INTERNAL_PHY_ID; /* fixed phy id */
486 write_buf = HW_CFG_LRST_;
487 ret = smsc95xx_write_reg(dev, HW_CFG, write_buf);
493 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
498 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
500 if (timeout >= 100) {
501 debug("timeout waiting for completion of Lite Reset\n");
505 write_buf = PM_CTL_PHY_RST_;
506 ret = smsc95xx_write_reg(dev, PM_CTRL, write_buf);
512 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
517 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
518 if (timeout >= 100) {
519 debug("timeout waiting for PHY Reset\n");
522 if (!priv->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
523 priv->have_hwaddr = 1;
524 if (!priv->have_hwaddr) {
525 puts("Error: SMSC95xx: No MAC address set - set usbethaddr\n");
528 if (smsc95xx_write_hwaddr(eth) < 0)
531 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
534 debug("Read Value from HW_CFG : 0x%08x\n", read_buf);
536 read_buf |= HW_CFG_BIR_;
537 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
541 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
544 debug("Read Value from HW_CFG after writing "
545 "HW_CFG_BIR_: 0x%08x\n", read_buf);
548 if (dev->pusb_dev->speed == USB_SPEED_HIGH) {
549 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
550 priv->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
552 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
553 priv->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
557 priv->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
559 debug("rx_urb_size=%ld\n", (ulong)priv->rx_urb_size);
561 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
565 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
568 debug("Read Value from BURST_CAP after writing: 0x%08x\n", read_buf);
570 read_buf = DEFAULT_BULK_IN_DELAY;
571 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, read_buf);
575 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
578 debug("Read Value from BULK_IN_DLY after writing: "
579 "0x%08x\n", read_buf);
581 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
584 debug("Read Value from HW_CFG: 0x%08x\n", read_buf);
587 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
589 read_buf &= ~HW_CFG_RXDOFF_;
591 #define NET_IP_ALIGN 0
592 read_buf |= NET_IP_ALIGN << 9;
594 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
598 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
601 debug("Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
603 write_buf = 0xFFFFFFFF;
604 ret = smsc95xx_write_reg(dev, INT_STS, write_buf);
608 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
611 debug("ID_REV = 0x%08x\n", read_buf);
615 ret = smsc95xx_write_reg(dev, FLOW, write_buf);
619 read_buf = AFC_CFG_DEFAULT;
620 ret = smsc95xx_write_reg(dev, AFC_CFG, read_buf);
624 ret = smsc95xx_read_reg(dev, MAC_CR, &priv->mac_cr);
628 /* Init Rx. Set Vlan */
629 write_buf = (u32)ETH_P_8021Q;
630 ret = smsc95xx_write_reg(dev, VLAN1, write_buf);
634 /* Disable checksum offload engines */
635 ret = smsc95xx_set_csums(dev, 0, 0);
637 debug("Failed to set csum offload: %d\n", ret);
640 smsc95xx_set_multicast(dev);
642 if (smsc95xx_phy_initialize(dev) < 0)
644 ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
648 /* enable PHY interrupts */
649 read_buf |= INT_EP_CTL_PHY_INT_;
651 ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
655 smsc95xx_start_tx_path(dev);
656 smsc95xx_start_rx_path(dev);
660 link_detected = smsc95xx_mdio_read(dev, dev->phy_id, MII_BMSR)
662 if (!link_detected) {
664 printf("Waiting for Ethernet connection... ");
665 udelay(TIMEOUT_RESOLUTION * 1000);
666 timeout += TIMEOUT_RESOLUTION;
668 } while (!link_detected && timeout < PHY_CONNECT_TIMEOUT);
673 printf("unable to connect.\n");
679 static int smsc95xx_send(struct eth_device *eth, void* packet, int length)
681 struct ueth_data *dev = (struct ueth_data *)eth->priv;
686 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, msg,
687 PKTSIZE + sizeof(tx_cmd_a) + sizeof(tx_cmd_b));
689 debug("** %s(), len %d, buf %#x\n", __func__, length, (int)msg);
690 if (length > PKTSIZE)
693 tx_cmd_a = (u32)length | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_;
694 tx_cmd_b = (u32)length;
695 cpu_to_le32s(&tx_cmd_a);
696 cpu_to_le32s(&tx_cmd_b);
698 /* prepend cmd_a and cmd_b */
699 memcpy(msg, &tx_cmd_a, sizeof(tx_cmd_a));
700 memcpy(msg + sizeof(tx_cmd_a), &tx_cmd_b, sizeof(tx_cmd_b));
701 memcpy(msg + sizeof(tx_cmd_a) + sizeof(tx_cmd_b), (void *)packet,
703 err = usb_bulk_msg(dev->pusb_dev,
704 usb_sndbulkpipe(dev->pusb_dev, dev->ep_out),
706 length + sizeof(tx_cmd_a) + sizeof(tx_cmd_b),
708 USB_BULK_SEND_TIMEOUT);
709 debug("Tx: len = %u, actual = %u, err = %d\n",
710 length + sizeof(tx_cmd_a) + sizeof(tx_cmd_b),
715 static int smsc95xx_recv(struct eth_device *eth)
717 struct ueth_data *dev = (struct ueth_data *)eth->priv;
718 DEFINE_CACHE_ALIGN_BUFFER(unsigned char, recv_buf, AX_RX_URB_SIZE);
719 unsigned char *buf_ptr;
725 debug("** %s()\n", __func__);
726 err = usb_bulk_msg(dev->pusb_dev,
727 usb_rcvbulkpipe(dev->pusb_dev, dev->ep_in),
731 USB_BULK_RECV_TIMEOUT);
732 debug("Rx: len = %u, actual = %u, err = %d\n", AX_RX_URB_SIZE,
735 debug("Rx: failed to receive\n");
738 if (actual_len > AX_RX_URB_SIZE) {
739 debug("Rx: received too many bytes %d\n", actual_len);
744 while (actual_len > 0) {
746 * 1st 4 bytes contain the length of the actual data plus error
747 * info. Extract data length.
749 if (actual_len < sizeof(packet_len)) {
750 debug("Rx: incomplete packet length\n");
753 memcpy(&packet_len, buf_ptr, sizeof(packet_len));
754 le32_to_cpus(&packet_len);
755 if (packet_len & RX_STS_ES_) {
756 debug("Rx: Error header=%#x", packet_len);
759 packet_len = ((packet_len & RX_STS_FL_) >> 16);
761 if (packet_len > actual_len - sizeof(packet_len)) {
762 debug("Rx: too large packet: %d\n", packet_len);
766 /* Notify net stack */
767 NetReceive(buf_ptr + sizeof(packet_len), packet_len - 4);
769 /* Adjust for next iteration */
770 actual_len -= sizeof(packet_len) + packet_len;
771 buf_ptr += sizeof(packet_len) + packet_len;
772 cur_buf_align = (int)buf_ptr - (int)recv_buf;
774 if (cur_buf_align & 0x03) {
775 int align = 4 - (cur_buf_align & 0x03);
784 static void smsc95xx_halt(struct eth_device *eth)
786 debug("** %s()\n", __func__);
790 * SMSC probing functions
792 void smsc95xx_eth_before_probe(void)
797 struct smsc95xx_dongle {
798 unsigned short vendor;
799 unsigned short product;
802 static const struct smsc95xx_dongle smsc95xx_dongles[] = {
803 { 0x0424, 0xec00 }, /* LAN9512/LAN9514 Ethernet */
804 { 0x0424, 0x9500 }, /* LAN9500 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;