1 /* 2 * SPDX-License-Identifier: BSD-3-Clause 3 * Copyright(c) 2023 Napatech A/S 4 */ 5 6 #ifndef _FLOW_API_H_ 7 #define _FLOW_API_H_ 8 9 #include <pthread.h> 10 11 #include "ntlog.h" 12 13 #include "flow_api_engine.h" 14 #include "hw_mod_backend.h" 15 #include "stream_binary_flow_api.h" 16 17 /* 18 * Flow NIC and Eth port device management 19 */ 20 21 struct hw_mod_resource_s { 22 uint8_t *alloc_bm; /* allocation bitmap */ 23 uint32_t *ref; /* reference counter for each resource element */ 24 uint32_t resource_count;/* number of total available entries */ 25 }; 26 27 /* 28 * Device Management API 29 */ 30 int flow_delete_eth_dev(struct flow_eth_dev *eth_dev); 31 32 /** 33 * A structure used to configure the Receive Side Scaling (RSS) feature 34 * of an Ethernet port. 35 */ 36 struct nt_eth_rss_conf { 37 /** 38 * In rte_eth_dev_rss_hash_conf_get(), the *rss_key_len* should be 39 * greater than or equal to the *hash_key_size* which get from 40 * rte_eth_dev_info_get() API. And the *rss_key* should contain at least 41 * *hash_key_size* bytes. If not meet these requirements, the query 42 * result is unreliable even if the operation returns success. 43 * 44 * In rte_eth_dev_rss_hash_update() or rte_eth_dev_configure(), if 45 * *rss_key* is not NULL, the *rss_key_len* indicates the length of the 46 * *rss_key* in bytes and it should be equal to *hash_key_size*. 47 * If *rss_key* is NULL, drivers are free to use a random or a default key. 48 */ 49 uint8_t rss_key[MAX_RSS_KEY_LEN]; 50 /** 51 * Indicates the type of packets or the specific part of packets to 52 * which RSS hashing is to be applied. 53 */ 54 uint64_t rss_hf; 55 /** 56 * Hash algorithm. 57 */ 58 enum rte_eth_hash_function algorithm; 59 }; 60 61 int sprint_nt_rss_mask(char *str, uint16_t str_len, const char *prefix, uint64_t hash_mask); 62 63 struct flow_eth_dev { 64 /* NIC that owns this port device */ 65 struct flow_nic_dev *ndev; 66 /* NIC port id */ 67 uint8_t port; 68 /* App assigned port_id - may be DPDK port_id */ 69 uint32_t port_id; 70 71 /* 0th for exception */ 72 struct flow_queue_id_s rx_queue[FLOW_MAX_QUEUES + 1]; 73 74 /* VSWITCH has exceptions sent on queue 0 per design */ 75 int num_queues; 76 77 /* QSL_HSH index if RSS needed QSL v6+ */ 78 int rss_target_id; 79 80 /* The size of buffer for aged out flow list */ 81 uint32_t nb_aging_objects; 82 83 struct flow_eth_dev *next; 84 }; 85 86 enum flow_nic_hash_e { 87 HASH_ALGO_ROUND_ROBIN = 0, 88 HASH_ALGO_5TUPLE, 89 }; 90 91 /* registered NIC backends */ 92 struct flow_nic_dev { 93 uint8_t adapter_no; /* physical adapter no in the host system */ 94 uint16_t ports; /* number of in-ports addressable on this NIC */ 95 /* flow profile this NIC is initially prepared for */ 96 enum flow_eth_dev_profile flow_profile; 97 int flow_mgnt_prepared; 98 99 struct hw_mod_resource_s res[RES_COUNT];/* raw NIC resource allocation table */ 100 void *km_res_handle; 101 void *kcc_res_handle; 102 103 void *group_handle; 104 void *hw_db_handle; 105 void *id_table_handle; 106 107 uint32_t flow_unique_id_counter; 108 /* linked list of all flows created on this NIC */ 109 struct flow_handle *flow_base; 110 /* linked list of all FLM flows created on this NIC */ 111 struct flow_handle *flow_base_flm; 112 pthread_mutex_t flow_mtx; 113 114 /* NIC backend API */ 115 struct flow_api_backend_s be; 116 /* linked list of created eth-port devices on this NIC */ 117 struct flow_eth_dev *eth_base; 118 pthread_mutex_t mtx; 119 120 /* RSS hashing configuration */ 121 struct nt_eth_rss_conf rss_conf; 122 /* next NIC linked list */ 123 struct flow_nic_dev *next; 124 }; 125 126 enum flow_nic_err_msg_e { 127 ERR_SUCCESS = 0, 128 ERR_FAILED = 1, 129 ERR_MEMORY = 2, 130 ERR_OUTPUT_TOO_MANY = 3, 131 ERR_RSS_TOO_MANY_QUEUES = 4, 132 ERR_VLAN_TYPE_NOT_SUPPORTED = 5, 133 ERR_VXLAN_HEADER_NOT_ACCEPTED = 6, 134 ERR_VXLAN_POP_INVALID_RECIRC_PORT = 7, 135 ERR_VXLAN_POP_FAILED_CREATING_VTEP = 8, 136 ERR_MATCH_VLAN_TOO_MANY = 9, 137 ERR_MATCH_INVALID_IPV6_HDR = 10, 138 ERR_MATCH_TOO_MANY_TUNNEL_PORTS = 11, 139 ERR_MATCH_INVALID_OR_UNSUPPORTED_ELEM = 12, 140 ERR_MATCH_FAILED_BY_HW_LIMITS = 13, 141 ERR_MATCH_RESOURCE_EXHAUSTION = 14, 142 ERR_MATCH_FAILED_TOO_COMPLEX = 15, 143 ERR_ACTION_REPLICATION_FAILED = 16, 144 ERR_ACTION_OUTPUT_RESOURCE_EXHAUSTION = 17, 145 ERR_ACTION_TUNNEL_HEADER_PUSH_OUTPUT_LIMIT = 18, 146 ERR_ACTION_INLINE_MOD_RESOURCE_EXHAUSTION = 19, 147 ERR_ACTION_RETRANSMIT_RESOURCE_EXHAUSTION = 20, 148 ERR_ACTION_FLOW_COUNTER_EXHAUSTION = 21, 149 ERR_ACTION_INTERNAL_RESOURCE_EXHAUSTION = 22, 150 ERR_INTERNAL_QSL_COMPARE_FAILED = 23, 151 ERR_INTERNAL_CAT_FUNC_REUSE_FAILED = 24, 152 ERR_MATCH_ENTROPHY_FAILED = 25, 153 ERR_MATCH_CAM_EXHAUSTED = 26, 154 ERR_INTERNAL_VIRTUAL_PORT_CREATION_FAILED = 27, 155 ERR_ACTION_UNSUPPORTED = 28, 156 ERR_REMOVE_FLOW_FAILED = 29, 157 ERR_ACTION_NO_OUTPUT_DEFINED_USE_DEFAULT = 30, 158 ERR_ACTION_NO_OUTPUT_QUEUE_FOUND = 31, 159 ERR_MATCH_UNSUPPORTED_ETHER_TYPE = 32, 160 ERR_OUTPUT_INVALID = 33, 161 ERR_MATCH_PARTIAL_OFFLOAD_NOT_SUPPORTED = 34, 162 ERR_MATCH_CAT_CAM_EXHAUSTED = 35, 163 ERR_MATCH_KCC_KEY_CLASH = 36, 164 ERR_MATCH_CAT_CAM_FAILED = 37, 165 ERR_PARTIAL_FLOW_MARK_TOO_BIG = 38, 166 ERR_FLOW_PRIORITY_VALUE_INVALID = 39, 167 ERR_ACTION_MULTIPLE_PORT_ID_UNSUPPORTED = 40, 168 ERR_RSS_TOO_LONG_KEY = 41, 169 ERR_ACTION_AGE_UNSUPPORTED_GROUP_0 = 42, 170 ERR_MSG_NO_MSG 171 }; 172 173 void flow_nic_set_error(enum flow_nic_err_msg_e msg, struct rte_flow_error *error); 174 175 /* 176 * Resources 177 */ 178 179 extern const char *dbg_res_descr[]; 180 181 #define flow_nic_set_bit(arr, x) \ 182 do { \ 183 uint8_t *_temp_arr = (arr); \ 184 size_t _temp_x = (x); \ 185 _temp_arr[_temp_x / 8] = \ 186 (uint8_t)(_temp_arr[_temp_x / 8] | (uint8_t)(1 << (_temp_x % 8))); \ 187 } while (0) 188 189 #define flow_nic_unset_bit(arr, x) \ 190 do { \ 191 size_t _temp_x = (x); \ 192 arr[_temp_x / 8] &= (uint8_t)(~(1 << (_temp_x % 8))); \ 193 } while (0) 194 195 #define flow_nic_is_bit_set(arr, x) \ 196 ({ \ 197 size_t _temp_x = (x); \ 198 (arr[_temp_x / 8] & (uint8_t)(1 << (_temp_x % 8))); \ 199 }) 200 201 #define flow_nic_mark_resource_used(_ndev, res_type, index) \ 202 do { \ 203 struct flow_nic_dev *_temp_ndev = (_ndev); \ 204 typeof(res_type) _temp_res_type = (res_type); \ 205 size_t _temp_index = (index); \ 206 NT_LOG(DBG, FILTER, "mark resource used: %s idx %zu", \ 207 dbg_res_descr[_temp_res_type], _temp_index); \ 208 assert(flow_nic_is_bit_set(_temp_ndev->res[_temp_res_type].alloc_bm, \ 209 _temp_index) == 0); \ 210 flow_nic_set_bit(_temp_ndev->res[_temp_res_type].alloc_bm, _temp_index); \ 211 } while (0) 212 213 #define flow_nic_mark_resource_unused(_ndev, res_type, index) \ 214 do { \ 215 typeof(res_type) _temp_res_type = (res_type); \ 216 size_t _temp_index = (index); \ 217 NT_LOG(DBG, FILTER, "mark resource unused: %s idx %zu", \ 218 dbg_res_descr[_temp_res_type], _temp_index); \ 219 flow_nic_unset_bit((_ndev)->res[_temp_res_type].alloc_bm, _temp_index); \ 220 } while (0) 221 222 #define flow_nic_is_resource_used(_ndev, res_type, index) \ 223 (!!flow_nic_is_bit_set((_ndev)->res[res_type].alloc_bm, index)) 224 225 int flow_nic_alloc_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, 226 uint32_t alignment); 227 228 int flow_nic_alloc_resource_config(struct flow_nic_dev *ndev, enum res_type_e res_type, 229 unsigned int num, uint32_t alignment); 230 void flow_nic_free_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int idx); 231 232 int flow_nic_ref_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int index); 233 int flow_nic_deref_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int index); 234 235 int flow_nic_set_hasher(struct flow_nic_dev *ndev, int hsh_idx, enum flow_nic_hash_e algorithm); 236 int flow_nic_set_hasher_fields(struct flow_nic_dev *ndev, int hsh_idx, 237 struct nt_eth_rss_conf rss_conf); 238 239 int flow_get_flm_stats(struct flow_nic_dev *ndev, uint64_t *data, uint64_t size); 240 241 #endif 242