6bfcbd59e5e84e2c6802606899e9cde9d8291671
[dpdk.git] / drivers / net / bnxt / tf_core / tf_em.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_EM_H_
7 #define _TF_EM_H_
8
9 #include "tf_core.h"
10 #include "tf_session.h"
11
12 #define TF_HACK_TBL_SCOPE_BASE 68
13 #define SUPPORT_CFA_HW_P4 1
14 #define SUPPORT_CFA_HW_P58 0
15 #define SUPPORT_CFA_HW_P59 0
16 #define SUPPORT_CFA_HW_ALL 0
17
18 #include "hcapi/hcapi_cfa_defs.h"
19
20 #define TF_HW_EM_KEY_MAX_SIZE 52
21 #define TF_EM_KEY_RECORD_SIZE 64
22
23 #define TF_EM_MAX_MASK 0x7FFF
24 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
25
26 /**
27  * Hardware Page sizes supported for EEM:
28  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
29  *
30  * Round-down other page sizes to the lower hardware page
31  * size supported.
32  */
33 #define TF_EM_PAGE_SIZE_4K 12
34 #define TF_EM_PAGE_SIZE_8K 13
35 #define TF_EM_PAGE_SIZE_64K 16
36 #define TF_EM_PAGE_SIZE_256K 18
37 #define TF_EM_PAGE_SIZE_1M 20
38 #define TF_EM_PAGE_SIZE_2M 21
39 #define TF_EM_PAGE_SIZE_4M 22
40 #define TF_EM_PAGE_SIZE_1G 30
41
42 /* Set page size */
43 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
44
45 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
46 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
47 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
48 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
49 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
50 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
51 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
52 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
53 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
54 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
55 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
56 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
57 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
66 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
67 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
68 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
69 #else
70 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
71 #endif
72
73 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
74 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
75
76 /*
77  * Used to build GFID:
78  *
79  *   15           2  0
80  *  +--------------+--+
81  *  |   Index      |E |
82  *  +--------------+--+
83  *
84  * E = Entry (bucket inndex)
85  */
86 #define TF_EM_INTERNAL_INDEX_SHIFT 2
87 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
88 #define TF_EM_INTERNAL_ENTRY_MASK  0x3
89
90 /** EM Entry
91  *  Each EM entry is 512-bit (64-bytes) but ordered differently to
92  *  EEM.
93  */
94 struct tf_em_64b_entry {
95         /** Header is 8 bytes long */
96         struct cfa_p4_eem_entry_hdr hdr;
97         /** Key is 448 bits - 56 bytes */
98         uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
99 };
100
101 /** EEM Memory Type
102  *
103  */
104 enum tf_mem_type {
105         TF_EEM_MEM_TYPE_INVALID,
106         TF_EEM_MEM_TYPE_HOST,
107         TF_EEM_MEM_TYPE_SYSTEM
108 };
109
110 /**
111  * tf_em_cfg_parms definition
112  */
113 struct tf_em_cfg_parms {
114         /**
115          * [in] Num entries in resource config
116          */
117         uint16_t num_elements;
118         /**
119          * [in] Resource config
120          */
121         struct tf_rm_element_cfg *cfg;
122         /**
123          * Session resource allocations
124          */
125         struct tf_session_resources *resources;
126         /**
127          * [in] Memory type.
128          */
129         enum tf_mem_type mem_type;
130 };
131
132 /**
133  * @page em EM
134  *
135  * @ref tf_alloc_eem_tbl_scope
136  *
137  * @ref tf_free_eem_tbl_scope_cb
138  *
139  * @ref tf_em_insert_int_entry
140  *
141  * @ref tf_em_delete_int_entry
142  *
143  * @ref tf_em_insert_ext_entry
144  *
145  * @ref tf_em_delete_ext_entry
146  *
147  * @ref tf_em_insert_ext_sys_entry
148  *
149  * @ref tf_em_delete_ext_sys_entry
150  *
151  * @ref tf_em_int_bind
152  *
153  * @ref tf_em_int_unbind
154  *
155  * @ref tf_em_ext_common_bind
156  *
157  * @ref tf_em_ext_common_unbind
158  *
159  * @ref tf_em_ext_host_alloc
160  *
161  * @ref tf_em_ext_host_free
162  *
163  * @ref tf_em_ext_system_alloc
164  *
165  * @ref tf_em_ext_system_free
166  *
167  * @ref tf_em_ext_common_free
168  *
169  * @ref tf_em_ext_common_alloc
170  */
171
172 /**
173  * Allocates EEM Table scope
174  *
175  * [in] tfp
176  *   Pointer to TruFlow handle
177  *
178  * [in] parms
179  *   Pointer to input parameters
180  *
181  * Returns:
182  *   0       - Success
183  *   -EINVAL - Parameter error
184  *   -ENOMEM - Out of memory
185  */
186 int tf_alloc_eem_tbl_scope(struct tf *tfp,
187                            struct tf_alloc_tbl_scope_parms *parms);
188
189 /**
190  * Free's EEM Table scope control block
191  *
192  * [in] tfp
193  *   Pointer to TruFlow handle
194  *
195  * [in] parms
196  *   Pointer to input parameters
197  *
198  * Returns:
199  *   0       - Success
200  *   -EINVAL - Parameter error
201  */
202 int tf_free_eem_tbl_scope_cb(struct tf *tfp,
203                              struct tf_free_tbl_scope_parms *parms);
204
205 /**
206  * Insert record in to internal EM table
207  *
208  * [in] tfp
209  *   Pointer to TruFlow handle
210  *
211  * [in] parms
212  *   Pointer to input parameters
213  *
214  * Returns:
215  *   0       - Success
216  *   -EINVAL - Parameter error
217  */
218 int tf_em_insert_int_entry(struct tf *tfp,
219                            struct tf_insert_em_entry_parms *parms);
220
221 /**
222  * Delete record from internal EM table
223  *
224  * [in] tfp
225  *   Pointer to TruFlow handle
226  *
227  * [in] parms
228  *   Pointer to input parameters
229  *
230  * Returns:
231  *   0       - Success
232  *   -EINVAL - Parameter error
233  */
234 int tf_em_delete_int_entry(struct tf *tfp,
235                            struct tf_delete_em_entry_parms *parms);
236
237 /**
238  * Insert record in to external EEM table
239  *
240  * [in] tfp
241  *   Pointer to TruFlow handle
242  *
243  * [in] parms
244  *   Pointer to input parameters
245  *
246  * Returns:
247  *   0       - Success
248  *   -EINVAL - Parameter error
249  */
250 int tf_em_insert_ext_entry(struct tf *tfp,
251                            struct tf_insert_em_entry_parms *parms);
252
253 /**
254  * Insert record from external EEM table
255  *
256  * [in] tfp
257  *   Pointer to TruFlow handle
258  *
259  * [in] parms
260  *   Pointer to input parameters
261  *
262  * Returns:
263  *   0       - Success
264  *   -EINVAL - Parameter error
265  */
266 int tf_em_delete_ext_entry(struct tf *tfp,
267                            struct tf_delete_em_entry_parms *parms);
268
269 /**
270  * Insert record in to external system EEM table
271  *
272  * [in] tfp
273  *   Pointer to TruFlow handle
274  *
275  * [in] parms
276  *   Pointer to input parameters
277  *
278  * Returns:
279  *   0       - Success
280  *   -EINVAL - Parameter error
281  */
282 int tf_em_insert_ext_sys_entry(struct tf *tfp,
283                                struct tf_insert_em_entry_parms *parms);
284
285 /**
286  * Delete record from external system EEM table
287  *
288  * [in] tfp
289  *   Pointer to TruFlow handle
290  *
291  * [in] parms
292  *   Pointer to input parameters
293  *
294  * Returns:
295  *   0       - Success
296  *   -EINVAL - Parameter error
297  */
298 int tf_em_delete_ext_sys_entry(struct tf *tfp,
299                                struct tf_delete_em_entry_parms *parms);
300
301 /**
302  * Bind internal EM device interface
303  *
304  * [in] tfp
305  *   Pointer to TruFlow handle
306  *
307  * [in] parms
308  *   Pointer to input parameters
309  *
310  * Returns:
311  *   0       - Success
312  *   -EINVAL - Parameter error
313  */
314 int tf_em_int_bind(struct tf *tfp,
315                    struct tf_em_cfg_parms *parms);
316
317 /**
318  * Unbind internal EM device interface
319  *
320  * [in] tfp
321  *   Pointer to TruFlow handle
322  *
323  * [in] parms
324  *   Pointer to input parameters
325  *
326  * Returns:
327  *   0       - Success
328  *   -EINVAL - Parameter error
329  */
330 int tf_em_int_unbind(struct tf *tfp);
331
332 /**
333  * Common bind for EEM device interface. Used for both host and
334  * system memory
335  *
336  * [in] tfp
337  *   Pointer to TruFlow handle
338  *
339  * [in] parms
340  *   Pointer to input parameters
341  *
342  * Returns:
343  *   0       - Success
344  *   -EINVAL - Parameter error
345  */
346 int tf_em_ext_common_bind(struct tf *tfp,
347                           struct tf_em_cfg_parms *parms);
348
349 /**
350  * Common unbind for EEM device interface. Used for both host and
351  * system memory
352  *
353  * [in] tfp
354  *   Pointer to TruFlow handle
355  *
356  * [in] parms
357  *   Pointer to input parameters
358  *
359  * Returns:
360  *   0       - Success
361  *   -EINVAL - Parameter error
362  */
363 int tf_em_ext_common_unbind(struct tf *tfp);
364
365 /**
366  * Alloc for external EEM using host memory
367  *
368  * [in] tfp
369  *   Pointer to TruFlow handle
370  *
371  * [in] parms
372  *   Pointer to input parameters
373  *
374  * Returns:
375  *   0       - Success
376  *   -EINVAL - Parameter error
377  */
378 int tf_em_ext_host_alloc(struct tf *tfp,
379                          struct tf_alloc_tbl_scope_parms *parms);
380
381 /**
382  * Free for external EEM using host memory
383  *
384  * [in] tfp
385  *   Pointer to TruFlow handle
386  *
387  * [in] parms
388  *   Pointer to input parameters
389  *
390  * Returns:
391  *   0       - Success
392  *   -EINVAL - Parameter error
393  */
394 int tf_em_ext_host_free(struct tf *tfp,
395                         struct tf_free_tbl_scope_parms *parms);
396
397 /**
398  * Alloc for external EEM using system memory
399  *
400  * [in] tfp
401  *   Pointer to TruFlow handle
402  *
403  * [in] parms
404  *   Pointer to input parameters
405  *
406  * Returns:
407  *   0       - Success
408  *   -EINVAL - Parameter error
409  */
410 int tf_em_ext_system_alloc(struct tf *tfp,
411                            struct tf_alloc_tbl_scope_parms *parms);
412
413 /**
414  * Free for external EEM using system memory
415  *
416  * [in] tfp
417  *   Pointer to TruFlow handle
418  *
419  * [in] parms
420  *   Pointer to input parameters
421  *
422  * Returns:
423  *   0       - Success
424  *   -EINVAL - Parameter error
425  */
426 int tf_em_ext_system_free(struct tf *tfp,
427                           struct tf_free_tbl_scope_parms *parms);
428
429 /**
430  * Common free for external EEM using host or system memory
431  *
432  * [in] tfp
433  *   Pointer to TruFlow handle
434  *
435  * [in] parms
436  *   Pointer to input parameters
437  *
438  * Returns:
439  *   0       - Success
440  *   -EINVAL - Parameter error
441  */
442 int tf_em_ext_common_free(struct tf *tfp,
443                           struct tf_free_tbl_scope_parms *parms);
444
445 /**
446  * Common alloc for external EEM using host or system memory
447  *
448  * [in] tfp
449  *   Pointer to TruFlow handle
450  *
451  * [in] parms
452  *   Pointer to input parameters
453  *
454  * Returns:
455  *   0       - Success
456  *   -EINVAL - Parameter error
457  */
458 int tf_em_ext_common_alloc(struct tf *tfp,
459                            struct tf_alloc_tbl_scope_parms *parms);
460 #endif /* _TF_EM_H_ */