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 void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *);
286 static ndis_status NdisMRegisterDevice(ndis_handle,
287 unicode_string *, unicode_string *, driver_dispatch **,
288 void **, ndis_handle *);
289 static ndis_status NdisMDeregisterDevice(ndis_handle);
291 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
292 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
293 static void dummy(void);
296 * Some really old drivers do not properly check the return value
297 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
298 * sometimes allocate few more buffers/packets that they originally
299 * requested when they created the pool. To prevent this from being
300 * a problem, we allocate a few extra buffers/packets beyond what
301 * the driver asks for. This #define controls how many.
303 #define NDIS_POOL_EXTRA 16
308 image_patch_table *patch;
310 strcpy(ndis_filepath, "/compat/ndis");
312 patch = ndis_functbl;
313 while (patch->ipt_func != NULL) {
314 windrv_wrap((funcptr)patch->ipt_func,
315 (funcptr *)&patch->ipt_wrap,
316 patch->ipt_argcnt, patch->ipt_ftype);
326 image_patch_table *patch;
328 patch = ndis_functbl;
329 while (patch->ipt_func != NULL) {
330 windrv_unwrap(patch->ipt_wrap);
341 image_patch_table *patch;
343 patch = ndis_functbl;
344 while (patch->ipt_func != NULL) {
345 if ((funcptr)patch->ipt_func == func)
346 return((funcptr)patch->ipt_wrap);
354 * This routine does the messy Windows Driver Model device attachment
355 * stuff on behalf of NDIS drivers. We register our own AddDevice
359 NdisInitializeWrapper(wrapper, drv, path, unused)
360 ndis_handle *wrapper;
366 * As of yet, I haven't come up with a compelling
367 * reason to define a private NDIS wrapper structure,
368 * so we use a pointer to the driver object as the
369 * wrapper handle. The driver object has the miniport
370 * characteristics struct for this driver hung off it
371 * via IoAllocateDriverObjectExtension(), and that's
372 * really all the private data we need.
378 * If this was really Windows, we'd be registering dispatch
379 * routines for the NDIS miniport module here, but we're
380 * not Windows so all we really need to do is set up an
381 * AddDevice function that'll be invoked when a new device
385 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
391 NdisTerminateWrapper(handle, syspec)
395 /* Nothing to see here, move along. */
400 NdisMRegisterMiniport(handle, characteristics, len)
402 ndis_miniport_characteristics *characteristics;
405 ndis_miniport_characteristics *ch = NULL;
408 drv = (driver_object *)handle;
411 * We need to save the NDIS miniport characteristics
412 * somewhere. This data is per-driver, not per-device
413 * (all devices handled by the same driver have the
414 * same characteristics) so we hook it onto the driver
415 * object using IoAllocateDriverObjectExtension().
416 * The extra extension info is automagically deleted when
417 * the driver is unloaded (see windrv_unload()).
420 if (IoAllocateDriverObjectExtension(drv, (void *)1,
421 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
423 return(NDIS_STATUS_RESOURCES);
426 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
428 bcopy((char *)characteristics, (char *)ch, len);
430 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
431 ch->nmc_shutdown_handler = NULL;
432 ch->nmc_canceltxpkts_handler = NULL;
433 ch->nmc_pnpevent_handler = NULL;
436 return(NDIS_STATUS_SUCCESS);
440 NdisAllocateMemoryWithTag(vaddr, len, tag)
447 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
449 return(NDIS_STATUS_RESOURCES);
453 return(NDIS_STATUS_SUCCESS);
457 NdisAllocateMemory(vaddr, len, flags, highaddr)
461 ndis_physaddr highaddr;
465 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
467 return(NDIS_STATUS_RESOURCES);
470 return(NDIS_STATUS_SUCCESS);
474 NdisFreeMemory(vaddr, len, flags)
488 NdisMSetAttributesEx(adapter_handle, adapter_ctx, hangsecs,
490 ndis_handle adapter_handle;
491 ndis_handle adapter_ctx;
494 ndis_interface_type iftype;
496 ndis_miniport_block *block;
499 * Save the adapter context, we need it for calling
500 * the driver's internal functions.
502 block = (ndis_miniport_block *)adapter_handle;
503 block->nmb_miniportadapterctx = adapter_ctx;
504 block->nmb_checkforhangsecs = hangsecs;
505 block->nmb_flags = flags;
507 return(NDIS_STATUS_SUCCESS);
511 NdisOpenConfiguration(status, cfg, wrapctx)
517 *status = NDIS_STATUS_SUCCESS;
523 NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle)
526 unicode_string *subkey;
527 ndis_handle *subhandle;
530 *status = NDIS_STATUS_SUCCESS;
536 NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle)
540 unicode_string *subkey;
541 ndis_handle *subhandle;
543 *status = NDIS_STATUS_FAILURE;
549 ndis_encode_parm(block, oid, type, parm)
550 ndis_miniport_block *block;
551 struct sysctl_oid *oid;
553 ndis_config_parm **parm;
556 ndis_parmlist_entry *np;
563 np = ExAllocatePoolWithTag(NonPagedPool,
564 sizeof(ndis_parmlist_entry), 0);
566 return(NDIS_STATUS_RESOURCES);
567 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
568 *parm = p = &np->np_parm;
571 case ndis_parm_string:
572 /* See if this might be a number. */
573 val = strtoul((char *)oid->oid_arg1, NULL, 10);
574 us = &p->ncp_parmdata.ncp_stringdata;
575 p->ncp_type = ndis_parm_string;
577 snprintf(tmp, 32, "%x", val);
578 RtlInitAnsiString(&as, tmp);
580 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
583 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
585 return(NDIS_STATUS_RESOURCES);
589 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
593 p->ncp_type = ndis_parm_int;
594 p->ncp_parmdata.ncp_intdata =
595 strtol((char *)oid->oid_arg1, NULL, base);
597 case ndis_parm_hexint:
599 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
605 p->ncp_type = ndis_parm_hexint;
606 p->ncp_parmdata.ncp_intdata =
607 strtoul((char *)oid->oid_arg1, NULL, base);
610 return(NDIS_STATUS_FAILURE);
614 return(NDIS_STATUS_SUCCESS);
618 NdisReadConfiguration(status, parm, cfg, key, type)
620 ndis_config_parm **parm;
626 ndis_miniport_block *block;
627 struct ndis_softc *sc;
628 struct sysctl_oid *oidp;
629 struct sysctl_ctx_entry *e;
632 block = (ndis_miniport_block *)cfg;
633 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
635 if (key->us_len == 0 || key->us_buf == NULL) {
636 *status = NDIS_STATUS_FAILURE;
640 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
641 *status = NDIS_STATUS_RESOURCES;
648 * See if registry key is already in a list of known keys
649 * included with the driver.
651 #if __FreeBSD_version < 502113
652 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
654 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
657 if (strcasecmp(oidp->oid_name, keystr) == 0) {
658 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
659 RtlFreeAnsiString(&as);
660 *status = NDIS_STATUS_FAILURE;
664 *status = ndis_encode_parm(block, oidp, type, parm);
665 RtlFreeAnsiString(&as);
671 * If the key didn't match, add it to the list of dynamically
672 * created ones. Sometimes, drivers refer to registry keys
673 * that aren't documented in their .INF files. These keys
674 * are supposed to be created by some sort of utility or
675 * control panel snap-in that comes with the driver software.
676 * Sometimes it's useful to be able to manipulate these.
677 * If the driver requests the key in the form of a string,
678 * make its default value an empty string, otherwise default
682 if (type == ndis_parm_int || type == ndis_parm_hexint)
683 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
684 "UNSET", CTLFLAG_RW);
686 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
687 "UNSET", CTLFLAG_RW);
689 RtlFreeAnsiString(&as);
690 *status = NDIS_STATUS_FAILURE;
696 ndis_decode_parm(block, parm, val)
697 ndis_miniport_block *block;
698 ndis_config_parm *parm;
701 unicode_string *ustr;
704 switch(parm->ncp_type) {
705 case ndis_parm_string:
706 ustr = &parm->ncp_parmdata.ncp_stringdata;
707 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
708 return(NDIS_STATUS_RESOURCES);
709 bcopy(as.as_buf, val, as.as_len);
710 RtlFreeAnsiString(&as);
713 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
715 case ndis_parm_hexint:
716 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
719 return(NDIS_STATUS_FAILURE);
722 return(NDIS_STATUS_SUCCESS);
726 NdisWriteConfiguration(status, cfg, key, parm)
730 ndis_config_parm *parm;
734 ndis_miniport_block *block;
735 struct ndis_softc *sc;
736 struct sysctl_oid *oidp;
737 struct sysctl_ctx_entry *e;
740 block = (ndis_miniport_block *)cfg;
741 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
743 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
744 *status = NDIS_STATUS_RESOURCES;
750 /* Decode the parameter into a string. */
751 bzero(val, sizeof(val));
752 *status = ndis_decode_parm(block, parm, val);
753 if (*status != NDIS_STATUS_SUCCESS) {
754 RtlFreeAnsiString(&as);
758 /* See if the key already exists. */
760 #if __FreeBSD_version < 502113
761 TAILQ_FOREACH(e, &sc->ndis_ctx, link) {
763 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
766 if (strcasecmp(oidp->oid_name, keystr) == 0) {
767 /* Found it, set the value. */
768 strcpy((char *)oidp->oid_arg1, val);
769 RtlFreeAnsiString(&as);
774 /* Not found, add a new key with the specified value. */
775 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
778 RtlFreeAnsiString(&as);
779 *status = NDIS_STATUS_SUCCESS;
784 NdisCloseConfiguration(cfg)
788 ndis_parmlist_entry *pe;
789 ndis_miniport_block *block;
792 block = (ndis_miniport_block *)cfg;
794 while (!IsListEmpty(&block->nmb_parmlist)) {
795 e = RemoveHeadList(&block->nmb_parmlist);
796 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
798 if (p->ncp_type == ndis_parm_string)
799 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
807 * Initialize a Windows spinlock.
810 NdisAllocateSpinLock(lock)
811 ndis_spin_lock *lock;
813 KeInitializeSpinLock(&lock->nsl_spinlock);
820 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
821 * for this. One is that it's sort of superfluous: we don't have to do anything
822 * special to deallocate the spinlock. The other is that there are some buggy
823 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
824 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
828 NdisFreeSpinLock(lock)
829 ndis_spin_lock *lock;
832 KeInitializeSpinLock(&lock->nsl_spinlock);
839 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
843 NdisAcquireSpinLock(lock)
844 ndis_spin_lock *lock;
846 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
851 * Release a spinlock from IRQL == DISPATCH_LEVEL.
855 NdisReleaseSpinLock(lock)
856 ndis_spin_lock *lock;
858 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
863 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
866 NdisDprAcquireSpinLock(lock)
867 ndis_spin_lock *lock;
869 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
874 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
877 NdisDprReleaseSpinLock(lock)
878 ndis_spin_lock *lock;
880 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
885 NdisInitializeReadWriteLock(lock)
888 KeInitializeSpinLock(&lock->nrl_spinlock);
889 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
894 NdisAcquireReadWriteLock(lock, writeacc, state)
897 ndis_lock_state *state;
899 if (writeacc == TRUE) {
900 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
909 NdisReleaseReadWriteLock(lock, state)
911 ndis_lock_state *state;
913 if (lock->nrl_rsvd[0]) {
915 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
923 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
930 ndis_miniport_block *block;
935 block = (ndis_miniport_block *)adapter;
940 dev = block->nmb_physdeviceobj->do_devext;
943 * I have a test system consisting of a Sun w2100z
944 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
945 * "Aries" miniPCI NIC. (The NIC is installed in the
946 * machine using a miniPCI to PCI bus adapter card.)
947 * When running in SMP mode, I found that
948 * performing a large number of consecutive calls to
949 * NdisReadPciSlotInformation() would result in a
950 * sudden system reset (or in some cases a freeze).
951 * My suspicion is that the multiple reads are somehow
952 * triggering a fatal PCI bus error that leads to a
953 * machine check. The 1us delay in the loop below
954 * seems to prevent this problem.
957 for (i = 0; i < len; i++) {
959 dest[i] = pci_read_config(dev, i + offset, 1);
966 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
973 ndis_miniport_block *block;
978 block = (ndis_miniport_block *)adapter;
984 dev = block->nmb_physdeviceobj->do_devext;
985 for (i = 0; i < len; i++) {
987 pci_write_config(dev, i + offset, dest[i], 1);
994 * The errorlog routine uses a variable argument list, so we
995 * have to declare it this way.
998 #define ERRMSGLEN 512
1000 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
1001 uint32_t numerrors, ...)
1003 ndis_miniport_block *block;
1010 struct ndis_softc *sc;
1013 ansi_string as = { 0, 0, NULL };
1015 block = (ndis_miniport_block *)adapter;
1016 dev = block->nmb_physdeviceobj->do_devext;
1017 drv = block->nmb_deviceobj->do_drvobj;
1018 sc = device_get_softc(dev);
1021 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1022 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
1023 code, &str, &i, &flags);
1025 if (flags & MESSAGE_RESOURCE_UNICODE) {
1026 RtlInitUnicodeString(&us, (uint16_t *)str);
1027 if (RtlUnicodeStringToAnsiString(&as,
1028 &us, TRUE) == STATUS_SUCCESS)
1036 device_printf (dev, "NDIS ERROR: %x (%s)\n", code,
1037 str == NULL ? "unknown error" : str);
1039 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1040 device_printf (dev, "NDIS NUMERRORS: %x\n", numerrors);
1041 va_start(ap, numerrors);
1042 for (i = 0; i < numerrors; i++)
1043 device_printf (dev, "argptr: %p\n",
1044 va_arg(ap, void *));
1049 RtlFreeAnsiString(&as);
1055 ndis_map_cb(arg, segs, nseg, error)
1057 bus_dma_segment_t *segs;
1061 struct ndis_map_arg *ctx;
1069 for (i = 0; i < nseg; i++) {
1070 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1071 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1074 ctx->nma_cnt = nseg;
1080 NdisMStartBufferPhysicalMapping(adapter, buf, mapreg, writedev, addrarray, arraysize)
1081 ndis_handle adapter;
1085 ndis_paddr_unit *addrarray;
1086 uint32_t *arraysize;
1088 ndis_miniport_block *block;
1089 struct ndis_softc *sc;
1090 struct ndis_map_arg nma;
1094 if (adapter == NULL)
1097 block = (ndis_miniport_block *)adapter;
1098 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1100 if (mapreg > sc->ndis_mmapcnt)
1103 map = sc->ndis_mmaps[mapreg];
1104 nma.nma_fraglist = addrarray;
1106 error = bus_dmamap_load(sc->ndis_mtag, map,
1107 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1108 (void *)&nma, BUS_DMA_NOWAIT);
1113 bus_dmamap_sync(sc->ndis_mtag, map,
1114 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1116 *arraysize = nma.nma_cnt;
1122 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1123 ndis_handle adapter;
1127 ndis_miniport_block *block;
1128 struct ndis_softc *sc;
1131 if (adapter == NULL)
1134 block = (ndis_miniport_block *)adapter;
1135 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1137 if (mapreg > sc->ndis_mmapcnt)
1140 map = sc->ndis_mmaps[mapreg];
1142 bus_dmamap_sync(sc->ndis_mtag, map,
1143 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1145 bus_dmamap_unload(sc->ndis_mtag, map);
1151 * This is an older (?) timer init routine which doesn't
1152 * accept a miniport context handle. Serialized miniports should
1153 * never call this function.
1157 NdisInitializeTimer(timer, func, ctx)
1159 ndis_timer_function func;
1162 KeInitializeTimer(&timer->nt_ktimer);
1163 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1164 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1170 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1172 ndis_miniport_timer *timer;
1177 * Since we're called as a DPC, we should be running
1178 * at DISPATCH_LEVEL here. This means to acquire the
1179 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1180 * rather than KeAcquireSpinLock().
1182 if (NDIS_SERIALIZED(timer->nmt_block))
1183 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1185 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1188 if (NDIS_SERIALIZED(timer->nmt_block))
1189 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1195 * For a long time I wondered why there were two NDIS timer initialization
1196 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1197 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1198 * function and context pointers separate from those in the DPC, which
1199 * allows for another level of indirection: when the timer fires, we
1200 * can have our own timer function invoked, and from there we can call
1201 * the driver's function. But why go to all that trouble? Then it hit
1202 * me: for serialized miniports, the timer callouts are not re-entrant.
1203 * By trapping the callouts and having access to the MiniportAdapterHandle,
1204 * we can protect the driver callouts by acquiring the NDIS serialization
1205 * lock. This is essential for allowing serialized miniports to work
1206 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1207 * is enough to prevent other threads from pre-empting you, but with
1208 * SMP, you must acquire a lock as well, otherwise the other CPU is
1209 * free to clobber you.
1212 NdisMInitializeTimer(timer, handle, func, ctx)
1213 ndis_miniport_timer *timer;
1215 ndis_timer_function func;
1218 /* Save the driver's funcptr and context */
1220 timer->nmt_timerfunc = func;
1221 timer->nmt_timerctx = ctx;
1222 timer->nmt_block = handle;
1225 * Set up the timer so it will call our intermediate DPC.
1226 * Be sure to use the wrapped entry point, since
1227 * ntoskrnl_run_dpc() expects to invoke a function with
1228 * Microsoft calling conventions.
1230 KeInitializeTimer(&timer->nmt_ktimer);
1231 KeInitializeDpc(&timer->nmt_kdpc,
1232 ndis_findwrap((funcptr)ndis_timercall), timer);
1233 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1239 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1240 * but the former is just a macro wrapper around the latter.
1243 NdisSetTimer(timer, msecs)
1248 * KeSetTimer() wants the period in
1249 * hundred nanosecond intervals.
1251 KeSetTimer(&timer->nt_ktimer,
1252 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1258 NdisMSetPeriodicTimer(timer, msecs)
1259 ndis_miniport_timer *timer;
1262 KeSetTimerEx(&timer->nmt_ktimer,
1263 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1269 * Technically, this is really NdisCancelTimer(), but we also
1270 * (ab)use it for NdisMCancelTimer(), since in our implementation
1271 * we don't need the extra info in the ndis_miniport_timer
1272 * structure just to cancel a timer.
1276 NdisMCancelTimer(timer, cancelled)
1280 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1285 NdisMQueryAdapterResources(status, adapter, list, buflen)
1286 ndis_status *status;
1287 ndis_handle adapter;
1288 ndis_resource_list *list;
1291 ndis_miniport_block *block;
1292 struct ndis_softc *sc;
1295 block = (ndis_miniport_block *)adapter;
1296 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1298 rsclen = sizeof(ndis_resource_list) +
1299 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1300 if (*buflen < rsclen) {
1302 *status = NDIS_STATUS_INVALID_LENGTH;
1306 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1307 *status = NDIS_STATUS_SUCCESS;
1313 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1315 ndis_handle adapter;
1319 struct ndis_miniport_block *block;
1320 struct ndis_softc *sc;
1322 if (adapter == NULL)
1323 return(NDIS_STATUS_FAILURE);
1325 block = (ndis_miniport_block *)adapter;
1326 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1328 if (sc->ndis_res_io == NULL)
1329 return(NDIS_STATUS_FAILURE);
1331 /* Don't let the device map more ports than we have. */
1332 if (rman_get_size(sc->ndis_res_io) < numports)
1333 return(NDIS_STATUS_INVALID_LENGTH);
1335 *offset = (void *)rman_get_start(sc->ndis_res_io);
1337 return(NDIS_STATUS_SUCCESS);
1341 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1342 ndis_handle adapter;
1351 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1352 ndis_status *status;
1355 ndis_handle adapter;
1357 struct ndis_softc *sc;
1358 ndis_miniport_block *block;
1359 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1361 block = (ndis_miniport_block *)adapter;
1362 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1363 if (sc->ifp == NULL) {
1364 *status = NDIS_STATUS_FAILURE;
1369 if (bcmp(IFP2ENADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1370 #elif __FreeBSD_version >= 700000
1371 if (sc->ifp->if_addr == NULL ||
1372 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1374 if (bcmp(sc->arpcom.ac_enaddr, empty, ETHER_ADDR_LEN) == 0)
1376 *status = NDIS_STATUS_FAILURE;
1379 *addr = IFP2ENADDR(sc->ifp);
1380 #elif __FreeBSD_version >= 700000
1381 *addr = IF_LLADDR(sc->ifp);
1383 *addr = sc->arpcom.ac_enaddr;
1385 *addrlen = ETHER_ADDR_LEN;
1386 *status = NDIS_STATUS_SUCCESS;
1393 NdisQueryMapRegisterCount(bustype, cnt)
1398 return(NDIS_STATUS_SUCCESS);
1402 NdisMAllocateMapRegisters(adapter, dmachannel, dmasize, physmapneeded, maxmap)
1403 ndis_handle adapter;
1404 uint32_t dmachannel;
1406 uint32_t physmapneeded;
1409 struct ndis_softc *sc;
1410 ndis_miniport_block *block;
1411 int error, i, nseg = NDIS_MAXSEG;
1413 block = (ndis_miniport_block *)adapter;
1414 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1416 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1417 M_DEVBUF, M_NOWAIT|M_ZERO);
1419 if (sc->ndis_mmaps == NULL)
1420 return(NDIS_STATUS_RESOURCES);
1422 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1423 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1424 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1425 NULL, NULL, &sc->ndis_mtag);
1428 free(sc->ndis_mmaps, M_DEVBUF);
1429 return(NDIS_STATUS_RESOURCES);
1432 for (i = 0; i < physmapneeded; i++)
1433 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1435 sc->ndis_mmapcnt = physmapneeded;
1437 return(NDIS_STATUS_SUCCESS);
1441 NdisMFreeMapRegisters(adapter)
1442 ndis_handle adapter;
1444 struct ndis_softc *sc;
1445 ndis_miniport_block *block;
1448 block = (ndis_miniport_block *)adapter;
1449 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1451 for (i = 0; i < sc->ndis_mmapcnt; i++)
1452 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1454 free(sc->ndis_mmaps, M_DEVBUF);
1456 bus_dma_tag_destroy(sc->ndis_mtag);
1462 ndis_mapshared_cb(arg, segs, nseg, error)
1464 bus_dma_segment_t *segs;
1470 if (error || nseg > 1)
1475 p->np_quad = segs[0].ds_addr;
1481 * This maps to bus_dmamem_alloc().
1485 NdisMAllocateSharedMemory(adapter, len, cached, vaddr, paddr)
1486 ndis_handle adapter;
1490 ndis_physaddr *paddr;
1492 ndis_miniport_block *block;
1493 struct ndis_softc *sc;
1494 struct ndis_shmem *sh;
1497 if (adapter == NULL)
1500 block = (ndis_miniport_block *)adapter;
1501 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1503 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1507 InitializeListHead(&sh->ndis_list);
1510 * When performing shared memory allocations, create a tag
1511 * with a lowaddr limit that restricts physical memory mappings
1512 * so that they all fall within the first 1GB of memory.
1513 * At least one device/driver combination (Linksys Instant
1514 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1515 * problems with performing DMA operations with physical
1516 * addresses that lie above the 1GB mark. I don't know if this
1517 * is a hardware limitation or if the addresses are being
1518 * truncated within the driver, but this seems to be the only
1519 * way to make these cards work reliably in systems with more
1520 * than 1GB of physical memory.
1523 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1524 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1525 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1533 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1534 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1537 bus_dma_tag_destroy(sh->ndis_stag);
1542 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1543 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1546 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1547 bus_dma_tag_destroy(sh->ndis_stag);
1553 * Save the physical address along with the source address.
1554 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1555 * with a bogus virtual address sometimes, but with a valid
1556 * physical address. To keep this from causing trouble, we
1557 * use the physical address to as a sanity check in case
1558 * searching based on the virtual address fails.
1562 sh->ndis_paddr.np_quad = paddr->np_quad;
1563 sh->ndis_saddr = *vaddr;
1564 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1570 struct ndis_allocwork {
1578 ndis_asyncmem_complete(dobj, arg)
1579 device_object *dobj;
1582 ndis_miniport_block *block;
1583 struct ndis_softc *sc;
1584 struct ndis_allocwork *w;
1586 ndis_physaddr paddr;
1587 ndis_allocdone_handler donefunc;
1590 block = (ndis_miniport_block *)dobj->do_devext;
1591 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1596 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1597 NdisMAllocateSharedMemory(block, w->na_len,
1598 w->na_cached, &vaddr, &paddr);
1599 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1601 IoFreeWorkItem(w->na_iw);
1608 NdisMAllocateSharedMemoryAsync(adapter, len, cached, ctx)
1609 ndis_handle adapter;
1614 ndis_miniport_block *block;
1615 struct ndis_allocwork *w;
1617 io_workitem_func ifw;
1619 if (adapter == NULL)
1620 return(NDIS_STATUS_FAILURE);
1624 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1626 return(NDIS_STATUS_FAILURE);
1628 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1631 return(NDIS_STATUS_FAILURE);
1633 w->na_cached = cached;
1638 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1639 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1641 return(NDIS_STATUS_PENDING);
1645 NdisMFreeSharedMemory(adapter, len, cached, vaddr, paddr)
1646 ndis_handle adapter;
1650 ndis_physaddr paddr;
1652 ndis_miniport_block *block;
1653 struct ndis_softc *sc;
1654 struct ndis_shmem *sh = NULL;
1657 if (vaddr == NULL || adapter == NULL)
1660 block = (ndis_miniport_block *)adapter;
1661 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1663 /* Sanity check: is list empty? */
1665 if (IsListEmpty(&sc->ndis_shlist))
1669 l = sc->ndis_shlist.nle_flink;
1670 while (l != &sc->ndis_shlist) {
1671 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1672 if (sh->ndis_saddr == vaddr)
1675 * Check the physaddr too, just in case the driver lied
1676 * about the virtual address.
1678 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1685 printf("NDIS: buggy driver tried to free "
1686 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1687 vaddr, (uintmax_t)paddr.np_quad);
1691 RemoveEntryList(&sh->ndis_list);
1695 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1696 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1697 bus_dma_tag_destroy(sh->ndis_stag);
1705 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1707 ndis_handle adapter;
1708 ndis_physaddr paddr;
1711 if (adapter == NULL)
1712 return(NDIS_STATUS_FAILURE);
1714 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1717 return(NDIS_STATUS_FAILURE);
1719 return(NDIS_STATUS_SUCCESS);
1723 NdisMUnmapIoSpace(adapter, vaddr, len)
1724 ndis_handle adapter;
1728 MmUnmapIoSpace(vaddr, len);
1733 NdisGetCacheFillSize(void)
1739 NdisMGetDmaAlignment(handle)
1746 * NDIS has two methods for dealing with NICs that support DMA.
1747 * One is to just pass packets to the driver and let it call
1748 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1749 * all by itself, and the other is to let the NDIS library handle the
1750 * buffer mapping internally, and hand the driver an already populated
1751 * scatter/gather fragment list. If the driver calls
1752 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1757 NdisMInitializeScatterGatherDma(adapter, is64, maxphysmap)
1758 ndis_handle adapter;
1760 uint32_t maxphysmap;
1762 struct ndis_softc *sc;
1763 ndis_miniport_block *block;
1766 if (adapter == NULL)
1767 return(NDIS_STATUS_FAILURE);
1768 block = (ndis_miniport_block *)adapter;
1769 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1771 /* Don't do this twice. */
1772 if (sc->ndis_sc == 1)
1773 return(NDIS_STATUS_SUCCESS);
1775 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1776 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1777 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1778 NULL, NULL, &sc->ndis_ttag);
1782 return(NDIS_STATUS_SUCCESS);
1786 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1787 ndis_status *status;
1790 uint32_t protrsvdlen;
1792 ndis_packet_pool *p;
1793 ndis_packet *packets;
1796 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1798 *status = NDIS_STATUS_RESOURCES;
1802 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1803 p->np_protrsvd = protrsvdlen;
1804 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1806 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1810 if (packets == NULL) {
1812 *status = NDIS_STATUS_RESOURCES;
1816 p->np_pktmem = packets;
1818 for (i = 0; i < p->np_cnt; i++)
1819 InterlockedPushEntrySList(&p->np_head,
1820 (struct slist_entry *)&packets[i]);
1822 #ifdef NDIS_DEBUG_PACKETS
1824 KeInitializeSpinLock(&p->np_lock);
1825 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1829 *status = NDIS_STATUS_SUCCESS;
1834 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1835 ndis_status *status;
1838 uint32_t oflowdescnum;
1839 uint32_t protrsvdlen;
1841 return(NdisAllocatePacketPool(status, pool,
1842 descnum + oflowdescnum, protrsvdlen));
1846 NdisPacketPoolUsage(pool)
1849 ndis_packet_pool *p;
1851 p = (ndis_packet_pool *)pool;
1852 return(p->np_cnt - ExQueryDepthSList(&p->np_head));
1856 NdisFreePacketPool(pool)
1859 ndis_packet_pool *p;
1861 #ifdef NDIS_DEBUG_PACKETS
1865 p = (ndis_packet_pool *)pool;
1867 #ifdef NDIS_DEBUG_PACKETS
1868 KeAcquireSpinLock(&p->np_lock, &irql);
1871 usage = NdisPacketPoolUsage(pool);
1873 #ifdef NDIS_DEBUG_PACKETS
1876 KeResetEvent(&p->np_event);
1877 KeReleaseSpinLock(&p->np_lock, irql);
1878 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1880 KeReleaseSpinLock(&p->np_lock, irql);
1883 ExFreePool(p->np_pktmem);
1890 NdisAllocatePacket(status, packet, pool)
1891 ndis_status *status;
1892 ndis_packet **packet;
1895 ndis_packet_pool *p;
1897 #ifdef NDIS_DEBUG_PACKETS
1901 p = (ndis_packet_pool *)pool;
1903 #ifdef NDIS_DEBUG_PACKETS
1904 KeAcquireSpinLock(&p->np_lock, &irql);
1906 KeReleaseSpinLock(&p->np_lock, irql);
1907 printf("NDIS: tried to allocate packet from dead pool %p\n",
1909 *status = NDIS_STATUS_RESOURCES;
1914 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1916 #ifdef NDIS_DEBUG_PACKETS
1917 KeReleaseSpinLock(&p->np_lock, irql);
1921 *status = NDIS_STATUS_RESOURCES;
1926 bzero((char *)pkt, sizeof(ndis_packet));
1928 /* Save pointer to the pool. */
1929 pkt->np_private.npp_pool = pool;
1931 /* Set the oob offset pointer. Lots of things expect this. */
1932 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1935 * We must initialize the packet flags correctly in order
1936 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1937 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1940 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1941 pkt->np_private.npp_validcounts = FALSE;
1945 *status = NDIS_STATUS_SUCCESS;
1951 NdisFreePacket(packet)
1952 ndis_packet *packet;
1954 ndis_packet_pool *p;
1955 #ifdef NDIS_DEBUG_PACKETS
1959 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1961 #ifdef NDIS_DEBUG_PACKETS
1962 KeAcquireSpinLock(&p->np_lock, &irql);
1965 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1967 #ifdef NDIS_DEBUG_PACKETS
1969 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1970 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1972 KeReleaseSpinLock(&p->np_lock, irql);
1979 NdisUnchainBufferAtFront(packet, buf)
1980 ndis_packet *packet;
1983 ndis_packet_private *priv;
1985 if (packet == NULL || buf == NULL)
1988 priv = &packet->np_private;
1990 priv->npp_validcounts = FALSE;
1992 if (priv->npp_head == priv->npp_tail) {
1993 *buf = priv->npp_head;
1994 priv->npp_head = priv->npp_tail = NULL;
1996 *buf = priv->npp_head;
1997 priv->npp_head = (*buf)->mdl_next;
2004 NdisUnchainBufferAtBack(packet, buf)
2005 ndis_packet *packet;
2008 ndis_packet_private *priv;
2011 if (packet == NULL || buf == NULL)
2014 priv = &packet->np_private;
2016 priv->npp_validcounts = FALSE;
2018 if (priv->npp_head == priv->npp_tail) {
2019 *buf = priv->npp_head;
2020 priv->npp_head = priv->npp_tail = NULL;
2022 *buf = priv->npp_tail;
2023 tmp = priv->npp_head;
2024 while (tmp->mdl_next != priv->npp_tail)
2025 tmp = tmp->mdl_next;
2026 priv->npp_tail = tmp;
2027 tmp->mdl_next = NULL;
2034 * The NDIS "buffer" is really an MDL (memory descriptor list)
2035 * which is used to describe a buffer in a way that allows it
2036 * to mapped into different contexts. We have to be careful how
2037 * we handle them: in some versions of Windows, the NdisFreeBuffer()
2038 * routine is an actual function in the NDIS API, but in others
2039 * it's just a macro wrapper around IoFreeMdl(). There's really
2040 * no way to use the 'descnum' parameter to count how many
2041 * "buffers" are allocated since in order to use IoFreeMdl() to
2042 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
2043 * them, and IoAllocateMdl() just grabs them out of the heap.
2047 NdisAllocateBufferPool(status, pool, descnum)
2048 ndis_status *status;
2054 * The only thing we can really do here is verify that descnum
2055 * is a reasonable value, but I really don't know what to check
2059 *pool = NonPagedPool;
2060 *status = NDIS_STATUS_SUCCESS;
2065 NdisFreeBufferPool(pool)
2072 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
2073 ndis_status *status;
2074 ndis_buffer **buffer;
2081 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
2083 *status = NDIS_STATUS_RESOURCES;
2087 MmBuildMdlForNonPagedPool(buf);
2090 *status = NDIS_STATUS_SUCCESS;
2106 NdisBufferLength(buf)
2109 return(MmGetMdlByteCount(buf));
2113 * Get the virtual address and length of a buffer.
2114 * Note: the vaddr argument is optional.
2118 NdisQueryBuffer(buf, vaddr, len)
2124 *vaddr = MmGetMdlVirtualAddress(buf);
2125 *len = MmGetMdlByteCount(buf);
2130 /* Same as above -- we don't care about the priority. */
2133 NdisQueryBufferSafe(buf, vaddr, len, prio)
2140 *vaddr = MmGetMdlVirtualAddress(buf);
2141 *len = MmGetMdlByteCount(buf);
2146 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2149 NdisBufferVirtualAddress(buf)
2152 return(MmGetMdlVirtualAddress(buf));
2156 NdisBufferVirtualAddressSafe(buf, prio)
2160 return(MmGetMdlVirtualAddress(buf));
2164 NdisAdjustBufferLength(buf, len)
2168 MmGetMdlByteCount(buf) = len;
2174 NdisInterlockedIncrement(addend)
2177 atomic_add_long((u_long *)addend, 1);
2182 NdisInterlockedDecrement(addend)
2185 atomic_subtract_long((u_long *)addend, 1);
2190 NdisInitializeEvent(event)
2194 * NDIS events are always notification
2195 * events, and should be initialized to the
2196 * not signaled state.
2198 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2206 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2211 NdisResetEvent(event)
2214 KeResetEvent(&event->ne_event);
2219 NdisWaitEvent(event, msecs)
2226 duetime = ((int64_t)msecs * -10000);
2227 rval = KeWaitForSingleObject(event,
2228 0, 0, TRUE, msecs ? & duetime : NULL);
2230 if (rval == STATUS_TIMEOUT)
2237 NdisUnicodeStringToAnsiString(dstr, sstr)
2239 unicode_string *sstr;
2243 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2245 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2246 return(NDIS_STATUS_RESOURCES);
2248 return(NDIS_STATUS_FAILURE);
2250 return (NDIS_STATUS_SUCCESS);
2254 NdisAnsiStringToUnicodeString(dstr, sstr)
2255 unicode_string *dstr;
2260 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2262 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2263 return(NDIS_STATUS_RESOURCES);
2265 return(NDIS_STATUS_FAILURE);
2267 return (NDIS_STATUS_SUCCESS);
2271 NdisMPciAssignResources(adapter, slot, list)
2272 ndis_handle adapter;
2274 ndis_resource_list **list;
2276 ndis_miniport_block *block;
2278 if (adapter == NULL || list == NULL)
2279 return (NDIS_STATUS_FAILURE);
2281 block = (ndis_miniport_block *)adapter;
2282 *list = block->nmb_rlist;
2284 return (NDIS_STATUS_SUCCESS);
2288 ndis_intr(iobj, arg)
2292 struct ndis_softc *sc;
2293 uint8_t is_our_intr = FALSE;
2295 ndis_miniport_interrupt *intr;
2298 intr = sc->ndis_block->nmb_interrupt;
2300 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2303 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2304 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2305 sc->ndis_block->nmb_miniportadapterctx);
2307 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2308 sc->ndis_block->nmb_miniportadapterctx);
2313 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2315 return(is_our_intr);
2319 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2321 ndis_miniport_interrupt *intr;
2325 struct ndis_softc *sc;
2326 ndis_miniport_block *block;
2327 ndis_handle adapter;
2329 block = intr->ni_block;
2330 adapter = block->nmb_miniportadapterctx;
2331 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2333 if (NDIS_SERIALIZED(sc->ndis_block))
2334 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2336 MSCALL1(intr->ni_dpcfunc, adapter);
2338 /* If there's a MiniportEnableInterrupt() routine, call it. */
2340 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2341 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2343 if (NDIS_SERIALIZED(sc->ndis_block))
2344 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2347 * Set the completion event if we've drained all
2348 * pending interrupts.
2351 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2353 if (intr->ni_dpccnt == 0)
2354 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2355 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2361 NdisMRegisterInterrupt(intr, adapter, ivec, ilevel, reqisr, shared, imode)
2362 ndis_miniport_interrupt *intr;
2363 ndis_handle adapter;
2368 ndis_interrupt_mode imode;
2370 ndis_miniport_block *block;
2371 ndis_miniport_characteristics *ch;
2372 struct ndis_softc *sc;
2376 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2377 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2380 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2381 sizeof(struct mtx), 0);
2382 if (intr->ni_rsvd == NULL)
2383 return(NDIS_STATUS_RESOURCES);
2385 intr->ni_block = adapter;
2386 intr->ni_isrreq = reqisr;
2387 intr->ni_shared = shared;
2388 intr->ni_dpccnt = 0;
2389 intr->ni_isrfunc = ch->nmc_isr_func;
2390 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2392 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2393 KeInitializeDpc(&intr->ni_dpc,
2394 ndis_findwrap((funcptr)ndis_intrhand), intr);
2395 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2397 error = IoConnectInterrupt(&intr->ni_introbj,
2398 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2399 ivec, ilevel, 0, imode, shared, 0, FALSE);
2401 if (error != STATUS_SUCCESS)
2402 return(NDIS_STATUS_FAILURE);
2404 block->nmb_interrupt = intr;
2406 return(NDIS_STATUS_SUCCESS);
2410 NdisMDeregisterInterrupt(intr)
2411 ndis_miniport_interrupt *intr;
2413 ndis_miniport_block *block;
2414 struct ndis_softc *sc;
2417 block = intr->ni_block;
2418 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2420 /* Should really be KeSynchronizeExecution() */
2422 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2423 block->nmb_interrupt = NULL;
2424 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2426 KeFlushQueuedDpcs();
2428 /* Disconnect our ISR */
2430 IoDisconnectInterrupt(intr->ni_introbj);
2432 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2433 KeResetEvent(&intr->ni_dpcevt);
2439 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2440 ndis_handle adapter;
2442 ndis_shutdown_handler shutdownfunc;
2444 ndis_miniport_block *block;
2445 ndis_miniport_characteristics *chars;
2446 struct ndis_softc *sc;
2448 if (adapter == NULL)
2451 block = (ndis_miniport_block *)adapter;
2452 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2453 chars = sc->ndis_chars;
2455 chars->nmc_shutdown_handler = shutdownfunc;
2456 chars->nmc_rsvd0 = shutdownctx;
2462 NdisMDeregisterAdapterShutdownHandler(adapter)
2463 ndis_handle adapter;
2465 ndis_miniport_block *block;
2466 ndis_miniport_characteristics *chars;
2467 struct ndis_softc *sc;
2469 if (adapter == NULL)
2472 block = (ndis_miniport_block *)adapter;
2473 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2474 chars = sc->ndis_chars;
2476 chars->nmc_shutdown_handler = NULL;
2477 chars->nmc_rsvd0 = NULL;
2483 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2488 if (MmGetMdlByteCount(buf) == 0)
2490 return(SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2491 MmGetMdlByteCount(buf)));
2495 NdisGetBufferPhysicalArraySize(buf, pages)
2502 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2507 NdisQueryBufferOffset(buf, off, len)
2515 *off = MmGetMdlByteOffset(buf);
2516 *len = MmGetMdlByteCount(buf);
2528 * During system bootstrap, (i.e. cold == 1), we aren't
2529 * allowed to sleep, so we have to do a hard DELAY()
2536 KeInitializeTimer(&timer);
2537 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2538 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2545 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2551 struct ndis_softc *sc;
2552 ndis_miniport_block *block;
2553 bus_space_handle_t bh;
2561 block = (ndis_miniport_block *)handle;
2562 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2565 bh = rman_get_bushandle(sc->ndis_res_am);
2566 bt = rman_get_bustag(sc->ndis_res_am);
2568 for (i = 0; i < len; i++)
2569 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2575 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2581 struct ndis_softc *sc;
2582 ndis_miniport_block *block;
2583 bus_space_handle_t bh;
2591 block = (ndis_miniport_block *)handle;
2592 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2595 bh = rman_get_bushandle(sc->ndis_res_am);
2596 bt = rman_get_bustag(sc->ndis_res_am);
2598 for (i = 0; i < len; i++)
2599 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2605 NdisInterlockedInsertHeadList(head, entry, lock)
2608 ndis_spin_lock *lock;
2612 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2613 flink = head->nle_flink;
2614 entry->nle_flink = flink;
2615 entry->nle_blink = head;
2616 flink->nle_blink = entry;
2617 head->nle_flink = entry;
2618 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2624 NdisInterlockedRemoveHeadList(head, lock)
2626 ndis_spin_lock *lock;
2631 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2632 entry = head->nle_flink;
2633 flink = entry->nle_flink;
2634 head->nle_flink = flink;
2635 flink->nle_blink = head;
2636 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2642 NdisInterlockedInsertTailList(head, entry, lock)
2645 ndis_spin_lock *lock;
2649 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2650 blink = head->nle_blink;
2651 entry->nle_flink = head;
2652 entry->nle_blink = blink;
2653 blink->nle_flink = entry;
2654 head->nle_blink = entry;
2655 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2661 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2662 ndis_miniport_interrupt *intr;
2666 return(KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2670 NdisGetCurrentSystemTime(tval)
2673 ntoskrnl_time(tval);
2678 * Return the number of milliseconds since the system booted.
2681 NdisGetSystemUpTime(tval)
2687 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2693 NdisInitializeString(dst, src)
2694 unicode_string *dst;
2698 RtlInitAnsiString(&as, src);
2699 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2705 unicode_string *str;
2707 RtlFreeUnicodeString(str);
2712 NdisMRemoveMiniport(adapter)
2713 ndis_handle *adapter;
2715 return(NDIS_STATUS_SUCCESS);
2719 NdisInitAnsiString(dst, src)
2723 RtlInitAnsiString(dst, src);
2728 NdisInitUnicodeString(dst, src)
2729 unicode_string *dst;
2732 RtlInitUnicodeString(dst, src);
2736 static void NdisMGetDeviceProperty(adapter, phydevobj,
2737 funcdevobj, nextdevobj, resources, transresources)
2738 ndis_handle adapter;
2739 device_object **phydevobj;
2740 device_object **funcdevobj;
2741 device_object **nextdevobj;
2742 cm_resource_list *resources;
2743 cm_resource_list *transresources;
2745 ndis_miniport_block *block;
2747 block = (ndis_miniport_block *)adapter;
2749 if (phydevobj != NULL)
2750 *phydevobj = block->nmb_physdeviceobj;
2751 if (funcdevobj != NULL)
2752 *funcdevobj = block->nmb_deviceobj;
2753 if (nextdevobj != NULL)
2754 *nextdevobj = block->nmb_nextdeviceobj;
2760 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2761 ndis_packet *packet;
2769 tmp = packet->np_private.npp_head;
2773 *firstlen = *totlen = 0;
2775 *firstva = MmGetMdlVirtualAddress(tmp);
2776 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2777 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2778 *totlen += MmGetMdlByteCount(tmp);
2785 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2786 ndis_packet *packet;
2793 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2797 ndis_find_sym(lf, filename, suffix, sym)
2807 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2808 if (fullsym == NULL)
2811 bzero(fullsym, MAXPATHLEN);
2812 strncpy(fullsym, filename, MAXPATHLEN);
2813 if (strlen(filename) < 4) {
2814 ExFreePool(fullsym);
2818 /* If the filename has a .ko suffix, strip if off. */
2819 suf = fullsym + (strlen(filename) - 3);
2820 if (strcmp(suf, ".ko") == 0)
2823 for (i = 0; i < strlen(fullsym); i++) {
2824 if (fullsym[i] == '.')
2827 fullsym[i] = tolower(fullsym[i]);
2829 strcat(fullsym, suffix);
2830 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2831 ExFreePool(fullsym);
2838 struct ndis_checkmodule {
2844 * See if a single module contains the symbols for a specified file.
2847 NdisCheckModule(linker_file_t lf, void *context)
2849 struct ndis_checkmodule *nc;
2850 caddr_t kldstart, kldend;
2852 nc = (struct ndis_checkmodule *)context;
2853 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2855 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2858 nc->fh->nf_map = NULL;
2859 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2860 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2864 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2866 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2867 ndis_status *status;
2868 ndis_handle *filehandle;
2869 uint32_t *filelength;
2870 unicode_string *filename;
2871 ndis_physaddr highestaddr;
2874 char *afilename = NULL;
2875 struct thread *td = curthread;
2876 struct nameidata nd;
2877 int flags, error, vfslocked;
2879 struct vattr *vap = &vat;
2882 struct ndis_checkmodule nc;
2884 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2885 *status = NDIS_STATUS_RESOURCES;
2889 afilename = strdup(as.as_buf, M_DEVBUF);
2890 RtlFreeAnsiString(&as);
2892 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2894 free(afilename, M_DEVBUF);
2895 *status = NDIS_STATUS_RESOURCES;
2899 fh->nf_name = afilename;
2902 * During system bootstrap, it's impossible to load files
2903 * from the rootfs since it's not mounted yet. We therefore
2904 * offer the possibility of opening files that have been
2905 * preloaded as modules instead. Both choices will work
2906 * when kldloading a module from multiuser, but only the
2907 * module option will work during bootstrap. The module
2908 * loading option works by using the ndiscvt(8) utility
2909 * to convert the arbitrary file into a .ko using objcopy(1).
2910 * This file will contain two special symbols: filename_start
2911 * and filename_end. All we have to do is traverse the KLD
2912 * list in search of those symbols and we've found the file
2913 * data. As an added bonus, ndiscvt(8) will also generate
2914 * a normal .o file which can be linked statically with
2915 * the kernel. This means that the symbols will actual reside
2916 * in the kernel's symbol table, but that doesn't matter to
2917 * us since the kernel appears to us as just another module.
2920 nc.afilename = afilename;
2922 if (linker_file_foreach(NdisCheckModule, &nc)) {
2923 *filelength = fh->nf_maplen;
2925 *status = NDIS_STATUS_SUCCESS;
2929 if (TAILQ_EMPTY(&mountlist)) {
2931 *status = NDIS_STATUS_FILE_NOT_FOUND;
2932 printf("NDIS: could not find file %s in linker list\n",
2934 printf("NDIS: and no filesystems mounted yet, "
2935 "aborting NdisOpenFile()\n");
2936 free(afilename, M_DEVBUF);
2940 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2943 free(afilename, M_DEVBUF);
2944 *status = NDIS_STATUS_RESOURCES;
2948 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2950 /* Some threads don't have a current working directory. */
2952 if (td->td_proc->p_fd->fd_rdir == NULL)
2953 td->td_proc->p_fd->fd_rdir = rootvnode;
2954 if (td->td_proc->p_fd->fd_cdir == NULL)
2955 td->td_proc->p_fd->fd_cdir = rootvnode;
2957 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td);
2960 error = vn_open(&nd, &flags, 0, NULL);
2962 *status = NDIS_STATUS_FILE_NOT_FOUND;
2964 printf("NDIS: open file %s failed: %d\n", path, error);
2966 free(afilename, M_DEVBUF);
2969 vfslocked = NDHASGIANT(&nd);
2973 NDFREE(&nd, NDF_ONLY_PNBUF);
2975 /* Get the file size. */
2976 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred);
2977 VOP_UNLOCK(nd.ni_vp, 0);
2978 VFS_UNLOCK_GIANT(vfslocked);
2980 fh->nf_vp = nd.ni_vp;
2982 fh->nf_type = NDIS_FH_TYPE_VFS;
2984 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2985 *status = NDIS_STATUS_SUCCESS;
2991 NdisMapFile(status, mappedbuffer, filehandle)
2992 ndis_status *status;
2993 void **mappedbuffer;
2994 ndis_handle filehandle;
2997 struct thread *td = curthread;
3000 int error, resid, vfslocked;
3003 if (filehandle == NULL) {
3004 *status = NDIS_STATUS_FAILURE;
3008 fh = (ndis_fh *)filehandle;
3010 if (fh->nf_vp == NULL) {
3011 *status = NDIS_STATUS_FAILURE;
3015 if (fh->nf_map != NULL) {
3016 *status = NDIS_STATUS_ALREADY_MAPPED;
3020 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
3022 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
3023 *status = NDIS_STATUS_FAILURE;
3026 fh->nf_map = kldstart;
3027 *status = NDIS_STATUS_SUCCESS;
3028 *mappedbuffer = fh->nf_map;
3032 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
3034 if (fh->nf_map == NULL) {
3035 *status = NDIS_STATUS_RESOURCES;
3040 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3041 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
3042 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
3043 VFS_UNLOCK_GIANT(vfslocked);
3046 *status = NDIS_STATUS_FAILURE;
3048 *status = NDIS_STATUS_SUCCESS;
3049 *mappedbuffer = fh->nf_map;
3056 NdisUnmapFile(filehandle)
3057 ndis_handle filehandle;
3060 fh = (ndis_fh *)filehandle;
3062 if (fh->nf_map == NULL)
3065 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3066 ExFreePool(fh->nf_map);
3073 NdisCloseFile(filehandle)
3074 ndis_handle filehandle;
3076 struct thread *td = curthread;
3081 if (filehandle == NULL)
3084 fh = (ndis_fh *)filehandle;
3085 if (fh->nf_map != NULL) {
3086 if (fh->nf_type == NDIS_FH_TYPE_VFS)
3087 ExFreePool(fh->nf_map);
3091 if (fh->nf_vp == NULL)
3094 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
3096 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3097 vn_close(vp, FREAD, td->td_ucred, td);
3098 VFS_UNLOCK_GIANT(vfslocked);
3102 free(fh->nf_name, M_DEVBUF);
3109 NdisSystemProcessorCount()
3114 typedef void (*ndis_statusdone_handler)(ndis_handle);
3115 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
3119 NdisMIndicateStatusComplete(adapter)
3120 ndis_handle adapter;
3122 ndis_miniport_block *block;
3123 ndis_statusdone_handler statusdonefunc;
3125 block = (ndis_miniport_block *)adapter;
3126 statusdonefunc = block->nmb_statusdone_func;
3128 MSCALL1(statusdonefunc, adapter);
3133 NdisMIndicateStatus(adapter, status, sbuf, slen)
3134 ndis_handle adapter;
3139 ndis_miniport_block *block;
3140 ndis_status_handler statusfunc;
3142 block = (ndis_miniport_block *)adapter;
3143 statusfunc = block->nmb_status_func;
3145 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3150 * The DDK documentation says that you should use IoQueueWorkItem()
3151 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3152 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3153 * depends on the API semantics of ExQueueWorkItem(). In our world,
3154 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3157 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3158 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3159 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3160 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3161 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3162 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3163 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3164 * to ExQueueWorkItem().
3166 * Got all that? (Sheesh.)
3170 NdisScheduleWorkItem(work)
3171 ndis_work_item *work;
3173 work_queue_item *wqi;
3175 wqi = (work_queue_item *)work->nwi_wraprsvd;
3176 ExInitializeWorkItem(wqi,
3177 (work_item_func)work->nwi_func, work->nwi_ctx);
3178 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3180 return(NDIS_STATUS_SUCCESS);
3184 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3192 ndis_buffer *src, *dst;
3194 int resid, copied, len, scnt, dcnt;
3198 src = spkt->np_private.npp_head;
3199 dst = dpkt->np_private.npp_head;
3201 sptr = MmGetMdlVirtualAddress(src);
3202 dptr = MmGetMdlVirtualAddress(dst);
3203 scnt = MmGetMdlByteCount(src);
3204 dcnt = MmGetMdlByteCount(dst);
3207 if (MmGetMdlByteCount(src) > soff) {
3209 scnt = MmGetMdlByteCount(src)- soff;
3212 soff -= MmGetMdlByteCount(src);
3213 src = src->mdl_next;
3216 sptr = MmGetMdlVirtualAddress(src);
3220 if (MmGetMdlByteCount(dst) > doff) {
3222 dcnt = MmGetMdlByteCount(dst) - doff;
3225 doff -= MmGetMdlByteCount(dst);
3226 dst = dst->mdl_next;
3229 dptr = MmGetMdlVirtualAddress(dst);
3243 bcopy(sptr, dptr, len);
3252 dst = dst->mdl_next;
3255 dptr = MmGetMdlVirtualAddress(dst);
3256 dcnt = MmGetMdlByteCount(dst);
3261 src = src->mdl_next;
3264 sptr = MmGetMdlVirtualAddress(src);
3265 scnt = MmGetMdlByteCount(src);
3274 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3283 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3288 NdisIMCopySendPerPacketInfo(dpkt, spkt)
3292 memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension));
3296 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3298 unicode_string *devname;
3299 unicode_string *symname;
3300 driver_dispatch *majorfuncs[];
3302 ndis_handle *devhandle;
3305 device_object *dobj;
3307 status = IoCreateDevice(handle, 0, devname,
3308 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3310 if (status == STATUS_SUCCESS) {
3319 NdisMDeregisterDevice(handle)
3322 IoDeleteDevice(handle);
3323 return(NDIS_STATUS_SUCCESS);
3327 NdisMQueryAdapterInstanceName(name, handle)
3328 unicode_string *name;
3331 ndis_miniport_block *block;
3335 block = (ndis_miniport_block *)handle;
3336 dev = block->nmb_physdeviceobj->do_devext;
3338 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3339 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3340 return(NDIS_STATUS_RESOURCES);
3342 return(NDIS_STATUS_SUCCESS);
3346 NdisMRegisterUnloadHandler(handle, func)
3356 printf ("NDIS dummy called...\n");
3361 * Note: a couple of entries in this table specify the
3362 * number of arguments as "foo + 1". These are routines
3363 * that accept a 64-bit argument, passed by value. On
3364 * x86, these arguments consume two longwords on the stack,
3365 * so we lie and say there's one additional argument so
3366 * that the wrapping routines will do the right thing.
3369 image_patch_table ndis_functbl[] = {
3370 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3371 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3372 IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2),
3373 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3374 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3375 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3376 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3377 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3378 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3379 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3380 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3381 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3382 IMPORT_SFUNC(NdisInitAnsiString, 2),
3383 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3384 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3385 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3386 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3387 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3388 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3389 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3390 IMPORT_SFUNC(NdisInitializeString, 2),
3391 IMPORT_SFUNC(NdisFreeString, 1),
3392 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3393 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3394 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3395 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3396 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3397 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3398 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3399 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3400 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3401 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3402 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3403 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3404 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3405 IMPORT_SFUNC(NdisReadConfiguration, 5),
3406 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3407 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3408 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3409 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3410 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3411 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3412 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3413 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3414 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3415 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3416 IMPORT_SFUNC(NdisFreeMemory, 3),
3417 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3418 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3419 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3420 NdisReadPciSlotInformation, 5),
3421 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3422 NdisWritePciSlotInformation, 5),
3423 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3424 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3425 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3426 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3427 IMPORT_SFUNC(NdisInitializeTimer, 3),
3428 IMPORT_SFUNC(NdisSetTimer, 2),
3429 IMPORT_SFUNC(NdisMCancelTimer, 2),
3430 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3431 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3432 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3433 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3434 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3435 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3436 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3437 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3438 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3439 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3440 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3441 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3442 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3443 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3444 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3445 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3446 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3447 IMPORT_SFUNC(NdisAllocatePacket, 3),
3448 IMPORT_SFUNC(NdisFreePacket, 1),
3449 IMPORT_SFUNC(NdisFreePacketPool, 1),
3450 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3451 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3452 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3453 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3454 IMPORT_SFUNC(NdisQueryBuffer, 3),
3455 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3456 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3457 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3458 IMPORT_SFUNC(NdisBufferLength, 1),
3459 IMPORT_SFUNC(NdisFreeBuffer, 1),
3460 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3461 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3462 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3463 IMPORT_SFUNC(NdisInitializeEvent, 1),
3464 IMPORT_SFUNC(NdisSetEvent, 1),
3465 IMPORT_SFUNC(NdisResetEvent, 1),
3466 IMPORT_SFUNC(NdisWaitEvent, 2),
3467 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3468 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3469 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3470 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3471 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3472 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3473 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3474 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3475 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3476 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3477 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3478 IMPORT_SFUNC(NdisMSleep, 1),
3479 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3480 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3481 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3482 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3483 IMPORT_SFUNC(NdisMapFile, 3),
3484 IMPORT_SFUNC(NdisUnmapFile, 1),
3485 IMPORT_SFUNC(NdisCloseFile, 1),
3486 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3487 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3488 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3489 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3490 IMPORT_SFUNC(ndis_timercall, 4),
3491 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3492 IMPORT_SFUNC(ndis_intr, 2),
3493 IMPORT_SFUNC(ndis_intrhand, 4),
3496 * This last entry is a catch-all for any function we haven't
3497 * implemented yet. The PE import list patching routine will
3498 * use it for any function that doesn't have an explicit match
3502 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3506 { NULL, NULL, NULL }