bfin_mac.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*
  2. * Driver for Blackfin On-Chip MAC device
  3. *
  4. * Copyright (c) 2005-2008 Analog Device, Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <common.h>
  9. #include <config.h>
  10. #include <net.h>
  11. #include <netdev.h>
  12. #include <command.h>
  13. #include <malloc.h>
  14. #include <miiphy.h>
  15. #include <linux/mii.h>
  16. #include <asm/blackfin.h>
  17. #include <asm/mach-common/bits/dma.h>
  18. #include <asm/mach-common/bits/emac.h>
  19. #include <asm/mach-common/bits/pll.h>
  20. #include "bfin_mac.h"
  21. #ifndef CONFIG_PHY_ADDR
  22. # define CONFIG_PHY_ADDR 1
  23. #endif
  24. #ifndef CONFIG_PHY_CLOCK_FREQ
  25. # define CONFIG_PHY_CLOCK_FREQ 2500000
  26. #endif
  27. #ifdef CONFIG_POST
  28. #include <post.h>
  29. #endif
  30. #define RXBUF_BASE_ADDR 0xFF900000
  31. #define TXBUF_BASE_ADDR 0xFF800000
  32. #define TX_BUF_CNT 1
  33. #define TOUT_LOOP 1000000
  34. ADI_ETHER_BUFFER *txbuf[TX_BUF_CNT];
  35. ADI_ETHER_BUFFER *rxbuf[PKTBUFSRX];
  36. static u16 txIdx; /* index of the current RX buffer */
  37. static u16 rxIdx; /* index of the current TX buffer */
  38. /* DMAx_CONFIG values at DMA Restart */
  39. const ADI_DMA_CONFIG_REG rxdmacfg = {
  40. .b_DMA_EN = 1, /* enabled */
  41. .b_WNR = 1, /* write to memory */
  42. .b_WDSIZE = 2, /* wordsize is 32 bits */
  43. .b_DMA2D = 0,
  44. .b_RESTART = 0,
  45. .b_DI_SEL = 0,
  46. .b_DI_EN = 0, /* no interrupt */
  47. .b_NDSIZE = 5, /* 5 half words is desc size */
  48. .b_FLOW = 7 /* large desc flow */
  49. };
  50. const ADI_DMA_CONFIG_REG txdmacfg = {
  51. .b_DMA_EN = 1, /* enabled */
  52. .b_WNR = 0, /* read from memory */
  53. .b_WDSIZE = 2, /* wordsize is 32 bits */
  54. .b_DMA2D = 0,
  55. .b_RESTART = 0,
  56. .b_DI_SEL = 0,
  57. .b_DI_EN = 0, /* no interrupt */
  58. .b_NDSIZE = 5, /* 5 half words is desc size */
  59. .b_FLOW = 7 /* large desc flow */
  60. };
  61. static int bfin_miiphy_wait(void)
  62. {
  63. /* poll the STABUSY bit */
  64. while (bfin_read_EMAC_STAADD() & STABUSY)
  65. continue;
  66. return 0;
  67. }
  68. static int bfin_miiphy_read(char *devname, uchar addr, uchar reg, ushort *val)
  69. {
  70. if (bfin_miiphy_wait())
  71. return 1;
  72. bfin_write_EMAC_STAADD(SET_PHYAD(addr) | SET_REGAD(reg) | STABUSY);
  73. if (bfin_miiphy_wait())
  74. return 1;
  75. *val = bfin_read_EMAC_STADAT();
  76. return 0;
  77. }
  78. static int bfin_miiphy_write(char *devname, uchar addr, uchar reg, ushort val)
  79. {
  80. if (bfin_miiphy_wait())
  81. return 1;
  82. bfin_write_EMAC_STADAT(val);
  83. bfin_write_EMAC_STAADD(SET_PHYAD(addr) | SET_REGAD(reg) | STAOP | STABUSY);
  84. return 0;
  85. }
  86. int bfin_EMAC_initialize(bd_t *bis)
  87. {
  88. struct eth_device *dev;
  89. dev = malloc(sizeof(*dev));
  90. if (dev == NULL)
  91. hang();
  92. memset(dev, 0, sizeof(*dev));
  93. sprintf(dev->name, "Blackfin EMAC");
  94. dev->iobase = 0;
  95. dev->priv = 0;
  96. dev->init = bfin_EMAC_init;
  97. dev->halt = bfin_EMAC_halt;
  98. dev->send = bfin_EMAC_send;
  99. dev->recv = bfin_EMAC_recv;
  100. eth_register(dev);
  101. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  102. miiphy_register(dev->name, bfin_miiphy_read, bfin_miiphy_write);
  103. #endif
  104. return 0;
  105. }
  106. static int bfin_EMAC_send(struct eth_device *dev, volatile void *packet,
  107. int length)
  108. {
  109. int i;
  110. int result = 0;
  111. unsigned int *buf;
  112. buf = (unsigned int *)packet;
  113. if (length <= 0) {
  114. printf("Ethernet: bad packet size: %d\n", length);
  115. goto out;
  116. }
  117. if ((*pDMA2_IRQ_STATUS & DMA_ERR) != 0) {
  118. printf("Ethernet: tx DMA error\n");
  119. goto out;
  120. }
  121. for (i = 0; (*pDMA2_IRQ_STATUS & DMA_RUN) != 0; i++) {
  122. if (i > TOUT_LOOP) {
  123. puts("Ethernet: tx time out\n");
  124. goto out;
  125. }
  126. }
  127. txbuf[txIdx]->FrmData->NoBytes = length;
  128. memcpy(txbuf[txIdx]->FrmData->Dest, (void *)packet, length);
  129. txbuf[txIdx]->Dma[0].START_ADDR = (u32) txbuf[txIdx]->FrmData;
  130. *pDMA2_NEXT_DESC_PTR = &txbuf[txIdx]->Dma[0];
  131. *pDMA2_CONFIG = *(u16 *) (void *)(&txdmacfg);
  132. *pEMAC_OPMODE |= TE;
  133. for (i = 0; (txbuf[txIdx]->StatusWord & TX_COMP) == 0; i++) {
  134. if (i > TOUT_LOOP) {
  135. puts("Ethernet: tx error\n");
  136. goto out;
  137. }
  138. }
  139. result = txbuf[txIdx]->StatusWord;
  140. txbuf[txIdx]->StatusWord = 0;
  141. if ((txIdx + 1) >= TX_BUF_CNT)
  142. txIdx = 0;
  143. else
  144. txIdx++;
  145. out:
  146. debug("BFIN EMAC send: length = %d\n", length);
  147. return result;
  148. }
  149. static int bfin_EMAC_recv(struct eth_device *dev)
  150. {
  151. int length = 0;
  152. for (;;) {
  153. if ((rxbuf[rxIdx]->StatusWord & RX_COMP) == 0) {
  154. length = -1;
  155. break;
  156. }
  157. if ((rxbuf[rxIdx]->StatusWord & RX_DMAO) != 0) {
  158. printf("Ethernet: rx dma overrun\n");
  159. break;
  160. }
  161. if ((rxbuf[rxIdx]->StatusWord & RX_OK) == 0) {
  162. printf("Ethernet: rx error\n");
  163. break;
  164. }
  165. length = rxbuf[rxIdx]->StatusWord & 0x000007FF;
  166. if (length <= 4) {
  167. printf("Ethernet: bad frame\n");
  168. break;
  169. }
  170. NetRxPackets[rxIdx] =
  171. (volatile uchar *)(rxbuf[rxIdx]->FrmData->Dest);
  172. NetReceive(NetRxPackets[rxIdx], length - 4);
  173. *pDMA1_IRQ_STATUS |= DMA_DONE | DMA_ERR;
  174. rxbuf[rxIdx]->StatusWord = 0x00000000;
  175. if ((rxIdx + 1) >= PKTBUFSRX)
  176. rxIdx = 0;
  177. else
  178. rxIdx++;
  179. }
  180. return length;
  181. }
  182. /**************************************************************
  183. *
  184. * Ethernet Initialization Routine
  185. *
  186. *************************************************************/
  187. /* MDC = SCLK / MDC_freq / 2 - 1 */
  188. #define MDC_FREQ_TO_DIV(mdc_freq) (get_sclk() / (mdc_freq) / 2 - 1)
  189. static int bfin_miiphy_init(struct eth_device *dev, int *opmode)
  190. {
  191. u16 phydat;
  192. size_t count;
  193. /* Enable PHY output */
  194. *pVR_CTL |= CLKBUFOE;
  195. /* Set all the pins to peripheral mode */
  196. #ifdef CONFIG_RMII
  197. /* grab RMII pins */
  198. # if defined(__ADSPBF51x__)
  199. *pPORTF_MUX = (*pPORTF_MUX & \
  200. ~(PORT_x_MUX_3_MASK | PORT_x_MUX_4_MASK | PORT_x_MUX_5_MASK)) | \
  201. PORT_x_MUX_3_FUNC_1 | PORT_x_MUX_4_FUNC_1 | PORT_x_MUX_5_FUNC_1;
  202. *pPORTF_FER |= PF8 | PF9 | PF10 | PF11 | PF12 | PF13 | PF14 | PF15;
  203. *pPORTG_MUX = (*pPORTG_MUX & ~PORT_x_MUX_0_MASK) | PORT_x_MUX_0_FUNC_1;
  204. *pPORTG_FER |= PG0 | PG1 | PG2;
  205. # elif defined(__ADSPBF52x__)
  206. *pPORTG_MUX = (*pPORTG_MUX & ~PORT_x_MUX_6_MASK) | PORT_x_MUX_6_FUNC_2;
  207. *pPORTG_FER |= PG14 | PG15;
  208. *pPORTH_MUX = (*pPORTH_MUX & ~(PORT_x_MUX_0_MASK | PORT_x_MUX_1_MASK)) | \
  209. PORT_x_MUX_0_FUNC_2 | PORT_x_MUX_1_FUNC_2;
  210. *pPORTH_FER |= PH0 | PH1 | PH2 | PH3 | PH4 | PH5 | PH6 | PH7 | PH8;
  211. # else
  212. *pPORTH_FER |= PH0 | PH1 | PH4 | PH5 | PH6 | PH8 | PH9 | PH14 | PH15;
  213. # endif
  214. #else
  215. /* grab MII & RMII pins */
  216. # if defined(__ADSPBF51x__)
  217. *pPORTF_MUX = (*pPORTF_MUX & \
  218. ~(PORT_x_MUX_0_MASK | PORT_x_MUX_1_MASK | PORT_x_MUX_3_MASK | PORT_x_MUX_4_MASK | PORT_x_MUX_5_MASK)) | \
  219. PORT_x_MUX_0_FUNC_1 | PORT_x_MUX_1_FUNC_1 | PORT_x_MUX_3_FUNC_1 | PORT_x_MUX_4_FUNC_1 | PORT_x_MUX_5_FUNC_1;
  220. *pPORTF_FER |= PF0 | PF1 | PF2 | PF3 | PF4 | PF5 | PF6 | PF8 | PF9 | PF10 | PF11 | PF12 | PF13 | PF14 | PF15;
  221. *pPORTG_MUX = (*pPORTG_MUX & ~PORT_x_MUX_0_MASK) | PORT_x_MUX_0_FUNC_1;
  222. *pPORTG_FER |= PG0 | PG1 | PG2;
  223. # elif defined(__ADSPBF52x__)
  224. *pPORTG_MUX = (*pPORTG_MUX & ~PORT_x_MUX_6_MASK) | PORT_x_MUX_6_FUNC_2;
  225. *pPORTG_FER |= PG14 | PG15;
  226. *pPORTH_MUX = PORT_x_MUX_0_FUNC_2 | PORT_x_MUX_1_FUNC_2 | PORT_x_MUX_2_FUNC_2;
  227. *pPORTH_FER = -1; /* all pins */
  228. # else
  229. *pPORTH_FER = -1; /* all pins */
  230. # endif
  231. #endif
  232. /* Odd word alignment for Receive Frame DMA word */
  233. /* Configure checksum support and rcve frame word alignment */
  234. bfin_write_EMAC_SYSCTL(RXDWA | RXCKS | SET_MDCDIV(MDC_FREQ_TO_DIV(CONFIG_PHY_CLOCK_FREQ)));
  235. /* turn on auto-negotiation and wait for link to come up */
  236. bfin_miiphy_write(dev->name, CONFIG_PHY_ADDR, MII_BMCR, BMCR_ANENABLE);
  237. count = 0;
  238. while (1) {
  239. ++count;
  240. if (bfin_miiphy_read(dev->name, CONFIG_PHY_ADDR, MII_BMSR, &phydat))
  241. return -1;
  242. if (phydat & BMSR_LSTATUS)
  243. break;
  244. if (count > 30000) {
  245. printf("%s: link down, check cable\n", dev->name);
  246. return -1;
  247. }
  248. udelay(100);
  249. }
  250. /* see what kind of link we have */
  251. if (bfin_miiphy_read(dev->name, CONFIG_PHY_ADDR, MII_LPA, &phydat))
  252. return -1;
  253. if (phydat & LPA_DUPLEX)
  254. *opmode = FDMODE;
  255. else
  256. *opmode = 0;
  257. bfin_write_EMAC_MMC_CTL(RSTC | CROLL);
  258. /* Initialize the TX DMA channel registers */
  259. *pDMA2_X_COUNT = 0;
  260. *pDMA2_X_MODIFY = 4;
  261. *pDMA2_Y_COUNT = 0;
  262. *pDMA2_Y_MODIFY = 0;
  263. /* Initialize the RX DMA channel registers */
  264. *pDMA1_X_COUNT = 0;
  265. *pDMA1_X_MODIFY = 4;
  266. *pDMA1_Y_COUNT = 0;
  267. *pDMA1_Y_MODIFY = 0;
  268. return 0;
  269. }
  270. static int bfin_EMAC_init(struct eth_device *dev, bd_t *bd)
  271. {
  272. u32 opmode;
  273. int dat;
  274. int i;
  275. debug("Eth_init: ......\n");
  276. txIdx = 0;
  277. rxIdx = 0;
  278. /* Initialize System Register */
  279. if (bfin_miiphy_init(dev, &dat) < 0)
  280. return -1;
  281. /* Initialize EMAC address */
  282. bfin_EMAC_setup_addr(bd);
  283. /* Initialize TX and RX buffer */
  284. for (i = 0; i < PKTBUFSRX; i++) {
  285. rxbuf[i] = SetupRxBuffer(i);
  286. if (i > 0) {
  287. rxbuf[i - 1]->Dma[1].NEXT_DESC_PTR =
  288. &(rxbuf[i]->Dma[0]);
  289. if (i == (PKTBUFSRX - 1))
  290. rxbuf[i]->Dma[1].NEXT_DESC_PTR =
  291. &(rxbuf[0]->Dma[0]);
  292. }
  293. }
  294. for (i = 0; i < TX_BUF_CNT; i++) {
  295. txbuf[i] = SetupTxBuffer(i);
  296. if (i > 0) {
  297. txbuf[i - 1]->Dma[1].NEXT_DESC_PTR =
  298. &(txbuf[i]->Dma[0]);
  299. if (i == (TX_BUF_CNT - 1))
  300. txbuf[i]->Dma[1].NEXT_DESC_PTR =
  301. &(txbuf[0]->Dma[0]);
  302. }
  303. }
  304. /* Set RX DMA */
  305. *pDMA1_NEXT_DESC_PTR = &rxbuf[0]->Dma[0];
  306. *pDMA1_CONFIG = *((u16 *) (void *)&rxbuf[0]->Dma[0].CONFIG);
  307. /* Wait MII done */
  308. bfin_miiphy_wait();
  309. /* We enable only RX here */
  310. /* ASTP : Enable Automatic Pad Stripping
  311. PR : Promiscuous Mode for test
  312. PSF : Receive frames with total length less than 64 bytes.
  313. FDMODE : Full Duplex Mode
  314. LB : Internal Loopback for test
  315. RE : Receiver Enable */
  316. if (dat == FDMODE)
  317. opmode = ASTP | FDMODE | PSF;
  318. else
  319. opmode = ASTP | PSF;
  320. opmode |= RE;
  321. #ifdef CONFIG_RMII
  322. opmode |= TE | RMII;
  323. #endif
  324. /* Turn on the EMAC */
  325. *pEMAC_OPMODE = opmode;
  326. return 0;
  327. }
  328. static void bfin_EMAC_halt(struct eth_device *dev)
  329. {
  330. debug("Eth_halt: ......\n");
  331. /* Turn off the EMAC */
  332. *pEMAC_OPMODE = 0x00000000;
  333. /* Turn off the EMAC RX DMA */
  334. *pDMA1_CONFIG = 0x0000;
  335. *pDMA2_CONFIG = 0x0000;
  336. }
  337. void bfin_EMAC_setup_addr(bd_t *bd)
  338. {
  339. *pEMAC_ADDRLO =
  340. bd->bi_enetaddr[0] |
  341. bd->bi_enetaddr[1] << 8 |
  342. bd->bi_enetaddr[2] << 16 |
  343. bd->bi_enetaddr[3] << 24;
  344. *pEMAC_ADDRHI =
  345. bd->bi_enetaddr[4] |
  346. bd->bi_enetaddr[5] << 8;
  347. }
  348. ADI_ETHER_BUFFER *SetupRxBuffer(int no)
  349. {
  350. ADI_ETHER_FRAME_BUFFER *frmbuf;
  351. ADI_ETHER_BUFFER *buf;
  352. int nobytes_buffer = sizeof(ADI_ETHER_BUFFER[2]) / 2; /* ensure a multi. of 4 */
  353. int total_size = nobytes_buffer + RECV_BUFSIZE;
  354. buf = (ADI_ETHER_BUFFER *) (RXBUF_BASE_ADDR + no * total_size);
  355. frmbuf =
  356. (ADI_ETHER_FRAME_BUFFER *) (RXBUF_BASE_ADDR + no * total_size +
  357. nobytes_buffer);
  358. memset(buf, 0x00, nobytes_buffer);
  359. buf->FrmData = frmbuf;
  360. memset(frmbuf, 0xfe, RECV_BUFSIZE);
  361. /* set up first desc to point to receive frame buffer */
  362. buf->Dma[0].NEXT_DESC_PTR = &(buf->Dma[1]);
  363. buf->Dma[0].START_ADDR = (u32) buf->FrmData;
  364. buf->Dma[0].CONFIG.b_DMA_EN = 1; /* enabled */
  365. buf->Dma[0].CONFIG.b_WNR = 1; /* Write to memory */
  366. buf->Dma[0].CONFIG.b_WDSIZE = 2; /* wordsize is 32 bits */
  367. buf->Dma[0].CONFIG.b_NDSIZE = 5; /* 5 half words is desc size. */
  368. buf->Dma[0].CONFIG.b_FLOW = 7; /* large desc flow */
  369. /* set up second desc to point to status word */
  370. buf->Dma[1].NEXT_DESC_PTR = &(buf->Dma[0]);
  371. buf->Dma[1].START_ADDR = (u32) & buf->IPHdrChksum;
  372. buf->Dma[1].CONFIG.b_DMA_EN = 1; /* enabled */
  373. buf->Dma[1].CONFIG.b_WNR = 1; /* Write to memory */
  374. buf->Dma[1].CONFIG.b_WDSIZE = 2; /* wordsize is 32 bits */
  375. buf->Dma[1].CONFIG.b_DI_EN = 1; /* enable interrupt */
  376. buf->Dma[1].CONFIG.b_NDSIZE = 5; /* must be 0 when FLOW is 0 */
  377. buf->Dma[1].CONFIG.b_FLOW = 7; /* stop */
  378. return buf;
  379. }
  380. ADI_ETHER_BUFFER *SetupTxBuffer(int no)
  381. {
  382. ADI_ETHER_FRAME_BUFFER *frmbuf;
  383. ADI_ETHER_BUFFER *buf;
  384. int nobytes_buffer = sizeof(ADI_ETHER_BUFFER[2]) / 2; /* ensure a multi. of 4 */
  385. int total_size = nobytes_buffer + RECV_BUFSIZE;
  386. buf = (ADI_ETHER_BUFFER *) (TXBUF_BASE_ADDR + no * total_size);
  387. frmbuf =
  388. (ADI_ETHER_FRAME_BUFFER *) (TXBUF_BASE_ADDR + no * total_size +
  389. nobytes_buffer);
  390. memset(buf, 0x00, nobytes_buffer);
  391. buf->FrmData = frmbuf;
  392. memset(frmbuf, 0x00, RECV_BUFSIZE);
  393. /* set up first desc to point to receive frame buffer */
  394. buf->Dma[0].NEXT_DESC_PTR = &(buf->Dma[1]);
  395. buf->Dma[0].START_ADDR = (u32) buf->FrmData;
  396. buf->Dma[0].CONFIG.b_DMA_EN = 1; /* enabled */
  397. buf->Dma[0].CONFIG.b_WNR = 0; /* Read to memory */
  398. buf->Dma[0].CONFIG.b_WDSIZE = 2; /* wordsize is 32 bits */
  399. buf->Dma[0].CONFIG.b_NDSIZE = 5; /* 5 half words is desc size. */
  400. buf->Dma[0].CONFIG.b_FLOW = 7; /* large desc flow */
  401. /* set up second desc to point to status word */
  402. buf->Dma[1].NEXT_DESC_PTR = &(buf->Dma[0]);
  403. buf->Dma[1].START_ADDR = (u32) & buf->StatusWord;
  404. buf->Dma[1].CONFIG.b_DMA_EN = 1; /* enabled */
  405. buf->Dma[1].CONFIG.b_WNR = 1; /* Write to memory */
  406. buf->Dma[1].CONFIG.b_WDSIZE = 2; /* wordsize is 32 bits */
  407. buf->Dma[1].CONFIG.b_DI_EN = 1; /* enable interrupt */
  408. buf->Dma[1].CONFIG.b_NDSIZE = 0; /* must be 0 when FLOW is 0 */
  409. buf->Dma[1].CONFIG.b_FLOW = 0; /* stop */
  410. return buf;
  411. }
  412. #if defined(CONFIG_POST) && defined(CONFIG_SYS_POST_ETHER)
  413. int ether_post_test(int flags)
  414. {
  415. uchar buf[64];
  416. int i, value = 0;
  417. int length;
  418. printf("\n--------");
  419. bfin_EMAC_init(NULL, NULL);
  420. /* construct the package */
  421. buf[0] = buf[6] = (unsigned char)(*pEMAC_ADDRLO & 0xFF);
  422. buf[1] = buf[7] = (unsigned char)((*pEMAC_ADDRLO & 0xFF00) >> 8);
  423. buf[2] = buf[8] = (unsigned char)((*pEMAC_ADDRLO & 0xFF0000) >> 16);
  424. buf[3] = buf[9] = (unsigned char)((*pEMAC_ADDRLO & 0xFF000000) >> 24);
  425. buf[4] = buf[10] = (unsigned char)(*pEMAC_ADDRHI & 0xFF);
  426. buf[5] = buf[11] = (unsigned char)((*pEMAC_ADDRHI & 0xFF00) >> 8);
  427. buf[12] = 0x08; /* Type: ARP */
  428. buf[13] = 0x06;
  429. buf[14] = 0x00; /* Hardware type: Ethernet */
  430. buf[15] = 0x01;
  431. buf[16] = 0x08; /* Protocal type: IP */
  432. buf[17] = 0x00;
  433. buf[18] = 0x06; /* Hardware size */
  434. buf[19] = 0x04; /* Protocol size */
  435. buf[20] = 0x00; /* Opcode: request */
  436. buf[21] = 0x01;
  437. for (i = 0; i < 42; i++)
  438. buf[i + 22] = i;
  439. printf("--------Send 64 bytes......\n");
  440. bfin_EMAC_send(NULL, (volatile void *)buf, 64);
  441. for (i = 0; i < 100; i++) {
  442. udelay(10000);
  443. if ((rxbuf[rxIdx]->StatusWord & RX_COMP) != 0) {
  444. value = 1;
  445. break;
  446. }
  447. }
  448. if (value == 0) {
  449. printf("--------EMAC can't receive any data\n");
  450. eth_halt();
  451. return -1;
  452. }
  453. length = rxbuf[rxIdx]->StatusWord & 0x000007FF - 4;
  454. for (i = 0; i < length; i++) {
  455. if (rxbuf[rxIdx]->FrmData->Dest[i] != buf[i]) {
  456. printf("--------EMAC receive error data!\n");
  457. eth_halt();
  458. return -1;
  459. }
  460. }
  461. printf("--------receive %d bytes, matched\n", length);
  462. bfin_EMAC_halt(NULL);
  463. return 0;
  464. }
  465. #endif