4 * Copyright(c) 2017 Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <rte_ethdev.h>
40 #include <rte_malloc.h>
41 #include <rte_cycles.h>
42 #include <rte_byteorder.h>
45 #include "bnxt_filter.h"
46 #include "bnxt_hwrm.h"
47 #include "bnxt_vnic.h"
48 #include "rte_pmd_bnxt.h"
49 #include "hsi_struct_def_dpdk.h"
51 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg)
53 struct rte_pmd_bnxt_mb_event_param cb_param;
55 cb_param.retval = RTE_PMD_BNXT_MB_EVENT_PROCEED;
56 cb_param.vf_id = vf_id;
59 _rte_eth_dev_callback_process(bp->eth_dev, RTE_ETH_EVENT_VF_MBOX,
62 /* Default to approve */
63 if (cb_param.retval == RTE_PMD_BNXT_MB_EVENT_PROCEED)
64 cb_param.retval = RTE_PMD_BNXT_MB_EVENT_NOOP_ACK;
66 return cb_param.retval == RTE_PMD_BNXT_MB_EVENT_NOOP_ACK ? true : false;
69 int rte_pmd_bnxt_set_tx_loopback(uint8_t port, uint8_t on)
71 struct rte_eth_dev *eth_dev;
75 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
80 eth_dev = &rte_eth_devices[port];
81 if (!is_bnxt_supported(eth_dev))
84 bp = (struct bnxt *)eth_dev->data->dev_private;
88 "Attempt to set Tx loopback on non-PF port %d!\n",
94 bp->pf.evb_mode = BNXT_EVB_MODE_VEB;
96 bp->pf.evb_mode = BNXT_EVB_MODE_VEPA;
98 rc = bnxt_hwrm_pf_evb_mode(bp);
104 rte_pmd_bnxt_set_all_queues_drop_en_cb(struct bnxt_vnic_info *vnic, void *onptr)
107 vnic->bd_stall = !(*on);
110 int rte_pmd_bnxt_set_all_queues_drop_en(uint8_t port, uint8_t on)
112 struct rte_eth_dev *eth_dev;
117 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
122 eth_dev = &rte_eth_devices[port];
123 if (!is_bnxt_supported(eth_dev))
126 bp = (struct bnxt *)eth_dev->data->dev_private;
130 "Attempt to set all queues drop on non-PF port!\n");
134 if (bp->vnic_info == NULL)
138 for (i = 0; i < bp->nr_vnics; i++) {
139 bp->vnic_info[i].bd_stall = !on;
140 rc = bnxt_hwrm_vnic_cfg(bp, &bp->vnic_info[i]);
142 RTE_LOG(ERR, PMD, "Failed to update PF VNIC %d.\n", i);
147 /* Stall all active VFs */
148 for (i = 0; i < bp->pf.active_vfs; i++) {
149 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, i,
150 rte_pmd_bnxt_set_all_queues_drop_en_cb, &on,
153 RTE_LOG(ERR, PMD, "Failed to update VF VNIC %d.\n", i);
161 int rte_pmd_bnxt_set_vf_mac_addr(uint8_t port, uint16_t vf,
162 struct ether_addr *mac_addr)
164 struct rte_eth_dev *dev;
165 struct rte_eth_dev_info dev_info;
169 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
171 dev = &rte_eth_devices[port];
172 if (!is_bnxt_supported(dev))
175 rte_eth_dev_info_get(port, &dev_info);
176 bp = (struct bnxt *)dev->data->dev_private;
178 if (vf >= dev_info.max_vfs || mac_addr == NULL)
183 "Attempt to set VF %d mac address on non-PF port %d!\n",
188 rc = bnxt_hwrm_func_vf_mac(bp, vf, (uint8_t *)mac_addr);
193 int rte_pmd_bnxt_set_vf_rate_limit(uint8_t port, uint16_t vf,
194 uint16_t tx_rate, uint64_t q_msk)
196 struct rte_eth_dev *eth_dev;
197 struct rte_eth_dev_info dev_info;
199 uint16_t tot_rate = 0;
203 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
205 eth_dev = &rte_eth_devices[port];
206 if (!is_bnxt_supported(eth_dev))
209 rte_eth_dev_info_get(port, &dev_info);
210 bp = (struct bnxt *)eth_dev->data->dev_private;
212 if (!bp->pf.active_vfs)
215 if (vf >= bp->pf.max_vfs)
218 /* Add up the per queue BW and configure MAX BW of the VF */
219 for (idx = 0; idx < 64; idx++) {
220 if ((1ULL << idx) & q_msk)
224 /* Requested BW can't be greater than link speed */
225 if (tot_rate > eth_dev->data->dev_link.link_speed) {
226 RTE_LOG(ERR, PMD, "Rate > Link speed. Set to %d\n", tot_rate);
230 /* Requested BW already configured */
231 if (tot_rate == bp->pf.vf_info[vf].max_tx_rate)
234 rc = bnxt_hwrm_func_bw_cfg(bp, vf, tot_rate,
235 HWRM_FUNC_CFG_INPUT_ENABLES_MAX_BW);
238 bp->pf.vf_info[vf].max_tx_rate = tot_rate;
243 int rte_pmd_bnxt_set_vf_mac_anti_spoof(uint8_t port, uint16_t vf, uint8_t on)
245 struct rte_eth_dev_info dev_info;
246 struct rte_eth_dev *dev;
251 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
256 dev = &rte_eth_devices[port];
257 if (!is_bnxt_supported(dev))
260 rte_eth_dev_info_get(port, &dev_info);
261 bp = (struct bnxt *)dev->data->dev_private;
265 "Attempt to set mac spoof on non-PF port %d!\n", port);
269 if (vf >= dev_info.max_vfs)
272 /* Prev setting same as new setting. */
273 if (on == bp->pf.vf_info[vf].mac_spoof_en)
276 func_flags = bp->pf.vf_info[vf].func_cfg_flags;
280 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE;
283 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE;
285 bp->pf.vf_info[vf].func_cfg_flags = func_flags;
287 rc = bnxt_hwrm_func_cfg_vf_set_flags(bp, vf);
289 bp->pf.vf_info[vf].mac_spoof_en = on;
294 int rte_pmd_bnxt_set_vf_vlan_anti_spoof(uint8_t port, uint16_t vf, uint8_t on)
296 struct rte_eth_dev_info dev_info;
297 struct rte_eth_dev *dev;
301 struct bnxt_vnic_info vnic;
303 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
308 dev = &rte_eth_devices[port];
309 if (!is_bnxt_supported(dev))
312 rte_eth_dev_info_get(port, &dev_info);
313 bp = (struct bnxt *)dev->data->dev_private;
317 "Attempt to set mac spoof on non-PF port %d!\n", port);
321 if (vf >= dev_info.max_vfs)
324 rc = bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(bp, vf, on);
326 bp->pf.vf_info[vf].vlan_spoof_en = on;
328 dflt_vnic = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf);
331 * This simply indicates there's no driver
332 * loaded. This is not an error.
335 "Unable to get default VNIC for VF %d\n",
338 vnic.fw_vnic_id = dflt_vnic;
339 if (bnxt_hwrm_vnic_qcfg(bp,
340 &vnic, bp->pf.first_vf_id + vf) == 0) {
341 if (bnxt_hwrm_cfa_l2_set_rx_mask(bp,
342 &vnic, bp->pf.vf_info[vf].vlan_count,
343 bp->pf.vf_info[vf].vlan_table))
349 RTE_LOG(ERR, PMD, "Failed to update VF VNIC %d.\n", vf);
356 rte_pmd_bnxt_set_vf_vlan_stripq_cb(struct bnxt_vnic_info *vnic, void *onptr)
359 vnic->vlan_strip = *on;
363 rte_pmd_bnxt_set_vf_vlan_stripq(uint8_t port, uint16_t vf, uint8_t on)
365 struct rte_eth_dev *dev;
366 struct rte_eth_dev_info dev_info;
370 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
372 dev = &rte_eth_devices[port];
373 if (!is_bnxt_supported(dev))
376 rte_eth_dev_info_get(port, &dev_info);
377 bp = (struct bnxt *)dev->data->dev_private;
379 if (vf >= dev_info.max_vfs)
384 "Attempt to set VF %d stripq on non-PF port %d!\n",
389 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
390 rte_pmd_bnxt_set_vf_vlan_stripq_cb, &on,
393 RTE_LOG(ERR, PMD, "Failed to update VF VNIC %d.\n", vf);
398 int rte_pmd_bnxt_set_vf_rxmode(uint8_t port, uint16_t vf,
399 uint16_t rx_mask, uint8_t on)
401 struct rte_eth_dev *dev;
402 struct rte_eth_dev_info dev_info;
407 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
409 dev = &rte_eth_devices[port];
410 if (!is_bnxt_supported(dev))
413 rte_eth_dev_info_get(port, &dev_info);
414 bp = (struct bnxt *)dev->data->dev_private;
419 if (vf >= bp->pdev->max_vfs)
422 if (rx_mask & (ETH_VMDQ_ACCEPT_UNTAG | ETH_VMDQ_ACCEPT_HASH_MC)) {
423 RTE_LOG(ERR, PMD, "Currently cannot toggle this setting\n");
427 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC && !on) {
428 RTE_LOG(ERR, PMD, "Currently cannot disable UC Rx\n");
432 if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
433 flag |= BNXT_VNIC_INFO_BCAST;
434 if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
435 flag |= BNXT_VNIC_INFO_ALLMULTI;
438 bp->pf.vf_info[vf].l2_rx_mask |= flag;
440 bp->pf.vf_info[vf].l2_rx_mask &= ~flag;
442 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
443 vf_vnic_set_rxmask_cb,
444 &bp->pf.vf_info[vf].l2_rx_mask,
445 bnxt_set_rx_mask_no_vlan);
447 RTE_LOG(ERR, PMD, "bnxt_hwrm_func_vf_vnic_set_rxmask failed\n");
452 int rte_pmd_bnxt_set_vf_vlan_filter(uint8_t port, uint16_t vlan,
453 uint64_t vf_mask, uint8_t vlan_on)
455 struct bnxt_vlan_table_entry *ve;
456 struct rte_eth_dev *dev;
462 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
464 dev = &rte_eth_devices[port];
465 if (!is_bnxt_supported(dev))
468 bp = (struct bnxt *)dev->data->dev_private;
472 for (i = 0; vf_mask; i++, vf_mask >>= 1) {
473 cnt = bp->pf.vf_info[i].vlan_count;
475 if (bp->pf.vf_info[i].vlan_table == NULL) {
480 /* First, search for a duplicate... */
481 for (j = 0; j < cnt; j++) {
482 if (rte_be_to_cpu_16(
483 bp->pf.vf_info[i].vlan_table[j].vid) ==
488 /* Now check that there's space */
489 if (cnt == getpagesize() /
490 sizeof(struct bnxt_vlan_table_entry)) {
492 "VF %d VLAN table is full\n",
495 "cannot add VLAN %u\n",
501 cnt = bp->pf.vf_info[i].vlan_count++;
503 * And finally, add to the
506 ve = &bp->pf.vf_info[i].vlan_table[cnt];
507 /* TODO: Hardcoded TPID */
508 ve->tpid = rte_cpu_to_be_16(0x8100);
509 ve->vid = rte_cpu_to_be_16(vlan);
512 for (j = 0; cnt; j++) {
513 if (rte_be_to_cpu_16(
514 bp->pf.vf_info[i].vlan_table[j].vid) !=
518 &bp->pf.vf_info[i].vlan_table[j],
519 &bp->pf.vf_info[i].vlan_table[j + 1],
522 sizeof(struct bnxt_vlan_table_entry)));
524 cnt = bp->pf.vf_info[i].vlan_count--;
527 rte_pmd_bnxt_set_vf_vlan_anti_spoof(dev->data->port_id,
528 i, bp->pf.vf_info[i].vlan_spoof_en);
535 int rte_pmd_bnxt_get_vf_stats(uint8_t port,
537 struct rte_eth_stats *stats)
539 struct rte_eth_dev *dev;
540 struct rte_eth_dev_info dev_info;
543 dev = &rte_eth_devices[port];
544 if (!is_bnxt_supported(dev))
547 rte_eth_dev_info_get(port, &dev_info);
548 bp = (struct bnxt *)dev->data->dev_private;
550 if (vf_id >= dev_info.max_vfs)
555 "Attempt to get VF %d stats on non-PF port %d!\n",
560 return bnxt_hwrm_func_qstats(bp, bp->pf.first_vf_id + vf_id, stats);
563 int rte_pmd_bnxt_reset_vf_stats(uint8_t port,
566 struct rte_eth_dev *dev;
567 struct rte_eth_dev_info dev_info;
570 dev = &rte_eth_devices[port];
571 if (!is_bnxt_supported(dev))
574 rte_eth_dev_info_get(port, &dev_info);
575 bp = (struct bnxt *)dev->data->dev_private;
577 if (vf_id >= dev_info.max_vfs)
582 "Attempt to reset VF %d stats on non-PF port %d!\n",
587 return bnxt_hwrm_func_clr_stats(bp, bp->pf.first_vf_id + vf_id);
590 int rte_pmd_bnxt_get_vf_rx_status(uint8_t port, uint16_t vf_id)
592 struct rte_eth_dev *dev;
593 struct rte_eth_dev_info dev_info;
596 dev = &rte_eth_devices[port];
597 if (!is_bnxt_supported(dev))
600 rte_eth_dev_info_get(port, &dev_info);
601 bp = (struct bnxt *)dev->data->dev_private;
603 if (vf_id >= dev_info.max_vfs)
608 "Attempt to query VF %d RX stats on non-PF port %d!\n",
613 return bnxt_vf_vnic_count(bp, vf_id);
616 int rte_pmd_bnxt_get_vf_tx_drop_count(uint8_t port, uint16_t vf_id,
619 struct rte_eth_dev *dev;
620 struct rte_eth_dev_info dev_info;
623 dev = &rte_eth_devices[port];
624 if (!is_bnxt_supported(dev))
627 rte_eth_dev_info_get(port, &dev_info);
628 bp = (struct bnxt *)dev->data->dev_private;
630 if (vf_id >= dev_info.max_vfs)
635 "Attempt to query VF %d TX drops on non-PF port %d!\n",
640 return bnxt_hwrm_func_qstats_tx_drop(bp, bp->pf.first_vf_id + vf_id,
644 int rte_pmd_bnxt_mac_addr_add(uint8_t port, struct ether_addr *addr,
647 struct rte_eth_dev *dev;
648 struct rte_eth_dev_info dev_info;
650 struct bnxt_filter_info *filter;
651 struct bnxt_vnic_info vnic;
652 struct ether_addr dflt_mac;
655 dev = &rte_eth_devices[port];
656 if (!is_bnxt_supported(dev))
659 rte_eth_dev_info_get(port, &dev_info);
660 bp = (struct bnxt *)dev->data->dev_private;
662 if (vf_id >= dev_info.max_vfs)
667 "Attempt to config VF %d MAC on non-PF port %d!\n",
672 /* If the VF currently uses a random MAC, update default to this one */
673 if (bp->pf.vf_info[vf_id].random_mac) {
674 if (rte_pmd_bnxt_get_vf_rx_status(port, vf_id) <= 0)
675 rc = bnxt_hwrm_func_vf_mac(bp, vf_id, (uint8_t *)addr);
678 /* query the default VNIC id used by the function */
679 rc = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf_id);
683 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
684 vnic.fw_vnic_id = rte_le_to_cpu_16(rc);
685 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf_id);
689 STAILQ_FOREACH(filter, &bp->pf.vf_info[vf_id].filter, next) {
691 HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX &&
693 (HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
694 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK) &&
695 memcmp(addr, filter->l2_addr, ETHER_ADDR_LEN) == 0) {
696 bnxt_hwrm_clear_filter(bp, filter);
702 filter = bnxt_alloc_vf_filter(bp, vf_id);
704 filter->fw_l2_filter_id = UINT64_MAX;
705 filter->flags = HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
706 filter->enables = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
707 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
708 memcpy(filter->l2_addr, addr, ETHER_ADDR_LEN);
709 memset(filter->l2_addr_mask, 0xff, ETHER_ADDR_LEN);
711 /* Do not add a filter for the default MAC */
712 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf_id, &dflt_mac) ||
713 memcmp(filter->l2_addr, dflt_mac.addr_bytes, ETHER_ADDR_LEN))
714 rc = bnxt_hwrm_set_filter(bp, vnic.fw_vnic_id, filter);
721 rte_pmd_bnxt_set_vf_vlan_insert(uint8_t port, uint16_t vf,
724 struct rte_eth_dev *dev;
725 struct rte_eth_dev_info dev_info;
729 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
731 dev = &rte_eth_devices[port];
732 if (!is_bnxt_supported(dev))
735 rte_eth_dev_info_get(port, &dev_info);
736 bp = (struct bnxt *)dev->data->dev_private;
738 if (vf >= dev_info.max_vfs)
743 "Attempt to set VF %d vlan insert on non-PF port %d!\n",
748 bp->pf.vf_info[vf].dflt_vlan = vlan_id;
749 if (bnxt_hwrm_func_qcfg_current_vf_vlan(bp, vf) ==
750 bp->pf.vf_info[vf].dflt_vlan)
753 rc = bnxt_hwrm_set_vf_vlan(bp, vf);