rtl8169.c 30 KB

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