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.

realtek.c 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * (EEPROM code originally implemented for rtl8139.c)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. */
  21. FILE_LICENCE ( GPL2_OR_LATER );
  22. #include <stdint.h>
  23. #include <string.h>
  24. #include <unistd.h>
  25. #include <errno.h>
  26. #include <byteswap.h>
  27. #include <ipxe/netdevice.h>
  28. #include <ipxe/ethernet.h>
  29. #include <ipxe/if_ether.h>
  30. #include <ipxe/iobuf.h>
  31. #include <ipxe/malloc.h>
  32. #include <ipxe/pci.h>
  33. #include <ipxe/nvs.h>
  34. #include <ipxe/threewire.h>
  35. #include <ipxe/bitbash.h>
  36. #include <ipxe/mii.h>
  37. #include "realtek.h"
  38. /** @file
  39. *
  40. * Realtek 10/100/1000 network card driver
  41. *
  42. * Based on the following datasheets:
  43. *
  44. * http://www.datasheetarchive.com/dl/Datasheets-8/DSA-153536.pdf
  45. * http://www.datasheetarchive.com/indexdl/Datasheet-028/DSA00494723.pdf
  46. */
  47. /******************************************************************************
  48. *
  49. * Debugging
  50. *
  51. ******************************************************************************
  52. */
  53. /**
  54. * Dump all registers (for debugging)
  55. *
  56. * @v rtl Realtek device
  57. */
  58. static __attribute__ (( unused )) void realtek_dump ( struct realtek_nic *rtl ){
  59. uint8_t regs[256];
  60. unsigned int i;
  61. /* Do nothing unless debug output is enabled */
  62. if ( ! DBG_LOG )
  63. return;
  64. /* Dump registers (via byte accesses; may not work for all registers) */
  65. for ( i = 0 ; i < sizeof ( regs ) ; i++ )
  66. regs[i] = readb ( rtl->regs + i );
  67. DBGC ( rtl, "REALTEK %p register dump:\n", rtl );
  68. DBGC_HDA ( rtl, 0, regs, sizeof ( regs ) );
  69. }
  70. /******************************************************************************
  71. *
  72. * EEPROM interface
  73. *
  74. ******************************************************************************
  75. */
  76. /** Pin mapping for SPI bit-bashing interface */
  77. static const uint8_t realtek_eeprom_bits[] = {
  78. [SPI_BIT_SCLK] = RTL_9346CR_EESK,
  79. [SPI_BIT_MOSI] = RTL_9346CR_EEDI,
  80. [SPI_BIT_MISO] = RTL_9346CR_EEDO,
  81. [SPI_BIT_SS(0)] = RTL_9346CR_EECS,
  82. };
  83. /**
  84. * Open bit-bashing interface
  85. *
  86. * @v basher Bit-bashing interface
  87. */
  88. static void realtek_spi_open_bit ( struct bit_basher *basher ) {
  89. struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
  90. spibit.basher );
  91. /* Enable EEPROM access */
  92. writeb ( RTL_9346CR_EEM_EEPROM, rtl->regs + RTL_9346CR );
  93. readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
  94. }
  95. /**
  96. * Close bit-bashing interface
  97. *
  98. * @v basher Bit-bashing interface
  99. */
  100. static void realtek_spi_close_bit ( struct bit_basher *basher ) {
  101. struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
  102. spibit.basher );
  103. /* Disable EEPROM access */
  104. writeb ( RTL_9346CR_EEM_NORMAL, rtl->regs + RTL_9346CR );
  105. readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
  106. }
  107. /**
  108. * Read input bit
  109. *
  110. * @v basher Bit-bashing interface
  111. * @v bit_id Bit number
  112. * @ret zero Input is a logic 0
  113. * @ret non-zero Input is a logic 1
  114. */
  115. static int realtek_spi_read_bit ( struct bit_basher *basher,
  116. unsigned int bit_id ) {
  117. struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
  118. spibit.basher );
  119. uint8_t mask = realtek_eeprom_bits[bit_id];
  120. uint8_t reg;
  121. DBG_DISABLE ( DBGLVL_IO );
  122. reg = readb ( rtl->regs + RTL_9346CR );
  123. DBG_ENABLE ( DBGLVL_IO );
  124. return ( reg & mask );
  125. }
  126. /**
  127. * Set/clear output bit
  128. *
  129. * @v basher Bit-bashing interface
  130. * @v bit_id Bit number
  131. * @v data Value to write
  132. */
  133. static void realtek_spi_write_bit ( struct bit_basher *basher,
  134. unsigned int bit_id, unsigned long data ) {
  135. struct realtek_nic *rtl = container_of ( basher, struct realtek_nic,
  136. spibit.basher );
  137. uint8_t mask = realtek_eeprom_bits[bit_id];
  138. uint8_t reg;
  139. DBG_DISABLE ( DBGLVL_IO );
  140. reg = readb ( rtl->regs + RTL_9346CR );
  141. reg &= ~mask;
  142. reg |= ( data & mask );
  143. writeb ( reg, rtl->regs + RTL_9346CR );
  144. readb ( rtl->regs + RTL_9346CR ); /* Ensure write reaches chip */
  145. DBG_ENABLE ( DBGLVL_IO );
  146. }
  147. /** SPI bit-bashing interface */
  148. static struct bit_basher_operations realtek_basher_ops = {
  149. .open = realtek_spi_open_bit,
  150. .close = realtek_spi_close_bit,
  151. .read = realtek_spi_read_bit,
  152. .write = realtek_spi_write_bit,
  153. };
  154. /**
  155. * Initialise EEPROM
  156. *
  157. * @v netdev Network device
  158. * @ret rc Return status code
  159. */
  160. static int realtek_init_eeprom ( struct net_device *netdev ) {
  161. struct realtek_nic *rtl = netdev->priv;
  162. uint16_t id;
  163. int rc;
  164. /* Initialise SPI bit-bashing interface */
  165. rtl->spibit.basher.op = &realtek_basher_ops;
  166. rtl->spibit.bus.mode = SPI_MODE_THREEWIRE;
  167. init_spi_bit_basher ( &rtl->spibit );
  168. /* Detect EEPROM type and initialise three-wire device */
  169. if ( readl ( rtl->regs + RTL_RCR ) & RTL_RCR_9356SEL ) {
  170. DBGC ( rtl, "REALTEK %p EEPROM is a 93C56\n", rtl );
  171. init_at93c56 ( &rtl->eeprom, 16 );
  172. } else {
  173. DBGC ( rtl, "REALTEK %p EEPROM is a 93C46\n", rtl );
  174. init_at93c46 ( &rtl->eeprom, 16 );
  175. }
  176. rtl->eeprom.bus = &rtl->spibit.bus;
  177. /* Check for EEPROM presence. Some onboard NICs will have no
  178. * EEPROM connected, with the BIOS being responsible for
  179. * programming the initial register values.
  180. */
  181. if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_ID,
  182. &id, sizeof ( id ) ) ) != 0 ) {
  183. DBGC ( rtl, "REALTEK %p could not read EEPROM ID: %s\n",
  184. rtl, strerror ( rc ) );
  185. return rc;
  186. }
  187. if ( id != cpu_to_le16 ( RTL_EEPROM_ID_MAGIC ) ) {
  188. DBGC ( rtl, "REALTEK %p EEPROM ID incorrect (%#04x); assuming "
  189. "no EEPROM\n", rtl, le16_to_cpu ( id ) );
  190. return -ENODEV;
  191. }
  192. /* Initialise space for non-volatile options, if available
  193. *
  194. * We use offset 0x40 (i.e. address 0x20), length 0x40. This
  195. * block is marked as VPD in the Realtek datasheets, so we use
  196. * it only if we detect that the card is not supporting VPD.
  197. */
  198. if ( readb ( rtl->regs + RTL_CONFIG1 ) & RTL_CONFIG1_VPD ) {
  199. DBGC ( rtl, "REALTEK %p EEPROM in use for VPD; cannot use "
  200. "for options\n", rtl );
  201. } else {
  202. nvo_init ( &rtl->nvo, &rtl->eeprom.nvs, RTL_EEPROM_VPD,
  203. RTL_EEPROM_VPD_LEN, NULL, &netdev->refcnt );
  204. }
  205. return 0;
  206. }
  207. /******************************************************************************
  208. *
  209. * MII interface
  210. *
  211. ******************************************************************************
  212. */
  213. /**
  214. * Read from MII register
  215. *
  216. * @v mii MII interface
  217. * @v reg Register address
  218. * @ret value Data read, or negative error
  219. */
  220. static int realtek_mii_read ( struct mii_interface *mii, unsigned int reg ) {
  221. struct realtek_nic *rtl = container_of ( mii, struct realtek_nic, mii );
  222. unsigned int i;
  223. uint32_t value;
  224. /* Fail if PHYAR register is not present */
  225. if ( ! rtl->have_phy_regs )
  226. return -ENOTSUP;
  227. /* Initiate read */
  228. writel ( RTL_PHYAR_VALUE ( 0, reg, 0 ), rtl->regs + RTL_PHYAR );
  229. /* Wait for read to complete */
  230. for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
  231. /* If read is not complete, delay 1us and retry */
  232. value = readl ( rtl->regs + RTL_PHYAR );
  233. if ( ! ( value & RTL_PHYAR_FLAG ) ) {
  234. udelay ( 1 );
  235. continue;
  236. }
  237. /* Return register value */
  238. return ( RTL_PHYAR_DATA ( value ) );
  239. }
  240. DBGC ( rtl, "REALTEK %p timed out waiting for MII read\n", rtl );
  241. return -ETIMEDOUT;
  242. }
  243. /**
  244. * Write to MII register
  245. *
  246. * @v mii MII interface
  247. * @v reg Register address
  248. * @v data Data to write
  249. * @ret rc Return status code
  250. */
  251. static int realtek_mii_write ( struct mii_interface *mii, unsigned int reg,
  252. unsigned int data) {
  253. struct realtek_nic *rtl = container_of ( mii, struct realtek_nic, mii );
  254. unsigned int i;
  255. /* Fail if PHYAR register is not present */
  256. if ( ! rtl->have_phy_regs )
  257. return -ENOTSUP;
  258. /* Initiate write */
  259. writel ( RTL_PHYAR_VALUE ( RTL_PHYAR_FLAG, reg, data ),
  260. rtl->regs + RTL_PHYAR );
  261. /* Wait for write to complete */
  262. for ( i = 0 ; i < RTL_MII_MAX_WAIT_US ; i++ ) {
  263. /* If write is not complete, delay 1us and retry */
  264. if ( readl ( rtl->regs + RTL_PHYAR ) & RTL_PHYAR_FLAG ) {
  265. udelay ( 1 );
  266. continue;
  267. }
  268. return 0;
  269. }
  270. DBGC ( rtl, "REALTEK %p timed out waiting for MII write\n", rtl );
  271. return -ETIMEDOUT;
  272. }
  273. /** Realtek MII operations */
  274. static struct mii_operations realtek_mii_operations = {
  275. .read = realtek_mii_read,
  276. .write = realtek_mii_write,
  277. };
  278. /******************************************************************************
  279. *
  280. * Device reset
  281. *
  282. ******************************************************************************
  283. */
  284. /**
  285. * Reset hardware
  286. *
  287. * @v rtl Realtek device
  288. * @ret rc Return status code
  289. */
  290. static int realtek_reset ( struct realtek_nic *rtl ) {
  291. unsigned int i;
  292. /* Issue reset */
  293. writeb ( RTL_CR_RST, rtl->regs + RTL_CR );
  294. /* Wait for reset to complete */
  295. for ( i = 0 ; i < RTL_RESET_MAX_WAIT_MS ; i++ ) {
  296. /* If reset is not complete, delay 1ms and retry */
  297. if ( readb ( rtl->regs + RTL_CR ) & RTL_CR_RST ) {
  298. mdelay ( 1 );
  299. continue;
  300. }
  301. return 0;
  302. }
  303. DBGC ( rtl, "REALTEK %p timed out waiting for reset\n", rtl );
  304. return -ETIMEDOUT;
  305. }
  306. /**
  307. * Configure PHY for Gigabit operation
  308. *
  309. * @v rtl Realtek device
  310. * @ret rc Return status code
  311. */
  312. static int realtek_phy_speed ( struct realtek_nic *rtl ) {
  313. int ctrl1000;
  314. int rc;
  315. /* Read CTRL1000 register */
  316. ctrl1000 = mii_read ( &rtl->mii, MII_CTRL1000 );
  317. if ( ctrl1000 < 0 ) {
  318. rc = ctrl1000;
  319. DBGC ( rtl, "REALTEK %p could not read CTRL1000: %s\n",
  320. rtl, strerror ( rc ) );
  321. return rc;
  322. }
  323. /* Advertise 1000Mbps speeds */
  324. ctrl1000 |= ( ADVERTISE_1000FULL | ADVERTISE_1000HALF );
  325. if ( ( rc = mii_write ( &rtl->mii, MII_CTRL1000, ctrl1000 ) ) != 0 ) {
  326. DBGC ( rtl, "REALTEK %p could not write CTRL1000: %s\n",
  327. rtl, strerror ( rc ) );
  328. return rc;
  329. }
  330. return 0;
  331. }
  332. /**
  333. * Reset PHY
  334. *
  335. * @v rtl Realtek device
  336. * @ret rc Return status code
  337. */
  338. static int realtek_phy_reset ( struct realtek_nic *rtl ) {
  339. int rc;
  340. /* Do nothing if we have no separate PHY register access */
  341. if ( ! rtl->have_phy_regs )
  342. return 0;
  343. /* Perform MII reset */
  344. if ( ( rc = mii_reset ( &rtl->mii ) ) != 0 ) {
  345. DBGC ( rtl, "REALTEK %p could not reset MII: %s\n",
  346. rtl, strerror ( rc ) );
  347. return rc;
  348. }
  349. /* Some cards (e.g. RTL8169SC) do not advertise Gigabit by
  350. * default. Try to enable advertisement of Gigabit speeds.
  351. */
  352. if ( ( rc = realtek_phy_speed ( rtl ) ) != 0 ) {
  353. /* Ignore failures, since the register may not be
  354. * present on non-Gigabit PHYs (e.g. RTL8101).
  355. */
  356. }
  357. /* Restart autonegotiation */
  358. if ( ( rc = mii_restart ( &rtl->mii ) ) != 0 ) {
  359. DBGC ( rtl, "REALTEK %p could not restart MII: %s\n",
  360. rtl, strerror ( rc ) );
  361. return rc;
  362. }
  363. return 0;
  364. }
  365. /******************************************************************************
  366. *
  367. * Link state
  368. *
  369. ******************************************************************************
  370. */
  371. /**
  372. * Check link state
  373. *
  374. * @v netdev Network device
  375. */
  376. static void realtek_check_link ( struct net_device *netdev ) {
  377. struct realtek_nic *rtl = netdev->priv;
  378. uint8_t phystatus;
  379. uint8_t msr;
  380. int link_up;
  381. /* Determine link state */
  382. if ( rtl->have_phy_regs ) {
  383. mii_dump ( &rtl->mii );
  384. phystatus = readb ( rtl->regs + RTL_PHYSTATUS );
  385. link_up = ( phystatus & RTL_PHYSTATUS_LINKSTS );
  386. DBGC ( rtl, "REALTEK %p PHY status is %02x (%s%s%s%s%s%s, "
  387. "Link%s, %sDuplex)\n", rtl, phystatus,
  388. ( ( phystatus & RTL_PHYSTATUS_ENTBI ) ? "TBI" : "GMII" ),
  389. ( ( phystatus & RTL_PHYSTATUS_TXFLOW ) ?
  390. ", TxFlow" : "" ),
  391. ( ( phystatus & RTL_PHYSTATUS_RXFLOW ) ?
  392. ", RxFlow" : "" ),
  393. ( ( phystatus & RTL_PHYSTATUS_1000MF ) ?
  394. ", 1000Mbps" : "" ),
  395. ( ( phystatus & RTL_PHYSTATUS_100M ) ?
  396. ", 100Mbps" : "" ),
  397. ( ( phystatus & RTL_PHYSTATUS_10M ) ?
  398. ", 10Mbps" : "" ),
  399. ( ( phystatus & RTL_PHYSTATUS_LINKSTS ) ?
  400. "Up" : "Down" ),
  401. ( ( phystatus & RTL_PHYSTATUS_FULLDUP ) ?
  402. "Full" : "Half" ) );
  403. } else {
  404. msr = readb ( rtl->regs + RTL_MSR );
  405. link_up = ( ! ( msr & RTL_MSR_LINKB ) );
  406. DBGC ( rtl, "REALTEK %p media status is %02x (Link%s, "
  407. "%dMbps%s%s%s%s%s)\n", rtl, msr,
  408. ( ( msr & RTL_MSR_LINKB ) ? "Down" : "Up" ),
  409. ( ( msr & RTL_MSR_SPEED_10 ) ? 10 : 100 ),
  410. ( ( msr & RTL_MSR_TXFCE ) ? ", TxFlow" : "" ),
  411. ( ( msr & RTL_MSR_RXFCE ) ? ", RxFlow" : "" ),
  412. ( ( msr & RTL_MSR_AUX_STATUS ) ? ", AuxPwr" : "" ),
  413. ( ( msr & RTL_MSR_TXPF ) ? ", TxPause" : "" ),
  414. ( ( msr & RTL_MSR_RXPF ) ? ", RxPause" : "" ) );
  415. }
  416. /* Report link state */
  417. if ( link_up ) {
  418. netdev_link_up ( netdev );
  419. } else {
  420. netdev_link_down ( netdev );
  421. }
  422. }
  423. /******************************************************************************
  424. *
  425. * Network device interface
  426. *
  427. ******************************************************************************
  428. */
  429. /**
  430. * Create receive buffer (legacy mode)
  431. *
  432. * @v rtl Realtek device
  433. * @ret rc Return status code
  434. */
  435. static int realtek_create_buffer ( struct realtek_nic *rtl ) {
  436. size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
  437. physaddr_t address;
  438. int rc;
  439. /* Do nothing unless in legacy mode */
  440. if ( ! rtl->legacy )
  441. return 0;
  442. /* Allocate buffer */
  443. rtl->rx_buffer = malloc_dma ( len, RTL_RXBUF_ALIGN );
  444. if ( ! rtl->rx_buffer ) {
  445. rc = -ENOMEM;
  446. goto err_alloc;
  447. }
  448. address = virt_to_bus ( rtl->rx_buffer );
  449. /* Check that card can support address */
  450. if ( address & ~0xffffffffULL ) {
  451. DBGC ( rtl, "REALTEK %p cannot support 64-bit RX buffer "
  452. "address\n", rtl );
  453. rc = -ENOTSUP;
  454. goto err_64bit;
  455. }
  456. /* Program buffer address */
  457. writel ( address, rtl->regs + RTL_RBSTART );
  458. DBGC ( rtl, "REALTEK %p receive buffer is at [%08llx,%08llx,%08llx)\n",
  459. rtl, ( ( unsigned long long ) address ),
  460. ( ( unsigned long long ) address + RTL_RXBUF_LEN ),
  461. ( ( unsigned long long ) address + len ) );
  462. return 0;
  463. err_64bit:
  464. free_dma ( rtl->rx_buffer, len );
  465. rtl->rx_buffer = NULL;
  466. err_alloc:
  467. return rc;
  468. }
  469. /**
  470. * Destroy receive buffer (legacy mode)
  471. *
  472. * @v rtl Realtek device
  473. */
  474. static void realtek_destroy_buffer ( struct realtek_nic *rtl ) {
  475. size_t len = ( RTL_RXBUF_LEN + RTL_RXBUF_PAD );
  476. /* Do nothing unless in legacy mode */
  477. if ( ! rtl->legacy )
  478. return;
  479. /* Clear buffer address */
  480. writel ( 0, rtl->regs + RTL_RBSTART );
  481. /* Free buffer */
  482. free_dma ( rtl->rx_buffer, len );
  483. rtl->rx_buffer = NULL;
  484. rtl->rx_offset = 0;
  485. }
  486. /**
  487. * Create descriptor ring
  488. *
  489. * @v rtl Realtek device
  490. * @v ring Descriptor ring
  491. * @ret rc Return status code
  492. */
  493. static int realtek_create_ring ( struct realtek_nic *rtl,
  494. struct realtek_ring *ring ) {
  495. physaddr_t address;
  496. /* Do nothing in legacy mode */
  497. if ( rtl->legacy )
  498. return 0;
  499. /* Allocate descriptor ring */
  500. ring->desc = malloc_dma ( ring->len, RTL_RING_ALIGN );
  501. if ( ! ring->desc )
  502. return -ENOMEM;
  503. /* Initialise descriptor ring */
  504. memset ( ring->desc, 0, ring->len );
  505. /* Program ring address */
  506. address = virt_to_bus ( ring->desc );
  507. writel ( ( ( ( uint64_t ) address ) >> 32 ),
  508. rtl->regs + ring->reg + 4 );
  509. writel ( ( address & 0xffffffffUL ), rtl->regs + ring->reg );
  510. DBGC ( rtl, "REALTEK %p ring %02x is at [%08llx,%08llx)\n",
  511. rtl, ring->reg, ( ( unsigned long long ) address ),
  512. ( ( unsigned long long ) address + ring->len ) );
  513. return 0;
  514. }
  515. /**
  516. * Destroy descriptor ring
  517. *
  518. * @v rtl Realtek device
  519. * @v ring Descriptor ring
  520. */
  521. static void realtek_destroy_ring ( struct realtek_nic *rtl,
  522. struct realtek_ring *ring ) {
  523. /* Reset producer and consumer counters */
  524. ring->prod = 0;
  525. ring->cons = 0;
  526. /* Do nothing more if in legacy mode */
  527. if ( rtl->legacy )
  528. return;
  529. /* Clear ring address */
  530. writel ( 0, rtl->regs + ring->reg );
  531. writel ( 0, rtl->regs + ring->reg + 4 );
  532. /* Free descriptor ring */
  533. free_dma ( ring->desc, ring->len );
  534. ring->desc = NULL;
  535. }
  536. /**
  537. * Refill receive descriptor ring
  538. *
  539. * @v rtl Realtek device
  540. */
  541. static void realtek_refill_rx ( struct realtek_nic *rtl ) {
  542. struct realtek_descriptor *rx;
  543. struct io_buffer *iobuf;
  544. unsigned int rx_idx;
  545. physaddr_t address;
  546. int is_last;
  547. /* Do nothing in legacy mode */
  548. if ( rtl->legacy )
  549. return;
  550. while ( ( rtl->rx.prod - rtl->rx.cons ) < RTL_NUM_RX_DESC ) {
  551. /* Allocate I/O buffer */
  552. iobuf = alloc_iob ( RTL_RX_MAX_LEN );
  553. if ( ! iobuf ) {
  554. /* Wait for next refill */
  555. return;
  556. }
  557. /* Get next receive descriptor */
  558. rx_idx = ( rtl->rx.prod++ % RTL_NUM_RX_DESC );
  559. is_last = ( rx_idx == ( RTL_NUM_RX_DESC - 1 ) );
  560. rx = &rtl->rx.desc[rx_idx];
  561. /* Populate receive descriptor */
  562. address = virt_to_bus ( iobuf->data );
  563. rx->address = cpu_to_le64 ( address );
  564. rx->length = cpu_to_le16 ( RTL_RX_MAX_LEN );
  565. wmb();
  566. rx->flags = ( cpu_to_le16 ( RTL_DESC_OWN ) |
  567. ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
  568. wmb();
  569. /* Record I/O buffer */
  570. assert ( rtl->rx_iobuf[rx_idx] == NULL );
  571. rtl->rx_iobuf[rx_idx] = iobuf;
  572. DBGC2 ( rtl, "REALTEK %p RX %d is [%llx,%llx)\n", rtl, rx_idx,
  573. ( ( unsigned long long ) address ),
  574. ( ( unsigned long long ) address + RTL_RX_MAX_LEN ) );
  575. }
  576. }
  577. /**
  578. * Open network device
  579. *
  580. * @v netdev Network device
  581. * @ret rc Return status code
  582. */
  583. static int realtek_open ( struct net_device *netdev ) {
  584. struct realtek_nic *rtl = netdev->priv;
  585. uint32_t tcr;
  586. uint32_t rcr;
  587. int rc;
  588. /* Create transmit descriptor ring */
  589. if ( ( rc = realtek_create_ring ( rtl, &rtl->tx ) ) != 0 )
  590. goto err_create_tx;
  591. /* Create receive descriptor ring */
  592. if ( ( rc = realtek_create_ring ( rtl, &rtl->rx ) ) != 0 )
  593. goto err_create_rx;
  594. /* Create receive buffer */
  595. if ( ( rc = realtek_create_buffer ( rtl ) ) != 0 )
  596. goto err_create_buffer;
  597. /* Accept all packets */
  598. writel ( 0xffffffffUL, rtl->regs + RTL_MAR0 );
  599. writel ( 0xffffffffUL, rtl->regs + RTL_MAR4 );
  600. /* Enable transmitter and receiver. RTL8139 requires that
  601. * this happens before writing to RCR.
  602. */
  603. writeb ( ( RTL_CR_TE | RTL_CR_RE ), rtl->regs + RTL_CR );
  604. /* Configure transmitter */
  605. tcr = readl ( rtl->regs + RTL_TCR );
  606. tcr &= ~RTL_TCR_MXDMA_MASK;
  607. tcr |= RTL_TCR_MXDMA_DEFAULT;
  608. writel ( tcr, rtl->regs + RTL_TCR );
  609. /* Configure receiver */
  610. rcr = readl ( rtl->regs + RTL_RCR );
  611. rcr &= ~( RTL_RCR_STOP_WORKING | RTL_RCR_RXFTH_MASK |
  612. RTL_RCR_RBLEN_MASK | RTL_RCR_MXDMA_MASK );
  613. rcr |= ( RTL_RCR_RXFTH_DEFAULT | RTL_RCR_RBLEN_DEFAULT |
  614. RTL_RCR_MXDMA_DEFAULT | RTL_RCR_WRAP | RTL_RCR_AB |
  615. RTL_RCR_AM | RTL_RCR_APM | RTL_RCR_AAP );
  616. writel ( rcr, rtl->regs + RTL_RCR );
  617. /* Fill receive ring */
  618. realtek_refill_rx ( rtl );
  619. /* Update link state */
  620. realtek_check_link ( netdev );
  621. return 0;
  622. realtek_destroy_buffer ( rtl );
  623. err_create_buffer:
  624. realtek_destroy_ring ( rtl, &rtl->rx );
  625. err_create_rx:
  626. realtek_destroy_ring ( rtl, &rtl->tx );
  627. err_create_tx:
  628. return rc;
  629. }
  630. /**
  631. * Close network device
  632. *
  633. * @v netdev Network device
  634. */
  635. static void realtek_close ( struct net_device *netdev ) {
  636. struct realtek_nic *rtl = netdev->priv;
  637. unsigned int i;
  638. /* Disable receiver and transmitter */
  639. writeb ( 0, rtl->regs + RTL_CR );
  640. /* Destroy receive buffer */
  641. realtek_destroy_buffer ( rtl );
  642. /* Destroy receive descriptor ring */
  643. realtek_destroy_ring ( rtl, &rtl->rx );
  644. /* Discard any unused receive buffers */
  645. for ( i = 0 ; i < RTL_NUM_RX_DESC ; i++ ) {
  646. if ( rtl->rx_iobuf[i] )
  647. free_iob ( rtl->rx_iobuf[i] );
  648. rtl->rx_iobuf[i] = NULL;
  649. }
  650. /* Destroy transmit descriptor ring */
  651. realtek_destroy_ring ( rtl, &rtl->tx );
  652. }
  653. /**
  654. * Transmit packet
  655. *
  656. * @v netdev Network device
  657. * @v iobuf I/O buffer
  658. * @ret rc Return status code
  659. */
  660. static int realtek_transmit ( struct net_device *netdev,
  661. struct io_buffer *iobuf ) {
  662. struct realtek_nic *rtl = netdev->priv;
  663. struct realtek_descriptor *tx;
  664. unsigned int tx_idx;
  665. physaddr_t address;
  666. int is_last;
  667. /* Get next transmit descriptor */
  668. if ( ( rtl->tx.prod - rtl->tx.cons ) >= RTL_NUM_TX_DESC ) {
  669. netdev_tx_defer ( netdev, iobuf );
  670. return 0;
  671. }
  672. tx_idx = ( rtl->tx.prod++ % RTL_NUM_TX_DESC );
  673. /* Transmit packet */
  674. if ( rtl->legacy ) {
  675. /* Pad and align packet */
  676. iob_pad ( iobuf, ETH_ZLEN );
  677. address = virt_to_bus ( iobuf->data );
  678. /* Check that card can support address */
  679. if ( address & ~0xffffffffULL ) {
  680. DBGC ( rtl, "REALTEK %p cannot support 64-bit TX "
  681. "buffer address\n", rtl );
  682. return -ENOTSUP;
  683. }
  684. /* Add to transmit ring */
  685. writel ( address, rtl->regs + RTL_TSAD ( tx_idx ) );
  686. writel ( ( RTL_TSD_ERTXTH_DEFAULT | iob_len ( iobuf ) ),
  687. rtl->regs + RTL_TSD ( tx_idx ) );
  688. } else {
  689. /* Populate transmit descriptor */
  690. address = virt_to_bus ( iobuf->data );
  691. is_last = ( tx_idx == ( RTL_NUM_TX_DESC - 1 ) );
  692. tx = &rtl->tx.desc[tx_idx];
  693. tx->address = cpu_to_le64 ( address );
  694. tx->length = cpu_to_le16 ( iob_len ( iobuf ) );
  695. wmb();
  696. tx->flags = ( cpu_to_le16 ( RTL_DESC_OWN | RTL_DESC_FS |
  697. RTL_DESC_LS ) |
  698. ( is_last ? cpu_to_le16 ( RTL_DESC_EOR ) : 0 ) );
  699. wmb();
  700. /* Notify card that there are packets ready to transmit */
  701. writeb ( RTL_TPPOLL_NPQ, rtl->regs + rtl->tppoll );
  702. }
  703. DBGC2 ( rtl, "REALTEK %p TX %d is [%llx,%llx)\n", rtl, tx_idx,
  704. ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ),
  705. ( ( ( unsigned long long ) virt_to_bus ( iobuf->data ) ) +
  706. iob_len ( iobuf ) ) );
  707. return 0;
  708. }
  709. /**
  710. * Poll for completed packets
  711. *
  712. * @v netdev Network device
  713. */
  714. static void realtek_poll_tx ( struct net_device *netdev ) {
  715. struct realtek_nic *rtl = netdev->priv;
  716. struct realtek_descriptor *tx;
  717. unsigned int tx_idx;
  718. /* Check for completed packets */
  719. while ( rtl->tx.cons != rtl->tx.prod ) {
  720. /* Get next transmit descriptor */
  721. tx_idx = ( rtl->tx.cons % RTL_NUM_TX_DESC );
  722. /* Stop if descriptor is still in use */
  723. if ( rtl->legacy ) {
  724. /* Check ownership bit in transmit status register */
  725. if ( ! ( readl ( rtl->regs + RTL_TSD ( tx_idx ) ) &
  726. RTL_TSD_OWN ) )
  727. return;
  728. } else {
  729. /* Check ownership bit in descriptor */
  730. tx = &rtl->tx.desc[tx_idx];
  731. if ( tx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
  732. return;
  733. }
  734. DBGC2 ( rtl, "REALTEK %p TX %d complete\n", rtl, tx_idx );
  735. /* Complete TX descriptor */
  736. rtl->tx.cons++;
  737. netdev_tx_complete_next ( netdev );
  738. }
  739. }
  740. /**
  741. * Poll for received packets (legacy mode)
  742. *
  743. * @v netdev Network device
  744. */
  745. static void realtek_legacy_poll_rx ( struct net_device *netdev ) {
  746. struct realtek_nic *rtl = netdev->priv;
  747. struct realtek_legacy_header *rx;
  748. struct io_buffer *iobuf;
  749. size_t len;
  750. /* Check for received packets */
  751. while ( ! ( readb ( rtl->regs + RTL_CR ) & RTL_CR_BUFE ) ) {
  752. /* Extract packet from receive buffer */
  753. rx = ( rtl->rx_buffer + rtl->rx_offset );
  754. len = le16_to_cpu ( rx->length );
  755. if ( rx->status & cpu_to_le16 ( RTL_STAT_ROK ) ) {
  756. DBGC2 ( rtl, "REALTEK %p RX offset %x+%zx\n",
  757. rtl, rtl->rx_offset, len );
  758. /* Allocate I/O buffer */
  759. iobuf = alloc_iob ( len );
  760. if ( ! iobuf ) {
  761. netdev_rx_err ( netdev, NULL, -ENOMEM );
  762. /* Leave packet for next poll */
  763. break;
  764. }
  765. /* Copy data to I/O buffer */
  766. memcpy ( iob_put ( iobuf, len ), rx->data, len );
  767. iob_unput ( iobuf, 4 /* strip CRC */ );
  768. /* Hand off to network stack */
  769. netdev_rx ( netdev, iobuf );
  770. } else {
  771. DBGC ( rtl, "REALTEK %p RX offset %x+%zx error %04x\n",
  772. rtl, rtl->rx_offset, len,
  773. le16_to_cpu ( rx->status ) );
  774. netdev_rx_err ( netdev, NULL, -EIO );
  775. }
  776. /* Update buffer offset */
  777. rtl->rx_offset = ( rtl->rx_offset + sizeof ( *rx ) + len );
  778. rtl->rx_offset = ( ( rtl->rx_offset + 3 ) & ~3 );
  779. rtl->rx_offset = ( rtl->rx_offset % RTL_RXBUF_LEN );
  780. writew ( ( rtl->rx_offset - 16 ), rtl->regs + RTL_CAPR );
  781. /* Give chip time to react before rechecking RTL_CR */
  782. readw ( rtl->regs + RTL_CAPR );
  783. }
  784. }
  785. /**
  786. * Poll for received packets
  787. *
  788. * @v netdev Network device
  789. */
  790. static void realtek_poll_rx ( struct net_device *netdev ) {
  791. struct realtek_nic *rtl = netdev->priv;
  792. struct realtek_descriptor *rx;
  793. struct io_buffer *iobuf;
  794. unsigned int rx_idx;
  795. size_t len;
  796. /* Poll receive buffer if in legacy mode */
  797. if ( rtl->legacy ) {
  798. realtek_legacy_poll_rx ( netdev );
  799. return;
  800. }
  801. /* Check for received packets */
  802. while ( rtl->rx.cons != rtl->rx.prod ) {
  803. /* Get next receive descriptor */
  804. rx_idx = ( rtl->rx.cons % RTL_NUM_RX_DESC );
  805. rx = &rtl->rx.desc[rx_idx];
  806. /* Stop if descriptor is still in use */
  807. if ( rx->flags & cpu_to_le16 ( RTL_DESC_OWN ) )
  808. return;
  809. /* Populate I/O buffer */
  810. iobuf = rtl->rx_iobuf[rx_idx];
  811. rtl->rx_iobuf[rx_idx] = NULL;
  812. len = ( le16_to_cpu ( rx->length ) & RTL_DESC_SIZE_MASK );
  813. iob_put ( iobuf, ( len - 4 /* strip CRC */ ) );
  814. /* Hand off to network stack */
  815. if ( rx->flags & cpu_to_le16 ( RTL_DESC_RES ) ) {
  816. DBGC ( rtl, "REALTEK %p RX %d error (length %zd, "
  817. "flags %04x)\n", rtl, rx_idx, len,
  818. le16_to_cpu ( rx->flags ) );
  819. netdev_rx_err ( netdev, iobuf, -EIO );
  820. } else {
  821. DBGC2 ( rtl, "REALTEK %p RX %d complete (length "
  822. "%zd)\n", rtl, rx_idx, len );
  823. netdev_rx ( netdev, iobuf );
  824. }
  825. rtl->rx.cons++;
  826. }
  827. }
  828. /**
  829. * Poll for completed and received packets
  830. *
  831. * @v netdev Network device
  832. */
  833. static void realtek_poll ( struct net_device *netdev ) {
  834. struct realtek_nic *rtl = netdev->priv;
  835. uint16_t isr;
  836. /* Check for and acknowledge interrupts */
  837. isr = readw ( rtl->regs + RTL_ISR );
  838. if ( ! isr )
  839. return;
  840. writew ( isr, rtl->regs + RTL_ISR );
  841. /* Poll for TX completions, if applicable */
  842. if ( isr & ( RTL_IRQ_TER | RTL_IRQ_TOK ) )
  843. realtek_poll_tx ( netdev );
  844. /* Poll for RX completionsm, if applicable */
  845. if ( isr & ( RTL_IRQ_RER | RTL_IRQ_ROK ) )
  846. realtek_poll_rx ( netdev );
  847. /* Check link state, if applicable */
  848. if ( isr & RTL_IRQ_PUN_LINKCHG )
  849. realtek_check_link ( netdev );
  850. /* Refill RX ring */
  851. realtek_refill_rx ( rtl );
  852. }
  853. /**
  854. * Enable or disable interrupts
  855. *
  856. * @v netdev Network device
  857. * @v enable Interrupts should be enabled
  858. */
  859. static void realtek_irq ( struct net_device *netdev, int enable ) {
  860. struct realtek_nic *rtl = netdev->priv;
  861. uint16_t imr;
  862. /* Set interrupt mask */
  863. imr = ( enable ? ( RTL_IRQ_PUN_LINKCHG | RTL_IRQ_TER | RTL_IRQ_TOK |
  864. RTL_IRQ_RER | RTL_IRQ_ROK ) : 0 );
  865. writew ( imr, rtl->regs + RTL_IMR );
  866. }
  867. /** Realtek network device operations */
  868. static struct net_device_operations realtek_operations = {
  869. .open = realtek_open,
  870. .close = realtek_close,
  871. .transmit = realtek_transmit,
  872. .poll = realtek_poll,
  873. .irq = realtek_irq,
  874. };
  875. /******************************************************************************
  876. *
  877. * PCI interface
  878. *
  879. ******************************************************************************
  880. */
  881. /**
  882. * Detect device type
  883. *
  884. * @v rtl Realtek device
  885. */
  886. static void realtek_detect ( struct realtek_nic *rtl ) {
  887. uint16_t rms;
  888. uint16_t check_rms;
  889. uint16_t cpcr;
  890. uint16_t check_cpcr;
  891. /* The RX Packet Maximum Size register is present only on
  892. * 8169. Try to set to our intended MTU.
  893. */
  894. rms = RTL_RX_MAX_LEN;
  895. writew ( rms, rtl->regs + RTL_RMS );
  896. check_rms = readw ( rtl->regs + RTL_RMS );
  897. /* The C+ Command register is present only on 8169 and 8139C+.
  898. * Try to enable C+ mode and PCI Dual Address Cycle (for
  899. * 64-bit systems), if supported.
  900. *
  901. * Note that enabling DAC seems to cause bizarre behaviour
  902. * (lockups, garbage data on the wire) on some systems, even
  903. * if only 32-bit addresses are used.
  904. */
  905. cpcr = readw ( rtl->regs + RTL_CPCR );
  906. cpcr |= ( RTL_CPCR_MULRW | RTL_CPCR_CPRX | RTL_CPCR_CPTX );
  907. if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
  908. cpcr |= RTL_CPCR_DAC;
  909. writew ( cpcr, rtl->regs + RTL_CPCR );
  910. check_cpcr = readw ( rtl->regs + RTL_CPCR );
  911. /* Detect device type */
  912. if ( check_rms == rms ) {
  913. DBGC ( rtl, "REALTEK %p appears to be an RTL8169\n", rtl );
  914. rtl->have_phy_regs = 1;
  915. rtl->tppoll = RTL_TPPOLL_8169;
  916. } else {
  917. if ( ( check_cpcr == cpcr ) && ( cpcr != 0xffff ) ) {
  918. DBGC ( rtl, "REALTEK %p appears to be an RTL8139C+\n",
  919. rtl );
  920. rtl->tppoll = RTL_TPPOLL_8139CP;
  921. } else {
  922. DBGC ( rtl, "REALTEK %p appears to be an RTL8139\n",
  923. rtl );
  924. rtl->legacy = 1;
  925. }
  926. }
  927. }
  928. /**
  929. * Probe PCI device
  930. *
  931. * @v pci PCI device
  932. * @ret rc Return status code
  933. */
  934. static int realtek_probe ( struct pci_device *pci ) {
  935. struct net_device *netdev;
  936. struct realtek_nic *rtl;
  937. unsigned int i;
  938. int rc;
  939. /* Allocate and initialise net device */
  940. netdev = alloc_etherdev ( sizeof ( *rtl ) );
  941. if ( ! netdev ) {
  942. rc = -ENOMEM;
  943. goto err_alloc;
  944. }
  945. netdev_init ( netdev, &realtek_operations );
  946. rtl = netdev->priv;
  947. pci_set_drvdata ( pci, netdev );
  948. netdev->dev = &pci->dev;
  949. memset ( rtl, 0, sizeof ( *rtl ) );
  950. realtek_init_ring ( &rtl->tx, RTL_NUM_TX_DESC, RTL_TNPDS );
  951. realtek_init_ring ( &rtl->rx, RTL_NUM_RX_DESC, RTL_RDSAR );
  952. /* Fix up PCI device */
  953. adjust_pci_device ( pci );
  954. /* Map registers */
  955. rtl->regs = ioremap ( pci->membase, RTL_BAR_SIZE );
  956. if ( ! rtl->regs ) {
  957. rc = -ENODEV;
  958. goto err_ioremap;
  959. }
  960. /* Reset the NIC */
  961. if ( ( rc = realtek_reset ( rtl ) ) != 0 )
  962. goto err_reset;
  963. /* Detect device type */
  964. realtek_detect ( rtl );
  965. /* Initialise EEPROM */
  966. if ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) {
  967. /* Read MAC address from EEPROM */
  968. if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
  969. netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
  970. DBGC ( rtl, "REALTEK %p could not read MAC address: "
  971. "%s\n", rtl, strerror ( rc ) );
  972. goto err_nvs_read;
  973. }
  974. } else {
  975. /* EEPROM not present. Fall back to reading the
  976. * current ID register value, which will hopefully
  977. * have been programmed by the platform firmware.
  978. */
  979. for ( i = 0 ; i < ETH_ALEN ; i++ )
  980. netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
  981. }
  982. /* Initialise and reset MII interface */
  983. mii_init ( &rtl->mii, &realtek_mii_operations );
  984. if ( ( rc = realtek_phy_reset ( rtl ) ) != 0 )
  985. goto err_phy_reset;
  986. /* Register network device */
  987. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  988. goto err_register_netdev;
  989. /* Set initial link state */
  990. realtek_check_link ( netdev );
  991. /* Register non-volatile options, if applicable */
  992. if ( rtl->nvo.nvs ) {
  993. if ( ( rc = register_nvo ( &rtl->nvo,
  994. netdev_settings ( netdev ) ) ) != 0)
  995. goto err_register_nvo;
  996. }
  997. return 0;
  998. err_register_nvo:
  999. unregister_netdev ( netdev );
  1000. err_register_netdev:
  1001. err_phy_reset:
  1002. err_nvs_read:
  1003. realtek_reset ( rtl );
  1004. err_reset:
  1005. iounmap ( rtl->regs );
  1006. err_ioremap:
  1007. netdev_nullify ( netdev );
  1008. netdev_put ( netdev );
  1009. err_alloc:
  1010. return rc;
  1011. }
  1012. /**
  1013. * Remove PCI device
  1014. *
  1015. * @v pci PCI device
  1016. */
  1017. static void realtek_remove ( struct pci_device *pci ) {
  1018. struct net_device *netdev = pci_get_drvdata ( pci );
  1019. struct realtek_nic *rtl = netdev->priv;
  1020. /* Unregister non-volatile options, if applicable */
  1021. if ( rtl->nvo.nvs )
  1022. unregister_nvo ( &rtl->nvo );
  1023. /* Unregister network device */
  1024. unregister_netdev ( netdev );
  1025. /* Reset card */
  1026. realtek_reset ( rtl );
  1027. /* Free network device */
  1028. iounmap ( rtl->regs );
  1029. netdev_nullify ( netdev );
  1030. netdev_put ( netdev );
  1031. }
  1032. /** Realtek PCI device IDs */
  1033. static struct pci_device_id realtek_nics[] = {
  1034. PCI_ROM ( 0x0001, 0x8168, "clone8169", "Cloned 8169", 0 ),
  1035. PCI_ROM ( 0x018a, 0x0106, "fpc0106tx", "LevelOne FPC-0106TX", 0 ),
  1036. PCI_ROM ( 0x021b, 0x8139, "hne300", "Compaq HNE-300", 0 ),
  1037. PCI_ROM ( 0x02ac, 0x1012, "s1012", "SpeedStream 1012", 0 ),
  1038. PCI_ROM ( 0x0357, 0x000a, "ttpmon", "TTTech TTP-Monitoring", 0 ),
  1039. PCI_ROM ( 0x10ec, 0x8129, "rtl8129", "RTL-8129", 0 ),
  1040. PCI_ROM ( 0x10ec, 0x8136, "rtl8136", "RTL8101E/RTL8102E", 0 ),
  1041. PCI_ROM ( 0x10ec, 0x8138, "rtl8138", "RT8139 (B/C)", 0 ),
  1042. PCI_ROM ( 0x10ec, 0x8139, "rtl8139", "RTL-8139/8139C/8139C+", 0 ),
  1043. PCI_ROM ( 0x10ec, 0x8167, "rtl8167", "RTL-8110SC/8169SC", 0 ),
  1044. PCI_ROM ( 0x10ec, 0x8168, "rtl8168", "RTL8111/8168B", 0 ),
  1045. PCI_ROM ( 0x10ec, 0x8169, "rtl8169", "RTL-8169", 0 ),
  1046. PCI_ROM ( 0x1113, 0x1211, "smc1211", "SMC2-1211TX", 0 ),
  1047. PCI_ROM ( 0x1186, 0x1300, "dfe538", "DFE530TX+/DFE538TX", 0 ),
  1048. PCI_ROM ( 0x1186, 0x1340, "dfe690", "DFE-690TXD", 0 ),
  1049. PCI_ROM ( 0x1186, 0x4300, "dge528t", "DGE-528T", 0 ),
  1050. PCI_ROM ( 0x11db, 0x1234, "sega8139", "Sega Enterprises 8139", 0 ),
  1051. PCI_ROM ( 0x1259, 0xa117, "allied8139", "Allied Telesyn 8139", 0 ),
  1052. PCI_ROM ( 0x1259, 0xa11e, "allied81xx", "Allied Telesyn 81xx", 0 ),
  1053. PCI_ROM ( 0x1259, 0xc107, "allied8169", "Allied Telesyn 8169", 0 ),
  1054. PCI_ROM ( 0x126c, 0x1211, "northen8139","Northern Telecom 8139", 0 ),
  1055. PCI_ROM ( 0x13d1, 0xab06, "fe2000vx", "Abocom FE2000VX", 0 ),
  1056. PCI_ROM ( 0x1432, 0x9130, "edi8139", "Edimax 8139", 0 ),
  1057. PCI_ROM ( 0x14ea, 0xab06, "fnw3603tx", "Planex FNW-3603-TX", 0 ),
  1058. PCI_ROM ( 0x14ea, 0xab07, "fnw3800tx", "Planex FNW-3800-TX", 0 ),
  1059. PCI_ROM ( 0x1500, 0x1360, "delta8139", "Delta Electronics 8139", 0 ),
  1060. PCI_ROM ( 0x16ec, 0x0116, "usr997902", "USR997902", 0 ),
  1061. PCI_ROM ( 0x1737, 0x1032, "linksys8169","Linksys 8169", 0 ),
  1062. PCI_ROM ( 0x1743, 0x8139, "rolf100", "Peppercorn ROL/F-100", 0 ),
  1063. PCI_ROM ( 0x4033, 0x1360, "addron8139", "Addtron 8139", 0 ),
  1064. PCI_ROM ( 0xffff, 0x8139, "clonse8139", "Cloned 8139", 0 ),
  1065. };
  1066. /** Realtek PCI driver */
  1067. struct pci_driver realtek_driver __pci_driver = {
  1068. .ids = realtek_nics,
  1069. .id_count = ( sizeof ( realtek_nics ) / sizeof ( realtek_nics[0] ) ),
  1070. .probe = realtek_probe,
  1071. .remove = realtek_remove,
  1072. };