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.
32 * $FreeBSD: src/sys/compat/ndis/subr_ndis.c,v 1.125 2010/12/06 20:54:53 bschmidt Exp $
36 * This file implements a translation layer between the BSD networking
37 * infrasturcture and Windows(R) NDIS network driver modules. A Windows
38 * NDIS driver calls into several functions in the NDIS.SYS Windows
39 * kernel module and exports a table of functions designed to be called
40 * by the NDIS subsystem. Using the PE loader, we can patch our own
41 * versions of the NDIS routines into a given Windows driver module and
42 * convince the driver that it is in fact running on Windows.
44 * We provide a table of all our implemented NDIS routines which is patched
45 * into the driver object code. All our exported routines must use the
46 * _stdcall calling convention, since that's what the Windows object code
51 #include <sys/ctype.h>
52 #include <sys/param.h>
53 #include <sys/types.h>
54 #include <sys/errno.h>
56 #include <sys/callout.h>
57 #include <sys/kernel.h>
58 #include <sys/systm.h>
59 #include <sys/malloc.h>
61 #include <sys/mutex.h>
62 #include <sys/socket.h>
63 #include <sys/sysctl.h>
64 #include <sys/_timespec.h>
65 #include <sys/queue.h>
67 #include <sys/filedesc.h>
68 #include <sys/nlookup.h>
69 #include <sys/fcntl.h>
70 #include <sys/vnode.h>
71 #include <sys/kthread.h>
72 #include <sys/linker.h>
73 #include <sys/mount.h>
74 #include <sys/sysproto.h>
77 #include <net/if_arp.h>
78 #include <net/ethernet.h>
79 #include <net/if_dl.h>
80 #include <net/if_media.h>
82 #include <machine/atomic.h>
86 #include <sys/mplock2.h>
88 #include <netproto/802_11/ieee80211_var.h>
89 #include <netproto/802_11/ieee80211_ioctl.h>
91 #include <bus/pci/pcireg.h>
92 #include <bus/pci/pcivar.h>
93 #include <bus/usb/usb.h>
94 #include <bus/usb/usbdi.h>
96 #include <emulation/ndis/pe_var.h>
97 #include <emulation/ndis/cfg_var.h>
98 #include <emulation/ndis/resource_var.h>
99 #include <emulation/ndis/ntoskrnl_var.h>
100 #include <emulation/ndis/hal_var.h>
101 #include <emulation/ndis/ndis_var.h>
102 #include <dev/netif/ndis/if_ndisvar.h>
105 #include <vm/vm_param.h>
107 #include <vm/vm_kern.h>
108 #include <vm/vm_map.h>
112 static char ndis_filepath[MAXPATHLEN];
114 SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath,
115 MAXPATHLEN, "Path used by NdisOpenFile() to search for files");
117 static void NdisInitializeWrapper(ndis_handle *,
118 driver_object *, void *, void *);
119 static ndis_status NdisMRegisterMiniport(ndis_handle,
120 ndis_miniport_characteristics *, int);
121 static ndis_status NdisAllocateMemoryWithTag(void **,
123 static ndis_status NdisAllocateMemory(void **,
124 uint32_t, uint32_t, ndis_physaddr);
125 static void NdisFreeMemory(void *, uint32_t, uint32_t);
126 static ndis_status NdisMSetAttributesEx(ndis_handle, ndis_handle,
127 uint32_t, uint32_t, ndis_interface_type);
128 static void NdisOpenConfiguration(ndis_status *,
129 ndis_handle *, ndis_handle);
130 static void NdisOpenConfigurationKeyByIndex(ndis_status *,
131 ndis_handle, uint32_t, unicode_string *, ndis_handle *);
132 static void NdisOpenConfigurationKeyByName(ndis_status *,
133 ndis_handle, unicode_string *, ndis_handle *);
134 static ndis_status ndis_encode_parm(ndis_miniport_block *,
135 struct sysctl_oid *, ndis_parm_type, ndis_config_parm **);
136 static ndis_status ndis_decode_parm(ndis_miniport_block *,
137 ndis_config_parm *, char *);
138 static void NdisReadConfiguration(ndis_status *, ndis_config_parm **,
139 ndis_handle, unicode_string *, ndis_parm_type);
140 static void NdisWriteConfiguration(ndis_status *, ndis_handle,
141 unicode_string *, ndis_config_parm *);
142 static void NdisCloseConfiguration(ndis_handle);
143 static void NdisAllocateSpinLock(ndis_spin_lock *);
144 static void NdisFreeSpinLock(ndis_spin_lock *);
145 static void NdisAcquireSpinLock(ndis_spin_lock *);
146 static void NdisReleaseSpinLock(ndis_spin_lock *);
147 static void NdisDprAcquireSpinLock(ndis_spin_lock *);
148 static void NdisDprReleaseSpinLock(ndis_spin_lock *);
149 static void NdisInitializeReadWriteLock(ndis_rw_lock *);
150 static void NdisAcquireReadWriteLock(ndis_rw_lock *,
151 uint8_t, ndis_lock_state *);
152 static void NdisReleaseReadWriteLock(ndis_rw_lock *, ndis_lock_state *);
153 static uint32_t NdisReadPciSlotInformation(ndis_handle, uint32_t,
154 uint32_t, void *, uint32_t);
155 static uint32_t NdisWritePciSlotInformation(ndis_handle, uint32_t,
156 uint32_t, void *, uint32_t);
157 static void NdisWriteErrorLogEntry(ndis_handle, ndis_error_code, uint32_t, ...);
158 static void ndis_map_cb(void *, bus_dma_segment_t *, int, int);
159 static void NdisMStartBufferPhysicalMapping(ndis_handle,
160 ndis_buffer *, uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *);
161 static void NdisMCompleteBufferPhysicalMapping(ndis_handle,
162 ndis_buffer *, uint32_t);
163 static void NdisMInitializeTimer(ndis_miniport_timer *, ndis_handle,
164 ndis_timer_function, void *);
165 static void NdisInitializeTimer(ndis_timer *,
166 ndis_timer_function, void *);
167 static void NdisSetTimer(ndis_timer *, uint32_t);
168 static void NdisMSetPeriodicTimer(ndis_miniport_timer *, uint32_t);
169 static void NdisMCancelTimer(ndis_timer *, uint8_t *);
170 static void ndis_timercall(kdpc *, ndis_miniport_timer *,
172 static void NdisMQueryAdapterResources(ndis_status *, ndis_handle,
173 ndis_resource_list *, uint32_t *);
174 static ndis_status NdisMRegisterIoPortRange(void **,
175 ndis_handle, uint32_t, uint32_t);
176 static void NdisMDeregisterIoPortRange(ndis_handle,
177 uint32_t, uint32_t, void *);
178 static void NdisReadNetworkAddress(ndis_status *, void **,
179 uint32_t *, ndis_handle);
180 static ndis_status NdisQueryMapRegisterCount(uint32_t, uint32_t *);
181 static ndis_status NdisMAllocateMapRegisters(ndis_handle,
182 uint32_t, uint8_t, uint32_t, uint32_t);
183 static void NdisMFreeMapRegisters(ndis_handle);
184 static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int);
185 static void NdisMAllocateSharedMemory(ndis_handle, uint32_t,
186 uint8_t, void **, ndis_physaddr *);
187 static void ndis_asyncmem_complete(device_object *, void *);
188 static ndis_status NdisMAllocateSharedMemoryAsync(ndis_handle,
189 uint32_t, uint8_t, void *);
190 static void NdisMFreeSharedMemory(ndis_handle, uint32_t,
191 uint8_t, void *, ndis_physaddr);
192 static ndis_status NdisMMapIoSpace(void **, ndis_handle,
193 ndis_physaddr, uint32_t);
194 static void NdisMUnmapIoSpace(ndis_handle, void *, uint32_t);
195 static uint32_t NdisGetCacheFillSize(void);
196 static void *NdisGetRoutineAddress(unicode_string *);
197 static uint32_t NdisMGetDmaAlignment(ndis_handle);
198 static ndis_status NdisMInitializeScatterGatherDma(ndis_handle,
200 static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **);
201 static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **);
202 static void NdisAllocateBufferPool(ndis_status *,
203 ndis_handle *, uint32_t);
204 static void NdisFreeBufferPool(ndis_handle);
205 static void NdisAllocateBuffer(ndis_status *, ndis_buffer **,
206 ndis_handle, void *, uint32_t);
207 static void NdisFreeBuffer(ndis_buffer *);
208 static uint32_t NdisBufferLength(ndis_buffer *);
209 static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *);
210 static void NdisQueryBufferSafe(ndis_buffer *, void **,
211 uint32_t *, uint32_t);
212 static void *NdisBufferVirtualAddress(ndis_buffer *);
213 static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t);
214 static void NdisAdjustBufferLength(ndis_buffer *, int);
215 static uint32_t NdisInterlockedIncrement(uint32_t *);
216 static uint32_t NdisInterlockedDecrement(uint32_t *);
217 static void NdisInitializeEvent(ndis_event *);
218 static void NdisSetEvent(ndis_event *);
219 static void NdisResetEvent(ndis_event *);
220 static uint8_t NdisWaitEvent(ndis_event *, uint32_t);
221 static ndis_status NdisUnicodeStringToAnsiString(ansi_string *,
224 NdisAnsiStringToUnicodeString(unicode_string *, ansi_string *);
225 static ndis_status NdisMPciAssignResources(ndis_handle,
226 uint32_t, ndis_resource_list **);
227 static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *,
228 ndis_handle, uint32_t, uint32_t, uint8_t,
229 uint8_t, ndis_interrupt_mode);
230 static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *);
231 static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *,
232 ndis_shutdown_handler);
233 static void NdisMDeregisterAdapterShutdownHandler(ndis_handle);
234 static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *);
235 static void NdisGetBufferPhysicalArraySize(ndis_buffer *,
237 static void NdisQueryBufferOffset(ndis_buffer *,
238 uint32_t *, uint32_t *);
239 static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle,
240 uint32_t, void *, uint32_t);
241 static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle,
242 uint32_t, void *, uint32_t);
243 static list_entry *NdisInterlockedInsertHeadList(list_entry *,
244 list_entry *, ndis_spin_lock *);
245 static list_entry *NdisInterlockedRemoveHeadList(list_entry *,
247 static list_entry *NdisInterlockedInsertTailList(list_entry *,
248 list_entry *, ndis_spin_lock *);
250 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *,
252 static void NdisGetCurrentSystemTime(uint64_t *);
253 static void NdisGetSystemUpTime(uint32_t *);
254 static uint32_t NdisGetVersion(void);
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 NdisGetCurrentProcessorCounts(uint32_t *, uint32_t *, uint32_t *);
276 static void NdisMIndicateStatusComplete(ndis_handle);
277 static void NdisMIndicateStatus(ndis_handle, ndis_status,
279 static uint8_t ndis_intr(kinterrupt *, void *);
280 static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *);
281 static funcptr ndis_findwrap(funcptr);
282 static void NdisCopyFromPacketToPacket(ndis_packet *,
283 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *);
284 static void NdisCopyFromPacketToPacketSafe(ndis_packet *,
285 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t);
286 static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *);
287 static ndis_status NdisMRegisterDevice(ndis_handle,
288 unicode_string *, unicode_string *, driver_dispatch **,
289 void **, ndis_handle *);
290 static ndis_status NdisMDeregisterDevice(ndis_handle);
292 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
293 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
294 static void dummy(void);
297 * Some really old drivers do not properly check the return value
298 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
299 * sometimes allocate few more buffers/packets that they originally
300 * requested when they created the pool. To prevent this from being
301 * a problem, we allocate a few extra buffers/packets beyond what
302 * the driver asks for. This #define controls how many.
304 #define NDIS_POOL_EXTRA 16
309 image_patch_table *patch;
311 strcpy(ndis_filepath, "/compat/ndis");
313 patch = ndis_functbl;
314 while (patch->ipt_func != NULL) {
315 windrv_wrap((funcptr)patch->ipt_func,
316 (funcptr *)&patch->ipt_wrap,
317 patch->ipt_argcnt, patch->ipt_ftype);
327 image_patch_table *patch;
329 patch = ndis_functbl;
330 while (patch->ipt_func != NULL) {
331 windrv_unwrap(patch->ipt_wrap);
339 ndis_findwrap(funcptr func)
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(ndis_handle *wrapper, driver_object *drv, void *path,
363 * As of yet, I haven't come up with a compelling
364 * reason to define a private NDIS wrapper structure,
365 * so we use a pointer to the driver object as the
366 * wrapper handle. The driver object has the miniport
367 * characteristics struct for this driver hung off it
368 * via IoAllocateDriverObjectExtension(), and that's
369 * really all the private data we need.
375 * If this was really Windows, we'd be registering dispatch
376 * routines for the NDIS miniport module here, but we're
377 * not Windows so all we really need to do is set up an
378 * AddDevice function that'll be invoked when a new device
382 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
386 NdisTerminateWrapper(ndis_handle handle, void *syspec)
388 /* Nothing to see here, move along. */
392 NdisMRegisterMiniport(ndis_handle handle,
393 ndis_miniport_characteristics *characteristics, int len)
395 ndis_miniport_characteristics *ch = NULL;
398 drv = (driver_object *)handle;
401 * We need to save the NDIS miniport characteristics
402 * somewhere. This data is per-driver, not per-device
403 * (all devices handled by the same driver have the
404 * same characteristics) so we hook it onto the driver
405 * object using IoAllocateDriverObjectExtension().
406 * The extra extension info is automagically deleted when
407 * the driver is unloaded (see windrv_unload()).
410 if (IoAllocateDriverObjectExtension(drv, (void *)1,
411 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
413 return (NDIS_STATUS_RESOURCES);
416 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
418 bcopy((char *)characteristics, (char *)ch, len);
420 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
421 ch->nmc_shutdown_handler = NULL;
422 ch->nmc_canceltxpkts_handler = NULL;
423 ch->nmc_pnpevent_handler = NULL;
426 return (NDIS_STATUS_SUCCESS);
430 NdisAllocateMemoryWithTag(void **vaddr, uint32_t len, uint32_t tag)
434 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
436 return (NDIS_STATUS_RESOURCES);
440 return (NDIS_STATUS_SUCCESS);
444 NdisAllocateMemory(void **vaddr, uint32_t len, uint32_t flags,
445 ndis_physaddr highaddr)
449 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
451 return (NDIS_STATUS_RESOURCES);
454 return (NDIS_STATUS_SUCCESS);
458 NdisFreeMemory(void *vaddr, uint32_t len, uint32_t flags)
467 NdisMSetAttributesEx(ndis_handle adapter_handle, ndis_handle adapter_ctx,
468 uint32_t hangsecs, uint32_t flags, ndis_interface_type iftype)
470 ndis_miniport_block *block;
473 * Save the adapter context, we need it for calling
474 * the driver's internal functions.
476 block = (ndis_miniport_block *)adapter_handle;
477 block->nmb_miniportadapterctx = adapter_ctx;
478 block->nmb_checkforhangsecs = hangsecs;
479 block->nmb_flags = flags;
481 return (NDIS_STATUS_SUCCESS);
485 NdisOpenConfiguration(ndis_status *status, ndis_handle *cfg,
489 *status = NDIS_STATUS_SUCCESS;
493 NdisOpenConfigurationKeyByName(ndis_status *status, ndis_handle cfg,
494 unicode_string *subkey, ndis_handle *subhandle)
497 *status = NDIS_STATUS_SUCCESS;
501 NdisOpenConfigurationKeyByIndex(ndis_status *status, ndis_handle cfg,
502 uint32_t idx, unicode_string *subkey, ndis_handle *subhandle)
504 *status = NDIS_STATUS_FAILURE;
508 ndis_encode_parm(ndis_miniport_block *block, struct sysctl_oid *oid,
509 ndis_parm_type type, ndis_config_parm **parm)
512 ndis_parmlist_entry *np;
519 np = ExAllocatePoolWithTag(NonPagedPool,
520 sizeof(ndis_parmlist_entry), 0);
522 return (NDIS_STATUS_RESOURCES);
523 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
524 *parm = p = &np->np_parm;
527 case ndis_parm_string:
528 /* See if this might be a number. */
529 val = strtoul((char *)oid->oid_arg1, NULL, 10);
530 us = &p->ncp_parmdata.ncp_stringdata;
531 p->ncp_type = ndis_parm_string;
533 ksnprintf(tmp, 32, "%x", val);
534 RtlInitAnsiString(&as, tmp);
536 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
539 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
541 return (NDIS_STATUS_RESOURCES);
545 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
549 p->ncp_type = ndis_parm_int;
550 p->ncp_parmdata.ncp_intdata =
551 strtol((char *)oid->oid_arg1, NULL, base);
553 case ndis_parm_hexint:
555 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
561 p->ncp_type = ndis_parm_hexint;
562 p->ncp_parmdata.ncp_intdata =
563 strtoul((char *)oid->oid_arg1, NULL, base);
566 return (NDIS_STATUS_FAILURE);
570 return (NDIS_STATUS_SUCCESS);
574 NdisReadConfiguration(ndis_status *status, ndis_config_parm **parm,
575 ndis_handle cfg, unicode_string *key, ndis_parm_type type)
578 ndis_miniport_block *block;
579 struct ndis_softc *sc;
580 struct sysctl_oid *oidp;
581 struct sysctl_ctx_entry *e;
584 block = (ndis_miniport_block *)cfg;
585 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
587 if (key->us_len == 0 || key->us_buf == NULL) {
588 *status = NDIS_STATUS_FAILURE;
592 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
593 *status = NDIS_STATUS_RESOURCES;
600 * See if registry key is already in a list of known keys
601 * included with the driver.
603 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
605 if (strcasecmp(oidp->oid_name, keystr) == 0) {
606 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
607 RtlFreeAnsiString(&as);
608 *status = NDIS_STATUS_FAILURE;
612 *status = ndis_encode_parm(block, oidp, type, parm);
613 RtlFreeAnsiString(&as);
619 * If the key didn't match, add it to the list of dynamically
620 * created ones. Sometimes, drivers refer to registry keys
621 * that aren't documented in their .INF files. These keys
622 * are supposed to be created by some sort of utility or
623 * control panel snap-in that comes with the driver software.
624 * Sometimes it's useful to be able to manipulate these.
625 * If the driver requests the key in the form of a string,
626 * make its default value an empty string, otherwise default
630 if (type == ndis_parm_int || type == ndis_parm_hexint)
631 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
632 "UNSET", CTLFLAG_RW);
634 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
635 "UNSET", CTLFLAG_RW);
637 RtlFreeAnsiString(&as);
638 *status = NDIS_STATUS_FAILURE;
642 ndis_decode_parm(ndis_miniport_block *block, ndis_config_parm *parm, char *val)
644 unicode_string *ustr;
647 switch(parm->ncp_type) {
648 case ndis_parm_string:
649 ustr = &parm->ncp_parmdata.ncp_stringdata;
650 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
651 return (NDIS_STATUS_RESOURCES);
652 bcopy(as.as_buf, val, as.as_len);
653 RtlFreeAnsiString(&as);
656 ksprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
658 case ndis_parm_hexint:
659 ksprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
662 return (NDIS_STATUS_FAILURE);
665 return (NDIS_STATUS_SUCCESS);
669 NdisWriteConfiguration(ndis_status *status, ndis_handle cfg,
670 unicode_string *key, ndis_config_parm *parm)
674 ndis_miniport_block *block;
675 struct ndis_softc *sc;
676 struct sysctl_oid *oidp;
677 struct sysctl_ctx_entry *e;
680 block = (ndis_miniport_block *)cfg;
681 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
683 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
684 *status = NDIS_STATUS_RESOURCES;
690 /* Decode the parameter into a string. */
691 bzero(val, sizeof(val));
692 *status = ndis_decode_parm(block, parm, val);
693 if (*status != NDIS_STATUS_SUCCESS) {
694 RtlFreeAnsiString(&as);
698 /* See if the key already exists. */
700 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
702 if (strcasecmp(oidp->oid_name, keystr) == 0) {
703 /* Found it, set the value. */
704 strcpy((char *)oidp->oid_arg1, val);
705 RtlFreeAnsiString(&as);
710 /* Not found, add a new key with the specified value. */
711 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
714 RtlFreeAnsiString(&as);
715 *status = NDIS_STATUS_SUCCESS;
719 NdisCloseConfiguration(ndis_handle cfg)
722 ndis_parmlist_entry *pe;
723 ndis_miniport_block *block;
726 block = (ndis_miniport_block *)cfg;
728 while (!IsListEmpty(&block->nmb_parmlist)) {
729 e = RemoveHeadList(&block->nmb_parmlist);
730 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
732 if (p->ncp_type == ndis_parm_string)
733 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
739 * Initialize a Windows spinlock.
742 NdisAllocateSpinLock(ndis_spin_lock *lock)
744 KeInitializeSpinLock(&lock->nsl_spinlock);
749 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
750 * for this. One is that it's sort of superfluous: we don't have to do anything
751 * special to deallocate the spinlock. The other is that there are some buggy
752 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
753 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
757 NdisFreeSpinLock(ndis_spin_lock *lock)
760 KeInitializeSpinLock(&lock->nsl_spinlock);
766 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
770 NdisAcquireSpinLock(ndis_spin_lock *lock)
772 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
776 * Release a spinlock from IRQL == DISPATCH_LEVEL.
780 NdisReleaseSpinLock(ndis_spin_lock *lock)
782 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
786 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
789 NdisDprAcquireSpinLock(ndis_spin_lock *lock)
791 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
795 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
798 NdisDprReleaseSpinLock(ndis_spin_lock *lock)
800 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
804 NdisInitializeReadWriteLock(ndis_rw_lock *lock)
806 KeInitializeSpinLock(&lock->nrl_spinlock);
807 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
811 NdisAcquireReadWriteLock(ndis_rw_lock *lock, uint8_t writeacc,
812 ndis_lock_state *state)
814 if (writeacc == TRUE) {
815 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
822 NdisReleaseReadWriteLock(ndis_rw_lock *lock, ndis_lock_state *state)
824 if (lock->nrl_rsvd[0]) {
826 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
832 NdisReadPciSlotInformation(ndis_handle adapter, uint32_t slot, uint32_t offset,
833 void *buf, uint32_t len)
835 ndis_miniport_block *block;
840 block = (ndis_miniport_block *)adapter;
845 dev = block->nmb_physdeviceobj->do_devext;
848 * I have a test system consisting of a Sun w2100z
849 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
850 * "Aries" miniPCI NIC. (The NIC is installed in the
851 * machine using a miniPCI to PCI bus adapter card.)
852 * When running in SMP mode, I found that
853 * performing a large number of consecutive calls to
854 * NdisReadPciSlotInformation() would result in a
855 * sudden system reset (or in some cases a freeze).
856 * My suspicion is that the multiple reads are somehow
857 * triggering a fatal PCI bus error that leads to a
858 * machine check. The 1us delay in the loop below
859 * seems to prevent this problem.
862 for (i = 0; i < len; i++) {
864 dest[i] = pci_read_config(dev, i + offset, 1);
871 NdisWritePciSlotInformation(ndis_handle adapter, uint32_t slot,
872 uint32_t offset, void *buf, uint32_t len)
874 ndis_miniport_block *block;
879 block = (ndis_miniport_block *)adapter;
885 dev = block->nmb_physdeviceobj->do_devext;
886 for (i = 0; i < len; i++) {
888 pci_write_config(dev, i + offset, dest[i], 1);
895 * The errorlog routine uses a variable argument list, so we
896 * have to declare it this way.
899 #define ERRMSGLEN 512
901 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
902 uint32_t numerrors, ...)
904 ndis_miniport_block *block;
911 struct ndis_softc *sc;
914 ansi_string as = { 0, 0, NULL };
916 block = (ndis_miniport_block *)adapter;
917 dev = block->nmb_physdeviceobj->do_devext;
918 drv = block->nmb_deviceobj->do_drvobj;
919 sc = device_get_softc(dev);
922 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
923 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
924 code, &str, &i, &flags);
926 if (flags & MESSAGE_RESOURCE_UNICODE) {
927 RtlInitUnicodeString(&us, (uint16_t *)str);
928 if (RtlUnicodeStringToAnsiString(&as,
929 &us, TRUE) == STATUS_SUCCESS)
937 device_printf(dev, "NDIS ERROR: %x (%s)\n", code,
938 str == NULL ? "unknown error" : str);
940 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
941 device_printf(dev, "NDIS NUMERRORS: %x\n", numerrors);
942 va_start(ap, numerrors);
943 for (i = 0; i < numerrors; i++)
944 device_printf(dev, "argptr: %p\n",
950 RtlFreeAnsiString(&as);
954 ndis_map_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
956 struct ndis_map_arg *ctx;
964 for (i = 0; i < nseg; i++) {
965 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
966 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
973 NdisMStartBufferPhysicalMapping(ndis_handle adapter, ndis_buffer *buf,
974 uint32_t mapreg, uint8_t writedev, ndis_paddr_unit *addrarray,
977 ndis_miniport_block *block;
978 struct ndis_softc *sc;
979 struct ndis_map_arg nma;
986 block = (ndis_miniport_block *)adapter;
987 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
989 if (mapreg > sc->ndis_mmapcnt)
992 map = sc->ndis_mmaps[mapreg];
993 nma.nma_fraglist = addrarray;
995 error = bus_dmamap_load(sc->ndis_mtag, map,
996 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
997 (void *)&nma, BUS_DMA_NOWAIT);
1002 bus_dmamap_sync(sc->ndis_mtag, map,
1003 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1005 *arraysize = nma.nma_cnt;
1009 NdisMCompleteBufferPhysicalMapping(ndis_handle adapter, ndis_buffer *buf,
1012 ndis_miniport_block *block;
1013 struct ndis_softc *sc;
1016 if (adapter == NULL)
1019 block = (ndis_miniport_block *)adapter;
1020 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1022 if (mapreg > sc->ndis_mmapcnt)
1025 map = sc->ndis_mmaps[mapreg];
1027 bus_dmamap_sync(sc->ndis_mtag, map,
1028 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1030 bus_dmamap_unload(sc->ndis_mtag, map);
1034 * This is an older (?) timer init routine which doesn't
1035 * accept a miniport context handle. Serialized miniports should
1036 * never call this function.
1040 NdisInitializeTimer(ndis_timer *timer, ndis_timer_function func, void *ctx)
1042 KeInitializeTimer(&timer->nt_ktimer);
1043 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1044 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1048 ndis_timercall(kdpc *dpc, ndis_miniport_timer *timer, void *sysarg1,
1052 * Since we're called as a DPC, we should be running
1053 * at DISPATCH_LEVEL here. This means to acquire the
1054 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1055 * rather than KeAcquireSpinLock().
1057 if (NDIS_SERIALIZED(timer->nmt_block))
1058 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1060 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1063 if (NDIS_SERIALIZED(timer->nmt_block))
1064 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1068 * For a long time I wondered why there were two NDIS timer initialization
1069 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1070 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1071 * function and context pointers separate from those in the DPC, which
1072 * allows for another level of indirection: when the timer fires, we
1073 * can have our own timer function invoked, and from there we can call
1074 * the driver's function. But why go to all that trouble? Then it hit
1075 * me: for serialized miniports, the timer callouts are not re-entrant.
1076 * By trapping the callouts and having access to the MiniportAdapterHandle,
1077 * we can protect the driver callouts by acquiring the NDIS serialization
1078 * lock. This is essential for allowing serialized miniports to work
1079 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1080 * is enough to prevent other threads from pre-empting you, but with
1081 * SMP, you must acquire a lock as well, otherwise the other CPU is
1082 * free to clobber you.
1085 NdisMInitializeTimer(ndis_miniport_timer *timer, ndis_handle handle,
1086 ndis_timer_function func, void *ctx)
1088 ndis_miniport_block *block;
1089 struct ndis_softc *sc;
1091 block = (ndis_miniport_block *)handle;
1092 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1094 /* Save the driver's funcptr and context */
1096 timer->nmt_timerfunc = func;
1097 timer->nmt_timerctx = ctx;
1098 timer->nmt_block = handle;
1101 * Set up the timer so it will call our intermediate DPC.
1102 * Be sure to use the wrapped entry point, since
1103 * ntoskrnl_run_dpc() expects to invoke a function with
1104 * Microsoft calling conventions.
1106 KeInitializeTimer(&timer->nmt_ktimer);
1107 KeInitializeDpc(&timer->nmt_kdpc,
1108 ndis_findwrap((funcptr)ndis_timercall), timer);
1109 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1113 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1114 * but the former is just a macro wrapper around the latter.
1117 NdisSetTimer(ndis_timer *timer, uint32_t msecs)
1120 * KeSetTimer() wants the period in
1121 * hundred nanosecond intervals.
1123 KeSetTimer(&timer->nt_ktimer,
1124 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1128 NdisMSetPeriodicTimer(ndis_miniport_timer *timer, uint32_t msecs)
1130 KeSetTimerEx(&timer->nmt_ktimer,
1131 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1135 * Technically, this is really NdisCancelTimer(), but we also
1136 * (ab)use it for NdisMCancelTimer(), since in our implementation
1137 * we don't need the extra info in the ndis_miniport_timer
1138 * structure just to cancel a timer.
1142 NdisMCancelTimer(ndis_timer *timer, uint8_t *cancelled)
1145 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1149 NdisMQueryAdapterResources(ndis_status *status, ndis_handle adapter,
1150 ndis_resource_list *list, uint32_t *buflen)
1152 ndis_miniport_block *block;
1153 struct ndis_softc *sc;
1156 block = (ndis_miniport_block *)adapter;
1157 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1159 rsclen = sizeof(ndis_resource_list) +
1160 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1161 if (*buflen < rsclen) {
1163 *status = NDIS_STATUS_INVALID_LENGTH;
1167 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1168 *status = NDIS_STATUS_SUCCESS;
1172 NdisMRegisterIoPortRange(void **offset, ndis_handle adapter, uint32_t port,
1175 struct ndis_miniport_block *block;
1176 struct ndis_softc *sc;
1178 if (adapter == NULL)
1179 return (NDIS_STATUS_FAILURE);
1181 block = (ndis_miniport_block *)adapter;
1182 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1184 if (sc->ndis_res_io == NULL)
1185 return (NDIS_STATUS_FAILURE);
1187 /* Don't let the device map more ports than we have. */
1188 if (rman_get_size(sc->ndis_res_io) < numports)
1189 return (NDIS_STATUS_INVALID_LENGTH);
1191 *offset = (void *)rman_get_start(sc->ndis_res_io);
1193 return (NDIS_STATUS_SUCCESS);
1197 NdisMDeregisterIoPortRange(ndis_handle adapter, uint32_t port,
1198 uint32_t numports, void *offset)
1203 NdisReadNetworkAddress(ndis_status *status, void **addr, uint32_t *addrlen,
1204 ndis_handle adapter)
1206 struct ndis_softc *sc;
1207 ndis_miniport_block *block;
1208 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1210 block = (ndis_miniport_block *)adapter;
1211 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1212 if (sc->ifp == NULL) {
1213 *status = NDIS_STATUS_FAILURE;
1217 if (sc->ifp->if_lladdr == NULL ||
1218 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1219 *status = NDIS_STATUS_FAILURE;
1221 *addr = IF_LLADDR(sc->ifp);
1222 *addrlen = ETHER_ADDR_LEN;
1223 *status = NDIS_STATUS_SUCCESS;
1228 NdisQueryMapRegisterCount(uint32_t bustype, uint32_t *cnt)
1231 return (NDIS_STATUS_SUCCESS);
1235 NdisMAllocateMapRegisters(ndis_handle adapter, uint32_t dmachannel,
1236 uint8_t dmasize, uint32_t physmapneeded, uint32_t maxmap)
1238 struct ndis_softc *sc;
1239 ndis_miniport_block *block;
1240 int error, i, nseg = NDIS_MAXSEG;
1242 block = (ndis_miniport_block *)adapter;
1243 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1245 sc->ndis_mmaps = kmalloc(sizeof(bus_dmamap_t) * physmapneeded,
1246 M_DEVBUF, M_NOWAIT|M_ZERO);
1248 if (sc->ndis_mmaps == NULL)
1249 return (NDIS_STATUS_RESOURCES);
1251 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1252 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1253 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1257 kfree(sc->ndis_mmaps, M_DEVBUF);
1258 return (NDIS_STATUS_RESOURCES);
1261 for (i = 0; i < physmapneeded; i++)
1262 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1264 sc->ndis_mmapcnt = physmapneeded;
1266 return (NDIS_STATUS_SUCCESS);
1270 NdisMFreeMapRegisters(ndis_handle adapter)
1272 struct ndis_softc *sc;
1273 ndis_miniport_block *block;
1276 block = (ndis_miniport_block *)adapter;
1277 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1279 for (i = 0; i < sc->ndis_mmapcnt; i++)
1280 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1282 kfree(sc->ndis_mmaps, M_DEVBUF);
1284 bus_dma_tag_destroy(sc->ndis_mtag);
1288 ndis_mapshared_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
1292 if (error || nseg > 1)
1297 p->np_quad = segs[0].ds_addr;
1301 * This maps to bus_dmamem_alloc().
1305 NdisMAllocateSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1306 void **vaddr, ndis_physaddr *paddr)
1308 ndis_miniport_block *block;
1309 struct ndis_softc *sc;
1310 struct ndis_shmem *sh;
1313 if (adapter == NULL)
1316 block = (ndis_miniport_block *)adapter;
1317 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1319 sh = kmalloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1323 InitializeListHead(&sh->ndis_list);
1326 * When performing shared memory allocations, create a tag
1327 * with a lowaddr limit that restricts physical memory mappings
1328 * so that they all fall within the first 1GB of memory.
1329 * At least one device/driver combination (Linksys Instant
1330 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1331 * problems with performing DMA operations with physical
1332 * addresses that lie above the 1GB mark. I don't know if this
1333 * is a hardware limitation or if the addresses are being
1334 * truncated within the driver, but this seems to be the only
1335 * way to make these cards work reliably in systems with more
1336 * than 1GB of physical memory.
1339 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1340 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1341 NULL, len, 1, len, BUS_DMA_ALLOCNOW, &sh->ndis_stag);
1344 kfree(sh, M_DEVBUF);
1348 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1349 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1352 bus_dma_tag_destroy(sh->ndis_stag);
1353 kfree(sh, M_DEVBUF);
1357 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1358 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1361 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1362 bus_dma_tag_destroy(sh->ndis_stag);
1363 kfree(sh, M_DEVBUF);
1368 * Save the physical address along with the source address.
1369 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1370 * with a bogus virtual address sometimes, but with a valid
1371 * physical address. To keep this from causing trouble, we
1372 * use the physical address to as a sanity check in case
1373 * searching based on the virtual address fails.
1377 sh->ndis_paddr.np_quad = paddr->np_quad;
1378 sh->ndis_saddr = *vaddr;
1379 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1383 struct ndis_allocwork {
1391 ndis_asyncmem_complete(device_object *dobj, void *arg)
1393 ndis_miniport_block *block;
1394 struct ndis_softc *sc;
1395 struct ndis_allocwork *w;
1397 ndis_physaddr paddr;
1398 ndis_allocdone_handler donefunc;
1401 block = (ndis_miniport_block *)dobj->do_devext;
1402 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1407 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1408 NdisMAllocateSharedMemory(block, w->na_len,
1409 w->na_cached, &vaddr, &paddr);
1410 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1412 IoFreeWorkItem(w->na_iw);
1417 NdisMAllocateSharedMemoryAsync(ndis_handle adapter, uint32_t len,
1418 uint8_t cached, void *ctx)
1420 ndis_miniport_block *block;
1421 struct ndis_allocwork *w;
1423 io_workitem_func ifw;
1425 if (adapter == NULL)
1426 return (NDIS_STATUS_FAILURE);
1430 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1432 return (NDIS_STATUS_FAILURE);
1434 w = kmalloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1437 return (NDIS_STATUS_FAILURE);
1439 w->na_cached = cached;
1444 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1445 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1447 return (NDIS_STATUS_PENDING);
1451 NdisMFreeSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1452 void *vaddr, ndis_physaddr paddr)
1454 ndis_miniport_block *block;
1455 struct ndis_softc *sc;
1456 struct ndis_shmem *sh = NULL;
1459 if (vaddr == NULL || adapter == NULL)
1462 block = (ndis_miniport_block *)adapter;
1463 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1465 /* Sanity check: is list empty? */
1467 if (IsListEmpty(&sc->ndis_shlist))
1471 l = sc->ndis_shlist.nle_flink;
1472 while (l != &sc->ndis_shlist) {
1473 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1474 if (sh->ndis_saddr == vaddr)
1477 * Check the physaddr too, just in case the driver lied
1478 * about the virtual address.
1480 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1487 kprintf("NDIS: buggy driver tried to free "
1488 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1489 vaddr, (uintmax_t)paddr.np_quad);
1493 RemoveEntryList(&sh->ndis_list);
1497 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1498 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1499 bus_dma_tag_destroy(sh->ndis_stag);
1501 kfree(sh, M_DEVBUF);
1505 NdisMMapIoSpace(void **vaddr, ndis_handle adapter, ndis_physaddr paddr,
1508 if (adapter == NULL)
1509 return (NDIS_STATUS_FAILURE);
1511 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1514 return (NDIS_STATUS_FAILURE);
1516 return (NDIS_STATUS_SUCCESS);
1520 NdisMUnmapIoSpace(ndis_handle adapter, void *vaddr, uint32_t len)
1522 MmUnmapIoSpace(vaddr, len);
1526 NdisGetCacheFillSize(void)
1532 NdisGetRoutineAddress(unicode_string *ustr)
1536 if (RtlUnicodeStringToAnsiString(&astr, ustr, TRUE))
1538 return (ndis_get_routine_address(ndis_functbl, astr.as_buf));
1542 NdisMGetDmaAlignment(ndis_handle handle)
1548 * NDIS has two methods for dealing with NICs that support DMA.
1549 * One is to just pass packets to the driver and let it call
1550 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1551 * all by itself, and the other is to let the NDIS library handle the
1552 * buffer mapping internally, and hand the driver an already populated
1553 * scatter/gather fragment list. If the driver calls
1554 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1559 NdisMInitializeScatterGatherDma(ndis_handle adapter, uint8_t is64,
1560 uint32_t maxphysmap)
1562 struct ndis_softc *sc;
1563 ndis_miniport_block *block;
1566 if (adapter == NULL)
1567 return (NDIS_STATUS_FAILURE);
1568 block = (ndis_miniport_block *)adapter;
1569 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1571 /* Don't do this twice. */
1572 if (sc->ndis_sc == 1)
1573 return (NDIS_STATUS_SUCCESS);
1575 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1576 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1577 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1582 return (NDIS_STATUS_SUCCESS);
1586 NdisAllocatePacketPool(ndis_status *status, ndis_handle *pool,
1587 uint32_t descnum, uint32_t protrsvdlen)
1589 ndis_packet_pool *p;
1590 ndis_packet *packets;
1593 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1595 *status = NDIS_STATUS_RESOURCES;
1599 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1600 p->np_protrsvd = protrsvdlen;
1601 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1603 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1607 if (packets == NULL) {
1609 *status = NDIS_STATUS_RESOURCES;
1613 p->np_pktmem = packets;
1615 for (i = 0; i < p->np_cnt; i++)
1616 InterlockedPushEntrySList(&p->np_head,
1617 (struct slist_entry *)&packets[i]);
1619 #ifdef NDIS_DEBUG_PACKETS
1621 KeInitializeSpinLock(&p->np_lock);
1622 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1626 *status = NDIS_STATUS_SUCCESS;
1630 NdisAllocatePacketPoolEx(ndis_status *status, ndis_handle *pool,
1631 uint32_t descnum, uint32_t oflowdescnum, uint32_t protrsvdlen)
1633 return (NdisAllocatePacketPool(status, pool,
1634 descnum + oflowdescnum, protrsvdlen));
1638 NdisPacketPoolUsage(ndis_handle pool)
1640 ndis_packet_pool *p;
1642 p = (ndis_packet_pool *)pool;
1643 return (p->np_cnt - ExQueryDepthSList(&p->np_head));
1647 NdisFreePacketPool(ndis_handle pool)
1649 ndis_packet_pool *p;
1651 #ifdef NDIS_DEBUG_PACKETS
1655 p = (ndis_packet_pool *)pool;
1657 #ifdef NDIS_DEBUG_PACKETS
1658 KeAcquireSpinLock(&p->np_lock, &irql);
1661 usage = NdisPacketPoolUsage(pool);
1663 #ifdef NDIS_DEBUG_PACKETS
1666 KeResetEvent(&p->np_event);
1667 KeReleaseSpinLock(&p->np_lock, irql);
1668 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1670 KeReleaseSpinLock(&p->np_lock, irql);
1673 ExFreePool(p->np_pktmem);
1678 NdisAllocatePacket(ndis_status *status, ndis_packet **packet, ndis_handle pool)
1680 ndis_packet_pool *p;
1682 #ifdef NDIS_DEBUG_PACKETS
1686 p = (ndis_packet_pool *)pool;
1688 #ifdef NDIS_DEBUG_PACKETS
1689 KeAcquireSpinLock(&p->np_lock, &irql);
1691 KeReleaseSpinLock(&p->np_lock, irql);
1692 kprintf("NDIS: tried to allocate packet from dead pool %p\n",
1694 *status = NDIS_STATUS_RESOURCES;
1699 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1701 #ifdef NDIS_DEBUG_PACKETS
1702 KeReleaseSpinLock(&p->np_lock, irql);
1706 *status = NDIS_STATUS_RESOURCES;
1711 bzero((char *)pkt, sizeof(ndis_packet));
1713 /* Save pointer to the pool. */
1714 pkt->np_private.npp_pool = pool;
1716 /* Set the oob offset pointer. Lots of things expect this. */
1717 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1720 * We must initialize the packet flags correctly in order
1721 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1722 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1725 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1726 pkt->np_private.npp_validcounts = FALSE;
1730 *status = NDIS_STATUS_SUCCESS;
1734 NdisFreePacket(ndis_packet *packet)
1736 ndis_packet_pool *p;
1737 #ifdef NDIS_DEBUG_PACKETS
1741 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1743 #ifdef NDIS_DEBUG_PACKETS
1744 KeAcquireSpinLock(&p->np_lock, &irql);
1747 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1749 #ifdef NDIS_DEBUG_PACKETS
1751 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1752 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1754 KeReleaseSpinLock(&p->np_lock, irql);
1759 NdisUnchainBufferAtFront(ndis_packet *packet, ndis_buffer **buf)
1761 ndis_packet_private *priv;
1763 if (packet == NULL || buf == NULL)
1766 priv = &packet->np_private;
1768 priv->npp_validcounts = FALSE;
1770 if (priv->npp_head == priv->npp_tail) {
1771 *buf = priv->npp_head;
1772 priv->npp_head = priv->npp_tail = NULL;
1774 *buf = priv->npp_head;
1775 priv->npp_head = (*buf)->mdl_next;
1780 NdisUnchainBufferAtBack(ndis_packet *packet, ndis_buffer **buf)
1782 ndis_packet_private *priv;
1785 if (packet == NULL || buf == NULL)
1788 priv = &packet->np_private;
1790 priv->npp_validcounts = FALSE;
1792 if (priv->npp_head == priv->npp_tail) {
1793 *buf = priv->npp_head;
1794 priv->npp_head = priv->npp_tail = NULL;
1796 *buf = priv->npp_tail;
1797 tmp = priv->npp_head;
1798 while (tmp->mdl_next != priv->npp_tail)
1799 tmp = tmp->mdl_next;
1800 priv->npp_tail = tmp;
1801 tmp->mdl_next = NULL;
1806 * The NDIS "buffer" is really an MDL (memory descriptor list)
1807 * which is used to describe a buffer in a way that allows it
1808 * to mapped into different contexts. We have to be careful how
1809 * we handle them: in some versions of Windows, the NdisFreeBuffer()
1810 * routine is an actual function in the NDIS API, but in others
1811 * it's just a macro wrapper around IoFreeMdl(). There's really
1812 * no way to use the 'descnum' parameter to count how many
1813 * "buffers" are allocated since in order to use IoFreeMdl() to
1814 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
1815 * them, and IoAllocateMdl() just grabs them out of the heap.
1819 NdisAllocateBufferPool(ndis_status *status, ndis_handle *pool,
1824 * The only thing we can really do here is verify that descnum
1825 * is a reasonable value, but I really don't know what to check
1829 *pool = NonPagedPool;
1830 *status = NDIS_STATUS_SUCCESS;
1834 NdisFreeBufferPool(ndis_handle pool)
1839 NdisAllocateBuffer(ndis_status *status, ndis_buffer **buffer, ndis_handle pool,
1840 void *vaddr, uint32_t len)
1844 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
1846 *status = NDIS_STATUS_RESOURCES;
1850 MmBuildMdlForNonPagedPool(buf);
1853 *status = NDIS_STATUS_SUCCESS;
1857 NdisFreeBuffer(ndis_buffer *buf)
1865 NdisBufferLength(ndis_buffer *buf)
1867 return (MmGetMdlByteCount(buf));
1871 * Get the virtual address and length of a buffer.
1872 * Note: the vaddr argument is optional.
1876 NdisQueryBuffer(ndis_buffer *buf, void **vaddr, uint32_t *len)
1879 *vaddr = MmGetMdlVirtualAddress(buf);
1880 *len = MmGetMdlByteCount(buf);
1883 /* Same as above -- we don't care about the priority. */
1886 NdisQueryBufferSafe(ndis_buffer *buf, void **vaddr, uint32_t *len,
1890 *vaddr = MmGetMdlVirtualAddress(buf);
1891 *len = MmGetMdlByteCount(buf);
1894 /* Damnit Microsoft!! How many ways can you do the same thing?! */
1897 NdisBufferVirtualAddress(ndis_buffer *buf)
1899 return (MmGetMdlVirtualAddress(buf));
1903 NdisBufferVirtualAddressSafe(ndis_buffer *buf, uint32_t prio)
1905 return (MmGetMdlVirtualAddress(buf));
1909 NdisAdjustBufferLength(ndis_buffer *buf, int len)
1911 MmGetMdlByteCount(buf) = len;
1915 NdisInterlockedIncrement(uint32_t *addend)
1917 atomic_add_long((u_long *)addend, 1);
1922 NdisInterlockedDecrement(uint32_t *addend)
1924 atomic_subtract_long((u_long *)addend, 1);
1929 NdisGetVersion(void)
1931 return (0x00050001);
1935 NdisInitializeEvent(ndis_event *event)
1938 * NDIS events are always notification
1939 * events, and should be initialized to the
1940 * not signaled state.
1942 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
1946 NdisSetEvent(ndis_event *event)
1948 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
1952 NdisResetEvent(ndis_event *event)
1954 KeResetEvent(&event->ne_event);
1958 NdisWaitEvent(ndis_event *event, uint32_t msecs)
1963 duetime = ((int64_t)msecs * -10000);
1964 rval = KeWaitForSingleObject(event,
1965 0, 0, TRUE, msecs ? & duetime : NULL);
1967 if (rval == STATUS_TIMEOUT)
1974 NdisUnicodeStringToAnsiString(ansi_string *dstr, unicode_string *sstr)
1978 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
1980 if (rval == STATUS_INSUFFICIENT_RESOURCES)
1981 return (NDIS_STATUS_RESOURCES);
1983 return (NDIS_STATUS_FAILURE);
1985 return (NDIS_STATUS_SUCCESS);
1989 NdisAnsiStringToUnicodeString(unicode_string *dstr, ansi_string *sstr)
1993 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
1995 if (rval == STATUS_INSUFFICIENT_RESOURCES)
1996 return (NDIS_STATUS_RESOURCES);
1998 return (NDIS_STATUS_FAILURE);
2000 return (NDIS_STATUS_SUCCESS);
2004 NdisMPciAssignResources(ndis_handle adapter, uint32_t slot,
2005 ndis_resource_list **list)
2007 ndis_miniport_block *block;
2009 if (adapter == NULL || list == NULL)
2010 return (NDIS_STATUS_FAILURE);
2012 block = (ndis_miniport_block *)adapter;
2013 *list = block->nmb_rlist;
2015 return (NDIS_STATUS_SUCCESS);
2019 ndis_intr(kinterrupt *iobj, void *arg)
2021 struct ndis_softc *sc;
2022 uint8_t is_our_intr = FALSE;
2024 ndis_miniport_interrupt *intr;
2027 intr = sc->ndis_block->nmb_interrupt;
2029 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2032 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2033 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2034 sc->ndis_block->nmb_miniportadapterctx);
2036 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2037 sc->ndis_block->nmb_miniportadapterctx);
2042 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2044 return (is_our_intr);
2048 ndis_intrhand(kdpc *dpc, ndis_miniport_interrupt *intr, void *sysarg1,
2051 struct ndis_softc *sc;
2052 ndis_miniport_block *block;
2053 ndis_handle adapter;
2055 block = intr->ni_block;
2056 adapter = block->nmb_miniportadapterctx;
2057 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2059 if (NDIS_SERIALIZED(sc->ndis_block))
2060 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2062 MSCALL1(intr->ni_dpcfunc, adapter);
2064 /* If there's a MiniportEnableInterrupt() routine, call it. */
2066 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2067 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2069 if (NDIS_SERIALIZED(sc->ndis_block))
2070 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2073 * Set the completion event if we've drained all
2074 * pending interrupts.
2077 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2079 if (intr->ni_dpccnt == 0)
2080 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2081 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2085 NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter,
2086 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared,
2087 ndis_interrupt_mode imode)
2089 ndis_miniport_block *block;
2090 ndis_miniport_characteristics *ch;
2091 struct ndis_softc *sc;
2095 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2096 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2099 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2100 sizeof(struct mtx), 0);
2101 if (intr->ni_rsvd == NULL)
2102 return (NDIS_STATUS_RESOURCES);
2104 intr->ni_block = adapter;
2105 intr->ni_isrreq = reqisr;
2106 intr->ni_shared = shared;
2107 intr->ni_dpccnt = 0;
2108 intr->ni_isrfunc = ch->nmc_isr_func;
2109 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2111 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2112 KeInitializeDpc(&intr->ni_dpc,
2113 ndis_findwrap((funcptr)ndis_intrhand), intr);
2114 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2116 error = IoConnectInterrupt(&intr->ni_introbj,
2117 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2118 ivec, ilevel, 0, imode, shared, 0, FALSE);
2120 if (error != STATUS_SUCCESS)
2121 return (NDIS_STATUS_FAILURE);
2123 block->nmb_interrupt = intr;
2125 return (NDIS_STATUS_SUCCESS);
2129 NdisMDeregisterInterrupt(ndis_miniport_interrupt *intr)
2131 ndis_miniport_block *block;
2134 block = intr->ni_block;
2136 /* Should really be KeSynchronizeExecution() */
2138 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2139 block->nmb_interrupt = NULL;
2140 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2142 KeFlushQueuedDpcs();
2144 /* Disconnect our ISR */
2146 IoDisconnectInterrupt(intr->ni_introbj);
2148 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2149 KeResetEvent(&intr->ni_dpcevt);
2153 NdisMRegisterAdapterShutdownHandler(ndis_handle adapter, void *shutdownctx,
2154 ndis_shutdown_handler shutdownfunc)
2156 ndis_miniport_block *block;
2157 ndis_miniport_characteristics *chars;
2158 struct ndis_softc *sc;
2160 if (adapter == NULL)
2163 block = (ndis_miniport_block *)adapter;
2164 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2165 chars = sc->ndis_chars;
2167 chars->nmc_shutdown_handler = shutdownfunc;
2168 chars->nmc_rsvd0 = shutdownctx;
2172 NdisMDeregisterAdapterShutdownHandler(ndis_handle adapter)
2174 ndis_miniport_block *block;
2175 ndis_miniport_characteristics *chars;
2176 struct ndis_softc *sc;
2178 if (adapter == NULL)
2181 block = (ndis_miniport_block *)adapter;
2182 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2183 chars = sc->ndis_chars;
2185 chars->nmc_shutdown_handler = NULL;
2186 chars->nmc_rsvd0 = NULL;
2190 NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *buf)
2194 if (MmGetMdlByteCount(buf) == 0)
2196 return (SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2197 MmGetMdlByteCount(buf)));
2201 NdisGetBufferPhysicalArraySize(ndis_buffer *buf, uint32_t *pages)
2206 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2210 NdisQueryBufferOffset(ndis_buffer *buf, uint32_t *off, uint32_t *len)
2215 *off = MmGetMdlByteOffset(buf);
2216 *len = MmGetMdlByteCount(buf);
2220 NdisMSleep(uint32_t usecs)
2225 * During system bootstrap, (i.e. cold == 1), we aren't
2226 * allowed to sleep, so we have to do a hard DELAY()
2233 KeInitializeTimer(&timer);
2234 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2235 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2240 NdisReadPcmciaAttributeMemory(ndis_handle handle, uint32_t offset, void *buf,
2243 struct ndis_softc *sc;
2244 ndis_miniport_block *block;
2245 bus_space_handle_t bh;
2253 block = (ndis_miniport_block *)handle;
2254 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2257 bh = rman_get_bushandle(sc->ndis_res_am);
2258 bt = rman_get_bustag(sc->ndis_res_am);
2260 for (i = 0; i < len; i++)
2261 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2267 NdisWritePcmciaAttributeMemory(ndis_handle handle, uint32_t offset, void *buf,
2270 struct ndis_softc *sc;
2271 ndis_miniport_block *block;
2272 bus_space_handle_t bh;
2280 block = (ndis_miniport_block *)handle;
2281 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2284 bh = rman_get_bushandle(sc->ndis_res_am);
2285 bt = rman_get_bustag(sc->ndis_res_am);
2287 for (i = 0; i < len; i++)
2288 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2294 NdisInterlockedInsertHeadList(list_entry *head, list_entry *entry,
2295 ndis_spin_lock *lock)
2299 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2300 flink = head->nle_flink;
2301 entry->nle_flink = flink;
2302 entry->nle_blink = head;
2303 flink->nle_blink = entry;
2304 head->nle_flink = entry;
2305 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2311 NdisInterlockedRemoveHeadList(list_entry *head, ndis_spin_lock *lock)
2316 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2317 entry = head->nle_flink;
2318 flink = entry->nle_flink;
2319 head->nle_flink = flink;
2320 flink->nle_blink = head;
2321 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2327 NdisInterlockedInsertTailList(list_entry *head, list_entry *entry,
2328 ndis_spin_lock *lock)
2332 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2333 blink = head->nle_blink;
2334 entry->nle_flink = head;
2335 entry->nle_blink = blink;
2336 blink->nle_flink = entry;
2337 head->nle_blink = entry;
2338 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2344 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *intr, void *syncfunc,
2347 return (KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2351 NdisGetCurrentSystemTime(uint64_t *tval)
2353 ntoskrnl_time(tval);
2357 * Return the number of milliseconds since the system booted.
2360 NdisGetSystemUpTime(uint32_t *tval)
2365 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2369 NdisInitializeString(unicode_string *dst, char *src)
2372 RtlInitAnsiString(&as, src);
2373 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2377 NdisFreeString(unicode_string *str)
2379 RtlFreeUnicodeString(str);
2383 NdisMRemoveMiniport(ndis_handle *adapter)
2385 return (NDIS_STATUS_SUCCESS);
2389 NdisInitAnsiString(ansi_string *dst, char *src)
2391 RtlInitAnsiString(dst, src);
2395 NdisInitUnicodeString(unicode_string *dst, uint16_t *src)
2397 RtlInitUnicodeString(dst, src);
2400 static void NdisMGetDeviceProperty(ndis_handle adapter,
2401 device_object **phydevobj, device_object **funcdevobj,
2402 device_object **nextdevobj, cm_resource_list *resources,
2403 cm_resource_list *transresources)
2405 ndis_miniport_block *block;
2407 block = (ndis_miniport_block *)adapter;
2409 if (phydevobj != NULL)
2410 *phydevobj = block->nmb_physdeviceobj;
2411 if (funcdevobj != NULL)
2412 *funcdevobj = block->nmb_deviceobj;
2413 if (nextdevobj != NULL)
2414 *nextdevobj = block->nmb_nextdeviceobj;
2418 NdisGetFirstBufferFromPacket(ndis_packet *packet, ndis_buffer **buf,
2419 void **firstva, uint32_t *firstlen, uint32_t *totlen)
2423 tmp = packet->np_private.npp_head;
2427 *firstlen = *totlen = 0;
2429 *firstva = MmGetMdlVirtualAddress(tmp);
2430 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2431 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2432 *totlen += MmGetMdlByteCount(tmp);
2437 NdisGetFirstBufferFromPacketSafe(ndis_packet *packet, ndis_buffer **buf,
2438 void **firstva, uint32_t *firstlen, uint32_t *totlen, uint32_t prio)
2440 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2444 ndis_find_sym(linker_file_t lf, char *filename, char *suffix, caddr_t *sym)
2450 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2451 if (fullsym == NULL)
2454 bzero(fullsym, MAXPATHLEN);
2455 strncpy(fullsym, filename, MAXPATHLEN);
2456 if (strlen(filename) < 4) {
2457 ExFreePool(fullsym);
2461 /* If the filename has a .ko suffix, strip if off. */
2462 suf = fullsym + (strlen(filename) - 3);
2463 if (strcmp(suf, ".ko") == 0)
2466 for (i = 0; i < strlen(fullsym); i++) {
2467 if (fullsym[i] == '.')
2470 fullsym[i] = tolower(fullsym[i]);
2472 strcat(fullsym, suffix);
2473 linker_file_lookup_symbol(lf, fullsym, 0, sym);
2474 ExFreePool(fullsym);
2481 struct ndis_checkmodule {
2487 * See if a single module contains the symbols for a specified file.
2490 NdisCheckModule(linker_file_t lf, void *context)
2492 struct ndis_checkmodule *nc;
2493 caddr_t kldstart, kldend;
2495 nc = (struct ndis_checkmodule *)context;
2496 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2498 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2501 nc->fh->nf_map = NULL;
2502 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2503 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2507 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2509 NdisOpenFile(ndis_status *status, ndis_handle *filehandle,
2510 uint32_t *filelength, unicode_string *filename, ndis_physaddr highestaddr)
2513 char *afilename = NULL;
2514 struct thread *td = curthread;
2515 struct nlookupdata nd;
2518 struct vattr *vap = &vat;
2521 struct ndis_checkmodule nc;
2524 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2525 *status = NDIS_STATUS_RESOURCES;
2529 afilename = kstrdup(as.as_buf, M_DEVBUF);
2530 RtlFreeAnsiString(&as);
2532 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2534 kfree(afilename, M_DEVBUF);
2535 *status = NDIS_STATUS_RESOURCES;
2539 fh->nf_name = afilename;
2542 * During system bootstrap, it's impossible to load files
2543 * from the rootfs since it's not mounted yet. We therefore
2544 * offer the possibility of opening files that have been
2545 * preloaded as modules instead. Both choices will work
2546 * when kldloading a module from multiuser, but only the
2547 * module option will work during bootstrap. The module
2548 * loading option works by using the ndiscvt(8) utility
2549 * to convert the arbitrary file into a .ko using objcopy(1).
2550 * This file will contain two special symbols: filename_start
2551 * and filename_end. All we have to do is traverse the KLD
2552 * list in search of those symbols and we've found the file
2553 * data. As an added bonus, ndiscvt(8) will also generate
2554 * a normal .o file which can be linked statically with
2555 * the kernel. This means that the symbols will actual reside
2556 * in the kernel's symbol table, but that doesn't matter to
2557 * us since the kernel appears to us as just another module.
2560 nc.afilename = afilename;
2562 if (linker_file_foreach(NdisCheckModule, &nc)) {
2563 *filelength = fh->nf_maplen;
2565 *status = NDIS_STATUS_SUCCESS;
2569 if (mountlist_boot_getfirst() == NULL) {
2571 *status = NDIS_STATUS_FILE_NOT_FOUND;
2572 kprintf("NDIS: could not find file %s in linker list\n",
2574 kprintf("NDIS: and no filesystems mounted yet, "
2575 "aborting NdisOpenFile()\n");
2576 kfree(afilename, M_DEVBUF);
2580 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2583 kfree(afilename, M_DEVBUF);
2584 *status = NDIS_STATUS_RESOURCES;
2588 ksnprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2590 /* Some threads don't have a current working directory. */
2592 if (td->td_proc && td->td_proc->p_fd->fd_rdir == NULL)
2593 td->td_proc->p_fd->fd_rdir = rootvnode;
2594 if (td->td_proc && td->td_proc->p_fd->fd_cdir == NULL)
2595 td->td_proc->p_fd->fd_cdir = rootvnode;
2597 error = nlookup_init(&nd, path, UIO_SYSSPACE, NLC_FOLLOW|NLC_LOCKVP);
2600 error = vn_open(&nd, NULL, FREAD, 0);
2607 nd.nl_open_vp = NULL;
2609 /* Get the file size. */
2610 VOP_GETATTR(vp, vap);
2613 fh->nf_vp = nd.nl_open_vp;
2615 fh->nf_type = NDIS_FH_TYPE_VFS;
2617 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2618 *status = NDIS_STATUS_SUCCESS;
2625 *status = NDIS_STATUS_FILE_NOT_FOUND;
2627 kprintf("NDIS: open file %s failed: %d\n", path, error);
2629 kfree(afilename, M_DEVBUF);
2633 NdisMapFile(ndis_status *status, void **mappedbuffer, ndis_handle filehandle)
2636 struct thread *td = curthread;
2642 if (filehandle == NULL) {
2643 *status = NDIS_STATUS_FAILURE;
2647 fh = (ndis_fh *)filehandle;
2649 if (fh->nf_vp == NULL) {
2650 *status = NDIS_STATUS_FAILURE;
2654 if (fh->nf_map != NULL) {
2655 *status = NDIS_STATUS_ALREADY_MAPPED;
2659 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
2661 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
2662 *status = NDIS_STATUS_FAILURE;
2665 fh->nf_map = kldstart;
2666 *status = NDIS_STATUS_SUCCESS;
2667 *mappedbuffer = fh->nf_map;
2671 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
2673 if (fh->nf_map == NULL) {
2674 *status = NDIS_STATUS_RESOURCES;
2679 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
2680 UIO_SYSSPACE, 0, td->td_ucred, &resid);
2683 *status = NDIS_STATUS_FAILURE;
2685 *status = NDIS_STATUS_SUCCESS;
2686 *mappedbuffer = fh->nf_map;
2691 NdisUnmapFile(ndis_handle filehandle)
2694 fh = (ndis_fh *)filehandle;
2696 if (fh->nf_map == NULL)
2699 if (fh->nf_type == NDIS_FH_TYPE_VFS)
2700 ExFreePool(fh->nf_map);
2705 NdisCloseFile(ndis_handle filehandle)
2710 if (filehandle == NULL)
2713 fh = (ndis_fh *)filehandle;
2714 if (fh->nf_map != NULL) {
2715 if (fh->nf_type == NDIS_FH_TYPE_VFS)
2716 ExFreePool(fh->nf_map);
2720 if (fh->nf_vp == NULL)
2723 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
2725 vn_close(vp, FREAD);
2729 kfree(fh->nf_name, M_DEVBUF);
2734 NdisSystemProcessorCount(void)
2740 NdisGetCurrentProcessorCounts(uint32_t *idle_count, uint32_t *kernel_and_user,
2743 #if 0 /* XXX swildner */
2746 pcpu = pcpu_find(curthread->td_oncpu);
2747 *index = pcpu->pc_cpuid;
2748 *idle_count = pcpu->pc_cp_time[CP_IDLE];
2749 *kernel_and_user = pcpu->pc_cp_time[CP_INTR];
2751 panic("%s", __func__);
2755 typedef void (*ndis_statusdone_handler)(ndis_handle);
2756 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
2760 NdisMIndicateStatusComplete(ndis_handle adapter)
2762 ndis_miniport_block *block;
2763 ndis_statusdone_handler statusdonefunc;
2765 block = (ndis_miniport_block *)adapter;
2766 statusdonefunc = block->nmb_statusdone_func;
2768 MSCALL1(statusdonefunc, adapter);
2772 NdisMIndicateStatus(ndis_handle adapter, ndis_status status, void *sbuf,
2775 ndis_miniport_block *block;
2776 ndis_status_handler statusfunc;
2778 block = (ndis_miniport_block *)adapter;
2779 statusfunc = block->nmb_status_func;
2781 MSCALL4(statusfunc, adapter, status, sbuf, slen);
2785 * The DDK documentation says that you should use IoQueueWorkItem()
2786 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
2787 * is fundamentally incompatible with NdisScheduleWorkItem(), which
2788 * depends on the API semantics of ExQueueWorkItem(). In our world,
2789 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
2792 * There are actually three distinct APIs here. NdisScheduleWorkItem()
2793 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
2794 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
2795 * to an opaque work item thingie which you get from IoAllocateWorkItem().
2796 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
2797 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
2798 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
2799 * to ExQueueWorkItem().
2801 * Got all that? (Sheesh.)
2805 NdisScheduleWorkItem(ndis_work_item *work)
2807 work_queue_item *wqi;
2809 wqi = (work_queue_item *)work->nwi_wraprsvd;
2810 ExInitializeWorkItem(wqi,
2811 (work_item_func)work->nwi_func, work->nwi_ctx);
2812 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
2814 return (NDIS_STATUS_SUCCESS);
2818 NdisCopyFromPacketToPacket(ndis_packet *dpkt, uint32_t doff, uint32_t reqlen,
2819 ndis_packet *spkt, uint32_t soff, uint32_t *cpylen)
2821 ndis_buffer *src, *dst;
2823 int resid, copied, len, scnt, dcnt;
2827 src = spkt->np_private.npp_head;
2828 dst = dpkt->np_private.npp_head;
2830 sptr = MmGetMdlVirtualAddress(src);
2831 dptr = MmGetMdlVirtualAddress(dst);
2832 scnt = MmGetMdlByteCount(src);
2833 dcnt = MmGetMdlByteCount(dst);
2836 if (MmGetMdlByteCount(src) > soff) {
2838 scnt = MmGetMdlByteCount(src)- soff;
2841 soff -= MmGetMdlByteCount(src);
2842 src = src->mdl_next;
2845 sptr = MmGetMdlVirtualAddress(src);
2849 if (MmGetMdlByteCount(dst) > doff) {
2851 dcnt = MmGetMdlByteCount(dst) - doff;
2854 doff -= MmGetMdlByteCount(dst);
2855 dst = dst->mdl_next;
2858 dptr = MmGetMdlVirtualAddress(dst);
2872 bcopy(sptr, dptr, len);
2881 dst = dst->mdl_next;
2884 dptr = MmGetMdlVirtualAddress(dst);
2885 dcnt = MmGetMdlByteCount(dst);
2890 src = src->mdl_next;
2893 sptr = MmGetMdlVirtualAddress(src);
2894 scnt = MmGetMdlByteCount(src);
2902 NdisCopyFromPacketToPacketSafe(ndis_packet *dpkt, uint32_t doff,
2903 uint32_t reqlen, ndis_packet *spkt, uint32_t soff, uint32_t *cpylen,
2906 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
2910 NdisIMCopySendPerPacketInfo(ndis_packet *dpkt, ndis_packet *spkt)
2912 memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension));
2916 NdisMRegisterDevice(ndis_handle handle, unicode_string *devname,
2917 unicode_string *symname, driver_dispatch *majorfuncs[], void **devobj,
2918 ndis_handle *devhandle)
2921 device_object *dobj;
2923 status = IoCreateDevice(handle, 0, devname,
2924 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
2926 if (status == STATUS_SUCCESS) {
2935 NdisMDeregisterDevice(ndis_handle handle)
2937 IoDeleteDevice(handle);
2938 return (NDIS_STATUS_SUCCESS);
2942 NdisMQueryAdapterInstanceName(unicode_string *name, ndis_handle handle)
2944 ndis_miniport_block *block;
2948 block = (ndis_miniport_block *)handle;
2949 dev = block->nmb_physdeviceobj->do_devext;
2951 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
2952 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
2953 return (NDIS_STATUS_RESOURCES);
2955 return (NDIS_STATUS_SUCCESS);
2959 NdisMRegisterUnloadHandler(ndis_handle handle, void *func)
2966 kprintf("NDIS dummy called...\n");
2970 * Note: a couple of entries in this table specify the
2971 * number of arguments as "foo + 1". These are routines
2972 * that accept a 64-bit argument, passed by value. On
2973 * x86, these arguments consume two longwords on the stack,
2974 * so we lie and say there's one additional argument so
2975 * that the wrapping routines will do the right thing.
2978 image_patch_table ndis_functbl[] = {
2979 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
2980 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
2981 IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2),
2982 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
2983 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
2984 IMPORT_SFUNC(NdisMIndicateStatus, 4),
2985 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
2986 IMPORT_SFUNC(NdisGetCurrentProcessorCounts, 3),
2987 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
2988 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
2989 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
2990 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
2991 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
2992 IMPORT_SFUNC(NdisInitAnsiString, 2),
2993 IMPORT_SFUNC(NdisInitUnicodeString, 2),
2994 IMPORT_SFUNC(NdisWriteConfiguration, 4),
2995 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
2996 IMPORT_SFUNC(NdisTerminateWrapper, 2),
2997 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
2998 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
2999 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3000 IMPORT_SFUNC(NdisInitializeString, 2),
3001 IMPORT_SFUNC(NdisFreeString, 1),
3002 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3003 IMPORT_SFUNC(NdisGetRoutineAddress, 1),
3004 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3005 IMPORT_SFUNC(NdisGetVersion, 0),
3006 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3007 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3008 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3009 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3010 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3011 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3012 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3013 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3014 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3015 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3016 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3017 IMPORT_SFUNC(NdisReadConfiguration, 5),
3018 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3019 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3020 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3021 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3022 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3023 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3024 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3025 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3026 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3027 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3028 IMPORT_SFUNC(NdisFreeMemory, 3),
3029 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3030 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3031 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3032 NdisReadPciSlotInformation, 5),
3033 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3034 NdisWritePciSlotInformation, 5),
3035 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3036 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3037 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3038 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3039 IMPORT_SFUNC(NdisInitializeTimer, 3),
3040 IMPORT_SFUNC(NdisSetTimer, 2),
3041 IMPORT_SFUNC(NdisMCancelTimer, 2),
3042 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3043 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3044 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3045 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3046 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3047 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3048 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3049 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3050 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3051 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3052 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3053 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3054 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3055 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3056 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3057 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3058 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3059 IMPORT_SFUNC(NdisAllocatePacket, 3),
3060 IMPORT_SFUNC(NdisFreePacket, 1),
3061 IMPORT_SFUNC(NdisFreePacketPool, 1),
3062 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3063 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3064 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3065 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3066 IMPORT_SFUNC(NdisQueryBuffer, 3),
3067 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3068 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3069 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3070 IMPORT_SFUNC(NdisBufferLength, 1),
3071 IMPORT_SFUNC(NdisFreeBuffer, 1),
3072 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3073 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3074 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3075 IMPORT_SFUNC(NdisInitializeEvent, 1),
3076 IMPORT_SFUNC(NdisSetEvent, 1),
3077 IMPORT_SFUNC(NdisResetEvent, 1),
3078 IMPORT_SFUNC(NdisWaitEvent, 2),
3079 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3080 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3081 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3082 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3083 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3084 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3085 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3086 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3087 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3088 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3089 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3090 IMPORT_SFUNC(NdisMSleep, 1),
3091 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3092 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3093 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3094 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3095 IMPORT_SFUNC(NdisMapFile, 3),
3096 IMPORT_SFUNC(NdisUnmapFile, 1),
3097 IMPORT_SFUNC(NdisCloseFile, 1),
3098 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3099 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3100 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3101 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3102 IMPORT_SFUNC(ndis_timercall, 4),
3103 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3104 IMPORT_SFUNC(ndis_intr, 2),
3105 IMPORT_SFUNC(ndis_intrhand, 4),
3108 * This last entry is a catch-all for any function we haven't
3109 * implemented yet. The PE import list patching routine will
3110 * use it for any function that doesn't have an explicit match
3114 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3118 { NULL, NULL, NULL }