You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smsc95xx.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <string.h>
  25. #include <unistd.h>
  26. #include <errno.h>
  27. #include <byteswap.h>
  28. #include <ipxe/ethernet.h>
  29. #include <ipxe/usb.h>
  30. #include <ipxe/usbnet.h>
  31. #include <ipxe/profile.h>
  32. #include <ipxe/base16.h>
  33. #include <ipxe/smbios.h>
  34. #include "smsc95xx.h"
  35. /** @file
  36. *
  37. * SMSC LAN95xx USB Ethernet driver
  38. *
  39. */
  40. /** Bulk IN completion profiler */
  41. static struct profiler smsc95xx_in_profiler __profiler =
  42. { .name = "smsc95xx.in" };
  43. /** Bulk OUT profiler */
  44. static struct profiler smsc95xx_out_profiler __profiler =
  45. { .name = "smsc95xx.out" };
  46. /******************************************************************************
  47. *
  48. * MAC address
  49. *
  50. ******************************************************************************
  51. */
  52. /**
  53. * Construct MAC address for Honeywell VM3
  54. *
  55. * @v smscusb SMSC USB device
  56. * @ret rc Return status code
  57. */
  58. static int smsc95xx_vm3_fetch_mac ( struct smscusb_device *smscusb ) {
  59. struct net_device *netdev = smscusb->netdev;
  60. struct smbios_structure structure;
  61. struct smbios_system_information system;
  62. struct {
  63. char manufacturer[ 10 /* "Honeywell" + NUL */ ];
  64. char product[ 4 /* "VM3" + NUL */ ];
  65. char mac[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
  66. } strings;
  67. int len;
  68. int rc;
  69. /* Find system information */
  70. if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION, 0,
  71. &structure ) ) != 0 ) {
  72. DBGC ( smscusb, "SMSC95XX %p could not find system "
  73. "information: %s\n", smscusb, strerror ( rc ) );
  74. return rc;
  75. }
  76. /* Read system information */
  77. if ( ( rc = read_smbios_structure ( &structure, &system,
  78. sizeof ( system ) ) ) != 0 ) {
  79. DBGC ( smscusb, "SMSC95XX %p could not read system "
  80. "information: %s\n", smscusb, strerror ( rc ) );
  81. return rc;
  82. }
  83. /* NUL-terminate all strings to be fetched */
  84. memset ( &strings, 0, sizeof ( strings ) );
  85. /* Fetch system manufacturer name */
  86. len = read_smbios_string ( &structure, system.manufacturer,
  87. strings.manufacturer,
  88. ( sizeof ( strings.manufacturer ) - 1 ) );
  89. if ( len < 0 ) {
  90. rc = len;
  91. DBGC ( smscusb, "SMSC95XX %p could not read manufacturer "
  92. "name: %s\n", smscusb, strerror ( rc ) );
  93. return rc;
  94. }
  95. /* Fetch system product name */
  96. len = read_smbios_string ( &structure, system.product, strings.product,
  97. ( sizeof ( strings.product ) - 1 ) );
  98. if ( len < 0 ) {
  99. rc = len;
  100. DBGC ( smscusb, "SMSC95XX %p could not read product name: "
  101. "%s\n", smscusb, strerror ( rc ) );
  102. return rc;
  103. }
  104. /* Ignore non-VM3 devices */
  105. if ( ( strcmp ( strings.manufacturer, "Honeywell" ) != 0 ) ||
  106. ( strcmp ( strings.product, "VM3" ) != 0 ) )
  107. return -ENOTTY;
  108. /* Find OEM strings */
  109. if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_OEM_STRINGS, 0,
  110. &structure ) ) != 0 ) {
  111. DBGC ( smscusb, "SMSC95XX %p could not find OEM strings: %s\n",
  112. smscusb, strerror ( rc ) );
  113. return rc;
  114. }
  115. /* Fetch MAC address */
  116. len = read_smbios_string ( &structure, SMSC95XX_VM3_OEM_STRING_MAC,
  117. strings.mac, ( sizeof ( strings.mac ) - 1 ));
  118. if ( len < 0 ) {
  119. rc = len;
  120. DBGC ( smscusb, "SMSC95XX %p could not read OEM string: %s\n",
  121. smscusb, strerror ( rc ) );
  122. return rc;
  123. }
  124. /* Sanity check */
  125. if ( len != ( ( int ) ( sizeof ( strings.mac ) - 1 ) ) ) {
  126. DBGC ( smscusb, "SMSC95XX %p invalid MAC address \"%s\"\n",
  127. smscusb, strings.mac );
  128. return -EINVAL;
  129. }
  130. /* Decode MAC address */
  131. len = base16_decode ( strings.mac, netdev->hw_addr, ETH_ALEN );
  132. if ( len < 0 ) {
  133. rc = len;
  134. DBGC ( smscusb, "SMSC95XX %p invalid MAC address \"%s\"\n",
  135. smscusb, strings.mac );
  136. return rc;
  137. }
  138. DBGC ( smscusb, "SMSC95XX %p using VM3 MAC %s\n",
  139. smscusb, eth_ntoa ( netdev->hw_addr ) );
  140. return 0;
  141. }
  142. /**
  143. * Fetch MAC address
  144. *
  145. * @v smscusb SMSC USB device
  146. * @ret rc Return status code
  147. */
  148. static int smsc95xx_fetch_mac ( struct smscusb_device *smscusb ) {
  149. struct net_device *netdev = smscusb->netdev;
  150. int rc;
  151. /* Read MAC address from EEPROM, if present */
  152. if ( ( rc = smscusb_eeprom_fetch_mac ( smscusb,
  153. SMSC95XX_E2P_BASE ) ) == 0 )
  154. return 0;
  155. /* Read MAC address from device tree, if present */
  156. if ( ( rc = smscusb_fdt_fetch_mac ( smscusb ) ) == 0 )
  157. return 0;
  158. /* Construct MAC address for Honeywell VM3, if applicable */
  159. if ( ( rc = smsc95xx_vm3_fetch_mac ( smscusb ) ) == 0 )
  160. return 0;
  161. /* Otherwise, generate a random MAC address */
  162. eth_random_addr ( netdev->hw_addr );
  163. DBGC ( smscusb, "SMSC95XX %p using random MAC %s\n",
  164. smscusb, eth_ntoa ( netdev->hw_addr ) );
  165. return 0;
  166. }
  167. /******************************************************************************
  168. *
  169. * Statistics (for debugging)
  170. *
  171. ******************************************************************************
  172. */
  173. /**
  174. * Dump statistics (for debugging)
  175. *
  176. * @v smscusb SMSC USB device
  177. * @ret rc Return status code
  178. */
  179. static int smsc95xx_dump_statistics ( struct smscusb_device *smscusb ) {
  180. struct smsc95xx_rx_statistics rx;
  181. struct smsc95xx_tx_statistics tx;
  182. int rc;
  183. /* Do nothing unless debugging is enabled */
  184. if ( ! DBG_LOG )
  185. return 0;
  186. /* Get RX statistics */
  187. if ( ( rc = smscusb_get_statistics ( smscusb, SMSC95XX_RX_STATISTICS,
  188. &rx, sizeof ( rx ) ) ) != 0 ) {
  189. DBGC ( smscusb, "SMSC95XX %p could not get RX statistics: "
  190. "%s\n", smscusb, strerror ( rc ) );
  191. return rc;
  192. }
  193. /* Get TX statistics */
  194. if ( ( rc = smscusb_get_statistics ( smscusb, SMSC95XX_TX_STATISTICS,
  195. &tx, sizeof ( tx ) ) ) != 0 ) {
  196. DBGC ( smscusb, "SMSC95XX %p could not get TX statistics: "
  197. "%s\n", smscusb, strerror ( rc ) );
  198. return rc;
  199. }
  200. /* Dump statistics */
  201. DBGC ( smscusb, "SMSC95XX %p RX good %d bad %d crc %d und %d aln %d "
  202. "ovr %d lat %d drp %d\n", smscusb, le32_to_cpu ( rx.good ),
  203. le32_to_cpu ( rx.bad ), le32_to_cpu ( rx.crc ),
  204. le32_to_cpu ( rx.undersize ), le32_to_cpu ( rx.alignment ),
  205. le32_to_cpu ( rx.oversize ), le32_to_cpu ( rx.late ),
  206. le32_to_cpu ( rx.dropped ) );
  207. DBGC ( smscusb, "SMSC95XX %p TX good %d bad %d pau %d sgl %d mul %d "
  208. "exc %d lat %d und %d def %d car %d\n", smscusb,
  209. le32_to_cpu ( tx.good ), le32_to_cpu ( tx.bad ),
  210. le32_to_cpu ( tx.pause ), le32_to_cpu ( tx.single ),
  211. le32_to_cpu ( tx.multiple ), le32_to_cpu ( tx.excessive ),
  212. le32_to_cpu ( tx.late ), le32_to_cpu ( tx.underrun ),
  213. le32_to_cpu ( tx.deferred ), le32_to_cpu ( tx.carrier ) );
  214. return 0;
  215. }
  216. /******************************************************************************
  217. *
  218. * Device reset
  219. *
  220. ******************************************************************************
  221. */
  222. /**
  223. * Reset device
  224. *
  225. * @v smscusb SMSC USB device
  226. * @ret rc Return status code
  227. */
  228. static int smsc95xx_reset ( struct smscusb_device *smscusb ) {
  229. uint32_t hw_cfg;
  230. uint32_t led_gpio_cfg;
  231. int rc;
  232. /* Reset device */
  233. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_HW_CFG,
  234. SMSC95XX_HW_CFG_LRST ) ) != 0 )
  235. return rc;
  236. /* Wait for reset to complete */
  237. udelay ( SMSC95XX_RESET_DELAY_US );
  238. /* Check that reset has completed */
  239. if ( ( rc = smscusb_readl ( smscusb, SMSC95XX_HW_CFG, &hw_cfg ) ) != 0 )
  240. return rc;
  241. if ( hw_cfg & SMSC95XX_HW_CFG_LRST ) {
  242. DBGC ( smscusb, "SMSC95XX %p failed to reset\n", smscusb );
  243. return -ETIMEDOUT;
  244. }
  245. /* Configure LEDs */
  246. led_gpio_cfg = ( SMSC95XX_LED_GPIO_CFG_GPCTL2_NSPD_LED |
  247. SMSC95XX_LED_GPIO_CFG_GPCTL1_NLNKA_LED |
  248. SMSC95XX_LED_GPIO_CFG_GPCTL0_NFDX_LED );
  249. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_LED_GPIO_CFG,
  250. led_gpio_cfg ) ) != 0 ) {
  251. DBGC ( smscusb, "SMSC95XX %p could not configure LEDs: %s\n",
  252. smscusb, strerror ( rc ) );
  253. /* Ignore error and continue */
  254. }
  255. return 0;
  256. }
  257. /******************************************************************************
  258. *
  259. * Endpoint operations
  260. *
  261. ******************************************************************************
  262. */
  263. /**
  264. * Complete bulk IN transfer
  265. *
  266. * @v ep USB endpoint
  267. * @v iobuf I/O buffer
  268. * @v rc Completion status code
  269. */
  270. static void smsc95xx_in_complete ( struct usb_endpoint *ep,
  271. struct io_buffer *iobuf, int rc ) {
  272. struct smscusb_device *smscusb =
  273. container_of ( ep, struct smscusb_device, usbnet.in );
  274. struct net_device *netdev = smscusb->netdev;
  275. struct smsc95xx_rx_header *header;
  276. /* Profile completions */
  277. profile_start ( &smsc95xx_in_profiler );
  278. /* Ignore packets cancelled when the endpoint closes */
  279. if ( ! ep->open ) {
  280. free_iob ( iobuf );
  281. return;
  282. }
  283. /* Record USB errors against the network device */
  284. if ( rc != 0 ) {
  285. DBGC ( smscusb, "SMSC95XX %p bulk IN failed: %s\n",
  286. smscusb, strerror ( rc ) );
  287. goto err;
  288. }
  289. /* Sanity check */
  290. if ( iob_len ( iobuf ) < ( sizeof ( *header ) + 4 /* CRC */ ) ) {
  291. DBGC ( smscusb, "SMSC95XX %p underlength bulk IN\n",
  292. smscusb );
  293. DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
  294. rc = -EINVAL;
  295. goto err;
  296. }
  297. /* Strip header and CRC */
  298. header = iobuf->data;
  299. iob_pull ( iobuf, sizeof ( *header ) );
  300. iob_unput ( iobuf, 4 /* CRC */ );
  301. /* Check for errors */
  302. if ( header->command & cpu_to_le32 ( SMSC95XX_RX_RUNT |
  303. SMSC95XX_RX_LATE |
  304. SMSC95XX_RX_CRC ) ) {
  305. DBGC ( smscusb, "SMSC95XX %p receive error (%08x):\n",
  306. smscusb, le32_to_cpu ( header->command ) );
  307. DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
  308. rc = -EIO;
  309. goto err;
  310. }
  311. /* Hand off to network stack */
  312. netdev_rx ( netdev, iob_disown ( iobuf ) );
  313. profile_stop ( &smsc95xx_in_profiler );
  314. return;
  315. err:
  316. /* Hand off to network stack */
  317. netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
  318. }
  319. /** Bulk IN endpoint operations */
  320. static struct usb_endpoint_driver_operations smsc95xx_in_operations = {
  321. .complete = smsc95xx_in_complete,
  322. };
  323. /**
  324. * Transmit packet
  325. *
  326. * @v smscusb SMSC USB device
  327. * @v iobuf I/O buffer
  328. * @ret rc Return status code
  329. */
  330. static int smsc95xx_out_transmit ( struct smscusb_device *smscusb,
  331. struct io_buffer *iobuf ) {
  332. struct smsc95xx_tx_header *header;
  333. size_t len = iob_len ( iobuf );
  334. int rc;
  335. /* Profile transmissions */
  336. profile_start ( &smsc95xx_out_profiler );
  337. /* Prepend header */
  338. if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 )
  339. return rc;
  340. header = iob_push ( iobuf, sizeof ( *header ) );
  341. header->command = cpu_to_le32 ( SMSC95XX_TX_FIRST | SMSC95XX_TX_LAST |
  342. SMSC95XX_TX_LEN ( len ) );
  343. header->len = cpu_to_le32 ( len );
  344. /* Enqueue I/O buffer */
  345. if ( ( rc = usb_stream ( &smscusb->usbnet.out, iobuf, 0 ) ) != 0 )
  346. return rc;
  347. profile_stop ( &smsc95xx_out_profiler );
  348. return 0;
  349. }
  350. /******************************************************************************
  351. *
  352. * Network device interface
  353. *
  354. ******************************************************************************
  355. */
  356. /**
  357. * Open network device
  358. *
  359. * @v netdev Network device
  360. * @ret rc Return status code
  361. */
  362. static int smsc95xx_open ( struct net_device *netdev ) {
  363. struct smscusb_device *smscusb = netdev->priv;
  364. int rc;
  365. /* Clear stored interrupt status */
  366. smscusb->int_sts = 0;
  367. /* Configure bulk IN empty response */
  368. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_HW_CFG,
  369. SMSC95XX_HW_CFG_BIR ) ) != 0 )
  370. goto err_hw_cfg;
  371. /* Open USB network device */
  372. if ( ( rc = usbnet_open ( &smscusb->usbnet ) ) != 0 ) {
  373. DBGC ( smscusb, "SMSC95XX %p could not open: %s\n",
  374. smscusb, strerror ( rc ) );
  375. goto err_open;
  376. }
  377. /* Configure interrupt endpoint */
  378. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_INT_EP_CTL,
  379. ( SMSC95XX_INT_EP_CTL_RXDF_EN |
  380. SMSC95XX_INT_EP_CTL_PHY_EN ) ) ) != 0 )
  381. goto err_int_ep_ctl;
  382. /* Configure bulk IN delay */
  383. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_BULK_IN_DLY,
  384. SMSC95XX_BULK_IN_DLY_SET ( 0 ) ) ) != 0 )
  385. goto err_bulk_in_dly;
  386. /* Configure MAC */
  387. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_MAC_CR,
  388. ( SMSC95XX_MAC_CR_RXALL |
  389. SMSC95XX_MAC_CR_FDPX |
  390. SMSC95XX_MAC_CR_MCPAS |
  391. SMSC95XX_MAC_CR_PRMS |
  392. SMSC95XX_MAC_CR_PASSBAD |
  393. SMSC95XX_MAC_CR_TXEN |
  394. SMSC95XX_MAC_CR_RXEN ) ) ) != 0 )
  395. goto err_mac_cr;
  396. /* Configure transmit datapath */
  397. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_TX_CFG,
  398. SMSC95XX_TX_CFG_ON ) ) != 0 )
  399. goto err_tx_cfg;
  400. /* Set MAC address */
  401. if ( ( rc = smscusb_set_address ( smscusb, SMSC95XX_ADDR_BASE ) ) != 0 )
  402. goto err_set_address;
  403. /* Enable PHY interrupts and update link status */
  404. if ( ( rc = smscusb_mii_open ( smscusb, SMSC95XX_MII_PHY_INTR_MASK,
  405. ( SMSC95XX_PHY_INTR_ANEG_DONE |
  406. SMSC95XX_PHY_INTR_LINK_DOWN ) ) ) != 0)
  407. goto err_mii_open;
  408. return 0;
  409. err_mii_open:
  410. err_set_address:
  411. err_tx_cfg:
  412. err_mac_cr:
  413. err_bulk_in_dly:
  414. err_int_ep_ctl:
  415. usbnet_close ( &smscusb->usbnet );
  416. err_open:
  417. err_hw_cfg:
  418. smsc95xx_reset ( smscusb );
  419. return rc;
  420. }
  421. /**
  422. * Close network device
  423. *
  424. * @v netdev Network device
  425. */
  426. static void smsc95xx_close ( struct net_device *netdev ) {
  427. struct smscusb_device *smscusb = netdev->priv;
  428. /* Close USB network device */
  429. usbnet_close ( &smscusb->usbnet );
  430. /* Dump statistics (for debugging) */
  431. smsc95xx_dump_statistics ( smscusb );
  432. /* Reset device */
  433. smsc95xx_reset ( smscusb );
  434. }
  435. /**
  436. * Transmit packet
  437. *
  438. * @v netdev Network device
  439. * @v iobuf I/O buffer
  440. * @ret rc Return status code
  441. */
  442. static int smsc95xx_transmit ( struct net_device *netdev,
  443. struct io_buffer *iobuf ) {
  444. struct smscusb_device *smscusb = netdev->priv;
  445. int rc;
  446. /* Transmit packet */
  447. if ( ( rc = smsc95xx_out_transmit ( smscusb, iobuf ) ) != 0 )
  448. return rc;
  449. return 0;
  450. }
  451. /**
  452. * Poll for completed and received packets
  453. *
  454. * @v netdev Network device
  455. */
  456. static void smsc95xx_poll ( struct net_device *netdev ) {
  457. struct smscusb_device *smscusb = netdev->priv;
  458. uint32_t int_sts;
  459. int rc;
  460. /* Poll USB bus */
  461. usb_poll ( smscusb->bus );
  462. /* Refill endpoints */
  463. if ( ( rc = usbnet_refill ( &smscusb->usbnet ) ) != 0 )
  464. netdev_rx_err ( netdev, NULL, rc );
  465. /* Do nothing more unless there are interrupts to handle */
  466. int_sts = smscusb->int_sts;
  467. if ( ! int_sts )
  468. return;
  469. /* Check link status if applicable */
  470. if ( int_sts & SMSC95XX_INT_STS_PHY_INT ) {
  471. smscusb_mii_check_link ( smscusb );
  472. int_sts &= ~SMSC95XX_INT_STS_PHY_INT;
  473. }
  474. /* Record RX FIFO overflow if applicable */
  475. if ( int_sts & SMSC95XX_INT_STS_RXDF_INT ) {
  476. DBGC2 ( smscusb, "SMSC95XX %p RX FIFO overflowed\n",
  477. smscusb );
  478. netdev_rx_err ( netdev, NULL, -ENOBUFS );
  479. int_sts &= ~SMSC95XX_INT_STS_RXDF_INT;
  480. }
  481. /* Check for unexpected interrupts */
  482. if ( int_sts ) {
  483. DBGC ( smscusb, "SMSC95XX %p unexpected interrupt %#08x\n",
  484. smscusb, int_sts );
  485. netdev_rx_err ( netdev, NULL, -ENOTTY );
  486. }
  487. /* Clear interrupts */
  488. if ( ( rc = smscusb_writel ( smscusb, SMSC95XX_INT_STS,
  489. smscusb->int_sts ) ) != 0 )
  490. netdev_rx_err ( netdev, NULL, rc );
  491. smscusb->int_sts = 0;
  492. }
  493. /** SMSC95xx network device operations */
  494. static struct net_device_operations smsc95xx_operations = {
  495. .open = smsc95xx_open,
  496. .close = smsc95xx_close,
  497. .transmit = smsc95xx_transmit,
  498. .poll = smsc95xx_poll,
  499. };
  500. /******************************************************************************
  501. *
  502. * USB interface
  503. *
  504. ******************************************************************************
  505. */
  506. /**
  507. * Probe device
  508. *
  509. * @v func USB function
  510. * @v config Configuration descriptor
  511. * @ret rc Return status code
  512. */
  513. static int smsc95xx_probe ( struct usb_function *func,
  514. struct usb_configuration_descriptor *config ) {
  515. struct net_device *netdev;
  516. struct smscusb_device *smscusb;
  517. int rc;
  518. /* Allocate and initialise structure */
  519. netdev = alloc_etherdev ( sizeof ( *smscusb ) );
  520. if ( ! netdev ) {
  521. rc = -ENOMEM;
  522. goto err_alloc;
  523. }
  524. netdev_init ( netdev, &smsc95xx_operations );
  525. netdev->dev = &func->dev;
  526. smscusb = netdev->priv;
  527. memset ( smscusb, 0, sizeof ( *smscusb ) );
  528. smscusb_init ( smscusb, netdev, func, &smsc95xx_in_operations );
  529. smscusb_mii_init ( smscusb, SMSC95XX_MII_BASE,
  530. SMSC95XX_MII_PHY_INTR_SOURCE );
  531. usb_refill_init ( &smscusb->usbnet.in,
  532. ( sizeof ( struct smsc95xx_tx_header ) -
  533. sizeof ( struct smsc95xx_rx_header ) ),
  534. SMSC95XX_IN_MTU, SMSC95XX_IN_MAX_FILL );
  535. DBGC ( smscusb, "SMSC95XX %p on %s\n", smscusb, func->name );
  536. /* Describe USB network device */
  537. if ( ( rc = usbnet_describe ( &smscusb->usbnet, config ) ) != 0 ) {
  538. DBGC ( smscusb, "SMSC95XX %p could not describe: %s\n",
  539. smscusb, strerror ( rc ) );
  540. goto err_describe;
  541. }
  542. /* Reset device */
  543. if ( ( rc = smsc95xx_reset ( smscusb ) ) != 0 )
  544. goto err_reset;
  545. /* Read MAC address */
  546. if ( ( rc = smsc95xx_fetch_mac ( smscusb ) ) != 0 )
  547. goto err_fetch_mac;
  548. /* Register network device */
  549. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  550. goto err_register;
  551. usb_func_set_drvdata ( func, netdev );
  552. return 0;
  553. unregister_netdev ( netdev );
  554. err_register:
  555. err_fetch_mac:
  556. err_reset:
  557. err_describe:
  558. netdev_nullify ( netdev );
  559. netdev_put ( netdev );
  560. err_alloc:
  561. return rc;
  562. }
  563. /**
  564. * Remove device
  565. *
  566. * @v func USB function
  567. */
  568. static void smsc95xx_remove ( struct usb_function *func ) {
  569. struct net_device *netdev = usb_func_get_drvdata ( func );
  570. unregister_netdev ( netdev );
  571. netdev_nullify ( netdev );
  572. netdev_put ( netdev );
  573. }
  574. /** SMSC95xx device IDs */
  575. static struct usb_device_id smsc95xx_ids[] = {
  576. {
  577. .name = "smsc9500",
  578. .vendor = 0x0424,
  579. .product = 0x9500,
  580. },
  581. {
  582. .name = "smsc9505",
  583. .vendor = 0x0424,
  584. .product = 0x9505,
  585. },
  586. {
  587. .name = "smsc9500a",
  588. .vendor = 0x0424,
  589. .product = 0x9e00,
  590. },
  591. {
  592. .name = "smsc9505a",
  593. .vendor = 0x0424,
  594. .product = 0x9e01,
  595. },
  596. {
  597. .name = "smsc9514",
  598. .vendor = 0x0424,
  599. .product = 0xec00,
  600. },
  601. {
  602. .name = "smsc9500-s",
  603. .vendor = 0x0424,
  604. .product = 0x9900,
  605. },
  606. {
  607. .name = "smsc9505-s",
  608. .vendor = 0x0424,
  609. .product = 0x9901,
  610. },
  611. {
  612. .name = "smsc9500a-s",
  613. .vendor = 0x0424,
  614. .product = 0x9902,
  615. },
  616. {
  617. .name = "smsc9505a-s",
  618. .vendor = 0x0424,
  619. .product = 0x9903,
  620. },
  621. {
  622. .name = "smsc9514-s",
  623. .vendor = 0x0424,
  624. .product = 0x9904,
  625. },
  626. {
  627. .name = "smsc9500a-h",
  628. .vendor = 0x0424,
  629. .product = 0x9905,
  630. },
  631. {
  632. .name = "smsc9505a-h",
  633. .vendor = 0x0424,
  634. .product = 0x9906,
  635. },
  636. {
  637. .name = "smsc9500-2",
  638. .vendor = 0x0424,
  639. .product = 0x9907,
  640. },
  641. {
  642. .name = "smsc9500a-2",
  643. .vendor = 0x0424,
  644. .product = 0x9908,
  645. },
  646. {
  647. .name = "smsc9514-2",
  648. .vendor = 0x0424,
  649. .product = 0x9909,
  650. },
  651. {
  652. .name = "smsc9530",
  653. .vendor = 0x0424,
  654. .product = 0x9530,
  655. },
  656. {
  657. .name = "smsc9730",
  658. .vendor = 0x0424,
  659. .product = 0x9730,
  660. },
  661. {
  662. .name = "smsc89530",
  663. .vendor = 0x0424,
  664. .product = 0x9e08,
  665. },
  666. };
  667. /** SMSC LAN95xx driver */
  668. struct usb_driver smsc95xx_driver __usb_driver = {
  669. .ids = smsc95xx_ids,
  670. .id_count = ( sizeof ( smsc95xx_ids ) / sizeof ( smsc95xx_ids[0] ) ),
  671. .class = USB_CLASS_ID ( 0xff, 0x00, 0xff ),
  672. .score = USB_SCORE_NORMAL,
  673. .probe = smsc95xx_probe,
  674. .remove = smsc95xx_remove,
  675. };