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