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