fsl_mcdmafec.c 16 KB

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