net/bnxt: enable NAT action with tagged traffic
[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         void                            *mapper_data;
51         struct bnxt_ulp_port_db         *port_db;
52         struct bnxt_ulp_fc_info         *fc_info;
53         uint32_t                        ulp_flags;
54         struct bnxt_ulp_df_rule_info    df_rule_info[RTE_MAX_ETHPORTS];
55         struct bnxt_ulp_vfr_rule_info   vfr_rule_info[RTE_MAX_ETHPORTS];
56 };
57
58 struct bnxt_ulp_context {
59         struct bnxt_ulp_data    *cfg_data;
60         struct tf               *g_tfp;
61 };
62
63 struct bnxt_ulp_pci_info {
64         uint32_t        domain;
65         uint8_t         bus;
66 };
67
68 struct bnxt_ulp_session_state {
69         STAILQ_ENTRY(bnxt_ulp_session_state)    next;
70         bool                                    bnxt_ulp_init;
71         pthread_mutex_t                         bnxt_ulp_mutex;
72         struct bnxt_ulp_pci_info                pci_info;
73         struct bnxt_ulp_data                    *cfg_data;
74         struct tf                               *g_tfp;
75         uint32_t                                session_opened;
76 };
77
78 /* ULP flow id structure */
79 struct rte_tf_flow {
80         uint32_t        flow_id;
81 };
82
83 struct ulp_tlv_param {
84         enum bnxt_ulp_df_param_type type;
85         uint32_t length;
86         uint8_t value[16];
87 };
88
89 /*
90  * Allow the deletion of context only for the bnxt device that
91  * created the session
92  */
93 bool
94 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx);
95
96 /* Function to set the device id of the hardware. */
97 int32_t
98 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, uint32_t dev_id);
99
100 /* Function to get the device id of the hardware. */
101 int32_t
102 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, uint32_t *dev_id);
103
104 /* Function to set the table scope id of the EEM table. */
105 int32_t
106 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
107                                 uint32_t tbl_scope_id);
108
109 /* Function to get the table scope id of the EEM table. */
110 int32_t
111 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
112                                 uint32_t *tbl_scope_id);
113
114 /* Function to set the tfp session details in the ulp context. */
115 int32_t
116 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
117
118 /* Function to get the tfp session details from ulp context. */
119 struct tf *
120 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp);
121
122 /* Get the device table entry based on the device id. */
123 struct bnxt_ulp_device_params *
124 bnxt_ulp_device_params_get(uint32_t dev_id);
125
126 int32_t
127 bnxt_ulp_ctxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
128                                struct bnxt_ulp_mark_tbl *mark_tbl);
129
130 struct bnxt_ulp_mark_tbl *
131 bnxt_ulp_ctxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx);
132
133 /* Function to set the flow database to the ulp context. */
134 int32_t
135 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
136                                 struct bnxt_ulp_flow_db *flow_db);
137
138 /* Function to get the flow database from the ulp context. */
139 struct bnxt_ulp_flow_db *
140 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx);
141
142 /* Function to get the ulp context from eth device. */
143 struct bnxt_ulp_context *
144 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev);
145
146 /* Function to add the ulp mapper data to the ulp context */
147 int32_t
148 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
149                                     void *mapper_data);
150
151 /* Function to get the ulp mapper data from the ulp context */
152 void *
153 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx);
154
155 /* Function to set the port database to the ulp context. */
156 int32_t
157 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
158                                 struct bnxt_ulp_port_db *port_db);
159
160 /* Function to get the port database from the ulp context. */
161 struct bnxt_ulp_port_db *
162 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx);
163
164 /* Function to create default flows. */
165 int32_t
166 ulp_default_flow_create(struct rte_eth_dev *eth_dev,
167                         struct ulp_tlv_param *param_list,
168                         uint32_t ulp_class_tid,
169                         uint32_t *flow_id);
170
171 /* Function to destroy default flows. */
172 int32_t
173 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev,
174                          uint32_t flow_id);
175
176 int
177 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
178                       struct rte_flow_error *error);
179
180 int32_t
181 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
182                                 struct bnxt_ulp_fc_info *ulp_fc_info);
183
184 struct bnxt_ulp_fc_info *
185 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx);
186
187 int32_t
188 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
189                                   uint32_t *flags);
190
191 int32_t
192 bnxt_ulp_get_df_rule_info(uint8_t port_id, struct bnxt_ulp_context *ulp_ctx,
193                           struct bnxt_ulp_df_rule_info *info);
194
195 struct bnxt_ulp_vfr_rule_info*
196 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
197                                      uint32_t port_id);
198
199 #endif /* _BNXT_ULP_H_ */