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"
46 #include "bnxt_ring.h"
49 #include "bnxt_stats.h"
52 #include "bnxt_vnic.h"
53 #include "hsi_struct_def_dpdk.h"
55 #define DRV_MODULE_NAME "bnxt"
56 static const char bnxt_version[] =
57 "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
59 #define PCI_VENDOR_ID_BROADCOM 0x14E4
61 #define BROADCOM_DEV_ID_57301 0x16c8
62 #define BROADCOM_DEV_ID_57302 0x16c9
63 #define BROADCOM_DEV_ID_57304_PF 0x16ca
64 #define BROADCOM_DEV_ID_57304_VF 0x16cb
65 #define BROADCOM_DEV_ID_57417_MF 0x16cc
66 #define BROADCOM_DEV_ID_NS2 0x16cd
67 #define BROADCOM_DEV_ID_57311 0x16ce
68 #define BROADCOM_DEV_ID_57312 0x16cf
69 #define BROADCOM_DEV_ID_57402 0x16d0
70 #define BROADCOM_DEV_ID_57404 0x16d1
71 #define BROADCOM_DEV_ID_57406_PF 0x16d2
72 #define BROADCOM_DEV_ID_57406_VF 0x16d3
73 #define BROADCOM_DEV_ID_57402_MF 0x16d4
74 #define BROADCOM_DEV_ID_57407_RJ45 0x16d5
75 #define BROADCOM_DEV_ID_57412 0x16d6
76 #define BROADCOM_DEV_ID_57414 0x16d7
77 #define BROADCOM_DEV_ID_57416_RJ45 0x16d8
78 #define BROADCOM_DEV_ID_57417_RJ45 0x16d9
79 #define BROADCOM_DEV_ID_5741X_VF 0x16dc
80 #define BROADCOM_DEV_ID_57412_MF 0x16de
81 #define BROADCOM_DEV_ID_57314 0x16df
82 #define BROADCOM_DEV_ID_57317_RJ45 0x16e0
83 #define BROADCOM_DEV_ID_5731X_VF 0x16e1
84 #define BROADCOM_DEV_ID_57417_SFP 0x16e2
85 #define BROADCOM_DEV_ID_57416_SFP 0x16e3
86 #define BROADCOM_DEV_ID_57317_SFP 0x16e4
87 #define BROADCOM_DEV_ID_57404_MF 0x16e7
88 #define BROADCOM_DEV_ID_57406_MF 0x16e8
89 #define BROADCOM_DEV_ID_57407_SFP 0x16e9
90 #define BROADCOM_DEV_ID_57407_MF 0x16ea
91 #define BROADCOM_DEV_ID_57414_MF 0x16ec
92 #define BROADCOM_DEV_ID_57416_MF 0x16ee
94 static struct rte_pci_id bnxt_pci_id_map[] = {
95 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
96 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
97 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
98 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
99 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
100 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
101 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
102 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
103 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
104 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
105 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
106 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
107 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
108 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
109 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
110 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
111 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
112 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
113 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
114 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
115 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
116 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
117 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
118 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
119 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
120 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
121 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
122 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
123 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
124 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
125 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
126 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
127 { .vendor_id = 0, /* sentinel */ },
130 #define BNXT_ETH_RSS_SUPPORT ( \
132 ETH_RSS_NONFRAG_IPV4_TCP | \
133 ETH_RSS_NONFRAG_IPV4_UDP | \
135 ETH_RSS_NONFRAG_IPV6_TCP | \
136 ETH_RSS_NONFRAG_IPV6_UDP)
138 /***********************/
141 * High level utility functions
144 static void bnxt_free_mem(struct bnxt *bp)
146 bnxt_free_filter_mem(bp);
147 bnxt_free_vnic_attributes(bp);
148 bnxt_free_vnic_mem(bp);
151 bnxt_free_tx_rings(bp);
152 bnxt_free_rx_rings(bp);
153 bnxt_free_def_cp_ring(bp);
156 static int bnxt_alloc_mem(struct bnxt *bp)
160 /* Default completion ring */
161 rc = bnxt_init_def_ring_struct(bp, SOCKET_ID_ANY);
165 rc = bnxt_alloc_rings(bp, 0, NULL, NULL,
166 bp->def_cp_ring, "def_cp");
170 rc = bnxt_alloc_vnic_mem(bp);
174 rc = bnxt_alloc_vnic_attributes(bp);
178 rc = bnxt_alloc_filter_mem(bp);
189 static int bnxt_init_chip(struct bnxt *bp)
191 unsigned int i, rss_idx, fw_idx;
194 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
196 RTE_LOG(ERR, PMD, "HWRM stat ctx alloc failure rc: %x\n", rc);
200 rc = bnxt_alloc_hwrm_rings(bp);
202 RTE_LOG(ERR, PMD, "HWRM ring alloc failure rc: %x\n", rc);
206 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
208 RTE_LOG(ERR, PMD, "HWRM ring grp alloc failure: %x\n", rc);
212 rc = bnxt_mq_rx_configure(bp);
214 RTE_LOG(ERR, PMD, "MQ mode configure failure rc: %x\n", rc);
218 /* VNIC configuration */
219 for (i = 0; i < bp->nr_vnics; i++) {
220 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
222 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
224 RTE_LOG(ERR, PMD, "HWRM vnic alloc failure rc: %x\n",
229 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic);
232 "HWRM vnic ctx alloc failure rc: %x\n", rc);
236 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
238 RTE_LOG(ERR, PMD, "HWRM vnic cfg failure rc: %x\n", rc);
242 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
244 RTE_LOG(ERR, PMD, "HWRM vnic filter failure rc: %x\n",
248 if (vnic->rss_table && vnic->hash_type) {
250 * Fill the RSS hash & redirection table with
251 * ring group ids for all VNICs
253 for (rss_idx = 0, fw_idx = 0;
254 rss_idx < HW_HASH_INDEX_SIZE;
255 rss_idx++, fw_idx++) {
256 if (vnic->fw_grp_ids[fw_idx] ==
259 vnic->rss_table[rss_idx] =
260 vnic->fw_grp_ids[fw_idx];
262 rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
265 "HWRM vnic set RSS failure rc: %x\n",
271 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0]);
274 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
281 bnxt_free_all_hwrm_resources(bp);
286 static int bnxt_shutdown_nic(struct bnxt *bp)
288 bnxt_free_all_hwrm_resources(bp);
289 bnxt_free_all_filters(bp);
290 bnxt_free_all_vnics(bp);
294 static int bnxt_init_nic(struct bnxt *bp)
298 bnxt_init_ring_grps(bp);
300 bnxt_init_filters(bp);
302 rc = bnxt_init_chip(bp);
310 * Device configuration and status function
313 static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
314 struct rte_eth_dev_info *dev_info)
316 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
317 uint16_t max_vnics, i, j, vpool, vrxq;
320 dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
321 dev_info->max_hash_mac_addrs = 0;
323 /* PF/VF specifics */
325 dev_info->max_rx_queues = bp->pf.max_rx_rings;
326 dev_info->max_tx_queues = bp->pf.max_tx_rings;
327 dev_info->max_vfs = bp->pf.active_vfs;
328 dev_info->reta_size = bp->pf.max_rsscos_ctx;
329 max_vnics = bp->pf.max_vnics;
331 dev_info->max_rx_queues = bp->vf.max_rx_rings;
332 dev_info->max_tx_queues = bp->vf.max_tx_rings;
333 dev_info->reta_size = bp->vf.max_rsscos_ctx;
334 max_vnics = bp->vf.max_vnics;
337 /* Fast path specifics */
338 dev_info->min_rx_bufsize = 1;
339 dev_info->max_rx_pktlen = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN
341 dev_info->rx_offload_capa = 0;
342 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
343 DEV_TX_OFFLOAD_TCP_CKSUM |
344 DEV_TX_OFFLOAD_UDP_CKSUM |
345 DEV_TX_OFFLOAD_TCP_TSO;
348 dev_info->default_rxconf = (struct rte_eth_rxconf) {
354 .rx_free_thresh = 32,
358 dev_info->default_txconf = (struct rte_eth_txconf) {
364 .tx_free_thresh = 32,
366 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
367 ETH_TXQ_FLAGS_NOOFFLOADS,
372 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
373 * need further investigation.
377 vpool = 64; /* ETH_64_POOLS */
378 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
379 for (i = 0; i < 4; vpool >>= 1, i++) {
380 if (max_vnics > vpool) {
381 for (j = 0; j < 5; vrxq >>= 1, j++) {
382 if (dev_info->max_rx_queues > vrxq) {
388 /* Not enough resources to support VMDq */
392 /* Not enough resources to support VMDq */
396 dev_info->max_vmdq_pools = vpool;
397 dev_info->vmdq_queue_num = vrxq;
399 dev_info->vmdq_pool_base = 0;
400 dev_info->vmdq_queue_base = 0;
403 /* Configure the device based on the configuration provided */
404 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
406 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
409 bp->rx_queues = (void *)eth_dev->data->rx_queues;
410 bp->tx_queues = (void *)eth_dev->data->tx_queues;
412 /* Inherit new configurations */
413 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
414 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
415 bp->rx_cp_nr_rings = bp->rx_nr_rings;
416 bp->tx_cp_nr_rings = bp->tx_nr_rings;
418 if (eth_dev->data->dev_conf.rxmode.jumbo_frame)
420 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
421 ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE;
422 rc = bnxt_set_hwrm_link_config(bp, true);
426 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
428 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
431 rc = bnxt_hwrm_func_reset(bp);
433 RTE_LOG(ERR, PMD, "hwrm chip reset failure rc: %x\n", rc);
438 rc = bnxt_alloc_mem(bp);
442 rc = bnxt_init_nic(bp);
449 bnxt_shutdown_nic(bp);
450 bnxt_free_tx_mbufs(bp);
451 bnxt_free_rx_mbufs(bp);
456 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
458 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
460 eth_dev->data->dev_link.link_status = 1;
461 bnxt_set_hwrm_link_config(bp, true);
465 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
467 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
469 eth_dev->data->dev_link.link_status = 0;
470 bnxt_set_hwrm_link_config(bp, false);
474 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
476 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
478 bnxt_free_tx_mbufs(bp);
479 bnxt_free_rx_mbufs(bp);
481 rte_free(eth_dev->data->mac_addrs);
484 /* Unload the driver, release resources */
485 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
487 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
489 if (bp->eth_dev->data->dev_started) {
490 /* TBD: STOP HW queues DMA */
491 eth_dev->data->dev_link.link_status = 0;
493 bnxt_shutdown_nic(bp);
496 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
499 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
500 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
501 struct bnxt_vnic_info *vnic;
502 struct bnxt_filter_info *filter, *temp_filter;
506 * Loop through all VNICs from the specified filter flow pools to
507 * remove the corresponding MAC addr filter
509 for (i = 0; i < MAX_FF_POOLS; i++) {
510 if (!(pool_mask & (1 << i)))
513 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
514 filter = STAILQ_FIRST(&vnic->filter);
516 temp_filter = STAILQ_NEXT(filter, next);
517 if (filter->mac_index == index) {
518 STAILQ_REMOVE(&vnic->filter, filter,
519 bnxt_filter_info, next);
520 bnxt_hwrm_clear_filter(bp, filter);
521 filter->mac_index = INVALID_MAC_INDEX;
522 memset(&filter->l2_addr, 0,
525 &bp->free_filter_list,
528 filter = temp_filter;
534 static void bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
535 struct ether_addr *mac_addr,
536 uint32_t index, uint32_t pool)
538 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
539 struct bnxt_vnic_info *vnic = STAILQ_FIRST(&bp->ff_pool[pool]);
540 struct bnxt_filter_info *filter;
543 RTE_LOG(ERR, PMD, "Cannot add MAC address to a VF interface\n");
548 RTE_LOG(ERR, PMD, "VNIC not found for pool %d!\n", pool);
551 /* Attach requested MAC address to the new l2_filter */
552 STAILQ_FOREACH(filter, &vnic->filter, next) {
553 if (filter->mac_index == index) {
555 "MAC addr already existed for pool %d\n", pool);
559 filter = bnxt_alloc_filter(bp);
561 RTE_LOG(ERR, PMD, "L2 filter alloc failed\n");
564 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
565 filter->mac_index = index;
566 memcpy(filter->l2_addr, mac_addr, ETHER_ADDR_LEN);
567 bnxt_hwrm_set_filter(bp, vnic, filter);
570 static int bnxt_link_update_op(struct rte_eth_dev *eth_dev,
571 int wait_to_complete)
574 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
575 struct rte_eth_link new;
576 unsigned int cnt = BNXT_LINK_WAIT_CNT;
578 memset(&new, 0, sizeof(new));
580 /* Retrieve link info from hardware */
581 rc = bnxt_get_hwrm_link_config(bp, &new);
583 new.link_speed = ETH_LINK_SPEED_100M;
584 new.link_duplex = ETH_LINK_FULL_DUPLEX;
586 "Failed to retrieve link rc = 0x%x!", rc);
589 if (!wait_to_complete)
592 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
594 } while (!new.link_status && cnt--);
596 /* Timed out or success */
597 if (new.link_status) {
598 /* Update only if success */
599 eth_dev->data->dev_link.link_duplex = new.link_duplex;
600 eth_dev->data->dev_link.link_speed = new.link_speed;
602 eth_dev->data->dev_link.link_status = new.link_status;
607 static void bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
609 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
610 struct bnxt_vnic_info *vnic;
612 if (bp->vnic_info == NULL)
615 vnic = &bp->vnic_info[0];
617 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
618 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
621 static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
623 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
624 struct bnxt_vnic_info *vnic;
626 if (bp->vnic_info == NULL)
629 vnic = &bp->vnic_info[0];
631 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
632 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
635 static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
637 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
638 struct bnxt_vnic_info *vnic;
640 if (bp->vnic_info == NULL)
643 vnic = &bp->vnic_info[0];
645 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
646 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
649 static void bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
651 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
652 struct bnxt_vnic_info *vnic;
654 if (bp->vnic_info == NULL)
657 vnic = &bp->vnic_info[0];
659 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
660 bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
663 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
664 struct rte_eth_rss_reta_entry64 *reta_conf,
667 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
668 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
669 struct bnxt_vnic_info *vnic;
672 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
675 if (reta_size != HW_HASH_INDEX_SIZE) {
676 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
677 "(%d) must equal the size supported by the hardware "
678 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
681 /* Update the RSS VNIC(s) */
682 for (i = 0; i < MAX_FF_POOLS; i++) {
683 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
684 memcpy(vnic->rss_table, reta_conf, reta_size);
686 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
692 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
693 struct rte_eth_rss_reta_entry64 *reta_conf,
696 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
697 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
699 /* Retrieve from the default VNIC */
702 if (!vnic->rss_table)
705 if (reta_size != HW_HASH_INDEX_SIZE) {
706 RTE_LOG(ERR, PMD, "The configured hash table lookup size "
707 "(%d) must equal the size supported by the hardware "
708 "(%d)\n", reta_size, HW_HASH_INDEX_SIZE);
711 /* EW - need to revisit here copying from u64 to u16 */
712 memcpy(reta_conf, vnic->rss_table, reta_size);
717 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
718 struct rte_eth_rss_conf *rss_conf)
720 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
721 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
722 struct bnxt_vnic_info *vnic;
723 uint16_t hash_type = 0;
727 * If RSS enablement were different than dev_configure,
728 * then return -EINVAL
730 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
731 if (!rss_conf->rss_hf)
734 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
737 if (rss_conf->rss_hf & ETH_RSS_IPV4)
738 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
739 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
740 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
741 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
742 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
743 if (rss_conf->rss_hf & ETH_RSS_IPV6)
744 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
745 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
746 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
747 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
748 hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
750 /* Update the RSS VNIC(s) */
751 for (i = 0; i < MAX_FF_POOLS; i++) {
752 STAILQ_FOREACH(vnic, &bp->ff_pool[i], next) {
753 vnic->hash_type = hash_type;
756 * Use the supplied key if the key length is
757 * acceptable and the rss_key is not NULL
759 if (rss_conf->rss_key &&
760 rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
761 memcpy(vnic->rss_hash_key, rss_conf->rss_key,
762 rss_conf->rss_key_len);
764 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
770 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
771 struct rte_eth_rss_conf *rss_conf)
773 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
774 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
778 /* RSS configuration is the same for all VNICs */
779 if (vnic && vnic->rss_hash_key) {
780 if (rss_conf->rss_key) {
781 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
782 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
783 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
786 hash_types = vnic->hash_type;
787 rss_conf->rss_hf = 0;
788 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
789 rss_conf->rss_hf |= ETH_RSS_IPV4;
790 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
792 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
793 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
795 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
797 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
798 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
800 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
802 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
803 rss_conf->rss_hf |= ETH_RSS_IPV6;
804 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
806 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
807 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
809 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
811 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
812 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
814 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
818 "Unknwon RSS config from firmware (%08x), RSS disabled",
823 rss_conf->rss_hf = 0;
828 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
829 struct rte_eth_fc_conf *fc_conf __rte_unused)
831 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
832 struct rte_eth_link link_info;
835 rc = bnxt_get_hwrm_link_config(bp, &link_info);
839 memset(fc_conf, 0, sizeof(*fc_conf));
840 if (bp->link_info.auto_pause)
841 fc_conf->autoneg = 1;
842 switch (bp->link_info.pause) {
844 fc_conf->mode = RTE_FC_NONE;
846 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
847 fc_conf->mode = RTE_FC_TX_PAUSE;
849 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
850 fc_conf->mode = RTE_FC_RX_PAUSE;
852 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
853 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
854 fc_conf->mode = RTE_FC_FULL;
860 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
861 struct rte_eth_fc_conf *fc_conf)
863 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
865 if (BNXT_NPAR_PF(bp) || BNXT_VF(bp)) {
866 RTE_LOG(ERR, PMD, "Flow Control Settings cannot be modified\n");
870 switch (fc_conf->mode) {
872 bp->link_info.auto_pause = 0;
873 bp->link_info.force_pause = 0;
875 case RTE_FC_RX_PAUSE:
876 if (fc_conf->autoneg) {
877 bp->link_info.auto_pause =
878 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
879 bp->link_info.force_pause = 0;
881 bp->link_info.auto_pause = 0;
882 bp->link_info.force_pause =
883 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
886 case RTE_FC_TX_PAUSE:
887 if (fc_conf->autoneg) {
888 bp->link_info.auto_pause =
889 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
890 bp->link_info.force_pause = 0;
892 bp->link_info.auto_pause = 0;
893 bp->link_info.force_pause =
894 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
898 if (fc_conf->autoneg) {
899 bp->link_info.auto_pause =
900 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
901 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
902 bp->link_info.force_pause = 0;
904 bp->link_info.auto_pause = 0;
905 bp->link_info.force_pause =
906 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
907 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
911 return bnxt_set_hwrm_link_config(bp, true);
918 static struct eth_dev_ops bnxt_dev_ops = {
919 .dev_infos_get = bnxt_dev_info_get_op,
920 .dev_close = bnxt_dev_close_op,
921 .dev_configure = bnxt_dev_configure_op,
922 .dev_start = bnxt_dev_start_op,
923 .dev_stop = bnxt_dev_stop_op,
924 .dev_set_link_up = bnxt_dev_set_link_up_op,
925 .dev_set_link_down = bnxt_dev_set_link_down_op,
926 .stats_get = bnxt_stats_get_op,
927 .stats_reset = bnxt_stats_reset_op,
928 .rx_queue_setup = bnxt_rx_queue_setup_op,
929 .rx_queue_release = bnxt_rx_queue_release_op,
930 .tx_queue_setup = bnxt_tx_queue_setup_op,
931 .tx_queue_release = bnxt_tx_queue_release_op,
932 .reta_update = bnxt_reta_update_op,
933 .reta_query = bnxt_reta_query_op,
934 .rss_hash_update = bnxt_rss_hash_update_op,
935 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
936 .link_update = bnxt_link_update_op,
937 .promiscuous_enable = bnxt_promiscuous_enable_op,
938 .promiscuous_disable = bnxt_promiscuous_disable_op,
939 .allmulticast_enable = bnxt_allmulticast_enable_op,
940 .allmulticast_disable = bnxt_allmulticast_disable_op,
941 .mac_addr_add = bnxt_mac_addr_add_op,
942 .mac_addr_remove = bnxt_mac_addr_remove_op,
943 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
944 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
947 static bool bnxt_vf_pciid(uint16_t id)
949 if (id == BROADCOM_DEV_ID_57304_VF ||
950 id == BROADCOM_DEV_ID_57406_VF ||
951 id == BROADCOM_DEV_ID_5731X_VF ||
952 id == BROADCOM_DEV_ID_5741X_VF)
957 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
960 struct bnxt *bp = eth_dev->data->dev_private;
962 /* enable device (incl. PCI PM wakeup), and bus-mastering */
963 if (!eth_dev->pci_dev->mem_resource[0].addr) {
965 "Cannot find PCI device base address, aborting\n");
967 goto init_err_disable;
970 bp->eth_dev = eth_dev;
971 bp->pdev = eth_dev->pci_dev;
973 bp->bar0 = (void *)eth_dev->pci_dev->mem_resource[0].addr;
975 RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
977 goto init_err_release;
991 bnxt_dev_init(struct rte_eth_dev *eth_dev)
993 static int version_printed;
997 if (version_printed++ == 0)
998 RTE_LOG(INFO, PMD, "%s", bnxt_version);
1000 rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
1001 bp = eth_dev->data->dev_private;
1003 if (bnxt_vf_pciid(eth_dev->pci_dev->id.device_id))
1004 bp->flags |= BNXT_FLAG_VF;
1006 rc = bnxt_init_board(eth_dev);
1009 "Board initialization failed rc: %x\n", rc);
1012 eth_dev->dev_ops = &bnxt_dev_ops;
1013 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
1014 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
1016 rc = bnxt_alloc_hwrm_resources(bp);
1019 "hwrm resource allocation failure rc: %x\n", rc);
1022 rc = bnxt_hwrm_ver_get(bp);
1025 bnxt_hwrm_queue_qportcfg(bp);
1027 bnxt_hwrm_func_qcfg(bp);
1029 /* Get the MAX capabilities for this function */
1030 rc = bnxt_hwrm_func_qcaps(bp);
1032 RTE_LOG(ERR, PMD, "hwrm query capability failure rc: %x\n", rc);
1035 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
1036 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR, 0);
1037 if (eth_dev->data->mac_addrs == NULL) {
1039 "Failed to alloc %u bytes needed to store MAC addr tbl",
1040 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR);
1044 /* Copy the permanent MAC from the qcap response address now. */
1046 memcpy(bp->mac_addr, bp->pf.mac_addr, sizeof(bp->mac_addr));
1048 memcpy(bp->mac_addr, bp->vf.mac_addr, sizeof(bp->mac_addr));
1049 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
1050 bp->grp_info = rte_zmalloc("bnxt_grp_info",
1051 sizeof(*bp->grp_info) * bp->max_ring_grps, 0);
1052 if (!bp->grp_info) {
1054 "Failed to alloc %zu bytes needed to store group info table\n",
1055 sizeof(*bp->grp_info) * bp->max_ring_grps);
1060 rc = bnxt_hwrm_func_driver_register(bp, 0,
1064 "Failed to register driver");
1070 DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
1071 eth_dev->pci_dev->mem_resource[0].phys_addr,
1072 eth_dev->pci_dev->mem_resource[0].addr);
1077 eth_dev->driver->eth_dev_uninit(eth_dev);
1083 bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
1084 struct bnxt *bp = eth_dev->data->dev_private;
1087 if (eth_dev->data->mac_addrs)
1088 rte_free(eth_dev->data->mac_addrs);
1090 rte_free(bp->grp_info);
1091 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
1092 bnxt_free_hwrm_resources(bp);
1096 static struct eth_driver bnxt_rte_pmd = {
1098 .id_table = bnxt_pci_id_map,
1099 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1100 .probe = rte_eth_dev_pci_probe,
1101 .remove = rte_eth_dev_pci_remove
1103 .eth_dev_init = bnxt_dev_init,
1104 .eth_dev_uninit = bnxt_dev_uninit,
1105 .dev_private_size = sizeof(struct bnxt),
1108 DRIVER_REGISTER_PCI(net_bnxt, bnxt_rte_pmd.pci_drv);
1109 DRIVER_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);