Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <inttypes.h>
7 : : #include <stdbool.h>
8 : : #include <unistd.h>
9 : :
10 : : #include <dev_driver.h>
11 : : #include <ethdev_driver.h>
12 : : #include <eal_export.h>
13 : : #include <rte_malloc.h>
14 : : #include <rte_cycles.h>
15 : : #include <rte_byteorder.h>
16 : :
17 : : #include "bnxt.h"
18 : : #include "bnxt_filter.h"
19 : : #include "bnxt_hwrm.h"
20 : : #include "bnxt_vnic.h"
21 : : #include "rte_pmd_bnxt.h"
22 : : #include "hsi_struct_def_dpdk.h"
23 : :
24 : 0 : int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg)
25 : : {
26 : : struct rte_pmd_bnxt_mb_event_param ret_param;
27 : :
28 : 0 : ret_param.retval = RTE_PMD_BNXT_MB_EVENT_PROCEED;
29 : 0 : ret_param.vf_id = vf_id;
30 : 0 : ret_param.msg = msg;
31 : :
32 : 0 : rte_eth_dev_callback_process(bp->eth_dev, RTE_ETH_EVENT_VF_MBOX,
33 : : &ret_param);
34 : :
35 : : /* Default to approve */
36 [ # # ]: 0 : if (ret_param.retval == RTE_PMD_BNXT_MB_EVENT_PROCEED)
37 : 0 : ret_param.retval = RTE_PMD_BNXT_MB_EVENT_NOOP_ACK;
38 : :
39 : 0 : return ret_param.retval == RTE_PMD_BNXT_MB_EVENT_NOOP_ACK ?
40 : 0 : true : false;
41 : : }
42 : :
43 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_tx_loopback)
44 : 0 : int rte_pmd_bnxt_set_tx_loopback(uint16_t port, uint8_t on)
45 : : {
46 : : struct rte_eth_dev *eth_dev;
47 : : struct bnxt *bp;
48 : : int rc;
49 : :
50 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
51 : :
52 [ # # ]: 0 : if (on > 1)
53 : : return -EINVAL;
54 : :
55 : 0 : eth_dev = &rte_eth_devices[port];
56 [ # # ]: 0 : if (!is_bnxt_supported(eth_dev))
57 : : return -ENOTSUP;
58 : :
59 : 0 : bp = eth_dev->data->dev_private;
60 : :
61 [ # # ]: 0 : if (!BNXT_PF(bp)) {
62 : 0 : PMD_DRV_LOG_LINE(ERR,
63 : : "Attempt to set Tx loopback on non-PF port %d!",
64 : : port);
65 : 0 : return -ENOTSUP;
66 : : }
67 : :
68 [ # # ]: 0 : if (on)
69 : 0 : bp->pf->evb_mode = BNXT_EVB_MODE_VEB;
70 : : else
71 : 0 : bp->pf->evb_mode = BNXT_EVB_MODE_VEPA;
72 : :
73 : 0 : rc = bnxt_hwrm_pf_evb_mode(bp);
74 : :
75 : 0 : return rc;
76 : : }
77 : :
78 : : static void
79 : 0 : rte_pmd_bnxt_set_all_queues_drop_en_cb(struct bnxt_vnic_info *vnic, void *onptr)
80 : : {
81 : : uint8_t *on = onptr;
82 : 0 : vnic->bd_stall = !(*on);
83 : 0 : }
84 : :
85 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_all_queues_drop_en)
86 : 0 : int rte_pmd_bnxt_set_all_queues_drop_en(uint16_t port, uint8_t on)
87 : : {
88 : : struct rte_eth_dev *eth_dev;
89 : : struct bnxt *bp;
90 : : uint32_t i;
91 : : int rc = -EINVAL;
92 : :
93 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
94 : :
95 [ # # ]: 0 : if (on > 1)
96 : : return -EINVAL;
97 : :
98 : 0 : eth_dev = &rte_eth_devices[port];
99 [ # # ]: 0 : if (!is_bnxt_supported(eth_dev))
100 : : return -ENOTSUP;
101 : :
102 : 0 : bp = eth_dev->data->dev_private;
103 : :
104 [ # # ]: 0 : if (!BNXT_PF(bp)) {
105 : 0 : PMD_DRV_LOG_LINE(ERR,
106 : : "Attempt to set all queues drop on non-PF port!");
107 : 0 : return -ENOTSUP;
108 : : }
109 : :
110 [ # # ]: 0 : if (bp->vnic_info == NULL)
111 : : return -ENODEV;
112 : :
113 : : /* Stall PF */
114 [ # # ]: 0 : for (i = 0; i < bp->nr_vnics; i++) {
115 : 0 : bp->vnic_info[i].bd_stall = !on;
116 : 0 : rc = bnxt_hwrm_vnic_cfg(bp, &bp->vnic_info[i]);
117 [ # # ]: 0 : if (rc) {
118 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to update PF VNIC %d.", i);
119 : 0 : return rc;
120 : : }
121 : : }
122 : :
123 : : /* Stall all active VFs */
124 [ # # ]: 0 : for (i = 0; i < bp->pf->active_vfs; i++) {
125 : 0 : rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, i,
126 : : rte_pmd_bnxt_set_all_queues_drop_en_cb, &on,
127 : : bnxt_hwrm_vnic_cfg);
128 [ # # ]: 0 : if (rc) {
129 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to update VF VNIC %d.", i);
130 : 0 : break;
131 : : }
132 : : }
133 : :
134 : : return rc;
135 : : }
136 : :
137 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_mac_addr)
138 : 0 : int rte_pmd_bnxt_set_vf_mac_addr(uint16_t port, uint16_t vf,
139 : : struct rte_ether_addr *mac_addr)
140 : : {
141 : : struct rte_eth_dev *dev;
142 : : struct rte_eth_dev_info dev_info;
143 : : struct bnxt *bp;
144 : : int rc;
145 : :
146 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
147 : :
148 : 0 : dev = &rte_eth_devices[port];
149 [ # # ]: 0 : if (!is_bnxt_supported(dev))
150 : : return -ENOTSUP;
151 : :
152 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
153 [ # # ]: 0 : if (rc != 0) {
154 : 0 : PMD_DRV_LOG_LINE(ERR,
155 : : "Error during getting device (port %u) info: %s",
156 : : port, strerror(-rc));
157 : :
158 : 0 : return rc;
159 : : }
160 : :
161 : 0 : bp = dev->data->dev_private;
162 : :
163 [ # # # # ]: 0 : if (vf >= dev_info.max_vfs || mac_addr == NULL)
164 : : return -EINVAL;
165 : :
166 [ # # ]: 0 : if (!BNXT_PF(bp)) {
167 : 0 : PMD_DRV_LOG_LINE(ERR,
168 : : "Attempt to set VF %d mac address on non-PF port %d!",
169 : : vf, port);
170 : 0 : return -ENOTSUP;
171 : : }
172 : :
173 : 0 : rc = bnxt_hwrm_func_vf_mac(bp, vf, (uint8_t *)mac_addr);
174 : :
175 : 0 : return rc;
176 : : }
177 : :
178 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_rate_limit)
179 : 0 : int rte_pmd_bnxt_set_vf_rate_limit(uint16_t port, uint16_t vf,
180 : : uint32_t tx_rate, uint64_t q_msk)
181 : : {
182 : : struct rte_eth_dev *eth_dev;
183 : : struct rte_eth_dev_info dev_info;
184 : : struct bnxt *bp;
185 : : uint32_t tot_rate = 0;
186 : : uint64_t idx;
187 : : int rc;
188 : :
189 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
190 : :
191 : 0 : eth_dev = &rte_eth_devices[port];
192 [ # # ]: 0 : if (!is_bnxt_supported(eth_dev))
193 : : return -ENOTSUP;
194 : :
195 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
196 [ # # ]: 0 : if (rc != 0) {
197 : 0 : PMD_DRV_LOG_LINE(ERR,
198 : : "Error during getting device (port %u) info: %s",
199 : : port, strerror(-rc));
200 : :
201 : 0 : return rc;
202 : : }
203 : 0 : bp = eth_dev->data->dev_private;
204 : :
205 [ # # ]: 0 : if (!bp->pf->active_vfs)
206 : : return -EINVAL;
207 : :
208 [ # # ]: 0 : if (vf >= bp->pf->max_vfs)
209 : : return -EINVAL;
210 : :
211 : : /* Add up the per queue BW and configure MAX BW of the VF */
212 [ # # ]: 0 : for (idx = 0; idx < 64; idx++) {
213 [ # # ]: 0 : if ((1ULL << idx) & q_msk)
214 : 0 : tot_rate += tx_rate;
215 : : }
216 : :
217 : : /* Requested BW can't be greater than link speed */
218 [ # # ]: 0 : if (tot_rate > eth_dev->data->dev_link.link_speed) {
219 : 0 : PMD_DRV_LOG_LINE(ERR, "Rate > Link speed. Set to %d", tot_rate);
220 : 0 : return -EINVAL;
221 : : }
222 : :
223 : : /* Requested BW already configured */
224 [ # # ]: 0 : if (tot_rate == bp->pf->vf_info[vf].max_tx_rate)
225 : : return 0;
226 : :
227 : 0 : rc = bnxt_hwrm_func_bw_cfg(bp, vf, tot_rate,
228 : : HWRM_FUNC_CFG_INPUT_ENABLES_MAX_BW);
229 : :
230 [ # # ]: 0 : if (!rc)
231 : 0 : bp->pf->vf_info[vf].max_tx_rate = tot_rate;
232 : :
233 : : return rc;
234 : : }
235 : :
236 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_mac_anti_spoof)
237 : 0 : int rte_pmd_bnxt_set_vf_mac_anti_spoof(uint16_t port, uint16_t vf, uint8_t on)
238 : : {
239 : : struct rte_eth_dev_info dev_info;
240 : : struct rte_eth_dev *dev;
241 : : uint32_t func_flags;
242 : : struct bnxt *bp;
243 : : int rc;
244 : :
245 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
246 : :
247 [ # # ]: 0 : if (on > 1)
248 : : return -EINVAL;
249 : :
250 : 0 : dev = &rte_eth_devices[port];
251 [ # # ]: 0 : if (!is_bnxt_supported(dev))
252 : : return -ENOTSUP;
253 : :
254 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
255 [ # # ]: 0 : if (rc != 0) {
256 : 0 : PMD_DRV_LOG_LINE(ERR,
257 : : "Error during getting device (port %u) info: %s",
258 : : port, strerror(-rc));
259 : :
260 : 0 : return rc;
261 : : }
262 : 0 : bp = dev->data->dev_private;
263 : :
264 [ # # ]: 0 : if (!BNXT_PF(bp)) {
265 : 0 : PMD_DRV_LOG_LINE(ERR,
266 : : "Attempt to set mac spoof on non-PF port %d!", port);
267 : 0 : return -EINVAL;
268 : : }
269 : :
270 [ # # ]: 0 : if (vf >= dev_info.max_vfs)
271 : : return -EINVAL;
272 : :
273 : : /* Prev setting same as new setting. */
274 [ # # ]: 0 : if (on == bp->pf->vf_info[vf].mac_spoof_en)
275 : : return 0;
276 : :
277 : 0 : func_flags = bp->pf->vf_info[vf].func_cfg_flags;
278 : 0 : func_flags &= ~(HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE |
279 : : HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE);
280 : :
281 [ # # ]: 0 : if (on)
282 : 0 : func_flags |=
283 : : HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE;
284 : : else
285 : 0 : func_flags |=
286 : : HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE;
287 : :
288 : 0 : rc = bnxt_hwrm_func_cfg_vf_set_flags(bp, vf, func_flags);
289 [ # # ]: 0 : if (!rc) {
290 : 0 : bp->pf->vf_info[vf].mac_spoof_en = on;
291 : 0 : bp->pf->vf_info[vf].func_cfg_flags = func_flags;
292 : : }
293 : :
294 : : return rc;
295 : : }
296 : :
297 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_vlan_anti_spoof)
298 : 0 : int rte_pmd_bnxt_set_vf_vlan_anti_spoof(uint16_t port, uint16_t vf, uint8_t on)
299 : : {
300 : : struct rte_eth_dev_info dev_info;
301 : : struct rte_eth_dev *dev;
302 : : struct bnxt *bp;
303 : : int rc;
304 : :
305 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
306 : :
307 [ # # ]: 0 : if (on > 1)
308 : : return -EINVAL;
309 : :
310 : 0 : dev = &rte_eth_devices[port];
311 [ # # ]: 0 : if (!is_bnxt_supported(dev))
312 : : return -ENOTSUP;
313 : :
314 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
315 [ # # ]: 0 : if (rc != 0) {
316 : 0 : PMD_DRV_LOG_LINE(ERR,
317 : : "Error during getting device (port %u) info: %s",
318 : : port, strerror(-rc));
319 : :
320 : 0 : return rc;
321 : : }
322 : 0 : bp = dev->data->dev_private;
323 : :
324 [ # # ]: 0 : if (!BNXT_PF(bp)) {
325 : 0 : PMD_DRV_LOG_LINE(ERR,
326 : : "Attempt to set VLAN spoof on non-PF port %d!", port);
327 : 0 : return -EINVAL;
328 : : }
329 : :
330 [ # # ]: 0 : if (vf >= dev_info.max_vfs)
331 : : return -EINVAL;
332 : :
333 : 0 : rc = bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(bp, vf, on);
334 [ # # ]: 0 : if (!rc) {
335 : 0 : bp->pf->vf_info[vf].vlan_spoof_en = on;
336 [ # # ]: 0 : if (on) {
337 [ # # ]: 0 : if (bnxt_hwrm_cfa_vlan_antispoof_cfg(bp,
338 : 0 : bp->pf->first_vf_id + vf,
339 : 0 : bp->pf->vf_info[vf].vlan_count,
340 : : bp->pf->vf_info[vf].vlan_as_table))
341 : : rc = -1;
342 : : }
343 : : } else {
344 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to update VF VNIC %d.", vf);
345 : : }
346 : :
347 : : return rc;
348 : : }
349 : :
350 : : static void
351 : 0 : rte_pmd_bnxt_set_vf_vlan_stripq_cb(struct bnxt_vnic_info *vnic, void *onptr)
352 : : {
353 : : uint8_t *on = onptr;
354 : 0 : vnic->vlan_strip = *on;
355 : 0 : }
356 : :
357 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_vlan_stripq)
358 : : int
359 : 0 : rte_pmd_bnxt_set_vf_vlan_stripq(uint16_t port, uint16_t vf, uint8_t on)
360 : : {
361 : : struct rte_eth_dev *dev;
362 : : struct rte_eth_dev_info dev_info;
363 : : struct bnxt *bp;
364 : : int rc;
365 : :
366 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
367 : :
368 : 0 : dev = &rte_eth_devices[port];
369 [ # # ]: 0 : if (!is_bnxt_supported(dev))
370 : : return -ENOTSUP;
371 : :
372 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
373 [ # # ]: 0 : if (rc != 0) {
374 : 0 : PMD_DRV_LOG_LINE(ERR,
375 : : "Error during getting device (port %u) info: %s",
376 : : port, strerror(-rc));
377 : :
378 : 0 : return rc;
379 : : }
380 : 0 : bp = dev->data->dev_private;
381 : :
382 [ # # ]: 0 : if (vf >= dev_info.max_vfs)
383 : : return -EINVAL;
384 : :
385 [ # # ]: 0 : if (!BNXT_PF(bp)) {
386 : 0 : PMD_DRV_LOG_LINE(ERR,
387 : : "Attempt to set VF %d stripq on non-PF port %d!",
388 : : vf, port);
389 : 0 : return -ENOTSUP;
390 : : }
391 : :
392 : 0 : rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
393 : : rte_pmd_bnxt_set_vf_vlan_stripq_cb, &on,
394 : : bnxt_hwrm_vnic_cfg);
395 [ # # ]: 0 : if (rc)
396 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to update VF VNIC %d.", vf);
397 : :
398 : : return rc;
399 : : }
400 : :
401 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_rxmode)
402 : 0 : int rte_pmd_bnxt_set_vf_rxmode(uint16_t port, uint16_t vf,
403 : : uint16_t rx_mask, uint8_t on)
404 : : {
405 : : struct rte_eth_dev *dev;
406 : : struct rte_eth_dev_info dev_info;
407 : : uint16_t flag = 0;
408 : : struct bnxt *bp;
409 : : int rc;
410 : :
411 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
412 : :
413 : 0 : dev = &rte_eth_devices[port];
414 [ # # ]: 0 : if (!is_bnxt_supported(dev))
415 : : return -ENOTSUP;
416 : :
417 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
418 [ # # ]: 0 : if (rc != 0) {
419 : 0 : PMD_DRV_LOG_LINE(ERR,
420 : : "Error during getting device (port %u) info: %s",
421 : : port, strerror(-rc));
422 : :
423 : 0 : return rc;
424 : : }
425 : 0 : bp = dev->data->dev_private;
426 : :
427 [ # # ]: 0 : if (!bp->pf->vf_info)
428 : : return -EINVAL;
429 : :
430 [ # # ]: 0 : if (vf >= bp->pdev->max_vfs)
431 : : return -EINVAL;
432 : :
433 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_UNTAG) {
434 : 0 : PMD_DRV_LOG_LINE(ERR, "Currently cannot toggle this setting");
435 : 0 : return -ENOTSUP;
436 : : }
437 : :
438 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_HASH_UC)
439 : : flag |= BNXT_VNIC_INFO_PROMISC;
440 : :
441 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_BROADCAST)
442 : 0 : flag |= BNXT_VNIC_INFO_BCAST;
443 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_MULTICAST)
444 : 0 : flag |= BNXT_VNIC_INFO_ALLMULTI | BNXT_VNIC_INFO_MCAST;
445 : :
446 [ # # ]: 0 : if (on)
447 : 0 : bp->pf->vf_info[vf].l2_rx_mask |= flag;
448 : : else
449 : 0 : bp->pf->vf_info[vf].l2_rx_mask &= ~flag;
450 : :
451 : 0 : rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
452 : : vf_vnic_set_rxmask_cb,
453 : 0 : &bp->pf->vf_info[vf].l2_rx_mask,
454 : : bnxt_set_rx_mask_no_vlan);
455 [ # # ]: 0 : if (rc)
456 : 0 : PMD_DRV_LOG_LINE(ERR, "bnxt_hwrm_func_vf_vnic_set_rxmask failed");
457 : :
458 : : return rc;
459 : : }
460 : :
461 : 0 : static int bnxt_set_vf_table(struct bnxt *bp, uint16_t vf)
462 : : {
463 : : int rc = 0;
464 : : int dflt_vnic;
465 : : struct bnxt_vnic_info vnic;
466 : :
467 [ # # ]: 0 : if (!BNXT_PF(bp)) {
468 : 0 : PMD_DRV_LOG_LINE(ERR,
469 : : "Attempt to set VLAN table on non-PF port!");
470 : 0 : return -EINVAL;
471 : : }
472 : :
473 [ # # ]: 0 : if (vf >= bp->pdev->max_vfs)
474 : : return -EINVAL;
475 : :
476 : 0 : dflt_vnic = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf);
477 [ # # ]: 0 : if (dflt_vnic < 0) {
478 : : /* This simply indicates there's no driver loaded.
479 : : * This is not an error.
480 : : */
481 : 0 : PMD_DRV_LOG_LINE(ERR, "Unable to get default VNIC for VF %d", vf);
482 : : } else {
483 : : memset(&vnic, 0, sizeof(vnic));
484 : 0 : vnic.fw_vnic_id = dflt_vnic;
485 [ # # ]: 0 : if (bnxt_hwrm_vnic_qcfg(bp, &vnic,
486 : 0 : bp->pf->first_vf_id + vf) == 0) {
487 [ # # ]: 0 : if (bnxt_hwrm_cfa_l2_set_rx_mask(bp, &vnic,
488 : 0 : bp->pf->vf_info[vf].vlan_count,
489 : 0 : bp->pf->vf_info[vf].vlan_table))
490 : : rc = -1;
491 : : } else {
492 : : rc = -1;
493 : : }
494 : : }
495 : :
496 : : return rc;
497 : : }
498 : :
499 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_vlan_filter)
500 : 0 : int rte_pmd_bnxt_set_vf_vlan_filter(uint16_t port, uint16_t vlan,
501 : : uint64_t vf_mask, uint8_t vlan_on)
502 : : {
503 : : struct bnxt_vlan_table_entry *ve;
504 : : struct bnxt_vlan_antispoof_table_entry *vase;
505 : : struct rte_eth_dev *dev;
506 : : struct bnxt *bp;
507 : : uint16_t cnt;
508 : : int rc = 0;
509 : : int i, j;
510 : :
511 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
512 : :
513 : 0 : dev = &rte_eth_devices[port];
514 [ # # ]: 0 : if (!is_bnxt_supported(dev))
515 : : return -ENOTSUP;
516 : :
517 : 0 : bp = dev->data->dev_private;
518 [ # # ]: 0 : if (!bp->pf->vf_info)
519 : : return -EINVAL;
520 : :
521 [ # # ]: 0 : for (i = 0; vf_mask; i++, vf_mask >>= 1) {
522 : 0 : cnt = bp->pf->vf_info[i].vlan_count;
523 [ # # ]: 0 : if ((vf_mask & 1) == 0)
524 : 0 : continue;
525 : :
526 [ # # ]: 0 : if (bp->pf->vf_info[i].vlan_table == NULL) {
527 : : rc = -1;
528 : 0 : continue;
529 : : }
530 [ # # ]: 0 : if (bp->pf->vf_info[i].vlan_as_table == NULL) {
531 : : rc = -1;
532 : 0 : continue;
533 : : }
534 [ # # ]: 0 : if (vlan_on) {
535 : : /* First, search for a duplicate... */
536 [ # # ]: 0 : for (j = 0; j < cnt; j++) {
537 [ # # ]: 0 : if (rte_be_to_cpu_16(
538 [ # # ]: 0 : bp->pf->vf_info[i].vlan_table[j].vid) ==
539 : : vlan)
540 : : break;
541 : : }
542 [ # # ]: 0 : if (j == cnt) {
543 : : /* Now check that there's space */
544 [ # # ]: 0 : if (cnt == getpagesize() / sizeof(struct
545 : : bnxt_vlan_antispoof_table_entry)) {
546 : 0 : PMD_DRV_LOG_LINE(ERR,
547 : : "VLAN anti-spoof table is full");
548 : 0 : PMD_DRV_LOG_LINE(ERR,
549 : : "VF %d cannot add VLAN %u",
550 : : i, vlan);
551 : : rc = -1;
552 : 0 : continue;
553 : : }
554 : :
555 : : /* cnt is one less than vlan_count */
556 : 0 : cnt = bp->pf->vf_info[i].vlan_count++;
557 : : /*
558 : : * And finally, add to the
559 : : * end of the table
560 : : */
561 : 0 : vase = &bp->pf->vf_info[i].vlan_as_table[cnt];
562 : : // TODO: Hardcoded TPID
563 : 0 : vase->tpid = rte_cpu_to_be_16(0x8100);
564 [ # # ]: 0 : vase->vid = rte_cpu_to_be_16(vlan);
565 : 0 : vase->mask = rte_cpu_to_be_16(0xfff);
566 : 0 : ve = &bp->pf->vf_info[i].vlan_table[cnt];
567 : : /* TODO: Hardcoded TPID */
568 : 0 : ve->tpid = rte_cpu_to_be_16(0x8100);
569 [ # # ]: 0 : ve->vid = rte_cpu_to_be_16(vlan);
570 : : }
571 : : } else {
572 [ # # ]: 0 : for (j = 0; j < cnt; j++) {
573 [ # # ]: 0 : if (rte_be_to_cpu_16(
574 [ # # ]: 0 : bp->pf->vf_info[i].vlan_table[j].vid) !=
575 : : vlan)
576 : 0 : continue;
577 : 0 : memmove(&bp->pf->vf_info[i].vlan_table[j],
578 : 0 : &bp->pf->vf_info[i].vlan_table[j + 1],
579 : 0 : getpagesize() - ((j + 1) *
580 : : sizeof(struct bnxt_vlan_table_entry)));
581 : 0 : memmove(&bp->pf->vf_info[i].vlan_as_table[j],
582 : 0 : &bp->pf->vf_info[i].vlan_as_table[j + 1],
583 : 0 : getpagesize() - ((j + 1) * sizeof(struct
584 : : bnxt_vlan_antispoof_table_entry)));
585 : 0 : j--;
586 : 0 : cnt = --bp->pf->vf_info[i].vlan_count;
587 : : }
588 : : }
589 : 0 : bnxt_set_vf_table(bp, i);
590 : : }
591 : :
592 : : return rc;
593 : : }
594 : :
595 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_get_vf_stats)
596 : 0 : int rte_pmd_bnxt_get_vf_stats(uint16_t port,
597 : : uint16_t vf_id,
598 : : struct rte_eth_stats *stats)
599 : : {
600 : : struct rte_eth_dev *dev;
601 : : struct rte_eth_dev_info dev_info;
602 : : struct bnxt *bp;
603 : : int rc;
604 : :
605 : 0 : dev = &rte_eth_devices[port];
606 [ # # ]: 0 : if (!is_bnxt_supported(dev))
607 : : return -ENOTSUP;
608 : :
609 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
610 [ # # ]: 0 : if (rc != 0) {
611 : 0 : PMD_DRV_LOG_LINE(ERR,
612 : : "Error during getting device (port %u) info: %s",
613 : : port, strerror(-rc));
614 : :
615 : 0 : return rc;
616 : : }
617 : 0 : bp = dev->data->dev_private;
618 : :
619 [ # # ]: 0 : if (vf_id >= dev_info.max_vfs)
620 : : return -EINVAL;
621 : :
622 [ # # ]: 0 : if (!BNXT_PF(bp)) {
623 : 0 : PMD_DRV_LOG_LINE(ERR,
624 : : "Attempt to get VF %d stats on non-PF port %d!",
625 : : vf_id, port);
626 : 0 : return -ENOTSUP;
627 : : }
628 : :
629 : 0 : return bnxt_hwrm_func_qstats(bp, bp->pf->first_vf_id + vf_id, stats,
630 : : NULL);
631 : : }
632 : :
633 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_reset_vf_stats)
634 : 0 : int rte_pmd_bnxt_reset_vf_stats(uint16_t port,
635 : : uint16_t vf_id)
636 : : {
637 : : struct rte_eth_dev *dev;
638 : : struct rte_eth_dev_info dev_info;
639 : : struct bnxt *bp;
640 : : int rc;
641 : :
642 : 0 : dev = &rte_eth_devices[port];
643 [ # # ]: 0 : if (!is_bnxt_supported(dev))
644 : : return -ENOTSUP;
645 : :
646 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
647 [ # # ]: 0 : if (rc != 0) {
648 : 0 : PMD_DRV_LOG_LINE(ERR,
649 : : "Error during getting device (port %u) info: %s",
650 : : port, strerror(-rc));
651 : :
652 : 0 : return rc;
653 : : }
654 : 0 : bp = dev->data->dev_private;
655 : :
656 [ # # ]: 0 : if (vf_id >= dev_info.max_vfs)
657 : : return -EINVAL;
658 : :
659 [ # # ]: 0 : if (!BNXT_PF(bp)) {
660 : 0 : PMD_DRV_LOG_LINE(ERR,
661 : : "Attempt to reset VF %d stats on non-PF port %d!",
662 : : vf_id, port);
663 : 0 : return -ENOTSUP;
664 : : }
665 : :
666 : 0 : return bnxt_hwrm_func_clr_stats(bp, bp->pf->first_vf_id + vf_id);
667 : : }
668 : :
669 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_get_vf_rx_status)
670 : 0 : int rte_pmd_bnxt_get_vf_rx_status(uint16_t port, uint16_t vf_id)
671 : : {
672 : : struct rte_eth_dev *dev;
673 : : struct rte_eth_dev_info dev_info;
674 : : struct bnxt *bp;
675 : : int rc;
676 : :
677 : 0 : dev = &rte_eth_devices[port];
678 [ # # ]: 0 : if (!is_bnxt_supported(dev))
679 : : return -ENOTSUP;
680 : :
681 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
682 [ # # ]: 0 : if (rc != 0) {
683 : 0 : PMD_DRV_LOG_LINE(ERR,
684 : : "Error during getting device (port %u) info: %s",
685 : : port, strerror(-rc));
686 : :
687 : 0 : return rc;
688 : : }
689 : 0 : bp = dev->data->dev_private;
690 : :
691 [ # # ]: 0 : if (vf_id >= dev_info.max_vfs)
692 : : return -EINVAL;
693 : :
694 [ # # ]: 0 : if (!BNXT_PF(bp)) {
695 : 0 : PMD_DRV_LOG_LINE(ERR,
696 : : "Attempt to query VF %d RX stats on non-PF port %d!",
697 : : vf_id, port);
698 : 0 : return -ENOTSUP;
699 : : }
700 : :
701 : 0 : return bnxt_vf_vnic_count(bp, vf_id);
702 : : }
703 : :
704 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_get_vf_tx_drop_count)
705 : 0 : int rte_pmd_bnxt_get_vf_tx_drop_count(uint16_t port, uint16_t vf_id,
706 : : uint64_t *count)
707 : : {
708 : : struct rte_eth_dev *dev;
709 : : struct rte_eth_dev_info dev_info;
710 : : struct bnxt *bp;
711 : : int rc;
712 : :
713 : 0 : dev = &rte_eth_devices[port];
714 [ # # ]: 0 : if (!is_bnxt_supported(dev))
715 : : return -ENOTSUP;
716 : :
717 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
718 [ # # ]: 0 : if (rc != 0) {
719 : 0 : PMD_DRV_LOG_LINE(ERR,
720 : : "Error during getting device (port %u) info: %s",
721 : : port, strerror(-rc));
722 : :
723 : 0 : return rc;
724 : : }
725 : 0 : bp = dev->data->dev_private;
726 : :
727 [ # # ]: 0 : if (vf_id >= dev_info.max_vfs)
728 : : return -EINVAL;
729 : :
730 [ # # ]: 0 : if (!BNXT_PF(bp)) {
731 : 0 : PMD_DRV_LOG_LINE(ERR,
732 : : "Attempt to query VF %d TX drops on non-PF port %d!",
733 : : vf_id, port);
734 : 0 : return -ENOTSUP;
735 : : }
736 : :
737 : 0 : return bnxt_hwrm_func_qstats_tx_drop(bp, bp->pf->first_vf_id + vf_id,
738 : : count);
739 : : }
740 : :
741 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_mac_addr_add)
742 : 0 : int rte_pmd_bnxt_mac_addr_add(uint16_t port, struct rte_ether_addr *addr,
743 : : uint32_t vf_id)
744 : : {
745 : : struct rte_eth_dev *dev;
746 : : struct rte_eth_dev_info dev_info;
747 : : struct bnxt *bp;
748 : : struct bnxt_filter_info *filter;
749 : : struct bnxt_vnic_info vnic;
750 : : struct rte_ether_addr dflt_mac;
751 : : int rc;
752 : :
753 : 0 : dev = &rte_eth_devices[port];
754 [ # # ]: 0 : if (!is_bnxt_supported(dev))
755 : : return -ENOTSUP;
756 : :
757 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
758 [ # # ]: 0 : if (rc != 0) {
759 : 0 : PMD_DRV_LOG_LINE(ERR,
760 : : "Error during getting device (port %u) info: %s",
761 : : port, strerror(-rc));
762 : :
763 : 0 : return rc;
764 : : }
765 : 0 : bp = dev->data->dev_private;
766 : :
767 [ # # ]: 0 : if (vf_id >= dev_info.max_vfs)
768 : : return -EINVAL;
769 : :
770 [ # # ]: 0 : if (!BNXT_PF(bp)) {
771 : 0 : PMD_DRV_LOG_LINE(ERR,
772 : : "Attempt to config VF %d MAC on non-PF port %d!",
773 : : vf_id, port);
774 : 0 : return -ENOTSUP;
775 : : }
776 : :
777 : : /* If the VF currently uses a random MAC, update default to this one */
778 [ # # ]: 0 : if (bp->pf->vf_info[vf_id].random_mac) {
779 [ # # ]: 0 : if (rte_pmd_bnxt_get_vf_rx_status(port, vf_id) <= 0)
780 : 0 : bnxt_hwrm_func_vf_mac(bp, vf_id, (uint8_t *)addr);
781 : : }
782 : :
783 : : /* query the default VNIC id used by the function */
784 : 0 : rc = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf_id);
785 [ # # ]: 0 : if (rc < 0)
786 : 0 : goto exit;
787 : :
788 : : memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
789 : 0 : vnic.fw_vnic_id = rte_le_to_cpu_16(rc);
790 : 0 : rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf->first_vf_id + vf_id);
791 [ # # ]: 0 : if (rc < 0)
792 : 0 : goto exit;
793 : :
794 [ # # ]: 0 : STAILQ_FOREACH(filter, &bp->pf->vf_info[vf_id].filter, next) {
795 : 0 : if (filter->flags ==
796 [ # # ]: 0 : HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX &&
797 : : filter->enables ==
798 : : (HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
799 : 0 : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK) &&
800 [ # # ]: 0 : memcmp(addr, filter->l2_addr, RTE_ETHER_ADDR_LEN) == 0) {
801 : 0 : bnxt_hwrm_clear_l2_filter(bp, filter);
802 : 0 : break;
803 : : }
804 : : }
805 : :
806 [ # # ]: 0 : if (filter == NULL)
807 : 0 : filter = bnxt_alloc_vf_filter(bp, vf_id);
808 : :
809 : 0 : filter->fw_l2_filter_id = UINT64_MAX;
810 : 0 : filter->flags = HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
811 : 0 : filter->enables = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
812 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
813 : 0 : memcpy(filter->l2_addr, addr, RTE_ETHER_ADDR_LEN);
814 : 0 : memset(filter->l2_addr_mask, 0xff, RTE_ETHER_ADDR_LEN);
815 : :
816 : : /* Do not add a filter for the default MAC */
817 [ # # ]: 0 : if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf_id, &dflt_mac) ||
818 [ # # ]: 0 : memcmp(filter->l2_addr, dflt_mac.addr_bytes, RTE_ETHER_ADDR_LEN))
819 : 0 : rc = bnxt_hwrm_set_l2_filter(bp, vnic.fw_vnic_id, filter);
820 : :
821 : 0 : exit:
822 : : return rc;
823 : : }
824 : :
825 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_vlan_insert)
826 : : int
827 : 0 : rte_pmd_bnxt_set_vf_vlan_insert(uint16_t port, uint16_t vf,
828 : : uint16_t vlan_id)
829 : : {
830 : : struct rte_eth_dev *dev;
831 : : struct rte_eth_dev_info dev_info;
832 : : struct bnxt *bp;
833 : : int rc;
834 : :
835 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
836 : :
837 : 0 : dev = &rte_eth_devices[port];
838 [ # # ]: 0 : if (!is_bnxt_supported(dev))
839 : : return -ENOTSUP;
840 : :
841 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
842 [ # # ]: 0 : if (rc != 0) {
843 : 0 : PMD_DRV_LOG_LINE(ERR,
844 : : "Error during getting device (port %u) info: %s",
845 : : port, strerror(-rc));
846 : :
847 : 0 : return rc;
848 : : }
849 : 0 : bp = dev->data->dev_private;
850 : :
851 [ # # ]: 0 : if (vf >= dev_info.max_vfs)
852 : : return -EINVAL;
853 : :
854 [ # # ]: 0 : if (!BNXT_PF(bp)) {
855 : 0 : PMD_DRV_LOG_LINE(ERR,
856 : : "Attempt to set VF %d vlan insert on non-PF port %d!",
857 : : vf, port);
858 : 0 : return -ENOTSUP;
859 : : }
860 : :
861 : 0 : bp->pf->vf_info[vf].dflt_vlan = vlan_id;
862 : 0 : if (bnxt_hwrm_func_qcfg_current_vf_vlan(bp, vf) ==
863 [ # # ]: 0 : bp->pf->vf_info[vf].dflt_vlan)
864 : : return 0;
865 : :
866 : 0 : rc = bnxt_hwrm_set_vf_vlan(bp, vf);
867 : :
868 : 0 : return rc;
869 : : }
870 : :
871 : : RTE_EXPORT_SYMBOL(rte_pmd_bnxt_set_vf_persist_stats)
872 : 0 : int rte_pmd_bnxt_set_vf_persist_stats(uint16_t port, uint16_t vf, uint8_t on)
873 : : {
874 : : struct rte_eth_dev_info dev_info;
875 : : struct rte_eth_dev *dev;
876 : : uint32_t func_flags;
877 : : struct bnxt *bp;
878 : : int rc;
879 : :
880 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
881 : :
882 [ # # ]: 0 : if (on > 1)
883 : : return -EINVAL;
884 : :
885 : : dev = &rte_eth_devices[port];
886 : 0 : rc = rte_eth_dev_info_get(port, &dev_info);
887 [ # # ]: 0 : if (rc != 0) {
888 : 0 : PMD_DRV_LOG_LINE(ERR,
889 : : "Error during getting device (port %u) info: %s",
890 : : port, strerror(-rc));
891 : :
892 : 0 : return rc;
893 : : }
894 : 0 : bp = dev->data->dev_private;
895 : :
896 [ # # ]: 0 : if (!BNXT_PF(bp)) {
897 : 0 : PMD_DRV_LOG_LINE(ERR,
898 : : "Attempt to set persist stats on non-PF port %d!",
899 : : port);
900 : 0 : return -EINVAL;
901 : : }
902 : :
903 [ # # ]: 0 : if (vf >= dev_info.max_vfs)
904 : : return -EINVAL;
905 : :
906 : : /* Prev setting same as new setting. */
907 [ # # ]: 0 : if (on == bp->pf->vf_info[vf].persist_stats)
908 : : return 0;
909 : :
910 : 0 : func_flags = bp->pf->vf_info[vf].func_cfg_flags;
911 : :
912 [ # # ]: 0 : if (on)
913 : 0 : func_flags |=
914 : : HWRM_FUNC_CFG_INPUT_FLAGS_NO_AUTOCLEAR_STATISTIC;
915 : : else
916 : 0 : func_flags &=
917 : : ~HWRM_FUNC_CFG_INPUT_FLAGS_NO_AUTOCLEAR_STATISTIC;
918 : :
919 : 0 : rc = bnxt_hwrm_func_cfg_vf_set_flags(bp, vf, func_flags);
920 [ # # ]: 0 : if (!rc) {
921 : 0 : bp->pf->vf_info[vf].persist_stats = on;
922 : 0 : bp->pf->vf_info[vf].func_cfg_flags = func_flags;
923 : : }
924 : :
925 : : return rc;
926 : : }
|