7a54436786a602f5acabb54992a7fabad2410269
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_TBL_H_
7 #define _TF_TBL_H_
8
9 #include <stdint.h>
10 #include "stack.h"
11
12 enum tf_pg_tbl_lvl {
13         PT_LVL_0,
14         PT_LVL_1,
15         PT_LVL_2,
16         PT_LVL_MAX
17 };
18
19 enum tf_em_table_type {
20         KEY0_TABLE,
21         KEY1_TABLE,
22         RECORD_TABLE,
23         EFC_TABLE,
24         MAX_TABLE
25 };
26
27 struct tf_em_page_tbl {
28         uint32_t        pg_count;
29         uint32_t        pg_size;
30         void            **pg_va_tbl;
31         uint64_t        *pg_pa_tbl;
32 };
33
34 struct tf_em_table {
35         int                             type;
36         uint32_t                        num_entries;
37         uint16_t                        ctx_id;
38         uint32_t                        entry_size;
39         int                             num_lvl;
40         uint32_t                        page_cnt[PT_LVL_MAX];
41         uint64_t                        num_data_pages;
42         void                            *l0_addr;
43         uint64_t                        l0_dma_addr;
44         struct tf_em_page_tbl pg_tbl[PT_LVL_MAX];
45 };
46
47 struct tf_em_ctx_mem_info {
48         struct tf_em_table              em_tables[MAX_TABLE];
49 };
50
51 /** table scope control block content */
52 struct tf_em_caps {
53         uint32_t flags;
54         uint32_t supported;
55         uint32_t max_entries_supported;
56         uint16_t key_entry_size;
57         uint16_t record_entry_size;
58         uint16_t efc_entry_size;
59 };
60
61 /** Invalid table scope id */
62 #define TF_TBL_SCOPE_INVALID 0xffffffff
63
64 /**
65  * Table Scope Control Block
66  *
67  * Holds private data for a table scope. Only one instance of a table
68  * scope with Internal EM is supported.
69  */
70 struct tf_tbl_scope_cb {
71         uint32_t tbl_scope_id;
72         int index;
73         struct tf_em_ctx_mem_info  em_ctx_info[TF_DIR_MAX];
74         struct tf_em_caps          em_caps[TF_DIR_MAX];
75         struct stack               ext_act_pool[TF_DIR_MAX];
76         uint32_t                  *ext_act_pool_mem[TF_DIR_MAX];
77 };
78
79 /**
80  * Hardware Page sizes supported for EEM:
81  *   4K, 8K, 64K, 256K, 1M, 2M, 4M, 1G.
82  *
83  * Round-down other page sizes to the lower hardware page
84  * size supported.
85  */
86 #define TF_EM_PAGE_SIZE_4K 12
87 #define TF_EM_PAGE_SIZE_8K 13
88 #define TF_EM_PAGE_SIZE_64K 16
89 #define TF_EM_PAGE_SIZE_256K 18
90 #define TF_EM_PAGE_SIZE_1M 20
91 #define TF_EM_PAGE_SIZE_2M 21
92 #define TF_EM_PAGE_SIZE_4M 22
93 #define TF_EM_PAGE_SIZE_1G 30
94
95 /* Set page size */
96 #define BNXT_TF_PAGE_SIZE TF_EM_PAGE_SIZE_2M
97
98 #if (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4K)   /** 4K */
99 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4K
100 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4K
101 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_8K) /** 8K */
102 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_8K
103 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_8K
104 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_64K)        /** 64K */
105 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_64K
106 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_64K
107 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_256K)       /** 256K */
108 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_256K
109 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_256K
110 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1M) /** 1M */
111 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1M
112 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1M
113 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_2M) /** 2M */
114 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_2M
115 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_2M
116 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_4M) /** 4M */
117 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_4M
118 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_4M
119 #elif (BNXT_TF_PAGE_SIZE == TF_EM_PAGE_SIZE_1G) /** 1G */
120 #define TF_EM_PAGE_SHIFT TF_EM_PAGE_SIZE_1G
121 #define TF_EM_PAGE_SIZE_ENUM HWRM_TF_CTXT_MEM_RGTR_INPUT_PAGE_SIZE_1G
122 #else
123 #error "Invalid Page Size specified. Please use a TF_EM_PAGE_SIZE_n define"
124 #endif
125
126 #define TF_EM_PAGE_SIZE (1 << TF_EM_PAGE_SHIFT)
127 #define TF_EM_PAGE_ALIGNMENT (1 << TF_EM_PAGE_SHIFT)
128
129 /**
130  * Initialize table pool structure to indicate
131  * no table scope has been associated with the
132  * external pool of indexes.
133  *
134  * [in] session
135  */
136 void
137 tf_init_tbl_pool(struct tf_session *session);
138
139 #endif /* _TF_TBL_H_ */