1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
8 #include <rte_cycles.h>
9 #include <rte_malloc.h>
13 #include "bnxt_ring.h"
14 #include "hsi_struct_def_dpdk.h"
20 void bnxt_int_handler(void *param)
22 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
23 struct bnxt *bp = eth_dev->data->dev_private;
24 uint32_t cons, raw_cons, cp_ring_size;
25 struct bnxt_cp_ring_info *cpr;
26 struct cmpl_base *cmp;
31 cpr = bp->async_cp_ring;
35 raw_cons = cpr->cp_raw_cons;
36 pthread_mutex_lock(&bp->def_cp_lock);
38 if (!cpr || !cpr->cp_ring_struct || !cpr->cp_db.doorbell) {
39 pthread_mutex_unlock(&bp->def_cp_lock);
43 if (is_bnxt_in_error(bp)) {
44 pthread_mutex_unlock(&bp->def_cp_lock);
48 cp_ring_size = cpr->cp_ring_struct->ring_size;
49 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
50 cmp = &cpr->cp_desc_ring[cons];
52 if (!bnxt_cpr_cmp_valid(cmp, raw_cons, cp_ring_size))
55 bnxt_event_hwrm_resp_handler(bp, cmp);
56 raw_cons = NEXT_RAW_CMP(raw_cons);
59 cpr->cp_raw_cons = raw_cons;
63 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
65 pthread_mutex_unlock(&bp->def_cp_lock);
68 int bnxt_free_int(struct bnxt *bp)
70 struct rte_intr_handle *intr_handle = bp->pdev->intr_handle;
71 struct bnxt_irq *irq = bp->irq_tbl;
81 * Callback deregistration will fail with rc -EAGAIN if the
82 * callback is currently active. Retry every 50 ms until
83 * successful or 500 ms has elapsed.
86 rc = rte_intr_callback_unregister(intr_handle,
94 } while (count++ < 10);
97 PMD_DRV_LOG(ERR, "irq cb unregister failed rc: %d\n",
103 rte_free(bp->irq_tbl);
109 void bnxt_disable_int(struct bnxt *bp)
111 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
113 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
116 if (is_bnxt_in_error(bp))
119 if (!cpr || !cpr->cp_db.doorbell)
122 /* Only the default completion ring */
129 void bnxt_enable_int(struct bnxt *bp)
131 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
133 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
136 if (!cpr || !cpr->cp_db.doorbell)
139 /* Only the default completion ring */
146 int bnxt_setup_int(struct bnxt *bp)
149 const int len = sizeof(bp->irq_tbl[0].name);
152 /* DPDK host only supports 1 MSI-X vector */
154 bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
155 sizeof(struct bnxt_irq), 0);
157 for (i = 0; i < total_vecs; i++) {
158 bp->irq_tbl[i].vector_idx = i;
159 snprintf(bp->irq_tbl[i].name, len,
160 "%s-%d", bp->eth_dev->device->name, i);
161 bp->irq_tbl[i].handler = bnxt_int_handler;
164 PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
171 int bnxt_request_int(struct bnxt *bp)
173 struct rte_intr_handle *intr_handle = bp->pdev->intr_handle;
174 struct bnxt_irq *irq = bp->irq_tbl;
180 if (!irq->requested) {
181 rc = rte_intr_callback_register(intr_handle,
188 #ifdef RTE_EXEC_ENV_FREEBSD
190 * In FreeBSD OS, nic_uio does not support interrupts and
191 * interrupt register callback will fail.