2 * Copyright (c) 2014 Chelsio Communications, Inc.
4 * Written by: Navdeep Parhar <np@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
32 #include "opt_inet6.h"
35 #include <sys/param.h>
37 #include <sys/eventhandler.h>
40 #include <sys/module.h>
41 #include <sys/selinfo.h>
42 #include <sys/socket.h>
43 #include <sys/sockio.h>
44 #include <machine/bus.h>
47 #include <net/ethernet.h>
49 #include <net/if_media.h>
50 #include <net/if_var.h>
51 #include <net/if_clone.h>
52 #include <net/if_types.h>
53 #include <net/netmap.h>
54 #include <dev/netmap/netmap_kern.h>
56 #include "common/common.h"
57 #include "common/t4_regs.h"
58 #include "common/t4_regs_values.h"
60 extern int fl_pad; /* XXXNM */
63 * 0 = normal netmap rx
65 * 2 = supermassive black hole (buffer packing enabled)
68 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_black_hole, CTLFLAG_RWTUN, &black_hole, 0,
69 "Sink incoming packets.");
72 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_rx_ndesc, CTLFLAG_RWTUN,
73 &rx_ndesc, 0, "# of rx descriptors after which the hw cidx is updated.");
76 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_rx_nframes, CTLFLAG_RWTUN,
77 &rx_nframes, 0, "max # of frames received before waking up netmap rx.");
79 int holdoff_tmr_idx = 2;
80 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_holdoff_tmr_idx, CTLFLAG_RWTUN,
81 &holdoff_tmr_idx, 0, "Holdoff timer index for netmap rx queues.");
85 * -1: no congestion feedback (not recommended).
86 * 0: backpressure the channel instead of dropping packets right away.
87 * 1: no backpressure, drop packets for the congested queue immediately.
89 static int nm_cong_drop = 1;
90 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_cong_drop, CTLFLAG_RWTUN,
92 "Congestion control for netmap rx queues (0 = backpressure, 1 = drop");
95 SYSCTL_INT(_hw_cxgbe, OID_AUTO, starve_fl, CTLFLAG_RWTUN,
96 &starve_fl, 0, "Don't ring fl db for netmap rx queues.");
99 * Try to process tx credits in bulk. This may cause a delay in the return of
100 * tx credits and is suitable for bursty or non-stop tx only.
102 int lazy_tx_credit_flush = 1;
103 SYSCTL_INT(_hw_cxgbe, OID_AUTO, lazy_tx_credit_flush, CTLFLAG_RWTUN,
104 &lazy_tx_credit_flush, 0, "lazy credit flush for netmap tx queues.");
107 * Split the netmap rx queues into two groups that populate separate halves of
108 * the RSS indirection table. This allows filters with hashmask to steer to a
109 * particular group of queues.
111 static int nm_split_rss = 0;
112 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_split_rss, CTLFLAG_RWTUN,
113 &nm_split_rss, 0, "Split the netmap rx queues into two groups.");
116 * netmap(4) says "netmap does not use features such as checksum offloading, TCP
117 * segmentation offloading, encryption, VLAN encapsulation/decapsulation, etc."
118 * but this knob can be used to get the hardware to checksum all tx traffic
121 static int nm_txcsum = 0;
122 SYSCTL_INT(_hw_cxgbe, OID_AUTO, nm_txcsum, CTLFLAG_RWTUN,
123 &nm_txcsum, 0, "Enable transmit checksum offloading.");
126 alloc_nm_rxq_hwq(struct vi_info *vi, struct sge_nm_rxq *nm_rxq, int cong)
130 struct adapter *sc = vi->adapter;
131 struct sge_params *sp = &sc->params.sge;
132 struct netmap_adapter *na = NA(vi->ifp);
136 MPASS(nm_rxq->iq_desc != NULL);
137 MPASS(nm_rxq->fl_desc != NULL);
139 bzero(nm_rxq->iq_desc, vi->qsize_rxq * IQ_ESIZE);
140 bzero(nm_rxq->fl_desc, na->num_rx_desc * EQ_ESIZE + sp->spg_len);
142 bzero(&c, sizeof(c));
143 c.op_to_vfn = htobe32(V_FW_CMD_OP(FW_IQ_CMD) | F_FW_CMD_REQUEST |
144 F_FW_CMD_WRITE | F_FW_CMD_EXEC | V_FW_IQ_CMD_PFN(sc->pf) |
146 c.alloc_to_len16 = htobe32(F_FW_IQ_CMD_ALLOC | F_FW_IQ_CMD_IQSTART |
148 MPASS(!forwarding_intr_to_fwq(sc));
149 KASSERT(nm_rxq->intr_idx < sc->intr_count,
150 ("%s: invalid direct intr_idx %d", __func__, nm_rxq->intr_idx));
151 v = V_FW_IQ_CMD_IQANDSTINDEX(nm_rxq->intr_idx);
152 c.type_to_iqandstindex = htobe32(v |
153 V_FW_IQ_CMD_TYPE(FW_IQ_TYPE_FL_INT_CAP) |
154 V_FW_IQ_CMD_VIID(vi->viid) |
155 V_FW_IQ_CMD_IQANUD(X_UPDATEDELIVERY_INTERRUPT));
156 c.iqdroprss_to_iqesize = htobe16(V_FW_IQ_CMD_IQPCIECH(vi->pi->tx_chan) |
157 F_FW_IQ_CMD_IQGTSMODE |
158 V_FW_IQ_CMD_IQINTCNTTHRESH(0) |
159 V_FW_IQ_CMD_IQESIZE(ilog2(IQ_ESIZE) - 4));
160 c.iqsize = htobe16(vi->qsize_rxq);
161 c.iqaddr = htobe64(nm_rxq->iq_ba);
163 c.iqns_to_fl0congen = htobe32(F_FW_IQ_CMD_IQFLINTCONGEN |
164 V_FW_IQ_CMD_FL0CNGCHMAP(cong) | F_FW_IQ_CMD_FL0CONGCIF |
165 F_FW_IQ_CMD_FL0CONGEN);
167 c.iqns_to_fl0congen |=
168 htobe32(V_FW_IQ_CMD_FL0HOSTFCMODE(X_HOSTFCMODE_NONE) |
169 F_FW_IQ_CMD_FL0FETCHRO | F_FW_IQ_CMD_FL0DATARO |
170 (fl_pad ? F_FW_IQ_CMD_FL0PADEN : 0) |
171 (black_hole == 2 ? F_FW_IQ_CMD_FL0PACKEN : 0));
172 c.fl0dcaen_to_fl0cidxfthresh =
173 htobe16(V_FW_IQ_CMD_FL0FBMIN(chip_id(sc) <= CHELSIO_T5 ?
174 X_FETCHBURSTMIN_128B : X_FETCHBURSTMIN_64B_T6) |
175 V_FW_IQ_CMD_FL0FBMAX(chip_id(sc) <= CHELSIO_T5 ?
176 X_FETCHBURSTMAX_512B : X_FETCHBURSTMAX_256B));
177 c.fl0size = htobe16(na->num_rx_desc / 8 + sp->spg_len / EQ_ESIZE);
178 c.fl0addr = htobe64(nm_rxq->fl_ba);
180 rc = -t4_wr_mbox(sc, sc->mbox, &c, sizeof(c), &c);
182 device_printf(sc->dev,
183 "failed to create netmap ingress queue: %d\n", rc);
188 MPASS(nm_rxq->iq_sidx == vi->qsize_rxq - sp->spg_len / IQ_ESIZE);
189 nm_rxq->iq_gen = F_RSPD_GEN;
190 nm_rxq->iq_cntxt_id = be16toh(c.iqid);
191 nm_rxq->iq_abs_id = be16toh(c.physiqid);
192 cntxt_id = nm_rxq->iq_cntxt_id - sc->sge.iq_start;
193 if (cntxt_id >= sc->sge.iqmap_sz) {
194 panic ("%s: nm_rxq->iq_cntxt_id (%d) more than the max (%d)",
195 __func__, cntxt_id, sc->sge.iqmap_sz - 1);
197 sc->sge.iqmap[cntxt_id] = (void *)nm_rxq;
199 nm_rxq->fl_cntxt_id = be16toh(c.fl0id);
200 nm_rxq->fl_pidx = nm_rxq->fl_cidx = 0;
201 nm_rxq->fl_db_saved = 0;
202 /* matches the X_FETCHBURSTMAX_512B or X_FETCHBURSTMAX_256B above. */
203 nm_rxq->fl_db_threshold = chip_id(sc) <= CHELSIO_T5 ? 8 : 4;
204 MPASS(nm_rxq->fl_sidx == na->num_rx_desc);
205 cntxt_id = nm_rxq->fl_cntxt_id - sc->sge.eq_start;
206 if (cntxt_id >= sc->sge.eqmap_sz) {
207 panic("%s: nm_rxq->fl_cntxt_id (%d) more than the max (%d)",
208 __func__, cntxt_id, sc->sge.eqmap_sz - 1);
210 sc->sge.eqmap[cntxt_id] = (void *)nm_rxq;
212 nm_rxq->fl_db_val = V_QID(nm_rxq->fl_cntxt_id) |
213 sc->chip_params->sge_fl_db;
215 if (chip_id(sc) >= CHELSIO_T5 && cong >= 0) {
218 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
219 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DMAQ_CONM_CTXT) |
220 V_FW_PARAMS_PARAM_YZ(nm_rxq->iq_cntxt_id);
225 for (i = 0; i < 4; i++) {
227 val |= 1 << (i << 2);
231 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
233 /* report error but carry on */
234 device_printf(sc->dev,
235 "failed to set congestion manager context for "
236 "ingress queue %d: %d\n", nm_rxq->iq_cntxt_id, rc);
240 t4_write_reg(sc, sc->sge_gts_reg,
241 V_INGRESSQID(nm_rxq->iq_cntxt_id) |
242 V_SEINTARM(V_QINTR_TIMER_IDX(holdoff_tmr_idx)));
248 free_nm_rxq_hwq(struct vi_info *vi, struct sge_nm_rxq *nm_rxq)
250 struct adapter *sc = vi->adapter;
253 rc = -t4_iq_free(sc, sc->mbox, sc->pf, 0, FW_IQ_TYPE_FL_INT_CAP,
254 nm_rxq->iq_cntxt_id, nm_rxq->fl_cntxt_id, 0xffff);
256 device_printf(sc->dev, "%s: failed for iq %d, fl %d: %d\n",
257 __func__, nm_rxq->iq_cntxt_id, nm_rxq->fl_cntxt_id, rc);
258 nm_rxq->iq_cntxt_id = INVALID_NM_RXQ_CNTXT_ID;
263 alloc_nm_txq_hwq(struct vi_info *vi, struct sge_nm_txq *nm_txq)
267 struct adapter *sc = vi->adapter;
268 struct netmap_adapter *na = NA(vi->ifp);
269 struct fw_eq_eth_cmd c;
272 MPASS(nm_txq->desc != NULL);
274 len = na->num_tx_desc * EQ_ESIZE + sc->params.sge.spg_len;
275 bzero(nm_txq->desc, len);
277 bzero(&c, sizeof(c));
278 c.op_to_vfn = htobe32(V_FW_CMD_OP(FW_EQ_ETH_CMD) | F_FW_CMD_REQUEST |
279 F_FW_CMD_WRITE | F_FW_CMD_EXEC | V_FW_EQ_ETH_CMD_PFN(sc->pf) |
280 V_FW_EQ_ETH_CMD_VFN(0));
281 c.alloc_to_len16 = htobe32(F_FW_EQ_ETH_CMD_ALLOC |
282 F_FW_EQ_ETH_CMD_EQSTART | FW_LEN16(c));
283 c.autoequiqe_to_viid = htobe32(F_FW_EQ_ETH_CMD_AUTOEQUIQE |
284 F_FW_EQ_ETH_CMD_AUTOEQUEQE | V_FW_EQ_ETH_CMD_VIID(vi->viid));
286 htobe32(V_FW_EQ_ETH_CMD_HOSTFCMODE(X_HOSTFCMODE_NONE) |
287 V_FW_EQ_ETH_CMD_PCIECHN(vi->pi->tx_chan) | F_FW_EQ_ETH_CMD_FETCHRO |
288 V_FW_EQ_ETH_CMD_IQID(sc->sge.nm_rxq[nm_txq->iqidx].iq_cntxt_id));
290 htobe32(V_FW_EQ_ETH_CMD_FBMIN(chip_id(sc) <= CHELSIO_T5 ?
291 X_FETCHBURSTMIN_64B : X_FETCHBURSTMIN_64B_T6) |
292 V_FW_EQ_ETH_CMD_FBMAX(X_FETCHBURSTMAX_512B) |
293 V_FW_EQ_ETH_CMD_EQSIZE(len / EQ_ESIZE));
294 c.eqaddr = htobe64(nm_txq->ba);
296 rc = -t4_wr_mbox(sc, sc->mbox, &c, sizeof(c), &c);
298 device_printf(vi->dev,
299 "failed to create netmap egress queue: %d\n", rc);
303 nm_txq->cntxt_id = G_FW_EQ_ETH_CMD_EQID(be32toh(c.eqid_pkd));
304 cntxt_id = nm_txq->cntxt_id - sc->sge.eq_start;
305 if (cntxt_id >= sc->sge.eqmap_sz)
306 panic("%s: nm_txq->cntxt_id (%d) more than the max (%d)", __func__,
307 cntxt_id, sc->sge.eqmap_sz - 1);
308 sc->sge.eqmap[cntxt_id] = (void *)nm_txq;
310 nm_txq->pidx = nm_txq->cidx = 0;
311 MPASS(nm_txq->sidx == na->num_tx_desc);
312 nm_txq->equiqidx = nm_txq->equeqidx = nm_txq->dbidx = 0;
314 nm_txq->doorbells = sc->doorbells;
315 if (isset(&nm_txq->doorbells, DOORBELL_UDB) ||
316 isset(&nm_txq->doorbells, DOORBELL_UDBWC) ||
317 isset(&nm_txq->doorbells, DOORBELL_WCWR)) {
318 uint32_t s_qpp = sc->params.sge.eq_s_qpp;
319 uint32_t mask = (1 << s_qpp) - 1;
320 volatile uint8_t *udb;
322 udb = sc->udbs_base + UDBS_DB_OFFSET;
323 udb += (nm_txq->cntxt_id >> s_qpp) << PAGE_SHIFT;
324 nm_txq->udb_qid = nm_txq->cntxt_id & mask;
325 if (nm_txq->udb_qid >= PAGE_SIZE / UDBS_SEG_SIZE)
326 clrbit(&nm_txq->doorbells, DOORBELL_WCWR);
328 udb += nm_txq->udb_qid << UDBS_SEG_SHIFT;
331 nm_txq->udb = (volatile void *)udb;
334 if (sc->params.fw_vers < FW_VERSION32(1, 25, 1, 0)) {
337 param = V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DMAQ) |
338 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DMAQ_EQ_SCHEDCLASS_ETH) |
339 V_FW_PARAMS_PARAM_YZ(nm_txq->cntxt_id);
341 rc = -t4_set_params(sc, sc->mbox, sc->pf, 0, 1, ¶m, &val);
343 device_printf(vi->dev,
344 "failed to bind netmap txq %d to class 0xff: %d\n",
345 nm_txq->cntxt_id, rc);
354 free_nm_txq_hwq(struct vi_info *vi, struct sge_nm_txq *nm_txq)
356 struct adapter *sc = vi->adapter;
359 rc = -t4_eth_eq_free(sc, sc->mbox, sc->pf, 0, nm_txq->cntxt_id);
361 device_printf(sc->dev, "%s: failed for eq %d: %d\n", __func__,
362 nm_txq->cntxt_id, rc);
363 nm_txq->cntxt_id = INVALID_NM_TXQ_CNTXT_ID;
368 cxgbe_netmap_simple_rss(struct adapter *sc, struct vi_info *vi,
369 struct ifnet *ifp, struct netmap_adapter *na)
371 struct netmap_kring *kring;
372 struct sge_nm_rxq *nm_rxq;
373 int rc, i, j, nm_state, defq;
377 * Check if there's at least one active (or about to go active) netmap
381 for_each_nm_rxq(vi, j, nm_rxq) {
382 nm_state = atomic_load_int(&nm_rxq->nm_state);
383 kring = na->rx_rings[nm_rxq->nid];
384 if ((nm_state != NM_OFF && !nm_kring_pending_off(kring)) ||
385 (nm_state == NM_OFF && nm_kring_pending_on(kring))) {
386 MPASS(nm_rxq->iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID);
388 defq = nm_rxq->iq_abs_id;
395 /* No active netmap queues. Switch back to NIC queues. */
399 for (i = 0; i < vi->rss_size;) {
400 for_each_nm_rxq(vi, j, nm_rxq) {
401 nm_state = atomic_load_int(&nm_rxq->nm_state);
402 kring = na->rx_rings[nm_rxq->nid];
403 if ((nm_state != NM_OFF &&
404 !nm_kring_pending_off(kring)) ||
405 (nm_state == NM_OFF &&
406 nm_kring_pending_on(kring))) {
407 MPASS(nm_rxq->iq_cntxt_id !=
408 INVALID_NM_RXQ_CNTXT_ID);
409 vi->nm_rss[i++] = nm_rxq->iq_abs_id;
410 if (i == vi->rss_size)
418 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size, rss,
421 if_printf(ifp, "netmap rss_config failed: %d\n", rc);
423 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, vi->hashen, defq, 0, 0);
425 if_printf(ifp, "netmap defaultq config failed: %d\n", rc);
432 * Odd number of rx queues work best for split RSS mode as the first queue can
433 * be dedicated for non-RSS traffic and the rest divided into two equal halves.
436 cxgbe_netmap_split_rss(struct adapter *sc, struct vi_info *vi,
437 struct ifnet *ifp, struct netmap_adapter *na)
439 struct netmap_kring *kring;
440 struct sge_nm_rxq *nm_rxq;
441 int rc, i, j, nm_state, defq;
442 int nactive[2] = {0, 0};
443 int dq[2] = {-1, -1};
444 bool dq_norss; /* default queue should not be in RSS table. */
446 MPASS(nm_split_rss != 0);
447 MPASS(vi->nnmrxq > 1);
449 for_each_nm_rxq(vi, i, nm_rxq) {
450 j = i / ((vi->nnmrxq + 1) / 2);
451 nm_state = atomic_load_int(&nm_rxq->nm_state);
452 kring = na->rx_rings[nm_rxq->nid];
453 if ((nm_state != NM_OFF && !nm_kring_pending_off(kring)) ||
454 (nm_state == NM_OFF && nm_kring_pending_on(kring))) {
455 MPASS(nm_rxq->iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID);
458 dq[j] = nm_rxq->iq_abs_id;
464 if (nactive[0] == 0 || nactive[1] == 0)
465 return (cxgbe_netmap_simple_rss(sc, vi, ifp, na));
467 MPASS(dq[0] != -1 && dq[1] != -1);
468 if (nactive[0] > nactive[1]) {
471 } else if (nactive[0] < nactive[1]) {
480 nm_rxq = &sc->sge.nm_rxq[vi->first_nm_rxq];
481 while (i < vi->rss_size / 2) {
482 for (j = 0; j < (vi->nnmrxq + 1) / 2; j++) {
483 nm_state = atomic_load_int(&nm_rxq[j].nm_state);
484 kring = na->rx_rings[nm_rxq[j].nid];
485 if ((nm_state == NM_OFF &&
486 !nm_kring_pending_on(kring)) ||
487 (nm_state == NM_ON &&
488 nm_kring_pending_off(kring))) {
491 MPASS(nm_rxq[j].iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID);
492 if (dq_norss && defq == nm_rxq[j].iq_abs_id)
494 vi->nm_rss[i++] = nm_rxq[j].iq_abs_id;
495 if (i == vi->rss_size / 2)
499 while (i < vi->rss_size) {
500 for (j = (vi->nnmrxq + 1) / 2; j < vi->nnmrxq; j++) {
501 nm_state = atomic_load_int(&nm_rxq[j].nm_state);
502 kring = na->rx_rings[nm_rxq[j].nid];
503 if ((nm_state == NM_OFF &&
504 !nm_kring_pending_on(kring)) ||
505 (nm_state == NM_ON &&
506 nm_kring_pending_off(kring))) {
509 MPASS(nm_rxq[j].iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID);
510 if (dq_norss && defq == nm_rxq[j].iq_abs_id)
512 vi->nm_rss[i++] = nm_rxq[j].iq_abs_id;
513 if (i == vi->rss_size)
518 rc = -t4_config_rss_range(sc, sc->mbox, vi->viid, 0, vi->rss_size,
519 vi->nm_rss, vi->rss_size);
521 if_printf(ifp, "netmap split_rss_config failed: %d\n", rc);
523 rc = -t4_config_vi_rss(sc, sc->mbox, vi->viid, vi->hashen, defq, 0, 0);
525 if_printf(ifp, "netmap defaultq config failed: %d\n", rc);
531 cxgbe_netmap_rss(struct adapter *sc, struct vi_info *vi, struct ifnet *ifp,
532 struct netmap_adapter *na)
535 if (nm_split_rss == 0 || vi->nnmrxq == 1)
536 return (cxgbe_netmap_simple_rss(sc, vi, ifp, na));
538 return (cxgbe_netmap_split_rss(sc, vi, ifp, na));
542 cxgbe_netmap_on(struct adapter *sc, struct vi_info *vi, struct ifnet *ifp,
543 struct netmap_adapter *na)
545 struct netmap_slot *slot;
546 struct netmap_kring *kring;
547 struct sge_nm_rxq *nm_rxq;
548 struct sge_nm_txq *nm_txq;
550 struct rx_buf_info *rxb;
552 ASSERT_SYNCHRONIZED_OP(sc);
553 MPASS(vi->nnmrxq > 0);
554 MPASS(vi->nnmtxq > 0);
556 if ((vi->flags & VI_INIT_DONE) == 0 ||
557 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
558 if_printf(ifp, "cannot enable netmap operation because "
559 "interface is not UP.\n");
563 rxb = &sc->sge.rx_buf_info[0];
564 for (i = 0; i < SW_ZONE_SIZES; i++, rxb++) {
565 if (rxb->size1 == NETMAP_BUF_SIZE(na)) {
569 if (rxb->size2 == NETMAP_BUF_SIZE(na)) {
574 if (i >= SW_ZONE_SIZES) {
575 if_printf(ifp, "no hwidx for netmap buffer size %d.\n",
576 NETMAP_BUF_SIZE(na));
580 /* Must set caps before calling netmap_reset */
581 nm_set_native_flags(na);
583 for_each_nm_rxq(vi, i, nm_rxq) {
584 kring = na->rx_rings[nm_rxq->nid];
585 if (!nm_kring_pending_on(kring) ||
586 nm_rxq->iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID)
589 alloc_nm_rxq_hwq(vi, nm_rxq, tnl_cong(vi->pi, nm_cong_drop));
590 nm_rxq->fl_hwidx = hwidx;
591 nm_rxq->bb_zone = rxb->zone;
592 nm_rxq->bb = uma_zalloc(nm_rxq->bb_zone, M_WAITOK);
593 slot = netmap_reset(na, NR_RX, i, 0);
594 MPASS(slot != NULL); /* XXXNM: error check, not assert */
596 /* We deal with 8 bufs at a time */
597 MPASS((na->num_rx_desc & 7) == 0);
598 MPASS(na->num_rx_desc == nm_rxq->fl_sidx);
599 for (j = 0; j < nm_rxq->fl_sidx; j++) {
602 PNMB(na, &slot[j], &ba);
604 nm_rxq->fl_desc[j] = htobe64(ba | hwidx);
606 j = nm_rxq->fl_pidx = nm_rxq->fl_sidx - 8;
608 j /= 8; /* driver pidx to hardware pidx */
610 t4_write_reg(sc, sc->sge_kdoorbell_reg,
611 nm_rxq->fl_db_val | V_PIDX(j));
613 (void) atomic_cmpset_int(&nm_rxq->nm_state, NM_OFF, NM_ON);
616 for_each_nm_txq(vi, i, nm_txq) {
617 kring = na->tx_rings[nm_txq->nid];
618 if (!nm_kring_pending_on(kring) ||
619 nm_txq->cntxt_id != INVALID_NM_TXQ_CNTXT_ID)
622 alloc_nm_txq_hwq(vi, nm_txq);
623 slot = netmap_reset(na, NR_TX, i, 0);
624 MPASS(slot != NULL); /* XXXNM: error check, not assert */
627 if (vi->nm_rss == NULL) {
628 vi->nm_rss = malloc(vi->rss_size * sizeof(uint16_t), M_CXGBE,
632 return (cxgbe_netmap_rss(sc, vi, ifp, na));
636 flush_nm_rxq(struct adapter *sc, struct vi_info *vi, struct sge_nm_rxq *nm_rxq)
639 u_int fl_pidx, fl_pidx_target, hw_cidx_desc;
640 const uint64_t ba = pmap_kextract((vm_offset_t)nm_rxq->bb);
642 hw_cidx_desc = nm_rxq->fl_cidx / 8;
643 if (hw_cidx_desc == 0)
644 fl_pidx_target = nm_rxq->fl_sidx2 - 8;
646 fl_pidx_target = (hw_cidx_desc - 1) * 8;
647 MPASS((fl_pidx_target & 7) == 0);
649 fl_pidx = nm_rxq->fl_pidx;
650 MPASS((fl_pidx & 7) == 0);
651 for (n = 0; fl_pidx != fl_pidx_target; n++) {
652 for (i = 0; i < 8; i++, fl_pidx++)
653 nm_rxq->fl_desc[fl_pidx] = htobe64(ba | nm_rxq->fl_hwidx);
654 if (__predict_false(fl_pidx == nm_rxq->fl_sidx2))
657 t4_write_reg(sc, sc->sge_kdoorbell_reg, nm_rxq->fl_db_val | V_PIDX(n));
661 cxgbe_netmap_off(struct adapter *sc, struct vi_info *vi, struct ifnet *ifp,
662 struct netmap_adapter *na)
664 struct netmap_kring *kring;
665 int rc, i, nm_state, nactive;
666 struct sge_nm_txq *nm_txq;
667 struct sge_nm_rxq *nm_rxq;
669 ASSERT_SYNCHRONIZED_OP(sc);
670 MPASS(vi->nnmrxq > 0);
671 MPASS(vi->nnmtxq > 0);
673 if (!nm_netmap_on(na))
676 if ((vi->flags & VI_INIT_DONE) == 0)
679 /* First remove the queues that are stopping from the RSS table. */
680 rc = cxgbe_netmap_rss(sc, vi, ifp, na);
682 return (rc); /* error message logged already. */
685 * First pass over the rx queues to make sure they're all caught up.
687 * The freelists could be out of buffers and we may need to arrange
688 * things so that any packets still in flight (after TP's cong_drop
689 * logic but not yet DMA'd) have somewhere to go and do not block the
690 * pipeline. Do this before trying to free any queue.
692 for_each_nm_rxq(vi, i, nm_rxq) {
693 nm_state = atomic_load_int(&nm_rxq->nm_state);
694 kring = na->rx_rings[nm_rxq->nid];
695 if (nm_state == NM_OFF || !nm_kring_pending_off(kring))
697 MPASS(nm_rxq->iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID);
698 flush_nm_rxq(sc, vi, nm_rxq);
701 for_each_nm_txq(vi, i, nm_txq) {
702 struct sge_qstat *spg = (void *)&nm_txq->desc[nm_txq->sidx];
704 kring = na->tx_rings[nm_txq->nid];
705 if (!nm_kring_pending_off(kring) ||
706 nm_txq->cntxt_id == INVALID_NM_TXQ_CNTXT_ID)
709 /* Wait for hw pidx to catch up ... */
710 while (be16toh(nm_txq->pidx) != spg->pidx)
713 /* ... and then for the cidx. */
714 while (spg->pidx != spg->cidx)
717 free_nm_txq_hwq(vi, nm_txq);
719 /* XXX: netmap, not the driver, should do this. */
720 kring->rhead = kring->rcur = kring->nr_hwcur = 0;
721 kring->rtail = kring->nr_hwtail = kring->nkr_num_slots - 1;
724 for_each_nm_rxq(vi, i, nm_rxq) {
725 nm_state = atomic_load_int(&nm_rxq->nm_state);
726 kring = na->rx_rings[nm_rxq->nid];
727 if (nm_state != NM_OFF && !nm_kring_pending_off(kring))
729 if (nm_state == NM_OFF || !nm_kring_pending_off(kring))
732 MPASS(nm_rxq->iq_cntxt_id != INVALID_NM_RXQ_CNTXT_ID);
733 while (!atomic_cmpset_int(&nm_rxq->nm_state, NM_ON, NM_OFF))
736 free_nm_rxq_hwq(vi, nm_rxq);
737 uma_zfree(nm_rxq->bb_zone, nm_rxq->bb);
740 /* XXX: netmap, not the driver, should do this. */
741 kring->rhead = kring->rcur = kring->nr_hwcur = 0;
742 kring->rtail = kring->nr_hwtail = 0;
744 netmap_krings_mode_commit(na, 0);
746 nm_clear_native_flags(na);
752 cxgbe_netmap_reg(struct netmap_adapter *na, int on)
754 struct ifnet *ifp = na->ifp;
755 struct vi_info *vi = ifp->if_softc;
756 struct adapter *sc = vi->adapter;
759 rc = begin_synchronized_op(sc, vi, SLEEP_OK | INTR_OK, "t4nmreg");
763 rc = cxgbe_netmap_on(sc, vi, ifp, na);
765 rc = cxgbe_netmap_off(sc, vi, ifp, na);
766 end_synchronized_op(sc, 0);
771 /* How many packets can a single type1 WR carry in n descriptors */
773 ndesc_to_npkt(const int n)
776 MPASS(n > 0 && n <= SGE_MAX_WR_NDESC);
780 #define MAX_NPKT_IN_TYPE1_WR (ndesc_to_npkt(SGE_MAX_WR_NDESC))
783 * Space (in descriptors) needed for a type1 WR (TX_PKTS or TX_PKTS2) that
787 npkt_to_ndesc(const int n)
790 MPASS(n > 0 && n <= MAX_NPKT_IN_TYPE1_WR);
792 return ((n + 2) / 2);
796 * Space (in 16B units) needed for a type1 WR (TX_PKTS or TX_PKTS2) that
800 npkt_to_len16(const int n)
803 MPASS(n > 0 && n <= MAX_NPKT_IN_TYPE1_WR);
808 #define NMIDXDIFF(q, idx) IDXDIFF((q)->pidx, (q)->idx, (q)->sidx)
811 ring_nm_txq_db(struct adapter *sc, struct sge_nm_txq *nm_txq)
814 u_int db = nm_txq->doorbells;
816 MPASS(nm_txq->pidx != nm_txq->dbidx);
818 n = NMIDXDIFF(nm_txq, dbidx);
820 clrbit(&db, DOORBELL_WCWR);
823 switch (ffs(db) - 1) {
825 *nm_txq->udb = htole32(V_QID(nm_txq->udb_qid) | V_PIDX(n));
828 case DOORBELL_WCWR: {
829 volatile uint64_t *dst, *src;
832 * Queues whose 128B doorbell segment fits in the page do not
833 * use relative qid (udb_qid is always 0). Only queues with
834 * doorbell segments can do WCWR.
836 KASSERT(nm_txq->udb_qid == 0 && n == 1,
837 ("%s: inappropriate doorbell (0x%x, %d, %d) for nm_txq %p",
838 __func__, nm_txq->doorbells, n, nm_txq->pidx, nm_txq));
840 dst = (volatile void *)((uintptr_t)nm_txq->udb +
841 UDBS_WR_OFFSET - UDBS_DB_OFFSET);
842 src = (void *)&nm_txq->desc[nm_txq->dbidx];
843 while (src != (void *)&nm_txq->desc[nm_txq->dbidx + 1])
850 *nm_txq->udb = htole32(V_QID(nm_txq->udb_qid) | V_PIDX(n));
855 t4_write_reg(sc, sc->sge_kdoorbell_reg,
856 V_QID(nm_txq->cntxt_id) | V_PIDX(n));
859 nm_txq->dbidx = nm_txq->pidx;
863 * Write work requests to send 'npkt' frames and ring the doorbell to send them
864 * on their way. No need to check for wraparound.
867 cxgbe_nm_tx(struct adapter *sc, struct sge_nm_txq *nm_txq,
868 struct netmap_kring *kring, int npkt, int npkt_remaining)
870 struct netmap_ring *ring = kring->ring;
871 struct netmap_slot *slot;
872 const u_int lim = kring->nkr_num_slots - 1;
873 struct fw_eth_tx_pkts_wr *wr = (void *)&nm_txq->desc[nm_txq->pidx];
876 struct cpl_tx_pkt_core *cpl;
877 struct ulptx_sgl *usgl;
881 n = min(npkt, MAX_NPKT_IN_TYPE1_WR);
884 wr = (void *)&nm_txq->desc[nm_txq->pidx];
885 wr->op_pkd = nm_txq->op_pkd;
886 wr->equiq_to_len16 = htobe32(V_FW_WR_LEN16(npkt_to_len16(n)));
890 cpl = (void *)(wr + 1);
892 for (i = 0; i < n; i++) {
893 slot = &ring->slot[kring->nr_hwcur];
894 PNMB(kring->na, slot, &ba);
897 cpl->ctrl0 = nm_txq->cpl_ctrl0;
899 cpl->len = htobe16(slot->len);
900 cpl->ctrl1 = nm_txcsum ? 0 :
901 htobe64(F_TXPKT_IPCSUM_DIS | F_TXPKT_L4CSUM_DIS);
903 usgl = (void *)(cpl + 1);
904 usgl->cmd_nsge = htobe32(V_ULPTX_CMD(ULP_TX_SC_DSGL) |
906 usgl->len0 = htobe32(slot->len);
907 usgl->addr0 = htobe64(ba);
909 slot->flags &= ~(NS_REPORT | NS_BUF_CHANGED);
910 cpl = (void *)(usgl + 1);
911 MPASS(slot->len + len <= UINT16_MAX);
913 kring->nr_hwcur = nm_next(kring->nr_hwcur, lim);
915 wr->plen = htobe16(len);
918 nm_txq->pidx += npkt_to_ndesc(n);
919 MPASS(nm_txq->pidx <= nm_txq->sidx);
920 if (__predict_false(nm_txq->pidx == nm_txq->sidx)) {
922 * This routine doesn't know how to write WRs that wrap
923 * around. Make sure it wasn't asked to.
929 if (npkt == 0 && npkt_remaining == 0) {
931 if (lazy_tx_credit_flush == 0) {
932 wr->equiq_to_len16 |= htobe32(F_FW_WR_EQUEQ |
934 nm_txq->equeqidx = nm_txq->pidx;
935 nm_txq->equiqidx = nm_txq->pidx;
937 ring_nm_txq_db(sc, nm_txq);
941 if (NMIDXDIFF(nm_txq, equiqidx) >= nm_txq->sidx / 2) {
942 wr->equiq_to_len16 |= htobe32(F_FW_WR_EQUEQ |
944 nm_txq->equeqidx = nm_txq->pidx;
945 nm_txq->equiqidx = nm_txq->pidx;
946 } else if (NMIDXDIFF(nm_txq, equeqidx) >= 64) {
947 wr->equiq_to_len16 |= htobe32(F_FW_WR_EQUEQ);
948 nm_txq->equeqidx = nm_txq->pidx;
950 if (NMIDXDIFF(nm_txq, dbidx) >= 2 * SGE_MAX_WR_NDESC)
951 ring_nm_txq_db(sc, nm_txq);
954 /* Will get called again. */
955 MPASS(npkt_remaining);
958 /* How many contiguous free descriptors starting at pidx */
960 contiguous_ndesc_available(struct sge_nm_txq *nm_txq)
963 if (nm_txq->cidx > nm_txq->pidx)
964 return (nm_txq->cidx - nm_txq->pidx - 1);
965 else if (nm_txq->cidx > 0)
966 return (nm_txq->sidx - nm_txq->pidx);
968 return (nm_txq->sidx - nm_txq->pidx - 1);
972 reclaim_nm_tx_desc(struct sge_nm_txq *nm_txq)
974 struct sge_qstat *spg = (void *)&nm_txq->desc[nm_txq->sidx];
975 uint16_t hw_cidx = spg->cidx; /* snapshot */
976 struct fw_eth_tx_pkts_wr *wr;
979 hw_cidx = be16toh(hw_cidx);
981 while (nm_txq->cidx != hw_cidx) {
982 wr = (void *)&nm_txq->desc[nm_txq->cidx];
984 MPASS(wr->op_pkd == htobe32(V_FW_WR_OP(FW_ETH_TX_PKTS_WR)) ||
985 wr->op_pkd == htobe32(V_FW_WR_OP(FW_ETH_TX_PKTS2_WR)));
986 MPASS(wr->type == 1);
987 MPASS(wr->npkt > 0 && wr->npkt <= MAX_NPKT_IN_TYPE1_WR);
990 nm_txq->cidx += npkt_to_ndesc(wr->npkt);
993 * We never sent a WR that wrapped around so the credits coming
994 * back, WR by WR, should never cause the cidx to wrap around
997 MPASS(nm_txq->cidx <= nm_txq->sidx);
998 if (__predict_false(nm_txq->cidx == nm_txq->sidx))
1006 cxgbe_netmap_txsync(struct netmap_kring *kring, int flags)
1008 struct netmap_adapter *na = kring->na;
1009 struct ifnet *ifp = na->ifp;
1010 struct vi_info *vi = ifp->if_softc;
1011 struct adapter *sc = vi->adapter;
1012 struct sge_nm_txq *nm_txq = &sc->sge.nm_txq[vi->first_nm_txq + kring->ring_id];
1013 const u_int head = kring->rhead;
1014 u_int reclaimed = 0;
1015 int n, d, npkt_remaining, ndesc_remaining;
1018 * Tx was at kring->nr_hwcur last time around and now we need to advance
1019 * to kring->rhead. Note that the driver's pidx moves independent of
1020 * netmap's kring->nr_hwcur (pidx counts descriptors and the relation
1021 * between descriptors and frames isn't 1:1).
1024 npkt_remaining = head >= kring->nr_hwcur ? head - kring->nr_hwcur :
1025 kring->nkr_num_slots - kring->nr_hwcur + head;
1026 while (npkt_remaining) {
1027 reclaimed += reclaim_nm_tx_desc(nm_txq);
1028 ndesc_remaining = contiguous_ndesc_available(nm_txq);
1029 /* Can't run out of descriptors with packets still remaining */
1030 MPASS(ndesc_remaining > 0);
1032 /* # of desc needed to tx all remaining packets */
1033 d = (npkt_remaining / MAX_NPKT_IN_TYPE1_WR) * SGE_MAX_WR_NDESC;
1034 if (npkt_remaining % MAX_NPKT_IN_TYPE1_WR)
1035 d += npkt_to_ndesc(npkt_remaining % MAX_NPKT_IN_TYPE1_WR);
1037 if (d <= ndesc_remaining)
1040 /* Can't send all, calculate how many can be sent */
1041 n = (ndesc_remaining / SGE_MAX_WR_NDESC) *
1042 MAX_NPKT_IN_TYPE1_WR;
1043 if (ndesc_remaining % SGE_MAX_WR_NDESC)
1044 n += ndesc_to_npkt(ndesc_remaining % SGE_MAX_WR_NDESC);
1047 /* Send n packets and update nm_txq->pidx and kring->nr_hwcur */
1048 npkt_remaining -= n;
1049 cxgbe_nm_tx(sc, nm_txq, kring, n, npkt_remaining);
1051 MPASS(npkt_remaining == 0);
1052 MPASS(kring->nr_hwcur == head);
1053 MPASS(nm_txq->dbidx == nm_txq->pidx);
1056 * Second part: reclaim buffers for completed transmissions.
1058 if (reclaimed || flags & NAF_FORCE_RECLAIM || nm_kr_txempty(kring)) {
1059 reclaimed += reclaim_nm_tx_desc(nm_txq);
1060 kring->nr_hwtail += reclaimed;
1061 if (kring->nr_hwtail >= kring->nkr_num_slots)
1062 kring->nr_hwtail -= kring->nkr_num_slots;
1069 cxgbe_netmap_rxsync(struct netmap_kring *kring, int flags)
1071 struct netmap_adapter *na = kring->na;
1072 struct netmap_ring *ring = kring->ring;
1073 struct ifnet *ifp = na->ifp;
1074 struct vi_info *vi = ifp->if_softc;
1075 struct adapter *sc = vi->adapter;
1076 struct sge_nm_rxq *nm_rxq = &sc->sge.nm_rxq[vi->first_nm_rxq + kring->ring_id];
1077 u_int const head = kring->rhead;
1079 int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR;
1082 return (0); /* No updates ever. */
1084 if (netmap_no_pendintr || force_update) {
1085 kring->nr_hwtail = atomic_load_acq_32(&nm_rxq->fl_cidx);
1086 kring->nr_kflags &= ~NKR_PENDINTR;
1089 if (nm_rxq->fl_db_saved > 0 && starve_fl == 0) {
1091 t4_write_reg(sc, sc->sge_kdoorbell_reg,
1092 nm_rxq->fl_db_val | V_PIDX(nm_rxq->fl_db_saved));
1093 nm_rxq->fl_db_saved = 0;
1096 /* Userspace done with buffers from kring->nr_hwcur to head */
1097 n = head >= kring->nr_hwcur ? head - kring->nr_hwcur :
1098 kring->nkr_num_slots - kring->nr_hwcur + head;
1101 u_int fl_pidx = nm_rxq->fl_pidx;
1102 struct netmap_slot *slot = &ring->slot[fl_pidx];
1104 int i, dbinc = 0, hwidx = nm_rxq->fl_hwidx;
1107 * We always deal with 8 buffers at a time. We must have
1108 * stopped at an 8B boundary (fl_pidx) last time around and we
1109 * must have a multiple of 8B buffers to give to the freelist.
1111 MPASS((fl_pidx & 7) == 0);
1112 MPASS((n & 7) == 0);
1114 IDXINCR(kring->nr_hwcur, n, kring->nkr_num_slots);
1115 IDXINCR(nm_rxq->fl_pidx, n, nm_rxq->fl_sidx2);
1118 for (i = 0; i < 8; i++, fl_pidx++, slot++) {
1119 PNMB(na, slot, &ba);
1121 nm_rxq->fl_desc[fl_pidx] = htobe64(ba | hwidx);
1122 slot->flags &= ~NS_BUF_CHANGED;
1123 MPASS(fl_pidx <= nm_rxq->fl_sidx2);
1126 if (fl_pidx == nm_rxq->fl_sidx2) {
1128 slot = &ring->slot[0];
1130 if (++dbinc == nm_rxq->fl_db_threshold) {
1133 nm_rxq->fl_db_saved += dbinc;
1135 t4_write_reg(sc, sc->sge_kdoorbell_reg,
1136 nm_rxq->fl_db_val | V_PIDX(dbinc));
1141 MPASS(nm_rxq->fl_pidx == fl_pidx);
1146 nm_rxq->fl_db_saved += dbinc;
1148 t4_write_reg(sc, sc->sge_kdoorbell_reg,
1149 nm_rxq->fl_db_val | V_PIDX(dbinc));
1158 cxgbe_nm_attach(struct vi_info *vi)
1160 struct port_info *pi;
1162 struct netmap_adapter na;
1164 MPASS(vi->nnmrxq > 0);
1165 MPASS(vi->ifp != NULL);
1170 bzero(&na, sizeof(na));
1173 na.na_flags = NAF_BDG_MAYSLEEP;
1175 /* Netmap doesn't know about the space reserved for the status page. */
1176 na.num_tx_desc = vi->qsize_txq - sc->params.sge.spg_len / EQ_ESIZE;
1179 * The freelist's cidx/pidx drives netmap's rx cidx/pidx. So
1180 * num_rx_desc is based on the number of buffers that can be held in the
1181 * freelist, and not the number of entries in the iq. (These two are
1182 * not exactly the same due to the space taken up by the status page).
1184 na.num_rx_desc = rounddown(vi->qsize_rxq, 8);
1185 na.nm_txsync = cxgbe_netmap_txsync;
1186 na.nm_rxsync = cxgbe_netmap_rxsync;
1187 na.nm_register = cxgbe_netmap_reg;
1188 na.num_tx_rings = vi->nnmtxq;
1189 na.num_rx_rings = vi->nnmrxq;
1190 na.rx_buf_maxsize = MAX_MTU;
1191 netmap_attach(&na); /* This adds IFCAP_NETMAP to if_capabilities */
1195 cxgbe_nm_detach(struct vi_info *vi)
1198 MPASS(vi->nnmrxq > 0);
1199 MPASS(vi->ifp != NULL);
1201 netmap_detach(vi->ifp);
1204 static inline const void *
1205 unwrap_nm_fw6_msg(const struct cpl_fw6_msg *cpl)
1208 MPASS(cpl->type == FW_TYPE_RSSCPL || cpl->type == FW6_TYPE_RSSCPL);
1210 /* data[0] is RSS header */
1211 return (&cpl->data[1]);
1215 handle_nm_sge_egr_update(struct adapter *sc, struct ifnet *ifp,
1216 const struct cpl_sge_egr_update *egr)
1219 struct sge_nm_txq *nm_txq;
1221 oq = be32toh(egr->opcode_qid);
1222 MPASS(G_CPL_OPCODE(oq) == CPL_SGE_EGR_UPDATE);
1223 nm_txq = (void *)sc->sge.eqmap[G_EGR_QID(oq) - sc->sge.eq_start];
1225 netmap_tx_irq(ifp, nm_txq->nid);
1229 service_nm_rxq(struct sge_nm_rxq *nm_rxq)
1231 struct vi_info *vi = nm_rxq->vi;
1232 struct adapter *sc = vi->adapter;
1233 struct ifnet *ifp = vi->ifp;
1234 struct netmap_adapter *na = NA(ifp);
1235 struct netmap_kring *kring = na->rx_rings[nm_rxq->nid];
1236 struct netmap_ring *ring = kring->ring;
1237 struct iq_desc *d = &nm_rxq->iq_desc[nm_rxq->iq_cidx];
1242 uint32_t fl_cidx = atomic_load_acq_32(&nm_rxq->fl_cidx);
1243 u_int fl_credits = fl_cidx & 7;
1244 u_int ndesc = 0; /* desc processed since last cidx update */
1245 u_int nframes = 0; /* frames processed since last netmap wakeup */
1247 while ((d->rsp.u.type_gen & F_RSPD_GEN) == nm_rxq->iq_gen) {
1251 lq = be32toh(d->rsp.pldbuflen_qid);
1252 opcode = d->rss.opcode;
1255 switch (G_RSPD_TYPE(d->rsp.u.type_gen)) {
1256 case X_RSPD_TYPE_FLBUF:
1260 case X_RSPD_TYPE_CPL:
1261 MPASS(opcode < NUM_CPL_CMDS);
1266 cpl = unwrap_nm_fw6_msg(cpl);
1268 case CPL_SGE_EGR_UPDATE:
1269 handle_nm_sge_egr_update(sc, ifp, cpl);
1272 ring->slot[fl_cidx].len = G_RSPD_LEN(lq) -
1273 sc->params.sge.fl_pktshift;
1274 ring->slot[fl_cidx].flags = 0;
1276 if (!(lq & F_RSPD_NEWBUF)) {
1277 MPASS(black_hole == 2);
1281 if (__predict_false(++fl_cidx == nm_rxq->fl_sidx))
1285 panic("%s: unexpected opcode 0x%x on nm_rxq %p",
1286 __func__, opcode, nm_rxq);
1290 case X_RSPD_TYPE_INTR:
1291 /* Not equipped to handle forwarded interrupts. */
1292 panic("%s: netmap queue received interrupt for iq %u\n",
1296 panic("%s: illegal response type %d on nm_rxq %p",
1297 __func__, G_RSPD_TYPE(d->rsp.u.type_gen), nm_rxq);
1301 if (__predict_false(++nm_rxq->iq_cidx == nm_rxq->iq_sidx)) {
1302 nm_rxq->iq_cidx = 0;
1303 d = &nm_rxq->iq_desc[0];
1304 nm_rxq->iq_gen ^= F_RSPD_GEN;
1307 if (__predict_false(++nframes == rx_nframes) && !black_hole) {
1308 atomic_store_rel_32(&nm_rxq->fl_cidx, fl_cidx);
1309 netmap_rx_irq(ifp, nm_rxq->nid, &work);
1313 if (__predict_false(++ndesc == rx_ndesc)) {
1314 if (black_hole && fl_credits >= 8) {
1316 IDXINCR(nm_rxq->fl_pidx, fl_credits * 8,
1318 t4_write_reg(sc, sc->sge_kdoorbell_reg,
1319 nm_rxq->fl_db_val | V_PIDX(fl_credits));
1320 fl_credits = fl_cidx & 7;
1322 t4_write_reg(sc, sc->sge_gts_reg,
1324 V_INGRESSQID(nm_rxq->iq_cntxt_id) |
1325 V_SEINTARM(V_QINTR_TIMER_IDX(X_TIMERREG_UPDATE_CIDX)));
1330 atomic_store_rel_32(&nm_rxq->fl_cidx, fl_cidx);
1333 IDXINCR(nm_rxq->fl_pidx, fl_credits * 8, nm_rxq->fl_sidx);
1334 t4_write_reg(sc, sc->sge_kdoorbell_reg,
1335 nm_rxq->fl_db_val | V_PIDX(fl_credits));
1336 } else if (nframes > 0)
1337 netmap_rx_irq(ifp, nm_rxq->nid, &work);
1339 t4_write_reg(sc, sc->sge_gts_reg, V_CIDXINC(ndesc) |
1340 V_INGRESSQID((u32)nm_rxq->iq_cntxt_id) |
1341 V_SEINTARM(V_QINTR_TIMER_IDX(holdoff_tmr_idx)));