--- ../freebsd/src/sys/compat/ndis/kern_ndis.c 2005-04-01 19:14:20.000000000 +0200 +++ ./sys/compat/ndis/kern_ndis.c 2005-06-20 18:21:46.000000000 +0200 @@ -31,7 +31,12 @@ */ #include +#ifdef __FreeBSD__ __FBSDID("$FreeBSD: src/sys/compat/ndis/kern_ndis.c,v 1.60.2.5 2005/04/01 17:14:20 wpaul Exp $"); +#endif +#ifdef __NetBSD__ +__KERNEL_RCSID(0, "$NetBSD$"); +#endif #include #include @@ -45,20 +50,33 @@ #include #include #include +#ifdef __FreeBSD__ #include +#endif #include #include +#ifdef __FreeBSD__ #include +#else +#include +#include +#endif #include #include +#ifdef __FreeBSD__ #include #include #include +#endif #include #include +#ifdef __FreeBSD__ #include +#else +#include +#endif #include #include @@ -138,6 +156,7 @@ * 'ndis.' */ +#ifdef __FreeBSD__ static int ndis_modevent(module_t mod, int cmd, void *arg) { @@ -210,6 +229,72 @@ } DEV_MODULE(ndisapi, ndis_modevent, NULL); MODULE_VERSION(ndisapi, 1); +#endif +#ifdef __NetBSD__ +MOD_MISC( "ndis"); + +static int +ndis_lkm_handle(struct lkm_table *lkmtp, int cmd) +{ + int error = 0; + image_patch_table *patch; + + switch (cmd) { + case LKM_E_LOAD: + /* Initialize subsystems */ + windrv_libinit(); + hal_libinit(); + ndis_libinit(); + ntoskrnl_libinit(); + usbd_libinit(); + + patch = kernndis_functbl; + while (patch->ipt_func != NULL) { + windrv_wrap((funcptr)patch->ipt_func, + (funcptr *)&patch->ipt_wrap); + patch++; + } + + ndis_create_kthreads(); + + TAILQ_INIT(&ndis_devhead); + + break; + case LKM_E_UNLOAD: + /* stop kthreads */ + ndis_destroy_kthreads(); + + /* Shut down subsystems */ + hal_libfini(); + ndis_libfini(); + ntoskrnl_libfini(); + usbd_libfini(); + windrv_libfini(); + + patch = kernndis_functbl; + while (patch->ipt_func != NULL) { + windrv_unwrap(patch->ipt_wrap); + patch++; + } + + break; + case LKM_E_STAT: + break; + default: + error = EINVAL; + break; + } + + return(error); +} + +int +ndis_lkmentry(struct lkm_table *lkmtp, int cmd, int ver) +{ + DISPATCH(lkmtp, cmd, ver, + ndis_lkm_handle, ndis_lkm_handle, ndis_lkm_handle); +} +#endif /* __NetBSD__ */ /* * We create two kthreads for the NDIS subsystem. One of them is a task @@ -272,9 +357,11 @@ } wakeup(die); +#ifdef __FreeBSD__ #if __FreeBSD_version < 502113 mtx_lock(&Giant); #endif +#endif kthread_exit(0); return; /* notreached */ } @@ -304,17 +391,27 @@ if (error == 0) { ndis_tproc.np_q = &ndis_ttodo; ndis_tproc.np_state = NDIS_PSTATE_SLEEPING; +#ifdef __FreeBSD__ error = kthread_create(ndis_runq, &ndis_tproc, &ndis_tproc.np_p, RFHIGHPID, NDIS_KSTACK_PAGES, "ndis taskqueue"); +#else + error = kthread_create1(ndis_runq, &ndis_tproc, + &ndis_tproc.np_p, "ndis taskqueue"); +#endif } if (error == 0) { ndis_iproc.np_q = &ndis_itodo; ndis_iproc.np_state = NDIS_PSTATE_SLEEPING; +#ifdef __FreeBSD__ error = kthread_create(ndis_runq, &ndis_iproc, &ndis_iproc.np_p, RFHIGHPID, NDIS_KSTACK_PAGES, "ndis swi"); +#else + error = kthread_create1(ndis_runq, &ndis_iproc, + &ndis_iproc.np_p, "ndis swi"); +#endif } if (error) { @@ -382,7 +479,11 @@ /* wait for thread exit */ +#ifdef __FreeBSD__ tsleep(r, curthread->td_priority|PCATCH, "ndisthexit", hz * 60); +#else + tsleep(r, curlwp->l_priority|PCATCH, "ndisthexit", hz * 60); +#endif /* Now empty the job list. */ @@ -539,6 +640,7 @@ { int error; +#ifdef __FreeBSD__ if (m != NULL) { error = msleep(&p->p_siglist, m, curthread->td_priority, "ndissp", timo); @@ -547,6 +649,14 @@ error = msleep(&p->p_siglist, &p->p_mtx, curthread->td_priority|PDROP, "ndissp", timo); } +#else + if (m != NULL) + error = ltsleep(&p->p_siglist, curlwp->l_priority, + "ndissp", timo, 0); + else + error = ltsleep(&p->p_siglist, curlwp->l_priority|PNORELOCK, + "ndissp", timo, 0); +#endif return(error); } @@ -579,7 +689,11 @@ block = adapter; sc = device_get_softc(block->nmb_physdeviceobj->do_devext); +#ifdef __FreeBSD__ ifp = &sc->arpcom.ac_if; +#else + ifp = &sc->arpcom.ec_if; +#endif if (ifp->if_flags & IFF_DEBUG) device_printf (sc->ndis_dev, "status: %x\n", status); return; @@ -595,7 +709,11 @@ block = adapter; sc = device_get_softc(block->nmb_physdeviceobj->do_devext); +#ifdef __FreeBSD__ ifp = &sc->arpcom.ac_if; +#else + ifp = &sc->arpcom.ec_if; +#endif if (ifp->if_flags & IFF_DEBUG) device_printf (sc->ndis_dev, "status complete\n"); return; @@ -639,7 +757,11 @@ block = adapter; sc = device_get_softc(block->nmb_physdeviceobj->do_devext); +#ifdef __FreeBSD__ ifp = &sc->arpcom.ac_if; +#else + ifp = &sc->arpcom.ec_if; +#endif if (ifp->if_flags & IFF_DEBUG) device_printf (sc->ndis_dev, "reset done...\n"); @@ -651,6 +773,7 @@ ndis_create_sysctls(arg) void *arg; { +#ifdef __FreeBSD__ struct ndis_softc *sc; ndis_cfg *vals; char buf[256]; @@ -748,6 +871,7 @@ "Interrupt Number", buf, CTLFLAG_RD); } +#endif /* __FreeBSD__ */ return(0); } @@ -759,6 +883,7 @@ char *val; int flag; { +#ifdef __FreeBSD__ struct ndis_softc *sc; struct ndis_cfglist *cfg; char descstr[256]; @@ -789,7 +914,7 @@ OID_AUTO, cfg->ndis_cfg.nc_cfgkey, flag, cfg->ndis_cfg.nc_val, sizeof(cfg->ndis_cfg.nc_val), cfg->ndis_cfg.nc_cfgdesc); - +#endif /* __FreeBSD__ */ return(0); } @@ -893,6 +1018,7 @@ return; } +#ifdef __FreeBSD__ int ndis_convert_res(arg) void *arg; @@ -917,7 +1043,6 @@ #if __FreeBSD_version < 600022 SLIST_INIT(&brl_rev); #endif - rl = malloc(sizeof(ndis_resource_list) + (sizeof(cm_partial_resource_desc) * (sc->ndis_rescnt - 1)), M_DEVBUF, M_NOWAIT|M_ZERO); @@ -1014,7 +1139,7 @@ return(error); } - +#endif /* __FreeBSD__ */ /* * Map an NDIS packet to an mbuf list. When an NDIS driver receives a * packet, it will hand it to us in the form of an ndis_packet, @@ -1057,8 +1182,13 @@ } m->m_len = MmGetMdlByteCount(buf); m->m_data = MmGetMdlVirtualAddress(buf); +#ifdef __FreeBSD__ MEXTADD(m, m->m_data, m->m_len, ndis_return_packet, - p, 0, EXT_NDIS); + p, 0, EXT_NDIS); +#else + MEXTADD(m, m->m_data, m->m_len, mbtypes[0], + ndis_return_packet, p); +#endif p->np_refcnt++; totlen += m->m_len; if (m->m_flags & MT_HEADER) @@ -1205,10 +1335,16 @@ if (rval == NDIS_STATUS_PENDING) { mtx_lock(&ndis_req_mtx); +#ifdef __FreeBSD__ error = msleep(&sc->ndis_block->nmb_setstat, &ndis_req_mtx, curthread->td_priority|PDROP, "ndisset", 5 * hz); +#else + error = ltsleep(&sc->ndis_block->nmb_setstat, + curlwp->l_priority|PNORELOCK, + "ndisset", 5 * hz, 0); +#endif rval = sc->ndis_block->nmb_setstat; } @@ -1335,8 +1471,14 @@ return(ENOMEM); for (i = 0; i < sc->ndis_maxpkts; i++) { +#ifdef __FreeBSD__ error = bus_dmamap_create(sc->ndis_ttag, 0, &sc->ndis_tmaps[i]); +#else + bus_dmamap_create(sc->ndis_mtag, sizeof(bus_dmamap_t), + 1, sizeof(bus_dmamap_t), BUS_DMA_NOWAIT, + 0, &sc->ndis_mmaps[i]); +#endif if (error) { free(sc->ndis_tmaps, M_DEVBUF); return(ENODEV); @@ -1388,7 +1530,11 @@ uint8_t irql; sc = arg; +#ifdef __FreeBSD__ ifp = &sc->arpcom.ac_if; +#else + ifp = &sc->arpcom.ec_if; +#endif adapter = sc->ndis_block->nmb_miniportadapterctx; resetfunc = sc->ndis_chars->nmc_reset_func; @@ -1406,8 +1552,12 @@ if (rval == NDIS_STATUS_PENDING) { mtx_lock(&ndis_req_mtx); +#ifdef __FreeBSD__ msleep(sc, &ndis_req_mtx, - curthread->td_priority|PDROP, "ndisrst", 0); + curthread->td_priority|PDROP, "ndisrst", 0); +#else + ltsleep(sc, curlwp->l_priority|PNORELOCK, "ndisrst", 0, 0); +#endif } return(0); @@ -1423,7 +1573,11 @@ struct ifnet *ifp; sc = arg; +#ifdef __FreeBSD__ ifp = &sc->arpcom.ac_if; +#else + ifp = &sc->arpcom.ec_if; +#endif NDIS_LOCK(sc); adapter = sc->ndis_block->nmb_miniportadapterctx; @@ -1659,10 +1813,15 @@ if (rval == NDIS_STATUS_PENDING) { mtx_lock(&ndis_req_mtx); +#ifdef __FreeBSD__ error = msleep(&sc->ndis_block->nmb_getstat, &ndis_req_mtx, curthread->td_priority|PDROP, "ndisget", 5 * hz); +#else + ltsleep(&sc->ndis_block->nmb_getstat, + curlwp->l_priority|PNORELOCK, "ndisget", 5 * hz, 0); +#endif rval = sc->ndis_block->nmb_getstat; }