2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2018 Chelsio Communications, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * 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"
34 #include <sys/param.h>
35 #include <sys/eventhandler.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
41 #include <sys/mutex.h>
42 #include <sys/rwlock.h>
43 #include <sys/socket.h>
45 #include <netinet/in.h>
47 #include "common/common.h"
48 #include "common/t4_msg.h"
49 #include "common/t4_regs.h"
50 #include "common/t4_regs_values.h"
51 #include "common/t4_tcb.h"
55 uint32_t valid:1; /* filter allocated and valid */
56 uint32_t locked:1; /* filter is administratively locked or busy */
57 uint32_t pending:1; /* filter action is pending firmware reply */
58 uint32_t smtidx:8; /* Source MAC Table index for smac */
59 int tid; /* tid of the filter TCB */
60 struct l2t_entry *l2te; /* L2 table entry for DMAC rewrite */
62 struct t4_filter_specification fs;
65 static void free_filter_resources(struct filter_entry *);
66 static int get_hashfilter(struct adapter *, struct t4_filter *);
67 static int set_hashfilter(struct adapter *, struct t4_filter *, uint64_t,
69 static int del_hashfilter(struct adapter *, struct t4_filter *);
70 static int configure_hashfilter_tcb(struct adapter *, struct filter_entry *);
73 insert_hftid(struct adapter *sc, int tid, void *ctx, int ntids)
75 struct tid_info *t = &sc->tids;
77 t->hftid_tab[tid] = ctx;
78 atomic_add_int(&t->tids_in_use, ntids);
82 lookup_hftid(struct adapter *sc, int tid)
84 struct tid_info *t = &sc->tids;
86 return (t->hftid_tab[tid]);
90 remove_hftid(struct adapter *sc, int tid, int ntids)
92 struct tid_info *t = &sc->tids;
94 t->hftid_tab[tid] = NULL;
95 atomic_subtract_int(&t->tids_in_use, ntids);
99 mode_to_fconf(uint32_t mode)
103 if (mode & T4_FILTER_IP_FRAGMENT)
104 fconf |= F_FRAGMENTATION;
106 if (mode & T4_FILTER_MPS_HIT_TYPE)
107 fconf |= F_MPSHITTYPE;
109 if (mode & T4_FILTER_MAC_IDX)
112 if (mode & T4_FILTER_ETH_TYPE)
113 fconf |= F_ETHERTYPE;
115 if (mode & T4_FILTER_IP_PROTO)
118 if (mode & T4_FILTER_IP_TOS)
121 if (mode & T4_FILTER_VLAN)
124 if (mode & T4_FILTER_VNIC)
127 if (mode & T4_FILTER_PORT)
130 if (mode & T4_FILTER_FCoE)
137 mode_to_iconf(uint32_t mode)
140 if (mode & T4_FILTER_IC_VNIC)
146 check_fspec_against_fconf_iconf(struct adapter *sc,
147 struct t4_filter_specification *fs)
149 struct tp_params *tpp = &sc->params.tp;
152 if (fs->val.frag || fs->mask.frag)
153 fconf |= F_FRAGMENTATION;
155 if (fs->val.matchtype || fs->mask.matchtype)
156 fconf |= F_MPSHITTYPE;
158 if (fs->val.macidx || fs->mask.macidx)
161 if (fs->val.ethtype || fs->mask.ethtype)
162 fconf |= F_ETHERTYPE;
164 if (fs->val.proto || fs->mask.proto)
167 if (fs->val.tos || fs->mask.tos)
170 if (fs->val.vlan_vld || fs->mask.vlan_vld)
173 if (fs->val.ovlan_vld || fs->mask.ovlan_vld) {
175 if (tpp->ingress_config & F_VNIC)
179 if (fs->val.pfvf_vld || fs->mask.pfvf_vld) {
181 if ((tpp->ingress_config & F_VNIC) == 0)
185 if (fs->val.iport || fs->mask.iport)
188 if (fs->val.fcoe || fs->mask.fcoe)
191 if ((tpp->vlan_pri_map | fconf) != tpp->vlan_pri_map)
198 get_filter_mode(struct adapter *sc, uint32_t *mode)
200 struct tp_params *tp = &sc->params.tp;
203 /* Non-zero incoming value in mode means "hashfilter mode". */
204 mask = *mode ? tp->hash_filter_mask : UINT64_MAX;
207 *mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
208 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
210 #define CHECK_FIELD(fconf_bit, field_shift, field_mask, mode_bit) do { \
211 if (tp->vlan_pri_map & (fconf_bit)) { \
212 MPASS(tp->field_shift >= 0); \
213 if ((mask >> tp->field_shift & field_mask) == field_mask) \
214 *mode |= (mode_bit); \
218 CHECK_FIELD(F_FRAGMENTATION, frag_shift, M_FT_FRAGMENTATION, T4_FILTER_IP_FRAGMENT);
219 CHECK_FIELD(F_MPSHITTYPE, matchtype_shift, M_FT_MPSHITTYPE, T4_FILTER_MPS_HIT_TYPE);
220 CHECK_FIELD(F_MACMATCH, macmatch_shift, M_FT_MACMATCH, T4_FILTER_MAC_IDX);
221 CHECK_FIELD(F_ETHERTYPE, ethertype_shift, M_FT_ETHERTYPE, T4_FILTER_ETH_TYPE);
222 CHECK_FIELD(F_PROTOCOL, protocol_shift, M_FT_PROTOCOL, T4_FILTER_IP_PROTO);
223 CHECK_FIELD(F_TOS, tos_shift, M_FT_TOS, T4_FILTER_IP_TOS);
224 CHECK_FIELD(F_VLAN, vlan_shift, M_FT_VLAN, T4_FILTER_VLAN);
225 CHECK_FIELD(F_VNIC_ID, vnic_shift, M_FT_VNIC_ID , T4_FILTER_VNIC);
226 if (tp->ingress_config & F_VNIC)
227 *mode |= T4_FILTER_IC_VNIC;
228 CHECK_FIELD(F_PORT, port_shift, M_FT_PORT , T4_FILTER_PORT);
229 CHECK_FIELD(F_FCOE, fcoe_shift, M_FT_FCOE , T4_FILTER_FCoE);
236 set_filter_mode(struct adapter *sc, uint32_t mode)
238 struct tp_params *tpp = &sc->params.tp;
239 uint32_t fconf, iconf;
242 iconf = mode_to_iconf(mode);
243 if ((iconf ^ tpp->ingress_config) & F_VNIC) {
245 * For now we just complain if A_TP_INGRESS_CONFIG is not
246 * already set to the correct value for the requested filter
247 * mode. It's not clear if it's safe to write to this register
248 * on the fly. (And we trust the cached value of the register).
250 * check_fspec_against_fconf_iconf and other code that looks at
251 * tp->vlan_pri_map and tp->ingress_config needs to be reviewed
252 * thorougly before allowing dynamic filter mode changes.
257 fconf = mode_to_fconf(mode);
259 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
264 if (sc->tids.ftids_in_use > 0) {
270 if (uld_active(sc, ULD_TOM)) {
276 rc = -t4_set_filter_mode(sc, fconf, true);
278 end_synchronized_op(sc, LOCK_HELD);
282 static inline uint64_t
283 get_filter_hits(struct adapter *sc, uint32_t tid)
287 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE) + tid * TCB_SIZE;
292 read_via_memwin(sc, 0, tcb_addr + 16, (uint32_t *)&hits, 8);
293 return (be64toh(hits));
297 read_via_memwin(sc, 0, tcb_addr + 24, &hits, 4);
298 return (be32toh(hits));
303 get_filter(struct adapter *sc, struct t4_filter *t)
305 int i, nfilters = sc->tids.nftids;
306 struct filter_entry *f;
309 return (get_hashfilter(sc, t));
311 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
312 t->idx >= nfilters) {
317 mtx_lock(&sc->tids.ftid_lock);
318 f = &sc->tids.ftid_tab[t->idx];
319 MPASS(f->tid == sc->tids.ftid_base + t->idx);
320 for (i = t->idx; i < nfilters; i++, f++) {
323 t->l2tidx = f->l2te ? f->l2te->idx : 0;
324 t->smtidx = f->smtidx;
326 t->hits = get_filter_hits(sc, f->tid);
328 t->hits = UINT64_MAX;
336 mtx_unlock(&sc->tids.ftid_lock);
341 set_tcamfilter(struct adapter *sc, struct t4_filter *t, struct l2t_entry *l2te)
343 struct filter_entry *f;
344 struct fw_filter2_wr *fwr;
345 u_int vnic_vld, vnic_vld_mask;
346 struct wrq_cookie cookie;
347 int i, rc, busy, locked;
348 const int ntids = t->fs.type ? 4 : 1;
351 MPASS(t->idx < sc->tids.nftids);
352 /* Already validated against fconf, iconf */
353 MPASS((t->fs.val.pfvf_vld & t->fs.val.ovlan_vld) == 0);
354 MPASS((t->fs.mask.pfvf_vld & t->fs.mask.ovlan_vld) == 0);
356 f = &sc->tids.ftid_tab[t->idx];
357 rc = busy = locked = 0;
358 mtx_lock(&sc->tids.ftid_lock);
359 for (i = 0; i < ntids; i++) {
360 busy += f[i].pending + f[i].valid;
361 locked += f[i].locked;
370 if (sc->params.filter2_wr_support)
371 len16 = howmany(sizeof(struct fw_filter2_wr), 16);
373 len16 = howmany(sizeof(struct fw_filter_wr), 16);
374 fwr = start_wrq_wr(&sc->sge.mgmtq, len16, &cookie);
375 if (__predict_false(fwr == NULL))
379 sc->tids.ftids_in_use++;
382 mtx_unlock(&sc->tids.ftid_lock);
385 t4_l2t_release(l2te);
390 * Can't fail now. A set-filter WR will definitely be sent.
393 f->tid = sc->tids.ftid_base + t->idx;
397 if (t->fs.val.pfvf_vld || t->fs.val.ovlan_vld)
401 if (t->fs.mask.pfvf_vld || t->fs.mask.ovlan_vld)
406 bzero(fwr, sizeof(*fwr));
407 if (sc->params.filter2_wr_support)
408 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER2_WR));
410 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
411 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
413 htobe32(V_FW_FILTER_WR_TID(f->tid) |
414 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
415 V_FW_FILTER_WR_NOREPLY(0) |
416 V_FW_FILTER_WR_IQ(f->fs.iq));
417 fwr->del_filter_to_l2tix =
418 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
419 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
420 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
421 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
422 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
423 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
424 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
425 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
426 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
427 f->fs.newvlan == VLAN_REWRITE) |
428 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
429 f->fs.newvlan == VLAN_REWRITE) |
430 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
431 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
432 V_FW_FILTER_WR_PRIO(f->fs.prio) |
433 V_FW_FILTER_WR_L2TIX(f->l2te ? f->l2te->idx : 0));
434 fwr->ethtype = htobe16(f->fs.val.ethtype);
435 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
436 fwr->frag_to_ovlan_vldm =
437 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
438 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
439 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
440 V_FW_FILTER_WR_OVLAN_VLD(vnic_vld) |
441 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
442 V_FW_FILTER_WR_OVLAN_VLDM(vnic_vld_mask));
444 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
445 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
446 fwr->maci_to_matchtypem =
447 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
448 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
449 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
450 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
451 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
452 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
453 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
454 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
455 fwr->ptcl = f->fs.val.proto;
456 fwr->ptclm = f->fs.mask.proto;
457 fwr->ttyp = f->fs.val.tos;
458 fwr->ttypm = f->fs.mask.tos;
459 fwr->ivlan = htobe16(f->fs.val.vlan);
460 fwr->ivlanm = htobe16(f->fs.mask.vlan);
461 fwr->ovlan = htobe16(f->fs.val.vnic);
462 fwr->ovlanm = htobe16(f->fs.mask.vnic);
463 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
464 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
465 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
466 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
467 fwr->lp = htobe16(f->fs.val.dport);
468 fwr->lpm = htobe16(f->fs.mask.dport);
469 fwr->fp = htobe16(f->fs.val.sport);
470 fwr->fpm = htobe16(f->fs.mask.sport);
472 /* XXX: need to use SMT idx instead */
473 bcopy(f->fs.smac, fwr->sma, sizeof (fwr->sma));
475 if (sc->params.filter2_wr_support) {
476 fwr->filter_type_swapmac =
477 V_FW_FILTER2_WR_SWAPMAC(f->fs.swapmac);
478 fwr->natmode_to_ulp_type =
479 V_FW_FILTER2_WR_ULP_TYPE(f->fs.nat_mode ?
480 ULP_MODE_TCPDDP : ULP_MODE_NONE) |
481 V_FW_FILTER2_WR_NATFLAGCHECK(f->fs.nat_flag_chk) |
482 V_FW_FILTER2_WR_NATMODE(f->fs.nat_mode);
483 memcpy(fwr->newlip, f->fs.nat_dip, sizeof(fwr->newlip));
484 memcpy(fwr->newfip, f->fs.nat_sip, sizeof(fwr->newfip));
485 fwr->newlport = htobe16(f->fs.nat_dport);
486 fwr->newfport = htobe16(f->fs.nat_sport);
487 fwr->natseqcheck = htobe32(f->fs.nat_seq_chk);
489 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
491 /* Wait for response. */
492 mtx_lock(&sc->tids.ftid_lock);
494 if (f->pending == 0) {
495 rc = f->valid ? 0 : EIO;
498 if (cv_wait_sig(&sc->tids.ftid_cv, &sc->tids.ftid_lock) != 0) {
503 mtx_unlock(&sc->tids.ftid_lock);
508 hashfilter_ntuple(struct adapter *sc, const struct t4_filter_specification *fs,
511 struct tp_params *tp = &sc->params.tp;
517 * Initialize each of the fields which we care about which are present
518 * in the Compressed Filter Tuple.
520 if (tp->vlan_shift >= 0 && fs->mask.vlan) {
521 *ftuple |= (F_FT_VLAN_VLD | fs->val.vlan) << tp->vlan_shift;
522 fmask |= M_FT_VLAN << tp->vlan_shift;
525 if (tp->port_shift >= 0 && fs->mask.iport) {
526 *ftuple |= (uint64_t)fs->val.iport << tp->port_shift;
527 fmask |= M_FT_PORT << tp->port_shift;
530 if (tp->protocol_shift >= 0 && fs->mask.proto) {
531 *ftuple |= (uint64_t)fs->val.proto << tp->protocol_shift;
532 fmask |= M_FT_PROTOCOL << tp->protocol_shift;
535 if (tp->tos_shift >= 0 && fs->mask.tos) {
536 *ftuple |= (uint64_t)(fs->val.tos) << tp->tos_shift;
537 fmask |= M_FT_TOS << tp->tos_shift;
540 if (tp->vnic_shift >= 0 && fs->mask.vnic) {
541 /* F_VNIC in ingress config was already validated. */
542 if (tp->ingress_config & F_VNIC)
543 MPASS(fs->mask.pfvf_vld);
545 MPASS(fs->mask.ovlan_vld);
547 *ftuple |= ((1ULL << 16) | fs->val.vnic) << tp->vnic_shift;
548 fmask |= M_FT_VNIC_ID << tp->vnic_shift;
551 if (tp->macmatch_shift >= 0 && fs->mask.macidx) {
552 *ftuple |= (uint64_t)(fs->val.macidx) << tp->macmatch_shift;
553 fmask |= M_FT_MACMATCH << tp->macmatch_shift;
556 if (tp->ethertype_shift >= 0 && fs->mask.ethtype) {
557 *ftuple |= (uint64_t)(fs->val.ethtype) << tp->ethertype_shift;
558 fmask |= M_FT_ETHERTYPE << tp->ethertype_shift;
561 if (tp->matchtype_shift >= 0 && fs->mask.matchtype) {
562 *ftuple |= (uint64_t)(fs->val.matchtype) << tp->matchtype_shift;
563 fmask |= M_FT_MPSHITTYPE << tp->matchtype_shift;
566 if (tp->frag_shift >= 0 && fs->mask.frag) {
567 *ftuple |= (uint64_t)(fs->val.frag) << tp->frag_shift;
568 fmask |= M_FT_FRAGMENTATION << tp->frag_shift;
571 if (tp->fcoe_shift >= 0 && fs->mask.fcoe) {
572 *ftuple |= (uint64_t)(fs->val.fcoe) << tp->fcoe_shift;
573 fmask |= M_FT_FCOE << tp->fcoe_shift;
576 /* A hashfilter must conform to the filterMask. */
577 if (fmask != tp->hash_filter_mask)
584 set_filter(struct adapter *sc, struct t4_filter *t)
586 struct tid_info *ti = &sc->tids;
587 struct l2t_entry *l2te;
592 * Basic filter checks first.
596 if (!is_hashfilter(sc) || ti->ntids == 0)
598 /* Hardware, not user, selects a tid for hashfilters. */
599 if (t->idx != (uint32_t)-1)
601 /* T5 can't count hashfilter hits. */
602 if (is_t5(sc) && t->fs.hitcnts)
604 rc = hashfilter_ntuple(sc, &t->fs, &ftuple);
610 if (t->idx >= ti->nftids)
612 /* IPv6 filter idx must be 4 aligned */
613 if (t->fs.type == 1 &&
614 ((t->idx & 0x3) || t->idx + 4 >= ti->nftids))
618 /* T4 doesn't support VLAN tag removal or rewrite, swapmac, and NAT. */
619 if (is_t4(sc) && t->fs.action == FILTER_SWITCH &&
620 (t->fs.newvlan == VLAN_REMOVE || t->fs.newvlan == VLAN_REWRITE ||
621 t->fs.swapmac || t->fs.nat_mode))
624 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= sc->params.nports)
626 if (t->fs.val.iport >= sc->params.nports)
629 /* Can't specify an iq if not steering to it */
630 if (!t->fs.dirsteer && t->fs.iq)
633 /* Validate against the global filter mode and ingress config */
634 rc = check_fspec_against_fconf_iconf(sc, &t->fs);
639 * Basic checks passed. Make sure the queues and tid tables are setup.
642 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
645 if (!(sc->flags & FULL_INIT_DONE) &&
646 ((rc = adapter_full_init(sc)) != 0)) {
647 end_synchronized_op(sc, 0);
651 if (__predict_false(ti->hftid_tab == NULL)) {
652 ti->hftid_tab = malloc(sizeof(*ti->hftid_tab) * ti->ntids,
653 M_CXGBE, M_NOWAIT | M_ZERO);
654 if (ti->hftid_tab == NULL) {
658 mtx_init(&ti->hftid_lock, "T4 hashfilters", 0, MTX_DEF);
659 cv_init(&ti->hftid_cv, "t4hfcv");
661 if (__predict_false(sc->tids.atid_tab == NULL)) {
662 rc = alloc_atid_tab(&sc->tids, M_NOWAIT);
666 } else if (__predict_false(ti->ftid_tab == NULL)) {
667 KASSERT(ti->ftids_in_use == 0,
668 ("%s: no memory allocated but ftids_in_use > 0", __func__));
669 ti->ftid_tab = malloc(sizeof(struct filter_entry) * ti->nftids,
670 M_CXGBE, M_NOWAIT | M_ZERO);
671 if (ti->ftid_tab == NULL) {
675 mtx_init(&ti->ftid_lock, "T4 filters", 0, MTX_DEF);
676 cv_init(&ti->ftid_cv, "t4fcv");
679 end_synchronized_op(sc, 0);
684 * Allocate L2T entry, SMT entry, etc.
688 if (t->fs.newdmac || t->fs.newvlan) {
689 /* This filter needs an L2T entry; allocate one. */
690 l2te = t4_l2t_alloc_switching(sc->l2t);
691 if (__predict_false(l2te == NULL))
693 if (t4_l2t_set_switching(sc, l2te, t->fs.vlan, t->fs.eport,
695 t4_l2t_release(l2te);
706 return (set_hashfilter(sc, t, ftuple, l2te));
708 return (set_tcamfilter(sc, t, l2te));
713 del_tcamfilter(struct adapter *sc, struct t4_filter *t)
715 struct filter_entry *f;
716 struct fw_filter_wr *fwr;
717 struct wrq_cookie cookie;
720 MPASS(sc->tids.ftid_tab != NULL);
721 MPASS(sc->tids.nftids > 0);
723 if (t->idx >= sc->tids.nftids)
726 mtx_lock(&sc->tids.ftid_lock);
727 f = &sc->tids.ftid_tab[t->idx];
740 MPASS(f->tid == sc->tids.ftid_base + t->idx);
741 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
747 bzero(fwr, sizeof (*fwr));
748 t4_mk_filtdelwr(f->tid, fwr, sc->sge.fwq.abs_id);
750 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
751 t->fs = f->fs; /* extra info for the caller */
754 if (f->pending == 0) {
755 rc = f->valid ? EIO : 0;
758 if (cv_wait_sig(&sc->tids.ftid_cv, &sc->tids.ftid_lock) != 0) {
764 mtx_unlock(&sc->tids.ftid_lock);
769 del_filter(struct adapter *sc, struct t4_filter *t)
772 /* No filters possible if not initialized yet. */
773 if (!(sc->flags & FULL_INIT_DONE))
777 * The checks for tid tables ensure that the locks that del_* will reach
778 * for are initialized.
781 if (sc->tids.hftid_tab != NULL)
782 return (del_hashfilter(sc, t));
784 if (sc->tids.ftid_tab != NULL)
785 return (del_tcamfilter(sc, t));
792 * Release secondary resources associated with the filter.
795 free_filter_resources(struct filter_entry *f)
799 t4_l2t_release(f->l2te);
805 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
807 struct adapter *sc = iq->adapter;
808 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
809 u_int tid = GET_TID(rpl);
810 u_int rc, cleanup, idx;
811 struct filter_entry *f;
813 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
815 MPASS(is_ftid(sc, tid));
818 idx = tid - sc->tids.ftid_base;
819 f = &sc->tids.ftid_tab[idx];
820 rc = G_COOKIE(rpl->cookie);
822 mtx_lock(&sc->tids.ftid_lock);
823 KASSERT(f->pending, ("%s: reply %d for filter[%u] that isn't pending.",
826 case FW_FILTER_WR_FLT_ADDED:
827 /* set-filter succeeded */
829 f->smtidx = (be64toh(rpl->oldval) >> 24) & 0xff;
831 case FW_FILTER_WR_FLT_DELETED:
832 /* del-filter succeeded */
833 MPASS(f->valid == 1);
836 case FW_FILTER_WR_SMT_TBL_FULL:
837 /* set-filter failed due to lack of SMT space. */
838 MPASS(f->valid == 0);
839 free_filter_resources(f);
840 sc->tids.ftids_in_use--;
842 case FW_FILTER_WR_SUCCESS:
843 case FW_FILTER_WR_EINVAL:
845 panic("%s: unexpected reply %d for filter[%d].", __func__, rc,
849 cv_broadcast(&sc->tids.ftid_cv);
850 mtx_unlock(&sc->tids.ftid_lock);
856 * This is the reply to the Active Open that created the filter. Additional TCB
857 * updates may be required to complete the filter configuration.
860 t4_hashfilter_ao_rpl(struct sge_iq *iq, const struct rss_header *rss,
863 struct adapter *sc = iq->adapter;
864 const struct cpl_act_open_rpl *cpl = (const void *)(rss + 1);
865 u_int atid = G_TID_TID(G_AOPEN_ATID(be32toh(cpl->atid_status)));
866 u_int status = G_AOPEN_STATUS(be32toh(cpl->atid_status));
867 struct filter_entry *f = lookup_atid(sc, atid);
869 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
871 mtx_lock(&sc->tids.hftid_lock);
872 KASSERT(f->pending, ("%s: hashfilter[%p] isn't pending.", __func__, f));
873 KASSERT(f->tid == -1, ("%s: hashfilter[%p] has tid %d already.",
874 __func__, f, f->tid));
875 if (status == CPL_ERR_NONE) {
876 struct filter_entry *f2;
878 f->tid = GET_TID(cpl);
879 MPASS(f->tid < sc->tids.ntids);
880 if (__predict_false((f2 = lookup_hftid(sc, f->tid)) != NULL)) {
881 /* XXX: avoid hash collisions in the first place. */
882 MPASS(f2->tid == f->tid);
883 remove_hftid(sc, f2->tid, f2->fs.type ? 2 : 1);
884 free_filter_resources(f2);
887 insert_hftid(sc, f->tid, f, f->fs.type ? 2 : 1);
889 * Leave the filter pending until it is fully set up, which will
890 * be indicated by the reply to the last TCB update. No need to
891 * unblock the ioctl thread either.
893 if (configure_hashfilter_tcb(sc, f) == EINPROGRESS)
898 /* provide errno instead of tid to ioctl */
899 f->tid = act_open_rpl_status_to_errno(status);
901 if (act_open_has_tid(status))
902 release_tid(sc, GET_TID(cpl), &sc->sge.mgmtq);
903 free_filter_resources(f);
907 cv_broadcast(&sc->tids.hftid_cv);
909 mtx_unlock(&sc->tids.hftid_lock);
916 t4_hashfilter_tcb_rpl(struct sge_iq *iq, const struct rss_header *rss,
919 struct adapter *sc = iq->adapter;
920 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
921 u_int tid = GET_TID(rpl);
922 struct filter_entry *f;
924 mtx_lock(&sc->tids.hftid_lock);
925 f = lookup_hftid(sc, tid);
926 KASSERT(f->tid == tid, ("%s: filter tid mismatch", __func__));
927 KASSERT(f->pending, ("%s: hashfilter %p [%u] isn't pending.", __func__,
929 KASSERT(f->valid == 0, ("%s: hashfilter %p [%u] is valid already.",
932 if (rpl->status == 0) {
937 free_filter_resources(f);
938 remove_hftid(sc, tid, f->fs.type ? 2 : 1);
939 release_tid(sc, tid, &sc->sge.mgmtq);
943 cv_broadcast(&sc->tids.hftid_cv);
944 mtx_unlock(&sc->tids.hftid_lock);
950 t4_del_hashfilter_rpl(struct sge_iq *iq, const struct rss_header *rss,
953 struct adapter *sc = iq->adapter;
954 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
955 unsigned int tid = GET_TID(cpl);
956 struct filter_entry *f;
958 mtx_lock(&sc->tids.hftid_lock);
959 f = lookup_hftid(sc, tid);
960 KASSERT(f->tid == tid, ("%s: filter tid mismatch", __func__));
961 KASSERT(f->pending, ("%s: hashfilter %p [%u] isn't pending.", __func__,
963 KASSERT(f->valid, ("%s: hashfilter %p [%u] isn't valid.", __func__, f,
966 if (cpl->status == 0) {
968 free_filter_resources(f);
969 remove_hftid(sc, tid, f->fs.type ? 2 : 1);
970 release_tid(sc, tid, &sc->sge.mgmtq);
974 cv_broadcast(&sc->tids.hftid_cv);
975 mtx_unlock(&sc->tids.hftid_lock);
981 get_hashfilter(struct adapter *sc, struct t4_filter *t)
983 int i, nfilters = sc->tids.ntids;
984 struct filter_entry *f;
986 if (sc->tids.tids_in_use == 0 || sc->tids.hftid_tab == NULL ||
987 t->idx >= nfilters) {
992 mtx_lock(&sc->tids.hftid_lock);
993 for (i = t->idx; i < nfilters; i++) {
994 f = lookup_hftid(sc, i);
995 if (f != NULL && f->valid) {
997 t->l2tidx = f->l2te ? f->l2te->idx : 0;
998 t->smtidx = f->smtidx;
1000 t->hits = get_filter_hits(sc, t->idx);
1002 t->hits = UINT64_MAX;
1008 t->idx = 0xffffffff;
1010 mtx_unlock(&sc->tids.hftid_lock);
1015 mk_act_open_req6(struct adapter *sc, struct filter_entry *f, int atid,
1016 uint64_t ftuple, struct cpl_act_open_req6 *cpl)
1018 struct cpl_t5_act_open_req6 *cpl5 = (void *)cpl;
1019 struct cpl_t6_act_open_req6 *cpl6 = (void *)cpl;
1021 /* Review changes to CPL after cpl_t6_act_open_req if this goes off. */
1022 MPASS(chip_id(sc) >= CHELSIO_T5 && chip_id(sc) <= CHELSIO_T6);
1025 if (chip_id(sc) == CHELSIO_T5) {
1026 INIT_TP_WR(cpl5, 0);
1028 INIT_TP_WR(cpl6, 0);
1033 OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
1034 V_TID_QID(sc->sge.fwq.abs_id) | V_TID_TID(atid) |
1035 V_TID_COOKIE(CPL_COOKIE_HASHFILTER)));
1036 cpl->local_port = htobe16(f->fs.val.dport);
1037 cpl->peer_port = htobe16(f->fs.val.sport);
1038 cpl->local_ip_hi = *(uint64_t *)(&f->fs.val.dip);
1039 cpl->local_ip_lo = *(((uint64_t *)&f->fs.val.dip) + 1);
1040 cpl->peer_ip_hi = *(uint64_t *)(&f->fs.val.sip);
1041 cpl->peer_ip_lo = *(((uint64_t *)&f->fs.val.sip) + 1);
1042 cpl->opt0 = htobe64(V_NAGLE(f->fs.newvlan == VLAN_REMOVE ||
1043 f->fs.newvlan == VLAN_REWRITE) | V_DELACK(f->fs.hitcnts) |
1044 V_L2T_IDX(f->l2te ? f->l2te->idx : 0) | V_TX_CHAN(f->fs.eport) |
1045 V_NO_CONG(f->fs.rpttid) |
1046 V_ULP_MODE(f->fs.nat_mode ? ULP_MODE_TCPDDP : ULP_MODE_NONE) |
1047 F_TCAM_BYPASS | F_NON_OFFLOAD);
1049 cpl6->params = htobe64(V_FILTER_TUPLE(ftuple));
1050 cpl6->opt2 = htobe32(F_RSS_QUEUE_VALID | V_RSS_QUEUE(f->fs.iq) |
1051 V_TX_QUEUE(f->fs.nat_mode) | V_WND_SCALE_EN(f->fs.nat_flag_chk) |
1052 V_RX_FC_DISABLE(f->fs.nat_seq_chk ? 1 : 0) | F_T5_OPT_2_VALID |
1053 F_RX_CHANNEL | V_SACK_EN(f->fs.swapmac) |
1054 V_CONG_CNTRL((f->fs.action == FILTER_DROP) | (f->fs.dirsteer << 1)) |
1055 V_PACE(f->fs.maskhash | (f->fs.dirsteerhash << 1)));
1059 mk_act_open_req(struct adapter *sc, struct filter_entry *f, int atid,
1060 uint64_t ftuple, struct cpl_act_open_req *cpl)
1062 struct cpl_t5_act_open_req *cpl5 = (void *)cpl;
1063 struct cpl_t6_act_open_req *cpl6 = (void *)cpl;
1065 /* Review changes to CPL after cpl_t6_act_open_req if this goes off. */
1066 MPASS(chip_id(sc) >= CHELSIO_T5 && chip_id(sc) <= CHELSIO_T6);
1069 if (chip_id(sc) == CHELSIO_T5) {
1070 INIT_TP_WR(cpl5, 0);
1072 INIT_TP_WR(cpl6, 0);
1077 OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
1078 V_TID_QID(sc->sge.fwq.abs_id) | V_TID_TID(atid) |
1079 V_TID_COOKIE(CPL_COOKIE_HASHFILTER)));
1080 cpl->local_port = htobe16(f->fs.val.dport);
1081 cpl->peer_port = htobe16(f->fs.val.sport);
1082 cpl->local_ip = f->fs.val.dip[0] | f->fs.val.dip[1] << 8 |
1083 f->fs.val.dip[2] << 16 | f->fs.val.dip[3] << 24;
1084 cpl->peer_ip = f->fs.val.sip[0] | f->fs.val.sip[1] << 8 |
1085 f->fs.val.sip[2] << 16 | f->fs.val.sip[3] << 24;
1086 cpl->opt0 = htobe64(V_NAGLE(f->fs.newvlan == VLAN_REMOVE ||
1087 f->fs.newvlan == VLAN_REWRITE) | V_DELACK(f->fs.hitcnts) |
1088 V_L2T_IDX(f->l2te ? f->l2te->idx : 0) | V_TX_CHAN(f->fs.eport) |
1089 V_NO_CONG(f->fs.rpttid) |
1090 V_ULP_MODE(f->fs.nat_mode ? ULP_MODE_TCPDDP : ULP_MODE_NONE) |
1091 F_TCAM_BYPASS | F_NON_OFFLOAD);
1093 cpl6->params = htobe64(V_FILTER_TUPLE(ftuple));
1094 cpl6->opt2 = htobe32(F_RSS_QUEUE_VALID | V_RSS_QUEUE(f->fs.iq) |
1095 V_TX_QUEUE(f->fs.nat_mode) | V_WND_SCALE_EN(f->fs.nat_flag_chk) |
1096 V_RX_FC_DISABLE(f->fs.nat_seq_chk ? 1 : 0) | F_T5_OPT_2_VALID |
1097 F_RX_CHANNEL | V_SACK_EN(f->fs.swapmac) |
1098 V_CONG_CNTRL((f->fs.action == FILTER_DROP) | (f->fs.dirsteer << 1)) |
1099 V_PACE(f->fs.maskhash | (f->fs.dirsteerhash << 1)));
1103 act_open_cpl_len16(struct adapter *sc, int isipv6)
1106 static const int sz_table[3][2] = {
1108 howmany(sizeof (struct cpl_act_open_req), 16),
1109 howmany(sizeof (struct cpl_act_open_req6), 16)
1112 howmany(sizeof (struct cpl_t5_act_open_req), 16),
1113 howmany(sizeof (struct cpl_t5_act_open_req6), 16)
1116 howmany(sizeof (struct cpl_t6_act_open_req), 16),
1117 howmany(sizeof (struct cpl_t6_act_open_req6), 16)
1121 MPASS(chip_id(sc) >= CHELSIO_T4);
1122 idx = min(chip_id(sc) - CHELSIO_T4, 2);
1124 return (sz_table[idx][!!isipv6]);
1128 set_hashfilter(struct adapter *sc, struct t4_filter *t, uint64_t ftuple,
1129 struct l2t_entry *l2te)
1132 struct wrq_cookie cookie;
1133 struct filter_entry *f;
1137 /* Already validated against fconf, iconf */
1138 MPASS((t->fs.val.pfvf_vld & t->fs.val.ovlan_vld) == 0);
1139 MPASS((t->fs.mask.pfvf_vld & t->fs.mask.ovlan_vld) == 0);
1141 mtx_lock(&sc->tids.hftid_lock);
1144 * XXX: Check for hash collisions and insert in the hash based lookup
1145 * table so that in-flight hashfilters are also considered when checking
1149 f = malloc(sizeof(*f), M_CXGBE, M_ZERO | M_NOWAIT);
1150 if (__predict_false(f == NULL)) {
1152 t4_l2t_release(l2te);
1159 atid = alloc_atid(sc, f);
1160 if (__predict_false(atid) == -1) {
1162 t4_l2t_release(l2te);
1169 wr = start_wrq_wr(&sc->sge.mgmtq, act_open_cpl_len16(sc, f->fs.type),
1172 free_atid(sc, atid);
1174 t4_l2t_release(l2te);
1180 mk_act_open_req6(sc, f, atid, ftuple, wr);
1182 mk_act_open_req(sc, f, atid, ftuple, wr);
1184 f->locked = 1; /* ithread mustn't free f if ioctl is still around. */
1187 commit_wrq_wr(&sc->sge.mgmtq, wr, &cookie);
1191 if (f->pending == 0) {
1202 if (cv_wait_sig(&sc->tids.hftid_cv, &sc->tids.hftid_lock) != 0) {
1209 mtx_unlock(&sc->tids.hftid_lock);
1213 /* SET_TCB_FIELD sent as a ULP command looks like this */
1214 #define LEN__SET_TCB_FIELD_ULP (sizeof(struct ulp_txpkt) + \
1215 sizeof(struct ulptx_idata) + sizeof(struct cpl_set_tcb_field_core))
1218 mk_set_tcb_field_ulp(struct ulp_txpkt *ulpmc, uint64_t word, uint64_t mask,
1219 uint64_t val, uint32_t tid, uint32_t qid)
1221 struct ulptx_idata *ulpsc;
1222 struct cpl_set_tcb_field_core *req;
1224 ulpmc->cmd_dest = htonl(V_ULPTX_CMD(ULP_TX_PKT) | V_ULP_TXPKT_DEST(0));
1225 ulpmc->len = htobe32(howmany(LEN__SET_TCB_FIELD_ULP, 16));
1227 ulpsc = (struct ulptx_idata *)(ulpmc + 1);
1228 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM));
1229 ulpsc->len = htobe32(sizeof(*req));
1231 req = (struct cpl_set_tcb_field_core *)(ulpsc + 1);
1232 OPCODE_TID(req) = htobe32(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
1233 req->reply_ctrl = htobe16(V_NO_REPLY(1) | V_QUEUENO(qid));
1234 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(0));
1235 req->mask = htobe64(mask);
1236 req->val = htobe64(val);
1238 ulpsc = (struct ulptx_idata *)(req + 1);
1239 if (LEN__SET_TCB_FIELD_ULP % 16) {
1240 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_NOOP));
1241 ulpsc->len = htobe32(0);
1247 /* ABORT_REQ sent as a ULP command looks like this */
1248 #define LEN__ABORT_REQ_ULP (sizeof(struct ulp_txpkt) + \
1249 sizeof(struct ulptx_idata) + sizeof(struct cpl_abort_req_core))
1252 mk_abort_req_ulp(struct ulp_txpkt *ulpmc, uint32_t tid)
1254 struct ulptx_idata *ulpsc;
1255 struct cpl_abort_req_core *req;
1257 ulpmc->cmd_dest = htonl(V_ULPTX_CMD(ULP_TX_PKT) | V_ULP_TXPKT_DEST(0));
1258 ulpmc->len = htobe32(howmany(LEN__ABORT_REQ_ULP, 16));
1260 ulpsc = (struct ulptx_idata *)(ulpmc + 1);
1261 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM));
1262 ulpsc->len = htobe32(sizeof(*req));
1264 req = (struct cpl_abort_req_core *)(ulpsc + 1);
1265 OPCODE_TID(req) = htobe32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
1266 req->rsvd0 = htonl(0);
1268 req->cmd = CPL_ABORT_NO_RST;
1270 ulpsc = (struct ulptx_idata *)(req + 1);
1271 if (LEN__ABORT_REQ_ULP % 16) {
1272 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_NOOP));
1273 ulpsc->len = htobe32(0);
1279 /* ABORT_RPL sent as a ULP command looks like this */
1280 #define LEN__ABORT_RPL_ULP (sizeof(struct ulp_txpkt) + \
1281 sizeof(struct ulptx_idata) + sizeof(struct cpl_abort_rpl_core))
1284 mk_abort_rpl_ulp(struct ulp_txpkt *ulpmc, uint32_t tid)
1286 struct ulptx_idata *ulpsc;
1287 struct cpl_abort_rpl_core *rpl;
1289 ulpmc->cmd_dest = htonl(V_ULPTX_CMD(ULP_TX_PKT) | V_ULP_TXPKT_DEST(0));
1290 ulpmc->len = htobe32(howmany(LEN__ABORT_RPL_ULP, 16));
1292 ulpsc = (struct ulptx_idata *)(ulpmc + 1);
1293 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM));
1294 ulpsc->len = htobe32(sizeof(*rpl));
1296 rpl = (struct cpl_abort_rpl_core *)(ulpsc + 1);
1297 OPCODE_TID(rpl) = htobe32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
1298 rpl->rsvd0 = htonl(0);
1300 rpl->cmd = CPL_ABORT_NO_RST;
1302 ulpsc = (struct ulptx_idata *)(rpl + 1);
1303 if (LEN__ABORT_RPL_ULP % 16) {
1304 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_NOOP));
1305 ulpsc->len = htobe32(0);
1312 del_hashfilter_wrlen(void)
1315 return (sizeof(struct work_request_hdr) +
1316 roundup2(LEN__SET_TCB_FIELD_ULP, 16) +
1317 roundup2(LEN__ABORT_REQ_ULP, 16) +
1318 roundup2(LEN__ABORT_RPL_ULP, 16));
1322 mk_del_hashfilter_wr(int tid, struct work_request_hdr *wrh, int wrlen, int qid)
1324 struct ulp_txpkt *ulpmc;
1326 INIT_ULPTX_WRH(wrh, wrlen, 0, 0);
1327 ulpmc = (struct ulp_txpkt *)(wrh + 1);
1328 ulpmc = mk_set_tcb_field_ulp(ulpmc, W_TCB_RSS_INFO,
1329 V_TCB_RSS_INFO(M_TCB_RSS_INFO), V_TCB_RSS_INFO(qid), tid, 0);
1330 ulpmc = mk_abort_req_ulp(ulpmc, tid);
1331 ulpmc = mk_abort_rpl_ulp(ulpmc, tid);
1335 del_hashfilter(struct adapter *sc, struct t4_filter *t)
1338 struct filter_entry *f;
1339 struct wrq_cookie cookie;
1341 const int wrlen = del_hashfilter_wrlen();
1343 MPASS(sc->tids.hftid_tab != NULL);
1344 MPASS(sc->tids.ntids > 0);
1346 if (t->idx >= sc->tids.ntids)
1349 mtx_lock(&sc->tids.hftid_lock);
1350 f = lookup_hftid(sc, t->idx);
1351 if (f == NULL || f->valid == 0) {
1355 MPASS(f->tid == t->idx);
1364 wr = start_wrq_wr(&sc->sge.mgmtq, howmany(wrlen, 16), &cookie);
1370 mk_del_hashfilter_wr(t->idx, wr, wrlen, sc->sge.fwq.abs_id);
1373 commit_wrq_wr(&sc->sge.mgmtq, wr, &cookie);
1374 t->fs = f->fs; /* extra info for the caller */
1378 if (f->pending == 0) {
1388 if (cv_wait_sig(&sc->tids.hftid_cv, &sc->tids.hftid_lock) != 0) {
1395 mtx_unlock(&sc->tids.hftid_lock);
1400 set_tcb_field(struct adapter *sc, u_int tid, uint16_t word, uint64_t mask,
1401 uint64_t val, int no_reply)
1403 struct wrq_cookie cookie;
1404 struct cpl_set_tcb_field *req;
1406 req = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*req), 16), &cookie);
1409 bzero(req, sizeof(*req));
1410 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, tid);
1411 if (no_reply == 0) {
1412 req->reply_ctrl = htobe16(V_QUEUENO(sc->sge.fwq.abs_id) |
1415 req->reply_ctrl = htobe16(V_NO_REPLY(1));
1416 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(CPL_COOKIE_HASHFILTER));
1417 req->mask = htobe64(mask);
1418 req->val = htobe64(val);
1419 commit_wrq_wr(&sc->sge.mgmtq, req, &cookie);
1424 /* Set one of the t_flags bits in the TCB. */
1426 set_tcb_tflag(struct adapter *sc, int tid, u_int bit_pos, u_int val,
1430 return (set_tcb_field(sc, tid, W_TCB_T_FLAGS, 1ULL << bit_pos,
1431 (uint64_t)val << bit_pos, no_reply));
1434 #define WORD_MASK 0xffffffff
1436 set_nat_params(struct adapter *sc, struct filter_entry *f, const bool dip,
1437 const bool sip, const bool dp, const bool sp)
1442 set_tcb_field(sc, f->tid, W_TCB_SND_UNA_RAW, WORD_MASK,
1443 f->fs.nat_dip[15] | f->fs.nat_dip[14] << 8 |
1444 f->fs.nat_dip[13] << 16 | f->fs.nat_dip[12] << 24, 1);
1446 set_tcb_field(sc, f->tid,
1447 W_TCB_SND_UNA_RAW + 1, WORD_MASK,
1448 f->fs.nat_dip[11] | f->fs.nat_dip[10] << 8 |
1449 f->fs.nat_dip[9] << 16 | f->fs.nat_dip[8] << 24, 1);
1451 set_tcb_field(sc, f->tid,
1452 W_TCB_SND_UNA_RAW + 2, WORD_MASK,
1453 f->fs.nat_dip[7] | f->fs.nat_dip[6] << 8 |
1454 f->fs.nat_dip[5] << 16 | f->fs.nat_dip[4] << 24, 1);
1456 set_tcb_field(sc, f->tid,
1457 W_TCB_SND_UNA_RAW + 3, WORD_MASK,
1458 f->fs.nat_dip[3] | f->fs.nat_dip[2] << 8 |
1459 f->fs.nat_dip[1] << 16 | f->fs.nat_dip[0] << 24, 1);
1461 set_tcb_field(sc, f->tid,
1462 W_TCB_RX_FRAG3_LEN_RAW, WORD_MASK,
1463 f->fs.nat_dip[3] | f->fs.nat_dip[2] << 8 |
1464 f->fs.nat_dip[1] << 16 | f->fs.nat_dip[0] << 24, 1);
1470 set_tcb_field(sc, f->tid,
1471 W_TCB_RX_FRAG2_PTR_RAW, WORD_MASK,
1472 f->fs.nat_sip[15] | f->fs.nat_sip[14] << 8 |
1473 f->fs.nat_sip[13] << 16 | f->fs.nat_sip[12] << 24, 1);
1475 set_tcb_field(sc, f->tid,
1476 W_TCB_RX_FRAG2_PTR_RAW + 1, WORD_MASK,
1477 f->fs.nat_sip[11] | f->fs.nat_sip[10] << 8 |
1478 f->fs.nat_sip[9] << 16 | f->fs.nat_sip[8] << 24, 1);
1480 set_tcb_field(sc, f->tid,
1481 W_TCB_RX_FRAG2_PTR_RAW + 2, WORD_MASK,
1482 f->fs.nat_sip[7] | f->fs.nat_sip[6] << 8 |
1483 f->fs.nat_sip[5] << 16 | f->fs.nat_sip[4] << 24, 1);
1485 set_tcb_field(sc, f->tid,
1486 W_TCB_RX_FRAG2_PTR_RAW + 3, WORD_MASK,
1487 f->fs.nat_sip[3] | f->fs.nat_sip[2] << 8 |
1488 f->fs.nat_sip[1] << 16 | f->fs.nat_sip[0] << 24, 1);
1491 set_tcb_field(sc, f->tid,
1492 W_TCB_RX_FRAG3_START_IDX_OFFSET_RAW, WORD_MASK,
1493 f->fs.nat_sip[3] | f->fs.nat_sip[2] << 8 |
1494 f->fs.nat_sip[1] << 16 | f->fs.nat_sip[0] << 24, 1);
1498 set_tcb_field(sc, f->tid, W_TCB_PDU_HDR_LEN, WORD_MASK,
1499 (dp ? f->fs.nat_dport : 0) | (sp ? f->fs.nat_sport << 16 : 0), 1);
1503 * Returns EINPROGRESS to indicate that at least one TCB update was sent and the
1504 * last of the series of updates requested a reply. The reply informs the
1505 * driver that the filter is fully setup.
1508 configure_hashfilter_tcb(struct adapter *sc, struct filter_entry *f)
1512 MPASS(f->tid < sc->tids.ntids);
1515 MPASS(f->valid == 0);
1517 if (f->fs.newdmac) {
1518 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_ECE, 1, 1);
1522 if (f->fs.newvlan == VLAN_INSERT || f->fs.newvlan == VLAN_REWRITE) {
1523 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_RFR, 1, 1);
1527 if (f->fs.newsmac) {
1528 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_CWR, 1, 1);
1529 set_tcb_field(sc, f->tid, W_TCB_SMAC_SEL,
1530 V_TCB_SMAC_SEL(M_TCB_SMAC_SEL), V_TCB_SMAC_SEL(f->smtidx),
1535 switch(f->fs.nat_mode) {
1539 set_nat_params(sc, f, true, false, false, false);
1542 case NAT_MODE_DIP_DP:
1543 set_nat_params(sc, f, true, false, true, false);
1546 case NAT_MODE_DIP_DP_SIP:
1547 set_nat_params(sc, f, true, true, true, false);
1550 case NAT_MODE_DIP_DP_SP:
1551 set_nat_params(sc, f, true, false, true, true);
1554 case NAT_MODE_SIP_SP:
1555 set_nat_params(sc, f, false, true, false, true);
1558 case NAT_MODE_DIP_SIP_SP:
1559 set_nat_params(sc, f, true, true, false, true);
1563 set_nat_params(sc, f, true, true, true, true);
1567 MPASS(0); /* should have been validated earlier */
1572 if (f->fs.nat_seq_chk) {
1573 set_tcb_field(sc, f->tid, W_TCB_RCV_NXT,
1574 V_TCB_RCV_NXT(M_TCB_RCV_NXT),
1575 V_TCB_RCV_NXT(f->fs.nat_seq_chk), 1);
1579 if (is_t5(sc) && f->fs.action == FILTER_DROP) {
1581 * Migrating = 1, Non-offload = 0 to get a T5 hashfilter to drop.
1583 set_tcb_field(sc, f->tid, W_TCB_T_FLAGS, V_TF_NON_OFFLOAD(1) |
1584 V_TF_MIGRATING(1), V_TF_MIGRATING(1), 1);
1589 * Enable switching after all secondary resources (L2T entry, SMT entry,
1590 * etc.) are setup so that any switched packet will use correct
1593 if (f->fs.action == FILTER_SWITCH) {
1594 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_ECN, 1, 1);
1598 if (f->fs.hitcnts || updated > 0) {
1599 set_tcb_field(sc, f->tid, W_TCB_TIMESTAMP,
1600 V_TCB_TIMESTAMP(M_TCB_TIMESTAMP) |
1601 V_TCB_T_RTT_TS_RECENT_AGE(M_TCB_T_RTT_TS_RECENT_AGE),
1602 V_TCB_TIMESTAMP(0ULL) | V_TCB_T_RTT_TS_RECENT_AGE(0ULL), 0);
1603 return (EINPROGRESS);