1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
10 #include <rte_ethdev_driver.h>
11 #include <rte_ethdev_pci.h>
12 #include <rte_malloc.h>
13 #include <rte_cycles.h>
14 #include <rte_alarm.h>
15 #include <rte_kvargs.h>
18 #include "bnxt_filter.h"
19 #include "bnxt_hwrm.h"
21 #include "bnxt_reps.h"
22 #include "bnxt_ring.h"
25 #include "bnxt_stats.h"
28 #include "bnxt_vnic.h"
29 #include "hsi_struct_def_dpdk.h"
30 #include "bnxt_nvm_defs.h"
31 #include "bnxt_tf_common.h"
32 #include "ulp_flow_db.h"
34 #define DRV_MODULE_NAME "bnxt"
35 static const char bnxt_version[] =
36 "Broadcom NetXtreme driver " DRV_MODULE_NAME;
39 * The set of PCI devices this driver supports
41 static const struct rte_pci_id bnxt_pci_id_map[] = {
42 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
43 BROADCOM_DEV_ID_STRATUS_NIC_VF1) },
44 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
45 BROADCOM_DEV_ID_STRATUS_NIC_VF2) },
46 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
47 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
48 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
49 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
50 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
51 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
52 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
53 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
54 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
55 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
56 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
57 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
58 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
59 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
60 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
61 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
62 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
63 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
64 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
65 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
66 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
67 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
68 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
69 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
70 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
71 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
72 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
73 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
74 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
75 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
76 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
77 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
78 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
79 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
80 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802) },
81 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58804) },
82 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58808) },
83 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802_VF) },
84 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508) },
85 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504) },
86 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502) },
87 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF1) },
88 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF2) },
89 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF1) },
90 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF1) },
91 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF1) },
92 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF2) },
93 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF2) },
94 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF2) },
95 { .vendor_id = 0, /* sentinel */ },
98 #define BNXT_DEVARG_TRUFLOW "host-based-truflow"
99 #define BNXT_DEVARG_FLOW_XSTAT "flow-xstat"
100 #define BNXT_DEVARG_MAX_NUM_KFLOWS "max-num-kflows"
101 #define BNXT_DEVARG_REPRESENTOR "representor"
103 static const char *const bnxt_dev_args[] = {
104 BNXT_DEVARG_REPRESENTOR,
106 BNXT_DEVARG_FLOW_XSTAT,
107 BNXT_DEVARG_MAX_NUM_KFLOWS,
112 * truflow == false to disable the feature
113 * truflow == true to enable the feature
115 #define BNXT_DEVARG_TRUFLOW_INVALID(truflow) ((truflow) > 1)
118 * flow_xstat == false to disable the feature
119 * flow_xstat == true to enable the feature
121 #define BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat) ((flow_xstat) > 1)
124 * max_num_kflows must be >= 32
125 * and must be a power-of-2 supported value
126 * return: 1 -> invalid
129 static int bnxt_devarg_max_num_kflow_invalid(uint16_t max_num_kflows)
131 if (max_num_kflows < 32 || !rte_is_power_of_2(max_num_kflows))
136 static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
137 static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
138 static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev);
139 static int bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev);
140 static void bnxt_cancel_fw_health_check(struct bnxt *bp);
141 static int bnxt_restore_vlan_filters(struct bnxt *bp);
142 static void bnxt_dev_recover(void *arg);
143 static void bnxt_free_error_recovery_info(struct bnxt *bp);
144 static void bnxt_free_rep_info(struct bnxt *bp);
146 int is_bnxt_in_error(struct bnxt *bp)
148 if (bp->flags & BNXT_FLAG_FATAL_ERROR)
150 if (bp->flags & BNXT_FLAG_FW_RESET)
156 /***********************/
159 * High level utility functions
162 static uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
164 if (!BNXT_CHIP_THOR(bp))
167 return RTE_ALIGN_MUL_CEIL(bp->rx_nr_rings,
168 BNXT_RSS_ENTRIES_PER_CTX_THOR) /
169 BNXT_RSS_ENTRIES_PER_CTX_THOR;
172 uint16_t bnxt_rss_hash_tbl_size(const struct bnxt *bp)
174 if (!BNXT_CHIP_THOR(bp))
175 return HW_HASH_INDEX_SIZE;
177 return bnxt_rss_ctxts(bp) * BNXT_RSS_ENTRIES_PER_CTX_THOR;
180 static void bnxt_free_parent_info(struct bnxt *bp)
182 rte_free(bp->parent);
185 static void bnxt_free_pf_info(struct bnxt *bp)
190 static void bnxt_free_link_info(struct bnxt *bp)
192 rte_free(bp->link_info);
195 static void bnxt_free_leds_info(struct bnxt *bp)
204 static void bnxt_free_flow_stats_info(struct bnxt *bp)
206 rte_free(bp->flow_stat);
207 bp->flow_stat = NULL;
210 static void bnxt_free_cos_queues(struct bnxt *bp)
212 rte_free(bp->rx_cos_queue);
213 rte_free(bp->tx_cos_queue);
216 static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
218 bnxt_free_filter_mem(bp);
219 bnxt_free_vnic_attributes(bp);
220 bnxt_free_vnic_mem(bp);
222 /* tx/rx rings are configured as part of *_queue_setup callbacks.
223 * If the number of rings change across fw update,
224 * we don't have much choice except to warn the user.
228 bnxt_free_tx_rings(bp);
229 bnxt_free_rx_rings(bp);
231 bnxt_free_async_cp_ring(bp);
232 bnxt_free_rxtx_nq_ring(bp);
234 rte_free(bp->grp_info);
238 static int bnxt_alloc_parent_info(struct bnxt *bp)
240 bp->parent = rte_zmalloc("bnxt_parent_info",
241 sizeof(struct bnxt_parent_info), 0);
242 if (bp->parent == NULL)
248 static int bnxt_alloc_pf_info(struct bnxt *bp)
250 bp->pf = rte_zmalloc("bnxt_pf_info", sizeof(struct bnxt_pf_info), 0);
257 static int bnxt_alloc_link_info(struct bnxt *bp)
260 rte_zmalloc("bnxt_link_info", sizeof(struct bnxt_link_info), 0);
261 if (bp->link_info == NULL)
267 static int bnxt_alloc_leds_info(struct bnxt *bp)
272 bp->leds = rte_zmalloc("bnxt_leds",
273 BNXT_MAX_LED * sizeof(struct bnxt_led_info),
275 if (bp->leds == NULL)
281 static int bnxt_alloc_cos_queues(struct bnxt *bp)
284 rte_zmalloc("bnxt_rx_cosq",
285 BNXT_COS_QUEUE_COUNT *
286 sizeof(struct bnxt_cos_queue_info),
288 if (bp->rx_cos_queue == NULL)
292 rte_zmalloc("bnxt_tx_cosq",
293 BNXT_COS_QUEUE_COUNT *
294 sizeof(struct bnxt_cos_queue_info),
296 if (bp->tx_cos_queue == NULL)
302 static int bnxt_alloc_flow_stats_info(struct bnxt *bp)
304 bp->flow_stat = rte_zmalloc("bnxt_flow_xstat",
305 sizeof(struct bnxt_flow_stat_info), 0);
306 if (bp->flow_stat == NULL)
312 static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
316 rc = bnxt_alloc_ring_grps(bp);
320 rc = bnxt_alloc_async_ring_struct(bp);
324 rc = bnxt_alloc_vnic_mem(bp);
328 rc = bnxt_alloc_vnic_attributes(bp);
332 rc = bnxt_alloc_filter_mem(bp);
336 rc = bnxt_alloc_async_cp_ring(bp);
340 rc = bnxt_alloc_rxtx_nq_ring(bp);
344 if (BNXT_FLOW_XSTATS_EN(bp)) {
345 rc = bnxt_alloc_flow_stats_info(bp);
353 bnxt_free_mem(bp, reconfig);
357 static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)
359 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
360 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
361 uint64_t rx_offloads = dev_conf->rxmode.offloads;
362 struct bnxt_rx_queue *rxq;
366 rc = bnxt_vnic_grp_alloc(bp, vnic);
370 PMD_DRV_LOG(DEBUG, "vnic[%d] = %p vnic->fw_grp_ids = %p\n",
371 vnic_id, vnic, vnic->fw_grp_ids);
373 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
377 /* Alloc RSS context only if RSS mode is enabled */
378 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS) {
379 int j, nr_ctxs = bnxt_rss_ctxts(bp);
382 for (j = 0; j < nr_ctxs; j++) {
383 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, j);
389 "HWRM vnic %d ctx %d alloc failure rc: %x\n",
393 vnic->num_lb_ctxts = nr_ctxs;
397 * Firmware sets pf pair in default vnic cfg. If the VLAN strip
398 * setting is not available at this time, it will not be
399 * configured correctly in the CFA.
401 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
402 vnic->vlan_strip = true;
404 vnic->vlan_strip = false;
406 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
410 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
414 for (j = 0; j < bp->rx_num_qs_per_vnic; j++) {
415 rxq = bp->eth_dev->data->rx_queues[j];
418 "rxq[%d]->vnic=%p vnic->fw_grp_ids=%p\n",
419 j, rxq->vnic, rxq->vnic->fw_grp_ids);
421 if (BNXT_HAS_RING_GRPS(bp) && rxq->rx_deferred_start)
422 rxq->vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
424 vnic->rx_queue_cnt++;
427 PMD_DRV_LOG(DEBUG, "vnic->rx_queue_cnt = %d\n", vnic->rx_queue_cnt);
429 rc = bnxt_vnic_rss_configure(bp, vnic);
433 bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
435 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
436 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 1);
438 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 0);
442 PMD_DRV_LOG(ERR, "HWRM vnic %d cfg failure rc: %x\n",
447 static int bnxt_register_fc_ctx_mem(struct bnxt *bp)
451 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_in_tbl.dma,
452 &bp->flow_stat->rx_fc_in_tbl.ctx_id);
457 "rx_fc_in_tbl.va = %p rx_fc_in_tbl.dma = %p"
458 " rx_fc_in_tbl.ctx_id = %d\n",
459 bp->flow_stat->rx_fc_in_tbl.va,
460 (void *)((uintptr_t)bp->flow_stat->rx_fc_in_tbl.dma),
461 bp->flow_stat->rx_fc_in_tbl.ctx_id);
463 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_out_tbl.dma,
464 &bp->flow_stat->rx_fc_out_tbl.ctx_id);
469 "rx_fc_out_tbl.va = %p rx_fc_out_tbl.dma = %p"
470 " rx_fc_out_tbl.ctx_id = %d\n",
471 bp->flow_stat->rx_fc_out_tbl.va,
472 (void *)((uintptr_t)bp->flow_stat->rx_fc_out_tbl.dma),
473 bp->flow_stat->rx_fc_out_tbl.ctx_id);
475 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_in_tbl.dma,
476 &bp->flow_stat->tx_fc_in_tbl.ctx_id);
481 "tx_fc_in_tbl.va = %p tx_fc_in_tbl.dma = %p"
482 " tx_fc_in_tbl.ctx_id = %d\n",
483 bp->flow_stat->tx_fc_in_tbl.va,
484 (void *)((uintptr_t)bp->flow_stat->tx_fc_in_tbl.dma),
485 bp->flow_stat->tx_fc_in_tbl.ctx_id);
487 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_out_tbl.dma,
488 &bp->flow_stat->tx_fc_out_tbl.ctx_id);
493 "tx_fc_out_tbl.va = %p tx_fc_out_tbl.dma = %p"
494 " tx_fc_out_tbl.ctx_id = %d\n",
495 bp->flow_stat->tx_fc_out_tbl.va,
496 (void *)((uintptr_t)bp->flow_stat->tx_fc_out_tbl.dma),
497 bp->flow_stat->tx_fc_out_tbl.ctx_id);
499 memset(bp->flow_stat->rx_fc_out_tbl.va,
501 bp->flow_stat->rx_fc_out_tbl.size);
502 rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
503 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
504 bp->flow_stat->rx_fc_out_tbl.ctx_id,
505 bp->flow_stat->max_fc,
510 memset(bp->flow_stat->tx_fc_out_tbl.va,
512 bp->flow_stat->tx_fc_out_tbl.size);
513 rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
514 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
515 bp->flow_stat->tx_fc_out_tbl.ctx_id,
516 bp->flow_stat->max_fc,
522 static int bnxt_alloc_ctx_mem_buf(char *type, size_t size,
523 struct bnxt_ctx_mem_buf_info *ctx)
528 ctx->va = rte_zmalloc(type, size, 0);
531 rte_mem_lock_page(ctx->va);
533 ctx->dma = rte_mem_virt2iova(ctx->va);
534 if (ctx->dma == RTE_BAD_IOVA)
540 static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
542 struct rte_pci_device *pdev = bp->pdev;
543 char type[RTE_MEMZONE_NAMESIZE];
547 max_fc = bp->flow_stat->max_fc;
549 sprintf(type, "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
550 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
551 /* 4 bytes for each counter-id */
552 rc = bnxt_alloc_ctx_mem_buf(type,
554 &bp->flow_stat->rx_fc_in_tbl);
558 sprintf(type, "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
559 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
560 /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
561 rc = bnxt_alloc_ctx_mem_buf(type,
563 &bp->flow_stat->rx_fc_out_tbl);
567 sprintf(type, "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
568 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
569 /* 4 bytes for each counter-id */
570 rc = bnxt_alloc_ctx_mem_buf(type,
572 &bp->flow_stat->tx_fc_in_tbl);
576 sprintf(type, "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
577 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
578 /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
579 rc = bnxt_alloc_ctx_mem_buf(type,
581 &bp->flow_stat->tx_fc_out_tbl);
585 rc = bnxt_register_fc_ctx_mem(bp);
590 static int bnxt_init_ctx_mem(struct bnxt *bp)
594 if (!(bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS) ||
595 !(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) ||
596 !BNXT_FLOW_XSTATS_EN(bp))
599 rc = bnxt_hwrm_cfa_counter_qcaps(bp, &bp->flow_stat->max_fc);
603 rc = bnxt_init_fc_ctx_mem(bp);
608 static int bnxt_init_chip(struct bnxt *bp)
610 struct rte_eth_link new;
611 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(bp->eth_dev);
612 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
613 uint32_t intr_vector = 0;
614 uint32_t queue_id, base = BNXT_MISC_VEC_ID;
615 uint32_t vec = BNXT_MISC_VEC_ID;
619 if (bp->eth_dev->data->mtu > RTE_ETHER_MTU) {
620 bp->eth_dev->data->dev_conf.rxmode.offloads |=
621 DEV_RX_OFFLOAD_JUMBO_FRAME;
622 bp->flags |= BNXT_FLAG_JUMBO;
624 bp->eth_dev->data->dev_conf.rxmode.offloads &=
625 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
626 bp->flags &= ~BNXT_FLAG_JUMBO;
629 /* THOR does not support ring groups.
630 * But we will use the array to save RSS context IDs.
632 if (BNXT_CHIP_THOR(bp))
633 bp->max_ring_grps = BNXT_MAX_RSS_CTXTS_THOR;
635 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
637 PMD_DRV_LOG(ERR, "HWRM stat ctx alloc failure rc: %x\n", rc);
641 rc = bnxt_alloc_hwrm_rings(bp);
643 PMD_DRV_LOG(ERR, "HWRM ring alloc failure rc: %x\n", rc);
647 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
649 PMD_DRV_LOG(ERR, "HWRM ring grp alloc failure: %x\n", rc);
653 if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
656 for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
657 if (bp->rx_cos_queue[i].id != 0xff) {
658 struct bnxt_vnic_info *vnic = &bp->vnic_info[j++];
662 "Num pools more than FW profile\n");
666 vnic->cos_queue_id = bp->rx_cos_queue[i].id;
672 rc = bnxt_mq_rx_configure(bp);
674 PMD_DRV_LOG(ERR, "MQ mode configure failure rc: %x\n", rc);
678 /* VNIC configuration */
679 for (i = 0; i < bp->nr_vnics; i++) {
680 rc = bnxt_setup_one_vnic(bp, i);
685 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
688 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
692 /* check and configure queue intr-vector mapping */
693 if ((rte_intr_cap_multiple(intr_handle) ||
694 !RTE_ETH_DEV_SRIOV(bp->eth_dev).active) &&
695 bp->eth_dev->data->dev_conf.intr_conf.rxq != 0) {
696 intr_vector = bp->eth_dev->data->nb_rx_queues;
697 PMD_DRV_LOG(DEBUG, "intr_vector = %d\n", intr_vector);
698 if (intr_vector > bp->rx_cp_nr_rings) {
699 PMD_DRV_LOG(ERR, "At most %d intr queues supported",
703 rc = rte_intr_efd_enable(intr_handle, intr_vector);
708 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
709 intr_handle->intr_vec =
710 rte_zmalloc("intr_vec",
711 bp->eth_dev->data->nb_rx_queues *
713 if (intr_handle->intr_vec == NULL) {
714 PMD_DRV_LOG(ERR, "Failed to allocate %d rx_queues"
715 " intr_vec", bp->eth_dev->data->nb_rx_queues);
719 PMD_DRV_LOG(DEBUG, "intr_handle->intr_vec = %p "
720 "intr_handle->nb_efd = %d intr_handle->max_intr = %d\n",
721 intr_handle->intr_vec, intr_handle->nb_efd,
722 intr_handle->max_intr);
723 for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
725 intr_handle->intr_vec[queue_id] =
726 vec + BNXT_RX_VEC_START;
727 if (vec < base + intr_handle->nb_efd - 1)
732 /* enable uio/vfio intr/eventfd mapping */
733 rc = rte_intr_enable(intr_handle);
734 #ifndef RTE_EXEC_ENV_FREEBSD
735 /* In FreeBSD OS, nic_uio driver does not support interrupts */
740 rc = bnxt_get_hwrm_link_config(bp, &new);
742 PMD_DRV_LOG(ERR, "HWRM Get link config failure rc: %x\n", rc);
746 if (!bp->link_info->link_up) {
747 rc = bnxt_set_hwrm_link_config(bp, true);
750 "HWRM link config failure rc: %x\n", rc);
754 bnxt_print_link_info(bp->eth_dev);
756 bp->mark_table = rte_zmalloc("bnxt_mark_table", BNXT_MARK_TABLE_SZ, 0);
758 PMD_DRV_LOG(ERR, "Allocation of mark table failed\n");
763 rte_free(intr_handle->intr_vec);
765 rte_intr_efd_disable(intr_handle);
767 /* Some of the error status returned by FW may not be from errno.h */
774 static int bnxt_shutdown_nic(struct bnxt *bp)
776 bnxt_free_all_hwrm_resources(bp);
777 bnxt_free_all_filters(bp);
778 bnxt_free_all_vnics(bp);
783 * Device configuration and status function
786 uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
788 uint32_t link_speed = bp->link_info->support_speeds;
789 uint32_t speed_capa = 0;
791 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB)
792 speed_capa |= ETH_LINK_SPEED_100M;
793 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MBHD)
794 speed_capa |= ETH_LINK_SPEED_100M_HD;
795 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
796 speed_capa |= ETH_LINK_SPEED_1G;
797 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
798 speed_capa |= ETH_LINK_SPEED_2_5G;
799 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
800 speed_capa |= ETH_LINK_SPEED_10G;
801 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
802 speed_capa |= ETH_LINK_SPEED_20G;
803 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
804 speed_capa |= ETH_LINK_SPEED_25G;
805 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
806 speed_capa |= ETH_LINK_SPEED_40G;
807 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
808 speed_capa |= ETH_LINK_SPEED_50G;
809 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
810 speed_capa |= ETH_LINK_SPEED_100G;
811 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_200GB)
812 speed_capa |= ETH_LINK_SPEED_200G;
814 if (bp->link_info->auto_mode ==
815 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
816 speed_capa |= ETH_LINK_SPEED_FIXED;
818 speed_capa |= ETH_LINK_SPEED_AUTONEG;
823 static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
824 struct rte_eth_dev_info *dev_info)
826 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
827 struct bnxt *bp = eth_dev->data->dev_private;
828 uint16_t max_vnics, i, j, vpool, vrxq;
829 unsigned int max_rx_rings;
832 rc = is_bnxt_in_error(bp);
837 dev_info->max_mac_addrs = bp->max_l2_ctx;
838 dev_info->max_hash_mac_addrs = 0;
840 /* PF/VF specifics */
842 dev_info->max_vfs = pdev->max_vfs;
844 max_rx_rings = BNXT_MAX_RINGS(bp);
845 /* For the sake of symmetry, max_rx_queues = max_tx_queues */
846 dev_info->max_rx_queues = max_rx_rings;
847 dev_info->max_tx_queues = max_rx_rings;
848 dev_info->reta_size = bnxt_rss_hash_tbl_size(bp);
849 dev_info->hash_key_size = 40;
850 max_vnics = bp->max_vnics;
853 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
854 dev_info->max_mtu = BNXT_MAX_MTU;
856 /* Fast path specifics */
857 dev_info->min_rx_bufsize = 1;
858 dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
860 dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
861 if (bp->flags & BNXT_FLAG_PTP_SUPPORTED)
862 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TIMESTAMP;
863 dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
864 dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
866 dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
869 dev_info->default_rxconf = (struct rte_eth_rxconf) {
875 .rx_free_thresh = 32,
876 /* If no descriptors available, pkts are dropped by default */
880 dev_info->default_txconf = (struct rte_eth_txconf) {
886 .tx_free_thresh = 32,
889 eth_dev->data->dev_conf.intr_conf.lsc = 1;
891 eth_dev->data->dev_conf.intr_conf.rxq = 1;
892 dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
893 dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
894 dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
895 dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
900 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
901 * need further investigation.
905 vpool = 64; /* ETH_64_POOLS */
906 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
907 for (i = 0; i < 4; vpool >>= 1, i++) {
908 if (max_vnics > vpool) {
909 for (j = 0; j < 5; vrxq >>= 1, j++) {
910 if (dev_info->max_rx_queues > vrxq) {
916 /* Not enough resources to support VMDq */
920 /* Not enough resources to support VMDq */
924 dev_info->max_vmdq_pools = vpool;
925 dev_info->vmdq_queue_num = vrxq;
927 dev_info->vmdq_pool_base = 0;
928 dev_info->vmdq_queue_base = 0;
933 /* Configure the device based on the configuration provided */
934 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
936 struct bnxt *bp = eth_dev->data->dev_private;
937 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
940 bp->rx_queues = (void *)eth_dev->data->rx_queues;
941 bp->tx_queues = (void *)eth_dev->data->tx_queues;
942 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
943 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
945 rc = is_bnxt_in_error(bp);
949 if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
950 rc = bnxt_hwrm_check_vf_rings(bp);
952 PMD_DRV_LOG(ERR, "HWRM insufficient resources\n");
956 /* If a resource has already been allocated - in this case
957 * it is the async completion ring, free it. Reallocate it after
958 * resource reservation. This will ensure the resource counts
959 * are calculated correctly.
962 pthread_mutex_lock(&bp->def_cp_lock);
964 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
965 bnxt_disable_int(bp);
966 bnxt_free_cp_ring(bp, bp->async_cp_ring);
969 rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
971 PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc);
972 pthread_mutex_unlock(&bp->def_cp_lock);
976 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
977 rc = bnxt_alloc_async_cp_ring(bp);
979 pthread_mutex_unlock(&bp->def_cp_lock);
985 pthread_mutex_unlock(&bp->def_cp_lock);
987 /* legacy driver needs to get updated values */
988 rc = bnxt_hwrm_func_qcaps(bp);
990 PMD_DRV_LOG(ERR, "hwrm func qcaps fail:%d\n", rc);
995 /* Inherit new configurations */
996 if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
997 eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
998 eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
999 + BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
1000 eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
1002 goto resource_error;
1004 if (BNXT_HAS_RING_GRPS(bp) &&
1005 (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
1006 goto resource_error;
1008 if (!(eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS) &&
1009 bp->max_vnics < eth_dev->data->nb_rx_queues)
1010 goto resource_error;
1012 bp->rx_cp_nr_rings = bp->rx_nr_rings;
1013 bp->tx_cp_nr_rings = bp->tx_nr_rings;
1015 if (eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
1016 rx_offloads |= DEV_RX_OFFLOAD_RSS_HASH;
1017 eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
1019 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1020 eth_dev->data->mtu =
1021 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
1022 RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE *
1024 bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
1030 "Insufficient resources to support requested config\n");
1032 "Num Queues Requested: Tx %d, Rx %d\n",
1033 eth_dev->data->nb_tx_queues,
1034 eth_dev->data->nb_rx_queues);
1036 "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d\n",
1037 bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
1038 bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
1042 void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
1044 struct rte_eth_link *link = ð_dev->data->dev_link;
1046 if (link->link_status)
1047 PMD_DRV_LOG(INFO, "Port %d Link Up - speed %u Mbps - %s\n",
1048 eth_dev->data->port_id,
1049 (uint32_t)link->link_speed,
1050 (link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
1051 ("full-duplex") : ("half-duplex\n"));
1053 PMD_DRV_LOG(INFO, "Port %d Link Down\n",
1054 eth_dev->data->port_id);
1058 * Determine whether the current configuration requires support for scattered
1059 * receive; return 1 if scattered receive is required and 0 if not.
1061 static int bnxt_scattered_rx(struct rte_eth_dev *eth_dev)
1066 if (eth_dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER)
1069 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1070 struct bnxt_rx_queue *rxq = eth_dev->data->rx_queues[i];
1072 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
1073 RTE_PKTMBUF_HEADROOM);
1074 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len > buf_size)
1080 static eth_rx_burst_t
1081 bnxt_receive_function(struct rte_eth_dev *eth_dev)
1083 struct bnxt *bp = eth_dev->data->dev_private;
1085 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
1086 #ifndef RTE_LIBRTE_IEEE1588
1088 * Vector mode receive can be enabled only if scatter rx is not
1089 * in use and rx offloads are limited to VLAN stripping and
1092 if (!eth_dev->data->scattered_rx &&
1093 !(eth_dev->data->dev_conf.rxmode.offloads &
1094 ~(DEV_RX_OFFLOAD_VLAN_STRIP |
1095 DEV_RX_OFFLOAD_KEEP_CRC |
1096 DEV_RX_OFFLOAD_JUMBO_FRAME |
1097 DEV_RX_OFFLOAD_IPV4_CKSUM |
1098 DEV_RX_OFFLOAD_UDP_CKSUM |
1099 DEV_RX_OFFLOAD_TCP_CKSUM |
1100 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
1101 DEV_RX_OFFLOAD_RSS_HASH |
1102 DEV_RX_OFFLOAD_VLAN_FILTER)) &&
1103 !BNXT_TRUFLOW_EN(bp)) {
1104 PMD_DRV_LOG(INFO, "Using vector mode receive for port %d\n",
1105 eth_dev->data->port_id);
1106 bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
1107 return bnxt_recv_pkts_vec;
1109 PMD_DRV_LOG(INFO, "Vector mode receive disabled for port %d\n",
1110 eth_dev->data->port_id);
1112 "Port %d scatter: %d rx offload: %" PRIX64 "\n",
1113 eth_dev->data->port_id,
1114 eth_dev->data->scattered_rx,
1115 eth_dev->data->dev_conf.rxmode.offloads);
1118 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1119 return bnxt_recv_pkts;
1122 static eth_tx_burst_t
1123 bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
1125 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
1126 #ifndef RTE_LIBRTE_IEEE1588
1127 struct bnxt *bp = eth_dev->data->dev_private;
1130 * Vector mode transmit can be enabled only if not using scatter rx
1133 if (!eth_dev->data->scattered_rx &&
1134 !eth_dev->data->dev_conf.txmode.offloads &&
1135 !BNXT_TRUFLOW_EN(bp)) {
1136 PMD_DRV_LOG(INFO, "Using vector mode transmit for port %d\n",
1137 eth_dev->data->port_id);
1138 return bnxt_xmit_pkts_vec;
1140 PMD_DRV_LOG(INFO, "Vector mode transmit disabled for port %d\n",
1141 eth_dev->data->port_id);
1143 "Port %d scatter: %d tx offload: %" PRIX64 "\n",
1144 eth_dev->data->port_id,
1145 eth_dev->data->scattered_rx,
1146 eth_dev->data->dev_conf.txmode.offloads);
1149 return bnxt_xmit_pkts;
1152 static int bnxt_handle_if_change_status(struct bnxt *bp)
1156 /* Since fw has undergone a reset and lost all contexts,
1157 * set fatal flag to not issue hwrm during cleanup
1159 bp->flags |= BNXT_FLAG_FATAL_ERROR;
1160 bnxt_uninit_resources(bp, true);
1162 /* clear fatal flag so that re-init happens */
1163 bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
1164 rc = bnxt_init_resources(bp, true);
1166 bp->flags &= ~BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
1172 bnxt_create_port_app_df_rule(struct bnxt *bp, uint8_t flow_type,
1175 uint16_t port_id = bp->eth_dev->data->port_id;
1176 struct ulp_tlv_param param_list[] = {
1178 .type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
1180 .value = {(port_id >> 8) & 0xff, port_id & 0xff}
1183 .type = BNXT_ULP_DF_PARAM_TYPE_LAST,
1189 return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
1194 bnxt_create_df_rules(struct bnxt *bp)
1196 struct bnxt_ulp_data *cfg_data;
1199 cfg_data = bp->ulp_ctx->cfg_data;
1200 rc = bnxt_create_port_app_df_rule(bp, BNXT_ULP_DF_TPL_PORT_TO_VS,
1201 &cfg_data->port_to_app_flow_id);
1204 "Failed to create port to app default rule\n");
1208 BNXT_TF_DBG(DEBUG, "***** created port to app default rule ******\n");
1209 rc = bnxt_create_port_app_df_rule(bp, BNXT_ULP_DF_TPL_VS_TO_PORT,
1210 &cfg_data->app_to_port_flow_id);
1212 rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
1213 cfg_data->app_to_port_flow_id,
1214 &cfg_data->tx_cfa_action);
1219 "***** created app to port default rule *****\n");
1224 BNXT_TF_DBG(DEBUG, "Failed to create app to port default rule\n");
1229 bnxt_destroy_df_rules(struct bnxt *bp)
1231 struct bnxt_ulp_data *cfg_data;
1233 cfg_data = bp->ulp_ctx->cfg_data;
1234 ulp_default_flow_destroy(bp->eth_dev, cfg_data->port_to_app_flow_id);
1235 ulp_default_flow_destroy(bp->eth_dev, cfg_data->app_to_port_flow_id);
1238 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
1240 struct bnxt *bp = eth_dev->data->dev_private;
1241 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
1243 int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
1245 if (!eth_dev->data->nb_tx_queues || !eth_dev->data->nb_rx_queues) {
1246 PMD_DRV_LOG(ERR, "Queues are not configured yet!\n");
1250 if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1252 "RxQ cnt %d > CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
1253 bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1257 rc = bnxt_hwrm_if_change(bp, true);
1258 if (rc == 0 || rc != -EAGAIN)
1261 rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
1262 } while (retry_cnt--);
1267 if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
1268 rc = bnxt_handle_if_change_status(bp);
1273 bnxt_enable_int(bp);
1275 rc = bnxt_init_chip(bp);
1279 eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
1280 eth_dev->data->dev_started = 1;
1282 bnxt_link_update(eth_dev, 1, ETH_LINK_UP);
1284 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1285 vlan_mask |= ETH_VLAN_FILTER_MASK;
1286 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1287 vlan_mask |= ETH_VLAN_STRIP_MASK;
1288 rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
1292 eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
1293 eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
1295 pthread_mutex_lock(&bp->def_cp_lock);
1296 bnxt_schedule_fw_health_check(bp);
1297 pthread_mutex_unlock(&bp->def_cp_lock);
1299 if (BNXT_TRUFLOW_EN(bp))
1305 bnxt_shutdown_nic(bp);
1306 bnxt_free_tx_mbufs(bp);
1307 bnxt_free_rx_mbufs(bp);
1308 bnxt_hwrm_if_change(bp, false);
1309 eth_dev->data->dev_started = 0;
1313 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
1315 struct bnxt *bp = eth_dev->data->dev_private;
1318 if (!bp->link_info->link_up)
1319 rc = bnxt_set_hwrm_link_config(bp, true);
1321 eth_dev->data->dev_link.link_status = 1;
1323 bnxt_print_link_info(eth_dev);
1327 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
1329 struct bnxt *bp = eth_dev->data->dev_private;
1331 eth_dev->data->dev_link.link_status = 0;
1332 bnxt_set_hwrm_link_config(bp, false);
1333 bp->link_info->link_up = 0;
1338 static void bnxt_free_switch_domain(struct bnxt *bp)
1340 if (bp->switch_domain_id)
1341 rte_eth_switch_domain_free(bp->switch_domain_id);
1344 /* Unload the driver, release resources */
1345 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
1347 struct bnxt *bp = eth_dev->data->dev_private;
1348 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1349 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1351 eth_dev->data->dev_started = 0;
1352 /* Prevent crashes when queues are still in use */
1353 eth_dev->rx_pkt_burst = &bnxt_dummy_recv_pkts;
1354 eth_dev->tx_pkt_burst = &bnxt_dummy_xmit_pkts;
1356 bnxt_disable_int(bp);
1358 /* disable uio/vfio intr/eventfd mapping */
1359 rte_intr_disable(intr_handle);
1361 bnxt_cancel_fw_health_check(bp);
1363 bnxt_dev_set_link_down_op(eth_dev);
1365 /* Wait for link to be reset and the async notification to process.
1366 * During reset recovery, there is no need to wait and
1367 * VF/NPAR functions do not have privilege to change PHY config.
1369 if (!is_bnxt_in_error(bp) && BNXT_SINGLE_PF(bp))
1370 bnxt_link_update(eth_dev, 1, ETH_LINK_DOWN);
1372 /* Clean queue intr-vector mapping */
1373 rte_intr_efd_disable(intr_handle);
1374 if (intr_handle->intr_vec != NULL) {
1375 rte_free(intr_handle->intr_vec);
1376 intr_handle->intr_vec = NULL;
1379 bnxt_hwrm_port_clr_stats(bp);
1380 bnxt_free_tx_mbufs(bp);
1381 bnxt_free_rx_mbufs(bp);
1382 /* Process any remaining notifications in default completion queue */
1383 bnxt_int_handler(eth_dev);
1384 bnxt_shutdown_nic(bp);
1385 bnxt_hwrm_if_change(bp, false);
1387 rte_free(bp->mark_table);
1388 bp->mark_table = NULL;
1390 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1391 bp->rx_cosq_cnt = 0;
1392 /* All filters are deleted on a port stop. */
1393 if (BNXT_FLOW_XSTATS_EN(bp))
1394 bp->flow_stat->flow_count = 0;
1397 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
1399 struct bnxt *bp = eth_dev->data->dev_private;
1401 /* cancel the recovery handler before remove dev */
1402 rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
1403 rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
1404 bnxt_cancel_fc_thread(bp);
1406 if (BNXT_TRUFLOW_EN(bp)) {
1407 bnxt_destroy_df_rules(bp);
1408 bnxt_ulp_deinit(bp);
1411 if (eth_dev->data->dev_started)
1412 bnxt_dev_stop_op(eth_dev);
1414 bnxt_free_switch_domain(bp);
1416 bnxt_uninit_resources(bp, false);
1418 bnxt_free_leds_info(bp);
1419 bnxt_free_cos_queues(bp);
1420 bnxt_free_link_info(bp);
1421 bnxt_free_pf_info(bp);
1422 bnxt_free_parent_info(bp);
1424 eth_dev->dev_ops = NULL;
1425 eth_dev->rx_pkt_burst = NULL;
1426 eth_dev->tx_pkt_burst = NULL;
1428 rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
1429 bp->tx_mem_zone = NULL;
1430 rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
1431 bp->rx_mem_zone = NULL;
1433 rte_free(bp->pf->vf_info);
1434 bp->pf->vf_info = NULL;
1436 rte_free(bp->grp_info);
1437 bp->grp_info = NULL;
1440 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
1443 struct bnxt *bp = eth_dev->data->dev_private;
1444 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
1445 struct bnxt_vnic_info *vnic;
1446 struct bnxt_filter_info *filter, *temp_filter;
1449 if (is_bnxt_in_error(bp))
1453 * Loop through all VNICs from the specified filter flow pools to
1454 * remove the corresponding MAC addr filter
1456 for (i = 0; i < bp->nr_vnics; i++) {
1457 if (!(pool_mask & (1ULL << i)))
1460 vnic = &bp->vnic_info[i];
1461 filter = STAILQ_FIRST(&vnic->filter);
1463 temp_filter = STAILQ_NEXT(filter, next);
1464 if (filter->mac_index == index) {
1465 STAILQ_REMOVE(&vnic->filter, filter,
1466 bnxt_filter_info, next);
1467 bnxt_hwrm_clear_l2_filter(bp, filter);
1468 bnxt_free_filter(bp, filter);
1470 filter = temp_filter;
1475 static int bnxt_add_mac_filter(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1476 struct rte_ether_addr *mac_addr, uint32_t index,
1479 struct bnxt_filter_info *filter;
1482 /* Attach requested MAC address to the new l2_filter */
1483 STAILQ_FOREACH(filter, &vnic->filter, next) {
1484 if (filter->mac_index == index) {
1486 "MAC addr already existed for pool %d\n",
1492 filter = bnxt_alloc_filter(bp);
1494 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
1498 /* bnxt_alloc_filter copies default MAC to filter->l2_addr. So,
1499 * if the MAC that's been programmed now is a different one, then,
1500 * copy that addr to filter->l2_addr
1503 memcpy(filter->l2_addr, mac_addr, RTE_ETHER_ADDR_LEN);
1504 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
1506 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
1508 filter->mac_index = index;
1509 if (filter->mac_index == 0)
1510 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
1512 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
1514 bnxt_free_filter(bp, filter);
1520 static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
1521 struct rte_ether_addr *mac_addr,
1522 uint32_t index, uint32_t pool)
1524 struct bnxt *bp = eth_dev->data->dev_private;
1525 struct bnxt_vnic_info *vnic = &bp->vnic_info[pool];
1528 rc = is_bnxt_in_error(bp);
1532 if (BNXT_VF(bp) & !BNXT_VF_IS_TRUSTED(bp)) {
1533 PMD_DRV_LOG(ERR, "Cannot add MAC address to a VF interface\n");
1538 PMD_DRV_LOG(ERR, "VNIC not found for pool %d!\n", pool);
1542 /* Filter settings will get applied when port is started */
1543 if (!eth_dev->data->dev_started)
1546 rc = bnxt_add_mac_filter(bp, vnic, mac_addr, index, pool);
1551 int bnxt_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete,
1552 bool exp_link_status)
1555 struct bnxt *bp = eth_dev->data->dev_private;
1556 struct rte_eth_link new;
1557 int cnt = exp_link_status ? BNXT_LINK_UP_WAIT_CNT :
1558 BNXT_LINK_DOWN_WAIT_CNT;
1560 rc = is_bnxt_in_error(bp);
1564 memset(&new, 0, sizeof(new));
1566 /* Retrieve link info from hardware */
1567 rc = bnxt_get_hwrm_link_config(bp, &new);
1569 new.link_speed = ETH_LINK_SPEED_100M;
1570 new.link_duplex = ETH_LINK_FULL_DUPLEX;
1572 "Failed to retrieve link rc = 0x%x!\n", rc);
1576 if (!wait_to_complete || new.link_status == exp_link_status)
1579 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
1583 /* Timed out or success */
1584 if (new.link_status != eth_dev->data->dev_link.link_status ||
1585 new.link_speed != eth_dev->data->dev_link.link_speed) {
1586 rte_eth_linkstatus_set(eth_dev, &new);
1588 _rte_eth_dev_callback_process(eth_dev,
1589 RTE_ETH_EVENT_INTR_LSC,
1592 bnxt_print_link_info(eth_dev);
1598 int bnxt_link_update_op(struct rte_eth_dev *eth_dev,
1599 int wait_to_complete)
1601 return bnxt_link_update(eth_dev, wait_to_complete, ETH_LINK_UP);
1604 static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
1606 struct bnxt *bp = eth_dev->data->dev_private;
1607 struct bnxt_vnic_info *vnic;
1611 rc = is_bnxt_in_error(bp);
1615 /* Filter settings will get applied when port is started */
1616 if (!eth_dev->data->dev_started)
1619 if (bp->vnic_info == NULL)
1622 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1624 old_flags = vnic->flags;
1625 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
1626 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1628 vnic->flags = old_flags;
1633 static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
1635 struct bnxt *bp = eth_dev->data->dev_private;
1636 struct bnxt_vnic_info *vnic;
1640 rc = is_bnxt_in_error(bp);
1644 /* Filter settings will get applied when port is started */
1645 if (!eth_dev->data->dev_started)
1648 if (bp->vnic_info == NULL)
1651 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1653 old_flags = vnic->flags;
1654 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
1655 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1657 vnic->flags = old_flags;
1659 if (BNXT_TRUFLOW_EN(bp))
1660 bnxt_create_df_rules(bp);
1665 static int bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
1667 struct bnxt *bp = eth_dev->data->dev_private;
1668 struct bnxt_vnic_info *vnic;
1672 rc = is_bnxt_in_error(bp);
1676 /* Filter settings will get applied when port is started */
1677 if (!eth_dev->data->dev_started)
1680 if (bp->vnic_info == NULL)
1683 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1685 old_flags = vnic->flags;
1686 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
1687 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1689 vnic->flags = old_flags;
1694 static int bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
1696 struct bnxt *bp = eth_dev->data->dev_private;
1697 struct bnxt_vnic_info *vnic;
1701 rc = is_bnxt_in_error(bp);
1705 /* Filter settings will get applied when port is started */
1706 if (!eth_dev->data->dev_started)
1709 if (bp->vnic_info == NULL)
1712 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1714 old_flags = vnic->flags;
1715 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
1716 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1718 vnic->flags = old_flags;
1723 /* Return bnxt_rx_queue pointer corresponding to a given rxq. */
1724 static struct bnxt_rx_queue *bnxt_qid_to_rxq(struct bnxt *bp, uint16_t qid)
1726 if (qid >= bp->rx_nr_rings)
1729 return bp->eth_dev->data->rx_queues[qid];
1732 /* Return rxq corresponding to a given rss table ring/group ID. */
1733 static uint16_t bnxt_rss_to_qid(struct bnxt *bp, uint16_t fwr)
1735 struct bnxt_rx_queue *rxq;
1738 if (!BNXT_HAS_RING_GRPS(bp)) {
1739 for (i = 0; i < bp->rx_nr_rings; i++) {
1740 rxq = bp->eth_dev->data->rx_queues[i];
1741 if (rxq->rx_ring->rx_ring_struct->fw_ring_id == fwr)
1745 for (i = 0; i < bp->rx_nr_rings; i++) {
1746 if (bp->grp_info[i].fw_grp_id == fwr)
1751 return INVALID_HW_RING_ID;
1754 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
1755 struct rte_eth_rss_reta_entry64 *reta_conf,
1758 struct bnxt *bp = eth_dev->data->dev_private;
1759 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1760 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1761 uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
1765 rc = is_bnxt_in_error(bp);
1769 if (!vnic->rss_table)
1772 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
1775 if (reta_size != tbl_size) {
1776 PMD_DRV_LOG(ERR, "The configured hash table lookup size "
1777 "(%d) must equal the size supported by the hardware "
1778 "(%d)\n", reta_size, tbl_size);
1782 for (i = 0; i < reta_size; i++) {
1783 struct bnxt_rx_queue *rxq;
1785 idx = i / RTE_RETA_GROUP_SIZE;
1786 sft = i % RTE_RETA_GROUP_SIZE;
1788 if (!(reta_conf[idx].mask & (1ULL << sft)))
1791 rxq = bnxt_qid_to_rxq(bp, reta_conf[idx].reta[sft]);
1793 PMD_DRV_LOG(ERR, "Invalid ring in reta_conf.\n");
1797 if (BNXT_CHIP_THOR(bp)) {
1798 vnic->rss_table[i * 2] =
1799 rxq->rx_ring->rx_ring_struct->fw_ring_id;
1800 vnic->rss_table[i * 2 + 1] =
1801 rxq->cp_ring->cp_ring_struct->fw_ring_id;
1803 vnic->rss_table[i] =
1804 vnic->fw_grp_ids[reta_conf[idx].reta[sft]];
1808 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
1812 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
1813 struct rte_eth_rss_reta_entry64 *reta_conf,
1816 struct bnxt *bp = eth_dev->data->dev_private;
1817 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1818 uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
1819 uint16_t idx, sft, i;
1822 rc = is_bnxt_in_error(bp);
1826 /* Retrieve from the default VNIC */
1829 if (!vnic->rss_table)
1832 if (reta_size != tbl_size) {
1833 PMD_DRV_LOG(ERR, "The configured hash table lookup size "
1834 "(%d) must equal the size supported by the hardware "
1835 "(%d)\n", reta_size, tbl_size);
1839 for (idx = 0, i = 0; i < reta_size; i++) {
1840 idx = i / RTE_RETA_GROUP_SIZE;
1841 sft = i % RTE_RETA_GROUP_SIZE;
1843 if (reta_conf[idx].mask & (1ULL << sft)) {
1846 if (BNXT_CHIP_THOR(bp))
1847 qid = bnxt_rss_to_qid(bp,
1848 vnic->rss_table[i * 2]);
1850 qid = bnxt_rss_to_qid(bp, vnic->rss_table[i]);
1852 if (qid == INVALID_HW_RING_ID) {
1853 PMD_DRV_LOG(ERR, "Inv. entry in rss table.\n");
1856 reta_conf[idx].reta[sft] = qid;
1863 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
1864 struct rte_eth_rss_conf *rss_conf)
1866 struct bnxt *bp = eth_dev->data->dev_private;
1867 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1868 struct bnxt_vnic_info *vnic;
1871 rc = is_bnxt_in_error(bp);
1876 * If RSS enablement were different than dev_configure,
1877 * then return -EINVAL
1879 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
1880 if (!rss_conf->rss_hf)
1881 PMD_DRV_LOG(ERR, "Hash type NONE\n");
1883 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
1887 bp->flags |= BNXT_FLAG_UPDATE_HASH;
1888 memcpy(ð_dev->data->dev_conf.rx_adv_conf.rss_conf,
1892 /* Update the default RSS VNIC(s) */
1893 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1894 vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
1897 * If hashkey is not specified, use the previously configured
1900 if (!rss_conf->rss_key)
1903 if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE) {
1905 "Invalid hashkey length, should be 16 bytes\n");
1908 memcpy(vnic->rss_hash_key, rss_conf->rss_key, rss_conf->rss_key_len);
1911 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
1915 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
1916 struct rte_eth_rss_conf *rss_conf)
1918 struct bnxt *bp = eth_dev->data->dev_private;
1919 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1921 uint32_t hash_types;
1923 rc = is_bnxt_in_error(bp);
1927 /* RSS configuration is the same for all VNICs */
1928 if (vnic && vnic->rss_hash_key) {
1929 if (rss_conf->rss_key) {
1930 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
1931 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
1932 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
1935 hash_types = vnic->hash_type;
1936 rss_conf->rss_hf = 0;
1937 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
1938 rss_conf->rss_hf |= ETH_RSS_IPV4;
1939 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
1941 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
1942 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
1944 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
1946 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
1947 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
1949 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
1951 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
1952 rss_conf->rss_hf |= ETH_RSS_IPV6;
1953 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
1955 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
1956 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
1958 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
1960 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
1961 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
1963 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
1967 "Unknown RSS config from firmware (%08x), RSS disabled",
1972 rss_conf->rss_hf = 0;
1977 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
1978 struct rte_eth_fc_conf *fc_conf)
1980 struct bnxt *bp = dev->data->dev_private;
1981 struct rte_eth_link link_info;
1984 rc = is_bnxt_in_error(bp);
1988 rc = bnxt_get_hwrm_link_config(bp, &link_info);
1992 memset(fc_conf, 0, sizeof(*fc_conf));
1993 if (bp->link_info->auto_pause)
1994 fc_conf->autoneg = 1;
1995 switch (bp->link_info->pause) {
1997 fc_conf->mode = RTE_FC_NONE;
1999 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
2000 fc_conf->mode = RTE_FC_TX_PAUSE;
2002 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
2003 fc_conf->mode = RTE_FC_RX_PAUSE;
2005 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2006 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
2007 fc_conf->mode = RTE_FC_FULL;
2013 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
2014 struct rte_eth_fc_conf *fc_conf)
2016 struct bnxt *bp = dev->data->dev_private;
2019 rc = is_bnxt_in_error(bp);
2023 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp)) {
2024 PMD_DRV_LOG(ERR, "Flow Control Settings cannot be modified\n");
2028 switch (fc_conf->mode) {
2030 bp->link_info->auto_pause = 0;
2031 bp->link_info->force_pause = 0;
2033 case RTE_FC_RX_PAUSE:
2034 if (fc_conf->autoneg) {
2035 bp->link_info->auto_pause =
2036 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
2037 bp->link_info->force_pause = 0;
2039 bp->link_info->auto_pause = 0;
2040 bp->link_info->force_pause =
2041 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
2044 case RTE_FC_TX_PAUSE:
2045 if (fc_conf->autoneg) {
2046 bp->link_info->auto_pause =
2047 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
2048 bp->link_info->force_pause = 0;
2050 bp->link_info->auto_pause = 0;
2051 bp->link_info->force_pause =
2052 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
2056 if (fc_conf->autoneg) {
2057 bp->link_info->auto_pause =
2058 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
2059 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
2060 bp->link_info->force_pause = 0;
2062 bp->link_info->auto_pause = 0;
2063 bp->link_info->force_pause =
2064 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
2065 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
2069 return bnxt_set_hwrm_link_config(bp, true);
2072 /* Add UDP tunneling port */
2074 bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
2075 struct rte_eth_udp_tunnel *udp_tunnel)
2077 struct bnxt *bp = eth_dev->data->dev_private;
2078 uint16_t tunnel_type = 0;
2081 rc = is_bnxt_in_error(bp);
2085 switch (udp_tunnel->prot_type) {
2086 case RTE_TUNNEL_TYPE_VXLAN:
2087 if (bp->vxlan_port_cnt) {
2088 PMD_DRV_LOG(ERR, "Tunnel Port %d already programmed\n",
2089 udp_tunnel->udp_port);
2090 if (bp->vxlan_port != udp_tunnel->udp_port) {
2091 PMD_DRV_LOG(ERR, "Only one port allowed\n");
2094 bp->vxlan_port_cnt++;
2098 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
2099 bp->vxlan_port_cnt++;
2101 case RTE_TUNNEL_TYPE_GENEVE:
2102 if (bp->geneve_port_cnt) {
2103 PMD_DRV_LOG(ERR, "Tunnel Port %d already programmed\n",
2104 udp_tunnel->udp_port);
2105 if (bp->geneve_port != udp_tunnel->udp_port) {
2106 PMD_DRV_LOG(ERR, "Only one port allowed\n");
2109 bp->geneve_port_cnt++;
2113 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
2114 bp->geneve_port_cnt++;
2117 PMD_DRV_LOG(ERR, "Tunnel type is not supported\n");
2120 rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
2126 bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
2127 struct rte_eth_udp_tunnel *udp_tunnel)
2129 struct bnxt *bp = eth_dev->data->dev_private;
2130 uint16_t tunnel_type = 0;
2134 rc = is_bnxt_in_error(bp);
2138 switch (udp_tunnel->prot_type) {
2139 case RTE_TUNNEL_TYPE_VXLAN:
2140 if (!bp->vxlan_port_cnt) {
2141 PMD_DRV_LOG(ERR, "No Tunnel port configured yet\n");
2144 if (bp->vxlan_port != udp_tunnel->udp_port) {
2145 PMD_DRV_LOG(ERR, "Req Port: %d. Configured port: %d\n",
2146 udp_tunnel->udp_port, bp->vxlan_port);
2149 if (--bp->vxlan_port_cnt)
2153 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
2154 port = bp->vxlan_fw_dst_port_id;
2156 case RTE_TUNNEL_TYPE_GENEVE:
2157 if (!bp->geneve_port_cnt) {
2158 PMD_DRV_LOG(ERR, "No Tunnel port configured yet\n");
2161 if (bp->geneve_port != udp_tunnel->udp_port) {
2162 PMD_DRV_LOG(ERR, "Req Port: %d. Configured port: %d\n",
2163 udp_tunnel->udp_port, bp->geneve_port);
2166 if (--bp->geneve_port_cnt)
2170 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
2171 port = bp->geneve_fw_dst_port_id;
2174 PMD_DRV_LOG(ERR, "Tunnel type is not supported\n");
2178 rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
2181 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN)
2184 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE)
2185 bp->geneve_port = 0;
2190 static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2192 struct bnxt_filter_info *filter;
2193 struct bnxt_vnic_info *vnic;
2195 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2197 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2198 filter = STAILQ_FIRST(&vnic->filter);
2200 /* Search for this matching MAC+VLAN filter */
2201 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id)) {
2202 /* Delete the filter */
2203 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2206 STAILQ_REMOVE(&vnic->filter, filter,
2207 bnxt_filter_info, next);
2208 bnxt_free_filter(bp, filter);
2210 "Deleted vlan filter for %d\n",
2214 filter = STAILQ_NEXT(filter, next);
2219 static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2221 struct bnxt_filter_info *filter;
2222 struct bnxt_vnic_info *vnic;
2224 uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
2225 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
2226 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2228 /* Implementation notes on the use of VNIC in this command:
2230 * By default, these filters belong to default vnic for the function.
2231 * Once these filters are set up, only destination VNIC can be modified.
2232 * If the destination VNIC is not specified in this command,
2233 * then the HWRM shall only create an l2 context id.
2236 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2237 filter = STAILQ_FIRST(&vnic->filter);
2238 /* Check if the VLAN has already been added */
2240 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id))
2243 filter = STAILQ_NEXT(filter, next);
2246 /* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
2247 * command to create MAC+VLAN filter with the right flags, enables set.
2249 filter = bnxt_alloc_filter(bp);
2252 "MAC/VLAN filter alloc failed\n");
2255 /* MAC + VLAN ID filter */
2256 /* If l2_ivlan == 0 and l2_ivlan_mask != 0, only
2257 * untagged packets are received
2259 * If l2_ivlan != 0 and l2_ivlan_mask != 0, untagged
2260 * packets and only the programmed vlan's packets are received
2262 filter->l2_ivlan = vlan_id;
2263 filter->l2_ivlan_mask = 0x0FFF;
2264 filter->enables |= en;
2265 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
2267 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
2269 /* Free the newly allocated filter as we were
2270 * not able to create the filter in hardware.
2272 bnxt_free_filter(bp, filter);
2276 filter->mac_index = 0;
2277 /* Add this new filter to the list */
2279 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
2281 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
2284 "Added Vlan filter for %d\n", vlan_id);
2288 static int bnxt_vlan_filter_set_op(struct rte_eth_dev *eth_dev,
2289 uint16_t vlan_id, int on)
2291 struct bnxt *bp = eth_dev->data->dev_private;
2294 rc = is_bnxt_in_error(bp);
2298 if (!eth_dev->data->dev_started) {
2299 PMD_DRV_LOG(ERR, "port must be started before setting vlan\n");
2303 /* These operations apply to ALL existing MAC/VLAN filters */
2305 return bnxt_add_vlan_filter(bp, vlan_id);
2307 return bnxt_del_vlan_filter(bp, vlan_id);
2310 static int bnxt_del_dflt_mac_filter(struct bnxt *bp,
2311 struct bnxt_vnic_info *vnic)
2313 struct bnxt_filter_info *filter;
2316 filter = STAILQ_FIRST(&vnic->filter);
2318 if (filter->mac_index == 0 &&
2319 !memcmp(filter->l2_addr, bp->mac_addr,
2320 RTE_ETHER_ADDR_LEN)) {
2321 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2323 STAILQ_REMOVE(&vnic->filter, filter,
2324 bnxt_filter_info, next);
2325 bnxt_free_filter(bp, filter);
2329 filter = STAILQ_NEXT(filter, next);
2335 bnxt_config_vlan_hw_filter(struct bnxt *bp, uint64_t rx_offloads)
2337 struct bnxt_vnic_info *vnic;
2341 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2342 if (!(rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)) {
2343 /* Remove any VLAN filters programmed */
2344 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2345 bnxt_del_vlan_filter(bp, i);
2347 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2351 /* Default filter will allow packets that match the
2352 * dest mac. So, it has to be deleted, otherwise, we
2353 * will endup receiving vlan packets for which the
2354 * filter is not programmed, when hw-vlan-filter
2355 * configuration is ON
2357 bnxt_del_dflt_mac_filter(bp, vnic);
2358 /* This filter will allow only untagged packets */
2359 bnxt_add_vlan_filter(bp, 0);
2361 PMD_DRV_LOG(DEBUG, "VLAN Filtering: %d\n",
2362 !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER));
2367 static int bnxt_free_one_vnic(struct bnxt *bp, uint16_t vnic_id)
2369 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
2373 /* Destroy vnic filters and vnic */
2374 if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2375 DEV_RX_OFFLOAD_VLAN_FILTER) {
2376 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2377 bnxt_del_vlan_filter(bp, i);
2379 bnxt_del_dflt_mac_filter(bp, vnic);
2381 rc = bnxt_hwrm_vnic_free(bp, vnic);
2385 rte_free(vnic->fw_grp_ids);
2386 vnic->fw_grp_ids = NULL;
2388 vnic->rx_queue_cnt = 0;
2394 bnxt_config_vlan_hw_stripping(struct bnxt *bp, uint64_t rx_offloads)
2396 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
2399 /* Destroy, recreate and reconfigure the default vnic */
2400 rc = bnxt_free_one_vnic(bp, 0);
2404 /* default vnic 0 */
2405 rc = bnxt_setup_one_vnic(bp, 0);
2409 if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2410 DEV_RX_OFFLOAD_VLAN_FILTER) {
2411 rc = bnxt_add_vlan_filter(bp, 0);
2414 rc = bnxt_restore_vlan_filters(bp);
2418 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2423 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2427 PMD_DRV_LOG(DEBUG, "VLAN Strip Offload: %d\n",
2428 !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP));
2434 bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
2436 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
2437 struct bnxt *bp = dev->data->dev_private;
2440 rc = is_bnxt_in_error(bp);
2444 /* Filter settings will get applied when port is started */
2445 if (!dev->data->dev_started)
2448 if (mask & ETH_VLAN_FILTER_MASK) {
2449 /* Enable or disable VLAN filtering */
2450 rc = bnxt_config_vlan_hw_filter(bp, rx_offloads);
2455 if (mask & ETH_VLAN_STRIP_MASK) {
2456 /* Enable or disable VLAN stripping */
2457 rc = bnxt_config_vlan_hw_stripping(bp, rx_offloads);
2462 if (mask & ETH_VLAN_EXTEND_MASK) {
2463 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2464 PMD_DRV_LOG(DEBUG, "Extend VLAN supported\n");
2466 PMD_DRV_LOG(INFO, "Extend VLAN unsupported\n");
2473 bnxt_vlan_tpid_set_op(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
2476 struct bnxt *bp = dev->data->dev_private;
2477 int qinq = dev->data->dev_conf.rxmode.offloads &
2478 DEV_RX_OFFLOAD_VLAN_EXTEND;
2480 if (vlan_type != ETH_VLAN_TYPE_INNER &&
2481 vlan_type != ETH_VLAN_TYPE_OUTER) {
2483 "Unsupported vlan type.");
2488 "QinQ not enabled. Needs to be ON as we can "
2489 "accelerate only outer vlan\n");
2493 if (vlan_type == ETH_VLAN_TYPE_OUTER) {
2495 case RTE_ETHER_TYPE_QINQ:
2497 TX_BD_LONG_CFA_META_VLAN_TPID_TPID88A8;
2499 case RTE_ETHER_TYPE_VLAN:
2501 TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
2503 case RTE_ETHER_TYPE_QINQ1:
2505 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9100;
2507 case RTE_ETHER_TYPE_QINQ2:
2509 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9200;
2511 case RTE_ETHER_TYPE_QINQ3:
2513 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9300;
2516 PMD_DRV_LOG(ERR, "Invalid TPID: %x\n", tpid);
2519 bp->outer_tpid_bd |= tpid;
2520 PMD_DRV_LOG(INFO, "outer_tpid_bd = %x\n", bp->outer_tpid_bd);
2521 } else if (vlan_type == ETH_VLAN_TYPE_INNER) {
2523 "Can accelerate only outer vlan in QinQ\n");
2531 bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
2532 struct rte_ether_addr *addr)
2534 struct bnxt *bp = dev->data->dev_private;
2535 /* Default Filter is tied to VNIC 0 */
2536 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
2539 rc = is_bnxt_in_error(bp);
2543 if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
2546 if (rte_is_zero_ether_addr(addr))
2549 /* Filter settings will get applied when port is started */
2550 if (!dev->data->dev_started)
2553 /* Check if the requested MAC is already added */
2554 if (memcmp(addr, bp->mac_addr, RTE_ETHER_ADDR_LEN) == 0)
2557 /* Destroy filter and re-create it */
2558 bnxt_del_dflt_mac_filter(bp, vnic);
2560 memcpy(bp->mac_addr, addr, RTE_ETHER_ADDR_LEN);
2561 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
2562 /* This filter will allow only untagged packets */
2563 rc = bnxt_add_vlan_filter(bp, 0);
2565 rc = bnxt_add_mac_filter(bp, vnic, addr, 0, 0);
2568 PMD_DRV_LOG(DEBUG, "Set MAC addr\n");
2573 bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
2574 struct rte_ether_addr *mc_addr_set,
2575 uint32_t nb_mc_addr)
2577 struct bnxt *bp = eth_dev->data->dev_private;
2578 char *mc_addr_list = (char *)mc_addr_set;
2579 struct bnxt_vnic_info *vnic;
2580 uint32_t off = 0, i = 0;
2583 rc = is_bnxt_in_error(bp);
2587 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2589 if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
2590 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
2594 /* TODO Check for Duplicate mcast addresses */
2595 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
2596 for (i = 0; i < nb_mc_addr; i++) {
2597 memcpy(vnic->mc_list + off, &mc_addr_list[i],
2598 RTE_ETHER_ADDR_LEN);
2599 off += RTE_ETHER_ADDR_LEN;
2602 vnic->mc_addr_cnt = i;
2603 if (vnic->mc_addr_cnt)
2604 vnic->flags |= BNXT_VNIC_INFO_MCAST;
2606 vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
2609 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2613 bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
2615 struct bnxt *bp = dev->data->dev_private;
2616 uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
2617 uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
2618 uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
2619 uint8_t fw_rsvd = bp->fw_ver & 0xff;
2622 ret = snprintf(fw_version, fw_size, "%d.%d.%d.%d",
2623 fw_major, fw_minor, fw_updt, fw_rsvd);
2625 ret += 1; /* add the size of '\0' */
2626 if (fw_size < (uint32_t)ret)
2633 bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
2634 struct rte_eth_rxq_info *qinfo)
2636 struct bnxt *bp = dev->data->dev_private;
2637 struct bnxt_rx_queue *rxq;
2639 if (is_bnxt_in_error(bp))
2642 rxq = dev->data->rx_queues[queue_id];
2644 qinfo->mp = rxq->mb_pool;
2645 qinfo->scattered_rx = dev->data->scattered_rx;
2646 qinfo->nb_desc = rxq->nb_rx_desc;
2648 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2649 qinfo->conf.rx_drop_en = 0;
2650 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
2654 bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
2655 struct rte_eth_txq_info *qinfo)
2657 struct bnxt *bp = dev->data->dev_private;
2658 struct bnxt_tx_queue *txq;
2660 if (is_bnxt_in_error(bp))
2663 txq = dev->data->tx_queues[queue_id];
2665 qinfo->nb_desc = txq->nb_tx_desc;
2667 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2668 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2669 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2671 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
2672 qinfo->conf.tx_rs_thresh = 0;
2673 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
2677 bnxt_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2678 struct rte_eth_burst_mode *mode)
2680 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
2682 if (pkt_burst == bnxt_recv_pkts) {
2683 snprintf(mode->info, sizeof(mode->info), "%s",
2687 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
2688 if (pkt_burst == bnxt_recv_pkts_vec) {
2689 snprintf(mode->info, sizeof(mode->info), "%s",
2699 bnxt_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2700 struct rte_eth_burst_mode *mode)
2702 eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
2704 if (pkt_burst == bnxt_xmit_pkts) {
2705 snprintf(mode->info, sizeof(mode->info), "%s",
2709 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
2710 if (pkt_burst == bnxt_xmit_pkts_vec) {
2711 snprintf(mode->info, sizeof(mode->info), "%s",
2720 int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
2722 struct bnxt *bp = eth_dev->data->dev_private;
2723 uint32_t new_pkt_size;
2727 rc = is_bnxt_in_error(bp);
2731 /* Exit if receive queues are not configured yet */
2732 if (!eth_dev->data->nb_rx_queues)
2735 new_pkt_size = new_mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
2736 VLAN_TAG_SIZE * BNXT_NUM_VLANS;
2738 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
2740 * If vector-mode tx/rx is active, disallow any MTU change that would
2741 * require scattered receive support.
2743 if (eth_dev->data->dev_started &&
2744 (eth_dev->rx_pkt_burst == bnxt_recv_pkts_vec ||
2745 eth_dev->tx_pkt_burst == bnxt_xmit_pkts_vec) &&
2747 eth_dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
2749 "MTU change would require scattered rx support. ");
2750 PMD_DRV_LOG(ERR, "Stop port before changing MTU.\n");
2755 if (new_mtu > RTE_ETHER_MTU) {
2756 bp->flags |= BNXT_FLAG_JUMBO;
2757 bp->eth_dev->data->dev_conf.rxmode.offloads |=
2758 DEV_RX_OFFLOAD_JUMBO_FRAME;
2760 bp->eth_dev->data->dev_conf.rxmode.offloads &=
2761 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2762 bp->flags &= ~BNXT_FLAG_JUMBO;
2765 /* Is there a change in mtu setting? */
2766 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len == new_pkt_size)
2769 for (i = 0; i < bp->nr_vnics; i++) {
2770 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2773 vnic->mru = BNXT_VNIC_MRU(new_mtu);
2774 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
2778 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
2779 size -= RTE_PKTMBUF_HEADROOM;
2781 if (size < new_mtu) {
2782 rc = bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
2789 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = new_pkt_size;
2791 PMD_DRV_LOG(INFO, "New MTU is %d\n", new_mtu);
2797 bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
2799 struct bnxt *bp = dev->data->dev_private;
2800 uint16_t vlan = bp->vlan;
2803 rc = is_bnxt_in_error(bp);
2807 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp)) {
2809 "PVID cannot be modified for this function\n");
2812 bp->vlan = on ? pvid : 0;
2814 rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
2821 bnxt_dev_led_on_op(struct rte_eth_dev *dev)
2823 struct bnxt *bp = dev->data->dev_private;
2826 rc = is_bnxt_in_error(bp);
2830 return bnxt_hwrm_port_led_cfg(bp, true);
2834 bnxt_dev_led_off_op(struct rte_eth_dev *dev)
2836 struct bnxt *bp = dev->data->dev_private;
2839 rc = is_bnxt_in_error(bp);
2843 return bnxt_hwrm_port_led_cfg(bp, false);
2847 bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
2849 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2850 uint32_t desc = 0, raw_cons = 0, cons;
2851 struct bnxt_cp_ring_info *cpr;
2852 struct bnxt_rx_queue *rxq;
2853 struct rx_pkt_cmpl *rxcmp;
2856 rc = is_bnxt_in_error(bp);
2860 rxq = dev->data->rx_queues[rx_queue_id];
2862 raw_cons = cpr->cp_raw_cons;
2865 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
2866 rte_prefetch0(&cpr->cp_desc_ring[cons]);
2867 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2869 if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct)) {
2881 bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)
2883 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
2884 struct bnxt_rx_ring_info *rxr;
2885 struct bnxt_cp_ring_info *cpr;
2886 struct bnxt_sw_rx_bd *rx_buf;
2887 struct rx_pkt_cmpl *rxcmp;
2888 uint32_t cons, cp_cons;
2894 rc = is_bnxt_in_error(rxq->bp);
2901 if (offset >= rxq->nb_rx_desc)
2904 cons = RING_CMP(cpr->cp_ring_struct, offset);
2905 cp_cons = cpr->cp_raw_cons;
2906 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2908 if (cons > cp_cons) {
2909 if (CMPL_VALID(rxcmp, cpr->valid))
2910 return RTE_ETH_RX_DESC_DONE;
2912 if (CMPL_VALID(rxcmp, !cpr->valid))
2913 return RTE_ETH_RX_DESC_DONE;
2915 rx_buf = &rxr->rx_buf_ring[cons];
2916 if (rx_buf->mbuf == NULL)
2917 return RTE_ETH_RX_DESC_UNAVAIL;
2920 return RTE_ETH_RX_DESC_AVAIL;
2924 bnxt_tx_descriptor_status_op(void *tx_queue, uint16_t offset)
2926 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
2927 struct bnxt_tx_ring_info *txr;
2928 struct bnxt_cp_ring_info *cpr;
2929 struct bnxt_sw_tx_bd *tx_buf;
2930 struct tx_pkt_cmpl *txcmp;
2931 uint32_t cons, cp_cons;
2937 rc = is_bnxt_in_error(txq->bp);
2944 if (offset >= txq->nb_tx_desc)
2947 cons = RING_CMP(cpr->cp_ring_struct, offset);
2948 txcmp = (struct tx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2949 cp_cons = cpr->cp_raw_cons;
2951 if (cons > cp_cons) {
2952 if (CMPL_VALID(txcmp, cpr->valid))
2953 return RTE_ETH_TX_DESC_UNAVAIL;
2955 if (CMPL_VALID(txcmp, !cpr->valid))
2956 return RTE_ETH_TX_DESC_UNAVAIL;
2958 tx_buf = &txr->tx_buf_ring[cons];
2959 if (tx_buf->mbuf == NULL)
2960 return RTE_ETH_TX_DESC_DONE;
2962 return RTE_ETH_TX_DESC_FULL;
2965 static struct bnxt_filter_info *
2966 bnxt_match_and_validate_ether_filter(struct bnxt *bp,
2967 struct rte_eth_ethertype_filter *efilter,
2968 struct bnxt_vnic_info *vnic0,
2969 struct bnxt_vnic_info *vnic,
2972 struct bnxt_filter_info *mfilter = NULL;
2976 if (efilter->ether_type == RTE_ETHER_TYPE_IPV4 ||
2977 efilter->ether_type == RTE_ETHER_TYPE_IPV6) {
2978 PMD_DRV_LOG(ERR, "invalid ether_type(0x%04x) in"
2979 " ethertype filter.", efilter->ether_type);
2983 if (efilter->queue >= bp->rx_nr_rings) {
2984 PMD_DRV_LOG(ERR, "Invalid queue %d\n", efilter->queue);
2989 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
2990 vnic = &bp->vnic_info[efilter->queue];
2992 PMD_DRV_LOG(ERR, "Invalid queue %d\n", efilter->queue);
2997 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
2998 STAILQ_FOREACH(mfilter, &vnic0->filter, next) {
2999 if ((!memcmp(efilter->mac_addr.addr_bytes,
3000 mfilter->l2_addr, RTE_ETHER_ADDR_LEN) &&
3002 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP &&
3003 mfilter->ethertype == efilter->ether_type)) {
3009 STAILQ_FOREACH(mfilter, &vnic->filter, next)
3010 if ((!memcmp(efilter->mac_addr.addr_bytes,
3011 mfilter->l2_addr, RTE_ETHER_ADDR_LEN) &&
3012 mfilter->ethertype == efilter->ether_type &&
3014 HWRM_CFA_L2_FILTER_CFG_INPUT_FLAGS_PATH_RX)) {
3028 bnxt_ethertype_filter(struct rte_eth_dev *dev,
3029 enum rte_filter_op filter_op,
3032 struct bnxt *bp = dev->data->dev_private;
3033 struct rte_eth_ethertype_filter *efilter =
3034 (struct rte_eth_ethertype_filter *)arg;
3035 struct bnxt_filter_info *bfilter, *filter1;
3036 struct bnxt_vnic_info *vnic, *vnic0;
3039 if (filter_op == RTE_ETH_FILTER_NOP)
3043 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3048 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3049 vnic = &bp->vnic_info[efilter->queue];
3051 switch (filter_op) {
3052 case RTE_ETH_FILTER_ADD:
3053 bnxt_match_and_validate_ether_filter(bp, efilter,
3058 bfilter = bnxt_get_unused_filter(bp);
3059 if (bfilter == NULL) {
3061 "Not enough resources for a new filter.\n");
3064 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3065 memcpy(bfilter->l2_addr, efilter->mac_addr.addr_bytes,
3066 RTE_ETHER_ADDR_LEN);
3067 memcpy(bfilter->dst_macaddr, efilter->mac_addr.addr_bytes,
3068 RTE_ETHER_ADDR_LEN);
3069 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
3070 bfilter->ethertype = efilter->ether_type;
3071 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3073 filter1 = bnxt_get_l2_filter(bp, bfilter, vnic0);
3074 if (filter1 == NULL) {
3079 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3080 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3082 bfilter->dst_id = vnic->fw_vnic_id;
3084 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
3086 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
3089 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
3092 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
3094 case RTE_ETH_FILTER_DELETE:
3095 filter1 = bnxt_match_and_validate_ether_filter(bp, efilter,
3097 if (ret == -EEXIST) {
3098 ret = bnxt_hwrm_clear_ntuple_filter(bp, filter1);
3100 STAILQ_REMOVE(&vnic->filter, filter1, bnxt_filter_info,
3102 bnxt_free_filter(bp, filter1);
3103 } else if (ret == 0) {
3104 PMD_DRV_LOG(ERR, "No matching filter found\n");
3108 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3114 bnxt_free_filter(bp, bfilter);
3120 parse_ntuple_filter(struct bnxt *bp,
3121 struct rte_eth_ntuple_filter *nfilter,
3122 struct bnxt_filter_info *bfilter)
3126 if (nfilter->queue >= bp->rx_nr_rings) {
3127 PMD_DRV_LOG(ERR, "Invalid queue %d\n", nfilter->queue);
3131 switch (nfilter->dst_port_mask) {
3133 bfilter->dst_port_mask = -1;
3134 bfilter->dst_port = nfilter->dst_port;
3135 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT |
3136 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3139 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3143 bfilter->ip_addr_type = NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3144 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3146 switch (nfilter->proto_mask) {
3148 if (nfilter->proto == 17) /* IPPROTO_UDP */
3149 bfilter->ip_protocol = 17;
3150 else if (nfilter->proto == 6) /* IPPROTO_TCP */
3151 bfilter->ip_protocol = 6;
3154 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3157 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3161 switch (nfilter->dst_ip_mask) {
3163 bfilter->dst_ipaddr_mask[0] = -1;
3164 bfilter->dst_ipaddr[0] = nfilter->dst_ip;
3165 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR |
3166 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3169 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
3173 switch (nfilter->src_ip_mask) {
3175 bfilter->src_ipaddr_mask[0] = -1;
3176 bfilter->src_ipaddr[0] = nfilter->src_ip;
3177 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR |
3178 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3181 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
3185 switch (nfilter->src_port_mask) {
3187 bfilter->src_port_mask = -1;
3188 bfilter->src_port = nfilter->src_port;
3189 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT |
3190 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3193 PMD_DRV_LOG(ERR, "invalid src_port mask.");
3197 bfilter->enables = en;
3201 static struct bnxt_filter_info*
3202 bnxt_match_ntuple_filter(struct bnxt *bp,
3203 struct bnxt_filter_info *bfilter,
3204 struct bnxt_vnic_info **mvnic)
3206 struct bnxt_filter_info *mfilter = NULL;
3209 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3210 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3211 STAILQ_FOREACH(mfilter, &vnic->filter, next) {
3212 if (bfilter->src_ipaddr[0] == mfilter->src_ipaddr[0] &&
3213 bfilter->src_ipaddr_mask[0] ==
3214 mfilter->src_ipaddr_mask[0] &&
3215 bfilter->src_port == mfilter->src_port &&
3216 bfilter->src_port_mask == mfilter->src_port_mask &&
3217 bfilter->dst_ipaddr[0] == mfilter->dst_ipaddr[0] &&
3218 bfilter->dst_ipaddr_mask[0] ==
3219 mfilter->dst_ipaddr_mask[0] &&
3220 bfilter->dst_port == mfilter->dst_port &&
3221 bfilter->dst_port_mask == mfilter->dst_port_mask &&
3222 bfilter->flags == mfilter->flags &&
3223 bfilter->enables == mfilter->enables) {
3234 bnxt_cfg_ntuple_filter(struct bnxt *bp,
3235 struct rte_eth_ntuple_filter *nfilter,
3236 enum rte_filter_op filter_op)
3238 struct bnxt_filter_info *bfilter, *mfilter, *filter1;
3239 struct bnxt_vnic_info *vnic, *vnic0, *mvnic;
3242 if (nfilter->flags != RTE_5TUPLE_FLAGS) {
3243 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
3247 if (nfilter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
3248 PMD_DRV_LOG(ERR, "Ntuple filter: TCP flags not supported\n");
3252 bfilter = bnxt_get_unused_filter(bp);
3253 if (bfilter == NULL) {
3255 "Not enough resources for a new filter.\n");
3258 ret = parse_ntuple_filter(bp, nfilter, bfilter);
3262 vnic = &bp->vnic_info[nfilter->queue];
3263 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3264 filter1 = STAILQ_FIRST(&vnic0->filter);
3265 if (filter1 == NULL) {
3270 bfilter->dst_id = vnic->fw_vnic_id;
3271 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3273 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3274 bfilter->ethertype = 0x800;
3275 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3277 mfilter = bnxt_match_ntuple_filter(bp, bfilter, &mvnic);
3279 if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
3280 bfilter->dst_id == mfilter->dst_id) {
3281 PMD_DRV_LOG(ERR, "filter exists.\n");
3284 } else if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
3285 bfilter->dst_id != mfilter->dst_id) {
3286 mfilter->dst_id = vnic->fw_vnic_id;
3287 ret = bnxt_hwrm_set_ntuple_filter(bp, mfilter->dst_id, mfilter);
3288 STAILQ_REMOVE(&mvnic->filter, mfilter, bnxt_filter_info, next);
3289 STAILQ_INSERT_TAIL(&vnic->filter, mfilter, next);
3290 PMD_DRV_LOG(ERR, "filter with matching pattern exists.\n");
3291 PMD_DRV_LOG(ERR, " Updated it to the new destination queue\n");
3294 if (mfilter == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
3295 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3300 if (filter_op == RTE_ETH_FILTER_ADD) {
3301 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3302 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
3305 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
3307 if (mfilter == NULL) {
3308 /* This should not happen. But for Coverity! */
3312 ret = bnxt_hwrm_clear_ntuple_filter(bp, mfilter);
3314 STAILQ_REMOVE(&vnic->filter, mfilter, bnxt_filter_info, next);
3315 bnxt_free_filter(bp, mfilter);
3316 bnxt_free_filter(bp, bfilter);
3321 bnxt_free_filter(bp, bfilter);
3326 bnxt_ntuple_filter(struct rte_eth_dev *dev,
3327 enum rte_filter_op filter_op,
3330 struct bnxt *bp = dev->data->dev_private;
3333 if (filter_op == RTE_ETH_FILTER_NOP)
3337 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3342 switch (filter_op) {
3343 case RTE_ETH_FILTER_ADD:
3344 ret = bnxt_cfg_ntuple_filter(bp,
3345 (struct rte_eth_ntuple_filter *)arg,
3348 case RTE_ETH_FILTER_DELETE:
3349 ret = bnxt_cfg_ntuple_filter(bp,
3350 (struct rte_eth_ntuple_filter *)arg,
3354 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3362 bnxt_parse_fdir_filter(struct bnxt *bp,
3363 struct rte_eth_fdir_filter *fdir,
3364 struct bnxt_filter_info *filter)
3366 enum rte_fdir_mode fdir_mode =
3367 bp->eth_dev->data->dev_conf.fdir_conf.mode;
3368 struct bnxt_vnic_info *vnic0, *vnic;
3369 struct bnxt_filter_info *filter1;
3373 if (fdir_mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3376 filter->l2_ovlan = fdir->input.flow_ext.vlan_tci;
3377 en |= EM_FLOW_ALLOC_INPUT_EN_OVLAN_VID;
3379 switch (fdir->input.flow_type) {
3380 case RTE_ETH_FLOW_IPV4:
3381 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
3383 filter->src_ipaddr[0] = fdir->input.flow.ip4_flow.src_ip;
3384 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3385 filter->dst_ipaddr[0] = fdir->input.flow.ip4_flow.dst_ip;
3386 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3387 filter->ip_protocol = fdir->input.flow.ip4_flow.proto;
3388 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3389 filter->ip_addr_type =
3390 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3391 filter->src_ipaddr_mask[0] = 0xffffffff;
3392 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3393 filter->dst_ipaddr_mask[0] = 0xffffffff;
3394 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3395 filter->ethertype = 0x800;
3396 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3398 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
3399 filter->src_port = fdir->input.flow.tcp4_flow.src_port;
3400 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3401 filter->dst_port = fdir->input.flow.tcp4_flow.dst_port;
3402 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3403 filter->dst_port_mask = 0xffff;
3404 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3405 filter->src_port_mask = 0xffff;
3406 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3407 filter->src_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.src_ip;
3408 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3409 filter->dst_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.dst_ip;
3410 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3411 filter->ip_protocol = 6;
3412 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3413 filter->ip_addr_type =
3414 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3415 filter->src_ipaddr_mask[0] = 0xffffffff;
3416 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3417 filter->dst_ipaddr_mask[0] = 0xffffffff;
3418 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3419 filter->ethertype = 0x800;
3420 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3422 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
3423 filter->src_port = fdir->input.flow.udp4_flow.src_port;
3424 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3425 filter->dst_port = fdir->input.flow.udp4_flow.dst_port;
3426 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3427 filter->dst_port_mask = 0xffff;
3428 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3429 filter->src_port_mask = 0xffff;
3430 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3431 filter->src_ipaddr[0] = fdir->input.flow.udp4_flow.ip.src_ip;
3432 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3433 filter->dst_ipaddr[0] = fdir->input.flow.udp4_flow.ip.dst_ip;
3434 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3435 filter->ip_protocol = 17;
3436 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3437 filter->ip_addr_type =
3438 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3439 filter->src_ipaddr_mask[0] = 0xffffffff;
3440 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3441 filter->dst_ipaddr_mask[0] = 0xffffffff;
3442 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3443 filter->ethertype = 0x800;
3444 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3446 case RTE_ETH_FLOW_IPV6:
3447 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
3449 filter->ip_addr_type =
3450 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3451 filter->ip_protocol = fdir->input.flow.ipv6_flow.proto;
3452 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3453 rte_memcpy(filter->src_ipaddr,
3454 fdir->input.flow.ipv6_flow.src_ip, 16);
3455 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3456 rte_memcpy(filter->dst_ipaddr,
3457 fdir->input.flow.ipv6_flow.dst_ip, 16);
3458 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3459 memset(filter->dst_ipaddr_mask, 0xff, 16);
3460 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3461 memset(filter->src_ipaddr_mask, 0xff, 16);
3462 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3463 filter->ethertype = 0x86dd;
3464 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3466 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
3467 filter->src_port = fdir->input.flow.tcp6_flow.src_port;
3468 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3469 filter->dst_port = fdir->input.flow.tcp6_flow.dst_port;
3470 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3471 filter->dst_port_mask = 0xffff;
3472 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3473 filter->src_port_mask = 0xffff;
3474 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3475 filter->ip_addr_type =
3476 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3477 filter->ip_protocol = fdir->input.flow.tcp6_flow.ip.proto;
3478 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3479 rte_memcpy(filter->src_ipaddr,
3480 fdir->input.flow.tcp6_flow.ip.src_ip, 16);
3481 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3482 rte_memcpy(filter->dst_ipaddr,
3483 fdir->input.flow.tcp6_flow.ip.dst_ip, 16);
3484 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3485 memset(filter->dst_ipaddr_mask, 0xff, 16);
3486 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3487 memset(filter->src_ipaddr_mask, 0xff, 16);
3488 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3489 filter->ethertype = 0x86dd;
3490 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3492 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
3493 filter->src_port = fdir->input.flow.udp6_flow.src_port;
3494 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3495 filter->dst_port = fdir->input.flow.udp6_flow.dst_port;
3496 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3497 filter->dst_port_mask = 0xffff;
3498 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3499 filter->src_port_mask = 0xffff;
3500 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3501 filter->ip_addr_type =
3502 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3503 filter->ip_protocol = fdir->input.flow.udp6_flow.ip.proto;
3504 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3505 rte_memcpy(filter->src_ipaddr,
3506 fdir->input.flow.udp6_flow.ip.src_ip, 16);
3507 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3508 rte_memcpy(filter->dst_ipaddr,
3509 fdir->input.flow.udp6_flow.ip.dst_ip, 16);
3510 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3511 memset(filter->dst_ipaddr_mask, 0xff, 16);
3512 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3513 memset(filter->src_ipaddr_mask, 0xff, 16);
3514 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3515 filter->ethertype = 0x86dd;
3516 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3518 case RTE_ETH_FLOW_L2_PAYLOAD:
3519 filter->ethertype = fdir->input.flow.l2_flow.ether_type;
3520 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3522 case RTE_ETH_FLOW_VXLAN:
3523 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3525 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
3526 filter->tunnel_type =
3527 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN;
3528 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
3530 case RTE_ETH_FLOW_NVGRE:
3531 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3533 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
3534 filter->tunnel_type =
3535 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_NVGRE;
3536 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
3538 case RTE_ETH_FLOW_UNKNOWN:
3539 case RTE_ETH_FLOW_RAW:
3540 case RTE_ETH_FLOW_FRAG_IPV4:
3541 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
3542 case RTE_ETH_FLOW_FRAG_IPV6:
3543 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
3544 case RTE_ETH_FLOW_IPV6_EX:
3545 case RTE_ETH_FLOW_IPV6_TCP_EX:
3546 case RTE_ETH_FLOW_IPV6_UDP_EX:
3547 case RTE_ETH_FLOW_GENEVE:
3553 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3554 vnic = &bp->vnic_info[fdir->action.rx_queue];
3556 PMD_DRV_LOG(ERR, "Invalid queue %d\n", fdir->action.rx_queue);
3560 if (fdir_mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3561 rte_memcpy(filter->dst_macaddr,
3562 fdir->input.flow.mac_vlan_flow.mac_addr.addr_bytes, 6);
3563 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
3566 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT) {
3567 filter->flags = HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
3568 filter1 = STAILQ_FIRST(&vnic0->filter);
3569 //filter1 = bnxt_get_l2_filter(bp, filter, vnic0);
3571 filter->dst_id = vnic->fw_vnic_id;
3572 for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
3573 if (filter->dst_macaddr[i] == 0x00)
3574 filter1 = STAILQ_FIRST(&vnic0->filter);
3576 filter1 = bnxt_get_l2_filter(bp, filter, vnic);
3579 if (filter1 == NULL)
3582 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3583 filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3585 filter->enables = en;
3590 static struct bnxt_filter_info *
3591 bnxt_match_fdir(struct bnxt *bp, struct bnxt_filter_info *nf,
3592 struct bnxt_vnic_info **mvnic)
3594 struct bnxt_filter_info *mf = NULL;
3597 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3598 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3600 STAILQ_FOREACH(mf, &vnic->filter, next) {
3601 if (mf->filter_type == nf->filter_type &&
3602 mf->flags == nf->flags &&
3603 mf->src_port == nf->src_port &&
3604 mf->src_port_mask == nf->src_port_mask &&
3605 mf->dst_port == nf->dst_port &&
3606 mf->dst_port_mask == nf->dst_port_mask &&
3607 mf->ip_protocol == nf->ip_protocol &&
3608 mf->ip_addr_type == nf->ip_addr_type &&
3609 mf->ethertype == nf->ethertype &&
3610 mf->vni == nf->vni &&
3611 mf->tunnel_type == nf->tunnel_type &&
3612 mf->l2_ovlan == nf->l2_ovlan &&
3613 mf->l2_ovlan_mask == nf->l2_ovlan_mask &&
3614 mf->l2_ivlan == nf->l2_ivlan &&
3615 mf->l2_ivlan_mask == nf->l2_ivlan_mask &&
3616 !memcmp(mf->l2_addr, nf->l2_addr,
3617 RTE_ETHER_ADDR_LEN) &&
3618 !memcmp(mf->l2_addr_mask, nf->l2_addr_mask,
3619 RTE_ETHER_ADDR_LEN) &&
3620 !memcmp(mf->src_macaddr, nf->src_macaddr,
3621 RTE_ETHER_ADDR_LEN) &&
3622 !memcmp(mf->dst_macaddr, nf->dst_macaddr,
3623 RTE_ETHER_ADDR_LEN) &&
3624 !memcmp(mf->src_ipaddr, nf->src_ipaddr,
3625 sizeof(nf->src_ipaddr)) &&
3626 !memcmp(mf->src_ipaddr_mask, nf->src_ipaddr_mask,
3627 sizeof(nf->src_ipaddr_mask)) &&
3628 !memcmp(mf->dst_ipaddr, nf->dst_ipaddr,
3629 sizeof(nf->dst_ipaddr)) &&
3630 !memcmp(mf->dst_ipaddr_mask, nf->dst_ipaddr_mask,
3631 sizeof(nf->dst_ipaddr_mask))) {
3642 bnxt_fdir_filter(struct rte_eth_dev *dev,
3643 enum rte_filter_op filter_op,
3646 struct bnxt *bp = dev->data->dev_private;
3647 struct rte_eth_fdir_filter *fdir = (struct rte_eth_fdir_filter *)arg;
3648 struct bnxt_filter_info *filter, *match;
3649 struct bnxt_vnic_info *vnic, *mvnic;
3652 if (filter_op == RTE_ETH_FILTER_NOP)
3655 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
3658 switch (filter_op) {
3659 case RTE_ETH_FILTER_ADD:
3660 case RTE_ETH_FILTER_DELETE:
3662 filter = bnxt_get_unused_filter(bp);
3663 if (filter == NULL) {
3665 "Not enough resources for a new flow.\n");
3669 ret = bnxt_parse_fdir_filter(bp, fdir, filter);
3672 filter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3674 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3675 vnic = &bp->vnic_info[0];
3677 vnic = &bp->vnic_info[fdir->action.rx_queue];
3679 match = bnxt_match_fdir(bp, filter, &mvnic);
3680 if (match != NULL && filter_op == RTE_ETH_FILTER_ADD) {
3681 if (match->dst_id == vnic->fw_vnic_id) {
3682 PMD_DRV_LOG(ERR, "Flow already exists.\n");
3686 match->dst_id = vnic->fw_vnic_id;
3687 ret = bnxt_hwrm_set_ntuple_filter(bp,
3690 STAILQ_REMOVE(&mvnic->filter, match,
3691 bnxt_filter_info, next);
3692 STAILQ_INSERT_TAIL(&vnic->filter, match, next);
3694 "Filter with matching pattern exist\n");
3696 "Updated it to new destination q\n");
3700 if (match == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
3701 PMD_DRV_LOG(ERR, "Flow does not exist.\n");
3706 if (filter_op == RTE_ETH_FILTER_ADD) {
3707 ret = bnxt_hwrm_set_ntuple_filter(bp,
3712 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
3714 ret = bnxt_hwrm_clear_ntuple_filter(bp, match);
3715 STAILQ_REMOVE(&vnic->filter, match,
3716 bnxt_filter_info, next);
3717 bnxt_free_filter(bp, match);
3718 bnxt_free_filter(bp, filter);
3721 case RTE_ETH_FILTER_FLUSH:
3722 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3723 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3725 STAILQ_FOREACH(filter, &vnic->filter, next) {
3726 if (filter->filter_type ==
3727 HWRM_CFA_NTUPLE_FILTER) {
3729 bnxt_hwrm_clear_ntuple_filter(bp,
3731 STAILQ_REMOVE(&vnic->filter, filter,
3732 bnxt_filter_info, next);
3737 case RTE_ETH_FILTER_UPDATE:
3738 case RTE_ETH_FILTER_STATS:
3739 case RTE_ETH_FILTER_INFO:
3740 PMD_DRV_LOG(ERR, "operation %u not implemented", filter_op);
3743 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
3750 bnxt_free_filter(bp, filter);
3755 bnxt_filter_ctrl_op(struct rte_eth_dev *dev,
3756 enum rte_filter_type filter_type,
3757 enum rte_filter_op filter_op, void *arg)
3759 struct bnxt *bp = dev->data->dev_private;
3762 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
3763 struct bnxt_vf_representor *vfr = dev->data->dev_private;
3764 bp = vfr->parent_dev->data->dev_private;
3767 ret = is_bnxt_in_error(bp);
3771 switch (filter_type) {
3772 case RTE_ETH_FILTER_TUNNEL:
3774 "filter type: %d: To be implemented\n", filter_type);
3776 case RTE_ETH_FILTER_FDIR:
3777 ret = bnxt_fdir_filter(dev, filter_op, arg);
3779 case RTE_ETH_FILTER_NTUPLE:
3780 ret = bnxt_ntuple_filter(dev, filter_op, arg);
3782 case RTE_ETH_FILTER_ETHERTYPE:
3783 ret = bnxt_ethertype_filter(dev, filter_op, arg);
3785 case RTE_ETH_FILTER_GENERIC:
3786 if (filter_op != RTE_ETH_FILTER_GET)
3788 if (BNXT_TRUFLOW_EN(bp))
3789 *(const void **)arg = &bnxt_ulp_rte_flow_ops;
3791 *(const void **)arg = &bnxt_flow_ops;
3795 "Filter type (%d) not supported", filter_type);
3802 static const uint32_t *
3803 bnxt_dev_supported_ptypes_get_op(struct rte_eth_dev *dev)
3805 static const uint32_t ptypes[] = {
3806 RTE_PTYPE_L2_ETHER_VLAN,
3807 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
3808 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
3812 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
3813 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
3814 RTE_PTYPE_INNER_L4_ICMP,
3815 RTE_PTYPE_INNER_L4_TCP,
3816 RTE_PTYPE_INNER_L4_UDP,
3820 if (!dev->rx_pkt_burst)
3826 static int bnxt_map_regs(struct bnxt *bp, uint32_t *reg_arr, int count,
3829 uint32_t reg_base = *reg_arr & 0xfffff000;
3833 for (i = 0; i < count; i++) {
3834 if ((reg_arr[i] & 0xfffff000) != reg_base)
3837 win_off = BNXT_GRCPF_REG_WINDOW_BASE_OUT + (reg_win - 1) * 4;
3838 rte_write32(reg_base, (uint8_t *)bp->bar0 + win_off);
3842 static int bnxt_map_ptp_regs(struct bnxt *bp)
3844 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3848 reg_arr = ptp->rx_regs;
3849 rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_RX_REGS, 5);
3853 reg_arr = ptp->tx_regs;
3854 rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_TX_REGS, 6);
3858 for (i = 0; i < BNXT_PTP_RX_REGS; i++)
3859 ptp->rx_mapped_regs[i] = 0x5000 + (ptp->rx_regs[i] & 0xfff);
3861 for (i = 0; i < BNXT_PTP_TX_REGS; i++)
3862 ptp->tx_mapped_regs[i] = 0x6000 + (ptp->tx_regs[i] & 0xfff);
3867 static void bnxt_unmap_ptp_regs(struct bnxt *bp)
3869 rte_write32(0, (uint8_t *)bp->bar0 +
3870 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 16);
3871 rte_write32(0, (uint8_t *)bp->bar0 +
3872 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 20);
3875 static uint64_t bnxt_cc_read(struct bnxt *bp)
3879 ns = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3880 BNXT_GRCPF_REG_SYNC_TIME));
3881 ns |= (uint64_t)(rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3882 BNXT_GRCPF_REG_SYNC_TIME + 4))) << 32;
3886 static int bnxt_get_tx_ts(struct bnxt *bp, uint64_t *ts)
3888 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3891 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3892 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3893 if (fifo & BNXT_PTP_TX_FIFO_EMPTY)
3896 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3897 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3898 *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3899 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_L]));
3900 *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3901 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_H])) << 32;
3906 static int bnxt_get_rx_ts(struct bnxt *bp, uint64_t *ts)
3908 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3909 struct bnxt_pf_info *pf = bp->pf;
3916 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3917 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3918 if (!(fifo & BNXT_PTP_RX_FIFO_PENDING))
3921 port_id = pf->port_id;
3922 rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
3923 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
3925 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3926 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3927 if (fifo & BNXT_PTP_RX_FIFO_PENDING) {
3928 /* bnxt_clr_rx_ts(bp); TBD */
3932 *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3933 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
3934 *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3935 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
3941 bnxt_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
3944 struct bnxt *bp = dev->data->dev_private;
3945 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3950 ns = rte_timespec_to_ns(ts);
3951 /* Set the timecounters to a new value. */
3958 bnxt_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
3960 struct bnxt *bp = dev->data->dev_private;
3961 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3962 uint64_t ns, systime_cycles = 0;
3968 if (BNXT_CHIP_THOR(bp))
3969 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
3972 systime_cycles = bnxt_cc_read(bp);
3974 ns = rte_timecounter_update(&ptp->tc, systime_cycles);
3975 *ts = rte_ns_to_timespec(ns);
3980 bnxt_timesync_enable(struct rte_eth_dev *dev)
3982 struct bnxt *bp = dev->data->dev_private;
3983 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3991 ptp->tx_tstamp_en = 1;
3992 ptp->rxctl = BNXT_PTP_MSG_EVENTS;
3994 rc = bnxt_hwrm_ptp_cfg(bp);
3998 memset(&ptp->tc, 0, sizeof(struct rte_timecounter));
3999 memset(&ptp->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4000 memset(&ptp->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4002 ptp->tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
4003 ptp->tc.cc_shift = shift;
4004 ptp->tc.nsec_mask = (1ULL << shift) - 1;
4006 ptp->rx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
4007 ptp->rx_tstamp_tc.cc_shift = shift;
4008 ptp->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4010 ptp->tx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
4011 ptp->tx_tstamp_tc.cc_shift = shift;
4012 ptp->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4014 if (!BNXT_CHIP_THOR(bp))
4015 bnxt_map_ptp_regs(bp);
4021 bnxt_timesync_disable(struct rte_eth_dev *dev)
4023 struct bnxt *bp = dev->data->dev_private;
4024 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4030 ptp->tx_tstamp_en = 0;
4033 bnxt_hwrm_ptp_cfg(bp);
4035 if (!BNXT_CHIP_THOR(bp))
4036 bnxt_unmap_ptp_regs(bp);
4042 bnxt_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4043 struct timespec *timestamp,
4044 uint32_t flags __rte_unused)
4046 struct bnxt *bp = dev->data->dev_private;
4047 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4048 uint64_t rx_tstamp_cycles = 0;
4054 if (BNXT_CHIP_THOR(bp))
4055 rx_tstamp_cycles = ptp->rx_timestamp;
4057 bnxt_get_rx_ts(bp, &rx_tstamp_cycles);
4059 ns = rte_timecounter_update(&ptp->rx_tstamp_tc, rx_tstamp_cycles);
4060 *timestamp = rte_ns_to_timespec(ns);
4065 bnxt_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
4066 struct timespec *timestamp)
4068 struct bnxt *bp = dev->data->dev_private;
4069 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4070 uint64_t tx_tstamp_cycles = 0;
4077 if (BNXT_CHIP_THOR(bp))
4078 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_PATH_TX,
4081 rc = bnxt_get_tx_ts(bp, &tx_tstamp_cycles);
4083 ns = rte_timecounter_update(&ptp->tx_tstamp_tc, tx_tstamp_cycles);
4084 *timestamp = rte_ns_to_timespec(ns);
4090 bnxt_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4092 struct bnxt *bp = dev->data->dev_private;
4093 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4098 ptp->tc.nsec += delta;
4104 bnxt_get_eeprom_length_op(struct rte_eth_dev *dev)
4106 struct bnxt *bp = dev->data->dev_private;
4108 uint32_t dir_entries;
4109 uint32_t entry_length;
4111 rc = is_bnxt_in_error(bp);
4115 PMD_DRV_LOG(INFO, PCI_PRI_FMT "\n",
4116 bp->pdev->addr.domain, bp->pdev->addr.bus,
4117 bp->pdev->addr.devid, bp->pdev->addr.function);
4119 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
4123 return dir_entries * entry_length;
4127 bnxt_get_eeprom_op(struct rte_eth_dev *dev,
4128 struct rte_dev_eeprom_info *in_eeprom)
4130 struct bnxt *bp = dev->data->dev_private;
4135 rc = is_bnxt_in_error(bp);
4139 PMD_DRV_LOG(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d\n",
4140 bp->pdev->addr.domain, bp->pdev->addr.bus,
4141 bp->pdev->addr.devid, bp->pdev->addr.function,
4142 in_eeprom->offset, in_eeprom->length);
4144 if (in_eeprom->offset == 0) /* special offset value to get directory */
4145 return bnxt_get_nvram_directory(bp, in_eeprom->length,
4148 index = in_eeprom->offset >> 24;
4149 offset = in_eeprom->offset & 0xffffff;
4152 return bnxt_hwrm_get_nvram_item(bp, index - 1, offset,
4153 in_eeprom->length, in_eeprom->data);
4158 static bool bnxt_dir_type_is_ape_bin_format(uint16_t dir_type)
4161 case BNX_DIR_TYPE_CHIMP_PATCH:
4162 case BNX_DIR_TYPE_BOOTCODE:
4163 case BNX_DIR_TYPE_BOOTCODE_2:
4164 case BNX_DIR_TYPE_APE_FW:
4165 case BNX_DIR_TYPE_APE_PATCH:
4166 case BNX_DIR_TYPE_KONG_FW:
4167 case BNX_DIR_TYPE_KONG_PATCH:
4168 case BNX_DIR_TYPE_BONO_FW:
4169 case BNX_DIR_TYPE_BONO_PATCH:
4177 static bool bnxt_dir_type_is_other_exec_format(uint16_t dir_type)
4180 case BNX_DIR_TYPE_AVS:
4181 case BNX_DIR_TYPE_EXP_ROM_MBA:
4182 case BNX_DIR_TYPE_PCIE:
4183 case BNX_DIR_TYPE_TSCF_UCODE:
4184 case BNX_DIR_TYPE_EXT_PHY:
4185 case BNX_DIR_TYPE_CCM:
4186 case BNX_DIR_TYPE_ISCSI_BOOT:
4187 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
4188 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
4196 static bool bnxt_dir_type_is_executable(uint16_t dir_type)
4198 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
4199 bnxt_dir_type_is_other_exec_format(dir_type);
4203 bnxt_set_eeprom_op(struct rte_eth_dev *dev,
4204 struct rte_dev_eeprom_info *in_eeprom)
4206 struct bnxt *bp = dev->data->dev_private;
4207 uint8_t index, dir_op;
4208 uint16_t type, ext, ordinal, attr;
4211 rc = is_bnxt_in_error(bp);
4215 PMD_DRV_LOG(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d\n",
4216 bp->pdev->addr.domain, bp->pdev->addr.bus,
4217 bp->pdev->addr.devid, bp->pdev->addr.function,
4218 in_eeprom->offset, in_eeprom->length);
4221 PMD_DRV_LOG(ERR, "NVM write not supported from a VF\n");
4225 type = in_eeprom->magic >> 16;
4227 if (type == 0xffff) { /* special value for directory operations */
4228 index = in_eeprom->magic & 0xff;
4229 dir_op = in_eeprom->magic >> 8;
4233 case 0x0e: /* erase */
4234 if (in_eeprom->offset != ~in_eeprom->magic)
4236 return bnxt_hwrm_erase_nvram_directory(bp, index - 1);
4242 /* Create or re-write an NVM item: */
4243 if (bnxt_dir_type_is_executable(type) == true)
4245 ext = in_eeprom->magic & 0xffff;
4246 ordinal = in_eeprom->offset >> 16;
4247 attr = in_eeprom->offset & 0xffff;
4249 return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
4250 in_eeprom->data, in_eeprom->length);
4257 static const struct eth_dev_ops bnxt_dev_ops = {
4258 .dev_infos_get = bnxt_dev_info_get_op,
4259 .dev_close = bnxt_dev_close_op,
4260 .dev_configure = bnxt_dev_configure_op,
4261 .dev_start = bnxt_dev_start_op,
4262 .dev_stop = bnxt_dev_stop_op,
4263 .dev_set_link_up = bnxt_dev_set_link_up_op,
4264 .dev_set_link_down = bnxt_dev_set_link_down_op,
4265 .stats_get = bnxt_stats_get_op,
4266 .stats_reset = bnxt_stats_reset_op,
4267 .rx_queue_setup = bnxt_rx_queue_setup_op,
4268 .rx_queue_release = bnxt_rx_queue_release_op,
4269 .tx_queue_setup = bnxt_tx_queue_setup_op,
4270 .tx_queue_release = bnxt_tx_queue_release_op,
4271 .rx_queue_intr_enable = bnxt_rx_queue_intr_enable_op,
4272 .rx_queue_intr_disable = bnxt_rx_queue_intr_disable_op,
4273 .reta_update = bnxt_reta_update_op,
4274 .reta_query = bnxt_reta_query_op,
4275 .rss_hash_update = bnxt_rss_hash_update_op,
4276 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
4277 .link_update = bnxt_link_update_op,
4278 .promiscuous_enable = bnxt_promiscuous_enable_op,
4279 .promiscuous_disable = bnxt_promiscuous_disable_op,
4280 .allmulticast_enable = bnxt_allmulticast_enable_op,
4281 .allmulticast_disable = bnxt_allmulticast_disable_op,
4282 .mac_addr_add = bnxt_mac_addr_add_op,
4283 .mac_addr_remove = bnxt_mac_addr_remove_op,
4284 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
4285 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
4286 .udp_tunnel_port_add = bnxt_udp_tunnel_port_add_op,
4287 .udp_tunnel_port_del = bnxt_udp_tunnel_port_del_op,
4288 .vlan_filter_set = bnxt_vlan_filter_set_op,
4289 .vlan_offload_set = bnxt_vlan_offload_set_op,
4290 .vlan_tpid_set = bnxt_vlan_tpid_set_op,
4291 .vlan_pvid_set = bnxt_vlan_pvid_set_op,
4292 .mtu_set = bnxt_mtu_set_op,
4293 .mac_addr_set = bnxt_set_default_mac_addr_op,
4294 .xstats_get = bnxt_dev_xstats_get_op,
4295 .xstats_get_names = bnxt_dev_xstats_get_names_op,
4296 .xstats_reset = bnxt_dev_xstats_reset_op,
4297 .fw_version_get = bnxt_fw_version_get,
4298 .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
4299 .rxq_info_get = bnxt_rxq_info_get_op,
4300 .txq_info_get = bnxt_txq_info_get_op,
4301 .rx_burst_mode_get = bnxt_rx_burst_mode_get,
4302 .tx_burst_mode_get = bnxt_tx_burst_mode_get,
4303 .dev_led_on = bnxt_dev_led_on_op,
4304 .dev_led_off = bnxt_dev_led_off_op,
4305 .xstats_get_by_id = bnxt_dev_xstats_get_by_id_op,
4306 .xstats_get_names_by_id = bnxt_dev_xstats_get_names_by_id_op,
4307 .rx_queue_count = bnxt_rx_queue_count_op,
4308 .rx_descriptor_status = bnxt_rx_descriptor_status_op,
4309 .tx_descriptor_status = bnxt_tx_descriptor_status_op,
4310 .rx_queue_start = bnxt_rx_queue_start,
4311 .rx_queue_stop = bnxt_rx_queue_stop,
4312 .tx_queue_start = bnxt_tx_queue_start,
4313 .tx_queue_stop = bnxt_tx_queue_stop,
4314 .filter_ctrl = bnxt_filter_ctrl_op,
4315 .dev_supported_ptypes_get = bnxt_dev_supported_ptypes_get_op,
4316 .get_eeprom_length = bnxt_get_eeprom_length_op,
4317 .get_eeprom = bnxt_get_eeprom_op,
4318 .set_eeprom = bnxt_set_eeprom_op,
4319 .timesync_enable = bnxt_timesync_enable,
4320 .timesync_disable = bnxt_timesync_disable,
4321 .timesync_read_time = bnxt_timesync_read_time,
4322 .timesync_write_time = bnxt_timesync_write_time,
4323 .timesync_adjust_time = bnxt_timesync_adjust_time,
4324 .timesync_read_rx_timestamp = bnxt_timesync_read_rx_timestamp,
4325 .timesync_read_tx_timestamp = bnxt_timesync_read_tx_timestamp,
4328 static uint32_t bnxt_map_reset_regs(struct bnxt *bp, uint32_t reg)
4332 /* Only pre-map the reset GRC registers using window 3 */
4333 rte_write32(reg & 0xfffff000, (uint8_t *)bp->bar0 +
4334 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 8);
4336 offset = BNXT_GRCP_WINDOW_3_BASE + (reg & 0xffc);
4341 int bnxt_map_fw_health_status_regs(struct bnxt *bp)
4343 struct bnxt_error_recovery_info *info = bp->recovery_info;
4344 uint32_t reg_base = 0xffffffff;
4347 /* Only pre-map the monitoring GRC registers using window 2 */
4348 for (i = 0; i < BNXT_FW_STATUS_REG_CNT; i++) {
4349 uint32_t reg = info->status_regs[i];
4351 if (BNXT_FW_STATUS_REG_TYPE(reg) != BNXT_FW_STATUS_REG_TYPE_GRC)
4354 if (reg_base == 0xffffffff)
4355 reg_base = reg & 0xfffff000;
4356 if ((reg & 0xfffff000) != reg_base)
4359 /* Use mask 0xffc as the Lower 2 bits indicates
4360 * address space location
4362 info->mapped_status_regs[i] = BNXT_GRCP_WINDOW_2_BASE +
4366 if (reg_base == 0xffffffff)
4369 rte_write32(reg_base, (uint8_t *)bp->bar0 +
4370 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
4375 static void bnxt_write_fw_reset_reg(struct bnxt *bp, uint32_t index)
4377 struct bnxt_error_recovery_info *info = bp->recovery_info;
4378 uint32_t delay = info->delay_after_reset[index];
4379 uint32_t val = info->reset_reg_val[index];
4380 uint32_t reg = info->reset_reg[index];
4381 uint32_t type, offset;
4383 type = BNXT_FW_STATUS_REG_TYPE(reg);
4384 offset = BNXT_FW_STATUS_REG_OFF(reg);
4387 case BNXT_FW_STATUS_REG_TYPE_CFG:
4388 rte_pci_write_config(bp->pdev, &val, sizeof(val), offset);
4390 case BNXT_FW_STATUS_REG_TYPE_GRC:
4391 offset = bnxt_map_reset_regs(bp, offset);
4392 rte_write32(val, (uint8_t *)bp->bar0 + offset);
4394 case BNXT_FW_STATUS_REG_TYPE_BAR0:
4395 rte_write32(val, (uint8_t *)bp->bar0 + offset);
4398 /* wait on a specific interval of time until core reset is complete */
4400 rte_delay_ms(delay);
4403 static void bnxt_dev_cleanup(struct bnxt *bp)
4405 bnxt_set_hwrm_link_config(bp, false);
4406 bp->link_info->link_up = 0;
4407 if (bp->eth_dev->data->dev_started)
4408 bnxt_dev_stop_op(bp->eth_dev);
4410 bnxt_uninit_resources(bp, true);
4413 static int bnxt_restore_vlan_filters(struct bnxt *bp)
4415 struct rte_eth_dev *dev = bp->eth_dev;
4416 struct rte_vlan_filter_conf *vfc;
4420 for (vlan_id = 1; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
4421 vfc = &dev->data->vlan_filter_conf;
4422 vidx = vlan_id / 64;
4423 vbit = vlan_id % 64;
4425 /* Each bit corresponds to a VLAN id */
4426 if (vfc->ids[vidx] & (UINT64_C(1) << vbit)) {
4427 rc = bnxt_add_vlan_filter(bp, vlan_id);
4436 static int bnxt_restore_mac_filters(struct bnxt *bp)
4438 struct rte_eth_dev *dev = bp->eth_dev;
4439 struct rte_eth_dev_info dev_info;
4440 struct rte_ether_addr *addr;
4446 if (BNXT_VF(bp) & !BNXT_VF_IS_TRUSTED(bp))
4449 rc = bnxt_dev_info_get_op(dev, &dev_info);
4453 /* replay MAC address configuration */
4454 for (i = 1; i < dev_info.max_mac_addrs; i++) {
4455 addr = &dev->data->mac_addrs[i];
4457 /* skip zero address */
4458 if (rte_is_zero_ether_addr(addr))
4462 pool_mask = dev->data->mac_pool_sel[i];
4465 if (pool_mask & 1ULL) {
4466 rc = bnxt_mac_addr_add_op(dev, addr, i, pool);
4472 } while (pool_mask);
4478 static int bnxt_restore_filters(struct bnxt *bp)
4480 struct rte_eth_dev *dev = bp->eth_dev;
4483 if (dev->data->all_multicast) {
4484 ret = bnxt_allmulticast_enable_op(dev);
4488 if (dev->data->promiscuous) {
4489 ret = bnxt_promiscuous_enable_op(dev);
4494 ret = bnxt_restore_mac_filters(bp);
4498 ret = bnxt_restore_vlan_filters(bp);
4499 /* TODO restore other filters as well */
4503 static void bnxt_dev_recover(void *arg)
4505 struct bnxt *bp = arg;
4506 int timeout = bp->fw_reset_max_msecs;
4509 /* Clear Error flag so that device re-init should happen */
4510 bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
4513 rc = bnxt_hwrm_ver_get(bp, SHORT_HWRM_CMD_TIMEOUT);
4516 rte_delay_ms(BNXT_FW_READY_WAIT_INTERVAL);
4517 timeout -= BNXT_FW_READY_WAIT_INTERVAL;
4518 } while (rc && timeout);
4521 PMD_DRV_LOG(ERR, "FW is not Ready after reset\n");
4525 rc = bnxt_init_resources(bp, true);
4528 "Failed to initialize resources after reset\n");
4531 /* clear reset flag as the device is initialized now */
4532 bp->flags &= ~BNXT_FLAG_FW_RESET;
4534 rc = bnxt_dev_start_op(bp->eth_dev);
4536 PMD_DRV_LOG(ERR, "Failed to start port after reset\n");
4540 rc = bnxt_restore_filters(bp);
4544 PMD_DRV_LOG(INFO, "Recovered from FW reset\n");
4547 bnxt_dev_stop_op(bp->eth_dev);
4549 bp->flags |= BNXT_FLAG_FATAL_ERROR;
4550 bnxt_uninit_resources(bp, false);
4551 PMD_DRV_LOG(ERR, "Failed to recover from FW reset\n");
4554 void bnxt_dev_reset_and_resume(void *arg)
4556 struct bnxt *bp = arg;
4559 bnxt_dev_cleanup(bp);
4561 bnxt_wait_for_device_shutdown(bp);
4563 rc = rte_eal_alarm_set(US_PER_MS * bp->fw_reset_min_msecs,
4564 bnxt_dev_recover, (void *)bp);
4566 PMD_DRV_LOG(ERR, "Error setting recovery alarm");
4569 uint32_t bnxt_read_fw_status_reg(struct bnxt *bp, uint32_t index)
4571 struct bnxt_error_recovery_info *info = bp->recovery_info;
4572 uint32_t reg = info->status_regs[index];
4573 uint32_t type, offset, val = 0;
4575 type = BNXT_FW_STATUS_REG_TYPE(reg);
4576 offset = BNXT_FW_STATUS_REG_OFF(reg);
4579 case BNXT_FW_STATUS_REG_TYPE_CFG:
4580 rte_pci_read_config(bp->pdev, &val, sizeof(val), offset);
4582 case BNXT_FW_STATUS_REG_TYPE_GRC:
4583 offset = info->mapped_status_regs[index];
4585 case BNXT_FW_STATUS_REG_TYPE_BAR0:
4586 val = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
4594 static int bnxt_fw_reset_all(struct bnxt *bp)
4596 struct bnxt_error_recovery_info *info = bp->recovery_info;
4600 if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4601 /* Reset through master function driver */
4602 for (i = 0; i < info->reg_array_cnt; i++)
4603 bnxt_write_fw_reset_reg(bp, i);
4604 /* Wait for time specified by FW after triggering reset */
4605 rte_delay_ms(info->master_func_wait_period_after_reset);
4606 } else if (info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) {
4607 /* Reset with the help of Kong processor */
4608 rc = bnxt_hwrm_fw_reset(bp);
4610 PMD_DRV_LOG(ERR, "Failed to reset FW\n");
4616 static void bnxt_fw_reset_cb(void *arg)
4618 struct bnxt *bp = arg;
4619 struct bnxt_error_recovery_info *info = bp->recovery_info;
4622 /* Only Master function can do FW reset */
4623 if (bnxt_is_master_func(bp) &&
4624 bnxt_is_recovery_enabled(bp)) {
4625 rc = bnxt_fw_reset_all(bp);
4627 PMD_DRV_LOG(ERR, "Adapter recovery failed\n");
4632 /* if recovery method is ERROR_RECOVERY_CO_CPU, KONG will send
4633 * EXCEPTION_FATAL_ASYNC event to all the functions
4634 * (including MASTER FUNC). After receiving this Async, all the active
4635 * drivers should treat this case as FW initiated recovery
4637 if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4638 bp->fw_reset_min_msecs = BNXT_MIN_FW_READY_TIMEOUT;
4639 bp->fw_reset_max_msecs = BNXT_MAX_FW_RESET_TIMEOUT;
4641 /* To recover from error */
4642 rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
4647 /* Driver should poll FW heartbeat, reset_counter with the frequency
4648 * advertised by FW in HWRM_ERROR_RECOVERY_QCFG.
4649 * When the driver detects heartbeat stop or change in reset_counter,
4650 * it has to trigger a reset to recover from the error condition.
4651 * A “master PF” is the function who will have the privilege to
4652 * initiate the chimp reset. The master PF will be elected by the
4653 * firmware and will be notified through async message.
4655 static void bnxt_check_fw_health(void *arg)
4657 struct bnxt *bp = arg;
4658 struct bnxt_error_recovery_info *info = bp->recovery_info;
4659 uint32_t val = 0, wait_msec;
4661 if (!info || !bnxt_is_recovery_enabled(bp) ||
4662 is_bnxt_in_error(bp))
4665 val = bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
4666 if (val == info->last_heart_beat)
4669 info->last_heart_beat = val;
4671 val = bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
4672 if (val != info->last_reset_counter)
4675 info->last_reset_counter = val;
4677 rte_eal_alarm_set(US_PER_MS * info->driver_polling_freq,
4678 bnxt_check_fw_health, (void *)bp);
4682 /* Stop DMA to/from device */
4683 bp->flags |= BNXT_FLAG_FATAL_ERROR;
4684 bp->flags |= BNXT_FLAG_FW_RESET;
4686 PMD_DRV_LOG(ERR, "Detected FW dead condition\n");
4688 if (bnxt_is_master_func(bp))
4689 wait_msec = info->master_func_wait_period;
4691 wait_msec = info->normal_func_wait_period;
4693 rte_eal_alarm_set(US_PER_MS * wait_msec,
4694 bnxt_fw_reset_cb, (void *)bp);
4697 void bnxt_schedule_fw_health_check(struct bnxt *bp)
4699 uint32_t polling_freq;
4701 if (!bnxt_is_recovery_enabled(bp))
4704 if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
4707 polling_freq = bp->recovery_info->driver_polling_freq;
4709 rte_eal_alarm_set(US_PER_MS * polling_freq,
4710 bnxt_check_fw_health, (void *)bp);
4711 bp->flags |= BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4714 static void bnxt_cancel_fw_health_check(struct bnxt *bp)
4716 if (!bnxt_is_recovery_enabled(bp))
4719 rte_eal_alarm_cancel(bnxt_check_fw_health, (void *)bp);
4720 bp->flags &= ~BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4723 static bool bnxt_vf_pciid(uint16_t device_id)
4725 switch (device_id) {
4726 case BROADCOM_DEV_ID_57304_VF:
4727 case BROADCOM_DEV_ID_57406_VF:
4728 case BROADCOM_DEV_ID_5731X_VF:
4729 case BROADCOM_DEV_ID_5741X_VF:
4730 case BROADCOM_DEV_ID_57414_VF:
4731 case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
4732 case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
4733 case BROADCOM_DEV_ID_58802_VF:
4734 case BROADCOM_DEV_ID_57500_VF1:
4735 case BROADCOM_DEV_ID_57500_VF2:
4743 static bool bnxt_thor_device(uint16_t device_id)
4745 switch (device_id) {
4746 case BROADCOM_DEV_ID_57508:
4747 case BROADCOM_DEV_ID_57504:
4748 case BROADCOM_DEV_ID_57502:
4749 case BROADCOM_DEV_ID_57508_MF1:
4750 case BROADCOM_DEV_ID_57504_MF1:
4751 case BROADCOM_DEV_ID_57502_MF1:
4752 case BROADCOM_DEV_ID_57508_MF2:
4753 case BROADCOM_DEV_ID_57504_MF2:
4754 case BROADCOM_DEV_ID_57502_MF2:
4755 case BROADCOM_DEV_ID_57500_VF1:
4756 case BROADCOM_DEV_ID_57500_VF2:
4764 bool bnxt_stratus_device(struct bnxt *bp)
4766 uint16_t device_id = bp->pdev->id.device_id;
4768 switch (device_id) {
4769 case BROADCOM_DEV_ID_STRATUS_NIC:
4770 case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
4771 case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
4779 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
4781 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
4782 struct bnxt *bp = eth_dev->data->dev_private;
4784 /* enable device (incl. PCI PM wakeup), and bus-mastering */
4785 bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
4786 bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
4787 if (!bp->bar0 || !bp->doorbell_base) {
4788 PMD_DRV_LOG(ERR, "Unable to access Hardware\n");
4792 bp->eth_dev = eth_dev;
4798 static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
4799 struct bnxt_ctx_pg_info *ctx_pg,
4804 struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
4805 const struct rte_memzone *mz = NULL;
4806 char mz_name[RTE_MEMZONE_NAMESIZE];
4807 rte_iova_t mz_phys_addr;
4808 uint64_t valid_bits = 0;
4815 rmem->nr_pages = RTE_ALIGN_MUL_CEIL(mem_size, BNXT_PAGE_SIZE) /
4817 rmem->page_size = BNXT_PAGE_SIZE;
4818 rmem->pg_arr = ctx_pg->ctx_pg_arr;
4819 rmem->dma_arr = ctx_pg->ctx_dma_arr;
4820 rmem->flags = BNXT_RMEM_VALID_PTE_FLAG;
4822 valid_bits = PTU_PTE_VALID;
4824 if (rmem->nr_pages > 1) {
4825 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
4826 "bnxt_ctx_pg_tbl%s_%x_%d",
4827 suffix, idx, bp->eth_dev->data->port_id);
4828 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
4829 mz = rte_memzone_lookup(mz_name);
4831 mz = rte_memzone_reserve_aligned(mz_name,
4835 RTE_MEMZONE_SIZE_HINT_ONLY |
4836 RTE_MEMZONE_IOVA_CONTIG,
4842 memset(mz->addr, 0, mz->len);
4843 mz_phys_addr = mz->iova;
4845 rmem->pg_tbl = mz->addr;
4846 rmem->pg_tbl_map = mz_phys_addr;
4847 rmem->pg_tbl_mz = mz;
4850 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_%s_%x_%d",
4851 suffix, idx, bp->eth_dev->data->port_id);
4852 mz = rte_memzone_lookup(mz_name);
4854 mz = rte_memzone_reserve_aligned(mz_name,
4858 RTE_MEMZONE_SIZE_HINT_ONLY |
4859 RTE_MEMZONE_IOVA_CONTIG,
4865 memset(mz->addr, 0, mz->len);
4866 mz_phys_addr = mz->iova;
4868 for (sz = 0, i = 0; sz < mem_size; sz += BNXT_PAGE_SIZE, i++) {
4869 rmem->pg_arr[i] = ((char *)mz->addr) + sz;
4870 rmem->dma_arr[i] = mz_phys_addr + sz;
4872 if (rmem->nr_pages > 1) {
4873 if (i == rmem->nr_pages - 2 &&
4874 (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
4875 valid_bits |= PTU_PTE_NEXT_TO_LAST;
4876 else if (i == rmem->nr_pages - 1 &&
4877 (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
4878 valid_bits |= PTU_PTE_LAST;
4880 rmem->pg_tbl[i] = rte_cpu_to_le_64(rmem->dma_arr[i] |
4886 if (rmem->vmem_size)
4887 rmem->vmem = (void **)mz->addr;
4888 rmem->dma_arr[0] = mz_phys_addr;
4892 static void bnxt_free_ctx_mem(struct bnxt *bp)
4896 if (!bp->ctx || !(bp->ctx->flags & BNXT_CTX_FLAG_INITED))
4899 bp->ctx->flags &= ~BNXT_CTX_FLAG_INITED;
4900 rte_memzone_free(bp->ctx->qp_mem.ring_mem.mz);
4901 rte_memzone_free(bp->ctx->srq_mem.ring_mem.mz);
4902 rte_memzone_free(bp->ctx->cq_mem.ring_mem.mz);
4903 rte_memzone_free(bp->ctx->vnic_mem.ring_mem.mz);
4904 rte_memzone_free(bp->ctx->stat_mem.ring_mem.mz);
4905 rte_memzone_free(bp->ctx->qp_mem.ring_mem.pg_tbl_mz);
4906 rte_memzone_free(bp->ctx->srq_mem.ring_mem.pg_tbl_mz);
4907 rte_memzone_free(bp->ctx->cq_mem.ring_mem.pg_tbl_mz);
4908 rte_memzone_free(bp->ctx->vnic_mem.ring_mem.pg_tbl_mz);
4909 rte_memzone_free(bp->ctx->stat_mem.ring_mem.pg_tbl_mz);
4911 for (i = 0; i < bp->ctx->tqm_fp_rings_count + 1; i++) {
4912 if (bp->ctx->tqm_mem[i])
4913 rte_memzone_free(bp->ctx->tqm_mem[i]->ring_mem.mz);
4920 #define bnxt_roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
4922 #define min_t(type, x, y) ({ \
4923 type __min1 = (x); \
4924 type __min2 = (y); \
4925 __min1 < __min2 ? __min1 : __min2; })
4927 #define max_t(type, x, y) ({ \
4928 type __max1 = (x); \
4929 type __max2 = (y); \
4930 __max1 > __max2 ? __max1 : __max2; })
4932 #define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
4934 int bnxt_alloc_ctx_mem(struct bnxt *bp)
4936 struct bnxt_ctx_pg_info *ctx_pg;
4937 struct bnxt_ctx_mem_info *ctx;
4938 uint32_t mem_size, ena, entries;
4939 uint32_t entries_sp, min;
4942 rc = bnxt_hwrm_func_backing_store_qcaps(bp);
4944 PMD_DRV_LOG(ERR, "Query context mem capability failed\n");
4948 if (!ctx || (ctx->flags & BNXT_CTX_FLAG_INITED))
4951 ctx_pg = &ctx->qp_mem;
4952 ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries;
4953 mem_size = ctx->qp_entry_size * ctx_pg->entries;
4954 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "qp_mem", 0);
4958 ctx_pg = &ctx->srq_mem;
4959 ctx_pg->entries = ctx->srq_max_l2_entries;
4960 mem_size = ctx->srq_entry_size * ctx_pg->entries;
4961 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "srq_mem", 0);
4965 ctx_pg = &ctx->cq_mem;
4966 ctx_pg->entries = ctx->cq_max_l2_entries;
4967 mem_size = ctx->cq_entry_size * ctx_pg->entries;
4968 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "cq_mem", 0);
4972 ctx_pg = &ctx->vnic_mem;
4973 ctx_pg->entries = ctx->vnic_max_vnic_entries +
4974 ctx->vnic_max_ring_table_entries;
4975 mem_size = ctx->vnic_entry_size * ctx_pg->entries;
4976 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "vnic_mem", 0);
4980 ctx_pg = &ctx->stat_mem;
4981 ctx_pg->entries = ctx->stat_max_entries;
4982 mem_size = ctx->stat_entry_size * ctx_pg->entries;
4983 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "stat_mem", 0);
4987 min = ctx->tqm_min_entries_per_ring;
4989 entries_sp = ctx->qp_max_l2_entries +
4990 ctx->vnic_max_vnic_entries +
4991 2 * ctx->qp_min_qp1_entries + min;
4992 entries_sp = bnxt_roundup(entries_sp, ctx->tqm_entries_multiple);
4994 entries = ctx->qp_max_l2_entries + ctx->qp_min_qp1_entries;
4995 entries = bnxt_roundup(entries, ctx->tqm_entries_multiple);
4996 entries = clamp_t(uint32_t, entries, min,
4997 ctx->tqm_max_entries_per_ring);
4998 for (i = 0, ena = 0; i < ctx->tqm_fp_rings_count + 1; i++) {
4999 ctx_pg = ctx->tqm_mem[i];
5000 ctx_pg->entries = i ? entries : entries_sp;
5001 mem_size = ctx->tqm_entry_size * ctx_pg->entries;
5002 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "tqm_mem", i);
5005 ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP << i;
5008 ena |= FUNC_BACKING_STORE_CFG_INPUT_DFLT_ENABLES;
5009 rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
5012 "Failed to configure context mem: rc = %d\n", rc);
5014 ctx->flags |= BNXT_CTX_FLAG_INITED;
5019 static int bnxt_alloc_stats_mem(struct bnxt *bp)
5021 struct rte_pci_device *pci_dev = bp->pdev;
5022 char mz_name[RTE_MEMZONE_NAMESIZE];
5023 const struct rte_memzone *mz = NULL;
5024 uint32_t total_alloc_len;
5025 rte_iova_t mz_phys_addr;
5027 if (pci_dev->id.device_id == BROADCOM_DEV_ID_NS2)
5030 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
5031 "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
5032 pci_dev->addr.bus, pci_dev->addr.devid,
5033 pci_dev->addr.function, "rx_port_stats");
5034 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5035 mz = rte_memzone_lookup(mz_name);
5037 RTE_CACHE_LINE_ROUNDUP(sizeof(struct rx_port_stats) +
5038 sizeof(struct rx_port_stats_ext) + 512);
5040 mz = rte_memzone_reserve(mz_name, total_alloc_len,
5043 RTE_MEMZONE_SIZE_HINT_ONLY |
5044 RTE_MEMZONE_IOVA_CONTIG);
5048 memset(mz->addr, 0, mz->len);
5049 mz_phys_addr = mz->iova;
5051 bp->rx_mem_zone = (const void *)mz;
5052 bp->hw_rx_port_stats = mz->addr;
5053 bp->hw_rx_port_stats_map = mz_phys_addr;
5055 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
5056 "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
5057 pci_dev->addr.bus, pci_dev->addr.devid,
5058 pci_dev->addr.function, "tx_port_stats");
5059 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5060 mz = rte_memzone_lookup(mz_name);
5062 RTE_CACHE_LINE_ROUNDUP(sizeof(struct tx_port_stats) +
5063 sizeof(struct tx_port_stats_ext) + 512);
5065 mz = rte_memzone_reserve(mz_name,
5069 RTE_MEMZONE_SIZE_HINT_ONLY |
5070 RTE_MEMZONE_IOVA_CONTIG);
5074 memset(mz->addr, 0, mz->len);
5075 mz_phys_addr = mz->iova;
5077 bp->tx_mem_zone = (const void *)mz;
5078 bp->hw_tx_port_stats = mz->addr;
5079 bp->hw_tx_port_stats_map = mz_phys_addr;
5080 bp->flags |= BNXT_FLAG_PORT_STATS;
5082 /* Display extended statistics if FW supports it */
5083 if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
5084 bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0 ||
5085 !(bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED))
5088 bp->hw_rx_port_stats_ext = (void *)
5089 ((uint8_t *)bp->hw_rx_port_stats +
5090 sizeof(struct rx_port_stats));
5091 bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
5092 sizeof(struct rx_port_stats);
5093 bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
5095 if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2 ||
5096 bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED) {
5097 bp->hw_tx_port_stats_ext = (void *)
5098 ((uint8_t *)bp->hw_tx_port_stats +
5099 sizeof(struct tx_port_stats));
5100 bp->hw_tx_port_stats_ext_map =
5101 bp->hw_tx_port_stats_map +
5102 sizeof(struct tx_port_stats);
5103 bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
5109 static int bnxt_setup_mac_addr(struct rte_eth_dev *eth_dev)
5111 struct bnxt *bp = eth_dev->data->dev_private;
5114 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
5115 RTE_ETHER_ADDR_LEN *
5118 if (eth_dev->data->mac_addrs == NULL) {
5119 PMD_DRV_LOG(ERR, "Failed to alloc MAC addr tbl\n");
5123 if (!BNXT_HAS_DFLT_MAC_SET(bp)) {
5127 /* Generate a random MAC address, if none was assigned by PF */
5128 PMD_DRV_LOG(INFO, "VF MAC address not assigned by Host PF\n");
5129 bnxt_eth_hw_addr_random(bp->mac_addr);
5131 "Assign random MAC:%02X:%02X:%02X:%02X:%02X:%02X\n",
5132 bp->mac_addr[0], bp->mac_addr[1], bp->mac_addr[2],
5133 bp->mac_addr[3], bp->mac_addr[4], bp->mac_addr[5]);
5135 rc = bnxt_hwrm_set_mac(bp);
5140 /* Copy the permanent MAC from the FUNC_QCAPS response */
5141 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, RTE_ETHER_ADDR_LEN);
5146 static int bnxt_restore_dflt_mac(struct bnxt *bp)
5150 /* MAC is already configured in FW */
5151 if (BNXT_HAS_DFLT_MAC_SET(bp))
5154 /* Restore the old MAC configured */
5155 rc = bnxt_hwrm_set_mac(bp);
5157 PMD_DRV_LOG(ERR, "Failed to restore MAC address\n");
5162 static void bnxt_config_vf_req_fwd(struct bnxt *bp)
5167 #define ALLOW_FUNC(x) \
5169 uint32_t arg = (x); \
5170 bp->pf->vf_req_fwd[((arg) >> 5)] &= \
5171 ~rte_cpu_to_le_32(1 << ((arg) & 0x1f)); \
5174 /* Forward all requests if firmware is new enough */
5175 if (((bp->fw_ver >= ((20 << 24) | (6 << 16) | (100 << 8))) &&
5176 (bp->fw_ver < ((20 << 24) | (7 << 16)))) ||
5177 ((bp->fw_ver >= ((20 << 24) | (8 << 16))))) {
5178 memset(bp->pf->vf_req_fwd, 0xff, sizeof(bp->pf->vf_req_fwd));
5180 PMD_DRV_LOG(WARNING,
5181 "Firmware too old for VF mailbox functionality\n");
5182 memset(bp->pf->vf_req_fwd, 0, sizeof(bp->pf->vf_req_fwd));
5186 * The following are used for driver cleanup. If we disallow these,
5187 * VF drivers can't clean up cleanly.
5189 ALLOW_FUNC(HWRM_FUNC_DRV_UNRGTR);
5190 ALLOW_FUNC(HWRM_VNIC_FREE);
5191 ALLOW_FUNC(HWRM_RING_FREE);
5192 ALLOW_FUNC(HWRM_RING_GRP_FREE);
5193 ALLOW_FUNC(HWRM_VNIC_RSS_COS_LB_CTX_FREE);
5194 ALLOW_FUNC(HWRM_CFA_L2_FILTER_FREE);
5195 ALLOW_FUNC(HWRM_STAT_CTX_FREE);
5196 ALLOW_FUNC(HWRM_PORT_PHY_QCFG);
5197 ALLOW_FUNC(HWRM_VNIC_TPA_CFG);
5201 bnxt_get_svif(uint16_t port_id, bool func_svif,
5202 enum bnxt_ulp_intf_type type)
5204 struct rte_eth_dev *eth_dev;
5207 eth_dev = &rte_eth_devices[port_id];
5208 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5209 struct bnxt_vf_representor *vfr = eth_dev->data->dev_private;
5213 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5216 eth_dev = vfr->parent_dev;
5219 bp = eth_dev->data->dev_private;
5221 return func_svif ? bp->func_svif : bp->port_svif;
5225 bnxt_get_vnic_id(uint16_t port, enum bnxt_ulp_intf_type type)
5227 struct rte_eth_dev *eth_dev;
5228 struct bnxt_vnic_info *vnic;
5231 eth_dev = &rte_eth_devices[port];
5232 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5233 struct bnxt_vf_representor *vfr = eth_dev->data->dev_private;
5237 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5238 return vfr->dflt_vnic_id;
5240 eth_dev = vfr->parent_dev;
5243 bp = eth_dev->data->dev_private;
5245 vnic = BNXT_GET_DEFAULT_VNIC(bp);
5247 return vnic->fw_vnic_id;
5251 bnxt_get_fw_func_id(uint16_t port, enum bnxt_ulp_intf_type type)
5253 struct rte_eth_dev *eth_dev;
5256 eth_dev = &rte_eth_devices[port];
5257 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5258 struct bnxt_vf_representor *vfr = eth_dev->data->dev_private;
5262 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5265 eth_dev = vfr->parent_dev;
5268 bp = eth_dev->data->dev_private;
5273 enum bnxt_ulp_intf_type
5274 bnxt_get_interface_type(uint16_t port)
5276 struct rte_eth_dev *eth_dev;
5279 eth_dev = &rte_eth_devices[port];
5280 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev))
5281 return BNXT_ULP_INTF_TYPE_VF_REP;
5283 bp = eth_dev->data->dev_private;
5285 return BNXT_ULP_INTF_TYPE_PF;
5286 else if (BNXT_VF_IS_TRUSTED(bp))
5287 return BNXT_ULP_INTF_TYPE_TRUSTED_VF;
5288 else if (BNXT_VF(bp))
5289 return BNXT_ULP_INTF_TYPE_VF;
5291 return BNXT_ULP_INTF_TYPE_INVALID;
5295 bnxt_get_phy_port_id(uint16_t port_id)
5297 struct bnxt_vf_representor *vfr;
5298 struct rte_eth_dev *eth_dev;
5301 eth_dev = &rte_eth_devices[port_id];
5302 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5303 vfr = eth_dev->data->dev_private;
5307 eth_dev = vfr->parent_dev;
5310 bp = eth_dev->data->dev_private;
5312 return BNXT_PF(bp) ? bp->pf->port_id : bp->parent->port_id;
5316 bnxt_get_parif(uint16_t port_id, enum bnxt_ulp_intf_type type)
5318 struct rte_eth_dev *eth_dev;
5321 eth_dev = &rte_eth_devices[port_id];
5322 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5323 struct bnxt_vf_representor *vfr = eth_dev->data->dev_private;
5327 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5328 return vfr->fw_fid - 1;
5330 eth_dev = vfr->parent_dev;
5333 bp = eth_dev->data->dev_private;
5335 return BNXT_PF(bp) ? bp->fw_fid - 1 : bp->parent->fid - 1;
5339 bnxt_get_vport(uint16_t port_id)
5341 return (1 << bnxt_get_phy_port_id(port_id));
5344 static void bnxt_alloc_error_recovery_info(struct bnxt *bp)
5346 struct bnxt_error_recovery_info *info = bp->recovery_info;
5349 if (!(bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS))
5350 memset(info, 0, sizeof(*info));
5354 if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
5357 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5360 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5362 bp->recovery_info = info;
5365 static void bnxt_check_fw_status(struct bnxt *bp)
5369 if (!(bp->recovery_info &&
5370 (bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS)))
5373 fw_status = bnxt_read_fw_status_reg(bp, BNXT_FW_STATUS_REG);
5374 if (fw_status != BNXT_FW_STATUS_HEALTHY)
5375 PMD_DRV_LOG(ERR, "Firmware not responding, status: %#x\n",
5379 static int bnxt_map_hcomm_fw_status_reg(struct bnxt *bp)
5381 struct bnxt_error_recovery_info *info = bp->recovery_info;
5382 uint32_t status_loc;
5385 rte_write32(HCOMM_STATUS_STRUCT_LOC, (uint8_t *)bp->bar0 +
5386 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5387 sig_ver = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5388 BNXT_GRCP_WINDOW_2_BASE +
5389 offsetof(struct hcomm_status,
5391 /* If the signature is absent, then FW does not support this feature */
5392 if ((sig_ver & HCOMM_STATUS_SIGNATURE_MASK) !=
5393 HCOMM_STATUS_SIGNATURE_VAL)
5397 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5401 bp->recovery_info = info;
5403 memset(info, 0, sizeof(*info));
5406 status_loc = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5407 BNXT_GRCP_WINDOW_2_BASE +
5408 offsetof(struct hcomm_status,
5411 /* Only pre-map the FW health status GRC register */
5412 if (BNXT_FW_STATUS_REG_TYPE(status_loc) != BNXT_FW_STATUS_REG_TYPE_GRC)
5415 info->status_regs[BNXT_FW_STATUS_REG] = status_loc;
5416 info->mapped_status_regs[BNXT_FW_STATUS_REG] =
5417 BNXT_GRCP_WINDOW_2_BASE + (status_loc & BNXT_GRCP_OFFSET_MASK);
5419 rte_write32((status_loc & BNXT_GRCP_BASE_MASK), (uint8_t *)bp->bar0 +
5420 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5422 bp->fw_cap |= BNXT_FW_CAP_HCOMM_FW_STATUS;
5427 static int bnxt_init_fw(struct bnxt *bp)
5434 rc = bnxt_map_hcomm_fw_status_reg(bp);
5438 rc = bnxt_hwrm_ver_get(bp, DFLT_HWRM_CMD_TIMEOUT);
5440 bnxt_check_fw_status(bp);
5444 rc = bnxt_hwrm_func_reset(bp);
5448 rc = bnxt_hwrm_vnic_qcaps(bp);
5452 rc = bnxt_hwrm_queue_qportcfg(bp);
5456 /* Get the MAX capabilities for this function.
5457 * This function also allocates context memory for TQM rings and
5458 * informs the firmware about this allocated backing store memory.
5460 rc = bnxt_hwrm_func_qcaps(bp);
5464 rc = bnxt_hwrm_func_qcfg(bp, &mtu);
5468 bnxt_hwrm_port_mac_qcfg(bp);
5470 bnxt_hwrm_parent_pf_qcfg(bp);
5472 bnxt_hwrm_port_phy_qcaps(bp);
5474 bnxt_alloc_error_recovery_info(bp);
5475 /* Get the adapter error recovery support info */
5476 rc = bnxt_hwrm_error_recovery_qcfg(bp);
5478 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5480 bnxt_hwrm_port_led_qcaps(bp);
5486 bnxt_init_locks(struct bnxt *bp)
5490 err = pthread_mutex_init(&bp->flow_lock, NULL);
5492 PMD_DRV_LOG(ERR, "Unable to initialize flow_lock\n");
5496 err = pthread_mutex_init(&bp->def_cp_lock, NULL);
5498 PMD_DRV_LOG(ERR, "Unable to initialize def_cp_lock\n");
5502 static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
5506 rc = bnxt_init_fw(bp);
5510 if (!reconfig_dev) {
5511 rc = bnxt_setup_mac_addr(bp->eth_dev);
5515 rc = bnxt_restore_dflt_mac(bp);
5520 bnxt_config_vf_req_fwd(bp);
5522 rc = bnxt_hwrm_func_driver_register(bp);
5524 PMD_DRV_LOG(ERR, "Failed to register driver");
5529 if (bp->pdev->max_vfs) {
5530 rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
5532 PMD_DRV_LOG(ERR, "Failed to allocate VFs\n");
5536 rc = bnxt_hwrm_allocate_pf_only(bp);
5539 "Failed to allocate PF resources");
5545 rc = bnxt_alloc_mem(bp, reconfig_dev);
5549 rc = bnxt_setup_int(bp);
5553 rc = bnxt_request_int(bp);
5557 rc = bnxt_init_ctx_mem(bp);
5559 PMD_DRV_LOG(ERR, "Failed to init adv_flow_counters\n");
5563 rc = bnxt_init_locks(bp);
5571 bnxt_parse_devarg_truflow(__rte_unused const char *key,
5572 const char *value, void *opaque_arg)
5574 struct bnxt *bp = opaque_arg;
5575 unsigned long truflow;
5578 if (!value || !opaque_arg) {
5580 "Invalid parameter passed to truflow devargs.\n");
5584 truflow = strtoul(value, &end, 10);
5585 if (end == NULL || *end != '\0' ||
5586 (truflow == ULONG_MAX && errno == ERANGE)) {
5588 "Invalid parameter passed to truflow devargs.\n");
5592 if (BNXT_DEVARG_TRUFLOW_INVALID(truflow)) {
5594 "Invalid value passed to truflow devargs.\n");
5598 bp->flags |= BNXT_FLAG_TRUFLOW_EN;
5599 if (BNXT_TRUFLOW_EN(bp))
5600 PMD_DRV_LOG(INFO, "Host-based truflow feature enabled.\n");
5606 bnxt_parse_devarg_flow_xstat(__rte_unused const char *key,
5607 const char *value, void *opaque_arg)
5609 struct bnxt *bp = opaque_arg;
5610 unsigned long flow_xstat;
5613 if (!value || !opaque_arg) {
5615 "Invalid parameter passed to flow_xstat devarg.\n");
5619 flow_xstat = strtoul(value, &end, 10);
5620 if (end == NULL || *end != '\0' ||
5621 (flow_xstat == ULONG_MAX && errno == ERANGE)) {
5623 "Invalid parameter passed to flow_xstat devarg.\n");
5627 if (BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat)) {
5629 "Invalid value passed to flow_xstat devarg.\n");
5633 bp->flags |= BNXT_FLAG_FLOW_XSTATS_EN;
5634 if (BNXT_FLOW_XSTATS_EN(bp))
5635 PMD_DRV_LOG(INFO, "flow_xstat feature enabled.\n");
5641 bnxt_parse_devarg_max_num_kflows(__rte_unused const char *key,
5642 const char *value, void *opaque_arg)
5644 struct bnxt *bp = opaque_arg;
5645 unsigned long max_num_kflows;
5648 if (!value || !opaque_arg) {
5650 "Invalid parameter passed to max_num_kflows devarg.\n");
5654 max_num_kflows = strtoul(value, &end, 10);
5655 if (end == NULL || *end != '\0' ||
5656 (max_num_kflows == ULONG_MAX && errno == ERANGE)) {
5658 "Invalid parameter passed to max_num_kflows devarg.\n");
5662 if (bnxt_devarg_max_num_kflow_invalid(max_num_kflows)) {
5664 "Invalid value passed to max_num_kflows devarg.\n");
5668 bp->max_num_kflows = max_num_kflows;
5669 if (bp->max_num_kflows)
5670 PMD_DRV_LOG(INFO, "max_num_kflows set as %ldK.\n",
5677 bnxt_parse_dev_args(struct bnxt *bp, struct rte_devargs *devargs)
5679 struct rte_kvargs *kvlist;
5681 if (devargs == NULL)
5684 kvlist = rte_kvargs_parse(devargs->args, bnxt_dev_args);
5689 * Handler for "truflow" devarg.
5690 * Invoked as for ex: "-w 0000:00:0d.0,host-based-truflow=1"
5692 rte_kvargs_process(kvlist, BNXT_DEVARG_TRUFLOW,
5693 bnxt_parse_devarg_truflow, bp);
5696 * Handler for "flow_xstat" devarg.
5697 * Invoked as for ex: "-w 0000:00:0d.0,flow_xstat=1"
5699 rte_kvargs_process(kvlist, BNXT_DEVARG_FLOW_XSTAT,
5700 bnxt_parse_devarg_flow_xstat, bp);
5703 * Handler for "max_num_kflows" devarg.
5704 * Invoked as for ex: "-w 000:00:0d.0,max_num_kflows=32"
5706 rte_kvargs_process(kvlist, BNXT_DEVARG_MAX_NUM_KFLOWS,
5707 bnxt_parse_devarg_max_num_kflows, bp);
5709 rte_kvargs_free(kvlist);
5712 static int bnxt_alloc_switch_domain(struct bnxt *bp)
5716 if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
5717 rc = rte_eth_switch_domain_alloc(&bp->switch_domain_id);
5720 "Failed to alloc switch domain: %d\n", rc);
5723 "Switch domain allocated %d\n",
5724 bp->switch_domain_id);
5731 bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
5733 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
5734 static int version_printed;
5738 if (version_printed++ == 0)
5739 PMD_DRV_LOG(INFO, "%s\n", bnxt_version);
5741 eth_dev->dev_ops = &bnxt_dev_ops;
5742 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
5743 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
5746 * For secondary processes, we don't initialise any further
5747 * as primary has already done this work.
5749 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5752 rte_eth_copy_pci_info(eth_dev, pci_dev);
5754 bp = eth_dev->data->dev_private;
5756 /* Parse dev arguments passed on when starting the DPDK application. */
5757 bnxt_parse_dev_args(bp, pci_dev->device.devargs);
5759 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
5761 if (bnxt_vf_pciid(pci_dev->id.device_id))
5762 bp->flags |= BNXT_FLAG_VF;
5764 if (bnxt_thor_device(pci_dev->id.device_id))
5765 bp->flags |= BNXT_FLAG_THOR_CHIP;
5767 if (pci_dev->id.device_id == BROADCOM_DEV_ID_58802 ||
5768 pci_dev->id.device_id == BROADCOM_DEV_ID_58804 ||
5769 pci_dev->id.device_id == BROADCOM_DEV_ID_58808 ||
5770 pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
5771 bp->flags |= BNXT_FLAG_STINGRAY;
5773 rc = bnxt_init_board(eth_dev);
5776 "Failed to initialize board rc: %x\n", rc);
5780 rc = bnxt_alloc_pf_info(bp);
5784 rc = bnxt_alloc_link_info(bp);
5788 rc = bnxt_alloc_parent_info(bp);
5792 rc = bnxt_alloc_hwrm_resources(bp);
5795 "Failed to allocate hwrm resource rc: %x\n", rc);
5798 rc = bnxt_alloc_leds_info(bp);
5802 rc = bnxt_alloc_cos_queues(bp);
5806 rc = bnxt_init_resources(bp, false);
5810 rc = bnxt_alloc_stats_mem(bp);
5814 bnxt_alloc_switch_domain(bp);
5816 /* Pass the information to the rte_eth_dev_close() that it should also
5817 * release the private port resources.
5819 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
5822 DRV_MODULE_NAME "found at mem %" PRIX64 ", node addr %pM\n",
5823 pci_dev->mem_resource[0].phys_addr,
5824 pci_dev->mem_resource[0].addr);
5829 bnxt_dev_uninit(eth_dev);
5834 static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
5843 ctx->dma = RTE_BAD_IOVA;
5844 ctx->ctx_id = BNXT_CTX_VAL_INVAL;
5847 static void bnxt_unregister_fc_ctx_mem(struct bnxt *bp)
5849 bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
5850 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
5851 bp->flow_stat->rx_fc_out_tbl.ctx_id,
5852 bp->flow_stat->max_fc,
5855 bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
5856 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
5857 bp->flow_stat->tx_fc_out_tbl.ctx_id,
5858 bp->flow_stat->max_fc,
5861 if (bp->flow_stat->rx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5862 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_in_tbl.ctx_id);
5863 bp->flow_stat->rx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5865 if (bp->flow_stat->rx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5866 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_out_tbl.ctx_id);
5867 bp->flow_stat->rx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5869 if (bp->flow_stat->tx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5870 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_in_tbl.ctx_id);
5871 bp->flow_stat->tx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5873 if (bp->flow_stat->tx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5874 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_out_tbl.ctx_id);
5875 bp->flow_stat->tx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5878 static void bnxt_uninit_fc_ctx_mem(struct bnxt *bp)
5880 bnxt_unregister_fc_ctx_mem(bp);
5882 bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_in_tbl);
5883 bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_out_tbl);
5884 bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_in_tbl);
5885 bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_out_tbl);
5888 static void bnxt_uninit_ctx_mem(struct bnxt *bp)
5890 if (BNXT_FLOW_XSTATS_EN(bp))
5891 bnxt_uninit_fc_ctx_mem(bp);
5895 bnxt_free_error_recovery_info(struct bnxt *bp)
5897 rte_free(bp->recovery_info);
5898 bp->recovery_info = NULL;
5899 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5903 bnxt_uninit_locks(struct bnxt *bp)
5905 pthread_mutex_destroy(&bp->flow_lock);
5906 pthread_mutex_destroy(&bp->def_cp_lock);
5908 pthread_mutex_destroy(&bp->rep_info->vfr_lock);
5912 bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
5917 bnxt_free_mem(bp, reconfig_dev);
5918 bnxt_hwrm_func_buf_unrgtr(bp);
5919 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
5920 bp->flags &= ~BNXT_FLAG_REGISTERED;
5921 bnxt_free_ctx_mem(bp);
5922 if (!reconfig_dev) {
5923 bnxt_free_hwrm_resources(bp);
5924 bnxt_free_error_recovery_info(bp);
5927 bnxt_uninit_ctx_mem(bp);
5929 bnxt_uninit_locks(bp);
5930 bnxt_free_flow_stats_info(bp);
5931 bnxt_free_rep_info(bp);
5932 rte_free(bp->ptp_cfg);
5938 bnxt_dev_uninit(struct rte_eth_dev *eth_dev)
5940 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5943 PMD_DRV_LOG(DEBUG, "Calling Device uninit\n");
5945 if (eth_dev->state != RTE_ETH_DEV_UNUSED)
5946 bnxt_dev_close_op(eth_dev);
5951 static int bnxt_pci_remove_dev_with_reps(struct rte_eth_dev *eth_dev)
5953 struct bnxt *bp = eth_dev->data->dev_private;
5954 struct rte_eth_dev *vf_rep_eth_dev;
5960 for (i = 0; i < bp->num_reps; i++) {
5961 vf_rep_eth_dev = bp->rep_info[i].vfr_eth_dev;
5962 if (!vf_rep_eth_dev)
5964 rte_eth_dev_destroy(vf_rep_eth_dev, bnxt_vf_representor_uninit);
5966 ret = rte_eth_dev_destroy(eth_dev, bnxt_dev_uninit);
5971 static void bnxt_free_rep_info(struct bnxt *bp)
5973 rte_free(bp->rep_info);
5974 bp->rep_info = NULL;
5975 rte_free(bp->cfa_code_map);
5976 bp->cfa_code_map = NULL;
5979 static int bnxt_init_rep_info(struct bnxt *bp)
5986 bp->rep_info = rte_zmalloc("bnxt_rep_info",
5987 sizeof(bp->rep_info[0]) * BNXT_MAX_VF_REPS,
5989 if (!bp->rep_info) {
5990 PMD_DRV_LOG(ERR, "Failed to alloc memory for rep info\n");
5993 bp->cfa_code_map = rte_zmalloc("bnxt_cfa_code_map",
5994 sizeof(*bp->cfa_code_map) *
5995 BNXT_MAX_CFA_CODE, 0);
5996 if (!bp->cfa_code_map) {
5997 PMD_DRV_LOG(ERR, "Failed to alloc memory for cfa_code_map\n");
5998 bnxt_free_rep_info(bp);
6002 for (i = 0; i < BNXT_MAX_CFA_CODE; i++)
6003 bp->cfa_code_map[i] = BNXT_VF_IDX_INVALID;
6005 rc = pthread_mutex_init(&bp->rep_info->vfr_lock, NULL);
6007 PMD_DRV_LOG(ERR, "Unable to initialize vfr_lock\n");
6008 bnxt_free_rep_info(bp);
6014 static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
6015 struct rte_eth_devargs eth_da,
6016 struct rte_eth_dev *backing_eth_dev)
6018 struct rte_eth_dev *vf_rep_eth_dev;
6019 char name[RTE_ETH_NAME_MAX_LEN];
6020 struct bnxt *backing_bp;
6024 num_rep = eth_da.nb_representor_ports;
6025 if (num_rep > BNXT_MAX_VF_REPS) {
6026 PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
6027 num_rep, BNXT_MAX_VF_REPS);
6031 if (num_rep > RTE_MAX_ETHPORTS) {
6033 "nb_representor_ports = %d > %d MAX ETHPORTS\n",
6034 num_rep, RTE_MAX_ETHPORTS);
6038 backing_bp = backing_eth_dev->data->dev_private;
6040 if (!(BNXT_PF(backing_bp) || BNXT_VF_IS_TRUSTED(backing_bp))) {
6042 "Not a PF or trusted VF. No Representor support\n");
6043 /* Returning an error is not an option.
6044 * Applications are not handling this correctly
6049 if (bnxt_init_rep_info(backing_bp))
6052 for (i = 0; i < num_rep; i++) {
6053 struct bnxt_vf_representor representor = {
6054 .vf_id = eth_da.representor_ports[i],
6055 .switch_domain_id = backing_bp->switch_domain_id,
6056 .parent_dev = backing_eth_dev
6059 if (representor.vf_id >= BNXT_MAX_VF_REPS) {
6060 PMD_DRV_LOG(ERR, "VF-Rep id %d >= %d MAX VF ID\n",
6061 representor.vf_id, BNXT_MAX_VF_REPS);
6065 /* representor port net_bdf_port */
6066 snprintf(name, sizeof(name), "net_%s_representor_%d",
6067 pci_dev->device.name, eth_da.representor_ports[i]);
6069 ret = rte_eth_dev_create(&pci_dev->device, name,
6070 sizeof(struct bnxt_vf_representor),
6072 bnxt_vf_representor_init,
6076 vf_rep_eth_dev = rte_eth_dev_allocated(name);
6077 if (!vf_rep_eth_dev) {
6078 PMD_DRV_LOG(ERR, "Failed to find the eth_dev"
6079 " for VF-Rep: %s.", name);
6080 bnxt_pci_remove_dev_with_reps(backing_eth_dev);
6084 backing_bp->rep_info[representor.vf_id].vfr_eth_dev =
6086 backing_bp->num_reps++;
6088 PMD_DRV_LOG(ERR, "failed to create bnxt vf "
6089 "representor %s.", name);
6090 bnxt_pci_remove_dev_with_reps(backing_eth_dev);
6097 static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
6098 struct rte_pci_device *pci_dev)
6100 struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
6101 struct rte_eth_dev *backing_eth_dev;
6105 if (pci_dev->device.devargs) {
6106 ret = rte_eth_devargs_parse(pci_dev->device.devargs->args,
6112 num_rep = eth_da.nb_representor_ports;
6113 PMD_DRV_LOG(DEBUG, "nb_representor_ports = %d\n",
6116 /* We could come here after first level of probe is already invoked
6117 * as part of an application bringup(OVS-DPDK vswitchd), so first check
6118 * for already allocated eth_dev for the backing device (PF/Trusted VF)
6120 backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6121 if (backing_eth_dev == NULL) {
6122 ret = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
6123 sizeof(struct bnxt),
6124 eth_dev_pci_specific_init, pci_dev,
6125 bnxt_dev_init, NULL);
6127 if (ret || !num_rep)
6130 backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6133 /* probe representor ports now */
6134 ret = bnxt_rep_port_probe(pci_dev, eth_da, backing_eth_dev);
6139 static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
6141 struct rte_eth_dev *eth_dev;
6143 eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6145 return 0; /* Invoked typically only by OVS-DPDK, by the
6146 * time it comes here the eth_dev is already
6147 * deleted by rte_eth_dev_close(), so returning
6148 * +ve value will at least help in proper cleanup
6151 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
6152 if (eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
6153 return rte_eth_dev_destroy(eth_dev,
6154 bnxt_vf_representor_uninit);
6156 return rte_eth_dev_destroy(eth_dev,
6159 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
6163 static struct rte_pci_driver bnxt_rte_pmd = {
6164 .id_table = bnxt_pci_id_map,
6165 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
6166 RTE_PCI_DRV_PROBE_AGAIN, /* Needed in case of VF-REPs
6169 .probe = bnxt_pci_probe,
6170 .remove = bnxt_pci_remove,
6174 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
6176 if (strcmp(dev->device->driver->name, drv->driver.name))
6182 bool is_bnxt_supported(struct rte_eth_dev *dev)
6184 return is_device_supported(dev, &bnxt_rte_pmd);
6187 RTE_LOG_REGISTER(bnxt_logtype_driver, pmd.net.bnxt.driver, NOTICE);
6188 RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
6189 RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
6190 RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");