xref: /freebsd/sys/dev/ath/if_ath_sysctl.c (revision 850e744187a6784353d7628d2d5a119dcb834f75)
1 /*-
2  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  */
29 
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 /*
34  * Driver for the Atheros Wireless LAN controller.
35  *
36  * This software is derived from work of Atsushi Onoe; his contribution
37  * is greatly appreciated.
38  */
39 
40 #include "opt_inet.h"
41 #include "opt_ath.h"
42 #include "opt_wlan.h"
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/sysctl.h>
47 #include <sys/mbuf.h>
48 #include <sys/malloc.h>
49 #include <sys/lock.h>
50 #include <sys/mutex.h>
51 #include <sys/kernel.h>
52 #include <sys/socket.h>
53 #include <sys/sockio.h>
54 #include <sys/errno.h>
55 #include <sys/callout.h>
56 #include <sys/bus.h>
57 #include <sys/endian.h>
58 #include <sys/kthread.h>
59 #include <sys/taskqueue.h>
60 #include <sys/priv.h>
61 
62 #include <machine/bus.h>
63 
64 #include <net/if.h>
65 #include <net/if_dl.h>
66 #include <net/if_media.h>
67 #include <net/if_types.h>
68 #include <net/if_arp.h>
69 #include <net/ethernet.h>
70 #include <net/if_llc.h>
71 
72 #include <net80211/ieee80211_var.h>
73 #include <net80211/ieee80211_regdomain.h>
74 #ifdef IEEE80211_SUPPORT_SUPERG
75 #include <net80211/ieee80211_superg.h>
76 #endif
77 #ifdef IEEE80211_SUPPORT_TDMA
78 #include <net80211/ieee80211_tdma.h>
79 #endif
80 
81 #include <net/bpf.h>
82 
83 #ifdef INET
84 #include <netinet/in.h>
85 #include <netinet/if_ether.h>
86 #endif
87 
88 #include <dev/ath/if_athvar.h>
89 #include <dev/ath/ath_hal/ah_devid.h>		/* XXX for softled */
90 #include <dev/ath/ath_hal/ah_diagcodes.h>
91 
92 #include <dev/ath/if_ath_debug.h>
93 #include <dev/ath/if_ath_led.h>
94 #include <dev/ath/if_ath_misc.h>
95 #include <dev/ath/if_ath_tx.h>
96 #include <dev/ath/if_ath_sysctl.h>
97 
98 #ifdef ATH_TX99_DIAG
99 #include <dev/ath/ath_tx99/ath_tx99.h>
100 #endif
101 
102 #ifdef	ATH_DEBUG_ALQ
103 #include <dev/ath/if_ath_alq.h>
104 #endif
105 
106 static int
107 ath_sysctl_slottime(SYSCTL_HANDLER_ARGS)
108 {
109 	struct ath_softc *sc = arg1;
110 	u_int slottime = ath_hal_getslottime(sc->sc_ah);
111 	int error;
112 
113 	error = sysctl_handle_int(oidp, &slottime, 0, req);
114 	if (error || !req->newptr)
115 		return error;
116 	return !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0;
117 }
118 
119 static int
120 ath_sysctl_acktimeout(SYSCTL_HANDLER_ARGS)
121 {
122 	struct ath_softc *sc = arg1;
123 	u_int acktimeout = ath_hal_getacktimeout(sc->sc_ah);
124 	int error;
125 
126 	error = sysctl_handle_int(oidp, &acktimeout, 0, req);
127 	if (error || !req->newptr)
128 		return error;
129 	return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
130 }
131 
132 static int
133 ath_sysctl_ctstimeout(SYSCTL_HANDLER_ARGS)
134 {
135 	struct ath_softc *sc = arg1;
136 	u_int ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
137 	int error;
138 
139 	error = sysctl_handle_int(oidp, &ctstimeout, 0, req);
140 	if (error || !req->newptr)
141 		return error;
142 	return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
143 }
144 
145 static int
146 ath_sysctl_softled(SYSCTL_HANDLER_ARGS)
147 {
148 	struct ath_softc *sc = arg1;
149 	int softled = sc->sc_softled;
150 	int error;
151 
152 	error = sysctl_handle_int(oidp, &softled, 0, req);
153 	if (error || !req->newptr)
154 		return error;
155 	softled = (softled != 0);
156 	if (softled != sc->sc_softled) {
157 		if (softled) {
158 			/* NB: handle any sc_ledpin change */
159 			ath_led_config(sc);
160 		}
161 		sc->sc_softled = softled;
162 	}
163 	return 0;
164 }
165 
166 static int
167 ath_sysctl_ledpin(SYSCTL_HANDLER_ARGS)
168 {
169 	struct ath_softc *sc = arg1;
170 	int ledpin = sc->sc_ledpin;
171 	int error;
172 
173 	error = sysctl_handle_int(oidp, &ledpin, 0, req);
174 	if (error || !req->newptr)
175 		return error;
176 	if (ledpin != sc->sc_ledpin) {
177 		sc->sc_ledpin = ledpin;
178 		if (sc->sc_softled) {
179 			ath_led_config(sc);
180 		}
181 	}
182 	return 0;
183 }
184 
185 static int
186 ath_sysctl_hardled(SYSCTL_HANDLER_ARGS)
187 {
188 	struct ath_softc *sc = arg1;
189 	int hardled = sc->sc_hardled;
190 	int error;
191 
192 	error = sysctl_handle_int(oidp, &hardled, 0, req);
193 	if (error || !req->newptr)
194 		return error;
195 	hardled = (hardled != 0);
196 	if (hardled != sc->sc_hardled) {
197 		if (hardled) {
198 			/* NB: handle any sc_ledpin change */
199 			ath_led_config(sc);
200 		}
201 		sc->sc_hardled = hardled;
202 	}
203 	return 0;
204 }
205 
206 static int
207 ath_sysctl_txantenna(SYSCTL_HANDLER_ARGS)
208 {
209 	struct ath_softc *sc = arg1;
210 	u_int txantenna = ath_hal_getantennaswitch(sc->sc_ah);
211 	int error;
212 
213 	error = sysctl_handle_int(oidp, &txantenna, 0, req);
214 	if (!error && req->newptr) {
215 		/* XXX assumes 2 antenna ports */
216 		if (txantenna < HAL_ANT_VARIABLE || txantenna > HAL_ANT_FIXED_B)
217 			return EINVAL;
218 		ath_hal_setantennaswitch(sc->sc_ah, txantenna);
219 		/*
220 		 * NB: with the switch locked this isn't meaningful,
221 		 *     but set it anyway so things like radiotap get
222 		 *     consistent info in their data.
223 		 */
224 		sc->sc_txantenna = txantenna;
225 	}
226 	return error;
227 }
228 
229 static int
230 ath_sysctl_rxantenna(SYSCTL_HANDLER_ARGS)
231 {
232 	struct ath_softc *sc = arg1;
233 	u_int defantenna = ath_hal_getdefantenna(sc->sc_ah);
234 	int error;
235 
236 	error = sysctl_handle_int(oidp, &defantenna, 0, req);
237 	if (!error && req->newptr)
238 		ath_hal_setdefantenna(sc->sc_ah, defantenna);
239 	return error;
240 }
241 
242 static int
243 ath_sysctl_diversity(SYSCTL_HANDLER_ARGS)
244 {
245 	struct ath_softc *sc = arg1;
246 	u_int diversity = ath_hal_getdiversity(sc->sc_ah);
247 	int error;
248 
249 	error = sysctl_handle_int(oidp, &diversity, 0, req);
250 	if (error || !req->newptr)
251 		return error;
252 	if (!ath_hal_setdiversity(sc->sc_ah, diversity))
253 		return EINVAL;
254 	sc->sc_diversity = diversity;
255 	return 0;
256 }
257 
258 static int
259 ath_sysctl_diag(SYSCTL_HANDLER_ARGS)
260 {
261 	struct ath_softc *sc = arg1;
262 	u_int32_t diag;
263 	int error;
264 
265 	if (!ath_hal_getdiag(sc->sc_ah, &diag))
266 		return EINVAL;
267 	error = sysctl_handle_int(oidp, &diag, 0, req);
268 	if (error || !req->newptr)
269 		return error;
270 	return !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
271 }
272 
273 static int
274 ath_sysctl_tpscale(SYSCTL_HANDLER_ARGS)
275 {
276 	struct ath_softc *sc = arg1;
277 	struct ifnet *ifp = sc->sc_ifp;
278 	u_int32_t scale;
279 	int error;
280 
281 	(void) ath_hal_gettpscale(sc->sc_ah, &scale);
282 	error = sysctl_handle_int(oidp, &scale, 0, req);
283 	if (error || !req->newptr)
284 		return error;
285 	return !ath_hal_settpscale(sc->sc_ah, scale) ? EINVAL :
286 	    (ifp->if_drv_flags & IFF_DRV_RUNNING) ?
287 	      ath_reset(ifp, ATH_RESET_NOLOSS) : 0;
288 }
289 
290 static int
291 ath_sysctl_tpc(SYSCTL_HANDLER_ARGS)
292 {
293 	struct ath_softc *sc = arg1;
294 	u_int tpc = ath_hal_gettpc(sc->sc_ah);
295 	int error;
296 
297 	error = sysctl_handle_int(oidp, &tpc, 0, req);
298 	if (error || !req->newptr)
299 		return error;
300 	return !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
301 }
302 
303 static int
304 ath_sysctl_rfkill(SYSCTL_HANDLER_ARGS)
305 {
306 	struct ath_softc *sc = arg1;
307 	struct ifnet *ifp = sc->sc_ifp;
308 	struct ath_hal *ah = sc->sc_ah;
309 	u_int rfkill = ath_hal_getrfkill(ah);
310 	int error;
311 
312 	error = sysctl_handle_int(oidp, &rfkill, 0, req);
313 	if (error || !req->newptr)
314 		return error;
315 	if (rfkill == ath_hal_getrfkill(ah))	/* unchanged */
316 		return 0;
317 	if (!ath_hal_setrfkill(ah, rfkill))
318 		return EINVAL;
319 	return (ifp->if_drv_flags & IFF_DRV_RUNNING) ?
320 	    ath_reset(ifp, ATH_RESET_FULL) : 0;
321 }
322 
323 static int
324 ath_sysctl_txagg(SYSCTL_HANDLER_ARGS)
325 {
326 	struct ath_softc *sc = arg1;
327 	int i, t, param = 0;
328 	int error;
329 	struct ath_buf *bf;
330 
331 	error = sysctl_handle_int(oidp, &param, 0, req);
332 	if (error || !req->newptr)
333 		return error;
334 
335 	if (param != 1)
336 		return 0;
337 
338 	printf("no tx bufs (empty list): %d\n", sc->sc_stats.ast_tx_getnobuf);
339 	printf("no tx bufs (was busy): %d\n", sc->sc_stats.ast_tx_getbusybuf);
340 
341 	printf("aggr single packet: %d\n",
342 	    sc->sc_aggr_stats.aggr_single_pkt);
343 	printf("aggr single packet w/ BAW closed: %d\n",
344 	    sc->sc_aggr_stats.aggr_baw_closed_single_pkt);
345 	printf("aggr non-baw packet: %d\n",
346 	    sc->sc_aggr_stats.aggr_nonbaw_pkt);
347 	printf("aggr aggregate packet: %d\n",
348 	    sc->sc_aggr_stats.aggr_aggr_pkt);
349 	printf("aggr single packet low hwq: %d\n",
350 	    sc->sc_aggr_stats.aggr_low_hwq_single_pkt);
351 	printf("aggr single packet RTS aggr limited: %d\n",
352 	    sc->sc_aggr_stats.aggr_rts_aggr_limited);
353 	printf("aggr sched, no work: %d\n",
354 	    sc->sc_aggr_stats.aggr_sched_nopkt);
355 	for (i = 0; i < 64; i++) {
356 		printf("%2d: %10d ", i, sc->sc_aggr_stats.aggr_pkts[i]);
357 		if (i % 4 == 3)
358 			printf("\n");
359 	}
360 	printf("\n");
361 
362 	for (i = 0; i < HAL_NUM_TX_QUEUES; i++) {
363 		if (ATH_TXQ_SETUP(sc, i)) {
364 			printf("HW TXQ %d: axq_depth=%d, axq_aggr_depth=%d, axq_fifo_depth=%d\n",
365 			    i,
366 			    sc->sc_txq[i].axq_depth,
367 			    sc->sc_txq[i].axq_aggr_depth,
368 			    sc->sc_txq[i].axq_fifo_depth);
369 		}
370 	}
371 
372 	i = t = 0;
373 	ATH_TXBUF_LOCK(sc);
374 	TAILQ_FOREACH(bf, &sc->sc_txbuf, bf_list) {
375 		if (bf->bf_flags & ATH_BUF_BUSY) {
376 			printf("Busy: %d\n", t);
377 			i++;
378 		}
379 		t++;
380 	}
381 	ATH_TXBUF_UNLOCK(sc);
382 	printf("Total TX buffers: %d; Total TX buffers busy: %d (%d)\n",
383 	    t, i, sc->sc_txbuf_cnt);
384 
385 	i = t = 0;
386 	ATH_TXBUF_LOCK(sc);
387 	TAILQ_FOREACH(bf, &sc->sc_txbuf_mgmt, bf_list) {
388 		if (bf->bf_flags & ATH_BUF_BUSY) {
389 			printf("Busy: %d\n", t);
390 			i++;
391 		}
392 		t++;
393 	}
394 	ATH_TXBUF_UNLOCK(sc);
395 	printf("Total mgmt TX buffers: %d; Total mgmt TX buffers busy: %d\n",
396 	    t, i);
397 
398 	return 0;
399 }
400 
401 static int
402 ath_sysctl_rfsilent(SYSCTL_HANDLER_ARGS)
403 {
404 	struct ath_softc *sc = arg1;
405 	u_int rfsilent;
406 	int error;
407 
408 	(void) ath_hal_getrfsilent(sc->sc_ah, &rfsilent);
409 	error = sysctl_handle_int(oidp, &rfsilent, 0, req);
410 	if (error || !req->newptr)
411 		return error;
412 	if (!ath_hal_setrfsilent(sc->sc_ah, rfsilent))
413 		return EINVAL;
414 	sc->sc_rfsilentpin = rfsilent & 0x1c;
415 	sc->sc_rfsilentpol = (rfsilent & 0x2) != 0;
416 	return 0;
417 }
418 
419 static int
420 ath_sysctl_tpack(SYSCTL_HANDLER_ARGS)
421 {
422 	struct ath_softc *sc = arg1;
423 	u_int32_t tpack;
424 	int error;
425 
426 	(void) ath_hal_gettpack(sc->sc_ah, &tpack);
427 	error = sysctl_handle_int(oidp, &tpack, 0, req);
428 	if (error || !req->newptr)
429 		return error;
430 	return !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
431 }
432 
433 static int
434 ath_sysctl_tpcts(SYSCTL_HANDLER_ARGS)
435 {
436 	struct ath_softc *sc = arg1;
437 	u_int32_t tpcts;
438 	int error;
439 
440 	(void) ath_hal_gettpcts(sc->sc_ah, &tpcts);
441 	error = sysctl_handle_int(oidp, &tpcts, 0, req);
442 	if (error || !req->newptr)
443 		return error;
444 	return !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
445 }
446 
447 static int
448 ath_sysctl_intmit(SYSCTL_HANDLER_ARGS)
449 {
450 	struct ath_softc *sc = arg1;
451 	int intmit, error;
452 
453 	intmit = ath_hal_getintmit(sc->sc_ah);
454 	error = sysctl_handle_int(oidp, &intmit, 0, req);
455 	if (error || !req->newptr)
456 		return error;
457 
458 	/* reusing error; 1 here means "good"; 0 means "fail" */
459 	error = ath_hal_setintmit(sc->sc_ah, intmit);
460 	if (! error)
461 		return EINVAL;
462 
463 	/*
464 	 * Reset the hardware here - disabling ANI in the HAL
465 	 * doesn't reset ANI related registers, so it'll leave
466 	 * things in an inconsistent state.
467 	 */
468 	if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
469 		ath_reset(sc->sc_ifp, ATH_RESET_NOLOSS);
470 
471 	return 0;
472 }
473 
474 #ifdef IEEE80211_SUPPORT_TDMA
475 static int
476 ath_sysctl_setcca(SYSCTL_HANDLER_ARGS)
477 {
478 	struct ath_softc *sc = arg1;
479 	int setcca, error;
480 
481 	setcca = sc->sc_setcca;
482 	error = sysctl_handle_int(oidp, &setcca, 0, req);
483 	if (error || !req->newptr)
484 		return error;
485 	sc->sc_setcca = (setcca != 0);
486 	return 0;
487 }
488 #endif /* IEEE80211_SUPPORT_TDMA */
489 
490 static int
491 ath_sysctl_forcebstuck(SYSCTL_HANDLER_ARGS)
492 {
493 	struct ath_softc *sc = arg1;
494 	int val = 0;
495 	int error;
496 
497 	error = sysctl_handle_int(oidp, &val, 0, req);
498 	if (error || !req->newptr)
499 		return error;
500 	if (val == 0)
501 		return 0;
502 
503 	taskqueue_enqueue_fast(sc->sc_tq, &sc->sc_bstucktask);
504 	val = 0;
505 	return 0;
506 }
507 
508 static int
509 ath_sysctl_hangcheck(SYSCTL_HANDLER_ARGS)
510 {
511 	struct ath_softc *sc = arg1;
512 	int val = 0;
513 	int error;
514 	uint32_t mask = 0xffffffff;
515 	uint32_t *sp;
516 	uint32_t rsize;
517 	struct ath_hal *ah = sc->sc_ah;
518 
519 	error = sysctl_handle_int(oidp, &val, 0, req);
520 	if (error || !req->newptr)
521 		return error;
522 	if (val == 0)
523 		return 0;
524 
525 	/* Do a hang check */
526 	if (!ath_hal_getdiagstate(ah, HAL_DIAG_CHECK_HANGS,
527 	    &mask, sizeof(mask),
528 	    (void *) &sp, &rsize))
529 		return (0);
530 	device_printf(sc->sc_dev, "%s: sp=0x%08x\n", __func__, *sp);
531 
532 	val = 0;
533 	return 0;
534 }
535 
536 #ifdef ATH_DEBUG_ALQ
537 static int
538 ath_sysctl_alq_log(SYSCTL_HANDLER_ARGS)
539 {
540 	struct ath_softc *sc = arg1;
541 	int error, enable;
542 
543 	enable = (sc->sc_alq.sc_alq_isactive);
544 
545 	error = sysctl_handle_int(oidp, &enable, 0, req);
546 	if (error || !req->newptr)
547 		return (error);
548 	else if (enable)
549 		error = if_ath_alq_start(&sc->sc_alq);
550 	else
551 		error = if_ath_alq_stop(&sc->sc_alq);
552 	return (error);
553 }
554 
555 /*
556  * Attach the ALQ debugging if required.
557  */
558 static void
559 ath_sysctl_alq_attach(struct ath_softc *sc)
560 {
561 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
562 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
563 	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
564 
565 	tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "alq", CTLFLAG_RD,
566 	    NULL, "Atheros ALQ logging parameters");
567 	child = SYSCTL_CHILDREN(tree);
568 
569 	SYSCTL_ADD_STRING(ctx, child, OID_AUTO, "filename",
570 	    CTLFLAG_RW, sc->sc_alq.sc_alq_filename, 0, "ALQ filename");
571 
572 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
573 		"enable", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
574 		ath_sysctl_alq_log, "I", "");
575 
576 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
577 		"debugmask", CTLFLAG_RW, &sc->sc_alq.sc_alq_debug, 0,
578 		"ALQ debug mask");
579 
580 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
581 		"numlost", CTLFLAG_RW, &sc->sc_alq.sc_alq_numlost, 0,
582 		"number lost");
583 }
584 #endif /* ATH_DEBUG_ALQ */
585 
586 void
587 ath_sysctlattach(struct ath_softc *sc)
588 {
589 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
590 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
591 	struct ath_hal *ah = sc->sc_ah;
592 
593 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
594 		"countrycode", CTLFLAG_RD, &sc->sc_eecc, 0,
595 		"EEPROM country code");
596 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
597 		"regdomain", CTLFLAG_RD, &sc->sc_eerd, 0,
598 		"EEPROM regdomain code");
599 #ifdef	ATH_DEBUG
600 	SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
601 		"debug", CTLFLAG_RW, &sc->sc_debug,
602 		"control debugging printfs");
603 #endif
604 #ifdef	ATH_DEBUG_ALQ
605 	SYSCTL_ADD_QUAD(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
606 		"ktrdebug", CTLFLAG_RW, &sc->sc_ktrdebug,
607 		"control debugging KTR");
608 #endif /* ATH_DEBUG_ALQ */
609 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
610 		"slottime", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
611 		ath_sysctl_slottime, "I", "802.11 slot time (us)");
612 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
613 		"acktimeout", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
614 		ath_sysctl_acktimeout, "I", "802.11 ACK timeout (us)");
615 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
616 		"ctstimeout", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
617 		ath_sysctl_ctstimeout, "I", "802.11 CTS timeout (us)");
618 
619 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
620 		"softled", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
621 		ath_sysctl_softled, "I", "enable/disable software LED support");
622 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
623 		"ledpin", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
624 		ath_sysctl_ledpin, "I", "GPIO pin connected to LED");
625 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
626 		"ledon", CTLFLAG_RW, &sc->sc_ledon, 0,
627 		"setting to turn LED on");
628 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
629 		"ledidle", CTLFLAG_RW, &sc->sc_ledidle, 0,
630 		"idle time for inactivity LED (ticks)");
631 
632 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
633 		"hardled", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
634 		ath_sysctl_hardled, "I", "enable/disable hardware LED support");
635 	/* XXX Laziness - configure pins, then flip hardled off/on */
636 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
637 		"led_net_pin", CTLFLAG_RW, &sc->sc_led_net_pin, 0,
638 		"MAC Network LED pin, or -1 to disable");
639 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
640 		"led_pwr_pin", CTLFLAG_RW, &sc->sc_led_pwr_pin, 0,
641 		"MAC Power LED pin, or -1 to disable");
642 
643 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
644 		"txantenna", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
645 		ath_sysctl_txantenna, "I", "antenna switch");
646 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
647 		"rxantenna", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
648 		ath_sysctl_rxantenna, "I", "default/rx antenna");
649 	if (ath_hal_hasdiversity(ah))
650 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
651 			"diversity", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
652 			ath_sysctl_diversity, "I", "antenna diversity");
653 	sc->sc_txintrperiod = ATH_TXINTR_PERIOD;
654 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
655 		"txintrperiod", CTLFLAG_RW, &sc->sc_txintrperiod, 0,
656 		"tx descriptor batching");
657 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
658 		"diag", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
659 		ath_sysctl_diag, "I", "h/w diagnostic control");
660 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
661 		"tpscale", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
662 		ath_sysctl_tpscale, "I", "tx power scaling");
663 	if (ath_hal_hastpc(ah)) {
664 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
665 			"tpc", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
666 			ath_sysctl_tpc, "I", "enable/disable per-packet TPC");
667 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
668 			"tpack", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
669 			ath_sysctl_tpack, "I", "tx power for ack frames");
670 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
671 			"tpcts", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
672 			ath_sysctl_tpcts, "I", "tx power for cts frames");
673 	}
674 	if (ath_hal_hasrfsilent(ah)) {
675 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
676 			"rfsilent", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
677 			ath_sysctl_rfsilent, "I", "h/w RF silent config");
678 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
679 			"rfkill", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
680 			ath_sysctl_rfkill, "I", "enable/disable RF kill switch");
681 	}
682 
683 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
684 		"txagg", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
685 		ath_sysctl_txagg, "I", "");
686 
687 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
688 		"forcebstuck", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
689 		ath_sysctl_forcebstuck, "I", "");
690 
691 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
692 		"hangcheck", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
693 		ath_sysctl_hangcheck, "I", "");
694 
695 	if (ath_hal_hasintmit(ah)) {
696 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
697 			"intmit", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
698 			ath_sysctl_intmit, "I", "interference mitigation");
699 	}
700 	sc->sc_monpass = HAL_RXERR_DECRYPT | HAL_RXERR_MIC;
701 	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
702 		"monpass", CTLFLAG_RW, &sc->sc_monpass, 0,
703 		"mask of error frames to pass when monitoring");
704 
705 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
706 		"hwq_limit", CTLFLAG_RW, &sc->sc_hwq_limit, 0,
707 		"");
708 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
709 		"tid_hwq_lo", CTLFLAG_RW, &sc->sc_tid_hwq_lo, 0,
710 		"");
711 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
712 		"tid_hwq_hi", CTLFLAG_RW, &sc->sc_tid_hwq_hi, 0,
713 		"");
714 
715 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
716 		"txq_data_minfree", CTLFLAG_RW, &sc->sc_txq_data_minfree,
717 		0, "Minimum free buffers before adding a data frame"
718 		" to the TX queue");
719 
720 	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
721 		"txq_mcastq_maxdepth", CTLFLAG_RW,
722 		&sc->sc_txq_mcastq_maxdepth, 0,
723 		"Maximum buffer depth for multicast/broadcast frames");
724 
725 #ifdef IEEE80211_SUPPORT_TDMA
726 	if (ath_hal_macversion(ah) > 0x78) {
727 		sc->sc_tdmadbaprep = 2;
728 		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
729 			"dbaprep", CTLFLAG_RW, &sc->sc_tdmadbaprep, 0,
730 			"TDMA DBA preparation time");
731 		sc->sc_tdmaswbaprep = 10;
732 		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
733 			"swbaprep", CTLFLAG_RW, &sc->sc_tdmaswbaprep, 0,
734 			"TDMA SWBA preparation time");
735 		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
736 			"guardtime", CTLFLAG_RW, &sc->sc_tdmaguard, 0,
737 			"TDMA slot guard time");
738 		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
739 			"superframe", CTLFLAG_RD, &sc->sc_tdmabintval, 0,
740 			"TDMA calculated super frame");
741 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
742 			"setcca", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
743 			ath_sysctl_setcca, "I", "enable CCA control");
744 	}
745 #endif
746 
747 #ifdef	ATH_DEBUG_ALQ
748 	ath_sysctl_alq_attach(sc);
749 #endif
750 }
751 
752 static int
753 ath_sysctl_clearstats(SYSCTL_HANDLER_ARGS)
754 {
755 	struct ath_softc *sc = arg1;
756 	int val = 0;
757 	int error;
758 
759 	error = sysctl_handle_int(oidp, &val, 0, req);
760 	if (error || !req->newptr)
761 		return error;
762 	if (val == 0)
763 		return 0;       /* Not clearing the stats is still valid */
764 	memset(&sc->sc_stats, 0, sizeof(sc->sc_stats));
765 	memset(&sc->sc_aggr_stats, 0, sizeof(sc->sc_aggr_stats));
766 	memset(&sc->sc_intr_stats, 0, sizeof(sc->sc_intr_stats));
767 
768 	val = 0;
769 	return 0;
770 }
771 
772 static void
773 ath_sysctl_stats_attach_rxphyerr(struct ath_softc *sc, struct sysctl_oid_list *parent)
774 {
775 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
776 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
777 	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
778 	int i;
779 	char sn[8];
780 
781 	tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx_phy_err", CTLFLAG_RD, NULL, "Per-code RX PHY Errors");
782 	child = SYSCTL_CHILDREN(tree);
783 	for (i = 0; i < 64; i++) {
784 		snprintf(sn, sizeof(sn), "%d", i);
785 		SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD, &sc->sc_stats.ast_rx_phy[i], 0, "");
786 	}
787 }
788 
789 static void
790 ath_sysctl_stats_attach_intr(struct ath_softc *sc,
791     struct sysctl_oid_list *parent)
792 {
793 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
794 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
795 	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
796 	int i;
797 	char sn[8];
798 
799 	tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "sync_intr",
800 	    CTLFLAG_RD, NULL, "Sync interrupt statistics");
801 	child = SYSCTL_CHILDREN(tree);
802 	for (i = 0; i < 32; i++) {
803 		snprintf(sn, sizeof(sn), "%d", i);
804 		SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD,
805 		    &sc->sc_intr_stats.sync_intr[i], 0, "");
806 	}
807 }
808 
809 void
810 ath_sysctl_stats_attach(struct ath_softc *sc)
811 {
812 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
813 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
814 	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
815 
816 	/* Create "clear" node */
817 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
818 	    "clear_stats", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
819 	    ath_sysctl_clearstats, "I", "clear stats");
820 
821 	/* Create stats node */
822 	tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "stats", CTLFLAG_RD,
823 	    NULL, "Statistics");
824 	child = SYSCTL_CHILDREN(tree);
825 
826 	/* This was generated from if_athioctl.h */
827 
828 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_watchdog", CTLFLAG_RD,
829 	    &sc->sc_stats.ast_watchdog, 0, "device reset by watchdog");
830 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_hardware", CTLFLAG_RD,
831 	    &sc->sc_stats.ast_hardware, 0, "fatal hardware error interrupts");
832 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_bmiss", CTLFLAG_RD,
833 	    &sc->sc_stats.ast_bmiss, 0, "beacon miss interrupts");
834 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_bmiss_phantom", CTLFLAG_RD,
835 	    &sc->sc_stats.ast_bmiss_phantom, 0, "beacon miss interrupts");
836 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_bstuck", CTLFLAG_RD,
837 	    &sc->sc_stats.ast_bstuck, 0, "beacon stuck interrupts");
838 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rxorn", CTLFLAG_RD,
839 	    &sc->sc_stats.ast_rxorn, 0, "rx overrun interrupts");
840 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rxeol", CTLFLAG_RD,
841 	    &sc->sc_stats.ast_rxeol, 0, "rx eol interrupts");
842 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_txurn", CTLFLAG_RD,
843 	    &sc->sc_stats.ast_txurn, 0, "tx underrun interrupts");
844 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_mib", CTLFLAG_RD,
845 	    &sc->sc_stats.ast_mib, 0, "mib interrupts");
846 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_intrcoal", CTLFLAG_RD,
847 	    &sc->sc_stats.ast_intrcoal, 0, "interrupts coalesced");
848 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_packets", CTLFLAG_RD,
849 	    &sc->sc_stats.ast_tx_packets, 0, "packet sent on the interface");
850 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_mgmt", CTLFLAG_RD,
851 	    &sc->sc_stats.ast_tx_mgmt, 0, "management frames transmitted");
852 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_discard", CTLFLAG_RD,
853 	    &sc->sc_stats.ast_tx_discard, 0, "frames discarded prior to assoc");
854 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_qstop", CTLFLAG_RD,
855 	    &sc->sc_stats.ast_tx_qstop, 0, "output stopped 'cuz no buffer");
856 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_encap", CTLFLAG_RD,
857 	    &sc->sc_stats.ast_tx_encap, 0, "tx encapsulation failed");
858 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nonode", CTLFLAG_RD,
859 	    &sc->sc_stats.ast_tx_nonode, 0, "tx failed 'cuz no node");
860 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nombuf", CTLFLAG_RD,
861 	    &sc->sc_stats.ast_tx_nombuf, 0, "tx failed 'cuz no mbuf");
862 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nomcl", CTLFLAG_RD,
863 	    &sc->sc_stats.ast_tx_nomcl, 0, "tx failed 'cuz no cluster");
864 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_linear", CTLFLAG_RD,
865 	    &sc->sc_stats.ast_tx_linear, 0, "tx linearized to cluster");
866 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nodata", CTLFLAG_RD,
867 	    &sc->sc_stats.ast_tx_nodata, 0, "tx discarded empty frame");
868 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_busdma", CTLFLAG_RD,
869 	    &sc->sc_stats.ast_tx_busdma, 0, "tx failed for dma resrcs");
870 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_xretries", CTLFLAG_RD,
871 	    &sc->sc_stats.ast_tx_xretries, 0, "tx failed 'cuz too many retries");
872 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_fifoerr", CTLFLAG_RD,
873 	    &sc->sc_stats.ast_tx_fifoerr, 0, "tx failed 'cuz FIFO underrun");
874 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_filtered", CTLFLAG_RD,
875 	    &sc->sc_stats.ast_tx_filtered, 0, "tx failed 'cuz xmit filtered");
876 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_shortretry", CTLFLAG_RD,
877 	    &sc->sc_stats.ast_tx_shortretry, 0, "tx on-chip retries (short)");
878 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_longretry", CTLFLAG_RD,
879 	    &sc->sc_stats.ast_tx_longretry, 0, "tx on-chip retries (long)");
880 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_badrate", CTLFLAG_RD,
881 	    &sc->sc_stats.ast_tx_badrate, 0, "tx failed 'cuz bogus xmit rate");
882 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_noack", CTLFLAG_RD,
883 	    &sc->sc_stats.ast_tx_noack, 0, "tx frames with no ack marked");
884 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_rts", CTLFLAG_RD,
885 	    &sc->sc_stats.ast_tx_rts, 0, "tx frames with rts enabled");
886 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_cts", CTLFLAG_RD,
887 	    &sc->sc_stats.ast_tx_cts, 0, "tx frames with cts enabled");
888 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_shortpre", CTLFLAG_RD,
889 	    &sc->sc_stats.ast_tx_shortpre, 0, "tx frames with short preamble");
890 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_altrate", CTLFLAG_RD,
891 	    &sc->sc_stats.ast_tx_altrate, 0, "tx frames with alternate rate");
892 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_protect", CTLFLAG_RD,
893 	    &sc->sc_stats.ast_tx_protect, 0, "tx frames with protection");
894 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_ctsburst", CTLFLAG_RD,
895 	    &sc->sc_stats.ast_tx_ctsburst, 0, "tx frames with cts and bursting");
896 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_ctsext", CTLFLAG_RD,
897 	    &sc->sc_stats.ast_tx_ctsext, 0, "tx frames with cts extension");
898 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_nombuf", CTLFLAG_RD,
899 	    &sc->sc_stats.ast_rx_nombuf, 0, "rx setup failed 'cuz no mbuf");
900 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_busdma", CTLFLAG_RD,
901 	    &sc->sc_stats.ast_rx_busdma, 0, "rx setup failed for dma resrcs");
902 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_orn", CTLFLAG_RD,
903 	    &sc->sc_stats.ast_rx_orn, 0, "rx failed 'cuz of desc overrun");
904 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_crcerr", CTLFLAG_RD,
905 	    &sc->sc_stats.ast_rx_crcerr, 0, "rx failed 'cuz of bad CRC");
906 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_fifoerr", CTLFLAG_RD,
907 	    &sc->sc_stats.ast_rx_fifoerr, 0, "rx failed 'cuz of FIFO overrun");
908 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_badcrypt", CTLFLAG_RD,
909 	    &sc->sc_stats.ast_rx_badcrypt, 0, "rx failed 'cuz decryption");
910 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_badmic", CTLFLAG_RD,
911 	    &sc->sc_stats.ast_rx_badmic, 0, "rx failed 'cuz MIC failure");
912 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_phyerr", CTLFLAG_RD,
913 	    &sc->sc_stats.ast_rx_phyerr, 0, "rx failed 'cuz of PHY err");
914 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_tooshort", CTLFLAG_RD,
915 	    &sc->sc_stats.ast_rx_tooshort, 0, "rx discarded 'cuz frame too short");
916 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_toobig", CTLFLAG_RD,
917 	    &sc->sc_stats.ast_rx_toobig, 0, "rx discarded 'cuz frame too large");
918 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_packets", CTLFLAG_RD,
919 	    &sc->sc_stats.ast_rx_packets, 0, "packet recv on the interface");
920 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_mgt", CTLFLAG_RD,
921 	    &sc->sc_stats.ast_rx_mgt, 0, "management frames received");
922 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_ctl", CTLFLAG_RD,
923 	    &sc->sc_stats.ast_rx_ctl, 0, "rx discarded 'cuz ctl frame");
924 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_be_xmit", CTLFLAG_RD,
925 	    &sc->sc_stats.ast_be_xmit, 0, "beacons transmitted");
926 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_be_nombuf", CTLFLAG_RD,
927 	    &sc->sc_stats.ast_be_nombuf, 0, "beacon setup failed 'cuz no mbuf");
928 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_per_cal", CTLFLAG_RD,
929 	    &sc->sc_stats.ast_per_cal, 0, "periodic calibration calls");
930 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_per_calfail", CTLFLAG_RD,
931 	    &sc->sc_stats.ast_per_calfail, 0, "periodic calibration failed");
932 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_per_rfgain", CTLFLAG_RD,
933 	    &sc->sc_stats.ast_per_rfgain, 0, "periodic calibration rfgain reset");
934 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rate_calls", CTLFLAG_RD,
935 	    &sc->sc_stats.ast_rate_calls, 0, "rate control checks");
936 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rate_raise", CTLFLAG_RD,
937 	    &sc->sc_stats.ast_rate_raise, 0, "rate control raised xmit rate");
938 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rate_drop", CTLFLAG_RD,
939 	    &sc->sc_stats.ast_rate_drop, 0, "rate control dropped xmit rate");
940 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ant_defswitch", CTLFLAG_RD,
941 	    &sc->sc_stats.ast_ant_defswitch, 0, "rx/default antenna switches");
942 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ant_txswitch", CTLFLAG_RD,
943 	    &sc->sc_stats.ast_ant_txswitch, 0, "tx antenna switches");
944 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_cabq_xmit", CTLFLAG_RD,
945 	    &sc->sc_stats.ast_cabq_xmit, 0, "cabq frames transmitted");
946 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_cabq_busy", CTLFLAG_RD,
947 	    &sc->sc_stats.ast_cabq_busy, 0, "cabq found busy");
948 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_raw", CTLFLAG_RD,
949 	    &sc->sc_stats.ast_tx_raw, 0, "tx frames through raw api");
950 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_txok", CTLFLAG_RD,
951 	    &sc->sc_stats.ast_ff_txok, 0, "fast frames tx'd successfully");
952 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_txerr", CTLFLAG_RD,
953 	    &sc->sc_stats.ast_ff_txerr, 0, "fast frames tx'd w/ error");
954 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_rx", CTLFLAG_RD,
955 	    &sc->sc_stats.ast_ff_rx, 0, "fast frames rx'd");
956 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_flush", CTLFLAG_RD,
957 	    &sc->sc_stats.ast_ff_flush, 0, "fast frames flushed from staging q");
958 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_qfull", CTLFLAG_RD,
959 	    &sc->sc_stats.ast_tx_qfull, 0, "tx dropped 'cuz of queue limit");
960 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nobuf", CTLFLAG_RD,
961 	    &sc->sc_stats.ast_tx_nobuf, 0, "tx dropped 'cuz no ath buffer");
962 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_update", CTLFLAG_RD,
963 	    &sc->sc_stats.ast_tdma_update, 0, "TDMA slot timing updates");
964 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_timers", CTLFLAG_RD,
965 	    &sc->sc_stats.ast_tdma_timers, 0, "TDMA slot update set beacon timers");
966 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_tsf", CTLFLAG_RD,
967 	    &sc->sc_stats.ast_tdma_tsf, 0, "TDMA slot update set TSF");
968 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_ack", CTLFLAG_RD,
969 	    &sc->sc_stats.ast_tdma_ack, 0, "TDMA tx failed 'cuz ACK required");
970 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_raw_fail", CTLFLAG_RD,
971 	    &sc->sc_stats.ast_tx_raw_fail, 0, "raw tx failed 'cuz h/w down");
972 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nofrag", CTLFLAG_RD,
973 	    &sc->sc_stats.ast_tx_nofrag, 0, "tx dropped 'cuz no ath frag buffer");
974 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_be_missed", CTLFLAG_RD,
975 	    &sc->sc_stats.ast_be_missed, 0, "number of -missed- beacons");
976 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ani_cal", CTLFLAG_RD,
977 	    &sc->sc_stats.ast_ani_cal, 0, "number of ANI polls");
978 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_agg", CTLFLAG_RD,
979 	    &sc->sc_stats.ast_rx_agg, 0, "number of aggregate frames received");
980 
981 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_halfgi", CTLFLAG_RD,
982 	    &sc->sc_stats.ast_rx_halfgi, 0, "number of frames received with half-GI");
983 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_2040", CTLFLAG_RD,
984 	    &sc->sc_stats.ast_rx_2040, 0, "number of HT/40 frames received");
985 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_pre_crc_err", CTLFLAG_RD,
986 	    &sc->sc_stats.ast_rx_pre_crc_err, 0, "number of delimeter-CRC errors detected");
987 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_post_crc_err", CTLFLAG_RD,
988 	    &sc->sc_stats.ast_rx_post_crc_err, 0, "number of post-delimiter CRC errors detected");
989 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_decrypt_busy_err", CTLFLAG_RD,
990 	    &sc->sc_stats.ast_rx_decrypt_busy_err, 0, "number of frames received w/ busy decrypt engine");
991 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_hi_rx_chain", CTLFLAG_RD,
992 	    &sc->sc_stats.ast_rx_hi_rx_chain, 0, "");
993 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_htprotect", CTLFLAG_RD,
994 	    &sc->sc_stats.ast_tx_htprotect, 0, "HT tx frames with protection");
995 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_hitqueueend", CTLFLAG_RD,
996 	    &sc->sc_stats.ast_rx_hitqueueend, 0, "RX hit queue end");
997 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_timeout", CTLFLAG_RD,
998 	    &sc->sc_stats.ast_tx_timeout, 0, "TX Global Timeout");
999 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_cst", CTLFLAG_RD,
1000 	    &sc->sc_stats.ast_tx_cst, 0, "TX Carrier Sense Timeout");
1001 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_xtxop", CTLFLAG_RD,
1002 	    &sc->sc_stats.ast_tx_xtxop, 0, "TX exceeded TXOP");
1003 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_timerexpired", CTLFLAG_RD,
1004 	    &sc->sc_stats.ast_tx_timerexpired, 0, "TX exceeded TX_TIMER register");
1005 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_desccfgerr", CTLFLAG_RD,
1006 	    &sc->sc_stats.ast_tx_desccfgerr, 0, "TX Descriptor Cfg Error");
1007 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_swretries", CTLFLAG_RD,
1008 	    &sc->sc_stats.ast_tx_swretries, 0, "TX software retry count");
1009 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_swretrymax", CTLFLAG_RD,
1010 	    &sc->sc_stats.ast_tx_swretrymax, 0, "TX software retry max reached");
1011 
1012 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_data_underrun", CTLFLAG_RD,
1013 	    &sc->sc_stats.ast_tx_data_underrun, 0, "");
1014 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_delim_underrun", CTLFLAG_RD,
1015 	    &sc->sc_stats.ast_tx_delim_underrun, 0, "");
1016 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_aggr_failall", CTLFLAG_RD,
1017 	    &sc->sc_stats.ast_tx_aggr_failall, 0,
1018 	    "Number of aggregate TX failures (whole frame)");
1019 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_aggr_ok", CTLFLAG_RD,
1020 	    &sc->sc_stats.ast_tx_aggr_ok, 0,
1021 	    "Number of aggregate TX OK completions (subframe)");
1022 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_aggr_fail", CTLFLAG_RD,
1023 	    &sc->sc_stats.ast_tx_aggr_fail, 0,
1024 	    "Number of aggregate TX failures (subframe)");
1025 
1026 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_intr", CTLFLAG_RD,
1027 	    &sc->sc_stats.ast_rx_intr, 0, "RX interrupts");
1028 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_intr", CTLFLAG_RD,
1029 	    &sc->sc_stats.ast_tx_intr, 0, "TX interrupts");
1030 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_mcastq_overflow",
1031 	    CTLFLAG_RD, &sc->sc_stats.ast_tx_mcastq_overflow, 0,
1032 	    "Number of multicast frames exceeding maximum mcast queue depth");
1033 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_keymiss", CTLFLAG_RD,
1034 	    &sc->sc_stats.ast_rx_keymiss, 0, "");
1035 	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_swfiltered", CTLFLAG_RD,
1036 	    &sc->sc_stats.ast_tx_swfiltered, 0, "");
1037 
1038 	/* Attach the RX phy error array */
1039 	ath_sysctl_stats_attach_rxphyerr(sc, child);
1040 
1041 	/* Attach the interrupt statistics array */
1042 	ath_sysctl_stats_attach_intr(sc, child);
1043 }
1044 
1045 /*
1046  * This doesn't necessarily belong here (because it's HAL related, not
1047  * driver related).
1048  */
1049 void
1050 ath_sysctl_hal_attach(struct ath_softc *sc)
1051 {
1052 	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
1053 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
1054 	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
1055 
1056 	tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hal", CTLFLAG_RD,
1057 	    NULL, "Atheros HAL parameters");
1058 	child = SYSCTL_CHILDREN(tree);
1059 
1060 	sc->sc_ah->ah_config.ah_debug = 0;
1061 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "debug", CTLFLAG_RW,
1062 	    &sc->sc_ah->ah_config.ah_debug, 0, "Atheros HAL debugging printfs");
1063 
1064 	sc->sc_ah->ah_config.ah_ar5416_biasadj = 0;
1065 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "ar5416_biasadj", CTLFLAG_RW,
1066 	    &sc->sc_ah->ah_config.ah_ar5416_biasadj, 0,
1067 	    "Enable 2GHz AR5416 direction sensitivity bias adjust");
1068 
1069 	sc->sc_ah->ah_config.ah_dma_beacon_response_time = 2;
1070 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "dma_brt", CTLFLAG_RW,
1071 	    &sc->sc_ah->ah_config.ah_dma_beacon_response_time, 0,
1072 	    "Atheros HAL DMA beacon response time");
1073 
1074 	sc->sc_ah->ah_config.ah_sw_beacon_response_time = 10;
1075 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "sw_brt", CTLFLAG_RW,
1076 	    &sc->sc_ah->ah_config.ah_sw_beacon_response_time, 0,
1077 	    "Atheros HAL software beacon response time");
1078 
1079 	sc->sc_ah->ah_config.ah_additional_swba_backoff = 0;
1080 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "swba_backoff", CTLFLAG_RW,
1081 	    &sc->sc_ah->ah_config.ah_additional_swba_backoff, 0,
1082 	    "Atheros HAL additional SWBA backoff time");
1083 
1084 	sc->sc_ah->ah_config.ah_force_full_reset = 0;
1085 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "force_full_reset", CTLFLAG_RW,
1086 	    &sc->sc_ah->ah_config.ah_force_full_reset, 0,
1087 	    "Force full chip reset rather than a warm reset");
1088 
1089 	/*
1090 	 * This is initialised by the driver.
1091 	 */
1092 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "serialise_reg_war", CTLFLAG_RW,
1093 	    &sc->sc_ah->ah_config.ah_serialise_reg_war, 0,
1094 	    "Force register access serialisation");
1095 }
1096