xref: /freebsd/sys/dev/sfxge/common/efx_ev.c (revision a3fe009ab4774dc8bf5cce2cbc77c429d3064336)
1e948693eSPhilip Paeps /*-
2929c7febSAndrew Rybchenko  * Copyright (c) 2007-2016 Solarflare Communications Inc.
33c838a9fSAndrew Rybchenko  * All rights reserved.
4e948693eSPhilip Paeps  *
5e948693eSPhilip Paeps  * Redistribution and use in source and binary forms, with or without
63c838a9fSAndrew Rybchenko  * modification, are permitted provided that the following conditions are met:
7e948693eSPhilip Paeps  *
83c838a9fSAndrew Rybchenko  * 1. Redistributions of source code must retain the above copyright notice,
93c838a9fSAndrew Rybchenko  *    this list of conditions and the following disclaimer.
103c838a9fSAndrew Rybchenko  * 2. Redistributions in binary form must reproduce the above copyright notice,
113c838a9fSAndrew Rybchenko  *    this list of conditions and the following disclaimer in the documentation
123c838a9fSAndrew Rybchenko  *    and/or other materials provided with the distribution.
133c838a9fSAndrew Rybchenko  *
143c838a9fSAndrew Rybchenko  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
153c838a9fSAndrew Rybchenko  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
163c838a9fSAndrew Rybchenko  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
173c838a9fSAndrew Rybchenko  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
183c838a9fSAndrew Rybchenko  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
193c838a9fSAndrew Rybchenko  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
203c838a9fSAndrew Rybchenko  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
213c838a9fSAndrew Rybchenko  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
223c838a9fSAndrew Rybchenko  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
233c838a9fSAndrew Rybchenko  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
243c838a9fSAndrew Rybchenko  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253c838a9fSAndrew Rybchenko  *
263c838a9fSAndrew Rybchenko  * The views and conclusions contained in the software and documentation are
273c838a9fSAndrew Rybchenko  * those of the authors and should not be interpreted as representing official
283c838a9fSAndrew Rybchenko  * policies, either expressed or implied, of the FreeBSD Project.
29e948693eSPhilip Paeps  */
30e948693eSPhilip Paeps 
315dee87d7SPhilip Paeps #include <sys/cdefs.h>
325dee87d7SPhilip Paeps __FBSDID("$FreeBSD$");
335dee87d7SPhilip Paeps 
34e948693eSPhilip Paeps #include "efx.h"
35e948693eSPhilip Paeps #include "efx_impl.h"
3647d4cf23SAndrew Rybchenko #if EFSYS_OPT_MON_MCDI
373c838a9fSAndrew Rybchenko #include "mcdi_mon.h"
3847d4cf23SAndrew Rybchenko #endif
39e948693eSPhilip Paeps 
40e948693eSPhilip Paeps #if EFSYS_OPT_QSTATS
41e948693eSPhilip Paeps #define	EFX_EV_QSTAT_INCR(_eep, _stat)					\
42e948693eSPhilip Paeps 	do {								\
43e948693eSPhilip Paeps 		(_eep)->ee_stat[_stat]++;				\
44e948693eSPhilip Paeps 	_NOTE(CONSTANTCONDITION)					\
45e948693eSPhilip Paeps 	} while (B_FALSE)
46e948693eSPhilip Paeps #else
47e948693eSPhilip Paeps #define	EFX_EV_QSTAT_INCR(_eep, _stat)
48e948693eSPhilip Paeps #endif
49e948693eSPhilip Paeps 
503c838a9fSAndrew Rybchenko #define	EFX_EV_PRESENT(_qword)						\
513c838a9fSAndrew Rybchenko 	(EFX_QWORD_FIELD((_qword), EFX_DWORD_0) != 0xffffffff &&	\
523c838a9fSAndrew Rybchenko 	EFX_QWORD_FIELD((_qword), EFX_DWORD_1) != 0xffffffff)
533c838a9fSAndrew Rybchenko 
543c838a9fSAndrew Rybchenko 
553c838a9fSAndrew Rybchenko 
56e75412c9SAndrew Rybchenko #if EFSYS_OPT_SIENA
573c838a9fSAndrew Rybchenko 
58460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
590f981da7SAndrew Rybchenko siena_ev_init(
603c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp);
613c838a9fSAndrew Rybchenko 
623c838a9fSAndrew Rybchenko static			void
630f981da7SAndrew Rybchenko siena_ev_fini(
643c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp);
653c838a9fSAndrew Rybchenko 
66460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
670f981da7SAndrew Rybchenko siena_ev_qcreate(
683c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp,
693c838a9fSAndrew Rybchenko 	__in		unsigned int index,
703c838a9fSAndrew Rybchenko 	__in		efsys_mem_t *esmp,
713c838a9fSAndrew Rybchenko 	__in		size_t n,
723c838a9fSAndrew Rybchenko 	__in		uint32_t id,
735c4c3d92SAndrew Rybchenko 	__in		uint32_t us,
74*a3fe009aSAndrew Rybchenko 	__in		uint32_t flags,
753c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep);
763c838a9fSAndrew Rybchenko 
773c838a9fSAndrew Rybchenko static			void
780f981da7SAndrew Rybchenko siena_ev_qdestroy(
793c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep);
803c838a9fSAndrew Rybchenko 
81460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
820f981da7SAndrew Rybchenko siena_ev_qprime(
833c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
843c838a9fSAndrew Rybchenko 	__in		unsigned int count);
853c838a9fSAndrew Rybchenko 
863c838a9fSAndrew Rybchenko static			void
870f981da7SAndrew Rybchenko siena_ev_qpoll(
883c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
893c838a9fSAndrew Rybchenko 	__inout		unsigned int *countp,
903c838a9fSAndrew Rybchenko 	__in		const efx_ev_callbacks_t *eecp,
913c838a9fSAndrew Rybchenko 	__in_opt	void *arg);
923c838a9fSAndrew Rybchenko 
933c838a9fSAndrew Rybchenko static			void
940f981da7SAndrew Rybchenko siena_ev_qpost(
953c838a9fSAndrew Rybchenko 	__in	efx_evq_t *eep,
963c838a9fSAndrew Rybchenko 	__in	uint16_t data);
973c838a9fSAndrew Rybchenko 
98460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
990f981da7SAndrew Rybchenko siena_ev_qmoderate(
1003c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
1013c838a9fSAndrew Rybchenko 	__in		unsigned int us);
1023c838a9fSAndrew Rybchenko 
1033c838a9fSAndrew Rybchenko #if EFSYS_OPT_QSTATS
1043c838a9fSAndrew Rybchenko static			void
1050f981da7SAndrew Rybchenko siena_ev_qstats_update(
1063c838a9fSAndrew Rybchenko 	__in				efx_evq_t *eep,
1073c838a9fSAndrew Rybchenko 	__inout_ecount(EV_NQSTATS)	efsys_stat_t *stat);
1083c838a9fSAndrew Rybchenko 
1093c838a9fSAndrew Rybchenko #endif
1103c838a9fSAndrew Rybchenko 
111e75412c9SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
1123c838a9fSAndrew Rybchenko 
1133c838a9fSAndrew Rybchenko #if EFSYS_OPT_SIENA
114ec831f7fSAndrew Rybchenko static const efx_ev_ops_t	__efx_ev_siena_ops = {
1150f981da7SAndrew Rybchenko 	siena_ev_init,				/* eevo_init */
1160f981da7SAndrew Rybchenko 	siena_ev_fini,				/* eevo_fini */
1170f981da7SAndrew Rybchenko 	siena_ev_qcreate,			/* eevo_qcreate */
1180f981da7SAndrew Rybchenko 	siena_ev_qdestroy,			/* eevo_qdestroy */
1190f981da7SAndrew Rybchenko 	siena_ev_qprime,			/* eevo_qprime */
1200f981da7SAndrew Rybchenko 	siena_ev_qpost,				/* eevo_qpost */
1210f981da7SAndrew Rybchenko 	siena_ev_qmoderate,			/* eevo_qmoderate */
1223c838a9fSAndrew Rybchenko #if EFSYS_OPT_QSTATS
1230f981da7SAndrew Rybchenko 	siena_ev_qstats_update,			/* eevo_qstats_update */
1243c838a9fSAndrew Rybchenko #endif
1253c838a9fSAndrew Rybchenko };
1263c838a9fSAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
1273c838a9fSAndrew Rybchenko 
128ad8a32cbSAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
129ec831f7fSAndrew Rybchenko static const efx_ev_ops_t	__efx_ev_ef10_ops = {
130ad8a32cbSAndrew Rybchenko 	ef10_ev_init,				/* eevo_init */
131ad8a32cbSAndrew Rybchenko 	ef10_ev_fini,				/* eevo_fini */
132ad8a32cbSAndrew Rybchenko 	ef10_ev_qcreate,			/* eevo_qcreate */
133ad8a32cbSAndrew Rybchenko 	ef10_ev_qdestroy,			/* eevo_qdestroy */
134ad8a32cbSAndrew Rybchenko 	ef10_ev_qprime,				/* eevo_qprime */
135ad8a32cbSAndrew Rybchenko 	ef10_ev_qpost,				/* eevo_qpost */
136ad8a32cbSAndrew Rybchenko 	ef10_ev_qmoderate,			/* eevo_qmoderate */
1373c838a9fSAndrew Rybchenko #if EFSYS_OPT_QSTATS
138ad8a32cbSAndrew Rybchenko 	ef10_ev_qstats_update,			/* eevo_qstats_update */
1393c838a9fSAndrew Rybchenko #endif
1403c838a9fSAndrew Rybchenko };
141ad8a32cbSAndrew Rybchenko #endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
1423c838a9fSAndrew Rybchenko 
1433c838a9fSAndrew Rybchenko 
144460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
145e948693eSPhilip Paeps efx_ev_init(
146e948693eSPhilip Paeps 	__in		efx_nic_t *enp)
147e948693eSPhilip Paeps {
148ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop;
149460cb568SAndrew Rybchenko 	efx_rc_t rc;
150e948693eSPhilip Paeps 
151e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
152e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
153e948693eSPhilip Paeps 
154e948693eSPhilip Paeps 	if (enp->en_mod_flags & EFX_MOD_EV) {
155e948693eSPhilip Paeps 		rc = EINVAL;
156e948693eSPhilip Paeps 		goto fail1;
157e948693eSPhilip Paeps 	}
158e948693eSPhilip Paeps 
1593c838a9fSAndrew Rybchenko 	switch (enp->en_family) {
1603c838a9fSAndrew Rybchenko #if EFSYS_OPT_SIENA
1613c838a9fSAndrew Rybchenko 	case EFX_FAMILY_SIENA:
162ec831f7fSAndrew Rybchenko 		eevop = &__efx_ev_siena_ops;
1633c838a9fSAndrew Rybchenko 		break;
1643c838a9fSAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
1653c838a9fSAndrew Rybchenko 
1663c838a9fSAndrew Rybchenko #if EFSYS_OPT_HUNTINGTON
1673c838a9fSAndrew Rybchenko 	case EFX_FAMILY_HUNTINGTON:
168ec831f7fSAndrew Rybchenko 		eevop = &__efx_ev_ef10_ops;
1693c838a9fSAndrew Rybchenko 		break;
1703c838a9fSAndrew Rybchenko #endif /* EFSYS_OPT_HUNTINGTON */
1713c838a9fSAndrew Rybchenko 
172ad8a32cbSAndrew Rybchenko #if EFSYS_OPT_MEDFORD
173ad8a32cbSAndrew Rybchenko 	case EFX_FAMILY_MEDFORD:
174ec831f7fSAndrew Rybchenko 		eevop = &__efx_ev_ef10_ops;
175ad8a32cbSAndrew Rybchenko 		break;
176ad8a32cbSAndrew Rybchenko #endif /* EFSYS_OPT_MEDFORD */
177ad8a32cbSAndrew Rybchenko 
1783c838a9fSAndrew Rybchenko 	default:
1793c838a9fSAndrew Rybchenko 		EFSYS_ASSERT(0);
1803c838a9fSAndrew Rybchenko 		rc = ENOTSUP;
1813c838a9fSAndrew Rybchenko 		goto fail1;
1823c838a9fSAndrew Rybchenko 	}
1833c838a9fSAndrew Rybchenko 
184e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
185e948693eSPhilip Paeps 
1863c838a9fSAndrew Rybchenko 	if ((rc = eevop->eevo_init(enp)) != 0)
1873c838a9fSAndrew Rybchenko 		goto fail2;
1883c838a9fSAndrew Rybchenko 
1893c838a9fSAndrew Rybchenko 	enp->en_eevop = eevop;
1903c838a9fSAndrew Rybchenko 	enp->en_mod_flags |= EFX_MOD_EV;
1913c838a9fSAndrew Rybchenko 	return (0);
1923c838a9fSAndrew Rybchenko 
1933c838a9fSAndrew Rybchenko fail2:
1943c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail2);
1953c838a9fSAndrew Rybchenko 
1963c838a9fSAndrew Rybchenko fail1:
197460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1983c838a9fSAndrew Rybchenko 
1993c838a9fSAndrew Rybchenko 	enp->en_eevop = NULL;
2003c838a9fSAndrew Rybchenko 	enp->en_mod_flags &= ~EFX_MOD_EV;
2013c838a9fSAndrew Rybchenko 	return (rc);
2023c838a9fSAndrew Rybchenko }
2033c838a9fSAndrew Rybchenko 
2043c838a9fSAndrew Rybchenko 		void
2053c838a9fSAndrew Rybchenko efx_ev_fini(
2063c838a9fSAndrew Rybchenko 	__in	efx_nic_t *enp)
2073c838a9fSAndrew Rybchenko {
208ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
2093c838a9fSAndrew Rybchenko 
2103c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
2113c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_INTR);
2123c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
2133c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_RX));
2143c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_TX));
2153c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_ev_qcount, ==, 0);
2163c838a9fSAndrew Rybchenko 
2173c838a9fSAndrew Rybchenko 	eevop->eevo_fini(enp);
2183c838a9fSAndrew Rybchenko 
2193c838a9fSAndrew Rybchenko 	enp->en_eevop = NULL;
2203c838a9fSAndrew Rybchenko 	enp->en_mod_flags &= ~EFX_MOD_EV;
2213c838a9fSAndrew Rybchenko }
2223c838a9fSAndrew Rybchenko 
2233c838a9fSAndrew Rybchenko 
224460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
2253c838a9fSAndrew Rybchenko efx_ev_qcreate(
2263c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp,
2273c838a9fSAndrew Rybchenko 	__in		unsigned int index,
2283c838a9fSAndrew Rybchenko 	__in		efsys_mem_t *esmp,
2293c838a9fSAndrew Rybchenko 	__in		size_t n,
2303c838a9fSAndrew Rybchenko 	__in		uint32_t id,
2315c4c3d92SAndrew Rybchenko 	__in		uint32_t us,
232*a3fe009aSAndrew Rybchenko 	__in		uint32_t flags,
2333c838a9fSAndrew Rybchenko 	__deref_out	efx_evq_t **eepp)
2343c838a9fSAndrew Rybchenko {
235ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
2363c838a9fSAndrew Rybchenko 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
2373c838a9fSAndrew Rybchenko 	efx_evq_t *eep;
238460cb568SAndrew Rybchenko 	efx_rc_t rc;
2393c838a9fSAndrew Rybchenko 
2403c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
2413c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_EV);
2423c838a9fSAndrew Rybchenko 
2433c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(enp->en_ev_qcount + 1, <, encp->enc_evq_limit);
2443c838a9fSAndrew Rybchenko 
2453c838a9fSAndrew Rybchenko 	/* Allocate an EVQ object */
2463c838a9fSAndrew Rybchenko 	EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (efx_evq_t), eep);
2473c838a9fSAndrew Rybchenko 	if (eep == NULL) {
2483c838a9fSAndrew Rybchenko 		rc = ENOMEM;
2493c838a9fSAndrew Rybchenko 		goto fail1;
2503c838a9fSAndrew Rybchenko 	}
2513c838a9fSAndrew Rybchenko 
2523c838a9fSAndrew Rybchenko 	eep->ee_magic = EFX_EVQ_MAGIC;
2533c838a9fSAndrew Rybchenko 	eep->ee_enp = enp;
2543c838a9fSAndrew Rybchenko 	eep->ee_index = index;
2553c838a9fSAndrew Rybchenko 	eep->ee_mask = n - 1;
2563c838a9fSAndrew Rybchenko 	eep->ee_esmp = esmp;
2573c838a9fSAndrew Rybchenko 
258bdb482bfSAndrew Rybchenko 	/*
259bdb482bfSAndrew Rybchenko 	 * Set outputs before the queue is created because interrupts may be
260bdb482bfSAndrew Rybchenko 	 * raised for events immediately after the queue is created, before the
261bdb482bfSAndrew Rybchenko 	 * function call below returns. See bug58606.
262bdb482bfSAndrew Rybchenko 	 *
263bdb482bfSAndrew Rybchenko 	 * The eepp pointer passed in by the client must therefore point to data
264bdb482bfSAndrew Rybchenko 	 * shared with the client's event processing context.
265bdb482bfSAndrew Rybchenko 	 */
2663c838a9fSAndrew Rybchenko 	enp->en_ev_qcount++;
2673c838a9fSAndrew Rybchenko 	*eepp = eep;
2683c838a9fSAndrew Rybchenko 
269*a3fe009aSAndrew Rybchenko 	if ((rc = eevop->eevo_qcreate(enp, index, esmp, n, id, us, flags,
270*a3fe009aSAndrew Rybchenko 	    eep)) != 0)
271bdb482bfSAndrew Rybchenko 		goto fail2;
272bdb482bfSAndrew Rybchenko 
2733c838a9fSAndrew Rybchenko 	return (0);
2743c838a9fSAndrew Rybchenko 
2753c838a9fSAndrew Rybchenko fail2:
2763c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail2);
277bdb482bfSAndrew Rybchenko 
278bdb482bfSAndrew Rybchenko 	*eepp = NULL;
279bdb482bfSAndrew Rybchenko 	enp->en_ev_qcount--;
2803c838a9fSAndrew Rybchenko 	EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
2813c838a9fSAndrew Rybchenko fail1:
282460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
2833c838a9fSAndrew Rybchenko 	return (rc);
2843c838a9fSAndrew Rybchenko }
2853c838a9fSAndrew Rybchenko 
2863c838a9fSAndrew Rybchenko 		void
2873c838a9fSAndrew Rybchenko efx_ev_qdestroy(
2883c838a9fSAndrew Rybchenko 	__in	efx_evq_t *eep)
2893c838a9fSAndrew Rybchenko {
2903c838a9fSAndrew Rybchenko 	efx_nic_t *enp = eep->ee_enp;
291ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
2923c838a9fSAndrew Rybchenko 
2933c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
2943c838a9fSAndrew Rybchenko 
2953c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(enp->en_ev_qcount != 0);
2963c838a9fSAndrew Rybchenko 	--enp->en_ev_qcount;
2973c838a9fSAndrew Rybchenko 
2983c838a9fSAndrew Rybchenko 	eevop->eevo_qdestroy(eep);
2993c838a9fSAndrew Rybchenko 
3003c838a9fSAndrew Rybchenko 	/* Free the EVQ object */
3013c838a9fSAndrew Rybchenko 	EFSYS_KMEM_FREE(enp->en_esip, sizeof (efx_evq_t), eep);
3023c838a9fSAndrew Rybchenko }
3033c838a9fSAndrew Rybchenko 
304460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
3053c838a9fSAndrew Rybchenko efx_ev_qprime(
3063c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
3073c838a9fSAndrew Rybchenko 	__in		unsigned int count)
3083c838a9fSAndrew Rybchenko {
3093c838a9fSAndrew Rybchenko 	efx_nic_t *enp = eep->ee_enp;
310ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
311460cb568SAndrew Rybchenko 	efx_rc_t rc;
3123c838a9fSAndrew Rybchenko 
3133c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
3143c838a9fSAndrew Rybchenko 
3153c838a9fSAndrew Rybchenko 	if (!(enp->en_mod_flags & EFX_MOD_INTR)) {
3163c838a9fSAndrew Rybchenko 		rc = EINVAL;
3173c838a9fSAndrew Rybchenko 		goto fail1;
3183c838a9fSAndrew Rybchenko 	}
3193c838a9fSAndrew Rybchenko 
3203c838a9fSAndrew Rybchenko 	if ((rc = eevop->eevo_qprime(eep, count)) != 0)
3213c838a9fSAndrew Rybchenko 		goto fail2;
3223c838a9fSAndrew Rybchenko 
3233c838a9fSAndrew Rybchenko 	return (0);
3243c838a9fSAndrew Rybchenko 
3253c838a9fSAndrew Rybchenko fail2:
3263c838a9fSAndrew Rybchenko 	EFSYS_PROBE(fail2);
3273c838a9fSAndrew Rybchenko fail1:
328460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
3293c838a9fSAndrew Rybchenko 	return (rc);
3303c838a9fSAndrew Rybchenko }
3313c838a9fSAndrew Rybchenko 
3323c838a9fSAndrew Rybchenko 	__checkReturn	boolean_t
3333c838a9fSAndrew Rybchenko efx_ev_qpending(
3343c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
3353c838a9fSAndrew Rybchenko 	__in		unsigned int count)
3363c838a9fSAndrew Rybchenko {
3373c838a9fSAndrew Rybchenko 	size_t offset;
3383c838a9fSAndrew Rybchenko 	efx_qword_t qword;
3393c838a9fSAndrew Rybchenko 
3403c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
3413c838a9fSAndrew Rybchenko 
3423c838a9fSAndrew Rybchenko 	offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
3433c838a9fSAndrew Rybchenko 	EFSYS_MEM_READQ(eep->ee_esmp, offset, &qword);
3443c838a9fSAndrew Rybchenko 
3453c838a9fSAndrew Rybchenko 	return (EFX_EV_PRESENT(qword));
3463c838a9fSAndrew Rybchenko }
3473c838a9fSAndrew Rybchenko 
3483c838a9fSAndrew Rybchenko #if EFSYS_OPT_EV_PREFETCH
3493c838a9fSAndrew Rybchenko 
3503c838a9fSAndrew Rybchenko 			void
3513c838a9fSAndrew Rybchenko efx_ev_qprefetch(
3523c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
3533c838a9fSAndrew Rybchenko 	__in		unsigned int count)
3543c838a9fSAndrew Rybchenko {
3553c838a9fSAndrew Rybchenko 	unsigned int offset;
3563c838a9fSAndrew Rybchenko 
3573c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
3583c838a9fSAndrew Rybchenko 
3593c838a9fSAndrew Rybchenko 	offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
3603c838a9fSAndrew Rybchenko 	EFSYS_MEM_PREFETCH(eep->ee_esmp, offset);
3613c838a9fSAndrew Rybchenko }
3623c838a9fSAndrew Rybchenko 
3633c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_EV_PREFETCH */
3643c838a9fSAndrew Rybchenko 
3653c838a9fSAndrew Rybchenko 			void
3663c838a9fSAndrew Rybchenko efx_ev_qpoll(
3673c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
3683c838a9fSAndrew Rybchenko 	__inout		unsigned int *countp,
3693c838a9fSAndrew Rybchenko 	__in		const efx_ev_callbacks_t *eecp,
3703c838a9fSAndrew Rybchenko 	__in_opt	void *arg)
3713c838a9fSAndrew Rybchenko {
3723c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
3733c838a9fSAndrew Rybchenko 
3743c838a9fSAndrew Rybchenko 	/*
3753c838a9fSAndrew Rybchenko 	 * FIXME: Huntington will require support for hardware event batching
3763c838a9fSAndrew Rybchenko 	 * and merging, which will need a different ev_qpoll implementation.
3773c838a9fSAndrew Rybchenko 	 *
3783c838a9fSAndrew Rybchenko 	 * Without those features the Falcon/Siena code can be used unchanged.
3793c838a9fSAndrew Rybchenko 	 */
3803c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESF_DZ_EV_CODE_LBN == FSF_AZ_EV_CODE_LBN);
3813c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESF_DZ_EV_CODE_WIDTH == FSF_AZ_EV_CODE_WIDTH);
3823c838a9fSAndrew Rybchenko 
3833c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_RX_EV == FSE_AZ_EV_CODE_RX_EV);
3843c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_TX_EV == FSE_AZ_EV_CODE_TX_EV);
3853c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_DRIVER_EV == FSE_AZ_EV_CODE_DRIVER_EV);
3863c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_DRV_GEN_EV ==
3873c838a9fSAndrew Rybchenko 	    FSE_AZ_EV_CODE_DRV_GEN_EV);
3883c838a9fSAndrew Rybchenko #if EFSYS_OPT_MCDI
3893c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ESE_DZ_EV_CODE_MCDI_EV ==
3903c838a9fSAndrew Rybchenko 	    FSE_AZ_EV_CODE_MCDI_EVRESPONSE);
3913c838a9fSAndrew Rybchenko #endif
3920f981da7SAndrew Rybchenko 	siena_ev_qpoll(eep, countp, eecp, arg);
3933c838a9fSAndrew Rybchenko }
3943c838a9fSAndrew Rybchenko 
3953c838a9fSAndrew Rybchenko 			void
3963c838a9fSAndrew Rybchenko efx_ev_qpost(
3973c838a9fSAndrew Rybchenko 	__in	efx_evq_t *eep,
3983c838a9fSAndrew Rybchenko 	__in	uint16_t data)
3993c838a9fSAndrew Rybchenko {
4003c838a9fSAndrew Rybchenko 	efx_nic_t *enp = eep->ee_enp;
401ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
4023c838a9fSAndrew Rybchenko 
4033c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
4043c838a9fSAndrew Rybchenko 
4053c838a9fSAndrew Rybchenko 	EFSYS_ASSERT(eevop != NULL &&
4063c838a9fSAndrew Rybchenko 	    eevop->eevo_qpost != NULL);
4073c838a9fSAndrew Rybchenko 
4083c838a9fSAndrew Rybchenko 	eevop->eevo_qpost(eep, data);
4093c838a9fSAndrew Rybchenko }
4103c838a9fSAndrew Rybchenko 
411460cb568SAndrew Rybchenko 	__checkReturn	efx_rc_t
412b839ed60SAndrew Rybchenko efx_ev_usecs_to_ticks(
413b839ed60SAndrew Rybchenko 	__in		efx_nic_t *enp,
414b839ed60SAndrew Rybchenko 	__in		unsigned int us,
415b839ed60SAndrew Rybchenko 	__out		unsigned int *ticksp)
416b839ed60SAndrew Rybchenko {
417b839ed60SAndrew Rybchenko 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
418b839ed60SAndrew Rybchenko 	unsigned int ticks;
419b839ed60SAndrew Rybchenko 
420b839ed60SAndrew Rybchenko 	/* Convert microseconds to a timer tick count */
421b839ed60SAndrew Rybchenko 	if (us == 0)
422b839ed60SAndrew Rybchenko 		ticks = 0;
423b839ed60SAndrew Rybchenko 	else if (us * 1000 < encp->enc_evq_timer_quantum_ns)
424b839ed60SAndrew Rybchenko 		ticks = 1;	/* Never round down to zero */
425b839ed60SAndrew Rybchenko 	else
426b839ed60SAndrew Rybchenko 		ticks = us * 1000 / encp->enc_evq_timer_quantum_ns;
427b839ed60SAndrew Rybchenko 
428b839ed60SAndrew Rybchenko 	*ticksp = ticks;
429b839ed60SAndrew Rybchenko 	return (0);
430b839ed60SAndrew Rybchenko }
431b839ed60SAndrew Rybchenko 
432b839ed60SAndrew Rybchenko 	__checkReturn	efx_rc_t
4333c838a9fSAndrew Rybchenko efx_ev_qmoderate(
4343c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep,
4353c838a9fSAndrew Rybchenko 	__in		unsigned int us)
4363c838a9fSAndrew Rybchenko {
4373c838a9fSAndrew Rybchenko 	efx_nic_t *enp = eep->ee_enp;
438ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
439460cb568SAndrew Rybchenko 	efx_rc_t rc;
4403c838a9fSAndrew Rybchenko 
4413c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
4423c838a9fSAndrew Rybchenko 
4433c838a9fSAndrew Rybchenko 	if ((rc = eevop->eevo_qmoderate(eep, us)) != 0)
4443c838a9fSAndrew Rybchenko 		goto fail1;
4453c838a9fSAndrew Rybchenko 
4463c838a9fSAndrew Rybchenko 	return (0);
4473c838a9fSAndrew Rybchenko 
4483c838a9fSAndrew Rybchenko fail1:
449460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
4503c838a9fSAndrew Rybchenko 	return (rc);
4513c838a9fSAndrew Rybchenko }
4523c838a9fSAndrew Rybchenko 
4533c838a9fSAndrew Rybchenko #if EFSYS_OPT_QSTATS
4543c838a9fSAndrew Rybchenko 					void
4553c838a9fSAndrew Rybchenko efx_ev_qstats_update(
4563c838a9fSAndrew Rybchenko 	__in				efx_evq_t *eep,
4573c838a9fSAndrew Rybchenko 	__inout_ecount(EV_NQSTATS)	efsys_stat_t *stat)
4583c838a9fSAndrew Rybchenko 
4593c838a9fSAndrew Rybchenko {	efx_nic_t *enp = eep->ee_enp;
460ec831f7fSAndrew Rybchenko 	const efx_ev_ops_t *eevop = enp->en_eevop;
4613c838a9fSAndrew Rybchenko 
4623c838a9fSAndrew Rybchenko 	EFSYS_ASSERT3U(eep->ee_magic, ==, EFX_EVQ_MAGIC);
4633c838a9fSAndrew Rybchenko 
4643c838a9fSAndrew Rybchenko 	eevop->eevo_qstats_update(eep, stat);
4653c838a9fSAndrew Rybchenko }
4663c838a9fSAndrew Rybchenko 
4673c838a9fSAndrew Rybchenko #endif	/* EFSYS_OPT_QSTATS */
4683c838a9fSAndrew Rybchenko 
469e75412c9SAndrew Rybchenko #if EFSYS_OPT_SIENA
4703c838a9fSAndrew Rybchenko 
471460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
4720f981da7SAndrew Rybchenko siena_ev_init(
4733c838a9fSAndrew Rybchenko 	__in		efx_nic_t *enp)
4743c838a9fSAndrew Rybchenko {
4753c838a9fSAndrew Rybchenko 	efx_oword_t oword;
4763c838a9fSAndrew Rybchenko 
477e948693eSPhilip Paeps 	/*
478e948693eSPhilip Paeps 	 * Program the event queue for receive and transmit queue
479e948693eSPhilip Paeps 	 * flush events.
480e948693eSPhilip Paeps 	 */
481e948693eSPhilip Paeps 	EFX_BAR_READO(enp, FR_AZ_DP_CTRL_REG, &oword);
482e948693eSPhilip Paeps 	EFX_SET_OWORD_FIELD(oword, FRF_AZ_FLS_EVQ_ID, 0);
483e948693eSPhilip Paeps 	EFX_BAR_WRITEO(enp, FR_AZ_DP_CTRL_REG, &oword);
484e948693eSPhilip Paeps 
485e948693eSPhilip Paeps 	return (0);
486e948693eSPhilip Paeps 
487e948693eSPhilip Paeps }
488e948693eSPhilip Paeps 
489e948693eSPhilip Paeps static  __checkReturn   boolean_t
4900f981da7SAndrew Rybchenko siena_ev_rx_not_ok(
491e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
492e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
493e948693eSPhilip Paeps 	__in		uint32_t label,
494e948693eSPhilip Paeps 	__in		uint32_t id,
495e948693eSPhilip Paeps 	__inout		uint16_t *flagsp)
496e948693eSPhilip Paeps {
497e948693eSPhilip Paeps 	boolean_t ignore = B_FALSE;
498e948693eSPhilip Paeps 
499e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TOBE_DISC) != 0) {
500e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_TOBE_DISC);
501e948693eSPhilip Paeps 		EFSYS_PROBE(tobe_disc);
5020ff23789SAndrew Rybchenko 		/*
5030ff23789SAndrew Rybchenko 		 * Assume this is a unicast address mismatch, unless below
504e948693eSPhilip Paeps 		 * we find either FSF_AZ_RX_EV_ETH_CRC_ERR or
505e948693eSPhilip Paeps 		 * EV_RX_PAUSE_FRM_ERR is set.
506e948693eSPhilip Paeps 		 */
507e948693eSPhilip Paeps 		(*flagsp) |= EFX_ADDR_MISMATCH;
508e948693eSPhilip Paeps 	}
509e948693eSPhilip Paeps 
510e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_FRM_TRUNC) != 0) {
511e948693eSPhilip Paeps 		EFSYS_PROBE2(frm_trunc, uint32_t, label, uint32_t, id);
512e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_FRM_TRUNC);
513e948693eSPhilip Paeps 		(*flagsp) |= EFX_DISCARD;
514e948693eSPhilip Paeps 
5151b02e3c0SAndrew Rybchenko #if EFSYS_OPT_RX_SCATTER
5160ff23789SAndrew Rybchenko 		/*
5170ff23789SAndrew Rybchenko 		 * Lookout for payload queue ran dry errors and ignore them.
518e948693eSPhilip Paeps 		 *
519e948693eSPhilip Paeps 		 * Sadly for the header/data split cases, the descriptor
520e948693eSPhilip Paeps 		 * pointer in this event refers to the header queue and
521e948693eSPhilip Paeps 		 * therefore cannot be easily detected as duplicate.
522e948693eSPhilip Paeps 		 * So we drop these and rely on the receive processing seeing
523e948693eSPhilip Paeps 		 * a subsequent packet with FSF_AZ_RX_EV_SOP set to discard
524e948693eSPhilip Paeps 		 * the partially received packet.
525e948693eSPhilip Paeps 		 */
526e948693eSPhilip Paeps 		if ((EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) == 0) &&
527e948693eSPhilip Paeps 		    (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) == 0) &&
528e948693eSPhilip Paeps 		    (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT) == 0))
529e948693eSPhilip Paeps 			ignore = B_TRUE;
5301b02e3c0SAndrew Rybchenko #endif	/* EFSYS_OPT_RX_SCATTER */
531e948693eSPhilip Paeps 	}
532e948693eSPhilip Paeps 
533e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_ETH_CRC_ERR) != 0) {
534e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_ETH_CRC_ERR);
535e948693eSPhilip Paeps 		EFSYS_PROBE(crc_err);
536e948693eSPhilip Paeps 		(*flagsp) &= ~EFX_ADDR_MISMATCH;
537e948693eSPhilip Paeps 		(*flagsp) |= EFX_DISCARD;
538e948693eSPhilip Paeps 	}
539e948693eSPhilip Paeps 
540e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PAUSE_FRM_ERR) != 0) {
541e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_PAUSE_FRM_ERR);
542e948693eSPhilip Paeps 		EFSYS_PROBE(pause_frm_err);
543e948693eSPhilip Paeps 		(*flagsp) &= ~EFX_ADDR_MISMATCH;
544e948693eSPhilip Paeps 		(*flagsp) |= EFX_DISCARD;
545e948693eSPhilip Paeps 	}
546e948693eSPhilip Paeps 
547e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BUF_OWNER_ID_ERR) != 0) {
548e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_BUF_OWNER_ID_ERR);
549e948693eSPhilip Paeps 		EFSYS_PROBE(owner_id_err);
550e948693eSPhilip Paeps 		(*flagsp) |= EFX_DISCARD;
551e948693eSPhilip Paeps 	}
552e948693eSPhilip Paeps 
553e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR) != 0) {
554e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_IPV4_HDR_CHKSUM_ERR);
555e948693eSPhilip Paeps 		EFSYS_PROBE(ipv4_err);
556e948693eSPhilip Paeps 		(*flagsp) &= ~EFX_CKSUM_IPV4;
557e948693eSPhilip Paeps 	}
558e948693eSPhilip Paeps 
559e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR) != 0) {
560e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_UDP_CHKSUM_ERR);
561e948693eSPhilip Paeps 		EFSYS_PROBE(udp_chk_err);
562e948693eSPhilip Paeps 		(*flagsp) &= ~EFX_CKSUM_TCPUDP;
563e948693eSPhilip Paeps 	}
564e948693eSPhilip Paeps 
565e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_IP_FRAG_ERR) != 0) {
566e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_IP_FRAG_ERR);
567e948693eSPhilip Paeps 
568e948693eSPhilip Paeps 		/*
569e948693eSPhilip Paeps 		 * If IP is fragmented FSF_AZ_RX_EV_IP_FRAG_ERR is set. This
570e948693eSPhilip Paeps 		 * causes FSF_AZ_RX_EV_PKT_OK to be clear. This is not an error
571e948693eSPhilip Paeps 		 * condition.
572e948693eSPhilip Paeps 		 */
573e948693eSPhilip Paeps 		(*flagsp) &= ~(EFX_PKT_TCP | EFX_PKT_UDP | EFX_CKSUM_TCPUDP);
574e948693eSPhilip Paeps 	}
575e948693eSPhilip Paeps 
576e948693eSPhilip Paeps 	return (ignore);
577e948693eSPhilip Paeps }
578e948693eSPhilip Paeps 
579e948693eSPhilip Paeps static	__checkReturn	boolean_t
5800f981da7SAndrew Rybchenko siena_ev_rx(
581e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
582e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
583e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
584e948693eSPhilip Paeps 	__in_opt	void *arg)
585e948693eSPhilip Paeps {
586e948693eSPhilip Paeps 	uint32_t id;
587e948693eSPhilip Paeps 	uint32_t size;
588e948693eSPhilip Paeps 	uint32_t label;
589e948693eSPhilip Paeps 	boolean_t ok;
5901b02e3c0SAndrew Rybchenko #if EFSYS_OPT_RX_SCATTER
591e948693eSPhilip Paeps 	boolean_t sop;
592e948693eSPhilip Paeps 	boolean_t jumbo_cont;
5931b02e3c0SAndrew Rybchenko #endif	/* EFSYS_OPT_RX_SCATTER */
594e948693eSPhilip Paeps 	uint32_t hdr_type;
595e948693eSPhilip Paeps 	boolean_t is_v6;
596e948693eSPhilip Paeps 	uint16_t flags;
597e948693eSPhilip Paeps 	boolean_t ignore;
598e948693eSPhilip Paeps 	boolean_t should_abort;
599e948693eSPhilip Paeps 
600e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_RX);
601e948693eSPhilip Paeps 
602e948693eSPhilip Paeps 	/* Basic packet information */
603e948693eSPhilip Paeps 	id = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_DESC_PTR);
604e948693eSPhilip Paeps 	size = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_BYTE_CNT);
605e948693eSPhilip Paeps 	label = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_Q_LABEL);
606e948693eSPhilip Paeps 	ok = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_OK) != 0);
607e948693eSPhilip Paeps 
6081b02e3c0SAndrew Rybchenko #if EFSYS_OPT_RX_SCATTER
609e948693eSPhilip Paeps 	sop = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_SOP) != 0);
610e948693eSPhilip Paeps 	jumbo_cont = (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_JUMBO_CONT) != 0);
6111b02e3c0SAndrew Rybchenko #endif	/* EFSYS_OPT_RX_SCATTER */
612e948693eSPhilip Paeps 
613e948693eSPhilip Paeps 	hdr_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_HDR_TYPE);
614e948693eSPhilip Paeps 
615a4983a11SAndrew Rybchenko 	is_v6 = (EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_IPV6_PKT) != 0);
616e948693eSPhilip Paeps 
617e948693eSPhilip Paeps 	/*
618e948693eSPhilip Paeps 	 * If packet is marked as OK and packet type is TCP/IP or
619e948693eSPhilip Paeps 	 * UDP/IP or other IP, then we can rely on the hardware checksums.
620e948693eSPhilip Paeps 	 */
621e948693eSPhilip Paeps 	switch (hdr_type) {
622e948693eSPhilip Paeps 	case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_TCP:
623e948693eSPhilip Paeps 		flags = EFX_PKT_TCP | EFX_CKSUM_TCPUDP;
624e948693eSPhilip Paeps 		if (is_v6) {
625e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV6);
626e948693eSPhilip Paeps 			flags |= EFX_PKT_IPV6;
627e948693eSPhilip Paeps 		} else {
628e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_TCP_IPV4);
629e948693eSPhilip Paeps 			flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
630e948693eSPhilip Paeps 		}
631e948693eSPhilip Paeps 		break;
632e948693eSPhilip Paeps 
633e948693eSPhilip Paeps 	case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_UDP:
634e948693eSPhilip Paeps 		flags = EFX_PKT_UDP | EFX_CKSUM_TCPUDP;
635e948693eSPhilip Paeps 		if (is_v6) {
636e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV6);
637e948693eSPhilip Paeps 			flags |= EFX_PKT_IPV6;
638e948693eSPhilip Paeps 		} else {
639e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_UDP_IPV4);
640e948693eSPhilip Paeps 			flags |= EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
641e948693eSPhilip Paeps 		}
642e948693eSPhilip Paeps 		break;
643e948693eSPhilip Paeps 
644e948693eSPhilip Paeps 	case FSE_AZ_RX_EV_HDR_TYPE_IPV4V6_OTHER:
645e948693eSPhilip Paeps 		if (is_v6) {
646e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV6);
647e948693eSPhilip Paeps 			flags = EFX_PKT_IPV6;
648e948693eSPhilip Paeps 		} else {
649e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_OTHER_IPV4);
650e948693eSPhilip Paeps 			flags = EFX_PKT_IPV4 | EFX_CKSUM_IPV4;
651e948693eSPhilip Paeps 		}
652e948693eSPhilip Paeps 		break;
653e948693eSPhilip Paeps 
654e948693eSPhilip Paeps 	case FSE_AZ_RX_EV_HDR_TYPE_OTHER:
655e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_NON_IP);
656e948693eSPhilip Paeps 		flags = 0;
657e948693eSPhilip Paeps 		break;
658e948693eSPhilip Paeps 
659e948693eSPhilip Paeps 	default:
660e948693eSPhilip Paeps 		EFSYS_ASSERT(B_FALSE);
661e948693eSPhilip Paeps 		flags = 0;
662e948693eSPhilip Paeps 		break;
663e948693eSPhilip Paeps 	}
664e948693eSPhilip Paeps 
6651b02e3c0SAndrew Rybchenko #if EFSYS_OPT_RX_SCATTER
666e948693eSPhilip Paeps 	/* Report scatter and header/lookahead split buffer flags */
667e948693eSPhilip Paeps 	if (sop)
668e948693eSPhilip Paeps 		flags |= EFX_PKT_START;
669e948693eSPhilip Paeps 	if (jumbo_cont)
670e948693eSPhilip Paeps 		flags |= EFX_PKT_CONT;
6711b02e3c0SAndrew Rybchenko #endif	/* EFSYS_OPT_RX_SCATTER */
672e948693eSPhilip Paeps 
673e948693eSPhilip Paeps 	/* Detect errors included in the FSF_AZ_RX_EV_PKT_OK indication */
674e948693eSPhilip Paeps 	if (!ok) {
6750f981da7SAndrew Rybchenko 		ignore = siena_ev_rx_not_ok(eep, eqp, label, id, &flags);
676e948693eSPhilip Paeps 		if (ignore) {
677e948693eSPhilip Paeps 			EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
678e948693eSPhilip Paeps 			    uint32_t, size, uint16_t, flags);
679e948693eSPhilip Paeps 
680e948693eSPhilip Paeps 			return (B_FALSE);
681e948693eSPhilip Paeps 		}
682e948693eSPhilip Paeps 	}
683e948693eSPhilip Paeps 
684e948693eSPhilip Paeps 	/* If we're not discarding the packet then it is ok */
685e948693eSPhilip Paeps 	if (~flags & EFX_DISCARD)
686e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_OK);
687e948693eSPhilip Paeps 
688e948693eSPhilip Paeps 	/* Detect multicast packets that didn't match the filter */
689e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_PKT) != 0) {
690e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_PKT);
691e948693eSPhilip Paeps 
692e948693eSPhilip Paeps 		if (EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_MCAST_HASH_MATCH) != 0) {
693e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_RX_MCAST_HASH_MATCH);
694e948693eSPhilip Paeps 		} else {
695e948693eSPhilip Paeps 			EFSYS_PROBE(mcast_mismatch);
696e948693eSPhilip Paeps 			flags |= EFX_ADDR_MISMATCH;
697e948693eSPhilip Paeps 		}
698e948693eSPhilip Paeps 	} else {
699e948693eSPhilip Paeps 		flags |= EFX_PKT_UNICAST;
700e948693eSPhilip Paeps 	}
701e948693eSPhilip Paeps 
702e948693eSPhilip Paeps 	/*
703e948693eSPhilip Paeps 	 * The packet parser in Siena can abort parsing packets under
704e948693eSPhilip Paeps 	 * certain error conditions, setting the PKT_NOT_PARSED bit
705e948693eSPhilip Paeps 	 * (which clears PKT_OK). If this is set, then don't trust
706e948693eSPhilip Paeps 	 * the PKT_TYPE field.
707e948693eSPhilip Paeps 	 */
708a4983a11SAndrew Rybchenko 	if (!ok) {
709e948693eSPhilip Paeps 		uint32_t parse_err;
710e948693eSPhilip Paeps 
711e948693eSPhilip Paeps 		parse_err = EFX_QWORD_FIELD(*eqp, FSF_CZ_RX_EV_PKT_NOT_PARSED);
712e948693eSPhilip Paeps 		if (parse_err != 0)
713e948693eSPhilip Paeps 			flags |= EFX_CHECK_VLAN;
714e948693eSPhilip Paeps 	}
715e948693eSPhilip Paeps 
716e948693eSPhilip Paeps 	if (~flags & EFX_CHECK_VLAN) {
717e948693eSPhilip Paeps 		uint32_t pkt_type;
718e948693eSPhilip Paeps 
719e948693eSPhilip Paeps 		pkt_type = EFX_QWORD_FIELD(*eqp, FSF_AZ_RX_EV_PKT_TYPE);
720e948693eSPhilip Paeps 		if (pkt_type >= FSE_AZ_RX_EV_PKT_TYPE_VLAN)
721e948693eSPhilip Paeps 			flags |= EFX_PKT_VLAN_TAGGED;
722e948693eSPhilip Paeps 	}
723e948693eSPhilip Paeps 
724e948693eSPhilip Paeps 	EFSYS_PROBE4(rx_complete, uint32_t, label, uint32_t, id,
725e948693eSPhilip Paeps 	    uint32_t, size, uint16_t, flags);
726e948693eSPhilip Paeps 
727e948693eSPhilip Paeps 	EFSYS_ASSERT(eecp->eec_rx != NULL);
728e948693eSPhilip Paeps 	should_abort = eecp->eec_rx(arg, label, id, size, flags);
729e948693eSPhilip Paeps 
730e948693eSPhilip Paeps 	return (should_abort);
731e948693eSPhilip Paeps }
732e948693eSPhilip Paeps 
733e948693eSPhilip Paeps static	__checkReturn	boolean_t
7340f981da7SAndrew Rybchenko siena_ev_tx(
735e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
736e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
737e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
738e948693eSPhilip Paeps 	__in_opt	void *arg)
739e948693eSPhilip Paeps {
740e948693eSPhilip Paeps 	uint32_t id;
741e948693eSPhilip Paeps 	uint32_t label;
742e948693eSPhilip Paeps 	boolean_t should_abort;
743e948693eSPhilip Paeps 
744e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_TX);
745e948693eSPhilip Paeps 
746e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0 &&
747e948693eSPhilip Paeps 	    EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) == 0 &&
748e948693eSPhilip Paeps 	    EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) == 0 &&
749e948693eSPhilip Paeps 	    EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) == 0) {
750e948693eSPhilip Paeps 
751e948693eSPhilip Paeps 		id = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_DESC_PTR);
752e948693eSPhilip Paeps 		label = EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_Q_LABEL);
753e948693eSPhilip Paeps 
754e948693eSPhilip Paeps 		EFSYS_PROBE2(tx_complete, uint32_t, label, uint32_t, id);
755e948693eSPhilip Paeps 
756e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_tx != NULL);
757e948693eSPhilip Paeps 		should_abort = eecp->eec_tx(arg, label, id);
758e948693eSPhilip Paeps 
759e948693eSPhilip Paeps 		return (should_abort);
760e948693eSPhilip Paeps 	}
761e948693eSPhilip Paeps 
762e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_COMP) != 0)
763e948693eSPhilip Paeps 		EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
764e948693eSPhilip Paeps 			    uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
765e948693eSPhilip Paeps 			    uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
766e948693eSPhilip Paeps 
767e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_ERR) != 0)
768e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_ERR);
769e948693eSPhilip Paeps 
770e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_PKT_TOO_BIG) != 0)
771e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_TX_PKT_TOO_BIG);
772e948693eSPhilip Paeps 
773e948693eSPhilip Paeps 	if (EFX_QWORD_FIELD(*eqp, FSF_AZ_TX_EV_WQ_FF_FULL) != 0)
774e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_TX_WQ_FF_FULL);
775e948693eSPhilip Paeps 
776e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_TX_UNEXPECTED);
777e948693eSPhilip Paeps 	return (B_FALSE);
778e948693eSPhilip Paeps }
779e948693eSPhilip Paeps 
780e948693eSPhilip Paeps static	__checkReturn	boolean_t
7810f981da7SAndrew Rybchenko siena_ev_global(
782e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
783e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
784e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
785e948693eSPhilip Paeps 	__in_opt	void *arg)
786e948693eSPhilip Paeps {
7870de035aaSAndrew Rybchenko 	_NOTE(ARGUNUSED(eqp, eecp, arg))
788e948693eSPhilip Paeps 
789e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_GLOBAL);
790e948693eSPhilip Paeps 
7910de035aaSAndrew Rybchenko 	return (B_FALSE);
792e948693eSPhilip Paeps }
793e948693eSPhilip Paeps 
794e948693eSPhilip Paeps static	__checkReturn	boolean_t
7950f981da7SAndrew Rybchenko siena_ev_driver(
796e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
797e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
798e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
799e948693eSPhilip Paeps 	__in_opt	void *arg)
800e948693eSPhilip Paeps {
801e948693eSPhilip Paeps 	boolean_t should_abort;
802e948693eSPhilip Paeps 
803e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_DRIVER);
804e948693eSPhilip Paeps 	should_abort = B_FALSE;
805e948693eSPhilip Paeps 
806e948693eSPhilip Paeps 	switch (EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBCODE)) {
807e948693eSPhilip Paeps 	case FSE_AZ_TX_DESCQ_FLS_DONE_EV: {
808cf07c70dSGeorge V. Neville-Neil 		uint32_t txq_index;
809e948693eSPhilip Paeps 
810e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DESCQ_FLS_DONE);
811e948693eSPhilip Paeps 
812cf07c70dSGeorge V. Neville-Neil 		txq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
813e948693eSPhilip Paeps 
814cf07c70dSGeorge V. Neville-Neil 		EFSYS_PROBE1(tx_descq_fls_done, uint32_t, txq_index);
815e948693eSPhilip Paeps 
816e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_txq_flush_done != NULL);
817cf07c70dSGeorge V. Neville-Neil 		should_abort = eecp->eec_txq_flush_done(arg, txq_index);
818e948693eSPhilip Paeps 
819e948693eSPhilip Paeps 		break;
820e948693eSPhilip Paeps 	}
821e948693eSPhilip Paeps 	case FSE_AZ_RX_DESCQ_FLS_DONE_EV: {
822cf07c70dSGeorge V. Neville-Neil 		uint32_t rxq_index;
823e948693eSPhilip Paeps 		uint32_t failed;
824e948693eSPhilip Paeps 
825cf07c70dSGeorge V. Neville-Neil 		rxq_index = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
826e948693eSPhilip Paeps 		failed = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
827e948693eSPhilip Paeps 
828e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_rxq_flush_done != NULL);
829e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_rxq_flush_failed != NULL);
830e948693eSPhilip Paeps 
831e948693eSPhilip Paeps 		if (failed) {
832e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_FAILED);
833e948693eSPhilip Paeps 
834cf07c70dSGeorge V. Neville-Neil 			EFSYS_PROBE1(rx_descq_fls_failed, uint32_t, rxq_index);
835e948693eSPhilip Paeps 
8363c838a9fSAndrew Rybchenko 			should_abort = eecp->eec_rxq_flush_failed(arg,
8373c838a9fSAndrew Rybchenko 								    rxq_index);
838e948693eSPhilip Paeps 		} else {
839e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DESCQ_FLS_DONE);
840e948693eSPhilip Paeps 
841cf07c70dSGeorge V. Neville-Neil 			EFSYS_PROBE1(rx_descq_fls_done, uint32_t, rxq_index);
842e948693eSPhilip Paeps 
843cf07c70dSGeorge V. Neville-Neil 			should_abort = eecp->eec_rxq_flush_done(arg, rxq_index);
844e948693eSPhilip Paeps 		}
845e948693eSPhilip Paeps 
846e948693eSPhilip Paeps 		break;
847e948693eSPhilip Paeps 	}
848e948693eSPhilip Paeps 	case FSE_AZ_EVQ_INIT_DONE_EV:
849e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_initialized != NULL);
850e948693eSPhilip Paeps 		should_abort = eecp->eec_initialized(arg);
851e948693eSPhilip Paeps 
852e948693eSPhilip Paeps 		break;
853e948693eSPhilip Paeps 
854e948693eSPhilip Paeps 	case FSE_AZ_EVQ_NOT_EN_EV:
855e948693eSPhilip Paeps 		EFSYS_PROBE(evq_not_en);
856e948693eSPhilip Paeps 		break;
857e948693eSPhilip Paeps 
858e948693eSPhilip Paeps 	case FSE_AZ_SRM_UPD_DONE_EV: {
859e948693eSPhilip Paeps 		uint32_t code;
860e948693eSPhilip Paeps 
861e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_DRIVER_SRM_UPD_DONE);
862e948693eSPhilip Paeps 
863e948693eSPhilip Paeps 		code = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
864e948693eSPhilip Paeps 
865e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_sram != NULL);
866e948693eSPhilip Paeps 		should_abort = eecp->eec_sram(arg, code);
867e948693eSPhilip Paeps 
868e948693eSPhilip Paeps 		break;
869e948693eSPhilip Paeps 	}
870e948693eSPhilip Paeps 	case FSE_AZ_WAKE_UP_EV: {
871e948693eSPhilip Paeps 		uint32_t id;
872e948693eSPhilip Paeps 
873e948693eSPhilip Paeps 		id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
874e948693eSPhilip Paeps 
875e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_wake_up != NULL);
876e948693eSPhilip Paeps 		should_abort = eecp->eec_wake_up(arg, id);
877e948693eSPhilip Paeps 
878e948693eSPhilip Paeps 		break;
879e948693eSPhilip Paeps 	}
880e948693eSPhilip Paeps 	case FSE_AZ_TX_PKT_NON_TCP_UDP:
881e948693eSPhilip Paeps 		EFSYS_PROBE(tx_pkt_non_tcp_udp);
882e948693eSPhilip Paeps 		break;
883e948693eSPhilip Paeps 
884e948693eSPhilip Paeps 	case FSE_AZ_TIMER_EV: {
885e948693eSPhilip Paeps 		uint32_t id;
886e948693eSPhilip Paeps 
887e948693eSPhilip Paeps 		id = EFX_QWORD_FIELD(*eqp, FSF_AZ_DRIVER_EV_SUBDATA);
888e948693eSPhilip Paeps 
889e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_timer != NULL);
890e948693eSPhilip Paeps 		should_abort = eecp->eec_timer(arg, id);
891e948693eSPhilip Paeps 
892e948693eSPhilip Paeps 		break;
893e948693eSPhilip Paeps 	}
894e948693eSPhilip Paeps 	case FSE_AZ_RX_DSC_ERROR_EV:
895e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_DRIVER_RX_DSC_ERROR);
896e948693eSPhilip Paeps 
897e948693eSPhilip Paeps 		EFSYS_PROBE(rx_dsc_error);
898e948693eSPhilip Paeps 
899e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_exception != NULL);
900e948693eSPhilip Paeps 		should_abort = eecp->eec_exception(arg,
901e948693eSPhilip Paeps 			EFX_EXCEPTION_RX_DSC_ERROR, 0);
902e948693eSPhilip Paeps 
903e948693eSPhilip Paeps 		break;
904e948693eSPhilip Paeps 
905e948693eSPhilip Paeps 	case FSE_AZ_TX_DSC_ERROR_EV:
906e948693eSPhilip Paeps 		EFX_EV_QSTAT_INCR(eep, EV_DRIVER_TX_DSC_ERROR);
907e948693eSPhilip Paeps 
908e948693eSPhilip Paeps 		EFSYS_PROBE(tx_dsc_error);
909e948693eSPhilip Paeps 
910e948693eSPhilip Paeps 		EFSYS_ASSERT(eecp->eec_exception != NULL);
911e948693eSPhilip Paeps 		should_abort = eecp->eec_exception(arg,
912e948693eSPhilip Paeps 			EFX_EXCEPTION_TX_DSC_ERROR, 0);
913e948693eSPhilip Paeps 
914e948693eSPhilip Paeps 		break;
915e948693eSPhilip Paeps 
916e948693eSPhilip Paeps 	default:
917e948693eSPhilip Paeps 		break;
918e948693eSPhilip Paeps 	}
919e948693eSPhilip Paeps 
920e948693eSPhilip Paeps 	return (should_abort);
921e948693eSPhilip Paeps }
922e948693eSPhilip Paeps 
923e948693eSPhilip Paeps static	__checkReturn	boolean_t
9240f981da7SAndrew Rybchenko siena_ev_drv_gen(
925e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
926e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
927e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
928e948693eSPhilip Paeps 	__in_opt	void *arg)
929e948693eSPhilip Paeps {
930e948693eSPhilip Paeps 	uint32_t data;
931e948693eSPhilip Paeps 	boolean_t should_abort;
932e948693eSPhilip Paeps 
933e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_DRV_GEN);
934e948693eSPhilip Paeps 
935e948693eSPhilip Paeps 	data = EFX_QWORD_FIELD(*eqp, FSF_AZ_EV_DATA_DW0);
936e948693eSPhilip Paeps 	if (data >= ((uint32_t)1 << 16)) {
937e948693eSPhilip Paeps 		EFSYS_PROBE3(bad_event, unsigned int, eep->ee_index,
938e948693eSPhilip Paeps 			    uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_1),
939e948693eSPhilip Paeps 			    uint32_t, EFX_QWORD_FIELD(*eqp, EFX_DWORD_0));
940e948693eSPhilip Paeps 		return (B_TRUE);
941e948693eSPhilip Paeps 	}
942e948693eSPhilip Paeps 
943e948693eSPhilip Paeps 	EFSYS_ASSERT(eecp->eec_software != NULL);
944e948693eSPhilip Paeps 	should_abort = eecp->eec_software(arg, (uint16_t)data);
945e948693eSPhilip Paeps 
946e948693eSPhilip Paeps 	return (should_abort);
947e948693eSPhilip Paeps }
948e948693eSPhilip Paeps 
949e948693eSPhilip Paeps #if EFSYS_OPT_MCDI
950e948693eSPhilip Paeps 
951e948693eSPhilip Paeps static	__checkReturn	boolean_t
9520f981da7SAndrew Rybchenko siena_ev_mcdi(
953e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
954e948693eSPhilip Paeps 	__in		efx_qword_t *eqp,
955e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
956e948693eSPhilip Paeps 	__in_opt	void *arg)
957e948693eSPhilip Paeps {
958e948693eSPhilip Paeps 	efx_nic_t *enp = eep->ee_enp;
95998a9ac91SAndrew Rybchenko 	unsigned int code;
960e948693eSPhilip Paeps 	boolean_t should_abort = B_FALSE;
961e948693eSPhilip Paeps 
962e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
963e948693eSPhilip Paeps 
964e948693eSPhilip Paeps 	if (enp->en_family != EFX_FAMILY_SIENA)
965e948693eSPhilip Paeps 		goto out;
966e948693eSPhilip Paeps 
9676da0beb5SAndrew Rybchenko 	EFSYS_ASSERT(eecp->eec_link_change != NULL);
9686da0beb5SAndrew Rybchenko 	EFSYS_ASSERT(eecp->eec_exception != NULL);
9696da0beb5SAndrew Rybchenko #if EFSYS_OPT_MON_STATS
9706da0beb5SAndrew Rybchenko 	EFSYS_ASSERT(eecp->eec_monitor != NULL);
9716da0beb5SAndrew Rybchenko #endif
9726da0beb5SAndrew Rybchenko 
973e948693eSPhilip Paeps 	EFX_EV_QSTAT_INCR(eep, EV_MCDI_RESPONSE);
974e948693eSPhilip Paeps 
975e948693eSPhilip Paeps 	code = EFX_QWORD_FIELD(*eqp, MCDI_EVENT_CODE);
976e948693eSPhilip Paeps 	switch (code) {
977e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_BADSSERT:
978e948693eSPhilip Paeps 		efx_mcdi_ev_death(enp, EINTR);
979e948693eSPhilip Paeps 		break;
980e948693eSPhilip Paeps 
981e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_CMDDONE:
982e948693eSPhilip Paeps 		efx_mcdi_ev_cpl(enp,
983d8574f4fSAndrew Rybchenko 		    MCDI_EV_FIELD(eqp, CMDDONE_SEQ),
984d8574f4fSAndrew Rybchenko 		    MCDI_EV_FIELD(eqp, CMDDONE_DATALEN),
985d8574f4fSAndrew Rybchenko 		    MCDI_EV_FIELD(eqp, CMDDONE_ERRNO));
986e948693eSPhilip Paeps 		break;
987e948693eSPhilip Paeps 
988e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_LINKCHANGE: {
989e948693eSPhilip Paeps 		efx_link_mode_t link_mode;
990e948693eSPhilip Paeps 
991e948693eSPhilip Paeps 		siena_phy_link_ev(enp, eqp, &link_mode);
992e948693eSPhilip Paeps 		should_abort = eecp->eec_link_change(arg, link_mode);
993e948693eSPhilip Paeps 		break;
994e948693eSPhilip Paeps 	}
995e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_SENSOREVT: {
996e948693eSPhilip Paeps #if EFSYS_OPT_MON_STATS
997e948693eSPhilip Paeps 		efx_mon_stat_t id;
998e948693eSPhilip Paeps 		efx_mon_stat_value_t value;
999460cb568SAndrew Rybchenko 		efx_rc_t rc;
1000e948693eSPhilip Paeps 
10013c838a9fSAndrew Rybchenko 		if ((rc = mcdi_mon_ev(enp, eqp, &id, &value)) == 0)
1002e948693eSPhilip Paeps 			should_abort = eecp->eec_monitor(arg, id, value);
1003e948693eSPhilip Paeps 		else if (rc == ENOTSUP) {
1004e948693eSPhilip Paeps 			should_abort = eecp->eec_exception(arg,
1005e948693eSPhilip Paeps 				EFX_EXCEPTION_UNKNOWN_SENSOREVT,
1006e948693eSPhilip Paeps 				MCDI_EV_FIELD(eqp, DATA));
1007e948693eSPhilip Paeps 		} else
1008e948693eSPhilip Paeps 			EFSYS_ASSERT(rc == ENODEV);	/* Wrong port */
1009e948693eSPhilip Paeps #else
1010e948693eSPhilip Paeps 		should_abort = B_FALSE;
1011e948693eSPhilip Paeps #endif
1012e948693eSPhilip Paeps 		break;
1013e948693eSPhilip Paeps 	}
1014e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_SCHEDERR:
1015e948693eSPhilip Paeps 		/* Informational only */
1016e948693eSPhilip Paeps 		break;
1017e948693eSPhilip Paeps 
1018e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_REBOOT:
1019e948693eSPhilip Paeps 		efx_mcdi_ev_death(enp, EIO);
1020e948693eSPhilip Paeps 		break;
1021e948693eSPhilip Paeps 
1022e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_MAC_STATS_DMA:
1023e948693eSPhilip Paeps #if EFSYS_OPT_MAC_STATS
1024e948693eSPhilip Paeps 		if (eecp->eec_mac_stats != NULL) {
1025e948693eSPhilip Paeps 			eecp->eec_mac_stats(arg,
1026e948693eSPhilip Paeps 			    MCDI_EV_FIELD(eqp, MAC_STATS_DMA_GENERATION));
1027e948693eSPhilip Paeps 		}
1028e948693eSPhilip Paeps #endif
1029e948693eSPhilip Paeps 		break;
1030e948693eSPhilip Paeps 
1031e948693eSPhilip Paeps 	case MCDI_EVENT_CODE_FWALERT: {
1032e948693eSPhilip Paeps 		uint32_t reason = MCDI_EV_FIELD(eqp, FWALERT_REASON);
1033e948693eSPhilip Paeps 
1034e948693eSPhilip Paeps 		if (reason == MCDI_EVENT_FWALERT_REASON_SRAM_ACCESS)
1035e948693eSPhilip Paeps 			should_abort = eecp->eec_exception(arg,
1036e948693eSPhilip Paeps 				EFX_EXCEPTION_FWALERT_SRAM,
1037e948693eSPhilip Paeps 				MCDI_EV_FIELD(eqp, FWALERT_DATA));
1038e948693eSPhilip Paeps 		else
1039e948693eSPhilip Paeps 			should_abort = eecp->eec_exception(arg,
1040e948693eSPhilip Paeps 				EFX_EXCEPTION_UNKNOWN_FWALERT,
1041e948693eSPhilip Paeps 				MCDI_EV_FIELD(eqp, DATA));
1042e948693eSPhilip Paeps 		break;
1043e948693eSPhilip Paeps 	}
1044e948693eSPhilip Paeps 
1045e948693eSPhilip Paeps 	default:
1046e948693eSPhilip Paeps 		EFSYS_PROBE1(mc_pcol_error, int, code);
1047e948693eSPhilip Paeps 		break;
1048e948693eSPhilip Paeps 	}
1049e948693eSPhilip Paeps 
1050e948693eSPhilip Paeps out:
1051e948693eSPhilip Paeps 	return (should_abort);
1052e948693eSPhilip Paeps }
1053e948693eSPhilip Paeps 
1054c071447aSAndrew Rybchenko #endif	/* EFSYS_OPT_MCDI */
1055e948693eSPhilip Paeps 
1056460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
10570f981da7SAndrew Rybchenko siena_ev_qprime(
1058e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
1059e948693eSPhilip Paeps 	__in		unsigned int count)
1060e948693eSPhilip Paeps {
1061e948693eSPhilip Paeps 	efx_nic_t *enp = eep->ee_enp;
1062e948693eSPhilip Paeps 	uint32_t rptr;
1063e948693eSPhilip Paeps 	efx_dword_t dword;
1064e948693eSPhilip Paeps 
1065e948693eSPhilip Paeps 	rptr = count & eep->ee_mask;
1066e948693eSPhilip Paeps 
1067e948693eSPhilip Paeps 	EFX_POPULATE_DWORD_1(dword, FRF_AZ_EVQ_RPTR, rptr);
1068e948693eSPhilip Paeps 
1069e948693eSPhilip Paeps 	EFX_BAR_TBL_WRITED(enp, FR_AZ_EVQ_RPTR_REG, eep->ee_index,
1070e948693eSPhilip Paeps 			    &dword, B_FALSE);
1071e948693eSPhilip Paeps 
1072e948693eSPhilip Paeps 	return (0);
1073e948693eSPhilip Paeps }
1074e948693eSPhilip Paeps 
1075e948693eSPhilip Paeps #define	EFX_EV_BATCH	8
1076e948693eSPhilip Paeps 
10773c838a9fSAndrew Rybchenko static			void
10780f981da7SAndrew Rybchenko siena_ev_qpoll(
1079e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
1080e948693eSPhilip Paeps 	__inout		unsigned int *countp,
1081e948693eSPhilip Paeps 	__in		const efx_ev_callbacks_t *eecp,
1082e948693eSPhilip Paeps 	__in_opt	void *arg)
1083e948693eSPhilip Paeps {
1084e948693eSPhilip Paeps 	efx_qword_t ev[EFX_EV_BATCH];
1085e948693eSPhilip Paeps 	unsigned int batch;
1086e948693eSPhilip Paeps 	unsigned int total;
1087e948693eSPhilip Paeps 	unsigned int count;
1088e948693eSPhilip Paeps 	unsigned int index;
1089e948693eSPhilip Paeps 	size_t offset;
1090e948693eSPhilip Paeps 
1091e948693eSPhilip Paeps 	EFSYS_ASSERT(countp != NULL);
1092e948693eSPhilip Paeps 	EFSYS_ASSERT(eecp != NULL);
1093e948693eSPhilip Paeps 
1094e948693eSPhilip Paeps 	count = *countp;
1095e948693eSPhilip Paeps 	do {
1096e948693eSPhilip Paeps 		/* Read up until the end of the batch period */
1097e948693eSPhilip Paeps 		batch = EFX_EV_BATCH - (count & (EFX_EV_BATCH - 1));
1098e948693eSPhilip Paeps 		offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
1099e948693eSPhilip Paeps 		for (total = 0; total < batch; ++total) {
1100e948693eSPhilip Paeps 			EFSYS_MEM_READQ(eep->ee_esmp, offset, &(ev[total]));
1101e948693eSPhilip Paeps 
1102e948693eSPhilip Paeps 			if (!EFX_EV_PRESENT(ev[total]))
1103e948693eSPhilip Paeps 				break;
1104e948693eSPhilip Paeps 
1105e948693eSPhilip Paeps 			EFSYS_PROBE3(event, unsigned int, eep->ee_index,
1106e948693eSPhilip Paeps 			    uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_1),
1107e948693eSPhilip Paeps 			    uint32_t, EFX_QWORD_FIELD(ev[total], EFX_DWORD_0));
1108e948693eSPhilip Paeps 
1109e948693eSPhilip Paeps 			offset += sizeof (efx_qword_t);
1110e948693eSPhilip Paeps 		}
1111e948693eSPhilip Paeps 
1112e948693eSPhilip Paeps #if EFSYS_OPT_EV_PREFETCH && (EFSYS_OPT_EV_PREFETCH_PERIOD > 1)
1113e948693eSPhilip Paeps 		/*
1114e948693eSPhilip Paeps 		 * Prefetch the next batch when we get within PREFETCH_PERIOD
1115e948693eSPhilip Paeps 		 * of a completed batch. If the batch is smaller, then prefetch
1116e948693eSPhilip Paeps 		 * immediately.
1117e948693eSPhilip Paeps 		 */
1118e948693eSPhilip Paeps 		if (total == batch && total < EFSYS_OPT_EV_PREFETCH_PERIOD)
1119e948693eSPhilip Paeps 			EFSYS_MEM_PREFETCH(eep->ee_esmp, offset);
1120e948693eSPhilip Paeps #endif	/* EFSYS_OPT_EV_PREFETCH */
1121e948693eSPhilip Paeps 
1122e948693eSPhilip Paeps 		/* Process the batch of events */
1123e948693eSPhilip Paeps 		for (index = 0; index < total; ++index) {
1124e948693eSPhilip Paeps 			boolean_t should_abort;
1125e948693eSPhilip Paeps 			uint32_t code;
1126e948693eSPhilip Paeps 
1127e948693eSPhilip Paeps #if EFSYS_OPT_EV_PREFETCH
1128e948693eSPhilip Paeps 			/* Prefetch if we've now reached the batch period */
1129e948693eSPhilip Paeps 			if (total == batch &&
1130e948693eSPhilip Paeps 			    index + EFSYS_OPT_EV_PREFETCH_PERIOD == total) {
1131e948693eSPhilip Paeps 				offset = (count + batch) & eep->ee_mask;
1132e948693eSPhilip Paeps 				offset *= sizeof (efx_qword_t);
1133e948693eSPhilip Paeps 
1134e948693eSPhilip Paeps 				EFSYS_MEM_PREFETCH(eep->ee_esmp, offset);
1135e948693eSPhilip Paeps 			}
1136e948693eSPhilip Paeps #endif	/* EFSYS_OPT_EV_PREFETCH */
1137e948693eSPhilip Paeps 
1138e948693eSPhilip Paeps 			EFX_EV_QSTAT_INCR(eep, EV_ALL);
1139e948693eSPhilip Paeps 
1140e948693eSPhilip Paeps 			code = EFX_QWORD_FIELD(ev[index], FSF_AZ_EV_CODE);
11413c838a9fSAndrew Rybchenko 			switch (code) {
11423c838a9fSAndrew Rybchenko 			case FSE_AZ_EV_CODE_RX_EV:
11433c838a9fSAndrew Rybchenko 				should_abort = eep->ee_rx(eep,
11443c838a9fSAndrew Rybchenko 				    &(ev[index]), eecp, arg);
11453c838a9fSAndrew Rybchenko 				break;
11463c838a9fSAndrew Rybchenko 			case FSE_AZ_EV_CODE_TX_EV:
11473c838a9fSAndrew Rybchenko 				should_abort = eep->ee_tx(eep,
11483c838a9fSAndrew Rybchenko 				    &(ev[index]), eecp, arg);
11493c838a9fSAndrew Rybchenko 				break;
11503c838a9fSAndrew Rybchenko 			case FSE_AZ_EV_CODE_DRIVER_EV:
11513c838a9fSAndrew Rybchenko 				should_abort = eep->ee_driver(eep,
11523c838a9fSAndrew Rybchenko 				    &(ev[index]), eecp, arg);
11533c838a9fSAndrew Rybchenko 				break;
11543c838a9fSAndrew Rybchenko 			case FSE_AZ_EV_CODE_DRV_GEN_EV:
11553c838a9fSAndrew Rybchenko 				should_abort = eep->ee_drv_gen(eep,
11563c838a9fSAndrew Rybchenko 				    &(ev[index]), eecp, arg);
11573c838a9fSAndrew Rybchenko 				break;
11583c838a9fSAndrew Rybchenko #if EFSYS_OPT_MCDI
11593c838a9fSAndrew Rybchenko 			case FSE_AZ_EV_CODE_MCDI_EVRESPONSE:
11603c838a9fSAndrew Rybchenko 				should_abort = eep->ee_mcdi(eep,
11613c838a9fSAndrew Rybchenko 				    &(ev[index]), eecp, arg);
11623c838a9fSAndrew Rybchenko 				break;
11633c838a9fSAndrew Rybchenko #endif
11643c838a9fSAndrew Rybchenko 			case FSE_AZ_EV_CODE_GLOBAL_EV:
11653c838a9fSAndrew Rybchenko 				if (eep->ee_global) {
11663c838a9fSAndrew Rybchenko 					should_abort = eep->ee_global(eep,
11673c838a9fSAndrew Rybchenko 					    &(ev[index]), eecp, arg);
11683c838a9fSAndrew Rybchenko 					break;
11693c838a9fSAndrew Rybchenko 				}
11703c838a9fSAndrew Rybchenko 				/* else fallthrough */
11713c838a9fSAndrew Rybchenko 			default:
11723c838a9fSAndrew Rybchenko 				EFSYS_PROBE3(bad_event,
11733c838a9fSAndrew Rybchenko 				    unsigned int, eep->ee_index,
11743c838a9fSAndrew Rybchenko 				    uint32_t,
11753c838a9fSAndrew Rybchenko 				    EFX_QWORD_FIELD(ev[index], EFX_DWORD_1),
11763c838a9fSAndrew Rybchenko 				    uint32_t,
11773c838a9fSAndrew Rybchenko 				    EFX_QWORD_FIELD(ev[index], EFX_DWORD_0));
11783c838a9fSAndrew Rybchenko 
11793c838a9fSAndrew Rybchenko 				EFSYS_ASSERT(eecp->eec_exception != NULL);
11803c838a9fSAndrew Rybchenko 				(void) eecp->eec_exception(arg,
11813c838a9fSAndrew Rybchenko 					EFX_EXCEPTION_EV_ERROR, code);
11823c838a9fSAndrew Rybchenko 				should_abort = B_TRUE;
11833c838a9fSAndrew Rybchenko 			}
1184e948693eSPhilip Paeps 			if (should_abort) {
1185e948693eSPhilip Paeps 				/* Ignore subsequent events */
1186e948693eSPhilip Paeps 				total = index + 1;
1187e948693eSPhilip Paeps 				break;
1188e948693eSPhilip Paeps 			}
1189e948693eSPhilip Paeps 		}
1190e948693eSPhilip Paeps 
1191e948693eSPhilip Paeps 		/*
1192e948693eSPhilip Paeps 		 * Now that the hardware has most likely moved onto dma'ing
1193e948693eSPhilip Paeps 		 * into the next cache line, clear the processed events. Take
1194e948693eSPhilip Paeps 		 * care to only clear out events that we've processed
1195e948693eSPhilip Paeps 		 */
1196e948693eSPhilip Paeps 		EFX_SET_QWORD(ev[0]);
1197e948693eSPhilip Paeps 		offset = (count & eep->ee_mask) * sizeof (efx_qword_t);
1198e948693eSPhilip Paeps 		for (index = 0; index < total; ++index) {
1199e948693eSPhilip Paeps 			EFSYS_MEM_WRITEQ(eep->ee_esmp, offset, &(ev[0]));
1200e948693eSPhilip Paeps 			offset += sizeof (efx_qword_t);
1201e948693eSPhilip Paeps 		}
1202e948693eSPhilip Paeps 
1203e948693eSPhilip Paeps 		count += total;
1204e948693eSPhilip Paeps 
1205e948693eSPhilip Paeps 	} while (total == batch);
1206e948693eSPhilip Paeps 
1207e948693eSPhilip Paeps 	*countp = count;
1208e948693eSPhilip Paeps }
1209e948693eSPhilip Paeps 
12103c838a9fSAndrew Rybchenko static		void
12110f981da7SAndrew Rybchenko siena_ev_qpost(
1212e948693eSPhilip Paeps 	__in	efx_evq_t *eep,
1213e948693eSPhilip Paeps 	__in	uint16_t data)
1214e948693eSPhilip Paeps {
1215e948693eSPhilip Paeps 	efx_nic_t *enp = eep->ee_enp;
1216e948693eSPhilip Paeps 	efx_qword_t ev;
1217e948693eSPhilip Paeps 	efx_oword_t oword;
1218e948693eSPhilip Paeps 
1219e948693eSPhilip Paeps 	EFX_POPULATE_QWORD_2(ev, FSF_AZ_EV_CODE, FSE_AZ_EV_CODE_DRV_GEN_EV,
1220e948693eSPhilip Paeps 	    FSF_AZ_EV_DATA_DW0, (uint32_t)data);
1221e948693eSPhilip Paeps 
1222e948693eSPhilip Paeps 	EFX_POPULATE_OWORD_3(oword, FRF_AZ_DRV_EV_QID, eep->ee_index,
1223e948693eSPhilip Paeps 	    EFX_DWORD_0, EFX_QWORD_FIELD(ev, EFX_DWORD_0),
1224e948693eSPhilip Paeps 	    EFX_DWORD_1, EFX_QWORD_FIELD(ev, EFX_DWORD_1));
1225e948693eSPhilip Paeps 
1226e948693eSPhilip Paeps 	EFX_BAR_WRITEO(enp, FR_AZ_DRV_EV_REG, &oword);
1227e948693eSPhilip Paeps }
1228e948693eSPhilip Paeps 
1229460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
12300f981da7SAndrew Rybchenko siena_ev_qmoderate(
1231e948693eSPhilip Paeps 	__in		efx_evq_t *eep,
1232e948693eSPhilip Paeps 	__in		unsigned int us)
1233e948693eSPhilip Paeps {
1234e948693eSPhilip Paeps 	efx_nic_t *enp = eep->ee_enp;
12358bf93a04SAndrew Rybchenko 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1236e948693eSPhilip Paeps 	unsigned int locked;
1237e948693eSPhilip Paeps 	efx_dword_t dword;
1238460cb568SAndrew Rybchenko 	efx_rc_t rc;
1239e948693eSPhilip Paeps 
1240af9078c3SAndrew Rybchenko 	if (us > encp->enc_evq_timer_max_us) {
1241e948693eSPhilip Paeps 		rc = EINVAL;
1242e948693eSPhilip Paeps 		goto fail1;
1243e948693eSPhilip Paeps 	}
1244e948693eSPhilip Paeps 
1245e948693eSPhilip Paeps 	/* If the value is zero then disable the timer */
1246e948693eSPhilip Paeps 	if (us == 0) {
1247e948693eSPhilip Paeps 		EFX_POPULATE_DWORD_2(dword,
1248e948693eSPhilip Paeps 		    FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS,
1249e948693eSPhilip Paeps 		    FRF_CZ_TC_TIMER_VAL, 0);
1250e948693eSPhilip Paeps 	} else {
1251b839ed60SAndrew Rybchenko 		unsigned int ticks;
1252e948693eSPhilip Paeps 
1253b839ed60SAndrew Rybchenko 		if ((rc = efx_ev_usecs_to_ticks(enp, us, &ticks)) != 0)
1254b839ed60SAndrew Rybchenko 			goto fail2;
1255e948693eSPhilip Paeps 
1256b839ed60SAndrew Rybchenko 		EFSYS_ASSERT(ticks > 0);
1257e948693eSPhilip Paeps 		EFX_POPULATE_DWORD_2(dword,
1258e948693eSPhilip Paeps 		    FRF_CZ_TC_TIMER_MODE, FFE_CZ_TIMER_MODE_INT_HLDOFF,
1259b839ed60SAndrew Rybchenko 		    FRF_CZ_TC_TIMER_VAL, ticks - 1);
1260e948693eSPhilip Paeps 	}
1261e948693eSPhilip Paeps 
1262e948693eSPhilip Paeps 	locked = (eep->ee_index == 0) ? 1 : 0;
1263e948693eSPhilip Paeps 
1264e948693eSPhilip Paeps 	EFX_BAR_TBL_WRITED(enp, FR_BZ_TIMER_COMMAND_REGP0,
1265e948693eSPhilip Paeps 	    eep->ee_index, &dword, locked);
1266e948693eSPhilip Paeps 
1267e948693eSPhilip Paeps 	return (0);
1268e948693eSPhilip Paeps 
1269b839ed60SAndrew Rybchenko fail2:
1270b839ed60SAndrew Rybchenko 	EFSYS_PROBE(fail2);
1271e948693eSPhilip Paeps fail1:
1272460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1273e948693eSPhilip Paeps 
1274e948693eSPhilip Paeps 	return (rc);
1275e948693eSPhilip Paeps }
1276e948693eSPhilip Paeps 
1277460cb568SAndrew Rybchenko static	__checkReturn	efx_rc_t
12780f981da7SAndrew Rybchenko siena_ev_qcreate(
1279e948693eSPhilip Paeps 	__in		efx_nic_t *enp,
1280e948693eSPhilip Paeps 	__in		unsigned int index,
1281e948693eSPhilip Paeps 	__in		efsys_mem_t *esmp,
1282e948693eSPhilip Paeps 	__in		size_t n,
1283e948693eSPhilip Paeps 	__in		uint32_t id,
12845c4c3d92SAndrew Rybchenko 	__in		uint32_t us,
1285*a3fe009aSAndrew Rybchenko 	__in		uint32_t flags,
12863c838a9fSAndrew Rybchenko 	__in		efx_evq_t *eep)
1287e948693eSPhilip Paeps {
1288e948693eSPhilip Paeps 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1289e948693eSPhilip Paeps 	uint32_t size;
1290e948693eSPhilip Paeps 	efx_oword_t oword;
1291460cb568SAndrew Rybchenko 	efx_rc_t rc;
1292e948693eSPhilip Paeps 
1293a92a2133SAndrew Rybchenko 	_NOTE(ARGUNUSED(esmp))
1294a92a2133SAndrew Rybchenko 
12953c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ISP2(EFX_EVQ_MAXNEVS));
12963c838a9fSAndrew Rybchenko 	EFX_STATIC_ASSERT(ISP2(EFX_EVQ_MINNEVS));
1297e948693eSPhilip Paeps 
12983c838a9fSAndrew Rybchenko 	if (!ISP2(n) || (n < EFX_EVQ_MINNEVS) || (n > EFX_EVQ_MAXNEVS)) {
1299e948693eSPhilip Paeps 		rc = EINVAL;
1300e948693eSPhilip Paeps 		goto fail1;
1301e948693eSPhilip Paeps 	}
1302e948693eSPhilip Paeps 	if (index >= encp->enc_evq_limit) {
1303e948693eSPhilip Paeps 		rc = EINVAL;
1304e948693eSPhilip Paeps 		goto fail2;
1305e948693eSPhilip Paeps 	}
1306e948693eSPhilip Paeps #if EFSYS_OPT_RX_SCALE
1307e948693eSPhilip Paeps 	if (enp->en_intr.ei_type == EFX_INTR_LINE &&
1308e948693eSPhilip Paeps 	    index >= EFX_MAXRSS_LEGACY) {
1309e948693eSPhilip Paeps 		rc = EINVAL;
1310e948693eSPhilip Paeps 		goto fail3;
1311e948693eSPhilip Paeps 	}
1312e948693eSPhilip Paeps #endif
1313e948693eSPhilip Paeps 	for (size = 0; (1 << size) <= (EFX_EVQ_MAXNEVS / EFX_EVQ_MINNEVS);
1314e948693eSPhilip Paeps 	    size++)
1315e948693eSPhilip Paeps 		if ((1 << size) == (int)(n / EFX_EVQ_MINNEVS))
1316e948693eSPhilip Paeps 			break;
1317e948693eSPhilip Paeps 	if (id + (1 << size) >= encp->enc_buftbl_limit) {
1318e948693eSPhilip Paeps 		rc = EINVAL;
1319e948693eSPhilip Paeps 		goto fail4;
1320e948693eSPhilip Paeps 	}
1321e948693eSPhilip Paeps 
1322e948693eSPhilip Paeps 	/* Set up the handler table */
13230f981da7SAndrew Rybchenko 	eep->ee_rx	= siena_ev_rx;
13240f981da7SAndrew Rybchenko 	eep->ee_tx	= siena_ev_tx;
13250f981da7SAndrew Rybchenko 	eep->ee_driver	= siena_ev_driver;
13260f981da7SAndrew Rybchenko 	eep->ee_global	= siena_ev_global;
13270f981da7SAndrew Rybchenko 	eep->ee_drv_gen	= siena_ev_drv_gen;
1328e948693eSPhilip Paeps #if EFSYS_OPT_MCDI
13290f981da7SAndrew Rybchenko 	eep->ee_mcdi	= siena_ev_mcdi;
1330c071447aSAndrew Rybchenko #endif	/* EFSYS_OPT_MCDI */
1331e948693eSPhilip Paeps 
1332e948693eSPhilip Paeps 	/* Set up the new event queue */
1333e948693eSPhilip Paeps 	EFX_POPULATE_OWORD_1(oword, FRF_CZ_TIMER_Q_EN, 1);
13343c838a9fSAndrew Rybchenko 	EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, index, &oword, B_TRUE);
1335e948693eSPhilip Paeps 
1336e948693eSPhilip Paeps 	EFX_POPULATE_OWORD_3(oword, FRF_AZ_EVQ_EN, 1, FRF_AZ_EVQ_SIZE, size,
1337e948693eSPhilip Paeps 	    FRF_AZ_EVQ_BUF_BASE_ID, id);
1338e948693eSPhilip Paeps 
13393c838a9fSAndrew Rybchenko 	EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, index, &oword, B_TRUE);
1340e948693eSPhilip Paeps 
13415c4c3d92SAndrew Rybchenko 	/* Set initial interrupt moderation */
13425c4c3d92SAndrew Rybchenko 	siena_ev_qmoderate(eep, us);
13435c4c3d92SAndrew Rybchenko 
1344e948693eSPhilip Paeps 	return (0);
1345e948693eSPhilip Paeps 
1346e948693eSPhilip Paeps fail4:
1347e948693eSPhilip Paeps 	EFSYS_PROBE(fail4);
1348e948693eSPhilip Paeps #if EFSYS_OPT_RX_SCALE
1349e948693eSPhilip Paeps fail3:
1350e948693eSPhilip Paeps 	EFSYS_PROBE(fail3);
1351e948693eSPhilip Paeps #endif
1352e948693eSPhilip Paeps fail2:
1353e948693eSPhilip Paeps 	EFSYS_PROBE(fail2);
1354e948693eSPhilip Paeps fail1:
1355460cb568SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
1356e948693eSPhilip Paeps 
1357e948693eSPhilip Paeps 	return (rc);
1358e948693eSPhilip Paeps }
1359e948693eSPhilip Paeps 
1360e75412c9SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
13613c838a9fSAndrew Rybchenko 
1362fe900081SAndrew Rybchenko #if EFSYS_OPT_QSTATS
1363e948693eSPhilip Paeps #if EFSYS_OPT_NAMES
1364a260bd77SAndrew Rybchenko /* START MKCONFIG GENERATED EfxEventQueueStatNamesBlock c0f3bc5083b40532 */
1365a260bd77SAndrew Rybchenko static const char * const __efx_ev_qstat_name[] = {
1366e948693eSPhilip Paeps 	"all",
1367e948693eSPhilip Paeps 	"rx",
1368e948693eSPhilip Paeps 	"rx_ok",
1369e948693eSPhilip Paeps 	"rx_frm_trunc",
1370e948693eSPhilip Paeps 	"rx_tobe_disc",
1371e948693eSPhilip Paeps 	"rx_pause_frm_err",
1372e948693eSPhilip Paeps 	"rx_buf_owner_id_err",
1373e948693eSPhilip Paeps 	"rx_ipv4_hdr_chksum_err",
1374e948693eSPhilip Paeps 	"rx_tcp_udp_chksum_err",
1375e948693eSPhilip Paeps 	"rx_eth_crc_err",
1376e948693eSPhilip Paeps 	"rx_ip_frag_err",
1377e948693eSPhilip Paeps 	"rx_mcast_pkt",
1378e948693eSPhilip Paeps 	"rx_mcast_hash_match",
1379e948693eSPhilip Paeps 	"rx_tcp_ipv4",
1380e948693eSPhilip Paeps 	"rx_tcp_ipv6",
1381e948693eSPhilip Paeps 	"rx_udp_ipv4",
1382e948693eSPhilip Paeps 	"rx_udp_ipv6",
1383e948693eSPhilip Paeps 	"rx_other_ipv4",
1384e948693eSPhilip Paeps 	"rx_other_ipv6",
1385e948693eSPhilip Paeps 	"rx_non_ip",
13863c838a9fSAndrew Rybchenko 	"rx_batch",
1387e948693eSPhilip Paeps 	"tx",
1388e948693eSPhilip Paeps 	"tx_wq_ff_full",
1389e948693eSPhilip Paeps 	"tx_pkt_err",
1390e948693eSPhilip Paeps 	"tx_pkt_too_big",
1391e948693eSPhilip Paeps 	"tx_unexpected",
1392e948693eSPhilip Paeps 	"global",
1393e948693eSPhilip Paeps 	"global_mnt",
1394e948693eSPhilip Paeps 	"driver",
1395e948693eSPhilip Paeps 	"driver_srm_upd_done",
1396e948693eSPhilip Paeps 	"driver_tx_descq_fls_done",
1397e948693eSPhilip Paeps 	"driver_rx_descq_fls_done",
1398e948693eSPhilip Paeps 	"driver_rx_descq_fls_failed",
1399e948693eSPhilip Paeps 	"driver_rx_dsc_error",
1400e948693eSPhilip Paeps 	"driver_tx_dsc_error",
1401e948693eSPhilip Paeps 	"drv_gen",
1402e948693eSPhilip Paeps 	"mcdi_response",
1403e948693eSPhilip Paeps };
1404e948693eSPhilip Paeps /* END MKCONFIG GENERATED EfxEventQueueStatNamesBlock */
1405e948693eSPhilip Paeps 
14063c838a9fSAndrew Rybchenko 		const char *
1407e948693eSPhilip Paeps efx_ev_qstat_name(
1408e948693eSPhilip Paeps 	__in	efx_nic_t *enp,
1409e948693eSPhilip Paeps 	__in	unsigned int id)
1410e948693eSPhilip Paeps {
1411e948693eSPhilip Paeps 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
1412e948693eSPhilip Paeps 	EFSYS_ASSERT3U(id, <, EV_NQSTATS);
1413e948693eSPhilip Paeps 
1414e948693eSPhilip Paeps 	return (__efx_ev_qstat_name[id]);
1415e948693eSPhilip Paeps }
1416e948693eSPhilip Paeps #endif	/* EFSYS_OPT_NAMES */
1417fe900081SAndrew Rybchenko #endif	/* EFSYS_OPT_QSTATS */
1418e948693eSPhilip Paeps 
1419e75412c9SAndrew Rybchenko #if EFSYS_OPT_SIENA
14203c838a9fSAndrew Rybchenko 
1421e948693eSPhilip Paeps #if EFSYS_OPT_QSTATS
14223c838a9fSAndrew Rybchenko static					void
14230f981da7SAndrew Rybchenko siena_ev_qstats_update(
1424e948693eSPhilip Paeps 	__in				efx_evq_t *eep,
1425e948693eSPhilip Paeps 	__inout_ecount(EV_NQSTATS)	efsys_stat_t *stat)
1426e948693eSPhilip Paeps {
1427e948693eSPhilip Paeps 	unsigned int id;
1428e948693eSPhilip Paeps 
1429e948693eSPhilip Paeps 	for (id = 0; id < EV_NQSTATS; id++) {
1430e948693eSPhilip Paeps 		efsys_stat_t *essp = &stat[id];
1431e948693eSPhilip Paeps 
1432e948693eSPhilip Paeps 		EFSYS_STAT_INCR(essp, eep->ee_stat[id]);
1433e948693eSPhilip Paeps 		eep->ee_stat[id] = 0;
1434e948693eSPhilip Paeps 	}
1435e948693eSPhilip Paeps }
1436e948693eSPhilip Paeps #endif	/* EFSYS_OPT_QSTATS */
1437e948693eSPhilip Paeps 
14383c838a9fSAndrew Rybchenko static		void
14390f981da7SAndrew Rybchenko siena_ev_qdestroy(
1440e948693eSPhilip Paeps 	__in	efx_evq_t *eep)
1441e948693eSPhilip Paeps {
1442e948693eSPhilip Paeps 	efx_nic_t *enp = eep->ee_enp;
1443e948693eSPhilip Paeps 	efx_oword_t oword;
1444e948693eSPhilip Paeps 
1445e948693eSPhilip Paeps 	/* Purge event queue */
1446e948693eSPhilip Paeps 	EFX_ZERO_OWORD(oword);
1447e948693eSPhilip Paeps 
1448e948693eSPhilip Paeps 	EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL,
14493c838a9fSAndrew Rybchenko 	    eep->ee_index, &oword, B_TRUE);
1450e948693eSPhilip Paeps 
1451e948693eSPhilip Paeps 	EFX_ZERO_OWORD(oword);
1452a4983a11SAndrew Rybchenko 	EFX_BAR_TBL_WRITEO(enp, FR_AZ_TIMER_TBL, eep->ee_index, &oword, B_TRUE);
1453e948693eSPhilip Paeps }
1454e948693eSPhilip Paeps 
14553c838a9fSAndrew Rybchenko static		void
14560f981da7SAndrew Rybchenko siena_ev_fini(
1457e948693eSPhilip Paeps 	__in	efx_nic_t *enp)
1458e948693eSPhilip Paeps {
14593c838a9fSAndrew Rybchenko 	_NOTE(ARGUNUSED(enp))
1460e948693eSPhilip Paeps }
14613c838a9fSAndrew Rybchenko 
1462e75412c9SAndrew Rybchenko #endif /* EFSYS_OPT_SIENA */
1463