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.

r8169.c 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /**************************************************************************
  2. * r8169.c: Etherboot device driver for the RealTek RTL-8169 Gigabit
  3. * Written 2003 by Timothy Legge <tlegge@rogers.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU 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. * Portions of this code based on:
  20. * r8169.c: A RealTek RTL-8169 Gigabit Ethernet driver
  21. * for Linux kernel 2.4.x.
  22. *
  23. * Written 2002 ShuChen <shuchen@realtek.com.tw>
  24. * See Linux Driver for full information
  25. *
  26. * Linux Driver Versions:
  27. * 1.27a, 10.02.2002
  28. * RTL8169_VERSION "2.2" <2004/08/09>
  29. *
  30. * Thanks to:
  31. * Jean Chen of RealTek Semiconductor Corp. for
  32. * providing the evaluation NIC used to develop
  33. * this driver. RealTek's support for Etherboot
  34. * is appreciated.
  35. *
  36. * REVISION HISTORY:
  37. * ================
  38. *
  39. * v1.0 11-26-2003 timlegge Initial port of Linux driver
  40. * v1.5 01-17-2004 timlegge Initial driver output cleanup
  41. * v1.6 03-27-2004 timlegge Additional Cleanup
  42. * v1.7 11-22-2005 timlegge Update to RealTek Driver Version 2.2
  43. *
  44. * Indent Options: indent -kr -i8
  45. ***************************************************************************/
  46. #include "etherboot.h"
  47. #include "nic.h"
  48. #include <gpxe/pci.h>
  49. #include <gpxe/ethernet.h>
  50. #include <gpxe/malloc.h>
  51. #include "timer.h"
  52. #define drv_version "v1.6"
  53. #define drv_date "03-27-2004"
  54. #define HZ 1000
  55. static u32 ioaddr;
  56. /* Condensed operations for readability. */
  57. #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
  58. #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
  59. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  60. #undef RTL8169_DEBUG
  61. #undef RTL8169_JUMBO_FRAME_SUPPORT
  62. #undef RTL8169_HW_FLOW_CONTROL_SUPPORT
  63. #undef RTL8169_IOCTL_SUPPORT
  64. #undef RTL8169_DYNAMIC_CONTROL
  65. #define RTL8169_USE_IO
  66. /* media options
  67. _10_Half = 0x01,
  68. _10_Full = 0x02,
  69. _100_Half = 0x04,
  70. _100_Full = 0x08,
  71. _1000_Full = 0x10,
  72. */
  73. static int media = -1;
  74. #if 0
  75. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  76. static int max_interrupt_work = 20;
  77. #endif
  78. #if 0
  79. /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
  80. The RTL chips use a 64 element hash table based on the Ethernet CRC. */
  81. static int multicast_filter_limit = 32;
  82. #endif
  83. /* MAC address length*/
  84. #define MAC_ADDR_LEN 6
  85. /* max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4).*/
  86. #define MAX_ETH_FRAME_SIZE 1536
  87. #define TX_FIFO_THRESH 256 /* In bytes */
  88. #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */
  89. #define RX_DMA_BURST 7 /* Maximum PCI burst, '6' is 1024 */
  90. #define TX_DMA_BURST 7 /* Maximum PCI burst, '6' is 1024 */
  91. #define ETTh 0x3F /* 0x3F means NO threshold */
  92. #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */
  93. #define RxPacketMaxSize 0x0800 /* Maximum size supported is 16K-1 */
  94. #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */
  95. #define NUM_TX_DESC 1 /* Number of Tx descriptor registers */
  96. #define NUM_RX_DESC 4 /* Number of Rx descriptor registers */
  97. #define RX_BUF_SIZE 1536 /* Rx Buffer size */
  98. #define RTL_MIN_IO_SIZE 0x80
  99. #define TX_TIMEOUT (6*HZ)
  100. #define RTL8169_TIMER_EXPIRE_TIME 100 //100
  101. #define ETH_HDR_LEN 14
  102. #define DEFAULT_MTU 1500
  103. #define DEFAULT_RX_BUF_LEN 1536
  104. #ifdef RTL8169_JUMBO_FRAME_SUPPORT
  105. #define MAX_JUMBO_FRAME_MTU ( 10000 )
  106. #define MAX_RX_SKBDATA_SIZE ( MAX_JUMBO_FRAME_MTU + ETH_HDR_LEN )
  107. #else
  108. #define MAX_RX_SKBDATA_SIZE 1600
  109. #endif //end #ifdef RTL8169_JUMBO_FRAME_SUPPORT
  110. #ifdef RTL8169_USE_IO
  111. #define RTL_W8(reg, val8) outb ((val8), ioaddr + (reg))
  112. #define RTL_W16(reg, val16) outw ((val16), ioaddr + (reg))
  113. #define RTL_W32(reg, val32) outl ((val32), ioaddr + (reg))
  114. #define RTL_R8(reg) inb (ioaddr + (reg))
  115. #define RTL_R16(reg) inw (ioaddr + (reg))
  116. #define RTL_R32(reg) ((unsigned long) inl (ioaddr + (reg)))
  117. #else
  118. /* write/read MMIO register */
  119. #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))
  120. #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))
  121. #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg))
  122. #define RTL_R8(reg) readb (ioaddr + (reg))
  123. #define RTL_R16(reg) readw (ioaddr + (reg))
  124. #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg)))
  125. #endif
  126. #define MCFG_METHOD_1 0x01
  127. #define MCFG_METHOD_2 0x02
  128. #define MCFG_METHOD_3 0x03
  129. #define MCFG_METHOD_4 0x04
  130. #define PCFG_METHOD_1 0x01 //PHY Reg 0x03 bit0-3 == 0x0000
  131. #define PCFG_METHOD_2 0x02 //PHY Reg 0x03 bit0-3 == 0x0001
  132. #define PCFG_METHOD_3 0x03 //PHY Reg 0x03 bit0-3 == 0x0002
  133. static struct {
  134. const char *name;
  135. u8 mcfg; /* depend on RTL8169 docs */
  136. u32 RxConfigMask; /* should clear the bits supported by this chip */
  137. } rtl_chip_info[] = {
  138. {
  139. "RTL-8169", MCFG_METHOD_1, 0xff7e1880,}, {
  140. "RTL8169s/8110s", MCFG_METHOD_2, 0xff7e1880}, {
  141. "RTL8169s/8110s", MCFG_METHOD_3, 0xff7e1880},};
  142. enum RTL8169_registers {
  143. MAC0 = 0x0, /* Ethernet hardware address. */
  144. MAR0 = 0x8, /* Multicast filter. */
  145. TxDescStartAddr = 0x20,
  146. TxHDescStartAddr = 0x28,
  147. FLASH = 0x30,
  148. ERSR = 0x36,
  149. ChipCmd = 0x37,
  150. TxPoll = 0x38,
  151. IntrMask = 0x3C,
  152. IntrStatus = 0x3E,
  153. TxConfig = 0x40,
  154. RxConfig = 0x44,
  155. RxMissed = 0x4C,
  156. Cfg9346 = 0x50,
  157. Config0 = 0x51,
  158. Config1 = 0x52,
  159. Config2 = 0x53,
  160. Config3 = 0x54,
  161. Config4 = 0x55,
  162. Config5 = 0x56,
  163. MultiIntr = 0x5C,
  164. PHYAR = 0x60,
  165. TBICSR = 0x64,
  166. TBI_ANAR = 0x68,
  167. TBI_LPAR = 0x6A,
  168. PHYstatus = 0x6C,
  169. RxMaxSize = 0xDA,
  170. CPlusCmd = 0xE0,
  171. RxDescStartAddr = 0xE4,
  172. ETThReg = 0xEC,
  173. FuncEvent = 0xF0,
  174. FuncEventMask = 0xF4,
  175. FuncPresetState = 0xF8,
  176. FuncForceEvent = 0xFC,
  177. };
  178. enum RTL8169_register_content {
  179. /*InterruptStatusBits */
  180. SYSErr = 0x8000,
  181. PCSTimeout = 0x4000,
  182. SWInt = 0x0100,
  183. TxDescUnavail = 0x80,
  184. RxFIFOOver = 0x40,
  185. LinkChg = 0x20,
  186. RxOverflow = 0x10,
  187. TxErr = 0x08,
  188. TxOK = 0x04,
  189. RxErr = 0x02,
  190. RxOK = 0x01,
  191. /*RxStatusDesc */
  192. RxRES = 0x00200000,
  193. RxCRC = 0x00080000,
  194. RxRUNT = 0x00100000,
  195. RxRWT = 0x00400000,
  196. /*ChipCmdBits */
  197. CmdReset = 0x10,
  198. CmdRxEnb = 0x08,
  199. CmdTxEnb = 0x04,
  200. RxBufEmpty = 0x01,
  201. /*Cfg9346Bits */
  202. Cfg9346_Lock = 0x00,
  203. Cfg9346_Unlock = 0xC0,
  204. /*rx_mode_bits */
  205. AcceptErr = 0x20,
  206. AcceptRunt = 0x10,
  207. AcceptBroadcast = 0x08,
  208. AcceptMulticast = 0x04,
  209. AcceptMyPhys = 0x02,
  210. AcceptAllPhys = 0x01,
  211. /*RxConfigBits */
  212. RxCfgFIFOShift = 13,
  213. RxCfgDMAShift = 8,
  214. /*TxConfigBits */
  215. TxInterFrameGapShift = 24,
  216. TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
  217. /*rtl8169_PHYstatus */
  218. TBI_Enable = 0x80,
  219. TxFlowCtrl = 0x40,
  220. RxFlowCtrl = 0x20,
  221. _1000bpsF = 0x10,
  222. _100bps = 0x08,
  223. _10bps = 0x04,
  224. LinkStatus = 0x02,
  225. FullDup = 0x01,
  226. /*GIGABIT_PHY_registers */
  227. PHY_CTRL_REG = 0,
  228. PHY_STAT_REG = 1,
  229. PHY_AUTO_NEGO_REG = 4,
  230. PHY_1000_CTRL_REG = 9,
  231. /*GIGABIT_PHY_REG_BIT */
  232. PHY_Restart_Auto_Nego = 0x0200,
  233. PHY_Enable_Auto_Nego = 0x1000,
  234. /* PHY_STAT_REG = 1; */
  235. PHY_Auto_Neco_Comp = 0x0020,
  236. /* PHY_AUTO_NEGO_REG = 4; */
  237. PHY_Cap_10_Half = 0x0020,
  238. PHY_Cap_10_Full = 0x0040,
  239. PHY_Cap_100_Half = 0x0080,
  240. PHY_Cap_100_Full = 0x0100,
  241. /* PHY_1000_CTRL_REG = 9; */
  242. PHY_Cap_1000_Full = 0x0200,
  243. PHY_Cap_1000_Half = 0x0100,
  244. PHY_Cap_PAUSE = 0x0400,
  245. PHY_Cap_ASYM_PAUSE = 0x0800,
  246. PHY_Cap_Null = 0x0,
  247. /*_MediaType*/
  248. _10_Half = 0x01,
  249. _10_Full = 0x02,
  250. _100_Half = 0x04,
  251. _100_Full = 0x08,
  252. _1000_Full = 0x10,
  253. /*_TBICSRBit*/
  254. TBILinkOK = 0x02000000,
  255. };
  256. enum _DescStatusBit {
  257. OWNbit = 0x80000000,
  258. EORbit = 0x40000000,
  259. FSbit = 0x20000000,
  260. LSbit = 0x10000000,
  261. };
  262. struct TxDesc {
  263. u32 status;
  264. u32 vlan_tag;
  265. u32 buf_addr;
  266. u32 buf_Haddr;
  267. };
  268. struct RxDesc {
  269. u32 status;
  270. u32 vlan_tag;
  271. u32 buf_addr;
  272. u32 buf_Haddr;
  273. };
  274. /* The descriptors for this card are required to be aligned on 256
  275. * byte boundaries. As the align attribute does not do more than 16
  276. * bytes of alignment it requires some extra steps. Add 256 to the
  277. * size of the array and the init_ring adjusts the alignment.
  278. *
  279. * UPDATE: This is no longer true; we can request arbitrary alignment.
  280. */
  281. /* Define the TX and RX Descriptors and Buffers */
  282. #define __align_256 __attribute__ (( aligned ( 256 ) ))
  283. struct {
  284. struct TxDesc tx_ring[NUM_TX_DESC] __align_256;
  285. unsigned char txb[NUM_TX_DESC * RX_BUF_SIZE];
  286. struct RxDesc rx_ring[NUM_RX_DESC] __align_256;
  287. unsigned char rxb[NUM_RX_DESC * RX_BUF_SIZE];
  288. } *r8169_bufs;
  289. #define tx_ring r8169_bufs->tx_ring
  290. #define rx_ring r8169_bufs->rx_ring
  291. #define txb r8169_bufs->txb
  292. #define rxb r8169_bufs->rxb
  293. static struct rtl8169_private {
  294. void *mmio_addr; /* memory map physical address */
  295. int chipset;
  296. int pcfg;
  297. int mcfg;
  298. unsigned long cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
  299. unsigned long cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
  300. struct TxDesc *TxDescArray; /* Index of 256-alignment Tx Descriptor buffer */
  301. struct RxDesc *RxDescArray; /* Index of 256-alignment Rx Descriptor buffer */
  302. unsigned char *RxBufferRing[NUM_RX_DESC]; /* Index of Rx Buffer array */
  303. unsigned char *Tx_skbuff[NUM_TX_DESC];
  304. } tpx;
  305. static struct rtl8169_private *tpc;
  306. static const u16 rtl8169_intr_mask =
  307. LinkChg | RxOverflow | RxFIFOOver | TxErr | TxOK | RxErr | RxOK;
  308. static const unsigned int rtl8169_rx_config =
  309. (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift) |
  310. 0x0000000E;
  311. static void rtl8169_hw_PHY_config(struct nic *nic __unused);
  312. //static void rtl8169_hw_PHY_reset(struct net_device *dev);
  313. #define RTL8169_WRITE_GMII_REG_BIT( ioaddr, reg, bitnum, bitval )\
  314. { \
  315. int val; \
  316. if( bitval == 1 ){ val = ( RTL8169_READ_GMII_REG( ioaddr, reg ) | (bitval<<bitnum) ) & 0xffff ; } \
  317. else{ val = ( RTL8169_READ_GMII_REG( ioaddr, reg ) & (~(0x0001<<bitnum)) ) & 0xffff ; } \
  318. RTL8169_WRITE_GMII_REG( ioaddr, reg, val ); \
  319. }
  320. //=================================================================
  321. // PHYAR
  322. // bit Symbol
  323. // 31 Flag
  324. // 30-21 reserved
  325. // 20-16 5-bit GMII/MII register address
  326. // 15-0 16-bit GMII/MII register data
  327. //=================================================================
  328. static void RTL8169_WRITE_GMII_REG(unsigned long ioaddr, int RegAddr, int value)
  329. {
  330. int i;
  331. RTL_W32(PHYAR, 0x80000000 | (RegAddr & 0xFF) << 16 | value);
  332. udelay(1000);
  333. for (i = 2000; i > 0; i--) {
  334. // Check if the RTL8169 has completed writing to the specified MII register
  335. if (!(RTL_R32(PHYAR) & 0x80000000)) {
  336. break;
  337. } else {
  338. udelay(100);
  339. } // end of if( ! (RTL_R32(PHYAR)&0x80000000) )
  340. } // end of for() loop
  341. }
  342. //=================================================================
  343. static int RTL8169_READ_GMII_REG(unsigned long ioaddr, int RegAddr)
  344. {
  345. int i, value = -1;
  346. RTL_W32(PHYAR, 0x0 | (RegAddr & 0xFF) << 16);
  347. udelay(1000);
  348. for (i = 2000; i > 0; i--) {
  349. // Check if the RTL8169 has completed retrieving data from the specified MII register
  350. if (RTL_R32(PHYAR) & 0x80000000) {
  351. value = (int) (RTL_R32(PHYAR) & 0xFFFF);
  352. break;
  353. } else {
  354. udelay(100);
  355. } // end of if( RTL_R32(PHYAR) & 0x80000000 )
  356. } // end of for() loop
  357. return value;
  358. }
  359. #if 0
  360. static void mdio_write(int RegAddr, int value)
  361. {
  362. int i;
  363. RTL_W32(PHYAR, 0x80000000 | (RegAddr & 0xFF) << 16 | value);
  364. udelay(1000);
  365. for (i = 2000; i > 0; i--) {
  366. /* Check if the RTL8169 has completed writing to the specified MII register */
  367. if (!(RTL_R32(PHYAR) & 0x80000000)) {
  368. break;
  369. } else {
  370. udelay(100);
  371. }
  372. }
  373. }
  374. static int mdio_read(int RegAddr)
  375. {
  376. int i, value = -1;
  377. RTL_W32(PHYAR, 0x0 | (RegAddr & 0xFF) << 16);
  378. udelay(1000);
  379. for (i = 2000; i > 0; i--) {
  380. /* Check if the RTL8169 has completed retrieving data from the specified MII register */
  381. if (RTL_R32(PHYAR) & 0x80000000) {
  382. value = (int) (RTL_R32(PHYAR) & 0xFFFF);
  383. break;
  384. } else {
  385. udelay(100);
  386. }
  387. }
  388. return value;
  389. }
  390. #endif
  391. #define IORESOURCE_MEM 0x00000200
  392. static int rtl8169_init_board(struct pci_device *pdev)
  393. {
  394. int i;
  395. // unsigned long mmio_end, mmio_flags
  396. unsigned long mmio_start, mmio_len;
  397. adjust_pci_device(pdev);
  398. mmio_start = pci_bar_start(pdev, PCI_BASE_ADDRESS_1);
  399. // mmio_end = pci_resource_end (pdev, 1);
  400. // mmio_flags = pci_resource_flags (pdev, PCI_BASE_ADDRESS_1);
  401. mmio_len = pci_bar_size(pdev, PCI_BASE_ADDRESS_1);
  402. // make sure PCI base addr 1 is MMIO
  403. // if (!(mmio_flags & IORESOURCE_MEM)) {
  404. // printf ("region #1 not an MMIO resource, aborting\n");
  405. // return 0;
  406. // }
  407. // check for weird/broken PCI region reporting
  408. if (mmio_len < RTL_MIN_IO_SIZE) {
  409. printf("Invalid PCI region size(s), aborting\n");
  410. return 0;
  411. }
  412. #ifdef RTL8169_USE_IO
  413. ioaddr = pci_bar_start(pdev, PCI_BASE_ADDRESS_0);
  414. #else
  415. // ioremap MMIO region
  416. ioaddr = (unsigned long) ioremap(mmio_start, mmio_len);
  417. if (ioaddr == 0) {
  418. printk("cannot remap MMIO, aborting\n");
  419. return 0;
  420. }
  421. #endif
  422. tpc->mmio_addr = &ioaddr;
  423. /* Soft reset the chip. */
  424. RTL_W8(ChipCmd, CmdReset);
  425. /* Check that the chip has finished the reset. */
  426. for (i = 1000; i > 0; i--)
  427. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  428. break;
  429. else
  430. udelay(10);
  431. // identify config method
  432. {
  433. unsigned long val32 = (RTL_R32(TxConfig) & 0x7c800000);
  434. if (val32 == (0x1 << 28)) {
  435. tpc->mcfg = MCFG_METHOD_4;
  436. } else if (val32 == (0x1 << 26)) {
  437. tpc->mcfg = MCFG_METHOD_3;
  438. } else if (val32 == (0x1 << 23)) {
  439. tpc->mcfg = MCFG_METHOD_2;
  440. } else if (val32 == 0x00000000) {
  441. tpc->mcfg = MCFG_METHOD_1;
  442. } else {
  443. tpc->mcfg = MCFG_METHOD_1;
  444. }
  445. }
  446. {
  447. unsigned char val8 =
  448. (unsigned char) (RTL8169_READ_GMII_REG(ioaddr, 3) &
  449. 0x000f);
  450. if (val8 == 0x00) {
  451. tpc->pcfg = PCFG_METHOD_1;
  452. } else if (val8 == 0x01) {
  453. tpc->pcfg = PCFG_METHOD_2;
  454. } else if (val8 == 0x02) {
  455. tpc->pcfg = PCFG_METHOD_3;
  456. } else {
  457. tpc->pcfg = PCFG_METHOD_3;
  458. }
  459. }
  460. /* identify chip attached to board */
  461. for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--)
  462. if (tpc->mcfg == rtl_chip_info[i].mcfg) {
  463. tpc->chipset = i;
  464. goto match;
  465. }
  466. /* if unknown chip, assume array element #0, original RTL-8169 in this case */
  467. DBG ( "PCI device: unknown chip version, assuming RTL-8169\n" );
  468. DBG ( "PCI device: TxConfig = %#lX\n", ( unsigned long ) RTL_R32 ( TxConfig ) );
  469. tpc->chipset = 0;
  470. return 1;
  471. match:
  472. return 0;
  473. }
  474. /**************************************************************************
  475. IRQ - Wait for a frame
  476. ***************************************************************************/
  477. static void r8169_irq(struct nic *nic __unused, irq_action_t action)
  478. {
  479. int intr_status = 0;
  480. int interested = RxOverflow | RxFIFOOver | RxErr | RxOK;
  481. switch (action) {
  482. case DISABLE:
  483. case ENABLE:
  484. intr_status = RTL_R16(IntrStatus);
  485. /* h/w no longer present (hotplug?) or major error,
  486. bail */
  487. if (intr_status == 0xFFFF)
  488. break;
  489. intr_status = intr_status & ~interested;
  490. if (action == ENABLE)
  491. intr_status = intr_status | interested;
  492. RTL_W16(IntrMask, intr_status);
  493. break;
  494. case FORCE:
  495. RTL_W8(TxPoll, (RTL_R8(TxPoll) | 0x01));
  496. break;
  497. }
  498. }
  499. /**************************************************************************
  500. POLL - Wait for a frame
  501. ***************************************************************************/
  502. static int r8169_poll(struct nic *nic, int retreive)
  503. {
  504. /* return true if there's an ethernet packet ready to read */
  505. /* nic->packet should contain data on return */
  506. /* nic->packetlen should contain length of data */
  507. int cur_rx;
  508. unsigned int intr_status = 0;
  509. cur_rx = tpc->cur_rx;
  510. if ((tpc->RxDescArray[cur_rx].status & OWNbit) == 0) {
  511. /* There is a packet ready */
  512. if (!retreive)
  513. return 1;
  514. intr_status = RTL_R16(IntrStatus);
  515. /* h/w no longer present (hotplug?) or major error,
  516. bail */
  517. if (intr_status == 0xFFFF)
  518. return 0;
  519. RTL_W16(IntrStatus, intr_status &
  520. ~(RxFIFOOver | RxOverflow | RxOK));
  521. if (!(tpc->RxDescArray[cur_rx].status & RxRES)) {
  522. nic->packetlen = (int) (tpc->RxDescArray[cur_rx].
  523. status & 0x00001FFF) - 4;
  524. memcpy(nic->packet, tpc->RxBufferRing[cur_rx],
  525. nic->packetlen);
  526. if (cur_rx == NUM_RX_DESC - 1)
  527. tpc->RxDescArray[cur_rx].status =
  528. (OWNbit | EORbit) + RX_BUF_SIZE;
  529. else
  530. tpc->RxDescArray[cur_rx].status =
  531. OWNbit + RX_BUF_SIZE;
  532. tpc->RxDescArray[cur_rx].buf_addr =
  533. virt_to_bus(tpc->RxBufferRing[cur_rx]);
  534. } else
  535. printf("Error Rx");
  536. /* FIXME: shouldn't I reset the status on an error */
  537. cur_rx = (cur_rx + 1) % NUM_RX_DESC;
  538. tpc->cur_rx = cur_rx;
  539. RTL_W16(IntrStatus, intr_status &
  540. (RxFIFOOver | RxOverflow | RxOK));
  541. return 1;
  542. }
  543. tpc->cur_rx = cur_rx;
  544. /* FIXME: There is no reason to do this as cur_rx did not change */
  545. return (0); /* initially as this is called to flush the input */
  546. }
  547. /**************************************************************************
  548. TRANSMIT - Transmit a frame
  549. ***************************************************************************/
  550. static void r8169_transmit(struct nic *nic, const char *d, /* Destination */
  551. unsigned int t, /* Type */
  552. unsigned int s, /* size */
  553. const char *p)
  554. { /* Packet */
  555. /* send the packet to destination */
  556. u16 nstype;
  557. u32 to;
  558. u8 *ptxb;
  559. int entry = tpc->cur_tx % NUM_TX_DESC;
  560. /* point to the current txb incase multiple tx_rings are used */
  561. ptxb = tpc->Tx_skbuff[entry * MAX_ETH_FRAME_SIZE];
  562. memcpy(ptxb, d, ETH_ALEN);
  563. memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN);
  564. nstype = htons((u16) t);
  565. memcpy(ptxb + 2 * ETH_ALEN, (u8 *) & nstype, 2);
  566. memcpy(ptxb + ETH_HLEN, p, s);
  567. s += ETH_HLEN;
  568. s &= 0x0FFF;
  569. while (s < ETH_ZLEN)
  570. ptxb[s++] = '\0';
  571. tpc->TxDescArray[entry].buf_addr = virt_to_bus(ptxb);
  572. if (entry != (NUM_TX_DESC - 1))
  573. tpc->TxDescArray[entry].status =
  574. (OWNbit | FSbit | LSbit) | ((s > ETH_ZLEN) ? s :
  575. ETH_ZLEN);
  576. else
  577. tpc->TxDescArray[entry].status =
  578. (OWNbit | EORbit | FSbit | LSbit) | ((s > ETH_ZLEN) ? s
  579. : ETH_ZLEN);
  580. RTL_W8(TxPoll, 0x40); /* set polling bit */
  581. tpc->cur_tx++;
  582. to = currticks() + TX_TIMEOUT;
  583. while ((tpc->TxDescArray[entry].status & OWNbit) && (currticks() < to)); /* wait */
  584. if (currticks() >= to) {
  585. printf("TX Time Out");
  586. }
  587. }
  588. static void rtl8169_set_rx_mode(struct nic *nic __unused)
  589. {
  590. u32 mc_filter[2]; /* Multicast hash filter */
  591. int rx_mode;
  592. u32 tmp = 0;
  593. /* IFF_ALLMULTI */
  594. /* Too many to filter perfectly -- accept all multicasts. */
  595. rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
  596. mc_filter[1] = mc_filter[0] = 0xffffffff;
  597. tmp =
  598. rtl8169_rx_config | rx_mode | (RTL_R32(RxConfig) &
  599. rtl_chip_info[tpc->chipset].
  600. RxConfigMask);
  601. RTL_W32(RxConfig, tmp);
  602. RTL_W32(MAR0 + 0, mc_filter[0]);
  603. RTL_W32(MAR0 + 4, mc_filter[1]);
  604. }
  605. static void rtl8169_hw_start(struct nic *nic)
  606. {
  607. u32 i;
  608. /* Soft reset the chip. */
  609. RTL_W8(ChipCmd, CmdReset);
  610. /* Check that the chip has finished the reset. */
  611. for (i = 1000; i > 0; i--) {
  612. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  613. break;
  614. else
  615. udelay(10);
  616. }
  617. RTL_W8(Cfg9346, Cfg9346_Unlock);
  618. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  619. RTL_W8(ETThReg, ETTh);
  620. /* For gigabit rtl8169 */
  621. RTL_W16(RxMaxSize, RxPacketMaxSize);
  622. /* Set Rx Config register */
  623. i = rtl8169_rx_config | (RTL_R32(RxConfig) &
  624. rtl_chip_info[tpc->chipset].RxConfigMask);
  625. RTL_W32(RxConfig, i);
  626. /* Set DMA burst size and Interframe Gap Time */
  627. RTL_W32(TxConfig,
  628. (TX_DMA_BURST << TxDMAShift) | (InterFrameGap <<
  629. TxInterFrameGapShift));
  630. RTL_W16(CPlusCmd, RTL_R16(CPlusCmd));
  631. if (tpc->mcfg == MCFG_METHOD_2 || tpc->mcfg == MCFG_METHOD_3) {
  632. RTL_W16(CPlusCmd,
  633. (RTL_R16(CPlusCmd) | (1 << 14) | (1 << 3)));
  634. DBG
  635. ("Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n");
  636. } else {
  637. RTL_W16(CPlusCmd, (RTL_R16(CPlusCmd) | (1 << 3)));
  638. DBG("Set MAC Reg C+CR Offset 0xE0: bit-3.\n");
  639. }
  640. {
  641. //RTL_W16(0xE2, 0x1517);
  642. //RTL_W16(0xE2, 0x152a);
  643. //RTL_W16(0xE2, 0x282a);
  644. RTL_W16(0xE2, 0x0000);
  645. }
  646. tpc->cur_rx = 0;
  647. RTL_W32(TxDescStartAddr, virt_to_le32desc(tpc->TxDescArray));
  648. RTL_W32(RxDescStartAddr, virt_to_le32desc(tpc->RxDescArray));
  649. RTL_W8(Cfg9346, Cfg9346_Lock);
  650. udelay(10);
  651. RTL_W32(RxMissed, 0);
  652. rtl8169_set_rx_mode(nic);
  653. /* no early-rx interrupts */
  654. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  655. RTL_W16(IntrMask, rtl8169_intr_mask);
  656. }
  657. static void rtl8169_init_ring(struct nic *nic __unused)
  658. {
  659. int i;
  660. tpc->cur_rx = 0;
  661. tpc->cur_tx = 0;
  662. memset(tpc->TxDescArray, 0x0, NUM_TX_DESC * sizeof(struct TxDesc));
  663. memset(tpc->RxDescArray, 0x0, NUM_RX_DESC * sizeof(struct RxDesc));
  664. for (i = 0; i < NUM_TX_DESC; i++) {
  665. tpc->Tx_skbuff[i] = &txb[i];
  666. }
  667. for (i = 0; i < NUM_RX_DESC; i++) {
  668. if (i == (NUM_RX_DESC - 1))
  669. tpc->RxDescArray[i].status =
  670. (OWNbit | EORbit) | RX_BUF_SIZE;
  671. else
  672. tpc->RxDescArray[i].status = OWNbit | RX_BUF_SIZE;
  673. tpc->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
  674. tpc->RxDescArray[i].buf_addr =
  675. virt_to_bus(tpc->RxBufferRing[i]);
  676. }
  677. }
  678. /**************************************************************************
  679. RESET - Finish setting up the ethernet interface
  680. ***************************************************************************/
  681. static void r8169_reset(struct nic *nic)
  682. {
  683. int i;
  684. tpc->TxDescArray = tx_ring;
  685. tpc->RxDescArray = rx_ring;
  686. rtl8169_init_ring(nic);
  687. rtl8169_hw_start(nic);
  688. /* Construct a perfect filter frame with the mac address as first match
  689. * and broadcast for all others */
  690. for (i = 0; i < 192; i++)
  691. txb[i] = 0xFF;
  692. txb[0] = nic->node_addr[0];
  693. txb[1] = nic->node_addr[1];
  694. txb[2] = nic->node_addr[2];
  695. txb[3] = nic->node_addr[3];
  696. txb[4] = nic->node_addr[4];
  697. txb[5] = nic->node_addr[5];
  698. }
  699. /**************************************************************************
  700. DISABLE - Turn off ethernet interface
  701. ***************************************************************************/
  702. static void r8169_disable ( struct nic *nic __unused ) {
  703. int i;
  704. /* Stop the chip's Tx and Rx DMA processes. */
  705. RTL_W8(ChipCmd, 0x00);
  706. /* Disable interrupts by clearing the interrupt mask. */
  707. RTL_W16(IntrMask, 0x0000);
  708. RTL_W32(RxMissed, 0);
  709. tpc->TxDescArray = NULL;
  710. tpc->RxDescArray = NULL;
  711. for (i = 0; i < NUM_RX_DESC; i++) {
  712. tpc->RxBufferRing[i] = NULL;
  713. }
  714. }
  715. static struct nic_operations r8169_operations = {
  716. .connect = dummy_connect,
  717. .poll = r8169_poll,
  718. .transmit = r8169_transmit,
  719. .irq = r8169_irq,
  720. };
  721. static struct pci_device_id r8169_nics[] = {
  722. PCI_ROM(0x10ec, 0x8169, "r8169", "RealTek RTL8169 Gigabit Ethernet"),
  723. PCI_ROM(0x16ec, 0x0116, "usr-r8169", "US Robotics RTL8169 Gigabit Ethernet"),
  724. PCI_ROM(0x1186, 0x4300, "dlink-r8169", "D-Link RTL8169 Gigabit Ethernet"),
  725. PCI_ROM(0x1737, 0x1032, "linksys-r8169", "Linksys RTL8169 Gigabit Ethernet"),
  726. };
  727. PCI_DRIVER ( r8169_driver, r8169_nics, PCI_NO_CLASS );
  728. /**************************************************************************
  729. PROBE - Look for an adapter, this routine's visible to the outside
  730. ***************************************************************************/
  731. #define board_found 1
  732. #define valid_link 0
  733. static int r8169_probe ( struct nic *nic, struct pci_device *pci ) {
  734. static int board_idx = -1;
  735. static int printed_version = 0;
  736. int i, rc;
  737. int option = -1, Cap10_100 = 0, Cap1000 = 0;
  738. printf ( "r8169.c: Found %s, Vendor=%hX Device=%hX\n",
  739. pci->driver_name, pci->vendor, pci->device );
  740. board_idx++;
  741. printed_version = 1;
  742. /* Quick and very dirty hack to get r8169 driver working
  743. * again, pre-rewrite
  744. */
  745. if ( ! r8169_bufs )
  746. r8169_bufs = malloc_dma ( sizeof ( *r8169_bufs ), 256 );
  747. if ( ! r8169_bufs )
  748. return 0;
  749. memset ( r8169_bufs, 0, sizeof ( *r8169_bufs ) );
  750. /* point to private storage */
  751. tpc = &tpx;
  752. rc = rtl8169_init_board(pci); /* Return code is meaningless */
  753. /* Get MAC address. FIXME: read EEPROM */
  754. for (i = 0; i < MAC_ADDR_LEN; i++)
  755. nic->node_addr[i] = RTL_R8(MAC0 + i);
  756. DBG ( "%s: Identified chip type is '%s'.\n", pci->driver_name,
  757. rtl_chip_info[tpc->chipset].name );
  758. /* Print out some hardware info */
  759. DBG ( "%s: %s at IOAddr %#hX, ", pci->driver_name, eth_ntoa ( nic->node_addr ),
  760. (unsigned int) ioaddr );
  761. /* Config PHY */
  762. rtl8169_hw_PHY_config(nic);
  763. DBG("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
  764. RTL_W8(0x82, 0x01);
  765. if (tpc->mcfg < MCFG_METHOD_3) {
  766. DBG("Set PCI Latency=0x40\n");
  767. pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0x40);
  768. }
  769. if (tpc->mcfg == MCFG_METHOD_2) {
  770. DBG("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
  771. RTL_W8(0x82, 0x01);
  772. DBG("Set PHY Reg 0x0bh = 0x00h\n");
  773. RTL8169_WRITE_GMII_REG(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0
  774. }
  775. /* if TBI is not endbled */
  776. if (!(RTL_R8(PHYstatus) & TBI_Enable)) {
  777. int val = RTL8169_READ_GMII_REG(ioaddr, PHY_AUTO_NEGO_REG);
  778. #ifdef RTL8169_HW_FLOW_CONTROL_SUPPORT
  779. val |= PHY_Cap_PAUSE | PHY_Cap_ASYM_PAUSE;
  780. #endif //end #define RTL8169_HW_FLOW_CONTROL_SUPPORT
  781. option = media;
  782. /* Force RTL8169 in 10/100/1000 Full/Half mode. */
  783. if (option > 0) {
  784. printf(" Force-mode Enabled.\n");
  785. Cap10_100 = 0, Cap1000 = 0;
  786. switch (option) {
  787. case _10_Half:
  788. Cap10_100 = PHY_Cap_10_Half;
  789. Cap1000 = PHY_Cap_Null;
  790. break;
  791. case _10_Full:
  792. Cap10_100 = PHY_Cap_10_Full;
  793. Cap1000 = PHY_Cap_Null;
  794. break;
  795. case _100_Half:
  796. Cap10_100 = PHY_Cap_100_Half;
  797. Cap1000 = PHY_Cap_Null;
  798. break;
  799. case _100_Full:
  800. Cap10_100 = PHY_Cap_100_Full;
  801. Cap1000 = PHY_Cap_Null;
  802. break;
  803. case _1000_Full:
  804. Cap10_100 = PHY_Cap_Null;
  805. Cap1000 = PHY_Cap_1000_Full;
  806. break;
  807. default:
  808. break;
  809. }
  810. RTL8169_WRITE_GMII_REG(ioaddr, PHY_AUTO_NEGO_REG, Cap10_100 | (val & 0xC1F)); //leave PHY_AUTO_NEGO_REG bit4:0 unchanged
  811. RTL8169_WRITE_GMII_REG(ioaddr, PHY_1000_CTRL_REG,
  812. Cap1000);
  813. } else {
  814. DBG ( "%s: Auto-negotiation Enabled.\n", pci->driver_name );
  815. // enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged
  816. RTL8169_WRITE_GMII_REG(ioaddr, PHY_AUTO_NEGO_REG,
  817. PHY_Cap_10_Half |
  818. PHY_Cap_10_Full |
  819. PHY_Cap_100_Half |
  820. PHY_Cap_100_Full | (val &
  821. 0xC1F));
  822. // enable 1000 Full Mode
  823. // RTL8169_WRITE_GMII_REG( ioaddr, PHY_1000_CTRL_REG, PHY_Cap_1000_Full );
  824. RTL8169_WRITE_GMII_REG(ioaddr, PHY_1000_CTRL_REG, PHY_Cap_1000_Full | PHY_Cap_1000_Half); //rtl8168
  825. } // end of if( option > 0 )
  826. // Enable auto-negotiation and restart auto-nigotiation
  827. RTL8169_WRITE_GMII_REG(ioaddr, PHY_CTRL_REG,
  828. PHY_Enable_Auto_Nego |
  829. PHY_Restart_Auto_Nego);
  830. udelay(100);
  831. // wait for auto-negotiation process
  832. for (i = 10000; i > 0; i--) {
  833. //check if auto-negotiation complete
  834. if (RTL8169_READ_GMII_REG(ioaddr, PHY_STAT_REG) &
  835. PHY_Auto_Neco_Comp) {
  836. udelay(100);
  837. option = RTL_R8(PHYstatus);
  838. if (option & _1000bpsF) {
  839. printf
  840. ("1000Mbps Full-duplex operation.\n");
  841. } else {
  842. printf
  843. ("%sMbps %s-duplex operation.\n",
  844. (option & _100bps) ? "100" :
  845. "10",
  846. (option & FullDup) ? "Full" :
  847. "Half");
  848. }
  849. break;
  850. } else {
  851. udelay(100);
  852. } // end of if( RTL8169_READ_GMII_REG(ioaddr, 1) & 0x20 )
  853. } // end for-loop to wait for auto-negotiation process
  854. } else {
  855. udelay(100);
  856. printf
  857. ("%s: 1000Mbps Full-duplex operation, TBI Link %s!\n",
  858. pci->driver_name,
  859. (RTL_R32(TBICSR) & TBILinkOK) ? "OK" : "Failed");
  860. }
  861. r8169_reset(nic);
  862. /* point to NIC specific routines */
  863. nic->nic_op = &r8169_operations;
  864. nic->irqno = pci->irq;
  865. nic->ioaddr = ioaddr;
  866. return 1;
  867. }
  868. //======================================================================================================
  869. /*
  870. static void rtl8169_hw_PHY_reset(struct nic *nic __unused)
  871. {
  872. int val, phy_reset_expiretime = 50;
  873. struct rtl8169_private *priv = dev->priv;
  874. unsigned long ioaddr = priv->ioaddr;
  875. DBG("%s: Reset RTL8169s PHY\n", dev->name);
  876. val = ( RTL8169_READ_GMII_REG( ioaddr, 0 ) | 0x8000 ) & 0xffff;
  877. RTL8169_WRITE_GMII_REG( ioaddr, 0, val );
  878. do //waiting for phy reset
  879. {
  880. if( RTL8169_READ_GMII_REG( ioaddr, 0 ) & 0x8000 ){
  881. phy_reset_expiretime --;
  882. udelay(100);
  883. }
  884. else{
  885. break;
  886. }
  887. }while( phy_reset_expiretime >= 0 );
  888. assert( phy_reset_expiretime > 0 );
  889. }
  890. */
  891. //======================================================================================================
  892. static void rtl8169_hw_PHY_config(struct nic *nic __unused)
  893. {
  894. DBG("priv->mcfg=%d, priv->pcfg=%d\n", tpc->mcfg, tpc->pcfg);
  895. if (tpc->mcfg == MCFG_METHOD_4) {
  896. /*
  897. RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x1F, 0x0001 );
  898. RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x1b, 0x841e );
  899. RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x0e, 0x7bfb );
  900. RTL8169_WRITE_GMII_REG( (unsigned long)ioaddr, 0x09, 0x273a );
  901. */
  902. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
  903. 0x0002);
  904. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
  905. 0x90D0);
  906. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
  907. 0x0000);
  908. } else if ((tpc->mcfg == MCFG_METHOD_2)
  909. || (tpc->mcfg == MCFG_METHOD_3)) {
  910. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
  911. 0x0001);
  912. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x15,
  913. 0x1000);
  914. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x18,
  915. 0x65C7);
  916. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  917. 0x0000);
  918. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
  919. 0x00A1);
  920. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
  921. 0x0008);
  922. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
  923. 0x1020);
  924. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
  925. 0x1000);
  926. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  927. 0x0800);
  928. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  929. 0x0000);
  930. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  931. 0x7000);
  932. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
  933. 0xFF41);
  934. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
  935. 0xDE60);
  936. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
  937. 0x0140);
  938. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
  939. 0x0077);
  940. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  941. 0x7800);
  942. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  943. 0x7000);
  944. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  945. 0xA000);
  946. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
  947. 0xDF01);
  948. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
  949. 0xDF20);
  950. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
  951. 0xFF95);
  952. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
  953. 0xFA00);
  954. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  955. 0xA800);
  956. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  957. 0xA000);
  958. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  959. 0xB000);
  960. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
  961. 0xFF41);
  962. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
  963. 0xDE20);
  964. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
  965. 0x0140);
  966. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
  967. 0x00BB);
  968. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  969. 0xB800);
  970. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  971. 0xB000);
  972. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  973. 0xF000);
  974. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x03,
  975. 0xDF01);
  976. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x02,
  977. 0xDF20);
  978. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x01,
  979. 0xFF95);
  980. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x00,
  981. 0xBF00);
  982. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  983. 0xF800);
  984. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  985. 0xF000);
  986. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x04,
  987. 0x0000);
  988. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x1F,
  989. 0x0000);
  990. RTL8169_WRITE_GMII_REG((unsigned long) ioaddr, 0x0B,
  991. 0x0000);
  992. } else {
  993. DBG("tpc->mcfg=%d. Discard hw PHY config.\n",
  994. tpc->mcfg);
  995. }
  996. }
  997. DRIVER ( "r8169/PCI", nic_driver, pci_driver, r8169_driver,
  998. r8169_probe, r8169_disable );
  999. /*
  1000. * Local variables:
  1001. * c-basic-offset: 8
  1002. * c-indent-level: 8
  1003. * tab-width: 8
  1004. * End:
  1005. */