iPXE
smsc95xx.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <string.h>
00027 #include <unistd.h>
00028 #include <errno.h>
00029 #include <byteswap.h>
00030 #include <ipxe/ethernet.h>
00031 #include <ipxe/usb.h>
00032 #include <ipxe/usbnet.h>
00033 #include <ipxe/profile.h>
00034 #include <ipxe/base16.h>
00035 #include <ipxe/smbios.h>
00036 #include "smsc95xx.h"
00037 
00038 /** @file
00039  *
00040  * SMSC LAN95xx USB Ethernet driver
00041  *
00042  */
00043 
00044 /** Bulk IN completion profiler */
00045 static struct profiler smsc95xx_in_profiler __profiler =
00046         { .name = "smsc95xx.in" };
00047 
00048 /** Bulk OUT profiler */
00049 static struct profiler smsc95xx_out_profiler __profiler =
00050         { .name = "smsc95xx.out" };
00051 
00052 /******************************************************************************
00053  *
00054  * MAC address
00055  *
00056  ******************************************************************************
00057  */
00058 
00059 /**
00060  * Construct MAC address for Honeywell VM3
00061  *
00062  * @v smscusb           SMSC USB device
00063  * @ret rc              Return status code
00064  */
00065 static int smsc95xx_vm3_fetch_mac ( struct smscusb_device *smscusb ) {
00066         struct net_device *netdev = smscusb->netdev;
00067         struct smbios_structure structure;
00068         struct smbios_system_information system;
00069         struct {
00070                 char manufacturer[ 10 /* "Honeywell" + NUL */ ];
00071                 char product[ 4 /* "VM3" + NUL */ ];
00072                 char mac[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
00073         } strings;
00074         int len;
00075         int rc;
00076 
00077         /* Find system information */
00078         if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION, 0,
00079                                             &structure ) ) != 0 ) {
00080                 DBGC ( smscusb, "SMSC95XX %p could not find system "
00081                        "information: %s\n", smscusb, strerror ( rc ) );
00082                 return rc;
00083         }
00084 
00085         /* Read system information */
00086         if ( ( rc = read_smbios_structure ( &structure, &system,
00087                                             sizeof ( system ) ) ) != 0 ) {
00088                 DBGC ( smscusb, "SMSC95XX %p could not read system "
00089                        "information: %s\n", smscusb, strerror ( rc ) );
00090                 return rc;
00091         }
00092 
00093         /* NUL-terminate all strings to be fetched */
00094         memset ( &strings, 0, sizeof ( strings ) );
00095 
00096         /* Fetch system manufacturer name */
00097         len = read_smbios_string ( &structure, system.manufacturer,
00098                                    strings.manufacturer,
00099                                    ( sizeof ( strings.manufacturer ) - 1 ) );
00100         if ( len < 0 ) {
00101                 rc = len;
00102                 DBGC ( smscusb, "SMSC95XX %p could not read manufacturer "
00103                        "name: %s\n", smscusb, strerror ( rc ) );
00104                 return rc;
00105         }
00106 
00107         /* Fetch system product name */
00108         len = read_smbios_string ( &structure, system.product, strings.product,
00109                                    ( sizeof ( strings.product ) - 1 ) );
00110         if ( len < 0 ) {
00111                 rc = len;
00112                 DBGC ( smscusb, "SMSC95XX %p could not read product name: "
00113                        "%s\n", smscusb, strerror ( rc ) );
00114                 return rc;
00115         }
00116 
00117         /* Ignore non-VM3 devices */
00118         if ( ( strcmp ( strings.manufacturer, "Honeywell" ) != 0 ) ||
00119              ( strcmp ( strings.product, "VM3" ) != 0 ) )
00120                 return -ENOTTY;
00121 
00122         /* Find OEM strings */
00123         if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_OEM_STRINGS, 0,
00124                                             &structure ) ) != 0 ) {
00125                 DBGC ( smscusb, "SMSC95XX %p could not find OEM strings: %s\n",
00126                        smscusb, strerror ( rc ) );
00127                 return rc;
00128         }
00129 
00130         /* Fetch MAC address */
00131         len = read_smbios_string ( &structure, SMSC95XX_VM3_OEM_STRING_MAC,
00132                                    strings.mac, ( sizeof ( strings.mac ) - 1 ));
00133         if ( len < 0 ) {
00134                 rc = len;
00135                 DBGC ( smscusb, "SMSC95XX %p could not read OEM string: %s\n",
00136                        smscusb, strerror ( rc ) );
00137                 return rc;
00138         }
00139 
00140         /* Sanity check */
00141         if ( len != ( ( int ) ( sizeof ( strings.mac ) - 1 ) ) ) {
00142                 DBGC ( smscusb, "SMSC95XX %p invalid MAC address \"%s\"\n",
00143                        smscusb, strings.mac );
00144                 return -EINVAL;
00145         }
00146 
00147         /* Decode MAC address */
00148         len = base16_decode ( strings.mac, netdev->hw_addr, ETH_ALEN );
00149         if ( len < 0 ) {
00150                 rc = len;
00151                 DBGC ( smscusb, "SMSC95XX %p invalid MAC address \"%s\"\n",
00152                        smscusb, strings.mac );
00153                 return rc;
00154         }
00155 
00156         DBGC ( smscusb, "SMSC95XX %p using VM3 MAC %s\n",
00157                smscusb, eth_ntoa ( netdev->hw_addr ) );
00158         return 0;
00159 }
00160 
00161 /**
00162  * Fetch MAC address
00163  *
00164  * @v smscusb           SMSC USB device
00165  * @ret rc              Return status code
00166  */
00167 static int smsc95xx_fetch_mac ( struct smscusb_device *smscusb ) {
00168         struct net_device *netdev = smscusb->netdev;
00169         int rc;
00170 
00171         /* Read MAC address from EEPROM, if present */
00172         if ( ( rc = smscusb_eeprom_fetch_mac ( smscusb,
00173                                                SMSC95XX_E2P_BASE ) ) == 0 )
00174                 return 0;
00175 
00176         /* Construct MAC address for Honeywell VM3, if applicable */
00177         if ( ( rc = smsc95xx_vm3_fetch_mac ( smscusb ) ) == 0 )
00178                 return 0;
00179 
00180         /* Otherwise, generate a random MAC address */
00181         eth_random_addr ( netdev->hw_addr );
00182         DBGC ( smscusb, "SMSC95XX %p using random MAC %s\n",
00183                smscusb, eth_ntoa ( netdev->hw_addr ) );
00184         return 0;
00185 }
00186 
00187 /******************************************************************************
00188  *
00189  * Statistics (for debugging)
00190  *
00191  ******************************************************************************
00192  */
00193 
00194 /**
00195  * Dump statistics (for debugging)
00196  *
00197  * @v smscusb           SMSC USB device
00198  * @ret rc              Return status code
00199  */
00200 static int smsc95xx_dump_statistics ( struct smscusb_device *smscusb ) {
00201         struct smsc95xx_rx_statistics rx;
00202         struct smsc95xx_tx_statistics tx;
00203         int rc;
00204 
00205         /* Do nothing unless debugging is enabled */
00206         if ( ! DBG_LOG )
00207                 return 0;
00208 
00209         /* Get RX statistics */
00210         if ( ( rc = smscusb_get_statistics ( smscusb, SMSC95XX_RX_STATISTICS,
00211                                              &rx, sizeof ( rx ) ) ) != 0 ) {
00212                 DBGC ( smscusb, "SMSC95XX %p could not get RX statistics: "
00213                        "%s\n", smscusb, strerror ( rc ) );
00214                 return rc;
00215         }
00216 
00217         /* Get TX statistics */
00218         if ( ( rc = smscusb_get_statistics ( smscusb, SMSC95XX_TX_STATISTICS,
00219                                              &tx, sizeof ( tx ) ) ) != 0 ) {
00220                 DBGC ( smscusb, "SMSC95XX %p could not get TX statistics: "
00221                        "%s\n", smscusb, strerror ( rc ) );
00222                 return rc;
00223         }
00224 
00225         /* Dump statistics */
00226         DBGC ( smscusb, "SMSC95XX %p RX good %d bad %d crc %d und %d aln %d "
00227                "ovr %d lat %d drp %d\n", smscusb, le32_to_cpu ( rx.good ),
00228                le32_to_cpu ( rx.bad ), le32_to_cpu ( rx.crc ),
00229                le32_to_cpu ( rx.undersize ), le32_to_cpu ( rx.alignment ),
00230                le32_to_cpu ( rx.oversize ), le32_to_cpu ( rx.late ),
00231                le32_to_cpu ( rx.dropped ) );
00232         DBGC ( smscusb, "SMSC95XX %p TX good %d bad %d pau %d sgl %d mul %d "
00233                "exc %d lat %d und %d def %d car %d\n", smscusb,
00234                le32_to_cpu ( tx.good ), le32_to_cpu ( tx.bad ),
00235                le32_to_cpu ( tx.pause ), le32_to_cpu ( tx.single ),
00236                le32_to_cpu ( tx.multiple ), le32_to_cpu ( tx.excessive ),
00237                le32_to_cpu ( tx.late ), le32_to_cpu ( tx.underrun ),
00238                le32_to_cpu ( tx.deferred ), le32_to_cpu ( tx.carrier ) );
00239 
00240         return 0;
00241 }
00242 
00243 /******************************************************************************
00244  *
00245  * Device reset
00246  *
00247  ******************************************************************************
00248  */
00249 
00250 /**
00251  * Reset device
00252  *
00253  * @v smscusb           SMSC USB device
00254  * @ret rc              Return status code
00255  */
00256 static int smsc95xx_reset ( struct smscusb_device *smscusb ) {
00257         uint32_t hw_cfg;
00258         uint32_t led_gpio_cfg;
00259         int rc;
00260 
00261         /* Reset device */
00262         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_HW_CFG,
00263                                      SMSC95XX_HW_CFG_LRST ) ) != 0 )
00264                 return rc;
00265 
00266         /* Wait for reset to complete */
00267         udelay ( SMSC95XX_RESET_DELAY_US );
00268 
00269         /* Check that reset has completed */
00270         if ( ( rc = smscusb_readl ( smscusb, SMSC95XX_HW_CFG, &hw_cfg ) ) != 0 )
00271                 return rc;
00272         if ( hw_cfg & SMSC95XX_HW_CFG_LRST ) {
00273                 DBGC ( smscusb, "SMSC95XX %p failed to reset\n", smscusb );
00274                 return -ETIMEDOUT;
00275         }
00276 
00277         /* Configure LEDs */
00278         led_gpio_cfg = ( SMSC95XX_LED_GPIO_CFG_GPCTL2_NSPD_LED |
00279                          SMSC95XX_LED_GPIO_CFG_GPCTL1_NLNKA_LED |
00280                          SMSC95XX_LED_GPIO_CFG_GPCTL0_NFDX_LED );
00281         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_LED_GPIO_CFG,
00282                                      led_gpio_cfg ) ) != 0 ) {
00283                 DBGC ( smscusb, "SMSC95XX %p could not configure LEDs: %s\n",
00284                        smscusb, strerror ( rc ) );
00285                 /* Ignore error and continue */
00286         }
00287 
00288         return 0;
00289 }
00290 
00291 /******************************************************************************
00292  *
00293  * Endpoint operations
00294  *
00295  ******************************************************************************
00296  */
00297 
00298 /**
00299  * Complete bulk IN transfer
00300  *
00301  * @v ep                USB endpoint
00302  * @v iobuf             I/O buffer
00303  * @v rc                Completion status code
00304  */
00305 static void smsc95xx_in_complete ( struct usb_endpoint *ep,
00306                                    struct io_buffer *iobuf, int rc ) {
00307         struct smscusb_device *smscusb =
00308                 container_of ( ep, struct smscusb_device, usbnet.in );
00309         struct net_device *netdev = smscusb->netdev;
00310         struct smsc95xx_rx_header *header;
00311 
00312         /* Profile completions */
00313         profile_start ( &smsc95xx_in_profiler );
00314 
00315         /* Ignore packets cancelled when the endpoint closes */
00316         if ( ! ep->open ) {
00317                 free_iob ( iobuf );
00318                 return;
00319         }
00320 
00321         /* Record USB errors against the network device */
00322         if ( rc != 0 ) {
00323                 DBGC ( smscusb, "SMSC95XX %p bulk IN failed: %s\n",
00324                        smscusb, strerror ( rc ) );
00325                 goto err;
00326         }
00327 
00328         /* Sanity check */
00329         if ( iob_len ( iobuf ) < ( sizeof ( *header ) + 4 /* CRC */ ) ) {
00330                 DBGC ( smscusb, "SMSC95XX %p underlength bulk IN\n",
00331                        smscusb );
00332                 DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
00333                 rc = -EINVAL;
00334                 goto err;
00335         }
00336 
00337         /* Strip header and CRC */
00338         header = iobuf->data;
00339         iob_pull ( iobuf, sizeof ( *header ) );
00340         iob_unput ( iobuf, 4 /* CRC */ );
00341 
00342         /* Check for errors */
00343         if ( header->command & cpu_to_le32 ( SMSC95XX_RX_RUNT |
00344                                              SMSC95XX_RX_LATE |
00345                                              SMSC95XX_RX_CRC ) ) {
00346                 DBGC ( smscusb, "SMSC95XX %p receive error (%08x):\n",
00347                        smscusb, le32_to_cpu ( header->command ) );
00348                 DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
00349                 rc = -EIO;
00350                 goto err;
00351         }
00352 
00353         /* Hand off to network stack */
00354         netdev_rx ( netdev, iob_disown ( iobuf ) );
00355 
00356         profile_stop ( &smsc95xx_in_profiler );
00357         return;
00358 
00359  err:
00360         /* Hand off to network stack */
00361         netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
00362 }
00363 
00364 /** Bulk IN endpoint operations */
00365 static struct usb_endpoint_driver_operations smsc95xx_in_operations = {
00366         .complete = smsc95xx_in_complete,
00367 };
00368 
00369 /**
00370  * Transmit packet
00371  *
00372  * @v smscusb           SMSC USB device
00373  * @v iobuf             I/O buffer
00374  * @ret rc              Return status code
00375  */
00376 static int smsc95xx_out_transmit ( struct smscusb_device *smscusb,
00377                                    struct io_buffer *iobuf ) {
00378         struct smsc95xx_tx_header *header;
00379         size_t len = iob_len ( iobuf );
00380         int rc;
00381 
00382         /* Profile transmissions */
00383         profile_start ( &smsc95xx_out_profiler );
00384 
00385         /* Prepend header */
00386         if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 )
00387                 return rc;
00388         header = iob_push ( iobuf, sizeof ( *header ) );
00389         header->command = cpu_to_le32 ( SMSC95XX_TX_FIRST | SMSC95XX_TX_LAST |
00390                                         SMSC95XX_TX_LEN ( len ) );
00391         header->len = cpu_to_le32 ( len );
00392 
00393         /* Enqueue I/O buffer */
00394         if ( ( rc = usb_stream ( &smscusb->usbnet.out, iobuf, 0 ) ) != 0 )
00395                 return rc;
00396 
00397         profile_stop ( &smsc95xx_out_profiler );
00398         return 0;
00399 }
00400 
00401 /******************************************************************************
00402  *
00403  * Network device interface
00404  *
00405  ******************************************************************************
00406  */
00407 
00408 /**
00409  * Open network device
00410  *
00411  * @v netdev            Network device
00412  * @ret rc              Return status code
00413  */
00414 static int smsc95xx_open ( struct net_device *netdev ) {
00415         struct smscusb_device *smscusb = netdev->priv;
00416         int rc;
00417 
00418         /* Clear stored interrupt status */
00419         smscusb->int_sts = 0;
00420 
00421         /* Configure bulk IN empty response */
00422         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_HW_CFG,
00423                                      SMSC95XX_HW_CFG_BIR ) ) != 0 )
00424                 goto err_hw_cfg;
00425 
00426         /* Open USB network device */
00427         if ( ( rc = usbnet_open ( &smscusb->usbnet ) ) != 0 ) {
00428                 DBGC ( smscusb, "SMSC95XX %p could not open: %s\n",
00429                        smscusb, strerror ( rc ) );
00430                 goto err_open;
00431         }
00432 
00433         /* Configure interrupt endpoint */
00434         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_INT_EP_CTL,
00435                                      ( SMSC95XX_INT_EP_CTL_RXDF_EN |
00436                                        SMSC95XX_INT_EP_CTL_PHY_EN ) ) ) != 0 )
00437                 goto err_int_ep_ctl;
00438 
00439         /* Configure bulk IN delay */
00440         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_BULK_IN_DLY,
00441                                      SMSC95XX_BULK_IN_DLY_SET ( 0 ) ) ) != 0 )
00442                 goto err_bulk_in_dly;
00443 
00444         /* Configure MAC */
00445         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_MAC_CR,
00446                                      ( SMSC95XX_MAC_CR_RXALL |
00447                                        SMSC95XX_MAC_CR_FDPX |
00448                                        SMSC95XX_MAC_CR_MCPAS |
00449                                        SMSC95XX_MAC_CR_PRMS |
00450                                        SMSC95XX_MAC_CR_PASSBAD |
00451                                        SMSC95XX_MAC_CR_TXEN |
00452                                        SMSC95XX_MAC_CR_RXEN ) ) ) != 0 )
00453                 goto err_mac_cr;
00454 
00455         /* Configure transmit datapath */
00456         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_TX_CFG,
00457                                      SMSC95XX_TX_CFG_ON ) ) != 0 )
00458                 goto err_tx_cfg;
00459 
00460         /* Set MAC address */
00461         if ( ( rc = smscusb_set_address ( smscusb, SMSC95XX_ADDR_BASE ) ) != 0 )
00462                 goto err_set_address;
00463 
00464         /* Enable PHY interrupts and update link status */
00465         if ( ( rc = smscusb_mii_open ( smscusb, SMSC95XX_MII_PHY_INTR_MASK,
00466                                        ( SMSC95XX_PHY_INTR_ANEG_DONE |
00467                                          SMSC95XX_PHY_INTR_LINK_DOWN ) ) ) != 0)
00468                 goto err_mii_open;
00469 
00470         return 0;
00471 
00472  err_mii_open:
00473  err_set_address:
00474  err_tx_cfg:
00475  err_mac_cr:
00476  err_bulk_in_dly:
00477  err_int_ep_ctl:
00478         usbnet_close ( &smscusb->usbnet );
00479  err_open:
00480  err_hw_cfg:
00481         smsc95xx_reset ( smscusb );
00482         return rc;
00483 }
00484 
00485 /**
00486  * Close network device
00487  *
00488  * @v netdev            Network device
00489  */
00490 static void smsc95xx_close ( struct net_device *netdev ) {
00491         struct smscusb_device *smscusb = netdev->priv;
00492 
00493         /* Close USB network device */
00494         usbnet_close ( &smscusb->usbnet );
00495 
00496         /* Dump statistics (for debugging) */
00497         smsc95xx_dump_statistics ( smscusb );
00498 
00499         /* Reset device */
00500         smsc95xx_reset ( smscusb );
00501 }
00502 
00503 /**
00504  * Transmit packet
00505  *
00506  * @v netdev            Network device
00507  * @v iobuf             I/O buffer
00508  * @ret rc              Return status code
00509  */
00510 static int smsc95xx_transmit ( struct net_device *netdev,
00511                                struct io_buffer *iobuf ) {
00512         struct smscusb_device *smscusb = netdev->priv;
00513         int rc;
00514 
00515         /* Transmit packet */
00516         if ( ( rc = smsc95xx_out_transmit ( smscusb, iobuf ) ) != 0 )
00517                 return rc;
00518 
00519         return 0;
00520 }
00521 
00522 /**
00523  * Poll for completed and received packets
00524  *
00525  * @v netdev            Network device
00526  */
00527 static void smsc95xx_poll ( struct net_device *netdev ) {
00528         struct smscusb_device *smscusb = netdev->priv;
00529         uint32_t int_sts;
00530         int rc;
00531 
00532         /* Poll USB bus */
00533         usb_poll ( smscusb->bus );
00534 
00535         /* Refill endpoints */
00536         if ( ( rc = usbnet_refill ( &smscusb->usbnet ) ) != 0 )
00537                 netdev_rx_err ( netdev, NULL, rc );
00538 
00539         /* Do nothing more unless there are interrupts to handle */
00540         int_sts = smscusb->int_sts;
00541         if ( ! int_sts )
00542                 return;
00543 
00544         /* Check link status if applicable */
00545         if ( int_sts & SMSC95XX_INT_STS_PHY_INT ) {
00546                 smscusb_mii_check_link ( smscusb );
00547                 int_sts &= ~SMSC95XX_INT_STS_PHY_INT;
00548         }
00549 
00550         /* Record RX FIFO overflow if applicable */
00551         if ( int_sts & SMSC95XX_INT_STS_RXDF_INT ) {
00552                 DBGC2 ( smscusb, "SMSC95XX %p RX FIFO overflowed\n",
00553                         smscusb );
00554                 netdev_rx_err ( netdev, NULL, -ENOBUFS );
00555                 int_sts &= ~SMSC95XX_INT_STS_RXDF_INT;
00556         }
00557 
00558         /* Check for unexpected interrupts */
00559         if ( int_sts ) {
00560                 DBGC ( smscusb, "SMSC95XX %p unexpected interrupt %#08x\n",
00561                        smscusb, int_sts );
00562                 netdev_rx_err ( netdev, NULL, -ENOTTY );
00563         }
00564 
00565         /* Clear interrupts */
00566         if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_INT_STS,
00567                                      smscusb->int_sts ) ) != 0 )
00568                 netdev_rx_err ( netdev, NULL, rc );
00569         smscusb->int_sts = 0;
00570 }
00571 
00572 /** SMSC95xx network device operations */
00573 static struct net_device_operations smsc95xx_operations = {
00574         .open           = smsc95xx_open,
00575         .close          = smsc95xx_close,
00576         .transmit       = smsc95xx_transmit,
00577         .poll           = smsc95xx_poll,
00578 };
00579 
00580 /******************************************************************************
00581  *
00582  * USB interface
00583  *
00584  ******************************************************************************
00585  */
00586 
00587 /**
00588  * Probe device
00589  *
00590  * @v func              USB function
00591  * @v config            Configuration descriptor
00592  * @ret rc              Return status code
00593  */
00594 static int smsc95xx_probe ( struct usb_function *func,
00595                             struct usb_configuration_descriptor *config ) {
00596         struct net_device *netdev;
00597         struct smscusb_device *smscusb;
00598         int rc;
00599 
00600         /* Allocate and initialise structure */
00601         netdev = alloc_etherdev ( sizeof ( *smscusb ) );
00602         if ( ! netdev ) {
00603                 rc = -ENOMEM;
00604                 goto err_alloc;
00605         }
00606         netdev_init ( netdev, &smsc95xx_operations );
00607         netdev->dev = &func->dev;
00608         smscusb = netdev->priv;
00609         memset ( smscusb, 0, sizeof ( *smscusb ) );
00610         smscusb_init ( smscusb, netdev, func, &smsc95xx_in_operations );
00611         smscusb_mii_init ( smscusb, SMSC95XX_MII_BASE,
00612                            SMSC95XX_MII_PHY_INTR_SOURCE );
00613         usb_refill_init ( &smscusb->usbnet.in,
00614                           ( sizeof ( struct smsc95xx_tx_header ) -
00615                             sizeof ( struct smsc95xx_rx_header ) ),
00616                           SMSC95XX_IN_MTU, SMSC95XX_IN_MAX_FILL );
00617         DBGC ( smscusb, "SMSC95XX %p on %s\n", smscusb, func->name );
00618 
00619         /* Describe USB network device */
00620         if ( ( rc = usbnet_describe ( &smscusb->usbnet, config ) ) != 0 ) {
00621                 DBGC ( smscusb, "SMSC95XX %p could not describe: %s\n",
00622                        smscusb, strerror ( rc ) );
00623                 goto err_describe;
00624         }
00625 
00626         /* Reset device */
00627         if ( ( rc = smsc95xx_reset ( smscusb ) ) != 0 )
00628                 goto err_reset;
00629 
00630         /* Read MAC address */
00631         if ( ( rc = smsc95xx_fetch_mac ( smscusb ) ) != 0 )
00632                 goto err_fetch_mac;
00633 
00634         /* Register network device */
00635         if ( ( rc = register_netdev ( netdev ) ) != 0 )
00636                 goto err_register;
00637 
00638         usb_func_set_drvdata ( func, netdev );
00639         return 0;
00640 
00641         unregister_netdev ( netdev );
00642  err_register:
00643  err_fetch_mac:
00644  err_reset:
00645  err_describe:
00646         netdev_nullify ( netdev );
00647         netdev_put ( netdev );
00648  err_alloc:
00649         return rc;
00650 }
00651 
00652 /**
00653  * Remove device
00654  *
00655  * @v func              USB function
00656  */
00657 static void smsc95xx_remove ( struct usb_function *func ) {
00658         struct net_device *netdev = usb_func_get_drvdata ( func );
00659 
00660         unregister_netdev ( netdev );
00661         netdev_nullify ( netdev );
00662         netdev_put ( netdev );
00663 }
00664 
00665 /** SMSC95xx device IDs */
00666 static struct usb_device_id smsc95xx_ids[] = {
00667         {
00668                 .name = "smsc9500",
00669                 .vendor = 0x0424,
00670                 .product = 0x9500,
00671         },
00672         {
00673                 .name = "smsc9505",
00674                 .vendor = 0x0424,
00675                 .product = 0x9505,
00676         },
00677         {
00678                 .name = "smsc9500a",
00679                 .vendor = 0x0424,
00680                 .product = 0x9e00,
00681         },
00682         {
00683                 .name = "smsc9505a",
00684                 .vendor = 0x0424,
00685                 .product = 0x9e01,
00686         },
00687         {
00688                 .name = "smsc9514",
00689                 .vendor = 0x0424,
00690                 .product = 0xec00,
00691         },
00692         {
00693                 .name = "smsc9500-s",
00694                 .vendor = 0x0424,
00695                 .product = 0x9900,
00696         },
00697         {
00698                 .name = "smsc9505-s",
00699                 .vendor = 0x0424,
00700                 .product = 0x9901,
00701         },
00702         {
00703                 .name = "smsc9500a-s",
00704                 .vendor = 0x0424,
00705                 .product = 0x9902,
00706         },
00707         {
00708                 .name = "smsc9505a-s",
00709                 .vendor = 0x0424,
00710                 .product = 0x9903,
00711         },
00712         {
00713                 .name = "smsc9514-s",
00714                 .vendor = 0x0424,
00715                 .product = 0x9904,
00716         },
00717         {
00718                 .name = "smsc9500a-h",
00719                 .vendor = 0x0424,
00720                 .product = 0x9905,
00721         },
00722         {
00723                 .name = "smsc9505a-h",
00724                 .vendor = 0x0424,
00725                 .product = 0x9906,
00726         },
00727         {
00728                 .name = "smsc9500-2",
00729                 .vendor = 0x0424,
00730                 .product = 0x9907,
00731         },
00732         {
00733                 .name = "smsc9500a-2",
00734                 .vendor = 0x0424,
00735                 .product = 0x9908,
00736         },
00737         {
00738                 .name = "smsc9514-2",
00739                 .vendor = 0x0424,
00740                 .product = 0x9909,
00741         },
00742         {
00743                 .name = "smsc9530",
00744                 .vendor = 0x0424,
00745                 .product = 0x9530,
00746         },
00747         {
00748                 .name = "smsc9730",
00749                 .vendor = 0x0424,
00750                 .product = 0x9730,
00751         },
00752         {
00753                 .name = "smsc89530",
00754                 .vendor = 0x0424,
00755                 .product = 0x9e08,
00756         },
00757 };
00758 
00759 /** SMSC LAN95xx driver */
00760 struct usb_driver smsc95xx_driver __usb_driver = {
00761         .ids = smsc95xx_ids,
00762         .id_count = ( sizeof ( smsc95xx_ids ) / sizeof ( smsc95xx_ids[0] ) ),
00763         .class = USB_CLASS_ID ( 0xff, 0x00, 0xff ),
00764         .score = USB_SCORE_NORMAL,
00765         .probe = smsc95xx_probe,
00766         .remove = smsc95xx_remove,
00767 };