sfxge_ev.c (272325) | sfxge_ev.c (272328) |
---|---|
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: head/sys/dev/sfxge/sfxge_ev.c 272325 2014-09-30 20:18:10Z gnn $"); | 31__FBSDID("$FreeBSD: head/sys/dev/sfxge/sfxge_ev.c 272328 2014-09-30 20:36:07Z gnn $"); |
32 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/param.h> 37#include <sys/queue.h> 38#include <sys/systm.h> 39#include <sys/taskqueue.h> --- 57 unchanged lines hidden (view full) --- 97 rxq = sc->rxq[label]; 98 KASSERT(rxq != NULL, ("rxq == NULL")); 99 KASSERT(evq->index == rxq->index, 100 ("evq->index != rxq->index")); 101 102 if (rxq->init_state != SFXGE_RXQ_STARTED) 103 goto done; 104 | 32 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/param.h> 37#include <sys/queue.h> 38#include <sys/systm.h> 39#include <sys/taskqueue.h> --- 57 unchanged lines hidden (view full) --- 97 rxq = sc->rxq[label]; 98 KASSERT(rxq != NULL, ("rxq == NULL")); 99 KASSERT(evq->index == rxq->index, 100 ("evq->index != rxq->index")); 101 102 if (rxq->init_state != SFXGE_RXQ_STARTED) 103 goto done; 104 |
105 expected = rxq->pending++ & (SFXGE_NDESCS - 1); | 105 expected = rxq->pending++ & rxq->ptr_mask; |
106 if (id != expected) { 107 evq->exception = B_TRUE; 108 109 device_printf(sc->dev, "RX completion out of order" 110 " (id=%#x expected=%#x flags=%#x); resetting\n", 111 id, expected, flags); 112 sfxge_schedule_reset(sc); 113 --- 128 unchanged lines hidden (view full) --- 242 243 KASSERT(txq != NULL, ("txq == NULL")); 244 KASSERT(evq->index == txq->evq_index, 245 ("evq->index != txq->evq_index")); 246 247 if (txq->init_state != SFXGE_TXQ_STARTED) 248 goto done; 249 | 106 if (id != expected) { 107 evq->exception = B_TRUE; 108 109 device_printf(sc->dev, "RX completion out of order" 110 " (id=%#x expected=%#x flags=%#x); resetting\n", 111 id, expected, flags); 112 sfxge_schedule_reset(sc); 113 --- 128 unchanged lines hidden (view full) --- 242 243 KASSERT(txq != NULL, ("txq == NULL")); 244 KASSERT(evq->index == txq->evq_index, 245 ("evq->index != txq->evq_index")); 246 247 if (txq->init_state != SFXGE_TXQ_STARTED) 248 goto done; 249 |
250 stop = (id + 1) & (SFXGE_NDESCS - 1); 251 id = txq->pending & (SFXGE_NDESCS - 1); | 250 stop = (id + 1) & txq->ptr_mask; 251 id = txq->pending & txq->ptr_mask; |
252 | 252 |
253 delta = (stop >= id) ? (stop - id) : (SFXGE_NDESCS - id + stop); | 253 delta = (stop >= id) ? (stop - id) : (txq->entries - id + stop); |
254 txq->pending += delta; 255 256 evq->tx_done++; 257 258 if (txq->next == NULL && 259 evq->txqs != &(txq->next)) { 260 *(evq->txqs) = txq; 261 evq->txqs = &(txq->next); --- 368 unchanged lines hidden (view full) --- 630 evq->read_ptr = 0; 631 evq->exception = B_FALSE; 632 633 /* Add event counts before discarding the common evq state */ 634 efx_ev_qstats_update(evq->common, sc->ev_stats); 635 636 efx_ev_qdestroy(evq->common); 637 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id, | 254 txq->pending += delta; 255 256 evq->tx_done++; 257 258 if (txq->next == NULL && 259 evq->txqs != &(txq->next)) { 260 *(evq->txqs) = txq; 261 evq->txqs = &(txq->next); --- 368 unchanged lines hidden (view full) --- 630 evq->read_ptr = 0; 631 evq->exception = B_FALSE; 632 633 /* Add event counts before discarding the common evq state */ 634 efx_ev_qstats_update(evq->common, sc->ev_stats); 635 636 efx_ev_qdestroy(evq->common); 637 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id, |
638 EFX_EVQ_NBUFS(SFXGE_NEVS)); | 638 EFX_EVQ_NBUFS(evq->entries)); |
639 mtx_unlock(&evq->lock); 640} 641 642static int 643sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index) 644{ 645 struct sfxge_evq *evq; 646 efsys_mem_t *esmp; 647 int count; 648 int rc; 649 650 evq = sc->evq[index]; 651 esmp = &evq->mem; 652 653 KASSERT(evq->init_state == SFXGE_EVQ_INITIALIZED, 654 ("evq->init_state != SFXGE_EVQ_INITIALIZED")); 655 656 /* Clear all events. */ | 639 mtx_unlock(&evq->lock); 640} 641 642static int 643sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index) 644{ 645 struct sfxge_evq *evq; 646 efsys_mem_t *esmp; 647 int count; 648 int rc; 649 650 evq = sc->evq[index]; 651 esmp = &evq->mem; 652 653 KASSERT(evq->init_state == SFXGE_EVQ_INITIALIZED, 654 ("evq->init_state != SFXGE_EVQ_INITIALIZED")); 655 656 /* Clear all events. */ |
657 (void)memset(esmp->esm_base, 0xff, EFX_EVQ_SIZE(SFXGE_NEVS)); | 657 (void)memset(esmp->esm_base, 0xff, EFX_EVQ_SIZE(evq->entries)); |
658 659 /* Program the buffer table. */ 660 if ((rc = efx_sram_buf_tbl_set(sc->enp, evq->buf_base_id, esmp, | 658 659 /* Program the buffer table. */ 660 if ((rc = efx_sram_buf_tbl_set(sc->enp, evq->buf_base_id, esmp, |
661 EFX_EVQ_NBUFS(SFXGE_NEVS))) != 0) 662 return rc; | 661 EFX_EVQ_NBUFS(evq->entries))) != 0) 662 return (rc); |
663 664 /* Create the common code event queue. */ | 663 664 /* Create the common code event queue. */ |
665 if ((rc = efx_ev_qcreate(sc->enp, index, esmp, SFXGE_NEVS, | 665 if ((rc = efx_ev_qcreate(sc->enp, index, esmp, evq->entries, |
666 evq->buf_base_id, &evq->common)) != 0) 667 goto fail; 668 669 mtx_lock(&evq->lock); 670 671 /* Set the default moderation */ 672 (void)efx_ev_qmoderate(evq->common, sc->ev_moderation); 673 --- 26 unchanged lines hidden (view full) --- 700fail3: 701 mtx_lock(&evq->lock); 702 evq->init_state = SFXGE_EVQ_INITIALIZED; 703fail2: 704 mtx_unlock(&evq->lock); 705 efx_ev_qdestroy(evq->common); 706fail: 707 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id, | 666 evq->buf_base_id, &evq->common)) != 0) 667 goto fail; 668 669 mtx_lock(&evq->lock); 670 671 /* Set the default moderation */ 672 (void)efx_ev_qmoderate(evq->common, sc->ev_moderation); 673 --- 26 unchanged lines hidden (view full) --- 700fail3: 701 mtx_lock(&evq->lock); 702 evq->init_state = SFXGE_EVQ_INITIALIZED; 703fail2: 704 mtx_unlock(&evq->lock); 705 efx_ev_qdestroy(evq->common); 706fail: 707 efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id, |
708 EFX_EVQ_NBUFS(SFXGE_NEVS)); | 708 EFX_EVQ_NBUFS(evq->entries)); |
709 710 return (rc); 711} 712 713void 714sfxge_ev_stop(struct sfxge_softc *sc) 715{ 716 struct sfxge_intr *intr; --- 80 unchanged lines hidden (view full) --- 797 KASSERT(index < SFXGE_RX_SCALE_MAX, ("index >= SFXGE_RX_SCALE_MAX")); 798 799 evq = malloc(sizeof(struct sfxge_evq), M_SFXGE, M_ZERO | M_WAITOK); 800 evq->sc = sc; 801 evq->index = index; 802 sc->evq[index] = evq; 803 esmp = &evq->mem; 804 | 709 710 return (rc); 711} 712 713void 714sfxge_ev_stop(struct sfxge_softc *sc) 715{ 716 struct sfxge_intr *intr; --- 80 unchanged lines hidden (view full) --- 797 KASSERT(index < SFXGE_RX_SCALE_MAX, ("index >= SFXGE_RX_SCALE_MAX")); 798 799 evq = malloc(sizeof(struct sfxge_evq), M_SFXGE, M_ZERO | M_WAITOK); 800 evq->sc = sc; 801 evq->index = index; 802 sc->evq[index] = evq; 803 esmp = &evq->mem; 804 |
805 /* Build an event queue with room for one event per tx and rx buffer, 806 * plus some extra for link state events and MCDI completions. 807 * There are three tx queues in the first event queue and one in 808 * other. 809 */ 810 if (index == 0) 811 evq->entries = 812 ROUNDUP_POW_OF_TWO(sc->rxq_entries + 813 3 * sc->txq_entries + 814 128); 815 else 816 evq->entries = 817 ROUNDUP_POW_OF_TWO(sc->rxq_entries + 818 sc->txq_entries + 819 128); 820 |
|
805 /* Initialise TX completion list */ 806 evq->txqs = &evq->txq; 807 808 /* Allocate DMA space. */ | 821 /* Initialise TX completion list */ 822 evq->txqs = &evq->txq; 823 824 /* Allocate DMA space. */ |
809 if ((rc = sfxge_dma_alloc(sc, EFX_EVQ_SIZE(SFXGE_NEVS), esmp)) != 0) | 825 if ((rc = sfxge_dma_alloc(sc, EFX_EVQ_SIZE(evq->entries), esmp)) != 0) |
810 return (rc); 811 812 /* Allocate buffer table entries. */ | 826 return (rc); 827 828 /* Allocate buffer table entries. */ |
813 sfxge_sram_buf_tbl_alloc(sc, EFX_EVQ_NBUFS(SFXGE_NEVS), | 829 sfxge_sram_buf_tbl_alloc(sc, EFX_EVQ_NBUFS(evq->entries), |
814 &evq->buf_base_id); 815 816 mtx_init(&evq->lock, "evq", NULL, MTX_DEF); 817 818 evq->init_state = SFXGE_EVQ_INITIALIZED; 819 820 return (0); 821} --- 61 unchanged lines hidden --- | 830 &evq->buf_base_id); 831 832 mtx_init(&evq->lock, "evq", NULL, MTX_DEF); 833 834 evq->init_state = SFXGE_EVQ_INITIALIZED; 835 836 return (0); 837} --- 61 unchanged lines hidden --- |