1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2007-2018 Solarflare Communications Inc.
13 #define EFX_EV_PRESENT(_qword) \
14 (EFX_QWORD_FIELD((_qword), EFX_DWORD_0) != 0xffffffff && \
15 EFX_QWORD_FIELD((_qword), EFX_DWORD_1) != 0xffffffff)
21 static __checkReturn efx_rc_t
29 static __checkReturn efx_rc_t
32 __in unsigned int index,
33 __in efsys_mem_t *esmp,
44 static __checkReturn efx_rc_t
47 __in unsigned int count);
54 static __checkReturn efx_rc_t
57 __in unsigned int us);
61 siena_ev_qstats_update(
63 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat);
67 #endif /* EFSYS_OPT_SIENA */
70 static const efx_ev_ops_t __efx_ev_siena_ops = {
71 siena_ev_init, /* eevo_init */
72 siena_ev_fini, /* eevo_fini */
73 siena_ev_qcreate, /* eevo_qcreate */
74 siena_ev_qdestroy, /* eevo_qdestroy */
75 siena_ev_qprime, /* eevo_qprime */
76 siena_ev_qpost, /* eevo_qpost */
77 siena_ev_qmoderate, /* eevo_qmoderate */
79 siena_ev_qstats_update, /* eevo_qstats_update */
82 #endif /* EFSYS_OPT_SIENA */
85 static const efx_ev_ops_t __efx_ev_ef10_ops = {
86 ef10_ev_init, /* eevo_init */
87 ef10_ev_fini, /* eevo_fini */
88 ef10_ev_qcreate, /* eevo_qcreate */
89 ef10_ev_qdestroy, /* eevo_qdestroy */
90 ef10_ev_qprime, /* eevo_qprime */
91 ef10_ev_qpost, /* eevo_qpost */
92 ef10_ev_qmoderate, /* eevo_qmoderate */
94 ef10_ev_qstats_update, /* eevo_qstats_update */
97 #endif /* EFX_OPTS_EF10() */
100 __checkReturn efx_rc_t
104 const efx_ev_ops_t *eevop;
107 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
108 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
110 if (enp->en_mod_flags & EFX_MOD_EV) {
115 switch (enp->en_family) {
117 case EFX_FAMILY_SIENA:
118 eevop = &__efx_ev_siena_ops;
120 #endif /* EFSYS_OPT_SIENA */
122 #if EFSYS_OPT_HUNTINGTON
123 case EFX_FAMILY_HUNTINGTON:
124 eevop = &__efx_ev_ef10_ops;
126 #endif /* EFSYS_OPT_HUNTINGTON */
128 #if EFSYS_OPT_MEDFORD
129 case EFX_FAMILY_MEDFORD:
130 eevop = &__efx_ev_ef10_ops;
132 #endif /* EFSYS_OPT_MEDFORD */
134 #if EFSYS_OPT_MEDFORD2
135 case EFX_FAMILY_MEDFORD2:
136 eevop = &__efx_ev_ef10_ops;
138 #endif /* EFSYS_OPT_MEDFORD2 */
146 EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
148 if ((rc = eevop->eevo_init(enp)) != 0)
151 enp->en_eevop = eevop;
152 enp->en_mod_flags |= EFX_MOD_EV;
159 EFSYS_PROBE1(fail1, efx_rc_t, rc);
161 enp->en_eevop = NULL;
162 enp->en_mod_flags &= ~EFX_MOD_EV;
168 __in const efx_nic_t *enp,
169 __in unsigned int ndescs)
171 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
173 return (ndescs * encp->enc_ev_desc_size);
176 __checkReturn unsigned int
178 __in const efx_nic_t *enp,
179 __in unsigned int ndescs)
181 return (EFX_DIV_ROUND_UP(efx_evq_size(enp, ndescs), EFX_BUF_SIZE));
188 const efx_ev_ops_t *eevop = enp->en_eevop;
190 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
191 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
192 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
193 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_RX));
194 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_TX));
195 EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
197 eevop->eevo_fini(enp);
199 enp->en_eevop = NULL;
200 enp->en_mod_flags &= ~EFX_MOD_EV;
204 __checkReturn efx_rc_t
207 __in unsigned int index,
208 __in efsys_mem_t *esmp,
213 __deref_out efx_evq_t **eepp)
215 const efx_ev_ops_t *eevop = enp->en_eevop;
217 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
220 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
221 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
223 EFSYS_ASSERT3U(enp->en_ev_qcount + 1, <,
224 enp->en_nic_cfg.enc_evq_limit);
226 switch (flags & EFX_EVQ_FLAGS_NOTIFY_MASK) {
227 case EFX_EVQ_FLAGS_NOTIFY_INTERRUPT:
229 case EFX_EVQ_FLAGS_NOTIFY_DISABLED:
240 EFSYS_ASSERT(ISP2(encp->enc_evq_max_nevs));
241 EFSYS_ASSERT(ISP2(encp->enc_evq_min_nevs));
244 ndescs < encp->enc_evq_min_nevs ||
245 ndescs > encp->enc_evq_max_nevs) {
250 /* Allocate an EVQ object */
251 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_evq_t), eep);
257 eep->ee_magic = EFX_EVQ_MAGIC;
259 eep->ee_index = index;
260 eep->ee_mask = ndescs - 1;
261 eep->ee_flags = flags;
265 * Set outputs before the queue is created because interrupts may be
266 * raised for events immediately after the queue is created, before the
267 * function call below returns. See bug58606.
269 * The eepp pointer passed in by the client must therefore point to data
270 * shared with the client's event processing context.
275 if ((rc = eevop->eevo_qcreate(enp, index, esmp, ndescs, id, us, flags,
286 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
294 EFSYS_PROBE1(fail1, efx_rc_t, rc);
302 efx_nic_t *enp = eep->ee_enp;
303 const efx_ev_ops_t *eevop = enp->en_eevop;
305 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
307 EFSYS_ASSERT(enp->en_ev_qcount != 0);
310 eevop->eevo_qdestroy(eep);
312 /* Free the EVQ object */
313 EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
316 __checkReturn efx_rc_t
319 __in unsigned int count)
321 efx_nic_t *enp = eep->ee_enp;
322 const efx_ev_ops_t *eevop = enp->en_eevop;
325 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
327 if (!(enp->en_mod_flags & EFX_MOD_INTR)) {
332 if ((rc = eevop->eevo_qprime(eep, count)) != 0)
340 EFSYS_PROBE1(fail1, efx_rc_t, rc);
344 __checkReturn boolean_t
347 __in unsigned int count)
352 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
354 offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
355 EFSYS_MEM_READQ(eep->ee_esmp, offset, &qword);
357 return (EFX_EV_PRESENT(qword));
360 #if EFSYS_OPT_EV_PREFETCH
365 __in unsigned int count)
369 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
371 offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
372 EFSYS_MEM_PREFETCH(eep->ee_esmp, offset);
375 #endif /* EFSYS_OPT_EV_PREFETCH */
377 #define EFX_EV_BATCH 8
382 __inout unsigned int *countp,
383 __in const efx_ev_callbacks_t *eecp,
386 efx_qword_t ev[EFX_EV_BATCH];
393 /* Ensure events codes match for EF10 (Huntington/Medford) and Siena */
394 EFX_STATIC_ASSERT(ESF_DZ_EV_CODE_LBN == FSF_AZ_EV_CODE_LBN);
395 EFX_STATIC_ASSERT(ESF_DZ_EV_CODE_WIDTH == FSF_AZ_EV_CODE_WIDTH);
397 EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_RX_EV == FSE_AZ_EV_CODE_RX_EV);
398 EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_TX_EV == FSE_AZ_EV_CODE_TX_EV);
399 EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_DRIVER_EV == FSE_AZ_EV_CODE_DRIVER_EV);
400 EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_DRV_GEN_EV ==
401 FSE_AZ_EV_CODE_DRV_GEN_EV);
403 EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_MCDI_EV ==
404 FSE_AZ_EV_CODE_MCDI_EVRESPONSE);
407 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
408 EFSYS_ASSERT(countp != NULL);
409 EFSYS_ASSERT(eecp != NULL);
413 /* Read up until the end of the batch period */
414 batch = EFX_EV_BATCH - (count & (EFX_EV_BATCH - 1));
415 offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
416 for (total = 0; total < batch; ++total) {
417 EFSYS_MEM_READQ(eep->ee_esmp, offset, &(ev[total]));
419 if (!EFX_EV_PRESENT(ev[total]))
422 EFSYS_PROBE3(event, unsigned int, eep->ee_index,
423 uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_1),
424 uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_0));
426 offset += sizeof (efx_qword_t);
429 #if EFSYS_OPT_EV_PREFETCH && (EFSYS_OPT_EV_PREFETCH_PERIOD > 1)
431 * Prefetch the next batch when we get within PREFETCH_PERIOD
432 * of a completed batch. If the batch is smaller, then prefetch
435 if (total == batch && total < EFSYS_OPT_EV_PREFETCH_PERIOD)
436 EFSYS_MEM_PREFETCH(eep->ee_esmp, offset);
437 #endif /* EFSYS_OPT_EV_PREFETCH */
439 /* Process the batch of events */
440 for (index = 0; index < total; ++index) {
441 boolean_t should_abort;
444 #if EFSYS_OPT_EV_PREFETCH
445 /* Prefetch if we've now reached the batch period */
446 if (total == batch &&
447 index + EFSYS_OPT_EV_PREFETCH_PERIOD == total) {
448 offset = (count + batch) & eep->ee_mask;
449 offset *= sizeof (efx_qword_t);
451 EFSYS_MEM_PREFETCH(eep->ee_esmp, offset);
453 #endif /* EFSYS_OPT_EV_PREFETCH */
455 EFX_EV_QSTAT_INCR(eep, EV_ALL);
457 code = EFX_QWORD_FIELD(ev[index], FSF_AZ_EV_CODE);
459 case FSE_AZ_EV_CODE_RX_EV:
460 should_abort = eep->ee_rx(eep,
461 &(ev[index]), eecp, arg);
463 case FSE_AZ_EV_CODE_TX_EV:
464 should_abort = eep->ee_tx(eep,
465 &(ev[index]), eecp, arg);
467 case FSE_AZ_EV_CODE_DRIVER_EV:
468 should_abort = eep->ee_driver(eep,
469 &(ev[index]), eecp, arg);
471 case FSE_AZ_EV_CODE_DRV_GEN_EV:
472 should_abort = eep->ee_drv_gen(eep,
473 &(ev[index]), eecp, arg);
476 case FSE_AZ_EV_CODE_MCDI_EVRESPONSE:
477 should_abort = eep->ee_mcdi(eep,
478 &(ev[index]), eecp, arg);
481 case FSE_AZ_EV_CODE_GLOBAL_EV:
482 if (eep->ee_global) {
483 should_abort = eep->ee_global(eep,
484 &(ev[index]), eecp, arg);
487 /* else fallthrough */
489 EFSYS_PROBE3(bad_event,
490 unsigned int, eep->ee_index,
492 EFX_QWORD_FIELD(ev[index], EFX_DWORD_1),
494 EFX_QWORD_FIELD(ev[index], EFX_DWORD_0));
496 EFSYS_ASSERT(eecp->eec_exception != NULL);
497 (void) eecp->eec_exception(arg,
498 EFX_EXCEPTION_EV_ERROR, code);
499 should_abort = B_TRUE;
502 /* Ignore subsequent events */
506 * Poison batch to ensure the outer
507 * loop is broken out of.
509 EFSYS_ASSERT(batch <= EFX_EV_BATCH);
510 batch += (EFX_EV_BATCH << 1);
511 EFSYS_ASSERT(total != batch);
517 * Now that the hardware has most likely moved onto dma'ing
518 * into the next cache line, clear the processed events. Take
519 * care to only clear out events that we've processed
521 EFX_SET_QWORD(ev[0]);
522 offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
523 for (index = 0; index < total; ++index) {
524 EFSYS_MEM_WRITEQ(eep->ee_esmp, offset, &(ev[0]));
525 offset += sizeof (efx_qword_t);
530 } while (total == batch);
540 efx_nic_t *enp = eep->ee_enp;
541 const efx_ev_ops_t *eevop = enp->en_eevop;
543 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
545 EFSYS_ASSERT(eevop != NULL &&
546 eevop->eevo_qpost != NULL);
548 eevop->eevo_qpost(eep, data);
551 __checkReturn efx_rc_t
552 efx_ev_usecs_to_ticks(
554 __in unsigned int us,
555 __out unsigned int *ticksp)
557 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
561 if (encp->enc_evq_timer_quantum_ns == 0) {
566 /* Convert microseconds to a timer tick count */
569 else if (us * 1000 < encp->enc_evq_timer_quantum_ns)
570 ticks = 1; /* Never round down to zero */
572 ticks = us * 1000 / encp->enc_evq_timer_quantum_ns;
578 EFSYS_PROBE1(fail1, efx_rc_t, rc);
582 __checkReturn efx_rc_t
585 __in unsigned int us)
587 efx_nic_t *enp = eep->ee_enp;
588 const efx_ev_ops_t *eevop = enp->en_eevop;
591 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
593 if ((eep->ee_flags & EFX_EVQ_FLAGS_NOTIFY_MASK) ==
594 EFX_EVQ_FLAGS_NOTIFY_DISABLED) {
599 if ((rc = eevop->eevo_qmoderate(eep, us)) != 0)
607 EFSYS_PROBE1(fail1, efx_rc_t, rc);
613 efx_ev_qstats_update(
615 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat)
617 { efx_nic_t *enp = eep->ee_enp;
618 const efx_ev_ops_t *eevop = enp->en_eevop;
620 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
622 eevop->eevo_qstats_update(eep, stat);
625 #endif /* EFSYS_OPT_QSTATS */
629 static __checkReturn efx_rc_t
636 * Program the event queue for receive and transmit queue
639 EFX_BAR_READO(enp, FR_AZ_DP_CTRL_REG, &oword);
640 EFX_SET_OWORD_FIELD(oword, FRF_AZ_FLS_EVQ_ID, 0);
641 EFX_BAR_WRITEO(enp, FR_AZ_DP_CTRL_REG, &oword);
647 static __checkReturn boolean_t
650 __in efx_qword_t *eqp,
653 __inout uint16_t *flagsp)
655 boolean_t ignore = B_FALSE;
657 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TOBE_DISC) != 0) {
658 EFX_EV_QSTAT_INCR(eep, EV_RX_TOBE_DISC);
659 EFSYS_PROBE(tobe_disc);
661 * Assume this is a unicast address mismatch, unless below
662 * we find either FSF_AZ_RX_EV_ETH_CRC_ERR or
663 * EV_RX_PAUSE_FRM_ERR is set.
665 (*flagsp) |= EFX_ADDR_MISMATCH;
668 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_FRM_TRUNC) != 0) {
669 EFSYS_PROBE2(frm_trunc, uint32_t, label, uint32_t, id);
670 EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC);
671 (*flagsp) |= EFX_DISCARD;
673 #if EFSYS_OPT_RX_SCATTER
675 * Lookout for payload queue ran dry errors and ignore them.
677 * Sadly for the header/data split cases, the descriptor
678 * pointer in this event refers to the header queue and
679 * therefore cannot be easily detected as duplicate.
680 * So we drop these and rely on the receive processing seeing
681 * a subsequent packet with FSF_AZ_RX_EV_SOP set to discard
682 * the partially received packet.
684 if ((EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) == 0) &&
685 (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) == 0) &&
686 (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT) == 0))
688 #endif /* EFSYS_OPT_RX_SCATTER */
691 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_ETH_CRC_ERR) != 0) {
692 EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR);
693 EFSYS_PROBE(crc_err);
694 (*flagsp) &= ~EFX_ADDR_MISMATCH;
695 (*flagsp) |= EFX_DISCARD;
698 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PAUSE_FRM_ERR) != 0) {
699 EFX_EV_QSTAT_INCR(eep, EV_RX_PAUSE_FRM_ERR);
700 EFSYS_PROBE(pause_frm_err);
701 (*flagsp) &= ~EFX_ADDR_MISMATCH;
702 (*flagsp) |= EFX_DISCARD;
705 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BUF_OWNER_ID_ERR) != 0) {
706 EFX_EV_QSTAT_INCR(eep, EV_RX_BUF_OWNER_ID_ERR);
707 EFSYS_PROBE(owner_id_err);
708 (*flagsp) |= EFX_DISCARD;
711 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR) != 0) {
712 EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR);
713 EFSYS_PROBE(ipv4_err);
714 (*flagsp) &= ~EFX_CKSUM_IPV4;
717 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR) != 0) {
718 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR);
719 EFSYS_PROBE(udp_chk_err);
720 (*flagsp) &= ~EFX_CKSUM_TCPUDP;
723 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_FRAG_ERR) != 0) {
724 EFX_EV_QSTAT_INCR(eep, EV_RX_IP_FRAG_ERR);
727 * If IP is fragmented FSF_AZ_RX_EV_IP_FRAG_ERR is set. This
728 * causes FSF_AZ_RX_EV_PKT_OK to be clear. This is not an error
731 (*flagsp) &= ~(EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP);
737 static __checkReturn boolean_t
740 __in efx_qword_t *eqp,
741 __in const efx_ev_callbacks_t *eecp,
748 #if EFSYS_OPT_RX_SCATTER
750 boolean_t jumbo_cont;
751 #endif /* EFSYS_OPT_RX_SCATTER */
756 boolean_t should_abort;
758 EFX_EV_QSTAT_INCR(eep, EV_RX);
760 /* Basic packet information */
761 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_DESC_PTR);
762 size = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT);
763 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_Q_LABEL);
764 ok = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_OK) != 0);
766 #if EFSYS_OPT_RX_SCATTER
767 sop = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) != 0);
768 jumbo_cont = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) != 0);
769 #endif /* EFSYS_OPT_RX_SCATTER */
771 hdr_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_HDR_TYPE);
773 is_v6 = (EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_IPV6_PKT) != 0);
776 * If packet is marked as OK and packet type is TCP/IP or
777 * UDP/IP or other IP, then we can rely on the hardware checksums.
780 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_TCP:
781 flags = EFX_PKT_TCP | EFX_CKSUM_TCPUDP;
783 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV6);
784 flags |= EFX_PKT_IPV6;
786 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV4);
787 flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
791 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_UDP:
792 flags = EFX_PKT_UDP | EFX_CKSUM_TCPUDP;
794 EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV6);
795 flags |= EFX_PKT_IPV6;
797 EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV4);
798 flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
802 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_OTHER:
804 EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV6);
805 flags = EFX_PKT_IPV6;
807 EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV4);
808 flags = EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
812 case FSE_AZ_RX_EV_HDR_TYPE_OTHER:
813 EFX_EV_QSTAT_INCR(eep, EV_RX_NON_IP);
818 EFSYS_ASSERT(B_FALSE);
823 #if EFSYS_OPT_RX_SCATTER
824 /* Report scatter and header/lookahead split buffer flags */
826 flags |= EFX_PKT_START;
828 flags |= EFX_PKT_CONT;
829 #endif /* EFSYS_OPT_RX_SCATTER */
831 /* Detect errors included in the FSF_AZ_RX_EV_PKT_OK indication */
833 ignore = siena_ev_rx_not_ok(eep, eqp, label, id, &flags);
835 EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
836 uint32_t, size, uint16_t, flags);
842 /* If we're not discarding the packet then it is ok */
843 if (~flags & EFX_DISCARD)
844 EFX_EV_QSTAT_INCR(eep, EV_RX_OK);
846 /* Detect multicast packets that didn't match the filter */
847 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_PKT) != 0) {
848 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_PKT);
850 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_HASH_MATCH) != 0) {
851 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_HASH_MATCH);
853 EFSYS_PROBE(mcast_mismatch);
854 flags |= EFX_ADDR_MISMATCH;
857 flags |= EFX_PKT_UNICAST;
861 * The packet parser in Siena can abort parsing packets under
862 * certain error conditions, setting the PKT_NOT_PARSED bit
863 * (which clears PKT_OK). If this is set, then don't trust
864 * the PKT_TYPE field.
869 parse_err = EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_PKT_NOT_PARSED);
871 flags |= EFX_CHECK_VLAN;
874 if (~flags & EFX_CHECK_VLAN) {
877 pkt_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_TYPE);
878 if (pkt_type >= FSE_AZ_RX_EV_PKT_TYPE_VLAN)
879 flags |= EFX_PKT_VLAN_TAGGED;
882 EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
883 uint32_t, size, uint16_t, flags);
885 EFSYS_ASSERT(eecp->eec_rx != NULL);
886 should_abort = eecp->eec_rx(arg, label, id, size, flags);
888 return (should_abort);
891 static __checkReturn boolean_t
894 __in efx_qword_t *eqp,
895 __in const efx_ev_callbacks_t *eecp,
900 boolean_t should_abort;
902 EFX_EV_QSTAT_INCR(eep, EV_TX);
904 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0 &&
905 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) == 0 &&
906 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) == 0 &&
907 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) == 0) {
909 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_DESC_PTR);
910 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_Q_LABEL);
912 EFSYS_PROBE2(tx_complete, uint32_t, label, uint32_t, id);
914 EFSYS_ASSERT(eecp->eec_tx != NULL);
915 should_abort = eecp->eec_tx(arg, label, id);
917 return (should_abort);
920 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0)
921 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
922 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
923 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
925 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) != 0)
926 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_ERR);
928 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) != 0)
929 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_TOO_BIG);
931 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) != 0)
932 EFX_EV_QSTAT_INCR(eep, EV_TX_WQ_FF_FULL);
934 EFX_EV_QSTAT_INCR(eep, EV_TX_UNEXPECTED);
938 static __checkReturn boolean_t
941 __in efx_qword_t *eqp,
942 __in const efx_ev_callbacks_t *eecp,
945 _NOTE(ARGUNUSED(eqp, eecp, arg))
947 EFX_EV_QSTAT_INCR(eep, EV_GLOBAL);
952 static __checkReturn boolean_t
955 __in efx_qword_t *eqp,
956 __in const efx_ev_callbacks_t *eecp,
959 boolean_t should_abort;
961 EFX_EV_QSTAT_INCR(eep, EV_DRIVER);
962 should_abort = B_FALSE;
964 switch (EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBCODE)) {
965 case FSE_AZ_TX_DESCQ_FLS_DONE_EV: {
968 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DESCQ_FLS_DONE);
970 txq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
972 EFSYS_PROBE1(tx_descq_fls_done, uint32_t, txq_index);
974 EFSYS_ASSERT(eecp->eec_txq_flush_done != NULL);
975 should_abort = eecp->eec_txq_flush_done(arg, txq_index);
979 case FSE_AZ_RX_DESCQ_FLS_DONE_EV: {
983 rxq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
984 failed = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
986 EFSYS_ASSERT(eecp->eec_rxq_flush_done != NULL);
987 EFSYS_ASSERT(eecp->eec_rxq_flush_failed != NULL);
990 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_FAILED);
992 EFSYS_PROBE1(rx_descq_fls_failed, uint32_t, rxq_index);
994 should_abort = eecp->eec_rxq_flush_failed(arg,
997 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_DONE);
999 EFSYS_PROBE1(rx_descq_fls_done, uint32_t, rxq_index);
1001 should_abort = eecp->eec_rxq_flush_done(arg, rxq_index);
1006 case FSE_AZ_EVQ_INIT_DONE_EV:
1007 EFSYS_ASSERT(eecp->eec_initialized != NULL);
1008 should_abort = eecp->eec_initialized(arg);
1012 case FSE_AZ_EVQ_NOT_EN_EV:
1013 EFSYS_PROBE(evq_not_en);
1016 case FSE_AZ_SRM_UPD_DONE_EV: {
1019 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_SRM_UPD_DONE);
1021 code = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
1023 EFSYS_ASSERT(eecp->eec_sram != NULL);
1024 should_abort = eecp->eec_sram(arg, code);
1028 case FSE_AZ_WAKE_UP_EV: {
1031 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
1033 EFSYS_ASSERT(eecp->eec_wake_up != NULL);
1034 should_abort = eecp->eec_wake_up(arg, id);
1038 case FSE_AZ_TX_PKT_NON_TCP_UDP:
1039 EFSYS_PROBE(tx_pkt_non_tcp_udp);
1042 case FSE_AZ_TIMER_EV: {
1045 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
1047 EFSYS_ASSERT(eecp->eec_timer != NULL);
1048 should_abort = eecp->eec_timer(arg, id);
1052 case FSE_AZ_RX_DSC_ERROR_EV:
1053 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DSC_ERROR);
1055 EFSYS_PROBE(rx_dsc_error);
1057 EFSYS_ASSERT(eecp->eec_exception != NULL);
1058 should_abort = eecp->eec_exception(arg,
1059 EFX_EXCEPTION_RX_DSC_ERROR, 0);
1063 case FSE_AZ_TX_DSC_ERROR_EV:
1064 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DSC_ERROR);
1066 EFSYS_PROBE(tx_dsc_error);
1068 EFSYS_ASSERT(eecp->eec_exception != NULL);
1069 should_abort = eecp->eec_exception(arg,
1070 EFX_EXCEPTION_TX_DSC_ERROR, 0);
1078 return (should_abort);
1081 static __checkReturn boolean_t
1083 __in efx_evq_t *eep,
1084 __in efx_qword_t *eqp,
1085 __in const efx_ev_callbacks_t *eecp,
1089 boolean_t should_abort;
1091 EFX_EV_QSTAT_INCR(eep, EV_DRV_GEN);
1093 data = EFX_QWORD_FIELD(*eqp, FSF_AZ_EV_DATA_DW0);
1094 if (data >= ((uint32_t)1 << 16)) {
1095 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
1096 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
1097 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
1101 EFSYS_ASSERT(eecp->eec_software != NULL);
1102 should_abort = eecp->eec_software(arg, (uint16_t)data);
1104 return (should_abort);
1109 static __checkReturn boolean_t
1111 __in efx_evq_t *eep,
1112 __in efx_qword_t *eqp,
1113 __in const efx_ev_callbacks_t *eecp,
1116 efx_nic_t *enp = eep->ee_enp;
1118 boolean_t should_abort = B_FALSE;
1120 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
1122 if (enp->en_family != EFX_FAMILY_SIENA)
1125 EFSYS_ASSERT(eecp->eec_link_change != NULL);
1126 EFSYS_ASSERT(eecp->eec_exception != NULL);
1127 #if EFSYS_OPT_MON_STATS
1128 EFSYS_ASSERT(eecp->eec_monitor != NULL);
1131 EFX_EV_QSTAT_INCR(eep, EV_MCDI_RESPONSE);
1133 code = EFX_QWORD_FIELD(*eqp, MCDI_EVENT_CODE);
1135 case MCDI_EVENT_CODE_BADSSERT:
1136 efx_mcdi_ev_death(enp, EINTR);
1139 case MCDI_EVENT_CODE_CMDDONE:
1140 efx_mcdi_ev_cpl(enp,
1141 MCDI_EV_FIELD(eqp, CMDDONE_SEQ),
1142 MCDI_EV_FIELD(eqp, CMDDONE_DATALEN),
1143 MCDI_EV_FIELD(eqp, CMDDONE_ERRNO));
1146 case MCDI_EVENT_CODE_LINKCHANGE: {
1147 efx_link_mode_t link_mode;
1149 siena_phy_link_ev(enp, eqp, &link_mode);
1150 should_abort = eecp->eec_link_change(arg, link_mode);
1153 case MCDI_EVENT_CODE_SENSOREVT: {
1154 #if EFSYS_OPT_MON_STATS
1156 efx_mon_stat_value_t value;
1159 if ((rc = mcdi_mon_ev(enp, eqp, &id, &value)) == 0)
1160 should_abort = eecp->eec_monitor(arg, id, value);
1161 else if (rc == ENOTSUP) {
1162 should_abort = eecp->eec_exception(arg,
1163 EFX_EXCEPTION_UNKNOWN_SENSOREVT,
1164 MCDI_EV_FIELD(eqp, DATA));
1166 EFSYS_ASSERT(rc == ENODEV); /* Wrong port */
1168 should_abort = B_FALSE;
1172 case MCDI_EVENT_CODE_SCHEDERR:
1173 /* Informational only */
1176 case MCDI_EVENT_CODE_REBOOT:
1177 efx_mcdi_ev_death(enp, EIO);
1180 case MCDI_EVENT_CODE_MAC_STATS_DMA:
1181 #if EFSYS_OPT_MAC_STATS
1182 if (eecp->eec_mac_stats != NULL) {
1183 eecp->eec_mac_stats(arg,
1184 MCDI_EV_FIELD(eqp, MAC_STATS_DMA_GENERATION));
1189 case MCDI_EVENT_CODE_FWALERT: {
1190 uint32_t reason = MCDI_EV_FIELD(eqp, FWALERT_REASON);
1192 if (reason == MCDI_EVENT_FWALERT_REASON_SRAM_ACCESS)
1193 should_abort = eecp->eec_exception(arg,
1194 EFX_EXCEPTION_FWALERT_SRAM,
1195 MCDI_EV_FIELD(eqp, FWALERT_DATA));
1197 should_abort = eecp->eec_exception(arg,
1198 EFX_EXCEPTION_UNKNOWN_FWALERT,
1199 MCDI_EV_FIELD(eqp, DATA));
1204 EFSYS_PROBE1(mc_pcol_error, int, code);
1209 return (should_abort);
1212 #endif /* EFSYS_OPT_MCDI */
1214 static __checkReturn efx_rc_t
1216 __in efx_evq_t *eep,
1217 __in unsigned int count)
1219 efx_nic_t *enp = eep->ee_enp;
1223 rptr = count & eep->ee_mask;
1225 EFX_POPULATE_DWORD_1(dword, FRF_AZ_EVQ_RPTR, rptr);
1227 EFX_BAR_TBL_WRITED(enp, FR_AZ_EVQ_RPTR_REG, eep->ee_index,
1235 __in efx_evq_t *eep,
1238 efx_nic_t *enp = eep->ee_enp;
1242 EFX_POPULATE_QWORD_2(ev, FSF_AZ_EV_CODE, FSE_AZ_EV_CODE_DRV_GEN_EV,
1243 FSF_AZ_EV_DATA_DW0, (uint32_t)data);
1245 EFX_POPULATE_OWORD_3(oword, FRF_AZ_DRV_EV_QID, eep->ee_index,
1246 EFX_DWORD_0, EFX_QWORD_FIELD(ev, EFX_DWORD_0),
1247 EFX_DWORD_1, EFX_QWORD_FIELD(ev, EFX_DWORD_1));
1249 EFX_BAR_WRITEO(enp, FR_AZ_DRV_EV_REG, &oword);
1252 static __checkReturn efx_rc_t
1254 __in efx_evq_t *eep,
1255 __in unsigned int us)
1257 efx_nic_t *enp = eep->ee_enp;
1258 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1259 unsigned int locked;
1263 if (us > encp->enc_evq_timer_max_us) {
1268 /* If the value is zero then disable the timer */
1270 EFX_POPULATE_DWORD_2(dword,
1271 FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS,
1272 FRF_CZ_TC_TIMER_VAL, 0);
1276 if ((rc = efx_ev_usecs_to_ticks(enp, us, &ticks)) != 0)
1279 EFSYS_ASSERT(ticks > 0);
1280 EFX_POPULATE_DWORD_2(dword,
1281 FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_INT_HLDOFF,
1282 FRF_CZ_TC_TIMER_VAL, ticks - 1);
1285 locked = (eep->ee_index == 0) ? 1 : 0;
1287 EFX_BAR_TBL_WRITED(enp, FR_BZ_TIMER_COMMAND_REGP0,
1288 eep->ee_index, &dword, locked);
1295 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1300 static __checkReturn efx_rc_t
1302 __in efx_nic_t *enp,
1303 __in unsigned int index,
1304 __in efsys_mem_t *esmp,
1308 __in uint32_t flags,
1309 __in efx_evq_t *eep)
1311 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1315 boolean_t notify_mode;
1317 _NOTE(ARGUNUSED(esmp))
1319 if (index >= encp->enc_evq_limit) {
1323 #if EFSYS_OPT_RX_SCALE
1324 if (enp->en_intr.ei_type == EFX_INTR_LINE &&
1325 index >= EFX_MAXRSS_LEGACY) {
1331 (1U << size) <= encp->enc_evq_max_nevs / encp->enc_evq_min_nevs;
1333 if ((1U << size) == (uint32_t)ndescs / encp->enc_evq_min_nevs)
1335 if (id + (1 << size) >= encp->enc_buftbl_limit) {
1340 /* Set up the handler table */
1341 eep->ee_rx = siena_ev_rx;
1342 eep->ee_tx = siena_ev_tx;
1343 eep->ee_driver = siena_ev_driver;
1344 eep->ee_global = siena_ev_global;
1345 eep->ee_drv_gen = siena_ev_drv_gen;
1347 eep->ee_mcdi = siena_ev_mcdi;
1348 #endif /* EFSYS_OPT_MCDI */
1350 notify_mode = ((flags & EFX_EVQ_FLAGS_NOTIFY_MASK) !=
1351 EFX_EVQ_FLAGS_NOTIFY_INTERRUPT);
1353 /* Set up the new event queue */
1354 EFX_POPULATE_OWORD_3(oword, FRF_CZ_TIMER_Q_EN, 1,
1355 FRF_CZ_HOST_NOTIFY_MODE, notify_mode,
1356 FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
1357 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, index, &oword, B_TRUE);
1359 EFX_POPULATE_OWORD_3(oword, FRF_AZ_EVQ_EN, 1, FRF_AZ_EVQ_SIZE, size,
1360 FRF_AZ_EVQ_BUF_BASE_ID, id);
1362 EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, index, &oword, B_TRUE);
1364 /* Set initial interrupt moderation */
1365 siena_ev_qmoderate(eep, us);
1371 #if EFSYS_OPT_RX_SCALE
1376 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1381 #endif /* EFSYS_OPT_SIENA */
1383 #if EFSYS_OPT_QSTATS
1385 /* START MKCONFIG GENERATED EfxEventQueueStatNamesBlock ac223f7134058b4f */
1386 static const char * const __efx_ev_qstat_name[] = {
1393 "rx_buf_owner_id_err",
1394 "rx_ipv4_hdr_chksum_err",
1395 "rx_tcp_udp_chksum_err",
1399 "rx_mcast_hash_match",
1416 "driver_srm_upd_done",
1417 "driver_tx_descq_fls_done",
1418 "driver_rx_descq_fls_done",
1419 "driver_rx_descq_fls_failed",
1420 "driver_rx_dsc_error",
1421 "driver_tx_dsc_error",
1424 "rx_parse_incomplete",
1426 /* END MKCONFIG GENERATED EfxEventQueueStatNamesBlock */
1430 __in efx_nic_t *enp,
1431 __in unsigned int id)
1433 _NOTE(ARGUNUSED(enp))
1435 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
1436 EFSYS_ASSERT3U(id, <, EV_NQSTATS);
1438 return (__efx_ev_qstat_name[id]);
1440 #endif /* EFSYS_OPT_NAMES */
1441 #endif /* EFSYS_OPT_QSTATS */
1445 #if EFSYS_OPT_QSTATS
1447 siena_ev_qstats_update(
1448 __in efx_evq_t *eep,
1449 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat)
1453 for (id = 0; id < EV_NQSTATS; id++) {
1454 efsys_stat_t *essp = &stat[id];
1456 EFSYS_STAT_INCR(essp, eep->ee_stat[id]);
1457 eep->ee_stat[id] = 0;
1460 #endif /* EFSYS_OPT_QSTATS */
1464 __in efx_evq_t *eep)
1466 efx_nic_t *enp = eep->ee_enp;
1469 /* Purge event queue */
1470 EFX_ZERO_OWORD(oword);
1472 EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL,
1473 eep->ee_index, &oword, B_TRUE);
1475 EFX_ZERO_OWORD(oword);
1476 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, eep->ee_index, &oword, B_TRUE);
1481 __in efx_nic_t *enp)
1483 _NOTE(ARGUNUSED(enp))
1486 #endif /* EFSYS_OPT_SIENA */