* iflib_fl_refill - refill an rxq free-buffer list * @ctx: the iflib context * @fl: the free list to refill * @count: the number of new buffers to allocate * * (Re)populate an rxq free-buffer list with up to @count new packet buffers. * The caller must assure that @count does not exceed the queue's capacity * minus one (since we always leave a descriptor unavailable). */
| 2003 | * minus one (since we always leave a descriptor unavailable). |
| 2004 | */ |
| 2005 | static uint8_t |
| 2006 | iflib_fl_refill(if_ctx_t ctx, iflib_fl_t fl, int count) |
| 2007 | { |
| 2008 | struct if_rxd_update iru; |
| 2009 | struct rxq_refill_cb_arg cb_arg; |
| 2010 | struct mbuf *m; |
| 2011 | caddr_t cl, *sd_cl; |
| 2012 | struct mbuf **sd_m; |
| 2013 | bus_dmamap_t *sd_map; |
| 2014 | bus_addr_t bus_addr, *sd_ba; |
| 2015 | int err, frag_idx, i, idx, n, pidx; |
| 2016 | qidx_t credits; |
| 2017 | |
| 2018 | MPASS(count <= fl->ifl_size - fl->ifl_credits - 1); |
| 2019 | |
| 2020 | sd_m = fl->ifl_sds.ifsd_m; |
| 2021 | sd_map = fl->ifl_sds.ifsd_map; |
| 2022 | sd_cl = fl->ifl_sds.ifsd_cl; |
| 2023 | sd_ba = fl->ifl_sds.ifsd_ba; |
| 2024 | pidx = fl->ifl_pidx; |
| 2025 | idx = pidx; |
| 2026 | frag_idx = fl->ifl_fragidx; |
| 2027 | credits = fl->ifl_credits; |
| 2028 | |
| 2029 | i = 0; |
| 2030 | n = count; |
| 2031 | MPASS(n > 0); |
| 2032 | MPASS(credits + n <= fl->ifl_size); |
| 2033 | |
| 2034 | if (pidx < fl->ifl_cidx) |
| 2035 | MPASS(pidx + n <= fl->ifl_cidx); |
| 2036 | if (pidx == fl->ifl_cidx && (credits < fl->ifl_size)) |
| 2037 | MPASS(fl->ifl_gen == 0); |
| 2038 | if (pidx > fl->ifl_cidx) |
| 2039 | MPASS(n <= fl->ifl_size - pidx + fl->ifl_cidx); |
| 2040 | |
| 2041 | DBG_COUNTER_INC(fl_refills); |
| 2042 | if (n > 8) |
| 2043 | DBG_COUNTER_INC(fl_refills_large); |
| 2044 | iru_init(&iru, fl->ifl_rxq, fl->ifl_id); |
| 2045 | while (n-- > 0) { |
| 2046 | /* |
| 2047 | * We allocate an uninitialized mbuf + cluster, mbuf is |
| 2048 | * initialized after rx. |
| 2049 | * |
| 2050 | * If the cluster is still set then we know a minimum sized |
| 2051 | * packet was received |
| 2052 | */ |
| 2053 | bit_ffc_at(fl->ifl_rx_bitmap, frag_idx, fl->ifl_size, |
| 2054 | &frag_idx); |
| 2055 | if (frag_idx < 0) |
| 2056 | bit_ffc(fl->ifl_rx_bitmap, fl->ifl_size, &frag_idx); |
| 2057 | MPASS(frag_idx >= 0); |
| 2058 | if ((cl = sd_cl[frag_idx]) == NULL) { |
| 2059 | cl = uma_zalloc(fl->ifl_zone, M_NOWAIT); |
| 2060 | if (__predict_false(cl == NULL)) |
| 2061 | break; |
| 2062 |
no test coverage detected