2 * Copyright (c) 2010-2016 Solarflare Communications Inc.
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * The views and conclusions contained in the software and documentation are
30 * those of the authors and should not be interpreted as representing official
31 * policies, either expressed or implied, of the FreeBSD Project.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/param.h>
41 #include <sys/queue.h>
42 #include <sys/systm.h>
43 #include <sys/taskqueue.h>
45 #include "common/efx.h"
50 sfxge_ev_qcomplete(struct sfxge_evq *evq, boolean_t eop)
52 struct sfxge_softc *sc;
54 struct sfxge_rxq *rxq;
55 struct sfxge_txq *txq;
57 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
63 if ((txq = evq->txq) != NULL) {
65 evq->txqs = &(evq->txq);
68 struct sfxge_txq *next;
73 KASSERT(txq->evq_index == index,
74 ("txq->evq_index != index"));
76 if (txq->pending != txq->completed)
77 sfxge_tx_qcomplete(txq, evq);
80 } while (txq != NULL);
83 if (rxq->pending != rxq->completed)
84 sfxge_rx_qcomplete(rxq, eop);
87 static struct sfxge_rxq *
88 sfxge_get_rxq_by_label(struct sfxge_evq *evq, uint32_t label)
90 struct sfxge_rxq *rxq;
92 KASSERT(label == 0, ("unexpected rxq label != 0"));
94 rxq = evq->sc->rxq[evq->index];
96 KASSERT(rxq != NULL, ("rxq == NULL"));
97 KASSERT(evq->index == rxq->index, ("evq->index != rxq->index"));
103 sfxge_ev_rx(void *arg, uint32_t label, uint32_t id, uint32_t size,
106 struct sfxge_evq *evq;
107 struct sfxge_softc *sc;
108 struct sfxge_rxq *rxq;
111 struct sfxge_rx_sw_desc *rx_desc;
114 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
121 rxq = sfxge_get_rxq_by_label(evq, label);
122 if (__predict_false(rxq->init_state != SFXGE_RXQ_STARTED))
125 stop = (id + 1) & rxq->ptr_mask;
126 id = rxq->pending & rxq->ptr_mask;
127 delta = (stop >= id) ? (stop - id) : (rxq->entries - id + stop);
128 rxq->pending += delta;
132 (delta > efx_nic_cfg_get(sc->enp)->enc_rx_batch_max)) {
133 evq->exception = B_TRUE;
135 device_printf(sc->dev, "RX completion out of order"
136 " (id=%#x delta=%u flags=%#x); resetting\n",
138 sfxge_schedule_reset(sc);
144 rx_desc = &rxq->queue[id];
146 prefetch_read_many(rx_desc->mbuf);
148 for (; id != stop; id = (id + 1) & rxq->ptr_mask) {
149 rx_desc = &rxq->queue[id];
150 KASSERT(rx_desc->flags == EFX_DISCARD,
151 ("rx_desc->flags != EFX_DISCARD"));
152 rx_desc->flags = flags;
154 KASSERT(size < (1 << 16), ("size > (1 << 16)"));
155 rx_desc->size = (uint16_t)size;
160 if (rxq->pending - rxq->completed >= SFXGE_RX_BATCH)
161 sfxge_ev_qcomplete(evq, B_FALSE);
164 return (evq->rx_done >= SFXGE_EV_BATCH);
168 sfxge_ev_exception(void *arg, uint32_t code, uint32_t data)
170 struct sfxge_evq *evq;
171 struct sfxge_softc *sc;
173 evq = (struct sfxge_evq *)arg;
174 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
178 DBGPRINT(sc->dev, "[%d] %s", evq->index,
179 (code == EFX_EXCEPTION_RX_RECOVERY) ? "RX_RECOVERY" :
180 (code == EFX_EXCEPTION_RX_DSC_ERROR) ? "RX_DSC_ERROR" :
181 (code == EFX_EXCEPTION_TX_DSC_ERROR) ? "TX_DSC_ERROR" :
182 (code == EFX_EXCEPTION_UNKNOWN_SENSOREVT) ? "UNKNOWN_SENSOREVT" :
183 (code == EFX_EXCEPTION_FWALERT_SRAM) ? "FWALERT_SRAM" :
184 (code == EFX_EXCEPTION_UNKNOWN_FWALERT) ? "UNKNOWN_FWALERT" :
185 (code == EFX_EXCEPTION_RX_ERROR) ? "RX_ERROR" :
186 (code == EFX_EXCEPTION_TX_ERROR) ? "TX_ERROR" :
187 (code == EFX_EXCEPTION_EV_ERROR) ? "EV_ERROR" :
190 evq->exception = B_TRUE;
192 if (code != EFX_EXCEPTION_UNKNOWN_SENSOREVT) {
193 device_printf(sc->dev,
194 "hardware exception (code=%u); resetting\n",
196 sfxge_schedule_reset(sc);
203 sfxge_ev_rxq_flush_done(void *arg, uint32_t rxq_index)
205 struct sfxge_evq *evq;
206 struct sfxge_softc *sc;
207 struct sfxge_rxq *rxq;
211 evq = (struct sfxge_evq *)arg;
212 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
215 rxq = sc->rxq[rxq_index];
217 KASSERT(rxq != NULL, ("rxq == NULL"));
219 /* Resend a software event on the correct queue */
221 if (index == evq->index) {
222 sfxge_rx_qflush_done(rxq);
226 evq = sc->evq[index];
227 magic = sfxge_sw_ev_rxq_magic(SFXGE_SW_EV_RX_QFLUSH_DONE, rxq);
229 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
230 ("evq not started"));
231 efx_ev_qpost(evq->common, magic);
237 sfxge_ev_rxq_flush_failed(void *arg, uint32_t rxq_index)
239 struct sfxge_evq *evq;
240 struct sfxge_softc *sc;
241 struct sfxge_rxq *rxq;
245 evq = (struct sfxge_evq *)arg;
246 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
249 rxq = sc->rxq[rxq_index];
251 KASSERT(rxq != NULL, ("rxq == NULL"));
253 /* Resend a software event on the correct queue */
255 evq = sc->evq[index];
256 magic = sfxge_sw_ev_rxq_magic(SFXGE_SW_EV_RX_QFLUSH_FAILED, rxq);
258 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
259 ("evq not started"));
260 efx_ev_qpost(evq->common, magic);
265 static struct sfxge_txq *
266 sfxge_get_txq_by_label(struct sfxge_evq *evq, enum sfxge_txq_type label)
270 KASSERT((evq->index == 0 && label < SFXGE_TXQ_NTYPES) ||
271 (label == SFXGE_TXQ_IP_TCP_UDP_CKSUM), ("unexpected txq label"));
272 index = (evq->index == 0) ? label : (evq->index - 1 + SFXGE_TXQ_NTYPES);
273 return (evq->sc->txq[index]);
277 sfxge_ev_tx(void *arg, uint32_t label, uint32_t id)
279 struct sfxge_evq *evq;
280 struct sfxge_txq *txq;
284 evq = (struct sfxge_evq *)arg;
285 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
287 txq = sfxge_get_txq_by_label(evq, label);
289 KASSERT(txq != NULL, ("txq == NULL"));
290 KASSERT(evq->index == txq->evq_index,
291 ("evq->index != txq->evq_index"));
293 if (__predict_false(txq->init_state != SFXGE_TXQ_STARTED))
296 stop = (id + 1) & txq->ptr_mask;
297 id = txq->pending & txq->ptr_mask;
299 delta = (stop >= id) ? (stop - id) : (txq->entries - id + stop);
300 txq->pending += delta;
304 if (txq->next == NULL &&
305 evq->txqs != &(txq->next)) {
307 evq->txqs = &(txq->next);
310 if (txq->pending - txq->completed >= SFXGE_TX_BATCH)
311 sfxge_tx_qcomplete(txq, evq);
314 return (evq->tx_done >= SFXGE_EV_BATCH);
318 sfxge_ev_txq_flush_done(void *arg, uint32_t txq_index)
320 struct sfxge_evq *evq;
321 struct sfxge_softc *sc;
322 struct sfxge_txq *txq;
325 evq = (struct sfxge_evq *)arg;
326 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
329 txq = sc->txq[txq_index];
331 KASSERT(txq != NULL, ("txq == NULL"));
332 KASSERT(txq->init_state == SFXGE_TXQ_INITIALIZED,
333 ("txq not initialized"));
335 if (txq->evq_index == evq->index) {
336 sfxge_tx_qflush_done(txq);
340 /* Resend a software event on the correct queue */
341 evq = sc->evq[txq->evq_index];
342 magic = sfxge_sw_ev_txq_magic(SFXGE_SW_EV_TX_QFLUSH_DONE, txq);
344 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
345 ("evq not started"));
346 efx_ev_qpost(evq->common, magic);
352 sfxge_ev_software(void *arg, uint16_t magic)
354 struct sfxge_evq *evq;
355 struct sfxge_softc *sc;
358 evq = (struct sfxge_evq *)arg;
359 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
363 label = magic & SFXGE_MAGIC_DMAQ_LABEL_MASK;
364 magic &= ~SFXGE_MAGIC_DMAQ_LABEL_MASK;
367 case SFXGE_SW_EV_MAGIC(SFXGE_SW_EV_RX_QFLUSH_DONE):
368 sfxge_rx_qflush_done(sfxge_get_rxq_by_label(evq, label));
371 case SFXGE_SW_EV_MAGIC(SFXGE_SW_EV_RX_QFLUSH_FAILED):
372 sfxge_rx_qflush_failed(sfxge_get_rxq_by_label(evq, label));
375 case SFXGE_SW_EV_MAGIC(SFXGE_SW_EV_RX_QREFILL):
376 sfxge_rx_qrefill(sfxge_get_rxq_by_label(evq, label));
379 case SFXGE_SW_EV_MAGIC(SFXGE_SW_EV_TX_QFLUSH_DONE): {
380 struct sfxge_txq *txq = sfxge_get_txq_by_label(evq, label);
382 KASSERT(txq != NULL, ("txq == NULL"));
383 KASSERT(evq->index == txq->evq_index,
384 ("evq->index != txq->evq_index"));
386 sfxge_tx_qflush_done(txq);
397 sfxge_ev_sram(void *arg, uint32_t code)
403 case EFX_SRAM_UPDATE:
404 EFSYS_PROBE(sram_update);
408 EFSYS_PROBE(sram_clear);
411 case EFX_SRAM_ILLEGAL_CLEAR:
412 EFSYS_PROBE(sram_illegal_clear);
416 KASSERT(B_FALSE, ("Impossible SRAM event"));
424 sfxge_ev_timer(void *arg, uint32_t index)
433 sfxge_ev_wake_up(void *arg, uint32_t index)
444 sfxge_ev_stat_update(struct sfxge_softc *sc)
446 struct sfxge_evq *evq;
450 SFXGE_ADAPTER_LOCK(sc);
452 if (__predict_false(sc->evq[0]->init_state != SFXGE_EVQ_STARTED))
456 if ((unsigned int)(now - sc->ev_stats_update_time) < (unsigned int)hz)
459 sc->ev_stats_update_time = now;
461 /* Add event counts from each event queue in turn */
462 for (index = 0; index < sc->evq_count; index++) {
463 evq = sc->evq[index];
465 efx_ev_qstats_update(evq->common, sc->ev_stats);
466 SFXGE_EVQ_UNLOCK(evq);
469 SFXGE_ADAPTER_UNLOCK(sc);
473 sfxge_ev_stat_handler(SYSCTL_HANDLER_ARGS)
475 struct sfxge_softc *sc = arg1;
476 unsigned int id = arg2;
478 sfxge_ev_stat_update(sc);
480 return (SYSCTL_OUT(req, &sc->ev_stats[id], sizeof(sc->ev_stats[id])));
484 sfxge_ev_stat_init(struct sfxge_softc *sc)
486 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
487 struct sysctl_oid_list *stat_list;
491 stat_list = SYSCTL_CHILDREN(sc->stats_node);
493 for (id = 0; id < EV_NQSTATS; id++) {
494 snprintf(name, sizeof(name), "ev_%s",
495 efx_ev_qstat_name(sc->enp, id));
498 OID_AUTO, name, CTLTYPE_U64|CTLFLAG_RD,
499 sc, id, sfxge_ev_stat_handler, "Q",
504 #endif /* EFSYS_OPT_QSTATS */
507 sfxge_ev_qmoderate(struct sfxge_softc *sc, unsigned int idx, unsigned int us)
509 struct sfxge_evq *evq;
515 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
516 ("evq->init_state != SFXGE_EVQ_STARTED"));
518 (void)efx_ev_qmoderate(eep, us);
522 sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
524 struct sfxge_softc *sc = arg1;
525 struct sfxge_intr *intr = &sc->intr;
526 unsigned int moderation;
530 SFXGE_ADAPTER_LOCK(sc);
532 if (req->newptr != NULL) {
533 if ((error = SYSCTL_IN(req, &moderation, sizeof(moderation)))
537 /* We may not be calling efx_ev_qmoderate() now,
538 * so we have to range-check the value ourselves.
541 efx_nic_cfg_get(sc->enp)->enc_evq_timer_max_us) {
546 sc->ev_moderation = moderation;
547 if (intr->state == SFXGE_INTR_STARTED) {
548 for (index = 0; index < sc->evq_count; index++)
549 sfxge_ev_qmoderate(sc, index, moderation);
552 error = SYSCTL_OUT(req, &sc->ev_moderation,
553 sizeof(sc->ev_moderation));
557 SFXGE_ADAPTER_UNLOCK(sc);
563 sfxge_ev_initialized(void *arg)
565 struct sfxge_evq *evq;
567 evq = (struct sfxge_evq *)arg;
568 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
570 /* Init done events may be duplicated on 7xxx */
571 KASSERT(evq->init_state == SFXGE_EVQ_STARTING ||
572 evq->init_state == SFXGE_EVQ_STARTED,
573 ("evq not starting"));
575 evq->init_state = SFXGE_EVQ_STARTED;
581 sfxge_ev_link_change(void *arg, efx_link_mode_t link_mode)
583 struct sfxge_evq *evq;
584 struct sfxge_softc *sc;
586 evq = (struct sfxge_evq *)arg;
587 SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
591 sfxge_mac_link_update(sc, link_mode);
596 static const efx_ev_callbacks_t sfxge_ev_callbacks = {
597 .eec_initialized = sfxge_ev_initialized,
598 .eec_rx = sfxge_ev_rx,
599 .eec_tx = sfxge_ev_tx,
600 .eec_exception = sfxge_ev_exception,
601 .eec_rxq_flush_done = sfxge_ev_rxq_flush_done,
602 .eec_rxq_flush_failed = sfxge_ev_rxq_flush_failed,
603 .eec_txq_flush_done = sfxge_ev_txq_flush_done,
604 .eec_software = sfxge_ev_software,
605 .eec_sram = sfxge_ev_sram,
606 .eec_wake_up = sfxge_ev_wake_up,
607 .eec_timer = sfxge_ev_timer,
608 .eec_link_change = sfxge_ev_link_change,
613 sfxge_ev_qpoll(struct sfxge_evq *evq)
619 if (__predict_false(evq->init_state != SFXGE_EVQ_STARTING &&
620 evq->init_state != SFXGE_EVQ_STARTED)) {
625 /* Synchronize the DMA memory for reading */
626 bus_dmamap_sync(evq->mem.esm_tag, evq->mem.esm_map,
627 BUS_DMASYNC_POSTREAD);
629 KASSERT(evq->rx_done == 0, ("evq->rx_done != 0"));
630 KASSERT(evq->tx_done == 0, ("evq->tx_done != 0"));
631 KASSERT(evq->txq == NULL, ("evq->txq != NULL"));
632 KASSERT(evq->txqs == &evq->txq, ("evq->txqs != &evq->txq"));
635 efx_ev_qpoll(evq->common, &evq->read_ptr, &sfxge_ev_callbacks, evq);
640 /* Perform any pending completion processing */
641 sfxge_ev_qcomplete(evq, B_TRUE);
643 /* Re-prime the event queue for interrupts */
644 if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
647 SFXGE_EVQ_UNLOCK(evq);
652 SFXGE_EVQ_UNLOCK(evq);
657 sfxge_ev_qstop(struct sfxge_softc *sc, unsigned int index)
659 struct sfxge_evq *evq;
661 evq = sc->evq[index];
663 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
664 ("evq->init_state != SFXGE_EVQ_STARTED"));
667 evq->init_state = SFXGE_EVQ_INITIALIZED;
669 evq->exception = B_FALSE;
672 /* Add event counts before discarding the common evq state */
673 efx_ev_qstats_update(evq->common, sc->ev_stats);
676 efx_ev_qdestroy(evq->common);
677 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
678 EFX_EVQ_NBUFS(evq->entries));
679 SFXGE_EVQ_UNLOCK(evq);
683 sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index)
685 struct sfxge_evq *evq;
690 evq = sc->evq[index];
693 KASSERT(evq->init_state == SFXGE_EVQ_INITIALIZED,
694 ("evq->init_state != SFXGE_EVQ_INITIALIZED"));
696 /* Clear all events. */
697 (void)memset(esmp->esm_base, 0xff, EFX_EVQ_SIZE(evq->entries));
699 /* Program the buffer table. */
700 if ((rc = efx_sram_buf_tbl_set(sc->enp, evq->buf_base_id, esmp,
701 EFX_EVQ_NBUFS(evq->entries))) != 0)
704 /* Create the common code event queue. */
705 if ((rc = efx_ev_qcreate(sc->enp, index, esmp, evq->entries,
706 evq->buf_base_id, sc->ev_moderation, &evq->common)) != 0)
711 /* Prime the event queue for interrupts */
712 if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
715 evq->init_state = SFXGE_EVQ_STARTING;
717 SFXGE_EVQ_UNLOCK(evq);
719 /* Wait for the initialization event */
722 /* Pause for 100 ms */
723 pause("sfxge evq init", hz / 10);
725 /* Check to see if the test event has been processed */
726 if (evq->init_state == SFXGE_EVQ_STARTED)
729 } while (++count < 20);
739 evq->init_state = SFXGE_EVQ_INITIALIZED;
741 SFXGE_EVQ_UNLOCK(evq);
742 efx_ev_qdestroy(evq->common);
744 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
745 EFX_EVQ_NBUFS(evq->entries));
751 sfxge_ev_stop(struct sfxge_softc *sc)
753 struct sfxge_intr *intr;
760 KASSERT(intr->state == SFXGE_INTR_STARTED,
761 ("Interrupts not started"));
763 /* Stop the event queue(s) */
764 index = sc->evq_count;
766 sfxge_ev_qstop(sc, index);
768 /* Tear down the event module */
773 sfxge_ev_start(struct sfxge_softc *sc)
775 struct sfxge_intr *intr;
781 KASSERT(intr->state == SFXGE_INTR_STARTED,
782 ("intr->state != SFXGE_INTR_STARTED"));
784 /* Initialize the event module */
785 if ((rc = efx_ev_init(sc->enp)) != 0)
788 /* Start the event queues */
789 for (index = 0; index < sc->evq_count; index++) {
790 if ((rc = sfxge_ev_qstart(sc, index)) != 0)
797 /* Stop the event queue(s) */
799 sfxge_ev_qstop(sc, index);
801 /* Tear down the event module */
802 efx_ev_fini(sc->enp);
808 sfxge_ev_qfini(struct sfxge_softc *sc, unsigned int index)
810 struct sfxge_evq *evq;
812 evq = sc->evq[index];
814 KASSERT(evq->init_state == SFXGE_EVQ_INITIALIZED,
815 ("evq->init_state != SFXGE_EVQ_INITIALIZED"));
816 KASSERT(evq->txqs == &evq->txq, ("evq->txqs != &evq->txq"));
818 sfxge_dma_free(&evq->mem);
820 sc->evq[index] = NULL;
822 SFXGE_EVQ_LOCK_DESTROY(evq);
828 sfxge_ev_qinit(struct sfxge_softc *sc, unsigned int index)
830 struct sfxge_evq *evq;
834 KASSERT(index < SFXGE_RX_SCALE_MAX, ("index >= SFXGE_RX_SCALE_MAX"));
836 evq = malloc(sizeof(struct sfxge_evq), M_SFXGE, M_ZERO | M_WAITOK);
839 sc->evq[index] = evq;
842 /* Build an event queue with room for one event per tx and rx buffer,
843 * plus some extra for link state events and MCDI completions.
844 * There are three tx queues in the first event queue and one in
849 ROUNDUP_POW_OF_TWO(sc->rxq_entries +
850 3 * sc->txq_entries +
854 ROUNDUP_POW_OF_TWO(sc->rxq_entries +
858 /* Initialise TX completion list */
859 evq->txqs = &evq->txq;
861 /* Allocate DMA space. */
862 if ((rc = sfxge_dma_alloc(sc, EFX_EVQ_SIZE(evq->entries), esmp)) != 0)
865 /* Allocate buffer table entries. */
866 sfxge_sram_buf_tbl_alloc(sc, EFX_EVQ_NBUFS(evq->entries),
869 SFXGE_EVQ_LOCK_INIT(evq, device_get_nameunit(sc->dev), index);
871 evq->init_state = SFXGE_EVQ_INITIALIZED;
877 sfxge_ev_fini(struct sfxge_softc *sc)
879 struct sfxge_intr *intr;
884 KASSERT(intr->state == SFXGE_INTR_INITIALIZED,
885 ("intr->state != SFXGE_INTR_INITIALIZED"));
887 sc->ev_moderation = 0;
889 /* Tear down the event queue(s). */
890 index = sc->evq_count;
892 sfxge_ev_qfini(sc, index);
898 sfxge_ev_init(struct sfxge_softc *sc)
900 struct sysctl_ctx_list *sysctl_ctx = device_get_sysctl_ctx(sc->dev);
901 struct sysctl_oid *sysctl_tree = device_get_sysctl_tree(sc->dev);
902 struct sfxge_intr *intr;
908 sc->evq_count = intr->n_alloc;
910 KASSERT(intr->state == SFXGE_INTR_INITIALIZED,
911 ("intr->state != SFXGE_INTR_INITIALIZED"));
913 /* Set default interrupt moderation; add a sysctl to
914 * read and change it.
916 sc->ev_moderation = SFXGE_MODERATION;
917 SYSCTL_ADD_PROC(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
918 OID_AUTO, "int_mod", CTLTYPE_UINT|CTLFLAG_RW,
919 sc, 0, sfxge_int_mod_handler, "IU",
920 "sfxge interrupt moderation (us)");
923 * Initialize the event queue(s) - one per interrupt.
925 for (index = 0; index < sc->evq_count; index++) {
926 if ((rc = sfxge_ev_qinit(sc, index)) != 0)
931 sfxge_ev_stat_init(sc);
938 sfxge_ev_qfini(sc, index);