1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Chelsio Communications.
6 #include "cxgbe_flow.h"
8 #define __CXGBE_FILL_FS(__v, __m, fs, elem, e) \
10 if (!((fs)->val.elem || (fs)->mask.elem)) { \
11 (fs)->val.elem = (__v); \
12 (fs)->mask.elem = (__m); \
14 return rte_flow_error_set(e, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM, \
15 NULL, "a filter can be specified" \
20 #define __CXGBE_FILL_FS_MEMCPY(__v, __m, fs, elem) \
22 memcpy(&(fs)->val.elem, &(__v), sizeof(__v)); \
23 memcpy(&(fs)->mask.elem, &(__m), sizeof(__m)); \
26 #define CXGBE_FILL_FS(v, m, elem) \
27 __CXGBE_FILL_FS(v, m, fs, elem, e)
29 #define CXGBE_FILL_FS_MEMCPY(v, m, elem) \
30 __CXGBE_FILL_FS_MEMCPY(v, m, fs, elem)
33 cxgbe_validate_item(const struct rte_flow_item *i, struct rte_flow_error *e)
35 /* rte_flow specification does not allow it. */
36 if (!i->spec && (i->mask || i->last))
37 return rte_flow_error_set(e, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
38 i, "last or mask given without spec");
40 * We don't support it.
41 * Although, we can support values in last as 0's or last == spec.
42 * But this will not provide user with any additional functionality
43 * and will only increase the complexity for us.
46 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
47 i, "last is not supported by chelsio pmd");
52 cxgbe_fill_filter_region(struct adapter *adap,
53 struct ch_filter_specification *fs)
55 struct tp_params *tp = &adap->params.tp;
56 u64 hash_filter_mask = tp->hash_filter_mask;
61 if (!is_hashfilter(adap))
65 uint8_t biton[16] = {0xff, 0xff, 0xff, 0xff,
66 0xff, 0xff, 0xff, 0xff,
67 0xff, 0xff, 0xff, 0xff,
68 0xff, 0xff, 0xff, 0xff};
69 uint8_t bitoff[16] = {0};
71 if (!memcmp(fs->val.lip, bitoff, sizeof(bitoff)) ||
72 !memcmp(fs->val.fip, bitoff, sizeof(bitoff)) ||
73 memcmp(fs->mask.lip, biton, sizeof(biton)) ||
74 memcmp(fs->mask.fip, biton, sizeof(biton)))
77 uint32_t biton = 0xffffffff;
78 uint32_t bitoff = 0x0U;
80 if (!memcmp(fs->val.lip, &bitoff, sizeof(bitoff)) ||
81 !memcmp(fs->val.fip, &bitoff, sizeof(bitoff)) ||
82 memcmp(fs->mask.lip, &biton, sizeof(biton)) ||
83 memcmp(fs->mask.fip, &biton, sizeof(biton)))
87 if (!fs->val.lport || fs->mask.lport != 0xffff)
89 if (!fs->val.fport || fs->mask.fport != 0xffff)
92 if (tp->protocol_shift >= 0)
93 ntuple_mask |= (u64)fs->mask.proto << tp->protocol_shift;
94 if (tp->ethertype_shift >= 0)
95 ntuple_mask |= (u64)fs->mask.ethtype << tp->ethertype_shift;
96 if (tp->port_shift >= 0)
97 ntuple_mask |= (u64)fs->mask.iport << tp->port_shift;
99 if (ntuple_mask != hash_filter_mask)
102 fs->cap = 1; /* use hash region */
106 ch_rte_parsetype_port(const void *dmask, const struct rte_flow_item *item,
107 struct ch_filter_specification *fs,
108 struct rte_flow_error *e)
110 const struct rte_flow_item_phy_port *val = item->spec;
111 const struct rte_flow_item_phy_port *umask = item->mask;
112 const struct rte_flow_item_phy_port *mask;
114 mask = umask ? umask : (const struct rte_flow_item_phy_port *)dmask;
116 if (val->index > 0x7)
117 return rte_flow_error_set(e, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
119 "port index upto 0x7 is supported");
121 CXGBE_FILL_FS(val->index, mask->index, iport);
127 ch_rte_parsetype_udp(const void *dmask, const struct rte_flow_item *item,
128 struct ch_filter_specification *fs,
129 struct rte_flow_error *e)
131 const struct rte_flow_item_udp *val = item->spec;
132 const struct rte_flow_item_udp *umask = item->mask;
133 const struct rte_flow_item_udp *mask;
135 mask = umask ? umask : (const struct rte_flow_item_udp *)dmask;
137 if (mask->hdr.dgram_len || mask->hdr.dgram_cksum)
138 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
140 "udp: only src/dst port supported");
142 CXGBE_FILL_FS(IPPROTO_UDP, 0xff, proto);
145 CXGBE_FILL_FS(be16_to_cpu(val->hdr.src_port),
146 be16_to_cpu(mask->hdr.src_port), fport);
147 CXGBE_FILL_FS(be16_to_cpu(val->hdr.dst_port),
148 be16_to_cpu(mask->hdr.dst_port), lport);
153 ch_rte_parsetype_tcp(const void *dmask, const struct rte_flow_item *item,
154 struct ch_filter_specification *fs,
155 struct rte_flow_error *e)
157 const struct rte_flow_item_tcp *val = item->spec;
158 const struct rte_flow_item_tcp *umask = item->mask;
159 const struct rte_flow_item_tcp *mask;
161 mask = umask ? umask : (const struct rte_flow_item_tcp *)dmask;
163 if (mask->hdr.sent_seq || mask->hdr.recv_ack || mask->hdr.data_off ||
164 mask->hdr.tcp_flags || mask->hdr.rx_win || mask->hdr.cksum ||
166 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
168 "tcp: only src/dst port supported");
170 CXGBE_FILL_FS(IPPROTO_TCP, 0xff, proto);
173 CXGBE_FILL_FS(be16_to_cpu(val->hdr.src_port),
174 be16_to_cpu(mask->hdr.src_port), fport);
175 CXGBE_FILL_FS(be16_to_cpu(val->hdr.dst_port),
176 be16_to_cpu(mask->hdr.dst_port), lport);
181 ch_rte_parsetype_ipv4(const void *dmask, const struct rte_flow_item *item,
182 struct ch_filter_specification *fs,
183 struct rte_flow_error *e)
185 const struct rte_flow_item_ipv4 *val = item->spec;
186 const struct rte_flow_item_ipv4 *umask = item->mask;
187 const struct rte_flow_item_ipv4 *mask;
189 mask = umask ? umask : (const struct rte_flow_item_ipv4 *)dmask;
191 if (mask->hdr.time_to_live || mask->hdr.type_of_service)
192 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
193 item, "ttl/tos are not supported");
195 fs->type = FILTER_TYPE_IPV4;
196 CXGBE_FILL_FS(ETHER_TYPE_IPv4, 0xffff, ethtype);
198 return 0; /* ipv4 wild card */
200 CXGBE_FILL_FS(val->hdr.next_proto_id, mask->hdr.next_proto_id, proto);
201 CXGBE_FILL_FS_MEMCPY(val->hdr.dst_addr, mask->hdr.dst_addr, lip);
202 CXGBE_FILL_FS_MEMCPY(val->hdr.src_addr, mask->hdr.src_addr, fip);
208 ch_rte_parsetype_ipv6(const void *dmask, const struct rte_flow_item *item,
209 struct ch_filter_specification *fs,
210 struct rte_flow_error *e)
212 const struct rte_flow_item_ipv6 *val = item->spec;
213 const struct rte_flow_item_ipv6 *umask = item->mask;
214 const struct rte_flow_item_ipv6 *mask;
216 mask = umask ? umask : (const struct rte_flow_item_ipv6 *)dmask;
218 if (mask->hdr.vtc_flow ||
219 mask->hdr.payload_len || mask->hdr.hop_limits)
220 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
222 "tc/flow/hop are not supported");
224 fs->type = FILTER_TYPE_IPV6;
225 CXGBE_FILL_FS(ETHER_TYPE_IPv6, 0xffff, ethtype);
227 return 0; /* ipv6 wild card */
229 CXGBE_FILL_FS(val->hdr.proto, mask->hdr.proto, proto);
230 CXGBE_FILL_FS_MEMCPY(val->hdr.dst_addr, mask->hdr.dst_addr, lip);
231 CXGBE_FILL_FS_MEMCPY(val->hdr.src_addr, mask->hdr.src_addr, fip);
237 cxgbe_rtef_parse_attr(struct rte_flow *flow, const struct rte_flow_attr *attr,
238 struct rte_flow_error *e)
241 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ATTR,
242 attr, "attribute:<egress> is"
245 return rte_flow_error_set(e, ENOTSUP, RTE_FLOW_ERROR_TYPE_ATTR,
246 attr, "group parameter is"
249 flow->fidx = attr->priority ? attr->priority - 1 : FILTER_ID_MAX;
254 static inline int check_rxq(struct rte_eth_dev *dev, uint16_t rxq)
256 struct port_info *pi = ethdev2pinfo(dev);
258 if (rxq > pi->n_rx_qsets)
263 static int cxgbe_validate_fidxondel(struct filter_entry *f, unsigned int fidx)
265 struct adapter *adap = ethdev2adap(f->dev);
266 struct ch_filter_specification fs = f->fs;
268 if (fidx >= adap->tids.nftids) {
269 dev_err(adap, "invalid flow index %d.\n", fidx);
272 if (!is_filter_set(&adap->tids, fidx, fs.type)) {
273 dev_err(adap, "Already free fidx:%d f:%p\n", fidx, f);
281 cxgbe_validate_fidxonadd(struct ch_filter_specification *fs,
282 struct adapter *adap, unsigned int fidx)
284 if (is_filter_set(&adap->tids, fidx, fs->type)) {
285 dev_err(adap, "filter index: %d is busy.\n", fidx);
288 if (fidx >= adap->tids.nftids) {
289 dev_err(adap, "filter index (%u) >= max(%u)\n",
290 fidx, adap->tids.nftids);
298 cxgbe_verify_fidx(struct rte_flow *flow, unsigned int fidx, uint8_t del)
301 return 0; /* Hash filters */
302 return del ? cxgbe_validate_fidxondel(flow->f, fidx) :
303 cxgbe_validate_fidxonadd(&flow->fs,
304 ethdev2adap(flow->dev), fidx);
307 static int cxgbe_get_fidx(struct rte_flow *flow, unsigned int *fidx)
309 struct ch_filter_specification *fs = &flow->fs;
310 struct adapter *adap = ethdev2adap(flow->dev);
312 /* For tcam get the next available slot, if default value specified */
313 if (flow->fidx == FILTER_ID_MAX) {
316 idx = cxgbe_alloc_ftid(adap, fs->type);
318 dev_err(adap, "unable to get a filter index in tcam\n");
321 *fidx = (unsigned int)idx;
330 ch_rte_parse_atype_switch(const struct rte_flow_action *a,
331 struct ch_filter_specification *fs,
332 struct rte_flow_error *e)
334 const struct rte_flow_action_of_set_vlan_vid *vlanid;
335 const struct rte_flow_action_of_push_vlan *pushvlan;
336 const struct rte_flow_action_phy_port *port;
339 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
340 vlanid = (const struct rte_flow_action_of_set_vlan_vid *)
342 fs->newvlan = VLAN_REWRITE;
343 fs->vlan = vlanid->vlan_vid;
345 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
346 pushvlan = (const struct rte_flow_action_of_push_vlan *)
348 if (pushvlan->ethertype != ETHER_TYPE_VLAN)
349 return rte_flow_error_set(e, EINVAL,
350 RTE_FLOW_ERROR_TYPE_ACTION, a,
351 "only ethertype 0x8100 "
352 "supported for push vlan.");
353 fs->newvlan = VLAN_INSERT;
355 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
356 fs->newvlan = VLAN_REMOVE;
358 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
359 port = (const struct rte_flow_action_phy_port *)a->conf;
360 fs->eport = port->index;
363 /* We are not supposed to come here */
364 return rte_flow_error_set(e, EINVAL,
365 RTE_FLOW_ERROR_TYPE_ACTION, a,
366 "Action not supported");
373 cxgbe_rtef_parse_actions(struct rte_flow *flow,
374 const struct rte_flow_action action[],
375 struct rte_flow_error *e)
377 struct ch_filter_specification *fs = &flow->fs;
378 const struct rte_flow_action_queue *q;
379 const struct rte_flow_action *a;
383 for (a = action; a->type != RTE_FLOW_ACTION_TYPE_END; a++) {
385 case RTE_FLOW_ACTION_TYPE_VOID:
387 case RTE_FLOW_ACTION_TYPE_DROP:
389 return rte_flow_error_set(e, EINVAL,
390 RTE_FLOW_ERROR_TYPE_ACTION, a,
391 "specify only 1 pass/drop");
392 fs->action = FILTER_DROP;
394 case RTE_FLOW_ACTION_TYPE_QUEUE:
395 q = (const struct rte_flow_action_queue *)a->conf;
397 return rte_flow_error_set(e, EINVAL,
398 RTE_FLOW_ERROR_TYPE_ACTION, q,
399 "specify rx queue index");
400 if (check_rxq(flow->dev, q->index))
401 return rte_flow_error_set(e, EINVAL,
402 RTE_FLOW_ERROR_TYPE_ACTION, q,
405 return rte_flow_error_set(e, EINVAL,
406 RTE_FLOW_ERROR_TYPE_ACTION, a,
407 "specify only 1 pass/drop");
408 fs->action = FILTER_PASS;
412 case RTE_FLOW_ACTION_TYPE_COUNT:
415 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
416 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
417 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
418 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
419 /* We allow multiple switch actions, but switch is
420 * not compatible with either queue or drop
422 if (abit++ && fs->action != FILTER_SWITCH)
423 return rte_flow_error_set(e, EINVAL,
424 RTE_FLOW_ERROR_TYPE_ACTION, a,
425 "overlapping action specified");
426 ret = ch_rte_parse_atype_switch(a, fs, e);
429 fs->action = FILTER_SWITCH;
432 /* Not supported action : return error */
433 return rte_flow_error_set(e, ENOTSUP,
434 RTE_FLOW_ERROR_TYPE_ACTION,
435 a, "Action not supported");
442 struct chrte_fparse parseitem[] = {
443 [RTE_FLOW_ITEM_TYPE_PHY_PORT] = {
444 .fptr = ch_rte_parsetype_port,
445 .dmask = &(const struct rte_flow_item_phy_port){
450 [RTE_FLOW_ITEM_TYPE_IPV4] = {
451 .fptr = ch_rte_parsetype_ipv4,
452 .dmask = &rte_flow_item_ipv4_mask,
455 [RTE_FLOW_ITEM_TYPE_IPV6] = {
456 .fptr = ch_rte_parsetype_ipv6,
457 .dmask = &rte_flow_item_ipv6_mask,
460 [RTE_FLOW_ITEM_TYPE_UDP] = {
461 .fptr = ch_rte_parsetype_udp,
462 .dmask = &rte_flow_item_udp_mask,
465 [RTE_FLOW_ITEM_TYPE_TCP] = {
466 .fptr = ch_rte_parsetype_tcp,
467 .dmask = &rte_flow_item_tcp_mask,
472 cxgbe_rtef_parse_items(struct rte_flow *flow,
473 const struct rte_flow_item items[],
474 struct rte_flow_error *e)
476 struct adapter *adap = ethdev2adap(flow->dev);
477 const struct rte_flow_item *i;
478 char repeat[ARRAY_SIZE(parseitem)] = {0};
480 for (i = items; i->type != RTE_FLOW_ITEM_TYPE_END; i++) {
481 struct chrte_fparse *idx;
484 if (i->type >= ARRAY_SIZE(parseitem))
485 return rte_flow_error_set(e, ENOTSUP,
486 RTE_FLOW_ERROR_TYPE_ITEM,
487 i, "Item not supported");
490 case RTE_FLOW_ITEM_TYPE_VOID:
493 /* check if item is repeated */
495 return rte_flow_error_set(e, ENOTSUP,
496 RTE_FLOW_ERROR_TYPE_ITEM, i,
497 "parse items cannot be repeated (except void)");
500 /* validate the item */
501 ret = cxgbe_validate_item(i, e);
505 idx = &flow->item_parser[i->type];
506 if (!idx || !idx->fptr) {
507 return rte_flow_error_set(e, ENOTSUP,
508 RTE_FLOW_ERROR_TYPE_ITEM, i,
509 "Item not supported");
511 ret = idx->fptr(idx->dmask, i, &flow->fs, e);
518 cxgbe_fill_filter_region(adap, &flow->fs);
524 cxgbe_flow_parse(struct rte_flow *flow,
525 const struct rte_flow_attr *attr,
526 const struct rte_flow_item item[],
527 const struct rte_flow_action action[],
528 struct rte_flow_error *e)
532 /* parse user request into ch_filter_specification */
533 ret = cxgbe_rtef_parse_attr(flow, attr, e);
536 ret = cxgbe_rtef_parse_items(flow, item, e);
539 return cxgbe_rtef_parse_actions(flow, action, e);
542 static int __cxgbe_flow_create(struct rte_eth_dev *dev, struct rte_flow *flow)
544 struct ch_filter_specification *fs = &flow->fs;
545 struct adapter *adap = ethdev2adap(dev);
546 struct tid_info *t = &adap->tids;
547 struct filter_ctx ctx;
551 if (cxgbe_get_fidx(flow, &fidx))
553 if (cxgbe_verify_fidx(flow, fidx, 0))
556 t4_init_completion(&ctx.completion);
557 /* go create the filter */
558 err = cxgbe_set_filter(dev, fidx, fs, &ctx);
560 dev_err(adap, "Error %d while creating filter.\n", err);
564 /* Poll the FW for reply */
565 err = cxgbe_poll_for_completion(&adap->sge.fw_evtq,
570 dev_err(adap, "Filter set operation timed out (%d)\n", err);
574 dev_err(adap, "Hardware error %d while creating the filter.\n",
579 if (fs->cap) { /* to destroy the filter */
580 flow->fidx = ctx.tid;
581 flow->f = lookup_tid(t, ctx.tid);
584 flow->f = &adap->tids.ftid_tab[fidx];
590 static struct rte_flow *
591 cxgbe_flow_create(struct rte_eth_dev *dev,
592 const struct rte_flow_attr *attr,
593 const struct rte_flow_item item[],
594 const struct rte_flow_action action[],
595 struct rte_flow_error *e)
597 struct rte_flow *flow;
600 flow = t4_os_alloc(sizeof(struct rte_flow));
602 rte_flow_error_set(e, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
603 NULL, "Unable to allocate memory for"
608 flow->item_parser = parseitem;
611 if (cxgbe_flow_parse(flow, attr, item, action, e)) {
616 /* go, interact with cxgbe_filter */
617 ret = __cxgbe_flow_create(dev, flow);
619 rte_flow_error_set(e, ret, RTE_FLOW_ERROR_TYPE_HANDLE,
620 NULL, "Unable to create flow rule");
625 flow->f->private = flow; /* Will be used during flush */
630 static int __cxgbe_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
632 struct adapter *adap = ethdev2adap(dev);
633 struct filter_entry *f = flow->f;
634 struct ch_filter_specification *fs;
635 struct filter_ctx ctx;
639 if (cxgbe_verify_fidx(flow, flow->fidx, 1))
642 t4_init_completion(&ctx.completion);
643 err = cxgbe_del_filter(dev, flow->fidx, fs, &ctx);
645 dev_err(adap, "Error %d while deleting filter.\n", err);
649 /* Poll the FW for reply */
650 err = cxgbe_poll_for_completion(&adap->sge.fw_evtq,
655 dev_err(adap, "Filter delete operation timed out (%d)\n", err);
659 dev_err(adap, "Hardware error %d while deleting the filter.\n",
668 cxgbe_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
669 struct rte_flow_error *e)
673 ret = __cxgbe_flow_destroy(dev, flow);
675 return rte_flow_error_set(e, ret, RTE_FLOW_ERROR_TYPE_HANDLE,
676 flow, "error destroying filter.");
681 static int __cxgbe_flow_query(struct rte_flow *flow, u64 *count,
684 struct adapter *adap = ethdev2adap(flow->dev);
685 struct ch_filter_specification fs = flow->f->fs;
686 unsigned int fidx = flow->fidx;
689 ret = cxgbe_get_filter_count(adap, fidx, count, fs.cap, 0);
692 return cxgbe_get_filter_count(adap, fidx, byte_count, fs.cap, 1);
696 cxgbe_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow,
697 const struct rte_flow_action *action, void *data,
698 struct rte_flow_error *e)
700 struct ch_filter_specification fs;
701 struct rte_flow_query_count *c;
702 struct filter_entry *f;
710 if (action->type != RTE_FLOW_ACTION_TYPE_COUNT)
711 return rte_flow_error_set(e, ENOTSUP,
712 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
713 "only count supported for query");
716 * This is a valid operation, Since we are allowed to do chelsio
717 * specific operations in rte side of our code but not vise-versa
719 * So, fs can be queried/modified here BUT rte_flow_query_count
720 * cannot be worked on by the lower layer since we want to maintain
721 * it as rte_flow agnostic.
724 return rte_flow_error_set(e, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
725 &fs, "filter hit counters were not"
726 " enabled during filter creation");
728 c = (struct rte_flow_query_count *)data;
729 ret = __cxgbe_flow_query(flow, &c->hits, &c->bytes);
731 return rte_flow_error_set(e, -ret, RTE_FLOW_ERROR_TYPE_ACTION,
732 f, "cxgbe pmd failed to"
735 /* Query was successful */
739 return 0; /* success / partial_success */
743 cxgbe_flow_validate(struct rte_eth_dev *dev,
744 const struct rte_flow_attr *attr,
745 const struct rte_flow_item item[],
746 const struct rte_flow_action action[],
747 struct rte_flow_error *e)
749 struct adapter *adap = ethdev2adap(dev);
750 struct rte_flow *flow;
754 flow = t4_os_alloc(sizeof(struct rte_flow));
756 return rte_flow_error_set(e, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
758 "Unable to allocate memory for filter_entry");
760 flow->item_parser = parseitem;
763 ret = cxgbe_flow_parse(flow, attr, item, action, e);
769 if (validate_filter(adap, &flow->fs)) {
771 return rte_flow_error_set(e, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
773 "validation failed. Check f/w config file.");
776 if (cxgbe_get_fidx(flow, &fidx)) {
778 return rte_flow_error_set(e, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
779 NULL, "no memory in tcam.");
782 if (cxgbe_verify_fidx(flow, fidx, 0)) {
784 return rte_flow_error_set(e, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
785 NULL, "validation failed");
793 * @ret : > 0 filter destroyed succsesfully
794 * < 0 error destroying filter
795 * == 1 filter not active / not found
798 cxgbe_check_n_destroy(struct filter_entry *f, struct rte_eth_dev *dev,
799 struct rte_flow_error *e)
801 if (f && (f->valid || f->pending) &&
802 f->dev == dev && /* Only if user has asked for this port */
803 f->private) /* We (rte_flow) created this filter */
804 return cxgbe_flow_destroy(dev, (struct rte_flow *)f->private,
809 static int cxgbe_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *e)
811 struct adapter *adap = ethdev2adap(dev);
815 if (adap->tids.ftid_tab) {
816 struct filter_entry *f = &adap->tids.ftid_tab[0];
818 for (i = 0; i < adap->tids.nftids; i++, f++) {
819 ret = cxgbe_check_n_destroy(f, dev, e);
825 if (is_hashfilter(adap) && adap->tids.tid_tab) {
826 struct filter_entry *f;
828 for (i = adap->tids.hash_base; i <= adap->tids.ntids; i++) {
829 f = (struct filter_entry *)adap->tids.tid_tab[i];
831 ret = cxgbe_check_n_destroy(f, dev, e);
838 return ret >= 0 ? 0 : ret;
841 static const struct rte_flow_ops cxgbe_flow_ops = {
842 .validate = cxgbe_flow_validate,
843 .create = cxgbe_flow_create,
844 .destroy = cxgbe_flow_destroy,
845 .flush = cxgbe_flow_flush,
846 .query = cxgbe_flow_query,
851 cxgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
852 enum rte_filter_type filter_type,
853 enum rte_filter_op filter_op,
859 switch (filter_type) {
860 case RTE_ETH_FILTER_GENERIC:
861 if (filter_op != RTE_ETH_FILTER_GET)
863 *(const void **)arg = &cxgbe_flow_ops;