mcffec.c 18 KB

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