ether.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Ethernet driver for TI TMS320DM644x (DaVinci) chips.
  3. *
  4. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  5. *
  6. * Parts shamelessly stolen from TI's dm644x_emac.c. Original copyright
  7. * follows:
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * dm644x_emac.c
  12. *
  13. * TI DaVinci (DM644X) EMAC peripheral driver source for DV-EVM
  14. *
  15. * Copyright (C) 2005 Texas Instruments.
  16. *
  17. * ----------------------------------------------------------------------------
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. * ----------------------------------------------------------------------------
  33. * Modifications:
  34. * ver. 1.0: Sep 2005, Anant Gole - Created EMAC version for uBoot.
  35. * ver 1.1: Nov 2005, Anant Gole - Extended the RX logic for multiple descriptors
  36. *
  37. */
  38. #include <common.h>
  39. #include <command.h>
  40. #include <net.h>
  41. #include <miiphy.h>
  42. #include <asm/arch/emac_defs.h>
  43. #ifdef CONFIG_DRIVER_TI_EMAC
  44. #ifdef CONFIG_CMD_NET
  45. unsigned int emac_dbg = 0;
  46. #define debug_emac(fmt,args...) if (emac_dbg) printf(fmt,##args)
  47. /* Internal static functions */
  48. static int dm644x_eth_hw_init (void);
  49. static int dm644x_eth_open (void);
  50. static int dm644x_eth_close (void);
  51. static int dm644x_eth_send_packet (volatile void *packet, int length);
  52. static int dm644x_eth_rcv_packet (void);
  53. static void dm644x_eth_mdio_enable(void);
  54. static int gen_init_phy(int phy_addr);
  55. static int gen_is_phy_connected(int phy_addr);
  56. static int gen_get_link_speed(int phy_addr);
  57. static int gen_auto_negotiate(int phy_addr);
  58. /* Wrappers exported to the U-Boot proper */
  59. int eth_hw_init(void)
  60. {
  61. return(dm644x_eth_hw_init());
  62. }
  63. int eth_init(bd_t * bd)
  64. {
  65. return(dm644x_eth_open());
  66. }
  67. void eth_halt(void)
  68. {
  69. dm644x_eth_close();
  70. }
  71. int eth_send(volatile void *packet, int length)
  72. {
  73. return(dm644x_eth_send_packet(packet, length));
  74. }
  75. int eth_rx(void)
  76. {
  77. return(dm644x_eth_rcv_packet());
  78. }
  79. void eth_mdio_enable(void)
  80. {
  81. dm644x_eth_mdio_enable();
  82. }
  83. /* End of wrappers */
  84. static u_int8_t dm644x_eth_mac_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  85. /*
  86. * This function must be called before emac_open() if you want to override
  87. * the default mac address.
  88. */
  89. void dm644x_eth_set_mac_addr(const u_int8_t *addr)
  90. {
  91. int i;
  92. for (i = 0; i < sizeof (dm644x_eth_mac_addr); i++) {
  93. dm644x_eth_mac_addr[i] = addr[i];
  94. }
  95. }
  96. /* EMAC Addresses */
  97. static volatile emac_regs *adap_emac = (emac_regs *)EMAC_BASE_ADDR;
  98. static volatile ewrap_regs *adap_ewrap = (ewrap_regs *)EMAC_WRAPPER_BASE_ADDR;
  99. static volatile mdio_regs *adap_mdio = (mdio_regs *)EMAC_MDIO_BASE_ADDR;
  100. /* EMAC descriptors */
  101. static volatile emac_desc *emac_rx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE);
  102. static volatile emac_desc *emac_tx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
  103. static volatile emac_desc *emac_rx_active_head = 0;
  104. static volatile emac_desc *emac_rx_active_tail = 0;
  105. static int emac_rx_queue_active = 0;
  106. /* Receive packet buffers */
  107. static unsigned char emac_rx_buffers[EMAC_MAX_RX_BUFFERS * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
  108. /* PHY address for a discovered PHY (0xff - not found) */
  109. static volatile u_int8_t active_phy_addr = 0xff;
  110. phy_t phy;
  111. static void dm644x_eth_mdio_enable(void)
  112. {
  113. u_int32_t clkdiv;
  114. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  115. adap_mdio->CONTROL = (clkdiv & 0xff) |
  116. MDIO_CONTROL_ENABLE |
  117. MDIO_CONTROL_FAULT |
  118. MDIO_CONTROL_FAULT_ENABLE;
  119. while (adap_mdio->CONTROL & MDIO_CONTROL_IDLE) {;}
  120. }
  121. /*
  122. * Tries to find an active connected PHY. Returns 1 if address if found.
  123. * If no active PHY (or more than one PHY) found returns 0.
  124. * Sets active_phy_addr variable.
  125. */
  126. static int dm644x_eth_phy_detect(void)
  127. {
  128. u_int32_t phy_act_state;
  129. int i;
  130. active_phy_addr = 0xff;
  131. if ((phy_act_state = adap_mdio->ALIVE) == 0)
  132. return(0); /* No active PHYs */
  133. debug_emac("dm644x_eth_phy_detect(), ALIVE = 0x%08x\n", phy_act_state);
  134. for (i = 0; i < 32; i++) {
  135. if (phy_act_state & (1 << i)) {
  136. if (phy_act_state & ~(1 << i))
  137. return(0); /* More than one PHY */
  138. else {
  139. active_phy_addr = i;
  140. return(1);
  141. }
  142. }
  143. }
  144. return(0); /* Just to make GCC happy */
  145. }
  146. /* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise */
  147. int dm644x_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data)
  148. {
  149. int tmp;
  150. while (adap_mdio->USERACCESS0 & MDIO_USERACCESS0_GO) {;}
  151. adap_mdio->USERACCESS0 = MDIO_USERACCESS0_GO |
  152. MDIO_USERACCESS0_WRITE_READ |
  153. ((reg_num & 0x1f) << 21) |
  154. ((phy_addr & 0x1f) << 16);
  155. /* Wait for command to complete */
  156. while ((tmp = adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO) {;}
  157. if (tmp & MDIO_USERACCESS0_ACK) {
  158. *data = tmp & 0xffff;
  159. return(1);
  160. }
  161. *data = -1;
  162. return(0);
  163. }
  164. /* Write to a PHY register via MDIO inteface. Blocks until operation is complete. */
  165. int dm644x_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data)
  166. {
  167. while (adap_mdio->USERACCESS0 & MDIO_USERACCESS0_GO) {;}
  168. adap_mdio->USERACCESS0 = MDIO_USERACCESS0_GO |
  169. MDIO_USERACCESS0_WRITE_WRITE |
  170. ((reg_num & 0x1f) << 21) |
  171. ((phy_addr & 0x1f) << 16) |
  172. (data & 0xffff);
  173. /* Wait for command to complete */
  174. while (adap_mdio->USERACCESS0 & MDIO_USERACCESS0_GO) {;}
  175. return(1);
  176. }
  177. /* PHY functions for a generic PHY */
  178. static int gen_init_phy(int phy_addr)
  179. {
  180. int ret = 1;
  181. if (gen_get_link_speed(phy_addr)) {
  182. /* Try another time */
  183. ret = gen_get_link_speed(phy_addr);
  184. }
  185. return(ret);
  186. }
  187. static int gen_is_phy_connected(int phy_addr)
  188. {
  189. u_int16_t dummy;
  190. return(dm644x_eth_phy_read(phy_addr, PHY_PHYIDR1, &dummy));
  191. }
  192. static int gen_get_link_speed(int phy_addr)
  193. {
  194. u_int16_t tmp;
  195. if (dm644x_eth_phy_read(phy_addr, MII_STATUS_REG, &tmp) && (tmp & 0x04))
  196. return(1);
  197. return(0);
  198. }
  199. static int gen_auto_negotiate(int phy_addr)
  200. {
  201. u_int16_t tmp;
  202. if (!dm644x_eth_phy_read(phy_addr, PHY_BMCR, &tmp))
  203. return(0);
  204. /* Restart Auto_negotiation */
  205. tmp |= PHY_BMCR_AUTON;
  206. dm644x_eth_phy_write(phy_addr, PHY_BMCR, tmp);
  207. /*check AutoNegotiate complete */
  208. udelay (10000);
  209. if (!dm644x_eth_phy_read(phy_addr, PHY_BMSR, &tmp))
  210. return(0);
  211. if (!(tmp & PHY_BMSR_AUTN_COMP))
  212. return(0);
  213. return(gen_get_link_speed(phy_addr));
  214. }
  215. /* End of generic PHY functions */
  216. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  217. static int dm644x_mii_phy_read(char *devname, unsigned char addr, unsigned char reg, unsigned short *value)
  218. {
  219. return(dm644x_eth_phy_read(addr, reg, value) ? 0 : 1);
  220. }
  221. static int dm644x_mii_phy_write(char *devname, unsigned char addr, unsigned char reg, unsigned short value)
  222. {
  223. return(dm644x_eth_phy_write(addr, reg, value) ? 0 : 1);
  224. }
  225. int dm644x_eth_miiphy_initialize(bd_t *bis)
  226. {
  227. miiphy_register(phy.name, dm644x_mii_phy_read, dm644x_mii_phy_write);
  228. return(1);
  229. }
  230. #endif
  231. /*
  232. * This function initializes the emac hardware. It does NOT initialize
  233. * EMAC modules power or pin multiplexors, that is done by board_init()
  234. * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  235. */
  236. static int dm644x_eth_hw_init(void)
  237. {
  238. u_int32_t phy_id;
  239. u_int16_t tmp;
  240. int i;
  241. dm644x_eth_mdio_enable();
  242. for (i = 0; i < 256; i++) {
  243. if (adap_mdio->ALIVE)
  244. break;
  245. udelay(10);
  246. }
  247. if (i >= 256) {
  248. printf("No ETH PHY detected!!!\n");
  249. return(0);
  250. }
  251. /* Find if a PHY is connected and get it's address */
  252. if (!dm644x_eth_phy_detect())
  253. return(0);
  254. /* Get PHY ID and initialize phy_ops for a detected PHY */
  255. if (!dm644x_eth_phy_read(active_phy_addr, PHY_PHYIDR1, &tmp)) {
  256. active_phy_addr = 0xff;
  257. return(0);
  258. }
  259. phy_id = (tmp << 16) & 0xffff0000;
  260. if (!dm644x_eth_phy_read(active_phy_addr, PHY_PHYIDR2, &tmp)) {
  261. active_phy_addr = 0xff;
  262. return(0);
  263. }
  264. phy_id |= tmp & 0x0000ffff;
  265. switch (phy_id) {
  266. case PHY_LXT972:
  267. sprintf(phy.name, "LXT972 @ 0x%02x", active_phy_addr);
  268. phy.init = lxt972_init_phy;
  269. phy.is_phy_connected = lxt972_is_phy_connected;
  270. phy.get_link_speed = lxt972_get_link_speed;
  271. phy.auto_negotiate = lxt972_auto_negotiate;
  272. break;
  273. case PHY_DP83848:
  274. sprintf(phy.name, "DP83848 @ 0x%02x", active_phy_addr);
  275. phy.init = dp83848_init_phy;
  276. phy.is_phy_connected = dp83848_is_phy_connected;
  277. phy.get_link_speed = dp83848_get_link_speed;
  278. phy.auto_negotiate = dp83848_auto_negotiate;
  279. break;
  280. default:
  281. sprintf(phy.name, "GENERIC @ 0x%02x", active_phy_addr);
  282. phy.init = gen_init_phy;
  283. phy.is_phy_connected = gen_is_phy_connected;
  284. phy.get_link_speed = gen_get_link_speed;
  285. phy.auto_negotiate = gen_auto_negotiate;
  286. }
  287. return(1);
  288. }
  289. /* Eth device open */
  290. static int dm644x_eth_open(void)
  291. {
  292. dv_reg_p addr;
  293. u_int32_t clkdiv, cnt;
  294. volatile emac_desc *rx_desc;
  295. debug_emac("+ emac_open\n");
  296. /* Reset EMAC module and disable interrupts in wrapper */
  297. adap_emac->SOFTRESET = 1;
  298. while (adap_emac->SOFTRESET != 0) {;}
  299. adap_ewrap->EWCTL = 0;
  300. for (cnt = 0; cnt < 5; cnt++) {
  301. clkdiv = adap_ewrap->EWCTL;
  302. }
  303. rx_desc = emac_rx_desc;
  304. adap_emac->TXCONTROL = 0x01;
  305. adap_emac->RXCONTROL = 0x01;
  306. /* Set MAC Addresses & Init multicast Hash to 0 (disable any multicast receive) */
  307. /* Using channel 0 only - other channels are disabled */
  308. adap_emac->MACINDEX = 0;
  309. adap_emac->MACADDRHI =
  310. (dm644x_eth_mac_addr[3] << 24) |
  311. (dm644x_eth_mac_addr[2] << 16) |
  312. (dm644x_eth_mac_addr[1] << 8) |
  313. (dm644x_eth_mac_addr[0]);
  314. adap_emac->MACADDRLO =
  315. (dm644x_eth_mac_addr[5] << 8) |
  316. (dm644x_eth_mac_addr[4]);
  317. adap_emac->MACHASH1 = 0;
  318. adap_emac->MACHASH2 = 0;
  319. /* Set source MAC address - REQUIRED */
  320. adap_emac->MACSRCADDRHI =
  321. (dm644x_eth_mac_addr[3] << 24) |
  322. (dm644x_eth_mac_addr[2] << 16) |
  323. (dm644x_eth_mac_addr[1] << 8) |
  324. (dm644x_eth_mac_addr[0]);
  325. adap_emac->MACSRCADDRLO =
  326. (dm644x_eth_mac_addr[4] << 8) |
  327. (dm644x_eth_mac_addr[5]);
  328. /* Set DMA 8 TX / 8 RX Head pointers to 0 */
  329. addr = &adap_emac->TX0HDP;
  330. for(cnt = 0; cnt < 16; cnt++)
  331. *addr++ = 0;
  332. addr = &adap_emac->RX0HDP;
  333. for(cnt = 0; cnt < 16; cnt++)
  334. *addr++ = 0;
  335. /* Clear Statistics (do this before setting MacControl register) */
  336. addr = &adap_emac->RXGOODFRAMES;
  337. for(cnt = 0; cnt < EMAC_NUM_STATS; cnt++)
  338. *addr++ = 0;
  339. /* No multicast addressing */
  340. adap_emac->MACHASH1 = 0;
  341. adap_emac->MACHASH2 = 0;
  342. /* Create RX queue and set receive process in place */
  343. emac_rx_active_head = emac_rx_desc;
  344. for (cnt = 0; cnt < EMAC_MAX_RX_BUFFERS; cnt++) {
  345. rx_desc->next = (u_int32_t)(rx_desc + 1);
  346. rx_desc->buffer = &emac_rx_buffers[cnt * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
  347. rx_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
  348. rx_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
  349. rx_desc++;
  350. }
  351. /* Set the last descriptor's "next" parameter to 0 to end the RX desc list */
  352. rx_desc--;
  353. rx_desc->next = 0;
  354. emac_rx_active_tail = rx_desc;
  355. emac_rx_queue_active = 1;
  356. /* Enable TX/RX */
  357. adap_emac->RXMAXLEN = EMAC_MAX_ETHERNET_PKT_SIZE;
  358. adap_emac->RXBUFFEROFFSET = 0;
  359. /* No fancy configs - Use this for promiscous for debug - EMAC_RXMBPENABLE_RXCAFEN_ENABLE */
  360. adap_emac->RXMBPENABLE = EMAC_RXMBPENABLE_RXBROADEN;
  361. /* Enable ch 0 only */
  362. adap_emac->RXUNICASTSET = 0x01;
  363. /* Enable MII interface and Full duplex mode */
  364. adap_emac->MACCONTROL = (EMAC_MACCONTROL_MIIEN_ENABLE | EMAC_MACCONTROL_FULLDUPLEX_ENABLE);
  365. /* Init MDIO & get link state */
  366. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  367. adap_mdio->CONTROL = ((clkdiv & 0xff) | MDIO_CONTROL_ENABLE | MDIO_CONTROL_FAULT);
  368. if (!phy.get_link_speed(active_phy_addr))
  369. return(0);
  370. /* Start receive process */
  371. adap_emac->RX0HDP = (u_int32_t)emac_rx_desc;
  372. debug_emac("- emac_open\n");
  373. return(1);
  374. }
  375. /* EMAC Channel Teardown */
  376. static void dm644x_eth_ch_teardown(int ch)
  377. {
  378. dv_reg dly = 0xff;
  379. dv_reg cnt;
  380. debug_emac("+ emac_ch_teardown\n");
  381. if (ch == EMAC_CH_TX) {
  382. /* Init TX channel teardown */
  383. adap_emac->TXTEARDOWN = 1;
  384. for(cnt = 0; cnt != 0xfffffffc; cnt = adap_emac->TX0CP) {
  385. /* Wait here for Tx teardown completion interrupt to occur
  386. * Note: A task delay can be called here to pend rather than
  387. * occupying CPU cycles - anyway it has been found that teardown
  388. * takes very few cpu cycles and does not affect functionality */
  389. dly--;
  390. udelay(1);
  391. if (dly == 0)
  392. break;
  393. }
  394. adap_emac->TX0CP = cnt;
  395. adap_emac->TX0HDP = 0;
  396. } else {
  397. /* Init RX channel teardown */
  398. adap_emac->RXTEARDOWN = 1;
  399. for(cnt = 0; cnt != 0xfffffffc; cnt = adap_emac->RX0CP) {
  400. /* Wait here for Rx teardown completion interrupt to occur
  401. * Note: A task delay can be called here to pend rather than
  402. * occupying CPU cycles - anyway it has been found that teardown
  403. * takes very few cpu cycles and does not affect functionality */
  404. dly--;
  405. udelay(1);
  406. if (dly == 0)
  407. break;
  408. }
  409. adap_emac->RX0CP = cnt;
  410. adap_emac->RX0HDP = 0;
  411. }
  412. debug_emac("- emac_ch_teardown\n");
  413. }
  414. /* Eth device close */
  415. static int dm644x_eth_close(void)
  416. {
  417. debug_emac("+ emac_close\n");
  418. dm644x_eth_ch_teardown(EMAC_CH_TX); /* TX Channel teardown */
  419. dm644x_eth_ch_teardown(EMAC_CH_RX); /* RX Channel teardown */
  420. /* Reset EMAC module and disable interrupts in wrapper */
  421. adap_emac->SOFTRESET = 1;
  422. adap_ewrap->EWCTL = 0;
  423. debug_emac("- emac_close\n");
  424. return(1);
  425. }
  426. static int tx_send_loop = 0;
  427. /*
  428. * This function sends a single packet on the network and returns
  429. * positive number (number of bytes transmitted) or negative for error
  430. */
  431. static int dm644x_eth_send_packet(volatile void *packet, int length)
  432. {
  433. int ret_status = -1;
  434. tx_send_loop = 0;
  435. /* Return error if no link */
  436. if (!phy.get_link_speed(active_phy_addr))
  437. {
  438. printf("WARN: emac_send_packet: No link\n");
  439. return (ret_status);
  440. }
  441. /* Check packet size and if < EMAC_MIN_ETHERNET_PKT_SIZE, pad it up */
  442. if (length < EMAC_MIN_ETHERNET_PKT_SIZE)
  443. {
  444. length = EMAC_MIN_ETHERNET_PKT_SIZE;
  445. }
  446. /* Populate the TX descriptor */
  447. emac_tx_desc->next = 0;
  448. emac_tx_desc->buffer = (u_int8_t *)packet;
  449. emac_tx_desc->buff_off_len = (length & 0xffff);
  450. emac_tx_desc->pkt_flag_len = ((length & 0xffff) |
  451. EMAC_CPPI_SOP_BIT |
  452. EMAC_CPPI_OWNERSHIP_BIT |
  453. EMAC_CPPI_EOP_BIT);
  454. /* Send the packet */
  455. adap_emac->TX0HDP = (unsigned int)emac_tx_desc;
  456. /* Wait for packet to complete or link down */
  457. while (1) {
  458. if (!phy.get_link_speed(active_phy_addr)) {
  459. dm644x_eth_ch_teardown(EMAC_CH_TX);
  460. return (ret_status);
  461. }
  462. if (adap_emac->TXINTSTATRAW & 0x01) {
  463. ret_status = length;
  464. break;
  465. }
  466. tx_send_loop++;
  467. }
  468. return(ret_status);
  469. }
  470. /*
  471. * This function handles receipt of a packet from the network
  472. */
  473. static int dm644x_eth_rcv_packet(void)
  474. {
  475. volatile emac_desc *rx_curr_desc;
  476. volatile emac_desc *curr_desc;
  477. volatile emac_desc *tail_desc;
  478. int status, ret = -1;
  479. rx_curr_desc = emac_rx_active_head;
  480. status = rx_curr_desc->pkt_flag_len;
  481. if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
  482. if (status & EMAC_CPPI_RX_ERROR_FRAME) {
  483. /* Error in packet - discard it and requeue desc */
  484. printf("WARN: emac_rcv_pkt: Error in packet\n");
  485. } else {
  486. NetReceive(rx_curr_desc->buffer, (rx_curr_desc->buff_off_len & 0xffff));
  487. ret = rx_curr_desc->buff_off_len & 0xffff;
  488. }
  489. /* Ack received packet descriptor */
  490. adap_emac->RX0CP = (unsigned int)rx_curr_desc;
  491. curr_desc = rx_curr_desc;
  492. emac_rx_active_head = (volatile emac_desc *)rx_curr_desc->next;
  493. if (status & EMAC_CPPI_EOQ_BIT) {
  494. if (emac_rx_active_head) {
  495. adap_emac->RX0HDP = (unsigned int)emac_rx_active_head;
  496. } else {
  497. emac_rx_queue_active = 0;
  498. printf("INFO:emac_rcv_packet: RX Queue not active\n");
  499. }
  500. }
  501. /* Recycle RX descriptor */
  502. rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
  503. rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
  504. rx_curr_desc->next = 0;
  505. if (emac_rx_active_head == 0) {
  506. printf("INFO: emac_rcv_pkt: active queue head = 0\n");
  507. emac_rx_active_head = curr_desc;
  508. emac_rx_active_tail = curr_desc;
  509. if (emac_rx_queue_active != 0) {
  510. adap_emac->RX0HDP = (unsigned int)emac_rx_active_head;
  511. printf("INFO: emac_rcv_pkt: active queue head = 0, HDP fired\n");
  512. emac_rx_queue_active = 1;
  513. }
  514. } else {
  515. tail_desc = emac_rx_active_tail;
  516. emac_rx_active_tail = curr_desc;
  517. tail_desc->next = (unsigned int)curr_desc;
  518. status = tail_desc->pkt_flag_len;
  519. if (status & EMAC_CPPI_EOQ_BIT) {
  520. adap_emac->RX0HDP = (unsigned int)curr_desc;
  521. status &= ~EMAC_CPPI_EOQ_BIT;
  522. tail_desc->pkt_flag_len = status;
  523. }
  524. }
  525. return(ret);
  526. }
  527. return(0);
  528. }
  529. #endif /* CONFIG_CMD_NET */
  530. #endif /* CONFIG_DRIVER_TI_EMAC */