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_malloc.h>
40 #include <rte_cycles.h>
44 #include "bnxt_filter.h"
45 #include "bnxt_hwrm.h"
47 #include "bnxt_ring.h"
50 #include "bnxt_stats.h"
53 #include "bnxt_vnic.h"
54 #include "hsi_struct_def_dpdk.h"
56 #define DRV_MODULE_NAME "bnxt"
57 static const char bnxt_version[] =
58 "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
60 #define PCI_VENDOR_ID_BROADCOM 0x14E4
62 #define BROADCOM_DEV_ID_57301 0x16c8
63 #define BROADCOM_DEV_ID_57302 0x16c9
64 #define BROADCOM_DEV_ID_57304_PF 0x16ca
65 #define BROADCOM_DEV_ID_57304_VF 0x16cb
66 #define BROADCOM_DEV_ID_57417_MF 0x16cc
67 #define BROADCOM_DEV_ID_NS2 0x16cd
68 #define BROADCOM_DEV_ID_57311 0x16ce
69 #define BROADCOM_DEV_ID_57312 0x16cf
70 #define BROADCOM_DEV_ID_57402 0x16d0
71 #define BROADCOM_DEV_ID_57404 0x16d1
72 #define BROADCOM_DEV_ID_57406_PF 0x16d2
73 #define BROADCOM_DEV_ID_57406_VF 0x16d3
74 #define BROADCOM_DEV_ID_57402_MF 0x16d4
75 #define BROADCOM_DEV_ID_57407_RJ45 0x16d5
76 #define BROADCOM_DEV_ID_57412 0x16d6
77 #define BROADCOM_DEV_ID_57414 0x16d7
78 #define BROADCOM_DEV_ID_57416_RJ45 0x16d8
79 #define BROADCOM_DEV_ID_57417_RJ45 0x16d9
80 #define BROADCOM_DEV_ID_5741X_VF 0x16dc
81 #define BROADCOM_DEV_ID_57412_MF 0x16de
82 #define BROADCOM_DEV_ID_57314 0x16df
83 #define BROADCOM_DEV_ID_57317_RJ45 0x16e0
84 #define BROADCOM_DEV_ID_5731X_VF 0x16e1
85 #define BROADCOM_DEV_ID_57417_SFP 0x16e2
86 #define BROADCOM_DEV_ID_57416_SFP 0x16e3
87 #define BROADCOM_DEV_ID_57317_SFP 0x16e4
88 #define BROADCOM_DEV_ID_57404_MF 0x16e7
89 #define BROADCOM_DEV_ID_57406_MF 0x16e8
90 #define BROADCOM_DEV_ID_57407_SFP 0x16e9
91 #define BROADCOM_DEV_ID_57407_MF 0x16ea
92 #define BROADCOM_DEV_ID_57414_MF 0x16ec
93 #define BROADCOM_DEV_ID_57416_MF 0x16ee
95 static struct rte_pci_id bnxt_pci_id_map[] = {
96 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
97 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
98 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
99 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
100 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
101 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
102 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
103 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
104 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
105 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
106 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
107 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
108 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
109 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
110 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
111 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
112 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
113 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
114 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
115 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
116 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
117 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
118 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
119 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
120 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
121 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
122 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
123 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
124 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
125 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
126 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
127 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
128 { .vendor_id = 0, /* sentinel */ },
131 #define BNXT_ETH_RSS_SUPPORT ( \
133 ETH_RSS_NONFRAG_IPV4_TCP | \
134 ETH_RSS_NONFRAG_IPV4_UDP | \
136 ETH_RSS_NONFRAG_IPV6_TCP | \
137 ETH_RSS_NONFRAG_IPV6_UDP)
139 /***********************/
142 * High level utility functions
145 static void bnxt_free_mem(struct bnxt *bp)
147 bnxt_free_filter_mem(bp);
148 bnxt_free_vnic_attributes(bp);
149 bnxt_free_vnic_mem(bp);
152 bnxt_free_tx_rings(bp);
153 bnxt_free_rx_rings(bp);
154 bnxt_free_def_cp_ring(bp);
157 static int bnxt_alloc_mem(struct bnxt *bp)
161 /* Default completion ring */
162 rc = bnxt_init_def_ring_struct(bp, SOCKET_ID_ANY);
166 rc = bnxt_alloc_rings(bp, 0, NULL, NULL,
167 bp->def_cp_ring, "def_cp");
171 rc = bnxt_alloc_vnic_mem(bp);
175 rc = bnxt_alloc_vnic_attributes(bp);
179 rc = bnxt_alloc_filter_mem(bp);
190 static int bnxt_init_chip(struct bnxt *bp)
192 unsigned int i, rss_idx, fw_idx;
193 struct rte_eth_link new;
196 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
198 RTE_LOG(ERR, PMD, "HWRM stat ctx alloc failure rc: %x\n", rc);
202 rc = bnxt_alloc_hwrm_rings(bp);
204 RTE_LOG(ERR, PMD, "HWRM ring alloc failure rc: %x\n", rc);
208 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
210 RTE_LOG(ERR, PMD, "HWRM ring grp alloc failure: %x\n", rc);
214 rc = bnxt_mq_rx_configure(bp);
216 RTE_LOG(ERR, PMD, "MQ mode configure failure rc: %x\n", rc);
220 /* VNIC configuration */
221 for (i = 0; i < bp->nr_vnics; i++) {
222 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
224 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
226 RTE_LOG(ERR, PMD, "HWRM vnic alloc failure rc: %x\n",
231 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic);
234 "HWRM vnic ctx alloc failure rc: %x\n", rc);
238 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
240 RTE_LOG(ERR, PMD, "HWRM vnic cfg failure rc: %x\n", rc);
244 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
246 RTE_LOG(ERR, PMD, "HWRM vnic filter failure rc: %x\n",
250 if (vnic->rss_table && vnic->hash_type) {
252 * Fill the RSS hash & redirection table with
253 * ring group ids for all VNICs
255 for (rss_idx = 0, fw_idx = 0;
256 rss_idx < HW_HASH_INDEX_SIZE;
257 rss_idx++, fw_idx++) {
258 if (vnic->fw_grp_ids[fw_idx] ==
261 vnic->rss_table[rss_idx] =
262 vnic->fw_grp_ids[fw_idx];
264 rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
267 "HWRM vnic set RSS failure rc: %x\n",
273 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0]);
276 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
280 rc = bnxt_get_hwrm_link_config(bp, &new);
282 RTE_LOG(ERR, PMD, "HWRM Get link config failure rc: %x\n", rc);
286 if (!bp->link_info.link_up) {
287 rc = bnxt_set_hwrm_link_config(bp, true);
290 "HWRM link config failure rc: %x\n", rc);
298 bnxt_free_all_hwrm_resources(bp);
303 static int bnxt_shutdown_nic(struct bnxt *bp)
305 bnxt_free_all_hwrm_resources(bp);
306 bnxt_free_all_filters(bp);
307 bnxt_free_all_vnics(bp);
311 static int bnxt_init_nic(struct bnxt *bp)
315 bnxt_init_ring_grps(bp);
317 bnxt_init_filters(bp);
319 rc = bnxt_init_chip(bp);
327 * Device configuration and status function
330 static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
331 struct rte_eth_dev_info *dev_info)
333 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
334 uint16_t max_vnics, i, j, vpool, vrxq;
337 dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
338 dev_info->max_hash_mac_addrs = 0;
340 /* PF/VF specifics */
342 dev_info->max_rx_queues = bp->pf.max_rx_rings;
343 dev_info->max_tx_queues = bp->pf.max_tx_rings;
344 dev_info->max_vfs = bp->pf.active_vfs;
345 dev_info->reta_size = bp->pf.max_rsscos_ctx;
346 max_vnics = bp->pf.max_vnics;
348 dev_info->max_rx_queues = bp->vf.max_rx_rings;
349 dev_info->max_tx_queues = bp->vf.max_tx_rings;
350 dev_info->reta_size = bp->vf.max_rsscos_ctx;
351 max_vnics = bp->vf.max_vnics;
354 /* Fast path specifics */
355 dev_info->min_rx_bufsize = 1;
356 dev_info->max_rx_pktlen = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN
358 dev_info->rx_offload_capa = 0;
359 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
360 DEV_TX_OFFLOAD_TCP_CKSUM |
361 DEV_TX_OFFLOAD_UDP_CKSUM |
362 DEV_TX_OFFLOAD_TCP_TSO;
365 dev_info->default_rxconf = (struct rte_eth_rxconf) {
371 .rx_free_thresh = 32,
375 dev_info->default_txconf = (struct rte_eth_txconf) {
381 .tx_free_thresh = 32,
383 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
384 ETH_TXQ_FLAGS_NOOFFLOADS,
386 eth_dev->data->dev_conf.intr_conf.lsc = 1;
391 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
392 * need further investigation.
396 vpool = 64; /* ETH_64_POOLS */
397 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
398 for (i = 0; i < 4; vpool >>= 1, i++) {
399 if (max_vnics > vpool) {
400 for (j = 0; j < 5; vrxq >>= 1, j++) {
401 if (dev_info->max_rx_queues > vrxq) {
407 /* Not enough resources to support VMDq */
411 /* Not enough resources to support VMDq */
415 dev_info->max_vmdq_pools = vpool;
416 dev_info->vmdq_queue_num = vrxq;
418 dev_info->vmdq_pool_base = 0;
419 dev_info->vmdq_queue_base = 0;
422 /* Configure the device based on the configuration provided */
423 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
425 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
427 bp->rx_queues = (void *)eth_dev->data->rx_queues;
428 bp->tx_queues = (void *)eth_dev->data->tx_queues;
430 /* Inherit new configurations */
431 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
432 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
433 bp->rx_cp_nr_rings = bp->rx_nr_rings;
434 bp->tx_cp_nr_rings = bp->tx_nr_rings;
436 if (eth_dev->data->dev_conf.rxmode.jumbo_frame)
438 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
439 ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE;
444 rte_bnxt_atomic_write_link_status(struct rte_eth_dev *eth_dev,
445 struct rte_eth_link *link)
447 struct rte_eth_link *dst = ð_dev->data->dev_link;
448 struct rte_eth_link *src = link;
450 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
451 *(uint64_t *)src) == 0)
457 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
459 struct rte_eth_link *link = ð_dev->data->dev_link;
461 if (link->link_status)
462 RTE_LOG(INFO, PMD, "Port %d Link Up - speed %u Mbps - %s\n",
463 (uint8_t)(eth_dev->data->port_id),
464 (uint32_t)link->link_speed,
465 (link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
466 ("full-duplex") : ("half-duplex\n"));
468 RTE_LOG(INFO, PMD, "Port %d Link Down\n",
469 (uint8_t)(eth_dev->data->port_id));
472 static int bnxt_dev_lsc_intr_setup(struct rte_eth_dev *eth_dev)
474 bnxt_print_link_info(eth_dev);
478 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
480 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
484 rc = bnxt_hwrm_func_reset(bp);
486 RTE_LOG(ERR, PMD, "hwrm chip reset failure rc: %x\n", rc);
491 rc = bnxt_setup_int(bp);
495 rc = bnxt_alloc_mem(bp);
499 rc = bnxt_request_int(bp);
503 rc = bnxt_init_nic(bp);
509 bnxt_link_update_op(eth_dev, 0);
513 bnxt_shutdown_nic(bp);
514 bnxt_disable_int(bp);
516 bnxt_free_tx_mbufs(bp);
517 bnxt_free_rx_mbufs(bp);
522 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
524 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
526 eth_dev->data->dev_link.link_status = 1;
527 bnxt_set_hwrm_link_config(bp, true);
531 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
533 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
535 eth_dev->data->dev_link.link_status = 0;
536 bnxt_set_hwrm_link_config(bp, false);
540 /* Unload the driver, release resources */
541 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
543 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
545 if (bp->eth_dev->data->dev_started) {
546 /* TBD: STOP HW queues DMA */
547 eth_dev->data->dev_link.link_status = 0;
549 bnxt_set_hwrm_link_config(bp, false);
550 bnxt_disable_int(bp);
552 bnxt_shutdown_nic(bp);
556 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
558 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
560 if (bp->dev_stopped == 0)
561 bnxt_dev_stop_op(eth_dev);
563 bnxt_free_tx_mbufs(bp);
564 bnxt_free_rx_mbufs(bp);
566 if (eth_dev->data->mac_addrs != NULL) {
567 rte_free(eth_dev->data->mac_addrs);
568 eth_dev->data->mac_addrs = NULL;
570 if (bp->grp_info != NULL) {
571 rte_free(bp->grp_info);
576 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
579 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
580 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
581 struct bnxt_vnic_info *vnic;
582 struct bnxt_filter_info *filter, *temp_filter;
586 * Loop through all VNICs from the specified filter flow pools to
587 * remove the corresponding MAC addr filter
589 for (i = 0; i < MAX_FF_POOLS; i++) {
590 if (!(pool_mask & (1ULL << i)))
593 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
594 filter = STAILQ_FIRST(&vnic->filter);
596 temp_filter = STAILQ_NEXT(filter, next);
597 if (filter->mac_index == index) {
598 STAILQ_REMOVE(&vnic->filter, filter,
599 bnxt_filter_info, next);
600 bnxt_hwrm_clear_filter(bp, filter);
601 filter->mac_index = INVALID_MAC_INDEX;
602 memset(&filter->l2_addr, 0,
605 &bp->free_filter_list,
608 filter = temp_filter;
614 static void bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
615 struct ether_addr *mac_addr,
616 uint32_t index, uint32_t pool)
618 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
619 struct bnxt_vnic_info *vnic = STAILQ_FIRST(&bp->ff_pool[pool]);
620 struct bnxt_filter_info *filter;
623 RTE_LOG(ERR, PMD, "Cannot add MAC address to a VF interface\n");
628 RTE_LOG(ERR, PMD, "VNIC not found for pool %d!\n", pool);
631 /* Attach requested MAC address to the new l2_filter */
632 STAILQ_FOREACH(filter, &vnic->filter, next) {
633 if (filter->mac_index == index) {
635 "MAC addr already existed for pool %d\n", pool);
639 filter = bnxt_alloc_filter(bp);
641 RTE_LOG(ERR, PMD, "L2 filter alloc failed\n");
644 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
645 filter->mac_index = index;
646 memcpy(filter->l2_addr, mac_addr, ETHER_ADDR_LEN);
647 bnxt_hwrm_set_filter(bp, vnic, filter);
650 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
653 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
654 struct rte_eth_link new;
655 unsigned int cnt = BNXT_LINK_WAIT_CNT;
657 memset(&new, 0, sizeof(new));
659 /* Retrieve link info from hardware */
660 rc = bnxt_get_hwrm_link_config(bp, &new);
662 new.link_speed = ETH_LINK_SPEED_100M;
663 new.link_duplex = ETH_LINK_FULL_DUPLEX;
665 "Failed to retrieve link rc = 0x%x!", rc);
668 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
670 if (!wait_to_complete)
672 } while (!new.link_status && cnt--);
675 /* Timed out or success */
676 if (new.link_status != eth_dev->data->dev_link.link_status ||
677 new.link_speed != eth_dev->data->dev_link.link_speed) {
678 rte_bnxt_atomic_write_link_status(eth_dev, &new);
679 bnxt_print_link_info(eth_dev);
685 static void bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
687 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
688 struct bnxt_vnic_info *vnic;
690 if (bp->vnic_info == NULL)
693 vnic = &bp->vnic_info[0];
695 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
696 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
699 static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
701 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
702 struct bnxt_vnic_info *vnic;
704 if (bp->vnic_info == NULL)
707 vnic = &bp->vnic_info[0];
709 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
710 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
713 static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
715 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
716 struct bnxt_vnic_info *vnic;
718 if (bp->vnic_info == NULL)
721 vnic = &bp->vnic_info[0];
723 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
724 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
727 static void bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
729 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
730 struct bnxt_vnic_info *vnic;
732 if (bp->vnic_info == NULL)
735 vnic = &bp->vnic_info[0];
737 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
738 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
741 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
742 struct rte_eth_rss_reta_entry64 *reta_conf,
745 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
746 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
747 struct bnxt_vnic_info *vnic;
750 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
753 if (reta_size != HW_HASH_INDEX_SIZE) {
754 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
755 "(%d) must equal the size supported by the hardware "
756 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
759 /* Update the RSS VNIC(s) */
760 for (i = 0; i < MAX_FF_POOLS; i++) {
761 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
762 memcpy(vnic->rss_table, reta_conf, reta_size);
764 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
770 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
771 struct rte_eth_rss_reta_entry64 *reta_conf,
774 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
775 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
777 /* Retrieve from the default VNIC */
780 if (!vnic->rss_table)
783 if (reta_size != HW_HASH_INDEX_SIZE) {
784 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
785 "(%d) must equal the size supported by the hardware "
786 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
789 /* EW - need to revisit here copying from u64 to u16 */
790 memcpy(reta_conf, vnic->rss_table, reta_size);
792 if (rte_intr_allow_others(ð_dev->pci_dev->intr_handle)) {
793 if (eth_dev->data->dev_conf.intr_conf.lsc != 0)
794 bnxt_dev_lsc_intr_setup(eth_dev);
800 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
801 struct rte_eth_rss_conf *rss_conf)
803 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
804 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
805 struct bnxt_vnic_info *vnic;
806 uint16_t hash_type = 0;
810 * If RSS enablement were different than dev_configure,
811 * then return -EINVAL
813 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
814 if (!rss_conf->rss_hf)
817 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
820 if (rss_conf->rss_hf & ETH_RSS_IPV4)
821 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
822 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
823 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
824 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
825 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
826 if (rss_conf->rss_hf & ETH_RSS_IPV6)
827 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
828 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
829 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
830 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
831 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
833 /* Update the RSS VNIC(s) */
834 for (i = 0; i < MAX_FF_POOLS; i++) {
835 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
836 vnic->hash_type = hash_type;
839 * Use the supplied key if the key length is
840 * acceptable and the rss_key is not NULL
842 if (rss_conf->rss_key &&
843 rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
844 memcpy(vnic->rss_hash_key, rss_conf->rss_key,
845 rss_conf->rss_key_len);
847 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
853 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
854 struct rte_eth_rss_conf *rss_conf)
856 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
857 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
861 /* RSS configuration is the same for all VNICs */
862 if (vnic && vnic->rss_hash_key) {
863 if (rss_conf->rss_key) {
864 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
865 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
866 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
869 hash_types = vnic->hash_type;
870 rss_conf->rss_hf = 0;
871 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
872 rss_conf->rss_hf |= ETH_RSS_IPV4;
873 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
875 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
876 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
878 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
880 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
881 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
883 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
885 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
886 rss_conf->rss_hf |= ETH_RSS_IPV6;
887 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
889 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
890 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
892 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
894 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
895 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
897 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
901 "Unknwon RSS config from firmware (%08x), RSS disabled",
906 rss_conf->rss_hf = 0;
911 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
912 struct rte_eth_fc_conf *fc_conf __rte_unused)
914 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
915 struct rte_eth_link link_info;
918 rc = bnxt_get_hwrm_link_config(bp, &link_info);
922 memset(fc_conf, 0, sizeof(*fc_conf));
923 if (bp->link_info.auto_pause)
924 fc_conf->autoneg = 1;
925 switch (bp->link_info.pause) {
927 fc_conf->mode = RTE_FC_NONE;
929 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
930 fc_conf->mode = RTE_FC_TX_PAUSE;
932 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
933 fc_conf->mode = RTE_FC_RX_PAUSE;
935 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
936 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
937 fc_conf->mode = RTE_FC_FULL;
943 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
944 struct rte_eth_fc_conf *fc_conf)
946 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
948 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp)) {
949 RTE_LOG(ERR, PMD, "Flow Control Settings cannot be modified\n");
953 switch (fc_conf->mode) {
955 bp->link_info.auto_pause = 0;
956 bp->link_info.force_pause = 0;
958 case RTE_FC_RX_PAUSE:
959 if (fc_conf->autoneg) {
960 bp->link_info.auto_pause =
961 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
962 bp->link_info.force_pause = 0;
964 bp->link_info.auto_pause = 0;
965 bp->link_info.force_pause =
966 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
969 case RTE_FC_TX_PAUSE:
970 if (fc_conf->autoneg) {
971 bp->link_info.auto_pause =
972 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
973 bp->link_info.force_pause = 0;
975 bp->link_info.auto_pause = 0;
976 bp->link_info.force_pause =
977 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
981 if (fc_conf->autoneg) {
982 bp->link_info.auto_pause =
983 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
984 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
985 bp->link_info.force_pause = 0;
987 bp->link_info.auto_pause = 0;
988 bp->link_info.force_pause =
989 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
990 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
994 return bnxt_set_hwrm_link_config(bp, true);
1001 static struct eth_dev_ops bnxt_dev_ops = {
1002 .dev_infos_get = bnxt_dev_info_get_op,
1003 .dev_close = bnxt_dev_close_op,
1004 .dev_configure = bnxt_dev_configure_op,
1005 .dev_start = bnxt_dev_start_op,
1006 .dev_stop = bnxt_dev_stop_op,
1007 .dev_set_link_up = bnxt_dev_set_link_up_op,
1008 .dev_set_link_down = bnxt_dev_set_link_down_op,
1009 .stats_get = bnxt_stats_get_op,
1010 .stats_reset = bnxt_stats_reset_op,
1011 .rx_queue_setup = bnxt_rx_queue_setup_op,
1012 .rx_queue_release = bnxt_rx_queue_release_op,
1013 .tx_queue_setup = bnxt_tx_queue_setup_op,
1014 .tx_queue_release = bnxt_tx_queue_release_op,
1015 .reta_update = bnxt_reta_update_op,
1016 .reta_query = bnxt_reta_query_op,
1017 .rss_hash_update = bnxt_rss_hash_update_op,
1018 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
1019 .link_update = bnxt_link_update_op,
1020 .promiscuous_enable = bnxt_promiscuous_enable_op,
1021 .promiscuous_disable = bnxt_promiscuous_disable_op,
1022 .allmulticast_enable = bnxt_allmulticast_enable_op,
1023 .allmulticast_disable = bnxt_allmulticast_disable_op,
1024 .mac_addr_add = bnxt_mac_addr_add_op,
1025 .mac_addr_remove = bnxt_mac_addr_remove_op,
1026 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
1027 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
1030 static bool bnxt_vf_pciid(uint16_t id)
1032 if (id == BROADCOM_DEV_ID_57304_VF ||
1033 id == BROADCOM_DEV_ID_57406_VF ||
1034 id == BROADCOM_DEV_ID_5731X_VF ||
1035 id == BROADCOM_DEV_ID_5741X_VF)
1040 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
1043 struct bnxt *bp = eth_dev->data->dev_private;
1045 /* enable device (incl. PCI PM wakeup), and bus-mastering */
1046 if (!eth_dev->pci_dev->mem_resource[0].addr) {
1048 "Cannot find PCI device base address, aborting\n");
1050 goto init_err_disable;
1053 bp->eth_dev = eth_dev;
1054 bp->pdev = eth_dev->pci_dev;
1056 bp->bar0 = (void *)eth_dev->pci_dev->mem_resource[0].addr;
1058 RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
1060 goto init_err_release;
1074 bnxt_dev_init(struct rte_eth_dev *eth_dev)
1076 static int version_printed;
1080 if (version_printed++ == 0)
1081 RTE_LOG(INFO, PMD, "%s", bnxt_version);
1083 rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
1084 bp = eth_dev->data->dev_private;
1086 if (bnxt_vf_pciid(eth_dev->pci_dev->id.device_id))
1087 bp->flags |= BNXT_FLAG_VF;
1089 rc = bnxt_init_board(eth_dev);
1092 "Board initialization failed rc: %x\n", rc);
1095 eth_dev->dev_ops = &bnxt_dev_ops;
1096 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
1097 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
1099 rc = bnxt_alloc_hwrm_resources(bp);
1102 "hwrm resource allocation failure rc: %x\n", rc);
1105 rc = bnxt_hwrm_ver_get(bp);
1108 bnxt_hwrm_queue_qportcfg(bp);
1110 bnxt_hwrm_func_qcfg(bp);
1112 /* Get the MAX capabilities for this function */
1113 rc = bnxt_hwrm_func_qcaps(bp);
1115 RTE_LOG(ERR, PMD, "hwrm query capability failure rc: %x\n", rc);
1118 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
1119 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR, 0);
1120 if (eth_dev->data->mac_addrs == NULL) {
1122 "Failed to alloc %u bytes needed to store MAC addr tbl",
1123 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR);
1127 /* Copy the permanent MAC from the qcap response address now. */
1129 memcpy(bp->mac_addr, bp->pf.mac_addr, sizeof(bp->mac_addr));
1131 memcpy(bp->mac_addr, bp->vf.mac_addr, sizeof(bp->mac_addr));
1132 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
1133 bp->grp_info = rte_zmalloc("bnxt_grp_info",
1134 sizeof(*bp->grp_info) * bp->max_ring_grps, 0);
1135 if (!bp->grp_info) {
1137 "Failed to alloc %zu bytes needed to store group info table\n",
1138 sizeof(*bp->grp_info) * bp->max_ring_grps);
1143 rc = bnxt_hwrm_func_driver_register(bp, 0,
1147 "Failed to register driver");
1153 DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
1154 eth_dev->pci_dev->mem_resource[0].phys_addr,
1155 eth_dev->pci_dev->mem_resource[0].addr);
1157 bp->dev_stopped = 0;
1162 eth_dev->driver->eth_dev_uninit(eth_dev);
1168 bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
1169 struct bnxt *bp = eth_dev->data->dev_private;
1172 if (eth_dev->data->mac_addrs != NULL) {
1173 rte_free(eth_dev->data->mac_addrs);
1174 eth_dev->data->mac_addrs = NULL;
1176 if (bp->grp_info != NULL) {
1177 rte_free(bp->grp_info);
1178 bp->grp_info = NULL;
1180 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
1181 bnxt_free_hwrm_resources(bp);
1182 if (bp->dev_stopped == 0)
1183 bnxt_dev_close_op(eth_dev);
1184 eth_dev->dev_ops = NULL;
1185 eth_dev->rx_pkt_burst = NULL;
1186 eth_dev->tx_pkt_burst = NULL;
1191 static struct eth_driver bnxt_rte_pmd = {
1193 .id_table = bnxt_pci_id_map,
1194 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
1195 RTE_PCI_DRV_DETACHABLE | RTE_PCI_DRV_INTR_LSC,
1196 .probe = rte_eth_dev_pci_probe,
1197 .remove = rte_eth_dev_pci_remove
1199 .eth_dev_init = bnxt_dev_init,
1200 .eth_dev_uninit = bnxt_dev_uninit,
1201 .dev_private_size = sizeof(struct bnxt),
1204 DRIVER_REGISTER_PCI(net_bnxt, bnxt_rte_pmd.pci_drv);
1205 DRIVER_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);