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