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 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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. /** Interrupt completion profiler */
  41. static struct profiler smsc95xx_intr_profiler __profiler =
  42. { .name = "smsc95xx.intr" };
  43. /** Bulk IN completion profiler */
  44. static struct profiler smsc95xx_in_profiler __profiler =
  45. { .name = "smsc95xx.in" };
  46. /** Bulk OUT profiler */
  47. static struct profiler smsc95xx_out_profiler __profiler =
  48. { .name = "smsc95xx.out" };
  49. /******************************************************************************
  50. *
  51. * Register access
  52. *
  53. ******************************************************************************
  54. */
  55. /**
  56. * Write register (without byte-swapping)
  57. *
  58. * @v smsc95xx SMSC95xx device
  59. * @v address Register address
  60. * @v value Register value
  61. * @ret rc Return status code
  62. */
  63. static int smsc95xx_raw_writel ( struct smsc95xx_device *smsc95xx,
  64. unsigned int address, uint32_t value ) {
  65. int rc;
  66. /* Write register */
  67. DBGCIO ( smsc95xx, "SMSC95XX %p [%03x] <= %08x\n",
  68. smsc95xx, address, le32_to_cpu ( value ) );
  69. if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_REGISTER_WRITE, 0,
  70. address, &value, sizeof ( value ) ) ) != 0 ) {
  71. DBGC ( smsc95xx, "SMSC95XX %p could not write %03x: %s\n",
  72. smsc95xx, address, strerror ( rc ) );
  73. return rc;
  74. }
  75. return 0;
  76. }
  77. /**
  78. * Write register
  79. *
  80. * @v smsc95xx SMSC95xx device
  81. * @v address Register address
  82. * @v value Register value
  83. * @ret rc Return status code
  84. */
  85. static inline __attribute__ (( always_inline )) int
  86. smsc95xx_writel ( struct smsc95xx_device *smsc95xx, unsigned int address,
  87. uint32_t value ) {
  88. int rc;
  89. /* Write register */
  90. if ( ( rc = smsc95xx_raw_writel ( smsc95xx, address,
  91. cpu_to_le32 ( value ) ) ) != 0 )
  92. return rc;
  93. return 0;
  94. }
  95. /**
  96. * Read register (without byte-swapping)
  97. *
  98. * @v smsc95xx SMSC95xx device
  99. * @v address Register address
  100. * @ret value Register value
  101. * @ret rc Return status code
  102. */
  103. static int smsc95xx_raw_readl ( struct smsc95xx_device *smsc95xx,
  104. unsigned int address, uint32_t *value ) {
  105. int rc;
  106. /* Read register */
  107. if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_REGISTER_READ, 0,
  108. address, value, sizeof ( *value ) ) ) != 0 ) {
  109. DBGC ( smsc95xx, "SMSC95XX %p could not read %03x: %s\n",
  110. smsc95xx, address, strerror ( rc ) );
  111. return rc;
  112. }
  113. DBGCIO ( smsc95xx, "SMSC95XX %p [%03x] => %08x\n",
  114. smsc95xx, address, le32_to_cpu ( *value ) );
  115. return 0;
  116. }
  117. /**
  118. * Read register
  119. *
  120. * @v smsc95xx SMSC95xx device
  121. * @v address Register address
  122. * @ret value Register value
  123. * @ret rc Return status code
  124. */
  125. static inline __attribute__ (( always_inline )) int
  126. smsc95xx_readl ( struct smsc95xx_device *smsc95xx, unsigned int address,
  127. uint32_t *value ) {
  128. int rc;
  129. /* Read register */
  130. if ( ( rc = smsc95xx_raw_readl ( smsc95xx, address, value ) ) != 0 )
  131. return rc;
  132. le32_to_cpus ( value );
  133. return 0;
  134. }
  135. /******************************************************************************
  136. *
  137. * EEPROM access
  138. *
  139. ******************************************************************************
  140. */
  141. /**
  142. * Wait for EEPROM to become idle
  143. *
  144. * @v smsc95xx SMSC95xx device
  145. * @ret rc Return status code
  146. */
  147. static int smsc95xx_eeprom_wait ( struct smsc95xx_device *smsc95xx ) {
  148. uint32_t e2p_cmd;
  149. unsigned int i;
  150. int rc;
  151. /* Wait for EPC_BSY to become clear */
  152. for ( i = 0 ; i < SMSC95XX_EEPROM_MAX_WAIT_MS ; i++ ) {
  153. /* Read E2P_CMD and check EPC_BSY */
  154. if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_E2P_CMD,
  155. &e2p_cmd ) ) != 0 )
  156. return rc;
  157. if ( ! ( e2p_cmd & SMSC95XX_E2P_CMD_EPC_BSY ) )
  158. return 0;
  159. /* Delay */
  160. mdelay ( 1 );
  161. }
  162. DBGC ( smsc95xx, "SMSC95XX %p timed out waiting for EEPROM\n",
  163. smsc95xx );
  164. return -ETIMEDOUT;
  165. }
  166. /**
  167. * Read byte from EEPROM
  168. *
  169. * @v smsc95xx SMSC95xx device
  170. * @v address EEPROM address
  171. * @ret byte Byte read, or negative error
  172. */
  173. static int smsc95xx_eeprom_read_byte ( struct smsc95xx_device *smsc95xx,
  174. unsigned int address ) {
  175. uint32_t e2p_cmd;
  176. uint32_t e2p_data;
  177. int rc;
  178. /* Wait for EEPROM to become idle */
  179. if ( ( rc = smsc95xx_eeprom_wait ( smsc95xx ) ) != 0 )
  180. return rc;
  181. /* Initiate read command */
  182. e2p_cmd = ( SMSC95XX_E2P_CMD_EPC_BSY | SMSC95XX_E2P_CMD_EPC_CMD_READ |
  183. SMSC95XX_E2P_CMD_EPC_ADDR ( address ) );
  184. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_E2P_CMD,
  185. e2p_cmd ) ) != 0 )
  186. return rc;
  187. /* Wait for command to complete */
  188. if ( ( rc = smsc95xx_eeprom_wait ( smsc95xx ) ) != 0 )
  189. return rc;
  190. /* Read EEPROM data */
  191. if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_E2P_DATA,
  192. &e2p_data ) ) != 0 )
  193. return rc;
  194. return SMSC95XX_E2P_DATA_GET ( e2p_data );
  195. }
  196. /**
  197. * Read data from EEPROM
  198. *
  199. * @v smsc95xx SMSC95xx device
  200. * @v address EEPROM address
  201. * @v data Data buffer
  202. * @v len Length of data
  203. * @ret rc Return status code
  204. */
  205. static int smsc95xx_eeprom_read ( struct smsc95xx_device *smsc95xx,
  206. unsigned int address, void *data,
  207. size_t len ) {
  208. uint8_t *bytes;
  209. int byte;
  210. /* Read bytes */
  211. for ( bytes = data ; len-- ; address++, bytes++ ) {
  212. byte = smsc95xx_eeprom_read_byte ( smsc95xx, address );
  213. if ( byte < 0 )
  214. return byte;
  215. *bytes = byte;
  216. }
  217. return 0;
  218. }
  219. /******************************************************************************
  220. *
  221. * MAC address
  222. *
  223. ******************************************************************************
  224. */
  225. /**
  226. * Fetch MAC address from EEPROM
  227. *
  228. * @v smsc95xx SMSC95xx device
  229. * @v hw_addr Hardware address to fill in
  230. * @ret rc Return status code
  231. */
  232. static int smsc95xx_fetch_mac_eeprom ( struct smsc95xx_device *smsc95xx,
  233. uint8_t *hw_addr ) {
  234. int rc;
  235. /* Read MAC address from EEPROM */
  236. if ( ( rc = smsc95xx_eeprom_read ( smsc95xx, SMSC95XX_EEPROM_MAC,
  237. hw_addr, ETH_ALEN ) ) != 0 )
  238. return rc;
  239. /* Check that EEPROM is physically present */
  240. if ( ! is_valid_ether_addr ( hw_addr ) ) {
  241. DBGC ( smsc95xx, "SMSC95XX %p has no EEPROM (%s)\n",
  242. smsc95xx, eth_ntoa ( hw_addr ) );
  243. return -ENODEV;
  244. }
  245. DBGC ( smsc95xx, "SMSC95XX %p using EEPROM MAC %s\n",
  246. smsc95xx, eth_ntoa ( hw_addr ) );
  247. return 0;
  248. }
  249. /**
  250. * Construct MAC address for Honeywell VM3
  251. *
  252. * @v smsc95xx SMSC95xx device
  253. * @v hw_addr Hardware address to fill in
  254. * @ret rc Return status code
  255. */
  256. static int smsc95xx_fetch_mac_vm3 ( struct smsc95xx_device *smsc95xx,
  257. uint8_t *hw_addr ) {
  258. struct smbios_structure structure;
  259. struct smbios_system_information system;
  260. struct {
  261. char manufacturer[ 10 /* "Honeywell" + NUL */ ];
  262. char product[ 4 /* "VM3" + NUL */ ];
  263. char mac[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
  264. } strings;
  265. int len;
  266. int rc;
  267. /* Find system information */
  268. if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_SYSTEM_INFORMATION, 0,
  269. &structure ) ) != 0 ) {
  270. DBGC ( smsc95xx, "SMSC95XX %p could not find system "
  271. "information: %s\n", smsc95xx, strerror ( rc ) );
  272. return rc;
  273. }
  274. /* Read system information */
  275. if ( ( rc = read_smbios_structure ( &structure, &system,
  276. sizeof ( system ) ) ) != 0 ) {
  277. DBGC ( smsc95xx, "SMSC95XX %p could not read system "
  278. "information: %s\n", smsc95xx, strerror ( rc ) );
  279. return rc;
  280. }
  281. /* NUL-terminate all strings to be fetched */
  282. memset ( &strings, 0, sizeof ( strings ) );
  283. /* Fetch system manufacturer name */
  284. len = read_smbios_string ( &structure, system.manufacturer,
  285. strings.manufacturer,
  286. ( sizeof ( strings.manufacturer ) - 1 ) );
  287. if ( len < 0 ) {
  288. rc = len;
  289. DBGC ( smsc95xx, "SMSC95XX %p could not read manufacturer "
  290. "name: %s\n", smsc95xx, strerror ( rc ) );
  291. return rc;
  292. }
  293. /* Fetch system product name */
  294. len = read_smbios_string ( &structure, system.product, strings.product,
  295. ( sizeof ( strings.product ) - 1 ) );
  296. if ( len < 0 ) {
  297. rc = len;
  298. DBGC ( smsc95xx, "SMSC95XX %p could not read product name: "
  299. "%s\n", smsc95xx, strerror ( rc ) );
  300. return rc;
  301. }
  302. /* Ignore non-VM3 devices */
  303. if ( ( strcmp ( strings.manufacturer, "Honeywell" ) != 0 ) ||
  304. ( strcmp ( strings.product, "VM3" ) != 0 ) )
  305. return -ENOTTY;
  306. /* Find OEM strings */
  307. if ( ( rc = find_smbios_structure ( SMBIOS_TYPE_OEM_STRINGS, 0,
  308. &structure ) ) != 0 ) {
  309. DBGC ( smsc95xx, "SMSC95XX %p could not find OEM strings: %s\n",
  310. smsc95xx, strerror ( rc ) );
  311. return rc;
  312. }
  313. /* Fetch MAC address */
  314. len = read_smbios_string ( &structure, SMSC95XX_VM3_OEM_STRING_MAC,
  315. strings.mac, ( sizeof ( strings.mac ) - 1 ));
  316. if ( len < 0 ) {
  317. rc = len;
  318. DBGC ( smsc95xx, "SMSC95XX %p could not read OEM string: %s\n",
  319. smsc95xx, strerror ( rc ) );
  320. return rc;
  321. }
  322. /* Sanity check */
  323. if ( len != ( ( int ) ( sizeof ( strings.mac ) - 1 ) ) ) {
  324. DBGC ( smsc95xx, "SMSC95XX %p invalid MAC address \"%s\"\n",
  325. smsc95xx, strings.mac );
  326. return -EINVAL;
  327. }
  328. /* Decode MAC address */
  329. len = base16_decode ( strings.mac, hw_addr, ETH_ALEN );
  330. if ( len < 0 ) {
  331. rc = len;
  332. DBGC ( smsc95xx, "SMSC95XX %p invalid MAC address \"%s\"\n",
  333. smsc95xx, strings.mac );
  334. return rc;
  335. }
  336. DBGC ( smsc95xx, "SMSC95XX %p using VM3 MAC %s\n",
  337. smsc95xx, eth_ntoa ( hw_addr ) );
  338. return 0;
  339. }
  340. /**
  341. * Fetch MAC address
  342. *
  343. * @v smsc95xx SMSC95xx device
  344. * @v hw_addr Hardware address to fill in
  345. * @ret rc Return status code
  346. */
  347. static int smsc95xx_fetch_mac ( struct smsc95xx_device *smsc95xx,
  348. uint8_t *hw_addr ) {
  349. int rc;
  350. /* Read MAC address from EEPROM, if present */
  351. if ( ( rc = smsc95xx_fetch_mac_eeprom ( smsc95xx, hw_addr ) ) == 0 )
  352. return 0;
  353. /* Construct MAC address for Honeywell VM3, if applicable */
  354. if ( ( rc = smsc95xx_fetch_mac_vm3 ( smsc95xx, hw_addr ) ) == 0 )
  355. return 0;
  356. /* Otherwise, generate a random MAC address */
  357. eth_random_addr ( hw_addr );
  358. DBGC ( smsc95xx, "SMSC95XX %p using random MAC %s\n",
  359. smsc95xx, eth_ntoa ( hw_addr ) );
  360. return 0;
  361. }
  362. /******************************************************************************
  363. *
  364. * MII access
  365. *
  366. ******************************************************************************
  367. */
  368. /**
  369. * Wait for MII to become idle
  370. *
  371. * @v smsc95xx SMSC95xx device
  372. * @ret rc Return status code
  373. */
  374. static int smsc95xx_mii_wait ( struct smsc95xx_device *smsc95xx ) {
  375. uint32_t mii_access;
  376. unsigned int i;
  377. int rc;
  378. /* Wait for MIIBZY to become clear */
  379. for ( i = 0 ; i < SMSC95XX_MII_MAX_WAIT_MS ; i++ ) {
  380. /* Read MII_ACCESS and check MIIBZY */
  381. if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_MII_ACCESS,
  382. &mii_access ) ) != 0 )
  383. return rc;
  384. if ( ! ( mii_access & SMSC95XX_MII_ACCESS_MIIBZY ) )
  385. return 0;
  386. /* Delay */
  387. mdelay ( 1 );
  388. }
  389. DBGC ( smsc95xx, "SMSC95XX %p timed out waiting for MII\n",
  390. smsc95xx );
  391. return -ETIMEDOUT;
  392. }
  393. /**
  394. * Read from MII register
  395. *
  396. * @v mii MII interface
  397. * @v reg Register address
  398. * @ret value Data read, or negative error
  399. */
  400. static int smsc95xx_mii_read ( struct mii_interface *mii, unsigned int reg ) {
  401. struct smsc95xx_device *smsc95xx =
  402. container_of ( mii, struct smsc95xx_device, mii );
  403. uint32_t mii_access;
  404. uint32_t mii_data;
  405. int rc;
  406. /* Wait for MII to become idle */
  407. if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 )
  408. return rc;
  409. /* Initiate read command */
  410. mii_access = ( SMSC95XX_MII_ACCESS_PHY_ADDRESS |
  411. SMSC95XX_MII_ACCESS_MIIRINDA ( reg ) |
  412. SMSC95XX_MII_ACCESS_MIIBZY );
  413. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MII_ACCESS,
  414. mii_access ) ) != 0 )
  415. return rc;
  416. /* Wait for command to complete */
  417. if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 )
  418. return rc;
  419. /* Read MII data */
  420. if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_MII_DATA,
  421. &mii_data ) ) != 0 )
  422. return rc;
  423. return SMSC95XX_MII_DATA_GET ( mii_data );
  424. }
  425. /**
  426. * Write to MII register
  427. *
  428. * @v mii MII interface
  429. * @v reg Register address
  430. * @v data Data to write
  431. * @ret rc Return status code
  432. */
  433. static int smsc95xx_mii_write ( struct mii_interface *mii, unsigned int reg,
  434. unsigned int data ) {
  435. struct smsc95xx_device *smsc95xx =
  436. container_of ( mii, struct smsc95xx_device, mii );
  437. uint32_t mii_access;
  438. uint32_t mii_data;
  439. int rc;
  440. /* Wait for MII to become idle */
  441. if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 )
  442. return rc;
  443. /* Write MII data */
  444. mii_data = SMSC95XX_MII_DATA_SET ( data );
  445. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MII_DATA,
  446. mii_data ) ) != 0 )
  447. return rc;
  448. /* Initiate write command */
  449. mii_access = ( SMSC95XX_MII_ACCESS_PHY_ADDRESS |
  450. SMSC95XX_MII_ACCESS_MIIRINDA ( reg ) |
  451. SMSC95XX_MII_ACCESS_MIIWNR |
  452. SMSC95XX_MII_ACCESS_MIIBZY );
  453. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MII_ACCESS,
  454. mii_access ) ) != 0 )
  455. return rc;
  456. /* Wait for command to complete */
  457. if ( ( rc = smsc95xx_mii_wait ( smsc95xx ) ) != 0 )
  458. return rc;
  459. return 0;
  460. }
  461. /** MII operations */
  462. static struct mii_operations smsc95xx_mii_operations = {
  463. .read = smsc95xx_mii_read,
  464. .write = smsc95xx_mii_write,
  465. };
  466. /**
  467. * Check link status
  468. *
  469. * @v smsc95xx SMSC95xx device
  470. * @ret rc Return status code
  471. */
  472. static int smsc95xx_check_link ( struct smsc95xx_device *smsc95xx ) {
  473. struct net_device *netdev = smsc95xx->netdev;
  474. int intr;
  475. int rc;
  476. /* Read PHY interrupt source */
  477. intr = mii_read ( &smsc95xx->mii, SMSC95XX_MII_PHY_INTR_SOURCE );
  478. if ( intr < 0 ) {
  479. rc = intr;
  480. DBGC ( smsc95xx, "SMSC95XX %p could not get PHY interrupt "
  481. "source: %s\n", smsc95xx, strerror ( rc ) );
  482. return rc;
  483. }
  484. /* Acknowledge PHY interrupt */
  485. if ( ( rc = mii_write ( &smsc95xx->mii, SMSC95XX_MII_PHY_INTR_SOURCE,
  486. intr ) ) != 0 ) {
  487. DBGC ( smsc95xx, "SMSC95XX %p could not acknowledge PHY "
  488. "interrupt: %s\n", smsc95xx, strerror ( rc ) );
  489. return rc;
  490. }
  491. /* Check link status */
  492. if ( ( rc = mii_check_link ( &smsc95xx->mii, netdev ) ) != 0 ) {
  493. DBGC ( smsc95xx, "SMSC95XX %p could not check link: %s\n",
  494. smsc95xx, strerror ( rc ) );
  495. return rc;
  496. }
  497. DBGC ( smsc95xx, "SMSC95XX %p link %s (intr %#04x)\n",
  498. smsc95xx, ( netdev_link_ok ( netdev ) ? "up" : "down" ), intr );
  499. return 0;
  500. }
  501. /******************************************************************************
  502. *
  503. * Statistics (for debugging)
  504. *
  505. ******************************************************************************
  506. */
  507. /**
  508. * Get RX statistics
  509. *
  510. * @v smsc95xx SMSC95xx device
  511. * @v stats Statistics to fill in
  512. * @ret rc Return status code
  513. */
  514. static int smsc95xx_get_rx_statistics ( struct smsc95xx_device *smsc95xx,
  515. struct smsc95xx_rx_statistics *stats ) {
  516. int rc;
  517. /* Get statistics */
  518. if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_GET_STATISTICS, 0,
  519. SMSC95XX_RX_STATISTICS, stats,
  520. sizeof ( *stats ) ) ) != 0 ) {
  521. DBGC ( smsc95xx, "SMSC95XX %p could not get RX statistics: "
  522. "%s\n", smsc95xx, strerror ( rc ) );
  523. return rc;
  524. }
  525. return 0;
  526. }
  527. /**
  528. * Get TX statistics
  529. *
  530. * @v smsc95xx SMSC95xx device
  531. * @v stats Statistics to fill in
  532. * @ret rc Return status code
  533. */
  534. static int smsc95xx_get_tx_statistics ( struct smsc95xx_device *smsc95xx,
  535. struct smsc95xx_tx_statistics *stats ) {
  536. int rc;
  537. /* Get statistics */
  538. if ( ( rc = usb_control ( smsc95xx->usb, SMSC95XX_GET_STATISTICS, 0,
  539. SMSC95XX_TX_STATISTICS, stats,
  540. sizeof ( *stats ) ) ) != 0 ) {
  541. DBGC ( smsc95xx, "SMSC95XX %p could not get TX statistics: "
  542. "%s\n", smsc95xx, strerror ( rc ) );
  543. return rc;
  544. }
  545. return 0;
  546. }
  547. /**
  548. * Dump statistics (for debugging)
  549. *
  550. * @v smsc95xx SMSC95xx device
  551. * @ret rc Return status code
  552. */
  553. static int smsc95xx_dump_statistics ( struct smsc95xx_device *smsc95xx ) {
  554. struct smsc95xx_rx_statistics rx;
  555. struct smsc95xx_tx_statistics tx;
  556. int rc;
  557. /* Do nothing unless debugging is enabled */
  558. if ( ! DBG_LOG )
  559. return 0;
  560. /* Get RX statistics */
  561. if ( ( rc = smsc95xx_get_rx_statistics ( smsc95xx, &rx ) ) != 0 )
  562. return rc;
  563. /* Get TX statistics */
  564. if ( ( rc = smsc95xx_get_tx_statistics ( smsc95xx, &tx ) ) != 0 )
  565. return rc;
  566. /* Dump statistics */
  567. DBGC ( smsc95xx, "SMSC95XX %p RX good %d bad %d crc %d und %d aln %d "
  568. "ovr %d lat %d drp %d\n", smsc95xx, le32_to_cpu ( rx.good ),
  569. le32_to_cpu ( rx.bad ), le32_to_cpu ( rx.crc ),
  570. le32_to_cpu ( rx.undersize ), le32_to_cpu ( rx.alignment ),
  571. le32_to_cpu ( rx.oversize ), le32_to_cpu ( rx.late ),
  572. le32_to_cpu ( rx.dropped ) );
  573. DBGC ( smsc95xx, "SMSC95XX %p TX good %d bad %d pau %d sgl %d mul %d "
  574. "exc %d lat %d und %d def %d car %d\n", smsc95xx,
  575. le32_to_cpu ( tx.good ), le32_to_cpu ( tx.bad ),
  576. le32_to_cpu ( tx.pause ), le32_to_cpu ( tx.single ),
  577. le32_to_cpu ( tx.multiple ), le32_to_cpu ( tx.excessive ),
  578. le32_to_cpu ( tx.late ), le32_to_cpu ( tx.underrun ),
  579. le32_to_cpu ( tx.deferred ), le32_to_cpu ( tx.carrier ) );
  580. return 0;
  581. }
  582. /******************************************************************************
  583. *
  584. * Device reset
  585. *
  586. ******************************************************************************
  587. */
  588. /**
  589. * Reset device
  590. *
  591. * @v smsc95xx SMSC95xx device
  592. * @ret rc Return status code
  593. */
  594. static int smsc95xx_reset ( struct smsc95xx_device *smsc95xx ) {
  595. uint32_t hw_cfg;
  596. uint32_t led_gpio_cfg;
  597. int rc;
  598. /* Reset device */
  599. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_HW_CFG,
  600. SMSC95XX_HW_CFG_LRST ) ) != 0 )
  601. return rc;
  602. /* Wait for reset to complete */
  603. udelay ( SMSC95XX_RESET_DELAY_US );
  604. /* Check that reset has completed */
  605. if ( ( rc = smsc95xx_readl ( smsc95xx, SMSC95XX_HW_CFG,
  606. &hw_cfg ) ) != 0 )
  607. return rc;
  608. if ( hw_cfg & SMSC95XX_HW_CFG_LRST ) {
  609. DBGC ( smsc95xx, "SMSC95XX %p failed to reset\n", smsc95xx );
  610. return -ETIMEDOUT;
  611. }
  612. /* Configure LEDs */
  613. led_gpio_cfg = ( SMSC95XX_LED_GPIO_CFG_GPCTL2_NSPD_LED |
  614. SMSC95XX_LED_GPIO_CFG_GPCTL1_NLNKA_LED |
  615. SMSC95XX_LED_GPIO_CFG_GPCTL0_NFDX_LED );
  616. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_LED_GPIO_CFG,
  617. led_gpio_cfg ) ) != 0 ) {
  618. DBGC ( smsc95xx, "SMSC95XX %p could not configure LEDs: %s\n",
  619. smsc95xx, strerror ( rc ) );
  620. /* Ignore error and continue */
  621. }
  622. return 0;
  623. }
  624. /******************************************************************************
  625. *
  626. * Endpoint operations
  627. *
  628. ******************************************************************************
  629. */
  630. /**
  631. * Complete interrupt transfer
  632. *
  633. * @v ep USB endpoint
  634. * @v iobuf I/O buffer
  635. * @v rc Completion status code
  636. */
  637. static void smsc95xx_intr_complete ( struct usb_endpoint *ep,
  638. struct io_buffer *iobuf, int rc ) {
  639. struct smsc95xx_device *smsc95xx =
  640. container_of ( ep, struct smsc95xx_device, usbnet.intr );
  641. struct net_device *netdev = smsc95xx->netdev;
  642. struct smsc95xx_interrupt *intr;
  643. /* Profile completions */
  644. profile_start ( &smsc95xx_intr_profiler );
  645. /* Ignore packets cancelled when the endpoint closes */
  646. if ( ! ep->open )
  647. goto done;
  648. /* Record USB errors against the network device */
  649. if ( rc != 0 ) {
  650. DBGC ( smsc95xx, "SMSC95XX %p interrupt failed: %s\n",
  651. smsc95xx, strerror ( rc ) );
  652. DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) );
  653. netdev_rx_err ( netdev, NULL, rc );
  654. goto done;
  655. }
  656. /* Extract interrupt data */
  657. if ( iob_len ( iobuf ) != sizeof ( *intr ) ) {
  658. DBGC ( smsc95xx, "SMSC95XX %p malformed interrupt\n",
  659. smsc95xx );
  660. DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) );
  661. netdev_rx_err ( netdev, NULL, rc );
  662. goto done;
  663. }
  664. intr = iobuf->data;
  665. /* Record interrupt status */
  666. smsc95xx->int_sts = le32_to_cpu ( intr->int_sts );
  667. profile_stop ( &smsc95xx_intr_profiler );
  668. done:
  669. /* Free I/O buffer */
  670. free_iob ( iobuf );
  671. }
  672. /** Interrupt endpoint operations */
  673. static struct usb_endpoint_driver_operations smsc95xx_intr_operations = {
  674. .complete = smsc95xx_intr_complete,
  675. };
  676. /**
  677. * Complete bulk IN transfer
  678. *
  679. * @v ep USB endpoint
  680. * @v iobuf I/O buffer
  681. * @v rc Completion status code
  682. */
  683. static void smsc95xx_in_complete ( struct usb_endpoint *ep,
  684. struct io_buffer *iobuf, int rc ) {
  685. struct smsc95xx_device *smsc95xx =
  686. container_of ( ep, struct smsc95xx_device, usbnet.in );
  687. struct net_device *netdev = smsc95xx->netdev;
  688. struct smsc95xx_rx_header *header;
  689. /* Profile completions */
  690. profile_start ( &smsc95xx_in_profiler );
  691. /* Ignore packets cancelled when the endpoint closes */
  692. if ( ! ep->open ) {
  693. free_iob ( iobuf );
  694. return;
  695. }
  696. /* Record USB errors against the network device */
  697. if ( rc != 0 ) {
  698. DBGC ( smsc95xx, "SMSC95XX %p bulk IN failed: %s\n",
  699. smsc95xx, strerror ( rc ) );
  700. goto err;
  701. }
  702. /* Sanity check */
  703. if ( iob_len ( iobuf ) < ( sizeof ( *header ) + 4 /* CRC */ ) ) {
  704. DBGC ( smsc95xx, "SMSC95XX %p underlength bulk IN\n",
  705. smsc95xx );
  706. DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) );
  707. rc = -EINVAL;
  708. goto err;
  709. }
  710. /* Strip header and CRC */
  711. header = iobuf->data;
  712. iob_pull ( iobuf, sizeof ( *header ) );
  713. iob_unput ( iobuf, 4 /* CRC */ );
  714. /* Check for errors */
  715. if ( header->command & cpu_to_le32 ( SMSC95XX_RX_RUNT |
  716. SMSC95XX_RX_LATE |
  717. SMSC95XX_RX_CRC ) ) {
  718. DBGC ( smsc95xx, "SMSC95XX %p receive error (%08x):\n",
  719. smsc95xx, le32_to_cpu ( header->command ) );
  720. DBGC_HDA ( smsc95xx, 0, iobuf->data, iob_len ( iobuf ) );
  721. rc = -EIO;
  722. goto err;
  723. }
  724. /* Hand off to network stack */
  725. netdev_rx ( netdev, iob_disown ( iobuf ) );
  726. profile_stop ( &smsc95xx_in_profiler );
  727. return;
  728. err:
  729. /* Hand off to network stack */
  730. netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
  731. }
  732. /** Bulk IN endpoint operations */
  733. static struct usb_endpoint_driver_operations smsc95xx_in_operations = {
  734. .complete = smsc95xx_in_complete,
  735. };
  736. /**
  737. * Transmit packet
  738. *
  739. * @v smsc95xx SMSC95xx device
  740. * @v iobuf I/O buffer
  741. * @ret rc Return status code
  742. */
  743. static int smsc95xx_out_transmit ( struct smsc95xx_device *smsc95xx,
  744. struct io_buffer *iobuf ) {
  745. struct smsc95xx_tx_header *header;
  746. size_t len = iob_len ( iobuf );
  747. int rc;
  748. /* Profile transmissions */
  749. profile_start ( &smsc95xx_out_profiler );
  750. /* Prepend header */
  751. if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 )
  752. return rc;
  753. header = iob_push ( iobuf, sizeof ( *header ) );
  754. header->command = cpu_to_le32 ( SMSC95XX_TX_FIRST | SMSC95XX_TX_LAST |
  755. SMSC95XX_TX_LEN ( len ) );
  756. header->len = cpu_to_le32 ( len );
  757. /* Enqueue I/O buffer */
  758. if ( ( rc = usb_stream ( &smsc95xx->usbnet.out, iobuf, 0 ) ) != 0 )
  759. return rc;
  760. profile_stop ( &smsc95xx_out_profiler );
  761. return 0;
  762. }
  763. /**
  764. * Complete bulk OUT transfer
  765. *
  766. * @v ep USB endpoint
  767. * @v iobuf I/O buffer
  768. * @v rc Completion status code
  769. */
  770. static void smsc95xx_out_complete ( struct usb_endpoint *ep,
  771. struct io_buffer *iobuf, int rc ) {
  772. struct smsc95xx_device *smsc95xx =
  773. container_of ( ep, struct smsc95xx_device, usbnet.out );
  774. struct net_device *netdev = smsc95xx->netdev;
  775. /* Report TX completion */
  776. netdev_tx_complete_err ( netdev, iobuf, rc );
  777. }
  778. /** Bulk OUT endpoint operations */
  779. static struct usb_endpoint_driver_operations smsc95xx_out_operations = {
  780. .complete = smsc95xx_out_complete,
  781. };
  782. /******************************************************************************
  783. *
  784. * Network device interface
  785. *
  786. ******************************************************************************
  787. */
  788. /**
  789. * Open network device
  790. *
  791. * @v netdev Network device
  792. * @ret rc Return status code
  793. */
  794. static int smsc95xx_open ( struct net_device *netdev ) {
  795. struct smsc95xx_device *smsc95xx = netdev->priv;
  796. union smsc95xx_mac mac;
  797. int rc;
  798. /* Clear stored interrupt status */
  799. smsc95xx->int_sts = 0;
  800. /* Copy MAC address */
  801. memset ( &mac, 0, sizeof ( mac ) );
  802. memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
  803. /* Configure bulk IN empty response */
  804. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_HW_CFG,
  805. SMSC95XX_HW_CFG_BIR ) ) != 0 )
  806. goto err_hw_cfg;
  807. /* Open USB network device */
  808. if ( ( rc = usbnet_open ( &smsc95xx->usbnet ) ) != 0 ) {
  809. DBGC ( smsc95xx, "SMSC95XX %p could not open: %s\n",
  810. smsc95xx, strerror ( rc ) );
  811. goto err_open;
  812. }
  813. /* Configure interrupt endpoint */
  814. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_INT_EP_CTL,
  815. ( SMSC95XX_INT_EP_CTL_RXDF_EN |
  816. SMSC95XX_INT_EP_CTL_PHY_EN ) ) ) != 0 )
  817. goto err_int_ep_ctl;
  818. /* Configure bulk IN delay */
  819. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_BULK_IN_DLY,
  820. SMSC95XX_BULK_IN_DLY_SET ( 0 ) ) ) != 0 )
  821. goto err_bulk_in_dly;
  822. /* Configure MAC */
  823. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_MAC_CR,
  824. ( SMSC95XX_MAC_CR_RXALL |
  825. SMSC95XX_MAC_CR_FDPX |
  826. SMSC95XX_MAC_CR_MCPAS |
  827. SMSC95XX_MAC_CR_PRMS |
  828. SMSC95XX_MAC_CR_PASSBAD |
  829. SMSC95XX_MAC_CR_TXEN |
  830. SMSC95XX_MAC_CR_RXEN ) ) ) != 0 )
  831. goto err_mac_cr;
  832. /* Configure transmit datapath */
  833. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_TX_CFG,
  834. SMSC95XX_TX_CFG_ON ) ) != 0 )
  835. goto err_tx_cfg;
  836. /* Write MAC address high register */
  837. if ( ( rc = smsc95xx_raw_writel ( smsc95xx, SMSC95XX_ADDRH,
  838. mac.addr.h ) ) != 0 )
  839. goto err_addrh;
  840. /* Write MAC address low register */
  841. if ( ( rc = smsc95xx_raw_writel ( smsc95xx, SMSC95XX_ADDRL,
  842. mac.addr.l ) ) != 0 )
  843. goto err_addrl;
  844. /* Enable PHY interrupts */
  845. if ( ( rc = mii_write ( &smsc95xx->mii, SMSC95XX_MII_PHY_INTR_MASK,
  846. ( SMSC95XX_PHY_INTR_ANEG_DONE |
  847. SMSC95XX_PHY_INTR_LINK_DOWN ) ) ) != 0 ) {
  848. DBGC ( smsc95xx, "SMSC95XX %p could not set PHY interrupt "
  849. "mask: %s\n", smsc95xx, strerror ( rc ) );
  850. goto err_phy_intr_mask;
  851. }
  852. /* Update link status */
  853. smsc95xx_check_link ( smsc95xx );
  854. return 0;
  855. err_phy_intr_mask:
  856. err_addrl:
  857. err_addrh:
  858. err_tx_cfg:
  859. err_mac_cr:
  860. err_bulk_in_dly:
  861. err_int_ep_ctl:
  862. usbnet_close ( &smsc95xx->usbnet );
  863. err_open:
  864. err_hw_cfg:
  865. smsc95xx_reset ( smsc95xx );
  866. return rc;
  867. }
  868. /**
  869. * Close network device
  870. *
  871. * @v netdev Network device
  872. */
  873. static void smsc95xx_close ( struct net_device *netdev ) {
  874. struct smsc95xx_device *smsc95xx = netdev->priv;
  875. /* Close USB network device */
  876. usbnet_close ( &smsc95xx->usbnet );
  877. /* Dump statistics (for debugging) */
  878. smsc95xx_dump_statistics ( smsc95xx );
  879. /* Reset device */
  880. smsc95xx_reset ( smsc95xx );
  881. }
  882. /**
  883. * Transmit packet
  884. *
  885. * @v netdev Network device
  886. * @v iobuf I/O buffer
  887. * @ret rc Return status code
  888. */
  889. static int smsc95xx_transmit ( struct net_device *netdev,
  890. struct io_buffer *iobuf ) {
  891. struct smsc95xx_device *smsc95xx = netdev->priv;
  892. int rc;
  893. /* Transmit packet */
  894. if ( ( rc = smsc95xx_out_transmit ( smsc95xx, iobuf ) ) != 0 )
  895. return rc;
  896. return 0;
  897. }
  898. /**
  899. * Poll for completed and received packets
  900. *
  901. * @v netdev Network device
  902. */
  903. static void smsc95xx_poll ( struct net_device *netdev ) {
  904. struct smsc95xx_device *smsc95xx = netdev->priv;
  905. uint32_t int_sts;
  906. int rc;
  907. /* Poll USB bus */
  908. usb_poll ( smsc95xx->bus );
  909. /* Refill endpoints */
  910. if ( ( rc = usbnet_refill ( &smsc95xx->usbnet ) ) != 0 )
  911. netdev_rx_err ( netdev, NULL, rc );
  912. /* Do nothing more unless there are interrupts to handle */
  913. int_sts = smsc95xx->int_sts;
  914. if ( ! int_sts )
  915. return;
  916. /* Check link status if applicable */
  917. if ( int_sts & SMSC95XX_INT_STS_PHY_INT ) {
  918. smsc95xx_check_link ( smsc95xx );
  919. int_sts &= ~SMSC95XX_INT_STS_PHY_INT;
  920. }
  921. /* Record RX FIFO overflow if applicable */
  922. if ( int_sts & SMSC95XX_INT_STS_RXDF_INT ) {
  923. DBGC2 ( smsc95xx, "SMSC95XX %p RX FIFO overflowed\n",
  924. smsc95xx );
  925. netdev_rx_err ( netdev, NULL, -ENOBUFS );
  926. int_sts &= ~SMSC95XX_INT_STS_RXDF_INT;
  927. }
  928. /* Check for unexpected interrupts */
  929. if ( int_sts ) {
  930. DBGC ( smsc95xx, "SMSC95XX %p unexpected interrupt %#08x\n",
  931. smsc95xx, int_sts );
  932. netdev_rx_err ( netdev, NULL, -ENOTTY );
  933. }
  934. /* Clear interrupts */
  935. if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_INT_STS,
  936. smsc95xx->int_sts ) ) != 0 )
  937. netdev_rx_err ( netdev, NULL, rc );
  938. smsc95xx->int_sts = 0;
  939. }
  940. /** SMSC95xx network device operations */
  941. static struct net_device_operations smsc95xx_operations = {
  942. .open = smsc95xx_open,
  943. .close = smsc95xx_close,
  944. .transmit = smsc95xx_transmit,
  945. .poll = smsc95xx_poll,
  946. };
  947. /******************************************************************************
  948. *
  949. * USB interface
  950. *
  951. ******************************************************************************
  952. */
  953. /**
  954. * Probe device
  955. *
  956. * @v func USB function
  957. * @v config Configuration descriptor
  958. * @ret rc Return status code
  959. */
  960. static int smsc95xx_probe ( struct usb_function *func,
  961. struct usb_configuration_descriptor *config ) {
  962. struct usb_device *usb = func->usb;
  963. struct net_device *netdev;
  964. struct smsc95xx_device *smsc95xx;
  965. int rc;
  966. /* Allocate and initialise structure */
  967. netdev = alloc_etherdev ( sizeof ( *smsc95xx ) );
  968. if ( ! netdev ) {
  969. rc = -ENOMEM;
  970. goto err_alloc;
  971. }
  972. netdev_init ( netdev, &smsc95xx_operations );
  973. netdev->dev = &func->dev;
  974. smsc95xx = netdev->priv;
  975. memset ( smsc95xx, 0, sizeof ( *smsc95xx ) );
  976. smsc95xx->usb = usb;
  977. smsc95xx->bus = usb->port->hub->bus;
  978. smsc95xx->netdev = netdev;
  979. usbnet_init ( &smsc95xx->usbnet, func, &smsc95xx_intr_operations,
  980. &smsc95xx_in_operations, &smsc95xx_out_operations );
  981. usb_refill_init ( &smsc95xx->usbnet.intr, 0, 0,
  982. SMSC95XX_INTR_MAX_FILL );
  983. usb_refill_init ( &smsc95xx->usbnet.in,
  984. ( sizeof ( struct smsc95xx_tx_header ) -
  985. sizeof ( struct smsc95xx_rx_header ) ),
  986. SMSC95XX_IN_MTU, SMSC95XX_IN_MAX_FILL );
  987. mii_init ( &smsc95xx->mii, &smsc95xx_mii_operations );
  988. DBGC ( smsc95xx, "SMSC95XX %p on %s\n", smsc95xx, func->name );
  989. /* Describe USB network device */
  990. if ( ( rc = usbnet_describe ( &smsc95xx->usbnet, config ) ) != 0 ) {
  991. DBGC ( smsc95xx, "SMSC95XX %p could not describe: %s\n",
  992. smsc95xx, strerror ( rc ) );
  993. goto err_describe;
  994. }
  995. /* Reset device */
  996. if ( ( rc = smsc95xx_reset ( smsc95xx ) ) != 0 )
  997. goto err_reset;
  998. /* Read MAC address */
  999. if ( ( rc = smsc95xx_fetch_mac ( smsc95xx, netdev->hw_addr ) ) != 0 )
  1000. goto err_fetch_mac;
  1001. /* Register network device */
  1002. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  1003. goto err_register;
  1004. usb_func_set_drvdata ( func, netdev );
  1005. return 0;
  1006. unregister_netdev ( netdev );
  1007. err_register:
  1008. err_fetch_mac:
  1009. err_reset:
  1010. err_describe:
  1011. netdev_nullify ( netdev );
  1012. netdev_put ( netdev );
  1013. err_alloc:
  1014. return rc;
  1015. }
  1016. /**
  1017. * Remove device
  1018. *
  1019. * @v func USB function
  1020. */
  1021. static void smsc95xx_remove ( struct usb_function *func ) {
  1022. struct net_device *netdev = usb_func_get_drvdata ( func );
  1023. unregister_netdev ( netdev );
  1024. netdev_nullify ( netdev );
  1025. netdev_put ( netdev );
  1026. }
  1027. /** SMSC95xx device IDs */
  1028. static struct usb_device_id smsc95xx_ids[] = {
  1029. {
  1030. .name = "smsc9500",
  1031. .vendor = 0x0424,
  1032. .product = 0x9500,
  1033. },
  1034. {
  1035. .name = "smsc9505",
  1036. .vendor = 0x0424,
  1037. .product = 0x9505,
  1038. },
  1039. {
  1040. .name = "smsc9500a",
  1041. .vendor = 0x0424,
  1042. .product = 0x9e00,
  1043. },
  1044. {
  1045. .name = "smsc9505a",
  1046. .vendor = 0x0424,
  1047. .product = 0x9e01,
  1048. },
  1049. {
  1050. .name = "smsc9514",
  1051. .vendor = 0x0424,
  1052. .product = 0xec00,
  1053. },
  1054. {
  1055. .name = "smsc9500-s",
  1056. .vendor = 0x0424,
  1057. .product = 0x9900,
  1058. },
  1059. {
  1060. .name = "smsc9505-s",
  1061. .vendor = 0x0424,
  1062. .product = 0x9901,
  1063. },
  1064. {
  1065. .name = "smsc9500a-s",
  1066. .vendor = 0x0424,
  1067. .product = 0x9902,
  1068. },
  1069. {
  1070. .name = "smsc9505a-s",
  1071. .vendor = 0x0424,
  1072. .product = 0x9903,
  1073. },
  1074. {
  1075. .name = "smsc9514-s",
  1076. .vendor = 0x0424,
  1077. .product = 0x9904,
  1078. },
  1079. {
  1080. .name = "smsc9500a-h",
  1081. .vendor = 0x0424,
  1082. .product = 0x9905,
  1083. },
  1084. {
  1085. .name = "smsc9505a-h",
  1086. .vendor = 0x0424,
  1087. .product = 0x9906,
  1088. },
  1089. {
  1090. .name = "smsc9500-2",
  1091. .vendor = 0x0424,
  1092. .product = 0x9907,
  1093. },
  1094. {
  1095. .name = "smsc9500a-2",
  1096. .vendor = 0x0424,
  1097. .product = 0x9908,
  1098. },
  1099. {
  1100. .name = "smsc9514-2",
  1101. .vendor = 0x0424,
  1102. .product = 0x9909,
  1103. },
  1104. {
  1105. .name = "smsc9530",
  1106. .vendor = 0x0424,
  1107. .product = 0x9530,
  1108. },
  1109. {
  1110. .name = "smsc9730",
  1111. .vendor = 0x0424,
  1112. .product = 0x9730,
  1113. },
  1114. {
  1115. .name = "smsc89530",
  1116. .vendor = 0x0424,
  1117. .product = 0x9e08,
  1118. },
  1119. };
  1120. /** SMSC LAN95xx driver */
  1121. struct usb_driver smsc95xx_driver __usb_driver = {
  1122. .ids = smsc95xx_ids,
  1123. .id_count = ( sizeof ( smsc95xx_ids ) / sizeof ( smsc95xx_ids[0] ) ),
  1124. .class = USB_CLASS_ID ( 0xff, 0x00, 0xff ),
  1125. .score = USB_SCORE_NORMAL,
  1126. .probe = smsc95xx_probe,
  1127. .remove = smsc95xx_remove,
  1128. };