net/sfc/base: import libefx base
[dpdk.git] / drivers / net / sfc / base / efx_intr.c
1 /*
2  * Copyright (c) 2007-2016 Solarflare Communications Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are
27  * those of the authors and should not be interpreted as representing official
28  * policies, either expressed or implied, of the FreeBSD Project.
29  */
30
31 #include "efx.h"
32 #include "efx_impl.h"
33
34
35         __checkReturn   efx_rc_t
36 efx_intr_init(
37         __in            efx_nic_t *enp,
38         __in            efx_intr_type_t type,
39         __in            efsys_mem_t *esmp)
40 {
41         efx_intr_t *eip = &(enp->en_intr);
42         const efx_intr_ops_t *eiop;
43         efx_rc_t rc;
44
45         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
46         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
47
48         if (enp->en_mod_flags & EFX_MOD_INTR) {
49                 rc = EINVAL;
50                 goto fail1;
51         }
52
53         eip->ei_esmp = esmp;
54         eip->ei_type = type;
55         eip->ei_level = 0;
56
57         enp->en_mod_flags |= EFX_MOD_INTR;
58
59         switch (enp->en_family) {
60
61         default:
62                 EFSYS_ASSERT(B_FALSE);
63                 rc = ENOTSUP;
64                 goto fail2;
65         }
66
67         if ((rc = eiop->eio_init(enp, type, esmp)) != 0)
68                 goto fail3;
69
70         eip->ei_eiop = eiop;
71
72         return (0);
73
74 fail3:
75         EFSYS_PROBE(fail3);
76 fail2:
77         EFSYS_PROBE(fail2);
78 fail1:
79         EFSYS_PROBE1(fail1, efx_rc_t, rc);
80
81         return (rc);
82 }
83
84                 void
85 efx_intr_fini(
86         __in    efx_nic_t *enp)
87 {
88         efx_intr_t *eip = &(enp->en_intr);
89         const efx_intr_ops_t *eiop = eip->ei_eiop;
90
91         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
92         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
93         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
94
95         eiop->eio_fini(enp);
96
97         enp->en_mod_flags &= ~EFX_MOD_INTR;
98 }
99
100                         void
101 efx_intr_enable(
102         __in            efx_nic_t *enp)
103 {
104         efx_intr_t *eip = &(enp->en_intr);
105         const efx_intr_ops_t *eiop = eip->ei_eiop;
106
107         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
108         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
109
110         eiop->eio_enable(enp);
111 }
112
113                         void
114 efx_intr_disable(
115         __in            efx_nic_t *enp)
116 {
117         efx_intr_t *eip = &(enp->en_intr);
118         const efx_intr_ops_t *eiop = eip->ei_eiop;
119
120         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
121         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
122
123         eiop->eio_disable(enp);
124 }
125
126                         void
127 efx_intr_disable_unlocked(
128         __in            efx_nic_t *enp)
129 {
130         efx_intr_t *eip = &(enp->en_intr);
131         const efx_intr_ops_t *eiop = eip->ei_eiop;
132
133         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
134         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
135
136         eiop->eio_disable_unlocked(enp);
137 }
138
139
140         __checkReturn   efx_rc_t
141 efx_intr_trigger(
142         __in            efx_nic_t *enp,
143         __in            unsigned int level)
144 {
145         efx_intr_t *eip = &(enp->en_intr);
146         const efx_intr_ops_t *eiop = eip->ei_eiop;
147
148         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
149         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
150
151         return (eiop->eio_trigger(enp, level));
152 }
153
154                         void
155 efx_intr_status_line(
156         __in            efx_nic_t *enp,
157         __out           boolean_t *fatalp,
158         __out           uint32_t *qmaskp)
159 {
160         efx_intr_t *eip = &(enp->en_intr);
161         const efx_intr_ops_t *eiop = eip->ei_eiop;
162
163         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
164         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
165
166         eiop->eio_status_line(enp, fatalp, qmaskp);
167 }
168
169                         void
170 efx_intr_status_message(
171         __in            efx_nic_t *enp,
172         __in            unsigned int message,
173         __out           boolean_t *fatalp)
174 {
175         efx_intr_t *eip = &(enp->en_intr);
176         const efx_intr_ops_t *eiop = eip->ei_eiop;
177
178         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
179         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
180
181         eiop->eio_status_message(enp, message, fatalp);
182 }
183
184                 void
185 efx_intr_fatal(
186         __in    efx_nic_t *enp)
187 {
188         efx_intr_t *eip = &(enp->en_intr);
189         const efx_intr_ops_t *eiop = eip->ei_eiop;
190
191         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
192         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
193
194         eiop->eio_fatal(enp);
195 }
196
197
198 /* ************************************************************************* */
199 /* ************************************************************************* */
200 /* ************************************************************************* */
201