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.

rtl8139.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /* rtl8139.c - etherboot driver for the Realtek 8139 chipset
  2. ported from the linux driver written by Donald Becker
  3. by Rainer Bawidamann (Rainer.Bawidamann@informatik.uni-ulm.de) 1999
  4. This software may be used and distributed according to the terms
  5. of the GNU Public License, incorporated herein by reference.
  6. changes to the original driver:
  7. - removed support for interrupts, switching to polling mode (yuck!)
  8. - removed support for the 8129 chip (external MII)
  9. */
  10. /*********************************************************************/
  11. /* Revision History */
  12. /*********************************************************************/
  13. /*
  14. 27 May 2006 mcb30@users.sourceforge.net (Michael Brown)
  15. Rewrote to use the new net driver API, the updated PCI API, and
  16. the generic three-wire serial device support for EEPROM access.
  17. 28 Dec 2002 ken_yap@users.sourceforge.net (Ken Yap)
  18. Put in virt_to_bus calls to allow Etherboot relocation.
  19. 06 Apr 2001 ken_yap@users.sourceforge.net (Ken Yap)
  20. Following email from Hyun-Joon Cha, added a disable routine, otherwise
  21. NIC remains live and can crash the kernel later.
  22. 4 Feb 2000 espenlaub@informatik.uni-ulm.de (Klaus Espenlaub)
  23. Shuffled things around, removed the leftovers from the 8129 support
  24. that was in the Linux driver and added a bit more 8139 definitions.
  25. Moved the 8K receive buffer to a fixed, available address outside the
  26. 0x98000-0x9ffff range. This is a bit of a hack, but currently the only
  27. way to make room for the Etherboot features that need substantial amounts
  28. of code like the ANSI console support. Currently the buffer is just below
  29. 0x10000, so this even conforms to the tagged boot image specification,
  30. which reserves the ranges 0x00000-0x10000 and 0x98000-0xA0000. My
  31. interpretation of this "reserved" is that Etherboot may do whatever it
  32. likes, as long as its environment is kept intact (like the BIOS
  33. variables). Hopefully fixed rtl_poll() once and for all. The symptoms
  34. were that if Etherboot was left at the boot menu for several minutes, the
  35. first eth_poll failed. Seems like I am the only person who does this.
  36. First of all I fixed the debugging code and then set out for a long bug
  37. hunting session. It took me about a week full time work - poking around
  38. various places in the driver, reading Don Becker's and Jeff Garzik's Linux
  39. driver and even the FreeBSD driver (what a piece of crap!) - and
  40. eventually spotted the nasty thing: the transmit routine was acknowledging
  41. each and every interrupt pending, including the RxOverrun and RxFIFIOver
  42. interrupts. This confused the RTL8139 thoroughly. It destroyed the
  43. Rx ring contents by dumping the 2K FIFO contents right where we wanted to
  44. get the next packet. Oh well, what fun.
  45. 18 Jan 2000 mdc@etherboot.org (Marty Connor)
  46. Drastically simplified error handling. Basically, if any error
  47. in transmission or reception occurs, the card is reset.
  48. Also, pointed all transmit descriptors to the same buffer to
  49. save buffer space. This should decrease driver size and avoid
  50. corruption because of exceeding 32K during runtime.
  51. 28 Jul 1999 (Matthias Meixner - meixner@rbg.informatik.tu-darmstadt.de)
  52. rtl_poll was quite broken: it used the RxOK interrupt flag instead
  53. of the RxBufferEmpty flag which often resulted in very bad
  54. transmission performace - below 1kBytes/s.
  55. */
  56. #include <stdint.h>
  57. #include <stdlib.h>
  58. #include <stdio.h>
  59. #include <io.h>
  60. #include <errno.h>
  61. #include <timer.h>
  62. #include <byteswap.h>
  63. #include <gpxe/pci.h>
  64. #include <gpxe/if_ether.h>
  65. #include <gpxe/ethernet.h>
  66. #include <gpxe/iobuf.h>
  67. #include <gpxe/netdevice.h>
  68. #include <gpxe/spi_bit.h>
  69. #include <gpxe/threewire.h>
  70. #include <gpxe/nvo.h>
  71. #define TX_RING_SIZE 4
  72. struct rtl8139_tx {
  73. unsigned int next;
  74. struct io_buffer *iobuf[TX_RING_SIZE];
  75. };
  76. struct rtl8139_rx {
  77. void *ring;
  78. unsigned int offset;
  79. };
  80. struct rtl8139_nic {
  81. unsigned short ioaddr;
  82. struct rtl8139_tx tx;
  83. struct rtl8139_rx rx;
  84. struct spi_bit_basher spibit;
  85. struct spi_device eeprom;
  86. struct nvo_block nvo;
  87. };
  88. /* Tuning Parameters */
  89. #define TX_FIFO_THRESH 256 /* In bytes, rounded down to 32 byte units. */
  90. #define RX_FIFO_THRESH 4 /* Rx buffer level before first PCI xfer. */
  91. #define RX_DMA_BURST 4 /* Maximum PCI burst, '4' is 256 bytes */
  92. #define TX_DMA_BURST 4 /* Calculate as 16<<val. */
  93. #define TX_IPG 3 /* This is the only valid value */
  94. #define RX_BUF_LEN_IDX 0 /* 0, 1, 2 is allowed - 8,16,32K rx buffer */
  95. #define RX_BUF_LEN ( (8192 << RX_BUF_LEN_IDX) )
  96. #define RX_BUF_PAD 4
  97. /* Symbolic offsets to registers. */
  98. enum RTL8139_registers {
  99. MAC0=0, /* Ethernet hardware address. */
  100. MAR0=8, /* Multicast filter. */
  101. TxStatus0=0x10, /* Transmit status (four 32bit registers). */
  102. TxAddr0=0x20, /* Tx descriptors (also four 32bit). */
  103. RxBuf=0x30, RxEarlyCnt=0x34, RxEarlyStatus=0x36,
  104. ChipCmd=0x37, RxBufPtr=0x38, RxBufAddr=0x3A,
  105. IntrMask=0x3C, IntrStatus=0x3E,
  106. TxConfig=0x40, RxConfig=0x44,
  107. Timer=0x48, /* general-purpose counter. */
  108. RxMissed=0x4C, /* 24 bits valid, write clears. */
  109. Cfg9346=0x50, Config0=0x51, Config1=0x52,
  110. TimerIntrReg=0x54, /* intr if gp counter reaches this value */
  111. MediaStatus=0x58,
  112. Config3=0x59,
  113. MultiIntr=0x5C,
  114. RevisionID=0x5E, /* revision of the RTL8139 chip */
  115. TxSummary=0x60,
  116. MII_BMCR=0x62, MII_BMSR=0x64, NWayAdvert=0x66, NWayLPAR=0x68,
  117. NWayExpansion=0x6A,
  118. DisconnectCnt=0x6C, FalseCarrierCnt=0x6E,
  119. NWayTestReg=0x70,
  120. RxCnt=0x72, /* packet received counter */
  121. CSCR=0x74, /* chip status and configuration register */
  122. PhyParm1=0x78,TwisterParm=0x7c,PhyParm2=0x80, /* undocumented */
  123. /* from 0x84 onwards are a number of power management/wakeup frame
  124. * definitions we will probably never need to know about. */
  125. };
  126. enum RxEarlyStatusBits {
  127. ERGood=0x08, ERBad=0x04, EROVW=0x02, EROK=0x01
  128. };
  129. enum ChipCmdBits {
  130. CmdReset=0x10, CmdRxEnb=0x08, CmdTxEnb=0x04, RxBufEmpty=0x01, };
  131. enum IntrMaskBits {
  132. SERR=0x8000, TimeOut=0x4000, LenChg=0x2000,
  133. FOVW=0x40, PUN_LinkChg=0x20, RXOVW=0x10,
  134. TER=0x08, TOK=0x04, RER=0x02, ROK=0x01
  135. };
  136. /* Interrupt register bits, using my own meaningful names. */
  137. enum IntrStatusBits {
  138. PCIErr=0x8000, PCSTimeout=0x4000, CableLenChange= 0x2000,
  139. RxFIFOOver=0x40, RxUnderrun=0x20, RxOverflow=0x10,
  140. TxErr=0x08, TxOK=0x04, RxErr=0x02, RxOK=0x01,
  141. };
  142. enum TxStatusBits {
  143. TxHostOwns=0x2000, TxUnderrun=0x4000, TxStatOK=0x8000,
  144. TxOutOfWindow=0x20000000, TxAborted=0x40000000,
  145. TxCarrierLost=0x80000000,
  146. };
  147. enum RxStatusBits {
  148. RxMulticast=0x8000, RxPhysical=0x4000, RxBroadcast=0x2000,
  149. RxBadSymbol=0x0020, RxRunt=0x0010, RxTooLong=0x0008, RxCRCErr=0x0004,
  150. RxBadAlign=0x0002, RxStatusOK=0x0001,
  151. };
  152. enum MediaStatusBits {
  153. MSRTxFlowEnable=0x80, MSRRxFlowEnable=0x40, MSRSpeed10=0x08,
  154. MSRLinkFail=0x04, MSRRxPauseFlag=0x02, MSRTxPauseFlag=0x01,
  155. };
  156. enum MIIBMCRBits {
  157. BMCRReset=0x8000, BMCRSpeed100=0x2000, BMCRNWayEnable=0x1000,
  158. BMCRRestartNWay=0x0200, BMCRDuplex=0x0100,
  159. };
  160. enum CSCRBits {
  161. CSCR_LinkOKBit=0x0400, CSCR_LinkChangeBit=0x0800,
  162. CSCR_LinkStatusBits=0x0f000, CSCR_LinkDownOffCmd=0x003c0,
  163. CSCR_LinkDownCmd=0x0f3c0,
  164. };
  165. enum RxConfigBits {
  166. RxCfgWrap=0x80,
  167. Eeprom9356=0x40,
  168. AcceptErr=0x20, AcceptRunt=0x10, AcceptBroadcast=0x08,
  169. AcceptMulticast=0x04, AcceptMyPhys=0x02, AcceptAllPhys=0x01,
  170. };
  171. enum Config1Bits {
  172. VPDEnable=0x02,
  173. };
  174. /* EEPROM access */
  175. #define EE_M1 0x80 /* Mode select bit 1 */
  176. #define EE_M0 0x40 /* Mode select bit 0 */
  177. #define EE_CS 0x08 /* EEPROM chip select */
  178. #define EE_SK 0x04 /* EEPROM shift clock */
  179. #define EE_DI 0x02 /* Data in */
  180. #define EE_DO 0x01 /* Data out */
  181. /* Offsets within EEPROM (these are word offsets) */
  182. #define EE_MAC 7
  183. static const uint8_t rtl_ee_bits[] = {
  184. [SPI_BIT_SCLK] = EE_SK,
  185. [SPI_BIT_MOSI] = EE_DI,
  186. [SPI_BIT_MISO] = EE_DO,
  187. [SPI_BIT_SS(0)] = ( EE_CS | EE_M1 ),
  188. };
  189. static int rtl_spi_read_bit ( struct bit_basher *basher,
  190. unsigned int bit_id ) {
  191. struct rtl8139_nic *rtl = container_of ( basher, struct rtl8139_nic,
  192. spibit.basher );
  193. uint8_t mask = rtl_ee_bits[bit_id];
  194. uint8_t eereg;
  195. eereg = inb ( rtl->ioaddr + Cfg9346 );
  196. return ( eereg & mask );
  197. }
  198. static void rtl_spi_write_bit ( struct bit_basher *basher,
  199. unsigned int bit_id, unsigned long data ) {
  200. struct rtl8139_nic *rtl = container_of ( basher, struct rtl8139_nic,
  201. spibit.basher );
  202. uint8_t mask = rtl_ee_bits[bit_id];
  203. uint8_t eereg;
  204. eereg = inb ( rtl->ioaddr + Cfg9346 );
  205. eereg &= ~mask;
  206. eereg |= ( data & mask );
  207. outb ( eereg, rtl->ioaddr + Cfg9346 );
  208. }
  209. static struct bit_basher_operations rtl_basher_ops = {
  210. .read = rtl_spi_read_bit,
  211. .write = rtl_spi_write_bit,
  212. };
  213. /** Portion of EEPROM available for non-volatile stored options
  214. *
  215. * We use offset 0x40 (i.e. address 0x20), length 0x40. This block is
  216. * marked as VPD in the rtl8139 datasheets, so we use it only if we
  217. * detect that the card is not supporting VPD.
  218. */
  219. static struct nvo_fragment rtl_nvo_fragments[] = {
  220. { 0x20, 0x40 },
  221. { 0, 0 }
  222. };
  223. /**
  224. * Set up for EEPROM access
  225. *
  226. * @v rtl RTL8139 NIC
  227. */
  228. void rtl_init_eeprom ( struct rtl8139_nic *rtl ) {
  229. int ee9356;
  230. int vpd;
  231. /* Initialise three-wire bus */
  232. rtl->spibit.basher.op = &rtl_basher_ops;
  233. rtl->spibit.bus.mode = SPI_MODE_THREEWIRE;
  234. init_spi_bit_basher ( &rtl->spibit );
  235. /* Detect EEPROM type and initialise three-wire device */
  236. ee9356 = ( inw ( rtl->ioaddr + RxConfig ) & Eeprom9356 );
  237. if ( ee9356 ) {
  238. DBG ( "EEPROM is an AT93C56\n" );
  239. init_at93c56 ( &rtl->eeprom, 16 );
  240. } else {
  241. DBG ( "EEPROM is an AT93C46\n" );
  242. init_at93c46 ( &rtl->eeprom, 16 );
  243. }
  244. rtl->eeprom.bus = &rtl->spibit.bus;
  245. /* Initialise space for non-volatile options, if available */
  246. vpd = ( inw ( rtl->ioaddr + Config1 ) & VPDEnable );
  247. if ( vpd ) {
  248. DBG ( "EEPROM in use for VPD; cannot use for options\n" );
  249. } else {
  250. rtl->nvo.nvs = &rtl->eeprom.nvs;
  251. rtl->nvo.fragments = rtl_nvo_fragments;
  252. }
  253. }
  254. /**
  255. * Reset NIC
  256. *
  257. * @v rtl RTL8139 NIC
  258. *
  259. * Issues a hardware reset and waits for the reset to complete.
  260. */
  261. static void rtl_reset ( struct rtl8139_nic *rtl ) {
  262. /* Reset chip */
  263. outb ( CmdReset, rtl->ioaddr + ChipCmd );
  264. mdelay ( 10 );
  265. memset ( &rtl->tx, 0, sizeof ( rtl->tx ) );
  266. rtl->rx.offset = 0;
  267. }
  268. /**
  269. * Open NIC
  270. *
  271. * @v netdev Net device
  272. * @ret rc Return status code
  273. */
  274. static int rtl_open ( struct net_device *netdev ) {
  275. struct rtl8139_nic *rtl = netdev->priv;
  276. int i;
  277. /* Program the MAC address */
  278. for ( i = 0 ; i < ETH_ALEN ; i++ )
  279. outb ( netdev->ll_addr[i], rtl->ioaddr + MAC0 + i );
  280. /* Set up RX ring */
  281. rtl->rx.ring = malloc ( RX_BUF_LEN + RX_BUF_PAD );
  282. if ( ! rtl->rx.ring )
  283. return -ENOMEM;
  284. outl ( virt_to_bus ( rtl->rx.ring ), rtl->ioaddr + RxBuf );
  285. DBG ( "RX ring at %lx\n", virt_to_bus ( rtl->rx.ring ) );
  286. /* Enable TX and RX */
  287. outb ( ( CmdRxEnb | CmdTxEnb ), rtl->ioaddr + ChipCmd );
  288. outl ( ( ( RX_FIFO_THRESH << 13 ) | ( RX_BUF_LEN_IDX << 11 ) |
  289. ( RX_DMA_BURST << 8 ) | AcceptBroadcast | AcceptMulticast |
  290. AcceptMyPhys ), rtl->ioaddr + RxConfig );
  291. outl ( 0xffffffffUL, rtl->ioaddr + MAR0 + 0 );
  292. outl ( 0xffffffffUL, rtl->ioaddr + MAR0 + 4 );
  293. outl ( ( ( TX_DMA_BURST << 8 ) | ( TX_IPG << 24 ) ),
  294. rtl->ioaddr + TxConfig );
  295. return 0;
  296. }
  297. /**
  298. * Close NIC
  299. *
  300. * @v netdev Net device
  301. */
  302. static void rtl_close ( struct net_device *netdev ) {
  303. struct rtl8139_nic *rtl = netdev->priv;
  304. /* Reset the hardware to disable everything in one go */
  305. rtl_reset ( rtl );
  306. /* Free RX ring */
  307. free ( rtl->rx.ring );
  308. rtl->rx.ring = NULL;
  309. }
  310. /**
  311. * Transmit packet
  312. *
  313. * @v netdev Network device
  314. * @v iobuf I/O buffer
  315. * @ret rc Return status code
  316. */
  317. static int rtl_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
  318. struct rtl8139_nic *rtl = netdev->priv;
  319. /* Check for space in TX ring */
  320. if ( rtl->tx.iobuf[rtl->tx.next] != NULL ) {
  321. printf ( "TX overflow\n" );
  322. return -ENOBUFS;
  323. }
  324. /* Pad and align packet */
  325. iob_pad ( iobuf, ETH_ZLEN );
  326. /* Add to TX ring */
  327. DBG ( "TX id %d at %lx+%x\n", rtl->tx.next,
  328. virt_to_bus ( iobuf->data ), iob_len ( iobuf ) );
  329. rtl->tx.iobuf[rtl->tx.next] = iobuf;
  330. outl ( virt_to_bus ( iobuf->data ),
  331. rtl->ioaddr + TxAddr0 + 4 * rtl->tx.next );
  332. outl ( ( ( ( TX_FIFO_THRESH & 0x7e0 ) << 11 ) | iob_len ( iobuf ) ),
  333. rtl->ioaddr + TxStatus0 + 4 * rtl->tx.next );
  334. rtl->tx.next = ( rtl->tx.next + 1 ) % TX_RING_SIZE;
  335. return 0;
  336. }
  337. /**
  338. * Poll for received packets
  339. *
  340. * @v netdev Network device
  341. * @v rx_quota Maximum number of packets to receive
  342. */
  343. static void rtl_poll ( struct net_device *netdev, unsigned int rx_quota ) {
  344. struct rtl8139_nic *rtl = netdev->priv;
  345. unsigned int status;
  346. unsigned int tsad;
  347. unsigned int rx_status;
  348. unsigned int rx_len;
  349. struct io_buffer *rx_iob;
  350. int wrapped_len;
  351. int i;
  352. /* Acknowledge interrupts */
  353. status = inw ( rtl->ioaddr + IntrStatus );
  354. if ( ! status )
  355. return;
  356. outw ( status, rtl->ioaddr + IntrStatus );
  357. /* Handle TX completions */
  358. tsad = inw ( rtl->ioaddr + TxSummary );
  359. for ( i = 0 ; i < TX_RING_SIZE ; i++ ) {
  360. if ( ( rtl->tx.iobuf[i] != NULL ) && ( tsad & ( 1 << i ) ) ) {
  361. DBG ( "TX id %d complete\n", i );
  362. netdev_tx_complete ( netdev, rtl->tx.iobuf[i] );
  363. rtl->tx.iobuf[i] = NULL;
  364. }
  365. }
  366. /* Handle received packets */
  367. while ( rx_quota && ! ( inw ( rtl->ioaddr + ChipCmd ) & RxBufEmpty ) ){
  368. rx_status = * ( ( uint16_t * )
  369. ( rtl->rx.ring + rtl->rx.offset ) );
  370. rx_len = * ( ( uint16_t * )
  371. ( rtl->rx.ring + rtl->rx.offset + 2 ) );
  372. if ( rx_status & RxOK ) {
  373. DBG ( "RX packet at offset %x+%x\n", rtl->rx.offset,
  374. rx_len );
  375. rx_iob = alloc_iob ( rx_len );
  376. if ( ! rx_iob ) {
  377. /* Leave packet for next call to poll() */
  378. break;
  379. }
  380. wrapped_len = ( ( rtl->rx.offset + 4 + rx_len )
  381. - RX_BUF_LEN );
  382. if ( wrapped_len < 0 )
  383. wrapped_len = 0;
  384. memcpy ( iob_put ( rx_iob, rx_len - wrapped_len ),
  385. rtl->rx.ring + rtl->rx.offset + 4,
  386. rx_len - wrapped_len );
  387. memcpy ( iob_put ( rx_iob, wrapped_len ),
  388. rtl->rx.ring, wrapped_len );
  389. netdev_rx ( netdev, rx_iob );
  390. rx_quota--;
  391. } else {
  392. DBG ( "RX bad packet (status %#04x len %d)\n",
  393. rx_status, rx_len );
  394. }
  395. rtl->rx.offset = ( ( ( rtl->rx.offset + 4 + rx_len + 3 ) & ~3 )
  396. % RX_BUF_LEN );
  397. outw ( rtl->rx.offset - 16, rtl->ioaddr + RxBufPtr );
  398. }
  399. }
  400. #if 0
  401. static void rtl_irq(struct nic *nic, irq_action_t action)
  402. {
  403. unsigned int mask;
  404. /* Bit of a guess as to which interrupts we should allow */
  405. unsigned int interested = ROK | RER | RXOVW | FOVW | SERR;
  406. switch ( action ) {
  407. case DISABLE :
  408. case ENABLE :
  409. mask = inw(rtl->ioaddr + IntrMask);
  410. mask = mask & ~interested;
  411. if ( action == ENABLE ) mask = mask | interested;
  412. outw(mask, rtl->ioaddr + IntrMask);
  413. break;
  414. case FORCE :
  415. /* Apparently writing a 1 to this read-only bit of a
  416. * read-only and otherwise unrelated register will
  417. * force an interrupt. If you ever want to see how
  418. * not to write a datasheet, read the one for the
  419. * RTL8139...
  420. */
  421. outb(EROK, rtl->ioaddr + RxEarlyStatus);
  422. break;
  423. }
  424. }
  425. #endif
  426. /**
  427. * Probe PCI device
  428. *
  429. * @v pci PCI device
  430. * @v id PCI ID
  431. * @ret rc Return status code
  432. */
  433. static int rtl_probe ( struct pci_device *pci,
  434. const struct pci_device_id *id __unused ) {
  435. struct net_device *netdev;
  436. struct rtl8139_nic *rtl = NULL;
  437. int registered_netdev = 0;
  438. int rc;
  439. /* Fix up PCI device */
  440. adjust_pci_device ( pci );
  441. /* Allocate net device */
  442. netdev = alloc_etherdev ( sizeof ( *rtl ) );
  443. if ( ! netdev ) {
  444. rc = -ENOMEM;
  445. goto err;
  446. }
  447. rtl = netdev->priv;
  448. pci_set_drvdata ( pci, netdev );
  449. netdev->dev = &pci->dev;
  450. memset ( rtl, 0, sizeof ( *rtl ) );
  451. rtl->ioaddr = pci->ioaddr;
  452. /* Reset the NIC, set up EEPROM access and read MAC address */
  453. rtl_reset ( rtl );
  454. rtl_init_eeprom ( rtl );
  455. nvs_read ( &rtl->eeprom.nvs, EE_MAC, netdev->ll_addr, ETH_ALEN );
  456. /* Point to NIC specific routines */
  457. netdev->open = rtl_open;
  458. netdev->close = rtl_close;
  459. netdev->transmit = rtl_transmit;
  460. netdev->poll = rtl_poll;
  461. /* Register network device */
  462. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  463. goto err;
  464. registered_netdev = 1;
  465. /* Register non-volatile storage */
  466. if ( rtl->nvo.nvs ) {
  467. if ( ( rc = nvo_register ( &rtl->nvo ) ) != 0 )
  468. goto err;
  469. }
  470. return 0;
  471. err:
  472. /* Disable NIC */
  473. if ( rtl )
  474. rtl_reset ( rtl );
  475. if ( registered_netdev )
  476. unregister_netdev ( netdev );
  477. /* Free net device */
  478. free_netdev ( netdev );
  479. return rc;
  480. }
  481. /**
  482. * Remove PCI device
  483. *
  484. * @v pci PCI device
  485. */
  486. static void rtl_remove ( struct pci_device *pci ) {
  487. struct net_device *netdev = pci_get_drvdata ( pci );
  488. struct rtl8139_nic *rtl = netdev->priv;
  489. if ( rtl->nvo.nvs )
  490. nvo_unregister ( &rtl->nvo );
  491. unregister_netdev ( netdev );
  492. rtl_reset ( rtl );
  493. free_netdev ( netdev );
  494. }
  495. static struct pci_device_id rtl8139_nics[] = {
  496. PCI_ROM(0x10ec, 0x8129, "rtl8129", "Realtek 8129"),
  497. PCI_ROM(0x10ec, 0x8139, "rtl8139", "Realtek 8139"),
  498. PCI_ROM(0x10ec, 0x8138, "rtl8139b", "Realtek 8139B"),
  499. PCI_ROM(0x1186, 0x1300, "dfe538", "DFE530TX+/DFE538TX"),
  500. PCI_ROM(0x1113, 0x1211, "smc1211-1", "SMC EZ10/100"),
  501. PCI_ROM(0x1112, 0x1211, "smc1211", "SMC EZ10/100"),
  502. PCI_ROM(0x1500, 0x1360, "delta8139", "Delta Electronics 8139"),
  503. PCI_ROM(0x4033, 0x1360, "addtron8139", "Addtron Technology 8139"),
  504. PCI_ROM(0x1186, 0x1340, "dfe690txd", "D-Link DFE690TXD"),
  505. PCI_ROM(0x13d1, 0xab06, "fe2000vx", "AboCom FE2000VX"),
  506. PCI_ROM(0x1259, 0xa117, "allied8139", "Allied Telesyn 8139"),
  507. PCI_ROM(0x14ea, 0xab06, "fnw3603tx", "Planex FNW-3603-TX"),
  508. PCI_ROM(0x14ea, 0xab07, "fnw3800tx", "Planex FNW-3800-TX"),
  509. PCI_ROM(0xffff, 0x8139, "clone-rtl8139", "Cloned 8139"),
  510. };
  511. struct pci_driver rtl8139_driver __pci_driver = {
  512. .ids = rtl8139_nics,
  513. .id_count = ( sizeof ( rtl8139_nics ) / sizeof ( rtl8139_nics[0] ) ),
  514. .probe = rtl_probe,
  515. .remove = rtl_remove,
  516. };