mcffec.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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 <asm/fec.h>
  29. #include <asm/immap.h>
  30. #include <command.h>
  31. #include <net.h>
  32. #include <miiphy.h>
  33. #undef ET_DEBUG
  34. #undef MII_DEBUG
  35. /* Ethernet Transmit and Receive Buffers */
  36. #define DBUF_LENGTH 1520
  37. #define TX_BUF_CNT 2
  38. #define PKT_MAXBUF_SIZE 1518
  39. #define PKT_MINBUF_SIZE 64
  40. #define PKT_MAXBLR_SIZE 1520
  41. #define LAST_PKTBUFSRX PKTBUFSRX - 1
  42. #define BD_ENET_RX_W_E (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY)
  43. #define BD_ENET_TX_RDY_LST (BD_ENET_TX_READY | BD_ENET_TX_LAST)
  44. DECLARE_GLOBAL_DATA_PTR;
  45. struct fec_info_s fec_info[] = {
  46. #ifdef CFG_FEC0_IOBASE
  47. {
  48. 0, /* index */
  49. CFG_FEC0_IOBASE, /* io base */
  50. CFG_FEC0_PINMUX, /* gpio pin muxing */
  51. CFG_FEC0_MIIBASE, /* mii base */
  52. -1, /* phy_addr */
  53. 0, /* duplex and speed */
  54. 0, /* phy name */
  55. 0, /* phyname init */
  56. 0, /* RX BD */
  57. 0, /* TX BD */
  58. 0, /* rx Index */
  59. 0, /* tx Index */
  60. 0, /* tx buffer */
  61. 0, /* initialized flag */
  62. },
  63. #endif
  64. #ifdef CFG_FEC1_IOBASE
  65. {
  66. 1, /* index */
  67. CFG_FEC1_IOBASE, /* io base */
  68. CFG_FEC1_PINMUX, /* gpio pin muxing */
  69. CFG_FEC1_MIIBASE, /* mii base */
  70. -1, /* phy_addr */
  71. 0, /* duplex and speed */
  72. 0, /* phy name */
  73. 0, /* phy name init */
  74. 0, /* RX BD */
  75. 0, /* TX BD */
  76. 0, /* rx Index */
  77. 0, /* tx Index */
  78. 0, /* tx buffer */
  79. 0, /* initialized flag */
  80. }
  81. #endif
  82. };
  83. int fec_send(struct eth_device *dev, volatile void *packet, int length);
  84. int fec_recv(struct eth_device *dev);
  85. int fec_init(struct eth_device *dev, bd_t * bd);
  86. void fec_halt(struct eth_device *dev);
  87. void fec_reset(struct eth_device *dev);
  88. extern int fecpin_setclear(struct eth_device *dev, int setclear);
  89. #ifdef CFG_DISCOVER_PHY
  90. extern void __mii_init(void);
  91. extern uint mii_send(uint mii_cmd);
  92. extern int mii_discover_phy(struct eth_device *dev);
  93. extern int mcffec_miiphy_read(char *devname, unsigned char addr,
  94. unsigned char reg, unsigned short *value);
  95. extern int mcffec_miiphy_write(char *devname, unsigned char addr,
  96. unsigned char reg, unsigned short value);
  97. #endif
  98. void setFecDuplexSpeed(volatile fec_t * fecp, bd_t * bd, int dup_spd)
  99. {
  100. if ((dup_spd >> 16) == FULL) {
  101. /* Set maximum frame length */
  102. fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | FEC_RCR_MII_MODE |
  103. FEC_RCR_PROM | 0x100;
  104. fecp->tcr = FEC_TCR_FDEN;
  105. } else {
  106. /* Half duplex mode */
  107. fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) |
  108. FEC_RCR_MII_MODE | FEC_RCR_DRT;
  109. fecp->tcr &= ~FEC_TCR_FDEN;
  110. }
  111. if ((dup_spd & 0xFFFF) == _100BASET) {
  112. #ifdef CONFIG_MCF5445x
  113. fecp->rcr &= ~0x200; /* disabled 10T base */
  114. #endif
  115. #ifdef MII_DEBUG
  116. printf("100Mbps\n");
  117. #endif
  118. bd->bi_ethspeed = 100;
  119. } else {
  120. #ifdef CONFIG_MCF5445x
  121. fecp->rcr |= 0x200; /* enabled 10T base */
  122. #endif
  123. #ifdef MII_DEBUG
  124. printf("10Mbps\n");
  125. #endif
  126. bd->bi_ethspeed = 10;
  127. }
  128. }
  129. int fec_send(struct eth_device *dev, volatile void *packet, int length)
  130. {
  131. struct fec_info_s *info = dev->priv;
  132. volatile fec_t *fecp = (fec_t *) (info->iobase);
  133. int j, rc;
  134. u16 phyStatus;
  135. miiphy_read(dev->name, info->phy_addr, PHY_BMSR, &phyStatus);
  136. /* section 16.9.23.3
  137. * Wait for ready
  138. */
  139. j = 0;
  140. while ((info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_READY) &&
  141. (j < MCFFEC_TOUT_LOOP)) {
  142. udelay(1);
  143. j++;
  144. }
  145. if (j >= MCFFEC_TOUT_LOOP) {
  146. printf("TX not ready\n");
  147. }
  148. info->txbd[info->txIdx].cbd_bufaddr = (uint) packet;
  149. info->txbd[info->txIdx].cbd_datlen = length;
  150. info->txbd[info->txIdx].cbd_sc |= BD_ENET_TX_RDY_LST;
  151. /* Activate transmit Buffer Descriptor polling */
  152. fecp->tdar = 0x01000000; /* Descriptor polling active */
  153. /* FEC fix for MCF5275, FEC unable to initial transmit data packet.
  154. * A nop will ensure the descriptor polling active completed.
  155. */
  156. #ifdef CONFIG_M5275
  157. __asm__ ("nop");
  158. #endif
  159. #ifdef CFG_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. #ifdef CFG_UNIFY_CACHE
  189. icache_invalid();
  190. #endif
  191. /* section 16.9.23.2 */
  192. if (info->rxbd[info->rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
  193. length = -1;
  194. break; /* nothing received - leave for() loop */
  195. }
  196. length = info->rxbd[info->rxIdx].cbd_datlen;
  197. if (info->rxbd[info->rxIdx].cbd_sc & 0x003f) {
  198. printf("%s[%d] err: %x\n",
  199. __FUNCTION__, __LINE__,
  200. info->rxbd[info->rxIdx].cbd_sc);
  201. #ifdef ET_DEBUG
  202. printf("%s[%d] err: %x\n",
  203. __FUNCTION__, __LINE__,
  204. info->rxbd[info->rxIdx].cbd_sc);
  205. #endif
  206. } else {
  207. length -= 4;
  208. /* Pass the packet up to the protocol layers. */
  209. NetReceive(NetRxPackets[info->rxIdx], length);
  210. fecp->eir |= FEC_EIR_RXF;
  211. }
  212. /* Give the buffer back to the FEC. */
  213. info->rxbd[info->rxIdx].cbd_datlen = 0;
  214. /* wrap around buffer index when necessary */
  215. if (info->rxIdx == LAST_PKTBUFSRX) {
  216. info->rxbd[PKTBUFSRX - 1].cbd_sc = BD_ENET_RX_W_E;
  217. info->rxIdx = 0;
  218. } else {
  219. info->rxbd[info->rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
  220. info->rxIdx++;
  221. }
  222. /* Try to fill Buffer Descriptors */
  223. fecp->rdar = 0x01000000; /* Descriptor polling active */
  224. }
  225. return length;
  226. }
  227. #ifdef ET_DEBUG
  228. void dbgFecRegs(struct eth_device *dev)
  229. {
  230. struct fec_info_s *info = dev->priv;
  231. volatile fec_t *fecp = (fec_t *) (info->iobase);
  232. printf("=====\n");
  233. printf("ievent %x - %x\n", (int)&fecp->eir, fecp->eir);
  234. printf("imask %x - %x\n", (int)&fecp->eimr, fecp->eimr);
  235. printf("r_des_active %x - %x\n", (int)&fecp->rdar, fecp->rdar);
  236. printf("x_des_active %x - %x\n", (int)&fecp->tdar, fecp->tdar);
  237. printf("ecntrl %x - %x\n", (int)&fecp->ecr, fecp->ecr);
  238. printf("mii_mframe %x - %x\n", (int)&fecp->mmfr, fecp->mmfr);
  239. printf("mii_speed %x - %x\n", (int)&fecp->mscr, fecp->mscr);
  240. printf("mii_ctrlstat %x - %x\n", (int)&fecp->mibc, fecp->mibc);
  241. printf("r_cntrl %x - %x\n", (int)&fecp->rcr, fecp->rcr);
  242. printf("x_cntrl %x - %x\n", (int)&fecp->tcr, fecp->tcr);
  243. printf("padr_l %x - %x\n", (int)&fecp->palr, fecp->palr);
  244. printf("padr_u %x - %x\n", (int)&fecp->paur, fecp->paur);
  245. printf("op_pause %x - %x\n", (int)&fecp->opd, fecp->opd);
  246. printf("iadr_u %x - %x\n", (int)&fecp->iaur, fecp->iaur);
  247. printf("iadr_l %x - %x\n", (int)&fecp->ialr, fecp->ialr);
  248. printf("gadr_u %x - %x\n", (int)&fecp->gaur, fecp->gaur);
  249. printf("gadr_l %x - %x\n", (int)&fecp->galr, fecp->galr);
  250. printf("x_wmrk %x - %x\n", (int)&fecp->tfwr, fecp->tfwr);
  251. printf("r_bound %x - %x\n", (int)&fecp->frbr, fecp->frbr);
  252. printf("r_fstart %x - %x\n", (int)&fecp->frsr, fecp->frsr);
  253. printf("r_drng %x - %x\n", (int)&fecp->erdsr, fecp->erdsr);
  254. printf("x_drng %x - %x\n", (int)&fecp->etdsr, fecp->etdsr);
  255. printf("r_bufsz %x - %x\n", (int)&fecp->emrbr, fecp->emrbr);
  256. printf("\n");
  257. printf("rmon_t_drop %x - %x\n", (int)&fecp->rmon_t_drop,
  258. fecp->rmon_t_drop);
  259. printf("rmon_t_packets %x - %x\n", (int)&fecp->rmon_t_packets,
  260. fecp->rmon_t_packets);
  261. printf("rmon_t_bc_pkt %x - %x\n", (int)&fecp->rmon_t_bc_pkt,
  262. fecp->rmon_t_bc_pkt);
  263. printf("rmon_t_mc_pkt %x - %x\n", (int)&fecp->rmon_t_mc_pkt,
  264. fecp->rmon_t_mc_pkt);
  265. printf("rmon_t_crc_align %x - %x\n", (int)&fecp->rmon_t_crc_align,
  266. fecp->rmon_t_crc_align);
  267. printf("rmon_t_undersize %x - %x\n", (int)&fecp->rmon_t_undersize,
  268. fecp->rmon_t_undersize);
  269. printf("rmon_t_oversize %x - %x\n", (int)&fecp->rmon_t_oversize,
  270. fecp->rmon_t_oversize);
  271. printf("rmon_t_frag %x - %x\n", (int)&fecp->rmon_t_frag,
  272. fecp->rmon_t_frag);
  273. printf("rmon_t_jab %x - %x\n", (int)&fecp->rmon_t_jab,
  274. fecp->rmon_t_jab);
  275. printf("rmon_t_col %x - %x\n", (int)&fecp->rmon_t_col,
  276. fecp->rmon_t_col);
  277. printf("rmon_t_p64 %x - %x\n", (int)&fecp->rmon_t_p64,
  278. fecp->rmon_t_p64);
  279. printf("rmon_t_p65to127 %x - %x\n", (int)&fecp->rmon_t_p65to127,
  280. fecp->rmon_t_p65to127);
  281. printf("rmon_t_p128to255 %x - %x\n", (int)&fecp->rmon_t_p128to255,
  282. fecp->rmon_t_p128to255);
  283. printf("rmon_t_p256to511 %x - %x\n", (int)&fecp->rmon_t_p256to511,
  284. fecp->rmon_t_p256to511);
  285. printf("rmon_t_p512to1023 %x - %x\n", (int)&fecp->rmon_t_p512to1023,
  286. fecp->rmon_t_p512to1023);
  287. printf("rmon_t_p1024to2047 %x - %x\n", (int)&fecp->rmon_t_p1024to2047,
  288. fecp->rmon_t_p1024to2047);
  289. printf("rmon_t_p_gte2048 %x - %x\n", (int)&fecp->rmon_t_p_gte2048,
  290. fecp->rmon_t_p_gte2048);
  291. printf("rmon_t_octets %x - %x\n", (int)&fecp->rmon_t_octets,
  292. fecp->rmon_t_octets);
  293. printf("\n");
  294. printf("ieee_t_drop %x - %x\n", (int)&fecp->ieee_t_drop,
  295. fecp->ieee_t_drop);
  296. printf("ieee_t_frame_ok %x - %x\n", (int)&fecp->ieee_t_frame_ok,
  297. fecp->ieee_t_frame_ok);
  298. printf("ieee_t_1col %x - %x\n", (int)&fecp->ieee_t_1col,
  299. fecp->ieee_t_1col);
  300. printf("ieee_t_mcol %x - %x\n", (int)&fecp->ieee_t_mcol,
  301. fecp->ieee_t_mcol);
  302. printf("ieee_t_def %x - %x\n", (int)&fecp->ieee_t_def,
  303. fecp->ieee_t_def);
  304. printf("ieee_t_lcol %x - %x\n", (int)&fecp->ieee_t_lcol,
  305. fecp->ieee_t_lcol);
  306. printf("ieee_t_excol %x - %x\n", (int)&fecp->ieee_t_excol,
  307. fecp->ieee_t_excol);
  308. printf("ieee_t_macerr %x - %x\n", (int)&fecp->ieee_t_macerr,
  309. fecp->ieee_t_macerr);
  310. printf("ieee_t_cserr %x - %x\n", (int)&fecp->ieee_t_cserr,
  311. fecp->ieee_t_cserr);
  312. printf("ieee_t_sqe %x - %x\n", (int)&fecp->ieee_t_sqe,
  313. fecp->ieee_t_sqe);
  314. printf("ieee_t_fdxfc %x - %x\n", (int)&fecp->ieee_t_fdxfc,
  315. fecp->ieee_t_fdxfc);
  316. printf("ieee_t_octets_ok %x - %x\n", (int)&fecp->ieee_t_octets_ok,
  317. fecp->ieee_t_octets_ok);
  318. printf("\n");
  319. printf("rmon_r_drop %x - %x\n", (int)&fecp->rmon_r_drop,
  320. fecp->rmon_r_drop);
  321. printf("rmon_r_packets %x - %x\n", (int)&fecp->rmon_r_packets,
  322. fecp->rmon_r_packets);
  323. printf("rmon_r_bc_pkt %x - %x\n", (int)&fecp->rmon_r_bc_pkt,
  324. fecp->rmon_r_bc_pkt);
  325. printf("rmon_r_mc_pkt %x - %x\n", (int)&fecp->rmon_r_mc_pkt,
  326. fecp->rmon_r_mc_pkt);
  327. printf("rmon_r_crc_align %x - %x\n", (int)&fecp->rmon_r_crc_align,
  328. fecp->rmon_r_crc_align);
  329. printf("rmon_r_undersize %x - %x\n", (int)&fecp->rmon_r_undersize,
  330. fecp->rmon_r_undersize);
  331. printf("rmon_r_oversize %x - %x\n", (int)&fecp->rmon_r_oversize,
  332. fecp->rmon_r_oversize);
  333. printf("rmon_r_frag %x - %x\n", (int)&fecp->rmon_r_frag,
  334. fecp->rmon_r_frag);
  335. printf("rmon_r_jab %x - %x\n", (int)&fecp->rmon_r_jab,
  336. fecp->rmon_r_jab);
  337. printf("rmon_r_p64 %x - %x\n", (int)&fecp->rmon_r_p64,
  338. fecp->rmon_r_p64);
  339. printf("rmon_r_p65to127 %x - %x\n", (int)&fecp->rmon_r_p65to127,
  340. fecp->rmon_r_p65to127);
  341. printf("rmon_r_p128to255 %x - %x\n", (int)&fecp->rmon_r_p128to255,
  342. fecp->rmon_r_p128to255);
  343. printf("rmon_r_p256to511 %x - %x\n", (int)&fecp->rmon_r_p256to511,
  344. fecp->rmon_r_p256to511);
  345. printf("rmon_r_p512to1023 %x - %x\n", (int)&fecp->rmon_r_p512to1023,
  346. fecp->rmon_r_p512to1023);
  347. printf("rmon_r_p1024to2047 %x - %x\n", (int)&fecp->rmon_r_p1024to2047,
  348. fecp->rmon_r_p1024to2047);
  349. printf("rmon_r_p_gte2048 %x - %x\n", (int)&fecp->rmon_r_p_gte2048,
  350. fecp->rmon_r_p_gte2048);
  351. printf("rmon_r_octets %x - %x\n", (int)&fecp->rmon_r_octets,
  352. fecp->rmon_r_octets);
  353. printf("\n");
  354. printf("ieee_r_drop %x - %x\n", (int)&fecp->ieee_r_drop,
  355. fecp->ieee_r_drop);
  356. printf("ieee_r_frame_ok %x - %x\n", (int)&fecp->ieee_r_frame_ok,
  357. fecp->ieee_r_frame_ok);
  358. printf("ieee_r_crc %x - %x\n", (int)&fecp->ieee_r_crc,
  359. fecp->ieee_r_crc);
  360. printf("ieee_r_align %x - %x\n", (int)&fecp->ieee_r_align,
  361. fecp->ieee_r_align);
  362. printf("ieee_r_macerr %x - %x\n", (int)&fecp->ieee_r_macerr,
  363. fecp->ieee_r_macerr);
  364. printf("ieee_r_fdxfc %x - %x\n", (int)&fecp->ieee_r_fdxfc,
  365. fecp->ieee_r_fdxfc);
  366. printf("ieee_r_octets_ok %x - %x\n", (int)&fecp->ieee_r_octets_ok,
  367. fecp->ieee_r_octets_ok);
  368. printf("\n\n\n");
  369. }
  370. #endif
  371. int fec_init(struct eth_device *dev, bd_t * bd)
  372. {
  373. struct fec_info_s *info = dev->priv;
  374. volatile fec_t *fecp = (fec_t *) (info->iobase);
  375. int i;
  376. u8 *ea = NULL;
  377. fecpin_setclear(dev, 1);
  378. fec_reset(dev);
  379. #if defined(CONFIG_CMD_MII) || defined (CONFIG_MII) || \
  380. defined (CFG_DISCOVER_PHY)
  381. mii_init();
  382. setFecDuplexSpeed(fecp, bd, info->dup_spd);
  383. #else
  384. #ifndef CFG_DISCOVER_PHY
  385. setFecDuplexSpeed(fecp, bd, (FECDUPLEX << 16) | FECSPEED);
  386. #endif /* ifndef CFG_DISCOVER_PHY */
  387. #endif /* CONFIG_CMD_MII || CONFIG_MII */
  388. /* We use strictly polling mode only */
  389. fecp->eimr = 0;
  390. /* Clear any pending interrupt */
  391. fecp->eir = 0xffffffff;
  392. /* Set station address */
  393. if ((u32) fecp == CFG_FEC0_IOBASE) {
  394. #ifdef CFG_FEC1_IOBASE
  395. volatile fec_t *fecp1 = (fec_t *) (CFG_FEC1_IOBASE);
  396. ea = &bd->bi_enet1addr[0];
  397. fecp1->palr =
  398. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  399. fecp1->paur = (ea[4] << 24) | (ea[5] << 16);
  400. #endif
  401. ea = &bd->bi_enetaddr[0];
  402. fecp->palr =
  403. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  404. fecp->paur = (ea[4] << 24) | (ea[5] << 16);
  405. } else {
  406. #ifdef CFG_FEC0_IOBASE
  407. volatile fec_t *fecp0 = (fec_t *) (CFG_FEC0_IOBASE);
  408. ea = &bd->bi_enetaddr[0];
  409. fecp0->palr =
  410. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  411. fecp0->paur = (ea[4] << 24) | (ea[5] << 16);
  412. #endif
  413. #ifdef CFG_FEC1_IOBASE
  414. ea = &bd->bi_enet1addr[0];
  415. fecp->palr =
  416. (ea[0] << 24) | (ea[1] << 16) | (ea[2] << 8) | (ea[3]);
  417. fecp->paur = (ea[4] << 24) | (ea[5] << 16);
  418. #endif
  419. }
  420. /* Clear unicast address hash table */
  421. fecp->iaur = 0;
  422. fecp->ialr = 0;
  423. /* Clear multicast address hash table */
  424. fecp->gaur = 0;
  425. fecp->galr = 0;
  426. /* Set maximum receive buffer size. */
  427. fecp->emrbr = PKT_MAXBLR_SIZE;
  428. /*
  429. * Setup Buffers and Buffer Desriptors
  430. */
  431. info->rxIdx = 0;
  432. info->txIdx = 0;
  433. /*
  434. * Setup Receiver Buffer Descriptors (13.14.24.18)
  435. * Settings:
  436. * Empty, Wrap
  437. */
  438. for (i = 0; i < PKTBUFSRX; i++) {
  439. info->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
  440. info->rxbd[i].cbd_datlen = 0; /* Reset */
  441. info->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
  442. }
  443. info->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
  444. /*
  445. * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
  446. * Settings:
  447. * Last, Tx CRC
  448. */
  449. for (i = 0; i < TX_BUF_CNT; i++) {
  450. info->txbd[i].cbd_sc = BD_ENET_TX_LAST | BD_ENET_TX_TC;
  451. info->txbd[i].cbd_datlen = 0; /* Reset */
  452. info->txbd[i].cbd_bufaddr = (uint) (&info->txbuf[0]);
  453. }
  454. info->txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
  455. /* Set receive and transmit descriptor base */
  456. fecp->erdsr = (unsigned int)(&info->rxbd[0]);
  457. fecp->etdsr = (unsigned int)(&info->txbd[0]);
  458. /* Now enable the transmit and receive processing */
  459. fecp->ecr |= FEC_ECR_ETHER_EN;
  460. /* And last, try to fill Rx Buffer Descriptors */
  461. fecp->rdar = 0x01000000; /* Descriptor polling active */
  462. return 1;
  463. }
  464. void fec_reset(struct eth_device *dev)
  465. {
  466. struct fec_info_s *info = dev->priv;
  467. volatile fec_t *fecp = (fec_t *) (info->iobase);
  468. int i;
  469. fecp->ecr = FEC_ECR_RESET;
  470. for (i = 0; (fecp->ecr & FEC_ECR_RESET) && (i < FEC_RESET_DELAY); ++i) {
  471. udelay(1);
  472. }
  473. if (i == FEC_RESET_DELAY) {
  474. printf("FEC_RESET_DELAY timeout\n");
  475. }
  476. }
  477. void fec_halt(struct eth_device *dev)
  478. {
  479. struct fec_info_s *info = dev->priv;
  480. fec_reset(dev);
  481. fecpin_setclear(dev, 0);
  482. info->rxIdx = info->txIdx = 0;
  483. memset(info->rxbd, 0, PKTBUFSRX * sizeof(cbd_t));
  484. memset(info->txbd, 0, TX_BUF_CNT * sizeof(cbd_t));
  485. memset(info->txbuf, 0, DBUF_LENGTH);
  486. }
  487. int mcffec_initialize(bd_t * bis)
  488. {
  489. struct eth_device *dev;
  490. int i;
  491. for (i = 0; i < sizeof(fec_info) / sizeof(fec_info[0]); i++) {
  492. dev =
  493. (struct eth_device *)memalign(CFG_CACHELINE_SIZE,
  494. sizeof *dev);
  495. if (dev == NULL)
  496. hang();
  497. memset(dev, 0, sizeof(*dev));
  498. sprintf(dev->name, "FEC%d", fec_info[i].index);
  499. dev->priv = &fec_info[i];
  500. dev->init = fec_init;
  501. dev->halt = fec_halt;
  502. dev->send = fec_send;
  503. dev->recv = fec_recv;
  504. /* setup Receive and Transmit buffer descriptor */
  505. fec_info[i].rxbd =
  506. (cbd_t *) memalign(CFG_CACHELINE_SIZE,
  507. (PKTBUFSRX * sizeof(cbd_t)));
  508. fec_info[i].txbd =
  509. (cbd_t *) memalign(CFG_CACHELINE_SIZE,
  510. (TX_BUF_CNT * sizeof(cbd_t)));
  511. fec_info[i].txbuf =
  512. (char *)memalign(CFG_CACHELINE_SIZE, DBUF_LENGTH);
  513. #ifdef ET_DEBUG
  514. printf("rxbd %x txbd %x\n",
  515. (int)fec_info[i].rxbd, (int)fec_info[i].txbd);
  516. #endif
  517. fec_info[i].phy_name = (char *)memalign(CFG_CACHELINE_SIZE, 32);
  518. eth_register(dev);
  519. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  520. miiphy_register(dev->name,
  521. mcffec_miiphy_read, mcffec_miiphy_write);
  522. #endif
  523. }
  524. /* default speed */
  525. bis->bi_ethspeed = 10;
  526. return 1;
  527. }