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.

myson.c 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * Copyright (C) 2012 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 <stdint.h>
  25. #include <string.h>
  26. #include <unistd.h>
  27. #include <errno.h>
  28. #include <byteswap.h>
  29. #include <ipxe/netdevice.h>
  30. #include <ipxe/ethernet.h>
  31. #include <ipxe/if_ether.h>
  32. #include <ipxe/iobuf.h>
  33. #include <ipxe/malloc.h>
  34. #include <ipxe/pci.h>
  35. #include <ipxe/mii.h>
  36. #include "myson.h"
  37. /** @file
  38. *
  39. * Myson Technology network card driver
  40. *
  41. */
  42. /******************************************************************************
  43. *
  44. * Device reset
  45. *
  46. ******************************************************************************
  47. */
  48. /**
  49. * Reset controller chip
  50. *
  51. * @v myson Myson device
  52. * @ret rc Return status code
  53. */
  54. static int myson_soft_reset ( struct myson_nic *myson ) {
  55. uint32_t bcr;
  56. unsigned int i;
  57. /* Initiate reset */
  58. bcr = readl ( myson->regs + MYSON_BCR );
  59. writel ( ( bcr | MYSON_BCR_SWR ), myson->regs + MYSON_BCR );
  60. /* Wait for reset to complete */
  61. for ( i = 0 ; i < MYSON_RESET_MAX_WAIT_MS ; i++ ) {
  62. /* If reset is not complete, delay 1ms and retry */
  63. if ( readl ( myson->regs + MYSON_BCR ) & MYSON_BCR_SWR ) {
  64. mdelay ( 1 );
  65. continue;
  66. }
  67. /* Apply a sensible default bus configuration */
  68. bcr = readl ( myson->regs + MYSON_BCR );
  69. bcr &= ~MYSON_BCR_PBL_MASK;
  70. bcr |= ( MYSON_BCR_RLE | MYSON_BCR_RME | MYSON_BCR_WIE |
  71. MYSON_BCR_PBL_DEFAULT );
  72. writel ( bcr, myson->regs + MYSON_BCR );
  73. DBGC ( myson, "MYSON %p using configuration %08x\n",
  74. myson, bcr );
  75. return 0;
  76. }
  77. DBGC ( myson, "MYSON %p timed out waiting for reset\n", myson );
  78. return -ETIMEDOUT;
  79. }
  80. /**
  81. * Reload configuration from EEPROM
  82. *
  83. * @v myson Myson device
  84. * @ret rc Return status code
  85. */
  86. static int myson_reload_config ( struct myson_nic *myson ) {
  87. unsigned int i;
  88. /* Initiate reload */
  89. writel ( MYSON_ROM_AUTOLD, myson->regs + MYSON_ROM_MII );
  90. /* Wait for reload to complete */
  91. for ( i = 0 ; i < MYSON_AUTOLD_MAX_WAIT_MS ; i++ ) {
  92. /* If reload is not complete, delay 1ms and retry */
  93. if ( readl ( myson->regs + MYSON_ROM_MII ) & MYSON_ROM_AUTOLD ){
  94. mdelay ( 1 );
  95. continue;
  96. }
  97. return 0;
  98. }
  99. DBGC ( myson, "MYSON %p timed out waiting for configuration "
  100. "reload\n", myson );
  101. return -ETIMEDOUT;
  102. }
  103. /**
  104. * Reset hardware
  105. *
  106. * @v myson Myson device
  107. * @ret rc Return status code
  108. */
  109. static int myson_reset ( struct myson_nic *myson ) {
  110. int rc;
  111. /* Disable all interrupts */
  112. writel ( 0, myson->regs + MYSON_IMR );
  113. /* Perform soft reset */
  114. if ( ( rc = myson_soft_reset ( myson ) ) != 0 )
  115. return rc;
  116. /* Reload configuration from EEPROM */
  117. if ( ( rc = myson_reload_config ( myson ) ) != 0 )
  118. return rc;
  119. return 0;
  120. }
  121. /******************************************************************************
  122. *
  123. * Network device interface
  124. *
  125. ******************************************************************************
  126. */
  127. /**
  128. * Create descriptor ring
  129. *
  130. * @v myson Myson device
  131. * @v ring Descriptor ring
  132. * @ret rc Return status code
  133. */
  134. static int myson_create_ring ( struct myson_nic *myson,
  135. struct myson_ring *ring ) {
  136. size_t len = ( ring->count * sizeof ( ring->desc[0] ) );
  137. struct myson_descriptor *desc;
  138. struct myson_descriptor *next;
  139. physaddr_t address;
  140. unsigned int i;
  141. int rc;
  142. /* Allocate descriptor ring */
  143. ring->desc = malloc_dma ( len, MYSON_RING_ALIGN );
  144. if ( ! ring->desc ) {
  145. rc = -ENOMEM;
  146. goto err_alloc;
  147. }
  148. address = virt_to_bus ( ring->desc );
  149. /* Check address is usable by card */
  150. if ( ! myson_address_ok ( address + len ) ) {
  151. DBGC ( myson, "MYSON %p cannot support 64-bit ring address\n",
  152. myson );
  153. rc = -ENOTSUP;
  154. goto err_64bit;
  155. }
  156. /* Initialise descriptor ring */
  157. memset ( ring->desc, 0, len );
  158. for ( i = 0 ; i < ring->count ; i++ ) {
  159. desc = &ring->desc[i];
  160. next = &ring->desc[ ( i + 1 ) % ring->count ];
  161. desc->next = cpu_to_le32 ( virt_to_bus ( next ) );
  162. }
  163. /* Program ring address */
  164. writel ( address, myson->regs + ring->reg );
  165. DBGC ( myson, "MYSON %p ring %02x is at [%08llx,%08llx)\n",
  166. myson, ring->reg, ( ( unsigned long long ) address ),
  167. ( ( unsigned long long ) address + len ) );
  168. return 0;
  169. err_64bit:
  170. free_dma ( ring->desc, len );
  171. ring->desc = NULL;
  172. err_alloc:
  173. return rc;
  174. }
  175. /**
  176. * Destroy descriptor ring
  177. *
  178. * @v myson Myson device
  179. * @v ring Descriptor ring
  180. */
  181. static void myson_destroy_ring ( struct myson_nic *myson,
  182. struct myson_ring *ring ) {
  183. size_t len = ( ring->count * sizeof ( ring->desc[0] ) );
  184. /* Clear ring address */
  185. writel ( 0, myson->regs + ring->reg );
  186. /* Free descriptor ring */
  187. free_dma ( ring->desc, len );
  188. ring->desc = NULL;
  189. ring->prod = 0;
  190. ring->cons = 0;
  191. }
  192. /**
  193. * Refill receive descriptor ring
  194. *
  195. * @v netdev Network device
  196. */
  197. static void myson_refill_rx ( struct net_device *netdev ) {
  198. struct myson_nic *myson = netdev->priv;
  199. struct myson_descriptor *rx;
  200. struct io_buffer *iobuf;
  201. unsigned int rx_idx;
  202. physaddr_t address;
  203. while ( ( myson->rx.prod - myson->rx.cons ) < MYSON_NUM_RX_DESC ) {
  204. /* Allocate I/O buffer */
  205. iobuf = alloc_iob ( MYSON_RX_MAX_LEN );
  206. if ( ! iobuf ) {
  207. /* Wait for next refill */
  208. return;
  209. }
  210. /* Check address is usable by card */
  211. address = virt_to_bus ( iobuf->data );
  212. if ( ! myson_address_ok ( address ) ) {
  213. DBGC ( myson, "MYSON %p cannot support 64-bit RX "
  214. "buffer address\n", myson );
  215. netdev_rx_err ( netdev, iobuf, -ENOTSUP );
  216. return;
  217. }
  218. /* Get next receive descriptor */
  219. rx_idx = ( myson->rx.prod++ % MYSON_NUM_RX_DESC );
  220. rx = &myson->rx.desc[rx_idx];
  221. /* Populate receive descriptor */
  222. rx->address = cpu_to_le32 ( address );
  223. rx->control =
  224. cpu_to_le32 ( MYSON_RX_CTRL_RBS ( MYSON_RX_MAX_LEN ) );
  225. wmb();
  226. rx->status = cpu_to_le32 ( MYSON_RX_STAT_OWN );
  227. wmb();
  228. /* Record I/O buffer */
  229. assert ( myson->rx_iobuf[rx_idx] == NULL );
  230. myson->rx_iobuf[rx_idx] = iobuf;
  231. /* Notify card that there are descriptors available */
  232. writel ( 0, myson->regs + MYSON_RXPDR );
  233. DBGC2 ( myson, "MYSON %p RX %d is [%llx,%llx)\n", myson,
  234. rx_idx, ( ( unsigned long long ) address ),
  235. ( ( unsigned long long ) address + MYSON_RX_MAX_LEN ) );
  236. }
  237. }
  238. /**
  239. * Open network device
  240. *
  241. * @v netdev Network device
  242. * @ret rc Return status code
  243. */
  244. static int myson_open ( struct net_device *netdev ) {
  245. struct myson_nic *myson = netdev->priv;
  246. union myson_physical_address mac;
  247. int rc;
  248. /* Set MAC address */
  249. memset ( &mac, 0, sizeof ( mac ) );
  250. memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
  251. writel ( le32_to_cpu ( mac.reg.low ), myson->regs + MYSON_PAR0 );
  252. writel ( le32_to_cpu ( mac.reg.high ), myson->regs + MYSON_PAR4 );
  253. /* Create transmit descriptor ring */
  254. if ( ( rc = myson_create_ring ( myson, &myson->tx ) ) != 0 )
  255. goto err_create_tx;
  256. /* Create receive descriptor ring */
  257. if ( ( rc = myson_create_ring ( myson, &myson->rx ) ) != 0 )
  258. goto err_create_rx;
  259. /* Configure transmitter and receiver */
  260. writel ( ( MYSON_TCR_TE | MYSON_RCR_PROM | MYSON_RCR_AB | MYSON_RCR_AM |
  261. MYSON_RCR_ARP | MYSON_RCR_ALP | MYSON_RCR_RE ),
  262. myson->regs + MYSON_TCR_RCR );
  263. /* Fill receive ring */
  264. myson_refill_rx ( netdev );
  265. return 0;
  266. myson_destroy_ring ( myson, &myson->rx );
  267. err_create_rx:
  268. myson_destroy_ring ( myson, &myson->tx );
  269. err_create_tx:
  270. return rc;
  271. }
  272. /**
  273. * Wait for transmit and receive to become idle
  274. *
  275. * @v myson Myson device
  276. * @ret rc Return status code
  277. */
  278. static int myson_wait_idle ( struct myson_nic *myson ) {
  279. uint32_t tcr_rcr;
  280. unsigned int i;
  281. /* Wait for both transmit and receive to be idle */
  282. for ( i = 0 ; i < MYSON_IDLE_MAX_WAIT_MS ; i++ ) {
  283. /* If either process is running, delay 1ms and retry */
  284. tcr_rcr = readl ( myson->regs + MYSON_TCR_RCR );
  285. if ( tcr_rcr & ( MYSON_TCR_TXS | MYSON_RCR_RXS ) ) {
  286. mdelay ( 1 );
  287. continue;
  288. }
  289. return 0;
  290. }
  291. DBGC ( myson, "MYSON %p timed out waiting for idle state (status "
  292. "%08x)\n", myson, tcr_rcr );
  293. return -ETIMEDOUT;
  294. }
  295. /**
  296. * Close network device
  297. *
  298. * @v netdev Network device
  299. */
  300. static void myson_close ( struct net_device *netdev ) {
  301. struct myson_nic *myson = netdev->priv;
  302. unsigned int i;
  303. /* Disable receiver and transmitter */
  304. writel ( 0, myson->regs + MYSON_TCR_RCR );
  305. /* Allow time for receiver and transmitter to become idle */
  306. myson_wait_idle ( myson );
  307. /* Destroy receive descriptor ring */
  308. myson_destroy_ring ( myson, &myson->rx );
  309. /* Discard any unused receive buffers */
  310. for ( i = 0 ; i < MYSON_NUM_RX_DESC ; i++ ) {
  311. if ( myson->rx_iobuf[i] )
  312. free_iob ( myson->rx_iobuf[i] );
  313. myson->rx_iobuf[i] = NULL;
  314. }
  315. /* Destroy transmit descriptor ring */
  316. myson_destroy_ring ( myson, &myson->tx );
  317. }
  318. /**
  319. * Transmit packet
  320. *
  321. * @v netdev Network device
  322. * @v iobuf I/O buffer
  323. * @ret rc Return status code
  324. */
  325. static int myson_transmit ( struct net_device *netdev,
  326. struct io_buffer *iobuf ) {
  327. struct myson_nic *myson = netdev->priv;
  328. struct myson_descriptor *tx;
  329. unsigned int tx_idx;
  330. physaddr_t address;
  331. /* Check address is usable by card */
  332. address = virt_to_bus ( iobuf->data );
  333. if ( ! myson_address_ok ( address ) ) {
  334. DBGC ( myson, "MYSON %p cannot support 64-bit TX buffer "
  335. "address\n", myson );
  336. return -ENOTSUP;
  337. }
  338. /* Get next transmit descriptor */
  339. if ( ( myson->tx.prod - myson->tx.cons ) >= MYSON_NUM_TX_DESC ) {
  340. DBGC ( myson, "MYSON %p out of transmit descriptors\n",
  341. myson );
  342. return -ENOBUFS;
  343. }
  344. tx_idx = ( myson->tx.prod++ % MYSON_NUM_TX_DESC );
  345. tx = &myson->tx.desc[tx_idx];
  346. /* Populate transmit descriptor */
  347. tx->address = cpu_to_le32 ( address );
  348. tx->control = cpu_to_le32 ( MYSON_TX_CTRL_IC | MYSON_TX_CTRL_LD |
  349. MYSON_TX_CTRL_FD | MYSON_TX_CTRL_CRC |
  350. MYSON_TX_CTRL_PAD | MYSON_TX_CTRL_RTLC |
  351. MYSON_TX_CTRL_PKTS ( iob_len ( iobuf ) ) |
  352. MYSON_TX_CTRL_TBS ( iob_len ( iobuf ) ) );
  353. wmb();
  354. tx->status = cpu_to_le32 ( MYSON_TX_STAT_OWN );
  355. wmb();
  356. /* Notify card that there are packets ready to transmit */
  357. writel ( 0, myson->regs + MYSON_TXPDR );
  358. DBGC2 ( myson, "MYSON %p TX %d is [%llx,%llx)\n", myson, tx_idx,
  359. ( ( unsigned long long ) address ),
  360. ( ( unsigned long long ) address + iob_len ( iobuf ) ) );
  361. return 0;
  362. }
  363. /**
  364. * Poll for completed packets
  365. *
  366. * @v netdev Network device
  367. */
  368. static void myson_poll_tx ( struct net_device *netdev ) {
  369. struct myson_nic *myson = netdev->priv;
  370. struct myson_descriptor *tx;
  371. unsigned int tx_idx;
  372. /* Check for completed packets */
  373. while ( myson->tx.cons != myson->tx.prod ) {
  374. /* Get next transmit descriptor */
  375. tx_idx = ( myson->tx.cons % MYSON_NUM_TX_DESC );
  376. tx = &myson->tx.desc[tx_idx];
  377. /* Stop if descriptor is still in use */
  378. if ( tx->status & cpu_to_le32 ( MYSON_TX_STAT_OWN ) )
  379. return;
  380. /* Complete TX descriptor */
  381. if ( tx->status & cpu_to_le32 ( MYSON_TX_STAT_ABORT |
  382. MYSON_TX_STAT_CSL ) ) {
  383. DBGC ( myson, "MYSON %p TX %d completion error "
  384. "(%08x)\n", myson, tx_idx,
  385. le32_to_cpu ( tx->status ) );
  386. netdev_tx_complete_next_err ( netdev, -EIO );
  387. } else {
  388. DBGC2 ( myson, "MYSON %p TX %d complete\n",
  389. myson, tx_idx );
  390. netdev_tx_complete_next ( netdev );
  391. }
  392. myson->tx.cons++;
  393. }
  394. }
  395. /**
  396. * Poll for received packets
  397. *
  398. * @v netdev Network device
  399. */
  400. static void myson_poll_rx ( struct net_device *netdev ) {
  401. struct myson_nic *myson = netdev->priv;
  402. struct myson_descriptor *rx;
  403. struct io_buffer *iobuf;
  404. unsigned int rx_idx;
  405. size_t len;
  406. /* Check for received packets */
  407. while ( myson->rx.cons != myson->rx.prod ) {
  408. /* Get next receive descriptor */
  409. rx_idx = ( myson->rx.cons % MYSON_NUM_RX_DESC );
  410. rx = &myson->rx.desc[rx_idx];
  411. /* Stop if descriptor is still in use */
  412. if ( rx->status & MYSON_RX_STAT_OWN )
  413. return;
  414. /* Populate I/O buffer */
  415. iobuf = myson->rx_iobuf[rx_idx];
  416. myson->rx_iobuf[rx_idx] = NULL;
  417. len = MYSON_RX_STAT_FLNG ( le32_to_cpu ( rx->status ) );
  418. iob_put ( iobuf, len - 4 /* strip CRC */ );
  419. /* Hand off to network stack */
  420. if ( rx->status & cpu_to_le32 ( MYSON_RX_STAT_ES ) ) {
  421. DBGC ( myson, "MYSON %p RX %d error (length %zd, "
  422. "status %08x)\n", myson, rx_idx, len,
  423. le32_to_cpu ( rx->status ) );
  424. netdev_rx_err ( netdev, iobuf, -EIO );
  425. } else {
  426. DBGC2 ( myson, "MYSON %p RX %d complete (length "
  427. "%zd)\n", myson, rx_idx, len );
  428. netdev_rx ( netdev, iobuf );
  429. }
  430. myson->rx.cons++;
  431. }
  432. }
  433. /**
  434. * Poll for completed and received packets
  435. *
  436. * @v netdev Network device
  437. */
  438. static void myson_poll ( struct net_device *netdev ) {
  439. struct myson_nic *myson = netdev->priv;
  440. uint32_t isr;
  441. unsigned int i;
  442. /* Polling the ISR seems to really upset this card; it ends up
  443. * getting no useful PCI transfers done and, for some reason,
  444. * flooding the network with invalid packets. Work around
  445. * this by introducing deliberate delays between ISR reads.
  446. */
  447. for ( i = 0 ; i < MYSON_ISR_IODELAY_COUNT ; i++ )
  448. iodelay();
  449. /* Check for and acknowledge interrupts */
  450. isr = readl ( myson->regs + MYSON_ISR );
  451. if ( ! isr )
  452. return;
  453. writel ( isr, myson->regs + MYSON_ISR );
  454. /* Poll for TX completions, if applicable */
  455. if ( isr & MYSON_IRQ_TI )
  456. myson_poll_tx ( netdev );
  457. /* Poll for RX completionsm, if applicable */
  458. if ( isr & MYSON_IRQ_RI )
  459. myson_poll_rx ( netdev );
  460. /* Refill RX ring */
  461. myson_refill_rx ( netdev );
  462. }
  463. /**
  464. * Enable or disable interrupts
  465. *
  466. * @v netdev Network device
  467. * @v enable Interrupts should be enabled
  468. */
  469. static void myson_irq ( struct net_device *netdev, int enable ) {
  470. struct myson_nic *myson = netdev->priv;
  471. uint32_t imr;
  472. imr = ( enable ? ( MYSON_IRQ_TI | MYSON_IRQ_RI ) : 0 );
  473. writel ( imr, myson->regs + MYSON_IMR );
  474. }
  475. /** Myson network device operations */
  476. static struct net_device_operations myson_operations = {
  477. .open = myson_open,
  478. .close = myson_close,
  479. .transmit = myson_transmit,
  480. .poll = myson_poll,
  481. .irq = myson_irq,
  482. };
  483. /******************************************************************************
  484. *
  485. * PCI interface
  486. *
  487. ******************************************************************************
  488. */
  489. /**
  490. * Probe PCI device
  491. *
  492. * @v pci PCI device
  493. * @ret rc Return status code
  494. */
  495. static int myson_probe ( struct pci_device *pci ) {
  496. struct net_device *netdev;
  497. struct myson_nic *myson;
  498. union myson_physical_address mac;
  499. int rc;
  500. /* Allocate and initialise net device */
  501. netdev = alloc_etherdev ( sizeof ( *myson ) );
  502. if ( ! netdev ) {
  503. rc = -ENOMEM;
  504. goto err_alloc;
  505. }
  506. netdev_init ( netdev, &myson_operations );
  507. myson = netdev->priv;
  508. pci_set_drvdata ( pci, netdev );
  509. netdev->dev = &pci->dev;
  510. memset ( myson, 0, sizeof ( *myson ) );
  511. myson_init_ring ( &myson->tx, MYSON_NUM_TX_DESC, MYSON_TXLBA );
  512. myson_init_ring ( &myson->rx, MYSON_NUM_RX_DESC, MYSON_RXLBA );
  513. /* Fix up PCI device */
  514. adjust_pci_device ( pci );
  515. /* Map registers */
  516. myson->regs = ioremap ( pci->membase, MYSON_BAR_SIZE );
  517. if ( ! myson->regs ) {
  518. rc = -ENODEV;
  519. goto err_ioremap;
  520. }
  521. /* Reset the NIC */
  522. if ( ( rc = myson_reset ( myson ) ) != 0 )
  523. goto err_reset;
  524. /* Read MAC address */
  525. mac.reg.low = cpu_to_le32 ( readl ( myson->regs + MYSON_PAR0 ) );
  526. mac.reg.high = cpu_to_le32 ( readl ( myson->regs + MYSON_PAR4 ) );
  527. memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN );
  528. /* Register network device */
  529. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  530. goto err_register_netdev;
  531. /* Mark as link up; we don't yet handle link state */
  532. netdev_link_up ( netdev );
  533. return 0;
  534. unregister_netdev ( netdev );
  535. err_register_netdev:
  536. myson_reset ( myson );
  537. err_reset:
  538. iounmap ( myson->regs );
  539. err_ioremap:
  540. netdev_nullify ( netdev );
  541. netdev_put ( netdev );
  542. err_alloc:
  543. return rc;
  544. }
  545. /**
  546. * Remove PCI device
  547. *
  548. * @v pci PCI device
  549. */
  550. static void myson_remove ( struct pci_device *pci ) {
  551. struct net_device *netdev = pci_get_drvdata ( pci );
  552. struct myson_nic *myson = netdev->priv;
  553. /* Unregister network device */
  554. unregister_netdev ( netdev );
  555. /* Reset card */
  556. myson_reset ( myson );
  557. /* Free network device */
  558. iounmap ( myson->regs );
  559. netdev_nullify ( netdev );
  560. netdev_put ( netdev );
  561. }
  562. /** Myson PCI device IDs */
  563. static struct pci_device_id myson_nics[] = {
  564. PCI_ROM ( 0x1516, 0x0800, "mtd800", "MTD-8xx", 0 ),
  565. PCI_ROM ( 0x1516, 0x0803, "mtd803", "Surecom EP-320X-S", 0 ),
  566. PCI_ROM ( 0x1516, 0x0891, "mtd891", "MTD-8xx", 0 ),
  567. };
  568. /** Myson PCI driver */
  569. struct pci_driver myson_driver __pci_driver = {
  570. .ids = myson_nics,
  571. .id_count = ( sizeof ( myson_nics ) / sizeof ( myson_nics[0] ) ),
  572. .probe = myson_probe,
  573. .remove = myson_remove,
  574. };