rtl8169.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. /*
  2. * rtl8169.c : U-Boot driver for the RealTek RTL8169
  3. *
  4. * Masami Komiya (mkomiya@sonare.it)
  5. *
  6. * Most part is taken from r8169.c of etherboot
  7. *
  8. */
  9. /**************************************************************************
  10. * r8169.c: Etherboot device driver for the RealTek RTL-8169 Gigabit
  11. * Written 2003 by Timothy Legge <tlegge@rogers.com>
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. *
  15. * Portions of this code based on:
  16. * r8169.c: A RealTek RTL-8169 Gigabit Ethernet driver
  17. * for Linux kernel 2.4.x.
  18. *
  19. * Written 2002 ShuChen <shuchen@realtek.com.tw>
  20. * See Linux Driver for full information
  21. *
  22. * Linux Driver Version 1.27a, 10.02.2002
  23. *
  24. * Thanks to:
  25. * Jean Chen of RealTek Semiconductor Corp. for
  26. * providing the evaluation NIC used to develop
  27. * this driver. RealTek's support for Etherboot
  28. * is appreciated.
  29. *
  30. * REVISION HISTORY:
  31. * ================
  32. *
  33. * v1.0 11-26-2003 timlegge Initial port of Linux driver
  34. * v1.5 01-17-2004 timlegge Initial driver output cleanup
  35. *
  36. * Indent Options: indent -kr -i8
  37. ***************************************************************************/
  38. /*
  39. * 26 August 2006 Mihai Georgian <u-boot@linuxnotincluded.org.uk>
  40. * Modified to use le32_to_cpu and cpu_to_le32 properly
  41. */
  42. #include <common.h>
  43. #include <dm.h>
  44. #include <errno.h>
  45. #include <malloc.h>
  46. #include <memalign.h>
  47. #include <net.h>
  48. #ifndef CONFIG_DM_ETH
  49. #include <netdev.h>
  50. #endif
  51. #include <asm/io.h>
  52. #include <pci.h>
  53. #undef DEBUG_RTL8169
  54. #undef DEBUG_RTL8169_TX
  55. #undef DEBUG_RTL8169_RX
  56. #define drv_version "v1.5"
  57. #define drv_date "01-17-2004"
  58. static unsigned long ioaddr;
  59. /* Condensed operations for readability. */
  60. #define currticks() get_timer(0)
  61. /* media options */
  62. #define MAX_UNITS 8
  63. static int media[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  64. /* MAC address length*/
  65. #define MAC_ADDR_LEN 6
  66. /* max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4).*/
  67. #define MAX_ETH_FRAME_SIZE 1536
  68. #define TX_FIFO_THRESH 256 /* In bytes */
  69. #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */
  70. #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
  71. #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
  72. #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */
  73. #define RxPacketMaxSize 0x0800 /* Maximum size supported is 16K-1 */
  74. #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */
  75. #define NUM_TX_DESC 1 /* Number of Tx descriptor registers */
  76. #ifdef CONFIG_SYS_RX_ETH_BUFFER
  77. #define NUM_RX_DESC CONFIG_SYS_RX_ETH_BUFFER
  78. #else
  79. #define NUM_RX_DESC 4 /* Number of Rx descriptor registers */
  80. #endif
  81. #define RX_BUF_SIZE 1536 /* Rx Buffer size */
  82. #define RX_BUF_LEN 8192
  83. #define RTL_MIN_IO_SIZE 0x80
  84. #define TX_TIMEOUT (6*HZ)
  85. /* write/read MMIO register. Notice: {read,write}[wl] do the necessary swapping */
  86. #define RTL_W8(reg, val8) writeb((val8), ioaddr + (reg))
  87. #define RTL_W16(reg, val16) writew((val16), ioaddr + (reg))
  88. #define RTL_W32(reg, val32) writel((val32), ioaddr + (reg))
  89. #define RTL_R8(reg) readb(ioaddr + (reg))
  90. #define RTL_R16(reg) readw(ioaddr + (reg))
  91. #define RTL_R32(reg) readl(ioaddr + (reg))
  92. #define ETH_FRAME_LEN MAX_ETH_FRAME_SIZE
  93. #define ETH_ALEN MAC_ADDR_LEN
  94. #define ETH_ZLEN 60
  95. #define bus_to_phys(a) pci_mem_to_phys((pci_dev_t)(unsigned long)dev->priv, \
  96. (pci_addr_t)(unsigned long)a)
  97. #define phys_to_bus(a) pci_phys_to_mem((pci_dev_t)(unsigned long)dev->priv, \
  98. (phys_addr_t)a)
  99. enum RTL8169_registers {
  100. MAC0 = 0, /* Ethernet hardware address. */
  101. MAR0 = 8, /* Multicast filter. */
  102. TxDescStartAddrLow = 0x20,
  103. TxDescStartAddrHigh = 0x24,
  104. TxHDescStartAddrLow = 0x28,
  105. TxHDescStartAddrHigh = 0x2c,
  106. FLASH = 0x30,
  107. ERSR = 0x36,
  108. ChipCmd = 0x37,
  109. TxPoll = 0x38,
  110. IntrMask = 0x3C,
  111. IntrStatus = 0x3E,
  112. TxConfig = 0x40,
  113. RxConfig = 0x44,
  114. RxMissed = 0x4C,
  115. Cfg9346 = 0x50,
  116. Config0 = 0x51,
  117. Config1 = 0x52,
  118. Config2 = 0x53,
  119. Config3 = 0x54,
  120. Config4 = 0x55,
  121. Config5 = 0x56,
  122. MultiIntr = 0x5C,
  123. PHYAR = 0x60,
  124. TBICSR = 0x64,
  125. TBI_ANAR = 0x68,
  126. TBI_LPAR = 0x6A,
  127. PHYstatus = 0x6C,
  128. RxMaxSize = 0xDA,
  129. CPlusCmd = 0xE0,
  130. RxDescStartAddrLow = 0xE4,
  131. RxDescStartAddrHigh = 0xE8,
  132. EarlyTxThres = 0xEC,
  133. FuncEvent = 0xF0,
  134. FuncEventMask = 0xF4,
  135. FuncPresetState = 0xF8,
  136. FuncForceEvent = 0xFC,
  137. };
  138. enum RTL8169_register_content {
  139. /*InterruptStatusBits */
  140. SYSErr = 0x8000,
  141. PCSTimeout = 0x4000,
  142. SWInt = 0x0100,
  143. TxDescUnavail = 0x80,
  144. RxFIFOOver = 0x40,
  145. RxUnderrun = 0x20,
  146. RxOverflow = 0x10,
  147. TxErr = 0x08,
  148. TxOK = 0x04,
  149. RxErr = 0x02,
  150. RxOK = 0x01,
  151. /*RxStatusDesc */
  152. RxRES = 0x00200000,
  153. RxCRC = 0x00080000,
  154. RxRUNT = 0x00100000,
  155. RxRWT = 0x00400000,
  156. /*ChipCmdBits */
  157. CmdReset = 0x10,
  158. CmdRxEnb = 0x08,
  159. CmdTxEnb = 0x04,
  160. RxBufEmpty = 0x01,
  161. /*Cfg9346Bits */
  162. Cfg9346_Lock = 0x00,
  163. Cfg9346_Unlock = 0xC0,
  164. /*rx_mode_bits */
  165. AcceptErr = 0x20,
  166. AcceptRunt = 0x10,
  167. AcceptBroadcast = 0x08,
  168. AcceptMulticast = 0x04,
  169. AcceptMyPhys = 0x02,
  170. AcceptAllPhys = 0x01,
  171. /*RxConfigBits */
  172. RxCfgFIFOShift = 13,
  173. RxCfgDMAShift = 8,
  174. /*TxConfigBits */
  175. TxInterFrameGapShift = 24,
  176. TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
  177. /*rtl8169_PHYstatus */
  178. TBI_Enable = 0x80,
  179. TxFlowCtrl = 0x40,
  180. RxFlowCtrl = 0x20,
  181. _1000bpsF = 0x10,
  182. _100bps = 0x08,
  183. _10bps = 0x04,
  184. LinkStatus = 0x02,
  185. FullDup = 0x01,
  186. /*GIGABIT_PHY_registers */
  187. PHY_CTRL_REG = 0,
  188. PHY_STAT_REG = 1,
  189. PHY_AUTO_NEGO_REG = 4,
  190. PHY_1000_CTRL_REG = 9,
  191. /*GIGABIT_PHY_REG_BIT */
  192. PHY_Restart_Auto_Nego = 0x0200,
  193. PHY_Enable_Auto_Nego = 0x1000,
  194. /* PHY_STAT_REG = 1; */
  195. PHY_Auto_Nego_Comp = 0x0020,
  196. /* PHY_AUTO_NEGO_REG = 4; */
  197. PHY_Cap_10_Half = 0x0020,
  198. PHY_Cap_10_Full = 0x0040,
  199. PHY_Cap_100_Half = 0x0080,
  200. PHY_Cap_100_Full = 0x0100,
  201. /* PHY_1000_CTRL_REG = 9; */
  202. PHY_Cap_1000_Full = 0x0200,
  203. PHY_Cap_Null = 0x0,
  204. /*_MediaType*/
  205. _10_Half = 0x01,
  206. _10_Full = 0x02,
  207. _100_Half = 0x04,
  208. _100_Full = 0x08,
  209. _1000_Full = 0x10,
  210. /*_TBICSRBit*/
  211. TBILinkOK = 0x02000000,
  212. };
  213. static struct {
  214. const char *name;
  215. u8 version; /* depend on RTL8169 docs */
  216. u32 RxConfigMask; /* should clear the bits supported by this chip */
  217. } rtl_chip_info[] = {
  218. {"RTL-8169", 0x00, 0xff7e1880,},
  219. {"RTL-8169", 0x04, 0xff7e1880,},
  220. {"RTL-8169", 0x00, 0xff7e1880,},
  221. {"RTL-8169s/8110s", 0x02, 0xff7e1880,},
  222. {"RTL-8169s/8110s", 0x04, 0xff7e1880,},
  223. {"RTL-8169sb/8110sb", 0x10, 0xff7e1880,},
  224. {"RTL-8169sc/8110sc", 0x18, 0xff7e1880,},
  225. {"RTL-8168b/8111sb", 0x30, 0xff7e1880,},
  226. {"RTL-8168b/8111sb", 0x38, 0xff7e1880,},
  227. {"RTL-8168d/8111d", 0x28, 0xff7e1880,},
  228. {"RTL-8168evl/8111evl", 0x2e, 0xff7e1880,},
  229. {"RTL-8168/8111g", 0x4c, 0xff7e1880,},
  230. {"RTL-8101e", 0x34, 0xff7e1880,},
  231. {"RTL-8100e", 0x32, 0xff7e1880,},
  232. };
  233. enum _DescStatusBit {
  234. OWNbit = 0x80000000,
  235. EORbit = 0x40000000,
  236. FSbit = 0x20000000,
  237. LSbit = 0x10000000,
  238. };
  239. struct TxDesc {
  240. u32 status;
  241. u32 vlan_tag;
  242. u32 buf_addr;
  243. u32 buf_Haddr;
  244. };
  245. struct RxDesc {
  246. u32 status;
  247. u32 vlan_tag;
  248. u32 buf_addr;
  249. u32 buf_Haddr;
  250. };
  251. static unsigned char rxdata[RX_BUF_LEN];
  252. #define RTL8169_DESC_SIZE 16
  253. #if ARCH_DMA_MINALIGN > 256
  254. # define RTL8169_ALIGN ARCH_DMA_MINALIGN
  255. #else
  256. # define RTL8169_ALIGN 256
  257. #endif
  258. /*
  259. * Warn if the cache-line size is larger than the descriptor size. In such
  260. * cases the driver will likely fail because the CPU needs to flush the cache
  261. * when requeuing RX buffers, therefore descriptors written by the hardware
  262. * may be discarded.
  263. *
  264. * This can be fixed by defining CONFIG_SYS_NONCACHED_MEMORY which will cause
  265. * the driver to allocate descriptors from a pool of non-cached memory.
  266. */
  267. #if RTL8169_DESC_SIZE < ARCH_DMA_MINALIGN
  268. #if !defined(CONFIG_SYS_NONCACHED_MEMORY) && \
  269. !defined(CONFIG_SYS_DCACHE_OFF) && !defined(CONFIG_X86)
  270. #warning cache-line size is larger than descriptor size
  271. #endif
  272. #endif
  273. /*
  274. * Create a static buffer of size RX_BUF_SZ for each TX Descriptor. All
  275. * descriptors point to a part of this buffer.
  276. */
  277. DEFINE_ALIGN_BUFFER(u8, txb, NUM_TX_DESC * RX_BUF_SIZE, RTL8169_ALIGN);
  278. /*
  279. * Create a static buffer of size RX_BUF_SZ for each RX Descriptor. All
  280. * descriptors point to a part of this buffer.
  281. */
  282. DEFINE_ALIGN_BUFFER(u8, rxb, NUM_RX_DESC * RX_BUF_SIZE, RTL8169_ALIGN);
  283. struct rtl8169_private {
  284. ulong iobase;
  285. void *mmio_addr; /* memory map physical address */
  286. int chipset;
  287. unsigned long cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
  288. unsigned long cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
  289. unsigned long dirty_tx;
  290. struct TxDesc *TxDescArray; /* Index of 256-alignment Tx Descriptor buffer */
  291. struct RxDesc *RxDescArray; /* Index of 256-alignment Rx Descriptor buffer */
  292. unsigned char *RxBufferRings; /* Index of Rx Buffer */
  293. unsigned char *RxBufferRing[NUM_RX_DESC]; /* Index of Rx Buffer array */
  294. unsigned char *Tx_skbuff[NUM_TX_DESC];
  295. } tpx;
  296. static struct rtl8169_private *tpc;
  297. static const u16 rtl8169_intr_mask =
  298. SYSErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver | TxErr |
  299. TxOK | RxErr | RxOK;
  300. static const unsigned int rtl8169_rx_config =
  301. (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
  302. static struct pci_device_id supported[] = {
  303. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167) },
  304. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168) },
  305. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169) },
  306. {}
  307. };
  308. void mdio_write(int RegAddr, int value)
  309. {
  310. int i;
  311. RTL_W32(PHYAR, 0x80000000 | (RegAddr & 0xFF) << 16 | value);
  312. udelay(1000);
  313. for (i = 2000; i > 0; i--) {
  314. /* Check if the RTL8169 has completed writing to the specified MII register */
  315. if (!(RTL_R32(PHYAR) & 0x80000000)) {
  316. break;
  317. } else {
  318. udelay(100);
  319. }
  320. }
  321. }
  322. int mdio_read(int RegAddr)
  323. {
  324. int i, value = -1;
  325. RTL_W32(PHYAR, 0x0 | (RegAddr & 0xFF) << 16);
  326. udelay(1000);
  327. for (i = 2000; i > 0; i--) {
  328. /* Check if the RTL8169 has completed retrieving data from the specified MII register */
  329. if (RTL_R32(PHYAR) & 0x80000000) {
  330. value = (int) (RTL_R32(PHYAR) & 0xFFFF);
  331. break;
  332. } else {
  333. udelay(100);
  334. }
  335. }
  336. return value;
  337. }
  338. static int rtl8169_init_board(unsigned long dev_iobase, const char *name)
  339. {
  340. int i;
  341. u32 tmp;
  342. #ifdef DEBUG_RTL8169
  343. printf ("%s\n", __FUNCTION__);
  344. #endif
  345. ioaddr = dev_iobase;
  346. /* Soft reset the chip. */
  347. RTL_W8(ChipCmd, CmdReset);
  348. /* Check that the chip has finished the reset. */
  349. for (i = 1000; i > 0; i--)
  350. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  351. break;
  352. else
  353. udelay(10);
  354. /* identify chip attached to board */
  355. tmp = RTL_R32(TxConfig);
  356. tmp = ((tmp & 0x7c000000) + ((tmp & 0x00800000) << 2)) >> 24;
  357. for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--){
  358. if (tmp == rtl_chip_info[i].version) {
  359. tpc->chipset = i;
  360. goto match;
  361. }
  362. }
  363. /* if unknown chip, assume array element #0, original RTL-8169 in this case */
  364. printf("PCI device %s: unknown chip version, assuming RTL-8169\n",
  365. name);
  366. printf("PCI device: TxConfig = 0x%lX\n", (unsigned long) RTL_R32(TxConfig));
  367. tpc->chipset = 0;
  368. match:
  369. return 0;
  370. }
  371. /*
  372. * TX and RX descriptors are 16 bytes. This causes problems with the cache
  373. * maintenance on CPUs where the cache-line size exceeds the size of these
  374. * descriptors. What will happen is that when the driver receives a packet
  375. * it will be immediately requeued for the hardware to reuse. The CPU will
  376. * therefore need to flush the cache-line containing the descriptor, which
  377. * will cause all other descriptors in the same cache-line to be flushed
  378. * along with it. If one of those descriptors had been written to by the
  379. * device those changes (and the associated packet) will be lost.
  380. *
  381. * To work around this, we make use of non-cached memory if available. If
  382. * descriptors are mapped uncached there's no need to manually flush them
  383. * or invalidate them.
  384. *
  385. * Note that this only applies to descriptors. The packet data buffers do
  386. * not have the same constraints since they are 1536 bytes large, so they
  387. * are unlikely to share cache-lines.
  388. */
  389. static void *rtl_alloc_descs(unsigned int num)
  390. {
  391. size_t size = num * RTL8169_DESC_SIZE;
  392. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  393. return (void *)noncached_alloc(size, RTL8169_ALIGN);
  394. #else
  395. return memalign(RTL8169_ALIGN, size);
  396. #endif
  397. }
  398. /*
  399. * Cache maintenance functions. These are simple wrappers around the more
  400. * general purpose flush_cache() and invalidate_dcache_range() functions.
  401. */
  402. static void rtl_inval_rx_desc(struct RxDesc *desc)
  403. {
  404. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  405. unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
  406. unsigned long end = ALIGN(start + sizeof(*desc), ARCH_DMA_MINALIGN);
  407. invalidate_dcache_range(start, end);
  408. #endif
  409. }
  410. static void rtl_flush_rx_desc(struct RxDesc *desc)
  411. {
  412. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  413. flush_cache((unsigned long)desc, sizeof(*desc));
  414. #endif
  415. }
  416. static void rtl_inval_tx_desc(struct TxDesc *desc)
  417. {
  418. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  419. unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
  420. unsigned long end = ALIGN(start + sizeof(*desc), ARCH_DMA_MINALIGN);
  421. invalidate_dcache_range(start, end);
  422. #endif
  423. }
  424. static void rtl_flush_tx_desc(struct TxDesc *desc)
  425. {
  426. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  427. flush_cache((unsigned long)desc, sizeof(*desc));
  428. #endif
  429. }
  430. static void rtl_inval_buffer(void *buf, size_t size)
  431. {
  432. unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1);
  433. unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN);
  434. invalidate_dcache_range(start, end);
  435. }
  436. static void rtl_flush_buffer(void *buf, size_t size)
  437. {
  438. flush_cache((unsigned long)buf, size);
  439. }
  440. /**************************************************************************
  441. RECV - Receive a frame
  442. ***************************************************************************/
  443. #ifdef CONFIG_DM_ETH
  444. static int rtl_recv_common(struct udevice *dev, unsigned long dev_iobase,
  445. uchar **packetp)
  446. #else
  447. static int rtl_recv_common(pci_dev_t dev, unsigned long dev_iobase,
  448. uchar **packetp)
  449. #endif
  450. {
  451. /* return true if there's an ethernet packet ready to read */
  452. /* nic->packet should contain data on return */
  453. /* nic->packetlen should contain length of data */
  454. int cur_rx;
  455. int length = 0;
  456. #ifdef DEBUG_RTL8169_RX
  457. printf ("%s\n", __FUNCTION__);
  458. #endif
  459. ioaddr = dev_iobase;
  460. cur_rx = tpc->cur_rx;
  461. rtl_inval_rx_desc(&tpc->RxDescArray[cur_rx]);
  462. if ((le32_to_cpu(tpc->RxDescArray[cur_rx].status) & OWNbit) == 0) {
  463. if (!(le32_to_cpu(tpc->RxDescArray[cur_rx].status) & RxRES)) {
  464. length = (int) (le32_to_cpu(tpc->RxDescArray[cur_rx].
  465. status) & 0x00001FFF) - 4;
  466. rtl_inval_buffer(tpc->RxBufferRing[cur_rx], length);
  467. memcpy(rxdata, tpc->RxBufferRing[cur_rx], length);
  468. if (cur_rx == NUM_RX_DESC - 1)
  469. tpc->RxDescArray[cur_rx].status =
  470. cpu_to_le32((OWNbit | EORbit) + RX_BUF_SIZE);
  471. else
  472. tpc->RxDescArray[cur_rx].status =
  473. cpu_to_le32(OWNbit + RX_BUF_SIZE);
  474. #ifdef CONFIG_DM_ETH
  475. tpc->RxDescArray[cur_rx].buf_addr = cpu_to_le32(
  476. dm_pci_mem_to_phys(dev,
  477. (pci_addr_t)(unsigned long)
  478. tpc->RxBufferRing[cur_rx]));
  479. #else
  480. tpc->RxDescArray[cur_rx].buf_addr = cpu_to_le32(
  481. pci_mem_to_phys(dev, (pci_addr_t)(unsigned long)
  482. tpc->RxBufferRing[cur_rx]));
  483. #endif
  484. rtl_flush_rx_desc(&tpc->RxDescArray[cur_rx]);
  485. #ifdef CONFIG_DM_ETH
  486. *packetp = rxdata;
  487. #else
  488. net_process_received_packet(rxdata, length);
  489. #endif
  490. } else {
  491. puts("Error Rx");
  492. length = -EIO;
  493. }
  494. cur_rx = (cur_rx + 1) % NUM_RX_DESC;
  495. tpc->cur_rx = cur_rx;
  496. return length;
  497. } else {
  498. ushort sts = RTL_R8(IntrStatus);
  499. RTL_W8(IntrStatus, sts & ~(TxErr | RxErr | SYSErr));
  500. udelay(100); /* wait */
  501. }
  502. tpc->cur_rx = cur_rx;
  503. return (0); /* initially as this is called to flush the input */
  504. }
  505. #ifdef CONFIG_DM_ETH
  506. int rtl8169_eth_recv(struct udevice *dev, int flags, uchar **packetp)
  507. {
  508. struct rtl8169_private *priv = dev_get_priv(dev);
  509. return rtl_recv_common(dev, priv->iobase, packetp);
  510. }
  511. #else
  512. static int rtl_recv(struct eth_device *dev)
  513. {
  514. return rtl_recv_common((pci_dev_t)(unsigned long)dev->priv,
  515. dev->iobase, NULL);
  516. }
  517. #endif /* nCONFIG_DM_ETH */
  518. #define HZ 1000
  519. /**************************************************************************
  520. SEND - Transmit a frame
  521. ***************************************************************************/
  522. #ifdef CONFIG_DM_ETH
  523. static int rtl_send_common(struct udevice *dev, unsigned long dev_iobase,
  524. void *packet, int length)
  525. #else
  526. static int rtl_send_common(pci_dev_t dev, unsigned long dev_iobase,
  527. void *packet, int length)
  528. #endif
  529. {
  530. /* send the packet to destination */
  531. u32 to;
  532. u8 *ptxb;
  533. int entry = tpc->cur_tx % NUM_TX_DESC;
  534. u32 len = length;
  535. int ret;
  536. #ifdef DEBUG_RTL8169_TX
  537. int stime = currticks();
  538. printf ("%s\n", __FUNCTION__);
  539. printf("sending %d bytes\n", len);
  540. #endif
  541. ioaddr = dev_iobase;
  542. /* point to the current txb incase multiple tx_rings are used */
  543. ptxb = tpc->Tx_skbuff[entry * MAX_ETH_FRAME_SIZE];
  544. memcpy(ptxb, (char *)packet, (int)length);
  545. rtl_flush_buffer(ptxb, length);
  546. while (len < ETH_ZLEN)
  547. ptxb[len++] = '\0';
  548. tpc->TxDescArray[entry].buf_Haddr = 0;
  549. #ifdef CONFIG_DM_ETH
  550. tpc->TxDescArray[entry].buf_addr = cpu_to_le32(
  551. dm_pci_mem_to_phys(dev, (pci_addr_t)(unsigned long)ptxb));
  552. #else
  553. tpc->TxDescArray[entry].buf_addr = cpu_to_le32(
  554. pci_mem_to_phys(dev, (pci_addr_t)(unsigned long)ptxb));
  555. #endif
  556. if (entry != (NUM_TX_DESC - 1)) {
  557. tpc->TxDescArray[entry].status =
  558. cpu_to_le32((OWNbit | FSbit | LSbit) |
  559. ((len > ETH_ZLEN) ? len : ETH_ZLEN));
  560. } else {
  561. tpc->TxDescArray[entry].status =
  562. cpu_to_le32((OWNbit | EORbit | FSbit | LSbit) |
  563. ((len > ETH_ZLEN) ? len : ETH_ZLEN));
  564. }
  565. rtl_flush_tx_desc(&tpc->TxDescArray[entry]);
  566. RTL_W8(TxPoll, 0x40); /* set polling bit */
  567. tpc->cur_tx++;
  568. to = currticks() + TX_TIMEOUT;
  569. do {
  570. rtl_inval_tx_desc(&tpc->TxDescArray[entry]);
  571. } while ((le32_to_cpu(tpc->TxDescArray[entry].status) & OWNbit)
  572. && (currticks() < to)); /* wait */
  573. if (currticks() >= to) {
  574. #ifdef DEBUG_RTL8169_TX
  575. puts("tx timeout/error\n");
  576. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  577. #endif
  578. ret = -ETIMEDOUT;
  579. } else {
  580. #ifdef DEBUG_RTL8169_TX
  581. puts("tx done\n");
  582. #endif
  583. ret = 0;
  584. }
  585. /* Delay to make net console (nc) work properly */
  586. udelay(20);
  587. return ret;
  588. }
  589. #ifdef CONFIG_DM_ETH
  590. int rtl8169_eth_send(struct udevice *dev, void *packet, int length)
  591. {
  592. struct rtl8169_private *priv = dev_get_priv(dev);
  593. return rtl_send_common(dev, priv->iobase, packet, length);
  594. }
  595. #else
  596. static int rtl_send(struct eth_device *dev, void *packet, int length)
  597. {
  598. return rtl_send_common((pci_dev_t)(unsigned long)dev->priv,
  599. dev->iobase, packet, length);
  600. }
  601. #endif
  602. static void rtl8169_set_rx_mode(void)
  603. {
  604. u32 mc_filter[2]; /* Multicast hash filter */
  605. int rx_mode;
  606. u32 tmp = 0;
  607. #ifdef DEBUG_RTL8169
  608. printf ("%s\n", __FUNCTION__);
  609. #endif
  610. /* IFF_ALLMULTI */
  611. /* Too many to filter perfectly -- accept all multicasts. */
  612. rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
  613. mc_filter[1] = mc_filter[0] = 0xffffffff;
  614. tmp = rtl8169_rx_config | rx_mode | (RTL_R32(RxConfig) &
  615. rtl_chip_info[tpc->chipset].RxConfigMask);
  616. RTL_W32(RxConfig, tmp);
  617. RTL_W32(MAR0 + 0, mc_filter[0]);
  618. RTL_W32(MAR0 + 4, mc_filter[1]);
  619. }
  620. #ifdef CONFIG_DM_ETH
  621. static void rtl8169_hw_start(struct udevice *dev)
  622. #else
  623. static void rtl8169_hw_start(pci_dev_t dev)
  624. #endif
  625. {
  626. u32 i;
  627. #ifdef DEBUG_RTL8169
  628. int stime = currticks();
  629. printf ("%s\n", __FUNCTION__);
  630. #endif
  631. #if 0
  632. /* Soft reset the chip. */
  633. RTL_W8(ChipCmd, CmdReset);
  634. /* Check that the chip has finished the reset. */
  635. for (i = 1000; i > 0; i--) {
  636. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  637. break;
  638. else
  639. udelay(10);
  640. }
  641. #endif
  642. RTL_W8(Cfg9346, Cfg9346_Unlock);
  643. /* RTL-8169sb/8110sb or previous version */
  644. if (tpc->chipset <= 5)
  645. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  646. RTL_W8(EarlyTxThres, EarlyTxThld);
  647. /* For gigabit rtl8169 */
  648. RTL_W16(RxMaxSize, RxPacketMaxSize);
  649. /* Set Rx Config register */
  650. i = rtl8169_rx_config | (RTL_R32(RxConfig) &
  651. rtl_chip_info[tpc->chipset].RxConfigMask);
  652. RTL_W32(RxConfig, i);
  653. /* Set DMA burst size and Interframe Gap Time */
  654. RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
  655. (InterFrameGap << TxInterFrameGapShift));
  656. tpc->cur_rx = 0;
  657. #ifdef CONFIG_DM_ETH
  658. RTL_W32(TxDescStartAddrLow, dm_pci_mem_to_phys(dev,
  659. (pci_addr_t)(unsigned long)tpc->TxDescArray));
  660. #else
  661. RTL_W32(TxDescStartAddrLow, pci_mem_to_phys(dev,
  662. (pci_addr_t)(unsigned long)tpc->TxDescArray));
  663. #endif
  664. RTL_W32(TxDescStartAddrHigh, (unsigned long)0);
  665. #ifdef CONFIG_DM_ETH
  666. RTL_W32(RxDescStartAddrLow, dm_pci_mem_to_phys(
  667. dev, (pci_addr_t)(unsigned long)tpc->RxDescArray));
  668. #else
  669. RTL_W32(RxDescStartAddrLow, pci_mem_to_phys(
  670. dev, (pci_addr_t)(unsigned long)tpc->RxDescArray));
  671. #endif
  672. RTL_W32(RxDescStartAddrHigh, (unsigned long)0);
  673. /* RTL-8169sc/8110sc or later version */
  674. if (tpc->chipset > 5)
  675. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  676. RTL_W8(Cfg9346, Cfg9346_Lock);
  677. udelay(10);
  678. RTL_W32(RxMissed, 0);
  679. rtl8169_set_rx_mode();
  680. /* no early-rx interrupts */
  681. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  682. #ifdef DEBUG_RTL8169
  683. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  684. #endif
  685. }
  686. #ifdef CONFIG_DM_ETH
  687. static void rtl8169_init_ring(struct udevice *dev)
  688. #else
  689. static void rtl8169_init_ring(pci_dev_t dev)
  690. #endif
  691. {
  692. int i;
  693. #ifdef DEBUG_RTL8169
  694. int stime = currticks();
  695. printf ("%s\n", __FUNCTION__);
  696. #endif
  697. tpc->cur_rx = 0;
  698. tpc->cur_tx = 0;
  699. tpc->dirty_tx = 0;
  700. memset(tpc->TxDescArray, 0x0, NUM_TX_DESC * sizeof(struct TxDesc));
  701. memset(tpc->RxDescArray, 0x0, NUM_RX_DESC * sizeof(struct RxDesc));
  702. for (i = 0; i < NUM_TX_DESC; i++) {
  703. tpc->Tx_skbuff[i] = &txb[i];
  704. }
  705. for (i = 0; i < NUM_RX_DESC; i++) {
  706. if (i == (NUM_RX_DESC - 1))
  707. tpc->RxDescArray[i].status =
  708. cpu_to_le32((OWNbit | EORbit) + RX_BUF_SIZE);
  709. else
  710. tpc->RxDescArray[i].status =
  711. cpu_to_le32(OWNbit + RX_BUF_SIZE);
  712. tpc->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
  713. #ifdef CONFIG_DM_ETH
  714. tpc->RxDescArray[i].buf_addr = cpu_to_le32(dm_pci_mem_to_phys(
  715. dev, (pci_addr_t)(unsigned long)tpc->RxBufferRing[i]));
  716. #else
  717. tpc->RxDescArray[i].buf_addr = cpu_to_le32(pci_mem_to_phys(
  718. dev, (pci_addr_t)(unsigned long)tpc->RxBufferRing[i]));
  719. #endif
  720. rtl_flush_rx_desc(&tpc->RxDescArray[i]);
  721. }
  722. #ifdef DEBUG_RTL8169
  723. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  724. #endif
  725. }
  726. #ifdef CONFIG_DM_ETH
  727. static void rtl8169_common_start(struct udevice *dev, unsigned char *enetaddr,
  728. unsigned long dev_iobase)
  729. #else
  730. static void rtl8169_common_start(pci_dev_t dev, unsigned char *enetaddr,
  731. unsigned long dev_iobase)
  732. #endif
  733. {
  734. int i;
  735. #ifdef DEBUG_RTL8169
  736. int stime = currticks();
  737. printf ("%s\n", __FUNCTION__);
  738. #endif
  739. ioaddr = dev_iobase;
  740. rtl8169_init_ring(dev);
  741. rtl8169_hw_start(dev);
  742. /* Construct a perfect filter frame with the mac address as first match
  743. * and broadcast for all others */
  744. for (i = 0; i < 192; i++)
  745. txb[i] = 0xFF;
  746. txb[0] = enetaddr[0];
  747. txb[1] = enetaddr[1];
  748. txb[2] = enetaddr[2];
  749. txb[3] = enetaddr[3];
  750. txb[4] = enetaddr[4];
  751. txb[5] = enetaddr[5];
  752. #ifdef DEBUG_RTL8169
  753. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  754. #endif
  755. }
  756. #ifdef CONFIG_DM_ETH
  757. static int rtl8169_eth_start(struct udevice *dev)
  758. {
  759. struct eth_pdata *plat = dev_get_platdata(dev);
  760. struct rtl8169_private *priv = dev_get_priv(dev);
  761. rtl8169_common_start(dev, plat->enetaddr, priv->iobase);
  762. return 0;
  763. }
  764. #else
  765. /**************************************************************************
  766. RESET - Finish setting up the ethernet interface
  767. ***************************************************************************/
  768. static int rtl_reset(struct eth_device *dev, bd_t *bis)
  769. {
  770. rtl8169_common_start((pci_dev_t)(unsigned long)dev->priv,
  771. dev->enetaddr, dev->iobase);
  772. return 0;
  773. }
  774. #endif /* nCONFIG_DM_ETH */
  775. static void rtl_halt_common(unsigned long dev_iobase)
  776. {
  777. int i;
  778. #ifdef DEBUG_RTL8169
  779. printf ("%s\n", __FUNCTION__);
  780. #endif
  781. ioaddr = dev_iobase;
  782. /* Stop the chip's Tx and Rx DMA processes. */
  783. RTL_W8(ChipCmd, 0x00);
  784. /* Disable interrupts by clearing the interrupt mask. */
  785. RTL_W16(IntrMask, 0x0000);
  786. RTL_W32(RxMissed, 0);
  787. for (i = 0; i < NUM_RX_DESC; i++) {
  788. tpc->RxBufferRing[i] = NULL;
  789. }
  790. }
  791. #ifdef CONFIG_DM_ETH
  792. void rtl8169_eth_stop(struct udevice *dev)
  793. {
  794. struct rtl8169_private *priv = dev_get_priv(dev);
  795. rtl_halt_common(priv->iobase);
  796. }
  797. #else
  798. /**************************************************************************
  799. HALT - Turn off ethernet interface
  800. ***************************************************************************/
  801. static void rtl_halt(struct eth_device *dev)
  802. {
  803. rtl_halt_common(dev->iobase);
  804. }
  805. #endif
  806. /**************************************************************************
  807. INIT - Look for an adapter, this routine's visible to the outside
  808. ***************************************************************************/
  809. #define board_found 1
  810. #define valid_link 0
  811. static int rtl_init(unsigned long dev_ioaddr, const char *name,
  812. unsigned char *enetaddr)
  813. {
  814. static int board_idx = -1;
  815. int i, rc;
  816. int option = -1, Cap10_100 = 0, Cap1000 = 0;
  817. #ifdef DEBUG_RTL8169
  818. printf ("%s\n", __FUNCTION__);
  819. #endif
  820. ioaddr = dev_ioaddr;
  821. board_idx++;
  822. /* point to private storage */
  823. tpc = &tpx;
  824. rc = rtl8169_init_board(ioaddr, name);
  825. if (rc)
  826. return rc;
  827. /* Get MAC address. FIXME: read EEPROM */
  828. for (i = 0; i < MAC_ADDR_LEN; i++)
  829. enetaddr[i] = RTL_R8(MAC0 + i);
  830. #ifdef DEBUG_RTL8169
  831. printf("chipset = %d\n", tpc->chipset);
  832. printf("MAC Address");
  833. for (i = 0; i < MAC_ADDR_LEN; i++)
  834. printf(":%02x", enetaddr[i]);
  835. putc('\n');
  836. #endif
  837. #ifdef DEBUG_RTL8169
  838. /* Print out some hardware info */
  839. printf("%s: at ioaddr 0x%lx\n", name, ioaddr);
  840. #endif
  841. /* if TBI is not endbled */
  842. if (!(RTL_R8(PHYstatus) & TBI_Enable)) {
  843. int val = mdio_read(PHY_AUTO_NEGO_REG);
  844. option = (board_idx >= MAX_UNITS) ? 0 : media[board_idx];
  845. /* Force RTL8169 in 10/100/1000 Full/Half mode. */
  846. if (option > 0) {
  847. #ifdef DEBUG_RTL8169
  848. printf("%s: Force-mode Enabled.\n", name);
  849. #endif
  850. Cap10_100 = 0, Cap1000 = 0;
  851. switch (option) {
  852. case _10_Half:
  853. Cap10_100 = PHY_Cap_10_Half;
  854. Cap1000 = PHY_Cap_Null;
  855. break;
  856. case _10_Full:
  857. Cap10_100 = PHY_Cap_10_Full;
  858. Cap1000 = PHY_Cap_Null;
  859. break;
  860. case _100_Half:
  861. Cap10_100 = PHY_Cap_100_Half;
  862. Cap1000 = PHY_Cap_Null;
  863. break;
  864. case _100_Full:
  865. Cap10_100 = PHY_Cap_100_Full;
  866. Cap1000 = PHY_Cap_Null;
  867. break;
  868. case _1000_Full:
  869. Cap10_100 = PHY_Cap_Null;
  870. Cap1000 = PHY_Cap_1000_Full;
  871. break;
  872. default:
  873. break;
  874. }
  875. mdio_write(PHY_AUTO_NEGO_REG, Cap10_100 | (val & 0x1F)); /* leave PHY_AUTO_NEGO_REG bit4:0 unchanged */
  876. mdio_write(PHY_1000_CTRL_REG, Cap1000);
  877. } else {
  878. #ifdef DEBUG_RTL8169
  879. printf("%s: Auto-negotiation Enabled.\n",
  880. name);
  881. #endif
  882. /* enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged */
  883. mdio_write(PHY_AUTO_NEGO_REG,
  884. PHY_Cap_10_Half | PHY_Cap_10_Full |
  885. PHY_Cap_100_Half | PHY_Cap_100_Full |
  886. (val & 0x1F));
  887. /* enable 1000 Full Mode */
  888. mdio_write(PHY_1000_CTRL_REG, PHY_Cap_1000_Full);
  889. }
  890. /* Enable auto-negotiation and restart auto-nigotiation */
  891. mdio_write(PHY_CTRL_REG,
  892. PHY_Enable_Auto_Nego | PHY_Restart_Auto_Nego);
  893. udelay(100);
  894. /* wait for auto-negotiation process */
  895. for (i = 10000; i > 0; i--) {
  896. /* check if auto-negotiation complete */
  897. if (mdio_read(PHY_STAT_REG) & PHY_Auto_Nego_Comp) {
  898. udelay(100);
  899. option = RTL_R8(PHYstatus);
  900. if (option & _1000bpsF) {
  901. #ifdef DEBUG_RTL8169
  902. printf("%s: 1000Mbps Full-duplex operation.\n",
  903. name);
  904. #endif
  905. } else {
  906. #ifdef DEBUG_RTL8169
  907. printf("%s: %sMbps %s-duplex operation.\n",
  908. name,
  909. (option & _100bps) ? "100" :
  910. "10",
  911. (option & FullDup) ? "Full" :
  912. "Half");
  913. #endif
  914. }
  915. break;
  916. } else {
  917. udelay(100);
  918. }
  919. } /* end for-loop to wait for auto-negotiation process */
  920. } else {
  921. udelay(100);
  922. #ifdef DEBUG_RTL8169
  923. printf
  924. ("%s: 1000Mbps Full-duplex operation, TBI Link %s!\n",
  925. name,
  926. (RTL_R32(TBICSR) & TBILinkOK) ? "OK" : "Failed");
  927. #endif
  928. }
  929. tpc->RxDescArray = rtl_alloc_descs(NUM_RX_DESC);
  930. if (!tpc->RxDescArray)
  931. return -ENOMEM;
  932. tpc->TxDescArray = rtl_alloc_descs(NUM_TX_DESC);
  933. if (!tpc->TxDescArray)
  934. return -ENOMEM;
  935. return 0;
  936. }
  937. #ifndef CONFIG_DM_ETH
  938. int rtl8169_initialize(bd_t *bis)
  939. {
  940. pci_dev_t devno;
  941. int card_number = 0;
  942. struct eth_device *dev;
  943. u32 iobase;
  944. int idx=0;
  945. while(1){
  946. unsigned int region;
  947. u16 device;
  948. int err;
  949. /* Find RTL8169 */
  950. if ((devno = pci_find_devices(supported, idx++)) < 0)
  951. break;
  952. pci_read_config_word(devno, PCI_DEVICE_ID, &device);
  953. switch (device) {
  954. case 0x8168:
  955. region = 2;
  956. break;
  957. default:
  958. region = 1;
  959. break;
  960. }
  961. pci_read_config_dword(devno, PCI_BASE_ADDRESS_0 + (region * 4), &iobase);
  962. iobase &= ~0xf;
  963. debug ("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
  964. dev = (struct eth_device *)malloc(sizeof *dev);
  965. if (!dev) {
  966. printf("Can not allocate memory of rtl8169\n");
  967. break;
  968. }
  969. memset(dev, 0, sizeof(*dev));
  970. sprintf (dev->name, "RTL8169#%d", card_number);
  971. dev->priv = (void *)(unsigned long)devno;
  972. dev->iobase = (int)pci_mem_to_phys(devno, iobase);
  973. dev->init = rtl_reset;
  974. dev->halt = rtl_halt;
  975. dev->send = rtl_send;
  976. dev->recv = rtl_recv;
  977. err = rtl_init(dev->iobase, dev->name, dev->enetaddr);
  978. if (err < 0) {
  979. printf(pr_fmt("failed to initialize card: %d\n"), err);
  980. free(dev);
  981. continue;
  982. }
  983. eth_register (dev);
  984. card_number++;
  985. }
  986. return card_number;
  987. }
  988. #endif
  989. #ifdef CONFIG_DM_ETH
  990. static int rtl8169_eth_probe(struct udevice *dev)
  991. {
  992. struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
  993. struct rtl8169_private *priv = dev_get_priv(dev);
  994. struct eth_pdata *plat = dev_get_platdata(dev);
  995. u32 iobase;
  996. int region;
  997. int ret;
  998. debug("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
  999. switch (pplat->device) {
  1000. case 0x8168:
  1001. region = 2;
  1002. break;
  1003. default:
  1004. region = 1;
  1005. break;
  1006. }
  1007. dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0 + region * 4, &iobase);
  1008. iobase &= ~0xf;
  1009. priv->iobase = (int)dm_pci_mem_to_phys(dev, iobase);
  1010. ret = rtl_init(priv->iobase, dev->name, plat->enetaddr);
  1011. if (ret < 0) {
  1012. printf(pr_fmt("failed to initialize card: %d\n"), ret);
  1013. return ret;
  1014. }
  1015. return 0;
  1016. }
  1017. static const struct eth_ops rtl8169_eth_ops = {
  1018. .start = rtl8169_eth_start,
  1019. .send = rtl8169_eth_send,
  1020. .recv = rtl8169_eth_recv,
  1021. .stop = rtl8169_eth_stop,
  1022. };
  1023. static const struct udevice_id rtl8169_eth_ids[] = {
  1024. { .compatible = "realtek,rtl8169" },
  1025. { }
  1026. };
  1027. U_BOOT_DRIVER(eth_rtl8169) = {
  1028. .name = "eth_rtl8169",
  1029. .id = UCLASS_ETH,
  1030. .of_match = rtl8169_eth_ids,
  1031. .probe = rtl8169_eth_probe,
  1032. .ops = &rtl8169_eth_ops,
  1033. .priv_auto_alloc_size = sizeof(struct rtl8169_private),
  1034. .platdata_auto_alloc_size = sizeof(struct eth_pdata),
  1035. };
  1036. U_BOOT_PCI_DEVICE(eth_rtl8169, supported);
  1037. #endif