New upstream version 18.08
[deb_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                 bnxt_event_hwrm_resp_handler(bp, cmp);
44                 raw_cons = NEXT_RAW_CMP(raw_cons);
45         };
46
47         cpr->cp_raw_cons = raw_cons;
48         B_CP_DB_REARM(cpr, cpr->cp_raw_cons);
49 }
50
51 void bnxt_free_int(struct bnxt *bp)
52 {
53         struct bnxt_irq *irq;
54
55         irq = bp->irq_tbl;
56         if (irq) {
57                 if (irq->requested) {
58                         rte_intr_disable(&bp->pdev->intr_handle);
59                         rte_intr_callback_unregister(&bp->pdev->intr_handle,
60                                                      irq->handler,
61                                                      (void *)bp->eth_dev);
62                         irq->requested = 0;
63                 }
64                 rte_free((void *)bp->irq_tbl);
65                 bp->irq_tbl = NULL;
66         }
67 }
68
69 void bnxt_disable_int(struct bnxt *bp)
70 {
71         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
72
73         /* Only the default completion ring */
74         if (cpr != NULL && cpr->cp_doorbell != NULL)
75                 B_CP_DB_DISARM(cpr);
76 }
77
78 void bnxt_enable_int(struct bnxt *bp)
79 {
80         struct bnxt_cp_ring_info *cpr = bp->def_cp_ring;
81
82         /* Only the default completion ring */
83         if (cpr != NULL && cpr->cp_doorbell != NULL)
84                 B_CP_DB_ARM(cpr);
85 }
86
87 int bnxt_setup_int(struct bnxt *bp)
88 {
89         uint16_t total_vecs;
90         const int len = sizeof(bp->irq_tbl[0].name);
91         int i, rc = 0;
92
93         /* DPDK host only supports 1 MSI-X vector */
94         total_vecs = 1;
95         bp->irq_tbl = rte_calloc("bnxt_irq_tbl", total_vecs,
96                                  sizeof(struct bnxt_irq), 0);
97         if (bp->irq_tbl) {
98                 for (i = 0; i < total_vecs; i++) {
99                         bp->irq_tbl[i].vector = i;
100                         snprintf(bp->irq_tbl[i].name, len,
101                                  "%s-%d", bp->eth_dev->device->name, i);
102                         bp->irq_tbl[i].handler = bnxt_int_handler;
103                 }
104         } else {
105                 rc = -ENOMEM;
106                 goto setup_exit;
107         }
108         return 0;
109
110 setup_exit:
111         PMD_DRV_LOG(ERR, "bnxt_irq_tbl setup failed\n");
112         return rc;
113 }
114
115 int bnxt_request_int(struct bnxt *bp)
116 {
117         int rc = 0;
118
119         struct bnxt_irq *irq = bp->irq_tbl;
120
121         rte_intr_callback_register(&bp->pdev->intr_handle, irq->handler,
122                                    (void *)bp->eth_dev);
123         rte_intr_enable(&bp->pdev->intr_handle);
124
125         irq->requested = 1;
126         return rc;
127 }