ethdev: increase port id range
[dpdk.git] / drivers / net / bnxt / bnxt_irq.c
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
48 static void bnxt_int_handler(void *param)
49 {
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         uint32_t raw_cons = cpr->cp_raw_cons;
54         uint32_t cons;
55         struct cmpl_base *cmp;
56
57         while (1) {
58                 if (!cpr || !cpr->cp_ring_struct)
59                         return;
60
61                 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
62                 cmp = &cpr->cp_desc_ring[cons];
63
64                 if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
65                         break;
66
67                 switch (CMP_TYPE(cmp)) {
68                 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
69                         /* Handle any async event */
70                         bnxt_handle_async_event(bp, cmp);
71                         break;
72                 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
73                         /* Handle HWRM forwarded responses */
74                         bnxt_handle_fwd_req(bp, cmp);
75                         break;
76                 default:
77                         /* Ignore any other events */
78                         if (cmp->type & rte_cpu_to_le_16(0x01)) {
79                                 if (!CMP_VALID(cmp, raw_cons,
80                                                cpr->cp_ring_struct))
81                                         goto no_more;
82                         }
83                         RTE_LOG(INFO, PMD,
84                                 "Ignoring %02x completion\n", CMP_TYPE(cmp));
85                         break;
86                 }
87                 raw_cons = NEXT_RAW_CMP(raw_cons);
88
89         };
90 no_more:
91         cpr->cp_raw_cons = raw_cons;
92         B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
93 }
94
95 void bnxt_free_int(struct bnxt *bp)
96 {
97         struct bnxt_irq *irq;
98
99         irq = bp->irq_tbl;
100         if (irq) {
101                 if (irq->requested) {
102                         rte_intr_disable(&bp->pdev->intr_handle);
103                         rte_intr_callback_unregister(&bp->pdev->intr_handle,
104                                                      irq->handler,
105                                                      (void *)bp->eth_dev);
106                         irq->requested = 0;
107                 }
108                 rte_free((void *)bp->irq_tbl);
109                 bp->irq_tbl = NULL;
110         }
111 }
112
113 void bnxt_disable_int(struct bnxt *bp)
114 {
115         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
116
117         /* Only the default completion ring */
118         if (cpr != NULL && cpr->cp_doorbell != NULL)
119                 B_CP_DB_DISARM(cpr);
120 }
121
122 void bnxt_enable_int(struct bnxt *bp)
123 {
124         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
125
126         B_CP_DB_ARM(cpr);
127 }
128
129 int bnxt_setup_int(struct bnxt *bp)
130 {
131         uint16_t total_vecs;
132         const int len = sizeof(bp->irq_tbl[0].name);
133         int i, rc = 0;
134
135         /* DPDK host only supports 1 MSI-X vector */
136         total_vecs = 1;
137         bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
138                                  sizeof(struct bnxt_irq), 0);
139         if (bp->irq_tbl) {
140                 for (i = 0; i < total_vecs; i++) {
141                         bp->irq_tbl[i].vector = i;
142                         snprintf(bp->irq_tbl[i].name, len,
143                                  "%s-%d", bp->eth_dev->device->name, i);
144                         bp->irq_tbl[i].handler = bnxt_int_handler;
145                 }
146         } else {
147                 rc = -ENOMEM;
148                 goto setup_exit;
149         }
150         return 0;
151
152 setup_exit:
153         RTE_LOG(ERR, PMD, "bnxt_irq_tbl setup failed\n");
154         return rc;
155 }
156
157 int bnxt_request_int(struct bnxt *bp)
158 {
159         int rc = 0;
160
161         struct bnxt_irq *irq = bp->irq_tbl;
162
163         rte_intr_callback_register(&bp->pdev->intr_handle, irq->handler,
164                                    (void *)bp->eth_dev);
165         rte_intr_enable(&bp->pdev->intr_handle);
166
167         irq->requested = 1;
168         return rc;
169 }