2 * This file is part of the Chelsio T4 Ethernet driver for Linux.
4 * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 #include "t4_values.h"
44 #include "cxgb4_filter.h"
46 static inline bool is_field_set(u32 val, u32 mask)
51 static inline bool unsupported(u32 conf, u32 conf_mask, u32 val, u32 mask)
53 return !(conf & conf_mask) && is_field_set(val, mask);
56 static int set_tcb_field(struct adapter *adap, struct filter_entry *f,
57 unsigned int ftid, u16 word, u64 mask, u64 val,
60 struct cpl_set_tcb_field *req;
63 skb = alloc_skb(sizeof(struct cpl_set_tcb_field), GFP_ATOMIC);
67 req = (struct cpl_set_tcb_field *)__skb_put_zero(skb, sizeof(*req));
68 INIT_TP_WR_CPL(req, CPL_SET_TCB_FIELD, ftid);
69 req->reply_ctrl = htons(REPLY_CHAN_V(0) |
70 QUEUENO_V(adap->sge.fw_evtq.abs_id) |
71 NO_REPLY_V(no_reply));
72 req->word_cookie = htons(TCB_WORD_V(word) | TCB_COOKIE_V(ftid));
73 req->mask = cpu_to_be64(mask);
74 req->val = cpu_to_be64(val);
75 set_wr_txq(skb, CPL_PRIORITY_CONTROL, f->fs.val.iport & 0x3);
76 t4_ofld_send(adap, skb);
80 /* Set one of the t_flags bits in the TCB.
82 static int set_tcb_tflag(struct adapter *adap, struct filter_entry *f,
83 unsigned int ftid, unsigned int bit_pos,
84 unsigned int val, int no_reply)
86 return set_tcb_field(adap, f, ftid, TCB_T_FLAGS_W, 1ULL << bit_pos,
87 (unsigned long long)val << bit_pos, no_reply);
90 static void mk_abort_req_ulp(struct cpl_abort_req *abort_req, unsigned int tid)
92 struct ulp_txpkt *txpkt = (struct ulp_txpkt *)abort_req;
93 struct ulptx_idata *sc = (struct ulptx_idata *)(txpkt + 1);
95 txpkt->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) | ULP_TXPKT_DEST_V(0));
96 txpkt->len = htonl(DIV_ROUND_UP(sizeof(*abort_req), 16));
97 sc->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
98 sc->len = htonl(sizeof(*abort_req) - sizeof(struct work_request_hdr));
99 OPCODE_TID(abort_req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
100 abort_req->rsvd0 = htonl(0);
101 abort_req->rsvd1 = 0;
102 abort_req->cmd = CPL_ABORT_NO_RST;
105 static void mk_abort_rpl_ulp(struct cpl_abort_rpl *abort_rpl, unsigned int tid)
107 struct ulp_txpkt *txpkt = (struct ulp_txpkt *)abort_rpl;
108 struct ulptx_idata *sc = (struct ulptx_idata *)(txpkt + 1);
110 txpkt->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) | ULP_TXPKT_DEST_V(0));
111 txpkt->len = htonl(DIV_ROUND_UP(sizeof(*abort_rpl), 16));
112 sc->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
113 sc->len = htonl(sizeof(*abort_rpl) - sizeof(struct work_request_hdr));
114 OPCODE_TID(abort_rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
115 abort_rpl->rsvd0 = htonl(0);
116 abort_rpl->rsvd1 = 0;
117 abort_rpl->cmd = CPL_ABORT_NO_RST;
120 static void mk_set_tcb_ulp(struct filter_entry *f,
121 struct cpl_set_tcb_field *req,
122 unsigned int word, u64 mask, u64 val,
123 u8 cookie, int no_reply)
125 struct ulp_txpkt *txpkt = (struct ulp_txpkt *)req;
126 struct ulptx_idata *sc = (struct ulptx_idata *)(txpkt + 1);
128 txpkt->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) | ULP_TXPKT_DEST_V(0));
129 txpkt->len = htonl(DIV_ROUND_UP(sizeof(*req), 16));
130 sc->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
131 sc->len = htonl(sizeof(*req) - sizeof(struct work_request_hdr));
132 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, f->tid));
133 req->reply_ctrl = htons(NO_REPLY_V(no_reply) | REPLY_CHAN_V(0) |
135 req->word_cookie = htons(TCB_WORD_V(word) | TCB_COOKIE_V(cookie));
136 req->mask = cpu_to_be64(mask);
137 req->val = cpu_to_be64(val);
138 sc = (struct ulptx_idata *)(req + 1);
139 sc->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_NOOP));
143 static int configure_filter_smac(struct adapter *adap, struct filter_entry *f)
147 /* do a set-tcb for smac-sel and CWR bit.. */
148 err = set_tcb_tflag(adap, f, f->tid, TF_CCTRL_CWR_S, 1, 1);
152 err = set_tcb_field(adap, f, f->tid, TCB_SMAC_SEL_W,
153 TCB_SMAC_SEL_V(TCB_SMAC_SEL_M),
154 TCB_SMAC_SEL_V(f->smt->idx), 1);
159 dev_err(adap->pdev_dev, "filter %u smac config failed with error %u\n",
164 static void set_nat_params(struct adapter *adap, struct filter_entry *f,
165 unsigned int tid, bool dip, bool sip, bool dp,
170 set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W,
171 WORD_MASK, f->fs.nat_lip[15] |
172 f->fs.nat_lip[14] << 8 |
173 f->fs.nat_lip[13] << 16 |
174 f->fs.nat_lip[12] << 24, 1);
176 set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W + 1,
177 WORD_MASK, f->fs.nat_lip[11] |
178 f->fs.nat_lip[10] << 8 |
179 f->fs.nat_lip[9] << 16 |
180 f->fs.nat_lip[8] << 24, 1);
182 set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W + 2,
183 WORD_MASK, f->fs.nat_lip[7] |
184 f->fs.nat_lip[6] << 8 |
185 f->fs.nat_lip[5] << 16 |
186 f->fs.nat_lip[4] << 24, 1);
188 set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W + 3,
189 WORD_MASK, f->fs.nat_lip[3] |
190 f->fs.nat_lip[2] << 8 |
191 f->fs.nat_lip[1] << 16 |
192 f->fs.nat_lip[0] << 24, 1);
194 set_tcb_field(adap, f, tid, TCB_RX_FRAG3_LEN_RAW_W,
195 WORD_MASK, f->fs.nat_lip[3] |
196 f->fs.nat_lip[2] << 8 |
197 f->fs.nat_lip[1] << 16 |
198 f->fs.nat_lip[0] << 24, 1);
204 set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W,
205 WORD_MASK, f->fs.nat_fip[15] |
206 f->fs.nat_fip[14] << 8 |
207 f->fs.nat_fip[13] << 16 |
208 f->fs.nat_fip[12] << 24, 1);
210 set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W + 1,
211 WORD_MASK, f->fs.nat_fip[11] |
212 f->fs.nat_fip[10] << 8 |
213 f->fs.nat_fip[9] << 16 |
214 f->fs.nat_fip[8] << 24, 1);
216 set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W + 2,
217 WORD_MASK, f->fs.nat_fip[7] |
218 f->fs.nat_fip[6] << 8 |
219 f->fs.nat_fip[5] << 16 |
220 f->fs.nat_fip[4] << 24, 1);
222 set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W + 3,
223 WORD_MASK, f->fs.nat_fip[3] |
224 f->fs.nat_fip[2] << 8 |
225 f->fs.nat_fip[1] << 16 |
226 f->fs.nat_fip[0] << 24, 1);
229 set_tcb_field(adap, f, tid,
230 TCB_RX_FRAG3_START_IDX_OFFSET_RAW_W,
231 WORD_MASK, f->fs.nat_fip[3] |
232 f->fs.nat_fip[2] << 8 |
233 f->fs.nat_fip[1] << 16 |
234 f->fs.nat_fip[0] << 24, 1);
238 set_tcb_field(adap, f, tid, TCB_PDU_HDR_LEN_W, WORD_MASK,
239 (dp ? f->fs.nat_lport : 0) |
240 (sp ? f->fs.nat_fport << 16 : 0), 1);
243 /* Validate filter spec against configuration done on the card. */
244 static int validate_filter(struct net_device *dev,
245 struct ch_filter_specification *fs)
247 struct adapter *adapter = netdev2adap(dev);
250 /* Check for unconfigured fields being used. */
251 fconf = adapter->params.tp.vlan_pri_map;
252 iconf = adapter->params.tp.ingress_config;
254 if (unsupported(fconf, FCOE_F, fs->val.fcoe, fs->mask.fcoe) ||
255 unsupported(fconf, PORT_F, fs->val.iport, fs->mask.iport) ||
256 unsupported(fconf, TOS_F, fs->val.tos, fs->mask.tos) ||
257 unsupported(fconf, ETHERTYPE_F, fs->val.ethtype,
259 unsupported(fconf, MACMATCH_F, fs->val.macidx, fs->mask.macidx) ||
260 unsupported(fconf, MPSHITTYPE_F, fs->val.matchtype,
261 fs->mask.matchtype) ||
262 unsupported(fconf, FRAGMENTATION_F, fs->val.frag, fs->mask.frag) ||
263 unsupported(fconf, PROTOCOL_F, fs->val.proto, fs->mask.proto) ||
264 unsupported(fconf, VNIC_ID_F, fs->val.pfvf_vld,
265 fs->mask.pfvf_vld) ||
266 unsupported(fconf, VNIC_ID_F, fs->val.ovlan_vld,
267 fs->mask.ovlan_vld) ||
268 unsupported(fconf, VNIC_ID_F, fs->val.encap_vld,
269 fs->mask.encap_vld) ||
270 unsupported(fconf, VLAN_F, fs->val.ivlan_vld, fs->mask.ivlan_vld))
273 /* T4 inconveniently uses the same FT_VNIC_ID_W bits for both the Outer
274 * VLAN Tag and PF/VF/VFvld fields based on VNIC_F being set
275 * in TP_INGRESS_CONFIG. Hense the somewhat crazy checks
276 * below. Additionally, since the T4 firmware interface also
277 * carries that overlap, we need to translate any PF/VF
278 * specification into that internal format below.
280 if ((is_field_set(fs->val.pfvf_vld, fs->mask.pfvf_vld) &&
281 is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld)) ||
282 (is_field_set(fs->val.pfvf_vld, fs->mask.pfvf_vld) &&
283 is_field_set(fs->val.encap_vld, fs->mask.encap_vld)) ||
284 (is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld) &&
285 is_field_set(fs->val.encap_vld, fs->mask.encap_vld)))
287 if (unsupported(iconf, VNIC_F, fs->val.pfvf_vld, fs->mask.pfvf_vld) ||
288 (is_field_set(fs->val.ovlan_vld, fs->mask.ovlan_vld) &&
291 if (fs->val.pf > 0x7 || fs->val.vf > 0x7f)
296 /* If the user is requesting that the filter action loop
297 * matching packets back out one of our ports, make sure that
298 * the egress port is in range.
300 if (fs->action == FILTER_SWITCH &&
301 fs->eport >= adapter->params.nports)
304 /* Don't allow various trivially obvious bogus out-of-range values... */
305 if (fs->val.iport >= adapter->params.nports)
308 /* T4 doesn't support removing VLAN Tags for loop back filters. */
309 if (is_t4(adapter->params.chip) &&
310 fs->action == FILTER_SWITCH &&
311 (fs->newvlan == VLAN_REMOVE ||
312 fs->newvlan == VLAN_REWRITE))
315 if (fs->val.encap_vld &&
316 CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
321 static int get_filter_steerq(struct net_device *dev,
322 struct ch_filter_specification *fs)
324 struct adapter *adapter = netdev2adap(dev);
327 /* If the user has requested steering matching Ingress Packets
328 * to a specific Queue Set, we need to make sure it's in range
329 * for the port and map that into the Absolute Queue ID of the
330 * Queue Set's Response Queue.
337 struct port_info *pi = netdev_priv(dev);
339 /* If the iq id is greater than the number of qsets,
340 * then assume it is an absolute qid.
342 if (fs->iq < pi->nqsets)
343 iq = adapter->sge.ethrxq[pi->first_qset +
352 static int get_filter_count(struct adapter *adapter, unsigned int fidx,
353 u64 *pkts, u64 *bytes, bool hash)
355 unsigned int tcb_base, tcbaddr;
356 unsigned int word_offset;
357 struct filter_entry *f;
358 __be64 be64_byte_count;
361 tcb_base = t4_read_reg(adapter, TP_CMM_TCB_BASE_A);
362 if (is_hashfilter(adapter) && hash) {
363 if (fidx < adapter->tids.ntids) {
364 f = adapter->tids.tid_tab[fidx];
371 if ((fidx != (adapter->tids.nftids +
372 adapter->tids.nsftids - 1)) &&
373 fidx >= adapter->tids.nftids)
376 f = &adapter->tids.ftid_tab[fidx];
380 tcbaddr = tcb_base + f->tid * TCB_SIZE;
382 spin_lock(&adapter->win0_lock);
383 if (is_t4(adapter->params.chip)) {
386 /* T4 doesn't maintain byte counts in hw */
391 ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
392 tcbaddr + (word_offset * sizeof(__be32)),
394 (__be32 *)&be64_count,
398 *pkts = be64_to_cpu(be64_count);
404 ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
405 tcbaddr + (word_offset * sizeof(__be32)),
406 sizeof(be64_byte_count),
411 *bytes = be64_to_cpu(be64_byte_count);
415 ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
416 tcbaddr + (word_offset * sizeof(__be32)),
422 *pkts = (u64)be32_to_cpu(be32_count);
426 spin_unlock(&adapter->win0_lock);
430 int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
431 u64 *hitcnt, u64 *bytecnt, bool hash)
433 struct adapter *adapter = netdev2adap(dev);
435 return get_filter_count(adapter, fidx, hitcnt, bytecnt, hash);
438 int cxgb4_get_free_ftid(struct net_device *dev, int family)
440 struct adapter *adap = netdev2adap(dev);
441 struct tid_info *t = &adap->tids;
444 spin_lock_bh(&t->ftid_lock);
445 if (family == PF_INET) {
446 ftid = find_first_zero_bit(t->ftid_bmap, t->nftids);
447 if (ftid >= t->nftids)
450 if (is_t6(adap->params.chip)) {
451 ftid = bitmap_find_free_region(t->ftid_bmap,
456 /* this is only a lookup, keep the found region
459 bitmap_release_region(t->ftid_bmap, ftid, 1);
461 ftid = bitmap_find_free_region(t->ftid_bmap,
466 bitmap_release_region(t->ftid_bmap, ftid, 2);
470 spin_unlock_bh(&t->ftid_lock);
474 static int cxgb4_set_ftid(struct tid_info *t, int fidx, int family,
475 unsigned int chip_ver)
477 spin_lock_bh(&t->ftid_lock);
479 if (test_bit(fidx, t->ftid_bmap)) {
480 spin_unlock_bh(&t->ftid_lock);
484 if (family == PF_INET) {
485 __set_bit(fidx, t->ftid_bmap);
487 if (chip_ver < CHELSIO_T6)
488 bitmap_allocate_region(t->ftid_bmap, fidx, 2);
490 bitmap_allocate_region(t->ftid_bmap, fidx, 1);
493 spin_unlock_bh(&t->ftid_lock);
497 static void cxgb4_clear_ftid(struct tid_info *t, int fidx, int family,
498 unsigned int chip_ver)
500 spin_lock_bh(&t->ftid_lock);
501 if (family == PF_INET) {
502 __clear_bit(fidx, t->ftid_bmap);
504 if (chip_ver < CHELSIO_T6)
505 bitmap_release_region(t->ftid_bmap, fidx, 2);
507 bitmap_release_region(t->ftid_bmap, fidx, 1);
509 spin_unlock_bh(&t->ftid_lock);
512 /* Delete the filter at a specified index. */
513 static int del_filter_wr(struct adapter *adapter, int fidx)
515 struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
516 struct fw_filter_wr *fwr;
522 skb = alloc_skb(len, GFP_KERNEL);
526 fwr = __skb_put(skb, len);
527 t4_mk_filtdelwr(f->tid, fwr, (adapter->flags & SHUTTING_DOWN) ? -1
528 : adapter->sge.fw_evtq.abs_id);
530 /* Mark the filter as "pending" and ship off the Filter Work Request.
531 * When we get the Work Request Reply we'll clear the pending status.
534 t4_mgmt_tx(adapter, skb);
538 /* Send a Work Request to write the filter at a specified index. We construct
539 * a Firmware Filter Work Request to have the work done and put the indicated
540 * filter into "pending" mode which will prevent any further actions against
541 * it till we get a reply from the firmware on the completion status of the
544 int set_filter_wr(struct adapter *adapter, int fidx)
546 struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
547 struct fw_filter2_wr *fwr;
550 skb = alloc_skb(sizeof(*fwr), GFP_KERNEL);
554 /* If the new filter requires loopback Destination MAC and/or VLAN
555 * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
558 if (f->fs.newdmac || f->fs.newvlan) {
559 /* allocate L2T entry for new filter */
560 f->l2t = t4_l2t_alloc_switching(adapter, f->fs.vlan,
561 f->fs.eport, f->fs.dmac);
568 /* If the new filter requires loopback Source MAC rewriting then
569 * we need to allocate a SMT entry for the filter.
572 f->smt = cxgb4_smt_alloc_switching(f->dev, f->fs.smac);
575 cxgb4_l2t_release(f->l2t);
583 fwr = __skb_put_zero(skb, sizeof(*fwr));
585 /* It would be nice to put most of the following in t4_hw.c but most
586 * of the work is translating the cxgbtool ch_filter_specification
587 * into the Work Request and the definition of that structure is
588 * currently in cxgbtool.h which isn't appropriate to pull into the
589 * common code. We may eventually try to come up with a more neutral
590 * filter specification structure but for now it's easiest to simply
591 * put this fairly direct code in line ...
593 if (adapter->params.filter2_wr_support)
594 fwr->op_pkd = htonl(FW_WR_OP_V(FW_FILTER2_WR));
596 fwr->op_pkd = htonl(FW_WR_OP_V(FW_FILTER_WR));
597 fwr->len16_pkd = htonl(FW_WR_LEN16_V(sizeof(*fwr) / 16));
599 htonl(FW_FILTER_WR_TID_V(f->tid) |
600 FW_FILTER_WR_RQTYPE_V(f->fs.type) |
601 FW_FILTER_WR_NOREPLY_V(0) |
602 FW_FILTER_WR_IQ_V(f->fs.iq));
603 fwr->del_filter_to_l2tix =
604 htonl(FW_FILTER_WR_RPTTID_V(f->fs.rpttid) |
605 FW_FILTER_WR_DROP_V(f->fs.action == FILTER_DROP) |
606 FW_FILTER_WR_DIRSTEER_V(f->fs.dirsteer) |
607 FW_FILTER_WR_MASKHASH_V(f->fs.maskhash) |
608 FW_FILTER_WR_DIRSTEERHASH_V(f->fs.dirsteerhash) |
609 FW_FILTER_WR_LPBK_V(f->fs.action == FILTER_SWITCH) |
610 FW_FILTER_WR_DMAC_V(f->fs.newdmac) |
611 FW_FILTER_WR_INSVLAN_V(f->fs.newvlan == VLAN_INSERT ||
612 f->fs.newvlan == VLAN_REWRITE) |
613 FW_FILTER_WR_RMVLAN_V(f->fs.newvlan == VLAN_REMOVE ||
614 f->fs.newvlan == VLAN_REWRITE) |
615 FW_FILTER_WR_HITCNTS_V(f->fs.hitcnts) |
616 FW_FILTER_WR_TXCHAN_V(f->fs.eport) |
617 FW_FILTER_WR_PRIO_V(f->fs.prio) |
618 FW_FILTER_WR_L2TIX_V(f->l2t ? f->l2t->idx : 0));
619 fwr->ethtype = htons(f->fs.val.ethtype);
620 fwr->ethtypem = htons(f->fs.mask.ethtype);
621 fwr->frag_to_ovlan_vldm =
622 (FW_FILTER_WR_FRAG_V(f->fs.val.frag) |
623 FW_FILTER_WR_FRAGM_V(f->fs.mask.frag) |
624 FW_FILTER_WR_IVLAN_VLD_V(f->fs.val.ivlan_vld) |
625 FW_FILTER_WR_OVLAN_VLD_V(f->fs.val.ovlan_vld) |
626 FW_FILTER_WR_IVLAN_VLDM_V(f->fs.mask.ivlan_vld) |
627 FW_FILTER_WR_OVLAN_VLDM_V(f->fs.mask.ovlan_vld));
629 fwr->rx_chan_rx_rpl_iq =
630 htons(FW_FILTER_WR_RX_CHAN_V(0) |
631 FW_FILTER_WR_RX_RPL_IQ_V(adapter->sge.fw_evtq.abs_id));
632 fwr->maci_to_matchtypem =
633 htonl(FW_FILTER_WR_MACI_V(f->fs.val.macidx) |
634 FW_FILTER_WR_MACIM_V(f->fs.mask.macidx) |
635 FW_FILTER_WR_FCOE_V(f->fs.val.fcoe) |
636 FW_FILTER_WR_FCOEM_V(f->fs.mask.fcoe) |
637 FW_FILTER_WR_PORT_V(f->fs.val.iport) |
638 FW_FILTER_WR_PORTM_V(f->fs.mask.iport) |
639 FW_FILTER_WR_MATCHTYPE_V(f->fs.val.matchtype) |
640 FW_FILTER_WR_MATCHTYPEM_V(f->fs.mask.matchtype));
641 fwr->ptcl = f->fs.val.proto;
642 fwr->ptclm = f->fs.mask.proto;
643 fwr->ttyp = f->fs.val.tos;
644 fwr->ttypm = f->fs.mask.tos;
645 fwr->ivlan = htons(f->fs.val.ivlan);
646 fwr->ivlanm = htons(f->fs.mask.ivlan);
647 fwr->ovlan = htons(f->fs.val.ovlan);
648 fwr->ovlanm = htons(f->fs.mask.ovlan);
649 memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip));
650 memcpy(fwr->lipm, f->fs.mask.lip, sizeof(fwr->lipm));
651 memcpy(fwr->fip, f->fs.val.fip, sizeof(fwr->fip));
652 memcpy(fwr->fipm, f->fs.mask.fip, sizeof(fwr->fipm));
653 fwr->lp = htons(f->fs.val.lport);
654 fwr->lpm = htons(f->fs.mask.lport);
655 fwr->fp = htons(f->fs.val.fport);
656 fwr->fpm = htons(f->fs.mask.fport);
658 if (adapter->params.filter2_wr_support) {
659 fwr->natmode_to_ulp_type =
660 FW_FILTER2_WR_ULP_TYPE_V(f->fs.nat_mode ?
663 FW_FILTER2_WR_NATMODE_V(f->fs.nat_mode);
664 memcpy(fwr->newlip, f->fs.nat_lip, sizeof(fwr->newlip));
665 memcpy(fwr->newfip, f->fs.nat_fip, sizeof(fwr->newfip));
666 fwr->newlport = htons(f->fs.nat_lport);
667 fwr->newfport = htons(f->fs.nat_fport);
670 /* Mark the filter as "pending" and ship off the Filter Work Request.
671 * When we get the Work Request Reply we'll clear the pending status.
674 set_wr_txq(skb, CPL_PRIORITY_CONTROL, f->fs.val.iport & 0x3);
675 t4_ofld_send(adapter, skb);
679 /* Return an error number if the indicated filter isn't writable ... */
680 int writable_filter(struct filter_entry *f)
690 /* Delete the filter at the specified index (if valid). The checks for all
691 * the common problems with doing this like the filter being locked, currently
692 * pending in another operation, etc.
694 int delete_filter(struct adapter *adapter, unsigned int fidx)
696 struct filter_entry *f;
699 if (fidx >= adapter->tids.nftids + adapter->tids.nsftids)
702 f = &adapter->tids.ftid_tab[fidx];
703 ret = writable_filter(f);
707 return del_filter_wr(adapter, fidx);
712 /* Clear a filter and release any of its resources that we own. This also
713 * clears the filter's "pending" status.
715 void clear_filter(struct adapter *adap, struct filter_entry *f)
717 struct port_info *pi = netdev_priv(f->dev);
719 /* If the new or old filter have loopback rewriteing rules then we'll
720 * need to free any existing L2T, SMT, CLIP entries of filter
724 cxgb4_l2t_release(f->l2t);
727 cxgb4_smt_release(f->smt);
729 if (f->fs.val.encap_vld && f->fs.val.ovlan_vld)
730 if (atomic_dec_and_test(&adap->mps_encap[f->fs.val.ovlan &
732 t4_free_encap_mac_filt(adap, pi->viid,
733 f->fs.val.ovlan & 0x1ff, 0);
735 if ((f->fs.hash || is_t6(adap->params.chip)) && f->fs.type)
736 cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
738 /* The zeroing of the filter rule below clears the filter valid,
739 * pending, locked flags, l2t pointer, etc. so it's all we need for
742 memset(f, 0, sizeof(*f));
745 void clear_all_filters(struct adapter *adapter)
749 if (adapter->tids.ftid_tab) {
750 struct filter_entry *f = &adapter->tids.ftid_tab[0];
751 unsigned int max_ftid = adapter->tids.nftids +
752 adapter->tids.nsftids;
754 for (i = 0; i < max_ftid; i++, f++)
755 if (f->valid || f->pending)
756 clear_filter(adapter, f);
760 /* Fill up default masks for set match fields. */
761 static void fill_default_mask(struct ch_filter_specification *fs)
763 unsigned int lip = 0, lip_mask = 0;
764 unsigned int fip = 0, fip_mask = 0;
767 if (fs->val.iport && !fs->mask.iport)
768 fs->mask.iport |= ~0;
769 if (fs->val.fcoe && !fs->mask.fcoe)
771 if (fs->val.matchtype && !fs->mask.matchtype)
772 fs->mask.matchtype |= ~0;
773 if (fs->val.macidx && !fs->mask.macidx)
774 fs->mask.macidx |= ~0;
775 if (fs->val.ethtype && !fs->mask.ethtype)
776 fs->mask.ethtype |= ~0;
777 if (fs->val.ivlan && !fs->mask.ivlan)
778 fs->mask.ivlan |= ~0;
779 if (fs->val.ovlan && !fs->mask.ovlan)
780 fs->mask.ovlan |= ~0;
781 if (fs->val.frag && !fs->mask.frag)
783 if (fs->val.tos && !fs->mask.tos)
785 if (fs->val.proto && !fs->mask.proto)
786 fs->mask.proto |= ~0;
788 for (i = 0; i < ARRAY_SIZE(fs->val.lip); i++) {
789 lip |= fs->val.lip[i];
790 lip_mask |= fs->mask.lip[i];
791 fip |= fs->val.fip[i];
792 fip_mask |= fs->mask.fip[i];
795 if (lip && !lip_mask)
796 memset(fs->mask.lip, ~0, sizeof(fs->mask.lip));
798 if (fip && !fip_mask)
799 memset(fs->mask.fip, ~0, sizeof(fs->mask.lip));
801 if (fs->val.lport && !fs->mask.lport)
803 if (fs->val.fport && !fs->mask.fport)
807 static bool is_addr_all_mask(u8 *ipmask, int family)
809 if (family == AF_INET) {
810 struct in_addr *addr;
812 addr = (struct in_addr *)ipmask;
813 if (addr->s_addr == 0xffffffff)
815 } else if (family == AF_INET6) {
816 struct in6_addr *addr6;
818 addr6 = (struct in6_addr *)ipmask;
819 if (addr6->s6_addr32[0] == 0xffffffff &&
820 addr6->s6_addr32[1] == 0xffffffff &&
821 addr6->s6_addr32[2] == 0xffffffff &&
822 addr6->s6_addr32[3] == 0xffffffff)
828 static bool is_inaddr_any(u8 *ip, int family)
832 if (family == AF_INET) {
833 struct in_addr *addr;
835 addr = (struct in_addr *)ip;
836 if (addr->s_addr == htonl(INADDR_ANY))
838 } else if (family == AF_INET6) {
839 struct in6_addr *addr6;
841 addr6 = (struct in6_addr *)ip;
842 addr_type = ipv6_addr_type((const struct in6_addr *)
844 if (addr_type == IPV6_ADDR_ANY)
850 bool is_filter_exact_match(struct adapter *adap,
851 struct ch_filter_specification *fs)
853 struct tp_params *tp = &adap->params.tp;
854 u64 hash_filter_mask = tp->hash_filter_mask;
857 if (!is_hashfilter(adap))
860 /* Keep tunnel VNI match disabled for hash-filters for now */
861 if (fs->mask.encap_vld)
865 if (is_inaddr_any(fs->val.fip, AF_INET6) ||
866 !is_addr_all_mask(fs->mask.fip, AF_INET6))
869 if (is_inaddr_any(fs->val.lip, AF_INET6) ||
870 !is_addr_all_mask(fs->mask.lip, AF_INET6))
873 if (is_inaddr_any(fs->val.fip, AF_INET) ||
874 !is_addr_all_mask(fs->mask.fip, AF_INET))
877 if (is_inaddr_any(fs->val.lip, AF_INET) ||
878 !is_addr_all_mask(fs->mask.lip, AF_INET))
882 if (!fs->val.lport || fs->mask.lport != 0xffff)
885 if (!fs->val.fport || fs->mask.fport != 0xffff)
888 /* calculate tuple mask and compare with mask configured in hw */
889 if (tp->fcoe_shift >= 0)
890 ntuple_mask |= (u64)fs->mask.fcoe << tp->fcoe_shift;
892 if (tp->port_shift >= 0)
893 ntuple_mask |= (u64)fs->mask.iport << tp->port_shift;
895 if (tp->vnic_shift >= 0) {
896 if ((adap->params.tp.ingress_config & VNIC_F))
897 ntuple_mask |= (u64)fs->mask.pfvf_vld << tp->vnic_shift;
899 ntuple_mask |= (u64)fs->mask.ovlan_vld <<
903 if (tp->vlan_shift >= 0)
904 ntuple_mask |= (u64)fs->mask.ivlan << tp->vlan_shift;
906 if (tp->tos_shift >= 0)
907 ntuple_mask |= (u64)fs->mask.tos << tp->tos_shift;
909 if (tp->protocol_shift >= 0)
910 ntuple_mask |= (u64)fs->mask.proto << tp->protocol_shift;
912 if (tp->ethertype_shift >= 0)
913 ntuple_mask |= (u64)fs->mask.ethtype << tp->ethertype_shift;
915 if (tp->macmatch_shift >= 0)
916 ntuple_mask |= (u64)fs->mask.macidx << tp->macmatch_shift;
918 if (tp->matchtype_shift >= 0)
919 ntuple_mask |= (u64)fs->mask.matchtype << tp->matchtype_shift;
921 if (tp->frag_shift >= 0)
922 ntuple_mask |= (u64)fs->mask.frag << tp->frag_shift;
924 if (ntuple_mask != hash_filter_mask)
930 static u64 hash_filter_ntuple(struct ch_filter_specification *fs,
931 struct net_device *dev)
933 struct adapter *adap = netdev2adap(dev);
934 struct tp_params *tp = &adap->params.tp;
937 /* Initialize each of the fields which we care about which are present
938 * in the Compressed Filter Tuple.
940 if (tp->vlan_shift >= 0 && fs->mask.ivlan)
941 ntuple |= (FT_VLAN_VLD_F | fs->val.ivlan) << tp->vlan_shift;
943 if (tp->port_shift >= 0 && fs->mask.iport)
944 ntuple |= (u64)fs->val.iport << tp->port_shift;
946 if (tp->protocol_shift >= 0) {
948 ntuple |= (u64)IPPROTO_TCP << tp->protocol_shift;
950 ntuple |= (u64)fs->val.proto << tp->protocol_shift;
953 if (tp->tos_shift >= 0 && fs->mask.tos)
954 ntuple |= (u64)(fs->val.tos) << tp->tos_shift;
956 if (tp->vnic_shift >= 0) {
957 if ((adap->params.tp.ingress_config & USE_ENC_IDX_F) &&
959 ntuple |= (u64)((fs->val.encap_vld << 16) |
960 (fs->val.ovlan)) << tp->vnic_shift;
961 else if ((adap->params.tp.ingress_config & VNIC_F) &&
963 ntuple |= (u64)((fs->val.pfvf_vld << 16) |
965 (fs->val.vf)) << tp->vnic_shift;
967 ntuple |= (u64)((fs->val.ovlan_vld << 16) |
968 (fs->val.ovlan)) << tp->vnic_shift;
971 if (tp->macmatch_shift >= 0 && fs->mask.macidx)
972 ntuple |= (u64)(fs->val.macidx) << tp->macmatch_shift;
974 if (tp->ethertype_shift >= 0 && fs->mask.ethtype)
975 ntuple |= (u64)(fs->val.ethtype) << tp->ethertype_shift;
977 if (tp->matchtype_shift >= 0 && fs->mask.matchtype)
978 ntuple |= (u64)(fs->val.matchtype) << tp->matchtype_shift;
980 if (tp->frag_shift >= 0 && fs->mask.frag)
981 ntuple |= (u64)(fs->val.frag) << tp->frag_shift;
983 if (tp->fcoe_shift >= 0 && fs->mask.fcoe)
984 ntuple |= (u64)(fs->val.fcoe) << tp->fcoe_shift;
988 static void mk_act_open_req6(struct filter_entry *f, struct sk_buff *skb,
989 unsigned int qid_filterid, struct adapter *adap)
991 struct cpl_t6_act_open_req6 *t6req = NULL;
992 struct cpl_act_open_req6 *req = NULL;
994 t6req = (struct cpl_t6_act_open_req6 *)__skb_put(skb, sizeof(*t6req));
995 INIT_TP_WR(t6req, 0);
996 req = (struct cpl_act_open_req6 *)t6req;
997 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, qid_filterid));
998 req->local_port = cpu_to_be16(f->fs.val.lport);
999 req->peer_port = cpu_to_be16(f->fs.val.fport);
1000 req->local_ip_hi = *(__be64 *)(&f->fs.val.lip);
1001 req->local_ip_lo = *(((__be64 *)&f->fs.val.lip) + 1);
1002 req->peer_ip_hi = *(__be64 *)(&f->fs.val.fip);
1003 req->peer_ip_lo = *(((__be64 *)&f->fs.val.fip) + 1);
1004 req->opt0 = cpu_to_be64(NAGLE_V(f->fs.newvlan == VLAN_REMOVE ||
1005 f->fs.newvlan == VLAN_REWRITE) |
1006 DELACK_V(f->fs.hitcnts) |
1007 L2T_IDX_V(f->l2t ? f->l2t->idx : 0) |
1008 SMAC_SEL_V((cxgb4_port_viid(f->dev) &
1010 TX_CHAN_V(f->fs.eport) |
1011 NO_CONG_V(f->fs.rpttid) |
1012 ULP_MODE_V(f->fs.nat_mode ?
1013 ULP_MODE_TCPDDP : ULP_MODE_NONE) |
1014 TCAM_BYPASS_F | NON_OFFLOAD_F);
1015 t6req->params = cpu_to_be64(FILTER_TUPLE_V(hash_filter_ntuple(&f->fs,
1017 t6req->opt2 = htonl(RSS_QUEUE_VALID_F |
1018 RSS_QUEUE_V(f->fs.iq) |
1019 TX_QUEUE_V(f->fs.nat_mode) |
1022 CONG_CNTRL_V((f->fs.action == FILTER_DROP) |
1023 (f->fs.dirsteer << 1)) |
1024 PACE_V((f->fs.maskhash) |
1025 ((f->fs.dirsteerhash) << 1)) |
1026 CCTRL_ECN_V(f->fs.action == FILTER_SWITCH));
1029 static void mk_act_open_req(struct filter_entry *f, struct sk_buff *skb,
1030 unsigned int qid_filterid, struct adapter *adap)
1032 struct cpl_t6_act_open_req *t6req = NULL;
1033 struct cpl_act_open_req *req = NULL;
1035 t6req = (struct cpl_t6_act_open_req *)__skb_put(skb, sizeof(*t6req));
1036 INIT_TP_WR(t6req, 0);
1037 req = (struct cpl_act_open_req *)t6req;
1038 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, qid_filterid));
1039 req->local_port = cpu_to_be16(f->fs.val.lport);
1040 req->peer_port = cpu_to_be16(f->fs.val.fport);
1041 memcpy(&req->local_ip, f->fs.val.lip, 4);
1042 memcpy(&req->peer_ip, f->fs.val.fip, 4);
1043 req->opt0 = cpu_to_be64(NAGLE_V(f->fs.newvlan == VLAN_REMOVE ||
1044 f->fs.newvlan == VLAN_REWRITE) |
1045 DELACK_V(f->fs.hitcnts) |
1046 L2T_IDX_V(f->l2t ? f->l2t->idx : 0) |
1047 SMAC_SEL_V((cxgb4_port_viid(f->dev) &
1049 TX_CHAN_V(f->fs.eport) |
1050 NO_CONG_V(f->fs.rpttid) |
1051 ULP_MODE_V(f->fs.nat_mode ?
1052 ULP_MODE_TCPDDP : ULP_MODE_NONE) |
1053 TCAM_BYPASS_F | NON_OFFLOAD_F);
1055 t6req->params = cpu_to_be64(FILTER_TUPLE_V(hash_filter_ntuple(&f->fs,
1057 t6req->opt2 = htonl(RSS_QUEUE_VALID_F |
1058 RSS_QUEUE_V(f->fs.iq) |
1059 TX_QUEUE_V(f->fs.nat_mode) |
1062 CONG_CNTRL_V((f->fs.action == FILTER_DROP) |
1063 (f->fs.dirsteer << 1)) |
1064 PACE_V((f->fs.maskhash) |
1065 ((f->fs.dirsteerhash) << 1)) |
1066 CCTRL_ECN_V(f->fs.action == FILTER_SWITCH));
1069 static int cxgb4_set_hash_filter(struct net_device *dev,
1070 struct ch_filter_specification *fs,
1071 struct filter_ctx *ctx)
1073 struct adapter *adapter = netdev2adap(dev);
1074 struct port_info *pi = netdev_priv(dev);
1075 struct tid_info *t = &adapter->tids;
1076 struct filter_entry *f;
1077 struct sk_buff *skb;
1082 fill_default_mask(fs);
1083 ret = validate_filter(dev, fs);
1087 iq = get_filter_steerq(dev, fs);
1091 f = kzalloc(sizeof(*f), GFP_KERNEL);
1100 /* If the new filter requires loopback Destination MAC and/or VLAN
1101 * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
1104 if (f->fs.newdmac || f->fs.newvlan) {
1105 /* allocate L2T entry for new filter */
1106 f->l2t = t4_l2t_alloc_switching(adapter, f->fs.vlan,
1107 f->fs.eport, f->fs.dmac);
1114 /* If the new filter requires loopback Source MAC rewriting then
1115 * we need to allocate a SMT entry for the filter.
1117 if (f->fs.newsmac) {
1118 f->smt = cxgb4_smt_alloc_switching(f->dev, f->fs.smac);
1121 cxgb4_l2t_release(f->l2t);
1129 atid = cxgb4_alloc_atid(t, f);
1135 iconf = adapter->params.tp.ingress_config;
1136 if (iconf & VNIC_F) {
1137 f->fs.val.ovlan = (fs->val.pf << 13) | fs->val.vf;
1138 f->fs.mask.ovlan = (fs->mask.pf << 13) | fs->mask.vf;
1139 f->fs.val.ovlan_vld = fs->val.pfvf_vld;
1140 f->fs.mask.ovlan_vld = fs->mask.pfvf_vld;
1141 } else if (iconf & USE_ENC_IDX_F) {
1142 if (f->fs.val.encap_vld) {
1143 struct port_info *pi = netdev_priv(f->dev);
1144 u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
1146 /* allocate MPS TCAM entry */
1147 ret = t4_alloc_encap_mac_filt(adapter, pi->viid,
1156 atomic_inc(&adapter->mps_encap[ret].refcnt);
1157 f->fs.val.ovlan = ret;
1158 f->fs.mask.ovlan = 0xffff;
1159 f->fs.val.ovlan_vld = 1;
1160 f->fs.mask.ovlan_vld = 1;
1164 size = sizeof(struct cpl_t6_act_open_req);
1166 ret = cxgb4_clip_get(f->dev, (const u32 *)&f->fs.val.lip, 1);
1170 skb = alloc_skb(size, GFP_KERNEL);
1176 mk_act_open_req6(f, skb,
1177 ((adapter->sge.fw_evtq.abs_id << 14) | atid),
1180 skb = alloc_skb(size, GFP_KERNEL);
1186 mk_act_open_req(f, skb,
1187 ((adapter->sge.fw_evtq.abs_id << 14) | atid),
1192 set_wr_txq(skb, CPL_PRIORITY_SETUP, f->fs.val.iport & 0x3);
1193 t4_ofld_send(adapter, skb);
1197 cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
1200 if (f->fs.val.encap_vld && f->fs.val.ovlan_vld)
1201 t4_free_encap_mac_filt(adapter, pi->viid, f->fs.val.ovlan, 1);
1204 cxgb4_free_atid(t, atid);
1208 cxgb4_smt_release(f->smt);
1214 cxgb4_l2t_release(f->l2t);
1223 /* Check a Chelsio Filter Request for validity, convert it into our internal
1224 * format and send it to the hardware. Return 0 on success, an error number
1225 * otherwise. We attach any provided filter operation context to the internal
1226 * filter specification in order to facilitate signaling completion of the
1229 int __cxgb4_set_filter(struct net_device *dev, int filter_id,
1230 struct ch_filter_specification *fs,
1231 struct filter_ctx *ctx)
1233 struct adapter *adapter = netdev2adap(dev);
1234 unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
1235 unsigned int max_fidx, fidx;
1236 struct filter_entry *f;
1241 if (is_hashfilter(adapter))
1242 return cxgb4_set_hash_filter(dev, fs, ctx);
1243 netdev_err(dev, "%s: Exact-match filters only supported with Hash Filter configuration\n",
1248 max_fidx = adapter->tids.nftids;
1249 if (filter_id != (max_fidx + adapter->tids.nsftids - 1) &&
1250 filter_id >= max_fidx)
1253 fill_default_mask(fs);
1255 ret = validate_filter(dev, fs);
1259 iq = get_filter_steerq(dev, fs);
1263 /* IPv6 filters occupy four slots and must be aligned on
1264 * four-slot boundaries. IPv4 filters only occupy a single
1265 * slot and have no alignment requirements but writing a new
1266 * IPv4 filter into the middle of an existing IPv6 filter
1267 * requires clearing the old IPv6 filter and hence we prevent
1270 if (fs->type == 0) { /* IPv4 */
1271 /* For T6, If our IPv4 filter isn't being written to a
1272 * multiple of two filter index and there's an IPv6
1273 * filter at the multiple of 2 base slot, then we need
1274 * to delete that IPv6 filter ...
1275 * For adapters below T6, IPv6 filter occupies 4 entries.
1276 * Hence we need to delete the filter in multiple of 4 slot.
1278 if (chip_ver < CHELSIO_T6)
1279 fidx = filter_id & ~0x3;
1281 fidx = filter_id & ~0x1;
1283 if (fidx != filter_id &&
1284 adapter->tids.ftid_tab[fidx].fs.type) {
1285 f = &adapter->tids.ftid_tab[fidx];
1287 dev_err(adapter->pdev_dev,
1288 "Invalid location. IPv6 requires 4 slots and is occupying slots %u to %u\n",
1294 if (chip_ver < CHELSIO_T6) {
1295 /* Ensure that the IPv6 filter is aligned on a
1296 * multiple of 4 boundary.
1298 if (filter_id & 0x3) {
1299 dev_err(adapter->pdev_dev,
1300 "Invalid location. IPv6 must be aligned on a 4-slot boundary\n");
1304 /* Check all except the base overlapping IPv4 filter
1307 for (fidx = filter_id + 1; fidx < filter_id + 4;
1309 f = &adapter->tids.ftid_tab[fidx];
1311 dev_err(adapter->pdev_dev,
1312 "Invalid location. IPv6 requires 4 slots and an IPv4 filter exists at %u\n",
1318 /* For T6, CLIP being enabled, IPv6 filter would occupy
1321 if (filter_id & 0x1)
1323 /* Check overlapping IPv4 filter slot */
1324 fidx = filter_id + 1;
1325 f = &adapter->tids.ftid_tab[fidx];
1327 pr_err("%s: IPv6 filter requires 2 indices. IPv4 filter already present at %d. Please remove IPv4 filter first.\n",
1334 /* Check to make sure that provided filter index is not
1335 * already in use by someone else
1337 f = &adapter->tids.ftid_tab[filter_id];
1341 fidx = filter_id + adapter->tids.ftid_base;
1342 ret = cxgb4_set_ftid(&adapter->tids, filter_id,
1343 fs->type ? PF_INET6 : PF_INET,
1348 /* Check t make sure the filter requested is writable ... */
1349 ret = writable_filter(f);
1351 /* Clear the bits we have set above */
1352 cxgb4_clear_ftid(&adapter->tids, filter_id,
1353 fs->type ? PF_INET6 : PF_INET,
1358 if (is_t6(adapter->params.chip) && fs->type &&
1359 ipv6_addr_type((const struct in6_addr *)fs->val.lip) !=
1361 ret = cxgb4_clip_get(dev, (const u32 *)&fs->val.lip, 1);
1363 cxgb4_clear_ftid(&adapter->tids, filter_id, PF_INET6,
1369 /* Convert the filter specification into our internal format.
1370 * We copy the PF/VF specification into the Outer VLAN field
1371 * here so the rest of the code -- including the interface to
1372 * the firmware -- doesn't have to constantly do these checks.
1378 iconf = adapter->params.tp.ingress_config;
1379 if (iconf & VNIC_F) {
1380 f->fs.val.ovlan = (fs->val.pf << 13) | fs->val.vf;
1381 f->fs.mask.ovlan = (fs->mask.pf << 13) | fs->mask.vf;
1382 f->fs.val.ovlan_vld = fs->val.pfvf_vld;
1383 f->fs.mask.ovlan_vld = fs->mask.pfvf_vld;
1384 } else if (iconf & USE_ENC_IDX_F) {
1385 if (f->fs.val.encap_vld) {
1386 struct port_info *pi = netdev_priv(f->dev);
1387 u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
1389 /* allocate MPS TCAM entry */
1390 ret = t4_alloc_encap_mac_filt(adapter, pi->viid,
1399 atomic_inc(&adapter->mps_encap[ret].refcnt);
1400 f->fs.val.ovlan = ret;
1401 f->fs.mask.ovlan = 0x1ff;
1402 f->fs.val.ovlan_vld = 1;
1403 f->fs.mask.ovlan_vld = 1;
1407 /* Attempt to set the filter. If we don't succeed, we clear
1408 * it and return the failure.
1411 f->tid = fidx; /* Save the actual tid */
1412 ret = set_filter_wr(adapter, filter_id);
1414 cxgb4_clear_ftid(&adapter->tids, filter_id,
1415 fs->type ? PF_INET6 : PF_INET,
1417 clear_filter(adapter, f);
1423 if (is_t6(adapter->params.chip) && f->fs.type)
1424 cxgb4_clip_release(f->dev, (const u32 *)&f->fs.val.lip, 1);
1425 cxgb4_clear_ftid(&adapter->tids, filter_id,
1426 fs->type ? PF_INET6 : PF_INET, chip_ver);
1430 static int cxgb4_del_hash_filter(struct net_device *dev, int filter_id,
1431 struct filter_ctx *ctx)
1433 struct adapter *adapter = netdev2adap(dev);
1434 struct tid_info *t = &adapter->tids;
1435 struct cpl_abort_req *abort_req;
1436 struct cpl_abort_rpl *abort_rpl;
1437 struct cpl_set_tcb_field *req;
1438 struct ulptx_idata *aligner;
1439 struct work_request_hdr *wr;
1440 struct filter_entry *f;
1441 struct sk_buff *skb;
1445 netdev_dbg(dev, "%s: filter_id = %d ; nftids = %d\n",
1446 __func__, filter_id, adapter->tids.nftids);
1448 if (filter_id > adapter->tids.ntids)
1451 f = lookup_tid(t, filter_id);
1453 netdev_err(dev, "%s: no filter entry for filter_id = %d",
1454 __func__, filter_id);
1458 ret = writable_filter(f);
1467 wrlen = roundup(sizeof(*wr) + (sizeof(*req) + sizeof(*aligner))
1468 + sizeof(*abort_req) + sizeof(*abort_rpl), 16);
1469 skb = alloc_skb(wrlen, GFP_KERNEL);
1471 netdev_err(dev, "%s: could not allocate skb ..\n", __func__);
1474 set_wr_txq(skb, CPL_PRIORITY_CONTROL, f->fs.val.iport & 0x3);
1475 req = (struct cpl_set_tcb_field *)__skb_put(skb, wrlen);
1476 INIT_ULPTX_WR(req, wrlen, 0, 0);
1477 wr = (struct work_request_hdr *)req;
1479 req = (struct cpl_set_tcb_field *)wr;
1480 mk_set_tcb_ulp(f, req, TCB_RSS_INFO_W, TCB_RSS_INFO_V(TCB_RSS_INFO_M),
1481 TCB_RSS_INFO_V(adapter->sge.fw_evtq.abs_id), 0, 1);
1482 aligner = (struct ulptx_idata *)(req + 1);
1483 abort_req = (struct cpl_abort_req *)(aligner + 1);
1484 mk_abort_req_ulp(abort_req, f->tid);
1485 abort_rpl = (struct cpl_abort_rpl *)(abort_req + 1);
1486 mk_abort_rpl_ulp(abort_rpl, f->tid);
1487 t4_ofld_send(adapter, skb);
1491 /* Check a delete filter request for validity and send it to the hardware.
1492 * Return 0 on success, an error number otherwise. We attach any provided
1493 * filter operation context to the internal filter specification in order to
1494 * facilitate signaling completion of the operation.
1496 int __cxgb4_del_filter(struct net_device *dev, int filter_id,
1497 struct ch_filter_specification *fs,
1498 struct filter_ctx *ctx)
1500 struct adapter *adapter = netdev2adap(dev);
1501 unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
1502 struct filter_entry *f;
1503 unsigned int max_fidx;
1506 if (fs && fs->hash) {
1507 if (is_hashfilter(adapter))
1508 return cxgb4_del_hash_filter(dev, filter_id, ctx);
1509 netdev_err(dev, "%s: Exact-match filters only supported with Hash Filter configuration\n",
1514 max_fidx = adapter->tids.nftids;
1515 if (filter_id != (max_fidx + adapter->tids.nsftids - 1) &&
1516 filter_id >= max_fidx)
1519 f = &adapter->tids.ftid_tab[filter_id];
1520 ret = writable_filter(f);
1526 cxgb4_clear_ftid(&adapter->tids, filter_id,
1527 f->fs.type ? PF_INET6 : PF_INET,
1529 return del_filter_wr(adapter, filter_id);
1532 /* If the caller has passed in a Completion Context then we need to
1533 * mark it as a successful completion so they don't stall waiting
1538 complete(&ctx->completion);
1543 int cxgb4_set_filter(struct net_device *dev, int filter_id,
1544 struct ch_filter_specification *fs)
1546 struct filter_ctx ctx;
1549 init_completion(&ctx.completion);
1551 ret = __cxgb4_set_filter(dev, filter_id, fs, &ctx);
1555 /* Wait for reply */
1556 ret = wait_for_completion_timeout(&ctx.completion, 10 * HZ);
1565 int cxgb4_del_filter(struct net_device *dev, int filter_id,
1566 struct ch_filter_specification *fs)
1568 struct filter_ctx ctx;
1571 /* If we are shutting down the adapter do not wait for completion */
1572 if (netdev2adap(dev)->flags & SHUTTING_DOWN)
1573 return __cxgb4_del_filter(dev, filter_id, fs, NULL);
1575 init_completion(&ctx.completion);
1577 ret = __cxgb4_del_filter(dev, filter_id, fs, &ctx);
1581 /* Wait for reply */
1582 ret = wait_for_completion_timeout(&ctx.completion, 10 * HZ);
1591 static int configure_filter_tcb(struct adapter *adap, unsigned int tid,
1592 struct filter_entry *f)
1595 set_tcb_field(adap, f, tid, TCB_TIMESTAMP_W,
1596 TCB_TIMESTAMP_V(TCB_TIMESTAMP_M) |
1597 TCB_RTT_TS_RECENT_AGE_V(TCB_RTT_TS_RECENT_AGE_M),
1598 TCB_TIMESTAMP_V(0ULL) |
1599 TCB_RTT_TS_RECENT_AGE_V(0ULL),
1603 set_tcb_tflag(adap, f, tid, TF_CCTRL_ECE_S, 1,
1606 if (f->fs.newvlan == VLAN_INSERT ||
1607 f->fs.newvlan == VLAN_REWRITE)
1608 set_tcb_tflag(adap, f, tid, TF_CCTRL_RFR_S, 1,
1611 configure_filter_smac(adap, f);
1613 if (f->fs.nat_mode) {
1614 switch (f->fs.nat_mode) {
1616 set_nat_params(adap, f, tid, true, false, false, false);
1619 case NAT_MODE_DIP_DP:
1620 set_nat_params(adap, f, tid, true, false, true, false);
1623 case NAT_MODE_DIP_DP_SIP:
1624 set_nat_params(adap, f, tid, true, true, true, false);
1626 case NAT_MODE_DIP_DP_SP:
1627 set_nat_params(adap, f, tid, true, false, true, true);
1630 case NAT_MODE_SIP_SP:
1631 set_nat_params(adap, f, tid, false, true, false, true);
1634 case NAT_MODE_DIP_SIP_SP:
1635 set_nat_params(adap, f, tid, true, true, false, true);
1639 set_nat_params(adap, f, tid, true, true, true, true);
1643 pr_err("%s: Invalid NAT mode: %d\n",
1644 __func__, f->fs.nat_mode);
1651 void hash_del_filter_rpl(struct adapter *adap,
1652 const struct cpl_abort_rpl_rss *rpl)
1654 unsigned int status = rpl->status;
1655 struct tid_info *t = &adap->tids;
1656 unsigned int tid = GET_TID(rpl);
1657 struct filter_ctx *ctx = NULL;
1658 struct filter_entry *f;
1660 dev_dbg(adap->pdev_dev, "%s: status = %u; tid = %u\n",
1661 __func__, status, tid);
1663 f = lookup_tid(t, tid);
1665 dev_err(adap->pdev_dev, "%s:could not find filter entry",
1671 clear_filter(adap, f);
1672 cxgb4_remove_tid(t, 0, tid, 0);
1676 complete(&ctx->completion);
1680 void hash_filter_rpl(struct adapter *adap, const struct cpl_act_open_rpl *rpl)
1682 unsigned int ftid = TID_TID_G(AOPEN_ATID_G(ntohl(rpl->atid_status)));
1683 unsigned int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
1684 struct tid_info *t = &adap->tids;
1685 unsigned int tid = GET_TID(rpl);
1686 struct filter_ctx *ctx = NULL;
1687 struct filter_entry *f;
1689 dev_dbg(adap->pdev_dev, "%s: tid = %u; atid = %u; status = %u\n",
1690 __func__, tid, ftid, status);
1692 f = lookup_atid(t, ftid);
1694 dev_err(adap->pdev_dev, "%s:could not find filter entry",
1706 cxgb4_insert_tid(t, f, f->tid, 0);
1707 cxgb4_free_atid(t, ftid);
1712 if (configure_filter_tcb(adap, tid, f)) {
1713 clear_filter(adap, f);
1714 cxgb4_remove_tid(t, 0, tid, 0);
1717 ctx->result = -EINVAL;
1718 complete(&ctx->completion);
1725 dev_err(adap->pdev_dev, "%s: filter creation PROBLEM; status = %u\n",
1729 if (status == CPL_ERR_TCAM_FULL)
1730 ctx->result = -EAGAIN;
1732 ctx->result = -EINVAL;
1734 clear_filter(adap, f);
1735 cxgb4_free_atid(t, ftid);
1739 complete(&ctx->completion);
1742 /* Handle a filter write/deletion reply. */
1743 void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
1745 unsigned int tid = GET_TID(rpl);
1746 struct filter_entry *f = NULL;
1747 unsigned int max_fidx;
1750 max_fidx = adap->tids.nftids + adap->tids.nsftids;
1751 /* Get the corresponding filter entry for this tid */
1752 if (adap->tids.ftid_tab) {
1753 /* Check this in normal filter region */
1754 idx = tid - adap->tids.ftid_base;
1755 if (idx >= max_fidx)
1757 f = &adap->tids.ftid_tab[idx];
1762 /* We found the filter entry for this tid */
1764 unsigned int ret = TCB_COOKIE_G(rpl->cookie);
1765 struct filter_ctx *ctx;
1767 /* Pull off any filter operation context attached to the
1773 if (ret == FW_FILTER_WR_FLT_DELETED) {
1774 /* Clear the filter when we get confirmation from the
1775 * hardware that the filter has been deleted.
1777 clear_filter(adap, f);
1780 } else if (ret == FW_FILTER_WR_FLT_ADDED) {
1784 err = configure_filter_smac(adap, f);
1787 f->pending = 0; /* async setup completed */
1794 clear_filter(adap, f);
1799 /* Something went wrong. Issue a warning about the
1800 * problem and clear everything out.
1802 dev_err(adap->pdev_dev, "filter %u setup failed with error %u\n",
1804 clear_filter(adap, f);
1806 ctx->result = -EINVAL;
1809 complete(&ctx->completion);
1813 int init_hash_filter(struct adapter *adap)
1815 /* On T6, verify the necessary register configs and warn the user in
1816 * case of improper config
1818 if (is_t6(adap->params.chip)) {
1819 if (TCAM_ACTV_HIT_G(t4_read_reg(adap, LE_DB_RSP_CODE_0_A)) != 4)
1822 if (HASH_ACTV_HIT_G(t4_read_reg(adap, LE_DB_RSP_CODE_1_A)) != 4)
1825 dev_err(adap->pdev_dev, "Hash filter supported only on T6\n");
1828 adap->params.hash_filter = 1;
1831 dev_warn(adap->pdev_dev, "Invalid hash filter config!\n");