This source file includes following definitions.
- msix_initialize
- msix_request_irq
- msix_request_rcd_irq
- msix_request_sdma_irq
- enable_sdma_srcs
- msix_request_irqs
- msix_free_irq
- msix_clean_up_interrupts
- msix_vnic_synchronize_irq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 #include "hfi.h"
50 #include "affinity.h"
51 #include "sdma.h"
52
53
54
55
56
57
58 int msix_initialize(struct hfi1_devdata *dd)
59 {
60 u32 total;
61 int ret;
62 struct hfi1_msix_entry *entries;
63
64
65
66
67
68
69
70
71
72 total = 1 + dd->num_sdma + dd->n_krcv_queues + dd->num_vnic_contexts;
73
74 if (total >= CCE_NUM_MSIX_VECTORS)
75 return -EINVAL;
76
77 ret = pci_alloc_irq_vectors(dd->pcidev, total, total, PCI_IRQ_MSIX);
78 if (ret < 0) {
79 dd_dev_err(dd, "pci_alloc_irq_vectors() failed: %d\n", ret);
80 return ret;
81 }
82
83 entries = kcalloc(total, sizeof(*dd->msix_info.msix_entries),
84 GFP_KERNEL);
85 if (!entries) {
86 pci_free_irq_vectors(dd->pcidev);
87 return -ENOMEM;
88 }
89
90 dd->msix_info.msix_entries = entries;
91 spin_lock_init(&dd->msix_info.msix_lock);
92 bitmap_zero(dd->msix_info.in_use_msix, total);
93 dd->msix_info.max_requested = total;
94 dd_dev_info(dd, "%u MSI-X interrupts allocated\n", total);
95
96 return 0;
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 static int msix_request_irq(struct hfi1_devdata *dd, void *arg,
117 irq_handler_t handler, irq_handler_t thread,
118 u32 idx, enum irq_type type)
119 {
120 unsigned long nr;
121 int irq;
122 int ret;
123 const char *err_info;
124 char name[MAX_NAME_SIZE];
125 struct hfi1_msix_entry *me;
126
127
128 spin_lock(&dd->msix_info.msix_lock);
129 nr = find_first_zero_bit(dd->msix_info.in_use_msix,
130 dd->msix_info.max_requested);
131 if (nr < dd->msix_info.max_requested)
132 __set_bit(nr, dd->msix_info.in_use_msix);
133 spin_unlock(&dd->msix_info.msix_lock);
134
135 if (nr == dd->msix_info.max_requested)
136 return -ENOSPC;
137
138
139 switch (type) {
140 case IRQ_GENERAL:
141
142 if (nr) {
143 spin_lock(&dd->msix_info.msix_lock);
144 __clear_bit(nr, dd->msix_info.in_use_msix);
145 spin_unlock(&dd->msix_info.msix_lock);
146 dd_dev_err(dd, "Invalid index %lu for GENERAL IRQ\n",
147 nr);
148 return -EINVAL;
149 }
150 snprintf(name, sizeof(name), DRIVER_NAME "_%d", dd->unit);
151 err_info = "general";
152 break;
153 case IRQ_SDMA:
154 snprintf(name, sizeof(name), DRIVER_NAME "_%d sdma%d",
155 dd->unit, idx);
156 err_info = "sdma";
157 break;
158 case IRQ_RCVCTXT:
159 snprintf(name, sizeof(name), DRIVER_NAME "_%d kctxt%d",
160 dd->unit, idx);
161 err_info = "receive context";
162 break;
163 case IRQ_OTHER:
164 default:
165 return -EINVAL;
166 }
167 name[sizeof(name) - 1] = 0;
168
169 irq = pci_irq_vector(dd->pcidev, nr);
170 ret = pci_request_irq(dd->pcidev, nr, handler, thread, arg, name);
171 if (ret) {
172 dd_dev_err(dd,
173 "%s: request for IRQ %d failed, MSIx %d, err %d\n",
174 err_info, irq, idx, ret);
175 spin_lock(&dd->msix_info.msix_lock);
176 __clear_bit(nr, dd->msix_info.in_use_msix);
177 spin_unlock(&dd->msix_info.msix_lock);
178 return ret;
179 }
180
181
182
183
184
185 me = &dd->msix_info.msix_entries[nr];
186 me->irq = irq;
187 me->arg = arg;
188 me->type = type;
189
190
191 ret = hfi1_get_irq_affinity(dd, me);
192 if (ret)
193 dd_dev_err(dd, "unable to pin IRQ %d\n", ret);
194
195 return nr;
196 }
197
198
199
200
201
202
203 int msix_request_rcd_irq(struct hfi1_ctxtdata *rcd)
204 {
205 int nr;
206
207 nr = msix_request_irq(rcd->dd, rcd, receive_context_interrupt,
208 receive_context_thread, rcd->ctxt, IRQ_RCVCTXT);
209 if (nr < 0)
210 return nr;
211
212
213
214
215
216 rcd->ireg = (IS_RCVAVAIL_START + rcd->ctxt) / 64;
217 rcd->imask = ((u64)1) << ((IS_RCVAVAIL_START + rcd->ctxt) % 64);
218 rcd->msix_intr = nr;
219 remap_intr(rcd->dd, IS_RCVAVAIL_START + rcd->ctxt, nr);
220
221 return 0;
222 }
223
224
225
226
227
228
229 int msix_request_sdma_irq(struct sdma_engine *sde)
230 {
231 int nr;
232
233 nr = msix_request_irq(sde->dd, sde, sdma_interrupt, NULL,
234 sde->this_idx, IRQ_SDMA);
235 if (nr < 0)
236 return nr;
237 sde->msix_intr = nr;
238 remap_sdma_interrupts(sde->dd, sde->this_idx, nr);
239
240 return 0;
241 }
242
243
244
245
246
247
248 static void enable_sdma_srcs(struct hfi1_devdata *dd, int i)
249 {
250 set_intr_bits(dd, IS_SDMA_START + i, IS_SDMA_START + i, true);
251 set_intr_bits(dd, IS_SDMA_PROGRESS_START + i,
252 IS_SDMA_PROGRESS_START + i, true);
253 set_intr_bits(dd, IS_SDMA_IDLE_START + i, IS_SDMA_IDLE_START + i, true);
254 set_intr_bits(dd, IS_SDMAENG_ERR_START + i, IS_SDMAENG_ERR_START + i,
255 true);
256 }
257
258
259
260
261
262
263
264
265 int msix_request_irqs(struct hfi1_devdata *dd)
266 {
267 int i;
268 int ret;
269
270 ret = msix_request_irq(dd, dd, general_interrupt, NULL, 0, IRQ_GENERAL);
271 if (ret < 0)
272 return ret;
273
274 for (i = 0; i < dd->num_sdma; i++) {
275 struct sdma_engine *sde = &dd->per_sdma[i];
276
277 ret = msix_request_sdma_irq(sde);
278 if (ret)
279 return ret;
280 enable_sdma_srcs(sde->dd, i);
281 }
282
283 for (i = 0; i < dd->n_krcv_queues; i++) {
284 struct hfi1_ctxtdata *rcd = hfi1_rcd_get_by_index_safe(dd, i);
285
286 if (rcd)
287 ret = msix_request_rcd_irq(rcd);
288 hfi1_rcd_put(rcd);
289 if (ret)
290 return ret;
291 }
292
293 return 0;
294 }
295
296
297
298
299
300
301
302 void msix_free_irq(struct hfi1_devdata *dd, u8 msix_intr)
303 {
304 struct hfi1_msix_entry *me;
305
306 if (msix_intr >= dd->msix_info.max_requested)
307 return;
308
309 me = &dd->msix_info.msix_entries[msix_intr];
310
311 if (!me->arg)
312 return;
313
314 hfi1_put_irq_affinity(dd, me);
315 pci_free_irq(dd->pcidev, msix_intr, me->arg);
316
317 me->arg = NULL;
318
319 spin_lock(&dd->msix_info.msix_lock);
320 __clear_bit(msix_intr, dd->msix_info.in_use_msix);
321 spin_unlock(&dd->msix_info.msix_lock);
322 }
323
324
325
326
327
328
329
330 void msix_clean_up_interrupts(struct hfi1_devdata *dd)
331 {
332 int i;
333 struct hfi1_msix_entry *me = dd->msix_info.msix_entries;
334
335
336 for (i = 0; i < dd->msix_info.max_requested; i++, me++)
337 msix_free_irq(dd, i);
338
339
340 kfree(dd->msix_info.msix_entries);
341 dd->msix_info.msix_entries = NULL;
342 dd->msix_info.max_requested = 0;
343
344 pci_free_irq_vectors(dd->pcidev);
345 }
346
347
348
349
350
351 void msix_vnic_synchronize_irq(struct hfi1_devdata *dd)
352 {
353 int i;
354
355 for (i = 0; i < dd->vnic.num_ctxt; i++) {
356 struct hfi1_ctxtdata *rcd = dd->vnic.ctxt[i];
357 struct hfi1_msix_entry *me;
358
359 me = &dd->msix_info.msix_entries[rcd->msix_intr];
360
361 synchronize_irq(me->irq);
362 }
363 }