Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Simplify the code.
details: https://anonhg.NetBSD.org/src/rev/ca38396bbdfa
branches: trunk
changeset: 816037:ca38396bbdfa
user: skrll <skrll%NetBSD.org@localhost>
date: Tue Jun 14 09:07:22 2016 +0000
description:
Simplify the code.
WM_[RT]X_* macros are removed and replaced with mutex_* calls directly.
OK from nakahara@ and msaitoh@
diffstat:
sys/dev/pci/if_wm.c | 128 ++++++++++++++++++++-------------------------------
1 files changed, 51 insertions(+), 77 deletions(-)
diffs (truncated from 421 to 300 lines):
diff -r df0213d9afbb -r ca38396bbdfa sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c Tue Jun 14 07:51:10 2016 +0000
+++ b/sys/dev/pci/if_wm.c Tue Jun 14 09:07:22 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_wm.c,v 1.412 2016/06/10 13:27:14 ozaki-r Exp $ */
+/* $NetBSD: if_wm.c,v 1.413 2016/06/14 09:07:22 skrll Exp $ */
/*
* Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -85,7 +85,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.412 2016/06/10 13:27:14 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.413 2016/06/14 09:07:22 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -470,13 +470,6 @@
struct if_percpuq *sc_ipq; /* softint-based input queues */
};
-#define WM_TX_LOCK(_txq) if ((_txq)->txq_lock) mutex_enter((_txq)->txq_lock)
-#define WM_TX_TRYLOCK(_txq) ((_txq)->txq_lock == NULL || mutex_tryenter((_txq)->txq_lock))
-#define WM_TX_UNLOCK(_txq) if ((_txq)->txq_lock) mutex_exit((_txq)->txq_lock)
-#define WM_TX_LOCKED(_txq) (!(_txq)->txq_lock || mutex_owned((_txq)->txq_lock))
-#define WM_RX_LOCK(_rxq) if ((_rxq)->rxq_lock) mutex_enter((_rxq)->rxq_lock)
-#define WM_RX_UNLOCK(_rxq) if ((_rxq)->rxq_lock) mutex_exit((_rxq)->rxq_lock)
-#define WM_RX_LOCKED(_rxq) (!(_rxq)->rxq_lock || mutex_owned((_rxq)->rxq_lock))
#define WM_CORE_LOCK(_sc) if ((_sc)->sc_core_lock) mutex_enter((_sc)->sc_core_lock)
#define WM_CORE_UNLOCK(_sc) if ((_sc)->sc_core_lock) mutex_exit((_sc)->sc_core_lock)
#define WM_CORE_LOCKED(_sc) (!(_sc)->sc_core_lock || mutex_owned((_sc)->sc_core_lock))
@@ -2603,23 +2596,13 @@
struct wm_softc *sc = device_private(self);
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
int i;
-#ifndef WM_MPSAFE
- int s;
-#endif
if ((sc->sc_flags & WM_F_ATTACHED) == 0)
return 0;
-#ifndef WM_MPSAFE
- s = splnet();
-#endif
/* Stop the interface. Callouts are stopped in it. */
wm_stop(ifp, 1);
-#ifndef WM_MPSAFE
- splx(s);
-#endif
-
pmf_device_deregister(self);
/* Tell the firmware about the release */
@@ -2640,9 +2623,9 @@
/* Unload RX dmamaps and free mbufs */
for (i = 0; i < sc->sc_nqueues; i++) {
struct wm_rxqueue *rxq = &sc->sc_queue[i].wmq_rxq;
- WM_RX_LOCK(rxq);
+ mutex_enter(rxq->rxq_lock);
wm_rxdrain(rxq);
- WM_RX_UNLOCK(rxq);
+ mutex_exit(rxq->rxq_lock);
}
/* Must unlock here */
@@ -2738,9 +2721,9 @@
* Since we're using delayed interrupts, sweep up
* before we report an error.
*/
- WM_TX_LOCK(txq);
+ mutex_enter(txq->txq_lock);
wm_txeof(sc, txq);
- WM_TX_UNLOCK(txq);
+ mutex_exit(txq->txq_lock);
if (txq->txq_free != WM_NTXDESC(txq)) {
#ifdef WM_DEBUG
@@ -2785,9 +2768,7 @@
struct wm_softc *sc = arg;
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
#ifndef WM_MPSAFE
- int s;
-
- s = splnet();
+ int s = splnet();
#endif
WM_CORE_LOCK(sc);
@@ -4081,7 +4062,7 @@
struct mbuf *m;
int error;
- KASSERT(WM_RX_LOCKED(rxq));
+ KASSERT(mutex_owned(rxq->rxq_lock));
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
@@ -4133,7 +4114,7 @@
struct wm_rxsoft *rxs;
int i;
- KASSERT(WM_RX_LOCKED(rxq));
+ KASSERT(mutex_owned(rxq->rxq_lock));
for (i = 0; i < WM_NRXDESC; i++) {
rxs = &rxq->rxq_soft[i];
@@ -5011,9 +4992,9 @@
for (qidx = 0; qidx < sc->sc_nqueues; qidx++) {
struct wm_rxqueue *rxq = &sc->sc_queue[qidx].wmq_rxq;
for (i = 0; i < WM_NRXDESC; i++) {
- WM_RX_LOCK(rxq);
+ mutex_enter(rxq->rxq_lock);
wm_init_rxdesc(rxq, i);
- WM_RX_UNLOCK(rxq);
+ mutex_exit(rxq->rxq_lock);
}
}
@@ -5106,7 +5087,7 @@
for (qidx = 0; qidx < sc->sc_nqueues; qidx++) {
struct wm_queue *wmq = &sc->sc_queue[qidx];
struct wm_txqueue *txq = &wmq->wmq_txq;
- WM_TX_LOCK(txq);
+ mutex_enter(txq->txq_lock);
for (i = 0; i < WM_TXQUEUELEN(txq); i++) {
txs = &txq->txq_soft[i];
if (txs->txs_mbuf != NULL) {
@@ -5158,7 +5139,7 @@
printf("XXX need RX flush\n");
}
}
- WM_TX_UNLOCK(txq);
+ mutex_exit(txq->txq_lock);
}
/* Mark the interface as down and cancel the watchdog timer. */
@@ -5168,9 +5149,9 @@
if (disable) {
for (i = 0; i < sc->sc_nqueues; i++) {
struct wm_rxqueue *rxq = &sc->sc_queue[i].wmq_rxq;
- WM_RX_LOCK(rxq);
+ mutex_enter(rxq->rxq_lock);
wm_rxdrain(rxq);
- WM_RX_UNLOCK(rxq);
+ mutex_exit(rxq->rxq_lock);
}
}
@@ -5206,12 +5187,8 @@
{
struct wm_softc *sc = arg;
struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq;
-#ifndef WM_MPSAFE
- int s;
-
- s = splnet();
-#endif
- WM_TX_LOCK(txq);
+
+ mutex_enter(txq->txq_lock);
if (sc->sc_stopping)
goto out;
@@ -5247,10 +5224,7 @@
}
out:
- WM_TX_UNLOCK(txq);
-#ifndef WM_MPSAFE
- splx(s);
-#endif
+ mutex_exit(txq->txq_lock);
}
/*
@@ -5666,7 +5640,7 @@
wm_init_tx_descs(struct wm_softc *sc __unused, struct wm_txqueue *txq)
{
- KASSERT(WM_TX_LOCKED(txq));
+ KASSERT(mutex_owned(txq->txq_lock));
/* Initialize the transmit descriptor ring. */
memset(txq->txq_descs, 0, WM_TXDESCS_SIZE(txq));
@@ -5681,7 +5655,7 @@
struct wm_txqueue *txq)
{
- KASSERT(WM_TX_LOCKED(txq));
+ KASSERT(mutex_owned(txq->txq_lock));
if (sc->sc_type < WM_T_82543) {
CSR_WRITE(sc, WMREG_OLD_TDBAH, WM_CDTXADDR_HI(txq, 0));
@@ -5726,7 +5700,7 @@
{
int i;
- KASSERT(WM_TX_LOCKED(txq));
+ KASSERT(mutex_owned(txq->txq_lock));
/* Initialize the transmit job descriptors. */
for (i = 0; i < WM_TXQUEUELEN(txq); i++)
@@ -5741,7 +5715,7 @@
struct wm_txqueue *txq)
{
- KASSERT(WM_TX_LOCKED(txq));
+ KASSERT(mutex_owned(txq->txq_lock));
/*
* Set up some register offsets that are different between
@@ -5762,7 +5736,7 @@
struct wm_rxqueue *rxq)
{
- KASSERT(WM_RX_LOCKED(rxq));
+ KASSERT(mutex_owned(rxq->rxq_lock));
/*
* Initialize the receive descriptor and receive job
@@ -5819,7 +5793,7 @@
struct wm_rxsoft *rxs;
int error, i;
- KASSERT(WM_RX_LOCKED(rxq));
+ KASSERT(mutex_owned(rxq->rxq_lock));
for (i = 0; i < WM_NRXDESC; i++) {
rxs = &rxq->rxq_soft[i];
@@ -5857,7 +5831,7 @@
struct wm_rxqueue *rxq)
{
- KASSERT(WM_RX_LOCKED(rxq));
+ KASSERT(mutex_owned(rxq->rxq_lock));
/*
* Set up some register offsets that are different between
@@ -5888,13 +5862,13 @@
struct wm_txqueue *txq = &wmq->wmq_txq;
struct wm_rxqueue *rxq = &wmq->wmq_rxq;
- WM_TX_LOCK(txq);
+ mutex_enter(txq->txq_lock);
wm_init_tx_queue(sc, wmq, txq);
- WM_TX_UNLOCK(txq);
-
- WM_RX_LOCK(rxq);
+ mutex_exit(txq->txq_lock);
+
+ mutex_enter(rxq->rxq_lock);
error = wm_init_rx_queue(sc, wmq, rxq);
- WM_RX_UNLOCK(rxq);
+ mutex_exit(rxq->rxq_lock);
if (error)
break;
}
@@ -6109,10 +6083,10 @@
struct wm_softc *sc = ifp->if_softc;
struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq;
- WM_TX_LOCK(txq);
+ mutex_enter(txq->txq_lock);
if (!sc->sc_stopping)
wm_start_locked(ifp);
- WM_TX_UNLOCK(txq);
+ mutex_exit(txq->txq_lock);
}
static void
@@ -6130,7 +6104,7 @@
uint32_t cksumcmd;
uint8_t cksumfields;
- KASSERT(WM_TX_LOCKED(txq));
+ KASSERT(mutex_owned(txq->txq_lock));
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
return;
@@ -6626,10 +6600,10 @@
struct wm_softc *sc = ifp->if_softc;
struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq;
- WM_TX_LOCK(txq);
+ mutex_enter(txq->txq_lock);
if (!sc->sc_stopping)
wm_nq_start_locked(ifp);
- WM_TX_UNLOCK(txq);
+ mutex_exit(txq->txq_lock);
}
static void
@@ -6671,7 +6645,7 @@
return ENOBUFS;
}
- if (WM_TX_TRYLOCK(txq)) {
Home |
Main Index |
Thread Index |
Old Index