| 830 | } |
| 831 | |
| 832 | static int |
| 833 | netmap_fl_refill(iflib_rxq_t rxq, struct netmap_kring *kring, bool init) |
| 834 | { |
| 835 | struct netmap_adapter *na = kring->na; |
| 836 | u_int const lim = kring->nkr_num_slots - 1; |
| 837 | struct netmap_ring *ring = kring->ring; |
| 838 | bus_dmamap_t *map; |
| 839 | struct if_rxd_update iru; |
| 840 | if_ctx_t ctx = rxq->ifr_ctx; |
| 841 | iflib_fl_t fl = &rxq->ifr_fl[0]; |
| 842 | u_int nic_i_first, nic_i; |
| 843 | u_int nm_i; |
| 844 | int i, n; |
| 845 | #if IFLIB_DEBUG_COUNTERS |
| 846 | int rf_count = 0; |
| 847 | #endif |
| 848 | |
| 849 | /* |
| 850 | * This function is used both at initialization and in rxsync. |
| 851 | * At initialization we need to prepare (with isc_rxd_refill()) |
| 852 | * all the netmap buffers currently owned by the kernel, in |
| 853 | * such a way to keep fl->ifl_pidx and kring->nr_hwcur in sync |
| 854 | * (except for kring->nkr_hwofs). These may be less than |
| 855 | * kring->nkr_num_slots if netmap_reset() was called while |
| 856 | * an application using the kring that still owned some |
| 857 | * buffers. |
| 858 | * At rxsync time, both indexes point to the next buffer to be |
| 859 | * refilled. |
| 860 | * In any case we publish (with isc_rxd_flush()) up to |
| 861 | * (fl->ifl_pidx - 1) % N (included), to avoid the NIC tail/prod |
| 862 | * pointer to overrun the head/cons pointer, although this is |
| 863 | * not necessary for some NICs (e.g. vmx). |
| 864 | */ |
| 865 | if (__predict_false(init)) { |
| 866 | n = kring->nkr_num_slots - nm_kr_rxspace(kring); |
| 867 | } else { |
| 868 | n = kring->rhead - kring->nr_hwcur; |
| 869 | if (n == 0) |
| 870 | return (0); /* Nothing to do. */ |
| 871 | if (n < 0) |
| 872 | n += kring->nkr_num_slots; |
| 873 | } |
| 874 | |
| 875 | iru_init(&iru, rxq, 0 /* flid */); |
| 876 | map = fl->ifl_sds.ifsd_map; |
| 877 | nic_i = fl->ifl_pidx; |
| 878 | nm_i = netmap_idx_n2k(kring, nic_i); |
| 879 | if (__predict_false(init)) { |
| 880 | /* |
| 881 | * On init/reset, nic_i must be 0, and we must |
| 882 | * start to refill from hwtail (see netmap_reset()). |
| 883 | */ |
| 884 | MPASS(nic_i == 0); |
| 885 | MPASS(nm_i == kring->nr_hwtail); |
| 886 | } else |
| 887 | MPASS(nm_i == kring->nr_hwcur); |
| 888 | DBG_COUNTER_INC(fl_refills); |
| 889 | while (n > 0) { |
no test coverage detected