net/bnxt: add CFA subdirectory of HCAPI
[dpdk.git] / drivers / net / bnxt / hcapi / cfa / hcapi_cfa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _HCAPI_CFA_H_
7 #define _HCAPI_CFA_H_
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdbool.h>
12 #include <stdint.h>
13 #include <stddef.h>
14
15 #include "hcapi_cfa_defs.h"
16
17 /**
18  * Index used for the sram_entries field
19  */
20 enum hcapi_cfa_resc_type_sram {
21         HCAPI_CFA_RESC_TYPE_SRAM_FULL_ACTION,
22         HCAPI_CFA_RESC_TYPE_SRAM_MCG,
23         HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_8B,
24         HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_16B,
25         HCAPI_CFA_RESC_TYPE_SRAM_ENCAP_64B,
26         HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC,
27         HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV4,
28         HCAPI_CFA_RESC_TYPE_SRAM_SP_SMAC_IPV6,
29         HCAPI_CFA_RESC_TYPE_SRAM_COUNTER_64B,
30         HCAPI_CFA_RESC_TYPE_SRAM_NAT_SPORT,
31         HCAPI_CFA_RESC_TYPE_SRAM_NAT_DPORT,
32         HCAPI_CFA_RESC_TYPE_SRAM_NAT_S_IPV4,
33         HCAPI_CFA_RESC_TYPE_SRAM_NAT_D_IPV4,
34         HCAPI_CFA_RESC_TYPE_SRAM_MAX
35 };
36
37 /**
38  * Index used for the hw_entries field in struct cfa_rm_db
39  */
40 enum hcapi_cfa_resc_type_hw {
41         /* common HW resources for all chip variants */
42         HCAPI_CFA_RESC_TYPE_HW_L2_CTXT_TCAM,
43         HCAPI_CFA_RESC_TYPE_HW_PROF_FUNC,
44         HCAPI_CFA_RESC_TYPE_HW_PROF_TCAM,
45         HCAPI_CFA_RESC_TYPE_HW_EM_PROF_ID,
46         HCAPI_CFA_RESC_TYPE_HW_EM_REC,
47         HCAPI_CFA_RESC_TYPE_HW_WC_TCAM_PROF_ID,
48         HCAPI_CFA_RESC_TYPE_HW_WC_TCAM,
49         HCAPI_CFA_RESC_TYPE_HW_METER_PROF,
50         HCAPI_CFA_RESC_TYPE_HW_METER_INST,
51         HCAPI_CFA_RESC_TYPE_HW_MIRROR,
52         HCAPI_CFA_RESC_TYPE_HW_UPAR,
53         /* Wh+/SR specific HW resources */
54         HCAPI_CFA_RESC_TYPE_HW_SP_TCAM,
55         /* Thor, SR2 common HW resources */
56         HCAPI_CFA_RESC_TYPE_HW_FKB,
57         /* SR specific HW resources */
58         HCAPI_CFA_RESC_TYPE_HW_TBL_SCOPE,
59         HCAPI_CFA_RESC_TYPE_HW_L2_FUNC,
60         HCAPI_CFA_RESC_TYPE_HW_EPOCH0,
61         HCAPI_CFA_RESC_TYPE_HW_EPOCH1,
62         HCAPI_CFA_RESC_TYPE_HW_METADATA,
63         HCAPI_CFA_RESC_TYPE_HW_CT_STATE,
64         HCAPI_CFA_RESC_TYPE_HW_RANGE_PROF,
65         HCAPI_CFA_RESC_TYPE_HW_RANGE_ENTRY,
66         HCAPI_CFA_RESC_TYPE_HW_LAG_ENTRY,
67         HCAPI_CFA_RESC_TYPE_HW_MAX
68 };
69
70 struct hcapi_cfa_key_result {
71         uint64_t bucket_mem_ptr;
72         uint8_t bucket_idx;
73 };
74
75 /* common CFA register access macros */
76 #define CFA_REG(x)              OFFSETOF(cfa_reg_t, cfa_##x)
77
78 #ifndef TF_REG_WR
79 #define TF_REG_WR(_p, x, y)  (*((uint32_t volatile *)(x)) = (y))
80 #endif
81 #ifndef TF_REG_RD
82 #define TF_REG_RD(_p, x)  (*((uint32_t volatile *)(x)))
83 #endif
84 #ifndef TF_CFA_REG_RD
85 #define TF_CFA_REG_RD(_p, x)    \
86         TF_REG_RD(0, (uint32_t)(_p)->base_addr + CFA_REG(x))
87 #endif
88 #ifndef TF_CFA_REG_WR
89 #define TF_CFA_REG_WR(_p, x, y) \
90         TF_REG_WR(0, (uint32_t)(_p)->base_addr + CFA_REG(x), y)
91 #endif
92
93 /* Constants used by Resource Manager Registration*/
94 #define RM_CLIENT_NAME_MAX_LEN          32
95
96 /**
97  *  Resource Manager Data Structures used for resource requests
98  */
99 struct hcapi_cfa_resc_req_entry {
100         uint16_t min;
101         uint16_t max;
102 };
103
104 struct hcapi_cfa_resc_req {
105         /* Wh+/SR specific onchip Action SRAM resources */
106         /* Validity of each sram type is indicated by the
107          * corresponding sram type bit in the sram_resc_flags. When
108          * set to 1, the CFA sram resource type is valid and amount of
109          * resources for this type is reserved. Each sram resource
110          * pool is identified by the starting index and number of
111          * resources in the pool.
112          */
113         uint32_t sram_resc_flags;
114         struct hcapi_cfa_resc_req_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
115
116         /* Validity of each resource type is indicated by the
117          * corresponding resource type bit in the hw_resc_flags. When
118          * set to 1, the CFA resource type is valid and amount of
119          * resource of this type is reserved. Each resource pool is
120          * identified by the starting index and the number of
121          * resources in the pool.
122          */
123         uint32_t hw_resc_flags;
124         struct hcapi_cfa_resc_req_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
125 };
126
127 struct hcapi_cfa_resc_req_db {
128         struct hcapi_cfa_resc_req rx;
129         struct hcapi_cfa_resc_req tx;
130 };
131
132 struct hcapi_cfa_resc_entry {
133         uint16_t start;
134         uint16_t stride;
135         uint16_t tag;
136 };
137
138 struct hcapi_cfa_resc {
139         /* Wh+/SR specific onchip Action SRAM resources */
140         /* Validity of each sram type is indicated by the
141          * corresponding sram type bit in the sram_resc_flags. When
142          * set to 1, the CFA sram resource type is valid and amount of
143          * resources for this type is reserved. Each sram resource
144          * pool is identified by the starting index and number of
145          * resources in the pool.
146          */
147         uint32_t sram_resc_flags;
148         struct hcapi_cfa_resc_entry sram_resc[HCAPI_CFA_RESC_TYPE_SRAM_MAX];
149
150         /* Validity of each resource type is indicated by the
151          * corresponding resource type bit in the hw_resc_flags. When
152          * set to 1, the CFA resource type is valid and amount of
153          * resource of this type is reserved. Each resource pool is
154          * identified by the starting index and the number of resources
155          * in the pool.
156          */
157         uint32_t hw_resc_flags;
158         struct hcapi_cfa_resc_entry hw_resc[HCAPI_CFA_RESC_TYPE_HW_MAX];
159 };
160
161 struct hcapi_cfa_resc_db {
162         struct hcapi_cfa_resc rx;
163         struct hcapi_cfa_resc tx;
164 };
165
166 /**
167  * This is the main data structure used by the CFA Resource
168  * Manager.  This data structure holds all the state and table
169  * management information.
170  */
171 typedef struct hcapi_cfa_rm_data {
172         uint32_t dummy_data;
173 } hcapi_cfa_rm_data_t;
174
175 /* End RM support */
176
177 struct hcapi_cfa_devops;
178
179 struct hcapi_cfa_devinfo {
180         uint8_t global_cfg_data[CFA_GLOBAL_CFG_DATA_SZ];
181         struct hcapi_cfa_layout_tbl layouts;
182         struct hcapi_cfa_devops *devops;
183 };
184
185 int hcapi_cfa_dev_bind(enum hcapi_cfa_ver hw_ver,
186                        struct hcapi_cfa_devinfo *dev_info);
187
188 int hcapi_cfa_key_compile_layout(struct hcapi_cfa_key_template *key_template,
189                                  struct hcapi_cfa_key_layout *key_layout);
190 uint64_t hcapi_cfa_key_hash(uint64_t *key_data, uint16_t bitlen);
191 int
192 hcapi_cfa_action_compile_layout(struct hcapi_cfa_action_template *act_template,
193                                 struct hcapi_cfa_action_layout *act_layout);
194 int hcapi_cfa_action_init_obj(uint64_t *act_obj,
195                               struct hcapi_cfa_action_layout *act_layout);
196 int hcapi_cfa_action_compute_ptr(uint64_t *act_obj,
197                                  struct hcapi_cfa_action_layout *act_layout,
198                                  uint32_t base_ptr);
199
200 int hcapi_cfa_action_hw_op(struct hcapi_cfa_hwop *op,
201                            uint8_t *act_tbl,
202                            struct hcapi_cfa_data *act_obj);
203 int hcapi_cfa_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
204                         struct hcapi_cfa_data *obj_data);
205 int hcapi_cfa_rm_register_client(hcapi_cfa_rm_data_t *data,
206                                  const char *client_name,
207                                  int *client_id);
208 int hcapi_cfa_rm_unregister_client(hcapi_cfa_rm_data_t *data,
209                                    int client_id);
210 int hcapi_cfa_rm_query_resources(hcapi_cfa_rm_data_t *data,
211                                  int client_id,
212                                  uint16_t chnl_id,
213                                  struct hcapi_cfa_resc_req_db *req_db);
214 int hcapi_cfa_rm_query_resources_one(hcapi_cfa_rm_data_t *data,
215                                      int clien_id,
216                                      struct hcapi_cfa_resc_db *resc_db);
217 int hcapi_cfa_rm_reserve_resources(hcapi_cfa_rm_data_t *data,
218                                    int client_id,
219                                    struct hcapi_cfa_resc_req_db *resc_req,
220                                    struct hcapi_cfa_resc_db *resc_db);
221 int hcapi_cfa_rm_release_resources(hcapi_cfa_rm_data_t *data,
222                                    int client_id,
223                                    struct hcapi_cfa_resc_req_db *resc_req,
224                                    struct hcapi_cfa_resc_db *resc_db);
225 int hcapi_cfa_rm_initialize(hcapi_cfa_rm_data_t *data);
226
227 #if SUPPORT_CFA_HW_P4
228
229 int hcapi_cfa_p4_dev_hw_op(struct hcapi_cfa_hwop *op, uint16_t tbl_id,
230                             struct hcapi_cfa_data *obj_data);
231 int hcapi_cfa_p4_prof_l2ctxt_hwop(struct hcapi_cfa_hwop *op,
232                                    struct hcapi_cfa_data *obj_data);
233 int hcapi_cfa_p4_prof_l2ctxtrmp_hwop(struct hcapi_cfa_hwop *op,
234                                       struct hcapi_cfa_data *obj_data);
235 int hcapi_cfa_p4_prof_tcam_hwop(struct hcapi_cfa_hwop *op,
236                                  struct hcapi_cfa_data *obj_data);
237 int hcapi_cfa_p4_prof_tcamrmp_hwop(struct hcapi_cfa_hwop *op,
238                                     struct hcapi_cfa_data *obj_data);
239 int hcapi_cfa_p4_wc_tcam_hwop(struct hcapi_cfa_hwop *op,
240                                struct hcapi_cfa_data *obj_data);
241 int hcapi_cfa_p4_wc_tcam_rec_hwop(struct hcapi_cfa_hwop *op,
242                                    struct hcapi_cfa_data *obj_data);
243 int hcapi_cfa_p4_mirror_hwop(struct hcapi_cfa_hwop *op,
244                              struct hcapi_cfa_data *mirror);
245 int hcapi_cfa_p4_global_cfg_hwop(struct hcapi_cfa_hwop *op,
246                                  uint32_t type,
247                                  struct hcapi_cfa_data *config);
248 /* SUPPORT_CFA_HW_P4 */
249 #elif SUPPORT_CFA_HW_P45
250 int hcapi_cfa_p45_mirror_hwop(struct hcapi_cfa_hwop *op,
251                               struct hcapi_cfa_data *mirror);
252 int hcapi_cfa_p45_global_cfg_hwop(struct hcapi_cfa_hwop *op,
253                                   uint32_t type,
254                                   struct hcapi_cfa_data *config);
255 /* SUPPORT_CFA_HW_P45 */
256 #endif
257 /**
258  *  HCAPI CFA device HW operation function callback definition
259  *  This is standardized function callback hook to install different
260  *  CFA HW table programming function callback.
261  */
262
263 struct hcapi_cfa_tbl_cb {
264         /**
265          * This function callback provides the functionality to read/write
266          * HW table entry from a HW table.
267          *
268          * @param[in] op
269          *   A pointer to the Hardware operation parameter
270          *
271          * @param[in] obj_data
272          *   A pointer to the HW data object for the hardware operation
273          *
274          * @return
275          *   0 for SUCCESS, negative value for FAILURE
276          */
277         int (*hwop_cb)(struct hcapi_cfa_hwop *op,
278                        struct hcapi_cfa_data *obj_data);
279 };
280
281 #endif  /* HCAPI_CFA_H_ */