Date: Tue, 22 Jan 2008 18:45:50 GMT From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 133885 for review Message-ID: <200801221845.m0MIjo43075135@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=133885 Change 133885 by sam@sam_ebb on 2008/01/22 18:45:44 add diagnostic api for fetching register contents etc. Affected files ... .. //depot/projects/wifi/sys/dev/ral/if_ral_pci.c#8 edit .. //depot/projects/wifi/sys/dev/ral/if_raldiag.h#1 add Differences ... ==== //depot/projects/wifi/sys/dev/ral/if_ral_pci.c#8 (text+ko) ==== @@ -269,3 +269,85 @@ return 0; } + +#include <dev/ral/if_raldiag.h> + +static int +getregdump(device_t dev, + const RAL_REGRANGE *regs, int nregs, + void *dstbuf, int space) +{ + struct ral_pci_softc *psc = device_get_softc(dev); + struct rt2560_softc *sc = &psc->u.sc_rt2560; + u_int32_t *dp = dstbuf; + int i; + + for (i = 0; i < nregs&& space >= 2*sizeof(u_int32_t); i++) { + u_int r = regs[i].start; + u_int e = regs[i].end; + *dp++ = (r<<16) | e; + space -= sizeof(u_int32_t); + do { + *dp++ = bus_space_read_4(sc->sc_st, sc->sc_sh, r); + r += sizeof(u_int32_t); + space -= sizeof(u_int32_t); + } while (r <= e && space >= sizeof(u_int32_t)); + } + return (char *) dp - (char *) dstbuf; +} + +/* + * Diagnostic interface. This is used by various + * tools to do things like retrieve register contents for + * debugging. The mechanism is intentionally opaque so that + * it can change frequently w/o concern for compatiblity. + */ +int +ral_ioctl_diag(device_t dev, struct ral_diag *ad) +{ + void *outdata, *indata; + int error, nregs, inspace; + RAL_REVS revs; + + switch (ad->ad_id & RAL_DIAG_ID) { + case RAL_DIAG_REVS: /* MAC/PHY/Radio revs */ + if (ad->ad_out_size != sizeof(revs)) + return EINVAL; + bzero(&revs, sizeof(revs)); + revs.ah_devid = pci_get_device(dev); + revs.ah_macRev = 0; + revs.ah_phyRev = 0; + return copyout(&revs, ad->ad_out_data, sizeof(revs)); + case RAL_DIAG_REGS: + /* + * Copy in register ranges. + */ + nregs = ad->ad_in_size / sizeof(RAL_REGRANGE); + if (nregs <= 0) + return EINVAL; + inspace = nregs * sizeof(RAL_REGRANGE); + indata = malloc(inspace, M_TEMP, M_NOWAIT); + if (indata == NULL) + return ENOMEM; + error = copyin(ad->ad_in_data, indata, inspace); + if (error) { + free(indata, M_TEMP); + return error; + } + /* + * Allocate a buffer for the results. + */ + outdata = malloc(ad->ad_out_size, M_TEMP, M_NOWAIT); + if (outdata == NULL) { + free(indata, M_TEMP); + return ENOMEM; + } + error = copyout(outdata, ad->ad_out_data, + getregdump(dev, indata, nregs, + outdata, ad->ad_out_size)); + free(indata, M_TEMP); + free(outdata, M_TEMP); + return error; + } + return EINVAL; +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801221845.m0MIjo43075135>