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>
19 #include "bnxt_filter.h"
20 #include "bnxt_hwrm.h"
22 #include "bnxt_reps.h"
23 #include "bnxt_ring.h"
26 #include "bnxt_stats.h"
29 #include "bnxt_vnic.h"
30 #include "hsi_struct_def_dpdk.h"
31 #include "bnxt_nvm_defs.h"
32 #include "bnxt_tf_common.h"
33 #include "ulp_flow_db.h"
34 #include "rte_pmd_bnxt.h"
36 #define DRV_MODULE_NAME "bnxt"
37 static const char bnxt_version[] =
38 "Broadcom NetXtreme driver " DRV_MODULE_NAME;
41 * The set of PCI devices this driver supports
43 static const struct rte_pci_id bnxt_pci_id_map[] = {
44 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
45 BROADCOM_DEV_ID_STRATUS_NIC_VF1) },
46 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
47 BROADCOM_DEV_ID_STRATUS_NIC_VF2) },
48 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
49 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
50 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
51 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
52 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
53 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
54 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
55 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
56 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
57 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
58 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
59 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
60 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
61 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
62 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
63 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
64 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
65 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
66 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
67 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
68 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
69 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
70 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
71 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
72 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
73 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
74 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
75 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
76 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
77 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
78 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
79 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
80 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
81 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
82 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802) },
83 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58804) },
84 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58808) },
85 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802_VF) },
86 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508) },
87 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504) },
88 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502) },
89 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF1) },
90 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF2) },
91 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF1) },
92 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF1) },
93 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF1) },
94 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF2) },
95 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF2) },
96 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF2) },
97 { .vendor_id = 0, /* sentinel */ },
100 #define BNXT_DEVARG_TRUFLOW "host-based-truflow"
101 #define BNXT_DEVARG_FLOW_XSTAT "flow-xstat"
102 #define BNXT_DEVARG_MAX_NUM_KFLOWS "max-num-kflows"
103 #define BNXT_DEVARG_REPRESENTOR "representor"
104 #define BNXT_DEVARG_REP_BASED_PF "rep-based-pf"
105 #define BNXT_DEVARG_REP_IS_PF "rep-is-pf"
106 #define BNXT_DEVARG_REP_Q_R2F "rep-q-r2f"
107 #define BNXT_DEVARG_REP_Q_F2R "rep-q-f2r"
108 #define BNXT_DEVARG_REP_FC_R2F "rep-fc-r2f"
109 #define BNXT_DEVARG_REP_FC_F2R "rep-fc-f2r"
111 static const char *const bnxt_dev_args[] = {
112 BNXT_DEVARG_REPRESENTOR,
114 BNXT_DEVARG_FLOW_XSTAT,
115 BNXT_DEVARG_MAX_NUM_KFLOWS,
116 BNXT_DEVARG_REP_BASED_PF,
117 BNXT_DEVARG_REP_IS_PF,
118 BNXT_DEVARG_REP_Q_R2F,
119 BNXT_DEVARG_REP_Q_F2R,
120 BNXT_DEVARG_REP_FC_R2F,
121 BNXT_DEVARG_REP_FC_F2R,
126 * truflow == false to disable the feature
127 * truflow == true to enable the feature
129 #define BNXT_DEVARG_TRUFLOW_INVALID(truflow) ((truflow) > 1)
132 * flow_xstat == false to disable the feature
133 * flow_xstat == true to enable the feature
135 #define BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat) ((flow_xstat) > 1)
138 * rep_is_pf == false to indicate VF representor
139 * rep_is_pf == true to indicate PF representor
141 #define BNXT_DEVARG_REP_IS_PF_INVALID(rep_is_pf) ((rep_is_pf) > 1)
144 * rep_based_pf == Physical index of the PF
146 #define BNXT_DEVARG_REP_BASED_PF_INVALID(rep_based_pf) ((rep_based_pf) > 15)
148 * rep_q_r2f == Logical COS Queue index for the rep to endpoint direction
150 #define BNXT_DEVARG_REP_Q_R2F_INVALID(rep_q_r2f) ((rep_q_r2f) > 3)
153 * rep_q_f2r == Logical COS Queue index for the endpoint to rep direction
155 #define BNXT_DEVARG_REP_Q_F2R_INVALID(rep_q_f2r) ((rep_q_f2r) > 3)
158 * rep_fc_r2f == Flow control for the representor to endpoint direction
160 #define BNXT_DEVARG_REP_FC_R2F_INVALID(rep_fc_r2f) ((rep_fc_r2f) > 1)
163 * rep_fc_f2r == Flow control for the endpoint to representor direction
165 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r) ((rep_fc_f2r) > 1)
167 int bnxt_cfa_code_dynfield_offset = -1;
170 * max_num_kflows must be >= 32
171 * and must be a power-of-2 supported value
172 * return: 1 -> invalid
175 static int bnxt_devarg_max_num_kflow_invalid(uint16_t max_num_kflows)
177 if (max_num_kflows < 32 || !rte_is_power_of_2(max_num_kflows))
182 static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
183 static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
184 static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev);
185 static int bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev);
186 static void bnxt_cancel_fw_health_check(struct bnxt *bp);
187 static int bnxt_restore_vlan_filters(struct bnxt *bp);
188 static void bnxt_dev_recover(void *arg);
189 static void bnxt_free_error_recovery_info(struct bnxt *bp);
190 static void bnxt_free_rep_info(struct bnxt *bp);
192 int is_bnxt_in_error(struct bnxt *bp)
194 if (bp->flags & BNXT_FLAG_FATAL_ERROR)
196 if (bp->flags & BNXT_FLAG_FW_RESET)
202 /***********************/
205 * High level utility functions
208 static uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
210 if (!BNXT_CHIP_THOR(bp))
213 return RTE_ALIGN_MUL_CEIL(bp->rx_nr_rings,
214 BNXT_RSS_ENTRIES_PER_CTX_THOR) /
215 BNXT_RSS_ENTRIES_PER_CTX_THOR;
218 uint16_t bnxt_rss_hash_tbl_size(const struct bnxt *bp)
220 if (!BNXT_CHIP_THOR(bp))
221 return HW_HASH_INDEX_SIZE;
223 return bnxt_rss_ctxts(bp) * BNXT_RSS_ENTRIES_PER_CTX_THOR;
226 static void bnxt_free_parent_info(struct bnxt *bp)
228 rte_free(bp->parent);
231 static void bnxt_free_pf_info(struct bnxt *bp)
236 static void bnxt_free_link_info(struct bnxt *bp)
238 rte_free(bp->link_info);
241 static void bnxt_free_leds_info(struct bnxt *bp)
250 static void bnxt_free_flow_stats_info(struct bnxt *bp)
252 rte_free(bp->flow_stat);
253 bp->flow_stat = NULL;
256 static void bnxt_free_cos_queues(struct bnxt *bp)
258 rte_free(bp->rx_cos_queue);
259 rte_free(bp->tx_cos_queue);
262 static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
264 bnxt_free_filter_mem(bp);
265 bnxt_free_vnic_attributes(bp);
266 bnxt_free_vnic_mem(bp);
268 /* tx/rx rings are configured as part of *_queue_setup callbacks.
269 * If the number of rings change across fw update,
270 * we don't have much choice except to warn the user.
274 bnxt_free_tx_rings(bp);
275 bnxt_free_rx_rings(bp);
277 bnxt_free_async_cp_ring(bp);
278 bnxt_free_rxtx_nq_ring(bp);
280 rte_free(bp->grp_info);
284 static int bnxt_alloc_parent_info(struct bnxt *bp)
286 bp->parent = rte_zmalloc("bnxt_parent_info",
287 sizeof(struct bnxt_parent_info), 0);
288 if (bp->parent == NULL)
294 static int bnxt_alloc_pf_info(struct bnxt *bp)
296 bp->pf = rte_zmalloc("bnxt_pf_info", sizeof(struct bnxt_pf_info), 0);
303 static int bnxt_alloc_link_info(struct bnxt *bp)
306 rte_zmalloc("bnxt_link_info", sizeof(struct bnxt_link_info), 0);
307 if (bp->link_info == NULL)
313 static int bnxt_alloc_leds_info(struct bnxt *bp)
318 bp->leds = rte_zmalloc("bnxt_leds",
319 BNXT_MAX_LED * sizeof(struct bnxt_led_info),
321 if (bp->leds == NULL)
327 static int bnxt_alloc_cos_queues(struct bnxt *bp)
330 rte_zmalloc("bnxt_rx_cosq",
331 BNXT_COS_QUEUE_COUNT *
332 sizeof(struct bnxt_cos_queue_info),
334 if (bp->rx_cos_queue == NULL)
338 rte_zmalloc("bnxt_tx_cosq",
339 BNXT_COS_QUEUE_COUNT *
340 sizeof(struct bnxt_cos_queue_info),
342 if (bp->tx_cos_queue == NULL)
348 static int bnxt_alloc_flow_stats_info(struct bnxt *bp)
350 bp->flow_stat = rte_zmalloc("bnxt_flow_xstat",
351 sizeof(struct bnxt_flow_stat_info), 0);
352 if (bp->flow_stat == NULL)
358 static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
362 rc = bnxt_alloc_ring_grps(bp);
366 rc = bnxt_alloc_async_ring_struct(bp);
370 rc = bnxt_alloc_vnic_mem(bp);
374 rc = bnxt_alloc_vnic_attributes(bp);
378 rc = bnxt_alloc_filter_mem(bp);
382 rc = bnxt_alloc_async_cp_ring(bp);
386 rc = bnxt_alloc_rxtx_nq_ring(bp);
390 if (BNXT_FLOW_XSTATS_EN(bp)) {
391 rc = bnxt_alloc_flow_stats_info(bp);
399 bnxt_free_mem(bp, reconfig);
403 static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)
405 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
406 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
407 uint64_t rx_offloads = dev_conf->rxmode.offloads;
408 struct bnxt_rx_queue *rxq;
412 rc = bnxt_vnic_grp_alloc(bp, vnic);
416 PMD_DRV_LOG(DEBUG, "vnic[%d] = %p vnic->fw_grp_ids = %p\n",
417 vnic_id, vnic, vnic->fw_grp_ids);
419 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
423 /* Alloc RSS context only if RSS mode is enabled */
424 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS) {
425 int j, nr_ctxs = bnxt_rss_ctxts(bp);
428 for (j = 0; j < nr_ctxs; j++) {
429 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, j);
435 "HWRM vnic %d ctx %d alloc failure rc: %x\n",
439 vnic->num_lb_ctxts = nr_ctxs;
443 * Firmware sets pf pair in default vnic cfg. If the VLAN strip
444 * setting is not available at this time, it will not be
445 * configured correctly in the CFA.
447 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
448 vnic->vlan_strip = true;
450 vnic->vlan_strip = false;
452 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
456 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
460 for (j = 0; j < bp->rx_num_qs_per_vnic; j++) {
461 rxq = bp->eth_dev->data->rx_queues[j];
464 "rxq[%d]->vnic=%p vnic->fw_grp_ids=%p\n",
465 j, rxq->vnic, rxq->vnic->fw_grp_ids);
467 if (BNXT_HAS_RING_GRPS(bp) && rxq->rx_deferred_start)
468 rxq->vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
470 vnic->rx_queue_cnt++;
473 PMD_DRV_LOG(DEBUG, "vnic->rx_queue_cnt = %d\n", vnic->rx_queue_cnt);
475 rc = bnxt_vnic_rss_configure(bp, vnic);
479 bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
481 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
482 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 1);
484 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 0);
488 PMD_DRV_LOG(ERR, "HWRM vnic %d cfg failure rc: %x\n",
493 static int bnxt_register_fc_ctx_mem(struct bnxt *bp)
497 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_in_tbl.dma,
498 &bp->flow_stat->rx_fc_in_tbl.ctx_id);
503 "rx_fc_in_tbl.va = %p rx_fc_in_tbl.dma = %p"
504 " rx_fc_in_tbl.ctx_id = %d\n",
505 bp->flow_stat->rx_fc_in_tbl.va,
506 (void *)((uintptr_t)bp->flow_stat->rx_fc_in_tbl.dma),
507 bp->flow_stat->rx_fc_in_tbl.ctx_id);
509 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_out_tbl.dma,
510 &bp->flow_stat->rx_fc_out_tbl.ctx_id);
515 "rx_fc_out_tbl.va = %p rx_fc_out_tbl.dma = %p"
516 " rx_fc_out_tbl.ctx_id = %d\n",
517 bp->flow_stat->rx_fc_out_tbl.va,
518 (void *)((uintptr_t)bp->flow_stat->rx_fc_out_tbl.dma),
519 bp->flow_stat->rx_fc_out_tbl.ctx_id);
521 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_in_tbl.dma,
522 &bp->flow_stat->tx_fc_in_tbl.ctx_id);
527 "tx_fc_in_tbl.va = %p tx_fc_in_tbl.dma = %p"
528 " tx_fc_in_tbl.ctx_id = %d\n",
529 bp->flow_stat->tx_fc_in_tbl.va,
530 (void *)((uintptr_t)bp->flow_stat->tx_fc_in_tbl.dma),
531 bp->flow_stat->tx_fc_in_tbl.ctx_id);
533 rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_out_tbl.dma,
534 &bp->flow_stat->tx_fc_out_tbl.ctx_id);
539 "tx_fc_out_tbl.va = %p tx_fc_out_tbl.dma = %p"
540 " tx_fc_out_tbl.ctx_id = %d\n",
541 bp->flow_stat->tx_fc_out_tbl.va,
542 (void *)((uintptr_t)bp->flow_stat->tx_fc_out_tbl.dma),
543 bp->flow_stat->tx_fc_out_tbl.ctx_id);
545 memset(bp->flow_stat->rx_fc_out_tbl.va,
547 bp->flow_stat->rx_fc_out_tbl.size);
548 rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
549 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
550 bp->flow_stat->rx_fc_out_tbl.ctx_id,
551 bp->flow_stat->max_fc,
556 memset(bp->flow_stat->tx_fc_out_tbl.va,
558 bp->flow_stat->tx_fc_out_tbl.size);
559 rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
560 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
561 bp->flow_stat->tx_fc_out_tbl.ctx_id,
562 bp->flow_stat->max_fc,
568 static int bnxt_alloc_ctx_mem_buf(char *type, size_t size,
569 struct bnxt_ctx_mem_buf_info *ctx)
574 ctx->va = rte_zmalloc(type, size, 0);
577 rte_mem_lock_page(ctx->va);
579 ctx->dma = rte_mem_virt2iova(ctx->va);
580 if (ctx->dma == RTE_BAD_IOVA)
586 static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
588 struct rte_pci_device *pdev = bp->pdev;
589 char type[RTE_MEMZONE_NAMESIZE];
593 max_fc = bp->flow_stat->max_fc;
595 sprintf(type, "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
596 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
597 /* 4 bytes for each counter-id */
598 rc = bnxt_alloc_ctx_mem_buf(type,
600 &bp->flow_stat->rx_fc_in_tbl);
604 sprintf(type, "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
605 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
606 /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
607 rc = bnxt_alloc_ctx_mem_buf(type,
609 &bp->flow_stat->rx_fc_out_tbl);
613 sprintf(type, "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
614 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
615 /* 4 bytes for each counter-id */
616 rc = bnxt_alloc_ctx_mem_buf(type,
618 &bp->flow_stat->tx_fc_in_tbl);
622 sprintf(type, "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
623 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
624 /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
625 rc = bnxt_alloc_ctx_mem_buf(type,
627 &bp->flow_stat->tx_fc_out_tbl);
631 rc = bnxt_register_fc_ctx_mem(bp);
636 static int bnxt_init_ctx_mem(struct bnxt *bp)
640 if (!(bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS) ||
641 !(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) ||
642 !BNXT_FLOW_XSTATS_EN(bp))
645 rc = bnxt_hwrm_cfa_counter_qcaps(bp, &bp->flow_stat->max_fc);
649 rc = bnxt_init_fc_ctx_mem(bp);
654 static int bnxt_update_phy_setting(struct bnxt *bp)
656 struct rte_eth_link new;
659 rc = bnxt_get_hwrm_link_config(bp, &new);
661 PMD_DRV_LOG(ERR, "Failed to get link settings\n");
666 * On BCM957508-N2100 adapters, FW will not allow any user other
667 * than BMC to shutdown the port. bnxt_get_hwrm_link_config() call
668 * always returns link up. Force phy update always in that case.
670 if (!new.link_status || IS_BNXT_DEV_957508_N2100(bp)) {
671 rc = bnxt_set_hwrm_link_config(bp, true);
673 PMD_DRV_LOG(ERR, "Failed to update PHY settings\n");
681 static int bnxt_init_chip(struct bnxt *bp)
683 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(bp->eth_dev);
684 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
685 uint32_t intr_vector = 0;
686 uint32_t queue_id, base = BNXT_MISC_VEC_ID;
687 uint32_t vec = BNXT_MISC_VEC_ID;
691 if (bp->eth_dev->data->mtu > RTE_ETHER_MTU) {
692 bp->eth_dev->data->dev_conf.rxmode.offloads |=
693 DEV_RX_OFFLOAD_JUMBO_FRAME;
694 bp->flags |= BNXT_FLAG_JUMBO;
696 bp->eth_dev->data->dev_conf.rxmode.offloads &=
697 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
698 bp->flags &= ~BNXT_FLAG_JUMBO;
701 /* THOR does not support ring groups.
702 * But we will use the array to save RSS context IDs.
704 if (BNXT_CHIP_THOR(bp))
705 bp->max_ring_grps = BNXT_MAX_RSS_CTXTS_THOR;
707 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
709 PMD_DRV_LOG(ERR, "HWRM stat ctx alloc failure rc: %x\n", rc);
713 rc = bnxt_alloc_hwrm_rings(bp);
715 PMD_DRV_LOG(ERR, "HWRM ring alloc failure rc: %x\n", rc);
719 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
721 PMD_DRV_LOG(ERR, "HWRM ring grp alloc failure: %x\n", rc);
725 if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
728 for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
729 if (bp->rx_cos_queue[i].id != 0xff) {
730 struct bnxt_vnic_info *vnic = &bp->vnic_info[j++];
734 "Num pools more than FW profile\n");
738 vnic->cos_queue_id = bp->rx_cos_queue[i].id;
744 rc = bnxt_mq_rx_configure(bp);
746 PMD_DRV_LOG(ERR, "MQ mode configure failure rc: %x\n", rc);
750 /* VNIC configuration */
751 for (i = 0; i < bp->nr_vnics; i++) {
752 rc = bnxt_setup_one_vnic(bp, i);
757 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
760 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
764 /* check and configure queue intr-vector mapping */
765 if ((rte_intr_cap_multiple(intr_handle) ||
766 !RTE_ETH_DEV_SRIOV(bp->eth_dev).active) &&
767 bp->eth_dev->data->dev_conf.intr_conf.rxq != 0) {
768 intr_vector = bp->eth_dev->data->nb_rx_queues;
769 PMD_DRV_LOG(DEBUG, "intr_vector = %d\n", intr_vector);
770 if (intr_vector > bp->rx_cp_nr_rings) {
771 PMD_DRV_LOG(ERR, "At most %d intr queues supported",
775 rc = rte_intr_efd_enable(intr_handle, intr_vector);
780 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
781 intr_handle->intr_vec =
782 rte_zmalloc("intr_vec",
783 bp->eth_dev->data->nb_rx_queues *
785 if (intr_handle->intr_vec == NULL) {
786 PMD_DRV_LOG(ERR, "Failed to allocate %d rx_queues"
787 " intr_vec", bp->eth_dev->data->nb_rx_queues);
791 PMD_DRV_LOG(DEBUG, "intr_handle->intr_vec = %p "
792 "intr_handle->nb_efd = %d intr_handle->max_intr = %d\n",
793 intr_handle->intr_vec, intr_handle->nb_efd,
794 intr_handle->max_intr);
795 for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
797 intr_handle->intr_vec[queue_id] =
798 vec + BNXT_RX_VEC_START;
799 if (vec < base + intr_handle->nb_efd - 1)
804 /* enable uio/vfio intr/eventfd mapping */
805 rc = rte_intr_enable(intr_handle);
806 #ifndef RTE_EXEC_ENV_FREEBSD
807 /* In FreeBSD OS, nic_uio driver does not support interrupts */
812 rc = bnxt_update_phy_setting(bp);
816 bp->mark_table = rte_zmalloc("bnxt_mark_table", BNXT_MARK_TABLE_SZ, 0);
818 PMD_DRV_LOG(ERR, "Allocation of mark table failed\n");
823 rte_free(intr_handle->intr_vec);
825 rte_intr_efd_disable(intr_handle);
827 /* Some of the error status returned by FW may not be from errno.h */
834 static int bnxt_shutdown_nic(struct bnxt *bp)
836 bnxt_free_all_hwrm_resources(bp);
837 bnxt_free_all_filters(bp);
838 bnxt_free_all_vnics(bp);
843 * Device configuration and status function
846 uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
848 uint32_t link_speed = bp->link_info->support_speeds;
849 uint32_t speed_capa = 0;
851 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB)
852 speed_capa |= ETH_LINK_SPEED_100M;
853 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MBHD)
854 speed_capa |= ETH_LINK_SPEED_100M_HD;
855 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
856 speed_capa |= ETH_LINK_SPEED_1G;
857 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
858 speed_capa |= ETH_LINK_SPEED_2_5G;
859 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
860 speed_capa |= ETH_LINK_SPEED_10G;
861 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
862 speed_capa |= ETH_LINK_SPEED_20G;
863 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
864 speed_capa |= ETH_LINK_SPEED_25G;
865 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
866 speed_capa |= ETH_LINK_SPEED_40G;
867 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
868 speed_capa |= ETH_LINK_SPEED_50G;
869 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
870 speed_capa |= ETH_LINK_SPEED_100G;
871 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_50G)
872 speed_capa |= ETH_LINK_SPEED_50G;
873 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_100G)
874 speed_capa |= ETH_LINK_SPEED_100G;
875 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_200G)
876 speed_capa |= ETH_LINK_SPEED_200G;
878 if (bp->link_info->auto_mode ==
879 HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
880 speed_capa |= ETH_LINK_SPEED_FIXED;
882 speed_capa |= ETH_LINK_SPEED_AUTONEG;
887 static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
888 struct rte_eth_dev_info *dev_info)
890 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
891 struct bnxt *bp = eth_dev->data->dev_private;
892 uint16_t max_vnics, i, j, vpool, vrxq;
893 unsigned int max_rx_rings;
896 rc = is_bnxt_in_error(bp);
901 dev_info->max_mac_addrs = bp->max_l2_ctx;
902 dev_info->max_hash_mac_addrs = 0;
904 /* PF/VF specifics */
906 dev_info->max_vfs = pdev->max_vfs;
908 max_rx_rings = BNXT_MAX_RINGS(bp);
909 /* For the sake of symmetry, max_rx_queues = max_tx_queues */
910 dev_info->max_rx_queues = max_rx_rings;
911 dev_info->max_tx_queues = max_rx_rings;
912 dev_info->reta_size = bnxt_rss_hash_tbl_size(bp);
913 dev_info->hash_key_size = 40;
914 max_vnics = bp->max_vnics;
917 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
918 dev_info->max_mtu = BNXT_MAX_MTU;
920 /* Fast path specifics */
921 dev_info->min_rx_bufsize = 1;
922 dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
924 dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
925 if (bp->flags & BNXT_FLAG_PTP_SUPPORTED)
926 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TIMESTAMP;
927 dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
928 dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT |
929 dev_info->tx_queue_offload_capa;
930 dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
932 dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
935 dev_info->default_rxconf = (struct rte_eth_rxconf) {
941 .rx_free_thresh = 32,
942 .rx_drop_en = BNXT_DEFAULT_RX_DROP_EN,
945 dev_info->default_txconf = (struct rte_eth_txconf) {
951 .tx_free_thresh = 32,
954 eth_dev->data->dev_conf.intr_conf.lsc = 1;
956 eth_dev->data->dev_conf.intr_conf.rxq = 1;
957 dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
958 dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
959 dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
960 dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
962 if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
963 dev_info->switch_info.name = eth_dev->device->name;
964 dev_info->switch_info.domain_id = bp->switch_domain_id;
965 dev_info->switch_info.port_id =
966 BNXT_PF(bp) ? BNXT_SWITCH_PORT_ID_PF :
967 BNXT_SWITCH_PORT_ID_TRUSTED_VF;
973 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
974 * need further investigation.
978 vpool = 64; /* ETH_64_POOLS */
979 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
980 for (i = 0; i < 4; vpool >>= 1, i++) {
981 if (max_vnics > vpool) {
982 for (j = 0; j < 5; vrxq >>= 1, j++) {
983 if (dev_info->max_rx_queues > vrxq) {
989 /* Not enough resources to support VMDq */
993 /* Not enough resources to support VMDq */
997 dev_info->max_vmdq_pools = vpool;
998 dev_info->vmdq_queue_num = vrxq;
1000 dev_info->vmdq_pool_base = 0;
1001 dev_info->vmdq_queue_base = 0;
1006 /* Configure the device based on the configuration provided */
1007 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
1009 struct bnxt *bp = eth_dev->data->dev_private;
1010 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
1013 bp->rx_queues = (void *)eth_dev->data->rx_queues;
1014 bp->tx_queues = (void *)eth_dev->data->tx_queues;
1015 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
1016 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
1018 rc = is_bnxt_in_error(bp);
1022 if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
1023 rc = bnxt_hwrm_check_vf_rings(bp);
1025 PMD_DRV_LOG(ERR, "HWRM insufficient resources\n");
1029 /* If a resource has already been allocated - in this case
1030 * it is the async completion ring, free it. Reallocate it after
1031 * resource reservation. This will ensure the resource counts
1032 * are calculated correctly.
1035 pthread_mutex_lock(&bp->def_cp_lock);
1037 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
1038 bnxt_disable_int(bp);
1039 bnxt_free_cp_ring(bp, bp->async_cp_ring);
1042 rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
1044 PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc);
1045 pthread_mutex_unlock(&bp->def_cp_lock);
1049 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
1050 rc = bnxt_alloc_async_cp_ring(bp);
1052 pthread_mutex_unlock(&bp->def_cp_lock);
1055 bnxt_enable_int(bp);
1058 pthread_mutex_unlock(&bp->def_cp_lock);
1060 /* legacy driver needs to get updated values */
1061 rc = bnxt_hwrm_func_qcaps(bp);
1063 PMD_DRV_LOG(ERR, "hwrm func qcaps fail:%d\n", rc);
1068 /* Inherit new configurations */
1069 if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
1070 eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
1071 eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
1072 + BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
1073 eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
1075 goto resource_error;
1077 if (BNXT_HAS_RING_GRPS(bp) &&
1078 (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
1079 goto resource_error;
1081 if (!(eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS) &&
1082 bp->max_vnics < eth_dev->data->nb_rx_queues)
1083 goto resource_error;
1085 bp->rx_cp_nr_rings = bp->rx_nr_rings;
1086 bp->tx_cp_nr_rings = bp->tx_nr_rings;
1088 if (eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
1089 rx_offloads |= DEV_RX_OFFLOAD_RSS_HASH;
1090 eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
1092 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
1093 eth_dev->data->mtu =
1094 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
1095 RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE *
1097 bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
1103 "Insufficient resources to support requested config\n");
1105 "Num Queues Requested: Tx %d, Rx %d\n",
1106 eth_dev->data->nb_tx_queues,
1107 eth_dev->data->nb_rx_queues);
1109 "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d\n",
1110 bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
1111 bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
1115 void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
1117 struct rte_eth_link *link = ð_dev->data->dev_link;
1119 if (link->link_status)
1120 PMD_DRV_LOG(INFO, "Port %d Link Up - speed %u Mbps - %s\n",
1121 eth_dev->data->port_id,
1122 (uint32_t)link->link_speed,
1123 (link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
1124 ("full-duplex") : ("half-duplex\n"));
1126 PMD_DRV_LOG(INFO, "Port %d Link Down\n",
1127 eth_dev->data->port_id);
1131 * Determine whether the current configuration requires support for scattered
1132 * receive; return 1 if scattered receive is required and 0 if not.
1134 static int bnxt_scattered_rx(struct rte_eth_dev *eth_dev)
1139 if (eth_dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER)
1142 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1143 struct bnxt_rx_queue *rxq = eth_dev->data->rx_queues[i];
1145 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
1146 RTE_PKTMBUF_HEADROOM);
1147 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len > buf_size)
1153 static eth_rx_burst_t
1154 bnxt_receive_function(struct rte_eth_dev *eth_dev)
1156 struct bnxt *bp = eth_dev->data->dev_private;
1158 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
1159 #ifndef RTE_LIBRTE_IEEE1588
1161 * Vector mode receive can be enabled only if scatter rx is not
1162 * in use and rx offloads are limited to VLAN stripping and
1165 if (!eth_dev->data->scattered_rx &&
1166 !(eth_dev->data->dev_conf.rxmode.offloads &
1167 ~(DEV_RX_OFFLOAD_VLAN_STRIP |
1168 DEV_RX_OFFLOAD_KEEP_CRC |
1169 DEV_RX_OFFLOAD_JUMBO_FRAME |
1170 DEV_RX_OFFLOAD_IPV4_CKSUM |
1171 DEV_RX_OFFLOAD_UDP_CKSUM |
1172 DEV_RX_OFFLOAD_TCP_CKSUM |
1173 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
1174 DEV_RX_OFFLOAD_RSS_HASH |
1175 DEV_RX_OFFLOAD_VLAN_FILTER)) &&
1176 !BNXT_TRUFLOW_EN(bp) && BNXT_NUM_ASYNC_CPR(bp) &&
1177 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
1178 PMD_DRV_LOG(INFO, "Using vector mode receive for port %d\n",
1179 eth_dev->data->port_id);
1180 bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
1181 return bnxt_recv_pkts_vec;
1183 PMD_DRV_LOG(INFO, "Vector mode receive disabled for port %d\n",
1184 eth_dev->data->port_id);
1186 "Port %d scatter: %d rx offload: %" PRIX64 "\n",
1187 eth_dev->data->port_id,
1188 eth_dev->data->scattered_rx,
1189 eth_dev->data->dev_conf.rxmode.offloads);
1192 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1193 return bnxt_recv_pkts;
1196 static eth_tx_burst_t
1197 bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
1199 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
1200 #ifndef RTE_LIBRTE_IEEE1588
1201 uint64_t offloads = eth_dev->data->dev_conf.txmode.offloads;
1202 struct bnxt *bp = eth_dev->data->dev_private;
1205 * Vector mode transmit can be enabled only if not using scatter rx
1208 if (!eth_dev->data->scattered_rx &&
1209 !(offloads & ~DEV_TX_OFFLOAD_MBUF_FAST_FREE) &&
1210 !BNXT_TRUFLOW_EN(bp) &&
1211 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
1212 PMD_DRV_LOG(INFO, "Using vector mode transmit for port %d\n",
1213 eth_dev->data->port_id);
1214 return bnxt_xmit_pkts_vec;
1216 PMD_DRV_LOG(INFO, "Vector mode transmit disabled for port %d\n",
1217 eth_dev->data->port_id);
1219 "Port %d scatter: %d tx offload: %" PRIX64 "\n",
1220 eth_dev->data->port_id,
1221 eth_dev->data->scattered_rx,
1225 return bnxt_xmit_pkts;
1228 static int bnxt_handle_if_change_status(struct bnxt *bp)
1232 /* Since fw has undergone a reset and lost all contexts,
1233 * set fatal flag to not issue hwrm during cleanup
1235 bp->flags |= BNXT_FLAG_FATAL_ERROR;
1236 bnxt_uninit_resources(bp, true);
1238 /* clear fatal flag so that re-init happens */
1239 bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
1240 rc = bnxt_init_resources(bp, true);
1242 bp->flags &= ~BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
1247 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
1249 struct bnxt *bp = eth_dev->data->dev_private;
1250 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
1252 int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
1254 if (!eth_dev->data->nb_tx_queues || !eth_dev->data->nb_rx_queues) {
1255 PMD_DRV_LOG(ERR, "Queues are not configured yet!\n");
1259 if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1261 "RxQ cnt %d > RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
1262 bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1266 rc = bnxt_hwrm_if_change(bp, true);
1267 if (rc == 0 || rc != -EAGAIN)
1270 rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
1271 } while (retry_cnt--);
1276 if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
1277 rc = bnxt_handle_if_change_status(bp);
1282 bnxt_enable_int(bp);
1284 rc = bnxt_init_chip(bp);
1288 eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
1289 eth_dev->data->dev_started = 1;
1291 bnxt_link_update_op(eth_dev, 1);
1293 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1294 vlan_mask |= ETH_VLAN_FILTER_MASK;
1295 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1296 vlan_mask |= ETH_VLAN_STRIP_MASK;
1297 rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
1301 /* Initialize bnxt ULP port details */
1302 rc = bnxt_ulp_port_init(bp);
1306 eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
1307 eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
1309 bnxt_schedule_fw_health_check(bp);
1314 bnxt_shutdown_nic(bp);
1315 bnxt_free_tx_mbufs(bp);
1316 bnxt_free_rx_mbufs(bp);
1317 bnxt_hwrm_if_change(bp, false);
1318 eth_dev->data->dev_started = 0;
1322 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
1324 struct bnxt *bp = eth_dev->data->dev_private;
1327 if (!bp->link_info->link_up)
1328 rc = bnxt_set_hwrm_link_config(bp, true);
1330 eth_dev->data->dev_link.link_status = 1;
1332 bnxt_print_link_info(eth_dev);
1336 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
1338 struct bnxt *bp = eth_dev->data->dev_private;
1340 eth_dev->data->dev_link.link_status = 0;
1341 bnxt_set_hwrm_link_config(bp, false);
1342 bp->link_info->link_up = 0;
1347 static void bnxt_free_switch_domain(struct bnxt *bp)
1349 if (bp->switch_domain_id)
1350 rte_eth_switch_domain_free(bp->switch_domain_id);
1353 /* Unload the driver, release resources */
1354 static int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
1356 struct bnxt *bp = eth_dev->data->dev_private;
1357 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1358 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1359 struct rte_eth_link link;
1362 eth_dev->data->dev_started = 0;
1363 eth_dev->data->scattered_rx = 0;
1365 /* Prevent crashes when queues are still in use */
1366 eth_dev->rx_pkt_burst = &bnxt_dummy_recv_pkts;
1367 eth_dev->tx_pkt_burst = &bnxt_dummy_xmit_pkts;
1369 bnxt_disable_int(bp);
1371 /* disable uio/vfio intr/eventfd mapping */
1372 rte_intr_disable(intr_handle);
1374 /* Stop the child representors for this device */
1375 ret = bnxt_rep_stop_all(bp);
1379 /* delete the bnxt ULP port details */
1380 bnxt_ulp_port_deinit(bp);
1382 bnxt_cancel_fw_health_check(bp);
1384 /* Do not bring link down during reset recovery */
1385 if (!is_bnxt_in_error(bp)) {
1386 bnxt_dev_set_link_down_op(eth_dev);
1387 /* Wait for link to be reset */
1388 if (BNXT_SINGLE_PF(bp))
1390 /* clear the recorded link status */
1391 memset(&link, 0, sizeof(link));
1392 rte_eth_linkstatus_set(eth_dev, &link);
1395 /* Clean queue intr-vector mapping */
1396 rte_intr_efd_disable(intr_handle);
1397 if (intr_handle->intr_vec != NULL) {
1398 rte_free(intr_handle->intr_vec);
1399 intr_handle->intr_vec = NULL;
1402 bnxt_hwrm_port_clr_stats(bp);
1403 bnxt_free_tx_mbufs(bp);
1404 bnxt_free_rx_mbufs(bp);
1405 /* Process any remaining notifications in default completion queue */
1406 bnxt_int_handler(eth_dev);
1407 bnxt_shutdown_nic(bp);
1408 bnxt_hwrm_if_change(bp, false);
1410 rte_free(bp->mark_table);
1411 bp->mark_table = NULL;
1413 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1414 bp->rx_cosq_cnt = 0;
1415 /* All filters are deleted on a port stop. */
1416 if (BNXT_FLOW_XSTATS_EN(bp))
1417 bp->flow_stat->flow_count = 0;
1422 static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
1424 struct bnxt *bp = eth_dev->data->dev_private;
1427 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1430 /* cancel the recovery handler before remove dev */
1431 rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
1432 rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
1433 bnxt_cancel_fc_thread(bp);
1435 if (eth_dev->data->dev_started)
1436 ret = bnxt_dev_stop_op(eth_dev);
1438 bnxt_free_switch_domain(bp);
1440 bnxt_uninit_resources(bp, false);
1442 bnxt_free_leds_info(bp);
1443 bnxt_free_cos_queues(bp);
1444 bnxt_free_link_info(bp);
1445 bnxt_free_pf_info(bp);
1446 bnxt_free_parent_info(bp);
1448 rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
1449 bp->tx_mem_zone = NULL;
1450 rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
1451 bp->rx_mem_zone = NULL;
1453 bnxt_hwrm_free_vf_info(bp);
1455 rte_free(bp->grp_info);
1456 bp->grp_info = NULL;
1461 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
1464 struct bnxt *bp = eth_dev->data->dev_private;
1465 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
1466 struct bnxt_vnic_info *vnic;
1467 struct bnxt_filter_info *filter, *temp_filter;
1470 if (is_bnxt_in_error(bp))
1474 * Loop through all VNICs from the specified filter flow pools to
1475 * remove the corresponding MAC addr filter
1477 for (i = 0; i < bp->nr_vnics; i++) {
1478 if (!(pool_mask & (1ULL << i)))
1481 vnic = &bp->vnic_info[i];
1482 filter = STAILQ_FIRST(&vnic->filter);
1484 temp_filter = STAILQ_NEXT(filter, next);
1485 if (filter->mac_index == index) {
1486 STAILQ_REMOVE(&vnic->filter, filter,
1487 bnxt_filter_info, next);
1488 bnxt_hwrm_clear_l2_filter(bp, filter);
1489 bnxt_free_filter(bp, filter);
1491 filter = temp_filter;
1496 static int bnxt_add_mac_filter(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1497 struct rte_ether_addr *mac_addr, uint32_t index,
1500 struct bnxt_filter_info *filter;
1503 /* Attach requested MAC address to the new l2_filter */
1504 STAILQ_FOREACH(filter, &vnic->filter, next) {
1505 if (filter->mac_index == index) {
1507 "MAC addr already existed for pool %d\n",
1513 filter = bnxt_alloc_filter(bp);
1515 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
1519 /* bnxt_alloc_filter copies default MAC to filter->l2_addr. So,
1520 * if the MAC that's been programmed now is a different one, then,
1521 * copy that addr to filter->l2_addr
1524 memcpy(filter->l2_addr, mac_addr, RTE_ETHER_ADDR_LEN);
1525 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
1527 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
1529 filter->mac_index = index;
1530 if (filter->mac_index == 0)
1531 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
1533 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
1535 bnxt_free_filter(bp, filter);
1541 static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
1542 struct rte_ether_addr *mac_addr,
1543 uint32_t index, uint32_t pool)
1545 struct bnxt *bp = eth_dev->data->dev_private;
1546 struct bnxt_vnic_info *vnic = &bp->vnic_info[pool];
1549 rc = is_bnxt_in_error(bp);
1553 if (BNXT_VF(bp) & !BNXT_VF_IS_TRUSTED(bp)) {
1554 PMD_DRV_LOG(ERR, "Cannot add MAC address to a VF interface\n");
1559 PMD_DRV_LOG(ERR, "VNIC not found for pool %d!\n", pool);
1563 /* Filter settings will get applied when port is started */
1564 if (!eth_dev->data->dev_started)
1567 rc = bnxt_add_mac_filter(bp, vnic, mac_addr, index, pool);
1572 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
1575 struct bnxt *bp = eth_dev->data->dev_private;
1576 struct rte_eth_link new;
1577 int cnt = wait_to_complete ? BNXT_MAX_LINK_WAIT_CNT :
1578 BNXT_MIN_LINK_WAIT_CNT;
1580 rc = is_bnxt_in_error(bp);
1584 memset(&new, 0, sizeof(new));
1586 /* Retrieve link info from hardware */
1587 rc = bnxt_get_hwrm_link_config(bp, &new);
1589 new.link_speed = ETH_LINK_SPEED_100M;
1590 new.link_duplex = ETH_LINK_FULL_DUPLEX;
1592 "Failed to retrieve link rc = 0x%x!\n", rc);
1596 if (!wait_to_complete || new.link_status)
1599 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
1602 /* Only single function PF can bring phy down.
1603 * When port is stopped, report link down for VF/MH/NPAR functions.
1605 if (!BNXT_SINGLE_PF(bp) && !eth_dev->data->dev_started)
1606 memset(&new, 0, sizeof(new));
1609 /* Timed out or success */
1610 if (new.link_status != eth_dev->data->dev_link.link_status ||
1611 new.link_speed != eth_dev->data->dev_link.link_speed) {
1612 rte_eth_linkstatus_set(eth_dev, &new);
1614 rte_eth_dev_callback_process(eth_dev,
1615 RTE_ETH_EVENT_INTR_LSC,
1618 bnxt_print_link_info(eth_dev);
1624 static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
1626 struct bnxt *bp = eth_dev->data->dev_private;
1627 struct bnxt_vnic_info *vnic;
1631 rc = is_bnxt_in_error(bp);
1635 /* Filter settings will get applied when port is started */
1636 if (!eth_dev->data->dev_started)
1639 if (bp->vnic_info == NULL)
1642 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1644 old_flags = vnic->flags;
1645 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
1646 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1648 vnic->flags = old_flags;
1653 static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
1655 struct bnxt *bp = eth_dev->data->dev_private;
1656 struct bnxt_vnic_info *vnic;
1660 rc = is_bnxt_in_error(bp);
1664 /* Filter settings will get applied when port is started */
1665 if (!eth_dev->data->dev_started)
1668 if (bp->vnic_info == NULL)
1671 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1673 old_flags = vnic->flags;
1674 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
1675 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1677 vnic->flags = old_flags;
1682 static int bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
1684 struct bnxt *bp = eth_dev->data->dev_private;
1685 struct bnxt_vnic_info *vnic;
1689 rc = is_bnxt_in_error(bp);
1693 /* Filter settings will get applied when port is started */
1694 if (!eth_dev->data->dev_started)
1697 if (bp->vnic_info == NULL)
1700 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1702 old_flags = vnic->flags;
1703 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
1704 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1706 vnic->flags = old_flags;
1711 static int bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
1713 struct bnxt *bp = eth_dev->data->dev_private;
1714 struct bnxt_vnic_info *vnic;
1718 rc = is_bnxt_in_error(bp);
1722 /* Filter settings will get applied when port is started */
1723 if (!eth_dev->data->dev_started)
1726 if (bp->vnic_info == NULL)
1729 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1731 old_flags = vnic->flags;
1732 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
1733 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1735 vnic->flags = old_flags;
1740 /* Return bnxt_rx_queue pointer corresponding to a given rxq. */
1741 static struct bnxt_rx_queue *bnxt_qid_to_rxq(struct bnxt *bp, uint16_t qid)
1743 if (qid >= bp->rx_nr_rings)
1746 return bp->eth_dev->data->rx_queues[qid];
1749 /* Return rxq corresponding to a given rss table ring/group ID. */
1750 static uint16_t bnxt_rss_to_qid(struct bnxt *bp, uint16_t fwr)
1752 struct bnxt_rx_queue *rxq;
1755 if (!BNXT_HAS_RING_GRPS(bp)) {
1756 for (i = 0; i < bp->rx_nr_rings; i++) {
1757 rxq = bp->eth_dev->data->rx_queues[i];
1758 if (rxq->rx_ring->rx_ring_struct->fw_ring_id == fwr)
1762 for (i = 0; i < bp->rx_nr_rings; i++) {
1763 if (bp->grp_info[i].fw_grp_id == fwr)
1768 return INVALID_HW_RING_ID;
1771 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
1772 struct rte_eth_rss_reta_entry64 *reta_conf,
1775 struct bnxt *bp = eth_dev->data->dev_private;
1776 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1777 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1778 uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
1782 rc = is_bnxt_in_error(bp);
1786 if (!vnic->rss_table)
1789 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
1792 if (reta_size != tbl_size) {
1793 PMD_DRV_LOG(ERR, "The configured hash table lookup size "
1794 "(%d) must equal the size supported by the hardware "
1795 "(%d)\n", reta_size, tbl_size);
1799 for (i = 0; i < reta_size; i++) {
1800 struct bnxt_rx_queue *rxq;
1802 idx = i / RTE_RETA_GROUP_SIZE;
1803 sft = i % RTE_RETA_GROUP_SIZE;
1805 if (!(reta_conf[idx].mask & (1ULL << sft)))
1808 rxq = bnxt_qid_to_rxq(bp, reta_conf[idx].reta[sft]);
1810 PMD_DRV_LOG(ERR, "Invalid ring in reta_conf.\n");
1814 if (BNXT_CHIP_THOR(bp)) {
1815 vnic->rss_table[i * 2] =
1816 rxq->rx_ring->rx_ring_struct->fw_ring_id;
1817 vnic->rss_table[i * 2 + 1] =
1818 rxq->cp_ring->cp_ring_struct->fw_ring_id;
1820 vnic->rss_table[i] =
1821 vnic->fw_grp_ids[reta_conf[idx].reta[sft]];
1825 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
1829 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
1830 struct rte_eth_rss_reta_entry64 *reta_conf,
1833 struct bnxt *bp = eth_dev->data->dev_private;
1834 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1835 uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
1836 uint16_t idx, sft, i;
1839 rc = is_bnxt_in_error(bp);
1843 /* Retrieve from the default VNIC */
1846 if (!vnic->rss_table)
1849 if (reta_size != tbl_size) {
1850 PMD_DRV_LOG(ERR, "The configured hash table lookup size "
1851 "(%d) must equal the size supported by the hardware "
1852 "(%d)\n", reta_size, tbl_size);
1856 for (idx = 0, i = 0; i < reta_size; i++) {
1857 idx = i / RTE_RETA_GROUP_SIZE;
1858 sft = i % RTE_RETA_GROUP_SIZE;
1860 if (reta_conf[idx].mask & (1ULL << sft)) {
1863 if (BNXT_CHIP_THOR(bp))
1864 qid = bnxt_rss_to_qid(bp,
1865 vnic->rss_table[i * 2]);
1867 qid = bnxt_rss_to_qid(bp, vnic->rss_table[i]);
1869 if (qid == INVALID_HW_RING_ID) {
1870 PMD_DRV_LOG(ERR, "Inv. entry in rss table.\n");
1873 reta_conf[idx].reta[sft] = qid;
1880 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
1881 struct rte_eth_rss_conf *rss_conf)
1883 struct bnxt *bp = eth_dev->data->dev_private;
1884 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1885 struct bnxt_vnic_info *vnic;
1888 rc = is_bnxt_in_error(bp);
1893 * If RSS enablement were different than dev_configure,
1894 * then return -EINVAL
1896 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
1897 if (!rss_conf->rss_hf)
1898 PMD_DRV_LOG(ERR, "Hash type NONE\n");
1900 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
1904 bp->flags |= BNXT_FLAG_UPDATE_HASH;
1905 memcpy(ð_dev->data->dev_conf.rx_adv_conf.rss_conf,
1909 /* Update the default RSS VNIC(s) */
1910 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1911 vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
1913 bnxt_rte_to_hwrm_hash_level(bp, rss_conf->rss_hf,
1914 ETH_RSS_LEVEL(rss_conf->rss_hf));
1917 * If hashkey is not specified, use the previously configured
1920 if (!rss_conf->rss_key)
1923 if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE) {
1925 "Invalid hashkey length, should be 16 bytes\n");
1928 memcpy(vnic->rss_hash_key, rss_conf->rss_key, rss_conf->rss_key_len);
1931 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
1935 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
1936 struct rte_eth_rss_conf *rss_conf)
1938 struct bnxt *bp = eth_dev->data->dev_private;
1939 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1941 uint32_t hash_types;
1943 rc = is_bnxt_in_error(bp);
1947 /* RSS configuration is the same for all VNICs */
1948 if (vnic && vnic->rss_hash_key) {
1949 if (rss_conf->rss_key) {
1950 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
1951 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
1952 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
1955 hash_types = vnic->hash_type;
1956 rss_conf->rss_hf = 0;
1957 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
1958 rss_conf->rss_hf |= ETH_RSS_IPV4;
1959 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
1961 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
1962 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
1964 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
1966 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
1967 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
1969 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
1971 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
1972 rss_conf->rss_hf |= ETH_RSS_IPV6;
1973 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
1975 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
1976 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
1978 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
1980 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
1981 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
1983 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
1987 bnxt_hwrm_to_rte_rss_level(bp, vnic->hash_mode);
1991 "Unknown RSS config from firmware (%08x), RSS disabled",
1996 rss_conf->rss_hf = 0;
2001 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
2002 struct rte_eth_fc_conf *fc_conf)
2004 struct bnxt *bp = dev->data->dev_private;
2005 struct rte_eth_link link_info;
2008 rc = is_bnxt_in_error(bp);
2012 rc = bnxt_get_hwrm_link_config(bp, &link_info);
2016 memset(fc_conf, 0, sizeof(*fc_conf));
2017 if (bp->link_info->auto_pause)
2018 fc_conf->autoneg = 1;
2019 switch (bp->link_info->pause) {
2021 fc_conf->mode = RTE_FC_NONE;
2023 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
2024 fc_conf->mode = RTE_FC_TX_PAUSE;
2026 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
2027 fc_conf->mode = RTE_FC_RX_PAUSE;
2029 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2030 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
2031 fc_conf->mode = RTE_FC_FULL;
2037 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
2038 struct rte_eth_fc_conf *fc_conf)
2040 struct bnxt *bp = dev->data->dev_private;
2043 rc = is_bnxt_in_error(bp);
2047 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp)) {
2048 PMD_DRV_LOG(ERR, "Flow Control Settings cannot be modified\n");
2052 switch (fc_conf->mode) {
2054 bp->link_info->auto_pause = 0;
2055 bp->link_info->force_pause = 0;
2057 case RTE_FC_RX_PAUSE:
2058 if (fc_conf->autoneg) {
2059 bp->link_info->auto_pause =
2060 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
2061 bp->link_info->force_pause = 0;
2063 bp->link_info->auto_pause = 0;
2064 bp->link_info->force_pause =
2065 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
2068 case RTE_FC_TX_PAUSE:
2069 if (fc_conf->autoneg) {
2070 bp->link_info->auto_pause =
2071 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
2072 bp->link_info->force_pause = 0;
2074 bp->link_info->auto_pause = 0;
2075 bp->link_info->force_pause =
2076 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
2080 if (fc_conf->autoneg) {
2081 bp->link_info->auto_pause =
2082 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
2083 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
2084 bp->link_info->force_pause = 0;
2086 bp->link_info->auto_pause = 0;
2087 bp->link_info->force_pause =
2088 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
2089 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
2093 return bnxt_set_hwrm_link_config(bp, true);
2096 /* Add UDP tunneling port */
2098 bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
2099 struct rte_eth_udp_tunnel *udp_tunnel)
2101 struct bnxt *bp = eth_dev->data->dev_private;
2102 uint16_t tunnel_type = 0;
2105 rc = is_bnxt_in_error(bp);
2109 switch (udp_tunnel->prot_type) {
2110 case RTE_TUNNEL_TYPE_VXLAN:
2111 if (bp->vxlan_port_cnt) {
2112 PMD_DRV_LOG(ERR, "Tunnel Port %d already programmed\n",
2113 udp_tunnel->udp_port);
2114 if (bp->vxlan_port != udp_tunnel->udp_port) {
2115 PMD_DRV_LOG(ERR, "Only one port allowed\n");
2118 bp->vxlan_port_cnt++;
2122 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
2123 bp->vxlan_port_cnt++;
2125 case RTE_TUNNEL_TYPE_GENEVE:
2126 if (bp->geneve_port_cnt) {
2127 PMD_DRV_LOG(ERR, "Tunnel Port %d already programmed\n",
2128 udp_tunnel->udp_port);
2129 if (bp->geneve_port != udp_tunnel->udp_port) {
2130 PMD_DRV_LOG(ERR, "Only one port allowed\n");
2133 bp->geneve_port_cnt++;
2137 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
2138 bp->geneve_port_cnt++;
2141 PMD_DRV_LOG(ERR, "Tunnel type is not supported\n");
2144 rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
2150 bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
2151 struct rte_eth_udp_tunnel *udp_tunnel)
2153 struct bnxt *bp = eth_dev->data->dev_private;
2154 uint16_t tunnel_type = 0;
2158 rc = is_bnxt_in_error(bp);
2162 switch (udp_tunnel->prot_type) {
2163 case RTE_TUNNEL_TYPE_VXLAN:
2164 if (!bp->vxlan_port_cnt) {
2165 PMD_DRV_LOG(ERR, "No Tunnel port configured yet\n");
2168 if (bp->vxlan_port != udp_tunnel->udp_port) {
2169 PMD_DRV_LOG(ERR, "Req Port: %d. Configured port: %d\n",
2170 udp_tunnel->udp_port, bp->vxlan_port);
2173 if (--bp->vxlan_port_cnt)
2177 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
2178 port = bp->vxlan_fw_dst_port_id;
2180 case RTE_TUNNEL_TYPE_GENEVE:
2181 if (!bp->geneve_port_cnt) {
2182 PMD_DRV_LOG(ERR, "No Tunnel port configured yet\n");
2185 if (bp->geneve_port != udp_tunnel->udp_port) {
2186 PMD_DRV_LOG(ERR, "Req Port: %d. Configured port: %d\n",
2187 udp_tunnel->udp_port, bp->geneve_port);
2190 if (--bp->geneve_port_cnt)
2194 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
2195 port = bp->geneve_fw_dst_port_id;
2198 PMD_DRV_LOG(ERR, "Tunnel type is not supported\n");
2202 rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
2206 static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2208 struct bnxt_filter_info *filter;
2209 struct bnxt_vnic_info *vnic;
2211 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2213 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2214 filter = STAILQ_FIRST(&vnic->filter);
2216 /* Search for this matching MAC+VLAN filter */
2217 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id)) {
2218 /* Delete the filter */
2219 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2222 STAILQ_REMOVE(&vnic->filter, filter,
2223 bnxt_filter_info, next);
2224 bnxt_free_filter(bp, filter);
2226 "Deleted vlan filter for %d\n",
2230 filter = STAILQ_NEXT(filter, next);
2235 static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2237 struct bnxt_filter_info *filter;
2238 struct bnxt_vnic_info *vnic;
2240 uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
2241 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
2242 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2244 /* Implementation notes on the use of VNIC in this command:
2246 * By default, these filters belong to default vnic for the function.
2247 * Once these filters are set up, only destination VNIC can be modified.
2248 * If the destination VNIC is not specified in this command,
2249 * then the HWRM shall only create an l2 context id.
2252 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2253 filter = STAILQ_FIRST(&vnic->filter);
2254 /* Check if the VLAN has already been added */
2256 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id))
2259 filter = STAILQ_NEXT(filter, next);
2262 /* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
2263 * command to create MAC+VLAN filter with the right flags, enables set.
2265 filter = bnxt_alloc_filter(bp);
2268 "MAC/VLAN filter alloc failed\n");
2271 /* MAC + VLAN ID filter */
2272 /* If l2_ivlan == 0 and l2_ivlan_mask != 0, only
2273 * untagged packets are received
2275 * If l2_ivlan != 0 and l2_ivlan_mask != 0, untagged
2276 * packets and only the programmed vlan's packets are received
2278 filter->l2_ivlan = vlan_id;
2279 filter->l2_ivlan_mask = 0x0FFF;
2280 filter->enables |= en;
2281 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
2283 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
2285 /* Free the newly allocated filter as we were
2286 * not able to create the filter in hardware.
2288 bnxt_free_filter(bp, filter);
2292 filter->mac_index = 0;
2293 /* Add this new filter to the list */
2295 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
2297 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
2300 "Added Vlan filter for %d\n", vlan_id);
2304 static int bnxt_vlan_filter_set_op(struct rte_eth_dev *eth_dev,
2305 uint16_t vlan_id, int on)
2307 struct bnxt *bp = eth_dev->data->dev_private;
2310 rc = is_bnxt_in_error(bp);
2314 if (!eth_dev->data->dev_started) {
2315 PMD_DRV_LOG(ERR, "port must be started before setting vlan\n");
2319 /* These operations apply to ALL existing MAC/VLAN filters */
2321 return bnxt_add_vlan_filter(bp, vlan_id);
2323 return bnxt_del_vlan_filter(bp, vlan_id);
2326 static int bnxt_del_dflt_mac_filter(struct bnxt *bp,
2327 struct bnxt_vnic_info *vnic)
2329 struct bnxt_filter_info *filter;
2332 filter = STAILQ_FIRST(&vnic->filter);
2334 if (filter->mac_index == 0 &&
2335 !memcmp(filter->l2_addr, bp->mac_addr,
2336 RTE_ETHER_ADDR_LEN)) {
2337 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2339 STAILQ_REMOVE(&vnic->filter, filter,
2340 bnxt_filter_info, next);
2341 bnxt_free_filter(bp, filter);
2345 filter = STAILQ_NEXT(filter, next);
2351 bnxt_config_vlan_hw_filter(struct bnxt *bp, uint64_t rx_offloads)
2353 struct bnxt_vnic_info *vnic;
2357 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2358 if (!(rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)) {
2359 /* Remove any VLAN filters programmed */
2360 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2361 bnxt_del_vlan_filter(bp, i);
2363 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2367 /* Default filter will allow packets that match the
2368 * dest mac. So, it has to be deleted, otherwise, we
2369 * will endup receiving vlan packets for which the
2370 * filter is not programmed, when hw-vlan-filter
2371 * configuration is ON
2373 bnxt_del_dflt_mac_filter(bp, vnic);
2374 /* This filter will allow only untagged packets */
2375 bnxt_add_vlan_filter(bp, 0);
2377 PMD_DRV_LOG(DEBUG, "VLAN Filtering: %d\n",
2378 !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER));
2383 static int bnxt_free_one_vnic(struct bnxt *bp, uint16_t vnic_id)
2385 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
2389 /* Destroy vnic filters and vnic */
2390 if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2391 DEV_RX_OFFLOAD_VLAN_FILTER) {
2392 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2393 bnxt_del_vlan_filter(bp, i);
2395 bnxt_del_dflt_mac_filter(bp, vnic);
2397 rc = bnxt_hwrm_vnic_free(bp, vnic);
2401 rte_free(vnic->fw_grp_ids);
2402 vnic->fw_grp_ids = NULL;
2404 vnic->rx_queue_cnt = 0;
2410 bnxt_config_vlan_hw_stripping(struct bnxt *bp, uint64_t rx_offloads)
2412 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
2415 /* Destroy, recreate and reconfigure the default vnic */
2416 rc = bnxt_free_one_vnic(bp, 0);
2420 /* default vnic 0 */
2421 rc = bnxt_setup_one_vnic(bp, 0);
2425 if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2426 DEV_RX_OFFLOAD_VLAN_FILTER) {
2427 rc = bnxt_add_vlan_filter(bp, 0);
2430 rc = bnxt_restore_vlan_filters(bp);
2434 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2439 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2443 PMD_DRV_LOG(DEBUG, "VLAN Strip Offload: %d\n",
2444 !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP));
2450 bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
2452 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
2453 struct bnxt *bp = dev->data->dev_private;
2456 rc = is_bnxt_in_error(bp);
2460 /* Filter settings will get applied when port is started */
2461 if (!dev->data->dev_started)
2464 if (mask & ETH_VLAN_FILTER_MASK) {
2465 /* Enable or disable VLAN filtering */
2466 rc = bnxt_config_vlan_hw_filter(bp, rx_offloads);
2471 if (mask & ETH_VLAN_STRIP_MASK) {
2472 /* Enable or disable VLAN stripping */
2473 rc = bnxt_config_vlan_hw_stripping(bp, rx_offloads);
2478 if (mask & ETH_VLAN_EXTEND_MASK) {
2479 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2480 PMD_DRV_LOG(DEBUG, "Extend VLAN supported\n");
2482 PMD_DRV_LOG(INFO, "Extend VLAN unsupported\n");
2489 bnxt_vlan_tpid_set_op(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
2492 struct bnxt *bp = dev->data->dev_private;
2493 int qinq = dev->data->dev_conf.rxmode.offloads &
2494 DEV_RX_OFFLOAD_VLAN_EXTEND;
2496 if (vlan_type != ETH_VLAN_TYPE_INNER &&
2497 vlan_type != ETH_VLAN_TYPE_OUTER) {
2499 "Unsupported vlan type.");
2504 "QinQ not enabled. Needs to be ON as we can "
2505 "accelerate only outer vlan\n");
2509 if (vlan_type == ETH_VLAN_TYPE_OUTER) {
2511 case RTE_ETHER_TYPE_QINQ:
2513 TX_BD_LONG_CFA_META_VLAN_TPID_TPID88A8;
2515 case RTE_ETHER_TYPE_VLAN:
2517 TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
2519 case RTE_ETHER_TYPE_QINQ1:
2521 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9100;
2523 case RTE_ETHER_TYPE_QINQ2:
2525 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9200;
2527 case RTE_ETHER_TYPE_QINQ3:
2529 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9300;
2532 PMD_DRV_LOG(ERR, "Invalid TPID: %x\n", tpid);
2535 bp->outer_tpid_bd |= tpid;
2536 PMD_DRV_LOG(INFO, "outer_tpid_bd = %x\n", bp->outer_tpid_bd);
2537 } else if (vlan_type == ETH_VLAN_TYPE_INNER) {
2539 "Can accelerate only outer vlan in QinQ\n");
2547 bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
2548 struct rte_ether_addr *addr)
2550 struct bnxt *bp = dev->data->dev_private;
2551 /* Default Filter is tied to VNIC 0 */
2552 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
2555 rc = is_bnxt_in_error(bp);
2559 if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
2562 if (rte_is_zero_ether_addr(addr))
2565 /* Filter settings will get applied when port is started */
2566 if (!dev->data->dev_started)
2569 /* Check if the requested MAC is already added */
2570 if (memcmp(addr, bp->mac_addr, RTE_ETHER_ADDR_LEN) == 0)
2573 /* Destroy filter and re-create it */
2574 bnxt_del_dflt_mac_filter(bp, vnic);
2576 memcpy(bp->mac_addr, addr, RTE_ETHER_ADDR_LEN);
2577 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
2578 /* This filter will allow only untagged packets */
2579 rc = bnxt_add_vlan_filter(bp, 0);
2581 rc = bnxt_add_mac_filter(bp, vnic, addr, 0, 0);
2584 PMD_DRV_LOG(DEBUG, "Set MAC addr\n");
2589 bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
2590 struct rte_ether_addr *mc_addr_set,
2591 uint32_t nb_mc_addr)
2593 struct bnxt *bp = eth_dev->data->dev_private;
2594 char *mc_addr_list = (char *)mc_addr_set;
2595 struct bnxt_vnic_info *vnic;
2596 uint32_t off = 0, i = 0;
2599 rc = is_bnxt_in_error(bp);
2603 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2605 if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
2606 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
2610 /* TODO Check for Duplicate mcast addresses */
2611 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
2612 for (i = 0; i < nb_mc_addr; i++) {
2613 memcpy(vnic->mc_list + off, &mc_addr_list[i],
2614 RTE_ETHER_ADDR_LEN);
2615 off += RTE_ETHER_ADDR_LEN;
2618 vnic->mc_addr_cnt = i;
2619 if (vnic->mc_addr_cnt)
2620 vnic->flags |= BNXT_VNIC_INFO_MCAST;
2622 vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
2625 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2629 bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
2631 struct bnxt *bp = dev->data->dev_private;
2632 uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
2633 uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
2634 uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
2635 uint8_t fw_rsvd = bp->fw_ver & 0xff;
2638 ret = snprintf(fw_version, fw_size, "%d.%d.%d.%d",
2639 fw_major, fw_minor, fw_updt, fw_rsvd);
2641 ret += 1; /* add the size of '\0' */
2642 if (fw_size < (uint32_t)ret)
2649 bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
2650 struct rte_eth_rxq_info *qinfo)
2652 struct bnxt *bp = dev->data->dev_private;
2653 struct bnxt_rx_queue *rxq;
2655 if (is_bnxt_in_error(bp))
2658 rxq = dev->data->rx_queues[queue_id];
2660 qinfo->mp = rxq->mb_pool;
2661 qinfo->scattered_rx = dev->data->scattered_rx;
2662 qinfo->nb_desc = rxq->nb_rx_desc;
2664 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2665 qinfo->conf.rx_drop_en = rxq->drop_en;
2666 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
2667 qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
2671 bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
2672 struct rte_eth_txq_info *qinfo)
2674 struct bnxt *bp = dev->data->dev_private;
2675 struct bnxt_tx_queue *txq;
2677 if (is_bnxt_in_error(bp))
2680 txq = dev->data->tx_queues[queue_id];
2682 qinfo->nb_desc = txq->nb_tx_desc;
2684 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2685 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2686 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2688 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
2689 qinfo->conf.tx_rs_thresh = 0;
2690 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
2691 qinfo->conf.offloads = txq->offloads;
2694 static const struct {
2695 eth_rx_burst_t pkt_burst;
2697 } bnxt_rx_burst_info[] = {
2698 {bnxt_recv_pkts, "Scalar"},
2699 #if defined(RTE_ARCH_X86)
2700 {bnxt_recv_pkts_vec, "Vector SSE"},
2701 #elif defined(RTE_ARCH_ARM64)
2702 {bnxt_recv_pkts_vec, "Vector Neon"},
2707 bnxt_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2708 struct rte_eth_burst_mode *mode)
2710 eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
2713 for (i = 0; i < RTE_DIM(bnxt_rx_burst_info); i++) {
2714 if (pkt_burst == bnxt_rx_burst_info[i].pkt_burst) {
2715 snprintf(mode->info, sizeof(mode->info), "%s",
2716 bnxt_rx_burst_info[i].info);
2724 static const struct {
2725 eth_tx_burst_t pkt_burst;
2727 } bnxt_tx_burst_info[] = {
2728 {bnxt_xmit_pkts, "Scalar"},
2729 #if defined(RTE_ARCH_X86)
2730 {bnxt_xmit_pkts_vec, "Vector SSE"},
2731 #elif defined(RTE_ARCH_ARM64)
2732 {bnxt_xmit_pkts_vec, "Vector Neon"},
2737 bnxt_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2738 struct rte_eth_burst_mode *mode)
2740 eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
2743 for (i = 0; i < RTE_DIM(bnxt_tx_burst_info); i++) {
2744 if (pkt_burst == bnxt_tx_burst_info[i].pkt_burst) {
2745 snprintf(mode->info, sizeof(mode->info), "%s",
2746 bnxt_tx_burst_info[i].info);
2754 int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
2756 struct bnxt *bp = eth_dev->data->dev_private;
2757 uint32_t new_pkt_size;
2761 rc = is_bnxt_in_error(bp);
2765 /* Exit if receive queues are not configured yet */
2766 if (!eth_dev->data->nb_rx_queues)
2769 new_pkt_size = new_mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
2770 VLAN_TAG_SIZE * BNXT_NUM_VLANS;
2773 * Disallow any MTU change that would require scattered receive support
2774 * if it is not already enabled.
2776 if (eth_dev->data->dev_started &&
2777 !eth_dev->data->scattered_rx &&
2779 eth_dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
2781 "MTU change would require scattered rx support. ");
2782 PMD_DRV_LOG(ERR, "Stop port before changing MTU.\n");
2786 if (new_mtu > RTE_ETHER_MTU) {
2787 bp->flags |= BNXT_FLAG_JUMBO;
2788 bp->eth_dev->data->dev_conf.rxmode.offloads |=
2789 DEV_RX_OFFLOAD_JUMBO_FRAME;
2791 bp->eth_dev->data->dev_conf.rxmode.offloads &=
2792 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2793 bp->flags &= ~BNXT_FLAG_JUMBO;
2796 /* Is there a change in mtu setting? */
2797 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len == new_pkt_size)
2800 for (i = 0; i < bp->nr_vnics; i++) {
2801 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2804 vnic->mru = BNXT_VNIC_MRU(new_mtu);
2805 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
2809 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
2810 size -= RTE_PKTMBUF_HEADROOM;
2812 if (size < new_mtu) {
2813 rc = bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
2820 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = new_pkt_size;
2822 PMD_DRV_LOG(INFO, "New MTU is %d\n", new_mtu);
2828 bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
2830 struct bnxt *bp = dev->data->dev_private;
2831 uint16_t vlan = bp->vlan;
2834 rc = is_bnxt_in_error(bp);
2838 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp)) {
2840 "PVID cannot be modified for this function\n");
2843 bp->vlan = on ? pvid : 0;
2845 rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
2852 bnxt_dev_led_on_op(struct rte_eth_dev *dev)
2854 struct bnxt *bp = dev->data->dev_private;
2857 rc = is_bnxt_in_error(bp);
2861 return bnxt_hwrm_port_led_cfg(bp, true);
2865 bnxt_dev_led_off_op(struct rte_eth_dev *dev)
2867 struct bnxt *bp = dev->data->dev_private;
2870 rc = is_bnxt_in_error(bp);
2874 return bnxt_hwrm_port_led_cfg(bp, false);
2878 bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
2880 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2881 uint32_t desc = 0, raw_cons = 0, cons;
2882 struct bnxt_cp_ring_info *cpr;
2883 struct bnxt_rx_queue *rxq;
2884 struct rx_pkt_cmpl *rxcmp;
2887 rc = is_bnxt_in_error(bp);
2891 rxq = dev->data->rx_queues[rx_queue_id];
2893 raw_cons = cpr->cp_raw_cons;
2896 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
2897 rte_prefetch0(&cpr->cp_desc_ring[cons]);
2898 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2900 if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct)) {
2912 bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)
2914 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
2915 struct bnxt_rx_ring_info *rxr;
2916 struct bnxt_cp_ring_info *cpr;
2917 struct rte_mbuf *rx_buf;
2918 struct rx_pkt_cmpl *rxcmp;
2919 uint32_t cons, cp_cons;
2925 rc = is_bnxt_in_error(rxq->bp);
2932 if (offset >= rxq->nb_rx_desc)
2935 cons = RING_CMP(cpr->cp_ring_struct, offset);
2936 cp_cons = cpr->cp_raw_cons;
2937 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2939 if (cons > cp_cons) {
2940 if (CMPL_VALID(rxcmp, cpr->valid))
2941 return RTE_ETH_RX_DESC_DONE;
2943 if (CMPL_VALID(rxcmp, !cpr->valid))
2944 return RTE_ETH_RX_DESC_DONE;
2946 rx_buf = rxr->rx_buf_ring[cons];
2947 if (rx_buf == NULL || rx_buf == &rxq->fake_mbuf)
2948 return RTE_ETH_RX_DESC_UNAVAIL;
2951 return RTE_ETH_RX_DESC_AVAIL;
2955 bnxt_tx_descriptor_status_op(void *tx_queue, uint16_t offset)
2957 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
2958 struct bnxt_tx_ring_info *txr;
2959 struct bnxt_cp_ring_info *cpr;
2960 struct bnxt_sw_tx_bd *tx_buf;
2961 struct tx_pkt_cmpl *txcmp;
2962 uint32_t cons, cp_cons;
2968 rc = is_bnxt_in_error(txq->bp);
2975 if (offset >= txq->nb_tx_desc)
2978 cons = RING_CMP(cpr->cp_ring_struct, offset);
2979 txcmp = (struct tx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2980 cp_cons = cpr->cp_raw_cons;
2982 if (cons > cp_cons) {
2983 if (CMPL_VALID(txcmp, cpr->valid))
2984 return RTE_ETH_TX_DESC_UNAVAIL;
2986 if (CMPL_VALID(txcmp, !cpr->valid))
2987 return RTE_ETH_TX_DESC_UNAVAIL;
2989 tx_buf = &txr->tx_buf_ring[cons];
2990 if (tx_buf->mbuf == NULL)
2991 return RTE_ETH_TX_DESC_DONE;
2993 return RTE_ETH_TX_DESC_FULL;
2996 static struct bnxt_filter_info *
2997 bnxt_match_and_validate_ether_filter(struct bnxt *bp,
2998 struct rte_eth_ethertype_filter *efilter,
2999 struct bnxt_vnic_info *vnic0,
3000 struct bnxt_vnic_info *vnic,
3003 struct bnxt_filter_info *mfilter = NULL;
3007 if (efilter->ether_type == RTE_ETHER_TYPE_IPV4 ||
3008 efilter->ether_type == RTE_ETHER_TYPE_IPV6) {
3009 PMD_DRV_LOG(ERR, "invalid ether_type(0x%04x) in"
3010 " ethertype filter.", efilter->ether_type);
3014 if (efilter->queue >= bp->rx_nr_rings) {
3015 PMD_DRV_LOG(ERR, "Invalid queue %d\n", efilter->queue);
3020 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3021 vnic = &bp->vnic_info[efilter->queue];
3023 PMD_DRV_LOG(ERR, "Invalid queue %d\n", efilter->queue);
3028 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
3029 STAILQ_FOREACH(mfilter, &vnic0->filter, next) {
3030 if ((!memcmp(efilter->mac_addr.addr_bytes,
3031 mfilter->l2_addr, RTE_ETHER_ADDR_LEN) &&
3033 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP &&
3034 mfilter->ethertype == efilter->ether_type)) {
3040 STAILQ_FOREACH(mfilter, &vnic->filter, next)
3041 if ((!memcmp(efilter->mac_addr.addr_bytes,
3042 mfilter->l2_addr, RTE_ETHER_ADDR_LEN) &&
3043 mfilter->ethertype == efilter->ether_type &&
3045 HWRM_CFA_L2_FILTER_CFG_INPUT_FLAGS_PATH_RX)) {
3059 bnxt_ethertype_filter(struct rte_eth_dev *dev,
3060 enum rte_filter_op filter_op,
3063 struct bnxt *bp = dev->data->dev_private;
3064 struct rte_eth_ethertype_filter *efilter =
3065 (struct rte_eth_ethertype_filter *)arg;
3066 struct bnxt_filter_info *bfilter, *filter1;
3067 struct bnxt_vnic_info *vnic, *vnic0;
3070 if (filter_op == RTE_ETH_FILTER_NOP)
3074 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3079 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3080 vnic = &bp->vnic_info[efilter->queue];
3082 switch (filter_op) {
3083 case RTE_ETH_FILTER_ADD:
3084 bnxt_match_and_validate_ether_filter(bp, efilter,
3089 bfilter = bnxt_get_unused_filter(bp);
3090 if (bfilter == NULL) {
3092 "Not enough resources for a new filter.\n");
3095 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3096 memcpy(bfilter->l2_addr, efilter->mac_addr.addr_bytes,
3097 RTE_ETHER_ADDR_LEN);
3098 memcpy(bfilter->dst_macaddr, efilter->mac_addr.addr_bytes,
3099 RTE_ETHER_ADDR_LEN);
3100 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
3101 bfilter->ethertype = efilter->ether_type;
3102 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3104 filter1 = bnxt_get_l2_filter(bp, bfilter, vnic0);
3105 if (filter1 == NULL) {
3110 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3111 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3113 bfilter->dst_id = vnic->fw_vnic_id;
3115 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
3117 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
3120 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
3123 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
3125 case RTE_ETH_FILTER_DELETE:
3126 filter1 = bnxt_match_and_validate_ether_filter(bp, efilter,
3128 if (ret == -EEXIST) {
3129 ret = bnxt_hwrm_clear_ntuple_filter(bp, filter1);
3131 STAILQ_REMOVE(&vnic->filter, filter1, bnxt_filter_info,
3133 bnxt_free_filter(bp, filter1);
3134 } else if (ret == 0) {
3135 PMD_DRV_LOG(ERR, "No matching filter found\n");
3139 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3145 bnxt_free_filter(bp, bfilter);
3151 parse_ntuple_filter(struct bnxt *bp,
3152 struct rte_eth_ntuple_filter *nfilter,
3153 struct bnxt_filter_info *bfilter)
3157 if (nfilter->queue >= bp->rx_nr_rings) {
3158 PMD_DRV_LOG(ERR, "Invalid queue %d\n", nfilter->queue);
3162 switch (nfilter->dst_port_mask) {
3164 bfilter->dst_port_mask = -1;
3165 bfilter->dst_port = nfilter->dst_port;
3166 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT |
3167 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3170 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3174 bfilter->ip_addr_type = NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3175 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3177 switch (nfilter->proto_mask) {
3179 if (nfilter->proto == 17) /* IPPROTO_UDP */
3180 bfilter->ip_protocol = 17;
3181 else if (nfilter->proto == 6) /* IPPROTO_TCP */
3182 bfilter->ip_protocol = 6;
3185 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3188 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3192 switch (nfilter->dst_ip_mask) {
3194 bfilter->dst_ipaddr_mask[0] = -1;
3195 bfilter->dst_ipaddr[0] = nfilter->dst_ip;
3196 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR |
3197 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3200 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
3204 switch (nfilter->src_ip_mask) {
3206 bfilter->src_ipaddr_mask[0] = -1;
3207 bfilter->src_ipaddr[0] = nfilter->src_ip;
3208 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR |
3209 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3212 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
3216 switch (nfilter->src_port_mask) {
3218 bfilter->src_port_mask = -1;
3219 bfilter->src_port = nfilter->src_port;
3220 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT |
3221 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3224 PMD_DRV_LOG(ERR, "invalid src_port mask.");
3228 bfilter->enables = en;
3232 static struct bnxt_filter_info*
3233 bnxt_match_ntuple_filter(struct bnxt *bp,
3234 struct bnxt_filter_info *bfilter,
3235 struct bnxt_vnic_info **mvnic)
3237 struct bnxt_filter_info *mfilter = NULL;
3240 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3241 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3242 STAILQ_FOREACH(mfilter, &vnic->filter, next) {
3243 if (bfilter->src_ipaddr[0] == mfilter->src_ipaddr[0] &&
3244 bfilter->src_ipaddr_mask[0] ==
3245 mfilter->src_ipaddr_mask[0] &&
3246 bfilter->src_port == mfilter->src_port &&
3247 bfilter->src_port_mask == mfilter->src_port_mask &&
3248 bfilter->dst_ipaddr[0] == mfilter->dst_ipaddr[0] &&
3249 bfilter->dst_ipaddr_mask[0] ==
3250 mfilter->dst_ipaddr_mask[0] &&
3251 bfilter->dst_port == mfilter->dst_port &&
3252 bfilter->dst_port_mask == mfilter->dst_port_mask &&
3253 bfilter->flags == mfilter->flags &&
3254 bfilter->enables == mfilter->enables) {
3265 bnxt_cfg_ntuple_filter(struct bnxt *bp,
3266 struct rte_eth_ntuple_filter *nfilter,
3267 enum rte_filter_op filter_op)
3269 struct bnxt_filter_info *bfilter, *mfilter, *filter1;
3270 struct bnxt_vnic_info *vnic, *vnic0, *mvnic;
3273 if (nfilter->flags != RTE_5TUPLE_FLAGS) {
3274 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
3278 if (nfilter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
3279 PMD_DRV_LOG(ERR, "Ntuple filter: TCP flags not supported\n");
3283 bfilter = bnxt_get_unused_filter(bp);
3284 if (bfilter == NULL) {
3286 "Not enough resources for a new filter.\n");
3289 ret = parse_ntuple_filter(bp, nfilter, bfilter);
3293 vnic = &bp->vnic_info[nfilter->queue];
3294 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3295 filter1 = STAILQ_FIRST(&vnic0->filter);
3296 if (filter1 == NULL) {
3301 bfilter->dst_id = vnic->fw_vnic_id;
3302 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3304 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3305 bfilter->ethertype = 0x800;
3306 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3308 mfilter = bnxt_match_ntuple_filter(bp, bfilter, &mvnic);
3310 if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
3311 bfilter->dst_id == mfilter->dst_id) {
3312 PMD_DRV_LOG(ERR, "filter exists.\n");
3315 } else if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
3316 bfilter->dst_id != mfilter->dst_id) {
3317 mfilter->dst_id = vnic->fw_vnic_id;
3318 ret = bnxt_hwrm_set_ntuple_filter(bp, mfilter->dst_id, mfilter);
3319 STAILQ_REMOVE(&mvnic->filter, mfilter, bnxt_filter_info, next);
3320 STAILQ_INSERT_TAIL(&vnic->filter, mfilter, next);
3321 PMD_DRV_LOG(ERR, "filter with matching pattern exists.\n");
3322 PMD_DRV_LOG(ERR, " Updated it to the new destination queue\n");
3325 if (mfilter == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
3326 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3331 if (filter_op == RTE_ETH_FILTER_ADD) {
3332 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3333 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
3336 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
3338 if (mfilter == NULL) {
3339 /* This should not happen. But for Coverity! */
3343 ret = bnxt_hwrm_clear_ntuple_filter(bp, mfilter);
3345 STAILQ_REMOVE(&vnic->filter, mfilter, bnxt_filter_info, next);
3346 bnxt_free_filter(bp, mfilter);
3347 bnxt_free_filter(bp, bfilter);
3352 bnxt_free_filter(bp, bfilter);
3357 bnxt_ntuple_filter(struct rte_eth_dev *dev,
3358 enum rte_filter_op filter_op,
3361 struct bnxt *bp = dev->data->dev_private;
3364 if (filter_op == RTE_ETH_FILTER_NOP)
3368 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3373 switch (filter_op) {
3374 case RTE_ETH_FILTER_ADD:
3375 ret = bnxt_cfg_ntuple_filter(bp,
3376 (struct rte_eth_ntuple_filter *)arg,
3379 case RTE_ETH_FILTER_DELETE:
3380 ret = bnxt_cfg_ntuple_filter(bp,
3381 (struct rte_eth_ntuple_filter *)arg,
3385 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3393 bnxt_parse_fdir_filter(struct bnxt *bp,
3394 struct rte_eth_fdir_filter *fdir,
3395 struct bnxt_filter_info *filter)
3397 enum rte_fdir_mode fdir_mode =
3398 bp->eth_dev->data->dev_conf.fdir_conf.mode;
3399 struct bnxt_vnic_info *vnic0, *vnic;
3400 struct bnxt_filter_info *filter1;
3404 if (fdir_mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3407 filter->l2_ovlan = fdir->input.flow_ext.vlan_tci;
3408 en |= EM_FLOW_ALLOC_INPUT_EN_OVLAN_VID;
3410 switch (fdir->input.flow_type) {
3411 case RTE_ETH_FLOW_IPV4:
3412 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
3414 filter->src_ipaddr[0] = fdir->input.flow.ip4_flow.src_ip;
3415 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3416 filter->dst_ipaddr[0] = fdir->input.flow.ip4_flow.dst_ip;
3417 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3418 filter->ip_protocol = fdir->input.flow.ip4_flow.proto;
3419 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3420 filter->ip_addr_type =
3421 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3422 filter->src_ipaddr_mask[0] = 0xffffffff;
3423 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3424 filter->dst_ipaddr_mask[0] = 0xffffffff;
3425 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3426 filter->ethertype = 0x800;
3427 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3429 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
3430 filter->src_port = fdir->input.flow.tcp4_flow.src_port;
3431 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3432 filter->dst_port = fdir->input.flow.tcp4_flow.dst_port;
3433 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3434 filter->dst_port_mask = 0xffff;
3435 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3436 filter->src_port_mask = 0xffff;
3437 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3438 filter->src_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.src_ip;
3439 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3440 filter->dst_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.dst_ip;
3441 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3442 filter->ip_protocol = 6;
3443 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3444 filter->ip_addr_type =
3445 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3446 filter->src_ipaddr_mask[0] = 0xffffffff;
3447 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3448 filter->dst_ipaddr_mask[0] = 0xffffffff;
3449 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3450 filter->ethertype = 0x800;
3451 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3453 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
3454 filter->src_port = fdir->input.flow.udp4_flow.src_port;
3455 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3456 filter->dst_port = fdir->input.flow.udp4_flow.dst_port;
3457 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3458 filter->dst_port_mask = 0xffff;
3459 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3460 filter->src_port_mask = 0xffff;
3461 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3462 filter->src_ipaddr[0] = fdir->input.flow.udp4_flow.ip.src_ip;
3463 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3464 filter->dst_ipaddr[0] = fdir->input.flow.udp4_flow.ip.dst_ip;
3465 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3466 filter->ip_protocol = 17;
3467 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3468 filter->ip_addr_type =
3469 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3470 filter->src_ipaddr_mask[0] = 0xffffffff;
3471 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3472 filter->dst_ipaddr_mask[0] = 0xffffffff;
3473 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3474 filter->ethertype = 0x800;
3475 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3477 case RTE_ETH_FLOW_IPV6:
3478 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
3480 filter->ip_addr_type =
3481 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3482 filter->ip_protocol = fdir->input.flow.ipv6_flow.proto;
3483 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3484 rte_memcpy(filter->src_ipaddr,
3485 fdir->input.flow.ipv6_flow.src_ip, 16);
3486 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3487 rte_memcpy(filter->dst_ipaddr,
3488 fdir->input.flow.ipv6_flow.dst_ip, 16);
3489 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3490 memset(filter->dst_ipaddr_mask, 0xff, 16);
3491 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3492 memset(filter->src_ipaddr_mask, 0xff, 16);
3493 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3494 filter->ethertype = 0x86dd;
3495 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3497 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
3498 filter->src_port = fdir->input.flow.tcp6_flow.src_port;
3499 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3500 filter->dst_port = fdir->input.flow.tcp6_flow.dst_port;
3501 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3502 filter->dst_port_mask = 0xffff;
3503 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3504 filter->src_port_mask = 0xffff;
3505 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3506 filter->ip_addr_type =
3507 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3508 filter->ip_protocol = fdir->input.flow.tcp6_flow.ip.proto;
3509 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3510 rte_memcpy(filter->src_ipaddr,
3511 fdir->input.flow.tcp6_flow.ip.src_ip, 16);
3512 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3513 rte_memcpy(filter->dst_ipaddr,
3514 fdir->input.flow.tcp6_flow.ip.dst_ip, 16);
3515 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3516 memset(filter->dst_ipaddr_mask, 0xff, 16);
3517 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3518 memset(filter->src_ipaddr_mask, 0xff, 16);
3519 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3520 filter->ethertype = 0x86dd;
3521 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3523 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
3524 filter->src_port = fdir->input.flow.udp6_flow.src_port;
3525 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3526 filter->dst_port = fdir->input.flow.udp6_flow.dst_port;
3527 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3528 filter->dst_port_mask = 0xffff;
3529 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3530 filter->src_port_mask = 0xffff;
3531 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3532 filter->ip_addr_type =
3533 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3534 filter->ip_protocol = fdir->input.flow.udp6_flow.ip.proto;
3535 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3536 rte_memcpy(filter->src_ipaddr,
3537 fdir->input.flow.udp6_flow.ip.src_ip, 16);
3538 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3539 rte_memcpy(filter->dst_ipaddr,
3540 fdir->input.flow.udp6_flow.ip.dst_ip, 16);
3541 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3542 memset(filter->dst_ipaddr_mask, 0xff, 16);
3543 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3544 memset(filter->src_ipaddr_mask, 0xff, 16);
3545 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3546 filter->ethertype = 0x86dd;
3547 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3549 case RTE_ETH_FLOW_L2_PAYLOAD:
3550 filter->ethertype = fdir->input.flow.l2_flow.ether_type;
3551 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3553 case RTE_ETH_FLOW_VXLAN:
3554 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3556 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
3557 filter->tunnel_type =
3558 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN;
3559 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
3561 case RTE_ETH_FLOW_NVGRE:
3562 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3564 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
3565 filter->tunnel_type =
3566 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_NVGRE;
3567 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
3569 case RTE_ETH_FLOW_UNKNOWN:
3570 case RTE_ETH_FLOW_RAW:
3571 case RTE_ETH_FLOW_FRAG_IPV4:
3572 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
3573 case RTE_ETH_FLOW_FRAG_IPV6:
3574 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
3575 case RTE_ETH_FLOW_IPV6_EX:
3576 case RTE_ETH_FLOW_IPV6_TCP_EX:
3577 case RTE_ETH_FLOW_IPV6_UDP_EX:
3578 case RTE_ETH_FLOW_GENEVE:
3584 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3585 vnic = &bp->vnic_info[fdir->action.rx_queue];
3587 PMD_DRV_LOG(ERR, "Invalid queue %d\n", fdir->action.rx_queue);
3591 if (fdir_mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3592 rte_memcpy(filter->dst_macaddr,
3593 fdir->input.flow.mac_vlan_flow.mac_addr.addr_bytes, 6);
3594 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
3597 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT) {
3598 filter->flags = HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
3599 filter1 = STAILQ_FIRST(&vnic0->filter);
3600 //filter1 = bnxt_get_l2_filter(bp, filter, vnic0);
3602 filter->dst_id = vnic->fw_vnic_id;
3603 for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
3604 if (filter->dst_macaddr[i] == 0x00)
3605 filter1 = STAILQ_FIRST(&vnic0->filter);
3607 filter1 = bnxt_get_l2_filter(bp, filter, vnic);
3610 if (filter1 == NULL)
3613 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3614 filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3616 filter->enables = en;
3621 static struct bnxt_filter_info *
3622 bnxt_match_fdir(struct bnxt *bp, struct bnxt_filter_info *nf,
3623 struct bnxt_vnic_info **mvnic)
3625 struct bnxt_filter_info *mf = NULL;
3628 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3629 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3631 STAILQ_FOREACH(mf, &vnic->filter, next) {
3632 if (mf->filter_type == nf->filter_type &&
3633 mf->flags == nf->flags &&
3634 mf->src_port == nf->src_port &&
3635 mf->src_port_mask == nf->src_port_mask &&
3636 mf->dst_port == nf->dst_port &&
3637 mf->dst_port_mask == nf->dst_port_mask &&
3638 mf->ip_protocol == nf->ip_protocol &&
3639 mf->ip_addr_type == nf->ip_addr_type &&
3640 mf->ethertype == nf->ethertype &&
3641 mf->vni == nf->vni &&
3642 mf->tunnel_type == nf->tunnel_type &&
3643 mf->l2_ovlan == nf->l2_ovlan &&
3644 mf->l2_ovlan_mask == nf->l2_ovlan_mask &&
3645 mf->l2_ivlan == nf->l2_ivlan &&
3646 mf->l2_ivlan_mask == nf->l2_ivlan_mask &&
3647 !memcmp(mf->l2_addr, nf->l2_addr,
3648 RTE_ETHER_ADDR_LEN) &&
3649 !memcmp(mf->l2_addr_mask, nf->l2_addr_mask,
3650 RTE_ETHER_ADDR_LEN) &&
3651 !memcmp(mf->src_macaddr, nf->src_macaddr,
3652 RTE_ETHER_ADDR_LEN) &&
3653 !memcmp(mf->dst_macaddr, nf->dst_macaddr,
3654 RTE_ETHER_ADDR_LEN) &&
3655 !memcmp(mf->src_ipaddr, nf->src_ipaddr,
3656 sizeof(nf->src_ipaddr)) &&
3657 !memcmp(mf->src_ipaddr_mask, nf->src_ipaddr_mask,
3658 sizeof(nf->src_ipaddr_mask)) &&
3659 !memcmp(mf->dst_ipaddr, nf->dst_ipaddr,
3660 sizeof(nf->dst_ipaddr)) &&
3661 !memcmp(mf->dst_ipaddr_mask, nf->dst_ipaddr_mask,
3662 sizeof(nf->dst_ipaddr_mask))) {
3673 bnxt_fdir_filter(struct rte_eth_dev *dev,
3674 enum rte_filter_op filter_op,
3677 struct bnxt *bp = dev->data->dev_private;
3678 struct rte_eth_fdir_filter *fdir = (struct rte_eth_fdir_filter *)arg;
3679 struct bnxt_filter_info *filter, *match;
3680 struct bnxt_vnic_info *vnic, *mvnic;
3683 if (filter_op == RTE_ETH_FILTER_NOP)
3686 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
3689 switch (filter_op) {
3690 case RTE_ETH_FILTER_ADD:
3691 case RTE_ETH_FILTER_DELETE:
3693 filter = bnxt_get_unused_filter(bp);
3694 if (filter == NULL) {
3696 "Not enough resources for a new flow.\n");
3700 ret = bnxt_parse_fdir_filter(bp, fdir, filter);
3703 filter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3705 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3706 vnic = &bp->vnic_info[0];
3708 vnic = &bp->vnic_info[fdir->action.rx_queue];
3710 match = bnxt_match_fdir(bp, filter, &mvnic);
3711 if (match != NULL && filter_op == RTE_ETH_FILTER_ADD) {
3712 if (match->dst_id == vnic->fw_vnic_id) {
3713 PMD_DRV_LOG(ERR, "Flow already exists.\n");
3717 match->dst_id = vnic->fw_vnic_id;
3718 ret = bnxt_hwrm_set_ntuple_filter(bp,
3721 STAILQ_REMOVE(&mvnic->filter, match,
3722 bnxt_filter_info, next);
3723 STAILQ_INSERT_TAIL(&vnic->filter, match, next);
3725 "Filter with matching pattern exist\n");
3727 "Updated it to new destination q\n");
3731 if (match == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
3732 PMD_DRV_LOG(ERR, "Flow does not exist.\n");
3737 if (filter_op == RTE_ETH_FILTER_ADD) {
3738 ret = bnxt_hwrm_set_ntuple_filter(bp,
3743 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
3745 ret = bnxt_hwrm_clear_ntuple_filter(bp, match);
3746 STAILQ_REMOVE(&vnic->filter, match,
3747 bnxt_filter_info, next);
3748 bnxt_free_filter(bp, match);
3749 bnxt_free_filter(bp, filter);
3752 case RTE_ETH_FILTER_FLUSH:
3753 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3754 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3756 STAILQ_FOREACH(filter, &vnic->filter, next) {
3757 if (filter->filter_type ==
3758 HWRM_CFA_NTUPLE_FILTER) {
3760 bnxt_hwrm_clear_ntuple_filter(bp,
3762 STAILQ_REMOVE(&vnic->filter, filter,
3763 bnxt_filter_info, next);
3768 case RTE_ETH_FILTER_UPDATE:
3769 case RTE_ETH_FILTER_STATS:
3770 case RTE_ETH_FILTER_INFO:
3771 PMD_DRV_LOG(ERR, "operation %u not implemented", filter_op);
3774 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
3781 bnxt_free_filter(bp, filter);
3786 bnxt_filter_ctrl_op(struct rte_eth_dev *dev,
3787 enum rte_filter_type filter_type,
3788 enum rte_filter_op filter_op, void *arg)
3790 struct bnxt *bp = dev->data->dev_private;
3796 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
3797 struct bnxt_representor *vfr = dev->data->dev_private;
3798 bp = vfr->parent_dev->data->dev_private;
3799 /* parent is deleted while children are still valid */
3801 PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR Error %d:%d\n",
3809 ret = is_bnxt_in_error(bp);
3813 switch (filter_type) {
3814 case RTE_ETH_FILTER_TUNNEL:
3816 "filter type: %d: To be implemented\n", filter_type);
3818 case RTE_ETH_FILTER_FDIR:
3819 ret = bnxt_fdir_filter(dev, filter_op, arg);
3821 case RTE_ETH_FILTER_NTUPLE:
3822 ret = bnxt_ntuple_filter(dev, filter_op, arg);
3824 case RTE_ETH_FILTER_ETHERTYPE:
3825 ret = bnxt_ethertype_filter(dev, filter_op, arg);
3827 case RTE_ETH_FILTER_GENERIC:
3828 if (filter_op != RTE_ETH_FILTER_GET)
3830 if (BNXT_TRUFLOW_EN(bp))
3831 *(const void **)arg = &bnxt_ulp_rte_flow_ops;
3833 *(const void **)arg = &bnxt_flow_ops;
3837 "Filter type (%d) not supported", filter_type);
3844 static const uint32_t *
3845 bnxt_dev_supported_ptypes_get_op(struct rte_eth_dev *dev)
3847 static const uint32_t ptypes[] = {
3848 RTE_PTYPE_L2_ETHER_VLAN,
3849 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
3850 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
3854 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
3855 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
3856 RTE_PTYPE_INNER_L4_ICMP,
3857 RTE_PTYPE_INNER_L4_TCP,
3858 RTE_PTYPE_INNER_L4_UDP,
3862 if (!dev->rx_pkt_burst)
3868 static int bnxt_map_regs(struct bnxt *bp, uint32_t *reg_arr, int count,
3871 uint32_t reg_base = *reg_arr & 0xfffff000;
3875 for (i = 0; i < count; i++) {
3876 if ((reg_arr[i] & 0xfffff000) != reg_base)
3879 win_off = BNXT_GRCPF_REG_WINDOW_BASE_OUT + (reg_win - 1) * 4;
3880 rte_write32(reg_base, (uint8_t *)bp->bar0 + win_off);
3884 static int bnxt_map_ptp_regs(struct bnxt *bp)
3886 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3890 reg_arr = ptp->rx_regs;
3891 rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_RX_REGS, 5);
3895 reg_arr = ptp->tx_regs;
3896 rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_TX_REGS, 6);
3900 for (i = 0; i < BNXT_PTP_RX_REGS; i++)
3901 ptp->rx_mapped_regs[i] = 0x5000 + (ptp->rx_regs[i] & 0xfff);
3903 for (i = 0; i < BNXT_PTP_TX_REGS; i++)
3904 ptp->tx_mapped_regs[i] = 0x6000 + (ptp->tx_regs[i] & 0xfff);
3909 static void bnxt_unmap_ptp_regs(struct bnxt *bp)
3911 rte_write32(0, (uint8_t *)bp->bar0 +
3912 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 16);
3913 rte_write32(0, (uint8_t *)bp->bar0 +
3914 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 20);
3917 static uint64_t bnxt_cc_read(struct bnxt *bp)
3921 ns = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3922 BNXT_GRCPF_REG_SYNC_TIME));
3923 ns |= (uint64_t)(rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3924 BNXT_GRCPF_REG_SYNC_TIME + 4))) << 32;
3928 static int bnxt_get_tx_ts(struct bnxt *bp, uint64_t *ts)
3930 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3933 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3934 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3935 if (fifo & BNXT_PTP_TX_FIFO_EMPTY)
3938 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3939 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3940 *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3941 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_L]));
3942 *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3943 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_H])) << 32;
3948 static int bnxt_get_rx_ts(struct bnxt *bp, uint64_t *ts)
3950 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3951 struct bnxt_pf_info *pf = bp->pf;
3958 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3959 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3960 if (!(fifo & BNXT_PTP_RX_FIFO_PENDING))
3963 port_id = pf->port_id;
3964 rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
3965 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
3967 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3968 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3969 if (fifo & BNXT_PTP_RX_FIFO_PENDING) {
3970 /* bnxt_clr_rx_ts(bp); TBD */
3974 *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3975 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
3976 *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3977 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
3983 bnxt_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
3986 struct bnxt *bp = dev->data->dev_private;
3987 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3992 ns = rte_timespec_to_ns(ts);
3993 /* Set the timecounters to a new value. */
4000 bnxt_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
4002 struct bnxt *bp = dev->data->dev_private;
4003 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4004 uint64_t ns, systime_cycles = 0;
4010 if (BNXT_CHIP_THOR(bp))
4011 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
4014 systime_cycles = bnxt_cc_read(bp);
4016 ns = rte_timecounter_update(&ptp->tc, systime_cycles);
4017 *ts = rte_ns_to_timespec(ns);
4022 bnxt_timesync_enable(struct rte_eth_dev *dev)
4024 struct bnxt *bp = dev->data->dev_private;
4025 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4033 ptp->tx_tstamp_en = 1;
4034 ptp->rxctl = BNXT_PTP_MSG_EVENTS;
4036 rc = bnxt_hwrm_ptp_cfg(bp);
4040 memset(&ptp->tc, 0, sizeof(struct rte_timecounter));
4041 memset(&ptp->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4042 memset(&ptp->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4044 ptp->tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
4045 ptp->tc.cc_shift = shift;
4046 ptp->tc.nsec_mask = (1ULL << shift) - 1;
4048 ptp->rx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
4049 ptp->rx_tstamp_tc.cc_shift = shift;
4050 ptp->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4052 ptp->tx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
4053 ptp->tx_tstamp_tc.cc_shift = shift;
4054 ptp->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4056 if (!BNXT_CHIP_THOR(bp))
4057 bnxt_map_ptp_regs(bp);
4063 bnxt_timesync_disable(struct rte_eth_dev *dev)
4065 struct bnxt *bp = dev->data->dev_private;
4066 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4072 ptp->tx_tstamp_en = 0;
4075 bnxt_hwrm_ptp_cfg(bp);
4077 if (!BNXT_CHIP_THOR(bp))
4078 bnxt_unmap_ptp_regs(bp);
4084 bnxt_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4085 struct timespec *timestamp,
4086 uint32_t flags __rte_unused)
4088 struct bnxt *bp = dev->data->dev_private;
4089 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4090 uint64_t rx_tstamp_cycles = 0;
4096 if (BNXT_CHIP_THOR(bp))
4097 rx_tstamp_cycles = ptp->rx_timestamp;
4099 bnxt_get_rx_ts(bp, &rx_tstamp_cycles);
4101 ns = rte_timecounter_update(&ptp->rx_tstamp_tc, rx_tstamp_cycles);
4102 *timestamp = rte_ns_to_timespec(ns);
4107 bnxt_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
4108 struct timespec *timestamp)
4110 struct bnxt *bp = dev->data->dev_private;
4111 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4112 uint64_t tx_tstamp_cycles = 0;
4119 if (BNXT_CHIP_THOR(bp))
4120 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_PATH_TX,
4123 rc = bnxt_get_tx_ts(bp, &tx_tstamp_cycles);
4125 ns = rte_timecounter_update(&ptp->tx_tstamp_tc, tx_tstamp_cycles);
4126 *timestamp = rte_ns_to_timespec(ns);
4132 bnxt_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4134 struct bnxt *bp = dev->data->dev_private;
4135 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4140 ptp->tc.nsec += delta;
4146 bnxt_get_eeprom_length_op(struct rte_eth_dev *dev)
4148 struct bnxt *bp = dev->data->dev_private;
4150 uint32_t dir_entries;
4151 uint32_t entry_length;
4153 rc = is_bnxt_in_error(bp);
4157 PMD_DRV_LOG(INFO, PCI_PRI_FMT "\n",
4158 bp->pdev->addr.domain, bp->pdev->addr.bus,
4159 bp->pdev->addr.devid, bp->pdev->addr.function);
4161 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
4165 return dir_entries * entry_length;
4169 bnxt_get_eeprom_op(struct rte_eth_dev *dev,
4170 struct rte_dev_eeprom_info *in_eeprom)
4172 struct bnxt *bp = dev->data->dev_private;
4177 rc = is_bnxt_in_error(bp);
4181 PMD_DRV_LOG(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d\n",
4182 bp->pdev->addr.domain, bp->pdev->addr.bus,
4183 bp->pdev->addr.devid, bp->pdev->addr.function,
4184 in_eeprom->offset, in_eeprom->length);
4186 if (in_eeprom->offset == 0) /* special offset value to get directory */
4187 return bnxt_get_nvram_directory(bp, in_eeprom->length,
4190 index = in_eeprom->offset >> 24;
4191 offset = in_eeprom->offset & 0xffffff;
4194 return bnxt_hwrm_get_nvram_item(bp, index - 1, offset,
4195 in_eeprom->length, in_eeprom->data);
4200 static bool bnxt_dir_type_is_ape_bin_format(uint16_t dir_type)
4203 case BNX_DIR_TYPE_CHIMP_PATCH:
4204 case BNX_DIR_TYPE_BOOTCODE:
4205 case BNX_DIR_TYPE_BOOTCODE_2:
4206 case BNX_DIR_TYPE_APE_FW:
4207 case BNX_DIR_TYPE_APE_PATCH:
4208 case BNX_DIR_TYPE_KONG_FW:
4209 case BNX_DIR_TYPE_KONG_PATCH:
4210 case BNX_DIR_TYPE_BONO_FW:
4211 case BNX_DIR_TYPE_BONO_PATCH:
4219 static bool bnxt_dir_type_is_other_exec_format(uint16_t dir_type)
4222 case BNX_DIR_TYPE_AVS:
4223 case BNX_DIR_TYPE_EXP_ROM_MBA:
4224 case BNX_DIR_TYPE_PCIE:
4225 case BNX_DIR_TYPE_TSCF_UCODE:
4226 case BNX_DIR_TYPE_EXT_PHY:
4227 case BNX_DIR_TYPE_CCM:
4228 case BNX_DIR_TYPE_ISCSI_BOOT:
4229 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
4230 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
4238 static bool bnxt_dir_type_is_executable(uint16_t dir_type)
4240 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
4241 bnxt_dir_type_is_other_exec_format(dir_type);
4245 bnxt_set_eeprom_op(struct rte_eth_dev *dev,
4246 struct rte_dev_eeprom_info *in_eeprom)
4248 struct bnxt *bp = dev->data->dev_private;
4249 uint8_t index, dir_op;
4250 uint16_t type, ext, ordinal, attr;
4253 rc = is_bnxt_in_error(bp);
4257 PMD_DRV_LOG(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d\n",
4258 bp->pdev->addr.domain, bp->pdev->addr.bus,
4259 bp->pdev->addr.devid, bp->pdev->addr.function,
4260 in_eeprom->offset, in_eeprom->length);
4263 PMD_DRV_LOG(ERR, "NVM write not supported from a VF\n");
4267 type = in_eeprom->magic >> 16;
4269 if (type == 0xffff) { /* special value for directory operations */
4270 index = in_eeprom->magic & 0xff;
4271 dir_op = in_eeprom->magic >> 8;
4275 case 0x0e: /* erase */
4276 if (in_eeprom->offset != ~in_eeprom->magic)
4278 return bnxt_hwrm_erase_nvram_directory(bp, index - 1);
4284 /* Create or re-write an NVM item: */
4285 if (bnxt_dir_type_is_executable(type) == true)
4287 ext = in_eeprom->magic & 0xffff;
4288 ordinal = in_eeprom->offset >> 16;
4289 attr = in_eeprom->offset & 0xffff;
4291 return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
4292 in_eeprom->data, in_eeprom->length);
4299 static const struct eth_dev_ops bnxt_dev_ops = {
4300 .dev_infos_get = bnxt_dev_info_get_op,
4301 .dev_close = bnxt_dev_close_op,
4302 .dev_configure = bnxt_dev_configure_op,
4303 .dev_start = bnxt_dev_start_op,
4304 .dev_stop = bnxt_dev_stop_op,
4305 .dev_set_link_up = bnxt_dev_set_link_up_op,
4306 .dev_set_link_down = bnxt_dev_set_link_down_op,
4307 .stats_get = bnxt_stats_get_op,
4308 .stats_reset = bnxt_stats_reset_op,
4309 .rx_queue_setup = bnxt_rx_queue_setup_op,
4310 .rx_queue_release = bnxt_rx_queue_release_op,
4311 .tx_queue_setup = bnxt_tx_queue_setup_op,
4312 .tx_queue_release = bnxt_tx_queue_release_op,
4313 .rx_queue_intr_enable = bnxt_rx_queue_intr_enable_op,
4314 .rx_queue_intr_disable = bnxt_rx_queue_intr_disable_op,
4315 .reta_update = bnxt_reta_update_op,
4316 .reta_query = bnxt_reta_query_op,
4317 .rss_hash_update = bnxt_rss_hash_update_op,
4318 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
4319 .link_update = bnxt_link_update_op,
4320 .promiscuous_enable = bnxt_promiscuous_enable_op,
4321 .promiscuous_disable = bnxt_promiscuous_disable_op,
4322 .allmulticast_enable = bnxt_allmulticast_enable_op,
4323 .allmulticast_disable = bnxt_allmulticast_disable_op,
4324 .mac_addr_add = bnxt_mac_addr_add_op,
4325 .mac_addr_remove = bnxt_mac_addr_remove_op,
4326 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
4327 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
4328 .udp_tunnel_port_add = bnxt_udp_tunnel_port_add_op,
4329 .udp_tunnel_port_del = bnxt_udp_tunnel_port_del_op,
4330 .vlan_filter_set = bnxt_vlan_filter_set_op,
4331 .vlan_offload_set = bnxt_vlan_offload_set_op,
4332 .vlan_tpid_set = bnxt_vlan_tpid_set_op,
4333 .vlan_pvid_set = bnxt_vlan_pvid_set_op,
4334 .mtu_set = bnxt_mtu_set_op,
4335 .mac_addr_set = bnxt_set_default_mac_addr_op,
4336 .xstats_get = bnxt_dev_xstats_get_op,
4337 .xstats_get_names = bnxt_dev_xstats_get_names_op,
4338 .xstats_reset = bnxt_dev_xstats_reset_op,
4339 .fw_version_get = bnxt_fw_version_get,
4340 .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
4341 .rxq_info_get = bnxt_rxq_info_get_op,
4342 .txq_info_get = bnxt_txq_info_get_op,
4343 .rx_burst_mode_get = bnxt_rx_burst_mode_get,
4344 .tx_burst_mode_get = bnxt_tx_burst_mode_get,
4345 .dev_led_on = bnxt_dev_led_on_op,
4346 .dev_led_off = bnxt_dev_led_off_op,
4347 .xstats_get_by_id = bnxt_dev_xstats_get_by_id_op,
4348 .xstats_get_names_by_id = bnxt_dev_xstats_get_names_by_id_op,
4349 .rx_queue_start = bnxt_rx_queue_start,
4350 .rx_queue_stop = bnxt_rx_queue_stop,
4351 .tx_queue_start = bnxt_tx_queue_start,
4352 .tx_queue_stop = bnxt_tx_queue_stop,
4353 .filter_ctrl = bnxt_filter_ctrl_op,
4354 .dev_supported_ptypes_get = bnxt_dev_supported_ptypes_get_op,
4355 .get_eeprom_length = bnxt_get_eeprom_length_op,
4356 .get_eeprom = bnxt_get_eeprom_op,
4357 .set_eeprom = bnxt_set_eeprom_op,
4358 .timesync_enable = bnxt_timesync_enable,
4359 .timesync_disable = bnxt_timesync_disable,
4360 .timesync_read_time = bnxt_timesync_read_time,
4361 .timesync_write_time = bnxt_timesync_write_time,
4362 .timesync_adjust_time = bnxt_timesync_adjust_time,
4363 .timesync_read_rx_timestamp = bnxt_timesync_read_rx_timestamp,
4364 .timesync_read_tx_timestamp = bnxt_timesync_read_tx_timestamp,
4367 static uint32_t bnxt_map_reset_regs(struct bnxt *bp, uint32_t reg)
4371 /* Only pre-map the reset GRC registers using window 3 */
4372 rte_write32(reg & 0xfffff000, (uint8_t *)bp->bar0 +
4373 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 8);
4375 offset = BNXT_GRCP_WINDOW_3_BASE + (reg & 0xffc);
4380 int bnxt_map_fw_health_status_regs(struct bnxt *bp)
4382 struct bnxt_error_recovery_info *info = bp->recovery_info;
4383 uint32_t reg_base = 0xffffffff;
4386 /* Only pre-map the monitoring GRC registers using window 2 */
4387 for (i = 0; i < BNXT_FW_STATUS_REG_CNT; i++) {
4388 uint32_t reg = info->status_regs[i];
4390 if (BNXT_FW_STATUS_REG_TYPE(reg) != BNXT_FW_STATUS_REG_TYPE_GRC)
4393 if (reg_base == 0xffffffff)
4394 reg_base = reg & 0xfffff000;
4395 if ((reg & 0xfffff000) != reg_base)
4398 /* Use mask 0xffc as the Lower 2 bits indicates
4399 * address space location
4401 info->mapped_status_regs[i] = BNXT_GRCP_WINDOW_2_BASE +
4405 if (reg_base == 0xffffffff)
4408 rte_write32(reg_base, (uint8_t *)bp->bar0 +
4409 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
4414 static void bnxt_write_fw_reset_reg(struct bnxt *bp, uint32_t index)
4416 struct bnxt_error_recovery_info *info = bp->recovery_info;
4417 uint32_t delay = info->delay_after_reset[index];
4418 uint32_t val = info->reset_reg_val[index];
4419 uint32_t reg = info->reset_reg[index];
4420 uint32_t type, offset;
4422 type = BNXT_FW_STATUS_REG_TYPE(reg);
4423 offset = BNXT_FW_STATUS_REG_OFF(reg);
4426 case BNXT_FW_STATUS_REG_TYPE_CFG:
4427 rte_pci_write_config(bp->pdev, &val, sizeof(val), offset);
4429 case BNXT_FW_STATUS_REG_TYPE_GRC:
4430 offset = bnxt_map_reset_regs(bp, offset);
4431 rte_write32(val, (uint8_t *)bp->bar0 + offset);
4433 case BNXT_FW_STATUS_REG_TYPE_BAR0:
4434 rte_write32(val, (uint8_t *)bp->bar0 + offset);
4437 /* wait on a specific interval of time until core reset is complete */
4439 rte_delay_ms(delay);
4442 static void bnxt_dev_cleanup(struct bnxt *bp)
4444 bp->eth_dev->data->dev_link.link_status = 0;
4445 bp->link_info->link_up = 0;
4446 if (bp->eth_dev->data->dev_started)
4447 bnxt_dev_stop_op(bp->eth_dev);
4449 bnxt_uninit_resources(bp, true);
4452 static int bnxt_restore_vlan_filters(struct bnxt *bp)
4454 struct rte_eth_dev *dev = bp->eth_dev;
4455 struct rte_vlan_filter_conf *vfc;
4459 for (vlan_id = 1; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
4460 vfc = &dev->data->vlan_filter_conf;
4461 vidx = vlan_id / 64;
4462 vbit = vlan_id % 64;
4464 /* Each bit corresponds to a VLAN id */
4465 if (vfc->ids[vidx] & (UINT64_C(1) << vbit)) {
4466 rc = bnxt_add_vlan_filter(bp, vlan_id);
4475 static int bnxt_restore_mac_filters(struct bnxt *bp)
4477 struct rte_eth_dev *dev = bp->eth_dev;
4478 struct rte_eth_dev_info dev_info;
4479 struct rte_ether_addr *addr;
4485 if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
4488 rc = bnxt_dev_info_get_op(dev, &dev_info);
4492 /* replay MAC address configuration */
4493 for (i = 1; i < dev_info.max_mac_addrs; i++) {
4494 addr = &dev->data->mac_addrs[i];
4496 /* skip zero address */
4497 if (rte_is_zero_ether_addr(addr))
4501 pool_mask = dev->data->mac_pool_sel[i];
4504 if (pool_mask & 1ULL) {
4505 rc = bnxt_mac_addr_add_op(dev, addr, i, pool);
4511 } while (pool_mask);
4517 static int bnxt_restore_filters(struct bnxt *bp)
4519 struct rte_eth_dev *dev = bp->eth_dev;
4522 if (dev->data->all_multicast) {
4523 ret = bnxt_allmulticast_enable_op(dev);
4527 if (dev->data->promiscuous) {
4528 ret = bnxt_promiscuous_enable_op(dev);
4533 ret = bnxt_restore_mac_filters(bp);
4537 ret = bnxt_restore_vlan_filters(bp);
4538 /* TODO restore other filters as well */
4542 static void bnxt_dev_recover(void *arg)
4544 struct bnxt *bp = arg;
4545 int timeout = bp->fw_reset_max_msecs;
4548 /* Clear Error flag so that device re-init should happen */
4549 bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
4552 rc = bnxt_hwrm_ver_get(bp, SHORT_HWRM_CMD_TIMEOUT);
4555 rte_delay_ms(BNXT_FW_READY_WAIT_INTERVAL);
4556 timeout -= BNXT_FW_READY_WAIT_INTERVAL;
4557 } while (rc && timeout);
4560 PMD_DRV_LOG(ERR, "FW is not Ready after reset\n");
4564 rc = bnxt_init_resources(bp, true);
4567 "Failed to initialize resources after reset\n");
4570 /* clear reset flag as the device is initialized now */
4571 bp->flags &= ~BNXT_FLAG_FW_RESET;
4573 rc = bnxt_dev_start_op(bp->eth_dev);
4575 PMD_DRV_LOG(ERR, "Failed to start port after reset\n");
4579 rc = bnxt_restore_filters(bp);
4583 PMD_DRV_LOG(INFO, "Recovered from FW reset\n");
4586 bnxt_dev_stop_op(bp->eth_dev);
4588 bp->flags |= BNXT_FLAG_FATAL_ERROR;
4589 bnxt_uninit_resources(bp, false);
4590 PMD_DRV_LOG(ERR, "Failed to recover from FW reset\n");
4593 void bnxt_dev_reset_and_resume(void *arg)
4595 struct bnxt *bp = arg;
4598 bnxt_dev_cleanup(bp);
4600 bnxt_wait_for_device_shutdown(bp);
4602 rc = rte_eal_alarm_set(US_PER_MS * bp->fw_reset_min_msecs,
4603 bnxt_dev_recover, (void *)bp);
4605 PMD_DRV_LOG(ERR, "Error setting recovery alarm");
4608 uint32_t bnxt_read_fw_status_reg(struct bnxt *bp, uint32_t index)
4610 struct bnxt_error_recovery_info *info = bp->recovery_info;
4611 uint32_t reg = info->status_regs[index];
4612 uint32_t type, offset, val = 0;
4614 type = BNXT_FW_STATUS_REG_TYPE(reg);
4615 offset = BNXT_FW_STATUS_REG_OFF(reg);
4618 case BNXT_FW_STATUS_REG_TYPE_CFG:
4619 rte_pci_read_config(bp->pdev, &val, sizeof(val), offset);
4621 case BNXT_FW_STATUS_REG_TYPE_GRC:
4622 offset = info->mapped_status_regs[index];
4624 case BNXT_FW_STATUS_REG_TYPE_BAR0:
4625 val = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
4633 static int bnxt_fw_reset_all(struct bnxt *bp)
4635 struct bnxt_error_recovery_info *info = bp->recovery_info;
4639 if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4640 /* Reset through master function driver */
4641 for (i = 0; i < info->reg_array_cnt; i++)
4642 bnxt_write_fw_reset_reg(bp, i);
4643 /* Wait for time specified by FW after triggering reset */
4644 rte_delay_ms(info->master_func_wait_period_after_reset);
4645 } else if (info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) {
4646 /* Reset with the help of Kong processor */
4647 rc = bnxt_hwrm_fw_reset(bp);
4649 PMD_DRV_LOG(ERR, "Failed to reset FW\n");
4655 static void bnxt_fw_reset_cb(void *arg)
4657 struct bnxt *bp = arg;
4658 struct bnxt_error_recovery_info *info = bp->recovery_info;
4661 /* Only Master function can do FW reset */
4662 if (bnxt_is_master_func(bp) &&
4663 bnxt_is_recovery_enabled(bp)) {
4664 rc = bnxt_fw_reset_all(bp);
4666 PMD_DRV_LOG(ERR, "Adapter recovery failed\n");
4671 /* if recovery method is ERROR_RECOVERY_CO_CPU, KONG will send
4672 * EXCEPTION_FATAL_ASYNC event to all the functions
4673 * (including MASTER FUNC). After receiving this Async, all the active
4674 * drivers should treat this case as FW initiated recovery
4676 if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4677 bp->fw_reset_min_msecs = BNXT_MIN_FW_READY_TIMEOUT;
4678 bp->fw_reset_max_msecs = BNXT_MAX_FW_RESET_TIMEOUT;
4680 /* To recover from error */
4681 rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
4686 /* Driver should poll FW heartbeat, reset_counter with the frequency
4687 * advertised by FW in HWRM_ERROR_RECOVERY_QCFG.
4688 * When the driver detects heartbeat stop or change in reset_counter,
4689 * it has to trigger a reset to recover from the error condition.
4690 * A “master PF” is the function who will have the privilege to
4691 * initiate the chimp reset. The master PF will be elected by the
4692 * firmware and will be notified through async message.
4694 static void bnxt_check_fw_health(void *arg)
4696 struct bnxt *bp = arg;
4697 struct bnxt_error_recovery_info *info = bp->recovery_info;
4698 uint32_t val = 0, wait_msec;
4700 if (!info || !bnxt_is_recovery_enabled(bp) ||
4701 is_bnxt_in_error(bp))
4704 val = bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
4705 if (val == info->last_heart_beat)
4708 info->last_heart_beat = val;
4710 val = bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
4711 if (val != info->last_reset_counter)
4714 info->last_reset_counter = val;
4716 rte_eal_alarm_set(US_PER_MS * info->driver_polling_freq,
4717 bnxt_check_fw_health, (void *)bp);
4721 /* Stop DMA to/from device */
4722 bp->flags |= BNXT_FLAG_FATAL_ERROR;
4723 bp->flags |= BNXT_FLAG_FW_RESET;
4725 PMD_DRV_LOG(ERR, "Detected FW dead condition\n");
4727 if (bnxt_is_master_func(bp))
4728 wait_msec = info->master_func_wait_period;
4730 wait_msec = info->normal_func_wait_period;
4732 rte_eal_alarm_set(US_PER_MS * wait_msec,
4733 bnxt_fw_reset_cb, (void *)bp);
4736 void bnxt_schedule_fw_health_check(struct bnxt *bp)
4738 uint32_t polling_freq;
4740 pthread_mutex_lock(&bp->health_check_lock);
4742 if (!bnxt_is_recovery_enabled(bp))
4745 if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
4748 polling_freq = bp->recovery_info->driver_polling_freq;
4750 rte_eal_alarm_set(US_PER_MS * polling_freq,
4751 bnxt_check_fw_health, (void *)bp);
4752 bp->flags |= BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4755 pthread_mutex_unlock(&bp->health_check_lock);
4758 static void bnxt_cancel_fw_health_check(struct bnxt *bp)
4760 if (!bnxt_is_recovery_enabled(bp))
4763 rte_eal_alarm_cancel(bnxt_check_fw_health, (void *)bp);
4764 bp->flags &= ~BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4767 static bool bnxt_vf_pciid(uint16_t device_id)
4769 switch (device_id) {
4770 case BROADCOM_DEV_ID_57304_VF:
4771 case BROADCOM_DEV_ID_57406_VF:
4772 case BROADCOM_DEV_ID_5731X_VF:
4773 case BROADCOM_DEV_ID_5741X_VF:
4774 case BROADCOM_DEV_ID_57414_VF:
4775 case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
4776 case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
4777 case BROADCOM_DEV_ID_58802_VF:
4778 case BROADCOM_DEV_ID_57500_VF1:
4779 case BROADCOM_DEV_ID_57500_VF2:
4787 static bool bnxt_thor_device(uint16_t device_id)
4789 switch (device_id) {
4790 case BROADCOM_DEV_ID_57508:
4791 case BROADCOM_DEV_ID_57504:
4792 case BROADCOM_DEV_ID_57502:
4793 case BROADCOM_DEV_ID_57508_MF1:
4794 case BROADCOM_DEV_ID_57504_MF1:
4795 case BROADCOM_DEV_ID_57502_MF1:
4796 case BROADCOM_DEV_ID_57508_MF2:
4797 case BROADCOM_DEV_ID_57504_MF2:
4798 case BROADCOM_DEV_ID_57502_MF2:
4799 case BROADCOM_DEV_ID_57500_VF1:
4800 case BROADCOM_DEV_ID_57500_VF2:
4808 bool bnxt_stratus_device(struct bnxt *bp)
4810 uint16_t device_id = bp->pdev->id.device_id;
4812 switch (device_id) {
4813 case BROADCOM_DEV_ID_STRATUS_NIC:
4814 case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
4815 case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
4823 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
4825 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
4826 struct bnxt *bp = eth_dev->data->dev_private;
4828 /* enable device (incl. PCI PM wakeup), and bus-mastering */
4829 bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
4830 bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
4831 if (!bp->bar0 || !bp->doorbell_base) {
4832 PMD_DRV_LOG(ERR, "Unable to access Hardware\n");
4836 bp->eth_dev = eth_dev;
4842 static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
4843 struct bnxt_ctx_pg_info *ctx_pg,
4848 struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
4849 const struct rte_memzone *mz = NULL;
4850 char mz_name[RTE_MEMZONE_NAMESIZE];
4851 rte_iova_t mz_phys_addr;
4852 uint64_t valid_bits = 0;
4859 rmem->nr_pages = RTE_ALIGN_MUL_CEIL(mem_size, BNXT_PAGE_SIZE) /
4861 rmem->page_size = BNXT_PAGE_SIZE;
4862 rmem->pg_arr = ctx_pg->ctx_pg_arr;
4863 rmem->dma_arr = ctx_pg->ctx_dma_arr;
4864 rmem->flags = BNXT_RMEM_VALID_PTE_FLAG;
4866 valid_bits = PTU_PTE_VALID;
4868 if (rmem->nr_pages > 1) {
4869 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
4870 "bnxt_ctx_pg_tbl%s_%x_%d",
4871 suffix, idx, bp->eth_dev->data->port_id);
4872 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
4873 mz = rte_memzone_lookup(mz_name);
4875 mz = rte_memzone_reserve_aligned(mz_name,
4879 RTE_MEMZONE_SIZE_HINT_ONLY |
4880 RTE_MEMZONE_IOVA_CONTIG,
4886 memset(mz->addr, 0, mz->len);
4887 mz_phys_addr = mz->iova;
4889 rmem->pg_tbl = mz->addr;
4890 rmem->pg_tbl_map = mz_phys_addr;
4891 rmem->pg_tbl_mz = mz;
4894 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_%s_%x_%d",
4895 suffix, idx, bp->eth_dev->data->port_id);
4896 mz = rte_memzone_lookup(mz_name);
4898 mz = rte_memzone_reserve_aligned(mz_name,
4902 RTE_MEMZONE_SIZE_HINT_ONLY |
4903 RTE_MEMZONE_IOVA_CONTIG,
4909 memset(mz->addr, 0, mz->len);
4910 mz_phys_addr = mz->iova;
4912 for (sz = 0, i = 0; sz < mem_size; sz += BNXT_PAGE_SIZE, i++) {
4913 rmem->pg_arr[i] = ((char *)mz->addr) + sz;
4914 rmem->dma_arr[i] = mz_phys_addr + sz;
4916 if (rmem->nr_pages > 1) {
4917 if (i == rmem->nr_pages - 2 &&
4918 (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
4919 valid_bits |= PTU_PTE_NEXT_TO_LAST;
4920 else if (i == rmem->nr_pages - 1 &&
4921 (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
4922 valid_bits |= PTU_PTE_LAST;
4924 rmem->pg_tbl[i] = rte_cpu_to_le_64(rmem->dma_arr[i] |
4930 if (rmem->vmem_size)
4931 rmem->vmem = (void **)mz->addr;
4932 rmem->dma_arr[0] = mz_phys_addr;
4936 static void bnxt_free_ctx_mem(struct bnxt *bp)
4940 if (!bp->ctx || !(bp->ctx->flags & BNXT_CTX_FLAG_INITED))
4943 bp->ctx->flags &= ~BNXT_CTX_FLAG_INITED;
4944 rte_memzone_free(bp->ctx->qp_mem.ring_mem.mz);
4945 rte_memzone_free(bp->ctx->srq_mem.ring_mem.mz);
4946 rte_memzone_free(bp->ctx->cq_mem.ring_mem.mz);
4947 rte_memzone_free(bp->ctx->vnic_mem.ring_mem.mz);
4948 rte_memzone_free(bp->ctx->stat_mem.ring_mem.mz);
4949 rte_memzone_free(bp->ctx->qp_mem.ring_mem.pg_tbl_mz);
4950 rte_memzone_free(bp->ctx->srq_mem.ring_mem.pg_tbl_mz);
4951 rte_memzone_free(bp->ctx->cq_mem.ring_mem.pg_tbl_mz);
4952 rte_memzone_free(bp->ctx->vnic_mem.ring_mem.pg_tbl_mz);
4953 rte_memzone_free(bp->ctx->stat_mem.ring_mem.pg_tbl_mz);
4955 for (i = 0; i < bp->ctx->tqm_fp_rings_count + 1; i++) {
4956 if (bp->ctx->tqm_mem[i])
4957 rte_memzone_free(bp->ctx->tqm_mem[i]->ring_mem.mz);
4964 #define bnxt_roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
4966 #define min_t(type, x, y) ({ \
4967 type __min1 = (x); \
4968 type __min2 = (y); \
4969 __min1 < __min2 ? __min1 : __min2; })
4971 #define max_t(type, x, y) ({ \
4972 type __max1 = (x); \
4973 type __max2 = (y); \
4974 __max1 > __max2 ? __max1 : __max2; })
4976 #define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
4978 int bnxt_alloc_ctx_mem(struct bnxt *bp)
4980 struct bnxt_ctx_pg_info *ctx_pg;
4981 struct bnxt_ctx_mem_info *ctx;
4982 uint32_t mem_size, ena, entries;
4983 uint32_t entries_sp, min;
4986 rc = bnxt_hwrm_func_backing_store_qcaps(bp);
4988 PMD_DRV_LOG(ERR, "Query context mem capability failed\n");
4992 if (!ctx || (ctx->flags & BNXT_CTX_FLAG_INITED))
4995 ctx_pg = &ctx->qp_mem;
4996 ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries;
4997 mem_size = ctx->qp_entry_size * ctx_pg->entries;
4998 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "qp_mem", 0);
5002 ctx_pg = &ctx->srq_mem;
5003 ctx_pg->entries = ctx->srq_max_l2_entries;
5004 mem_size = ctx->srq_entry_size * ctx_pg->entries;
5005 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "srq_mem", 0);
5009 ctx_pg = &ctx->cq_mem;
5010 ctx_pg->entries = ctx->cq_max_l2_entries;
5011 mem_size = ctx->cq_entry_size * ctx_pg->entries;
5012 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "cq_mem", 0);
5016 ctx_pg = &ctx->vnic_mem;
5017 ctx_pg->entries = ctx->vnic_max_vnic_entries +
5018 ctx->vnic_max_ring_table_entries;
5019 mem_size = ctx->vnic_entry_size * ctx_pg->entries;
5020 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "vnic_mem", 0);
5024 ctx_pg = &ctx->stat_mem;
5025 ctx_pg->entries = ctx->stat_max_entries;
5026 mem_size = ctx->stat_entry_size * ctx_pg->entries;
5027 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "stat_mem", 0);
5031 min = ctx->tqm_min_entries_per_ring;
5033 entries_sp = ctx->qp_max_l2_entries +
5034 ctx->vnic_max_vnic_entries +
5035 2 * ctx->qp_min_qp1_entries + min;
5036 entries_sp = bnxt_roundup(entries_sp, ctx->tqm_entries_multiple);
5038 entries = ctx->qp_max_l2_entries + ctx->qp_min_qp1_entries;
5039 entries = bnxt_roundup(entries, ctx->tqm_entries_multiple);
5040 entries = clamp_t(uint32_t, entries, min,
5041 ctx->tqm_max_entries_per_ring);
5042 for (i = 0, ena = 0; i < ctx->tqm_fp_rings_count + 1; i++) {
5043 ctx_pg = ctx->tqm_mem[i];
5044 ctx_pg->entries = i ? entries : entries_sp;
5045 mem_size = ctx->tqm_entry_size * ctx_pg->entries;
5046 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "tqm_mem", i);
5049 ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP << i;
5052 ena |= FUNC_BACKING_STORE_CFG_INPUT_DFLT_ENABLES;
5053 rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
5056 "Failed to configure context mem: rc = %d\n", rc);
5058 ctx->flags |= BNXT_CTX_FLAG_INITED;
5063 static int bnxt_alloc_stats_mem(struct bnxt *bp)
5065 struct rte_pci_device *pci_dev = bp->pdev;
5066 char mz_name[RTE_MEMZONE_NAMESIZE];
5067 const struct rte_memzone *mz = NULL;
5068 uint32_t total_alloc_len;
5069 rte_iova_t mz_phys_addr;
5071 if (pci_dev->id.device_id == BROADCOM_DEV_ID_NS2)
5074 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
5075 "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
5076 pci_dev->addr.bus, pci_dev->addr.devid,
5077 pci_dev->addr.function, "rx_port_stats");
5078 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5079 mz = rte_memzone_lookup(mz_name);
5081 RTE_CACHE_LINE_ROUNDUP(sizeof(struct rx_port_stats) +
5082 sizeof(struct rx_port_stats_ext) + 512);
5084 mz = rte_memzone_reserve(mz_name, total_alloc_len,
5087 RTE_MEMZONE_SIZE_HINT_ONLY |
5088 RTE_MEMZONE_IOVA_CONTIG);
5092 memset(mz->addr, 0, mz->len);
5093 mz_phys_addr = mz->iova;
5095 bp->rx_mem_zone = (const void *)mz;
5096 bp->hw_rx_port_stats = mz->addr;
5097 bp->hw_rx_port_stats_map = mz_phys_addr;
5099 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
5100 "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
5101 pci_dev->addr.bus, pci_dev->addr.devid,
5102 pci_dev->addr.function, "tx_port_stats");
5103 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5104 mz = rte_memzone_lookup(mz_name);
5106 RTE_CACHE_LINE_ROUNDUP(sizeof(struct tx_port_stats) +
5107 sizeof(struct tx_port_stats_ext) + 512);
5109 mz = rte_memzone_reserve(mz_name,
5113 RTE_MEMZONE_SIZE_HINT_ONLY |
5114 RTE_MEMZONE_IOVA_CONTIG);
5118 memset(mz->addr, 0, mz->len);
5119 mz_phys_addr = mz->iova;
5121 bp->tx_mem_zone = (const void *)mz;
5122 bp->hw_tx_port_stats = mz->addr;
5123 bp->hw_tx_port_stats_map = mz_phys_addr;
5124 bp->flags |= BNXT_FLAG_PORT_STATS;
5126 /* Display extended statistics if FW supports it */
5127 if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
5128 bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0 ||
5129 !(bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED))
5132 bp->hw_rx_port_stats_ext = (void *)
5133 ((uint8_t *)bp->hw_rx_port_stats +
5134 sizeof(struct rx_port_stats));
5135 bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
5136 sizeof(struct rx_port_stats);
5137 bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
5139 if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2 ||
5140 bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED) {
5141 bp->hw_tx_port_stats_ext = (void *)
5142 ((uint8_t *)bp->hw_tx_port_stats +
5143 sizeof(struct tx_port_stats));
5144 bp->hw_tx_port_stats_ext_map =
5145 bp->hw_tx_port_stats_map +
5146 sizeof(struct tx_port_stats);
5147 bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
5153 static int bnxt_setup_mac_addr(struct rte_eth_dev *eth_dev)
5155 struct bnxt *bp = eth_dev->data->dev_private;
5158 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
5159 RTE_ETHER_ADDR_LEN *
5162 if (eth_dev->data->mac_addrs == NULL) {
5163 PMD_DRV_LOG(ERR, "Failed to alloc MAC addr tbl\n");
5167 if (!BNXT_HAS_DFLT_MAC_SET(bp)) {
5171 /* Generate a random MAC address, if none was assigned by PF */
5172 PMD_DRV_LOG(INFO, "VF MAC address not assigned by Host PF\n");
5173 bnxt_eth_hw_addr_random(bp->mac_addr);
5175 "Assign random MAC:%02X:%02X:%02X:%02X:%02X:%02X\n",
5176 bp->mac_addr[0], bp->mac_addr[1], bp->mac_addr[2],
5177 bp->mac_addr[3], bp->mac_addr[4], bp->mac_addr[5]);
5179 rc = bnxt_hwrm_set_mac(bp);
5184 /* Copy the permanent MAC from the FUNC_QCAPS response */
5185 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, RTE_ETHER_ADDR_LEN);
5190 static int bnxt_restore_dflt_mac(struct bnxt *bp)
5194 /* MAC is already configured in FW */
5195 if (BNXT_HAS_DFLT_MAC_SET(bp))
5198 /* Restore the old MAC configured */
5199 rc = bnxt_hwrm_set_mac(bp);
5201 PMD_DRV_LOG(ERR, "Failed to restore MAC address\n");
5206 static void bnxt_config_vf_req_fwd(struct bnxt *bp)
5211 memset(bp->pf->vf_req_fwd, 0, sizeof(bp->pf->vf_req_fwd));
5213 if (!(bp->fw_cap & BNXT_FW_CAP_LINK_ADMIN))
5214 BNXT_HWRM_CMD_TO_FORWARD(HWRM_PORT_PHY_QCFG);
5215 BNXT_HWRM_CMD_TO_FORWARD(HWRM_FUNC_CFG);
5216 BNXT_HWRM_CMD_TO_FORWARD(HWRM_FUNC_VF_CFG);
5217 BNXT_HWRM_CMD_TO_FORWARD(HWRM_CFA_L2_FILTER_ALLOC);
5218 BNXT_HWRM_CMD_TO_FORWARD(HWRM_OEM_CMD);
5222 bnxt_get_svif(uint16_t port_id, bool func_svif,
5223 enum bnxt_ulp_intf_type type)
5225 struct rte_eth_dev *eth_dev;
5228 eth_dev = &rte_eth_devices[port_id];
5229 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5230 struct bnxt_representor *vfr = eth_dev->data->dev_private;
5234 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5237 eth_dev = vfr->parent_dev;
5240 bp = eth_dev->data->dev_private;
5242 return func_svif ? bp->func_svif : bp->port_svif;
5246 bnxt_get_vnic_id(uint16_t port, enum bnxt_ulp_intf_type type)
5248 struct rte_eth_dev *eth_dev;
5249 struct bnxt_vnic_info *vnic;
5252 eth_dev = &rte_eth_devices[port];
5253 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5254 struct bnxt_representor *vfr = eth_dev->data->dev_private;
5258 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5259 return vfr->dflt_vnic_id;
5261 eth_dev = vfr->parent_dev;
5264 bp = eth_dev->data->dev_private;
5266 vnic = BNXT_GET_DEFAULT_VNIC(bp);
5268 return vnic->fw_vnic_id;
5272 bnxt_get_fw_func_id(uint16_t port, enum bnxt_ulp_intf_type type)
5274 struct rte_eth_dev *eth_dev;
5277 eth_dev = &rte_eth_devices[port];
5278 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5279 struct bnxt_representor *vfr = eth_dev->data->dev_private;
5283 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5286 eth_dev = vfr->parent_dev;
5289 bp = eth_dev->data->dev_private;
5294 enum bnxt_ulp_intf_type
5295 bnxt_get_interface_type(uint16_t port)
5297 struct rte_eth_dev *eth_dev;
5300 eth_dev = &rte_eth_devices[port];
5301 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev))
5302 return BNXT_ULP_INTF_TYPE_VF_REP;
5304 bp = eth_dev->data->dev_private;
5306 return BNXT_ULP_INTF_TYPE_PF;
5307 else if (BNXT_VF_IS_TRUSTED(bp))
5308 return BNXT_ULP_INTF_TYPE_TRUSTED_VF;
5309 else if (BNXT_VF(bp))
5310 return BNXT_ULP_INTF_TYPE_VF;
5312 return BNXT_ULP_INTF_TYPE_INVALID;
5316 bnxt_get_phy_port_id(uint16_t port_id)
5318 struct bnxt_representor *vfr;
5319 struct rte_eth_dev *eth_dev;
5322 eth_dev = &rte_eth_devices[port_id];
5323 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5324 vfr = eth_dev->data->dev_private;
5328 eth_dev = vfr->parent_dev;
5331 bp = eth_dev->data->dev_private;
5333 return BNXT_PF(bp) ? bp->pf->port_id : bp->parent->port_id;
5337 bnxt_get_parif(uint16_t port_id, enum bnxt_ulp_intf_type type)
5339 struct rte_eth_dev *eth_dev;
5342 eth_dev = &rte_eth_devices[port_id];
5343 if (BNXT_ETH_DEV_IS_REPRESENTOR(eth_dev)) {
5344 struct bnxt_representor *vfr = eth_dev->data->dev_private;
5348 if (type == BNXT_ULP_INTF_TYPE_VF_REP)
5349 return vfr->fw_fid - 1;
5351 eth_dev = vfr->parent_dev;
5354 bp = eth_dev->data->dev_private;
5356 return BNXT_PF(bp) ? bp->fw_fid - 1 : bp->parent->fid - 1;
5360 bnxt_get_vport(uint16_t port_id)
5362 return (1 << bnxt_get_phy_port_id(port_id));
5365 static void bnxt_alloc_error_recovery_info(struct bnxt *bp)
5367 struct bnxt_error_recovery_info *info = bp->recovery_info;
5370 if (!(bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS))
5371 memset(info, 0, sizeof(*info));
5375 if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
5378 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5381 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5383 bp->recovery_info = info;
5386 static void bnxt_check_fw_status(struct bnxt *bp)
5390 if (!(bp->recovery_info &&
5391 (bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS)))
5394 fw_status = bnxt_read_fw_status_reg(bp, BNXT_FW_STATUS_REG);
5395 if (fw_status != BNXT_FW_STATUS_HEALTHY)
5396 PMD_DRV_LOG(ERR, "Firmware not responding, status: %#x\n",
5400 static int bnxt_map_hcomm_fw_status_reg(struct bnxt *bp)
5402 struct bnxt_error_recovery_info *info = bp->recovery_info;
5403 uint32_t status_loc;
5406 rte_write32(HCOMM_STATUS_STRUCT_LOC, (uint8_t *)bp->bar0 +
5407 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5408 sig_ver = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5409 BNXT_GRCP_WINDOW_2_BASE +
5410 offsetof(struct hcomm_status,
5412 /* If the signature is absent, then FW does not support this feature */
5413 if ((sig_ver & HCOMM_STATUS_SIGNATURE_MASK) !=
5414 HCOMM_STATUS_SIGNATURE_VAL)
5418 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5422 bp->recovery_info = info;
5424 memset(info, 0, sizeof(*info));
5427 status_loc = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5428 BNXT_GRCP_WINDOW_2_BASE +
5429 offsetof(struct hcomm_status,
5432 /* Only pre-map the FW health status GRC register */
5433 if (BNXT_FW_STATUS_REG_TYPE(status_loc) != BNXT_FW_STATUS_REG_TYPE_GRC)
5436 info->status_regs[BNXT_FW_STATUS_REG] = status_loc;
5437 info->mapped_status_regs[BNXT_FW_STATUS_REG] =
5438 BNXT_GRCP_WINDOW_2_BASE + (status_loc & BNXT_GRCP_OFFSET_MASK);
5440 rte_write32((status_loc & BNXT_GRCP_BASE_MASK), (uint8_t *)bp->bar0 +
5441 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5443 bp->fw_cap |= BNXT_FW_CAP_HCOMM_FW_STATUS;
5448 static int bnxt_init_fw(struct bnxt *bp)
5455 rc = bnxt_map_hcomm_fw_status_reg(bp);
5459 rc = bnxt_hwrm_ver_get(bp, DFLT_HWRM_CMD_TIMEOUT);
5461 bnxt_check_fw_status(bp);
5465 rc = bnxt_hwrm_func_reset(bp);
5469 rc = bnxt_hwrm_vnic_qcaps(bp);
5473 rc = bnxt_hwrm_queue_qportcfg(bp);
5477 /* Get the MAX capabilities for this function.
5478 * This function also allocates context memory for TQM rings and
5479 * informs the firmware about this allocated backing store memory.
5481 rc = bnxt_hwrm_func_qcaps(bp);
5485 rc = bnxt_hwrm_func_qcfg(bp, &mtu);
5489 bnxt_hwrm_port_mac_qcfg(bp);
5491 bnxt_hwrm_parent_pf_qcfg(bp);
5493 bnxt_hwrm_port_phy_qcaps(bp);
5495 bnxt_alloc_error_recovery_info(bp);
5496 /* Get the adapter error recovery support info */
5497 rc = bnxt_hwrm_error_recovery_qcfg(bp);
5499 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5501 bnxt_hwrm_port_led_qcaps(bp);
5507 bnxt_init_locks(struct bnxt *bp)
5511 err = pthread_mutex_init(&bp->flow_lock, NULL);
5513 PMD_DRV_LOG(ERR, "Unable to initialize flow_lock\n");
5517 err = pthread_mutex_init(&bp->def_cp_lock, NULL);
5519 PMD_DRV_LOG(ERR, "Unable to initialize def_cp_lock\n");
5521 err = pthread_mutex_init(&bp->health_check_lock, NULL);
5523 PMD_DRV_LOG(ERR, "Unable to initialize health_check_lock\n");
5527 static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
5531 rc = bnxt_init_fw(bp);
5535 if (!reconfig_dev) {
5536 rc = bnxt_setup_mac_addr(bp->eth_dev);
5540 rc = bnxt_restore_dflt_mac(bp);
5545 bnxt_config_vf_req_fwd(bp);
5547 rc = bnxt_hwrm_func_driver_register(bp);
5549 PMD_DRV_LOG(ERR, "Failed to register driver");
5554 if (bp->pdev->max_vfs) {
5555 rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
5557 PMD_DRV_LOG(ERR, "Failed to allocate VFs\n");
5561 rc = bnxt_hwrm_allocate_pf_only(bp);
5564 "Failed to allocate PF resources");
5570 rc = bnxt_alloc_mem(bp, reconfig_dev);
5574 rc = bnxt_setup_int(bp);
5578 rc = bnxt_request_int(bp);
5582 rc = bnxt_init_ctx_mem(bp);
5584 PMD_DRV_LOG(ERR, "Failed to init adv_flow_counters\n");
5588 rc = bnxt_init_locks(bp);
5596 bnxt_parse_devarg_truflow(__rte_unused const char *key,
5597 const char *value, void *opaque_arg)
5599 struct bnxt *bp = opaque_arg;
5600 unsigned long truflow;
5603 if (!value || !opaque_arg) {
5605 "Invalid parameter passed to truflow devargs.\n");
5609 truflow = strtoul(value, &end, 10);
5610 if (end == NULL || *end != '\0' ||
5611 (truflow == ULONG_MAX && errno == ERANGE)) {
5613 "Invalid parameter passed to truflow devargs.\n");
5617 if (BNXT_DEVARG_TRUFLOW_INVALID(truflow)) {
5619 "Invalid value passed to truflow devargs.\n");
5624 bp->flags |= BNXT_FLAG_TRUFLOW_EN;
5625 PMD_DRV_LOG(INFO, "Host-based truflow feature enabled.\n");
5627 bp->flags &= ~BNXT_FLAG_TRUFLOW_EN;
5628 PMD_DRV_LOG(INFO, "Host-based truflow feature disabled.\n");
5635 bnxt_parse_devarg_flow_xstat(__rte_unused const char *key,
5636 const char *value, void *opaque_arg)
5638 struct bnxt *bp = opaque_arg;
5639 unsigned long flow_xstat;
5642 if (!value || !opaque_arg) {
5644 "Invalid parameter passed to flow_xstat devarg.\n");
5648 flow_xstat = strtoul(value, &end, 10);
5649 if (end == NULL || *end != '\0' ||
5650 (flow_xstat == ULONG_MAX && errno == ERANGE)) {
5652 "Invalid parameter passed to flow_xstat devarg.\n");
5656 if (BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat)) {
5658 "Invalid value passed to flow_xstat devarg.\n");
5662 bp->flags |= BNXT_FLAG_FLOW_XSTATS_EN;
5663 if (BNXT_FLOW_XSTATS_EN(bp))
5664 PMD_DRV_LOG(INFO, "flow_xstat feature enabled.\n");
5670 bnxt_parse_devarg_max_num_kflows(__rte_unused const char *key,
5671 const char *value, void *opaque_arg)
5673 struct bnxt *bp = opaque_arg;
5674 unsigned long max_num_kflows;
5677 if (!value || !opaque_arg) {
5679 "Invalid parameter passed to max_num_kflows devarg.\n");
5683 max_num_kflows = strtoul(value, &end, 10);
5684 if (end == NULL || *end != '\0' ||
5685 (max_num_kflows == ULONG_MAX && errno == ERANGE)) {
5687 "Invalid parameter passed to max_num_kflows devarg.\n");
5691 if (bnxt_devarg_max_num_kflow_invalid(max_num_kflows)) {
5693 "Invalid value passed to max_num_kflows devarg.\n");
5697 bp->max_num_kflows = max_num_kflows;
5698 if (bp->max_num_kflows)
5699 PMD_DRV_LOG(INFO, "max_num_kflows set as %ldK.\n",
5706 bnxt_parse_devarg_rep_is_pf(__rte_unused const char *key,
5707 const char *value, void *opaque_arg)
5709 struct bnxt_representor *vfr_bp = opaque_arg;
5710 unsigned long rep_is_pf;
5713 if (!value || !opaque_arg) {
5715 "Invalid parameter passed to rep_is_pf devargs.\n");
5719 rep_is_pf = strtoul(value, &end, 10);
5720 if (end == NULL || *end != '\0' ||
5721 (rep_is_pf == ULONG_MAX && errno == ERANGE)) {
5723 "Invalid parameter passed to rep_is_pf devargs.\n");
5727 if (BNXT_DEVARG_REP_IS_PF_INVALID(rep_is_pf)) {
5729 "Invalid value passed to rep_is_pf devargs.\n");
5733 vfr_bp->flags |= rep_is_pf;
5734 if (BNXT_REP_PF(vfr_bp))
5735 PMD_DRV_LOG(INFO, "PF representor\n");
5737 PMD_DRV_LOG(INFO, "VF representor\n");
5743 bnxt_parse_devarg_rep_based_pf(__rte_unused const char *key,
5744 const char *value, void *opaque_arg)
5746 struct bnxt_representor *vfr_bp = opaque_arg;
5747 unsigned long rep_based_pf;
5750 if (!value || !opaque_arg) {
5752 "Invalid parameter passed to rep_based_pf "
5757 rep_based_pf = strtoul(value, &end, 10);
5758 if (end == NULL || *end != '\0' ||
5759 (rep_based_pf == ULONG_MAX && errno == ERANGE)) {
5761 "Invalid parameter passed to rep_based_pf "
5766 if (BNXT_DEVARG_REP_BASED_PF_INVALID(rep_based_pf)) {
5768 "Invalid value passed to rep_based_pf devargs.\n");
5772 vfr_bp->rep_based_pf = rep_based_pf;
5773 PMD_DRV_LOG(INFO, "rep-based-pf = %d\n", vfr_bp->rep_based_pf);
5779 bnxt_parse_devarg_rep_q_r2f(__rte_unused const char *key,
5780 const char *value, void *opaque_arg)
5782 struct bnxt_representor *vfr_bp = opaque_arg;
5783 unsigned long rep_q_r2f;
5786 if (!value || !opaque_arg) {
5788 "Invalid parameter passed to rep_q_r2f "
5793 rep_q_r2f = strtoul(value, &end, 10);
5794 if (end == NULL || *end != '\0' ||
5795 (rep_q_r2f == ULONG_MAX && errno == ERANGE)) {
5797 "Invalid parameter passed to rep_q_r2f "
5802 if (BNXT_DEVARG_REP_Q_R2F_INVALID(rep_q_r2f)) {
5804 "Invalid value passed to rep_q_r2f devargs.\n");
5808 vfr_bp->rep_q_r2f = rep_q_r2f;
5809 vfr_bp->flags |= BNXT_REP_Q_R2F_VALID;
5810 PMD_DRV_LOG(INFO, "rep-q-r2f = %d\n", vfr_bp->rep_q_r2f);
5816 bnxt_parse_devarg_rep_q_f2r(__rte_unused const char *key,
5817 const char *value, void *opaque_arg)
5819 struct bnxt_representor *vfr_bp = opaque_arg;
5820 unsigned long rep_q_f2r;
5823 if (!value || !opaque_arg) {
5825 "Invalid parameter passed to rep_q_f2r "
5830 rep_q_f2r = strtoul(value, &end, 10);
5831 if (end == NULL || *end != '\0' ||
5832 (rep_q_f2r == ULONG_MAX && errno == ERANGE)) {
5834 "Invalid parameter passed to rep_q_f2r "
5839 if (BNXT_DEVARG_REP_Q_F2R_INVALID(rep_q_f2r)) {
5841 "Invalid value passed to rep_q_f2r devargs.\n");
5845 vfr_bp->rep_q_f2r = rep_q_f2r;
5846 vfr_bp->flags |= BNXT_REP_Q_F2R_VALID;
5847 PMD_DRV_LOG(INFO, "rep-q-f2r = %d\n", vfr_bp->rep_q_f2r);
5853 bnxt_parse_devarg_rep_fc_r2f(__rte_unused const char *key,
5854 const char *value, void *opaque_arg)
5856 struct bnxt_representor *vfr_bp = opaque_arg;
5857 unsigned long rep_fc_r2f;
5860 if (!value || !opaque_arg) {
5862 "Invalid parameter passed to rep_fc_r2f "
5867 rep_fc_r2f = strtoul(value, &end, 10);
5868 if (end == NULL || *end != '\0' ||
5869 (rep_fc_r2f == ULONG_MAX && errno == ERANGE)) {
5871 "Invalid parameter passed to rep_fc_r2f "
5876 if (BNXT_DEVARG_REP_FC_R2F_INVALID(rep_fc_r2f)) {
5878 "Invalid value passed to rep_fc_r2f devargs.\n");
5882 vfr_bp->flags |= BNXT_REP_FC_R2F_VALID;
5883 vfr_bp->rep_fc_r2f = rep_fc_r2f;
5884 PMD_DRV_LOG(INFO, "rep-fc-r2f = %lu\n", rep_fc_r2f);
5890 bnxt_parse_devarg_rep_fc_f2r(__rte_unused const char *key,
5891 const char *value, void *opaque_arg)
5893 struct bnxt_representor *vfr_bp = opaque_arg;
5894 unsigned long rep_fc_f2r;
5897 if (!value || !opaque_arg) {
5899 "Invalid parameter passed to rep_fc_f2r "
5904 rep_fc_f2r = strtoul(value, &end, 10);
5905 if (end == NULL || *end != '\0' ||
5906 (rep_fc_f2r == ULONG_MAX && errno == ERANGE)) {
5908 "Invalid parameter passed to rep_fc_f2r "
5913 if (BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)) {
5915 "Invalid value passed to rep_fc_f2r devargs.\n");
5919 vfr_bp->flags |= BNXT_REP_FC_F2R_VALID;
5920 vfr_bp->rep_fc_f2r = rep_fc_f2r;
5921 PMD_DRV_LOG(INFO, "rep-fc-f2r = %lu\n", rep_fc_f2r);
5927 bnxt_parse_dev_args(struct bnxt *bp, struct rte_devargs *devargs)
5929 struct rte_kvargs *kvlist;
5931 if (devargs == NULL)
5934 kvlist = rte_kvargs_parse(devargs->args, bnxt_dev_args);
5939 * Handler for "truflow" devarg.
5940 * Invoked as for ex: "-w 0000:00:0d.0,host-based-truflow=1"
5942 rte_kvargs_process(kvlist, BNXT_DEVARG_TRUFLOW,
5943 bnxt_parse_devarg_truflow, bp);
5946 * Handler for "flow_xstat" devarg.
5947 * Invoked as for ex: "-w 0000:00:0d.0,flow_xstat=1"
5949 rte_kvargs_process(kvlist, BNXT_DEVARG_FLOW_XSTAT,
5950 bnxt_parse_devarg_flow_xstat, bp);
5953 * Handler for "max_num_kflows" devarg.
5954 * Invoked as for ex: "-w 000:00:0d.0,max_num_kflows=32"
5956 rte_kvargs_process(kvlist, BNXT_DEVARG_MAX_NUM_KFLOWS,
5957 bnxt_parse_devarg_max_num_kflows, bp);
5959 rte_kvargs_free(kvlist);
5962 static int bnxt_alloc_switch_domain(struct bnxt *bp)
5966 if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
5967 rc = rte_eth_switch_domain_alloc(&bp->switch_domain_id);
5970 "Failed to alloc switch domain: %d\n", rc);
5973 "Switch domain allocated %d\n",
5974 bp->switch_domain_id);
5981 bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
5983 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
5984 static int version_printed;
5988 if (version_printed++ == 0)
5989 PMD_DRV_LOG(INFO, "%s\n", bnxt_version);
5991 eth_dev->dev_ops = &bnxt_dev_ops;
5992 eth_dev->rx_queue_count = bnxt_rx_queue_count_op;
5993 eth_dev->rx_descriptor_status = bnxt_rx_descriptor_status_op;
5994 eth_dev->tx_descriptor_status = bnxt_tx_descriptor_status_op;
5995 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
5996 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
5999 * For secondary processes, we don't initialise any further
6000 * as primary has already done this work.
6002 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6005 rte_eth_copy_pci_info(eth_dev, pci_dev);
6006 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
6008 bp = eth_dev->data->dev_private;
6010 /* Parse dev arguments passed on when starting the DPDK application. */
6011 bnxt_parse_dev_args(bp, pci_dev->device.devargs);
6013 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
6015 if (bnxt_vf_pciid(pci_dev->id.device_id))
6016 bp->flags |= BNXT_FLAG_VF;
6018 if (bnxt_thor_device(pci_dev->id.device_id))
6019 bp->flags |= BNXT_FLAG_THOR_CHIP;
6021 if (pci_dev->id.device_id == BROADCOM_DEV_ID_58802 ||
6022 pci_dev->id.device_id == BROADCOM_DEV_ID_58804 ||
6023 pci_dev->id.device_id == BROADCOM_DEV_ID_58808 ||
6024 pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
6025 bp->flags |= BNXT_FLAG_STINGRAY;
6027 if (BNXT_TRUFLOW_EN(bp)) {
6028 /* extra mbuf field is required to store CFA code from mark */
6029 static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
6030 .name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
6031 .size = sizeof(bnxt_cfa_code_dynfield_t),
6032 .align = __alignof__(bnxt_cfa_code_dynfield_t),
6034 bnxt_cfa_code_dynfield_offset =
6035 rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
6036 if (bnxt_cfa_code_dynfield_offset < 0) {
6038 "Failed to register mbuf field for TruFlow mark\n");
6043 rc = bnxt_init_board(eth_dev);
6046 "Failed to initialize board rc: %x\n", rc);
6050 rc = bnxt_alloc_pf_info(bp);
6054 rc = bnxt_alloc_link_info(bp);
6058 rc = bnxt_alloc_parent_info(bp);
6062 rc = bnxt_alloc_hwrm_resources(bp);
6065 "Failed to allocate hwrm resource rc: %x\n", rc);
6068 rc = bnxt_alloc_leds_info(bp);
6072 rc = bnxt_alloc_cos_queues(bp);
6076 rc = bnxt_init_resources(bp, false);
6080 rc = bnxt_alloc_stats_mem(bp);
6084 bnxt_alloc_switch_domain(bp);
6087 DRV_MODULE_NAME "found at mem %" PRIX64 ", node addr %pM\n",
6088 pci_dev->mem_resource[0].phys_addr,
6089 pci_dev->mem_resource[0].addr);
6094 bnxt_dev_uninit(eth_dev);
6099 static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
6108 ctx->dma = RTE_BAD_IOVA;
6109 ctx->ctx_id = BNXT_CTX_VAL_INVAL;
6112 static void bnxt_unregister_fc_ctx_mem(struct bnxt *bp)
6114 bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
6115 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
6116 bp->flow_stat->rx_fc_out_tbl.ctx_id,
6117 bp->flow_stat->max_fc,
6120 bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
6121 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
6122 bp->flow_stat->tx_fc_out_tbl.ctx_id,
6123 bp->flow_stat->max_fc,
6126 if (bp->flow_stat->rx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6127 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_in_tbl.ctx_id);
6128 bp->flow_stat->rx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6130 if (bp->flow_stat->rx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6131 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_out_tbl.ctx_id);
6132 bp->flow_stat->rx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6134 if (bp->flow_stat->tx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6135 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_in_tbl.ctx_id);
6136 bp->flow_stat->tx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6138 if (bp->flow_stat->tx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6139 bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_out_tbl.ctx_id);
6140 bp->flow_stat->tx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6143 static void bnxt_uninit_fc_ctx_mem(struct bnxt *bp)
6145 bnxt_unregister_fc_ctx_mem(bp);
6147 bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_in_tbl);
6148 bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_out_tbl);
6149 bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_in_tbl);
6150 bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_out_tbl);
6153 static void bnxt_uninit_ctx_mem(struct bnxt *bp)
6155 if (BNXT_FLOW_XSTATS_EN(bp))
6156 bnxt_uninit_fc_ctx_mem(bp);
6160 bnxt_free_error_recovery_info(struct bnxt *bp)
6162 rte_free(bp->recovery_info);
6163 bp->recovery_info = NULL;
6164 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
6168 bnxt_uninit_locks(struct bnxt *bp)
6170 pthread_mutex_destroy(&bp->flow_lock);
6171 pthread_mutex_destroy(&bp->def_cp_lock);
6172 pthread_mutex_destroy(&bp->health_check_lock);
6174 pthread_mutex_destroy(&bp->rep_info->vfr_lock);
6175 pthread_mutex_destroy(&bp->rep_info->vfr_start_lock);
6180 bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
6185 bnxt_free_mem(bp, reconfig_dev);
6187 bnxt_hwrm_func_buf_unrgtr(bp);
6188 rte_free(bp->pf->vf_req_buf);
6190 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
6191 bp->flags &= ~BNXT_FLAG_REGISTERED;
6192 bnxt_free_ctx_mem(bp);
6193 if (!reconfig_dev) {
6194 bnxt_free_hwrm_resources(bp);
6195 bnxt_free_error_recovery_info(bp);
6198 bnxt_uninit_ctx_mem(bp);
6200 bnxt_uninit_locks(bp);
6201 bnxt_free_flow_stats_info(bp);
6202 bnxt_free_rep_info(bp);
6203 rte_free(bp->ptp_cfg);
6209 bnxt_dev_uninit(struct rte_eth_dev *eth_dev)
6211 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6214 PMD_DRV_LOG(DEBUG, "Calling Device uninit\n");
6216 if (eth_dev->state != RTE_ETH_DEV_UNUSED)
6217 bnxt_dev_close_op(eth_dev);
6222 static int bnxt_pci_remove_dev_with_reps(struct rte_eth_dev *eth_dev)
6224 struct bnxt *bp = eth_dev->data->dev_private;
6225 struct rte_eth_dev *vf_rep_eth_dev;
6231 for (i = 0; i < bp->num_reps; i++) {
6232 vf_rep_eth_dev = bp->rep_info[i].vfr_eth_dev;
6233 if (!vf_rep_eth_dev)
6235 PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR pci remove\n",
6236 vf_rep_eth_dev->data->port_id);
6237 rte_eth_dev_destroy(vf_rep_eth_dev, bnxt_representor_uninit);
6239 PMD_DRV_LOG(DEBUG, "BNXT Port:%d pci remove\n",
6240 eth_dev->data->port_id);
6241 ret = rte_eth_dev_destroy(eth_dev, bnxt_dev_uninit);
6246 static void bnxt_free_rep_info(struct bnxt *bp)
6248 rte_free(bp->rep_info);
6249 bp->rep_info = NULL;
6250 rte_free(bp->cfa_code_map);
6251 bp->cfa_code_map = NULL;
6254 static int bnxt_init_rep_info(struct bnxt *bp)
6261 bp->rep_info = rte_zmalloc("bnxt_rep_info",
6262 sizeof(bp->rep_info[0]) * BNXT_MAX_VF_REPS,
6264 if (!bp->rep_info) {
6265 PMD_DRV_LOG(ERR, "Failed to alloc memory for rep info\n");
6268 bp->cfa_code_map = rte_zmalloc("bnxt_cfa_code_map",
6269 sizeof(*bp->cfa_code_map) *
6270 BNXT_MAX_CFA_CODE, 0);
6271 if (!bp->cfa_code_map) {
6272 PMD_DRV_LOG(ERR, "Failed to alloc memory for cfa_code_map\n");
6273 bnxt_free_rep_info(bp);
6277 for (i = 0; i < BNXT_MAX_CFA_CODE; i++)
6278 bp->cfa_code_map[i] = BNXT_VF_IDX_INVALID;
6280 rc = pthread_mutex_init(&bp->rep_info->vfr_lock, NULL);
6282 PMD_DRV_LOG(ERR, "Unable to initialize vfr_lock\n");
6283 bnxt_free_rep_info(bp);
6287 rc = pthread_mutex_init(&bp->rep_info->vfr_start_lock, NULL);
6289 PMD_DRV_LOG(ERR, "Unable to initialize vfr_start_lock\n");
6290 bnxt_free_rep_info(bp);
6297 static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
6298 struct rte_eth_devargs eth_da,
6299 struct rte_eth_dev *backing_eth_dev,
6300 const char *dev_args)
6302 struct rte_eth_dev *vf_rep_eth_dev;
6303 char name[RTE_ETH_NAME_MAX_LEN];
6304 struct bnxt *backing_bp;
6307 struct rte_kvargs *kvlist;
6309 num_rep = eth_da.nb_representor_ports;
6310 if (num_rep > BNXT_MAX_VF_REPS) {
6311 PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
6312 num_rep, BNXT_MAX_VF_REPS);
6316 if (num_rep >= RTE_MAX_ETHPORTS) {
6318 "nb_representor_ports = %d > %d MAX ETHPORTS\n",
6319 num_rep, RTE_MAX_ETHPORTS);
6323 backing_bp = backing_eth_dev->data->dev_private;
6325 if (!(BNXT_PF(backing_bp) || BNXT_VF_IS_TRUSTED(backing_bp))) {
6327 "Not a PF or trusted VF. No Representor support\n");
6328 /* Returning an error is not an option.
6329 * Applications are not handling this correctly
6334 if (bnxt_init_rep_info(backing_bp))
6337 for (i = 0; i < num_rep; i++) {
6338 struct bnxt_representor representor = {
6339 .vf_id = eth_da.representor_ports[i],
6340 .switch_domain_id = backing_bp->switch_domain_id,
6341 .parent_dev = backing_eth_dev
6344 if (representor.vf_id >= BNXT_MAX_VF_REPS) {
6345 PMD_DRV_LOG(ERR, "VF-Rep id %d >= %d MAX VF ID\n",
6346 representor.vf_id, BNXT_MAX_VF_REPS);
6350 /* representor port net_bdf_port */
6351 snprintf(name, sizeof(name), "net_%s_representor_%d",
6352 pci_dev->device.name, eth_da.representor_ports[i]);
6354 kvlist = rte_kvargs_parse(dev_args, bnxt_dev_args);
6357 * Handler for "rep_is_pf" devarg.
6358 * Invoked as for ex: "-w 000:00:0d.0,
6359 * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6361 rte_kvargs_process(kvlist, BNXT_DEVARG_REP_IS_PF,
6362 bnxt_parse_devarg_rep_is_pf,
6363 (void *)&representor);
6365 * Handler for "rep_based_pf" devarg.
6366 * Invoked as for ex: "-w 000:00:0d.0,
6367 * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6369 rte_kvargs_process(kvlist, BNXT_DEVARG_REP_BASED_PF,
6370 bnxt_parse_devarg_rep_based_pf,
6371 (void *)&representor);
6373 * Handler for "rep_based_pf" devarg.
6374 * Invoked as for ex: "-w 000:00:0d.0,
6375 * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6377 rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_R2F,
6378 bnxt_parse_devarg_rep_q_r2f,
6379 (void *)&representor);
6381 * Handler for "rep_based_pf" devarg.
6382 * Invoked as for ex: "-w 000:00:0d.0,
6383 * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6385 rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_F2R,
6386 bnxt_parse_devarg_rep_q_f2r,
6387 (void *)&representor);
6389 * Handler for "rep_based_pf" devarg.
6390 * Invoked as for ex: "-w 000:00:0d.0,
6391 * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6393 rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_R2F,
6394 bnxt_parse_devarg_rep_fc_r2f,
6395 (void *)&representor);
6397 * Handler for "rep_based_pf" devarg.
6398 * Invoked as for ex: "-w 000:00:0d.0,
6399 * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6401 rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_F2R,
6402 bnxt_parse_devarg_rep_fc_f2r,
6403 (void *)&representor);
6406 ret = rte_eth_dev_create(&pci_dev->device, name,
6407 sizeof(struct bnxt_representor),
6409 bnxt_representor_init,
6412 PMD_DRV_LOG(ERR, "failed to create bnxt vf "
6413 "representor %s.", name);
6417 vf_rep_eth_dev = rte_eth_dev_allocated(name);
6418 if (!vf_rep_eth_dev) {
6419 PMD_DRV_LOG(ERR, "Failed to find the eth_dev"
6420 " for VF-Rep: %s.", name);
6425 PMD_DRV_LOG(DEBUG, "BNXT Port:%d VFR pci probe\n",
6426 backing_eth_dev->data->port_id);
6427 backing_bp->rep_info[representor.vf_id].vfr_eth_dev =
6429 backing_bp->num_reps++;
6436 /* If num_rep > 1, then rollback already created
6437 * ports, since we'll be failing the probe anyway
6440 bnxt_pci_remove_dev_with_reps(backing_eth_dev);
6445 static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
6446 struct rte_pci_device *pci_dev)
6448 struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
6449 struct rte_eth_dev *backing_eth_dev;
6453 if (pci_dev->device.devargs) {
6454 ret = rte_eth_devargs_parse(pci_dev->device.devargs->args,
6460 num_rep = eth_da.nb_representor_ports;
6461 PMD_DRV_LOG(DEBUG, "nb_representor_ports = %d\n",
6464 /* We could come here after first level of probe is already invoked
6465 * as part of an application bringup(OVS-DPDK vswitchd), so first check
6466 * for already allocated eth_dev for the backing device (PF/Trusted VF)
6468 backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6469 if (backing_eth_dev == NULL) {
6470 ret = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
6471 sizeof(struct bnxt),
6472 eth_dev_pci_specific_init, pci_dev,
6473 bnxt_dev_init, NULL);
6475 if (ret || !num_rep)
6478 backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6480 PMD_DRV_LOG(DEBUG, "BNXT Port:%d pci probe\n",
6481 backing_eth_dev->data->port_id);
6486 /* probe representor ports now */
6487 ret = bnxt_rep_port_probe(pci_dev, eth_da, backing_eth_dev,
6488 pci_dev->device.devargs->args);
6493 static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
6495 struct rte_eth_dev *eth_dev;
6497 eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6499 return 0; /* Invoked typically only by OVS-DPDK, by the
6500 * time it comes here the eth_dev is already
6501 * deleted by rte_eth_dev_close(), so returning
6502 * +ve value will at least help in proper cleanup
6505 PMD_DRV_LOG(DEBUG, "BNXT Port:%d pci remove\n", eth_dev->data->port_id);
6506 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
6507 if (eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
6508 return rte_eth_dev_destroy(eth_dev,
6509 bnxt_representor_uninit);
6511 return rte_eth_dev_destroy(eth_dev,
6514 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
6518 static struct rte_pci_driver bnxt_rte_pmd = {
6519 .id_table = bnxt_pci_id_map,
6520 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
6521 RTE_PCI_DRV_PROBE_AGAIN, /* Needed in case of VF-REPs
6524 .probe = bnxt_pci_probe,
6525 .remove = bnxt_pci_remove,
6529 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
6531 if (strcmp(dev->device->driver->name, drv->driver.name))
6537 bool is_bnxt_supported(struct rte_eth_dev *dev)
6539 return is_device_supported(dev, &bnxt_rte_pmd);
6542 RTE_LOG_REGISTER(bnxt_logtype_driver, pmd.net.bnxt.driver, NOTICE);
6543 RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
6544 RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
6545 RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");