Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2014-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <rte_malloc.h>
7 : : #include "bnxt.h"
8 : : #include "bnxt_vnic.h"
9 : : #include "bnxt_tf_common.h"
10 : : #include "bnxt_tf_pmd_shim.h"
11 : : #include "ulp_port_db.h"
12 : : #include "tfp.h"
13 : :
14 : : static uint32_t
15 : 0 : ulp_port_db_allocate_ifindex(struct bnxt_ulp_port_db *port_db)
16 : : {
17 : : uint32_t idx = 1;
18 : :
19 [ # # ]: 0 : while (idx < port_db->ulp_intf_list_size &&
20 [ # # ]: 0 : port_db->ulp_intf_list[idx].type != BNXT_ULP_INTF_TYPE_INVALID)
21 : 0 : idx++;
22 : :
23 [ # # ]: 0 : if (idx >= port_db->ulp_intf_list_size) {
24 : 0 : BNXT_TF_DBG(ERR, "Port DB interface list is full\n");
25 : 0 : return 0;
26 : : }
27 : : return idx;
28 : : }
29 : :
30 : : /*
31 : : * Initialize the port database. Memory is allocated in this
32 : : * call and assigned to the port database.
33 : : *
34 : : * ulp_ctxt [in] Ptr to ulp context
35 : : *
36 : : * Returns 0 on success or negative number on failure.
37 : : */
38 : 0 : int32_t ulp_port_db_init(struct bnxt_ulp_context *ulp_ctxt, uint8_t port_cnt)
39 : : {
40 : : struct bnxt_ulp_port_db *port_db;
41 : :
42 : 0 : port_db = rte_zmalloc("bnxt_ulp_port_db",
43 : : sizeof(struct bnxt_ulp_port_db), 0);
44 [ # # ]: 0 : if (!port_db) {
45 : 0 : BNXT_TF_DBG(ERR,
46 : : "Failed to allocate memory for port db\n");
47 : 0 : return -ENOMEM;
48 : : }
49 : :
50 : : /* Attach the port database to the ulp context. */
51 : 0 : bnxt_ulp_cntxt_ptr2_port_db_set(ulp_ctxt, port_db);
52 : :
53 : : /* index 0 is not being used hence add 1 to size */
54 : 0 : port_db->ulp_intf_list_size = BNXT_PORT_DB_MAX_INTF_LIST + 1;
55 : : /* Allocate the port tables */
56 : 0 : port_db->ulp_intf_list = rte_zmalloc("bnxt_ulp_port_db_intf_list",
57 : : port_db->ulp_intf_list_size *
58 : : sizeof(struct ulp_interface_info),
59 : : 0);
60 [ # # ]: 0 : if (!port_db->ulp_intf_list) {
61 : 0 : BNXT_TF_DBG(ERR,
62 : : "Failed to allocate mem for port interface list\n");
63 : 0 : goto error_free;
64 : : }
65 : :
66 : : /* Allocate the phy port list */
67 : 0 : port_db->phy_port_list = rte_zmalloc("bnxt_ulp_phy_port_list",
68 : : port_cnt *
69 : : sizeof(struct ulp_phy_port_info),
70 : : 0);
71 [ # # ]: 0 : if (!port_db->phy_port_list) {
72 : 0 : BNXT_TF_DBG(ERR,
73 : : "Failed to allocate mem for phy port list\n");
74 : 0 : goto error_free;
75 : : }
76 : 0 : port_db->phy_port_cnt = port_cnt;
77 : 0 : return 0;
78 : :
79 : 0 : error_free:
80 : 0 : ulp_port_db_deinit(ulp_ctxt);
81 : 0 : return -ENOMEM;
82 : : }
83 : :
84 : : /*
85 : : * Deinitialize the port database. Memory is deallocated in
86 : : * this call.
87 : : *
88 : : * ulp_ctxt [in] Ptr to ulp context
89 : : *
90 : : * Returns 0 on success.
91 : : */
92 : 0 : int32_t ulp_port_db_deinit(struct bnxt_ulp_context *ulp_ctxt)
93 : : {
94 : : struct bnxt_ulp_port_db *port_db;
95 : :
96 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
97 [ # # ]: 0 : if (!port_db) {
98 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
99 : 0 : return -EINVAL;
100 : : }
101 : :
102 : : /* Detach the flow database from the ulp context. */
103 : 0 : bnxt_ulp_cntxt_ptr2_port_db_set(ulp_ctxt, NULL);
104 : :
105 : : /* Free up all the memory. */
106 : 0 : rte_free(port_db->phy_port_list);
107 : 0 : rte_free(port_db->ulp_intf_list);
108 : 0 : rte_free(port_db);
109 : 0 : return 0;
110 : : }
111 : :
112 : : /*
113 : : * Update the port database.This api is called when the port
114 : : * details are available during the startup.
115 : : *
116 : : * ulp_ctxt [in] Ptr to ulp context
117 : : * bp [in]. ptr to the device function.
118 : : *
119 : : * Returns 0 on success or negative number on failure.
120 : : */
121 : 0 : int32_t ulp_port_db_port_update(struct bnxt_ulp_context *ulp_ctxt,
122 : : struct rte_eth_dev *eth_dev)
123 : : {
124 : 0 : uint32_t port_id = eth_dev->data->port_id;
125 : : struct ulp_phy_port_info *port_data;
126 : : struct bnxt_ulp_port_db *port_db;
127 : : struct ulp_interface_info *intf;
128 : : struct ulp_func_if_info *func;
129 : : uint32_t ifindex;
130 : : int32_t rc;
131 : :
132 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
133 [ # # ]: 0 : if (!port_db) {
134 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
135 : 0 : return -EINVAL;
136 : : }
137 : :
138 : 0 : rc = ulp_port_db_dev_port_to_ulp_index(ulp_ctxt, port_id, &ifindex);
139 [ # # ]: 0 : if (rc == -ENOENT) {
140 : : /* port not found, allocate one */
141 : 0 : ifindex = ulp_port_db_allocate_ifindex(port_db);
142 [ # # ]: 0 : if (!ifindex)
143 : : return -ENOMEM;
144 : 0 : port_db->dev_port_list[port_id] = ifindex;
145 [ # # ]: 0 : } else if (rc == -EINVAL) {
146 : : return -EINVAL;
147 : : }
148 : :
149 : : /* update the interface details */
150 : 0 : intf = &port_db->ulp_intf_list[ifindex];
151 : :
152 : 0 : intf->type = bnxt_pmd_get_interface_type(port_id);
153 [ # # ]: 0 : if (intf->type == BNXT_ULP_INTF_TYPE_PF)
154 : 0 : intf->type_is_pf = 1;
155 : : else
156 : 0 : intf->type_is_pf = 0;
157 : :
158 : 0 : intf->drv_func_id = bnxt_pmd_get_fw_func_id(port_id,
159 : : BNXT_ULP_INTF_TYPE_INVALID);
160 : :
161 : 0 : func = &port_db->ulp_func_id_tbl[intf->drv_func_id];
162 [ # # ]: 0 : if (!func->func_valid) {
163 : 0 : func->func_svif = bnxt_pmd_get_svif(port_id, true,
164 : : BNXT_ULP_INTF_TYPE_INVALID);
165 : 0 : func->func_spif = bnxt_pmd_get_phy_port_id(port_id);
166 : 0 : func->func_parif =
167 : 0 : bnxt_pmd_get_parif(port_id, BNXT_ULP_INTF_TYPE_INVALID);
168 : 0 : func->func_vnic =
169 : 0 : bnxt_pmd_get_vnic_id(port_id, BNXT_ULP_INTF_TYPE_INVALID);
170 : 0 : func->phy_port_id = bnxt_pmd_get_phy_port_id(port_id);
171 : 0 : func->func_valid = true;
172 : 0 : func->ifindex = ifindex;
173 : : }
174 : :
175 [ # # ]: 0 : if (intf->type == BNXT_ULP_INTF_TYPE_VF_REP) {
176 : 0 : intf->vf_func_id =
177 : 0 : bnxt_pmd_get_fw_func_id(port_id, BNXT_ULP_INTF_TYPE_VF_REP);
178 : :
179 : 0 : func = &port_db->ulp_func_id_tbl[intf->vf_func_id];
180 : 0 : func->func_svif =
181 : 0 : bnxt_pmd_get_svif(port_id, true, BNXT_ULP_INTF_TYPE_VF_REP);
182 : 0 : func->func_spif =
183 : 0 : bnxt_pmd_get_phy_port_id(port_id);
184 : 0 : func->func_parif =
185 : 0 : bnxt_pmd_get_parif(port_id, BNXT_ULP_INTF_TYPE_INVALID);
186 : 0 : func->func_vnic =
187 : 0 : bnxt_pmd_get_vnic_id(port_id, BNXT_ULP_INTF_TYPE_VF_REP);
188 : 0 : func->phy_port_id = bnxt_pmd_get_phy_port_id(port_id);
189 : 0 : func->ifindex = ifindex;
190 : 0 : func->func_valid = true;
191 [ # # ]: 0 : func->vf_meta_data = tfp_cpu_to_be_16(BNXT_ULP_META_VF_FLAG |
192 : : intf->vf_func_id);
193 : : }
194 : :
195 : : /* When there is no match, the default action is to send the packet to
196 : : * the kernel. And to send it to the kernel, we need the PF's vnic id.
197 : : */
198 : 0 : func->func_parent_vnic = bnxt_pmd_get_parent_vnic_id(port_id, intf->type);
199 [ # # ]: 0 : func->func_parent_vnic = tfp_cpu_to_be_16(func->func_parent_vnic);
200 : 0 : bnxt_pmd_get_iface_mac(port_id, intf->type, func->func_mac,
201 : 0 : func->func_parent_mac);
202 : :
203 : 0 : port_data = &port_db->phy_port_list[func->phy_port_id];
204 [ # # ]: 0 : if (!port_data->port_valid) {
205 : 0 : port_data->port_svif =
206 : 0 : bnxt_pmd_get_svif(port_id, false, BNXT_ULP_INTF_TYPE_INVALID);
207 : 0 : port_data->port_spif = bnxt_pmd_get_phy_port_id(port_id);
208 : 0 : port_data->port_parif =
209 : 0 : bnxt_pmd_get_parif(port_id, BNXT_ULP_INTF_TYPE_INVALID);
210 : 0 : port_data->port_vport = bnxt_pmd_get_vport(port_id);
211 : 0 : port_data->port_valid = true;
212 : : }
213 : : return 0;
214 : : }
215 : :
216 : : /*
217 : : * Api to get the ulp ifindex for a given device port.
218 : : *
219 : : * ulp_ctxt [in] Ptr to ulp context
220 : : * port_id [in].device port id
221 : : * ifindex [out] ulp ifindex
222 : : *
223 : : * Returns 0 on success or negative number on failure.
224 : : */
225 : : int32_t
226 : 0 : ulp_port_db_dev_port_to_ulp_index(struct bnxt_ulp_context *ulp_ctxt,
227 : : uint32_t port_id,
228 : : uint32_t *ifindex)
229 : : {
230 : : struct bnxt_ulp_port_db *port_db;
231 : :
232 : 0 : *ifindex = 0;
233 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
234 [ # # ]: 0 : if (!port_db || port_id >= RTE_MAX_ETHPORTS) {
235 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
236 : 0 : return -EINVAL;
237 : : }
238 [ # # ]: 0 : if (!port_db->dev_port_list[port_id])
239 : : return -ENOENT;
240 : :
241 : 0 : *ifindex = port_db->dev_port_list[port_id];
242 : 0 : return 0;
243 : : }
244 : :
245 : : /*
246 : : * Api to get the function id for a given ulp ifindex.
247 : : *
248 : : * ulp_ctxt [in] Ptr to ulp context
249 : : * ifindex [in] ulp ifindex
250 : : * func_id [out] the function id of the given ifindex.
251 : : *
252 : : * Returns 0 on success or negative number on failure.
253 : : */
254 : : int32_t
255 : 0 : ulp_port_db_function_id_get(struct bnxt_ulp_context *ulp_ctxt,
256 : : uint32_t ifindex,
257 : : uint32_t fid_type,
258 : : uint16_t *func_id)
259 : : {
260 : : struct bnxt_ulp_port_db *port_db;
261 : :
262 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
263 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
264 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
265 : 0 : return -EINVAL;
266 : : }
267 : :
268 [ # # ]: 0 : if (fid_type == BNXT_ULP_DRV_FUNC_FID)
269 : 0 : *func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
270 : : else
271 : 0 : *func_id = port_db->ulp_intf_list[ifindex].vf_func_id;
272 : :
273 : : return 0;
274 : : }
275 : :
276 : : /*
277 : : * Api to get the svif for a given ulp ifindex.
278 : : *
279 : : * ulp_ctxt [in] Ptr to ulp context
280 : : * ifindex [in] ulp ifindex
281 : : * svif_type [in] the svif type of the given ifindex.
282 : : * svif [out] the svif of the given ifindex.
283 : : *
284 : : * Returns 0 on success or negative number on failure.
285 : : */
286 : : int32_t
287 : 0 : ulp_port_db_svif_get(struct bnxt_ulp_context *ulp_ctxt,
288 : : uint32_t ifindex,
289 : : uint32_t svif_type,
290 : : uint16_t *svif)
291 : : {
292 : : struct bnxt_ulp_port_db *port_db;
293 : : uint16_t phy_port_id, func_id;
294 : :
295 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
296 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
297 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
298 : 0 : return -EINVAL;
299 : : }
300 : :
301 [ # # ]: 0 : if (svif_type == BNXT_ULP_DRV_FUNC_SVIF) {
302 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
303 : 0 : *svif = port_db->ulp_func_id_tbl[func_id].func_svif;
304 [ # # ]: 0 : } else if (svif_type == BNXT_ULP_VF_FUNC_SVIF) {
305 : 0 : func_id = port_db->ulp_intf_list[ifindex].vf_func_id;
306 : 0 : *svif = port_db->ulp_func_id_tbl[func_id].func_svif;
307 : : } else {
308 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
309 : 0 : phy_port_id = port_db->ulp_func_id_tbl[func_id].phy_port_id;
310 : 0 : *svif = port_db->phy_port_list[phy_port_id].port_svif;
311 : : }
312 : :
313 : : return 0;
314 : : }
315 : :
316 : : /*
317 : : * Api to get the spif for a given ulp ifindex.
318 : : *
319 : : * ulp_ctxt [in] Ptr to ulp context
320 : : * ifindex [in] ulp ifindex
321 : : * spif_type [in] the spif type of the given ifindex.
322 : : * spif [out] the spif of the given ifindex.
323 : : *
324 : : * Returns 0 on success or negative number on failure.
325 : : */
326 : : int32_t
327 : 0 : ulp_port_db_spif_get(struct bnxt_ulp_context *ulp_ctxt,
328 : : uint32_t ifindex,
329 : : uint32_t spif_type,
330 : : uint16_t *spif)
331 : : {
332 : : struct bnxt_ulp_port_db *port_db;
333 : : uint16_t phy_port_id, func_id;
334 : :
335 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
336 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
337 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
338 : 0 : return -EINVAL;
339 : : }
340 : :
341 [ # # ]: 0 : if (spif_type == BNXT_ULP_DRV_FUNC_SPIF) {
342 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
343 : 0 : *spif = port_db->ulp_func_id_tbl[func_id].func_spif;
344 [ # # ]: 0 : } else if (spif_type == BNXT_ULP_VF_FUNC_SPIF) {
345 : 0 : func_id = port_db->ulp_intf_list[ifindex].vf_func_id;
346 : 0 : *spif = port_db->ulp_func_id_tbl[func_id].func_spif;
347 : : } else {
348 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
349 : 0 : phy_port_id = port_db->ulp_func_id_tbl[func_id].phy_port_id;
350 : 0 : *spif = port_db->phy_port_list[phy_port_id].port_spif;
351 : : }
352 : :
353 : : return 0;
354 : : }
355 : :
356 : : /*
357 : : * Api to get the parif for a given ulp ifindex.
358 : : *
359 : : * ulp_ctxt [in] Ptr to ulp context
360 : : * ifindex [in] ulp ifindex
361 : : * parif_type [in] the parif type of the given ifindex.
362 : : * parif [out] the parif of the given ifindex.
363 : : *
364 : : * Returns 0 on success or negative number on failure.
365 : : */
366 : : int32_t
367 : 0 : ulp_port_db_parif_get(struct bnxt_ulp_context *ulp_ctxt,
368 : : uint32_t ifindex,
369 : : uint32_t parif_type,
370 : : uint16_t *parif)
371 : : {
372 : : struct bnxt_ulp_port_db *port_db;
373 : : uint16_t phy_port_id, func_id;
374 : :
375 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
376 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
377 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
378 : 0 : return -EINVAL;
379 : : }
380 [ # # ]: 0 : if (parif_type == BNXT_ULP_DRV_FUNC_PARIF) {
381 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
382 : 0 : *parif = port_db->ulp_func_id_tbl[func_id].func_parif;
383 [ # # ]: 0 : } else if (parif_type == BNXT_ULP_VF_FUNC_PARIF) {
384 : 0 : func_id = port_db->ulp_intf_list[ifindex].vf_func_id;
385 : 0 : *parif = port_db->ulp_func_id_tbl[func_id].func_parif;
386 : : } else {
387 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
388 : 0 : phy_port_id = port_db->ulp_func_id_tbl[func_id].phy_port_id;
389 : 0 : *parif = port_db->phy_port_list[phy_port_id].port_parif;
390 : : }
391 : : /* Parif needs to be reset to a free partition */
392 : 0 : *parif += BNXT_ULP_FREE_PARIF_BASE;
393 : :
394 : 0 : return 0;
395 : : }
396 : :
397 : : /*
398 : : * Api to get the vnic id for a given ulp ifindex.
399 : : *
400 : : * ulp_ctxt [in] Ptr to ulp context
401 : : * ifindex [in] ulp ifindex
402 : : * vnic [out] the vnic of the given ifindex.
403 : : *
404 : : * Returns 0 on success or negative number on failure.
405 : : */
406 : : int32_t
407 : 0 : ulp_port_db_default_vnic_get(struct bnxt_ulp_context *ulp_ctxt,
408 : : uint32_t ifindex,
409 : : uint32_t vnic_type,
410 : : uint16_t *vnic)
411 : : {
412 : : struct bnxt_ulp_port_db *port_db;
413 : : uint16_t func_id;
414 : :
415 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
416 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
417 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
418 : 0 : return -EINVAL;
419 : : }
420 : :
421 [ # # ]: 0 : if (vnic_type == BNXT_ULP_DRV_FUNC_VNIC) {
422 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
423 : 0 : *vnic = port_db->ulp_func_id_tbl[func_id].func_vnic;
424 : : } else {
425 : 0 : func_id = port_db->ulp_intf_list[ifindex].vf_func_id;
426 : 0 : *vnic = port_db->ulp_func_id_tbl[func_id].func_vnic;
427 : : }
428 : :
429 : : return 0;
430 : : }
431 : :
432 : : /*
433 : : * Api to get the vport id for a given ulp ifindex.
434 : : *
435 : : * ulp_ctxt [in] Ptr to ulp context
436 : : * ifindex [in] ulp ifindex
437 : : * vport [out] the port of the given ifindex.
438 : : *
439 : : * Returns 0 on success or negative number on failure.
440 : : */
441 : : int32_t
442 : 0 : ulp_port_db_vport_get(struct bnxt_ulp_context *ulp_ctxt,
443 : : uint32_t ifindex, uint16_t *vport)
444 : : {
445 : : struct bnxt_ulp_port_db *port_db;
446 : : uint16_t phy_port_id, func_id;
447 : :
448 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
449 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
450 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
451 : 0 : return -EINVAL;
452 : : }
453 : :
454 : 0 : func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
455 : 0 : phy_port_id = port_db->ulp_func_id_tbl[func_id].phy_port_id;
456 : 0 : *vport = port_db->phy_port_list[phy_port_id].port_vport;
457 : 0 : return 0;
458 : : }
459 : :
460 : : /*
461 : : * Api to get the vport for a given physical port.
462 : : *
463 : : * ulp_ctxt [in] Ptr to ulp context
464 : : * phy_port [in] physical port index
465 : : * out_port [out] the port of the given physical index
466 : : *
467 : : * Returns 0 on success or negative number on failure.
468 : : */
469 : : int32_t
470 : 0 : ulp_port_db_phy_port_vport_get(struct bnxt_ulp_context *ulp_ctxt,
471 : : uint32_t phy_port,
472 : : uint16_t *out_port)
473 : : {
474 : : struct bnxt_ulp_port_db *port_db;
475 : :
476 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
477 [ # # # # ]: 0 : if (!port_db || phy_port >= port_db->phy_port_cnt) {
478 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
479 : 0 : return -EINVAL;
480 : : }
481 : 0 : *out_port = port_db->phy_port_list[phy_port].port_vport;
482 : 0 : return 0;
483 : : }
484 : :
485 : : /*
486 : : * Api to get the svif for a given physical port.
487 : : *
488 : : * ulp_ctxt [in] Ptr to ulp context
489 : : * phy_port [in] physical port index
490 : : * svif [out] the svif of the given physical index
491 : : *
492 : : * Returns 0 on success or negative number on failure.
493 : : */
494 : : int32_t
495 : 0 : ulp_port_db_phy_port_svif_get(struct bnxt_ulp_context *ulp_ctxt,
496 : : uint32_t phy_port,
497 : : uint16_t *svif)
498 : : {
499 : : struct bnxt_ulp_port_db *port_db;
500 : :
501 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
502 [ # # # # ]: 0 : if (!port_db || phy_port >= port_db->phy_port_cnt) {
503 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
504 : 0 : return -EINVAL;
505 : : }
506 : 0 : *svif = port_db->phy_port_list[phy_port].port_svif;
507 : 0 : return 0;
508 : : }
509 : :
510 : : /*
511 : : * Api to get the port type for a given ulp ifindex.
512 : : *
513 : : * ulp_ctxt [in] Ptr to ulp context
514 : : * ifindex [in] ulp ifindex
515 : : *
516 : : * Returns port type.
517 : : */
518 : : enum bnxt_ulp_intf_type
519 : 0 : ulp_port_db_port_type_get(struct bnxt_ulp_context *ulp_ctxt,
520 : : uint32_t ifindex)
521 : : {
522 : : struct bnxt_ulp_port_db *port_db;
523 : :
524 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
525 [ # # # # : 0 : if (!port_db || ifindex >= port_db->ulp_intf_list_size || !ifindex) {
# # ]
526 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
527 : 0 : return BNXT_ULP_INTF_TYPE_INVALID;
528 : : }
529 : 0 : return port_db->ulp_intf_list[ifindex].type;
530 : : }
531 : :
532 : : /*
533 : : * Api to get the ulp ifindex for a given function id.
534 : : *
535 : : * ulp_ctxt [in] Ptr to ulp context
536 : : * func_id [in].device func id
537 : : * ifindex [out] ulp ifindex
538 : : *
539 : : * Returns 0 on success or negative number on failure.
540 : : */
541 : : int32_t
542 : 0 : ulp_port_db_dev_func_id_to_ulp_index(struct bnxt_ulp_context *ulp_ctxt,
543 : : uint32_t func_id, uint32_t *ifindex)
544 : : {
545 : : struct bnxt_ulp_port_db *port_db;
546 : :
547 : 0 : *ifindex = 0;
548 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
549 [ # # ]: 0 : if (!port_db || func_id >= BNXT_PORT_DB_MAX_FUNC) {
550 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
551 : 0 : return -EINVAL;
552 : : }
553 [ # # ]: 0 : if (!port_db->ulp_func_id_tbl[func_id].func_valid)
554 : : return -ENOENT;
555 : :
556 : 0 : *ifindex = port_db->ulp_func_id_tbl[func_id].ifindex;
557 : 0 : return 0;
558 : : }
559 : :
560 : : /*
561 : : * Api to get the function id for a given port id.
562 : : *
563 : : * ulp_ctxt [in] Ptr to ulp context
564 : : * port_id [in] dpdk port id
565 : : * func_id [out] the function id of the given ifindex.
566 : : *
567 : : * Returns 0 on success or negative number on failure.
568 : : */
569 : : int32_t
570 : 0 : ulp_port_db_port_func_id_get(struct bnxt_ulp_context *ulp_ctxt,
571 : : uint16_t port_id, uint16_t *func_id)
572 : : {
573 : : struct bnxt_ulp_port_db *port_db;
574 : : uint32_t ifindex;
575 : :
576 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
577 [ # # ]: 0 : if (!port_db || port_id >= RTE_MAX_ETHPORTS) {
578 : 0 : BNXT_TF_DBG(ERR, "Invalid Arguments\n");
579 : 0 : return -EINVAL;
580 : : }
581 : 0 : ifindex = port_db->dev_port_list[port_id];
582 [ # # ]: 0 : if (!ifindex)
583 : : return -ENOENT;
584 : :
585 [ # # # ]: 0 : switch (port_db->ulp_intf_list[ifindex].type) {
586 : 0 : case BNXT_ULP_INTF_TYPE_TRUSTED_VF:
587 : : case BNXT_ULP_INTF_TYPE_PF:
588 : 0 : *func_id = port_db->ulp_intf_list[ifindex].drv_func_id;
589 : 0 : break;
590 : 0 : case BNXT_ULP_INTF_TYPE_VF:
591 : : case BNXT_ULP_INTF_TYPE_VF_REP:
592 : 0 : *func_id = port_db->ulp_intf_list[ifindex].vf_func_id;
593 : 0 : break;
594 : 0 : default:
595 : 0 : *func_id = 0;
596 : 0 : break;
597 : : }
598 : : return 0;
599 : : }
600 : :
601 : : /* internal function to get the */
602 : : static struct ulp_func_if_info*
603 : 0 : ulp_port_db_func_if_info_get(struct bnxt_ulp_context *ulp_ctxt,
604 : : uint32_t port_id)
605 : : {
606 : : struct bnxt_ulp_port_db *port_db;
607 : : uint16_t func_id;
608 : :
609 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
610 [ # # ]: 0 : if (ulp_port_db_port_func_id_get(ulp_ctxt, port_id, &func_id)) {
611 : 0 : BNXT_TF_DBG(ERR, "Invalid port_id %x\n", port_id);
612 : 0 : return NULL;
613 : : }
614 : :
615 [ # # ]: 0 : if (!port_db->ulp_func_id_tbl[func_id].func_valid) {
616 : 0 : BNXT_TF_DBG(ERR, "Invalid func_id %x\n", func_id);
617 : 0 : return NULL;
618 : : }
619 : 0 : return &port_db->ulp_func_id_tbl[func_id];
620 : : }
621 : :
622 : : /*
623 : : * Api to get the parent mac address for a given port id.
624 : : *
625 : : * ulp_ctxt [in] Ptr to ulp context
626 : : * port_id [in] device port id
627 : : * mac_addr [out] mac address
628 : : *
629 : : * Returns 0 on success or negative number on failure.
630 : : */
631 : : int32_t
632 : 0 : ulp_port_db_parent_mac_addr_get(struct bnxt_ulp_context *ulp_ctxt,
633 : : uint32_t port_id, uint8_t **mac_addr)
634 : : {
635 : : struct ulp_func_if_info *info;
636 : :
637 : 0 : info = ulp_port_db_func_if_info_get(ulp_ctxt, port_id);
638 [ # # ]: 0 : if (info) {
639 : 0 : *mac_addr = info->func_parent_mac;
640 : 0 : return 0;
641 : : }
642 : : return -EINVAL;
643 : : }
644 : :
645 : : /*
646 : : * Api to get the mac address for a given port id.
647 : : *
648 : : * ulp_ctxt [in] Ptr to ulp context
649 : : * port_id [in] device port id
650 : : * mac_addr [out] mac address
651 : : *
652 : : * Returns 0 on success or negative number on failure.
653 : : */
654 : : int32_t
655 : 0 : ulp_port_db_drv_mac_addr_get(struct bnxt_ulp_context *ulp_ctxt,
656 : : uint32_t port_id, uint8_t **mac_addr)
657 : : {
658 : : struct ulp_func_if_info *info;
659 : :
660 : 0 : info = ulp_port_db_func_if_info_get(ulp_ctxt, port_id);
661 [ # # ]: 0 : if (info) {
662 : 0 : *mac_addr = info->func_mac;
663 : 0 : return 0;
664 : : }
665 : : return -EINVAL;
666 : : }
667 : :
668 : : /*
669 : : * Api to get the parent vnic for a given port id.
670 : : *
671 : : * ulp_ctxt [in] Ptr to ulp context
672 : : * port_id [in] device port id
673 : : * vnic [out] parent vnic
674 : : *
675 : : * Returns 0 on success or negative number on failure.
676 : : */
677 : : int32_t
678 : 0 : ulp_port_db_parent_vnic_get(struct bnxt_ulp_context *ulp_ctxt,
679 : : uint32_t port_id, uint8_t **vnic)
680 : : {
681 : : struct ulp_func_if_info *info;
682 : :
683 : 0 : info = ulp_port_db_func_if_info_get(ulp_ctxt, port_id);
684 [ # # ]: 0 : if (info) {
685 : 0 : *vnic = (uint8_t *)&info->func_parent_vnic;
686 : 0 : return 0;
687 : : }
688 : : return -EINVAL;
689 : : }
690 : :
691 : : /*
692 : : * Api to get the phy port for a given port id.
693 : : *
694 : : * ulp_ctxt [in] Ptr to ulp context
695 : : * port_id [in] device port id
696 : : * phy_port [out] phy_port of the dpdk port_id
697 : : *
698 : : * Returns 0 on success or negative number on failure.
699 : : */
700 : : int32_t
701 : 0 : ulp_port_db_phy_port_get(struct bnxt_ulp_context *ulp_ctxt,
702 : : uint32_t port_id, uint16_t *phy_port)
703 : : {
704 : : struct ulp_func_if_info *info;
705 : :
706 : 0 : info = ulp_port_db_func_if_info_get(ulp_ctxt, port_id);
707 [ # # ]: 0 : if (info) {
708 : 0 : *phy_port = info->phy_port_id;
709 : 0 : return 0;
710 : : }
711 : : return -EINVAL;
712 : : }
713 : :
714 : : /*
715 : : * Api to get the port type for a given port id.
716 : : *
717 : : * ulp_ctxt [in] Ptr to ulp context
718 : : * port_id [in] device port id
719 : : * type [out] type if pf or not
720 : : *
721 : : * Returns 0 on success or negative number on failure.
722 : : */
723 : : int32_t
724 : 0 : ulp_port_db_port_is_pf_get(struct bnxt_ulp_context *ulp_ctxt,
725 : : uint32_t port_id, uint8_t **type)
726 : : {
727 : : struct ulp_func_if_info *info;
728 : : struct bnxt_ulp_port_db *port_db;
729 : : uint16_t pid;
730 : :
731 : 0 : port_db = bnxt_ulp_cntxt_ptr2_port_db_get(ulp_ctxt);
732 : 0 : info = ulp_port_db_func_if_info_get(ulp_ctxt, port_id);
733 [ # # ]: 0 : if (info) {
734 : 0 : pid = info->ifindex;
735 : 0 : *type = &port_db->ulp_intf_list[pid].type_is_pf;
736 : 0 : return 0;
737 : : }
738 : : return -EINVAL;
739 : : }
740 : :
741 : : /*
742 : : * Api to get the meta data for a given port id.
743 : : *
744 : : * ulp_ctxt [in] Ptr to ulp context
745 : : * port_id [in] dpdk port id
746 : : * meta data [out] the meta data of the given port
747 : : *
748 : : * Returns 0 on success or negative number on failure.
749 : : */
750 : : int32_t
751 : 0 : ulp_port_db_port_meta_data_get(struct bnxt_ulp_context *ulp_ctxt,
752 : : uint16_t port_id, uint8_t **meta_data)
753 : : {
754 : : struct ulp_func_if_info *info;
755 : :
756 : 0 : info = ulp_port_db_func_if_info_get(ulp_ctxt, port_id);
757 [ # # ]: 0 : if (info) {
758 : 0 : *meta_data = (uint8_t *)&info->vf_meta_data;
759 : 0 : return 0;
760 : : }
761 : : return -EINVAL;
762 : : }
|