1 /* $NetBSD: ath_netbsd.c,v 1.16 2008/11/12 12:36:11 ad Exp $ */
4 * Copyright (c) 2003, 2004 David Young
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: ath_netbsd.c,v 1.16 2008/11/12 12:36:11 ad Exp $");
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/errno.h>
34 #include <sys/systm.h>
35 #include <sys/sysctl.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
39 #include <sys/socket.h>
40 #include <sys/sockio.h>
41 #include <sys/sysctl.h>
42 #include <sys/callout.h>
44 #include <machine/stdarg.h>
45 #include <sys/endian.h>
46 #include <sys/device.h>
49 #include <net/if_dl.h>
50 #include <net/if_media.h>
51 #include <net/if_arp.h>
52 #include <net/if_ether.h>
53 #include <net/if_llc.h>
55 #include <net80211/ieee80211_netbsd.h>
56 #include <net80211/ieee80211_var.h>
57 #include <dev/ic/ath_netbsd.h>
58 #include <dev/ic/athvar.h>
61 device_printf(device_t dev
, const char *fmt
, ...)
66 printf("%s: ", device_xname(dev
));
73 * Setup sysctl(3) MIB, hw.ath.*.
75 * TBD condition CTLFLAG_PERMANENT on being a module or not
77 SYSCTL_SETUP(sysctl_ath
, "sysctl ath subtree setup")
80 const struct sysctlnode
*cnode
, *rnode
;
82 if ((rnode
= ath_sysctl_treetop(clog
)) == NULL
)
85 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE
, "dwell",
86 "channel dwell time (ms) for AP/station scanning",
90 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE
, "calibrate",
91 "chip calibration interval (secs)", calinterval
)) != 0)
94 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE
, "outdoor",
95 "outdoor operation", outdoor
)) != 0)
99 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE
,
100 "countrycode", "country code", countrycode
)) != 0)
103 /* regulatory domain */
104 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE
, "regdomain",
105 "EEPROM regdomain code", regdomain
)) != 0)
108 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READWRITE
, "debug",
109 "control debugging printfs", debug
)) != 0)
112 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READONLY
, "rxbuf",
113 "rx buffers allocated", rxbuf
)) != 0)
115 if ((rc
= SYSCTL_GLOBAL_INT(CTLFLAG_READONLY
, "txbuf",
116 "tx buffers allocated", txbuf
)) != 0)
121 printf("%s: sysctl_createv failed (rc = %d)\n", __func__
, rc
);
125 ath_sysctl_slottime(SYSCTLFN_ARGS
)
127 struct ath_softc
*sc
;
128 struct sysctlnode node
;
133 sc
= (struct ath_softc
*)node
.sysctl_data
;
134 slottime
= ath_hal_getslottime(sc
->sc_ah
);
135 node
.sysctl_data
= &slottime
;
136 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
137 if (error
|| newp
== NULL
)
139 return !ath_hal_setslottime(sc
->sc_ah
, slottime
) ? EINVAL
: 0;
143 ath_sysctl_acktimeout(SYSCTLFN_ARGS
)
145 struct ath_softc
*sc
;
146 struct sysctlnode node
;
151 sc
= (struct ath_softc
*)node
.sysctl_data
;
152 acktimeout
= ath_hal_getacktimeout(sc
->sc_ah
);
153 node
.sysctl_data
= &acktimeout
;
154 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
155 if (error
|| newp
== NULL
)
157 return !ath_hal_setacktimeout(sc
->sc_ah
, acktimeout
) ? EINVAL
: 0;
161 ath_sysctl_ctstimeout(SYSCTLFN_ARGS
)
163 struct ath_softc
*sc
;
164 struct sysctlnode node
;
169 sc
= (struct ath_softc
*)node
.sysctl_data
;
170 ctstimeout
= ath_hal_getctstimeout(sc
->sc_ah
);
171 node
.sysctl_data
= &ctstimeout
;
172 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
173 if (error
|| newp
== NULL
)
175 return !ath_hal_setctstimeout(sc
->sc_ah
, ctstimeout
) ? EINVAL
: 0;
179 ath_sysctl_softled(SYSCTLFN_ARGS
)
181 struct ath_softc
*sc
;
182 struct sysctlnode node
;
187 sc
= (struct ath_softc
*)node
.sysctl_data
;
188 softled
= sc
->sc_softled
;
189 node
.sysctl_data
= &softled
;
190 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
191 if (error
|| newp
== NULL
)
193 softled
= (softled
!= 0);
194 if (softled
!= sc
->sc_softled
) {
196 /* NB: handle any sc_ledpin change */
197 ath_hal_gpioCfgOutput(sc
->sc_ah
, sc
->sc_ledpin
);
198 ath_hal_gpioset(sc
->sc_ah
, sc
->sc_ledpin
,
201 sc
->sc_softled
= softled
;
207 ath_sysctl_rxantenna(SYSCTLFN_ARGS
)
209 struct ath_softc
*sc
;
210 struct sysctlnode node
;
215 sc
= (struct ath_softc
*)node
.sysctl_data
;
216 defantenna
= ath_hal_getdefantenna(sc
->sc_ah
);
217 node
.sysctl_data
= &defantenna
;
218 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
219 if (error
|| newp
== NULL
)
221 ath_hal_setdefantenna(sc
->sc_ah
, defantenna
);
226 ath_sysctl_diversity(SYSCTLFN_ARGS
)
228 struct ath_softc
*sc
;
229 struct sysctlnode node
;
234 sc
= (struct ath_softc
*)node
.sysctl_data
;
235 diversity
= sc
->sc_diversity
;
236 node
.sysctl_data
= &diversity
;
237 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
238 if (error
|| newp
== NULL
)
240 if (!ath_hal_setdiversity(sc
->sc_ah
, diversity
))
242 sc
->sc_diversity
= diversity
;
247 ath_sysctl_diag(SYSCTLFN_ARGS
)
249 struct ath_softc
*sc
;
250 struct sysctlnode node
;
255 sc
= (struct ath_softc
*)node
.sysctl_data
;
256 if (!ath_hal_getdiag(sc
->sc_ah
, &diag
))
258 node
.sysctl_data
= &diag
;
259 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
260 if (error
|| newp
== NULL
)
262 return !ath_hal_setdiag(sc
->sc_ah
, diag
) ? EINVAL
: 0;
266 ath_sysctl_tpscale(SYSCTLFN_ARGS
)
268 struct ath_softc
*sc
;
269 struct sysctlnode node
;
274 sc
= (struct ath_softc
*)node
.sysctl_data
;
275 (void)ath_hal_gettpscale(sc
->sc_ah
, &scale
);
276 node
.sysctl_data
= &scale
;
277 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
278 if (error
|| newp
== NULL
)
280 return !ath_hal_settpscale(sc
->sc_ah
, scale
)
282 : ath_reset(&sc
->sc_if
);
286 ath_sysctl_tpc(SYSCTLFN_ARGS
)
288 struct ath_softc
*sc
;
289 struct sysctlnode node
;
294 sc
= (struct ath_softc
*)node
.sysctl_data
;
295 tpc
= ath_hal_gettpc(sc
->sc_ah
);
296 node
.sysctl_data
= &tpc
;
297 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
298 if (error
|| newp
== NULL
)
300 return !ath_hal_settpc(sc
->sc_ah
, tpc
) ? EINVAL
: 0;
304 ath_sysctl_rfkill(SYSCTLFN_ARGS
)
306 struct ath_softc
*sc
;
307 struct sysctlnode node
;
312 sc
= (struct ath_softc
*)node
.sysctl_data
;
313 rfkill
= ath_hal_getrfkill(sc
->sc_ah
);
314 node
.sysctl_data
= &rfkill
;
315 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
316 if (error
|| newp
== NULL
)
318 return !ath_hal_setrfkill(sc
->sc_ah
, rfkill
) ? EINVAL
: 0;
322 ath_sysctl_rfsilent(SYSCTLFN_ARGS
)
324 struct ath_softc
*sc
;
325 struct sysctlnode node
;
330 sc
= (struct ath_softc
*)node
.sysctl_data
;
331 (void)ath_hal_getrfsilent(sc
->sc_ah
, &rfsilent
);
332 node
.sysctl_data
= &rfsilent
;
333 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
334 if (error
|| newp
== NULL
)
336 return !ath_hal_setrfsilent(sc
->sc_ah
, rfsilent
) ? EINVAL
: 0;
340 ath_sysctl_regdomain(SYSCTLFN_ARGS
)
342 struct ath_softc
*sc
;
343 struct sysctlnode node
;
348 sc
= (struct ath_softc
*)node
.sysctl_data
;
349 if (!ath_hal_getregdomain(sc
->sc_ah
, &rd
))
351 node
.sysctl_data
= &rd
;
352 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
353 if (error
|| newp
== NULL
)
355 return !ath_hal_setregdomain(sc
->sc_ah
, rd
) ? EINVAL
: 0;
359 ath_sysctl_tpack(SYSCTLFN_ARGS
)
361 struct ath_softc
*sc
;
362 struct sysctlnode node
;
367 sc
= (struct ath_softc
*)node
.sysctl_data
;
368 (void)ath_hal_gettpack(sc
->sc_ah
, &tpack
);
369 node
.sysctl_data
= &tpack
;
370 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
371 if (error
|| newp
== NULL
)
373 return !ath_hal_settpack(sc
->sc_ah
, tpack
) ? EINVAL
: 0;
377 ath_sysctl_tpcts(SYSCTLFN_ARGS
)
379 struct ath_softc
*sc
;
380 struct sysctlnode node
;
385 sc
= (struct ath_softc
*)node
.sysctl_data
;
386 (void)ath_hal_gettpcts(sc
->sc_ah
, &tpcts
);
387 node
.sysctl_data
= &tpcts
;
388 error
= sysctl_lookup(SYSCTLFN_CALL(&node
));
389 if (error
|| newp
== NULL
)
391 return !ath_hal_settpcts(sc
->sc_ah
, tpcts
) ? EINVAL
: 0;
394 const struct sysctlnode
*
395 ath_sysctl_instance(const char *dvname
, struct sysctllog
**log
)
398 const struct sysctlnode
*rnode
;
400 if ((rc
= sysctl_createv(log
, 0, NULL
, &rnode
,
401 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, "hw", NULL
,
402 NULL
, 0, NULL
, 0, CTL_HW
, CTL_EOL
)) != 0)
405 if ((rc
= sysctl_createv(log
, 0, &rnode
, &rnode
,
406 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, dvname
,
407 SYSCTL_DESCR("ath information and options"),
408 NULL
, 0, NULL
, 0, CTL_CREATE
, CTL_EOL
)) != 0)
413 printf("%s: sysctl_createv failed, rc = %d\n", __func__
, rc
);
417 const struct sysctlnode
*
418 ath_sysctl_treetop(struct sysctllog
**log
)
421 const struct sysctlnode
*rnode
;
423 if ((rc
= sysctl_createv(log
, 0, NULL
, &rnode
,
424 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, "hw", NULL
,
425 NULL
, 0, NULL
, 0, CTL_HW
, CTL_EOL
)) != 0)
428 if ((rc
= sysctl_createv(log
, 0, &rnode
, &rnode
,
429 CTLFLAG_PERMANENT
, CTLTYPE_NODE
, "ath",
430 SYSCTL_DESCR("ath information and options"),
431 NULL
, 0, NULL
, 0, CTL_CREATE
, CTL_EOL
)) != 0)
436 printf("%s: sysctl_createv failed, rc = %d\n", __func__
, rc
);
441 ath_sysctlattach(struct ath_softc
*sc
)
444 struct sysctllog
**log
= &sc
->sc_sysctllog
;
445 const struct sysctlnode
*cnode
, *rnode
;
447 ath_hal_getcountrycode(sc
->sc_ah
, &sc
->sc_countrycode
);
448 (void)ath_hal_getregdomain(sc
->sc_ah
, &sc
->sc_regdomain
);
449 sc
->sc_debug
= ath_debug
;
450 sc
->sc_txintrperiod
= ATH_TXINTR_PERIOD
;
452 if ((rnode
= ath_sysctl_instance(device_xname(sc
->sc_dev
), log
)) == NULL
)
455 if ((rc
= SYSCTL_INT(0, countrycode
, "EEPROM country code")) != 0)
458 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, debug
,
459 "control debugging printfs")) != 0)
463 /* channel dwell time (ms) for AP/station scanning */
464 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, dwell
,
465 "Channel dwell time (ms) for scanning")) != 0)
469 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, slottime
,
470 "802.11 slot time (us)")) != 0)
472 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, acktimeout
,
473 "802.11 ACK timeout (us)")) != 0)
475 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, ctstimeout
,
476 "802.11 CTS timeout (us)")) != 0)
478 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, softled
,
479 "enable/disable software LED support")) != 0)
481 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, ledpin
,
482 "GPIO pin connected to LED")) != 0)
484 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, ledon
,
485 "setting to turn LED on")) != 0)
487 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, ledidle
,
488 "idle time for inactivity LED (ticks)")) != 0)
490 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, txantenna
,
491 "tx antenna (0=auto)")) != 0)
493 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, rxantenna
,
494 "default/rx antenna")) != 0)
496 if (ath_hal_hasdiversity(sc
->sc_ah
)) {
497 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, diversity
,
498 "antenna diversity")) != 0)
501 if ((rc
= SYSCTL_INT(CTLFLAG_READWRITE
, txintrperiod
,
502 "tx descriptor batching")) != 0)
504 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, diag
,
505 "h/w diagnostic control")) != 0)
507 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, tpscale
,
508 "tx power scaling")) != 0)
510 if (ath_hal_hastpc(sc
->sc_ah
)) {
511 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, tpc
,
512 "enable/disable per-packet TPC")) != 0)
514 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, tpack
,
515 "tx power for ack frames")) != 0)
517 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, tpcts
,
518 "tx power for cts frames")) != 0)
521 if (ath_hal_hasrfsilent(sc
->sc_ah
)) {
522 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, rfsilent
,
523 "h/w RF silent config")) != 0)
525 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, rfkill
,
526 "enable/disable RF kill switch")) != 0)
529 if ((rc
= SYSCTL_INT_SUBR(CTLFLAG_READWRITE
, regdomain
,
530 "EEPROM regdomain code")) != 0)
534 printf("%s: sysctl_createv failed, rc = %d\n", __func__
, rc
);