3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * This file implements a translation layer between the BSD networking
38 * infrasturcture and Windows(R) NDIS network driver modules. A Windows
39 * NDIS driver calls into several functions in the NDIS.SYS Windows
40 * kernel module and exports a table of functions designed to be called
41 * by the NDIS subsystem. Using the PE loader, we can patch our own
42 * versions of the NDIS routines into a given Windows driver module and
43 * convince the driver that it is in fact running on Windows.
45 * We provide a table of all our implemented NDIS routines which is patched
46 * into the driver object code. All our exported routines must use the
47 * _stdcall calling convention, since that's what the Windows object code
52 #include <sys/ctype.h>
53 #include <sys/param.h>
54 #include <sys/types.h>
55 #include <sys/errno.h>
57 #include <sys/callout.h>
58 #include <sys/kernel.h>
59 #include <sys/systm.h>
60 #include <sys/malloc.h>
62 #include <sys/mutex.h>
63 #include <sys/socket.h>
64 #include <sys/sysctl.h>
65 #include <sys/timespec.h>
67 #include <sys/queue.h>
69 #include <sys/filedesc.h>
70 #include <sys/namei.h>
71 #include <sys/fcntl.h>
72 #include <sys/vnode.h>
73 #include <sys/kthread.h>
74 #include <sys/linker.h>
75 #include <sys/mount.h>
76 #include <sys/sysproto.h>
79 #include <net/if_arp.h>
80 #include <net/ethernet.h>
81 #include <net/if_dl.h>
82 #include <net/if_media.h>
84 #include <machine/atomic.h>
85 #include <machine/bus.h>
86 #include <machine/resource.h>
91 #include <machine/stdarg.h>
93 #include <net80211/ieee80211_var.h>
94 #include <net80211/ieee80211_ioctl.h>
96 #include <dev/pci/pcireg.h>
97 #include <dev/pci/pcivar.h>
98 #include <dev/usb/usb.h>
99 #include <dev/usb/usbdi.h>
101 #include <compat/ndis/pe_var.h>
102 #include <compat/ndis/cfg_var.h>
103 #include <compat/ndis/resource_var.h>
104 #include <compat/ndis/ntoskrnl_var.h>
105 #include <compat/ndis/hal_var.h>
106 #include <compat/ndis/ndis_var.h>
107 #include <dev/if_ndis/if_ndisvar.h>
110 #include <vm/vm_param.h>
113 #include <vm/vm_kern.h>
114 #include <vm/vm_map.h>
116 static char ndis_filepath[MAXPATHLEN];
118 SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath,
119 MAXPATHLEN, "Path used by NdisOpenFile() to search for files");
121 static void NdisInitializeWrapper(ndis_handle *,
122 driver_object *, void *, void *);
123 static ndis_status NdisMRegisterMiniport(ndis_handle,
124 ndis_miniport_characteristics *, int);
125 static ndis_status NdisAllocateMemoryWithTag(void **,
127 static ndis_status NdisAllocateMemory(void **,
128 uint32_t, uint32_t, ndis_physaddr);
129 static void NdisFreeMemory(void *, uint32_t, uint32_t);
130 static ndis_status NdisMSetAttributesEx(ndis_handle, ndis_handle,
131 uint32_t, uint32_t, ndis_interface_type);
132 static void NdisOpenConfiguration(ndis_status *,
133 ndis_handle *, ndis_handle);
134 static void NdisOpenConfigurationKeyByIndex(ndis_status *,
135 ndis_handle, uint32_t, unicode_string *, ndis_handle *);
136 static void NdisOpenConfigurationKeyByName(ndis_status *,
137 ndis_handle, unicode_string *, ndis_handle *);
138 static ndis_status ndis_encode_parm(ndis_miniport_block *,
139 struct sysctl_oid *, ndis_parm_type, ndis_config_parm **);
140 static ndis_status ndis_decode_parm(ndis_miniport_block *,
141 ndis_config_parm *, char *);
142 static void NdisReadConfiguration(ndis_status *, ndis_config_parm **,
143 ndis_handle, unicode_string *, ndis_parm_type);
144 static void NdisWriteConfiguration(ndis_status *, ndis_handle,
145 unicode_string *, ndis_config_parm *);
146 static void NdisCloseConfiguration(ndis_handle);
147 static void NdisAllocateSpinLock(ndis_spin_lock *);
148 static void NdisFreeSpinLock(ndis_spin_lock *);
149 static void NdisAcquireSpinLock(ndis_spin_lock *);
150 static void NdisReleaseSpinLock(ndis_spin_lock *);
151 static void NdisDprAcquireSpinLock(ndis_spin_lock *);
152 static void NdisDprReleaseSpinLock(ndis_spin_lock *);
153 static void NdisInitializeReadWriteLock(ndis_rw_lock *);
154 static void NdisAcquireReadWriteLock(ndis_rw_lock *,
155 uint8_t, ndis_lock_state *);
156 static void NdisReleaseReadWriteLock(ndis_rw_lock *, ndis_lock_state *);
157 static uint32_t NdisReadPciSlotInformation(ndis_handle, uint32_t,
158 uint32_t, void *, uint32_t);
159 static uint32_t NdisWritePciSlotInformation(ndis_handle, uint32_t,
160 uint32_t, void *, uint32_t);
161 static void NdisWriteErrorLogEntry(ndis_handle, ndis_error_code, uint32_t, ...);
162 static void ndis_map_cb(void *, bus_dma_segment_t *, int, int);
163 static void NdisMStartBufferPhysicalMapping(ndis_handle,
164 ndis_buffer *, uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *);
165 static void NdisMCompleteBufferPhysicalMapping(ndis_handle,
166 ndis_buffer *, uint32_t);
167 static void NdisMInitializeTimer(ndis_miniport_timer *, ndis_handle,
168 ndis_timer_function, void *);
169 static void NdisInitializeTimer(ndis_timer *,
170 ndis_timer_function, void *);
171 static void NdisSetTimer(ndis_timer *, uint32_t);
172 static void NdisMSetPeriodicTimer(ndis_miniport_timer *, uint32_t);
173 static void NdisMCancelTimer(ndis_timer *, uint8_t *);
174 static void ndis_timercall(kdpc *, ndis_miniport_timer *,
176 static void NdisMQueryAdapterResources(ndis_status *, ndis_handle,
177 ndis_resource_list *, uint32_t *);
178 static ndis_status NdisMRegisterIoPortRange(void **,
179 ndis_handle, uint32_t, uint32_t);
180 static void NdisMDeregisterIoPortRange(ndis_handle,
181 uint32_t, uint32_t, void *);
182 static void NdisReadNetworkAddress(ndis_status *, void **,
183 uint32_t *, ndis_handle);
184 static ndis_status NdisQueryMapRegisterCount(uint32_t, uint32_t *);
185 static ndis_status NdisMAllocateMapRegisters(ndis_handle,
186 uint32_t, uint8_t, uint32_t, uint32_t);
187 static void NdisMFreeMapRegisters(ndis_handle);
188 static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int);
189 static void NdisMAllocateSharedMemory(ndis_handle, uint32_t,
190 uint8_t, void **, ndis_physaddr *);
191 static void ndis_asyncmem_complete(device_object *, void *);
192 static ndis_status NdisMAllocateSharedMemoryAsync(ndis_handle,
193 uint32_t, uint8_t, void *);
194 static void NdisMFreeSharedMemory(ndis_handle, uint32_t,
195 uint8_t, void *, ndis_physaddr);
196 static ndis_status NdisMMapIoSpace(void **, ndis_handle,
197 ndis_physaddr, uint32_t);
198 static void NdisMUnmapIoSpace(ndis_handle, void *, uint32_t);
199 static uint32_t NdisGetCacheFillSize(void);
200 static uint32_t NdisMGetDmaAlignment(ndis_handle);
201 static ndis_status NdisMInitializeScatterGatherDma(ndis_handle,
203 static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **);
204 static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **);
205 static void NdisAllocateBufferPool(ndis_status *,
206 ndis_handle *, uint32_t);
207 static void NdisFreeBufferPool(ndis_handle);
208 static void NdisAllocateBuffer(ndis_status *, ndis_buffer **,
209 ndis_handle, void *, uint32_t);
210 static void NdisFreeBuffer(ndis_buffer *);
211 static uint32_t NdisBufferLength(ndis_buffer *);
212 static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *);
213 static void NdisQueryBufferSafe(ndis_buffer *, void **,
214 uint32_t *, uint32_t);
215 static void *NdisBufferVirtualAddress(ndis_buffer *);
216 static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t);
217 static void NdisAdjustBufferLength(ndis_buffer *, int);
218 static uint32_t NdisInterlockedIncrement(uint32_t *);
219 static uint32_t NdisInterlockedDecrement(uint32_t *);
220 static void NdisInitializeEvent(ndis_event *);
221 static void NdisSetEvent(ndis_event *);
222 static void NdisResetEvent(ndis_event *);
223 static uint8_t NdisWaitEvent(ndis_event *, uint32_t);
224 static ndis_status NdisUnicodeStringToAnsiString(ansi_string *,
227 NdisAnsiStringToUnicodeString(unicode_string *, ansi_string *);
228 static ndis_status NdisMPciAssignResources(ndis_handle,
229 uint32_t, ndis_resource_list **);
230 static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *,
231 ndis_handle, uint32_t, uint32_t, uint8_t,
232 uint8_t, ndis_interrupt_mode);
233 static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *);
234 static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *,
235 ndis_shutdown_handler);
236 static void NdisMDeregisterAdapterShutdownHandler(ndis_handle);
237 static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *);
238 static void NdisGetBufferPhysicalArraySize(ndis_buffer *,
240 static void NdisQueryBufferOffset(ndis_buffer *,
241 uint32_t *, uint32_t *);
242 static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle,
243 uint32_t, void *, uint32_t);
244 static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle,
245 uint32_t, void *, uint32_t);
246 static list_entry *NdisInterlockedInsertHeadList(list_entry *,
247 list_entry *, ndis_spin_lock *);
248 static list_entry *NdisInterlockedRemoveHeadList(list_entry *,
250 static list_entry *NdisInterlockedInsertTailList(list_entry *,
251 list_entry *, ndis_spin_lock *);
253 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *,
255 static void NdisGetCurrentSystemTime(uint64_t *);
256 static void NdisGetSystemUpTime(uint32_t *);
257 static uint32_t NdisGetVersion(void);
258 static void NdisInitializeString(unicode_string *, char *);
259 static void NdisInitAnsiString(ansi_string *, char *);
260 static void NdisInitUnicodeString(unicode_string *, uint16_t *);
261 static void NdisFreeString(unicode_string *);
262 static ndis_status NdisMRemoveMiniport(ndis_handle *);
263 static void NdisTerminateWrapper(ndis_handle, void *);
264 static void NdisMGetDeviceProperty(ndis_handle, device_object **,
265 device_object **, device_object **, cm_resource_list *,
267 static void NdisGetFirstBufferFromPacket(ndis_packet *,
268 ndis_buffer **, void **, uint32_t *, uint32_t *);
269 static void NdisGetFirstBufferFromPacketSafe(ndis_packet *,
270 ndis_buffer **, void **, uint32_t *, uint32_t *, uint32_t);
271 static int ndis_find_sym(linker_file_t, char *, char *, caddr_t *);
272 static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *,
273 unicode_string *, ndis_physaddr);
274 static void NdisMapFile(ndis_status *, void **, ndis_handle);
275 static void NdisUnmapFile(ndis_handle);
276 static void NdisCloseFile(ndis_handle);
277 static uint8_t NdisSystemProcessorCount(void);
278 static void NdisGetCurrentProcessorCounts(uint32_t *, uint32_t *, uint32_t *);
279 static void NdisMIndicateStatusComplete(ndis_handle);
280 static void NdisMIndicateStatus(ndis_handle, ndis_status,
282 static uint8_t ndis_intr(kinterrupt *, void *);
283 static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *);
284 static funcptr ndis_findwrap(funcptr);
285 static void NdisCopyFromPacketToPacket(ndis_packet *,
286 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *);
287 static void NdisCopyFromPacketToPacketSafe(ndis_packet *,
288 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t);
289 static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *);
290 static ndis_status NdisMRegisterDevice(ndis_handle,
291 unicode_string *, unicode_string *, driver_dispatch **,
292 void **, ndis_handle *);
293 static ndis_status NdisMDeregisterDevice(ndis_handle);
295 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
296 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
297 static void dummy(void);
300 * Some really old drivers do not properly check the return value
301 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
302 * sometimes allocate few more buffers/packets that they originally
303 * requested when they created the pool. To prevent this from being
304 * a problem, we allocate a few extra buffers/packets beyond what
305 * the driver asks for. This #define controls how many.
307 #define NDIS_POOL_EXTRA 16
312 image_patch_table *patch;
314 strcpy(ndis_filepath, "/compat/ndis");
316 patch = ndis_functbl;
317 while (patch->ipt_func != NULL) {
318 windrv_wrap((funcptr)patch->ipt_func,
319 (funcptr *)&patch->ipt_wrap,
320 patch->ipt_argcnt, patch->ipt_ftype);
330 image_patch_table *patch;
332 patch = ndis_functbl;
333 while (patch->ipt_func != NULL) {
334 windrv_unwrap(patch->ipt_wrap);
345 image_patch_table *patch;
347 patch = ndis_functbl;
348 while (patch->ipt_func != NULL) {
349 if ((funcptr)patch->ipt_func == func)
350 return ((funcptr)patch->ipt_wrap);
358 * This routine does the messy Windows Driver Model device attachment
359 * stuff on behalf of NDIS drivers. We register our own AddDevice
363 NdisInitializeWrapper(wrapper, drv, path, unused)
364 ndis_handle *wrapper;
370 * As of yet, I haven't come up with a compelling
371 * reason to define a private NDIS wrapper structure,
372 * so we use a pointer to the driver object as the
373 * wrapper handle. The driver object has the miniport
374 * characteristics struct for this driver hung off it
375 * via IoAllocateDriverObjectExtension(), and that's
376 * really all the private data we need.
382 * If this was really Windows, we'd be registering dispatch
383 * routines for the NDIS miniport module here, but we're
384 * not Windows so all we really need to do is set up an
385 * AddDevice function that'll be invoked when a new device
389 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
393 NdisTerminateWrapper(handle, syspec)
397 /* Nothing to see here, move along. */
401 NdisMRegisterMiniport(handle, characteristics, len)
403 ndis_miniport_characteristics *characteristics;
406 ndis_miniport_characteristics *ch = NULL;
409 drv = (driver_object *)handle;
412 * We need to save the NDIS miniport characteristics
413 * somewhere. This data is per-driver, not per-device
414 * (all devices handled by the same driver have the
415 * same characteristics) so we hook it onto the driver
416 * object using IoAllocateDriverObjectExtension().
417 * The extra extension info is automagically deleted when
418 * the driver is unloaded (see windrv_unload()).
421 if (IoAllocateDriverObjectExtension(drv, (void *)1,
422 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
424 return (NDIS_STATUS_RESOURCES);
427 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
429 bcopy((char *)characteristics, (char *)ch, len);
431 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
432 ch->nmc_shutdown_handler = NULL;
433 ch->nmc_canceltxpkts_handler = NULL;
434 ch->nmc_pnpevent_handler = NULL;
437 return (NDIS_STATUS_SUCCESS);
441 NdisAllocateMemoryWithTag(vaddr, len, tag)
448 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
450 return (NDIS_STATUS_RESOURCES);
454 return (NDIS_STATUS_SUCCESS);
458 NdisAllocateMemory(vaddr, len, flags, highaddr)
462 ndis_physaddr highaddr;
466 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
468 return (NDIS_STATUS_RESOURCES);
471 return (NDIS_STATUS_SUCCESS);
475 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;
520 NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle)
523 unicode_string *subkey;
524 ndis_handle *subhandle;
527 *status = NDIS_STATUS_SUCCESS;
531 NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle)
535 unicode_string *subkey;
536 ndis_handle *subhandle;
538 *status = NDIS_STATUS_FAILURE;
542 ndis_encode_parm(block, oid, type, parm)
543 ndis_miniport_block *block;
544 struct sysctl_oid *oid;
546 ndis_config_parm **parm;
549 ndis_parmlist_entry *np;
556 np = ExAllocatePoolWithTag(NonPagedPool,
557 sizeof(ndis_parmlist_entry), 0);
559 return (NDIS_STATUS_RESOURCES);
560 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
561 *parm = p = &np->np_parm;
564 case ndis_parm_string:
565 /* See if this might be a number. */
566 val = strtoul((char *)oid->oid_arg1, NULL, 10);
567 us = &p->ncp_parmdata.ncp_stringdata;
568 p->ncp_type = ndis_parm_string;
570 snprintf(tmp, 32, "%x", val);
571 RtlInitAnsiString(&as, tmp);
573 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
576 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
578 return (NDIS_STATUS_RESOURCES);
582 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
586 p->ncp_type = ndis_parm_int;
587 p->ncp_parmdata.ncp_intdata =
588 strtol((char *)oid->oid_arg1, NULL, base);
590 case ndis_parm_hexint:
592 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
598 p->ncp_type = ndis_parm_hexint;
599 p->ncp_parmdata.ncp_intdata =
600 strtoul((char *)oid->oid_arg1, NULL, base);
603 return (NDIS_STATUS_FAILURE);
607 return (NDIS_STATUS_SUCCESS);
611 NdisReadConfiguration(status, parm, cfg, key, type)
613 ndis_config_parm **parm;
619 ndis_miniport_block *block;
620 struct ndis_softc *sc;
621 struct sysctl_oid *oidp;
622 struct sysctl_ctx_entry *e;
625 block = (ndis_miniport_block *)cfg;
626 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
628 if (key->us_len == 0 || key->us_buf == NULL) {
629 *status = NDIS_STATUS_FAILURE;
633 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
634 *status = NDIS_STATUS_RESOURCES;
641 * See if registry key is already in a list of known keys
642 * included with the driver.
644 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
646 if (strcasecmp(oidp->oid_name, keystr) == 0) {
647 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
648 RtlFreeAnsiString(&as);
649 *status = NDIS_STATUS_FAILURE;
653 *status = ndis_encode_parm(block, oidp, type, parm);
654 RtlFreeAnsiString(&as);
660 * If the key didn't match, add it to the list of dynamically
661 * created ones. Sometimes, drivers refer to registry keys
662 * that aren't documented in their .INF files. These keys
663 * are supposed to be created by some sort of utility or
664 * control panel snap-in that comes with the driver software.
665 * Sometimes it's useful to be able to manipulate these.
666 * If the driver requests the key in the form of a string,
667 * make its default value an empty string, otherwise default
671 if (type == ndis_parm_int || type == ndis_parm_hexint)
672 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
673 "UNSET", CTLFLAG_RW);
675 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
676 "UNSET", CTLFLAG_RW);
678 RtlFreeAnsiString(&as);
679 *status = NDIS_STATUS_FAILURE;
683 ndis_decode_parm(block, parm, val)
684 ndis_miniport_block *block;
685 ndis_config_parm *parm;
688 unicode_string *ustr;
691 switch(parm->ncp_type) {
692 case ndis_parm_string:
693 ustr = &parm->ncp_parmdata.ncp_stringdata;
694 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
695 return (NDIS_STATUS_RESOURCES);
696 bcopy(as.as_buf, val, as.as_len);
697 RtlFreeAnsiString(&as);
700 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
702 case ndis_parm_hexint:
703 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
706 return (NDIS_STATUS_FAILURE);
709 return (NDIS_STATUS_SUCCESS);
713 NdisWriteConfiguration(status, cfg, key, parm)
717 ndis_config_parm *parm;
721 ndis_miniport_block *block;
722 struct ndis_softc *sc;
723 struct sysctl_oid *oidp;
724 struct sysctl_ctx_entry *e;
727 block = (ndis_miniport_block *)cfg;
728 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
730 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
731 *status = NDIS_STATUS_RESOURCES;
737 /* Decode the parameter into a string. */
738 bzero(val, sizeof(val));
739 *status = ndis_decode_parm(block, parm, val);
740 if (*status != NDIS_STATUS_SUCCESS) {
741 RtlFreeAnsiString(&as);
745 /* See if the key already exists. */
747 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
749 if (strcasecmp(oidp->oid_name, keystr) == 0) {
750 /* Found it, set the value. */
751 strcpy((char *)oidp->oid_arg1, val);
752 RtlFreeAnsiString(&as);
757 /* Not found, add a new key with the specified value. */
758 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
761 RtlFreeAnsiString(&as);
762 *status = NDIS_STATUS_SUCCESS;
766 NdisCloseConfiguration(cfg)
770 ndis_parmlist_entry *pe;
771 ndis_miniport_block *block;
774 block = (ndis_miniport_block *)cfg;
776 while (!IsListEmpty(&block->nmb_parmlist)) {
777 e = RemoveHeadList(&block->nmb_parmlist);
778 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
780 if (p->ncp_type == ndis_parm_string)
781 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
787 * Initialize a Windows spinlock.
790 NdisAllocateSpinLock(lock)
791 ndis_spin_lock *lock;
793 KeInitializeSpinLock(&lock->nsl_spinlock);
798 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
799 * for this. One is that it's sort of superfluous: we don't have to do anything
800 * special to deallocate the spinlock. The other is that there are some buggy
801 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
802 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
806 NdisFreeSpinLock(lock)
807 ndis_spin_lock *lock;
810 KeInitializeSpinLock(&lock->nsl_spinlock);
816 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
820 NdisAcquireSpinLock(lock)
821 ndis_spin_lock *lock;
823 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
827 * Release a spinlock from IRQL == DISPATCH_LEVEL.
831 NdisReleaseSpinLock(lock)
832 ndis_spin_lock *lock;
834 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
838 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
841 NdisDprAcquireSpinLock(lock)
842 ndis_spin_lock *lock;
844 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
848 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
851 NdisDprReleaseSpinLock(lock)
852 ndis_spin_lock *lock;
854 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
858 NdisInitializeReadWriteLock(lock)
861 KeInitializeSpinLock(&lock->nrl_spinlock);
862 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
866 NdisAcquireReadWriteLock(ndis_rw_lock *lock, uint8_t writeacc,
867 ndis_lock_state *state)
869 if (writeacc == TRUE) {
870 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
877 NdisReleaseReadWriteLock(lock, state)
879 ndis_lock_state *state;
881 if (lock->nrl_rsvd[0]) {
883 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
889 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
896 ndis_miniport_block *block;
901 block = (ndis_miniport_block *)adapter;
906 dev = block->nmb_physdeviceobj->do_devext;
909 * I have a test system consisting of a Sun w2100z
910 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
911 * "Aries" miniPCI NIC. (The NIC is installed in the
912 * machine using a miniPCI to PCI bus adapter card.)
913 * When running in SMP mode, I found that
914 * performing a large number of consecutive calls to
915 * NdisReadPciSlotInformation() would result in a
916 * sudden system reset (or in some cases a freeze).
917 * My suspicion is that the multiple reads are somehow
918 * triggering a fatal PCI bus error that leads to a
919 * machine check. The 1us delay in the loop below
920 * seems to prevent this problem.
923 for (i = 0; i < len; i++) {
925 dest[i] = pci_read_config(dev, i + offset, 1);
932 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
939 ndis_miniport_block *block;
944 block = (ndis_miniport_block *)adapter;
950 dev = block->nmb_physdeviceobj->do_devext;
951 for (i = 0; i < len; i++) {
953 pci_write_config(dev, i + offset, dest[i], 1);
960 * The errorlog routine uses a variable argument list, so we
961 * have to declare it this way.
964 #define ERRMSGLEN 512
966 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
967 uint32_t numerrors, ...)
969 ndis_miniport_block *block;
976 struct ndis_softc *sc;
979 ansi_string as = { 0, 0, NULL };
981 block = (ndis_miniport_block *)adapter;
982 dev = block->nmb_physdeviceobj->do_devext;
983 drv = block->nmb_deviceobj->do_drvobj;
984 sc = device_get_softc(dev);
987 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
988 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
989 code, &str, &i, &flags);
991 if (flags & MESSAGE_RESOURCE_UNICODE) {
992 RtlInitUnicodeString(&us, (uint16_t *)str);
993 if (RtlUnicodeStringToAnsiString(&as,
994 &us, TRUE) == STATUS_SUCCESS)
1002 device_printf(dev, "NDIS ERROR: %x (%s)\n", code,
1003 str == NULL ? "unknown error" : str);
1005 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1006 device_printf(dev, "NDIS NUMERRORS: %x\n", numerrors);
1007 va_start(ap, numerrors);
1008 for (i = 0; i < numerrors; i++)
1009 device_printf(dev, "argptr: %p\n",
1010 va_arg(ap, void *));
1015 RtlFreeAnsiString(&as);
1019 ndis_map_cb(arg, segs, nseg, error)
1021 bus_dma_segment_t *segs;
1025 struct ndis_map_arg *ctx;
1033 for (i = 0; i < nseg; i++) {
1034 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1035 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1038 ctx->nma_cnt = nseg;
1042 NdisMStartBufferPhysicalMapping(ndis_handle adapter, ndis_buffer *buf,
1043 uint32_t mapreg, uint8_t writedev, ndis_paddr_unit *addrarray,
1044 uint32_t *arraysize)
1046 ndis_miniport_block *block;
1047 struct ndis_softc *sc;
1048 struct ndis_map_arg nma;
1052 if (adapter == NULL)
1055 block = (ndis_miniport_block *)adapter;
1056 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1058 if (mapreg > sc->ndis_mmapcnt)
1061 map = sc->ndis_mmaps[mapreg];
1062 nma.nma_fraglist = addrarray;
1064 error = bus_dmamap_load(sc->ndis_mtag, map,
1065 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1066 (void *)&nma, BUS_DMA_NOWAIT);
1071 bus_dmamap_sync(sc->ndis_mtag, map,
1072 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1074 *arraysize = nma.nma_cnt;
1078 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1079 ndis_handle adapter;
1083 ndis_miniport_block *block;
1084 struct ndis_softc *sc;
1087 if (adapter == NULL)
1090 block = (ndis_miniport_block *)adapter;
1091 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1093 if (mapreg > sc->ndis_mmapcnt)
1096 map = sc->ndis_mmaps[mapreg];
1098 bus_dmamap_sync(sc->ndis_mtag, map,
1099 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1101 bus_dmamap_unload(sc->ndis_mtag, map);
1105 * This is an older (?) timer init routine which doesn't
1106 * accept a miniport context handle. Serialized miniports should
1107 * never call this function.
1111 NdisInitializeTimer(timer, func, ctx)
1113 ndis_timer_function func;
1116 KeInitializeTimer(&timer->nt_ktimer);
1117 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1118 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1122 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1124 ndis_miniport_timer *timer;
1129 * Since we're called as a DPC, we should be running
1130 * at DISPATCH_LEVEL here. This means to acquire the
1131 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1132 * rather than KeAcquireSpinLock().
1134 if (NDIS_SERIALIZED(timer->nmt_block))
1135 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1137 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1140 if (NDIS_SERIALIZED(timer->nmt_block))
1141 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1145 * For a long time I wondered why there were two NDIS timer initialization
1146 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1147 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1148 * function and context pointers separate from those in the DPC, which
1149 * allows for another level of indirection: when the timer fires, we
1150 * can have our own timer function invoked, and from there we can call
1151 * the driver's function. But why go to all that trouble? Then it hit
1152 * me: for serialized miniports, the timer callouts are not re-entrant.
1153 * By trapping the callouts and having access to the MiniportAdapterHandle,
1154 * we can protect the driver callouts by acquiring the NDIS serialization
1155 * lock. This is essential for allowing serialized miniports to work
1156 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1157 * is enough to prevent other threads from pre-empting you, but with
1158 * SMP, you must acquire a lock as well, otherwise the other CPU is
1159 * free to clobber you.
1162 NdisMInitializeTimer(timer, handle, func, ctx)
1163 ndis_miniport_timer *timer;
1165 ndis_timer_function func;
1168 ndis_miniport_block *block;
1169 struct ndis_softc *sc;
1171 block = (ndis_miniport_block *)handle;
1172 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1174 /* Save the driver's funcptr and context */
1176 timer->nmt_timerfunc = func;
1177 timer->nmt_timerctx = ctx;
1178 timer->nmt_block = handle;
1181 * Set up the timer so it will call our intermediate DPC.
1182 * Be sure to use the wrapped entry point, since
1183 * ntoskrnl_run_dpc() expects to invoke a function with
1184 * Microsoft calling conventions.
1186 KeInitializeTimer(&timer->nmt_ktimer);
1187 KeInitializeDpc(&timer->nmt_kdpc,
1188 ndis_findwrap((funcptr)ndis_timercall), timer);
1189 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1193 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1194 * but the former is just a macro wrapper around the latter.
1197 NdisSetTimer(timer, msecs)
1202 * KeSetTimer() wants the period in
1203 * hundred nanosecond intervals.
1205 KeSetTimer(&timer->nt_ktimer,
1206 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1210 NdisMSetPeriodicTimer(timer, msecs)
1211 ndis_miniport_timer *timer;
1214 KeSetTimerEx(&timer->nmt_ktimer,
1215 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1219 * Technically, this is really NdisCancelTimer(), but we also
1220 * (ab)use it for NdisMCancelTimer(), since in our implementation
1221 * we don't need the extra info in the ndis_miniport_timer
1222 * structure just to cancel a timer.
1226 NdisMCancelTimer(timer, cancelled)
1231 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1235 NdisMQueryAdapterResources(status, adapter, list, buflen)
1236 ndis_status *status;
1237 ndis_handle adapter;
1238 ndis_resource_list *list;
1241 ndis_miniport_block *block;
1242 struct ndis_softc *sc;
1245 block = (ndis_miniport_block *)adapter;
1246 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1248 rsclen = sizeof(ndis_resource_list) +
1249 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1250 if (*buflen < rsclen) {
1252 *status = NDIS_STATUS_INVALID_LENGTH;
1256 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1257 *status = NDIS_STATUS_SUCCESS;
1261 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1263 ndis_handle adapter;
1267 struct ndis_miniport_block *block;
1268 struct ndis_softc *sc;
1270 if (adapter == NULL)
1271 return (NDIS_STATUS_FAILURE);
1273 block = (ndis_miniport_block *)adapter;
1274 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1276 if (sc->ndis_res_io == NULL)
1277 return (NDIS_STATUS_FAILURE);
1279 /* Don't let the device map more ports than we have. */
1280 if (rman_get_size(sc->ndis_res_io) < numports)
1281 return (NDIS_STATUS_INVALID_LENGTH);
1283 *offset = (void *)rman_get_start(sc->ndis_res_io);
1285 return (NDIS_STATUS_SUCCESS);
1289 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1290 ndis_handle adapter;
1298 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1299 ndis_status *status;
1302 ndis_handle adapter;
1304 struct ndis_softc *sc;
1305 ndis_miniport_block *block;
1306 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1308 block = (ndis_miniport_block *)adapter;
1309 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1310 if (sc->ifp == NULL) {
1311 *status = NDIS_STATUS_FAILURE;
1315 if (sc->ifp->if_addr == NULL ||
1316 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1317 *status = NDIS_STATUS_FAILURE;
1319 *addr = IF_LLADDR(sc->ifp);
1320 *addrlen = ETHER_ADDR_LEN;
1321 *status = NDIS_STATUS_SUCCESS;
1326 NdisQueryMapRegisterCount(bustype, cnt)
1331 return (NDIS_STATUS_SUCCESS);
1335 NdisMAllocateMapRegisters(ndis_handle adapter, uint32_t dmachannel,
1336 uint8_t dmasize, uint32_t physmapneeded, uint32_t maxmap)
1338 struct ndis_softc *sc;
1339 ndis_miniport_block *block;
1340 int error, i, nseg = NDIS_MAXSEG;
1342 block = (ndis_miniport_block *)adapter;
1343 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1345 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1346 M_DEVBUF, M_NOWAIT|M_ZERO);
1348 if (sc->ndis_mmaps == NULL)
1349 return (NDIS_STATUS_RESOURCES);
1351 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1352 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1353 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1354 NULL, NULL, &sc->ndis_mtag);
1357 free(sc->ndis_mmaps, M_DEVBUF);
1358 return (NDIS_STATUS_RESOURCES);
1361 for (i = 0; i < physmapneeded; i++)
1362 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1364 sc->ndis_mmapcnt = physmapneeded;
1366 return (NDIS_STATUS_SUCCESS);
1370 NdisMFreeMapRegisters(adapter)
1371 ndis_handle adapter;
1373 struct ndis_softc *sc;
1374 ndis_miniport_block *block;
1377 block = (ndis_miniport_block *)adapter;
1378 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1380 for (i = 0; i < sc->ndis_mmapcnt; i++)
1381 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1383 free(sc->ndis_mmaps, M_DEVBUF);
1385 bus_dma_tag_destroy(sc->ndis_mtag);
1389 ndis_mapshared_cb(arg, segs, nseg, error)
1391 bus_dma_segment_t *segs;
1397 if (error || nseg > 1)
1402 p->np_quad = segs[0].ds_addr;
1406 * This maps to bus_dmamem_alloc().
1410 NdisMAllocateSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1411 void **vaddr, ndis_physaddr *paddr)
1413 ndis_miniport_block *block;
1414 struct ndis_softc *sc;
1415 struct ndis_shmem *sh;
1418 if (adapter == NULL)
1421 block = (ndis_miniport_block *)adapter;
1422 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1424 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1428 InitializeListHead(&sh->ndis_list);
1431 * When performing shared memory allocations, create a tag
1432 * with a lowaddr limit that restricts physical memory mappings
1433 * so that they all fall within the first 1GB of memory.
1434 * At least one device/driver combination (Linksys Instant
1435 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1436 * problems with performing DMA operations with physical
1437 * addresses that lie above the 1GB mark. I don't know if this
1438 * is a hardware limitation or if the addresses are being
1439 * truncated within the driver, but this seems to be the only
1440 * way to make these cards work reliably in systems with more
1441 * than 1GB of physical memory.
1444 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1445 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1446 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1454 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1455 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1458 bus_dma_tag_destroy(sh->ndis_stag);
1463 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1464 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1467 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1468 bus_dma_tag_destroy(sh->ndis_stag);
1474 * Save the physical address along with the source address.
1475 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1476 * with a bogus virtual address sometimes, but with a valid
1477 * physical address. To keep this from causing trouble, we
1478 * use the physical address to as a sanity check in case
1479 * searching based on the virtual address fails.
1483 sh->ndis_paddr.np_quad = paddr->np_quad;
1484 sh->ndis_saddr = *vaddr;
1485 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1489 struct ndis_allocwork {
1497 ndis_asyncmem_complete(dobj, arg)
1498 device_object *dobj;
1501 ndis_miniport_block *block;
1502 struct ndis_softc *sc;
1503 struct ndis_allocwork *w;
1505 ndis_physaddr paddr;
1506 ndis_allocdone_handler donefunc;
1509 block = (ndis_miniport_block *)dobj->do_devext;
1510 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1515 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1516 NdisMAllocateSharedMemory(block, w->na_len,
1517 w->na_cached, &vaddr, &paddr);
1518 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1520 IoFreeWorkItem(w->na_iw);
1525 NdisMAllocateSharedMemoryAsync(ndis_handle adapter, uint32_t len,
1526 uint8_t cached, void *ctx)
1528 ndis_miniport_block *block;
1529 struct ndis_allocwork *w;
1531 io_workitem_func ifw;
1533 if (adapter == NULL)
1534 return (NDIS_STATUS_FAILURE);
1538 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1540 return (NDIS_STATUS_FAILURE);
1542 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1545 return (NDIS_STATUS_FAILURE);
1547 w->na_cached = cached;
1552 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1553 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1555 return (NDIS_STATUS_PENDING);
1559 NdisMFreeSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1560 void *vaddr, ndis_physaddr paddr)
1562 ndis_miniport_block *block;
1563 struct ndis_softc *sc;
1564 struct ndis_shmem *sh = NULL;
1567 if (vaddr == NULL || adapter == NULL)
1570 block = (ndis_miniport_block *)adapter;
1571 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1573 /* Sanity check: is list empty? */
1575 if (IsListEmpty(&sc->ndis_shlist))
1579 l = sc->ndis_shlist.nle_flink;
1580 while (l != &sc->ndis_shlist) {
1581 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1582 if (sh->ndis_saddr == vaddr)
1585 * Check the physaddr too, just in case the driver lied
1586 * about the virtual address.
1588 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1595 printf("NDIS: buggy driver tried to free "
1596 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1597 vaddr, (uintmax_t)paddr.np_quad);
1601 RemoveEntryList(&sh->ndis_list);
1605 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1606 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1607 bus_dma_tag_destroy(sh->ndis_stag);
1613 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1615 ndis_handle adapter;
1616 ndis_physaddr paddr;
1619 if (adapter == NULL)
1620 return (NDIS_STATUS_FAILURE);
1622 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1625 return (NDIS_STATUS_FAILURE);
1627 return (NDIS_STATUS_SUCCESS);
1631 NdisMUnmapIoSpace(adapter, vaddr, len)
1632 ndis_handle adapter;
1636 MmUnmapIoSpace(vaddr, len);
1640 NdisGetCacheFillSize(void)
1646 NdisMGetDmaAlignment(handle)
1653 * NDIS has two methods for dealing with NICs that support DMA.
1654 * One is to just pass packets to the driver and let it call
1655 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1656 * all by itself, and the other is to let the NDIS library handle the
1657 * buffer mapping internally, and hand the driver an already populated
1658 * scatter/gather fragment list. If the driver calls
1659 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1664 NdisMInitializeScatterGatherDma(ndis_handle adapter, uint8_t is64,
1665 uint32_t maxphysmap)
1667 struct ndis_softc *sc;
1668 ndis_miniport_block *block;
1671 if (adapter == NULL)
1672 return (NDIS_STATUS_FAILURE);
1673 block = (ndis_miniport_block *)adapter;
1674 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1676 /* Don't do this twice. */
1677 if (sc->ndis_sc == 1)
1678 return (NDIS_STATUS_SUCCESS);
1680 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1681 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1682 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1683 NULL, NULL, &sc->ndis_ttag);
1687 return (NDIS_STATUS_SUCCESS);
1691 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1692 ndis_status *status;
1695 uint32_t protrsvdlen;
1697 ndis_packet_pool *p;
1698 ndis_packet *packets;
1701 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1703 *status = NDIS_STATUS_RESOURCES;
1707 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1708 p->np_protrsvd = protrsvdlen;
1709 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1711 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1715 if (packets == NULL) {
1717 *status = NDIS_STATUS_RESOURCES;
1721 p->np_pktmem = packets;
1723 for (i = 0; i < p->np_cnt; i++)
1724 InterlockedPushEntrySList(&p->np_head,
1725 (struct slist_entry *)&packets[i]);
1727 #ifdef NDIS_DEBUG_PACKETS
1729 KeInitializeSpinLock(&p->np_lock);
1730 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1734 *status = NDIS_STATUS_SUCCESS;
1738 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1739 ndis_status *status;
1742 uint32_t oflowdescnum;
1743 uint32_t protrsvdlen;
1745 return (NdisAllocatePacketPool(status, pool,
1746 descnum + oflowdescnum, protrsvdlen));
1750 NdisPacketPoolUsage(pool)
1753 ndis_packet_pool *p;
1755 p = (ndis_packet_pool *)pool;
1756 return (p->np_cnt - ExQueryDepthSList(&p->np_head));
1760 NdisFreePacketPool(pool)
1763 ndis_packet_pool *p;
1765 #ifdef NDIS_DEBUG_PACKETS
1769 p = (ndis_packet_pool *)pool;
1771 #ifdef NDIS_DEBUG_PACKETS
1772 KeAcquireSpinLock(&p->np_lock, &irql);
1775 usage = NdisPacketPoolUsage(pool);
1777 #ifdef NDIS_DEBUG_PACKETS
1780 KeResetEvent(&p->np_event);
1781 KeReleaseSpinLock(&p->np_lock, irql);
1782 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1784 KeReleaseSpinLock(&p->np_lock, irql);
1787 ExFreePool(p->np_pktmem);
1792 NdisAllocatePacket(status, packet, pool)
1793 ndis_status *status;
1794 ndis_packet **packet;
1797 ndis_packet_pool *p;
1799 #ifdef NDIS_DEBUG_PACKETS
1803 p = (ndis_packet_pool *)pool;
1805 #ifdef NDIS_DEBUG_PACKETS
1806 KeAcquireSpinLock(&p->np_lock, &irql);
1808 KeReleaseSpinLock(&p->np_lock, irql);
1809 printf("NDIS: tried to allocate packet from dead pool %p\n",
1811 *status = NDIS_STATUS_RESOURCES;
1816 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1818 #ifdef NDIS_DEBUG_PACKETS
1819 KeReleaseSpinLock(&p->np_lock, irql);
1823 *status = NDIS_STATUS_RESOURCES;
1828 bzero((char *)pkt, sizeof(ndis_packet));
1830 /* Save pointer to the pool. */
1831 pkt->np_private.npp_pool = pool;
1833 /* Set the oob offset pointer. Lots of things expect this. */
1834 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1837 * We must initialize the packet flags correctly in order
1838 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1839 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1842 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1843 pkt->np_private.npp_validcounts = FALSE;
1847 *status = NDIS_STATUS_SUCCESS;
1851 NdisFreePacket(packet)
1852 ndis_packet *packet;
1854 ndis_packet_pool *p;
1855 #ifdef NDIS_DEBUG_PACKETS
1859 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1861 #ifdef NDIS_DEBUG_PACKETS
1862 KeAcquireSpinLock(&p->np_lock, &irql);
1865 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1867 #ifdef NDIS_DEBUG_PACKETS
1869 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1870 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1872 KeReleaseSpinLock(&p->np_lock, irql);
1877 NdisUnchainBufferAtFront(packet, buf)
1878 ndis_packet *packet;
1881 ndis_packet_private *priv;
1883 if (packet == NULL || buf == NULL)
1886 priv = &packet->np_private;
1888 priv->npp_validcounts = FALSE;
1890 if (priv->npp_head == priv->npp_tail) {
1891 *buf = priv->npp_head;
1892 priv->npp_head = priv->npp_tail = NULL;
1894 *buf = priv->npp_head;
1895 priv->npp_head = (*buf)->mdl_next;
1900 NdisUnchainBufferAtBack(packet, buf)
1901 ndis_packet *packet;
1904 ndis_packet_private *priv;
1907 if (packet == NULL || buf == NULL)
1910 priv = &packet->np_private;
1912 priv->npp_validcounts = FALSE;
1914 if (priv->npp_head == priv->npp_tail) {
1915 *buf = priv->npp_head;
1916 priv->npp_head = priv->npp_tail = NULL;
1918 *buf = priv->npp_tail;
1919 tmp = priv->npp_head;
1920 while (tmp->mdl_next != priv->npp_tail)
1921 tmp = tmp->mdl_next;
1922 priv->npp_tail = tmp;
1923 tmp->mdl_next = NULL;
1928 * The NDIS "buffer" is really an MDL (memory descriptor list)
1929 * which is used to describe a buffer in a way that allows it
1930 * to mapped into different contexts. We have to be careful how
1931 * we handle them: in some versions of Windows, the NdisFreeBuffer()
1932 * routine is an actual function in the NDIS API, but in others
1933 * it's just a macro wrapper around IoFreeMdl(). There's really
1934 * no way to use the 'descnum' parameter to count how many
1935 * "buffers" are allocated since in order to use IoFreeMdl() to
1936 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
1937 * them, and IoAllocateMdl() just grabs them out of the heap.
1941 NdisAllocateBufferPool(status, pool, descnum)
1942 ndis_status *status;
1948 * The only thing we can really do here is verify that descnum
1949 * is a reasonable value, but I really don't know what to check
1953 *pool = NonPagedPool;
1954 *status = NDIS_STATUS_SUCCESS;
1958 NdisFreeBufferPool(pool)
1964 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
1965 ndis_status *status;
1966 ndis_buffer **buffer;
1973 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
1975 *status = NDIS_STATUS_RESOURCES;
1979 MmBuildMdlForNonPagedPool(buf);
1982 *status = NDIS_STATUS_SUCCESS;
1995 NdisBufferLength(buf)
1998 return (MmGetMdlByteCount(buf));
2002 * Get the virtual address and length of a buffer.
2003 * Note: the vaddr argument is optional.
2007 NdisQueryBuffer(buf, vaddr, len)
2013 *vaddr = MmGetMdlVirtualAddress(buf);
2014 *len = MmGetMdlByteCount(buf);
2017 /* Same as above -- we don't care about the priority. */
2020 NdisQueryBufferSafe(buf, vaddr, len, prio)
2027 *vaddr = MmGetMdlVirtualAddress(buf);
2028 *len = MmGetMdlByteCount(buf);
2031 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2034 NdisBufferVirtualAddress(buf)
2037 return (MmGetMdlVirtualAddress(buf));
2041 NdisBufferVirtualAddressSafe(buf, prio)
2045 return (MmGetMdlVirtualAddress(buf));
2049 NdisAdjustBufferLength(buf, len)
2053 MmGetMdlByteCount(buf) = len;
2057 NdisInterlockedIncrement(addend)
2060 atomic_add_long((u_long *)addend, 1);
2065 NdisInterlockedDecrement(addend)
2068 atomic_subtract_long((u_long *)addend, 1);
2073 NdisGetVersion(void)
2075 return (0x00050001);
2079 NdisInitializeEvent(event)
2083 * NDIS events are always notification
2084 * events, and should be initialized to the
2085 * not signaled state.
2087 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2094 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2098 NdisResetEvent(event)
2101 KeResetEvent(&event->ne_event);
2105 NdisWaitEvent(event, msecs)
2112 duetime = ((int64_t)msecs * -10000);
2113 rval = KeWaitForSingleObject(event,
2114 0, 0, TRUE, msecs ? & duetime : NULL);
2116 if (rval == STATUS_TIMEOUT)
2123 NdisUnicodeStringToAnsiString(dstr, sstr)
2125 unicode_string *sstr;
2129 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2131 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2132 return (NDIS_STATUS_RESOURCES);
2134 return (NDIS_STATUS_FAILURE);
2136 return (NDIS_STATUS_SUCCESS);
2140 NdisAnsiStringToUnicodeString(dstr, sstr)
2141 unicode_string *dstr;
2146 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2148 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2149 return (NDIS_STATUS_RESOURCES);
2151 return (NDIS_STATUS_FAILURE);
2153 return (NDIS_STATUS_SUCCESS);
2157 NdisMPciAssignResources(adapter, slot, list)
2158 ndis_handle adapter;
2160 ndis_resource_list **list;
2162 ndis_miniport_block *block;
2164 if (adapter == NULL || list == NULL)
2165 return (NDIS_STATUS_FAILURE);
2167 block = (ndis_miniport_block *)adapter;
2168 *list = block->nmb_rlist;
2170 return (NDIS_STATUS_SUCCESS);
2174 ndis_intr(iobj, arg)
2178 struct ndis_softc *sc;
2179 uint8_t is_our_intr = FALSE;
2181 ndis_miniport_interrupt *intr;
2184 intr = sc->ndis_block->nmb_interrupt;
2186 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2189 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2190 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2191 sc->ndis_block->nmb_miniportadapterctx);
2193 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2194 sc->ndis_block->nmb_miniportadapterctx);
2199 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2201 return (is_our_intr);
2205 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2207 ndis_miniport_interrupt *intr;
2211 struct ndis_softc *sc;
2212 ndis_miniport_block *block;
2213 ndis_handle adapter;
2215 block = intr->ni_block;
2216 adapter = block->nmb_miniportadapterctx;
2217 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2219 if (NDIS_SERIALIZED(sc->ndis_block))
2220 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2222 MSCALL1(intr->ni_dpcfunc, adapter);
2224 /* If there's a MiniportEnableInterrupt() routine, call it. */
2226 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2227 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2229 if (NDIS_SERIALIZED(sc->ndis_block))
2230 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2233 * Set the completion event if we've drained all
2234 * pending interrupts.
2237 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2239 if (intr->ni_dpccnt == 0)
2240 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2241 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2245 NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter,
2246 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared,
2247 ndis_interrupt_mode imode)
2249 ndis_miniport_block *block;
2250 ndis_miniport_characteristics *ch;
2251 struct ndis_softc *sc;
2255 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2256 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2259 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2260 sizeof(struct mtx), 0);
2261 if (intr->ni_rsvd == NULL)
2262 return (NDIS_STATUS_RESOURCES);
2264 intr->ni_block = adapter;
2265 intr->ni_isrreq = reqisr;
2266 intr->ni_shared = shared;
2267 intr->ni_dpccnt = 0;
2268 intr->ni_isrfunc = ch->nmc_isr_func;
2269 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2271 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2272 KeInitializeDpc(&intr->ni_dpc,
2273 ndis_findwrap((funcptr)ndis_intrhand), intr);
2274 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2276 error = IoConnectInterrupt(&intr->ni_introbj,
2277 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2278 ivec, ilevel, 0, imode, shared, 0, FALSE);
2280 if (error != STATUS_SUCCESS)
2281 return (NDIS_STATUS_FAILURE);
2283 block->nmb_interrupt = intr;
2285 return (NDIS_STATUS_SUCCESS);
2289 NdisMDeregisterInterrupt(intr)
2290 ndis_miniport_interrupt *intr;
2292 ndis_miniport_block *block;
2295 block = intr->ni_block;
2297 /* Should really be KeSynchronizeExecution() */
2299 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2300 block->nmb_interrupt = NULL;
2301 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2303 KeFlushQueuedDpcs();
2305 /* Disconnect our ISR */
2307 IoDisconnectInterrupt(intr->ni_introbj);
2309 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2310 KeResetEvent(&intr->ni_dpcevt);
2314 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2315 ndis_handle adapter;
2317 ndis_shutdown_handler shutdownfunc;
2319 ndis_miniport_block *block;
2320 ndis_miniport_characteristics *chars;
2321 struct ndis_softc *sc;
2323 if (adapter == NULL)
2326 block = (ndis_miniport_block *)adapter;
2327 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2328 chars = sc->ndis_chars;
2330 chars->nmc_shutdown_handler = shutdownfunc;
2331 chars->nmc_rsvd0 = shutdownctx;
2335 NdisMDeregisterAdapterShutdownHandler(adapter)
2336 ndis_handle adapter;
2338 ndis_miniport_block *block;
2339 ndis_miniport_characteristics *chars;
2340 struct ndis_softc *sc;
2342 if (adapter == NULL)
2345 block = (ndis_miniport_block *)adapter;
2346 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2347 chars = sc->ndis_chars;
2349 chars->nmc_shutdown_handler = NULL;
2350 chars->nmc_rsvd0 = NULL;
2354 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2359 if (MmGetMdlByteCount(buf) == 0)
2361 return (SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2362 MmGetMdlByteCount(buf)));
2366 NdisGetBufferPhysicalArraySize(buf, pages)
2373 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2377 NdisQueryBufferOffset(buf, off, len)
2385 *off = MmGetMdlByteOffset(buf);
2386 *len = MmGetMdlByteCount(buf);
2396 * During system bootstrap, (i.e. cold == 1), we aren't
2397 * allowed to sleep, so we have to do a hard DELAY()
2404 KeInitializeTimer(&timer);
2405 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2406 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2411 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2417 struct ndis_softc *sc;
2418 ndis_miniport_block *block;
2419 bus_space_handle_t bh;
2427 block = (ndis_miniport_block *)handle;
2428 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2431 bh = rman_get_bushandle(sc->ndis_res_am);
2432 bt = rman_get_bustag(sc->ndis_res_am);
2434 for (i = 0; i < len; i++)
2435 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2441 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2447 struct ndis_softc *sc;
2448 ndis_miniport_block *block;
2449 bus_space_handle_t bh;
2457 block = (ndis_miniport_block *)handle;
2458 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2461 bh = rman_get_bushandle(sc->ndis_res_am);
2462 bt = rman_get_bustag(sc->ndis_res_am);
2464 for (i = 0; i < len; i++)
2465 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2471 NdisInterlockedInsertHeadList(head, entry, lock)
2474 ndis_spin_lock *lock;
2478 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2479 flink = head->nle_flink;
2480 entry->nle_flink = flink;
2481 entry->nle_blink = head;
2482 flink->nle_blink = entry;
2483 head->nle_flink = entry;
2484 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2490 NdisInterlockedRemoveHeadList(head, lock)
2492 ndis_spin_lock *lock;
2497 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2498 entry = head->nle_flink;
2499 flink = entry->nle_flink;
2500 head->nle_flink = flink;
2501 flink->nle_blink = head;
2502 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2508 NdisInterlockedInsertTailList(head, entry, lock)
2511 ndis_spin_lock *lock;
2515 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2516 blink = head->nle_blink;
2517 entry->nle_flink = head;
2518 entry->nle_blink = blink;
2519 blink->nle_flink = entry;
2520 head->nle_blink = entry;
2521 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2527 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2528 ndis_miniport_interrupt *intr;
2532 return (KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2536 NdisGetCurrentSystemTime(tval)
2539 ntoskrnl_time(tval);
2543 * Return the number of milliseconds since the system booted.
2546 NdisGetSystemUpTime(tval)
2552 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2556 NdisInitializeString(dst, src)
2557 unicode_string *dst;
2561 RtlInitAnsiString(&as, src);
2562 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2567 unicode_string *str;
2569 RtlFreeUnicodeString(str);
2573 NdisMRemoveMiniport(adapter)
2574 ndis_handle *adapter;
2576 return (NDIS_STATUS_SUCCESS);
2580 NdisInitAnsiString(dst, src)
2584 RtlInitAnsiString(dst, src);
2588 NdisInitUnicodeString(dst, src)
2589 unicode_string *dst;
2592 RtlInitUnicodeString(dst, src);
2595 static void NdisMGetDeviceProperty(adapter, phydevobj,
2596 funcdevobj, nextdevobj, resources, transresources)
2597 ndis_handle adapter;
2598 device_object **phydevobj;
2599 device_object **funcdevobj;
2600 device_object **nextdevobj;
2601 cm_resource_list *resources;
2602 cm_resource_list *transresources;
2604 ndis_miniport_block *block;
2606 block = (ndis_miniport_block *)adapter;
2608 if (phydevobj != NULL)
2609 *phydevobj = block->nmb_physdeviceobj;
2610 if (funcdevobj != NULL)
2611 *funcdevobj = block->nmb_deviceobj;
2612 if (nextdevobj != NULL)
2613 *nextdevobj = block->nmb_nextdeviceobj;
2617 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2618 ndis_packet *packet;
2626 tmp = packet->np_private.npp_head;
2630 *firstlen = *totlen = 0;
2632 *firstva = MmGetMdlVirtualAddress(tmp);
2633 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2634 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2635 *totlen += MmGetMdlByteCount(tmp);
2640 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2641 ndis_packet *packet;
2648 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2652 ndis_find_sym(lf, filename, suffix, sym)
2662 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2663 if (fullsym == NULL)
2666 bzero(fullsym, MAXPATHLEN);
2667 strncpy(fullsym, filename, MAXPATHLEN);
2668 if (strlen(filename) < 4) {
2669 ExFreePool(fullsym);
2673 /* If the filename has a .ko suffix, strip if off. */
2674 suf = fullsym + (strlen(filename) - 3);
2675 if (strcmp(suf, ".ko") == 0)
2678 for (i = 0; i < strlen(fullsym); i++) {
2679 if (fullsym[i] == '.')
2682 fullsym[i] = tolower(fullsym[i]);
2684 strcat(fullsym, suffix);
2685 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2686 ExFreePool(fullsym);
2693 struct ndis_checkmodule {
2699 * See if a single module contains the symbols for a specified file.
2702 NdisCheckModule(linker_file_t lf, void *context)
2704 struct ndis_checkmodule *nc;
2705 caddr_t kldstart, kldend;
2707 nc = (struct ndis_checkmodule *)context;
2708 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2710 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2713 nc->fh->nf_map = NULL;
2714 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2715 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2719 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2721 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2722 ndis_status *status;
2723 ndis_handle *filehandle;
2724 uint32_t *filelength;
2725 unicode_string *filename;
2726 ndis_physaddr highestaddr;
2729 char *afilename = NULL;
2730 struct thread *td = curthread;
2731 struct nameidata nd;
2732 int flags, error, vfslocked;
2734 struct vattr *vap = &vat;
2737 struct ndis_checkmodule nc;
2739 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2740 *status = NDIS_STATUS_RESOURCES;
2744 afilename = strdup(as.as_buf, M_DEVBUF);
2745 RtlFreeAnsiString(&as);
2747 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2749 free(afilename, M_DEVBUF);
2750 *status = NDIS_STATUS_RESOURCES;
2754 fh->nf_name = afilename;
2757 * During system bootstrap, it's impossible to load files
2758 * from the rootfs since it's not mounted yet. We therefore
2759 * offer the possibility of opening files that have been
2760 * preloaded as modules instead. Both choices will work
2761 * when kldloading a module from multiuser, but only the
2762 * module option will work during bootstrap. The module
2763 * loading option works by using the ndiscvt(8) utility
2764 * to convert the arbitrary file into a .ko using objcopy(1).
2765 * This file will contain two special symbols: filename_start
2766 * and filename_end. All we have to do is traverse the KLD
2767 * list in search of those symbols and we've found the file
2768 * data. As an added bonus, ndiscvt(8) will also generate
2769 * a normal .o file which can be linked statically with
2770 * the kernel. This means that the symbols will actual reside
2771 * in the kernel's symbol table, but that doesn't matter to
2772 * us since the kernel appears to us as just another module.
2775 nc.afilename = afilename;
2777 if (linker_file_foreach(NdisCheckModule, &nc)) {
2778 *filelength = fh->nf_maplen;
2780 *status = NDIS_STATUS_SUCCESS;
2784 if (TAILQ_EMPTY(&mountlist)) {
2786 *status = NDIS_STATUS_FILE_NOT_FOUND;
2787 printf("NDIS: could not find file %s in linker list\n",
2789 printf("NDIS: and no filesystems mounted yet, "
2790 "aborting NdisOpenFile()\n");
2791 free(afilename, M_DEVBUF);
2795 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2798 free(afilename, M_DEVBUF);
2799 *status = NDIS_STATUS_RESOURCES;
2803 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2805 /* Some threads don't have a current working directory. */
2807 if (td->td_proc->p_fd->fd_rdir == NULL)
2808 td->td_proc->p_fd->fd_rdir = rootvnode;
2809 if (td->td_proc->p_fd->fd_cdir == NULL)
2810 td->td_proc->p_fd->fd_cdir = rootvnode;
2812 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td);
2815 error = vn_open(&nd, &flags, 0, NULL);
2817 *status = NDIS_STATUS_FILE_NOT_FOUND;
2819 printf("NDIS: open file %s failed: %d\n", path, error);
2821 free(afilename, M_DEVBUF);
2824 vfslocked = NDHASGIANT(&nd);
2828 NDFREE(&nd, NDF_ONLY_PNBUF);
2830 /* Get the file size. */
2831 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred);
2832 VOP_UNLOCK(nd.ni_vp, 0);
2833 VFS_UNLOCK_GIANT(vfslocked);
2835 fh->nf_vp = nd.ni_vp;
2837 fh->nf_type = NDIS_FH_TYPE_VFS;
2839 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2840 *status = NDIS_STATUS_SUCCESS;
2844 NdisMapFile(status, mappedbuffer, filehandle)
2845 ndis_status *status;
2846 void **mappedbuffer;
2847 ndis_handle filehandle;
2850 struct thread *td = curthread;
2853 int error, resid, vfslocked;
2856 if (filehandle == NULL) {
2857 *status = NDIS_STATUS_FAILURE;
2861 fh = (ndis_fh *)filehandle;
2863 if (fh->nf_vp == NULL) {
2864 *status = NDIS_STATUS_FAILURE;
2868 if (fh->nf_map != NULL) {
2869 *status = NDIS_STATUS_ALREADY_MAPPED;
2873 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
2875 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
2876 *status = NDIS_STATUS_FAILURE;
2879 fh->nf_map = kldstart;
2880 *status = NDIS_STATUS_SUCCESS;
2881 *mappedbuffer = fh->nf_map;
2885 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
2887 if (fh->nf_map == NULL) {
2888 *status = NDIS_STATUS_RESOURCES;
2893 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2894 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
2895 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
2896 VFS_UNLOCK_GIANT(vfslocked);
2899 *status = NDIS_STATUS_FAILURE;
2901 *status = NDIS_STATUS_SUCCESS;
2902 *mappedbuffer = fh->nf_map;
2907 NdisUnmapFile(filehandle)
2908 ndis_handle filehandle;
2911 fh = (ndis_fh *)filehandle;
2913 if (fh->nf_map == NULL)
2916 if (fh->nf_type == NDIS_FH_TYPE_VFS)
2917 ExFreePool(fh->nf_map);
2922 NdisCloseFile(filehandle)
2923 ndis_handle filehandle;
2925 struct thread *td = curthread;
2930 if (filehandle == NULL)
2933 fh = (ndis_fh *)filehandle;
2934 if (fh->nf_map != NULL) {
2935 if (fh->nf_type == NDIS_FH_TYPE_VFS)
2936 ExFreePool(fh->nf_map);
2940 if (fh->nf_vp == NULL)
2943 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
2945 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2946 vn_close(vp, FREAD, td->td_ucred, td);
2947 VFS_UNLOCK_GIANT(vfslocked);
2951 free(fh->nf_name, M_DEVBUF);
2956 NdisSystemProcessorCount()
2962 NdisGetCurrentProcessorCounts(idle_count, kernel_and_user, index)
2963 uint32_t *idle_count;
2964 uint32_t *kernel_and_user;
2969 pcpu = pcpu_find(curthread->td_oncpu);
2970 *index = pcpu->pc_cpuid;
2971 *idle_count = pcpu->pc_cp_time[CP_IDLE];
2972 *kernel_and_user = pcpu->pc_cp_time[CP_INTR];
2975 typedef void (*ndis_statusdone_handler)(ndis_handle);
2976 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
2980 NdisMIndicateStatusComplete(adapter)
2981 ndis_handle adapter;
2983 ndis_miniport_block *block;
2984 ndis_statusdone_handler statusdonefunc;
2986 block = (ndis_miniport_block *)adapter;
2987 statusdonefunc = block->nmb_statusdone_func;
2989 MSCALL1(statusdonefunc, adapter);
2993 NdisMIndicateStatus(adapter, status, sbuf, slen)
2994 ndis_handle adapter;
2999 ndis_miniport_block *block;
3000 ndis_status_handler statusfunc;
3002 block = (ndis_miniport_block *)adapter;
3003 statusfunc = block->nmb_status_func;
3005 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3009 * The DDK documentation says that you should use IoQueueWorkItem()
3010 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3011 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3012 * depends on the API semantics of ExQueueWorkItem(). In our world,
3013 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3016 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3017 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3018 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3019 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3020 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3021 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3022 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3023 * to ExQueueWorkItem().
3025 * Got all that? (Sheesh.)
3029 NdisScheduleWorkItem(work)
3030 ndis_work_item *work;
3032 work_queue_item *wqi;
3034 wqi = (work_queue_item *)work->nwi_wraprsvd;
3035 ExInitializeWorkItem(wqi,
3036 (work_item_func)work->nwi_func, work->nwi_ctx);
3037 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3039 return (NDIS_STATUS_SUCCESS);
3043 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3051 ndis_buffer *src, *dst;
3053 int resid, copied, len, scnt, dcnt;
3057 src = spkt->np_private.npp_head;
3058 dst = dpkt->np_private.npp_head;
3060 sptr = MmGetMdlVirtualAddress(src);
3061 dptr = MmGetMdlVirtualAddress(dst);
3062 scnt = MmGetMdlByteCount(src);
3063 dcnt = MmGetMdlByteCount(dst);
3066 if (MmGetMdlByteCount(src) > soff) {
3068 scnt = MmGetMdlByteCount(src)- soff;
3071 soff -= MmGetMdlByteCount(src);
3072 src = src->mdl_next;
3075 sptr = MmGetMdlVirtualAddress(src);
3079 if (MmGetMdlByteCount(dst) > doff) {
3081 dcnt = MmGetMdlByteCount(dst) - doff;
3084 doff -= MmGetMdlByteCount(dst);
3085 dst = dst->mdl_next;
3088 dptr = MmGetMdlVirtualAddress(dst);
3102 bcopy(sptr, dptr, len);
3111 dst = dst->mdl_next;
3114 dptr = MmGetMdlVirtualAddress(dst);
3115 dcnt = MmGetMdlByteCount(dst);
3120 src = src->mdl_next;
3123 sptr = MmGetMdlVirtualAddress(src);
3124 scnt = MmGetMdlByteCount(src);
3132 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3141 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3145 NdisIMCopySendPerPacketInfo(dpkt, spkt)
3149 memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension));
3153 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3155 unicode_string *devname;
3156 unicode_string *symname;
3157 driver_dispatch *majorfuncs[];
3159 ndis_handle *devhandle;
3162 device_object *dobj;
3164 status = IoCreateDevice(handle, 0, devname,
3165 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3167 if (status == STATUS_SUCCESS) {
3176 NdisMDeregisterDevice(handle)
3179 IoDeleteDevice(handle);
3180 return (NDIS_STATUS_SUCCESS);
3184 NdisMQueryAdapterInstanceName(name, handle)
3185 unicode_string *name;
3188 ndis_miniport_block *block;
3192 block = (ndis_miniport_block *)handle;
3193 dev = block->nmb_physdeviceobj->do_devext;
3195 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3196 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3197 return (NDIS_STATUS_RESOURCES);
3199 return (NDIS_STATUS_SUCCESS);
3203 NdisMRegisterUnloadHandler(handle, func)
3212 printf("NDIS dummy called...\n");
3216 * Note: a couple of entries in this table specify the
3217 * number of arguments as "foo + 1". These are routines
3218 * that accept a 64-bit argument, passed by value. On
3219 * x86, these arguments consume two longwords on the stack,
3220 * so we lie and say there's one additional argument so
3221 * that the wrapping routines will do the right thing.
3224 image_patch_table ndis_functbl[] = {
3225 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3226 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3227 IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2),
3228 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3229 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3230 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3231 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3232 IMPORT_SFUNC(NdisGetCurrentProcessorCounts, 3),
3233 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3234 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3235 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3236 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3237 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3238 IMPORT_SFUNC(NdisInitAnsiString, 2),
3239 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3240 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3241 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3242 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3243 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3244 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3245 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3246 IMPORT_SFUNC(NdisInitializeString, 2),
3247 IMPORT_SFUNC(NdisFreeString, 1),
3248 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3249 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3250 IMPORT_SFUNC(NdisGetVersion, 0),
3251 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3252 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3253 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3254 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3255 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3256 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3257 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3258 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3259 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3260 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3261 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3262 IMPORT_SFUNC(NdisReadConfiguration, 5),
3263 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3264 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3265 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3266 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3267 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3268 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3269 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3270 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3271 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3272 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3273 IMPORT_SFUNC(NdisFreeMemory, 3),
3274 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3275 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3276 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3277 NdisReadPciSlotInformation, 5),
3278 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3279 NdisWritePciSlotInformation, 5),
3280 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3281 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3282 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3283 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3284 IMPORT_SFUNC(NdisInitializeTimer, 3),
3285 IMPORT_SFUNC(NdisSetTimer, 2),
3286 IMPORT_SFUNC(NdisMCancelTimer, 2),
3287 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3288 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3289 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3290 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3291 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3292 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3293 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3294 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3295 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3296 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3297 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3298 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3299 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3300 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3301 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3302 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3303 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3304 IMPORT_SFUNC(NdisAllocatePacket, 3),
3305 IMPORT_SFUNC(NdisFreePacket, 1),
3306 IMPORT_SFUNC(NdisFreePacketPool, 1),
3307 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3308 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3309 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3310 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3311 IMPORT_SFUNC(NdisQueryBuffer, 3),
3312 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3313 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3314 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3315 IMPORT_SFUNC(NdisBufferLength, 1),
3316 IMPORT_SFUNC(NdisFreeBuffer, 1),
3317 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3318 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3319 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3320 IMPORT_SFUNC(NdisInitializeEvent, 1),
3321 IMPORT_SFUNC(NdisSetEvent, 1),
3322 IMPORT_SFUNC(NdisResetEvent, 1),
3323 IMPORT_SFUNC(NdisWaitEvent, 2),
3324 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3325 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3326 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3327 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3328 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3329 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3330 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3331 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3332 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3333 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3334 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3335 IMPORT_SFUNC(NdisMSleep, 1),
3336 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3337 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3338 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3339 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3340 IMPORT_SFUNC(NdisMapFile, 3),
3341 IMPORT_SFUNC(NdisUnmapFile, 1),
3342 IMPORT_SFUNC(NdisCloseFile, 1),
3343 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3344 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3345 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3346 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3347 IMPORT_SFUNC(ndis_timercall, 4),
3348 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3349 IMPORT_SFUNC(ndis_intr, 2),
3350 IMPORT_SFUNC(ndis_intrhand, 4),
3353 * This last entry is a catch-all for any function we haven't
3354 * implemented yet. The PE import list patching routine will
3355 * use it for any function that doesn't have an explicit match
3359 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3363 { NULL, NULL, NULL }