4 #include <rte_hash_crc.h>
5 #include "base/ice_fdir.h"
6 #include "base/ice_flow.h"
7 #include "base/ice_type.h"
8 #include "ice_ethdev.h"
10 #include "ice_generic_flow.h"
12 #define ICE_FDIR_IPV6_TC_OFFSET 20
13 #define ICE_IPV6_TC_MASK (0xFF << ICE_FDIR_IPV6_TC_OFFSET)
15 #define ICE_FDIR_MAX_QREGION_SIZE 128
17 #define ICE_FDIR_INSET_ETH_IPV4 (\
19 ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_IPV4_TOS | \
20 ICE_INSET_IPV4_TTL | ICE_INSET_IPV4_PROTO)
22 #define ICE_FDIR_INSET_ETH_IPV4_UDP (\
23 ICE_FDIR_INSET_ETH_IPV4 | \
24 ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
26 #define ICE_FDIR_INSET_ETH_IPV4_TCP (\
27 ICE_FDIR_INSET_ETH_IPV4 | \
28 ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
30 #define ICE_FDIR_INSET_ETH_IPV4_SCTP (\
31 ICE_FDIR_INSET_ETH_IPV4 | \
32 ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
34 #define ICE_FDIR_INSET_ETH_IPV6 (\
35 ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_IPV6_TC | \
36 ICE_INSET_IPV6_HOP_LIMIT | ICE_INSET_IPV6_NEXT_HDR)
38 #define ICE_FDIR_INSET_ETH_IPV6_UDP (\
39 ICE_FDIR_INSET_ETH_IPV6 | \
40 ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT)
42 #define ICE_FDIR_INSET_ETH_IPV6_TCP (\
43 ICE_FDIR_INSET_ETH_IPV6 | \
44 ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT)
46 #define ICE_FDIR_INSET_ETH_IPV6_SCTP (\
47 ICE_FDIR_INSET_ETH_IPV6 | \
48 ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
50 #define ICE_FDIR_INSET_VXLAN_IPV4 (\
51 ICE_INSET_TUN_IPV4_SRC | ICE_INSET_TUN_IPV4_DST)
53 #define ICE_FDIR_INSET_VXLAN_IPV4_TCP (\
54 ICE_FDIR_INSET_VXLAN_IPV4 | \
55 ICE_INSET_TUN_TCP_SRC_PORT | ICE_INSET_TUN_TCP_DST_PORT)
57 #define ICE_FDIR_INSET_VXLAN_IPV4_UDP (\
58 ICE_FDIR_INSET_VXLAN_IPV4 | \
59 ICE_INSET_TUN_UDP_SRC_PORT | ICE_INSET_TUN_UDP_DST_PORT)
61 #define ICE_FDIR_INSET_VXLAN_IPV4_SCTP (\
62 ICE_FDIR_INSET_VXLAN_IPV4 | \
63 ICE_INSET_TUN_SCTP_SRC_PORT | ICE_INSET_TUN_SCTP_DST_PORT)
65 static struct ice_pattern_match_item ice_fdir_pattern[] = {
66 {pattern_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4, ICE_INSET_NONE},
67 {pattern_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_UDP, ICE_INSET_NONE},
68 {pattern_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_TCP, ICE_INSET_NONE},
69 {pattern_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_SCTP, ICE_INSET_NONE},
70 {pattern_eth_ipv6, ICE_FDIR_INSET_ETH_IPV6, ICE_INSET_NONE},
71 {pattern_eth_ipv6_udp, ICE_FDIR_INSET_ETH_IPV6_UDP, ICE_INSET_NONE},
72 {pattern_eth_ipv6_tcp, ICE_FDIR_INSET_ETH_IPV6_TCP, ICE_INSET_NONE},
73 {pattern_eth_ipv6_sctp, ICE_FDIR_INSET_ETH_IPV6_SCTP, ICE_INSET_NONE},
74 {pattern_eth_ipv4_udp_vxlan_ipv4,
75 ICE_FDIR_INSET_VXLAN_IPV4, ICE_INSET_NONE},
76 {pattern_eth_ipv4_udp_vxlan_ipv4_udp,
77 ICE_FDIR_INSET_VXLAN_IPV4_UDP, ICE_INSET_NONE},
78 {pattern_eth_ipv4_udp_vxlan_ipv4_tcp,
79 ICE_FDIR_INSET_VXLAN_IPV4_TCP, ICE_INSET_NONE},
80 {pattern_eth_ipv4_udp_vxlan_ipv4_sctp,
81 ICE_FDIR_INSET_VXLAN_IPV4_SCTP, ICE_INSET_NONE},
82 {pattern_eth_ipv4_udp_vxlan_eth_ipv4,
83 ICE_FDIR_INSET_VXLAN_IPV4, ICE_INSET_NONE},
84 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_udp,
85 ICE_FDIR_INSET_VXLAN_IPV4_UDP, ICE_INSET_NONE},
86 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_tcp,
87 ICE_FDIR_INSET_VXLAN_IPV4_TCP, ICE_INSET_NONE},
88 {pattern_eth_ipv4_udp_vxlan_eth_ipv4_sctp,
89 ICE_FDIR_INSET_VXLAN_IPV4_SCTP, ICE_INSET_NONE},
92 static struct ice_flow_parser ice_fdir_parser;
94 static const struct rte_memzone *
95 ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
97 return rte_memzone_reserve_aligned(name, len, socket_id,
98 RTE_MEMZONE_IOVA_CONTIG,
102 #define ICE_FDIR_MZ_NAME "FDIR_MEMZONE"
105 ice_fdir_prof_alloc(struct ice_hw *hw)
107 enum ice_fltr_ptype ptype, fltr_ptype;
109 if (!hw->fdir_prof) {
110 hw->fdir_prof = (struct ice_fd_hw_prof **)
111 ice_malloc(hw, ICE_FLTR_PTYPE_MAX *
112 sizeof(*hw->fdir_prof));
116 for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
117 ptype < ICE_FLTR_PTYPE_MAX;
119 if (!hw->fdir_prof[ptype]) {
120 hw->fdir_prof[ptype] = (struct ice_fd_hw_prof *)
121 ice_malloc(hw, sizeof(**hw->fdir_prof));
122 if (!hw->fdir_prof[ptype])
129 for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
132 rte_free(hw->fdir_prof[fltr_ptype]);
133 rte_free(hw->fdir_prof);
138 ice_fdir_counter_pool_add(__rte_unused struct ice_pf *pf,
139 struct ice_fdir_counter_pool_container *container,
140 uint32_t index_start,
143 struct ice_fdir_counter_pool *pool;
147 pool = rte_zmalloc("ice_fdir_counter_pool",
149 sizeof(struct ice_fdir_counter) * len,
153 "Failed to allocate memory for fdir counter pool");
157 TAILQ_INIT(&pool->counter_list);
158 TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
160 for (i = 0; i < len; i++) {
161 struct ice_fdir_counter *counter = &pool->counters[i];
163 counter->hw_index = index_start + i;
164 TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
167 if (container->index_free == ICE_FDIR_COUNTER_MAX_POOL_SIZE) {
168 PMD_INIT_LOG(ERR, "FDIR counter pool is full");
173 container->pools[container->index_free++] = pool;
182 ice_fdir_counter_init(struct ice_pf *pf)
184 struct ice_hw *hw = ICE_PF_TO_HW(pf);
185 struct ice_fdir_info *fdir_info = &pf->fdir;
186 struct ice_fdir_counter_pool_container *container =
188 uint32_t cnt_index, len;
191 TAILQ_INIT(&container->pool_list);
193 cnt_index = ICE_FDIR_COUNTER_INDEX(hw->fd_ctr_base);
194 len = ICE_FDIR_COUNTERS_PER_BLOCK;
196 ret = ice_fdir_counter_pool_add(pf, container, cnt_index, len);
198 PMD_INIT_LOG(ERR, "Failed to add fdir pool to container");
206 ice_fdir_counter_release(struct ice_pf *pf)
208 struct ice_fdir_info *fdir_info = &pf->fdir;
209 struct ice_fdir_counter_pool_container *container =
213 for (i = 0; i < container->index_free; i++)
214 rte_free(container->pools[i]);
219 static struct ice_fdir_counter *
220 ice_fdir_counter_shared_search(struct ice_fdir_counter_pool_container
224 struct ice_fdir_counter_pool *pool;
225 struct ice_fdir_counter *counter;
228 TAILQ_FOREACH(pool, &container->pool_list, next) {
229 for (i = 0; i < ICE_FDIR_COUNTERS_PER_BLOCK; i++) {
230 counter = &pool->counters[i];
232 if (counter->shared &&
242 static struct ice_fdir_counter *
243 ice_fdir_counter_alloc(struct ice_pf *pf, uint32_t shared, uint32_t id)
245 struct ice_hw *hw = ICE_PF_TO_HW(pf);
246 struct ice_fdir_info *fdir_info = &pf->fdir;
247 struct ice_fdir_counter_pool_container *container =
249 struct ice_fdir_counter_pool *pool = NULL;
250 struct ice_fdir_counter *counter_free = NULL;
253 counter_free = ice_fdir_counter_shared_search(container, id);
255 if (counter_free->ref_cnt + 1 == 0) {
259 counter_free->ref_cnt++;
264 TAILQ_FOREACH(pool, &container->pool_list, next) {
265 counter_free = TAILQ_FIRST(&pool->counter_list);
272 PMD_DRV_LOG(ERR, "No free counter found\n");
276 counter_free->shared = shared;
277 counter_free->id = id;
278 counter_free->ref_cnt = 1;
279 counter_free->pool = pool;
281 /* reset statistic counter value */
282 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter_free->hw_index), 0);
283 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter_free->hw_index), 0);
285 TAILQ_REMOVE(&pool->counter_list, counter_free, next);
286 if (TAILQ_EMPTY(&pool->counter_list)) {
287 TAILQ_REMOVE(&container->pool_list, pool, next);
288 TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
295 ice_fdir_counter_free(__rte_unused struct ice_pf *pf,
296 struct ice_fdir_counter *counter)
301 if (--counter->ref_cnt == 0) {
302 struct ice_fdir_counter_pool *pool = counter->pool;
304 TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
309 ice_fdir_init_filter_list(struct ice_pf *pf)
311 struct rte_eth_dev *dev = pf->adapter->eth_dev;
312 struct ice_fdir_info *fdir_info = &pf->fdir;
313 char fdir_hash_name[RTE_HASH_NAMESIZE];
316 struct rte_hash_parameters fdir_hash_params = {
317 .name = fdir_hash_name,
318 .entries = ICE_MAX_FDIR_FILTER_NUM,
319 .key_len = sizeof(struct ice_fdir_fltr_pattern),
320 .hash_func = rte_hash_crc,
321 .hash_func_init_val = 0,
322 .socket_id = rte_socket_id(),
325 /* Initialize hash */
326 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
327 "fdir_%s", dev->device->name);
328 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
329 if (!fdir_info->hash_table) {
330 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
333 fdir_info->hash_map = rte_zmalloc("ice_fdir_hash_map",
334 sizeof(*fdir_info->hash_map) *
335 ICE_MAX_FDIR_FILTER_NUM,
337 if (!fdir_info->hash_map) {
339 "Failed to allocate memory for fdir hash map!");
341 goto err_fdir_hash_map_alloc;
345 err_fdir_hash_map_alloc:
346 rte_hash_free(fdir_info->hash_table);
352 ice_fdir_release_filter_list(struct ice_pf *pf)
354 struct ice_fdir_info *fdir_info = &pf->fdir;
356 if (fdir_info->hash_map)
357 rte_free(fdir_info->hash_map);
358 if (fdir_info->hash_table)
359 rte_hash_free(fdir_info->hash_table);
363 * ice_fdir_setup - reserve and initialize the Flow Director resources
364 * @pf: board private structure
367 ice_fdir_setup(struct ice_pf *pf)
369 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
370 struct ice_hw *hw = ICE_PF_TO_HW(pf);
371 const struct rte_memzone *mz = NULL;
372 char z_name[RTE_MEMZONE_NAMESIZE];
374 int err = ICE_SUCCESS;
376 if ((pf->flags & ICE_FLAG_FDIR) == 0) {
377 PMD_INIT_LOG(ERR, "HW doesn't support FDIR");
381 PMD_DRV_LOG(INFO, "FDIR HW Capabilities: fd_fltr_guar = %u,"
382 " fd_fltr_best_effort = %u.",
383 hw->func_caps.fd_fltr_guar,
384 hw->func_caps.fd_fltr_best_effort);
386 if (pf->fdir.fdir_vsi) {
387 PMD_DRV_LOG(INFO, "FDIR initialization has been done.");
391 /* make new FDIR VSI */
392 vsi = ice_setup_vsi(pf, ICE_VSI_CTRL);
394 PMD_DRV_LOG(ERR, "Couldn't create FDIR VSI.");
397 pf->fdir.fdir_vsi = vsi;
399 err = ice_fdir_init_filter_list(pf);
401 PMD_DRV_LOG(ERR, "Failed to init FDIR filter list.");
405 err = ice_fdir_counter_init(pf);
407 PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
411 /*Fdir tx queue setup*/
412 err = ice_fdir_setup_tx_resources(pf);
414 PMD_DRV_LOG(ERR, "Failed to setup FDIR TX resources.");
418 /*Fdir rx queue setup*/
419 err = ice_fdir_setup_rx_resources(pf);
421 PMD_DRV_LOG(ERR, "Failed to setup FDIR RX resources.");
425 err = ice_fdir_tx_queue_start(eth_dev, pf->fdir.txq->queue_id);
427 PMD_DRV_LOG(ERR, "Failed to start FDIR TX queue.");
431 err = ice_fdir_rx_queue_start(eth_dev, pf->fdir.rxq->queue_id);
433 PMD_DRV_LOG(ERR, "Failed to start FDIR RX queue.");
437 /* reserve memory for the fdir programming packet */
438 snprintf(z_name, sizeof(z_name), "ICE_%s_%d",
440 eth_dev->data->port_id);
441 mz = ice_memzone_reserve(z_name, ICE_FDIR_PKT_LEN, SOCKET_ID_ANY);
443 PMD_DRV_LOG(ERR, "Cannot init memzone for "
444 "flow director program packet.");
448 pf->fdir.prg_pkt = mz->addr;
449 pf->fdir.dma_addr = mz->iova;
451 err = ice_fdir_prof_alloc(hw);
453 PMD_DRV_LOG(ERR, "Cannot allocate memory for "
454 "flow director profile.");
459 PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
464 ice_rx_queue_release(pf->fdir.rxq);
467 ice_tx_queue_release(pf->fdir.txq);
470 ice_release_vsi(vsi);
471 pf->fdir.fdir_vsi = NULL;
476 ice_fdir_prof_free(struct ice_hw *hw)
478 enum ice_fltr_ptype ptype;
480 for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
481 ptype < ICE_FLTR_PTYPE_MAX;
483 rte_free(hw->fdir_prof[ptype]);
485 rte_free(hw->fdir_prof);
488 /* Remove a profile for some filter type */
490 ice_fdir_prof_rm(struct ice_pf *pf, enum ice_fltr_ptype ptype, bool is_tunnel)
492 struct ice_hw *hw = ICE_PF_TO_HW(pf);
493 struct ice_fd_hw_prof *hw_prof;
498 if (!hw->fdir_prof || !hw->fdir_prof[ptype])
501 hw_prof = hw->fdir_prof[ptype];
503 prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
504 for (i = 0; i < pf->hw_prof_cnt[ptype][is_tunnel]; i++) {
505 if (hw_prof->entry_h[i][is_tunnel]) {
506 vsi_num = ice_get_hw_vsi_num(hw,
508 ice_rem_prof_id_flow(hw, ICE_BLK_FD,
510 ice_flow_rem_entry(hw,
511 hw_prof->entry_h[i][is_tunnel]);
512 hw_prof->entry_h[i][is_tunnel] = 0;
515 ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
516 rte_free(hw_prof->fdir_seg[is_tunnel]);
517 hw_prof->fdir_seg[is_tunnel] = NULL;
519 for (i = 0; i < hw_prof->cnt; i++)
520 hw_prof->vsi_h[i] = 0;
521 pf->hw_prof_cnt[ptype][is_tunnel] = 0;
524 /* Remove all created profiles */
526 ice_fdir_prof_rm_all(struct ice_pf *pf)
528 enum ice_fltr_ptype ptype;
530 for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
531 ptype < ICE_FLTR_PTYPE_MAX;
533 ice_fdir_prof_rm(pf, ptype, false);
534 ice_fdir_prof_rm(pf, ptype, true);
539 * ice_fdir_teardown - release the Flow Director resources
540 * @pf: board private structure
543 ice_fdir_teardown(struct ice_pf *pf)
545 struct rte_eth_dev *eth_dev = pf->adapter->eth_dev;
546 struct ice_hw *hw = ICE_PF_TO_HW(pf);
550 vsi = pf->fdir.fdir_vsi;
554 err = ice_fdir_tx_queue_stop(eth_dev, pf->fdir.txq->queue_id);
556 PMD_DRV_LOG(ERR, "Failed to stop TX queue.");
558 err = ice_fdir_rx_queue_stop(eth_dev, pf->fdir.rxq->queue_id);
560 PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
562 err = ice_fdir_counter_release(pf);
564 PMD_DRV_LOG(ERR, "Failed to release FDIR counter resource.");
566 ice_fdir_release_filter_list(pf);
568 ice_tx_queue_release(pf->fdir.txq);
570 ice_rx_queue_release(pf->fdir.rxq);
572 ice_fdir_prof_rm_all(pf);
573 ice_fdir_prof_free(hw);
574 ice_release_vsi(vsi);
575 pf->fdir.fdir_vsi = NULL;
579 ice_fdir_hw_tbl_conf(struct ice_pf *pf, struct ice_vsi *vsi,
580 struct ice_vsi *ctrl_vsi,
581 struct ice_flow_seg_info *seg,
582 enum ice_fltr_ptype ptype,
585 struct ice_hw *hw = ICE_PF_TO_HW(pf);
586 enum ice_flow_dir dir = ICE_FLOW_RX;
587 struct ice_flow_seg_info *ori_seg;
588 struct ice_fd_hw_prof *hw_prof;
589 struct ice_flow_prof *prof;
590 uint64_t entry_1 = 0;
591 uint64_t entry_2 = 0;
596 hw_prof = hw->fdir_prof[ptype];
597 ori_seg = hw_prof->fdir_seg[is_tunnel];
600 if (!memcmp(ori_seg, seg, sizeof(*seg)))
603 if (!memcmp(ori_seg, &seg[1], sizeof(*seg)))
607 if (pf->fdir_fltr_cnt[ptype][is_tunnel])
610 ice_fdir_prof_rm(pf, ptype, is_tunnel);
613 prof_id = ptype + is_tunnel * ICE_FLTR_PTYPE_MAX;
614 ret = ice_flow_add_prof(hw, ICE_BLK_FD, dir, prof_id, seg,
615 (is_tunnel) ? 2 : 1, NULL, 0, &prof);
618 ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
619 vsi->idx, ICE_FLOW_PRIO_NORMAL,
620 seg, NULL, 0, &entry_1);
622 PMD_DRV_LOG(ERR, "Failed to add main VSI flow entry for %d.",
626 ret = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id, vsi->idx,
627 ctrl_vsi->idx, ICE_FLOW_PRIO_NORMAL,
628 seg, NULL, 0, &entry_2);
630 PMD_DRV_LOG(ERR, "Failed to add control VSI flow entry for %d.",
635 pf->hw_prof_cnt[ptype][is_tunnel] = 0;
637 hw_prof->fdir_seg[is_tunnel] = seg;
638 hw_prof->vsi_h[hw_prof->cnt] = vsi->idx;
639 hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_1;
640 pf->hw_prof_cnt[ptype][is_tunnel]++;
641 hw_prof->vsi_h[hw_prof->cnt] = ctrl_vsi->idx;
642 hw_prof->entry_h[hw_prof->cnt++][is_tunnel] = entry_2;
643 pf->hw_prof_cnt[ptype][is_tunnel]++;
648 vsi_num = ice_get_hw_vsi_num(hw, vsi->idx);
649 ice_rem_prof_id_flow(hw, ICE_BLK_FD, vsi_num, prof_id);
650 ice_flow_rem_entry(hw, entry_1);
652 ice_flow_rem_prof(hw, ICE_BLK_FD, prof_id);
658 ice_fdir_input_set_parse(uint64_t inset, enum ice_flow_field *field)
662 struct ice_inset_map {
664 enum ice_flow_field fld;
666 static const struct ice_inset_map ice_inset_map[] = {
667 {ICE_INSET_DMAC, ICE_FLOW_FIELD_IDX_ETH_DA},
668 {ICE_INSET_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
669 {ICE_INSET_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
670 {ICE_INSET_IPV4_TOS, ICE_FLOW_FIELD_IDX_IPV4_DSCP},
671 {ICE_INSET_IPV4_TTL, ICE_FLOW_FIELD_IDX_IPV4_TTL},
672 {ICE_INSET_IPV4_PROTO, ICE_FLOW_FIELD_IDX_IPV4_PROT},
673 {ICE_INSET_IPV6_SRC, ICE_FLOW_FIELD_IDX_IPV6_SA},
674 {ICE_INSET_IPV6_DST, ICE_FLOW_FIELD_IDX_IPV6_DA},
675 {ICE_INSET_IPV6_TC, ICE_FLOW_FIELD_IDX_IPV6_DSCP},
676 {ICE_INSET_IPV6_NEXT_HDR, ICE_FLOW_FIELD_IDX_IPV6_PROT},
677 {ICE_INSET_IPV6_HOP_LIMIT, ICE_FLOW_FIELD_IDX_IPV6_TTL},
678 {ICE_INSET_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
679 {ICE_INSET_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
680 {ICE_INSET_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
681 {ICE_INSET_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
682 {ICE_INSET_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
683 {ICE_INSET_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
684 {ICE_INSET_TUN_IPV4_SRC, ICE_FLOW_FIELD_IDX_IPV4_SA},
685 {ICE_INSET_TUN_IPV4_DST, ICE_FLOW_FIELD_IDX_IPV4_DA},
686 {ICE_INSET_TUN_TCP_SRC_PORT, ICE_FLOW_FIELD_IDX_TCP_SRC_PORT},
687 {ICE_INSET_TUN_TCP_DST_PORT, ICE_FLOW_FIELD_IDX_TCP_DST_PORT},
688 {ICE_INSET_TUN_UDP_SRC_PORT, ICE_FLOW_FIELD_IDX_UDP_SRC_PORT},
689 {ICE_INSET_TUN_UDP_DST_PORT, ICE_FLOW_FIELD_IDX_UDP_DST_PORT},
690 {ICE_INSET_TUN_SCTP_SRC_PORT, ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT},
691 {ICE_INSET_TUN_SCTP_DST_PORT, ICE_FLOW_FIELD_IDX_SCTP_DST_PORT},
694 for (i = 0, j = 0; i < RTE_DIM(ice_inset_map); i++) {
695 if ((inset & ice_inset_map[i].inset) ==
696 ice_inset_map[i].inset)
697 field[j++] = ice_inset_map[i].fld;
702 ice_fdir_input_set_conf(struct ice_pf *pf, enum ice_fltr_ptype flow,
703 uint64_t input_set, bool is_tunnel)
705 struct ice_flow_seg_info *seg;
706 struct ice_flow_seg_info *seg_tun = NULL;
707 enum ice_flow_field field[ICE_FLOW_FIELD_IDX_MAX];
713 seg = (struct ice_flow_seg_info *)
714 ice_malloc(hw, sizeof(*seg));
716 PMD_DRV_LOG(ERR, "No memory can be allocated");
720 for (i = 0; i < ICE_FLOW_FIELD_IDX_MAX; i++)
721 field[i] = ICE_FLOW_FIELD_IDX_MAX;
722 ice_fdir_input_set_parse(input_set, field);
725 case ICE_FLTR_PTYPE_NONF_IPV4_UDP:
726 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
727 ICE_FLOW_SEG_HDR_IPV4);
729 case ICE_FLTR_PTYPE_NONF_IPV4_TCP:
730 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
731 ICE_FLOW_SEG_HDR_IPV4);
733 case ICE_FLTR_PTYPE_NONF_IPV4_SCTP:
734 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
735 ICE_FLOW_SEG_HDR_IPV4);
737 case ICE_FLTR_PTYPE_NONF_IPV4_OTHER:
738 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV4);
740 case ICE_FLTR_PTYPE_NONF_IPV6_UDP:
741 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_UDP |
742 ICE_FLOW_SEG_HDR_IPV6);
744 case ICE_FLTR_PTYPE_NONF_IPV6_TCP:
745 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_TCP |
746 ICE_FLOW_SEG_HDR_IPV6);
748 case ICE_FLTR_PTYPE_NONF_IPV6_SCTP:
749 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_SCTP |
750 ICE_FLOW_SEG_HDR_IPV6);
752 case ICE_FLTR_PTYPE_NONF_IPV6_OTHER:
753 ICE_FLOW_SET_HDRS(seg, ICE_FLOW_SEG_HDR_IPV6);
756 PMD_DRV_LOG(ERR, "not supported filter type.");
760 for (i = 0; field[i] != ICE_FLOW_FIELD_IDX_MAX; i++) {
761 ice_flow_set_fld(seg, field[i],
762 ICE_FLOW_FLD_OFF_INVAL,
763 ICE_FLOW_FLD_OFF_INVAL,
764 ICE_FLOW_FLD_OFF_INVAL, false);
768 ret = ice_fdir_hw_tbl_conf(pf, pf->main_vsi, pf->fdir.fdir_vsi,
771 seg_tun = (struct ice_flow_seg_info *)
772 ice_malloc(hw, sizeof(*seg) * ICE_FD_HW_SEG_MAX);
774 PMD_DRV_LOG(ERR, "No memory can be allocated");
778 rte_memcpy(&seg_tun[1], seg, sizeof(*seg));
779 ret = ice_fdir_hw_tbl_conf(pf, pf->main_vsi, pf->fdir.fdir_vsi,
780 seg_tun, flow, true);
785 } else if (ret < 0) {
789 return (ret == -EAGAIN) ? 0 : ret;
796 ice_fdir_cnt_update(struct ice_pf *pf, enum ice_fltr_ptype ptype,
797 bool is_tunnel, bool add)
799 struct ice_hw *hw = ICE_PF_TO_HW(pf);
802 cnt = (add) ? 1 : -1;
803 hw->fdir_active_fltr += cnt;
804 if (ptype == ICE_FLTR_PTYPE_NONF_NONE || ptype >= ICE_FLTR_PTYPE_MAX)
805 PMD_DRV_LOG(ERR, "Unknown filter type %d", ptype);
807 pf->fdir_fltr_cnt[ptype][is_tunnel] += cnt;
811 ice_fdir_init(struct ice_adapter *ad)
813 struct ice_pf *pf = &ad->pf;
816 ret = ice_fdir_setup(pf);
820 return ice_register_parser(&ice_fdir_parser, ad);
824 ice_fdir_uninit(struct ice_adapter *ad)
826 struct ice_pf *pf = &ad->pf;
828 ice_unregister_parser(&ice_fdir_parser, ad);
830 ice_fdir_teardown(pf);
834 ice_fdir_add_del_filter(struct ice_pf *pf,
835 struct ice_fdir_filter_conf *filter,
838 struct ice_fltr_desc desc;
839 struct ice_hw *hw = ICE_PF_TO_HW(pf);
840 unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt;
844 filter->input.dest_vsi = pf->main_vsi->idx;
846 memset(&desc, 0, sizeof(desc));
847 ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add);
849 is_tun = filter->tunnel_type ? true : false;
851 memset(pkt, 0, ICE_FDIR_PKT_LEN);
852 ret = ice_fdir_get_gen_prgm_pkt(hw, &filter->input, pkt, false, is_tun);
854 PMD_DRV_LOG(ERR, "Generate dummy packet failed");
858 return ice_fdir_programming(pf, &desc);
862 ice_fdir_extract_fltr_key(struct ice_fdir_fltr_pattern *key,
863 struct ice_fdir_filter_conf *filter)
865 struct ice_fdir_fltr *input = &filter->input;
866 memset(key, 0, sizeof(*key));
868 key->flow_type = input->flow_type;
869 rte_memcpy(&key->ip, &input->ip, sizeof(key->ip));
870 rte_memcpy(&key->mask, &input->mask, sizeof(key->mask));
871 rte_memcpy(&key->ext_data, &input->ext_data, sizeof(key->ext_data));
872 rte_memcpy(&key->ext_mask, &input->ext_mask, sizeof(key->ext_mask));
874 key->tunnel_type = filter->tunnel_type;
877 /* Check if there exists the flow director filter */
878 static struct ice_fdir_filter_conf *
879 ice_fdir_entry_lookup(struct ice_fdir_info *fdir_info,
880 const struct ice_fdir_fltr_pattern *key)
884 ret = rte_hash_lookup(fdir_info->hash_table, key);
888 return fdir_info->hash_map[ret];
891 /* Add a flow director entry into the SW list */
893 ice_fdir_entry_insert(struct ice_pf *pf,
894 struct ice_fdir_filter_conf *entry,
895 struct ice_fdir_fltr_pattern *key)
897 struct ice_fdir_info *fdir_info = &pf->fdir;
900 ret = rte_hash_add_key(fdir_info->hash_table, key);
903 "Failed to insert fdir entry to hash table %d!",
907 fdir_info->hash_map[ret] = entry;
912 /* Delete a flow director entry from the SW list */
914 ice_fdir_entry_del(struct ice_pf *pf, struct ice_fdir_fltr_pattern *key)
916 struct ice_fdir_info *fdir_info = &pf->fdir;
919 ret = rte_hash_del_key(fdir_info->hash_table, key);
922 "Failed to delete fdir filter to hash table %d!",
926 fdir_info->hash_map[ret] = NULL;
932 ice_fdir_create_filter(struct ice_adapter *ad,
933 struct rte_flow *flow,
935 struct rte_flow_error *error)
937 struct ice_pf *pf = &ad->pf;
938 struct ice_fdir_filter_conf *filter = meta;
939 struct ice_fdir_info *fdir_info = &pf->fdir;
940 struct ice_fdir_filter_conf *entry, *node;
941 struct ice_fdir_fltr_pattern key;
945 ice_fdir_extract_fltr_key(&key, filter);
946 node = ice_fdir_entry_lookup(fdir_info, &key);
948 rte_flow_error_set(error, EEXIST,
949 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
950 "Rule already exists!");
954 entry = rte_zmalloc("fdir_entry", sizeof(*entry), 0);
956 rte_flow_error_set(error, ENOMEM,
957 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
958 "Failed to allocate memory");
962 is_tun = filter->tunnel_type ? true : false;
964 ret = ice_fdir_input_set_conf(pf, filter->input.flow_type,
965 filter->input_set, is_tun);
967 rte_flow_error_set(error, -ret,
968 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
969 "Profile configure failed.");
973 /* alloc counter for FDIR */
974 if (filter->input.cnt_ena) {
975 struct rte_flow_action_count *act_count = &filter->act_count;
977 filter->counter = ice_fdir_counter_alloc(pf,
980 if (!filter->counter) {
981 rte_flow_error_set(error, EINVAL,
982 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
983 "Failed to alloc FDIR counter.");
986 filter->input.cnt_index = filter->counter->hw_index;
989 ret = ice_fdir_add_del_filter(pf, filter, true);
991 rte_flow_error_set(error, -ret,
992 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
993 "Add filter rule failed.");
997 rte_memcpy(entry, filter, sizeof(*entry));
998 ret = ice_fdir_entry_insert(pf, entry, &key);
1000 rte_flow_error_set(error, -ret,
1001 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1002 "Insert entry to table failed.");
1007 ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, true);
1012 if (filter->counter) {
1013 ice_fdir_counter_free(pf, filter->counter);
1014 filter->counter = NULL;
1023 ice_fdir_destroy_filter(struct ice_adapter *ad,
1024 struct rte_flow *flow,
1025 struct rte_flow_error *error)
1027 struct ice_pf *pf = &ad->pf;
1028 struct ice_fdir_info *fdir_info = &pf->fdir;
1029 struct ice_fdir_filter_conf *filter, *entry;
1030 struct ice_fdir_fltr_pattern key;
1034 filter = (struct ice_fdir_filter_conf *)flow->rule;
1036 is_tun = filter->tunnel_type ? true : false;
1038 if (filter->counter) {
1039 ice_fdir_counter_free(pf, filter->counter);
1040 filter->counter = NULL;
1043 ice_fdir_extract_fltr_key(&key, filter);
1044 entry = ice_fdir_entry_lookup(fdir_info, &key);
1046 rte_flow_error_set(error, ENOENT,
1047 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1048 "Can't find entry.");
1052 ret = ice_fdir_add_del_filter(pf, filter, false);
1054 rte_flow_error_set(error, -ret,
1055 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1056 "Del filter rule failed.");
1060 ret = ice_fdir_entry_del(pf, &key);
1062 rte_flow_error_set(error, -ret,
1063 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1064 "Remove entry from table failed.");
1068 ice_fdir_cnt_update(pf, filter->input.flow_type, is_tun, false);
1077 ice_fdir_query_count(struct ice_adapter *ad,
1078 struct rte_flow *flow,
1079 struct rte_flow_query_count *flow_stats,
1080 struct rte_flow_error *error)
1082 struct ice_pf *pf = &ad->pf;
1083 struct ice_hw *hw = ICE_PF_TO_HW(pf);
1084 struct ice_fdir_filter_conf *filter = flow->rule;
1085 struct ice_fdir_counter *counter = filter->counter;
1086 uint64_t hits_lo, hits_hi;
1089 rte_flow_error_set(error, EINVAL,
1090 RTE_FLOW_ERROR_TYPE_ACTION,
1092 "FDIR counters not available");
1097 * Reading the low 32-bits latches the high 32-bits into a shadow
1098 * register. Reading the high 32-bit returns the value in the
1101 hits_lo = ICE_READ_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index));
1102 hits_hi = ICE_READ_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index));
1104 flow_stats->hits_set = 1;
1105 flow_stats->hits = hits_lo | (hits_hi << 32);
1106 flow_stats->bytes_set = 0;
1107 flow_stats->bytes = 0;
1109 if (flow_stats->reset) {
1110 /* reset statistic counter value */
1111 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index), 0);
1112 ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index), 0);
1118 static struct ice_flow_engine ice_fdir_engine = {
1119 .init = ice_fdir_init,
1120 .uninit = ice_fdir_uninit,
1121 .create = ice_fdir_create_filter,
1122 .destroy = ice_fdir_destroy_filter,
1123 .query_count = ice_fdir_query_count,
1124 .type = ICE_FLOW_ENGINE_FDIR,
1128 ice_fdir_parse_action_qregion(struct ice_pf *pf,
1129 struct rte_flow_error *error,
1130 const struct rte_flow_action *act,
1131 struct ice_fdir_filter_conf *filter)
1133 const struct rte_flow_action_rss *rss = act->conf;
1136 if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
1137 rte_flow_error_set(error, EINVAL,
1138 RTE_FLOW_ERROR_TYPE_ACTION, act,
1143 if (rss->queue_num <= 1) {
1144 rte_flow_error_set(error, EINVAL,
1145 RTE_FLOW_ERROR_TYPE_ACTION, act,
1146 "Queue region size can't be 0 or 1.");
1150 /* check if queue index for queue region is continuous */
1151 for (i = 0; i < rss->queue_num - 1; i++) {
1152 if (rss->queue[i + 1] != rss->queue[i] + 1) {
1153 rte_flow_error_set(error, EINVAL,
1154 RTE_FLOW_ERROR_TYPE_ACTION, act,
1155 "Discontinuous queue region");
1160 if (rss->queue[rss->queue_num - 1] >= pf->dev_data->nb_rx_queues) {
1161 rte_flow_error_set(error, EINVAL,
1162 RTE_FLOW_ERROR_TYPE_ACTION, act,
1163 "Invalid queue region indexes.");
1167 if (!(rte_is_power_of_2(rss->queue_num) &&
1168 (rss->queue_num <= ICE_FDIR_MAX_QREGION_SIZE))) {
1169 rte_flow_error_set(error, EINVAL,
1170 RTE_FLOW_ERROR_TYPE_ACTION, act,
1171 "The region size should be any of the following values:"
1172 "1, 2, 4, 8, 16, 32, 64, 128 as long as the total number "
1173 "of queues do not exceed the VSI allocation.");
1177 filter->input.q_index = rss->queue[0];
1178 filter->input.q_region = rte_fls_u32(rss->queue_num) - 1;
1179 filter->input.dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
1185 ice_fdir_parse_action(struct ice_adapter *ad,
1186 const struct rte_flow_action actions[],
1187 struct rte_flow_error *error,
1188 struct ice_fdir_filter_conf *filter)
1190 struct ice_pf *pf = &ad->pf;
1191 const struct rte_flow_action_queue *act_q;
1192 const struct rte_flow_action_mark *mark_spec = NULL;
1193 const struct rte_flow_action_count *act_count;
1194 uint32_t dest_num = 0;
1195 uint32_t mark_num = 0;
1196 uint32_t counter_num = 0;
1199 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1200 switch (actions->type) {
1201 case RTE_FLOW_ACTION_TYPE_VOID:
1203 case RTE_FLOW_ACTION_TYPE_QUEUE:
1206 act_q = actions->conf;
1207 filter->input.q_index = act_q->index;
1208 if (filter->input.q_index >=
1209 pf->dev_data->nb_rx_queues) {
1210 rte_flow_error_set(error, EINVAL,
1211 RTE_FLOW_ERROR_TYPE_ACTION,
1213 "Invalid queue for FDIR.");
1216 filter->input.dest_ctl =
1217 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
1219 case RTE_FLOW_ACTION_TYPE_DROP:
1222 filter->input.dest_ctl =
1223 ICE_FLTR_PRGM_DESC_DEST_DROP_PKT;
1225 case RTE_FLOW_ACTION_TYPE_PASSTHRU:
1228 filter->input.dest_ctl =
1229 ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
1230 filter->input.q_index = 0;
1232 case RTE_FLOW_ACTION_TYPE_RSS:
1235 ret = ice_fdir_parse_action_qregion(pf,
1236 error, actions, filter);
1240 case RTE_FLOW_ACTION_TYPE_MARK:
1243 mark_spec = actions->conf;
1244 filter->input.fltr_id = mark_spec->id;
1246 case RTE_FLOW_ACTION_TYPE_COUNT:
1249 act_count = actions->conf;
1250 filter->input.cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
1251 rte_memcpy(&filter->act_count, act_count,
1252 sizeof(filter->act_count));
1256 rte_flow_error_set(error, EINVAL,
1257 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1263 if (dest_num == 0 || dest_num >= 2) {
1264 rte_flow_error_set(error, EINVAL,
1265 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1266 "Unsupported action combination");
1270 if (mark_num >= 2) {
1271 rte_flow_error_set(error, EINVAL,
1272 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1273 "Too many mark actions");
1277 if (counter_num >= 2) {
1278 rte_flow_error_set(error, EINVAL,
1279 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1280 "Too many count actions");
1288 ice_fdir_parse_pattern(__rte_unused struct ice_adapter *ad,
1289 const struct rte_flow_item pattern[],
1290 struct rte_flow_error *error,
1291 struct ice_fdir_filter_conf *filter)
1293 const struct rte_flow_item *item = pattern;
1294 enum rte_flow_item_type item_type;
1295 enum rte_flow_item_type l3 = RTE_FLOW_ITEM_TYPE_END;
1296 enum ice_fdir_tunnel_type tunnel_type = ICE_FDIR_TUNNEL_TYPE_NONE;
1297 const struct rte_flow_item_eth *eth_spec, *eth_mask;
1298 const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
1299 const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
1300 const struct rte_flow_item_tcp *tcp_spec, *tcp_mask;
1301 const struct rte_flow_item_udp *udp_spec, *udp_mask;
1302 const struct rte_flow_item_sctp *sctp_spec, *sctp_mask;
1303 const struct rte_flow_item_vxlan *vxlan_spec, *vxlan_mask;
1304 uint64_t input_set = ICE_INSET_NONE;
1305 uint8_t flow_type = ICE_FLTR_PTYPE_NONF_NONE;
1306 uint8_t ipv6_addr_mask[16] = {
1307 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1308 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
1310 uint32_t vtc_flow_cpu;
1313 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1315 rte_flow_error_set(error, EINVAL,
1316 RTE_FLOW_ERROR_TYPE_ITEM,
1318 "Not support range");
1321 item_type = item->type;
1323 switch (item_type) {
1324 case RTE_FLOW_ITEM_TYPE_ETH:
1325 eth_spec = item->spec;
1326 eth_mask = item->mask;
1328 if (eth_spec && eth_mask) {
1329 if (!rte_is_zero_ether_addr(ð_spec->src) ||
1330 !rte_is_zero_ether_addr(ð_mask->src)) {
1331 rte_flow_error_set(error, EINVAL,
1332 RTE_FLOW_ERROR_TYPE_ITEM,
1334 "Src mac not support");
1338 if (!rte_is_broadcast_ether_addr(ð_mask->dst)) {
1339 rte_flow_error_set(error, EINVAL,
1340 RTE_FLOW_ERROR_TYPE_ITEM,
1342 "Invalid mac addr mask");
1346 input_set |= ICE_INSET_DMAC;
1347 rte_memcpy(&filter->input.ext_data.dst_mac,
1349 RTE_ETHER_ADDR_LEN);
1352 case RTE_FLOW_ITEM_TYPE_IPV4:
1353 l3 = RTE_FLOW_ITEM_TYPE_IPV4;
1354 ipv4_spec = item->spec;
1355 ipv4_mask = item->mask;
1357 if (ipv4_spec && ipv4_mask) {
1358 /* Check IPv4 mask and update input set */
1359 if (ipv4_mask->hdr.version_ihl ||
1360 ipv4_mask->hdr.total_length ||
1361 ipv4_mask->hdr.packet_id ||
1362 ipv4_mask->hdr.fragment_offset ||
1363 ipv4_mask->hdr.hdr_checksum) {
1364 rte_flow_error_set(error, EINVAL,
1365 RTE_FLOW_ERROR_TYPE_ITEM,
1367 "Invalid IPv4 mask.");
1370 if (ipv4_mask->hdr.src_addr == UINT32_MAX)
1371 input_set |= tunnel_type ?
1372 ICE_INSET_TUN_IPV4_SRC :
1374 if (ipv4_mask->hdr.dst_addr == UINT32_MAX)
1375 input_set |= tunnel_type ?
1376 ICE_INSET_TUN_IPV4_DST :
1378 if (ipv4_mask->hdr.type_of_service == UINT8_MAX)
1379 input_set |= ICE_INSET_IPV4_TOS;
1380 if (ipv4_mask->hdr.time_to_live == UINT8_MAX)
1381 input_set |= ICE_INSET_IPV4_TTL;
1382 if (ipv4_mask->hdr.next_proto_id == UINT8_MAX)
1383 input_set |= ICE_INSET_IPV4_PROTO;
1385 filter->input.ip.v4.dst_ip =
1386 ipv4_spec->hdr.src_addr;
1387 filter->input.ip.v4.src_ip =
1388 ipv4_spec->hdr.dst_addr;
1389 filter->input.ip.v4.tos =
1390 ipv4_spec->hdr.type_of_service;
1391 filter->input.ip.v4.ttl =
1392 ipv4_spec->hdr.time_to_live;
1393 filter->input.ip.v4.proto =
1394 ipv4_spec->hdr.next_proto_id;
1397 flow_type = ICE_FLTR_PTYPE_NONF_IPV4_OTHER;
1399 case RTE_FLOW_ITEM_TYPE_IPV6:
1400 l3 = RTE_FLOW_ITEM_TYPE_IPV6;
1401 ipv6_spec = item->spec;
1402 ipv6_mask = item->mask;
1404 if (ipv6_spec && ipv6_mask) {
1405 /* Check IPv6 mask and update input set */
1406 if (ipv6_mask->hdr.payload_len) {
1407 rte_flow_error_set(error, EINVAL,
1408 RTE_FLOW_ERROR_TYPE_ITEM,
1410 "Invalid IPv6 mask");
1414 if (!memcmp(ipv6_mask->hdr.src_addr,
1416 RTE_DIM(ipv6_mask->hdr.src_addr)))
1417 input_set |= ICE_INSET_IPV6_SRC;
1418 if (!memcmp(ipv6_mask->hdr.dst_addr,
1420 RTE_DIM(ipv6_mask->hdr.dst_addr)))
1421 input_set |= ICE_INSET_IPV6_DST;
1423 if ((ipv6_mask->hdr.vtc_flow &
1424 rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
1425 == rte_cpu_to_be_32(ICE_IPV6_TC_MASK))
1426 input_set |= ICE_INSET_IPV6_TC;
1427 if (ipv6_mask->hdr.proto == UINT8_MAX)
1428 input_set |= ICE_INSET_IPV6_NEXT_HDR;
1429 if (ipv6_mask->hdr.hop_limits == UINT8_MAX)
1430 input_set |= ICE_INSET_IPV6_HOP_LIMIT;
1432 rte_memcpy(filter->input.ip.v6.dst_ip,
1433 ipv6_spec->hdr.src_addr, 16);
1434 rte_memcpy(filter->input.ip.v6.src_ip,
1435 ipv6_spec->hdr.dst_addr, 16);
1438 rte_be_to_cpu_32(ipv6_spec->hdr.vtc_flow);
1439 filter->input.ip.v6.tc =
1440 (uint8_t)(vtc_flow_cpu >>
1441 ICE_FDIR_IPV6_TC_OFFSET);
1442 filter->input.ip.v6.proto =
1443 ipv6_spec->hdr.proto;
1444 filter->input.ip.v6.hlim =
1445 ipv6_spec->hdr.hop_limits;
1448 flow_type = ICE_FLTR_PTYPE_NONF_IPV6_OTHER;
1450 case RTE_FLOW_ITEM_TYPE_TCP:
1451 tcp_spec = item->spec;
1452 tcp_mask = item->mask;
1454 if (tcp_spec && tcp_mask) {
1455 /* Check TCP mask and update input set */
1456 if (tcp_mask->hdr.sent_seq ||
1457 tcp_mask->hdr.recv_ack ||
1458 tcp_mask->hdr.data_off ||
1459 tcp_mask->hdr.tcp_flags ||
1460 tcp_mask->hdr.rx_win ||
1461 tcp_mask->hdr.cksum ||
1462 tcp_mask->hdr.tcp_urp) {
1463 rte_flow_error_set(error, EINVAL,
1464 RTE_FLOW_ERROR_TYPE_ITEM,
1466 "Invalid TCP mask");
1470 if (tcp_mask->hdr.src_port == UINT16_MAX)
1471 input_set |= tunnel_type ?
1472 ICE_INSET_TUN_TCP_SRC_PORT :
1473 ICE_INSET_TCP_SRC_PORT;
1474 if (tcp_mask->hdr.dst_port == UINT16_MAX)
1475 input_set |= tunnel_type ?
1476 ICE_INSET_TUN_TCP_DST_PORT :
1477 ICE_INSET_TCP_DST_PORT;
1479 /* Get filter info */
1480 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1481 filter->input.ip.v4.dst_port =
1482 tcp_spec->hdr.src_port;
1483 filter->input.ip.v4.src_port =
1484 tcp_spec->hdr.dst_port;
1486 ICE_FLTR_PTYPE_NONF_IPV4_TCP;
1487 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1488 filter->input.ip.v6.dst_port =
1489 tcp_spec->hdr.src_port;
1490 filter->input.ip.v6.src_port =
1491 tcp_spec->hdr.dst_port;
1493 ICE_FLTR_PTYPE_NONF_IPV6_TCP;
1497 case RTE_FLOW_ITEM_TYPE_UDP:
1498 udp_spec = item->spec;
1499 udp_mask = item->mask;
1501 if (udp_spec && udp_mask) {
1502 /* Check UDP mask and update input set*/
1503 if (udp_mask->hdr.dgram_len ||
1504 udp_mask->hdr.dgram_cksum) {
1505 rte_flow_error_set(error, EINVAL,
1506 RTE_FLOW_ERROR_TYPE_ITEM,
1508 "Invalid UDP mask");
1512 if (udp_mask->hdr.src_port == UINT16_MAX)
1513 input_set |= tunnel_type ?
1514 ICE_INSET_TUN_UDP_SRC_PORT :
1515 ICE_INSET_UDP_SRC_PORT;
1516 if (udp_mask->hdr.dst_port == UINT16_MAX)
1517 input_set |= tunnel_type ?
1518 ICE_INSET_TUN_UDP_DST_PORT :
1519 ICE_INSET_UDP_DST_PORT;
1521 /* Get filter info */
1522 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1523 filter->input.ip.v4.dst_port =
1524 udp_spec->hdr.src_port;
1525 filter->input.ip.v4.src_port =
1526 udp_spec->hdr.dst_port;
1528 ICE_FLTR_PTYPE_NONF_IPV4_UDP;
1529 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1530 filter->input.ip.v6.src_port =
1531 udp_spec->hdr.src_port;
1532 filter->input.ip.v6.dst_port =
1533 udp_spec->hdr.dst_port;
1535 ICE_FLTR_PTYPE_NONF_IPV6_UDP;
1539 case RTE_FLOW_ITEM_TYPE_SCTP:
1540 sctp_spec = item->spec;
1541 sctp_mask = item->mask;
1543 if (sctp_spec && sctp_mask) {
1544 /* Check SCTP mask and update input set */
1545 if (sctp_mask->hdr.cksum) {
1546 rte_flow_error_set(error, EINVAL,
1547 RTE_FLOW_ERROR_TYPE_ITEM,
1549 "Invalid UDP mask");
1553 if (sctp_mask->hdr.src_port == UINT16_MAX)
1554 input_set |= tunnel_type ?
1555 ICE_INSET_TUN_SCTP_SRC_PORT :
1556 ICE_INSET_SCTP_SRC_PORT;
1557 if (sctp_mask->hdr.dst_port == UINT16_MAX)
1558 input_set |= tunnel_type ?
1559 ICE_INSET_TUN_SCTP_DST_PORT :
1560 ICE_INSET_SCTP_DST_PORT;
1562 /* Get filter info */
1563 if (l3 == RTE_FLOW_ITEM_TYPE_IPV4) {
1564 filter->input.ip.v4.dst_port =
1565 sctp_spec->hdr.src_port;
1566 filter->input.ip.v4.src_port =
1567 sctp_spec->hdr.dst_port;
1569 ICE_FLTR_PTYPE_NONF_IPV4_SCTP;
1570 } else if (l3 == RTE_FLOW_ITEM_TYPE_IPV6) {
1571 filter->input.ip.v6.dst_port =
1572 sctp_spec->hdr.src_port;
1573 filter->input.ip.v6.src_port =
1574 sctp_spec->hdr.dst_port;
1576 ICE_FLTR_PTYPE_NONF_IPV6_SCTP;
1580 case RTE_FLOW_ITEM_TYPE_VOID:
1582 case RTE_FLOW_ITEM_TYPE_VXLAN:
1583 l3 = RTE_FLOW_ITEM_TYPE_END;
1584 vxlan_spec = item->spec;
1585 vxlan_mask = item->mask;
1587 if (vxlan_spec || vxlan_mask) {
1588 rte_flow_error_set(error, EINVAL,
1589 RTE_FLOW_ERROR_TYPE_ITEM,
1591 "Invalid vxlan field");
1595 tunnel_type = ICE_FDIR_TUNNEL_TYPE_VXLAN;
1598 rte_flow_error_set(error, EINVAL,
1599 RTE_FLOW_ERROR_TYPE_ITEM,
1601 "Invalid pattern item.");
1606 filter->tunnel_type = tunnel_type;
1607 filter->input.flow_type = flow_type;
1608 filter->input_set = input_set;
1614 ice_fdir_parse(struct ice_adapter *ad,
1615 struct ice_pattern_match_item *array,
1617 const struct rte_flow_item pattern[],
1618 const struct rte_flow_action actions[],
1620 struct rte_flow_error *error)
1622 struct ice_pf *pf = &ad->pf;
1623 struct ice_fdir_filter_conf *filter = &pf->fdir.conf;
1624 struct ice_pattern_match_item *item = NULL;
1628 memset(filter, 0, sizeof(*filter));
1629 item = ice_search_pattern_match_item(pattern, array, array_len, error);
1633 ret = ice_fdir_parse_pattern(ad, pattern, error, filter);
1636 input_set = filter->input_set;
1637 if (!input_set || input_set & ~item->input_set_mask) {
1638 rte_flow_error_set(error, EINVAL,
1639 RTE_FLOW_ERROR_TYPE_ITEM_SPEC,
1641 "Invalid input set");
1645 ret = ice_fdir_parse_action(ad, actions, error, filter);
1654 static struct ice_flow_parser ice_fdir_parser = {
1655 .engine = &ice_fdir_engine,
1656 .array = ice_fdir_pattern,
1657 .array_len = RTE_DIM(ice_fdir_pattern),
1658 .parse_pattern_action = ice_fdir_parse,
1659 .stage = ICE_FLOW_STAGE_DISTRIBUTOR,
1662 RTE_INIT(ice_fdir_engine_register)
1664 ice_register_flow_engine(&ice_fdir_engine);