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"
57 #define DRV_MODULE_NAME "bnxt"
58 static const char bnxt_version[] =
59 "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
61 #define PCI_VENDOR_ID_BROADCOM 0x14E4
63 #define BROADCOM_DEV_ID_STRATUS_NIC 0x1614
64 #define BROADCOM_DEV_ID_57414_VF 0x16c1
65 #define BROADCOM_DEV_ID_57301 0x16c8
66 #define BROADCOM_DEV_ID_57302 0x16c9
67 #define BROADCOM_DEV_ID_57304_PF 0x16ca
68 #define BROADCOM_DEV_ID_57304_VF 0x16cb
69 #define BROADCOM_DEV_ID_57417_MF 0x16cc
70 #define BROADCOM_DEV_ID_NS2 0x16cd
71 #define BROADCOM_DEV_ID_57311 0x16ce
72 #define BROADCOM_DEV_ID_57312 0x16cf
73 #define BROADCOM_DEV_ID_57402 0x16d0
74 #define BROADCOM_DEV_ID_57404 0x16d1
75 #define BROADCOM_DEV_ID_57406_PF 0x16d2
76 #define BROADCOM_DEV_ID_57406_VF 0x16d3
77 #define BROADCOM_DEV_ID_57402_MF 0x16d4
78 #define BROADCOM_DEV_ID_57407_RJ45 0x16d5
79 #define BROADCOM_DEV_ID_57412 0x16d6
80 #define BROADCOM_DEV_ID_57414 0x16d7
81 #define BROADCOM_DEV_ID_57416_RJ45 0x16d8
82 #define BROADCOM_DEV_ID_57417_RJ45 0x16d9
83 #define BROADCOM_DEV_ID_5741X_VF 0x16dc
84 #define BROADCOM_DEV_ID_57412_MF 0x16de
85 #define BROADCOM_DEV_ID_57314 0x16df
86 #define BROADCOM_DEV_ID_57317_RJ45 0x16e0
87 #define BROADCOM_DEV_ID_5731X_VF 0x16e1
88 #define BROADCOM_DEV_ID_57417_SFP 0x16e2
89 #define BROADCOM_DEV_ID_57416_SFP 0x16e3
90 #define BROADCOM_DEV_ID_57317_SFP 0x16e4
91 #define BROADCOM_DEV_ID_57404_MF 0x16e7
92 #define BROADCOM_DEV_ID_57406_MF 0x16e8
93 #define BROADCOM_DEV_ID_57407_SFP 0x16e9
94 #define BROADCOM_DEV_ID_57407_MF 0x16ea
95 #define BROADCOM_DEV_ID_57414_MF 0x16ec
96 #define BROADCOM_DEV_ID_57416_MF 0x16ee
98 static const struct rte_pci_id bnxt_pci_id_map[] = {
99 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
100 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
101 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
102 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
103 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
104 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
105 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
106 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
107 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
108 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
109 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
110 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
111 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
112 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
113 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
114 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
115 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
116 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
117 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
118 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
119 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
120 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
121 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
122 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
123 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
124 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
125 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
126 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
127 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
128 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
129 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
130 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
131 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
132 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
133 { .vendor_id = 0, /* sentinel */ },
136 #define BNXT_ETH_RSS_SUPPORT ( \
138 ETH_RSS_NONFRAG_IPV4_TCP | \
139 ETH_RSS_NONFRAG_IPV4_UDP | \
141 ETH_RSS_NONFRAG_IPV6_TCP | \
142 ETH_RSS_NONFRAG_IPV6_UDP)
144 /***********************/
147 * High level utility functions
150 static void bnxt_free_mem(struct bnxt *bp)
152 bnxt_free_filter_mem(bp);
153 bnxt_free_vnic_attributes(bp);
154 bnxt_free_vnic_mem(bp);
157 bnxt_free_tx_rings(bp);
158 bnxt_free_rx_rings(bp);
159 bnxt_free_def_cp_ring(bp);
162 static int bnxt_alloc_mem(struct bnxt *bp)
166 /* Default completion ring */
167 rc = bnxt_init_def_ring_struct(bp, SOCKET_ID_ANY);
171 rc = bnxt_alloc_rings(bp, 0, NULL, NULL,
172 bp->def_cp_ring, "def_cp");
176 rc = bnxt_alloc_vnic_mem(bp);
180 rc = bnxt_alloc_vnic_attributes(bp);
184 rc = bnxt_alloc_filter_mem(bp);
195 static int bnxt_init_chip(struct bnxt *bp)
197 unsigned int i, rss_idx, fw_idx;
198 struct rte_eth_link new;
201 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
203 RTE_LOG(ERR, PMD, "HWRM stat ctx alloc failure rc: %x\n", rc);
207 rc = bnxt_alloc_hwrm_rings(bp);
209 RTE_LOG(ERR, PMD, "HWRM ring alloc failure rc: %x\n", rc);
213 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
215 RTE_LOG(ERR, PMD, "HWRM ring grp alloc failure: %x\n", rc);
219 rc = bnxt_mq_rx_configure(bp);
221 RTE_LOG(ERR, PMD, "MQ mode configure failure rc: %x\n", rc);
225 /* VNIC configuration */
226 for (i = 0; i < bp->nr_vnics; i++) {
227 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
229 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
231 RTE_LOG(ERR, PMD, "HWRM vnic %d alloc failure rc: %x\n",
236 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic);
239 "HWRM vnic %d ctx alloc failure rc: %x\n",
244 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
246 RTE_LOG(ERR, PMD, "HWRM vnic %d cfg failure rc: %x\n",
251 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
254 "HWRM vnic %d filter failure rc: %x\n",
258 if (vnic->rss_table && vnic->hash_type) {
260 * Fill the RSS hash & redirection table with
261 * ring group ids for all VNICs
263 for (rss_idx = 0, fw_idx = 0;
264 rss_idx < HW_HASH_INDEX_SIZE;
265 rss_idx++, fw_idx++) {
266 if (vnic->fw_grp_ids[fw_idx] ==
269 vnic->rss_table[rss_idx] =
270 vnic->fw_grp_ids[fw_idx];
272 rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
275 "HWRM vnic %d set RSS failure rc: %x\n",
281 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0]);
284 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
288 rc = bnxt_get_hwrm_link_config(bp, &new);
290 RTE_LOG(ERR, PMD, "HWRM Get link config failure rc: %x\n", rc);
294 if (!bp->link_info.link_up) {
295 rc = bnxt_set_hwrm_link_config(bp, true);
298 "HWRM link config failure rc: %x\n", rc);
306 bnxt_free_all_hwrm_resources(bp);
311 static int bnxt_shutdown_nic(struct bnxt *bp)
313 bnxt_free_all_hwrm_resources(bp);
314 bnxt_free_all_filters(bp);
315 bnxt_free_all_vnics(bp);
319 static int bnxt_init_nic(struct bnxt *bp)
323 bnxt_init_ring_grps(bp);
325 bnxt_init_filters(bp);
327 rc = bnxt_init_chip(bp);
335 * Device configuration and status function
338 static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
339 struct rte_eth_dev_info *dev_info)
341 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
342 uint16_t max_vnics, i, j, vpool, vrxq;
344 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
347 dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
348 dev_info->max_hash_mac_addrs = 0;
350 /* PF/VF specifics */
352 dev_info->max_vfs = bp->pdev->max_vfs;
353 dev_info->max_rx_queues = bp->max_rx_rings;
354 dev_info->max_tx_queues = bp->max_tx_rings;
355 dev_info->reta_size = bp->max_rsscos_ctx;
356 max_vnics = bp->max_vnics;
358 /* Fast path specifics */
359 dev_info->min_rx_bufsize = 1;
360 dev_info->max_rx_pktlen = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN
362 dev_info->rx_offload_capa = 0;
363 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
364 DEV_TX_OFFLOAD_TCP_CKSUM |
365 DEV_TX_OFFLOAD_UDP_CKSUM |
366 DEV_TX_OFFLOAD_TCP_TSO |
367 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
368 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
369 DEV_TX_OFFLOAD_GRE_TNL_TSO |
370 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
371 DEV_TX_OFFLOAD_GENEVE_TNL_TSO;
374 dev_info->default_rxconf = (struct rte_eth_rxconf) {
380 .rx_free_thresh = 32,
384 dev_info->default_txconf = (struct rte_eth_txconf) {
390 .tx_free_thresh = 32,
392 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
393 ETH_TXQ_FLAGS_NOOFFLOADS,
395 eth_dev->data->dev_conf.intr_conf.lsc = 1;
400 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
401 * need further investigation.
405 vpool = 64; /* ETH_64_POOLS */
406 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
407 for (i = 0; i < 4; vpool >>= 1, i++) {
408 if (max_vnics > vpool) {
409 for (j = 0; j < 5; vrxq >>= 1, j++) {
410 if (dev_info->max_rx_queues > vrxq) {
416 /* Not enough resources to support VMDq */
420 /* Not enough resources to support VMDq */
424 dev_info->max_vmdq_pools = vpool;
425 dev_info->vmdq_queue_num = vrxq;
427 dev_info->vmdq_pool_base = 0;
428 dev_info->vmdq_queue_base = 0;
431 /* Configure the device based on the configuration provided */
432 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
434 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
436 bp->rx_queues = (void *)eth_dev->data->rx_queues;
437 bp->tx_queues = (void *)eth_dev->data->tx_queues;
439 /* Inherit new configurations */
440 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
441 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
442 bp->rx_cp_nr_rings = bp->rx_nr_rings;
443 bp->tx_cp_nr_rings = bp->tx_nr_rings;
445 if (eth_dev->data->dev_conf.rxmode.jumbo_frame)
447 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
448 ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE;
453 rte_bnxt_atomic_write_link_status(struct rte_eth_dev *eth_dev,
454 struct rte_eth_link *link)
456 struct rte_eth_link *dst = ð_dev->data->dev_link;
457 struct rte_eth_link *src = link;
459 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
460 *(uint64_t *)src) == 0)
466 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
468 struct rte_eth_link *link = ð_dev->data->dev_link;
470 if (link->link_status)
471 RTE_LOG(INFO, PMD, "Port %d Link Up - speed %u Mbps - %s\n",
472 (uint8_t)(eth_dev->data->port_id),
473 (uint32_t)link->link_speed,
474 (link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
475 ("full-duplex") : ("half-duplex\n"));
477 RTE_LOG(INFO, PMD, "Port %d Link Down\n",
478 (uint8_t)(eth_dev->data->port_id));
481 static int bnxt_dev_lsc_intr_setup(struct rte_eth_dev *eth_dev)
483 bnxt_print_link_info(eth_dev);
487 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
489 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
494 rc = bnxt_init_nic(bp);
498 bnxt_link_update_op(eth_dev, 0);
502 bnxt_shutdown_nic(bp);
503 bnxt_free_tx_mbufs(bp);
504 bnxt_free_rx_mbufs(bp);
508 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
510 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
512 eth_dev->data->dev_link.link_status = 1;
513 bnxt_set_hwrm_link_config(bp, true);
517 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
519 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
521 eth_dev->data->dev_link.link_status = 0;
522 bnxt_set_hwrm_link_config(bp, false);
526 /* Unload the driver, release resources */
527 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
529 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
531 if (bp->eth_dev->data->dev_started) {
532 /* TBD: STOP HW queues DMA */
533 eth_dev->data->dev_link.link_status = 0;
535 bnxt_set_hwrm_link_config(bp, false);
536 bnxt_shutdown_nic(bp);
540 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
542 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
544 if (bp->dev_stopped == 0)
545 bnxt_dev_stop_op(eth_dev);
547 bnxt_free_tx_mbufs(bp);
548 bnxt_free_rx_mbufs(bp);
550 if (eth_dev->data->mac_addrs != NULL) {
551 rte_free(eth_dev->data->mac_addrs);
552 eth_dev->data->mac_addrs = NULL;
554 if (bp->grp_info != NULL) {
555 rte_free(bp->grp_info);
560 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
563 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
564 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
565 struct bnxt_vnic_info *vnic;
566 struct bnxt_filter_info *filter, *temp_filter;
570 * Loop through all VNICs from the specified filter flow pools to
571 * remove the corresponding MAC addr filter
573 for (i = 0; i < MAX_FF_POOLS; i++) {
574 if (!(pool_mask & (1ULL << i)))
577 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
578 filter = STAILQ_FIRST(&vnic->filter);
580 temp_filter = STAILQ_NEXT(filter, next);
581 if (filter->mac_index == index) {
582 STAILQ_REMOVE(&vnic->filter, filter,
583 bnxt_filter_info, next);
584 bnxt_hwrm_clear_filter(bp, filter);
585 filter->mac_index = INVALID_MAC_INDEX;
586 memset(&filter->l2_addr, 0,
589 &bp->free_filter_list,
592 filter = temp_filter;
598 static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
599 struct ether_addr *mac_addr,
600 uint32_t index, uint32_t pool)
602 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
603 struct bnxt_vnic_info *vnic = STAILQ_FIRST(&bp->ff_pool[pool]);
604 struct bnxt_filter_info *filter;
607 RTE_LOG(ERR, PMD, "Cannot add MAC address to a VF interface\n");
612 RTE_LOG(ERR, PMD, "VNIC not found for pool %d!\n", pool);
615 /* Attach requested MAC address to the new l2_filter */
616 STAILQ_FOREACH(filter, &vnic->filter, next) {
617 if (filter->mac_index == index) {
619 "MAC addr already existed for pool %d\n", pool);
623 filter = bnxt_alloc_filter(bp);
625 RTE_LOG(ERR, PMD, "L2 filter alloc failed\n");
628 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
629 filter->mac_index = index;
630 memcpy(filter->l2_addr, mac_addr, ETHER_ADDR_LEN);
631 return bnxt_hwrm_set_filter(bp, vnic, filter);
634 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
637 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
638 struct rte_eth_link new;
639 unsigned int cnt = BNXT_LINK_WAIT_CNT;
641 memset(&new, 0, sizeof(new));
643 /* Retrieve link info from hardware */
644 rc = bnxt_get_hwrm_link_config(bp, &new);
646 new.link_speed = ETH_LINK_SPEED_100M;
647 new.link_duplex = ETH_LINK_FULL_DUPLEX;
649 "Failed to retrieve link rc = 0x%x!\n", rc);
652 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
654 if (!wait_to_complete)
656 } while (!new.link_status && cnt--);
659 /* Timed out or success */
660 if (new.link_status != eth_dev->data->dev_link.link_status ||
661 new.link_speed != eth_dev->data->dev_link.link_speed) {
662 rte_bnxt_atomic_write_link_status(eth_dev, &new);
663 bnxt_print_link_info(eth_dev);
669 static void bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
671 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
672 struct bnxt_vnic_info *vnic;
674 if (bp->vnic_info == NULL)
677 vnic = &bp->vnic_info[0];
679 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
680 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
683 static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
685 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
686 struct bnxt_vnic_info *vnic;
688 if (bp->vnic_info == NULL)
691 vnic = &bp->vnic_info[0];
693 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
694 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
697 static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
699 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
700 struct bnxt_vnic_info *vnic;
702 if (bp->vnic_info == NULL)
705 vnic = &bp->vnic_info[0];
707 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
708 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
711 static void bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
713 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
714 struct bnxt_vnic_info *vnic;
716 if (bp->vnic_info == NULL)
719 vnic = &bp->vnic_info[0];
721 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
722 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
725 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
726 struct rte_eth_rss_reta_entry64 *reta_conf,
729 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
730 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
731 struct bnxt_vnic_info *vnic;
734 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
737 if (reta_size != HW_HASH_INDEX_SIZE) {
738 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
739 "(%d) must equal the size supported by the hardware "
740 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
743 /* Update the RSS VNIC(s) */
744 for (i = 0; i < MAX_FF_POOLS; i++) {
745 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
746 memcpy(vnic->rss_table, reta_conf, reta_size);
748 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
754 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
755 struct rte_eth_rss_reta_entry64 *reta_conf,
758 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
759 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
760 struct rte_intr_handle *intr_handle
761 = &bp->pdev->intr_handle;
763 /* Retrieve from the default VNIC */
766 if (!vnic->rss_table)
769 if (reta_size != HW_HASH_INDEX_SIZE) {
770 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
771 "(%d) must equal the size supported by the hardware "
772 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
775 /* EW - need to revisit here copying from u64 to u16 */
776 memcpy(reta_conf, vnic->rss_table, reta_size);
778 if (rte_intr_allow_others(intr_handle)) {
779 if (eth_dev->data->dev_conf.intr_conf.lsc != 0)
780 bnxt_dev_lsc_intr_setup(eth_dev);
786 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
787 struct rte_eth_rss_conf *rss_conf)
789 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
790 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
791 struct bnxt_vnic_info *vnic;
792 uint16_t hash_type = 0;
796 * If RSS enablement were different than dev_configure,
797 * then return -EINVAL
799 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
800 if (!rss_conf->rss_hf)
803 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
806 if (rss_conf->rss_hf & ETH_RSS_IPV4)
807 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
808 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
809 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
810 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
811 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
812 if (rss_conf->rss_hf & ETH_RSS_IPV6)
813 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
814 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
815 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
816 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
817 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
819 /* Update the RSS VNIC(s) */
820 for (i = 0; i < MAX_FF_POOLS; i++) {
821 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
822 vnic->hash_type = hash_type;
825 * Use the supplied key if the key length is
826 * acceptable and the rss_key is not NULL
828 if (rss_conf->rss_key &&
829 rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
830 memcpy(vnic->rss_hash_key, rss_conf->rss_key,
831 rss_conf->rss_key_len);
833 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
839 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
840 struct rte_eth_rss_conf *rss_conf)
842 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
843 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
847 /* RSS configuration is the same for all VNICs */
848 if (vnic && vnic->rss_hash_key) {
849 if (rss_conf->rss_key) {
850 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
851 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
852 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
855 hash_types = vnic->hash_type;
856 rss_conf->rss_hf = 0;
857 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
858 rss_conf->rss_hf |= ETH_RSS_IPV4;
859 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
861 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
862 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
864 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
866 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
867 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
869 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
871 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
872 rss_conf->rss_hf |= ETH_RSS_IPV6;
873 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
875 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
876 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
878 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
880 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
881 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
883 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
887 "Unknwon RSS config from firmware (%08x), RSS disabled",
892 rss_conf->rss_hf = 0;
897 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
898 struct rte_eth_fc_conf *fc_conf)
900 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
901 struct rte_eth_link link_info;
904 rc = bnxt_get_hwrm_link_config(bp, &link_info);
908 memset(fc_conf, 0, sizeof(*fc_conf));
909 if (bp->link_info.auto_pause)
910 fc_conf->autoneg = 1;
911 switch (bp->link_info.pause) {
913 fc_conf->mode = RTE_FC_NONE;
915 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
916 fc_conf->mode = RTE_FC_TX_PAUSE;
918 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
919 fc_conf->mode = RTE_FC_RX_PAUSE;
921 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
922 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
923 fc_conf->mode = RTE_FC_FULL;
929 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
930 struct rte_eth_fc_conf *fc_conf)
932 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
934 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp)) {
935 RTE_LOG(ERR, PMD, "Flow Control Settings cannot be modified\n");
939 switch (fc_conf->mode) {
941 bp->link_info.auto_pause = 0;
942 bp->link_info.force_pause = 0;
944 case RTE_FC_RX_PAUSE:
945 if (fc_conf->autoneg) {
946 bp->link_info.auto_pause =
947 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
948 bp->link_info.force_pause = 0;
950 bp->link_info.auto_pause = 0;
951 bp->link_info.force_pause =
952 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
955 case RTE_FC_TX_PAUSE:
956 if (fc_conf->autoneg) {
957 bp->link_info.auto_pause =
958 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
959 bp->link_info.force_pause = 0;
961 bp->link_info.auto_pause = 0;
962 bp->link_info.force_pause =
963 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
967 if (fc_conf->autoneg) {
968 bp->link_info.auto_pause =
969 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
970 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
971 bp->link_info.force_pause = 0;
973 bp->link_info.auto_pause = 0;
974 bp->link_info.force_pause =
975 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
976 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
980 return bnxt_set_hwrm_link_config(bp, true);
983 /* Add UDP tunneling port */
985 bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
986 struct rte_eth_udp_tunnel *udp_tunnel)
988 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
989 uint16_t tunnel_type = 0;
992 switch (udp_tunnel->prot_type) {
993 case RTE_TUNNEL_TYPE_VXLAN:
994 if (bp->vxlan_port_cnt) {
995 RTE_LOG(ERR, PMD, "Tunnel Port %d already programmed\n",
996 udp_tunnel->udp_port);
997 if (bp->vxlan_port != udp_tunnel->udp_port) {
998 RTE_LOG(ERR, PMD, "Only one port allowed\n");
1001 bp->vxlan_port_cnt++;
1005 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
1006 bp->vxlan_port_cnt++;
1008 case RTE_TUNNEL_TYPE_GENEVE:
1009 if (bp->geneve_port_cnt) {
1010 RTE_LOG(ERR, PMD, "Tunnel Port %d already programmed\n",
1011 udp_tunnel->udp_port);
1012 if (bp->geneve_port != udp_tunnel->udp_port) {
1013 RTE_LOG(ERR, PMD, "Only one port allowed\n");
1016 bp->geneve_port_cnt++;
1020 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
1021 bp->geneve_port_cnt++;
1024 RTE_LOG(ERR, PMD, "Tunnel type is not supported\n");
1027 rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
1033 bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
1034 struct rte_eth_udp_tunnel *udp_tunnel)
1036 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
1037 uint16_t tunnel_type = 0;
1041 switch (udp_tunnel->prot_type) {
1042 case RTE_TUNNEL_TYPE_VXLAN:
1043 if (!bp->vxlan_port_cnt) {
1044 RTE_LOG(ERR, PMD, "No Tunnel port configured yet\n");
1047 if (bp->vxlan_port != udp_tunnel->udp_port) {
1048 RTE_LOG(ERR, PMD, "Req Port: %d. Configured port: %d\n",
1049 udp_tunnel->udp_port, bp->vxlan_port);
1052 if (--bp->vxlan_port_cnt)
1056 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
1057 port = bp->vxlan_fw_dst_port_id;
1059 case RTE_TUNNEL_TYPE_GENEVE:
1060 if (!bp->geneve_port_cnt) {
1061 RTE_LOG(ERR, PMD, "No Tunnel port configured yet\n");
1064 if (bp->geneve_port != udp_tunnel->udp_port) {
1065 RTE_LOG(ERR, PMD, "Req Port: %d. Configured port: %d\n",
1066 udp_tunnel->udp_port, bp->geneve_port);
1069 if (--bp->geneve_port_cnt)
1073 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
1074 port = bp->geneve_fw_dst_port_id;
1077 RTE_LOG(ERR, PMD, "Tunnel type is not supported\n");
1081 rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
1084 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN)
1087 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE)
1088 bp->geneve_port = 0;
1097 static const struct eth_dev_ops bnxt_dev_ops = {
1098 .dev_infos_get = bnxt_dev_info_get_op,
1099 .dev_close = bnxt_dev_close_op,
1100 .dev_configure = bnxt_dev_configure_op,
1101 .dev_start = bnxt_dev_start_op,
1102 .dev_stop = bnxt_dev_stop_op,
1103 .dev_set_link_up = bnxt_dev_set_link_up_op,
1104 .dev_set_link_down = bnxt_dev_set_link_down_op,
1105 .stats_get = bnxt_stats_get_op,
1106 .stats_reset = bnxt_stats_reset_op,
1107 .rx_queue_setup = bnxt_rx_queue_setup_op,
1108 .rx_queue_release = bnxt_rx_queue_release_op,
1109 .tx_queue_setup = bnxt_tx_queue_setup_op,
1110 .tx_queue_release = bnxt_tx_queue_release_op,
1111 .reta_update = bnxt_reta_update_op,
1112 .reta_query = bnxt_reta_query_op,
1113 .rss_hash_update = bnxt_rss_hash_update_op,
1114 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
1115 .link_update = bnxt_link_update_op,
1116 .promiscuous_enable = bnxt_promiscuous_enable_op,
1117 .promiscuous_disable = bnxt_promiscuous_disable_op,
1118 .allmulticast_enable = bnxt_allmulticast_enable_op,
1119 .allmulticast_disable = bnxt_allmulticast_disable_op,
1120 .mac_addr_add = bnxt_mac_addr_add_op,
1121 .mac_addr_remove = bnxt_mac_addr_remove_op,
1122 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
1123 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
1124 .udp_tunnel_port_add = bnxt_udp_tunnel_port_add_op,
1125 .udp_tunnel_port_del = bnxt_udp_tunnel_port_del_op,
1128 static bool bnxt_vf_pciid(uint16_t id)
1130 if (id == BROADCOM_DEV_ID_57304_VF ||
1131 id == BROADCOM_DEV_ID_57406_VF ||
1132 id == BROADCOM_DEV_ID_5731X_VF ||
1133 id == BROADCOM_DEV_ID_5741X_VF ||
1134 id == BROADCOM_DEV_ID_57414_VF)
1139 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
1141 struct bnxt *bp = eth_dev->data->dev_private;
1142 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1145 /* enable device (incl. PCI PM wakeup), and bus-mastering */
1146 if (!pci_dev->mem_resource[0].addr) {
1148 "Cannot find PCI device base address, aborting\n");
1150 goto init_err_disable;
1153 bp->eth_dev = eth_dev;
1156 bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
1158 RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
1160 goto init_err_release;
1173 static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
1175 #define ALLOW_FUNC(x) \
1177 typeof(x) arg = (x); \
1178 bp->pf.vf_req_fwd[((arg) >> 5)] &= \
1179 ~rte_cpu_to_le_32(1 << ((arg) & 0x1f)); \
1182 bnxt_dev_init(struct rte_eth_dev *eth_dev)
1184 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1185 static int version_printed;
1189 if (version_printed++ == 0)
1190 RTE_LOG(INFO, PMD, "%s\n", bnxt_version);
1192 rte_eth_copy_pci_info(eth_dev, pci_dev);
1193 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1195 bp = eth_dev->data->dev_private;
1196 bp->dev_stopped = 1;
1198 if (bnxt_vf_pciid(pci_dev->id.device_id))
1199 bp->flags |= BNXT_FLAG_VF;
1201 rc = bnxt_init_board(eth_dev);
1204 "Board initialization failed rc: %x\n", rc);
1207 eth_dev->dev_ops = &bnxt_dev_ops;
1208 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
1209 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
1211 rc = bnxt_alloc_hwrm_resources(bp);
1214 "hwrm resource allocation failure rc: %x\n", rc);
1217 rc = bnxt_hwrm_ver_get(bp);
1220 bnxt_hwrm_queue_qportcfg(bp);
1222 bnxt_hwrm_func_qcfg(bp);
1224 /* Get the MAX capabilities for this function */
1225 rc = bnxt_hwrm_func_qcaps(bp);
1227 RTE_LOG(ERR, PMD, "hwrm query capability failure rc: %x\n", rc);
1230 if (bp->max_tx_rings == 0) {
1231 RTE_LOG(ERR, PMD, "No TX rings available!\n");
1235 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
1236 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR, 0);
1237 if (eth_dev->data->mac_addrs == NULL) {
1239 "Failed to alloc %u bytes needed to store MAC addr tbl",
1240 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR);
1244 /* Copy the permanent MAC from the qcap response address now. */
1245 memcpy(bp->mac_addr, bp->dflt_mac_addr, sizeof(bp->mac_addr));
1246 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
1247 bp->grp_info = rte_zmalloc("bnxt_grp_info",
1248 sizeof(*bp->grp_info) * bp->max_ring_grps, 0);
1249 if (!bp->grp_info) {
1251 "Failed to alloc %zu bytes needed to store group info table\n",
1252 sizeof(*bp->grp_info) * bp->max_ring_grps);
1257 /* Forward all requests if firmware is new enough */
1258 if (((bp->fw_ver >= ((20 << 24) | (6 << 16) | (100 << 8))) &&
1259 (bp->fw_ver < ((20 << 24) | (7 << 16)))) ||
1260 ((bp->fw_ver >= ((20 << 24) | (8 << 16))))) {
1261 memset(bp->pf.vf_req_fwd, 0xff, sizeof(bp->pf.vf_req_fwd));
1263 RTE_LOG(WARNING, PMD,
1264 "Firmware too old for VF mailbox functionality\n");
1265 memset(bp->pf.vf_req_fwd, 0, sizeof(bp->pf.vf_req_fwd));
1269 * The following are used for driver cleanup. If we disallow these,
1270 * VF drivers can't clean up cleanly.
1272 ALLOW_FUNC(HWRM_FUNC_DRV_UNRGTR);
1273 ALLOW_FUNC(HWRM_VNIC_FREE);
1274 ALLOW_FUNC(HWRM_RING_FREE);
1275 ALLOW_FUNC(HWRM_RING_GRP_FREE);
1276 ALLOW_FUNC(HWRM_VNIC_RSS_COS_LB_CTX_FREE);
1277 ALLOW_FUNC(HWRM_CFA_L2_FILTER_FREE);
1278 ALLOW_FUNC(HWRM_STAT_CTX_FREE);
1279 rc = bnxt_hwrm_func_driver_register(bp);
1282 "Failed to register driver");
1288 DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
1289 pci_dev->mem_resource[0].phys_addr,
1290 pci_dev->mem_resource[0].addr);
1292 rc = bnxt_hwrm_func_reset(bp);
1294 RTE_LOG(ERR, PMD, "hwrm chip reset failure rc: %x\n", rc);
1300 //if (bp->pf.active_vfs) {
1301 // TODO: Deallocate VF resources?
1303 if (bp->pdev->max_vfs) {
1304 rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
1306 RTE_LOG(ERR, PMD, "Failed to allocate VFs\n");
1310 rc = bnxt_hwrm_allocate_pf_only(bp);
1313 "Failed to allocate PF resources\n");
1319 rc = bnxt_setup_int(bp);
1323 rc = bnxt_alloc_mem(bp);
1325 goto error_free_int;
1327 rc = bnxt_request_int(bp);
1329 goto error_free_int;
1331 rc = bnxt_alloc_def_cp_ring(bp);
1333 goto error_free_int;
1335 bnxt_enable_int(bp);
1340 bnxt_disable_int(bp);
1341 bnxt_free_def_cp_ring(bp);
1342 bnxt_hwrm_func_buf_unrgtr(bp);
1346 bnxt_dev_uninit(eth_dev);
1352 bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
1353 struct bnxt *bp = eth_dev->data->dev_private;
1356 bnxt_disable_int(bp);
1359 if (eth_dev->data->mac_addrs != NULL) {
1360 rte_free(eth_dev->data->mac_addrs);
1361 eth_dev->data->mac_addrs = NULL;
1363 if (bp->grp_info != NULL) {
1364 rte_free(bp->grp_info);
1365 bp->grp_info = NULL;
1367 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
1368 bnxt_free_hwrm_resources(bp);
1369 if (bp->dev_stopped == 0)
1370 bnxt_dev_close_op(eth_dev);
1372 rte_free(bp->pf.vf_info);
1373 eth_dev->dev_ops = NULL;
1374 eth_dev->rx_pkt_burst = NULL;
1375 eth_dev->tx_pkt_burst = NULL;
1380 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg)
1382 struct rte_pmd_bnxt_mb_event_param cb_param;
1384 cb_param.retval = RTE_PMD_BNXT_MB_EVENT_PROCEED;
1385 cb_param.vf_id = vf_id;
1388 _rte_eth_dev_callback_process(bp->eth_dev, RTE_ETH_EVENT_VF_MBOX,
1391 /* Default to approve */
1392 if (cb_param.retval == RTE_PMD_BNXT_MB_EVENT_PROCEED)
1393 cb_param.retval = RTE_PMD_BNXT_MB_EVENT_NOOP_ACK;
1395 return cb_param.retval == RTE_PMD_BNXT_MB_EVENT_NOOP_ACK ? true : false;
1398 static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1399 struct rte_pci_device *pci_dev)
1401 return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct bnxt),
1405 static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
1407 return rte_eth_dev_pci_generic_remove(pci_dev, bnxt_dev_uninit);
1410 static struct rte_pci_driver bnxt_rte_pmd = {
1411 .id_table = bnxt_pci_id_map,
1412 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
1413 RTE_PCI_DRV_INTR_LSC,
1414 .probe = bnxt_pci_probe,
1415 .remove = bnxt_pci_remove,
1418 RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
1419 RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
1420 RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");