subr_ndis.c (189004) | subr_ndis.c (189488) |
---|---|
1/*- 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 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. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 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. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_ndis.c 189004 2009-02-24 18:09:31Z rdivacky $"); | 34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_ndis.c 189488 2009-03-07 07:26:22Z weongyo $"); |
35 36/* 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 --- 47 unchanged lines hidden (view full) --- 90 91#include <machine/stdarg.h> 92 93#include <net80211/ieee80211_var.h> 94#include <net80211/ieee80211_ioctl.h> 95 96#include <dev/pci/pcireg.h> 97#include <dev/pci/pcivar.h> | 35 36/* 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 --- 47 unchanged lines hidden (view full) --- 90 91#include <machine/stdarg.h> 92 93#include <net80211/ieee80211_var.h> 94#include <net80211/ieee80211_ioctl.h> 95 96#include <dev/pci/pcireg.h> 97#include <dev/pci/pcivar.h> |
98#include <legacy/dev/usb/usb.h> 99#include <legacy/dev/usb/usbdi.h> | 98#include 99#include <dev/usb/usb_core.h> |
100 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> 108 109#include <vm/vm.h> 110#include <vm/vm_param.h> 111#include <vm/pmap.h> 112#include <vm/uma.h> 113#include <vm/vm_kern.h> 114#include <vm/vm_map.h> 115 116static char ndis_filepath[MAXPATHLEN]; 117 118SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath, | 100 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> 108 109#include <vm/vm.h> 110#include <vm/vm_param.h> 111#include <vm/pmap.h> 112#include <vm/uma.h> 113#include <vm/vm_kern.h> 114#include <vm/vm_map.h> 115 116static char ndis_filepath[MAXPATHLEN]; 117 118SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath, |
119 MAXPATHLEN, "Path used by NdisOpenFile() to search for files"); | 119 MAXPATHLEN, "Path used by NdisOpenFile() to search for files"); |
120 121static void NdisInitializeWrapper(ndis_handle *, 122 driver_object *, void *, void *); 123static ndis_status NdisMRegisterMiniport(ndis_handle, 124 ndis_miniport_characteristics *, int); 125static ndis_status NdisAllocateMemoryWithTag(void **, 126 uint32_t, uint32_t); 127static ndis_status NdisAllocateMemory(void **, --- 143 unchanged lines hidden (view full) --- 271static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *, 272 unicode_string *, ndis_physaddr); 273static void NdisMapFile(ndis_status *, void **, ndis_handle); 274static void NdisUnmapFile(ndis_handle); 275static void NdisCloseFile(ndis_handle); 276static uint8_t NdisSystemProcessorCount(void); 277static void NdisMIndicateStatusComplete(ndis_handle); 278static void NdisMIndicateStatus(ndis_handle, ndis_status, | 120 121static void NdisInitializeWrapper(ndis_handle *, 122 driver_object *, void *, void *); 123static ndis_status NdisMRegisterMiniport(ndis_handle, 124 ndis_miniport_characteristics *, int); 125static ndis_status NdisAllocateMemoryWithTag(void **, 126 uint32_t, uint32_t); 127static ndis_status NdisAllocateMemory(void **, --- 143 unchanged lines hidden (view full) --- 271static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *, 272 unicode_string *, ndis_physaddr); 273static void NdisMapFile(ndis_status *, void **, ndis_handle); 274static void NdisUnmapFile(ndis_handle); 275static void NdisCloseFile(ndis_handle); 276static uint8_t NdisSystemProcessorCount(void); 277static void NdisMIndicateStatusComplete(ndis_handle); 278static void NdisMIndicateStatus(ndis_handle, ndis_status, |
279 void *, uint32_t); | 279 void *, uint32_t); |
280static uint8_t ndis_intr(kinterrupt *, void *); 281static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *); 282static funcptr ndis_findwrap(funcptr); 283static void NdisCopyFromPacketToPacket(ndis_packet *, 284 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *); 285static void NdisCopyFromPacketToPacketSafe(ndis_packet *, 286 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t); 287static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *); --- 11 unchanged lines hidden (view full) --- 299 * from NdisAllocatePacket() and NdisAllocateBuffer() and will 300 * sometimes allocate few more buffers/packets that they originally 301 * requested when they created the pool. To prevent this from being 302 * a problem, we allocate a few extra buffers/packets beyond what 303 * the driver asks for. This #define controls how many. 304 */ 305#define NDIS_POOL_EXTRA 16 306 | 280static uint8_t ndis_intr(kinterrupt *, void *); 281static void ndis_intrhand(kdpc *, ndis_miniport_interrupt *, void *, void *); 282static funcptr ndis_findwrap(funcptr); 283static void NdisCopyFromPacketToPacket(ndis_packet *, 284 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *); 285static void NdisCopyFromPacketToPacketSafe(ndis_packet *, 286 uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t); 287static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *); --- 11 unchanged lines hidden (view full) --- 299 * from NdisAllocatePacket() and NdisAllocateBuffer() and will 300 * sometimes allocate few more buffers/packets that they originally 301 * requested when they created the pool. To prevent this from being 302 * a problem, we allocate a few extra buffers/packets beyond what 303 * the driver asks for. This #define controls how many. 304 */ 305#define NDIS_POOL_EXTRA 16 306 |
307struct ktimer_list { 308 ktimer *kl_timer; 309 list_entry kl_next; 310}; 311 312static struct list_entry ndis_timerlist; 313static kspin_lock ndis_timerlock; 314static int ndis_isusbdev; 315 | |
316int 317ndis_libinit() 318{ 319 image_patch_table *patch; 320 321 strcpy(ndis_filepath, "/compat/ndis"); 322 323 patch = ndis_functbl; 324 while (patch->ipt_func != NULL) { 325 windrv_wrap((funcptr)patch->ipt_func, 326 (funcptr *)&patch->ipt_wrap, 327 patch->ipt_argcnt, patch->ipt_ftype); 328 patch++; 329 } 330 | 307int 308ndis_libinit() 309{ 310 image_patch_table *patch; 311 312 strcpy(ndis_filepath, "/compat/ndis"); 313 314 patch = ndis_functbl; 315 while (patch->ipt_func != NULL) { 316 windrv_wrap((funcptr)patch->ipt_func, 317 (funcptr *)&patch->ipt_wrap, 318 patch->ipt_argcnt, patch->ipt_ftype); 319 patch++; 320 } 321 |
331 KeInitializeSpinLock(&ndis_timerlock); 332 InitializeListHead(&ndis_timerlist); 333 | |
334 return(0); 335} 336 337int 338ndis_libfini() 339{ 340 image_patch_table *patch; 341 --- 215 unchanged lines hidden (view full) --- 557 *status = NDIS_STATUS_FAILURE; 558 559 return; 560} 561 562static ndis_status 563ndis_encode_parm(block, oid, type, parm) 564 ndis_miniport_block *block; | 322 return(0); 323} 324 325int 326ndis_libfini() 327{ 328 image_patch_table *patch; 329 --- 215 unchanged lines hidden (view full) --- 545 *status = NDIS_STATUS_FAILURE; 546 547 return; 548} 549 550static ndis_status 551ndis_encode_parm(block, oid, type, parm) 552 ndis_miniport_block *block; |
565 struct sysctl_oid *oid; | 553 struct sysctl_oid *oid; |
566 ndis_parm_type type; 567 ndis_config_parm **parm; 568{ 569 ndis_config_parm *p; 570 ndis_parmlist_entry *np; 571 unicode_string *us; 572 ansi_string as; 573 int base = 0; --- 60 unchanged lines hidden (view full) --- 634 ndis_config_parm **parm; 635 ndis_handle cfg; 636 unicode_string *key; 637 ndis_parm_type type; 638{ 639 char *keystr = NULL; 640 ndis_miniport_block *block; 641 struct ndis_softc *sc; | 554 ndis_parm_type type; 555 ndis_config_parm **parm; 556{ 557 ndis_config_parm *p; 558 ndis_parmlist_entry *np; 559 unicode_string *us; 560 ansi_string as; 561 int base = 0; --- 60 unchanged lines hidden (view full) --- 622 ndis_config_parm **parm; 623 ndis_handle cfg; 624 unicode_string *key; 625 ndis_parm_type type; 626{ 627 char *keystr = NULL; 628 ndis_miniport_block *block; 629 struct ndis_softc *sc; |
642 struct sysctl_oid *oidp; | 630 struct sysctl_oid *oidp; |
643 struct sysctl_ctx_entry *e; 644 ansi_string as; 645 646 block = (ndis_miniport_block *)cfg; 647 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); 648 649 if (key->us_len == 0 || key->us_buf == NULL) { 650 *status = NDIS_STATUS_FAILURE; --- 91 unchanged lines hidden (view full) --- 742 ndis_handle cfg; 743 unicode_string *key; 744 ndis_config_parm *parm; 745{ 746 ansi_string as; 747 char *keystr = NULL; 748 ndis_miniport_block *block; 749 struct ndis_softc *sc; | 631 struct sysctl_ctx_entry *e; 632 ansi_string as; 633 634 block = (ndis_miniport_block *)cfg; 635 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); 636 637 if (key->us_len == 0 || key->us_buf == NULL) { 638 *status = NDIS_STATUS_FAILURE; --- 91 unchanged lines hidden (view full) --- 730 ndis_handle cfg; 731 unicode_string *key; 732 ndis_config_parm *parm; 733{ 734 ansi_string as; 735 char *keystr = NULL; 736 ndis_miniport_block *block; 737 struct ndis_softc *sc; |
750 struct sysctl_oid *oidp; | 738 struct sysctl_oid *oidp; |
751 struct sysctl_ctx_entry *e; 752 char val[256]; 753 754 block = (ndis_miniport_block *)cfg; 755 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); 756 757 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) { 758 *status = NDIS_STATUS_RESOURCES; --- 42 unchanged lines hidden (view full) --- 801 list_entry *e; 802 ndis_parmlist_entry *pe; 803 ndis_miniport_block *block; 804 ndis_config_parm *p; 805 806 block = (ndis_miniport_block *)cfg; 807 808 while (!IsListEmpty(&block->nmb_parmlist)) { | 739 struct sysctl_ctx_entry *e; 740 char val[256]; 741 742 block = (ndis_miniport_block *)cfg; 743 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); 744 745 if (RtlUnicodeStringToAnsiString(&as, key, TRUE)) { 746 *status = NDIS_STATUS_RESOURCES; --- 42 unchanged lines hidden (view full) --- 789 list_entry *e; 790 ndis_parmlist_entry *pe; 791 ndis_miniport_block *block; 792 ndis_config_parm *p; 793 794 block = (ndis_miniport_block *)cfg; 795 796 while (!IsListEmpty(&block->nmb_parmlist)) { |
809 e = RemoveHeadList(&block->nmb_parmlist); 810 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list); | 797 e = RemoveHeadList(&block->nmb_parmlist); 798 pe = CONTAINING_RECORD(e, ndis_parmlist_entry, np_list); |
811 p = &pe->np_parm; 812 if (p->ncp_type == ndis_parm_string) 813 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata); 814 ExFreePool(e); 815 } 816 817 return; 818} --- 400 unchanged lines hidden (view full) --- 1219static void 1220NdisMInitializeTimer(timer, handle, func, ctx) 1221 ndis_miniport_timer *timer; 1222 ndis_handle handle; 1223 ndis_timer_function func; 1224 void *ctx; 1225{ 1226 ndis_miniport_block *block; | 799 p = &pe->np_parm; 800 if (p->ncp_type == ndis_parm_string) 801 RtlFreeUnicodeString(&p->ncp_parmdata.ncp_stringdata); 802 ExFreePool(e); 803 } 804 805 return; 806} --- 400 unchanged lines hidden (view full) --- 1207static void 1208NdisMInitializeTimer(timer, handle, func, ctx) 1209 ndis_miniport_timer *timer; 1210 ndis_handle handle; 1211 ndis_timer_function func; 1212 void *ctx; 1213{ 1214 ndis_miniport_block *block; |
1227 struct ktimer_list *kl; | |
1228 struct ndis_softc *sc; | 1215 struct ndis_softc *sc; |
1229 uint8_t irql; | |
1230 1231 block = (ndis_miniport_block *)handle; 1232 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); | 1216 1217 block = (ndis_miniport_block *)handle; 1218 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); |
1233 if (sc->ndis_iftype == PNPBus && ndis_isusbdev == 0) 1234 ndis_isusbdev = 1; | |
1235 1236 /* Save the driver's funcptr and context */ 1237 1238 timer->nmt_timerfunc = func; 1239 timer->nmt_timerctx = ctx; 1240 timer->nmt_block = handle; 1241 1242 /* 1243 * Set up the timer so it will call our intermediate DPC. 1244 * Be sure to use the wrapped entry point, since 1245 * ntoskrnl_run_dpc() expects to invoke a function with 1246 * Microsoft calling conventions. 1247 */ 1248 KeInitializeTimer(&timer->nmt_ktimer); 1249 KeInitializeDpc(&timer->nmt_kdpc, 1250 ndis_findwrap((funcptr)ndis_timercall), timer); 1251 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc; | 1219 1220 /* Save the driver's funcptr and context */ 1221 1222 timer->nmt_timerfunc = func; 1223 timer->nmt_timerctx = ctx; 1224 timer->nmt_block = handle; 1225 1226 /* 1227 * Set up the timer so it will call our intermediate DPC. 1228 * Be sure to use the wrapped entry point, since 1229 * ntoskrnl_run_dpc() expects to invoke a function with 1230 * Microsoft calling conventions. 1231 */ 1232 KeInitializeTimer(&timer->nmt_ktimer); 1233 KeInitializeDpc(&timer->nmt_kdpc, 1234 ndis_findwrap((funcptr)ndis_timercall), timer); 1235 timer->nmt_ktimer.k_dpc = &timer->nmt_kdpc; |
1252 1253 if (ndis_isusbdev == 1) { 1254 kl = (struct ktimer_list *)malloc(sizeof(*kl), M_DEVBUF, 1255 M_NOWAIT | M_ZERO); 1256 if (kl == NULL) 1257 panic("out of memory"); /* no way to report errors */ 1258 1259 kl->kl_timer = &timer->nmt_ktimer; 1260 KeAcquireSpinLock(&ndis_timerlock, &irql); 1261 InsertHeadList((&ndis_timerlist), (&kl->kl_next)); 1262 KeReleaseSpinLock(&ndis_timerlock, irql); 1263 } | |
1264} 1265 | 1236} 1237 |
1266void 1267ndis_cancel_timerlist(void) 1268{ 1269 list_entry *l; 1270 struct ktimer_list *kl; 1271 uint8_t cancelled, irql; 1272 1273 KeAcquireSpinLock(&ndis_timerlock, &irql); 1274 1275 while(!IsListEmpty(&ndis_timerlist)) { 1276 l = RemoveHeadList(&ndis_timerlist); 1277 kl = CONTAINING_RECORD(l, struct ktimer_list, kl_next); 1278 KeReleaseSpinLock(&ndis_timerlock, irql); 1279 cancelled = KeCancelTimer(kl->kl_timer); 1280 free(kl, M_DEVBUF); 1281 KeAcquireSpinLock(&ndis_timerlock, &irql); 1282 } 1283 1284 KeReleaseSpinLock(&ndis_timerlock, irql); 1285} 1286 | |
1287/* 1288 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(), 1289 * but the former is just a macro wrapper around the latter. 1290 */ 1291static void 1292NdisSetTimer(timer, msecs) 1293 ndis_timer *timer; 1294 uint32_t msecs; --- 26 unchanged lines hidden (view full) --- 1321 * structure just to cancel a timer. 1322 */ 1323 1324static void 1325NdisMCancelTimer(timer, cancelled) 1326 ndis_timer *timer; 1327 uint8_t *cancelled; 1328{ | 1238/* 1239 * In Windows, there's both an NdisMSetTimer() and an NdisSetTimer(), 1240 * but the former is just a macro wrapper around the latter. 1241 */ 1242static void 1243NdisSetTimer(timer, msecs) 1244 ndis_timer *timer; 1245 uint32_t msecs; --- 26 unchanged lines hidden (view full) --- 1272 * structure just to cancel a timer. 1273 */ 1274 1275static void 1276NdisMCancelTimer(timer, cancelled) 1277 ndis_timer *timer; 1278 uint8_t *cancelled; 1279{ |
1329 list_entry *l; 1330 struct ktimer_list *kl; 1331 uint8_t irql; | |
1332 | 1280 |
1333 if (ndis_isusbdev == 1) { 1334 KeAcquireSpinLock(&ndis_timerlock, &irql); 1335 l = ndis_timerlist.nle_flink; 1336 while(l != &ndis_timerlist) { 1337 kl = CONTAINING_RECORD(l, struct ktimer_list, kl_next); 1338 if (kl->kl_timer == &timer->nt_ktimer) { 1339 RemoveEntryList((&kl->kl_next)); 1340 l = l->nle_flink; 1341 free(kl, M_DEVBUF); 1342 continue; 1343 } 1344 l = l->nle_flink; 1345 } 1346 KeReleaseSpinLock(&ndis_timerlock, irql); 1347 } 1348 | |
1349 *cancelled = KeCancelTimer(&timer->nt_ktimer); 1350 return; 1351} 1352 1353static void 1354NdisMQueryAdapterResources(status, adapter, list, buflen) 1355 ndis_status *status; 1356 ndis_handle adapter; --- 364 unchanged lines hidden (view full) --- 1721 1722 NDIS_LOCK(sc); 1723 l = sc->ndis_shlist.nle_flink; 1724 while (l != &sc->ndis_shlist) { 1725 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list); 1726 if (sh->ndis_saddr == vaddr) 1727 break; 1728 /* | 1281 *cancelled = KeCancelTimer(&timer->nt_ktimer); 1282 return; 1283} 1284 1285static void 1286NdisMQueryAdapterResources(status, adapter, list, buflen) 1287 ndis_status *status; 1288 ndis_handle adapter; --- 364 unchanged lines hidden (view full) --- 1653 1654 NDIS_LOCK(sc); 1655 l = sc->ndis_shlist.nle_flink; 1656 while (l != &sc->ndis_shlist) { 1657 sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list); 1658 if (sh->ndis_saddr == vaddr) 1659 break; 1660 /* |
1729 * Check the physaddr too, just in case the driver lied | 1661 * Check the physaddr too, just in case the driver lied |
1730 * about the virtual address. 1731 */ 1732 if (sh->ndis_paddr.np_quad == paddr.np_quad) 1733 break; 1734 l = l->nle_flink; 1735 } 1736 1737 if (sh == NULL) { --- 131 unchanged lines hidden (view full) --- 1869 1870 for (i = 0; i < p->np_cnt; i++) 1871 InterlockedPushEntrySList(&p->np_head, 1872 (struct slist_entry *)&packets[i]); 1873 1874#ifdef NDIS_DEBUG_PACKETS 1875 p->np_dead = 0; 1876 KeInitializeSpinLock(&p->np_lock); | 1662 * about the virtual address. 1663 */ 1664 if (sh->ndis_paddr.np_quad == paddr.np_quad) 1665 break; 1666 l = l->nle_flink; 1667 } 1668 1669 if (sh == NULL) { --- 131 unchanged lines hidden (view full) --- 1801 1802 for (i = 0; i < p->np_cnt; i++) 1803 InterlockedPushEntrySList(&p->np_head, 1804 (struct slist_entry *)&packets[i]); 1805 1806#ifdef NDIS_DEBUG_PACKETS 1807 p->np_dead = 0; 1808 KeInitializeSpinLock(&p->np_lock); |
1877 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE); | 1809 KeInitializeEvent(&p->np_event, EVENT_TYPE_NOTIFY, TRUE); |
1878#endif 1879 1880 *pool = p; 1881 *status = NDIS_STATUS_SUCCESS; 1882 return; 1883} 1884 1885void --- 19 unchanged lines hidden (view full) --- 1905} 1906 1907void 1908NdisFreePacketPool(pool) 1909 ndis_handle pool; 1910{ 1911 ndis_packet_pool *p; 1912 int usage; | 1810#endif 1811 1812 *pool = p; 1813 *status = NDIS_STATUS_SUCCESS; 1814 return; 1815} 1816 1817void --- 19 unchanged lines hidden (view full) --- 1837} 1838 1839void 1840NdisFreePacketPool(pool) 1841 ndis_handle pool; 1842{ 1843 ndis_packet_pool *p; 1844 int usage; |
1913#ifdef NDIS_DEBUG_PACKETS | 1845#ifdef NDIS_DEBUG_PACKETS |
1914 uint8_t irql; 1915#endif 1916 1917 p = (ndis_packet_pool *)pool; 1918 | 1846 uint8_t irql; 1847#endif 1848 1849 p = (ndis_packet_pool *)pool; 1850 |
1919#ifdef NDIS_DEBUG_PACKETS | 1851#ifdef NDIS_DEBUG_PACKETS |
1920 KeAcquireSpinLock(&p->np_lock, &irql); 1921#endif 1922 1923 usage = NdisPacketPoolUsage(pool); 1924 | 1852 KeAcquireSpinLock(&p->np_lock, &irql); 1853#endif 1854 1855 usage = NdisPacketPoolUsage(pool); 1856 |
1925#ifdef NDIS_DEBUG_PACKETS | 1857#ifdef NDIS_DEBUG_PACKETS |
1926 if (usage) { 1927 p->np_dead = 1; 1928 KeResetEvent(&p->np_event); 1929 KeReleaseSpinLock(&p->np_lock, irql); 1930 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL); 1931 } else 1932 KeReleaseSpinLock(&p->np_lock, irql); 1933#endif --- 7 unchanged lines hidden (view full) --- 1941void 1942NdisAllocatePacket(status, packet, pool) 1943 ndis_status *status; 1944 ndis_packet **packet; 1945 ndis_handle pool; 1946{ 1947 ndis_packet_pool *p; 1948 ndis_packet *pkt; | 1858 if (usage) { 1859 p->np_dead = 1; 1860 KeResetEvent(&p->np_event); 1861 KeReleaseSpinLock(&p->np_lock, irql); 1862 KeWaitForSingleObject(&p->np_event, 0, 0, FALSE, NULL); 1863 } else 1864 KeReleaseSpinLock(&p->np_lock, irql); 1865#endif --- 7 unchanged lines hidden (view full) --- 1873void 1874NdisAllocatePacket(status, packet, pool) 1875 ndis_status *status; 1876 ndis_packet **packet; 1877 ndis_handle pool; 1878{ 1879 ndis_packet_pool *p; 1880 ndis_packet *pkt; |
1949#ifdef NDIS_DEBUG_PACKETS | 1881#ifdef NDIS_DEBUG_PACKETS |
1950 uint8_t irql; 1951#endif 1952 1953 p = (ndis_packet_pool *)pool; 1954 | 1882 uint8_t irql; 1883#endif 1884 1885 p = (ndis_packet_pool *)pool; 1886 |
1955#ifdef NDIS_DEBUG_PACKETS | 1887#ifdef NDIS_DEBUG_PACKETS |
1956 KeAcquireSpinLock(&p->np_lock, &irql); 1957 if (p->np_dead) { 1958 KeReleaseSpinLock(&p->np_lock, irql); 1959 printf("NDIS: tried to allocate packet from dead pool %p\n", 1960 pool); 1961 *status = NDIS_STATUS_RESOURCES; 1962 return; 1963 } 1964#endif 1965 1966 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head); 1967 | 1888 KeAcquireSpinLock(&p->np_lock, &irql); 1889 if (p->np_dead) { 1890 KeReleaseSpinLock(&p->np_lock, irql); 1891 printf("NDIS: tried to allocate packet from dead pool %p\n", 1892 pool); 1893 *status = NDIS_STATUS_RESOURCES; 1894 return; 1895 } 1896#endif 1897 1898 pkt = (ndis_packet *)InterlockedPopEntrySList(&p->np_head); 1899 |
1968#ifdef NDIS_DEBUG_PACKETS | 1900#ifdef NDIS_DEBUG_PACKETS |
1969 KeReleaseSpinLock(&p->np_lock, irql); 1970#endif 1971 1972 if (pkt == NULL) { 1973 *status = NDIS_STATUS_RESOURCES; 1974 return; 1975 } 1976 --- 5 unchanged lines hidden (view full) --- 1982 1983 /* Set the oob offset pointer. Lots of things expect this. */ 1984 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob); 1985 1986 /* 1987 * We must initialize the packet flags correctly in order 1988 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and 1989 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work | 1901 KeReleaseSpinLock(&p->np_lock, irql); 1902#endif 1903 1904 if (pkt == NULL) { 1905 *status = NDIS_STATUS_RESOURCES; 1906 return; 1907 } 1908 --- 5 unchanged lines hidden (view full) --- 1914 1915 /* Set the oob offset pointer. Lots of things expect this. */ 1916 pkt->np_private.npp_packetooboffset = offsetof(ndis_packet, np_oob); 1917 1918 /* 1919 * We must initialize the packet flags correctly in order 1920 * for the NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO() and 1921 * NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO() macros to work |
1990 * correctly. | 1922 * correctly. |
1991 */ 1992 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS; 1993 pkt->np_private.npp_validcounts = FALSE; 1994 1995 *packet = pkt; 1996 1997 *status = NDIS_STATUS_SUCCESS; 1998 1999 return; 2000} 2001 2002void 2003NdisFreePacket(packet) 2004 ndis_packet *packet; 2005{ 2006 ndis_packet_pool *p; | 1923 */ 1924 pkt->np_private.npp_ndispktflags = NDIS_PACKET_ALLOCATED_BY_NDIS; 1925 pkt->np_private.npp_validcounts = FALSE; 1926 1927 *packet = pkt; 1928 1929 *status = NDIS_STATUS_SUCCESS; 1930 1931 return; 1932} 1933 1934void 1935NdisFreePacket(packet) 1936 ndis_packet *packet; 1937{ 1938 ndis_packet_pool *p; |
2007#ifdef NDIS_DEBUG_PACKETS | 1939#ifdef NDIS_DEBUG_PACKETS |
2008 uint8_t irql; 2009#endif 2010 2011 p = (ndis_packet_pool *)packet->np_private.npp_pool; 2012 | 1940 uint8_t irql; 1941#endif 1942 1943 p = (ndis_packet_pool *)packet->np_private.npp_pool; 1944 |
2013#ifdef NDIS_DEBUG_PACKETS | 1945#ifdef NDIS_DEBUG_PACKETS |
2014 KeAcquireSpinLock(&p->np_lock, &irql); 2015#endif 2016 2017 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet); 2018 | 1946 KeAcquireSpinLock(&p->np_lock, &irql); 1947#endif 1948 1949 InterlockedPushEntrySList(&p->np_head, (slist_entry *)packet); 1950 |
2019#ifdef NDIS_DEBUG_PACKETS | 1951#ifdef NDIS_DEBUG_PACKETS |
2020 if (p->np_dead) { 2021 if (ExQueryDepthSList(&p->np_head) == p->np_cnt) 2022 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE); 2023 } 2024 KeReleaseSpinLock(&p->np_lock, irql); 2025#endif 2026 2027 return; --- 306 unchanged lines hidden (view full) --- 2334 *list = block->nmb_rlist; 2335 2336 return (NDIS_STATUS_SUCCESS); 2337} 2338 2339static uint8_t 2340ndis_intr(iobj, arg) 2341 kinterrupt *iobj; | 1952 if (p->np_dead) { 1953 if (ExQueryDepthSList(&p->np_head) == p->np_cnt) 1954 KeSetEvent(&p->np_event, IO_NO_INCREMENT, FALSE); 1955 } 1956 KeReleaseSpinLock(&p->np_lock, irql); 1957#endif 1958 1959 return; --- 306 unchanged lines hidden (view full) --- 2266 *list = block->nmb_rlist; 2267 2268 return (NDIS_STATUS_SUCCESS); 2269} 2270 2271static uint8_t 2272ndis_intr(iobj, arg) 2273 kinterrupt *iobj; |
2342 void *arg; | 2274 void *arg; |
2343{ 2344 struct ndis_softc *sc; 2345 uint8_t is_our_intr = FALSE; 2346 int call_isr = 0; 2347 ndis_miniport_interrupt *intr; 2348 2349 sc = arg; 2350 intr = sc->ndis_block->nmb_interrupt; --- 20 unchanged lines hidden (view full) --- 2371ndis_intrhand(dpc, intr, sysarg1, sysarg2) 2372 kdpc *dpc; 2373 ndis_miniport_interrupt *intr; 2374 void *sysarg1; 2375 void *sysarg2; 2376{ 2377 struct ndis_softc *sc; 2378 ndis_miniport_block *block; | 2275{ 2276 struct ndis_softc *sc; 2277 uint8_t is_our_intr = FALSE; 2278 int call_isr = 0; 2279 ndis_miniport_interrupt *intr; 2280 2281 sc = arg; 2282 intr = sc->ndis_block->nmb_interrupt; --- 20 unchanged lines hidden (view full) --- 2303ndis_intrhand(dpc, intr, sysarg1, sysarg2) 2304 kdpc *dpc; 2305 ndis_miniport_interrupt *intr; 2306 void *sysarg1; 2307 void *sysarg2; 2308{ 2309 struct ndis_softc *sc; 2310 ndis_miniport_block *block; |
2379 ndis_handle adapter; | 2311 ndis_handle adapter; |
2380 2381 block = intr->ni_block; | 2312 2313 block = intr->ni_block; |
2382 adapter = block->nmb_miniportadapterctx; | 2314 adapter = block->nmb_miniportadapterctx; |
2383 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); 2384 | 2315 sc = device_get_softc(block->nmb_physdeviceobj->do_devext); 2316 |
2385 if (NDIS_SERIALIZED(sc->ndis_block)) 2386 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock); | 2317 if (NDIS_SERIALIZED(sc->ndis_block)) 2318 KeAcquireSpinLockAtDpcLevel(&block->nmb_lock); |
2387 | 2319 |
2388 MSCALL1(intr->ni_dpcfunc, adapter); | 2320 MSCALL1(intr->ni_dpcfunc, adapter); |
2389 | 2321 |
2390 /* If there's a MiniportEnableInterrupt() routine, call it. */ | 2322 /* If there's a MiniportEnableInterrupt() routine, call it. */ |
2391 2392 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL) 2393 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter); 2394 | 2323 2324 if (sc->ndis_chars->nmc_enable_interrupts_func != NULL) 2325 MSCALL1(sc->ndis_chars->nmc_enable_interrupts_func, adapter); 2326 |
2395 if (NDIS_SERIALIZED(sc->ndis_block)) 2396 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock); | 2327 if (NDIS_SERIALIZED(sc->ndis_block)) 2328 KeReleaseSpinLockFromDpcLevel(&block->nmb_lock); |
2397 2398 /* 2399 * Set the completion event if we've drained all 2400 * pending interrupts. 2401 */ 2402 2403 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock); 2404 intr->ni_dpccnt--; 2405 if (intr->ni_dpccnt == 0) 2406 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE); 2407 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock); 2408 | 2329 2330 /* 2331 * Set the completion event if we've drained all 2332 * pending interrupts. 2333 */ 2334 2335 KeAcquireSpinLockAtDpcLevel(&intr->ni_dpccountlock); 2336 intr->ni_dpccnt--; 2337 if (intr->ni_dpccnt == 0) 2338 KeSetEvent(&intr->ni_dpcevt, IO_NO_INCREMENT, FALSE); 2339 KeReleaseSpinLockFromDpcLevel(&intr->ni_dpccountlock); 2340 |
2409 return; | 2341 return; |
2410} 2411 2412static ndis_status 2413NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter, 2414 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared, 2415 ndis_interrupt_mode imode) 2416{ 2417 ndis_miniport_block *block; --- 13 unchanged lines hidden (view full) --- 2431 2432 intr->ni_block = adapter; 2433 intr->ni_isrreq = reqisr; 2434 intr->ni_shared = shared; 2435 intr->ni_dpccnt = 0; 2436 intr->ni_isrfunc = ch->nmc_isr_func; 2437 intr->ni_dpcfunc = ch->nmc_interrupt_func; 2438 | 2342} 2343 2344static ndis_status 2345NdisMRegisterInterrupt(ndis_miniport_interrupt *intr, ndis_handle adapter, 2346 uint32_t ivec, uint32_t ilevel, uint8_t reqisr, uint8_t shared, 2347 ndis_interrupt_mode imode) 2348{ 2349 ndis_miniport_block *block; --- 13 unchanged lines hidden (view full) --- 2363 2364 intr->ni_block = adapter; 2365 intr->ni_isrreq = reqisr; 2366 intr->ni_shared = shared; 2367 intr->ni_dpccnt = 0; 2368 intr->ni_isrfunc = ch->nmc_isr_func; 2369 intr->ni_dpcfunc = ch->nmc_interrupt_func; 2370 |
2439 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE); 2440 KeInitializeDpc(&intr->ni_dpc, | 2371 KeInitializeEvent(&intr->ni_dpcevt, EVENT_TYPE_NOTIFY, TRUE); 2372 KeInitializeDpc(&intr->ni_dpc, |
2441 ndis_findwrap((funcptr)ndis_intrhand), intr); | 2373 ndis_findwrap((funcptr)ndis_intrhand), intr); |
2442 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW); | 2374 KeSetImportanceDpc(&intr->ni_dpc, KDPC_IMPORTANCE_LOW); |
2443 2444 error = IoConnectInterrupt(&intr->ni_introbj, 2445 ndis_findwrap((funcptr)ndis_intr), sc, NULL, 2446 ivec, ilevel, 0, imode, shared, 0, FALSE); 2447 2448 if (error != STATUS_SUCCESS) 2449 return(NDIS_STATUS_FAILURE); 2450 2451 block->nmb_interrupt = intr; 2452 2453 return(NDIS_STATUS_SUCCESS); | 2375 2376 error = IoConnectInterrupt(&intr->ni_introbj, 2377 ndis_findwrap((funcptr)ndis_intr), sc, NULL, 2378 ivec, ilevel, 0, imode, shared, 0, FALSE); 2379 2380 if (error != STATUS_SUCCESS) 2381 return(NDIS_STATUS_FAILURE); 2382 2383 block->nmb_interrupt = intr; 2384 2385 return(NDIS_STATUS_SUCCESS); |
2454} | 2386} |
2455 2456static void 2457NdisMDeregisterInterrupt(intr) 2458 ndis_miniport_interrupt *intr; 2459{ 2460 ndis_miniport_block *block; 2461 struct ndis_softc *sc; 2462 uint8_t irql; --- 261 unchanged lines hidden (view full) --- 2724/* 2725 * Return the number of milliseconds since the system booted. 2726 */ 2727static void 2728NdisGetSystemUpTime(tval) 2729 uint32_t *tval; 2730{ 2731 struct timespec ts; | 2387 2388static void 2389NdisMDeregisterInterrupt(intr) 2390 ndis_miniport_interrupt *intr; 2391{ 2392 ndis_miniport_block *block; 2393 struct ndis_softc *sc; 2394 uint8_t irql; --- 261 unchanged lines hidden (view full) --- 2656/* 2657 * Return the number of milliseconds since the system booted. 2658 */ 2659static void 2660NdisGetSystemUpTime(tval) 2661 uint32_t *tval; 2662{ 2663 struct timespec ts; |
2732 | 2664 |
2733 nanouptime(&ts); 2734 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000; 2735 2736 return; 2737} 2738 2739static void 2740NdisInitializeString(dst, src) --- 414 unchanged lines hidden (view full) --- 3155static uint8_t 3156NdisSystemProcessorCount() 3157{ 3158 return(mp_ncpus); 3159} 3160 3161typedef void (*ndis_statusdone_handler)(ndis_handle); 3162typedef void (*ndis_status_handler)(ndis_handle, ndis_status, | 2665 nanouptime(&ts); 2666 *tval = ts.tv_nsec / 1000000 + ts.tv_sec * 1000; 2667 2668 return; 2669} 2670 2671static void 2672NdisInitializeString(dst, src) --- 414 unchanged lines hidden (view full) --- 3087static uint8_t 3088NdisSystemProcessorCount() 3089{ 3090 return(mp_ncpus); 3091} 3092 3093typedef void (*ndis_statusdone_handler)(ndis_handle); 3094typedef void (*ndis_status_handler)(ndis_handle, ndis_status, |
3163 void *, uint32_t); | 3095 void *, uint32_t); |
3164 3165static void 3166NdisMIndicateStatusComplete(adapter) 3167 ndis_handle adapter; 3168{ 3169 ndis_miniport_block *block; 3170 ndis_statusdone_handler statusdonefunc; 3171 --- 257 unchanged lines hidden (view full) --- 3429 IMPORT_SFUNC(NdisInitAnsiString, 2), 3430 IMPORT_SFUNC(NdisInitUnicodeString, 2), 3431 IMPORT_SFUNC(NdisWriteConfiguration, 4), 3432 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2), 3433 IMPORT_SFUNC(NdisTerminateWrapper, 2), 3434 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4), 3435 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5), 3436 IMPORT_SFUNC(NdisMRemoveMiniport, 1), | 3096 3097static void 3098NdisMIndicateStatusComplete(adapter) 3099 ndis_handle adapter; 3100{ 3101 ndis_miniport_block *block; 3102 ndis_statusdone_handler statusdonefunc; 3103 --- 257 unchanged lines hidden (view full) --- 3361 IMPORT_SFUNC(NdisInitAnsiString, 2), 3362 IMPORT_SFUNC(NdisInitUnicodeString, 2), 3363 IMPORT_SFUNC(NdisWriteConfiguration, 4), 3364 IMPORT_SFUNC(NdisAnsiStringToUnicodeString, 2), 3365 IMPORT_SFUNC(NdisTerminateWrapper, 2), 3366 IMPORT_SFUNC(NdisOpenConfigurationKeyByName, 4), 3367 IMPORT_SFUNC(NdisOpenConfigurationKeyByIndex, 5), 3368 IMPORT_SFUNC(NdisMRemoveMiniport, 1), |
3437 IMPORT_SFUNC(NdisInitializeString, 2), 3438 IMPORT_SFUNC(NdisFreeString, 1), | 3369 IMPORT_SFUNC(NdisInitializeString, 2), 3370 IMPORT_SFUNC(NdisFreeString, 1), |
3439 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1), 3440 IMPORT_SFUNC(NdisGetSystemUpTime, 1), 3441 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3), 3442 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4), 3443 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3), 3444 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3), 3445 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2), 3446 IMPORT_SFUNC(NdisInitializeWrapper, 4), --- 108 unchanged lines hidden --- | 3371 IMPORT_SFUNC(NdisGetCurrentSystemTime, 1), 3372 IMPORT_SFUNC(NdisGetSystemUpTime, 1), 3373 IMPORT_SFUNC(NdisMSynchronizeWithInterrupt, 3), 3374 IMPORT_SFUNC(NdisMAllocateSharedMemoryAsync, 4), 3375 IMPORT_SFUNC(NdisInterlockedInsertHeadList, 3), 3376 IMPORT_SFUNC(NdisInterlockedInsertTailList, 3), 3377 IMPORT_SFUNC(NdisInterlockedRemoveHeadList, 2), 3378 IMPORT_SFUNC(NdisInitializeWrapper, 4), --- 108 unchanged lines hidden --- |