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