2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2004-03-07 02:49:06 +00:00
|
|
|
* Copyright (c) 2003
|
|
|
|
* Bill Paul <wpaul@windriver.com>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/ctype.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-06-01 23:27:36 +00:00
|
|
|
#include <sys/module.h>
|
2004-03-07 02:49:06 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2009-03-07 07:26:22 +00:00
|
|
|
#include <dev/usb/usb.h>
|
2009-06-23 02:19:59 +00:00
|
|
|
#include <dev/usb/usbdi.h>
|
2004-03-07 02:49:06 +00:00
|
|
|
|
2009-03-07 07:26:22 +00:00
|
|
|
#include <net80211/ieee80211_var.h>
|
2008-12-27 08:03:32 +00:00
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
#include <compat/ndis/pe_var.h>
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
#include <compat/ndis/cfg_var.h>
|
2004-03-07 02:49:06 +00:00
|
|
|
#include <compat/ndis/resource_var.h>
|
|
|
|
#include <compat/ndis/ntoskrnl_var.h>
|
|
|
|
#include <compat/ndis/ndis_var.h>
|
|
|
|
#include <dev/if_ndis/if_ndisvar.h>
|
|
|
|
|
|
|
|
#include <dev/pccard/pccardvar.h>
|
|
|
|
#include "card_if.h"
|
|
|
|
|
|
|
|
MODULE_DEPEND(ndis, pccard, 1, 1, 1);
|
|
|
|
|
|
|
|
static int ndis_probe_pccard (device_t);
|
|
|
|
static int ndis_attach_pccard (device_t);
|
2004-07-11 00:19:30 +00:00
|
|
|
static struct resource_list *ndis_get_resource_list
|
|
|
|
(device_t, device_t);
|
2005-05-08 23:19:20 +00:00
|
|
|
static int ndis_devcompare (interface_type,
|
|
|
|
struct ndis_pccard_type *, device_t);
|
Next step on the road to IRPs: create and use an imitation of the
Windows DRIVER_OBJECT and DEVICE_OBJECT mechanism so that we can
simulate driver stacking.
In Windows, each loaded driver image is attached to a DRIVER_OBJECT
structure. Windows uses the registry to match up a given vendor/device
ID combination with a corresponding DRIVER_OBJECT. When a driver image
is first loaded, its DriverEntry() routine is invoked, which sets up
the AddDevice() function pointer in the DRIVER_OBJECT and creates
a dispatch table (based on IRP major codes). When a Windows bus driver
detects a new device, it creates a Physical Device Object (PDO) for
it. This is a DEVICE_OBJECT structure, with semantics analagous to
that of a device_t in FreeBSD. The Windows PNP manager will invoke
the driver's AddDevice() function and pass it pointers to the DRIVER_OBJECT
and the PDO.
The AddDevice() function then creates a new DRIVER_OBJECT structure of
its own. This is known as the Functional Device Object (FDO) and
corresponds roughly to a private softc instance. The driver uses
IoAttachDeviceToDeviceStack() to add this device object to the
driver stack for this PDO. Subsequent drivers (called filter drivers
in Windows-speak) can be loaded which add themselves to the stack.
When someone issues an IRP to a device, it travel along the stack
passing through several possible filter drivers until it reaches
the functional driver (which actually knows how to talk to the hardware)
at which point it will be completed. This is how Windows achieves
driver layering.
Project Evil now simulates most of this. if_ndis now has a modevent
handler which will use MOD_LOAD and MOD_UNLOAD events to drive the
creation and destruction of DRIVER_OBJECTs. (The load event also
does the relocation/dynalinking of the image.) We don't have a registry,
so the DRIVER_OBJECTS are stored in a linked list for now. Eventually,
the list entry will contain the vendor/device ID list extracted from
the .INF file. When ndis_probe() is called and detectes a supported
device, it will create a PDO for the device instance and attach it
to the DRIVER_OBJECT just as in Windows. ndis_attach() will then call
our NdisAddDevice() handler to create the FDO. The NDIS miniport block
is now a device extension hung off the FDO, just as it is in Windows.
The miniport characteristics table is now an extension hung off the
DRIVER_OBJECT as well (the characteristics are the same for all devices
handled by a given driver, so they don't need to be per-instance.)
We also do an IoAttachDeviceToDeviceStack() to put the FDO on the
stack for the PDO. There are a couple of fake bus drivers created
for the PCI and pccard buses. Eventually, there will be one for USB,
which will actually accept USB IRP.s
Things should still work just as before, only now we do things in
the proper order and maintain the correct framework to support passing
IRPs between drivers.
Various changes:
- corrected the comments about IRQL handling in subr_hal.c to more
accurately reflect reality
- update ndiscvt to make the drv_data symbol in ndis_driver_data.h a
global so that if_ndis_pci.o and/or if_ndis_pccard.o can see it.
- Obtain the softc pointer from the miniport block by referencing
the PDO rather than a private pointer of our own (nmb_ifp is no
longer used)
- implement IoAttachDeviceToDeviceStack(), IoDetachDevice(),
IoGetAttachedDevice(), IoAllocateDriverObjectExtension(),
IoGetDriverObjectExtension(), IoCreateDevice(), IoDeleteDevice(),
IoAllocateIrp(), IoReuseIrp(), IoMakeAssociatedIrp(), IoFreeIrp(),
IoInitializeIrp()
- fix a few mistakes in the driver_object and device_object definitions
- add a new module, kern_windrv.c, to handle the driver registration
and relocation/dynalinkign duties (which don't really belong in
kern_ndis.c).
- made ndis_block and ndis_chars in the ndis_softc stucture pointers
and modified all references to it
- fixed NdisMRegisterMiniport() and NdisInitializeWrapper() so they
work correctly with the new driver_object mechanism
- changed ndis_attach() to call NdisAddDevice() instead of ndis_load_driver()
(which is now deprecated)
- used ExAllocatePoolWithTag()/ExFreePool() in lookaside list routines
instead of kludged up alloc/free routines
- added kern_windrv.c to sys/modules/ndis/Makefile and files.i386.
2005-02-08 17:23:25 +00:00
|
|
|
extern int ndisdrv_modevent (module_t, int, void *);
|
2004-03-07 02:49:06 +00:00
|
|
|
extern int ndis_attach (device_t);
|
|
|
|
extern int ndis_shutdown (device_t);
|
|
|
|
extern int ndis_detach (device_t);
|
|
|
|
extern int ndis_suspend (device_t);
|
|
|
|
extern int ndis_resume (device_t);
|
|
|
|
|
Next step on the road to IRPs: create and use an imitation of the
Windows DRIVER_OBJECT and DEVICE_OBJECT mechanism so that we can
simulate driver stacking.
In Windows, each loaded driver image is attached to a DRIVER_OBJECT
structure. Windows uses the registry to match up a given vendor/device
ID combination with a corresponding DRIVER_OBJECT. When a driver image
is first loaded, its DriverEntry() routine is invoked, which sets up
the AddDevice() function pointer in the DRIVER_OBJECT and creates
a dispatch table (based on IRP major codes). When a Windows bus driver
detects a new device, it creates a Physical Device Object (PDO) for
it. This is a DEVICE_OBJECT structure, with semantics analagous to
that of a device_t in FreeBSD. The Windows PNP manager will invoke
the driver's AddDevice() function and pass it pointers to the DRIVER_OBJECT
and the PDO.
The AddDevice() function then creates a new DRIVER_OBJECT structure of
its own. This is known as the Functional Device Object (FDO) and
corresponds roughly to a private softc instance. The driver uses
IoAttachDeviceToDeviceStack() to add this device object to the
driver stack for this PDO. Subsequent drivers (called filter drivers
in Windows-speak) can be loaded which add themselves to the stack.
When someone issues an IRP to a device, it travel along the stack
passing through several possible filter drivers until it reaches
the functional driver (which actually knows how to talk to the hardware)
at which point it will be completed. This is how Windows achieves
driver layering.
Project Evil now simulates most of this. if_ndis now has a modevent
handler which will use MOD_LOAD and MOD_UNLOAD events to drive the
creation and destruction of DRIVER_OBJECTs. (The load event also
does the relocation/dynalinking of the image.) We don't have a registry,
so the DRIVER_OBJECTS are stored in a linked list for now. Eventually,
the list entry will contain the vendor/device ID list extracted from
the .INF file. When ndis_probe() is called and detectes a supported
device, it will create a PDO for the device instance and attach it
to the DRIVER_OBJECT just as in Windows. ndis_attach() will then call
our NdisAddDevice() handler to create the FDO. The NDIS miniport block
is now a device extension hung off the FDO, just as it is in Windows.
The miniport characteristics table is now an extension hung off the
DRIVER_OBJECT as well (the characteristics are the same for all devices
handled by a given driver, so they don't need to be per-instance.)
We also do an IoAttachDeviceToDeviceStack() to put the FDO on the
stack for the PDO. There are a couple of fake bus drivers created
for the PCI and pccard buses. Eventually, there will be one for USB,
which will actually accept USB IRP.s
Things should still work just as before, only now we do things in
the proper order and maintain the correct framework to support passing
IRPs between drivers.
Various changes:
- corrected the comments about IRQL handling in subr_hal.c to more
accurately reflect reality
- update ndiscvt to make the drv_data symbol in ndis_driver_data.h a
global so that if_ndis_pci.o and/or if_ndis_pccard.o can see it.
- Obtain the softc pointer from the miniport block by referencing
the PDO rather than a private pointer of our own (nmb_ifp is no
longer used)
- implement IoAttachDeviceToDeviceStack(), IoDetachDevice(),
IoGetAttachedDevice(), IoAllocateDriverObjectExtension(),
IoGetDriverObjectExtension(), IoCreateDevice(), IoDeleteDevice(),
IoAllocateIrp(), IoReuseIrp(), IoMakeAssociatedIrp(), IoFreeIrp(),
IoInitializeIrp()
- fix a few mistakes in the driver_object and device_object definitions
- add a new module, kern_windrv.c, to handle the driver registration
and relocation/dynalinkign duties (which don't really belong in
kern_ndis.c).
- made ndis_block and ndis_chars in the ndis_softc stucture pointers
and modified all references to it
- fixed NdisMRegisterMiniport() and NdisInitializeWrapper() so they
work correctly with the new driver_object mechanism
- changed ndis_attach() to call NdisAddDevice() instead of ndis_load_driver()
(which is now deprecated)
- used ExAllocatePoolWithTag()/ExFreePool() in lookaside list routines
instead of kludged up alloc/free routines
- added kern_windrv.c to sys/modules/ndis/Makefile and files.i386.
2005-02-08 17:23:25 +00:00
|
|
|
extern unsigned char drv_data[];
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
static device_method_t ndis_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, ndis_probe_pccard),
|
|
|
|
DEVMETHOD(device_attach, ndis_attach_pccard),
|
|
|
|
DEVMETHOD(device_detach, ndis_detach),
|
|
|
|
DEVMETHOD(device_shutdown, ndis_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, ndis_suspend),
|
|
|
|
DEVMETHOD(device_resume, ndis_resume),
|
|
|
|
|
2004-07-11 00:19:30 +00:00
|
|
|
/* Bus interface. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an awful kludge, but we need it becase pccard
|
|
|
|
* does not implement a bus_get_resource_list() method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEVMETHOD(bus_get_resource_list, ndis_get_resource_list),
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ndis_driver = {
|
|
|
|
"ndis",
|
|
|
|
ndis_methods,
|
|
|
|
sizeof(struct ndis_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t ndis_devclass;
|
|
|
|
|
Next step on the road to IRPs: create and use an imitation of the
Windows DRIVER_OBJECT and DEVICE_OBJECT mechanism so that we can
simulate driver stacking.
In Windows, each loaded driver image is attached to a DRIVER_OBJECT
structure. Windows uses the registry to match up a given vendor/device
ID combination with a corresponding DRIVER_OBJECT. When a driver image
is first loaded, its DriverEntry() routine is invoked, which sets up
the AddDevice() function pointer in the DRIVER_OBJECT and creates
a dispatch table (based on IRP major codes). When a Windows bus driver
detects a new device, it creates a Physical Device Object (PDO) for
it. This is a DEVICE_OBJECT structure, with semantics analagous to
that of a device_t in FreeBSD. The Windows PNP manager will invoke
the driver's AddDevice() function and pass it pointers to the DRIVER_OBJECT
and the PDO.
The AddDevice() function then creates a new DRIVER_OBJECT structure of
its own. This is known as the Functional Device Object (FDO) and
corresponds roughly to a private softc instance. The driver uses
IoAttachDeviceToDeviceStack() to add this device object to the
driver stack for this PDO. Subsequent drivers (called filter drivers
in Windows-speak) can be loaded which add themselves to the stack.
When someone issues an IRP to a device, it travel along the stack
passing through several possible filter drivers until it reaches
the functional driver (which actually knows how to talk to the hardware)
at which point it will be completed. This is how Windows achieves
driver layering.
Project Evil now simulates most of this. if_ndis now has a modevent
handler which will use MOD_LOAD and MOD_UNLOAD events to drive the
creation and destruction of DRIVER_OBJECTs. (The load event also
does the relocation/dynalinking of the image.) We don't have a registry,
so the DRIVER_OBJECTS are stored in a linked list for now. Eventually,
the list entry will contain the vendor/device ID list extracted from
the .INF file. When ndis_probe() is called and detectes a supported
device, it will create a PDO for the device instance and attach it
to the DRIVER_OBJECT just as in Windows. ndis_attach() will then call
our NdisAddDevice() handler to create the FDO. The NDIS miniport block
is now a device extension hung off the FDO, just as it is in Windows.
The miniport characteristics table is now an extension hung off the
DRIVER_OBJECT as well (the characteristics are the same for all devices
handled by a given driver, so they don't need to be per-instance.)
We also do an IoAttachDeviceToDeviceStack() to put the FDO on the
stack for the PDO. There are a couple of fake bus drivers created
for the PCI and pccard buses. Eventually, there will be one for USB,
which will actually accept USB IRP.s
Things should still work just as before, only now we do things in
the proper order and maintain the correct framework to support passing
IRPs between drivers.
Various changes:
- corrected the comments about IRQL handling in subr_hal.c to more
accurately reflect reality
- update ndiscvt to make the drv_data symbol in ndis_driver_data.h a
global so that if_ndis_pci.o and/or if_ndis_pccard.o can see it.
- Obtain the softc pointer from the miniport block by referencing
the PDO rather than a private pointer of our own (nmb_ifp is no
longer used)
- implement IoAttachDeviceToDeviceStack(), IoDetachDevice(),
IoGetAttachedDevice(), IoAllocateDriverObjectExtension(),
IoGetDriverObjectExtension(), IoCreateDevice(), IoDeleteDevice(),
IoAllocateIrp(), IoReuseIrp(), IoMakeAssociatedIrp(), IoFreeIrp(),
IoInitializeIrp()
- fix a few mistakes in the driver_object and device_object definitions
- add a new module, kern_windrv.c, to handle the driver registration
and relocation/dynalinkign duties (which don't really belong in
kern_ndis.c).
- made ndis_block and ndis_chars in the ndis_softc stucture pointers
and modified all references to it
- fixed NdisMRegisterMiniport() and NdisInitializeWrapper() so they
work correctly with the new driver_object mechanism
- changed ndis_attach() to call NdisAddDevice() instead of ndis_load_driver()
(which is now deprecated)
- used ExAllocatePoolWithTag()/ExFreePool() in lookaside list routines
instead of kludged up alloc/free routines
- added kern_windrv.c to sys/modules/ndis/Makefile and files.i386.
2005-02-08 17:23:25 +00:00
|
|
|
DRIVER_MODULE(ndis, pccard, ndis_driver, ndis_devclass, ndisdrv_modevent, 0);
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
static int
|
2005-05-08 23:19:20 +00:00
|
|
|
ndis_devcompare(bustype, t, dev)
|
|
|
|
interface_type bustype;
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
struct ndis_pccard_type *t;
|
2004-03-07 02:49:06 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
const char *prodstr, *vendstr;
|
|
|
|
int error;
|
|
|
|
|
2005-05-08 23:19:20 +00:00
|
|
|
if (bustype != PCMCIABus)
|
|
|
|
return(FALSE);
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
error = pccard_get_product_str(dev, &prodstr);
|
|
|
|
if (error)
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
return(FALSE);
|
2004-03-07 02:49:06 +00:00
|
|
|
error = pccard_get_vendor_str(dev, &vendstr);
|
|
|
|
if (error)
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
return(FALSE);
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
while(t->ndis_name != NULL) {
|
2007-04-06 11:21:01 +00:00
|
|
|
if (strcasecmp(vendstr, t->ndis_vid) == 0 &&
|
|
|
|
strcasecmp(prodstr, t->ndis_did) == 0) {
|
2004-03-07 02:49:06 +00:00
|
|
|
device_set_desc(dev, t->ndis_name);
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
return(TRUE);
|
2004-03-07 02:49:06 +00:00
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ndis_probe_pccard(dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
driver_object *drv;
|
|
|
|
struct drvdb_ent *db;
|
|
|
|
|
|
|
|
drv = windrv_lookup(0, "PCCARD Bus");
|
|
|
|
if (drv == NULL)
|
|
|
|
return(ENXIO);
|
|
|
|
|
|
|
|
db = windrv_match((matchfuncptr)ndis_devcompare, dev);
|
|
|
|
|
|
|
|
if (db != NULL) {
|
|
|
|
/* Create PDO for this device instance */
|
|
|
|
windrv_create_pdo(drv, dev);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface. Allocate softc structures, do ifmedia
|
|
|
|
* setup and ethernet/BPF attach.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ndis_attach_pccard(dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct ndis_softc *sc;
|
|
|
|
int unit, error = 0, rid;
|
|
|
|
struct ndis_pccard_type *t;
|
|
|
|
int devidx = 0;
|
|
|
|
const char *prodstr, *vendstr;
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
struct drvdb_ent *db;
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
unit = device_get_unit(dev);
|
|
|
|
sc->ndis_dev = dev;
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
|
|
|
|
db = windrv_match((matchfuncptr)ndis_devcompare, dev);
|
|
|
|
if (db == NULL)
|
|
|
|
return (ENXIO);
|
2005-05-08 23:07:51 +00:00
|
|
|
sc->ndis_dobj = db->windrv_object;
|
|
|
|
sc->ndis_regvals = db->windrv_regvals;
|
2004-07-11 00:19:30 +00:00
|
|
|
resource_list_init(&sc->ndis_rl);
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
sc->ndis_io_rid = 0;
|
2010-12-16 15:19:32 +00:00
|
|
|
sc->ndis_res_io = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
|
|
|
|
&sc->ndis_io_rid, RF_ACTIVE);
|
2004-03-07 02:49:06 +00:00
|
|
|
if (sc->ndis_res_io == NULL) {
|
|
|
|
device_printf(dev,
|
|
|
|
"couldn't map iospace\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sc->ndis_rescnt++;
|
2012-01-03 18:40:41 +00:00
|
|
|
resource_list_add(&sc->ndis_rl, SYS_RES_IOPORT, sc->ndis_io_rid,
|
2004-07-11 00:19:30 +00:00
|
|
|
rman_get_start(sc->ndis_res_io), rman_get_end(sc->ndis_res_io),
|
|
|
|
rman_get_size(sc->ndis_res_io));
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
rid = 0;
|
2010-12-16 15:19:32 +00:00
|
|
|
sc->ndis_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
2004-03-07 02:49:06 +00:00
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
if (sc->ndis_irq == NULL) {
|
|
|
|
device_printf(dev,
|
|
|
|
"couldn't map interrupt\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sc->ndis_rescnt++;
|
2004-07-11 00:19:30 +00:00
|
|
|
resource_list_add(&sc->ndis_rl, SYS_RES_IRQ, rid,
|
|
|
|
rman_get_start(sc->ndis_irq), rman_get_start(sc->ndis_irq), 1);
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
sc->ndis_iftype = PCMCIABus;
|
|
|
|
|
|
|
|
/* Figure out exactly which device we matched. */
|
|
|
|
|
Throw the switch on the new driver generation/loading mechanism. From
here on in, if_ndis.ko will be pre-built as a module, and can be built
into a static kernel (though it's not part of GENERIC). Drivers are
created using the new ndisgen(8) script, which uses ndiscvt(8) under
the covers, along with a few other tools. The result is a driver module
that can be kldloaded into the kernel.
A driver with foo.inf and foo.sys files will be converted into
foo_sys.ko (and foo_sys.o, for those who want/need to make static
kernels). This module contains all of the necessary info from the
.INF file and the driver binary image, converted into an ELF module.
You can kldload this module (or add it to /boot/loader.conf) to have
it loaded automatically. Any required firmware files can be bundled
into the module as well (or converted/loaded separately).
Also, add a workaround for a problem in NdisMSleep(). During system
bootstrap (cold == 1), msleep() always returns 0 without actually
sleeping. The Intel 2200BG driver uses NdisMSleep() to wait for
the NIC's firmware to come to life, and fails to load if NdisMSleep()
doesn't actually delay. As a workaround, if msleep() (and hence
ndis_thsuspend()) returns 0, use a hard DELAY() to sleep instead).
This is not really the right thing to do, but we can't really do much
else. At the very least, this makes the Intel driver happy.
There are probably other drivers that fail in this way during bootstrap.
Unfortunately, the only workaround for those is to avoid pre-loading
them and kldload them once the system is running instead.
2005-04-24 20:21:22 +00:00
|
|
|
t = db->windrv_devlist;
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
error = pccard_get_product_str(dev, &prodstr);
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
error = pccard_get_vendor_str(dev, &vendstr);
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
|
|
|
|
while(t->ndis_name != NULL) {
|
2007-04-06 11:21:01 +00:00
|
|
|
if (strcasecmp(vendstr, t->ndis_vid) == 0 &&
|
|
|
|
strcasecmp(prodstr, t->ndis_did) == 0)
|
2004-03-07 02:49:06 +00:00
|
|
|
break;
|
|
|
|
t++;
|
|
|
|
devidx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->ndis_devidx = devidx;
|
|
|
|
|
|
|
|
error = ndis_attach(dev);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2004-07-11 00:19:30 +00:00
|
|
|
static struct resource_list *
|
|
|
|
ndis_get_resource_list(dev, child)
|
|
|
|
device_t dev;
|
|
|
|
device_t child;
|
|
|
|
{
|
|
|
|
struct ndis_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
return (&sc->ndis_rl);
|
|
|
|
}
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
#define NDIS_AM_RID 3
|
|
|
|
|
|
|
|
int
|
|
|
|
ndis_alloc_amem(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ndis_softc *sc;
|
|
|
|
int error, rid;
|
|
|
|
|
|
|
|
if (arg == NULL)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
rid = NDIS_AM_RID;
|
|
|
|
sc->ndis_res_am = bus_alloc_resource(sc->ndis_dev, SYS_RES_MEMORY,
|
|
|
|
&rid, 0UL, ~0UL, 0x1000, RF_ACTIVE);
|
|
|
|
|
|
|
|
if (sc->ndis_res_am == NULL) {
|
|
|
|
device_printf(sc->ndis_dev,
|
|
|
|
"failed to allocate attribute memory\n");
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
2004-07-11 00:19:30 +00:00
|
|
|
sc->ndis_rescnt++;
|
|
|
|
resource_list_add(&sc->ndis_rl, SYS_RES_MEMORY, rid,
|
|
|
|
rman_get_start(sc->ndis_res_am), rman_get_end(sc->ndis_res_am),
|
|
|
|
rman_get_size(sc->ndis_res_am));
|
2004-03-07 02:49:06 +00:00
|
|
|
|
|
|
|
error = CARD_SET_MEMORY_OFFSET(device_get_parent(sc->ndis_dev),
|
|
|
|
sc->ndis_dev, rid, 0, NULL);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->ndis_dev,
|
|
|
|
"CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = CARD_SET_RES_FLAGS(device_get_parent(sc->ndis_dev),
|
|
|
|
sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
device_printf(sc->ndis_dev,
|
|
|
|
"CARD_SET_RES_FLAGS() returned 0x%x\n", error);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2004-07-11 00:19:30 +00:00
|
|
|
sc->ndis_am_rid = rid;
|
|
|
|
|
2004-03-07 02:49:06 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2004-07-11 00:19:30 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ndis_free_amem(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ndis_softc *sc;
|
|
|
|
|
|
|
|
if (arg == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
|
|
|
|
if (sc->ndis_res_am != NULL)
|
|
|
|
bus_release_resource(sc->ndis_dev, SYS_RES_MEMORY,
|
|
|
|
sc->ndis_am_rid, sc->ndis_res_am);
|
|
|
|
resource_list_free(&sc->ndis_rl);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|