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 void *NdisGetRoutineAddress(unicode_string *);
201 static uint32_t NdisMGetDmaAlignment(ndis_handle);
202 static ndis_status NdisMInitializeScatterGatherDma(ndis_handle,
204 static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **);
205 static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **);
206 static void NdisAllocateBufferPool(ndis_status *,
207 ndis_handle *, uint32_t);
208 static void NdisFreeBufferPool(ndis_handle);
209 static void NdisAllocateBuffer(ndis_status *, ndis_buffer **,
210 ndis_handle, void *, uint32_t);
211 static void NdisFreeBuffer(ndis_buffer *);
212 static uint32_t NdisBufferLength(ndis_buffer *);
213 static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *);
214 static void NdisQueryBufferSafe(ndis_buffer *, void **,
215 uint32_t *, uint32_t);
216 static void *NdisBufferVirtualAddress(ndis_buffer *);
217 static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t);
218 static void NdisAdjustBufferLength(ndis_buffer *, int);
219 static uint32_t NdisInterlockedIncrement(uint32_t *);
220 static uint32_t NdisInterlockedDecrement(uint32_t *);
221 static void NdisInitializeEvent(ndis_event *);
222 static void NdisSetEvent(ndis_event *);
223 static void NdisResetEvent(ndis_event *);
224 static uint8_t NdisWaitEvent(ndis_event *, uint32_t);
225 static ndis_status NdisUnicodeStringToAnsiString(ansi_string *,
228 NdisAnsiStringToUnicodeString(unicode_string *, ansi_string *);
229 static ndis_status NdisMPciAssignResources(ndis_handle,
230 uint32_t, ndis_resource_list **);
231 static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *,
232 ndis_handle, uint32_t, uint32_t, uint8_t,
233 uint8_t, ndis_interrupt_mode);
234 static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *);
235 static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *,
236 ndis_shutdown_handler);
237 static void NdisMDeregisterAdapterShutdownHandler(ndis_handle);
238 static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *);
239 static void NdisGetBufferPhysicalArraySize(ndis_buffer *,
241 static void NdisQueryBufferOffset(ndis_buffer *,
242 uint32_t *, uint32_t *);
243 static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle,
244 uint32_t, void *, uint32_t);
245 static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle,
246 uint32_t, void *, uint32_t);
247 static list_entry *NdisInterlockedInsertHeadList(list_entry *,
248 list_entry *, ndis_spin_lock *);
249 static list_entry *NdisInterlockedRemoveHeadList(list_entry *,
251 static list_entry *NdisInterlockedInsertTailList(list_entry *,
252 list_entry *, ndis_spin_lock *);
254 NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *,
256 static void NdisGetCurrentSystemTime(uint64_t *);
257 static void NdisGetSystemUpTime(uint32_t *);
258 static uint32_t NdisGetVersion(void);
259 static void NdisInitializeString(unicode_string *, char *);
260 static void NdisInitAnsiString(ansi_string *, char *);
261 static void NdisInitUnicodeString(unicode_string *, uint16_t *);
262 static void NdisFreeString(unicode_string *);
263 static ndis_status NdisMRemoveMiniport(ndis_handle *);
264 static void NdisTerminateWrapper(ndis_handle, void *);
265 static void NdisMGetDeviceProperty(ndis_handle, device_object **,
266 device_object **, device_object **, cm_resource_list *,
268 static void NdisGetFirstBufferFromPacket(ndis_packet *,
269 ndis_buffer **, void **, uint32_t *, uint32_t *);
270 static void NdisGetFirstBufferFromPacketSafe(ndis_packet *,
271 ndis_buffer **, void **, uint32_t *, uint32_t *, uint32_t);
272 static int ndis_find_sym(linker_file_t, char *, char *, caddr_t *);
273 static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *,
274 unicode_string *, ndis_physaddr);
275 static void NdisMapFile(ndis_status *, void **, ndis_handle);
276 static void NdisUnmapFile(ndis_handle);
277 static void NdisCloseFile(ndis_handle);
278 static uint8_t NdisSystemProcessorCount(void);
279 static void NdisGetCurrentProcessorCounts(uint32_t *, uint32_t *, uint32_t *);
280 static void NdisMIndicateStatusComplete(ndis_handle);
281 static void NdisMIndicateStatus(ndis_handle, ndis_status,
283 static uint8_t ndis_intr(kinterrupt *, void *);
284 static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *);
285 static funcptr ndis_findwrap(funcptr);
286 static void NdisCopyFromPacketToPacket(ndis_packet *,
287 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *);
288 static void NdisCopyFromPacketToPacketSafe(ndis_packet *,
289 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t);
290 static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *);
291 static ndis_status NdisMRegisterDevice(ndis_handle,
292 unicode_string *, unicode_string *, driver_dispatch **,
293 void **, ndis_handle *);
294 static ndis_status NdisMDeregisterDevice(ndis_handle);
296 NdisMQueryAdapterInstanceName(unicode_string *, ndis_handle);
297 static void NdisMRegisterUnloadHandler(ndis_handle, void *);
298 static void dummy(void);
301 * Some really old drivers do not properly check the return value
302 * from NdisAllocatePacket() and NdisAllocateBuffer() and will
303 * sometimes allocate few more buffers/packets that they originally
304 * requested when they created the pool. To prevent this from being
305 * a problem, we allocate a few extra buffers/packets beyond what
306 * the driver asks for. This #define controls how many.
308 #define NDIS_POOL_EXTRA 16
313 image_patch_table *patch;
315 strcpy(ndis_filepath, "/compat/ndis");
317 patch = ndis_functbl;
318 while (patch->ipt_func != NULL) {
319 windrv_wrap((funcptr)patch->ipt_func,
320 (funcptr *)&patch->ipt_wrap,
321 patch->ipt_argcnt, patch->ipt_ftype);
331 image_patch_table *patch;
333 patch = ndis_functbl;
334 while (patch->ipt_func != NULL) {
335 windrv_unwrap(patch->ipt_wrap);
346 image_patch_table *patch;
348 patch = ndis_functbl;
349 while (patch->ipt_func != NULL) {
350 if ((funcptr)patch->ipt_func == func)
351 return ((funcptr)patch->ipt_wrap);
359 * This routine does the messy Windows Driver Model device attachment
360 * stuff on behalf of NDIS drivers. We register our own AddDevice
364 NdisInitializeWrapper(wrapper, drv, path, unused)
365 ndis_handle *wrapper;
371 * As of yet, I haven't come up with a compelling
372 * reason to define a private NDIS wrapper structure,
373 * so we use a pointer to the driver object as the
374 * wrapper handle. The driver object has the miniport
375 * characteristics struct for this driver hung off it
376 * via IoAllocateDriverObjectExtension(), and that's
377 * really all the private data we need.
383 * If this was really Windows, we'd be registering dispatch
384 * routines for the NDIS miniport module here, but we're
385 * not Windows so all we really need to do is set up an
386 * AddDevice function that'll be invoked when a new device
390 drv->dro_driverext->dre_adddevicefunc = NdisAddDevice;
394 NdisTerminateWrapper(handle, syspec)
398 /* Nothing to see here, move along. */
402 NdisMRegisterMiniport(handle, characteristics, len)
404 ndis_miniport_characteristics *characteristics;
407 ndis_miniport_characteristics *ch = NULL;
410 drv = (driver_object *)handle;
413 * We need to save the NDIS miniport characteristics
414 * somewhere. This data is per-driver, not per-device
415 * (all devices handled by the same driver have the
416 * same characteristics) so we hook it onto the driver
417 * object using IoAllocateDriverObjectExtension().
418 * The extra extension info is automagically deleted when
419 * the driver is unloaded (see windrv_unload()).
422 if (IoAllocateDriverObjectExtension(drv, (void *)1,
423 sizeof(ndis_miniport_characteristics), (void **)&ch) !=
425 return (NDIS_STATUS_RESOURCES);
428 bzero((char *)ch, sizeof(ndis_miniport_characteristics));
430 bcopy((char *)characteristics, (char *)ch, len);
432 if (ch->nmc_version_major < 5 || ch->nmc_version_minor < 1) {
433 ch->nmc_shutdown_handler = NULL;
434 ch->nmc_canceltxpkts_handler = NULL;
435 ch->nmc_pnpevent_handler = NULL;
438 return (NDIS_STATUS_SUCCESS);
442 NdisAllocateMemoryWithTag(vaddr, len, tag)
449 mem = ExAllocatePoolWithTag(NonPagedPool, len, tag);
451 return (NDIS_STATUS_RESOURCES);
455 return (NDIS_STATUS_SUCCESS);
459 NdisAllocateMemory(vaddr, len, flags, highaddr)
463 ndis_physaddr highaddr;
467 mem = ExAllocatePoolWithTag(NonPagedPool, len, 0);
469 return (NDIS_STATUS_RESOURCES);
472 return (NDIS_STATUS_SUCCESS);
476 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;
521 NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle)
524 unicode_string *subkey;
525 ndis_handle *subhandle;
528 *status = NDIS_STATUS_SUCCESS;
532 NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle)
536 unicode_string *subkey;
537 ndis_handle *subhandle;
539 *status = NDIS_STATUS_FAILURE;
543 ndis_encode_parm(block, oid, type, parm)
544 ndis_miniport_block *block;
545 struct sysctl_oid *oid;
547 ndis_config_parm **parm;
550 ndis_parmlist_entry *np;
557 np = ExAllocatePoolWithTag(NonPagedPool,
558 sizeof(ndis_parmlist_entry), 0);
560 return (NDIS_STATUS_RESOURCES);
561 InsertHeadList((&block->nmb_parmlist), (&np->np_list));
562 *parm = p = &np->np_parm;
565 case ndis_parm_string:
566 /* See if this might be a number. */
567 val = strtoul((char *)oid->oid_arg1, NULL, 10);
568 us = &p->ncp_parmdata.ncp_stringdata;
569 p->ncp_type = ndis_parm_string;
571 snprintf(tmp, 32, "%x", val);
572 RtlInitAnsiString(&as, tmp);
574 RtlInitAnsiString(&as, (char *)oid->oid_arg1);
577 if (RtlAnsiStringToUnicodeString(us, &as, TRUE)) {
579 return (NDIS_STATUS_RESOURCES);
583 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
587 p->ncp_type = ndis_parm_int;
588 p->ncp_parmdata.ncp_intdata =
589 strtol((char *)oid->oid_arg1, NULL, base);
591 case ndis_parm_hexint:
593 if (strncmp((char *)oid->oid_arg1, "0x", 2) == 0)
599 p->ncp_type = ndis_parm_hexint;
600 p->ncp_parmdata.ncp_intdata =
601 strtoul((char *)oid->oid_arg1, NULL, base);
604 return (NDIS_STATUS_FAILURE);
608 return (NDIS_STATUS_SUCCESS);
612 NdisReadConfiguration(status, parm, cfg, key, type)
614 ndis_config_parm **parm;
620 ndis_miniport_block *block;
621 struct ndis_softc *sc;
622 struct sysctl_oid *oidp;
623 struct sysctl_ctx_entry *e;
626 block = (ndis_miniport_block *)cfg;
627 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
629 if (key->us_len == 0 || key->us_buf == NULL) {
630 *status = NDIS_STATUS_FAILURE;
634 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
635 *status = NDIS_STATUS_RESOURCES;
642 * See if registry key is already in a list of known keys
643 * included with the driver.
645 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
647 if (strcasecmp(oidp->oid_name, keystr) == 0) {
648 if (strcmp((char *)oidp->oid_arg1, "UNSET") == 0) {
649 RtlFreeAnsiString(&as);
650 *status = NDIS_STATUS_FAILURE;
654 *status = ndis_encode_parm(block, oidp, type, parm);
655 RtlFreeAnsiString(&as);
661 * If the key didn't match, add it to the list of dynamically
662 * created ones. Sometimes, drivers refer to registry keys
663 * that aren't documented in their .INF files. These keys
664 * are supposed to be created by some sort of utility or
665 * control panel snap-in that comes with the driver software.
666 * Sometimes it's useful to be able to manipulate these.
667 * If the driver requests the key in the form of a string,
668 * make its default value an empty string, otherwise default
672 if (type == ndis_parm_int || type == ndis_parm_hexint)
673 ndis_add_sysctl(sc, keystr, "(dynamic integer key)",
674 "UNSET", CTLFLAG_RW);
676 ndis_add_sysctl(sc, keystr, "(dynamic string key)",
677 "UNSET", CTLFLAG_RW);
679 RtlFreeAnsiString(&as);
680 *status = NDIS_STATUS_FAILURE;
684 ndis_decode_parm(block, parm, val)
685 ndis_miniport_block *block;
686 ndis_config_parm *parm;
689 unicode_string *ustr;
692 switch(parm->ncp_type) {
693 case ndis_parm_string:
694 ustr = &parm->ncp_parmdata.ncp_stringdata;
695 if (RtlUnicodeStringToAnsiString(&as, ustr, TRUE))
696 return (NDIS_STATUS_RESOURCES);
697 bcopy(as.as_buf, val, as.as_len);
698 RtlFreeAnsiString(&as);
701 sprintf(val, "%d", parm->ncp_parmdata.ncp_intdata);
703 case ndis_parm_hexint:
704 sprintf(val, "%xu", parm->ncp_parmdata.ncp_intdata);
707 return (NDIS_STATUS_FAILURE);
710 return (NDIS_STATUS_SUCCESS);
714 NdisWriteConfiguration(status, cfg, key, parm)
718 ndis_config_parm *parm;
722 ndis_miniport_block *block;
723 struct ndis_softc *sc;
724 struct sysctl_oid *oidp;
725 struct sysctl_ctx_entry *e;
728 block = (ndis_miniport_block *)cfg;
729 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
731 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) {
732 *status = NDIS_STATUS_RESOURCES;
738 /* Decode the parameter into a string. */
739 bzero(val, sizeof(val));
740 *status = ndis_decode_parm(block, parm, val);
741 if (*status != NDIS_STATUS_SUCCESS) {
742 RtlFreeAnsiString(&as);
746 /* See if the key already exists. */
748 TAILQ_FOREACH(e, device_get_sysctl_ctx(sc->ndis_dev), link) {
750 if (strcasecmp(oidp->oid_name, keystr) == 0) {
751 /* Found it, set the value. */
752 strcpy((char *)oidp->oid_arg1, val);
753 RtlFreeAnsiString(&as);
758 /* Not found, add a new key with the specified value. */
759 ndis_add_sysctl(sc, keystr, "(dynamically set key)",
762 RtlFreeAnsiString(&as);
763 *status = NDIS_STATUS_SUCCESS;
767 NdisCloseConfiguration(cfg)
771 ndis_parmlist_entry *pe;
772 ndis_miniport_block *block;
775 block = (ndis_miniport_block *)cfg;
777 while (!IsListEmpty(&block->nmb_parmlist)) {
778 e = RemoveHeadList(&block->nmb_parmlist);
779 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list);
781 if (p->ncp_type == ndis_parm_string)
782 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata);
788 * Initialize a Windows spinlock.
791 NdisAllocateSpinLock(lock)
792 ndis_spin_lock *lock;
794 KeInitializeSpinLock(&lock->nsl_spinlock);
799 * Destroy a Windows spinlock. This is a no-op for now. There are two reasons
800 * for this. One is that it's sort of superfluous: we don't have to do anything
801 * special to deallocate the spinlock. The other is that there are some buggy
802 * drivers which call NdisFreeSpinLock() _after_ calling NdisFreeMemory() on
803 * the block of memory in which the spinlock resides. (Yes, ADMtek, I'm
807 NdisFreeSpinLock(lock)
808 ndis_spin_lock *lock;
811 KeInitializeSpinLock(&lock->nsl_spinlock);
817 * Acquire a spinlock from IRQL <= DISPATCH_LEVEL.
821 NdisAcquireSpinLock(lock)
822 ndis_spin_lock *lock;
824 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
828 * Release a spinlock from IRQL == DISPATCH_LEVEL.
832 NdisReleaseSpinLock(lock)
833 ndis_spin_lock *lock;
835 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
839 * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL.
842 NdisDprAcquireSpinLock(lock)
843 ndis_spin_lock *lock;
845 KeAcquireSpinLockAtDpcLevel(&lock->nsl_spinlock);
849 * Release a spinlock without leaving IRQL == DISPATCH_LEVEL.
852 NdisDprReleaseSpinLock(lock)
853 ndis_spin_lock *lock;
855 KeReleaseSpinLockFromDpcLevel(&lock->nsl_spinlock);
859 NdisInitializeReadWriteLock(lock)
862 KeInitializeSpinLock(&lock->nrl_spinlock);
863 bzero((char *)&lock->nrl_rsvd, sizeof(lock->nrl_rsvd));
867 NdisAcquireReadWriteLock(ndis_rw_lock *lock, uint8_t writeacc,
868 ndis_lock_state *state)
870 if (writeacc == TRUE) {
871 KeAcquireSpinLock(&lock->nrl_spinlock, &state->nls_oldirql);
878 NdisReleaseReadWriteLock(lock, state)
880 ndis_lock_state *state;
882 if (lock->nrl_rsvd[0]) {
884 KeReleaseSpinLock(&lock->nrl_spinlock, state->nls_oldirql);
890 NdisReadPciSlotInformation(adapter, slot, offset, buf, len)
897 ndis_miniport_block *block;
902 block = (ndis_miniport_block *)adapter;
907 dev = block->nmb_physdeviceobj->do_devext;
910 * I have a test system consisting of a Sun w2100z
911 * dual 2.4Ghz Opteron machine and an Atheros 802.11a/b/g
912 * "Aries" miniPCI NIC. (The NIC is installed in the
913 * machine using a miniPCI to PCI bus adapter card.)
914 * When running in SMP mode, I found that
915 * performing a large number of consecutive calls to
916 * NdisReadPciSlotInformation() would result in a
917 * sudden system reset (or in some cases a freeze).
918 * My suspicion is that the multiple reads are somehow
919 * triggering a fatal PCI bus error that leads to a
920 * machine check. The 1us delay in the loop below
921 * seems to prevent this problem.
924 for (i = 0; i < len; i++) {
926 dest[i] = pci_read_config(dev, i + offset, 1);
933 NdisWritePciSlotInformation(adapter, slot, offset, buf, len)
940 ndis_miniport_block *block;
945 block = (ndis_miniport_block *)adapter;
951 dev = block->nmb_physdeviceobj->do_devext;
952 for (i = 0; i < len; i++) {
954 pci_write_config(dev, i + offset, dest[i], 1);
961 * The errorlog routine uses a variable argument list, so we
962 * have to declare it this way.
965 #define ERRMSGLEN 512
967 NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code,
968 uint32_t numerrors, ...)
970 ndis_miniport_block *block;
977 struct ndis_softc *sc;
980 ansi_string as = { 0, 0, NULL };
982 block = (ndis_miniport_block *)adapter;
983 dev = block->nmb_physdeviceobj->do_devext;
984 drv = block->nmb_deviceobj->do_drvobj;
985 sc = device_get_softc(dev);
988 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
989 error = pe_get_message((vm_offset_t)drv->dro_driverstart,
990 code, &str, &i, &flags);
992 if (flags & MESSAGE_RESOURCE_UNICODE) {
993 RtlInitUnicodeString(&us, (uint16_t *)str);
994 if (RtlUnicodeStringToAnsiString(&as,
995 &us, TRUE) == STATUS_SUCCESS)
1003 device_printf(dev, "NDIS ERROR: %x (%s)\n", code,
1004 str == NULL ? "unknown error" : str);
1006 if (ifp != NULL && ifp->if_flags & IFF_DEBUG) {
1007 device_printf(dev, "NDIS NUMERRORS: %x\n", numerrors);
1008 va_start(ap, numerrors);
1009 for (i = 0; i < numerrors; i++)
1010 device_printf(dev, "argptr: %p\n",
1011 va_arg(ap, void *));
1016 RtlFreeAnsiString(&as);
1020 ndis_map_cb(arg, segs, nseg, error)
1022 bus_dma_segment_t *segs;
1026 struct ndis_map_arg *ctx;
1034 for (i = 0; i < nseg; i++) {
1035 ctx->nma_fraglist[i].npu_physaddr.np_quad = segs[i].ds_addr;
1036 ctx->nma_fraglist[i].npu_len = segs[i].ds_len;
1039 ctx->nma_cnt = nseg;
1043 NdisMStartBufferPhysicalMapping(ndis_handle adapter, ndis_buffer *buf,
1044 uint32_t mapreg, uint8_t writedev, ndis_paddr_unit *addrarray,
1045 uint32_t *arraysize)
1047 ndis_miniport_block *block;
1048 struct ndis_softc *sc;
1049 struct ndis_map_arg nma;
1053 if (adapter == NULL)
1056 block = (ndis_miniport_block *)adapter;
1057 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1059 if (mapreg > sc->ndis_mmapcnt)
1062 map = sc->ndis_mmaps[mapreg];
1063 nma.nma_fraglist = addrarray;
1065 error = bus_dmamap_load(sc->ndis_mtag, map,
1066 MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb,
1067 (void *)&nma, BUS_DMA_NOWAIT);
1072 bus_dmamap_sync(sc->ndis_mtag, map,
1073 writedev ? BUS_DMASYNC_PREWRITE : BUS_DMASYNC_PREREAD);
1075 *arraysize = nma.nma_cnt;
1079 NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg)
1080 ndis_handle adapter;
1084 ndis_miniport_block *block;
1085 struct ndis_softc *sc;
1088 if (adapter == NULL)
1091 block = (ndis_miniport_block *)adapter;
1092 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1094 if (mapreg > sc->ndis_mmapcnt)
1097 map = sc->ndis_mmaps[mapreg];
1099 bus_dmamap_sync(sc->ndis_mtag, map,
1100 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1102 bus_dmamap_unload(sc->ndis_mtag, map);
1106 * This is an older (?) timer init routine which doesn't
1107 * accept a miniport context handle. Serialized miniports should
1108 * never call this function.
1112 NdisInitializeTimer(timer, func, ctx)
1114 ndis_timer_function func;
1117 KeInitializeTimer(&timer->nt_ktimer);
1118 KeInitializeDpc(&timer->nt_kdpc, func, ctx);
1119 KeSetImportanceDpc(&timer->nt_kdpc, KDPC_IMPORTANCE_LOW);
1123 ndis_timercall(dpc, timer, sysarg1, sysarg2)
1125 ndis_miniport_timer *timer;
1130 * Since we're called as a DPC, we should be running
1131 * at DISPATCH_LEVEL here. This means to acquire the
1132 * spinlock, we can use KeAcquireSpinLockAtDpcLevel()
1133 * rather than KeAcquireSpinLock().
1135 if (NDIS_SERIALIZED(timer->nmt_block))
1136 KeAcquireSpinLockAtDpcLevel(&timer->nmt_block->nmb_lock);
1138 MSCALL4(timer->nmt_timerfunc, dpc, timer->nmt_timerctx,
1141 if (NDIS_SERIALIZED(timer->nmt_block))
1142 KeReleaseSpinLockFromDpcLevel(&timer->nmt_block->nmb_lock);
1146 * For a long time I wondered why there were two NDIS timer initialization
1147 * routines, and why this one needed an NDIS_MINIPORT_TIMER and the
1148 * MiniportAdapterHandle. The NDIS_MINIPORT_TIMER has its own callout
1149 * function and context pointers separate from those in the DPC, which
1150 * allows for another level of indirection: when the timer fires, we
1151 * can have our own timer function invoked, and from there we can call
1152 * the driver's function. But why go to all that trouble? Then it hit
1153 * me: for serialized miniports, the timer callouts are not re-entrant.
1154 * By trapping the callouts and having access to the MiniportAdapterHandle,
1155 * we can protect the driver callouts by acquiring the NDIS serialization
1156 * lock. This is essential for allowing serialized miniports to work
1157 * correctly on SMP systems. On UP hosts, setting IRQL to DISPATCH_LEVEL
1158 * is enough to prevent other threads from pre-empting you, but with
1159 * SMP, you must acquire a lock as well, otherwise the other CPU is
1160 * free to clobber you.
1163 NdisMInitializeTimer(timer, handle, func, ctx)
1164 ndis_miniport_timer *timer;
1166 ndis_timer_function func;
1169 ndis_miniport_block *block;
1170 struct ndis_softc *sc;
1172 block = (ndis_miniport_block *)handle;
1173 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1175 /* Save the driver's funcptr and context */
1177 timer->nmt_timerfunc = func;
1178 timer->nmt_timerctx = ctx;
1179 timer->nmt_block = handle;
1182 * Set up the timer so it will call our intermediate DPC.
1183 * Be sure to use the wrapped entry point, since
1184 * ntoskrnl_run_dpc() expects to invoke a function with
1185 * Microsoft calling conventions.
1187 KeInitializeTimer(&timer->nmt_ktimer);
1188 KeInitializeDpc(&timer->nmt_kdpc,
1189 ndis_findwrap((funcptr)ndis_timercall), timer);
1190 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc;
1194 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(),
1195 * but the former is just a macro wrapper around the latter.
1198 NdisSetTimer(timer, msecs)
1203 * KeSetTimer() wants the period in
1204 * hundred nanosecond intervals.
1206 KeSetTimer(&timer->nt_ktimer,
1207 ((int64_t)msecs * -10000), &timer->nt_kdpc);
1211 NdisMSetPeriodicTimer(timer, msecs)
1212 ndis_miniport_timer *timer;
1215 KeSetTimerEx(&timer->nmt_ktimer,
1216 ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc);
1220 * Technically, this is really NdisCancelTimer(), but we also
1221 * (ab)use it for NdisMCancelTimer(), since in our implementation
1222 * we don't need the extra info in the ndis_miniport_timer
1223 * structure just to cancel a timer.
1227 NdisMCancelTimer(timer, cancelled)
1232 *cancelled = KeCancelTimer(&timer->nt_ktimer);
1236 NdisMQueryAdapterResources(status, adapter, list, buflen)
1237 ndis_status *status;
1238 ndis_handle adapter;
1239 ndis_resource_list *list;
1242 ndis_miniport_block *block;
1243 struct ndis_softc *sc;
1246 block = (ndis_miniport_block *)adapter;
1247 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1249 rsclen = sizeof(ndis_resource_list) +
1250 (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1));
1251 if (*buflen < rsclen) {
1253 *status = NDIS_STATUS_INVALID_LENGTH;
1257 bcopy((char *)block->nmb_rlist, (char *)list, rsclen);
1258 *status = NDIS_STATUS_SUCCESS;
1262 NdisMRegisterIoPortRange(offset, adapter, port, numports)
1264 ndis_handle adapter;
1268 struct ndis_miniport_block *block;
1269 struct ndis_softc *sc;
1271 if (adapter == NULL)
1272 return (NDIS_STATUS_FAILURE);
1274 block = (ndis_miniport_block *)adapter;
1275 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1277 if (sc->ndis_res_io == NULL)
1278 return (NDIS_STATUS_FAILURE);
1280 /* Don't let the device map more ports than we have. */
1281 if (rman_get_size(sc->ndis_res_io) < numports)
1282 return (NDIS_STATUS_INVALID_LENGTH);
1284 *offset = (void *)rman_get_start(sc->ndis_res_io);
1286 return (NDIS_STATUS_SUCCESS);
1290 NdisMDeregisterIoPortRange(adapter, port, numports, offset)
1291 ndis_handle adapter;
1299 NdisReadNetworkAddress(status, addr, addrlen, adapter)
1300 ndis_status *status;
1303 ndis_handle adapter;
1305 struct ndis_softc *sc;
1306 ndis_miniport_block *block;
1307 uint8_t empty[] = { 0, 0, 0, 0, 0, 0 };
1309 block = (ndis_miniport_block *)adapter;
1310 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1311 if (sc->ifp == NULL) {
1312 *status = NDIS_STATUS_FAILURE;
1316 if (sc->ifp->if_addr == NULL ||
1317 bcmp(IF_LLADDR(sc->ifp), empty, ETHER_ADDR_LEN) == 0)
1318 *status = NDIS_STATUS_FAILURE;
1320 *addr = IF_LLADDR(sc->ifp);
1321 *addrlen = ETHER_ADDR_LEN;
1322 *status = NDIS_STATUS_SUCCESS;
1327 NdisQueryMapRegisterCount(bustype, cnt)
1332 return (NDIS_STATUS_SUCCESS);
1336 NdisMAllocateMapRegisters(ndis_handle adapter, uint32_t dmachannel,
1337 uint8_t dmasize, uint32_t physmapneeded, uint32_t maxmap)
1339 struct ndis_softc *sc;
1340 ndis_miniport_block *block;
1341 int error, i, nseg = NDIS_MAXSEG;
1343 block = (ndis_miniport_block *)adapter;
1344 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1346 sc->ndis_mmaps = malloc(sizeof(bus_dmamap_t) * physmapneeded,
1347 M_DEVBUF, M_NOWAIT|M_ZERO);
1349 if (sc->ndis_mmaps == NULL)
1350 return (NDIS_STATUS_RESOURCES);
1352 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1353 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL,
1354 NULL, maxmap * nseg, nseg, maxmap, BUS_DMA_ALLOCNOW,
1355 NULL, NULL, &sc->ndis_mtag);
1358 free(sc->ndis_mmaps, M_DEVBUF);
1359 return (NDIS_STATUS_RESOURCES);
1362 for (i = 0; i < physmapneeded; i++)
1363 bus_dmamap_create(sc->ndis_mtag, 0, &sc->ndis_mmaps[i]);
1365 sc->ndis_mmapcnt = physmapneeded;
1367 return (NDIS_STATUS_SUCCESS);
1371 NdisMFreeMapRegisters(adapter)
1372 ndis_handle adapter;
1374 struct ndis_softc *sc;
1375 ndis_miniport_block *block;
1378 block = (ndis_miniport_block *)adapter;
1379 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1381 for (i = 0; i < sc->ndis_mmapcnt; i++)
1382 bus_dmamap_destroy(sc->ndis_mtag, sc->ndis_mmaps[i]);
1384 free(sc->ndis_mmaps, M_DEVBUF);
1386 bus_dma_tag_destroy(sc->ndis_mtag);
1390 ndis_mapshared_cb(arg, segs, nseg, error)
1392 bus_dma_segment_t *segs;
1398 if (error || nseg > 1)
1403 p->np_quad = segs[0].ds_addr;
1407 * This maps to bus_dmamem_alloc().
1411 NdisMAllocateSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1412 void **vaddr, ndis_physaddr *paddr)
1414 ndis_miniport_block *block;
1415 struct ndis_softc *sc;
1416 struct ndis_shmem *sh;
1419 if (adapter == NULL)
1422 block = (ndis_miniport_block *)adapter;
1423 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1425 sh = malloc(sizeof(struct ndis_shmem), M_DEVBUF, M_NOWAIT|M_ZERO);
1429 InitializeListHead(&sh->ndis_list);
1432 * When performing shared memory allocations, create a tag
1433 * with a lowaddr limit that restricts physical memory mappings
1434 * so that they all fall within the first 1GB of memory.
1435 * At least one device/driver combination (Linksys Instant
1436 * Wireless PCI Card V2.7, Broadcom 802.11b) seems to have
1437 * problems with performing DMA operations with physical
1438 * addresses that lie above the 1GB mark. I don't know if this
1439 * is a hardware limitation or if the addresses are being
1440 * truncated within the driver, but this seems to be the only
1441 * way to make these cards work reliably in systems with more
1442 * than 1GB of physical memory.
1445 error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
1446 0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1447 NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
1455 error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
1456 BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
1459 bus_dma_tag_destroy(sh->ndis_stag);
1464 error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
1465 len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
1468 bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
1469 bus_dma_tag_destroy(sh->ndis_stag);
1475 * Save the physical address along with the source address.
1476 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
1477 * with a bogus virtual address sometimes, but with a valid
1478 * physical address. To keep this from causing trouble, we
1479 * use the physical address to as a sanity check in case
1480 * searching based on the virtual address fails.
1484 sh->ndis_paddr.np_quad = paddr->np_quad;
1485 sh->ndis_saddr = *vaddr;
1486 InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
1490 struct ndis_allocwork {
1498 ndis_asyncmem_complete(dobj, arg)
1499 device_object *dobj;
1502 ndis_miniport_block *block;
1503 struct ndis_softc *sc;
1504 struct ndis_allocwork *w;
1506 ndis_physaddr paddr;
1507 ndis_allocdone_handler donefunc;
1510 block = (ndis_miniport_block *)dobj->do_devext;
1511 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1516 donefunc = sc->ndis_chars->nmc_allocate_complete_func;
1517 NdisMAllocateSharedMemory(block, w->na_len,
1518 w->na_cached, &vaddr, &paddr);
1519 MSCALL5(donefunc, block, vaddr, &paddr, w->na_len, w->na_ctx);
1521 IoFreeWorkItem(w->na_iw);
1526 NdisMAllocateSharedMemoryAsync(ndis_handle adapter, uint32_t len,
1527 uint8_t cached, void *ctx)
1529 ndis_miniport_block *block;
1530 struct ndis_allocwork *w;
1532 io_workitem_func ifw;
1534 if (adapter == NULL)
1535 return (NDIS_STATUS_FAILURE);
1539 iw = IoAllocateWorkItem(block->nmb_deviceobj);
1541 return (NDIS_STATUS_FAILURE);
1543 w = malloc(sizeof(struct ndis_allocwork), M_TEMP, M_NOWAIT);
1546 return (NDIS_STATUS_FAILURE);
1548 w->na_cached = cached;
1553 ifw = (io_workitem_func)ndis_findwrap((funcptr)ndis_asyncmem_complete);
1554 IoQueueWorkItem(iw, ifw, WORKQUEUE_DELAYED, w);
1556 return (NDIS_STATUS_PENDING);
1560 NdisMFreeSharedMemory(ndis_handle adapter, uint32_t len, uint8_t cached,
1561 void *vaddr, ndis_physaddr paddr)
1563 ndis_miniport_block *block;
1564 struct ndis_softc *sc;
1565 struct ndis_shmem *sh = NULL;
1568 if (vaddr == NULL || adapter == NULL)
1571 block = (ndis_miniport_block *)adapter;
1572 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1574 /* Sanity check: is list empty? */
1576 if (IsListEmpty(&sc->ndis_shlist))
1580 l = sc->ndis_shlist.nle_flink;
1581 while (l != &sc->ndis_shlist) {
1582 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
1583 if (sh->ndis_saddr == vaddr)
1586 * Check the physaddr too, just in case the driver lied
1587 * about the virtual address.
1589 if (sh->ndis_paddr.np_quad == paddr.np_quad)
1596 printf("NDIS: buggy driver tried to free "
1597 "invalid shared memory: vaddr: %p paddr: 0x%jx\n",
1598 vaddr, (uintmax_t)paddr.np_quad);
1602 RemoveEntryList(&sh->ndis_list);
1606 bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
1607 bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
1608 bus_dma_tag_destroy(sh->ndis_stag);
1614 NdisMMapIoSpace(vaddr, adapter, paddr, len)
1616 ndis_handle adapter;
1617 ndis_physaddr paddr;
1620 if (adapter == NULL)
1621 return (NDIS_STATUS_FAILURE);
1623 *vaddr = MmMapIoSpace(paddr.np_quad, len, 0);
1626 return (NDIS_STATUS_FAILURE);
1628 return (NDIS_STATUS_SUCCESS);
1632 NdisMUnmapIoSpace(adapter, vaddr, len)
1633 ndis_handle adapter;
1637 MmUnmapIoSpace(vaddr, len);
1641 NdisGetCacheFillSize(void)
1647 NdisGetRoutineAddress(ustr)
1648 unicode_string *ustr;
1652 if (RtlUnicodeStringToAnsiString(&astr, ustr, TRUE))
1654 return (ndis_get_routine_address(ndis_functbl, astr.as_buf));
1658 NdisMGetDmaAlignment(handle)
1665 * NDIS has two methods for dealing with NICs that support DMA.
1666 * One is to just pass packets to the driver and let it call
1667 * NdisMStartBufferPhysicalMapping() to map each buffer in the packet
1668 * all by itself, and the other is to let the NDIS library handle the
1669 * buffer mapping internally, and hand the driver an already populated
1670 * scatter/gather fragment list. If the driver calls
1671 * NdisMInitializeScatterGatherDma(), it wants to use the latter
1676 NdisMInitializeScatterGatherDma(ndis_handle adapter, uint8_t is64,
1677 uint32_t maxphysmap)
1679 struct ndis_softc *sc;
1680 ndis_miniport_block *block;
1683 if (adapter == NULL)
1684 return (NDIS_STATUS_FAILURE);
1685 block = (ndis_miniport_block *)adapter;
1686 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
1688 /* Don't do this twice. */
1689 if (sc->ndis_sc == 1)
1690 return (NDIS_STATUS_SUCCESS);
1692 error = bus_dma_tag_create(sc->ndis_parent_tag, ETHER_ALIGN, 0,
1693 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
1694 MCLBYTES * NDIS_MAXSEG, NDIS_MAXSEG, MCLBYTES, BUS_DMA_ALLOCNOW,
1695 NULL, NULL, &sc->ndis_ttag);
1699 return (NDIS_STATUS_SUCCESS);
1703 NdisAllocatePacketPool(status, pool, descnum, protrsvdlen)
1704 ndis_status *status;
1707 uint32_t protrsvdlen;
1709 ndis_packet_pool *p;
1710 ndis_packet *packets;
1713 p = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_packet_pool), 0);
1715 *status = NDIS_STATUS_RESOURCES;
1719 p->np_cnt = descnum + NDIS_POOL_EXTRA;
1720 p->np_protrsvd = protrsvdlen;
1721 p->np_len = sizeof(ndis_packet) + protrsvdlen;
1723 packets = ExAllocatePoolWithTag(NonPagedPool, p->np_cnt *
1727 if (packets == NULL) {
1729 *status = NDIS_STATUS_RESOURCES;
1733 p->np_pktmem = packets;
1735 for (i = 0; i < p->np_cnt; i++)
1736 InterlockedPushEntrySList(&p->np_head,
1737 (struct slist_entry *)&packets[i]);
1739 #ifdef NDIS_DEBUG_PACKETS
1741 KeInitializeSpinLock(&p->np_lock);
1742 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE);
1746 *status = NDIS_STATUS_SUCCESS;
1750 NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen)
1751 ndis_status *status;
1754 uint32_t oflowdescnum;
1755 uint32_t protrsvdlen;
1757 return (NdisAllocatePacketPool(status, pool,
1758 descnum + oflowdescnum, protrsvdlen));
1762 NdisPacketPoolUsage(pool)
1765 ndis_packet_pool *p;
1767 p = (ndis_packet_pool *)pool;
1768 return (p->np_cnt - ExQueryDepthSList(&p->np_head));
1772 NdisFreePacketPool(pool)
1775 ndis_packet_pool *p;
1777 #ifdef NDIS_DEBUG_PACKETS
1781 p = (ndis_packet_pool *)pool;
1783 #ifdef NDIS_DEBUG_PACKETS
1784 KeAcquireSpinLock(&p->np_lock, &irql);
1787 usage = NdisPacketPoolUsage(pool);
1789 #ifdef NDIS_DEBUG_PACKETS
1792 KeResetEvent(&p->np_event);
1793 KeReleaseSpinLock(&p->np_lock, irql);
1794 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL);
1796 KeReleaseSpinLock(&p->np_lock, irql);
1799 ExFreePool(p->np_pktmem);
1804 NdisAllocatePacket(status, packet, pool)
1805 ndis_status *status;
1806 ndis_packet **packet;
1809 ndis_packet_pool *p;
1811 #ifdef NDIS_DEBUG_PACKETS
1815 p = (ndis_packet_pool *)pool;
1817 #ifdef NDIS_DEBUG_PACKETS
1818 KeAcquireSpinLock(&p->np_lock, &irql);
1820 KeReleaseSpinLock(&p->np_lock, irql);
1821 printf("NDIS: tried to allocate packet from dead pool %p\n",
1823 *status = NDIS_STATUS_RESOURCES;
1828 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head);
1830 #ifdef NDIS_DEBUG_PACKETS
1831 KeReleaseSpinLock(&p->np_lock, irql);
1835 *status = NDIS_STATUS_RESOURCES;
1840 bzero((char *)pkt, sizeof(ndis_packet));
1842 /* Save pointer to the pool. */
1843 pkt->np_private.npp_pool = pool;
1845 /* Set the oob offset pointer. Lots of things expect this. */
1846 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob);
1849 * We must initialize the packet flags correctly in order
1850 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and
1851 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work
1854 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS;
1855 pkt->np_private.npp_validcounts = FALSE;
1859 *status = NDIS_STATUS_SUCCESS;
1863 NdisFreePacket(packet)
1864 ndis_packet *packet;
1866 ndis_packet_pool *p;
1867 #ifdef NDIS_DEBUG_PACKETS
1871 p = (ndis_packet_pool *)packet->np_private.npp_pool;
1873 #ifdef NDIS_DEBUG_PACKETS
1874 KeAcquireSpinLock(&p->np_lock, &irql);
1877 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet);
1879 #ifdef NDIS_DEBUG_PACKETS
1881 if (ExQueryDepthSList(&p->np_head) == p->np_cnt)
1882 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE);
1884 KeReleaseSpinLock(&p->np_lock, irql);
1889 NdisUnchainBufferAtFront(packet, buf)
1890 ndis_packet *packet;
1893 ndis_packet_private *priv;
1895 if (packet == NULL || buf == NULL)
1898 priv = &packet->np_private;
1900 priv->npp_validcounts = FALSE;
1902 if (priv->npp_head == priv->npp_tail) {
1903 *buf = priv->npp_head;
1904 priv->npp_head = priv->npp_tail = NULL;
1906 *buf = priv->npp_head;
1907 priv->npp_head = (*buf)->mdl_next;
1912 NdisUnchainBufferAtBack(packet, buf)
1913 ndis_packet *packet;
1916 ndis_packet_private *priv;
1919 if (packet == NULL || buf == NULL)
1922 priv = &packet->np_private;
1924 priv->npp_validcounts = FALSE;
1926 if (priv->npp_head == priv->npp_tail) {
1927 *buf = priv->npp_head;
1928 priv->npp_head = priv->npp_tail = NULL;
1930 *buf = priv->npp_tail;
1931 tmp = priv->npp_head;
1932 while (tmp->mdl_next != priv->npp_tail)
1933 tmp = tmp->mdl_next;
1934 priv->npp_tail = tmp;
1935 tmp->mdl_next = NULL;
1940 * The NDIS "buffer" is really an MDL (memory descriptor list)
1941 * which is used to describe a buffer in a way that allows it
1942 * to mapped into different contexts. We have to be careful how
1943 * we handle them: in some versions of Windows, the NdisFreeBuffer()
1944 * routine is an actual function in the NDIS API, but in others
1945 * it's just a macro wrapper around IoFreeMdl(). There's really
1946 * no way to use the 'descnum' parameter to count how many
1947 * "buffers" are allocated since in order to use IoFreeMdl() to
1948 * dispose of a buffer, we have to use IoAllocateMdl() to allocate
1949 * them, and IoAllocateMdl() just grabs them out of the heap.
1953 NdisAllocateBufferPool(status, pool, descnum)
1954 ndis_status *status;
1960 * The only thing we can really do here is verify that descnum
1961 * is a reasonable value, but I really don't know what to check
1965 *pool = NonPagedPool;
1966 *status = NDIS_STATUS_SUCCESS;
1970 NdisFreeBufferPool(pool)
1976 NdisAllocateBuffer(status, buffer, pool, vaddr, len)
1977 ndis_status *status;
1978 ndis_buffer **buffer;
1985 buf = IoAllocateMdl(vaddr, len, FALSE, FALSE, NULL);
1987 *status = NDIS_STATUS_RESOURCES;
1991 MmBuildMdlForNonPagedPool(buf);
1994 *status = NDIS_STATUS_SUCCESS;
2007 NdisBufferLength(buf)
2010 return (MmGetMdlByteCount(buf));
2014 * Get the virtual address and length of a buffer.
2015 * Note: the vaddr argument is optional.
2019 NdisQueryBuffer(buf, vaddr, len)
2025 *vaddr = MmGetMdlVirtualAddress(buf);
2026 *len = MmGetMdlByteCount(buf);
2029 /* Same as above -- we don't care about the priority. */
2032 NdisQueryBufferSafe(buf, vaddr, len, prio)
2039 *vaddr = MmGetMdlVirtualAddress(buf);
2040 *len = MmGetMdlByteCount(buf);
2043 /* Damnit Microsoft!! How many ways can you do the same thing?! */
2046 NdisBufferVirtualAddress(buf)
2049 return (MmGetMdlVirtualAddress(buf));
2053 NdisBufferVirtualAddressSafe(buf, prio)
2057 return (MmGetMdlVirtualAddress(buf));
2061 NdisAdjustBufferLength(buf, len)
2065 MmGetMdlByteCount(buf) = len;
2069 NdisInterlockedIncrement(addend)
2072 atomic_add_long((u_long *)addend, 1);
2077 NdisInterlockedDecrement(addend)
2080 atomic_subtract_long((u_long *)addend, 1);
2085 NdisGetVersion(void)
2087 return (0x00050001);
2091 NdisInitializeEvent(event)
2095 * NDIS events are always notification
2096 * events, and should be initialized to the
2097 * not signaled state.
2099 KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE);
2106 KeSetEvent(&event->ne_event, IO_NO_INCREMENT, FALSE);
2110 NdisResetEvent(event)
2113 KeResetEvent(&event->ne_event);
2117 NdisWaitEvent(event, msecs)
2124 duetime = ((int64_t)msecs * -10000);
2125 rval = KeWaitForSingleObject(event,
2126 0, 0, TRUE, msecs ? & duetime : NULL);
2128 if (rval == STATUS_TIMEOUT)
2135 NdisUnicodeStringToAnsiString(dstr, sstr)
2137 unicode_string *sstr;
2141 rval = RtlUnicodeStringToAnsiString(dstr, sstr, FALSE);
2143 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2144 return (NDIS_STATUS_RESOURCES);
2146 return (NDIS_STATUS_FAILURE);
2148 return (NDIS_STATUS_SUCCESS);
2152 NdisAnsiStringToUnicodeString(dstr, sstr)
2153 unicode_string *dstr;
2158 rval = RtlAnsiStringToUnicodeString(dstr, sstr, FALSE);
2160 if (rval == STATUS_INSUFFICIENT_RESOURCES)
2161 return (NDIS_STATUS_RESOURCES);
2163 return (NDIS_STATUS_FAILURE);
2165 return (NDIS_STATUS_SUCCESS);
2169 NdisMPciAssignResources(adapter, slot, list)
2170 ndis_handle adapter;
2172 ndis_resource_list **list;
2174 ndis_miniport_block *block;
2176 if (adapter == NULL || list == NULL)
2177 return (NDIS_STATUS_FAILURE);
2179 block = (ndis_miniport_block *)adapter;
2180 *list = block->nmb_rlist;
2182 return (NDIS_STATUS_SUCCESS);
2186 ndis_intr(iobj, arg)
2190 struct ndis_softc *sc;
2191 uint8_t is_our_intr = FALSE;
2193 ndis_miniport_interrupt *intr;
2196 intr = sc->ndis_block->nmb_interrupt;
2198 if (intr == NULL || sc->ndis_block->nmb_miniportadapterctx == NULL)
2201 if (sc->ndis_block->nmb_interrupt->ni_isrreq == TRUE)
2202 MSCALL3(intr->ni_isrfunc, &is_our_intr, &call_isr,
2203 sc->ndis_block->nmb_miniportadapterctx);
2205 MSCALL1(sc->ndis_chars->nmc_disable_interrupts_func,
2206 sc->ndis_block->nmb_miniportadapterctx);
2211 IoRequestDpc(sc->ndis_block->nmb_deviceobj, NULL, sc);
2213 return (is_our_intr);
2217 ndis_intrhand(dpc, intr, sysarg1, sysarg2)
2219 ndis_miniport_interrupt *intr;
2223 struct ndis_softc *sc;
2224 ndis_miniport_block *block;
2225 ndis_handle adapter;
2227 block = intr->ni_block;
2228 adapter = block->nmb_miniportadapterctx;
2229 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2231 if (NDIS_SERIALIZED(sc->ndis_block))
2232 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock);
2234 MSCALL1(intr->ni_dpcfunc, adapter);
2236 /* If there's a MiniportEnableInterrupt() routine, call it. */
2238 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL)
2239 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter);
2241 if (NDIS_SERIALIZED(sc->ndis_block))
2242 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock);
2245 * Set the completion event if we've drained all
2246 * pending interrupts.
2249 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock);
2251 if (intr->ni_dpccnt == 0)
2252 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE);
2253 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock);
2257 NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter,
2258 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared,
2259 ndis_interrupt_mode imode)
2261 ndis_miniport_block *block;
2262 ndis_miniport_characteristics *ch;
2263 struct ndis_softc *sc;
2267 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2268 ch = IoGetDriverObjectExtension(block->nmb_deviceobj->do_drvobj,
2271 intr->ni_rsvd = ExAllocatePoolWithTag(NonPagedPool,
2272 sizeof(struct mtx), 0);
2273 if (intr->ni_rsvd == NULL)
2274 return (NDIS_STATUS_RESOURCES);
2276 intr->ni_block = adapter;
2277 intr->ni_isrreq = reqisr;
2278 intr->ni_shared = shared;
2279 intr->ni_dpccnt = 0;
2280 intr->ni_isrfunc = ch->nmc_isr_func;
2281 intr->ni_dpcfunc = ch->nmc_interrupt_func;
2283 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE);
2284 KeInitializeDpc(&intr->ni_dpc,
2285 ndis_findwrap((funcptr)ndis_intrhand), intr);
2286 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW);
2288 error = IoConnectInterrupt(&intr->ni_introbj,
2289 ndis_findwrap((funcptr)ndis_intr), sc, NULL,
2290 ivec, ilevel, 0, imode, shared, 0, FALSE);
2292 if (error != STATUS_SUCCESS)
2293 return (NDIS_STATUS_FAILURE);
2295 block->nmb_interrupt = intr;
2297 return (NDIS_STATUS_SUCCESS);
2301 NdisMDeregisterInterrupt(intr)
2302 ndis_miniport_interrupt *intr;
2304 ndis_miniport_block *block;
2307 block = intr->ni_block;
2309 /* Should really be KeSynchronizeExecution() */
2311 KeAcquireSpinLock(intr->ni_introbj->ki_lock, &irql);
2312 block->nmb_interrupt = NULL;
2313 KeReleaseSpinLock(intr->ni_introbj->ki_lock, irql);
2315 KeFlushQueuedDpcs();
2317 /* Disconnect our ISR */
2319 IoDisconnectInterrupt(intr->ni_introbj);
2321 KeWaitForSingleObject(&intr->ni_dpcevt, 0, 0, FALSE, NULL);
2322 KeResetEvent(&intr->ni_dpcevt);
2326 NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc)
2327 ndis_handle adapter;
2329 ndis_shutdown_handler shutdownfunc;
2331 ndis_miniport_block *block;
2332 ndis_miniport_characteristics *chars;
2333 struct ndis_softc *sc;
2335 if (adapter == NULL)
2338 block = (ndis_miniport_block *)adapter;
2339 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2340 chars = sc->ndis_chars;
2342 chars->nmc_shutdown_handler = shutdownfunc;
2343 chars->nmc_rsvd0 = shutdownctx;
2347 NdisMDeregisterAdapterShutdownHandler(adapter)
2348 ndis_handle adapter;
2350 ndis_miniport_block *block;
2351 ndis_miniport_characteristics *chars;
2352 struct ndis_softc *sc;
2354 if (adapter == NULL)
2357 block = (ndis_miniport_block *)adapter;
2358 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2359 chars = sc->ndis_chars;
2361 chars->nmc_shutdown_handler = NULL;
2362 chars->nmc_rsvd0 = NULL;
2366 NDIS_BUFFER_TO_SPAN_PAGES(buf)
2371 if (MmGetMdlByteCount(buf) == 0)
2373 return (SPAN_PAGES(MmGetMdlVirtualAddress(buf),
2374 MmGetMdlByteCount(buf)));
2378 NdisGetBufferPhysicalArraySize(buf, pages)
2385 *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf);
2389 NdisQueryBufferOffset(buf, off, len)
2397 *off = MmGetMdlByteOffset(buf);
2398 *len = MmGetMdlByteCount(buf);
2408 * During system bootstrap, (i.e. cold == 1), we aren't
2409 * allowed to sleep, so we have to do a hard DELAY()
2416 KeInitializeTimer(&timer);
2417 KeSetTimer(&timer, ((int64_t)usecs * -10), NULL);
2418 KeWaitForSingleObject(&timer, 0, 0, FALSE, NULL);
2423 NdisReadPcmciaAttributeMemory(handle, offset, buf, len)
2429 struct ndis_softc *sc;
2430 ndis_miniport_block *block;
2431 bus_space_handle_t bh;
2439 block = (ndis_miniport_block *)handle;
2440 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2443 bh = rman_get_bushandle(sc->ndis_res_am);
2444 bt = rman_get_bustag(sc->ndis_res_am);
2446 for (i = 0; i < len; i++)
2447 dest[i] = bus_space_read_1(bt, bh, (offset + i) * 2);
2453 NdisWritePcmciaAttributeMemory(handle, offset, buf, len)
2459 struct ndis_softc *sc;
2460 ndis_miniport_block *block;
2461 bus_space_handle_t bh;
2469 block = (ndis_miniport_block *)handle;
2470 sc = device_get_softc(block->nmb_physdeviceobj->do_devext);
2473 bh = rman_get_bushandle(sc->ndis_res_am);
2474 bt = rman_get_bustag(sc->ndis_res_am);
2476 for (i = 0; i < len; i++)
2477 bus_space_write_1(bt, bh, (offset + i) * 2, src[i]);
2483 NdisInterlockedInsertHeadList(head, entry, lock)
2486 ndis_spin_lock *lock;
2490 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2491 flink = head->nle_flink;
2492 entry->nle_flink = flink;
2493 entry->nle_blink = head;
2494 flink->nle_blink = entry;
2495 head->nle_flink = entry;
2496 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2502 NdisInterlockedRemoveHeadList(head, lock)
2504 ndis_spin_lock *lock;
2509 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2510 entry = head->nle_flink;
2511 flink = entry->nle_flink;
2512 head->nle_flink = flink;
2513 flink->nle_blink = head;
2514 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2520 NdisInterlockedInsertTailList(head, entry, lock)
2523 ndis_spin_lock *lock;
2527 KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql);
2528 blink = head->nle_blink;
2529 entry->nle_flink = head;
2530 entry->nle_blink = blink;
2531 blink->nle_flink = entry;
2532 head->nle_blink = entry;
2533 KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql);
2539 NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx)
2540 ndis_miniport_interrupt *intr;
2544 return (KeSynchronizeExecution(intr->ni_introbj, syncfunc, syncctx));
2548 NdisGetCurrentSystemTime(tval)
2551 ntoskrnl_time(tval);
2555 * Return the number of milliseconds since the system booted.
2558 NdisGetSystemUpTime(tval)
2564 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
2568 NdisInitializeString(dst, src)
2569 unicode_string *dst;
2573 RtlInitAnsiString(&as, src);
2574 RtlAnsiStringToUnicodeString(dst, &as, TRUE);
2579 unicode_string *str;
2581 RtlFreeUnicodeString(str);
2585 NdisMRemoveMiniport(adapter)
2586 ndis_handle *adapter;
2588 return (NDIS_STATUS_SUCCESS);
2592 NdisInitAnsiString(dst, src)
2596 RtlInitAnsiString(dst, src);
2600 NdisInitUnicodeString(dst, src)
2601 unicode_string *dst;
2604 RtlInitUnicodeString(dst, src);
2607 static void NdisMGetDeviceProperty(adapter, phydevobj,
2608 funcdevobj, nextdevobj, resources, transresources)
2609 ndis_handle adapter;
2610 device_object **phydevobj;
2611 device_object **funcdevobj;
2612 device_object **nextdevobj;
2613 cm_resource_list *resources;
2614 cm_resource_list *transresources;
2616 ndis_miniport_block *block;
2618 block = (ndis_miniport_block *)adapter;
2620 if (phydevobj != NULL)
2621 *phydevobj = block->nmb_physdeviceobj;
2622 if (funcdevobj != NULL)
2623 *funcdevobj = block->nmb_deviceobj;
2624 if (nextdevobj != NULL)
2625 *nextdevobj = block->nmb_nextdeviceobj;
2629 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen)
2630 ndis_packet *packet;
2638 tmp = packet->np_private.npp_head;
2642 *firstlen = *totlen = 0;
2644 *firstva = MmGetMdlVirtualAddress(tmp);
2645 *firstlen = *totlen = MmGetMdlByteCount(tmp);
2646 for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next)
2647 *totlen += MmGetMdlByteCount(tmp);
2652 NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio)
2653 ndis_packet *packet;
2660 NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen);
2664 ndis_find_sym(lf, filename, suffix, sym)
2674 fullsym = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2675 if (fullsym == NULL)
2678 bzero(fullsym, MAXPATHLEN);
2679 strncpy(fullsym, filename, MAXPATHLEN);
2680 if (strlen(filename) < 4) {
2681 ExFreePool(fullsym);
2685 /* If the filename has a .ko suffix, strip if off. */
2686 suf = fullsym + (strlen(filename) - 3);
2687 if (strcmp(suf, ".ko") == 0)
2690 for (i = 0; i < strlen(fullsym); i++) {
2691 if (fullsym[i] == '.')
2694 fullsym[i] = tolower(fullsym[i]);
2696 strcat(fullsym, suffix);
2697 *sym = linker_file_lookup_symbol(lf, fullsym, 0);
2698 ExFreePool(fullsym);
2705 struct ndis_checkmodule {
2711 * See if a single module contains the symbols for a specified file.
2714 NdisCheckModule(linker_file_t lf, void *context)
2716 struct ndis_checkmodule *nc;
2717 caddr_t kldstart, kldend;
2719 nc = (struct ndis_checkmodule *)context;
2720 if (ndis_find_sym(lf, nc->afilename, "_start", &kldstart))
2722 if (ndis_find_sym(lf, nc->afilename, "_end", &kldend))
2725 nc->fh->nf_map = NULL;
2726 nc->fh->nf_type = NDIS_FH_TYPE_MODULE;
2727 nc->fh->nf_maplen = (kldend - kldstart) & 0xFFFFFFFF;
2731 /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */
2733 NdisOpenFile(status, filehandle, filelength, filename, highestaddr)
2734 ndis_status *status;
2735 ndis_handle *filehandle;
2736 uint32_t *filelength;
2737 unicode_string *filename;
2738 ndis_physaddr highestaddr;
2741 char *afilename = NULL;
2742 struct thread *td = curthread;
2743 struct nameidata nd;
2744 int flags, error, vfslocked;
2746 struct vattr *vap = &vat;
2749 struct ndis_checkmodule nc;
2751 if (RtlUnicodeStringToAnsiString(&as, filename, TRUE)) {
2752 *status = NDIS_STATUS_RESOURCES;
2756 afilename = strdup(as.as_buf, M_DEVBUF);
2757 RtlFreeAnsiString(&as);
2759 fh = ExAllocatePoolWithTag(NonPagedPool, sizeof(ndis_fh), 0);
2761 free(afilename, M_DEVBUF);
2762 *status = NDIS_STATUS_RESOURCES;
2766 fh->nf_name = afilename;
2769 * During system bootstrap, it's impossible to load files
2770 * from the rootfs since it's not mounted yet. We therefore
2771 * offer the possibility of opening files that have been
2772 * preloaded as modules instead. Both choices will work
2773 * when kldloading a module from multiuser, but only the
2774 * module option will work during bootstrap. The module
2775 * loading option works by using the ndiscvt(8) utility
2776 * to convert the arbitrary file into a .ko using objcopy(1).
2777 * This file will contain two special symbols: filename_start
2778 * and filename_end. All we have to do is traverse the KLD
2779 * list in search of those symbols and we've found the file
2780 * data. As an added bonus, ndiscvt(8) will also generate
2781 * a normal .o file which can be linked statically with
2782 * the kernel. This means that the symbols will actual reside
2783 * in the kernel's symbol table, but that doesn't matter to
2784 * us since the kernel appears to us as just another module.
2787 nc.afilename = afilename;
2789 if (linker_file_foreach(NdisCheckModule, &nc)) {
2790 *filelength = fh->nf_maplen;
2792 *status = NDIS_STATUS_SUCCESS;
2796 if (TAILQ_EMPTY(&mountlist)) {
2798 *status = NDIS_STATUS_FILE_NOT_FOUND;
2799 printf("NDIS: could not find file %s in linker list\n",
2801 printf("NDIS: and no filesystems mounted yet, "
2802 "aborting NdisOpenFile()\n");
2803 free(afilename, M_DEVBUF);
2807 path = ExAllocatePoolWithTag(NonPagedPool, MAXPATHLEN, 0);
2810 free(afilename, M_DEVBUF);
2811 *status = NDIS_STATUS_RESOURCES;
2815 snprintf(path, MAXPATHLEN, "%s/%s", ndis_filepath, afilename);
2817 /* Some threads don't have a current working directory. */
2819 if (td->td_proc->p_fd->fd_rdir == NULL)
2820 td->td_proc->p_fd->fd_rdir = rootvnode;
2821 if (td->td_proc->p_fd->fd_cdir == NULL)
2822 td->td_proc->p_fd->fd_cdir = rootvnode;
2824 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td);
2827 error = vn_open(&nd, &flags, 0, NULL);
2829 *status = NDIS_STATUS_FILE_NOT_FOUND;
2831 printf("NDIS: open file %s failed: %d\n", path, error);
2833 free(afilename, M_DEVBUF);
2836 vfslocked = NDHASGIANT(&nd);
2840 NDFREE(&nd, NDF_ONLY_PNBUF);
2842 /* Get the file size. */
2843 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred);
2844 VOP_UNLOCK(nd.ni_vp, 0);
2845 VFS_UNLOCK_GIANT(vfslocked);
2847 fh->nf_vp = nd.ni_vp;
2849 fh->nf_type = NDIS_FH_TYPE_VFS;
2851 *filelength = fh->nf_maplen = vap->va_size & 0xFFFFFFFF;
2852 *status = NDIS_STATUS_SUCCESS;
2856 NdisMapFile(status, mappedbuffer, filehandle)
2857 ndis_status *status;
2858 void **mappedbuffer;
2859 ndis_handle filehandle;
2862 struct thread *td = curthread;
2865 int error, vfslocked;
2869 if (filehandle == NULL) {
2870 *status = NDIS_STATUS_FAILURE;
2874 fh = (ndis_fh *)filehandle;
2876 if (fh->nf_vp == NULL) {
2877 *status = NDIS_STATUS_FAILURE;
2881 if (fh->nf_map != NULL) {
2882 *status = NDIS_STATUS_ALREADY_MAPPED;
2886 if (fh->nf_type == NDIS_FH_TYPE_MODULE) {
2888 if (ndis_find_sym(lf, fh->nf_name, "_start", &kldstart)) {
2889 *status = NDIS_STATUS_FAILURE;
2892 fh->nf_map = kldstart;
2893 *status = NDIS_STATUS_SUCCESS;
2894 *mappedbuffer = fh->nf_map;
2898 fh->nf_map = ExAllocatePoolWithTag(NonPagedPool, fh->nf_maplen, 0);
2900 if (fh->nf_map == NULL) {
2901 *status = NDIS_STATUS_RESOURCES;
2906 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2907 error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0,
2908 UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td);
2909 VFS_UNLOCK_GIANT(vfslocked);
2912 *status = NDIS_STATUS_FAILURE;
2914 *status = NDIS_STATUS_SUCCESS;
2915 *mappedbuffer = fh->nf_map;
2920 NdisUnmapFile(filehandle)
2921 ndis_handle filehandle;
2924 fh = (ndis_fh *)filehandle;
2926 if (fh->nf_map == NULL)
2929 if (fh->nf_type == NDIS_FH_TYPE_VFS)
2930 ExFreePool(fh->nf_map);
2935 NdisCloseFile(filehandle)
2936 ndis_handle filehandle;
2938 struct thread *td = curthread;
2943 if (filehandle == NULL)
2946 fh = (ndis_fh *)filehandle;
2947 if (fh->nf_map != NULL) {
2948 if (fh->nf_type == NDIS_FH_TYPE_VFS)
2949 ExFreePool(fh->nf_map);
2953 if (fh->nf_vp == NULL)
2956 if (fh->nf_type == NDIS_FH_TYPE_VFS) {
2958 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2959 vn_close(vp, FREAD, td->td_ucred, td);
2960 VFS_UNLOCK_GIANT(vfslocked);
2964 free(fh->nf_name, M_DEVBUF);
2969 NdisSystemProcessorCount()
2975 NdisGetCurrentProcessorCounts(idle_count, kernel_and_user, index)
2976 uint32_t *idle_count;
2977 uint32_t *kernel_and_user;
2982 pcpu = pcpu_find(curthread->td_oncpu);
2983 *index = pcpu->pc_cpuid;
2984 *idle_count = pcpu->pc_cp_time[CP_IDLE];
2985 *kernel_and_user = pcpu->pc_cp_time[CP_INTR];
2988 typedef void (*ndis_statusdone_handler)(ndis_handle);
2989 typedef void (*ndis_status_handler)(ndis_handle, ndis_status,
2993 NdisMIndicateStatusComplete(adapter)
2994 ndis_handle adapter;
2996 ndis_miniport_block *block;
2997 ndis_statusdone_handler statusdonefunc;
2999 block = (ndis_miniport_block *)adapter;
3000 statusdonefunc = block->nmb_statusdone_func;
3002 MSCALL1(statusdonefunc, adapter);
3006 NdisMIndicateStatus(adapter, status, sbuf, slen)
3007 ndis_handle adapter;
3012 ndis_miniport_block *block;
3013 ndis_status_handler statusfunc;
3015 block = (ndis_miniport_block *)adapter;
3016 statusfunc = block->nmb_status_func;
3018 MSCALL4(statusfunc, adapter, status, sbuf, slen);
3022 * The DDK documentation says that you should use IoQueueWorkItem()
3023 * instead of ExQueueWorkItem(). The problem is, IoQueueWorkItem()
3024 * is fundamentally incompatible with NdisScheduleWorkItem(), which
3025 * depends on the API semantics of ExQueueWorkItem(). In our world,
3026 * ExQueueWorkItem() is implemented on top of IoAllocateQueueItem()
3029 * There are actually three distinct APIs here. NdisScheduleWorkItem()
3030 * takes a pointer to an NDIS_WORK_ITEM. ExQueueWorkItem() takes a pointer
3031 * to a WORK_QUEUE_ITEM. And finally, IoQueueWorkItem() takes a pointer
3032 * to an opaque work item thingie which you get from IoAllocateWorkItem().
3033 * An NDIS_WORK_ITEM is not the same as a WORK_QUEUE_ITEM. However,
3034 * the NDIS_WORK_ITEM has some opaque storage at the end of it, and we
3035 * (ab)use this storage as a WORK_QUEUE_ITEM, which is what we submit
3036 * to ExQueueWorkItem().
3038 * Got all that? (Sheesh.)
3042 NdisScheduleWorkItem(work)
3043 ndis_work_item *work;
3045 work_queue_item *wqi;
3047 wqi = (work_queue_item *)work->nwi_wraprsvd;
3048 ExInitializeWorkItem(wqi,
3049 (work_item_func)work->nwi_func, work->nwi_ctx);
3050 ExQueueWorkItem(wqi, WORKQUEUE_DELAYED);
3052 return (NDIS_STATUS_SUCCESS);
3056 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen)
3064 ndis_buffer *src, *dst;
3066 int resid, copied, len, scnt, dcnt;
3070 src = spkt->np_private.npp_head;
3071 dst = dpkt->np_private.npp_head;
3073 sptr = MmGetMdlVirtualAddress(src);
3074 dptr = MmGetMdlVirtualAddress(dst);
3075 scnt = MmGetMdlByteCount(src);
3076 dcnt = MmGetMdlByteCount(dst);
3079 if (MmGetMdlByteCount(src) > soff) {
3081 scnt = MmGetMdlByteCount(src)- soff;
3084 soff -= MmGetMdlByteCount(src);
3085 src = src->mdl_next;
3088 sptr = MmGetMdlVirtualAddress(src);
3092 if (MmGetMdlByteCount(dst) > doff) {
3094 dcnt = MmGetMdlByteCount(dst) - doff;
3097 doff -= MmGetMdlByteCount(dst);
3098 dst = dst->mdl_next;
3101 dptr = MmGetMdlVirtualAddress(dst);
3115 bcopy(sptr, dptr, len);
3124 dst = dst->mdl_next;
3127 dptr = MmGetMdlVirtualAddress(dst);
3128 dcnt = MmGetMdlByteCount(dst);
3133 src = src->mdl_next;
3136 sptr = MmGetMdlVirtualAddress(src);
3137 scnt = MmGetMdlByteCount(src);
3145 NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio)
3154 NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen);
3158 NdisIMCopySendPerPacketInfo(dpkt, spkt)
3162 memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension));
3166 NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle)
3168 unicode_string *devname;
3169 unicode_string *symname;
3170 driver_dispatch *majorfuncs[];
3172 ndis_handle *devhandle;
3175 device_object *dobj;
3177 status = IoCreateDevice(handle, 0, devname,
3178 FILE_DEVICE_UNKNOWN, 0, FALSE, &dobj);
3180 if (status == STATUS_SUCCESS) {
3189 NdisMDeregisterDevice(handle)
3192 IoDeleteDevice(handle);
3193 return (NDIS_STATUS_SUCCESS);
3197 NdisMQueryAdapterInstanceName(name, handle)
3198 unicode_string *name;
3201 ndis_miniport_block *block;
3205 block = (ndis_miniport_block *)handle;
3206 dev = block->nmb_physdeviceobj->do_devext;
3208 RtlInitAnsiString(&as, __DECONST(char *, device_get_nameunit(dev)));
3209 if (RtlAnsiStringToUnicodeString(name, &as, TRUE))
3210 return (NDIS_STATUS_RESOURCES);
3212 return (NDIS_STATUS_SUCCESS);
3216 NdisMRegisterUnloadHandler(handle, func)
3225 printf("NDIS dummy called...\n");
3229 * Note: a couple of entries in this table specify the
3230 * number of arguments as "foo + 1". These are routines
3231 * that accept a 64-bit argument, passed by value. On
3232 * x86, these arguments consume two longwords on the stack,
3233 * so we lie and say there's one additional argument so
3234 * that the wrapping routines will do the right thing.
3237 image_patch_table ndis_functbl[] = {
3238 IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6),
3239 IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7),
3240 IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2),
3241 IMPORT_SFUNC(NdisScheduleWorkItem, 1),
3242 IMPORT_SFUNC(NdisMIndicateStatusComplete, 1),
3243 IMPORT_SFUNC(NdisMIndicateStatus, 4),
3244 IMPORT_SFUNC(NdisSystemProcessorCount, 0),
3245 IMPORT_SFUNC(NdisGetCurrentProcessorCounts, 3),
3246 IMPORT_SFUNC(NdisUnchainBufferAtBack, 2),
3247 IMPORT_SFUNC(NdisGetFirstBufferFromPacket, 5),
3248 IMPORT_SFUNC(NdisGetFirstBufferFromPacketSafe, 6),
3249 IMPORT_SFUNC(NdisGetBufferPhysicalArraySize, 2),
3250 IMPORT_SFUNC(NdisMGetDeviceProperty, 6),
3251 IMPORT_SFUNC(NdisInitAnsiString, 2),
3252 IMPORT_SFUNC(NdisInitUnicodeString, 2),
3253 IMPORT_SFUNC(NdisWriteConfiguration, 4),
3254 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2),
3255 IMPORT_SFUNC(NdisTerminateWrapper, 2),
3256 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4),
3257 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5),
3258 IMPORT_SFUNC(NdisMRemoveMiniport, 1),
3259 IMPORT_SFUNC(NdisInitializeString, 2),
3260 IMPORT_SFUNC(NdisFreeString, 1),
3261 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1),
3262 IMPORT_SFUNC(NdisGetRoutineAddress, 1),
3263 IMPORT_SFUNC(NdisGetSystemUpTime, 1),
3264 IMPORT_SFUNC(NdisGetVersion, 0),
3265 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3),
3266 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4),
3267 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3),
3268 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3),
3269 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2),
3270 IMPORT_SFUNC(NdisInitializeWrapper, 4),
3271 IMPORT_SFUNC(NdisMRegisterMiniport, 3),
3272 IMPORT_SFUNC(NdisAllocateMemoryWithTag, 3),
3273 IMPORT_SFUNC(NdisAllocateMemory, 4 + 1),
3274 IMPORT_SFUNC(NdisMSetAttributesEx, 5),
3275 IMPORT_SFUNC(NdisCloseConfiguration, 1),
3276 IMPORT_SFUNC(NdisReadConfiguration, 5),
3277 IMPORT_SFUNC(NdisOpenConfiguration, 3),
3278 IMPORT_SFUNC(NdisAcquireSpinLock, 1),
3279 IMPORT_SFUNC(NdisReleaseSpinLock, 1),
3280 IMPORT_SFUNC(NdisDprAcquireSpinLock, 1),
3281 IMPORT_SFUNC(NdisDprReleaseSpinLock, 1),
3282 IMPORT_SFUNC(NdisAllocateSpinLock, 1),
3283 IMPORT_SFUNC(NdisInitializeReadWriteLock, 1),
3284 IMPORT_SFUNC(NdisAcquireReadWriteLock, 3),
3285 IMPORT_SFUNC(NdisReleaseReadWriteLock, 2),
3286 IMPORT_SFUNC(NdisFreeSpinLock, 1),
3287 IMPORT_SFUNC(NdisFreeMemory, 3),
3288 IMPORT_SFUNC(NdisReadPciSlotInformation, 5),
3289 IMPORT_SFUNC(NdisWritePciSlotInformation, 5),
3290 IMPORT_SFUNC_MAP(NdisImmediateReadPciSlotInformation,
3291 NdisReadPciSlotInformation, 5),
3292 IMPORT_SFUNC_MAP(NdisImmediateWritePciSlotInformation,
3293 NdisWritePciSlotInformation, 5),
3294 IMPORT_CFUNC(NdisWriteErrorLogEntry, 0),
3295 IMPORT_SFUNC(NdisMStartBufferPhysicalMapping, 6),
3296 IMPORT_SFUNC(NdisMCompleteBufferPhysicalMapping, 3),
3297 IMPORT_SFUNC(NdisMInitializeTimer, 4),
3298 IMPORT_SFUNC(NdisInitializeTimer, 3),
3299 IMPORT_SFUNC(NdisSetTimer, 2),
3300 IMPORT_SFUNC(NdisMCancelTimer, 2),
3301 IMPORT_SFUNC_MAP(NdisCancelTimer, NdisMCancelTimer, 2),
3302 IMPORT_SFUNC(NdisMSetPeriodicTimer, 2),
3303 IMPORT_SFUNC(NdisMQueryAdapterResources, 4),
3304 IMPORT_SFUNC(NdisMRegisterIoPortRange, 4),
3305 IMPORT_SFUNC(NdisMDeregisterIoPortRange, 4),
3306 IMPORT_SFUNC(NdisReadNetworkAddress, 4),
3307 IMPORT_SFUNC(NdisQueryMapRegisterCount, 2),
3308 IMPORT_SFUNC(NdisMAllocateMapRegisters, 5),
3309 IMPORT_SFUNC(NdisMFreeMapRegisters, 1),
3310 IMPORT_SFUNC(NdisMAllocateSharedMemory, 5),
3311 IMPORT_SFUNC(NdisMMapIoSpace, 4 + 1),
3312 IMPORT_SFUNC(NdisMUnmapIoSpace, 3),
3313 IMPORT_SFUNC(NdisGetCacheFillSize, 0),
3314 IMPORT_SFUNC(NdisMGetDmaAlignment, 1),
3315 IMPORT_SFUNC(NdisMInitializeScatterGatherDma, 3),
3316 IMPORT_SFUNC(NdisAllocatePacketPool, 4),
3317 IMPORT_SFUNC(NdisAllocatePacketPoolEx, 5),
3318 IMPORT_SFUNC(NdisAllocatePacket, 3),
3319 IMPORT_SFUNC(NdisFreePacket, 1),
3320 IMPORT_SFUNC(NdisFreePacketPool, 1),
3321 IMPORT_SFUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket, 3),
3322 IMPORT_SFUNC_MAP(NdisDprFreePacket, NdisFreePacket, 1),
3323 IMPORT_SFUNC(NdisAllocateBufferPool, 3),
3324 IMPORT_SFUNC(NdisAllocateBuffer, 5),
3325 IMPORT_SFUNC(NdisQueryBuffer, 3),
3326 IMPORT_SFUNC(NdisQueryBufferSafe, 4),
3327 IMPORT_SFUNC(NdisBufferVirtualAddress, 1),
3328 IMPORT_SFUNC(NdisBufferVirtualAddressSafe, 2),
3329 IMPORT_SFUNC(NdisBufferLength, 1),
3330 IMPORT_SFUNC(NdisFreeBuffer, 1),
3331 IMPORT_SFUNC(NdisFreeBufferPool, 1),
3332 IMPORT_SFUNC(NdisInterlockedIncrement, 1),
3333 IMPORT_SFUNC(NdisInterlockedDecrement, 1),
3334 IMPORT_SFUNC(NdisInitializeEvent, 1),
3335 IMPORT_SFUNC(NdisSetEvent, 1),
3336 IMPORT_SFUNC(NdisResetEvent, 1),
3337 IMPORT_SFUNC(NdisWaitEvent, 2),
3338 IMPORT_SFUNC(NdisUnicodeStringToAnsiString, 2),
3339 IMPORT_SFUNC(NdisMPciAssignResources, 3),
3340 IMPORT_SFUNC(NdisMFreeSharedMemory, 5 + 1),
3341 IMPORT_SFUNC(NdisMRegisterInterrupt, 7),
3342 IMPORT_SFUNC(NdisMDeregisterInterrupt, 1),
3343 IMPORT_SFUNC(NdisMRegisterAdapterShutdownHandler, 3),
3344 IMPORT_SFUNC(NdisMDeregisterAdapterShutdownHandler, 1),
3345 IMPORT_SFUNC(NDIS_BUFFER_TO_SPAN_PAGES, 1),
3346 IMPORT_SFUNC(NdisQueryBufferOffset, 3),
3347 IMPORT_SFUNC(NdisAdjustBufferLength, 2),
3348 IMPORT_SFUNC(NdisPacketPoolUsage, 1),
3349 IMPORT_SFUNC(NdisMSleep, 1),
3350 IMPORT_SFUNC(NdisUnchainBufferAtFront, 2),
3351 IMPORT_SFUNC(NdisReadPcmciaAttributeMemory, 4),
3352 IMPORT_SFUNC(NdisWritePcmciaAttributeMemory, 4),
3353 IMPORT_SFUNC(NdisOpenFile, 5 + 1),
3354 IMPORT_SFUNC(NdisMapFile, 3),
3355 IMPORT_SFUNC(NdisUnmapFile, 1),
3356 IMPORT_SFUNC(NdisCloseFile, 1),
3357 IMPORT_SFUNC(NdisMRegisterDevice, 6),
3358 IMPORT_SFUNC(NdisMDeregisterDevice, 1),
3359 IMPORT_SFUNC(NdisMQueryAdapterInstanceName, 2),
3360 IMPORT_SFUNC(NdisMRegisterUnloadHandler, 2),
3361 IMPORT_SFUNC(ndis_timercall, 4),
3362 IMPORT_SFUNC(ndis_asyncmem_complete, 2),
3363 IMPORT_SFUNC(ndis_intr, 2),
3364 IMPORT_SFUNC(ndis_intrhand, 4),
3367 * This last entry is a catch-all for any function we haven't
3368 * implemented yet. The PE import list patching routine will
3369 * use it for any function that doesn't have an explicit match
3373 { NULL, (FUNC)dummy, NULL, 0, WINDRV_WRAP_STDCALL },
3377 { NULL, NULL, NULL }