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