New upstream version 18.08
[deb_dpdk.git] / drivers / net / sfc / base / efx_intr.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2007-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9
10
11 #if EFSYS_OPT_SIENA
12
13 static  __checkReturn   efx_rc_t
14 siena_intr_init(
15         __in            efx_nic_t *enp,
16         __in            efx_intr_type_t type,
17         __in            efsys_mem_t *esmp);
18
19 static                  void
20 siena_intr_enable(
21         __in            efx_nic_t *enp);
22
23 static                  void
24 siena_intr_disable(
25         __in            efx_nic_t *enp);
26
27 static                  void
28 siena_intr_disable_unlocked(
29         __in            efx_nic_t *enp);
30
31 static  __checkReturn   efx_rc_t
32 siena_intr_trigger(
33         __in            efx_nic_t *enp,
34         __in            unsigned int level);
35
36 static                  void
37 siena_intr_fini(
38         __in            efx_nic_t *enp);
39
40 static                  void
41 siena_intr_status_line(
42         __in            efx_nic_t *enp,
43         __out           boolean_t *fatalp,
44         __out           uint32_t *qmaskp);
45
46 static                  void
47 siena_intr_status_message(
48         __in            efx_nic_t *enp,
49         __in            unsigned int message,
50         __out           boolean_t *fatalp);
51
52 static                  void
53 siena_intr_fatal(
54         __in            efx_nic_t *enp);
55
56 static  __checkReturn   boolean_t
57 siena_intr_check_fatal(
58         __in            efx_nic_t *enp);
59
60
61 #endif /* EFSYS_OPT_SIENA */
62
63
64 #if EFSYS_OPT_SIENA
65 static const efx_intr_ops_t     __efx_intr_siena_ops = {
66         siena_intr_init,                /* eio_init */
67         siena_intr_enable,              /* eio_enable */
68         siena_intr_disable,             /* eio_disable */
69         siena_intr_disable_unlocked,    /* eio_disable_unlocked */
70         siena_intr_trigger,             /* eio_trigger */
71         siena_intr_status_line,         /* eio_status_line */
72         siena_intr_status_message,      /* eio_status_message */
73         siena_intr_fatal,               /* eio_fatal */
74         siena_intr_fini,                /* eio_fini */
75 };
76 #endif  /* EFSYS_OPT_SIENA */
77
78 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
79 static const efx_intr_ops_t     __efx_intr_ef10_ops = {
80         ef10_intr_init,                 /* eio_init */
81         ef10_intr_enable,               /* eio_enable */
82         ef10_intr_disable,              /* eio_disable */
83         ef10_intr_disable_unlocked,     /* eio_disable_unlocked */
84         ef10_intr_trigger,              /* eio_trigger */
85         ef10_intr_status_line,          /* eio_status_line */
86         ef10_intr_status_message,       /* eio_status_message */
87         ef10_intr_fatal,                /* eio_fatal */
88         ef10_intr_fini,                 /* eio_fini */
89 };
90 #endif  /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */
91
92         __checkReturn   efx_rc_t
93 efx_intr_init(
94         __in            efx_nic_t *enp,
95         __in            efx_intr_type_t type,
96         __in            efsys_mem_t *esmp)
97 {
98         efx_intr_t *eip = &(enp->en_intr);
99         const efx_intr_ops_t *eiop;
100         efx_rc_t rc;
101
102         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
103         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
104
105         if (enp->en_mod_flags & EFX_MOD_INTR) {
106                 rc = EINVAL;
107                 goto fail1;
108         }
109
110         eip->ei_esmp = esmp;
111         eip->ei_type = type;
112         eip->ei_level = 0;
113
114         enp->en_mod_flags |= EFX_MOD_INTR;
115
116         switch (enp->en_family) {
117 #if EFSYS_OPT_SIENA
118         case EFX_FAMILY_SIENA:
119                 eiop = &__efx_intr_siena_ops;
120                 break;
121 #endif  /* EFSYS_OPT_SIENA */
122
123 #if EFSYS_OPT_HUNTINGTON
124         case EFX_FAMILY_HUNTINGTON:
125                 eiop = &__efx_intr_ef10_ops;
126                 break;
127 #endif  /* EFSYS_OPT_HUNTINGTON */
128
129 #if EFSYS_OPT_MEDFORD
130         case EFX_FAMILY_MEDFORD:
131                 eiop = &__efx_intr_ef10_ops;
132                 break;
133 #endif  /* EFSYS_OPT_MEDFORD */
134
135 #if EFSYS_OPT_MEDFORD2
136         case EFX_FAMILY_MEDFORD2:
137                 eiop = &__efx_intr_ef10_ops;
138                 break;
139 #endif  /* EFSYS_OPT_MEDFORD2 */
140
141         default:
142                 EFSYS_ASSERT(B_FALSE);
143                 rc = ENOTSUP;
144                 goto fail2;
145         }
146
147         if ((rc = eiop->eio_init(enp, type, esmp)) != 0)
148                 goto fail3;
149
150         eip->ei_eiop = eiop;
151
152         return (0);
153
154 fail3:
155         EFSYS_PROBE(fail3);
156 fail2:
157         EFSYS_PROBE(fail2);
158 fail1:
159         EFSYS_PROBE1(fail1, efx_rc_t, rc);
160
161         return (rc);
162 }
163
164                 void
165 efx_intr_fini(
166         __in    efx_nic_t *enp)
167 {
168         efx_intr_t *eip = &(enp->en_intr);
169         const efx_intr_ops_t *eiop = eip->ei_eiop;
170
171         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
172         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
173         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
174
175         eiop->eio_fini(enp);
176
177         enp->en_mod_flags &= ~EFX_MOD_INTR;
178 }
179
180                         void
181 efx_intr_enable(
182         __in            efx_nic_t *enp)
183 {
184         efx_intr_t *eip = &(enp->en_intr);
185         const efx_intr_ops_t *eiop = eip->ei_eiop;
186
187         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
188         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
189
190         eiop->eio_enable(enp);
191 }
192
193                         void
194 efx_intr_disable(
195         __in            efx_nic_t *enp)
196 {
197         efx_intr_t *eip = &(enp->en_intr);
198         const efx_intr_ops_t *eiop = eip->ei_eiop;
199
200         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
201         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
202
203         eiop->eio_disable(enp);
204 }
205
206                         void
207 efx_intr_disable_unlocked(
208         __in            efx_nic_t *enp)
209 {
210         efx_intr_t *eip = &(enp->en_intr);
211         const efx_intr_ops_t *eiop = eip->ei_eiop;
212
213         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
214         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
215
216         eiop->eio_disable_unlocked(enp);
217 }
218
219
220         __checkReturn   efx_rc_t
221 efx_intr_trigger(
222         __in            efx_nic_t *enp,
223         __in            unsigned int level)
224 {
225         efx_intr_t *eip = &(enp->en_intr);
226         const efx_intr_ops_t *eiop = eip->ei_eiop;
227
228         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
229         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
230
231         return (eiop->eio_trigger(enp, level));
232 }
233
234                         void
235 efx_intr_status_line(
236         __in            efx_nic_t *enp,
237         __out           boolean_t *fatalp,
238         __out           uint32_t *qmaskp)
239 {
240         efx_intr_t *eip = &(enp->en_intr);
241         const efx_intr_ops_t *eiop = eip->ei_eiop;
242
243         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
244         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
245
246         eiop->eio_status_line(enp, fatalp, qmaskp);
247 }
248
249                         void
250 efx_intr_status_message(
251         __in            efx_nic_t *enp,
252         __in            unsigned int message,
253         __out           boolean_t *fatalp)
254 {
255         efx_intr_t *eip = &(enp->en_intr);
256         const efx_intr_ops_t *eiop = eip->ei_eiop;
257
258         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
259         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
260
261         eiop->eio_status_message(enp, message, fatalp);
262 }
263
264                 void
265 efx_intr_fatal(
266         __in    efx_nic_t *enp)
267 {
268         efx_intr_t *eip = &(enp->en_intr);
269         const efx_intr_ops_t *eiop = eip->ei_eiop;
270
271         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
272         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
273
274         eiop->eio_fatal(enp);
275 }
276
277
278 /* ************************************************************************* */
279 /* ************************************************************************* */
280 /* ************************************************************************* */
281
282 #if EFSYS_OPT_SIENA
283
284 static  __checkReturn   efx_rc_t
285 siena_intr_init(
286         __in            efx_nic_t *enp,
287         __in            efx_intr_type_t type,
288         __in            efsys_mem_t *esmp)
289 {
290         efx_intr_t *eip = &(enp->en_intr);
291         efx_oword_t oword;
292         efx_rc_t rc;
293
294         if ((esmp == NULL) || (EFSYS_MEM_SIZE(esmp) < EFX_INTR_SIZE)) {
295                 rc = EINVAL;
296                 goto fail1;
297         }
298
299         /*
300          * bug17213 workaround.
301          *
302          * Under legacy interrupts, don't share a level between fatal
303          * interrupts and event queue interrupts. Under MSI-X, they
304          * must share, or we won't get an interrupt.
305          */
306         if (enp->en_family == EFX_FAMILY_SIENA &&
307             eip->ei_type == EFX_INTR_LINE)
308                 eip->ei_level = 0x1f;
309         else
310                 eip->ei_level = 0;
311
312         /* Enable all the genuinely fatal interrupts */
313         EFX_SET_OWORD(oword);
314         EFX_SET_OWORD_FIELD(oword, FRF_AZ_ILL_ADR_INT_KER_EN, 0);
315         EFX_SET_OWORD_FIELD(oword, FRF_AZ_RBUF_OWN_INT_KER_EN, 0);
316         EFX_SET_OWORD_FIELD(oword, FRF_AZ_TBUF_OWN_INT_KER_EN, 0);
317         if (enp->en_family >= EFX_FAMILY_SIENA)
318                 EFX_SET_OWORD_FIELD(oword, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 0);
319         EFX_BAR_WRITEO(enp, FR_AZ_FATAL_INTR_REG_KER, &oword);
320
321         /* Set up the interrupt address register */
322         EFX_POPULATE_OWORD_3(oword,
323             FRF_AZ_NORM_INT_VEC_DIS_KER, (type == EFX_INTR_MESSAGE) ? 1 : 0,
324             FRF_AZ_INT_ADR_KER_DW0, EFSYS_MEM_ADDR(esmp) & 0xffffffff,
325             FRF_AZ_INT_ADR_KER_DW1, EFSYS_MEM_ADDR(esmp) >> 32);
326         EFX_BAR_WRITEO(enp, FR_AZ_INT_ADR_REG_KER, &oword);
327
328         return (0);
329
330 fail1:
331         EFSYS_PROBE1(fail1, efx_rc_t, rc);
332
333         return (rc);
334 }
335
336 static                  void
337 siena_intr_enable(
338         __in            efx_nic_t *enp)
339 {
340         efx_intr_t *eip = &(enp->en_intr);
341         efx_oword_t oword;
342
343         EFX_BAR_READO(enp, FR_AZ_INT_EN_REG_KER, &oword);
344
345         EFX_SET_OWORD_FIELD(oword, FRF_AZ_KER_INT_LEVE_SEL, eip->ei_level);
346         EFX_SET_OWORD_FIELD(oword, FRF_AZ_DRV_INT_EN_KER, 1);
347         EFX_BAR_WRITEO(enp, FR_AZ_INT_EN_REG_KER, &oword);
348 }
349
350 static                  void
351 siena_intr_disable(
352         __in            efx_nic_t *enp)
353 {
354         efx_oword_t oword;
355
356         EFX_BAR_READO(enp, FR_AZ_INT_EN_REG_KER, &oword);
357         EFX_SET_OWORD_FIELD(oword, FRF_AZ_DRV_INT_EN_KER, 0);
358         EFX_BAR_WRITEO(enp, FR_AZ_INT_EN_REG_KER, &oword);
359
360         EFSYS_SPIN(10);
361 }
362
363 static                  void
364 siena_intr_disable_unlocked(
365         __in            efx_nic_t *enp)
366 {
367         efx_oword_t oword;
368
369         EFSYS_BAR_READO(enp->en_esbp, FR_AZ_INT_EN_REG_KER_OFST,
370                         &oword, B_FALSE);
371         EFX_SET_OWORD_FIELD(oword, FRF_AZ_DRV_INT_EN_KER, 0);
372         EFSYS_BAR_WRITEO(enp->en_esbp, FR_AZ_INT_EN_REG_KER_OFST,
373             &oword, B_FALSE);
374 }
375
376 static  __checkReturn   efx_rc_t
377 siena_intr_trigger(
378         __in            efx_nic_t *enp,
379         __in            unsigned int level)
380 {
381         efx_intr_t *eip = &(enp->en_intr);
382         efx_oword_t oword;
383         unsigned int count;
384         uint32_t sel;
385         efx_rc_t rc;
386
387         /* bug16757: No event queues can be initialized */
388         EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_EV));
389
390         if (level >= EFX_NINTR_SIENA) {
391                 rc = EINVAL;
392                 goto fail1;
393         }
394
395         if (level > EFX_MASK32(FRF_AZ_KER_INT_LEVE_SEL))
396                 return (ENOTSUP); /* avoid EFSYS_PROBE() */
397
398         sel = level;
399
400         /* Trigger a test interrupt */
401         EFX_BAR_READO(enp, FR_AZ_INT_EN_REG_KER, &oword);
402         EFX_SET_OWORD_FIELD(oword, FRF_AZ_KER_INT_LEVE_SEL, sel);
403         EFX_SET_OWORD_FIELD(oword, FRF_AZ_KER_INT_KER, 1);
404         EFX_BAR_WRITEO(enp, FR_AZ_INT_EN_REG_KER, &oword);
405
406         /*
407          * Wait up to 100ms for the interrupt to be raised before restoring
408          * KER_INT_LEVE_SEL. Ignore a failure to raise (the caller will
409          * observe this soon enough anyway), but always reset KER_INT_LEVE_SEL
410          */
411         count = 0;
412         do {
413                 EFSYS_SPIN(100);        /* 100us */
414
415                 EFX_BAR_READO(enp, FR_AZ_INT_EN_REG_KER, &oword);
416         } while (EFX_OWORD_FIELD(oword, FRF_AZ_KER_INT_KER) && ++count < 1000);
417
418         EFX_SET_OWORD_FIELD(oword, FRF_AZ_KER_INT_LEVE_SEL, eip->ei_level);
419         EFX_BAR_WRITEO(enp, FR_AZ_INT_EN_REG_KER, &oword);
420
421         return (0);
422
423 fail1:
424         EFSYS_PROBE1(fail1, efx_rc_t, rc);
425
426         return (rc);
427 }
428
429 static  __checkReturn   boolean_t
430 siena_intr_check_fatal(
431         __in            efx_nic_t *enp)
432 {
433         efx_intr_t *eip = &(enp->en_intr);
434         efsys_mem_t *esmp = eip->ei_esmp;
435         efx_oword_t oword;
436
437         /* Read the syndrome */
438         EFSYS_MEM_READO(esmp, 0, &oword);
439
440         if (EFX_OWORD_FIELD(oword, FSF_AZ_NET_IVEC_FATAL_INT) != 0) {
441                 EFSYS_PROBE(fatal);
442
443                 /* Clear the fatal interrupt condition */
444                 EFX_SET_OWORD_FIELD(oword, FSF_AZ_NET_IVEC_FATAL_INT, 0);
445                 EFSYS_MEM_WRITEO(esmp, 0, &oword);
446
447                 return (B_TRUE);
448         }
449
450         return (B_FALSE);
451 }
452
453 static                  void
454 siena_intr_status_line(
455         __in            efx_nic_t *enp,
456         __out           boolean_t *fatalp,
457         __out           uint32_t *qmaskp)
458 {
459         efx_intr_t *eip = &(enp->en_intr);
460         efx_dword_t dword;
461
462         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
463         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
464
465         /*
466          * Read the queue mask and implicitly acknowledge the
467          * interrupt.
468          */
469         EFX_BAR_READD(enp, FR_BZ_INT_ISR0_REG, &dword, B_FALSE);
470         *qmaskp = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
471
472         EFSYS_PROBE1(qmask, uint32_t, *qmaskp);
473
474         if (*qmaskp & (1U << eip->ei_level))
475                 *fatalp = siena_intr_check_fatal(enp);
476         else
477                 *fatalp = B_FALSE;
478 }
479
480 static                  void
481 siena_intr_status_message(
482         __in            efx_nic_t *enp,
483         __in            unsigned int message,
484         __out           boolean_t *fatalp)
485 {
486         efx_intr_t *eip = &(enp->en_intr);
487
488         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
489         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
490
491         if (message == eip->ei_level)
492                 *fatalp = siena_intr_check_fatal(enp);
493         else
494                 *fatalp = B_FALSE;
495 }
496
497
498 static          void
499 siena_intr_fatal(
500         __in    efx_nic_t *enp)
501 {
502 #if EFSYS_OPT_DECODE_INTR_FATAL
503         efx_oword_t fatal;
504         efx_oword_t mem_per;
505
506         EFX_BAR_READO(enp, FR_AZ_FATAL_INTR_REG_KER, &fatal);
507         EFX_ZERO_OWORD(mem_per);
508
509         if (EFX_OWORD_FIELD(fatal, FRF_AZ_SRM_PERR_INT_KER) != 0 ||
510             EFX_OWORD_FIELD(fatal, FRF_AZ_MEM_PERR_INT_KER) != 0)
511                 EFX_BAR_READO(enp, FR_AZ_MEM_STAT_REG, &mem_per);
512
513         if (EFX_OWORD_FIELD(fatal, FRF_AZ_SRAM_OOB_INT_KER) != 0)
514                 EFSYS_ERR(enp->en_esip, EFX_ERR_SRAM_OOB, 0, 0);
515
516         if (EFX_OWORD_FIELD(fatal, FRF_AZ_BUFID_DC_OOB_INT_KER) != 0)
517                 EFSYS_ERR(enp->en_esip, EFX_ERR_BUFID_DC_OOB, 0, 0);
518
519         if (EFX_OWORD_FIELD(fatal, FRF_AZ_MEM_PERR_INT_KER) != 0)
520                 EFSYS_ERR(enp->en_esip, EFX_ERR_MEM_PERR,
521                     EFX_OWORD_FIELD(mem_per, EFX_DWORD_0),
522                     EFX_OWORD_FIELD(mem_per, EFX_DWORD_1));
523
524         if (EFX_OWORD_FIELD(fatal, FRF_AZ_RBUF_OWN_INT_KER) != 0)
525                 EFSYS_ERR(enp->en_esip, EFX_ERR_RBUF_OWN, 0, 0);
526
527         if (EFX_OWORD_FIELD(fatal, FRF_AZ_TBUF_OWN_INT_KER) != 0)
528                 EFSYS_ERR(enp->en_esip, EFX_ERR_TBUF_OWN, 0, 0);
529
530         if (EFX_OWORD_FIELD(fatal, FRF_AZ_RDESCQ_OWN_INT_KER) != 0)
531                 EFSYS_ERR(enp->en_esip, EFX_ERR_RDESQ_OWN, 0, 0);
532
533         if (EFX_OWORD_FIELD(fatal, FRF_AZ_TDESCQ_OWN_INT_KER) != 0)
534                 EFSYS_ERR(enp->en_esip, EFX_ERR_TDESQ_OWN, 0, 0);
535
536         if (EFX_OWORD_FIELD(fatal, FRF_AZ_EVQ_OWN_INT_KER) != 0)
537                 EFSYS_ERR(enp->en_esip, EFX_ERR_EVQ_OWN, 0, 0);
538
539         if (EFX_OWORD_FIELD(fatal, FRF_AZ_EVF_OFLO_INT_KER) != 0)
540                 EFSYS_ERR(enp->en_esip, EFX_ERR_EVFF_OFLO, 0, 0);
541
542         if (EFX_OWORD_FIELD(fatal, FRF_AZ_ILL_ADR_INT_KER) != 0)
543                 EFSYS_ERR(enp->en_esip, EFX_ERR_ILL_ADDR, 0, 0);
544
545         if (EFX_OWORD_FIELD(fatal, FRF_AZ_SRM_PERR_INT_KER) != 0)
546                 EFSYS_ERR(enp->en_esip, EFX_ERR_SRAM_PERR,
547                     EFX_OWORD_FIELD(mem_per, EFX_DWORD_0),
548                     EFX_OWORD_FIELD(mem_per, EFX_DWORD_1));
549 #else
550         EFSYS_ASSERT(0);
551 #endif
552 }
553
554 static          void
555 siena_intr_fini(
556         __in    efx_nic_t *enp)
557 {
558         efx_oword_t oword;
559
560         /* Clear the interrupt address register */
561         EFX_ZERO_OWORD(oword);
562         EFX_BAR_WRITEO(enp, FR_AZ_INT_ADR_REG_KER, &oword);
563 }
564
565 #endif /* EFSYS_OPT_SIENA */