4 * Copyright(c) 2014-2015 Broadcom Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_malloc.h>
41 #include "bnxt_ring.h"
42 #include "hsi_struct_def_dpdk.h"
48 static void bnxt_int_handler(void *param)
50 struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
51 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
52 struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
53 struct cmpl_base *cmp;
60 raw_cons = cpr->cp_raw_cons;
62 if (!cpr || !cpr->cp_ring_struct)
65 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
66 cmp = &cpr->cp_desc_ring[cons];
68 if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
71 switch (CMP_TYPE(cmp)) {
72 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
73 /* Handle any async event */
74 bnxt_handle_async_event(bp, cmp);
76 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
77 /* Handle HWRM forwarded responses */
78 bnxt_handle_fwd_req(bp, cmp);
81 /* Ignore any other events */
82 if (cmp->type & rte_cpu_to_le_16(0x01)) {
83 if (!CMP_VALID(cmp, raw_cons,
88 "Ignoring %02x completion\n", CMP_TYPE(cmp));
91 raw_cons = NEXT_RAW_CMP(raw_cons);
95 cpr->cp_raw_cons = raw_cons;
96 B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
99 void bnxt_free_int(struct bnxt *bp)
101 struct bnxt_irq *irq;
105 if (irq->requested) {
106 rte_intr_disable(&bp->pdev->intr_handle);
107 rte_intr_callback_unregister(&bp->pdev->intr_handle,
109 (void *)bp->eth_dev);
112 rte_free((void *)bp->irq_tbl);
117 void bnxt_disable_int(struct bnxt *bp)
119 struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
121 /* Only the default completion ring */
122 if (cpr != NULL && cpr->cp_doorbell != NULL)
126 void bnxt_enable_int(struct bnxt *bp)
128 struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
133 int bnxt_setup_int(struct bnxt *bp)
136 const int len = sizeof(bp->irq_tbl[0].name);
139 /* DPDK host only supports 1 MSI-X vector */
141 bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
142 sizeof(struct bnxt_irq), 0);
144 for (i = 0; i < total_vecs; i++) {
145 bp->irq_tbl[i].vector = i;
146 snprintf(bp->irq_tbl[i].name, len,
147 "%s-%d", bp->eth_dev->device->name, i);
148 bp->irq_tbl[i].handler = bnxt_int_handler;
157 PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
161 int bnxt_request_int(struct bnxt *bp)
165 struct bnxt_irq *irq = bp->irq_tbl;
167 rte_intr_callback_register(&bp->pdev->intr_handle, irq->handler,
168 (void *)bp->eth_dev);
169 rte_intr_enable(&bp->pdev->intr_handle);