1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2021 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _ULP_FLOW_DB_H_ 7 #define _ULP_FLOW_DB_H_ 8 9 #include "bnxt_ulp.h" 10 #include "ulp_template_db_enum.h" 11 #include "ulp_mapper.h" 12 13 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS 512 14 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES 8 15 16 /* Defines for the fdb flag */ 17 #define ULP_FDB_FLAG_SHARED_SESSION 0x1 18 19 /* 20 * Structure for the flow database resource information 21 * The below structure is based on the below partitions 22 * nxt_resource_idx = dir[31],resource_func_upper[30:28],nxt_resource_idx[27:0] 23 * If resource_func is EM_TBL then use resource_em_handle. 24 * Else the other part of the union is used and 25 * resource_func is resource_func_upper[30:28] << 5 | resource_func_lower 26 */ 27 struct ulp_fdb_resource_info { 28 /* Points to next resource in the chained list. */ 29 uint32_t nxt_resource_idx; 30 union { 31 uint64_t resource_em_handle; 32 struct { 33 uint8_t resource_func_lower; 34 uint8_t resource_type; 35 uint8_t resource_sub_type; 36 uint8_t fdb_flags; 37 uint32_t resource_hndl; 38 }; 39 }; 40 }; 41 42 /* Structure for the flow database resource information. */ 43 struct bnxt_ulp_flow_tbl { 44 /* Flow tbl is the resource object list for each flow id. */ 45 struct ulp_fdb_resource_info *flow_resources; 46 47 /* Flow table stack to track free list of resources. */ 48 uint32_t *flow_tbl_stack; 49 uint32_t head_index; 50 uint32_t tail_index; 51 52 /* Table to track the active flows. */ 53 uint64_t *active_reg_flows; 54 uint64_t *active_dflt_flows; 55 uint32_t num_flows; 56 uint32_t num_resources; 57 }; 58 59 /* Structure to maintain parent-child flow relationships */ 60 struct ulp_fdb_parent_info { 61 uint32_t parent_fid; 62 uint32_t counter_acc; 63 uint64_t pkt_count; 64 uint64_t byte_count; 65 uint64_t *child_fid_bitset; 66 uint32_t f2_cnt; 67 uint8_t tun_idx; 68 }; 69 70 /* Structure to maintain parent-child flow relationships */ 71 struct ulp_fdb_parent_child_db { 72 struct ulp_fdb_parent_info *parent_flow_tbl; 73 uint32_t child_bitset_size; 74 uint32_t entries_count; 75 uint8_t *parent_flow_tbl_mem; 76 }; 77 78 /* Structure for the flow database resource information. */ 79 struct bnxt_ulp_flow_db { 80 struct bnxt_ulp_flow_tbl flow_tbl; 81 uint16_t *func_id_tbl; 82 uint32_t func_id_tbl_size; 83 struct ulp_fdb_parent_child_db parent_child_db; 84 }; 85 86 /* flow db resource params to add resources */ 87 struct ulp_flow_db_res_params { 88 enum tf_dir direction; 89 enum bnxt_ulp_resource_func resource_func; 90 uint8_t resource_type; 91 uint8_t resource_sub_type; 92 uint8_t fdb_flags; 93 uint8_t critical_resource; 94 uint64_t resource_hndl; 95 }; 96 97 /* 98 * Initialize the flow database. Memory is allocated in this 99 * call and assigned to the flow database. 100 * 101 * ulp_ctxt [in] Ptr to ulp context 102 * 103 * Returns 0 on success or negative number on failure. 104 */ 105 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt); 106 107 /* 108 * Deinitialize the flow database. Memory is deallocated in 109 * this call and all flows should have been purged before this 110 * call. 111 * 112 * ulp_ctxt [in] Ptr to ulp context 113 * 114 * Returns 0 on success. 115 */ 116 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt); 117 118 /* 119 * Allocate the flow database entry 120 * 121 * ulp_ctxt [in] Ptr to ulp_context 122 * tbl_idx [in] Specify it is regular or default flow 123 * func_id [in] The function id of the device.Valid only for regular flows. 124 * fid [out] The index to the flow entry 125 * 126 * returns 0 on success and negative on failure. 127 */ 128 int32_t 129 ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt, 130 enum bnxt_ulp_fdb_type flow_type, 131 uint16_t func_id, 132 uint32_t *fid); 133 134 /* 135 * Allocate the flow database entry. 136 * The params->critical_resource has to be set to 0 to allocate a new resource. 137 * 138 * ulp_ctxt [in] Ptr to ulp_context 139 * tbl_idx [in] Specify it is regular or default flow 140 * fid [in] The index to the flow entry 141 * params [in] The contents to be copied into resource 142 * 143 * returns 0 on success and negative on failure. 144 */ 145 int32_t 146 ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt, 147 enum bnxt_ulp_fdb_type flow_type, 148 uint32_t fid, 149 struct ulp_flow_db_res_params *params); 150 151 /* 152 * Free the flow database entry. 153 * The params->critical_resource has to be set to 1 to free the first resource. 154 * 155 * ulp_ctxt [in] Ptr to ulp_context 156 * tbl_idx [in] Specify it is regular or default flow 157 * fid [in] The index to the flow entry 158 * params [in/out] The contents to be copied into params. 159 * Only the critical_resource needs to be set by the caller. 160 * 161 * Returns 0 on success and negative on failure. 162 */ 163 int32_t 164 ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt, 165 enum bnxt_ulp_fdb_type flow_type, 166 uint32_t fid, 167 struct ulp_flow_db_res_params *params); 168 169 /* 170 * Free the flow database entry 171 * 172 * ulp_ctxt [in] Ptr to ulp_context 173 * tbl_idx [in] Specify it is regular or default flow 174 * fid [in] The index to the flow entry 175 * 176 * returns 0 on success and negative on failure. 177 */ 178 int32_t 179 ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt, 180 enum bnxt_ulp_fdb_type tbl_idx, 181 uint32_t fid); 182 183 /* 184 *Get the flow database entry details 185 * 186 * ulp_ctxt [in] Ptr to ulp_context 187 * tbl_idx [in] Specify it is regular or default flow 188 * fid [in] The index to the flow entry 189 * nxt_idx [in/out] the index to the next entry 190 * params [out] The contents to be copied into params. 191 * 192 * returns 0 on success and negative on failure. 193 */ 194 int32_t 195 ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt, 196 enum bnxt_ulp_fdb_type flow_type, 197 uint32_t fid, 198 uint32_t *nxt_idx, 199 struct ulp_flow_db_res_params *params); 200 201 /* 202 * Flush all flows in the flow database. 203 * 204 * ulp_ctxt [in] Ptr to ulp context 205 * tbl_idx [in] The index to table 206 * 207 * returns 0 on success or negative number on failure 208 */ 209 int32_t 210 ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx, 211 uint32_t idx); 212 213 /* 214 * Flush all flows in the flow database that belong to a device function. 215 * 216 * ulp_ctxt [in] Ptr to ulp context 217 * tbl_idx [in] The index to table 218 * 219 * returns 0 on success or negative number on failure 220 */ 221 int32_t 222 ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx, 223 uint16_t func_id); 224 225 /* 226 * Flush all flows in the flow database that are associated with the session. 227 * 228 * ulp_ctxt [in] Ptr to ulp context 229 * 230 * returns 0 on success or negative number on failure 231 */ 232 int32_t 233 ulp_flow_db_session_flow_flush(struct bnxt_ulp_context *ulp_ctx); 234 235 /* 236 * Check that flow id matches the function id or not 237 * 238 * ulp_ctxt [in] Ptr to ulp context 239 * flow_id [in] flow id of the flow. 240 * func_id [in] The func_id to be set, for reset pass zero. 241 * 242 * returns true on success or false on failure 243 */ 244 bool 245 ulp_flow_db_validate_flow_func(struct bnxt_ulp_context *ulp_ctx, 246 uint32_t flow_id, 247 uint32_t func_id); 248 249 /* 250 * Api to get the cfa action pointer from a flow. 251 * 252 * ulp_ctxt [in] Ptr to ulp context 253 * flow_id [in] flow id 254 * cfa_action [out] The resource handle stored in the flow database 255 * 256 * returns 0 on success 257 */ 258 int32_t 259 ulp_default_flow_db_cfa_action_get(struct bnxt_ulp_context *ulp_ctx, 260 uint32_t flow_id, 261 uint16_t *cfa_action); 262 /* 263 * Allocate the entry in the parent-child database 264 * 265 * ulp_ctxt [in] Ptr to ulp_context 266 * fid [in] The flow id to the flow entry 267 * 268 * returns index on success and negative on failure. 269 */ 270 int32_t 271 ulp_flow_db_parent_flow_alloc(struct bnxt_ulp_context *ulp_ctxt, 272 uint32_t fid); 273 274 /* 275 * Free the entry in the parent-child database 276 * 277 * ulp_ctxt [in] Ptr to ulp_context 278 * fid [in] The flow id to the flow entry 279 * 280 * returns 0 on success and negative on failure. 281 */ 282 int32_t 283 ulp_flow_db_parent_flow_free(struct bnxt_ulp_context *ulp_ctxt, 284 uint32_t fid); 285 286 /* 287 * Set or reset the child flow in the parent-child database 288 * 289 * ulp_ctxt [in] Ptr to ulp_context 290 * parent_fid [in] The flow id of the parent flow entry 291 * child_fid [in] The flow id of the child flow entry 292 * set_flag [in] Use 1 for setting child, 0 to reset 293 * 294 * returns zero on success and negative on failure. 295 */ 296 int32_t 297 ulp_flow_db_parent_child_flow_set(struct bnxt_ulp_context *ulp_ctxt, 298 uint32_t parent_fid, 299 uint32_t child_fid, 300 uint32_t set_flag); 301 302 /* 303 * Get the parent index from the parent-child database 304 * 305 * ulp_ctxt [in] Ptr to ulp_context 306 * parent_fid [in] The flow id of the parent flow entry 307 * parent_idx [out] The parent index of parent flow entry 308 * 309 * returns zero on success and negative on failure. 310 */ 311 int32_t 312 ulp_flow_db_parent_flow_idx_get(struct bnxt_ulp_context *ulp_ctxt, 313 uint32_t parent_fid, 314 uint32_t *parent_idx); 315 316 /* 317 * Get the next child flow in the parent-child database 318 * 319 * ulp_ctxt [in] Ptr to ulp_context 320 * parent_fid [in] The flow id of the parent flow entry 321 * child_fid [in/out] The flow id of the child flow entry 322 * 323 * returns zero on success and negative on failure. 324 * Pass child_fid as zero for first entry. 325 */ 326 int32_t 327 ulp_flow_db_parent_child_flow_next_entry_get(struct bnxt_ulp_flow_db *flow_db, 328 uint32_t parent_idx, 329 uint32_t *child_fid); 330 331 /* 332 * Orphan the child flow entry 333 * This is called only for child flows that have 334 * BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW resource 335 * 336 * ulp_ctxt [in] Ptr to ulp_context 337 * flow_type [in] Specify it is regular or default flow 338 * fid [in] The index to the flow entry 339 * 340 * Returns 0 on success and negative on failure. 341 */ 342 int32_t 343 ulp_flow_db_child_flow_reset(struct bnxt_ulp_context *ulp_ctxt, 344 enum bnxt_ulp_fdb_type flow_type, 345 uint32_t fid); 346 347 /* 348 * Create parent flow in the parent flow tbl 349 * 350 * parms [in] Ptr to mapper params 351 * 352 * Returns 0 on success and negative on failure. 353 */ 354 int32_t 355 ulp_flow_db_parent_flow_create(struct bnxt_ulp_mapper_parms *parms); 356 357 /* 358 * Create child flow in the parent flow tbl 359 * 360 * parms [in] Ptr to mapper params 361 * 362 * Returns 0 on success and negative on failure. 363 */ 364 int32_t 365 ulp_flow_db_child_flow_create(struct bnxt_ulp_mapper_parms *parms); 366 367 /* 368 * Update the parent counters 369 * 370 * ulp_ctxt [in] Ptr to ulp_context 371 * parent_fid [in] The flow id of the parent flow entry 372 * packet_count [in] - packet count 373 * byte_count [in] - byte count 374 * 375 * returns 0 on success 376 */ 377 int32_t 378 ulp_flow_db_parent_flow_count_update(struct bnxt_ulp_context *ulp_ctxt, 379 uint32_t parent_fid, 380 uint64_t packet_count, 381 uint64_t byte_count); 382 /* 383 * Get the parent accumulation counters 384 * 385 * ulp_ctxt [in] Ptr to ulp_context 386 * parent_fid [in] The flow id of the parent flow entry 387 * packet_count [out] - packet count 388 * byte_count [out] - byte count 389 * 390 * returns 0 on success 391 */ 392 int32_t 393 ulp_flow_db_parent_flow_count_get(struct bnxt_ulp_context *ulp_ctxt, 394 uint32_t parent_fid, 395 uint64_t *packet_count, 396 uint64_t *byte_count, 397 uint8_t count_reset); 398 399 /* 400 * reset the parent accumulation counters 401 * 402 * ulp_ctxt [in] Ptr to ulp_context 403 * 404 * returns none 405 */ 406 void 407 ulp_flow_db_parent_flow_count_reset(struct bnxt_ulp_context *ulp_ctxt); 408 409 /* 410 * Set the shared bit for the flow db entry 411 * 412 * res [in] Ptr to fdb entry 413 * shared [in] shared flag 414 * 415 * returns none 416 */ 417 void ulp_flow_db_shared_session_set(struct ulp_flow_db_res_params *res, 418 enum bnxt_ulp_shared_session shared); 419 420 #endif /* _ULP_FLOW_DB_H_ */ 421