3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * This file implements a translation layer between the BSD networking
38 * infrasturcture and Windows(R) NDIS network driver modules. A Windows
39 * NDIS driver calls into several functions in the NDIS.SYS Windows
40 * kernel module and exports a table of functions designed to be called
41 * by the NDIS subsystem. Using the PE loader, we can patch our own
42 * versions of the NDIS routines into a given Windows driver module and
43 * convince the driver that it is in fact running on Windows.
45 * We provide a table of all our implemented NDIS routines which is patched
46 * into the driver object code. All our exported routines must use the
47 * _stdcall calling convention, since that's what the Windows object code
52 #include <sys/ctype.h>
53 #include <sys/param.h>
54 #include <sys/types.h>
55 #include <sys/errno.h>
57 #include <sys/callout.h>
58 #include <sys/kernel.h>
59 #include <sys/systm.h>
60 #include <sys/malloc.h>
62 #include <sys/mutex.h>
63 #include <sys/socket.h>
64 #include <sys/sysctl.h>
65 #include <sys/timespec.h>
67 #include <sys/queue.h>
69 #include <sys/filedesc.h>
70 #include <sys/namei.h>
71 #include <sys/fcntl.h>
72 #include <sys/vnode.h>
73 #include <sys/kthread.h>
74 #include <sys/linker.h>
75 #include <sys/mount.h>
76 #include <sys/sysproto.h>
79 #include <net/if_arp.h>
80 #include <net/ethernet.h>
81 #include <net/if_dl.h>
82 #include <net/if_media.h>
84 #include <machine/atomic.h>
85 #include <machine/bus.h>
86 #include <machine/resource.h>
91 #include <machine/stdarg.h>
93 #include <net80211/ieee80211_var.h>
94 #include <net80211/ieee80211_ioctl.h>
96 #include <dev/pci/pcireg.h>
97 #include <dev/pci/pcivar.h>
99 #include <compat/ndis/pe_var.h>
100 #include <compat/ndis/cfg_var.h>
101 #include <compat/ndis/resource_var.h>
102 #include <compat/ndis/ntoskrnl_var.h>
103 #include <compat/ndis/hal_var.h>
104 #include <compat/ndis/ndis_var.h>
105 #include <dev/if_ndis/if_ndisvar.h>
108 #include <vm/vm_param.h>
111 #include <vm/vm_kern.h>
112 #include <vm/vm_map.h>
114 static char ndis_filepath[MAXPATHLEN];
116 SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath,
117 MAXPATHLEN, "Path used by NdisOpenFile() to search for files");
119 static void NdisInitializeWrapper(ndis_handle *,
120 driver_object *, void *, void *);
121 static ndis_status NdisMRegisterMiniport(ndis_handle,
122 ndis_miniport_characteristics *, int);
123 static ndis_status NdisAllocateMemoryWithTag(void **,
125 static ndis_status NdisAllocateMemory(void **,
126 uint32_t, uint32_t, ndis_physaddr);
127 static void NdisFreeMemory(void *, uint32_t, uint32_t);
128 static ndis_status NdisMSetAttributesEx(ndis_handle, ndis_handle,
129 uint32_t, uint32_t, ndis_interface_type);
130 static void NdisOpenConfiguration(ndis_status *,
131 ndis_handle *, ndis_handle);
132 static void NdisOpenConfigurationKeyByIndex(ndis_status *,
133 ndis_handle, uint32_t, unicode_string *, ndis_handle *);
134 static void NdisOpenConfigurationKeyByName(ndis_status *,
135 ndis_handle, unicode_string *, ndis_handle *);
136 static ndis_status ndis_encode_parm(ndis_miniport_block *,
137 struct sysctl_oid *, ndis_parm_type, ndis_config_parm **);
138 static ndis_status ndis_decode_parm(ndis_miniport_block *,
139 ndis_config_parm *, char *);
140 static void NdisReadConfiguration(ndis_status *, ndis_config_parm **,
141 ndis_handle, unicode_string *, ndis_parm_type);
142 static void NdisWriteConfiguration(ndis_status *, ndis_handle,
143 unicode_string *, ndis_config_parm *);
144 static void NdisCloseConfiguration(ndis_handle);
145 static void NdisAllocateSpinLock(ndis_spin_lock *);
146 static void NdisFreeSpinLock(ndis_spin_lock *);
147 static void NdisAcquireSpinLock(ndis_spin_lock *);
148 static void NdisReleaseSpinLock(ndis_spin_lock *);
149 static void NdisDprAcquireSpinLock(ndis_spin_lock *);
150 static void NdisDprReleaseSpinLock(ndis_spin_lock *);
151 static void NdisInitializeReadWriteLock(ndis_rw_lock *);
152 static void NdisAcquireReadWriteLock(ndis_rw_lock *,
153 uint8_t, ndis_lock_state *);
154 static void NdisReleaseReadWriteLock(ndis_rw_lock *, ndis_lock_state *);
155 static uint32_t NdisReadPciSlotInformation(ndis_handle, uint32_t,
156 uint32_t, void *, uint32_t);
157 static uint32_t NdisWritePciSlotInformation(ndis_handle, uint32_t,
158 uint32_t, void *, uint32_t);
159 static void NdisWriteErrorLogEntry(ndis_handle, ndis_error_code, uint32_t, ...);
160 static void ndis_map_cb(void *, bus_dma_segment_t *, int, int);
161 static void NdisMStartBufferPhysicalMapping(ndis_handle,
162 ndis_buffer *, uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *);
163 static void NdisMCompleteBufferPhysicalMapping(ndis_handle,
164 ndis_buffer *, uint32_t);
165 static void NdisMInitializeTimer(ndis_miniport_timer *, ndis_handle,
166 ndis_timer_function, void *);
167 static void NdisInitializeTimer(ndis_timer *,
168 ndis_timer_function, void *);
169 static void NdisSetTimer(ndis_timer *, uint32_t);
170 static void NdisMSetPeriodicTimer(ndis_miniport_timer *, uint32_t);
171 static void NdisMCancelTimer(ndis_timer *, uint8_t *);
172 static void ndis_timercall(kdpc *, ndis_miniport_timer *,
174 static void NdisMQueryAdapterResources(ndis_status *, ndis_handle,
175 ndis_resource_list *, uint32_t *);
176 static ndis_status NdisMRegisterIoPortRange(void **,
177 ndis_handle, uint32_t, uint32_t);
178 static void NdisMDeregisterIoPortRange(ndis_handle,
179 uint32_t, uint32_t, void *);
180 static void NdisReadNetworkAddress(ndis_status *, void **,
181 uint32_t *, ndis_handle);
182 static ndis_status NdisQueryMapRegisterCount(uint32_t, uint32_t *);
183 static ndis_status NdisMAllocateMapRegisters(ndis_handle,
184 uint32_t, uint8_t, uint32_t, uint32_t);
185 static void NdisMFreeMapRegisters(ndis_handle);
186 static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int);
187 static void NdisMAllocateSharedMemory(ndis_handle, uint32_t,
188 uint8_t, void **, ndis_physaddr *);
189 static void ndis_asyncmem_complete(device_object *, void *);
190 static ndis_status NdisMAllocateSharedMemoryAsync(ndis_handle,
191 uint32_t, uint8_t, void *);
192 static void NdisMFreeSharedMemory(ndis_handle, uint32_t,
193 uint8_t, void *, ndis_physaddr);
194 static ndis_status NdisMMapIoSpace(void **, ndis_handle,
195 ndis_physaddr, uint32_t);
196 static void NdisMUnmapIoSpace(ndis_handle, void *, uint32_t);
197 static uint32_t NdisGetCacheFillSize(void);
198 static uint32_t NdisMGetDmaAlignment(ndis_handle);
199 static ndis_status NdisMInitializeScatterGatherDma(ndis_handle,
201 static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **);
202 static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **);
203 static void NdisAllocateBufferPool(ndis_status *,
204 ndis_handle *, uint32_t);
205 static void NdisFreeBufferPool(ndis_handle);
206 static void NdisAllocateBuffer(ndis_status *, ndis_buffer **,
207 ndis_handle, void *, uint32_t);
208 static void NdisFreeBuffer(ndis_buffer *);
209 static uint32_t NdisBufferLength(ndis_buffer *);
210 static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *);
211 static void NdisQueryBufferSafe(ndis_buffer *, void **,
212 uint32_t *, uint32_t);
213 static void *NdisBufferVirtualAddress(ndis_buffer *);
214 static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t);
215 static void NdisAdjustBufferLength(ndis_buffer *, int);
216 static uint32_t NdisInterlockedIncrement(uint32_t *);
217 static uint32_t NdisInterlockedDecrement(uint32_t *);
218 static void NdisInitializeEvent(ndis_event *);
219 static void NdisSetEvent(ndis_event *);
220 static void NdisResetEvent(ndis_event *);
221 static uint8_t NdisWaitEvent(ndis_event *, uint32_t);
222 static ndis_status NdisUnicodeStringToAnsiString(ansi_string *,
225 NdisAnsiStringToUnicodeString(unicode_string *, ansi_string *);
226 static ndis_status NdisMPciAssignResources(ndis_handle,
227 uint32_t, ndis_resource_list **);
228 static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *,
229 ndis_handle, uint32_t, uint32_t, uint8_t,
230 uint8_t, ndis_interrupt_mode);
231 static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *);
232 static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *,
233 ndis_shutdown_handler);
234 static void NdisMDeregisterAdapterShutdownHandler(ndis_handle);
235 static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *);
236 static void NdisGetBufferPhysicalArraySize(ndis_buffer *,
238 static void NdisQueryBufferOffset(ndis_buffer *,
239 uint32_t *, uint32_t *);
240 static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle,
241 uint32_t, void *, uint32_t);
242 static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle,
243 uint32_t, void *, uint32_t);
244 static list_entry *NdisInterlockedInsertHeadList(list_entry *,
245 list_entry *, ndis_spin_lock *);
246 static list_entry *NdisInterlockedRemoveHeadList(list_entry *,
248 static list_entry *NdisInterlockedInsertTailList(list_entry *,
249 list_entry *, ndis_spin_lock *);
251 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *,
253 static void NdisGetCurrentSystemTime(uint64_t *);
254 static void NdisGetSystemUpTime(uint32_t *);
255 static void NdisInitializeString(unicode_string *, char *);
256 static void NdisInitAnsiString(ansi_string *, char *);
257 static void NdisInitUnicodeString(unicode_string *, uint16_t *);
258 static void NdisFreeString(unicode_string *);
259 static ndis_status NdisMRemoveMiniport(ndis_handle *);
260 static void NdisTerminateWrapper(ndis_handle, void *);
261 static void NdisMGetDeviceProperty(ndis_handle, device_object **,
262 device_object **, device_object **, cm_resource_list *,
264 static void NdisGetFirstBufferFromPacket(ndis_packet *,
265 ndis_buffer **, void **, uint32_t *, uint32_t *);
266 static void NdisGetFirstBufferFromPacketSafe(ndis_packet *,
267 ndis_buffer **, void **, uint32_t *, uint32_t *, uint32_t);
268 static int ndis_find_sym(linker_file_t, char *, char *, caddr_t *);
269 static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *,
270 unicode_string *, ndis_physaddr);
271 static void NdisMapFile(ndis_status *, void **, ndis_handle);
272 static void NdisUnmapFile(ndis_handle);
273 static void NdisCloseFile(ndis_handle);
274 static uint8_t NdisSystemProcessorCount(void);
275 static void NdisMIndicateStatusComplete(ndis_handle);
276 static void NdisMIndicateStatus(ndis_handle, ndis_status,
278 static uint8_t ndis_intr(kinterrupt *, void *);
279 static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *);
280 static funcptr ndis_findwrap(funcptr);
281 static void NdisCopyFromPacketToPacket(ndis_packet *,
282 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *);
283 static void NdisCopyFromPacketToPacketSafe(ndis_packet *,
284 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t);
285 static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *);
286 static ndis_status NdisMRegisterDevice(ndis_handle,
287 unicode_string *, unicode_string *, driver_dispatch **,
288 void **, ndis_handle *);
289 static ndis_status NdisMDeregisterDevice(ndis_handle);
291 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
292 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
293 static void dummy(void);
296 * Some really old drivers do not properly check the return value
297 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
298 * sometimes allocate few more buffers/packets that they originally
299 * requested when they created the pool. To prevent this from being
300 * a problem, we allocate a few extra buffers/packets beyond what
301 * the driver asks for. This #define controls how many.
303 #define NDIS_POOL_EXTRA 16
308 image_patch_table *patch;
310 strcpy(ndis_filepath, "/compat/ndis");
312 patch = ndis_functbl;
313 while (patch->ipt_func != NULL) {
314 windrv_wrap((funcptr)patch->ipt_func,
315 (funcptr *)&patch->ipt_wrap,
316 patch->ipt_argcnt, patch->ipt_ftype);
326 image_patch_table *patch;
328 patch = ndis_functbl;
329 while (patch->ipt_func != NULL) {
330 windrv_unwrap(patch->ipt_wrap);
341 image_patch_table *patch;
343 patch = ndis_functbl;
344 while (patch->ipt_func != NULL) {
345 if ((funcptr)patch->ipt_func == func)
346 return((funcptr)patch->ipt_wrap);
354 * This routine does the messy Windows Driver Model device attachment
355 * stuff on behalf of NDIS drivers. We register our own AddDevice
359 NdisInitializeWrapper(wrapper, drv, path, unused)
360 ndis_handle *wrapper;
366 * As of yet, I haven't come up with a compelling
367 * reason to define a private NDIS wrapper structure,
368 * so we use a pointer to the driver object as the
369 * wrapper handle. The driver object has the miniport
370 * characteristics struct for this driver hung off it
371 * via IoAllocateDriverObjectExtension(), and that's
372 * really all the private data we need.
378 * If this was really Windows, we'd be registering dispatch
379 * routines for the NDIS miniport module here, but we're
380 * not Windows so all we really need to do is set up an
381 * AddDevice function that'll be invoked when a new device
385 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
391 NdisTerminateWrapper(handle, syspec)
395 /* Nothing to see here, move along. */
400 NdisMRegisterMiniport(handle, characteristics, len)
402 ndis_miniport_characteristics *characteristics;
405 ndis_miniport_characteristics *ch = NULL;
408 drv = (driver_object *)handle;
411 * We need to save the NDIS miniport characteristics
412 * somewhere. This data is per-driver, not per-device
413 * (all devices handled by the same driver have the
414 * same characteristics) so we hook it onto the driver
415 * object using IoAllocateDriverObjectExtension().
416 * The extra extension info is automagically deleted when
417 * the driver is unloaded (see windrv_unload()).
420 if (IoAllocateDriverObjectExtension(drv, (void *)1,
421 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
423 return(NDIS_STATUS_RESOURCES);
426 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
428 bcopy((char *)characteristics, (char *)ch, len);
430 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
431 ch->nmc_shutdown_handler = NULL;
432 ch->nmc_canceltxpkts_handler = NULL;
433 ch->nmc_pnpevent_handler = NULL;
436 return(NDIS_STATUS_SUCCESS);
440 NdisAllocateMemoryWithTag(vaddr, len, tag)
447 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
449 return(NDIS_STATUS_RESOURCES);
453 return(NDIS_STATUS_SUCCESS);
457 NdisAllocateMemory(vaddr, len, flags, highaddr)
461 ndis_physaddr highaddr;
465 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
467 return(NDIS_STATUS_RESOURCES);
470 return(NDIS_STATUS_SUCCESS);
474 NdisFreeMemory(vaddr, len, flags)
488 NdisMSetAttributesEx(adapter_handle, adapter_ctx, hangsecs,
490 ndis_handle adapter_handle;
491 ndis_handle adapter_ctx;
494 ndis_interface_type iftype;
496 ndis_miniport_block *block;
499 * Save the adapter context, we need it for calling
500 * the driver's internal functions.
502 block = (ndis_miniport_block *)adapter_handle;
503 block->nmb_miniportadapterctx = adapter_ctx;
504 block->nmb_checkforhangsecs = hangsecs;
505 block->nmb_flags = flags;
507 return(NDIS_STATUS_SUCCESS);
511 NdisOpenConfiguration(status, cfg, wrapctx)
517 *status = NDIS_STATUS_SUCCESS;
523 NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle)
526 unicode_string *subkey;
527 ndis_handle *subhandle;
530 *status = NDIS_STATUS_SUCCESS;
536 NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle)
540 unicode_string *subkey;
541 ndis_handle *subhandle;
543 *status = NDIS_STATUS_FAILURE;
549 ndis_encode_parm(block, oid, type, parm)
550 ndis_miniport_block *block;
551 struct sysctl_oid *oid;
553 ndis_config_parm **parm;
556 ndis_parmlist_entry *np;
563 np = ExAllocatePoolWithTag(NonPagedPool,
564 sizeof(ndis_parmlist_entry), 0);
566 return(NDIS_STATUS_RESOURCES);
567 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
568 *parm = p = &np->np_parm;
571 case ndis_parm_string:
572 /* See if this might be a number. */
573 val = strtoul((char *)oid->oid_arg1, NULL, 10);
574 us = &p->ncp_parmdata.ncp_stringdata;
575 p->ncp_type = ndis_parm_string;
577 snprintf(tmp, 32, "%x", val);
578 RtlInitAnsiString(&as, tmp);
580 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
583 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
585 return(NDIS_STATUS_RESOURCES);
589 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
593 p->ncp_type = ndis_parm_int;
594 p->ncp_parmdata.ncp_intdata =
595 strtol((char *)oid->oid_arg1, NULL, base);
597 case ndis_parm_hexint:
599 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
605 p->ncp_type = ndis_parm_hexint;
606 p->ncp_parmdata.ncp_intdata =
607 strtoul((char *)oid->oid_arg1, NULL, base);
610 return(NDIS_STATUS_FAILURE);
614 return(NDIS_STATUS_SUCCESS);
618 NdisReadConfiguration(status, parm, cfg, key, type)
620 ndis_config_parm **parm;
626 ndis_miniport_block *block;
627 struct ndis_softc *sc;
628 struct sysctl_oid *oidp;
629 struct sysctl_ctx_entry *e;
632 block = (ndis_miniport_block *)cfg;
633 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
635 if (key->us_len == 0 || key->us_buf == NULL) {
636 *status = NDIS_STATUS_FAILURE;
640 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
641 *status = NDIS_STATUS_RESOURCES;
648 * See if registry key is already in a list of known keys
649 * included with the driver.
651 #if __FreeBSD_version < 502113
652 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
654 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
657 if (strcasecmp(oidp->oid_name, keystr) == 0) {
658 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
659 RtlFreeAnsiString(&as);
660 *status = NDIS_STATUS_FAILURE;
664 *status = ndis_encode_parm(block, oidp, type, parm);
665 RtlFreeAnsiString(&as);
671 * If the key didn't match, add it to the list of dynamically
672 * created ones. Sometimes, drivers refer to registry keys
673 * that aren't documented in their .INF files. These keys
674 * are supposed to be created by some sort of utility or
675 * control panel snap-in that comes with the driver software.
676 * Sometimes it's useful to be able to manipulate these.
677 * If the driver requests the key in the form of a string,
678 * make its default value an empty string, otherwise default
682 if (type == ndis_parm_int || type == ndis_parm_hexint)
683 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
684 "UNSET", CTLFLAG_RW);
686 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
687 "UNSET", CTLFLAG_RW);
689 RtlFreeAnsiString(&as);
690 *status = NDIS_STATUS_FAILURE;
696 ndis_decode_parm(block, parm, val)
697 ndis_miniport_block *block;
698 ndis_config_parm *parm;
701 unicode_string *ustr;
704 switch(parm->ncp_type) {
705 case ndis_parm_string:
706 ustr = &parm->ncp_parmdata.ncp_stringdata;
707 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
708 return(NDIS_STATUS_RESOURCES);
709 bcopy(as.as_buf, val, as.as_len);
710 RtlFreeAnsiString(&as);
713 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
715 case ndis_parm_hexint:
716 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
719 return(NDIS_STATUS_FAILURE);
722 return(NDIS_STATUS_SUCCESS);
726 NdisWriteConfiguration(status, cfg, key, parm)
730 ndis_config_parm *parm;
734 ndis_miniport_block *block;
735 struct ndis_softc *sc;
736 struct sysctl_oid *oidp;
737 struct sysctl_ctx_entry *e;
740 block = (ndis_miniport_block *)cfg;
741 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
743 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
744 *status = NDIS_STATUS_RESOURCES;
750 /* Decode the parameter into a string. */
751 bzero(val, sizeof(val));
752 *status = ndis_decode_parm(block, parm, val);
753 if (*status != NDIS_STATUS_SUCCESS) {
754 RtlFreeAnsiString(&as);
758 /* See if the key already exists. */
760 #if __FreeBSD_version < 502113
761 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
763 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
766 if (strcasecmp(oidp->oid_name, keystr) == 0) {
767 /* Found it, set the value. */
768 strcpy((char *)oidp->oid_arg1, val);
769 RtlFreeAnsiString(&as);
774 /* Not found, add a new key with the specified value. */
775 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
778 RtlFreeAnsiString(&as);
779 *status = NDIS_STATUS_SUCCESS;
784 NdisCloseConfiguration(cfg)
788 ndis_parmlist_entry *pe;
789 ndis_miniport_block *block;
792 block = (ndis_miniport_block *)cfg;
794 while (!IsListEmpty(&block->nmb_parmlist)) {
795 e = RemoveHeadList(&block->nmb_parmlist);
796 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
798 if (p->ncp_type == ndis_parm_string)
799 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
807 * Initialize a Windows spinlock.
810 NdisAllocateSpinLock(lock)
811 ndis_spin_lock *lock;
813 KeInitializeSpinLock(&lock->nsl_spinlock);
820 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
821 * for this. One is that it's sort of superfluous: we don't have to do anything
822 * special to deallocate the spinlock. The other is that there are some buggy
823 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
824 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
828 NdisFreeSpinLock(lock)
829 ndis_spin_lock *lock;
832 KeInitializeSpinLock(&lock->nsl_spinlock);
839 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
843 NdisAcquireSpinLock(lock)
844 ndis_spin_lock *lock;
846 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
851 * Release a spinlock from IRQL == DISPATCH_LEVEL.
855 NdisReleaseSpinLock(lock)
856 ndis_spin_lock *lock;
858 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
863 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
866 NdisDprAcquireSpinLock(lock)
867 ndis_spin_lock *lock;
869 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
874 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
877 NdisDprReleaseSpinLock(lock)
878 ndis_spin_lock *lock;
880 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
885 NdisInitializeReadWriteLock(lock)
888 KeInitializeSpinLock(&lock->nrl_spinlock);
889 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
894 NdisAcquireReadWriteLock(ndis_rw_lock *lock, uint8_t writeacc,
895 ndis_lock_state *state)
897 if (writeacc == TRUE) {
898 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
907 NdisReleaseReadWriteLock(lock, state)
909 ndis_lock_state *state;
911 if (lock->nrl_rsvd[0]) {
913 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
921 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
928 ndis_miniport_block *block;
933 block = (ndis_miniport_block *)adapter;
938 dev = block->nmb_physdeviceobj->do_devext;
941 * I have a test system consisting of a Sun w2100z
942 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
943 * "Aries" miniPCI NIC. (The NIC is installed in the
944 * machine using a miniPCI to PCI bus adapter card.)
945 * When running in SMP mode, I found that
946 * performing a large number of consecutive calls to
947 * NdisReadPciSlotInformation() would result in a
948 * sudden system reset (or in some cases a freeze).
949 * My suspicion is that the multiple reads are somehow
950 * triggering a fatal PCI bus error that leads to a
951 * machine check. The 1us delay in the loop below
952 * seems to prevent this problem.
955 for (i = 0; i < len; i++) {
957 dest[i] = pci_read_config(dev, i + offset, 1);
964 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
971 ndis_miniport_block *block;
976 block = (ndis_miniport_block *)adapter;
982 dev = block->nmb_physdeviceobj->do_devext;
983 for (i = 0; i < len; i++) {
985 pci_write_config(dev, i + offset, dest[i], 1);
992 * The errorlog routine uses a variable argument list, so we
993 * have to declare it this way.
996 #define ERRMSGLEN 512
998 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
999 uint32_t numerrors, ...)
1001 ndis_miniport_block *block;
1008 struct ndis_softc *sc;
1011 ansi_string as = { 0, 0, NULL };
1013 block = (ndis_miniport_block *)adapter;
1014 dev = block->nmb_physdeviceobj->do_devext;
1015 drv = block->nmb_deviceobj->do_drvobj;
1016 sc = device_get_softc(dev);
1019 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1020 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
1021 code, &str, &i, &flags);
1023 if (flags & MESSAGE_RESOURCE_UNICODE) {
1024 RtlInitUnicodeString(&us, (uint16_t *)str);
1025 if (RtlUnicodeStringToAnsiString(&as,
1026 &us, TRUE) == STATUS_SUCCESS)
1034 device_printf (dev, "NDIS ERROR: %x (%s)\n", code,
1035 str == NULL ? "unknown error" : str);
1037 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1038 device_printf (dev, "NDIS NUMERRORS: %x\n", numerrors);
1039 va_start(ap, numerrors);
1040 for (i = 0; i < numerrors; i++)
1041 device_printf (dev, "argptr: %p\n",
1042 va_arg(ap, void *));
1047 RtlFreeAnsiString(&as);
1053 ndis_map_cb(arg, segs, nseg, error)
1055 bus_dma_segment_t *segs;
1059 struct ndis_map_arg *ctx;
1067 for (i = 0; i < nseg; i++) {
1068 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1069 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1072 ctx->nma_cnt = nseg;
1078 NdisMStartBufferPhysicalMapping(ndis_handle adapter, ndis_buffer *buf,
1079 uint32_t mapreg, uint8_t writedev, ndis_paddr_unit *addrarray,
1080 uint32_t *arraysize)
1082 ndis_miniport_block *block;
1083 struct ndis_softc *sc;
1084 struct ndis_map_arg nma;
1088 if (adapter == NULL)
1091 block = (ndis_miniport_block *)adapter;
1092 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1094 if (mapreg > sc->ndis_mmapcnt)
1097 map = sc->ndis_mmaps[mapreg];
1098 nma.nma_fraglist = addrarray;
1100 error = bus_dmamap_load(sc->ndis_mtag, map,
1101 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1102 (void *)&nma, BUS_DMA_NOWAIT);
1107 bus_dmamap_sync(sc->ndis_mtag, map,
1108 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1110 *arraysize = nma.nma_cnt;
1116 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1117 ndis_handle adapter;
1121 ndis_miniport_block *block;
1122 struct ndis_softc *sc;
1125 if (adapter == NULL)
1128 block = (ndis_miniport_block *)adapter;
1129 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1131 if (mapreg > sc->ndis_mmapcnt)
1134 map = sc->ndis_mmaps[mapreg];
1136 bus_dmamap_sync(sc->ndis_mtag, map,
1137 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1139 bus_dmamap_unload(sc->ndis_mtag, map);
1145 * This is an older (?) timer init routine which doesn't
1146 * accept a miniport context handle. Serialized miniports should
1147 * never call this function.
1151 NdisInitializeTimer(timer, func, ctx)
1153 ndis_timer_function func;
1156 KeInitializeTimer(&timer->nt_ktimer);
1157 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1158 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1164 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1166 ndis_miniport_timer *timer;
1171 * Since we're called as a DPC, we should be running
1172 * at DISPATCH_LEVEL here. This means to acquire the
1173 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1174 * rather than KeAcquireSpinLock().
1176 if (NDIS_SERIALIZED(timer->nmt_block))
1177 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1179 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1182 if (NDIS_SERIALIZED(timer->nmt_block))
1183 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1189 * For a long time I wondered why there were two NDIS timer initialization
1190 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1191 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1192 * function and context pointers separate from those in the DPC, which
1193 * allows for another level of indirection: when the timer fires, we
1194 * can have our own timer function invoked, and from there we can call
1195 * the driver's function. But why go to all that trouble? Then it hit
1196 * me: for serialized miniports, the timer callouts are not re-entrant.
1197 * By trapping the callouts and having access to the MiniportAdapterHandle,
1198 * we can protect the driver callouts by acquiring the NDIS serialization
1199 * lock. This is essential for allowing serialized miniports to work
1200 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1201 * is enough to prevent other threads from pre-empting you, but with
1202 * SMP, you must acquire a lock as well, otherwise the other CPU is
1203 * free to clobber you.
1206 NdisMInitializeTimer(timer, handle, func, ctx)
1207 ndis_miniport_timer *timer;
1209 ndis_timer_function func;
1212 /* Save the driver's funcptr and context */
1214 timer->nmt_timerfunc = func;
1215 timer->nmt_timerctx = ctx;
1216 timer->nmt_block = handle;
1219 * Set up the timer so it will call our intermediate DPC.
1220 * Be sure to use the wrapped entry point, since
1221 * ntoskrnl_run_dpc() expects to invoke a function with
1222 * Microsoft calling conventions.
1224 KeInitializeTimer(&timer->nmt_ktimer);
1225 KeInitializeDpc(&timer->nmt_kdpc,
1226 ndis_findwrap((funcptr)ndis_timercall), timer);
1227 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1233 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1234 * but the former is just a macro wrapper around the latter.
1237 NdisSetTimer(timer, msecs)
1242 * KeSetTimer() wants the period in
1243 * hundred nanosecond intervals.
1245 KeSetTimer(&timer->nt_ktimer,
1246 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1252 NdisMSetPeriodicTimer(timer, msecs)
1253 ndis_miniport_timer *timer;
1256 KeSetTimerEx(&timer->nmt_ktimer,
1257 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1263 * Technically, this is really NdisCancelTimer(), but we also
1264 * (ab)use it for NdisMCancelTimer(), since in our implementation
1265 * we don't need the extra info in the ndis_miniport_timer
1266 * structure just to cancel a timer.
1270 NdisMCancelTimer(timer, cancelled)
1274 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1279 NdisMQueryAdapterResources(status, adapter, list, buflen)
1280 ndis_status *status;
1281 ndis_handle adapter;
1282 ndis_resource_list *list;
1285 ndis_miniport_block *block;
1286 struct ndis_softc *sc;
1289 block = (ndis_miniport_block *)adapter;
1290 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1292 rsclen = sizeof(ndis_resource_list) +
1293 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1294 if (*buflen < rsclen) {
1296 *status = NDIS_STATUS_INVALID_LENGTH;
1300 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1301 *status = NDIS_STATUS_SUCCESS;
1307 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1309 ndis_handle adapter;
1313 struct ndis_miniport_block *block;
1314 struct ndis_softc *sc;
1316 if (adapter == NULL)
1317 return(NDIS_STATUS_FAILURE);
1319 block = (ndis_miniport_block *)adapter;
1320 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1322 if (sc->ndis_res_io == NULL)
1323 return(NDIS_STATUS_FAILURE);
1325 /* Don't let the device map more ports than we have. */
1326 if (rman_get_size(sc->ndis_res_io) < numports)
1327 return(NDIS_STATUS_INVALID_LENGTH);
1329 *offset = (void *)rman_get_start(sc->ndis_res_io);
1331 return(NDIS_STATUS_SUCCESS);
1335 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1336 ndis_handle adapter;
1345 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1346 ndis_status *status;
1349 ndis_handle adapter;
1351 struct ndis_softc *sc;
1352 ndis_miniport_block *block;
1353 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1355 block = (ndis_miniport_block *)adapter;
1356 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1357 if (sc->ifp == NULL) {
1358 *status = NDIS_STATUS_FAILURE;
1363 if (bcmp(IFP2ENADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1364 #elif __FreeBSD_version >= 700000
1365 if (sc->ifp->if_addr == NULL ||
1366 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1368 if (bcmp(sc->arpcom.ac_enaddr, empty, ETHER_ADDR_LEN) == 0)
1370 *status = NDIS_STATUS_FAILURE;
1373 *addr = IFP2ENADDR(sc->ifp);
1374 #elif __FreeBSD_version >= 700000
1375 *addr = IF_LLADDR(sc->ifp);
1377 *addr = sc->arpcom.ac_enaddr;
1379 *addrlen = ETHER_ADDR_LEN;
1380 *status = NDIS_STATUS_SUCCESS;
1387 NdisQueryMapRegisterCount(bustype, cnt)
1392 return(NDIS_STATUS_SUCCESS);
1396 NdisMAllocateMapRegisters(ndis_handle adapter, uint32_t dmachannel,
1397 uint8_t dmasize, uint32_t physmapneeded, uint32_t maxmap)
1399 struct ndis_softc *sc;
1400 ndis_miniport_block *block;
1401 int error, i, nseg = NDIS_MAXSEG;
1403 block = (ndis_miniport_block *)adapter;
1404 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1406 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1407 M_DEVBUF, M_NOWAIT|M_ZERO);
1409 if (sc->ndis_mmaps == NULL)
1410 return(NDIS_STATUS_RESOURCES);
1412 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1413 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1414 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1415 NULL, NULL, &sc->ndis_mtag);
1418 free(sc->ndis_mmaps, M_DEVBUF);
1419 return(NDIS_STATUS_RESOURCES);
1422 for (i = 0; i < physmapneeded; i++)
1423 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1425 sc->ndis_mmapcnt = physmapneeded;
1427 return(NDIS_STATUS_SUCCESS);
1431 NdisMFreeMapRegisters(adapter)
1432 ndis_handle adapter;
1434 struct ndis_softc *sc;
1435 ndis_miniport_block *block;
1438 block = (ndis_miniport_block *)adapter;
1439 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1441 for (i = 0; i < sc->ndis_mmapcnt; i++)
1442 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1444 free(sc->ndis_mmaps, M_DEVBUF);
1446 bus_dma_tag_destroy(sc->ndis_mtag);
1452 ndis_mapshared_cb(arg, segs, nseg, error)
1454 bus_dma_segment_t *segs;
1460 if (error || nseg > 1)
1465 p->np_quad = segs[0].ds_addr;
1471 * This maps to bus_dmamem_alloc().
1475 NdisMAllocateSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1476 void **vaddr, ndis_physaddr *paddr)
1478 ndis_miniport_block *block;
1479 struct ndis_softc *sc;
1480 struct ndis_shmem *sh;
1483 if (adapter == NULL)
1486 block = (ndis_miniport_block *)adapter;
1487 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1489 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1493 InitializeListHead(&sh->ndis_list);
1496 * When performing shared memory allocations, create a tag
1497 * with a lowaddr limit that restricts physical memory mappings
1498 * so that they all fall within the first 1GB of memory.
1499 * At least one device/driver combination (Linksys Instant
1500 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1501 * problems with performing DMA operations with physical
1502 * addresses that lie above the 1GB mark. I don't know if this
1503 * is a hardware limitation or if the addresses are being
1504 * truncated within the driver, but this seems to be the only
1505 * way to make these cards work reliably in systems with more
1506 * than 1GB of physical memory.
1509 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1510 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1511 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1519 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1520 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1523 bus_dma_tag_destroy(sh->ndis_stag);
1528 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1529 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1532 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1533 bus_dma_tag_destroy(sh->ndis_stag);
1539 * Save the physical address along with the source address.
1540 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1541 * with a bogus virtual address sometimes, but with a valid
1542 * physical address. To keep this from causing trouble, we
1543 * use the physical address to as a sanity check in case
1544 * searching based on the virtual address fails.
1548 sh->ndis_paddr.np_quad = paddr->np_quad;
1549 sh->ndis_saddr = *vaddr;
1550 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1556 struct ndis_allocwork {
1564 ndis_asyncmem_complete(dobj, arg)
1565 device_object *dobj;
1568 ndis_miniport_block *block;
1569 struct ndis_softc *sc;
1570 struct ndis_allocwork *w;
1572 ndis_physaddr paddr;
1573 ndis_allocdone_handler donefunc;
1576 block = (ndis_miniport_block *)dobj->do_devext;
1577 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1582 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1583 NdisMAllocateSharedMemory(block, w->na_len,
1584 w->na_cached, &vaddr, &paddr);
1585 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1587 IoFreeWorkItem(w->na_iw);
1594 NdisMAllocateSharedMemoryAsync(ndis_handle adapter, uint32_t len,
1595 uint8_t cached, void *ctx)
1597 ndis_miniport_block *block;
1598 struct ndis_allocwork *w;
1600 io_workitem_func ifw;
1602 if (adapter == NULL)
1603 return(NDIS_STATUS_FAILURE);
1607 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1609 return(NDIS_STATUS_FAILURE);
1611 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1614 return(NDIS_STATUS_FAILURE);
1616 w->na_cached = cached;
1621 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1622 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1624 return(NDIS_STATUS_PENDING);
1628 NdisMFreeSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1629 void *vaddr, ndis_physaddr paddr)
1631 ndis_miniport_block *block;
1632 struct ndis_softc *sc;
1633 struct ndis_shmem *sh = NULL;
1636 if (vaddr == NULL || adapter == NULL)
1639 block = (ndis_miniport_block *)adapter;
1640 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1642 /* Sanity check: is list empty? */
1644 if (IsListEmpty(&sc->ndis_shlist))
1648 l = sc->ndis_shlist.nle_flink;
1649 while (l != &sc->ndis_shlist) {
1650 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1651 if (sh->ndis_saddr == vaddr)
1654 * Check the physaddr too, just in case the driver lied
1655 * about the virtual address.
1657 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1664 printf("NDIS: buggy driver tried to free "
1665 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1666 vaddr, (uintmax_t)paddr.np_quad);
1670 RemoveEntryList(&sh->ndis_list);
1674 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1675 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1676 bus_dma_tag_destroy(sh->ndis_stag);
1684 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1686 ndis_handle adapter;
1687 ndis_physaddr paddr;
1690 if (adapter == NULL)
1691 return(NDIS_STATUS_FAILURE);
1693 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1696 return(NDIS_STATUS_FAILURE);
1698 return(NDIS_STATUS_SUCCESS);
1702 NdisMUnmapIoSpace(adapter, vaddr, len)
1703 ndis_handle adapter;
1707 MmUnmapIoSpace(vaddr, len);
1712 NdisGetCacheFillSize(void)
1718 NdisMGetDmaAlignment(handle)
1725 * NDIS has two methods for dealing with NICs that support DMA.
1726 * One is to just pass packets to the driver and let it call
1727 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1728 * all by itself, and the other is to let the NDIS library handle the
1729 * buffer mapping internally, and hand the driver an already populated
1730 * scatter/gather fragment list. If the driver calls
1731 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1736 NdisMInitializeScatterGatherDma(ndis_handle adapter, uint8_t is64,
1737 uint32_t maxphysmap)
1739 struct ndis_softc *sc;
1740 ndis_miniport_block *block;
1743 if (adapter == NULL)
1744 return(NDIS_STATUS_FAILURE);
1745 block = (ndis_miniport_block *)adapter;
1746 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1748 /* Don't do this twice. */
1749 if (sc->ndis_sc == 1)
1750 return(NDIS_STATUS_SUCCESS);
1752 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1753 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1754 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1755 NULL, NULL, &sc->ndis_ttag);
1759 return(NDIS_STATUS_SUCCESS);
1763 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1764 ndis_status *status;
1767 uint32_t protrsvdlen;
1769 ndis_packet_pool *p;
1770 ndis_packet *packets;
1773 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1775 *status = NDIS_STATUS_RESOURCES;
1779 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1780 p->np_protrsvd = protrsvdlen;
1781 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1783 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1787 if (packets == NULL) {
1789 *status = NDIS_STATUS_RESOURCES;
1793 p->np_pktmem = packets;
1795 for (i = 0; i < p->np_cnt; i++)
1796 InterlockedPushEntrySList(&p->np_head,
1797 (struct slist_entry *)&packets[i]);
1799 #ifdef NDIS_DEBUG_PACKETS
1801 KeInitializeSpinLock(&p->np_lock);
1802 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1806 *status = NDIS_STATUS_SUCCESS;
1811 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1812 ndis_status *status;
1815 uint32_t oflowdescnum;
1816 uint32_t protrsvdlen;
1818 return(NdisAllocatePacketPool(status, pool,
1819 descnum + oflowdescnum, protrsvdlen));
1823 NdisPacketPoolUsage(pool)
1826 ndis_packet_pool *p;
1828 p = (ndis_packet_pool *)pool;
1829 return(p->np_cnt - ExQueryDepthSList(&p->np_head));
1833 NdisFreePacketPool(pool)
1836 ndis_packet_pool *p;
1838 #ifdef NDIS_DEBUG_PACKETS
1842 p = (ndis_packet_pool *)pool;
1844 #ifdef NDIS_DEBUG_PACKETS
1845 KeAcquireSpinLock(&p->np_lock, &irql);
1848 usage = NdisPacketPoolUsage(pool);
1850 #ifdef NDIS_DEBUG_PACKETS
1853 KeResetEvent(&p->np_event);
1854 KeReleaseSpinLock(&p->np_lock, irql);
1855 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1857 KeReleaseSpinLock(&p->np_lock, irql);
1860 ExFreePool(p->np_pktmem);
1867 NdisAllocatePacket(status, packet, pool)
1868 ndis_status *status;
1869 ndis_packet **packet;
1872 ndis_packet_pool *p;
1874 #ifdef NDIS_DEBUG_PACKETS
1878 p = (ndis_packet_pool *)pool;
1880 #ifdef NDIS_DEBUG_PACKETS
1881 KeAcquireSpinLock(&p->np_lock, &irql);
1883 KeReleaseSpinLock(&p->np_lock, irql);
1884 printf("NDIS: tried to allocate packet from dead pool %p\n",
1886 *status = NDIS_STATUS_RESOURCES;
1891 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1893 #ifdef NDIS_DEBUG_PACKETS
1894 KeReleaseSpinLock(&p->np_lock, irql);
1898 *status = NDIS_STATUS_RESOURCES;
1903 bzero((char *)pkt, sizeof(ndis_packet));
1905 /* Save pointer to the pool. */
1906 pkt->np_private.npp_pool = pool;
1908 /* Set the oob offset pointer. Lots of things expect this. */
1909 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1912 * We must initialize the packet flags correctly in order
1913 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1914 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1917 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1918 pkt->np_private.npp_validcounts = FALSE;
1922 *status = NDIS_STATUS_SUCCESS;
1928 NdisFreePacket(packet)
1929 ndis_packet *packet;
1931 ndis_packet_pool *p;
1932 #ifdef NDIS_DEBUG_PACKETS
1936 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1938 #ifdef NDIS_DEBUG_PACKETS
1939 KeAcquireSpinLock(&p->np_lock, &irql);
1942 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1944 #ifdef NDIS_DEBUG_PACKETS
1946 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1947 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1949 KeReleaseSpinLock(&p->np_lock, irql);
1956 NdisUnchainBufferAtFront(packet, buf)
1957 ndis_packet *packet;
1960 ndis_packet_private *priv;
1962 if (packet == NULL || buf == NULL)
1965 priv = &packet->np_private;
1967 priv->npp_validcounts = FALSE;
1969 if (priv->npp_head == priv->npp_tail) {
1970 *buf = priv->npp_head;
1971 priv->npp_head = priv->npp_tail = NULL;
1973 *buf = priv->npp_head;
1974 priv->npp_head = (*buf)->mdl_next;
1981 NdisUnchainBufferAtBack(packet, buf)
1982 ndis_packet *packet;
1985 ndis_packet_private *priv;
1988 if (packet == NULL || buf == NULL)
1991 priv = &packet->np_private;
1993 priv->npp_validcounts = FALSE;
1995 if (priv->npp_head == priv->npp_tail) {
1996 *buf = priv->npp_head;
1997 priv->npp_head = priv->npp_tail = NULL;
1999 *buf = priv->npp_tail;
2000 tmp = priv->npp_head;
2001 while (tmp->mdl_next != priv->npp_tail)
2002 tmp = tmp->mdl_next;
2003 priv->npp_tail = tmp;
2004 tmp->mdl_next = NULL;
2011 * The NDIS "buffer" is really an MDL (memory descriptor list)
2012 * which is used to describe a buffer in a way that allows it
2013 * to mapped into different contexts. We have to be careful how
2014 * we handle them: in some versions of Windows, the NdisFreeBuffer()
2015 * routine is an actual function in the NDIS API, but in others
2016 * it's just a macro wrapper around IoFreeMdl(). There's really
2017 * no way to use the 'descnum' parameter to count how many
2018 * "buffers" are allocated since in order to use IoFreeMdl() to
2019 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
2020 * them, and IoAllocateMdl() just grabs them out of the heap.
2024 NdisAllocateBufferPool(status, pool, descnum)
2025 ndis_status *status;
2031 * The only thing we can really do here is verify that descnum
2032 * is a reasonable value, but I really don't know what to check
2036 *pool = NonPagedPool;
2037 *status = NDIS_STATUS_SUCCESS;
2042 NdisFreeBufferPool(pool)
2049 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
2050 ndis_status *status;
2051 ndis_buffer **buffer;
2058 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
2060 *status = NDIS_STATUS_RESOURCES;
2064 MmBuildMdlForNonPagedPool(buf);
2067 *status = NDIS_STATUS_SUCCESS;
2083 NdisBufferLength(buf)
2086 return(MmGetMdlByteCount(buf));
2090 * Get the virtual address and length of a buffer.
2091 * Note: the vaddr argument is optional.
2095 NdisQueryBuffer(buf, vaddr, len)
2101 *vaddr = MmGetMdlVirtualAddress(buf);
2102 *len = MmGetMdlByteCount(buf);
2107 /* Same as above -- we don't care about the priority. */
2110 NdisQueryBufferSafe(buf, vaddr, len, prio)
2117 *vaddr = MmGetMdlVirtualAddress(buf);
2118 *len = MmGetMdlByteCount(buf);
2123 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2126 NdisBufferVirtualAddress(buf)
2129 return(MmGetMdlVirtualAddress(buf));
2133 NdisBufferVirtualAddressSafe(buf, prio)
2137 return(MmGetMdlVirtualAddress(buf));
2141 NdisAdjustBufferLength(buf, len)
2145 MmGetMdlByteCount(buf) = len;
2151 NdisInterlockedIncrement(addend)
2154 atomic_add_long((u_long *)addend, 1);
2159 NdisInterlockedDecrement(addend)
2162 atomic_subtract_long((u_long *)addend, 1);
2167 NdisInitializeEvent(event)
2171 * NDIS events are always notification
2172 * events, and should be initialized to the
2173 * not signaled state.
2175 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2183 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2188 NdisResetEvent(event)
2191 KeResetEvent(&event->ne_event);
2196 NdisWaitEvent(event, msecs)
2203 duetime = ((int64_t)msecs * -10000);
2204 rval = KeWaitForSingleObject(event,
2205 0, 0, TRUE, msecs ? & duetime : NULL);
2207 if (rval == STATUS_TIMEOUT)
2214 NdisUnicodeStringToAnsiString(dstr, sstr)
2216 unicode_string *sstr;
2220 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2222 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2223 return(NDIS_STATUS_RESOURCES);
2225 return(NDIS_STATUS_FAILURE);
2227 return (NDIS_STATUS_SUCCESS);
2231 NdisAnsiStringToUnicodeString(dstr, sstr)
2232 unicode_string *dstr;
2237 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2239 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2240 return(NDIS_STATUS_RESOURCES);
2242 return(NDIS_STATUS_FAILURE);
2244 return (NDIS_STATUS_SUCCESS);
2248 NdisMPciAssignResources(adapter, slot, list)
2249 ndis_handle adapter;
2251 ndis_resource_list **list;
2253 ndis_miniport_block *block;
2255 if (adapter == NULL || list == NULL)
2256 return (NDIS_STATUS_FAILURE);
2258 block = (ndis_miniport_block *)adapter;
2259 *list = block->nmb_rlist;
2261 return (NDIS_STATUS_SUCCESS);
2265 ndis_intr(iobj, arg)
2269 struct ndis_softc *sc;
2270 uint8_t is_our_intr = FALSE;
2272 ndis_miniport_interrupt *intr;
2275 intr = sc->ndis_block->nmb_interrupt;
2277 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2280 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2281 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2282 sc->ndis_block->nmb_miniportadapterctx);
2284 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2285 sc->ndis_block->nmb_miniportadapterctx);
2290 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2292 return(is_our_intr);
2296 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2298 ndis_miniport_interrupt *intr;
2302 struct ndis_softc *sc;
2303 ndis_miniport_block *block;
2304 ndis_handle adapter;
2306 block = intr->ni_block;
2307 adapter = block->nmb_miniportadapterctx;
2308 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2310 if (NDIS_SERIALIZED(sc->ndis_block))
2311 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2313 MSCALL1(intr->ni_dpcfunc, adapter);
2315 /* If there's a MiniportEnableInterrupt() routine, call it. */
2317 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2318 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2320 if (NDIS_SERIALIZED(sc->ndis_block))
2321 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2324 * Set the completion event if we've drained all
2325 * pending interrupts.
2328 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2330 if (intr->ni_dpccnt == 0)
2331 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2332 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2338 NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter,
2339 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared,
2340 ndis_interrupt_mode imode)
2342 ndis_miniport_block *block;
2343 ndis_miniport_characteristics *ch;
2344 struct ndis_softc *sc;
2348 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2349 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2352 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2353 sizeof(struct mtx), 0);
2354 if (intr->ni_rsvd == NULL)
2355 return(NDIS_STATUS_RESOURCES);
2357 intr->ni_block = adapter;
2358 intr->ni_isrreq = reqisr;
2359 intr->ni_shared = shared;
2360 intr->ni_dpccnt = 0;
2361 intr->ni_isrfunc = ch->nmc_isr_func;
2362 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2364 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2365 KeInitializeDpc(&intr->ni_dpc,
2366 ndis_findwrap((funcptr)ndis_intrhand), intr);
2367 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2369 error = IoConnectInterrupt(&intr->ni_introbj,
2370 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2371 ivec, ilevel, 0, imode, shared, 0, FALSE);
2373 if (error != STATUS_SUCCESS)
2374 return(NDIS_STATUS_FAILURE);
2376 block->nmb_interrupt = intr;
2378 return(NDIS_STATUS_SUCCESS);
2382 NdisMDeregisterInterrupt(intr)
2383 ndis_miniport_interrupt *intr;
2385 ndis_miniport_block *block;
2386 struct ndis_softc *sc;
2389 block = intr->ni_block;
2390 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2392 /* Should really be KeSynchronizeExecution() */
2394 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2395 block->nmb_interrupt = NULL;
2396 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2398 KeFlushQueuedDpcs();
2400 /* Disconnect our ISR */
2402 IoDisconnectInterrupt(intr->ni_introbj);
2404 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2405 KeResetEvent(&intr->ni_dpcevt);
2411 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2412 ndis_handle adapter;
2414 ndis_shutdown_handler shutdownfunc;
2416 ndis_miniport_block *block;
2417 ndis_miniport_characteristics *chars;
2418 struct ndis_softc *sc;
2420 if (adapter == NULL)
2423 block = (ndis_miniport_block *)adapter;
2424 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2425 chars = sc->ndis_chars;
2427 chars->nmc_shutdown_handler = shutdownfunc;
2428 chars->nmc_rsvd0 = shutdownctx;
2434 NdisMDeregisterAdapterShutdownHandler(adapter)
2435 ndis_handle adapter;
2437 ndis_miniport_block *block;
2438 ndis_miniport_characteristics *chars;
2439 struct ndis_softc *sc;
2441 if (adapter == NULL)
2444 block = (ndis_miniport_block *)adapter;
2445 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2446 chars = sc->ndis_chars;
2448 chars->nmc_shutdown_handler = NULL;
2449 chars->nmc_rsvd0 = NULL;
2455 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2460 if (MmGetMdlByteCount(buf) == 0)
2462 return(SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2463 MmGetMdlByteCount(buf)));
2467 NdisGetBufferPhysicalArraySize(buf, pages)
2474 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2479 NdisQueryBufferOffset(buf, off, len)
2487 *off = MmGetMdlByteOffset(buf);
2488 *len = MmGetMdlByteCount(buf);
2500 * During system bootstrap, (i.e. cold == 1), we aren't
2501 * allowed to sleep, so we have to do a hard DELAY()
2508 KeInitializeTimer(&timer);
2509 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2510 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2517 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2523 struct ndis_softc *sc;
2524 ndis_miniport_block *block;
2525 bus_space_handle_t bh;
2533 block = (ndis_miniport_block *)handle;
2534 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2537 bh = rman_get_bushandle(sc->ndis_res_am);
2538 bt = rman_get_bustag(sc->ndis_res_am);
2540 for (i = 0; i < len; i++)
2541 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2547 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2553 struct ndis_softc *sc;
2554 ndis_miniport_block *block;
2555 bus_space_handle_t bh;
2563 block = (ndis_miniport_block *)handle;
2564 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2567 bh = rman_get_bushandle(sc->ndis_res_am);
2568 bt = rman_get_bustag(sc->ndis_res_am);
2570 for (i = 0; i < len; i++)
2571 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2577 NdisInterlockedInsertHeadList(head, entry, lock)
2580 ndis_spin_lock *lock;
2584 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2585 flink = head->nle_flink;
2586 entry->nle_flink = flink;
2587 entry->nle_blink = head;
2588 flink->nle_blink = entry;
2589 head->nle_flink = entry;
2590 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2596 NdisInterlockedRemoveHeadList(head, lock)
2598 ndis_spin_lock *lock;
2603 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2604 entry = head->nle_flink;
2605 flink = entry->nle_flink;
2606 head->nle_flink = flink;
2607 flink->nle_blink = head;
2608 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2614 NdisInterlockedInsertTailList(head, entry, lock)
2617 ndis_spin_lock *lock;
2621 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2622 blink = head->nle_blink;
2623 entry->nle_flink = head;
2624 entry->nle_blink = blink;
2625 blink->nle_flink = entry;
2626 head->nle_blink = entry;
2627 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2633 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2634 ndis_miniport_interrupt *intr;
2638 return(KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2642 NdisGetCurrentSystemTime(tval)
2645 ntoskrnl_time(tval);
2650 * Return the number of milliseconds since the system booted.
2653 NdisGetSystemUpTime(tval)
2659 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2665 NdisInitializeString(dst, src)
2666 unicode_string *dst;
2670 RtlInitAnsiString(&as, src);
2671 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2677 unicode_string *str;
2679 RtlFreeUnicodeString(str);
2684 NdisMRemoveMiniport(adapter)
2685 ndis_handle *adapter;
2687 return(NDIS_STATUS_SUCCESS);
2691 NdisInitAnsiString(dst, src)
2695 RtlInitAnsiString(dst, src);
2700 NdisInitUnicodeString(dst, src)
2701 unicode_string *dst;
2704 RtlInitUnicodeString(dst, src);
2708 static void NdisMGetDeviceProperty(adapter, phydevobj,
2709 funcdevobj, nextdevobj, resources, transresources)
2710 ndis_handle adapter;
2711 device_object **phydevobj;
2712 device_object **funcdevobj;
2713 device_object **nextdevobj;
2714 cm_resource_list *resources;
2715 cm_resource_list *transresources;
2717 ndis_miniport_block *block;
2719 block = (ndis_miniport_block *)adapter;
2721 if (phydevobj != NULL)
2722 *phydevobj = block->nmb_physdeviceobj;
2723 if (funcdevobj != NULL)
2724 *funcdevobj = block->nmb_deviceobj;
2725 if (nextdevobj != NULL)
2726 *nextdevobj = block->nmb_nextdeviceobj;
2732 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2733 ndis_packet *packet;
2741 tmp = packet->np_private.npp_head;
2745 *firstlen = *totlen = 0;
2747 *firstva = MmGetMdlVirtualAddress(tmp);
2748 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2749 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2750 *totlen += MmGetMdlByteCount(tmp);
2757 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2758 ndis_packet *packet;
2765 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2769 ndis_find_sym(lf, filename, suffix, sym)
2779 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2780 if (fullsym == NULL)
2783 bzero(fullsym, MAXPATHLEN);
2784 strncpy(fullsym, filename, MAXPATHLEN);
2785 if (strlen(filename) < 4) {
2786 ExFreePool(fullsym);
2790 /* If the filename has a .ko suffix, strip if off. */
2791 suf = fullsym + (strlen(filename) - 3);
2792 if (strcmp(suf, ".ko") == 0)
2795 for (i = 0; i < strlen(fullsym); i++) {
2796 if (fullsym[i] == '.')
2799 fullsym[i] = tolower(fullsym[i]);
2801 strcat(fullsym, suffix);
2802 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2803 ExFreePool(fullsym);
2810 struct ndis_checkmodule {
2816 * See if a single module contains the symbols for a specified file.
2819 NdisCheckModule(linker_file_t lf, void *context)
2821 struct ndis_checkmodule *nc;
2822 caddr_t kldstart, kldend;
2824 nc = (struct ndis_checkmodule *)context;
2825 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2827 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2830 nc->fh->nf_map = NULL;
2831 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2832 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2836 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2838 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2839 ndis_status *status;
2840 ndis_handle *filehandle;
2841 uint32_t *filelength;
2842 unicode_string *filename;
2843 ndis_physaddr highestaddr;
2846 char *afilename = NULL;
2847 struct thread *td = curthread;
2848 struct nameidata nd;
2849 int flags, error, vfslocked;
2851 struct vattr *vap = &vat;
2854 struct ndis_checkmodule nc;
2856 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2857 *status = NDIS_STATUS_RESOURCES;
2861 afilename = strdup(as.as_buf, M_DEVBUF);
2862 RtlFreeAnsiString(&as);
2864 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2866 free(afilename, M_DEVBUF);
2867 *status = NDIS_STATUS_RESOURCES;
2871 fh->nf_name = afilename;
2874 * During system bootstrap, it's impossible to load files
2875 * from the rootfs since it's not mounted yet. We therefore
2876 * offer the possibility of opening files that have been
2877 * preloaded as modules instead. Both choices will work
2878 * when kldloading a module from multiuser, but only the
2879 * module option will work during bootstrap. The module
2880 * loading option works by using the ndiscvt(8) utility
2881 * to convert the arbitrary file into a .ko using objcopy(1).
2882 * This file will contain two special symbols: filename_start
2883 * and filename_end. All we have to do is traverse the KLD
2884 * list in search of those symbols and we've found the file
2885 * data. As an added bonus, ndiscvt(8) will also generate
2886 * a normal .o file which can be linked statically with
2887 * the kernel. This means that the symbols will actual reside
2888 * in the kernel's symbol table, but that doesn't matter to
2889 * us since the kernel appears to us as just another module.
2892 nc.afilename = afilename;
2894 if (linker_file_foreach(NdisCheckModule, &nc)) {
2895 *filelength = fh->nf_maplen;
2897 *status = NDIS_STATUS_SUCCESS;
2901 if (TAILQ_EMPTY(&mountlist)) {
2903 *status = NDIS_STATUS_FILE_NOT_FOUND;
2904 printf("NDIS: could not find file %s in linker list\n",
2906 printf("NDIS: and no filesystems mounted yet, "
2907 "aborting NdisOpenFile()\n");
2908 free(afilename, M_DEVBUF);
2912 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2915 free(afilename, M_DEVBUF);
2916 *status = NDIS_STATUS_RESOURCES;
2920 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2922 /* Some threads don't have a current working directory. */
2924 if (td->td_proc->p_fd->fd_rdir == NULL)
2925 td->td_proc->p_fd->fd_rdir = rootvnode;
2926 if (td->td_proc->p_fd->fd_cdir == NULL)
2927 td->td_proc->p_fd->fd_cdir = rootvnode;
2929 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td);
2932 error = vn_open(&nd, &flags, 0, NULL);
2934 *status = NDIS_STATUS_FILE_NOT_FOUND;
2936 printf("NDIS: open file %s failed: %d\n", path, error);
2938 free(afilename, M_DEVBUF);
2941 vfslocked = NDHASGIANT(&nd);
2945 NDFREE(&nd, NDF_ONLY_PNBUF);
2947 /* Get the file size. */
2948 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred, td);
2949 VOP_UNLOCK(nd.ni_vp, 0, td);
2950 VFS_UNLOCK_GIANT(vfslocked);
2952 fh->nf_vp = nd.ni_vp;
2954 fh->nf_type = NDIS_FH_TYPE_VFS;
2956 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2957 *status = NDIS_STATUS_SUCCESS;
2963 NdisMapFile(status, mappedbuffer, filehandle)
2964 ndis_status *status;
2965 void **mappedbuffer;
2966 ndis_handle filehandle;
2969 struct thread *td = curthread;
2972 int error, resid, vfslocked;
2975 if (filehandle == NULL) {
2976 *status = NDIS_STATUS_FAILURE;
2980 fh = (ndis_fh *)filehandle;
2982 if (fh->nf_vp == NULL) {
2983 *status = NDIS_STATUS_FAILURE;
2987 if (fh->nf_map != NULL) {
2988 *status = NDIS_STATUS_ALREADY_MAPPED;
2992 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
2994 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
2995 *status = NDIS_STATUS_FAILURE;
2998 fh->nf_map = kldstart;
2999 *status = NDIS_STATUS_SUCCESS;
3000 *mappedbuffer = fh->nf_map;
3004 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
3006 if (fh->nf_map == NULL) {
3007 *status = NDIS_STATUS_RESOURCES;
3012 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3013 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
3014 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
3015 VFS_UNLOCK_GIANT(vfslocked);
3018 *status = NDIS_STATUS_FAILURE;
3020 *status = NDIS_STATUS_SUCCESS;
3021 *mappedbuffer = fh->nf_map;
3028 NdisUnmapFile(filehandle)
3029 ndis_handle filehandle;
3032 fh = (ndis_fh *)filehandle;
3034 if (fh->nf_map == NULL)
3037 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3038 ExFreePool(fh->nf_map);
3045 NdisCloseFile(filehandle)
3046 ndis_handle filehandle;
3048 struct thread *td = curthread;
3053 if (filehandle == NULL)
3056 fh = (ndis_fh *)filehandle;
3057 if (fh->nf_map != NULL) {
3058 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3059 ExFreePool(fh->nf_map);
3063 if (fh->nf_vp == NULL)
3066 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
3068 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3069 vn_close(vp, FREAD, td->td_ucred, td);
3070 VFS_UNLOCK_GIANT(vfslocked);
3074 free(fh->nf_name, M_DEVBUF);
3081 NdisSystemProcessorCount()
3086 typedef void (*ndis_statusdone_handler)(ndis_handle);
3087 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
3091 NdisMIndicateStatusComplete(adapter)
3092 ndis_handle adapter;
3094 ndis_miniport_block *block;
3095 ndis_statusdone_handler statusdonefunc;
3097 block = (ndis_miniport_block *)adapter;
3098 statusdonefunc = block->nmb_statusdone_func;
3100 MSCALL1(statusdonefunc, adapter);
3105 NdisMIndicateStatus(adapter, status, sbuf, slen)
3106 ndis_handle adapter;
3111 ndis_miniport_block *block;
3112 ndis_status_handler statusfunc;
3114 block = (ndis_miniport_block *)adapter;
3115 statusfunc = block->nmb_status_func;
3117 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3122 * The DDK documentation says that you should use IoQueueWorkItem()
3123 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3124 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3125 * depends on the API semantics of ExQueueWorkItem(). In our world,
3126 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3129 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3130 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3131 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3132 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3133 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3134 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3135 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3136 * to ExQueueWorkItem().
3138 * Got all that? (Sheesh.)
3142 NdisScheduleWorkItem(work)
3143 ndis_work_item *work;
3145 work_queue_item *wqi;
3147 wqi = (work_queue_item *)work->nwi_wraprsvd;
3148 ExInitializeWorkItem(wqi,
3149 (work_item_func)work->nwi_func, work->nwi_ctx);
3150 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3152 return(NDIS_STATUS_SUCCESS);
3156 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3164 ndis_buffer *src, *dst;
3166 int resid, copied, len, scnt, dcnt;
3170 src = spkt->np_private.npp_head;
3171 dst = dpkt->np_private.npp_head;
3173 sptr = MmGetMdlVirtualAddress(src);
3174 dptr = MmGetMdlVirtualAddress(dst);
3175 scnt = MmGetMdlByteCount(src);
3176 dcnt = MmGetMdlByteCount(dst);
3179 if (MmGetMdlByteCount(src) > soff) {
3181 scnt = MmGetMdlByteCount(src)- soff;
3184 soff -= MmGetMdlByteCount(src);
3185 src = src->mdl_next;
3188 sptr = MmGetMdlVirtualAddress(src);
3192 if (MmGetMdlByteCount(dst) > doff) {
3194 dcnt = MmGetMdlByteCount(dst) - doff;
3197 doff -= MmGetMdlByteCount(dst);
3198 dst = dst->mdl_next;
3201 dptr = MmGetMdlVirtualAddress(dst);
3215 bcopy(sptr, dptr, len);
3224 dst = dst->mdl_next;
3227 dptr = MmGetMdlVirtualAddress(dst);
3228 dcnt = MmGetMdlByteCount(dst);
3233 src = src->mdl_next;
3236 sptr = MmGetMdlVirtualAddress(src);
3237 scnt = MmGetMdlByteCount(src);
3246 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3255 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3260 NdisIMCopySendPerPacketInfo(dpkt, spkt)
3264 memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension));
3268 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3270 unicode_string *devname;
3271 unicode_string *symname;
3272 driver_dispatch *majorfuncs[];
3274 ndis_handle *devhandle;
3277 device_object *dobj;
3279 status = IoCreateDevice(handle, 0, devname,
3280 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3282 if (status == STATUS_SUCCESS) {
3291 NdisMDeregisterDevice(handle)
3294 IoDeleteDevice(handle);
3295 return(NDIS_STATUS_SUCCESS);
3299 NdisMQueryAdapterInstanceName(name, handle)
3300 unicode_string *name;
3303 ndis_miniport_block *block;
3307 block = (ndis_miniport_block *)handle;
3308 dev = block->nmb_physdeviceobj->do_devext;
3310 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3311 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3312 return(NDIS_STATUS_RESOURCES);
3314 return(NDIS_STATUS_SUCCESS);
3318 NdisMRegisterUnloadHandler(handle, func)
3328 printf ("NDIS dummy called...\n");
3333 * Note: a couple of entries in this table specify the
3334 * number of arguments as "foo + 1". These are routines
3335 * that accept a 64-bit argument, passed by value. On
3336 * x86, these arguments consume two longwords on the stack,
3337 * so we lie and say there's one additional argument so
3338 * that the wrapping routines will do the right thing.
3341 image_patch_table ndis_functbl[] = {
3342 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3343 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3344 IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2),
3345 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3346 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3347 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3348 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3349 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3350 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3351 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3352 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3353 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3354 IMPORT_SFUNC(NdisInitAnsiString, 2),
3355 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3356 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3357 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3358 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3359 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3360 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3361 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3362 IMPORT_SFUNC(NdisInitializeString, 2),
3363 IMPORT_SFUNC(NdisFreeString, 1),
3364 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3365 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3366 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3367 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3368 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3369 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3370 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3371 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3372 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3373 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3374 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3375 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3376 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3377 IMPORT_SFUNC(NdisReadConfiguration, 5),
3378 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3379 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3380 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3381 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3382 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3383 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3384 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3385 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3386 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3387 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3388 IMPORT_SFUNC(NdisFreeMemory, 3),
3389 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3390 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3391 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3392 NdisReadPciSlotInformation, 5),
3393 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3394 NdisWritePciSlotInformation, 5),
3395 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3396 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3397 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3398 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3399 IMPORT_SFUNC(NdisInitializeTimer, 3),
3400 IMPORT_SFUNC(NdisSetTimer, 2),
3401 IMPORT_SFUNC(NdisMCancelTimer, 2),
3402 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3403 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3404 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3405 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3406 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3407 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3408 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3409 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3410 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3411 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3412 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3413 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3414 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3415 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3416 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3417 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3418 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3419 IMPORT_SFUNC(NdisAllocatePacket, 3),
3420 IMPORT_SFUNC(NdisFreePacket, 1),
3421 IMPORT_SFUNC(NdisFreePacketPool, 1),
3422 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3423 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3424 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3425 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3426 IMPORT_SFUNC(NdisQueryBuffer, 3),
3427 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3428 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3429 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3430 IMPORT_SFUNC(NdisBufferLength, 1),
3431 IMPORT_SFUNC(NdisFreeBuffer, 1),
3432 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3433 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3434 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3435 IMPORT_SFUNC(NdisInitializeEvent, 1),
3436 IMPORT_SFUNC(NdisSetEvent, 1),
3437 IMPORT_SFUNC(NdisResetEvent, 1),
3438 IMPORT_SFUNC(NdisWaitEvent, 2),
3439 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3440 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3441 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3442 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3443 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3444 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3445 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3446 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3447 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3448 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3449 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3450 IMPORT_SFUNC(NdisMSleep, 1),
3451 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3452 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3453 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3454 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3455 IMPORT_SFUNC(NdisMapFile, 3),
3456 IMPORT_SFUNC(NdisUnmapFile, 1),
3457 IMPORT_SFUNC(NdisCloseFile, 1),
3458 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3459 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3460 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3461 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3462 IMPORT_SFUNC(ndis_timercall, 4),
3463 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3464 IMPORT_SFUNC(ndis_intr, 2),
3465 IMPORT_SFUNC(ndis_intrhand, 4),
3468 * This last entry is a catch-all for any function we haven't
3469 * implemented yet. The PE import list patching routine will
3470 * use it for any function that doesn't have an explicit match
3474 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3478 { NULL, NULL, NULL }