1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2019 Broadcom
6 #ifndef _ULP_FLOW_DB_H_
7 #define _ULP_FLOW_DB_H_
10 #include "ulp_template_db.h"
12 #define BNXT_FLOW_DB_DEFAULT_NUM_FLOWS 128
13 #define BNXT_FLOW_DB_DEFAULT_NUM_RESOURCES 5
15 /* Structure for the flow database resource information. */
16 struct ulp_fdb_resource_info {
17 /* Points to next resource in the chained list. */
18 uint32_t nxt_resource_idx;
20 uint64_t resource_em_handle;
22 uint32_t resource_type;
23 uint32_t resource_hndl;
28 /* Structure for the flow database resource information. */
29 struct bnxt_ulp_flow_tbl {
30 /* Flow tbl is the resource object list for each flow id. */
31 struct ulp_fdb_resource_info *flow_resources;
33 /* Flow table stack to track free list of resources. */
34 uint32_t *flow_tbl_stack;
38 /* Table to track the active flows. */
39 uint64_t *active_flow_tbl;
41 uint32_t num_resources;
44 /* Flow database supports two tables. */
45 enum bnxt_ulp_flow_db_tables {
46 BNXT_ULP_REGULAR_FLOW_TABLE,
47 BNXT_ULP_DEFAULT_FLOW_TABLE,
48 BNXT_ULP_FLOW_TABLE_MAX
51 /* Structure for the flow database resource information. */
52 struct bnxt_ulp_flow_db {
53 struct bnxt_ulp_flow_tbl flow_tbl[BNXT_ULP_FLOW_TABLE_MAX];
56 /* flow db resource params to add resources */
57 struct ulp_flow_db_res_params {
58 enum tf_dir direction;
59 enum bnxt_ulp_resource_func resource_func;
60 uint64_t resource_hndl;
61 uint32_t resource_type;
62 uint32_t critical_resource;
66 * Initialize the flow database. Memory is allocated in this
67 * call and assigned to the flow database.
69 * ulp_ctxt [in] Ptr to ulp context
71 * Returns 0 on success or negative number on failure.
73 int32_t ulp_flow_db_init(struct bnxt_ulp_context *ulp_ctxt);
76 * Deinitialize the flow database. Memory is deallocated in
77 * this call and all flows should have been purged before this
80 * ulp_ctxt [in] Ptr to ulp context
82 * Returns 0 on success.
84 int32_t ulp_flow_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
87 * Allocate the flow database entry
89 * ulp_ctxt [in] Ptr to ulp_context
90 * tbl_idx [in] Specify it is regular or default flow
91 * fid [out] The index to the flow entry
93 * returns 0 on success and negative on failure.
95 int32_t ulp_flow_db_fid_alloc(struct bnxt_ulp_context *ulp_ctxt,
96 enum bnxt_ulp_flow_db_tables tbl_idx,
100 * Allocate the flow database entry.
101 * The params->critical_resource has to be set to 0 to allocate a new resource.
103 * ulp_ctxt [in] Ptr to ulp_context
104 * tbl_idx [in] Specify it is regular or default flow
105 * fid [in] The index to the flow entry
106 * params [in] The contents to be copied into resource
108 * returns 0 on success and negative on failure.
110 int32_t ulp_flow_db_resource_add(struct bnxt_ulp_context *ulp_ctxt,
111 enum bnxt_ulp_flow_db_tables tbl_idx,
113 struct ulp_flow_db_res_params *params);
116 * Free the flow database entry.
117 * The params->critical_resource has to be set to 1 to free the first resource.
119 * ulp_ctxt [in] Ptr to ulp_context
120 * tbl_idx [in] Specify it is regular or default flow
121 * fid [in] The index to the flow entry
122 * params [in/out] The contents to be copied into params.
123 * Only the critical_resource needs to be set by the caller.
125 * Returns 0 on success and negative on failure.
127 int32_t ulp_flow_db_resource_del(struct bnxt_ulp_context *ulp_ctxt,
128 enum bnxt_ulp_flow_db_tables tbl_idx,
130 struct ulp_flow_db_res_params *params);
133 * Free the flow database entry
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
139 * returns 0 on success and negative on failure.
141 int32_t ulp_flow_db_fid_free(struct bnxt_ulp_context *ulp_ctxt,
142 enum bnxt_ulp_flow_db_tables tbl_idx,
146 *Get the flow database entry details
148 * ulp_ctxt [in] Ptr to ulp_context
149 * tbl_idx [in] Specify it is regular or default flow
150 * fid [in] The index to the flow entry
151 * nxt_idx [in/out] the index to the next entry
152 * params [out] The contents to be copied into params.
154 * returns 0 on success and negative on failure.
156 int32_t ulp_flow_db_resource_get(struct bnxt_ulp_context *ulp_ctxt,
157 enum bnxt_ulp_flow_db_tables tbl_idx,
160 struct ulp_flow_db_res_params *params);
163 * Flush all flows in the flow database.
165 * ulp_ctxt [in] Ptr to ulp context
166 * tbl_idx [in] The index to table
168 * returns 0 on success or negative number on failure
170 int32_t ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
173 #endif /* _ULP_FLOW_DB_H_ */