Home | History | Annotate | Line # | Download | only in ic
ath_netbsd.c revision 1.10.20.1
      1  1.10.20.1    bouyer /*	$NetBSD: ath_netbsd.c,v 1.10.20.1 2007/10/25 22:37:31 bouyer Exp $ */
      2        1.6   xtraeme 
      3        1.1    dyoung /*-
      4        1.1    dyoung  * Copyright (c) 2003, 2004 David Young
      5        1.1    dyoung  * All rights reserved.
      6        1.1    dyoung  *
      7        1.1    dyoung  * Redistribution and use in source and binary forms, with or without
      8        1.1    dyoung  * modification, are permitted provided that the following conditions
      9        1.1    dyoung  * are met:
     10        1.1    dyoung  * 1. Redistributions of source code must retain the above copyright
     11        1.1    dyoung  *    notice, this list of conditions and the following disclaimer.
     12        1.1    dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1    dyoung  *    notice, this list of conditions and the following disclaimer in the
     14        1.1    dyoung  *    documentation and/or other materials provided with the distribution.
     15        1.1    dyoung  * 3. The name of the author may not be used to endorse or promote products
     16        1.1    dyoung  *    derived from this software without specific prior written permission.
     17        1.1    dyoung  *
     18        1.1    dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19        1.1    dyoung  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20        1.1    dyoung  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21        1.1    dyoung  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22        1.1    dyoung  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23        1.1    dyoung  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24        1.1    dyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25        1.1    dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26        1.1    dyoung  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27        1.1    dyoung  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28        1.1    dyoung  */
     29        1.6   xtraeme 
     30        1.6   xtraeme #include <sys/cdefs.h>
     31  1.10.20.1    bouyer __KERNEL_RCSID(0, "$NetBSD: ath_netbsd.c,v 1.10.20.1 2007/10/25 22:37:31 bouyer Exp $");
     32        1.6   xtraeme 
     33        1.1    dyoung #include <sys/param.h>
     34        1.1    dyoung #include <sys/types.h>
     35        1.1    dyoung #include <sys/errno.h>
     36        1.9   hubertf #include <sys/systm.h>
     37        1.1    dyoung #include <sys/sysctl.h>
     38        1.9   hubertf #include <sys/mbuf.h>
     39        1.1    dyoung #include <sys/malloc.h>
     40        1.1    dyoung #include <sys/lock.h>
     41        1.1    dyoung #include <sys/kernel.h>
     42        1.1    dyoung #include <sys/socket.h>
     43        1.1    dyoung #include <sys/sockio.h>
     44        1.1    dyoung #include <sys/sysctl.h>
     45        1.1    dyoung #include <sys/callout.h>
     46  1.10.20.1    bouyer #include <sys/bus.h>
     47        1.1    dyoung #include <machine/stdarg.h>
     48        1.1    dyoung #include <sys/endian.h>
     49        1.2    martin #include <sys/device.h>
     50        1.1    dyoung 
     51        1.1    dyoung #include <net/if.h>
     52        1.1    dyoung #include <net/if_dl.h>
     53        1.1    dyoung #include <net/if_media.h>
     54        1.1    dyoung #include <net/if_arp.h>
     55        1.1    dyoung #include <net/if_ether.h>
     56        1.1    dyoung #include <net/if_llc.h>
     57        1.1    dyoung 
     58        1.1    dyoung #include <net80211/ieee80211_netbsd.h>
     59        1.1    dyoung #include <net80211/ieee80211_var.h>
     60        1.1    dyoung #include <dev/ic/ath_netbsd.h>
     61        1.1    dyoung #include <dev/ic/athvar.h>
     62        1.3    dyoung 
     63        1.1    dyoung void
     64        1.1    dyoung device_printf(struct device dv, const char *fmt, ...)
     65        1.1    dyoung {
     66        1.1    dyoung         va_list ap;
     67        1.1    dyoung 
     68        1.1    dyoung         va_start(ap, fmt);
     69        1.1    dyoung         printf("%s: ", dv.dv_xname);
     70        1.1    dyoung         vprintf(fmt, ap);
     71        1.1    dyoung         va_end(ap);
     72        1.1    dyoung 	return;
     73        1.1    dyoung }
     74        1.1    dyoung 
     75        1.1    dyoung struct mbuf *
     76        1.1    dyoung m_defrag(struct mbuf *m0, int flags)
     77        1.1    dyoung {
     78        1.1    dyoung 	struct mbuf *m;
     79        1.1    dyoung 	MGETHDR(m, flags, MT_DATA);
     80        1.1    dyoung 	if (m == NULL)
     81        1.1    dyoung 		return NULL;
     82        1.1    dyoung 
     83        1.1    dyoung 	M_COPY_PKTHDR(m, m0);
     84        1.1    dyoung 	MCLGET(m, flags);
     85        1.1    dyoung 	if ((m->m_flags & M_EXT) == 0) {
     86        1.1    dyoung 		m_free(m);
     87        1.1    dyoung 		return NULL;
     88        1.1    dyoung 	}
     89       1.10  christos 	m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, void *));
     90        1.1    dyoung 	m->m_len = m->m_pkthdr.len;
     91        1.1    dyoung 	return m;
     92        1.1    dyoung }
     93        1.1    dyoung 
     94        1.1    dyoung /*
     95        1.7    dyoung  * Setup sysctl(3) MIB, hw.ath.*.
     96        1.1    dyoung  *
     97        1.1    dyoung  * TBD condition CTLFLAG_PERMANENT on being an LKM or not
     98        1.1    dyoung  */
     99        1.1    dyoung SYSCTL_SETUP(sysctl_ath, "sysctl ath subtree setup")
    100        1.1    dyoung {
    101        1.1    dyoung 	int rc;
    102        1.1    dyoung 	const struct sysctlnode *cnode, *rnode;
    103        1.1    dyoung 
    104        1.1    dyoung 	if ((rnode = ath_sysctl_treetop(clog)) == NULL)
    105        1.1    dyoung 		return;
    106        1.1    dyoung 
    107        1.1    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "dwell",
    108        1.1    dyoung 	    "channel dwell time (ms) for AP/station scanning",
    109        1.1    dyoung 	    dwelltime)) != 0)
    110        1.1    dyoung 		goto err;
    111        1.1    dyoung 
    112        1.1    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "calibrate",
    113        1.1    dyoung 	    "chip calibration interval (secs)", calinterval)) != 0)
    114        1.1    dyoung 		goto err;
    115        1.1    dyoung 
    116        1.1    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "outdoor",
    117        1.1    dyoung 	    "outdoor operation", outdoor)) != 0)
    118        1.1    dyoung 		goto err;
    119        1.1    dyoung 
    120        1.1    dyoung 	/* country code */
    121        1.1    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE,
    122        1.1    dyoung 	    "countrycode", "country code", countrycode)) != 0)
    123        1.1    dyoung 		goto err;
    124        1.1    dyoung 
    125        1.1    dyoung 	/* regulatory domain */
    126        1.7    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "regdomain",
    127        1.7    dyoung 	    "EEPROM regdomain code", regdomain)) != 0)
    128        1.1    dyoung 		goto err;
    129        1.1    dyoung 
    130        1.1    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE, "debug",
    131        1.1    dyoung 	    "control debugging printfs", debug)) != 0)
    132        1.1    dyoung 		goto err;
    133        1.1    dyoung 
    134        1.7    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READONLY, "rxbuf",
    135        1.7    dyoung 	    "rx buffers allocated", rxbuf)) != 0)
    136        1.7    dyoung 		goto err;
    137        1.7    dyoung 	if ((rc = SYSCTL_GLOBAL_INT(CTLFLAG_READONLY, "txbuf",
    138        1.7    dyoung 	    "tx buffers allocated", txbuf)) != 0)
    139        1.7    dyoung 		goto err;
    140        1.7    dyoung 
    141        1.1    dyoung 	return;
    142        1.1    dyoung err:
    143        1.1    dyoung 	printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
    144        1.1    dyoung }
    145        1.1    dyoung 
    146        1.1    dyoung static int
    147        1.1    dyoung ath_sysctl_slottime(SYSCTLFN_ARGS)
    148        1.1    dyoung {
    149        1.1    dyoung 	struct ath_softc *sc;
    150        1.1    dyoung 	struct sysctlnode node;
    151        1.1    dyoung 	u_int slottime;
    152        1.1    dyoung 	int error;
    153        1.1    dyoung 
    154        1.1    dyoung 	node = *rnode;
    155        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    156        1.1    dyoung 	slottime = ath_hal_getslottime(sc->sc_ah);
    157        1.1    dyoung 	node.sysctl_data = &slottime;
    158        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    159        1.1    dyoung 	if (error || newp == NULL)
    160        1.1    dyoung 		return error;
    161        1.1    dyoung 	return !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0;
    162        1.1    dyoung }
    163        1.1    dyoung 
    164        1.1    dyoung static int
    165        1.1    dyoung ath_sysctl_acktimeout(SYSCTLFN_ARGS)
    166        1.1    dyoung {
    167        1.1    dyoung 	struct ath_softc *sc;
    168        1.1    dyoung 	struct sysctlnode node;
    169        1.1    dyoung 	u_int acktimeout;
    170        1.1    dyoung 	int error;
    171        1.1    dyoung 
    172        1.1    dyoung 	node = *rnode;
    173        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    174        1.1    dyoung 	acktimeout = ath_hal_getacktimeout(sc->sc_ah);
    175        1.1    dyoung 	node.sysctl_data = &acktimeout;
    176        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    177        1.1    dyoung 	if (error || newp == NULL)
    178        1.1    dyoung 		return error;
    179        1.1    dyoung 	return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
    180        1.1    dyoung }
    181        1.1    dyoung 
    182        1.1    dyoung static int
    183        1.1    dyoung ath_sysctl_ctstimeout(SYSCTLFN_ARGS)
    184        1.1    dyoung {
    185        1.1    dyoung 	struct ath_softc *sc;
    186        1.1    dyoung 	struct sysctlnode node;
    187        1.1    dyoung 	u_int ctstimeout;
    188        1.1    dyoung 	int error;
    189        1.1    dyoung 
    190        1.1    dyoung 	node = *rnode;
    191        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    192        1.1    dyoung 	ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
    193        1.1    dyoung 	node.sysctl_data = &ctstimeout;
    194        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    195        1.1    dyoung 	if (error || newp == NULL)
    196        1.1    dyoung 		return error;
    197        1.1    dyoung 	return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
    198        1.1    dyoung }
    199        1.1    dyoung 
    200        1.1    dyoung static int
    201        1.1    dyoung ath_sysctl_softled(SYSCTLFN_ARGS)
    202        1.1    dyoung {
    203        1.1    dyoung 	struct ath_softc *sc;
    204        1.1    dyoung 	struct sysctlnode node;
    205        1.1    dyoung 	int softled;
    206        1.1    dyoung 	int error;
    207        1.1    dyoung 
    208        1.1    dyoung 	node = *rnode;
    209        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    210        1.1    dyoung 	softled = sc->sc_softled;
    211        1.1    dyoung 	node.sysctl_data = &softled;
    212        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    213        1.1    dyoung 	if (error || newp == NULL)
    214        1.1    dyoung 		return error;
    215        1.1    dyoung 	softled = (softled != 0);
    216        1.1    dyoung 	if (softled != sc->sc_softled) {
    217        1.1    dyoung 		if (softled) {
    218        1.1    dyoung 			/* NB: handle any sc_ledpin change */
    219        1.1    dyoung 			ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin);
    220        1.1    dyoung 			ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin,
    221        1.1    dyoung 				!sc->sc_ledon);
    222        1.1    dyoung 		}
    223        1.1    dyoung 		sc->sc_softled = softled;
    224        1.1    dyoung 	}
    225        1.1    dyoung 	return 0;
    226        1.1    dyoung }
    227        1.1    dyoung 
    228        1.1    dyoung static int
    229        1.1    dyoung ath_sysctl_rxantenna(SYSCTLFN_ARGS)
    230        1.1    dyoung {
    231        1.1    dyoung 	struct ath_softc *sc;
    232        1.1    dyoung 	struct sysctlnode node;
    233        1.1    dyoung 	u_int defantenna;
    234        1.1    dyoung 	int error;
    235        1.1    dyoung 
    236        1.1    dyoung 	node = *rnode;
    237        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    238        1.1    dyoung 	defantenna = ath_hal_getdefantenna(sc->sc_ah);
    239        1.1    dyoung 	node.sysctl_data = &defantenna;
    240        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    241        1.1    dyoung 	if (error || newp == NULL)
    242        1.1    dyoung 		return error;
    243        1.1    dyoung 	ath_hal_setdefantenna(sc->sc_ah, defantenna);
    244        1.1    dyoung 	return 0;
    245        1.1    dyoung }
    246        1.1    dyoung 
    247        1.1    dyoung static int
    248        1.1    dyoung ath_sysctl_diversity(SYSCTLFN_ARGS)
    249        1.1    dyoung {
    250        1.1    dyoung 	struct ath_softc *sc;
    251        1.1    dyoung 	struct sysctlnode node;
    252        1.1    dyoung 	u_int diversity;
    253        1.1    dyoung 	int error;
    254        1.1    dyoung 
    255        1.1    dyoung 	node = *rnode;
    256        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    257        1.1    dyoung 	diversity = sc->sc_diversity;
    258        1.1    dyoung 	node.sysctl_data = &diversity;
    259        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    260        1.1    dyoung 	if (error || newp == NULL)
    261        1.1    dyoung 		return error;
    262        1.1    dyoung 	if (!ath_hal_setdiversity(sc->sc_ah, diversity))
    263        1.1    dyoung 		return EINVAL;
    264        1.1    dyoung 	sc->sc_diversity = diversity;
    265        1.1    dyoung 	return 0;
    266        1.1    dyoung }
    267        1.1    dyoung 
    268        1.1    dyoung static int
    269        1.1    dyoung ath_sysctl_diag(SYSCTLFN_ARGS)
    270        1.1    dyoung {
    271        1.1    dyoung 	struct ath_softc *sc;
    272        1.1    dyoung 	struct sysctlnode node;
    273        1.1    dyoung 	u_int32_t diag;
    274        1.1    dyoung 	int error;
    275        1.1    dyoung 
    276        1.1    dyoung 	node = *rnode;
    277        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    278        1.1    dyoung 	if (!ath_hal_getdiag(sc->sc_ah, &diag))
    279        1.1    dyoung 		return EINVAL;
    280        1.1    dyoung 	node.sysctl_data = &diag;
    281        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    282        1.1    dyoung 	if (error || newp == NULL)
    283        1.1    dyoung 		return error;
    284        1.1    dyoung 	return !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
    285        1.1    dyoung }
    286        1.1    dyoung 
    287        1.1    dyoung static int
    288        1.1    dyoung ath_sysctl_tpscale(SYSCTLFN_ARGS)
    289        1.1    dyoung {
    290        1.1    dyoung 	struct ath_softc *sc;
    291        1.1    dyoung 	struct sysctlnode node;
    292        1.1    dyoung 	u_int32_t scale;
    293        1.1    dyoung 	int error;
    294        1.1    dyoung 
    295        1.1    dyoung 	node = *rnode;
    296        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    297        1.8       mrg 	(void)ath_hal_gettpscale(sc->sc_ah, &scale);
    298        1.1    dyoung 	node.sysctl_data = &scale;
    299        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    300        1.1    dyoung 	if (error || newp == NULL)
    301        1.1    dyoung 		return error;
    302        1.1    dyoung 	return !ath_hal_settpscale(sc->sc_ah, scale)
    303        1.1    dyoung 	    ? EINVAL
    304        1.1    dyoung 	    : ath_reset(&sc->sc_if);
    305        1.1    dyoung }
    306        1.1    dyoung 
    307        1.1    dyoung static int
    308        1.1    dyoung ath_sysctl_tpc(SYSCTLFN_ARGS)
    309        1.1    dyoung {
    310        1.1    dyoung 	struct ath_softc *sc;
    311        1.1    dyoung 	struct sysctlnode node;
    312        1.1    dyoung 	u_int tpc;
    313        1.1    dyoung 	int error;
    314        1.1    dyoung 
    315        1.1    dyoung 	node = *rnode;
    316        1.1    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    317        1.1    dyoung 	tpc = ath_hal_gettpc(sc->sc_ah);
    318        1.1    dyoung 	node.sysctl_data = &tpc;
    319        1.1    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    320        1.1    dyoung 	if (error || newp == NULL)
    321        1.1    dyoung 		return error;
    322        1.1    dyoung 	return !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
    323        1.1    dyoung }
    324        1.1    dyoung 
    325        1.7    dyoung static int
    326        1.7    dyoung ath_sysctl_rfkill(SYSCTLFN_ARGS)
    327        1.7    dyoung {
    328        1.7    dyoung 	struct ath_softc *sc;
    329        1.7    dyoung 	struct sysctlnode node;
    330        1.7    dyoung 	u_int rfkill;
    331        1.7    dyoung 	int error;
    332        1.7    dyoung 
    333        1.7    dyoung 	node = *rnode;
    334        1.7    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    335        1.7    dyoung 	rfkill = ath_hal_getrfkill(sc->sc_ah);
    336        1.7    dyoung 	node.sysctl_data = &rfkill;
    337        1.7    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    338        1.7    dyoung 	if (error || newp == NULL)
    339        1.7    dyoung 		return error;
    340        1.7    dyoung 	return !ath_hal_setrfkill(sc->sc_ah, rfkill) ? EINVAL : 0;
    341        1.7    dyoung }
    342        1.7    dyoung 
    343        1.7    dyoung static int
    344        1.7    dyoung ath_sysctl_rfsilent(SYSCTLFN_ARGS)
    345        1.7    dyoung {
    346        1.7    dyoung 	struct ath_softc *sc;
    347        1.7    dyoung 	struct sysctlnode node;
    348        1.7    dyoung 	u_int rfsilent;
    349        1.7    dyoung 	int error;
    350        1.7    dyoung 
    351        1.7    dyoung 	node = *rnode;
    352        1.7    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    353        1.8       mrg 	(void)ath_hal_getrfsilent(sc->sc_ah, &rfsilent);
    354        1.7    dyoung 	node.sysctl_data = &rfsilent;
    355        1.7    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    356        1.7    dyoung 	if (error || newp == NULL)
    357        1.7    dyoung 		return error;
    358        1.7    dyoung 	return !ath_hal_setrfsilent(sc->sc_ah, rfsilent) ? EINVAL : 0;
    359        1.7    dyoung }
    360        1.7    dyoung 
    361        1.7    dyoung static int
    362        1.7    dyoung ath_sysctl_regdomain(SYSCTLFN_ARGS)
    363        1.7    dyoung {
    364        1.7    dyoung 	struct ath_softc *sc;
    365        1.7    dyoung 	struct sysctlnode node;
    366        1.7    dyoung 	u_int32_t rd;
    367        1.7    dyoung 	int error;
    368        1.7    dyoung 
    369        1.7    dyoung 	node = *rnode;
    370        1.7    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    371        1.7    dyoung 	if (!ath_hal_getregdomain(sc->sc_ah, &rd))
    372        1.7    dyoung 		return EINVAL;
    373        1.7    dyoung 	node.sysctl_data = &rd;
    374        1.7    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    375        1.7    dyoung 	if (error || newp == NULL)
    376        1.7    dyoung 		return error;
    377        1.7    dyoung 	return !ath_hal_setregdomain(sc->sc_ah, rd) ? EINVAL : 0;
    378        1.7    dyoung }
    379        1.7    dyoung 
    380        1.7    dyoung static int
    381        1.7    dyoung ath_sysctl_tpack(SYSCTLFN_ARGS)
    382        1.7    dyoung {
    383        1.7    dyoung 	struct ath_softc *sc;
    384        1.7    dyoung 	struct sysctlnode node;
    385        1.7    dyoung 	u_int32_t tpack;
    386        1.7    dyoung 	int error;
    387        1.7    dyoung 
    388        1.7    dyoung 	node = *rnode;
    389        1.7    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    390        1.8       mrg 	(void)ath_hal_gettpack(sc->sc_ah, &tpack);
    391        1.7    dyoung 	node.sysctl_data = &tpack;
    392        1.7    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    393        1.7    dyoung 	if (error || newp == NULL)
    394        1.7    dyoung 		return error;
    395        1.7    dyoung 	return !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
    396        1.7    dyoung }
    397        1.7    dyoung 
    398        1.7    dyoung static int
    399        1.7    dyoung ath_sysctl_tpcts(SYSCTLFN_ARGS)
    400        1.7    dyoung {
    401        1.7    dyoung 	struct ath_softc *sc;
    402        1.7    dyoung 	struct sysctlnode node;
    403        1.7    dyoung 	u_int32_t tpcts;
    404        1.7    dyoung 	int error;
    405        1.7    dyoung 
    406        1.7    dyoung 	node = *rnode;
    407        1.7    dyoung 	sc = (struct ath_softc *)node.sysctl_data;
    408        1.8       mrg 	(void)ath_hal_gettpcts(sc->sc_ah, &tpcts);
    409        1.7    dyoung 	node.sysctl_data = &tpcts;
    410        1.7    dyoung 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    411        1.7    dyoung 	if (error || newp == NULL)
    412        1.7    dyoung 		return error;
    413        1.7    dyoung 	return !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
    414        1.7    dyoung }
    415        1.7    dyoung 
    416        1.4    dyoung const struct sysctlnode *
    417        1.3    dyoung ath_sysctl_instance(const char *dvname, struct sysctllog **log)
    418        1.3    dyoung {
    419        1.3    dyoung 	int rc;
    420        1.3    dyoung 	const struct sysctlnode *rnode;
    421        1.3    dyoung 
    422        1.3    dyoung 	if ((rc = sysctl_createv(log, 0, NULL, &rnode,
    423        1.3    dyoung 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
    424        1.3    dyoung 	    NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
    425        1.3    dyoung 		goto err;
    426        1.3    dyoung 
    427        1.3    dyoung 	if ((rc = sysctl_createv(log, 0, &rnode, &rnode,
    428        1.3    dyoung 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, dvname,
    429        1.3    dyoung 	    SYSCTL_DESCR("ath information and options"),
    430        1.3    dyoung 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
    431        1.3    dyoung 		goto err;
    432        1.3    dyoung 
    433        1.3    dyoung 	return rnode;
    434        1.3    dyoung err:
    435        1.3    dyoung 	printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
    436        1.3    dyoung 	return NULL;
    437        1.3    dyoung }
    438        1.3    dyoung 
    439        1.1    dyoung const struct sysctlnode *
    440        1.1    dyoung ath_sysctl_treetop(struct sysctllog **log)
    441        1.1    dyoung {
    442        1.1    dyoung 	int rc;
    443        1.1    dyoung 	const struct sysctlnode *rnode;
    444        1.1    dyoung 
    445        1.1    dyoung 	if ((rc = sysctl_createv(log, 0, NULL, &rnode,
    446        1.1    dyoung 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
    447        1.1    dyoung 	    NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
    448        1.1    dyoung 		goto err;
    449        1.1    dyoung 
    450        1.1    dyoung 	if ((rc = sysctl_createv(log, 0, &rnode, &rnode,
    451        1.1    dyoung 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "ath",
    452        1.1    dyoung 	    SYSCTL_DESCR("ath information and options"),
    453        1.1    dyoung 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
    454        1.1    dyoung 		goto err;
    455        1.1    dyoung 
    456        1.1    dyoung 	return rnode;
    457        1.1    dyoung err:
    458        1.1    dyoung 	printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
    459        1.1    dyoung 	return NULL;
    460        1.1    dyoung }
    461        1.1    dyoung 
    462        1.1    dyoung void
    463        1.1    dyoung ath_sysctlattach(struct ath_softc *sc)
    464        1.1    dyoung {
    465        1.1    dyoung 	int rc;
    466        1.1    dyoung 	struct sysctllog **log = &sc->sc_sysctllog;
    467        1.1    dyoung 	const struct sysctlnode *cnode, *rnode;
    468        1.1    dyoung 
    469        1.1    dyoung 	ath_hal_getcountrycode(sc->sc_ah, &sc->sc_countrycode);
    470        1.8       mrg 	(void)ath_hal_getregdomain(sc->sc_ah, &sc->sc_regdomain);
    471        1.1    dyoung 	sc->sc_debug = ath_debug;
    472        1.1    dyoung 	sc->sc_txintrperiod = ATH_TXINTR_PERIOD;
    473        1.1    dyoung 
    474        1.3    dyoung 	if ((rnode = ath_sysctl_instance(sc->sc_dev.dv_xname, log)) == NULL)
    475        1.1    dyoung 		return;
    476        1.1    dyoung 
    477        1.1    dyoung 	if ((rc = SYSCTL_INT(0, countrycode, "EEPROM country code")) != 0)
    478        1.1    dyoung 		goto err;
    479        1.1    dyoung 
    480        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, debug,
    481        1.1    dyoung 	    "control debugging printfs")) != 0)
    482        1.1    dyoung 		goto err;
    483        1.1    dyoung 
    484        1.1    dyoung #if 0
    485        1.1    dyoung 	/* channel dwell time (ms) for AP/station scanning */
    486        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, dwell,
    487        1.1    dyoung 	    "Channel dwell time (ms) for scanning")) != 0)
    488        1.1    dyoung 		goto err;
    489        1.1    dyoung #endif
    490        1.1    dyoung 
    491        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, slottime,
    492        1.1    dyoung 	    "802.11 slot time (us)")) != 0)
    493        1.1    dyoung 		goto err;
    494        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, acktimeout,
    495        1.1    dyoung 	    "802.11 ACK timeout (us)")) != 0)
    496        1.1    dyoung 		goto err;
    497        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, ctstimeout,
    498        1.1    dyoung 	    "802.11 CTS timeout (us)")) != 0)
    499        1.1    dyoung 		goto err;
    500        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, softled,
    501        1.1    dyoung 	    "enable/disable software LED support")) != 0)
    502        1.1    dyoung 		goto err;
    503        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledpin,
    504        1.1    dyoung 	    "GPIO pin connected to LED")) != 0)
    505        1.1    dyoung 		goto err;
    506        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledon,
    507        1.1    dyoung 	    "setting to turn LED on")) != 0)
    508        1.1    dyoung 		goto err;
    509        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, ledidle,
    510        1.1    dyoung 	    "idle time for inactivity LED (ticks)")) != 0)
    511        1.1    dyoung 		goto err;
    512        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, txantenna,
    513        1.1    dyoung 	    "tx antenna (0=auto)")) != 0)
    514        1.1    dyoung 		goto err;
    515        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rxantenna,
    516        1.1    dyoung 	    "default/rx antenna")) != 0)
    517        1.1    dyoung 		goto err;
    518        1.5     skrll 	if (ath_hal_hasdiversity(sc->sc_ah)) {
    519        1.1    dyoung 		if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, diversity,
    520        1.1    dyoung 		    "antenna diversity")) != 0)
    521        1.1    dyoung 			goto err;
    522        1.1    dyoung 	}
    523        1.1    dyoung 	if ((rc = SYSCTL_INT(CTLFLAG_READWRITE, txintrperiod,
    524        1.1    dyoung 	    "tx descriptor batching")) != 0)
    525        1.1    dyoung 		goto err;
    526        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, diag,
    527        1.1    dyoung 	    "h/w diagnostic control")) != 0)
    528        1.1    dyoung 		goto err;
    529        1.1    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpscale,
    530        1.1    dyoung 	    "tx power scaling")) != 0)
    531        1.1    dyoung 		goto err;
    532        1.5     skrll 	if (ath_hal_hastpc(sc->sc_ah)) {
    533        1.1    dyoung 		if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpc,
    534        1.1    dyoung 		    "enable/disable per-packet TPC")) != 0)
    535        1.1    dyoung 			goto err;
    536        1.7    dyoung 		if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpack,
    537        1.7    dyoung 		    "tx power for ack frames")) != 0)
    538        1.7    dyoung 			goto err;
    539        1.7    dyoung 		if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, tpcts,
    540        1.7    dyoung 		    "tx power for cts frames")) != 0)
    541        1.7    dyoung 			goto err;
    542        1.1    dyoung 	}
    543        1.7    dyoung 	if (ath_hal_hasrfsilent(sc->sc_ah)) {
    544        1.7    dyoung 		if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rfsilent,
    545        1.7    dyoung 		    "h/w RF silent config")) != 0)
    546        1.7    dyoung 			goto err;
    547        1.7    dyoung 		if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, rfkill,
    548        1.7    dyoung 		    "enable/disable RF kill switch")) != 0)
    549        1.7    dyoung 			goto err;
    550        1.7    dyoung 	}
    551        1.7    dyoung 	if ((rc = SYSCTL_INT_SUBR(CTLFLAG_READWRITE, regdomain,
    552        1.7    dyoung 	    "EEPROM regdomain code")) != 0)
    553        1.7    dyoung 		goto err;
    554        1.1    dyoung 	return;
    555        1.1    dyoung err:
    556        1.1    dyoung 	printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
    557        1.1    dyoung }
    558