sfxge: Add macros to init, destroy, acquire, release and assert locks

Sponsored by:   Solarflare Communications, Inc.
Approved by:    gnn (mentor)
This commit is contained in:
arybchik 2015-02-04 20:03:57 +00:00
parent 8b7dd6cde0
commit 364932ee59
9 changed files with 192 additions and 128 deletions

View File

@ -517,6 +517,15 @@ typedef struct efsys_bar_s {
struct resource *esb_res;
} efsys_bar_t;
#define SFXGE_BAR_LOCK_INIT(_esbp, _name) \
mtx_init(&(_esbp)->esb_lock, (_name), NULL, MTX_DEF)
#define SFXGE_BAR_LOCK_DESTROY(_esbp) \
mtx_destroy(&(_esbp)->esb_lock)
#define SFXGE_BAR_LOCK(_esbp) \
mtx_lock(&(_esbp)->esb_lock)
#define SFXGE_BAR_UNLOCK(_esbp) \
mtx_unlock(&(_esbp)->esb_lock)
#define EFSYS_BAR_READD(_esbp, _offset, _edp, _lock) \
do { \
_NOTE(CONSTANTCONDITION) \
@ -525,7 +534,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_lock(&((_esbp)->esb_lock)); \
SFXGE_BAR_LOCK(_esbp); \
\
(_edp)->ed_u32[0] = bus_space_read_4((_esbp)->esb_tag, \
(_esbp)->esb_handle, (_offset)); \
@ -535,7 +544,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_unlock(&((_esbp)->esb_lock)); \
SFXGE_BAR_UNLOCK(_esbp); \
_NOTE(CONSTANTCONDITION) \
} while (B_FALSE)
@ -545,7 +554,7 @@ typedef struct efsys_bar_s {
KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \
("not power of 2 aligned")); \
\
mtx_lock(&((_esbp)->esb_lock)); \
SFXGE_BAR_LOCK(_esbp); \
\
(_eqp)->eq_u32[0] = bus_space_read_4((_esbp)->esb_tag, \
(_esbp)->esb_handle, (_offset)); \
@ -556,7 +565,7 @@ typedef struct efsys_bar_s {
uint32_t, (_eqp)->eq_u32[1], \
uint32_t, (_eqp)->eq_u32[0]); \
\
mtx_unlock(&((_esbp)->esb_lock)); \
SFXGE_BAR_UNLOCK(_esbp); \
_NOTE(CONSTANTCONDITION) \
} while (B_FALSE)
@ -568,7 +577,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_lock(&((_esbp)->esb_lock)); \
SFXGE_BAR_LOCK(_esbp); \
\
(_eop)->eo_u32[0] = bus_space_read_4((_esbp)->esb_tag, \
(_esbp)->esb_handle, (_offset)); \
@ -587,7 +596,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_unlock(&((_esbp)->esb_lock)); \
SFXGE_BAR_UNLOCK(_esbp); \
_NOTE(CONSTANTCONDITION) \
} while (B_FALSE)
@ -599,7 +608,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_lock(&((_esbp)->esb_lock)); \
SFXGE_BAR_LOCK(_esbp); \
\
EFSYS_PROBE2(bar_writed, unsigned int, (_offset), \
uint32_t, (_edp)->ed_u32[0]); \
@ -609,7 +618,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_unlock(&((_esbp)->esb_lock)); \
SFXGE_BAR_UNLOCK(_esbp); \
_NOTE(CONSTANTCONDITION) \
} while (B_FALSE)
@ -619,7 +628,7 @@ typedef struct efsys_bar_s {
KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \
("not power of 2 aligned")); \
\
mtx_lock(&((_esbp)->esb_lock)); \
SFXGE_BAR_LOCK(_esbp); \
\
EFSYS_PROBE3(bar_writeq, unsigned int, (_offset), \
uint32_t, (_eqp)->eq_u32[1], \
@ -630,7 +639,7 @@ typedef struct efsys_bar_s {
bus_space_write_4((_esbp)->esb_tag, (_esbp)->esb_handle,\
(_offset+4), (_eqp)->eq_u32[1]); \
\
mtx_unlock(&((_esbp)->esb_lock)); \
SFXGE_BAR_UNLOCK(_esbp); \
_NOTE(CONSTANTCONDITION) \
} while (B_FALSE)
@ -642,7 +651,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_lock(&((_esbp)->esb_lock)); \
SFXGE_BAR_LOCK(_esbp); \
\
EFSYS_PROBE5(bar_writeo, unsigned int, (_offset), \
uint32_t, (_eop)->eo_u32[3], \
@ -661,7 +670,7 @@ typedef struct efsys_bar_s {
\
_NOTE(CONSTANTCONDITION) \
if (_lock) \
mtx_unlock(&((_esbp)->esb_lock)); \
SFXGE_BAR_UNLOCK(_esbp); \
_NOTE(CONSTANTCONDITION) \
} while (B_FALSE)

View File

@ -95,7 +95,7 @@ sfxge_start(struct sfxge_softc *sc)
{
int rc;
sx_assert(&sc->softc_lock, LA_XLOCKED);
SFXGE_ADAPTER_LOCK_ASSERT_OWNED(sc);
if (sc->init_state == SFXGE_STARTED)
return (0);
@ -164,15 +164,15 @@ sfxge_if_init(void *arg)
sc = (struct sfxge_softc *)arg;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
(void)sfxge_start(sc);
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
}
static void
sfxge_stop(struct sfxge_softc *sc)
{
sx_assert(&sc->softc_lock, LA_XLOCKED);
SFXGE_ADAPTER_LOCK_ASSERT_OWNED(sc);
if (sc->init_state != SFXGE_STARTED)
return;
@ -212,7 +212,7 @@ sfxge_if_ioctl(struct ifnet *ifp, unsigned long command, caddr_t data)
switch (command) {
case SIOCSIFFLAGS:
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
if (ifp->if_flags & IFF_UP) {
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
if ((ifp->if_flags ^ sc->if_flags) &
@ -225,7 +225,7 @@ sfxge_if_ioctl(struct ifnet *ifp, unsigned long command, caddr_t data)
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
sfxge_stop(sc);
sc->if_flags = ifp->if_flags;
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
break;
case SIOCSIFMTU:
if (ifr->ifr_mtu == ifp->if_mtu) {
@ -238,11 +238,11 @@ sfxge_if_ioctl(struct ifnet *ifp, unsigned long command, caddr_t data)
error = 0;
} else {
/* Restart required */
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
sfxge_stop(sc);
ifp->if_mtu = ifr->ifr_mtu;
error = sfxge_start(sc);
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
if (error != 0) {
ifp->if_flags &= ~IFF_UP;
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
@ -256,7 +256,7 @@ sfxge_if_ioctl(struct ifnet *ifp, unsigned long command, caddr_t data)
sfxge_mac_filter_set(sc);
break;
case SIOCSIFCAP:
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
/*
* The networking core already rejects attempts to
@ -266,7 +266,7 @@ sfxge_if_ioctl(struct ifnet *ifp, unsigned long command, caddr_t data)
*/
if (~ifr->ifr_reqcap & SFXGE_CAP_FIXED) {
error = EINVAL;
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
break;
}
@ -280,7 +280,7 @@ sfxge_if_ioctl(struct ifnet *ifp, unsigned long command, caddr_t data)
else
ifp->if_hwassist &= ~CSUM_TSO;
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
break;
case SIOCSIFMEDIA:
case SIOCGIFMEDIA:
@ -298,9 +298,9 @@ sfxge_ifnet_fini(struct ifnet *ifp)
{
struct sfxge_softc *sc = ifp->if_softc;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
sfxge_stop(sc);
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
ifmedia_removeall(&sc->media);
ether_ifdetach(ifp);
@ -376,7 +376,7 @@ sfxge_bar_init(struct sfxge_softc *sc)
}
esbp->esb_tag = rman_get_bustag(esbp->esb_res);
esbp->esb_handle = rman_get_bushandle(esbp->esb_res);
mtx_init(&esbp->esb_lock, "sfxge_efsys_bar", NULL, MTX_DEF);
SFXGE_BAR_LOCK_INIT(esbp, "sfxge_efsys_bar");
return (0);
}
@ -388,7 +388,7 @@ sfxge_bar_fini(struct sfxge_softc *sc)
bus_release_resource(sc->dev, SYS_RES_MEMORY, esbp->esb_rid,
esbp->esb_res);
mtx_destroy(&esbp->esb_lock);
SFXGE_BAR_LOCK_DESTROY(esbp);
}
static int
@ -401,7 +401,7 @@ sfxge_create(struct sfxge_softc *sc)
dev = sc->dev;
sx_init(&sc->softc_lock, "sfxge_softc");
SFXGE_ADAPTER_LOCK_INIT(sc, "sfxge_softc");
sc->max_rss_channels = 0;
snprintf(rss_param_name, sizeof(rss_param_name),
@ -545,7 +545,7 @@ fail3:
fail:
sc->dev = NULL;
sx_destroy(&sc->softc_lock);
SFXGE_ADAPTER_LOCK_DESTROY(sc);
return (error);
}
@ -594,7 +594,7 @@ sfxge_destroy(struct sfxge_softc *sc)
taskqueue_drain(taskqueue_thread, &sc->task_reset);
/* Destroy the softc lock. */
sx_destroy(&sc->softc_lock);
SFXGE_ADAPTER_LOCK_DESTROY(sc);
}
static int
@ -696,7 +696,7 @@ sfxge_reset(void *arg, int npending)
sc = (struct sfxge_softc *)arg;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
if (sc->init_state != SFXGE_STARTED)
goto done;
@ -709,7 +709,7 @@ sfxge_reset(void *arg, int npending)
rc);
done:
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
}
void

View File

@ -314,4 +314,48 @@ extern int sfxge_port_ifmedia_init(struct sfxge_softc *sc);
#define SFXGE_MAX_MTU (9 * 1024)
#define SFXGE_ADAPTER_LOCK_INIT(_sc, _name) \
sx_init(&(_sc)->softc_lock, (_name))
#define SFXGE_ADAPTER_LOCK_DESTROY(_sc) \
sx_destroy(&(_sc)->softc_lock)
#define SFXGE_ADAPTER_LOCK(_sc) \
sx_xlock(&(_sc)->softc_lock)
#define SFXGE_ADAPTER_UNLOCK(_sc) \
sx_xunlock(&(_sc)->softc_lock)
#define SFXGE_ADAPTER_LOCK_ASSERT_OWNED(_sc) \
sx_assert(&(_sc)->softc_lock, LA_XLOCKED)
#define SFXGE_PORT_LOCK_INIT(_port, _name) \
mtx_init(&(_port)->lock, (_name), NULL, MTX_DEF)
#define SFXGE_PORT_LOCK_DESTROY(_port) \
mtx_destroy(&(_port)->lock)
#define SFXGE_PORT_LOCK(_port) \
mtx_lock(&(_port)->lock)
#define SFXGE_PORT_UNLOCK(_port) \
mtx_unlock(&(_port)->lock)
#define SFXGE_PORT_LOCK_ASSERT_OWNED(_port) \
mtx_assert(&(_port)->lock, MA_OWNED)
#define SFXGE_MCDI_LOCK_INIT(_mcdi, _name) \
mtx_init(&(_mcdi)->lock, (_name), NULL, MTX_DEF)
#define SFXGE_MCDI_LOCK_DESTROY(_mcdi) \
mtx_destroy(&(_mcdi)->lock)
#define SFXGE_MCDI_LOCK(_mcdi) \
mtx_lock(&(_mcdi)->lock)
#define SFXGE_MCDI_UNLOCK(_mcdi) \
mtx_unlock(&(_mcdi)->lock)
#define SFXGE_MCDI_LOCK_ASSERT_OWNED(_mcdi) \
mtx_assert(&(_mcdi)->lock, MA_OWNED)
#define SFXGE_EVQ_LOCK_INIT(_evq, _name) \
mtx_init(&(_evq)->lock, (_name), NULL, MTX_DEF)
#define SFXGE_EVQ_LOCK_DESTROY(_evq) \
mtx_destroy(&(_evq)->lock)
#define SFXGE_EVQ_LOCK(_evq) \
mtx_lock(&(_evq)->lock)
#define SFXGE_EVQ_UNLOCK(_evq) \
mtx_unlock(&(_evq)->lock)
#define SFXGE_EVQ_LOCK_ASSERT_OWNED(_evq) \
mtx_assert(&(_evq)->lock, MA_OWNED)
#endif /* _SFXGE_H */

View File

@ -415,7 +415,7 @@ sfxge_ev_stat_update(struct sfxge_softc *sc)
unsigned int index;
clock_t now;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
if (sc->evq[0]->init_state != SFXGE_EVQ_STARTED)
goto out;
@ -429,12 +429,12 @@ sfxge_ev_stat_update(struct sfxge_softc *sc)
/* Add event counts from each event queue in turn */
for (index = 0; index < sc->intr.n_alloc; index++) {
evq = sc->evq[index];
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
efx_ev_qstats_update(evq->common, sc->ev_stats);
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
}
out:
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
}
static int
@ -495,7 +495,7 @@ sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
int error;
int index;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
if (req->newptr != NULL) {
if ((error = SYSCTL_IN(req, &moderation, sizeof(moderation)))
@ -522,7 +522,7 @@ sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
}
out:
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
return (error);
}
@ -577,7 +577,7 @@ sfxge_ev_qpoll(struct sfxge_evq *evq)
{
int rc;
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
if (evq->init_state != SFXGE_EVQ_STARTING &&
evq->init_state != SFXGE_EVQ_STARTED) {
@ -607,12 +607,12 @@ sfxge_ev_qpoll(struct sfxge_evq *evq)
if ((rc = efx_ev_qprime(evq->common, evq->read_ptr)) != 0)
goto fail;
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
return (0);
fail:
mtx_unlock(&(evq->lock));
SFXGE_EVQ_UNLOCK(evq);
return (rc);
}
@ -626,7 +626,7 @@ sfxge_ev_qstop(struct sfxge_softc *sc, unsigned int index)
KASSERT(evq->init_state == SFXGE_EVQ_STARTED,
("evq->init_state != SFXGE_EVQ_STARTED"));
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
evq->init_state = SFXGE_EVQ_INITIALIZED;
evq->read_ptr = 0;
evq->exception = B_FALSE;
@ -639,7 +639,7 @@ sfxge_ev_qstop(struct sfxge_softc *sc, unsigned int index)
efx_ev_qdestroy(evq->common);
efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
EFX_EVQ_NBUFS(evq->entries));
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
}
static int
@ -669,7 +669,7 @@ sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index)
evq->buf_base_id, &evq->common)) != 0)
goto fail;
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
/* Set the default moderation */
(void)efx_ev_qmoderate(evq->common, sc->ev_moderation);
@ -680,7 +680,7 @@ sfxge_ev_qstart(struct sfxge_softc *sc, unsigned int index)
evq->init_state = SFXGE_EVQ_STARTING;
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
/* Wait for the initialization event */
count = 0;
@ -701,10 +701,10 @@ done:
return (0);
fail3:
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
evq->init_state = SFXGE_EVQ_INITIALIZED;
fail2:
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
efx_ev_qdestroy(evq->common);
fail:
efx_sram_buf_tbl_clear(sc->enp, evq->buf_base_id,
@ -785,7 +785,7 @@ sfxge_ev_qfini(struct sfxge_softc *sc, unsigned int index)
sc->evq[index] = NULL;
mtx_destroy(&evq->lock);
SFXGE_EVQ_LOCK_DESTROY(evq);
free(evq, M_SFXGE);
}
@ -832,7 +832,7 @@ sfxge_ev_qinit(struct sfxge_softc *sc, unsigned int index)
sfxge_sram_buf_tbl_alloc(sc, EFX_EVQ_NBUFS(evq->entries),
&evq->buf_base_id);
mtx_init(&evq->lock, "evq", NULL, MTX_DEF);
SFXGE_EVQ_LOCK_INIT(evq, "evq");
evq->init_state = SFXGE_EVQ_INITIALIZED;

View File

@ -52,8 +52,7 @@ __FBSDID("$FreeBSD$");
static void
sfxge_mcdi_acquire(struct sfxge_mcdi *mcdi)
{
mtx_lock(&mcdi->lock);
SFXGE_MCDI_LOCK(mcdi);
KASSERT(mcdi->state != SFXGE_MCDI_UNINITIALIZED,
("MCDI not initialized"));
@ -61,15 +60,14 @@ sfxge_mcdi_acquire(struct sfxge_mcdi *mcdi)
(void)cv_wait_sig(&mcdi->cv, &mcdi->lock);
mcdi->state = SFXGE_MCDI_BUSY;
mtx_unlock(&mcdi->lock);
SFXGE_MCDI_UNLOCK(mcdi);
}
/* Release ownership of MCDI on request completion. */
static void
sfxge_mcdi_release(struct sfxge_mcdi *mcdi)
{
mtx_lock(&mcdi->lock);
SFXGE_MCDI_LOCK(mcdi);
KASSERT((mcdi->state == SFXGE_MCDI_BUSY ||
mcdi->state == SFXGE_MCDI_COMPLETED),
("MCDI not busy or task not completed"));
@ -77,7 +75,7 @@ sfxge_mcdi_release(struct sfxge_mcdi *mcdi)
mcdi->state = SFXGE_MCDI_INITIALIZED;
cv_broadcast(&mcdi->cv);
mtx_unlock(&mcdi->lock);
SFXGE_MCDI_UNLOCK(mcdi);
}
static void
@ -160,11 +158,11 @@ sfxge_mcdi_ev_cpl(void *arg)
sc = (struct sfxge_softc *)arg;
mcdi = &sc->mcdi;
mtx_lock(&mcdi->lock);
SFXGE_MCDI_LOCK(mcdi);
KASSERT(mcdi->state == SFXGE_MCDI_BUSY, ("MCDI not busy"));
mcdi->state = SFXGE_MCDI_COMPLETED;
cv_broadcast(&mcdi->cv);
mtx_unlock(&mcdi->lock);
SFXGE_MCDI_UNLOCK(mcdi);
}
static void
@ -203,7 +201,7 @@ sfxge_mcdi_init(struct sfxge_softc *sc)
KASSERT(mcdi->state == SFXGE_MCDI_UNINITIALIZED,
("MCDI already initialized"));
mtx_init(&mcdi->lock, "sfxge_mcdi", NULL, MTX_DEF);
SFXGE_MCDI_LOCK_INIT(mcdi, "sfxge_mcdi");
mcdi->state = SFXGE_MCDI_INITIALIZED;
@ -220,7 +218,7 @@ sfxge_mcdi_init(struct sfxge_softc *sc)
return (0);
fail:
mtx_destroy(&mcdi->lock);
SFXGE_MCDI_LOCK_DESTROY(mcdi);
mcdi->state = SFXGE_MCDI_UNINITIALIZED;
return (rc);
}
@ -236,7 +234,7 @@ sfxge_mcdi_fini(struct sfxge_softc *sc)
mcdi = &sc->mcdi;
emtp = &mcdi->transport;
mtx_lock(&mcdi->lock);
SFXGE_MCDI_LOCK(mcdi);
KASSERT(mcdi->state == SFXGE_MCDI_INITIALIZED,
("MCDI not initialized"));
@ -244,7 +242,7 @@ sfxge_mcdi_fini(struct sfxge_softc *sc)
bzero(emtp, sizeof(*emtp));
cv_destroy(&mcdi->cv);
mtx_unlock(&mcdi->lock);
SFXGE_MCDI_UNLOCK(mcdi);
mtx_destroy(&mcdi->lock);
SFXGE_MCDI_LOCK_DESTROY(mcdi);
}

View File

@ -48,7 +48,7 @@ sfxge_mac_stat_update(struct sfxge_softc *sc)
unsigned int count;
int rc;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
if (port->init_state != SFXGE_PORT_STARTED) {
rc = 0;
@ -82,7 +82,7 @@ sfxge_mac_stat_update(struct sfxge_softc *sc)
rc = ETIMEDOUT;
out:
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
return (rc);
}
@ -170,7 +170,7 @@ sfxge_port_wanted_fc_handler(SYSCTL_HANDLER_ARGS)
sc = arg1;
port = &sc->port;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
if (req->newptr != NULL) {
if ((error = SYSCTL_IN(req, &fcntl, sizeof(fcntl))) != 0)
@ -191,7 +191,7 @@ sfxge_port_wanted_fc_handler(SYSCTL_HANDLER_ARGS)
}
out:
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
return (error);
}
@ -207,13 +207,13 @@ sfxge_port_link_fc_handler(SYSCTL_HANDLER_ARGS)
sc = arg1;
port = &sc->port;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
if (port->init_state == SFXGE_PORT_STARTED && SFXGE_LINK_UP(sc))
efx_mac_fcntl_get(sc->enp, &wanted_fc, &link_fc);
else
link_fc = 0;
error = SYSCTL_OUT(req, &link_fc, sizeof(link_fc));
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
return (error);
}
@ -262,7 +262,7 @@ sfxge_mac_poll_work(void *arg, int npending)
enp = sc->enp;
port = &sc->port;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
if (port->init_state != SFXGE_PORT_STARTED)
goto done;
@ -272,7 +272,7 @@ sfxge_mac_poll_work(void *arg, int npending)
sfxge_mac_link_update(sc, mode);
done:
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
}
static int
@ -320,7 +320,7 @@ sfxge_mac_filter_set(struct sfxge_softc *sc)
struct sfxge_port *port = &sc->port;
int rc;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
/*
* The function may be called without softc_lock held in the
* case of SIOCADDMULTI and SIOCDELMULTI ioctls. ioctl handler
@ -335,7 +335,7 @@ sfxge_mac_filter_set(struct sfxge_softc *sc)
rc = sfxge_mac_filter_set_locked(sc);
else
rc = 0;
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
return (rc);
}
@ -348,7 +348,7 @@ sfxge_port_stop(struct sfxge_softc *sc)
port = &sc->port;
enp = sc->enp;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
KASSERT(port->init_state == SFXGE_PORT_STARTED,
("port not started"));
@ -367,7 +367,7 @@ sfxge_port_stop(struct sfxge_softc *sc)
/* Destroy the common code port object. */
efx_port_fini(sc->enp);
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
}
int
@ -383,7 +383,7 @@ sfxge_port_start(struct sfxge_softc *sc)
port = &sc->port;
enp = sc->enp;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
KASSERT(port->init_state == SFXGE_PORT_INITIALIZED,
("port not initialized"));
@ -426,7 +426,7 @@ sfxge_port_start(struct sfxge_softc *sc)
port->init_state = SFXGE_PORT_STARTED;
/* Single poll in case there were missing initial events */
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
sfxge_mac_poll_work(sc, 0);
return (0);
@ -439,7 +439,7 @@ fail3:
fail2:
efx_port_fini(sc->enp);
fail:
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
return (rc);
}
@ -453,7 +453,7 @@ sfxge_phy_stat_update(struct sfxge_softc *sc)
unsigned int count;
int rc;
mtx_lock(&port->lock);
SFXGE_PORT_LOCK(port);
if (port->init_state != SFXGE_PORT_STARTED) {
rc = 0;
@ -487,7 +487,7 @@ sfxge_phy_stat_update(struct sfxge_softc *sc)
rc = ETIMEDOUT;
out:
mtx_unlock(&port->lock);
SFXGE_PORT_UNLOCK(port);
return (rc);
}
@ -554,7 +554,7 @@ sfxge_port_fini(struct sfxge_softc *sc)
sfxge_dma_free(esmp);
free(port->mac_stats.decode_buf, M_SFXGE);
mtx_destroy(&port->lock);
SFXGE_PORT_LOCK_DESTROY(port);
port->sc = NULL;
}
@ -577,7 +577,7 @@ sfxge_port_init(struct sfxge_softc *sc)
port->sc = sc;
mtx_init(&port->lock, "sfxge_port", NULL, MTX_DEF);
SFXGE_PORT_LOCK_INIT(port, "sfxge_port");
port->phy_stats.decode_buf = malloc(EFX_PHY_NSTATS * sizeof(uint32_t),
M_SFXGE, M_WAITOK | M_ZERO);
@ -615,7 +615,7 @@ fail2:
sfxge_dma_free(phy_stats_buf);
fail:
free(port->phy_stats.decode_buf, M_SFXGE);
(void)mtx_destroy(&port->lock);
SFXGE_PORT_LOCK_DESTROY(port);
port->sc = NULL;
return (rc);
}
@ -655,7 +655,7 @@ sfxge_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
efx_link_mode_t mode;
sc = ifp->if_softc;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
ifmr->ifm_status = IFM_AVALID;
ifmr->ifm_active = IFM_ETHER;
@ -669,7 +669,7 @@ sfxge_media_status(struct ifnet *ifp, struct ifmediareq *ifmr)
ifmr->ifm_active |= sfxge_port_link_fc_ifm(sc);
}
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
}
static int
@ -682,7 +682,7 @@ sfxge_media_change(struct ifnet *ifp)
sc = ifp->if_softc;
ifm = sc->media.ifm_cur;
sx_xlock(&sc->softc_lock);
SFXGE_ADAPTER_LOCK(sc);
if (!SFXGE_RUNNING(sc)) {
rc = 0;
@ -695,7 +695,7 @@ sfxge_media_change(struct ifnet *ifp)
rc = efx_phy_adv_cap_set(sc->enp, ifm->ifm_data);
out:
sx_xunlock(&sc->softc_lock);
SFXGE_ADAPTER_UNLOCK(sc);
return (rc);
}

View File

@ -207,7 +207,7 @@ sfxge_rx_qfill(struct sfxge_rxq *rxq, unsigned int target, boolean_t retrying)
prefetch_read_many(sc->enp);
prefetch_read_many(rxq->common);
mtx_assert(&evq->lock, MA_OWNED);
SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
if (rxq->init_state != SFXGE_RXQ_STARTED)
return;
@ -749,7 +749,7 @@ sfxge_rx_qcomplete(struct sfxge_rxq *rxq, boolean_t eop)
index = rxq->index;
evq = sc->evq[index];
mtx_assert(&evq->lock, MA_OWNED);
SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
completed = rxq->completed;
while (completed != rxq->pending) {
@ -834,7 +834,7 @@ sfxge_rx_qstop(struct sfxge_softc *sc, unsigned int index)
rxq = sc->rxq[index];
evq = sc->evq[index];
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
KASSERT(rxq->init_state == SFXGE_RXQ_STARTED,
("rxq not started"));
@ -849,7 +849,7 @@ again:
/* Flush the receive queue */
efx_rx_qflush(rxq->common);
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
count = 0;
do {
@ -861,7 +861,7 @@ again:
} while (++count < 20);
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
if (rxq->flush_state == SFXGE_FLUSH_FAILED)
goto again;
@ -885,7 +885,7 @@ again:
efx_sram_buf_tbl_clear(sc->enp, rxq->buf_base_id,
EFX_RXQ_NBUFS(sc->rxq_entries));
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
}
static int
@ -916,7 +916,7 @@ sfxge_rx_qstart(struct sfxge_softc *sc, unsigned int index)
&rxq->common)) != 0)
goto fail;
mtx_lock(&evq->lock);
SFXGE_EVQ_LOCK(evq);
/* Enable the receive queue. */
efx_rx_qenable(rxq->common);
@ -926,7 +926,7 @@ sfxge_rx_qstart(struct sfxge_softc *sc, unsigned int index)
/* Try to fill the queue from the pool. */
sfxge_rx_qfill(rxq, EFX_RXQ_LIMIT(sc->rxq_entries), B_FALSE);
mtx_unlock(&evq->lock);
SFXGE_EVQ_UNLOCK(evq);
return (0);

View File

@ -118,7 +118,7 @@ sfxge_tx_qcomplete(struct sfxge_txq *txq, struct sfxge_evq *evq)
{
unsigned int completed;
mtx_assert(&evq->lock, MA_OWNED);
SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
completed = txq->completed;
while (completed != txq->pending) {
@ -178,7 +178,7 @@ sfxge_tx_qdpl_swizzle(struct sfxge_txq *txq)
unsigned int count;
unsigned int non_tcp_count;
mtx_assert(&txq->lock, MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
stdp = &txq->dpl;
@ -221,7 +221,7 @@ sfxge_tx_qdpl_swizzle(struct sfxge_txq *txq)
static void
sfxge_tx_qreap(struct sfxge_txq *txq)
{
mtx_assert(SFXGE_TXQ_LOCK(txq), MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
txq->reaped = txq->completed;
}
@ -233,7 +233,7 @@ sfxge_tx_qlist_post(struct sfxge_txq *txq)
unsigned int level;
int rc;
mtx_assert(SFXGE_TXQ_LOCK(txq), MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
KASSERT(txq->n_pend_desc != 0, ("txq->n_pend_desc == 0"));
KASSERT(txq->n_pend_desc <= SFXGE_TSO_MAX_DESC,
@ -408,7 +408,7 @@ sfxge_tx_qdpl_drain(struct sfxge_txq *txq)
unsigned int pushed;
int rc;
mtx_assert(&txq->lock, MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
sc = txq->sc;
stdp = &txq->dpl;
@ -484,7 +484,7 @@ sfxge_tx_qdpl_drain(struct sfxge_txq *txq)
static inline void
sfxge_tx_qdpl_service(struct sfxge_txq *txq)
{
mtx_assert(&txq->lock, MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
do {
if (SFXGE_TX_QDPL_PENDING(txq))
@ -493,9 +493,9 @@ sfxge_tx_qdpl_service(struct sfxge_txq *txq)
if (!txq->blocked)
sfxge_tx_qdpl_drain(txq);
mtx_unlock(&txq->lock);
SFXGE_TXQ_UNLOCK(txq);
} while (SFXGE_TX_QDPL_PENDING(txq) &&
mtx_trylock(&txq->lock));
SFXGE_TXQ_TRYLOCK(txq));
}
/*
@ -519,7 +519,7 @@ sfxge_tx_qdpl_put(struct sfxge_txq *txq, struct mbuf *mbuf, int locked)
KASSERT(mbuf->m_nextpkt == NULL, ("mbuf->m_nextpkt != NULL"));
if (locked) {
mtx_assert(&txq->lock, MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
sfxge_tx_qdpl_swizzle(txq);
@ -588,11 +588,11 @@ sfxge_tx_packet_add(struct sfxge_txq *txq, struct mbuf *m)
* the packet will be appended to the "get list" of the deferred
* packet list. Otherwise, it will be pushed on the "put list".
*/
locked = mtx_trylock(&txq->lock);
locked = SFXGE_TXQ_TRYLOCK(txq);
if (sfxge_tx_qdpl_put(txq, m, locked) != 0) {
if (locked)
mtx_unlock(&txq->lock);
SFXGE_TXQ_UNLOCK(txq);
rc = ENOBUFS;
goto fail;
}
@ -605,7 +605,7 @@ sfxge_tx_packet_add(struct sfxge_txq *txq, struct mbuf *m)
* is processing the list.
*/
if (!locked)
locked = mtx_trylock(&txq->lock);
locked = SFXGE_TXQ_TRYLOCK(txq);
if (locked) {
/* Try to service the list. */
@ -626,7 +626,7 @@ sfxge_tx_qdpl_flush(struct sfxge_txq *txq)
struct sfxge_tx_dpl *stdp = &txq->dpl;
struct mbuf *mbuf, *next;
mtx_lock(&txq->lock);
SFXGE_TXQ_LOCK(txq);
sfxge_tx_qdpl_swizzle(txq);
for (mbuf = stdp->std_get; mbuf != NULL; mbuf = next) {
@ -638,7 +638,7 @@ sfxge_tx_qdpl_flush(struct sfxge_txq *txq)
stdp->std_get_non_tcp_count = 0;
stdp->std_getp = &stdp->std_get;
mtx_unlock(&txq->lock);
SFXGE_TXQ_UNLOCK(txq);
}
void
@ -753,21 +753,20 @@ void sfxge_if_start(struct ifnet *ifp)
{
struct sfxge_softc *sc = ifp->if_softc;
mtx_lock(&sc->tx_lock);
SFXGE_TXQ_LOCK(sc->txq[0]);
sfxge_if_start_locked(ifp);
mtx_unlock(&sc->tx_lock);
SFXGE_TXQ_UNLOCK(sc->txq[0]);
}
static inline void
sfxge_tx_qdpl_service(struct sfxge_txq *txq)
{
struct sfxge_softc *sc = txq->sc;
struct ifnet *ifp = sc->ifnet;
struct ifnet *ifp = txq->sc->ifnet;
mtx_assert(&sc->tx_lock, MA_OWNED);
SFXGE_TXQ_LOCK_ASSERT_OWNED(txq);
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
sfxge_if_start_locked(ifp);
mtx_unlock(&sc->tx_lock);
SFXGE_TXQ_UNLOCK(txq);
}
#endif /* SFXGE_HAVE_MQ */
@ -1118,12 +1117,12 @@ sfxge_tx_qunblock(struct sfxge_txq *txq)
sc = txq->sc;
evq = sc->evq[txq->evq_index];
mtx_assert(&evq->lock, MA_OWNED);
SFXGE_EVQ_LOCK_ASSERT_OWNED(evq);
if (txq->init_state != SFXGE_TXQ_STARTED)
return;
mtx_lock(SFXGE_TXQ_LOCK(txq));
SFXGE_TXQ_LOCK(txq);
if (txq->blocked) {
unsigned int level;
@ -1154,7 +1153,7 @@ sfxge_tx_qstop(struct sfxge_softc *sc, unsigned int index)
txq = sc->txq[index];
evq = sc->evq[txq->evq_index];
mtx_lock(SFXGE_TXQ_LOCK(txq));
SFXGE_TXQ_LOCK(txq);
KASSERT(txq->init_state == SFXGE_TXQ_STARTED,
("txq->init_state != SFXGE_TXQ_STARTED"));
@ -1165,7 +1164,7 @@ sfxge_tx_qstop(struct sfxge_softc *sc, unsigned int index)
/* Flush the transmit queue. */
efx_tx_qflush(txq->common);
mtx_unlock(SFXGE_TXQ_LOCK(txq));
SFXGE_TXQ_UNLOCK(txq);
count = 0;
do {
@ -1176,8 +1175,8 @@ sfxge_tx_qstop(struct sfxge_softc *sc, unsigned int index)
break;
} while (++count < 20);
mtx_lock(&evq->lock);
mtx_lock(SFXGE_TXQ_LOCK(txq));
SFXGE_EVQ_LOCK(evq);
SFXGE_TXQ_LOCK(txq);
KASSERT(txq->flush_state != SFXGE_FLUSH_FAILED,
("txq->flush_state == SFXGE_FLUSH_FAILED"));
@ -1207,8 +1206,8 @@ sfxge_tx_qstop(struct sfxge_softc *sc, unsigned int index)
efx_sram_buf_tbl_clear(sc->enp, txq->buf_base_id,
EFX_TXQ_NBUFS(sc->txq_entries));
mtx_unlock(&evq->lock);
mtx_unlock(SFXGE_TXQ_LOCK(txq));
SFXGE_EVQ_UNLOCK(evq);
SFXGE_TXQ_UNLOCK(txq);
}
static int
@ -1257,14 +1256,14 @@ sfxge_tx_qstart(struct sfxge_softc *sc, unsigned int index)
&txq->common)) != 0)
goto fail;
mtx_lock(SFXGE_TXQ_LOCK(txq));
SFXGE_TXQ_LOCK(txq);
/* Enable the transmit queue. */
efx_tx_qenable(txq->common);
txq->init_state = SFXGE_TXQ_STARTED;
mtx_unlock(SFXGE_TXQ_LOCK(txq));
SFXGE_TXQ_UNLOCK(txq);
return (0);
@ -1362,7 +1361,7 @@ sfxge_tx_qfini(struct sfxge_softc *sc, unsigned int index)
sc->txq[index] = NULL;
#ifdef SFXGE_HAVE_MQ
mtx_destroy(&txq->lock);
SFXGE_TXQ_LOCK_DESTROY(txq);
#endif
free(txq, M_SFXGE);
@ -1468,7 +1467,7 @@ sfxge_tx_qinit(struct sfxge_softc *sc, unsigned int txq_index,
stdp->std_get_non_tcp_max = sfxge_tx_dpl_get_non_tcp_max;
stdp->std_getp = &stdp->std_get;
mtx_init(&txq->lock, "txq", NULL, MTX_DEF);
SFXGE_TXQ_LOCK_INIT(txq, "txq");
SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev),
SYSCTL_CHILDREN(txq_node), OID_AUTO,

View File

@ -123,13 +123,27 @@ enum sfxge_txq_type {
#define SFXGE_TX_BATCH 64
#ifdef SFXGE_HAVE_MQ
#define SFXGE_TXQ_LOCK(txq) (&(txq)->lock)
#define SFXGE_TX_LOCK(txq) (&(txq)->lock)
#define SFXGE_TX_SCALE(sc) ((sc)->intr.n_alloc)
#else
#define SFXGE_TXQ_LOCK(txq) (&(txq)->sc->tx_lock)
#define SFXGE_TX_LOCK(txq) (&(txq)->sc->tx_lock)
#define SFXGE_TX_SCALE(sc) 1
#endif
#define SFXGE_TXQ_LOCK_INIT(_txq, _name) \
mtx_init(&(_txq)->lock, (_name), NULL, MTX_DEF)
#define SFXGE_TXQ_LOCK_DESTROY(_txq) \
mtx_destroy(&(_txq)->lock)
#define SFXGE_TXQ_LOCK(_txq) \
mtx_lock(SFXGE_TX_LOCK(_txq))
#define SFXGE_TXQ_TRYLOCK(_txq) \
mtx_trylock(SFXGE_TX_LOCK(_txq))
#define SFXGE_TXQ_UNLOCK(_txq) \
mtx_unlock(SFXGE_TX_LOCK(_txq))
#define SFXGE_TXQ_LOCK_ASSERT_OWNED(_txq) \
mtx_assert(SFXGE_TX_LOCK(_txq), MA_OWNED)
struct sfxge_txq {
/* The following fields should be written very rarely */
struct sfxge_softc *sc;