39a216341b33e2aa93aa9c447261c750a3223904
[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 SUPPORT_CFA_HW_P4 1
13 #define SUPPORT_CFA_HW_P58 0
14 #define SUPPORT_CFA_HW_P59 0
15 #define SUPPORT_CFA_HW_ALL 0
16
17 #include "hcapi/hcapi_cfa_defs.h"
18
19 #define TF_HW_EM_KEY_MAX_SIZE 52
20 #define TF_EM_KEY_RECORD_SIZE 64
21
22 #define TF_EM_MAX_MASK 0x7FFF
23 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
24
25 /**
26  * Hardware Page sizes supported for EEM:
27  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
28  *
29  * Round-down other page sizes to the lower hardware page
30  * size supported.
31  */
32 #define TF_EM_PAGE_SIZE_4K 12
33 #define TF_EM_PAGE_SIZE_8K 13
34 #define TF_EM_PAGE_SIZE_64K 16
35 #define TF_EM_PAGE_SIZE_256K 18
36 #define TF_EM_PAGE_SIZE_1M 20
37 #define TF_EM_PAGE_SIZE_2M 21
38 #define TF_EM_PAGE_SIZE_4M 22
39 #define TF_EM_PAGE_SIZE_1G 30
40
41 /* Set page size */
42 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
43
44 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
45 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
46 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
47 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
48 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
49 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
50 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
51 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
52 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
53 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
54 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
55 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
56 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
57 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
58 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
59 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
60 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
61 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
62 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
63 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
64 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
65 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
66 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
67 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
68 #else
69 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
70 #endif
71
72 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
73 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
74
75 /*
76  * Used to build GFID:
77  *
78  *   15           2  0
79  *  +--------------+--+
80  *  |   Index      |E |
81  *  +--------------+--+
82  *
83  * E = Entry (bucket inndex)
84  */
85 #define TF_EM_INTERNAL_INDEX_SHIFT 2
86 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
87 #define TF_EM_INTERNAL_ENTRY_MASK  0x3
88
89 /** EM Entry
90  *  Each EM entry is 512-bit (64-bytes) but ordered differently to
91  *  EEM.
92  */
93 struct tf_em_64b_entry {
94         /** Header is 8 bytes long */
95         struct cfa_p4_eem_entry_hdr hdr;
96         /** Key is 448 bits - 56 bytes */
97         uint8_t key[TF_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
98 };
99
100 /** EEM Memory Type
101  *
102  */
103 enum tf_mem_type {
104         TF_EEM_MEM_TYPE_INVALID,
105         TF_EEM_MEM_TYPE_HOST,
106         TF_EEM_MEM_TYPE_SYSTEM
107 };
108
109 /**
110  * tf_em_cfg_parms definition
111  */
112 struct tf_em_cfg_parms {
113         /**
114          * [in] Num entries in resource config
115          */
116         uint16_t num_elements;
117         /**
118          * [in] Resource config
119          */
120         struct tf_rm_element_cfg *cfg;
121         /**
122          * Session resource allocations
123          */
124         struct tf_session_resources *resources;
125         /**
126          * [in] Memory type.
127          */
128         enum tf_mem_type mem_type;
129 };
130
131 /**
132  * @page em EM
133  *
134  * @ref tf_alloc_eem_tbl_scope
135  *
136  * @ref tf_free_eem_tbl_scope_cb
137  *
138  * @ref tf_em_insert_int_entry
139  *
140  * @ref tf_em_delete_int_entry
141  *
142  * @ref tf_em_insert_ext_entry
143  *
144  * @ref tf_em_delete_ext_entry
145  *
146  * @ref tf_em_insert_ext_sys_entry
147  *
148  * @ref tf_em_delete_ext_sys_entry
149  *
150  * @ref tf_em_int_bind
151  *
152  * @ref tf_em_int_unbind
153  *
154  * @ref tf_em_ext_common_bind
155  *
156  * @ref tf_em_ext_common_unbind
157  *
158  * @ref tf_em_ext_host_alloc
159  *
160  * @ref tf_em_ext_host_free
161  *
162  * @ref tf_em_ext_system_alloc
163  *
164  * @ref tf_em_ext_system_free
165  *
166  * @ref tf_em_ext_common_free
167  *
168  * @ref tf_em_ext_common_alloc
169  */
170
171 /**
172  * Allocates EEM Table scope
173  *
174  * [in] tfp
175  *   Pointer to TruFlow handle
176  *
177  * [in] parms
178  *   Pointer to input parameters
179  *
180  * Returns:
181  *   0       - Success
182  *   -EINVAL - Parameter error
183  *   -ENOMEM - Out of memory
184  */
185 int tf_alloc_eem_tbl_scope(struct tf *tfp,
186                            struct tf_alloc_tbl_scope_parms *parms);
187
188 /**
189  * Free's EEM Table scope control block
190  *
191  * [in] tfp
192  *   Pointer to TruFlow handle
193  *
194  * [in] parms
195  *   Pointer to input parameters
196  *
197  * Returns:
198  *   0       - Success
199  *   -EINVAL - Parameter error
200  */
201 int tf_free_eem_tbl_scope_cb(struct tf *tfp,
202                              struct tf_free_tbl_scope_parms *parms);
203
204 /**
205  * Insert record in to internal EM table
206  *
207  * [in] tfp
208  *   Pointer to TruFlow handle
209  *
210  * [in] parms
211  *   Pointer to input parameters
212  *
213  * Returns:
214  *   0       - Success
215  *   -EINVAL - Parameter error
216  */
217 int tf_em_insert_int_entry(struct tf *tfp,
218                            struct tf_insert_em_entry_parms *parms);
219
220 /**
221  * Delete record from internal EM table
222  *
223  * [in] tfp
224  *   Pointer to TruFlow handle
225  *
226  * [in] parms
227  *   Pointer to input parameters
228  *
229  * Returns:
230  *   0       - Success
231  *   -EINVAL - Parameter error
232  */
233 int tf_em_delete_int_entry(struct tf *tfp,
234                            struct tf_delete_em_entry_parms *parms);
235
236 /**
237  * Insert record in to external EEM table
238  *
239  * [in] tfp
240  *   Pointer to TruFlow handle
241  *
242  * [in] parms
243  *   Pointer to input parameters
244  *
245  * Returns:
246  *   0       - Success
247  *   -EINVAL - Parameter error
248  */
249 int tf_em_insert_ext_entry(struct tf *tfp,
250                            struct tf_insert_em_entry_parms *parms);
251
252 /**
253  * Insert record from external EEM table
254  *
255  * [in] tfp
256  *   Pointer to TruFlow handle
257  *
258  * [in] parms
259  *   Pointer to input parameters
260  *
261  * Returns:
262  *   0       - Success
263  *   -EINVAL - Parameter error
264  */
265 int tf_em_delete_ext_entry(struct tf *tfp,
266                            struct tf_delete_em_entry_parms *parms);
267
268 /**
269  * Insert record in to external system EEM table
270  *
271  * [in] tfp
272  *   Pointer to TruFlow handle
273  *
274  * [in] parms
275  *   Pointer to input parameters
276  *
277  * Returns:
278  *   0       - Success
279  *   -EINVAL - Parameter error
280  */
281 int tf_em_insert_ext_sys_entry(struct tf *tfp,
282                                struct tf_insert_em_entry_parms *parms);
283
284 /**
285  * Delete record from external system EEM table
286  *
287  * [in] tfp
288  *   Pointer to TruFlow handle
289  *
290  * [in] parms
291  *   Pointer to input parameters
292  *
293  * Returns:
294  *   0       - Success
295  *   -EINVAL - Parameter error
296  */
297 int tf_em_delete_ext_sys_entry(struct tf *tfp,
298                                struct tf_delete_em_entry_parms *parms);
299
300 /**
301  * Bind internal EM device interface
302  *
303  * [in] tfp
304  *   Pointer to TruFlow handle
305  *
306  * [in] parms
307  *   Pointer to input parameters
308  *
309  * Returns:
310  *   0       - Success
311  *   -EINVAL - Parameter error
312  */
313 int tf_em_int_bind(struct tf *tfp,
314                    struct tf_em_cfg_parms *parms);
315
316 /**
317  * Unbind internal EM device interface
318  *
319  * [in] tfp
320  *   Pointer to TruFlow handle
321  *
322  * [in] parms
323  *   Pointer to input parameters
324  *
325  * Returns:
326  *   0       - Success
327  *   -EINVAL - Parameter error
328  */
329 int tf_em_int_unbind(struct tf *tfp);
330
331 /**
332  * Common bind for EEM device interface. Used for both host and
333  * system memory
334  *
335  * [in] tfp
336  *   Pointer to TruFlow handle
337  *
338  * [in] parms
339  *   Pointer to input parameters
340  *
341  * Returns:
342  *   0       - Success
343  *   -EINVAL - Parameter error
344  */
345 int tf_em_ext_common_bind(struct tf *tfp,
346                           struct tf_em_cfg_parms *parms);
347
348 /**
349  * Common unbind for EEM device interface. Used for both host and
350  * system memory
351  *
352  * [in] tfp
353  *   Pointer to TruFlow handle
354  *
355  * [in] parms
356  *   Pointer to input parameters
357  *
358  * Returns:
359  *   0       - Success
360  *   -EINVAL - Parameter error
361  */
362 int tf_em_ext_common_unbind(struct tf *tfp);
363
364 /**
365  * Alloc for external EEM using host memory
366  *
367  * [in] tfp
368  *   Pointer to TruFlow handle
369  *
370  * [in] parms
371  *   Pointer to input parameters
372  *
373  * Returns:
374  *   0       - Success
375  *   -EINVAL - Parameter error
376  */
377 int tf_em_ext_host_alloc(struct tf *tfp,
378                          struct tf_alloc_tbl_scope_parms *parms);
379
380 /**
381  * Free for external EEM using host memory
382  *
383  * [in] tfp
384  *   Pointer to TruFlow handle
385  *
386  * [in] parms
387  *   Pointer to input parameters
388  *
389  * Returns:
390  *   0       - Success
391  *   -EINVAL - Parameter error
392  */
393 int tf_em_ext_host_free(struct tf *tfp,
394                         struct tf_free_tbl_scope_parms *parms);
395
396 /**
397  * Alloc for external EEM using system memory
398  *
399  * [in] tfp
400  *   Pointer to TruFlow handle
401  *
402  * [in] parms
403  *   Pointer to input parameters
404  *
405  * Returns:
406  *   0       - Success
407  *   -EINVAL - Parameter error
408  */
409 int tf_em_ext_system_alloc(struct tf *tfp,
410                            struct tf_alloc_tbl_scope_parms *parms);
411
412 /**
413  * Free for external EEM using system memory
414  *
415  * [in] tfp
416  *   Pointer to TruFlow handle
417  *
418  * [in] parms
419  *   Pointer to input parameters
420  *
421  * Returns:
422  *   0       - Success
423  *   -EINVAL - Parameter error
424  */
425 int tf_em_ext_system_free(struct tf *tfp,
426                           struct tf_free_tbl_scope_parms *parms);
427
428 /**
429  * Common free for external EEM using host or system memory
430  *
431  * [in] tfp
432  *   Pointer to TruFlow handle
433  *
434  * [in] parms
435  *   Pointer to input parameters
436  *
437  * Returns:
438  *   0       - Success
439  *   -EINVAL - Parameter error
440  */
441 int tf_em_ext_common_free(struct tf *tfp,
442                           struct tf_free_tbl_scope_parms *parms);
443
444 /**
445  * Common alloc for external EEM using host or system memory
446  *
447  * [in] tfp
448  *   Pointer to TruFlow handle
449  *
450  * [in] parms
451  *   Pointer to input parameters
452  *
453  * Returns:
454  *   0       - Success
455  *   -EINVAL - Parameter error
456  */
457 int tf_em_ext_common_alloc(struct tf *tfp,
458                            struct tf_alloc_tbl_scope_parms *parms);
459
460 /**
461  * Allocate External Tbl entry from the scope pool.
462  *
463  * [in] tfp
464  *   Pointer to Truflow Handle
465  * [in] parms
466  *   Allocation parameters
467  *
468  * Return:
469  *  0       - Success, entry allocated - no search support
470  *  -ENOMEM -EINVAL -EOPNOTSUPP
471  *          - Failure, entry not allocated, out of resources
472  */
473 int
474 tf_tbl_ext_alloc(struct tf *tfp,
475                  struct tf_tbl_alloc_parms *parms);
476
477 /**
478  * Free External Tbl entry to the scope pool.
479  *
480  * [in] tfp
481  *   Pointer to Truflow Handle
482  * [in] parms
483  *   Allocation parameters
484  *
485  * Return:
486  *  0       - Success, entry freed
487  *
488  * - Failure, entry not successfully freed for these reasons
489  *  -ENOMEM
490  *  -EOPNOTSUPP
491  *  -EINVAL
492  */
493 int
494 tf_tbl_ext_free(struct tf *tfp,
495                 struct tf_tbl_free_parms *parms);
496
497 /**
498  * Sets the specified external table type element.
499  *
500  * This API sets the specified element data by invoking the
501  * firmware.
502  *
503  * [in] tfp
504  *   Pointer to TF handle
505  *
506  * [in] parms
507  *   Pointer to table set parameters
508  *
509  * Returns
510  *   - (0) if successful.
511  *   - (-EINVAL) on failure.
512  */
513 int tf_tbl_ext_set(struct tf *tfp,
514                    struct tf_tbl_set_parms *parms);
515
516 /**
517  * Sets the specified external table type element.
518  *
519  * This API sets the specified element data by invoking the
520  * firmware.
521  *
522  * [in] tfp
523  *   Pointer to TF handle
524  *
525  * [in] parms
526  *   Pointer to table set parameters
527  *
528  * Returns
529  *   - (0) if successful.
530  *   - (-EINVAL) on failure.
531  */
532 int tf_tbl_ext_host_set(struct tf *tfp,
533                         struct tf_tbl_set_parms *parms);
534
535 /**
536  * Sets the specified external table type element.
537  *
538  * This API sets the specified element data by invoking the
539  * firmware.
540  *
541  * [in] tfp
542  *   Pointer to TF handle
543  *
544  * [in] parms
545  *   Pointer to table set parameters
546  *
547  * Returns
548  *   - (0) if successful.
549  *   - (-EINVAL) on failure.
550  */
551 int tf_tbl_ext_system_set(struct tf *tfp,
552                           struct tf_tbl_set_parms *parms);
553
554 #endif /* _TF_EM_H_ */