net/bnxt: remove unused Txq flags
[dpdk.git] / drivers / net / bnxt / bnxt_irq.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Broadcom
3  * All rights reserved.
4  */
5
6 #include <inttypes.h>
7
8 #include <rte_malloc.h>
9
10 #include "bnxt.h"
11 #include "bnxt_cpr.h"
12 #include "bnxt_irq.h"
13 #include "bnxt_ring.h"
14 #include "hsi_struct_def_dpdk.h"
15
16 /*
17  * Interrupts
18  */
19
20 static void bnxt_int_handler(void *param)
21 {
22         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)param;
23         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
24         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
25         struct cmpl_base *cmp;
26         uint32_t raw_cons;
27         uint32_t cons;
28
29         if (cpr == NULL)
30                 return;
31
32         raw_cons = cpr->cp_raw_cons;
33         while (1) {
34                 if (!cpr || !cpr->cp_ring_struct)
35                         return;
36
37                 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
38                 cmp = &cpr->cp_desc_ring[cons];
39
40                 if (!CMP_VALID(cmp, raw_cons, cpr->cp_ring_struct))
41                         break;
42
43                 switch (CMP_TYPE(cmp)) {
44                 case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
45                         /* Handle any async event */
46                         bnxt_handle_async_event(bp, cmp);
47                         break;
48                 case CMPL_BASE_TYPE_HWRM_FWD_REQ:
49                         /* Handle HWRM forwarded responses */
50                         bnxt_handle_fwd_req(bp, cmp);
51                         break;
52                 default:
53                         /* Ignore any other events */
54                         if (cmp->type & rte_cpu_to_le_16(0x01)) {
55                                 if (!CMP_VALID(cmp, raw_cons,
56                                                cpr->cp_ring_struct))
57                                         goto no_more;
58                         }
59                         PMD_DRV_LOG(INFO,
60                                 "Ignoring %02x completion\n", CMP_TYPE(cmp));
61                         break;
62                 }
63                 raw_cons = NEXT_RAW_CMP(raw_cons);
64
65         };
66 no_more:
67         cpr->cp_raw_cons = raw_cons;
68         B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
69 }
70
71 void bnxt_free_int(struct bnxt *bp)
72 {
73         struct bnxt_irq *irq;
74
75         irq = bp->irq_tbl;
76         if (irq) {
77                 if (irq->requested) {
78                         rte_intr_disable(&bp->pdev->intr_handle);
79                         rte_intr_callback_unregister(&bp->pdev->intr_handle,
80                                                      irq->handler,
81                                                      (void *)bp->eth_dev);
82                         irq->requested = 0;
83                 }
84                 rte_free((void *)bp->irq_tbl);
85                 bp->irq_tbl = NULL;
86         }
87 }
88
89 void bnxt_disable_int(struct bnxt *bp)
90 {
91         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
92
93         /* Only the default completion ring */
94         if (cpr != NULL && cpr->cp_doorbell != NULL)
95                 B_CP_DB_DISARM(cpr);
96 }
97
98 void bnxt_enable_int(struct bnxt *bp)
99 {
100         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
101
102         B_CP_DB_ARM(cpr);
103 }
104
105 int bnxt_setup_int(struct bnxt *bp)
106 {
107         uint16_t total_vecs;
108         const int len = sizeof(bp->irq_tbl[0].name);
109         int i, rc = 0;
110
111         /* DPDK host only supports 1 MSI-X vector */
112         total_vecs = 1;
113         bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
114                                  sizeof(struct bnxt_irq), 0);
115         if (bp->irq_tbl) {
116                 for (i = 0; i < total_vecs; i++) {
117                         bp->irq_tbl[i].vector = i;
118                         snprintf(bp->irq_tbl[i].name, len,
119                                  "%s-%d", bp->eth_dev->device->name, i);
120                         bp->irq_tbl[i].handler = bnxt_int_handler;
121                 }
122         } else {
123                 rc = -ENOMEM;
124                 goto setup_exit;
125         }
126         return 0;
127
128 setup_exit:
129         PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
130         return rc;
131 }
132
133 int bnxt_request_int(struct bnxt *bp)
134 {
135         int rc = 0;
136
137         struct bnxt_irq *irq = bp->irq_tbl;
138
139         rte_intr_callback_register(&bp->pdev->intr_handle, irq->handler,
140                                    (void *)bp->eth_dev);
141         rte_intr_enable(&bp->pdev->intr_handle);
142
143         irq->requested = 1;
144         return rc;
145 }