xref: /dpdk/drivers/net/bnxt/tf_core/tf_em.h (revision aa49b38fa7c350da251b70f455224ae8e3f79d0b)
169c410b8SPete Spreadborough /* SPDX-License-Identifier: BSD-3-Clause
2e6e8f03eSRandy Schacher  * Copyright(c) 2019-2023 Broadcom
369c410b8SPete Spreadborough  * All rights reserved.
469c410b8SPete Spreadborough  */
569c410b8SPete Spreadborough 
669c410b8SPete Spreadborough #ifndef _TF_EM_H_
769c410b8SPete Spreadborough #define _TF_EM_H_
869c410b8SPete Spreadborough 
969c410b8SPete Spreadborough #include "tf_core.h"
1069c410b8SPete Spreadborough #include "tf_session.h"
1108e1af1aSFarah Smith #include "tf_em_common.h"
1208e1af1aSFarah Smith 
1308e1af1aSFarah Smith #include "hcapi_cfa_defs.h"
1477805a17SRandy Schacher 
15b56a8975SPeter Spreadborough #define TF_P4_HW_EM_KEY_MAX_SIZE 52
16b56a8975SPeter Spreadborough #define TF_P4_EM_KEY_RECORD_SIZE 64
17b56a8975SPeter Spreadborough 
18b56a8975SPeter Spreadborough #define TF_P58_HW_EM_KEY_MAX_SIZE 80
1969c410b8SPete Spreadborough 
20ae2ebb98SPeter Spreadborough /*
21ae2ebb98SPeter Spreadborough  * Used to build GFID:
22ae2ebb98SPeter Spreadborough  *
23ae2ebb98SPeter Spreadborough  *   15           2  0
24ae2ebb98SPeter Spreadborough  *  +--------------+--+
25ae2ebb98SPeter Spreadborough  *  |   Index      |E |
26ae2ebb98SPeter Spreadborough  *  +--------------+--+
27ae2ebb98SPeter Spreadborough  *
281993b267SShahaji Bhosle  * E = Entry (bucket index)
29ae2ebb98SPeter Spreadborough  */
30ae2ebb98SPeter Spreadborough #define TF_EM_INTERNAL_INDEX_SHIFT 2
31ae2ebb98SPeter Spreadborough #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
32ae2ebb98SPeter Spreadborough #define TF_EM_INTERNAL_ENTRY_MASK  0x3
33ae2ebb98SPeter Spreadborough 
34ae2ebb98SPeter Spreadborough 
35ca5e61bdSPeter Spreadborough /** EEM Memory Type
36ca5e61bdSPeter Spreadborough  *
37ca5e61bdSPeter Spreadborough  */
38ca5e61bdSPeter Spreadborough enum tf_mem_type {
39ca5e61bdSPeter Spreadborough 	TF_EEM_MEM_TYPE_INVALID,
40ca5e61bdSPeter Spreadborough 	TF_EEM_MEM_TYPE_HOST,
41ca5e61bdSPeter Spreadborough 	TF_EEM_MEM_TYPE_SYSTEM
42ca5e61bdSPeter Spreadborough };
43ca5e61bdSPeter Spreadborough 
44ca5e61bdSPeter Spreadborough /**
45ca5e61bdSPeter Spreadborough  * tf_em_cfg_parms definition
46ca5e61bdSPeter Spreadborough  */
47ca5e61bdSPeter Spreadborough struct tf_em_cfg_parms {
48ca5e61bdSPeter Spreadborough 	/**
49ca5e61bdSPeter Spreadborough 	 * [in] Num entries in resource config
50ca5e61bdSPeter Spreadborough 	 */
51ca5e61bdSPeter Spreadborough 	uint16_t num_elements;
52ca5e61bdSPeter Spreadborough 	/**
53ca5e61bdSPeter Spreadborough 	 * [in] Resource config
54ca5e61bdSPeter Spreadborough 	 */
55ca5e61bdSPeter Spreadborough 	struct tf_rm_element_cfg *cfg;
56ca5e61bdSPeter Spreadborough 	/**
57ca5e61bdSPeter Spreadborough 	 * Session resource allocations
58ca5e61bdSPeter Spreadborough 	 */
59ca5e61bdSPeter Spreadborough 	struct tf_session_resources *resources;
60ca5e61bdSPeter Spreadborough 	/**
61ca5e61bdSPeter Spreadborough 	 * [in] Memory type.
62ca5e61bdSPeter Spreadborough 	 */
63ca5e61bdSPeter Spreadborough 	enum tf_mem_type mem_type;
64ca5e61bdSPeter Spreadborough };
65ca5e61bdSPeter Spreadborough 
66*aa49b38fSShuanglin Wang /** EM Entry
67*aa49b38fSShuanglin Wang  *  Each EM entry is 512-bit (64-bytes) but ordered differently to
68*aa49b38fSShuanglin Wang  *  EEM.
69*aa49b38fSShuanglin Wang  */
70*aa49b38fSShuanglin Wang struct tf_em_64b_entry {
71*aa49b38fSShuanglin Wang 	/** Header is 8 bytes long */
72*aa49b38fSShuanglin Wang 	struct cfa_p4_eem_entry_hdr hdr;
73*aa49b38fSShuanglin Wang 	/** Key is 448 bits - 56 bytes */
74*aa49b38fSShuanglin Wang 	uint8_t key[TF_P4_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
75*aa49b38fSShuanglin Wang };
76*aa49b38fSShuanglin Wang 
77ca5e61bdSPeter Spreadborough /**
7838dc96f9SJay Ding  * EM database
7938dc96f9SJay Ding  *
8038dc96f9SJay Ding  * EM rm database
8138dc96f9SJay Ding  *
8238dc96f9SJay Ding  */
8338dc96f9SJay Ding struct em_rm_db {
8438dc96f9SJay Ding 	struct rm_db *em_db[TF_DIR_MAX];
8538dc96f9SJay Ding };
8638dc96f9SJay Ding 
8738dc96f9SJay Ding /**
88ced3cdedSMichael Wildt  * @page em EM
89ca5e61bdSPeter Spreadborough  *
90ca5e61bdSPeter Spreadborough  * @ref tf_alloc_eem_tbl_scope
91ca5e61bdSPeter Spreadborough  *
92ca5e61bdSPeter Spreadborough  * @ref tf_free_eem_tbl_scope_cb
93ca5e61bdSPeter Spreadborough  *
94ced3cdedSMichael Wildt  * @ref tf_em_insert_int_entry
95ced3cdedSMichael Wildt  *
96ced3cdedSMichael Wildt  * @ref tf_em_delete_int_entry
97ced3cdedSMichael Wildt  *
98*aa49b38fSShuanglin Wang  * @ref tf_em_insert_ext_entry DEFUNCT
99ced3cdedSMichael Wildt  *
100*aa49b38fSShuanglin Wang  * @ref tf_em_delete_ext_entry DEFUNCT
101ced3cdedSMichael Wildt  *
102*aa49b38fSShuanglin Wang  * @ref tf_em_insert_ext_sys_entry DEFUNCT
103ced3cdedSMichael Wildt  *
104*aa49b38fSShuanglin Wang  * @ref tf_em_delete_ext_sys_entry DEFUNCT
105ced3cdedSMichael Wildt  *
106ced3cdedSMichael Wildt  * @ref tf_em_int_bind
107ced3cdedSMichael Wildt  *
108ced3cdedSMichael Wildt  * @ref tf_em_int_unbind
109ced3cdedSMichael Wildt  *
110*aa49b38fSShuanglin Wang  * @ref tf_em_ext_common_bind DEFUNCT
111ced3cdedSMichael Wildt  *
112*aa49b38fSShuanglin Wang  * @ref tf_em_ext_common_unbind DEFUNCT
113ced3cdedSMichael Wildt  *
114*aa49b38fSShuanglin Wang  * @ref tf_em_ext_host_alloc DEFUNCT
115ced3cdedSMichael Wildt  *
116*aa49b38fSShuanglin Wang  * @ref tf_em_ext_host_free DEFUNCT
117ced3cdedSMichael Wildt  *
118*aa49b38fSShuanglin Wang  * @ref tf_em_ext_system_alloc DEFUNCT
119ced3cdedSMichael Wildt  *
120*aa49b38fSShuanglin Wang  * @ref tf_em_ext_system_free DEFUNCT
121*aa49b38fSShuanglin Wang  *
122*aa49b38fSShuanglin Wang  * @ref tf_em_ext_common_free DEFUNCT
123*aa49b38fSShuanglin Wang  *
124*aa49b38fSShuanglin Wang  * @ref tf_em_ext_common_alloc DEFUNCT
125ca5e61bdSPeter Spreadborough  */
126ca5e61bdSPeter Spreadborough 
12769c410b8SPete Spreadborough /**
128ca5e61bdSPeter Spreadborough  * Insert record in to internal EM table
12969c410b8SPete Spreadborough  *
130ca5e61bdSPeter Spreadborough  * [in] tfp
131ca5e61bdSPeter Spreadborough  *   Pointer to TruFlow handle
132ca5e61bdSPeter Spreadborough  *
133ca5e61bdSPeter Spreadborough  * [in] parms
134ca5e61bdSPeter Spreadborough  *   Pointer to input parameters
13569c410b8SPete Spreadborough  *
13669c410b8SPete Spreadborough  * Returns:
137ca5e61bdSPeter Spreadborough  *   0       - Success
138ca5e61bdSPeter Spreadborough  *   -EINVAL - Parameter error
13969c410b8SPete Spreadborough  */
140ca5e61bdSPeter Spreadborough int tf_em_insert_int_entry(struct tf *tfp,
14177805a17SRandy Schacher 			   struct tf_insert_em_entry_parms *parms);
14277805a17SRandy Schacher 
143ca5e61bdSPeter Spreadborough /**
144ca5e61bdSPeter Spreadborough  * Delete record from internal EM table
145ca5e61bdSPeter Spreadborough  *
146ca5e61bdSPeter Spreadborough  * [in] tfp
147ca5e61bdSPeter Spreadborough  *   Pointer to TruFlow handle
148ca5e61bdSPeter Spreadborough  *
149ca5e61bdSPeter Spreadborough  * [in] parms
150ca5e61bdSPeter Spreadborough  *   Pointer to input parameters
151ca5e61bdSPeter Spreadborough  *
152ca5e61bdSPeter Spreadborough  * Returns:
153ca5e61bdSPeter Spreadborough  *   0       - Success
154ca5e61bdSPeter Spreadborough  *   -EINVAL - Parameter error
155ca5e61bdSPeter Spreadborough  */
156ca5e61bdSPeter Spreadborough int tf_em_delete_int_entry(struct tf *tfp,
15777805a17SRandy Schacher 			   struct tf_delete_em_entry_parms *parms);
158ca5e61bdSPeter Spreadborough 
159ca5e61bdSPeter Spreadborough /**
160539931eaSPeter Spreadborough  * Insert record in to internal EM table
161539931eaSPeter Spreadborough  *
162539931eaSPeter Spreadborough  * [in] tfp
163539931eaSPeter Spreadborough  *   Pointer to TruFlow handle
164539931eaSPeter Spreadborough  *
165539931eaSPeter Spreadborough  * [in] parms
166539931eaSPeter Spreadborough  *   Pointer to input parameters
167539931eaSPeter Spreadborough  *
168539931eaSPeter Spreadborough  * Returns:
169539931eaSPeter Spreadborough  *   0       - Success
170539931eaSPeter Spreadborough  *   -EINVAL - Parameter error
171539931eaSPeter Spreadborough  */
172539931eaSPeter Spreadborough int tf_em_hash_insert_int_entry(struct tf *tfp,
173539931eaSPeter Spreadborough 				struct tf_insert_em_entry_parms *parms);
174539931eaSPeter Spreadborough 
175539931eaSPeter Spreadborough /**
176539931eaSPeter Spreadborough  * Delete record from internal EM table
177539931eaSPeter Spreadborough  *
178539931eaSPeter Spreadborough  * [in] tfp
179539931eaSPeter Spreadborough  *   Pointer to TruFlow handle
180539931eaSPeter Spreadborough  *
181539931eaSPeter Spreadborough  * [in] parms
182539931eaSPeter Spreadborough  *   Pointer to input parameters
183539931eaSPeter Spreadborough  *
184539931eaSPeter Spreadborough  * Returns:
185539931eaSPeter Spreadborough  *   0       - Success
186539931eaSPeter Spreadborough  *   -EINVAL - Parameter error
187539931eaSPeter Spreadborough  */
188539931eaSPeter Spreadborough int tf_em_hash_delete_int_entry(struct tf *tfp,
189539931eaSPeter Spreadborough 				struct tf_delete_em_entry_parms *parms);
190539931eaSPeter Spreadborough 
191539931eaSPeter Spreadborough /**
19205b405d5SPeter Spreadborough  * Move record from internal EM table
19305b405d5SPeter Spreadborough  *
19405b405d5SPeter Spreadborough  * [in] tfp
19505b405d5SPeter Spreadborough  *   Pointer to TruFlow handle
19605b405d5SPeter Spreadborough  *
19705b405d5SPeter Spreadborough  * [in] parms
19805b405d5SPeter Spreadborough  *   Pointer to input parameters
19905b405d5SPeter Spreadborough  *
20005b405d5SPeter Spreadborough  * Returns:
20105b405d5SPeter Spreadborough  *   0       - Success
20205b405d5SPeter Spreadborough  *   -EINVAL - Parameter error
20305b405d5SPeter Spreadborough  */
20405b405d5SPeter Spreadborough int tf_em_move_int_entry(struct tf *tfp,
20505b405d5SPeter Spreadborough 			 struct tf_move_em_entry_parms *parms);
20605b405d5SPeter Spreadborough 
20705b405d5SPeter Spreadborough /**
208ca5e61bdSPeter Spreadborough  * Bind internal EM device interface
209ca5e61bdSPeter Spreadborough  *
210ca5e61bdSPeter Spreadborough  * [in] tfp
211ca5e61bdSPeter Spreadborough  *   Pointer to TruFlow handle
212ca5e61bdSPeter Spreadborough  *
213ca5e61bdSPeter Spreadborough  * [in] parms
214ca5e61bdSPeter Spreadborough  *   Pointer to input parameters
215ca5e61bdSPeter Spreadborough  *
216ca5e61bdSPeter Spreadborough  * Returns:
217ca5e61bdSPeter Spreadborough  *   0       - Success
218ca5e61bdSPeter Spreadborough  *   -EINVAL - Parameter error
219ca5e61bdSPeter Spreadborough  */
220ca5e61bdSPeter Spreadborough int tf_em_int_bind(struct tf *tfp,
221ca5e61bdSPeter Spreadborough 		   struct tf_em_cfg_parms *parms);
222ca5e61bdSPeter Spreadborough 
223ca5e61bdSPeter Spreadborough /**
224ca5e61bdSPeter Spreadborough  * Unbind internal EM device interface
225ca5e61bdSPeter Spreadborough  *
226ca5e61bdSPeter Spreadborough  * [in] tfp
227ca5e61bdSPeter Spreadborough  *   Pointer to TruFlow handle
228ca5e61bdSPeter Spreadborough  *
229ca5e61bdSPeter Spreadborough  * [in] parms
230ca5e61bdSPeter Spreadborough  *   Pointer to input parameters
231ca5e61bdSPeter Spreadborough  *
232ca5e61bdSPeter Spreadborough  * Returns:
233ca5e61bdSPeter Spreadborough  *   0       - Success
234ca5e61bdSPeter Spreadborough  *   -EINVAL - Parameter error
235ca5e61bdSPeter Spreadborough  */
236ca5e61bdSPeter Spreadborough int tf_em_int_unbind(struct tf *tfp);
237ca5e61bdSPeter Spreadborough 
238ca5e61bdSPeter Spreadborough /**
239873661aaSJay Ding  * Retrieves the allocated resource info
240873661aaSJay Ding  *
241873661aaSJay Ding  * [in] tfp
242873661aaSJay Ding  *   Pointer to TF handle, used for HCAPI communication
243873661aaSJay Ding  *
244873661aaSJay Ding  * [in] parms
245873661aaSJay Ding  *   Pointer to parameters
246873661aaSJay Ding  *
247873661aaSJay Ding  * Returns
248873661aaSJay Ding  *   - (0) if successful.
249873661aaSJay Ding  *   - (-EINVAL) on failure.
250873661aaSJay Ding  */
251873661aaSJay Ding int
252873661aaSJay Ding tf_em_get_resc_info(struct tf *tfp,
253873661aaSJay Ding 		    struct tf_em_resource_info *em);
25469c410b8SPete Spreadborough #endif /* _TF_EM_H_ */
255