rtl8169.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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 unsigned int rtl8169_rx_config =
  298. (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
  299. static struct pci_device_id supported[] = {
  300. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167) },
  301. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168) },
  302. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169) },
  303. {}
  304. };
  305. void mdio_write(int RegAddr, int value)
  306. {
  307. int i;
  308. RTL_W32(PHYAR, 0x80000000 | (RegAddr & 0xFF) << 16 | value);
  309. udelay(1000);
  310. for (i = 2000; i > 0; i--) {
  311. /* Check if the RTL8169 has completed writing to the specified MII register */
  312. if (!(RTL_R32(PHYAR) & 0x80000000)) {
  313. break;
  314. } else {
  315. udelay(100);
  316. }
  317. }
  318. }
  319. int mdio_read(int RegAddr)
  320. {
  321. int i, value = -1;
  322. RTL_W32(PHYAR, 0x0 | (RegAddr & 0xFF) << 16);
  323. udelay(1000);
  324. for (i = 2000; i > 0; i--) {
  325. /* Check if the RTL8169 has completed retrieving data from the specified MII register */
  326. if (RTL_R32(PHYAR) & 0x80000000) {
  327. value = (int) (RTL_R32(PHYAR) & 0xFFFF);
  328. break;
  329. } else {
  330. udelay(100);
  331. }
  332. }
  333. return value;
  334. }
  335. static int rtl8169_init_board(unsigned long dev_iobase, const char *name)
  336. {
  337. int i;
  338. u32 tmp;
  339. #ifdef DEBUG_RTL8169
  340. printf ("%s\n", __FUNCTION__);
  341. #endif
  342. ioaddr = dev_iobase;
  343. /* Soft reset the chip. */
  344. RTL_W8(ChipCmd, CmdReset);
  345. /* Check that the chip has finished the reset. */
  346. for (i = 1000; i > 0; i--)
  347. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  348. break;
  349. else
  350. udelay(10);
  351. /* identify chip attached to board */
  352. tmp = RTL_R32(TxConfig);
  353. tmp = ((tmp & 0x7c000000) + ((tmp & 0x00800000) << 2)) >> 24;
  354. for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--){
  355. if (tmp == rtl_chip_info[i].version) {
  356. tpc->chipset = i;
  357. goto match;
  358. }
  359. }
  360. /* if unknown chip, assume array element #0, original RTL-8169 in this case */
  361. printf("PCI device %s: unknown chip version, assuming RTL-8169\n",
  362. name);
  363. printf("PCI device: TxConfig = 0x%lX\n", (unsigned long) RTL_R32(TxConfig));
  364. tpc->chipset = 0;
  365. match:
  366. return 0;
  367. }
  368. /*
  369. * TX and RX descriptors are 16 bytes. This causes problems with the cache
  370. * maintenance on CPUs where the cache-line size exceeds the size of these
  371. * descriptors. What will happen is that when the driver receives a packet
  372. * it will be immediately requeued for the hardware to reuse. The CPU will
  373. * therefore need to flush the cache-line containing the descriptor, which
  374. * will cause all other descriptors in the same cache-line to be flushed
  375. * along with it. If one of those descriptors had been written to by the
  376. * device those changes (and the associated packet) will be lost.
  377. *
  378. * To work around this, we make use of non-cached memory if available. If
  379. * descriptors are mapped uncached there's no need to manually flush them
  380. * or invalidate them.
  381. *
  382. * Note that this only applies to descriptors. The packet data buffers do
  383. * not have the same constraints since they are 1536 bytes large, so they
  384. * are unlikely to share cache-lines.
  385. */
  386. static void *rtl_alloc_descs(unsigned int num)
  387. {
  388. size_t size = num * RTL8169_DESC_SIZE;
  389. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  390. return (void *)noncached_alloc(size, RTL8169_ALIGN);
  391. #else
  392. return memalign(RTL8169_ALIGN, size);
  393. #endif
  394. }
  395. /*
  396. * Cache maintenance functions. These are simple wrappers around the more
  397. * general purpose flush_cache() and invalidate_dcache_range() functions.
  398. */
  399. static void rtl_inval_rx_desc(struct RxDesc *desc)
  400. {
  401. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  402. unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
  403. unsigned long end = ALIGN(start + sizeof(*desc), ARCH_DMA_MINALIGN);
  404. invalidate_dcache_range(start, end);
  405. #endif
  406. }
  407. static void rtl_flush_rx_desc(struct RxDesc *desc)
  408. {
  409. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  410. flush_cache((unsigned long)desc, sizeof(*desc));
  411. #endif
  412. }
  413. static void rtl_inval_tx_desc(struct TxDesc *desc)
  414. {
  415. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  416. unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
  417. unsigned long end = ALIGN(start + sizeof(*desc), ARCH_DMA_MINALIGN);
  418. invalidate_dcache_range(start, end);
  419. #endif
  420. }
  421. static void rtl_flush_tx_desc(struct TxDesc *desc)
  422. {
  423. #ifndef CONFIG_SYS_NONCACHED_MEMORY
  424. flush_cache((unsigned long)desc, sizeof(*desc));
  425. #endif
  426. }
  427. static void rtl_inval_buffer(void *buf, size_t size)
  428. {
  429. unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1);
  430. unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN);
  431. invalidate_dcache_range(start, end);
  432. }
  433. static void rtl_flush_buffer(void *buf, size_t size)
  434. {
  435. flush_cache((unsigned long)buf, size);
  436. }
  437. /**************************************************************************
  438. RECV - Receive a frame
  439. ***************************************************************************/
  440. #ifdef CONFIG_DM_ETH
  441. static int rtl_recv_common(struct udevice *dev, unsigned long dev_iobase,
  442. uchar **packetp)
  443. #else
  444. static int rtl_recv_common(pci_dev_t dev, unsigned long dev_iobase,
  445. uchar **packetp)
  446. #endif
  447. {
  448. /* return true if there's an ethernet packet ready to read */
  449. /* nic->packet should contain data on return */
  450. /* nic->packetlen should contain length of data */
  451. int cur_rx;
  452. int length = 0;
  453. #ifdef DEBUG_RTL8169_RX
  454. printf ("%s\n", __FUNCTION__);
  455. #endif
  456. ioaddr = dev_iobase;
  457. cur_rx = tpc->cur_rx;
  458. rtl_inval_rx_desc(&tpc->RxDescArray[cur_rx]);
  459. if ((le32_to_cpu(tpc->RxDescArray[cur_rx].status) & OWNbit) == 0) {
  460. if (!(le32_to_cpu(tpc->RxDescArray[cur_rx].status) & RxRES)) {
  461. length = (int) (le32_to_cpu(tpc->RxDescArray[cur_rx].
  462. status) & 0x00001FFF) - 4;
  463. rtl_inval_buffer(tpc->RxBufferRing[cur_rx], length);
  464. memcpy(rxdata, tpc->RxBufferRing[cur_rx], length);
  465. if (cur_rx == NUM_RX_DESC - 1)
  466. tpc->RxDescArray[cur_rx].status =
  467. cpu_to_le32((OWNbit | EORbit) + RX_BUF_SIZE);
  468. else
  469. tpc->RxDescArray[cur_rx].status =
  470. cpu_to_le32(OWNbit + RX_BUF_SIZE);
  471. #ifdef CONFIG_DM_ETH
  472. tpc->RxDescArray[cur_rx].buf_addr = cpu_to_le32(
  473. dm_pci_mem_to_phys(dev,
  474. (pci_addr_t)(unsigned long)
  475. tpc->RxBufferRing[cur_rx]));
  476. #else
  477. tpc->RxDescArray[cur_rx].buf_addr = cpu_to_le32(
  478. pci_mem_to_phys(dev, (pci_addr_t)(unsigned long)
  479. tpc->RxBufferRing[cur_rx]));
  480. #endif
  481. rtl_flush_rx_desc(&tpc->RxDescArray[cur_rx]);
  482. #ifdef CONFIG_DM_ETH
  483. *packetp = rxdata;
  484. #else
  485. net_process_received_packet(rxdata, length);
  486. #endif
  487. } else {
  488. puts("Error Rx");
  489. length = -EIO;
  490. }
  491. cur_rx = (cur_rx + 1) % NUM_RX_DESC;
  492. tpc->cur_rx = cur_rx;
  493. return length;
  494. } else {
  495. ushort sts = RTL_R8(IntrStatus);
  496. RTL_W8(IntrStatus, sts & ~(TxErr | RxErr | SYSErr));
  497. udelay(100); /* wait */
  498. }
  499. tpc->cur_rx = cur_rx;
  500. return (0); /* initially as this is called to flush the input */
  501. }
  502. #ifdef CONFIG_DM_ETH
  503. int rtl8169_eth_recv(struct udevice *dev, int flags, uchar **packetp)
  504. {
  505. struct rtl8169_private *priv = dev_get_priv(dev);
  506. return rtl_recv_common(dev, priv->iobase, packetp);
  507. }
  508. #else
  509. static int rtl_recv(struct eth_device *dev)
  510. {
  511. return rtl_recv_common((pci_dev_t)(unsigned long)dev->priv,
  512. dev->iobase, NULL);
  513. }
  514. #endif /* nCONFIG_DM_ETH */
  515. #define HZ 1000
  516. /**************************************************************************
  517. SEND - Transmit a frame
  518. ***************************************************************************/
  519. #ifdef CONFIG_DM_ETH
  520. static int rtl_send_common(struct udevice *dev, unsigned long dev_iobase,
  521. void *packet, int length)
  522. #else
  523. static int rtl_send_common(pci_dev_t dev, unsigned long dev_iobase,
  524. void *packet, int length)
  525. #endif
  526. {
  527. /* send the packet to destination */
  528. u32 to;
  529. u8 *ptxb;
  530. int entry = tpc->cur_tx % NUM_TX_DESC;
  531. u32 len = length;
  532. int ret;
  533. #ifdef DEBUG_RTL8169_TX
  534. int stime = currticks();
  535. printf ("%s\n", __FUNCTION__);
  536. printf("sending %d bytes\n", len);
  537. #endif
  538. ioaddr = dev_iobase;
  539. /* point to the current txb incase multiple tx_rings are used */
  540. ptxb = tpc->Tx_skbuff[entry * MAX_ETH_FRAME_SIZE];
  541. memcpy(ptxb, (char *)packet, (int)length);
  542. while (len < ETH_ZLEN)
  543. ptxb[len++] = '\0';
  544. rtl_flush_buffer(ptxb, ALIGN(len, RTL8169_ALIGN));
  545. tpc->TxDescArray[entry].buf_Haddr = 0;
  546. #ifdef CONFIG_DM_ETH
  547. tpc->TxDescArray[entry].buf_addr = cpu_to_le32(
  548. dm_pci_mem_to_phys(dev, (pci_addr_t)(unsigned long)ptxb));
  549. #else
  550. tpc->TxDescArray[entry].buf_addr = cpu_to_le32(
  551. pci_mem_to_phys(dev, (pci_addr_t)(unsigned long)ptxb));
  552. #endif
  553. if (entry != (NUM_TX_DESC - 1)) {
  554. tpc->TxDescArray[entry].status =
  555. cpu_to_le32((OWNbit | FSbit | LSbit) |
  556. ((len > ETH_ZLEN) ? len : ETH_ZLEN));
  557. } else {
  558. tpc->TxDescArray[entry].status =
  559. cpu_to_le32((OWNbit | EORbit | FSbit | LSbit) |
  560. ((len > ETH_ZLEN) ? len : ETH_ZLEN));
  561. }
  562. rtl_flush_tx_desc(&tpc->TxDescArray[entry]);
  563. RTL_W8(TxPoll, 0x40); /* set polling bit */
  564. tpc->cur_tx++;
  565. to = currticks() + TX_TIMEOUT;
  566. do {
  567. rtl_inval_tx_desc(&tpc->TxDescArray[entry]);
  568. } while ((le32_to_cpu(tpc->TxDescArray[entry].status) & OWNbit)
  569. && (currticks() < to)); /* wait */
  570. if (currticks() >= to) {
  571. #ifdef DEBUG_RTL8169_TX
  572. puts("tx timeout/error\n");
  573. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  574. #endif
  575. ret = -ETIMEDOUT;
  576. } else {
  577. #ifdef DEBUG_RTL8169_TX
  578. puts("tx done\n");
  579. #endif
  580. ret = 0;
  581. }
  582. /* Delay to make net console (nc) work properly */
  583. udelay(20);
  584. return ret;
  585. }
  586. #ifdef CONFIG_DM_ETH
  587. int rtl8169_eth_send(struct udevice *dev, void *packet, int length)
  588. {
  589. struct rtl8169_private *priv = dev_get_priv(dev);
  590. return rtl_send_common(dev, priv->iobase, packet, length);
  591. }
  592. #else
  593. static int rtl_send(struct eth_device *dev, void *packet, int length)
  594. {
  595. return rtl_send_common((pci_dev_t)(unsigned long)dev->priv,
  596. dev->iobase, packet, length);
  597. }
  598. #endif
  599. static void rtl8169_set_rx_mode(void)
  600. {
  601. u32 mc_filter[2]; /* Multicast hash filter */
  602. int rx_mode;
  603. u32 tmp = 0;
  604. #ifdef DEBUG_RTL8169
  605. printf ("%s\n", __FUNCTION__);
  606. #endif
  607. /* IFF_ALLMULTI */
  608. /* Too many to filter perfectly -- accept all multicasts. */
  609. rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
  610. mc_filter[1] = mc_filter[0] = 0xffffffff;
  611. tmp = rtl8169_rx_config | rx_mode | (RTL_R32(RxConfig) &
  612. rtl_chip_info[tpc->chipset].RxConfigMask);
  613. RTL_W32(RxConfig, tmp);
  614. RTL_W32(MAR0 + 0, mc_filter[0]);
  615. RTL_W32(MAR0 + 4, mc_filter[1]);
  616. }
  617. #ifdef CONFIG_DM_ETH
  618. static void rtl8169_hw_start(struct udevice *dev)
  619. #else
  620. static void rtl8169_hw_start(pci_dev_t dev)
  621. #endif
  622. {
  623. u32 i;
  624. #ifdef DEBUG_RTL8169
  625. int stime = currticks();
  626. printf ("%s\n", __FUNCTION__);
  627. #endif
  628. #if 0
  629. /* Soft reset the chip. */
  630. RTL_W8(ChipCmd, CmdReset);
  631. /* Check that the chip has finished the reset. */
  632. for (i = 1000; i > 0; i--) {
  633. if ((RTL_R8(ChipCmd) & CmdReset) == 0)
  634. break;
  635. else
  636. udelay(10);
  637. }
  638. #endif
  639. RTL_W8(Cfg9346, Cfg9346_Unlock);
  640. /* RTL-8169sb/8110sb or previous version */
  641. if (tpc->chipset <= 5)
  642. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  643. RTL_W8(EarlyTxThres, EarlyTxThld);
  644. /* For gigabit rtl8169 */
  645. RTL_W16(RxMaxSize, RxPacketMaxSize);
  646. /* Set Rx Config register */
  647. i = rtl8169_rx_config | (RTL_R32(RxConfig) &
  648. rtl_chip_info[tpc->chipset].RxConfigMask);
  649. RTL_W32(RxConfig, i);
  650. /* Set DMA burst size and Interframe Gap Time */
  651. RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
  652. (InterFrameGap << TxInterFrameGapShift));
  653. tpc->cur_rx = 0;
  654. #ifdef CONFIG_DM_ETH
  655. RTL_W32(TxDescStartAddrLow, dm_pci_mem_to_phys(dev,
  656. (pci_addr_t)(unsigned long)tpc->TxDescArray));
  657. #else
  658. RTL_W32(TxDescStartAddrLow, pci_mem_to_phys(dev,
  659. (pci_addr_t)(unsigned long)tpc->TxDescArray));
  660. #endif
  661. RTL_W32(TxDescStartAddrHigh, (unsigned long)0);
  662. #ifdef CONFIG_DM_ETH
  663. RTL_W32(RxDescStartAddrLow, dm_pci_mem_to_phys(
  664. dev, (pci_addr_t)(unsigned long)tpc->RxDescArray));
  665. #else
  666. RTL_W32(RxDescStartAddrLow, pci_mem_to_phys(
  667. dev, (pci_addr_t)(unsigned long)tpc->RxDescArray));
  668. #endif
  669. RTL_W32(RxDescStartAddrHigh, (unsigned long)0);
  670. /* RTL-8169sc/8110sc or later version */
  671. if (tpc->chipset > 5)
  672. RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
  673. RTL_W8(Cfg9346, Cfg9346_Lock);
  674. udelay(10);
  675. RTL_W32(RxMissed, 0);
  676. rtl8169_set_rx_mode();
  677. /* no early-rx interrupts */
  678. RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
  679. #ifdef DEBUG_RTL8169
  680. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  681. #endif
  682. }
  683. #ifdef CONFIG_DM_ETH
  684. static void rtl8169_init_ring(struct udevice *dev)
  685. #else
  686. static void rtl8169_init_ring(pci_dev_t dev)
  687. #endif
  688. {
  689. int i;
  690. #ifdef DEBUG_RTL8169
  691. int stime = currticks();
  692. printf ("%s\n", __FUNCTION__);
  693. #endif
  694. tpc->cur_rx = 0;
  695. tpc->cur_tx = 0;
  696. tpc->dirty_tx = 0;
  697. memset(tpc->TxDescArray, 0x0, NUM_TX_DESC * sizeof(struct TxDesc));
  698. memset(tpc->RxDescArray, 0x0, NUM_RX_DESC * sizeof(struct RxDesc));
  699. for (i = 0; i < NUM_TX_DESC; i++) {
  700. tpc->Tx_skbuff[i] = &txb[i];
  701. }
  702. for (i = 0; i < NUM_RX_DESC; i++) {
  703. if (i == (NUM_RX_DESC - 1))
  704. tpc->RxDescArray[i].status =
  705. cpu_to_le32((OWNbit | EORbit) + RX_BUF_SIZE);
  706. else
  707. tpc->RxDescArray[i].status =
  708. cpu_to_le32(OWNbit + RX_BUF_SIZE);
  709. tpc->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
  710. #ifdef CONFIG_DM_ETH
  711. tpc->RxDescArray[i].buf_addr = cpu_to_le32(dm_pci_mem_to_phys(
  712. dev, (pci_addr_t)(unsigned long)tpc->RxBufferRing[i]));
  713. #else
  714. tpc->RxDescArray[i].buf_addr = cpu_to_le32(pci_mem_to_phys(
  715. dev, (pci_addr_t)(unsigned long)tpc->RxBufferRing[i]));
  716. #endif
  717. rtl_flush_rx_desc(&tpc->RxDescArray[i]);
  718. }
  719. #ifdef DEBUG_RTL8169
  720. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  721. #endif
  722. }
  723. #ifdef CONFIG_DM_ETH
  724. static void rtl8169_common_start(struct udevice *dev, unsigned char *enetaddr,
  725. unsigned long dev_iobase)
  726. #else
  727. static void rtl8169_common_start(pci_dev_t dev, unsigned char *enetaddr,
  728. unsigned long dev_iobase)
  729. #endif
  730. {
  731. int i;
  732. #ifdef DEBUG_RTL8169
  733. int stime = currticks();
  734. printf ("%s\n", __FUNCTION__);
  735. #endif
  736. ioaddr = dev_iobase;
  737. rtl8169_init_ring(dev);
  738. rtl8169_hw_start(dev);
  739. /* Construct a perfect filter frame with the mac address as first match
  740. * and broadcast for all others */
  741. for (i = 0; i < 192; i++)
  742. txb[i] = 0xFF;
  743. txb[0] = enetaddr[0];
  744. txb[1] = enetaddr[1];
  745. txb[2] = enetaddr[2];
  746. txb[3] = enetaddr[3];
  747. txb[4] = enetaddr[4];
  748. txb[5] = enetaddr[5];
  749. #ifdef DEBUG_RTL8169
  750. printf("%s elapsed time : %lu\n", __func__, currticks()-stime);
  751. #endif
  752. }
  753. #ifdef CONFIG_DM_ETH
  754. static int rtl8169_eth_start(struct udevice *dev)
  755. {
  756. struct eth_pdata *plat = dev_get_platdata(dev);
  757. struct rtl8169_private *priv = dev_get_priv(dev);
  758. rtl8169_common_start(dev, plat->enetaddr, priv->iobase);
  759. return 0;
  760. }
  761. #else
  762. /**************************************************************************
  763. RESET - Finish setting up the ethernet interface
  764. ***************************************************************************/
  765. static int rtl_reset(struct eth_device *dev, bd_t *bis)
  766. {
  767. rtl8169_common_start((pci_dev_t)(unsigned long)dev->priv,
  768. dev->enetaddr, dev->iobase);
  769. return 0;
  770. }
  771. #endif /* nCONFIG_DM_ETH */
  772. static void rtl_halt_common(unsigned long dev_iobase)
  773. {
  774. int i;
  775. #ifdef DEBUG_RTL8169
  776. printf ("%s\n", __FUNCTION__);
  777. #endif
  778. ioaddr = dev_iobase;
  779. /* Stop the chip's Tx and Rx DMA processes. */
  780. RTL_W8(ChipCmd, 0x00);
  781. /* Disable interrupts by clearing the interrupt mask. */
  782. RTL_W16(IntrMask, 0x0000);
  783. RTL_W32(RxMissed, 0);
  784. for (i = 0; i < NUM_RX_DESC; i++) {
  785. tpc->RxBufferRing[i] = NULL;
  786. }
  787. }
  788. #ifdef CONFIG_DM_ETH
  789. void rtl8169_eth_stop(struct udevice *dev)
  790. {
  791. struct rtl8169_private *priv = dev_get_priv(dev);
  792. rtl_halt_common(priv->iobase);
  793. }
  794. #else
  795. /**************************************************************************
  796. HALT - Turn off ethernet interface
  797. ***************************************************************************/
  798. static void rtl_halt(struct eth_device *dev)
  799. {
  800. rtl_halt_common(dev->iobase);
  801. }
  802. #endif
  803. /**************************************************************************
  804. INIT - Look for an adapter, this routine's visible to the outside
  805. ***************************************************************************/
  806. #define board_found 1
  807. #define valid_link 0
  808. static int rtl_init(unsigned long dev_ioaddr, const char *name,
  809. unsigned char *enetaddr)
  810. {
  811. static int board_idx = -1;
  812. int i, rc;
  813. int option = -1, Cap10_100 = 0, Cap1000 = 0;
  814. #ifdef DEBUG_RTL8169
  815. printf ("%s\n", __FUNCTION__);
  816. #endif
  817. ioaddr = dev_ioaddr;
  818. board_idx++;
  819. /* point to private storage */
  820. tpc = &tpx;
  821. rc = rtl8169_init_board(ioaddr, name);
  822. if (rc)
  823. return rc;
  824. /* Get MAC address. FIXME: read EEPROM */
  825. for (i = 0; i < MAC_ADDR_LEN; i++)
  826. enetaddr[i] = RTL_R8(MAC0 + i);
  827. #ifdef DEBUG_RTL8169
  828. printf("chipset = %d\n", tpc->chipset);
  829. printf("MAC Address");
  830. for (i = 0; i < MAC_ADDR_LEN; i++)
  831. printf(":%02x", enetaddr[i]);
  832. putc('\n');
  833. #endif
  834. #ifdef DEBUG_RTL8169
  835. /* Print out some hardware info */
  836. printf("%s: at ioaddr 0x%lx\n", name, ioaddr);
  837. #endif
  838. /* if TBI is not endbled */
  839. if (!(RTL_R8(PHYstatus) & TBI_Enable)) {
  840. int val = mdio_read(PHY_AUTO_NEGO_REG);
  841. option = (board_idx >= MAX_UNITS) ? 0 : media[board_idx];
  842. /* Force RTL8169 in 10/100/1000 Full/Half mode. */
  843. if (option > 0) {
  844. #ifdef DEBUG_RTL8169
  845. printf("%s: Force-mode Enabled.\n", name);
  846. #endif
  847. Cap10_100 = 0, Cap1000 = 0;
  848. switch (option) {
  849. case _10_Half:
  850. Cap10_100 = PHY_Cap_10_Half;
  851. Cap1000 = PHY_Cap_Null;
  852. break;
  853. case _10_Full:
  854. Cap10_100 = PHY_Cap_10_Full;
  855. Cap1000 = PHY_Cap_Null;
  856. break;
  857. case _100_Half:
  858. Cap10_100 = PHY_Cap_100_Half;
  859. Cap1000 = PHY_Cap_Null;
  860. break;
  861. case _100_Full:
  862. Cap10_100 = PHY_Cap_100_Full;
  863. Cap1000 = PHY_Cap_Null;
  864. break;
  865. case _1000_Full:
  866. Cap10_100 = PHY_Cap_Null;
  867. Cap1000 = PHY_Cap_1000_Full;
  868. break;
  869. default:
  870. break;
  871. }
  872. mdio_write(PHY_AUTO_NEGO_REG, Cap10_100 | (val & 0x1F)); /* leave PHY_AUTO_NEGO_REG bit4:0 unchanged */
  873. mdio_write(PHY_1000_CTRL_REG, Cap1000);
  874. } else {
  875. #ifdef DEBUG_RTL8169
  876. printf("%s: Auto-negotiation Enabled.\n",
  877. name);
  878. #endif
  879. /* enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged */
  880. mdio_write(PHY_AUTO_NEGO_REG,
  881. PHY_Cap_10_Half | PHY_Cap_10_Full |
  882. PHY_Cap_100_Half | PHY_Cap_100_Full |
  883. (val & 0x1F));
  884. /* enable 1000 Full Mode */
  885. mdio_write(PHY_1000_CTRL_REG, PHY_Cap_1000_Full);
  886. }
  887. /* Enable auto-negotiation and restart auto-nigotiation */
  888. mdio_write(PHY_CTRL_REG,
  889. PHY_Enable_Auto_Nego | PHY_Restart_Auto_Nego);
  890. udelay(100);
  891. /* wait for auto-negotiation process */
  892. for (i = 10000; i > 0; i--) {
  893. /* check if auto-negotiation complete */
  894. if (mdio_read(PHY_STAT_REG) & PHY_Auto_Nego_Comp) {
  895. udelay(100);
  896. option = RTL_R8(PHYstatus);
  897. if (option & _1000bpsF) {
  898. #ifdef DEBUG_RTL8169
  899. printf("%s: 1000Mbps Full-duplex operation.\n",
  900. name);
  901. #endif
  902. } else {
  903. #ifdef DEBUG_RTL8169
  904. printf("%s: %sMbps %s-duplex operation.\n",
  905. name,
  906. (option & _100bps) ? "100" :
  907. "10",
  908. (option & FullDup) ? "Full" :
  909. "Half");
  910. #endif
  911. }
  912. break;
  913. } else {
  914. udelay(100);
  915. }
  916. } /* end for-loop to wait for auto-negotiation process */
  917. } else {
  918. udelay(100);
  919. #ifdef DEBUG_RTL8169
  920. printf
  921. ("%s: 1000Mbps Full-duplex operation, TBI Link %s!\n",
  922. name,
  923. (RTL_R32(TBICSR) & TBILinkOK) ? "OK" : "Failed");
  924. #endif
  925. }
  926. tpc->RxDescArray = rtl_alloc_descs(NUM_RX_DESC);
  927. if (!tpc->RxDescArray)
  928. return -ENOMEM;
  929. tpc->TxDescArray = rtl_alloc_descs(NUM_TX_DESC);
  930. if (!tpc->TxDescArray)
  931. return -ENOMEM;
  932. return 0;
  933. }
  934. #ifndef CONFIG_DM_ETH
  935. int rtl8169_initialize(bd_t *bis)
  936. {
  937. pci_dev_t devno;
  938. int card_number = 0;
  939. struct eth_device *dev;
  940. u32 iobase;
  941. int idx=0;
  942. while(1){
  943. unsigned int region;
  944. u16 device;
  945. int err;
  946. /* Find RTL8169 */
  947. if ((devno = pci_find_devices(supported, idx++)) < 0)
  948. break;
  949. pci_read_config_word(devno, PCI_DEVICE_ID, &device);
  950. switch (device) {
  951. case 0x8168:
  952. region = 2;
  953. break;
  954. default:
  955. region = 1;
  956. break;
  957. }
  958. pci_read_config_dword(devno, PCI_BASE_ADDRESS_0 + (region * 4), &iobase);
  959. iobase &= ~0xf;
  960. debug ("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
  961. dev = (struct eth_device *)malloc(sizeof *dev);
  962. if (!dev) {
  963. printf("Can not allocate memory of rtl8169\n");
  964. break;
  965. }
  966. memset(dev, 0, sizeof(*dev));
  967. sprintf (dev->name, "RTL8169#%d", card_number);
  968. dev->priv = (void *)(unsigned long)devno;
  969. dev->iobase = (int)pci_mem_to_phys(devno, iobase);
  970. dev->init = rtl_reset;
  971. dev->halt = rtl_halt;
  972. dev->send = rtl_send;
  973. dev->recv = rtl_recv;
  974. err = rtl_init(dev->iobase, dev->name, dev->enetaddr);
  975. if (err < 0) {
  976. printf(pr_fmt("failed to initialize card: %d\n"), err);
  977. free(dev);
  978. continue;
  979. }
  980. eth_register (dev);
  981. card_number++;
  982. }
  983. return card_number;
  984. }
  985. #endif
  986. #ifdef CONFIG_DM_ETH
  987. static int rtl8169_eth_probe(struct udevice *dev)
  988. {
  989. struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
  990. struct rtl8169_private *priv = dev_get_priv(dev);
  991. struct eth_pdata *plat = dev_get_platdata(dev);
  992. u32 iobase;
  993. int region;
  994. int ret;
  995. debug("rtl8169: REALTEK RTL8169 @0x%x\n", iobase);
  996. switch (pplat->device) {
  997. case 0x8168:
  998. region = 2;
  999. break;
  1000. default:
  1001. region = 1;
  1002. break;
  1003. }
  1004. dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0 + region * 4, &iobase);
  1005. iobase &= ~0xf;
  1006. priv->iobase = (int)dm_pci_mem_to_phys(dev, iobase);
  1007. ret = rtl_init(priv->iobase, dev->name, plat->enetaddr);
  1008. if (ret < 0) {
  1009. printf(pr_fmt("failed to initialize card: %d\n"), ret);
  1010. return ret;
  1011. }
  1012. return 0;
  1013. }
  1014. static const struct eth_ops rtl8169_eth_ops = {
  1015. .start = rtl8169_eth_start,
  1016. .send = rtl8169_eth_send,
  1017. .recv = rtl8169_eth_recv,
  1018. .stop = rtl8169_eth_stop,
  1019. };
  1020. static const struct udevice_id rtl8169_eth_ids[] = {
  1021. { .compatible = "realtek,rtl8169" },
  1022. { }
  1023. };
  1024. U_BOOT_DRIVER(eth_rtl8169) = {
  1025. .name = "eth_rtl8169",
  1026. .id = UCLASS_ETH,
  1027. .of_match = rtl8169_eth_ids,
  1028. .probe = rtl8169_eth_probe,
  1029. .ops = &rtl8169_eth_ops,
  1030. .priv_auto_alloc_size = sizeof(struct rtl8169_private),
  1031. .platdata_auto_alloc_size = sizeof(struct eth_pdata),
  1032. };
  1033. U_BOOT_PCI_DEVICE(eth_rtl8169, supported);
  1034. #endif