59f4d0284de49d64f27dcb27e02504af46690c39
[dpdk.git] / drivers / net / sfc / base / efx_ev.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 #define EFX_EV_QSTAT_INCR(_eep, _stat)
35
36 #define EFX_EV_PRESENT(_qword)                                          \
37         (EFX_QWORD_FIELD((_qword), EFX_DWORD_0) != 0xffffffff &&        \
38         EFX_QWORD_FIELD((_qword), EFX_DWORD_1) != 0xffffffff)
39
40
41
42 #if EFSYS_OPT_SIENA
43
44 static  __checkReturn   efx_rc_t
45 siena_ev_init(
46         __in            efx_nic_t *enp);
47
48 static                  void
49 siena_ev_fini(
50         __in            efx_nic_t *enp);
51
52 static  __checkReturn   efx_rc_t
53 siena_ev_qcreate(
54         __in            efx_nic_t *enp,
55         __in            unsigned int index,
56         __in            efsys_mem_t *esmp,
57         __in            size_t n,
58         __in            uint32_t id,
59         __in            uint32_t us,
60         __in            uint32_t flags,
61         __in            efx_evq_t *eep);
62
63 static                  void
64 siena_ev_qdestroy(
65         __in            efx_evq_t *eep);
66
67 static  __checkReturn   efx_rc_t
68 siena_ev_qprime(
69         __in            efx_evq_t *eep,
70         __in            unsigned int count);
71
72 static                  void
73 siena_ev_qpost(
74         __in    efx_evq_t *eep,
75         __in    uint16_t data);
76
77 static  __checkReturn   efx_rc_t
78 siena_ev_qmoderate(
79         __in            efx_evq_t *eep,
80         __in            unsigned int us);
81
82 #endif /* EFSYS_OPT_SIENA */
83
84 #if EFSYS_OPT_SIENA
85 static const efx_ev_ops_t       __efx_ev_siena_ops = {
86         siena_ev_init,                          /* eevo_init */
87         siena_ev_fini,                          /* eevo_fini */
88         siena_ev_qcreate,                       /* eevo_qcreate */
89         siena_ev_qdestroy,                      /* eevo_qdestroy */
90         siena_ev_qprime,                        /* eevo_qprime */
91         siena_ev_qpost,                         /* eevo_qpost */
92         siena_ev_qmoderate,                     /* eevo_qmoderate */
93 };
94 #endif /* EFSYS_OPT_SIENA */
95
96
97         __checkReturn   efx_rc_t
98 efx_ev_init(
99         __in            efx_nic_t *enp)
100 {
101         const efx_ev_ops_t *eevop;
102         efx_rc_t rc;
103
104         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
105         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
106
107         if (enp->en_mod_flags & EFX_MOD_EV) {
108                 rc = EINVAL;
109                 goto fail1;
110         }
111
112         switch (enp->en_family) {
113 #if EFSYS_OPT_SIENA
114         case EFX_FAMILY_SIENA:
115                 eevop = &__efx_ev_siena_ops;
116                 break;
117 #endif /* EFSYS_OPT_SIENA */
118
119         default:
120                 EFSYS_ASSERT(0);
121                 rc = ENOTSUP;
122                 goto fail1;
123         }
124
125         EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
126
127         if ((rc = eevop->eevo_init(enp)) != 0)
128                 goto fail2;
129
130         enp->en_eevop = eevop;
131         enp->en_mod_flags |= EFX_MOD_EV;
132         return (0);
133
134 fail2:
135         EFSYS_PROBE(fail2);
136
137 fail1:
138         EFSYS_PROBE1(fail1, efx_rc_t, rc);
139
140         enp->en_eevop = NULL;
141         enp->en_mod_flags &= ~EFX_MOD_EV;
142         return (rc);
143 }
144
145                 void
146 efx_ev_fini(
147         __in    efx_nic_t *enp)
148 {
149         const efx_ev_ops_t *eevop = enp->en_eevop;
150
151         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
152         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
153         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
154         EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_RX));
155         EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_TX));
156         EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
157
158         eevop->eevo_fini(enp);
159
160         enp->en_eevop = NULL;
161         enp->en_mod_flags &= ~EFX_MOD_EV;
162 }
163
164
165         __checkReturn   efx_rc_t
166 efx_ev_qcreate(
167         __in            efx_nic_t *enp,
168         __in            unsigned int index,
169         __in            efsys_mem_t *esmp,
170         __in            size_t n,
171         __in            uint32_t id,
172         __in            uint32_t us,
173         __in            uint32_t flags,
174         __deref_out     efx_evq_t **eepp)
175 {
176         const efx_ev_ops_t *eevop = enp->en_eevop;
177         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
178         efx_evq_t *eep;
179         efx_rc_t rc;
180
181         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
182         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
183
184         EFSYS_ASSERT3U(enp->en_ev_qcount + 1, <, encp->enc_evq_limit);
185
186         switch (flags & EFX_EVQ_FLAGS_NOTIFY_MASK) {
187         case EFX_EVQ_FLAGS_NOTIFY_INTERRUPT:
188                 break;
189         case EFX_EVQ_FLAGS_NOTIFY_DISABLED:
190                 if (us != 0) {
191                         rc = EINVAL;
192                         goto fail1;
193                 }
194                 break;
195         default:
196                 rc = EINVAL;
197                 goto fail2;
198         }
199
200         /* Allocate an EVQ object */
201         EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_evq_t), eep);
202         if (eep == NULL) {
203                 rc = ENOMEM;
204                 goto fail3;
205         }
206
207         eep->ee_magic = EFX_EVQ_MAGIC;
208         eep->ee_enp = enp;
209         eep->ee_index = index;
210         eep->ee_mask = n - 1;
211         eep->ee_flags = flags;
212         eep->ee_esmp = esmp;
213
214         /*
215          * Set outputs before the queue is created because interrupts may be
216          * raised for events immediately after the queue is created, before the
217          * function call below returns. See bug58606.
218          *
219          * The eepp pointer passed in by the client must therefore point to data
220          * shared with the client's event processing context.
221          */
222         enp->en_ev_qcount++;
223         *eepp = eep;
224
225         if ((rc = eevop->eevo_qcreate(enp, index, esmp, n, id, us, flags,
226             eep)) != 0)
227                 goto fail4;
228
229         return (0);
230
231 fail4:
232         EFSYS_PROBE(fail4);
233
234         *eepp = NULL;
235         enp->en_ev_qcount--;
236         EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
237 fail3:
238         EFSYS_PROBE(fail3);
239 fail2:
240         EFSYS_PROBE(fail2);
241 fail1:
242         EFSYS_PROBE1(fail1, efx_rc_t, rc);
243         return (rc);
244 }
245
246                 void
247 efx_ev_qdestroy(
248         __in    efx_evq_t *eep)
249 {
250         efx_nic_t *enp = eep->ee_enp;
251         const efx_ev_ops_t *eevop = enp->en_eevop;
252
253         EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
254
255         EFSYS_ASSERT(enp->en_ev_qcount != 0);
256         --enp->en_ev_qcount;
257
258         eevop->eevo_qdestroy(eep);
259
260         /* Free the EVQ object */
261         EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
262 }
263
264         __checkReturn   efx_rc_t
265 efx_ev_qprime(
266         __in            efx_evq_t *eep,
267         __in            unsigned int count)
268 {
269         efx_nic_t *enp = eep->ee_enp;
270         const efx_ev_ops_t *eevop = enp->en_eevop;
271         efx_rc_t rc;
272
273         EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
274
275         if (!(enp->en_mod_flags & EFX_MOD_INTR)) {
276                 rc = EINVAL;
277                 goto fail1;
278         }
279
280         if ((rc = eevop->eevo_qprime(eep, count)) != 0)
281                 goto fail2;
282
283         return (0);
284
285 fail2:
286         EFSYS_PROBE(fail2);
287 fail1:
288         EFSYS_PROBE1(fail1, efx_rc_t, rc);
289         return (rc);
290 }
291
292         __checkReturn   boolean_t
293 efx_ev_qpending(
294         __in            efx_evq_t *eep,
295         __in            unsigned int count)
296 {
297         size_t offset;
298         efx_qword_t qword;
299
300         EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
301
302         offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
303         EFSYS_MEM_READQ(eep->ee_esmp, offset, &qword);
304
305         return (EFX_EV_PRESENT(qword));
306 }
307
308 #define EFX_EV_BATCH    8
309
310                         void
311 efx_ev_qpoll(
312         __in            efx_evq_t *eep,
313         __inout         unsigned int *countp,
314         __in            const efx_ev_callbacks_t *eecp,
315         __in_opt        void *arg)
316 {
317         efx_qword_t ev[EFX_EV_BATCH];
318         unsigned int batch;
319         unsigned int total;
320         unsigned int count;
321         unsigned int index;
322         size_t offset;
323
324         /* Ensure events codes match for EF10 (Huntington/Medford) and Siena */
325         EFX_STATIC_ASSERT(ESF_DZ_EV_CODE_LBN == FSF_AZ_EV_CODE_LBN);
326         EFX_STATIC_ASSERT(ESF_DZ_EV_CODE_WIDTH == FSF_AZ_EV_CODE_WIDTH);
327
328         EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_RX_EV == FSE_AZ_EV_CODE_RX_EV);
329         EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_TX_EV == FSE_AZ_EV_CODE_TX_EV);
330         EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_DRIVER_EV == FSE_AZ_EV_CODE_DRIVER_EV);
331         EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_DRV_GEN_EV ==
332             FSE_AZ_EV_CODE_DRV_GEN_EV);
333 #if EFSYS_OPT_MCDI
334         EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_MCDI_EV ==
335             FSE_AZ_EV_CODE_MCDI_EVRESPONSE);
336 #endif
337
338         EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
339         EFSYS_ASSERT(countp != NULL);
340         EFSYS_ASSERT(eecp != NULL);
341
342         count = *countp;
343         do {
344                 /* Read up until the end of the batch period */
345                 batch = EFX_EV_BATCH - (count & (EFX_EV_BATCH - 1));
346                 offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
347                 for (total = 0; total < batch; ++total) {
348                         EFSYS_MEM_READQ(eep->ee_esmp, offset, &(ev[total]));
349
350                         if (!EFX_EV_PRESENT(ev[total]))
351                                 break;
352
353                         EFSYS_PROBE3(event, unsigned int, eep->ee_index,
354                             uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_1),
355                             uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_0));
356
357                         offset += sizeof (efx_qword_t);
358                 }
359
360                 /* Process the batch of events */
361                 for (index = 0; index < total; ++index) {
362                         boolean_t should_abort;
363                         uint32_t code;
364
365                         EFX_EV_QSTAT_INCR(eep, EV_ALL);
366
367                         code = EFX_QWORD_FIELD(ev[index], FSF_AZ_EV_CODE);
368                         switch (code) {
369                         case FSE_AZ_EV_CODE_RX_EV:
370                                 should_abort = eep->ee_rx(eep,
371                                     &(ev[index]), eecp, arg);
372                                 break;
373                         case FSE_AZ_EV_CODE_TX_EV:
374                                 should_abort = eep->ee_tx(eep,
375                                     &(ev[index]), eecp, arg);
376                                 break;
377                         case FSE_AZ_EV_CODE_DRIVER_EV:
378                                 should_abort = eep->ee_driver(eep,
379                                     &(ev[index]), eecp, arg);
380                                 break;
381                         case FSE_AZ_EV_CODE_DRV_GEN_EV:
382                                 should_abort = eep->ee_drv_gen(eep,
383                                     &(ev[index]), eecp, arg);
384                                 break;
385 #if EFSYS_OPT_MCDI
386                         case FSE_AZ_EV_CODE_MCDI_EVRESPONSE:
387                                 should_abort = eep->ee_mcdi(eep,
388                                     &(ev[index]), eecp, arg);
389                                 break;
390 #endif
391                         case FSE_AZ_EV_CODE_GLOBAL_EV:
392                                 if (eep->ee_global) {
393                                         should_abort = eep->ee_global(eep,
394                                             &(ev[index]), eecp, arg);
395                                         break;
396                                 }
397                                 /* else fallthrough */
398                         default:
399                                 EFSYS_PROBE3(bad_event,
400                                     unsigned int, eep->ee_index,
401                                     uint32_t,
402                                     EFX_QWORD_FIELD(ev[index], EFX_DWORD_1),
403                                     uint32_t,
404                                     EFX_QWORD_FIELD(ev[index], EFX_DWORD_0));
405
406                                 EFSYS_ASSERT(eecp->eec_exception != NULL);
407                                 (void) eecp->eec_exception(arg,
408                                         EFX_EXCEPTION_EV_ERROR, code);
409                                 should_abort = B_TRUE;
410                         }
411                         if (should_abort) {
412                                 /* Ignore subsequent events */
413                                 total = index + 1;
414                                 break;
415                         }
416                 }
417
418                 /*
419                  * Now that the hardware has most likely moved onto dma'ing
420                  * into the next cache line, clear the processed events. Take
421                  * care to only clear out events that we've processed
422                  */
423                 EFX_SET_QWORD(ev[0]);
424                 offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
425                 for (index = 0; index < total; ++index) {
426                         EFSYS_MEM_WRITEQ(eep->ee_esmp, offset, &(ev[0]));
427                         offset += sizeof (efx_qword_t);
428                 }
429
430                 count += total;
431
432         } while (total == batch);
433
434         *countp = count;
435 }
436
437                         void
438 efx_ev_qpost(
439         __in    efx_evq_t *eep,
440         __in    uint16_t data)
441 {
442         efx_nic_t *enp = eep->ee_enp;
443         const efx_ev_ops_t *eevop = enp->en_eevop;
444
445         EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
446
447         EFSYS_ASSERT(eevop != NULL &&
448             eevop->eevo_qpost != NULL);
449
450         eevop->eevo_qpost(eep, data);
451 }
452
453         __checkReturn   efx_rc_t
454 efx_ev_usecs_to_ticks(
455         __in            efx_nic_t *enp,
456         __in            unsigned int us,
457         __out           unsigned int *ticksp)
458 {
459         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
460         unsigned int ticks;
461
462         /* Convert microseconds to a timer tick count */
463         if (us == 0)
464                 ticks = 0;
465         else if (us * 1000 < encp->enc_evq_timer_quantum_ns)
466                 ticks = 1;      /* Never round down to zero */
467         else
468                 ticks = us * 1000 / encp->enc_evq_timer_quantum_ns;
469
470         *ticksp = ticks;
471         return (0);
472 }
473
474         __checkReturn   efx_rc_t
475 efx_ev_qmoderate(
476         __in            efx_evq_t *eep,
477         __in            unsigned int us)
478 {
479         efx_nic_t *enp = eep->ee_enp;
480         const efx_ev_ops_t *eevop = enp->en_eevop;
481         efx_rc_t rc;
482
483         EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
484
485         if ((eep->ee_flags & EFX_EVQ_FLAGS_NOTIFY_MASK) ==
486             EFX_EVQ_FLAGS_NOTIFY_DISABLED) {
487                 rc = EINVAL;
488                 goto fail1;
489         }
490
491         if ((rc = eevop->eevo_qmoderate(eep, us)) != 0)
492                 goto fail2;
493
494         return (0);
495
496 fail2:
497         EFSYS_PROBE(fail2);
498 fail1:
499         EFSYS_PROBE1(fail1, efx_rc_t, rc);
500         return (rc);
501 }
502
503 #if EFSYS_OPT_SIENA
504
505 static  __checkReturn   efx_rc_t
506 siena_ev_init(
507         __in            efx_nic_t *enp)
508 {
509         efx_oword_t oword;
510
511         /*
512          * Program the event queue for receive and transmit queue
513          * flush events.
514          */
515         EFX_BAR_READO(enp, FR_AZ_DP_CTRL_REG, &oword);
516         EFX_SET_OWORD_FIELD(oword, FRF_AZ_FLS_EVQ_ID, 0);
517         EFX_BAR_WRITEO(enp, FR_AZ_DP_CTRL_REG, &oword);
518
519         return (0);
520
521 }
522
523 static  __checkReturn   boolean_t
524 siena_ev_rx_not_ok(
525         __in            efx_evq_t *eep,
526         __in            efx_qword_t *eqp,
527         __in            uint32_t label,
528         __in            uint32_t id,
529         __inout         uint16_t *flagsp)
530 {
531         boolean_t ignore = B_FALSE;
532
533         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TOBE_DISC) != 0) {
534                 EFX_EV_QSTAT_INCR(eep, EV_RX_TOBE_DISC);
535                 EFSYS_PROBE(tobe_disc);
536                 /*
537                  * Assume this is a unicast address mismatch, unless below
538                  * we find either FSF_AZ_RX_EV_ETH_CRC_ERR or
539                  * EV_RX_PAUSE_FRM_ERR is set.
540                  */
541                 (*flagsp) |= EFX_ADDR_MISMATCH;
542         }
543
544         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_FRM_TRUNC) != 0) {
545                 EFSYS_PROBE2(frm_trunc, uint32_t, label, uint32_t, id);
546                 EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC);
547                 (*flagsp) |= EFX_DISCARD;
548
549         }
550
551         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_ETH_CRC_ERR) != 0) {
552                 EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR);
553                 EFSYS_PROBE(crc_err);
554                 (*flagsp) &= ~EFX_ADDR_MISMATCH;
555                 (*flagsp) |= EFX_DISCARD;
556         }
557
558         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PAUSE_FRM_ERR) != 0) {
559                 EFX_EV_QSTAT_INCR(eep, EV_RX_PAUSE_FRM_ERR);
560                 EFSYS_PROBE(pause_frm_err);
561                 (*flagsp) &= ~EFX_ADDR_MISMATCH;
562                 (*flagsp) |= EFX_DISCARD;
563         }
564
565         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BUF_OWNER_ID_ERR) != 0) {
566                 EFX_EV_QSTAT_INCR(eep, EV_RX_BUF_OWNER_ID_ERR);
567                 EFSYS_PROBE(owner_id_err);
568                 (*flagsp) |= EFX_DISCARD;
569         }
570
571         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR) != 0) {
572                 EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR);
573                 EFSYS_PROBE(ipv4_err);
574                 (*flagsp) &= ~EFX_CKSUM_IPV4;
575         }
576
577         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR) != 0) {
578                 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR);
579                 EFSYS_PROBE(udp_chk_err);
580                 (*flagsp) &= ~EFX_CKSUM_TCPUDP;
581         }
582
583         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_FRAG_ERR) != 0) {
584                 EFX_EV_QSTAT_INCR(eep, EV_RX_IP_FRAG_ERR);
585
586                 /*
587                  * If IP is fragmented FSF_AZ_RX_EV_IP_FRAG_ERR is set. This
588                  * causes FSF_AZ_RX_EV_PKT_OK to be clear. This is not an error
589                  * condition.
590                  */
591                 (*flagsp) &= ~(EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP);
592         }
593
594         return (ignore);
595 }
596
597 static  __checkReturn   boolean_t
598 siena_ev_rx(
599         __in            efx_evq_t *eep,
600         __in            efx_qword_t *eqp,
601         __in            const efx_ev_callbacks_t *eecp,
602         __in_opt        void *arg)
603 {
604         uint32_t id;
605         uint32_t size;
606         uint32_t label;
607         boolean_t ok;
608         uint32_t hdr_type;
609         boolean_t is_v6;
610         uint16_t flags;
611         boolean_t ignore;
612         boolean_t should_abort;
613
614         EFX_EV_QSTAT_INCR(eep, EV_RX);
615
616         /* Basic packet information */
617         id = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_DESC_PTR);
618         size = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT);
619         label = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_Q_LABEL);
620         ok = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_OK) != 0);
621
622         hdr_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_HDR_TYPE);
623
624         is_v6 = (EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_IPV6_PKT) != 0);
625
626         /*
627          * If packet is marked as OK and packet type is TCP/IP or
628          * UDP/IP or other IP, then we can rely on the hardware checksums.
629          */
630         switch (hdr_type) {
631         case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_TCP:
632                 flags = EFX_PKT_TCP | EFX_CKSUM_TCPUDP;
633                 if (is_v6) {
634                         EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV6);
635                         flags |= EFX_PKT_IPV6;
636                 } else {
637                         EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV4);
638                         flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
639                 }
640                 break;
641
642         case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_UDP:
643                 flags = EFX_PKT_UDP | EFX_CKSUM_TCPUDP;
644                 if (is_v6) {
645                         EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV6);
646                         flags |= EFX_PKT_IPV6;
647                 } else {
648                         EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV4);
649                         flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
650                 }
651                 break;
652
653         case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_OTHER:
654                 if (is_v6) {
655                         EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV6);
656                         flags = EFX_PKT_IPV6;
657                 } else {
658                         EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV4);
659                         flags = EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
660                 }
661                 break;
662
663         case FSE_AZ_RX_EV_HDR_TYPE_OTHER:
664                 EFX_EV_QSTAT_INCR(eep, EV_RX_NON_IP);
665                 flags = 0;
666                 break;
667
668         default:
669                 EFSYS_ASSERT(B_FALSE);
670                 flags = 0;
671                 break;
672         }
673
674         /* Detect errors included in the FSF_AZ_RX_EV_PKT_OK indication */
675         if (!ok) {
676                 ignore = siena_ev_rx_not_ok(eep, eqp, label, id, &flags);
677                 if (ignore) {
678                         EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
679                             uint32_t, size, uint16_t, flags);
680
681                         return (B_FALSE);
682                 }
683         }
684
685         /* If we're not discarding the packet then it is ok */
686         if (~flags & EFX_DISCARD)
687                 EFX_EV_QSTAT_INCR(eep, EV_RX_OK);
688
689         /* Detect multicast packets that didn't match the filter */
690         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_PKT) != 0) {
691                 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_PKT);
692
693                 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_HASH_MATCH) != 0) {
694                         EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_HASH_MATCH);
695                 } else {
696                         EFSYS_PROBE(mcast_mismatch);
697                         flags |= EFX_ADDR_MISMATCH;
698                 }
699         } else {
700                 flags |= EFX_PKT_UNICAST;
701         }
702
703         /*
704          * The packet parser in Siena can abort parsing packets under
705          * certain error conditions, setting the PKT_NOT_PARSED bit
706          * (which clears PKT_OK). If this is set, then don't trust
707          * the PKT_TYPE field.
708          */
709         if (!ok) {
710                 uint32_t parse_err;
711
712                 parse_err = EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_PKT_NOT_PARSED);
713                 if (parse_err != 0)
714                         flags |= EFX_CHECK_VLAN;
715         }
716
717         if (~flags & EFX_CHECK_VLAN) {
718                 uint32_t pkt_type;
719
720                 pkt_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_TYPE);
721                 if (pkt_type >= FSE_AZ_RX_EV_PKT_TYPE_VLAN)
722                         flags |= EFX_PKT_VLAN_TAGGED;
723         }
724
725         EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
726             uint32_t, size, uint16_t, flags);
727
728         EFSYS_ASSERT(eecp->eec_rx != NULL);
729         should_abort = eecp->eec_rx(arg, label, id, size, flags);
730
731         return (should_abort);
732 }
733
734 static  __checkReturn   boolean_t
735 siena_ev_tx(
736         __in            efx_evq_t *eep,
737         __in            efx_qword_t *eqp,
738         __in            const efx_ev_callbacks_t *eecp,
739         __in_opt        void *arg)
740 {
741         uint32_t id;
742         uint32_t label;
743         boolean_t should_abort;
744
745         EFX_EV_QSTAT_INCR(eep, EV_TX);
746
747         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0 &&
748             EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) == 0 &&
749             EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) == 0 &&
750             EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) == 0) {
751
752                 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_DESC_PTR);
753                 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_Q_LABEL);
754
755                 EFSYS_PROBE2(tx_complete, uint32_t, label, uint32_t, id);
756
757                 EFSYS_ASSERT(eecp->eec_tx != NULL);
758                 should_abort = eecp->eec_tx(arg, label, id);
759
760                 return (should_abort);
761         }
762
763         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0)
764                 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
765                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
766                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
767
768         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) != 0)
769                 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_ERR);
770
771         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) != 0)
772                 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_TOO_BIG);
773
774         if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) != 0)
775                 EFX_EV_QSTAT_INCR(eep, EV_TX_WQ_FF_FULL);
776
777         EFX_EV_QSTAT_INCR(eep, EV_TX_UNEXPECTED);
778         return (B_FALSE);
779 }
780
781 static  __checkReturn   boolean_t
782 siena_ev_global(
783         __in            efx_evq_t *eep,
784         __in            efx_qword_t *eqp,
785         __in            const efx_ev_callbacks_t *eecp,
786         __in_opt        void *arg)
787 {
788         _NOTE(ARGUNUSED(eqp, eecp, arg))
789
790         EFX_EV_QSTAT_INCR(eep, EV_GLOBAL);
791
792         return (B_FALSE);
793 }
794
795 static  __checkReturn   boolean_t
796 siena_ev_driver(
797         __in            efx_evq_t *eep,
798         __in            efx_qword_t *eqp,
799         __in            const efx_ev_callbacks_t *eecp,
800         __in_opt        void *arg)
801 {
802         boolean_t should_abort;
803
804         EFX_EV_QSTAT_INCR(eep, EV_DRIVER);
805         should_abort = B_FALSE;
806
807         switch (EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBCODE)) {
808         case FSE_AZ_TX_DESCQ_FLS_DONE_EV: {
809                 uint32_t txq_index;
810
811                 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DESCQ_FLS_DONE);
812
813                 txq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
814
815                 EFSYS_PROBE1(tx_descq_fls_done, uint32_t, txq_index);
816
817                 EFSYS_ASSERT(eecp->eec_txq_flush_done != NULL);
818                 should_abort = eecp->eec_txq_flush_done(arg, txq_index);
819
820                 break;
821         }
822         case FSE_AZ_RX_DESCQ_FLS_DONE_EV: {
823                 uint32_t rxq_index;
824                 uint32_t failed;
825
826                 rxq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
827                 failed = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
828
829                 EFSYS_ASSERT(eecp->eec_rxq_flush_done != NULL);
830                 EFSYS_ASSERT(eecp->eec_rxq_flush_failed != NULL);
831
832                 if (failed) {
833                         EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_FAILED);
834
835                         EFSYS_PROBE1(rx_descq_fls_failed, uint32_t, rxq_index);
836
837                         should_abort = eecp->eec_rxq_flush_failed(arg,
838                                                                     rxq_index);
839                 } else {
840                         EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_DONE);
841
842                         EFSYS_PROBE1(rx_descq_fls_done, uint32_t, rxq_index);
843
844                         should_abort = eecp->eec_rxq_flush_done(arg, rxq_index);
845                 }
846
847                 break;
848         }
849         case FSE_AZ_EVQ_INIT_DONE_EV:
850                 EFSYS_ASSERT(eecp->eec_initialized != NULL);
851                 should_abort = eecp->eec_initialized(arg);
852
853                 break;
854
855         case FSE_AZ_EVQ_NOT_EN_EV:
856                 EFSYS_PROBE(evq_not_en);
857                 break;
858
859         case FSE_AZ_SRM_UPD_DONE_EV: {
860                 uint32_t code;
861
862                 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_SRM_UPD_DONE);
863
864                 code = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
865
866                 EFSYS_ASSERT(eecp->eec_sram != NULL);
867                 should_abort = eecp->eec_sram(arg, code);
868
869                 break;
870         }
871         case FSE_AZ_WAKE_UP_EV: {
872                 uint32_t id;
873
874                 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
875
876                 EFSYS_ASSERT(eecp->eec_wake_up != NULL);
877                 should_abort = eecp->eec_wake_up(arg, id);
878
879                 break;
880         }
881         case FSE_AZ_TX_PKT_NON_TCP_UDP:
882                 EFSYS_PROBE(tx_pkt_non_tcp_udp);
883                 break;
884
885         case FSE_AZ_TIMER_EV: {
886                 uint32_t id;
887
888                 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
889
890                 EFSYS_ASSERT(eecp->eec_timer != NULL);
891                 should_abort = eecp->eec_timer(arg, id);
892
893                 break;
894         }
895         case FSE_AZ_RX_DSC_ERROR_EV:
896                 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DSC_ERROR);
897
898                 EFSYS_PROBE(rx_dsc_error);
899
900                 EFSYS_ASSERT(eecp->eec_exception != NULL);
901                 should_abort = eecp->eec_exception(arg,
902                         EFX_EXCEPTION_RX_DSC_ERROR, 0);
903
904                 break;
905
906         case FSE_AZ_TX_DSC_ERROR_EV:
907                 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DSC_ERROR);
908
909                 EFSYS_PROBE(tx_dsc_error);
910
911                 EFSYS_ASSERT(eecp->eec_exception != NULL);
912                 should_abort = eecp->eec_exception(arg,
913                         EFX_EXCEPTION_TX_DSC_ERROR, 0);
914
915                 break;
916
917         default:
918                 break;
919         }
920
921         return (should_abort);
922 }
923
924 static  __checkReturn   boolean_t
925 siena_ev_drv_gen(
926         __in            efx_evq_t *eep,
927         __in            efx_qword_t *eqp,
928         __in            const efx_ev_callbacks_t *eecp,
929         __in_opt        void *arg)
930 {
931         uint32_t data;
932         boolean_t should_abort;
933
934         EFX_EV_QSTAT_INCR(eep, EV_DRV_GEN);
935
936         data = EFX_QWORD_FIELD(*eqp, FSF_AZ_EV_DATA_DW0);
937         if (data >= ((uint32_t)1 << 16)) {
938                 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
939                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
940                             uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
941                 return (B_TRUE);
942         }
943
944         EFSYS_ASSERT(eecp->eec_software != NULL);
945         should_abort = eecp->eec_software(arg, (uint16_t)data);
946
947         return (should_abort);
948 }
949
950 #if EFSYS_OPT_MCDI
951
952 static  __checkReturn   boolean_t
953 siena_ev_mcdi(
954         __in            efx_evq_t *eep,
955         __in            efx_qword_t *eqp,
956         __in            const efx_ev_callbacks_t *eecp,
957         __in_opt        void *arg)
958 {
959         efx_nic_t *enp = eep->ee_enp;
960         unsigned int code;
961         boolean_t should_abort = B_FALSE;
962
963         EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
964
965         if (enp->en_family != EFX_FAMILY_SIENA)
966                 goto out;
967
968         EFSYS_ASSERT(eecp->eec_link_change != NULL);
969         EFSYS_ASSERT(eecp->eec_exception != NULL);
970
971         EFX_EV_QSTAT_INCR(eep, EV_MCDI_RESPONSE);
972
973         code = EFX_QWORD_FIELD(*eqp, MCDI_EVENT_CODE);
974         switch (code) {
975         case MCDI_EVENT_CODE_BADSSERT:
976                 efx_mcdi_ev_death(enp, EINTR);
977                 break;
978
979         case MCDI_EVENT_CODE_CMDDONE:
980                 efx_mcdi_ev_cpl(enp,
981                     MCDI_EV_FIELD(eqp, CMDDONE_SEQ),
982                     MCDI_EV_FIELD(eqp, CMDDONE_DATALEN),
983                     MCDI_EV_FIELD(eqp, CMDDONE_ERRNO));
984                 break;
985
986         case MCDI_EVENT_CODE_LINKCHANGE: {
987                 efx_link_mode_t link_mode;
988
989                 siena_phy_link_ev(enp, eqp, &link_mode);
990                 should_abort = eecp->eec_link_change(arg, link_mode);
991                 break;
992         }
993         case MCDI_EVENT_CODE_SENSOREVT: {
994                 should_abort = B_FALSE;
995                 break;
996         }
997         case MCDI_EVENT_CODE_SCHEDERR:
998                 /* Informational only */
999                 break;
1000
1001         case MCDI_EVENT_CODE_REBOOT:
1002                 efx_mcdi_ev_death(enp, EIO);
1003                 break;
1004
1005         case MCDI_EVENT_CODE_MAC_STATS_DMA:
1006                 break;
1007
1008         case MCDI_EVENT_CODE_FWALERT: {
1009                 uint32_t reason = MCDI_EV_FIELD(eqp, FWALERT_REASON);
1010
1011                 if (reason == MCDI_EVENT_FWALERT_REASON_SRAM_ACCESS)
1012                         should_abort = eecp->eec_exception(arg,
1013                                 EFX_EXCEPTION_FWALERT_SRAM,
1014                                 MCDI_EV_FIELD(eqp, FWALERT_DATA));
1015                 else
1016                         should_abort = eecp->eec_exception(arg,
1017                                 EFX_EXCEPTION_UNKNOWN_FWALERT,
1018                                 MCDI_EV_FIELD(eqp, DATA));
1019                 break;
1020         }
1021
1022         default:
1023                 EFSYS_PROBE1(mc_pcol_error, int, code);
1024                 break;
1025         }
1026
1027 out:
1028         return (should_abort);
1029 }
1030
1031 #endif  /* EFSYS_OPT_MCDI */
1032
1033 static  __checkReturn   efx_rc_t
1034 siena_ev_qprime(
1035         __in            efx_evq_t *eep,
1036         __in            unsigned int count)
1037 {
1038         efx_nic_t *enp = eep->ee_enp;
1039         uint32_t rptr;
1040         efx_dword_t dword;
1041
1042         rptr = count & eep->ee_mask;
1043
1044         EFX_POPULATE_DWORD_1(dword, FRF_AZ_EVQ_RPTR, rptr);
1045
1046         EFX_BAR_TBL_WRITED(enp, FR_AZ_EVQ_RPTR_REG, eep->ee_index,
1047                             &dword, B_FALSE);
1048
1049         return (0);
1050 }
1051
1052 static          void
1053 siena_ev_qpost(
1054         __in    efx_evq_t *eep,
1055         __in    uint16_t data)
1056 {
1057         efx_nic_t *enp = eep->ee_enp;
1058         efx_qword_t ev;
1059         efx_oword_t oword;
1060
1061         EFX_POPULATE_QWORD_2(ev, FSF_AZ_EV_CODE, FSE_AZ_EV_CODE_DRV_GEN_EV,
1062             FSF_AZ_EV_DATA_DW0, (uint32_t)data);
1063
1064         EFX_POPULATE_OWORD_3(oword, FRF_AZ_DRV_EV_QID, eep->ee_index,
1065             EFX_DWORD_0, EFX_QWORD_FIELD(ev, EFX_DWORD_0),
1066             EFX_DWORD_1, EFX_QWORD_FIELD(ev, EFX_DWORD_1));
1067
1068         EFX_BAR_WRITEO(enp, FR_AZ_DRV_EV_REG, &oword);
1069 }
1070
1071 static  __checkReturn   efx_rc_t
1072 siena_ev_qmoderate(
1073         __in            efx_evq_t *eep,
1074         __in            unsigned int us)
1075 {
1076         efx_nic_t *enp = eep->ee_enp;
1077         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1078         unsigned int locked;
1079         efx_dword_t dword;
1080         efx_rc_t rc;
1081
1082         if (us > encp->enc_evq_timer_max_us) {
1083                 rc = EINVAL;
1084                 goto fail1;
1085         }
1086
1087         /* If the value is zero then disable the timer */
1088         if (us == 0) {
1089                 EFX_POPULATE_DWORD_2(dword,
1090                     FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS,
1091                     FRF_CZ_TC_TIMER_VAL, 0);
1092         } else {
1093                 unsigned int ticks;
1094
1095                 if ((rc = efx_ev_usecs_to_ticks(enp, us, &ticks)) != 0)
1096                         goto fail2;
1097
1098                 EFSYS_ASSERT(ticks > 0);
1099                 EFX_POPULATE_DWORD_2(dword,
1100                     FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_INT_HLDOFF,
1101                     FRF_CZ_TC_TIMER_VAL, ticks - 1);
1102         }
1103
1104         locked = (eep->ee_index == 0) ? 1 : 0;
1105
1106         EFX_BAR_TBL_WRITED(enp, FR_BZ_TIMER_COMMAND_REGP0,
1107             eep->ee_index, &dword, locked);
1108
1109         return (0);
1110
1111 fail2:
1112         EFSYS_PROBE(fail2);
1113 fail1:
1114         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1115
1116         return (rc);
1117 }
1118
1119 static  __checkReturn   efx_rc_t
1120 siena_ev_qcreate(
1121         __in            efx_nic_t *enp,
1122         __in            unsigned int index,
1123         __in            efsys_mem_t *esmp,
1124         __in            size_t n,
1125         __in            uint32_t id,
1126         __in            uint32_t us,
1127         __in            uint32_t flags,
1128         __in            efx_evq_t *eep)
1129 {
1130         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1131         uint32_t size;
1132         efx_oword_t oword;
1133         efx_rc_t rc;
1134         boolean_t notify_mode;
1135
1136         _NOTE(ARGUNUSED(esmp))
1137
1138         EFX_STATIC_ASSERT(ISP2(EFX_EVQ_MAXNEVS));
1139         EFX_STATIC_ASSERT(ISP2(EFX_EVQ_MINNEVS));
1140
1141         if (!ISP2(n) || (n < EFX_EVQ_MINNEVS) || (n > EFX_EVQ_MAXNEVS)) {
1142                 rc = EINVAL;
1143                 goto fail1;
1144         }
1145         if (index >= encp->enc_evq_limit) {
1146                 rc = EINVAL;
1147                 goto fail2;
1148         }
1149         for (size = 0; (1 << size) <= (EFX_EVQ_MAXNEVS / EFX_EVQ_MINNEVS);
1150             size++)
1151                 if ((1 << size) == (int)(n / EFX_EVQ_MINNEVS))
1152                         break;
1153         if (id + (1 << size) >= encp->enc_buftbl_limit) {
1154                 rc = EINVAL;
1155                 goto fail4;
1156         }
1157
1158         /* Set up the handler table */
1159         eep->ee_rx      = siena_ev_rx;
1160         eep->ee_tx      = siena_ev_tx;
1161         eep->ee_driver  = siena_ev_driver;
1162         eep->ee_global  = siena_ev_global;
1163         eep->ee_drv_gen = siena_ev_drv_gen;
1164 #if EFSYS_OPT_MCDI
1165         eep->ee_mcdi    = siena_ev_mcdi;
1166 #endif  /* EFSYS_OPT_MCDI */
1167
1168         notify_mode = ((flags & EFX_EVQ_FLAGS_NOTIFY_MASK) !=
1169             EFX_EVQ_FLAGS_NOTIFY_INTERRUPT);
1170
1171         /* Set up the new event queue */
1172         EFX_POPULATE_OWORD_3(oword, FRF_CZ_TIMER_Q_EN, 1,
1173             FRF_CZ_HOST_NOTIFY_MODE, notify_mode,
1174             FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
1175         EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, index, &oword, B_TRUE);
1176
1177         EFX_POPULATE_OWORD_3(oword, FRF_AZ_EVQ_EN, 1, FRF_AZ_EVQ_SIZE, size,
1178             FRF_AZ_EVQ_BUF_BASE_ID, id);
1179
1180         EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, index, &oword, B_TRUE);
1181
1182         /* Set initial interrupt moderation */
1183         siena_ev_qmoderate(eep, us);
1184
1185         return (0);
1186
1187 fail4:
1188         EFSYS_PROBE(fail4);
1189 fail2:
1190         EFSYS_PROBE(fail2);
1191 fail1:
1192         EFSYS_PROBE1(fail1, efx_rc_t, rc);
1193
1194         return (rc);
1195 }
1196
1197 #endif /* EFSYS_OPT_SIENA */
1198
1199 #if EFSYS_OPT_SIENA
1200
1201 static          void
1202 siena_ev_qdestroy(
1203         __in    efx_evq_t *eep)
1204 {
1205         efx_nic_t *enp = eep->ee_enp;
1206         efx_oword_t oword;
1207
1208         /* Purge event queue */
1209         EFX_ZERO_OWORD(oword);
1210
1211         EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL,
1212             eep->ee_index, &oword, B_TRUE);
1213
1214         EFX_ZERO_OWORD(oword);
1215         EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, eep->ee_index, &oword, B_TRUE);
1216 }
1217
1218 static          void
1219 siena_ev_fini(
1220         __in    efx_nic_t *enp)
1221 {
1222         _NOTE(ARGUNUSED(enp))
1223 }
1224
1225 #endif /* EFSYS_OPT_SIENA */