1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2021 Xilinx, Inc. 4 */ 5 6 #ifndef _SFC_FLOW_TUNNEL_H 7 #define _SFC_FLOW_TUNNEL_H 8 9 #include <limits.h> 10 #include <stdbool.h> 11 #include <stdint.h> 12 13 #include <rte_flow.h> 14 15 #include "efx.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** Flow Tunnel (FT) SW entry ID */ 22 typedef uint8_t sfc_ft_id_t; 23 24 #define SFC_FT_TUNNEL_MARK_BITS \ 25 (sizeof(sfc_ft_id_t) * CHAR_BIT) 26 27 #define SFC_FT_USER_MARK_BITS \ 28 (sizeof(uint32_t) * CHAR_BIT - SFC_FT_TUNNEL_MARK_BITS) 29 30 #define SFC_FT_USER_MARK_MASK \ 31 RTE_LEN2MASK(SFC_FT_USER_MARK_BITS, uint32_t) 32 33 #define SFC_FT_GET_TUNNEL_MARK(_mark) \ 34 ((_mark) >> SFC_FT_USER_MARK_BITS) 35 36 #define SFC_FT_TUNNEL_MARK_INVALID (0) 37 38 #define SFC_FT_TUNNEL_MARK_TO_ID(_tunnel_mark) \ 39 ((_tunnel_mark) - 1) 40 41 #define SFC_FT_ID_TO_TUNNEL_MARK(_id) \ 42 ((_id) + 1) 43 44 #define SFC_FT_ID_TO_MARK(_id) \ 45 (SFC_FT_ID_TO_TUNNEL_MARK(_id) << SFC_FT_USER_MARK_BITS) 46 47 #define SFC_FT_GET_USER_MARK(_mark) \ 48 ((_mark) & SFC_FT_USER_MARK_MASK) 49 50 #define SFC_FT_MAX_NTUNNELS \ 51 (RTE_LEN2MASK(SFC_FT_TUNNEL_MARK_BITS, uint8_t) - 1) 52 53 struct sfc_flow_tunnel { 54 bool jump_rule_is_set; 55 efx_tunnel_protocol_t encap_type; 56 struct rte_flow_tunnel rte_tunnel; 57 unsigned int refcnt; 58 sfc_ft_id_t id; 59 60 struct rte_flow_action_mark action_mark; 61 struct rte_flow_action action; 62 63 struct rte_flow_item_mark item_mark_v; 64 struct rte_flow_item_mark item_mark_m; 65 struct rte_flow_item item; 66 67 uint64_t reset_jump_hit_counter; 68 uint64_t group_hit_counter; 69 }; 70 71 struct sfc_adapter; 72 73 bool sfc_flow_tunnel_is_supported(struct sfc_adapter *sa); 74 75 bool sfc_flow_tunnel_is_active(struct sfc_adapter *sa); 76 77 struct sfc_flow_tunnel *sfc_flow_tunnel_pick(struct sfc_adapter *sa, 78 uint32_t ft_mark); 79 80 int sfc_flow_tunnel_detect_jump_rule(struct sfc_adapter *sa, 81 const struct rte_flow_action *actions, 82 struct sfc_flow_spec_mae *spec, 83 struct rte_flow_error *error); 84 85 int sfc_flow_tunnel_decap_set(struct rte_eth_dev *dev, 86 struct rte_flow_tunnel *tunnel, 87 struct rte_flow_action **pmd_actions, 88 uint32_t *num_of_actions, 89 struct rte_flow_error *err); 90 91 int sfc_flow_tunnel_match(struct rte_eth_dev *dev, 92 struct rte_flow_tunnel *tunnel, 93 struct rte_flow_item **pmd_items, 94 uint32_t *num_of_items, 95 struct rte_flow_error *err); 96 97 int sfc_flow_tunnel_item_release(struct rte_eth_dev *dev, 98 struct rte_flow_item *pmd_items, 99 uint32_t num_items, 100 struct rte_flow_error *err); 101 102 int sfc_flow_tunnel_action_decap_release(struct rte_eth_dev *dev, 103 struct rte_flow_action *pmd_actions, 104 uint32_t num_actions, 105 struct rte_flow_error *err); 106 107 int sfc_flow_tunnel_get_restore_info(struct rte_eth_dev *dev, 108 struct rte_mbuf *m, 109 struct rte_flow_restore_info *info, 110 struct rte_flow_error *err); 111 112 void sfc_flow_tunnel_reset_hit_counters(struct sfc_adapter *sa); 113 114 #ifdef __cplusplus 115 } 116 #endif 117 #endif /* _SFC_FLOW_TUNNEL_H */ 118