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