mcffec.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2007 Freescale Semiconductor, Inc.
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <malloc.h>
  28. #include <command.h>
  29. #include <net.h>
  30. #include <netdev.h>
  31. #include <miiphy.h>
  32. #include <asm/fec.h>
  33. #include <asm/immap.h>
  34. #undef ET_DEBUG
  35. #undef MII_DEBUG
  36. /* Ethernet Transmit and Receive Buffers */
  37. #define DBUF_LENGTH 1520
  38. #define TX_BUF_CNT 2
  39. #define PKT_MAXBUF_SIZE 1518
  40. #define PKT_MINBUF_SIZE 64
  41. #define PKT_MAXBLR_SIZE 1520
  42. #define LAST_PKTBUFSRX PKTBUFSRX - 1
  43. #define BD_ENET_RX_W_E (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY)
  44. #define BD_ENET_TX_RDY_LST (BD_ENET_TX_READY | BD_ENET_TX_LAST)
  45. DECLARE_GLOBAL_DATA_PTR;
  46. struct fec_info_s fec_info[] = {
  47. #ifdef CONFIG_SYS_FEC0_IOBASE
  48. {
  49. 0, /* index */
  50. CONFIG_SYS_FEC0_IOBASE, /* io base */
  51. CONFIG_SYS_FEC0_PINMUX, /* gpio pin muxing */
  52. CONFIG_SYS_FEC0_MIIBASE, /* mii base */
  53. -1, /* phy_addr */
  54. 0, /* duplex and speed */
  55. 0, /* phy name */
  56. 0, /* phyname init */
  57. 0, /* RX BD */
  58. 0, /* TX BD */
  59. 0, /* rx Index */
  60. 0, /* tx Index */
  61. 0, /* tx buffer */
  62. 0, /* initialized flag */
  63. (struct fec_info_s *)-1,
  64. },
  65. #endif
  66. #ifdef CONFIG_SYS_FEC1_IOBASE
  67. {
  68. 1, /* index */
  69. CONFIG_SYS_FEC1_IOBASE, /* io base */
  70. CONFIG_SYS_FEC1_PINMUX, /* gpio pin muxing */
  71. CONFIG_SYS_FEC1_MIIBASE, /* mii base */
  72. -1, /* phy_addr */
  73. 0, /* duplex and speed */
  74. 0, /* phy name */
  75. 0, /* phy name init */
  76. #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
  77. (cbd_t *)DBUF_LENGTH, /* RX BD */
  78. #else
  79. 0, /* RX BD */
  80. #endif
  81. 0, /* TX BD */
  82. 0, /* rx Index */
  83. 0, /* tx Index */
  84. 0, /* tx buffer */
  85. 0, /* initialized flag */
  86. (struct fec_info_s *)-1,
  87. }
  88. #endif
  89. };
  90. int fec_recv(struct eth_device *dev);
  91. int fec_init(struct eth_device *dev, bd_t * bd);
  92. void fec_halt(struct eth_device *dev);
  93. void fec_reset(struct eth_device *dev);
  94. void setFecDuplexSpeed(volatile fec_t * fecp, bd_t * bd, int dup_spd)
  95. {
  96. if ((dup_spd >> 16) == FULL) {
  97. /* Set maximum frame length */
  98. fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | FEC_RCR_MII_MODE |
  99. FEC_RCR_PROM | 0x100;
  100. fecp->tcr = FEC_TCR_FDEN;
  101. } else {
  102. /* Half duplex mode */
  103. fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) |
  104. FEC_RCR_MII_MODE | FEC_RCR_DRT;
  105. fecp->tcr &= ~FEC_TCR_FDEN;
  106. }
  107. if ((dup_spd & 0xFFFF) == _100BASET) {
  108. #ifdef CONFIG_MCF5445x
  109. fecp->rcr &= ~0x200; /* disabled 10T base */
  110. #endif
  111. #ifdef MII_DEBUG
  112. printf("100Mbps\n");
  113. #endif
  114. bd->bi_ethspeed = 100;
  115. } else {
  116. #ifdef CONFIG_MCF5445x
  117. fecp->rcr |= 0x200; /* enabled 10T base */
  118. #endif
  119. #ifdef MII_DEBUG
  120. printf("10Mbps\n");
  121. #endif
  122. bd->bi_ethspeed = 10;
  123. }
  124. }
  125. static int fec_send(struct eth_device *dev, void *packet, int length)
  126. {
  127. struct fec_info_s *info = dev->priv;
  128. volatile fec_t *fecp = (fec_t *) (info->iobase);
  129. int j, rc;
  130. u16 phyStatus;
  131. miiphy_read(dev->name, info->phy_addr, MII_BMSR, &phyStatus);
  132. /* section 16.9.23.3
  133. * Wait for ready
  134. */
  135. j = 0;
  136. while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) &&
  137. (j < MCFFEC_TOUT_LOOP)) {
  138. udelay(1);
  139. j++;
  140. }
  141. if (j >= MCFFEC_TOUT_LOOP) {
  142. printf("TX not ready\n");
  143. }
  144. info->txbd[info->txIdx].cbd_bufaddr = (uint) packet;
  145. info->txbd[info->txIdx].cbd_datlen = length;
  146. info->txbd[info->txIdx].cbd_sc |= BD_ENET_TX_RDY_LST;
  147. /* Activate transmit Buffer Descriptor polling */
  148. fecp->tdar = 0x01000000; /* Descriptor polling active */
  149. #ifndef CONFIG_SYS_FEC_BUF_USE_SRAM
  150. /*
  151. * FEC unable to initial transmit data packet.
  152. * A nop will ensure the descriptor polling active completed.
  153. * CF Internal RAM has shorter cycle access than DRAM. If use
  154. * DRAM as Buffer descriptor and data, a nop is a must.
  155. * Affect only V2 and V3.
  156. */
  157. __asm__ ("nop");
  158. #endif
  159. #ifdef CONFIG_SYS_UNIFY_CACHE
  160. icache_invalid();
  161. #endif
  162. j = 0;
  163. while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) &&
  164. (j < MCFFEC_TOUT_LOOP)) {
  165. udelay(1);
  166. j++;
  167. }
  168. if (j >= MCFFEC_TOUT_LOOP) {
  169. printf("TX timeout\n");
  170. }
  171. #ifdef ET_DEBUG
  172. printf("%s[%d] %s: cycles: %d status: %x retry cnt: %d\n",
  173. __FILE__, __LINE__, __FUNCTION__, j,
  174. info->txbd[info->txIdx].cbd_sc,
  175. (info->txbd[info->txIdx].cbd_sc & 0x003C) >> 2);
  176. #endif
  177. /* return only status bits */
  178. rc = (info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_STATS);
  179. info->txIdx = (info->txIdx + 1) % TX_BUF_CNT;
  180. return rc;
  181. }
  182. int fec_recv(struct eth_device *dev)
  183. {
  184. struct fec_info_s *info = dev->priv;
  185. volatile fec_t *fecp = (fec_t *) (info->iobase);
  186. int length;
  187. for (;;) {
  188. #ifndef CONFIG_SYS_FEC_BUF_USE_SRAM
  189. #endif
  190. #ifdef CONFIG_SYS_UNIFY_CACHE
  191. icache_invalid();
  192. #endif
  193. /* section 16.9.23.2 */
  194. if (info->rxbd[info->rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
  195. length = -1;
  196. break; /* nothing received - leave for() loop */
  197. }
  198. length = info->rxbd[info->rxIdx].cbd_datlen;
  199. if (info->rxbd[info->rxIdx].cbd_sc & 0x003f) {
  200. printf("%s[%d] err: %x\n",
  201. __FUNCTION__, __LINE__,
  202. info->rxbd[info->rxIdx].cbd_sc);
  203. #ifdef ET_DEBUG
  204. printf("%s[%d] err: %x\n",
  205. __FUNCTION__, __LINE__,
  206. info->rxbd[info->rxIdx].cbd_sc);
  207. #endif
  208. } else {
  209. length -= 4;
  210. /* Pass the packet up to the protocol layers. */
  211. NetReceive(NetRxPackets[info->rxIdx], length);
  212. fecp->eir |= FEC_EIR_RXF;
  213. }
  214. /* Give the buffer back to the FEC. */
  215. info->rxbd[info->rxIdx].cbd_datlen = 0;
  216. /* wrap around buffer index when necessary */
  217. if (info->rxIdx == LAST_PKTBUFSRX) {
  218. info->rxbd[PKTBUFSRX - 1].cbd_sc = BD_ENET_RX_W_E;
  219. info->rxIdx = 0;
  220. } else {
  221. info->rxbd[info->rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
  222. info->rxIdx++;
  223. }
  224. /* Try to fill Buffer Descriptors */
  225. fecp->rdar = 0x01000000; /* Descriptor polling active */
  226. }
  227. return length;
  228. }
  229. #ifdef ET_DEBUG
  230. void dbgFecRegs(struct eth_device *dev)
  231. {
  232. struct fec_info_s *info = dev->priv;
  233. volatile fec_t *fecp = (fec_t *) (info->iobase);
  234. printf("=====\n");
  235. printf("ievent %x - %x\n", (int)&fecp->eir, fecp->eir);
  236. printf("imask %x - %x\n", (int)&fecp->eimr, fecp->eimr);
  237. printf("r_des_active %x - %x\n", (int)&fecp->rdar, fecp->rdar);
  238. printf("x_des_active %x - %x\n", (int)&fecp->tdar, fecp->tdar);
  239. printf("ecntrl %x - %x\n", (int)&fecp->ecr, fecp->ecr);
  240. printf("mii_mframe %x - %x\n", (int)&fecp->mmfr, fecp->mmfr);
  241. printf("mii_speed %x - %x\n", (int)&fecp->mscr, fecp->mscr);
  242. printf("mii_ctrlstat %x - %x\n", (int)&fecp->mibc, fecp->mibc);
  243. printf("r_cntrl %x - %x\n", (int)&fecp->rcr, fecp->rcr);
  244. printf("x_cntrl %x - %x\n", (int)&fecp->tcr, fecp->tcr);
  245. printf("padr_l %x - %x\n", (int)&fecp->palr, fecp->palr);
  246. printf("padr_u %x - %x\n", (int)&fecp->paur, fecp->paur);
  247. printf("op_pause %x - %x\n", (int)&fecp->opd, fecp->opd);
  248. printf("iadr_u %x - %x\n", (int)&fecp->iaur, fecp->iaur);
  249. printf("iadr_l %x - %x\n", (int)&fecp->ialr, fecp->ialr);
  250. printf("gadr_u %x - %x\n", (int)&fecp->gaur, fecp->gaur);
  251. printf("gadr_l %x - %x\n", (int)&fecp->galr, fecp->galr);
  252. printf("x_wmrk %x - %x\n", (int)&fecp->tfwr, fecp->tfwr);
  253. printf("r_bound %x - %x\n", (int)&fecp->frbr, fecp->frbr);
  254. printf("r_fstart %x - %x\n", (int)&fecp->frsr, fecp->frsr);
  255. printf("r_drng %x - %x\n", (int)&fecp->erdsr, fecp->erdsr);
  256. printf("x_drng %x - %x\n", (int)&fecp->etdsr, fecp->etdsr);
  257. printf("r_bufsz %x - %x\n", (int)&fecp->emrbr, fecp->emrbr);
  258. printf("\n");
  259. printf("rmon_t_drop %x - %x\n", (int)&fecp->rmon_t_drop,
  260. fecp->rmon_t_drop);
  261. printf("rmon_t_packets %x - %x\n", (int)&fecp->rmon_t_packets,
  262. fecp->rmon_t_packets);
  263. printf("rmon_t_bc_pkt %x - %x\n", (int)&fecp->rmon_t_bc_pkt,
  264. fecp->rmon_t_bc_pkt);
  265. printf("rmon_t_mc_pkt %x - %x\n", (int)&fecp->rmon_t_mc_pkt,
  266. fecp->rmon_t_mc_pkt);
  267. printf("rmon_t_crc_align %x - %x\n", (int)&fecp->rmon_t_crc_align,
  268. fecp->rmon_t_crc_align);
  269. printf("rmon_t_undersize %x - %x\n", (int)&fecp->rmon_t_undersize,
  270. fecp->rmon_t_undersize);
  271. printf("rmon_t_oversize %x - %x\n", (int)&fecp->rmon_t_oversize,
  272. fecp->rmon_t_oversize);
  273. printf("rmon_t_frag %x - %x\n", (int)&fecp->rmon_t_frag,
  274. fecp->rmon_t_frag);
  275. printf("rmon_t_jab %x - %x\n", (int)&fecp->rmon_t_jab,
  276. fecp->rmon_t_jab);
  277. printf("rmon_t_col %x - %x\n", (int)&fecp->rmon_t_col,
  278. fecp->rmon_t_col);
  279. printf("rmon_t_p64 %x - %x\n", (int)&fecp->rmon_t_p64,
  280. fecp->rmon_t_p64);
  281. printf("rmon_t_p65to127 %x - %x\n", (int)&fecp->rmon_t_p65to127,
  282. fecp->rmon_t_p65to127);
  283. printf("rmon_t_p128to255 %x - %x\n", (int)&fecp->rmon_t_p128to255,
  284. fecp->rmon_t_p128to255);
  285. printf("rmon_t_p256to511 %x - %x\n", (int)&fecp->rmon_t_p256to511,
  286. fecp->rmon_t_p256to511);
  287. printf("rmon_t_p512to1023 %x - %x\n", (int)&fecp->rmon_t_p512to1023,
  288. fecp->rmon_t_p512to1023);
  289. printf("rmon_t_p1024to2047 %x - %x\n", (int)&fecp->rmon_t_p1024to2047,
  290. fecp->rmon_t_p1024to2047);
  291. printf("rmon_t_p_gte2048 %x - %x\n", (int)&fecp->rmon_t_p_gte2048,
  292. fecp->rmon_t_p_gte2048);
  293. printf("rmon_t_octets %x - %x\n", (int)&fecp->rmon_t_octets,
  294. fecp->rmon_t_octets);
  295. printf("\n");
  296. printf("ieee_t_drop %x - %x\n", (int)&fecp->ieee_t_drop,
  297. fecp->ieee_t_drop);
  298. printf("ieee_t_frame_ok %x - %x\n", (int)&fecp->ieee_t_frame_ok,
  299. fecp->ieee_t_frame_ok);
  300. printf("ieee_t_1col %x - %x\n", (int)&fecp->ieee_t_1col,
  301. fecp->ieee_t_1col);
  302. printf("ieee_t_mcol %x - %x\n", (int)&fecp->ieee_t_mcol,
  303. fecp->ieee_t_mcol);
  304. printf("ieee_t_def %x - %x\n", (int)&fecp->ieee_t_def,
  305. fecp->ieee_t_def);
  306. printf("ieee_t_lcol %x - %x\n", (int)&fecp->ieee_t_lcol,
  307. fecp->ieee_t_lcol);
  308. printf("ieee_t_excol %x - %x\n", (int)&fecp->ieee_t_excol,
  309. fecp->ieee_t_excol);
  310. printf("ieee_t_macerr %x - %x\n", (int)&fecp->ieee_t_macerr,
  311. fecp->ieee_t_macerr);
  312. printf("ieee_t_cserr %x - %x\n", (int)&fecp->ieee_t_cserr,
  313. fecp->ieee_t_cserr);
  314. printf("ieee_t_sqe %x - %x\n", (int)&fecp->ieee_t_sqe,
  315. fecp->ieee_t_sqe);
  316. printf("ieee_t_fdxfc %x - %x\n", (int)&fecp->ieee_t_fdxfc,
  317. fecp->ieee_t_fdxfc);
  318. printf("ieee_t_octets_ok %x - %x\n", (int)&fecp->ieee_t_octets_ok,
  319. fecp->ieee_t_octets_ok);
  320. printf("\n");
  321. printf("rmon_r_drop %x - %x\n", (int)&fecp->rmon_r_drop,
  322. fecp->rmon_r_drop);
  323. printf("rmon_r_packets %x - %x\n", (int)&fecp->rmon_r_packets,
  324. fecp->rmon_r_packets);
  325. printf("rmon_r_bc_pkt %x - %x\n", (int)&fecp->rmon_r_bc_pkt,
  326. fecp->rmon_r_bc_pkt);
  327. printf("rmon_r_mc_pkt %x - %x\n", (int)&fecp->rmon_r_mc_pkt,
  328. fecp->rmon_r_mc_pkt);
  329. printf("rmon_r_crc_align %x - %x\n", (int)&fecp->rmon_r_crc_align,
  330. fecp->rmon_r_crc_align);
  331. printf("rmon_r_undersize %x - %x\n", (int)&fecp->rmon_r_undersize,
  332. fecp->rmon_r_undersize);
  333. printf("rmon_r_oversize %x - %x\n", (int)&fecp->rmon_r_oversize,
  334. fecp->rmon_r_oversize);
  335. printf("rmon_r_frag %x - %x\n", (int)&fecp->rmon_r_frag,
  336. fecp->rmon_r_frag);
  337. printf("rmon_r_jab %x - %x\n", (int)&fecp->rmon_r_jab,
  338. fecp->rmon_r_jab);
  339. printf("rmon_r_p64 %x - %x\n", (int)&fecp->rmon_r_p64,
  340. fecp->rmon_r_p64);
  341. printf("rmon_r_p65to127 %x - %x\n", (int)&fecp->rmon_r_p65to127,
  342. fecp->rmon_r_p65to127);
  343. printf("rmon_r_p128to255 %x - %x\n", (int)&fecp->rmon_r_p128to255,
  344. fecp->rmon_r_p128to255);
  345. printf("rmon_r_p256to511 %x - %x\n", (int)&fecp->rmon_r_p256to511,
  346. fecp->rmon_r_p256to511);
  347. printf("rmon_r_p512to1023 %x - %x\n", (int)&fecp->rmon_r_p512to1023,
  348. fecp->rmon_r_p512to1023);
  349. printf("rmon_r_p1024to2047 %x - %x\n", (int)&fecp->rmon_r_p1024to2047,
  350. fecp->rmon_r_p1024to2047);
  351. printf("rmon_r_p_gte2048 %x - %x\n", (int)&fecp->rmon_r_p_gte2048,
  352. fecp->rmon_r_p_gte2048);
  353. printf("rmon_r_octets %x - %x\n", (int)&fecp->rmon_r_octets,
  354. fecp->rmon_r_octets);
  355. printf("\n");
  356. printf("ieee_r_drop %x - %x\n", (int)&fecp->ieee_r_drop,
  357. fecp->ieee_r_drop);
  358. printf("ieee_r_frame_ok %x - %x\n", (int)&fecp->ieee_r_frame_ok,
  359. fecp->ieee_r_frame_ok);
  360. printf("ieee_r_crc %x - %x\n", (int)&fecp->ieee_r_crc,
  361. fecp->ieee_r_crc);
  362. printf("ieee_r_align %x - %x\n", (int)&fecp->ieee_r_align,
  363. fecp->ieee_r_align);
  364. printf("ieee_r_macerr %x - %x\n", (int)&fecp->ieee_r_macerr,
  365. fecp->ieee_r_macerr);
  366. printf("ieee_r_fdxfc %x - %x\n", (int)&fecp->ieee_r_fdxfc,
  367. fecp->ieee_r_fdxfc);
  368. printf("ieee_r_octets_ok %x - %x\n", (int)&fecp->ieee_r_octets_ok,
  369. fecp->ieee_r_octets_ok);
  370. printf("\n\n\n");
  371. }
  372. #endif
  373. int fec_init(struct eth_device *dev, bd_t * bd)
  374. {
  375. struct fec_info_s *info = dev->priv;
  376. volatile fec_t *fecp = (fec_t *) (info->iobase);
  377. int i;
  378. uchar ea[6];
  379. fecpin_setclear(dev, 1);
  380. fec_reset(dev);
  381. #if defined(CONFIG_CMD_MII) || defined (CONFIG_MII) || \
  382. defined (CONFIG_SYS_DISCOVER_PHY)
  383. mii_init();
  384. setFecDuplexSpeed(fecp, bd, info->dup_spd);
  385. #else
  386. #ifndef CONFIG_SYS_DISCOVER_PHY
  387. setFecDuplexSpeed(fecp, bd, (FECDUPLEX << 16) | FECSPEED);
  388. #endif /* ifndef CONFIG_SYS_DISCOVER_PHY */
  389. #endif /* CONFIG_CMD_MII || CONFIG_MII */
  390. /* We use strictly polling mode only */
  391. fecp->eimr = 0;
  392. /* Clear any pending interrupt */
  393. fecp->eir = 0xffffffff;
  394. /* Set station address */
  395. if ((u32) fecp == CONFIG_SYS_FEC0_IOBASE) {
  396. #ifdef CONFIG_SYS_FEC1_IOBASE
  397. volatile fec_t *fecp1 = (fec_t *) (CONFIG_SYS_FEC1_IOBASE);
  398. eth_getenv_enetaddr("eth1addr", ea);
  399. fecp1->palr =
  400. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  401. fecp1->paur = (ea[4] << 24) | (ea[5] << 16);
  402. #endif
  403. eth_getenv_enetaddr("ethaddr", ea);
  404. fecp->palr =
  405. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  406. fecp->paur = (ea[4] << 24) | (ea[5] << 16);
  407. } else {
  408. #ifdef CONFIG_SYS_FEC0_IOBASE
  409. volatile fec_t *fecp0 = (fec_t *) (CONFIG_SYS_FEC0_IOBASE);
  410. eth_getenv_enetaddr("ethaddr", ea);
  411. fecp0->palr =
  412. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  413. fecp0->paur = (ea[4] << 24) | (ea[5] << 16);
  414. #endif
  415. #ifdef CONFIG_SYS_FEC1_IOBASE
  416. eth_getenv_enetaddr("eth1addr", ea);
  417. fecp->palr =
  418. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  419. fecp->paur = (ea[4] << 24) | (ea[5] << 16);
  420. #endif
  421. }
  422. /* Clear unicast address hash table */
  423. fecp->iaur = 0;
  424. fecp->ialr = 0;
  425. /* Clear multicast address hash table */
  426. fecp->gaur = 0;
  427. fecp->galr = 0;
  428. /* Set maximum receive buffer size. */
  429. fecp->emrbr = PKT_MAXBLR_SIZE;
  430. /*
  431. * Setup Buffers and Buffer Desriptors
  432. */
  433. info->rxIdx = 0;
  434. info->txIdx = 0;
  435. /*
  436. * Setup Receiver Buffer Descriptors (13.14.24.18)
  437. * Settings:
  438. * Empty, Wrap
  439. */
  440. for (i = 0; i < PKTBUFSRX; i++) {
  441. info->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
  442. info->rxbd[i].cbd_datlen = 0; /* Reset */
  443. info->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
  444. }
  445. info->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
  446. /*
  447. * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
  448. * Settings:
  449. * Last, Tx CRC
  450. */
  451. for (i = 0; i < TX_BUF_CNT; i++) {
  452. info->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
  453. info->txbd[i].cbd_datlen = 0; /* Reset */
  454. info->txbd[i].cbd_bufaddr = (uint) (&info->txbuf[0]);
  455. }
  456. info->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
  457. /* Set receive and transmit descriptor base */
  458. fecp->erdsr = (unsigned int)(&info->rxbd[0]);
  459. fecp->etdsr = (unsigned int)(&info->txbd[0]);
  460. /* Now enable the transmit and receive processing */
  461. fecp->ecr |= FEC_ECR_ETHER_EN;
  462. /* And last, try to fill Rx Buffer Descriptors */
  463. fecp->rdar = 0x01000000; /* Descriptor polling active */
  464. return 1;
  465. }
  466. void fec_reset(struct eth_device *dev)
  467. {
  468. struct fec_info_s *info = dev->priv;
  469. volatile fec_t *fecp = (fec_t *) (info->iobase);
  470. int i;
  471. fecp->ecr = FEC_ECR_RESET;
  472. for (i = 0; (fecp->ecr & FEC_ECR_RESET) && (i < FEC_RESET_DELAY); ++i) {
  473. udelay(1);
  474. }
  475. if (i == FEC_RESET_DELAY) {
  476. printf("FEC_RESET_DELAY timeout\n");
  477. }
  478. }
  479. void fec_halt(struct eth_device *dev)
  480. {
  481. struct fec_info_s *info = dev->priv;
  482. fec_reset(dev);
  483. fecpin_setclear(dev, 0);
  484. info->rxIdx = info->txIdx = 0;
  485. memset(info->rxbd, 0, PKTBUFSRX * sizeof(cbd_t));
  486. memset(info->txbd, 0, TX_BUF_CNT * sizeof(cbd_t));
  487. memset(info->txbuf, 0, DBUF_LENGTH);
  488. }
  489. int mcffec_initialize(bd_t * bis)
  490. {
  491. struct eth_device *dev;
  492. int i;
  493. #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
  494. u32 tmp = CONFIG_SYS_INIT_RAM_ADDR + 0x1000;
  495. #endif
  496. for (i = 0; i < sizeof(fec_info) / sizeof(fec_info[0]); i++) {
  497. dev =
  498. (struct eth_device *)memalign(CONFIG_SYS_CACHELINE_SIZE,
  499. sizeof *dev);
  500. if (dev == NULL)
  501. hang();
  502. memset(dev, 0, sizeof(*dev));
  503. sprintf(dev->name, "FEC%d", fec_info[i].index);
  504. dev->priv = &fec_info[i];
  505. dev->init = fec_init;
  506. dev->halt = fec_halt;
  507. dev->send = fec_send;
  508. dev->recv = fec_recv;
  509. /* setup Receive and Transmit buffer descriptor */
  510. #ifdef CONFIG_SYS_FEC_BUF_USE_SRAM
  511. fec_info[i].rxbd = (cbd_t *)((u32)fec_info[i].rxbd + tmp);
  512. tmp = (u32)fec_info[i].rxbd;
  513. fec_info[i].txbd =
  514. (cbd_t *)((u32)fec_info[i].txbd + tmp +
  515. (PKTBUFSRX * sizeof(cbd_t)));
  516. tmp = (u32)fec_info[i].txbd;
  517. fec_info[i].txbuf =
  518. (char *)((u32)fec_info[i].txbuf + tmp +
  519. (CONFIG_SYS_TX_ETH_BUFFER * sizeof(cbd_t)));
  520. tmp = (u32)fec_info[i].txbuf;
  521. #else
  522. fec_info[i].rxbd =
  523. (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE,
  524. (PKTBUFSRX * sizeof(cbd_t)));
  525. fec_info[i].txbd =
  526. (cbd_t *) memalign(CONFIG_SYS_CACHELINE_SIZE,
  527. (TX_BUF_CNT * sizeof(cbd_t)));
  528. fec_info[i].txbuf =
  529. (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, DBUF_LENGTH);
  530. #endif
  531. #ifdef ET_DEBUG
  532. printf("rxbd %x txbd %x\n",
  533. (int)fec_info[i].rxbd, (int)fec_info[i].txbd);
  534. #endif
  535. fec_info[i].phy_name = (char *)memalign(CONFIG_SYS_CACHELINE_SIZE, 32);
  536. eth_register(dev);
  537. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  538. miiphy_register(dev->name,
  539. mcffec_miiphy_read, mcffec_miiphy_write);
  540. #endif
  541. if (i > 0)
  542. fec_info[i - 1].next = &fec_info[i];
  543. }
  544. fec_info[i - 1].next = &fec_info[0];
  545. /* default speed */
  546. bis->bi_ethspeed = 10;
  547. return 0;
  548. }