FreeBSD/sys/dev/ixl/ixl_txrx.c
/*********************************************************************
 *
 *  Refresh mbuf buffers for RX descriptor rings
 *   - now keeps its own state so discards due to resource
 *     exhaustion are unnecessary, if an mbuf cannot be obtained
 *     it just returns, keeping its placeholder, thus it can simply
 *     be recalled to try again.
 *
 **********************************************************************/
Refresh mbuf buffers for RX descriptor rings
- now keeps its own state so discards due to resource
exhaustion are unnecessary, if an mbuf cannot be obtained
it just returns, keeping its placeholder, thus it can simply
be recalled to try again.
Refresh mbuf buffers for RX descriptor rings - now keeps its own state so discards due to resource exhaustion are unnecessary if an mbuf cannot be obtained it just returns keeping its placeholder thus it can simply be recalled to try again .
static void
ixl_refresh_mbufs(struct ixl_queue *que, int limit)
{
	struct ixl_vsi		*vsi = que->vsi;
	struct rx_ring		*rxr = &que->rxr;
	bus_dma_segment_t	hseg[1];
	bus_dma_segment_t	pseg[1];
	struct ixl_rx_buf	*buf;
	struct mbuf		*mh, *mp;
	int			i, j, nsegs, error;
	bool			refreshed = FALSE;
	i = j = rxr->next_refresh;
	if (++j == que->num_desc)
		j = 0;
	while (j != limit) {
		buf = &rxr->buffers[i];
		if (rxr->hdr_split == FALSE)
			goto no_split;
		if (buf->m_head == NULL) {
			mh = m_gethdr(M_NOWAIT, MT_DATA);
			if (mh == NULL)
				goto update;
		} else
			mh = buf->m_head;
		mh->m_pkthdr.len = mh->m_len = MHLEN;
		mh->m_len = MHLEN;
		mh->m_flags |= M_PKTHDR;
		error = bus_dmamap_load_mbuf_sg(rxr->htag,
		    buf->hmap, mh, hseg, &nsegs, BUS_DMA_NOWAIT);
		if (error != 0) {
			printf("Refresh mbufs: hdr dmamap load"
			    " failure - %d\n", error);
			m_free(mh);
			buf->m_head = NULL;
			goto update;
		}
		buf->m_head = mh;
		bus_dmamap_sync(rxr->htag, buf->hmap,
		    BUS_DMASYNC_PREREAD);
		rxr->base[i].read.hdr_addr =
		   htole64(hseg[0].ds_addr);
no_split:
		if (buf->m_pack == NULL) {
			mp = m_getjcl(M_NOWAIT, MT_DATA,
			    M_PKTHDR, rxr->mbuf_sz);
			if (mp == NULL)
				goto update;
		} else
			mp = buf->m_pack;
		mp->m_pkthdr.len = mp->m_len = rxr->mbuf_sz;
		error = bus_dmamap_load_mbuf_sg(rxr->ptag,
		    buf->pmap, mp, pseg, &nsegs, BUS_DMA_NOWAIT);
		if (error != 0) {
			printf("Refresh mbufs: payload dmamap load"
			    " failure - %d\n", error);
			m_free(mp);
			buf->m_pack = NULL;
			goto update;
		}
		buf->m_pack = mp;
		bus_dmamap_sync(rxr->ptag, buf->pmap,
		    BUS_DMASYNC_PREREAD);
		rxr->base[i].read.pkt_addr =
		   htole64(pseg[0].ds_addr);
		rxr->base[i].read.hdr_addr = 0;
		refreshed = TRUE;
		i = j;
		rxr->next_refresh = i;
		if (++j == que->num_desc)
			j = 0;
	}
update:
	if (refreshed) 
		wr32(vsi->hw, rxr->tail, rxr->next_refresh);
	return;
}
static void ixl_refresh_mbufs ( struct ixl_queue * que , int limit ) { struct ixl_vsi * vsi = que -> vsi ; struct rx_ring * rxr = & que -> rxr ; bus_dma_segment_t hseg [ 1 ] ; bus_dma_segment_t pseg [ 1 ] ; struct ixl_rx_buf * buf ; struct mbuf * mh , * mp ; int i , j , nsegs , error ; bool refreshed = FALSE ; i = j = rxr -> next_refresh ; if ( ++ j == que -> num_desc ) j = 0 ; while ( j != limit ) { buf = & rxr -> buffers [ i ] ; if ( rxr -> hdr_split == FALSE ) goto no_split ; if ( buf -> m_head == NULL ) { mh = m_gethdr ( M_NOWAIT , MT_DATA ) ; if ( mh == NULL ) goto update ; } else mh = buf -> m_head ; mh -> m_pkthdr . len = mh -> m_len = MHLEN ; mh -> m_len = MHLEN ; mh -> m_flags |= M_PKTHDR ; error = bus_dmamap_load_mbuf_sg ( rxr -> htag , buf -> hmap , mh , hseg , & nsegs , BUS_DMA_NOWAIT ) ; if ( error != 0 ) { printf ( " " " \n " , error ) ; m_free ( mh ) ; buf -> m_head = NULL ; goto update ; } buf -> m_head = mh ; bus_dmamap_sync ( rxr -> htag , buf -> hmap , BUS_DMASYNC_PREREAD ) ; rxr -> base [ i ] . read . hdr_addr = htole64 ( hseg [ 0 ] . ds_addr ) ; no_split : if ( buf -> m_pack == NULL ) { mp = m_getjcl ( M_NOWAIT , MT_DATA , M_PKTHDR , rxr -> mbuf_sz ) ; if ( mp == NULL ) goto update ; } else mp = buf -> m_pack ; mp -> m_pkthdr . len = mp -> m_len = rxr -> mbuf_sz ; error = bus_dmamap_load_mbuf_sg ( rxr -> ptag , buf -> pmap , mp , pseg , & nsegs , BUS_DMA_NOWAIT ) ; if ( error != 0 ) { printf ( " " " \n " , error ) ; m_free ( mp ) ; buf -> m_pack = NULL ; goto update ; } buf -> m_pack = mp ; bus_dmamap_sync ( rxr -> ptag , buf -> pmap , BUS_DMASYNC_PREREAD ) ; rxr -> base [ i ] . read . pkt_addr = htole64 ( pseg [ 0 ] . ds_addr ) ; rxr -> base [ i ] . read . hdr_addr = 0 ; refreshed = TRUE ; i = j ; rxr -> next_refresh = i ; if ( ++ j == que -> num_desc ) j = 0 ; } update : if ( refreshed ) wr32 ( vsi -> hw , rxr -> tail , rxr -> next_refresh ) ; return ; }
Refresh mbuf buffers for RX descriptor rings
   - now keeps its own state so discards due to resource
     exhaustion are unnecessary, if an mbuf cannot be obtained
     it just returns, keeping its placeholder, thus it can simply
     be recalled to try again.
Refresh mbuf buffers for RX descriptor rings - now keeps its own state so discards due to resource exhaustion are unnecessary if an mbuf cannot be obtained it just returns keeping its placeholder thus it can simply be recalled to try again .
/* Control the loop with one beyond */ /* Get the memory mapping */ /* Get the memory mapping */ /* Used only when doing header split */ /* Next is precalculated */ /* Update hardware tail index */