summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2016-09-05 08:17:29 +0000
committertedu <tedu@openbsd.org>2016-09-05 08:17:29 +0000
commit3ce014738c84bba56a2c997bd0f1afb446ddbc9e (patch)
treebd89bc6763e899a10d32765a97091eaf939ef6c2
parentInitialize stack variables to zero before memmove(). (diff)
downloadwireguard-openbsd-3ce014738c84bba56a2c997bd0f1afb446ddbc9e.tar.xz
wireguard-openbsd-3ce014738c84bba56a2c997bd0f1afb446ddbc9e.zip
convert busy flag and tsleep to rwlock as in iwm
-rw-r--r--sys/dev/pci/if_ipw.c31
-rw-r--r--sys/dev/pci/if_ipwvar.h6
2 files changed, 11 insertions, 26 deletions
diff --git a/sys/dev/pci/if_ipw.c b/sys/dev/pci/if_ipw.c
index f47b220afb5..c9a0ed2c144 100644
--- a/sys/dev/pci/if_ipw.c
+++ b/sys/dev/pci/if_ipw.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ipw.c,v 1.115 2016/04/13 10:34:32 mpi Exp $ */
+/* $OpenBSD: if_ipw.c,v 1.116 2016/09/05 08:17:29 tedu Exp $ */
/*-
* Copyright (c) 2004-2008
@@ -28,6 +28,7 @@
#include <sys/task.h>
#include <sys/mbuf.h>
#include <sys/kernel.h>
+#include <sys/rwlock.h>
#include <sys/socket.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -203,6 +204,7 @@ ipw_attach(struct device *parent, struct device *self, void *aux)
}
printf(": %s", intrstr);
+ rw_init(&sc->sc_rwlock, "ipwlock");
task_set(&sc->sc_scantask, ipw_scan, sc);
task_set(&sc->sc_authandassoctask, ipw_auth_and_assoc, sc);
@@ -318,17 +320,14 @@ ipw_wakeup(struct ipw_softc *sc)
data &= ~0x0000ff00;
pci_conf_write(sc->sc_pct, sc->sc_pcitag, 0x40, data);
+ rw_enter_write(&sc->sc_rwlock);
s = splnet();
- while (sc->sc_flags & IPW_FLAG_BUSY)
- tsleep(&sc->sc_flags, PZERO, "ipwpwr", 0);
- sc->sc_flags |= IPW_FLAG_BUSY;
if (ifp->if_flags & IFF_UP)
ipw_init(ifp);
- sc->sc_flags &= ~IPW_FLAG_BUSY;
- wakeup(&sc->sc_flags);
splx(s);
+ rw_exit_write(&sc->sc_rwlock);
}
int
@@ -1359,18 +1358,10 @@ ipw_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
struct ifreq *ifr;
int s, error = 0;
- s = splnet();
- /*
- * Prevent processes from entering this function while another
- * process is tsleep'ing in it.
- */
- while ((sc->sc_flags & IPW_FLAG_BUSY) && error == 0)
- error = tsleep(&sc->sc_flags, PCATCH, "ipwioc", 0);
- if (error != 0) {
- splx(s);
+ error = rw_enter(&sc->sc_rwlock, RW_ENTER | RW_INTR);
+ if (error)
return error;
- }
- sc->sc_flags |= IPW_FLAG_BUSY;
+ s = splnet();
switch (cmd) {
case SIOCSIFADDR:
@@ -1419,9 +1410,8 @@ ipw_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = 0;
}
- sc->sc_flags &= ~IPW_FLAG_BUSY;
- wakeup(&sc->sc_flags);
splx(s);
+ rw_exit_write(&sc->sc_rwlock);
return error;
}
@@ -1483,8 +1473,6 @@ ipw_stop_master(struct ipw_softc *sc)
tmp = CSR_READ_4(sc, IPW_CSR_RST);
CSR_WRITE_4(sc, IPW_CSR_RST, tmp | IPW_RST_PRINCETON_RESET);
-
- sc->sc_flags &= ~IPW_FLAG_FW_INITED;
}
int
@@ -2004,7 +1992,6 @@ ipw_init(struct ifnet *ifp)
printf("%s: could not load firmware\n", sc->sc_dev.dv_xname);
goto fail2;
}
- sc->sc_flags |= IPW_FLAG_FW_INITED;
free(fw.data, M_DEVBUF, fw.size);
fw.data = NULL;
diff --git a/sys/dev/pci/if_ipwvar.h b/sys/dev/pci/if_ipwvar.h
index 8d01e4dab89..bef0fff5f23 100644
--- a/sys/dev/pci/if_ipwvar.h
+++ b/sys/dev/pci/if_ipwvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ipwvar.h,v 1.25 2015/09/01 07:09:55 deraadt Exp $ */
+/* $OpenBSD: if_ipwvar.h,v 1.26 2016/09/05 08:17:29 tedu Exp $ */
/*-
* Copyright (c) 2004-2006
@@ -82,9 +82,7 @@ struct ipw_softc {
int (*sc_newstate)(struct ieee80211com *,
enum ieee80211_state, int);
- uint32_t sc_flags;
-#define IPW_FLAG_FW_INITED (1 << 0)
-#define IPW_FLAG_BUSY (1 << 1)
+ struct rwlock sc_rwlock;
bus_space_tag_t sc_st;
bus_space_handle_t sc_sh;