5a67ca35092db03b33933c9f4c8117b9da9d5063
[dpdk.git] / drivers / net / bnxt / tf_core / tf_em.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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 #include "hcapi/cfa/hcapi_cfa_defs.h"
13
14 #define TF_EM_MIN_ENTRIES     (1 << 15) /* 32K */
15 #define TF_EM_MAX_ENTRIES     (1 << 27) /* 128M */
16
17 #define TF_HW_EM_KEY_MAX_SIZE 52
18 #define TF_EM_KEY_RECORD_SIZE 64
19
20 #define TF_EM_MAX_MASK 0x7FFF
21 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
22
23 /**
24  * Hardware Page sizes supported for EEM:
25  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
26  *
27  * Round-down other page sizes to the lower hardware page
28  * size supported.
29  */
30 #define TF_EM_PAGE_SIZE_4K 12
31 #define TF_EM_PAGE_SIZE_8K 13
32 #define TF_EM_PAGE_SIZE_64K 16
33 #define TF_EM_PAGE_SIZE_256K 18
34 #define TF_EM_PAGE_SIZE_1M 20
35 #define TF_EM_PAGE_SIZE_2M 21
36 #define TF_EM_PAGE_SIZE_4M 22
37 #define TF_EM_PAGE_SIZE_1G 30
38
39 /* Set page size */
40 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
41
42 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
43 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
44 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
45 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
46 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
47 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
48 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
49 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
50 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
51 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
52 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
53 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
54 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
55 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
56 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
57 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
58 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
59 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
60 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
61 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
62 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
63 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
64 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
65 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
66 #else
67 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
68 #endif
69
70 /*
71  * System memory always uses 4K pages
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_alloc
160  *
161  * @ref tf_em_ext_free
162  *
163  * @ref tf_em_ext_common_free
164  *
165  * @ref tf_em_ext_common_alloc
166  */
167
168 /**
169  * Insert record in to internal EM table
170  *
171  * [in] tfp
172  *   Pointer to TruFlow handle
173  *
174  * [in] parms
175  *   Pointer to input parameters
176  *
177  * Returns:
178  *   0       - Success
179  *   -EINVAL - Parameter error
180  */
181 int tf_em_insert_int_entry(struct tf *tfp,
182                            struct tf_insert_em_entry_parms *parms);
183
184 /**
185  * Delete record from internal EM table
186  *
187  * [in] tfp
188  *   Pointer to TruFlow handle
189  *
190  * [in] parms
191  *   Pointer to input parameters
192  *
193  * Returns:
194  *   0       - Success
195  *   -EINVAL - Parameter error
196  */
197 int tf_em_delete_int_entry(struct tf *tfp,
198                            struct tf_delete_em_entry_parms *parms);
199
200 /**
201  * Insert record in to internal EM table
202  *
203  * [in] tfp
204  *   Pointer to TruFlow handle
205  *
206  * [in] parms
207  *   Pointer to input parameters
208  *
209  * Returns:
210  *   0       - Success
211  *   -EINVAL - Parameter error
212  */
213 int tf_em_hash_insert_int_entry(struct tf *tfp,
214                                 struct tf_insert_em_entry_parms *parms);
215
216 /**
217  * Delete record from internal EM table
218  *
219  * [in] tfp
220  *   Pointer to TruFlow handle
221  *
222  * [in] parms
223  *   Pointer to input parameters
224  *
225  * Returns:
226  *   0       - Success
227  *   -EINVAL - Parameter error
228  */
229 int tf_em_hash_delete_int_entry(struct tf *tfp,
230                                 struct tf_delete_em_entry_parms *parms);
231
232 /**
233  * Insert record in to external EEM table
234  *
235  * [in] tfp
236  *   Pointer to TruFlow handle
237  *
238  * [in] parms
239  *   Pointer to input parameters
240  *
241  * Returns:
242  *   0       - Success
243  *   -EINVAL - Parameter error
244  */
245 int tf_em_insert_ext_entry(struct tf *tfp,
246                            struct tf_insert_em_entry_parms *parms);
247
248 /**
249  * Insert record from external EEM table
250  *
251  * [in] tfp
252  *   Pointer to TruFlow handle
253  *
254  * [in] parms
255  *   Pointer to input parameters
256  *
257  * Returns:
258  *   0       - Success
259  *   -EINVAL - Parameter error
260  */
261 int tf_em_delete_ext_entry(struct tf *tfp,
262                            struct tf_delete_em_entry_parms *parms);
263
264 /**
265  * Insert record in to external system EEM table
266  *
267  * [in] tfp
268  *   Pointer to TruFlow handle
269  *
270  * [in] parms
271  *   Pointer to input parameters
272  *
273  * Returns:
274  *   0       - Success
275  *   -EINVAL - Parameter error
276  */
277 int tf_em_insert_ext_sys_entry(struct tf *tfp,
278                                struct tf_insert_em_entry_parms *parms);
279
280 /**
281  * Delete record from external system EEM table
282  *
283  * [in] tfp
284  *   Pointer to TruFlow handle
285  *
286  * [in] parms
287  *   Pointer to input parameters
288  *
289  * Returns:
290  *   0       - Success
291  *   -EINVAL - Parameter error
292  */
293 int tf_em_delete_ext_sys_entry(struct tf *tfp,
294                                struct tf_delete_em_entry_parms *parms);
295
296 /**
297  * Bind internal EM device interface
298  *
299  * [in] tfp
300  *   Pointer to TruFlow handle
301  *
302  * [in] parms
303  *   Pointer to input parameters
304  *
305  * Returns:
306  *   0       - Success
307  *   -EINVAL - Parameter error
308  */
309 int tf_em_int_bind(struct tf *tfp,
310                    struct tf_em_cfg_parms *parms);
311
312 /**
313  * Unbind internal EM device interface
314  *
315  * [in] tfp
316  *   Pointer to TruFlow handle
317  *
318  * [in] parms
319  *   Pointer to input parameters
320  *
321  * Returns:
322  *   0       - Success
323  *   -EINVAL - Parameter error
324  */
325 int tf_em_int_unbind(struct tf *tfp);
326
327 /**
328  * Common bind for EEM device interface. Used for both host and
329  * system memory
330  *
331  * [in] tfp
332  *   Pointer to TruFlow handle
333  *
334  * [in] parms
335  *   Pointer to input parameters
336  *
337  * Returns:
338  *   0       - Success
339  *   -EINVAL - Parameter error
340  */
341 int tf_em_ext_common_bind(struct tf *tfp,
342                           struct tf_em_cfg_parms *parms);
343
344 /**
345  * Common unbind for EEM device interface. Used for both host and
346  * system memory
347  *
348  * [in] tfp
349  *   Pointer to TruFlow handle
350  *
351  * [in] parms
352  *   Pointer to input parameters
353  *
354  * Returns:
355  *   0       - Success
356  *   -EINVAL - Parameter error
357  */
358 int tf_em_ext_common_unbind(struct tf *tfp);
359
360 /**
361  * Alloc for external EEM using host memory
362  *
363  * [in] tfp
364  *   Pointer to TruFlow handle
365  *
366  * [in] parms
367  *   Pointer to input parameters
368  *
369  * Returns:
370  *   0       - Success
371  *   -EINVAL - Parameter error
372  */
373 int tf_em_ext_alloc(struct tf *tfp,
374                     struct tf_alloc_tbl_scope_parms *parms);
375
376 /**
377  * Free for external EEM using host memory
378  *
379  * [in] tfp
380  *   Pointer to TruFlow handle
381  *
382  * [in] parms
383  *   Pointer to input parameters
384  *
385  * Returns:
386  *   0       - Success
387  *   -EINVAL - Parameter error
388  */
389 int tf_em_ext_free(struct tf *tfp,
390                    struct tf_free_tbl_scope_parms *parms);
391
392 /**
393  * Common free table scope for external EEM using host or system memory
394  *
395  * [in] tfp
396  *   Pointer to TruFlow handle
397  *
398  * [in] parms
399  *   Pointer to input parameters
400  *
401  * Returns:
402  *   0       - Success
403  *   -EINVAL - Parameter error
404  */
405 int tf_em_ext_common_free(struct tf *tfp,
406                           struct tf_free_tbl_scope_parms *parms);
407
408 /**
409  * Common alloc table scope for external EEM using host or system memory
410  *
411  * [in] tfp
412  *   Pointer to TruFlow handle
413  *
414  * [in] parms
415  *   Pointer to input parameters
416  *
417  * Returns:
418  *   0       - Success
419  *   -EINVAL - Parameter error
420  */
421 int tf_em_ext_common_alloc(struct tf *tfp,
422                            struct tf_alloc_tbl_scope_parms *parms);
423 /**
424  * Map a set of parifs to a set of EEM base addresses (table scope)
425  *
426  * [in] tfp
427  *   Pointer to TruFlow handle
428  *
429  * [in] parms
430  *   Pointer to input parameters
431  *
432  * Returns:
433  *   0       - Success
434  *   -EINVAL - Parameter error
435  */
436 int tf_em_ext_map_tbl_scope(struct tf *tfp,
437                             struct tf_map_tbl_scope_parms *parms);
438
439 /**
440  * Allocate External Tbl entry from the scope pool.
441  *
442  * [in] tfp
443  *   Pointer to Truflow Handle
444  * [in] parms
445  *   Allocation parameters
446  *
447  * Return:
448  *  0       - Success, entry allocated - no search support
449  *  -ENOMEM -EINVAL -EOPNOTSUPP
450  *          - Failure, entry not allocated, out of resources
451  */
452 int
453 tf_tbl_ext_alloc(struct tf *tfp,
454                  struct tf_tbl_alloc_parms *parms);
455
456 /**
457  * Free External Tbl entry to the scope pool.
458  *
459  * [in] tfp
460  *   Pointer to Truflow Handle
461  * [in] parms
462  *   Allocation parameters
463  *
464  * Return:
465  *  0       - Success, entry freed
466  *
467  * - Failure, entry not successfully freed for these reasons
468  *  -ENOMEM
469  *  -EOPNOTSUPP
470  *  -EINVAL
471  */
472 int
473 tf_tbl_ext_free(struct tf *tfp,
474                 struct tf_tbl_free_parms *parms);
475
476 /**
477  * Sets the specified external table type element.
478  *
479  * This API sets the specified element data by invoking the
480  * firmware.
481  *
482  * [in] tfp
483  *   Pointer to TF handle
484  *
485  * [in] parms
486  *   Pointer to table set parameters
487  *
488  * Returns
489  *   - (0) if successful.
490  *   - (-EINVAL) on failure.
491  */
492 int tf_tbl_ext_common_set(struct tf *tfp,
493                           struct tf_tbl_set_parms *parms);
494
495 /**
496  * Sets the specified external table type element.
497  *
498  * This API sets the specified element data by invoking the
499  * firmware.
500  *
501  * [in] tfp
502  *   Pointer to TF handle
503  *
504  * [in] parms
505  *   Pointer to table set parameters
506  *
507  * Returns
508  *   - (0) if successful.
509  *   - (-EINVAL) on failure.
510  */
511 int tf_tbl_ext_set(struct tf *tfp,
512                    struct tf_tbl_set_parms *parms);
513
514 int
515 tf_em_ext_system_bind(struct tf *tfp,
516                       struct tf_em_cfg_parms *parms);
517
518 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
519 #endif /* _TF_EM_H_ */