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_BUSY_))
271 } while (get_timer(start_time) < 1 * 1000 * 1000);
273 debug("EEPROM is busy\n");
277 static int smsc95xx_wait_eeprom(struct ueth_data *dev)
279 unsigned long start_time = get_timer(0);
283 smsc95xx_read_reg(dev, E2P_CMD, &val);
284 if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
287 } while (get_timer(start_time) < 1 * 1000 * 1000);
289 if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) {
290 debug("EEPROM read operation timeout\n");
296 static int smsc95xx_read_eeprom(struct ueth_data *dev, u32 offset, u32 length,
302 ret = smsc95xx_eeprom_confirm_not_busy(dev);
306 for (i = 0; i < length; i++) {
307 val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
308 smsc95xx_write_reg(dev, E2P_CMD, val);
310 ret = smsc95xx_wait_eeprom(dev);
314 smsc95xx_read_reg(dev, E2P_DATA, &val);
315 data[i] = val & 0xFF;
322 * mii_nway_restart - restart NWay (autonegotiation) for this interface
324 * Returns 0 on success, negative on error.
326 static int mii_nway_restart(struct ueth_data *dev)
331 /* if autoneg is off, it's an error */
332 bmcr = smsc95xx_mdio_read(dev, dev->phy_id, MII_BMCR);
334 if (bmcr & BMCR_ANENABLE) {
335 bmcr |= BMCR_ANRESTART;
336 smsc95xx_mdio_write(dev, dev->phy_id, MII_BMCR, bmcr);
342 static int smsc95xx_phy_initialize(struct ueth_data *dev)
344 smsc95xx_mdio_write(dev, dev->phy_id, MII_BMCR, BMCR_RESET);
345 smsc95xx_mdio_write(dev, dev->phy_id, MII_ADVERTISE,
346 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
347 ADVERTISE_PAUSE_ASYM);
350 smsc95xx_mdio_read(dev, dev->phy_id, PHY_INT_SRC);
352 smsc95xx_mdio_write(dev, dev->phy_id, PHY_INT_MASK,
353 PHY_INT_MASK_DEFAULT_);
354 mii_nway_restart(dev);
356 debug("phy initialised succesfully\n");
360 static int smsc95xx_init_mac_address(struct eth_device *eth,
361 struct ueth_data *dev)
363 /* try reading mac address from EEPROM */
364 if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
365 eth->enetaddr) == 0) {
366 if (is_valid_ether_addr(eth->enetaddr)) {
367 /* eeprom values are valid so use them */
368 debug("MAC address read from EEPROM\n");
374 * No eeprom, or eeprom values are invalid. Generating a random MAC
375 * address is not safe. Just return an error.
380 static int smsc95xx_write_hwaddr(struct eth_device *eth)
382 struct ueth_data *dev = (struct ueth_data *)eth->priv;
383 struct smsc95xx_private *priv = dev->dev_priv;
384 u32 addr_lo = __get_unaligned_le32(ð->enetaddr[0]);
385 u32 addr_hi = __get_unaligned_le16(ð->enetaddr[4]);
388 /* set hardware address */
389 debug("** %s()\n", __func__);
390 ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
394 ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
398 debug("MAC %pM\n", eth->enetaddr);
399 priv->have_hwaddr = 1;
403 /* Enable or disable Tx & Rx checksum offload engines */
404 static int smsc95xx_set_csums(struct ueth_data *dev,
405 int use_tx_csum, int use_rx_csum)
408 int ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
413 read_buf |= Tx_COE_EN_;
415 read_buf &= ~Tx_COE_EN_;
418 read_buf |= Rx_COE_EN_;
420 read_buf &= ~Rx_COE_EN_;
422 ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
426 debug("COE_CR = 0x%08x\n", read_buf);
430 static void smsc95xx_set_multicast(struct ueth_data *dev)
432 struct smsc95xx_private *priv = dev->dev_priv;
434 /* No multicast in u-boot */
435 priv->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_);
438 /* starts the TX path */
439 static void smsc95xx_start_tx_path(struct ueth_data *dev)
441 struct smsc95xx_private *priv = dev->dev_priv;
444 /* Enable Tx at MAC */
445 priv->mac_cr |= MAC_CR_TXEN_;
447 smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
449 /* Enable Tx at SCSRs */
450 reg_val = TX_CFG_ON_;
451 smsc95xx_write_reg(dev, TX_CFG, reg_val);
454 /* Starts the Receive path */
455 static void smsc95xx_start_rx_path(struct ueth_data *dev)
457 struct smsc95xx_private *priv = dev->dev_priv;
459 priv->mac_cr |= MAC_CR_RXEN_;
460 smsc95xx_write_reg(dev, MAC_CR, priv->mac_cr);
466 static int smsc95xx_init(struct eth_device *eth, bd_t *bd)
473 struct ueth_data *dev = (struct ueth_data *)eth->priv;
474 struct smsc95xx_private *priv =
475 (struct smsc95xx_private *)dev->dev_priv;
476 #define TIMEOUT_RESOLUTION 50 /* ms */
479 debug("** %s()\n", __func__);
480 dev->phy_id = SMSC95XX_INTERNAL_PHY_ID; /* fixed phy id */
482 write_buf = HW_CFG_LRST_;
483 ret = smsc95xx_write_reg(dev, HW_CFG, write_buf);
489 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
494 } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
496 if (timeout >= 100) {
497 debug("timeout waiting for completion of Lite Reset\n");
501 write_buf = PM_CTL_PHY_RST_;
502 ret = smsc95xx_write_reg(dev, PM_CTRL, write_buf);
508 ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
513 } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
514 if (timeout >= 100) {
515 debug("timeout waiting for PHY Reset\n");
518 if (!priv->have_hwaddr && smsc95xx_init_mac_address(eth, dev) == 0)
519 priv->have_hwaddr = 1;
520 if (!priv->have_hwaddr) {
521 puts("Error: SMSC95xx: No MAC address set - set usbethaddr\n");
524 if (smsc95xx_write_hwaddr(eth) < 0)
527 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
530 debug("Read Value from HW_CFG : 0x%08x\n", read_buf);
532 read_buf |= HW_CFG_BIR_;
533 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
537 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
540 debug("Read Value from HW_CFG after writing "
541 "HW_CFG_BIR_: 0x%08x\n", read_buf);
544 if (dev->pusb_dev->speed == USB_SPEED_HIGH) {
545 burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE;
546 priv->rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE;
548 burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE;
549 priv->rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE;
553 priv->rx_urb_size = MAX_SINGLE_PACKET_SIZE;
555 debug("rx_urb_size=%ld\n", (ulong)priv->rx_urb_size);
557 ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
561 ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
564 debug("Read Value from BURST_CAP after writing: 0x%08x\n", read_buf);
566 read_buf = DEFAULT_BULK_IN_DELAY;
567 ret = smsc95xx_write_reg(dev, BULK_IN_DLY, read_buf);
571 ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
574 debug("Read Value from BULK_IN_DLY after writing: "
575 "0x%08x\n", read_buf);
577 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
580 debug("Read Value from HW_CFG: 0x%08x\n", read_buf);
583 read_buf |= (HW_CFG_MEF_ | HW_CFG_BCE_);
585 read_buf &= ~HW_CFG_RXDOFF_;
587 #define NET_IP_ALIGN 0
588 read_buf |= NET_IP_ALIGN << 9;
590 ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
594 ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
597 debug("Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
599 write_buf = 0xFFFFFFFF;
600 ret = smsc95xx_write_reg(dev, INT_STS, write_buf);
604 ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
607 debug("ID_REV = 0x%08x\n", read_buf);
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 NetReceive(buf_ptr + sizeof(packet_len), packet_len - 4);
765 /* Adjust for next iteration */
766 actual_len -= sizeof(packet_len) + packet_len;
767 buf_ptr += sizeof(packet_len) + packet_len;
768 cur_buf_align = (int)buf_ptr - (int)recv_buf;
770 if (cur_buf_align & 0x03) {
771 int align = 4 - (cur_buf_align & 0x03);
780 static void smsc95xx_halt(struct eth_device *eth)
782 debug("** %s()\n", __func__);
786 * SMSC probing functions
788 void smsc95xx_eth_before_probe(void)
793 struct smsc95xx_dongle {
794 unsigned short vendor;
795 unsigned short product;
798 static const struct smsc95xx_dongle smsc95xx_dongles[] = {
799 { 0x0424, 0xec00 }, /* LAN9512/LAN9514 Ethernet */
800 { 0x0424, 0x9500 }, /* LAN9500 Ethernet */
801 { 0x0424, 0x9730 }, /* LAN9730 Ethernet (HSIC) */
802 { 0x0000, 0x0000 } /* END - Do not remove */
805 /* Probe to see if a new device is actually an SMSC device */
806 int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
807 struct ueth_data *ss)
809 struct usb_interface *iface;
810 struct usb_interface_descriptor *iface_desc;
813 /* let's examine the device now */
814 iface = &dev->config.if_desc[ifnum];
815 iface_desc = &dev->config.if_desc[ifnum].desc;
817 for (i = 0; smsc95xx_dongles[i].vendor != 0; i++) {
818 if (dev->descriptor.idVendor == smsc95xx_dongles[i].vendor &&
819 dev->descriptor.idProduct == smsc95xx_dongles[i].product)
820 /* Found a supported dongle */
823 if (smsc95xx_dongles[i].vendor == 0)
826 /* At this point, we know we've got a live one */
827 debug("\n\nUSB Ethernet device detected\n");
828 memset(ss, '\0', sizeof(struct ueth_data));
830 /* Initialize the ueth_data structure with some useful info */
833 ss->subclass = iface_desc->bInterfaceSubClass;
834 ss->protocol = iface_desc->bInterfaceProtocol;
837 * We are expecting a minimum of 3 endpoints - in, out (bulk), and int.
838 * We will ignore any others.
840 for (i = 0; i < iface_desc->bNumEndpoints; i++) {
841 /* is it an BULK endpoint? */
842 if ((iface->ep_desc[i].bmAttributes &
843 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) {
844 if (iface->ep_desc[i].bEndpointAddress & USB_DIR_IN)
846 iface->ep_desc[i].bEndpointAddress &
847 USB_ENDPOINT_NUMBER_MASK;
850 iface->ep_desc[i].bEndpointAddress &
851 USB_ENDPOINT_NUMBER_MASK;
854 /* is it an interrupt endpoint? */
855 if ((iface->ep_desc[i].bmAttributes &
856 USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) {
857 ss->ep_int = iface->ep_desc[i].bEndpointAddress &
858 USB_ENDPOINT_NUMBER_MASK;
859 ss->irqinterval = iface->ep_desc[i].bInterval;
862 debug("Endpoints In %d Out %d Int %d\n",
863 ss->ep_in, ss->ep_out, ss->ep_int);
865 /* Do some basic sanity checks, and bail if we find a problem */
866 if (usb_set_interface(dev, iface_desc->bInterfaceNumber, 0) ||
867 !ss->ep_in || !ss->ep_out || !ss->ep_int) {
868 debug("Problems with device\n");
871 dev->privptr = (void *)ss;
873 /* alloc driver private */
874 ss->dev_priv = calloc(1, sizeof(struct smsc95xx_private));
881 int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
882 struct eth_device *eth)
884 debug("** %s()\n", __func__);
886 debug("%s: missing parameter.\n", __func__);
889 sprintf(eth->name, "%s%d", SMSC95XX_BASE_NAME, curr_eth_dev++);
890 eth->init = smsc95xx_init;
891 eth->send = smsc95xx_send;
892 eth->recv = smsc95xx_recv;
893 eth->halt = smsc95xx_halt;
894 eth->write_hwaddr = smsc95xx_write_hwaddr;