2 * Copyright (c) 2007-2016 Solarflare Communications Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
36 #if EFSYS_OPT_MON_MCDI
41 #define EFX_EV_QSTAT_INCR(_eep, _stat) \
43 (_eep)->ee_stat[_stat]++; \
44 _NOTE(CONSTANTCONDITION) \
47 #define EFX_EV_QSTAT_INCR(_eep, _stat)
50 #define EFX_EV_PRESENT(_qword) \
51 (EFX_QWORD_FIELD((_qword), EFX_DWORD_0) != 0xffffffff && \
52 EFX_QWORD_FIELD((_qword), EFX_DWORD_1) != 0xffffffff)
58 static __checkReturn efx_rc_t
66 static __checkReturn efx_rc_t
69 __in unsigned int index,
70 __in efsys_mem_t *esmp,
81 static __checkReturn efx_rc_t
84 __in unsigned int count);
91 static __checkReturn efx_rc_t
94 __in unsigned int us);
98 siena_ev_qstats_update(
100 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat);
104 #endif /* EFSYS_OPT_SIENA */
107 static const efx_ev_ops_t __efx_ev_siena_ops = {
108 siena_ev_init, /* eevo_init */
109 siena_ev_fini, /* eevo_fini */
110 siena_ev_qcreate, /* eevo_qcreate */
111 siena_ev_qdestroy, /* eevo_qdestroy */
112 siena_ev_qprime, /* eevo_qprime */
113 siena_ev_qpost, /* eevo_qpost */
114 siena_ev_qmoderate, /* eevo_qmoderate */
116 siena_ev_qstats_update, /* eevo_qstats_update */
119 #endif /* EFSYS_OPT_SIENA */
121 #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
122 static const efx_ev_ops_t __efx_ev_ef10_ops = {
123 ef10_ev_init, /* eevo_init */
124 ef10_ev_fini, /* eevo_fini */
125 ef10_ev_qcreate, /* eevo_qcreate */
126 ef10_ev_qdestroy, /* eevo_qdestroy */
127 ef10_ev_qprime, /* eevo_qprime */
128 ef10_ev_qpost, /* eevo_qpost */
129 ef10_ev_qmoderate, /* eevo_qmoderate */
131 ef10_ev_qstats_update, /* eevo_qstats_update */
134 #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
137 __checkReturn efx_rc_t
141 const efx_ev_ops_t *eevop;
144 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
145 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
147 if (enp->en_mod_flags & EFX_MOD_EV) {
152 switch (enp->en_family) {
154 case EFX_FAMILY_SIENA:
155 eevop = &__efx_ev_siena_ops;
157 #endif /* EFSYS_OPT_SIENA */
159 #if EFSYS_OPT_HUNTINGTON
160 case EFX_FAMILY_HUNTINGTON:
161 eevop = &__efx_ev_ef10_ops;
163 #endif /* EFSYS_OPT_HUNTINGTON */
165 #if EFSYS_OPT_MEDFORD
166 case EFX_FAMILY_MEDFORD:
167 eevop = &__efx_ev_ef10_ops;
169 #endif /* EFSYS_OPT_MEDFORD */
177 EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
179 if ((rc = eevop->eevo_init(enp)) != 0)
182 enp->en_eevop = eevop;
183 enp->en_mod_flags |= EFX_MOD_EV;
190 EFSYS_PROBE1(fail1, efx_rc_t, rc);
192 enp->en_eevop = NULL;
193 enp->en_mod_flags &= ~EFX_MOD_EV;
201 const efx_ev_ops_t *eevop = enp->en_eevop;
203 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
204 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
205 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
206 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_RX));
207 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_TX));
208 EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
210 eevop->eevo_fini(enp);
212 enp->en_eevop = NULL;
213 enp->en_mod_flags &= ~EFX_MOD_EV;
217 __checkReturn efx_rc_t
220 __in unsigned int index,
221 __in efsys_mem_t *esmp,
226 __deref_out efx_evq_t **eepp)
228 const efx_ev_ops_t *eevop = enp->en_eevop;
232 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
233 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
235 EFSYS_ASSERT3U(enp->en_ev_qcount + 1, <,
236 enp->en_nic_cfg.enc_evq_limit);
238 switch (flags & EFX_EVQ_FLAGS_NOTIFY_MASK) {
239 case EFX_EVQ_FLAGS_NOTIFY_INTERRUPT:
241 case EFX_EVQ_FLAGS_NOTIFY_DISABLED:
252 /* Allocate an EVQ object */
253 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_evq_t), eep);
259 eep->ee_magic = EFX_EVQ_MAGIC;
261 eep->ee_index = index;
262 eep->ee_mask = n - 1;
263 eep->ee_flags = flags;
267 * Set outputs before the queue is created because interrupts may be
268 * raised for events immediately after the queue is created, before the
269 * function call below returns. See bug58606.
271 * The eepp pointer passed in by the client must therefore point to data
272 * shared with the client's event processing context.
277 if ((rc = eevop->eevo_qcreate(enp, index, esmp, n, id, us, flags,
288 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);
560 /* Convert microseconds to a timer tick count */
563 else if (us * 1000 < encp->enc_evq_timer_quantum_ns)
564 ticks = 1; /* Never round down to zero */
566 ticks = us * 1000 / encp->enc_evq_timer_quantum_ns;
572 __checkReturn efx_rc_t
575 __in unsigned int us)
577 efx_nic_t *enp = eep->ee_enp;
578 const efx_ev_ops_t *eevop = enp->en_eevop;
581 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
583 if ((eep->ee_flags & EFX_EVQ_FLAGS_NOTIFY_MASK) ==
584 EFX_EVQ_FLAGS_NOTIFY_DISABLED) {
589 if ((rc = eevop->eevo_qmoderate(eep, us)) != 0)
597 EFSYS_PROBE1(fail1, efx_rc_t, rc);
603 efx_ev_qstats_update(
605 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat)
607 { efx_nic_t *enp = eep->ee_enp;
608 const efx_ev_ops_t *eevop = enp->en_eevop;
610 EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
612 eevop->eevo_qstats_update(eep, stat);
615 #endif /* EFSYS_OPT_QSTATS */
619 static __checkReturn efx_rc_t
626 * Program the event queue for receive and transmit queue
629 EFX_BAR_READO(enp, FR_AZ_DP_CTRL_REG, &oword);
630 EFX_SET_OWORD_FIELD(oword, FRF_AZ_FLS_EVQ_ID, 0);
631 EFX_BAR_WRITEO(enp, FR_AZ_DP_CTRL_REG, &oword);
637 static __checkReturn boolean_t
640 __in efx_qword_t *eqp,
643 __inout uint16_t *flagsp)
645 boolean_t ignore = B_FALSE;
647 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TOBE_DISC) != 0) {
648 EFX_EV_QSTAT_INCR(eep, EV_RX_TOBE_DISC);
649 EFSYS_PROBE(tobe_disc);
651 * Assume this is a unicast address mismatch, unless below
652 * we find either FSF_AZ_RX_EV_ETH_CRC_ERR or
653 * EV_RX_PAUSE_FRM_ERR is set.
655 (*flagsp) |= EFX_ADDR_MISMATCH;
658 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_FRM_TRUNC) != 0) {
659 EFSYS_PROBE2(frm_trunc, uint32_t, label, uint32_t, id);
660 EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC);
661 (*flagsp) |= EFX_DISCARD;
663 #if EFSYS_OPT_RX_SCATTER
665 * Lookout for payload queue ran dry errors and ignore them.
667 * Sadly for the header/data split cases, the descriptor
668 * pointer in this event refers to the header queue and
669 * therefore cannot be easily detected as duplicate.
670 * So we drop these and rely on the receive processing seeing
671 * a subsequent packet with FSF_AZ_RX_EV_SOP set to discard
672 * the partially received packet.
674 if ((EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) == 0) &&
675 (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) == 0) &&
676 (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT) == 0))
678 #endif /* EFSYS_OPT_RX_SCATTER */
681 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_ETH_CRC_ERR) != 0) {
682 EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR);
683 EFSYS_PROBE(crc_err);
684 (*flagsp) &= ~EFX_ADDR_MISMATCH;
685 (*flagsp) |= EFX_DISCARD;
688 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PAUSE_FRM_ERR) != 0) {
689 EFX_EV_QSTAT_INCR(eep, EV_RX_PAUSE_FRM_ERR);
690 EFSYS_PROBE(pause_frm_err);
691 (*flagsp) &= ~EFX_ADDR_MISMATCH;
692 (*flagsp) |= EFX_DISCARD;
695 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BUF_OWNER_ID_ERR) != 0) {
696 EFX_EV_QSTAT_INCR(eep, EV_RX_BUF_OWNER_ID_ERR);
697 EFSYS_PROBE(owner_id_err);
698 (*flagsp) |= EFX_DISCARD;
701 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR) != 0) {
702 EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR);
703 EFSYS_PROBE(ipv4_err);
704 (*flagsp) &= ~EFX_CKSUM_IPV4;
707 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR) != 0) {
708 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR);
709 EFSYS_PROBE(udp_chk_err);
710 (*flagsp) &= ~EFX_CKSUM_TCPUDP;
713 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_FRAG_ERR) != 0) {
714 EFX_EV_QSTAT_INCR(eep, EV_RX_IP_FRAG_ERR);
717 * If IP is fragmented FSF_AZ_RX_EV_IP_FRAG_ERR is set. This
718 * causes FSF_AZ_RX_EV_PKT_OK to be clear. This is not an error
721 (*flagsp) &= ~(EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP);
727 static __checkReturn boolean_t
730 __in efx_qword_t *eqp,
731 __in const efx_ev_callbacks_t *eecp,
738 #if EFSYS_OPT_RX_SCATTER
740 boolean_t jumbo_cont;
741 #endif /* EFSYS_OPT_RX_SCATTER */
746 boolean_t should_abort;
748 EFX_EV_QSTAT_INCR(eep, EV_RX);
750 /* Basic packet information */
751 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_DESC_PTR);
752 size = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT);
753 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_Q_LABEL);
754 ok = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_OK) != 0);
756 #if EFSYS_OPT_RX_SCATTER
757 sop = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) != 0);
758 jumbo_cont = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) != 0);
759 #endif /* EFSYS_OPT_RX_SCATTER */
761 hdr_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_HDR_TYPE);
763 is_v6 = (EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_IPV6_PKT) != 0);
766 * If packet is marked as OK and packet type is TCP/IP or
767 * UDP/IP or other IP, then we can rely on the hardware checksums.
770 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_TCP:
771 flags = EFX_PKT_TCP | EFX_CKSUM_TCPUDP;
773 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV6);
774 flags |= EFX_PKT_IPV6;
776 EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV4);
777 flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
781 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_UDP:
782 flags = EFX_PKT_UDP | EFX_CKSUM_TCPUDP;
784 EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV6);
785 flags |= EFX_PKT_IPV6;
787 EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV4);
788 flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
792 case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_OTHER:
794 EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV6);
795 flags = EFX_PKT_IPV6;
797 EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV4);
798 flags = EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
802 case FSE_AZ_RX_EV_HDR_TYPE_OTHER:
803 EFX_EV_QSTAT_INCR(eep, EV_RX_NON_IP);
808 EFSYS_ASSERT(B_FALSE);
813 #if EFSYS_OPT_RX_SCATTER
814 /* Report scatter and header/lookahead split buffer flags */
816 flags |= EFX_PKT_START;
818 flags |= EFX_PKT_CONT;
819 #endif /* EFSYS_OPT_RX_SCATTER */
821 /* Detect errors included in the FSF_AZ_RX_EV_PKT_OK indication */
823 ignore = siena_ev_rx_not_ok(eep, eqp, label, id, &flags);
825 EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
826 uint32_t, size, uint16_t, flags);
832 /* If we're not discarding the packet then it is ok */
833 if (~flags & EFX_DISCARD)
834 EFX_EV_QSTAT_INCR(eep, EV_RX_OK);
836 /* Detect multicast packets that didn't match the filter */
837 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_PKT) != 0) {
838 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_PKT);
840 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_HASH_MATCH) != 0) {
841 EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_HASH_MATCH);
843 EFSYS_PROBE(mcast_mismatch);
844 flags |= EFX_ADDR_MISMATCH;
847 flags |= EFX_PKT_UNICAST;
851 * The packet parser in Siena can abort parsing packets under
852 * certain error conditions, setting the PKT_NOT_PARSED bit
853 * (which clears PKT_OK). If this is set, then don't trust
854 * the PKT_TYPE field.
859 parse_err = EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_PKT_NOT_PARSED);
861 flags |= EFX_CHECK_VLAN;
864 if (~flags & EFX_CHECK_VLAN) {
867 pkt_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_TYPE);
868 if (pkt_type >= FSE_AZ_RX_EV_PKT_TYPE_VLAN)
869 flags |= EFX_PKT_VLAN_TAGGED;
872 EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
873 uint32_t, size, uint16_t, flags);
875 EFSYS_ASSERT(eecp->eec_rx != NULL);
876 should_abort = eecp->eec_rx(arg, label, id, size, flags);
878 return (should_abort);
881 static __checkReturn boolean_t
884 __in efx_qword_t *eqp,
885 __in const efx_ev_callbacks_t *eecp,
890 boolean_t should_abort;
892 EFX_EV_QSTAT_INCR(eep, EV_TX);
894 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0 &&
895 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) == 0 &&
896 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) == 0 &&
897 EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) == 0) {
899 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_DESC_PTR);
900 label = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_Q_LABEL);
902 EFSYS_PROBE2(tx_complete, uint32_t, label, uint32_t, id);
904 EFSYS_ASSERT(eecp->eec_tx != NULL);
905 should_abort = eecp->eec_tx(arg, label, id);
907 return (should_abort);
910 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0)
911 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
912 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
913 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
915 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) != 0)
916 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_ERR);
918 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) != 0)
919 EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_TOO_BIG);
921 if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) != 0)
922 EFX_EV_QSTAT_INCR(eep, EV_TX_WQ_FF_FULL);
924 EFX_EV_QSTAT_INCR(eep, EV_TX_UNEXPECTED);
928 static __checkReturn boolean_t
931 __in efx_qword_t *eqp,
932 __in const efx_ev_callbacks_t *eecp,
935 _NOTE(ARGUNUSED(eqp, eecp, arg))
937 EFX_EV_QSTAT_INCR(eep, EV_GLOBAL);
942 static __checkReturn boolean_t
945 __in efx_qword_t *eqp,
946 __in const efx_ev_callbacks_t *eecp,
949 boolean_t should_abort;
951 EFX_EV_QSTAT_INCR(eep, EV_DRIVER);
952 should_abort = B_FALSE;
954 switch (EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBCODE)) {
955 case FSE_AZ_TX_DESCQ_FLS_DONE_EV: {
958 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DESCQ_FLS_DONE);
960 txq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
962 EFSYS_PROBE1(tx_descq_fls_done, uint32_t, txq_index);
964 EFSYS_ASSERT(eecp->eec_txq_flush_done != NULL);
965 should_abort = eecp->eec_txq_flush_done(arg, txq_index);
969 case FSE_AZ_RX_DESCQ_FLS_DONE_EV: {
973 rxq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
974 failed = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
976 EFSYS_ASSERT(eecp->eec_rxq_flush_done != NULL);
977 EFSYS_ASSERT(eecp->eec_rxq_flush_failed != NULL);
980 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_FAILED);
982 EFSYS_PROBE1(rx_descq_fls_failed, uint32_t, rxq_index);
984 should_abort = eecp->eec_rxq_flush_failed(arg,
987 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_DONE);
989 EFSYS_PROBE1(rx_descq_fls_done, uint32_t, rxq_index);
991 should_abort = eecp->eec_rxq_flush_done(arg, rxq_index);
996 case FSE_AZ_EVQ_INIT_DONE_EV:
997 EFSYS_ASSERT(eecp->eec_initialized != NULL);
998 should_abort = eecp->eec_initialized(arg);
1002 case FSE_AZ_EVQ_NOT_EN_EV:
1003 EFSYS_PROBE(evq_not_en);
1006 case FSE_AZ_SRM_UPD_DONE_EV: {
1009 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_SRM_UPD_DONE);
1011 code = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
1013 EFSYS_ASSERT(eecp->eec_sram != NULL);
1014 should_abort = eecp->eec_sram(arg, code);
1018 case FSE_AZ_WAKE_UP_EV: {
1021 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
1023 EFSYS_ASSERT(eecp->eec_wake_up != NULL);
1024 should_abort = eecp->eec_wake_up(arg, id);
1028 case FSE_AZ_TX_PKT_NON_TCP_UDP:
1029 EFSYS_PROBE(tx_pkt_non_tcp_udp);
1032 case FSE_AZ_TIMER_EV: {
1035 id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
1037 EFSYS_ASSERT(eecp->eec_timer != NULL);
1038 should_abort = eecp->eec_timer(arg, id);
1042 case FSE_AZ_RX_DSC_ERROR_EV:
1043 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DSC_ERROR);
1045 EFSYS_PROBE(rx_dsc_error);
1047 EFSYS_ASSERT(eecp->eec_exception != NULL);
1048 should_abort = eecp->eec_exception(arg,
1049 EFX_EXCEPTION_RX_DSC_ERROR, 0);
1053 case FSE_AZ_TX_DSC_ERROR_EV:
1054 EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DSC_ERROR);
1056 EFSYS_PROBE(tx_dsc_error);
1058 EFSYS_ASSERT(eecp->eec_exception != NULL);
1059 should_abort = eecp->eec_exception(arg,
1060 EFX_EXCEPTION_TX_DSC_ERROR, 0);
1068 return (should_abort);
1071 static __checkReturn boolean_t
1073 __in efx_evq_t *eep,
1074 __in efx_qword_t *eqp,
1075 __in const efx_ev_callbacks_t *eecp,
1079 boolean_t should_abort;
1081 EFX_EV_QSTAT_INCR(eep, EV_DRV_GEN);
1083 data = EFX_QWORD_FIELD(*eqp, FSF_AZ_EV_DATA_DW0);
1084 if (data >= ((uint32_t)1 << 16)) {
1085 EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
1086 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
1087 uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
1091 EFSYS_ASSERT(eecp->eec_software != NULL);
1092 should_abort = eecp->eec_software(arg, (uint16_t)data);
1094 return (should_abort);
1099 static __checkReturn boolean_t
1101 __in efx_evq_t *eep,
1102 __in efx_qword_t *eqp,
1103 __in const efx_ev_callbacks_t *eecp,
1106 efx_nic_t *enp = eep->ee_enp;
1108 boolean_t should_abort = B_FALSE;
1110 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
1112 if (enp->en_family != EFX_FAMILY_SIENA)
1115 EFSYS_ASSERT(eecp->eec_link_change != NULL);
1116 EFSYS_ASSERT(eecp->eec_exception != NULL);
1117 #if EFSYS_OPT_MON_STATS
1118 EFSYS_ASSERT(eecp->eec_monitor != NULL);
1121 EFX_EV_QSTAT_INCR(eep, EV_MCDI_RESPONSE);
1123 code = EFX_QWORD_FIELD(*eqp, MCDI_EVENT_CODE);
1125 case MCDI_EVENT_CODE_BADSSERT:
1126 efx_mcdi_ev_death(enp, EINTR);
1129 case MCDI_EVENT_CODE_CMDDONE:
1130 efx_mcdi_ev_cpl(enp,
1131 MCDI_EV_FIELD(eqp, CMDDONE_SEQ),
1132 MCDI_EV_FIELD(eqp, CMDDONE_DATALEN),
1133 MCDI_EV_FIELD(eqp, CMDDONE_ERRNO));
1136 case MCDI_EVENT_CODE_LINKCHANGE: {
1137 efx_link_mode_t link_mode;
1139 siena_phy_link_ev(enp, eqp, &link_mode);
1140 should_abort = eecp->eec_link_change(arg, link_mode);
1143 case MCDI_EVENT_CODE_SENSOREVT: {
1144 #if EFSYS_OPT_MON_STATS
1146 efx_mon_stat_value_t value;
1149 if ((rc = mcdi_mon_ev(enp, eqp, &id, &value)) == 0)
1150 should_abort = eecp->eec_monitor(arg, id, value);
1151 else if (rc == ENOTSUP) {
1152 should_abort = eecp->eec_exception(arg,
1153 EFX_EXCEPTION_UNKNOWN_SENSOREVT,
1154 MCDI_EV_FIELD(eqp, DATA));
1156 EFSYS_ASSERT(rc == ENODEV); /* Wrong port */
1158 should_abort = B_FALSE;
1162 case MCDI_EVENT_CODE_SCHEDERR:
1163 /* Informational only */
1166 case MCDI_EVENT_CODE_REBOOT:
1167 efx_mcdi_ev_death(enp, EIO);
1170 case MCDI_EVENT_CODE_MAC_STATS_DMA:
1171 #if EFSYS_OPT_MAC_STATS
1172 if (eecp->eec_mac_stats != NULL) {
1173 eecp->eec_mac_stats(arg,
1174 MCDI_EV_FIELD(eqp, MAC_STATS_DMA_GENERATION));
1179 case MCDI_EVENT_CODE_FWALERT: {
1180 uint32_t reason = MCDI_EV_FIELD(eqp, FWALERT_REASON);
1182 if (reason == MCDI_EVENT_FWALERT_REASON_SRAM_ACCESS)
1183 should_abort = eecp->eec_exception(arg,
1184 EFX_EXCEPTION_FWALERT_SRAM,
1185 MCDI_EV_FIELD(eqp, FWALERT_DATA));
1187 should_abort = eecp->eec_exception(arg,
1188 EFX_EXCEPTION_UNKNOWN_FWALERT,
1189 MCDI_EV_FIELD(eqp, DATA));
1194 EFSYS_PROBE1(mc_pcol_error, int, code);
1199 return (should_abort);
1202 #endif /* EFSYS_OPT_MCDI */
1204 static __checkReturn efx_rc_t
1206 __in efx_evq_t *eep,
1207 __in unsigned int count)
1209 efx_nic_t *enp = eep->ee_enp;
1213 rptr = count & eep->ee_mask;
1215 EFX_POPULATE_DWORD_1(dword, FRF_AZ_EVQ_RPTR, rptr);
1217 EFX_BAR_TBL_WRITED(enp, FR_AZ_EVQ_RPTR_REG, eep->ee_index,
1225 __in efx_evq_t *eep,
1228 efx_nic_t *enp = eep->ee_enp;
1232 EFX_POPULATE_QWORD_2(ev, FSF_AZ_EV_CODE, FSE_AZ_EV_CODE_DRV_GEN_EV,
1233 FSF_AZ_EV_DATA_DW0, (uint32_t)data);
1235 EFX_POPULATE_OWORD_3(oword, FRF_AZ_DRV_EV_QID, eep->ee_index,
1236 EFX_DWORD_0, EFX_QWORD_FIELD(ev, EFX_DWORD_0),
1237 EFX_DWORD_1, EFX_QWORD_FIELD(ev, EFX_DWORD_1));
1239 EFX_BAR_WRITEO(enp, FR_AZ_DRV_EV_REG, &oword);
1242 static __checkReturn efx_rc_t
1244 __in efx_evq_t *eep,
1245 __in unsigned int us)
1247 efx_nic_t *enp = eep->ee_enp;
1248 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1249 unsigned int locked;
1253 if (us > encp->enc_evq_timer_max_us) {
1258 /* If the value is zero then disable the timer */
1260 EFX_POPULATE_DWORD_2(dword,
1261 FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS,
1262 FRF_CZ_TC_TIMER_VAL, 0);
1266 if ((rc = efx_ev_usecs_to_ticks(enp, us, &ticks)) != 0)
1269 EFSYS_ASSERT(ticks > 0);
1270 EFX_POPULATE_DWORD_2(dword,
1271 FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_INT_HLDOFF,
1272 FRF_CZ_TC_TIMER_VAL, ticks - 1);
1275 locked = (eep->ee_index == 0) ? 1 : 0;
1277 EFX_BAR_TBL_WRITED(enp, FR_BZ_TIMER_COMMAND_REGP0,
1278 eep->ee_index, &dword, locked);
1285 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1290 static __checkReturn efx_rc_t
1292 __in efx_nic_t *enp,
1293 __in unsigned int index,
1294 __in efsys_mem_t *esmp,
1298 __in uint32_t flags,
1299 __in efx_evq_t *eep)
1301 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1305 boolean_t notify_mode;
1307 _NOTE(ARGUNUSED(esmp))
1309 EFX_STATIC_ASSERT(ISP2(EFX_EVQ_MAXNEVS));
1310 EFX_STATIC_ASSERT(ISP2(EFX_EVQ_MINNEVS));
1312 if (!ISP2(n) || (n < EFX_EVQ_MINNEVS) || (n > EFX_EVQ_MAXNEVS)) {
1316 if (index >= encp->enc_evq_limit) {
1320 #if EFSYS_OPT_RX_SCALE
1321 if (enp->en_intr.ei_type == EFX_INTR_LINE &&
1322 index >= EFX_MAXRSS_LEGACY) {
1327 for (size = 0; (1 << size) <= (EFX_EVQ_MAXNEVS / EFX_EVQ_MINNEVS);
1329 if ((1 << size) == (int)(n / EFX_EVQ_MINNEVS))
1331 if (id + (1 << size) >= encp->enc_buftbl_limit) {
1336 /* Set up the handler table */
1337 eep->ee_rx = siena_ev_rx;
1338 eep->ee_tx = siena_ev_tx;
1339 eep->ee_driver = siena_ev_driver;
1340 eep->ee_global = siena_ev_global;
1341 eep->ee_drv_gen = siena_ev_drv_gen;
1343 eep->ee_mcdi = siena_ev_mcdi;
1344 #endif /* EFSYS_OPT_MCDI */
1346 notify_mode = ((flags & EFX_EVQ_FLAGS_NOTIFY_MASK) !=
1347 EFX_EVQ_FLAGS_NOTIFY_INTERRUPT);
1349 /* Set up the new event queue */
1350 EFX_POPULATE_OWORD_3(oword, FRF_CZ_TIMER_Q_EN, 1,
1351 FRF_CZ_HOST_NOTIFY_MODE, notify_mode,
1352 FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
1353 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, index, &oword, B_TRUE);
1355 EFX_POPULATE_OWORD_3(oword, FRF_AZ_EVQ_EN, 1, FRF_AZ_EVQ_SIZE, size,
1356 FRF_AZ_EVQ_BUF_BASE_ID, id);
1358 EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, index, &oword, B_TRUE);
1360 /* Set initial interrupt moderation */
1361 siena_ev_qmoderate(eep, us);
1367 #if EFSYS_OPT_RX_SCALE
1374 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1379 #endif /* EFSYS_OPT_SIENA */
1381 #if EFSYS_OPT_QSTATS
1383 /* START MKCONFIG GENERATED EfxEventQueueStatNamesBlock c0f3bc5083b40532 */
1384 static const char * const __efx_ev_qstat_name[] = {
1391 "rx_buf_owner_id_err",
1392 "rx_ipv4_hdr_chksum_err",
1393 "rx_tcp_udp_chksum_err",
1397 "rx_mcast_hash_match",
1414 "driver_srm_upd_done",
1415 "driver_tx_descq_fls_done",
1416 "driver_rx_descq_fls_done",
1417 "driver_rx_descq_fls_failed",
1418 "driver_rx_dsc_error",
1419 "driver_tx_dsc_error",
1423 /* END MKCONFIG GENERATED EfxEventQueueStatNamesBlock */
1427 __in efx_nic_t *enp,
1428 __in unsigned int id)
1430 _NOTE(ARGUNUSED(enp))
1432 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
1433 EFSYS_ASSERT3U(id, <, EV_NQSTATS);
1435 return (__efx_ev_qstat_name[id]);
1437 #endif /* EFSYS_OPT_NAMES */
1438 #endif /* EFSYS_OPT_QSTATS */
1442 #if EFSYS_OPT_QSTATS
1444 siena_ev_qstats_update(
1445 __in efx_evq_t *eep,
1446 __inout_ecount(EV_NQSTATS) efsys_stat_t *stat)
1450 for (id = 0; id < EV_NQSTATS; id++) {
1451 efsys_stat_t *essp = &stat[id];
1453 EFSYS_STAT_INCR(essp, eep->ee_stat[id]);
1454 eep->ee_stat[id] = 0;
1457 #endif /* EFSYS_OPT_QSTATS */
1461 __in efx_evq_t *eep)
1463 efx_nic_t *enp = eep->ee_enp;
1466 /* Purge event queue */
1467 EFX_ZERO_OWORD(oword);
1469 EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL,
1470 eep->ee_index, &oword, B_TRUE);
1472 EFX_ZERO_OWORD(oword);
1473 EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, eep->ee_index, &oword, B_TRUE);
1478 __in efx_nic_t *enp)
1480 _NOTE(ARGUNUSED(enp))
1483 #endif /* EFSYS_OPT_SIENA */