1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
8 #include <rte_hash_crc.h>
9 #include "base/ice_fdir.h"
10 #include "base/ice_flow.h"
11 #include "base/ice_type.h"
12 #include "ice_ethdev.h"
14 #include "ice_generic_flow.h"
16 #define ICE_FDIR_IPV6_TC_OFFSET 20
17 #define ICE_IPV6_TC_MASK (0xFF << ICE_FDIR_IPV6_TC_OFFSET)
19 #define ICE_FDIR_MAX_QREGION_SIZE 128
21 #define ICE_FDIR_INSET_ETH (\
22 ICE_INSET_DMAC | ICE_INSET_SMAC | ICE_INSET_ETHERTYPE)
24 #define ICE_FDIR_INSET_ETH_IPV4 (\
25 ICE_FDIR_INSET_ETH | \
26 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_IPV4_TOS | \
27 ICE_INSET_IPV4_TTL | ICE_INSET_IPV4_PROTO)
29 #define ICE_FDIR_INSET_ETH_IPV4_UDP (\
30 ICE_FDIR_INSET_ETH_IPV4 | \
31 ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
33 #define ICE_FDIR_INSET_ETH_IPV4_TCP (\
34 ICE_FDIR_INSET_ETH_IPV4 | \
35 ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
37 #define ICE_FDIR_INSET_ETH_IPV4_SCTP (\
38 ICE_FDIR_INSET_ETH_IPV4 | \
39 ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
41 #define ICE_FDIR_INSET_ETH_IPV6 (\
43 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_IPV6_TC | \
44 ICE_INSET_IPV6_HOP_LIMIT | ICE_INSET_IPV6_NEXT_HDR)
46 #define ICE_FDIR_INSET_ETH_IPV6_UDP (\
47 ICE_FDIR_INSET_ETH_IPV6 | \
48 ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
50 #define ICE_FDIR_INSET_ETH_IPV6_TCP (\
51 ICE_FDIR_INSET_ETH_IPV6 | \
52 ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
54 #define ICE_FDIR_INSET_ETH_IPV6_SCTP (\
55 ICE_FDIR_INSET_ETH_IPV6 | \
56 ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
58 #define ICE_FDIR_INSET_VXLAN_IPV4 (\
59 ICE_INSET_TUN_IPV4_SRC | ICE_INSET_TUN_IPV4_DST)
61 #define ICE_FDIR_INSET_VXLAN_IPV4_TCP (\
62 ICE_FDIR_INSET_VXLAN_IPV4 | \
63 ICE_INSET_TUN_TCP_SRC_PORT | ICE_INSET_TUN_TCP_DST_PORT)
65 #define ICE_FDIR_INSET_VXLAN_IPV4_UDP (\
66 ICE_FDIR_INSET_VXLAN_IPV4 | \
67 ICE_INSET_TUN_UDP_SRC_PORT | ICE_INSET_TUN_UDP_DST_PORT)
69 #define ICE_FDIR_INSET_VXLAN_IPV4_SCTP (\
70 ICE_FDIR_INSET_VXLAN_IPV4 | \
71 ICE_INSET_TUN_SCTP_SRC_PORT | ICE_INSET_TUN_SCTP_DST_PORT)
73 #define ICE_FDIR_INSET_IPV4_GTPU (\
74 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_GTPU_TEID)
76 #define ICE_FDIR_INSET_IPV4_GTPU_EH (\
77 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
78 ICE_INSET_GTPU_TEID | ICE_INSET_GTPU_QFI)
80 #define ICE_FDIR_INSET_IPV6_GTPU (\
81 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_GTPU_TEID)
83 #define ICE_FDIR_INSET_IPV6_GTPU_EH (\
84 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
85 ICE_INSET_GTPU_TEID | ICE_INSET_GTPU_QFI)
87 static struct ice_pattern_match_item ice_fdir_pattern_list[] = {
88 {pattern_ethertype, ICE_FDIR_INSET_ETH, ICE_INSET_NONE},
89 {pattern_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4, ICE_INSET_NONE},
90 {pattern_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_UDP, ICE_INSET_NONE},
91 {pattern_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_TCP, ICE_INSET_NONE},
92 {pattern_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_SCTP, ICE_INSET_NONE},
93 {pattern_eth_ipv6, ICE_FDIR_INSET_ETH_IPV6, ICE_INSET_NONE},
94 {pattern_eth_ipv6_udp, ICE_FDIR_INSET_ETH_IPV6_UDP, ICE_INSET_NONE},
95 {pattern_eth_ipv6_tcp, ICE_FDIR_INSET_ETH_IPV6_TCP, ICE_INSET_NONE},
96 {pattern_eth_ipv6_sctp, ICE_FDIR_INSET_ETH_IPV6_SCTP, ICE_INSET_NONE},
97 {pattern_eth_ipv4_udp_vxlan_ipv4,
98 ICE_FDIR_INSET_VXLAN_IPV4, ICE_INSET_NONE},
99 {pattern_eth_ipv4_udp_vxlan_ipv4_udp,
100 ICE_FDIR_INSET_VXLAN_IPV4_UDP, ICE_INSET_NONE},
101 {pattern_eth_ipv4_udp_vxlan_ipv4_tcp,
102 ICE_FDIR_INSET_VXLAN_IPV4_TCP, ICE_INSET_NONE},
103 {pattern_eth_ipv4_udp_vxlan_ipv4_sctp,
104 ICE_FDIR_INSET_VXLAN_IPV4_SCTP, ICE_INSET_NONE},
105 {pattern_eth_ipv4_udp_vxlan_eth_ipv4,
106 ICE_FDIR_INSET_VXLAN_IPV4, ICE_INSET_NONE},
107 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_udp,
108 ICE_FDIR_INSET_VXLAN_IPV4_UDP, ICE_INSET_NONE},
109 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_tcp,
110 ICE_FDIR_INSET_VXLAN_IPV4_TCP, ICE_INSET_NONE},
111 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_sctp,
112 ICE_FDIR_INSET_VXLAN_IPV4_SCTP, ICE_INSET_NONE},
113 {pattern_eth_ipv4_gtpu, ICE_FDIR_INSET_IPV4_GTPU, ICE_INSET_NONE},
114 {pattern_eth_ipv4_gtpu_eh, ICE_FDIR_INSET_IPV4_GTPU_EH, ICE_INSET_NONE},
115 {pattern_eth_ipv6_gtpu, ICE_FDIR_INSET_IPV6_GTPU, ICE_INSET_NONE},
116 {pattern_eth_ipv6_gtpu_eh, ICE_FDIR_INSET_IPV6_GTPU_EH, ICE_INSET_NONE},
119 static struct ice_flow_parser ice_fdir_parser;
122 ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type);
124 static const struct rte_memzone *
125 ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
127 const struct rte_memzone *mz;
129 mz = rte_memzone_lookup(name);
133 return rte_memzone_reserve_aligned(name, len, socket_id,
134 RTE_MEMZONE_IOVA_CONTIG,
135 ICE_RING_BASE_ALIGN);
138 #define ICE_FDIR_MZ_NAME "FDIR_MEMZONE"
141 ice_fdir_prof_alloc(struct ice_hw *hw)
143 enum ice_fltr_ptype ptype, fltr_ptype;
145 if (!hw->fdir_prof) {
146 hw->fdir_prof = (struct ice_fd_hw_prof **)
147 ice_malloc(hw, ICE_FLTR_PTYPE_MAX *
148 sizeof(*hw->fdir_prof));
152 for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
153 ptype < ICE_FLTR_PTYPE_MAX;
155 if (!hw->fdir_prof[ptype]) {
156 hw->fdir_prof[ptype] = (struct ice_fd_hw_prof *)
157 ice_malloc(hw, sizeof(**hw->fdir_prof));
158 if (!hw->fdir_prof[ptype])
165 for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
168 rte_free(hw->fdir_prof[fltr_ptype]);
169 hw->fdir_prof[fltr_ptype] = NULL;
172 rte_free(hw->fdir_prof);
173 hw->fdir_prof = NULL;
179 ice_fdir_counter_pool_add(__rte_unused struct ice_pf *pf,
180 struct ice_fdir_counter_pool_container *container,
181 uint32_t index_start,
184 struct ice_fdir_counter_pool *pool;
188 pool = rte_zmalloc("ice_fdir_counter_pool",
190 sizeof(struct ice_fdir_counter) * len,
194 "Failed to allocate memory for fdir counter pool");
198 TAILQ_INIT(&pool->counter_list);
199 TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
201 for (i = 0; i < len; i++) {
202 struct ice_fdir_counter *counter = &pool->counters[i];
204 counter->hw_index = index_start + i;
205 TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
208 if (container->index_free == ICE_FDIR_COUNTER_MAX_POOL_SIZE) {
209 PMD_INIT_LOG(ERR, "FDIR counter pool is full");
214 container->pools[container->index_free++] = pool;
223 ice_fdir_counter_init(struct ice_pf *pf)
225 struct ice_hw *hw = ICE_PF_TO_HW(pf);
226 struct ice_fdir_info *fdir_info = &pf->fdir;
227 struct ice_fdir_counter_pool_container *container =
229 uint32_t cnt_index, len;
232 TAILQ_INIT(&container->pool_list);
234 cnt_index = ICE_FDIR_COUNTER_INDEX(hw->fd_ctr_base);
235 len = ICE_FDIR_COUNTERS_PER_BLOCK;
237 ret = ice_fdir_counter_pool_add(pf, container, cnt_index, len);
239 PMD_INIT_LOG(ERR, "Failed to add fdir pool to container");
247 ice_fdir_counter_release(struct ice_pf *pf)
249 struct ice_fdir_info *fdir_info = &pf->fdir;
250 struct ice_fdir_counter_pool_container *container =
254 for (i = 0; i < container->index_free; i++) {
255 rte_free(container->pools[i]);
256 container->pools[i] = NULL;
259 TAILQ_INIT(&container->pool_list);
260 container->index_free = 0;
265 static struct ice_fdir_counter *
266 ice_fdir_counter_shared_search(struct ice_fdir_counter_pool_container
270 struct ice_fdir_counter_pool *pool;
271 struct ice_fdir_counter *counter;
274 TAILQ_FOREACH(pool, &container->pool_list, next) {
275 for (i = 0; i < ICE_FDIR_COUNTERS_PER_BLOCK; i++) {
276 counter = &pool->counters[i];
278 if (counter->shared &&
288 static struct ice_fdir_counter *
289 ice_fdir_counter_alloc(struct ice_pf *pf, uint32_t shared, uint32_t id)
291 struct ice_hw *hw = ICE_PF_TO_HW(pf);
292 struct ice_fdir_info *fdir_info = &pf->fdir;
293 struct ice_fdir_counter_pool_container *container =
295 struct ice_fdir_counter_pool *pool = NULL;
296 struct ice_fdir_counter *counter_free = NULL;
299 counter_free = ice_fdir_counter_shared_search(container, id);
301 if (counter_free->ref_cnt + 1 == 0) {
305 counter_free->ref_cnt++;
310 TAILQ_FOREACH(pool, &container->pool_list, next) {
311 counter_free = TAILQ_FIRST(&pool->counter_list);
318 PMD_DRV_LOG(ERR, "No free counter found\n");
322 counter_free->shared = shared;
323 counter_free->id = id;
324 counter_free->ref_cnt = 1;
325 counter_free->pool = pool;
327 /* reset statistic counter value */
328 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter_free->hw_index), 0);
329 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter_free->hw_index), 0);
331 TAILQ_REMOVE(&pool->counter_list, counter_free, next);
332 if (TAILQ_EMPTY(&pool->counter_list)) {
333 TAILQ_REMOVE(&container->pool_list, pool, next);
334 TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
341 ice_fdir_counter_free(__rte_unused struct ice_pf *pf,
342 struct ice_fdir_counter *counter)
347 if (--counter->ref_cnt == 0) {
348 struct ice_fdir_counter_pool *pool = counter->pool;
350 TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
355 ice_fdir_init_filter_list(struct ice_pf *pf)
357 struct rte_eth_dev *dev = pf->adapter->eth_dev;
358 struct ice_fdir_info *fdir_info = &pf->fdir;
359 char fdir_hash_name[RTE_HASH_NAMESIZE];
362 struct rte_hash_parameters fdir_hash_params = {
363 .name = fdir_hash_name,
364 .entries = ICE_MAX_FDIR_FILTER_NUM,
365 .key_len = sizeof(struct ice_fdir_fltr_pattern),
366 .hash_func = rte_hash_crc,
367 .hash_func_init_val = 0,
368 .socket_id = rte_socket_id(),
369 .extra_flag = RTE_HASH_EXTRA_FLAGS_EXT_TABLE,
372 /* Initialize hash */
373 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
374 "fdir_%s", dev->device->name);
375 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
376 if (!fdir_info->hash_table) {
377 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
380 fdir_info->hash_map = rte_zmalloc("ice_fdir_hash_map",
381 sizeof(*fdir_info->hash_map) *
382 ICE_MAX_FDIR_FILTER_NUM,
384 if (!fdir_info->hash_map) {
386 "Failed to allocate memory for fdir hash map!");
388 goto err_fdir_hash_map_alloc;
392 err_fdir_hash_map_alloc:
393 rte_hash_free(fdir_info->hash_table);
399 ice_fdir_release_filter_list(struct ice_pf *pf)
401 struct ice_fdir_info *fdir_info = &pf->fdir;
403 if (fdir_info->hash_map)
404 rte_free(fdir_info->hash_map);
405 if (fdir_info->hash_table)
406 rte_hash_free(fdir_info->hash_table);
408 fdir_info->hash_map = NULL;
409 fdir_info->hash_table = NULL;
413 * ice_fdir_setup - reserve and initialize the Flow Director resources
414 * @pf: board private structure
417 ice_fdir_setup(struct ice_pf *pf)
419 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
420 struct ice_hw *hw = ICE_PF_TO_HW(pf);
421 const struct rte_memzone *mz = NULL;
422 char z_name[RTE_MEMZONE_NAMESIZE];
424 int err = ICE_SUCCESS;
426 if ((pf->flags & ICE_FLAG_FDIR) == 0) {
427 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
431 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
432 " fd_fltr_best_effort = %u.",
433 hw->func_caps.fd_fltr_guar,
434 hw->func_caps.fd_fltr_best_effort);
436 if (pf->fdir.fdir_vsi) {
437 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
441 /* make new FDIR VSI */
442 vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
444 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
447 pf->fdir.fdir_vsi = vsi;
449 err = ice_fdir_init_filter_list(pf);
451 PMD_DRV_LOG(ERR, "Failed to init FDIR filter list.");
455 err = ice_fdir_counter_init(pf);
457 PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
461 /*Fdir tx queue setup*/
462 err = ice_fdir_setup_tx_resources(pf);
464 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
468 /*Fdir rx queue setup*/
469 err = ice_fdir_setup_rx_resources(pf);
471 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
475 err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
477 PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
481 err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
483 PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
487 /* Enable FDIR MSIX interrupt */
488 vsi->nb_used_qps = 1;
489 ice_vsi_queues_bind_intr(vsi);
490 ice_vsi_enable_queues_intr(vsi);
492 /* reserve memory for the fdir programming packet */
493 snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
495 eth_dev->data->port_id);
496 mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
498 PMD_DRV_LOG(ERR, "Cannot init memzone for "
499 "flow director program packet.");
503 pf->fdir.prg_pkt = mz->addr;
504 pf->fdir.dma_addr = mz->iova;
507 err = ice_fdir_prof_alloc(hw);
509 PMD_DRV_LOG(ERR, "Cannot allocate memory for "
510 "flow director profile.");
515 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
520 rte_memzone_free(pf->fdir.mz);
523 ice_rx_queue_release(pf->fdir.rxq);
526 ice_tx_queue_release(pf->fdir.txq);
529 ice_release_vsi(vsi);
530 pf->fdir.fdir_vsi = NULL;
535 ice_fdir_prof_free(struct ice_hw *hw)
537 enum ice_fltr_ptype ptype;
539 for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
540 ptype < ICE_FLTR_PTYPE_MAX;
542 rte_free(hw->fdir_prof[ptype]);
543 hw->fdir_prof[ptype] = NULL;
546 rte_free(hw->fdir_prof);
547 hw->fdir_prof = NULL;
550 /* Remove a profile for some filter type */
552 ice_fdir_prof_rm(struct ice_pf *pf, enum ice_fltr_ptype ptype, bool is_tunnel)
554 struct ice_hw *hw = ICE_PF_TO_HW(pf);
555 struct ice_fd_hw_prof *hw_prof;
560 if (!hw->fdir_prof || !hw->fdir_prof[ptype])
563 hw_prof = hw->fdir_prof[ptype];
565 prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
566 for (i = 0; i < pf->hw_prof_cnt[ptype][is_tunnel]; i++) {
567 if (hw_prof->entry_h[i][is_tunnel]) {
568 vsi_num = ice_get_hw_vsi_num(hw,
570 ice_rem_prof_id_flow(hw, ICE_BLK_FD,
572 ice_flow_rem_entry(hw, ICE_BLK_FD,
573 hw_prof->entry_h[i][is_tunnel]);
574 hw_prof->entry_h[i][is_tunnel] = 0;
577 ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
578 rte_free(hw_prof->fdir_seg[is_tunnel]);
579 hw_prof->fdir_seg[is_tunnel] = NULL;
581 for (i = 0; i < hw_prof->cnt; i++)
582 hw_prof->vsi_h[i] = 0;
583 pf->hw_prof_cnt[ptype][is_tunnel] = 0;
586 /* Remove all created profiles */
588 ice_fdir_prof_rm_all(struct ice_pf *pf)
590 enum ice_fltr_ptype ptype;
592 for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
593 ptype < ICE_FLTR_PTYPE_MAX;
595 ice_fdir_prof_rm(pf, ptype, false);
596 ice_fdir_prof_rm(pf, ptype, true);
601 * ice_fdir_teardown - release the Flow Director resources
602 * @pf: board private structure
605 ice_fdir_teardown(struct ice_pf *pf)
607 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
608 struct ice_hw *hw = ICE_PF_TO_HW(pf);
612 vsi = pf->fdir.fdir_vsi;
616 ice_vsi_disable_queues_intr(vsi);
618 err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
620 PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
622 err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
624 PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
626 err = ice_fdir_counter_release(pf);
628 PMD_DRV_LOG(ERR, "Failed to release FDIR counter resource.");
630 ice_fdir_release_filter_list(pf);
632 ice_tx_queue_release(pf->fdir.txq);
634 ice_rx_queue_release(pf->fdir.rxq);
636 ice_fdir_prof_rm_all(pf);
637 ice_fdir_prof_free(hw);
638 ice_release_vsi(vsi);
639 pf->fdir.fdir_vsi = NULL;
642 err = rte_memzone_free(pf->fdir.mz);
645 PMD_DRV_LOG(ERR, "Failed to free FDIR memezone.");
650 ice_fdir_cur_prof_conflict(struct ice_pf *pf,
651 enum ice_fltr_ptype ptype,
652 struct ice_flow_seg_info *seg,
655 struct ice_hw *hw = ICE_PF_TO_HW(pf);
656 struct ice_flow_seg_info *ori_seg;
657 struct ice_fd_hw_prof *hw_prof;
659 hw_prof = hw->fdir_prof[ptype];
660 ori_seg = hw_prof->fdir_seg[is_tunnel];
662 /* profile does not exist */
666 /* if no input set conflict, return -EEXIST */
667 if ((!is_tunnel && !memcmp(ori_seg, seg, sizeof(*seg))) ||
668 (is_tunnel && !memcmp(&ori_seg[1], &seg[1], sizeof(*seg)))) {
669 PMD_DRV_LOG(DEBUG, "Profile already exists for flow type %d.",
674 /* a rule with input set conflict already exist, so give up */
675 if (pf->fdir_fltr_cnt[ptype][is_tunnel]) {
676 PMD_DRV_LOG(DEBUG, "Failed to create profile for flow type %d due to conflict with existing rule.",
681 /* it's safe to delete an empty profile */
682 ice_fdir_prof_rm(pf, ptype, is_tunnel);
687 ice_fdir_prof_resolve_conflict(struct ice_pf *pf,
688 enum ice_fltr_ptype ptype,
691 struct ice_hw *hw = ICE_PF_TO_HW(pf);
692 struct ice_fd_hw_prof *hw_prof;
693 struct ice_flow_seg_info *seg;
695 hw_prof = hw->fdir_prof[ptype];
696 seg = hw_prof->fdir_seg[is_tunnel];
698 /* profile does not exist */
702 /* profile exists and rule exists, fail to resolve the conflict */
703 if (pf->fdir_fltr_cnt[ptype][is_tunnel] != 0)
706 /* it's safe to delete an empty profile */
707 ice_fdir_prof_rm(pf, ptype, is_tunnel);
713 ice_fdir_cross_prof_conflict(struct ice_pf *pf,
714 enum ice_fltr_ptype ptype,
717 enum ice_fltr_ptype cflct_ptype;
721 case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
722 case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
723 case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
724 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
725 if (!ice_fdir_prof_resolve_conflict
726 (pf, cflct_ptype, is_tunnel))
729 case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
730 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
731 if (!ice_fdir_prof_resolve_conflict
732 (pf, cflct_ptype, is_tunnel))
734 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
735 if (!ice_fdir_prof_resolve_conflict
736 (pf, cflct_ptype, is_tunnel))
738 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
739 if (!ice_fdir_prof_resolve_conflict
740 (pf, cflct_ptype, is_tunnel))
744 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP:
745 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP:
746 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP:
747 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER;
748 if (!ice_fdir_prof_resolve_conflict
749 (pf, cflct_ptype, is_tunnel))
752 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER:
753 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP;
754 if (!ice_fdir_prof_resolve_conflict
755 (pf, cflct_ptype, is_tunnel))
757 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP;
758 if (!ice_fdir_prof_resolve_conflict
759 (pf, cflct_ptype, is_tunnel))
761 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP;
762 if (!ice_fdir_prof_resolve_conflict
763 (pf, cflct_ptype, is_tunnel))
767 case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
768 case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
769 case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
770 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
771 if (!ice_fdir_prof_resolve_conflict
772 (pf, cflct_ptype, is_tunnel))
775 case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
776 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
777 if (!ice_fdir_prof_resolve_conflict
778 (pf, cflct_ptype, is_tunnel))
780 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
781 if (!ice_fdir_prof_resolve_conflict
782 (pf, cflct_ptype, is_tunnel))
784 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
785 if (!ice_fdir_prof_resolve_conflict
786 (pf, cflct_ptype, is_tunnel))
794 PMD_DRV_LOG(DEBUG, "Failed to create profile for flow type %d due to conflict with existing rule of flow type %d.",
800 ice_fdir_hw_tbl_conf(struct ice_pf *pf, struct ice_vsi *vsi,
801 struct ice_vsi *ctrl_vsi,
802 struct ice_flow_seg_info *seg,
803 enum ice_fltr_ptype ptype,
806 struct ice_hw *hw = ICE_PF_TO_HW(pf);
807 enum ice_flow_dir dir = ICE_FLOW_RX;
808 struct ice_fd_hw_prof *hw_prof;
809 struct ice_flow_prof *prof;
810 uint64_t entry_1 = 0;
811 uint64_t entry_2 = 0;
816 /* check if have input set conflict on current profile. */
817 ret = ice_fdir_cur_prof_conflict(pf, ptype, seg, is_tunnel);
821 /* check if the profile is conflict with other profile. */
822 ret = ice_fdir_cross_prof_conflict(pf, ptype, is_tunnel);
826 prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
827 ret = ice_flow_add_prof(hw, ICE_BLK_FD, dir, prof_id, seg,
828 (is_tunnel) ? 2 : 1, NULL, 0, &prof);
831 ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
832 vsi->idx, ICE_FLOW_PRIO_NORMAL,
833 seg, NULL, 0, &entry_1);
835 PMD_DRV_LOG(ERR, "Failed to add main VSI flow entry for %d.",
839 ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
840 ctrl_vsi->idx, ICE_FLOW_PRIO_NORMAL,
841 seg, NULL, 0, &entry_2);
843 PMD_DRV_LOG(ERR, "Failed to add control VSI flow entry for %d.",
848 hw_prof = hw->fdir_prof[ptype];
849 pf->hw_prof_cnt[ptype][is_tunnel] = 0;
851 hw_prof->fdir_seg[is_tunnel] = seg;
852 hw_prof->vsi_h[hw_prof->cnt] = vsi->idx;
853 hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_1;
854 pf->hw_prof_cnt[ptype][is_tunnel]++;
855 hw_prof->vsi_h[hw_prof->cnt] = ctrl_vsi->idx;
856 hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_2;
857 pf->hw_prof_cnt[ptype][is_tunnel]++;
862 vsi_num = ice_get_hw_vsi_num(hw, vsi->idx);
863 ice_rem_prof_id_flow(hw, ICE_BLK_FD, vsi_num, prof_id);
864 ice_flow_rem_entry(hw, ICE_BLK_FD, entry_1);
866 ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
872 ice_fdir_input_set_parse(uint64_t inset, enum ice_flow_field *field)
876 struct ice_inset_map {
878 enum ice_flow_field fld;
880 static const struct ice_inset_map ice_inset_map[] = {
881 {ICE_INSET_DMAC, ICE_FLOW_FIELD_IDX_ETH_DA},
882 {ICE_INSET_ETHERTYPE, ICE_FLOW_FIELD_IDX_ETH_TYPE},
883 {ICE_INSET_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
884 {ICE_INSET_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
885 {ICE_INSET_IPV4_TOS, ICE_FLOW_FIELD_IDX_IPV4_DSCP},
886 {ICE_INSET_IPV4_TTL, ICE_FLOW_FIELD_IDX_IPV4_TTL},
887 {ICE_INSET_IPV4_PROTO, ICE_FLOW_FIELD_IDX_IPV4_PROT},
888 {ICE_INSET_IPV6_SRC, ICE_FLOW_FIELD_IDX_IPV6_SA},
889 {ICE_INSET_IPV6_DST, ICE_FLOW_FIELD_IDX_IPV6_DA},
890 {ICE_INSET_IPV6_TC, ICE_FLOW_FIELD_IDX_IPV6_DSCP},
891 {ICE_INSET_IPV6_NEXT_HDR, ICE_FLOW_FIELD_IDX_IPV6_PROT},
892 {ICE_INSET_IPV6_HOP_LIMIT, ICE_FLOW_FIELD_IDX_IPV6_TTL},
893 {ICE_INSET_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
894 {ICE_INSET_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
895 {ICE_INSET_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
896 {ICE_INSET_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
897 {ICE_INSET_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
898 {ICE_INSET_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
899 {ICE_INSET_TUN_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
900 {ICE_INSET_TUN_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
901 {ICE_INSET_TUN_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
902 {ICE_INSET_TUN_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
903 {ICE_INSET_TUN_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
904 {ICE_INSET_TUN_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
905 {ICE_INSET_TUN_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
906 {ICE_INSET_TUN_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
907 {ICE_INSET_GTPU_TEID, ICE_FLOW_FIELD_IDX_GTPU_IP_TEID},
908 {ICE_INSET_GTPU_QFI, ICE_FLOW_FIELD_IDX_GTPU_EH_QFI},
911 for (i = 0, j = 0; i < RTE_DIM(ice_inset_map); i++) {
912 if ((inset & ice_inset_map[i].inset) ==
913 ice_inset_map[i].inset)
914 field[j++] = ice_inset_map[i].fld;
919 ice_fdir_input_set_hdrs(enum ice_fltr_ptype flow, struct ice_flow_seg_info *seg)
922 case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
923 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
924 ICE_FLOW_SEG_HDR_IPV4 |
925 ICE_FLOW_SEG_HDR_IPV_OTHER);
927 case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
928 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
929 ICE_FLOW_SEG_HDR_IPV4 |
930 ICE_FLOW_SEG_HDR_IPV_OTHER);
932 case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
933 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
934 ICE_FLOW_SEG_HDR_IPV4 |
935 ICE_FLOW_SEG_HDR_IPV_OTHER);
937 case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
938 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4 |
939 ICE_FLOW_SEG_HDR_IPV_OTHER);
941 case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
942 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
943 ICE_FLOW_SEG_HDR_IPV6 |
944 ICE_FLOW_SEG_HDR_IPV_OTHER);
946 case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
947 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
948 ICE_FLOW_SEG_HDR_IPV6 |
949 ICE_FLOW_SEG_HDR_IPV_OTHER);
951 case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
952 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
953 ICE_FLOW_SEG_HDR_IPV6 |
954 ICE_FLOW_SEG_HDR_IPV_OTHER);
956 case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
957 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 |
958 ICE_FLOW_SEG_HDR_IPV_OTHER);
960 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP:
961 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP:
962 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP:
963 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER:
964 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_IP |
965 ICE_FLOW_SEG_HDR_IPV4 |
966 ICE_FLOW_SEG_HDR_IPV_OTHER);
968 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_OTHER:
969 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_EH |
970 ICE_FLOW_SEG_HDR_GTPU_IP |
971 ICE_FLOW_SEG_HDR_IPV4 |
972 ICE_FLOW_SEG_HDR_IPV_OTHER);
974 case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_IPV6_OTHER:
975 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_IP |
976 ICE_FLOW_SEG_HDR_IPV6 |
977 ICE_FLOW_SEG_HDR_IPV_OTHER);
979 case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_IPV6_OTHER:
980 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_EH |
981 ICE_FLOW_SEG_HDR_GTPU_IP |
982 ICE_FLOW_SEG_HDR_IPV6 |
983 ICE_FLOW_SEG_HDR_IPV_OTHER);
985 case ICE_FLTR_PTYPE_NON_IP_L2:
986 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH_NON_IP);
989 PMD_DRV_LOG(ERR, "not supported filter type.");
995 ice_fdir_input_set_conf(struct ice_pf *pf, enum ice_fltr_ptype flow,
996 uint64_t inner_input_set, uint64_t outer_input_set,
997 enum ice_fdir_tunnel_type ttype)
999 struct ice_flow_seg_info *seg;
1000 struct ice_flow_seg_info *seg_tun = NULL;
1001 enum ice_flow_field field[ICE_FLOW_FIELD_IDX_MAX];
1006 if (!(inner_input_set | outer_input_set))
1009 seg_tun = (struct ice_flow_seg_info *)
1010 ice_malloc(hw, sizeof(*seg_tun) * ICE_FD_HW_SEG_MAX);
1012 PMD_DRV_LOG(ERR, "No memory can be allocated");
1016 /* use seg_tun[1] to record tunnel inner part or non-tunnel */
1017 for (k = 0; k <= ICE_FD_HW_SEG_TUN; k++) {
1019 input_set = (k == ICE_FD_HW_SEG_TUN) ? inner_input_set : outer_input_set;
1023 for (i = 0; i < ICE_FLOW_FIELD_IDX_MAX; i++)
1024 field[i] = ICE_FLOW_FIELD_IDX_MAX;
1026 ice_fdir_input_set_parse(input_set, field);
1028 ice_fdir_input_set_hdrs(flow, seg);
1030 for (i = 0; field[i] != ICE_FLOW_FIELD_IDX_MAX; i++) {
1031 ice_flow_set_fld(seg, field[i],
1032 ICE_FLOW_FLD_OFF_INVAL,
1033 ICE_FLOW_FLD_OFF_INVAL,
1034 ICE_FLOW_FLD_OFF_INVAL, false);
1038 is_tunnel = ice_fdir_is_tunnel_profile(ttype);
1040 ret = ice_fdir_hw_tbl_conf(pf, pf->main_vsi, pf->fdir.fdir_vsi,
1041 seg_tun + 1, flow, false);
1043 ret = ice_fdir_hw_tbl_conf(pf, pf->main_vsi, pf->fdir.fdir_vsi,
1044 seg_tun, flow, true);
1049 } else if (ret < 0) {
1051 return (ret == -EEXIST) ? 0 : ret;
1058 ice_fdir_cnt_update(struct ice_pf *pf, enum ice_fltr_ptype ptype,
1059 bool is_tunnel, bool add)
1061 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1064 cnt = (add) ? 1 : -1;
1065 hw->fdir_active_fltr += cnt;
1066 if (ptype == ICE_FLTR_PTYPE_NONF_NONE || ptype >= ICE_FLTR_PTYPE_MAX)
1067 PMD_DRV_LOG(ERR, "Unknown filter type %d", ptype);
1069 pf->fdir_fltr_cnt[ptype][is_tunnel] += cnt;
1073 ice_fdir_init(struct ice_adapter *ad)
1075 struct ice_pf *pf = &ad->pf;
1076 struct ice_flow_parser *parser;
1079 if (ad->hw.dcf_enabled)
1082 ret = ice_fdir_setup(pf);
1086 parser = &ice_fdir_parser;
1088 return ice_register_parser(parser, ad);
1092 ice_fdir_uninit(struct ice_adapter *ad)
1094 struct ice_flow_parser *parser;
1095 struct ice_pf *pf = &ad->pf;
1097 if (ad->hw.dcf_enabled)
1100 parser = &ice_fdir_parser;
1102 ice_unregister_parser(parser, ad);
1104 ice_fdir_teardown(pf);
1108 ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type)
1110 if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN)
1117 ice_fdir_add_del_filter(struct ice_pf *pf,
1118 struct ice_fdir_filter_conf *filter,
1121 struct ice_fltr_desc desc;
1122 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1123 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1127 filter->input.dest_vsi = pf->main_vsi->idx;
1129 memset(&desc, 0, sizeof(desc));
1130 filter->input.comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW;
1131 ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add);
1133 is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1135 memset(pkt, 0, ICE_FDIR_PKT_LEN);
1136 ret = ice_fdir_get_gen_prgm_pkt(hw, &filter->input, pkt, false, is_tun);
1138 PMD_DRV_LOG(ERR, "Generate dummy packet failed");
1142 return ice_fdir_programming(pf, &desc);
1146 ice_fdir_extract_fltr_key(struct ice_fdir_fltr_pattern *key,
1147 struct ice_fdir_filter_conf *filter)
1149 struct ice_fdir_fltr *input = &filter->input;
1150 memset(key, 0, sizeof(*key));
1152 key->flow_type = input->flow_type;
1153 rte_memcpy(&key->ip, &input->ip, sizeof(key->ip));
1154 rte_memcpy(&key->mask, &input->mask, sizeof(key->mask));
1155 rte_memcpy(&key->ext_data, &input->ext_data, sizeof(key->ext_data));
1156 rte_memcpy(&key->ext_mask, &input->ext_mask, sizeof(key->ext_mask));
1158 rte_memcpy(&key->gtpu_data, &input->gtpu_data, sizeof(key->gtpu_data));
1159 rte_memcpy(&key->gtpu_mask, &input->gtpu_mask, sizeof(key->gtpu_mask));
1161 key->tunnel_type = filter->tunnel_type;
1164 /* Check if there exists the flow director filter */
1165 static struct ice_fdir_filter_conf *
1166 ice_fdir_entry_lookup(struct ice_fdir_info *fdir_info,
1167 const struct ice_fdir_fltr_pattern *key)
1171 ret = rte_hash_lookup(fdir_info->hash_table, key);
1175 return fdir_info->hash_map[ret];
1178 /* Add a flow director entry into the SW list */
1180 ice_fdir_entry_insert(struct ice_pf *pf,
1181 struct ice_fdir_filter_conf *entry,
1182 struct ice_fdir_fltr_pattern *key)
1184 struct ice_fdir_info *fdir_info = &pf->fdir;
1187 ret = rte_hash_add_key(fdir_info->hash_table, key);
1190 "Failed to insert fdir entry to hash table %d!",
1194 fdir_info->hash_map[ret] = entry;
1199 /* Delete a flow director entry from the SW list */
1201 ice_fdir_entry_del(struct ice_pf *pf, struct ice_fdir_fltr_pattern *key)
1203 struct ice_fdir_info *fdir_info = &pf->fdir;
1206 ret = rte_hash_del_key(fdir_info->hash_table, key);
1209 "Failed to delete fdir filter to hash table %d!",
1213 fdir_info->hash_map[ret] = NULL;
1219 ice_fdir_create_filter(struct ice_adapter *ad,
1220 struct rte_flow *flow,
1222 struct rte_flow_error *error)
1224 struct ice_pf *pf = &ad->pf;
1225 struct ice_fdir_filter_conf *filter = meta;
1226 struct ice_fdir_info *fdir_info = &pf->fdir;
1227 struct ice_fdir_filter_conf *entry, *node;
1228 struct ice_fdir_fltr_pattern key;
1232 ice_fdir_extract_fltr_key(&key, filter);
1233 node = ice_fdir_entry_lookup(fdir_info, &key);
1235 rte_flow_error_set(error, EEXIST,
1236 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1237 "Rule already exists!");
1241 entry = rte_zmalloc("fdir_entry", sizeof(*entry), 0);
1243 rte_flow_error_set(error, ENOMEM,
1244 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1245 "Failed to allocate memory");
1249 is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1251 ret = ice_fdir_input_set_conf(pf, filter->input.flow_type,
1252 filter->input_set, filter->outer_input_set,
1253 filter->tunnel_type);
1255 rte_flow_error_set(error, -ret,
1256 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1257 "Profile configure failed.");
1261 /* alloc counter for FDIR */
1262 if (filter->input.cnt_ena) {
1263 struct rte_flow_action_count *act_count = &filter->act_count;
1265 filter->counter = ice_fdir_counter_alloc(pf,
1268 if (!filter->counter) {
1269 rte_flow_error_set(error, EINVAL,
1270 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1271 "Failed to alloc FDIR counter.");
1274 filter->input.cnt_index = filter->counter->hw_index;
1277 ret = ice_fdir_add_del_filter(pf, filter, true);
1279 rte_flow_error_set(error, -ret,
1280 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1281 "Add filter rule failed.");
1285 if (filter->mark_flag == 1)
1286 ice_fdir_rx_parsing_enable(ad, 1);
1288 rte_memcpy(entry, filter, sizeof(*entry));
1289 ret = ice_fdir_entry_insert(pf, entry, &key);
1291 rte_flow_error_set(error, -ret,
1292 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1293 "Insert entry to table failed.");
1298 ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, true);
1303 if (filter->counter) {
1304 ice_fdir_counter_free(pf, filter->counter);
1305 filter->counter = NULL;
1314 ice_fdir_destroy_filter(struct ice_adapter *ad,
1315 struct rte_flow *flow,
1316 struct rte_flow_error *error)
1318 struct ice_pf *pf = &ad->pf;
1319 struct ice_fdir_info *fdir_info = &pf->fdir;
1320 struct ice_fdir_filter_conf *filter, *entry;
1321 struct ice_fdir_fltr_pattern key;
1325 filter = (struct ice_fdir_filter_conf *)flow->rule;
1327 is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1329 if (filter->counter) {
1330 ice_fdir_counter_free(pf, filter->counter);
1331 filter->counter = NULL;
1334 ice_fdir_extract_fltr_key(&key, filter);
1335 entry = ice_fdir_entry_lookup(fdir_info, &key);
1337 rte_flow_error_set(error, ENOENT,
1338 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1339 "Can't find entry.");
1343 ret = ice_fdir_add_del_filter(pf, filter, false);
1345 rte_flow_error_set(error, -ret,
1346 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1347 "Del filter rule failed.");
1351 ret = ice_fdir_entry_del(pf, &key);
1353 rte_flow_error_set(error, -ret,
1354 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1355 "Remove entry from table failed.");
1359 ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, false);
1361 if (filter->mark_flag == 1)
1362 ice_fdir_rx_parsing_enable(ad, 0);
1372 ice_fdir_query_count(struct ice_adapter *ad,
1373 struct rte_flow *flow,
1374 struct rte_flow_query_count *flow_stats,
1375 struct rte_flow_error *error)
1377 struct ice_pf *pf = &ad->pf;
1378 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1379 struct ice_fdir_filter_conf *filter = flow->rule;
1380 struct ice_fdir_counter *counter = filter->counter;
1381 uint64_t hits_lo, hits_hi;
1384 rte_flow_error_set(error, EINVAL,
1385 RTE_FLOW_ERROR_TYPE_ACTION,
1387 "FDIR counters not available");
1392 * Reading the low 32-bits latches the high 32-bits into a shadow
1393 * register. Reading the high 32-bit returns the value in the
1396 hits_lo = ICE_READ_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index));
1397 hits_hi = ICE_READ_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index));
1399 flow_stats->hits_set = 1;
1400 flow_stats->hits = hits_lo | (hits_hi << 32);
1401 flow_stats->bytes_set = 0;
1402 flow_stats->bytes = 0;
1404 if (flow_stats->reset) {
1405 /* reset statistic counter value */
1406 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index), 0);
1407 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index), 0);
1413 static struct ice_flow_engine ice_fdir_engine = {
1414 .init = ice_fdir_init,
1415 .uninit = ice_fdir_uninit,
1416 .create = ice_fdir_create_filter,
1417 .destroy = ice_fdir_destroy_filter,
1418 .query_count = ice_fdir_query_count,
1419 .type = ICE_FLOW_ENGINE_FDIR,
1423 ice_fdir_parse_action_qregion(struct ice_pf *pf,
1424 struct rte_flow_error *error,
1425 const struct rte_flow_action *act,
1426 struct ice_fdir_filter_conf *filter)
1428 const struct rte_flow_action_rss *rss = act->conf;
1431 if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
1432 rte_flow_error_set(error, EINVAL,
1433 RTE_FLOW_ERROR_TYPE_ACTION, act,
1438 if (rss->queue_num <= 1) {
1439 rte_flow_error_set(error, EINVAL,
1440 RTE_FLOW_ERROR_TYPE_ACTION, act,
1441 "Queue region size can't be 0 or 1.");
1445 /* check if queue index for queue region is continuous */
1446 for (i = 0; i < rss->queue_num - 1; i++) {
1447 if (rss->queue[i + 1] != rss->queue[i] + 1) {
1448 rte_flow_error_set(error, EINVAL,
1449 RTE_FLOW_ERROR_TYPE_ACTION, act,
1450 "Discontinuous queue region");
1455 if (rss->queue[rss->queue_num - 1] >= pf->dev_data->nb_rx_queues) {
1456 rte_flow_error_set(error, EINVAL,
1457 RTE_FLOW_ERROR_TYPE_ACTION, act,
1458 "Invalid queue region indexes.");
1462 if (!(rte_is_power_of_2(rss->queue_num) &&
1463 (rss->queue_num <= ICE_FDIR_MAX_QREGION_SIZE))) {
1464 rte_flow_error_set(error, EINVAL,
1465 RTE_FLOW_ERROR_TYPE_ACTION, act,
1466 "The region size should be any of the following values:"
1467 "1, 2, 4, 8, 16, 32, 64, 128 as long as the total number "
1468 "of queues do not exceed the VSI allocation.");
1472 filter->input.q_index = rss->queue[0];
1473 filter->input.q_region = rte_fls_u32(rss->queue_num) - 1;
1474 filter->input.dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
1480 ice_fdir_parse_action(struct ice_adapter *ad,
1481 const struct rte_flow_action actions[],
1482 struct rte_flow_error *error,
1483 struct ice_fdir_filter_conf *filter)
1485 struct ice_pf *pf = &ad->pf;
1486 const struct rte_flow_action_queue *act_q;
1487 const struct rte_flow_action_mark *mark_spec = NULL;
1488 const struct rte_flow_action_count *act_count;
1489 uint32_t dest_num = 0;
1490 uint32_t mark_num = 0;
1491 uint32_t counter_num = 0;
1494 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1495 switch (actions->type) {
1496 case RTE_FLOW_ACTION_TYPE_VOID:
1498 case RTE_FLOW_ACTION_TYPE_QUEUE:
1501 act_q = actions->conf;
1502 filter->input.q_index = act_q->index;
1503 if (filter->input.q_index >=
1504 pf->dev_data->nb_rx_queues) {
1505 rte_flow_error_set(error, EINVAL,
1506 RTE_FLOW_ERROR_TYPE_ACTION,
1508 "Invalid queue for FDIR.");
1511 filter->input.dest_ctl =
1512 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
1514 case RTE_FLOW_ACTION_TYPE_DROP:
1517 filter->input.dest_ctl =
1518 ICE_FLTR_PRGM_DESC_DEST_DROP_PKT;
1520 case RTE_FLOW_ACTION_TYPE_PASSTHRU:
1523 filter->input.dest_ctl =
1524 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER;
1526 case RTE_FLOW_ACTION_TYPE_RSS:
1529 ret = ice_fdir_parse_action_qregion(pf,
1530 error, actions, filter);
1534 case RTE_FLOW_ACTION_TYPE_MARK:
1536 filter->mark_flag = 1;
1537 mark_spec = actions->conf;
1538 filter->input.fltr_id = mark_spec->id;
1539 filter->input.fdid_prio = ICE_FXD_FLTR_QW1_FDID_PRI_ONE;
1541 case RTE_FLOW_ACTION_TYPE_COUNT:
1544 act_count = actions->conf;
1545 filter->input.cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
1546 rte_memcpy(&filter->act_count, act_count,
1547 sizeof(filter->act_count));
1551 rte_flow_error_set(error, EINVAL,
1552 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1558 if (dest_num >= 2) {
1559 rte_flow_error_set(error, EINVAL,
1560 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1561 "Unsupported action combination");
1565 if (mark_num >= 2) {
1566 rte_flow_error_set(error, EINVAL,
1567 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1568 "Too many mark actions");
1572 if (counter_num >= 2) {
1573 rte_flow_error_set(error, EINVAL,
1574 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1575 "Too many count actions");
1579 if (dest_num + mark_num + counter_num == 0) {
1580 rte_flow_error_set(error, EINVAL,
1581 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1586 /* set default action to PASSTHRU mode, in "mark/count only" case. */
1588 filter->input.dest_ctl =
1589 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER;
1595 ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
1596 const struct rte_flow_item pattern[],
1597 struct rte_flow_error *error,
1598 struct ice_fdir_filter_conf *filter)
1600 const struct rte_flow_item *item = pattern;
1601 enum rte_flow_item_type item_type;
1602 enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
1603 enum ice_fdir_tunnel_type tunnel_type = ICE_FDIR_TUNNEL_TYPE_NONE;
1604 const struct rte_flow_item_eth *eth_spec, *eth_mask;
1605 const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
1606 const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
1607 const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
1608 const struct rte_flow_item_udp *udp_spec, *udp_mask;
1609 const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
1610 const struct rte_flow_item_vxlan *vxlan_spec, *vxlan_mask;
1611 const struct rte_flow_item_gtp *gtp_spec, *gtp_mask;
1612 const struct rte_flow_item_gtp_psc *gtp_psc_spec, *gtp_psc_mask;
1613 uint64_t input_set = ICE_INSET_NONE;
1614 uint8_t flow_type = ICE_FLTR_PTYPE_NONF_NONE;
1615 uint8_t ipv6_addr_mask[16] = {
1616 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1617 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
1619 uint32_t vtc_flow_cpu;
1620 uint16_t ether_type;
1621 enum rte_flow_item_type next_type;
1623 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1625 rte_flow_error_set(error, EINVAL,
1626 RTE_FLOW_ERROR_TYPE_ITEM,
1628 "Not support range");
1631 item_type = item->type;
1633 switch (item_type) {
1634 case RTE_FLOW_ITEM_TYPE_ETH:
1635 eth_spec = item->spec;
1636 eth_mask = item->mask;
1637 next_type = (item + 1)->type;
1639 if (eth_spec && eth_mask) {
1640 if (!rte_is_zero_ether_addr(ð_mask->dst)) {
1641 input_set |= ICE_INSET_DMAC;
1642 rte_memcpy(&filter->input.ext_data.dst_mac,
1644 RTE_ETHER_ADDR_LEN);
1647 if (!rte_is_zero_ether_addr(ð_mask->src)) {
1648 input_set |= ICE_INSET_SMAC;
1649 rte_memcpy(&filter->input.ext_data.src_mac,
1651 RTE_ETHER_ADDR_LEN);
1654 /* Ignore this field except for ICE_FLTR_PTYPE_NON_IP_L2 */
1655 if (eth_mask->type == RTE_BE16(0xffff) &&
1656 next_type == RTE_FLOW_ITEM_TYPE_END) {
1657 input_set |= ICE_INSET_ETHERTYPE;
1658 ether_type = rte_be_to_cpu_16(eth_spec->type);
1660 if (ether_type == RTE_ETHER_TYPE_IPV4 ||
1661 ether_type == RTE_ETHER_TYPE_IPV6) {
1662 rte_flow_error_set(error, EINVAL,
1663 RTE_FLOW_ERROR_TYPE_ITEM,
1665 "Unsupported ether_type.");
1669 rte_memcpy(&filter->input.ext_data.ether_type,
1671 sizeof(eth_spec->type));
1672 flow_type = ICE_FLTR_PTYPE_NON_IP_L2;
1676 case RTE_FLOW_ITEM_TYPE_IPV4:
1677 l3 = RTE_FLOW_ITEM_TYPE_IPV4;
1678 ipv4_spec = item->spec;
1679 ipv4_mask = item->mask;
1681 if (ipv4_spec && ipv4_mask) {
1682 /* Check IPv4 mask and update input set */
1683 if (ipv4_mask->hdr.version_ihl ||
1684 ipv4_mask->hdr.total_length ||
1685 ipv4_mask->hdr.packet_id ||
1686 ipv4_mask->hdr.fragment_offset ||
1687 ipv4_mask->hdr.hdr_checksum) {
1688 rte_flow_error_set(error, EINVAL,
1689 RTE_FLOW_ERROR_TYPE_ITEM,
1691 "Invalid IPv4 mask.");
1694 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
1695 input_set |= tunnel_type ?
1696 ICE_INSET_TUN_IPV4_SRC :
1698 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
1699 input_set |= tunnel_type ?
1700 ICE_INSET_TUN_IPV4_DST :
1702 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
1703 input_set |= ICE_INSET_IPV4_TOS;
1704 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
1705 input_set |= ICE_INSET_IPV4_TTL;
1706 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
1707 input_set |= ICE_INSET_IPV4_PROTO;
1709 filter->input.ip.v4.dst_ip =
1710 ipv4_spec->hdr.dst_addr;
1711 filter->input.ip.v4.src_ip =
1712 ipv4_spec->hdr.src_addr;
1713 filter->input.ip.v4.tos =
1714 ipv4_spec->hdr.type_of_service;
1715 filter->input.ip.v4.ttl =
1716 ipv4_spec->hdr.time_to_live;
1717 filter->input.ip.v4.proto =
1718 ipv4_spec->hdr.next_proto_id;
1721 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
1723 case RTE_FLOW_ITEM_TYPE_IPV6:
1724 l3 = RTE_FLOW_ITEM_TYPE_IPV6;
1725 ipv6_spec = item->spec;
1726 ipv6_mask = item->mask;
1728 if (ipv6_spec && ipv6_mask) {
1729 /* Check IPv6 mask and update input set */
1730 if (ipv6_mask->hdr.payload_len) {
1731 rte_flow_error_set(error, EINVAL,
1732 RTE_FLOW_ERROR_TYPE_ITEM,
1734 "Invalid IPv6 mask");
1738 if (!memcmp(ipv6_mask->hdr.src_addr,
1740 RTE_DIM(ipv6_mask->hdr.src_addr)))
1741 input_set |= ICE_INSET_IPV6_SRC;
1742 if (!memcmp(ipv6_mask->hdr.dst_addr,
1744 RTE_DIM(ipv6_mask->hdr.dst_addr)))
1745 input_set |= ICE_INSET_IPV6_DST;
1747 if ((ipv6_mask->hdr.vtc_flow &
1748 rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
1749 == rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
1750 input_set |= ICE_INSET_IPV6_TC;
1751 if (ipv6_mask->hdr.proto == UINT8_MAX)
1752 input_set |= ICE_INSET_IPV6_NEXT_HDR;
1753 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
1754 input_set |= ICE_INSET_IPV6_HOP_LIMIT;
1756 rte_memcpy(filter->input.ip.v6.dst_ip,
1757 ipv6_spec->hdr.dst_addr, 16);
1758 rte_memcpy(filter->input.ip.v6.src_ip,
1759 ipv6_spec->hdr.src_addr, 16);
1762 rte_be_to_cpu_32(ipv6_spec->hdr.vtc_flow);
1763 filter->input.ip.v6.tc =
1764 (uint8_t)(vtc_flow_cpu >>
1765 ICE_FDIR_IPV6_TC_OFFSET);
1766 filter->input.ip.v6.proto =
1767 ipv6_spec->hdr.proto;
1768 filter->input.ip.v6.hlim =
1769 ipv6_spec->hdr.hop_limits;
1772 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
1774 case RTE_FLOW_ITEM_TYPE_TCP:
1775 tcp_spec = item->spec;
1776 tcp_mask = item->mask;
1778 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
1779 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
1780 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
1781 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
1783 if (tcp_spec && tcp_mask) {
1784 /* Check TCP mask and update input set */
1785 if (tcp_mask->hdr.sent_seq ||
1786 tcp_mask->hdr.recv_ack ||
1787 tcp_mask->hdr.data_off ||
1788 tcp_mask->hdr.tcp_flags ||
1789 tcp_mask->hdr.rx_win ||
1790 tcp_mask->hdr.cksum ||
1791 tcp_mask->hdr.tcp_urp) {
1792 rte_flow_error_set(error, EINVAL,
1793 RTE_FLOW_ERROR_TYPE_ITEM,
1795 "Invalid TCP mask");
1799 if (tcp_mask->hdr.src_port == UINT16_MAX)
1800 input_set |= tunnel_type ?
1801 ICE_INSET_TUN_TCP_SRC_PORT :
1802 ICE_INSET_TCP_SRC_PORT;
1803 if (tcp_mask->hdr.dst_port == UINT16_MAX)
1804 input_set |= tunnel_type ?
1805 ICE_INSET_TUN_TCP_DST_PORT :
1806 ICE_INSET_TCP_DST_PORT;
1808 /* Get filter info */
1809 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1810 filter->input.ip.v4.dst_port =
1811 tcp_spec->hdr.dst_port;
1812 filter->input.ip.v4.src_port =
1813 tcp_spec->hdr.src_port;
1814 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1815 filter->input.ip.v6.dst_port =
1816 tcp_spec->hdr.dst_port;
1817 filter->input.ip.v6.src_port =
1818 tcp_spec->hdr.src_port;
1822 case RTE_FLOW_ITEM_TYPE_UDP:
1823 udp_spec = item->spec;
1824 udp_mask = item->mask;
1826 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
1827 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
1828 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
1829 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
1831 if (udp_spec && udp_mask) {
1832 /* Check UDP mask and update input set*/
1833 if (udp_mask->hdr.dgram_len ||
1834 udp_mask->hdr.dgram_cksum) {
1835 rte_flow_error_set(error, EINVAL,
1836 RTE_FLOW_ERROR_TYPE_ITEM,
1838 "Invalid UDP mask");
1842 if (udp_mask->hdr.src_port == UINT16_MAX)
1843 input_set |= tunnel_type ?
1844 ICE_INSET_TUN_UDP_SRC_PORT :
1845 ICE_INSET_UDP_SRC_PORT;
1846 if (udp_mask->hdr.dst_port == UINT16_MAX)
1847 input_set |= tunnel_type ?
1848 ICE_INSET_TUN_UDP_DST_PORT :
1849 ICE_INSET_UDP_DST_PORT;
1851 /* Get filter info */
1852 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1853 filter->input.ip.v4.dst_port =
1854 udp_spec->hdr.dst_port;
1855 filter->input.ip.v4.src_port =
1856 udp_spec->hdr.src_port;
1857 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1858 filter->input.ip.v6.src_port =
1859 udp_spec->hdr.src_port;
1860 filter->input.ip.v6.dst_port =
1861 udp_spec->hdr.dst_port;
1865 case RTE_FLOW_ITEM_TYPE_SCTP:
1866 sctp_spec = item->spec;
1867 sctp_mask = item->mask;
1869 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
1870 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
1871 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
1872 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
1874 if (sctp_spec && sctp_mask) {
1875 /* Check SCTP mask and update input set */
1876 if (sctp_mask->hdr.cksum) {
1877 rte_flow_error_set(error, EINVAL,
1878 RTE_FLOW_ERROR_TYPE_ITEM,
1880 "Invalid UDP mask");
1884 if (sctp_mask->hdr.src_port == UINT16_MAX)
1885 input_set |= tunnel_type ?
1886 ICE_INSET_TUN_SCTP_SRC_PORT :
1887 ICE_INSET_SCTP_SRC_PORT;
1888 if (sctp_mask->hdr.dst_port == UINT16_MAX)
1889 input_set |= tunnel_type ?
1890 ICE_INSET_TUN_SCTP_DST_PORT :
1891 ICE_INSET_SCTP_DST_PORT;
1893 /* Get filter info */
1894 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1895 filter->input.ip.v4.dst_port =
1896 sctp_spec->hdr.dst_port;
1897 filter->input.ip.v4.src_port =
1898 sctp_spec->hdr.src_port;
1899 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1900 filter->input.ip.v6.dst_port =
1901 sctp_spec->hdr.dst_port;
1902 filter->input.ip.v6.src_port =
1903 sctp_spec->hdr.src_port;
1907 case RTE_FLOW_ITEM_TYPE_VOID:
1909 case RTE_FLOW_ITEM_TYPE_VXLAN:
1910 l3 = RTE_FLOW_ITEM_TYPE_END;
1911 vxlan_spec = item->spec;
1912 vxlan_mask = item->mask;
1914 if (vxlan_spec || vxlan_mask) {
1915 rte_flow_error_set(error, EINVAL,
1916 RTE_FLOW_ERROR_TYPE_ITEM,
1918 "Invalid vxlan field");
1922 tunnel_type = ICE_FDIR_TUNNEL_TYPE_VXLAN;
1924 case RTE_FLOW_ITEM_TYPE_GTPU:
1925 l3 = RTE_FLOW_ITEM_TYPE_END;
1926 gtp_spec = item->spec;
1927 gtp_mask = item->mask;
1929 if (gtp_spec && gtp_mask) {
1930 if (gtp_mask->v_pt_rsv_flags ||
1931 gtp_mask->msg_type ||
1932 gtp_mask->msg_len) {
1933 rte_flow_error_set(error, EINVAL,
1934 RTE_FLOW_ERROR_TYPE_ITEM,
1936 "Invalid GTP mask");
1940 if (gtp_mask->teid == UINT32_MAX)
1941 input_set |= ICE_INSET_GTPU_TEID;
1943 filter->input.gtpu_data.teid = gtp_spec->teid;
1946 tunnel_type = ICE_FDIR_TUNNEL_TYPE_GTPU;
1948 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
1949 gtp_psc_spec = item->spec;
1950 gtp_psc_mask = item->mask;
1952 if (gtp_psc_spec && gtp_psc_mask) {
1953 if (gtp_psc_mask->qfi == UINT8_MAX)
1954 input_set |= ICE_INSET_GTPU_QFI;
1956 filter->input.gtpu_data.qfi =
1959 tunnel_type = ICE_FDIR_TUNNEL_TYPE_GTPU_EH;
1962 rte_flow_error_set(error, EINVAL,
1963 RTE_FLOW_ERROR_TYPE_ITEM,
1965 "Invalid pattern item.");
1970 if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU &&
1971 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
1972 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER;
1973 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU_EH &&
1974 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
1975 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH_IPV4_OTHER;
1976 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU &&
1977 flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
1978 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_GTPU_IPV6_OTHER;
1979 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU_EH &&
1980 flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
1981 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH_IPV6_OTHER;
1983 filter->tunnel_type = tunnel_type;
1984 filter->input.flow_type = flow_type;
1985 filter->input_set = input_set;
1991 ice_fdir_parse(struct ice_adapter *ad,
1992 struct ice_pattern_match_item *array,
1994 const struct rte_flow_item pattern[],
1995 const struct rte_flow_action actions[],
1997 struct rte_flow_error *error)
1999 struct ice_pf *pf = &ad->pf;
2000 struct ice_fdir_filter_conf *filter = &pf->fdir.conf;
2001 struct ice_pattern_match_item *item = NULL;
2005 memset(filter, 0, sizeof(*filter));
2006 item = ice_search_pattern_match_item(ad, pattern, array, array_len,
2011 ret = ice_fdir_parse_pattern(ad, pattern, error, filter);
2014 input_set = filter->input_set | filter->outer_input_set;
2015 if (!input_set || input_set & ~item->input_set_mask) {
2016 rte_flow_error_set(error, EINVAL,
2017 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2019 "Invalid input set");
2024 ret = ice_fdir_parse_action(ad, actions, error, filter);
2035 static struct ice_flow_parser ice_fdir_parser = {
2036 .engine = &ice_fdir_engine,
2037 .array = ice_fdir_pattern_list,
2038 .array_len = RTE_DIM(ice_fdir_pattern_list),
2039 .parse_pattern_action = ice_fdir_parse,
2040 .stage = ICE_FLOW_STAGE_DISTRIBUTOR,
2043 RTE_INIT(ice_fdir_engine_register)
2045 ice_register_flow_engine(&ice_fdir_engine);