3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * This file implements a translation layer between the BSD networking
38 * infrasturcture and Windows(R) NDIS network driver modules. A Windows
39 * NDIS driver calls into several functions in the NDIS.SYS Windows
40 * kernel module and exports a table of functions designed to be called
41 * by the NDIS subsystem. Using the PE loader, we can patch our own
42 * versions of the NDIS routines into a given Windows driver module and
43 * convince the driver that it is in fact running on Windows.
45 * We provide a table of all our implemented NDIS routines which is patched
46 * into the driver object code. All our exported routines must use the
47 * _stdcall calling convention, since that's what the Windows object code
52 #include <sys/ctype.h>
53 #include <sys/param.h>
54 #include <sys/types.h>
55 #include <sys/errno.h>
57 #include <sys/callout.h>
58 #include <sys/kernel.h>
59 #include <sys/systm.h>
60 #include <sys/malloc.h>
62 #include <sys/mutex.h>
63 #include <sys/socket.h>
64 #include <sys/sysctl.h>
65 #include <sys/timespec.h>
67 #include <sys/queue.h>
69 #include <sys/filedesc.h>
70 #include <sys/namei.h>
71 #include <sys/fcntl.h>
72 #include <sys/vnode.h>
73 #include <sys/kthread.h>
74 #include <sys/linker.h>
75 #include <sys/mount.h>
76 #include <sys/sysproto.h>
79 #include <net/if_arp.h>
80 #include <net/ethernet.h>
81 #include <net/if_dl.h>
82 #include <net/if_media.h>
84 #include <machine/atomic.h>
85 #include <machine/bus.h>
86 #include <machine/resource.h>
91 #include <machine/stdarg.h>
93 #include <net80211/ieee80211_var.h>
94 #include <net80211/ieee80211_ioctl.h>
96 #include <dev/pci/pcireg.h>
97 #include <dev/pci/pcivar.h>
99 #include <compat/ndis/pe_var.h>
100 #include <compat/ndis/cfg_var.h>
101 #include <compat/ndis/resource_var.h>
102 #include <compat/ndis/ntoskrnl_var.h>
103 #include <compat/ndis/hal_var.h>
104 #include <compat/ndis/ndis_var.h>
105 #include <dev/if_ndis/if_ndisvar.h>
108 #include <vm/vm_param.h>
111 #include <vm/vm_kern.h>
112 #include <vm/vm_map.h>
114 static char ndis_filepath[MAXPATHLEN];
116 SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath,
117 MAXPATHLEN, "Path used by NdisOpenFile() to search for files");
119 static void NdisInitializeWrapper(ndis_handle *,
120 driver_object *, void *, void *);
121 static ndis_status NdisMRegisterMiniport(ndis_handle,
122 ndis_miniport_characteristics *, int);
123 static ndis_status NdisAllocateMemoryWithTag(void **,
125 static ndis_status NdisAllocateMemory(void **,
126 uint32_t, uint32_t, ndis_physaddr);
127 static void NdisFreeMemory(void *, uint32_t, uint32_t);
128 static ndis_status NdisMSetAttributesEx(ndis_handle, ndis_handle,
129 uint32_t, uint32_t, ndis_interface_type);
130 static void NdisOpenConfiguration(ndis_status *,
131 ndis_handle *, ndis_handle);
132 static void NdisOpenConfigurationKeyByIndex(ndis_status *,
133 ndis_handle, uint32_t, unicode_string *, ndis_handle *);
134 static void NdisOpenConfigurationKeyByName(ndis_status *,
135 ndis_handle, unicode_string *, ndis_handle *);
136 static ndis_status ndis_encode_parm(ndis_miniport_block *,
137 struct sysctl_oid *, ndis_parm_type, ndis_config_parm **);
138 static ndis_status ndis_decode_parm(ndis_miniport_block *,
139 ndis_config_parm *, char *);
140 static void NdisReadConfiguration(ndis_status *, ndis_config_parm **,
141 ndis_handle, unicode_string *, ndis_parm_type);
142 static void NdisWriteConfiguration(ndis_status *, ndis_handle,
143 unicode_string *, ndis_config_parm *);
144 static void NdisCloseConfiguration(ndis_handle);
145 static void NdisAllocateSpinLock(ndis_spin_lock *);
146 static void NdisFreeSpinLock(ndis_spin_lock *);
147 static void NdisAcquireSpinLock(ndis_spin_lock *);
148 static void NdisReleaseSpinLock(ndis_spin_lock *);
149 static void NdisDprAcquireSpinLock(ndis_spin_lock *);
150 static void NdisDprReleaseSpinLock(ndis_spin_lock *);
151 static void NdisInitializeReadWriteLock(ndis_rw_lock *);
152 static void NdisAcquireReadWriteLock(ndis_rw_lock *,
153 uint8_t, ndis_lock_state *);
154 static void NdisReleaseReadWriteLock(ndis_rw_lock *, ndis_lock_state *);
155 static uint32_t NdisReadPciSlotInformation(ndis_handle, uint32_t,
156 uint32_t, void *, uint32_t);
157 static uint32_t NdisWritePciSlotInformation(ndis_handle, uint32_t,
158 uint32_t, void *, uint32_t);
159 static void NdisWriteErrorLogEntry(ndis_handle, ndis_error_code, uint32_t, ...);
160 static void ndis_map_cb(void *, bus_dma_segment_t *, int, int);
161 static void NdisMStartBufferPhysicalMapping(ndis_handle,
162 ndis_buffer *, uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *);
163 static void NdisMCompleteBufferPhysicalMapping(ndis_handle,
164 ndis_buffer *, uint32_t);
165 static void NdisMInitializeTimer(ndis_miniport_timer *, ndis_handle,
166 ndis_timer_function, void *);
167 static void NdisInitializeTimer(ndis_timer *,
168 ndis_timer_function, void *);
169 static void NdisSetTimer(ndis_timer *, uint32_t);
170 static void NdisMSetPeriodicTimer(ndis_miniport_timer *, uint32_t);
171 static void NdisMCancelTimer(ndis_timer *, uint8_t *);
172 static void ndis_timercall(kdpc *, ndis_miniport_timer *,
174 static void NdisMQueryAdapterResources(ndis_status *, ndis_handle,
175 ndis_resource_list *, uint32_t *);
176 static ndis_status NdisMRegisterIoPortRange(void **,
177 ndis_handle, uint32_t, uint32_t);
178 static void NdisMDeregisterIoPortRange(ndis_handle,
179 uint32_t, uint32_t, void *);
180 static void NdisReadNetworkAddress(ndis_status *, void **,
181 uint32_t *, ndis_handle);
182 static ndis_status NdisQueryMapRegisterCount(uint32_t, uint32_t *);
183 static ndis_status NdisMAllocateMapRegisters(ndis_handle,
184 uint32_t, uint8_t, uint32_t, uint32_t);
185 static void NdisMFreeMapRegisters(ndis_handle);
186 static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int);
187 static void NdisMAllocateSharedMemory(ndis_handle, uint32_t,
188 uint8_t, void **, ndis_physaddr *);
189 static void ndis_asyncmem_complete(device_object *, void *);
190 static ndis_status NdisMAllocateSharedMemoryAsync(ndis_handle,
191 uint32_t, uint8_t, void *);
192 static void NdisMFreeSharedMemory(ndis_handle, uint32_t,
193 uint8_t, void *, ndis_physaddr);
194 static ndis_status NdisMMapIoSpace(void **, ndis_handle,
195 ndis_physaddr, uint32_t);
196 static void NdisMUnmapIoSpace(ndis_handle, void *, uint32_t);
197 static uint32_t NdisGetCacheFillSize(void);
198 static uint32_t NdisMGetDmaAlignment(ndis_handle);
199 static ndis_status NdisMInitializeScatterGatherDma(ndis_handle,
201 static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **);
202 static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **);
203 static void NdisAllocateBufferPool(ndis_status *,
204 ndis_handle *, uint32_t);
205 static void NdisFreeBufferPool(ndis_handle);
206 static void NdisAllocateBuffer(ndis_status *, ndis_buffer **,
207 ndis_handle, void *, uint32_t);
208 static void NdisFreeBuffer(ndis_buffer *);
209 static uint32_t NdisBufferLength(ndis_buffer *);
210 static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *);
211 static void NdisQueryBufferSafe(ndis_buffer *, void **,
212 uint32_t *, uint32_t);
213 static void *NdisBufferVirtualAddress(ndis_buffer *);
214 static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t);
215 static void NdisAdjustBufferLength(ndis_buffer *, int);
216 static uint32_t NdisInterlockedIncrement(uint32_t *);
217 static uint32_t NdisInterlockedDecrement(uint32_t *);
218 static void NdisInitializeEvent(ndis_event *);
219 static void NdisSetEvent(ndis_event *);
220 static void NdisResetEvent(ndis_event *);
221 static uint8_t NdisWaitEvent(ndis_event *, uint32_t);
222 static ndis_status NdisUnicodeStringToAnsiString(ansi_string *,
225 NdisAnsiStringToUnicodeString(unicode_string *, ansi_string *);
226 static ndis_status NdisMPciAssignResources(ndis_handle,
227 uint32_t, ndis_resource_list **);
228 static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *,
229 ndis_handle, uint32_t, uint32_t, uint8_t,
230 uint8_t, ndis_interrupt_mode);
231 static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *);
232 static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *,
233 ndis_shutdown_handler);
234 static void NdisMDeregisterAdapterShutdownHandler(ndis_handle);
235 static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *);
236 static void NdisGetBufferPhysicalArraySize(ndis_buffer *,
238 static void NdisQueryBufferOffset(ndis_buffer *,
239 uint32_t *, uint32_t *);
240 static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle,
241 uint32_t, void *, uint32_t);
242 static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle,
243 uint32_t, void *, uint32_t);
244 static list_entry *NdisInterlockedInsertHeadList(list_entry *,
245 list_entry *, ndis_spin_lock *);
246 static list_entry *NdisInterlockedRemoveHeadList(list_entry *,
248 static list_entry *NdisInterlockedInsertTailList(list_entry *,
249 list_entry *, ndis_spin_lock *);
251 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *,
253 static void NdisGetCurrentSystemTime(uint64_t *);
254 static void NdisGetSystemUpTime(uint32_t *);
255 static void NdisInitializeString(unicode_string *, char *);
256 static void NdisInitAnsiString(ansi_string *, char *);
257 static void NdisInitUnicodeString(unicode_string *, uint16_t *);
258 static void NdisFreeString(unicode_string *);
259 static ndis_status NdisMRemoveMiniport(ndis_handle *);
260 static void NdisTerminateWrapper(ndis_handle, void *);
261 static void NdisMGetDeviceProperty(ndis_handle, device_object **,
262 device_object **, device_object **, cm_resource_list *,
264 static void NdisGetFirstBufferFromPacket(ndis_packet *,
265 ndis_buffer **, void **, uint32_t *, uint32_t *);
266 static void NdisGetFirstBufferFromPacketSafe(ndis_packet *,
267 ndis_buffer **, void **, uint32_t *, uint32_t *, uint32_t);
268 static int ndis_find_sym(linker_file_t, char *, char *, caddr_t *);
269 static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *,
270 unicode_string *, ndis_physaddr);
271 static void NdisMapFile(ndis_status *, void **, ndis_handle);
272 static void NdisUnmapFile(ndis_handle);
273 static void NdisCloseFile(ndis_handle);
274 static uint8_t NdisSystemProcessorCount(void);
275 static void NdisMIndicateStatusComplete(ndis_handle);
276 static void NdisMIndicateStatus(ndis_handle, ndis_status,
278 static uint8_t ndis_intr(kinterrupt *, void *);
279 static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *);
280 static funcptr ndis_findwrap(funcptr);
281 static void NdisCopyFromPacketToPacket(ndis_packet *,
282 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *);
283 static void NdisCopyFromPacketToPacketSafe(ndis_packet *,
284 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t);
285 static ndis_status NdisMRegisterDevice(ndis_handle,
286 unicode_string *, unicode_string *, driver_dispatch **,
287 void **, ndis_handle *);
288 static ndis_status NdisMDeregisterDevice(ndis_handle);
290 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
291 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
292 static void dummy(void);
295 * Some really old drivers do not properly check the return value
296 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
297 * sometimes allocate few more buffers/packets that they originally
298 * requested when they created the pool. To prevent this from being
299 * a problem, we allocate a few extra buffers/packets beyond what
300 * the driver asks for. This #define controls how many.
302 #define NDIS_POOL_EXTRA 16
307 image_patch_table *patch;
309 strcpy(ndis_filepath, "/compat/ndis");
311 patch = ndis_functbl;
312 while (patch->ipt_func != NULL) {
313 windrv_wrap((funcptr)patch->ipt_func,
314 (funcptr *)&patch->ipt_wrap,
315 patch->ipt_argcnt, patch->ipt_ftype);
325 image_patch_table *patch;
327 patch = ndis_functbl;
328 while (patch->ipt_func != NULL) {
329 windrv_unwrap(patch->ipt_wrap);
340 image_patch_table *patch;
342 patch = ndis_functbl;
343 while (patch->ipt_func != NULL) {
344 if ((funcptr)patch->ipt_func == func)
345 return((funcptr)patch->ipt_wrap);
353 * This routine does the messy Windows Driver Model device attachment
354 * stuff on behalf of NDIS drivers. We register our own AddDevice
358 NdisInitializeWrapper(wrapper, drv, path, unused)
359 ndis_handle *wrapper;
365 * As of yet, I haven't come up with a compelling
366 * reason to define a private NDIS wrapper structure,
367 * so we use a pointer to the driver object as the
368 * wrapper handle. The driver object has the miniport
369 * characteristics struct for this driver hung off it
370 * via IoAllocateDriverObjectExtension(), and that's
371 * really all the private data we need.
377 * If this was really Windows, we'd be registering dispatch
378 * routines for the NDIS miniport module here, but we're
379 * not Windows so all we really need to do is set up an
380 * AddDevice function that'll be invoked when a new device
384 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
390 NdisTerminateWrapper(handle, syspec)
394 /* Nothing to see here, move along. */
399 NdisMRegisterMiniport(handle, characteristics, len)
401 ndis_miniport_characteristics *characteristics;
404 ndis_miniport_characteristics *ch = NULL;
407 drv = (driver_object *)handle;
410 * We need to save the NDIS miniport characteristics
411 * somewhere. This data is per-driver, not per-device
412 * (all devices handled by the same driver have the
413 * same characteristics) so we hook it onto the driver
414 * object using IoAllocateDriverObjectExtension().
415 * The extra extension info is automagically deleted when
416 * the driver is unloaded (see windrv_unload()).
419 if (IoAllocateDriverObjectExtension(drv, (void *)1,
420 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
422 return(NDIS_STATUS_RESOURCES);
425 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
427 bcopy((char *)characteristics, (char *)ch, len);
429 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
430 ch->nmc_shutdown_handler = NULL;
431 ch->nmc_canceltxpkts_handler = NULL;
432 ch->nmc_pnpevent_handler = NULL;
435 return(NDIS_STATUS_SUCCESS);
439 NdisAllocateMemoryWithTag(vaddr, len, tag)
446 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
448 return(NDIS_STATUS_RESOURCES);
452 return(NDIS_STATUS_SUCCESS);
456 NdisAllocateMemory(vaddr, len, flags, highaddr)
460 ndis_physaddr highaddr;
464 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
466 return(NDIS_STATUS_RESOURCES);
469 return(NDIS_STATUS_SUCCESS);
473 NdisFreeMemory(vaddr, len, flags)
487 NdisMSetAttributesEx(adapter_handle, adapter_ctx, hangsecs,
489 ndis_handle adapter_handle;
490 ndis_handle adapter_ctx;
493 ndis_interface_type iftype;
495 ndis_miniport_block *block;
498 * Save the adapter context, we need it for calling
499 * the driver's internal functions.
501 block = (ndis_miniport_block *)adapter_handle;
502 block->nmb_miniportadapterctx = adapter_ctx;
503 block->nmb_checkforhangsecs = hangsecs;
504 block->nmb_flags = flags;
506 return(NDIS_STATUS_SUCCESS);
510 NdisOpenConfiguration(status, cfg, wrapctx)
516 *status = NDIS_STATUS_SUCCESS;
522 NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle)
525 unicode_string *subkey;
526 ndis_handle *subhandle;
529 *status = NDIS_STATUS_SUCCESS;
535 NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle)
539 unicode_string *subkey;
540 ndis_handle *subhandle;
542 *status = NDIS_STATUS_FAILURE;
548 ndis_encode_parm(block, oid, type, parm)
549 ndis_miniport_block *block;
550 struct sysctl_oid *oid;
552 ndis_config_parm **parm;
555 ndis_parmlist_entry *np;
562 np = ExAllocatePoolWithTag(NonPagedPool,
563 sizeof(ndis_parmlist_entry), 0);
565 return(NDIS_STATUS_RESOURCES);
566 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
567 *parm = p = &np->np_parm;
570 case ndis_parm_string:
571 /* See if this might be a number. */
572 val = strtoul((char *)oid->oid_arg1, NULL, 10);
573 us = &p->ncp_parmdata.ncp_stringdata;
574 p->ncp_type = ndis_parm_string;
576 snprintf(tmp, 32, "%x", val);
577 RtlInitAnsiString(&as, tmp);
579 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
582 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
584 return(NDIS_STATUS_RESOURCES);
588 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
592 p->ncp_type = ndis_parm_int;
593 p->ncp_parmdata.ncp_intdata =
594 strtol((char *)oid->oid_arg1, NULL, base);
596 case ndis_parm_hexint:
598 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
604 p->ncp_type = ndis_parm_hexint;
605 p->ncp_parmdata.ncp_intdata =
606 strtoul((char *)oid->oid_arg1, NULL, base);
609 return(NDIS_STATUS_FAILURE);
613 return(NDIS_STATUS_SUCCESS);
617 NdisReadConfiguration(status, parm, cfg, key, type)
619 ndis_config_parm **parm;
625 ndis_miniport_block *block;
626 struct ndis_softc *sc;
627 struct sysctl_oid *oidp;
628 struct sysctl_ctx_entry *e;
631 block = (ndis_miniport_block *)cfg;
632 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
634 if (key->us_len == 0 || key->us_buf == NULL) {
635 *status = NDIS_STATUS_FAILURE;
639 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
640 *status = NDIS_STATUS_RESOURCES;
647 * See if registry key is already in a list of known keys
648 * included with the driver.
650 #if __FreeBSD_version < 502113
651 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
653 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
656 if (strcasecmp(oidp->oid_name, keystr) == 0) {
657 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
658 RtlFreeAnsiString(&as);
659 *status = NDIS_STATUS_FAILURE;
663 *status = ndis_encode_parm(block, oidp, type, parm);
664 RtlFreeAnsiString(&as);
670 * If the key didn't match, add it to the list of dynamically
671 * created ones. Sometimes, drivers refer to registry keys
672 * that aren't documented in their .INF files. These keys
673 * are supposed to be created by some sort of utility or
674 * control panel snap-in that comes with the driver software.
675 * Sometimes it's useful to be able to manipulate these.
676 * If the driver requests the key in the form of a string,
677 * make its default value an empty string, otherwise default
681 if (type == ndis_parm_int || type == ndis_parm_hexint)
682 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
683 "UNSET", CTLFLAG_RW);
685 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
686 "UNSET", CTLFLAG_RW);
688 RtlFreeAnsiString(&as);
689 *status = NDIS_STATUS_FAILURE;
695 ndis_decode_parm(block, parm, val)
696 ndis_miniport_block *block;
697 ndis_config_parm *parm;
700 unicode_string *ustr;
703 switch(parm->ncp_type) {
704 case ndis_parm_string:
705 ustr = &parm->ncp_parmdata.ncp_stringdata;
706 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
707 return(NDIS_STATUS_RESOURCES);
708 bcopy(as.as_buf, val, as.as_len);
709 RtlFreeAnsiString(&as);
712 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
714 case ndis_parm_hexint:
715 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
718 return(NDIS_STATUS_FAILURE);
721 return(NDIS_STATUS_SUCCESS);
725 NdisWriteConfiguration(status, cfg, key, parm)
729 ndis_config_parm *parm;
733 ndis_miniport_block *block;
734 struct ndis_softc *sc;
735 struct sysctl_oid *oidp;
736 struct sysctl_ctx_entry *e;
739 block = (ndis_miniport_block *)cfg;
740 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
742 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
743 *status = NDIS_STATUS_RESOURCES;
749 /* Decode the parameter into a string. */
750 bzero(val, sizeof(val));
751 *status = ndis_decode_parm(block, parm, val);
752 if (*status != NDIS_STATUS_SUCCESS) {
753 RtlFreeAnsiString(&as);
757 /* See if the key already exists. */
759 #if __FreeBSD_version < 502113
760 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
762 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
765 if (strcasecmp(oidp->oid_name, keystr) == 0) {
766 /* Found it, set the value. */
767 strcpy((char *)oidp->oid_arg1, val);
768 RtlFreeAnsiString(&as);
773 /* Not found, add a new key with the specified value. */
774 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
777 RtlFreeAnsiString(&as);
778 *status = NDIS_STATUS_SUCCESS;
783 NdisCloseConfiguration(cfg)
787 ndis_parmlist_entry *pe;
788 ndis_miniport_block *block;
791 block = (ndis_miniport_block *)cfg;
793 while (!IsListEmpty(&block->nmb_parmlist)) {
794 e = RemoveHeadList(&block->nmb_parmlist);
795 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
797 if (p->ncp_type == ndis_parm_string)
798 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
806 * Initialize a Windows spinlock.
809 NdisAllocateSpinLock(lock)
810 ndis_spin_lock *lock;
812 KeInitializeSpinLock(&lock->nsl_spinlock);
819 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
820 * for this. One is that it's sort of superfluous: we don't have to do anything
821 * special to deallocate the spinlock. The other is that there are some buggy
822 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
823 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
827 NdisFreeSpinLock(lock)
828 ndis_spin_lock *lock;
831 KeInitializeSpinLock(&lock->nsl_spinlock);
838 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
842 NdisAcquireSpinLock(lock)
843 ndis_spin_lock *lock;
845 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
850 * Release a spinlock from IRQL == DISPATCH_LEVEL.
854 NdisReleaseSpinLock(lock)
855 ndis_spin_lock *lock;
857 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
862 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
865 NdisDprAcquireSpinLock(lock)
866 ndis_spin_lock *lock;
868 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
873 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
876 NdisDprReleaseSpinLock(lock)
877 ndis_spin_lock *lock;
879 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
884 NdisInitializeReadWriteLock(lock)
887 KeInitializeSpinLock(&lock->nrl_spinlock);
888 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
893 NdisAcquireReadWriteLock(lock, writeacc, state)
896 ndis_lock_state *state;
898 if (writeacc == TRUE) {
899 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
908 NdisReleaseReadWriteLock(lock, state)
910 ndis_lock_state *state;
912 if (lock->nrl_rsvd[0]) {
914 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
922 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
929 ndis_miniport_block *block;
934 block = (ndis_miniport_block *)adapter;
939 dev = block->nmb_physdeviceobj->do_devext;
942 * I have a test system consisting of a Sun w2100z
943 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
944 * "Aries" miniPCI NIC. (The NIC is installed in the
945 * machine using a miniPCI to PCI bus adapter card.)
946 * When running in SMP mode, I found that
947 * performing a large number of consecutive calls to
948 * NdisReadPciSlotInformation() would result in a
949 * sudden system reset (or in some cases a freeze).
950 * My suspicion is that the multiple reads are somehow
951 * triggering a fatal PCI bus error that leads to a
952 * machine check. The 1us delay in the loop below
953 * seems to prevent this problem.
956 for (i = 0; i < len; i++) {
958 dest[i] = pci_read_config(dev, i + offset, 1);
965 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
972 ndis_miniport_block *block;
977 block = (ndis_miniport_block *)adapter;
983 dev = block->nmb_physdeviceobj->do_devext;
984 for (i = 0; i < len; i++) {
986 pci_write_config(dev, i + offset, dest[i], 1);
993 * The errorlog routine uses a variable argument list, so we
994 * have to declare it this way.
997 #define ERRMSGLEN 512
999 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
1000 uint32_t numerrors, ...)
1002 ndis_miniport_block *block;
1009 struct ndis_softc *sc;
1012 ansi_string as = { 0, 0, NULL };
1014 block = (ndis_miniport_block *)adapter;
1015 dev = block->nmb_physdeviceobj->do_devext;
1016 drv = block->nmb_deviceobj->do_drvobj;
1017 sc = device_get_softc(dev);
1020 if (ifp->if_flags & IFF_DEBUG) {
1021 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
1022 code, &str, &i, &flags);
1024 if (flags & MESSAGE_RESOURCE_UNICODE) {
1025 RtlInitUnicodeString(&us, (uint16_t *)str);
1026 if (RtlUnicodeStringToAnsiString(&as,
1027 &us, TRUE) == STATUS_SUCCESS)
1035 device_printf (dev, "NDIS ERROR: %x (%s)\n", code,
1036 str == NULL ? "unknown error" : str);
1038 if (ifp->if_flags & IFF_DEBUG) {
1039 device_printf (dev, "NDIS NUMERRORS: %x\n", numerrors);
1040 va_start(ap, numerrors);
1041 for (i = 0; i < numerrors; i++)
1042 device_printf (dev, "argptr: %p\n",
1043 va_arg(ap, void *));
1048 RtlFreeAnsiString(&as);
1054 ndis_map_cb(arg, segs, nseg, error)
1056 bus_dma_segment_t *segs;
1060 struct ndis_map_arg *ctx;
1068 for (i = 0; i < nseg; i++) {
1069 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1070 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1073 ctx->nma_cnt = nseg;
1079 NdisMStartBufferPhysicalMapping(adapter, buf, mapreg, writedev, addrarray, arraysize)
1080 ndis_handle adapter;
1084 ndis_paddr_unit *addrarray;
1085 uint32_t *arraysize;
1087 ndis_miniport_block *block;
1088 struct ndis_softc *sc;
1089 struct ndis_map_arg nma;
1093 if (adapter == NULL)
1096 block = (ndis_miniport_block *)adapter;
1097 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1099 if (mapreg > sc->ndis_mmapcnt)
1102 map = sc->ndis_mmaps[mapreg];
1103 nma.nma_fraglist = addrarray;
1105 error = bus_dmamap_load(sc->ndis_mtag, map,
1106 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1107 (void *)&nma, BUS_DMA_NOWAIT);
1112 bus_dmamap_sync(sc->ndis_mtag, map,
1113 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1115 *arraysize = nma.nma_cnt;
1121 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1122 ndis_handle adapter;
1126 ndis_miniport_block *block;
1127 struct ndis_softc *sc;
1130 if (adapter == NULL)
1133 block = (ndis_miniport_block *)adapter;
1134 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1136 if (mapreg > sc->ndis_mmapcnt)
1139 map = sc->ndis_mmaps[mapreg];
1141 bus_dmamap_sync(sc->ndis_mtag, map,
1142 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1144 bus_dmamap_unload(sc->ndis_mtag, map);
1150 * This is an older (?) timer init routine which doesn't
1151 * accept a miniport context handle. Serialized miniports should
1152 * never call this function.
1156 NdisInitializeTimer(timer, func, ctx)
1158 ndis_timer_function func;
1161 KeInitializeTimer(&timer->nt_ktimer);
1162 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1163 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1169 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1171 ndis_miniport_timer *timer;
1176 * Since we're called as a DPC, we should be running
1177 * at DISPATCH_LEVEL here. This means to acquire the
1178 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1179 * rather than KeAcquireSpinLock().
1181 if (NDIS_SERIALIZED(timer->nmt_block))
1182 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1184 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1187 if (NDIS_SERIALIZED(timer->nmt_block))
1188 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1194 * For a long time I wondered why there were two NDIS timer initialization
1195 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1196 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1197 * function and context pointers separate from those in the DPC, which
1198 * allows for another level of indirection: when the timer fires, we
1199 * can have our own timer function invoked, and from there we can call
1200 * the driver's function. But why go to all that trouble? Then it hit
1201 * me: for serialized miniports, the timer callouts are not re-entrant.
1202 * By trapping the callouts and having access to the MiniportAdapterHandle,
1203 * we can protect the driver callouts by acquiring the NDIS serialization
1204 * lock. This is essential for allowing serialized miniports to work
1205 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1206 * is enough to prevent other threads from pre-empting you, but with
1207 * SMP, you must acquire a lock as well, otherwise the other CPU is
1208 * free to clobber you.
1211 NdisMInitializeTimer(timer, handle, func, ctx)
1212 ndis_miniport_timer *timer;
1214 ndis_timer_function func;
1217 /* Save the driver's funcptr and context */
1219 timer->nmt_timerfunc = func;
1220 timer->nmt_timerctx = ctx;
1221 timer->nmt_block = handle;
1224 * Set up the timer so it will call our intermediate DPC.
1225 * Be sure to use the wrapped entry point, since
1226 * ntoskrnl_run_dpc() expects to invoke a function with
1227 * Microsoft calling conventions.
1229 KeInitializeTimer(&timer->nmt_ktimer);
1230 KeInitializeDpc(&timer->nmt_kdpc,
1231 ndis_findwrap((funcptr)ndis_timercall), timer);
1232 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1238 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1239 * but the former is just a macro wrapper around the latter.
1242 NdisSetTimer(timer, msecs)
1247 * KeSetTimer() wants the period in
1248 * hundred nanosecond intervals.
1250 KeSetTimer(&timer->nt_ktimer,
1251 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1257 NdisMSetPeriodicTimer(timer, msecs)
1258 ndis_miniport_timer *timer;
1261 KeSetTimerEx(&timer->nmt_ktimer,
1262 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1268 * Technically, this is really NdisCancelTimer(), but we also
1269 * (ab)use it for NdisMCancelTimer(), since in our implementation
1270 * we don't need the extra info in the ndis_miniport_timer
1271 * structure just to cancel a timer.
1275 NdisMCancelTimer(timer, cancelled)
1279 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1284 NdisMQueryAdapterResources(status, adapter, list, buflen)
1285 ndis_status *status;
1286 ndis_handle adapter;
1287 ndis_resource_list *list;
1290 ndis_miniport_block *block;
1291 struct ndis_softc *sc;
1294 block = (ndis_miniport_block *)adapter;
1295 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1297 rsclen = sizeof(ndis_resource_list) +
1298 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1299 if (*buflen < rsclen) {
1301 *status = NDIS_STATUS_INVALID_LENGTH;
1305 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1306 *status = NDIS_STATUS_SUCCESS;
1312 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1314 ndis_handle adapter;
1318 struct ndis_miniport_block *block;
1319 struct ndis_softc *sc;
1321 if (adapter == NULL)
1322 return(NDIS_STATUS_FAILURE);
1324 block = (ndis_miniport_block *)adapter;
1325 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1327 if (sc->ndis_res_io == NULL)
1328 return(NDIS_STATUS_FAILURE);
1330 /* Don't let the device map more ports than we have. */
1331 if (rman_get_size(sc->ndis_res_io) < numports)
1332 return(NDIS_STATUS_INVALID_LENGTH);
1334 *offset = (void *)rman_get_start(sc->ndis_res_io);
1336 return(NDIS_STATUS_SUCCESS);
1340 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1341 ndis_handle adapter;
1350 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1351 ndis_status *status;
1354 ndis_handle adapter;
1356 struct ndis_softc *sc;
1357 ndis_miniport_block *block;
1358 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1360 block = (ndis_miniport_block *)adapter;
1361 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1364 if (bcmp(IFP2ENADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1365 #elif __FreeBSD_version >= 700000
1366 if (sc->ifp->if_addr == NULL ||
1367 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1369 if (bcmp(sc->arpcom.ac_enaddr, empty, ETHER_ADDR_LEN) == 0)
1371 *status = NDIS_STATUS_FAILURE;
1374 *addr = IFP2ENADDR(sc->ifp);
1375 #elif __FreeBSD_version >= 700000
1376 *addr = IF_LLADDR(sc->ifp);
1378 *addr = sc->arpcom.ac_enaddr;
1380 *addrlen = ETHER_ADDR_LEN;
1381 *status = NDIS_STATUS_SUCCESS;
1388 NdisQueryMapRegisterCount(bustype, cnt)
1393 return(NDIS_STATUS_SUCCESS);
1397 NdisMAllocateMapRegisters(adapter, dmachannel, dmasize, physmapneeded, maxmap)
1398 ndis_handle adapter;
1399 uint32_t dmachannel;
1401 uint32_t physmapneeded;
1404 struct ndis_softc *sc;
1405 ndis_miniport_block *block;
1406 int error, i, nseg = NDIS_MAXSEG;
1408 block = (ndis_miniport_block *)adapter;
1409 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1411 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1412 M_DEVBUF, M_NOWAIT|M_ZERO);
1414 if (sc->ndis_mmaps == NULL)
1415 return(NDIS_STATUS_RESOURCES);
1417 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1418 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1419 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1420 NULL, NULL, &sc->ndis_mtag);
1423 free(sc->ndis_mmaps, M_DEVBUF);
1424 return(NDIS_STATUS_RESOURCES);
1427 for (i = 0; i < physmapneeded; i++)
1428 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1430 sc->ndis_mmapcnt = physmapneeded;
1432 return(NDIS_STATUS_SUCCESS);
1436 NdisMFreeMapRegisters(adapter)
1437 ndis_handle adapter;
1439 struct ndis_softc *sc;
1440 ndis_miniport_block *block;
1443 block = (ndis_miniport_block *)adapter;
1444 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1446 for (i = 0; i < sc->ndis_mmapcnt; i++)
1447 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1449 free(sc->ndis_mmaps, M_DEVBUF);
1451 bus_dma_tag_destroy(sc->ndis_mtag);
1457 ndis_mapshared_cb(arg, segs, nseg, error)
1459 bus_dma_segment_t *segs;
1465 if (error || nseg > 1)
1470 p->np_quad = segs[0].ds_addr;
1476 * This maps to bus_dmamem_alloc().
1480 NdisMAllocateSharedMemory(adapter, len, cached, vaddr, paddr)
1481 ndis_handle adapter;
1485 ndis_physaddr *paddr;
1487 ndis_miniport_block *block;
1488 struct ndis_softc *sc;
1489 struct ndis_shmem *sh;
1492 if (adapter == NULL)
1495 block = (ndis_miniport_block *)adapter;
1496 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1498 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1502 InitializeListHead(&sh->ndis_list);
1505 * When performing shared memory allocations, create a tag
1506 * with a lowaddr limit that restricts physical memory mappings
1507 * so that they all fall within the first 1GB of memory.
1508 * At least one device/driver combination (Linksys Instant
1509 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1510 * problems with performing DMA operations with physical
1511 * addresses that lie above the 1GB mark. I don't know if this
1512 * is a hardware limitation or if the addresses are being
1513 * truncated within the driver, but this seems to be the only
1514 * way to make these cards work reliably in systems with more
1515 * than 1GB of physical memory.
1518 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1519 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1520 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1528 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1529 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1532 bus_dma_tag_destroy(sh->ndis_stag);
1537 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1538 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1541 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1542 bus_dma_tag_destroy(sh->ndis_stag);
1548 * Save the physical address along with the source address.
1549 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1550 * with a bogus virtual address sometimes, but with a valid
1551 * physical address. To keep this from causing trouble, we
1552 * use the physical address to as a sanity check in case
1553 * searching based on the virtual address fails.
1557 sh->ndis_paddr.np_quad = paddr->np_quad;
1558 sh->ndis_saddr = *vaddr;
1559 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1565 struct ndis_allocwork {
1573 ndis_asyncmem_complete(dobj, arg)
1574 device_object *dobj;
1577 ndis_miniport_block *block;
1578 struct ndis_softc *sc;
1579 struct ndis_allocwork *w;
1581 ndis_physaddr paddr;
1582 ndis_allocdone_handler donefunc;
1585 block = (ndis_miniport_block *)dobj->do_devext;
1586 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1591 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1592 NdisMAllocateSharedMemory(block, w->na_len,
1593 w->na_cached, &vaddr, &paddr);
1594 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1596 IoFreeWorkItem(w->na_iw);
1603 NdisMAllocateSharedMemoryAsync(adapter, len, cached, ctx)
1604 ndis_handle adapter;
1609 ndis_miniport_block *block;
1610 struct ndis_allocwork *w;
1612 io_workitem_func ifw;
1614 if (adapter == NULL)
1615 return(NDIS_STATUS_FAILURE);
1619 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1621 return(NDIS_STATUS_FAILURE);
1623 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1626 return(NDIS_STATUS_FAILURE);
1628 w->na_cached = cached;
1633 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1634 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1636 return(NDIS_STATUS_PENDING);
1640 NdisMFreeSharedMemory(adapter, len, cached, vaddr, paddr)
1641 ndis_handle adapter;
1645 ndis_physaddr paddr;
1647 ndis_miniport_block *block;
1648 struct ndis_softc *sc;
1649 struct ndis_shmem *sh = NULL;
1652 if (vaddr == NULL || adapter == NULL)
1655 block = (ndis_miniport_block *)adapter;
1656 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1658 /* Sanity check: is list empty? */
1660 if (IsListEmpty(&sc->ndis_shlist))
1664 l = sc->ndis_shlist.nle_flink;
1665 while (l != &sc->ndis_shlist) {
1666 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1667 if (sh->ndis_saddr == vaddr)
1670 * Check the physaddr too, just in case the driver lied
1671 * about the virtual address.
1673 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1680 printf("NDIS: buggy driver tried to free "
1681 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1682 vaddr, (uintmax_t)paddr.np_quad);
1686 RemoveEntryList(&sh->ndis_list);
1690 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1691 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1692 bus_dma_tag_destroy(sh->ndis_stag);
1700 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1702 ndis_handle adapter;
1703 ndis_physaddr paddr;
1706 if (adapter == NULL)
1707 return(NDIS_STATUS_FAILURE);
1709 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1712 return(NDIS_STATUS_FAILURE);
1714 return(NDIS_STATUS_SUCCESS);
1718 NdisMUnmapIoSpace(adapter, vaddr, len)
1719 ndis_handle adapter;
1723 MmUnmapIoSpace(vaddr, len);
1728 NdisGetCacheFillSize(void)
1734 NdisMGetDmaAlignment(handle)
1741 * NDIS has two methods for dealing with NICs that support DMA.
1742 * One is to just pass packets to the driver and let it call
1743 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1744 * all by itself, and the other is to let the NDIS library handle the
1745 * buffer mapping internally, and hand the driver an already populated
1746 * scatter/gather fragment list. If the driver calls
1747 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1752 NdisMInitializeScatterGatherDma(adapter, is64, maxphysmap)
1753 ndis_handle adapter;
1755 uint32_t maxphysmap;
1757 struct ndis_softc *sc;
1758 ndis_miniport_block *block;
1761 if (adapter == NULL)
1762 return(NDIS_STATUS_FAILURE);
1763 block = (ndis_miniport_block *)adapter;
1764 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1766 /* Don't do this twice. */
1767 if (sc->ndis_sc == 1)
1768 return(NDIS_STATUS_SUCCESS);
1770 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1771 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1772 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1773 NULL, NULL, &sc->ndis_ttag);
1777 return(NDIS_STATUS_SUCCESS);
1781 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1782 ndis_status *status;
1785 uint32_t protrsvdlen;
1787 ndis_packet_pool *p;
1788 ndis_packet *packets;
1791 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1793 *status = NDIS_STATUS_RESOURCES;
1797 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1798 p->np_protrsvd = protrsvdlen;
1799 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1801 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1805 if (packets == NULL) {
1807 *status = NDIS_STATUS_RESOURCES;
1811 p->np_pktmem = packets;
1813 for (i = 0; i < p->np_cnt; i++)
1814 InterlockedPushEntrySList(&p->np_head,
1815 (struct slist_entry *)&packets[i]);
1817 #ifdef NDIS_DEBUG_PACKETS
1819 KeInitializeSpinLock(&p->np_lock);
1820 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1824 *status = NDIS_STATUS_SUCCESS;
1829 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1830 ndis_status *status;
1833 uint32_t oflowdescnum;
1834 uint32_t protrsvdlen;
1836 return(NdisAllocatePacketPool(status, pool,
1837 descnum + oflowdescnum, protrsvdlen));
1841 NdisPacketPoolUsage(pool)
1844 ndis_packet_pool *p;
1846 p = (ndis_packet_pool *)pool;
1847 return(p->np_cnt - ExQueryDepthSList(&p->np_head));
1851 NdisFreePacketPool(pool)
1854 ndis_packet_pool *p;
1856 #ifdef NDIS_DEBUG_PACKETS
1860 p = (ndis_packet_pool *)pool;
1862 #ifdef NDIS_DEBUG_PACKETS
1863 KeAcquireSpinLock(&p->np_lock, &irql);
1866 usage = NdisPacketPoolUsage(pool);
1868 #ifdef NDIS_DEBUG_PACKETS
1871 KeResetEvent(&p->np_event);
1872 KeReleaseSpinLock(&p->np_lock, irql);
1873 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1875 KeReleaseSpinLock(&p->np_lock, irql);
1878 ExFreePool(p->np_pktmem);
1885 NdisAllocatePacket(status, packet, pool)
1886 ndis_status *status;
1887 ndis_packet **packet;
1890 ndis_packet_pool *p;
1892 #ifdef NDIS_DEBUG_PACKETS
1896 p = (ndis_packet_pool *)pool;
1898 #ifdef NDIS_DEBUG_PACKETS
1899 KeAcquireSpinLock(&p->np_lock, &irql);
1901 KeReleaseSpinLock(&p->np_lock, irql);
1902 printf("NDIS: tried to allocate packet from dead pool %p\n",
1904 *status = NDIS_STATUS_RESOURCES;
1909 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1911 #ifdef NDIS_DEBUG_PACKETS
1912 KeReleaseSpinLock(&p->np_lock, irql);
1916 *status = NDIS_STATUS_RESOURCES;
1921 bzero((char *)pkt, sizeof(ndis_packet));
1923 /* Save pointer to the pool. */
1924 pkt->np_private.npp_pool = pool;
1926 /* Set the oob offset pointer. Lots of things expect this. */
1927 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1930 * We must initialize the packet flags correctly in order
1931 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1932 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1935 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1936 pkt->np_private.npp_validcounts = FALSE;
1940 *status = NDIS_STATUS_SUCCESS;
1946 NdisFreePacket(packet)
1947 ndis_packet *packet;
1949 ndis_packet_pool *p;
1950 #ifdef NDIS_DEBUG_PACKETS
1954 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1956 #ifdef NDIS_DEBUG_PACKETS
1957 KeAcquireSpinLock(&p->np_lock, &irql);
1960 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1962 #ifdef NDIS_DEBUG_PACKETS
1964 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1965 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1967 KeReleaseSpinLock(&p->np_lock, irql);
1974 NdisUnchainBufferAtFront(packet, buf)
1975 ndis_packet *packet;
1978 ndis_packet_private *priv;
1980 if (packet == NULL || buf == NULL)
1983 priv = &packet->np_private;
1985 priv->npp_validcounts = FALSE;
1987 if (priv->npp_head == priv->npp_tail) {
1988 *buf = priv->npp_head;
1989 priv->npp_head = priv->npp_tail = NULL;
1991 *buf = priv->npp_head;
1992 priv->npp_head = (*buf)->mdl_next;
1999 NdisUnchainBufferAtBack(packet, buf)
2000 ndis_packet *packet;
2003 ndis_packet_private *priv;
2006 if (packet == NULL || buf == NULL)
2009 priv = &packet->np_private;
2011 priv->npp_validcounts = FALSE;
2013 if (priv->npp_head == priv->npp_tail) {
2014 *buf = priv->npp_head;
2015 priv->npp_head = priv->npp_tail = NULL;
2017 *buf = priv->npp_tail;
2018 tmp = priv->npp_head;
2019 while (tmp->mdl_next != priv->npp_tail)
2020 tmp = tmp->mdl_next;
2021 priv->npp_tail = tmp;
2022 tmp->mdl_next = NULL;
2029 * The NDIS "buffer" is really an MDL (memory descriptor list)
2030 * which is used to describe a buffer in a way that allows it
2031 * to mapped into different contexts. We have to be careful how
2032 * we handle them: in some versions of Windows, the NdisFreeBuffer()
2033 * routine is an actual function in the NDIS API, but in others
2034 * it's just a macro wrapper around IoFreeMdl(). There's really
2035 * no way to use the 'descnum' parameter to count how many
2036 * "buffers" are allocated since in order to use IoFreeMdl() to
2037 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
2038 * them, and IoAllocateMdl() just grabs them out of the heap.
2042 NdisAllocateBufferPool(status, pool, descnum)
2043 ndis_status *status;
2049 * The only thing we can really do here is verify that descnum
2050 * is a reasonable value, but I really don't know what to check
2054 *pool = NonPagedPool;
2055 *status = NDIS_STATUS_SUCCESS;
2060 NdisFreeBufferPool(pool)
2067 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
2068 ndis_status *status;
2069 ndis_buffer **buffer;
2076 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
2078 *status = NDIS_STATUS_RESOURCES;
2082 MmBuildMdlForNonPagedPool(buf);
2085 *status = NDIS_STATUS_SUCCESS;
2101 NdisBufferLength(buf)
2104 return(MmGetMdlByteCount(buf));
2108 * Get the virtual address and length of a buffer.
2109 * Note: the vaddr argument is optional.
2113 NdisQueryBuffer(buf, vaddr, len)
2119 *vaddr = MmGetMdlVirtualAddress(buf);
2120 *len = MmGetMdlByteCount(buf);
2125 /* Same as above -- we don't care about the priority. */
2128 NdisQueryBufferSafe(buf, vaddr, len, prio)
2135 *vaddr = MmGetMdlVirtualAddress(buf);
2136 *len = MmGetMdlByteCount(buf);
2141 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2144 NdisBufferVirtualAddress(buf)
2147 return(MmGetMdlVirtualAddress(buf));
2151 NdisBufferVirtualAddressSafe(buf, prio)
2155 return(MmGetMdlVirtualAddress(buf));
2159 NdisAdjustBufferLength(buf, len)
2163 MmGetMdlByteCount(buf) = len;
2169 NdisInterlockedIncrement(addend)
2172 atomic_add_long((u_long *)addend, 1);
2177 NdisInterlockedDecrement(addend)
2180 atomic_subtract_long((u_long *)addend, 1);
2185 NdisInitializeEvent(event)
2189 * NDIS events are always notification
2190 * events, and should be initialized to the
2191 * not signaled state.
2193 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2201 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2206 NdisResetEvent(event)
2209 KeResetEvent(&event->ne_event);
2214 NdisWaitEvent(event, msecs)
2221 duetime = ((int64_t)msecs * -10000);
2222 rval = KeWaitForSingleObject(event,
2223 0, 0, TRUE, msecs ? & duetime : NULL);
2225 if (rval == STATUS_TIMEOUT)
2232 NdisUnicodeStringToAnsiString(dstr, sstr)
2234 unicode_string *sstr;
2238 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2240 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2241 return(NDIS_STATUS_RESOURCES);
2243 return(NDIS_STATUS_FAILURE);
2245 return (NDIS_STATUS_SUCCESS);
2249 NdisAnsiStringToUnicodeString(dstr, sstr)
2250 unicode_string *dstr;
2255 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2257 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2258 return(NDIS_STATUS_RESOURCES);
2260 return(NDIS_STATUS_FAILURE);
2262 return (NDIS_STATUS_SUCCESS);
2266 NdisMPciAssignResources(adapter, slot, list)
2267 ndis_handle adapter;
2269 ndis_resource_list **list;
2271 ndis_miniport_block *block;
2273 if (adapter == NULL || list == NULL)
2274 return (NDIS_STATUS_FAILURE);
2276 block = (ndis_miniport_block *)adapter;
2277 *list = block->nmb_rlist;
2279 return (NDIS_STATUS_SUCCESS);
2283 ndis_intr(iobj, arg)
2287 struct ndis_softc *sc;
2288 uint8_t is_our_intr = FALSE;
2290 ndis_miniport_interrupt *intr;
2293 intr = sc->ndis_block->nmb_interrupt;
2295 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2298 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2299 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2300 sc->ndis_block->nmb_miniportadapterctx);
2302 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2303 sc->ndis_block->nmb_miniportadapterctx);
2308 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2310 return(is_our_intr);
2314 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2316 ndis_miniport_interrupt *intr;
2320 struct ndis_softc *sc;
2321 ndis_miniport_block *block;
2322 ndis_handle adapter;
2324 block = intr->ni_block;
2325 adapter = block->nmb_miniportadapterctx;
2326 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2328 if (NDIS_SERIALIZED(sc->ndis_block))
2329 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2331 MSCALL1(intr->ni_dpcfunc, adapter);
2333 /* If there's a MiniportEnableInterrupt() routine, call it. */
2335 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2336 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2338 if (NDIS_SERIALIZED(sc->ndis_block))
2339 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2342 * Set the completion event if we've drained all
2343 * pending interrupts.
2346 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2348 if (intr->ni_dpccnt == 0)
2349 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2350 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2356 NdisMRegisterInterrupt(intr, adapter, ivec, ilevel, reqisr, shared, imode)
2357 ndis_miniport_interrupt *intr;
2358 ndis_handle adapter;
2363 ndis_interrupt_mode imode;
2365 ndis_miniport_block *block;
2366 ndis_miniport_characteristics *ch;
2367 struct ndis_softc *sc;
2371 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2372 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2375 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2376 sizeof(struct mtx), 0);
2377 if (intr->ni_rsvd == NULL)
2378 return(NDIS_STATUS_RESOURCES);
2380 intr->ni_block = adapter;
2381 intr->ni_isrreq = reqisr;
2382 intr->ni_shared = shared;
2383 intr->ni_dpccnt = 0;
2384 intr->ni_isrfunc = ch->nmc_isr_func;
2385 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2387 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2388 KeInitializeDpc(&intr->ni_dpc,
2389 ndis_findwrap((funcptr)ndis_intrhand), intr);
2390 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2392 error = IoConnectInterrupt(&intr->ni_introbj,
2393 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2394 ivec, ilevel, 0, imode, shared, 0, FALSE);
2396 if (error != STATUS_SUCCESS)
2397 return(NDIS_STATUS_FAILURE);
2399 block->nmb_interrupt = intr;
2401 return(NDIS_STATUS_SUCCESS);
2405 NdisMDeregisterInterrupt(intr)
2406 ndis_miniport_interrupt *intr;
2408 ndis_miniport_block *block;
2409 struct ndis_softc *sc;
2412 block = intr->ni_block;
2413 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2415 /* Should really be KeSynchronizeExecution() */
2417 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2418 block->nmb_interrupt = NULL;
2419 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2421 KeFlushQueuedDpcs();
2423 /* Disconnect our ISR */
2425 IoDisconnectInterrupt(intr->ni_introbj);
2427 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2428 KeResetEvent(&intr->ni_dpcevt);
2434 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2435 ndis_handle adapter;
2437 ndis_shutdown_handler shutdownfunc;
2439 ndis_miniport_block *block;
2440 ndis_miniport_characteristics *chars;
2441 struct ndis_softc *sc;
2443 if (adapter == NULL)
2446 block = (ndis_miniport_block *)adapter;
2447 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2448 chars = sc->ndis_chars;
2450 chars->nmc_shutdown_handler = shutdownfunc;
2451 chars->nmc_rsvd0 = shutdownctx;
2457 NdisMDeregisterAdapterShutdownHandler(adapter)
2458 ndis_handle adapter;
2460 ndis_miniport_block *block;
2461 ndis_miniport_characteristics *chars;
2462 struct ndis_softc *sc;
2464 if (adapter == NULL)
2467 block = (ndis_miniport_block *)adapter;
2468 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2469 chars = sc->ndis_chars;
2471 chars->nmc_shutdown_handler = NULL;
2472 chars->nmc_rsvd0 = NULL;
2478 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2483 if (MmGetMdlByteCount(buf) == 0)
2485 return(SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2486 MmGetMdlByteCount(buf)));
2490 NdisGetBufferPhysicalArraySize(buf, pages)
2497 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2502 NdisQueryBufferOffset(buf, off, len)
2510 *off = MmGetMdlByteOffset(buf);
2511 *len = MmGetMdlByteCount(buf);
2523 * During system bootstrap, (i.e. cold == 1), we aren't
2524 * allowed to sleep, so we have to do a hard DELAY()
2531 KeInitializeTimer(&timer);
2532 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2533 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2540 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2546 struct ndis_softc *sc;
2547 ndis_miniport_block *block;
2548 bus_space_handle_t bh;
2556 block = (ndis_miniport_block *)handle;
2557 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2560 bh = rman_get_bushandle(sc->ndis_res_am);
2561 bt = rman_get_bustag(sc->ndis_res_am);
2563 for (i = 0; i < len; i++)
2564 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2570 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2576 struct ndis_softc *sc;
2577 ndis_miniport_block *block;
2578 bus_space_handle_t bh;
2586 block = (ndis_miniport_block *)handle;
2587 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2590 bh = rman_get_bushandle(sc->ndis_res_am);
2591 bt = rman_get_bustag(sc->ndis_res_am);
2593 for (i = 0; i < len; i++)
2594 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2600 NdisInterlockedInsertHeadList(head, entry, lock)
2603 ndis_spin_lock *lock;
2607 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2608 flink = head->nle_flink;
2609 entry->nle_flink = flink;
2610 entry->nle_blink = head;
2611 flink->nle_blink = entry;
2612 head->nle_flink = entry;
2613 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2619 NdisInterlockedRemoveHeadList(head, lock)
2621 ndis_spin_lock *lock;
2626 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2627 entry = head->nle_flink;
2628 flink = entry->nle_flink;
2629 head->nle_flink = flink;
2630 flink->nle_blink = head;
2631 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2637 NdisInterlockedInsertTailList(head, entry, lock)
2640 ndis_spin_lock *lock;
2644 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2645 blink = head->nle_blink;
2646 entry->nle_flink = head;
2647 entry->nle_blink = blink;
2648 blink->nle_flink = entry;
2649 head->nle_blink = entry;
2650 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2656 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2657 ndis_miniport_interrupt *intr;
2661 return(KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2665 * Return the number of 100 nanosecond intervals since
2666 * January 1, 1601. (?!?!)
2669 NdisGetCurrentSystemTime(tval)
2675 *tval = (uint64_t)ts.tv_nsec / 100 + (uint64_t)ts.tv_sec * 10000000 +
2682 * Return the number of milliseconds since the system booted.
2685 NdisGetSystemUpTime(tval)
2691 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2697 NdisInitializeString(dst, src)
2698 unicode_string *dst;
2702 RtlInitAnsiString(&as, src);
2703 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2709 unicode_string *str;
2711 RtlFreeUnicodeString(str);
2716 NdisMRemoveMiniport(adapter)
2717 ndis_handle *adapter;
2719 return(NDIS_STATUS_SUCCESS);
2723 NdisInitAnsiString(dst, src)
2727 RtlInitAnsiString(dst, src);
2732 NdisInitUnicodeString(dst, src)
2733 unicode_string *dst;
2736 RtlInitUnicodeString(dst, src);
2740 static void NdisMGetDeviceProperty(adapter, phydevobj,
2741 funcdevobj, nextdevobj, resources, transresources)
2742 ndis_handle adapter;
2743 device_object **phydevobj;
2744 device_object **funcdevobj;
2745 device_object **nextdevobj;
2746 cm_resource_list *resources;
2747 cm_resource_list *transresources;
2749 ndis_miniport_block *block;
2751 block = (ndis_miniport_block *)adapter;
2753 if (phydevobj != NULL)
2754 *phydevobj = block->nmb_physdeviceobj;
2755 if (funcdevobj != NULL)
2756 *funcdevobj = block->nmb_deviceobj;
2757 if (nextdevobj != NULL)
2758 *nextdevobj = block->nmb_nextdeviceobj;
2764 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2765 ndis_packet *packet;
2773 tmp = packet->np_private.npp_head;
2777 *firstlen = *totlen = 0;
2779 *firstva = MmGetMdlVirtualAddress(tmp);
2780 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2781 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2782 *totlen += MmGetMdlByteCount(tmp);
2789 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2790 ndis_packet *packet;
2797 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2801 ndis_find_sym(lf, filename, suffix, sym)
2811 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2812 if (fullsym == NULL)
2815 bzero(fullsym, MAXPATHLEN);
2816 strncpy(fullsym, filename, MAXPATHLEN);
2817 if (strlen(filename) < 4) {
2818 ExFreePool(fullsym);
2822 /* If the filename has a .ko suffix, strip if off. */
2823 suf = fullsym + (strlen(filename) - 3);
2824 if (strcmp(suf, ".ko") == 0)
2827 for (i = 0; i < strlen(fullsym); i++) {
2828 if (fullsym[i] == '.')
2831 fullsym[i] = tolower(fullsym[i]);
2833 strcat(fullsym, suffix);
2834 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2835 ExFreePool(fullsym);
2842 struct ndis_checkmodule {
2848 * See if a single module contains the symbols for a specified file.
2851 NdisCheckModule(linker_file_t lf, void *context)
2853 struct ndis_checkmodule *nc;
2854 caddr_t kldstart, kldend;
2856 nc = (struct ndis_checkmodule *)context;
2857 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2859 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2862 nc->fh->nf_map = NULL;
2863 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2864 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2868 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2870 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2871 ndis_status *status;
2872 ndis_handle *filehandle;
2873 uint32_t *filelength;
2874 unicode_string *filename;
2875 ndis_physaddr highestaddr;
2878 char *afilename = NULL;
2879 struct thread *td = curthread;
2880 struct nameidata nd;
2881 int flags, error, vfslocked;
2883 struct vattr *vap = &vat;
2886 struct ndis_checkmodule nc;
2888 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2889 *status = NDIS_STATUS_RESOURCES;
2893 afilename = strdup(as.as_buf, M_DEVBUF);
2894 RtlFreeAnsiString(&as);
2896 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2898 free(afilename, M_DEVBUF);
2899 *status = NDIS_STATUS_RESOURCES;
2903 fh->nf_name = afilename;
2906 * During system bootstrap, it's impossible to load files
2907 * from the rootfs since it's not mounted yet. We therefore
2908 * offer the possibility of opening files that have been
2909 * preloaded as modules instead. Both choices will work
2910 * when kldloading a module from multiuser, but only the
2911 * module option will work during bootstrap. The module
2912 * loading option works by using the ndiscvt(8) utility
2913 * to convert the arbitrary file into a .ko using objcopy(1).
2914 * This file will contain two special symbols: filename_start
2915 * and filename_end. All we have to do is traverse the KLD
2916 * list in search of those symbols and we've found the file
2917 * data. As an added bonus, ndiscvt(8) will also generate
2918 * a normal .o file which can be linked statically with
2919 * the kernel. This means that the symbols will actual reside
2920 * in the kernel's symbol table, but that doesn't matter to
2921 * us since the kernel appears to us as just another module.
2924 nc.afilename = afilename;
2926 if (linker_file_foreach(NdisCheckModule, &nc)) {
2927 *filelength = fh->nf_maplen;
2929 *status = NDIS_STATUS_SUCCESS;
2933 if (TAILQ_EMPTY(&mountlist)) {
2935 *status = NDIS_STATUS_FILE_NOT_FOUND;
2936 printf("NDIS: could not find file %s in linker list\n",
2938 printf("NDIS: and no filesystems mounted yet, "
2939 "aborting NdisOpenFile()\n");
2940 free(afilename, M_DEVBUF);
2944 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2947 free(afilename, M_DEVBUF);
2948 *status = NDIS_STATUS_RESOURCES;
2952 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2954 /* Some threads don't have a current working directory. */
2956 if (td->td_proc->p_fd->fd_rdir == NULL)
2957 td->td_proc->p_fd->fd_rdir = rootvnode;
2958 if (td->td_proc->p_fd->fd_cdir == NULL)
2959 td->td_proc->p_fd->fd_cdir = rootvnode;
2961 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td);
2964 error = vn_open(&nd, &flags, 0, -1);
2966 *status = NDIS_STATUS_FILE_NOT_FOUND;
2968 printf("NDIS: open file %s failed: %d\n", path, error);
2970 free(afilename, M_DEVBUF);
2973 vfslocked = NDHASGIANT(&nd);
2977 NDFREE(&nd, NDF_ONLY_PNBUF);
2979 /* Get the file size. */
2980 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred, td);
2981 VOP_UNLOCK(nd.ni_vp, 0, td);
2982 VFS_UNLOCK_GIANT(vfslocked);
2984 fh->nf_vp = nd.ni_vp;
2986 fh->nf_type = NDIS_FH_TYPE_VFS;
2988 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2989 *status = NDIS_STATUS_SUCCESS;
2995 NdisMapFile(status, mappedbuffer, filehandle)
2996 ndis_status *status;
2997 void **mappedbuffer;
2998 ndis_handle filehandle;
3001 struct thread *td = curthread;
3004 int error, resid, vfslocked;
3007 if (filehandle == NULL) {
3008 *status = NDIS_STATUS_FAILURE;
3012 fh = (ndis_fh *)filehandle;
3014 if (fh->nf_vp == NULL) {
3015 *status = NDIS_STATUS_FAILURE;
3019 if (fh->nf_map != NULL) {
3020 *status = NDIS_STATUS_ALREADY_MAPPED;
3024 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
3026 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
3027 *status = NDIS_STATUS_FAILURE;
3030 fh->nf_map = kldstart;
3031 *status = NDIS_STATUS_SUCCESS;
3032 *mappedbuffer = fh->nf_map;
3036 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
3038 if (fh->nf_map == NULL) {
3039 *status = NDIS_STATUS_RESOURCES;
3044 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3045 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
3046 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
3047 VFS_UNLOCK_GIANT(vfslocked);
3050 *status = NDIS_STATUS_FAILURE;
3052 *status = NDIS_STATUS_SUCCESS;
3053 *mappedbuffer = fh->nf_map;
3060 NdisUnmapFile(filehandle)
3061 ndis_handle filehandle;
3064 fh = (ndis_fh *)filehandle;
3066 if (fh->nf_map == NULL)
3069 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3070 ExFreePool(fh->nf_map);
3077 NdisCloseFile(filehandle)
3078 ndis_handle filehandle;
3080 struct thread *td = curthread;
3085 if (filehandle == NULL)
3088 fh = (ndis_fh *)filehandle;
3089 if (fh->nf_map != NULL) {
3090 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3091 ExFreePool(fh->nf_map);
3095 if (fh->nf_vp == NULL)
3098 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
3100 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3101 vn_close(vp, FREAD, td->td_ucred, td);
3102 VFS_UNLOCK_GIANT(vfslocked);
3106 free(fh->nf_name, M_DEVBUF);
3113 NdisSystemProcessorCount()
3118 typedef void (*ndis_statusdone_handler)(ndis_handle);
3119 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
3123 NdisMIndicateStatusComplete(adapter)
3124 ndis_handle adapter;
3126 ndis_miniport_block *block;
3127 ndis_statusdone_handler statusdonefunc;
3129 block = (ndis_miniport_block *)adapter;
3130 statusdonefunc = block->nmb_statusdone_func;
3132 MSCALL1(statusdonefunc, adapter);
3137 NdisMIndicateStatus(adapter, status, sbuf, slen)
3138 ndis_handle adapter;
3143 ndis_miniport_block *block;
3144 ndis_status_handler statusfunc;
3146 block = (ndis_miniport_block *)adapter;
3147 statusfunc = block->nmb_status_func;
3149 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3154 * The DDK documentation says that you should use IoQueueWorkItem()
3155 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3156 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3157 * depends on the API semantics of ExQueueWorkItem(). In our world,
3158 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3161 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3162 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3163 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3164 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3165 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3166 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3167 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3168 * to ExQueueWorkItem().
3170 * Got all that? (Sheesh.)
3174 NdisScheduleWorkItem(work)
3175 ndis_work_item *work;
3177 work_queue_item *wqi;
3179 wqi = (work_queue_item *)work->nwi_wraprsvd;
3180 ExInitializeWorkItem(wqi,
3181 (work_item_func)work->nwi_func, work->nwi_ctx);
3182 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3184 return(NDIS_STATUS_SUCCESS);
3188 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3196 ndis_buffer *src, *dst;
3198 int resid, copied, len, scnt, dcnt;
3202 src = spkt->np_private.npp_head;
3203 dst = dpkt->np_private.npp_head;
3205 sptr = MmGetMdlVirtualAddress(src);
3206 dptr = MmGetMdlVirtualAddress(dst);
3207 scnt = MmGetMdlByteCount(src);
3208 dcnt = MmGetMdlByteCount(dst);
3211 if (MmGetMdlByteCount(src) > soff) {
3213 scnt = MmGetMdlByteCount(src)- soff;
3216 soff -= MmGetMdlByteCount(src);
3217 src = src->mdl_next;
3220 sptr = MmGetMdlVirtualAddress(src);
3224 if (MmGetMdlByteCount(dst) > doff) {
3226 dcnt = MmGetMdlByteCount(dst) - doff;
3229 doff -= MmGetMdlByteCount(dst);
3230 dst = dst->mdl_next;
3233 dptr = MmGetMdlVirtualAddress(dst);
3247 bcopy(sptr, dptr, len);
3256 dst = dst->mdl_next;
3259 dptr = MmGetMdlVirtualAddress(dst);
3260 dcnt = MmGetMdlByteCount(dst);
3265 src = src->mdl_next;
3268 sptr = MmGetMdlVirtualAddress(src);
3269 scnt = MmGetMdlByteCount(src);
3278 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3287 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3292 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3294 unicode_string *devname;
3295 unicode_string *symname;
3296 driver_dispatch *majorfuncs[];
3298 ndis_handle *devhandle;
3301 device_object *dobj;
3303 status = IoCreateDevice(handle, 0, devname,
3304 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3306 if (status == STATUS_SUCCESS) {
3315 NdisMDeregisterDevice(handle)
3318 IoDeleteDevice(handle);
3319 return(NDIS_STATUS_SUCCESS);
3323 NdisMQueryAdapterInstanceName(name, handle)
3324 unicode_string *name;
3327 ndis_miniport_block *block;
3331 block = (ndis_miniport_block *)handle;
3332 dev = block->nmb_physdeviceobj->do_devext;
3334 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3335 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3336 return(NDIS_STATUS_RESOURCES);
3338 return(NDIS_STATUS_SUCCESS);
3342 NdisMRegisterUnloadHandler(handle, func)
3352 printf ("NDIS dummy called...\n");
3357 * Note: a couple of entries in this table specify the
3358 * number of arguments as "foo + 1". These are routines
3359 * that accept a 64-bit argument, passed by value. On
3360 * x86, these arguments consume two longwords on the stack,
3361 * so we lie and say there's one additional argument so
3362 * that the wrapping routines will do the right thing.
3365 image_patch_table ndis_functbl[] = {
3366 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3367 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3368 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3369 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3370 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3371 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3372 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3373 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3374 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3375 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3376 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3377 IMPORT_SFUNC(NdisInitAnsiString, 2),
3378 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3379 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3380 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3381 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3382 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3383 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3384 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3385 IMPORT_SFUNC(NdisInitializeString, 2),
3386 IMPORT_SFUNC(NdisFreeString, 1),
3387 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3388 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3389 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3390 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3391 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3392 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3393 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3394 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3395 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3396 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3397 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3398 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3399 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3400 IMPORT_SFUNC(NdisReadConfiguration, 5),
3401 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3402 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3403 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3404 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3405 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3406 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3407 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3408 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3409 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3410 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3411 IMPORT_SFUNC(NdisFreeMemory, 3),
3412 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3413 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3414 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3415 NdisReadPciSlotInformation, 5),
3416 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3417 NdisWritePciSlotInformation, 5),
3418 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3419 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3420 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3421 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3422 IMPORT_SFUNC(NdisInitializeTimer, 3),
3423 IMPORT_SFUNC(NdisSetTimer, 2),
3424 IMPORT_SFUNC(NdisMCancelTimer, 2),
3425 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3426 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3427 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3428 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3429 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3430 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3431 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3432 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3433 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3434 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3435 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3436 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3437 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3438 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3439 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3440 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3441 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3442 IMPORT_SFUNC(NdisAllocatePacket, 3),
3443 IMPORT_SFUNC(NdisFreePacket, 1),
3444 IMPORT_SFUNC(NdisFreePacketPool, 1),
3445 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3446 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3447 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3448 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3449 IMPORT_SFUNC(NdisQueryBuffer, 3),
3450 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3451 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3452 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3453 IMPORT_SFUNC(NdisBufferLength, 1),
3454 IMPORT_SFUNC(NdisFreeBuffer, 1),
3455 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3456 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3457 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3458 IMPORT_SFUNC(NdisInitializeEvent, 1),
3459 IMPORT_SFUNC(NdisSetEvent, 1),
3460 IMPORT_SFUNC(NdisResetEvent, 1),
3461 IMPORT_SFUNC(NdisWaitEvent, 2),
3462 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3463 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3464 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3465 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3466 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3467 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3468 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3469 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3470 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3471 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3472 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3473 IMPORT_SFUNC(NdisMSleep, 1),
3474 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3475 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3476 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3477 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3478 IMPORT_SFUNC(NdisMapFile, 3),
3479 IMPORT_SFUNC(NdisUnmapFile, 1),
3480 IMPORT_SFUNC(NdisCloseFile, 1),
3481 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3482 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3483 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3484 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3485 IMPORT_SFUNC(ndis_timercall, 4),
3486 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3487 IMPORT_SFUNC(ndis_intr, 2),
3488 IMPORT_SFUNC(ndis_intrhand, 4),
3491 * This last entry is a catch-all for any function we haven't
3492 * implemented yet. The PE import list patching routine will
3493 * use it for any function that doesn't have an explicit match
3497 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3501 { NULL, NULL, NULL }