Deleted Added
full compact
sfxge_ev.c (280517) sfxge_ev.c (280522)
1/*-
2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
3 * All rights reserved.
4 *
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2010-2011 Solarflare Communications, Inc.
3 * All rights reserved.
4 *
5 * This software was developed in part by Philip Paeps under contract for
6 * Solarflare Communications, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/10/sys/dev/sfxge/sfxge_ev.c 280517 2015-03-25 10:21:42Z arybchik $");
31__FBSDID("$FreeBSD: stable/10/sys/dev/sfxge/sfxge_ev.c 280522 2015-03-25 10:27:54Z arybchik $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35
36#include "common/efx.h"
37
38#include "sfxge.h"
39

--- 365 unchanged lines hidden (view full) ---

405
406static void
407sfxge_ev_stat_update(struct sfxge_softc *sc)
408{
409 struct sfxge_evq *evq;
410 unsigned int index;
411 clock_t now;
412
32
33#include <sys/param.h>
34#include <sys/systm.h>
35
36#include "common/efx.h"
37
38#include "sfxge.h"
39

--- 365 unchanged lines hidden (view full) ---

405
406static void
407sfxge_ev_stat_update(struct sfxge_softc *sc)
408{
409 struct sfxge_evq *evq;
410 unsigned int index;
411 clock_t now;
412
413 sx_xlock(&sc->softc_lock);
413 SFXGE_ADAPTER_LOCK(sc);
414
415 if (sc->evq[0]->init_state != SFXGE_EVQ_STARTED)
416 goto out;
417
418 now = ticks;
419 if (now - sc->ev_stats_update_time < hz)
420 goto out;
421
422 sc->ev_stats_update_time = now;
423
424 /* Add event counts from each event queue in turn */
425 for (index = 0; index < sc->intr.n_alloc; index++) {
426 evq = sc->evq[index];
414
415 if (sc->evq[0]->init_state != SFXGE_EVQ_STARTED)
416 goto out;
417
418 now = ticks;
419 if (now - sc->ev_stats_update_time < hz)
420 goto out;
421
422 sc->ev_stats_update_time = now;
423
424 /* Add event counts from each event queue in turn */
425 for (index = 0; index < sc->intr.n_alloc; index++) {
426 evq = sc->evq[index];
427 mtx_lock(&evq->lock);
427 SFXGE_EVQ_LOCK(evq);
428 efx_ev_qstats_update(evq->common, sc->ev_stats);
428 efx_ev_qstats_update(evq->common, sc->ev_stats);
429 mtx_unlock(&evq->lock);
429 SFXGE_EVQ_UNLOCK(evq);
430 }
431out:
430 }
431out:
432 sx_xunlock(&sc->softc_lock);
432 SFXGE_ADAPTER_UNLOCK(sc);
433}
434
435static int
436sfxge_ev_stat_handler(SYSCTL_HANDLER_ARGS)
437{
438 struct sfxge_softc *sc = arg1;
439 unsigned int id = arg2;
440

--- 44 unchanged lines hidden (view full) ---

485sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
486{
487 struct sfxge_softc *sc = arg1;
488 struct sfxge_intr *intr = &sc->intr;
489 unsigned int moderation;
490 int error;
491 int index;
492
433}
434
435static int
436sfxge_ev_stat_handler(SYSCTL_HANDLER_ARGS)
437{
438 struct sfxge_softc *sc = arg1;
439 unsigned int id = arg2;
440

--- 44 unchanged lines hidden (view full) ---

485sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
486{
487 struct sfxge_softc *sc = arg1;
488 struct sfxge_intr *intr = &sc->intr;
489 unsigned int moderation;
490 int error;
491 int index;
492
493 sx_xlock(&sc->softc_lock);
493 SFXGE_ADAPTER_LOCK(sc);
494
495 if (req->newptr != NULL) {
496 if ((error = SYSCTL_IN(req, &moderation, sizeof(moderation)))
497 != 0)
498 goto out;
499
500 /* We may not be calling efx_ev_qmoderate() now,
501 * so we have to range-check the value ourselves.

--- 10 unchanged lines hidden (view full) ---

512 sfxge_ev_qmoderate(sc, index, moderation);
513 }
514 } else {
515 error = SYSCTL_OUT(req, &sc->ev_moderation,
516 sizeof(sc->ev_moderation));
517 }
518
519out:
494
495 if (req->newptr != NULL) {
496 if ((error = SYSCTL_IN(req, &moderation, sizeof(moderation)))
497 != 0)
498 goto out;
499
500 /* We may not be calling efx_ev_qmoderate() now,
501 * so we have to range-check the value ourselves.

--- 10 unchanged lines hidden (view full) ---

512 sfxge_ev_qmoderate(sc, index, moderation);
513 }
514 } else {
515 error = SYSCTL_OUT(req, &sc->ev_moderation,
516 sizeof(sc->ev_moderation));
517 }
518
519out:
520 sx_xunlock(&sc->softc_lock);
520 SFXGE_ADAPTER_UNLOCK(sc);
521
522 return (error);
523}
524
525static boolean_t
526sfxge_ev_initialized(void *arg)
527{
528 struct sfxge_evq *evq;

--- 38 unchanged lines hidden (view full) ---

567};
568
569
570int
571sfxge_ev_qpoll(struct sfxge_evq *evq)
572{
573 int rc;
574
521
522 return (error);
523}
524
525static boolean_t
526sfxge_ev_initialized(void *arg)
527{
528 struct sfxge_evq *evq;

--- 38 unchanged lines hidden (view full) ---

567};
568
569
570int
571sfxge_ev_qpoll(struct sfxge_evq *evq)
572{
573 int rc;
574
575 mtx_lock(&evq->lock);
575 SFXGE_EVQ_LOCK(evq);
576
577 if (evq->init_state != SFXGE_EVQ_STARTING &&
578 evq->init_state != SFXGE_EVQ_STARTED) {
579 rc = EINVAL;
580 goto fail;
581 }
582
583 /* Synchronize the DMA memory for reading */

--- 13 unchanged lines hidden (view full) ---

597
598 /* Perform any pending completion processing */
599 sfxge_ev_qcomplete(evq, B_TRUE);
600
601 /* Re-prime the event queue for interrupts */
602 if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
603 goto fail;
604
576
577 if (evq->init_state != SFXGE_EVQ_STARTING &&
578 evq->init_state != SFXGE_EVQ_STARTED) {
579 rc = EINVAL;
580 goto fail;
581 }
582
583 /* Synchronize the DMA memory for reading */

--- 13 unchanged lines hidden (view full) ---

597
598 /* Perform any pending completion processing */
599 sfxge_ev_qcomplete(evq, B_TRUE);
600
601 /* Re-prime the event queue for interrupts */
602 if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
603 goto fail;
604
605 mtx_unlock(&evq->lock);
605 SFXGE_EVQ_UNLOCK(evq);
606
607 return (0);
608
609fail:
606
607 return (0);
608
609fail:
610 mtx_unlock(&(evq->lock));
610 SFXGE_EVQ_UNLOCK(evq);
611 return (rc);
612}
613
614static void
615sfxge_ev_qstop(struct sfxge_softc *sc, unsigned int index)
616{
617 struct sfxge_evq *evq;
618
619 evq = sc->evq[index];
620
621 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
622 ("evq->init_state != SFXGE_EVQ_STARTED"));
623
611 return (rc);
612}
613
614static void
615sfxge_ev_qstop(struct sfxge_softc *sc, unsigned int index)
616{
617 struct sfxge_evq *evq;
618
619 evq = sc->evq[index];
620
621 KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
622 ("evq->init_state != SFXGE_EVQ_STARTED"));
623
624 mtx_lock(&evq->lock);
624 SFXGE_EVQ_LOCK(evq);
625 evq->init_state = SFXGE_EVQ_INITIALIZED;
626 evq->read_ptr = 0;
627 evq->exception = B_FALSE;
628
629#if EFSYS_OPT_QSTATS
630 /* Add event counts before discarding the common evq state */
631 efx_ev_qstats_update(evq->common, sc->ev_stats);
632#endif
633
634 efx_ev_qdestroy(evq->common);
635 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
636 EFX_EVQ_NBUFS(evq->entries));
625 evq->init_state = SFXGE_EVQ_INITIALIZED;
626 evq->read_ptr = 0;
627 evq->exception = B_FALSE;
628
629#if EFSYS_OPT_QSTATS
630 /* Add event counts before discarding the common evq state */
631 efx_ev_qstats_update(evq->common, sc->ev_stats);
632#endif
633
634 efx_ev_qdestroy(evq->common);
635 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
636 EFX_EVQ_NBUFS(evq->entries));
637 mtx_unlock(&evq->lock);
637 SFXGE_EVQ_UNLOCK(evq);
638}
639
640static int
641sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index)
642{
643 struct sfxge_evq *evq;
644 efsys_mem_t *esmp;
645 int count;

--- 13 unchanged lines hidden (view full) ---

659 EFX_EVQ_NBUFS(evq->entries))) != 0)
660 return (rc);
661
662 /* Create the common code event queue. */
663 if ((rc = efx_ev_qcreate(sc->enp, index, esmp, evq->entries,
664 evq->buf_base_id, &evq->common)) != 0)
665 goto fail;
666
638}
639
640static int
641sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index)
642{
643 struct sfxge_evq *evq;
644 efsys_mem_t *esmp;
645 int count;

--- 13 unchanged lines hidden (view full) ---

659 EFX_EVQ_NBUFS(evq->entries))) != 0)
660 return (rc);
661
662 /* Create the common code event queue. */
663 if ((rc = efx_ev_qcreate(sc->enp, index, esmp, evq->entries,
664 evq->buf_base_id, &evq->common)) != 0)
665 goto fail;
666
667 mtx_lock(&evq->lock);
667 SFXGE_EVQ_LOCK(evq);
668
669 /* Set the default moderation */
670 (void)efx_ev_qmoderate(evq->common, sc->ev_moderation);
671
672 /* Prime the event queue for interrupts */
673 if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
674 goto fail2;
675
676 evq->init_state = SFXGE_EVQ_STARTING;
677
668
669 /* Set the default moderation */
670 (void)efx_ev_qmoderate(evq->common, sc->ev_moderation);
671
672 /* Prime the event queue for interrupts */
673 if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
674 goto fail2;
675
676 evq->init_state = SFXGE_EVQ_STARTING;
677
678 mtx_unlock(&evq->lock);
678 SFXGE_EVQ_UNLOCK(evq);
679
680 /* Wait for the initialization event */
681 count = 0;
682 do {
683 /* Pause for 100 ms */
684 pause("sfxge evq init", hz / 10);
685
686 /* Check to see if the test event has been processed */

--- 4 unchanged lines hidden (view full) ---

691
692 rc = ETIMEDOUT;
693 goto fail3;
694
695done:
696 return (0);
697
698fail3:
679
680 /* Wait for the initialization event */
681 count = 0;
682 do {
683 /* Pause for 100 ms */
684 pause("sfxge evq init", hz / 10);
685
686 /* Check to see if the test event has been processed */

--- 4 unchanged lines hidden (view full) ---

691
692 rc = ETIMEDOUT;
693 goto fail3;
694
695done:
696 return (0);
697
698fail3:
699 mtx_lock(&evq->lock);
699 SFXGE_EVQ_LOCK(evq);
700 evq->init_state = SFXGE_EVQ_INITIALIZED;
701fail2:
700 evq->init_state = SFXGE_EVQ_INITIALIZED;
701fail2:
702 mtx_unlock(&evq->lock);
702 SFXGE_EVQ_UNLOCK(evq);
703 efx_ev_qdestroy(evq->common);
704fail:
705 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
706 EFX_EVQ_NBUFS(evq->entries));
707
708 return (rc);
709}
710

--- 64 unchanged lines hidden (view full) ---

775 KASSERT(evq->init_state == SFXGE_EVQ_INITIALIZED,
776 ("evq->init_state != SFXGE_EVQ_INITIALIZED"));
777 KASSERT(evq->txqs == &evq->txq, ("evq->txqs != &evq->txq"));
778
779 sfxge_dma_free(&evq->mem);
780
781 sc->evq[index] = NULL;
782
703 efx_ev_qdestroy(evq->common);
704fail:
705 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
706 EFX_EVQ_NBUFS(evq->entries));
707
708 return (rc);
709}
710

--- 64 unchanged lines hidden (view full) ---

775 KASSERT(evq->init_state == SFXGE_EVQ_INITIALIZED,
776 ("evq->init_state != SFXGE_EVQ_INITIALIZED"));
777 KASSERT(evq->txqs == &evq->txq, ("evq->txqs != &evq->txq"));
778
779 sfxge_dma_free(&evq->mem);
780
781 sc->evq[index] = NULL;
782
783 mtx_destroy(&evq->lock);
783 SFXGE_EVQ_LOCK_DESTROY(evq);
784
785 free(evq, M_SFXGE);
786}
787
788static int
789sfxge_ev_qinit(struct sfxge_softc *sc, unsigned int index)
790{
791 struct sfxge_evq *evq;

--- 30 unchanged lines hidden (view full) ---

822 /* Allocate DMA space. */
823 if ((rc = sfxge_dma_alloc(sc, EFX_EVQ_SIZE(evq->entries), esmp)) != 0)
824 return (rc);
825
826 /* Allocate buffer table entries. */
827 sfxge_sram_buf_tbl_alloc(sc, EFX_EVQ_NBUFS(evq->entries),
828 &evq->buf_base_id);
829
784
785 free(evq, M_SFXGE);
786}
787
788static int
789sfxge_ev_qinit(struct sfxge_softc *sc, unsigned int index)
790{
791 struct sfxge_evq *evq;

--- 30 unchanged lines hidden (view full) ---

822 /* Allocate DMA space. */
823 if ((rc = sfxge_dma_alloc(sc, EFX_EVQ_SIZE(evq->entries), esmp)) != 0)
824 return (rc);
825
826 /* Allocate buffer table entries. */
827 sfxge_sram_buf_tbl_alloc(sc, EFX_EVQ_NBUFS(evq->entries),
828 &evq->buf_base_id);
829
830 mtx_init(&evq->lock, "evq", NULL, MTX_DEF);
830 SFXGE_EVQ_LOCK_INIT(evq, "evq");
831
832 evq->init_state = SFXGE_EVQ_INITIALIZED;
833
834 return (0);
835}
836
837void
838sfxge_ev_fini(struct sfxge_softc *sc)

--- 60 unchanged lines hidden ---
831
832 evq->init_state = SFXGE_EVQ_INITIALIZED;
833
834 return (0);
835}
836
837void
838sfxge_ev_fini(struct sfxge_softc *sc)

--- 60 unchanged lines hidden ---