9d0e613fc8086b85b128c1df77a29989908ca764
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_port_db.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _ULP_PORT_DB_H_
7 #define _ULP_PORT_DB_H_
8
9 #include "bnxt_ulp.h"
10
11 #define BNXT_PORT_DB_MAX_INTF_LIST              256
12 #define BNXT_PORT_DB_MAX_FUNC                   2048
13 #define BNXT_ULP_FREE_PARIF_BASE                11
14
15 enum bnxt_ulp_svif_type {
16         BNXT_ULP_DRV_FUNC_SVIF = 0,
17         BNXT_ULP_VF_FUNC_SVIF,
18         BNXT_ULP_PHY_PORT_SVIF
19 };
20
21 enum bnxt_ulp_spif_type {
22         BNXT_ULP_DRV_FUNC_SPIF = 0,
23         BNXT_ULP_VF_FUNC_SPIF,
24         BNXT_ULP_PHY_PORT_SPIF
25 };
26
27 enum bnxt_ulp_parif_type {
28         BNXT_ULP_DRV_FUNC_PARIF = 0,
29         BNXT_ULP_VF_FUNC_PARIF,
30         BNXT_ULP_PHY_PORT_PARIF
31 };
32
33 enum bnxt_ulp_vnic_type {
34         BNXT_ULP_DRV_FUNC_VNIC = 0,
35         BNXT_ULP_VF_FUNC_VNIC
36 };
37
38 enum bnxt_ulp_fid_type {
39         BNXT_ULP_DRV_FUNC_FID,
40         BNXT_ULP_VF_FUNC_FID
41 };
42
43 struct ulp_func_if_info {
44         uint16_t                func_valid;
45         uint16_t                func_svif;
46         uint16_t                func_spif;
47         uint16_t                func_parif;
48         uint16_t                func_vnic;
49         uint8_t                 func_mac[RTE_ETHER_ADDR_LEN];
50         uint16_t                func_parent_vnic;
51         uint8_t                 func_parent_mac[RTE_ETHER_ADDR_LEN];
52         uint16_t                phy_port_id;
53         uint16_t                ifindex;
54 };
55
56 /* Structure for the Port database resource information. */
57 struct ulp_interface_info {
58         enum bnxt_ulp_intf_type type;
59         uint16_t                drv_func_id;
60         uint16_t                vf_func_id;
61 };
62
63 struct ulp_phy_port_info {
64         uint16_t        port_valid;
65         uint16_t        port_svif;
66         uint16_t        port_spif;
67         uint16_t        port_parif;
68         uint16_t        port_vport;
69 };
70
71 /* Structure for the Port database */
72 struct bnxt_ulp_port_db {
73         struct ulp_interface_info       *ulp_intf_list;
74         uint32_t                        ulp_intf_list_size;
75
76         /* dpdk device external port list */
77         uint16_t                        dev_port_list[RTE_MAX_ETHPORTS];
78         struct ulp_phy_port_info        *phy_port_list;
79         uint16_t                        phy_port_cnt;
80         struct ulp_func_if_info         ulp_func_id_tbl[BNXT_PORT_DB_MAX_FUNC];
81 };
82
83 /*
84  * Initialize the port database. Memory is allocated in this
85  * call and assigned to the port database.
86  *
87  * ulp_ctxt [in] Ptr to ulp context
88  *
89  * Returns 0 on success or negative number on failure.
90  */
91 int32_t ulp_port_db_init(struct bnxt_ulp_context *ulp_ctxt, uint8_t port_cnt);
92
93 /*
94  * Deinitialize the port database. Memory is deallocated in
95  * this call.
96  *
97  * ulp_ctxt [in] Ptr to ulp context
98  *
99  * Returns 0 on success.
100  */
101 int32_t ulp_port_db_deinit(struct bnxt_ulp_context *ulp_ctxt);
102
103 /*
104  * Update the port database.This api is called when the port
105  * details are available during the startup.
106  *
107  * ulp_ctxt [in] Ptr to ulp context
108  * bp [in]. ptr to the device function.
109  *
110  * Returns 0 on success or negative number on failure.
111  */
112 int32_t ulp_port_db_dev_port_intf_update(struct bnxt_ulp_context *ulp_ctxt,
113                                          struct rte_eth_dev *eth_dev);
114
115 /*
116  * Api to get the ulp ifindex for a given device port.
117  *
118  * ulp_ctxt [in] Ptr to ulp context
119  * port_id [in].device port id
120  * ifindex [out] ulp ifindex
121  *
122  * Returns 0 on success or negative number on failure.
123  */
124 int32_t
125 ulp_port_db_dev_port_to_ulp_index(struct bnxt_ulp_context *ulp_ctxt,
126                                   uint32_t port_id, uint32_t *ifindex);
127
128 /*
129  * Api to get the function id for a given ulp ifindex.
130  *
131  * ulp_ctxt [in] Ptr to ulp context
132  * ifindex [in] ulp ifindex
133  * func_id [out] the function id of the given ifindex.
134  *
135  * Returns 0 on success or negative number on failure.
136  */
137 int32_t
138 ulp_port_db_function_id_get(struct bnxt_ulp_context *ulp_ctxt,
139                             uint32_t ifindex, uint32_t fid_type,
140                             uint16_t *func_id);
141
142 /*
143  * Api to get the svif for a given ulp ifindex.
144  *
145  * ulp_ctxt [in] Ptr to ulp context
146  * ifindex [in] ulp ifindex
147  * dir [in] the direction for the flow.
148  * svif [out] the svif of the given ifindex.
149  *
150  * Returns 0 on success or negative number on failure.
151  */
152 int32_t
153 ulp_port_db_svif_get(struct bnxt_ulp_context *ulp_ctxt,
154                      uint32_t ifindex, uint32_t dir, uint16_t *svif);
155
156 /*
157  * Api to get the spif for a given ulp ifindex.
158  *
159  * ulp_ctxt [in] Ptr to ulp context
160  * ifindex [in] ulp ifindex
161  * dir [in] the direction for the flow.
162  * spif [out] the spif of the given ifindex.
163  *
164  * Returns 0 on success or negative number on failure.
165  */
166 int32_t
167 ulp_port_db_spif_get(struct bnxt_ulp_context *ulp_ctxt,
168                      uint32_t ifindex, uint32_t dir, uint16_t *spif);
169
170
171 /*
172  * Api to get the parif for a given ulp ifindex.
173  *
174  * ulp_ctxt [in] Ptr to ulp context
175  * ifindex [in] ulp ifindex
176  * dir [in] the direction for the flow.
177  * parif [out] the parif of the given ifindex.
178  *
179  * Returns 0 on success or negative number on failure.
180  */
181 int32_t
182 ulp_port_db_parif_get(struct bnxt_ulp_context *ulp_ctxt,
183                       uint32_t ifindex, uint32_t dir, uint16_t *parif);
184
185 /*
186  * Api to get the vnic id for a given ulp ifindex.
187  *
188  * ulp_ctxt [in] Ptr to ulp context
189  * ifindex [in] ulp ifindex
190  * vnic [out] the vnic of the given ifindex.
191  *
192  * Returns 0 on success or negative number on failure.
193  */
194 int32_t
195 ulp_port_db_default_vnic_get(struct bnxt_ulp_context *ulp_ctxt,
196                              uint32_t ifindex, uint32_t vnic_type,
197                              uint16_t *vnic);
198
199 /*
200  * Api to get the vport id for a given ulp ifindex.
201  *
202  * ulp_ctxt [in] Ptr to ulp context
203  * ifindex [in] ulp ifindex
204  * vport [out] the port of the given ifindex.
205  *
206  * Returns 0 on success or negative number on failure.
207  */
208 int32_t
209 ulp_port_db_vport_get(struct bnxt_ulp_context *ulp_ctxt,
210                       uint32_t ifindex, uint16_t *vport);
211
212 /*
213  * Api to get the vport for a given physical port.
214  *
215  * ulp_ctxt [in] Ptr to ulp context
216  * phy_port [in] physical port index
217  * out_port [out] the port of the given physical index
218  *
219  * Returns 0 on success or negative number on failure.
220  */
221 int32_t
222 ulp_port_db_phy_port_vport_get(struct bnxt_ulp_context *ulp_ctxt,
223                                uint32_t phy_port,
224                                uint16_t *out_port);
225
226 /*
227  * Api to get the svif for a given physical port.
228  *
229  * ulp_ctxt [in] Ptr to ulp context
230  * phy_port [in] physical port index
231  * svif [out] the svif of the given physical index
232  *
233  * Returns 0 on success or negative number on failure.
234  */
235 int32_t
236 ulp_port_db_phy_port_svif_get(struct bnxt_ulp_context *ulp_ctxt,
237                               uint32_t phy_port,
238                               uint16_t *svif);
239
240 /*
241  * Api to get the port type for a given ulp ifindex.
242  *
243  * ulp_ctxt [in] Ptr to ulp context
244  * ifindex [in] ulp ifindex
245  *
246  * Returns port type.
247  */
248 enum bnxt_ulp_intf_type
249 ulp_port_db_port_type_get(struct bnxt_ulp_context *ulp_ctxt,
250                           uint32_t ifindex);
251
252 /*
253  * Api to get the ulp ifindex for a given function id.
254  *
255  * ulp_ctxt [in] Ptr to ulp context
256  * func_id [in].device func id
257  * ifindex [out] ulp ifindex
258  *
259  * Returns 0 on success or negative number on failure.
260  */
261 int32_t
262 ulp_port_db_dev_func_id_to_ulp_index(struct bnxt_ulp_context *ulp_ctxt,
263                                      uint32_t func_id, uint32_t *ifindex);
264
265 /*
266  * Api to get the function id for a given port id.
267  *
268  * ulp_ctxt [in] Ptr to ulp context
269  * port_id [in] dpdk port id
270  * func_id [out] the function id of the given ifindex.
271  *
272  * Returns 0 on success or negative number on failure.
273  */
274 int32_t
275 ulp_port_db_port_func_id_get(struct bnxt_ulp_context *ulp_ctxt,
276                              uint16_t port_id, uint16_t *func_id);
277
278 /*
279  * Api to get the parent mac address for a given port id.
280  *
281  * ulp_ctxt [in] Ptr to ulp context
282  * port_id [in].device port id
283  * mac_addr [out] mac address
284  *
285  * Returns 0 on success or negative number on failure.
286  */
287 int32_t
288 ulp_port_db_parent_mac_addr_get(struct bnxt_ulp_context *ulp_ctxt,
289                                 uint32_t port_id, uint8_t **mac_addr);
290 #endif /* _ULP_PORT_DB_H_ */