ether.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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) || defined(CONFIG_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. printf("Ethernet PHY: %s\n", phy.name);
  288. return(1);
  289. }
  290. /* Eth device open */
  291. static int dm644x_eth_open(void)
  292. {
  293. dv_reg_p addr;
  294. u_int32_t clkdiv, cnt;
  295. volatile emac_desc *rx_desc;
  296. debug_emac("+ emac_open\n");
  297. /* Reset EMAC module and disable interrupts in wrapper */
  298. adap_emac->SOFTRESET = 1;
  299. while (adap_emac->SOFTRESET != 0) {;}
  300. adap_ewrap->EWCTL = 0;
  301. for (cnt = 0; cnt < 5; cnt++) {
  302. clkdiv = adap_ewrap->EWCTL;
  303. }
  304. rx_desc = emac_rx_desc;
  305. adap_emac->TXCONTROL = 0x01;
  306. adap_emac->RXCONTROL = 0x01;
  307. /* Set MAC Addresses & Init multicast Hash to 0 (disable any multicast receive) */
  308. /* Using channel 0 only - other channels are disabled */
  309. adap_emac->MACINDEX = 0;
  310. adap_emac->MACADDRHI =
  311. (dm644x_eth_mac_addr[3] << 24) |
  312. (dm644x_eth_mac_addr[2] << 16) |
  313. (dm644x_eth_mac_addr[1] << 8) |
  314. (dm644x_eth_mac_addr[0]);
  315. adap_emac->MACADDRLO =
  316. (dm644x_eth_mac_addr[5] << 8) |
  317. (dm644x_eth_mac_addr[4]);
  318. adap_emac->MACHASH1 = 0;
  319. adap_emac->MACHASH2 = 0;
  320. /* Set source MAC address - REQUIRED */
  321. adap_emac->MACSRCADDRHI =
  322. (dm644x_eth_mac_addr[3] << 24) |
  323. (dm644x_eth_mac_addr[2] << 16) |
  324. (dm644x_eth_mac_addr[1] << 8) |
  325. (dm644x_eth_mac_addr[0]);
  326. adap_emac->MACSRCADDRLO =
  327. (dm644x_eth_mac_addr[4] << 8) |
  328. (dm644x_eth_mac_addr[5]);
  329. /* Set DMA 8 TX / 8 RX Head pointers to 0 */
  330. addr = &adap_emac->TX0HDP;
  331. for(cnt = 0; cnt < 16; cnt++)
  332. *addr++ = 0;
  333. addr = &adap_emac->RX0HDP;
  334. for(cnt = 0; cnt < 16; cnt++)
  335. *addr++ = 0;
  336. /* Clear Statistics (do this before setting MacControl register) */
  337. addr = &adap_emac->RXGOODFRAMES;
  338. for(cnt = 0; cnt < EMAC_NUM_STATS; cnt++)
  339. *addr++ = 0;
  340. /* No multicast addressing */
  341. adap_emac->MACHASH1 = 0;
  342. adap_emac->MACHASH2 = 0;
  343. /* Create RX queue and set receive process in place */
  344. emac_rx_active_head = emac_rx_desc;
  345. for (cnt = 0; cnt < EMAC_MAX_RX_BUFFERS; cnt++) {
  346. rx_desc->next = (u_int32_t)(rx_desc + 1);
  347. rx_desc->buffer = &emac_rx_buffers[cnt * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
  348. rx_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
  349. rx_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
  350. rx_desc++;
  351. }
  352. /* Set the last descriptor's "next" parameter to 0 to end the RX desc list */
  353. rx_desc--;
  354. rx_desc->next = 0;
  355. emac_rx_active_tail = rx_desc;
  356. emac_rx_queue_active = 1;
  357. /* Enable TX/RX */
  358. adap_emac->RXMAXLEN = EMAC_MAX_ETHERNET_PKT_SIZE;
  359. adap_emac->RXBUFFEROFFSET = 0;
  360. /* No fancy configs - Use this for promiscous for debug - EMAC_RXMBPENABLE_RXCAFEN_ENABLE */
  361. adap_emac->RXMBPENABLE = EMAC_RXMBPENABLE_RXBROADEN;
  362. /* Enable ch 0 only */
  363. adap_emac->RXUNICASTSET = 0x01;
  364. /* Enable MII interface and Full duplex mode */
  365. adap_emac->MACCONTROL = (EMAC_MACCONTROL_MIIEN_ENABLE | EMAC_MACCONTROL_FULLDUPLEX_ENABLE);
  366. /* Init MDIO & get link state */
  367. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  368. adap_mdio->CONTROL = ((clkdiv & 0xff) | MDIO_CONTROL_ENABLE | MDIO_CONTROL_FAULT);
  369. if (!phy.get_link_speed(active_phy_addr))
  370. return(0);
  371. /* Start receive process */
  372. adap_emac->RX0HDP = (u_int32_t)emac_rx_desc;
  373. debug_emac("- emac_open\n");
  374. return(1);
  375. }
  376. /* EMAC Channel Teardown */
  377. static void dm644x_eth_ch_teardown(int ch)
  378. {
  379. dv_reg dly = 0xff;
  380. dv_reg cnt;
  381. debug_emac("+ emac_ch_teardown\n");
  382. if (ch == EMAC_CH_TX) {
  383. /* Init TX channel teardown */
  384. adap_emac->TXTEARDOWN = 1;
  385. for(cnt = 0; cnt != 0xfffffffc; cnt = adap_emac->TX0CP) {
  386. /* Wait here for Tx teardown completion interrupt to occur
  387. * Note: A task delay can be called here to pend rather than
  388. * occupying CPU cycles - anyway it has been found that teardown
  389. * takes very few cpu cycles and does not affect functionality */
  390. dly--;
  391. udelay(1);
  392. if (dly == 0)
  393. break;
  394. }
  395. adap_emac->TX0CP = cnt;
  396. adap_emac->TX0HDP = 0;
  397. } else {
  398. /* Init RX channel teardown */
  399. adap_emac->RXTEARDOWN = 1;
  400. for(cnt = 0; cnt != 0xfffffffc; cnt = adap_emac->RX0CP) {
  401. /* Wait here for Rx teardown completion interrupt to occur
  402. * Note: A task delay can be called here to pend rather than
  403. * occupying CPU cycles - anyway it has been found that teardown
  404. * takes very few cpu cycles and does not affect functionality */
  405. dly--;
  406. udelay(1);
  407. if (dly == 0)
  408. break;
  409. }
  410. adap_emac->RX0CP = cnt;
  411. adap_emac->RX0HDP = 0;
  412. }
  413. debug_emac("- emac_ch_teardown\n");
  414. }
  415. /* Eth device close */
  416. static int dm644x_eth_close(void)
  417. {
  418. debug_emac("+ emac_close\n");
  419. dm644x_eth_ch_teardown(EMAC_CH_TX); /* TX Channel teardown */
  420. dm644x_eth_ch_teardown(EMAC_CH_RX); /* RX Channel teardown */
  421. /* Reset EMAC module and disable interrupts in wrapper */
  422. adap_emac->SOFTRESET = 1;
  423. adap_ewrap->EWCTL = 0;
  424. debug_emac("- emac_close\n");
  425. return(1);
  426. }
  427. static int tx_send_loop = 0;
  428. /*
  429. * This function sends a single packet on the network and returns
  430. * positive number (number of bytes transmitted) or negative for error
  431. */
  432. static int dm644x_eth_send_packet (volatile void *packet, int length)
  433. {
  434. int ret_status = -1;
  435. tx_send_loop = 0;
  436. /* Return error if no link */
  437. if (!phy.get_link_speed (active_phy_addr)) {
  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. length = EMAC_MIN_ETHERNET_PKT_SIZE;
  444. }
  445. /* Populate the TX descriptor */
  446. emac_tx_desc->next = 0;
  447. emac_tx_desc->buffer = (u_int8_t *) packet;
  448. emac_tx_desc->buff_off_len = (length & 0xffff);
  449. emac_tx_desc->pkt_flag_len = ((length & 0xffff) |
  450. EMAC_CPPI_SOP_BIT |
  451. EMAC_CPPI_OWNERSHIP_BIT |
  452. EMAC_CPPI_EOP_BIT);
  453. /* Send the packet */
  454. adap_emac->TX0HDP = (unsigned int) emac_tx_desc;
  455. /* Wait for packet to complete or link down */
  456. while (1) {
  457. if (!phy.get_link_speed (active_phy_addr)) {
  458. dm644x_eth_ch_teardown (EMAC_CH_TX);
  459. return (ret_status);
  460. }
  461. if (adap_emac->TXINTSTATRAW & 0x01) {
  462. ret_status = length;
  463. break;
  464. }
  465. tx_send_loop++;
  466. }
  467. return (ret_status);
  468. }
  469. /*
  470. * This function handles receipt of a packet from the network
  471. */
  472. static int dm644x_eth_rcv_packet (void)
  473. {
  474. volatile emac_desc *rx_curr_desc;
  475. volatile emac_desc *curr_desc;
  476. volatile emac_desc *tail_desc;
  477. int status, ret = -1;
  478. rx_curr_desc = emac_rx_active_head;
  479. status = rx_curr_desc->pkt_flag_len;
  480. if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
  481. if (status & EMAC_CPPI_RX_ERROR_FRAME) {
  482. /* Error in packet - discard it and requeue desc */
  483. printf ("WARN: emac_rcv_pkt: Error in packet\n");
  484. } else {
  485. NetReceive (rx_curr_desc->buffer,
  486. (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 =
  493. (volatile emac_desc *) rx_curr_desc->next;
  494. if (status & EMAC_CPPI_EOQ_BIT) {
  495. if (emac_rx_active_head) {
  496. adap_emac->RX0HDP =
  497. (unsigned int) emac_rx_active_head;
  498. } else {
  499. emac_rx_queue_active = 0;
  500. printf ("INFO:emac_rcv_packet: RX Queue not active\n");
  501. }
  502. }
  503. /* Recycle RX descriptor */
  504. rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
  505. rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
  506. rx_curr_desc->next = 0;
  507. if (emac_rx_active_head == 0) {
  508. printf ("INFO: emac_rcv_pkt: active queue head = 0\n");
  509. emac_rx_active_head = curr_desc;
  510. emac_rx_active_tail = curr_desc;
  511. if (emac_rx_queue_active != 0) {
  512. adap_emac->RX0HDP =
  513. (unsigned int) emac_rx_active_head;
  514. printf ("INFO: emac_rcv_pkt: active queue head = 0, HDP fired\n");
  515. emac_rx_queue_active = 1;
  516. }
  517. } else {
  518. tail_desc = emac_rx_active_tail;
  519. emac_rx_active_tail = curr_desc;
  520. tail_desc->next = (unsigned int) curr_desc;
  521. status = tail_desc->pkt_flag_len;
  522. if (status & EMAC_CPPI_EOQ_BIT) {
  523. adap_emac->RX0HDP = (unsigned int) curr_desc;
  524. status &= ~EMAC_CPPI_EOQ_BIT;
  525. tail_desc->pkt_flag_len = status;
  526. }
  527. }
  528. return (ret);
  529. }
  530. return (0);
  531. }
  532. #endif /* CONFIG_CMD_NET */
  533. #endif /* CONFIG_DRIVER_TI_EMAC */