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