void setup_rx_bds(xemacpsif_s *xemacpsif, XEmacPs_BdRing *rxring) { XEmacPs_Bd *rxbd; XStatus status; struct pbuf *p; u32_t freebds; u32_t bdindex; u32_t *temp; u32_t index = 0; if (xemacpsif->emacps.Config.BaseAddress != XPAR_XEMACPS_0_BASEADDR) { index = sizeof(s32_t) * XLWIP_CONFIG_N_RX_DESC; } freebds = XEmacPs_BdRingGetFreeCnt (rxring); while (freebds > 0) { freebds--; p = pbuf_alloc(PBUF_RAW, XEMACPS_MAX_FRAME_SIZE, PBUF_POOL); if (!p) { #if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.drop++; #endif printf("unable to alloc pbuf in recv_handler\r\n"); return; } status = XEmacPs_BdRingAlloc(rxring, 1, &rxbd); if (status != XST_SUCCESS) { LWIP_DEBUGF(NETIF_DEBUG, ("setup_rx_bds: Error allocating RxBD\r\n")); pbuf_free(p); return; } status = XEmacPs_BdRingToHw(rxring, 1, rxbd); if (status != XST_SUCCESS) { LWIP_DEBUGF(NETIF_DEBUG, ("Error committing RxBD to hardware: ")); if (status == XST_DMA_SG_LIST_ERROR) LWIP_DEBUGF(NETIF_DEBUG, ("XST_DMA_SG_LIST_ERROR: this function was called out of sequence with XEmacPs_BdRingAlloc()\r\n")); else LWIP_DEBUGF(NETIF_DEBUG, ("set of BDs was rejected because the first BD did not have its start-of-packet bit set, or the last BD did not have its end-of-packet bit set, or any one of the BD set has 0 as length value\r\n")); pbuf_free(p); XEmacPs_BdRingUnAlloc(rxring, 1, rxbd); return; } Xil_DCacheInvalidateRange((u32_t)p->payload, (u32_t)XEMACPS_MAX_FRAME_SIZE); bdindex = XEMACPS_BD_TO_INDEX(rxring, rxbd); temp = (u32_t *)rxbd; *temp = 0; if (bdindex == (XLWIP_CONFIG_N_RX_DESC - 1)) { *temp = 0x00000002; } temp++; *temp = 0; XEmacPs_BdSetAddressRx(rxbd, (u32_t)p->payload); rx_pbufs_storage[index + bdindex] = (s32_t)p; } }
void _setup_rx_bds(XEmacPs_BdRing *rxring) { XEmacPs_Bd *rxbd, *CurBdPtr; int n_bds, i; XStatus Status; struct pbuf *p; u32 BdSts; unsigned int FreeBds, k; unsigned int BdIndex; unsigned int *Temp; FreeBds = XEmacPs_BdRingGetFreeCnt (rxring); Status = XEmacPs_BdRingAlloc(rxring, FreeBds, &rxbd); if (Status != XST_SUCCESS) { LWIP_DEBUGF(NETIF_DEBUG, ("setup_rx_bds: Error allocating RxBD\r\n")); return; } for (k = 0, CurBdPtr = rxbd; k < FreeBds; k++) { p = pbuf_alloc(PBUF_RAW, XEMACPS_MAX_FRAME_SIZE, PBUF_POOL); if (!p) { #if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.drop++; #endif LWIP_DEBUGF(NETIF_DEBUG, ("unable to alloc pbuf in recv_handler\r\n")); return; } BdIndex = XEMACPS_BD_TO_INDEX(rxring, CurBdPtr); Temp = (unsigned int *)CurBdPtr; *Temp = 0; if (BdIndex == (XLWIP_CONFIG_N_RX_DESC - 1)) { *Temp = 0x00000002; } Temp++; *Temp = 0; XEmacPs_BdSetAddressRx(CurBdPtr, (u32)p->payload); dsb(); rx_pbufs_storage[BdIndex] = (int)p; CurBdPtr = XEmacPs_BdRingNext (rxring, CurBdPtr); /* Enqueue to HW */ } Status = XEmacPs_BdRingToHw(rxring, FreeBds, rxbd); if (Status != XST_SUCCESS) { LWIP_DEBUGF(NETIF_DEBUG, ("Error committing RxBD to hardware: ")); if (Status == XST_DMA_SG_LIST_ERROR) LWIP_DEBUGF(NETIF_DEBUG, ("XST_DMA_SG_LIST_ERROR: this function was called out of sequence with XEmacPs_BdRingAlloc()\r\n")); else LWIP_DEBUGF(NETIF_DEBUG, ("set of BDs was rejected because the first BD did not have its start-of-packet bit set, or the last BD did not have its end-of-packet bit set, or any one of the BD set has 0 as length value\r\n")); return; } }
s32_t is_tx_space_available(xemacpsif_s *emac) { XEmacPs_BdRing *txring; s32_t freecnt = 0; txring = &(XEmacPs_GetTxRing(&emac->emacps)); /* tx space is available as long as there are valid BD's */ freecnt = XEmacPs_BdRingGetFreeCnt(txring); return freecnt; }