net/bnxt: add Stingray support to core layer
[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 #include "hcapi/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 external EEM 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_insert_ext_entry(struct tf *tfp,
214                            struct tf_insert_em_entry_parms *parms);
215
216 /**
217  * Insert record from external EEM 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_delete_ext_entry(struct tf *tfp,
230                            struct tf_delete_em_entry_parms *parms);
231
232 /**
233  * Insert record in to external system 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_sys_entry(struct tf *tfp,
246                                struct tf_insert_em_entry_parms *parms);
247
248 /**
249  * Delete record from external system 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_sys_entry(struct tf *tfp,
262                                struct tf_delete_em_entry_parms *parms);
263
264 /**
265  * Bind internal EM device interface
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_int_bind(struct tf *tfp,
278                    struct tf_em_cfg_parms *parms);
279
280 /**
281  * Unbind internal EM device interface
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_int_unbind(struct tf *tfp);
294
295 /**
296  * Common bind for EEM device interface. Used for both host and
297  * system memory
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_ext_common_bind(struct tf *tfp,
310                           struct tf_em_cfg_parms *parms);
311
312 /**
313  * Common unbind for EEM device interface. Used for both host and
314  * system memory
315  *
316  * [in] tfp
317  *   Pointer to TruFlow handle
318  *
319  * [in] parms
320  *   Pointer to input parameters
321  *
322  * Returns:
323  *   0       - Success
324  *   -EINVAL - Parameter error
325  */
326 int tf_em_ext_common_unbind(struct tf *tfp);
327
328 /**
329  * Alloc for external EEM using host 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_alloc(struct tf *tfp,
342                     struct tf_alloc_tbl_scope_parms *parms);
343
344 /**
345  * Free for external EEM using host memory
346  *
347  * [in] tfp
348  *   Pointer to TruFlow handle
349  *
350  * [in] parms
351  *   Pointer to input parameters
352  *
353  * Returns:
354  *   0       - Success
355  *   -EINVAL - Parameter error
356  */
357 int tf_em_ext_free(struct tf *tfp,
358                    struct tf_free_tbl_scope_parms *parms);
359
360 /**
361  * Common free for external EEM using host or system 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_common_free(struct tf *tfp,
374                           struct tf_free_tbl_scope_parms *parms);
375
376 /**
377  * Common alloc for external EEM using host or system 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_common_alloc(struct tf *tfp,
390                            struct tf_alloc_tbl_scope_parms *parms);
391
392 /**
393  * Allocate External Tbl entry from the scope pool.
394  *
395  * [in] tfp
396  *   Pointer to Truflow Handle
397  * [in] parms
398  *   Allocation parameters
399  *
400  * Return:
401  *  0       - Success, entry allocated - no search support
402  *  -ENOMEM -EINVAL -EOPNOTSUPP
403  *          - Failure, entry not allocated, out of resources
404  */
405 int
406 tf_tbl_ext_alloc(struct tf *tfp,
407                  struct tf_tbl_alloc_parms *parms);
408
409 /**
410  * Free External Tbl entry to the scope pool.
411  *
412  * [in] tfp
413  *   Pointer to Truflow Handle
414  * [in] parms
415  *   Allocation parameters
416  *
417  * Return:
418  *  0       - Success, entry freed
419  *
420  * - Failure, entry not successfully freed for these reasons
421  *  -ENOMEM
422  *  -EOPNOTSUPP
423  *  -EINVAL
424  */
425 int
426 tf_tbl_ext_free(struct tf *tfp,
427                 struct tf_tbl_free_parms *parms);
428
429 /**
430  * Sets the specified external table type element.
431  *
432  * This API sets the specified element data by invoking the
433  * firmware.
434  *
435  * [in] tfp
436  *   Pointer to TF handle
437  *
438  * [in] parms
439  *   Pointer to table set parameters
440  *
441  * Returns
442  *   - (0) if successful.
443  *   - (-EINVAL) on failure.
444  */
445 int tf_tbl_ext_common_set(struct tf *tfp,
446                           struct tf_tbl_set_parms *parms);
447
448 /**
449  * Sets the specified external table type element.
450  *
451  * This API sets the specified element data by invoking the
452  * firmware.
453  *
454  * [in] tfp
455  *   Pointer to TF handle
456  *
457  * [in] parms
458  *   Pointer to table set parameters
459  *
460  * Returns
461  *   - (0) if successful.
462  *   - (-EINVAL) on failure.
463  */
464 int tf_tbl_ext_set(struct tf *tfp,
465                    struct tf_tbl_set_parms *parms);
466
467 int
468 tf_em_ext_system_bind(struct tf *tfp,
469                       struct tf_em_cfg_parms *parms);
470
471 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
472 #endif /* _TF_EM_H_ */