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"
56 uint32_t valid:1; /* filter allocated and valid */
57 uint32_t locked:1; /* filter is administratively locked or busy */
58 uint32_t pending:1; /* filter action is pending firmware reply */
59 int tid; /* tid of the filter TCB */
60 struct l2t_entry *l2te; /* L2 table entry for DMAC rewrite */
61 struct smt_entry *smt; /* SMT entry for SMAC rewrite */
63 struct t4_filter_specification fs;
66 static void free_filter_resources(struct filter_entry *);
67 static int get_hashfilter(struct adapter *, struct t4_filter *);
68 static int set_hashfilter(struct adapter *, struct t4_filter *, uint64_t,
69 struct l2t_entry *, struct smt_entry *);
70 static int del_hashfilter(struct adapter *, struct t4_filter *);
71 static int configure_hashfilter_tcb(struct adapter *, struct filter_entry *);
74 insert_hftid(struct adapter *sc, int tid, void *ctx, int ntids)
76 struct tid_info *t = &sc->tids;
78 t->hftid_tab[tid] = ctx;
79 atomic_add_int(&t->tids_in_use, ntids);
83 lookup_hftid(struct adapter *sc, int tid)
85 struct tid_info *t = &sc->tids;
87 return (t->hftid_tab[tid]);
91 remove_hftid(struct adapter *sc, int tid, int ntids)
93 struct tid_info *t = &sc->tids;
95 t->hftid_tab[tid] = NULL;
96 atomic_subtract_int(&t->tids_in_use, ntids);
100 mode_to_fconf(uint32_t mode)
104 if (mode & T4_FILTER_IP_FRAGMENT)
105 fconf |= F_FRAGMENTATION;
107 if (mode & T4_FILTER_MPS_HIT_TYPE)
108 fconf |= F_MPSHITTYPE;
110 if (mode & T4_FILTER_MAC_IDX)
113 if (mode & T4_FILTER_ETH_TYPE)
114 fconf |= F_ETHERTYPE;
116 if (mode & T4_FILTER_IP_PROTO)
119 if (mode & T4_FILTER_IP_TOS)
122 if (mode & T4_FILTER_VLAN)
125 if (mode & T4_FILTER_VNIC)
128 if (mode & T4_FILTER_PORT)
131 if (mode & T4_FILTER_FCoE)
138 mode_to_iconf(uint32_t mode)
141 if (mode & T4_FILTER_IC_VNIC)
147 check_fspec_against_fconf_iconf(struct adapter *sc,
148 struct t4_filter_specification *fs)
150 struct tp_params *tpp = &sc->params.tp;
153 if (fs->val.frag || fs->mask.frag)
154 fconf |= F_FRAGMENTATION;
156 if (fs->val.matchtype || fs->mask.matchtype)
157 fconf |= F_MPSHITTYPE;
159 if (fs->val.macidx || fs->mask.macidx)
162 if (fs->val.ethtype || fs->mask.ethtype)
163 fconf |= F_ETHERTYPE;
165 if (fs->val.proto || fs->mask.proto)
168 if (fs->val.tos || fs->mask.tos)
171 if (fs->val.vlan_vld || fs->mask.vlan_vld)
174 if (fs->val.ovlan_vld || fs->mask.ovlan_vld) {
176 if (tpp->ingress_config & F_VNIC)
180 if (fs->val.pfvf_vld || fs->mask.pfvf_vld) {
182 if ((tpp->ingress_config & F_VNIC) == 0)
186 if (fs->val.iport || fs->mask.iport)
189 if (fs->val.fcoe || fs->mask.fcoe)
192 if ((tpp->vlan_pri_map | fconf) != tpp->vlan_pri_map)
199 get_filter_mode(struct adapter *sc, uint32_t *mode)
201 struct tp_params *tp = &sc->params.tp;
204 /* Non-zero incoming value in mode means "hashfilter mode". */
205 mask = *mode ? tp->hash_filter_mask : UINT64_MAX;
208 *mode = T4_FILTER_IPv4 | T4_FILTER_IPv6 | T4_FILTER_IP_SADDR |
209 T4_FILTER_IP_DADDR | T4_FILTER_IP_SPORT | T4_FILTER_IP_DPORT;
211 #define CHECK_FIELD(fconf_bit, field_shift, field_mask, mode_bit) do { \
212 if (tp->vlan_pri_map & (fconf_bit)) { \
213 MPASS(tp->field_shift >= 0); \
214 if ((mask >> tp->field_shift & field_mask) == field_mask) \
215 *mode |= (mode_bit); \
219 CHECK_FIELD(F_FRAGMENTATION, frag_shift, M_FT_FRAGMENTATION, T4_FILTER_IP_FRAGMENT);
220 CHECK_FIELD(F_MPSHITTYPE, matchtype_shift, M_FT_MPSHITTYPE, T4_FILTER_MPS_HIT_TYPE);
221 CHECK_FIELD(F_MACMATCH, macmatch_shift, M_FT_MACMATCH, T4_FILTER_MAC_IDX);
222 CHECK_FIELD(F_ETHERTYPE, ethertype_shift, M_FT_ETHERTYPE, T4_FILTER_ETH_TYPE);
223 CHECK_FIELD(F_PROTOCOL, protocol_shift, M_FT_PROTOCOL, T4_FILTER_IP_PROTO);
224 CHECK_FIELD(F_TOS, tos_shift, M_FT_TOS, T4_FILTER_IP_TOS);
225 CHECK_FIELD(F_VLAN, vlan_shift, M_FT_VLAN, T4_FILTER_VLAN);
226 CHECK_FIELD(F_VNIC_ID, vnic_shift, M_FT_VNIC_ID , T4_FILTER_VNIC);
227 if (tp->ingress_config & F_VNIC)
228 *mode |= T4_FILTER_IC_VNIC;
229 CHECK_FIELD(F_PORT, port_shift, M_FT_PORT , T4_FILTER_PORT);
230 CHECK_FIELD(F_FCOE, fcoe_shift, M_FT_FCOE , T4_FILTER_FCoE);
237 set_filter_mode(struct adapter *sc, uint32_t mode)
239 struct tp_params *tpp = &sc->params.tp;
240 uint32_t fconf, iconf;
243 iconf = mode_to_iconf(mode);
244 if ((iconf ^ tpp->ingress_config) & F_VNIC) {
246 * For now we just complain if A_TP_INGRESS_CONFIG is not
247 * already set to the correct value for the requested filter
248 * mode. It's not clear if it's safe to write to this register
249 * on the fly. (And we trust the cached value of the register).
251 * check_fspec_against_fconf_iconf and other code that looks at
252 * tp->vlan_pri_map and tp->ingress_config needs to be reviewed
253 * thorougly before allowing dynamic filter mode changes.
258 fconf = mode_to_fconf(mode);
260 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK | SLEEP_OK | INTR_OK,
265 if (sc->tids.ftids_in_use > 0) {
271 if (uld_active(sc, ULD_TOM)) {
277 rc = -t4_set_filter_mode(sc, fconf, true);
279 end_synchronized_op(sc, LOCK_HELD);
283 static inline uint64_t
284 get_filter_hits(struct adapter *sc, uint32_t tid)
288 tcb_addr = t4_read_reg(sc, A_TP_CMM_TCB_BASE) + tid * TCB_SIZE;
293 read_via_memwin(sc, 0, tcb_addr + 16, (uint32_t *)&hits, 8);
294 return (be64toh(hits));
298 read_via_memwin(sc, 0, tcb_addr + 24, &hits, 4);
299 return (be32toh(hits));
304 get_filter(struct adapter *sc, struct t4_filter *t)
306 int i, nfilters = sc->tids.nftids;
307 struct filter_entry *f;
310 return (get_hashfilter(sc, t));
312 if (sc->tids.ftids_in_use == 0 || sc->tids.ftid_tab == NULL ||
313 t->idx >= nfilters) {
318 mtx_lock(&sc->tids.ftid_lock);
319 f = &sc->tids.ftid_tab[t->idx];
320 for (i = t->idx; i < nfilters; i++, f++) {
322 MPASS(f->tid == sc->tids.ftid_base + i);
324 t->l2tidx = f->l2te ? f->l2te->idx : 0;
325 t->smtidx = f->smt ? f->smt->idx : 0;
327 t->hits = get_filter_hits(sc, f->tid);
329 t->hits = UINT64_MAX;
337 mtx_unlock(&sc->tids.ftid_lock);
342 set_tcamfilter(struct adapter *sc, struct t4_filter *t, struct l2t_entry *l2te,
343 struct smt_entry *smt)
345 struct filter_entry *f;
346 struct fw_filter2_wr *fwr;
347 u_int vnic_vld, vnic_vld_mask;
348 struct wrq_cookie cookie;
349 int i, rc, busy, locked;
350 const int ntids = t->fs.type ? 4 : 1;
353 MPASS(t->idx < sc->tids.nftids);
354 /* Already validated against fconf, iconf */
355 MPASS((t->fs.val.pfvf_vld & t->fs.val.ovlan_vld) == 0);
356 MPASS((t->fs.mask.pfvf_vld & t->fs.mask.ovlan_vld) == 0);
358 f = &sc->tids.ftid_tab[t->idx];
359 rc = busy = locked = 0;
360 mtx_lock(&sc->tids.ftid_lock);
361 for (i = 0; i < ntids; i++) {
362 busy += f[i].pending + f[i].valid;
363 locked += f[i].locked;
372 if (sc->params.filter2_wr_support)
373 len16 = howmany(sizeof(struct fw_filter2_wr), 16);
375 len16 = howmany(sizeof(struct fw_filter_wr), 16);
376 fwr = start_wrq_wr(&sc->sge.mgmtq, len16, &cookie);
377 if (__predict_false(fwr == NULL))
381 sc->tids.ftids_in_use++;
384 mtx_unlock(&sc->tids.ftid_lock);
387 t4_l2t_release(l2te);
394 * Can't fail now. A set-filter WR will definitely be sent.
397 f->tid = sc->tids.ftid_base + t->idx;
402 if (t->fs.val.pfvf_vld || t->fs.val.ovlan_vld)
406 if (t->fs.mask.pfvf_vld || t->fs.mask.ovlan_vld)
411 bzero(fwr, sizeof(*fwr));
412 if (sc->params.filter2_wr_support)
413 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER2_WR));
415 fwr->op_pkd = htobe32(V_FW_WR_OP(FW_FILTER_WR));
416 fwr->len16_pkd = htobe32(FW_LEN16(*fwr));
418 htobe32(V_FW_FILTER_WR_TID(f->tid) |
419 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
420 V_FW_FILTER_WR_NOREPLY(0) |
421 V_FW_FILTER_WR_IQ(f->fs.iq));
422 fwr->del_filter_to_l2tix =
423 htobe32(V_FW_FILTER_WR_RPTTID(f->fs.rpttid) |
424 V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
425 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
426 V_FW_FILTER_WR_MASKHASH(f->fs.maskhash) |
427 V_FW_FILTER_WR_DIRSTEERHASH(f->fs.dirsteerhash) |
428 V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) |
429 V_FW_FILTER_WR_DMAC(f->fs.newdmac) |
430 V_FW_FILTER_WR_SMAC(f->fs.newsmac) |
431 V_FW_FILTER_WR_INSVLAN(f->fs.newvlan == VLAN_INSERT ||
432 f->fs.newvlan == VLAN_REWRITE) |
433 V_FW_FILTER_WR_RMVLAN(f->fs.newvlan == VLAN_REMOVE ||
434 f->fs.newvlan == VLAN_REWRITE) |
435 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
436 V_FW_FILTER_WR_TXCHAN(f->fs.eport) |
437 V_FW_FILTER_WR_PRIO(f->fs.prio) |
438 V_FW_FILTER_WR_L2TIX(f->l2te ? f->l2te->idx : 0));
439 fwr->ethtype = htobe16(f->fs.val.ethtype);
440 fwr->ethtypem = htobe16(f->fs.mask.ethtype);
441 fwr->frag_to_ovlan_vldm =
442 (V_FW_FILTER_WR_FRAG(f->fs.val.frag) |
443 V_FW_FILTER_WR_FRAGM(f->fs.mask.frag) |
444 V_FW_FILTER_WR_IVLAN_VLD(f->fs.val.vlan_vld) |
445 V_FW_FILTER_WR_OVLAN_VLD(vnic_vld) |
446 V_FW_FILTER_WR_IVLAN_VLDM(f->fs.mask.vlan_vld) |
447 V_FW_FILTER_WR_OVLAN_VLDM(vnic_vld_mask));
449 fwr->rx_chan_rx_rpl_iq = htobe16(V_FW_FILTER_WR_RX_CHAN(0) |
450 V_FW_FILTER_WR_RX_RPL_IQ(sc->sge.fwq.abs_id));
451 fwr->maci_to_matchtypem =
452 htobe32(V_FW_FILTER_WR_MACI(f->fs.val.macidx) |
453 V_FW_FILTER_WR_MACIM(f->fs.mask.macidx) |
454 V_FW_FILTER_WR_FCOE(f->fs.val.fcoe) |
455 V_FW_FILTER_WR_FCOEM(f->fs.mask.fcoe) |
456 V_FW_FILTER_WR_PORT(f->fs.val.iport) |
457 V_FW_FILTER_WR_PORTM(f->fs.mask.iport) |
458 V_FW_FILTER_WR_MATCHTYPE(f->fs.val.matchtype) |
459 V_FW_FILTER_WR_MATCHTYPEM(f->fs.mask.matchtype));
460 fwr->ptcl = f->fs.val.proto;
461 fwr->ptclm = f->fs.mask.proto;
462 fwr->ttyp = f->fs.val.tos;
463 fwr->ttypm = f->fs.mask.tos;
464 fwr->ivlan = htobe16(f->fs.val.vlan);
465 fwr->ivlanm = htobe16(f->fs.mask.vlan);
466 fwr->ovlan = htobe16(f->fs.val.vnic);
467 fwr->ovlanm = htobe16(f->fs.mask.vnic);
468 bcopy(f->fs.val.dip, fwr->lip, sizeof (fwr->lip));
469 bcopy(f->fs.mask.dip, fwr->lipm, sizeof (fwr->lipm));
470 bcopy(f->fs.val.sip, fwr->fip, sizeof (fwr->fip));
471 bcopy(f->fs.mask.sip, fwr->fipm, sizeof (fwr->fipm));
472 fwr->lp = htobe16(f->fs.val.dport);
473 fwr->lpm = htobe16(f->fs.mask.dport);
474 fwr->fp = htobe16(f->fs.val.sport);
475 fwr->fpm = htobe16(f->fs.mask.sport);
476 /* sma = 0 tells the fw to use SMAC_SEL for source MAC address */
477 bzero(fwr->sma, sizeof (fwr->sma));
478 if (sc->params.filter2_wr_support) {
479 fwr->filter_type_swapmac =
480 V_FW_FILTER2_WR_SWAPMAC(f->fs.swapmac);
481 fwr->natmode_to_ulp_type =
482 V_FW_FILTER2_WR_ULP_TYPE(f->fs.nat_mode ?
483 ULP_MODE_TCPDDP : ULP_MODE_NONE) |
484 V_FW_FILTER2_WR_NATFLAGCHECK(f->fs.nat_flag_chk) |
485 V_FW_FILTER2_WR_NATMODE(f->fs.nat_mode);
486 memcpy(fwr->newlip, f->fs.nat_dip, sizeof(fwr->newlip));
487 memcpy(fwr->newfip, f->fs.nat_sip, sizeof(fwr->newfip));
488 fwr->newlport = htobe16(f->fs.nat_dport);
489 fwr->newfport = htobe16(f->fs.nat_sport);
490 fwr->natseqcheck = htobe32(f->fs.nat_seq_chk);
492 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
494 /* Wait for response. */
495 mtx_lock(&sc->tids.ftid_lock);
497 if (f->pending == 0) {
498 rc = f->valid ? 0 : EIO;
501 if (cv_wait_sig(&sc->tids.ftid_cv, &sc->tids.ftid_lock) != 0) {
506 mtx_unlock(&sc->tids.ftid_lock);
511 hashfilter_ntuple(struct adapter *sc, const struct t4_filter_specification *fs,
514 struct tp_params *tp = &sc->params.tp;
520 * Initialize each of the fields which we care about which are present
521 * in the Compressed Filter Tuple.
523 if (tp->vlan_shift >= 0 && fs->mask.vlan) {
524 *ftuple |= (F_FT_VLAN_VLD | fs->val.vlan) << tp->vlan_shift;
525 fmask |= M_FT_VLAN << tp->vlan_shift;
528 if (tp->port_shift >= 0 && fs->mask.iport) {
529 *ftuple |= (uint64_t)fs->val.iport << tp->port_shift;
530 fmask |= M_FT_PORT << tp->port_shift;
533 if (tp->protocol_shift >= 0 && fs->mask.proto) {
534 *ftuple |= (uint64_t)fs->val.proto << tp->protocol_shift;
535 fmask |= M_FT_PROTOCOL << tp->protocol_shift;
538 if (tp->tos_shift >= 0 && fs->mask.tos) {
539 *ftuple |= (uint64_t)(fs->val.tos) << tp->tos_shift;
540 fmask |= M_FT_TOS << tp->tos_shift;
543 if (tp->vnic_shift >= 0 && fs->mask.vnic) {
544 /* F_VNIC in ingress config was already validated. */
545 if (tp->ingress_config & F_VNIC)
546 MPASS(fs->mask.pfvf_vld);
548 MPASS(fs->mask.ovlan_vld);
550 *ftuple |= ((1ULL << 16) | fs->val.vnic) << tp->vnic_shift;
551 fmask |= M_FT_VNIC_ID << tp->vnic_shift;
554 if (tp->macmatch_shift >= 0 && fs->mask.macidx) {
555 *ftuple |= (uint64_t)(fs->val.macidx) << tp->macmatch_shift;
556 fmask |= M_FT_MACMATCH << tp->macmatch_shift;
559 if (tp->ethertype_shift >= 0 && fs->mask.ethtype) {
560 *ftuple |= (uint64_t)(fs->val.ethtype) << tp->ethertype_shift;
561 fmask |= M_FT_ETHERTYPE << tp->ethertype_shift;
564 if (tp->matchtype_shift >= 0 && fs->mask.matchtype) {
565 *ftuple |= (uint64_t)(fs->val.matchtype) << tp->matchtype_shift;
566 fmask |= M_FT_MPSHITTYPE << tp->matchtype_shift;
569 if (tp->frag_shift >= 0 && fs->mask.frag) {
570 *ftuple |= (uint64_t)(fs->val.frag) << tp->frag_shift;
571 fmask |= M_FT_FRAGMENTATION << tp->frag_shift;
574 if (tp->fcoe_shift >= 0 && fs->mask.fcoe) {
575 *ftuple |= (uint64_t)(fs->val.fcoe) << tp->fcoe_shift;
576 fmask |= M_FT_FCOE << tp->fcoe_shift;
579 /* A hashfilter must conform to the filterMask. */
580 if (fmask != tp->hash_filter_mask)
587 set_filter(struct adapter *sc, struct t4_filter *t)
589 struct tid_info *ti = &sc->tids;
590 struct l2t_entry *l2te;
591 struct smt_entry *smt;
596 * Basic filter checks first.
600 if (!is_hashfilter(sc) || ti->ntids == 0)
602 /* Hardware, not user, selects a tid for hashfilters. */
603 if (t->idx != (uint32_t)-1)
605 /* T5 can't count hashfilter hits. */
606 if (is_t5(sc) && t->fs.hitcnts)
608 rc = hashfilter_ntuple(sc, &t->fs, &ftuple);
614 if (t->idx >= ti->nftids)
616 /* IPv6 filter idx must be 4 aligned */
617 if (t->fs.type == 1 &&
618 ((t->idx & 0x3) || t->idx + 4 >= ti->nftids))
622 /* T4 doesn't support VLAN tag removal or rewrite, swapmac, and NAT. */
623 if (is_t4(sc) && t->fs.action == FILTER_SWITCH &&
624 (t->fs.newvlan == VLAN_REMOVE || t->fs.newvlan == VLAN_REWRITE ||
625 t->fs.swapmac || t->fs.nat_mode))
628 if (t->fs.action == FILTER_SWITCH && t->fs.eport >= sc->params.nports)
630 if (t->fs.val.iport >= sc->params.nports)
633 /* Can't specify an iq if not steering to it */
634 if (!t->fs.dirsteer && t->fs.iq)
637 /* Validate against the global filter mode and ingress config */
638 rc = check_fspec_against_fconf_iconf(sc, &t->fs);
643 * Basic checks passed. Make sure the queues and tid tables are setup.
646 rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4setf");
649 if (!(sc->flags & FULL_INIT_DONE) &&
650 ((rc = adapter_full_init(sc)) != 0)) {
651 end_synchronized_op(sc, 0);
655 if (__predict_false(ti->hftid_tab == NULL)) {
656 ti->hftid_tab = malloc(sizeof(*ti->hftid_tab) * ti->ntids,
657 M_CXGBE, M_NOWAIT | M_ZERO);
658 if (ti->hftid_tab == NULL) {
662 mtx_init(&ti->hftid_lock, "T4 hashfilters", 0, MTX_DEF);
663 cv_init(&ti->hftid_cv, "t4hfcv");
665 if (__predict_false(sc->tids.atid_tab == NULL)) {
666 rc = alloc_atid_tab(&sc->tids, M_NOWAIT);
670 } else if (__predict_false(ti->ftid_tab == NULL)) {
671 KASSERT(ti->ftids_in_use == 0,
672 ("%s: no memory allocated but ftids_in_use > 0", __func__));
673 ti->ftid_tab = malloc(sizeof(struct filter_entry) * ti->nftids,
674 M_CXGBE, M_NOWAIT | M_ZERO);
675 if (ti->ftid_tab == NULL) {
679 mtx_init(&ti->ftid_lock, "T4 filters", 0, MTX_DEF);
680 cv_init(&ti->ftid_cv, "t4fcv");
683 end_synchronized_op(sc, 0);
688 * Allocate L2T entry, SMT entry, etc.
692 if (t->fs.newdmac || t->fs.newvlan) {
693 /* This filter needs an L2T entry; allocate one. */
694 l2te = t4_l2t_alloc_switching(sc->l2t);
695 if (__predict_false(l2te == NULL))
697 rc = t4_l2t_set_switching(sc, l2te, t->fs.vlan, t->fs.eport,
700 t4_l2t_release(l2te);
707 /* This filter needs an SMT entry; allocate one. */
708 smt = t4_smt_alloc_switching(sc->smt, t->fs.smac);
709 if (__predict_false(smt == NULL)) {
711 t4_l2t_release(l2te);
714 rc = t4_smt_set_switching(sc, smt, 0x0, t->fs.smac);
718 t4_l2t_release(l2te);
724 return (set_hashfilter(sc, t, ftuple, l2te, smt));
726 return (set_tcamfilter(sc, t, l2te, smt));
731 del_tcamfilter(struct adapter *sc, struct t4_filter *t)
733 struct filter_entry *f;
734 struct fw_filter_wr *fwr;
735 struct wrq_cookie cookie;
738 MPASS(sc->tids.ftid_tab != NULL);
739 MPASS(sc->tids.nftids > 0);
741 if (t->idx >= sc->tids.nftids)
744 mtx_lock(&sc->tids.ftid_lock);
745 f = &sc->tids.ftid_tab[t->idx];
758 MPASS(f->tid == sc->tids.ftid_base + t->idx);
759 fwr = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*fwr), 16), &cookie);
765 bzero(fwr, sizeof (*fwr));
766 t4_mk_filtdelwr(f->tid, fwr, sc->sge.fwq.abs_id);
768 commit_wrq_wr(&sc->sge.mgmtq, fwr, &cookie);
769 t->fs = f->fs; /* extra info for the caller */
772 if (f->pending == 0) {
773 rc = f->valid ? EIO : 0;
776 if (cv_wait_sig(&sc->tids.ftid_cv, &sc->tids.ftid_lock) != 0) {
782 mtx_unlock(&sc->tids.ftid_lock);
787 del_filter(struct adapter *sc, struct t4_filter *t)
790 /* No filters possible if not initialized yet. */
791 if (!(sc->flags & FULL_INIT_DONE))
795 * The checks for tid tables ensure that the locks that del_* will reach
796 * for are initialized.
799 if (sc->tids.hftid_tab != NULL)
800 return (del_hashfilter(sc, t));
802 if (sc->tids.ftid_tab != NULL)
803 return (del_tcamfilter(sc, t));
810 * Release secondary resources associated with the filter.
813 free_filter_resources(struct filter_entry *f)
817 t4_l2t_release(f->l2te);
821 t4_smt_release(f->smt);
827 set_tcb_field(struct adapter *sc, u_int tid, uint16_t word, uint64_t mask,
828 uint64_t val, int no_reply)
830 struct wrq_cookie cookie;
831 struct cpl_set_tcb_field *req;
833 req = start_wrq_wr(&sc->sge.mgmtq, howmany(sizeof(*req), 16), &cookie);
836 bzero(req, sizeof(*req));
837 INIT_TP_WR_MIT_CPL(req, CPL_SET_TCB_FIELD, tid);
839 req->reply_ctrl = htobe16(V_QUEUENO(sc->sge.fwq.abs_id) |
842 req->reply_ctrl = htobe16(V_NO_REPLY(1));
843 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(CPL_COOKIE_HASHFILTER));
844 req->mask = htobe64(mask);
845 req->val = htobe64(val);
846 commit_wrq_wr(&sc->sge.mgmtq, req, &cookie);
851 /* Set one of the t_flags bits in the TCB. */
853 set_tcb_tflag(struct adapter *sc, int tid, u_int bit_pos, u_int val,
857 return (set_tcb_field(sc, tid, W_TCB_T_FLAGS, 1ULL << bit_pos,
858 (uint64_t)val << bit_pos, no_reply));
862 t4_filter_rpl(struct sge_iq *iq, const struct rss_header *rss, struct mbuf *m)
864 struct adapter *sc = iq->adapter;
865 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
866 u_int tid = GET_TID(rpl);
867 u_int rc, cleanup, idx;
868 struct filter_entry *f;
870 KASSERT(m == NULL, ("%s: payload with opcode %02x", __func__,
872 MPASS(is_ftid(sc, tid));
875 idx = tid - sc->tids.ftid_base;
876 f = &sc->tids.ftid_tab[idx];
877 rc = G_COOKIE(rpl->cookie);
879 mtx_lock(&sc->tids.ftid_lock);
880 KASSERT(f->pending, ("%s: reply %d for filter[%u] that isn't pending.",
883 case FW_FILTER_WR_FLT_ADDED:
884 /* set-filter succeeded */
887 MPASS(f->smt != NULL);
888 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_CWR, 1, 1);
889 set_tcb_field(sc, f->tid, W_TCB_SMAC_SEL,
890 V_TCB_SMAC_SEL(M_TCB_SMAC_SEL),
891 V_TCB_SMAC_SEL(f->smt->idx), 1);
892 /* XXX: wait for reply to TCB update before !pending */
895 case FW_FILTER_WR_FLT_DELETED:
896 /* del-filter succeeded */
897 MPASS(f->valid == 1);
900 case FW_FILTER_WR_SMT_TBL_FULL:
901 /* set-filter failed due to lack of SMT space. */
902 MPASS(f->valid == 0);
903 free_filter_resources(f);
904 sc->tids.ftids_in_use--;
906 case FW_FILTER_WR_SUCCESS:
907 case FW_FILTER_WR_EINVAL:
909 panic("%s: unexpected reply %d for filter[%d].", __func__, rc,
913 cv_broadcast(&sc->tids.ftid_cv);
914 mtx_unlock(&sc->tids.ftid_lock);
920 * This is the reply to the Active Open that created the filter. Additional TCB
921 * updates may be required to complete the filter configuration.
924 t4_hashfilter_ao_rpl(struct sge_iq *iq, const struct rss_header *rss,
927 struct adapter *sc = iq->adapter;
928 const struct cpl_act_open_rpl *cpl = (const void *)(rss + 1);
929 u_int atid = G_TID_TID(G_AOPEN_ATID(be32toh(cpl->atid_status)));
930 u_int status = G_AOPEN_STATUS(be32toh(cpl->atid_status));
931 struct filter_entry *f = lookup_atid(sc, atid);
933 KASSERT(m == NULL, ("%s: wasn't expecting payload", __func__));
935 mtx_lock(&sc->tids.hftid_lock);
936 KASSERT(f->pending, ("%s: hashfilter[%p] isn't pending.", __func__, f));
937 KASSERT(f->tid == -1, ("%s: hashfilter[%p] has tid %d already.",
938 __func__, f, f->tid));
939 if (status == CPL_ERR_NONE) {
940 struct filter_entry *f2;
942 f->tid = GET_TID(cpl);
943 MPASS(f->tid < sc->tids.ntids);
944 if (__predict_false((f2 = lookup_hftid(sc, f->tid)) != NULL)) {
945 /* XXX: avoid hash collisions in the first place. */
946 MPASS(f2->tid == f->tid);
947 remove_hftid(sc, f2->tid, f2->fs.type ? 2 : 1);
948 free_filter_resources(f2);
951 insert_hftid(sc, f->tid, f, f->fs.type ? 2 : 1);
953 * Leave the filter pending until it is fully set up, which will
954 * be indicated by the reply to the last TCB update. No need to
955 * unblock the ioctl thread either.
957 if (configure_hashfilter_tcb(sc, f) == EINPROGRESS)
962 /* provide errno instead of tid to ioctl */
963 f->tid = act_open_rpl_status_to_errno(status);
965 if (act_open_has_tid(status))
966 release_tid(sc, GET_TID(cpl), &sc->sge.mgmtq);
967 free_filter_resources(f);
971 cv_broadcast(&sc->tids.hftid_cv);
973 mtx_unlock(&sc->tids.hftid_lock);
980 t4_hashfilter_tcb_rpl(struct sge_iq *iq, const struct rss_header *rss,
983 struct adapter *sc = iq->adapter;
984 const struct cpl_set_tcb_rpl *rpl = (const void *)(rss + 1);
985 u_int tid = GET_TID(rpl);
986 struct filter_entry *f;
988 mtx_lock(&sc->tids.hftid_lock);
989 f = lookup_hftid(sc, tid);
990 KASSERT(f->tid == tid, ("%s: filter tid mismatch", __func__));
991 KASSERT(f->pending, ("%s: hashfilter %p [%u] isn't pending.", __func__,
993 KASSERT(f->valid == 0, ("%s: hashfilter %p [%u] is valid already.",
996 if (rpl->status == 0) {
1001 free_filter_resources(f);
1002 remove_hftid(sc, tid, f->fs.type ? 2 : 1);
1003 release_tid(sc, tid, &sc->sge.mgmtq);
1007 cv_broadcast(&sc->tids.hftid_cv);
1008 mtx_unlock(&sc->tids.hftid_lock);
1014 t4_del_hashfilter_rpl(struct sge_iq *iq, const struct rss_header *rss,
1017 struct adapter *sc = iq->adapter;
1018 const struct cpl_abort_rpl_rss *cpl = (const void *)(rss + 1);
1019 unsigned int tid = GET_TID(cpl);
1020 struct filter_entry *f;
1022 mtx_lock(&sc->tids.hftid_lock);
1023 f = lookup_hftid(sc, tid);
1024 KASSERT(f->tid == tid, ("%s: filter tid mismatch", __func__));
1025 KASSERT(f->pending, ("%s: hashfilter %p [%u] isn't pending.", __func__,
1027 KASSERT(f->valid, ("%s: hashfilter %p [%u] isn't valid.", __func__, f,
1030 if (cpl->status == 0) {
1032 free_filter_resources(f);
1033 remove_hftid(sc, tid, f->fs.type ? 2 : 1);
1034 release_tid(sc, tid, &sc->sge.mgmtq);
1038 cv_broadcast(&sc->tids.hftid_cv);
1039 mtx_unlock(&sc->tids.hftid_lock);
1045 get_hashfilter(struct adapter *sc, struct t4_filter *t)
1047 int i, nfilters = sc->tids.ntids;
1048 struct filter_entry *f;
1050 if (sc->tids.tids_in_use == 0 || sc->tids.hftid_tab == NULL ||
1051 t->idx >= nfilters) {
1052 t->idx = 0xffffffff;
1056 mtx_lock(&sc->tids.hftid_lock);
1057 for (i = t->idx; i < nfilters; i++) {
1058 f = lookup_hftid(sc, i);
1059 if (f != NULL && f->valid) {
1061 t->l2tidx = f->l2te ? f->l2te->idx : 0;
1062 t->smtidx = f->smt ? f->smt->idx : 0;
1064 t->hits = get_filter_hits(sc, t->idx);
1066 t->hits = UINT64_MAX;
1072 t->idx = 0xffffffff;
1074 mtx_unlock(&sc->tids.hftid_lock);
1079 mk_act_open_req6(struct adapter *sc, struct filter_entry *f, int atid,
1080 uint64_t ftuple, struct cpl_act_open_req6 *cpl)
1082 struct cpl_t5_act_open_req6 *cpl5 = (void *)cpl;
1083 struct cpl_t6_act_open_req6 *cpl6 = (void *)cpl;
1085 /* Review changes to CPL after cpl_t6_act_open_req if this goes off. */
1086 MPASS(chip_id(sc) >= CHELSIO_T5 && chip_id(sc) <= CHELSIO_T6);
1089 if (chip_id(sc) == CHELSIO_T5) {
1090 INIT_TP_WR(cpl5, 0);
1092 INIT_TP_WR(cpl6, 0);
1097 OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
1098 V_TID_QID(sc->sge.fwq.abs_id) | V_TID_TID(atid) |
1099 V_TID_COOKIE(CPL_COOKIE_HASHFILTER)));
1100 cpl->local_port = htobe16(f->fs.val.dport);
1101 cpl->peer_port = htobe16(f->fs.val.sport);
1102 cpl->local_ip_hi = *(uint64_t *)(&f->fs.val.dip);
1103 cpl->local_ip_lo = *(((uint64_t *)&f->fs.val.dip) + 1);
1104 cpl->peer_ip_hi = *(uint64_t *)(&f->fs.val.sip);
1105 cpl->peer_ip_lo = *(((uint64_t *)&f->fs.val.sip) + 1);
1106 cpl->opt0 = htobe64(V_NAGLE(f->fs.newvlan == VLAN_REMOVE ||
1107 f->fs.newvlan == VLAN_REWRITE) | V_DELACK(f->fs.hitcnts) |
1108 V_L2T_IDX(f->l2te ? f->l2te->idx : 0) | V_TX_CHAN(f->fs.eport) |
1109 V_NO_CONG(f->fs.rpttid) |
1110 V_ULP_MODE(f->fs.nat_mode ? ULP_MODE_TCPDDP : ULP_MODE_NONE) |
1111 F_TCAM_BYPASS | F_NON_OFFLOAD);
1113 cpl6->params = htobe64(V_FILTER_TUPLE(ftuple));
1114 cpl6->opt2 = htobe32(F_RSS_QUEUE_VALID | V_RSS_QUEUE(f->fs.iq) |
1115 V_TX_QUEUE(f->fs.nat_mode) | V_WND_SCALE_EN(f->fs.nat_flag_chk) |
1116 V_RX_FC_DISABLE(f->fs.nat_seq_chk ? 1 : 0) | F_T5_OPT_2_VALID |
1117 F_RX_CHANNEL | V_SACK_EN(f->fs.swapmac) |
1118 V_CONG_CNTRL((f->fs.action == FILTER_DROP) | (f->fs.dirsteer << 1)) |
1119 V_PACE(f->fs.maskhash | (f->fs.dirsteerhash << 1)));
1123 mk_act_open_req(struct adapter *sc, struct filter_entry *f, int atid,
1124 uint64_t ftuple, struct cpl_act_open_req *cpl)
1126 struct cpl_t5_act_open_req *cpl5 = (void *)cpl;
1127 struct cpl_t6_act_open_req *cpl6 = (void *)cpl;
1129 /* Review changes to CPL after cpl_t6_act_open_req if this goes off. */
1130 MPASS(chip_id(sc) >= CHELSIO_T5 && chip_id(sc) <= CHELSIO_T6);
1133 if (chip_id(sc) == CHELSIO_T5) {
1134 INIT_TP_WR(cpl5, 0);
1136 INIT_TP_WR(cpl6, 0);
1141 OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
1142 V_TID_QID(sc->sge.fwq.abs_id) | V_TID_TID(atid) |
1143 V_TID_COOKIE(CPL_COOKIE_HASHFILTER)));
1144 cpl->local_port = htobe16(f->fs.val.dport);
1145 cpl->peer_port = htobe16(f->fs.val.sport);
1146 cpl->local_ip = f->fs.val.dip[0] | f->fs.val.dip[1] << 8 |
1147 f->fs.val.dip[2] << 16 | f->fs.val.dip[3] << 24;
1148 cpl->peer_ip = f->fs.val.sip[0] | f->fs.val.sip[1] << 8 |
1149 f->fs.val.sip[2] << 16 | f->fs.val.sip[3] << 24;
1150 cpl->opt0 = htobe64(V_NAGLE(f->fs.newvlan == VLAN_REMOVE ||
1151 f->fs.newvlan == VLAN_REWRITE) | V_DELACK(f->fs.hitcnts) |
1152 V_L2T_IDX(f->l2te ? f->l2te->idx : 0) | V_TX_CHAN(f->fs.eport) |
1153 V_NO_CONG(f->fs.rpttid) |
1154 V_ULP_MODE(f->fs.nat_mode ? ULP_MODE_TCPDDP : ULP_MODE_NONE) |
1155 F_TCAM_BYPASS | F_NON_OFFLOAD);
1157 cpl6->params = htobe64(V_FILTER_TUPLE(ftuple));
1158 cpl6->opt2 = htobe32(F_RSS_QUEUE_VALID | V_RSS_QUEUE(f->fs.iq) |
1159 V_TX_QUEUE(f->fs.nat_mode) | V_WND_SCALE_EN(f->fs.nat_flag_chk) |
1160 V_RX_FC_DISABLE(f->fs.nat_seq_chk ? 1 : 0) | F_T5_OPT_2_VALID |
1161 F_RX_CHANNEL | V_SACK_EN(f->fs.swapmac) |
1162 V_CONG_CNTRL((f->fs.action == FILTER_DROP) | (f->fs.dirsteer << 1)) |
1163 V_PACE(f->fs.maskhash | (f->fs.dirsteerhash << 1)));
1167 act_open_cpl_len16(struct adapter *sc, int isipv6)
1170 static const int sz_table[3][2] = {
1172 howmany(sizeof (struct cpl_act_open_req), 16),
1173 howmany(sizeof (struct cpl_act_open_req6), 16)
1176 howmany(sizeof (struct cpl_t5_act_open_req), 16),
1177 howmany(sizeof (struct cpl_t5_act_open_req6), 16)
1180 howmany(sizeof (struct cpl_t6_act_open_req), 16),
1181 howmany(sizeof (struct cpl_t6_act_open_req6), 16)
1185 MPASS(chip_id(sc) >= CHELSIO_T4);
1186 idx = min(chip_id(sc) - CHELSIO_T4, 2);
1188 return (sz_table[idx][!!isipv6]);
1192 set_hashfilter(struct adapter *sc, struct t4_filter *t, uint64_t ftuple,
1193 struct l2t_entry *l2te, struct smt_entry *smt)
1196 struct wrq_cookie cookie;
1197 struct filter_entry *f;
1201 /* Already validated against fconf, iconf */
1202 MPASS((t->fs.val.pfvf_vld & t->fs.val.ovlan_vld) == 0);
1203 MPASS((t->fs.mask.pfvf_vld & t->fs.mask.ovlan_vld) == 0);
1205 mtx_lock(&sc->tids.hftid_lock);
1208 * XXX: Check for hash collisions and insert in the hash based lookup
1209 * table so that in-flight hashfilters are also considered when checking
1213 f = malloc(sizeof(*f), M_CXGBE, M_ZERO | M_NOWAIT);
1214 if (__predict_false(f == NULL)) {
1216 t4_l2t_release(l2te);
1218 t4_smt_release(smt);
1226 atid = alloc_atid(sc, f);
1227 if (__predict_false(atid) == -1) {
1229 t4_l2t_release(l2te);
1231 t4_smt_release(smt);
1238 wr = start_wrq_wr(&sc->sge.mgmtq, act_open_cpl_len16(sc, f->fs.type),
1241 free_atid(sc, atid);
1243 t4_l2t_release(l2te);
1245 t4_smt_release(smt);
1251 mk_act_open_req6(sc, f, atid, ftuple, wr);
1253 mk_act_open_req(sc, f, atid, ftuple, wr);
1255 f->locked = 1; /* ithread mustn't free f if ioctl is still around. */
1258 commit_wrq_wr(&sc->sge.mgmtq, wr, &cookie);
1262 if (f->pending == 0) {
1273 if (cv_wait_sig(&sc->tids.hftid_cv, &sc->tids.hftid_lock) != 0) {
1280 mtx_unlock(&sc->tids.hftid_lock);
1284 /* SET_TCB_FIELD sent as a ULP command looks like this */
1285 #define LEN__SET_TCB_FIELD_ULP (sizeof(struct ulp_txpkt) + \
1286 sizeof(struct ulptx_idata) + sizeof(struct cpl_set_tcb_field_core))
1289 mk_set_tcb_field_ulp(struct ulp_txpkt *ulpmc, uint64_t word, uint64_t mask,
1290 uint64_t val, uint32_t tid, uint32_t qid)
1292 struct ulptx_idata *ulpsc;
1293 struct cpl_set_tcb_field_core *req;
1295 ulpmc->cmd_dest = htonl(V_ULPTX_CMD(ULP_TX_PKT) | V_ULP_TXPKT_DEST(0));
1296 ulpmc->len = htobe32(howmany(LEN__SET_TCB_FIELD_ULP, 16));
1298 ulpsc = (struct ulptx_idata *)(ulpmc + 1);
1299 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM));
1300 ulpsc->len = htobe32(sizeof(*req));
1302 req = (struct cpl_set_tcb_field_core *)(ulpsc + 1);
1303 OPCODE_TID(req) = htobe32(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
1304 req->reply_ctrl = htobe16(V_NO_REPLY(1) | V_QUEUENO(qid));
1305 req->word_cookie = htobe16(V_WORD(word) | V_COOKIE(0));
1306 req->mask = htobe64(mask);
1307 req->val = htobe64(val);
1309 ulpsc = (struct ulptx_idata *)(req + 1);
1310 if (LEN__SET_TCB_FIELD_ULP % 16) {
1311 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_NOOP));
1312 ulpsc->len = htobe32(0);
1318 /* ABORT_REQ sent as a ULP command looks like this */
1319 #define LEN__ABORT_REQ_ULP (sizeof(struct ulp_txpkt) + \
1320 sizeof(struct ulptx_idata) + sizeof(struct cpl_abort_req_core))
1323 mk_abort_req_ulp(struct ulp_txpkt *ulpmc, uint32_t tid)
1325 struct ulptx_idata *ulpsc;
1326 struct cpl_abort_req_core *req;
1328 ulpmc->cmd_dest = htonl(V_ULPTX_CMD(ULP_TX_PKT) | V_ULP_TXPKT_DEST(0));
1329 ulpmc->len = htobe32(howmany(LEN__ABORT_REQ_ULP, 16));
1331 ulpsc = (struct ulptx_idata *)(ulpmc + 1);
1332 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM));
1333 ulpsc->len = htobe32(sizeof(*req));
1335 req = (struct cpl_abort_req_core *)(ulpsc + 1);
1336 OPCODE_TID(req) = htobe32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
1337 req->rsvd0 = htonl(0);
1339 req->cmd = CPL_ABORT_NO_RST;
1341 ulpsc = (struct ulptx_idata *)(req + 1);
1342 if (LEN__ABORT_REQ_ULP % 16) {
1343 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_NOOP));
1344 ulpsc->len = htobe32(0);
1350 /* ABORT_RPL sent as a ULP command looks like this */
1351 #define LEN__ABORT_RPL_ULP (sizeof(struct ulp_txpkt) + \
1352 sizeof(struct ulptx_idata) + sizeof(struct cpl_abort_rpl_core))
1355 mk_abort_rpl_ulp(struct ulp_txpkt *ulpmc, uint32_t tid)
1357 struct ulptx_idata *ulpsc;
1358 struct cpl_abort_rpl_core *rpl;
1360 ulpmc->cmd_dest = htonl(V_ULPTX_CMD(ULP_TX_PKT) | V_ULP_TXPKT_DEST(0));
1361 ulpmc->len = htobe32(howmany(LEN__ABORT_RPL_ULP, 16));
1363 ulpsc = (struct ulptx_idata *)(ulpmc + 1);
1364 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_IMM));
1365 ulpsc->len = htobe32(sizeof(*rpl));
1367 rpl = (struct cpl_abort_rpl_core *)(ulpsc + 1);
1368 OPCODE_TID(rpl) = htobe32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
1369 rpl->rsvd0 = htonl(0);
1371 rpl->cmd = CPL_ABORT_NO_RST;
1373 ulpsc = (struct ulptx_idata *)(rpl + 1);
1374 if (LEN__ABORT_RPL_ULP % 16) {
1375 ulpsc->cmd_more = htobe32(V_ULPTX_CMD(ULP_TX_SC_NOOP));
1376 ulpsc->len = htobe32(0);
1383 del_hashfilter_wrlen(void)
1386 return (sizeof(struct work_request_hdr) +
1387 roundup2(LEN__SET_TCB_FIELD_ULP, 16) +
1388 roundup2(LEN__ABORT_REQ_ULP, 16) +
1389 roundup2(LEN__ABORT_RPL_ULP, 16));
1393 mk_del_hashfilter_wr(int tid, struct work_request_hdr *wrh, int wrlen, int qid)
1395 struct ulp_txpkt *ulpmc;
1397 INIT_ULPTX_WRH(wrh, wrlen, 0, 0);
1398 ulpmc = (struct ulp_txpkt *)(wrh + 1);
1399 ulpmc = mk_set_tcb_field_ulp(ulpmc, W_TCB_RSS_INFO,
1400 V_TCB_RSS_INFO(M_TCB_RSS_INFO), V_TCB_RSS_INFO(qid), tid, 0);
1401 ulpmc = mk_abort_req_ulp(ulpmc, tid);
1402 ulpmc = mk_abort_rpl_ulp(ulpmc, tid);
1406 del_hashfilter(struct adapter *sc, struct t4_filter *t)
1409 struct filter_entry *f;
1410 struct wrq_cookie cookie;
1412 const int wrlen = del_hashfilter_wrlen();
1414 MPASS(sc->tids.hftid_tab != NULL);
1415 MPASS(sc->tids.ntids > 0);
1417 if (t->idx >= sc->tids.ntids)
1420 mtx_lock(&sc->tids.hftid_lock);
1421 f = lookup_hftid(sc, t->idx);
1422 if (f == NULL || f->valid == 0) {
1426 MPASS(f->tid == t->idx);
1435 wr = start_wrq_wr(&sc->sge.mgmtq, howmany(wrlen, 16), &cookie);
1441 mk_del_hashfilter_wr(t->idx, wr, wrlen, sc->sge.fwq.abs_id);
1444 commit_wrq_wr(&sc->sge.mgmtq, wr, &cookie);
1445 t->fs = f->fs; /* extra info for the caller */
1449 if (f->pending == 0) {
1459 if (cv_wait_sig(&sc->tids.hftid_cv, &sc->tids.hftid_lock) != 0) {
1466 mtx_unlock(&sc->tids.hftid_lock);
1470 #define WORD_MASK 0xffffffff
1472 set_nat_params(struct adapter *sc, struct filter_entry *f, const bool dip,
1473 const bool sip, const bool dp, const bool sp)
1478 set_tcb_field(sc, f->tid, W_TCB_SND_UNA_RAW, WORD_MASK,
1479 f->fs.nat_dip[15] | f->fs.nat_dip[14] << 8 |
1480 f->fs.nat_dip[13] << 16 | f->fs.nat_dip[12] << 24, 1);
1482 set_tcb_field(sc, f->tid,
1483 W_TCB_SND_UNA_RAW + 1, WORD_MASK,
1484 f->fs.nat_dip[11] | f->fs.nat_dip[10] << 8 |
1485 f->fs.nat_dip[9] << 16 | f->fs.nat_dip[8] << 24, 1);
1487 set_tcb_field(sc, f->tid,
1488 W_TCB_SND_UNA_RAW + 2, WORD_MASK,
1489 f->fs.nat_dip[7] | f->fs.nat_dip[6] << 8 |
1490 f->fs.nat_dip[5] << 16 | f->fs.nat_dip[4] << 24, 1);
1492 set_tcb_field(sc, f->tid,
1493 W_TCB_SND_UNA_RAW + 3, WORD_MASK,
1494 f->fs.nat_dip[3] | f->fs.nat_dip[2] << 8 |
1495 f->fs.nat_dip[1] << 16 | f->fs.nat_dip[0] << 24, 1);
1497 set_tcb_field(sc, f->tid,
1498 W_TCB_RX_FRAG3_LEN_RAW, WORD_MASK,
1499 f->fs.nat_dip[3] | f->fs.nat_dip[2] << 8 |
1500 f->fs.nat_dip[1] << 16 | f->fs.nat_dip[0] << 24, 1);
1506 set_tcb_field(sc, f->tid,
1507 W_TCB_RX_FRAG2_PTR_RAW, WORD_MASK,
1508 f->fs.nat_sip[15] | f->fs.nat_sip[14] << 8 |
1509 f->fs.nat_sip[13] << 16 | f->fs.nat_sip[12] << 24, 1);
1511 set_tcb_field(sc, f->tid,
1512 W_TCB_RX_FRAG2_PTR_RAW + 1, WORD_MASK,
1513 f->fs.nat_sip[11] | f->fs.nat_sip[10] << 8 |
1514 f->fs.nat_sip[9] << 16 | f->fs.nat_sip[8] << 24, 1);
1516 set_tcb_field(sc, f->tid,
1517 W_TCB_RX_FRAG2_PTR_RAW + 2, WORD_MASK,
1518 f->fs.nat_sip[7] | f->fs.nat_sip[6] << 8 |
1519 f->fs.nat_sip[5] << 16 | f->fs.nat_sip[4] << 24, 1);
1521 set_tcb_field(sc, f->tid,
1522 W_TCB_RX_FRAG2_PTR_RAW + 3, WORD_MASK,
1523 f->fs.nat_sip[3] | f->fs.nat_sip[2] << 8 |
1524 f->fs.nat_sip[1] << 16 | f->fs.nat_sip[0] << 24, 1);
1527 set_tcb_field(sc, f->tid,
1528 W_TCB_RX_FRAG3_START_IDX_OFFSET_RAW, WORD_MASK,
1529 f->fs.nat_sip[3] | f->fs.nat_sip[2] << 8 |
1530 f->fs.nat_sip[1] << 16 | f->fs.nat_sip[0] << 24, 1);
1534 set_tcb_field(sc, f->tid, W_TCB_PDU_HDR_LEN, WORD_MASK,
1535 (dp ? f->fs.nat_dport : 0) | (sp ? f->fs.nat_sport << 16 : 0), 1);
1539 * Returns EINPROGRESS to indicate that at least one TCB update was sent and the
1540 * last of the series of updates requested a reply. The reply informs the
1541 * driver that the filter is fully setup.
1544 configure_hashfilter_tcb(struct adapter *sc, struct filter_entry *f)
1548 MPASS(f->tid < sc->tids.ntids);
1551 MPASS(f->valid == 0);
1553 if (f->fs.newdmac) {
1554 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_ECE, 1, 1);
1558 if (f->fs.newvlan == VLAN_INSERT || f->fs.newvlan == VLAN_REWRITE) {
1559 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_RFR, 1, 1);
1563 if (f->fs.newsmac) {
1564 MPASS(f->smt != NULL);
1565 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_CWR, 1, 1);
1566 set_tcb_field(sc, f->tid, W_TCB_SMAC_SEL,
1567 V_TCB_SMAC_SEL(M_TCB_SMAC_SEL), V_TCB_SMAC_SEL(f->smt->idx),
1572 switch(f->fs.nat_mode) {
1576 set_nat_params(sc, f, true, false, false, false);
1579 case NAT_MODE_DIP_DP:
1580 set_nat_params(sc, f, true, false, true, false);
1583 case NAT_MODE_DIP_DP_SIP:
1584 set_nat_params(sc, f, true, true, true, false);
1587 case NAT_MODE_DIP_DP_SP:
1588 set_nat_params(sc, f, true, false, true, true);
1591 case NAT_MODE_SIP_SP:
1592 set_nat_params(sc, f, false, true, false, true);
1595 case NAT_MODE_DIP_SIP_SP:
1596 set_nat_params(sc, f, true, true, false, true);
1600 set_nat_params(sc, f, true, true, true, true);
1604 MPASS(0); /* should have been validated earlier */
1609 if (f->fs.nat_seq_chk) {
1610 set_tcb_field(sc, f->tid, W_TCB_RCV_NXT,
1611 V_TCB_RCV_NXT(M_TCB_RCV_NXT),
1612 V_TCB_RCV_NXT(f->fs.nat_seq_chk), 1);
1616 if (is_t5(sc) && f->fs.action == FILTER_DROP) {
1618 * Migrating = 1, Non-offload = 0 to get a T5 hashfilter to drop.
1620 set_tcb_field(sc, f->tid, W_TCB_T_FLAGS, V_TF_NON_OFFLOAD(1) |
1621 V_TF_MIGRATING(1), V_TF_MIGRATING(1), 1);
1626 * Enable switching after all secondary resources (L2T entry, SMT entry,
1627 * etc.) are setup so that any switched packet will use correct
1630 if (f->fs.action == FILTER_SWITCH) {
1631 set_tcb_tflag(sc, f->tid, S_TF_CCTRL_ECN, 1, 1);
1635 if (f->fs.hitcnts || updated > 0) {
1636 set_tcb_field(sc, f->tid, W_TCB_TIMESTAMP,
1637 V_TCB_TIMESTAMP(M_TCB_TIMESTAMP) |
1638 V_TCB_T_RTT_TS_RECENT_AGE(M_TCB_T_RTT_TS_RECENT_AGE),
1639 V_TCB_TIMESTAMP(0ULL) | V_TCB_T_RTT_TS_RECENT_AGE(0ULL), 0);
1640 return (EINPROGRESS);