net/bnxt: modify TRUFLOW HWRM messages
[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 "tf_em_common.h"
13
14 #include "hcapi_cfa_defs.h"
15
16 #define TF_EM_MIN_ENTRIES     (1 << 15) /* 32K */
17 #define TF_EM_MAX_ENTRIES     (1 << 27) /* 128M */
18
19 #define TF_P4_HW_EM_KEY_MAX_SIZE 52
20 #define TF_P4_EM_KEY_RECORD_SIZE 64
21
22 #define TF_P58_HW_EM_KEY_MAX_SIZE 80
23
24 #define TF_EM_MAX_MASK 0x7FFF
25 #define TF_EM_MAX_ENTRY (128 * 1024 * 1024)
26
27 /**
28  * Hardware Page sizes supported for EEM:
29  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
30  *
31  * Round-down other page sizes to the lower hardware page
32  * size supported.
33  */
34 #define TF_EM_PAGE_SIZE_4K 12
35 #define TF_EM_PAGE_SIZE_8K 13
36 #define TF_EM_PAGE_SIZE_64K 16
37 #define TF_EM_PAGE_SIZE_256K 18
38 #define TF_EM_PAGE_SIZE_1M 20
39 #define TF_EM_PAGE_SIZE_2M 21
40 #define TF_EM_PAGE_SIZE_4M 22
41 #define TF_EM_PAGE_SIZE_1G 30
42
43 /* Set page size */
44 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
45
46 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
47 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
48 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
49 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
50 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
51 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
52 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
53 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
54 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
55 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
56 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
57 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
58 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
59 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
60 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
61 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
62 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
63 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
64 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
65 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
66 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
67 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
68 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
69 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
70 #else
71 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
72 #endif
73
74 /*
75  * System memory always uses 4K pages
76  */
77 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
78 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
79
80 /*
81  * Used to build GFID:
82  *
83  *   15           2  0
84  *  +--------------+--+
85  *  |   Index      |E |
86  *  +--------------+--+
87  *
88  * E = Entry (bucket inndex)
89  */
90 #define TF_EM_INTERNAL_INDEX_SHIFT 2
91 #define TF_EM_INTERNAL_INDEX_MASK 0xFFFC
92 #define TF_EM_INTERNAL_ENTRY_MASK  0x3
93
94 /** EM Entry
95  *  Each EM entry is 512-bit (64-bytes) but ordered differently to
96  *  EEM.
97  */
98 struct tf_em_64b_entry {
99         /** Header is 8 bytes long */
100         struct cfa_p4_eem_entry_hdr hdr;
101         /** Key is 448 bits - 56 bytes */
102         uint8_t key[TF_P4_EM_KEY_RECORD_SIZE - sizeof(struct cfa_p4_eem_entry_hdr)];
103 };
104
105 /** EEM Memory Type
106  *
107  */
108 enum tf_mem_type {
109         TF_EEM_MEM_TYPE_INVALID,
110         TF_EEM_MEM_TYPE_HOST,
111         TF_EEM_MEM_TYPE_SYSTEM
112 };
113
114 /**
115  * tf_em_cfg_parms definition
116  */
117 struct tf_em_cfg_parms {
118         /**
119          * [in] Num entries in resource config
120          */
121         uint16_t num_elements;
122         /**
123          * [in] Resource config
124          */
125         struct tf_rm_element_cfg *cfg;
126         /**
127          * Session resource allocations
128          */
129         struct tf_session_resources *resources;
130         /**
131          * [in] Memory type.
132          */
133         enum tf_mem_type mem_type;
134 };
135
136 /**
137  * @page em EM
138  *
139  * @ref tf_alloc_eem_tbl_scope
140  *
141  * @ref tf_free_eem_tbl_scope_cb
142  *
143  * @ref tf_em_insert_int_entry
144  *
145  * @ref tf_em_delete_int_entry
146  *
147  * @ref tf_em_insert_ext_entry
148  *
149  * @ref tf_em_delete_ext_entry
150  *
151  * @ref tf_em_insert_ext_sys_entry
152  *
153  * @ref tf_em_delete_ext_sys_entry
154  *
155  * @ref tf_em_int_bind
156  *
157  * @ref tf_em_int_unbind
158  *
159  * @ref tf_em_ext_common_bind
160  *
161  * @ref tf_em_ext_common_unbind
162  *
163  * @ref tf_em_ext_alloc
164  *
165  * @ref tf_em_ext_free
166  *
167  * @ref tf_em_ext_common_free
168  *
169  * @ref tf_em_ext_common_alloc
170  */
171
172 /**
173  * Insert record in to internal EM table
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  */
185 int tf_em_insert_int_entry(struct tf *tfp,
186                            struct tf_insert_em_entry_parms *parms);
187
188 /**
189  * Delete record from internal EM table
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_em_delete_int_entry(struct tf *tfp,
202                            struct tf_delete_em_entry_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_hash_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_hash_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_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_free(struct tf *tfp,
394                    struct tf_free_tbl_scope_parms *parms);
395
396 /**
397  * Common free table scope for external EEM using host or 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_common_free(struct tf *tfp,
410                           struct tf_free_tbl_scope_parms *parms);
411
412 /**
413  * Common alloc table scope for external EEM using host or 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_common_alloc(struct tf *tfp,
426                            struct tf_alloc_tbl_scope_parms *parms);
427 /**
428  * Map a set of parifs to a set of EEM base addresses (table scope)
429  *
430  * [in] tfp
431  *   Pointer to TruFlow handle
432  *
433  * [in] parms
434  *   Pointer to input parameters
435  *
436  * Returns:
437  *   0       - Success
438  *   -EINVAL - Parameter error
439  */
440 int tf_em_ext_map_tbl_scope(struct tf *tfp,
441                             struct tf_map_tbl_scope_parms *parms);
442
443 /**
444  * Allocate External Tbl entry from the scope pool.
445  *
446  * [in] tfp
447  *   Pointer to Truflow Handle
448  * [in] parms
449  *   Allocation parameters
450  *
451  * Return:
452  *  0       - Success, entry allocated - no search support
453  *  -ENOMEM -EINVAL -EOPNOTSUPP
454  *          - Failure, entry not allocated, out of resources
455  */
456 int
457 tf_tbl_ext_alloc(struct tf *tfp,
458                  struct tf_tbl_alloc_parms *parms);
459
460 /**
461  * Free External Tbl entry to 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 freed
470  *
471  * - Failure, entry not successfully freed for these reasons
472  *  -ENOMEM
473  *  -EOPNOTSUPP
474  *  -EINVAL
475  */
476 int
477 tf_tbl_ext_free(struct tf *tfp,
478                 struct tf_tbl_free_parms *parms);
479
480 /**
481  * Sets the specified external table type element.
482  *
483  * This API sets the specified element data by invoking the
484  * firmware.
485  *
486  * [in] tfp
487  *   Pointer to TF handle
488  *
489  * [in] parms
490  *   Pointer to table set parameters
491  *
492  * Returns
493  *   - (0) if successful.
494  *   - (-EINVAL) on failure.
495  */
496 int tf_tbl_ext_common_set(struct tf *tfp,
497                           struct tf_tbl_set_parms *parms);
498
499 /**
500  * Sets the specified external table type element.
501  *
502  * This API sets the specified element data by invoking the
503  * firmware.
504  *
505  * [in] tfp
506  *   Pointer to TF handle
507  *
508  * [in] parms
509  *   Pointer to table set parameters
510  *
511  * Returns
512  *   - (0) if successful.
513  *   - (-EINVAL) on failure.
514  */
515 int tf_tbl_ext_set(struct tf *tfp,
516                    struct tf_tbl_set_parms *parms);
517
518 int
519 tf_em_ext_system_bind(struct tf *tfp,
520                       struct tf_em_cfg_parms *parms);
521
522 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
523 #endif /* _TF_EM_H_ */