Date: Wed, 16 Apr 2003 13:11:12 -0700 (PDT) From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 29083 for review Message-ID: <200304162011.h3GKBC9R004192@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=29083 Change 29083 by jhb@jhb_laptop on 2003/04/16 13:10:20 IFC @29082 so alpha LINT builds. Affected files ... .. //depot/projects/smpng/sys/alpha/linux/linux.h#7 integrate .. //depot/projects/smpng/sys/alpha/linux/linux_machdep.c#12 integrate .. //depot/projects/smpng/sys/compat/linprocfs/linprocfs.c#25 integrate .. //depot/projects/smpng/sys/compat/linux/linux_misc.c#35 integrate .. //depot/projects/smpng/sys/dev/wl/if_wl.c#12 integrate .. //depot/projects/smpng/sys/dev/wl/if_wl.h#3 integrate Differences ... ==== //depot/projects/smpng/sys/alpha/linux/linux.h#7 (text+ko) ==== @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/alpha/linux/linux.h,v 1.57 2003/02/03 17:43:20 ume Exp $ + * $FreeBSD: src/sys/alpha/linux/linux.h,v 1.58 2003/04/16 20:04:47 jhb Exp $ */ #ifndef _ALPHA_LINUX_LINUX_H_ @@ -38,8 +38,8 @@ */ extern u_char linux_debug_map[]; #define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name) -#define ARGS(nm, fmt) "linux(%ld): "#nm"("fmt")\n", (long)p->p_pid -#define LMSG(fmt) "linux(%ld): "fmt"\n", (long)p->p_pid +#define ARGS(nm, fmt) "linux(%ld): "#nm"("fmt")\n", (long)td->td_proc->p_pid +#define LMSG(fmt) "linux(%ld): "fmt"\n", (long)td->td_proc->p_pid #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_LINUX); ==== //depot/projects/smpng/sys/alpha/linux/linux_machdep.c#12 (text+ko) ==== @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/alpha/linux/linux_machdep.c,v 1.26 2003/03/03 09:17:12 des Exp $ + * $FreeBSD: src/sys/alpha/linux/linux_machdep.c,v 1.28 2003/04/16 20:05:42 jhb Exp $ */ #include <sys/param.h> @@ -133,8 +133,8 @@ #ifdef DEBUG if (ldebug(clone)) { - printf(ARGS(clone, "flags %x, stack %x"), - (unsigned int)args->flags, (unsigned int)args->stack); + printf(ARGS(clone, "flags %x, stack %p"), + (unsigned int)args->flags, args->stack); if (args->flags & CLONE_PID) printf(LMSG("CLONE_PID not yet supported")); } @@ -208,7 +208,7 @@ #ifdef DEBUG if (ldebug(mmap)) - printf(ARGS(mmap, "%p, 0x%lx, 0x%x, 0x%x, 0x%x, 0x%lx"), + printf(ARGS(mmap, "%p, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx"), (void *)linux_args->addr, linux_args->len, linux_args->prot, linux_args->flags, linux_args->fd, linux_args->pos); @@ -281,7 +281,7 @@ bsd_args.pad = 0; #ifdef DEBUG if (ldebug(mmap)) - printf(ARGS(mmap, "%p, 0x%lx, 0x%x, 0x%x, 0x%x, 0x%lx)", + printf(ARGS(mmap, "%p, 0x%lx, 0x%x, 0x%x, 0x%x, 0x%lx"), (void *)bsd_args.addr, bsd_args.len, bsd_args.prot, @@ -294,7 +294,7 @@ error = mmap(td, &bsd_args); #ifdef DEBUG if (ldebug(mmap)) - printf(LMSG("mmap returns %d, 0x%lx", error, td->td_retval[0]); + printf(LMSG("mmap returns %d, 0x%lx"), error, td->td_retval[0]); #endif return (error); } @@ -314,7 +314,7 @@ #ifdef DEBUG if (ldebug(rt_sigsuspend)) - printf(ARGS(rt_sigsuspend, "%p, %d"), + printf(ARGS(rt_sigsuspend, "%p, %zd"), (void *)uap->newset, uap->sigsetsize); #endif if (uap->sigsetsize != sizeof(l_sigset_t)) @@ -338,7 +338,7 @@ #ifdef DEBUG if (ldebug(mprotect)) - printf(ARGS(mprotect, "%p, 0x%lx, 0x%x)", + printf(ARGS(mprotect, "%p, 0x%zx, 0x%lx"), (void *)uap->addr, uap->len, uap->prot); #endif return (mprotect(td, (void *)uap)); @@ -352,7 +352,7 @@ #ifdef DEBUG if (ldebug(munmap)) - printf(ARGS(munmap, "%p, 0x%lx", + printf(ARGS(munmap, "%p, 0x%lx"), (void *)uap->addr, uap->len); #endif return (munmap(td, (void *)uap)); ==== //depot/projects/smpng/sys/compat/linprocfs/linprocfs.c#25 (text+ko) ==== @@ -38,7 +38,7 @@ * * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 * - * $FreeBSD: src/sys/compat/linprocfs/linprocfs.c,v 1.62 2003/03/13 22:45:43 jhb Exp $ + * $FreeBSD: src/sys/compat/linprocfs/linprocfs.c,v 1.63 2003/04/16 19:46:26 jhb Exp $ */ #include <sys/param.h> @@ -116,9 +116,9 @@ unsigned long memfree; /* free memory in bytes */ unsigned long memshared; /* shared memory ??? */ unsigned long buffers, cached; /* buffer / cache memory ??? */ - u_quad_t swaptotal; /* total swap space in bytes */ - u_quad_t swapused; /* used swap space in bytes */ - u_quad_t swapfree; /* free swap space in bytes */ + unsigned long long swaptotal; /* total swap space in bytes */ + unsigned long long swapused; /* used swap space in bytes */ + unsigned long long swapfree; /* free swap space in bytes */ vm_object_t object; memtotal = physmem * PAGE_SIZE; @@ -209,20 +209,20 @@ "cpu\t\t\t: Alpha\n" "cpu model\t\t: %s\n" "cpu variation\t\t: %ld\n" - "cpu revision\t\t: %ld\n" + "cpu revision\t\t: %d\n" "cpu serial number\t: %s\n" "system type\t\t: %s\n" "system variation\t: %s\n" - "system revision\t\t: %ld\n" + "system revision\t\t: %d\n" "system serial number\t: %s\n" "cycle frequency [Hz]\t: %lu\n" - "timer frequency [Hz]\t: %lu\n" + "timer frequency [Hz]\t: %u\n" "page size [bytes]\t: %ld\n" "phys. address bits\t: %ld\n" "max. addr. space #\t: %ld\n" - "BogoMIPS\t\t: %lu.%02lu\n" - "kernel unaligned acc\t: %ld (pc=%lx,va=%lx)\n" - "user unaligned acc\t: %ld (pc=%lx,va=%lx)\n" + "BogoMIPS\t\t: %u.%02u\n" + "kernel unaligned acc\t: %d (pc=%x,va=%x)\n" + "user unaligned acc\t: %d (pc=%x,va=%x)\n" "platform string\t\t: %s\n" "cpus detected\t\t: %d\n" , @@ -421,7 +421,7 @@ cnt.v_swappgsout, cnt.v_intr, cnt.v_swtch, - (quad_t)boottime.tv_sec); + (long long)boottime.tv_sec); return (0); } @@ -435,7 +435,7 @@ getmicrouptime(&tv); sbuf_printf(sb, "%lld.%02ld %ld.%02ld\n", - (quad_t)tv.tv_sec, tv.tv_usec / 10000, + (long long)tv.tv_sec, tv.tv_usec / 10000, T2S(cp_time[CP_IDLE]), T2J(cp_time[CP_IDLE]) % 100); return (0); } @@ -514,8 +514,8 @@ PS_ADD("timeout", "%u", 0); /* XXX */ PS_ADD("itrealvalue", "%u", 0); /* XXX */ PS_ADD("starttime", "%d", 0); /* XXX */ - PS_ADD("vsize", "%u", kp.ki_size); - PS_ADD("rss", "%u", P2K(kp.ki_rssize)); + PS_ADD("vsize", "%ju", (uintmax_t)kp.ki_size); + PS_ADD("rss", "%ju", P2K((uintmax_t)kp.ki_rssize)); PS_ADD("rlim", "%u", 0); /* XXX */ PS_ADD("startcode", "%u", (unsigned)0); PS_ADD("endcode", "%u", 0); /* XXX */ @@ -625,15 +625,15 @@ * could also compute VmLck, but I don't really care enough to * implement it. Submissions are welcome. */ - sbuf_printf(sb, "VmSize:\t%8u kB\n", B2K(kp.ki_size)); + sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size)); sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */ - sbuf_printf(sb, "VmRss:\t%8u kB\n", P2K(kp.ki_rssize)); - sbuf_printf(sb, "VmData:\t%8u kB\n", P2K(kp.ki_dsize)); - sbuf_printf(sb, "VmStk:\t%8u kB\n", P2K(kp.ki_ssize)); - sbuf_printf(sb, "VmExe:\t%8u kB\n", P2K(kp.ki_tsize)); + sbuf_printf(sb, "VmRss:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize)); + sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize)); + sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize)); + sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize)); lsize = B2P(kp.ki_size) - kp.ki_dsize - kp.ki_ssize - kp.ki_tsize - 1; - sbuf_printf(sb, "VmLib:\t%8u kB\n", P2K(lsize)); + sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize)); /* * Signal masks ==== //depot/projects/smpng/sys/compat/linux/linux_misc.c#35 (text+ko) ==== @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/compat/linux/linux_misc.c,v 1.139 2003/03/13 22:45:43 jhb Exp $ + * $FreeBSD: src/sys/compat/linux/linux_misc.c,v 1.140 2003/04/16 20:07:48 jhb Exp $ */ #include "opt_mac.h" @@ -878,7 +878,7 @@ { #ifdef DEBUG if (ldebug(personality)) - printf(ARGS(personality, "%d"), args->per); + printf(ARGS(personality, "%ld"), args->per); #endif #ifndef __alpha__ if (args->per != 0) ==== //depot/projects/smpng/sys/dev/wl/if_wl.c#12 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $FreeBSD: src/sys/dev/wl/if_wl.c,v 1.48 2003/04/16 15:52:20 jhay Exp $ */ +/* $FreeBSD: src/sys/dev/wl/if_wl.c,v 1.50 2003/04/16 17:42:38 jhay Exp $ */ /* * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -188,7 +188,6 @@ * transmit buffer available in sram space. */ -#define NWL 4 #include "opt_wavelan.h" #include "opt_inet.h" @@ -199,12 +198,16 @@ #include <sys/mbuf.h> #include <sys/socket.h> #include <sys/syslog.h> +#include <machine/bus.h> +#include <machine/resource.h> #include <sys/bus.h> +#include <sys/rman.h> #include <sys/sysctl.h> #include <net/ethernet.h> #include <net/if.h> +#include <net/if_arp.h> #include <net/if_dl.h> #ifdef INET @@ -215,7 +218,7 @@ #endif #include <net/bpf.h> -#include <i386/isa/isa_device.h> +#include <isa/isavar.h> #include <i386/isa/ic/if_wl_i82586.h> /* Definitions for the Intel chip */ /* was 1000 in original, fed to DELAY(x) */ @@ -223,10 +226,6 @@ #include <dev/wl/if_wl.h> #include <machine/if_wl_wavelan.h> -#ifndef COMPAT_OLDISA -#error "The wl device requires the old isa compatibility shims" -#endif - static char t_packet[ETHERMTU + sizeof(struct ether_header) + sizeof(long)]; struct wl_softc{ @@ -246,7 +245,15 @@ short mode; u_char chan24; /* 2.4 Gz: channel number/EEPROM Area # */ u_short freq24; /* 2.4 Gz: resulting frequency */ - struct callout_handle watchdog_ch; + int rid_ioport; + int rid_irq; + struct resource *res_ioport; + struct resource *res_irq; + void *intr_cookie; + bus_space_tag_t bt; + bus_space_handle_t bh; + struct mtx wl_mtx; + struct callout_handle watchdog_ch; #ifdef WLCACHE int w_sigitems; /* number of cached entries */ /* array of cache entries */ @@ -255,21 +262,35 @@ int w_wrapindex; /* next "free" cache entry */ #endif }; -static struct wl_softc wl_softc[NWL]; + +#define WL_LOCK(_sc) mtx_lock(&(_sc)->wl_mtx) +#define WL_UNLOCK(_sc) mtx_unlock(&(_sc)->wl_mtx) -#define WLSOFTC(unit) ((struct wl_softc *)(&wl_softc[unit])) +static int wlprobe(device_t); +static int wlattach(device_t); +static int wldetach(device_t); -static int wlprobe(struct isa_device *); -static int wlattach(struct isa_device *); +static device_method_t wl_methods[] = { + DEVMETHOD(device_probe, wlprobe), + DEVMETHOD(device_attach, wlattach), + DEVMETHOD(device_detach, wldetach), + { 0, 0} +}; -struct isa_driver wldriver = { - INTR_TYPE_NET, - wlprobe, - wlattach, +static driver_t wl_driver = { "wl", - 0 + wl_methods, + sizeof (struct wl_softc) +}; + +devclass_t wl_devclass; +DRIVER_MODULE(wl, isa, wl_driver, wl_devclass, 0, 0); +MODULE_DEPEND(wl, isa, 1, 1, 1); +MODULE_DEPEND(wl, ether, 1, 1, 1); + +static struct isa_pnp_id wl_ids[] = { + {0, NULL} }; -COMPAT_ISA_DRIVER(wl, wldriver); /* * XXX The Wavelan appears to be prone to dropping stuff if you talk to @@ -301,39 +322,41 @@ static int gathersnr = 0; SYSCTL_INT(_machdep, OID_AUTO, wl_gather_snr, CTLFLAG_RW, &gathersnr, 0, ""); +static int wl_allocate_resources(device_t device); +static int wl_deallocate_resources(device_t device); static void wlstart(struct ifnet *ifp); static void wlinit(void *xsc); static int wlioctl(struct ifnet *ifp, u_long cmd, caddr_t data); static timeout_t wlwatchdog; -static ointhand2_t wlintr; -static void wlxmt(int unt, struct mbuf *m); -static int wldiag(int unt); -static int wlconfig(int unit); -static int wlcmd(int unit, char *str); -static void wlmmcstat(int unit); -static u_short wlbldru(int unit); +static void wlintr(void *arg); +static void wlxmt(struct wl_softc *sc, struct mbuf *m); +static int wldiag(struct wl_softc *sc); +static int wlconfig(struct wl_softc *sc); +static int wlcmd(struct wl_softc *sc, char *str); +static void wlmmcstat(struct wl_softc *sc); +static u_short wlbldru(struct wl_softc *sc); static u_short wlmmcread(u_int base, u_short reg); -static void wlinitmmc(int unit); -static int wlhwrst(int unit); -static void wlrustrt(int unit); -static void wlbldcu(int unit); -static int wlack(int unit); -static int wlread(int unit, u_short fd_p); -static void getsnr(int unit); -static void wlrcv(int unit); -static int wlrequeue(int unit, u_short fd_p); -static void wlsftwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, int unit); -static void wlhdwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, int unit); +static void wlinitmmc(struct wl_softc *sc); +static int wlhwrst(struct wl_softc *sc); +static void wlrustrt(struct wl_softc *sc); +static void wlbldcu(struct wl_softc *sc); +static int wlack(struct wl_softc *sc); +static int wlread(struct wl_softc *sc, u_short fd_p); +static void getsnr(struct wl_softc *sc); +static void wlrcv(struct wl_softc *sc); +static int wlrequeue(struct wl_softc *sc, u_short fd_p); +static void wlsftwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, struct wl_softc *sc); +static void wlhdwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, struct wl_softc *sc); #ifdef WLDEBUG -static void wltbd(int unit); +static void wltbd(struct wl_softc *sc); #endif static void wlgetpsa(int base, u_char *buf); -static void wlsetpsa(int unit); +static void wlsetpsa(struct wl_softc *sc); static u_short wlpsacrc(u_char *buf); -static void wldump(int unit); +static void wldump(struct wl_softc *sc); #ifdef WLCACHE -static void wl_cache_store(int, int, struct ether_header *, struct mbuf *); -static void wl_cache_zero(int unit); +static void wl_cache_store(struct wl_softc *, int, struct ether_header *, struct mbuf *); +static void wl_cache_zero(struct wl_softc *sc); #endif /* array for maping irq numbers to values for the irq parameter register */ @@ -360,26 +383,35 @@ * */ static int -wlprobe(struct isa_device *id) +wlprobe(device_t device) { - struct wl_softc *sc = &wl_softc[id->id_unit]; - short base = id->id_iobase; + struct wl_softc *sc; + short base; char *str = "wl%d: board out of range [0..%d]\n"; u_char inbuf[100]; - unsigned long oldpri; - int irq; + unsigned long junk, sirq; + int error, irq; + + error = ISA_PNP_PROBE(device_get_parent(device), device, wl_ids); + if (error == ENXIO || error == 0) + return (error); + + sc = device_get_softc(device); + error = wl_allocate_resources(device); + if (error) + goto errexit; + + base = rman_get_start(sc->res_ioport); /* TBD. not true. * regular CMD() will not work, since no softc yet */ #define PCMD(base, hacr) outw((base), (hacr)) - oldpri = splimp(); PCMD(base, HACR_RESET); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ PCMD(base, HACR_RESET); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ - splx(oldpri); /* clear reset command and set PIO#1 in autoincrement mode */ PCMD(base, HACR_DEFAULT); @@ -390,8 +422,10 @@ outw(PIOR1(base), 0); /* rewind */ insw(PIOP1(base), inbuf, strlen(str)/2+1); /* read result */ - if (bcmp(str, inbuf, strlen(str))) - return(0); + if (bcmp(str, inbuf, strlen(str))) { + error = ENXIO; + goto errexit; + } sc->chan24 = 0; /* 2.4 Gz: config channel */ sc->freq24 = 0; /* 2.4 Gz: frequency */ @@ -404,17 +438,26 @@ if (irqvals[irq] == inbuf[WLPSA_IRQNO]) break; if ((irq == 0) || (irqvals[irq] == 0)){ - printf("wl%d: PSA corrupt (invalid IRQ value)\n", id->id_unit); - id->id_irq = 0; /* no interrupt */ + printf("wl%d: PSA corrupt (invalid IRQ value)\n", + device_get_unit(device)); } else { /* * If the IRQ requested by the PSA is already claimed by another * device, the board won't work, but the user can still access the * driver to change the IRQ. */ - id->id_irq = (1<<irq); /* use IRQ from PSA */ + if (bus_get_resource(device, SYS_RES_IRQ, 0, &sirq, &junk)) + goto errexit; + if (irq != (int)sirq) + printf("wl%d: board is configured for interrupt %d\n", + device_get_unit(device), irq); } - return(16); + wl_deallocate_resources(device); + return (0); + +errexit: + wl_deallocate_resources(device); + return (error); } @@ -431,30 +474,45 @@ * */ static int -wlattach(struct isa_device *id) +wlattach(device_t device) { - struct wl_softc *sc = (struct wl_softc *) &wl_softc[id->id_unit]; - short base = id->id_iobase; - int i,j; - u_char unit = id->id_unit; - struct ifnet *ifp = &sc->wl_if; + struct wl_softc *sc; + short base; + int error, i, j; + int unit; + struct ifnet *ifp; + + sc = device_get_softc(device); + ifp = &sc->wl_if; + + mtx_init(&sc->wl_mtx, device_get_nameunit(device), MTX_NETWORK_LOCK, + MTX_DEF | MTX_RECURSE); + + error = wl_allocate_resources(device); + if (error) { + wl_deallocate_resources(device); + return (ENXIO); + } + + base = rman_get_start(sc->res_ioport); + unit = device_get_unit(device); #ifdef WLDEBUG printf("wlattach: base %x, unit %d\n", base, unit); #endif - id->id_ointr = wlintr; + sc->base = base; sc->unit = unit; sc->flags = 0; sc->mode = 0; sc->hacr = HACR_RESET; callout_handle_init(&sc->watchdog_ch); - CMD(unit); /* reset the board */ + CMD(sc); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ /* clear reset command and set PIO#2 in parameter access mode */ sc->hacr = (HACR_DEFAULT & ~HACR_16BITS); - CMD(unit); + CMD(sc); /* Read the PSA from the board for our later reference */ wlgetpsa(base, sc->psa); @@ -473,9 +531,9 @@ /* enter normal 16 bit mode operation */ sc->hacr = HACR_DEFAULT; - CMD(unit); + CMD(sc); - wlinitmmc(unit); + wlinitmmc(sc); outw(PIOR1(base), OFFSET_SCB + 8); /* address of scb_crcerrs */ outw(PIOP1(base), 0); /* clear scb_crcerrs */ outw(PIOP1(base), 0); /* clear scb_alnerrs */ @@ -484,7 +542,6 @@ bzero(ifp, sizeof(ifp)); ifp->if_softc = sc; - ifp->if_unit = id->id_unit; ifp->if_mtu = WAVELAN_MTU; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; #ifdef WLDEBUG @@ -500,6 +557,7 @@ ifp->if_start = wlstart; ifp->if_ioctl = wlioctl; ifp->if_timer = 0; /* paranoia */ + ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; /* no entries ifp->if_watchdog ifp->if_done @@ -514,20 +572,94 @@ printf(", Freq %d MHz",sc->freq24); /* 2.4 Gz */ printf("\n"); /* 2.4 Gz */ + bus_setup_intr(device, sc->res_irq, INTR_TYPE_NET, wlintr, sc, &sc->intr_cookie); if (bootverbose) - wldump(unit); - return(1); + wldump(sc); + return (0); +} + +static int +wldetach(device_t device) +{ + struct wl_softc *sc = device_get_softc(device); + device_t parent = device_get_parent(device); + struct ifnet *ifp; + + ifp = &sc->wl_if; + ether_ifdetach(ifp); + + WL_LOCK(sc); + + /* reset the board */ + sc->hacr = HACR_RESET; + CMD(sc); + sc->hacr = HACR_DEFAULT; + CMD(sc); + + if (sc->intr_cookie != NULL) { + BUS_TEARDOWN_INTR(parent, device, sc->res_irq, sc->intr_cookie); + sc->intr_cookie = NULL; + } + + bus_generic_detach(device); + wl_deallocate_resources(device); + WL_UNLOCK(sc); + mtx_destroy(&sc->wl_mtx); + return (0); +} + +static int +wl_allocate_resources(device_t device) +{ + struct wl_softc *sc = device_get_softc(device); + int ports = 16; /* Number of ports */ + + sc->res_ioport = bus_alloc_resource(device, SYS_RES_IOPORT, + &sc->rid_ioport, 0ul, ~0ul, ports, RF_ACTIVE); + if (sc->res_ioport == NULL) + goto errexit; + + sc->res_irq = bus_alloc_resource(device, SYS_RES_IRQ, + &sc->rid_irq, 0ul, ~0ul, 1, RF_SHAREABLE|RF_ACTIVE); + if (sc->res_irq == NULL) + goto errexit; + return (0); + +errexit: + wl_deallocate_resources(device); + return (ENXIO); +} + +static int +wl_deallocate_resources(device_t device) +{ + struct wl_softc *sc = device_get_softc(device); + + if (sc->res_irq != 0) { + bus_deactivate_resource(device, SYS_RES_IRQ, + sc->rid_irq, sc->res_irq); + bus_release_resource(device, SYS_RES_IRQ, + sc->rid_irq, sc->res_irq); + sc->res_irq = 0; + } + if (sc->res_ioport != 0) { + bus_deactivate_resource(device, SYS_RES_IOPORT, + sc->rid_ioport, sc->res_ioport); + bus_release_resource(device, SYS_RES_IOPORT, + sc->rid_ioport, sc->res_ioport); + sc->res_ioport = 0; + } + return (0); } /* * Print out interesting information about the 82596. */ static void -wldump(int unit) +wldump(struct wl_softc *sc) { - struct wl_softc *sp = WLSOFTC(unit); - int base = sp->base; + int base = sc->base; int i; printf("hasr %04x\n", inw(HASR(base))); @@ -553,19 +685,18 @@ /* Initialize the Modem Management Controller */ static void -wlinitmmc(int unit) +wlinitmmc(struct wl_softc *sc) { - struct wl_softc *sp = WLSOFTC(unit); - int base = sp->base; + int base = sc->base; int configured; - int mode = sp->mode; + int mode = sc->mode; int i; /* 2.4 Gz */ /* enter 8 bit operation */ - sp->hacr = (HACR_DEFAULT & ~HACR_16BITS); - CMD(unit); + sc->hacr = (HACR_DEFAULT & ~HACR_16BITS); + CMD(sc); - configured = sp->psa[WLPSA_CONFIGURED] & 1; + configured = sc->psa[WLPSA_CONFIGURED] & 1; /* * Set default modem control parameters. Taken from NCR document @@ -580,7 +711,7 @@ MMC_WRITE(MMC_DECAY_UPDAT_PRM, 0x00); if (!configured) { MMC_WRITE(MMC_LOOPT_SEL, 0x00); - if (sp->psa[WLPSA_COMPATNO] & 1) { + if (sc->psa[WLPSA_COMPATNO] & 1) { MMC_WRITE(MMC_THR_PRE_SET, 0x01); /* 0x04 for AT and 0x01 for MCA */ } else { MMC_WRITE(MMC_THR_PRE_SET, 0x04); /* 0x04 for AT and 0x01 for MCA */ @@ -588,7 +719,7 @@ MMC_WRITE(MMC_QUALITY_THR, 0x03); } else { /* use configuration defaults from parameter storage area */ - if (sp->psa[WLPSA_NWIDENABLE] & 1) { + if (sc->psa[WLPSA_NWIDENABLE] & 1) { if ((mode & (MOD_PROM | MOD_ENAL)) && wl_ignore_nwid) { MMC_WRITE(MMC_LOOPT_SEL, 0x40); } else { @@ -597,23 +728,23 @@ } else { MMC_WRITE(MMC_LOOPT_SEL, 0x40); /* disable network id check */ } - MMC_WRITE(MMC_THR_PRE_SET, sp->psa[WLPSA_THRESH]); - MMC_WRITE(MMC_QUALITY_THR, sp->psa[WLPSA_QUALTHRESH]); + MMC_WRITE(MMC_THR_PRE_SET, sc->psa[WLPSA_THRESH]); + MMC_WRITE(MMC_QUALITY_THR, sc->psa[WLPSA_QUALTHRESH]); } MMC_WRITE(MMC_FREEZE, 0x00); MMC_WRITE(MMC_ENCR_ENABLE, 0x00); - MMC_WRITE(MMC_NETW_ID_L,sp->nwid[1]); /* set NWID */ - MMC_WRITE(MMC_NETW_ID_H,sp->nwid[0]); + MMC_WRITE(MMC_NETW_ID_L,sc->nwid[1]); /* set NWID */ + MMC_WRITE(MMC_NETW_ID_H,sc->nwid[0]); /* enter normal 16 bit mode operation */ - sp->hacr = HACR_DEFAULT; - CMD(unit); - CMD(unit); /* virtualpc1 needs this! */ + sc->hacr = HACR_DEFAULT; + CMD(sc); + CMD(sc); /* virtualpc1 needs this! */ - if (sp->psa[WLPSA_COMPATNO]== /* 2.4 Gz: half-card ver */ + if (sc->psa[WLPSA_COMPATNO]== /* 2.4 Gz: half-card ver */ WLPSA_COMPATNO_WL24B) { /* 2.4 Gz */ - i=sp->chan24<<4; /* 2.4 Gz: position ch # */ + i=sc->chan24<<4; /* 2.4 Gz: position ch # */ MMC_WRITE(MMC_EEADDR,i+0x0f); /* 2.4 Gz: named ch, wc=16 */ MMC_WRITE(MMC_EECTRL,MMC_EECTRL_DWLD+ /* 2.4 Gz: Download Synths */ MMC_EECTRL_EEOP_READ); /* 2.4 Gz: Read EEPROM */ @@ -639,14 +770,14 @@ MMC_WRITE(MMC_ANALCTRL, /* 2.4 Gz: EXT ant+polarity */ MMC_ANALCTRL_ANTPOL + /* 2.4 Gz: */ MMC_ANALCTRL_EXTANT); /* 2.4 Gz: */ - i=sp->chan24<<4; /* 2.4 Gz: position ch # */ + i=sc->chan24<<4; /* 2.4 Gz: position ch # */ MMC_WRITE(MMC_EEADDR,i); /* 2.4 Gz: get frequency */ MMC_WRITE(MMC_EECTRL, /* 2.4 Gz: EEPROM read */ MMC_EECTRL_EEOP_READ); /* 2.4 Gz: */ DELAY(40); /* 2.4 Gz */ i = wlmmcread(base,MMC_EEDATALrv) /* 2.4 Gz: freq val */ + (wlmmcread(base,MMC_EEDATAHrv)<<8); /* 2.4 Gz */ - sp->freq24 = (i>>6)+2400; /* 2.4 Gz: save real freq */ + sc->freq24 = (i>>6)+2400; /* 2.4 Gz: save real freq */ } } @@ -667,7 +798,6 @@ struct wl_softc *sc = xsc; struct ifnet *ifp = &sc->wl_if; int stat; - u_long oldpri; #ifdef WLDEBUG if (sc->wl_if.if_flags & IFF_DEBUG) @@ -675,8 +805,7 @@ #endif if (TAILQ_FIRST(&ifp->if_addrhead) == (struct ifaddr *)0) return; - oldpri = splimp(); - if ((stat = wlhwrst(sc->unit)) == TRUE) { + if ((stat = wlhwrst(sc)) == TRUE) { sc->wl_if.if_flags |= IFF_RUNNING; /* same as DSF_RUNNING */ /* * OACTIVE is used by upper-level routines @@ -692,7 +821,6 @@ } else { printf("wl%d init(): trouble resetting board.\n", sc->unit); } - splx(oldpri); } /* @@ -706,40 +834,39 @@ * */ static int -wlhwrst(int unit) +wlhwrst(struct wl_softc *sc) { - struct wl_softc *sc = WLSOFTC(unit); #ifdef WLDEBUG if (sc->wl_if.if_flags & IFF_DEBUG) - printf("wl%d: entered wlhwrst()\n",unit); + printf("wl%d: entered wlhwrst()\n", sc->unit); #endif sc->hacr = HACR_RESET; - CMD(unit); /* reset the board */ + CMD(sc); /* reset the board */ /* clear reset command and set PIO#1 in autoincrement mode */ sc->hacr = HACR_DEFAULT; - CMD(unit); + CMD(sc); #ifdef WLDEBUG if (sc->wl_if.if_flags & IFF_DEBUG) - wlmmcstat(unit); /* Display MMC registers */ + wlmmcstat(sc); /* Display MMC registers */ #endif /* WLDEBUG */ - wlbldcu(unit); /* set up command unit structures */ + wlbldcu(sc); /* set up command unit structures */ - if (wldiag(unit) == 0) + if (wldiag(sc) == 0) return(0); - if (wlconfig(unit) == 0) + if (wlconfig(sc) == 0) return(0); /* * insert code for loopback test here */ - wlrustrt(unit); /* start receive unit */ + wlrustrt(sc); /* start receive unit */ /* enable interrupts */ sc->hacr = (HACR_DEFAULT | HACR_INTRON); - CMD(unit); + CMD(sc); return(1); } @@ -752,16 +879,15 @@ * */ static void -wlbldcu(int unit) +wlbldcu(struct wl_softc *sc) { - struct wl_softc *sc = WLSOFTC(unit); short base = sc->base; scp_t scp; iscp_t iscp; scb_t scb; ac_t cb; tbd_t tbd; - int i; + int i; bzero(&scp, sizeof(scp)); scp.scp_sysbus = 0; @@ -789,21 +915,21 @@ outw(PIOR1(base), OFFSET_SCB); outsw(PIOP1(base), &scb, sizeof(scb_t)/2); - SET_CHAN_ATTN(unit); + SET_CHAN_ATTN(sc); outw(PIOR0(base), OFFSET_ISCP + 0); /* address of iscp_busy */ for (i = 1000000; inw(PIOP0(base)) && (i-- > 0); ) continue; if (i <= 0) - printf("wl%d bldcu(): iscp_busy timeout.\n", unit); + printf("wl%d bldcu(): iscp_busy timeout.\n", sc->unit); outw(PIOR0(base), OFFSET_SCB + 0); /* address of scb_status */ for (i = STATUS_TRIES; i-- > 0; ) { if (inw(PIOP0(base)) == (SCB_SW_CX|SCB_SW_CNA)) break; } if (i <= 0) - printf("wl%d bldcu(): not ready after reset.\n", unit); - wlack(unit); + printf("wl%d bldcu(): not ready after reset.\n", sc->unit); + wlack(sc); cb.ac_status = 0; cb.ac_command = AC_CW_EL; /* NOP */ @@ -833,10 +959,11 @@ { int unit = ifp->if_unit; struct mbuf *m; - struct wl_softc *sc = WLSOFTC(unit); + struct wl_softc *sc = ifp->if_softc; short base = sc->base; int scb_status, cu_status, scb_command; + WL_LOCK(sc); #ifdef WLDEBUG if (sc->wl_if.if_flags & IFF_DEBUG) printf("wl%d: entered wlstart()\n",unit); @@ -869,6 +996,7 @@ #endif if (xmt_watch) printf("!!"); } else { + WL_UNLOCK(sc); return; /* genuinely still busy */ } } else if ((scb_status & 0x0700) == SCB_CUS_ACTV || @@ -878,6 +1006,7 @@ unit, scb_status, cu_status); #endif if (xmt_watch) printf("wl%d: busy?!",unit); + WL_UNLOCK(sc); return; /* hey, why are we busy? */ } @@ -895,10 +1024,11 @@ sc->watchdog_ch = timeout(wlwatchdog, sc, 10); sc->wl_ac.ac_if.if_flags |= IFF_OACTIVE; sc->wl_if.if_opackets++; - wlxmt(unit, m); + wlxmt(sc, m); } else { sc->wl_ac.ac_if.if_flags &= ~IFF_OACTIVE; } + WL_UNLOCK(sc); return; } @@ -921,9 +1051,8 @@ * */ static int -wlread(int unit, u_short fd_p) +wlread(struct wl_softc *sc, u_short fd_p) { - struct wl_softc *sc = WLSOFTC(unit); struct ifnet *ifp = &sc->wl_if; short base = sc->base; fd_t fd; @@ -937,12 +1066,12 @@ #ifdef WLDEBUG if (sc->wl_if.if_flags & IFF_DEBUG) - printf("wl%d: entered wlread()\n", unit); + printf("wl%d: entered wlread()\n", sc->unit); #endif if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) { - printf("wl%d read(): board is not running.\n", unit); + printf("wl%d read(): board is not running.\n", sc->unit); sc->hacr &= ~HACR_INTRON; - CMD(unit); /* turn off interrupts */ + CMD(sc); /* turn off interrupts */ } /* @@ -951,10 +1080,10 @@ outw(PIOR1(base), fd_p); insw(PIOP1(base), &fd, sizeof(fd_t)/2); if (fd.rbd_offset == I82586NULL) { - if (wlhwrst(unit) != TRUE) { + if (wlhwrst(sc) != TRUE) { sc->hacr &= ~HACR_INTRON; - CMD(unit); /* turn off interrupts */ - printf("wl%d read(): hwrst trouble.\n", unit); + CMD(sc); /* turn off interrupts */ + printf("wl%d read(): hwrst trouble.\n", sc->unit); } return 0; } @@ -968,10 +1097,10 @@ */ m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); if (m == NULL) { - if (wlhwrst(unit) != TRUE) { + if (wlhwrst(sc) != TRUE) { sc->hacr &= ~HACR_INTRON; - CMD(unit); /* turn off interrupts */ - printf("wl%d read(): hwrst trouble.\n", unit); + CMD(sc); /* turn off interrupts */ + printf("wl%d read(): hwrst trouble.\n", sc->unit); >>> TRUNCATED FOR MAIL (1000 lines) <<<help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304162011.h3GKBC9R004192>
