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

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