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 rte_pmd_bnxt_set_tx_loopback(uint8_t port, uint8_t on)
53 struct rte_eth_dev *eth_dev;
57 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
62 eth_dev = &rte_eth_devices[port];
63 if (!is_bnxt_supported(eth_dev))
66 bp = (struct bnxt *)eth_dev->data->dev_private;
70 "Attempt to set Tx loopback on non-PF port %d!\n",
76 bp->pf.evb_mode = BNXT_EVB_MODE_VEB;
78 bp->pf.evb_mode = BNXT_EVB_MODE_VEPA;
80 rc = bnxt_hwrm_pf_evb_mode(bp);
86 rte_pmd_bnxt_set_all_queues_drop_en_cb(struct bnxt_vnic_info *vnic, void *onptr)
89 vnic->bd_stall = !(*on);
92 int rte_pmd_bnxt_set_all_queues_drop_en(uint8_t port, uint8_t on)
94 struct rte_eth_dev *eth_dev;
99 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
104 eth_dev = &rte_eth_devices[port];
105 if (!is_bnxt_supported(eth_dev))
108 bp = (struct bnxt *)eth_dev->data->dev_private;
112 "Attempt to set all queues drop on non-PF port!\n");
116 if (bp->vnic_info == NULL)
120 for (i = 0; i < bp->nr_vnics; i++) {
121 bp->vnic_info[i].bd_stall = !on;
122 rc = bnxt_hwrm_vnic_cfg(bp, &bp->vnic_info[i]);
124 RTE_LOG(ERR, PMD, "Failed to update PF VNIC %d.\n", i);
129 /* Stall all active VFs */
130 for (i = 0; i < bp->pf.active_vfs; i++) {
131 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, i,
132 rte_pmd_bnxt_set_all_queues_drop_en_cb, &on,
135 RTE_LOG(ERR, PMD, "Failed to update VF VNIC %d.\n", i);
143 int rte_pmd_bnxt_set_vf_mac_addr(uint8_t port, uint16_t vf,
144 struct ether_addr *mac_addr)
146 struct rte_eth_dev *dev;
147 struct rte_eth_dev_info dev_info;
151 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
153 dev = &rte_eth_devices[port];
154 if (!is_bnxt_supported(dev))
157 rte_eth_dev_info_get(port, &dev_info);
158 bp = (struct bnxt *)dev->data->dev_private;
160 if (vf >= dev_info.max_vfs || mac_addr == NULL)
165 "Attempt to set VF %d mac address on non-PF port %d!\n",
170 rc = bnxt_hwrm_func_vf_mac(bp, vf, (uint8_t *)mac_addr);
175 int rte_pmd_bnxt_set_vf_rate_limit(uint8_t port, uint16_t vf,
176 uint16_t tx_rate, uint64_t q_msk)
178 struct rte_eth_dev *eth_dev;
179 struct rte_eth_dev_info dev_info;
181 uint16_t tot_rate = 0;
185 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
187 eth_dev = &rte_eth_devices[port];
188 if (!is_bnxt_supported(eth_dev))
191 rte_eth_dev_info_get(port, &dev_info);
192 bp = (struct bnxt *)eth_dev->data->dev_private;
194 if (!bp->pf.active_vfs)
197 if (vf >= bp->pf.max_vfs)
200 /* Add up the per queue BW and configure MAX BW of the VF */
201 for (idx = 0; idx < 64; idx++) {
202 if ((1ULL << idx) & q_msk)
206 /* Requested BW can't be greater than link speed */
207 if (tot_rate > eth_dev->data->dev_link.link_speed) {
208 RTE_LOG(ERR, PMD, "Rate > Link speed. Set to %d\n", tot_rate);
212 /* Requested BW already configured */
213 if (tot_rate == bp->pf.vf_info[vf].max_tx_rate)
216 rc = bnxt_hwrm_func_bw_cfg(bp, vf, tot_rate,
217 HWRM_FUNC_CFG_INPUT_ENABLES_MAX_BW);
220 bp->pf.vf_info[vf].max_tx_rate = tot_rate;
225 int rte_pmd_bnxt_set_vf_mac_anti_spoof(uint8_t port, uint16_t vf, uint8_t on)
227 struct rte_eth_dev_info dev_info;
228 struct rte_eth_dev *dev;
233 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
238 dev = &rte_eth_devices[port];
239 if (!is_bnxt_supported(dev))
242 rte_eth_dev_info_get(port, &dev_info);
243 bp = (struct bnxt *)dev->data->dev_private;
247 "Attempt to set mac spoof on non-PF port %d!\n", port);
251 if (vf >= dev_info.max_vfs)
254 /* Prev setting same as new setting. */
255 if (on == bp->pf.vf_info[vf].mac_spoof_en)
258 func_flags = bp->pf.vf_info[vf].func_cfg_flags;
262 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE;
265 HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE;
267 bp->pf.vf_info[vf].func_cfg_flags = func_flags;
269 rc = bnxt_hwrm_func_cfg_vf_set_flags(bp, vf);
271 bp->pf.vf_info[vf].mac_spoof_en = on;
276 int rte_pmd_bnxt_set_vf_vlan_anti_spoof(uint8_t port, uint16_t vf, uint8_t on)
278 struct rte_eth_dev_info dev_info;
279 struct rte_eth_dev *dev;
283 struct bnxt_vnic_info vnic;
285 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
290 dev = &rte_eth_devices[port];
291 if (!is_bnxt_supported(dev))
294 rte_eth_dev_info_get(port, &dev_info);
295 bp = (struct bnxt *)dev->data->dev_private;
299 "Attempt to set mac spoof on non-PF port %d!\n", port);
303 if (vf >= dev_info.max_vfs)
306 rc = bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(bp, vf, on);
308 bp->pf.vf_info[vf].vlan_spoof_en = on;
310 dflt_vnic = bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(bp, vf);
313 * This simply indicates there's no driver
314 * loaded. This is not an error.
317 "Unable to get default VNIC for VF %d\n",
320 vnic.fw_vnic_id = dflt_vnic;
321 if (bnxt_hwrm_vnic_qcfg(bp,
322 &vnic, bp->pf.first_vf_id + vf) == 0) {
323 if (bnxt_hwrm_cfa_l2_set_rx_mask(bp,
324 &vnic, bp->pf.vf_info[vf].vlan_count,
325 bp->pf.vf_info[vf].vlan_table))
331 RTE_LOG(ERR, PMD, "Failed to update VF VNIC %d.\n", vf);
338 rte_pmd_bnxt_set_vf_vlan_stripq_cb(struct bnxt_vnic_info *vnic, void *onptr)
341 vnic->vlan_strip = *on;
345 rte_pmd_bnxt_set_vf_vlan_stripq(uint8_t port, uint16_t vf, uint8_t on)
347 struct rte_eth_dev *dev;
348 struct rte_eth_dev_info dev_info;
352 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
354 dev = &rte_eth_devices[port];
355 if (!is_bnxt_supported(dev))
358 rte_eth_dev_info_get(port, &dev_info);
359 bp = (struct bnxt *)dev->data->dev_private;
361 if (vf >= dev_info.max_vfs)
366 "Attempt to set VF %d stripq on non-PF port %d!\n",
371 rc = bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf,
372 rte_pmd_bnxt_set_vf_vlan_stripq_cb, &on,
375 RTE_LOG(ERR, PMD, "Failed to update VF VNIC %d.\n", vf);
380 int rte_pmd_bnxt_set_vf_vlan_filter(uint8_t port, uint16_t vlan,
381 uint64_t vf_mask, uint8_t vlan_on)
383 struct bnxt_vlan_table_entry *ve;
384 struct rte_eth_dev *dev;
390 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
392 dev = &rte_eth_devices[port];
393 if (!is_bnxt_supported(dev))
396 bp = (struct bnxt *)dev->data->dev_private;
400 for (i = 0; vf_mask; i++, vf_mask >>= 1) {
401 cnt = bp->pf.vf_info[i].vlan_count;
403 if (bp->pf.vf_info[i].vlan_table == NULL) {
408 /* First, search for a duplicate... */
409 for (j = 0; j < cnt; j++) {
410 if (rte_be_to_cpu_16(
411 bp->pf.vf_info[i].vlan_table[j].vid) ==
416 /* Now check that there's space */
417 if (cnt == getpagesize() /
418 sizeof(struct bnxt_vlan_table_entry)) {
420 "VF %d VLAN table is full\n",
423 "cannot add VLAN %u\n",
429 cnt = bp->pf.vf_info[i].vlan_count++;
431 * And finally, add to the
434 ve = &bp->pf.vf_info[i].vlan_table[cnt];
435 /* TODO: Hardcoded TPID */
436 ve->tpid = rte_cpu_to_be_16(0x8100);
437 ve->vid = rte_cpu_to_be_16(vlan);
440 for (j = 0; cnt; j++) {
441 if (rte_be_to_cpu_16(
442 bp->pf.vf_info[i].vlan_table[j].vid) !=
446 &bp->pf.vf_info[i].vlan_table[j],
447 &bp->pf.vf_info[i].vlan_table[j + 1],
450 sizeof(struct bnxt_vlan_table_entry)));
452 cnt = bp->pf.vf_info[i].vlan_count--;
455 rte_pmd_bnxt_set_vf_vlan_anti_spoof(dev->data->port_id,
456 i, bp->pf.vf_info[i].vlan_spoof_en);