fsl_mcdmafec.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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 <config.h>
  30. #include <net.h>
  31. #include <miiphy.h>
  32. #ifdef CONFIG_FSLDMAFEC
  33. #undef ET_DEBUG
  34. #undef MII_DEBUG
  35. /* Ethernet Transmit and Receive Buffers */
  36. #define DBUF_LENGTH 1520
  37. #define PKT_MAXBUF_SIZE 1518
  38. #define PKT_MINBUF_SIZE 64
  39. #define PKT_MAXBLR_SIZE 1536
  40. #define LAST_PKTBUFSRX PKTBUFSRX - 1
  41. #define BD_ENET_RX_W_E (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY)
  42. #define BD_ENET_TX_RDY_LST (BD_ENET_TX_READY | BD_ENET_TX_LAST)
  43. #define FIFO_ERRSTAT (FIFO_STAT_RXW | FIFO_STAT_UF | FIFO_STAT_OF)
  44. /* RxBD bits definitions */
  45. #define BD_ENET_RX_ERR (BD_ENET_RX_LG | BD_ENET_RX_NO | BD_ENET_RX_CR | \
  46. BD_ENET_RX_OV | BD_ENET_RX_TR)
  47. #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
  48. #include <asm/immap.h>
  49. #include <asm/fsl_mcdmafec.h>
  50. #include "MCD_dma.h"
  51. DECLARE_GLOBAL_DATA_PTR;
  52. struct fec_info_dma fec_info[] = {
  53. #ifdef CFG_FEC0_IOBASE
  54. {
  55. 0, /* index */
  56. CFG_FEC0_IOBASE, /* io base */
  57. CFG_FEC0_PINMUX, /* gpio pin muxing */
  58. CFG_FEC0_MIIBASE, /* mii base */
  59. -1, /* phy_addr */
  60. 0, /* duplex and speed */
  61. 0, /* phy name */
  62. 0, /* phyname init */
  63. 0, /* RX BD */
  64. 0, /* TX BD */
  65. 0, /* rx Index */
  66. 0, /* tx Index */
  67. 0, /* tx buffer */
  68. 0, /* initialized flag */
  69. (struct fec_info_dma *)-1, /* next */
  70. FEC0_RX_TASK, /* rxTask */
  71. FEC0_TX_TASK, /* txTask */
  72. FEC0_RX_PRIORITY, /* rxPri */
  73. FEC0_TX_PRIORITY, /* txPri */
  74. FEC0_RX_INIT, /* rxInit */
  75. FEC0_TX_INIT, /* txInit */
  76. 0, /* usedTbdIndex */
  77. 0, /* cleanTbdNum */
  78. },
  79. #endif
  80. #ifdef CFG_FEC1_IOBASE
  81. {
  82. 1, /* index */
  83. CFG_FEC1_IOBASE, /* io base */
  84. CFG_FEC1_PINMUX, /* gpio pin muxing */
  85. CFG_FEC1_MIIBASE, /* mii base */
  86. -1, /* phy_addr */
  87. 0, /* duplex and speed */
  88. 0, /* phy name */
  89. 0, /* phy name init */
  90. #ifdef CFG_DMA_USE_INTSRAM
  91. DBUF_LENGTH, /* RX BD */
  92. #else
  93. 0, /* RX BD */
  94. #endif
  95. 0, /* TX BD */
  96. 0, /* rx Index */
  97. 0, /* tx Index */
  98. 0, /* tx buffer */
  99. 0, /* initialized flag */
  100. (struct fec_info_dma *)-1, /* next */
  101. FEC1_RX_TASK, /* rxTask */
  102. FEC1_TX_TASK, /* txTask */
  103. FEC1_RX_PRIORITY, /* rxPri */
  104. FEC1_TX_PRIORITY, /* txPri */
  105. FEC1_RX_INIT, /* rxInit */
  106. FEC1_TX_INIT, /* txInit */
  107. 0, /* usedTbdIndex */
  108. 0, /* cleanTbdNum */
  109. }
  110. #endif
  111. };
  112. static int fec_send(struct eth_device *dev, volatile void *packet, int length);
  113. static int fec_recv(struct eth_device *dev);
  114. static int fec_init(struct eth_device *dev, bd_t * bd);
  115. static void fec_halt(struct eth_device *dev);
  116. #ifdef ET_DEBUG
  117. static void dbg_fec_regs(struct eth_device *dev)
  118. {
  119. struct fec_info_dma *info = dev->priv;
  120. volatile fecdma_t *fecp = (fecdma_t *) (info->iobase);
  121. printf("=====\n");
  122. printf("ievent %x - %x\n", (int)&fecp->eir, fecp->eir);
  123. printf("imask %x - %x\n", (int)&fecp->eimr, fecp->eimr);
  124. printf("ecntrl %x - %x\n", (int)&fecp->ecr, fecp->ecr);
  125. printf("mii_mframe %x - %x\n", (int)&fecp->mmfr, fecp->mmfr);
  126. printf("mii_speed %x - %x\n", (int)&fecp->mscr, fecp->mscr);
  127. printf("mii_ctrlstat %x - %x\n", (int)&fecp->mibc, fecp->mibc);
  128. printf("r_cntrl %x - %x\n", (int)&fecp->rcr, fecp->rcr);
  129. printf("r hash %x - %x\n", (int)&fecp->rhr, fecp->rhr);
  130. printf("x_cntrl %x - %x\n", (int)&fecp->tcr, fecp->tcr);
  131. printf("padr_l %x - %x\n", (int)&fecp->palr, fecp->palr);
  132. printf("padr_u %x - %x\n", (int)&fecp->paur, fecp->paur);
  133. printf("op_pause %x - %x\n", (int)&fecp->opd, fecp->opd);
  134. printf("iadr_u %x - %x\n", (int)&fecp->iaur, fecp->iaur);
  135. printf("iadr_l %x - %x\n", (int)&fecp->ialr, fecp->ialr);
  136. printf("gadr_u %x - %x\n", (int)&fecp->gaur, fecp->gaur);
  137. printf("gadr_l %x - %x\n", (int)&fecp->galr, fecp->galr);
  138. printf("x_wmrk %x - %x\n", (int)&fecp->tfwr, fecp->tfwr);
  139. printf("r_fdata %x - %x\n", (int)&fecp->rfdr, fecp->rfdr);
  140. printf("r_fstat %x - %x\n", (int)&fecp->rfsr, fecp->rfsr);
  141. printf("r_fctrl %x - %x\n", (int)&fecp->rfcr, fecp->rfcr);
  142. printf("r_flrfp %x - %x\n", (int)&fecp->rlrfp, fecp->rlrfp);
  143. printf("r_flwfp %x - %x\n", (int)&fecp->rlwfp, fecp->rlwfp);
  144. printf("r_frfar %x - %x\n", (int)&fecp->rfar, fecp->rfar);
  145. printf("r_frfrp %x - %x\n", (int)&fecp->rfrp, fecp->rfrp);
  146. printf("r_frfwp %x - %x\n", (int)&fecp->rfwp, fecp->rfwp);
  147. printf("t_fdata %x - %x\n", (int)&fecp->tfdr, fecp->tfdr);
  148. printf("t_fstat %x - %x\n", (int)&fecp->tfsr, fecp->tfsr);
  149. printf("t_fctrl %x - %x\n", (int)&fecp->tfcr, fecp->tfcr);
  150. printf("t_flrfp %x - %x\n", (int)&fecp->tlrfp, fecp->tlrfp);
  151. printf("t_flwfp %x - %x\n", (int)&fecp->tlwfp, fecp->tlwfp);
  152. printf("t_ftfar %x - %x\n", (int)&fecp->tfar, fecp->tfar);
  153. printf("t_ftfrp %x - %x\n", (int)&fecp->tfrp, fecp->tfrp);
  154. printf("t_ftfwp %x - %x\n", (int)&fecp->tfwp, fecp->tfwp);
  155. printf("frst %x - %x\n", (int)&fecp->frst, fecp->frst);
  156. printf("ctcwr %x - %x\n", (int)&fecp->ctcwr, fecp->ctcwr);
  157. }
  158. #endif
  159. static void set_fec_duplex_speed(volatile fecdma_t * fecp, bd_t * bd,
  160. int dup_spd)
  161. {
  162. if ((dup_spd >> 16) == FULL) {
  163. /* Set maximum frame length */
  164. fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) | FEC_RCR_MII_MODE |
  165. FEC_RCR_PROM | 0x100;
  166. fecp->tcr = FEC_TCR_FDEN;
  167. } else {
  168. /* Half duplex mode */
  169. fecp->rcr = FEC_RCR_MAX_FL(PKT_MAXBUF_SIZE) |
  170. FEC_RCR_MII_MODE | FEC_RCR_DRT;
  171. fecp->tcr &= ~FEC_TCR_FDEN;
  172. }
  173. if ((dup_spd & 0xFFFF) == _100BASET) {
  174. #ifdef MII_DEBUG
  175. printf("100Mbps\n");
  176. #endif
  177. bd->bi_ethspeed = 100;
  178. } else {
  179. #ifdef MII_DEBUG
  180. printf("10Mbps\n");
  181. #endif
  182. bd->bi_ethspeed = 10;
  183. }
  184. }
  185. static int fec_send(struct eth_device *dev, volatile void *packet, int length)
  186. {
  187. struct fec_info_dma *info = dev->priv;
  188. cbd_t *pTbd, *pUsedTbd;
  189. u16 phyStatus;
  190. miiphy_read(dev->name, info->phy_addr, PHY_BMSR, &phyStatus);
  191. /* process all the consumed TBDs */
  192. while (info->cleanTbdNum < CFG_TX_ETH_BUFFER) {
  193. pUsedTbd = &info->txbd[info->usedTbdIdx];
  194. if (pUsedTbd->cbd_sc & BD_ENET_TX_READY) {
  195. #ifdef ET_DEBUG
  196. printf("Cannot clean TBD %d, in use\n",
  197. info->cleanTbdNum);
  198. #endif
  199. return 0;
  200. }
  201. /* clean this buffer descriptor */
  202. if (info->usedTbdIdx == (CFG_TX_ETH_BUFFER - 1))
  203. pUsedTbd->cbd_sc = BD_ENET_TX_WRAP;
  204. else
  205. pUsedTbd->cbd_sc = 0;
  206. /* update some indeces for a correct handling of the TBD ring */
  207. info->cleanTbdNum++;
  208. info->usedTbdIdx = (info->usedTbdIdx + 1) % CFG_TX_ETH_BUFFER;
  209. }
  210. /* Check for valid length of data. */
  211. if ((length > 1500) || (length <= 0)) {
  212. return -1;
  213. }
  214. /* Check the number of vacant TxBDs. */
  215. if (info->cleanTbdNum < 1) {
  216. printf("No available TxBDs ...\n");
  217. return -1;
  218. }
  219. /* Get the first TxBD to send the mac header */
  220. pTbd = &info->txbd[info->txIdx];
  221. pTbd->cbd_datlen = length;
  222. pTbd->cbd_bufaddr = (u32) packet;
  223. pTbd->cbd_sc |= BD_ENET_TX_LAST | BD_ENET_TX_TC | BD_ENET_TX_READY;
  224. info->txIdx = (info->txIdx + 1) % CFG_TX_ETH_BUFFER;
  225. /* Enable DMA transmit task */
  226. MCD_continDma(info->txTask);
  227. info->cleanTbdNum -= 1;
  228. /* wait until frame is sent . */
  229. while (pTbd->cbd_sc & BD_ENET_TX_READY) {
  230. udelay(10);
  231. }
  232. return (int)(info->txbd[info->txIdx].cbd_sc & BD_ENET_TX_STATS);
  233. }
  234. static int fec_recv(struct eth_device *dev)
  235. {
  236. struct fec_info_dma *info = dev->priv;
  237. volatile fecdma_t *fecp = (fecdma_t *) (info->iobase);
  238. cbd_t *pRbd = &info->rxbd[info->rxIdx];
  239. u32 ievent;
  240. int frame_length, len = 0;
  241. /* Check if any critical events have happened */
  242. ievent = fecp->eir;
  243. if (ievent != 0) {
  244. fecp->eir = ievent;
  245. if (ievent & (FEC_EIR_BABT | FEC_EIR_TXERR | FEC_EIR_RXERR)) {
  246. printf("fec_recv: error\n");
  247. fec_halt(dev);
  248. fec_init(dev, NULL);
  249. return 0;
  250. }
  251. if (ievent & FEC_EIR_HBERR) {
  252. /* Heartbeat error */
  253. fecp->tcr |= FEC_TCR_GTS;
  254. }
  255. if (ievent & FEC_EIR_GRA) {
  256. /* Graceful stop complete */
  257. if (fecp->tcr & FEC_TCR_GTS) {
  258. printf("fec_recv: tcr_gts\n");
  259. fec_halt(dev);
  260. fecp->tcr &= ~FEC_TCR_GTS;
  261. fec_init(dev, NULL);
  262. }
  263. }
  264. }
  265. if (!(pRbd->cbd_sc & BD_ENET_RX_EMPTY)) {
  266. if ((pRbd->cbd_sc & BD_ENET_RX_LAST)
  267. && !(pRbd->cbd_sc & BD_ENET_RX_ERR)
  268. && ((pRbd->cbd_datlen - 4) > 14)) {
  269. /* Get buffer address and size */
  270. frame_length = pRbd->cbd_datlen - 4;
  271. /* Fill the buffer and pass it to upper layers */
  272. NetReceive((volatile uchar *)pRbd->cbd_bufaddr,
  273. frame_length);
  274. len = frame_length;
  275. }
  276. /* Reset buffer descriptor as empty */
  277. if ((info->rxIdx) == (PKTBUFSRX - 1))
  278. pRbd->cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
  279. else
  280. pRbd->cbd_sc = BD_ENET_RX_EMPTY;
  281. pRbd->cbd_datlen = PKTSIZE_ALIGN;
  282. /* Now, we have an empty RxBD, restart the DMA receive task */
  283. MCD_continDma(info->rxTask);
  284. /* Increment BD count */
  285. info->rxIdx = (info->rxIdx + 1) % PKTBUFSRX;
  286. }
  287. return len;
  288. }
  289. static void fec_set_hwaddr(volatile fecdma_t * fecp, u8 * mac)
  290. {
  291. u8 currByte; /* byte for which to compute the CRC */
  292. int byte; /* loop - counter */
  293. int bit; /* loop - counter */
  294. u32 crc = 0xffffffff; /* initial value */
  295. for (byte = 0; byte < 6; byte++) {
  296. currByte = mac[byte];
  297. for (bit = 0; bit < 8; bit++) {
  298. if ((currByte & 0x01) ^ (crc & 0x01)) {
  299. crc >>= 1;
  300. crc = crc ^ 0xedb88320;
  301. } else {
  302. crc >>= 1;
  303. }
  304. currByte >>= 1;
  305. }
  306. }
  307. crc = crc >> 26;
  308. /* Set individual hash table register */
  309. if (crc >= 32) {
  310. fecp->ialr = (1 << (crc - 32));
  311. fecp->iaur = 0;
  312. } else {
  313. fecp->ialr = 0;
  314. fecp->iaur = (1 << crc);
  315. }
  316. /* Set physical address */
  317. fecp->palr = (mac[0] << 24) + (mac[1] << 16) + (mac[2] << 8) + mac[3];
  318. fecp->paur = (mac[4] << 24) + (mac[5] << 16) + 0x8808;
  319. /* Clear multicast address hash table */
  320. fecp->gaur = 0;
  321. fecp->galr = 0;
  322. }
  323. static int fec_init(struct eth_device *dev, bd_t * bd)
  324. {
  325. struct fec_info_dma *info = dev->priv;
  326. volatile fecdma_t *fecp = (fecdma_t *) (info->iobase);
  327. int i;
  328. #ifdef ET_DEBUG
  329. printf("fec_init: iobase 0x%08x ...\n", info->iobase);
  330. #endif
  331. fecpin_setclear(dev, 1);
  332. fec_halt(dev);
  333. #if defined(CONFIG_CMD_MII) || defined (CONFIG_MII) || \
  334. defined (CFG_DISCOVER_PHY)
  335. mii_init();
  336. set_fec_duplex_speed(fecp, bd, info->dup_spd);
  337. #else
  338. #ifndef CFG_DISCOVER_PHY
  339. set_fec_duplex_speed(fecp, bd, (FECDUPLEX << 16) | FECSPEED);
  340. #endif /* ifndef CFG_DISCOVER_PHY */
  341. #endif /* CONFIG_CMD_MII || CONFIG_MII */
  342. /* We use strictly polling mode only */
  343. fecp->eimr = 0;
  344. /* Clear any pending interrupt */
  345. fecp->eir = 0xffffffff;
  346. /* Set station address */
  347. if ((u32) fecp == CFG_FEC0_IOBASE) {
  348. fec_set_hwaddr(fecp, bd->bi_enetaddr);
  349. } else {
  350. fec_set_hwaddr(fecp, bd->bi_enet1addr);
  351. }
  352. /* Set Opcode/Pause Duration Register */
  353. fecp->opd = 0x00010020;
  354. /* Setup Buffers and Buffer Desriptors */
  355. info->rxIdx = 0;
  356. info->txIdx = 0;
  357. /* Setup Receiver Buffer Descriptors (13.14.24.18)
  358. * Settings: Empty, Wrap */
  359. for (i = 0; i < PKTBUFSRX; i++) {
  360. info->rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
  361. info->rxbd[i].cbd_datlen = PKTSIZE_ALIGN;
  362. info->rxbd[i].cbd_bufaddr = (uint) NetRxPackets[i];
  363. }
  364. info->rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
  365. /* Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
  366. * Settings: Last, Tx CRC */
  367. for (i = 0; i < CFG_TX_ETH_BUFFER; i++) {
  368. info->txbd[i].cbd_sc = 0;
  369. info->txbd[i].cbd_datlen = 0;
  370. info->txbd[i].cbd_bufaddr = (uint) (&info->txbuf[0]);
  371. }
  372. info->txbd[CFG_TX_ETH_BUFFER - 1].cbd_sc |= BD_ENET_TX_WRAP;
  373. info->usedTbdIdx = 0;
  374. info->cleanTbdNum = CFG_TX_ETH_BUFFER;
  375. /* Set Rx FIFO alarm and granularity value */
  376. fecp->rfcr = 0x0c000000;
  377. fecp->rfar = 0x0000030c;
  378. /* Set Tx FIFO granularity value */
  379. fecp->tfcr = FIFO_CTRL_FRAME | FIFO_CTRL_GR(6) | 0x00040000;
  380. fecp->tfar = 0x00000080;
  381. fecp->tfwr = 0x2;
  382. fecp->ctcwr = 0x03000000;
  383. /* Enable DMA receive task */
  384. MCD_startDma(info->rxTask, /* Dma channel */
  385. (s8 *) info->rxbd, /*Source Address */
  386. 0, /* Source increment */
  387. (s8 *) (&fecp->rfdr), /* dest */
  388. 4, /* dest increment */
  389. 0, /* DMA size */
  390. 4, /* xfer size */
  391. info->rxInit, /* initiator */
  392. info->rxPri, /* priority */
  393. (MCD_FECRX_DMA | MCD_TT_FLAGS_DEF), /* Flags */
  394. (MCD_NO_CSUM | MCD_NO_BYTE_SWAP) /* Function description */
  395. );
  396. /* Enable DMA tx task with no ready buffer descriptors */
  397. MCD_startDma(info->txTask, /* Dma channel */
  398. (s8 *) info->txbd, /*Source Address */
  399. 0, /* Source increment */
  400. (s8 *) (&fecp->tfdr), /* dest */
  401. 4, /* dest incr */
  402. 0, /* DMA size */
  403. 4, /* xfer size */
  404. info->txInit, /* initiator */
  405. info->txPri, /* priority */
  406. (MCD_FECTX_DMA | MCD_TT_FLAGS_DEF), /* Flags */
  407. (MCD_NO_CSUM | MCD_NO_BYTE_SWAP) /* Function description */
  408. );
  409. /* Now enable the transmit and receive processing */
  410. fecp->ecr |= FEC_ECR_ETHER_EN;
  411. return 1;
  412. }
  413. static void fec_halt(struct eth_device *dev)
  414. {
  415. struct fec_info_dma *info = dev->priv;
  416. volatile fecdma_t *fecp = (fecdma_t *) (info->iobase);
  417. int counter = 0xffff;
  418. /* issue graceful stop command to the FEC transmitter if necessary */
  419. fecp->tcr |= FEC_TCR_GTS;
  420. /* wait for graceful stop to register */
  421. while ((counter--) && (!(fecp->eir & FEC_EIR_GRA))) ;
  422. /* Disable DMA tasks */
  423. MCD_killDma(info->txTask);
  424. MCD_killDma(info->rxTask);;
  425. /* Disable the Ethernet Controller */
  426. fecp->ecr &= ~FEC_ECR_ETHER_EN;
  427. /* Clear FIFO status registers */
  428. fecp->rfsr &= FIFO_ERRSTAT;
  429. fecp->tfsr &= FIFO_ERRSTAT;
  430. fecp->frst = 0x01000000;
  431. /* Issue a reset command to the FEC chip */
  432. fecp->ecr |= FEC_ECR_RESET;
  433. /* wait at least 20 clock cycles */
  434. udelay(10000);
  435. #ifdef ET_DEBUG
  436. printf("Ethernet task stopped\n");
  437. #endif
  438. }
  439. int mcdmafec_initialize(bd_t * bis)
  440. {
  441. struct eth_device *dev;
  442. int i;
  443. #ifdef CFG_DMA_USE_INTSRAM
  444. u32 tmp = CFG_INTSRAM + 0x2000;
  445. #endif
  446. for (i = 0; i < sizeof(fec_info) / sizeof(fec_info[0]); i++) {
  447. dev =
  448. (struct eth_device *)memalign(CFG_CACHELINE_SIZE,
  449. sizeof *dev);
  450. if (dev == NULL)
  451. hang();
  452. memset(dev, 0, sizeof(*dev));
  453. sprintf(dev->name, "FEC%d", fec_info[i].index);
  454. dev->priv = &fec_info[i];
  455. dev->init = fec_init;
  456. dev->halt = fec_halt;
  457. dev->send = fec_send;
  458. dev->recv = fec_recv;
  459. /* setup Receive and Transmit buffer descriptor */
  460. #ifdef CFG_DMA_USE_INTSRAM
  461. fec_info[i].rxbd = (int)fec_info[i].rxbd + tmp;
  462. tmp = fec_info[i].rxbd;
  463. fec_info[i].txbd =
  464. (int)fec_info[i].txbd + tmp + (PKTBUFSRX * sizeof(cbd_t));
  465. tmp = fec_info[i].txbd;
  466. fec_info[i].txbuf =
  467. (int)fec_info[i].txbuf + tmp +
  468. (CFG_TX_ETH_BUFFER * sizeof(cbd_t));
  469. tmp = fec_info[i].txbuf;
  470. #else
  471. fec_info[i].rxbd =
  472. (cbd_t *) memalign(CFG_CACHELINE_SIZE,
  473. (PKTBUFSRX * sizeof(cbd_t)));
  474. fec_info[i].txbd =
  475. (cbd_t *) memalign(CFG_CACHELINE_SIZE,
  476. (CFG_TX_ETH_BUFFER * sizeof(cbd_t)));
  477. fec_info[i].txbuf =
  478. (char *)memalign(CFG_CACHELINE_SIZE, DBUF_LENGTH);
  479. #endif
  480. #ifdef ET_DEBUG
  481. printf("rxbd %x txbd %x\n",
  482. (int)fec_info[i].rxbd, (int)fec_info[i].txbd);
  483. #endif
  484. fec_info[i].phy_name = (char *)memalign(CFG_CACHELINE_SIZE, 32);
  485. eth_register(dev);
  486. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  487. miiphy_register(dev->name,
  488. mcffec_miiphy_read, mcffec_miiphy_write);
  489. #endif
  490. if (i > 0)
  491. fec_info[i - 1].next = &fec_info[i];
  492. }
  493. fec_info[i - 1].next = &fec_info[0];
  494. /* default speed */
  495. bis->bi_ethspeed = 10;
  496. return 1;
  497. }
  498. #endif /* CONFIG_CMD_NET && CONFIG_NET_MULTI */
  499. #endif /* CONFIG_FSLDMAFEC */