bnxt_irq.c revision 6b3e017e
1/*-
2 *   BSD LICENSE
3 *
4 *   Copyright(c) 2014-2015 Broadcom Corporation.
5 *   All rights reserved.
6 *
7 *   Redistribution and use in source and binary forms, with or without
8 *   modification, are permitted provided that the following conditions
9 *   are met:
10 *
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
16 *       distribution.
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.
20 *
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.
32 */
33
34#include <inttypes.h>
35
36#include <rte_malloc.h>
37
38#include "bnxt.h"
39#include "bnxt_cpr.h"
40#include "bnxt_irq.h"
41#include "bnxt_ring.h"
42#include "hsi_struct_def_dpdk.h"
43
44/*
45 * Interrupts
46 */
47
48static void bnxt_int_handler(struct rte_intr_handle *handle __rte_unused,
49			     void *param)
50{
51	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
52	struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
53	struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
54	uint32_t raw_cons = cpr->cp_raw_cons;
55	uint32_t cons;
56	struct cmpl_base *cmp;
57
58	while (1) {
59		cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
60		cmp = &cpr->cp_desc_ring[cons];
61
62		if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
63			break;
64
65		switch (CMP_TYPE(cmp)) {
66		case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
67			/* Handle any async event */
68			bnxt_handle_async_event(bp, cmp);
69			break;
70		case CMPL_BASE_TYPE_HWRM_FWD_RESP:
71			/* Handle HWRM forwarded responses */
72			bnxt_handle_fwd_req(bp, cmp);
73			break;
74		default:
75			/* Ignore any other events */
76			break;
77		}
78		raw_cons = NEXT_RAW_CMP(raw_cons);
79	}
80	B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
81}
82
83void bnxt_free_int(struct bnxt *bp)
84{
85	struct bnxt_irq *irq;
86
87	irq = bp->irq_tbl;
88	if (irq) {
89		if (irq->requested) {
90			rte_intr_disable(&bp->pdev->intr_handle);
91			rte_intr_callback_unregister(&bp->pdev->intr_handle,
92						     irq->handler,
93						     (void *)bp->eth_dev);
94			irq->requested = 0;
95		}
96		rte_free((void *)bp->irq_tbl);
97		bp->irq_tbl = NULL;
98	}
99}
100
101void bnxt_disable_int(struct bnxt *bp)
102{
103	struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
104
105	/* Only the default completion ring */
106	B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
107}
108
109void bnxt_enable_int(struct bnxt *bp)
110{
111	struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
112
113	B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
114}
115
116int bnxt_setup_int(struct bnxt *bp)
117{
118	uint16_t total_vecs;
119	const int len = sizeof(bp->irq_tbl[0].name);
120	int i, rc = 0;
121
122	/* DPDK host only supports 1 MSI-X vector */
123	total_vecs = 1;
124	bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
125				 sizeof(struct bnxt_irq), 0);
126	if (bp->irq_tbl) {
127		for (i = 0; i < total_vecs; i++) {
128			bp->irq_tbl[i].vector = i;
129			snprintf(bp->irq_tbl[i].name, len,
130				 "%s-%d", bp->eth_dev->data->name, i);
131			bp->irq_tbl[i].handler = bnxt_int_handler;
132		}
133	} else {
134		rc = -ENOMEM;
135		goto setup_exit;
136	}
137	return 0;
138
139setup_exit:
140	RTE_LOG(ERR, PMD, "bnxt_irq_tbl setup failed");
141	return rc;
142}
143
144int bnxt_request_int(struct bnxt *bp)
145{
146	int rc = 0;
147
148	struct bnxt_irq *irq = bp->irq_tbl;
149
150	rte_intr_callback_register(&bp->pdev->intr_handle, irq->handler,
151				   (void *)bp->eth_dev);
152	rte_intr_enable(&bp->pdev->intr_handle);
153
154	irq->requested = 1;
155	return rc;
156}
157