From f2fdf0b3519a8485605a34ff0a32c3c4aae742de Mon Sep 17 00:00:00 2001 From: arybchik Date: Fri, 17 Jun 2016 08:56:01 +0000 Subject: [PATCH] MFC r301122 sfxge(4): set moderation in efx_ev_qcreate This simplifies setting an initial interrupt moderation value, and avoids most calls to evx_ev_qmoderate from contexts where MCDI is not allowed (MCDI is need for an EVQ timer workaround in a later patch). Submitted by: Andy Moreton Reviewed by: gnn Sponsored by: Solarflare Communications, Inc. Differential Revision: https://reviews.freebsd.org/D6673 git-svn-id: svn://svn.freebsd.org/base/stable/10@301980 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/sfxge/common/ef10_ev.c | 40 ++++++++++++++++++++++++++------ sys/dev/sfxge/common/ef10_impl.h | 1 + sys/dev/sfxge/common/efx.h | 1 + sys/dev/sfxge/common/efx_ev.c | 8 ++++++- sys/dev/sfxge/common/efx_impl.h | 2 +- sys/dev/sfxge/sfxge_ev.c | 5 +--- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/sys/dev/sfxge/common/ef10_ev.c b/sys/dev/sfxge/common/ef10_ev.c index 58582b26d..5a1c609df 100644 --- a/sys/dev/sfxge/common/ef10_ev.c +++ b/sys/dev/sfxge/common/ef10_ev.c @@ -92,8 +92,10 @@ efx_mcdi_init_evq( __in unsigned int instance, __in efsys_mem_t *esmp, __in size_t nevs, - __in uint32_t irq) + __in uint32_t irq, + __in uint32_t us) { + efx_nic_cfg_t *encp = &(enp->en_nic_cfg); efx_mcdi_req_t req; uint8_t payload[ MAX(MC_CMD_INIT_EVQ_IN_LEN(EFX_EVQ_NBUFS(EFX_EVQ_MAXNEVS)), @@ -141,10 +143,26 @@ efx_mcdi_init_evq( INIT_EVQ_IN_FLAG_RX_MERGE, 1, INIT_EVQ_IN_FLAG_TX_MERGE, 1); - MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_MODE, - MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); - MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_LOAD, 0); - MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_RELOAD, 0); + if (us == 0) { + MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_MODE, + MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); + MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_LOAD, 0); + MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_RELOAD, 0); + } else { + uint32_t timer_val; + + /* Calculate the timer value in quanta */ + timer_val = us * 1000 / encp->enc_evq_timer_quantum_ns; + + /* Moderation value is base 0 so we need to deduct 1 */ + if (timer_val > 0) + timer_val--; + + MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_MODE, + MC_CMD_INIT_EVQ_IN_TMR_INT_HLDOFF); + MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_LOAD, timer_val); + MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_TMR_RELOAD, timer_val); + } MCDI_IN_SET_DWORD(req, INIT_EVQ_IN_COUNT_MODE, MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); @@ -246,6 +264,7 @@ ef10_ev_qcreate( __in efsys_mem_t *esmp, __in size_t n, __in uint32_t id, + __in uint32_t us, __in efx_evq_t *eep) { efx_nic_cfg_t *encp = &(enp->en_nic_cfg); @@ -266,6 +285,11 @@ ef10_ev_qcreate( goto fail2; } + if (us > encp->enc_evq_timer_max_us) { + rc = EINVAL; + goto fail3; + } + /* Set up the handler table */ eep->ee_rx = ef10_ev_rx; eep->ee_tx = ef10_ev_tx; @@ -280,11 +304,13 @@ ef10_ev_qcreate( * Interrupts may be raised for events immediately after the queue is * created. See bug58606. */ - if ((rc = efx_mcdi_init_evq(enp, index, esmp, n, irq)) != 0) - goto fail3; + if ((rc = efx_mcdi_init_evq(enp, index, esmp, n, irq, us)) != 0) + goto fail4; return (0); +fail4: + EFSYS_PROBE(fail4); fail3: EFSYS_PROBE(fail3); fail2: diff --git a/sys/dev/sfxge/common/ef10_impl.h b/sys/dev/sfxge/common/ef10_impl.h index 3b850d2d0..68329c0b4 100644 --- a/sys/dev/sfxge/common/ef10_impl.h +++ b/sys/dev/sfxge/common/ef10_impl.h @@ -84,6 +84,7 @@ ef10_ev_qcreate( __in efsys_mem_t *esmp, __in size_t n, __in uint32_t id, + __in uint32_t us, __in efx_evq_t *eep); void diff --git a/sys/dev/sfxge/common/efx.h b/sys/dev/sfxge/common/efx.h index 32a3dfa3e..366dc135c 100644 --- a/sys/dev/sfxge/common/efx.h +++ b/sys/dev/sfxge/common/efx.h @@ -1602,6 +1602,7 @@ efx_ev_qcreate( __in efsys_mem_t *esmp, __in size_t n, __in uint32_t id, + __in uint32_t us, __deref_out efx_evq_t **eepp); extern void diff --git a/sys/dev/sfxge/common/efx_ev.c b/sys/dev/sfxge/common/efx_ev.c index 5e3bc40c1..b8aae06ac 100644 --- a/sys/dev/sfxge/common/efx_ev.c +++ b/sys/dev/sfxge/common/efx_ev.c @@ -70,6 +70,7 @@ siena_ev_qcreate( __in efsys_mem_t *esmp, __in size_t n, __in uint32_t id, + __in uint32_t us, __in efx_evq_t *eep); static void @@ -226,6 +227,7 @@ efx_ev_qcreate( __in efsys_mem_t *esmp, __in size_t n, __in uint32_t id, + __in uint32_t us, __deref_out efx_evq_t **eepp) { const efx_ev_ops_t *eevop = enp->en_eevop; @@ -262,7 +264,7 @@ efx_ev_qcreate( enp->en_ev_qcount++; *eepp = eep; - if ((rc = eevop->eevo_qcreate(enp, index, esmp, n, id, eep)) != 0) + if ((rc = eevop->eevo_qcreate(enp, index, esmp, n, id, us, eep)) != 0) goto fail2; return (0); @@ -1257,6 +1259,7 @@ siena_ev_qcreate( __in efsys_mem_t *esmp, __in size_t n, __in uint32_t id, + __in uint32_t us, __in efx_evq_t *eep) { efx_nic_cfg_t *encp = &(enp->en_nic_cfg); @@ -1312,6 +1315,9 @@ siena_ev_qcreate( EFX_BAR_TBL_WRITEO(enp, FR_AZ_EVQ_PTR_TBL, index, &oword, B_TRUE); + /* Set initial interrupt moderation */ + siena_ev_qmoderate(eep, us); + return (0); fail4: diff --git a/sys/dev/sfxge/common/efx_impl.h b/sys/dev/sfxge/common/efx_impl.h index 43e949202..18812a58b 100644 --- a/sys/dev/sfxge/common/efx_impl.h +++ b/sys/dev/sfxge/common/efx_impl.h @@ -95,7 +95,7 @@ typedef struct efx_ev_ops_s { void (*eevo_fini)(efx_nic_t *); efx_rc_t (*eevo_qcreate)(efx_nic_t *, unsigned int, efsys_mem_t *, size_t, uint32_t, - efx_evq_t *); + uint32_t, efx_evq_t *); void (*eevo_qdestroy)(efx_evq_t *); efx_rc_t (*eevo_qprime)(efx_evq_t *, unsigned int); void (*eevo_qpost)(efx_evq_t *, uint16_t); diff --git a/sys/dev/sfxge/sfxge_ev.c b/sys/dev/sfxge/sfxge_ev.c index c3cd32469..cfa106a30 100644 --- a/sys/dev/sfxge/sfxge_ev.c +++ b/sys/dev/sfxge/sfxge_ev.c @@ -699,14 +699,11 @@ sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index) /* Create the common code event queue. */ if ((rc = efx_ev_qcreate(sc->enp, index, esmp, evq->entries, - evq->buf_base_id, &evq->common)) != 0) + evq->buf_base_id, sc->ev_moderation, &evq->common)) != 0) goto fail; SFXGE_EVQ_LOCK(evq); - /* Set the default moderation */ - (void)efx_ev_qmoderate(evq->common, sc->ev_moderation); - /* Prime the event queue for interrupts */ if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0) goto fail2; -- 2.45.0