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

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