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 ndis_strcasecmp(s1, s2)
624 * In the kernel, toupper() is a macro. Have to be careful
625 * not to use pointer arithmetic when passing it arguments.
631 if (toupper(a) != toupper(b))
637 return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
641 ndis_strncasecmp(s1, s2, n)
652 if (toupper(a) != toupper(b))
653 return (*(const unsigned char *)s1 -
654 *(const unsigned char *)(s2 - 1));
664 NdisReadConfiguration(status, parm, cfg, key, type)
666 ndis_config_parm **parm;
672 ndis_miniport_block *block;
673 struct ndis_softc *sc;
674 struct sysctl_oid *oidp;
675 struct sysctl_ctx_entry *e;
678 block = (ndis_miniport_block *)cfg;
679 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
681 if (key->us_len == 0 || key->us_buf == NULL) {
682 *status = NDIS_STATUS_FAILURE;
686 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
687 *status = NDIS_STATUS_RESOURCES;
694 * See if registry key is already in a list of known keys
695 * included with the driver.
697 #if __FreeBSD_version < 502113
698 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
700 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
703 if (ndis_strcasecmp(oidp->oid_name, keystr) == 0) {
704 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
705 RtlFreeAnsiString(&as);
706 *status = NDIS_STATUS_FAILURE;
710 *status = ndis_encode_parm(block, oidp, type, parm);
711 RtlFreeAnsiString(&as);
717 * If the key didn't match, add it to the list of dynamically
718 * created ones. Sometimes, drivers refer to registry keys
719 * that aren't documented in their .INF files. These keys
720 * are supposed to be created by some sort of utility or
721 * control panel snap-in that comes with the driver software.
722 * Sometimes it's useful to be able to manipulate these.
723 * If the driver requests the key in the form of a string,
724 * make its default value an empty string, otherwise default
728 if (type == ndis_parm_int || type == ndis_parm_hexint)
729 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
730 "UNSET", CTLFLAG_RW);
732 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
733 "UNSET", CTLFLAG_RW);
735 RtlFreeAnsiString(&as);
736 *status = NDIS_STATUS_FAILURE;
742 ndis_decode_parm(block, parm, val)
743 ndis_miniport_block *block;
744 ndis_config_parm *parm;
747 unicode_string *ustr;
750 switch(parm->ncp_type) {
751 case ndis_parm_string:
752 ustr = &parm->ncp_parmdata.ncp_stringdata;
753 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
754 return(NDIS_STATUS_RESOURCES);
755 bcopy(as.as_buf, val, as.as_len);
756 RtlFreeAnsiString(&as);
759 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
761 case ndis_parm_hexint:
762 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
765 return(NDIS_STATUS_FAILURE);
768 return(NDIS_STATUS_SUCCESS);
772 NdisWriteConfiguration(status, cfg, key, parm)
776 ndis_config_parm *parm;
780 ndis_miniport_block *block;
781 struct ndis_softc *sc;
782 struct sysctl_oid *oidp;
783 struct sysctl_ctx_entry *e;
786 block = (ndis_miniport_block *)cfg;
787 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
789 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
790 *status = NDIS_STATUS_RESOURCES;
796 /* Decode the parameter into a string. */
797 bzero(val, sizeof(val));
798 *status = ndis_decode_parm(block, parm, val);
799 if (*status != NDIS_STATUS_SUCCESS) {
800 RtlFreeAnsiString(&as);
804 /* See if the key already exists. */
806 #if __FreeBSD_version < 502113
807 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
809 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
812 if (ndis_strcasecmp(oidp->oid_name, keystr) == 0) {
813 /* Found it, set the value. */
814 strcpy((char *)oidp->oid_arg1, val);
815 RtlFreeAnsiString(&as);
820 /* Not found, add a new key with the specified value. */
821 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
824 RtlFreeAnsiString(&as);
825 *status = NDIS_STATUS_SUCCESS;
830 NdisCloseConfiguration(cfg)
834 ndis_parmlist_entry *pe;
835 ndis_miniport_block *block;
838 block = (ndis_miniport_block *)cfg;
840 while (!IsListEmpty(&block->nmb_parmlist)) {
841 e = RemoveHeadList(&block->nmb_parmlist);
842 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
844 if (p->ncp_type == ndis_parm_string)
845 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
853 * Initialize a Windows spinlock.
856 NdisAllocateSpinLock(lock)
857 ndis_spin_lock *lock;
859 KeInitializeSpinLock(&lock->nsl_spinlock);
866 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
867 * for this. One is that it's sort of superfluous: we don't have to do anything
868 * special to deallocate the spinlock. The other is that there are some buggy
869 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
870 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
874 NdisFreeSpinLock(lock)
875 ndis_spin_lock *lock;
878 KeInitializeSpinLock(&lock->nsl_spinlock);
885 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
889 NdisAcquireSpinLock(lock)
890 ndis_spin_lock *lock;
892 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
897 * Release a spinlock from IRQL == DISPATCH_LEVEL.
901 NdisReleaseSpinLock(lock)
902 ndis_spin_lock *lock;
904 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
909 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
912 NdisDprAcquireSpinLock(lock)
913 ndis_spin_lock *lock;
915 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
920 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
923 NdisDprReleaseSpinLock(lock)
924 ndis_spin_lock *lock;
926 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
931 NdisInitializeReadWriteLock(lock)
934 KeInitializeSpinLock(&lock->nrl_spinlock);
935 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
940 NdisAcquireReadWriteLock(lock, writeacc, state)
943 ndis_lock_state *state;
945 if (writeacc == TRUE) {
946 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
955 NdisReleaseReadWriteLock(lock, state)
957 ndis_lock_state *state;
959 if (lock->nrl_rsvd[0]) {
961 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
969 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
976 ndis_miniport_block *block;
981 block = (ndis_miniport_block *)adapter;
986 dev = block->nmb_physdeviceobj->do_devext;
989 * I have a test system consisting of a Sun w2100z
990 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
991 * "Aries" miniPCI NIC. (The NIC is installed in the
992 * machine using a miniPCI to PCI bus adapter card.)
993 * When running in SMP mode, I found that
994 * performing a large number of consecutive calls to
995 * NdisReadPciSlotInformation() would result in a
996 * sudden system reset (or in some cases a freeze).
997 * My suspicion is that the multiple reads are somehow
998 * triggering a fatal PCI bus error that leads to a
999 * machine check. The 1us delay in the loop below
1000 * seems to prevent this problem.
1003 for (i = 0; i < len; i++) {
1005 dest[i] = pci_read_config(dev, i + offset, 1);
1012 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
1013 ndis_handle adapter;
1019 ndis_miniport_block *block;
1024 block = (ndis_miniport_block *)adapter;
1030 dev = block->nmb_physdeviceobj->do_devext;
1031 for (i = 0; i < len; i++) {
1033 pci_write_config(dev, i + offset, dest[i], 1);
1040 * The errorlog routine uses a variable argument list, so we
1041 * have to declare it this way.
1044 #define ERRMSGLEN 512
1046 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
1047 uint32_t numerrors, ...)
1049 ndis_miniport_block *block;
1056 struct ndis_softc *sc;
1059 ansi_string as = { 0, 0, NULL };
1061 block = (ndis_miniport_block *)adapter;
1062 dev = block->nmb_physdeviceobj->do_devext;
1063 drv = block->nmb_deviceobj->do_drvobj;
1064 sc = device_get_softc(dev);
1067 if (ifp->if_flags & IFF_DEBUG) {
1068 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
1069 code, &str, &i, &flags);
1071 if (flags & MESSAGE_RESOURCE_UNICODE) {
1072 RtlInitUnicodeString(&us, (uint16_t *)str);
1073 if (RtlUnicodeStringToAnsiString(&as,
1074 &us, TRUE) == STATUS_SUCCESS)
1082 device_printf (dev, "NDIS ERROR: %x (%s)\n", code,
1083 str == NULL ? "unknown error" : str);
1085 if (ifp->if_flags & IFF_DEBUG) {
1086 device_printf (dev, "NDIS NUMERRORS: %x\n", numerrors);
1087 va_start(ap, numerrors);
1088 for (i = 0; i < numerrors; i++)
1089 device_printf (dev, "argptr: %p\n",
1090 va_arg(ap, void *));
1095 RtlFreeAnsiString(&as);
1101 ndis_map_cb(arg, segs, nseg, error)
1103 bus_dma_segment_t *segs;
1107 struct ndis_map_arg *ctx;
1115 for (i = 0; i < nseg; i++) {
1116 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1117 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1120 ctx->nma_cnt = nseg;
1126 NdisMStartBufferPhysicalMapping(adapter, buf, mapreg, writedev, addrarray, arraysize)
1127 ndis_handle adapter;
1131 ndis_paddr_unit *addrarray;
1132 uint32_t *arraysize;
1134 ndis_miniport_block *block;
1135 struct ndis_softc *sc;
1136 struct ndis_map_arg nma;
1140 if (adapter == NULL)
1143 block = (ndis_miniport_block *)adapter;
1144 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1146 if (mapreg > sc->ndis_mmapcnt)
1149 map = sc->ndis_mmaps[mapreg];
1150 nma.nma_fraglist = addrarray;
1152 error = bus_dmamap_load(sc->ndis_mtag, map,
1153 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1154 (void *)&nma, BUS_DMA_NOWAIT);
1159 bus_dmamap_sync(sc->ndis_mtag, map,
1160 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1162 *arraysize = nma.nma_cnt;
1168 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1169 ndis_handle adapter;
1173 ndis_miniport_block *block;
1174 struct ndis_softc *sc;
1177 if (adapter == NULL)
1180 block = (ndis_miniport_block *)adapter;
1181 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1183 if (mapreg > sc->ndis_mmapcnt)
1186 map = sc->ndis_mmaps[mapreg];
1188 bus_dmamap_sync(sc->ndis_mtag, map,
1189 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1191 bus_dmamap_unload(sc->ndis_mtag, map);
1197 * This is an older (?) timer init routine which doesn't
1198 * accept a miniport context handle. Serialized miniports should
1199 * never call this function.
1203 NdisInitializeTimer(timer, func, ctx)
1205 ndis_timer_function func;
1208 KeInitializeTimer(&timer->nt_ktimer);
1209 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1210 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1216 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1218 ndis_miniport_timer *timer;
1223 * Since we're called as a DPC, we should be running
1224 * at DISPATCH_LEVEL here. This means to acquire the
1225 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1226 * rather than KeAcquireSpinLock().
1228 if (NDIS_SERIALIZED(timer->nmt_block))
1229 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1231 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1234 if (NDIS_SERIALIZED(timer->nmt_block))
1235 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1241 * For a long time I wondered why there were two NDIS timer initialization
1242 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1243 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1244 * function and context pointers separate from those in the DPC, which
1245 * allows for another level of indirection: when the timer fires, we
1246 * can have our own timer function invoked, and from there we can call
1247 * the driver's function. But why go to all that trouble? Then it hit
1248 * me: for serialized miniports, the timer callouts are not re-entrant.
1249 * By trapping the callouts and having access to the MiniportAdapterHandle,
1250 * we can protect the driver callouts by acquiring the NDIS serialization
1251 * lock. This is essential for allowing serialized miniports to work
1252 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1253 * is enough to prevent other threads from pre-empting you, but with
1254 * SMP, you must acquire a lock as well, otherwise the other CPU is
1255 * free to clobber you.
1258 NdisMInitializeTimer(timer, handle, func, ctx)
1259 ndis_miniport_timer *timer;
1261 ndis_timer_function func;
1264 /* Save the driver's funcptr and context */
1266 timer->nmt_timerfunc = func;
1267 timer->nmt_timerctx = ctx;
1268 timer->nmt_block = handle;
1271 * Set up the timer so it will call our intermediate DPC.
1272 * Be sure to use the wrapped entry point, since
1273 * ntoskrnl_run_dpc() expects to invoke a function with
1274 * Microsoft calling conventions.
1276 KeInitializeTimer(&timer->nmt_ktimer);
1277 KeInitializeDpc(&timer->nmt_kdpc,
1278 ndis_findwrap((funcptr)ndis_timercall), timer);
1279 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1285 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1286 * but the former is just a macro wrapper around the latter.
1289 NdisSetTimer(timer, msecs)
1294 * KeSetTimer() wants the period in
1295 * hundred nanosecond intervals.
1297 KeSetTimer(&timer->nt_ktimer,
1298 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1304 NdisMSetPeriodicTimer(timer, msecs)
1305 ndis_miniport_timer *timer;
1308 KeSetTimerEx(&timer->nmt_ktimer,
1309 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1315 * Technically, this is really NdisCancelTimer(), but we also
1316 * (ab)use it for NdisMCancelTimer(), since in our implementation
1317 * we don't need the extra info in the ndis_miniport_timer
1318 * structure just to cancel a timer.
1322 NdisMCancelTimer(timer, cancelled)
1326 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1331 NdisMQueryAdapterResources(status, adapter, list, buflen)
1332 ndis_status *status;
1333 ndis_handle adapter;
1334 ndis_resource_list *list;
1337 ndis_miniport_block *block;
1338 struct ndis_softc *sc;
1341 block = (ndis_miniport_block *)adapter;
1342 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1344 rsclen = sizeof(ndis_resource_list) +
1345 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1346 if (*buflen < rsclen) {
1348 *status = NDIS_STATUS_INVALID_LENGTH;
1352 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1353 *status = NDIS_STATUS_SUCCESS;
1359 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1361 ndis_handle adapter;
1365 struct ndis_miniport_block *block;
1366 struct ndis_softc *sc;
1368 if (adapter == NULL)
1369 return(NDIS_STATUS_FAILURE);
1371 block = (ndis_miniport_block *)adapter;
1372 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1374 if (sc->ndis_res_io == NULL)
1375 return(NDIS_STATUS_FAILURE);
1377 /* Don't let the device map more ports than we have. */
1378 if (rman_get_size(sc->ndis_res_io) < numports)
1379 return(NDIS_STATUS_INVALID_LENGTH);
1381 *offset = (void *)rman_get_start(sc->ndis_res_io);
1383 return(NDIS_STATUS_SUCCESS);
1387 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1388 ndis_handle adapter;
1397 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1398 ndis_status *status;
1401 ndis_handle adapter;
1403 struct ndis_softc *sc;
1404 ndis_miniport_block *block;
1405 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1407 block = (ndis_miniport_block *)adapter;
1408 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1411 if (bcmp(IFP2ENADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1412 #elif __FreeBSD_version >= 700000
1413 if (sc->ifp->if_addr == NULL ||
1414 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1416 if (bcmp(sc->arpcom.ac_enaddr, empty, ETHER_ADDR_LEN) == 0)
1418 *status = NDIS_STATUS_FAILURE;
1421 *addr = IFP2ENADDR(sc->ifp);
1422 #elif __FreeBSD_version >= 700000
1423 *addr = IF_LLADDR(sc->ifp);
1425 *addr = sc->arpcom.ac_enaddr;
1427 *addrlen = ETHER_ADDR_LEN;
1428 *status = NDIS_STATUS_SUCCESS;
1435 NdisQueryMapRegisterCount(bustype, cnt)
1440 return(NDIS_STATUS_SUCCESS);
1444 NdisMAllocateMapRegisters(adapter, dmachannel, dmasize, physmapneeded, maxmap)
1445 ndis_handle adapter;
1446 uint32_t dmachannel;
1448 uint32_t physmapneeded;
1451 struct ndis_softc *sc;
1452 ndis_miniport_block *block;
1453 int error, i, nseg = NDIS_MAXSEG;
1455 block = (ndis_miniport_block *)adapter;
1456 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1458 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1459 M_DEVBUF, M_NOWAIT|M_ZERO);
1461 if (sc->ndis_mmaps == NULL)
1462 return(NDIS_STATUS_RESOURCES);
1464 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1465 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1466 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1467 NULL, NULL, &sc->ndis_mtag);
1470 free(sc->ndis_mmaps, M_DEVBUF);
1471 return(NDIS_STATUS_RESOURCES);
1474 for (i = 0; i < physmapneeded; i++)
1475 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1477 sc->ndis_mmapcnt = physmapneeded;
1479 return(NDIS_STATUS_SUCCESS);
1483 NdisMFreeMapRegisters(adapter)
1484 ndis_handle adapter;
1486 struct ndis_softc *sc;
1487 ndis_miniport_block *block;
1490 block = (ndis_miniport_block *)adapter;
1491 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1493 for (i = 0; i < sc->ndis_mmapcnt; i++)
1494 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1496 free(sc->ndis_mmaps, M_DEVBUF);
1498 bus_dma_tag_destroy(sc->ndis_mtag);
1504 ndis_mapshared_cb(arg, segs, nseg, error)
1506 bus_dma_segment_t *segs;
1512 if (error || nseg > 1)
1517 p->np_quad = segs[0].ds_addr;
1523 * This maps to bus_dmamem_alloc().
1527 NdisMAllocateSharedMemory(adapter, len, cached, vaddr, paddr)
1528 ndis_handle adapter;
1532 ndis_physaddr *paddr;
1534 ndis_miniport_block *block;
1535 struct ndis_softc *sc;
1536 struct ndis_shmem *sh;
1539 if (adapter == NULL)
1542 block = (ndis_miniport_block *)adapter;
1543 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1545 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1549 InitializeListHead(&sh->ndis_list);
1552 * When performing shared memory allocations, create a tag
1553 * with a lowaddr limit that restricts physical memory mappings
1554 * so that they all fall within the first 1GB of memory.
1555 * At least one device/driver combination (Linksys Instant
1556 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1557 * problems with performing DMA operations with physical
1558 * addresses that lie above the 1GB mark. I don't know if this
1559 * is a hardware limitation or if the addresses are being
1560 * truncated within the driver, but this seems to be the only
1561 * way to make these cards work reliably in systems with more
1562 * than 1GB of physical memory.
1565 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1566 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1567 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1575 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1576 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1579 bus_dma_tag_destroy(sh->ndis_stag);
1584 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1585 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1588 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1589 bus_dma_tag_destroy(sh->ndis_stag);
1595 * Save the physical address along with the source address.
1596 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1597 * with a bogus virtual address sometimes, but with a valid
1598 * physical address. To keep this from causing trouble, we
1599 * use the physical address to as a sanity check in case
1600 * searching based on the virtual address fails.
1604 sh->ndis_paddr.np_quad = paddr->np_quad;
1605 sh->ndis_saddr = *vaddr;
1606 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1612 struct ndis_allocwork {
1620 ndis_asyncmem_complete(dobj, arg)
1621 device_object *dobj;
1624 ndis_miniport_block *block;
1625 struct ndis_softc *sc;
1626 struct ndis_allocwork *w;
1628 ndis_physaddr paddr;
1629 ndis_allocdone_handler donefunc;
1632 block = (ndis_miniport_block *)dobj->do_devext;
1633 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1638 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1639 NdisMAllocateSharedMemory(block, w->na_len,
1640 w->na_cached, &vaddr, &paddr);
1641 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1643 IoFreeWorkItem(w->na_iw);
1650 NdisMAllocateSharedMemoryAsync(adapter, len, cached, ctx)
1651 ndis_handle adapter;
1656 ndis_miniport_block *block;
1657 struct ndis_allocwork *w;
1659 io_workitem_func ifw;
1661 if (adapter == NULL)
1662 return(NDIS_STATUS_FAILURE);
1666 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1668 return(NDIS_STATUS_FAILURE);
1670 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1673 return(NDIS_STATUS_FAILURE);
1675 w->na_cached = cached;
1680 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1681 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1683 return(NDIS_STATUS_PENDING);
1687 NdisMFreeSharedMemory(adapter, len, cached, vaddr, paddr)
1688 ndis_handle adapter;
1692 ndis_physaddr paddr;
1694 ndis_miniport_block *block;
1695 struct ndis_softc *sc;
1696 struct ndis_shmem *sh = NULL;
1699 if (vaddr == NULL || adapter == NULL)
1702 block = (ndis_miniport_block *)adapter;
1703 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1705 /* Sanity check: is list empty? */
1707 if (IsListEmpty(&sc->ndis_shlist))
1711 l = sc->ndis_shlist.nle_flink;
1712 while (l != &sc->ndis_shlist) {
1713 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1714 if (sh->ndis_saddr == vaddr)
1717 * Check the physaddr too, just in case the driver lied
1718 * about the virtual address.
1720 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1727 printf("NDIS: buggy driver tried to free "
1728 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1729 vaddr, (uintmax_t)paddr.np_quad);
1733 RemoveEntryList(&sh->ndis_list);
1737 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1738 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1739 bus_dma_tag_destroy(sh->ndis_stag);
1747 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1749 ndis_handle adapter;
1750 ndis_physaddr paddr;
1753 if (adapter == NULL)
1754 return(NDIS_STATUS_FAILURE);
1756 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1759 return(NDIS_STATUS_FAILURE);
1761 return(NDIS_STATUS_SUCCESS);
1765 NdisMUnmapIoSpace(adapter, vaddr, len)
1766 ndis_handle adapter;
1770 MmUnmapIoSpace(vaddr, len);
1775 NdisGetCacheFillSize(void)
1781 NdisMGetDmaAlignment(handle)
1788 * NDIS has two methods for dealing with NICs that support DMA.
1789 * One is to just pass packets to the driver and let it call
1790 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1791 * all by itself, and the other is to let the NDIS library handle the
1792 * buffer mapping internally, and hand the driver an already populated
1793 * scatter/gather fragment list. If the driver calls
1794 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1799 NdisMInitializeScatterGatherDma(adapter, is64, maxphysmap)
1800 ndis_handle adapter;
1802 uint32_t maxphysmap;
1804 struct ndis_softc *sc;
1805 ndis_miniport_block *block;
1808 if (adapter == NULL)
1809 return(NDIS_STATUS_FAILURE);
1810 block = (ndis_miniport_block *)adapter;
1811 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1813 /* Don't do this twice. */
1814 if (sc->ndis_sc == 1)
1815 return(NDIS_STATUS_SUCCESS);
1817 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1818 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1819 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1820 NULL, NULL, &sc->ndis_ttag);
1824 return(NDIS_STATUS_SUCCESS);
1828 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1829 ndis_status *status;
1832 uint32_t protrsvdlen;
1834 ndis_packet_pool *p;
1835 ndis_packet *packets;
1838 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1840 *status = NDIS_STATUS_RESOURCES;
1844 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1845 p->np_protrsvd = protrsvdlen;
1846 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1848 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1852 if (packets == NULL) {
1854 *status = NDIS_STATUS_RESOURCES;
1858 p->np_pktmem = packets;
1860 for (i = 0; i < p->np_cnt; i++)
1861 InterlockedPushEntrySList(&p->np_head,
1862 (struct slist_entry *)&packets[i]);
1864 #ifdef NDIS_DEBUG_PACKETS
1866 KeInitializeSpinLock(&p->np_lock);
1867 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1871 *status = NDIS_STATUS_SUCCESS;
1876 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1877 ndis_status *status;
1880 uint32_t oflowdescnum;
1881 uint32_t protrsvdlen;
1883 return(NdisAllocatePacketPool(status, pool,
1884 descnum + oflowdescnum, protrsvdlen));
1888 NdisPacketPoolUsage(pool)
1891 ndis_packet_pool *p;
1893 p = (ndis_packet_pool *)pool;
1894 return(p->np_cnt - ExQueryDepthSList(&p->np_head));
1898 NdisFreePacketPool(pool)
1901 ndis_packet_pool *p;
1903 #ifdef NDIS_DEBUG_PACKETS
1907 p = (ndis_packet_pool *)pool;
1909 #ifdef NDIS_DEBUG_PACKETS
1910 KeAcquireSpinLock(&p->np_lock, &irql);
1913 usage = NdisPacketPoolUsage(pool);
1915 #ifdef NDIS_DEBUG_PACKETS
1918 KeResetEvent(&p->np_event);
1919 KeReleaseSpinLock(&p->np_lock, irql);
1920 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1922 KeReleaseSpinLock(&p->np_lock, irql);
1925 ExFreePool(p->np_pktmem);
1932 NdisAllocatePacket(status, packet, pool)
1933 ndis_status *status;
1934 ndis_packet **packet;
1937 ndis_packet_pool *p;
1939 #ifdef NDIS_DEBUG_PACKETS
1943 p = (ndis_packet_pool *)pool;
1945 #ifdef NDIS_DEBUG_PACKETS
1946 KeAcquireSpinLock(&p->np_lock, &irql);
1948 KeReleaseSpinLock(&p->np_lock, irql);
1949 printf("NDIS: tried to allocate packet from dead pool %p\n",
1951 *status = NDIS_STATUS_RESOURCES;
1956 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1958 #ifdef NDIS_DEBUG_PACKETS
1959 KeReleaseSpinLock(&p->np_lock, irql);
1963 *status = NDIS_STATUS_RESOURCES;
1968 bzero((char *)pkt, sizeof(ndis_packet));
1970 /* Save pointer to the pool. */
1971 pkt->np_private.npp_pool = pool;
1973 /* Set the oob offset pointer. Lots of things expect this. */
1974 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1977 * We must initialize the packet flags correctly in order
1978 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1979 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1982 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1983 pkt->np_private.npp_validcounts = FALSE;
1987 *status = NDIS_STATUS_SUCCESS;
1993 NdisFreePacket(packet)
1994 ndis_packet *packet;
1996 ndis_packet_pool *p;
1997 #ifdef NDIS_DEBUG_PACKETS
2001 p = (ndis_packet_pool *)packet->np_private.npp_pool;
2003 #ifdef NDIS_DEBUG_PACKETS
2004 KeAcquireSpinLock(&p->np_lock, &irql);
2007 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
2009 #ifdef NDIS_DEBUG_PACKETS
2011 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
2012 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
2014 KeReleaseSpinLock(&p->np_lock, irql);
2021 NdisUnchainBufferAtFront(packet, buf)
2022 ndis_packet *packet;
2025 ndis_packet_private *priv;
2027 if (packet == NULL || buf == NULL)
2030 priv = &packet->np_private;
2032 priv->npp_validcounts = FALSE;
2034 if (priv->npp_head == priv->npp_tail) {
2035 *buf = priv->npp_head;
2036 priv->npp_head = priv->npp_tail = NULL;
2038 *buf = priv->npp_head;
2039 priv->npp_head = (*buf)->mdl_next;
2046 NdisUnchainBufferAtBack(packet, buf)
2047 ndis_packet *packet;
2050 ndis_packet_private *priv;
2053 if (packet == NULL || buf == NULL)
2056 priv = &packet->np_private;
2058 priv->npp_validcounts = FALSE;
2060 if (priv->npp_head == priv->npp_tail) {
2061 *buf = priv->npp_head;
2062 priv->npp_head = priv->npp_tail = NULL;
2064 *buf = priv->npp_tail;
2065 tmp = priv->npp_head;
2066 while (tmp->mdl_next != priv->npp_tail)
2067 tmp = tmp->mdl_next;
2068 priv->npp_tail = tmp;
2069 tmp->mdl_next = NULL;
2076 * The NDIS "buffer" is really an MDL (memory descriptor list)
2077 * which is used to describe a buffer in a way that allows it
2078 * to mapped into different contexts. We have to be careful how
2079 * we handle them: in some versions of Windows, the NdisFreeBuffer()
2080 * routine is an actual function in the NDIS API, but in others
2081 * it's just a macro wrapper around IoFreeMdl(). There's really
2082 * no way to use the 'descnum' parameter to count how many
2083 * "buffers" are allocated since in order to use IoFreeMdl() to
2084 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
2085 * them, and IoAllocateMdl() just grabs them out of the heap.
2089 NdisAllocateBufferPool(status, pool, descnum)
2090 ndis_status *status;
2096 * The only thing we can really do here is verify that descnum
2097 * is a reasonable value, but I really don't know what to check
2101 *pool = NonPagedPool;
2102 *status = NDIS_STATUS_SUCCESS;
2107 NdisFreeBufferPool(pool)
2114 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
2115 ndis_status *status;
2116 ndis_buffer **buffer;
2123 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
2125 *status = NDIS_STATUS_RESOURCES;
2129 MmBuildMdlForNonPagedPool(buf);
2132 *status = NDIS_STATUS_SUCCESS;
2148 NdisBufferLength(buf)
2151 return(MmGetMdlByteCount(buf));
2155 * Get the virtual address and length of a buffer.
2156 * Note: the vaddr argument is optional.
2160 NdisQueryBuffer(buf, vaddr, len)
2166 *vaddr = MmGetMdlVirtualAddress(buf);
2167 *len = MmGetMdlByteCount(buf);
2172 /* Same as above -- we don't care about the priority. */
2175 NdisQueryBufferSafe(buf, vaddr, len, prio)
2182 *vaddr = MmGetMdlVirtualAddress(buf);
2183 *len = MmGetMdlByteCount(buf);
2188 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2191 NdisBufferVirtualAddress(buf)
2194 return(MmGetMdlVirtualAddress(buf));
2198 NdisBufferVirtualAddressSafe(buf, prio)
2202 return(MmGetMdlVirtualAddress(buf));
2206 NdisAdjustBufferLength(buf, len)
2210 MmGetMdlByteCount(buf) = len;
2216 NdisInterlockedIncrement(addend)
2219 atomic_add_long((u_long *)addend, 1);
2224 NdisInterlockedDecrement(addend)
2227 atomic_subtract_long((u_long *)addend, 1);
2232 NdisInitializeEvent(event)
2236 * NDIS events are always notification
2237 * events, and should be initialized to the
2238 * not signaled state.
2240 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2248 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2253 NdisResetEvent(event)
2256 KeResetEvent(&event->ne_event);
2261 NdisWaitEvent(event, msecs)
2268 duetime = ((int64_t)msecs * -10000);
2269 rval = KeWaitForSingleObject(event,
2270 0, 0, TRUE, msecs ? & duetime : NULL);
2272 if (rval == STATUS_TIMEOUT)
2279 NdisUnicodeStringToAnsiString(dstr, sstr)
2281 unicode_string *sstr;
2285 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2287 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2288 return(NDIS_STATUS_RESOURCES);
2290 return(NDIS_STATUS_FAILURE);
2292 return (NDIS_STATUS_SUCCESS);
2296 NdisAnsiStringToUnicodeString(dstr, sstr)
2297 unicode_string *dstr;
2302 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2304 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2305 return(NDIS_STATUS_RESOURCES);
2307 return(NDIS_STATUS_FAILURE);
2309 return (NDIS_STATUS_SUCCESS);
2313 NdisMPciAssignResources(adapter, slot, list)
2314 ndis_handle adapter;
2316 ndis_resource_list **list;
2318 ndis_miniport_block *block;
2320 if (adapter == NULL || list == NULL)
2321 return (NDIS_STATUS_FAILURE);
2323 block = (ndis_miniport_block *)adapter;
2324 *list = block->nmb_rlist;
2326 return (NDIS_STATUS_SUCCESS);
2330 ndis_intr(iobj, arg)
2334 struct ndis_softc *sc;
2335 uint8_t is_our_intr = FALSE;
2337 ndis_miniport_interrupt *intr;
2340 intr = sc->ndis_block->nmb_interrupt;
2342 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2345 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2346 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2347 sc->ndis_block->nmb_miniportadapterctx);
2349 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2350 sc->ndis_block->nmb_miniportadapterctx);
2355 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2357 return(is_our_intr);
2361 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2363 ndis_miniport_interrupt *intr;
2367 struct ndis_softc *sc;
2368 ndis_miniport_block *block;
2369 ndis_handle adapter;
2371 block = intr->ni_block;
2372 adapter = block->nmb_miniportadapterctx;
2373 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2375 if (NDIS_SERIALIZED(sc->ndis_block))
2376 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2378 MSCALL1(intr->ni_dpcfunc, adapter);
2380 /* If there's a MiniportEnableInterrupt() routine, call it. */
2382 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2383 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2385 if (NDIS_SERIALIZED(sc->ndis_block))
2386 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2389 * Set the completion event if we've drained all
2390 * pending interrupts.
2393 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2395 if (intr->ni_dpccnt == 0)
2396 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2397 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2403 NdisMRegisterInterrupt(intr, adapter, ivec, ilevel, reqisr, shared, imode)
2404 ndis_miniport_interrupt *intr;
2405 ndis_handle adapter;
2410 ndis_interrupt_mode imode;
2412 ndis_miniport_block *block;
2413 ndis_miniport_characteristics *ch;
2414 struct ndis_softc *sc;
2418 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2419 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2422 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2423 sizeof(struct mtx), 0);
2424 if (intr->ni_rsvd == NULL)
2425 return(NDIS_STATUS_RESOURCES);
2427 intr->ni_block = adapter;
2428 intr->ni_isrreq = reqisr;
2429 intr->ni_shared = shared;
2430 intr->ni_dpccnt = 0;
2431 intr->ni_isrfunc = ch->nmc_isr_func;
2432 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2434 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2435 KeInitializeDpc(&intr->ni_dpc,
2436 ndis_findwrap((funcptr)ndis_intrhand), intr);
2437 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2439 error = IoConnectInterrupt(&intr->ni_introbj,
2440 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2441 ivec, ilevel, 0, imode, shared, 0, FALSE);
2443 if (error != STATUS_SUCCESS)
2444 return(NDIS_STATUS_FAILURE);
2446 block->nmb_interrupt = intr;
2448 return(NDIS_STATUS_SUCCESS);
2452 NdisMDeregisterInterrupt(intr)
2453 ndis_miniport_interrupt *intr;
2455 ndis_miniport_block *block;
2456 struct ndis_softc *sc;
2459 block = intr->ni_block;
2460 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2462 /* Should really be KeSynchronizeExecution() */
2464 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2465 block->nmb_interrupt = NULL;
2466 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2468 KeFlushQueuedDpcs();
2470 /* Disconnect our ISR */
2472 IoDisconnectInterrupt(intr->ni_introbj);
2474 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2475 KeResetEvent(&intr->ni_dpcevt);
2481 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2482 ndis_handle adapter;
2484 ndis_shutdown_handler shutdownfunc;
2486 ndis_miniport_block *block;
2487 ndis_miniport_characteristics *chars;
2488 struct ndis_softc *sc;
2490 if (adapter == NULL)
2493 block = (ndis_miniport_block *)adapter;
2494 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2495 chars = sc->ndis_chars;
2497 chars->nmc_shutdown_handler = shutdownfunc;
2498 chars->nmc_rsvd0 = shutdownctx;
2504 NdisMDeregisterAdapterShutdownHandler(adapter)
2505 ndis_handle adapter;
2507 ndis_miniport_block *block;
2508 ndis_miniport_characteristics *chars;
2509 struct ndis_softc *sc;
2511 if (adapter == NULL)
2514 block = (ndis_miniport_block *)adapter;
2515 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2516 chars = sc->ndis_chars;
2518 chars->nmc_shutdown_handler = NULL;
2519 chars->nmc_rsvd0 = NULL;
2525 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2530 if (MmGetMdlByteCount(buf) == 0)
2532 return(SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2533 MmGetMdlByteCount(buf)));
2537 NdisGetBufferPhysicalArraySize(buf, pages)
2544 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2549 NdisQueryBufferOffset(buf, off, len)
2557 *off = MmGetMdlByteOffset(buf);
2558 *len = MmGetMdlByteCount(buf);
2570 * During system bootstrap, (i.e. cold == 1), we aren't
2571 * allowed to sleep, so we have to do a hard DELAY()
2578 KeInitializeTimer(&timer);
2579 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2580 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2587 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2593 struct ndis_softc *sc;
2594 ndis_miniport_block *block;
2595 bus_space_handle_t bh;
2603 block = (ndis_miniport_block *)handle;
2604 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2607 bh = rman_get_bushandle(sc->ndis_res_am);
2608 bt = rman_get_bustag(sc->ndis_res_am);
2610 for (i = 0; i < len; i++)
2611 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2617 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2623 struct ndis_softc *sc;
2624 ndis_miniport_block *block;
2625 bus_space_handle_t bh;
2633 block = (ndis_miniport_block *)handle;
2634 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2637 bh = rman_get_bushandle(sc->ndis_res_am);
2638 bt = rman_get_bustag(sc->ndis_res_am);
2640 for (i = 0; i < len; i++)
2641 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2647 NdisInterlockedInsertHeadList(head, entry, lock)
2650 ndis_spin_lock *lock;
2654 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2655 flink = head->nle_flink;
2656 entry->nle_flink = flink;
2657 entry->nle_blink = head;
2658 flink->nle_blink = entry;
2659 head->nle_flink = entry;
2660 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2666 NdisInterlockedRemoveHeadList(head, lock)
2668 ndis_spin_lock *lock;
2673 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2674 entry = head->nle_flink;
2675 flink = entry->nle_flink;
2676 head->nle_flink = flink;
2677 flink->nle_blink = head;
2678 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2684 NdisInterlockedInsertTailList(head, entry, lock)
2687 ndis_spin_lock *lock;
2691 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2692 blink = head->nle_blink;
2693 entry->nle_flink = head;
2694 entry->nle_blink = blink;
2695 blink->nle_flink = entry;
2696 head->nle_blink = entry;
2697 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2703 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2704 ndis_miniport_interrupt *intr;
2708 return(KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2712 * Return the number of 100 nanosecond intervals since
2713 * January 1, 1601. (?!?!)
2716 NdisGetCurrentSystemTime(tval)
2722 *tval = (uint64_t)ts.tv_nsec / 100 + (uint64_t)ts.tv_sec * 10000000 +
2729 * Return the number of milliseconds since the system booted.
2732 NdisGetSystemUpTime(tval)
2738 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2744 NdisInitializeString(dst, src)
2745 unicode_string *dst;
2749 RtlInitAnsiString(&as, src);
2750 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2756 unicode_string *str;
2758 RtlFreeUnicodeString(str);
2763 NdisMRemoveMiniport(adapter)
2764 ndis_handle *adapter;
2766 return(NDIS_STATUS_SUCCESS);
2770 NdisInitAnsiString(dst, src)
2774 RtlInitAnsiString(dst, src);
2779 NdisInitUnicodeString(dst, src)
2780 unicode_string *dst;
2783 RtlInitUnicodeString(dst, src);
2787 static void NdisMGetDeviceProperty(adapter, phydevobj,
2788 funcdevobj, nextdevobj, resources, transresources)
2789 ndis_handle adapter;
2790 device_object **phydevobj;
2791 device_object **funcdevobj;
2792 device_object **nextdevobj;
2793 cm_resource_list *resources;
2794 cm_resource_list *transresources;
2796 ndis_miniport_block *block;
2798 block = (ndis_miniport_block *)adapter;
2800 if (phydevobj != NULL)
2801 *phydevobj = block->nmb_physdeviceobj;
2802 if (funcdevobj != NULL)
2803 *funcdevobj = block->nmb_deviceobj;
2804 if (nextdevobj != NULL)
2805 *nextdevobj = block->nmb_nextdeviceobj;
2811 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2812 ndis_packet *packet;
2820 tmp = packet->np_private.npp_head;
2824 *firstlen = *totlen = 0;
2826 *firstva = MmGetMdlVirtualAddress(tmp);
2827 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2828 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2829 *totlen += MmGetMdlByteCount(tmp);
2836 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2837 ndis_packet *packet;
2844 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2848 ndis_find_sym(lf, filename, suffix, sym)
2858 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2859 if (fullsym == NULL)
2862 bzero(fullsym, MAXPATHLEN);
2863 strncpy(fullsym, filename, MAXPATHLEN);
2864 if (strlen(filename) < 4) {
2865 ExFreePool(fullsym);
2869 /* If the filename has a .ko suffix, strip if off. */
2870 suf = fullsym + (strlen(filename) - 3);
2871 if (strcmp(suf, ".ko") == 0)
2874 for (i = 0; i < strlen(fullsym); i++) {
2875 if (fullsym[i] == '.')
2878 fullsym[i] = tolower(fullsym[i]);
2880 strcat(fullsym, suffix);
2881 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2882 ExFreePool(fullsym);
2889 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2891 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2892 ndis_status *status;
2893 ndis_handle *filehandle;
2894 uint32_t *filelength;
2895 unicode_string *filename;
2896 ndis_physaddr highestaddr;
2899 char *afilename = NULL;
2900 struct thread *td = curthread;
2901 struct nameidata nd;
2904 struct vattr *vap = &vat;
2907 linker_file_t head, lf;
2908 caddr_t kldstart, kldend;
2910 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2911 *status = NDIS_STATUS_RESOURCES;
2915 afilename = strdup(as.as_buf, M_DEVBUF);
2916 RtlFreeAnsiString(&as);
2918 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2920 free(afilename, M_DEVBUF);
2921 *status = NDIS_STATUS_RESOURCES;
2925 fh->nf_name = afilename;
2928 * During system bootstrap, it's impossible to load files
2929 * from the rootfs since it's not mounted yet. We therefore
2930 * offer the possibility of opening files that have been
2931 * preloaded as modules instead. Both choices will work
2932 * when kldloading a module from multiuser, but only the
2933 * module option will work during bootstrap. The module
2934 * loading option works by using the ndiscvt(8) utility
2935 * to convert the arbitrary file into a .ko using objcopy(1).
2936 * This file will contain two special symbols: filename_start
2937 * and filename_end. All we have to do is traverse the KLD
2938 * list in search of those symbols and we've found the file
2939 * data. As an added bonus, ndiscvt(8) will also generate
2940 * a normal .o file which can be linked statically with
2941 * the kernel. This means that the symbols will actual reside
2942 * in the kernel's symbol table, but that doesn't matter to
2943 * us since the kernel appears to us as just another module.
2947 * This is an evil trick for getting the head of the linked
2948 * file list, which is not exported from kern_linker.o. It
2949 * happens that linker file #1 is always the kernel, and is
2950 * always the first element in the list.
2953 head = linker_find_file_by_id(1);
2954 for (lf = head; lf != NULL; lf = TAILQ_NEXT(lf, link)) {
2955 if (ndis_find_sym(lf, afilename, "_start", &kldstart))
2957 if (ndis_find_sym(lf, afilename, "_end", &kldend))
2961 fh->nf_type = NDIS_FH_TYPE_MODULE;
2962 *filelength = fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2964 *status = NDIS_STATUS_SUCCESS;
2968 if (TAILQ_EMPTY(&mountlist)) {
2970 *status = NDIS_STATUS_FILE_NOT_FOUND;
2971 printf("NDIS: could not find file %s in linker list\n",
2973 printf("NDIS: and no filesystems mounted yet, "
2974 "aborting NdisOpenFile()\n");
2975 free(afilename, M_DEVBUF);
2979 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2982 free(afilename, M_DEVBUF);
2983 *status = NDIS_STATUS_RESOURCES;
2987 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2991 /* Some threads don't have a current working directory. */
2993 if (td->td_proc->p_fd->fd_rdir == NULL)
2994 td->td_proc->p_fd->fd_rdir = rootvnode;
2995 if (td->td_proc->p_fd->fd_cdir == NULL)
2996 td->td_proc->p_fd->fd_cdir = rootvnode;
2998 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path, td);
3001 error = vn_open(&nd, &flags, 0, -1);
3004 *status = NDIS_STATUS_FILE_NOT_FOUND;
3006 printf("NDIS: open file %s failed: %d\n", path, error);
3008 free(afilename, M_DEVBUF);
3014 NDFREE(&nd, NDF_ONLY_PNBUF);
3016 /* Get the file size. */
3017 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred, td);
3018 VOP_UNLOCK(nd.ni_vp, 0, td);
3021 fh->nf_vp = nd.ni_vp;
3023 fh->nf_type = NDIS_FH_TYPE_VFS;
3025 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
3026 *status = NDIS_STATUS_SUCCESS;
3032 NdisMapFile(status, mappedbuffer, filehandle)
3033 ndis_status *status;
3034 void **mappedbuffer;
3035 ndis_handle filehandle;
3038 struct thread *td = curthread;
3043 if (filehandle == NULL) {
3044 *status = NDIS_STATUS_FAILURE;
3048 fh = (ndis_fh *)filehandle;
3050 if (fh->nf_vp == NULL) {
3051 *status = NDIS_STATUS_FAILURE;
3055 if (fh->nf_map != NULL) {
3056 *status = NDIS_STATUS_ALREADY_MAPPED;
3060 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
3062 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
3063 *status = NDIS_STATUS_FAILURE;
3066 fh->nf_map = kldstart;
3067 *status = NDIS_STATUS_SUCCESS;
3068 *mappedbuffer = fh->nf_map;
3072 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
3074 if (fh->nf_map == NULL) {
3075 *status = NDIS_STATUS_RESOURCES;
3080 error = vn_rdwr(UIO_READ, fh->nf_vp, fh->nf_map, fh->nf_maplen, 0,
3081 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
3085 *status = NDIS_STATUS_FAILURE;
3087 *status = NDIS_STATUS_SUCCESS;
3088 *mappedbuffer = fh->nf_map;
3095 NdisUnmapFile(filehandle)
3096 ndis_handle filehandle;
3099 fh = (ndis_fh *)filehandle;
3101 if (fh->nf_map == NULL)
3104 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3105 ExFreePool(fh->nf_map);
3112 NdisCloseFile(filehandle)
3113 ndis_handle filehandle;
3115 struct thread *td = curthread;
3118 if (filehandle == NULL)
3121 fh = (ndis_fh *)filehandle;
3122 if (fh->nf_map != NULL) {
3123 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3124 ExFreePool(fh->nf_map);
3128 if (fh->nf_vp == NULL)
3131 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
3133 vn_close(fh->nf_vp, FREAD, td->td_ucred, td);
3138 free(fh->nf_name, M_DEVBUF);
3145 NdisSystemProcessorCount()
3150 typedef void (*ndis_statusdone_handler)(ndis_handle);
3151 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
3155 NdisMIndicateStatusComplete(adapter)
3156 ndis_handle adapter;
3158 ndis_miniport_block *block;
3159 ndis_statusdone_handler statusdonefunc;
3161 block = (ndis_miniport_block *)adapter;
3162 statusdonefunc = block->nmb_statusdone_func;
3164 MSCALL1(statusdonefunc, adapter);
3169 NdisMIndicateStatus(adapter, status, sbuf, slen)
3170 ndis_handle adapter;
3175 ndis_miniport_block *block;
3176 ndis_status_handler statusfunc;
3178 block = (ndis_miniport_block *)adapter;
3179 statusfunc = block->nmb_status_func;
3181 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3186 * The DDK documentation says that you should use IoQueueWorkItem()
3187 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3188 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3189 * depends on the API semantics of ExQueueWorkItem(). In our world,
3190 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3193 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3194 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3195 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3196 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3197 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3198 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3199 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3200 * to ExQueueWorkItem().
3202 * Got all that? (Sheesh.)
3206 NdisScheduleWorkItem(work)
3207 ndis_work_item *work;
3209 work_queue_item *wqi;
3211 wqi = (work_queue_item *)work->nwi_wraprsvd;
3212 ExInitializeWorkItem(wqi,
3213 (work_item_func)work->nwi_func, work->nwi_ctx);
3214 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3216 return(NDIS_STATUS_SUCCESS);
3220 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3228 ndis_buffer *src, *dst;
3230 int resid, copied, len, scnt, dcnt;
3234 src = spkt->np_private.npp_head;
3235 dst = dpkt->np_private.npp_head;
3237 sptr = MmGetMdlVirtualAddress(src);
3238 dptr = MmGetMdlVirtualAddress(dst);
3239 scnt = MmGetMdlByteCount(src);
3240 dcnt = MmGetMdlByteCount(dst);
3243 if (MmGetMdlByteCount(src) > soff) {
3245 scnt = MmGetMdlByteCount(src)- soff;
3248 soff -= MmGetMdlByteCount(src);
3249 src = src->mdl_next;
3252 sptr = MmGetMdlVirtualAddress(src);
3256 if (MmGetMdlByteCount(dst) > doff) {
3258 dcnt = MmGetMdlByteCount(dst) - doff;
3261 doff -= MmGetMdlByteCount(dst);
3262 dst = dst->mdl_next;
3265 dptr = MmGetMdlVirtualAddress(dst);
3279 bcopy(sptr, dptr, len);
3288 dst = dst->mdl_next;
3291 dptr = MmGetMdlVirtualAddress(dst);
3292 dcnt = MmGetMdlByteCount(dst);
3297 src = src->mdl_next;
3300 sptr = MmGetMdlVirtualAddress(src);
3301 scnt = MmGetMdlByteCount(src);
3310 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3319 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3324 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3326 unicode_string *devname;
3327 unicode_string *symname;
3328 driver_dispatch *majorfuncs[];
3330 ndis_handle *devhandle;
3333 device_object *dobj;
3335 status = IoCreateDevice(handle, 0, devname,
3336 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3338 if (status == STATUS_SUCCESS) {
3347 NdisMDeregisterDevice(handle)
3350 IoDeleteDevice(handle);
3351 return(NDIS_STATUS_SUCCESS);
3355 NdisMQueryAdapterInstanceName(name, handle)
3356 unicode_string *name;
3359 ndis_miniport_block *block;
3363 block = (ndis_miniport_block *)handle;
3364 dev = block->nmb_physdeviceobj->do_devext;
3366 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3367 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3368 return(NDIS_STATUS_RESOURCES);
3370 return(NDIS_STATUS_SUCCESS);
3374 NdisMRegisterUnloadHandler(handle, func)
3384 printf ("NDIS dummy called...\n");
3389 * Note: a couple of entries in this table specify the
3390 * number of arguments as "foo + 1". These are routines
3391 * that accept a 64-bit argument, passed by value. On
3392 * x86, these arguments consume two longwords on the stack,
3393 * so we lie and say there's one additional argument so
3394 * that the wrapping routines will do the right thing.
3397 image_patch_table ndis_functbl[] = {
3398 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3399 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3400 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3401 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3402 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3403 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3404 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3405 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3406 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3407 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3408 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3409 IMPORT_SFUNC(NdisInitAnsiString, 2),
3410 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3411 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3412 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3413 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3414 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3415 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3416 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3417 IMPORT_SFUNC(NdisInitializeString, 2),
3418 IMPORT_SFUNC(NdisFreeString, 1),
3419 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3420 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3421 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3422 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3423 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3424 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3425 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3426 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3427 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3428 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3429 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3430 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3431 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3432 IMPORT_SFUNC(NdisReadConfiguration, 5),
3433 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3434 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3435 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3436 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3437 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3438 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3439 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3440 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3441 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3442 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3443 IMPORT_SFUNC(NdisFreeMemory, 3),
3444 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3445 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3446 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3447 NdisReadPciSlotInformation, 5),
3448 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3449 NdisWritePciSlotInformation, 5),
3450 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3451 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3452 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3453 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3454 IMPORT_SFUNC(NdisInitializeTimer, 3),
3455 IMPORT_SFUNC(NdisSetTimer, 2),
3456 IMPORT_SFUNC(NdisMCancelTimer, 2),
3457 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3458 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3459 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3460 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3461 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3462 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3463 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3464 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3465 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3466 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3467 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3468 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3469 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3470 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3471 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3472 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3473 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3474 IMPORT_SFUNC(NdisAllocatePacket, 3),
3475 IMPORT_SFUNC(NdisFreePacket, 1),
3476 IMPORT_SFUNC(NdisFreePacketPool, 1),
3477 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3478 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3479 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3480 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3481 IMPORT_SFUNC(NdisQueryBuffer, 3),
3482 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3483 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3484 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3485 IMPORT_SFUNC(NdisBufferLength, 1),
3486 IMPORT_SFUNC(NdisFreeBuffer, 1),
3487 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3488 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3489 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3490 IMPORT_SFUNC(NdisInitializeEvent, 1),
3491 IMPORT_SFUNC(NdisSetEvent, 1),
3492 IMPORT_SFUNC(NdisResetEvent, 1),
3493 IMPORT_SFUNC(NdisWaitEvent, 2),
3494 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3495 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3496 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3497 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3498 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3499 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3500 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3501 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3502 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3503 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3504 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3505 IMPORT_SFUNC(NdisMSleep, 1),
3506 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3507 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3508 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3509 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3510 IMPORT_SFUNC(NdisMapFile, 3),
3511 IMPORT_SFUNC(NdisUnmapFile, 1),
3512 IMPORT_SFUNC(NdisCloseFile, 1),
3513 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3514 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3515 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3516 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3517 IMPORT_SFUNC(ndis_timercall, 4),
3518 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3519 IMPORT_SFUNC(ndis_intr, 2),
3520 IMPORT_SFUNC(ndis_intrhand, 4),
3523 * This last entry is a catch-all for any function we haven't
3524 * implemented yet. The PE import list patching routine will
3525 * use it for any function that doesn't have an explicit match
3529 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3533 { NULL, NULL, NULL }