4 * Copyright(c) 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.
38 #include <rte_ethdev.h>
39 #include <rte_ethdev_pci.h>
40 #include <rte_malloc.h>
41 #include <rte_cycles.h>
45 #include "bnxt_filter.h"
46 #include "bnxt_hwrm.h"
48 #include "bnxt_ring.h"
51 #include "bnxt_stats.h"
54 #include "bnxt_vnic.h"
55 #include "hsi_struct_def_dpdk.h"
56 #include "bnxt_nvm_defs.h"
58 #define DRV_MODULE_NAME "bnxt"
59 static const char bnxt_version[] =
60 "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
62 #define PCI_VENDOR_ID_BROADCOM 0x14E4
64 #define BROADCOM_DEV_ID_STRATUS_NIC_VF 0x1609
65 #define BROADCOM_DEV_ID_STRATUS_NIC 0x1614
66 #define BROADCOM_DEV_ID_57414_VF 0x16c1
67 #define BROADCOM_DEV_ID_57301 0x16c8
68 #define BROADCOM_DEV_ID_57302 0x16c9
69 #define BROADCOM_DEV_ID_57304_PF 0x16ca
70 #define BROADCOM_DEV_ID_57304_VF 0x16cb
71 #define BROADCOM_DEV_ID_57417_MF 0x16cc
72 #define BROADCOM_DEV_ID_NS2 0x16cd
73 #define BROADCOM_DEV_ID_57311 0x16ce
74 #define BROADCOM_DEV_ID_57312 0x16cf
75 #define BROADCOM_DEV_ID_57402 0x16d0
76 #define BROADCOM_DEV_ID_57404 0x16d1
77 #define BROADCOM_DEV_ID_57406_PF 0x16d2
78 #define BROADCOM_DEV_ID_57406_VF 0x16d3
79 #define BROADCOM_DEV_ID_57402_MF 0x16d4
80 #define BROADCOM_DEV_ID_57407_RJ45 0x16d5
81 #define BROADCOM_DEV_ID_57412 0x16d6
82 #define BROADCOM_DEV_ID_57414 0x16d7
83 #define BROADCOM_DEV_ID_57416_RJ45 0x16d8
84 #define BROADCOM_DEV_ID_57417_RJ45 0x16d9
85 #define BROADCOM_DEV_ID_5741X_VF 0x16dc
86 #define BROADCOM_DEV_ID_57412_MF 0x16de
87 #define BROADCOM_DEV_ID_57314 0x16df
88 #define BROADCOM_DEV_ID_57317_RJ45 0x16e0
89 #define BROADCOM_DEV_ID_5731X_VF 0x16e1
90 #define BROADCOM_DEV_ID_57417_SFP 0x16e2
91 #define BROADCOM_DEV_ID_57416_SFP 0x16e3
92 #define BROADCOM_DEV_ID_57317_SFP 0x16e4
93 #define BROADCOM_DEV_ID_57404_MF 0x16e7
94 #define BROADCOM_DEV_ID_57406_MF 0x16e8
95 #define BROADCOM_DEV_ID_57407_SFP 0x16e9
96 #define BROADCOM_DEV_ID_57407_MF 0x16ea
97 #define BROADCOM_DEV_ID_57414_MF 0x16ec
98 #define BROADCOM_DEV_ID_57416_MF 0x16ee
100 static const struct rte_pci_id bnxt_pci_id_map[] = {
101 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
102 BROADCOM_DEV_ID_STRATUS_NIC_VF) },
103 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
104 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
105 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
106 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
107 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
108 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
109 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
110 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
111 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
112 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
113 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
114 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
115 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
116 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
117 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
118 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
119 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
120 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
121 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
122 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
123 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
124 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
125 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
126 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
127 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
128 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
129 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
130 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
131 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
132 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
133 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
134 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
135 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
136 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
137 { .vendor_id = 0, /* sentinel */ },
140 #define BNXT_ETH_RSS_SUPPORT ( \
142 ETH_RSS_NONFRAG_IPV4_TCP | \
143 ETH_RSS_NONFRAG_IPV4_UDP | \
145 ETH_RSS_NONFRAG_IPV6_TCP | \
146 ETH_RSS_NONFRAG_IPV6_UDP)
148 static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
149 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev);
151 /***********************/
154 * High level utility functions
157 static void bnxt_free_mem(struct bnxt *bp)
159 bnxt_free_filter_mem(bp);
160 bnxt_free_vnic_attributes(bp);
161 bnxt_free_vnic_mem(bp);
164 bnxt_free_tx_rings(bp);
165 bnxt_free_rx_rings(bp);
166 bnxt_free_def_cp_ring(bp);
169 static int bnxt_alloc_mem(struct bnxt *bp)
173 /* Default completion ring */
174 rc = bnxt_init_def_ring_struct(bp, SOCKET_ID_ANY);
178 rc = bnxt_alloc_rings(bp, 0, NULL, NULL,
179 bp->def_cp_ring, "def_cp");
183 rc = bnxt_alloc_vnic_mem(bp);
187 rc = bnxt_alloc_vnic_attributes(bp);
191 rc = bnxt_alloc_filter_mem(bp);
202 static int bnxt_init_chip(struct bnxt *bp)
204 unsigned int i, rss_idx, fw_idx;
205 struct rte_eth_link new;
206 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(bp->eth_dev);
207 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
208 uint32_t intr_vector = 0;
209 uint32_t queue_id, base = BNXT_MISC_VEC_ID;
210 uint32_t vec = BNXT_MISC_VEC_ID;
213 /* disable uio/vfio intr/eventfd mapping */
214 rte_intr_disable(intr_handle);
216 if (bp->eth_dev->data->mtu > ETHER_MTU) {
217 bp->eth_dev->data->dev_conf.rxmode.jumbo_frame = 1;
218 bp->flags |= BNXT_FLAG_JUMBO;
220 bp->eth_dev->data->dev_conf.rxmode.jumbo_frame = 0;
221 bp->flags &= ~BNXT_FLAG_JUMBO;
224 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
226 RTE_LOG(ERR, PMD, "HWRM stat ctx alloc failure rc: %x\n", rc);
230 rc = bnxt_alloc_hwrm_rings(bp);
232 RTE_LOG(ERR, PMD, "HWRM ring alloc failure rc: %x\n", rc);
236 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
238 RTE_LOG(ERR, PMD, "HWRM ring grp alloc failure: %x\n", rc);
242 rc = bnxt_mq_rx_configure(bp);
244 RTE_LOG(ERR, PMD, "MQ mode configure failure rc: %x\n", rc);
248 /* VNIC configuration */
249 for (i = 0; i < bp->nr_vnics; i++) {
250 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
252 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
254 RTE_LOG(ERR, PMD, "HWRM vnic %d alloc failure rc: %x\n",
259 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic);
262 "HWRM vnic %d ctx alloc failure rc: %x\n",
267 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
269 RTE_LOG(ERR, PMD, "HWRM vnic %d cfg failure rc: %x\n",
274 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
277 "HWRM vnic %d filter failure rc: %x\n",
281 if (vnic->rss_table && vnic->hash_type) {
283 * Fill the RSS hash & redirection table with
284 * ring group ids for all VNICs
286 for (rss_idx = 0, fw_idx = 0;
287 rss_idx < HW_HASH_INDEX_SIZE;
288 rss_idx++, fw_idx++) {
289 if (vnic->fw_grp_ids[fw_idx] ==
292 vnic->rss_table[rss_idx] =
293 vnic->fw_grp_ids[fw_idx];
295 rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
298 "HWRM vnic %d set RSS failure rc: %x\n",
304 bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
306 if (bp->eth_dev->data->dev_conf.rxmode.enable_lro)
307 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 1);
309 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 0);
311 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
314 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
318 /* check and configure queue intr-vector mapping */
319 if ((rte_intr_cap_multiple(intr_handle) ||
320 !RTE_ETH_DEV_SRIOV(bp->eth_dev).active) &&
321 bp->eth_dev->data->dev_conf.intr_conf.rxq != 0) {
322 intr_vector = bp->eth_dev->data->nb_rx_queues;
323 RTE_LOG(INFO, PMD, "%s(): intr_vector = %d\n", __func__,
325 if (intr_vector > bp->rx_cp_nr_rings) {
326 RTE_LOG(ERR, PMD, "At most %d intr queues supported",
330 if (rte_intr_efd_enable(intr_handle, intr_vector))
334 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
335 intr_handle->intr_vec =
336 rte_zmalloc("intr_vec",
337 bp->eth_dev->data->nb_rx_queues *
339 if (intr_handle->intr_vec == NULL) {
340 RTE_LOG(ERR, PMD, "Failed to allocate %d rx_queues"
341 " intr_vec", bp->eth_dev->data->nb_rx_queues);
344 RTE_LOG(DEBUG, PMD, "%s(): intr_handle->intr_vec = %p "
345 "intr_handle->nb_efd = %d intr_handle->max_intr = %d\n",
346 __func__, intr_handle->intr_vec, intr_handle->nb_efd,
347 intr_handle->max_intr);
350 for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
352 intr_handle->intr_vec[queue_id] = vec;
353 if (vec < base + intr_handle->nb_efd - 1)
357 /* enable uio/vfio intr/eventfd mapping */
358 rte_intr_enable(intr_handle);
360 rc = bnxt_get_hwrm_link_config(bp, &new);
362 RTE_LOG(ERR, PMD, "HWRM Get link config failure rc: %x\n", rc);
366 if (!bp->link_info.link_up) {
367 rc = bnxt_set_hwrm_link_config(bp, true);
370 "HWRM link config failure rc: %x\n", rc);
374 bnxt_print_link_info(bp->eth_dev);
379 bnxt_free_all_hwrm_resources(bp);
384 static int bnxt_shutdown_nic(struct bnxt *bp)
386 bnxt_free_all_hwrm_resources(bp);
387 bnxt_free_all_filters(bp);
388 bnxt_free_all_vnics(bp);
392 static int bnxt_init_nic(struct bnxt *bp)
396 bnxt_init_ring_grps(bp);
398 bnxt_init_filters(bp);
400 rc = bnxt_init_chip(bp);
408 * Device configuration and status function
411 static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
412 struct rte_eth_dev_info *dev_info)
414 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
415 uint16_t max_vnics, i, j, vpool, vrxq;
416 unsigned int max_rx_rings;
418 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
421 dev_info->max_mac_addrs = bp->max_l2_ctx;
422 dev_info->max_hash_mac_addrs = 0;
424 /* PF/VF specifics */
426 dev_info->max_vfs = bp->pdev->max_vfs;
427 max_rx_rings = RTE_MIN(bp->max_vnics, RTE_MIN(bp->max_l2_ctx,
428 RTE_MIN(bp->max_rsscos_ctx,
430 /* For the sake of symmetry, max_rx_queues = max_tx_queues */
431 dev_info->max_rx_queues = max_rx_rings;
432 dev_info->max_tx_queues = max_rx_rings;
433 dev_info->reta_size = bp->max_rsscos_ctx;
434 dev_info->hash_key_size = 40;
435 max_vnics = bp->max_vnics;
437 /* Fast path specifics */
438 dev_info->min_rx_bufsize = 1;
439 dev_info->max_rx_pktlen = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN
441 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
442 DEV_RX_OFFLOAD_IPV4_CKSUM |
443 DEV_RX_OFFLOAD_UDP_CKSUM |
444 DEV_RX_OFFLOAD_TCP_CKSUM |
445 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
446 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
447 DEV_TX_OFFLOAD_IPV4_CKSUM |
448 DEV_TX_OFFLOAD_TCP_CKSUM |
449 DEV_TX_OFFLOAD_UDP_CKSUM |
450 DEV_TX_OFFLOAD_TCP_TSO |
451 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
452 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
453 DEV_TX_OFFLOAD_GRE_TNL_TSO |
454 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
455 DEV_TX_OFFLOAD_GENEVE_TNL_TSO;
458 dev_info->default_rxconf = (struct rte_eth_rxconf) {
464 .rx_free_thresh = 32,
468 dev_info->default_txconf = (struct rte_eth_txconf) {
474 .tx_free_thresh = 32,
476 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
477 ETH_TXQ_FLAGS_NOOFFLOADS,
479 eth_dev->data->dev_conf.intr_conf.lsc = 1;
481 eth_dev->data->dev_conf.intr_conf.rxq = 1;
486 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
487 * need further investigation.
491 vpool = 64; /* ETH_64_POOLS */
492 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
493 for (i = 0; i < 4; vpool >>= 1, i++) {
494 if (max_vnics > vpool) {
495 for (j = 0; j < 5; vrxq >>= 1, j++) {
496 if (dev_info->max_rx_queues > vrxq) {
502 /* Not enough resources to support VMDq */
506 /* Not enough resources to support VMDq */
510 dev_info->max_vmdq_pools = vpool;
511 dev_info->vmdq_queue_num = vrxq;
513 dev_info->vmdq_pool_base = 0;
514 dev_info->vmdq_queue_base = 0;
517 /* Configure the device based on the configuration provided */
518 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
520 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
522 bp->rx_queues = (void *)eth_dev->data->rx_queues;
523 bp->tx_queues = (void *)eth_dev->data->tx_queues;
525 /* Inherit new configurations */
526 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
527 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
528 bp->rx_cp_nr_rings = bp->rx_nr_rings;
529 bp->tx_cp_nr_rings = bp->tx_nr_rings;
531 if (eth_dev->data->dev_conf.rxmode.jumbo_frame)
533 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
534 ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE;
538 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
540 struct rte_eth_link *link = ð_dev->data->dev_link;
542 if (link->link_status)
543 RTE_LOG(INFO, PMD, "Port %d Link Up - speed %u Mbps - %s\n",
544 eth_dev->data->port_id,
545 (uint32_t)link->link_speed,
546 (link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
547 ("full-duplex") : ("half-duplex\n"));
549 RTE_LOG(INFO, PMD, "Port %d Link Down\n",
550 eth_dev->data->port_id);
553 static int bnxt_dev_lsc_intr_setup(struct rte_eth_dev *eth_dev)
555 bnxt_print_link_info(eth_dev);
559 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
561 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
565 if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS) {
567 "RxQ cnt %d > CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
568 bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
572 rc = bnxt_init_nic(bp);
576 bnxt_link_update_op(eth_dev, 1);
578 if (eth_dev->data->dev_conf.rxmode.hw_vlan_filter)
579 vlan_mask |= ETH_VLAN_FILTER_MASK;
580 if (eth_dev->data->dev_conf.rxmode.hw_vlan_strip)
581 vlan_mask |= ETH_VLAN_STRIP_MASK;
582 rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
589 bnxt_shutdown_nic(bp);
590 bnxt_free_tx_mbufs(bp);
591 bnxt_free_rx_mbufs(bp);
595 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
597 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
600 if (!bp->link_info.link_up)
601 rc = bnxt_set_hwrm_link_config(bp, true);
603 eth_dev->data->dev_link.link_status = 1;
605 bnxt_print_link_info(eth_dev);
609 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
611 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
613 eth_dev->data->dev_link.link_status = 0;
614 bnxt_set_hwrm_link_config(bp, false);
615 bp->link_info.link_up = 0;
620 /* Unload the driver, release resources */
621 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
623 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
625 if (bp->eth_dev->data->dev_started) {
626 /* TBD: STOP HW queues DMA */
627 eth_dev->data->dev_link.link_status = 0;
629 bnxt_set_hwrm_link_config(bp, false);
630 bnxt_hwrm_port_clr_stats(bp);
631 bnxt_shutdown_nic(bp);
635 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
637 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
639 if (bp->dev_stopped == 0)
640 bnxt_dev_stop_op(eth_dev);
642 bnxt_free_tx_mbufs(bp);
643 bnxt_free_rx_mbufs(bp);
645 if (eth_dev->data->mac_addrs != NULL) {
646 rte_free(eth_dev->data->mac_addrs);
647 eth_dev->data->mac_addrs = NULL;
649 if (bp->grp_info != NULL) {
650 rte_free(bp->grp_info);
655 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
658 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
659 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
660 struct bnxt_vnic_info *vnic;
661 struct bnxt_filter_info *filter, *temp_filter;
662 uint32_t pool = RTE_MIN(MAX_FF_POOLS, ETH_64_POOLS);
666 * Loop through all VNICs from the specified filter flow pools to
667 * remove the corresponding MAC addr filter
669 for (i = 0; i < pool; i++) {
670 if (!(pool_mask & (1ULL << i)))
673 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
674 filter = STAILQ_FIRST(&vnic->filter);
676 temp_filter = STAILQ_NEXT(filter, next);
677 if (filter->mac_index == index) {
678 STAILQ_REMOVE(&vnic->filter, filter,
679 bnxt_filter_info, next);
680 bnxt_hwrm_clear_l2_filter(bp, filter);
681 filter->mac_index = INVALID_MAC_INDEX;
682 memset(&filter->l2_addr, 0,
685 &bp->free_filter_list,
688 filter = temp_filter;
694 static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
695 struct ether_addr *mac_addr,
696 uint32_t index, uint32_t pool)
698 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
699 struct bnxt_vnic_info *vnic = STAILQ_FIRST(&bp->ff_pool[pool]);
700 struct bnxt_filter_info *filter;
703 RTE_LOG(ERR, PMD, "Cannot add MAC address to a VF interface\n");
708 RTE_LOG(ERR, PMD, "VNIC not found for pool %d!\n", pool);
711 /* Attach requested MAC address to the new l2_filter */
712 STAILQ_FOREACH(filter, &vnic->filter, next) {
713 if (filter->mac_index == index) {
715 "MAC addr already existed for pool %d\n", pool);
719 filter = bnxt_alloc_filter(bp);
721 RTE_LOG(ERR, PMD, "L2 filter alloc failed\n");
724 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
725 filter->mac_index = index;
726 memcpy(filter->l2_addr, mac_addr, ETHER_ADDR_LEN);
727 return bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
730 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
733 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
734 struct rte_eth_link new;
735 unsigned int cnt = BNXT_LINK_WAIT_CNT;
737 memset(&new, 0, sizeof(new));
739 /* Retrieve link info from hardware */
740 rc = bnxt_get_hwrm_link_config(bp, &new);
742 new.link_speed = ETH_LINK_SPEED_100M;
743 new.link_duplex = ETH_LINK_FULL_DUPLEX;
745 "Failed to retrieve link rc = 0x%x!\n", rc);
748 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
750 if (!wait_to_complete)
752 } while (!new.link_status && cnt--);
755 /* Timed out or success */
756 if (new.link_status != eth_dev->data->dev_link.link_status ||
757 new.link_speed != eth_dev->data->dev_link.link_speed) {
758 memcpy(ð_dev->data->dev_link, &new,
759 sizeof(struct rte_eth_link));
760 bnxt_print_link_info(eth_dev);
766 static void bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
768 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
769 struct bnxt_vnic_info *vnic;
771 if (bp->vnic_info == NULL)
774 vnic = &bp->vnic_info[0];
776 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
777 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
780 static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
782 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
783 struct bnxt_vnic_info *vnic;
785 if (bp->vnic_info == NULL)
788 vnic = &bp->vnic_info[0];
790 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
791 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
794 static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
796 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
797 struct bnxt_vnic_info *vnic;
799 if (bp->vnic_info == NULL)
802 vnic = &bp->vnic_info[0];
804 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
805 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
808 static void bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
810 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
811 struct bnxt_vnic_info *vnic;
813 if (bp->vnic_info == NULL)
816 vnic = &bp->vnic_info[0];
818 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
819 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
822 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
823 struct rte_eth_rss_reta_entry64 *reta_conf,
826 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
827 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
828 struct bnxt_vnic_info *vnic;
831 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
834 if (reta_size != HW_HASH_INDEX_SIZE) {
835 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
836 "(%d) must equal the size supported by the hardware "
837 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
840 /* Update the RSS VNIC(s) */
841 for (i = 0; i < MAX_FF_POOLS; i++) {
842 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
843 memcpy(vnic->rss_table, reta_conf, reta_size);
845 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
851 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
852 struct rte_eth_rss_reta_entry64 *reta_conf,
855 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
856 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
857 struct rte_intr_handle *intr_handle
858 = &bp->pdev->intr_handle;
860 /* Retrieve from the default VNIC */
863 if (!vnic->rss_table)
866 if (reta_size != HW_HASH_INDEX_SIZE) {
867 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
868 "(%d) must equal the size supported by the hardware "
869 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
872 /* EW - need to revisit here copying from u64 to u16 */
873 memcpy(reta_conf, vnic->rss_table, reta_size);
875 if (rte_intr_allow_others(intr_handle)) {
876 if (eth_dev->data->dev_conf.intr_conf.lsc != 0)
877 bnxt_dev_lsc_intr_setup(eth_dev);
883 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
884 struct rte_eth_rss_conf *rss_conf)
886 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
887 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
888 struct bnxt_vnic_info *vnic;
889 uint16_t hash_type = 0;
893 * If RSS enablement were different than dev_configure,
894 * then return -EINVAL
896 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
897 if (!rss_conf->rss_hf)
898 RTE_LOG(ERR, PMD, "Hash type NONE\n");
900 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
904 bp->flags |= BNXT_FLAG_UPDATE_HASH;
905 memcpy(&bp->rss_conf, rss_conf, sizeof(*rss_conf));
907 if (rss_conf->rss_hf & ETH_RSS_IPV4)
908 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
909 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
910 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
911 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
912 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
913 if (rss_conf->rss_hf & ETH_RSS_IPV6)
914 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
915 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
916 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
917 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
918 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
920 /* Update the RSS VNIC(s) */
921 for (i = 0; i < MAX_FF_POOLS; i++) {
922 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
923 vnic->hash_type = hash_type;
926 * Use the supplied key if the key length is
927 * acceptable and the rss_key is not NULL
929 if (rss_conf->rss_key &&
930 rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
931 memcpy(vnic->rss_hash_key, rss_conf->rss_key,
932 rss_conf->rss_key_len);
934 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
940 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
941 struct rte_eth_rss_conf *rss_conf)
943 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
944 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
948 /* RSS configuration is the same for all VNICs */
949 if (vnic && vnic->rss_hash_key) {
950 if (rss_conf->rss_key) {
951 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
952 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
953 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
956 hash_types = vnic->hash_type;
957 rss_conf->rss_hf = 0;
958 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
959 rss_conf->rss_hf |= ETH_RSS_IPV4;
960 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
962 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
963 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
965 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
967 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
968 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
970 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
972 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
973 rss_conf->rss_hf |= ETH_RSS_IPV6;
974 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
976 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
977 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
979 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
981 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
982 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
984 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
988 "Unknwon RSS config from firmware (%08x), RSS disabled",
993 rss_conf->rss_hf = 0;
998 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
999 struct rte_eth_fc_conf *fc_conf)
1001 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1002 struct rte_eth_link link_info;
1005 rc = bnxt_get_hwrm_link_config(bp, &link_info);
1009 memset(fc_conf, 0, sizeof(*fc_conf));
1010 if (bp->link_info.auto_pause)
1011 fc_conf->autoneg = 1;
1012 switch (bp->link_info.pause) {
1014 fc_conf->mode = RTE_FC_NONE;
1016 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
1017 fc_conf->mode = RTE_FC_TX_PAUSE;
1019 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
1020 fc_conf->mode = RTE_FC_RX_PAUSE;
1022 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1023 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
1024 fc_conf->mode = RTE_FC_FULL;
1030 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
1031 struct rte_eth_fc_conf *fc_conf)
1033 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1035 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp)) {
1036 RTE_LOG(ERR, PMD, "Flow Control Settings cannot be modified\n");
1040 switch (fc_conf->mode) {
1042 bp->link_info.auto_pause = 0;
1043 bp->link_info.force_pause = 0;
1045 case RTE_FC_RX_PAUSE:
1046 if (fc_conf->autoneg) {
1047 bp->link_info.auto_pause =
1048 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
1049 bp->link_info.force_pause = 0;
1051 bp->link_info.auto_pause = 0;
1052 bp->link_info.force_pause =
1053 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
1056 case RTE_FC_TX_PAUSE:
1057 if (fc_conf->autoneg) {
1058 bp->link_info.auto_pause =
1059 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
1060 bp->link_info.force_pause = 0;
1062 bp->link_info.auto_pause = 0;
1063 bp->link_info.force_pause =
1064 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
1068 if (fc_conf->autoneg) {
1069 bp->link_info.auto_pause =
1070 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
1071 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
1072 bp->link_info.force_pause = 0;
1074 bp->link_info.auto_pause = 0;
1075 bp->link_info.force_pause =
1076 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
1077 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
1081 return bnxt_set_hwrm_link_config(bp, true);
1084 /* Add UDP tunneling port */
1086 bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
1087 struct rte_eth_udp_tunnel *udp_tunnel)
1089 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
1090 uint16_t tunnel_type = 0;
1093 switch (udp_tunnel->prot_type) {
1094 case RTE_TUNNEL_TYPE_VXLAN:
1095 if (bp->vxlan_port_cnt) {
1096 RTE_LOG(ERR, PMD, "Tunnel Port %d already programmed\n",
1097 udp_tunnel->udp_port);
1098 if (bp->vxlan_port != udp_tunnel->udp_port) {
1099 RTE_LOG(ERR, PMD, "Only one port allowed\n");
1102 bp->vxlan_port_cnt++;
1106 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
1107 bp->vxlan_port_cnt++;
1109 case RTE_TUNNEL_TYPE_GENEVE:
1110 if (bp->geneve_port_cnt) {
1111 RTE_LOG(ERR, PMD, "Tunnel Port %d already programmed\n",
1112 udp_tunnel->udp_port);
1113 if (bp->geneve_port != udp_tunnel->udp_port) {
1114 RTE_LOG(ERR, PMD, "Only one port allowed\n");
1117 bp->geneve_port_cnt++;
1121 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
1122 bp->geneve_port_cnt++;
1125 RTE_LOG(ERR, PMD, "Tunnel type is not supported\n");
1128 rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
1134 bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
1135 struct rte_eth_udp_tunnel *udp_tunnel)
1137 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
1138 uint16_t tunnel_type = 0;
1142 switch (udp_tunnel->prot_type) {
1143 case RTE_TUNNEL_TYPE_VXLAN:
1144 if (!bp->vxlan_port_cnt) {
1145 RTE_LOG(ERR, PMD, "No Tunnel port configured yet\n");
1148 if (bp->vxlan_port != udp_tunnel->udp_port) {
1149 RTE_LOG(ERR, PMD, "Req Port: %d. Configured port: %d\n",
1150 udp_tunnel->udp_port, bp->vxlan_port);
1153 if (--bp->vxlan_port_cnt)
1157 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
1158 port = bp->vxlan_fw_dst_port_id;
1160 case RTE_TUNNEL_TYPE_GENEVE:
1161 if (!bp->geneve_port_cnt) {
1162 RTE_LOG(ERR, PMD, "No Tunnel port configured yet\n");
1165 if (bp->geneve_port != udp_tunnel->udp_port) {
1166 RTE_LOG(ERR, PMD, "Req Port: %d. Configured port: %d\n",
1167 udp_tunnel->udp_port, bp->geneve_port);
1170 if (--bp->geneve_port_cnt)
1174 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
1175 port = bp->geneve_fw_dst_port_id;
1178 RTE_LOG(ERR, PMD, "Tunnel type is not supported\n");
1182 rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
1185 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN)
1188 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE)
1189 bp->geneve_port = 0;
1194 static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
1196 struct bnxt_filter_info *filter, *temp_filter, *new_filter;
1197 struct bnxt_vnic_info *vnic;
1200 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN;
1202 /* Cycle through all VNICs */
1203 for (i = 0; i < bp->nr_vnics; i++) {
1205 * For each VNIC and each associated filter(s)
1206 * if VLAN exists && VLAN matches vlan_id
1207 * remove the MAC+VLAN filter
1208 * add a new MAC only filter
1210 * VLAN filter doesn't exist, just skip and continue
1212 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
1213 filter = STAILQ_FIRST(&vnic->filter);
1215 temp_filter = STAILQ_NEXT(filter, next);
1217 if (filter->enables & chk &&
1218 filter->l2_ovlan == vlan_id) {
1219 /* Must delete the filter */
1220 STAILQ_REMOVE(&vnic->filter, filter,
1221 bnxt_filter_info, next);
1222 bnxt_hwrm_clear_l2_filter(bp, filter);
1224 &bp->free_filter_list,
1228 * Need to examine to see if the MAC
1229 * filter already existed or not before
1230 * allocating a new one
1233 new_filter = bnxt_alloc_filter(bp);
1236 "MAC/VLAN filter alloc failed\n");
1240 STAILQ_INSERT_TAIL(&vnic->filter,
1242 /* Inherit MAC from previous filter */
1243 new_filter->mac_index =
1245 memcpy(new_filter->l2_addr,
1246 filter->l2_addr, ETHER_ADDR_LEN);
1247 /* MAC only filter */
1248 rc = bnxt_hwrm_set_l2_filter(bp,
1254 "Del Vlan filter for %d\n",
1257 filter = temp_filter;
1265 static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
1267 struct bnxt_filter_info *filter, *temp_filter, *new_filter;
1268 struct bnxt_vnic_info *vnic;
1271 uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN |
1272 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK;
1273 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN;
1275 /* Cycle through all VNICs */
1276 for (i = 0; i < bp->nr_vnics; i++) {
1278 * For each VNIC and each associated filter(s)
1280 * if VLAN matches vlan_id
1281 * VLAN filter already exists, just skip and continue
1283 * add a new MAC+VLAN filter
1285 * Remove the old MAC only filter
1286 * Add a new MAC+VLAN filter
1288 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
1289 filter = STAILQ_FIRST(&vnic->filter);
1291 temp_filter = STAILQ_NEXT(filter, next);
1293 if (filter->enables & chk) {
1294 if (filter->l2_ovlan == vlan_id)
1297 /* Must delete the MAC filter */
1298 STAILQ_REMOVE(&vnic->filter, filter,
1299 bnxt_filter_info, next);
1300 bnxt_hwrm_clear_l2_filter(bp, filter);
1301 filter->l2_ovlan = 0;
1303 &bp->free_filter_list,
1306 new_filter = bnxt_alloc_filter(bp);
1309 "MAC/VLAN filter alloc failed\n");
1313 STAILQ_INSERT_TAIL(&vnic->filter, new_filter,
1315 /* Inherit MAC from the previous filter */
1316 new_filter->mac_index = filter->mac_index;
1317 memcpy(new_filter->l2_addr, filter->l2_addr,
1319 /* MAC + VLAN ID filter */
1320 new_filter->l2_ovlan = vlan_id;
1321 new_filter->l2_ovlan_mask = 0xF000;
1322 new_filter->enables |= en;
1323 rc = bnxt_hwrm_set_l2_filter(bp,
1329 "Added Vlan filter for %d\n", vlan_id);
1331 filter = temp_filter;
1339 static int bnxt_vlan_filter_set_op(struct rte_eth_dev *eth_dev,
1340 uint16_t vlan_id, int on)
1342 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
1344 /* These operations apply to ALL existing MAC/VLAN filters */
1346 return bnxt_add_vlan_filter(bp, vlan_id);
1348 return bnxt_del_vlan_filter(bp, vlan_id);
1352 bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
1354 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1357 if (mask & ETH_VLAN_FILTER_MASK) {
1358 if (!dev->data->dev_conf.rxmode.hw_vlan_filter) {
1359 /* Remove any VLAN filters programmed */
1360 for (i = 0; i < 4095; i++)
1361 bnxt_del_vlan_filter(bp, i);
1363 RTE_LOG(INFO, PMD, "VLAN Filtering: %d\n",
1364 dev->data->dev_conf.rxmode.hw_vlan_filter);
1367 if (mask & ETH_VLAN_STRIP_MASK) {
1368 /* Enable or disable VLAN stripping */
1369 for (i = 0; i < bp->nr_vnics; i++) {
1370 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
1371 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1372 vnic->vlan_strip = true;
1374 vnic->vlan_strip = false;
1375 bnxt_hwrm_vnic_cfg(bp, vnic);
1377 RTE_LOG(INFO, PMD, "VLAN Strip Offload: %d\n",
1378 dev->data->dev_conf.rxmode.hw_vlan_strip);
1381 if (mask & ETH_VLAN_EXTEND_MASK)
1382 RTE_LOG(ERR, PMD, "Extend VLAN Not supported\n");
1388 bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev, struct ether_addr *addr)
1390 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1391 /* Default Filter is tied to VNIC 0 */
1392 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
1393 struct bnxt_filter_info *filter;
1399 memcpy(bp->mac_addr, addr, sizeof(bp->mac_addr));
1400 memcpy(&dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
1402 STAILQ_FOREACH(filter, &vnic->filter, next) {
1403 /* Default Filter is at Index 0 */
1404 if (filter->mac_index != 0)
1406 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
1409 memcpy(filter->l2_addr, bp->mac_addr, ETHER_ADDR_LEN);
1410 memset(filter->l2_addr_mask, 0xff, ETHER_ADDR_LEN);
1411 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
1413 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
1414 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
1415 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
1418 filter->mac_index = 0;
1419 RTE_LOG(DEBUG, PMD, "Set MAC addr\n");
1424 bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
1425 struct ether_addr *mc_addr_set,
1426 uint32_t nb_mc_addr)
1428 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
1429 char *mc_addr_list = (char *)mc_addr_set;
1430 struct bnxt_vnic_info *vnic;
1431 uint32_t off = 0, i = 0;
1433 vnic = &bp->vnic_info[0];
1435 if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
1436 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
1440 /* TODO Check for Duplicate mcast addresses */
1441 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
1442 for (i = 0; i < nb_mc_addr; i++) {
1443 memcpy(vnic->mc_list + off, &mc_addr_list[i], ETHER_ADDR_LEN);
1444 off += ETHER_ADDR_LEN;
1447 vnic->mc_addr_cnt = i;
1450 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1454 bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
1456 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1457 uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
1458 uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
1459 uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
1462 ret = snprintf(fw_version, fw_size, "%d.%d.%d",
1463 fw_major, fw_minor, fw_updt);
1465 ret += 1; /* add the size of '\0' */
1466 if (fw_size < (uint32_t)ret)
1473 bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
1474 struct rte_eth_rxq_info *qinfo)
1476 struct bnxt_rx_queue *rxq;
1478 rxq = dev->data->rx_queues[queue_id];
1480 qinfo->mp = rxq->mb_pool;
1481 qinfo->scattered_rx = dev->data->scattered_rx;
1482 qinfo->nb_desc = rxq->nb_rx_desc;
1484 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
1485 qinfo->conf.rx_drop_en = 0;
1486 qinfo->conf.rx_deferred_start = 0;
1490 bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
1491 struct rte_eth_txq_info *qinfo)
1493 struct bnxt_tx_queue *txq;
1495 txq = dev->data->tx_queues[queue_id];
1497 qinfo->nb_desc = txq->nb_tx_desc;
1499 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
1500 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
1501 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
1503 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
1504 qinfo->conf.tx_rs_thresh = 0;
1505 qinfo->conf.txq_flags = txq->txq_flags;
1506 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
1509 static int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
1511 struct bnxt *bp = eth_dev->data->dev_private;
1512 struct rte_eth_dev_info dev_info;
1513 uint32_t max_dev_mtu;
1517 bnxt_dev_info_get_op(eth_dev, &dev_info);
1518 max_dev_mtu = dev_info.max_rx_pktlen -
1519 ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE * 2;
1521 if (new_mtu < ETHER_MIN_MTU || new_mtu > max_dev_mtu) {
1522 RTE_LOG(ERR, PMD, "MTU requested must be within (%d, %d)\n",
1523 ETHER_MIN_MTU, max_dev_mtu);
1528 if (new_mtu > ETHER_MTU) {
1529 bp->flags |= BNXT_FLAG_JUMBO;
1530 eth_dev->data->dev_conf.rxmode.jumbo_frame = 1;
1532 eth_dev->data->dev_conf.rxmode.jumbo_frame = 0;
1533 bp->flags &= ~BNXT_FLAG_JUMBO;
1536 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len =
1537 new_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE * 2;
1539 eth_dev->data->mtu = new_mtu;
1540 RTE_LOG(INFO, PMD, "New MTU is %d\n", eth_dev->data->mtu);
1542 for (i = 0; i < bp->nr_vnics; i++) {
1543 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
1545 vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
1546 ETHER_CRC_LEN + VLAN_TAG_SIZE * 2;
1547 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
1551 rc = bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
1560 bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
1562 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1563 uint16_t vlan = bp->vlan;
1566 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp)) {
1568 "PVID cannot be modified for this function\n");
1571 bp->vlan = on ? pvid : 0;
1573 rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
1580 bnxt_dev_led_on_op(struct rte_eth_dev *dev)
1582 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1584 return bnxt_hwrm_port_led_cfg(bp, true);
1588 bnxt_dev_led_off_op(struct rte_eth_dev *dev)
1590 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1592 return bnxt_hwrm_port_led_cfg(bp, false);
1596 bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1598 uint32_t desc = 0, raw_cons = 0, cons;
1599 struct bnxt_cp_ring_info *cpr;
1600 struct bnxt_rx_queue *rxq;
1601 struct rx_pkt_cmpl *rxcmp;
1606 rxq = dev->data->rx_queues[rx_queue_id];
1610 while (raw_cons < rxq->nb_rx_desc) {
1611 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
1612 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
1614 if (!CMPL_VALID(rxcmp, valid))
1616 valid = FLIP_VALID(cons, cpr->cp_ring_struct->ring_mask, valid);
1617 cmp_type = CMP_TYPE(rxcmp);
1618 if (cmp_type == RX_TPA_END_CMPL_TYPE_RX_TPA_END) {
1619 cmp = (rte_le_to_cpu_32(
1620 ((struct rx_tpa_end_cmpl *)
1621 (rxcmp))->agg_bufs_v1) &
1622 RX_TPA_END_CMPL_AGG_BUFS_MASK) >>
1623 RX_TPA_END_CMPL_AGG_BUFS_SFT;
1625 } else if (cmp_type == 0x11) {
1627 cmp = (rxcmp->agg_bufs_v1 &
1628 RX_PKT_CMPL_AGG_BUFS_MASK) >>
1629 RX_PKT_CMPL_AGG_BUFS_SFT;
1634 raw_cons += cmp ? cmp : 2;
1641 bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)
1643 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
1644 struct bnxt_rx_ring_info *rxr;
1645 struct bnxt_cp_ring_info *cpr;
1646 struct bnxt_sw_rx_bd *rx_buf;
1647 struct rx_pkt_cmpl *rxcmp;
1648 uint32_t cons, cp_cons;
1656 if (offset >= rxq->nb_rx_desc)
1659 cons = RING_CMP(cpr->cp_ring_struct, offset);
1660 cp_cons = cpr->cp_raw_cons;
1661 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
1663 if (cons > cp_cons) {
1664 if (CMPL_VALID(rxcmp, cpr->valid))
1665 return RTE_ETH_RX_DESC_DONE;
1667 if (CMPL_VALID(rxcmp, !cpr->valid))
1668 return RTE_ETH_RX_DESC_DONE;
1670 rx_buf = &rxr->rx_buf_ring[cons];
1671 if (rx_buf->mbuf == NULL)
1672 return RTE_ETH_RX_DESC_UNAVAIL;
1675 return RTE_ETH_RX_DESC_AVAIL;
1679 bnxt_tx_descriptor_status_op(void *tx_queue, uint16_t offset)
1681 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
1682 struct bnxt_tx_ring_info *txr;
1683 struct bnxt_cp_ring_info *cpr;
1684 struct bnxt_sw_tx_bd *tx_buf;
1685 struct tx_pkt_cmpl *txcmp;
1686 uint32_t cons, cp_cons;
1694 if (offset >= txq->nb_tx_desc)
1697 cons = RING_CMP(cpr->cp_ring_struct, offset);
1698 txcmp = (struct tx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
1699 cp_cons = cpr->cp_raw_cons;
1701 if (cons > cp_cons) {
1702 if (CMPL_VALID(txcmp, cpr->valid))
1703 return RTE_ETH_TX_DESC_UNAVAIL;
1705 if (CMPL_VALID(txcmp, !cpr->valid))
1706 return RTE_ETH_TX_DESC_UNAVAIL;
1708 tx_buf = &txr->tx_buf_ring[cons];
1709 if (tx_buf->mbuf == NULL)
1710 return RTE_ETH_TX_DESC_DONE;
1712 return RTE_ETH_TX_DESC_FULL;
1715 static struct bnxt_filter_info *
1716 bnxt_match_and_validate_ether_filter(struct bnxt *bp,
1717 struct rte_eth_ethertype_filter *efilter,
1718 struct bnxt_vnic_info *vnic0,
1719 struct bnxt_vnic_info *vnic,
1722 struct bnxt_filter_info *mfilter = NULL;
1726 if (efilter->ether_type != ETHER_TYPE_IPv4 &&
1727 efilter->ether_type != ETHER_TYPE_IPv6) {
1728 RTE_LOG(ERR, PMD, "unsupported ether_type(0x%04x) in"
1729 " ethertype filter.", efilter->ether_type);
1733 if (efilter->queue >= bp->rx_nr_rings) {
1734 RTE_LOG(ERR, PMD, "Invalid queue %d\n", efilter->queue);
1739 vnic0 = STAILQ_FIRST(&bp->ff_pool[0]);
1740 vnic = STAILQ_FIRST(&bp->ff_pool[efilter->queue]);
1742 RTE_LOG(ERR, PMD, "Invalid queue %d\n", efilter->queue);
1747 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
1748 STAILQ_FOREACH(mfilter, &vnic0->filter, next) {
1749 if ((!memcmp(efilter->mac_addr.addr_bytes,
1750 mfilter->l2_addr, ETHER_ADDR_LEN) &&
1752 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP &&
1753 mfilter->ethertype == efilter->ether_type)) {
1759 STAILQ_FOREACH(mfilter, &vnic->filter, next)
1760 if ((!memcmp(efilter->mac_addr.addr_bytes,
1761 mfilter->l2_addr, ETHER_ADDR_LEN) &&
1762 mfilter->ethertype == efilter->ether_type &&
1764 HWRM_CFA_L2_FILTER_CFG_INPUT_FLAGS_PATH_RX)) {
1778 bnxt_ethertype_filter(struct rte_eth_dev *dev,
1779 enum rte_filter_op filter_op,
1782 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1783 struct rte_eth_ethertype_filter *efilter =
1784 (struct rte_eth_ethertype_filter *)arg;
1785 struct bnxt_filter_info *bfilter, *filter1;
1786 struct bnxt_vnic_info *vnic, *vnic0;
1789 if (filter_op == RTE_ETH_FILTER_NOP)
1793 RTE_LOG(ERR, PMD, "arg shouldn't be NULL for operation %u.",
1798 vnic0 = STAILQ_FIRST(&bp->ff_pool[0]);
1799 vnic = STAILQ_FIRST(&bp->ff_pool[efilter->queue]);
1801 switch (filter_op) {
1802 case RTE_ETH_FILTER_ADD:
1803 bnxt_match_and_validate_ether_filter(bp, efilter,
1808 bfilter = bnxt_get_unused_filter(bp);
1809 if (bfilter == NULL) {
1811 "Not enough resources for a new filter.\n");
1814 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
1815 memcpy(bfilter->l2_addr, efilter->mac_addr.addr_bytes,
1817 memcpy(bfilter->dst_macaddr, efilter->mac_addr.addr_bytes,
1819 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
1820 bfilter->ethertype = efilter->ether_type;
1821 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
1823 filter1 = bnxt_get_l2_filter(bp, bfilter, vnic0);
1824 if (filter1 == NULL) {
1829 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
1830 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
1832 bfilter->dst_id = vnic->fw_vnic_id;
1834 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
1836 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
1839 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
1842 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
1844 case RTE_ETH_FILTER_DELETE:
1845 filter1 = bnxt_match_and_validate_ether_filter(bp, efilter,
1847 if (ret == -EEXIST) {
1848 ret = bnxt_hwrm_clear_ntuple_filter(bp, filter1);
1850 STAILQ_REMOVE(&vnic->filter, filter1, bnxt_filter_info,
1852 bnxt_free_filter(bp, filter1);
1853 } else if (ret == 0) {
1854 RTE_LOG(ERR, PMD, "No matching filter found\n");
1858 RTE_LOG(ERR, PMD, "unsupported operation %u.", filter_op);
1864 bnxt_free_filter(bp, bfilter);
1870 parse_ntuple_filter(struct bnxt *bp,
1871 struct rte_eth_ntuple_filter *nfilter,
1872 struct bnxt_filter_info *bfilter)
1876 if (nfilter->queue >= bp->rx_nr_rings) {
1877 RTE_LOG(ERR, PMD, "Invalid queue %d\n", nfilter->queue);
1881 switch (nfilter->dst_port_mask) {
1883 bfilter->dst_port_mask = -1;
1884 bfilter->dst_port = nfilter->dst_port;
1885 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT |
1886 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
1889 RTE_LOG(ERR, PMD, "invalid dst_port mask.");
1893 bfilter->ip_addr_type = NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
1894 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
1896 switch (nfilter->proto_mask) {
1898 if (nfilter->proto == 17) /* IPPROTO_UDP */
1899 bfilter->ip_protocol = 17;
1900 else if (nfilter->proto == 6) /* IPPROTO_TCP */
1901 bfilter->ip_protocol = 6;
1904 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
1907 RTE_LOG(ERR, PMD, "invalid protocol mask.");
1911 switch (nfilter->dst_ip_mask) {
1913 bfilter->dst_ipaddr_mask[0] = -1;
1914 bfilter->dst_ipaddr[0] = nfilter->dst_ip;
1915 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR |
1916 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
1919 RTE_LOG(ERR, PMD, "invalid dst_ip mask.");
1923 switch (nfilter->src_ip_mask) {
1925 bfilter->src_ipaddr_mask[0] = -1;
1926 bfilter->src_ipaddr[0] = nfilter->src_ip;
1927 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR |
1928 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
1931 RTE_LOG(ERR, PMD, "invalid src_ip mask.");
1935 switch (nfilter->src_port_mask) {
1937 bfilter->src_port_mask = -1;
1938 bfilter->src_port = nfilter->src_port;
1939 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT |
1940 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
1943 RTE_LOG(ERR, PMD, "invalid src_port mask.");
1948 //nfilter->priority = (uint8_t)filter->priority;
1950 bfilter->enables = en;
1954 static struct bnxt_filter_info*
1955 bnxt_match_ntuple_filter(struct bnxt *bp,
1956 struct bnxt_filter_info *bfilter)
1958 struct bnxt_filter_info *mfilter = NULL;
1961 for (i = bp->nr_vnics - 1; i >= 0; i--) {
1962 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
1963 STAILQ_FOREACH(mfilter, &vnic->filter, next) {
1964 if (bfilter->src_ipaddr[0] == mfilter->src_ipaddr[0] &&
1965 bfilter->src_ipaddr_mask[0] ==
1966 mfilter->src_ipaddr_mask[0] &&
1967 bfilter->src_port == mfilter->src_port &&
1968 bfilter->src_port_mask == mfilter->src_port_mask &&
1969 bfilter->dst_ipaddr[0] == mfilter->dst_ipaddr[0] &&
1970 bfilter->dst_ipaddr_mask[0] ==
1971 mfilter->dst_ipaddr_mask[0] &&
1972 bfilter->dst_port == mfilter->dst_port &&
1973 bfilter->dst_port_mask == mfilter->dst_port_mask &&
1974 bfilter->flags == mfilter->flags &&
1975 bfilter->enables == mfilter->enables)
1983 bnxt_cfg_ntuple_filter(struct bnxt *bp,
1984 struct rte_eth_ntuple_filter *nfilter,
1985 enum rte_filter_op filter_op)
1987 struct bnxt_filter_info *bfilter, *mfilter, *filter1;
1988 struct bnxt_vnic_info *vnic, *vnic0;
1991 if (nfilter->flags != RTE_5TUPLE_FLAGS) {
1992 RTE_LOG(ERR, PMD, "only 5tuple is supported.");
1996 if (nfilter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
1997 RTE_LOG(ERR, PMD, "Ntuple filter: TCP flags not supported\n");
2001 bfilter = bnxt_get_unused_filter(bp);
2002 if (bfilter == NULL) {
2004 "Not enough resources for a new filter.\n");
2007 ret = parse_ntuple_filter(bp, nfilter, bfilter);
2011 vnic = STAILQ_FIRST(&bp->ff_pool[nfilter->queue]);
2012 vnic0 = STAILQ_FIRST(&bp->ff_pool[0]);
2013 filter1 = STAILQ_FIRST(&vnic0->filter);
2014 if (filter1 == NULL) {
2019 bfilter->dst_id = vnic->fw_vnic_id;
2020 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
2022 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
2023 bfilter->ethertype = 0x800;
2024 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2026 mfilter = bnxt_match_ntuple_filter(bp, bfilter);
2028 if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD) {
2029 RTE_LOG(ERR, PMD, "filter exists.");
2033 if (mfilter == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
2034 RTE_LOG(ERR, PMD, "filter doesn't exist.");
2039 if (filter_op == RTE_ETH_FILTER_ADD) {
2040 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
2041 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
2044 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
2046 if (mfilter == NULL) {
2047 /* This should not happen. But for Coverity! */
2051 ret = bnxt_hwrm_clear_ntuple_filter(bp, mfilter);
2053 STAILQ_REMOVE(&vnic->filter, mfilter, bnxt_filter_info,
2055 bnxt_free_filter(bp, mfilter);
2056 bfilter->fw_l2_filter_id = -1;
2057 bnxt_free_filter(bp, bfilter);
2062 bfilter->fw_l2_filter_id = -1;
2063 bnxt_free_filter(bp, bfilter);
2068 bnxt_ntuple_filter(struct rte_eth_dev *dev,
2069 enum rte_filter_op filter_op,
2072 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2075 if (filter_op == RTE_ETH_FILTER_NOP)
2079 RTE_LOG(ERR, PMD, "arg shouldn't be NULL for operation %u.",
2084 switch (filter_op) {
2085 case RTE_ETH_FILTER_ADD:
2086 ret = bnxt_cfg_ntuple_filter(bp,
2087 (struct rte_eth_ntuple_filter *)arg,
2090 case RTE_ETH_FILTER_DELETE:
2091 ret = bnxt_cfg_ntuple_filter(bp,
2092 (struct rte_eth_ntuple_filter *)arg,
2096 RTE_LOG(ERR, PMD, "unsupported operation %u.", filter_op);
2104 bnxt_parse_fdir_filter(struct bnxt *bp,
2105 struct rte_eth_fdir_filter *fdir,
2106 struct bnxt_filter_info *filter)
2108 enum rte_fdir_mode fdir_mode =
2109 bp->eth_dev->data->dev_conf.fdir_conf.mode;
2110 struct bnxt_vnic_info *vnic0, *vnic;
2111 struct bnxt_filter_info *filter1;
2115 if (fdir_mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
2118 filter->l2_ovlan = fdir->input.flow_ext.vlan_tci;
2119 en |= EM_FLOW_ALLOC_INPUT_EN_OVLAN_VID;
2121 switch (fdir->input.flow_type) {
2122 case RTE_ETH_FLOW_IPV4:
2123 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
2125 filter->src_ipaddr[0] = fdir->input.flow.ip4_flow.src_ip;
2126 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
2127 filter->dst_ipaddr[0] = fdir->input.flow.ip4_flow.dst_ip;
2128 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
2129 filter->ip_protocol = fdir->input.flow.ip4_flow.proto;
2130 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2131 filter->ip_addr_type =
2132 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
2133 filter->src_ipaddr_mask[0] = 0xffffffff;
2134 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2135 filter->dst_ipaddr_mask[0] = 0xffffffff;
2136 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2137 filter->ethertype = 0x800;
2138 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2140 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
2141 filter->src_port = fdir->input.flow.tcp4_flow.src_port;
2142 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
2143 filter->dst_port = fdir->input.flow.tcp4_flow.dst_port;
2144 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
2145 filter->dst_port_mask = 0xffff;
2146 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
2147 filter->src_port_mask = 0xffff;
2148 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
2149 filter->src_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.src_ip;
2150 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
2151 filter->dst_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.dst_ip;
2152 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
2153 filter->ip_protocol = 6;
2154 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2155 filter->ip_addr_type =
2156 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
2157 filter->src_ipaddr_mask[0] = 0xffffffff;
2158 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2159 filter->dst_ipaddr_mask[0] = 0xffffffff;
2160 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2161 filter->ethertype = 0x800;
2162 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2164 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
2165 filter->src_port = fdir->input.flow.udp4_flow.src_port;
2166 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
2167 filter->dst_port = fdir->input.flow.udp4_flow.dst_port;
2168 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
2169 filter->dst_port_mask = 0xffff;
2170 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
2171 filter->src_port_mask = 0xffff;
2172 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
2173 filter->src_ipaddr[0] = fdir->input.flow.udp4_flow.ip.src_ip;
2174 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
2175 filter->dst_ipaddr[0] = fdir->input.flow.udp4_flow.ip.dst_ip;
2176 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
2177 filter->ip_protocol = 17;
2178 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2179 filter->ip_addr_type =
2180 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
2181 filter->src_ipaddr_mask[0] = 0xffffffff;
2182 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2183 filter->dst_ipaddr_mask[0] = 0xffffffff;
2184 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2185 filter->ethertype = 0x800;
2186 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2188 case RTE_ETH_FLOW_IPV6:
2189 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
2191 filter->ip_addr_type =
2192 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
2193 filter->ip_protocol = fdir->input.flow.ipv6_flow.proto;
2194 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2195 rte_memcpy(filter->src_ipaddr,
2196 fdir->input.flow.ipv6_flow.src_ip, 16);
2197 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
2198 rte_memcpy(filter->dst_ipaddr,
2199 fdir->input.flow.ipv6_flow.dst_ip, 16);
2200 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
2201 memset(filter->dst_ipaddr_mask, 0xff, 16);
2202 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2203 memset(filter->src_ipaddr_mask, 0xff, 16);
2204 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2205 filter->ethertype = 0x86dd;
2206 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2208 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
2209 filter->src_port = fdir->input.flow.tcp6_flow.src_port;
2210 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
2211 filter->dst_port = fdir->input.flow.tcp6_flow.dst_port;
2212 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
2213 filter->dst_port_mask = 0xffff;
2214 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
2215 filter->src_port_mask = 0xffff;
2216 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
2217 filter->ip_addr_type =
2218 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
2219 filter->ip_protocol = fdir->input.flow.tcp6_flow.ip.proto;
2220 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2221 rte_memcpy(filter->src_ipaddr,
2222 fdir->input.flow.tcp6_flow.ip.src_ip, 16);
2223 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
2224 rte_memcpy(filter->dst_ipaddr,
2225 fdir->input.flow.tcp6_flow.ip.dst_ip, 16);
2226 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
2227 memset(filter->dst_ipaddr_mask, 0xff, 16);
2228 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2229 memset(filter->src_ipaddr_mask, 0xff, 16);
2230 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2231 filter->ethertype = 0x86dd;
2232 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2234 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
2235 filter->src_port = fdir->input.flow.udp6_flow.src_port;
2236 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
2237 filter->dst_port = fdir->input.flow.udp6_flow.dst_port;
2238 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
2239 filter->dst_port_mask = 0xffff;
2240 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
2241 filter->src_port_mask = 0xffff;
2242 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
2243 filter->ip_addr_type =
2244 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
2245 filter->ip_protocol = fdir->input.flow.udp6_flow.ip.proto;
2246 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2247 rte_memcpy(filter->src_ipaddr,
2248 fdir->input.flow.udp6_flow.ip.src_ip, 16);
2249 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
2250 rte_memcpy(filter->dst_ipaddr,
2251 fdir->input.flow.udp6_flow.ip.dst_ip, 16);
2252 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
2253 memset(filter->dst_ipaddr_mask, 0xff, 16);
2254 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2255 memset(filter->src_ipaddr_mask, 0xff, 16);
2256 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2257 filter->ethertype = 0x86dd;
2258 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2260 case RTE_ETH_FLOW_L2_PAYLOAD:
2261 filter->ethertype = fdir->input.flow.l2_flow.ether_type;
2262 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2264 case RTE_ETH_FLOW_VXLAN:
2265 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
2267 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
2268 filter->tunnel_type =
2269 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN;
2270 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
2272 case RTE_ETH_FLOW_NVGRE:
2273 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
2275 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
2276 filter->tunnel_type =
2277 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_NVGRE;
2278 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
2280 case RTE_ETH_FLOW_UNKNOWN:
2281 case RTE_ETH_FLOW_RAW:
2282 case RTE_ETH_FLOW_FRAG_IPV4:
2283 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
2284 case RTE_ETH_FLOW_FRAG_IPV6:
2285 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
2286 case RTE_ETH_FLOW_IPV6_EX:
2287 case RTE_ETH_FLOW_IPV6_TCP_EX:
2288 case RTE_ETH_FLOW_IPV6_UDP_EX:
2289 case RTE_ETH_FLOW_GENEVE:
2295 vnic0 = STAILQ_FIRST(&bp->ff_pool[0]);
2296 vnic = STAILQ_FIRST(&bp->ff_pool[fdir->action.rx_queue]);
2298 RTE_LOG(ERR, PMD, "Invalid queue %d\n", fdir->action.rx_queue);
2303 if (fdir_mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
2304 rte_memcpy(filter->dst_macaddr,
2305 fdir->input.flow.mac_vlan_flow.mac_addr.addr_bytes, 6);
2306 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
2309 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT) {
2310 filter->flags = HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
2311 filter1 = STAILQ_FIRST(&vnic0->filter);
2312 //filter1 = bnxt_get_l2_filter(bp, filter, vnic0);
2314 filter->dst_id = vnic->fw_vnic_id;
2315 for (i = 0; i < ETHER_ADDR_LEN; i++)
2316 if (filter->dst_macaddr[i] == 0x00)
2317 filter1 = STAILQ_FIRST(&vnic0->filter);
2319 filter1 = bnxt_get_l2_filter(bp, filter, vnic);
2322 if (filter1 == NULL)
2325 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
2326 filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
2328 filter->enables = en;
2333 static struct bnxt_filter_info *
2334 bnxt_match_fdir(struct bnxt *bp, struct bnxt_filter_info *nf)
2336 struct bnxt_filter_info *mf = NULL;
2339 for (i = bp->nr_vnics - 1; i >= 0; i--) {
2340 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2342 STAILQ_FOREACH(mf, &vnic->filter, next) {
2343 if (mf->filter_type == nf->filter_type &&
2344 mf->flags == nf->flags &&
2345 mf->src_port == nf->src_port &&
2346 mf->src_port_mask == nf->src_port_mask &&
2347 mf->dst_port == nf->dst_port &&
2348 mf->dst_port_mask == nf->dst_port_mask &&
2349 mf->ip_protocol == nf->ip_protocol &&
2350 mf->ip_addr_type == nf->ip_addr_type &&
2351 mf->ethertype == nf->ethertype &&
2352 mf->vni == nf->vni &&
2353 mf->tunnel_type == nf->tunnel_type &&
2354 mf->l2_ovlan == nf->l2_ovlan &&
2355 mf->l2_ovlan_mask == nf->l2_ovlan_mask &&
2356 mf->l2_ivlan == nf->l2_ivlan &&
2357 mf->l2_ivlan_mask == nf->l2_ivlan_mask &&
2358 !memcmp(mf->l2_addr, nf->l2_addr, ETHER_ADDR_LEN) &&
2359 !memcmp(mf->l2_addr_mask, nf->l2_addr_mask,
2361 !memcmp(mf->src_macaddr, nf->src_macaddr,
2363 !memcmp(mf->dst_macaddr, nf->dst_macaddr,
2365 !memcmp(mf->src_ipaddr, nf->src_ipaddr,
2366 sizeof(nf->src_ipaddr)) &&
2367 !memcmp(mf->src_ipaddr_mask, nf->src_ipaddr_mask,
2368 sizeof(nf->src_ipaddr_mask)) &&
2369 !memcmp(mf->dst_ipaddr, nf->dst_ipaddr,
2370 sizeof(nf->dst_ipaddr)) &&
2371 !memcmp(mf->dst_ipaddr_mask, nf->dst_ipaddr_mask,
2372 sizeof(nf->dst_ipaddr_mask)))
2380 bnxt_fdir_filter(struct rte_eth_dev *dev,
2381 enum rte_filter_op filter_op,
2384 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2385 struct rte_eth_fdir_filter *fdir = (struct rte_eth_fdir_filter *)arg;
2386 struct bnxt_filter_info *filter, *match;
2387 struct bnxt_vnic_info *vnic;
2390 if (filter_op == RTE_ETH_FILTER_NOP)
2393 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
2396 switch (filter_op) {
2397 case RTE_ETH_FILTER_ADD:
2398 case RTE_ETH_FILTER_DELETE:
2400 filter = bnxt_get_unused_filter(bp);
2401 if (filter == NULL) {
2403 "Not enough resources for a new flow.\n");
2407 ret = bnxt_parse_fdir_filter(bp, fdir, filter);
2410 filter->filter_type = HWRM_CFA_NTUPLE_FILTER;
2412 match = bnxt_match_fdir(bp, filter);
2413 if (match != NULL && filter_op == RTE_ETH_FILTER_ADD) {
2414 RTE_LOG(ERR, PMD, "Flow already exists.\n");
2418 if (match == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
2419 RTE_LOG(ERR, PMD, "Flow does not exist.\n");
2424 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
2425 vnic = STAILQ_FIRST(&bp->ff_pool[0]);
2428 STAILQ_FIRST(&bp->ff_pool[fdir->action.rx_queue]);
2430 if (filter_op == RTE_ETH_FILTER_ADD) {
2431 ret = bnxt_hwrm_set_ntuple_filter(bp,
2436 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
2438 ret = bnxt_hwrm_clear_ntuple_filter(bp, match);
2439 STAILQ_REMOVE(&vnic->filter, match,
2440 bnxt_filter_info, next);
2441 bnxt_free_filter(bp, match);
2442 filter->fw_l2_filter_id = -1;
2443 bnxt_free_filter(bp, filter);
2446 case RTE_ETH_FILTER_FLUSH:
2447 for (i = bp->nr_vnics - 1; i >= 0; i--) {
2448 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2450 STAILQ_FOREACH(filter, &vnic->filter, next) {
2451 if (filter->filter_type ==
2452 HWRM_CFA_NTUPLE_FILTER) {
2454 bnxt_hwrm_clear_ntuple_filter(bp,
2456 STAILQ_REMOVE(&vnic->filter, filter,
2457 bnxt_filter_info, next);
2462 case RTE_ETH_FILTER_UPDATE:
2463 case RTE_ETH_FILTER_STATS:
2464 case RTE_ETH_FILTER_INFO:
2466 RTE_LOG(ERR, PMD, "operation %u not implemented", filter_op);
2469 RTE_LOG(ERR, PMD, "unknown operation %u", filter_op);
2476 filter->fw_l2_filter_id = -1;
2477 bnxt_free_filter(bp, filter);
2482 bnxt_filter_ctrl_op(struct rte_eth_dev *dev __rte_unused,
2483 enum rte_filter_type filter_type,
2484 enum rte_filter_op filter_op, void *arg)
2488 switch (filter_type) {
2489 case RTE_ETH_FILTER_TUNNEL:
2491 "filter type: %d: To be implemented\n", filter_type);
2493 case RTE_ETH_FILTER_FDIR:
2494 ret = bnxt_fdir_filter(dev, filter_op, arg);
2496 case RTE_ETH_FILTER_NTUPLE:
2497 ret = bnxt_ntuple_filter(dev, filter_op, arg);
2499 case RTE_ETH_FILTER_ETHERTYPE:
2500 ret = bnxt_ethertype_filter(dev, filter_op, arg);
2502 case RTE_ETH_FILTER_GENERIC:
2503 if (filter_op != RTE_ETH_FILTER_GET)
2505 *(const void **)arg = &bnxt_flow_ops;
2509 "Filter type (%d) not supported", filter_type);
2516 static const uint32_t *
2517 bnxt_dev_supported_ptypes_get_op(struct rte_eth_dev *dev)
2519 static const uint32_t ptypes[] = {
2520 RTE_PTYPE_L2_ETHER_VLAN,
2521 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
2522 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
2526 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
2527 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
2528 RTE_PTYPE_INNER_L4_ICMP,
2529 RTE_PTYPE_INNER_L4_TCP,
2530 RTE_PTYPE_INNER_L4_UDP,
2534 if (dev->rx_pkt_burst == bnxt_recv_pkts)
2542 bnxt_get_eeprom_length_op(struct rte_eth_dev *dev)
2544 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2546 uint32_t dir_entries;
2547 uint32_t entry_length;
2549 RTE_LOG(INFO, PMD, "%s(): %04x:%02x:%02x:%02x\n",
2550 __func__, bp->pdev->addr.domain, bp->pdev->addr.bus,
2551 bp->pdev->addr.devid, bp->pdev->addr.function);
2553 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
2557 return dir_entries * entry_length;
2561 bnxt_get_eeprom_op(struct rte_eth_dev *dev,
2562 struct rte_dev_eeprom_info *in_eeprom)
2564 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2568 RTE_LOG(INFO, PMD, "%s(): %04x:%02x:%02x:%02x in_eeprom->offset = %d "
2569 "len = %d\n", __func__, bp->pdev->addr.domain,
2570 bp->pdev->addr.bus, bp->pdev->addr.devid,
2571 bp->pdev->addr.function, in_eeprom->offset, in_eeprom->length);
2573 if (in_eeprom->offset == 0) /* special offset value to get directory */
2574 return bnxt_get_nvram_directory(bp, in_eeprom->length,
2577 index = in_eeprom->offset >> 24;
2578 offset = in_eeprom->offset & 0xffffff;
2581 return bnxt_hwrm_get_nvram_item(bp, index - 1, offset,
2582 in_eeprom->length, in_eeprom->data);
2587 static bool bnxt_dir_type_is_ape_bin_format(uint16_t dir_type)
2590 case BNX_DIR_TYPE_CHIMP_PATCH:
2591 case BNX_DIR_TYPE_BOOTCODE:
2592 case BNX_DIR_TYPE_BOOTCODE_2:
2593 case BNX_DIR_TYPE_APE_FW:
2594 case BNX_DIR_TYPE_APE_PATCH:
2595 case BNX_DIR_TYPE_KONG_FW:
2596 case BNX_DIR_TYPE_KONG_PATCH:
2597 case BNX_DIR_TYPE_BONO_FW:
2598 case BNX_DIR_TYPE_BONO_PATCH:
2605 static bool bnxt_dir_type_is_other_exec_format(uint16_t dir_type)
2608 case BNX_DIR_TYPE_AVS:
2609 case BNX_DIR_TYPE_EXP_ROM_MBA:
2610 case BNX_DIR_TYPE_PCIE:
2611 case BNX_DIR_TYPE_TSCF_UCODE:
2612 case BNX_DIR_TYPE_EXT_PHY:
2613 case BNX_DIR_TYPE_CCM:
2614 case BNX_DIR_TYPE_ISCSI_BOOT:
2615 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
2616 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
2623 static bool bnxt_dir_type_is_executable(uint16_t dir_type)
2625 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
2626 bnxt_dir_type_is_other_exec_format(dir_type);
2630 bnxt_set_eeprom_op(struct rte_eth_dev *dev,
2631 struct rte_dev_eeprom_info *in_eeprom)
2633 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2634 uint8_t index, dir_op;
2635 uint16_t type, ext, ordinal, attr;
2637 RTE_LOG(INFO, PMD, "%s(): %04x:%02x:%02x:%02x in_eeprom->offset = %d "
2638 "len = %d\n", __func__, bp->pdev->addr.domain,
2639 bp->pdev->addr.bus, bp->pdev->addr.devid,
2640 bp->pdev->addr.function, in_eeprom->offset, in_eeprom->length);
2643 RTE_LOG(ERR, PMD, "NVM write not supported from a VF\n");
2647 type = in_eeprom->magic >> 16;
2649 if (type == 0xffff) { /* special value for directory operations */
2650 index = in_eeprom->magic & 0xff;
2651 dir_op = in_eeprom->magic >> 8;
2655 case 0x0e: /* erase */
2656 if (in_eeprom->offset != ~in_eeprom->magic)
2658 return bnxt_hwrm_erase_nvram_directory(bp, index - 1);
2664 /* Create or re-write an NVM item: */
2665 if (bnxt_dir_type_is_executable(type) == true)
2667 ext = in_eeprom->magic & 0xffff;
2668 ordinal = in_eeprom->offset >> 16;
2669 attr = in_eeprom->offset & 0xffff;
2671 return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
2672 in_eeprom->data, in_eeprom->length);
2680 static const struct eth_dev_ops bnxt_dev_ops = {
2681 .dev_infos_get = bnxt_dev_info_get_op,
2682 .dev_close = bnxt_dev_close_op,
2683 .dev_configure = bnxt_dev_configure_op,
2684 .dev_start = bnxt_dev_start_op,
2685 .dev_stop = bnxt_dev_stop_op,
2686 .dev_set_link_up = bnxt_dev_set_link_up_op,
2687 .dev_set_link_down = bnxt_dev_set_link_down_op,
2688 .stats_get = bnxt_stats_get_op,
2689 .stats_reset = bnxt_stats_reset_op,
2690 .rx_queue_setup = bnxt_rx_queue_setup_op,
2691 .rx_queue_release = bnxt_rx_queue_release_op,
2692 .tx_queue_setup = bnxt_tx_queue_setup_op,
2693 .tx_queue_release = bnxt_tx_queue_release_op,
2694 .rx_queue_intr_enable = bnxt_rx_queue_intr_enable_op,
2695 .rx_queue_intr_disable = bnxt_rx_queue_intr_disable_op,
2696 .reta_update = bnxt_reta_update_op,
2697 .reta_query = bnxt_reta_query_op,
2698 .rss_hash_update = bnxt_rss_hash_update_op,
2699 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
2700 .link_update = bnxt_link_update_op,
2701 .promiscuous_enable = bnxt_promiscuous_enable_op,
2702 .promiscuous_disable = bnxt_promiscuous_disable_op,
2703 .allmulticast_enable = bnxt_allmulticast_enable_op,
2704 .allmulticast_disable = bnxt_allmulticast_disable_op,
2705 .mac_addr_add = bnxt_mac_addr_add_op,
2706 .mac_addr_remove = bnxt_mac_addr_remove_op,
2707 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
2708 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
2709 .udp_tunnel_port_add = bnxt_udp_tunnel_port_add_op,
2710 .udp_tunnel_port_del = bnxt_udp_tunnel_port_del_op,
2711 .vlan_filter_set = bnxt_vlan_filter_set_op,
2712 .vlan_offload_set = bnxt_vlan_offload_set_op,
2713 .vlan_pvid_set = bnxt_vlan_pvid_set_op,
2714 .mtu_set = bnxt_mtu_set_op,
2715 .mac_addr_set = bnxt_set_default_mac_addr_op,
2716 .xstats_get = bnxt_dev_xstats_get_op,
2717 .xstats_get_names = bnxt_dev_xstats_get_names_op,
2718 .xstats_reset = bnxt_dev_xstats_reset_op,
2719 .fw_version_get = bnxt_fw_version_get,
2720 .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
2721 .rxq_info_get = bnxt_rxq_info_get_op,
2722 .txq_info_get = bnxt_txq_info_get_op,
2723 .dev_led_on = bnxt_dev_led_on_op,
2724 .dev_led_off = bnxt_dev_led_off_op,
2725 .xstats_get_by_id = bnxt_dev_xstats_get_by_id_op,
2726 .xstats_get_names_by_id = bnxt_dev_xstats_get_names_by_id_op,
2727 .rx_queue_count = bnxt_rx_queue_count_op,
2728 .rx_descriptor_status = bnxt_rx_descriptor_status_op,
2729 .tx_descriptor_status = bnxt_tx_descriptor_status_op,
2730 .filter_ctrl = bnxt_filter_ctrl_op,
2731 .dev_supported_ptypes_get = bnxt_dev_supported_ptypes_get_op,
2732 .get_eeprom_length = bnxt_get_eeprom_length_op,
2733 .get_eeprom = bnxt_get_eeprom_op,
2734 .set_eeprom = bnxt_set_eeprom_op,
2737 static bool bnxt_vf_pciid(uint16_t id)
2739 if (id == BROADCOM_DEV_ID_57304_VF ||
2740 id == BROADCOM_DEV_ID_57406_VF ||
2741 id == BROADCOM_DEV_ID_5731X_VF ||
2742 id == BROADCOM_DEV_ID_5741X_VF ||
2743 id == BROADCOM_DEV_ID_57414_VF ||
2744 id == BROADCOM_DEV_ID_STRATUS_NIC_VF)
2749 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
2751 struct bnxt *bp = eth_dev->data->dev_private;
2752 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2755 /* enable device (incl. PCI PM wakeup), and bus-mastering */
2756 if (!pci_dev->mem_resource[0].addr) {
2758 "Cannot find PCI device base address, aborting\n");
2760 goto init_err_disable;
2763 bp->eth_dev = eth_dev;
2766 bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
2768 RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
2770 goto init_err_release;
2783 static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
2785 #define ALLOW_FUNC(x) \
2787 typeof(x) arg = (x); \
2788 bp->pf.vf_req_fwd[((arg) >> 5)] &= \
2789 ~rte_cpu_to_le_32(1 << ((arg) & 0x1f)); \
2792 bnxt_dev_init(struct rte_eth_dev *eth_dev)
2794 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2795 char mz_name[RTE_MEMZONE_NAMESIZE];
2796 const struct rte_memzone *mz = NULL;
2797 static int version_printed;
2798 uint32_t total_alloc_len;
2799 rte_iova_t mz_phys_addr;
2803 if (version_printed++ == 0)
2804 RTE_LOG(INFO, PMD, "%s\n", bnxt_version);
2806 rte_eth_copy_pci_info(eth_dev, pci_dev);
2808 bp = eth_dev->data->dev_private;
2810 rte_atomic64_init(&bp->rx_mbuf_alloc_fail);
2811 bp->dev_stopped = 1;
2813 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2816 if (bnxt_vf_pciid(pci_dev->id.device_id))
2817 bp->flags |= BNXT_FLAG_VF;
2819 rc = bnxt_init_board(eth_dev);
2822 "Board initialization failed rc: %x\n", rc);
2826 eth_dev->dev_ops = &bnxt_dev_ops;
2827 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2829 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
2830 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
2832 if (BNXT_PF(bp) && pci_dev->id.device_id != BROADCOM_DEV_ID_NS2) {
2833 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
2834 "bnxt_%04x:%02x:%02x:%02x-%s", pci_dev->addr.domain,
2835 pci_dev->addr.bus, pci_dev->addr.devid,
2836 pci_dev->addr.function, "rx_port_stats");
2837 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
2838 mz = rte_memzone_lookup(mz_name);
2839 total_alloc_len = RTE_CACHE_LINE_ROUNDUP(
2840 sizeof(struct rx_port_stats) + 512);
2842 mz = rte_memzone_reserve(mz_name, total_alloc_len,
2845 RTE_MEMZONE_SIZE_HINT_ONLY);
2849 memset(mz->addr, 0, mz->len);
2850 mz_phys_addr = mz->iova;
2851 if ((unsigned long)mz->addr == mz_phys_addr) {
2852 RTE_LOG(WARNING, PMD,
2853 "Memzone physical address same as virtual.\n");
2854 RTE_LOG(WARNING, PMD,
2855 "Using rte_mem_virt2iova()\n");
2856 mz_phys_addr = rte_mem_virt2iova(mz->addr);
2857 if (mz_phys_addr == 0) {
2859 "unable to map address to physical memory\n");
2864 bp->rx_mem_zone = (const void *)mz;
2865 bp->hw_rx_port_stats = mz->addr;
2866 bp->hw_rx_port_stats_map = mz_phys_addr;
2868 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
2869 "bnxt_%04x:%02x:%02x:%02x-%s", pci_dev->addr.domain,
2870 pci_dev->addr.bus, pci_dev->addr.devid,
2871 pci_dev->addr.function, "tx_port_stats");
2872 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
2873 mz = rte_memzone_lookup(mz_name);
2874 total_alloc_len = RTE_CACHE_LINE_ROUNDUP(
2875 sizeof(struct tx_port_stats) + 512);
2877 mz = rte_memzone_reserve(mz_name, total_alloc_len,
2880 RTE_MEMZONE_SIZE_HINT_ONLY);
2884 memset(mz->addr, 0, mz->len);
2885 mz_phys_addr = mz->iova;
2886 if ((unsigned long)mz->addr == mz_phys_addr) {
2887 RTE_LOG(WARNING, PMD,
2888 "Memzone physical address same as virtual.\n");
2889 RTE_LOG(WARNING, PMD,
2890 "Using rte_mem_virt2iova()\n");
2891 mz_phys_addr = rte_mem_virt2iova(mz->addr);
2892 if (mz_phys_addr == 0) {
2894 "unable to map address to physical memory\n");
2899 bp->tx_mem_zone = (const void *)mz;
2900 bp->hw_tx_port_stats = mz->addr;
2901 bp->hw_tx_port_stats_map = mz_phys_addr;
2903 bp->flags |= BNXT_FLAG_PORT_STATS;
2906 rc = bnxt_alloc_hwrm_resources(bp);
2909 "hwrm resource allocation failure rc: %x\n", rc);
2912 rc = bnxt_hwrm_ver_get(bp);
2915 bnxt_hwrm_queue_qportcfg(bp);
2917 bnxt_hwrm_func_qcfg(bp);
2919 /* Get the MAX capabilities for this function */
2920 rc = bnxt_hwrm_func_qcaps(bp);
2922 RTE_LOG(ERR, PMD, "hwrm query capability failure rc: %x\n", rc);
2925 if (bp->max_tx_rings == 0) {
2926 RTE_LOG(ERR, PMD, "No TX rings available!\n");
2930 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
2931 ETHER_ADDR_LEN * bp->max_l2_ctx, 0);
2932 if (eth_dev->data->mac_addrs == NULL) {
2934 "Failed to alloc %u bytes needed to store MAC addr tbl",
2935 ETHER_ADDR_LEN * bp->max_l2_ctx);
2939 /* Copy the permanent MAC from the qcap response address now. */
2940 memcpy(bp->mac_addr, bp->dflt_mac_addr, sizeof(bp->mac_addr));
2941 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
2942 bp->grp_info = rte_zmalloc("bnxt_grp_info",
2943 sizeof(*bp->grp_info) * bp->max_ring_grps, 0);
2944 if (!bp->grp_info) {
2946 "Failed to alloc %zu bytes needed to store group info table\n",
2947 sizeof(*bp->grp_info) * bp->max_ring_grps);
2952 /* Forward all requests if firmware is new enough */
2953 if (((bp->fw_ver >= ((20 << 24) | (6 << 16) | (100 << 8))) &&
2954 (bp->fw_ver < ((20 << 24) | (7 << 16)))) ||
2955 ((bp->fw_ver >= ((20 << 24) | (8 << 16))))) {
2956 memset(bp->pf.vf_req_fwd, 0xff, sizeof(bp->pf.vf_req_fwd));
2958 RTE_LOG(WARNING, PMD,
2959 "Firmware too old for VF mailbox functionality\n");
2960 memset(bp->pf.vf_req_fwd, 0, sizeof(bp->pf.vf_req_fwd));
2964 * The following are used for driver cleanup. If we disallow these,
2965 * VF drivers can't clean up cleanly.
2967 ALLOW_FUNC(HWRM_FUNC_DRV_UNRGTR);
2968 ALLOW_FUNC(HWRM_VNIC_FREE);
2969 ALLOW_FUNC(HWRM_RING_FREE);
2970 ALLOW_FUNC(HWRM_RING_GRP_FREE);
2971 ALLOW_FUNC(HWRM_VNIC_RSS_COS_LB_CTX_FREE);
2972 ALLOW_FUNC(HWRM_CFA_L2_FILTER_FREE);
2973 ALLOW_FUNC(HWRM_STAT_CTX_FREE);
2974 ALLOW_FUNC(HWRM_PORT_PHY_QCFG);
2975 ALLOW_FUNC(HWRM_VNIC_TPA_CFG);
2976 rc = bnxt_hwrm_func_driver_register(bp);
2979 "Failed to register driver");
2985 DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
2986 pci_dev->mem_resource[0].phys_addr,
2987 pci_dev->mem_resource[0].addr);
2989 rc = bnxt_hwrm_func_reset(bp);
2991 RTE_LOG(ERR, PMD, "hwrm chip reset failure rc: %x\n", rc);
2997 //if (bp->pf.active_vfs) {
2998 // TODO: Deallocate VF resources?
3000 if (bp->pdev->max_vfs) {
3001 rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
3003 RTE_LOG(ERR, PMD, "Failed to allocate VFs\n");
3007 rc = bnxt_hwrm_allocate_pf_only(bp);
3010 "Failed to allocate PF resources\n");
3016 bnxt_hwrm_port_led_qcaps(bp);
3018 rc = bnxt_setup_int(bp);
3022 rc = bnxt_alloc_mem(bp);
3024 goto error_free_int;
3026 rc = bnxt_request_int(bp);
3028 goto error_free_int;
3030 rc = bnxt_alloc_def_cp_ring(bp);
3032 goto error_free_int;
3034 bnxt_enable_int(bp);
3039 bnxt_disable_int(bp);
3040 bnxt_free_def_cp_ring(bp);
3041 bnxt_hwrm_func_buf_unrgtr(bp);
3045 bnxt_dev_uninit(eth_dev);
3051 bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
3052 struct bnxt *bp = eth_dev->data->dev_private;
3055 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3058 bnxt_disable_int(bp);
3061 if (eth_dev->data->mac_addrs != NULL) {
3062 rte_free(eth_dev->data->mac_addrs);
3063 eth_dev->data->mac_addrs = NULL;
3065 if (bp->grp_info != NULL) {
3066 rte_free(bp->grp_info);
3067 bp->grp_info = NULL;
3069 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
3070 bnxt_free_hwrm_resources(bp);
3071 rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
3072 rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
3073 if (bp->dev_stopped == 0)
3074 bnxt_dev_close_op(eth_dev);
3076 rte_free(bp->pf.vf_info);
3077 eth_dev->dev_ops = NULL;
3078 eth_dev->rx_pkt_burst = NULL;
3079 eth_dev->tx_pkt_burst = NULL;
3084 static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3085 struct rte_pci_device *pci_dev)
3087 return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct bnxt),
3091 static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
3093 return rte_eth_dev_pci_generic_remove(pci_dev, bnxt_dev_uninit);
3096 static struct rte_pci_driver bnxt_rte_pmd = {
3097 .id_table = bnxt_pci_id_map,
3098 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
3099 RTE_PCI_DRV_INTR_LSC,
3100 .probe = bnxt_pci_probe,
3101 .remove = bnxt_pci_remove,
3105 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
3107 if (strcmp(dev->device->driver->name, drv->driver.name))
3113 bool is_bnxt_supported(struct rte_eth_dev *dev)
3115 return is_device_supported(dev, &bnxt_rte_pmd);
3118 RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
3119 RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
3120 RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");