1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 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 = bp->async_cp_ring;
25 struct cmpl_base *cmp;
32 raw_cons = cpr->cp_raw_cons;
33 pthread_mutex_lock(&bp->def_cp_lock);
35 if (!cpr || !cpr->cp_ring_struct || !cpr->cp_db.doorbell) {
36 pthread_mutex_unlock(&bp->def_cp_lock);
40 if (is_bnxt_in_error(bp)) {
41 pthread_mutex_unlock(&bp->def_cp_lock);
45 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
46 cmp = &cpr->cp_desc_ring[cons];
48 if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
51 bnxt_event_hwrm_resp_handler(bp, cmp);
52 raw_cons = NEXT_RAW_CMP(raw_cons);
55 cpr->cp_raw_cons = raw_cons;
59 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
61 pthread_mutex_unlock(&bp->def_cp_lock);
64 int bnxt_free_int(struct bnxt *bp)
66 struct rte_intr_handle *intr_handle = &bp->pdev->intr_handle;
67 struct bnxt_irq *irq = bp->irq_tbl;
77 * Callback deregistration will fail with rc -EAGAIN if the
78 * callback is currently active. Retry every 50 ms until
79 * successful or 500 ms has elapsed.
82 rc = rte_intr_callback_unregister(intr_handle,
90 } while (count++ < 10);
93 PMD_DRV_LOG(ERR, "irq cb unregister failed rc: %d\n",
99 rte_free(bp->irq_tbl);
105 void bnxt_disable_int(struct bnxt *bp)
107 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
109 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
112 if (is_bnxt_in_error(bp))
115 if (!cpr || !cpr->cp_db.doorbell)
118 /* Only the default completion ring */
125 void bnxt_enable_int(struct bnxt *bp)
127 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
129 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
132 if (!cpr || !cpr->cp_db.doorbell)
135 /* Only the default completion ring */
142 int bnxt_setup_int(struct bnxt *bp)
145 const int len = sizeof(bp->irq_tbl[0].name);
148 /* DPDK host only supports 1 MSI-X vector */
150 bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
151 sizeof(struct bnxt_irq), 0);
153 for (i = 0; i < total_vecs; i++) {
154 bp->irq_tbl[i].vector = i;
155 snprintf(bp->irq_tbl[i].name, len,
156 "%s-%d", bp->eth_dev->device->name, i);
157 bp->irq_tbl[i].handler = bnxt_int_handler;
160 PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
167 int bnxt_request_int(struct bnxt *bp)
169 struct rte_intr_handle *intr_handle = &bp->pdev->intr_handle;
170 struct bnxt_irq *irq = bp->irq_tbl;
176 if (!irq->requested) {
177 rc = rte_intr_callback_register(intr_handle,
184 #ifdef RTE_EXEC_ENV_FREEBSD
186 * In FreeBSD OS, nic_uio does not support interrupts and
187 * interrupt register callback will fail.