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 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
41 cmp = &cpr->cp_desc_ring[cons];
43 if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
46 bnxt_event_hwrm_resp_handler(bp, cmp);
47 raw_cons = NEXT_RAW_CMP(raw_cons);
50 cpr->cp_raw_cons = raw_cons;
54 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
56 pthread_mutex_unlock(&bp->def_cp_lock);
59 int bnxt_free_int(struct bnxt *bp)
61 struct rte_intr_handle *intr_handle = &bp->pdev->intr_handle;
62 struct bnxt_irq *irq = bp->irq_tbl;
72 * Callback deregistration will fail with rc -EAGAIN if the
73 * callback is currently active. Retry every 50 ms until
74 * successful or 500 ms has elapsed.
77 rc = rte_intr_callback_unregister(intr_handle,
85 } while (count++ < 10);
88 PMD_DRV_LOG(ERR, "irq cb unregister failed rc: %d\n",
94 rte_free(bp->irq_tbl);
100 void bnxt_disable_int(struct bnxt *bp)
102 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
104 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
107 if (!cpr || !cpr->cp_db.doorbell)
110 /* Only the default completion ring */
117 void bnxt_enable_int(struct bnxt *bp)
119 struct bnxt_cp_ring_info *cpr = bp->async_cp_ring;
121 if (BNXT_NUM_ASYNC_CPR(bp) == 0)
124 if (!cpr || !cpr->cp_db.doorbell)
127 /* Only the default completion ring */
134 int bnxt_setup_int(struct bnxt *bp)
137 const int len = sizeof(bp->irq_tbl[0].name);
140 /* DPDK host only supports 1 MSI-X vector */
142 bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
143 sizeof(struct bnxt_irq), 0);
145 for (i = 0; i < total_vecs; i++) {
146 bp->irq_tbl[i].vector = i;
147 snprintf(bp->irq_tbl[i].name, len,
148 "%s-%d", bp->eth_dev->device->name, i);
149 bp->irq_tbl[i].handler = bnxt_int_handler;
152 PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
159 int bnxt_request_int(struct bnxt *bp)
161 struct rte_intr_handle *intr_handle = &bp->pdev->intr_handle;
162 struct bnxt_irq *irq = bp->irq_tbl;
168 if (!irq->requested) {
169 rc = rte_intr_callback_register(intr_handle,