1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Chelsio Communications.
8 #include "cxgbe_filter.h"
12 * Initialize Hash Filters
14 int init_hash_filter(struct adapter *adap)
16 unsigned int n_user_filters;
17 unsigned int user_filter_perc;
19 u32 params[7], val[7];
21 #define FW_PARAM_DEV(param) \
22 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
23 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
25 #define FW_PARAM_PFVF(param) \
26 (V_FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
27 V_FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param) | \
28 V_FW_PARAMS_PARAM_Y(0) | \
29 V_FW_PARAMS_PARAM_Z(0))
31 params[0] = FW_PARAM_DEV(NTID);
32 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
36 adap->tids.ntids = val[0];
37 adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
39 user_filter_perc = 100;
40 n_user_filters = mult_frac(adap->tids.nftids,
44 adap->tids.nftids = n_user_filters;
45 adap->params.hash_filter = 1;
50 * Validate if the requested filter specification can be set by checking
51 * if the requested features have been enabled
53 int validate_filter(struct adapter *adapter, struct ch_filter_specification *fs)
58 * Check for unconfigured fields being used.
60 fconf = adapter->params.tp.vlan_pri_map;
63 (fs->val._field || fs->mask._field)
64 #define U(_mask, _field) \
65 (!(fconf & (_mask)) && S(_field))
67 if (U(F_ETHERTYPE, ethtype) || U(F_PROTOCOL, proto))
76 * Get the queue to which the traffic must be steered to.
78 static unsigned int get_filter_steerq(struct rte_eth_dev *dev,
79 struct ch_filter_specification *fs)
81 struct port_info *pi = ethdev2pinfo(dev);
82 struct adapter *adapter = pi->adapter;
86 * If the user has requested steering matching Ingress Packets
87 * to a specific Queue Set, we need to make sure it's in range
88 * for the port and map that into the Absolute Queue ID of the
89 * Queue Set's Response Queue.
95 * If the iq id is greater than the number of qsets,
96 * then assume it is an absolute qid.
98 if (fs->iq < pi->n_rx_qsets)
99 iq = adapter->sge.ethrxq[pi->first_qset +
108 /* Return an error number if the indicated filter isn't writable ... */
109 int writable_filter(struct filter_entry *f)
120 * Check if entry already filled.
122 bool is_filter_set(struct tid_info *t, int fidx, int family)
127 /* IPv6 requires four slots and IPv4 requires only 1 slot.
128 * Ensure, there's enough slots available.
130 max = family == FILTER_TYPE_IPV6 ? fidx + 3 : fidx;
132 t4_os_lock(&t->ftid_lock);
133 for (i = fidx; i <= max; i++) {
134 if (rte_bitmap_get(t->ftid_bmap, i)) {
139 t4_os_unlock(&t->ftid_lock);
144 * Allocate a available free entry
146 int cxgbe_alloc_ftid(struct adapter *adap, unsigned int family)
148 struct tid_info *t = &adap->tids;
150 int size = t->nftids;
152 t4_os_lock(&t->ftid_lock);
153 if (family == FILTER_TYPE_IPV6)
154 pos = cxgbe_bitmap_find_free_region(t->ftid_bmap, size, 4);
156 pos = cxgbe_find_first_zero_bit(t->ftid_bmap, size);
157 t4_os_unlock(&t->ftid_lock);
159 return pos < size ? pos : -1;
163 * Construct hash filter ntuple.
165 static u64 hash_filter_ntuple(const struct filter_entry *f)
167 struct adapter *adap = ethdev2adap(f->dev);
168 struct tp_params *tp = &adap->params.tp;
170 u16 tcp_proto = IPPROTO_TCP; /* TCP Protocol Number */
172 if (tp->protocol_shift >= 0) {
173 if (!f->fs.val.proto)
174 ntuple |= (u64)tcp_proto << tp->protocol_shift;
176 ntuple |= (u64)f->fs.val.proto << tp->protocol_shift;
179 if (tp->ethertype_shift >= 0 && f->fs.mask.ethtype)
180 ntuple |= (u64)(f->fs.val.ethtype) << tp->ethertype_shift;
182 if (ntuple != tp->hash_filter_mask)
189 * Build a ACT_OPEN_REQ6 message for setting IPv6 hash filter.
191 static void mk_act_open_req6(struct filter_entry *f, struct rte_mbuf *mbuf,
192 unsigned int qid_filterid, struct adapter *adap)
194 struct cpl_t6_act_open_req6 *req = NULL;
195 u64 local_lo, local_hi, peer_lo, peer_hi;
196 u32 *lip = (u32 *)f->fs.val.lip;
197 u32 *fip = (u32 *)f->fs.val.fip;
199 switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
201 req = rte_pktmbuf_mtod(mbuf, struct cpl_t6_act_open_req6 *);
206 dev_err(adap, "%s: unsupported chip type!\n", __func__);
210 local_hi = ((u64)lip[1]) << 32 | lip[0];
211 local_lo = ((u64)lip[3]) << 32 | lip[2];
212 peer_hi = ((u64)fip[1]) << 32 | fip[0];
213 peer_lo = ((u64)fip[3]) << 32 | fip[2];
215 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
217 req->local_port = cpu_to_be16(f->fs.val.lport);
218 req->peer_port = cpu_to_be16(f->fs.val.fport);
219 req->local_ip_hi = local_hi;
220 req->local_ip_lo = local_lo;
221 req->peer_ip_hi = peer_hi;
222 req->peer_ip_lo = peer_lo;
223 req->opt0 = cpu_to_be64(V_DELACK(f->fs.hitcnts) |
224 V_SMAC_SEL((cxgbe_port_viid(f->dev) & 0x7F)
226 V_ULP_MODE(ULP_MODE_NONE) |
227 F_TCAM_BYPASS | F_NON_OFFLOAD);
228 req->params = cpu_to_be64(V_FILTER_TUPLE(hash_filter_ntuple(f)));
229 req->opt2 = cpu_to_be32(F_RSS_QUEUE_VALID |
230 V_RSS_QUEUE(f->fs.iq) |
233 V_CONG_CNTRL((f->fs.action == FILTER_DROP) |
234 (f->fs.dirsteer << 1)));
238 * Build a ACT_OPEN_REQ message for setting IPv4 hash filter.
240 static void mk_act_open_req(struct filter_entry *f, struct rte_mbuf *mbuf,
241 unsigned int qid_filterid, struct adapter *adap)
243 struct cpl_t6_act_open_req *req = NULL;
245 switch (CHELSIO_CHIP_VERSION(adap->params.chip)) {
247 req = rte_pktmbuf_mtod(mbuf, struct cpl_t6_act_open_req *);
252 dev_err(adap, "%s: unsupported chip type!\n", __func__);
256 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
258 req->local_port = cpu_to_be16(f->fs.val.lport);
259 req->peer_port = cpu_to_be16(f->fs.val.fport);
260 req->local_ip = f->fs.val.lip[0] | f->fs.val.lip[1] << 8 |
261 f->fs.val.lip[2] << 16 | f->fs.val.lip[3] << 24;
262 req->peer_ip = f->fs.val.fip[0] | f->fs.val.fip[1] << 8 |
263 f->fs.val.fip[2] << 16 | f->fs.val.fip[3] << 24;
264 req->opt0 = cpu_to_be64(V_DELACK(f->fs.hitcnts) |
265 V_SMAC_SEL((cxgbe_port_viid(f->dev) & 0x7F)
267 V_ULP_MODE(ULP_MODE_NONE) |
268 F_TCAM_BYPASS | F_NON_OFFLOAD);
269 req->params = cpu_to_be64(V_FILTER_TUPLE(hash_filter_ntuple(f)));
270 req->opt2 = cpu_to_be32(F_RSS_QUEUE_VALID |
271 V_RSS_QUEUE(f->fs.iq) |
274 V_CONG_CNTRL((f->fs.action == FILTER_DROP) |
275 (f->fs.dirsteer << 1)));
279 * Set the specified hash filter.
281 static int cxgbe_set_hash_filter(struct rte_eth_dev *dev,
282 struct ch_filter_specification *fs,
283 struct filter_ctx *ctx)
285 struct port_info *pi = ethdev2pinfo(dev);
286 struct adapter *adapter = pi->adapter;
287 struct tid_info *t = &adapter->tids;
288 struct filter_entry *f;
289 struct rte_mbuf *mbuf;
290 struct sge_ctrl_txq *ctrlq;
295 ret = validate_filter(adapter, fs);
299 iq = get_filter_steerq(dev, fs);
301 ctrlq = &adapter->sge.ctrlq[pi->port_id];
303 f = t4_os_alloc(sizeof(*f));
312 atid = cxgbe_alloc_atid(t, f);
317 /* IPv6 hash filter */
318 f->clipt = cxgbe_clip_alloc(f->dev, (u32 *)&f->fs.val.lip);
322 size = sizeof(struct cpl_t6_act_open_req6);
323 mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool);
329 mbuf->data_len = size;
330 mbuf->pkt_len = mbuf->data_len;
332 mk_act_open_req6(f, mbuf,
333 ((adapter->sge.fw_evtq.abs_id << 14) | atid),
336 /* IPv4 hash filter */
337 size = sizeof(struct cpl_t6_act_open_req);
338 mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool);
344 mbuf->data_len = size;
345 mbuf->pkt_len = mbuf->data_len;
347 mk_act_open_req(f, mbuf,
348 ((adapter->sge.fw_evtq.abs_id << 14) | atid),
353 t4_mgmt_tx(ctrlq, mbuf);
357 cxgbe_clip_release(f->dev, f->clipt);
359 cxgbe_free_atid(t, atid);
367 * Clear a filter and release any of its resources that we own. This also
368 * clears the filter's "pending" status.
370 void clear_filter(struct filter_entry *f)
373 cxgbe_clip_release(f->dev, f->clipt);
376 * The zeroing of the filter rule below clears the filter valid,
377 * pending, locked flags etc. so it's all we need for
380 memset(f, 0, sizeof(*f));
384 * t4_mk_filtdelwr - create a delete filter WR
385 * @ftid: the filter ID
386 * @wr: the filter work request to populate
387 * @qid: ingress queue to receive the delete notification
389 * Creates a filter work request to delete the supplied filter. If @qid is
390 * negative the delete notification is suppressed.
392 static void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid)
394 memset(wr, 0, sizeof(*wr));
395 wr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
396 wr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*wr) / 16));
397 wr->tid_to_iq = cpu_to_be32(V_FW_FILTER_WR_TID(ftid) |
398 V_FW_FILTER_WR_NOREPLY(qid < 0));
399 wr->del_filter_to_l2tix = cpu_to_be32(F_FW_FILTER_WR_DEL_FILTER);
401 wr->rx_chan_rx_rpl_iq =
402 cpu_to_be16(V_FW_FILTER_WR_RX_RPL_IQ(qid));
406 * Create FW work request to delete the filter at a specified index
408 static int del_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
410 struct adapter *adapter = ethdev2adap(dev);
411 struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
412 struct rte_mbuf *mbuf;
413 struct fw_filter_wr *fwr;
414 struct sge_ctrl_txq *ctrlq;
415 unsigned int port_id = ethdev2pinfo(dev)->port_id;
417 ctrlq = &adapter->sge.ctrlq[port_id];
418 mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool);
422 mbuf->data_len = sizeof(*fwr);
423 mbuf->pkt_len = mbuf->data_len;
425 fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter_wr *);
426 t4_mk_filtdelwr(f->tid, fwr, adapter->sge.fw_evtq.abs_id);
429 * Mark the filter as "pending" and ship off the Filter Work Request.
430 * When we get the Work Request Reply we'll clear the pending status.
433 t4_mgmt_tx(ctrlq, mbuf);
437 int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx)
439 struct adapter *adapter = ethdev2adap(dev);
440 struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
441 struct rte_mbuf *mbuf;
442 struct fw_filter_wr *fwr;
443 struct sge_ctrl_txq *ctrlq;
444 unsigned int port_id = ethdev2pinfo(dev)->port_id;
447 ctrlq = &adapter->sge.ctrlq[port_id];
448 mbuf = rte_pktmbuf_alloc(ctrlq->mb_pool);
454 mbuf->data_len = sizeof(*fwr);
455 mbuf->pkt_len = mbuf->data_len;
457 fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter_wr *);
458 memset(fwr, 0, sizeof(*fwr));
461 * Construct the work request to set the filter.
463 fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR));
464 fwr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*fwr) / 16));
466 cpu_to_be32(V_FW_FILTER_WR_TID(f->tid) |
467 V_FW_FILTER_WR_RQTYPE(f->fs.type) |
468 V_FW_FILTER_WR_NOREPLY(0) |
469 V_FW_FILTER_WR_IQ(f->fs.iq));
470 fwr->del_filter_to_l2tix =
471 cpu_to_be32(V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) |
472 V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) |
473 V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) |
474 V_FW_FILTER_WR_PRIO(f->fs.prio));
475 fwr->ethtype = cpu_to_be16(f->fs.val.ethtype);
476 fwr->ethtypem = cpu_to_be16(f->fs.mask.ethtype);
478 fwr->rx_chan_rx_rpl_iq =
479 cpu_to_be16(V_FW_FILTER_WR_RX_CHAN(0) |
480 V_FW_FILTER_WR_RX_RPL_IQ(adapter->sge.fw_evtq.abs_id
482 fwr->ptcl = f->fs.val.proto;
483 fwr->ptclm = f->fs.mask.proto;
484 rte_memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip));
485 rte_memcpy(fwr->lipm, f->fs.mask.lip, sizeof(fwr->lipm));
486 rte_memcpy(fwr->fip, f->fs.val.fip, sizeof(fwr->fip));
487 rte_memcpy(fwr->fipm, f->fs.mask.fip, sizeof(fwr->fipm));
488 fwr->lp = cpu_to_be16(f->fs.val.lport);
489 fwr->lpm = cpu_to_be16(f->fs.mask.lport);
490 fwr->fp = cpu_to_be16(f->fs.val.fport);
491 fwr->fpm = cpu_to_be16(f->fs.mask.fport);
494 * Mark the filter as "pending" and ship off the Filter Work Request.
495 * When we get the Work Request Reply we'll clear the pending status.
498 t4_mgmt_tx(ctrlq, mbuf);
506 * Set the corresponding entry in the bitmap. 4 slots are
507 * marked for IPv6, whereas only 1 slot is marked for IPv4.
509 static int cxgbe_set_ftid(struct tid_info *t, int fidx, int family)
511 t4_os_lock(&t->ftid_lock);
512 if (rte_bitmap_get(t->ftid_bmap, fidx)) {
513 t4_os_unlock(&t->ftid_lock);
517 if (family == FILTER_TYPE_IPV4) {
518 rte_bitmap_set(t->ftid_bmap, fidx);
520 rte_bitmap_set(t->ftid_bmap, fidx);
521 rte_bitmap_set(t->ftid_bmap, fidx + 1);
522 rte_bitmap_set(t->ftid_bmap, fidx + 2);
523 rte_bitmap_set(t->ftid_bmap, fidx + 3);
525 t4_os_unlock(&t->ftid_lock);
530 * Clear the corresponding entry in the bitmap. 4 slots are
531 * cleared for IPv6, whereas only 1 slot is cleared for IPv4.
533 static void cxgbe_clear_ftid(struct tid_info *t, int fidx, int family)
535 t4_os_lock(&t->ftid_lock);
536 if (family == FILTER_TYPE_IPV4) {
537 rte_bitmap_clear(t->ftid_bmap, fidx);
539 rte_bitmap_clear(t->ftid_bmap, fidx);
540 rte_bitmap_clear(t->ftid_bmap, fidx + 1);
541 rte_bitmap_clear(t->ftid_bmap, fidx + 2);
542 rte_bitmap_clear(t->ftid_bmap, fidx + 3);
544 t4_os_unlock(&t->ftid_lock);
548 * Check a delete filter request for validity and send it to the hardware.
549 * Return 0 on success, an error number otherwise. We attach any provided
550 * filter operation context to the internal filter specification in order to
551 * facilitate signaling completion of the operation.
553 int cxgbe_del_filter(struct rte_eth_dev *dev, unsigned int filter_id,
554 struct ch_filter_specification *fs,
555 struct filter_ctx *ctx)
557 struct port_info *pi = (struct port_info *)(dev->data->dev_private);
558 struct adapter *adapter = pi->adapter;
559 struct filter_entry *f;
560 unsigned int chip_ver;
563 if (filter_id >= adapter->tids.nftids)
566 chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
568 ret = is_filter_set(&adapter->tids, filter_id, fs->type);
570 dev_warn(adap, "%s: could not find filter entry: %u\n",
571 __func__, filter_id);
576 * Ensure filter id is aligned on the 2 slot boundary for T6,
577 * and 4 slot boundary for cards below T6.
580 if (chip_ver < CHELSIO_T6)
586 f = &adapter->tids.ftid_tab[filter_id];
587 ret = writable_filter(f);
593 cxgbe_clear_ftid(&adapter->tids,
594 f->tid - adapter->tids.ftid_base,
595 f->fs.type ? FILTER_TYPE_IPV6 :
597 return del_filter_wr(dev, filter_id);
601 * If the caller has passed in a Completion Context then we need to
602 * mark it as a successful completion so they don't stall waiting
607 t4_complete(&ctx->completion);
614 * Check a Chelsio Filter Request for validity, convert it into our internal
615 * format and send it to the hardware. Return 0 on success, an error number
616 * otherwise. We attach any provided filter operation context to the internal
617 * filter specification in order to facilitate signaling completion of the
620 int cxgbe_set_filter(struct rte_eth_dev *dev, unsigned int filter_id,
621 struct ch_filter_specification *fs,
622 struct filter_ctx *ctx)
624 struct port_info *pi = ethdev2pinfo(dev);
625 struct adapter *adapter = pi->adapter;
626 unsigned int fidx, iq, fid_bit = 0;
627 struct filter_entry *f;
628 unsigned int chip_ver;
629 uint8_t bitoff[16] = {0};
632 if (is_hashfilter(adapter) && fs->cap)
633 return cxgbe_set_hash_filter(dev, fs, ctx);
635 if (filter_id >= adapter->tids.nftids)
638 chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
640 ret = validate_filter(adapter, fs);
645 * Ensure filter id is aligned on the 4 slot boundary for IPv6
651 ret = is_filter_set(&adapter->tids, filter_id, fs->type);
655 iq = get_filter_steerq(dev, fs);
658 * IPv6 filters occupy four slots and must be aligned on four-slot
659 * boundaries for T5. On T6, IPv6 filters occupy two-slots and
660 * must be aligned on two-slot boundaries.
662 * IPv4 filters only occupy a single slot and have no alignment
663 * requirements but writing a new IPv4 filter into the middle
664 * of an existing IPv6 filter requires clearing the old IPv6
667 if (fs->type == FILTER_TYPE_IPV4) { /* IPv4 */
669 * For T6, If our IPv4 filter isn't being written to a
670 * multiple of two filter index and there's an IPv6
671 * filter at the multiple of 2 base slot, then we need
672 * to delete that IPv6 filter ...
673 * For adapters below T6, IPv6 filter occupies 4 entries.
675 if (chip_ver < CHELSIO_T6)
676 fidx = filter_id & ~0x3;
678 fidx = filter_id & ~0x1;
680 if (fidx != filter_id && adapter->tids.ftid_tab[fidx].fs.type) {
681 f = &adapter->tids.ftid_tab[fidx];
686 unsigned int max_filter_id;
688 if (chip_ver < CHELSIO_T6) {
690 * Ensure that the IPv6 filter is aligned on a
691 * multiple of 4 boundary.
696 max_filter_id = filter_id + 4;
699 * For T6, CLIP being enabled, IPv6 filter would occupy
705 max_filter_id = filter_id + 2;
709 * Check all except the base overlapping IPv4 filter
712 for (fidx = filter_id + 1; fidx < max_filter_id; fidx++) {
713 f = &adapter->tids.ftid_tab[fidx];
720 * Check to make sure that provided filter index is not
721 * already in use by someone else
723 f = &adapter->tids.ftid_tab[filter_id];
727 fidx = adapter->tids.ftid_base + filter_id;
729 ret = cxgbe_set_ftid(&adapter->tids, fid_bit,
730 fs->type ? FILTER_TYPE_IPV6 : FILTER_TYPE_IPV4);
735 * Check to make sure the filter requested is writable ...
737 ret = writable_filter(f);
739 /* Clear the bits we have set above */
740 cxgbe_clear_ftid(&adapter->tids, fid_bit,
741 fs->type ? FILTER_TYPE_IPV6 :
747 * Allocate a clip table entry only if we have non-zero IPv6 address
749 if (chip_ver > CHELSIO_T5 && fs->type &&
750 memcmp(fs->val.lip, bitoff, sizeof(bitoff))) {
751 f->clipt = cxgbe_clip_alloc(f->dev, (u32 *)&f->fs.val.lip);
757 * Convert the filter specification into our internal format.
758 * We copy the PF/VF specification into the Outer VLAN field
759 * here so the rest of the code -- including the interface to
760 * the firmware -- doesn't have to constantly do these checks.
767 * Attempt to set the filter. If we don't succeed, we clear
768 * it and return the failure.
771 f->tid = fidx; /* Save the actual tid */
772 ret = set_filter_wr(dev, filter_id);
774 fid_bit = f->tid - adapter->tids.ftid_base;
781 cxgbe_clear_ftid(&adapter->tids, fid_bit,
782 fs->type ? FILTER_TYPE_IPV6 :
789 * Handle a Hash filter write reply.
791 void hash_filter_rpl(struct adapter *adap, const struct cpl_act_open_rpl *rpl)
793 struct tid_info *t = &adap->tids;
794 struct filter_entry *f;
795 struct filter_ctx *ctx = NULL;
796 unsigned int tid = GET_TID(rpl);
797 unsigned int ftid = G_TID_TID(G_AOPEN_ATID
798 (be32_to_cpu(rpl->atid_status)));
799 unsigned int status = G_AOPEN_STATUS(be32_to_cpu(rpl->atid_status));
801 f = lookup_atid(t, ftid);
803 dev_warn(adap, "%s: could not find filter entry: %d\n",
814 f->pending = 0; /* asynchronous setup completed */
817 cxgbe_insert_tid(t, f, f->tid, 0);
818 cxgbe_free_atid(t, ftid);
826 dev_warn(adap, "%s: filter creation failed with status = %u\n",
830 if (status == CPL_ERR_TCAM_FULL)
831 ctx->result = -EAGAIN;
833 ctx->result = -EINVAL;
836 cxgbe_free_atid(t, ftid);
841 t4_complete(&ctx->completion);
845 * Handle a LE-TCAM filter write/deletion reply.
847 void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
849 struct filter_entry *f = NULL;
850 unsigned int tid = GET_TID(rpl);
851 int idx, max_fidx = adap->tids.nftids;
853 /* Get the corresponding filter entry for this tid */
854 if (adap->tids.ftid_tab) {
855 /* Check this in normal filter region */
856 idx = tid - adap->tids.ftid_base;
860 f = &adap->tids.ftid_tab[idx];
865 /* We found the filter entry for this tid */
867 unsigned int ret = G_COOKIE(rpl->cookie);
868 struct filter_ctx *ctx;
871 * Pull off any filter operation context attached to the
877 if (ret == FW_FILTER_WR_FLT_ADDED) {
878 f->pending = 0; /* asynchronous setup completed */
884 } else if (ret == FW_FILTER_WR_FLT_DELETED) {
886 * Clear the filter when we get confirmation from the
887 * hardware that the filter has been deleted.
894 * Something went wrong. Issue a warning about the
895 * problem and clear everything out.
897 dev_warn(adap, "filter %u setup failed with error %u\n",
901 ctx->result = -EINVAL;
905 t4_complete(&ctx->completion);
910 * Retrieve the packet count for the specified filter.
912 int cxgbe_get_filter_count(struct adapter *adapter, unsigned int fidx,
913 u64 *c, bool get_byte)
915 struct filter_entry *f;
916 unsigned int tcb_base, tcbaddr;
919 tcb_base = t4_read_reg(adapter, A_TP_CMM_TCB_BASE);
920 if (fidx >= adapter->tids.nftids)
923 f = &adapter->tids.ftid_tab[fidx];
927 tcbaddr = tcb_base + f->tid * TCB_SIZE;
929 if (is_t5(adapter->params.chip) || is_t6(adapter->params.chip)) {
931 * For T5, the Filter Packet Hit Count is maintained as a
932 * 32-bit Big Endian value in the TCB field {timestamp}.
933 * Similar to the craziness above, instead of the filter hit
934 * count showing up at offset 20 ((W_TCB_TIMESTAMP == 5) *
935 * sizeof(u32)), it actually shows up at offset 24. Whacky.
938 unsigned int word_offset = 4;
939 __be64 be64_byte_count;
941 t4_os_lock(&adapter->win0_lock);
942 ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
944 (word_offset * sizeof(__be32)),
945 sizeof(be64_byte_count),
948 t4_os_unlock(&adapter->win0_lock);
951 *c = be64_to_cpu(be64_byte_count);
953 unsigned int word_offset = 6;
956 t4_os_lock(&adapter->win0_lock);
957 ret = t4_memory_rw(adapter, MEMWIN_NIC, MEM_EDC0,
959 (word_offset * sizeof(__be32)),
960 sizeof(be32_count), &be32_count,
962 t4_os_unlock(&adapter->win0_lock);
965 *c = (u64)be32_to_cpu(be32_count);