realtek.c 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. /* Reset the NIC */
  957. if ( ( rc = realtek_reset ( rtl ) ) != 0 )
  958. goto err_reset;
  959. /* Detect device type */
  960. realtek_detect ( rtl );
  961. /* Initialise EEPROM */
  962. if ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) {
  963. /* Read MAC address from EEPROM */
  964. if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
  965. netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
  966. DBGC ( rtl, "REALTEK %p could not read MAC address: "
  967. "%s\n", rtl, strerror ( rc ) );
  968. goto err_nvs_read;
  969. }
  970. } else {
  971. /* EEPROM not present. Fall back to reading the
  972. * current ID register value, which will hopefully
  973. * have been programmed by the platform firmware.
  974. */
  975. for ( i = 0 ; i < ETH_ALEN ; i++ )
  976. netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
  977. }
  978. /* Initialise and reset MII interface */
  979. mii_init ( &rtl->mii, &realtek_mii_operations );
  980. if ( ( rc = realtek_phy_reset ( rtl ) ) != 0 )
  981. goto err_phy_reset;
  982. /* Register network device */
  983. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  984. goto err_register_netdev;
  985. /* Set initial link state */
  986. realtek_check_link ( netdev );
  987. /* Register non-volatile options, if applicable */
  988. if ( rtl->nvo.nvs ) {
  989. if ( ( rc = register_nvo ( &rtl->nvo,
  990. netdev_settings ( netdev ) ) ) != 0)
  991. goto err_register_nvo;
  992. }
  993. return 0;
  994. err_register_nvo:
  995. unregister_netdev ( netdev );
  996. err_register_netdev:
  997. err_phy_reset:
  998. err_nvs_read:
  999. realtek_reset ( rtl );
  1000. err_reset:
  1001. iounmap ( rtl->regs );
  1002. netdev_nullify ( netdev );
  1003. netdev_put ( netdev );
  1004. err_alloc:
  1005. return rc;
  1006. }
  1007. /**
  1008. * Remove PCI device
  1009. *
  1010. * @v pci PCI device
  1011. */
  1012. static void realtek_remove ( struct pci_device *pci ) {
  1013. struct net_device *netdev = pci_get_drvdata ( pci );
  1014. struct realtek_nic *rtl = netdev->priv;
  1015. /* Unregister non-volatile options, if applicable */
  1016. if ( rtl->nvo.nvs )
  1017. unregister_nvo ( &rtl->nvo );
  1018. /* Unregister network device */
  1019. unregister_netdev ( netdev );
  1020. /* Reset card */
  1021. realtek_reset ( rtl );
  1022. /* Free network device */
  1023. iounmap ( rtl->regs );
  1024. netdev_nullify ( netdev );
  1025. netdev_put ( netdev );
  1026. }
  1027. /** Realtek PCI device IDs */
  1028. static struct pci_device_id realtek_nics[] = {
  1029. PCI_ROM ( 0x0001, 0x8168, "clone8169", "Cloned 8169", 0 ),
  1030. PCI_ROM ( 0x018a, 0x0106, "fpc0106tx", "LevelOne FPC-0106TX", 0 ),
  1031. PCI_ROM ( 0x021b, 0x8139, "hne300", "Compaq HNE-300", 0 ),
  1032. PCI_ROM ( 0x02ac, 0x1012, "s1012", "SpeedStream 1012", 0 ),
  1033. PCI_ROM ( 0x0357, 0x000a, "ttpmon", "TTTech TTP-Monitoring", 0 ),
  1034. PCI_ROM ( 0x10ec, 0x8129, "rtl8129", "RTL-8129", 0 ),
  1035. PCI_ROM ( 0x10ec, 0x8136, "rtl8136", "RTL8101E/RTL8102E", 0 ),
  1036. PCI_ROM ( 0x10ec, 0x8138, "rtl8138", "RT8139 (B/C)", 0 ),
  1037. PCI_ROM ( 0x10ec, 0x8139, "rtl8139", "RTL-8139/8139C/8139C+", 0 ),
  1038. PCI_ROM ( 0x10ec, 0x8167, "rtl8167", "RTL-8110SC/8169SC", 0 ),
  1039. PCI_ROM ( 0x10ec, 0x8168, "rtl8168", "RTL8111/8168B", 0 ),
  1040. PCI_ROM ( 0x10ec, 0x8169, "rtl8169", "RTL-8169", 0 ),
  1041. PCI_ROM ( 0x1113, 0x1211, "smc1211", "SMC2-1211TX", 0 ),
  1042. PCI_ROM ( 0x1186, 0x1300, "dfe538", "DFE530TX+/DFE538TX", 0 ),
  1043. PCI_ROM ( 0x1186, 0x1340, "dfe690", "DFE-690TXD", 0 ),
  1044. PCI_ROM ( 0x1186, 0x4300, "dge528t", "DGE-528T", 0 ),
  1045. PCI_ROM ( 0x11db, 0x1234, "sega8139", "Sega Enterprises 8139", 0 ),
  1046. PCI_ROM ( 0x1259, 0xa117, "allied8139", "Allied Telesyn 8139", 0 ),
  1047. PCI_ROM ( 0x1259, 0xa11e, "allied81xx", "Allied Telesyn 81xx", 0 ),
  1048. PCI_ROM ( 0x1259, 0xc107, "allied8169", "Allied Telesyn 8169", 0 ),
  1049. PCI_ROM ( 0x126c, 0x1211, "northen8139","Northern Telecom 8139", 0 ),
  1050. PCI_ROM ( 0x13d1, 0xab06, "fe2000vx", "Abocom FE2000VX", 0 ),
  1051. PCI_ROM ( 0x1432, 0x9130, "edi8139", "Edimax 8139", 0 ),
  1052. PCI_ROM ( 0x14ea, 0xab06, "fnw3603tx", "Planex FNW-3603-TX", 0 ),
  1053. PCI_ROM ( 0x14ea, 0xab07, "fnw3800tx", "Planex FNW-3800-TX", 0 ),
  1054. PCI_ROM ( 0x1500, 0x1360, "delta8139", "Delta Electronics 8139", 0 ),
  1055. PCI_ROM ( 0x16ec, 0x0116, "usr997902", "USR997902", 0 ),
  1056. PCI_ROM ( 0x1737, 0x1032, "linksys8169","Linksys 8169", 0 ),
  1057. PCI_ROM ( 0x1743, 0x8139, "rolf100", "Peppercorn ROL/F-100", 0 ),
  1058. PCI_ROM ( 0x4033, 0x1360, "addron8139", "Addtron 8139", 0 ),
  1059. PCI_ROM ( 0xffff, 0x8139, "clonse8139", "Cloned 8139", 0 ),
  1060. };
  1061. /** Realtek PCI driver */
  1062. struct pci_driver realtek_driver __pci_driver = {
  1063. .ids = realtek_nics,
  1064. .id_count = ( sizeof ( realtek_nics ) / sizeof ( realtek_nics[0] ) ),
  1065. .probe = realtek_probe,
  1066. .remove = realtek_remove,
  1067. };