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>
98 #include <dev/usb/usb.h>
99 #include <dev/usb/usbdi.h>
101 #include <compat/ndis/pe_var.h>
102 #include <compat/ndis/cfg_var.h>
103 #include <compat/ndis/resource_var.h>
104 #include <compat/ndis/ntoskrnl_var.h>
105 #include <compat/ndis/hal_var.h>
106 #include <compat/ndis/ndis_var.h>
107 #include <dev/if_ndis/if_ndisvar.h>
110 #include <vm/vm_param.h>
113 #include <vm/vm_kern.h>
114 #include <vm/vm_map.h>
116 static char ndis_filepath[MAXPATHLEN];
118 SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath,
119 MAXPATHLEN, "Path used by NdisOpenFile() to search for files");
121 static void NdisInitializeWrapper(ndis_handle *,
122 driver_object *, void *, void *);
123 static ndis_status NdisMRegisterMiniport(ndis_handle,
124 ndis_miniport_characteristics *, int);
125 static ndis_status NdisAllocateMemoryWithTag(void **,
127 static ndis_status NdisAllocateMemory(void **,
128 uint32_t, uint32_t, ndis_physaddr);
129 static void NdisFreeMemory(void *, uint32_t, uint32_t);
130 static ndis_status NdisMSetAttributesEx(ndis_handle, ndis_handle,
131 uint32_t, uint32_t, ndis_interface_type);
132 static void NdisOpenConfiguration(ndis_status *,
133 ndis_handle *, ndis_handle);
134 static void NdisOpenConfigurationKeyByIndex(ndis_status *,
135 ndis_handle, uint32_t, unicode_string *, ndis_handle *);
136 static void NdisOpenConfigurationKeyByName(ndis_status *,
137 ndis_handle, unicode_string *, ndis_handle *);
138 static ndis_status ndis_encode_parm(ndis_miniport_block *,
139 struct sysctl_oid *, ndis_parm_type, ndis_config_parm **);
140 static ndis_status ndis_decode_parm(ndis_miniport_block *,
141 ndis_config_parm *, char *);
142 static void NdisReadConfiguration(ndis_status *, ndis_config_parm **,
143 ndis_handle, unicode_string *, ndis_parm_type);
144 static void NdisWriteConfiguration(ndis_status *, ndis_handle,
145 unicode_string *, ndis_config_parm *);
146 static void NdisCloseConfiguration(ndis_handle);
147 static void NdisAllocateSpinLock(ndis_spin_lock *);
148 static void NdisFreeSpinLock(ndis_spin_lock *);
149 static void NdisAcquireSpinLock(ndis_spin_lock *);
150 static void NdisReleaseSpinLock(ndis_spin_lock *);
151 static void NdisDprAcquireSpinLock(ndis_spin_lock *);
152 static void NdisDprReleaseSpinLock(ndis_spin_lock *);
153 static void NdisInitializeReadWriteLock(ndis_rw_lock *);
154 static void NdisAcquireReadWriteLock(ndis_rw_lock *,
155 uint8_t, ndis_lock_state *);
156 static void NdisReleaseReadWriteLock(ndis_rw_lock *, ndis_lock_state *);
157 static uint32_t NdisReadPciSlotInformation(ndis_handle, uint32_t,
158 uint32_t, void *, uint32_t);
159 static uint32_t NdisWritePciSlotInformation(ndis_handle, uint32_t,
160 uint32_t, void *, uint32_t);
161 static void NdisWriteErrorLogEntry(ndis_handle, ndis_error_code, uint32_t, ...);
162 static void ndis_map_cb(void *, bus_dma_segment_t *, int, int);
163 static void NdisMStartBufferPhysicalMapping(ndis_handle,
164 ndis_buffer *, uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *);
165 static void NdisMCompleteBufferPhysicalMapping(ndis_handle,
166 ndis_buffer *, uint32_t);
167 static void NdisMInitializeTimer(ndis_miniport_timer *, ndis_handle,
168 ndis_timer_function, void *);
169 static void NdisInitializeTimer(ndis_timer *,
170 ndis_timer_function, void *);
171 static void NdisSetTimer(ndis_timer *, uint32_t);
172 static void NdisMSetPeriodicTimer(ndis_miniport_timer *, uint32_t);
173 static void NdisMCancelTimer(ndis_timer *, uint8_t *);
174 static void ndis_timercall(kdpc *, ndis_miniport_timer *,
176 static void NdisMQueryAdapterResources(ndis_status *, ndis_handle,
177 ndis_resource_list *, uint32_t *);
178 static ndis_status NdisMRegisterIoPortRange(void **,
179 ndis_handle, uint32_t, uint32_t);
180 static void NdisMDeregisterIoPortRange(ndis_handle,
181 uint32_t, uint32_t, void *);
182 static void NdisReadNetworkAddress(ndis_status *, void **,
183 uint32_t *, ndis_handle);
184 static ndis_status NdisQueryMapRegisterCount(uint32_t, uint32_t *);
185 static ndis_status NdisMAllocateMapRegisters(ndis_handle,
186 uint32_t, uint8_t, uint32_t, uint32_t);
187 static void NdisMFreeMapRegisters(ndis_handle);
188 static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int);
189 static void NdisMAllocateSharedMemory(ndis_handle, uint32_t,
190 uint8_t, void **, ndis_physaddr *);
191 static void ndis_asyncmem_complete(device_object *, void *);
192 static ndis_status NdisMAllocateSharedMemoryAsync(ndis_handle,
193 uint32_t, uint8_t, void *);
194 static void NdisMFreeSharedMemory(ndis_handle, uint32_t,
195 uint8_t, void *, ndis_physaddr);
196 static ndis_status NdisMMapIoSpace(void **, ndis_handle,
197 ndis_physaddr, uint32_t);
198 static void NdisMUnmapIoSpace(ndis_handle, void *, uint32_t);
199 static uint32_t NdisGetCacheFillSize(void);
200 static uint32_t NdisMGetDmaAlignment(ndis_handle);
201 static ndis_status NdisMInitializeScatterGatherDma(ndis_handle,
203 static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **);
204 static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **);
205 static void NdisAllocateBufferPool(ndis_status *,
206 ndis_handle *, uint32_t);
207 static void NdisFreeBufferPool(ndis_handle);
208 static void NdisAllocateBuffer(ndis_status *, ndis_buffer **,
209 ndis_handle, void *, uint32_t);
210 static void NdisFreeBuffer(ndis_buffer *);
211 static uint32_t NdisBufferLength(ndis_buffer *);
212 static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *);
213 static void NdisQueryBufferSafe(ndis_buffer *, void **,
214 uint32_t *, uint32_t);
215 static void *NdisBufferVirtualAddress(ndis_buffer *);
216 static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t);
217 static void NdisAdjustBufferLength(ndis_buffer *, int);
218 static uint32_t NdisInterlockedIncrement(uint32_t *);
219 static uint32_t NdisInterlockedDecrement(uint32_t *);
220 static void NdisInitializeEvent(ndis_event *);
221 static void NdisSetEvent(ndis_event *);
222 static void NdisResetEvent(ndis_event *);
223 static uint8_t NdisWaitEvent(ndis_event *, uint32_t);
224 static ndis_status NdisUnicodeStringToAnsiString(ansi_string *,
227 NdisAnsiStringToUnicodeString(unicode_string *, ansi_string *);
228 static ndis_status NdisMPciAssignResources(ndis_handle,
229 uint32_t, ndis_resource_list **);
230 static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *,
231 ndis_handle, uint32_t, uint32_t, uint8_t,
232 uint8_t, ndis_interrupt_mode);
233 static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *);
234 static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *,
235 ndis_shutdown_handler);
236 static void NdisMDeregisterAdapterShutdownHandler(ndis_handle);
237 static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *);
238 static void NdisGetBufferPhysicalArraySize(ndis_buffer *,
240 static void NdisQueryBufferOffset(ndis_buffer *,
241 uint32_t *, uint32_t *);
242 static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle,
243 uint32_t, void *, uint32_t);
244 static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle,
245 uint32_t, void *, uint32_t);
246 static list_entry *NdisInterlockedInsertHeadList(list_entry *,
247 list_entry *, ndis_spin_lock *);
248 static list_entry *NdisInterlockedRemoveHeadList(list_entry *,
250 static list_entry *NdisInterlockedInsertTailList(list_entry *,
251 list_entry *, ndis_spin_lock *);
253 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *,
255 static void NdisGetCurrentSystemTime(uint64_t *);
256 static void NdisGetSystemUpTime(uint32_t *);
257 static void NdisInitializeString(unicode_string *, char *);
258 static void NdisInitAnsiString(ansi_string *, char *);
259 static void NdisInitUnicodeString(unicode_string *, uint16_t *);
260 static void NdisFreeString(unicode_string *);
261 static ndis_status NdisMRemoveMiniport(ndis_handle *);
262 static void NdisTerminateWrapper(ndis_handle, void *);
263 static void NdisMGetDeviceProperty(ndis_handle, device_object **,
264 device_object **, device_object **, cm_resource_list *,
266 static void NdisGetFirstBufferFromPacket(ndis_packet *,
267 ndis_buffer **, void **, uint32_t *, uint32_t *);
268 static void NdisGetFirstBufferFromPacketSafe(ndis_packet *,
269 ndis_buffer **, void **, uint32_t *, uint32_t *, uint32_t);
270 static int ndis_find_sym(linker_file_t, char *, char *, caddr_t *);
271 static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *,
272 unicode_string *, ndis_physaddr);
273 static void NdisMapFile(ndis_status *, void **, ndis_handle);
274 static void NdisUnmapFile(ndis_handle);
275 static void NdisCloseFile(ndis_handle);
276 static uint8_t NdisSystemProcessorCount(void);
277 static void NdisMIndicateStatusComplete(ndis_handle);
278 static void NdisMIndicateStatus(ndis_handle, ndis_status,
280 static uint8_t ndis_intr(kinterrupt *, void *);
281 static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *);
282 static funcptr ndis_findwrap(funcptr);
283 static void NdisCopyFromPacketToPacket(ndis_packet *,
284 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *);
285 static void NdisCopyFromPacketToPacketSafe(ndis_packet *,
286 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t);
287 static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *);
288 static ndis_status NdisMRegisterDevice(ndis_handle,
289 unicode_string *, unicode_string *, driver_dispatch **,
290 void **, ndis_handle *);
291 static ndis_status NdisMDeregisterDevice(ndis_handle);
293 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
294 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
295 static void dummy(void);
298 * Some really old drivers do not properly check the return value
299 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
300 * sometimes allocate few more buffers/packets that they originally
301 * requested when they created the pool. To prevent this from being
302 * a problem, we allocate a few extra buffers/packets beyond what
303 * the driver asks for. This #define controls how many.
305 #define NDIS_POOL_EXTRA 16
310 image_patch_table *patch;
312 strcpy(ndis_filepath, "/compat/ndis");
314 patch = ndis_functbl;
315 while (patch->ipt_func != NULL) {
316 windrv_wrap((funcptr)patch->ipt_func,
317 (funcptr *)&patch->ipt_wrap,
318 patch->ipt_argcnt, patch->ipt_ftype);
328 image_patch_table *patch;
330 patch = ndis_functbl;
331 while (patch->ipt_func != NULL) {
332 windrv_unwrap(patch->ipt_wrap);
343 image_patch_table *patch;
345 patch = ndis_functbl;
346 while (patch->ipt_func != NULL) {
347 if ((funcptr)patch->ipt_func == func)
348 return((funcptr)patch->ipt_wrap);
356 * This routine does the messy Windows Driver Model device attachment
357 * stuff on behalf of NDIS drivers. We register our own AddDevice
361 NdisInitializeWrapper(wrapper, drv, path, unused)
362 ndis_handle *wrapper;
368 * As of yet, I haven't come up with a compelling
369 * reason to define a private NDIS wrapper structure,
370 * so we use a pointer to the driver object as the
371 * wrapper handle. The driver object has the miniport
372 * characteristics struct for this driver hung off it
373 * via IoAllocateDriverObjectExtension(), and that's
374 * really all the private data we need.
380 * If this was really Windows, we'd be registering dispatch
381 * routines for the NDIS miniport module here, but we're
382 * not Windows so all we really need to do is set up an
383 * AddDevice function that'll be invoked when a new device
387 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
393 NdisTerminateWrapper(handle, syspec)
397 /* Nothing to see here, move along. */
402 NdisMRegisterMiniport(handle, characteristics, len)
404 ndis_miniport_characteristics *characteristics;
407 ndis_miniport_characteristics *ch = NULL;
410 drv = (driver_object *)handle;
413 * We need to save the NDIS miniport characteristics
414 * somewhere. This data is per-driver, not per-device
415 * (all devices handled by the same driver have the
416 * same characteristics) so we hook it onto the driver
417 * object using IoAllocateDriverObjectExtension().
418 * The extra extension info is automagically deleted when
419 * the driver is unloaded (see windrv_unload()).
422 if (IoAllocateDriverObjectExtension(drv, (void *)1,
423 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
425 return(NDIS_STATUS_RESOURCES);
428 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
430 bcopy((char *)characteristics, (char *)ch, len);
432 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
433 ch->nmc_shutdown_handler = NULL;
434 ch->nmc_canceltxpkts_handler = NULL;
435 ch->nmc_pnpevent_handler = NULL;
438 return(NDIS_STATUS_SUCCESS);
442 NdisAllocateMemoryWithTag(vaddr, len, tag)
449 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
451 return(NDIS_STATUS_RESOURCES);
455 return(NDIS_STATUS_SUCCESS);
459 NdisAllocateMemory(vaddr, len, flags, highaddr)
463 ndis_physaddr highaddr;
467 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
469 return(NDIS_STATUS_RESOURCES);
472 return(NDIS_STATUS_SUCCESS);
476 NdisFreeMemory(vaddr, len, flags)
490 NdisMSetAttributesEx(adapter_handle, adapter_ctx, hangsecs,
492 ndis_handle adapter_handle;
493 ndis_handle adapter_ctx;
496 ndis_interface_type iftype;
498 ndis_miniport_block *block;
501 * Save the adapter context, we need it for calling
502 * the driver's internal functions.
504 block = (ndis_miniport_block *)adapter_handle;
505 block->nmb_miniportadapterctx = adapter_ctx;
506 block->nmb_checkforhangsecs = hangsecs;
507 block->nmb_flags = flags;
509 return(NDIS_STATUS_SUCCESS);
513 NdisOpenConfiguration(status, cfg, wrapctx)
519 *status = NDIS_STATUS_SUCCESS;
525 NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle)
528 unicode_string *subkey;
529 ndis_handle *subhandle;
532 *status = NDIS_STATUS_SUCCESS;
538 NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle)
542 unicode_string *subkey;
543 ndis_handle *subhandle;
545 *status = NDIS_STATUS_FAILURE;
551 ndis_encode_parm(block, oid, type, parm)
552 ndis_miniport_block *block;
553 struct sysctl_oid *oid;
555 ndis_config_parm **parm;
558 ndis_parmlist_entry *np;
565 np = ExAllocatePoolWithTag(NonPagedPool,
566 sizeof(ndis_parmlist_entry), 0);
568 return(NDIS_STATUS_RESOURCES);
569 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
570 *parm = p = &np->np_parm;
573 case ndis_parm_string:
574 /* See if this might be a number. */
575 val = strtoul((char *)oid->oid_arg1, NULL, 10);
576 us = &p->ncp_parmdata.ncp_stringdata;
577 p->ncp_type = ndis_parm_string;
579 snprintf(tmp, 32, "%x", val);
580 RtlInitAnsiString(&as, tmp);
582 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
585 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
587 return(NDIS_STATUS_RESOURCES);
591 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
595 p->ncp_type = ndis_parm_int;
596 p->ncp_parmdata.ncp_intdata =
597 strtol((char *)oid->oid_arg1, NULL, base);
599 case ndis_parm_hexint:
601 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
607 p->ncp_type = ndis_parm_hexint;
608 p->ncp_parmdata.ncp_intdata =
609 strtoul((char *)oid->oid_arg1, NULL, base);
612 return(NDIS_STATUS_FAILURE);
616 return(NDIS_STATUS_SUCCESS);
620 NdisReadConfiguration(status, parm, cfg, key, type)
622 ndis_config_parm **parm;
628 ndis_miniport_block *block;
629 struct ndis_softc *sc;
630 struct sysctl_oid *oidp;
631 struct sysctl_ctx_entry *e;
634 block = (ndis_miniport_block *)cfg;
635 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
637 if (key->us_len == 0 || key->us_buf == NULL) {
638 *status = NDIS_STATUS_FAILURE;
642 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
643 *status = NDIS_STATUS_RESOURCES;
650 * See if registry key is already in a list of known keys
651 * included with the driver.
653 #if __FreeBSD_version < 502113
654 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
656 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
659 if (strcasecmp(oidp->oid_name, keystr) == 0) {
660 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
661 RtlFreeAnsiString(&as);
662 *status = NDIS_STATUS_FAILURE;
666 *status = ndis_encode_parm(block, oidp, type, parm);
667 RtlFreeAnsiString(&as);
673 * If the key didn't match, add it to the list of dynamically
674 * created ones. Sometimes, drivers refer to registry keys
675 * that aren't documented in their .INF files. These keys
676 * are supposed to be created by some sort of utility or
677 * control panel snap-in that comes with the driver software.
678 * Sometimes it's useful to be able to manipulate these.
679 * If the driver requests the key in the form of a string,
680 * make its default value an empty string, otherwise default
684 if (type == ndis_parm_int || type == ndis_parm_hexint)
685 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
686 "UNSET", CTLFLAG_RW);
688 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
689 "UNSET", CTLFLAG_RW);
691 RtlFreeAnsiString(&as);
692 *status = NDIS_STATUS_FAILURE;
698 ndis_decode_parm(block, parm, val)
699 ndis_miniport_block *block;
700 ndis_config_parm *parm;
703 unicode_string *ustr;
706 switch(parm->ncp_type) {
707 case ndis_parm_string:
708 ustr = &parm->ncp_parmdata.ncp_stringdata;
709 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
710 return(NDIS_STATUS_RESOURCES);
711 bcopy(as.as_buf, val, as.as_len);
712 RtlFreeAnsiString(&as);
715 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
717 case ndis_parm_hexint:
718 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
721 return(NDIS_STATUS_FAILURE);
724 return(NDIS_STATUS_SUCCESS);
728 NdisWriteConfiguration(status, cfg, key, parm)
732 ndis_config_parm *parm;
736 ndis_miniport_block *block;
737 struct ndis_softc *sc;
738 struct sysctl_oid *oidp;
739 struct sysctl_ctx_entry *e;
742 block = (ndis_miniport_block *)cfg;
743 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
745 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
746 *status = NDIS_STATUS_RESOURCES;
752 /* Decode the parameter into a string. */
753 bzero(val, sizeof(val));
754 *status = ndis_decode_parm(block, parm, val);
755 if (*status != NDIS_STATUS_SUCCESS) {
756 RtlFreeAnsiString(&as);
760 /* See if the key already exists. */
762 #if __FreeBSD_version < 502113
763 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
765 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
768 if (strcasecmp(oidp->oid_name, keystr) == 0) {
769 /* Found it, set the value. */
770 strcpy((char *)oidp->oid_arg1, val);
771 RtlFreeAnsiString(&as);
776 /* Not found, add a new key with the specified value. */
777 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
780 RtlFreeAnsiString(&as);
781 *status = NDIS_STATUS_SUCCESS;
786 NdisCloseConfiguration(cfg)
790 ndis_parmlist_entry *pe;
791 ndis_miniport_block *block;
794 block = (ndis_miniport_block *)cfg;
796 while (!IsListEmpty(&block->nmb_parmlist)) {
797 e = RemoveHeadList(&block->nmb_parmlist);
798 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
800 if (p->ncp_type == ndis_parm_string)
801 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
809 * Initialize a Windows spinlock.
812 NdisAllocateSpinLock(lock)
813 ndis_spin_lock *lock;
815 KeInitializeSpinLock(&lock->nsl_spinlock);
822 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
823 * for this. One is that it's sort of superfluous: we don't have to do anything
824 * special to deallocate the spinlock. The other is that there are some buggy
825 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
826 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
830 NdisFreeSpinLock(lock)
831 ndis_spin_lock *lock;
834 KeInitializeSpinLock(&lock->nsl_spinlock);
841 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
845 NdisAcquireSpinLock(lock)
846 ndis_spin_lock *lock;
848 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
853 * Release a spinlock from IRQL == DISPATCH_LEVEL.
857 NdisReleaseSpinLock(lock)
858 ndis_spin_lock *lock;
860 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
865 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
868 NdisDprAcquireSpinLock(lock)
869 ndis_spin_lock *lock;
871 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
876 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
879 NdisDprReleaseSpinLock(lock)
880 ndis_spin_lock *lock;
882 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
887 NdisInitializeReadWriteLock(lock)
890 KeInitializeSpinLock(&lock->nrl_spinlock);
891 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
896 NdisAcquireReadWriteLock(ndis_rw_lock *lock, uint8_t writeacc,
897 ndis_lock_state *state)
899 if (writeacc == TRUE) {
900 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
909 NdisReleaseReadWriteLock(lock, state)
911 ndis_lock_state *state;
913 if (lock->nrl_rsvd[0]) {
915 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
923 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
930 ndis_miniport_block *block;
935 block = (ndis_miniport_block *)adapter;
940 dev = block->nmb_physdeviceobj->do_devext;
943 * I have a test system consisting of a Sun w2100z
944 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
945 * "Aries" miniPCI NIC. (The NIC is installed in the
946 * machine using a miniPCI to PCI bus adapter card.)
947 * When running in SMP mode, I found that
948 * performing a large number of consecutive calls to
949 * NdisReadPciSlotInformation() would result in a
950 * sudden system reset (or in some cases a freeze).
951 * My suspicion is that the multiple reads are somehow
952 * triggering a fatal PCI bus error that leads to a
953 * machine check. The 1us delay in the loop below
954 * seems to prevent this problem.
957 for (i = 0; i < len; i++) {
959 dest[i] = pci_read_config(dev, i + offset, 1);
966 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
973 ndis_miniport_block *block;
978 block = (ndis_miniport_block *)adapter;
984 dev = block->nmb_physdeviceobj->do_devext;
985 for (i = 0; i < len; i++) {
987 pci_write_config(dev, i + offset, dest[i], 1);
994 * The errorlog routine uses a variable argument list, so we
995 * have to declare it this way.
998 #define ERRMSGLEN 512
1000 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
1001 uint32_t numerrors, ...)
1003 ndis_miniport_block *block;
1010 struct ndis_softc *sc;
1013 ansi_string as = { 0, 0, NULL };
1015 block = (ndis_miniport_block *)adapter;
1016 dev = block->nmb_physdeviceobj->do_devext;
1017 drv = block->nmb_deviceobj->do_drvobj;
1018 sc = device_get_softc(dev);
1021 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1022 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
1023 code, &str, &i, &flags);
1025 if (flags & MESSAGE_RESOURCE_UNICODE) {
1026 RtlInitUnicodeString(&us, (uint16_t *)str);
1027 if (RtlUnicodeStringToAnsiString(&as,
1028 &us, TRUE) == STATUS_SUCCESS)
1036 device_printf (dev, "NDIS ERROR: %x (%s)\n", code,
1037 str == NULL ? "unknown error" : str);
1039 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1040 device_printf (dev, "NDIS NUMERRORS: %x\n", numerrors);
1041 va_start(ap, numerrors);
1042 for (i = 0; i < numerrors; i++)
1043 device_printf (dev, "argptr: %p\n",
1044 va_arg(ap, void *));
1049 RtlFreeAnsiString(&as);
1055 ndis_map_cb(arg, segs, nseg, error)
1057 bus_dma_segment_t *segs;
1061 struct ndis_map_arg *ctx;
1069 for (i = 0; i < nseg; i++) {
1070 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1071 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1074 ctx->nma_cnt = nseg;
1080 NdisMStartBufferPhysicalMapping(ndis_handle adapter, ndis_buffer *buf,
1081 uint32_t mapreg, uint8_t writedev, ndis_paddr_unit *addrarray,
1082 uint32_t *arraysize)
1084 ndis_miniport_block *block;
1085 struct ndis_softc *sc;
1086 struct ndis_map_arg nma;
1090 if (adapter == NULL)
1093 block = (ndis_miniport_block *)adapter;
1094 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1096 if (mapreg > sc->ndis_mmapcnt)
1099 map = sc->ndis_mmaps[mapreg];
1100 nma.nma_fraglist = addrarray;
1102 error = bus_dmamap_load(sc->ndis_mtag, map,
1103 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1104 (void *)&nma, BUS_DMA_NOWAIT);
1109 bus_dmamap_sync(sc->ndis_mtag, map,
1110 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1112 *arraysize = nma.nma_cnt;
1118 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1119 ndis_handle adapter;
1123 ndis_miniport_block *block;
1124 struct ndis_softc *sc;
1127 if (adapter == NULL)
1130 block = (ndis_miniport_block *)adapter;
1131 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1133 if (mapreg > sc->ndis_mmapcnt)
1136 map = sc->ndis_mmaps[mapreg];
1138 bus_dmamap_sync(sc->ndis_mtag, map,
1139 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1141 bus_dmamap_unload(sc->ndis_mtag, map);
1147 * This is an older (?) timer init routine which doesn't
1148 * accept a miniport context handle. Serialized miniports should
1149 * never call this function.
1153 NdisInitializeTimer(timer, func, ctx)
1155 ndis_timer_function func;
1158 KeInitializeTimer(&timer->nt_ktimer);
1159 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1160 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1166 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1168 ndis_miniport_timer *timer;
1173 * Since we're called as a DPC, we should be running
1174 * at DISPATCH_LEVEL here. This means to acquire the
1175 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1176 * rather than KeAcquireSpinLock().
1178 if (NDIS_SERIALIZED(timer->nmt_block))
1179 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1181 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1184 if (NDIS_SERIALIZED(timer->nmt_block))
1185 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1191 * For a long time I wondered why there were two NDIS timer initialization
1192 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1193 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1194 * function and context pointers separate from those in the DPC, which
1195 * allows for another level of indirection: when the timer fires, we
1196 * can have our own timer function invoked, and from there we can call
1197 * the driver's function. But why go to all that trouble? Then it hit
1198 * me: for serialized miniports, the timer callouts are not re-entrant.
1199 * By trapping the callouts and having access to the MiniportAdapterHandle,
1200 * we can protect the driver callouts by acquiring the NDIS serialization
1201 * lock. This is essential for allowing serialized miniports to work
1202 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1203 * is enough to prevent other threads from pre-empting you, but with
1204 * SMP, you must acquire a lock as well, otherwise the other CPU is
1205 * free to clobber you.
1208 NdisMInitializeTimer(timer, handle, func, ctx)
1209 ndis_miniport_timer *timer;
1211 ndis_timer_function func;
1214 ndis_miniport_block *block;
1215 struct ndis_softc *sc;
1217 block = (ndis_miniport_block *)handle;
1218 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1220 /* Save the driver's funcptr and context */
1222 timer->nmt_timerfunc = func;
1223 timer->nmt_timerctx = ctx;
1224 timer->nmt_block = handle;
1227 * Set up the timer so it will call our intermediate DPC.
1228 * Be sure to use the wrapped entry point, since
1229 * ntoskrnl_run_dpc() expects to invoke a function with
1230 * Microsoft calling conventions.
1232 KeInitializeTimer(&timer->nmt_ktimer);
1233 KeInitializeDpc(&timer->nmt_kdpc,
1234 ndis_findwrap((funcptr)ndis_timercall), timer);
1235 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1239 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1240 * but the former is just a macro wrapper around the latter.
1243 NdisSetTimer(timer, msecs)
1248 * KeSetTimer() wants the period in
1249 * hundred nanosecond intervals.
1251 KeSetTimer(&timer->nt_ktimer,
1252 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1258 NdisMSetPeriodicTimer(timer, msecs)
1259 ndis_miniport_timer *timer;
1262 KeSetTimerEx(&timer->nmt_ktimer,
1263 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1269 * Technically, this is really NdisCancelTimer(), but we also
1270 * (ab)use it for NdisMCancelTimer(), since in our implementation
1271 * we don't need the extra info in the ndis_miniport_timer
1272 * structure just to cancel a timer.
1276 NdisMCancelTimer(timer, cancelled)
1281 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1286 NdisMQueryAdapterResources(status, adapter, list, buflen)
1287 ndis_status *status;
1288 ndis_handle adapter;
1289 ndis_resource_list *list;
1292 ndis_miniport_block *block;
1293 struct ndis_softc *sc;
1296 block = (ndis_miniport_block *)adapter;
1297 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1299 rsclen = sizeof(ndis_resource_list) +
1300 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1301 if (*buflen < rsclen) {
1303 *status = NDIS_STATUS_INVALID_LENGTH;
1307 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1308 *status = NDIS_STATUS_SUCCESS;
1314 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1316 ndis_handle adapter;
1320 struct ndis_miniport_block *block;
1321 struct ndis_softc *sc;
1323 if (adapter == NULL)
1324 return(NDIS_STATUS_FAILURE);
1326 block = (ndis_miniport_block *)adapter;
1327 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1329 if (sc->ndis_res_io == NULL)
1330 return(NDIS_STATUS_FAILURE);
1332 /* Don't let the device map more ports than we have. */
1333 if (rman_get_size(sc->ndis_res_io) < numports)
1334 return(NDIS_STATUS_INVALID_LENGTH);
1336 *offset = (void *)rman_get_start(sc->ndis_res_io);
1338 return(NDIS_STATUS_SUCCESS);
1342 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1343 ndis_handle adapter;
1352 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1353 ndis_status *status;
1356 ndis_handle adapter;
1358 struct ndis_softc *sc;
1359 ndis_miniport_block *block;
1360 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1362 block = (ndis_miniport_block *)adapter;
1363 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1364 if (sc->ifp == NULL) {
1365 *status = NDIS_STATUS_FAILURE;
1370 if (bcmp(IFP2ENADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1371 #elif __FreeBSD_version >= 700000
1372 if (sc->ifp->if_addr == NULL ||
1373 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1375 if (bcmp(sc->arpcom.ac_enaddr, empty, ETHER_ADDR_LEN) == 0)
1377 *status = NDIS_STATUS_FAILURE;
1380 *addr = IFP2ENADDR(sc->ifp);
1381 #elif __FreeBSD_version >= 700000
1382 *addr = IF_LLADDR(sc->ifp);
1384 *addr = sc->arpcom.ac_enaddr;
1386 *addrlen = ETHER_ADDR_LEN;
1387 *status = NDIS_STATUS_SUCCESS;
1394 NdisQueryMapRegisterCount(bustype, cnt)
1399 return(NDIS_STATUS_SUCCESS);
1403 NdisMAllocateMapRegisters(ndis_handle adapter, uint32_t dmachannel,
1404 uint8_t dmasize, uint32_t physmapneeded, uint32_t maxmap)
1406 struct ndis_softc *sc;
1407 ndis_miniport_block *block;
1408 int error, i, nseg = NDIS_MAXSEG;
1410 block = (ndis_miniport_block *)adapter;
1411 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1413 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1414 M_DEVBUF, M_NOWAIT|M_ZERO);
1416 if (sc->ndis_mmaps == NULL)
1417 return(NDIS_STATUS_RESOURCES);
1419 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1420 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1421 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1422 NULL, NULL, &sc->ndis_mtag);
1425 free(sc->ndis_mmaps, M_DEVBUF);
1426 return(NDIS_STATUS_RESOURCES);
1429 for (i = 0; i < physmapneeded; i++)
1430 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1432 sc->ndis_mmapcnt = physmapneeded;
1434 return(NDIS_STATUS_SUCCESS);
1438 NdisMFreeMapRegisters(adapter)
1439 ndis_handle adapter;
1441 struct ndis_softc *sc;
1442 ndis_miniport_block *block;
1445 block = (ndis_miniport_block *)adapter;
1446 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1448 for (i = 0; i < sc->ndis_mmapcnt; i++)
1449 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1451 free(sc->ndis_mmaps, M_DEVBUF);
1453 bus_dma_tag_destroy(sc->ndis_mtag);
1459 ndis_mapshared_cb(arg, segs, nseg, error)
1461 bus_dma_segment_t *segs;
1467 if (error || nseg > 1)
1472 p->np_quad = segs[0].ds_addr;
1478 * This maps to bus_dmamem_alloc().
1482 NdisMAllocateSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1483 void **vaddr, ndis_physaddr *paddr)
1485 ndis_miniport_block *block;
1486 struct ndis_softc *sc;
1487 struct ndis_shmem *sh;
1490 if (adapter == NULL)
1493 block = (ndis_miniport_block *)adapter;
1494 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1496 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1500 InitializeListHead(&sh->ndis_list);
1503 * When performing shared memory allocations, create a tag
1504 * with a lowaddr limit that restricts physical memory mappings
1505 * so that they all fall within the first 1GB of memory.
1506 * At least one device/driver combination (Linksys Instant
1507 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1508 * problems with performing DMA operations with physical
1509 * addresses that lie above the 1GB mark. I don't know if this
1510 * is a hardware limitation or if the addresses are being
1511 * truncated within the driver, but this seems to be the only
1512 * way to make these cards work reliably in systems with more
1513 * than 1GB of physical memory.
1516 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1517 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1518 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1526 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1527 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1530 bus_dma_tag_destroy(sh->ndis_stag);
1535 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1536 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1539 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1540 bus_dma_tag_destroy(sh->ndis_stag);
1546 * Save the physical address along with the source address.
1547 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1548 * with a bogus virtual address sometimes, but with a valid
1549 * physical address. To keep this from causing trouble, we
1550 * use the physical address to as a sanity check in case
1551 * searching based on the virtual address fails.
1555 sh->ndis_paddr.np_quad = paddr->np_quad;
1556 sh->ndis_saddr = *vaddr;
1557 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1563 struct ndis_allocwork {
1571 ndis_asyncmem_complete(dobj, arg)
1572 device_object *dobj;
1575 ndis_miniport_block *block;
1576 struct ndis_softc *sc;
1577 struct ndis_allocwork *w;
1579 ndis_physaddr paddr;
1580 ndis_allocdone_handler donefunc;
1583 block = (ndis_miniport_block *)dobj->do_devext;
1584 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1589 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1590 NdisMAllocateSharedMemory(block, w->na_len,
1591 w->na_cached, &vaddr, &paddr);
1592 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1594 IoFreeWorkItem(w->na_iw);
1601 NdisMAllocateSharedMemoryAsync(ndis_handle adapter, uint32_t len,
1602 uint8_t cached, void *ctx)
1604 ndis_miniport_block *block;
1605 struct ndis_allocwork *w;
1607 io_workitem_func ifw;
1609 if (adapter == NULL)
1610 return(NDIS_STATUS_FAILURE);
1614 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1616 return(NDIS_STATUS_FAILURE);
1618 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1621 return(NDIS_STATUS_FAILURE);
1623 w->na_cached = cached;
1628 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1629 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1631 return(NDIS_STATUS_PENDING);
1635 NdisMFreeSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1636 void *vaddr, ndis_physaddr paddr)
1638 ndis_miniport_block *block;
1639 struct ndis_softc *sc;
1640 struct ndis_shmem *sh = NULL;
1643 if (vaddr == NULL || adapter == NULL)
1646 block = (ndis_miniport_block *)adapter;
1647 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1649 /* Sanity check: is list empty? */
1651 if (IsListEmpty(&sc->ndis_shlist))
1655 l = sc->ndis_shlist.nle_flink;
1656 while (l != &sc->ndis_shlist) {
1657 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1658 if (sh->ndis_saddr == vaddr)
1661 * Check the physaddr too, just in case the driver lied
1662 * about the virtual address.
1664 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1671 printf("NDIS: buggy driver tried to free "
1672 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1673 vaddr, (uintmax_t)paddr.np_quad);
1677 RemoveEntryList(&sh->ndis_list);
1681 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1682 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1683 bus_dma_tag_destroy(sh->ndis_stag);
1691 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1693 ndis_handle adapter;
1694 ndis_physaddr paddr;
1697 if (adapter == NULL)
1698 return(NDIS_STATUS_FAILURE);
1700 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1703 return(NDIS_STATUS_FAILURE);
1705 return(NDIS_STATUS_SUCCESS);
1709 NdisMUnmapIoSpace(adapter, vaddr, len)
1710 ndis_handle adapter;
1714 MmUnmapIoSpace(vaddr, len);
1719 NdisGetCacheFillSize(void)
1725 NdisMGetDmaAlignment(handle)
1732 * NDIS has two methods for dealing with NICs that support DMA.
1733 * One is to just pass packets to the driver and let it call
1734 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1735 * all by itself, and the other is to let the NDIS library handle the
1736 * buffer mapping internally, and hand the driver an already populated
1737 * scatter/gather fragment list. If the driver calls
1738 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1743 NdisMInitializeScatterGatherDma(ndis_handle adapter, uint8_t is64,
1744 uint32_t maxphysmap)
1746 struct ndis_softc *sc;
1747 ndis_miniport_block *block;
1750 if (adapter == NULL)
1751 return(NDIS_STATUS_FAILURE);
1752 block = (ndis_miniport_block *)adapter;
1753 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1755 /* Don't do this twice. */
1756 if (sc->ndis_sc == 1)
1757 return(NDIS_STATUS_SUCCESS);
1759 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1760 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1761 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1762 NULL, NULL, &sc->ndis_ttag);
1766 return(NDIS_STATUS_SUCCESS);
1770 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1771 ndis_status *status;
1774 uint32_t protrsvdlen;
1776 ndis_packet_pool *p;
1777 ndis_packet *packets;
1780 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1782 *status = NDIS_STATUS_RESOURCES;
1786 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1787 p->np_protrsvd = protrsvdlen;
1788 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1790 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1794 if (packets == NULL) {
1796 *status = NDIS_STATUS_RESOURCES;
1800 p->np_pktmem = packets;
1802 for (i = 0; i < p->np_cnt; i++)
1803 InterlockedPushEntrySList(&p->np_head,
1804 (struct slist_entry *)&packets[i]);
1806 #ifdef NDIS_DEBUG_PACKETS
1808 KeInitializeSpinLock(&p->np_lock);
1809 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1813 *status = NDIS_STATUS_SUCCESS;
1818 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1819 ndis_status *status;
1822 uint32_t oflowdescnum;
1823 uint32_t protrsvdlen;
1825 return(NdisAllocatePacketPool(status, pool,
1826 descnum + oflowdescnum, protrsvdlen));
1830 NdisPacketPoolUsage(pool)
1833 ndis_packet_pool *p;
1835 p = (ndis_packet_pool *)pool;
1836 return(p->np_cnt - ExQueryDepthSList(&p->np_head));
1840 NdisFreePacketPool(pool)
1843 ndis_packet_pool *p;
1845 #ifdef NDIS_DEBUG_PACKETS
1849 p = (ndis_packet_pool *)pool;
1851 #ifdef NDIS_DEBUG_PACKETS
1852 KeAcquireSpinLock(&p->np_lock, &irql);
1855 usage = NdisPacketPoolUsage(pool);
1857 #ifdef NDIS_DEBUG_PACKETS
1860 KeResetEvent(&p->np_event);
1861 KeReleaseSpinLock(&p->np_lock, irql);
1862 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1864 KeReleaseSpinLock(&p->np_lock, irql);
1867 ExFreePool(p->np_pktmem);
1874 NdisAllocatePacket(status, packet, pool)
1875 ndis_status *status;
1876 ndis_packet **packet;
1879 ndis_packet_pool *p;
1881 #ifdef NDIS_DEBUG_PACKETS
1885 p = (ndis_packet_pool *)pool;
1887 #ifdef NDIS_DEBUG_PACKETS
1888 KeAcquireSpinLock(&p->np_lock, &irql);
1890 KeReleaseSpinLock(&p->np_lock, irql);
1891 printf("NDIS: tried to allocate packet from dead pool %p\n",
1893 *status = NDIS_STATUS_RESOURCES;
1898 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1900 #ifdef NDIS_DEBUG_PACKETS
1901 KeReleaseSpinLock(&p->np_lock, irql);
1905 *status = NDIS_STATUS_RESOURCES;
1910 bzero((char *)pkt, sizeof(ndis_packet));
1912 /* Save pointer to the pool. */
1913 pkt->np_private.npp_pool = pool;
1915 /* Set the oob offset pointer. Lots of things expect this. */
1916 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1919 * We must initialize the packet flags correctly in order
1920 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1921 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1924 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1925 pkt->np_private.npp_validcounts = FALSE;
1929 *status = NDIS_STATUS_SUCCESS;
1935 NdisFreePacket(packet)
1936 ndis_packet *packet;
1938 ndis_packet_pool *p;
1939 #ifdef NDIS_DEBUG_PACKETS
1943 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1945 #ifdef NDIS_DEBUG_PACKETS
1946 KeAcquireSpinLock(&p->np_lock, &irql);
1949 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1951 #ifdef NDIS_DEBUG_PACKETS
1953 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1954 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1956 KeReleaseSpinLock(&p->np_lock, irql);
1963 NdisUnchainBufferAtFront(packet, buf)
1964 ndis_packet *packet;
1967 ndis_packet_private *priv;
1969 if (packet == NULL || buf == NULL)
1972 priv = &packet->np_private;
1974 priv->npp_validcounts = FALSE;
1976 if (priv->npp_head == priv->npp_tail) {
1977 *buf = priv->npp_head;
1978 priv->npp_head = priv->npp_tail = NULL;
1980 *buf = priv->npp_head;
1981 priv->npp_head = (*buf)->mdl_next;
1988 NdisUnchainBufferAtBack(packet, buf)
1989 ndis_packet *packet;
1992 ndis_packet_private *priv;
1995 if (packet == NULL || buf == NULL)
1998 priv = &packet->np_private;
2000 priv->npp_validcounts = FALSE;
2002 if (priv->npp_head == priv->npp_tail) {
2003 *buf = priv->npp_head;
2004 priv->npp_head = priv->npp_tail = NULL;
2006 *buf = priv->npp_tail;
2007 tmp = priv->npp_head;
2008 while (tmp->mdl_next != priv->npp_tail)
2009 tmp = tmp->mdl_next;
2010 priv->npp_tail = tmp;
2011 tmp->mdl_next = NULL;
2018 * The NDIS "buffer" is really an MDL (memory descriptor list)
2019 * which is used to describe a buffer in a way that allows it
2020 * to mapped into different contexts. We have to be careful how
2021 * we handle them: in some versions of Windows, the NdisFreeBuffer()
2022 * routine is an actual function in the NDIS API, but in others
2023 * it's just a macro wrapper around IoFreeMdl(). There's really
2024 * no way to use the 'descnum' parameter to count how many
2025 * "buffers" are allocated since in order to use IoFreeMdl() to
2026 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
2027 * them, and IoAllocateMdl() just grabs them out of the heap.
2031 NdisAllocateBufferPool(status, pool, descnum)
2032 ndis_status *status;
2038 * The only thing we can really do here is verify that descnum
2039 * is a reasonable value, but I really don't know what to check
2043 *pool = NonPagedPool;
2044 *status = NDIS_STATUS_SUCCESS;
2049 NdisFreeBufferPool(pool)
2056 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
2057 ndis_status *status;
2058 ndis_buffer **buffer;
2065 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
2067 *status = NDIS_STATUS_RESOURCES;
2071 MmBuildMdlForNonPagedPool(buf);
2074 *status = NDIS_STATUS_SUCCESS;
2090 NdisBufferLength(buf)
2093 return(MmGetMdlByteCount(buf));
2097 * Get the virtual address and length of a buffer.
2098 * Note: the vaddr argument is optional.
2102 NdisQueryBuffer(buf, vaddr, len)
2108 *vaddr = MmGetMdlVirtualAddress(buf);
2109 *len = MmGetMdlByteCount(buf);
2114 /* Same as above -- we don't care about the priority. */
2117 NdisQueryBufferSafe(buf, vaddr, len, prio)
2124 *vaddr = MmGetMdlVirtualAddress(buf);
2125 *len = MmGetMdlByteCount(buf);
2130 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2133 NdisBufferVirtualAddress(buf)
2136 return(MmGetMdlVirtualAddress(buf));
2140 NdisBufferVirtualAddressSafe(buf, prio)
2144 return(MmGetMdlVirtualAddress(buf));
2148 NdisAdjustBufferLength(buf, len)
2152 MmGetMdlByteCount(buf) = len;
2158 NdisInterlockedIncrement(addend)
2161 atomic_add_long((u_long *)addend, 1);
2166 NdisInterlockedDecrement(addend)
2169 atomic_subtract_long((u_long *)addend, 1);
2174 NdisInitializeEvent(event)
2178 * NDIS events are always notification
2179 * events, and should be initialized to the
2180 * not signaled state.
2182 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2190 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2195 NdisResetEvent(event)
2198 KeResetEvent(&event->ne_event);
2203 NdisWaitEvent(event, msecs)
2210 duetime = ((int64_t)msecs * -10000);
2211 rval = KeWaitForSingleObject(event,
2212 0, 0, TRUE, msecs ? & duetime : NULL);
2214 if (rval == STATUS_TIMEOUT)
2221 NdisUnicodeStringToAnsiString(dstr, sstr)
2223 unicode_string *sstr;
2227 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2229 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2230 return(NDIS_STATUS_RESOURCES);
2232 return(NDIS_STATUS_FAILURE);
2234 return (NDIS_STATUS_SUCCESS);
2238 NdisAnsiStringToUnicodeString(dstr, sstr)
2239 unicode_string *dstr;
2244 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2246 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2247 return(NDIS_STATUS_RESOURCES);
2249 return(NDIS_STATUS_FAILURE);
2251 return (NDIS_STATUS_SUCCESS);
2255 NdisMPciAssignResources(adapter, slot, list)
2256 ndis_handle adapter;
2258 ndis_resource_list **list;
2260 ndis_miniport_block *block;
2262 if (adapter == NULL || list == NULL)
2263 return (NDIS_STATUS_FAILURE);
2265 block = (ndis_miniport_block *)adapter;
2266 *list = block->nmb_rlist;
2268 return (NDIS_STATUS_SUCCESS);
2272 ndis_intr(iobj, arg)
2276 struct ndis_softc *sc;
2277 uint8_t is_our_intr = FALSE;
2279 ndis_miniport_interrupt *intr;
2282 intr = sc->ndis_block->nmb_interrupt;
2284 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2287 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2288 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2289 sc->ndis_block->nmb_miniportadapterctx);
2291 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2292 sc->ndis_block->nmb_miniportadapterctx);
2297 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2299 return(is_our_intr);
2303 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2305 ndis_miniport_interrupt *intr;
2309 struct ndis_softc *sc;
2310 ndis_miniport_block *block;
2311 ndis_handle adapter;
2313 block = intr->ni_block;
2314 adapter = block->nmb_miniportadapterctx;
2315 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2317 if (NDIS_SERIALIZED(sc->ndis_block))
2318 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2320 MSCALL1(intr->ni_dpcfunc, adapter);
2322 /* If there's a MiniportEnableInterrupt() routine, call it. */
2324 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2325 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2327 if (NDIS_SERIALIZED(sc->ndis_block))
2328 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2331 * Set the completion event if we've drained all
2332 * pending interrupts.
2335 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2337 if (intr->ni_dpccnt == 0)
2338 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2339 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2345 NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter,
2346 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared,
2347 ndis_interrupt_mode imode)
2349 ndis_miniport_block *block;
2350 ndis_miniport_characteristics *ch;
2351 struct ndis_softc *sc;
2355 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2356 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2359 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2360 sizeof(struct mtx), 0);
2361 if (intr->ni_rsvd == NULL)
2362 return(NDIS_STATUS_RESOURCES);
2364 intr->ni_block = adapter;
2365 intr->ni_isrreq = reqisr;
2366 intr->ni_shared = shared;
2367 intr->ni_dpccnt = 0;
2368 intr->ni_isrfunc = ch->nmc_isr_func;
2369 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2371 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2372 KeInitializeDpc(&intr->ni_dpc,
2373 ndis_findwrap((funcptr)ndis_intrhand), intr);
2374 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2376 error = IoConnectInterrupt(&intr->ni_introbj,
2377 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2378 ivec, ilevel, 0, imode, shared, 0, FALSE);
2380 if (error != STATUS_SUCCESS)
2381 return(NDIS_STATUS_FAILURE);
2383 block->nmb_interrupt = intr;
2385 return(NDIS_STATUS_SUCCESS);
2389 NdisMDeregisterInterrupt(intr)
2390 ndis_miniport_interrupt *intr;
2392 ndis_miniport_block *block;
2395 block = intr->ni_block;
2397 /* Should really be KeSynchronizeExecution() */
2399 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2400 block->nmb_interrupt = NULL;
2401 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2403 KeFlushQueuedDpcs();
2405 /* Disconnect our ISR */
2407 IoDisconnectInterrupt(intr->ni_introbj);
2409 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2410 KeResetEvent(&intr->ni_dpcevt);
2416 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2417 ndis_handle adapter;
2419 ndis_shutdown_handler shutdownfunc;
2421 ndis_miniport_block *block;
2422 ndis_miniport_characteristics *chars;
2423 struct ndis_softc *sc;
2425 if (adapter == NULL)
2428 block = (ndis_miniport_block *)adapter;
2429 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2430 chars = sc->ndis_chars;
2432 chars->nmc_shutdown_handler = shutdownfunc;
2433 chars->nmc_rsvd0 = shutdownctx;
2439 NdisMDeregisterAdapterShutdownHandler(adapter)
2440 ndis_handle adapter;
2442 ndis_miniport_block *block;
2443 ndis_miniport_characteristics *chars;
2444 struct ndis_softc *sc;
2446 if (adapter == NULL)
2449 block = (ndis_miniport_block *)adapter;
2450 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2451 chars = sc->ndis_chars;
2453 chars->nmc_shutdown_handler = NULL;
2454 chars->nmc_rsvd0 = NULL;
2460 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2465 if (MmGetMdlByteCount(buf) == 0)
2467 return(SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2468 MmGetMdlByteCount(buf)));
2472 NdisGetBufferPhysicalArraySize(buf, pages)
2479 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2484 NdisQueryBufferOffset(buf, off, len)
2492 *off = MmGetMdlByteOffset(buf);
2493 *len = MmGetMdlByteCount(buf);
2505 * During system bootstrap, (i.e. cold == 1), we aren't
2506 * allowed to sleep, so we have to do a hard DELAY()
2513 KeInitializeTimer(&timer);
2514 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2515 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2522 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2528 struct ndis_softc *sc;
2529 ndis_miniport_block *block;
2530 bus_space_handle_t bh;
2538 block = (ndis_miniport_block *)handle;
2539 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2542 bh = rman_get_bushandle(sc->ndis_res_am);
2543 bt = rman_get_bustag(sc->ndis_res_am);
2545 for (i = 0; i < len; i++)
2546 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2552 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2558 struct ndis_softc *sc;
2559 ndis_miniport_block *block;
2560 bus_space_handle_t bh;
2568 block = (ndis_miniport_block *)handle;
2569 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2572 bh = rman_get_bushandle(sc->ndis_res_am);
2573 bt = rman_get_bustag(sc->ndis_res_am);
2575 for (i = 0; i < len; i++)
2576 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2582 NdisInterlockedInsertHeadList(head, entry, lock)
2585 ndis_spin_lock *lock;
2589 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2590 flink = head->nle_flink;
2591 entry->nle_flink = flink;
2592 entry->nle_blink = head;
2593 flink->nle_blink = entry;
2594 head->nle_flink = entry;
2595 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2601 NdisInterlockedRemoveHeadList(head, lock)
2603 ndis_spin_lock *lock;
2608 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2609 entry = head->nle_flink;
2610 flink = entry->nle_flink;
2611 head->nle_flink = flink;
2612 flink->nle_blink = head;
2613 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2619 NdisInterlockedInsertTailList(head, entry, lock)
2622 ndis_spin_lock *lock;
2626 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2627 blink = head->nle_blink;
2628 entry->nle_flink = head;
2629 entry->nle_blink = blink;
2630 blink->nle_flink = entry;
2631 head->nle_blink = entry;
2632 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2638 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2639 ndis_miniport_interrupt *intr;
2643 return(KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2647 NdisGetCurrentSystemTime(tval)
2650 ntoskrnl_time(tval);
2655 * Return the number of milliseconds since the system booted.
2658 NdisGetSystemUpTime(tval)
2664 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2670 NdisInitializeString(dst, src)
2671 unicode_string *dst;
2675 RtlInitAnsiString(&as, src);
2676 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2682 unicode_string *str;
2684 RtlFreeUnicodeString(str);
2689 NdisMRemoveMiniport(adapter)
2690 ndis_handle *adapter;
2692 return(NDIS_STATUS_SUCCESS);
2696 NdisInitAnsiString(dst, src)
2700 RtlInitAnsiString(dst, src);
2705 NdisInitUnicodeString(dst, src)
2706 unicode_string *dst;
2709 RtlInitUnicodeString(dst, src);
2713 static void NdisMGetDeviceProperty(adapter, phydevobj,
2714 funcdevobj, nextdevobj, resources, transresources)
2715 ndis_handle adapter;
2716 device_object **phydevobj;
2717 device_object **funcdevobj;
2718 device_object **nextdevobj;
2719 cm_resource_list *resources;
2720 cm_resource_list *transresources;
2722 ndis_miniport_block *block;
2724 block = (ndis_miniport_block *)adapter;
2726 if (phydevobj != NULL)
2727 *phydevobj = block->nmb_physdeviceobj;
2728 if (funcdevobj != NULL)
2729 *funcdevobj = block->nmb_deviceobj;
2730 if (nextdevobj != NULL)
2731 *nextdevobj = block->nmb_nextdeviceobj;
2737 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2738 ndis_packet *packet;
2746 tmp = packet->np_private.npp_head;
2750 *firstlen = *totlen = 0;
2752 *firstva = MmGetMdlVirtualAddress(tmp);
2753 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2754 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2755 *totlen += MmGetMdlByteCount(tmp);
2762 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2763 ndis_packet *packet;
2770 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2774 ndis_find_sym(lf, filename, suffix, sym)
2784 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2785 if (fullsym == NULL)
2788 bzero(fullsym, MAXPATHLEN);
2789 strncpy(fullsym, filename, MAXPATHLEN);
2790 if (strlen(filename) < 4) {
2791 ExFreePool(fullsym);
2795 /* If the filename has a .ko suffix, strip if off. */
2796 suf = fullsym + (strlen(filename) - 3);
2797 if (strcmp(suf, ".ko") == 0)
2800 for (i = 0; i < strlen(fullsym); i++) {
2801 if (fullsym[i] == '.')
2804 fullsym[i] = tolower(fullsym[i]);
2806 strcat(fullsym, suffix);
2807 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2808 ExFreePool(fullsym);
2815 struct ndis_checkmodule {
2821 * See if a single module contains the symbols for a specified file.
2824 NdisCheckModule(linker_file_t lf, void *context)
2826 struct ndis_checkmodule *nc;
2827 caddr_t kldstart, kldend;
2829 nc = (struct ndis_checkmodule *)context;
2830 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2832 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2835 nc->fh->nf_map = NULL;
2836 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2837 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2841 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2843 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2844 ndis_status *status;
2845 ndis_handle *filehandle;
2846 uint32_t *filelength;
2847 unicode_string *filename;
2848 ndis_physaddr highestaddr;
2851 char *afilename = NULL;
2852 struct thread *td = curthread;
2853 struct nameidata nd;
2854 int flags, error, vfslocked;
2856 struct vattr *vap = &vat;
2859 struct ndis_checkmodule nc;
2861 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2862 *status = NDIS_STATUS_RESOURCES;
2866 afilename = strdup(as.as_buf, M_DEVBUF);
2867 RtlFreeAnsiString(&as);
2869 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2871 free(afilename, M_DEVBUF);
2872 *status = NDIS_STATUS_RESOURCES;
2876 fh->nf_name = afilename;
2879 * During system bootstrap, it's impossible to load files
2880 * from the rootfs since it's not mounted yet. We therefore
2881 * offer the possibility of opening files that have been
2882 * preloaded as modules instead. Both choices will work
2883 * when kldloading a module from multiuser, but only the
2884 * module option will work during bootstrap. The module
2885 * loading option works by using the ndiscvt(8) utility
2886 * to convert the arbitrary file into a .ko using objcopy(1).
2887 * This file will contain two special symbols: filename_start
2888 * and filename_end. All we have to do is traverse the KLD
2889 * list in search of those symbols and we've found the file
2890 * data. As an added bonus, ndiscvt(8) will also generate
2891 * a normal .o file which can be linked statically with
2892 * the kernel. This means that the symbols will actual reside
2893 * in the kernel's symbol table, but that doesn't matter to
2894 * us since the kernel appears to us as just another module.
2897 nc.afilename = afilename;
2899 if (linker_file_foreach(NdisCheckModule, &nc)) {
2900 *filelength = fh->nf_maplen;
2902 *status = NDIS_STATUS_SUCCESS;
2906 if (TAILQ_EMPTY(&mountlist)) {
2908 *status = NDIS_STATUS_FILE_NOT_FOUND;
2909 printf("NDIS: could not find file %s in linker list\n",
2911 printf("NDIS: and no filesystems mounted yet, "
2912 "aborting NdisOpenFile()\n");
2913 free(afilename, M_DEVBUF);
2917 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2920 free(afilename, M_DEVBUF);
2921 *status = NDIS_STATUS_RESOURCES;
2925 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2927 /* Some threads don't have a current working directory. */
2929 if (td->td_proc->p_fd->fd_rdir == NULL)
2930 td->td_proc->p_fd->fd_rdir = rootvnode;
2931 if (td->td_proc->p_fd->fd_cdir == NULL)
2932 td->td_proc->p_fd->fd_cdir = rootvnode;
2934 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td);
2937 error = vn_open(&nd, &flags, 0, NULL);
2939 *status = NDIS_STATUS_FILE_NOT_FOUND;
2941 printf("NDIS: open file %s failed: %d\n", path, error);
2943 free(afilename, M_DEVBUF);
2946 vfslocked = NDHASGIANT(&nd);
2950 NDFREE(&nd, NDF_ONLY_PNBUF);
2952 /* Get the file size. */
2953 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred);
2954 VOP_UNLOCK(nd.ni_vp, 0);
2955 VFS_UNLOCK_GIANT(vfslocked);
2957 fh->nf_vp = nd.ni_vp;
2959 fh->nf_type = NDIS_FH_TYPE_VFS;
2961 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2962 *status = NDIS_STATUS_SUCCESS;
2968 NdisMapFile(status, mappedbuffer, filehandle)
2969 ndis_status *status;
2970 void **mappedbuffer;
2971 ndis_handle filehandle;
2974 struct thread *td = curthread;
2977 int error, resid, vfslocked;
2980 if (filehandle == NULL) {
2981 *status = NDIS_STATUS_FAILURE;
2985 fh = (ndis_fh *)filehandle;
2987 if (fh->nf_vp == NULL) {
2988 *status = NDIS_STATUS_FAILURE;
2992 if (fh->nf_map != NULL) {
2993 *status = NDIS_STATUS_ALREADY_MAPPED;
2997 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
2999 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
3000 *status = NDIS_STATUS_FAILURE;
3003 fh->nf_map = kldstart;
3004 *status = NDIS_STATUS_SUCCESS;
3005 *mappedbuffer = fh->nf_map;
3009 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
3011 if (fh->nf_map == NULL) {
3012 *status = NDIS_STATUS_RESOURCES;
3017 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3018 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
3019 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
3020 VFS_UNLOCK_GIANT(vfslocked);
3023 *status = NDIS_STATUS_FAILURE;
3025 *status = NDIS_STATUS_SUCCESS;
3026 *mappedbuffer = fh->nf_map;
3033 NdisUnmapFile(filehandle)
3034 ndis_handle filehandle;
3037 fh = (ndis_fh *)filehandle;
3039 if (fh->nf_map == NULL)
3042 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3043 ExFreePool(fh->nf_map);
3050 NdisCloseFile(filehandle)
3051 ndis_handle filehandle;
3053 struct thread *td = curthread;
3058 if (filehandle == NULL)
3061 fh = (ndis_fh *)filehandle;
3062 if (fh->nf_map != NULL) {
3063 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3064 ExFreePool(fh->nf_map);
3068 if (fh->nf_vp == NULL)
3071 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
3073 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3074 vn_close(vp, FREAD, td->td_ucred, td);
3075 VFS_UNLOCK_GIANT(vfslocked);
3079 free(fh->nf_name, M_DEVBUF);
3086 NdisSystemProcessorCount()
3091 typedef void (*ndis_statusdone_handler)(ndis_handle);
3092 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
3096 NdisMIndicateStatusComplete(adapter)
3097 ndis_handle adapter;
3099 ndis_miniport_block *block;
3100 ndis_statusdone_handler statusdonefunc;
3102 block = (ndis_miniport_block *)adapter;
3103 statusdonefunc = block->nmb_statusdone_func;
3105 MSCALL1(statusdonefunc, adapter);
3110 NdisMIndicateStatus(adapter, status, sbuf, slen)
3111 ndis_handle adapter;
3116 ndis_miniport_block *block;
3117 ndis_status_handler statusfunc;
3119 block = (ndis_miniport_block *)adapter;
3120 statusfunc = block->nmb_status_func;
3122 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3127 * The DDK documentation says that you should use IoQueueWorkItem()
3128 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3129 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3130 * depends on the API semantics of ExQueueWorkItem(). In our world,
3131 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3134 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3135 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3136 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3137 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3138 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3139 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3140 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3141 * to ExQueueWorkItem().
3143 * Got all that? (Sheesh.)
3147 NdisScheduleWorkItem(work)
3148 ndis_work_item *work;
3150 work_queue_item *wqi;
3152 wqi = (work_queue_item *)work->nwi_wraprsvd;
3153 ExInitializeWorkItem(wqi,
3154 (work_item_func)work->nwi_func, work->nwi_ctx);
3155 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3157 return(NDIS_STATUS_SUCCESS);
3161 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3169 ndis_buffer *src, *dst;
3171 int resid, copied, len, scnt, dcnt;
3175 src = spkt->np_private.npp_head;
3176 dst = dpkt->np_private.npp_head;
3178 sptr = MmGetMdlVirtualAddress(src);
3179 dptr = MmGetMdlVirtualAddress(dst);
3180 scnt = MmGetMdlByteCount(src);
3181 dcnt = MmGetMdlByteCount(dst);
3184 if (MmGetMdlByteCount(src) > soff) {
3186 scnt = MmGetMdlByteCount(src)- soff;
3189 soff -= MmGetMdlByteCount(src);
3190 src = src->mdl_next;
3193 sptr = MmGetMdlVirtualAddress(src);
3197 if (MmGetMdlByteCount(dst) > doff) {
3199 dcnt = MmGetMdlByteCount(dst) - doff;
3202 doff -= MmGetMdlByteCount(dst);
3203 dst = dst->mdl_next;
3206 dptr = MmGetMdlVirtualAddress(dst);
3220 bcopy(sptr, dptr, len);
3229 dst = dst->mdl_next;
3232 dptr = MmGetMdlVirtualAddress(dst);
3233 dcnt = MmGetMdlByteCount(dst);
3238 src = src->mdl_next;
3241 sptr = MmGetMdlVirtualAddress(src);
3242 scnt = MmGetMdlByteCount(src);
3251 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3260 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3265 NdisIMCopySendPerPacketInfo(dpkt, spkt)
3269 memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension));
3273 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3275 unicode_string *devname;
3276 unicode_string *symname;
3277 driver_dispatch *majorfuncs[];
3279 ndis_handle *devhandle;
3282 device_object *dobj;
3284 status = IoCreateDevice(handle, 0, devname,
3285 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3287 if (status == STATUS_SUCCESS) {
3296 NdisMDeregisterDevice(handle)
3299 IoDeleteDevice(handle);
3300 return(NDIS_STATUS_SUCCESS);
3304 NdisMQueryAdapterInstanceName(name, handle)
3305 unicode_string *name;
3308 ndis_miniport_block *block;
3312 block = (ndis_miniport_block *)handle;
3313 dev = block->nmb_physdeviceobj->do_devext;
3315 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3316 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3317 return(NDIS_STATUS_RESOURCES);
3319 return(NDIS_STATUS_SUCCESS);
3323 NdisMRegisterUnloadHandler(handle, func)
3333 printf ("NDIS dummy called...\n");
3338 * Note: a couple of entries in this table specify the
3339 * number of arguments as "foo + 1". These are routines
3340 * that accept a 64-bit argument, passed by value. On
3341 * x86, these arguments consume two longwords on the stack,
3342 * so we lie and say there's one additional argument so
3343 * that the wrapping routines will do the right thing.
3346 image_patch_table ndis_functbl[] = {
3347 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3348 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3349 IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2),
3350 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3351 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3352 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3353 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3354 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3355 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3356 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3357 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3358 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3359 IMPORT_SFUNC(NdisInitAnsiString, 2),
3360 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3361 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3362 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3363 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3364 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3365 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3366 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3367 IMPORT_SFUNC(NdisInitializeString, 2),
3368 IMPORT_SFUNC(NdisFreeString, 1),
3369 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3370 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3371 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3372 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3373 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3374 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3375 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3376 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3377 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3378 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3379 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3380 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3381 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3382 IMPORT_SFUNC(NdisReadConfiguration, 5),
3383 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3384 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3385 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3386 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3387 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3388 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3389 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3390 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3391 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3392 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3393 IMPORT_SFUNC(NdisFreeMemory, 3),
3394 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3395 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3396 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3397 NdisReadPciSlotInformation, 5),
3398 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3399 NdisWritePciSlotInformation, 5),
3400 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3401 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3402 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3403 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3404 IMPORT_SFUNC(NdisInitializeTimer, 3),
3405 IMPORT_SFUNC(NdisSetTimer, 2),
3406 IMPORT_SFUNC(NdisMCancelTimer, 2),
3407 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3408 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3409 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3410 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3411 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3412 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3413 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3414 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3415 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3416 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3417 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3418 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3419 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3420 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3421 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3422 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3423 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3424 IMPORT_SFUNC(NdisAllocatePacket, 3),
3425 IMPORT_SFUNC(NdisFreePacket, 1),
3426 IMPORT_SFUNC(NdisFreePacketPool, 1),
3427 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3428 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3429 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3430 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3431 IMPORT_SFUNC(NdisQueryBuffer, 3),
3432 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3433 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3434 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3435 IMPORT_SFUNC(NdisBufferLength, 1),
3436 IMPORT_SFUNC(NdisFreeBuffer, 1),
3437 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3438 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3439 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3440 IMPORT_SFUNC(NdisInitializeEvent, 1),
3441 IMPORT_SFUNC(NdisSetEvent, 1),
3442 IMPORT_SFUNC(NdisResetEvent, 1),
3443 IMPORT_SFUNC(NdisWaitEvent, 2),
3444 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3445 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3446 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3447 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3448 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3449 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3450 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3451 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3452 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3453 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3454 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3455 IMPORT_SFUNC(NdisMSleep, 1),
3456 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3457 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3458 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3459 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3460 IMPORT_SFUNC(NdisMapFile, 3),
3461 IMPORT_SFUNC(NdisUnmapFile, 1),
3462 IMPORT_SFUNC(NdisCloseFile, 1),
3463 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3464 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3465 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3466 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3467 IMPORT_SFUNC(ndis_timercall, 4),
3468 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3469 IMPORT_SFUNC(ndis_intr, 2),
3470 IMPORT_SFUNC(ndis_intrhand, 4),
3473 * This last entry is a catch-all for any function we haven't
3474 * implemented yet. The PE import list patching routine will
3475 * use it for any function that doesn't have an explicit match
3479 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3483 { NULL, NULL, NULL }