mcffec.c 18 KB

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