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