summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>2004-01-04 07:47:33 +0000
committerwpaul <wpaul@FreeBSD.org>2004-01-04 07:47:33 +0000
commit1319a94ada775ef8892c13f3ef70a121fc3ea151 (patch)
treed0dec3fd350aeccfc77d7c786d7f5215c85bb205
parentdd492c4df012defddc6b4ba3d7d684430f23648b (diff)
downloadFreeBSD-src-1319a94ada775ef8892c13f3ef70a121fc3ea151.zip
FreeBSD-src-1319a94ada775ef8892c13f3ef70a121fc3ea151.tar.gz
Implement NdisScheduleWorkItem() and RtlCompareMemory().
Also, call the libinit and libfini routines from the modevent handler in kern_ndis.c. This simplifies the initialization a little.
-rw-r--r--sys/compat/ndis/kern_ndis.c16
-rw-r--r--sys/compat/ndis/ndis_var.h11
-rw-r--r--sys/compat/ndis/subr_ndis.c45
-rw-r--r--sys/compat/ndis/subr_ntoskrnl.c34
4 files changed, 73 insertions, 33 deletions
diff --git a/sys/compat/ndis/kern_ndis.c b/sys/compat/ndis/kern_ndis.c
index 80abdb3..02d107b 100644
--- a/sys/compat/ndis/kern_ndis.c
+++ b/sys/compat/ndis/kern_ndis.c
@@ -100,6 +100,11 @@ ndis_modevent(module_t mod, int cmd, void *arg)
switch (cmd) {
case MOD_LOAD:
+ /* Initialize subsystems */
+ ndis_libinit();
+ ntoskrnl_libinit();
+
+ /* Initialize TX buffer UMA zone. */
ndis_packet_zone = uma_zcreate("NDIS packet",
sizeof(ndis_packet), NULL, NULL, NULL,
NULL, UMA_ALIGN_PTR, 0);
@@ -109,6 +114,11 @@ ndis_modevent(module_t mod, int cmd, void *arg)
break;
case MOD_UNLOAD:
case MOD_SHUTDOWN:
+ /* Shut down subsystems */
+ ndis_libfini();
+ ntoskrnl_libfini();
+
+ /* Remove zones */
uma_zdestroy(ndis_packet_zone);
uma_zdestroy(ndis_buffer_zone);
break;
@@ -1077,8 +1087,6 @@ ndis_unload_driver(arg)
free(sc->ndis_block.nmb_rlist, M_DEVBUF);
ndis_flush_sysctls(sc);
- ndis_libfini();
- ntoskrnl_libfini();
return(0);
}
@@ -1119,10 +1127,6 @@ ndis_load_driver(img, arg)
return(ENOEXEC);
}
- /* Initialize subsystems */
- ndis_libinit();
- ntoskrnl_libinit();
-
/* Locate the driver entry point */
pe_get_optional_header(img, &opt_hdr);
entry = (driver_entry)pe_translate_addr(img, opt_hdr.ioh_entryaddr);
diff --git a/sys/compat/ndis/ndis_var.h b/sys/compat/ndis/ndis_var.h
index 868636e..9dc30a9 100644
--- a/sys/compat/ndis/ndis_var.h
+++ b/sys/compat/ndis/ndis_var.h
@@ -830,6 +830,17 @@ enum ndis_interrupt_mode {
typedef enum ndis_interrupt_mode ndis_interrupt_mode;
+struct ndis_work_item;
+
+typedef void (*ndis_proc)(struct ndis_work_item *, void *);
+
+struct ndis_work_item {
+ void *nwi_ctx;
+ ndis_proc nwi_func;
+ uint8_t nwi_wraprsvd[sizeof(void *) * 8];
+};
+
+typedef struct ndis_work_item ndis_work_item;
struct ndis_buffer {
struct ndis_buffer *nb_next;
diff --git a/sys/compat/ndis/subr_ndis.c b/sys/compat/ndis/subr_ndis.c
index 1109e09..03ab318 100644
--- a/sys/compat/ndis/subr_ndis.c
+++ b/sys/compat/ndis/subr_ndis.c
@@ -63,6 +63,8 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/timespec.h>
#include <sys/smp.h>
+#include <sys/queue.h>
+#include <sys/taskqueue.h>
#include <net/if.h>
#include <net/if_arp.h>
@@ -97,7 +99,6 @@ __FBSDID("$FreeBSD$");
#define FUNC void(*)(void)
static struct mtx ndis_interlock;
-static int ndis_inits = 0;
__stdcall static void ndis_initwrap(ndis_handle,
ndis_driver_object *, void *, void *);
@@ -251,6 +252,8 @@ __stdcall static u_int8_t ndis_cpu_cnt(void);
__stdcall static void ndis_ind_statusdone(ndis_handle);
__stdcall static void ndis_ind_status(ndis_handle, ndis_status,
void *, uint32_t);
+static void ndis_workfunc(void *, int);
+__stdcall static ndis_status ndis_sched_workitem(ndis_work_item *);
__stdcall static void dummy(void);
/*
@@ -266,29 +269,16 @@ __stdcall static void dummy(void);
int
ndis_libinit()
{
- if (ndis_inits) {
- ndis_inits++;
- return(0);
- }
-
mtx_init(&ndis_interlock, "ndislock", MTX_NETWORK_LOCK,
MTX_DEF | MTX_RECURSE | MTX_DUPOK);
- ndis_inits++;
return(0);
}
int
ndis_libfini()
{
- if (ndis_inits != 1) {
- ndis_inits--;
- return(0);
- }
-
mtx_destroy(&ndis_interlock);
- ndis_inits--;
-
return(0);
}
@@ -2389,6 +2379,32 @@ ndis_ind_status(adapter, status, sbuf, slen)
return;
}
+static void
+ndis_workfunc(ctx, pending)
+ void *ctx;
+ int pending;
+{
+ ndis_work_item *work;
+ __stdcall ndis_proc workfunc;
+
+ work = ctx;
+ workfunc = work->nwi_func;
+ workfunc(work, work->nwi_ctx);
+ return;
+}
+
+__stdcall static ndis_status
+ndis_sched_workitem(work)
+ ndis_work_item *work;
+{
+ struct task *t;
+
+ t = (struct task *)&work->nwi_wraprsvd;
+ TASK_INIT(t, 0, ndis_workfunc, work);
+ taskqueue_enqueue(taskqueue_swi, t);
+ return(NDIS_STATUS_SUCCESS);
+}
+
__stdcall static void
dummy()
{
@@ -2397,6 +2413,7 @@ dummy()
}
image_patch_table ndis_functbl[] = {
+ { "NdisScheduleWorkItem", (FUNC)ndis_sched_workitem },
{ "NdisMIndicateStatusComplete", (FUNC)ndis_ind_statusdone },
{ "NdisMIndicateStatus", (FUNC)ndis_ind_status },
{ "NdisSystemProcessorCount", (FUNC)ndis_cpu_cnt },
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c
index 55b1f1b..c5f3c31 100644
--- a/sys/compat/ndis/subr_ntoskrnl.c
+++ b/sys/compat/ndis/subr_ntoskrnl.c
@@ -114,35 +114,23 @@ __stdcall static void ntoskrnl_freemdl(ndis_buffer *);
__stdcall static void *ntoskrnl_mmaplockedpages(ndis_buffer *, uint8_t);
__stdcall static void ntoskrnl_create_lock(kspin_lock *);
__stdcall static void dummy(void);
+__stdcall static size_t ntoskrnl_memcmp(const void *, const void *, size_t);
static struct mtx ntoskrnl_interlock;
-static int ntoskrnl_inits = 0;
int
ntoskrnl_libinit()
{
- if (ntoskrnl_inits) {
- ntoskrnl_inits++;
- return(0);
- }
-
mtx_init(&ntoskrnl_interlock, "ntoskrnllock", MTX_NETWORK_LOCK,
MTX_DEF | MTX_RECURSE);
- ntoskrnl_inits++;
return(0);
}
int
ntoskrnl_libfini()
{
- if (ntoskrnl_inits != 1) {
- ntoskrnl_inits--;
- return(0);
- }
-
mtx_destroy(&ntoskrnl_interlock);
- ntoskrnl_inits--;
return(0);
}
@@ -652,6 +640,25 @@ ntoskrnl_create_lock(lock)
return;
}
+__stdcall static size_t
+ntoskrnl_memcmp(s1, s2, len)
+ const void *s1;
+ const void *s2;
+ size_t len;
+{
+ size_t i, total = 0;
+ uint8_t *m1, *m2;
+
+ m1 = __DECONST(char *, s1);
+ m2 = __DECONST(char *, s2);
+
+ for (i = 0; i < len; i++) {
+ if (m1[i] == m2[i])
+ total++;
+ }
+ return(total);
+}
+
__stdcall static void
dummy()
{
@@ -661,6 +668,7 @@ dummy()
image_patch_table ntoskrnl_functbl[] = {
+ { "RtlCompareMemory", (FUNC)ntoskrnl_memcmp },
{ "RtlEqualUnicodeString", (FUNC)ntoskrnl_unicode_equal },
{ "RtlCopyUnicodeString", (FUNC)ntoskrnl_unicode_copy },
{ "RtlUnicodeStringToAnsiString", (FUNC)ntoskrnl_unicode_to_ansi },
OpenPOWER on IntegriCloud