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 struct bnxt_cp_ring_info *cpr;
25 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 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
49 cmp = &cpr->cp_desc_ring[cons];
51 if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
54 bnxt_event_hwrm_resp_handler(bp, cmp);
55 raw_cons = NEXT_RAW_CMP(raw_cons);
58 cpr->cp_raw_cons = raw_cons;
62 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
64 pthread_mutex_unlock(&bp->def_cp_lock);
67 int bnxt_free_int(struct bnxt *bp)
69 struct rte_intr_handle *intr_handle = &bp->pdev->intr_handle;
70 struct bnxt_irq *irq = bp->irq_tbl;
80 * Callback deregistration will fail with rc -EAGAIN if the
81 * callback is currently active. Retry every 50 ms until
82 * successful or 500 ms has elapsed.
85 rc = rte_intr_callback_unregister(intr_handle,
93 } while (count++ < 10);
96 PMD_DRV_LOG(ERR, "irq cb unregister failed rc: %d\n",
102 rte_free(bp->irq_tbl);
108 void bnxt_disable_int(struct bnxt *bp)
110 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
112 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
115 if (is_bnxt_in_error(bp))
118 if (!cpr || !cpr->cp_db.doorbell)
121 /* Only the default completion ring */
128 void bnxt_enable_int(struct bnxt *bp)
130 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
132 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
135 if (!cpr || !cpr->cp_db.doorbell)
138 /* Only the default completion ring */
145 int bnxt_setup_int(struct bnxt *bp)
148 const int len = sizeof(bp->irq_tbl[0].name);
151 /* DPDK host only supports 1 MSI-X vector */
153 bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
154 sizeof(struct bnxt_irq), 0);
156 for (i = 0; i < total_vecs; i++) {
157 bp->irq_tbl[i].vector_idx = i;
158 snprintf(bp->irq_tbl[i].name, len,
159 "%s-%d", bp->eth_dev->device->name, i);
160 bp->irq_tbl[i].handler = bnxt_int_handler;
163 PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
170 int bnxt_request_int(struct bnxt *bp)
172 struct rte_intr_handle *intr_handle = &bp->pdev->intr_handle;
173 struct bnxt_irq *irq = bp->irq_tbl;
179 if (!irq->requested) {
180 rc = rte_intr_callback_register(intr_handle,
187 #ifdef RTE_EXEC_ENV_FREEBSD
189 * In FreeBSD OS, nic_uio does not support interrupts and
190 * interrupt register callback will fail.