1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
10 #include <rte_ethdev_driver.h>
11 #include <rte_ethdev_pci.h>
12 #include <rte_malloc.h>
13 #include <rte_cycles.h>
14 #include <rte_alarm.h>
15 #include <rte_kvargs.h>
18 #include "bnxt_filter.h"
19 #include "bnxt_hwrm.h"
21 #include "bnxt_ring.h"
24 #include "bnxt_stats.h"
27 #include "bnxt_vnic.h"
28 #include "hsi_struct_def_dpdk.h"
29 #include "bnxt_nvm_defs.h"
31 #define DRV_MODULE_NAME "bnxt"
32 static const char bnxt_version[] =
33 "Broadcom NetXtreme driver " DRV_MODULE_NAME;
34 int bnxt_logtype_driver;
37 * The set of PCI devices this driver supports
39 static const struct rte_pci_id bnxt_pci_id_map[] = {
40 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
41 BROADCOM_DEV_ID_STRATUS_NIC_VF1) },
42 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
43 BROADCOM_DEV_ID_STRATUS_NIC_VF2) },
44 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
45 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
46 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
47 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57302) },
48 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_PF) },
49 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
50 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
51 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402) },
52 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404) },
53 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_PF) },
54 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
55 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57402_MF) },
56 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_RJ45) },
57 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57404_MF) },
58 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_MF) },
59 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_SFP) },
60 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
61 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
62 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
63 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57314) },
64 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
65 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57311) },
66 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57312) },
67 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
68 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
69 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
70 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
71 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
72 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
73 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
74 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
75 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
76 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
77 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
78 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802) },
79 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58804) },
80 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58808) },
81 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802_VF) },
82 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508) },
83 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504) },
84 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502) },
85 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF1) },
86 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF2) },
87 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF1) },
88 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF1) },
89 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF1) },
90 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF2) },
91 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF2) },
92 { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF2) },
93 { .vendor_id = 0, /* sentinel */ },
96 #define BNXT_ETH_RSS_SUPPORT ( \
98 ETH_RSS_NONFRAG_IPV4_TCP | \
99 ETH_RSS_NONFRAG_IPV4_UDP | \
101 ETH_RSS_NONFRAG_IPV6_TCP | \
102 ETH_RSS_NONFRAG_IPV6_UDP)
104 #define BNXT_DEV_TX_OFFLOAD_SUPPORT (DEV_TX_OFFLOAD_VLAN_INSERT | \
105 DEV_TX_OFFLOAD_IPV4_CKSUM | \
106 DEV_TX_OFFLOAD_TCP_CKSUM | \
107 DEV_TX_OFFLOAD_UDP_CKSUM | \
108 DEV_TX_OFFLOAD_TCP_TSO | \
109 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
110 DEV_TX_OFFLOAD_VXLAN_TNL_TSO | \
111 DEV_TX_OFFLOAD_GRE_TNL_TSO | \
112 DEV_TX_OFFLOAD_IPIP_TNL_TSO | \
113 DEV_TX_OFFLOAD_GENEVE_TNL_TSO | \
114 DEV_TX_OFFLOAD_QINQ_INSERT | \
115 DEV_TX_OFFLOAD_MULTI_SEGS)
117 #define BNXT_DEV_RX_OFFLOAD_SUPPORT (DEV_RX_OFFLOAD_VLAN_FILTER | \
118 DEV_RX_OFFLOAD_VLAN_STRIP | \
119 DEV_RX_OFFLOAD_IPV4_CKSUM | \
120 DEV_RX_OFFLOAD_UDP_CKSUM | \
121 DEV_RX_OFFLOAD_TCP_CKSUM | \
122 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM | \
123 DEV_RX_OFFLOAD_JUMBO_FRAME | \
124 DEV_RX_OFFLOAD_KEEP_CRC | \
125 DEV_RX_OFFLOAD_VLAN_EXTEND | \
126 DEV_RX_OFFLOAD_TCP_LRO | \
127 DEV_RX_OFFLOAD_SCATTER | \
128 DEV_RX_OFFLOAD_RSS_HASH)
130 #define BNXT_DEVARG_TRUFLOW "host-based-truflow"
131 #define BNXT_DEVARG_FLOW_XSTAT "flow-xstat"
132 static const char *const bnxt_dev_args[] = {
134 BNXT_DEVARG_FLOW_XSTAT,
139 * truflow == false to disable the feature
140 * truflow == true to enable the feature
142 #define BNXT_DEVARG_TRUFLOW_INVALID(truflow) ((truflow) > 1)
145 * flow_xstat == false to disable the feature
146 * flow_xstat == true to enable the feature
148 #define BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat) ((flow_xstat) > 1)
150 static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
151 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev);
152 static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
153 static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev);
154 static int bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev);
155 static void bnxt_cancel_fw_health_check(struct bnxt *bp);
156 static int bnxt_restore_vlan_filters(struct bnxt *bp);
157 static void bnxt_dev_recover(void *arg);
158 static void bnxt_free_error_recovery_info(struct bnxt *bp);
160 int is_bnxt_in_error(struct bnxt *bp)
162 if (bp->flags & BNXT_FLAG_FATAL_ERROR)
164 if (bp->flags & BNXT_FLAG_FW_RESET)
170 /***********************/
173 * High level utility functions
176 static uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
178 if (!BNXT_CHIP_THOR(bp))
181 return RTE_ALIGN_MUL_CEIL(bp->rx_nr_rings,
182 BNXT_RSS_ENTRIES_PER_CTX_THOR) /
183 BNXT_RSS_ENTRIES_PER_CTX_THOR;
186 static uint16_t bnxt_rss_hash_tbl_size(const struct bnxt *bp)
188 if (!BNXT_CHIP_THOR(bp))
189 return HW_HASH_INDEX_SIZE;
191 return bnxt_rss_ctxts(bp) * BNXT_RSS_ENTRIES_PER_CTX_THOR;
194 static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
196 bnxt_free_filter_mem(bp);
197 bnxt_free_vnic_attributes(bp);
198 bnxt_free_vnic_mem(bp);
200 /* tx/rx rings are configured as part of *_queue_setup callbacks.
201 * If the number of rings change across fw update,
202 * we don't have much choice except to warn the user.
206 bnxt_free_tx_rings(bp);
207 bnxt_free_rx_rings(bp);
209 bnxt_free_async_cp_ring(bp);
210 bnxt_free_rxtx_nq_ring(bp);
212 rte_free(bp->grp_info);
216 static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
220 rc = bnxt_alloc_ring_grps(bp);
224 rc = bnxt_alloc_async_ring_struct(bp);
228 rc = bnxt_alloc_vnic_mem(bp);
232 rc = bnxt_alloc_vnic_attributes(bp);
236 rc = bnxt_alloc_filter_mem(bp);
240 rc = bnxt_alloc_async_cp_ring(bp);
244 rc = bnxt_alloc_rxtx_nq_ring(bp);
251 bnxt_free_mem(bp, reconfig);
255 static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)
257 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
258 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
259 uint64_t rx_offloads = dev_conf->rxmode.offloads;
260 struct bnxt_rx_queue *rxq;
264 rc = bnxt_vnic_grp_alloc(bp, vnic);
268 PMD_DRV_LOG(DEBUG, "vnic[%d] = %p vnic->fw_grp_ids = %p\n",
269 vnic_id, vnic, vnic->fw_grp_ids);
271 rc = bnxt_hwrm_vnic_alloc(bp, vnic);
275 /* Alloc RSS context only if RSS mode is enabled */
276 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS) {
277 int j, nr_ctxs = bnxt_rss_ctxts(bp);
280 for (j = 0; j < nr_ctxs; j++) {
281 rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, j);
287 "HWRM vnic %d ctx %d alloc failure rc: %x\n",
291 vnic->num_lb_ctxts = nr_ctxs;
295 * Firmware sets pf pair in default vnic cfg. If the VLAN strip
296 * setting is not available at this time, it will not be
297 * configured correctly in the CFA.
299 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
300 vnic->vlan_strip = true;
302 vnic->vlan_strip = false;
304 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
308 rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
312 for (j = 0; j < bp->rx_num_qs_per_vnic; j++) {
313 rxq = bp->eth_dev->data->rx_queues[j];
316 "rxq[%d]->vnic=%p vnic->fw_grp_ids=%p\n",
317 j, rxq->vnic, rxq->vnic->fw_grp_ids);
319 if (BNXT_HAS_RING_GRPS(bp) && rxq->rx_deferred_start)
320 rxq->vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
322 vnic->rx_queue_cnt++;
325 PMD_DRV_LOG(DEBUG, "vnic->rx_queue_cnt = %d\n", vnic->rx_queue_cnt);
327 rc = bnxt_vnic_rss_configure(bp, vnic);
331 bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
333 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
334 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 1);
336 bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 0);
340 PMD_DRV_LOG(ERR, "HWRM vnic %d cfg failure rc: %x\n",
345 static int bnxt_register_fc_ctx_mem(struct bnxt *bp)
349 rc = bnxt_hwrm_ctx_rgtr(bp, bp->rx_fc_in_tbl.dma,
350 &bp->rx_fc_in_tbl.ctx_id);
355 "rx_fc_in_tbl.va = %p rx_fc_in_tbl.dma = %p"
356 " rx_fc_in_tbl.ctx_id = %d\n",
358 (void *)((uintptr_t)bp->rx_fc_in_tbl.dma),
359 bp->rx_fc_in_tbl.ctx_id);
361 rc = bnxt_hwrm_ctx_rgtr(bp, bp->rx_fc_out_tbl.dma,
362 &bp->rx_fc_out_tbl.ctx_id);
367 "rx_fc_out_tbl.va = %p rx_fc_out_tbl.dma = %p"
368 " rx_fc_out_tbl.ctx_id = %d\n",
369 bp->rx_fc_out_tbl.va,
370 (void *)((uintptr_t)bp->rx_fc_out_tbl.dma),
371 bp->rx_fc_out_tbl.ctx_id);
373 rc = bnxt_hwrm_ctx_rgtr(bp, bp->tx_fc_in_tbl.dma,
374 &bp->tx_fc_in_tbl.ctx_id);
379 "tx_fc_in_tbl.va = %p tx_fc_in_tbl.dma = %p"
380 " tx_fc_in_tbl.ctx_id = %d\n",
382 (void *)((uintptr_t)bp->tx_fc_in_tbl.dma),
383 bp->tx_fc_in_tbl.ctx_id);
385 rc = bnxt_hwrm_ctx_rgtr(bp, bp->tx_fc_out_tbl.dma,
386 &bp->tx_fc_out_tbl.ctx_id);
391 "tx_fc_out_tbl.va = %p tx_fc_out_tbl.dma = %p"
392 " tx_fc_out_tbl.ctx_id = %d\n",
393 bp->tx_fc_out_tbl.va,
394 (void *)((uintptr_t)bp->tx_fc_out_tbl.dma),
395 bp->tx_fc_out_tbl.ctx_id);
397 memset(bp->rx_fc_out_tbl.va, 0, bp->rx_fc_out_tbl.size);
398 rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
399 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
400 bp->rx_fc_out_tbl.ctx_id,
406 memset(bp->tx_fc_out_tbl.va, 0, bp->tx_fc_out_tbl.size);
407 rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
408 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
409 bp->tx_fc_out_tbl.ctx_id,
416 static int bnxt_alloc_ctx_mem_buf(char *type, size_t size,
417 struct bnxt_ctx_mem_buf_info *ctx)
422 ctx->va = rte_zmalloc(type, size, 0);
425 rte_mem_lock_page(ctx->va);
427 ctx->dma = rte_mem_virt2iova(ctx->va);
428 if (ctx->dma == RTE_BAD_IOVA)
434 static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
436 struct rte_pci_device *pdev = bp->pdev;
437 char type[RTE_MEMZONE_NAMESIZE];
443 sprintf(type, "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
444 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
445 /* 4 bytes for each counter-id */
446 rc = bnxt_alloc_ctx_mem_buf(type, max_fc * 4, &bp->rx_fc_in_tbl);
450 sprintf(type, "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
451 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
452 /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
453 rc = bnxt_alloc_ctx_mem_buf(type, max_fc * 16, &bp->rx_fc_out_tbl);
457 sprintf(type, "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
458 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
459 /* 4 bytes for each counter-id */
460 rc = bnxt_alloc_ctx_mem_buf(type, max_fc * 4, &bp->tx_fc_in_tbl);
464 sprintf(type, "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
465 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
466 /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
467 rc = bnxt_alloc_ctx_mem_buf(type, max_fc * 16, &bp->tx_fc_out_tbl);
471 rc = bnxt_register_fc_ctx_mem(bp);
476 static int bnxt_init_ctx_mem(struct bnxt *bp)
480 if (!(bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS) ||
481 !(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)))
484 rc = bnxt_hwrm_cfa_counter_qcaps(bp, &bp->max_fc);
488 rc = bnxt_init_fc_ctx_mem(bp);
493 static int bnxt_init_chip(struct bnxt *bp)
495 struct rte_eth_link new;
496 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(bp->eth_dev);
497 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
498 uint32_t intr_vector = 0;
499 uint32_t queue_id, base = BNXT_MISC_VEC_ID;
500 uint32_t vec = BNXT_MISC_VEC_ID;
504 if (bp->eth_dev->data->mtu > RTE_ETHER_MTU) {
505 bp->eth_dev->data->dev_conf.rxmode.offloads |=
506 DEV_RX_OFFLOAD_JUMBO_FRAME;
507 bp->flags |= BNXT_FLAG_JUMBO;
509 bp->eth_dev->data->dev_conf.rxmode.offloads &=
510 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
511 bp->flags &= ~BNXT_FLAG_JUMBO;
514 /* THOR does not support ring groups.
515 * But we will use the array to save RSS context IDs.
517 if (BNXT_CHIP_THOR(bp))
518 bp->max_ring_grps = BNXT_MAX_RSS_CTXTS_THOR;
520 rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
522 PMD_DRV_LOG(ERR, "HWRM stat ctx alloc failure rc: %x\n", rc);
526 rc = bnxt_alloc_hwrm_rings(bp);
528 PMD_DRV_LOG(ERR, "HWRM ring alloc failure rc: %x\n", rc);
532 rc = bnxt_alloc_all_hwrm_ring_grps(bp);
534 PMD_DRV_LOG(ERR, "HWRM ring grp alloc failure: %x\n", rc);
538 if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
541 for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
542 if (bp->rx_cos_queue[i].id != 0xff) {
543 struct bnxt_vnic_info *vnic = &bp->vnic_info[j++];
547 "Num pools more than FW profile\n");
551 vnic->cos_queue_id = bp->rx_cos_queue[i].id;
557 rc = bnxt_mq_rx_configure(bp);
559 PMD_DRV_LOG(ERR, "MQ mode configure failure rc: %x\n", rc);
563 /* VNIC configuration */
564 for (i = 0; i < bp->nr_vnics; i++) {
565 rc = bnxt_setup_one_vnic(bp, i);
570 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
573 "HWRM cfa l2 rx mask failure rc: %x\n", rc);
577 /* check and configure queue intr-vector mapping */
578 if ((rte_intr_cap_multiple(intr_handle) ||
579 !RTE_ETH_DEV_SRIOV(bp->eth_dev).active) &&
580 bp->eth_dev->data->dev_conf.intr_conf.rxq != 0) {
581 intr_vector = bp->eth_dev->data->nb_rx_queues;
582 PMD_DRV_LOG(DEBUG, "intr_vector = %d\n", intr_vector);
583 if (intr_vector > bp->rx_cp_nr_rings) {
584 PMD_DRV_LOG(ERR, "At most %d intr queues supported",
588 rc = rte_intr_efd_enable(intr_handle, intr_vector);
593 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
594 intr_handle->intr_vec =
595 rte_zmalloc("intr_vec",
596 bp->eth_dev->data->nb_rx_queues *
598 if (intr_handle->intr_vec == NULL) {
599 PMD_DRV_LOG(ERR, "Failed to allocate %d rx_queues"
600 " intr_vec", bp->eth_dev->data->nb_rx_queues);
604 PMD_DRV_LOG(DEBUG, "intr_handle->intr_vec = %p "
605 "intr_handle->nb_efd = %d intr_handle->max_intr = %d\n",
606 intr_handle->intr_vec, intr_handle->nb_efd,
607 intr_handle->max_intr);
608 for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
610 intr_handle->intr_vec[queue_id] =
611 vec + BNXT_RX_VEC_START;
612 if (vec < base + intr_handle->nb_efd - 1)
617 /* enable uio/vfio intr/eventfd mapping */
618 rc = rte_intr_enable(intr_handle);
619 #ifndef RTE_EXEC_ENV_FREEBSD
620 /* In FreeBSD OS, nic_uio driver does not support interrupts */
625 rc = bnxt_get_hwrm_link_config(bp, &new);
627 PMD_DRV_LOG(ERR, "HWRM Get link config failure rc: %x\n", rc);
631 if (!bp->link_info.link_up) {
632 rc = bnxt_set_hwrm_link_config(bp, true);
635 "HWRM link config failure rc: %x\n", rc);
639 bnxt_print_link_info(bp->eth_dev);
641 bp->mark_table = rte_zmalloc("bnxt_mark_table", BNXT_MARK_TABLE_SZ, 0);
643 PMD_DRV_LOG(ERR, "Allocation of mark table failed\n");
648 rte_free(intr_handle->intr_vec);
650 rte_intr_efd_disable(intr_handle);
652 /* Some of the error status returned by FW may not be from errno.h */
659 static int bnxt_shutdown_nic(struct bnxt *bp)
661 bnxt_free_all_hwrm_resources(bp);
662 bnxt_free_all_filters(bp);
663 bnxt_free_all_vnics(bp);
668 * Device configuration and status function
671 static uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
673 uint32_t link_speed = bp->link_info.support_speeds;
674 uint32_t speed_capa = 0;
676 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB)
677 speed_capa |= ETH_LINK_SPEED_100M;
678 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MBHD)
679 speed_capa |= ETH_LINK_SPEED_100M_HD;
680 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
681 speed_capa |= ETH_LINK_SPEED_1G;
682 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
683 speed_capa |= ETH_LINK_SPEED_2_5G;
684 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
685 speed_capa |= ETH_LINK_SPEED_10G;
686 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
687 speed_capa |= ETH_LINK_SPEED_20G;
688 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
689 speed_capa |= ETH_LINK_SPEED_25G;
690 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
691 speed_capa |= ETH_LINK_SPEED_40G;
692 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
693 speed_capa |= ETH_LINK_SPEED_50G;
694 if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
695 speed_capa |= ETH_LINK_SPEED_100G;
697 if (bp->link_info.auto_mode == HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
698 speed_capa |= ETH_LINK_SPEED_FIXED;
700 speed_capa |= ETH_LINK_SPEED_AUTONEG;
705 static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
706 struct rte_eth_dev_info *dev_info)
708 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
709 struct bnxt *bp = eth_dev->data->dev_private;
710 uint16_t max_vnics, i, j, vpool, vrxq;
711 unsigned int max_rx_rings;
714 rc = is_bnxt_in_error(bp);
719 dev_info->max_mac_addrs = bp->max_l2_ctx;
720 dev_info->max_hash_mac_addrs = 0;
722 /* PF/VF specifics */
724 dev_info->max_vfs = pdev->max_vfs;
726 max_rx_rings = BNXT_MAX_RINGS(bp);
727 /* For the sake of symmetry, max_rx_queues = max_tx_queues */
728 dev_info->max_rx_queues = max_rx_rings;
729 dev_info->max_tx_queues = max_rx_rings;
730 dev_info->reta_size = bnxt_rss_hash_tbl_size(bp);
731 dev_info->hash_key_size = 40;
732 max_vnics = bp->max_vnics;
735 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
736 dev_info->max_mtu = BNXT_MAX_MTU;
738 /* Fast path specifics */
739 dev_info->min_rx_bufsize = 1;
740 dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
742 dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
743 if (bp->flags & BNXT_FLAG_PTP_SUPPORTED)
744 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TIMESTAMP;
745 dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
746 dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
748 dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
751 dev_info->default_rxconf = (struct rte_eth_rxconf) {
757 .rx_free_thresh = 32,
758 /* If no descriptors available, pkts are dropped by default */
762 dev_info->default_txconf = (struct rte_eth_txconf) {
768 .tx_free_thresh = 32,
771 eth_dev->data->dev_conf.intr_conf.lsc = 1;
773 eth_dev->data->dev_conf.intr_conf.rxq = 1;
774 dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
775 dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
776 dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
777 dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
782 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
783 * need further investigation.
787 vpool = 64; /* ETH_64_POOLS */
788 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
789 for (i = 0; i < 4; vpool >>= 1, i++) {
790 if (max_vnics > vpool) {
791 for (j = 0; j < 5; vrxq >>= 1, j++) {
792 if (dev_info->max_rx_queues > vrxq) {
798 /* Not enough resources to support VMDq */
802 /* Not enough resources to support VMDq */
806 dev_info->max_vmdq_pools = vpool;
807 dev_info->vmdq_queue_num = vrxq;
809 dev_info->vmdq_pool_base = 0;
810 dev_info->vmdq_queue_base = 0;
815 /* Configure the device based on the configuration provided */
816 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
818 struct bnxt *bp = eth_dev->data->dev_private;
819 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
822 bp->rx_queues = (void *)eth_dev->data->rx_queues;
823 bp->tx_queues = (void *)eth_dev->data->tx_queues;
824 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
825 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
827 rc = is_bnxt_in_error(bp);
831 if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
832 rc = bnxt_hwrm_check_vf_rings(bp);
834 PMD_DRV_LOG(ERR, "HWRM insufficient resources\n");
838 /* If a resource has already been allocated - in this case
839 * it is the async completion ring, free it. Reallocate it after
840 * resource reservation. This will ensure the resource counts
841 * are calculated correctly.
844 pthread_mutex_lock(&bp->def_cp_lock);
846 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
847 bnxt_disable_int(bp);
848 bnxt_free_cp_ring(bp, bp->async_cp_ring);
851 rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
853 PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc);
854 pthread_mutex_unlock(&bp->def_cp_lock);
858 if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
859 rc = bnxt_alloc_async_cp_ring(bp);
861 pthread_mutex_unlock(&bp->def_cp_lock);
867 pthread_mutex_unlock(&bp->def_cp_lock);
869 /* legacy driver needs to get updated values */
870 rc = bnxt_hwrm_func_qcaps(bp);
872 PMD_DRV_LOG(ERR, "hwrm func qcaps fail:%d\n", rc);
877 /* Inherit new configurations */
878 if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
879 eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
880 eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
881 + BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
882 eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
886 if (BNXT_HAS_RING_GRPS(bp) &&
887 (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
890 if (!(eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS) &&
891 bp->max_vnics < eth_dev->data->nb_rx_queues)
894 bp->rx_cp_nr_rings = bp->rx_nr_rings;
895 bp->tx_cp_nr_rings = bp->tx_nr_rings;
897 if (eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
898 rx_offloads |= DEV_RX_OFFLOAD_RSS_HASH;
899 eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
901 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
903 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
904 RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE *
906 bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
912 "Insufficient resources to support requested config\n");
914 "Num Queues Requested: Tx %d, Rx %d\n",
915 eth_dev->data->nb_tx_queues,
916 eth_dev->data->nb_rx_queues);
918 "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d\n",
919 bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
920 bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
924 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
926 struct rte_eth_link *link = ð_dev->data->dev_link;
928 if (link->link_status)
929 PMD_DRV_LOG(INFO, "Port %d Link Up - speed %u Mbps - %s\n",
930 eth_dev->data->port_id,
931 (uint32_t)link->link_speed,
932 (link->link_duplex == ETH_LINK_FULL_DUPLEX) ?
933 ("full-duplex") : ("half-duplex\n"));
935 PMD_DRV_LOG(INFO, "Port %d Link Down\n",
936 eth_dev->data->port_id);
940 * Determine whether the current configuration requires support for scattered
941 * receive; return 1 if scattered receive is required and 0 if not.
943 static int bnxt_scattered_rx(struct rte_eth_dev *eth_dev)
948 if (eth_dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER)
951 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
952 struct bnxt_rx_queue *rxq = eth_dev->data->rx_queues[i];
954 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
955 RTE_PKTMBUF_HEADROOM);
956 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len > buf_size)
962 static eth_rx_burst_t
963 bnxt_receive_function(struct rte_eth_dev *eth_dev)
965 struct bnxt *bp = eth_dev->data->dev_private;
968 #ifndef RTE_LIBRTE_IEEE1588
970 * Vector mode receive can be enabled only if scatter rx is not
971 * in use and rx offloads are limited to VLAN stripping and
974 if (!eth_dev->data->scattered_rx &&
975 !(eth_dev->data->dev_conf.rxmode.offloads &
976 ~(DEV_RX_OFFLOAD_VLAN_STRIP |
977 DEV_RX_OFFLOAD_KEEP_CRC |
978 DEV_RX_OFFLOAD_JUMBO_FRAME |
979 DEV_RX_OFFLOAD_IPV4_CKSUM |
980 DEV_RX_OFFLOAD_UDP_CKSUM |
981 DEV_RX_OFFLOAD_TCP_CKSUM |
982 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
983 DEV_RX_OFFLOAD_RSS_HASH |
984 DEV_RX_OFFLOAD_VLAN_FILTER)) &&
986 PMD_DRV_LOG(INFO, "Using vector mode receive for port %d\n",
987 eth_dev->data->port_id);
988 bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
989 return bnxt_recv_pkts_vec;
991 PMD_DRV_LOG(INFO, "Vector mode receive disabled for port %d\n",
992 eth_dev->data->port_id);
994 "Port %d scatter: %d rx offload: %" PRIX64 "\n",
995 eth_dev->data->port_id,
996 eth_dev->data->scattered_rx,
997 eth_dev->data->dev_conf.rxmode.offloads);
1000 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1001 return bnxt_recv_pkts;
1004 static eth_tx_burst_t
1005 bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
1008 #ifndef RTE_LIBRTE_IEEE1588
1010 * Vector mode transmit can be enabled only if not using scatter rx
1013 if (!eth_dev->data->scattered_rx &&
1014 !eth_dev->data->dev_conf.txmode.offloads) {
1015 PMD_DRV_LOG(INFO, "Using vector mode transmit for port %d\n",
1016 eth_dev->data->port_id);
1017 return bnxt_xmit_pkts_vec;
1019 PMD_DRV_LOG(INFO, "Vector mode transmit disabled for port %d\n",
1020 eth_dev->data->port_id);
1022 "Port %d scatter: %d tx offload: %" PRIX64 "\n",
1023 eth_dev->data->port_id,
1024 eth_dev->data->scattered_rx,
1025 eth_dev->data->dev_conf.txmode.offloads);
1028 return bnxt_xmit_pkts;
1031 static int bnxt_handle_if_change_status(struct bnxt *bp)
1035 /* Since fw has undergone a reset and lost all contexts,
1036 * set fatal flag to not issue hwrm during cleanup
1038 bp->flags |= BNXT_FLAG_FATAL_ERROR;
1039 bnxt_uninit_resources(bp, true);
1041 /* clear fatal flag so that re-init happens */
1042 bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
1043 rc = bnxt_init_resources(bp, true);
1045 bp->flags &= ~BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
1050 static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
1052 struct bnxt *bp = eth_dev->data->dev_private;
1053 uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
1055 int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
1057 if (!eth_dev->data->nb_tx_queues || !eth_dev->data->nb_rx_queues) {
1058 PMD_DRV_LOG(ERR, "Queues are not configured yet!\n");
1062 if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1064 "RxQ cnt %d > CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
1065 bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1069 rc = bnxt_hwrm_if_change(bp, true);
1070 if (rc == 0 || rc != -EAGAIN)
1073 rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
1074 } while (retry_cnt--);
1079 if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
1080 rc = bnxt_handle_if_change_status(bp);
1085 bnxt_enable_int(bp);
1087 rc = bnxt_init_chip(bp);
1091 eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
1092 eth_dev->data->dev_started = 1;
1094 bnxt_link_update(eth_dev, 1, ETH_LINK_UP);
1096 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1097 vlan_mask |= ETH_VLAN_FILTER_MASK;
1098 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1099 vlan_mask |= ETH_VLAN_STRIP_MASK;
1100 rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
1104 eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
1105 eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
1107 pthread_mutex_lock(&bp->def_cp_lock);
1108 bnxt_schedule_fw_health_check(bp);
1109 pthread_mutex_unlock(&bp->def_cp_lock);
1117 bnxt_shutdown_nic(bp);
1118 bnxt_free_tx_mbufs(bp);
1119 bnxt_free_rx_mbufs(bp);
1120 bnxt_hwrm_if_change(bp, false);
1121 eth_dev->data->dev_started = 0;
1125 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
1127 struct bnxt *bp = eth_dev->data->dev_private;
1130 if (!bp->link_info.link_up)
1131 rc = bnxt_set_hwrm_link_config(bp, true);
1133 eth_dev->data->dev_link.link_status = 1;
1135 bnxt_print_link_info(eth_dev);
1139 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
1141 struct bnxt *bp = eth_dev->data->dev_private;
1143 eth_dev->data->dev_link.link_status = 0;
1144 bnxt_set_hwrm_link_config(bp, false);
1145 bp->link_info.link_up = 0;
1150 /* Unload the driver, release resources */
1151 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
1153 struct bnxt *bp = eth_dev->data->dev_private;
1154 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1155 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1158 bnxt_ulp_deinit(bp);
1160 eth_dev->data->dev_started = 0;
1161 /* Prevent crashes when queues are still in use */
1162 eth_dev->rx_pkt_burst = &bnxt_dummy_recv_pkts;
1163 eth_dev->tx_pkt_burst = &bnxt_dummy_xmit_pkts;
1165 bnxt_disable_int(bp);
1167 /* disable uio/vfio intr/eventfd mapping */
1168 rte_intr_disable(intr_handle);
1170 bnxt_cancel_fw_health_check(bp);
1172 bnxt_dev_set_link_down_op(eth_dev);
1174 /* Wait for link to be reset and the async notification to process.
1175 * During reset recovery, there is no need to wait and
1176 * VF/NPAR functions do not have privilege to change PHY config.
1178 if (!is_bnxt_in_error(bp) && BNXT_SINGLE_PF(bp))
1179 bnxt_link_update(eth_dev, 1, ETH_LINK_DOWN);
1181 /* Clean queue intr-vector mapping */
1182 rte_intr_efd_disable(intr_handle);
1183 if (intr_handle->intr_vec != NULL) {
1184 rte_free(intr_handle->intr_vec);
1185 intr_handle->intr_vec = NULL;
1188 bnxt_hwrm_port_clr_stats(bp);
1189 bnxt_free_tx_mbufs(bp);
1190 bnxt_free_rx_mbufs(bp);
1191 /* Process any remaining notifications in default completion queue */
1192 bnxt_int_handler(eth_dev);
1193 bnxt_shutdown_nic(bp);
1194 bnxt_hwrm_if_change(bp, false);
1196 rte_free(bp->mark_table);
1197 bp->mark_table = NULL;
1199 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1200 bp->rx_cosq_cnt = 0;
1203 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
1205 struct bnxt *bp = eth_dev->data->dev_private;
1207 /* cancel the recovery handler before remove dev */
1208 rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
1209 rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
1210 bnxt_cancel_fc_thread(bp);
1212 if (eth_dev->data->dev_started)
1213 bnxt_dev_stop_op(eth_dev);
1215 bnxt_uninit_resources(bp, false);
1217 eth_dev->dev_ops = NULL;
1218 eth_dev->rx_pkt_burst = NULL;
1219 eth_dev->tx_pkt_burst = NULL;
1221 rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
1222 bp->tx_mem_zone = NULL;
1223 rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
1224 bp->rx_mem_zone = NULL;
1226 rte_free(bp->pf.vf_info);
1227 bp->pf.vf_info = NULL;
1229 rte_free(bp->grp_info);
1230 bp->grp_info = NULL;
1233 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
1236 struct bnxt *bp = eth_dev->data->dev_private;
1237 uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
1238 struct bnxt_vnic_info *vnic;
1239 struct bnxt_filter_info *filter, *temp_filter;
1242 if (is_bnxt_in_error(bp))
1246 * Loop through all VNICs from the specified filter flow pools to
1247 * remove the corresponding MAC addr filter
1249 for (i = 0; i < bp->nr_vnics; i++) {
1250 if (!(pool_mask & (1ULL << i)))
1253 vnic = &bp->vnic_info[i];
1254 filter = STAILQ_FIRST(&vnic->filter);
1256 temp_filter = STAILQ_NEXT(filter, next);
1257 if (filter->mac_index == index) {
1258 STAILQ_REMOVE(&vnic->filter, filter,
1259 bnxt_filter_info, next);
1260 bnxt_hwrm_clear_l2_filter(bp, filter);
1261 bnxt_free_filter(bp, filter);
1263 filter = temp_filter;
1268 static int bnxt_add_mac_filter(struct bnxt *bp, struct bnxt_vnic_info *vnic,
1269 struct rte_ether_addr *mac_addr, uint32_t index,
1272 struct bnxt_filter_info *filter;
1275 /* Attach requested MAC address to the new l2_filter */
1276 STAILQ_FOREACH(filter, &vnic->filter, next) {
1277 if (filter->mac_index == index) {
1279 "MAC addr already existed for pool %d\n",
1285 filter = bnxt_alloc_filter(bp);
1287 PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
1291 /* bnxt_alloc_filter copies default MAC to filter->l2_addr. So,
1292 * if the MAC that's been programmed now is a different one, then,
1293 * copy that addr to filter->l2_addr
1296 memcpy(filter->l2_addr, mac_addr, RTE_ETHER_ADDR_LEN);
1297 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
1299 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
1301 filter->mac_index = index;
1302 if (filter->mac_index == 0)
1303 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
1305 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
1307 bnxt_free_filter(bp, filter);
1313 static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
1314 struct rte_ether_addr *mac_addr,
1315 uint32_t index, uint32_t pool)
1317 struct bnxt *bp = eth_dev->data->dev_private;
1318 struct bnxt_vnic_info *vnic = &bp->vnic_info[pool];
1321 rc = is_bnxt_in_error(bp);
1325 if (BNXT_VF(bp) & !BNXT_VF_IS_TRUSTED(bp)) {
1326 PMD_DRV_LOG(ERR, "Cannot add MAC address to a VF interface\n");
1331 PMD_DRV_LOG(ERR, "VNIC not found for pool %d!\n", pool);
1335 /* Filter settings will get applied when port is started */
1336 if (!eth_dev->data->dev_started)
1339 rc = bnxt_add_mac_filter(bp, vnic, mac_addr, index, pool);
1344 int bnxt_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete,
1345 bool exp_link_status)
1348 struct bnxt *bp = eth_dev->data->dev_private;
1349 struct rte_eth_link new;
1350 int cnt = exp_link_status ? BNXT_LINK_UP_WAIT_CNT :
1351 BNXT_LINK_DOWN_WAIT_CNT;
1353 rc = is_bnxt_in_error(bp);
1357 memset(&new, 0, sizeof(new));
1359 /* Retrieve link info from hardware */
1360 rc = bnxt_get_hwrm_link_config(bp, &new);
1362 new.link_speed = ETH_LINK_SPEED_100M;
1363 new.link_duplex = ETH_LINK_FULL_DUPLEX;
1365 "Failed to retrieve link rc = 0x%x!\n", rc);
1369 if (!wait_to_complete || new.link_status == exp_link_status)
1372 rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
1376 /* Timed out or success */
1377 if (new.link_status != eth_dev->data->dev_link.link_status ||
1378 new.link_speed != eth_dev->data->dev_link.link_speed) {
1379 rte_eth_linkstatus_set(eth_dev, &new);
1381 _rte_eth_dev_callback_process(eth_dev,
1382 RTE_ETH_EVENT_INTR_LSC,
1385 bnxt_print_link_info(eth_dev);
1391 static int bnxt_link_update_op(struct rte_eth_dev *eth_dev,
1392 int wait_to_complete)
1394 return bnxt_link_update(eth_dev, wait_to_complete, ETH_LINK_UP);
1397 static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
1399 struct bnxt *bp = eth_dev->data->dev_private;
1400 struct bnxt_vnic_info *vnic;
1404 rc = is_bnxt_in_error(bp);
1408 /* Filter settings will get applied when port is started */
1409 if (!eth_dev->data->dev_started)
1412 if (bp->vnic_info == NULL)
1415 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1417 old_flags = vnic->flags;
1418 vnic->flags |= BNXT_VNIC_INFO_PROMISC;
1419 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1421 vnic->flags = old_flags;
1426 static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
1428 struct bnxt *bp = eth_dev->data->dev_private;
1429 struct bnxt_vnic_info *vnic;
1433 rc = is_bnxt_in_error(bp);
1437 /* Filter settings will get applied when port is started */
1438 if (!eth_dev->data->dev_started)
1441 if (bp->vnic_info == NULL)
1444 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1446 old_flags = vnic->flags;
1447 vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
1448 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1450 vnic->flags = old_flags;
1455 static int bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
1457 struct bnxt *bp = eth_dev->data->dev_private;
1458 struct bnxt_vnic_info *vnic;
1462 rc = is_bnxt_in_error(bp);
1466 /* Filter settings will get applied when port is started */
1467 if (!eth_dev->data->dev_started)
1470 if (bp->vnic_info == NULL)
1473 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1475 old_flags = vnic->flags;
1476 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
1477 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1479 vnic->flags = old_flags;
1484 static int bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
1486 struct bnxt *bp = eth_dev->data->dev_private;
1487 struct bnxt_vnic_info *vnic;
1491 rc = is_bnxt_in_error(bp);
1495 /* Filter settings will get applied when port is started */
1496 if (!eth_dev->data->dev_started)
1499 if (bp->vnic_info == NULL)
1502 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1504 old_flags = vnic->flags;
1505 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
1506 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
1508 vnic->flags = old_flags;
1513 /* Return bnxt_rx_queue pointer corresponding to a given rxq. */
1514 static struct bnxt_rx_queue *bnxt_qid_to_rxq(struct bnxt *bp, uint16_t qid)
1516 if (qid >= bp->rx_nr_rings)
1519 return bp->eth_dev->data->rx_queues[qid];
1522 /* Return rxq corresponding to a given rss table ring/group ID. */
1523 static uint16_t bnxt_rss_to_qid(struct bnxt *bp, uint16_t fwr)
1525 struct bnxt_rx_queue *rxq;
1528 if (!BNXT_HAS_RING_GRPS(bp)) {
1529 for (i = 0; i < bp->rx_nr_rings; i++) {
1530 rxq = bp->eth_dev->data->rx_queues[i];
1531 if (rxq->rx_ring->rx_ring_struct->fw_ring_id == fwr)
1535 for (i = 0; i < bp->rx_nr_rings; i++) {
1536 if (bp->grp_info[i].fw_grp_id == fwr)
1541 return INVALID_HW_RING_ID;
1544 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
1545 struct rte_eth_rss_reta_entry64 *reta_conf,
1548 struct bnxt *bp = eth_dev->data->dev_private;
1549 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1550 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1551 uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
1555 rc = is_bnxt_in_error(bp);
1559 if (!vnic->rss_table)
1562 if (!(dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG))
1565 if (reta_size != tbl_size) {
1566 PMD_DRV_LOG(ERR, "The configured hash table lookup size "
1567 "(%d) must equal the size supported by the hardware "
1568 "(%d)\n", reta_size, tbl_size);
1572 for (i = 0; i < reta_size; i++) {
1573 struct bnxt_rx_queue *rxq;
1575 idx = i / RTE_RETA_GROUP_SIZE;
1576 sft = i % RTE_RETA_GROUP_SIZE;
1578 if (!(reta_conf[idx].mask & (1ULL << sft)))
1581 rxq = bnxt_qid_to_rxq(bp, reta_conf[idx].reta[sft]);
1583 PMD_DRV_LOG(ERR, "Invalid ring in reta_conf.\n");
1587 if (BNXT_CHIP_THOR(bp)) {
1588 vnic->rss_table[i * 2] =
1589 rxq->rx_ring->rx_ring_struct->fw_ring_id;
1590 vnic->rss_table[i * 2 + 1] =
1591 rxq->cp_ring->cp_ring_struct->fw_ring_id;
1593 vnic->rss_table[i] =
1594 vnic->fw_grp_ids[reta_conf[idx].reta[sft]];
1598 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
1602 static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
1603 struct rte_eth_rss_reta_entry64 *reta_conf,
1606 struct bnxt *bp = eth_dev->data->dev_private;
1607 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1608 uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
1609 uint16_t idx, sft, i;
1612 rc = is_bnxt_in_error(bp);
1616 /* Retrieve from the default VNIC */
1619 if (!vnic->rss_table)
1622 if (reta_size != tbl_size) {
1623 PMD_DRV_LOG(ERR, "The configured hash table lookup size "
1624 "(%d) must equal the size supported by the hardware "
1625 "(%d)\n", reta_size, tbl_size);
1629 for (idx = 0, i = 0; i < reta_size; i++) {
1630 idx = i / RTE_RETA_GROUP_SIZE;
1631 sft = i % RTE_RETA_GROUP_SIZE;
1633 if (reta_conf[idx].mask & (1ULL << sft)) {
1636 if (BNXT_CHIP_THOR(bp))
1637 qid = bnxt_rss_to_qid(bp,
1638 vnic->rss_table[i * 2]);
1640 qid = bnxt_rss_to_qid(bp, vnic->rss_table[i]);
1642 if (qid == INVALID_HW_RING_ID) {
1643 PMD_DRV_LOG(ERR, "Inv. entry in rss table.\n");
1646 reta_conf[idx].reta[sft] = qid;
1653 static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
1654 struct rte_eth_rss_conf *rss_conf)
1656 struct bnxt *bp = eth_dev->data->dev_private;
1657 struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
1658 struct bnxt_vnic_info *vnic;
1661 rc = is_bnxt_in_error(bp);
1666 * If RSS enablement were different than dev_configure,
1667 * then return -EINVAL
1669 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
1670 if (!rss_conf->rss_hf)
1671 PMD_DRV_LOG(ERR, "Hash type NONE\n");
1673 if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
1677 bp->flags |= BNXT_FLAG_UPDATE_HASH;
1678 memcpy(&bp->rss_conf, rss_conf, sizeof(*rss_conf));
1680 /* Update the default RSS VNIC(s) */
1681 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1682 vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
1685 * If hashkey is not specified, use the previously configured
1688 if (!rss_conf->rss_key)
1691 if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE) {
1693 "Invalid hashkey length, should be 16 bytes\n");
1696 memcpy(vnic->rss_hash_key, rss_conf->rss_key, rss_conf->rss_key_len);
1699 bnxt_hwrm_vnic_rss_cfg(bp, vnic);
1703 static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
1704 struct rte_eth_rss_conf *rss_conf)
1706 struct bnxt *bp = eth_dev->data->dev_private;
1707 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
1709 uint32_t hash_types;
1711 rc = is_bnxt_in_error(bp);
1715 /* RSS configuration is the same for all VNICs */
1716 if (vnic && vnic->rss_hash_key) {
1717 if (rss_conf->rss_key) {
1718 len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
1719 rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
1720 memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
1723 hash_types = vnic->hash_type;
1724 rss_conf->rss_hf = 0;
1725 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4) {
1726 rss_conf->rss_hf |= ETH_RSS_IPV4;
1727 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
1729 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4) {
1730 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
1732 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
1734 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4) {
1735 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
1737 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
1739 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6) {
1740 rss_conf->rss_hf |= ETH_RSS_IPV6;
1741 hash_types &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
1743 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6) {
1744 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
1746 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
1748 if (hash_types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6) {
1749 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
1751 ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
1755 "Unknown RSS config from firmware (%08x), RSS disabled",
1760 rss_conf->rss_hf = 0;
1765 static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
1766 struct rte_eth_fc_conf *fc_conf)
1768 struct bnxt *bp = dev->data->dev_private;
1769 struct rte_eth_link link_info;
1772 rc = is_bnxt_in_error(bp);
1776 rc = bnxt_get_hwrm_link_config(bp, &link_info);
1780 memset(fc_conf, 0, sizeof(*fc_conf));
1781 if (bp->link_info.auto_pause)
1782 fc_conf->autoneg = 1;
1783 switch (bp->link_info.pause) {
1785 fc_conf->mode = RTE_FC_NONE;
1787 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
1788 fc_conf->mode = RTE_FC_TX_PAUSE;
1790 case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
1791 fc_conf->mode = RTE_FC_RX_PAUSE;
1793 case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
1794 HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
1795 fc_conf->mode = RTE_FC_FULL;
1801 static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
1802 struct rte_eth_fc_conf *fc_conf)
1804 struct bnxt *bp = dev->data->dev_private;
1807 rc = is_bnxt_in_error(bp);
1811 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp)) {
1812 PMD_DRV_LOG(ERR, "Flow Control Settings cannot be modified\n");
1816 switch (fc_conf->mode) {
1818 bp->link_info.auto_pause = 0;
1819 bp->link_info.force_pause = 0;
1821 case RTE_FC_RX_PAUSE:
1822 if (fc_conf->autoneg) {
1823 bp->link_info.auto_pause =
1824 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
1825 bp->link_info.force_pause = 0;
1827 bp->link_info.auto_pause = 0;
1828 bp->link_info.force_pause =
1829 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
1832 case RTE_FC_TX_PAUSE:
1833 if (fc_conf->autoneg) {
1834 bp->link_info.auto_pause =
1835 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
1836 bp->link_info.force_pause = 0;
1838 bp->link_info.auto_pause = 0;
1839 bp->link_info.force_pause =
1840 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
1844 if (fc_conf->autoneg) {
1845 bp->link_info.auto_pause =
1846 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
1847 HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
1848 bp->link_info.force_pause = 0;
1850 bp->link_info.auto_pause = 0;
1851 bp->link_info.force_pause =
1852 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
1853 HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
1857 return bnxt_set_hwrm_link_config(bp, true);
1860 /* Add UDP tunneling port */
1862 bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
1863 struct rte_eth_udp_tunnel *udp_tunnel)
1865 struct bnxt *bp = eth_dev->data->dev_private;
1866 uint16_t tunnel_type = 0;
1869 rc = is_bnxt_in_error(bp);
1873 switch (udp_tunnel->prot_type) {
1874 case RTE_TUNNEL_TYPE_VXLAN:
1875 if (bp->vxlan_port_cnt) {
1876 PMD_DRV_LOG(ERR, "Tunnel Port %d already programmed\n",
1877 udp_tunnel->udp_port);
1878 if (bp->vxlan_port != udp_tunnel->udp_port) {
1879 PMD_DRV_LOG(ERR, "Only one port allowed\n");
1882 bp->vxlan_port_cnt++;
1886 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
1887 bp->vxlan_port_cnt++;
1889 case RTE_TUNNEL_TYPE_GENEVE:
1890 if (bp->geneve_port_cnt) {
1891 PMD_DRV_LOG(ERR, "Tunnel Port %d already programmed\n",
1892 udp_tunnel->udp_port);
1893 if (bp->geneve_port != udp_tunnel->udp_port) {
1894 PMD_DRV_LOG(ERR, "Only one port allowed\n");
1897 bp->geneve_port_cnt++;
1901 HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
1902 bp->geneve_port_cnt++;
1905 PMD_DRV_LOG(ERR, "Tunnel type is not supported\n");
1908 rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
1914 bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
1915 struct rte_eth_udp_tunnel *udp_tunnel)
1917 struct bnxt *bp = eth_dev->data->dev_private;
1918 uint16_t tunnel_type = 0;
1922 rc = is_bnxt_in_error(bp);
1926 switch (udp_tunnel->prot_type) {
1927 case RTE_TUNNEL_TYPE_VXLAN:
1928 if (!bp->vxlan_port_cnt) {
1929 PMD_DRV_LOG(ERR, "No Tunnel port configured yet\n");
1932 if (bp->vxlan_port != udp_tunnel->udp_port) {
1933 PMD_DRV_LOG(ERR, "Req Port: %d. Configured port: %d\n",
1934 udp_tunnel->udp_port, bp->vxlan_port);
1937 if (--bp->vxlan_port_cnt)
1941 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
1942 port = bp->vxlan_fw_dst_port_id;
1944 case RTE_TUNNEL_TYPE_GENEVE:
1945 if (!bp->geneve_port_cnt) {
1946 PMD_DRV_LOG(ERR, "No Tunnel port configured yet\n");
1949 if (bp->geneve_port != udp_tunnel->udp_port) {
1950 PMD_DRV_LOG(ERR, "Req Port: %d. Configured port: %d\n",
1951 udp_tunnel->udp_port, bp->geneve_port);
1954 if (--bp->geneve_port_cnt)
1958 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
1959 port = bp->geneve_fw_dst_port_id;
1962 PMD_DRV_LOG(ERR, "Tunnel type is not supported\n");
1966 rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
1969 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN)
1972 HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE)
1973 bp->geneve_port = 0;
1978 static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
1980 struct bnxt_filter_info *filter;
1981 struct bnxt_vnic_info *vnic;
1983 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
1985 vnic = BNXT_GET_DEFAULT_VNIC(bp);
1986 filter = STAILQ_FIRST(&vnic->filter);
1988 /* Search for this matching MAC+VLAN filter */
1989 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id)) {
1990 /* Delete the filter */
1991 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
1994 STAILQ_REMOVE(&vnic->filter, filter,
1995 bnxt_filter_info, next);
1996 bnxt_free_filter(bp, filter);
1998 "Deleted vlan filter for %d\n",
2002 filter = STAILQ_NEXT(filter, next);
2007 static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2009 struct bnxt_filter_info *filter;
2010 struct bnxt_vnic_info *vnic;
2012 uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
2013 HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
2014 uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2016 /* Implementation notes on the use of VNIC in this command:
2018 * By default, these filters belong to default vnic for the function.
2019 * Once these filters are set up, only destination VNIC can be modified.
2020 * If the destination VNIC is not specified in this command,
2021 * then the HWRM shall only create an l2 context id.
2024 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2025 filter = STAILQ_FIRST(&vnic->filter);
2026 /* Check if the VLAN has already been added */
2028 if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id))
2031 filter = STAILQ_NEXT(filter, next);
2034 /* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
2035 * command to create MAC+VLAN filter with the right flags, enables set.
2037 filter = bnxt_alloc_filter(bp);
2040 "MAC/VLAN filter alloc failed\n");
2043 /* MAC + VLAN ID filter */
2044 /* If l2_ivlan == 0 and l2_ivlan_mask != 0, only
2045 * untagged packets are received
2047 * If l2_ivlan != 0 and l2_ivlan_mask != 0, untagged
2048 * packets and only the programmed vlan's packets are received
2050 filter->l2_ivlan = vlan_id;
2051 filter->l2_ivlan_mask = 0x0FFF;
2052 filter->enables |= en;
2053 filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
2055 rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
2057 /* Free the newly allocated filter as we were
2058 * not able to create the filter in hardware.
2060 bnxt_free_filter(bp, filter);
2064 filter->mac_index = 0;
2065 /* Add this new filter to the list */
2067 STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
2069 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
2072 "Added Vlan filter for %d\n", vlan_id);
2076 static int bnxt_vlan_filter_set_op(struct rte_eth_dev *eth_dev,
2077 uint16_t vlan_id, int on)
2079 struct bnxt *bp = eth_dev->data->dev_private;
2082 rc = is_bnxt_in_error(bp);
2086 if (!eth_dev->data->dev_started) {
2087 PMD_DRV_LOG(ERR, "port must be started before setting vlan\n");
2091 /* These operations apply to ALL existing MAC/VLAN filters */
2093 return bnxt_add_vlan_filter(bp, vlan_id);
2095 return bnxt_del_vlan_filter(bp, vlan_id);
2098 static int bnxt_del_dflt_mac_filter(struct bnxt *bp,
2099 struct bnxt_vnic_info *vnic)
2101 struct bnxt_filter_info *filter;
2104 filter = STAILQ_FIRST(&vnic->filter);
2106 if (filter->mac_index == 0 &&
2107 !memcmp(filter->l2_addr, bp->mac_addr,
2108 RTE_ETHER_ADDR_LEN)) {
2109 rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2111 STAILQ_REMOVE(&vnic->filter, filter,
2112 bnxt_filter_info, next);
2113 bnxt_free_filter(bp, filter);
2117 filter = STAILQ_NEXT(filter, next);
2123 bnxt_config_vlan_hw_filter(struct bnxt *bp, uint64_t rx_offloads)
2125 struct bnxt_vnic_info *vnic;
2129 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2130 if (!(rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)) {
2131 /* Remove any VLAN filters programmed */
2132 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2133 bnxt_del_vlan_filter(bp, i);
2135 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2139 /* Default filter will allow packets that match the
2140 * dest mac. So, it has to be deleted, otherwise, we
2141 * will endup receiving vlan packets for which the
2142 * filter is not programmed, when hw-vlan-filter
2143 * configuration is ON
2145 bnxt_del_dflt_mac_filter(bp, vnic);
2146 /* This filter will allow only untagged packets */
2147 bnxt_add_vlan_filter(bp, 0);
2149 PMD_DRV_LOG(DEBUG, "VLAN Filtering: %d\n",
2150 !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER));
2155 static int bnxt_free_one_vnic(struct bnxt *bp, uint16_t vnic_id)
2157 struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
2161 /* Destroy vnic filters and vnic */
2162 if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2163 DEV_RX_OFFLOAD_VLAN_FILTER) {
2164 for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2165 bnxt_del_vlan_filter(bp, i);
2167 bnxt_del_dflt_mac_filter(bp, vnic);
2169 rc = bnxt_hwrm_vnic_free(bp, vnic);
2173 rte_free(vnic->fw_grp_ids);
2174 vnic->fw_grp_ids = NULL;
2176 vnic->rx_queue_cnt = 0;
2182 bnxt_config_vlan_hw_stripping(struct bnxt *bp, uint64_t rx_offloads)
2184 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
2187 /* Destroy, recreate and reconfigure the default vnic */
2188 rc = bnxt_free_one_vnic(bp, 0);
2192 /* default vnic 0 */
2193 rc = bnxt_setup_one_vnic(bp, 0);
2197 if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2198 DEV_RX_OFFLOAD_VLAN_FILTER) {
2199 rc = bnxt_add_vlan_filter(bp, 0);
2202 rc = bnxt_restore_vlan_filters(bp);
2206 rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2211 rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2215 PMD_DRV_LOG(DEBUG, "VLAN Strip Offload: %d\n",
2216 !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP));
2222 bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
2224 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
2225 struct bnxt *bp = dev->data->dev_private;
2228 rc = is_bnxt_in_error(bp);
2232 /* Filter settings will get applied when port is started */
2233 if (!dev->data->dev_started)
2236 if (mask & ETH_VLAN_FILTER_MASK) {
2237 /* Enable or disable VLAN filtering */
2238 rc = bnxt_config_vlan_hw_filter(bp, rx_offloads);
2243 if (mask & ETH_VLAN_STRIP_MASK) {
2244 /* Enable or disable VLAN stripping */
2245 rc = bnxt_config_vlan_hw_stripping(bp, rx_offloads);
2250 if (mask & ETH_VLAN_EXTEND_MASK) {
2251 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2252 PMD_DRV_LOG(DEBUG, "Extend VLAN supported\n");
2254 PMD_DRV_LOG(INFO, "Extend VLAN unsupported\n");
2261 bnxt_vlan_tpid_set_op(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
2264 struct bnxt *bp = dev->data->dev_private;
2265 int qinq = dev->data->dev_conf.rxmode.offloads &
2266 DEV_RX_OFFLOAD_VLAN_EXTEND;
2268 if (vlan_type != ETH_VLAN_TYPE_INNER &&
2269 vlan_type != ETH_VLAN_TYPE_OUTER) {
2271 "Unsupported vlan type.");
2276 "QinQ not enabled. Needs to be ON as we can "
2277 "accelerate only outer vlan\n");
2281 if (vlan_type == ETH_VLAN_TYPE_OUTER) {
2283 case RTE_ETHER_TYPE_QINQ:
2285 TX_BD_LONG_CFA_META_VLAN_TPID_TPID88A8;
2287 case RTE_ETHER_TYPE_VLAN:
2289 TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
2293 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9100;
2297 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9200;
2301 TX_BD_LONG_CFA_META_VLAN_TPID_TPID9300;
2304 PMD_DRV_LOG(ERR, "Invalid TPID: %x\n", tpid);
2307 bp->outer_tpid_bd |= tpid;
2308 PMD_DRV_LOG(INFO, "outer_tpid_bd = %x\n", bp->outer_tpid_bd);
2309 } else if (vlan_type == ETH_VLAN_TYPE_INNER) {
2311 "Can accelerate only outer vlan in QinQ\n");
2319 bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
2320 struct rte_ether_addr *addr)
2322 struct bnxt *bp = dev->data->dev_private;
2323 /* Default Filter is tied to VNIC 0 */
2324 struct bnxt_vnic_info *vnic = BNXT_GET_DEFAULT_VNIC(bp);
2327 rc = is_bnxt_in_error(bp);
2331 if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
2334 if (rte_is_zero_ether_addr(addr))
2337 /* Filter settings will get applied when port is started */
2338 if (!dev->data->dev_started)
2341 /* Check if the requested MAC is already added */
2342 if (memcmp(addr, bp->mac_addr, RTE_ETHER_ADDR_LEN) == 0)
2345 /* Destroy filter and re-create it */
2346 bnxt_del_dflt_mac_filter(bp, vnic);
2348 memcpy(bp->mac_addr, addr, RTE_ETHER_ADDR_LEN);
2349 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_VLAN_FILTER) {
2350 /* This filter will allow only untagged packets */
2351 rc = bnxt_add_vlan_filter(bp, 0);
2353 rc = bnxt_add_mac_filter(bp, vnic, addr, 0, 0);
2356 PMD_DRV_LOG(DEBUG, "Set MAC addr\n");
2361 bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
2362 struct rte_ether_addr *mc_addr_set,
2363 uint32_t nb_mc_addr)
2365 struct bnxt *bp = eth_dev->data->dev_private;
2366 char *mc_addr_list = (char *)mc_addr_set;
2367 struct bnxt_vnic_info *vnic;
2368 uint32_t off = 0, i = 0;
2371 rc = is_bnxt_in_error(bp);
2375 vnic = BNXT_GET_DEFAULT_VNIC(bp);
2377 if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
2378 vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
2382 /* TODO Check for Duplicate mcast addresses */
2383 vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
2384 for (i = 0; i < nb_mc_addr; i++) {
2385 memcpy(vnic->mc_list + off, &mc_addr_list[i],
2386 RTE_ETHER_ADDR_LEN);
2387 off += RTE_ETHER_ADDR_LEN;
2390 vnic->mc_addr_cnt = i;
2391 if (vnic->mc_addr_cnt)
2392 vnic->flags |= BNXT_VNIC_INFO_MCAST;
2394 vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
2397 return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2401 bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
2403 struct bnxt *bp = dev->data->dev_private;
2404 uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
2405 uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
2406 uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
2409 ret = snprintf(fw_version, fw_size, "%d.%d.%d",
2410 fw_major, fw_minor, fw_updt);
2412 ret += 1; /* add the size of '\0' */
2413 if (fw_size < (uint32_t)ret)
2420 bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
2421 struct rte_eth_rxq_info *qinfo)
2423 struct bnxt *bp = dev->data->dev_private;
2424 struct bnxt_rx_queue *rxq;
2426 if (is_bnxt_in_error(bp))
2429 rxq = dev->data->rx_queues[queue_id];
2431 qinfo->mp = rxq->mb_pool;
2432 qinfo->scattered_rx = dev->data->scattered_rx;
2433 qinfo->nb_desc = rxq->nb_rx_desc;
2435 qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
2436 qinfo->conf.rx_drop_en = 0;
2437 qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
2441 bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
2442 struct rte_eth_txq_info *qinfo)
2444 struct bnxt *bp = dev->data->dev_private;
2445 struct bnxt_tx_queue *txq;
2447 if (is_bnxt_in_error(bp))
2450 txq = dev->data->tx_queues[queue_id];
2452 qinfo->nb_desc = txq->nb_tx_desc;
2454 qinfo->conf.tx_thresh.pthresh = txq->pthresh;
2455 qinfo->conf.tx_thresh.hthresh = txq->hthresh;
2456 qinfo->conf.tx_thresh.wthresh = txq->wthresh;
2458 qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
2459 qinfo->conf.tx_rs_thresh = 0;
2460 qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
2463 int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
2465 struct bnxt *bp = eth_dev->data->dev_private;
2466 uint32_t new_pkt_size;
2470 rc = is_bnxt_in_error(bp);
2474 /* Exit if receive queues are not configured yet */
2475 if (!eth_dev->data->nb_rx_queues)
2478 new_pkt_size = new_mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
2479 VLAN_TAG_SIZE * BNXT_NUM_VLANS;
2483 * If vector-mode tx/rx is active, disallow any MTU change that would
2484 * require scattered receive support.
2486 if (eth_dev->data->dev_started &&
2487 (eth_dev->rx_pkt_burst == bnxt_recv_pkts_vec ||
2488 eth_dev->tx_pkt_burst == bnxt_xmit_pkts_vec) &&
2490 eth_dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
2492 "MTU change would require scattered rx support. ");
2493 PMD_DRV_LOG(ERR, "Stop port before changing MTU.\n");
2498 if (new_mtu > RTE_ETHER_MTU) {
2499 bp->flags |= BNXT_FLAG_JUMBO;
2500 bp->eth_dev->data->dev_conf.rxmode.offloads |=
2501 DEV_RX_OFFLOAD_JUMBO_FRAME;
2503 bp->eth_dev->data->dev_conf.rxmode.offloads &=
2504 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2505 bp->flags &= ~BNXT_FLAG_JUMBO;
2508 /* Is there a change in mtu setting? */
2509 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len == new_pkt_size)
2512 for (i = 0; i < bp->nr_vnics; i++) {
2513 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2516 vnic->mru = BNXT_VNIC_MRU(new_mtu);
2517 rc = bnxt_hwrm_vnic_cfg(bp, vnic);
2521 size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
2522 size -= RTE_PKTMBUF_HEADROOM;
2524 if (size < new_mtu) {
2525 rc = bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
2532 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = new_pkt_size;
2534 PMD_DRV_LOG(INFO, "New MTU is %d\n", new_mtu);
2540 bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
2542 struct bnxt *bp = dev->data->dev_private;
2543 uint16_t vlan = bp->vlan;
2546 rc = is_bnxt_in_error(bp);
2550 if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp)) {
2552 "PVID cannot be modified for this function\n");
2555 bp->vlan = on ? pvid : 0;
2557 rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
2564 bnxt_dev_led_on_op(struct rte_eth_dev *dev)
2566 struct bnxt *bp = dev->data->dev_private;
2569 rc = is_bnxt_in_error(bp);
2573 return bnxt_hwrm_port_led_cfg(bp, true);
2577 bnxt_dev_led_off_op(struct rte_eth_dev *dev)
2579 struct bnxt *bp = dev->data->dev_private;
2582 rc = is_bnxt_in_error(bp);
2586 return bnxt_hwrm_port_led_cfg(bp, false);
2590 bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
2592 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
2593 uint32_t desc = 0, raw_cons = 0, cons;
2594 struct bnxt_cp_ring_info *cpr;
2595 struct bnxt_rx_queue *rxq;
2596 struct rx_pkt_cmpl *rxcmp;
2599 rc = is_bnxt_in_error(bp);
2603 rxq = dev->data->rx_queues[rx_queue_id];
2605 raw_cons = cpr->cp_raw_cons;
2608 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
2609 rte_prefetch0(&cpr->cp_desc_ring[cons]);
2610 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2612 if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct)) {
2624 bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)
2626 struct bnxt_rx_queue *rxq = (struct bnxt_rx_queue *)rx_queue;
2627 struct bnxt_rx_ring_info *rxr;
2628 struct bnxt_cp_ring_info *cpr;
2629 struct bnxt_sw_rx_bd *rx_buf;
2630 struct rx_pkt_cmpl *rxcmp;
2631 uint32_t cons, cp_cons;
2637 rc = is_bnxt_in_error(rxq->bp);
2644 if (offset >= rxq->nb_rx_desc)
2647 cons = RING_CMP(cpr->cp_ring_struct, offset);
2648 cp_cons = cpr->cp_raw_cons;
2649 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2651 if (cons > cp_cons) {
2652 if (CMPL_VALID(rxcmp, cpr->valid))
2653 return RTE_ETH_RX_DESC_DONE;
2655 if (CMPL_VALID(rxcmp, !cpr->valid))
2656 return RTE_ETH_RX_DESC_DONE;
2658 rx_buf = &rxr->rx_buf_ring[cons];
2659 if (rx_buf->mbuf == NULL)
2660 return RTE_ETH_RX_DESC_UNAVAIL;
2663 return RTE_ETH_RX_DESC_AVAIL;
2667 bnxt_tx_descriptor_status_op(void *tx_queue, uint16_t offset)
2669 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
2670 struct bnxt_tx_ring_info *txr;
2671 struct bnxt_cp_ring_info *cpr;
2672 struct bnxt_sw_tx_bd *tx_buf;
2673 struct tx_pkt_cmpl *txcmp;
2674 uint32_t cons, cp_cons;
2680 rc = is_bnxt_in_error(txq->bp);
2687 if (offset >= txq->nb_tx_desc)
2690 cons = RING_CMP(cpr->cp_ring_struct, offset);
2691 txcmp = (struct tx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
2692 cp_cons = cpr->cp_raw_cons;
2694 if (cons > cp_cons) {
2695 if (CMPL_VALID(txcmp, cpr->valid))
2696 return RTE_ETH_TX_DESC_UNAVAIL;
2698 if (CMPL_VALID(txcmp, !cpr->valid))
2699 return RTE_ETH_TX_DESC_UNAVAIL;
2701 tx_buf = &txr->tx_buf_ring[cons];
2702 if (tx_buf->mbuf == NULL)
2703 return RTE_ETH_TX_DESC_DONE;
2705 return RTE_ETH_TX_DESC_FULL;
2708 static struct bnxt_filter_info *
2709 bnxt_match_and_validate_ether_filter(struct bnxt *bp,
2710 struct rte_eth_ethertype_filter *efilter,
2711 struct bnxt_vnic_info *vnic0,
2712 struct bnxt_vnic_info *vnic,
2715 struct bnxt_filter_info *mfilter = NULL;
2719 if (efilter->ether_type == RTE_ETHER_TYPE_IPV4 ||
2720 efilter->ether_type == RTE_ETHER_TYPE_IPV6) {
2721 PMD_DRV_LOG(ERR, "invalid ether_type(0x%04x) in"
2722 " ethertype filter.", efilter->ether_type);
2726 if (efilter->queue >= bp->rx_nr_rings) {
2727 PMD_DRV_LOG(ERR, "Invalid queue %d\n", efilter->queue);
2732 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
2733 vnic = &bp->vnic_info[efilter->queue];
2735 PMD_DRV_LOG(ERR, "Invalid queue %d\n", efilter->queue);
2740 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
2741 STAILQ_FOREACH(mfilter, &vnic0->filter, next) {
2742 if ((!memcmp(efilter->mac_addr.addr_bytes,
2743 mfilter->l2_addr, RTE_ETHER_ADDR_LEN) &&
2745 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP &&
2746 mfilter->ethertype == efilter->ether_type)) {
2752 STAILQ_FOREACH(mfilter, &vnic->filter, next)
2753 if ((!memcmp(efilter->mac_addr.addr_bytes,
2754 mfilter->l2_addr, RTE_ETHER_ADDR_LEN) &&
2755 mfilter->ethertype == efilter->ether_type &&
2757 HWRM_CFA_L2_FILTER_CFG_INPUT_FLAGS_PATH_RX)) {
2771 bnxt_ethertype_filter(struct rte_eth_dev *dev,
2772 enum rte_filter_op filter_op,
2775 struct bnxt *bp = dev->data->dev_private;
2776 struct rte_eth_ethertype_filter *efilter =
2777 (struct rte_eth_ethertype_filter *)arg;
2778 struct bnxt_filter_info *bfilter, *filter1;
2779 struct bnxt_vnic_info *vnic, *vnic0;
2782 if (filter_op == RTE_ETH_FILTER_NOP)
2786 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
2791 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
2792 vnic = &bp->vnic_info[efilter->queue];
2794 switch (filter_op) {
2795 case RTE_ETH_FILTER_ADD:
2796 bnxt_match_and_validate_ether_filter(bp, efilter,
2801 bfilter = bnxt_get_unused_filter(bp);
2802 if (bfilter == NULL) {
2804 "Not enough resources for a new filter.\n");
2807 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
2808 memcpy(bfilter->l2_addr, efilter->mac_addr.addr_bytes,
2809 RTE_ETHER_ADDR_LEN);
2810 memcpy(bfilter->dst_macaddr, efilter->mac_addr.addr_bytes,
2811 RTE_ETHER_ADDR_LEN);
2812 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
2813 bfilter->ethertype = efilter->ether_type;
2814 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
2816 filter1 = bnxt_get_l2_filter(bp, bfilter, vnic0);
2817 if (filter1 == NULL) {
2822 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
2823 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
2825 bfilter->dst_id = vnic->fw_vnic_id;
2827 if (efilter->flags & RTE_ETHTYPE_FLAGS_DROP) {
2829 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
2832 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
2835 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
2837 case RTE_ETH_FILTER_DELETE:
2838 filter1 = bnxt_match_and_validate_ether_filter(bp, efilter,
2840 if (ret == -EEXIST) {
2841 ret = bnxt_hwrm_clear_ntuple_filter(bp, filter1);
2843 STAILQ_REMOVE(&vnic->filter, filter1, bnxt_filter_info,
2845 bnxt_free_filter(bp, filter1);
2846 } else if (ret == 0) {
2847 PMD_DRV_LOG(ERR, "No matching filter found\n");
2851 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
2857 bnxt_free_filter(bp, bfilter);
2863 parse_ntuple_filter(struct bnxt *bp,
2864 struct rte_eth_ntuple_filter *nfilter,
2865 struct bnxt_filter_info *bfilter)
2869 if (nfilter->queue >= bp->rx_nr_rings) {
2870 PMD_DRV_LOG(ERR, "Invalid queue %d\n", nfilter->queue);
2874 switch (nfilter->dst_port_mask) {
2876 bfilter->dst_port_mask = -1;
2877 bfilter->dst_port = nfilter->dst_port;
2878 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT |
2879 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
2882 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
2886 bfilter->ip_addr_type = NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
2887 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2889 switch (nfilter->proto_mask) {
2891 if (nfilter->proto == 17) /* IPPROTO_UDP */
2892 bfilter->ip_protocol = 17;
2893 else if (nfilter->proto == 6) /* IPPROTO_TCP */
2894 bfilter->ip_protocol = 6;
2897 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
2900 PMD_DRV_LOG(ERR, "invalid protocol mask.");
2904 switch (nfilter->dst_ip_mask) {
2906 bfilter->dst_ipaddr_mask[0] = -1;
2907 bfilter->dst_ipaddr[0] = nfilter->dst_ip;
2908 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR |
2909 NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
2912 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
2916 switch (nfilter->src_ip_mask) {
2918 bfilter->src_ipaddr_mask[0] = -1;
2919 bfilter->src_ipaddr[0] = nfilter->src_ip;
2920 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR |
2921 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
2924 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
2928 switch (nfilter->src_port_mask) {
2930 bfilter->src_port_mask = -1;
2931 bfilter->src_port = nfilter->src_port;
2932 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT |
2933 NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
2936 PMD_DRV_LOG(ERR, "invalid src_port mask.");
2940 bfilter->enables = en;
2944 static struct bnxt_filter_info*
2945 bnxt_match_ntuple_filter(struct bnxt *bp,
2946 struct bnxt_filter_info *bfilter,
2947 struct bnxt_vnic_info **mvnic)
2949 struct bnxt_filter_info *mfilter = NULL;
2952 for (i = bp->nr_vnics - 1; i >= 0; i--) {
2953 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
2954 STAILQ_FOREACH(mfilter, &vnic->filter, next) {
2955 if (bfilter->src_ipaddr[0] == mfilter->src_ipaddr[0] &&
2956 bfilter->src_ipaddr_mask[0] ==
2957 mfilter->src_ipaddr_mask[0] &&
2958 bfilter->src_port == mfilter->src_port &&
2959 bfilter->src_port_mask == mfilter->src_port_mask &&
2960 bfilter->dst_ipaddr[0] == mfilter->dst_ipaddr[0] &&
2961 bfilter->dst_ipaddr_mask[0] ==
2962 mfilter->dst_ipaddr_mask[0] &&
2963 bfilter->dst_port == mfilter->dst_port &&
2964 bfilter->dst_port_mask == mfilter->dst_port_mask &&
2965 bfilter->flags == mfilter->flags &&
2966 bfilter->enables == mfilter->enables) {
2977 bnxt_cfg_ntuple_filter(struct bnxt *bp,
2978 struct rte_eth_ntuple_filter *nfilter,
2979 enum rte_filter_op filter_op)
2981 struct bnxt_filter_info *bfilter, *mfilter, *filter1;
2982 struct bnxt_vnic_info *vnic, *vnic0, *mvnic;
2985 if (nfilter->flags != RTE_5TUPLE_FLAGS) {
2986 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
2990 if (nfilter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
2991 PMD_DRV_LOG(ERR, "Ntuple filter: TCP flags not supported\n");
2995 bfilter = bnxt_get_unused_filter(bp);
2996 if (bfilter == NULL) {
2998 "Not enough resources for a new filter.\n");
3001 ret = parse_ntuple_filter(bp, nfilter, bfilter);
3005 vnic = &bp->vnic_info[nfilter->queue];
3006 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3007 filter1 = STAILQ_FIRST(&vnic0->filter);
3008 if (filter1 == NULL) {
3013 bfilter->dst_id = vnic->fw_vnic_id;
3014 bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3016 HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3017 bfilter->ethertype = 0x800;
3018 bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3020 mfilter = bnxt_match_ntuple_filter(bp, bfilter, &mvnic);
3022 if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
3023 bfilter->dst_id == mfilter->dst_id) {
3024 PMD_DRV_LOG(ERR, "filter exists.\n");
3027 } else if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
3028 bfilter->dst_id != mfilter->dst_id) {
3029 mfilter->dst_id = vnic->fw_vnic_id;
3030 ret = bnxt_hwrm_set_ntuple_filter(bp, mfilter->dst_id, mfilter);
3031 STAILQ_REMOVE(&mvnic->filter, mfilter, bnxt_filter_info, next);
3032 STAILQ_INSERT_TAIL(&vnic->filter, mfilter, next);
3033 PMD_DRV_LOG(ERR, "filter with matching pattern exists.\n");
3034 PMD_DRV_LOG(ERR, " Updated it to the new destination queue\n");
3037 if (mfilter == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
3038 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3043 if (filter_op == RTE_ETH_FILTER_ADD) {
3044 bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3045 ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
3048 STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
3050 if (mfilter == NULL) {
3051 /* This should not happen. But for Coverity! */
3055 ret = bnxt_hwrm_clear_ntuple_filter(bp, mfilter);
3057 STAILQ_REMOVE(&vnic->filter, mfilter, bnxt_filter_info, next);
3058 bnxt_free_filter(bp, mfilter);
3059 bnxt_free_filter(bp, bfilter);
3064 bnxt_free_filter(bp, bfilter);
3069 bnxt_ntuple_filter(struct rte_eth_dev *dev,
3070 enum rte_filter_op filter_op,
3073 struct bnxt *bp = dev->data->dev_private;
3076 if (filter_op == RTE_ETH_FILTER_NOP)
3080 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3085 switch (filter_op) {
3086 case RTE_ETH_FILTER_ADD:
3087 ret = bnxt_cfg_ntuple_filter(bp,
3088 (struct rte_eth_ntuple_filter *)arg,
3091 case RTE_ETH_FILTER_DELETE:
3092 ret = bnxt_cfg_ntuple_filter(bp,
3093 (struct rte_eth_ntuple_filter *)arg,
3097 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3105 bnxt_parse_fdir_filter(struct bnxt *bp,
3106 struct rte_eth_fdir_filter *fdir,
3107 struct bnxt_filter_info *filter)
3109 enum rte_fdir_mode fdir_mode =
3110 bp->eth_dev->data->dev_conf.fdir_conf.mode;
3111 struct bnxt_vnic_info *vnic0, *vnic;
3112 struct bnxt_filter_info *filter1;
3116 if (fdir_mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
3119 filter->l2_ovlan = fdir->input.flow_ext.vlan_tci;
3120 en |= EM_FLOW_ALLOC_INPUT_EN_OVLAN_VID;
3122 switch (fdir->input.flow_type) {
3123 case RTE_ETH_FLOW_IPV4:
3124 case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
3126 filter->src_ipaddr[0] = fdir->input.flow.ip4_flow.src_ip;
3127 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3128 filter->dst_ipaddr[0] = fdir->input.flow.ip4_flow.dst_ip;
3129 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3130 filter->ip_protocol = fdir->input.flow.ip4_flow.proto;
3131 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3132 filter->ip_addr_type =
3133 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3134 filter->src_ipaddr_mask[0] = 0xffffffff;
3135 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3136 filter->dst_ipaddr_mask[0] = 0xffffffff;
3137 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3138 filter->ethertype = 0x800;
3139 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3141 case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
3142 filter->src_port = fdir->input.flow.tcp4_flow.src_port;
3143 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3144 filter->dst_port = fdir->input.flow.tcp4_flow.dst_port;
3145 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3146 filter->dst_port_mask = 0xffff;
3147 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3148 filter->src_port_mask = 0xffff;
3149 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3150 filter->src_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.src_ip;
3151 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3152 filter->dst_ipaddr[0] = fdir->input.flow.tcp4_flow.ip.dst_ip;
3153 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3154 filter->ip_protocol = 6;
3155 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3156 filter->ip_addr_type =
3157 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3158 filter->src_ipaddr_mask[0] = 0xffffffff;
3159 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3160 filter->dst_ipaddr_mask[0] = 0xffffffff;
3161 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3162 filter->ethertype = 0x800;
3163 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3165 case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
3166 filter->src_port = fdir->input.flow.udp4_flow.src_port;
3167 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3168 filter->dst_port = fdir->input.flow.udp4_flow.dst_port;
3169 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3170 filter->dst_port_mask = 0xffff;
3171 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3172 filter->src_port_mask = 0xffff;
3173 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3174 filter->src_ipaddr[0] = fdir->input.flow.udp4_flow.ip.src_ip;
3175 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3176 filter->dst_ipaddr[0] = fdir->input.flow.udp4_flow.ip.dst_ip;
3177 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3178 filter->ip_protocol = 17;
3179 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3180 filter->ip_addr_type =
3181 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
3182 filter->src_ipaddr_mask[0] = 0xffffffff;
3183 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3184 filter->dst_ipaddr_mask[0] = 0xffffffff;
3185 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3186 filter->ethertype = 0x800;
3187 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3189 case RTE_ETH_FLOW_IPV6:
3190 case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
3192 filter->ip_addr_type =
3193 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3194 filter->ip_protocol = fdir->input.flow.ipv6_flow.proto;
3195 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3196 rte_memcpy(filter->src_ipaddr,
3197 fdir->input.flow.ipv6_flow.src_ip, 16);
3198 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3199 rte_memcpy(filter->dst_ipaddr,
3200 fdir->input.flow.ipv6_flow.dst_ip, 16);
3201 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3202 memset(filter->dst_ipaddr_mask, 0xff, 16);
3203 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3204 memset(filter->src_ipaddr_mask, 0xff, 16);
3205 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3206 filter->ethertype = 0x86dd;
3207 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3209 case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
3210 filter->src_port = fdir->input.flow.tcp6_flow.src_port;
3211 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3212 filter->dst_port = fdir->input.flow.tcp6_flow.dst_port;
3213 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3214 filter->dst_port_mask = 0xffff;
3215 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3216 filter->src_port_mask = 0xffff;
3217 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3218 filter->ip_addr_type =
3219 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3220 filter->ip_protocol = fdir->input.flow.tcp6_flow.ip.proto;
3221 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3222 rte_memcpy(filter->src_ipaddr,
3223 fdir->input.flow.tcp6_flow.ip.src_ip, 16);
3224 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3225 rte_memcpy(filter->dst_ipaddr,
3226 fdir->input.flow.tcp6_flow.ip.dst_ip, 16);
3227 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3228 memset(filter->dst_ipaddr_mask, 0xff, 16);
3229 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3230 memset(filter->src_ipaddr_mask, 0xff, 16);
3231 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3232 filter->ethertype = 0x86dd;
3233 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3235 case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
3236 filter->src_port = fdir->input.flow.udp6_flow.src_port;
3237 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT;
3238 filter->dst_port = fdir->input.flow.udp6_flow.dst_port;
3239 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT;
3240 filter->dst_port_mask = 0xffff;
3241 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
3242 filter->src_port_mask = 0xffff;
3243 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
3244 filter->ip_addr_type =
3245 NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV6;
3246 filter->ip_protocol = fdir->input.flow.udp6_flow.ip.proto;
3247 en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
3248 rte_memcpy(filter->src_ipaddr,
3249 fdir->input.flow.udp6_flow.ip.src_ip, 16);
3250 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR;
3251 rte_memcpy(filter->dst_ipaddr,
3252 fdir->input.flow.udp6_flow.ip.dst_ip, 16);
3253 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR;
3254 memset(filter->dst_ipaddr_mask, 0xff, 16);
3255 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
3256 memset(filter->src_ipaddr_mask, 0xff, 16);
3257 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
3258 filter->ethertype = 0x86dd;
3259 filter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3261 case RTE_ETH_FLOW_L2_PAYLOAD:
3262 filter->ethertype = fdir->input.flow.l2_flow.ether_type;
3263 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
3265 case RTE_ETH_FLOW_VXLAN:
3266 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3268 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
3269 filter->tunnel_type =
3270 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_VXLAN;
3271 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
3273 case RTE_ETH_FLOW_NVGRE:
3274 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3276 filter->vni = fdir->input.flow.tunnel_flow.tunnel_id;
3277 filter->tunnel_type =
3278 CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_NVGRE;
3279 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_TUNNEL_TYPE;
3281 case RTE_ETH_FLOW_UNKNOWN:
3282 case RTE_ETH_FLOW_RAW:
3283 case RTE_ETH_FLOW_FRAG_IPV4:
3284 case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
3285 case RTE_ETH_FLOW_FRAG_IPV6:
3286 case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
3287 case RTE_ETH_FLOW_IPV6_EX:
3288 case RTE_ETH_FLOW_IPV6_TCP_EX:
3289 case RTE_ETH_FLOW_IPV6_UDP_EX:
3290 case RTE_ETH_FLOW_GENEVE:
3296 vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
3297 vnic = &bp->vnic_info[fdir->action.rx_queue];
3299 PMD_DRV_LOG(ERR, "Invalid queue %d\n", fdir->action.rx_queue);
3303 if (fdir_mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
3304 rte_memcpy(filter->dst_macaddr,
3305 fdir->input.flow.mac_vlan_flow.mac_addr.addr_bytes, 6);
3306 en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_MACADDR;
3309 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT) {
3310 filter->flags = HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_DROP;
3311 filter1 = STAILQ_FIRST(&vnic0->filter);
3312 //filter1 = bnxt_get_l2_filter(bp, filter, vnic0);
3314 filter->dst_id = vnic->fw_vnic_id;
3315 for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
3316 if (filter->dst_macaddr[i] == 0x00)
3317 filter1 = STAILQ_FIRST(&vnic0->filter);
3319 filter1 = bnxt_get_l2_filter(bp, filter, vnic);
3322 if (filter1 == NULL)
3325 en |= HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
3326 filter->fw_l2_filter_id = filter1->fw_l2_filter_id;
3328 filter->enables = en;
3333 static struct bnxt_filter_info *
3334 bnxt_match_fdir(struct bnxt *bp, struct bnxt_filter_info *nf,
3335 struct bnxt_vnic_info **mvnic)
3337 struct bnxt_filter_info *mf = NULL;
3340 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3341 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3343 STAILQ_FOREACH(mf, &vnic->filter, next) {
3344 if (mf->filter_type == nf->filter_type &&
3345 mf->flags == nf->flags &&
3346 mf->src_port == nf->src_port &&
3347 mf->src_port_mask == nf->src_port_mask &&
3348 mf->dst_port == nf->dst_port &&
3349 mf->dst_port_mask == nf->dst_port_mask &&
3350 mf->ip_protocol == nf->ip_protocol &&
3351 mf->ip_addr_type == nf->ip_addr_type &&
3352 mf->ethertype == nf->ethertype &&
3353 mf->vni == nf->vni &&
3354 mf->tunnel_type == nf->tunnel_type &&
3355 mf->l2_ovlan == nf->l2_ovlan &&
3356 mf->l2_ovlan_mask == nf->l2_ovlan_mask &&
3357 mf->l2_ivlan == nf->l2_ivlan &&
3358 mf->l2_ivlan_mask == nf->l2_ivlan_mask &&
3359 !memcmp(mf->l2_addr, nf->l2_addr,
3360 RTE_ETHER_ADDR_LEN) &&
3361 !memcmp(mf->l2_addr_mask, nf->l2_addr_mask,
3362 RTE_ETHER_ADDR_LEN) &&
3363 !memcmp(mf->src_macaddr, nf->src_macaddr,
3364 RTE_ETHER_ADDR_LEN) &&
3365 !memcmp(mf->dst_macaddr, nf->dst_macaddr,
3366 RTE_ETHER_ADDR_LEN) &&
3367 !memcmp(mf->src_ipaddr, nf->src_ipaddr,
3368 sizeof(nf->src_ipaddr)) &&
3369 !memcmp(mf->src_ipaddr_mask, nf->src_ipaddr_mask,
3370 sizeof(nf->src_ipaddr_mask)) &&
3371 !memcmp(mf->dst_ipaddr, nf->dst_ipaddr,
3372 sizeof(nf->dst_ipaddr)) &&
3373 !memcmp(mf->dst_ipaddr_mask, nf->dst_ipaddr_mask,
3374 sizeof(nf->dst_ipaddr_mask))) {
3385 bnxt_fdir_filter(struct rte_eth_dev *dev,
3386 enum rte_filter_op filter_op,
3389 struct bnxt *bp = dev->data->dev_private;
3390 struct rte_eth_fdir_filter *fdir = (struct rte_eth_fdir_filter *)arg;
3391 struct bnxt_filter_info *filter, *match;
3392 struct bnxt_vnic_info *vnic, *mvnic;
3395 if (filter_op == RTE_ETH_FILTER_NOP)
3398 if (arg == NULL && filter_op != RTE_ETH_FILTER_FLUSH)
3401 switch (filter_op) {
3402 case RTE_ETH_FILTER_ADD:
3403 case RTE_ETH_FILTER_DELETE:
3405 filter = bnxt_get_unused_filter(bp);
3406 if (filter == NULL) {
3408 "Not enough resources for a new flow.\n");
3412 ret = bnxt_parse_fdir_filter(bp, fdir, filter);
3415 filter->filter_type = HWRM_CFA_NTUPLE_FILTER;
3417 if (fdir->action.behavior == RTE_ETH_FDIR_REJECT)
3418 vnic = &bp->vnic_info[0];
3420 vnic = &bp->vnic_info[fdir->action.rx_queue];
3422 match = bnxt_match_fdir(bp, filter, &mvnic);
3423 if (match != NULL && filter_op == RTE_ETH_FILTER_ADD) {
3424 if (match->dst_id == vnic->fw_vnic_id) {
3425 PMD_DRV_LOG(ERR, "Flow already exists.\n");
3429 match->dst_id = vnic->fw_vnic_id;
3430 ret = bnxt_hwrm_set_ntuple_filter(bp,
3433 STAILQ_REMOVE(&mvnic->filter, match,
3434 bnxt_filter_info, next);
3435 STAILQ_INSERT_TAIL(&vnic->filter, match, next);
3437 "Filter with matching pattern exist\n");
3439 "Updated it to new destination q\n");
3443 if (match == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
3444 PMD_DRV_LOG(ERR, "Flow does not exist.\n");
3449 if (filter_op == RTE_ETH_FILTER_ADD) {
3450 ret = bnxt_hwrm_set_ntuple_filter(bp,
3455 STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
3457 ret = bnxt_hwrm_clear_ntuple_filter(bp, match);
3458 STAILQ_REMOVE(&vnic->filter, match,
3459 bnxt_filter_info, next);
3460 bnxt_free_filter(bp, match);
3461 bnxt_free_filter(bp, filter);
3464 case RTE_ETH_FILTER_FLUSH:
3465 for (i = bp->nr_vnics - 1; i >= 0; i--) {
3466 struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3468 STAILQ_FOREACH(filter, &vnic->filter, next) {
3469 if (filter->filter_type ==
3470 HWRM_CFA_NTUPLE_FILTER) {
3472 bnxt_hwrm_clear_ntuple_filter(bp,
3474 STAILQ_REMOVE(&vnic->filter, filter,
3475 bnxt_filter_info, next);
3480 case RTE_ETH_FILTER_UPDATE:
3481 case RTE_ETH_FILTER_STATS:
3482 case RTE_ETH_FILTER_INFO:
3483 PMD_DRV_LOG(ERR, "operation %u not implemented", filter_op);
3486 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
3493 bnxt_free_filter(bp, filter);
3498 bnxt_filter_ctrl_op(struct rte_eth_dev *dev,
3499 enum rte_filter_type filter_type,
3500 enum rte_filter_op filter_op, void *arg)
3502 struct bnxt *bp = dev->data->dev_private;
3505 ret = is_bnxt_in_error(dev->data->dev_private);
3509 switch (filter_type) {
3510 case RTE_ETH_FILTER_TUNNEL:
3512 "filter type: %d: To be implemented\n", filter_type);
3514 case RTE_ETH_FILTER_FDIR:
3515 ret = bnxt_fdir_filter(dev, filter_op, arg);
3517 case RTE_ETH_FILTER_NTUPLE:
3518 ret = bnxt_ntuple_filter(dev, filter_op, arg);
3520 case RTE_ETH_FILTER_ETHERTYPE:
3521 ret = bnxt_ethertype_filter(dev, filter_op, arg);
3523 case RTE_ETH_FILTER_GENERIC:
3524 if (filter_op != RTE_ETH_FILTER_GET)
3527 *(const void **)arg = &bnxt_ulp_rte_flow_ops;
3529 *(const void **)arg = &bnxt_flow_ops;
3533 "Filter type (%d) not supported", filter_type);
3540 static const uint32_t *
3541 bnxt_dev_supported_ptypes_get_op(struct rte_eth_dev *dev)
3543 static const uint32_t ptypes[] = {
3544 RTE_PTYPE_L2_ETHER_VLAN,
3545 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
3546 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
3550 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
3551 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
3552 RTE_PTYPE_INNER_L4_ICMP,
3553 RTE_PTYPE_INNER_L4_TCP,
3554 RTE_PTYPE_INNER_L4_UDP,
3558 if (!dev->rx_pkt_burst)
3564 static int bnxt_map_regs(struct bnxt *bp, uint32_t *reg_arr, int count,
3567 uint32_t reg_base = *reg_arr & 0xfffff000;
3571 for (i = 0; i < count; i++) {
3572 if ((reg_arr[i] & 0xfffff000) != reg_base)
3575 win_off = BNXT_GRCPF_REG_WINDOW_BASE_OUT + (reg_win - 1) * 4;
3576 rte_write32(reg_base, (uint8_t *)bp->bar0 + win_off);
3580 static int bnxt_map_ptp_regs(struct bnxt *bp)
3582 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3586 reg_arr = ptp->rx_regs;
3587 rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_RX_REGS, 5);
3591 reg_arr = ptp->tx_regs;
3592 rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_TX_REGS, 6);
3596 for (i = 0; i < BNXT_PTP_RX_REGS; i++)
3597 ptp->rx_mapped_regs[i] = 0x5000 + (ptp->rx_regs[i] & 0xfff);
3599 for (i = 0; i < BNXT_PTP_TX_REGS; i++)
3600 ptp->tx_mapped_regs[i] = 0x6000 + (ptp->tx_regs[i] & 0xfff);
3605 static void bnxt_unmap_ptp_regs(struct bnxt *bp)
3607 rte_write32(0, (uint8_t *)bp->bar0 +
3608 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 16);
3609 rte_write32(0, (uint8_t *)bp->bar0 +
3610 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 20);
3613 static uint64_t bnxt_cc_read(struct bnxt *bp)
3617 ns = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3618 BNXT_GRCPF_REG_SYNC_TIME));
3619 ns |= (uint64_t)(rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3620 BNXT_GRCPF_REG_SYNC_TIME + 4))) << 32;
3624 static int bnxt_get_tx_ts(struct bnxt *bp, uint64_t *ts)
3626 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3629 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3630 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3631 if (fifo & BNXT_PTP_TX_FIFO_EMPTY)
3634 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3635 ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3636 *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3637 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_L]));
3638 *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3639 ptp->tx_mapped_regs[BNXT_PTP_TX_TS_H])) << 32;
3644 static int bnxt_get_rx_ts(struct bnxt *bp, uint64_t *ts)
3646 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3647 struct bnxt_pf_info *pf = &bp->pf;
3654 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3655 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3656 if (!(fifo & BNXT_PTP_RX_FIFO_PENDING))
3659 port_id = pf->port_id;
3660 rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
3661 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
3663 fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3664 ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3665 if (fifo & BNXT_PTP_RX_FIFO_PENDING) {
3666 /* bnxt_clr_rx_ts(bp); TBD */
3670 *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3671 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
3672 *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3673 ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
3679 bnxt_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
3682 struct bnxt *bp = dev->data->dev_private;
3683 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3688 ns = rte_timespec_to_ns(ts);
3689 /* Set the timecounters to a new value. */
3696 bnxt_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
3698 struct bnxt *bp = dev->data->dev_private;
3699 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3700 uint64_t ns, systime_cycles = 0;
3706 if (BNXT_CHIP_THOR(bp))
3707 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
3710 systime_cycles = bnxt_cc_read(bp);
3712 ns = rte_timecounter_update(&ptp->tc, systime_cycles);
3713 *ts = rte_ns_to_timespec(ns);
3718 bnxt_timesync_enable(struct rte_eth_dev *dev)
3720 struct bnxt *bp = dev->data->dev_private;
3721 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3729 ptp->tx_tstamp_en = 1;
3730 ptp->rxctl = BNXT_PTP_MSG_EVENTS;
3732 rc = bnxt_hwrm_ptp_cfg(bp);
3736 memset(&ptp->tc, 0, sizeof(struct rte_timecounter));
3737 memset(&ptp->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
3738 memset(&ptp->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
3740 ptp->tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
3741 ptp->tc.cc_shift = shift;
3742 ptp->tc.nsec_mask = (1ULL << shift) - 1;
3744 ptp->rx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
3745 ptp->rx_tstamp_tc.cc_shift = shift;
3746 ptp->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
3748 ptp->tx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
3749 ptp->tx_tstamp_tc.cc_shift = shift;
3750 ptp->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
3752 if (!BNXT_CHIP_THOR(bp))
3753 bnxt_map_ptp_regs(bp);
3759 bnxt_timesync_disable(struct rte_eth_dev *dev)
3761 struct bnxt *bp = dev->data->dev_private;
3762 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3768 ptp->tx_tstamp_en = 0;
3771 bnxt_hwrm_ptp_cfg(bp);
3773 if (!BNXT_CHIP_THOR(bp))
3774 bnxt_unmap_ptp_regs(bp);
3780 bnxt_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
3781 struct timespec *timestamp,
3782 uint32_t flags __rte_unused)
3784 struct bnxt *bp = dev->data->dev_private;
3785 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3786 uint64_t rx_tstamp_cycles = 0;
3792 if (BNXT_CHIP_THOR(bp))
3793 rx_tstamp_cycles = ptp->rx_timestamp;
3795 bnxt_get_rx_ts(bp, &rx_tstamp_cycles);
3797 ns = rte_timecounter_update(&ptp->rx_tstamp_tc, rx_tstamp_cycles);
3798 *timestamp = rte_ns_to_timespec(ns);
3803 bnxt_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
3804 struct timespec *timestamp)
3806 struct bnxt *bp = dev->data->dev_private;
3807 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3808 uint64_t tx_tstamp_cycles = 0;
3815 if (BNXT_CHIP_THOR(bp))
3816 rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_PATH_TX,
3819 rc = bnxt_get_tx_ts(bp, &tx_tstamp_cycles);
3821 ns = rte_timecounter_update(&ptp->tx_tstamp_tc, tx_tstamp_cycles);
3822 *timestamp = rte_ns_to_timespec(ns);
3828 bnxt_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
3830 struct bnxt *bp = dev->data->dev_private;
3831 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3836 ptp->tc.nsec += delta;
3842 bnxt_get_eeprom_length_op(struct rte_eth_dev *dev)
3844 struct bnxt *bp = dev->data->dev_private;
3846 uint32_t dir_entries;
3847 uint32_t entry_length;
3849 rc = is_bnxt_in_error(bp);
3853 PMD_DRV_LOG(INFO, PCI_PRI_FMT "\n",
3854 bp->pdev->addr.domain, bp->pdev->addr.bus,
3855 bp->pdev->addr.devid, bp->pdev->addr.function);
3857 rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
3861 return dir_entries * entry_length;
3865 bnxt_get_eeprom_op(struct rte_eth_dev *dev,
3866 struct rte_dev_eeprom_info *in_eeprom)
3868 struct bnxt *bp = dev->data->dev_private;
3873 rc = is_bnxt_in_error(bp);
3877 PMD_DRV_LOG(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d\n",
3878 bp->pdev->addr.domain, bp->pdev->addr.bus,
3879 bp->pdev->addr.devid, bp->pdev->addr.function,
3880 in_eeprom->offset, in_eeprom->length);
3882 if (in_eeprom->offset == 0) /* special offset value to get directory */
3883 return bnxt_get_nvram_directory(bp, in_eeprom->length,
3886 index = in_eeprom->offset >> 24;
3887 offset = in_eeprom->offset & 0xffffff;
3890 return bnxt_hwrm_get_nvram_item(bp, index - 1, offset,
3891 in_eeprom->length, in_eeprom->data);
3896 static bool bnxt_dir_type_is_ape_bin_format(uint16_t dir_type)
3899 case BNX_DIR_TYPE_CHIMP_PATCH:
3900 case BNX_DIR_TYPE_BOOTCODE:
3901 case BNX_DIR_TYPE_BOOTCODE_2:
3902 case BNX_DIR_TYPE_APE_FW:
3903 case BNX_DIR_TYPE_APE_PATCH:
3904 case BNX_DIR_TYPE_KONG_FW:
3905 case BNX_DIR_TYPE_KONG_PATCH:
3906 case BNX_DIR_TYPE_BONO_FW:
3907 case BNX_DIR_TYPE_BONO_PATCH:
3915 static bool bnxt_dir_type_is_other_exec_format(uint16_t dir_type)
3918 case BNX_DIR_TYPE_AVS:
3919 case BNX_DIR_TYPE_EXP_ROM_MBA:
3920 case BNX_DIR_TYPE_PCIE:
3921 case BNX_DIR_TYPE_TSCF_UCODE:
3922 case BNX_DIR_TYPE_EXT_PHY:
3923 case BNX_DIR_TYPE_CCM:
3924 case BNX_DIR_TYPE_ISCSI_BOOT:
3925 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
3926 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
3934 static bool bnxt_dir_type_is_executable(uint16_t dir_type)
3936 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
3937 bnxt_dir_type_is_other_exec_format(dir_type);
3941 bnxt_set_eeprom_op(struct rte_eth_dev *dev,
3942 struct rte_dev_eeprom_info *in_eeprom)
3944 struct bnxt *bp = dev->data->dev_private;
3945 uint8_t index, dir_op;
3946 uint16_t type, ext, ordinal, attr;
3949 rc = is_bnxt_in_error(bp);
3953 PMD_DRV_LOG(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d\n",
3954 bp->pdev->addr.domain, bp->pdev->addr.bus,
3955 bp->pdev->addr.devid, bp->pdev->addr.function,
3956 in_eeprom->offset, in_eeprom->length);
3959 PMD_DRV_LOG(ERR, "NVM write not supported from a VF\n");
3963 type = in_eeprom->magic >> 16;
3965 if (type == 0xffff) { /* special value for directory operations */
3966 index = in_eeprom->magic & 0xff;
3967 dir_op = in_eeprom->magic >> 8;
3971 case 0x0e: /* erase */
3972 if (in_eeprom->offset != ~in_eeprom->magic)
3974 return bnxt_hwrm_erase_nvram_directory(bp, index - 1);
3980 /* Create or re-write an NVM item: */
3981 if (bnxt_dir_type_is_executable(type) == true)
3983 ext = in_eeprom->magic & 0xffff;
3984 ordinal = in_eeprom->offset >> 16;
3985 attr = in_eeprom->offset & 0xffff;
3987 return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
3988 in_eeprom->data, in_eeprom->length);
3995 static const struct eth_dev_ops bnxt_dev_ops = {
3996 .dev_infos_get = bnxt_dev_info_get_op,
3997 .dev_close = bnxt_dev_close_op,
3998 .dev_configure = bnxt_dev_configure_op,
3999 .dev_start = bnxt_dev_start_op,
4000 .dev_stop = bnxt_dev_stop_op,
4001 .dev_set_link_up = bnxt_dev_set_link_up_op,
4002 .dev_set_link_down = bnxt_dev_set_link_down_op,
4003 .stats_get = bnxt_stats_get_op,
4004 .stats_reset = bnxt_stats_reset_op,
4005 .rx_queue_setup = bnxt_rx_queue_setup_op,
4006 .rx_queue_release = bnxt_rx_queue_release_op,
4007 .tx_queue_setup = bnxt_tx_queue_setup_op,
4008 .tx_queue_release = bnxt_tx_queue_release_op,
4009 .rx_queue_intr_enable = bnxt_rx_queue_intr_enable_op,
4010 .rx_queue_intr_disable = bnxt_rx_queue_intr_disable_op,
4011 .reta_update = bnxt_reta_update_op,
4012 .reta_query = bnxt_reta_query_op,
4013 .rss_hash_update = bnxt_rss_hash_update_op,
4014 .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
4015 .link_update = bnxt_link_update_op,
4016 .promiscuous_enable = bnxt_promiscuous_enable_op,
4017 .promiscuous_disable = bnxt_promiscuous_disable_op,
4018 .allmulticast_enable = bnxt_allmulticast_enable_op,
4019 .allmulticast_disable = bnxt_allmulticast_disable_op,
4020 .mac_addr_add = bnxt_mac_addr_add_op,
4021 .mac_addr_remove = bnxt_mac_addr_remove_op,
4022 .flow_ctrl_get = bnxt_flow_ctrl_get_op,
4023 .flow_ctrl_set = bnxt_flow_ctrl_set_op,
4024 .udp_tunnel_port_add = bnxt_udp_tunnel_port_add_op,
4025 .udp_tunnel_port_del = bnxt_udp_tunnel_port_del_op,
4026 .vlan_filter_set = bnxt_vlan_filter_set_op,
4027 .vlan_offload_set = bnxt_vlan_offload_set_op,
4028 .vlan_tpid_set = bnxt_vlan_tpid_set_op,
4029 .vlan_pvid_set = bnxt_vlan_pvid_set_op,
4030 .mtu_set = bnxt_mtu_set_op,
4031 .mac_addr_set = bnxt_set_default_mac_addr_op,
4032 .xstats_get = bnxt_dev_xstats_get_op,
4033 .xstats_get_names = bnxt_dev_xstats_get_names_op,
4034 .xstats_reset = bnxt_dev_xstats_reset_op,
4035 .fw_version_get = bnxt_fw_version_get,
4036 .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
4037 .rxq_info_get = bnxt_rxq_info_get_op,
4038 .txq_info_get = bnxt_txq_info_get_op,
4039 .dev_led_on = bnxt_dev_led_on_op,
4040 .dev_led_off = bnxt_dev_led_off_op,
4041 .xstats_get_by_id = bnxt_dev_xstats_get_by_id_op,
4042 .xstats_get_names_by_id = bnxt_dev_xstats_get_names_by_id_op,
4043 .rx_queue_count = bnxt_rx_queue_count_op,
4044 .rx_descriptor_status = bnxt_rx_descriptor_status_op,
4045 .tx_descriptor_status = bnxt_tx_descriptor_status_op,
4046 .rx_queue_start = bnxt_rx_queue_start,
4047 .rx_queue_stop = bnxt_rx_queue_stop,
4048 .tx_queue_start = bnxt_tx_queue_start,
4049 .tx_queue_stop = bnxt_tx_queue_stop,
4050 .filter_ctrl = bnxt_filter_ctrl_op,
4051 .dev_supported_ptypes_get = bnxt_dev_supported_ptypes_get_op,
4052 .get_eeprom_length = bnxt_get_eeprom_length_op,
4053 .get_eeprom = bnxt_get_eeprom_op,
4054 .set_eeprom = bnxt_set_eeprom_op,
4055 .timesync_enable = bnxt_timesync_enable,
4056 .timesync_disable = bnxt_timesync_disable,
4057 .timesync_read_time = bnxt_timesync_read_time,
4058 .timesync_write_time = bnxt_timesync_write_time,
4059 .timesync_adjust_time = bnxt_timesync_adjust_time,
4060 .timesync_read_rx_timestamp = bnxt_timesync_read_rx_timestamp,
4061 .timesync_read_tx_timestamp = bnxt_timesync_read_tx_timestamp,
4064 static uint32_t bnxt_map_reset_regs(struct bnxt *bp, uint32_t reg)
4068 /* Only pre-map the reset GRC registers using window 3 */
4069 rte_write32(reg & 0xfffff000, (uint8_t *)bp->bar0 +
4070 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 8);
4072 offset = BNXT_GRCP_WINDOW_3_BASE + (reg & 0xffc);
4077 int bnxt_map_fw_health_status_regs(struct bnxt *bp)
4079 struct bnxt_error_recovery_info *info = bp->recovery_info;
4080 uint32_t reg_base = 0xffffffff;
4083 /* Only pre-map the monitoring GRC registers using window 2 */
4084 for (i = 0; i < BNXT_FW_STATUS_REG_CNT; i++) {
4085 uint32_t reg = info->status_regs[i];
4087 if (BNXT_FW_STATUS_REG_TYPE(reg) != BNXT_FW_STATUS_REG_TYPE_GRC)
4090 if (reg_base == 0xffffffff)
4091 reg_base = reg & 0xfffff000;
4092 if ((reg & 0xfffff000) != reg_base)
4095 /* Use mask 0xffc as the Lower 2 bits indicates
4096 * address space location
4098 info->mapped_status_regs[i] = BNXT_GRCP_WINDOW_2_BASE +
4102 if (reg_base == 0xffffffff)
4105 rte_write32(reg_base, (uint8_t *)bp->bar0 +
4106 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
4111 static void bnxt_write_fw_reset_reg(struct bnxt *bp, uint32_t index)
4113 struct bnxt_error_recovery_info *info = bp->recovery_info;
4114 uint32_t delay = info->delay_after_reset[index];
4115 uint32_t val = info->reset_reg_val[index];
4116 uint32_t reg = info->reset_reg[index];
4117 uint32_t type, offset;
4119 type = BNXT_FW_STATUS_REG_TYPE(reg);
4120 offset = BNXT_FW_STATUS_REG_OFF(reg);
4123 case BNXT_FW_STATUS_REG_TYPE_CFG:
4124 rte_pci_write_config(bp->pdev, &val, sizeof(val), offset);
4126 case BNXT_FW_STATUS_REG_TYPE_GRC:
4127 offset = bnxt_map_reset_regs(bp, offset);
4128 rte_write32(val, (uint8_t *)bp->bar0 + offset);
4130 case BNXT_FW_STATUS_REG_TYPE_BAR0:
4131 rte_write32(val, (uint8_t *)bp->bar0 + offset);
4134 /* wait on a specific interval of time until core reset is complete */
4136 rte_delay_ms(delay);
4139 static void bnxt_dev_cleanup(struct bnxt *bp)
4141 bnxt_set_hwrm_link_config(bp, false);
4142 bp->link_info.link_up = 0;
4143 if (bp->eth_dev->data->dev_started)
4144 bnxt_dev_stop_op(bp->eth_dev);
4146 bnxt_uninit_resources(bp, true);
4149 static int bnxt_restore_vlan_filters(struct bnxt *bp)
4151 struct rte_eth_dev *dev = bp->eth_dev;
4152 struct rte_vlan_filter_conf *vfc;
4156 for (vlan_id = 1; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
4157 vfc = &dev->data->vlan_filter_conf;
4158 vidx = vlan_id / 64;
4159 vbit = vlan_id % 64;
4161 /* Each bit corresponds to a VLAN id */
4162 if (vfc->ids[vidx] & (UINT64_C(1) << vbit)) {
4163 rc = bnxt_add_vlan_filter(bp, vlan_id);
4172 static int bnxt_restore_mac_filters(struct bnxt *bp)
4174 struct rte_eth_dev *dev = bp->eth_dev;
4175 struct rte_eth_dev_info dev_info;
4176 struct rte_ether_addr *addr;
4182 if (BNXT_VF(bp) & !BNXT_VF_IS_TRUSTED(bp))
4185 rc = bnxt_dev_info_get_op(dev, &dev_info);
4189 /* replay MAC address configuration */
4190 for (i = 1; i < dev_info.max_mac_addrs; i++) {
4191 addr = &dev->data->mac_addrs[i];
4193 /* skip zero address */
4194 if (rte_is_zero_ether_addr(addr))
4198 pool_mask = dev->data->mac_pool_sel[i];
4201 if (pool_mask & 1ULL) {
4202 rc = bnxt_mac_addr_add_op(dev, addr, i, pool);
4208 } while (pool_mask);
4214 static int bnxt_restore_filters(struct bnxt *bp)
4216 struct rte_eth_dev *dev = bp->eth_dev;
4219 if (dev->data->all_multicast) {
4220 ret = bnxt_allmulticast_enable_op(dev);
4224 if (dev->data->promiscuous) {
4225 ret = bnxt_promiscuous_enable_op(dev);
4230 ret = bnxt_restore_mac_filters(bp);
4234 ret = bnxt_restore_vlan_filters(bp);
4235 /* TODO restore other filters as well */
4239 static void bnxt_dev_recover(void *arg)
4241 struct bnxt *bp = arg;
4242 int timeout = bp->fw_reset_max_msecs;
4245 /* Clear Error flag so that device re-init should happen */
4246 bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
4249 rc = bnxt_hwrm_ver_get(bp, SHORT_HWRM_CMD_TIMEOUT);
4252 rte_delay_ms(BNXT_FW_READY_WAIT_INTERVAL);
4253 timeout -= BNXT_FW_READY_WAIT_INTERVAL;
4254 } while (rc && timeout);
4257 PMD_DRV_LOG(ERR, "FW is not Ready after reset\n");
4261 rc = bnxt_init_resources(bp, true);
4264 "Failed to initialize resources after reset\n");
4267 /* clear reset flag as the device is initialized now */
4268 bp->flags &= ~BNXT_FLAG_FW_RESET;
4270 rc = bnxt_dev_start_op(bp->eth_dev);
4272 PMD_DRV_LOG(ERR, "Failed to start port after reset\n");
4276 rc = bnxt_restore_filters(bp);
4280 PMD_DRV_LOG(INFO, "Recovered from FW reset\n");
4283 bnxt_dev_stop_op(bp->eth_dev);
4285 bp->flags |= BNXT_FLAG_FATAL_ERROR;
4286 bnxt_uninit_resources(bp, false);
4287 PMD_DRV_LOG(ERR, "Failed to recover from FW reset\n");
4290 void bnxt_dev_reset_and_resume(void *arg)
4292 struct bnxt *bp = arg;
4295 bnxt_dev_cleanup(bp);
4297 bnxt_wait_for_device_shutdown(bp);
4299 rc = rte_eal_alarm_set(US_PER_MS * bp->fw_reset_min_msecs,
4300 bnxt_dev_recover, (void *)bp);
4302 PMD_DRV_LOG(ERR, "Error setting recovery alarm");
4305 uint32_t bnxt_read_fw_status_reg(struct bnxt *bp, uint32_t index)
4307 struct bnxt_error_recovery_info *info = bp->recovery_info;
4308 uint32_t reg = info->status_regs[index];
4309 uint32_t type, offset, val = 0;
4311 type = BNXT_FW_STATUS_REG_TYPE(reg);
4312 offset = BNXT_FW_STATUS_REG_OFF(reg);
4315 case BNXT_FW_STATUS_REG_TYPE_CFG:
4316 rte_pci_read_config(bp->pdev, &val, sizeof(val), offset);
4318 case BNXT_FW_STATUS_REG_TYPE_GRC:
4319 offset = info->mapped_status_regs[index];
4321 case BNXT_FW_STATUS_REG_TYPE_BAR0:
4322 val = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
4330 static int bnxt_fw_reset_all(struct bnxt *bp)
4332 struct bnxt_error_recovery_info *info = bp->recovery_info;
4336 if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4337 /* Reset through master function driver */
4338 for (i = 0; i < info->reg_array_cnt; i++)
4339 bnxt_write_fw_reset_reg(bp, i);
4340 /* Wait for time specified by FW after triggering reset */
4341 rte_delay_ms(info->master_func_wait_period_after_reset);
4342 } else if (info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) {
4343 /* Reset with the help of Kong processor */
4344 rc = bnxt_hwrm_fw_reset(bp);
4346 PMD_DRV_LOG(ERR, "Failed to reset FW\n");
4352 static void bnxt_fw_reset_cb(void *arg)
4354 struct bnxt *bp = arg;
4355 struct bnxt_error_recovery_info *info = bp->recovery_info;
4358 /* Only Master function can do FW reset */
4359 if (bnxt_is_master_func(bp) &&
4360 bnxt_is_recovery_enabled(bp)) {
4361 rc = bnxt_fw_reset_all(bp);
4363 PMD_DRV_LOG(ERR, "Adapter recovery failed\n");
4368 /* if recovery method is ERROR_RECOVERY_CO_CPU, KONG will send
4369 * EXCEPTION_FATAL_ASYNC event to all the functions
4370 * (including MASTER FUNC). After receiving this Async, all the active
4371 * drivers should treat this case as FW initiated recovery
4373 if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4374 bp->fw_reset_min_msecs = BNXT_MIN_FW_READY_TIMEOUT;
4375 bp->fw_reset_max_msecs = BNXT_MAX_FW_RESET_TIMEOUT;
4377 /* To recover from error */
4378 rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
4383 /* Driver should poll FW heartbeat, reset_counter with the frequency
4384 * advertised by FW in HWRM_ERROR_RECOVERY_QCFG.
4385 * When the driver detects heartbeat stop or change in reset_counter,
4386 * it has to trigger a reset to recover from the error condition.
4387 * A “master PF” is the function who will have the privilege to
4388 * initiate the chimp reset. The master PF will be elected by the
4389 * firmware and will be notified through async message.
4391 static void bnxt_check_fw_health(void *arg)
4393 struct bnxt *bp = arg;
4394 struct bnxt_error_recovery_info *info = bp->recovery_info;
4395 uint32_t val = 0, wait_msec;
4397 if (!info || !bnxt_is_recovery_enabled(bp) ||
4398 is_bnxt_in_error(bp))
4401 val = bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
4402 if (val == info->last_heart_beat)
4405 info->last_heart_beat = val;
4407 val = bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
4408 if (val != info->last_reset_counter)
4411 info->last_reset_counter = val;
4413 rte_eal_alarm_set(US_PER_MS * info->driver_polling_freq,
4414 bnxt_check_fw_health, (void *)bp);
4418 /* Stop DMA to/from device */
4419 bp->flags |= BNXT_FLAG_FATAL_ERROR;
4420 bp->flags |= BNXT_FLAG_FW_RESET;
4422 PMD_DRV_LOG(ERR, "Detected FW dead condition\n");
4424 if (bnxt_is_master_func(bp))
4425 wait_msec = info->master_func_wait_period;
4427 wait_msec = info->normal_func_wait_period;
4429 rte_eal_alarm_set(US_PER_MS * wait_msec,
4430 bnxt_fw_reset_cb, (void *)bp);
4433 void bnxt_schedule_fw_health_check(struct bnxt *bp)
4435 uint32_t polling_freq;
4437 if (!bnxt_is_recovery_enabled(bp))
4440 if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
4443 polling_freq = bp->recovery_info->driver_polling_freq;
4445 rte_eal_alarm_set(US_PER_MS * polling_freq,
4446 bnxt_check_fw_health, (void *)bp);
4447 bp->flags |= BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4450 static void bnxt_cancel_fw_health_check(struct bnxt *bp)
4452 if (!bnxt_is_recovery_enabled(bp))
4455 rte_eal_alarm_cancel(bnxt_check_fw_health, (void *)bp);
4456 bp->flags &= ~BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4459 static bool bnxt_vf_pciid(uint16_t device_id)
4461 switch (device_id) {
4462 case BROADCOM_DEV_ID_57304_VF:
4463 case BROADCOM_DEV_ID_57406_VF:
4464 case BROADCOM_DEV_ID_5731X_VF:
4465 case BROADCOM_DEV_ID_5741X_VF:
4466 case BROADCOM_DEV_ID_57414_VF:
4467 case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
4468 case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
4469 case BROADCOM_DEV_ID_58802_VF:
4470 case BROADCOM_DEV_ID_57500_VF1:
4471 case BROADCOM_DEV_ID_57500_VF2:
4479 static bool bnxt_thor_device(uint16_t device_id)
4481 switch (device_id) {
4482 case BROADCOM_DEV_ID_57508:
4483 case BROADCOM_DEV_ID_57504:
4484 case BROADCOM_DEV_ID_57502:
4485 case BROADCOM_DEV_ID_57508_MF1:
4486 case BROADCOM_DEV_ID_57504_MF1:
4487 case BROADCOM_DEV_ID_57502_MF1:
4488 case BROADCOM_DEV_ID_57508_MF2:
4489 case BROADCOM_DEV_ID_57504_MF2:
4490 case BROADCOM_DEV_ID_57502_MF2:
4491 case BROADCOM_DEV_ID_57500_VF1:
4492 case BROADCOM_DEV_ID_57500_VF2:
4500 bool bnxt_stratus_device(struct bnxt *bp)
4502 uint16_t device_id = bp->pdev->id.device_id;
4504 switch (device_id) {
4505 case BROADCOM_DEV_ID_STRATUS_NIC:
4506 case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
4507 case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
4515 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
4517 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
4518 struct bnxt *bp = eth_dev->data->dev_private;
4520 /* enable device (incl. PCI PM wakeup), and bus-mastering */
4521 bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
4522 bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
4523 if (!bp->bar0 || !bp->doorbell_base) {
4524 PMD_DRV_LOG(ERR, "Unable to access Hardware\n");
4528 bp->eth_dev = eth_dev;
4534 static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
4535 struct bnxt_ctx_pg_info *ctx_pg,
4540 struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
4541 const struct rte_memzone *mz = NULL;
4542 char mz_name[RTE_MEMZONE_NAMESIZE];
4543 rte_iova_t mz_phys_addr;
4544 uint64_t valid_bits = 0;
4551 rmem->nr_pages = RTE_ALIGN_MUL_CEIL(mem_size, BNXT_PAGE_SIZE) /
4553 rmem->page_size = BNXT_PAGE_SIZE;
4554 rmem->pg_arr = ctx_pg->ctx_pg_arr;
4555 rmem->dma_arr = ctx_pg->ctx_dma_arr;
4556 rmem->flags = BNXT_RMEM_VALID_PTE_FLAG;
4558 valid_bits = PTU_PTE_VALID;
4560 if (rmem->nr_pages > 1) {
4561 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
4562 "bnxt_ctx_pg_tbl%s_%x_%d",
4563 suffix, idx, bp->eth_dev->data->port_id);
4564 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
4565 mz = rte_memzone_lookup(mz_name);
4567 mz = rte_memzone_reserve_aligned(mz_name,
4571 RTE_MEMZONE_SIZE_HINT_ONLY |
4572 RTE_MEMZONE_IOVA_CONTIG,
4578 memset(mz->addr, 0, mz->len);
4579 mz_phys_addr = mz->iova;
4581 rmem->pg_tbl = mz->addr;
4582 rmem->pg_tbl_map = mz_phys_addr;
4583 rmem->pg_tbl_mz = mz;
4586 snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_%s_%x_%d",
4587 suffix, idx, bp->eth_dev->data->port_id);
4588 mz = rte_memzone_lookup(mz_name);
4590 mz = rte_memzone_reserve_aligned(mz_name,
4594 RTE_MEMZONE_SIZE_HINT_ONLY |
4595 RTE_MEMZONE_IOVA_CONTIG,
4601 memset(mz->addr, 0, mz->len);
4602 mz_phys_addr = mz->iova;
4604 for (sz = 0, i = 0; sz < mem_size; sz += BNXT_PAGE_SIZE, i++) {
4605 rmem->pg_arr[i] = ((char *)mz->addr) + sz;
4606 rmem->dma_arr[i] = mz_phys_addr + sz;
4608 if (rmem->nr_pages > 1) {
4609 if (i == rmem->nr_pages - 2 &&
4610 (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
4611 valid_bits |= PTU_PTE_NEXT_TO_LAST;
4612 else if (i == rmem->nr_pages - 1 &&
4613 (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
4614 valid_bits |= PTU_PTE_LAST;
4616 rmem->pg_tbl[i] = rte_cpu_to_le_64(rmem->dma_arr[i] |
4622 if (rmem->vmem_size)
4623 rmem->vmem = (void **)mz->addr;
4624 rmem->dma_arr[0] = mz_phys_addr;
4628 static void bnxt_free_ctx_mem(struct bnxt *bp)
4632 if (!bp->ctx || !(bp->ctx->flags & BNXT_CTX_FLAG_INITED))
4635 bp->ctx->flags &= ~BNXT_CTX_FLAG_INITED;
4636 rte_memzone_free(bp->ctx->qp_mem.ring_mem.mz);
4637 rte_memzone_free(bp->ctx->srq_mem.ring_mem.mz);
4638 rte_memzone_free(bp->ctx->cq_mem.ring_mem.mz);
4639 rte_memzone_free(bp->ctx->vnic_mem.ring_mem.mz);
4640 rte_memzone_free(bp->ctx->stat_mem.ring_mem.mz);
4641 rte_memzone_free(bp->ctx->qp_mem.ring_mem.pg_tbl_mz);
4642 rte_memzone_free(bp->ctx->srq_mem.ring_mem.pg_tbl_mz);
4643 rte_memzone_free(bp->ctx->cq_mem.ring_mem.pg_tbl_mz);
4644 rte_memzone_free(bp->ctx->vnic_mem.ring_mem.pg_tbl_mz);
4645 rte_memzone_free(bp->ctx->stat_mem.ring_mem.pg_tbl_mz);
4647 for (i = 0; i < BNXT_MAX_Q; i++) {
4648 if (bp->ctx->tqm_mem[i])
4649 rte_memzone_free(bp->ctx->tqm_mem[i]->ring_mem.mz);
4656 #define bnxt_roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
4658 #define min_t(type, x, y) ({ \
4659 type __min1 = (x); \
4660 type __min2 = (y); \
4661 __min1 < __min2 ? __min1 : __min2; })
4663 #define max_t(type, x, y) ({ \
4664 type __max1 = (x); \
4665 type __max2 = (y); \
4666 __max1 > __max2 ? __max1 : __max2; })
4668 #define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
4670 int bnxt_alloc_ctx_mem(struct bnxt *bp)
4672 struct bnxt_ctx_pg_info *ctx_pg;
4673 struct bnxt_ctx_mem_info *ctx;
4674 uint32_t mem_size, ena, entries;
4677 rc = bnxt_hwrm_func_backing_store_qcaps(bp);
4679 PMD_DRV_LOG(ERR, "Query context mem capability failed\n");
4683 if (!ctx || (ctx->flags & BNXT_CTX_FLAG_INITED))
4686 ctx_pg = &ctx->qp_mem;
4687 ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries;
4688 mem_size = ctx->qp_entry_size * ctx_pg->entries;
4689 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "qp_mem", 0);
4693 ctx_pg = &ctx->srq_mem;
4694 ctx_pg->entries = ctx->srq_max_l2_entries;
4695 mem_size = ctx->srq_entry_size * ctx_pg->entries;
4696 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "srq_mem", 0);
4700 ctx_pg = &ctx->cq_mem;
4701 ctx_pg->entries = ctx->cq_max_l2_entries;
4702 mem_size = ctx->cq_entry_size * ctx_pg->entries;
4703 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "cq_mem", 0);
4707 ctx_pg = &ctx->vnic_mem;
4708 ctx_pg->entries = ctx->vnic_max_vnic_entries +
4709 ctx->vnic_max_ring_table_entries;
4710 mem_size = ctx->vnic_entry_size * ctx_pg->entries;
4711 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "vnic_mem", 0);
4715 ctx_pg = &ctx->stat_mem;
4716 ctx_pg->entries = ctx->stat_max_entries;
4717 mem_size = ctx->stat_entry_size * ctx_pg->entries;
4718 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "stat_mem", 0);
4722 entries = ctx->qp_max_l2_entries +
4723 ctx->vnic_max_vnic_entries +
4724 ctx->tqm_min_entries_per_ring;
4725 entries = bnxt_roundup(entries, ctx->tqm_entries_multiple);
4726 entries = clamp_t(uint32_t, entries, ctx->tqm_min_entries_per_ring,
4727 ctx->tqm_max_entries_per_ring);
4728 for (i = 0, ena = 0; i < BNXT_MAX_Q; i++) {
4729 ctx_pg = ctx->tqm_mem[i];
4730 /* use min tqm entries for now. */
4731 ctx_pg->entries = entries;
4732 mem_size = ctx->tqm_entry_size * ctx_pg->entries;
4733 rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size, "tqm_mem", i);
4736 ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP << i;
4739 ena |= FUNC_BACKING_STORE_CFG_INPUT_DFLT_ENABLES;
4740 rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
4743 "Failed to configure context mem: rc = %d\n", rc);
4745 ctx->flags |= BNXT_CTX_FLAG_INITED;
4750 static int bnxt_alloc_stats_mem(struct bnxt *bp)
4752 struct rte_pci_device *pci_dev = bp->pdev;
4753 char mz_name[RTE_MEMZONE_NAMESIZE];
4754 const struct rte_memzone *mz = NULL;
4755 uint32_t total_alloc_len;
4756 rte_iova_t mz_phys_addr;
4758 if (pci_dev->id.device_id == BROADCOM_DEV_ID_NS2)
4761 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
4762 "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
4763 pci_dev->addr.bus, pci_dev->addr.devid,
4764 pci_dev->addr.function, "rx_port_stats");
4765 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
4766 mz = rte_memzone_lookup(mz_name);
4768 RTE_CACHE_LINE_ROUNDUP(sizeof(struct rx_port_stats) +
4769 sizeof(struct rx_port_stats_ext) + 512);
4771 mz = rte_memzone_reserve(mz_name, total_alloc_len,
4774 RTE_MEMZONE_SIZE_HINT_ONLY |
4775 RTE_MEMZONE_IOVA_CONTIG);
4779 memset(mz->addr, 0, mz->len);
4780 mz_phys_addr = mz->iova;
4782 bp->rx_mem_zone = (const void *)mz;
4783 bp->hw_rx_port_stats = mz->addr;
4784 bp->hw_rx_port_stats_map = mz_phys_addr;
4786 snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
4787 "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
4788 pci_dev->addr.bus, pci_dev->addr.devid,
4789 pci_dev->addr.function, "tx_port_stats");
4790 mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
4791 mz = rte_memzone_lookup(mz_name);
4793 RTE_CACHE_LINE_ROUNDUP(sizeof(struct tx_port_stats) +
4794 sizeof(struct tx_port_stats_ext) + 512);
4796 mz = rte_memzone_reserve(mz_name,
4800 RTE_MEMZONE_SIZE_HINT_ONLY |
4801 RTE_MEMZONE_IOVA_CONTIG);
4805 memset(mz->addr, 0, mz->len);
4806 mz_phys_addr = mz->iova;
4808 bp->tx_mem_zone = (const void *)mz;
4809 bp->hw_tx_port_stats = mz->addr;
4810 bp->hw_tx_port_stats_map = mz_phys_addr;
4811 bp->flags |= BNXT_FLAG_PORT_STATS;
4813 /* Display extended statistics if FW supports it */
4814 if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
4815 bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0 ||
4816 !(bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED))
4819 bp->hw_rx_port_stats_ext = (void *)
4820 ((uint8_t *)bp->hw_rx_port_stats +
4821 sizeof(struct rx_port_stats));
4822 bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
4823 sizeof(struct rx_port_stats);
4824 bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
4826 if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2 ||
4827 bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED) {
4828 bp->hw_tx_port_stats_ext = (void *)
4829 ((uint8_t *)bp->hw_tx_port_stats +
4830 sizeof(struct tx_port_stats));
4831 bp->hw_tx_port_stats_ext_map =
4832 bp->hw_tx_port_stats_map +
4833 sizeof(struct tx_port_stats);
4834 bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
4840 static int bnxt_setup_mac_addr(struct rte_eth_dev *eth_dev)
4842 struct bnxt *bp = eth_dev->data->dev_private;
4845 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
4846 RTE_ETHER_ADDR_LEN *
4849 if (eth_dev->data->mac_addrs == NULL) {
4850 PMD_DRV_LOG(ERR, "Failed to alloc MAC addr tbl\n");
4854 if (bnxt_check_zero_bytes(bp->dflt_mac_addr, RTE_ETHER_ADDR_LEN)) {
4858 /* Generate a random MAC address, if none was assigned by PF */
4859 PMD_DRV_LOG(INFO, "VF MAC address not assigned by Host PF\n");
4860 bnxt_eth_hw_addr_random(bp->mac_addr);
4862 "Assign random MAC:%02X:%02X:%02X:%02X:%02X:%02X\n",
4863 bp->mac_addr[0], bp->mac_addr[1], bp->mac_addr[2],
4864 bp->mac_addr[3], bp->mac_addr[4], bp->mac_addr[5]);
4866 rc = bnxt_hwrm_set_mac(bp);
4868 memcpy(&bp->eth_dev->data->mac_addrs[0], bp->mac_addr,
4869 RTE_ETHER_ADDR_LEN);
4873 /* Copy the permanent MAC from the FUNC_QCAPS response */
4874 memcpy(bp->mac_addr, bp->dflt_mac_addr, RTE_ETHER_ADDR_LEN);
4875 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, RTE_ETHER_ADDR_LEN);
4880 static int bnxt_restore_dflt_mac(struct bnxt *bp)
4884 /* MAC is already configured in FW */
4885 if (!bnxt_check_zero_bytes(bp->dflt_mac_addr, RTE_ETHER_ADDR_LEN))
4888 /* Restore the old MAC configured */
4889 rc = bnxt_hwrm_set_mac(bp);
4891 PMD_DRV_LOG(ERR, "Failed to restore MAC address\n");
4896 static void bnxt_config_vf_req_fwd(struct bnxt *bp)
4901 #define ALLOW_FUNC(x) \
4903 uint32_t arg = (x); \
4904 bp->pf.vf_req_fwd[((arg) >> 5)] &= \
4905 ~rte_cpu_to_le_32(1 << ((arg) & 0x1f)); \
4908 /* Forward all requests if firmware is new enough */
4909 if (((bp->fw_ver >= ((20 << 24) | (6 << 16) | (100 << 8))) &&
4910 (bp->fw_ver < ((20 << 24) | (7 << 16)))) ||
4911 ((bp->fw_ver >= ((20 << 24) | (8 << 16))))) {
4912 memset(bp->pf.vf_req_fwd, 0xff, sizeof(bp->pf.vf_req_fwd));
4914 PMD_DRV_LOG(WARNING,
4915 "Firmware too old for VF mailbox functionality\n");
4916 memset(bp->pf.vf_req_fwd, 0, sizeof(bp->pf.vf_req_fwd));
4920 * The following are used for driver cleanup. If we disallow these,
4921 * VF drivers can't clean up cleanly.
4923 ALLOW_FUNC(HWRM_FUNC_DRV_UNRGTR);
4924 ALLOW_FUNC(HWRM_VNIC_FREE);
4925 ALLOW_FUNC(HWRM_RING_FREE);
4926 ALLOW_FUNC(HWRM_RING_GRP_FREE);
4927 ALLOW_FUNC(HWRM_VNIC_RSS_COS_LB_CTX_FREE);
4928 ALLOW_FUNC(HWRM_CFA_L2_FILTER_FREE);
4929 ALLOW_FUNC(HWRM_STAT_CTX_FREE);
4930 ALLOW_FUNC(HWRM_PORT_PHY_QCFG);
4931 ALLOW_FUNC(HWRM_VNIC_TPA_CFG);
4935 bnxt_get_svif(uint16_t port_id, bool func_svif)
4937 struct rte_eth_dev *eth_dev;
4940 eth_dev = &rte_eth_devices[port_id];
4941 bp = eth_dev->data->dev_private;
4943 return func_svif ? bp->func_svif : bp->port_svif;
4947 bnxt_get_vnic_id(uint16_t port)
4949 struct rte_eth_dev *eth_dev;
4950 struct bnxt_vnic_info *vnic;
4953 eth_dev = &rte_eth_devices[port];
4954 bp = eth_dev->data->dev_private;
4956 vnic = BNXT_GET_DEFAULT_VNIC(bp);
4958 return vnic->fw_vnic_id;
4962 bnxt_get_fw_func_id(uint16_t port)
4964 struct rte_eth_dev *eth_dev;
4967 eth_dev = &rte_eth_devices[port];
4968 bp = eth_dev->data->dev_private;
4973 static void bnxt_alloc_error_recovery_info(struct bnxt *bp)
4975 struct bnxt_error_recovery_info *info = bp->recovery_info;
4978 if (!(bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS))
4979 memset(info, 0, sizeof(*info));
4983 if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
4986 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
4989 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
4991 bp->recovery_info = info;
4994 static void bnxt_check_fw_status(struct bnxt *bp)
4998 if (!(bp->recovery_info &&
4999 (bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS)))
5002 fw_status = bnxt_read_fw_status_reg(bp, BNXT_FW_STATUS_REG);
5003 if (fw_status != BNXT_FW_STATUS_HEALTHY)
5004 PMD_DRV_LOG(ERR, "Firmware not responding, status: %#x\n",
5008 static int bnxt_map_hcomm_fw_status_reg(struct bnxt *bp)
5010 struct bnxt_error_recovery_info *info = bp->recovery_info;
5011 uint32_t status_loc;
5014 rte_write32(HCOMM_STATUS_STRUCT_LOC, (uint8_t *)bp->bar0 +
5015 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5016 sig_ver = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5017 BNXT_GRCP_WINDOW_2_BASE +
5018 offsetof(struct hcomm_status,
5020 /* If the signature is absent, then FW does not support this feature */
5021 if ((sig_ver & HCOMM_STATUS_SIGNATURE_MASK) !=
5022 HCOMM_STATUS_SIGNATURE_VAL)
5026 info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5030 bp->recovery_info = info;
5032 memset(info, 0, sizeof(*info));
5035 status_loc = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5036 BNXT_GRCP_WINDOW_2_BASE +
5037 offsetof(struct hcomm_status,
5040 /* Only pre-map the FW health status GRC register */
5041 if (BNXT_FW_STATUS_REG_TYPE(status_loc) != BNXT_FW_STATUS_REG_TYPE_GRC)
5044 info->status_regs[BNXT_FW_STATUS_REG] = status_loc;
5045 info->mapped_status_regs[BNXT_FW_STATUS_REG] =
5046 BNXT_GRCP_WINDOW_2_BASE + (status_loc & BNXT_GRCP_OFFSET_MASK);
5048 rte_write32((status_loc & BNXT_GRCP_BASE_MASK), (uint8_t *)bp->bar0 +
5049 BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5051 bp->fw_cap |= BNXT_FW_CAP_HCOMM_FW_STATUS;
5056 static int bnxt_init_fw(struct bnxt *bp)
5063 rc = bnxt_map_hcomm_fw_status_reg(bp);
5067 rc = bnxt_hwrm_ver_get(bp, DFLT_HWRM_CMD_TIMEOUT);
5069 bnxt_check_fw_status(bp);
5073 rc = bnxt_hwrm_func_reset(bp);
5077 rc = bnxt_hwrm_vnic_qcaps(bp);
5081 rc = bnxt_hwrm_queue_qportcfg(bp);
5085 /* Get the MAX capabilities for this function.
5086 * This function also allocates context memory for TQM rings and
5087 * informs the firmware about this allocated backing store memory.
5089 rc = bnxt_hwrm_func_qcaps(bp);
5093 rc = bnxt_hwrm_func_qcfg(bp, &mtu);
5097 bnxt_hwrm_port_mac_qcfg(bp);
5099 rc = bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(bp);
5103 bnxt_alloc_error_recovery_info(bp);
5104 /* Get the adapter error recovery support info */
5105 rc = bnxt_hwrm_error_recovery_qcfg(bp);
5107 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5109 bnxt_hwrm_port_led_qcaps(bp);
5115 bnxt_init_locks(struct bnxt *bp)
5119 err = pthread_mutex_init(&bp->flow_lock, NULL);
5121 PMD_DRV_LOG(ERR, "Unable to initialize flow_lock\n");
5125 err = pthread_mutex_init(&bp->def_cp_lock, NULL);
5127 PMD_DRV_LOG(ERR, "Unable to initialize def_cp_lock\n");
5131 static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
5135 rc = bnxt_init_fw(bp);
5139 if (!reconfig_dev) {
5140 rc = bnxt_setup_mac_addr(bp->eth_dev);
5144 rc = bnxt_restore_dflt_mac(bp);
5149 bnxt_config_vf_req_fwd(bp);
5151 rc = bnxt_hwrm_func_driver_register(bp);
5153 PMD_DRV_LOG(ERR, "Failed to register driver");
5158 if (bp->pdev->max_vfs) {
5159 rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
5161 PMD_DRV_LOG(ERR, "Failed to allocate VFs\n");
5165 rc = bnxt_hwrm_allocate_pf_only(bp);
5168 "Failed to allocate PF resources");
5174 rc = bnxt_alloc_mem(bp, reconfig_dev);
5178 rc = bnxt_setup_int(bp);
5182 rc = bnxt_request_int(bp);
5186 rc = bnxt_init_ctx_mem(bp);
5188 PMD_DRV_LOG(ERR, "Failed to init adv_flow_counters\n");
5192 rc = bnxt_init_locks(bp);
5200 bnxt_parse_devarg_truflow(__rte_unused const char *key,
5201 const char *value, void *opaque_arg)
5203 struct bnxt *bp = opaque_arg;
5204 unsigned long truflow;
5207 if (!value || !opaque_arg) {
5209 "Invalid parameter passed to truflow devargs.\n");
5213 truflow = strtoul(value, &end, 10);
5214 if (end == NULL || *end != '\0' ||
5215 (truflow == ULONG_MAX && errno == ERANGE)) {
5217 "Invalid parameter passed to truflow devargs.\n");
5221 if (BNXT_DEVARG_TRUFLOW_INVALID(truflow)) {
5223 "Invalid value passed to truflow devargs.\n");
5227 bp->truflow = truflow;
5229 PMD_DRV_LOG(INFO, "Host-based truflow feature enabled.\n");
5235 bnxt_parse_devarg_flow_xstat(__rte_unused const char *key,
5236 const char *value, void *opaque_arg)
5238 struct bnxt *bp = opaque_arg;
5239 unsigned long flow_xstat;
5242 if (!value || !opaque_arg) {
5244 "Invalid parameter passed to flow_xstat devarg.\n");
5248 flow_xstat = strtoul(value, &end, 10);
5249 if (end == NULL || *end != '\0' ||
5250 (flow_xstat == ULONG_MAX && errno == ERANGE)) {
5252 "Invalid parameter passed to flow_xstat devarg.\n");
5256 if (BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat)) {
5258 "Invalid value passed to flow_xstat devarg.\n");
5262 bp->flow_xstat = flow_xstat;
5264 PMD_DRV_LOG(INFO, "flow_xstat feature enabled.\n");
5270 bnxt_parse_dev_args(struct bnxt *bp, struct rte_devargs *devargs)
5272 struct rte_kvargs *kvlist;
5274 if (devargs == NULL)
5277 kvlist = rte_kvargs_parse(devargs->args, bnxt_dev_args);
5282 * Handler for "truflow" devarg.
5283 * Invoked as for ex: "-w 0000:00:0d.0,host-based-truflow=1”
5285 rte_kvargs_process(kvlist, BNXT_DEVARG_TRUFLOW,
5286 bnxt_parse_devarg_truflow, bp);
5289 * Handler for "flow_xstat" devarg.
5290 * Invoked as for ex: "-w 0000:00:0d.0,flow_xstat=1”
5292 rte_kvargs_process(kvlist, BNXT_DEVARG_FLOW_XSTAT,
5293 bnxt_parse_devarg_flow_xstat, bp);
5295 rte_kvargs_free(kvlist);
5299 bnxt_dev_init(struct rte_eth_dev *eth_dev)
5301 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
5302 static int version_printed;
5306 if (version_printed++ == 0)
5307 PMD_DRV_LOG(INFO, "%s\n", bnxt_version);
5309 eth_dev->dev_ops = &bnxt_dev_ops;
5310 eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
5311 eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
5314 * For secondary processes, we don't initialise any further
5315 * as primary has already done this work.
5317 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5320 rte_eth_copy_pci_info(eth_dev, pci_dev);
5322 bp = eth_dev->data->dev_private;
5324 /* Parse dev arguments passed on when starting the DPDK application. */
5325 bnxt_parse_dev_args(bp, pci_dev->device.devargs);
5327 bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
5329 if (bnxt_vf_pciid(pci_dev->id.device_id))
5330 bp->flags |= BNXT_FLAG_VF;
5332 if (bnxt_thor_device(pci_dev->id.device_id))
5333 bp->flags |= BNXT_FLAG_THOR_CHIP;
5335 if (pci_dev->id.device_id == BROADCOM_DEV_ID_58802 ||
5336 pci_dev->id.device_id == BROADCOM_DEV_ID_58804 ||
5337 pci_dev->id.device_id == BROADCOM_DEV_ID_58808 ||
5338 pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
5339 bp->flags |= BNXT_FLAG_STINGRAY;
5341 rc = bnxt_init_board(eth_dev);
5344 "Failed to initialize board rc: %x\n", rc);
5348 rc = bnxt_alloc_hwrm_resources(bp);
5351 "Failed to allocate hwrm resource rc: %x\n", rc);
5354 rc = bnxt_init_resources(bp, false);
5358 rc = bnxt_alloc_stats_mem(bp);
5362 /* Pass the information to the rte_eth_dev_close() that it should also
5363 * release the private port resources.
5365 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
5368 DRV_MODULE_NAME "found at mem %" PRIX64 ", node addr %pM\n",
5369 pci_dev->mem_resource[0].phys_addr,
5370 pci_dev->mem_resource[0].addr);
5375 bnxt_dev_uninit(eth_dev);
5380 static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
5389 ctx->dma = RTE_BAD_IOVA;
5390 ctx->ctx_id = BNXT_CTX_VAL_INVAL;
5393 static void bnxt_unregister_fc_ctx_mem(struct bnxt *bp)
5395 bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
5396 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
5397 bp->rx_fc_out_tbl.ctx_id,
5401 bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
5402 CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
5403 bp->tx_fc_out_tbl.ctx_id,
5407 if (bp->rx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5408 bnxt_hwrm_ctx_unrgtr(bp, bp->rx_fc_in_tbl.ctx_id);
5409 bp->rx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5411 if (bp->rx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5412 bnxt_hwrm_ctx_unrgtr(bp, bp->rx_fc_out_tbl.ctx_id);
5413 bp->rx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5415 if (bp->tx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5416 bnxt_hwrm_ctx_unrgtr(bp, bp->tx_fc_in_tbl.ctx_id);
5417 bp->tx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5419 if (bp->tx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
5420 bnxt_hwrm_ctx_unrgtr(bp, bp->tx_fc_out_tbl.ctx_id);
5421 bp->tx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
5424 static void bnxt_uninit_fc_ctx_mem(struct bnxt *bp)
5426 bnxt_unregister_fc_ctx_mem(bp);
5428 bnxt_free_ctx_mem_buf(&bp->rx_fc_in_tbl);
5429 bnxt_free_ctx_mem_buf(&bp->rx_fc_out_tbl);
5430 bnxt_free_ctx_mem_buf(&bp->tx_fc_in_tbl);
5431 bnxt_free_ctx_mem_buf(&bp->tx_fc_out_tbl);
5434 static void bnxt_uninit_ctx_mem(struct bnxt *bp)
5436 bnxt_uninit_fc_ctx_mem(bp);
5440 bnxt_free_error_recovery_info(struct bnxt *bp)
5442 rte_free(bp->recovery_info);
5443 bp->recovery_info = NULL;
5444 bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5448 bnxt_uninit_locks(struct bnxt *bp)
5450 pthread_mutex_destroy(&bp->flow_lock);
5451 pthread_mutex_destroy(&bp->def_cp_lock);
5455 bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
5460 bnxt_free_mem(bp, reconfig_dev);
5461 bnxt_hwrm_func_buf_unrgtr(bp);
5462 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
5463 bp->flags &= ~BNXT_FLAG_REGISTERED;
5464 bnxt_free_ctx_mem(bp);
5465 if (!reconfig_dev) {
5466 bnxt_free_hwrm_resources(bp);
5467 bnxt_free_error_recovery_info(bp);
5470 bnxt_uninit_ctx_mem(bp);
5472 bnxt_uninit_locks(bp);
5473 rte_free(bp->ptp_cfg);
5479 bnxt_dev_uninit(struct rte_eth_dev *eth_dev)
5481 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5484 PMD_DRV_LOG(DEBUG, "Calling Device uninit\n");
5486 if (eth_dev->state != RTE_ETH_DEV_UNUSED)
5487 bnxt_dev_close_op(eth_dev);
5492 static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
5493 struct rte_pci_device *pci_dev)
5495 return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct bnxt),
5499 static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
5501 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
5502 return rte_eth_dev_pci_generic_remove(pci_dev,
5505 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
5508 static struct rte_pci_driver bnxt_rte_pmd = {
5509 .id_table = bnxt_pci_id_map,
5510 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
5511 .probe = bnxt_pci_probe,
5512 .remove = bnxt_pci_remove,
5516 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
5518 if (strcmp(dev->device->driver->name, drv->driver.name))
5524 bool is_bnxt_supported(struct rte_eth_dev *dev)
5526 return is_device_supported(dev, &bnxt_rte_pmd);
5529 RTE_INIT(bnxt_init_log)
5531 bnxt_logtype_driver = rte_log_register("pmd.net.bnxt.driver");
5532 if (bnxt_logtype_driver >= 0)
5533 rte_log_set_level(bnxt_logtype_driver, RTE_LOG_NOTICE);
5536 RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
5537 RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
5538 RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");