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 | ICE_INSET_IPV4_PKID)
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 | \
47 #define ICE_FDIR_INSET_ETH_IPV6_UDP (\
48 ICE_FDIR_INSET_ETH_IPV6 | \
49 ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
51 #define ICE_FDIR_INSET_ETH_IPV6_TCP (\
52 ICE_FDIR_INSET_ETH_IPV6 | \
53 ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
55 #define ICE_FDIR_INSET_ETH_IPV6_SCTP (\
56 ICE_FDIR_INSET_ETH_IPV6 | \
57 ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
59 #define ICE_FDIR_INSET_IPV4 (\
60 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
63 #define ICE_FDIR_INSET_IPV4_TCP (\
64 ICE_FDIR_INSET_IPV4 | \
65 ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
67 #define ICE_FDIR_INSET_IPV4_UDP (\
68 ICE_FDIR_INSET_IPV4 | \
69 ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
71 #define ICE_FDIR_INSET_IPV4_SCTP (\
72 ICE_FDIR_INSET_IPV4 | \
73 ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
75 #define ICE_FDIR_INSET_ETH_IPV4_VXLAN (\
76 ICE_FDIR_INSET_ETH | ICE_FDIR_INSET_ETH_IPV4 | \
79 #define ICE_FDIR_INSET_IPV4_GTPU (\
80 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_GTPU_TEID)
82 #define ICE_FDIR_INSET_IPV4_GTPU_EH (\
83 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
84 ICE_INSET_GTPU_TEID | ICE_INSET_GTPU_QFI)
86 #define ICE_FDIR_INSET_IPV6_GTPU (\
87 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_GTPU_TEID)
89 #define ICE_FDIR_INSET_IPV6_GTPU_EH (\
90 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
91 ICE_INSET_GTPU_TEID | ICE_INSET_GTPU_QFI)
93 #define ICE_FDIR_INSET_IPV4_ESP (\
94 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
97 #define ICE_FDIR_INSET_IPV6_ESP (\
98 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
101 #define ICE_FDIR_INSET_IPV4_NATT_ESP (\
102 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | \
103 ICE_INSET_NAT_T_ESP_SPI)
105 #define ICE_FDIR_INSET_IPV6_NATT_ESP (\
106 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | \
107 ICE_INSET_NAT_T_ESP_SPI)
109 static struct ice_pattern_match_item ice_fdir_pattern_list[] = {
110 {pattern_raw, ICE_INSET_NONE, ICE_INSET_NONE, ICE_INSET_NONE},
111 {pattern_ethertype, ICE_FDIR_INSET_ETH, ICE_INSET_NONE, ICE_INSET_NONE},
112 {pattern_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4, ICE_INSET_NONE, ICE_INSET_NONE},
113 {pattern_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_UDP, ICE_INSET_NONE, ICE_INSET_NONE},
114 {pattern_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_TCP, ICE_INSET_NONE, ICE_INSET_NONE},
115 {pattern_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_SCTP, ICE_INSET_NONE, ICE_INSET_NONE},
116 {pattern_eth_ipv6, ICE_FDIR_INSET_ETH_IPV6, ICE_INSET_NONE, ICE_INSET_NONE},
117 {pattern_eth_ipv6_frag_ext, ICE_FDIR_INSET_ETH_IPV6, ICE_INSET_NONE, ICE_INSET_NONE},
118 {pattern_eth_ipv6_udp, ICE_FDIR_INSET_ETH_IPV6_UDP, ICE_INSET_NONE, ICE_INSET_NONE},
119 {pattern_eth_ipv6_tcp, ICE_FDIR_INSET_ETH_IPV6_TCP, ICE_INSET_NONE, ICE_INSET_NONE},
120 {pattern_eth_ipv6_sctp, ICE_FDIR_INSET_ETH_IPV6_SCTP, ICE_INSET_NONE, ICE_INSET_NONE},
121 {pattern_eth_ipv4_esp, ICE_FDIR_INSET_IPV4_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
122 {pattern_eth_ipv4_udp_esp, ICE_FDIR_INSET_IPV4_NATT_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
123 {pattern_eth_ipv6_esp, ICE_FDIR_INSET_IPV6_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
124 {pattern_eth_ipv6_udp_esp, ICE_FDIR_INSET_IPV6_NATT_ESP, ICE_INSET_NONE, ICE_INSET_NONE},
125 {pattern_eth_ipv4_udp_vxlan_ipv4, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4, ICE_INSET_NONE},
126 {pattern_eth_ipv4_udp_vxlan_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4_UDP, ICE_INSET_NONE},
127 {pattern_eth_ipv4_udp_vxlan_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4_TCP, ICE_INSET_NONE},
128 {pattern_eth_ipv4_udp_vxlan_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_IPV4_SCTP, ICE_INSET_NONE},
129 {pattern_eth_ipv4_udp_vxlan_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4, ICE_INSET_NONE},
130 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4_UDP, ICE_INSET_NONE},
131 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4_TCP, ICE_INSET_NONE},
132 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_VXLAN, ICE_FDIR_INSET_ETH_IPV4_SCTP, ICE_INSET_NONE},
133 /* duplicated GTPU input set in 3rd column to align with shared code behavior. Ideally, only put GTPU field in 2nd column. */
134 {pattern_eth_ipv4_gtpu, ICE_FDIR_INSET_IPV4_GTPU, ICE_FDIR_INSET_IPV4_GTPU, ICE_INSET_NONE},
135 {pattern_eth_ipv4_gtpu_eh, ICE_FDIR_INSET_IPV4_GTPU_EH, ICE_FDIR_INSET_IPV4_GTPU_EH, ICE_INSET_NONE},
136 {pattern_eth_ipv6_gtpu, ICE_FDIR_INSET_IPV6_GTPU, ICE_FDIR_INSET_IPV6_GTPU, ICE_INSET_NONE},
137 {pattern_eth_ipv6_gtpu_eh, ICE_FDIR_INSET_IPV6_GTPU_EH, ICE_FDIR_INSET_IPV6_GTPU_EH, ICE_INSET_NONE},
140 static struct ice_flow_parser ice_fdir_parser;
143 ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type);
145 static const struct rte_memzone *
146 ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
148 const struct rte_memzone *mz;
150 mz = rte_memzone_lookup(name);
154 return rte_memzone_reserve_aligned(name, len, socket_id,
155 RTE_MEMZONE_IOVA_CONTIG,
156 ICE_RING_BASE_ALIGN);
159 #define ICE_FDIR_MZ_NAME "FDIR_MEMZONE"
162 ice_fdir_prof_alloc(struct ice_hw *hw)
164 enum ice_fltr_ptype ptype, fltr_ptype;
166 if (!hw->fdir_prof) {
167 hw->fdir_prof = (struct ice_fd_hw_prof **)
168 ice_malloc(hw, ICE_FLTR_PTYPE_MAX *
169 sizeof(*hw->fdir_prof));
173 for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
174 ptype < ICE_FLTR_PTYPE_MAX;
176 if (!hw->fdir_prof[ptype]) {
177 hw->fdir_prof[ptype] = (struct ice_fd_hw_prof *)
178 ice_malloc(hw, sizeof(**hw->fdir_prof));
179 if (!hw->fdir_prof[ptype])
186 for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
189 rte_free(hw->fdir_prof[fltr_ptype]);
190 hw->fdir_prof[fltr_ptype] = NULL;
193 rte_free(hw->fdir_prof);
194 hw->fdir_prof = NULL;
200 ice_fdir_counter_pool_add(__rte_unused struct ice_pf *pf,
201 struct ice_fdir_counter_pool_container *container,
202 uint32_t index_start,
205 struct ice_fdir_counter_pool *pool;
209 pool = rte_zmalloc("ice_fdir_counter_pool",
211 sizeof(struct ice_fdir_counter) * len,
215 "Failed to allocate memory for fdir counter pool");
219 TAILQ_INIT(&pool->counter_list);
220 TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
222 for (i = 0; i < len; i++) {
223 struct ice_fdir_counter *counter = &pool->counters[i];
225 counter->hw_index = index_start + i;
226 TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
229 if (container->index_free == ICE_FDIR_COUNTER_MAX_POOL_SIZE) {
230 PMD_INIT_LOG(ERR, "FDIR counter pool is full");
235 container->pools[container->index_free++] = pool;
244 ice_fdir_counter_init(struct ice_pf *pf)
246 struct ice_hw *hw = ICE_PF_TO_HW(pf);
247 struct ice_fdir_info *fdir_info = &pf->fdir;
248 struct ice_fdir_counter_pool_container *container =
250 uint32_t cnt_index, len;
253 TAILQ_INIT(&container->pool_list);
255 cnt_index = ICE_FDIR_COUNTER_INDEX(hw->fd_ctr_base);
256 len = ICE_FDIR_COUNTERS_PER_BLOCK;
258 ret = ice_fdir_counter_pool_add(pf, container, cnt_index, len);
260 PMD_INIT_LOG(ERR, "Failed to add fdir pool to container");
268 ice_fdir_counter_release(struct ice_pf *pf)
270 struct ice_fdir_info *fdir_info = &pf->fdir;
271 struct ice_fdir_counter_pool_container *container =
275 for (i = 0; i < container->index_free; i++) {
276 rte_free(container->pools[i]);
277 container->pools[i] = NULL;
280 TAILQ_INIT(&container->pool_list);
281 container->index_free = 0;
286 static struct ice_fdir_counter *
287 ice_fdir_counter_shared_search(struct ice_fdir_counter_pool_container
291 struct ice_fdir_counter_pool *pool;
292 struct ice_fdir_counter *counter;
295 TAILQ_FOREACH(pool, &container->pool_list, next) {
296 for (i = 0; i < ICE_FDIR_COUNTERS_PER_BLOCK; i++) {
297 counter = &pool->counters[i];
299 if (counter->shared &&
309 static struct ice_fdir_counter *
310 ice_fdir_counter_alloc(struct ice_pf *pf, uint32_t shared, uint32_t id)
312 struct ice_hw *hw = ICE_PF_TO_HW(pf);
313 struct ice_fdir_info *fdir_info = &pf->fdir;
314 struct ice_fdir_counter_pool_container *container =
316 struct ice_fdir_counter_pool *pool = NULL;
317 struct ice_fdir_counter *counter_free = NULL;
320 counter_free = ice_fdir_counter_shared_search(container, id);
322 if (counter_free->ref_cnt + 1 == 0) {
326 counter_free->ref_cnt++;
331 TAILQ_FOREACH(pool, &container->pool_list, next) {
332 counter_free = TAILQ_FIRST(&pool->counter_list);
339 PMD_DRV_LOG(ERR, "No free counter found\n");
343 counter_free->shared = shared;
344 counter_free->id = id;
345 counter_free->ref_cnt = 1;
346 counter_free->pool = pool;
348 /* reset statistic counter value */
349 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter_free->hw_index), 0);
350 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter_free->hw_index), 0);
352 TAILQ_REMOVE(&pool->counter_list, counter_free, next);
353 if (TAILQ_EMPTY(&pool->counter_list)) {
354 TAILQ_REMOVE(&container->pool_list, pool, next);
355 TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
362 ice_fdir_counter_free(__rte_unused struct ice_pf *pf,
363 struct ice_fdir_counter *counter)
368 if (--counter->ref_cnt == 0) {
369 struct ice_fdir_counter_pool *pool = counter->pool;
371 TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
376 ice_fdir_init_filter_list(struct ice_pf *pf)
378 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
379 struct ice_fdir_info *fdir_info = &pf->fdir;
380 char fdir_hash_name[RTE_HASH_NAMESIZE];
383 struct rte_hash_parameters fdir_hash_params = {
384 .name = fdir_hash_name,
385 .entries = ICE_MAX_FDIR_FILTER_NUM,
386 .key_len = sizeof(struct ice_fdir_fltr_pattern),
387 .hash_func = rte_hash_crc,
388 .hash_func_init_val = 0,
389 .socket_id = rte_socket_id(),
390 .extra_flag = RTE_HASH_EXTRA_FLAGS_EXT_TABLE,
393 /* Initialize hash */
394 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
395 "fdir_%s", dev->device->name);
396 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
397 if (!fdir_info->hash_table) {
398 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
401 fdir_info->hash_map = rte_zmalloc("ice_fdir_hash_map",
402 sizeof(*fdir_info->hash_map) *
403 ICE_MAX_FDIR_FILTER_NUM,
405 if (!fdir_info->hash_map) {
407 "Failed to allocate memory for fdir hash map!");
409 goto err_fdir_hash_map_alloc;
413 err_fdir_hash_map_alloc:
414 rte_hash_free(fdir_info->hash_table);
420 ice_fdir_release_filter_list(struct ice_pf *pf)
422 struct ice_fdir_info *fdir_info = &pf->fdir;
424 if (fdir_info->hash_map)
425 rte_free(fdir_info->hash_map);
426 if (fdir_info->hash_table)
427 rte_hash_free(fdir_info->hash_table);
429 fdir_info->hash_map = NULL;
430 fdir_info->hash_table = NULL;
434 * ice_fdir_setup - reserve and initialize the Flow Director resources
435 * @pf: board private structure
438 ice_fdir_setup(struct ice_pf *pf)
440 struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
441 struct ice_hw *hw = ICE_PF_TO_HW(pf);
442 const struct rte_memzone *mz = NULL;
443 char z_name[RTE_MEMZONE_NAMESIZE];
445 int err = ICE_SUCCESS;
447 if ((pf->flags & ICE_FLAG_FDIR) == 0) {
448 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
452 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
453 " fd_fltr_best_effort = %u.",
454 hw->func_caps.fd_fltr_guar,
455 hw->func_caps.fd_fltr_best_effort);
457 if (pf->fdir.fdir_vsi) {
458 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
462 /* make new FDIR VSI */
463 vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
465 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
468 pf->fdir.fdir_vsi = vsi;
470 err = ice_fdir_init_filter_list(pf);
472 PMD_DRV_LOG(ERR, "Failed to init FDIR filter list.");
476 err = ice_fdir_counter_init(pf);
478 PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
482 /*Fdir tx queue setup*/
483 err = ice_fdir_setup_tx_resources(pf);
485 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
489 /*Fdir rx queue setup*/
490 err = ice_fdir_setup_rx_resources(pf);
492 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
496 err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
498 PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
502 err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
504 PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
508 /* Enable FDIR MSIX interrupt */
509 vsi->nb_used_qps = 1;
510 ice_vsi_queues_bind_intr(vsi);
511 ice_vsi_enable_queues_intr(vsi);
513 /* reserve memory for the fdir programming packet */
514 snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
516 eth_dev->data->port_id);
517 mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
519 PMD_DRV_LOG(ERR, "Cannot init memzone for "
520 "flow director program packet.");
524 pf->fdir.prg_pkt = mz->addr;
525 pf->fdir.dma_addr = mz->iova;
528 err = ice_fdir_prof_alloc(hw);
530 PMD_DRV_LOG(ERR, "Cannot allocate memory for "
531 "flow director profile.");
536 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
541 rte_memzone_free(pf->fdir.mz);
544 ice_rx_queue_release(pf->fdir.rxq);
547 ice_tx_queue_release(pf->fdir.txq);
550 ice_release_vsi(vsi);
551 pf->fdir.fdir_vsi = NULL;
556 ice_fdir_prof_free(struct ice_hw *hw)
558 enum ice_fltr_ptype ptype;
560 for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
561 ptype < ICE_FLTR_PTYPE_MAX;
563 rte_free(hw->fdir_prof[ptype]);
564 hw->fdir_prof[ptype] = NULL;
567 rte_free(hw->fdir_prof);
568 hw->fdir_prof = NULL;
571 /* Remove a profile for some filter type */
573 ice_fdir_prof_rm(struct ice_pf *pf, enum ice_fltr_ptype ptype, bool is_tunnel)
575 struct ice_hw *hw = ICE_PF_TO_HW(pf);
576 struct ice_fd_hw_prof *hw_prof;
581 if (!hw->fdir_prof || !hw->fdir_prof[ptype])
584 hw_prof = hw->fdir_prof[ptype];
586 prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
587 for (i = 0; i < pf->hw_prof_cnt[ptype][is_tunnel]; i++) {
588 if (hw_prof->entry_h[i][is_tunnel]) {
589 vsi_num = ice_get_hw_vsi_num(hw,
591 ice_rem_prof_id_flow(hw, ICE_BLK_FD,
593 ice_flow_rem_entry(hw, ICE_BLK_FD,
594 hw_prof->entry_h[i][is_tunnel]);
595 hw_prof->entry_h[i][is_tunnel] = 0;
598 ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
599 rte_free(hw_prof->fdir_seg[is_tunnel]);
600 hw_prof->fdir_seg[is_tunnel] = NULL;
602 for (i = 0; i < hw_prof->cnt; i++)
603 hw_prof->vsi_h[i] = 0;
604 pf->hw_prof_cnt[ptype][is_tunnel] = 0;
607 /* Remove all created profiles */
609 ice_fdir_prof_rm_all(struct ice_pf *pf)
611 enum ice_fltr_ptype ptype;
613 for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
614 ptype < ICE_FLTR_PTYPE_MAX;
616 ice_fdir_prof_rm(pf, ptype, false);
617 ice_fdir_prof_rm(pf, ptype, true);
622 * ice_fdir_teardown - release the Flow Director resources
623 * @pf: board private structure
626 ice_fdir_teardown(struct ice_pf *pf)
628 struct rte_eth_dev *eth_dev = &rte_eth_devices[pf->dev_data->port_id];
629 struct ice_hw *hw = ICE_PF_TO_HW(pf);
633 vsi = pf->fdir.fdir_vsi;
637 ice_vsi_disable_queues_intr(vsi);
639 err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
641 PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
643 err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
645 PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
647 err = ice_fdir_counter_release(pf);
649 PMD_DRV_LOG(ERR, "Failed to release FDIR counter resource.");
651 ice_fdir_release_filter_list(pf);
653 ice_tx_queue_release(pf->fdir.txq);
655 ice_rx_queue_release(pf->fdir.rxq);
657 ice_fdir_prof_rm_all(pf);
658 ice_fdir_prof_free(hw);
659 ice_release_vsi(vsi);
660 pf->fdir.fdir_vsi = NULL;
663 err = rte_memzone_free(pf->fdir.mz);
666 PMD_DRV_LOG(ERR, "Failed to free FDIR memezone.");
671 ice_fdir_cur_prof_conflict(struct ice_pf *pf,
672 enum ice_fltr_ptype ptype,
673 struct ice_flow_seg_info *seg,
676 struct ice_hw *hw = ICE_PF_TO_HW(pf);
677 struct ice_flow_seg_info *ori_seg;
678 struct ice_fd_hw_prof *hw_prof;
680 hw_prof = hw->fdir_prof[ptype];
681 ori_seg = hw_prof->fdir_seg[is_tunnel];
683 /* profile does not exist */
687 /* if no input set conflict, return -EEXIST */
688 if ((!is_tunnel && !memcmp(ori_seg, seg, sizeof(*seg))) ||
689 (is_tunnel && !memcmp(&ori_seg[1], &seg[1], sizeof(*seg)))) {
690 PMD_DRV_LOG(DEBUG, "Profile already exists for flow type %d.",
695 /* a rule with input set conflict already exist, so give up */
696 if (pf->fdir_fltr_cnt[ptype][is_tunnel]) {
697 PMD_DRV_LOG(DEBUG, "Failed to create profile for flow type %d due to conflict with existing rule.",
702 /* it's safe to delete an empty profile */
703 ice_fdir_prof_rm(pf, ptype, is_tunnel);
708 ice_fdir_prof_resolve_conflict(struct ice_pf *pf,
709 enum ice_fltr_ptype ptype,
712 struct ice_hw *hw = ICE_PF_TO_HW(pf);
713 struct ice_fd_hw_prof *hw_prof;
714 struct ice_flow_seg_info *seg;
716 hw_prof = hw->fdir_prof[ptype];
717 seg = hw_prof->fdir_seg[is_tunnel];
719 /* profile does not exist */
723 /* profile exists and rule exists, fail to resolve the conflict */
724 if (pf->fdir_fltr_cnt[ptype][is_tunnel] != 0)
727 /* it's safe to delete an empty profile */
728 ice_fdir_prof_rm(pf, ptype, is_tunnel);
734 ice_fdir_cross_prof_conflict(struct ice_pf *pf,
735 enum ice_fltr_ptype ptype,
738 enum ice_fltr_ptype cflct_ptype;
742 case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
743 case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
744 case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
745 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
746 if (!ice_fdir_prof_resolve_conflict
747 (pf, cflct_ptype, is_tunnel))
750 case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
751 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
752 if (!ice_fdir_prof_resolve_conflict
753 (pf, cflct_ptype, is_tunnel))
755 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
756 if (!ice_fdir_prof_resolve_conflict
757 (pf, cflct_ptype, is_tunnel))
759 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
760 if (!ice_fdir_prof_resolve_conflict
761 (pf, cflct_ptype, is_tunnel))
765 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP:
766 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP:
767 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP:
768 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER;
769 if (!ice_fdir_prof_resolve_conflict
770 (pf, cflct_ptype, is_tunnel))
773 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_OTHER:
774 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_UDP;
775 if (!ice_fdir_prof_resolve_conflict
776 (pf, cflct_ptype, is_tunnel))
778 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_TCP;
779 if (!ice_fdir_prof_resolve_conflict
780 (pf, cflct_ptype, is_tunnel))
782 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_IPV4_ICMP;
783 if (!ice_fdir_prof_resolve_conflict
784 (pf, cflct_ptype, is_tunnel))
788 case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
789 case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
790 case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
791 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
792 if (!ice_fdir_prof_resolve_conflict
793 (pf, cflct_ptype, is_tunnel))
796 case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
797 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
798 if (!ice_fdir_prof_resolve_conflict
799 (pf, cflct_ptype, is_tunnel))
801 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
802 if (!ice_fdir_prof_resolve_conflict
803 (pf, cflct_ptype, is_tunnel))
805 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
806 if (!ice_fdir_prof_resolve_conflict
807 (pf, cflct_ptype, is_tunnel))
810 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP:
811 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP:
812 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP:
813 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER;
814 if (!ice_fdir_prof_resolve_conflict
815 (pf, cflct_ptype, is_tunnel))
818 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER:
819 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP;
820 if (!ice_fdir_prof_resolve_conflict
821 (pf, cflct_ptype, is_tunnel))
823 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP;
824 if (!ice_fdir_prof_resolve_conflict
825 (pf, cflct_ptype, is_tunnel))
827 cflct_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP;
828 if (!ice_fdir_prof_resolve_conflict
829 (pf, cflct_ptype, is_tunnel))
837 PMD_DRV_LOG(DEBUG, "Failed to create profile for flow type %d due to conflict with existing rule of flow type %d.",
843 ice_fdir_hw_tbl_conf(struct ice_pf *pf, struct ice_vsi *vsi,
844 struct ice_vsi *ctrl_vsi,
845 struct ice_flow_seg_info *seg,
846 enum ice_fltr_ptype ptype,
849 struct ice_hw *hw = ICE_PF_TO_HW(pf);
850 enum ice_flow_dir dir = ICE_FLOW_RX;
851 struct ice_fd_hw_prof *hw_prof;
852 struct ice_flow_prof *prof;
853 uint64_t entry_1 = 0;
854 uint64_t entry_2 = 0;
859 /* check if have input set conflict on current profile. */
860 ret = ice_fdir_cur_prof_conflict(pf, ptype, seg, is_tunnel);
864 /* check if the profile is conflict with other profile. */
865 ret = ice_fdir_cross_prof_conflict(pf, ptype, is_tunnel);
869 prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
870 ret = ice_flow_add_prof(hw, ICE_BLK_FD, dir, prof_id, seg,
871 (is_tunnel) ? 2 : 1, NULL, 0, &prof);
874 ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
875 vsi->idx, ICE_FLOW_PRIO_NORMAL,
876 seg, NULL, 0, &entry_1);
878 PMD_DRV_LOG(ERR, "Failed to add main VSI flow entry for %d.",
882 ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
883 ctrl_vsi->idx, ICE_FLOW_PRIO_NORMAL,
884 seg, NULL, 0, &entry_2);
886 PMD_DRV_LOG(ERR, "Failed to add control VSI flow entry for %d.",
891 hw_prof = hw->fdir_prof[ptype];
892 pf->hw_prof_cnt[ptype][is_tunnel] = 0;
894 hw_prof->fdir_seg[is_tunnel] = seg;
895 hw_prof->vsi_h[hw_prof->cnt] = vsi->idx;
896 hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_1;
897 pf->hw_prof_cnt[ptype][is_tunnel]++;
898 hw_prof->vsi_h[hw_prof->cnt] = ctrl_vsi->idx;
899 hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_2;
900 pf->hw_prof_cnt[ptype][is_tunnel]++;
905 vsi_num = ice_get_hw_vsi_num(hw, vsi->idx);
906 ice_rem_prof_id_flow(hw, ICE_BLK_FD, vsi_num, prof_id);
907 ice_flow_rem_entry(hw, ICE_BLK_FD, entry_1);
909 ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
915 ice_fdir_input_set_parse(uint64_t inset, enum ice_flow_field *field)
919 struct ice_inset_map {
921 enum ice_flow_field fld;
923 static const struct ice_inset_map ice_inset_map[] = {
924 {ICE_INSET_DMAC, ICE_FLOW_FIELD_IDX_ETH_DA},
925 {ICE_INSET_ETHERTYPE, ICE_FLOW_FIELD_IDX_ETH_TYPE},
926 {ICE_INSET_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
927 {ICE_INSET_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
928 {ICE_INSET_IPV4_TOS, ICE_FLOW_FIELD_IDX_IPV4_DSCP},
929 {ICE_INSET_IPV4_TTL, ICE_FLOW_FIELD_IDX_IPV4_TTL},
930 {ICE_INSET_IPV4_PROTO, ICE_FLOW_FIELD_IDX_IPV4_PROT},
931 {ICE_INSET_IPV4_PKID, ICE_FLOW_FIELD_IDX_IPV4_ID},
932 {ICE_INSET_IPV6_SRC, ICE_FLOW_FIELD_IDX_IPV6_SA},
933 {ICE_INSET_IPV6_DST, ICE_FLOW_FIELD_IDX_IPV6_DA},
934 {ICE_INSET_IPV6_TC, ICE_FLOW_FIELD_IDX_IPV6_DSCP},
935 {ICE_INSET_IPV6_NEXT_HDR, ICE_FLOW_FIELD_IDX_IPV6_PROT},
936 {ICE_INSET_IPV6_HOP_LIMIT, ICE_FLOW_FIELD_IDX_IPV6_TTL},
937 {ICE_INSET_IPV6_PKID, ICE_FLOW_FIELD_IDX_IPV6_ID},
938 {ICE_INSET_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
939 {ICE_INSET_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
940 {ICE_INSET_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
941 {ICE_INSET_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
942 {ICE_INSET_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
943 {ICE_INSET_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
944 {ICE_INSET_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
945 {ICE_INSET_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
946 {ICE_INSET_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
947 {ICE_INSET_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
948 {ICE_INSET_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
949 {ICE_INSET_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
950 {ICE_INSET_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
951 {ICE_INSET_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
952 {ICE_INSET_GTPU_TEID, ICE_FLOW_FIELD_IDX_GTPU_IP_TEID},
953 {ICE_INSET_GTPU_QFI, ICE_FLOW_FIELD_IDX_GTPU_EH_QFI},
954 {ICE_INSET_VXLAN_VNI, ICE_FLOW_FIELD_IDX_VXLAN_VNI},
955 {ICE_INSET_ESP_SPI, ICE_FLOW_FIELD_IDX_ESP_SPI},
956 {ICE_INSET_NAT_T_ESP_SPI, ICE_FLOW_FIELD_IDX_NAT_T_ESP_SPI},
959 for (i = 0, j = 0; i < RTE_DIM(ice_inset_map); i++) {
960 if ((inset & ice_inset_map[i].inset) ==
961 ice_inset_map[i].inset)
962 field[j++] = ice_inset_map[i].fld;
967 ice_fdir_input_set_hdrs(enum ice_fltr_ptype flow, struct ice_flow_seg_info *seg)
970 case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
971 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
972 ICE_FLOW_SEG_HDR_IPV4 |
973 ICE_FLOW_SEG_HDR_IPV_OTHER);
975 case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
976 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
977 ICE_FLOW_SEG_HDR_IPV4 |
978 ICE_FLOW_SEG_HDR_IPV_OTHER);
980 case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
981 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
982 ICE_FLOW_SEG_HDR_IPV4 |
983 ICE_FLOW_SEG_HDR_IPV_OTHER);
985 case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
986 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4 |
987 ICE_FLOW_SEG_HDR_IPV_OTHER);
989 case ICE_FLTR_PTYPE_FRAG_IPV4:
990 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4 |
991 ICE_FLOW_SEG_HDR_IPV_FRAG);
993 case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
994 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
995 ICE_FLOW_SEG_HDR_IPV6 |
996 ICE_FLOW_SEG_HDR_IPV_OTHER);
998 case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
999 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
1000 ICE_FLOW_SEG_HDR_IPV6 |
1001 ICE_FLOW_SEG_HDR_IPV_OTHER);
1003 case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
1004 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
1005 ICE_FLOW_SEG_HDR_IPV6 |
1006 ICE_FLOW_SEG_HDR_IPV_OTHER);
1008 case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
1009 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 |
1010 ICE_FLOW_SEG_HDR_IPV_OTHER);
1012 case ICE_FLTR_PTYPE_FRAG_IPV6:
1013 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6 |
1014 ICE_FLOW_SEG_HDR_IPV_FRAG);
1016 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP:
1017 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP:
1018 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP:
1020 case ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER:
1021 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV_OTHER);
1023 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU:
1024 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_IP |
1025 ICE_FLOW_SEG_HDR_IPV4 |
1026 ICE_FLOW_SEG_HDR_IPV_OTHER);
1028 case ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH:
1029 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_EH |
1030 ICE_FLOW_SEG_HDR_GTPU_IP |
1031 ICE_FLOW_SEG_HDR_IPV4 |
1032 ICE_FLOW_SEG_HDR_IPV_OTHER);
1034 case ICE_FLTR_PTYPE_NONF_IPV6_GTPU:
1035 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_IP |
1036 ICE_FLOW_SEG_HDR_IPV6 |
1037 ICE_FLOW_SEG_HDR_IPV_OTHER);
1039 case ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH:
1040 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_GTPU_EH |
1041 ICE_FLOW_SEG_HDR_GTPU_IP |
1042 ICE_FLOW_SEG_HDR_IPV6 |
1043 ICE_FLOW_SEG_HDR_IPV_OTHER);
1045 case ICE_FLTR_PTYPE_NON_IP_L2:
1046 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ETH_NON_IP);
1048 case ICE_FLTR_PTYPE_NONF_IPV4_ESP:
1049 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ESP |
1050 ICE_FLOW_SEG_HDR_IPV4 |
1051 ICE_FLOW_SEG_HDR_IPV_OTHER);
1053 case ICE_FLTR_PTYPE_NONF_IPV6_ESP:
1054 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_ESP |
1055 ICE_FLOW_SEG_HDR_IPV6 |
1056 ICE_FLOW_SEG_HDR_IPV_OTHER);
1058 case ICE_FLTR_PTYPE_NONF_IPV4_NAT_T_ESP:
1059 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_NAT_T_ESP |
1060 ICE_FLOW_SEG_HDR_IPV4 |
1061 ICE_FLOW_SEG_HDR_IPV_OTHER);
1063 case ICE_FLTR_PTYPE_NONF_IPV6_NAT_T_ESP:
1064 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_NAT_T_ESP |
1065 ICE_FLOW_SEG_HDR_IPV6 |
1066 ICE_FLOW_SEG_HDR_IPV_OTHER);
1069 PMD_DRV_LOG(ERR, "not supported filter type.");
1075 ice_fdir_input_set_conf(struct ice_pf *pf, enum ice_fltr_ptype flow,
1076 uint64_t inner_input_set, uint64_t outer_input_set,
1077 enum ice_fdir_tunnel_type ttype)
1079 struct ice_flow_seg_info *seg;
1080 struct ice_flow_seg_info *seg_tun = NULL;
1081 enum ice_flow_field field[ICE_FLOW_FIELD_IDX_MAX];
1086 if (!(inner_input_set | outer_input_set))
1089 seg_tun = (struct ice_flow_seg_info *)
1090 ice_malloc(hw, sizeof(*seg_tun) * ICE_FD_HW_SEG_MAX);
1092 PMD_DRV_LOG(ERR, "No memory can be allocated");
1096 /* use seg_tun[1] to record tunnel inner part */
1097 for (k = 0; k <= ICE_FD_HW_SEG_TUN; k++) {
1099 input_set = (k == ICE_FD_HW_SEG_TUN) ? inner_input_set : outer_input_set;
1103 for (i = 0; i < ICE_FLOW_FIELD_IDX_MAX; i++)
1104 field[i] = ICE_FLOW_FIELD_IDX_MAX;
1106 ice_fdir_input_set_parse(input_set, field);
1108 ice_fdir_input_set_hdrs(flow, seg);
1110 for (i = 0; field[i] != ICE_FLOW_FIELD_IDX_MAX; i++) {
1111 ice_flow_set_fld(seg, field[i],
1112 ICE_FLOW_FLD_OFF_INVAL,
1113 ICE_FLOW_FLD_OFF_INVAL,
1114 ICE_FLOW_FLD_OFF_INVAL, false);
1118 is_tunnel = ice_fdir_is_tunnel_profile(ttype);
1120 ret = ice_fdir_hw_tbl_conf(pf, pf->main_vsi, pf->fdir.fdir_vsi,
1121 seg_tun, flow, is_tunnel);
1125 } else if (ret < 0) {
1127 return (ret == -EEXIST) ? 0 : ret;
1134 ice_fdir_cnt_update(struct ice_pf *pf, enum ice_fltr_ptype ptype,
1135 bool is_tunnel, bool add)
1137 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1140 cnt = (add) ? 1 : -1;
1141 hw->fdir_active_fltr += cnt;
1142 if (ptype == ICE_FLTR_PTYPE_NONF_NONE || ptype >= ICE_FLTR_PTYPE_MAX)
1143 PMD_DRV_LOG(ERR, "Unknown filter type %d", ptype);
1145 pf->fdir_fltr_cnt[ptype][is_tunnel] += cnt;
1149 ice_fdir_init(struct ice_adapter *ad)
1151 struct ice_pf *pf = &ad->pf;
1152 struct ice_flow_parser *parser;
1155 if (ad->hw.dcf_enabled)
1158 ret = ice_fdir_setup(pf);
1162 parser = &ice_fdir_parser;
1164 return ice_register_parser(parser, ad);
1168 ice_fdir_uninit(struct ice_adapter *ad)
1170 struct ice_flow_parser *parser;
1171 struct ice_pf *pf = &ad->pf;
1173 if (ad->hw.dcf_enabled)
1176 parser = &ice_fdir_parser;
1178 ice_unregister_parser(parser, ad);
1180 ice_fdir_teardown(pf);
1184 ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type)
1186 if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN)
1193 ice_fdir_add_del_raw(struct ice_pf *pf,
1194 struct ice_fdir_filter_conf *filter,
1197 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1199 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1200 rte_memcpy(pkt, filter->pkt_buf, filter->pkt_len);
1202 struct ice_fltr_desc desc;
1203 memset(&desc, 0, sizeof(desc));
1204 filter->input.comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW;
1205 ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add);
1207 return ice_fdir_programming(pf, &desc);
1211 ice_fdir_add_del_filter(struct ice_pf *pf,
1212 struct ice_fdir_filter_conf *filter,
1215 struct ice_fltr_desc desc;
1216 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1217 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
1221 filter->input.dest_vsi = pf->main_vsi->idx;
1223 memset(&desc, 0, sizeof(desc));
1224 filter->input.comp_report = ICE_FXD_FLTR_QW0_COMP_REPORT_SW;
1225 ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add);
1227 is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1229 memset(pkt, 0, ICE_FDIR_PKT_LEN);
1230 ret = ice_fdir_get_gen_prgm_pkt(hw, &filter->input, pkt, false, is_tun);
1232 PMD_DRV_LOG(ERR, "Generate dummy packet failed");
1236 return ice_fdir_programming(pf, &desc);
1240 ice_fdir_extract_fltr_key(struct ice_fdir_fltr_pattern *key,
1241 struct ice_fdir_filter_conf *filter)
1243 struct ice_fdir_fltr *input = &filter->input;
1244 memset(key, 0, sizeof(*key));
1246 key->flow_type = input->flow_type;
1247 rte_memcpy(&key->ip, &input->ip, sizeof(key->ip));
1248 rte_memcpy(&key->mask, &input->mask, sizeof(key->mask));
1249 rte_memcpy(&key->ext_data, &input->ext_data, sizeof(key->ext_data));
1250 rte_memcpy(&key->ext_mask, &input->ext_mask, sizeof(key->ext_mask));
1252 rte_memcpy(&key->gtpu_data, &input->gtpu_data, sizeof(key->gtpu_data));
1253 rte_memcpy(&key->gtpu_mask, &input->gtpu_mask, sizeof(key->gtpu_mask));
1255 key->tunnel_type = filter->tunnel_type;
1258 /* Check if there exists the flow director filter */
1259 static struct ice_fdir_filter_conf *
1260 ice_fdir_entry_lookup(struct ice_fdir_info *fdir_info,
1261 const struct ice_fdir_fltr_pattern *key)
1265 ret = rte_hash_lookup(fdir_info->hash_table, key);
1269 return fdir_info->hash_map[ret];
1272 /* Add a flow director entry into the SW list */
1274 ice_fdir_entry_insert(struct ice_pf *pf,
1275 struct ice_fdir_filter_conf *entry,
1276 struct ice_fdir_fltr_pattern *key)
1278 struct ice_fdir_info *fdir_info = &pf->fdir;
1281 ret = rte_hash_add_key(fdir_info->hash_table, key);
1284 "Failed to insert fdir entry to hash table %d!",
1288 fdir_info->hash_map[ret] = entry;
1293 /* Delete a flow director entry from the SW list */
1295 ice_fdir_entry_del(struct ice_pf *pf, struct ice_fdir_fltr_pattern *key)
1297 struct ice_fdir_info *fdir_info = &pf->fdir;
1300 ret = rte_hash_del_key(fdir_info->hash_table, key);
1303 "Failed to delete fdir filter to hash table %d!",
1307 fdir_info->hash_map[ret] = NULL;
1313 ice_fdir_create_filter(struct ice_adapter *ad,
1314 struct rte_flow *flow,
1316 struct rte_flow_error *error)
1318 struct ice_pf *pf = &ad->pf;
1319 struct ice_fdir_filter_conf *filter = meta;
1320 struct ice_fdir_info *fdir_info = &pf->fdir;
1321 struct ice_fdir_filter_conf *entry, *node;
1322 struct ice_fdir_fltr_pattern key;
1327 if (filter->parser_ena) {
1328 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1330 int id = ice_find_first_bit(filter->prof->ptypes, UINT16_MAX);
1331 int ptg = hw->blk[ICE_BLK_FD].xlt1.t[id];
1332 u16 ctrl_vsi = pf->fdir.fdir_vsi->idx;
1333 u16 main_vsi = pf->main_vsi->idx;
1334 bool fv_found = false;
1336 struct ice_fdir_prof_info *pi = &ad->fdir_prof_info[ptg];
1337 if (pi->fdir_actived_cnt != 0) {
1338 for (i = 0; i < ICE_MAX_FV_WORDS; i++)
1339 if (pi->prof.fv[i].proto_id !=
1340 filter->prof->fv[i].proto_id ||
1341 pi->prof.fv[i].offset !=
1342 filter->prof->fv[i].offset ||
1343 pi->prof.fv[i].msk !=
1344 filter->prof->fv[i].msk)
1346 if (i == ICE_MAX_FV_WORDS) {
1348 pi->fdir_actived_cnt++;
1353 ret = ice_flow_set_hw_prof(hw, main_vsi, ctrl_vsi,
1354 filter->prof, ICE_BLK_FD);
1359 ret = ice_fdir_add_del_raw(pf, filter, true);
1364 for (i = 0; i < filter->prof->fv_num; i++) {
1365 pi->prof.fv[i].proto_id =
1366 filter->prof->fv[i].proto_id;
1367 pi->prof.fv[i].offset =
1368 filter->prof->fv[i].offset;
1369 pi->prof.fv[i].msk = filter->prof->fv[i].msk;
1371 pi->fdir_actived_cnt = 1;
1374 if (filter->mark_flag == 1)
1375 ice_fdir_rx_parsing_enable(ad, 1);
1377 entry = rte_zmalloc("fdir_entry", sizeof(*entry), 0);
1381 rte_memcpy(entry, filter, sizeof(*filter));
1388 ice_fdir_extract_fltr_key(&key, filter);
1389 node = ice_fdir_entry_lookup(fdir_info, &key);
1391 rte_flow_error_set(error, EEXIST,
1392 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1393 "Rule already exists!");
1397 entry = rte_zmalloc("fdir_entry", sizeof(*entry), 0);
1399 rte_flow_error_set(error, ENOMEM,
1400 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1401 "Failed to allocate memory");
1405 is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1407 ret = ice_fdir_input_set_conf(pf, filter->input.flow_type,
1408 filter->input_set_i, filter->input_set_o,
1409 filter->tunnel_type);
1411 rte_flow_error_set(error, -ret,
1412 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1413 "Profile configure failed.");
1417 /* alloc counter for FDIR */
1418 if (filter->input.cnt_ena) {
1419 struct rte_flow_action_count *act_count = &filter->act_count;
1421 filter->counter = ice_fdir_counter_alloc(pf, 0, act_count->id);
1422 if (!filter->counter) {
1423 rte_flow_error_set(error, EINVAL,
1424 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1425 "Failed to alloc FDIR counter.");
1428 filter->input.cnt_index = filter->counter->hw_index;
1431 ret = ice_fdir_add_del_filter(pf, filter, true);
1433 rte_flow_error_set(error, -ret,
1434 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1435 "Add filter rule failed.");
1439 if (filter->mark_flag == 1)
1440 ice_fdir_rx_parsing_enable(ad, 1);
1442 rte_memcpy(entry, filter, sizeof(*entry));
1443 ret = ice_fdir_entry_insert(pf, entry, &key);
1445 rte_flow_error_set(error, -ret,
1446 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1447 "Insert entry to table failed.");
1452 ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, true);
1457 if (filter->counter) {
1458 ice_fdir_counter_free(pf, filter->counter);
1459 filter->counter = NULL;
1467 rte_free(filter->prof);
1468 rte_free(filter->pkt_buf);
1473 ice_fdir_destroy_filter(struct ice_adapter *ad,
1474 struct rte_flow *flow,
1475 struct rte_flow_error *error)
1477 struct ice_pf *pf = &ad->pf;
1478 struct ice_fdir_info *fdir_info = &pf->fdir;
1479 struct ice_fdir_filter_conf *filter, *entry;
1480 struct ice_fdir_fltr_pattern key;
1484 filter = (struct ice_fdir_filter_conf *)flow->rule;
1486 if (filter->parser_ena) {
1487 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1489 int id = ice_find_first_bit(filter->prof->ptypes, UINT16_MAX);
1490 int ptg = hw->blk[ICE_BLK_FD].xlt1.t[id];
1491 u16 ctrl_vsi = pf->fdir.fdir_vsi->idx;
1492 u16 main_vsi = pf->main_vsi->idx;
1493 enum ice_block blk = ICE_BLK_FD;
1496 ret = ice_fdir_add_del_raw(pf, filter, false);
1500 struct ice_fdir_prof_info *pi = &ad->fdir_prof_info[ptg];
1501 if (pi->fdir_actived_cnt != 0) {
1502 pi->fdir_actived_cnt--;
1503 if (!pi->fdir_actived_cnt) {
1504 vsi_num = ice_get_hw_vsi_num(hw, ctrl_vsi);
1505 ice_rem_prof_id_flow(hw, blk, vsi_num, id);
1507 vsi_num = ice_get_hw_vsi_num(hw, main_vsi);
1508 ice_rem_prof_id_flow(hw, blk, vsi_num, id);
1512 if (filter->mark_flag == 1)
1513 ice_fdir_rx_parsing_enable(ad, 0);
1517 rte_free(filter->prof);
1518 rte_free(filter->pkt_buf);
1524 is_tun = ice_fdir_is_tunnel_profile(filter->tunnel_type);
1526 if (filter->counter) {
1527 ice_fdir_counter_free(pf, filter->counter);
1528 filter->counter = NULL;
1531 ice_fdir_extract_fltr_key(&key, filter);
1532 entry = ice_fdir_entry_lookup(fdir_info, &key);
1534 rte_flow_error_set(error, ENOENT,
1535 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1536 "Can't find entry.");
1540 ret = ice_fdir_add_del_filter(pf, filter, false);
1542 rte_flow_error_set(error, -ret,
1543 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1544 "Del filter rule failed.");
1548 ret = ice_fdir_entry_del(pf, &key);
1550 rte_flow_error_set(error, -ret,
1551 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1552 "Remove entry from table failed.");
1556 ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, false);
1558 if (filter->mark_flag == 1)
1559 ice_fdir_rx_parsing_enable(ad, 0);
1569 ice_fdir_query_count(struct ice_adapter *ad,
1570 struct rte_flow *flow,
1571 struct rte_flow_query_count *flow_stats,
1572 struct rte_flow_error *error)
1574 struct ice_pf *pf = &ad->pf;
1575 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1576 struct ice_fdir_filter_conf *filter = flow->rule;
1577 struct ice_fdir_counter *counter = filter->counter;
1578 uint64_t hits_lo, hits_hi;
1581 rte_flow_error_set(error, EINVAL,
1582 RTE_FLOW_ERROR_TYPE_ACTION,
1584 "FDIR counters not available");
1589 * Reading the low 32-bits latches the high 32-bits into a shadow
1590 * register. Reading the high 32-bit returns the value in the
1593 hits_lo = ICE_READ_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index));
1594 hits_hi = ICE_READ_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index));
1596 flow_stats->hits_set = 1;
1597 flow_stats->hits = hits_lo | (hits_hi << 32);
1598 flow_stats->bytes_set = 0;
1599 flow_stats->bytes = 0;
1601 if (flow_stats->reset) {
1602 /* reset statistic counter value */
1603 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index), 0);
1604 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index), 0);
1610 static struct ice_flow_engine ice_fdir_engine = {
1611 .init = ice_fdir_init,
1612 .uninit = ice_fdir_uninit,
1613 .create = ice_fdir_create_filter,
1614 .destroy = ice_fdir_destroy_filter,
1615 .query_count = ice_fdir_query_count,
1616 .type = ICE_FLOW_ENGINE_FDIR,
1620 ice_fdir_parse_action_qregion(struct ice_pf *pf,
1621 struct rte_flow_error *error,
1622 const struct rte_flow_action *act,
1623 struct ice_fdir_filter_conf *filter)
1625 const struct rte_flow_action_rss *rss = act->conf;
1628 if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
1629 rte_flow_error_set(error, EINVAL,
1630 RTE_FLOW_ERROR_TYPE_ACTION, act,
1635 if (rss->queue_num <= 1) {
1636 rte_flow_error_set(error, EINVAL,
1637 RTE_FLOW_ERROR_TYPE_ACTION, act,
1638 "Queue region size can't be 0 or 1.");
1642 /* check if queue index for queue region is continuous */
1643 for (i = 0; i < rss->queue_num - 1; i++) {
1644 if (rss->queue[i + 1] != rss->queue[i] + 1) {
1645 rte_flow_error_set(error, EINVAL,
1646 RTE_FLOW_ERROR_TYPE_ACTION, act,
1647 "Discontinuous queue region");
1652 if (rss->queue[rss->queue_num - 1] >= pf->dev_data->nb_rx_queues) {
1653 rte_flow_error_set(error, EINVAL,
1654 RTE_FLOW_ERROR_TYPE_ACTION, act,
1655 "Invalid queue region indexes.");
1659 if (!(rte_is_power_of_2(rss->queue_num) &&
1660 (rss->queue_num <= ICE_FDIR_MAX_QREGION_SIZE))) {
1661 rte_flow_error_set(error, EINVAL,
1662 RTE_FLOW_ERROR_TYPE_ACTION, act,
1663 "The region size should be any of the following values:"
1664 "1, 2, 4, 8, 16, 32, 64, 128 as long as the total number "
1665 "of queues do not exceed the VSI allocation.");
1669 filter->input.q_index = rss->queue[0];
1670 filter->input.q_region = rte_fls_u32(rss->queue_num) - 1;
1671 filter->input.dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
1677 ice_fdir_parse_action(struct ice_adapter *ad,
1678 const struct rte_flow_action actions[],
1679 struct rte_flow_error *error,
1680 struct ice_fdir_filter_conf *filter)
1682 struct ice_pf *pf = &ad->pf;
1683 const struct rte_flow_action_queue *act_q;
1684 const struct rte_flow_action_mark *mark_spec = NULL;
1685 const struct rte_flow_action_count *act_count;
1686 uint32_t dest_num = 0;
1687 uint32_t mark_num = 0;
1688 uint32_t counter_num = 0;
1691 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1692 switch (actions->type) {
1693 case RTE_FLOW_ACTION_TYPE_VOID:
1695 case RTE_FLOW_ACTION_TYPE_QUEUE:
1698 act_q = actions->conf;
1699 filter->input.q_index = act_q->index;
1700 if (filter->input.q_index >=
1701 pf->dev_data->nb_rx_queues) {
1702 rte_flow_error_set(error, EINVAL,
1703 RTE_FLOW_ERROR_TYPE_ACTION,
1705 "Invalid queue for FDIR.");
1708 filter->input.dest_ctl =
1709 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
1711 case RTE_FLOW_ACTION_TYPE_DROP:
1714 filter->input.dest_ctl =
1715 ICE_FLTR_PRGM_DESC_DEST_DROP_PKT;
1717 case RTE_FLOW_ACTION_TYPE_PASSTHRU:
1720 filter->input.dest_ctl =
1721 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER;
1723 case RTE_FLOW_ACTION_TYPE_RSS:
1726 ret = ice_fdir_parse_action_qregion(pf,
1727 error, actions, filter);
1731 case RTE_FLOW_ACTION_TYPE_MARK:
1733 filter->mark_flag = 1;
1734 mark_spec = actions->conf;
1735 filter->input.fltr_id = mark_spec->id;
1736 filter->input.fdid_prio = ICE_FXD_FLTR_QW1_FDID_PRI_ONE;
1738 case RTE_FLOW_ACTION_TYPE_COUNT:
1741 act_count = actions->conf;
1742 filter->input.cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
1743 rte_memcpy(&filter->act_count, act_count,
1744 sizeof(filter->act_count));
1748 rte_flow_error_set(error, EINVAL,
1749 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1755 if (dest_num >= 2) {
1756 rte_flow_error_set(error, EINVAL,
1757 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1758 "Unsupported action combination");
1762 if (mark_num >= 2) {
1763 rte_flow_error_set(error, EINVAL,
1764 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1765 "Too many mark actions");
1769 if (counter_num >= 2) {
1770 rte_flow_error_set(error, EINVAL,
1771 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1772 "Too many count actions");
1776 if (dest_num + mark_num + counter_num == 0) {
1777 rte_flow_error_set(error, EINVAL,
1778 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1783 /* set default action to PASSTHRU mode, in "mark/count only" case. */
1785 filter->input.dest_ctl =
1786 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_OTHER;
1792 ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
1793 const struct rte_flow_item pattern[],
1794 struct rte_flow_error *error,
1795 struct ice_fdir_filter_conf *filter)
1797 const struct rte_flow_item *item = pattern;
1798 enum rte_flow_item_type item_type;
1799 enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
1800 enum rte_flow_item_type l4 = RTE_FLOW_ITEM_TYPE_END;
1801 enum ice_fdir_tunnel_type tunnel_type = ICE_FDIR_TUNNEL_TYPE_NONE;
1802 const struct rte_flow_item_raw *raw_spec, *raw_mask;
1803 const struct rte_flow_item_eth *eth_spec, *eth_mask;
1804 const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_last, *ipv4_mask;
1805 const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
1806 const struct rte_flow_item_ipv6_frag_ext *ipv6_frag_spec,
1808 const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
1809 const struct rte_flow_item_udp *udp_spec, *udp_mask;
1810 const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
1811 const struct rte_flow_item_vxlan *vxlan_spec, *vxlan_mask;
1812 const struct rte_flow_item_gtp *gtp_spec, *gtp_mask;
1813 const struct rte_flow_item_gtp_psc *gtp_psc_spec, *gtp_psc_mask;
1814 const struct rte_flow_item_esp *esp_spec, *esp_mask;
1815 uint64_t input_set_i = ICE_INSET_NONE; /* only for tunnel inner */
1816 uint64_t input_set_o = ICE_INSET_NONE; /* non-tunnel and tunnel outer */
1817 uint64_t *input_set;
1818 uint8_t flow_type = ICE_FLTR_PTYPE_NONF_NONE;
1819 uint8_t ipv6_addr_mask[16] = {
1820 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1821 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
1823 uint32_t vtc_flow_cpu;
1824 uint16_t ether_type;
1825 enum rte_flow_item_type next_type;
1826 bool is_outer = true;
1827 struct ice_fdir_extra *p_ext_data;
1828 struct ice_fdir_v4 *p_v4 = NULL;
1829 struct ice_fdir_v6 *p_v6 = NULL;
1830 struct ice_parser_result rslt;
1831 struct ice_parser *psr;
1832 uint8_t item_num = 0;
1834 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1835 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN)
1836 tunnel_type = ICE_FDIR_TUNNEL_TYPE_VXLAN;
1837 /* To align with shared code behavior, save gtpu outer
1838 * fields in inner struct.
1840 if (item->type == RTE_FLOW_ITEM_TYPE_GTPU ||
1841 item->type == RTE_FLOW_ITEM_TYPE_GTP_PSC) {
1847 /* This loop parse flow pattern and distinguish Non-tunnel and tunnel
1848 * flow. input_set_i is used for inner part.
1850 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1851 item_type = item->type;
1853 if (item->last && !(item_type == RTE_FLOW_ITEM_TYPE_IPV4 ||
1855 RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT)) {
1856 rte_flow_error_set(error, EINVAL,
1857 RTE_FLOW_ERROR_TYPE_ITEM, item,
1858 "Not support range");
1861 input_set = (tunnel_type && !is_outer) ?
1862 &input_set_i : &input_set_o;
1864 switch (item_type) {
1865 case RTE_FLOW_ITEM_TYPE_RAW: {
1866 raw_spec = item->spec;
1867 raw_mask = item->mask;
1872 /* convert raw spec & mask from byte string to int */
1873 unsigned char *tmp_spec =
1874 (uint8_t *)(uintptr_t)raw_spec->pattern;
1875 unsigned char *tmp_mask =
1876 (uint8_t *)(uintptr_t)raw_mask->pattern;
1877 uint16_t udp_port = 0;
1878 uint16_t tmp_val = 0;
1879 uint8_t pkt_len = 0;
1883 pkt_len = strlen((char *)(uintptr_t)raw_spec->pattern);
1884 if (strlen((char *)(uintptr_t)raw_mask->pattern) !=
1888 for (i = 0, j = 0; i < pkt_len; i += 2, j++) {
1890 if (tmp >= 'a' && tmp <= 'f')
1891 tmp_val = tmp - 'a' + 10;
1892 if (tmp >= 'A' && tmp <= 'F')
1893 tmp_val = tmp - 'A' + 10;
1894 if (tmp >= '0' && tmp <= '9')
1895 tmp_val = tmp - '0';
1898 tmp = tmp_spec[i + 1];
1899 if (tmp >= 'a' && tmp <= 'f')
1900 tmp_spec[j] = tmp_val + tmp - 'a' + 10;
1901 if (tmp >= 'A' && tmp <= 'F')
1902 tmp_spec[j] = tmp_val + tmp - 'A' + 10;
1903 if (tmp >= '0' && tmp <= '9')
1904 tmp_spec[j] = tmp_val + tmp - '0';
1907 if (tmp >= 'a' && tmp <= 'f')
1908 tmp_val = tmp - 'a' + 10;
1909 if (tmp >= 'A' && tmp <= 'F')
1910 tmp_val = tmp - 'A' + 10;
1911 if (tmp >= '0' && tmp <= '9')
1912 tmp_val = tmp - '0';
1915 tmp = tmp_mask[i + 1];
1916 if (tmp >= 'a' && tmp <= 'f')
1917 tmp_mask[j] = tmp_val + tmp - 'a' + 10;
1918 if (tmp >= 'A' && tmp <= 'F')
1919 tmp_mask[j] = tmp_val + tmp - 'A' + 10;
1920 if (tmp >= '0' && tmp <= '9')
1921 tmp_mask[j] = tmp_val + tmp - '0';
1926 if (ice_parser_create(&ad->hw, &psr))
1928 if (ice_get_open_tunnel_port(&ad->hw, TNL_VXLAN,
1930 ice_parser_vxlan_tunnel_set(psr, udp_port,
1932 if (ice_parser_run(psr, tmp_spec, pkt_len, &rslt))
1934 ice_parser_destroy(psr);
1939 filter->prof = (struct ice_parser_profile *)
1940 ice_malloc(&ad->hw, sizeof(*filter->prof));
1944 if (ice_parser_profile_init(&rslt, tmp_spec, tmp_mask,
1945 pkt_len, ICE_BLK_FD, true, filter->prof))
1948 u8 *pkt_buf = (u8 *)ice_malloc(&ad->hw, pkt_len + 1);
1951 rte_memcpy(pkt_buf, tmp_spec, pkt_len);
1952 filter->pkt_buf = pkt_buf;
1954 filter->pkt_len = pkt_len;
1956 filter->parser_ena = true;
1961 case RTE_FLOW_ITEM_TYPE_ETH:
1962 flow_type = ICE_FLTR_PTYPE_NON_IP_L2;
1963 eth_spec = item->spec;
1964 eth_mask = item->mask;
1966 if (!(eth_spec && eth_mask))
1969 if (!rte_is_zero_ether_addr(ð_mask->dst))
1970 *input_set |= ICE_INSET_DMAC;
1971 if (!rte_is_zero_ether_addr(ð_mask->src))
1972 *input_set |= ICE_INSET_SMAC;
1974 next_type = (item + 1)->type;
1975 /* Ignore this field except for ICE_FLTR_PTYPE_NON_IP_L2 */
1976 if (eth_mask->type == RTE_BE16(0xffff) &&
1977 next_type == RTE_FLOW_ITEM_TYPE_END) {
1978 *input_set |= ICE_INSET_ETHERTYPE;
1979 ether_type = rte_be_to_cpu_16(eth_spec->type);
1981 if (ether_type == RTE_ETHER_TYPE_IPV4 ||
1982 ether_type == RTE_ETHER_TYPE_IPV6) {
1983 rte_flow_error_set(error, EINVAL,
1984 RTE_FLOW_ERROR_TYPE_ITEM,
1986 "Unsupported ether_type.");
1991 p_ext_data = (tunnel_type && is_outer) ?
1992 &filter->input.ext_data_outer :
1993 &filter->input.ext_data;
1994 rte_memcpy(&p_ext_data->src_mac,
1995 ð_spec->src, RTE_ETHER_ADDR_LEN);
1996 rte_memcpy(&p_ext_data->dst_mac,
1997 ð_spec->dst, RTE_ETHER_ADDR_LEN);
1998 rte_memcpy(&p_ext_data->ether_type,
1999 ð_spec->type, sizeof(eth_spec->type));
2001 case RTE_FLOW_ITEM_TYPE_IPV4:
2002 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
2003 l3 = RTE_FLOW_ITEM_TYPE_IPV4;
2004 ipv4_spec = item->spec;
2005 ipv4_last = item->last;
2006 ipv4_mask = item->mask;
2007 p_v4 = (tunnel_type && is_outer) ?
2008 &filter->input.ip_outer.v4 :
2009 &filter->input.ip.v4;
2011 if (!(ipv4_spec && ipv4_mask))
2014 /* Check IPv4 mask and update input set */
2015 if (ipv4_mask->hdr.version_ihl ||
2016 ipv4_mask->hdr.total_length ||
2017 ipv4_mask->hdr.hdr_checksum) {
2018 rte_flow_error_set(error, EINVAL,
2019 RTE_FLOW_ERROR_TYPE_ITEM,
2021 "Invalid IPv4 mask.");
2026 (ipv4_last->hdr.version_ihl ||
2027 ipv4_last->hdr.type_of_service ||
2028 ipv4_last->hdr.time_to_live ||
2029 ipv4_last->hdr.total_length |
2030 ipv4_last->hdr.next_proto_id ||
2031 ipv4_last->hdr.hdr_checksum ||
2032 ipv4_last->hdr.src_addr ||
2033 ipv4_last->hdr.dst_addr)) {
2034 rte_flow_error_set(error, EINVAL,
2035 RTE_FLOW_ERROR_TYPE_ITEM,
2036 item, "Invalid IPv4 last.");
2040 /* Mask for IPv4 src/dst addrs not supported */
2041 if (!ipv4_mask->hdr.src_addr &&
2042 ipv4_mask->hdr.src_addr != UINT32_MAX)
2044 if (!ipv4_mask->hdr.dst_addr &&
2045 ipv4_mask->hdr.dst_addr != UINT32_MAX)
2048 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
2049 *input_set |= ICE_INSET_IPV4_DST;
2050 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
2051 *input_set |= ICE_INSET_IPV4_SRC;
2052 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
2053 *input_set |= ICE_INSET_IPV4_TTL;
2054 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
2055 *input_set |= ICE_INSET_IPV4_PROTO;
2056 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
2057 *input_set |= ICE_INSET_IPV4_TOS;
2059 p_v4->dst_ip = ipv4_spec->hdr.dst_addr;
2060 p_v4->src_ip = ipv4_spec->hdr.src_addr;
2061 p_v4->ttl = ipv4_spec->hdr.time_to_live;
2062 p_v4->proto = ipv4_spec->hdr.next_proto_id;
2063 p_v4->tos = ipv4_spec->hdr.type_of_service;
2066 * spec is 0x2000, mask is 0x2000
2068 if (ipv4_spec->hdr.fragment_offset ==
2069 rte_cpu_to_be_16(RTE_IPV4_HDR_MF_FLAG) &&
2070 ipv4_mask->hdr.fragment_offset ==
2071 rte_cpu_to_be_16(RTE_IPV4_HDR_MF_FLAG)) {
2072 /* all IPv4 fragment packet has the same
2073 * ethertype, if the spec and mask is valid,
2074 * set ethertype into input set.
2076 flow_type = ICE_FLTR_PTYPE_FRAG_IPV4;
2077 *input_set |= ICE_INSET_ETHERTYPE;
2078 input_set_o |= ICE_INSET_ETHERTYPE;
2079 } else if (ipv4_mask->hdr.packet_id == UINT16_MAX) {
2080 rte_flow_error_set(error, EINVAL,
2081 RTE_FLOW_ERROR_TYPE_ITEM,
2082 item, "Invalid IPv4 mask.");
2087 case RTE_FLOW_ITEM_TYPE_IPV6:
2088 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
2089 l3 = RTE_FLOW_ITEM_TYPE_IPV6;
2090 ipv6_spec = item->spec;
2091 ipv6_mask = item->mask;
2092 p_v6 = (tunnel_type && is_outer) ?
2093 &filter->input.ip_outer.v6 :
2094 &filter->input.ip.v6;
2096 if (!(ipv6_spec && ipv6_mask))
2099 /* Check IPv6 mask and update input set */
2100 if (ipv6_mask->hdr.payload_len) {
2101 rte_flow_error_set(error, EINVAL,
2102 RTE_FLOW_ERROR_TYPE_ITEM,
2104 "Invalid IPv6 mask");
2108 if (!memcmp(ipv6_mask->hdr.src_addr, ipv6_addr_mask,
2109 RTE_DIM(ipv6_mask->hdr.src_addr)))
2110 *input_set |= ICE_INSET_IPV6_SRC;
2111 if (!memcmp(ipv6_mask->hdr.dst_addr, ipv6_addr_mask,
2112 RTE_DIM(ipv6_mask->hdr.dst_addr)))
2113 *input_set |= ICE_INSET_IPV6_DST;
2115 if ((ipv6_mask->hdr.vtc_flow &
2116 rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
2117 == rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
2118 *input_set |= ICE_INSET_IPV6_TC;
2119 if (ipv6_mask->hdr.proto == UINT8_MAX)
2120 *input_set |= ICE_INSET_IPV6_NEXT_HDR;
2121 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
2122 *input_set |= ICE_INSET_IPV6_HOP_LIMIT;
2124 rte_memcpy(&p_v6->dst_ip, ipv6_spec->hdr.dst_addr, 16);
2125 rte_memcpy(&p_v6->src_ip, ipv6_spec->hdr.src_addr, 16);
2126 vtc_flow_cpu = rte_be_to_cpu_32(ipv6_spec->hdr.vtc_flow);
2127 p_v6->tc = (uint8_t)(vtc_flow_cpu >> ICE_FDIR_IPV6_TC_OFFSET);
2128 p_v6->proto = ipv6_spec->hdr.proto;
2129 p_v6->hlim = ipv6_spec->hdr.hop_limits;
2131 case RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT:
2132 l3 = RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT;
2133 flow_type = ICE_FLTR_PTYPE_FRAG_IPV6;
2134 ipv6_frag_spec = item->spec;
2135 ipv6_frag_mask = item->mask;
2137 if (!(ipv6_frag_spec && ipv6_frag_mask))
2141 * spec is 0x1, mask is 0x1
2143 if (ipv6_frag_spec->hdr.frag_data ==
2144 rte_cpu_to_be_16(1) &&
2145 ipv6_frag_mask->hdr.frag_data ==
2146 rte_cpu_to_be_16(1)) {
2147 /* all IPv6 fragment packet has the same
2148 * ethertype, if the spec and mask is valid,
2149 * set ethertype into input set.
2151 *input_set |= ICE_INSET_ETHERTYPE;
2152 input_set_o |= ICE_INSET_ETHERTYPE;
2153 } else if (ipv6_frag_mask->hdr.id == UINT32_MAX) {
2154 rte_flow_error_set(error, EINVAL,
2155 RTE_FLOW_ERROR_TYPE_ITEM,
2156 item, "Invalid IPv6 mask.");
2162 case RTE_FLOW_ITEM_TYPE_TCP:
2163 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2164 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_TCP;
2165 if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2166 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_TCP;
2168 tcp_spec = item->spec;
2169 tcp_mask = item->mask;
2171 if (!(tcp_spec && tcp_mask))
2174 /* Check TCP mask and update input set */
2175 if (tcp_mask->hdr.sent_seq ||
2176 tcp_mask->hdr.recv_ack ||
2177 tcp_mask->hdr.data_off ||
2178 tcp_mask->hdr.tcp_flags ||
2179 tcp_mask->hdr.rx_win ||
2180 tcp_mask->hdr.cksum ||
2181 tcp_mask->hdr.tcp_urp) {
2182 rte_flow_error_set(error, EINVAL,
2183 RTE_FLOW_ERROR_TYPE_ITEM,
2185 "Invalid TCP mask");
2189 /* Mask for TCP src/dst ports not supported */
2190 if (!tcp_mask->hdr.src_port &&
2191 tcp_mask->hdr.src_port != UINT16_MAX)
2193 if (!tcp_mask->hdr.dst_port &&
2194 tcp_mask->hdr.dst_port != UINT16_MAX)
2197 if (tcp_mask->hdr.src_port == UINT16_MAX)
2198 *input_set |= ICE_INSET_TCP_SRC_PORT;
2199 if (tcp_mask->hdr.dst_port == UINT16_MAX)
2200 *input_set |= ICE_INSET_TCP_DST_PORT;
2202 /* Get filter info */
2203 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2205 p_v4->dst_port = tcp_spec->hdr.dst_port;
2206 p_v4->src_port = tcp_spec->hdr.src_port;
2207 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2209 p_v6->dst_port = tcp_spec->hdr.dst_port;
2210 p_v6->src_port = tcp_spec->hdr.src_port;
2213 case RTE_FLOW_ITEM_TYPE_UDP:
2214 l4 = RTE_FLOW_ITEM_TYPE_UDP;
2215 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2216 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
2217 if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2218 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_UDP;
2220 udp_spec = item->spec;
2221 udp_mask = item->mask;
2223 if (!(udp_spec && udp_mask))
2226 /* Check UDP mask and update input set*/
2227 if (udp_mask->hdr.dgram_len ||
2228 udp_mask->hdr.dgram_cksum) {
2229 rte_flow_error_set(error, EINVAL,
2230 RTE_FLOW_ERROR_TYPE_ITEM,
2232 "Invalid UDP mask");
2236 /* Mask for UDP src/dst ports not supported */
2237 if (!udp_mask->hdr.src_port &&
2238 udp_mask->hdr.src_port != UINT16_MAX)
2240 if (!udp_mask->hdr.dst_port &&
2241 udp_mask->hdr.dst_port != UINT16_MAX)
2244 if (udp_mask->hdr.src_port == UINT16_MAX)
2245 *input_set |= ICE_INSET_UDP_SRC_PORT;
2246 if (udp_mask->hdr.dst_port == UINT16_MAX)
2247 *input_set |= ICE_INSET_UDP_DST_PORT;
2249 /* Get filter info */
2250 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2252 p_v4->dst_port = udp_spec->hdr.dst_port;
2253 p_v4->src_port = udp_spec->hdr.src_port;
2254 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2256 p_v6->src_port = udp_spec->hdr.src_port;
2257 p_v6->dst_port = udp_spec->hdr.dst_port;
2260 case RTE_FLOW_ITEM_TYPE_SCTP:
2261 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2262 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
2263 if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2264 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
2266 sctp_spec = item->spec;
2267 sctp_mask = item->mask;
2269 if (!(sctp_spec && sctp_mask))
2272 /* Check SCTP mask and update input set */
2273 if (sctp_mask->hdr.cksum) {
2274 rte_flow_error_set(error, EINVAL,
2275 RTE_FLOW_ERROR_TYPE_ITEM,
2277 "Invalid UDP mask");
2281 /* Mask for SCTP src/dst ports not supported */
2282 if (!sctp_mask->hdr.src_port &&
2283 sctp_mask->hdr.src_port != UINT16_MAX)
2285 if (!sctp_mask->hdr.dst_port &&
2286 sctp_mask->hdr.dst_port != UINT16_MAX)
2289 if (sctp_mask->hdr.src_port == UINT16_MAX)
2290 *input_set |= ICE_INSET_SCTP_SRC_PORT;
2291 if (sctp_mask->hdr.dst_port == UINT16_MAX)
2292 *input_set |= ICE_INSET_SCTP_DST_PORT;
2294 /* Get filter info */
2295 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
2297 p_v4->dst_port = sctp_spec->hdr.dst_port;
2298 p_v4->src_port = sctp_spec->hdr.src_port;
2299 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
2301 p_v6->dst_port = sctp_spec->hdr.dst_port;
2302 p_v6->src_port = sctp_spec->hdr.src_port;
2305 case RTE_FLOW_ITEM_TYPE_VOID:
2307 case RTE_FLOW_ITEM_TYPE_VXLAN:
2308 l3 = RTE_FLOW_ITEM_TYPE_END;
2309 vxlan_spec = item->spec;
2310 vxlan_mask = item->mask;
2313 if (!(vxlan_spec && vxlan_mask))
2316 if (vxlan_mask->hdr.vx_flags) {
2317 rte_flow_error_set(error, EINVAL,
2318 RTE_FLOW_ERROR_TYPE_ITEM,
2320 "Invalid vxlan field");
2324 if (vxlan_mask->hdr.vx_vni)
2325 *input_set |= ICE_INSET_VXLAN_VNI;
2327 filter->input.vxlan_data.vni = vxlan_spec->hdr.vx_vni;
2330 case RTE_FLOW_ITEM_TYPE_GTPU:
2331 l3 = RTE_FLOW_ITEM_TYPE_END;
2332 tunnel_type = ICE_FDIR_TUNNEL_TYPE_GTPU;
2333 gtp_spec = item->spec;
2334 gtp_mask = item->mask;
2336 if (!(gtp_spec && gtp_mask))
2339 if (gtp_mask->v_pt_rsv_flags ||
2340 gtp_mask->msg_type ||
2341 gtp_mask->msg_len) {
2342 rte_flow_error_set(error, EINVAL,
2343 RTE_FLOW_ERROR_TYPE_ITEM,
2345 "Invalid GTP mask");
2349 if (gtp_mask->teid == UINT32_MAX)
2350 input_set_o |= ICE_INSET_GTPU_TEID;
2352 filter->input.gtpu_data.teid = gtp_spec->teid;
2354 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
2355 tunnel_type = ICE_FDIR_TUNNEL_TYPE_GTPU_EH;
2356 gtp_psc_spec = item->spec;
2357 gtp_psc_mask = item->mask;
2359 if (!(gtp_psc_spec && gtp_psc_mask))
2362 if (gtp_psc_mask->hdr.qfi == 0x3F)
2363 input_set_o |= ICE_INSET_GTPU_QFI;
2365 filter->input.gtpu_data.qfi =
2366 gtp_psc_spec->hdr.qfi;
2368 case RTE_FLOW_ITEM_TYPE_ESP:
2369 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4 &&
2370 l4 == RTE_FLOW_ITEM_TYPE_UDP)
2371 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_NAT_T_ESP;
2372 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6 &&
2373 l4 == RTE_FLOW_ITEM_TYPE_UDP)
2374 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_NAT_T_ESP;
2375 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV4 &&
2376 l4 == RTE_FLOW_ITEM_TYPE_END)
2377 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_ESP;
2378 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6 &&
2379 l4 == RTE_FLOW_ITEM_TYPE_END)
2380 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_ESP;
2382 esp_spec = item->spec;
2383 esp_mask = item->mask;
2385 if (!(esp_spec && esp_mask))
2388 if (esp_mask->hdr.spi == UINT32_MAX) {
2389 if (l4 == RTE_FLOW_ITEM_TYPE_UDP)
2390 *input_set |= ICE_INSET_NAT_T_ESP_SPI;
2392 *input_set |= ICE_INSET_ESP_SPI;
2395 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4)
2396 filter->input.ip.v4.sec_parm_idx =
2398 else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6)
2399 filter->input.ip.v6.sec_parm_idx =
2403 rte_flow_error_set(error, EINVAL,
2404 RTE_FLOW_ERROR_TYPE_ITEM,
2406 "Invalid pattern item.");
2411 if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU &&
2412 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
2413 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_GTPU;
2414 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU_EH &&
2415 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
2416 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_GTPU_EH;
2417 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU &&
2418 flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
2419 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_GTPU;
2420 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_GTPU_EH &&
2421 flow_type == ICE_FLTR_PTYPE_NONF_IPV6_UDP)
2422 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_GTPU_EH;
2423 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2424 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_UDP)
2425 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_UDP;
2426 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2427 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_TCP)
2428 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_TCP;
2429 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2430 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_SCTP)
2431 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_SCTP;
2432 else if (tunnel_type == ICE_FDIR_TUNNEL_TYPE_VXLAN &&
2433 flow_type == ICE_FLTR_PTYPE_NONF_IPV4_OTHER)
2434 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_UDP_VXLAN_IPV4_OTHER;
2436 filter->tunnel_type = tunnel_type;
2437 filter->input.flow_type = flow_type;
2438 filter->input_set_o = input_set_o;
2439 filter->input_set_i = input_set_i;
2445 ice_fdir_parse(struct ice_adapter *ad,
2446 struct ice_pattern_match_item *array,
2448 const struct rte_flow_item pattern[],
2449 const struct rte_flow_action actions[],
2452 struct rte_flow_error *error)
2454 struct ice_pf *pf = &ad->pf;
2455 struct ice_fdir_filter_conf *filter = &pf->fdir.conf;
2456 struct ice_pattern_match_item *item = NULL;
2461 memset(filter, 0, sizeof(*filter));
2462 item = ice_search_pattern_match_item(ad, pattern, array, array_len,
2465 if (!ad->devargs.pipe_mode_support && priority >= 1)
2471 ret = ice_fdir_parse_pattern(ad, pattern, error, filter);
2475 if (item->pattern_list[0] == RTE_FLOW_ITEM_TYPE_RAW)
2478 input_set = filter->input_set_o | filter->input_set_i;
2479 input_set = raw ? ~input_set : input_set;
2481 if (!input_set || filter->input_set_o &
2482 ~(item->input_set_mask_o | ICE_INSET_ETHERTYPE) ||
2483 filter->input_set_i & ~item->input_set_mask_i) {
2484 rte_flow_error_set(error, EINVAL,
2485 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
2487 "Invalid input set");
2492 ret = ice_fdir_parse_action(ad, actions, error, filter);
2502 rte_free(filter->prof);
2503 rte_free(filter->pkt_buf);
2508 static struct ice_flow_parser ice_fdir_parser = {
2509 .engine = &ice_fdir_engine,
2510 .array = ice_fdir_pattern_list,
2511 .array_len = RTE_DIM(ice_fdir_pattern_list),
2512 .parse_pattern_action = ice_fdir_parse,
2513 .stage = ICE_FLOW_STAGE_DISTRIBUTOR,
2516 RTE_INIT(ice_fdir_engine_register)
2518 ice_register_flow_engine(&ice_fdir_engine);