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

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