diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/compat/ndis/kern_ndis.c | 63 | ||||
-rw-r--r-- | sys/compat/ndis/subr_ndis.c | 9 | ||||
-rw-r--r-- | sys/dev/if_ndis/if_ndis.c | 90 |
3 files changed, 103 insertions, 59 deletions
diff --git a/sys/compat/ndis/kern_ndis.c b/sys/compat/ndis/kern_ndis.c index 53bfa77..3ab391a 100644 --- a/sys/compat/ndis/kern_ndis.c +++ b/sys/compat/ndis/kern_ndis.c @@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$"); #include <sys/bus.h> #include <sys/rman.h> +#include <vm/uma.h> + #include <net/if.h> #include <net/if_arp.h> #include <net/ethernet.h> @@ -82,6 +84,8 @@ __stdcall static void ndis_setdone_func(ndis_handle, ndis_status); __stdcall static void ndis_getdone_func(ndis_handle, ndis_status); __stdcall static void ndis_resetdone_func(ndis_handle, ndis_status, uint8_t); +static uma_zone_t ndis_packet_zone, ndis_buffer_zone; + /* * This allows us to export our symbols to other modules. * Note that we call ourselves 'ndisapi' to avoid a namespace @@ -91,7 +95,28 @@ __stdcall static void ndis_resetdone_func(ndis_handle, ndis_status, uint8_t); static int ndis_modevent(module_t mod, int cmd, void *arg) { - return(0); + int error = 0; + + switch (cmd) { + case MOD_LOAD: + ndis_packet_zone = uma_zcreate("NDIS packet", + sizeof(ndis_packet), NULL, NULL, NULL, + NULL, UMA_ALIGN_PTR, 0); + ndis_buffer_zone = uma_zcreate("NDIS buffer", + sizeof(ndis_buffer), NULL, NULL, NULL, + NULL, UMA_ALIGN_PTR, 0); + break; + case MOD_UNLOAD: + case MOD_SHUTDOWN: + uma_zdestroy(ndis_packet_zone); + uma_zdestroy(ndis_buffer_zone); + break; + default: + error = EINVAL; + break; + } + + return(error); } DEV_MODULE(ndisapi, ndis_modevent, NULL); MODULE_VERSION(ndisapi, 1); @@ -104,7 +129,10 @@ ndis_status_func(adapter, status, sbuf, slen) void *sbuf; uint32_t slen; { - printf ("status: %x\n", status); + ndis_miniport_block *block; + block = adapter; + + device_printf (block->nmb_dev, "status: %x\n", status); return; } @@ -112,7 +140,10 @@ __stdcall static void ndis_statusdone_func(adapter) ndis_handle adapter; { - printf ("status complete\n"); + ndis_miniport_block *block; + block = adapter; + + device_printf (block->nmb_dev, "status complete\n"); return; } @@ -148,7 +179,10 @@ ndis_resetdone_func(adapter, status, addressingreset) ndis_status status; uint8_t addressingreset; { - printf ("reset done...\n"); + ndis_miniport_block *block; + block = adapter; + + device_printf (block->nmb_dev, "reset done...\n"); return; } @@ -170,8 +204,8 @@ ndis_alloc_amem(arg) &rid, 0UL, ~0UL, 0x1000, RF_ACTIVE); if (sc->ndis_res_am == NULL) { - printf("ndis%d: failed to allocate attribute memory\n", - sc->ndis_unit); + device_printf(sc->ndis_dev, + "failed to allocate attribute memory\n"); return(ENXIO); } @@ -179,8 +213,8 @@ ndis_alloc_amem(arg) sc->ndis_dev, rid, 0, NULL); if (error) { - printf("ndis%d: CARD_SET_MEMORY_OFFSET() returned 0x%x\n", - sc->ndis_unit, error); + device_printf(sc->ndis_dev, + "CARD_SET_MEMORY_OFFSET() returned 0x%x\n", error); return(error); } @@ -188,8 +222,8 @@ ndis_alloc_amem(arg) sc->ndis_dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR); if (error) { - printf("ndis%d: CARD_SET_RES_FLAGS() returned 0x%x\n", - sc->ndis_unit, error); + device_printf(sc->ndis_dev, + "CARD_SET_RES_FLAGS() returned 0x%x\n", error); return(error); } @@ -369,7 +403,7 @@ ndis_free_bufs(b0) while(b0 != NULL) { next = b0->nb_next; - free (b0, M_DEVBUF); + uma_zfree (ndis_buffer_zone, b0); b0 = next; } @@ -384,7 +418,7 @@ ndis_free_packet(p) return; ndis_free_bufs(p->np_private.npp_head); - free(p, M_DEVBUF); + uma_zfree(ndis_packet_zone, p); return; } @@ -538,7 +572,7 @@ ndis_mtop(m0, p) /* If caller didn't supply a packet, make one. */ if (*p == NULL) { - *p = malloc(sizeof(ndis_packet), M_DEVBUF, M_NOWAIT|M_ZERO); + *p = uma_zalloc(ndis_packet_zone, M_NOWAIT|M_ZERO); if (*p == NULL) return(ENOMEM); @@ -551,7 +585,7 @@ ndis_mtop(m0, p) for (m = m0; m != NULL; m = m->m_next) { if (m->m_len == 0) continue; - buf = malloc(sizeof(ndis_buffer), M_DEVBUF, M_NOWAIT|M_ZERO); + buf = uma_zalloc(ndis_buffer_zone, M_NOWAIT | M_ZERO); if (buf == NULL) { ndis_free_packet(*p); *p = NULL; @@ -567,6 +601,7 @@ ndis_mtop(m0, p) } priv->npp_tail = buf; + priv->npp_totlen = m0->m_pkthdr.len; return(0); } diff --git a/sys/compat/ndis/subr_ndis.c b/sys/compat/ndis/subr_ndis.c index d93822e..975e6ee 100644 --- a/sys/compat/ndis/subr_ndis.c +++ b/sys/compat/ndis/subr_ndis.c @@ -769,12 +769,13 @@ ndis_syslog(ndis_handle adapter, ndis_error_code code, block = (ndis_miniport_block *)adapter; - printf ("NDIS ERROR: %x\n", code); - printf ("NDIS NUMERRORS: %x\n", numerrors); + device_printf (block->nmb_dev, "NDIS ERROR: %x\n", code); + device_printf (block->nmb_dev, "NDIS NUMERRORS: %x\n", numerrors); va_start(ap, numerrors); for (i = 0; i < numerrors; i++) - printf ("argptr: %p\n", va_arg(ap, void *)); + device_printf (block->nmb_dev, "argptr: %p\n", + va_arg(ap, void *)); va_end(ap); return; @@ -1829,7 +1830,7 @@ ndis_assign_pcirsrc(adapter, slot, list) block = (ndis_miniport_block *)adapter; *list = block->nmb_rlist; - printf ("assign PCI resources...\n"); + device_printf (block->nmb_dev, "assign PCI resources...\n"); return (NDIS_STATUS_SUCCESS); } diff --git a/sys/dev/if_ndis/if_ndis.c b/sys/dev/if_ndis/if_ndis.c index be89d35..e2f8c88 100644 --- a/sys/dev/if_ndis/if_ndis.c +++ b/sys/dev/if_ndis/if_ndis.c @@ -141,15 +141,28 @@ static device_method_t ndis_methods[] = { }; static driver_t ndis_driver = { +#ifdef NDIS_DEVNAME + NDIS_DEVNAME, +#else "ndis", +#endif ndis_methods, sizeof(struct ndis_softc) }; static devclass_t ndis_devclass; +#ifdef NDIS_MODNAME +#define NDIS_MODNAME_OVERRIDE_PCI(x) \ + DRIVER_MODULE(x, pci, ndis_driver, ndis_devclass, 0, 0) +#define NDIS_MODNAME_OVERRIDE_CARDBUS(x) \ + DRIVER_MODULE(x, cardbus, ndis_driver, ndis_devclass, 0, 0) +NDIS_MODNAME_OVERRIDE_PCI(NDIS_MODNAME); +NDIS_MODNAME_OVERRIDE_CARDBUS(NDIS_MODNAME); +#else DRIVER_MODULE(ndis, pci, ndis_driver, ndis_devclass, 0, 0); DRIVER_MODULE(ndis, cardbus, ndis_driver, ndis_devclass, 0, 0); +#endif /* * Program the 64-bit multicast hash filter. @@ -240,8 +253,8 @@ ndis_attach(dev) SYS_RES_IOPORT, &sc->ndis_io_rid, 0, ~0, 1, RF_ACTIVE); if (sc->ndis_res_io == NULL) { - printf("ndis%d: couldn't map " - "iospace\n", unit); + device_printf(dev, + "couldn't map iospace"); error = ENXIO; goto fail; } @@ -249,8 +262,8 @@ ndis_attach(dev) case SYS_RES_MEMORY: if (sc->ndis_res_altmem != NULL && sc->ndis_res_mem != NULL) { - printf ("ndis%d: too many memory " - "resources", sc->ndis_unit); + device_printf(dev, + "too many memory resources"); error = ENXIO; goto fail; } @@ -262,8 +275,8 @@ ndis_attach(dev) &sc->ndis_altmem_rid, 0, ~0, 1, RF_ACTIVE); if (sc->ndis_res_altmem == NULL) { - printf("ndis%d: couldn't map " - "alt memory\n", unit); + device_printf(dev, + "couldn't map alt memory"); error = ENXIO; goto fail; } @@ -275,8 +288,8 @@ ndis_attach(dev) &sc->ndis_mem_rid, 0, ~0, 1, RF_ACTIVE); if (sc->ndis_res_mem == NULL) { - printf("ndis%d: couldn't map " - "memory\n", unit); + device_printf(dev, + "couldn't map memory"); error = ENXIO; goto fail; } @@ -288,8 +301,8 @@ ndis_attach(dev) SYS_RES_IRQ, &rid, 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE); if (sc->ndis_irq == NULL) { - printf("ndis%d: couldn't map " - "interrupt\n", unit); + device_printf(dev, + "couldn't map interrupt"); error = ENXIO; goto fail; } @@ -310,7 +323,7 @@ ndis_attach(dev) ndis_intr, sc, &sc->ndis_intrhand); if (error) { - printf("ndis%d: couldn't set up irq\n", unit); + device_printf(dev, "couldn't set up irq\n"); goto fail; } @@ -377,7 +390,7 @@ ndis_attach(dev) /* Call driver's init routine. */ if (ndis_init_nic(sc)) { - printf ("ndis%d: init handler failed\n", sc->ndis_unit); + device_printf (dev, "init handler failed\n"); error = ENXIO; goto fail; } @@ -436,11 +449,8 @@ ndis_attach(dev) /* * An NDIS device was detected. Inform the world. */ - if (sc->ndis_80211) - printf("ndis%d: 802.11 address: %6D\n", unit, eaddr, ":"); - else - printf("ndis%d: Ethernet address: %6D\n", unit, eaddr, ":"); - + device_printf(dev, "%s address: %6D\n", + sc->ndis_80211 ? "802.11" : "Ethernet", eaddr, ":"); ifp = &sc->arpcom.ac_if; ifp->if_softc = sc; @@ -477,7 +487,7 @@ ndis_attach(dev) r = ndis_get_info(sc, OID_802_11_SUPPORTED_RATES, (void *)rates, &len); if (r) - printf ("get rates failed: 0x%x\n", r); + device_printf (dev, "get rates failed: 0x%x\n", r); /* * We need a way to distinguish between 802.11b cards * and 802.11g cards. Unfortunately, Microsoft doesn't @@ -685,7 +695,7 @@ ndis_rxeof(adapter, packets, pktcnt) /* Stash the softc here so ptom can use it. */ p->np_softc = sc; if (ndis_ptom(&m0, p)) { - printf ("ndis%d: ptom failed\n", sc->ndis_unit); + device_printf (sc->ndis_dev, "ptom failed\n"); if (p->np_oob.npo_status == NDIS_STATUS_SUCCESS) ndis_return_packet(sc, p); } else { @@ -786,14 +796,14 @@ ndis_linksts_done(adapter) switch (block->nmb_getstat) { case NDIS_STATUS_MEDIA_CONNECT: sc->ndis_link = 1; - printf("ndis%d: link up\n", sc->ndis_unit); + device_printf(sc->ndis_dev, "link up\n"); if (sc->ndis_80211) ndis_getstate_80211(sc); if (ifp->if_snd.ifq_head != NULL) ndis_start(ifp); break; case NDIS_STATUS_MEDIA_DISCONNECT: - printf("ndis%d: link down\n", sc->ndis_unit); + device_printf(sc->ndis_dev, "link down\n"); if (sc->ndis_80211) ndis_getstate_80211(sc); sc->ndis_link = 0; @@ -1050,7 +1060,7 @@ ndis_init(xsc) sc->ndis_filter = ndis_filter; if (error) - printf ("set filter failed: %d\n", error); + device_printf (sc->ndis_dev, "set filter failed: %d\n", error); sc->ndis_txidx = 0; sc->ndis_txpending = sc->ndis_maxpkts; @@ -1131,8 +1141,7 @@ ndis_ifmedia_sts(ifp, ifmr) ifmr->ifm_active |= IFM_1000_T; break; default: - printf("ndis%d: unknown speed: %d\n", - sc->ndis_unit, media_info); + device_printf(sc->ndis_dev, "unknown speed: %d\n", media_info); break; } @@ -1161,7 +1170,7 @@ ndis_setstate_80211(sc) rval = ndis_set_info(sc, OID_802_11_AUTHENTICATION_MODE, &arg, &len); if (rval) - printf ("ndis%d: set auth failed: %d\n", sc->ndis_unit, rval); + device_printf (sc->ndis_dev, "set auth failed: %d\n", rval); /* Set network infrastructure mode. */ @@ -1174,7 +1183,7 @@ ndis_setstate_80211(sc) rval = ndis_set_info(sc, OID_802_11_INFRASTRUCTURE_MODE, &arg, &len); if (rval) - printf ("ndis%d: set infra failed: %d\n", sc->ndis_unit, rval); + device_printf (sc->ndis_dev, "set infra failed: %d\n", rval); /* Set WEP */ @@ -1202,17 +1211,16 @@ ndis_setstate_80211(sc) rval = ndis_set_info(sc, OID_802_11_ADD_WEP, &wep, &len); if (rval) - printf("ndis%d: set wepkey " - "failed: %d\n", sc->ndis_unit, - rval); + device_printf(sc->ndis_dev, + "set wepkey failed: %d\n", rval); } } arg = NDIS_80211_WEPSTAT_ENABLED; len = sizeof(arg); rval = ndis_set_info(sc, OID_802_11_WEP_STATUS, &arg, &len); if (rval) - printf("ndis%d: enable WEP failed: %d\n", - sc->ndis_unit, rval); + device_printf(sc->ndis_dev, + "enable WEP failed: %d\n", rval); } else { arg = NDIS_80211_WEPSTAT_DISABLED; len = sizeof(arg); @@ -1232,7 +1240,7 @@ ndis_setstate_80211(sc) rval = ndis_set_info(sc, OID_802_11_SSID, &ssid, &len); if (rval) - printf ("ndis%d: set ssid failed: %d\n", sc->ndis_unit, rval); + device_printf (sc->ndis_dev, "set ssid failed: %d\n", rval); return; } @@ -1262,7 +1270,7 @@ ndis_getstate_80211(sc) rval = ndis_get_info(sc, OID_802_11_INFRASTRUCTURE_MODE, &arg, &len); if (rval) - printf ("ndis%d: get infra failed: %d\n", sc->ndis_unit, rval); + device_printf (sc->ndis_dev, "get infra failed: %d\n", rval); switch(arg) { case NDIS_80211_NET_INFRA_IBSS: @@ -1280,7 +1288,7 @@ ndis_getstate_80211(sc) rval = ndis_get_info(sc, OID_802_11_SSID, &ssid, &len); if (rval) - printf ("ndis%d: get ssid failed: %d\n", sc->ndis_unit, rval); + device_printf (sc->ndis_dev, "get ssid failed: %d\n", rval); bcopy(ssid.ns_ssid, ic->ic_bss->ni_essid, ssid.ns_ssidlen); ic->ic_bss->ni_esslen = ssid.ns_ssidlen; @@ -1307,8 +1315,8 @@ ndis_getstate_80211(sc) } if (i == ic->ic_bss->ni_rates.rs_nrates) - printf ("ndis%d: no matching rate for: %d\n", - sc->ndis_unit, (arg / 10000) * 2); + device_printf (sc->ndis_dev, "no matching rate for: %d\n", + (arg / 10000) * 2); else ic->ic_bss->ni_txrate = i; @@ -1316,8 +1324,8 @@ ndis_getstate_80211(sc) rval = ndis_get_info(sc, OID_802_11_POWER_MODE, &arg, &len); if (rval) - printf ("ndis%d: get power mode failed: %d\n", - sc->ndis_unit, rval); + device_printf (sc->ndis_dev, + "get power mode failed: %d\n", rval); if (arg == NDIS_80211_POWERMODE_CAM) ic->ic_flags &= ~IEEE80211_F_PMGTON; else @@ -1328,8 +1336,8 @@ ndis_getstate_80211(sc) rval = ndis_get_info(sc, OID_802_11_WEP_STATUS, &arg, &len); if (rval) - printf ("ndis%d: get wep status failed: %d\n", - sc->ndis_unit, rval); + device_printf (sc->ndis_dev, + "get wep status failed: %d\n", rval); if (arg == NDIS_80211_WEPSTAT_ENABLED) ic->ic_flags |= IEEE80211_F_WEPON; @@ -1423,7 +1431,7 @@ ndis_watchdog(ifp) NDIS_LOCK(sc); ifp->if_oerrors++; - printf("ndis%d: watchdog timeout\n", sc->ndis_unit); + device_printf(sc->ndis_dev, "watchdog timeout\n"); ndis_reset(sc); |