summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>2000-10-13 17:54:19 +0000
committerwpaul <wpaul@FreeBSD.org>2000-10-13 17:54:19 +0000
commit16ec4a91f179c9d047fe1cb7b7d68c657df986fc (patch)
treed2b24965fff6ef4ede33dd73cdf088620792bc7e /sys/dev
parent79bb6ec5ea6aacb1b51654255a46244dd3193676 (diff)
downloadFreeBSD-src-16ec4a91f179c9d047fe1cb7b7d68c657df986fc.zip
FreeBSD-src-16ec4a91f179c9d047fe1cb7b7d68c657df986fc.tar.gz
First round of converting network drivers from spls to mutexes. This
takes care of all the 10/100 and gigE PCI drivers that I've done. Next will be the wireless drivers, then the USB ones. I may pick up some stragglers along the way. I'm sort of playing this by ear: if anyone spots any places where I've screwed up horribly, please let me know.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/dc/if_dc.c80
-rw-r--r--sys/dev/dc/if_dcreg.h5
-rw-r--r--sys/dev/sf/if_sf.c70
-rw-r--r--sys/dev/sf/if_sfreg.h5
-rw-r--r--sys/dev/sk/if_sk.c74
-rw-r--r--sys/dev/sk/if_skreg.h6
-rw-r--r--sys/dev/ti/if_ti.c49
-rw-r--r--sys/dev/ti/if_tireg.h4
-rw-r--r--sys/dev/vr/if_vr.c74
-rw-r--r--sys/dev/vr/if_vrreg.h4
10 files changed, 246 insertions, 125 deletions
diff --git a/sys/dev/dc/if_dc.c b/sys/dev/dc/if_dc.c
index 695b019..f7c97a1 100644
--- a/sys/dev/dc/if_dc.c
+++ b/sys/dev/dc/if_dc.c
@@ -109,6 +109,7 @@
#include <machine/bus_memio.h>
#include <machine/bus.h>
#include <machine/resource.h>
+#include <machine/mutex.h>
#include <sys/bus.h>
#include <sys/rman.h>
@@ -555,9 +556,9 @@ static int dc_mii_readreg(sc, frame)
struct dc_mii_frame *frame;
{
- int i, ack, s;
+ int i, ack;
- s = splimp();
+ DC_LOCK(sc);
/*
* Set up frame for RX.
@@ -612,7 +613,7 @@ fail:
dc_mii_writebit(sc, 0);
dc_mii_writebit(sc, 0);
- splx(s);
+ DC_UNLOCK(sc);
if (ack)
return(1);
@@ -627,9 +628,7 @@ static int dc_mii_writereg(sc, frame)
struct dc_mii_frame *frame;
{
- int s;
-
- s = splimp();
+ DC_LOCK(sc);
/*
* Set up frame for TX.
*/
@@ -654,7 +653,7 @@ static int dc_mii_writereg(sc, frame)
dc_mii_writebit(sc, 0);
dc_mii_writebit(sc, 0);
- splx(s);
+ DC_UNLOCK(sc);
return(0);
}
@@ -1626,7 +1625,7 @@ static void dc_parse_21143_srom(sc)
static int dc_attach(dev)
device_t dev;
{
- int s, tmp = 0;
+ int tmp = 0;
u_char eaddr[ETHER_ADDR_LEN];
u_int32_t command;
struct dc_softc *sc;
@@ -1634,8 +1633,6 @@ static int dc_attach(dev)
u_int32_t revision;
int unit, error = 0, rid, mac_offset;
- s = splimp();
-
sc = device_get_softc(dev);
unit = device_get_unit(dev);
bzero(sc, sizeof(struct dc_softc));
@@ -1701,7 +1698,9 @@ static int dc_attach(dev)
printf("dc%d: couldn't set up irq\n", unit);
goto fail;
}
-
+
+ mtx_init(&sc->dc_mtx, "dc", MTX_DEF);
+ DC_LOCK(sc);
/* Need this info to decide on a chip type. */
sc->dc_info = dc_devtype(dev);
revision = pci_read_config(dev, DC_PCI_CFRV, 4) & 0x000000FF;
@@ -1966,10 +1965,12 @@ static int dc_attach(dev)
}
#endif
+ DC_UNLOCK(sc);
+ return(0);
fail:
- splx(s);
-
+ DC_UNLOCK(sc);
+ mtx_destroy(&sc->dc_mtx);
return(error);
}
@@ -1978,12 +1979,12 @@ static int dc_detach(dev)
{
struct dc_softc *sc;
struct ifnet *ifp;
- int s;
struct dc_mediainfo *m;
- s = splimp();
-
sc = device_get_softc(dev);
+
+ DC_LOCK(sc);
+
ifp = &sc->arpcom.ac_if;
dc_stop(sc);
@@ -2006,7 +2007,8 @@ static int dc_detach(dev)
sc->dc_mi = m;
}
- splx(s);
+ DC_UNLOCK(sc);
+ mtx_destroy(&sc->dc_mtx);
return(0);
}
@@ -2457,12 +2459,10 @@ static void dc_tick(xsc)
struct dc_softc *sc;
struct mii_data *mii;
struct ifnet *ifp;
- int s;
u_int32_t r;
- s = splimp();
-
sc = xsc;
+ DC_LOCK(sc);
ifp = &sc->arpcom.ac_if;
mii = device_get_softc(sc->dc_miibus);
@@ -2526,7 +2526,7 @@ static void dc_tick(xsc)
else
sc->dc_stat_ch = timeout(dc_tick, sc, hz);
- splx(s);
+ DC_UNLOCK(sc);
return;
}
@@ -2539,12 +2539,14 @@ static void dc_intr(arg)
u_int32_t status;
sc = arg;
+ DC_LOCK(sc);
ifp = &sc->arpcom.ac_if;
/* Supress unwanted interrupts */
if (!(ifp->if_flags & IFF_UP)) {
if (CSR_READ_4(sc, DC_ISR) & DC_INTRS)
dc_stop(sc);
+ DC_UNLOCK(sc);
return;
}
@@ -2621,6 +2623,8 @@ static void dc_intr(arg)
if (ifp->if_snd.ifq_head != NULL)
dc_start(ifp);
+ DC_UNLOCK(sc);
+
return;
}
@@ -2737,11 +2741,17 @@ static void dc_start(ifp)
sc = ifp->if_softc;
- if (!sc->dc_link)
+ DC_LOCK(sc);
+
+ if (!sc->dc_link) {
+ DC_UNLOCK(sc);
return;
+ }
- if (ifp->if_flags & IFF_OACTIVE)
+ if (ifp->if_flags & IFF_OACTIVE) {
+ DC_UNLOCK(sc);
return;
+ }
idx = sc->dc_cdata.dc_tx_prod;
@@ -2787,6 +2797,8 @@ static void dc_start(ifp)
*/
ifp->if_timer = 5;
+ DC_UNLOCK(sc);
+
return;
}
@@ -2796,9 +2808,8 @@ static void dc_init(xsc)
struct dc_softc *sc = xsc;
struct ifnet *ifp = &sc->arpcom.ac_if;
struct mii_data *mii;
- int s;
- s = splimp();
+ DC_LOCK(sc);
mii = device_get_softc(sc->dc_miibus);
@@ -2876,7 +2887,7 @@ static void dc_init(xsc)
printf("dc%d: initialization failed: no "
"memory for rx buffers\n", sc->dc_unit);
dc_stop(sc);
- (void)splx(s);
+ DC_UNLOCK(sc);
return;
}
@@ -2929,8 +2940,6 @@ static void dc_init(xsc)
ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE;
- (void)splx(s);
-
/* Don't start the ticker if this is a homePNA link. */
if (IFM_SUBTYPE(mii->mii_media.ifm_media) == IFM_homePNA)
sc->dc_link = 1;
@@ -2950,6 +2959,7 @@ static void dc_init(xsc)
sc->dc_srm_media = 0;
}
#endif
+ DC_UNLOCK(sc);
return;
}
@@ -3013,9 +3023,9 @@ static int dc_ioctl(ifp, command, data)
struct dc_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *) data;
struct mii_data *mii;
- int s, error = 0;
+ int error = 0;
- s = splimp();
+ DC_LOCK(sc);
switch(command) {
case SIOCSIFADDR:
@@ -3063,7 +3073,7 @@ static int dc_ioctl(ifp, command, data)
break;
}
- (void)splx(s);
+ DC_UNLOCK(sc);
return(error);
}
@@ -3075,6 +3085,8 @@ static void dc_watchdog(ifp)
sc = ifp->if_softc;
+ DC_LOCK(sc);
+
ifp->if_oerrors++;
printf("dc%d: watchdog timeout\n", sc->dc_unit);
@@ -3085,6 +3097,8 @@ static void dc_watchdog(ifp)
if (ifp->if_snd.ifq_head != NULL)
dc_start(ifp);
+ DC_UNLOCK(sc);
+
return;
}
@@ -3098,6 +3112,8 @@ static void dc_stop(sc)
register int i;
struct ifnet *ifp;
+ DC_LOCK(sc);
+
ifp = &sc->arpcom.ac_if;
ifp->if_timer = 0;
@@ -3141,6 +3157,8 @@ static void dc_stop(sc)
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+ DC_UNLOCK(sc);
+
return;
}
diff --git a/sys/dev/dc/if_dcreg.h b/sys/dev/dc/if_dcreg.h
index 9c6cfc4..e72d8b4 100644
--- a/sys/dev/dc/if_dcreg.h
+++ b/sys/dev/dc/if_dcreg.h
@@ -676,8 +676,13 @@ struct dc_softc {
#ifdef SRM_MEDIA
int dc_srm_media;
#endif
+ struct mtx dc_mtx;
};
+
+#define DC_LOCK(_sc) mtx_enter(&(_sc)->dc_mtx, MTX_DEF)
+#define DC_UNLOCK(_sc) mtx_exit(&(_sc)->dc_mtx, MTX_DEF)
+
#define DC_TX_POLL 0x00000001
#define DC_TX_COALESCE 0x00000002
#define DC_TX_ADMTEK_WAR 0x00000004
diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c
index 52c6f88..a7d14522 100644
--- a/sys/dev/sf/if_sf.c
+++ b/sys/dev/sf/if_sf.c
@@ -531,9 +531,9 @@ static int sf_ioctl(ifp, command, data)
struct sf_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *) data;
struct mii_data *mii;
- int s, error = 0;
+ int error = 0;
- s = splimp();
+ SF_LOCK(sc);
switch(command) {
case SIOCSIFADDR:
@@ -575,7 +575,7 @@ static int sf_ioctl(ifp, command, data)
break;
}
- (void)splx(s);
+ SF_UNLOCK(sc);
return(error);
}
@@ -670,14 +670,12 @@ static int sf_probe(dev)
static int sf_attach(dev)
device_t dev;
{
- int s, i;
+ int i;
u_int32_t command;
struct sf_softc *sc;
struct ifnet *ifp;
int unit, rid, error = 0;
- s = splimp();
-
sc = device_get_softc(dev);
unit = device_get_unit(dev);
bzero(sc, sizeof(struct sf_softc));
@@ -768,7 +766,8 @@ static int sf_attach(dev)
}
callout_handle_init(&sc->sf_stat_ch);
-
+ mtx_init(&sc->sf_mtx, "sf", MTX_DEF);
+ SF_LOCK(sc);
/* Reset the adapter. */
sf_reset(sc);
@@ -832,9 +831,12 @@ static int sf_attach(dev)
* Call MI attach routine.
*/
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
+ SF_UNLOCK(sc);
+ return(0);
fail:
- splx(s);
+ SF_UNLOCK(sc);
+ mtx_destroy(&sc->sf_mtx);
return(error);
}
@@ -843,11 +845,9 @@ static int sf_detach(dev)
{
struct sf_softc *sc;
struct ifnet *ifp;
- int s;
-
- s = splimp();
sc = device_get_softc(dev);
+ SF_LOCK(sc);
ifp = &sc->arpcom.ac_if;
ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
@@ -862,7 +862,8 @@ static int sf_detach(dev)
contigfree(sc->sf_ldata, sizeof(struct sf_list_data), M_DEVBUF);
- splx(s);
+ SF_UNLOCK(sc);
+ mtx_destroy(&sc->sf_mtx);
return(0);
}
@@ -1086,10 +1087,14 @@ static void sf_intr(arg)
u_int32_t status;
sc = arg;
+ SF_LOCK(sc);
+
ifp = &sc->arpcom.ac_if;
- if (!(csr_read_4(sc, SF_ISR_SHADOW) & SF_ISR_PCIINT_ASSERTED))
+ if (!(csr_read_4(sc, SF_ISR_SHADOW) & SF_ISR_PCIINT_ASSERTED)) {
+ SF_UNLOCK(sc);
return;
+ }
/* Disable interrupts. */
csr_write_4(sc, SF_IMR, 0x00000000);
@@ -1124,6 +1129,7 @@ static void sf_intr(arg)
if (ifp->if_snd.ifq_head != NULL)
sf_start(ifp);
+ SF_UNLOCK(sc);
return;
}
@@ -1133,11 +1139,10 @@ static void sf_init(xsc)
struct sf_softc *sc;
struct ifnet *ifp;
struct mii_data *mii;
- int i, s;
-
- s = splimp();
+ int i;
sc = xsc;
+ SF_LOCK(sc);
ifp = &sc->arpcom.ac_if;
mii = device_get_softc(sc->sf_miibus);
@@ -1162,7 +1167,7 @@ static void sf_init(xsc)
if (sf_init_rx_ring(sc) == ENOBUFS) {
printf("sf%d: initialization failed: no "
"memory for rx buffers\n", sc->sf_unit);
- (void)splx(s);
+ SF_UNLOCK(sc);
return;
}
@@ -1237,7 +1242,7 @@ static void sf_init(xsc)
sc->sf_stat_ch = timeout(sf_stats_update, sc, hz);
- splx(s);
+ SF_UNLOCK(sc);
return;
}
@@ -1314,12 +1319,17 @@ static void sf_start(ifp)
int i, txprod;
sc = ifp->if_softc;
+ SF_LOCK(sc);
- if (!sc->sf_link)
+ if (!sc->sf_link) {
+ SF_UNLOCK(sc);
return;
+ }
- if (ifp->if_flags & IFF_OACTIVE)
+ if (ifp->if_flags & IFF_OACTIVE) {
+ SF_UNLOCK(sc);
return;
+ }
txprod = csr_read_4(sc, SF_TXDQ_PRODIDX);
i = SF_IDX_HI(txprod) >> 4;
@@ -1345,8 +1355,10 @@ static void sf_start(ifp)
break;
}
- if (cur_tx == NULL)
+ if (cur_tx == NULL) {
+ SF_UNLOCK(sc);
return;
+ }
/* Transmit */
csr_write_4(sc, SF_TXDQ_PRODIDX,
@@ -1355,6 +1367,8 @@ static void sf_start(ifp)
ifp->if_timer = 5;
+ SF_UNLOCK(sc);
+
return;
}
@@ -1364,6 +1378,8 @@ static void sf_stop(sc)
int i;
struct ifnet *ifp;
+ SF_LOCK(sc);
+
ifp = &sc->arpcom.ac_if;
untimeout(sf_stats_update, sc, sc->sf_stat_ch);
@@ -1396,6 +1412,7 @@ static void sf_stop(sc)
}
ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
+ SF_UNLOCK(sc);
return;
}
@@ -1415,11 +1432,10 @@ static void sf_stats_update(xsc)
struct mii_data *mii;
struct sf_stats stats;
u_int32_t *ptr;
- int i, s;
-
- s = splimp();
+ int i;
sc = xsc;
+ SF_LOCK(sc);
ifp = &sc->arpcom.ac_if;
mii = device_get_softc(sc->sf_miibus);
@@ -1447,7 +1463,7 @@ static void sf_stats_update(xsc)
sc->sf_stat_ch = timeout(sf_stats_update, sc, hz);
- splx(s);
+ SF_UNLOCK(sc);
return;
}
@@ -1459,6 +1475,8 @@ static void sf_watchdog(ifp)
sc = ifp->if_softc;
+ SF_LOCK(sc);
+
ifp->if_oerrors++;
printf("sf%d: watchdog timeout\n", sc->sf_unit);
@@ -1469,6 +1487,8 @@ static void sf_watchdog(ifp)
if (ifp->if_snd.ifq_head != NULL)
sf_start(ifp);
+ SF_UNLOCK(sc);
+
return;
}
diff --git a/sys/dev/sf/if_sfreg.h b/sys/dev/sf/if_sfreg.h
index 49fdd5a..c2dc20e 100644
--- a/sys/dev/sf/if_sfreg.h
+++ b/sys/dev/sf/if_sfreg.h
@@ -1044,8 +1044,13 @@ struct sf_softc {
u_int8_t sf_link;
int sf_if_flags;
struct callout_handle sf_stat_ch;
+ struct mtx sf_mtx;
};
+
+#define SF_LOCK(_sc) mtx_enter(&(_sc)->sf_mtx, MTX_DEF)
+#define SF_UNLOCK(_sc) mtx_exit(&(_sc)->sf_mtx, MTX_DEF)
+
#define SF_TIMEOUT 1000
#ifdef __alpha__
diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c
index a83a606..963f754 100644
--- a/sys/dev/sk/if_sk.c
+++ b/sys/dev/sk/if_sk.c
@@ -413,6 +413,8 @@ static int sk_miibus_readreg(dev, phy, reg)
if (sc_if->sk_phytype == SK_PHYTYPE_XMAC && phy != 0)
return(0);
+ SK_IF_LOCK(sc_if);
+
SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8));
SK_XM_READ_2(sc_if, XM_PHY_DATA);
if (sc_if->sk_phytype != SK_PHYTYPE_XMAC) {
@@ -430,7 +432,9 @@ static int sk_miibus_readreg(dev, phy, reg)
}
}
DELAY(1);
- return(SK_XM_READ_2(sc_if, XM_PHY_DATA));
+ i = SK_XM_READ_2(sc_if, XM_PHY_DATA);
+ SK_IF_UNLOCK(sc_if);
+ return(i);
}
static int sk_miibus_writereg(dev, phy, reg, val)
@@ -441,6 +445,7 @@ static int sk_miibus_writereg(dev, phy, reg, val)
int i;
sc_if = device_get_softc(dev);
+ SK_IF_LOCK(sc_if);
SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8));
for (i = 0; i < SK_TIMEOUT; i++) {
@@ -460,6 +465,8 @@ static int sk_miibus_writereg(dev, phy, reg, val)
break;
}
+ SK_IF_UNLOCK(sc_if);
+
if (i == SK_TIMEOUT)
printf("sk%d: phy write timed out\n", sc_if->sk_unit);
@@ -474,7 +481,7 @@ static void sk_miibus_statchg(dev)
sc_if = device_get_softc(dev);
mii = device_get_softc(sc_if->sk_miibus);
-
+ SK_IF_LOCK(sc_if);
/*
* If this is a GMII PHY, manually set the XMAC's
* duplex mode accordingly.
@@ -486,6 +493,7 @@ static void sk_miibus_statchg(dev)
SK_XM_CLRBIT_2(sc_if, XM_MMUCMD, XM_MMUCMD_GMIIFDX);
}
}
+ SK_IF_UNLOCK(sc_if);
return;
}
@@ -872,10 +880,10 @@ static int sk_ioctl(ifp, command, data)
{
struct sk_if_softc *sc_if = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *) data;
- int s, error = 0;
+ int error = 0;
struct mii_data *mii;
- s = splimp();
+ SK_IF_LOCK(sc_if);
switch(command) {
case SIOCSIFADDR:
@@ -928,7 +936,7 @@ static int sk_ioctl(ifp, command, data)
break;
}
- (void)splx(s);
+ SK_IF_UNLOCK(sc_if);
return(error);
}
@@ -1025,6 +1033,7 @@ static int sk_attach_xmac(dev)
sc_if = device_get_softc(dev);
sc = device_get_softc(device_get_parent(dev));
+ SK_LOCK(sc);
port = *(int *)device_get_ivars(dev);
free(device_get_ivars(dev), M_DEVBUF);
device_set_ivars(dev, NULL);
@@ -1113,6 +1122,7 @@ static int sk_attach_xmac(dev)
if (sc_if->sk_rdata == NULL) {
printf("sk%d: no memory for list buffers!\n", sc_if->sk_unit);
sc->sk_if[port] = NULL;
+ SK_UNLOCK(sc);
return(ENOMEM);
}
@@ -1125,6 +1135,7 @@ static int sk_attach_xmac(dev)
contigfree(sc_if->sk_rdata,
sizeof(struct sk_ring_data), M_DEVBUF);
sc->sk_if[port] = NULL;
+ SK_UNLOCK(sc);
return(ENOMEM);
}
@@ -1151,6 +1162,7 @@ static int sk_attach_xmac(dev)
printf("skc%d: no PHY found!\n", sc_if->sk_unit);
contigfree(sc_if->sk_rdata,
sizeof(struct sk_ring_data), M_DEVBUF);
+ SK_UNLOCK(sc);
return(ENXIO);
}
@@ -1160,6 +1172,8 @@ static int sk_attach_xmac(dev)
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
callout_handle_init(&sc_if->sk_tick_ch);
+ SK_UNLOCK(sc);
+
return(0);
}
@@ -1170,13 +1184,10 @@ static int sk_attach_xmac(dev)
static int sk_attach(dev)
device_t dev;
{
- int s;
u_int32_t command;
struct sk_softc *sc;
int unit, error = 0, rid, *port;
- s = splimp();
-
sc = device_get_softc(dev);
unit = device_get_unit(dev);
bzero(sc, sizeof(struct sk_softc));
@@ -1266,6 +1277,8 @@ static int sk_attach(dev)
goto fail;
}
+ mtx_init(&sc->sk_mtx, "skc", MTX_DEF);
+ SK_LOCK(sc);
/* Reset the adapter. */
sk_reset(sc);
@@ -1345,9 +1358,12 @@ static int sk_attach(dev)
CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_ON);
bus_generic_attach(dev);
+ SK_UNLOCK(sc);
+ return(0);
fail:
- splx(s);
+ SK_UNLOCK(sc);
+ mtx_destroy(&sc->sk_mtx);
return(error);
}
@@ -1357,12 +1373,11 @@ static int sk_detach_xmac(dev)
struct sk_softc *sc;
struct sk_if_softc *sc_if;
struct ifnet *ifp;
- int s;
-
- s = splimp();
sc = device_get_softc(device_get_parent(dev));
sc_if = device_get_softc(dev);
+ SK_IF_LOCK(sc_if);
+
ifp = &sc_if->arpcom.ac_if;
sk_stop(sc_if);
ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
@@ -1371,6 +1386,7 @@ static int sk_detach_xmac(dev)
device_delete_child(dev, sc_if->sk_miibus);
contigfree(sc_if->sk_cdata.sk_jumbo_buf, SK_JMEM, M_DEVBUF);
contigfree(sc_if->sk_rdata, sizeof(struct sk_ring_data), M_DEVBUF);
+ SK_IF_UNLOCK(sc_if);
return(0);
}
@@ -1379,11 +1395,9 @@ static int sk_detach(dev)
device_t dev;
{
struct sk_softc *sc;
- int s;
-
- s = splimp();
sc = device_get_softc(dev);
+ SK_LOCK(sc);
bus_generic_detach(dev);
if (sc->sk_devs[SK_PORT_A] != NULL)
@@ -1395,7 +1409,8 @@ static int sk_detach(dev)
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sk_irq);
bus_release_resource(dev, SK_RES, SK_RID, sc->sk_res);
- splx(s);
+ SK_UNLOCK(sc);
+ mtx_destroy(&sc->sk_mtx);
return(0);
}
@@ -1460,6 +1475,8 @@ static void sk_start(ifp)
sc_if = ifp->if_softc;
sc = sc_if->sk_softc;
+ SK_IF_LOCK(sc_if);
+
idx = sc_if->sk_cdata.sk_tx_prod;
while(sc_if->sk_cdata.sk_tx_chain[idx].sk_mbuf == NULL) {
@@ -1492,6 +1509,7 @@ static void sk_start(ifp)
/* Set a timeout in case the chip goes out to lunch. */
ifp->if_timer = 5;
+ SK_IF_UNLOCK(sc_if);
return;
}
@@ -1516,6 +1534,7 @@ static void sk_shutdown(dev)
struct sk_softc *sc;
sc = device_get_softc(dev);
+ SK_LOCK(sc);
/* Turn off the 'driver is loaded' LED. */
CSR_WRITE_2(sc, SK_LED, SK_LED_GREEN_OFF);
@@ -1525,6 +1544,7 @@ static void sk_shutdown(dev)
* assert the resets on the attached XMAC(s).
*/
sk_reset(sc);
+ SK_UNLOCK(sc);
return;
}
@@ -1644,14 +1664,18 @@ static void sk_tick(xsc_if)
int i;
sc_if = xsc_if;
+ SK_IF_LOCK(sc_if);
ifp = &sc_if->arpcom.ac_if;
mii = device_get_softc(sc_if->sk_miibus);
- if (!(ifp->if_flags & IFF_UP))
+ if (!(ifp->if_flags & IFF_UP)) {
+ SK_IF_UNLOCK(sc_if);
return;
+ }
if (sc_if->sk_phytype == SK_PHYTYPE_BCOM) {
sk_intr_bcom(sc_if);
+ SK_IF_UNLOCK(sc_if);
return;
}
@@ -1669,6 +1693,7 @@ static void sk_tick(xsc_if)
if (i != 3) {
sc_if->sk_tick_ch = timeout(sk_tick, sc_if, hz);
+ SK_IF_UNLOCK(sc_if);
return;
}
@@ -1679,6 +1704,7 @@ static void sk_tick(xsc_if)
mii_pollstat(mii);
untimeout(sk_tick, sc_if, sc_if->sk_tick_ch);
+ SK_IF_UNLOCK(sc_if);
return;
}
@@ -1785,6 +1811,8 @@ static void sk_intr(xsc)
struct ifnet *ifp0 = NULL, *ifp1 = NULL;
u_int32_t status;
+ SK_LOCK(sc);
+
sc_if0 = sc->sk_if[SK_PORT_A];
sc_if1 = sc->sk_if[SK_PORT_B];
@@ -1846,6 +1874,8 @@ static void sk_intr(xsc)
if (ifp1 != NULL && ifp1->if_snd.ifq_head != NULL)
sk_start(ifp1);
+ SK_UNLOCK(sc);
+
return;
}
@@ -2028,9 +2058,8 @@ static void sk_init(xsc)
struct sk_softc *sc;
struct ifnet *ifp;
struct mii_data *mii;
- int s;
- s = splimp();
+ SK_IF_LOCK(sc_if);
ifp = &sc_if->arpcom.ac_if;
sc = sc_if->sk_softc;
@@ -2100,7 +2129,7 @@ static void sk_init(xsc)
printf("sk%d: initialization failed: no "
"memory for rx buffers\n", sc_if->sk_unit);
sk_stop(sc_if);
- (void)splx(s);
+ SK_IF_UNLOCK(sc_if);
return;
}
sk_init_tx_ring(sc_if);
@@ -2126,7 +2155,7 @@ static void sk_init(xsc)
ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE;
- splx(s);
+ SK_IF_UNLOCK(sc_if);
return;
}
@@ -2138,6 +2167,7 @@ static void sk_stop(sc_if)
struct sk_softc *sc;
struct ifnet *ifp;
+ SK_IF_LOCK(sc_if);
sc = sc_if->sk_softc;
ifp = &sc_if->arpcom.ac_if;
@@ -2198,6 +2228,6 @@ static void sk_stop(sc_if)
}
ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
-
+ SK_IF_UNLOCK(sc_if);
return;
}
diff --git a/sys/dev/sk/if_skreg.h b/sys/dev/sk/if_skreg.h
index 92a26be..6f31d1d 100644
--- a/sys/dev/sk/if_skreg.h
+++ b/sys/dev/sk/if_skreg.h
@@ -1179,8 +1179,14 @@ struct sk_softc {
u_int32_t sk_intrmask;
struct sk_if_softc *sk_if[2];
device_t sk_devs[2];
+ struct mtx sk_mtx;
};
+#define SK_LOCK(_sc) mtx_enter(&(_sc)->sk_mtx, MTX_DEF)
+#define SK_UNLOCK(_sc) mtx_exit(&(_sc)->sk_mtx, MTX_DEF)
+#define SK_IF_LOCK(_sc) mtx_enter(&(_sc)->sk_softc->sk_mtx, MTX_DEF)
+#define SK_IF_UNLOCK(_sc) mtx_exit(&(_sc)->sk_softc->sk_mtx, MTX_DEF)
+
/* Softc for each logical interface */
struct sk_if_softc {
struct arpcom arpcom; /* interface info */
diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c
index f1cfee5..04ec29d 100644
--- a/sys/dev/ti/if_ti.c
+++ b/sys/dev/ti/if_ti.c
@@ -1477,14 +1477,11 @@ static int ti_probe(dev)
static int ti_attach(dev)
device_t dev;
{
- int s;
u_int32_t command;
struct ifnet *ifp;
struct ti_softc *sc;
int unit, error = 0, rid;
- s = splimp();
-
sc = device_get_softc(dev);
unit = device_get_unit(dev);
bzero(sc, sizeof(struct ti_softc));
@@ -1540,6 +1537,9 @@ static int ti_attach(dev)
goto fail;
}
+ mtx_init(&sc->ti_mtx, "ti", MTX_DEF);
+ TI_LOCK(sc);
+
sc->ti_unit = unit;
if (ti_chipinit(sc)) {
@@ -1689,10 +1689,12 @@ static int ti_attach(dev)
* Call MI attach routine.
*/
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
+ TI_UNLOCK(sc);
+ return(0);
fail:
- splx(s);
-
+ TI_UNLOCK(sc);
+ mtx_destroy(&sc->ti_mtx);
return(error);
}
@@ -1701,11 +1703,10 @@ static int ti_detach(dev)
{
struct ti_softc *sc;
struct ifnet *ifp;
- int s;
- s = splimp();
sc = device_get_softc(dev);
+ TI_LOCK(sc);
ifp = &sc->arpcom.ac_if;
ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
@@ -1719,7 +1720,8 @@ static int ti_detach(dev)
contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), M_DEVBUF);
ifmedia_removeall(&sc->ifmedia);
- splx(s);
+ TI_UNLOCK(sc);
+ mtx_destroy(&sc->ti_mtx);
return(0);
}
@@ -1907,13 +1909,16 @@ static void ti_intr(xsc)
struct ifnet *ifp;
sc = xsc;
+ TI_LOCK(sc);
ifp = &sc->arpcom.ac_if;
#ifdef notdef
/* Avoid this for now -- checking this register is expensive. */
/* Make sure this is really our interrupt. */
- if (!(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_INTSTATE))
+ if (!(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_INTSTATE)) {
+ TI_UNLOCK(sc);
return;
+ }
#endif
/* Ack interrupt and stop others from occuring. */
@@ -1935,6 +1940,8 @@ static void ti_intr(xsc)
if (ifp->if_flags & IFF_RUNNING && ifp->if_snd.ifq_head != NULL)
ti_start(ifp);
+ TI_UNLOCK(sc);
+
return;
}
@@ -2069,6 +2076,7 @@ static void ti_start(ifp)
u_int32_t prodidx = 0;
sc = ifp->if_softc;
+ TI_LOCK(sc);
prodidx = CSR_READ_4(sc, TI_MB_SENDPROD_IDX);
@@ -2121,6 +2129,7 @@ static void ti_start(ifp)
* Set a timeout in case the chip goes out to lunch.
*/
ifp->if_timer = 5;
+ TI_UNLOCK(sc);
return;
}
@@ -2129,21 +2138,19 @@ static void ti_init(xsc)
void *xsc;
{
struct ti_softc *sc = xsc;
- int s;
-
- s = splimp();
/* Cancel pending I/O and flush buffers. */
ti_stop(sc);
+ TI_LOCK(sc);
/* Init the gen info block, ring control blocks and firmware. */
if (ti_gibinit(sc)) {
printf("ti%d: initialization failure\n", sc->ti_unit);
- splx(s);
+ TI_UNLOCK(sc);
return;
}
- splx(s);
+ TI_UNLOCK(sc);
return;
}
@@ -2355,10 +2362,10 @@ static int ti_ioctl(ifp, command, data)
{
struct ti_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *) data;
- int s, error = 0;
+ int error = 0;
struct ti_cmd_desc cmd;
- s = splimp();
+ TI_LOCK(sc);
switch(command) {
case SIOCSIFADDR:
@@ -2419,7 +2426,7 @@ static int ti_ioctl(ifp, command, data)
break;
}
- (void)splx(s);
+ TI_UNLOCK(sc);
return(error);
}
@@ -2430,12 +2437,14 @@ static void ti_watchdog(ifp)
struct ti_softc *sc;
sc = ifp->if_softc;
+ TI_LOCK(sc);
printf("ti%d: watchdog timeout -- resetting\n", sc->ti_unit);
ti_stop(sc);
ti_init(sc);
ifp->if_oerrors++;
+ TI_UNLOCK(sc);
return;
}
@@ -2450,6 +2459,8 @@ static void ti_stop(sc)
struct ifnet *ifp;
struct ti_cmd_desc cmd;
+ TI_LOCK(sc);
+
ifp = &sc->arpcom.ac_if;
/* Disable host interrupts. */
@@ -2482,6 +2493,7 @@ static void ti_stop(sc)
sc->ti_tx_saved_considx = TI_TXCONS_UNSET;
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+ TI_UNLOCK(sc);
return;
}
@@ -2496,8 +2508,9 @@ static void ti_shutdown(dev)
struct ti_softc *sc;
sc = device_get_softc(dev);
-
+ TI_LOCK(sc);
ti_chipinit(sc);
+ TI_UNLOCK(sc);
return;
}
diff --git a/sys/dev/ti/if_tireg.h b/sys/dev/ti/if_tireg.h
index 6346c67..d64cc7a 100644
--- a/sys/dev/ti/if_tireg.h
+++ b/sys/dev/ti/if_tireg.h
@@ -1148,8 +1148,12 @@ struct ti_softc {
u_int32_t ti_tx_buf_ratio;
int ti_if_flags;
int ti_txcnt;
+ struct mtx ti_mtx;
};
+#define TI_LOCK(_sc) mtx_enter(&(_sc)->ti_mtx, MTX_DEF)
+#define TI_UNLOCK(_sc) mtx_exit(&(_sc)->ti_mtx, MTX_DEF)
+
/*
* Microchip Technology 24Cxx EEPROM control bytes
*/
diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c
index 3649d7e..10b9942 100644
--- a/sys/dev/vr/if_vr.c
+++ b/sys/dev/vr/if_vr.c
@@ -285,9 +285,9 @@ static int vr_mii_readreg(sc, frame)
struct vr_mii_frame *frame;
{
- int i, ack, s;
+ int i, ack;
- s = splimp();
+ VR_LOCK(sc);
/*
* Set up frame for RX.
@@ -364,7 +364,7 @@ fail:
SIO_SET(VR_MIICMD_CLK);
DELAY(1);
- splx(s);
+ VR_UNLOCK(sc);
if (ack)
return(1);
@@ -379,9 +379,7 @@ static int vr_mii_writereg(sc, frame)
struct vr_mii_frame *frame;
{
- int s;
-
- s = splimp();
+ VR_LOCK(sc);
CSR_WRITE_1(sc, VR_MIICMD, 0);
VR_SETBIT(sc, VR_MIICMD, VR_MIICMD_DIRECTPGM);
@@ -419,7 +417,7 @@ static int vr_mii_writereg(sc, frame)
*/
SIO_CLR(VR_MIICMD_DIR);
- splx(s);
+ VR_UNLOCK(sc);
return(0);
}
@@ -467,8 +465,10 @@ static void vr_miibus_statchg(dev)
struct mii_data *mii;
sc = device_get_softc(dev);
+ VR_LOCK(sc);
mii = device_get_softc(sc->vr_miibus);
vr_setcfg(sc, mii->mii_media_active);
+ VR_UNLOCK(sc);
return;
}
@@ -633,15 +633,13 @@ static int vr_probe(dev)
static int vr_attach(dev)
device_t dev;
{
- int i, s;
+ int i;
u_char eaddr[ETHER_ADDR_LEN];
u_int32_t command;
struct vr_softc *sc;
struct ifnet *ifp;
int unit, error = 0, rid;
- s = splimp();
-
sc = device_get_softc(dev);
unit = device_get_unit(dev);
bzero(sc, sizeof(struct vr_softc *));
@@ -731,6 +729,8 @@ static int vr_attach(dev)
goto fail;
}
+ mtx_init(&sc->vr_mtx, "vr", MTX_DEF);
+ VR_LOCK(sc);
/* Reset the adapter. */
vr_reset(sc);
@@ -803,9 +803,13 @@ static int vr_attach(dev)
* Call MI attach routine.
*/
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
+ VR_UNLOCK(sc);
+ return(0);
fail:
- splx(s);
+ VR_UNLOCK(sc);
+ mtx_destroy(&sc->vr_mtx);
+
return(error);
}
@@ -814,11 +818,9 @@ static int vr_detach(dev)
{
struct vr_softc *sc;
struct ifnet *ifp;
- int s;
-
- s = splimp();
sc = device_get_softc(dev);
+ VR_LOCK(sc);
ifp = &sc->arpcom.ac_if;
vr_stop(sc);
@@ -833,7 +835,8 @@ static int vr_detach(dev)
contigfree(sc->vr_ldata, sizeof(struct vr_list_data), M_DEVBUF);
- splx(s);
+ VR_UNLOCK(sc);
+ mtx_destroy(&sc->vr_mtx);
return(0);
}
@@ -1146,17 +1149,15 @@ static void vr_tick(xsc)
{
struct vr_softc *sc;
struct mii_data *mii;
- int s;
-
- s = splimp();
sc = xsc;
+ VR_LOCK(sc);
mii = device_get_softc(sc->vr_miibus);
mii_tick(mii);
sc->vr_stat_ch = timeout(vr_tick, sc, hz);
- splx(s);
+ VR_UNLOCK(sc);
return;
}
@@ -1169,11 +1170,13 @@ static void vr_intr(arg)
u_int16_t status;
sc = arg;
+ VR_LOCK(sc);
ifp = &sc->arpcom.ac_if;
/* Supress unwanted interrupts. */
if (!(ifp->if_flags & IFF_UP)) {
vr_stop(sc);
+ VR_UNLOCK(sc);
return;
}
@@ -1226,6 +1229,8 @@ static void vr_intr(arg)
vr_start(ifp);
}
+ VR_UNLOCK(sc);
+
return;
}
@@ -1314,8 +1319,11 @@ static void vr_start(ifp)
sc = ifp->if_softc;
- if (ifp->if_flags & IFF_OACTIVE)
+ VR_LOCK(sc);
+ if (ifp->if_flags & IFF_OACTIVE) {
+ VR_UNLOCK(sc);
return;
+ }
/*
* Check for an available queue slot. If there are none,
@@ -1357,8 +1365,10 @@ static void vr_start(ifp)
/*
* If there are no frames queued, bail.
*/
- if (cur_tx == NULL)
+ if (cur_tx == NULL) {
+ VR_UNLOCK(sc);
return;
+ }
sc->vr_cdata.vr_tx_tail = cur_tx;
@@ -1369,6 +1379,7 @@ static void vr_start(ifp)
* Set a timeout in case the chip goes out to lunch.
*/
ifp->if_timer = 5;
+ VR_UNLOCK(sc);
return;
}
@@ -1379,9 +1390,8 @@ static void vr_init(xsc)
struct vr_softc *sc = xsc;
struct ifnet *ifp = &sc->arpcom.ac_if;
struct mii_data *mii;
- int s;
- s = splimp();
+ VR_LOCK(sc);
mii = device_get_softc(sc->vr_miibus);
@@ -1402,7 +1412,7 @@ static void vr_init(xsc)
printf("vr%d: initialization failed: no "
"memory for rx buffers\n", sc->vr_unit);
vr_stop(sc);
- (void)splx(s);
+ VR_UNLOCK(sc);
return;
}
@@ -1451,10 +1461,10 @@ static void vr_init(xsc)
ifp->if_flags |= IFF_RUNNING;
ifp->if_flags &= ~IFF_OACTIVE;
- (void)splx(s);
-
sc->vr_stat_ch = timeout(vr_tick, sc, hz);
+ VR_UNLOCK(sc);
+
return;
}
@@ -1501,9 +1511,9 @@ static int vr_ioctl(ifp, command, data)
struct vr_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *) data;
struct mii_data *mii;
- int s, error = 0;
+ int error = 0;
- s = splimp();
+ VR_LOCK(sc);
switch(command) {
case SIOCSIFADDR:
@@ -1535,7 +1545,7 @@ static int vr_ioctl(ifp, command, data)
break;
}
- (void)splx(s);
+ VR_UNLOCK(sc);
return(error);
}
@@ -1547,6 +1557,7 @@ static void vr_watchdog(ifp)
sc = ifp->if_softc;
+ VR_LOCK(sc);
ifp->if_oerrors++;
printf("vr%d: watchdog timeout\n", sc->vr_unit);
@@ -1557,6 +1568,8 @@ static void vr_watchdog(ifp)
if (ifp->if_snd.ifq_head != NULL)
vr_start(ifp);
+ VR_UNLOCK(sc);
+
return;
}
@@ -1570,6 +1583,8 @@ static void vr_stop(sc)
register int i;
struct ifnet *ifp;
+ VR_LOCK(sc);
+
ifp = &sc->arpcom.ac_if;
ifp->if_timer = 0;
@@ -1607,6 +1622,7 @@ static void vr_stop(sc)
sizeof(sc->vr_ldata->vr_tx_list));
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+ VR_UNLOCK(sc);
return;
}
diff --git a/sys/dev/vr/if_vrreg.h b/sys/dev/vr/if_vrreg.h
index 2f2ac97..8217a8c 100644
--- a/sys/dev/vr/if_vrreg.h
+++ b/sys/dev/vr/if_vrreg.h
@@ -411,8 +411,12 @@ struct vr_softc {
struct vr_list_data *vr_ldata;
struct vr_chain_data vr_cdata;
struct callout_handle vr_stat_ch;
+ struct mtx vr_mtx;
};
+#define VR_LOCK(_sc) mtx_enter(&(_sc)->vr_mtx, MTX_DEF)
+#define VR_UNLOCK(_sc) mtx_exit(&(_sc)->vr_mtx, MTX_DEF)
+
/*
* register space access macros
*/
OpenPOWER on IntegriCloud