net/bnxt: support runtime EM selection
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BNXT_ULP_H_
7 #define _BNXT_ULP_H_
8
9 #include <inttypes.h>
10 #include <stdbool.h>
11 #include <sys/queue.h>
12
13 #include "rte_ethdev.h"
14
15 #include "ulp_template_db_enum.h"
16
17 /* NAT defines to reuse existing inner L2 SMAC and DMAC */
18 #define BNXT_ULP_NAT_INNER_L2_HEADER_SMAC       0x2000
19 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC     0x6000
20 #define BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS    0xc00
21 #define BNXT_ULP_NAT_INNER_L2_HEADER_DMAC       0x100
22 #define BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC     0x300
23 #define BNXT_ULP_NAT_OUTER_MOST_FLAGS (BNXT_ULP_NAT_OUTER_MOST_L2_HDR_SMAC |\
24                                         BNXT_ULP_NAT_OUTER_MOST_L2_VLAN_TAGS |\
25                                         BNXT_ULP_NAT_OUTER_MOST_L2_HDR_DMAC)
26
27 /* defines for the ulp_flags */
28 #define BNXT_ULP_VF_REP_ENABLED         0x1
29 #define ULP_VF_REP_IS_ENABLED(flag)     ((flag) & BNXT_ULP_VF_REP_ENABLED)
30
31 struct bnxt_ulp_df_rule_info {
32         uint32_t                        port_to_app_flow_id;
33         uint32_t                        app_to_port_flow_id;
34         uint8_t                         valid;
35 };
36
37 struct bnxt_ulp_vfr_rule_info {
38         uint32_t                        rep2vf_flow_id;
39         uint32_t                        vf2rep_flow_id;
40         uint16_t                        parent_port_id;
41         uint8_t                         valid;
42 };
43
44 struct bnxt_ulp_data {
45         uint32_t                        tbl_scope_id;
46         struct bnxt_ulp_mark_tbl        *mark_tbl;
47         uint32_t                        dev_id; /* Hardware device id */
48         uint32_t                        ref_cnt;
49         struct bnxt_ulp_flow_db         *flow_db;
50         pthread_mutex_t                 flow_db_lock;
51         void                            *mapper_data;
52         struct bnxt_ulp_port_db         *port_db;
53         struct bnxt_ulp_fc_info         *fc_info;
54         uint32_t                        ulp_flags;
55         struct bnxt_ulp_df_rule_info    df_rule_info[RTE_MAX_ETHPORTS];
56         struct bnxt_ulp_vfr_rule_info   vfr_rule_info[RTE_MAX_ETHPORTS];
57         enum bnxt_ulp_flow_mem_type     mem_type;
58 };
59
60 struct bnxt_ulp_context {
61         struct bnxt_ulp_data    *cfg_data;
62         struct tf               *g_tfp;
63 };
64
65 struct bnxt_ulp_pci_info {
66         uint32_t        domain;
67         uint8_t         bus;
68 };
69
70 struct bnxt_ulp_session_state {
71         STAILQ_ENTRY(bnxt_ulp_session_state)    next;
72         bool                                    bnxt_ulp_init;
73         pthread_mutex_t                         bnxt_ulp_mutex;
74         struct bnxt_ulp_pci_info                pci_info;
75         struct bnxt_ulp_data                    *cfg_data;
76         struct tf                               *g_tfp;
77         uint32_t                                session_opened;
78 };
79
80 /* ULP flow id structure */
81 struct rte_tf_flow {
82         uint32_t        flow_id;
83 };
84
85 struct ulp_tlv_param {
86         enum bnxt_ulp_df_param_type type;
87         uint32_t length;
88         uint8_t value[16];
89 };
90
91 /*
92  * Allow the deletion of context only for the bnxt device that
93  * created the session
94  */
95 bool
96 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx);
97
98 /* Function to set the device id of the hardware. */
99 int32_t
100 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, uint32_t dev_id);
101
102 /* Function to get the device id of the hardware. */
103 int32_t
104 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, uint32_t *dev_id);
105
106 /* Function to get whether or not ext mem is used for EM */
107 int32_t
108 bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx,
109                             enum bnxt_ulp_flow_mem_type *mem_type);
110
111 /* Function to set whether or not ext mem is used for EM */
112 int32_t
113 bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx,
114                             enum bnxt_ulp_flow_mem_type mem_type);
115
116 /* Function to set the table scope id of the EEM table. */
117 int32_t
118 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
119                                 uint32_t tbl_scope_id);
120
121 /* Function to get the table scope id of the EEM table. */
122 int32_t
123 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
124                                 uint32_t *tbl_scope_id);
125
126 /* Function to set the tfp session details in the ulp context. */
127 int32_t
128 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
129
130 /* Function to get the tfp session details from ulp context. */
131 struct tf *
132 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp);
133
134 /* Get the device table entry based on the device id. */
135 struct bnxt_ulp_device_params *
136 bnxt_ulp_device_params_get(uint32_t dev_id);
137
138 int32_t
139 bnxt_ulp_ctxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
140                                struct bnxt_ulp_mark_tbl *mark_tbl);
141
142 struct bnxt_ulp_mark_tbl *
143 bnxt_ulp_ctxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx);
144
145 /* Function to set the flow database to the ulp context. */
146 int32_t
147 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
148                                 struct bnxt_ulp_flow_db *flow_db);
149
150 /* Function to get the flow database from the ulp context. */
151 struct bnxt_ulp_flow_db *
152 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx);
153
154 /* Function to get the ulp context from eth device. */
155 struct bnxt_ulp_context *
156 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev);
157
158 /* Function to add the ulp mapper data to the ulp context */
159 int32_t
160 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
161                                     void *mapper_data);
162
163 /* Function to get the ulp mapper data from the ulp context */
164 void *
165 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx);
166
167 /* Function to set the port database to the ulp context. */
168 int32_t
169 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
170                                 struct bnxt_ulp_port_db *port_db);
171
172 /* Function to get the port database from the ulp context. */
173 struct bnxt_ulp_port_db *
174 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx);
175
176 /* Function to create default flows. */
177 int32_t
178 ulp_default_flow_create(struct rte_eth_dev *eth_dev,
179                         struct ulp_tlv_param *param_list,
180                         uint32_t ulp_class_tid,
181                         uint32_t *flow_id);
182
183 /* Function to destroy default flows. */
184 int32_t
185 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev,
186                          uint32_t flow_id);
187
188 int
189 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
190                       struct rte_flow_error *error);
191
192 int32_t
193 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
194                                 struct bnxt_ulp_fc_info *ulp_fc_info);
195
196 struct bnxt_ulp_fc_info *
197 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx);
198
199 int32_t
200 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
201                                   uint32_t *flags);
202
203 int32_t
204 bnxt_ulp_get_df_rule_info(uint8_t port_id, struct bnxt_ulp_context *ulp_ctx,
205                           struct bnxt_ulp_df_rule_info *info);
206
207 struct bnxt_ulp_vfr_rule_info*
208 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
209                                      uint32_t port_id);
210
211 int32_t
212 bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
213
214 void
215 bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx);
216
217 #endif /* _BNXT_ULP_H_ */