Module Name: src
Committed By: rmind
Date: Sat May 14 12:44:16 UTC 2011
Modified Files:
src/sys/compat/ndis: kern_ndis.c nbcompat.c nbcompat.h ndis_var.h
subr_ndis.c subr_ntoskrnl.c
src/sys/dev/if_ndis: if_ndis.c if_ndisvar.h
Log Message:
Replace simple_lock(9) with mutex(9), clean up.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/compat/ndis/kern_ndis.c
cvs rdiff -u -r1.10 -r1.11 src/sys/compat/ndis/nbcompat.c
cvs rdiff -u -r1.14 -r1.15 src/sys/compat/ndis/nbcompat.h
cvs rdiff -u -r1.5 -r1.6 src/sys/compat/ndis/ndis_var.h
cvs rdiff -u -r1.23 -r1.24 src/sys/compat/ndis/subr_ndis.c
cvs rdiff -u -r1.18 -r1.19 src/sys/compat/ndis/subr_ntoskrnl.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/if_ndis/if_ndis.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/if_ndis/if_ndisvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/compat/ndis/kern_ndis.c
diff -u src/sys/compat/ndis/kern_ndis.c:1.21 src/sys/compat/ndis/kern_ndis.c:1.22
--- src/sys/compat/ndis/kern_ndis.c:1.21 Mon May 11 21:31:29 2009
+++ src/sys/compat/ndis/kern_ndis.c Sat May 14 12:44:16 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: kern_ndis.c,v 1.22 2011/05/14 12:44:16 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <[email protected]>. All rights reserved.
@@ -35,7 +37,7 @@
__FBSDID("$FreeBSD: src/sys/compat/ndis/kern_ndis.c,v 1.60.2.5 2005/04/01 17:14:20 wpaul Exp $");
#endif
#ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: kern_ndis.c,v 1.21 2009/05/11 21:31:29 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ndis.c,v 1.22 2011/05/14 12:44:16 rmind Exp $");
#endif
#include <sys/param.h>
@@ -50,9 +52,7 @@
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/lock.h>
-#ifdef __FreeBSD__
#include <sys/mutex.h>
-#endif
#include <sys/conf.h>
#include <sys/kernel.h>
@@ -134,9 +134,6 @@
struct proc *np_p;
int np_state;
uint8_t np_stack[PAGE_SIZE*NDIS_KSTACK_PAGES];
-#ifdef __NetBSD__
- int np_needs_wakeup;
-#endif
};
static void ndis_return(void *);
@@ -152,9 +149,7 @@
#ifdef __FreeBSD__
static struct mtx ndis_thr_mtx;
#else /* __NetBSD__ */
-static struct simplelock ndis_thr_mtx;
-#define THR_LOCK() do {old_ipl = splnet(); simple_lock(&ndis_thr_mtx);} while(0)
-#define THR_UNLOCK() do {simple_unlock(&ndis_thr_mtx); splx(old_ipl);} while(0)
+static kmutex_t ndis_thr_mtx;
#endif
static struct mtx ndis_req_mtx;
@@ -338,44 +333,18 @@
{
struct ndis_req *r = NULL, *die = NULL;
struct ndisproc *p;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
p = arg;
- while (1) {
+ for (;;) {
+ mtx_lock_spin(&ndis_thr_mtx);
+ ndis_thsuspend(p->np_p, &ndis_thr_mtx, 0);
- /* Protect against interrupts between checking if the queue is empty, and going to sleep
- * to avoid a wakeup before sleep.
- */
- old_ipl = splnet();
- /* Sleep, but preserve our original priority. */
- if(STAILQ_EMPTY(p->np_q)) {
- /* TODO: If we get an interrupt between checking if the queue is empty,
- * TODO: and sleeping, then in the interrupt, an item could be placed
- * TODO: on the queue, and we could be woken up before we sleep.
- *
- */
- ndis_thsuspend(p->np_p, NULL, 0);
- }
- splx(old_ipl);
-
-#ifdef __NetBSD__
- p->np_needs_wakeup = FALSE;
-#endif
-
/* Look for any jobs on the work queue. */
-#ifdef __FreeBSD__
- mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
-
p->np_state = NDIS_PSTATE_RUNNING;
- while(!STAILQ_EMPTY(p->np_q)/*STAILQ_FIRST(p->np_q) != NULL*/) {
+ while (!STAILQ_EMPTY(p->np_q)) {
r = STAILQ_FIRST(p->np_q);
- STAILQ_REMOVE_HEAD(p->np_q, link);
+ STAILQ_REMOVE_HEAD(p->np_q, link);
/* for debugging */
@@ -388,11 +357,8 @@
_ndis_swi_req = r;
r->area = 2;
}
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
+
/* Just for debugging */
if(p == &ndis_tproc) {
@@ -412,11 +378,7 @@
calling_in_swi = FALSE;
}
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
/* Zeroing out the ndis_req is just for debugging */
//memset(r, 0, sizeof(struct ndis_req));
@@ -428,11 +390,7 @@
}
p->np_state = NDIS_PSTATE_SLEEPING;
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
/* Bail if we were told to shut down. */
@@ -441,18 +399,9 @@
}
wakeup(die);
-#ifdef __FreeBSD__
-#if __FreeBSD_version < 502113
- mtx_lock(&Giant);
-#endif
-#endif
- if(p == &ndis_tproc) {
- printf("taskqueue thread exiting!\n");
- } else if(p == &ndis_iproc) {
- printf("swi thread exiting!\n");
- }
+
kthread_exit(0);
- return; /* notreached */
+ /* NOTREACHED */
}
/*static*/ int
@@ -466,9 +415,8 @@
#ifdef __FreeBSD__
mtx_init(&ndis_thr_mtx, "NDIS thread lock", NULL, MTX_SPIN);
#else /* __NetBSD__ */
- simple_lock_init(&ndis_thr_mtx);
- //lockinit(&ndis_thr_mtx, PWAIT, "NDIS thread lock", 0, 0);
-#endif
+ mutex_init(&ndis_thr_mtx, MUTEX_DEFAULT, IPL_NET);
+#endif
mtx_init(&ndis_req_mtx, "NDIS request lock", MTX_NDIS_LOCK, MTX_DEF);
STAILQ_INIT(&ndis_ttodo);
@@ -539,9 +487,7 @@
}
mtx_destroy(&ndis_req_mtx);
-#ifndef __NetBSD__
mtx_destroy(&ndis_thr_mtx);
-#endif
return;
}
@@ -552,9 +498,6 @@
struct ndis_req *r;
struct ndisqhead *q;
struct proc *p;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
if (t == NDIS_TASKQUEUE) {
q = &ndis_ttodo;
@@ -566,11 +509,8 @@
/* Create and post a special 'exit' job. */
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
+
r = STAILQ_FIRST(&ndis_free);
STAILQ_REMOVE_HEAD(&ndis_free, link);
r->nr_func = NULL;
@@ -578,40 +518,20 @@
r->nr_exit = TRUE;
r->area = 3;
STAILQ_INSERT_TAIL(q, r, link);
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
ndis_thresume(p);
- /* wait for thread exit */
-
-#ifdef __FreeBSD__
- tsleep(r, curthread->td_priority|PCATCH, "ndisthexit", hz * 60);
-#else
- tsleep(r, curlwp->l_priority|PCATCH, "ndisthexit", hz * 60);
-#endif
+ /* Wait for thread exit */
+ tsleep(r, PZERO | PCATCH, "ndisthexit", hz * 60);
/* Now empty the job list. */
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
while ((r = STAILQ_FIRST(q)) != NULL) {
STAILQ_REMOVE_HEAD(q, link);
STAILQ_INSERT_HEAD(&ndis_free, r, link);
}
-
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
-
- return;
}
static int
@@ -619,26 +539,16 @@
{
struct ndis_req *r;
int i;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
for (i = 0; i < cnt; i++) {
r = malloc(sizeof(struct ndis_req), M_DEVBUF, M_WAITOK);
if (r == NULL)
return(ENOMEM);
-#ifdef __FreeBSD__
+
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
STAILQ_INSERT_HEAD(&ndis_free, r, link);
ndis_jobs++;
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
}
return(0);
@@ -649,33 +559,17 @@
{
struct ndis_req *r;
int i;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
for (i = 0; i < cnt; i++) {
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
r = STAILQ_FIRST(&ndis_free);
if (r == NULL) {
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
return(ENOMEM);
}
STAILQ_REMOVE_HEAD(&ndis_free, link);
ndis_jobs--;
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
-
free(r, M_DEVBUF);
}
@@ -688,9 +582,6 @@
struct ndis_req *r;
struct ndisqhead *q;
struct proc *p;
-#ifdef __NetBSD__
- int old_ipl;
-#endif
if (t == NDIS_TASKQUEUE) {
q = &ndis_ttodo;
@@ -700,29 +591,18 @@
p = ndis_iproc.np_p;
}
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
STAILQ_FOREACH(r, q, link) {
if (r->nr_func == func && r->nr_arg == arg) {
r->area = 4;
STAILQ_REMOVE(q, r, ndis_req, link);
STAILQ_INSERT_HEAD(&ndis_free, r, link);
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
return(0);
}
}
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
+
return(ENOENT);
}
@@ -738,7 +618,6 @@
struct proc *p;
int s;
#ifdef __NetBSD__
- int old_ipl;
/* just for debugging */
struct ndis_req **ls;
//struct lwp *l = curlwp;
@@ -754,12 +633,8 @@
p = ndis_iproc.np_p;
}
-#ifdef __FreeBSD__
mtx_lock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_LOCK();
-#endif
-
+
/*
* Check to see if an instance of this job is already
* pending. If so, don't bother queuing it again.
@@ -772,11 +647,7 @@
else
s = ndis_iproc.np_state;
#endif
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
#ifdef __NetBSD__
/* The swi thread seemed to be going to sleep, and not waking up
* again, so I thought I'd try this out...
@@ -789,11 +660,7 @@
}
r = STAILQ_FIRST(&ndis_free);
if (r == NULL) {
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
return(EAGAIN);
}
STAILQ_REMOVE_HEAD(&ndis_free, link);
@@ -808,21 +675,10 @@
STAILQ_INSERT_TAIL(q, r, link);
if (t == NDIS_TASKQUEUE) {
s = ndis_tproc.np_state;
-#ifdef __NetBSD__
- ndis_tproc.np_needs_wakeup = TRUE;
-#endif
} else {
s = ndis_iproc.np_state;
-#ifdef __NetBSD__
- ndis_iproc.np_needs_wakeup = TRUE;
-#endif
}
-
-#ifdef __FreeBSD__
mtx_unlock_spin(&ndis_thr_mtx);
-#else /* __NetBSD__ */
- THR_UNLOCK();
-#endif
/*
* Post the job, but only if the thread is actually blocked
@@ -862,52 +718,17 @@
*/
int
-ndis_thsuspend(p, m, timo)
- struct proc *p;
-#ifdef __FreeBSD__
- struct mtx *m;
-#else /* __NetBSD__*/
- struct simplelock *m;
-#endif
- int timo;
+ndis_thsuspend(proc_t *p, kmutex_t *m, int timo)
{
- int error;
-
-#ifdef __FreeBSD__
- if (m != NULL) {
- error = msleep(&p->p_siglist, m,
- curthread->td_priority, "ndissp", timo);
- } else {
- PROC_LOCK(p);
- error = msleep(&p->p_siglist, &p->p_mtx,
- curthread->td_priority|PDROP, "ndissp", timo);
- }
-#else
-/* TODO: Why do they wait on &p->p_siglist? I noticed that in FreeBSD's
- * src/sys/sys/proc.h there is some mention of p_siglist having to do with
- * M:N threading.
- */
- if (m != NULL) {
- //mtx_unlock(m);
- error = ltsleep(&p->p_sigpend.sp_set, curlwp->l_priority,
- "ndissp", timo, m);
- //mtx_lock(m);
- } else {
- error = ltsleep(&p->p_sigpend.sp_set, curlwp->l_priority/*|PNORELOCK*/,
- "ndissp", timo, 0 /*&p->p_lock*/);
- }
-#endif
-
- return(error);
+ return mtsleep(&p->p_sigpend.sp_set, PZERO, "ndissp", timo, m);
}
void
ndis_thresume(struct proc *p)
{
+
wakeup(&p->p_sigpend.sp_set);
-
- return;
}
__stdcall static void
@@ -1667,9 +1488,6 @@
uint32_t byteswritten = 0, bytesneeded = 0;
int error;
uint8_t irql = 0; /* XXX: gcc */
-#ifdef __NetBSD__
- int s;
-#endif
/*
* According to the NDIS spec, MiniportQueryInformation()
@@ -1711,23 +1529,12 @@
if (rval == NDIS_STATUS_PENDING) {
mtx_lock(&ndis_req_mtx);
-#ifdef __FreeBSD__
- error = msleep(&sc->ndis_block->nmb_setstat,
- &ndis_req_mtx,
- curthread->td_priority|PDROP,
- "ndisset", 5 * hz);
-#else
- error = ltsleep(&sc->ndis_block->nmb_setstat,
- curlwp->l_priority|PNORELOCK,
- "ndisset", 5 * hz, 0);
-#endif
+ error = mtsleep(&sc->ndis_block->nmb_setstat,
+ PZERO | PNORELOCK,
+ "ndisset", 5 * hz, &ndis_req_mtx);
rval = sc->ndis_block->nmb_setstat;
-#ifdef __NetBSD__
- mtx_unlock(&ndis_req_mtx);
-#endif
}
-
if (byteswritten)
*buflen = byteswritten;
if (bytesneeded)
@@ -1929,13 +1736,7 @@
KeReleaseSpinLock(&sc->ndis_block->nmb_lock, irql);
if (rval == NDIS_STATUS_PENDING) {
- mtx_lock(&ndis_req_mtx);
-#ifdef __FreeBSD__
- msleep(sc, &ndis_req_mtx,
- curthread->td_priority|PDROP, "ndisrst", 0);
-#else
- ltsleep(sc, curlwp->l_priority|PNORELOCK, "ndisrst", 0, 0);
-#endif
+ mtsleep(sc, PZERO | PNORELOCK, "ndisrst", 0, &ndis_req_mtx);
}
return(0);
@@ -1948,9 +1749,6 @@
ndis_handle adapter;
__stdcall ndis_halt_handler haltfunc;
struct ifnet *ifp;
-#ifdef __NetBSD__
- int s;
-#endif
sc = arg;
#ifdef __FreeBSD__
@@ -1994,9 +1792,6 @@
struct ndis_softc *sc;
ndis_handle adapter;
__stdcall ndis_shutdown_handler shutdownfunc;
-#ifdef __NetBSD__
- int s;
-#endif
sc = arg;
@@ -2030,9 +1825,6 @@
ndis_status status, openstatus = 0;
ndis_medium mediumarray[NdisMediumMax];
uint32_t chosenmedium, i;
-#ifdef __NetBSD__
- int s;
-#endif
if (arg == NULL)
return(EINVAL);
@@ -2209,15 +2001,8 @@
if (rval == NDIS_STATUS_PENDING) {
mtx_lock(&ndis_req_mtx);
-#ifdef __FreeBSD__
- error = msleep(&sc->ndis_block->nmb_getstat,
- &ndis_req_mtx,
- curthread->td_priority|PDROP,
- "ndisget", 5 * hz);
-#else
- ltsleep(&sc->ndis_block->nmb_getstat,
- curlwp->l_priority|PNORELOCK, "ndisget", 5 * hz, 0);
-#endif
+ mtsleep(&sc->ndis_block->nmb_getstat, PZERO | PNORELOCK,
+ "ndisget", 5 * hz, &ndis_req_mtx);
rval = sc->ndis_block->nmb_getstat;
}
Index: src/sys/compat/ndis/nbcompat.c
diff -u src/sys/compat/ndis/nbcompat.c:1.10 src/sys/compat/ndis/nbcompat.c:1.11
--- src/sys/compat/ndis/nbcompat.c:1.10 Tue Jan 8 07:59:23 2008
+++ src/sys/compat/ndis/nbcompat.c Sat May 14 12:44:16 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: nbcompat.c,v 1.10 2008/01/08 07:59:23 he Exp $ */
+/* $NetBSD: nbcompat.c,v 1.11 2011/05/14 12:44:16 rmind Exp $ */
/* nbcompat.c
* Implementations of some FreeBSD functions on NetBSD to make things
@@ -6,7 +6,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nbcompat.c,v 1.10 2008/01/08 07:59:23 he Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nbcompat.c,v 1.11 2011/05/14 12:44:16 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -54,20 +54,6 @@
return 0;
}
-void
-mtx_lock(struct mtx *mutex)
-{
- /* XXXSMP needs doing
- */
- //mutex_enter(mutex);
-}
-
-void
-mtx_unlock(struct mtx *mutex)
-{
- //mutex_exit(mutex);
-}
-
int
device_is_attached(device_t dev)
{
Index: src/sys/compat/ndis/nbcompat.h
diff -u src/sys/compat/ndis/nbcompat.h:1.14 src/sys/compat/ndis/nbcompat.h:1.15
--- src/sys/compat/ndis/nbcompat.h:1.14 Sat Jan 22 12:06:51 2011
+++ src/sys/compat/ndis/nbcompat.h Sat May 14 12:44:16 2011
@@ -12,10 +12,12 @@
#define mtx kmutex
#define mtx_init(mtx, desc, type, opts) mutex_init(mtx, MUTEX_DEFAULT, IPL_NONE)
-/*
-#define mtx_lock(mtx) ndis_mtx_ipl = splnet() mutex_enter(mtx)
-#define mtx_unlock(mtx) splx(ndis_mtx_ipl) mutex_exit(mtx)
-*/
+
+#define mtx_lock(mtx) mutex_enter(mtx)
+#define mtx_unlock(mtx) mutex_exit(mtx)
+
+#define mtx_lock_spin(mtx) mutex_spin_enter(mtx);
+#define mtx_unlock_spin(mtx) mutex_spin_exit(mtx);
void mtx_lock(struct mtx *mutex);
void mtx_unlock(struct mtx *mutex);
Index: src/sys/compat/ndis/ndis_var.h
diff -u src/sys/compat/ndis/ndis_var.h:1.5 src/sys/compat/ndis/ndis_var.h:1.6
--- src/sys/compat/ndis/ndis_var.h:1.5 Fri Jan 4 21:17:46 2008
+++ src/sys/compat/ndis/ndis_var.h Sat May 14 12:44:16 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: ndis_var.h,v 1.6 2011/05/14 12:44:16 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <[email protected]>. All rights reserved.
@@ -35,7 +37,7 @@
#ifndef _NDIS_VAR_H_
#define _NDIS_VAR_H_
-#include <sys/simplelock.h>
+#include <sys/lock.h>
/* Forward declarations */
struct ndis_miniport_block;
@@ -1600,7 +1602,7 @@
#ifdef __FreeBSD__
extern int ndis_thsuspend(struct proc *, struct mtx *, int);
#else /* __NetBSD__ */
-extern int ndis_thsuspend(struct proc *, struct simplelock *, int);
+extern int ndis_thsuspend(struct proc *, kmutex_t *, int);
#endif
extern void ndis_thresume(struct proc *);
extern int ndis_strcasecmp(const char *, const char *);
Index: src/sys/compat/ndis/subr_ndis.c
diff -u src/sys/compat/ndis/subr_ndis.c:1.23 src/sys/compat/ndis/subr_ndis.c:1.24
--- src/sys/compat/ndis/subr_ndis.c:1.23 Mon Jul 26 22:33:23 2010
+++ src/sys/compat/ndis/subr_ndis.c Sat May 14 12:44:16 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: subr_ndis.c,v 1.24 2011/05/14 12:44:16 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <[email protected]>. All rights reserved.
@@ -35,7 +37,7 @@
__FBSDID("$FreeBSD: src/sys/compat/ndis/subr_ndis.c,v 1.67.2.7 2005/03/31 21:50:11 wpaul Exp $");
#endif
#ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: subr_ndis.c,v 1.23 2010/07/26 22:33:23 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_ndis.c,v 1.24 2011/05/14 12:44:16 rmind Exp $");
#endif
/*
@@ -2710,13 +2712,7 @@
tv.tv_sec = 0;
tv.tv_usec = usecs;
-#ifdef __FreeBSD__
- ndis_thsuspend(curthread->td_proc, NULL, tvtohz(&tv));
-#else
ndis_thsuspend(curproc, NULL, tvtohz(&tv));
-#endif
-
- return;
}
__stdcall static uint32_t
Index: src/sys/compat/ndis/subr_ntoskrnl.c
diff -u src/sys/compat/ndis/subr_ntoskrnl.c:1.18 src/sys/compat/ndis/subr_ntoskrnl.c:1.19
--- src/sys/compat/ndis/subr_ntoskrnl.c:1.18 Wed Mar 18 17:06:48 2009
+++ src/sys/compat/ndis/subr_ntoskrnl.c Sat May 14 12:44:16 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: subr_ntoskrnl.c,v 1.19 2011/05/14 12:44:16 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <[email protected]>. All rights reserved.
@@ -35,7 +37,7 @@
__FBSDID("$FreeBSD: src/sys/compat/ndis/subr_ntoskrnl.c,v 1.43.2.5 2005/03/31 04:24:36 wpaul Exp $");
#endif
#ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: subr_ntoskrnl.c,v 1.18 2009/03/18 17:06:48 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_ntoskrnl.c,v 1.19 2011/05/14 12:44:16 rmind Exp $");
#endif
#ifdef __FreeBSD__
@@ -47,10 +49,7 @@
#include <sys/errno.h>
#include <sys/systm.h>
#include <sys/malloc.h>
-#include <sys/lock.h>
-#ifdef __FreeBSD__
#include <sys/mutex.h>
-#endif
#include <sys/callout.h>
#if __FreeBSD_version > 502113
@@ -216,9 +215,7 @@
#ifdef __FreeBSD__
static struct mtx ntoskrnl_dispatchlock;
#else /* __NetBSD__ */
-static struct simplelock ntoskrnl_dispatchlock;
-#define DISPATCH_LOCK() do {s = splnet(); simple_lock(&ntoskrnl_dispatchlock);} while(0)
-#define DISPATCH_UNLOCK() do {simple_unlock(&ntoskrnl_dispatchlock); splx(s);} while(0)
+static kmutex_t ntoskrnl_dispatchlock;
#endif
static kspin_lock ntoskrnl_global;
@@ -239,7 +236,7 @@
mtx_init(&ntoskrnl_dispatchlock,
"ntoskrnl dispatch lock", MTX_NDIS_LOCK, MTX_DEF);
#else /* __NetBSD__ */
- simple_lock_init(&ntoskrnl_dispatchlock);
+ mutex_init(&ntoskrnl_dispatchlock, MUTEX_DEFAULT, IPL_NET);
#endif
KeInitializeSpinLock(&ntoskrnl_global);
KeInitializeSpinLock(&ntoskrnl_cancellock);
@@ -289,11 +286,10 @@
#ifdef __FreeBSD__
uma_zdestroy(mdl_zone);
- mtx_destroy(&ntoskrnl_dispatchlock);
#else
pool_destroy(&mdl_pool);
- /* XXX destroy lock */
#endif
+ mtx_destroy(&ntoskrnl_dispatchlock);
return(0);
}
@@ -781,30 +777,17 @@
IoMakeAssociatedIrp(irp *ip, uint8_t stsize)
{
irp *associrp;
-#ifdef __NetBSD__
- int s;
-#endif
associrp = IoAllocateIrp(stsize, FALSE);
if (associrp == NULL)
return(NULL);
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
associrp->irp_flags |= IRP_ASSOCIATED_IRP;
associrp->irp_tail.irp_overlay.irp_thread =
ip->irp_tail.irp_overlay.irp_thread;
associrp->irp_assoc.irp_master = ip;
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(associrp);
}
@@ -977,26 +960,13 @@
IoAttachDeviceToDeviceStack(device_object *src, device_object *dst)
{
device_object *attached;
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
attached = IoGetAttachedDevice(dst);
attached->do_attacheddev = src;
src->do_attacheddev = NULL;
src->do_stacksize = attached->do_stacksize + 1;
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(attached);
}
@@ -1005,24 +975,13 @@
IoDetachDevice(device_object *topdev)
{
device_object *tail;
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
/* First, break the chain. */
tail = topdev->do_attacheddev;
if (tail == NULL) {
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return;
}
topdev->do_attacheddev = tail->do_attacheddev;
@@ -1035,14 +994,7 @@
tail->do_stacksize--;
tail = tail->do_attacheddev;
}
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
-
- return;
}
/* Always called with dispatcher lock held. */
@@ -1167,18 +1119,11 @@
struct timeval tv;
int error = 0;
uint64_t curtime;
-#ifdef __NetBSD__
- int s;
-#endif
if (obj == NULL)
return(STATUS_INVALID_PARAMETER);
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
/*
* See if the object is a mutex. If so, and we already own
@@ -1205,23 +1150,13 @@
#else
km->km_ownerthread = curproc;
#endif
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return (STATUS_SUCCESS);
}
} else if (obj->dh_sigstate == TRUE) {
if (obj->dh_type == EVENT_TYPE_SYNC)
obj->dh_sigstate = FALSE;
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return (STATUS_SUCCESS);
}
@@ -1258,23 +1193,14 @@
}
}
-#ifdef __FreeBSD__
- error = ndis_thsuspend(td->td_proc, &ntoskrnl_dispatchlock,
- duetime == NULL ? 0 : tvtohz(&tv));
-#else
error = ndis_thsuspend(curproc, &ntoskrnl_dispatchlock,
duetime == NULL ? 0 : tvtohz(&tv));
-#endif
/* We timed out. Leave the object alone and return status. */
if (error == EWOULDBLOCK) {
REMOVE_LIST_ENTRY((&w.wb_waitlist));
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(STATUS_TIMEOUT);
}
@@ -1300,12 +1226,8 @@
if (obj->dh_type == EVENT_TYPE_SYNC)
obj->dh_sigstate = FALSE;
REMOVE_LIST_ENTRY((&w.wb_waitlist));
-
-#ifdef __FreeBSD__
+
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(STATUS_SUCCESS);
}
@@ -1333,21 +1255,14 @@
struct timespec t1, t2;
#ifdef __NetBSD__
struct timeval tv1,tv2;
- int s;
#endif
-
if (cnt > MAX_WAIT_OBJECTS)
return(STATUS_INVALID_PARAMETER);
if (cnt > THREAD_WAIT_OBJECTS && wb_array == NULL)
return(STATUS_INVALID_PARAMETER);
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
if (wb_array == NULL)
w = &_wb_array[0];
else
@@ -1372,11 +1287,7 @@
km->km_ownerthread = curproc;
#endif
if (wtype == WAITTYPE_ANY) {
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return (STATUS_WAIT_0 + i);
}
}
@@ -1384,11 +1295,7 @@
if (obj[i]->dh_type == EVENT_TYPE_SYNC)
obj[i]->dh_sigstate = FALSE;
if (wtype == WAITTYPE_ANY) {
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return (STATUS_WAIT_0 + i);
}
}
@@ -1436,13 +1343,9 @@
TIMEVAL_TO_TIMESPEC(&tv1,&t1);
#endif
-#ifdef __FreeBSD__
- error = ndis_thsuspend(td->td_proc, &ntoskrnl_dispatchlock,
- duetime == NULL ? 0 : tvtohz(&tv));
-#else
- error = ndis_thsuspend(curproc, &ntoskrnl_dispatchlock,
- duetime == NULL ? 0 : tvtohz(&tv));
-#endif
+ error = ndis_thsuspend(curproc, &ntoskrnl_dispatchlock,
+ duetime == NULL ? 0 : tvtohz(&tv));
+
#ifdef __FreeBSD__
nanotime(&t2);
#else
@@ -1487,28 +1390,15 @@
}
if (error == EWOULDBLOCK) {
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(STATUS_TIMEOUT);
}
if (wtype == WAITTYPE_ANY && wcnt) {
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(STATUS_WAIT_0 + widx);
}
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(STATUS_SUCCESS);
}
@@ -1843,11 +1733,6 @@
return(depth);
}
-/* TODO: Make sure that LOCKDEBUG isn't defined otherwise a "struct simplelock" will
- * TODO: be more than 4 bytes. I'm using a kspin_lock as a simplelock, and the
- * TODO: kspin lock is 4 bytes, so this is OK as long as LOCKDEBUG isn't defined.
- */
-
/*
* The KeInitializeSpinLock(), KefAcquireSpinLockAtDpcLevel()
* and KefReleaseSpinLockFromDpcLevel() appear to be analagous
@@ -1858,38 +1743,23 @@
__stdcall void
KeInitializeSpinLock(kspin_lock *lock)
{
-#ifdef __FreeBSD__
- *lock = 0;
-#else /* __NetBSD__ */
- simple_lock_init((struct simplelock *)lock);
-#endif
- return;
+ __cpu_simple_lock_init((__cpu_simple_lock_t *)lock);
}
#ifdef __i386__
__fastcall void
KefAcquireSpinLockAtDpcLevel(REGARGS1(kspin_lock *lock))
{
-#ifdef __FreeBSD__
- while (atomic_cmpset_acq_int((volatile u_int *)lock, 0, 1) == 0)
- /* sit and spin */;
-#else /* __NetBSD__ */
- simple_lock((struct simplelock *)lock);
-#endif
- return;
+ __cpu_simple_lock((__cpu_simple_lock_t *)lock);
}
__fastcall void
KefReleaseSpinLockFromDpcLevel(REGARGS1(kspin_lock *lock))
{
-#ifdef __FreeBSD__
- atomic_store_rel_int((volatile u_int *)lock, 0);
-#else /* __NetBSD__ */
- simple_unlock((struct simplelock *)lock);
-#endif
- return;
+
+ __cpu_simple_unlock((__cpu_simple_lock_t *)lock);
}
__stdcall uint8_t
@@ -2349,26 +2219,15 @@
kmutant *kmutex,
uint8_t kwait)
{
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
+
#ifdef __FreeBSD__
if (kmutex->km_ownerthread != curthread->td_proc) {
#else
if (kmutex->km_ownerthread != curproc) {
#endif
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(STATUS_MUTANT_NOT_OWNED);
}
kmutex->km_acquirecnt--;
@@ -2376,12 +2235,7 @@
kmutex->km_ownerthread = NULL;
ntoskrnl_wakeup(&kmutex->km_header);
}
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(kmutex->km_acquirecnt);
}
@@ -2406,24 +2260,11 @@
KeResetEvent(nt_kevent *kevent)
{
uint32_t prevstate;
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
prevstate = kevent->k_header.dh_sigstate;
kevent->k_header.dh_sigstate = FALSE;
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(prevstate);
}
@@ -2435,24 +2276,11 @@
uint8_t kwait)
{
uint32_t prevstate;
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
prevstate = kevent->k_header.dh_sigstate;
ntoskrnl_wakeup(&kevent->k_header);
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(prevstate);
}
@@ -2584,16 +2412,8 @@
PsTerminateSystemThread(ndis_status status)
{
struct nt_objref *nr;
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
TAILQ_FOREACH(nr, &ntoskrnl_reflist, link) {
#ifdef __FreeBSD__
if (nr->no_obj != curthread->td_proc)
@@ -2604,22 +2424,11 @@
ntoskrnl_wakeup(&nr->no_dh);
break;
}
-
-#ifdef __FreeBSD__
- mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
-
ntoskrnl_kth--;
+ mtx_unlock(&ntoskrnl_dispatchlock);
-#ifdef __FreeBSD__
-#if __FreeBSD_version < 502113
- mtx_lock(&Giant);
-#endif
-#endif /* __FreeBSD__ */
kthread_exit(0);
- return(0); /* notreached */
+ /* NOTREACHED */
}
static uint32_t
@@ -2652,19 +2461,8 @@
{
ktimer *timer;
struct timeval tv;
-#ifdef __NetBSD__
- int s;
-#endif
-#ifdef __FreeBSD__
- mtx_unlock(&Giant);
-#endif
-
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
timer = arg;
@@ -2695,18 +2493,7 @@
KeInsertQueueDpc(timer->k_dpc, NULL, NULL);
ntoskrnl_wakeup(&timer->k_header);
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
-
-#ifdef __FreeBSD__
- mtx_lock(&Giant);
-#endif
-
- return;
}
__stdcall void
@@ -2803,19 +2590,11 @@
struct timeval tv;
uint64_t curtime;
uint8_t pending;
-#ifdef __NetBSD__
- int s;
-#endif
if (timer == NULL)
return(FALSE);
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
-
if (timer->k_header.dh_inserted == TRUE) {
#ifdef __FreeBSD__
untimeout(ntoskrnl_timercall, timer, timer->k_handle);
@@ -2853,12 +2632,7 @@
#else
callout_reset(timer->k_handle, tvtohz(&tv), ntoskrnl_timercall, timer);
#endif
-
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(pending);
}
@@ -2873,18 +2647,11 @@
KeCancelTimer(ktimer *timer)
{
uint8_t pending;
-#ifdef __NetBSD__
- int s;
-#endif
if (timer == NULL)
return(FALSE);
-#ifdef __NetBSD__
- DISPATCH_LOCK();
-#else
mtx_lock(&ntoskrnl_dispatchlock);
-#endif
if (timer->k_header.dh_inserted == TRUE) {
#ifdef __FreeBSD__
@@ -2896,11 +2663,7 @@
} else
pending = KeRemoveQueueDpc(timer->k_dpc);
-#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
-#else /* __NetBSD__ */
- DISPATCH_UNLOCK();
-#endif
return(pending);
}
Index: src/sys/dev/if_ndis/if_ndis.c
diff -u src/sys/dev/if_ndis/if_ndis.c:1.31 src/sys/dev/if_ndis/if_ndis.c:1.32
--- src/sys/dev/if_ndis/if_ndis.c:1.31 Mon Apr 5 07:20:24 2010
+++ src/sys/dev/if_ndis/if_ndis.c Sat May 14 12:44:15 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: if_ndis.c,v 1.32 2011/05/14 12:44:15 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <[email protected]>. All rights reserved.
@@ -35,7 +37,7 @@
__FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis.c,v 1.69.2.6 2005/03/31 04:24:36 wpaul Exp $");
#endif
#ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: if_ndis.c,v 1.31 2010/04/05 07:20:24 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ndis.c,v 1.32 2011/05/14 12:44:15 rmind Exp $");
#endif
@@ -497,8 +499,8 @@
/* start out at dispatch level */
win_irql = DISPATCH_LEVEL;
- simple_lock_init(&sc->ndis_mtx);
-
+ mutex_init(&sc->ndis_mtx, MUTEX_DEFAULT, IPL_NET);
+
/*
* Hook interrupt early, since calling the driver's
* init routine may trigger an interrupt. Note that
@@ -942,9 +944,11 @@
if (drv == NULL)
panic("couldn't find driver object");
windrv_destroy_pdo(drv, dev);
+
/*
* TODO: Unmap dma for NetBSD
*/
+ mutex_destroy(&sc->ndis_mtx);
return(0);
}
Index: src/sys/dev/if_ndis/if_ndisvar.h
diff -u src/sys/dev/if_ndis/if_ndisvar.h:1.6 src/sys/dev/if_ndis/if_ndisvar.h:1.7
--- src/sys/dev/if_ndis/if_ndisvar.h:1.6 Wed Feb 24 18:16:50 2010
+++ src/sys/dev/if_ndis/if_ndisvar.h Sat May 14 12:44:16 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: if_ndisvar.h,v 1.7 2011/05/14 12:44:16 rmind Exp $ */
+
/*-
* Copyright (c) 2003
* Bill Paul <[email protected]>. All rights reserved.
@@ -182,7 +184,7 @@
#ifdef __FreeBSD__
struct mtx ndis_mtx;
#else /* __NetBSD__ */
- struct simplelock ndis_mtx;
+ kmutex_t ndis_mtx;
#endif
device_t ndis_dev;
int ndis_unit;
@@ -228,19 +230,9 @@
int ndis_mmapcnt;
};
-#ifdef __FreeBSD__
-
#define NDIS_LOCK(_sc) mtx_lock(&(_sc)->ndis_mtx)
#define NDIS_UNLOCK(_sc) mtx_unlock(&(_sc)->ndis_mtx)
-#else /* __NetBSD__ */
-
-#define NDIS_LOCK(_sc) do {s = spl_sc(); simple_lock(&(_sc)->ndis_mtx);} while(0)
-#define NDIS_UNLOCK(_sc) do {simple_unlock(&(_sc)->ndis_mtx); splx(s);} while(0)
-#define spl_sc() splnet()
-
-#endif
-
/*static*/ __stdcall void ndis_txeof (ndis_handle, ndis_packet *, ndis_status);
/*static*/ __stdcall void ndis_rxeof (ndis_handle, ndis_packet **, uint32_t);
/*static*/ __stdcall void ndis_linksts (ndis_handle, ndis_status, void *, uint32_t);