Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

r8169.c 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  1. /*
  2. * Copyright (c) 2008 Marty Connor <mdc@etherboot.org>
  3. * Copyright (c) 2008 Entity Cyber, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of the
  8. * License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * This driver is based on rtl8169 data sheets and work by:
  20. *
  21. * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
  22. * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
  23. * Copyright (c) a lot of people too. Please respect their work.
  24. */
  25. FILE_LICENCE ( GPL2_OR_LATER );
  26. #include <stdint.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <unistd.h>
  31. #include <assert.h>
  32. #include <byteswap.h>
  33. #include <errno.h>
  34. #include <gpxe/ethernet.h>
  35. #include <gpxe/if_ether.h>
  36. #include <gpxe/io.h>
  37. #include <gpxe/iobuf.h>
  38. #include <gpxe/malloc.h>
  39. #include <gpxe/netdevice.h>
  40. #include <gpxe/pci.h>
  41. #include <gpxe/timer.h>
  42. #include <mii.h>
  43. #include "r8169.h"
  44. /*** Low level hardware routines ***/
  45. static void mdio_write(void *ioaddr, int reg_addr, int value)
  46. {
  47. int i;
  48. DBGP ( "mdio_write\n" );
  49. RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff));
  50. for (i = 20; i > 0; i--) {
  51. /*
  52. * Check if the RTL8169 has completed writing to the specified
  53. * MII register.
  54. */
  55. if (!(RTL_R32(PHYAR) & 0x80000000))
  56. break;
  57. udelay(25);
  58. }
  59. }
  60. static int mdio_read(void *ioaddr, int reg_addr)
  61. {
  62. int i, value = -1;
  63. DBGP ( "mdio_read\n" );
  64. RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16);
  65. for (i = 20; i > 0; i--) {
  66. /*
  67. * Check if the RTL8169 has completed retrieving data from
  68. * the specified MII register.
  69. */
  70. if (RTL_R32(PHYAR) & 0x80000000) {
  71. value = RTL_R32(PHYAR) & 0xffff;
  72. break;
  73. }
  74. udelay(25);
  75. }
  76. return value;
  77. }
  78. static void mdio_patch(void *ioaddr, int reg_addr, int value)
  79. {
  80. DBGP ( "mdio_patch\n" );
  81. mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value);
  82. }
  83. static void rtl_ephy_write(void *ioaddr, int reg_addr, int value)
  84. {
  85. unsigned int i;
  86. DBGP ( "rtl_ephy_write\n" );
  87. RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
  88. (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
  89. for (i = 0; i < 100; i++) {
  90. if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG))
  91. break;
  92. udelay(10);
  93. }
  94. }
  95. static u16 rtl_ephy_read(void *ioaddr, int reg_addr)
  96. {
  97. u16 value = 0xffff;
  98. unsigned int i;
  99. DBGP ( "rtl_ephy_read\n" );
  100. RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
  101. for (i = 0; i < 100; i++) {
  102. if (RTL_R32(EPHYAR) & EPHYAR_FLAG) {
  103. value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK;
  104. break;
  105. }
  106. udelay(10);
  107. }
  108. return value;
  109. }
  110. static void rtl_csi_write(void *ioaddr, int addr, int value)
  111. {
  112. unsigned int i;
  113. DBGP ( "rtl_csi_write\n" );
  114. RTL_W32(CSIDR, value);
  115. RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
  116. CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
  117. for (i = 0; i < 100; i++) {
  118. if (!(RTL_R32(CSIAR) & CSIAR_FLAG))
  119. break;
  120. udelay(10);
  121. }
  122. }
  123. static u32 rtl_csi_read(void *ioaddr, int addr)
  124. {
  125. u32 value = ~0x00;
  126. unsigned int i;
  127. DBGP ( "rtl_csi_read\n" );
  128. RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) |
  129. CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
  130. for (i = 0; i < 100; i++) {
  131. if (RTL_R32(CSIAR) & CSIAR_FLAG) {
  132. value = RTL_R32(CSIDR);
  133. break;
  134. }
  135. udelay(10);
  136. }
  137. return value;
  138. }
  139. static void rtl8169_irq_mask_and_ack(void *ioaddr)
  140. {
  141. DBGP ( "rtl8169_irq_mask_and_ack\n" );
  142. RTL_W16(IntrMask, 0x0000);
  143. RTL_W16(IntrStatus, 0xffff);
  144. }
  145. static unsigned int rtl8169_tbi_reset_pending(void *ioaddr)
  146. {
  147. DBGP ( "rtl8169_tbi_reset_pending\n" );
  148. return RTL_R32(TBICSR) & TBIReset;
  149. }
  150. static unsigned int rtl8169_xmii_reset_pending(void *ioaddr)
  151. {
  152. DBGP ( "rtl8169_xmii_reset_pending\n" );
  153. return mdio_read(ioaddr, MII_BMCR) & BMCR_RESET;
  154. }
  155. static unsigned int rtl8169_tbi_link_ok(void *ioaddr)
  156. {
  157. DBGP ( "rtl8169_tbi_link_ok\n" );
  158. return RTL_R32(TBICSR) & TBILinkOk;
  159. }
  160. static unsigned int rtl8169_xmii_link_ok(void *ioaddr)
  161. {
  162. DBGP ( "rtl8169_xmii_link_ok\n" );
  163. return RTL_R8(PHYstatus) & LinkStatus;
  164. }
  165. static void rtl8169_tbi_reset_enable(void *ioaddr)
  166. {
  167. DBGP ( "rtl8169_tbi_reset_enable\n" );
  168. RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset);
  169. }
  170. static void rtl8169_xmii_reset_enable(void *ioaddr)
  171. {
  172. unsigned int val;
  173. DBGP ( "rtl8169_xmii_reset_enable\n" );
  174. val = mdio_read(ioaddr, MII_BMCR) | BMCR_RESET;
  175. mdio_write(ioaddr, MII_BMCR, val & 0xffff);
  176. }
  177. static int rtl8169_set_speed_tbi(struct net_device *dev,
  178. u8 autoneg, u16 speed, u8 duplex)
  179. {
  180. struct rtl8169_private *tp = netdev_priv(dev);
  181. void *ioaddr = tp->mmio_addr;
  182. int ret = 0;
  183. u32 reg;
  184. DBGP ( "rtl8169_set_speed_tbi\n" );
  185. reg = RTL_R32(TBICSR);
  186. if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) &&
  187. (duplex == DUPLEX_FULL)) {
  188. RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart));
  189. } else if (autoneg == AUTONEG_ENABLE)
  190. RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart);
  191. else {
  192. DBG ( "incorrect speed setting refused in TBI mode\n" );
  193. ret = -EOPNOTSUPP;
  194. }
  195. return ret;
  196. }
  197. static int rtl8169_set_speed_xmii(struct net_device *dev,
  198. u8 autoneg, u16 speed, u8 duplex)
  199. {
  200. struct rtl8169_private *tp = netdev_priv(dev);
  201. void *ioaddr = tp->mmio_addr;
  202. int auto_nego, giga_ctrl;
  203. DBGP ( "rtl8169_set_speed_xmii\n" );
  204. auto_nego = mdio_read(ioaddr, MII_ADVERTISE);
  205. auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
  206. ADVERTISE_100HALF | ADVERTISE_100FULL);
  207. giga_ctrl = mdio_read(ioaddr, MII_CTRL1000);
  208. giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
  209. if (autoneg == AUTONEG_ENABLE) {
  210. auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
  211. ADVERTISE_100HALF | ADVERTISE_100FULL);
  212. giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
  213. } else {
  214. if (speed == SPEED_10)
  215. auto_nego |= ADVERTISE_10HALF | ADVERTISE_10FULL;
  216. else if (speed == SPEED_100)
  217. auto_nego |= ADVERTISE_100HALF | ADVERTISE_100FULL;
  218. else if (speed == SPEED_1000)
  219. giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
  220. if (duplex == DUPLEX_HALF)
  221. auto_nego &= ~(ADVERTISE_10FULL | ADVERTISE_100FULL);
  222. if (duplex == DUPLEX_FULL)
  223. auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_100HALF);
  224. /* This tweak comes straight from Realtek's driver. */
  225. if ((speed == SPEED_100) && (duplex == DUPLEX_HALF) &&
  226. ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
  227. (tp->mac_version == RTL_GIGA_MAC_VER_16))) {
  228. auto_nego = ADVERTISE_100HALF | ADVERTISE_CSMA;
  229. }
  230. }
  231. /* The 8100e/8101e/8102e do Fast Ethernet only. */
  232. if ((tp->mac_version == RTL_GIGA_MAC_VER_07) ||
  233. (tp->mac_version == RTL_GIGA_MAC_VER_08) ||
  234. (tp->mac_version == RTL_GIGA_MAC_VER_09) ||
  235. (tp->mac_version == RTL_GIGA_MAC_VER_10) ||
  236. (tp->mac_version == RTL_GIGA_MAC_VER_13) ||
  237. (tp->mac_version == RTL_GIGA_MAC_VER_14) ||
  238. (tp->mac_version == RTL_GIGA_MAC_VER_15) ||
  239. (tp->mac_version == RTL_GIGA_MAC_VER_16)) {
  240. if ((giga_ctrl & (ADVERTISE_1000FULL | ADVERTISE_1000HALF))) {
  241. DBG ( "PHY does not support 1000Mbps.\n" );
  242. }
  243. giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
  244. }
  245. auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  246. if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
  247. (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
  248. (tp->mac_version >= RTL_GIGA_MAC_VER_17)) {
  249. /*
  250. * Wake up the PHY.
  251. * Vendor specific (0x1f) and reserved (0x0e) MII registers.
  252. */
  253. mdio_write(ioaddr, 0x1f, 0x0000);
  254. mdio_write(ioaddr, 0x0e, 0x0000);
  255. }
  256. tp->phy_auto_nego_reg = auto_nego;
  257. tp->phy_1000_ctrl_reg = giga_ctrl;
  258. mdio_write(ioaddr, MII_ADVERTISE, auto_nego);
  259. mdio_write(ioaddr, MII_CTRL1000, giga_ctrl);
  260. mdio_write(ioaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
  261. return 0;
  262. }
  263. static int rtl8169_set_speed(struct net_device *dev,
  264. u8 autoneg, u16 speed, u8 duplex)
  265. {
  266. struct rtl8169_private *tp = netdev_priv(dev);
  267. int ret;
  268. DBGP ( "rtl8169_set_speed\n" );
  269. ret = tp->set_speed(dev, autoneg, speed, duplex);
  270. return ret;
  271. }
  272. static void rtl8169_write_gmii_reg_bit(void *ioaddr, int reg,
  273. int bitnum, int bitval)
  274. {
  275. int val;
  276. DBGP ( "rtl8169_write_gmii_reg_bit\n" );
  277. val = mdio_read(ioaddr, reg);
  278. val = (bitval == 1) ?
  279. val | (bitval << bitnum) : val & ~(0x0001 << bitnum);
  280. mdio_write(ioaddr, reg, val & 0xffff);
  281. }
  282. static void rtl8169_get_mac_version(struct rtl8169_private *tp,
  283. void *ioaddr)
  284. {
  285. /*
  286. * The driver currently handles the 8168Bf and the 8168Be identically
  287. * but they can be identified more specifically through the test below
  288. * if needed:
  289. *
  290. * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
  291. *
  292. * Same thing for the 8101Eb and the 8101Ec:
  293. *
  294. * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
  295. */
  296. const struct {
  297. u32 mask;
  298. u32 val;
  299. int mac_version;
  300. } mac_info[] = {
  301. /* 8168D family. */
  302. { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_25 },
  303. /* 8168C family. */
  304. { 0x7cf00000, 0x3ca00000, RTL_GIGA_MAC_VER_24 },
  305. { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 },
  306. { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 },
  307. { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 },
  308. { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 },
  309. { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 },
  310. { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 },
  311. { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 },
  312. { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 },
  313. /* 8168B family. */
  314. { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 },
  315. { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 },
  316. { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 },
  317. { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 },
  318. /* 8101 family. */
  319. { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 },
  320. { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 },
  321. { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 },
  322. { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 },
  323. { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 },
  324. { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 },
  325. { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 },
  326. { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 },
  327. { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 },
  328. { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 },
  329. { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 },
  330. { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 },
  331. /* FIXME: where did these entries come from ? -- FR */
  332. { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 },
  333. { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 },
  334. /* 8110 family. */
  335. { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 },
  336. { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 },
  337. { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 },
  338. { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 },
  339. { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 },
  340. { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 },
  341. { 0x00000000, 0x00000000, RTL_GIGA_MAC_VER_01 } /* Catch-all */
  342. }, *p = mac_info;
  343. u32 reg;
  344. DBGP ( "rtl8169_get_mac_version\n" );
  345. reg = RTL_R32(TxConfig);
  346. while ((reg & p->mask) != p->val)
  347. p++;
  348. tp->mac_version = p->mac_version;
  349. DBG ( "tp->mac_version = %d\n", tp->mac_version );
  350. if (p->mask == 0x00000000) {
  351. DBG ( "unknown MAC (%08x)\n", reg );
  352. }
  353. }
  354. struct phy_reg {
  355. u16 reg;
  356. u16 val;
  357. };
  358. static void rtl_phy_write(void *ioaddr, struct phy_reg *regs, int len)
  359. {
  360. DBGP ( "rtl_phy_write\n" );
  361. while (len-- > 0) {
  362. mdio_write(ioaddr, regs->reg, regs->val);
  363. regs++;
  364. }
  365. }
  366. static void rtl8169s_hw_phy_config(void *ioaddr)
  367. {
  368. struct {
  369. u16 regs[5]; /* Beware of bit-sign propagation */
  370. } phy_magic[5] = { {
  371. { 0x0000, //w 4 15 12 0
  372. 0x00a1, //w 3 15 0 00a1
  373. 0x0008, //w 2 15 0 0008
  374. 0x1020, //w 1 15 0 1020
  375. 0x1000 } },{ //w 0 15 0 1000
  376. { 0x7000, //w 4 15 12 7
  377. 0xff41, //w 3 15 0 ff41
  378. 0xde60, //w 2 15 0 de60
  379. 0x0140, //w 1 15 0 0140
  380. 0x0077 } },{ //w 0 15 0 0077
  381. { 0xa000, //w 4 15 12 a
  382. 0xdf01, //w 3 15 0 df01
  383. 0xdf20, //w 2 15 0 df20
  384. 0xff95, //w 1 15 0 ff95
  385. 0xfa00 } },{ //w 0 15 0 fa00
  386. { 0xb000, //w 4 15 12 b
  387. 0xff41, //w 3 15 0 ff41
  388. 0xde20, //w 2 15 0 de20
  389. 0x0140, //w 1 15 0 0140
  390. 0x00bb } },{ //w 0 15 0 00bb
  391. { 0xf000, //w 4 15 12 f
  392. 0xdf01, //w 3 15 0 df01
  393. 0xdf20, //w 2 15 0 df20
  394. 0xff95, //w 1 15 0 ff95
  395. 0xbf00 } //w 0 15 0 bf00
  396. }
  397. }, *p = phy_magic;
  398. unsigned int i;
  399. DBGP ( "rtl8169s_hw_phy_config\n" );
  400. mdio_write(ioaddr, 0x1f, 0x0001); //w 31 2 0 1
  401. mdio_write(ioaddr, 0x15, 0x1000); //w 21 15 0 1000
  402. mdio_write(ioaddr, 0x18, 0x65c7); //w 24 15 0 65c7
  403. rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 0); //w 4 11 11 0
  404. for (i = 0; i < ARRAY_SIZE(phy_magic); i++, p++) {
  405. int val, pos = 4;
  406. val = (mdio_read(ioaddr, pos) & 0x0fff) | (p->regs[0] & 0xffff);
  407. mdio_write(ioaddr, pos, val);
  408. while (--pos >= 0)
  409. mdio_write(ioaddr, pos, p->regs[4 - pos] & 0xffff);
  410. rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 1); //w 4 11 11 1
  411. rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 0); //w 4 11 11 0
  412. }
  413. mdio_write(ioaddr, 0x1f, 0x0000); //w 31 2 0 0
  414. }
  415. static void rtl8169sb_hw_phy_config(void *ioaddr)
  416. {
  417. struct phy_reg phy_reg_init[] = {
  418. { 0x1f, 0x0002 },
  419. { 0x01, 0x90d0 },
  420. { 0x1f, 0x0000 }
  421. };
  422. DBGP ( "rtl8169sb_hw_phy_config\n" );
  423. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  424. }
  425. static void rtl8168bb_hw_phy_config(void *ioaddr)
  426. {
  427. struct phy_reg phy_reg_init[] = {
  428. { 0x10, 0xf41b },
  429. { 0x1f, 0x0000 }
  430. };
  431. mdio_write(ioaddr, 0x1f, 0x0001);
  432. mdio_patch(ioaddr, 0x16, 1 << 0);
  433. DBGP ( "rtl8168bb_hw_phy_config\n" );
  434. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  435. }
  436. static void rtl8168bef_hw_phy_config(void *ioaddr)
  437. {
  438. struct phy_reg phy_reg_init[] = {
  439. { 0x1f, 0x0001 },
  440. { 0x10, 0xf41b },
  441. { 0x1f, 0x0000 }
  442. };
  443. DBGP ( "rtl8168bef_hw_phy_config\n" );
  444. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  445. }
  446. static void rtl8168cp_1_hw_phy_config(void *ioaddr)
  447. {
  448. struct phy_reg phy_reg_init[] = {
  449. { 0x1f, 0x0000 },
  450. { 0x1d, 0x0f00 },
  451. { 0x1f, 0x0002 },
  452. { 0x0c, 0x1ec8 },
  453. { 0x1f, 0x0000 }
  454. };
  455. DBGP ( "rtl8168cp_1_hw_phy_config\n" );
  456. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  457. }
  458. static void rtl8168cp_2_hw_phy_config(void *ioaddr)
  459. {
  460. struct phy_reg phy_reg_init[] = {
  461. { 0x1f, 0x0001 },
  462. { 0x1d, 0x3d98 },
  463. { 0x1f, 0x0000 }
  464. };
  465. DBGP ( "rtl8168cp_2_hw_phy_config\n" );
  466. mdio_write(ioaddr, 0x1f, 0x0000);
  467. mdio_patch(ioaddr, 0x14, 1 << 5);
  468. mdio_patch(ioaddr, 0x0d, 1 << 5);
  469. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  470. }
  471. static void rtl8168c_1_hw_phy_config(void *ioaddr)
  472. {
  473. struct phy_reg phy_reg_init[] = {
  474. { 0x1f, 0x0001 },
  475. { 0x12, 0x2300 },
  476. { 0x1f, 0x0002 },
  477. { 0x00, 0x88d4 },
  478. { 0x01, 0x82b1 },
  479. { 0x03, 0x7002 },
  480. { 0x08, 0x9e30 },
  481. { 0x09, 0x01f0 },
  482. { 0x0a, 0x5500 },
  483. { 0x0c, 0x00c8 },
  484. { 0x1f, 0x0003 },
  485. { 0x12, 0xc096 },
  486. { 0x16, 0x000a },
  487. { 0x1f, 0x0000 },
  488. { 0x1f, 0x0000 },
  489. { 0x09, 0x2000 },
  490. { 0x09, 0x0000 }
  491. };
  492. DBGP ( "rtl8168c_1_hw_phy_config\n" );
  493. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  494. mdio_patch(ioaddr, 0x14, 1 << 5);
  495. mdio_patch(ioaddr, 0x0d, 1 << 5);
  496. mdio_write(ioaddr, 0x1f, 0x0000);
  497. }
  498. static void rtl8168c_2_hw_phy_config(void *ioaddr)
  499. {
  500. struct phy_reg phy_reg_init[] = {
  501. { 0x1f, 0x0001 },
  502. { 0x12, 0x2300 },
  503. { 0x03, 0x802f },
  504. { 0x02, 0x4f02 },
  505. { 0x01, 0x0409 },
  506. { 0x00, 0xf099 },
  507. { 0x04, 0x9800 },
  508. { 0x04, 0x9000 },
  509. { 0x1d, 0x3d98 },
  510. { 0x1f, 0x0002 },
  511. { 0x0c, 0x7eb8 },
  512. { 0x06, 0x0761 },
  513. { 0x1f, 0x0003 },
  514. { 0x16, 0x0f0a },
  515. { 0x1f, 0x0000 }
  516. };
  517. DBGP ( "rtl8168c_2_hw_phy_config\n" );
  518. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  519. mdio_patch(ioaddr, 0x16, 1 << 0);
  520. mdio_patch(ioaddr, 0x14, 1 << 5);
  521. mdio_patch(ioaddr, 0x0d, 1 << 5);
  522. mdio_write(ioaddr, 0x1f, 0x0000);
  523. }
  524. static void rtl8168c_3_hw_phy_config(void *ioaddr)
  525. {
  526. struct phy_reg phy_reg_init[] = {
  527. { 0x1f, 0x0001 },
  528. { 0x12, 0x2300 },
  529. { 0x1d, 0x3d98 },
  530. { 0x1f, 0x0002 },
  531. { 0x0c, 0x7eb8 },
  532. { 0x06, 0x5461 },
  533. { 0x1f, 0x0003 },
  534. { 0x16, 0x0f0a },
  535. { 0x1f, 0x0000 }
  536. };
  537. DBGP ( "rtl8168c_3_hw_phy_config\n" );
  538. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  539. mdio_patch(ioaddr, 0x16, 1 << 0);
  540. mdio_patch(ioaddr, 0x14, 1 << 5);
  541. mdio_patch(ioaddr, 0x0d, 1 << 5);
  542. mdio_write(ioaddr, 0x1f, 0x0000);
  543. }
  544. static void rtl8168c_4_hw_phy_config(void *ioaddr)
  545. {
  546. DBGP ( "rtl8168c_4_hw_phy_config\n" );
  547. rtl8168c_3_hw_phy_config(ioaddr);
  548. }
  549. static void rtl8168d_hw_phy_config(void *ioaddr)
  550. {
  551. struct phy_reg phy_reg_init_0[] = {
  552. { 0x1f, 0x0001 },
  553. { 0x09, 0x2770 },
  554. { 0x08, 0x04d0 },
  555. { 0x0b, 0xad15 },
  556. { 0x0c, 0x5bf0 },
  557. { 0x1c, 0xf101 },
  558. { 0x1f, 0x0003 },
  559. { 0x14, 0x94d7 },
  560. { 0x12, 0xf4d6 },
  561. { 0x09, 0xca0f },
  562. { 0x1f, 0x0002 },
  563. { 0x0b, 0x0b10 },
  564. { 0x0c, 0xd1f7 },
  565. { 0x1f, 0x0002 },
  566. { 0x06, 0x5461 },
  567. { 0x1f, 0x0002 },
  568. { 0x05, 0x6662 },
  569. { 0x1f, 0x0000 },
  570. { 0x14, 0x0060 },
  571. { 0x1f, 0x0000 },
  572. { 0x0d, 0xf8a0 },
  573. { 0x1f, 0x0005 },
  574. { 0x05, 0xffc2 }
  575. };
  576. DBGP ( "rtl8168d_hw_phy_config\n" );
  577. rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
  578. if (mdio_read(ioaddr, 0x06) == 0xc400) {
  579. struct phy_reg phy_reg_init_1[] = {
  580. { 0x1f, 0x0005 },
  581. { 0x01, 0x0300 },
  582. { 0x1f, 0x0000 },
  583. { 0x11, 0x401c },
  584. { 0x16, 0x4100 },
  585. { 0x1f, 0x0005 },
  586. { 0x07, 0x0010 },
  587. { 0x05, 0x83dc },
  588. { 0x06, 0x087d },
  589. { 0x05, 0x8300 },
  590. { 0x06, 0x0101 },
  591. { 0x06, 0x05f8 },
  592. { 0x06, 0xf9fa },
  593. { 0x06, 0xfbef },
  594. { 0x06, 0x79e2 },
  595. { 0x06, 0x835f },
  596. { 0x06, 0xe0f8 },
  597. { 0x06, 0x9ae1 },
  598. { 0x06, 0xf89b },
  599. { 0x06, 0xef31 },
  600. { 0x06, 0x3b65 },
  601. { 0x06, 0xaa07 },
  602. { 0x06, 0x81e4 },
  603. { 0x06, 0xf89a },
  604. { 0x06, 0xe5f8 },
  605. { 0x06, 0x9baf },
  606. { 0x06, 0x06ae },
  607. { 0x05, 0x83dc },
  608. { 0x06, 0x8300 },
  609. };
  610. rtl_phy_write(ioaddr, phy_reg_init_1,
  611. ARRAY_SIZE(phy_reg_init_1));
  612. }
  613. mdio_write(ioaddr, 0x1f, 0x0000);
  614. }
  615. static void rtl8102e_hw_phy_config(void *ioaddr)
  616. {
  617. struct phy_reg phy_reg_init[] = {
  618. { 0x1f, 0x0003 },
  619. { 0x08, 0x441d },
  620. { 0x01, 0x9100 },
  621. { 0x1f, 0x0000 }
  622. };
  623. DBGP ( "rtl8102e_hw_phy_config\n" );
  624. mdio_write(ioaddr, 0x1f, 0x0000);
  625. mdio_patch(ioaddr, 0x11, 1 << 12);
  626. mdio_patch(ioaddr, 0x19, 1 << 13);
  627. rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
  628. }
  629. static void rtl_hw_phy_config(struct net_device *dev)
  630. {
  631. struct rtl8169_private *tp = netdev_priv(dev);
  632. void *ioaddr = tp->mmio_addr;
  633. DBGP ( "rtl_hw_phy_config\n" );
  634. DBG ( "mac_version = 0x%02x\n", tp->mac_version );
  635. switch (tp->mac_version) {
  636. case RTL_GIGA_MAC_VER_01:
  637. break;
  638. case RTL_GIGA_MAC_VER_02:
  639. case RTL_GIGA_MAC_VER_03:
  640. rtl8169s_hw_phy_config(ioaddr);
  641. break;
  642. case RTL_GIGA_MAC_VER_04:
  643. rtl8169sb_hw_phy_config(ioaddr);
  644. break;
  645. case RTL_GIGA_MAC_VER_07:
  646. case RTL_GIGA_MAC_VER_08:
  647. case RTL_GIGA_MAC_VER_09:
  648. rtl8102e_hw_phy_config(ioaddr);
  649. break;
  650. case RTL_GIGA_MAC_VER_11:
  651. rtl8168bb_hw_phy_config(ioaddr);
  652. break;
  653. case RTL_GIGA_MAC_VER_12:
  654. rtl8168bef_hw_phy_config(ioaddr);
  655. break;
  656. case RTL_GIGA_MAC_VER_17:
  657. rtl8168bef_hw_phy_config(ioaddr);
  658. break;
  659. case RTL_GIGA_MAC_VER_18:
  660. rtl8168cp_1_hw_phy_config(ioaddr);
  661. break;
  662. case RTL_GIGA_MAC_VER_19:
  663. rtl8168c_1_hw_phy_config(ioaddr);
  664. break;
  665. case RTL_GIGA_MAC_VER_20:
  666. rtl8168c_2_hw_phy_config(ioaddr);
  667. break;
  668. case RTL_GIGA_MAC_VER_21:
  669. rtl8168c_3_hw_phy_config(ioaddr);
  670. break;
  671. case RTL_GIGA_MAC_VER_22:
  672. rtl8168c_4_hw_phy_config(ioaddr);
  673. break;
  674. case RTL_GIGA_MAC_VER_23:
  675. case RTL_GIGA_MAC_VER_24:
  676. rtl8168cp_2_hw_phy_config(ioaddr);
  677. break;
  678. case RTL_GIGA_MAC_VER_25:
  679. rtl8168d_hw_phy_config(ioaddr);
  680. break;
  681. default:
  682. break;
  683. }
  684. }
  685. static void rtl8169_phy_reset(struct net_device *dev __unused,
  686. struct rtl8169_private *tp)
  687. {
  688. void *ioaddr = tp->mmio_addr;
  689. unsigned int i;
  690. DBGP ( "rtl8169_phy_reset\n" );
  691. tp->phy_reset_enable(ioaddr);
  692. for (i = 0; i < 100; i++) {
  693. if (!tp->phy_reset_pending(ioaddr))
  694. return;
  695. mdelay ( 1 );
  696. }
  697. DBG ( "PHY reset failed.\n" );
  698. }
  699. static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
  700. {
  701. void *ioaddr = tp->mmio_addr;
  702. DBGP ( "rtl8169_init_phy\n" );
  703. rtl_hw_phy_config(dev);
  704. if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
  705. DBG ( "Set MAC Reg C+CR Offset 0x82h = 0x01h\n" );
  706. RTL_W8(0x82, 0x01);
  707. }
  708. pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
  709. if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
  710. pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
  711. if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
  712. DBG ( "Set MAC Reg C+CR Offset 0x82h = 0x01h\n" );
  713. RTL_W8(0x82, 0x01);
  714. DBG ( "Set PHY Reg 0x0bh = 0x00h\n" );
  715. mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0
  716. }
  717. rtl8169_phy_reset(dev, tp);
  718. /*
  719. * rtl8169_set_speed_xmii takes good care of the Fast Ethernet
  720. * only 8101. Don't panic.
  721. */
  722. rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL);
  723. if ((RTL_R8(PHYstatus) & TBI_Enable))
  724. DBG ( "TBI auto-negotiating\n" );
  725. }
  726. static const struct rtl_cfg_info {
  727. void (*hw_start)(struct net_device *);
  728. unsigned int region;
  729. unsigned int align;
  730. u16 intr_event;
  731. u16 napi_event;
  732. unsigned features;
  733. } rtl_cfg_infos [] = {
  734. [RTL_CFG_0] = {
  735. .hw_start = rtl_hw_start_8169,
  736. .region = 1,
  737. .align = 0,
  738. .intr_event = SYSErr | LinkChg | RxOverflow |
  739. RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
  740. .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
  741. .features = RTL_FEATURE_GMII
  742. },
  743. [RTL_CFG_1] = {
  744. .hw_start = rtl_hw_start_8168,
  745. .region = 2,
  746. .align = 8,
  747. .intr_event = SYSErr | LinkChg | RxOverflow |
  748. TxErr | TxOK | RxOK | RxErr,
  749. .napi_event = TxErr | TxOK | RxOK | RxOverflow,
  750. .features = RTL_FEATURE_GMII
  751. },
  752. [RTL_CFG_2] = {
  753. .hw_start = rtl_hw_start_8101,
  754. .region = 2,
  755. .align = 8,
  756. .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout |
  757. RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
  758. .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
  759. }
  760. };
  761. static void rtl8169_hw_reset(void *ioaddr)
  762. {
  763. DBGP ( "rtl8169_hw_reset\n" );
  764. /* Disable interrupts */
  765. rtl8169_irq_mask_and_ack(ioaddr);
  766. /* Reset the chipset */
  767. RTL_W8(ChipCmd, CmdReset);
  768. /* PCI commit */
  769. RTL_R8(ChipCmd);
  770. }
  771. static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
  772. {
  773. void *ioaddr = tp->mmio_addr;
  774. u32 cfg = rtl8169_rx_config;
  775. DBGP ( "rtl_set_rx_tx_config_registers\n" );
  776. cfg |= (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask);
  777. RTL_W32(RxConfig, cfg);
  778. /* Set DMA burst size and Interframe Gap Time */
  779. RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
  780. (InterFrameGap << TxInterFrameGapShift));
  781. }
  782. static void rtl_soft_reset ( struct net_device *dev )
  783. {
  784. struct rtl8169_private *tp = netdev_priv(dev);
  785. void *ioaddr = tp->mmio_addr;
  786. unsigned int i;
  787. DBGP ( "rtl_hw_soft_reset\n" );
  788. /* Soft reset the chip. */
  789. RTL_W8(ChipCmd, CmdReset);
  790. /* Check that the chip has finished the reset. */
  791. for (i = 0; i < 100; i++) {
  792. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  793. break;
  794. mdelay ( 1 );
  795. }
  796. if ( i == 100 ) {
  797. DBG ( "Reset Failed! (> 100 iterations)\n" );
  798. }
  799. }
  800. static void rtl_hw_start ( struct net_device *dev )
  801. {
  802. struct rtl8169_private *tp = netdev_priv ( dev );
  803. DBGP ( "rtl_hw_start\n" );
  804. /* Soft reset NIC */
  805. rtl_soft_reset ( dev );
  806. tp->hw_start ( dev );
  807. }
  808. static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp,
  809. void *ioaddr)
  810. {
  811. DBGP ( "rtl_set_rx_tx_desc_registers\n" );
  812. /*
  813. * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh
  814. * register to be written before TxDescAddrLow to work.
  815. * Switching from MMIO to I/O access fixes the issue as well.
  816. */
  817. RTL_W32 ( TxDescStartAddrHigh, 0 );
  818. RTL_W32 ( TxDescStartAddrLow, virt_to_bus ( tp->tx_base ) );
  819. RTL_W32 ( RxDescAddrHigh, 0 );
  820. RTL_W32 ( RxDescAddrLow, virt_to_bus ( tp->rx_base ) );
  821. }
  822. static u16 rtl_rw_cpluscmd(void *ioaddr)
  823. {
  824. u16 cmd;
  825. DBGP ( "rtl_rw_cpluscmd\n" );
  826. cmd = RTL_R16(CPlusCmd);
  827. RTL_W16(CPlusCmd, cmd);
  828. return cmd;
  829. }
  830. static void rtl_set_rx_max_size(void *ioaddr)
  831. {
  832. DBGP ( "rtl_set_rx_max_size\n" );
  833. RTL_W16 ( RxMaxSize, RX_BUF_SIZE );
  834. }
  835. static void rtl8169_set_magic_reg(void *ioaddr, unsigned mac_version)
  836. {
  837. struct {
  838. u32 mac_version;
  839. u32 clk;
  840. u32 val;
  841. } cfg2_info [] = {
  842. { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd
  843. { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff },
  844. { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe
  845. { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff }
  846. }, *p = cfg2_info;
  847. unsigned int i;
  848. u32 clk;
  849. DBGP ( "rtl8169_set_magic_reg\n" );
  850. clk = RTL_R8(Config2) & PCI_Clock_66MHz;
  851. for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
  852. if ((p->mac_version == mac_version) && (p->clk == clk)) {
  853. RTL_W32(0x7c, p->val);
  854. break;
  855. }
  856. }
  857. }
  858. static void rtl_set_rx_mode ( struct net_device *netdev )
  859. {
  860. struct rtl8169_private *tp = netdev_priv ( netdev );
  861. void *ioaddr = tp->mmio_addr;
  862. u32 tmp;
  863. DBGP ( "rtl_set_rx_mode\n" );
  864. /* Accept all Multicast Packets */
  865. RTL_W32 ( MAR0 + 0, 0xffffffff );
  866. RTL_W32 ( MAR0 + 4, 0xffffffff );
  867. tmp = rtl8169_rx_config | AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
  868. ( RTL_R32 ( RxConfig ) & rtl_chip_info[tp->chipset].RxConfigMask );
  869. RTL_W32 ( RxConfig, tmp );
  870. }
  871. static void rtl_hw_start_8169(struct net_device *dev)
  872. {
  873. struct rtl8169_private *tp = netdev_priv(dev);
  874. void *ioaddr = tp->mmio_addr;
  875. struct pci_device *pdev = tp->pci_dev;
  876. DBGP ( "rtl_hw_start_8169\n" );
  877. if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
  878. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW);
  879. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08);
  880. }
  881. RTL_W8(Cfg9346, Cfg9346_Unlock);
  882. if ((tp->mac_version == RTL_GIGA_MAC_VER_01) ||
  883. (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  884. (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
  885. (tp->mac_version == RTL_GIGA_MAC_VER_04))
  886. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  887. RTL_W8(EarlyTxThres, EarlyTxThld);
  888. rtl_set_rx_max_size(ioaddr);
  889. if ((tp->mac_version == RTL_GIGA_MAC_VER_01) ||
  890. (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  891. (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
  892. (tp->mac_version == RTL_GIGA_MAC_VER_04))
  893. rtl_set_rx_tx_config_registers(tp);
  894. tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
  895. if ((tp->mac_version == RTL_GIGA_MAC_VER_02) ||
  896. (tp->mac_version == RTL_GIGA_MAC_VER_03)) {
  897. DBG ( "Set MAC Reg C+CR Offset 0xE0. "
  898. "Bit-3 and bit-14 MUST be 1\n" );
  899. tp->cp_cmd |= (1 << 14);
  900. }
  901. RTL_W16(CPlusCmd, tp->cp_cmd);
  902. rtl8169_set_magic_reg(ioaddr, tp->mac_version);
  903. /*
  904. * Undocumented corner. Supposedly:
  905. * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
  906. */
  907. RTL_W16(IntrMitigate, 0x0000);
  908. rtl_set_rx_tx_desc_registers(tp, ioaddr);
  909. if ((tp->mac_version != RTL_GIGA_MAC_VER_01) &&
  910. (tp->mac_version != RTL_GIGA_MAC_VER_02) &&
  911. (tp->mac_version != RTL_GIGA_MAC_VER_03) &&
  912. (tp->mac_version != RTL_GIGA_MAC_VER_04)) {
  913. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  914. rtl_set_rx_tx_config_registers(tp);
  915. }
  916. RTL_W8(Cfg9346, Cfg9346_Lock);
  917. /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
  918. RTL_R8(IntrMask);
  919. RTL_W32(RxMissed, 0);
  920. rtl_set_rx_mode(dev);
  921. /* no early-rx interrupts */
  922. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  923. // RTL_W16(IntrMask, tp->intr_event);
  924. }
  925. static void rtl_tx_performance_tweak(struct pci_device *pdev, u16 force)
  926. {
  927. struct net_device *dev = pci_get_drvdata(pdev);
  928. struct rtl8169_private *tp = netdev_priv(dev);
  929. int cap = tp->pcie_cap;
  930. DBGP ( "rtl_tx_performance_tweak\n" );
  931. if (cap) {
  932. u16 ctl;
  933. pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl);
  934. ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force;
  935. pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl);
  936. }
  937. }
  938. static void rtl_csi_access_enable(void *ioaddr)
  939. {
  940. u32 csi;
  941. DBGP ( "rtl_csi_access_enable\n" );
  942. csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff;
  943. rtl_csi_write(ioaddr, 0x070c, csi | 0x27000000);
  944. }
  945. struct ephy_info {
  946. unsigned int offset;
  947. u16 mask;
  948. u16 bits;
  949. };
  950. static void rtl_ephy_init(void *ioaddr, struct ephy_info *e, int len)
  951. {
  952. u16 w;
  953. DBGP ( "rtl_ephy_init\n" );
  954. while (len-- > 0) {
  955. w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits;
  956. rtl_ephy_write(ioaddr, e->offset, w);
  957. e++;
  958. }
  959. }
  960. static void rtl_disable_clock_request(struct pci_device *pdev)
  961. {
  962. struct net_device *dev = pci_get_drvdata(pdev);
  963. struct rtl8169_private *tp = netdev_priv(dev);
  964. int cap = tp->pcie_cap;
  965. DBGP ( "rtl_disable_clock_request\n" );
  966. if (cap) {
  967. u16 ctl;
  968. pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl);
  969. ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN;
  970. pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl);
  971. }
  972. }
  973. #define R8168_CPCMD_QUIRK_MASK (\
  974. EnableBist | \
  975. Mac_dbgo_oe | \
  976. Force_half_dup | \
  977. Force_rxflow_en | \
  978. Force_txflow_en | \
  979. Cxpl_dbg_sel | \
  980. ASF | \
  981. PktCntrDisable | \
  982. Mac_dbgo_sel)
  983. static void rtl_hw_start_8168bb(void *ioaddr, struct pci_device *pdev)
  984. {
  985. DBGP ( "rtl_hw_start_8168bb\n" );
  986. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  987. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  988. rtl_tx_performance_tweak(pdev,
  989. (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN);
  990. }
  991. static void rtl_hw_start_8168bef(void *ioaddr, struct pci_device *pdev)
  992. {
  993. DBGP ( "rtl_hw_start_8168bef\n" );
  994. rtl_hw_start_8168bb(ioaddr, pdev);
  995. RTL_W8(EarlyTxThres, EarlyTxThld);
  996. RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0));
  997. }
  998. static void __rtl_hw_start_8168cp(void *ioaddr, struct pci_device *pdev)
  999. {
  1000. DBGP ( "__rtl_hw_start_8168cp\n" );
  1001. RTL_W8(Config1, RTL_R8(Config1) | Speed_down);
  1002. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  1003. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  1004. rtl_disable_clock_request(pdev);
  1005. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  1006. }
  1007. static void rtl_hw_start_8168cp_1(void *ioaddr, struct pci_device *pdev)
  1008. {
  1009. static struct ephy_info e_info_8168cp[] = {
  1010. { 0x01, 0, 0x0001 },
  1011. { 0x02, 0x0800, 0x1000 },
  1012. { 0x03, 0, 0x0042 },
  1013. { 0x06, 0x0080, 0x0000 },
  1014. { 0x07, 0, 0x2000 }
  1015. };
  1016. DBGP ( "rtl_hw_start_8168cp_1\n" );
  1017. rtl_csi_access_enable(ioaddr);
  1018. rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp));
  1019. __rtl_hw_start_8168cp(ioaddr, pdev);
  1020. }
  1021. static void rtl_hw_start_8168cp_2(void *ioaddr, struct pci_device *pdev)
  1022. {
  1023. DBGP ( "rtl_hw_start_8168cp_2\n" );
  1024. rtl_csi_access_enable(ioaddr);
  1025. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  1026. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  1027. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  1028. }
  1029. static void rtl_hw_start_8168cp_3(void *ioaddr, struct pci_device *pdev)
  1030. {
  1031. DBGP ( "rtl_hw_start_8168cp_3\n" );
  1032. rtl_csi_access_enable(ioaddr);
  1033. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  1034. /* Magic. */
  1035. RTL_W8(DBG_REG, 0x20);
  1036. RTL_W8(EarlyTxThres, EarlyTxThld);
  1037. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  1038. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  1039. }
  1040. static void rtl_hw_start_8168c_1(void *ioaddr, struct pci_device *pdev)
  1041. {
  1042. static struct ephy_info e_info_8168c_1[] = {
  1043. { 0x02, 0x0800, 0x1000 },
  1044. { 0x03, 0, 0x0002 },
  1045. { 0x06, 0x0080, 0x0000 }
  1046. };
  1047. DBGP ( "rtl_hw_start_8168c_1\n" );
  1048. rtl_csi_access_enable(ioaddr);
  1049. RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2);
  1050. rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1));
  1051. __rtl_hw_start_8168cp(ioaddr, pdev);
  1052. }
  1053. static void rtl_hw_start_8168c_2(void *ioaddr, struct pci_device *pdev)
  1054. {
  1055. static struct ephy_info e_info_8168c_2[] = {
  1056. { 0x01, 0, 0x0001 },
  1057. { 0x03, 0x0400, 0x0220 }
  1058. };
  1059. DBGP ( "rtl_hw_start_8168c_2\n" );
  1060. rtl_csi_access_enable(ioaddr);
  1061. rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2));
  1062. __rtl_hw_start_8168cp(ioaddr, pdev);
  1063. }
  1064. static void rtl_hw_start_8168c_3(void *ioaddr, struct pci_device *pdev)
  1065. {
  1066. DBGP ( "rtl_hw_start_8168c_3\n" );
  1067. rtl_hw_start_8168c_2(ioaddr, pdev);
  1068. }
  1069. static void rtl_hw_start_8168c_4(void *ioaddr, struct pci_device *pdev)
  1070. {
  1071. DBGP ( "rtl_hw_start_8168c_4\n" );
  1072. rtl_csi_access_enable(ioaddr);
  1073. __rtl_hw_start_8168cp(ioaddr, pdev);
  1074. }
  1075. static void rtl_hw_start_8168d(void *ioaddr, struct pci_device *pdev)
  1076. {
  1077. DBGP ( "rtl_hw_start_8168d\n" );
  1078. rtl_csi_access_enable(ioaddr);
  1079. rtl_disable_clock_request(pdev);
  1080. RTL_W8(EarlyTxThres, EarlyTxThld);
  1081. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  1082. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
  1083. }
  1084. static void rtl_hw_start_8168(struct net_device *dev)
  1085. {
  1086. struct rtl8169_private *tp = netdev_priv(dev);
  1087. void *ioaddr = tp->mmio_addr;
  1088. struct pci_device *pdev = tp->pci_dev;
  1089. DBGP ( "rtl_hw_start_8168\n" );
  1090. RTL_W8(Cfg9346, Cfg9346_Unlock);
  1091. RTL_W8(EarlyTxThres, EarlyTxThld);
  1092. rtl_set_rx_max_size(ioaddr);
  1093. tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1;
  1094. RTL_W16(CPlusCmd, tp->cp_cmd);
  1095. RTL_W16(IntrMitigate, 0x5151);
  1096. /* Work around for RxFIFO overflow. */
  1097. if (tp->mac_version == RTL_GIGA_MAC_VER_11) {
  1098. tp->intr_event |= RxFIFOOver | PCSTimeout;
  1099. tp->intr_event &= ~RxOverflow;
  1100. }
  1101. rtl_set_rx_tx_desc_registers(tp, ioaddr);
  1102. rtl_set_rx_mode(dev);
  1103. RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
  1104. (InterFrameGap << TxInterFrameGapShift));
  1105. RTL_R8(IntrMask);
  1106. switch (tp->mac_version) {
  1107. case RTL_GIGA_MAC_VER_11:
  1108. rtl_hw_start_8168bb(ioaddr, pdev);
  1109. break;
  1110. case RTL_GIGA_MAC_VER_12:
  1111. case RTL_GIGA_MAC_VER_17:
  1112. rtl_hw_start_8168bef(ioaddr, pdev);
  1113. break;
  1114. case RTL_GIGA_MAC_VER_18:
  1115. rtl_hw_start_8168cp_1(ioaddr, pdev);
  1116. break;
  1117. case RTL_GIGA_MAC_VER_19:
  1118. rtl_hw_start_8168c_1(ioaddr, pdev);
  1119. break;
  1120. case RTL_GIGA_MAC_VER_20:
  1121. rtl_hw_start_8168c_2(ioaddr, pdev);
  1122. break;
  1123. case RTL_GIGA_MAC_VER_21:
  1124. rtl_hw_start_8168c_3(ioaddr, pdev);
  1125. break;
  1126. case RTL_GIGA_MAC_VER_22:
  1127. rtl_hw_start_8168c_4(ioaddr, pdev);
  1128. break;
  1129. case RTL_GIGA_MAC_VER_23:
  1130. rtl_hw_start_8168cp_2(ioaddr, pdev);
  1131. break;
  1132. case RTL_GIGA_MAC_VER_24:
  1133. rtl_hw_start_8168cp_3(ioaddr, pdev);
  1134. break;
  1135. case RTL_GIGA_MAC_VER_25:
  1136. rtl_hw_start_8168d(ioaddr, pdev);
  1137. break;
  1138. default:
  1139. DBG ( "Unknown chipset (mac_version = %d).\n",
  1140. tp->mac_version );
  1141. break;
  1142. }
  1143. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  1144. RTL_W8(Cfg9346, Cfg9346_Lock);
  1145. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  1146. // RTL_W16(IntrMask, tp->intr_event);
  1147. }
  1148. #define R810X_CPCMD_QUIRK_MASK (\
  1149. EnableBist | \
  1150. Mac_dbgo_oe | \
  1151. Force_half_dup | \
  1152. Force_half_dup | \
  1153. Force_txflow_en | \
  1154. Cxpl_dbg_sel | \
  1155. ASF | \
  1156. PktCntrDisable | \
  1157. PCIDAC | \
  1158. PCIMulRW)
  1159. static void rtl_hw_start_8102e_1(void *ioaddr, struct pci_device *pdev)
  1160. {
  1161. static struct ephy_info e_info_8102e_1[] = {
  1162. { 0x01, 0, 0x6e65 },
  1163. { 0x02, 0, 0x091f },
  1164. { 0x03, 0, 0xc2f9 },
  1165. { 0x06, 0, 0xafb5 },
  1166. { 0x07, 0, 0x0e00 },
  1167. { 0x19, 0, 0xec80 },
  1168. { 0x01, 0, 0x2e65 },
  1169. { 0x01, 0, 0x6e65 }
  1170. };
  1171. u8 cfg1;
  1172. DBGP ( "rtl_hw_start_8102e_1\n" );
  1173. rtl_csi_access_enable(ioaddr);
  1174. RTL_W8(DBG_REG, FIX_NAK_1);
  1175. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  1176. RTL_W8(Config1,
  1177. LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable);
  1178. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  1179. cfg1 = RTL_R8(Config1);
  1180. if ((cfg1 & LEDS0) && (cfg1 & LEDS1))
  1181. RTL_W8(Config1, cfg1 & ~LEDS0);
  1182. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK);
  1183. rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1));
  1184. }
  1185. static void rtl_hw_start_8102e_2(void *ioaddr, struct pci_device *pdev)
  1186. {
  1187. DBGP ( "rtl_hw_start_8102e_2\n" );
  1188. rtl_csi_access_enable(ioaddr);
  1189. rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
  1190. RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable);
  1191. RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
  1192. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK);
  1193. }
  1194. static void rtl_hw_start_8102e_3(void *ioaddr, struct pci_device *pdev)
  1195. {
  1196. DBGP ( "rtl_hw_start_8102e_3\n" );
  1197. rtl_hw_start_8102e_2(ioaddr, pdev);
  1198. rtl_ephy_write(ioaddr, 0x03, 0xc2f9);
  1199. }
  1200. static void rtl_hw_start_8101(struct net_device *dev)
  1201. {
  1202. struct rtl8169_private *tp = netdev_priv(dev);
  1203. void *ioaddr = tp->mmio_addr;
  1204. struct pci_device *pdev = tp->pci_dev;
  1205. DBGP ( "rtl_hw_start_8101\n" );
  1206. if ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
  1207. (tp->mac_version == RTL_GIGA_MAC_VER_16)) {
  1208. int cap = tp->pcie_cap;
  1209. if (cap) {
  1210. pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL,
  1211. PCI_EXP_DEVCTL_NOSNOOP_EN);
  1212. }
  1213. }
  1214. switch (tp->mac_version) {
  1215. case RTL_GIGA_MAC_VER_07:
  1216. rtl_hw_start_8102e_1(ioaddr, pdev);
  1217. break;
  1218. case RTL_GIGA_MAC_VER_08:
  1219. rtl_hw_start_8102e_3(ioaddr, pdev);
  1220. break;
  1221. case RTL_GIGA_MAC_VER_09:
  1222. rtl_hw_start_8102e_2(ioaddr, pdev);
  1223. break;
  1224. }
  1225. RTL_W8(Cfg9346, Cfg9346_Unlock);
  1226. RTL_W8(EarlyTxThres, EarlyTxThld);
  1227. rtl_set_rx_max_size(ioaddr);
  1228. tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
  1229. RTL_W16(CPlusCmd, tp->cp_cmd);
  1230. RTL_W16(IntrMitigate, 0x0000);
  1231. rtl_set_rx_tx_desc_registers(tp, ioaddr);
  1232. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  1233. rtl_set_rx_tx_config_registers(tp);
  1234. RTL_W8(Cfg9346, Cfg9346_Lock);
  1235. RTL_R8(IntrMask);
  1236. rtl_set_rx_mode(dev);
  1237. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  1238. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
  1239. // RTL_W16(IntrMask, tp->intr_event);
  1240. }
  1241. /*** gPXE API Support Routines ***/
  1242. /**
  1243. * setup_tx_resources - allocate tx resources (descriptors)
  1244. *
  1245. * @v tp Driver private storage
  1246. *
  1247. * @ret rc Returns 0 on success, negative on failure
  1248. **/
  1249. static int
  1250. rtl8169_setup_tx_resources ( struct rtl8169_private *tp )
  1251. {
  1252. DBGP ( "rtl8169_setup_tx_resources\n" );
  1253. tp->tx_base = malloc_dma ( R8169_TX_RING_BYTES, TX_RING_ALIGN );
  1254. if ( ! tp->tx_base ) {
  1255. return -ENOMEM;
  1256. }
  1257. memset ( tp->tx_base, 0, R8169_TX_RING_BYTES );
  1258. DBG ( "tp->tx_base = %#08lx\n", virt_to_bus ( tp->tx_base ) );
  1259. tp->tx_fill_ctr = 0;
  1260. tp->tx_curr = 0;
  1261. tp->tx_tail = 0;
  1262. return 0;
  1263. }
  1264. static void
  1265. rtl8169_process_tx_packets ( struct net_device *netdev )
  1266. {
  1267. struct rtl8169_private *tp = netdev_priv ( netdev );
  1268. uint32_t tx_status;
  1269. struct TxDesc *tx_curr_desc;
  1270. DBGP ( "rtl8169_process_tx_packets\n" );
  1271. while ( tp->tx_tail != tp->tx_curr ) {
  1272. tx_curr_desc = tp->tx_base + tp->tx_tail;
  1273. tx_status = tx_curr_desc->opts1;
  1274. DBG2 ( "Before DescOwn check tx_status: %#08x\n", tx_status );
  1275. /* if the packet at tx_tail is not owned by hardware it is for us */
  1276. if ( tx_status & DescOwn )
  1277. break;
  1278. DBG ( "Transmitted packet.\n" );
  1279. DBG ( "tp->tx_fill_ctr = %d\n", tp->tx_fill_ctr );
  1280. DBG ( "tp->tx_tail = %d\n", tp->tx_tail );
  1281. DBG ( "tp->tx_curr = %d\n", tp->tx_curr );
  1282. DBG ( "tx_status = %d\n", tx_status );
  1283. DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
  1284. /* Pass packet to core for processing */
  1285. netdev_tx_complete ( netdev, tp->tx_iobuf[tp->tx_tail] );
  1286. memset ( tx_curr_desc, 0, sizeof ( *tx_curr_desc ) );
  1287. /* Decrement count of used descriptors */
  1288. tp->tx_fill_ctr--;
  1289. /* Increment sent packets index */
  1290. tp->tx_tail = ( tp->tx_tail + 1 ) % NUM_TX_DESC;
  1291. }
  1292. }
  1293. static void
  1294. rtl8169_free_tx_resources ( struct rtl8169_private *tp )
  1295. {
  1296. DBGP ( "rtl8169_free_tx_resources\n" );
  1297. free_dma ( tp->tx_base, R8169_TX_RING_BYTES );
  1298. }
  1299. static void
  1300. rtl8169_populate_rx_descriptor ( struct rtl8169_private *tp, struct RxDesc *rx_desc, uint32_t index )
  1301. {
  1302. DBGP ( "rtl8169_populate_rx_descriptor\n" );
  1303. DBG ( "Populating rx descriptor %d\n", index );
  1304. memset ( rx_desc, 0, sizeof ( *rx_desc ) );
  1305. rx_desc->addr_hi = 0;
  1306. rx_desc->addr_lo = virt_to_bus ( tp->rx_iobuf[index]->data );
  1307. rx_desc->opts2 = 0;
  1308. rx_desc->opts1 = ( index == ( NUM_RX_DESC - 1 ) ? RingEnd : 0 ) |
  1309. RX_BUF_SIZE;
  1310. rx_desc->opts1 |= DescOwn;
  1311. }
  1312. /**
  1313. * Refill descriptor ring
  1314. *
  1315. * @v netdev Net device
  1316. */
  1317. static void rtl8169_refill_rx_ring ( struct rtl8169_private *tp )
  1318. {
  1319. struct RxDesc *rx_curr_desc;
  1320. int i;
  1321. DBGP ( "rtl8169_refill_rx_ring\n" );
  1322. for ( i = 0; i < NUM_RX_DESC; i++ ) {
  1323. rx_curr_desc = ( tp->rx_base ) + i;
  1324. /* Don't touch descriptors owned by the NIC */
  1325. if ( rx_curr_desc->opts1 & DescOwn )
  1326. continue;
  1327. /* Don't touch descriptors with iobufs, they still need to be
  1328. processed by the poll routine */
  1329. if ( tp->rx_iobuf[tp->rx_curr] != NULL )
  1330. continue;
  1331. /** If we can't get an iobuf for this descriptor
  1332. try again later (next poll).
  1333. */
  1334. if ( ! ( tp->rx_iobuf[i] = alloc_iob ( RX_BUF_SIZE ) ) ) {
  1335. DBG ( "Refill rx ring failed!!\n" );
  1336. break;
  1337. }
  1338. rtl8169_populate_rx_descriptor ( tp, rx_curr_desc, i );
  1339. }
  1340. }
  1341. /**
  1342. * setup_rx_resources - allocate Rx resources (Descriptors)
  1343. *
  1344. * @v tp: Driver private structure
  1345. *
  1346. * @ret rc Returns 0 on success, negative on failure
  1347. *
  1348. **/
  1349. static int
  1350. rtl8169_setup_rx_resources ( struct rtl8169_private *tp )
  1351. {
  1352. DBGP ( "rtl8169_setup_rx_resources\n" );
  1353. tp->rx_base = malloc_dma ( R8169_RX_RING_BYTES, RX_RING_ALIGN );
  1354. DBG ( "tp->rx_base = %#08lx\n", virt_to_bus ( tp->rx_base ) );
  1355. if ( ! tp->rx_base ) {
  1356. return -ENOMEM;
  1357. }
  1358. memset ( tp->rx_base, 0, R8169_RX_RING_BYTES );
  1359. rtl8169_refill_rx_ring ( tp );
  1360. tp->rx_curr = 0;
  1361. return 0;
  1362. }
  1363. static void
  1364. rtl8169_process_rx_packets ( struct net_device *netdev )
  1365. {
  1366. struct rtl8169_private *tp = netdev_priv ( netdev );
  1367. uint32_t rx_status;
  1368. uint16_t rx_len;
  1369. struct RxDesc *rx_curr_desc;
  1370. int i;
  1371. DBGP ( "rtl8169_process_rx_packets\n" );
  1372. for ( i = 0; i < NUM_RX_DESC; i++ ) {
  1373. rx_curr_desc = tp->rx_base + tp->rx_curr;
  1374. rx_status = rx_curr_desc->opts1;
  1375. DBG2 ( "Before DescOwn check rx_status: %#08x\n", rx_status );
  1376. /* Hardware still owns the descriptor */
  1377. if ( rx_status & DescOwn )
  1378. break;
  1379. /* We own the descriptor, but it has not been refilled yet */
  1380. if ( tp->rx_iobuf[tp->rx_curr] == NULL )
  1381. break;
  1382. rx_len = rx_status & 0x3fff;
  1383. DBG ( "Received packet.\n" );
  1384. DBG ( "tp->rx_curr = %d\n", tp->rx_curr );
  1385. DBG ( "rx_len = %d\n", rx_len );
  1386. DBG ( "rx_status = %#08x\n", rx_status );
  1387. DBG ( "rx_curr_desc = %#08lx\n", virt_to_bus ( rx_curr_desc ) );
  1388. if ( rx_status & RxRES ) {
  1389. netdev_rx_err ( netdev, tp->rx_iobuf[tp->rx_curr], -EINVAL );
  1390. DBG ( "rtl8169_poll: Corrupted packet received!\n"
  1391. " rx_status: %#08x\n", rx_status );
  1392. } else {
  1393. /* Adjust size of the iobuf to reflect received data */
  1394. iob_put ( tp->rx_iobuf[tp->rx_curr], rx_len );
  1395. /* Add this packet to the receive queue. */
  1396. netdev_rx ( netdev, tp->rx_iobuf[tp->rx_curr] );
  1397. }
  1398. /* Invalidate this iobuf and descriptor */
  1399. tp->rx_iobuf[tp->rx_curr] = NULL;
  1400. memset ( rx_curr_desc, 0, sizeof ( *rx_curr_desc ) );
  1401. /* Update pointer to next available rx descriptor */
  1402. tp->rx_curr = ( tp->rx_curr + 1 ) % NUM_RX_DESC;
  1403. }
  1404. rtl8169_refill_rx_ring ( tp );
  1405. }
  1406. static void
  1407. rtl8169_free_rx_resources ( struct rtl8169_private *tp )
  1408. {
  1409. int i;
  1410. DBGP ( "rtl8169_free_rx_resources\n" );
  1411. free_dma ( tp->rx_base, R8169_RX_RING_BYTES );
  1412. for ( i = 0; i < NUM_RX_DESC; i++ ) {
  1413. free_iob ( tp->rx_iobuf[i] );
  1414. tp->rx_iobuf[i] = NULL;
  1415. }
  1416. }
  1417. /**
  1418. FIXME: Because gPXE's pci_device_id structure does not contain a
  1419. field to contain arbitrary data, we need the following table to
  1420. associate PCI IDs with nic variants, because a lot of driver
  1421. routines depend on knowing which kind of variant they are dealing
  1422. with. --mdc
  1423. **/
  1424. #define _R(VENDOR,DEVICE,INDEX) \
  1425. { .vendor = VENDOR, .device = DEVICE, .index = INDEX }
  1426. static const struct {
  1427. uint16_t vendor;
  1428. uint16_t device;
  1429. int index;
  1430. } nic_variant_table[] = {
  1431. _R(0x10ec, 0x8129, RTL_CFG_0),
  1432. _R(0x10ec, 0x8136, RTL_CFG_2),
  1433. _R(0x10ec, 0x8167, RTL_CFG_0),
  1434. _R(0x10ec, 0x8168, RTL_CFG_1),
  1435. _R(0x10ec, 0x8169, RTL_CFG_0),
  1436. _R(0x1186, 0x4300, RTL_CFG_0),
  1437. _R(0x1259, 0xc107, RTL_CFG_0),
  1438. _R(0x16ec, 0x0116, RTL_CFG_0),
  1439. _R(0x1737, 0x1032, RTL_CFG_0),
  1440. _R(0x0001, 0x8168, RTL_CFG_2),
  1441. };
  1442. #undef _R
  1443. static int
  1444. rtl8169_get_nic_variant ( uint16_t vendor, uint16_t device )
  1445. {
  1446. u32 i;
  1447. DBGP ( "rtl8169_get_nic_variant\n" );
  1448. for (i = 0; i < ARRAY_SIZE(nic_variant_table); i++) {
  1449. if ( ( nic_variant_table[i].vendor == vendor ) &&
  1450. ( nic_variant_table[i].device == device ) ) {
  1451. return ( nic_variant_table[i].index );
  1452. }
  1453. }
  1454. DBG ( "No matching NIC variant found!\n" );
  1455. return ( RTL_CFG_0 );
  1456. }
  1457. static void rtl8169_irq_enable ( struct rtl8169_private *tp )
  1458. {
  1459. void *ioaddr = tp->mmio_addr;
  1460. DBGP ( "rtl8169_irq_enable\n" );
  1461. RTL_W16 ( IntrMask, tp->intr_event );
  1462. }
  1463. static void rtl8169_irq_disable ( struct rtl8169_private *tp )
  1464. {
  1465. void *ioaddr = tp->mmio_addr;
  1466. DBGP ( "rtl8169_irq_disable\n" );
  1467. rtl8169_irq_mask_and_ack ( ioaddr );
  1468. }
  1469. /*** gPXE Core API Routines ***/
  1470. /**
  1471. * open - Called when a network interface is made active
  1472. *
  1473. * @v netdev network interface device structure
  1474. * @ret rc Return status code, 0 on success, negative value on failure
  1475. *
  1476. **/
  1477. static int
  1478. rtl8169_open ( struct net_device *netdev )
  1479. {
  1480. struct rtl8169_private *tp = netdev_priv ( netdev );
  1481. void *ioaddr = tp->mmio_addr;
  1482. int rc;
  1483. DBGP ( "rtl8169_open\n" );
  1484. /* allocate transmit descriptors */
  1485. rc = rtl8169_setup_tx_resources ( tp );
  1486. if ( rc ) {
  1487. DBG ( "Error setting up TX resources!\n" );
  1488. goto err_setup_tx;
  1489. }
  1490. /* allocate receive descriptors */
  1491. rc = rtl8169_setup_rx_resources ( tp );
  1492. if ( rc ) {
  1493. DBG ( "Error setting up RX resources!\n" );
  1494. goto err_setup_rx;
  1495. }
  1496. rtl_hw_start ( netdev );
  1497. DBG ( "TxDescStartAddrHigh = %#08lx\n", RTL_R32 ( TxDescStartAddrHigh ) );
  1498. DBG ( "TxDescStartAddrLow = %#08lx\n", RTL_R32 ( TxDescStartAddrLow ) );
  1499. DBG ( "RxDescAddrHigh = %#08lx\n", RTL_R32 ( RxDescAddrHigh ) );
  1500. DBG ( "RxDescAddrLow = %#08lx\n", RTL_R32 ( RxDescAddrLow ) );
  1501. return 0;
  1502. err_setup_rx:
  1503. rtl8169_free_tx_resources ( tp );
  1504. err_setup_tx:
  1505. rtl8169_hw_reset ( ioaddr );
  1506. return rc;
  1507. }
  1508. /**
  1509. * transmit - Transmit a packet
  1510. *
  1511. * @v netdev Network device
  1512. * @v iobuf I/O buffer
  1513. *
  1514. * @ret rc Returns 0 on success, negative on failure
  1515. */
  1516. static int
  1517. rtl8169_transmit ( struct net_device *netdev, struct io_buffer *iobuf )
  1518. {
  1519. struct rtl8169_private *tp = netdev_priv ( netdev );
  1520. void *ioaddr = tp->mmio_addr;
  1521. uint32_t tx_len = iob_len ( iobuf );
  1522. struct TxDesc *tx_curr_desc;
  1523. DBGP ("rtl8169_transmit\n");
  1524. if ( tp->tx_fill_ctr == NUM_TX_DESC ) {
  1525. DBG ("TX overflow\n");
  1526. return -ENOBUFS;
  1527. }
  1528. /**
  1529. * The rtl8169 family automatically pads short packets to a
  1530. * minimum size, but if it did not, like some older cards,
  1531. * we could do:
  1532. * iob_pad ( iobuf, ETH_ZLEN );
  1533. */
  1534. /* Save pointer to this iobuf we have been given to transmit so
  1535. we can pass it to netdev_tx_complete() later */
  1536. tp->tx_iobuf[tp->tx_curr] = iobuf;
  1537. tx_curr_desc = tp->tx_base + tp->tx_curr;
  1538. DBG ( "tp->tx_fill_ctr = %d\n", tp->tx_fill_ctr );
  1539. DBG ( "tp->tx_curr = %d\n", tp->tx_curr );
  1540. DBG ( "tx_curr_desc = %#08lx\n", virt_to_bus ( tx_curr_desc ) );
  1541. DBG ( "iobuf->data = %#08lx\n", virt_to_bus ( iobuf->data ) );
  1542. DBG ( "tx_len = %d\n", tx_len );
  1543. /* Configure current descriptor to transmit supplied packet */
  1544. tx_curr_desc->addr_hi = 0;
  1545. tx_curr_desc->addr_lo = virt_to_bus ( iobuf->data );
  1546. tx_curr_desc->opts2 = 0;
  1547. tx_curr_desc->opts1 = FirstFrag | LastFrag |
  1548. ( tp->tx_curr == ( NUM_TX_DESC - 1 ) ? RingEnd : 0 ) |
  1549. tx_len;
  1550. /* Mark descriptor as owned by NIC */
  1551. tx_curr_desc->opts1 |= DescOwn;
  1552. DBG ( "tx_curr_desc->opts1 = %#08x\n", tx_curr_desc->opts1 );
  1553. DBG ( "tx_curr_desc->opts2 = %#08x\n", tx_curr_desc->opts2 );
  1554. DBG ( "tx_curr_desc->addr_hi = %#08x\n", tx_curr_desc->addr_hi );
  1555. DBG ( "tx_curr_desc->addr_lo = %#08x\n", tx_curr_desc->addr_lo );
  1556. RTL_W8 ( TxPoll, NPQ ); /* set polling bit */
  1557. /* Point to next free descriptor */
  1558. tp->tx_curr = ( tp->tx_curr + 1 ) % NUM_TX_DESC;
  1559. /* Increment number of tx descriptors in use */
  1560. tp->tx_fill_ctr++;
  1561. return 0;
  1562. }
  1563. /**
  1564. * poll - Poll for received packets
  1565. *
  1566. * @v netdev Network device
  1567. */
  1568. static void
  1569. rtl8169_poll ( struct net_device *netdev )
  1570. {
  1571. struct rtl8169_private *tp = netdev_priv ( netdev );
  1572. void *ioaddr = tp->mmio_addr;
  1573. uint16_t intr_status;
  1574. uint16_t intr_mask;
  1575. DBGP ( "rtl8169_poll\n" );
  1576. intr_status = RTL_R16 ( IntrStatus );
  1577. intr_mask = RTL_R16 ( IntrMask );
  1578. DBG2 ( "rtl8169_poll (before): intr_mask = %#04x intr_status = %#04x\n",
  1579. intr_mask, intr_status );
  1580. RTL_W16 ( IntrStatus, 0xffff );
  1581. /* hotplug / major error / no more work / shared irq */
  1582. if ( intr_status == 0xffff )
  1583. return;
  1584. /* Process transmitted packets */
  1585. rtl8169_process_tx_packets ( netdev );
  1586. /* Process received packets */
  1587. rtl8169_process_rx_packets ( netdev );
  1588. }
  1589. /**
  1590. * close - Disable network interface
  1591. *
  1592. * @v netdev network interface device structure
  1593. *
  1594. **/
  1595. static void
  1596. rtl8169_close ( struct net_device *netdev )
  1597. {
  1598. struct rtl8169_private *tp = netdev_priv ( netdev );
  1599. void *ioaddr = tp->mmio_addr;
  1600. DBGP ( "r8169_close\n" );
  1601. rtl8169_hw_reset ( ioaddr );
  1602. rtl8169_free_tx_resources ( tp );
  1603. rtl8169_free_rx_resources ( tp );
  1604. }
  1605. /**
  1606. * irq - enable or Disable interrupts
  1607. *
  1608. * @v netdev network adapter
  1609. * @v action requested interrupt action
  1610. *
  1611. **/
  1612. static void
  1613. rtl8169_irq ( struct net_device *netdev, int action )
  1614. {
  1615. struct rtl8169_private *tp = netdev_priv ( netdev );
  1616. DBGP ( "rtl8169_irq\n" );
  1617. switch ( action ) {
  1618. case 0 :
  1619. rtl8169_irq_disable ( tp );
  1620. break;
  1621. default :
  1622. rtl8169_irq_enable ( tp );
  1623. break;
  1624. }
  1625. }
  1626. static struct net_device_operations rtl8169_operations = {
  1627. .open = rtl8169_open,
  1628. .transmit = rtl8169_transmit,
  1629. .poll = rtl8169_poll,
  1630. .close = rtl8169_close,
  1631. .irq = rtl8169_irq,
  1632. };
  1633. /**
  1634. * probe - Initial configuration of NIC
  1635. *
  1636. * @v pci PCI device
  1637. * @v id PCI IDs
  1638. *
  1639. * @ret rc Return status code
  1640. **/
  1641. static int
  1642. rtl8169_probe ( struct pci_device *pdev, const struct pci_device_id *ent )
  1643. {
  1644. int i, rc;
  1645. struct net_device *netdev;
  1646. struct rtl8169_private *tp;
  1647. void *ioaddr;
  1648. /** FIXME: This lookup is necessary because gPXE does not have a "data"
  1649. element in the structure pci_device_id which can pass an arbitrary
  1650. piece of data to the driver. It might be useful to add it. Then we
  1651. could just use ent->data instead of having to look up cfg_index.
  1652. **/
  1653. int cfg_index = rtl8169_get_nic_variant ( ent->vendor, ent->device );
  1654. const struct rtl_cfg_info *cfg = rtl_cfg_infos + cfg_index;
  1655. DBGP ( "rtl8169_probe\n" );
  1656. DBG ( "ent->vendor = %#04x, ent->device = %#04x\n", ent->vendor, ent->device );
  1657. DBG ( "cfg_index = %d\n", cfg_index );
  1658. DBG ( "cfg->intr_event = %#04x\n", cfg->intr_event );
  1659. rc = -ENOMEM;
  1660. /* Allocate net device ( also allocates memory for netdev->priv
  1661. and makes netdev-priv point to it )
  1662. */
  1663. netdev = alloc_etherdev ( sizeof ( *tp ) );
  1664. if ( ! netdev )
  1665. goto err_alloc_etherdev;
  1666. /* Associate driver-specific network operations with
  1667. generic network device layer
  1668. */
  1669. netdev_init ( netdev, &rtl8169_operations );
  1670. /* Associate this network device with the given PCI device */
  1671. pci_set_drvdata ( pdev, netdev );
  1672. netdev->dev = &pdev->dev;
  1673. /* Initialize driver private storage */
  1674. tp = netdev_priv ( netdev );
  1675. memset ( tp, 0, ( sizeof ( *tp ) ) );
  1676. tp->pci_dev = pdev;
  1677. tp->irqno = pdev->irq;
  1678. tp->netdev = netdev;
  1679. tp->cfg_index = cfg_index;
  1680. tp->intr_event = cfg->intr_event;
  1681. tp->cp_cmd = PCIMulRW;
  1682. tp->hw_start = cfg->hw_start;
  1683. rc = -EIO;
  1684. adjust_pci_device ( pdev );
  1685. /* ioremap MMIO region */
  1686. ioaddr = ioremap ( pdev->membase, R8169_REGS_SIZE );
  1687. if ( ! ioaddr ) {
  1688. DBG ( "cannot remap MMIO\n" );
  1689. rc = -EIO;
  1690. goto err_ioremap;
  1691. }
  1692. tp->mmio_addr = ioaddr;
  1693. tp->pcie_cap = pci_find_capability ( pdev, PCI_CAP_ID_EXP );
  1694. if ( tp->pcie_cap ) {
  1695. DBG ( "PCI Express capability\n" );
  1696. } else {
  1697. DBG ( "No PCI Express capability\n" );
  1698. }
  1699. /* Mask interrupts just in case */
  1700. rtl8169_irq_mask_and_ack ( ioaddr );
  1701. /* Soft reset NIC */
  1702. rtl_soft_reset ( netdev );
  1703. /* Identify chip attached to board */
  1704. rtl8169_get_mac_version ( tp, ioaddr );
  1705. for ( i = 0; (u32) i < ARRAY_SIZE ( rtl_chip_info ); i++ ) {
  1706. if ( tp->mac_version == rtl_chip_info[i].mac_version )
  1707. break;
  1708. }
  1709. if ( i == ARRAY_SIZE(rtl_chip_info ) ) {
  1710. /* Unknown chip: assume array element #0, original RTL-8169 */
  1711. DBG ( "Unknown chip version, assuming %s\n", rtl_chip_info[0].name );
  1712. i = 0;
  1713. }
  1714. tp->chipset = i;
  1715. if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) &&
  1716. (RTL_R8(PHYstatus) & TBI_Enable)) {
  1717. tp->set_speed = rtl8169_set_speed_tbi;
  1718. tp->phy_reset_enable = rtl8169_tbi_reset_enable;
  1719. tp->phy_reset_pending = rtl8169_tbi_reset_pending;
  1720. tp->link_ok = rtl8169_tbi_link_ok;
  1721. tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */
  1722. } else {
  1723. tp->set_speed = rtl8169_set_speed_xmii;
  1724. tp->phy_reset_enable = rtl8169_xmii_reset_enable;
  1725. tp->phy_reset_pending = rtl8169_xmii_reset_pending;
  1726. tp->link_ok = rtl8169_xmii_link_ok;
  1727. }
  1728. /* Get MAC address */
  1729. for ( i = 0; i < MAC_ADDR_LEN; i++ )
  1730. netdev->ll_addr[i] = RTL_R8 ( MAC0 + i );
  1731. DBG ( "%s\n", eth_ntoa ( netdev->ll_addr ) );
  1732. rtl8169_init_phy ( netdev, tp );
  1733. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  1734. goto err_register;
  1735. /* Mark as link up; we don't yet handle link state */
  1736. netdev_link_up ( netdev );
  1737. DBG ( "rtl8169_probe succeeded!\n" );
  1738. /* No errors, return success */
  1739. return 0;
  1740. /* Error return paths */
  1741. err_register:
  1742. err_ioremap:
  1743. netdev_put ( netdev );
  1744. err_alloc_etherdev:
  1745. return rc;
  1746. }
  1747. /**
  1748. * remove - Device Removal Routine
  1749. *
  1750. * @v pdev PCI device information struct
  1751. *
  1752. **/
  1753. static void
  1754. rtl8169_remove ( struct pci_device *pdev )
  1755. {
  1756. struct net_device *netdev = pci_get_drvdata ( pdev );
  1757. struct rtl8169_private *tp = netdev_priv ( netdev );
  1758. void *ioaddr = tp->mmio_addr;
  1759. DBGP ( "rtl8169_remove\n" );
  1760. rtl8169_hw_reset ( ioaddr );
  1761. unregister_netdev ( netdev );
  1762. netdev_nullify ( netdev );
  1763. netdev_put ( netdev );
  1764. }
  1765. static struct pci_device_id rtl8169_nics[] = {
  1766. PCI_ROM(0x10ec, 0x8129, "rtl8169-0x8129", "rtl8169-0x8129", 0),
  1767. PCI_ROM(0x10ec, 0x8136, "rtl8169-0x8136", "rtl8169-0x8136", 0),
  1768. PCI_ROM(0x10ec, 0x8167, "rtl8169-0x8167", "rtl8169-0x8167", 0),
  1769. PCI_ROM(0x10ec, 0x8168, "rtl8169-0x8168", "rtl8169-0x8168", 0),
  1770. PCI_ROM(0x10ec, 0x8169, "rtl8169-0x8169", "rtl8169-0x8169", 0),
  1771. PCI_ROM(0x1186, 0x4300, "rtl8169-0x4300", "rtl8169-0x4300", 0),
  1772. PCI_ROM(0x1259, 0xc107, "rtl8169-0xc107", "rtl8169-0xc107", 0),
  1773. PCI_ROM(0x16ec, 0x0116, "rtl8169-0x0116", "rtl8169-0x0116", 0),
  1774. PCI_ROM(0x1737, 0x1032, "rtl8169-0x1032", "rtl8169-0x1032", 0),
  1775. PCI_ROM(0x0001, 0x8168, "rtl8169-0x8168", "rtl8169-0x8168", 0),
  1776. };
  1777. struct pci_driver rtl8169_driver __pci_driver = {
  1778. .ids = rtl8169_nics,
  1779. .id_count = ( sizeof ( rtl8169_nics ) / sizeof ( rtl8169_nics[0] ) ),
  1780. .probe = rtl8169_probe,
  1781. .remove = rtl8169_remove,
  1782. };
  1783. /*
  1784. * Local variables:
  1785. * c-basic-offset: 8
  1786. * c-indent-level: 8
  1787. * tab-width: 8
  1788. * End:
  1789. */