Updated to the latest NDIS code. I added commented out lines in the files

arch/i386/conf/GENERIC, arch/i386/conf/files.i386 and dev/pci/files.pci which
can simply be uncommented to compile NDIS into the kernel.  I'll write some
documentation on this soon.

Note that NDIS is still somewhat experimental.  It is currently tested and
functions relatively well on on two cards:
1. Dell (Broadcom) TrueMobile 1400 Dual Band WLAN Mini-PCI
2. Intel EtherExpress Pro/100
This commit is contained in:
rittera 2006-03-31 00:03:57 +00:00
parent 6f0360f3e9
commit ace2baad8b
17 changed files with 2744 additions and 291 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: GENERIC,v 1.737 2006/03/28 20:58:40 pavel Exp $
# $NetBSD: GENERIC,v 1.738 2006/03/31 00:03:57 rittera Exp $
#
# GENERIC machine description file
#
@ -22,7 +22,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
#ident "GENERIC-$Revision: 1.737 $"
#ident "GENERIC-$Revision: 1.738 $"
maxusers 32 # estimated number of users
@ -146,6 +146,8 @@ options COMPAT_FREEBSD # binary compatibility with FreeBSD
#options COMPAT_MACH # binary compatibility with Mach binaries
#options COMPAT_DARWIN # binary compatibility with Darwin binaries
#options EXEC_MACHO # exec MACH-O binaries
#options COMPAT_NDIS # NDIS network driver
#makeoptions CFLAGS+="-DNDIS_DRV_DATA=\"ndis_data\""
#options COMPAT_PECOFF # kernel support to run Win32 apps
options COMPAT_BSDPTY # /dev/[pt]ty?? ptys.
@ -820,6 +822,7 @@ iwi* at pci? dev ? function ? # Intel PRO/Wireless 2200BG
le* at pci? dev ? function ? # PCnet-PCI Ethernet
lmc* at pci? dev ? function ? # Lan Media Corp SSI/HSSI/DS3
mtd* at pci? dev ? function ? # Myson MTD803 3-in-1 Ethernet
#ndis* at pci? dev ? function ? # Experimental - NDIS Network Driver
ne* at pci? dev ? function ? # NE2000-compatible Ethernet
nfe* at pci? dev ? function ? # NVIDIA nForce Ethernet
ntwoc* at pci? dev ? function ? # Riscom/N2 PCI Sync Serial

View File

@ -1,4 +1,4 @@
# $NetBSD: files.i386,v 1.283 2006/03/17 12:19:49 jmcneill Exp $
# $NetBSD: files.i386,v 1.284 2006/03/31 00:03:57 rittera Exp $
#
# new style config file for i386 architecture
#
@ -383,6 +383,9 @@ file arch/i386/i386/freebsd_machdep.c compat_freebsd
file arch/i386/i386/freebsd_sigcode.S compat_freebsd
file arch/i386/i386/freebsd_syscall.c compat_freebsd
# NDIS compatibilty (COMPAT_NDIS)
# include "compat/ndis/files.ndis"
# Win32 binary compatibility (COMPAT_PECOFF)
include "compat/pecoff/files.pecoff"

View File

@ -36,8 +36,8 @@
#define _CFG_VAR_H_
struct ndis_cfg {
char *nc_cfgkey;
char *nc_cfgdesc;
const char *nc_cfgkey;
const char *nc_cfgdesc;
char nc_val[256];
int nc_idx;
};

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,12 @@
*/
#include <sys/cdefs.h>
#ifdef __FreeBSD__
__FBSDID("$FreeBSD: src/sys/compat/ndis/kern_windrv.c,v 1.3.2.2 2005/03/31 04:24:35 wpaul Exp $");
#endif
#ifdef __NetBSD__
__KERNEL_RCSID(0, "$NetBSD: kern_windrv.c,v 1.2 2006/03/31 00:03:57 rittera Exp $");
#endif
#include <sys/param.h>
#include <sys/systm.h>
@ -41,11 +46,15 @@ __FBSDID("$FreeBSD: src/sys/compat/ndis/kern_windrv.c,v 1.3.2.2 2005/03/31 04:24
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#ifdef __FreeBSD__
#include <sys/mutex.h>
#include <sys/module.h>
#endif /* __FreeBSD__ */
#include <sys/conf.h>
#include <sys/mbuf.h>
#ifdef __FreeBSD__
#include <sys/bus.h>
#endif
#include <sys/queue.h>
@ -133,11 +142,14 @@ windrv_libfini(void)
driver_object *
windrv_lookup(img, name)
vm_offset_t img;
char *name;
const char *name;
{
struct drvdb_ent *d;
unicode_string us;
printf("In windrv_lookup():\n");
printf("name = %s\n", name);
/* Damn unicode. */
if (name != NULL) {
@ -145,14 +157,25 @@ windrv_lookup(img, name)
us.us_maxlen = strlen(name) * 2;
us.us_buf = NULL;
ndis_ascii_to_unicode(name, &us.us_buf);
} else {
us.us_len = 0;
us.us_maxlen = 0;
us.us_buf = NULL;
}
mtx_lock(&drvdb_mtx);
STAILQ_FOREACH(d, &drvdb_head, link) {
if (d->windrv_object->dro_driverstart == (void *)img ||
bcmp((char *)d->windrv_object->dro_drivername.us_buf,
(char *)us.us_buf, us.us_len) == 0) {
mtx_unlock(&drvdb_mtx);
#ifdef NDIS_LKM
printf("d->windrv_object->dro_driverstart = %x\n", d->windrv_object->dro_driverstart);
#endif
if (d->windrv_object->dro_driverstart == (void *)img ||
(bcmp((char *)d->windrv_object->dro_drivername.us_buf,
(char *)us.us_buf, us.us_len) == 0 && us.us_len > 0)) {
mtx_unlock(&drvdb_mtx);
printf("found driver object!\n");
#ifdef NDIS_LKM
printf("returning %x\n", d->windrv_object);
#endif
return(d->windrv_object);
}
}
@ -161,6 +184,7 @@ windrv_lookup(img, name)
if (name != NULL)
ExFreePool(us.us_buf);
printf("no driver object\n");
return(NULL);
}
@ -237,34 +261,48 @@ windrv_load(mod, img, len)
struct driver_object *drv;
int status;
#ifdef NDIS_LKM
printf("in windrv_load\n");
printf("img = %x\n", img);
#endif
/*
* First step: try to relocate and dynalink the executable
* driver image.
*/
/* Perform text relocation */
if (pe_relocate(img))
if (pe_relocate(img)) {
return(ENOEXEC);
}
/* Dynamically link the NDIS.SYS routines -- required. */
if (pe_patch_imports(img, "NDIS", ndis_functbl))
if (pe_patch_imports(img, "NDIS", ndis_functbl)) {
return(ENOEXEC);
}
/* Dynamically link the HAL.dll routines -- also required. */
if (pe_patch_imports(img, "HAL", hal_functbl))
if (pe_patch_imports(img, "HAL", hal_functbl)) {
return(ENOEXEC);
}
/* Dynamically link ntoskrnl.exe -- optional. */
if (pe_get_import_descriptor(img, &imp_desc, "ntoskrnl") == 0) {
if (pe_patch_imports(img, "ntoskrnl", ntoskrnl_functbl))
if (pe_patch_imports(img, "ntoskrnl", ntoskrnl_functbl))
return(ENOEXEC);
}
/* Dynamically link USBD.SYS -- optional */
if (pe_get_import_descriptor(img, &imp_desc, "USBD") == 0) {
if (pe_patch_imports(img, "USBD", usbd_functbl))
#if ubsimplemented
if (pe_patch_imports(img, "USBD", usbd_functbl)) {
return(ENOEXEC);
}
}
#else
//printf("windrv_load: pe_get_import_descriptor USBD failed");
return(ENOEXEC);
#endif
}
/* Next step: find the driver entry point. */
@ -386,7 +424,12 @@ windrv_find_pdo(drv, bsddev)
device_t bsddev;
{
device_object *pdo;
#ifdef NDIS_LKM
printf("In windrv_find_pdo: \ndrv = %x", drv);
printf("\nbsddev = %x", bsddev);
printf("\npdo = %x", drv->dro_devobj);
printf("\npdo->do_devext = %x\n", drv->dro_devobj->do_devext);
#endif
mtx_lock(&drvdb_mtx);
pdo = drv->dro_devobj;
if (pdo->do_devext != bsddev) {
@ -406,7 +449,7 @@ windrv_find_pdo(drv, bsddev)
int
windrv_bus_attach(drv, name)
driver_object *drv;
char *name;
const char *name;
{
struct drvdb_ent *new;
@ -418,6 +461,14 @@ windrv_bus_attach(drv, name)
drv->dro_drivername.us_maxlen = strlen(name) * 2;
drv->dro_drivername.us_buf = NULL;
ndis_ascii_to_unicode(name, &drv->dro_drivername.us_buf);
#ifdef __NetBSD__
/* I added this because windrv_lookup was getting
* fake_pccard_driver and fake_pci_driver mixed up.
* I'm not sure if it will mess anything else up.
*/
drv->dro_driverstart = drv;
#endif
new->windrv_object = drv;
new->windrv_devlist = NULL;

View File

@ -1557,7 +1557,7 @@ extern image_patch_table ndis_functbl[];
__BEGIN_DECLS
extern int ndis_libinit(void);
extern int ndis_libfini(void);
extern int ndis_ascii_to_unicode(char *, uint16_t **);
extern int ndis_ascii_to_unicode(const char *, uint16_t **);
extern int ndis_unicode_to_ascii(uint16_t *, int, char **);
extern int ndis_load_driver(vm_offset_t, void *);
extern int ndis_unload_driver(void *);
@ -1578,17 +1578,25 @@ extern int ndis_halt_nic(void *);
extern int ndis_shutdown_nic(void *);
extern int ndis_init_nic(void *);
extern int ndis_isr(void *, int *, int *);
#ifdef __FreeBSD__
extern void ndis_return_packet(void *, void *);
#else
extern void ndis_return_packet(struct mbuf *, caddr_t, size_t, void *);
#endif
extern void ndis_enable_intr(void *);
extern void ndis_disable_intr(void *);
extern int ndis_init_dma(void *);
extern int ndis_destroy_dma(void *);
extern int ndis_create_sysctls(void *);
extern int ndis_add_sysctl(void *, char *, char *, char *, int);
extern int ndis_add_sysctl(void *, const char *, const char *, const char *, int);
extern int ndis_flush_sysctls(void *);
extern int ndis_sched(void (*)(void *), void *, int);
extern int ndis_unsched(void (*)(void *), void *, int);
#ifdef __FreeBSD__
extern int ndis_thsuspend(struct proc *, struct mtx *, int);
#else /* __NetBSD__ */
extern int ndis_thsuspend(struct proc *, struct simplelock *, int);
#endif
extern void ndis_thresume(struct proc *);
extern int ndis_strcasecmp(const char *, const char *);
extern int ndis_strncasecmp(const char *, const char *, size_t);

View File

@ -299,8 +299,20 @@ typedef struct nt_dispatch_header nt_dispatch_header;
#define AT_DISPATCH_LEVEL(td) \
((td)->td_base_pri == PI_REALTIME)
#else
/* TODO: What is the best way to do this? */
int win_irql;
#define AT_DISPATCH_LEVEL(useless) \
(win_irql == DISPATCH_LEVEL)
/*
#define AT_DISPATCH_LEVEL(useless) \
curlwp->l_priority == 0
curlwp->l_priority > IPL_NONE
#define AT_DISPATCH_LEVEL(useless) \
TRUE
*/
#endif
#define AT_DIRQL_LEVEL(td) \
@ -342,8 +354,8 @@ struct ktimer {
list_entry k_timerlistentry;
#ifdef __FreeBSD__
struct callout_handle k_handle;
#else
struct callout k_handle;
#else /* __NetBSD__ */
struct callout *k_handle;
#endif
} u;
void *k_dpc;
@ -581,6 +593,10 @@ struct device_object {
uint16_t do_spare1;
struct devobj_extension *do_devobj_ext;
void *do_rsvd;
#ifdef __NetBSD__
struct ndis_softc *fdo_sc;
struct ndis_softc *pdo_sc;
#endif
};
typedef struct device_object device_object;
@ -1164,6 +1180,7 @@ typedef struct driver_object driver_object;
* Windows stack is larger, so we need to give our threads more
* stack pages. 4 should be enough, we use 8 just to extra safe.
*/
/* This is also defined in nbcompat.c */
#define NDIS_KSTACK_PAGES 8
extern image_patch_table ntoskrnl_functbl[];
@ -1172,13 +1189,13 @@ typedef void (*funcptr)(void);
__BEGIN_DECLS
extern int windrv_libinit(void);
extern int windrv_libfini(void);
extern driver_object *windrv_lookup(vm_offset_t, char *);
extern driver_object *windrv_lookup(vm_offset_t, const char *);
extern int windrv_load(module_t, vm_offset_t, int);
extern int windrv_unload(module_t, vm_offset_t, int);
extern int windrv_create_pdo(driver_object *, device_t);
extern void windrv_destroy_pdo(driver_object *, device_t);
extern device_object *windrv_find_pdo(driver_object *, device_t);
extern int windrv_bus_attach(driver_object *, char *);
extern int windrv_bus_attach(driver_object *, const char *);
extern int windrv_wrap(funcptr, funcptr *);
extern int windrv_unwrap(funcptr);

View File

@ -408,9 +408,9 @@ typedef struct message_resource_entry message_resource_entry;
#define MESSAGE_RESOURCE_UNICODE 0x0001
struct image_patch_table {
char *ipt_name;
void (*ipt_func)(void);
void (*ipt_wrap)(void);
const char *ipt_name;
void (*ipt_func)(void);
void (*ipt_wrap)(void);
};
typedef struct image_patch_table image_patch_table;
@ -568,8 +568,8 @@ extern vm_offset_t pe_directory_offset(vm_offset_t, uint32_t);
extern vm_offset_t pe_translate_addr (vm_offset_t, vm_offset_t);
extern int pe_get_section(vm_offset_t, image_section_header *, const char *);
extern int pe_relocate(vm_offset_t);
extern int pe_get_import_descriptor(vm_offset_t, image_import_descriptor *, char *);
extern int pe_patch_imports(vm_offset_t, char *, image_patch_table *);
extern int pe_get_import_descriptor(vm_offset_t, image_import_descriptor *, const char *);
extern int pe_patch_imports(vm_offset_t, const char *, image_patch_table *);
extern int pe_get_messagetable(vm_offset_t, message_resource_data **);
extern int pe_get_message(vm_offset_t, uint32_t, char **, int *, uint16_t *);
__END_DECLS

View File

@ -35,7 +35,7 @@
__FBSDID("$FreeBSD: src/sys/compat/ndis/subr_hal.c,v 1.13.2.3 2005/03/31 04:24:35 wpaul Exp $");
#endif
#ifdef __NetBSD__
__KERNEL_RCSID(0, "$NetBSD: subr_hal.c,v 1.2 2006/03/30 23:06:56 rittera Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_hal.c,v 1.3 2006/03/31 00:03:57 rittera Exp $");
#endif
#include <sys/param.h>
@ -344,13 +344,17 @@ KeQueryPerformanceCounter(freq)
return((uint64_t)ticks);
}
static int old_ipl;
static int ipl_raised = FALSE;
__fastcall uint8_t
KfRaiseIrql(REGARGS1(uint8_t irql))
{
uint8_t oldirql;
#ifdef __NetBSD__
uint8_t s;
#endif
uint8_t oldirql = 0;
//#ifdef __NetBSD__
// uint8_t s;
//#endif
if (irql < KeGetCurrentIrql())
panic("IRQL_NOT_LESS_THAN");
@ -358,10 +362,13 @@ KfRaiseIrql(REGARGS1(uint8_t irql))
if (KeGetCurrentIrql() == DISPATCH_LEVEL)
return(DISPATCH_LEVEL);
#ifdef __NetBSD__
SCHED_LOCK(s);
oldirql = curlwp->l_priority;
SCHED_UNLOCK(s);
#else
if(irql >= DISPATCH_LEVEL && !ipl_raised) {
old_ipl = splsoftclock();
ipl_raised = TRUE;
oldirql = win_irql;
win_irql = irql;
}
#else /* __FreeBSD__ */
mtx_lock_spin(&sched_lock);
oldirql = curthread->td_base_pri;
sched_prio(curthread, PI_REALTIME);
@ -369,7 +376,7 @@ KfRaiseIrql(REGARGS1(uint8_t irql))
curthread->td_base_pri = PI_REALTIME;
#endif
mtx_unlock_spin(&sched_lock);
#endif /* __NetBSD__ */
#endif /* __FreeBSD__ */
return(oldirql);
}
@ -377,20 +384,27 @@ KfRaiseIrql(REGARGS1(uint8_t irql))
__fastcall void
KfLowerIrql(REGARGS1(uint8_t oldirql))
{
#ifdef __NetBSD__
uint8_t s;
#endif
//#ifdef __NetBSD__
// uint8_t s;
//#endif
if (oldirql == DISPATCH_LEVEL)
return;
#ifdef __FreeBSD__
if (KeGetCurrentIrql() != DISPATCH_LEVEL)
panic("IRQL_NOT_GREATER_THAN");
#else /* __NetBSD__ */
if (KeGetCurrentIrql() < oldirql)
panic("IRQL_NOT_GREATER_THAN");
#endif
#ifdef __NetBSD__
SCHED_LOCK(s);
curlwp->l_priority = oldirql;
SCHED_UNLOCK(s);
if(oldirql < DISPATCH_LEVEL && ipl_raised) {
splx(old_ipl);
ipl_raised = FALSE;
win_irql = oldirql;
}
#else
mtx_lock_spin(&sched_lock);
#if __FreeBSD_version < 600000

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,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.2 2006/03/30 23:06:56 rittera Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_ntoskrnl.c,v 1.3 2006/03/31 00:03:57 rittera Exp $");
#endif
#ifdef __FreeBSD__
@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_ntoskrnl.c,v 1.2 2006/03/30 23:06:56 rittera Ex
#include <sys/module.h>
#else
#include <sys/lkm.h>
#include <sys/callout.h>
#endif
#include <machine/atomic.h>
@ -97,9 +98,17 @@ __KERNEL_RCSID(0, "$NetBSD: subr_ntoskrnl.c,v 1.2 2006/03/30 23:06:56 rittera Ex
#include <compat/ndis/hal_var.h>
#include <compat/ndis/resource_var.h>
#include <compat/ndis/ndis_var.h>
#ifdef __NetBSD__
#include <compat/ndis/nbcompat.h>
#endif
#define __regparm __attribute__((regparm(3)))
#ifdef __NetBSD__
/* Turn on DbgPrint() from Windows Driver*/
#define boothowto AB_VERBOSE
#endif
__stdcall static uint8_t RtlEqualUnicodeString(ndis_unicode_string *,
ndis_unicode_string *, uint8_t);
__stdcall static void RtlCopyUnicodeString(ndis_unicode_string *,
@ -210,7 +219,14 @@ static uint32_t DbgPrint(char *, ...);
__stdcall static void DbgBreakPoint(void);
__stdcall static void dummy(void);
#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)
#endif
static kspin_lock ntoskrnl_global;
static kspin_lock ntoskrnl_cancellock;
static int ntoskrnl_kth = 0;
@ -225,9 +241,12 @@ int
ntoskrnl_libinit()
{
image_patch_table *patch;
#ifdef __FreeBSD__
mtx_init(&ntoskrnl_dispatchlock,
"ntoskrnl dispatch lock", MTX_NDIS_LOCK, MTX_DEF);
#else /* __NetBSD__ */
simple_lock_init(&ntoskrnl_dispatchlock);
#endif
KeInitializeSpinLock(&ntoskrnl_global);
KeInitializeSpinLock(&ntoskrnl_cancellock);
TAILQ_INIT(&ntoskrnl_reflist);
@ -440,14 +459,17 @@ IoGetDriverObjectExtension(drv, clid)
list_entry *e;
custom_extension *ce;
printf("in IoGetDriverObjectExtension\n");
e = drv->dro_driverext->dre_usrext.nle_flink;
while (e != &drv->dro_driverext->dre_usrext) {
ce = (custom_extension *)e;
if (ce->ce_clid == clid)
printf("found\n");
return((void *)(ce + 1));
e = e->nle_flink;
}
printf("not found\n");
return(NULL);
}
@ -463,8 +485,15 @@ IoCreateDevice(drv, devextlen, devname, devtype, devchars, exclusive, newdev)
device_object **newdev;
{
device_object *dev;
#ifdef NDIS_LKM
printf("In IoCreateDevice: drv = %x, devextlen = %x\n", drv, devextlen);
#endif
dev = ExAllocatePoolWithTag(NonPagedPool, sizeof(device_object), 0);
#ifdef NDIS_LKM
printf("dev = %x\n", dev);
#endif
if (dev == NULL)
return(STATUS_INSUFFICIENT_RESOURCES);
@ -795,17 +824,30 @@ IoMakeAssociatedIrp(ip, stsize)
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);
}
@ -988,13 +1030,26 @@ IoAttachDeviceToDeviceStack(src, dst)
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);
}
@ -1004,13 +1059,24 @@ IoDetachDevice(topdev)
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;
@ -1024,7 +1090,11 @@ IoDetachDevice(topdev)
tail = tail->do_attacheddev;
}
#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
#else /* __NetBSD__ */
DISPATCH_UNLOCK();
#endif
return;
}
@ -1047,6 +1117,7 @@ ntoskrnl_wakeup(arg)
e = obj->dh_waitlisthead.nle_flink;
while (e != &obj->dh_waitlisthead) {
w = (wait_block *)e;
/* TODO: is this correct? */
#ifdef __FreeBSD__
td = w->wb_kthread;
ndis_thresume(td->td_proc);
@ -1070,8 +1141,14 @@ ntoskrnl_time(tval)
uint64_t *tval;
{
struct timespec ts;
#ifdef __NetBSD__
struct timeval tv;
microtime(&tv);
TIMEVAL_TO_TIMESPEC(&tv,&ts);
#else
nanotime(&ts);
#endif
nanotime(&ts);
*tval = (uint64_t)ts.tv_nsec / 100 + (uint64_t)ts.tv_sec * 10000000 +
(uint64_t)11644473600ULL;
@ -1146,11 +1223,18 @@ KeWaitForSingleObject(obj, reason, mode, alertable, duetime)
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
@ -1177,13 +1261,23 @@ KeWaitForSingleObject(obj, reason, mode, alertable, duetime)
#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);
}
@ -1232,7 +1326,11 @@ KeWaitForSingleObject(obj, reason, mode, alertable, duetime)
if (error == EWOULDBLOCK) {
REMOVE_LIST_ENTRY((&w.wb_waitlist));
#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
#else /* __NetBSD__ */
DISPATCH_UNLOCK();
#endif
return(STATUS_TIMEOUT);
}
@ -1258,8 +1356,12 @@ KeWaitForSingleObject(obj, reason, mode, alertable, duetime)
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);
}
@ -1286,13 +1388,22 @@ KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode,
int i, wcnt = 0, widx = 0, error = 0;
uint64_t curtime;
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];
@ -1318,7 +1429,11 @@ KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode,
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);
}
}
@ -1326,7 +1441,11 @@ KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode,
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);
}
}
@ -1367,7 +1486,12 @@ KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode,
}
while (wcnt) {
nanotime(&t1);
#ifdef __FreeBSD__
nanotime(&t1);
#else
microtime(&tv1);
TIMEVAL_TO_TIMESPEC(&tv1,&t1);
#endif
#ifdef __FreeBSD__
error = ndis_thsuspend(td->td_proc, &ntoskrnl_dispatchlock,
@ -1376,7 +1500,12 @@ KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode,
error = ndis_thsuspend(curproc, &ntoskrnl_dispatchlock,
duetime == NULL ? 0 : tvtohz(&tv));
#endif
nanotime(&t2);
#ifdef __FreeBSD__
nanotime(&t2);
#else
microtime(&tv2);
TIMEVAL_TO_TIMESPEC(&tv2,&t2);
#endif
for (i = 0; i < cnt; i++) {
if (obj[i]->dh_size == OTYPE_MUTEX) {
@ -1415,16 +1544,28 @@ KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode,
}
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);
}
@ -1797,6 +1938,11 @@ ExQueryDepthSList(head)
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
@ -1808,7 +1954,11 @@ __stdcall void
KeInitializeSpinLock(lock)
kspin_lock *lock;
{
#ifdef __FreeBSD__
*lock = 0;
#else /* __NetBSD__ */
simple_lock_init((struct simplelock *)lock);
#endif
return;
}
@ -1817,8 +1967,12 @@ KeInitializeSpinLock(lock)
__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;
}
@ -1826,8 +1980,11 @@ KefAcquireSpinLockAtDpcLevel(REGARGS1(kspin_lock *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;
}
@ -2195,16 +2352,45 @@ static int
atoi(str)
const char *str;
{
#ifdef __FreeBSD__
return (int)strtol(str, (char **)NULL, 10);
#else
int n;
for (n = 0; *str && *str >= '0' && *str <= '9'; str++)
n = n * 10 + *str - '0';
return n;
#endif
}
static long
atol(str)
const char *str;
{
#ifdef __FreeBSD__
return strtol(str, (char **)NULL, 10);
#else
long n;
for (n = 0; *str && *str >= '0' && *str <= '9'; str++)
n = n * 10 + *str - '0';
return n;
#endif
}
/*
* stolen from ./netipsec/key.c
*/
#ifdef __NetBSD__
void srandom(int arg);
void srandom(int arg) {return;}
#endif
static int
rand(void)
{
@ -2281,13 +2467,26 @@ KeReleaseMutex(kmutex, kwait)
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--;
@ -2295,7 +2494,12 @@ KeReleaseMutex(kmutex, kwait)
kmutex->km_ownerthread = NULL;
ntoskrnl_wakeup(&kmutex->km_header);
}
#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
#else /* __NetBSD__ */
DISPATCH_UNLOCK();
#endif
return(kmutex->km_acquirecnt);
}
@ -2325,11 +2529,24 @@ KeResetEvent(kevent)
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);
}
@ -2341,11 +2558,24 @@ KeSetEvent(kevent, increment, kwait)
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);
}
@ -2461,7 +2691,8 @@ PsCreateSystemThread(handle, reqaccess, objattrs, phandle,
error = kthread_create(ntoskrnl_thrfunc, tc, &p,
RFHIGHPID, NDIS_KSTACK_PAGES, tname);
#else
error = kthread_create1(ntoskrnl_thrfunc, tc, &p, tname);
/* TODO: Provide a larger stack for these threads (NDIS_KSTACK_PAGES) */
error = ndis_kthread_create(ntoskrnl_thrfunc, tc, &p, NULL, 0, tname);
#endif
*handle = p;
@ -2483,8 +2714,16 @@ PsTerminateSystemThread(status)
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)
@ -2495,7 +2734,12 @@ PsTerminateSystemThread(status)
ntoskrnl_wakeup(&nr->no_dh);
break;
}
#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
#else /* __NetBSD__ */
DISPATCH_UNLOCK();
#endif
ntoskrnl_kth--;
@ -2511,11 +2755,11 @@ PsTerminateSystemThread(status)
static uint32_t
DbgPrint(char *fmt, ...)
{
va_list ap;
//va_list ap;
if (bootverbose) {
va_start(ap, fmt);
vprintf(fmt, ap);
//va_start(ap, fmt);
//vprintf(fmt, ap);
}
return(STATUS_SUCCESS);
@ -2524,11 +2768,12 @@ DbgPrint(char *fmt, ...)
__stdcall static void
DbgBreakPoint(void)
{
#if __FreeBSD_version < 502113
#if defined(__FreeBSD__) && __FreeBSD_version < 502113
Debugger("DbgBreakPoint(): breakpoint");
#else
#elif defined(__FreeBSD__) && __FreeBSD_version >= 502113
kdb_enter("DbgBreakPoint(): breakpoint");
#else /* Netbsd case */
; /* TODO Search how to go into debugger without panic */
#endif
}
@ -2538,12 +2783,19 @@ ntoskrnl_timercall(arg)
{
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;
@ -2565,16 +2817,21 @@ ntoskrnl_timercall(arg)
#ifdef __FreeBSD__
timer->k_handle = timeout(ntoskrnl_timercall,
timer, tvtohz(&tv));
#else
timeout(ntoskrnl_timercall, timer, tvtohz(&tv));
#endif
#else /* __NetBSD__ */
callout_reset(timer->k_handle, tvtohz(&tv), ntoskrnl_timercall, timer);
#endif /* __NetBSD__ */
}
if (timer->k_dpc != NULL)
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);
@ -2611,7 +2868,7 @@ KeInitializeTimerEx(timer, type)
#ifdef __FreeBSD__
callout_handle_init(&timer->k_handle);
#else
callout_init(&timer->k_handle);
callout_init(timer->k_handle);
#endif
return;
@ -2692,14 +2949,25 @@ KeSetTimerEx(timer, duetime, period, dpc)
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);
#else /* __NetBSD__ */
callout_stop(timer->k_handle);
#endif
timer->k_header.dh_inserted = FALSE;
pending = TRUE;
} else
@ -2729,10 +2997,14 @@ KeSetTimerEx(timer, duetime, period, dpc)
#ifdef __FreeBSD__
timer->k_handle = timeout(ntoskrnl_timercall, timer, tvtohz(&tv));
#else
timeout(ntoskrnl_timercall, timer, tvtohz(&tv));
callout_reset(timer->k_handle, tvtohz(&tv), ntoskrnl_timercall, timer);
#endif
#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
#else /* __NetBSD__ */
DISPATCH_UNLOCK();
#endif
return(pending);
}
@ -2751,19 +3023,34 @@ KeCancelTimer(timer)
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__
untimeout(ntoskrnl_timercall, timer, timer->k_handle);
#else /* __NetBSD__ */
callout_stop(timer->k_handle);
#endif
pending = TRUE;
} else
pending = KeRemoveQueueDpc(timer->k_dpc);
#ifdef __FreeBSD__
mtx_unlock(&ntoskrnl_dispatchlock);
#else /* __NetBSD__ */
DISPATCH_UNLOCK();
#endif
return(pending);
}

View File

@ -35,7 +35,7 @@
__FBSDID("$FreeBSD: src/sys/compat/ndis/subr_pe.c,v 1.7.2.3 2005/03/31 04:24:36 wpaul Exp $");
#endif
#ifdef __NetBSD__
__KERNEL_RCSID(0, "$NetBSD: subr_pe.c,v 1.2 2006/03/30 23:06:56 rittera Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_pe.c,v 1.3 2006/03/31 00:03:57 rittera Exp $");
#endif
@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_pe.c,v 1.2 2006/03/30 23:06:56 rittera Exp $");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/lock.h>
#ifdef _KERNEL
#include <sys/systm.h>
extern int ndis_strncasecmp(const char *, const char *, size_t);
@ -447,7 +448,7 @@ int
pe_get_import_descriptor(imgbase, desc, module)
vm_offset_t imgbase;
image_import_descriptor *desc;
char *module;
const char *module;
{
vm_offset_t offset;
image_import_descriptor *imp_desc;
@ -608,7 +609,7 @@ pe_functbl_match(functbl, name)
int
pe_patch_imports(imgbase, module, functbl)
vm_offset_t imgbase;
char *module;
const char *module;
image_patch_table *functbl;
{
image_import_descriptor imp_desc;

View File

@ -31,7 +31,12 @@
*/
#include <sys/cdefs.h>
#ifdef __FreeBSD__
__FBSDID("$FreeBSD: src/sys/compat/ndis/subr_usbd.c,v 1.1.2.1 2005/03/31 04:24:36 wpaul Exp $");
#endif
#ifdef __NetBSD__
__KERNEL_RCSID(0, "$NetBSD");
#endif
#include <sys/param.h>
#include <sys/systm.h>
@ -41,11 +46,15 @@ __FBSDID("$FreeBSD: src/sys/compat/ndis/subr_usbd.c,v 1.1.2.1 2005/03/31 04:24:3
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#ifdef __FreeBSD__
#include <sys/mutex.h>
#include <sys/module.h>
#endif
#include <sys/conf.h>
#include <sys/mbuf.h>
#ifdef __FreeBSD__
#include <sys/bus.h>
#endif
#include <sys/queue.h>

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,11 @@ __FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pci.c,v 1.8.2.3 2005/03/31 04:24
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#ifdef __FreeBSD__
#include <sys/module.h>
#else
#include <sys/lkm.h>
#endif
#include <sys/socket.h>
#include <sys/queue.h>
#include <sys/sysctl.h>
@ -46,9 +50,16 @@ __FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pci.c,v 1.8.2.3 2005/03/31 04:24
#include <net/if_media.h>
#include <machine/bus.h>
#ifdef __FreeBSD__
#include <machine/resource.h>
#include <sys/bus.h>
#include <sys/rman.h>
#endif
#ifdef __NetBSD__
#include <sys/kthread.h>
#include <net/if_ether.h>
#endif
#include <net80211/ieee80211_var.h>
@ -62,14 +73,26 @@ __FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pci.c,v 1.8.2.3 2005/03/31 04:24
#include <compat/ndis/cfg_var.h>
#include <dev/if_ndis/if_ndisvar.h>
#ifdef NDIS_LKM
#include "ndis_driver_data.h"
#else
#include <modules/if_ndis/ndis_driver_data.h>
#endif /* NDIS_LKM */
#ifdef __NetBSD__
#ifndef NDIS_LKM
#include <compat/ndis/hal_var.h>
#endif
#endif /* __NetBSD__ */
#ifdef NDIS_PCI_DEV_TABLE
#ifdef __FreeBSD
MODULE_DEPEND(ndis, pci, 1, 1, 1);
MODULE_DEPEND(ndis, ether, 1, 1, 1);
MODULE_DEPEND(ndis, wlan, 1, 1, 1);
MODULE_DEPEND(ndis, ndisapi, 1, 1, 1);
#endif
/*
* Various supported device vendors/types and their names.
@ -82,19 +105,51 @@ static struct ndis_pci_type ndis_devs[] = {
{ 0, 0, 0, NULL }
};
#ifdef __FreeBSD__
static int ndis_probe_pci (device_t);
static int ndis_attach_pci (device_t);
#else /* __NetBSD__ */
/*static*/ int ndis_probe_pci(struct device *parent,
struct cfdata *match,
void *aux);
/*static*/ void ndis_attach_pci(struct device *parent,
struct device *self,
void *aux);
#endif
#ifdef __FreeBSD__
static struct resource_list *ndis_get_resource_list
(device_t, device_t);
extern int ndisdrv_modevent (module_t, int, void *);
#endif
#ifdef __FreeBSD__
extern int ndis_attach (device_t);
#else /* __NetBSD__ */
extern void ndis_attach (void *);
#endif
extern int ndis_shutdown (device_t);
#ifdef __FreeBSD__
extern int ndis_detach (device_t);
#else /* __NetBSD__ */
extern int ndis_detach (device_t, int);
#endif
extern int ndis_suspend (device_t);
extern int ndis_resume (device_t);
#ifdef __NetBSD__
extern void device_printf(device_t, const char *fmt, ...);
extern int ndis_intr(void *);
#endif
extern unsigned char drv_data[];
#ifndef NDIS_LKM
//static funcptr ndis_txeof_wrap;
//static funcptr ndis_rxeof_wrap;
//static funcptr ndis_linksts_wrap;
//static funcptr ndis_linksts_done_wrap;
#endif
#ifdef __FreeBSD__
static device_method_t ndis_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ndis_probe_pci),
@ -135,6 +190,24 @@ DRIVER_MODULE(ndis, pci, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
DRIVER_MODULE(ndis, cardbus, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
#endif
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
CFATTACH_DECL(
#ifdef NDIS_DEVNAME
NDIS_DEVNAME,
#else
ndis,
#endif
sizeof(struct ndis_softc),
ndis_probe_pci,
ndis_attach_pci,
ndis_detach,
NULL);
#endif /* __NetBSD__ */
#ifdef __FreeBSD__
/*
* Probe for an NDIS device. Check the PCI vendor and device
* IDs against our list and return a device name if we find a match.
@ -168,7 +241,68 @@ ndis_probe_pci(dev)
return(ENXIO);
}
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
extern int
ndis_lkm_handle(struct lkm_table *lkmtp, int cmd);
extern int
ndisdrv_modevent(module_t mod, int cmd);
/* These are just for the in-kernel version, to delay calling
* these functions untill enough context is built up.
*/
void load_ndisapi(void *);
void load_ndisdrv(void *);
void load_ndisapi(void *arg)
{
ndis_lkm_handle(NULL, MOD_LOAD);
}
void load_ndisdrv(void *arg)
{
ndisdrv_modevent(NULL, MOD_LOAD);
}
/*static*/ int
ndis_probe_pci(struct device *parent, struct cfdata *match, void *aux)
{
struct pci_attach_args *pa = aux;
int vendor = PCI_VENDOR(pa->pa_id);
int product = PCI_PRODUCT(pa->pa_id);
struct ndis_pci_type *t = ndis_devs;
driver_object *drv = NULL; /* = windrv_lookup(0, "PCI Bus");**/
printf("in ndis_probe_pci\n");
printf("vendor = %x, product = %x\n", vendor, product);
while(t->ndis_name != NULL) {
#ifdef NDIS_LKM
printf("t->ndis_vid = %x, t->ndis_did = %x\n",
t->ndis_vid, t->ndis_did);
#endif
if((vendor == t->ndis_vid) && (product == t->ndis_did)) {
#ifndef NDIS_LKM
ndis_lkm_handle(NULL, LKM_E_LOAD);
//kthread_create(load_ndisapi, NULL);
#endif /* NDIS_LKM */
ndisdrv_modevent(NULL, MOD_LOAD);
//kthread_create(load_ndisdrv, NULL);
drv = windrv_lookup(0, "PCI Bus");
printf("Matching vendor: %x, product: %x, name: %s\n", vendor, product, t->ndis_name);
windrv_create_pdo(drv, parent);
return 1;
}
t++;
}
return 0; /* dosen't match */
}
#endif /* __NetBSD__ */
#ifdef __FreeBSD__
/*
* Attach the interface. Allocate softc structures, do ifmedia
* setup and ethernet/BPF attach.
@ -335,7 +469,234 @@ ndis_attach_pci(dev)
fail:
return(error);
}
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
/* 6 BADR's + 1 IRQ (so far) */
#define MAX_RESOURCES 7
/*static*/
void ndis_attach_pci(struct device *parent, struct device *self, void *aux)
{
struct ndis_softc *sc = (struct ndis_softc*)self;
struct pci_attach_args *pa = aux;
char devinfo[256];
pci_intr_handle_t ih;
pcireg_t type;
bus_addr_t base;
bus_size_t size;
int flags;
ndis_resource_list *rl = NULL;
struct cm_partial_resource_desc *prd = NULL;
struct pci_conf_state conf_state;
int revision, i, bar;
printf("in ndis_attach_pci()\n");
/* initalize the softc */
//sc->ndis_hardware_type = NDIS_PCI;
sc->ndis_dev = self;
sc->ndis_iftype = PCIBus;
sc->ndis_res_pc = pa->pa_pc;
sc->ndis_res_pctag = pa->pa_tag;
/* TODO: is this correct? All are just pa->pa_dmat? */
sc->ndis_mtag = pa->pa_dmat;
sc->ndis_ttag = pa->pa_dmat;
sc->ndis_parent_tag = pa->pa_dmat;
sc->ndis_res_io = NULL;
sc->ndis_res_mem = NULL;
sc->ndis_res_altmem = NULL;
sc->ndis_block = NULL;
sc->ndis_shlist = NULL;
ndis_in_isr = FALSE;
printf("sc->ndis_mtag = %x\n", (unsigned int)sc->ndis_mtag);
rl = malloc(sizeof(ndis_resource_list) +
(sizeof(cm_partial_resource_desc) * (MAX_RESOURCES-1)),
M_DEVBUF, M_NOWAIT|M_ZERO);
if(rl == NULL) {
sc->error = ENOMEM;
//printf("error: out of memory\n");
return;
}
rl->cprl_version = 5;
rl->cprl_version = 1;
rl->cprl_count = 0;
prd = rl->cprl_partial_descs;
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof devinfo);
revision = PCI_REVISION(pa->pa_class);
//printf(": %s (rev. 0x%02x)\n", devinfo, revision);
pci_conf_print(sc->ndis_res_pc, sc->ndis_res_pctag, NULL);
pci_conf_capture(sc->ndis_res_pc, sc->ndis_res_pctag, &conf_state);
for(i=0; i<16; i++) {
//printf("conf_state.reg[%d] = %x\n", i, conf_state.reg[i]);
}
/* just do the conversion work in attach instead of calling ndis_convert_res() */
for(bar = 0x10; bar <= 0x24; bar += 0x04) {
type = pci_mapreg_type(sc->ndis_res_pc, sc->ndis_res_pctag, bar);
if(pci_mapreg_info(sc->ndis_res_pc, sc->ndis_res_pctag, bar, type, &base,
&size, &flags)) {
printf("pci_mapreg_info() failed on BAR 0x%x!\n", bar);
} else {
switch(type) {
case PCI_MAPREG_TYPE_IO:
prd->cprd_type = CmResourceTypePort;
prd->cprd_flags = CM_RESOURCE_PORT_IO;
prd->u.cprd_port.cprd_start.np_quad = (uint64_t)base;
prd->u.cprd_port.cprd_len = (uint32_t)size;
//printf("BAR 0x%x: type = PCI_MAPREG_TYPE_IO, base = %x, size = %x, flags = %x\n",
// bar, base, size, flags);
if((sc->ndis_res_io =
malloc(sizeof(struct ndis_resource), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
//printf("error: out of memory\n");
sc->error = ENOMEM;
return;
}
sc->ndis_res_io->res_base = base;
sc->ndis_res_io->res_size = size;
sc->ndis_res_io->res_tag = X86_BUS_SPACE_IO;
/* TODO: is this correct to just map the register here? */
bus_space_map(sc->ndis_res_io->res_tag,
sc->ndis_res_io->res_base,
sc->ndis_res_io->res_size,
flags,
&sc->ndis_res_io->res_handle);
/*if(pci_mapreg_map(pa, bar, type, flags,
&sc->ndis_res_io->res_tag,
&sc->ndis_res_io->res_handle,
&sc->ndis_res_io->res_base,
&sc->ndis_res_io->res_size)) {
printf("pci_mapreg_map() failed\n");
}*/
break;
case PCI_MAPREG_TYPE_MEM:
prd->cprd_type = CmResourceTypeMemory;
prd->cprd_flags = CM_RESOURCE_MEMORY_READ_WRITE;
prd->u.cprd_mem.cprd_start.np_quad = (uint64_t)base;
prd->u.cprd_mem.cprd_len = (uint32_t)size;
if(sc->ndis_res_mem != NULL &&
sc->ndis_res_altmem != NULL) {
printf("too many resources\n");
sc->error = ENXIO;
return;
}
if(sc->ndis_res_mem) {
if((sc->ndis_res_altmem =
malloc(sizeof(struct ndis_resource), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
//printf("error: out of memory\n");
sc->error = ENOMEM;
return;
}
sc->ndis_res_altmem->res_base = base;
sc->ndis_res_altmem->res_size = size;
sc->ndis_res_altmem->res_tag = X86_BUS_SPACE_MEM;
if(bus_space_map(sc->ndis_res_altmem->res_tag,
sc->ndis_res_altmem->res_base,
sc->ndis_res_altmem->res_size,
flags|BUS_SPACE_MAP_LINEAR,
&sc->ndis_res_altmem->res_handle)) {
printf("bus_space_map failed\n");
}
/*
if(pci_mapreg_map(pa, bar, type, flags|BUS_SPACE_MAP_LINEAR,
&sc->ndis_res_altmem->res_tag,
&sc->ndis_res_altmem->res_handle,
&sc->ndis_res_altmem->res_base,
&sc->ndis_res_altmem->res_size)) {
printf("pci_mapreg_map() failed\n");
}*/
} else {
if((sc->ndis_res_mem =
malloc(sizeof(struct ndis_resource), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) {
//printf("error: out of memory\n");
sc->error = ENOMEM;
return;
}
/* TODO: is this correct to just map the register here? */
sc->ndis_res_mem->res_base = base;
sc->ndis_res_mem->res_size = size;
sc->ndis_res_mem->res_tag = X86_BUS_SPACE_MEM;
if(bus_space_map(sc->ndis_res_mem->res_tag,
sc->ndis_res_mem->res_base,
sc->ndis_res_mem->res_size,
flags|BUS_SPACE_MAP_LINEAR,
&sc->ndis_res_mem->res_handle)) {
printf("bus_space_map failed\n");
}
/*
if(pci_mapreg_map(pa, bar, type, flags|BUS_SPACE_MAP_LINEAR,
&sc->ndis_res_mem->res_tag,
&sc->ndis_res_mem->res_handle,
&sc->ndis_res_mem->res_base,
&sc->ndis_res_mem->res_size)) {
printf("pci_mapreg_map() failed\n");
}*/
}
break;
default:
printf("unknown type\n");
}
prd->cprd_sharedisp = CmResourceShareDeviceExclusive;
rl->cprl_count++;
prd++;
}
}
/* add the interrupt to the list */
prd->cprd_type = CmResourceTypeInterrupt;
prd->cprd_flags = 0;
/* TODO: is this all we need to save for the interrupt? */
prd->u.cprd_intr.cprd_level = pa->pa_intrline;
prd->u.cprd_intr.cprd_vector = pa->pa_intrline;
prd->u.cprd_intr.cprd_affinity = 0;
rl->cprl_count++;
pci_intr_map(pa, &ih);
sc->ndis_intrhand = pci_intr_establish(pa->pa_pc, ih, IPL_NET /*| PCATCH*/, ndis_intr, sc);
sc->ndis_irq = (void *)sc->ndis_intrhand;
printf("pci interrupt: %s\n", pci_intr_string(pa->pa_pc, ih));
/*
realloc(rl, sizeof(ndis_resource_list) +
(sizeof(cm_partial_resource_desc) * (rl->cprl_count / *- 1* /)),
M_DEVBUF, M_NOWAIT|M_ZERO);
*/
if(rl == NULL) {
sc->error = ENOMEM;
//printf("error: out of memory\n");
return;
}
/* save resource list in the softc */
//sc->ndis_rl = *rl;
sc->ndis_rl = rl;
sc->ndis_rescnt = rl->cprl_count;
/*
sc->error = ndis_attach((device_t)sc);
*/
kthread_create(ndis_attach, (void *)sc);
}
#endif /* __NetBSD__ */
#ifdef __FreeBSD__
static struct resource_list *
ndis_get_resource_list(dev, child)
device_t dev;
@ -346,5 +707,6 @@ ndis_get_resource_list(dev, child)
sc = device_get_softc(dev);
return (BUS_GET_RESOURCE_LIST(device_get_parent(sc->ndis_dev), dev));
}
#endif /* __FreeBSD__ */
#endif /* NDIS_PCI_DEV_TABLE */

View File

@ -30,16 +30,29 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: src/sys/dev/if_ndis/if_ndisvar.h,v 1.15.2.2 2005/02/18 16:30:10 wpaul Exp $
*/
*/
#define NDIS_DEFAULT_NODENAME "FreeBSD NDIS node"
#define NDIS_NODENAME_LEN 32
#ifdef __NetBSD__
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
#include <dev/pcmcia/pcmciareg.h>
#include <dev/pcmcia/pcmciavar.h>
#include <dev/pcmcia/pcmciadevs.h>
#include <dev/cardbus/cardbusvar.h>
#include <dev/cardbus/cardbusreg.h>
#endif
struct ndis_pci_type {
uint16_t ndis_vid;
uint16_t ndis_did;
uint32_t ndis_subsys;
char *ndis_name;
const uint16_t ndis_vid;
const uint16_t ndis_did;
const uint32_t ndis_subsys;
const char *ndis_name;
};
struct ndis_pccard_type {
@ -65,14 +78,43 @@ TAILQ_HEAD(nch, ndis_cfglist);
#define NDIS_INITIALIZED(sc) (sc->ndis_block->nmb_miniportadapterctx != NULL)
#define NDIS_INC(x) \
(x)->ndis_txidx = ((x)->ndis_txidx + 1) % (x)->ndis_maxpkts
(x)->ndis_txidx = ((x)->ndis_txidx + 1) % (x)->ndis_maxpkts
#ifdef __NetBSD__
/* linked list of resources */
struct resource {
SLIST_ENTRY(resource) link;
cm_partial_resource_desc win_res;
};
SLIST_HEAD(resource_list, resource);
#endif /* __NetBSD__ */
#ifdef __FreeBSD__
#define arpcom ic.ic_ac
#endif
#ifdef __NetBSD__
struct ndis_resource {
bus_space_handle_t res_handle;
bus_space_tag_t res_tag;
bus_addr_t res_base;
bus_size_t res_size;
};
#endif
#ifdef __NetBSD__
int ndis_in_isr;
#endif
struct ndis_softc {
#ifndef __FreeBSD__
#ifdef __NetBSD__
/* TODO: It seems like in the attach function the ndis "struct device" object
* TODO: and the softc are the same thing, so I added a "struct device" to the
* TODO: front of the softc, to make sure the arpcom field wasn't getting
* TODO: messed up. However, I'm not sure if the arpcom field is supposed
* TODO: to be first for some other reason.
*/
struct device dev;
struct ethercom arpcom;
#endif
struct ieee80211com ic; /* interface info */
@ -86,6 +128,7 @@ struct ndis_softc {
bus_space_handle_t ndis_bhandle;
bus_space_tag_t ndis_btag;
void *ndis_intrhand;
#ifdef __FreeBSD__
struct resource *ndis_irq;
struct resource *ndis_res;
struct resource *ndis_res_io;
@ -97,12 +140,47 @@ struct ndis_softc {
struct resource *ndis_res_am; /* attribute mem (pccard) */
int ndis_am_rid;
struct resource *ndis_res_cm; /* common mem (pccard) */
#ifdef __FreeBSD__
struct resource_list ndis_rl;
#endif
#else /* __NetBSD__ */
int ndis_sysctl_mib;
struct sysctllog *sysctllog;
//ndis_resource_list ndis_rl;
ndis_resource_list *ndis_rl;
int error;
/* TODO: Is the ndis_irq set up right? */
void *ndis_irq;
/* for both pci and cardbus ? */
struct ndis_resource *ndis_res_io;
int ndis_io_rid; /* not actuially used, just for bus_release_resource() */
struct ndis_resource *ndis_res_mem;
struct ndis_resource *ndis_res_altmem;
int ndis_mem_rid; /* not actuially used, just for bus_release_resource() */
/* pci specific */
pci_chipset_tag_t ndis_res_pc; /* pci chipset */
pcitag_t ndis_res_pctag; /* pci tag */
pci_intr_handle_t pci_ih; /* interrupt handle */
/* pcmcia specific */
struct pcmcia_io_handle ndis_res_pcioh; /* specific i/o for pcmcia */
struct pcmcia_mem_handle ndis_res_pcmem; /* specific mem for pcmcia */
int sc_io_windows; /* i/o window */
struct pcmcia_function * ndis_res_pcfunc; /* pcmcia function */
/* cardbus specific */
cardbus_devfunc_t ndis_res_ct; /* cardbus devfuncs */
cardbustag_t ndis_res_ctag; /* carbus tag */
bus_size_t ndis_res_mapsize; /* size of mapped bus space region */
#endif /* end __NetBSD__ section */
int ndis_rescnt;
#ifdef __FreeBSD__
struct mtx ndis_mtx;
device_t ndis_dev;
#else /* __NetBSD__ */
struct simplelock ndis_mtx;
#endif
device_t ndis_dev;
int ndis_unit;
ndis_miniport_block *ndis_block;
ndis_miniport_characteristics *ndis_chars;
@ -120,7 +198,9 @@ struct ndis_softc {
ndis_packet **ndis_txarray;
ndis_handle ndis_txpool;
int ndis_sc;
//#ifdef __FreeBSD__
ndis_cfg *ndis_regvals;
//#endif
struct nch ndis_cfglist_head;
int ndis_80211;
int ndis_link;
@ -128,7 +208,9 @@ struct ndis_softc {
int ndis_if_flags;
int ndis_skip;
#ifdef __FreeBSD__
struct sysctl_ctx_list ndis_ctx;
#endif
#if __FreeBSD__ && __FreeBSD_version < 502113
struct sysctl_oid *ndis_tree;
#endif
@ -144,5 +226,28 @@ struct ndis_softc {
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__ */
/*
int ndis_spl;
#define NDIS_LOCK(_sc) ndis_spl = splnet(); \
simple_lock(&(_sc)->ndis_mtx)
#define NDIS_UNLOCK(_sc) simple_unlock(&(_sc)->ndis_mtx); \
splx(ndis_spl)
*/
//#define NDIS_LOCK(_sc) lockmgr(&(_sc)->ndis_mtx, LK_EXCLUSIVE, NULL);
//#define NDIS_UNLOCK(_sc) lockmgr(&(_sc)->ndis_mtx, LK_RELEASE, NULL);
#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);
/*static*/ __stdcall void ndis_linksts_done (ndis_handle);

View File

@ -1,4 +1,4 @@
# $NetBSD: files.pci,v 1.245 2006/03/21 20:42:14 he Exp $
# $NetBSD: files.pci,v 1.246 2006/03/31 00:03:57 rittera Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@ -761,6 +761,12 @@ file dev/pci/if_dge.c dge
attach re at pci with re_pci
file dev/pci/if_re_pci.c re_pci
# Windows NDIS drivers (Experimental)
#device ndis
#attach ndis at pci
#file dev/if_ndis/if_ndis.c
#file dev/if_ndis/if_ndis_pci.c
# Intel PRO/Wireless 2100
device ipw: ifnet, arp, wlan
attach ipw at pci