xref: /dpdk/drivers/net/bnxt/tf_core/tf_em_common.h (revision aa49b38fa7c350da251b70f455224ae8e3f79d0b)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2023 Broadcom
3  * All rights reserved.
4  */
5 
6 #ifndef _TF_EM_COMMON_H_
7 #define _TF_EM_COMMON_H_
8 
9 #include "hcapi_cfa_defs.h"
10 #include "tf_core.h"
11 #include "tf_session.h"
12 #include "ll.h"
13 
14 /**
15  * Function to search for table scope control block structure
16  * with specified table scope ID.
17  *
18  * [in] tbl_scope_id
19  *   Table scope ID to search for
20  *
21  * Returns:
22  *  Pointer to the found table scope control block struct or NULL if
23  *   table scope control block struct not found
24  */
25 struct tf_tbl_scope_cb *tbl_scope_cb_find(uint32_t tbl_scope_id);
26 
27 /**
28  * Table scope control block content
29  */
30 struct tf_em_caps {
31 	uint32_t flags;
32 	uint32_t supported;
33 	uint32_t max_entries_supported;
34 	uint16_t key_entry_size;
35 	uint16_t record_entry_size;
36 	uint16_t efc_entry_size;
37 };
38 
39 /**
40  *  EEM data
41  *
42  *  Link list of ext em data allocated and managed by EEM module
43  *  for a TruFlow session.
44  */
45 struct em_ext_db {
46 	struct ll tbl_scope_ll;
47 	struct rm_db *eem_db[TF_DIR_MAX];
48 };
49 
50 /**
51  * Table Scope Control Block
52  *
53  * Holds private data for a table scope.
54  */
55 struct tf_tbl_scope_cb {
56 	/**
57 	 * Linked list of tbl_scope
58 	 */
59 	struct ll_entry ll_entry; /* For inserting in link list, must be
60 				   * first field of struct.
61 				   */
62 
63 	uint32_t tbl_scope_id;
64 
65        /** The pf or parent pf of the vf used for table scope creation
66 	*/
67 	uint16_t pf;
68 	struct hcapi_cfa_em_ctx_mem_info em_ctx_info[TF_DIR_MAX];
69 	struct tf_em_caps em_caps[TF_DIR_MAX];
70 	struct stack ext_act_pool[TF_DIR_MAX];
71 	uint32_t *ext_act_pool_mem[TF_DIR_MAX];
72 };
73 
74 /**
75  * Create and initialize a stack to use for action entries
76  *
77  * [in] dir
78  *   Direction
79  * [in] tbl_scope_id
80  *   Table scope ID
81  * [in] num_entries
82  *   Number of EEM entries
83  * [in] entry_sz_bytes
84  *   Size of the entry
85  *
86  * Returns:
87  *   0       - Success
88  *   -ENOMEM - Out of memory
89  *   -EINVAL - Failure
90  */
91 int tf_create_tbl_pool_external(enum tf_dir dir,
92 				struct tf_tbl_scope_cb *tbl_scope_cb,
93 				uint32_t num_entries,
94 				uint32_t entry_sz_bytes);
95 
96 /**
97  * Delete and cleanup action record allocation stack
98  *
99  * [in] dir
100  *   Direction
101  * [in] tbl_scope_id
102  *   Table scope ID
103  *
104  */
105 void tf_destroy_tbl_pool_external(enum tf_dir dir,
106 				  struct tf_tbl_scope_cb *tbl_scope_cb);
107 
108 /**
109  * Get hash mask for current EEM table size
110  *
111  * [in] num_entries
112  *   Number of EEM entries
113  */
114 uint32_t tf_em_get_key_mask(int num_entries);
115 
116 /**
117  * Populate key_entry
118  *
119  * [in] result
120  *   Entry data
121  * [in] in_key
122  *   Key data
123  * [out] key_entry
124  *   Completed key record
125  */
126 void tf_em_create_key_entry(struct cfa_p4_eem_entry_hdr *result,
127 			    uint8_t	       *in_key,
128 			    struct cfa_p4_eem_64b_entry *key_entry);
129 
130 /**
131  * Find base page address for offset into specified table type
132  *
133  * [in] tbl_scope_cb
134  *   Table scope
135  * [in] dir
136  *   Direction
137  * [in] Offset
138  *   Offset in to table
139  * [in] table_type
140  *   Table type
141  *
142  * Returns:
143  *
144  * 0                                 - Failure
145  * Void pointer to page base address - Success
146  */
147 void *tf_em_get_table_page(struct tf_tbl_scope_cb *tbl_scope_cb,
148 			   enum tf_dir dir,
149 			   uint32_t offset,
150 			   enum hcapi_cfa_em_table_type table_type);
151 
152 /**
153  * Validates EM number of entries requested
154  *
155  * [in] tbl_scope_cb
156  *   Pointer to table scope control block to be populated
157  *
158  * [in] parms
159  *   Pointer to input parameters
160  *
161  * Returns:
162  *   0       - Success
163  *   -EINVAL - Parameter error
164  */
165 int tf_em_validate_num_entries(struct tf_tbl_scope_cb *tbl_scope_cb,
166 			       struct tf_alloc_tbl_scope_parms *parms);
167 
168 /**
169  * Size the EM table based on capabilities
170  *
171  * [in] tbl
172  *   EM table to size
173  *
174  * Returns:
175  *   0        - Success
176  *   - EINVAL - Parameter error
177  *   - ENOMEM - Out of memory
178  */
179 int tf_em_size_table(struct hcapi_cfa_em_table *tbl,
180 		     uint32_t page_size);
181 
182 /**
183  * Look up table scope control block using tbl_scope_id from
184  * tf_session
185  *
186  * [in] tbl_scope_cb
187  *   Pointer to Truflow Handle
188  *
189  * [in] tbl_scope_id
190  *   table scope id
191  *
192  * Returns:
193  *   - Pointer to the tf_tbl_scope_cb, if found.
194  *   - (NULL) on failure, not found.
195  */
196 struct tf_tbl_scope_cb *
197 tf_em_ext_common_tbl_scope_find(struct tf *tfp,
198 				uint32_t tbl_scope_id);
199 #endif /* _TF_EM_COMMON_H_ */
200