net/bnxt: support two table scopes
[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 table scope 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 table scope 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  * Map a set of parifs to a set of EEM base addresses (table scope)
393  *
394  * [in] tfp
395  *   Pointer to TruFlow handle
396  *
397  * [in] parms
398  *   Pointer to input parameters
399  *
400  * Returns:
401  *   0       - Success
402  *   -EINVAL - Parameter error
403  */
404 int tf_em_ext_map_tbl_scope(struct tf *tfp,
405                             struct tf_map_tbl_scope_parms *parms);
406
407 /**
408  * Allocate External Tbl entry from the scope pool.
409  *
410  * [in] tfp
411  *   Pointer to Truflow Handle
412  * [in] parms
413  *   Allocation parameters
414  *
415  * Return:
416  *  0       - Success, entry allocated - no search support
417  *  -ENOMEM -EINVAL -EOPNOTSUPP
418  *          - Failure, entry not allocated, out of resources
419  */
420 int
421 tf_tbl_ext_alloc(struct tf *tfp,
422                  struct tf_tbl_alloc_parms *parms);
423
424 /**
425  * Free External Tbl entry to the scope pool.
426  *
427  * [in] tfp
428  *   Pointer to Truflow Handle
429  * [in] parms
430  *   Allocation parameters
431  *
432  * Return:
433  *  0       - Success, entry freed
434  *
435  * - Failure, entry not successfully freed for these reasons
436  *  -ENOMEM
437  *  -EOPNOTSUPP
438  *  -EINVAL
439  */
440 int
441 tf_tbl_ext_free(struct tf *tfp,
442                 struct tf_tbl_free_parms *parms);
443
444 /**
445  * Sets the specified external table type element.
446  *
447  * This API sets the specified element data by invoking the
448  * firmware.
449  *
450  * [in] tfp
451  *   Pointer to TF handle
452  *
453  * [in] parms
454  *   Pointer to table set parameters
455  *
456  * Returns
457  *   - (0) if successful.
458  *   - (-EINVAL) on failure.
459  */
460 int tf_tbl_ext_common_set(struct tf *tfp,
461                           struct tf_tbl_set_parms *parms);
462
463 /**
464  * Sets the specified external table type element.
465  *
466  * This API sets the specified element data by invoking the
467  * firmware.
468  *
469  * [in] tfp
470  *   Pointer to TF handle
471  *
472  * [in] parms
473  *   Pointer to table set parameters
474  *
475  * Returns
476  *   - (0) if successful.
477  *   - (-EINVAL) on failure.
478  */
479 int tf_tbl_ext_set(struct tf *tfp,
480                    struct tf_tbl_set_parms *parms);
481
482 int
483 tf_em_ext_system_bind(struct tf *tfp,
484                       struct tf_em_cfg_parms *parms);
485
486 int offload_system_mmap(struct tf_tbl_scope_cb *tbl_scope_cb);
487 #endif /* _TF_EM_H_ */