1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017-2018 Broadcom
11 #include <rte_ethdev_driver.h>
12 #include <rte_malloc.h>
13 #include <rte_cycles.h>
14 #include <rte_byteorder.h>
17 #include "bnxt_filter.h"
18 #include "bnxt_hwrm.h"
19 #include "bnxt_vnic.h"
20 #include "rte_pmd_bnxt.h"
21 #include "hsi_struct_def_dpdk.h"
23 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg)
25 struct rte_pmd_bnxt_mb_event_param ret_param;
27 ret_param.retval = RTE_PMD_BNXT_MB_EVENT_PROCEED;
28 ret_param.vf_id = vf_id;
31 _rte_eth_dev_callback_process(bp->eth_dev, RTE_ETH_EVENT_VF_MBOX,
34 /* Default to approve */
35 if (ret_param.retval == RTE_PMD_BNXT_MB_EVENT_PROCEED)
36 ret_param.retval = RTE_PMD_BNXT_MB_EVENT_NOOP_ACK;
38 return ret_param.retval == RTE_PMD_BNXT_MB_EVENT_NOOP_ACK ?
42 int rte_pmd_bnxt_set_tx_loopback(uint16_t port, uint8_t on)
44 struct rte_eth_dev *eth_dev;
48 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
53 eth_dev = &rte_eth_devices[port];
54 if (!is_bnxt_supported(eth_dev))
57 bp = eth_dev->data->dev_private;
61 "Attempt to set Tx loopback on non-PF port %d!\n",
67 bp->pf.evb_mode = BNXT_EVB_MODE_VEB;
69 bp->pf.evb_mode = BNXT_EVB_MODE_VEPA;
71 rc = bnxt_hwrm_pf_evb_mode(bp);
77 rte_pmd_bnxt_set_all_queues_drop_en_cb(struct bnxt_vnic_info *vnic, void *onptr)
80 vnic->bd_stall = !(*on);
83 int rte_pmd_bnxt_set_all_queues_drop_en(uint16_t port, uint8_t on)
85 struct rte_eth_dev *eth_dev;
90 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
95 eth_dev = &rte_eth_devices[port];
96 if (!is_bnxt_supported(eth_dev))
99 bp = eth_dev->data->dev_private;
103 "Attempt to set all queues drop on non-PF port!\n");
107 if (bp->vnic_info == NULL)
111 for (i = 0; i < bp->nr_vnics; i++) {
112 bp->vnic_info[i].bd_stall = !on;
113 rc = bnxt_hwrm_vnic_cfg(bp, &bp->vnic_info[i]);
115 PMD_DRV_LOG(ERR, "Failed to update PF VNIC %d.\n", i);
120 /* Stall all active VFs */
121 for (i = 0; i < bp->pf.active_vfs; i++) {
122 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, i,
123 rte_pmd_bnxt_set_all_queues_drop_en_cb, &on,
126 PMD_DRV_LOG(ERR, "Failed to update VF VNIC %d.\n", i);
134 int rte_pmd_bnxt_set_vf_mac_addr(uint16_t port, uint16_t vf,
135 struct rte_ether_addr *mac_addr)
137 struct rte_eth_dev *dev;
138 struct rte_eth_dev_info dev_info;
142 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
144 dev = &rte_eth_devices[port];
145 if (!is_bnxt_supported(dev))
148 rc = rte_eth_dev_info_get(port, &dev_info);
151 "Error during getting device (port %u) info: %s\n",
152 port, strerror(-rc));
157 bp = dev->data->dev_private;
159 if (vf >= dev_info.max_vfs || mac_addr == NULL)
164 "Attempt to set VF %d mac address on non-PF port %d!\n",
169 rc = bnxt_hwrm_func_vf_mac(bp, vf, (uint8_t *)mac_addr);
174 int rte_pmd_bnxt_set_vf_rate_limit(uint16_t port, uint16_t vf,
175 uint16_t tx_rate, uint64_t q_msk)
177 struct rte_eth_dev *eth_dev;
178 struct rte_eth_dev_info dev_info;
180 uint16_t tot_rate = 0;
184 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
186 eth_dev = &rte_eth_devices[port];
187 if (!is_bnxt_supported(eth_dev))
190 rc = rte_eth_dev_info_get(port, &dev_info);
193 "Error during getting device (port %u) info: %s\n",
194 port, strerror(-rc));
198 bp = eth_dev->data->dev_private;
200 if (!bp->pf.active_vfs)
203 if (vf >= bp->pf.max_vfs)
206 /* Add up the per queue BW and configure MAX BW of the VF */
207 for (idx = 0; idx < 64; idx++) {
208 if ((1ULL << idx) & q_msk)
212 /* Requested BW can't be greater than link speed */
213 if (tot_rate > eth_dev->data->dev_link.link_speed) {
214 PMD_DRV_LOG(ERR, "Rate > Link speed. Set to %d\n", tot_rate);
218 /* Requested BW already configured */
219 if (tot_rate == bp->pf.vf_info[vf].max_tx_rate)
222 rc = bnxt_hwrm_func_bw_cfg(bp, vf, tot_rate,
223 HWRM_FUNC_CFG_INPUT_ENABLES_MAX_BW);
226 bp->pf.vf_info[vf].max_tx_rate = tot_rate;
231 int rte_pmd_bnxt_set_vf_mac_anti_spoof(uint16_t port, uint16_t vf, uint8_t on)
233 struct rte_eth_dev_info dev_info;
234 struct rte_eth_dev *dev;
239 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
244 dev = &rte_eth_devices[port];
245 if (!is_bnxt_supported(dev))
248 rc = rte_eth_dev_info_get(port, &dev_info);
251 "Error during getting device (port %u) info: %s\n",
252 port, strerror(-rc));
256 bp = dev->data->dev_private;
260 "Attempt to set mac spoof on non-PF port %d!\n", port);
264 if (vf >= dev_info.max_vfs)
267 /* Prev setting same as new setting. */
268 if (on == bp->pf.vf_info[vf].mac_spoof_en)
271 func_flags = bp->pf.vf_info[vf].func_cfg_flags;
272 func_flags &= ~(HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE |
273 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE);
277 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE;
280 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE;
282 rc = bnxt_hwrm_func_cfg_vf_set_flags(bp, vf, func_flags);
284 bp->pf.vf_info[vf].mac_spoof_en = on;
285 bp->pf.vf_info[vf].func_cfg_flags = func_flags;
291 int rte_pmd_bnxt_set_vf_vlan_anti_spoof(uint16_t port, uint16_t vf, uint8_t on)
293 struct rte_eth_dev_info dev_info;
294 struct rte_eth_dev *dev;
298 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
303 dev = &rte_eth_devices[port];
304 if (!is_bnxt_supported(dev))
307 rc = rte_eth_dev_info_get(port, &dev_info);
310 "Error during getting device (port %u) info: %s\n",
311 port, strerror(-rc));
315 bp = dev->data->dev_private;
319 "Attempt to set VLAN spoof on non-PF port %d!\n", port);
323 if (vf >= dev_info.max_vfs)
326 rc = bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(bp, vf, on);
328 bp->pf.vf_info[vf].vlan_spoof_en = on;
330 if (bnxt_hwrm_cfa_vlan_antispoof_cfg(bp,
331 bp->pf.first_vf_id + vf,
332 bp->pf.vf_info[vf].vlan_count,
333 bp->pf.vf_info[vf].vlan_as_table))
337 PMD_DRV_LOG(ERR, "Failed to update VF VNIC %d.\n", vf);
344 rte_pmd_bnxt_set_vf_vlan_stripq_cb(struct bnxt_vnic_info *vnic, void *onptr)
347 vnic->vlan_strip = *on;
351 rte_pmd_bnxt_set_vf_vlan_stripq(uint16_t port, uint16_t vf, uint8_t on)
353 struct rte_eth_dev *dev;
354 struct rte_eth_dev_info dev_info;
358 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
360 dev = &rte_eth_devices[port];
361 if (!is_bnxt_supported(dev))
364 rc = rte_eth_dev_info_get(port, &dev_info);
367 "Error during getting device (port %u) info: %s\n",
368 port, strerror(-rc));
372 bp = dev->data->dev_private;
374 if (vf >= dev_info.max_vfs)
379 "Attempt to set VF %d stripq on non-PF port %d!\n",
384 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
385 rte_pmd_bnxt_set_vf_vlan_stripq_cb, &on,
388 PMD_DRV_LOG(ERR, "Failed to update VF VNIC %d.\n", vf);
393 int rte_pmd_bnxt_set_vf_rxmode(uint16_t port, uint16_t vf,
394 uint16_t rx_mask, uint8_t on)
396 struct rte_eth_dev *dev;
397 struct rte_eth_dev_info dev_info;
402 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
404 dev = &rte_eth_devices[port];
405 if (!is_bnxt_supported(dev))
408 rc = rte_eth_dev_info_get(port, &dev_info);
411 "Error during getting device (port %u) info: %s\n",
412 port, strerror(-rc));
416 bp = dev->data->dev_private;
421 if (vf >= bp->pdev->max_vfs)
424 if (rx_mask & ETH_VMDQ_ACCEPT_UNTAG) {
425 PMD_DRV_LOG(ERR, "Currently cannot toggle this setting\n");
429 /* Is this really the correct mapping? VFd seems to think it is. */
430 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC)
431 flag |= BNXT_VNIC_INFO_PROMISC;
433 if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
434 flag |= BNXT_VNIC_INFO_BCAST;
435 if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
436 flag |= BNXT_VNIC_INFO_ALLMULTI | BNXT_VNIC_INFO_MCAST;
439 bp->pf.vf_info[vf].l2_rx_mask |= flag;
441 bp->pf.vf_info[vf].l2_rx_mask &= ~flag;
443 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
444 vf_vnic_set_rxmask_cb,
445 &bp->pf.vf_info[vf].l2_rx_mask,
446 bnxt_set_rx_mask_no_vlan);
448 PMD_DRV_LOG(ERR, "bnxt_hwrm_func_vf_vnic_set_rxmask failed\n");
453 static int bnxt_set_vf_table(struct bnxt *bp, uint16_t vf)
457 struct bnxt_vnic_info vnic;
461 "Attempt to set VLAN table on non-PF port!\n");
465 if (vf >= bp->pdev->max_vfs)
468 dflt_vnic = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf);
470 /* This simply indicates there's no driver loaded.
471 * This is not an error.
473 PMD_DRV_LOG(ERR, "Unable to get default VNIC for VF %d\n", vf);
475 memset(&vnic, 0, sizeof(vnic));
476 vnic.fw_vnic_id = dflt_vnic;
477 if (bnxt_hwrm_vnic_qcfg(bp, &vnic,
478 bp->pf.first_vf_id + vf) == 0) {
479 if (bnxt_hwrm_cfa_l2_set_rx_mask(bp, &vnic,
480 bp->pf.vf_info[vf].vlan_count,
481 bp->pf.vf_info[vf].vlan_table))
491 int rte_pmd_bnxt_set_vf_vlan_filter(uint16_t port, uint16_t vlan,
492 uint64_t vf_mask, uint8_t vlan_on)
494 struct bnxt_vlan_table_entry *ve;
495 struct bnxt_vlan_antispoof_table_entry *vase;
496 struct rte_eth_dev *dev;
502 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
504 dev = &rte_eth_devices[port];
505 if (!is_bnxt_supported(dev))
508 bp = dev->data->dev_private;
512 for (i = 0; vf_mask; i++, vf_mask >>= 1) {
513 cnt = bp->pf.vf_info[i].vlan_count;
514 if ((vf_mask & 1) == 0)
517 if (bp->pf.vf_info[i].vlan_table == NULL) {
521 if (bp->pf.vf_info[i].vlan_as_table == NULL) {
526 /* First, search for a duplicate... */
527 for (j = 0; j < cnt; j++) {
528 if (rte_be_to_cpu_16(
529 bp->pf.vf_info[i].vlan_table[j].vid) == vlan)
533 /* Now check that there's space */
534 if (cnt == getpagesize() / sizeof(struct
535 bnxt_vlan_antispoof_table_entry)) {
537 "VLAN anti-spoof table is full\n");
539 "VF %d cannot add VLAN %u\n",
545 /* cnt is one less than vlan_count */
546 cnt = bp->pf.vf_info[i].vlan_count++;
548 * And finally, add to the
551 vase = &bp->pf.vf_info[i].vlan_as_table[cnt];
552 // TODO: Hardcoded TPID
553 vase->tpid = rte_cpu_to_be_16(0x8100);
554 vase->vid = rte_cpu_to_be_16(vlan);
555 vase->mask = rte_cpu_to_be_16(0xfff);
556 ve = &bp->pf.vf_info[i].vlan_table[cnt];
557 /* TODO: Hardcoded TPID */
558 ve->tpid = rte_cpu_to_be_16(0x8100);
559 ve->vid = rte_cpu_to_be_16(vlan);
562 for (j = 0; j < cnt; j++) {
563 if (rte_be_to_cpu_16(
564 bp->pf.vf_info[i].vlan_table[j].vid) != vlan)
566 memmove(&bp->pf.vf_info[i].vlan_table[j],
567 &bp->pf.vf_info[i].vlan_table[j + 1],
568 getpagesize() - ((j + 1) *
569 sizeof(struct bnxt_vlan_table_entry)));
570 memmove(&bp->pf.vf_info[i].vlan_as_table[j],
571 &bp->pf.vf_info[i].vlan_as_table[j + 1],
572 getpagesize() - ((j + 1) * sizeof(struct
573 bnxt_vlan_antispoof_table_entry)));
575 cnt = --bp->pf.vf_info[i].vlan_count;
578 bnxt_set_vf_table(bp, i);
584 int rte_pmd_bnxt_get_vf_stats(uint16_t port,
586 struct rte_eth_stats *stats)
588 struct rte_eth_dev *dev;
589 struct rte_eth_dev_info dev_info;
593 dev = &rte_eth_devices[port];
594 if (!is_bnxt_supported(dev))
597 rc = rte_eth_dev_info_get(port, &dev_info);
600 "Error during getting device (port %u) info: %s\n",
601 port, strerror(-rc));
605 bp = dev->data->dev_private;
607 if (vf_id >= dev_info.max_vfs)
612 "Attempt to get VF %d stats on non-PF port %d!\n",
617 return bnxt_hwrm_func_qstats(bp, bp->pf.first_vf_id + vf_id, stats,
621 int rte_pmd_bnxt_reset_vf_stats(uint16_t port,
624 struct rte_eth_dev *dev;
625 struct rte_eth_dev_info dev_info;
629 dev = &rte_eth_devices[port];
630 if (!is_bnxt_supported(dev))
633 rc = rte_eth_dev_info_get(port, &dev_info);
636 "Error during getting device (port %u) info: %s\n",
637 port, strerror(-rc));
641 bp = dev->data->dev_private;
643 if (vf_id >= dev_info.max_vfs)
648 "Attempt to reset VF %d stats on non-PF port %d!\n",
653 return bnxt_hwrm_func_clr_stats(bp, bp->pf.first_vf_id + vf_id);
656 int rte_pmd_bnxt_get_vf_rx_status(uint16_t port, uint16_t vf_id)
658 struct rte_eth_dev *dev;
659 struct rte_eth_dev_info dev_info;
663 dev = &rte_eth_devices[port];
664 if (!is_bnxt_supported(dev))
667 rc = rte_eth_dev_info_get(port, &dev_info);
670 "Error during getting device (port %u) info: %s\n",
671 port, strerror(-rc));
675 bp = dev->data->dev_private;
677 if (vf_id >= dev_info.max_vfs)
682 "Attempt to query VF %d RX stats on non-PF port %d!\n",
687 return bnxt_vf_vnic_count(bp, vf_id);
690 int rte_pmd_bnxt_get_vf_tx_drop_count(uint16_t port, uint16_t vf_id,
693 struct rte_eth_dev *dev;
694 struct rte_eth_dev_info dev_info;
698 dev = &rte_eth_devices[port];
699 if (!is_bnxt_supported(dev))
702 rc = rte_eth_dev_info_get(port, &dev_info);
705 "Error during getting device (port %u) info: %s\n",
706 port, strerror(-rc));
710 bp = dev->data->dev_private;
712 if (vf_id >= dev_info.max_vfs)
717 "Attempt to query VF %d TX drops on non-PF port %d!\n",
722 return bnxt_hwrm_func_qstats_tx_drop(bp, bp->pf.first_vf_id + vf_id,
726 int rte_pmd_bnxt_mac_addr_add(uint16_t port, struct rte_ether_addr *addr,
729 struct rte_eth_dev *dev;
730 struct rte_eth_dev_info dev_info;
732 struct bnxt_filter_info *filter;
733 struct bnxt_vnic_info vnic;
734 struct rte_ether_addr dflt_mac;
737 dev = &rte_eth_devices[port];
738 if (!is_bnxt_supported(dev))
741 rc = rte_eth_dev_info_get(port, &dev_info);
744 "Error during getting device (port %u) info: %s\n",
745 port, strerror(-rc));
749 bp = dev->data->dev_private;
751 if (vf_id >= dev_info.max_vfs)
756 "Attempt to config VF %d MAC on non-PF port %d!\n",
761 /* If the VF currently uses a random MAC, update default to this one */
762 if (bp->pf.vf_info[vf_id].random_mac) {
763 if (rte_pmd_bnxt_get_vf_rx_status(port, vf_id) <= 0)
764 bnxt_hwrm_func_vf_mac(bp, vf_id, (uint8_t *)addr);
767 /* query the default VNIC id used by the function */
768 rc = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf_id);
772 memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
773 vnic.fw_vnic_id = rte_le_to_cpu_16(rc);
774 rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf_id);
778 STAILQ_FOREACH(filter, &bp->pf.vf_info[vf_id].filter, next) {
780 HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX &&
782 (HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
783 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK) &&
784 memcmp(addr, filter->l2_addr, RTE_ETHER_ADDR_LEN) == 0) {
785 bnxt_hwrm_clear_l2_filter(bp, filter);
791 filter = bnxt_alloc_vf_filter(bp, vf_id);
793 filter->fw_l2_filter_id = UINT64_MAX;
794 filter->flags = HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
795 filter->enables = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
796 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
797 memcpy(filter->l2_addr, addr, RTE_ETHER_ADDR_LEN);
798 memset(filter->l2_addr_mask, 0xff, RTE_ETHER_ADDR_LEN);
800 /* Do not add a filter for the default MAC */
801 if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf_id, &dflt_mac) ||
802 memcmp(filter->l2_addr, dflt_mac.addr_bytes, RTE_ETHER_ADDR_LEN))
803 rc = bnxt_hwrm_set_l2_filter(bp, vnic.fw_vnic_id, filter);
810 rte_pmd_bnxt_set_vf_vlan_insert(uint16_t port, uint16_t vf,
813 struct rte_eth_dev *dev;
814 struct rte_eth_dev_info dev_info;
818 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
820 dev = &rte_eth_devices[port];
821 if (!is_bnxt_supported(dev))
824 rc = rte_eth_dev_info_get(port, &dev_info);
827 "Error during getting device (port %u) info: %s\n",
828 port, strerror(-rc));
832 bp = dev->data->dev_private;
834 if (vf >= dev_info.max_vfs)
839 "Attempt to set VF %d vlan insert on non-PF port %d!\n",
844 bp->pf.vf_info[vf].dflt_vlan = vlan_id;
845 if (bnxt_hwrm_func_qcfg_current_vf_vlan(bp, vf) ==
846 bp->pf.vf_info[vf].dflt_vlan)
849 rc = bnxt_hwrm_set_vf_vlan(bp, vf);
854 int rte_pmd_bnxt_set_vf_persist_stats(uint16_t port, uint16_t vf, uint8_t on)
856 struct rte_eth_dev_info dev_info;
857 struct rte_eth_dev *dev;
862 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
867 dev = &rte_eth_devices[port];
868 rc = rte_eth_dev_info_get(port, &dev_info);
871 "Error during getting device (port %u) info: %s\n",
872 port, strerror(-rc));
876 bp = dev->data->dev_private;
880 "Attempt to set persist stats on non-PF port %d!\n",
885 if (vf >= dev_info.max_vfs)
888 /* Prev setting same as new setting. */
889 if (on == bp->pf.vf_info[vf].persist_stats)
892 func_flags = bp->pf.vf_info[vf].func_cfg_flags;
896 HWRM_FUNC_CFG_INPUT_FLAGS_NO_AUTOCLEAR_STATISTIC;
899 ~HWRM_FUNC_CFG_INPUT_FLAGS_NO_AUTOCLEAR_STATISTIC;
901 rc = bnxt_hwrm_func_cfg_vf_set_flags(bp, vf, func_flags);
903 bp->pf.vf_info[vf].persist_stats = on;
904 bp->pf.vf_info[vf].func_cfg_flags = func_flags;