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_misc.h>
94#include <dev/ath/if_ath_tx.h>
95#include <dev/ath/if_ath_sysctl.h>
96
97#ifdef ATH_TX99_DIAG
98#include <dev/ath/ath_tx99/ath_tx99.h>
99#endif
100
101static int
102ath_sysctl_slottime(SYSCTL_HANDLER_ARGS)
103{
104	struct ath_softc *sc = arg1;
105	u_int slottime = ath_hal_getslottime(sc->sc_ah);
106	int error;
107
108	error = sysctl_handle_int(oidp, &slottime, 0, req);
109	if (error || !req->newptr)
110		return error;
111	return !ath_hal_setslottime(sc->sc_ah, slottime) ? EINVAL : 0;
112}
113
114static int
115ath_sysctl_acktimeout(SYSCTL_HANDLER_ARGS)
116{
117	struct ath_softc *sc = arg1;
118	u_int acktimeout = ath_hal_getacktimeout(sc->sc_ah);
119	int error;
120
121	error = sysctl_handle_int(oidp, &acktimeout, 0, req);
122	if (error || !req->newptr)
123		return error;
124	return !ath_hal_setacktimeout(sc->sc_ah, acktimeout) ? EINVAL : 0;
125}
126
127static int
128ath_sysctl_ctstimeout(SYSCTL_HANDLER_ARGS)
129{
130	struct ath_softc *sc = arg1;
131	u_int ctstimeout = ath_hal_getctstimeout(sc->sc_ah);
132	int error;
133
134	error = sysctl_handle_int(oidp, &ctstimeout, 0, req);
135	if (error || !req->newptr)
136		return error;
137	return !ath_hal_setctstimeout(sc->sc_ah, ctstimeout) ? EINVAL : 0;
138}
139
140static int
141ath_sysctl_softled(SYSCTL_HANDLER_ARGS)
142{
143	struct ath_softc *sc = arg1;
144	int softled = sc->sc_softled;
145	int error;
146
147	error = sysctl_handle_int(oidp, &softled, 0, req);
148	if (error || !req->newptr)
149		return error;
150	softled = (softled != 0);
151	if (softled != sc->sc_softled) {
152		if (softled) {
153			/* NB: handle any sc_ledpin change */
154			ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin,
155			    HAL_GPIO_MUX_MAC_NETWORK_LED);
156			ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin,
157				!sc->sc_ledon);
158		}
159		sc->sc_softled = softled;
160	}
161	return 0;
162}
163
164static int
165ath_sysctl_ledpin(SYSCTL_HANDLER_ARGS)
166{
167	struct ath_softc *sc = arg1;
168	int ledpin = sc->sc_ledpin;
169	int error;
170
171	error = sysctl_handle_int(oidp, &ledpin, 0, req);
172	if (error || !req->newptr)
173		return error;
174	if (ledpin != sc->sc_ledpin) {
175		sc->sc_ledpin = ledpin;
176		if (sc->sc_softled) {
177			ath_hal_gpioCfgOutput(sc->sc_ah, sc->sc_ledpin,
178			    HAL_GPIO_MUX_MAC_NETWORK_LED);
179			ath_hal_gpioset(sc->sc_ah, sc->sc_ledpin,
180				!sc->sc_ledon);
181		}
182	}
183	return 0;
184}
185
186static int
187ath_sysctl_txantenna(SYSCTL_HANDLER_ARGS)
188{
189	struct ath_softc *sc = arg1;
190	u_int txantenna = ath_hal_getantennaswitch(sc->sc_ah);
191	int error;
192
193	error = sysctl_handle_int(oidp, &txantenna, 0, req);
194	if (!error && req->newptr) {
195		/* XXX assumes 2 antenna ports */
196		if (txantenna < HAL_ANT_VARIABLE || txantenna > HAL_ANT_FIXED_B)
197			return EINVAL;
198		ath_hal_setantennaswitch(sc->sc_ah, txantenna);
199		/*
200		 * NB: with the switch locked this isn't meaningful,
201		 *     but set it anyway so things like radiotap get
202		 *     consistent info in their data.
203		 */
204		sc->sc_txantenna = txantenna;
205	}
206	return error;
207}
208
209static int
210ath_sysctl_rxantenna(SYSCTL_HANDLER_ARGS)
211{
212	struct ath_softc *sc = arg1;
213	u_int defantenna = ath_hal_getdefantenna(sc->sc_ah);
214	int error;
215
216	error = sysctl_handle_int(oidp, &defantenna, 0, req);
217	if (!error && req->newptr)
218		ath_hal_setdefantenna(sc->sc_ah, defantenna);
219	return error;
220}
221
222static int
223ath_sysctl_diversity(SYSCTL_HANDLER_ARGS)
224{
225	struct ath_softc *sc = arg1;
226	u_int diversity = ath_hal_getdiversity(sc->sc_ah);
227	int error;
228
229	error = sysctl_handle_int(oidp, &diversity, 0, req);
230	if (error || !req->newptr)
231		return error;
232	if (!ath_hal_setdiversity(sc->sc_ah, diversity))
233		return EINVAL;
234	sc->sc_diversity = diversity;
235	return 0;
236}
237
238static int
239ath_sysctl_diag(SYSCTL_HANDLER_ARGS)
240{
241	struct ath_softc *sc = arg1;
242	u_int32_t diag;
243	int error;
244
245	if (!ath_hal_getdiag(sc->sc_ah, &diag))
246		return EINVAL;
247	error = sysctl_handle_int(oidp, &diag, 0, req);
248	if (error || !req->newptr)
249		return error;
250	return !ath_hal_setdiag(sc->sc_ah, diag) ? EINVAL : 0;
251}
252
253static int
254ath_sysctl_tpscale(SYSCTL_HANDLER_ARGS)
255{
256	struct ath_softc *sc = arg1;
257	struct ifnet *ifp = sc->sc_ifp;
258	u_int32_t scale;
259	int error;
260
261	(void) ath_hal_gettpscale(sc->sc_ah, &scale);
262	error = sysctl_handle_int(oidp, &scale, 0, req);
263	if (error || !req->newptr)
264		return error;
265	return !ath_hal_settpscale(sc->sc_ah, scale) ? EINVAL :
266	    (ifp->if_drv_flags & IFF_DRV_RUNNING) ? ath_reset(ifp) : 0;
267}
268
269static int
270ath_sysctl_tpc(SYSCTL_HANDLER_ARGS)
271{
272	struct ath_softc *sc = arg1;
273	u_int tpc = ath_hal_gettpc(sc->sc_ah);
274	int error;
275
276	error = sysctl_handle_int(oidp, &tpc, 0, req);
277	if (error || !req->newptr)
278		return error;
279	return !ath_hal_settpc(sc->sc_ah, tpc) ? EINVAL : 0;
280}
281
282static int
283ath_sysctl_rfkill(SYSCTL_HANDLER_ARGS)
284{
285	struct ath_softc *sc = arg1;
286	struct ifnet *ifp = sc->sc_ifp;
287	struct ath_hal *ah = sc->sc_ah;
288	u_int rfkill = ath_hal_getrfkill(ah);
289	int error;
290
291	error = sysctl_handle_int(oidp, &rfkill, 0, req);
292	if (error || !req->newptr)
293		return error;
294	if (rfkill == ath_hal_getrfkill(ah))	/* unchanged */
295		return 0;
296	if (!ath_hal_setrfkill(ah, rfkill))
297		return EINVAL;
298	return (ifp->if_drv_flags & IFF_DRV_RUNNING) ? ath_reset(ifp) : 0;
299}
300
301static int
302ath_sysctl_rfsilent(SYSCTL_HANDLER_ARGS)
303{
304	struct ath_softc *sc = arg1;
305	u_int rfsilent;
306	int error;
307
308	(void) ath_hal_getrfsilent(sc->sc_ah, &rfsilent);
309	error = sysctl_handle_int(oidp, &rfsilent, 0, req);
310	if (error || !req->newptr)
311		return error;
312	if (!ath_hal_setrfsilent(sc->sc_ah, rfsilent))
313		return EINVAL;
314	sc->sc_rfsilentpin = rfsilent & 0x1c;
315	sc->sc_rfsilentpol = (rfsilent & 0x2) != 0;
316	return 0;
317}
318
319static int
320ath_sysctl_tpack(SYSCTL_HANDLER_ARGS)
321{
322	struct ath_softc *sc = arg1;
323	u_int32_t tpack;
324	int error;
325
326	(void) ath_hal_gettpack(sc->sc_ah, &tpack);
327	error = sysctl_handle_int(oidp, &tpack, 0, req);
328	if (error || !req->newptr)
329		return error;
330	return !ath_hal_settpack(sc->sc_ah, tpack) ? EINVAL : 0;
331}
332
333static int
334ath_sysctl_tpcts(SYSCTL_HANDLER_ARGS)
335{
336	struct ath_softc *sc = arg1;
337	u_int32_t tpcts;
338	int error;
339
340	(void) ath_hal_gettpcts(sc->sc_ah, &tpcts);
341	error = sysctl_handle_int(oidp, &tpcts, 0, req);
342	if (error || !req->newptr)
343		return error;
344	return !ath_hal_settpcts(sc->sc_ah, tpcts) ? EINVAL : 0;
345}
346
347static int
348ath_sysctl_intmit(SYSCTL_HANDLER_ARGS)
349{
350	struct ath_softc *sc = arg1;
351	int intmit, error;
352
353	intmit = ath_hal_getintmit(sc->sc_ah);
354	error = sysctl_handle_int(oidp, &intmit, 0, req);
355	if (error || !req->newptr)
356		return error;
357
358	/* reusing error; 1 here means "good"; 0 means "fail" */
359	error = ath_hal_setintmit(sc->sc_ah, intmit);
360	if (! error)
361		return EINVAL;
362
363	/*
364	 * Reset the hardware here - disabling ANI in the HAL
365	 * doesn't reset ANI related registers, so it'll leave
366	 * things in an inconsistent state.
367	 */
368	if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
369		ath_reset(sc->sc_ifp);
370
371	return 0;
372}
373
374#ifdef IEEE80211_SUPPORT_TDMA
375static int
376ath_sysctl_setcca(SYSCTL_HANDLER_ARGS)
377{
378	struct ath_softc *sc = arg1;
379	int setcca, error;
380
381	setcca = sc->sc_setcca;
382	error = sysctl_handle_int(oidp, &setcca, 0, req);
383	if (error || !req->newptr)
384		return error;
385	sc->sc_setcca = (setcca != 0);
386	return 0;
387}
388#endif /* IEEE80211_SUPPORT_TDMA */
389
390void
391ath_sysctlattach(struct ath_softc *sc)
392{
393	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
394	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
395	struct ath_hal *ah = sc->sc_ah;
396
397	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
398		"countrycode", CTLFLAG_RD, &sc->sc_eecc, 0,
399		"EEPROM country code");
400	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
401		"regdomain", CTLFLAG_RD, &sc->sc_eerd, 0,
402		"EEPROM regdomain code");
403#ifdef	ATH_DEBUG
404	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
405		"debug", CTLFLAG_RW, &sc->sc_debug, 0,
406		"control debugging printfs");
407#endif
408	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
409		"slottime", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
410		ath_sysctl_slottime, "I", "802.11 slot time (us)");
411	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
412		"acktimeout", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
413		ath_sysctl_acktimeout, "I", "802.11 ACK timeout (us)");
414	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
415		"ctstimeout", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
416		ath_sysctl_ctstimeout, "I", "802.11 CTS timeout (us)");
417	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
418		"softled", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
419		ath_sysctl_softled, "I", "enable/disable software LED support");
420	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
421		"ledpin", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
422		ath_sysctl_ledpin, "I", "GPIO pin connected to LED");
423	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
424		"ledon", CTLFLAG_RW, &sc->sc_ledon, 0,
425		"setting to turn LED on");
426	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
427		"ledidle", CTLFLAG_RW, &sc->sc_ledidle, 0,
428		"idle time for inactivity LED (ticks)");
429	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
430		"txantenna", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
431		ath_sysctl_txantenna, "I", "antenna switch");
432	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
433		"rxantenna", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
434		ath_sysctl_rxantenna, "I", "default/rx antenna");
435	if (ath_hal_hasdiversity(ah))
436		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
437			"diversity", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
438			ath_sysctl_diversity, "I", "antenna diversity");
439	sc->sc_txintrperiod = ATH_TXINTR_PERIOD;
440	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
441		"txintrperiod", CTLFLAG_RW, &sc->sc_txintrperiod, 0,
442		"tx descriptor batching");
443	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
444		"diag", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
445		ath_sysctl_diag, "I", "h/w diagnostic control");
446	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
447		"tpscale", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
448		ath_sysctl_tpscale, "I", "tx power scaling");
449	if (ath_hal_hastpc(ah)) {
450		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
451			"tpc", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
452			ath_sysctl_tpc, "I", "enable/disable per-packet TPC");
453		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
454			"tpack", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
455			ath_sysctl_tpack, "I", "tx power for ack frames");
456		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
457			"tpcts", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
458			ath_sysctl_tpcts, "I", "tx power for cts frames");
459	}
460	if (ath_hal_hasrfsilent(ah)) {
461		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
462			"rfsilent", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
463			ath_sysctl_rfsilent, "I", "h/w RF silent config");
464		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
465			"rfkill", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
466			ath_sysctl_rfkill, "I", "enable/disable RF kill switch");
467	}
468	if (ath_hal_hasintmit(ah)) {
469		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
470			"intmit", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
471			ath_sysctl_intmit, "I", "interference mitigation");
472	}
473	sc->sc_monpass = HAL_RXERR_DECRYPT | HAL_RXERR_MIC;
474	SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
475		"monpass", CTLFLAG_RW, &sc->sc_monpass, 0,
476		"mask of error frames to pass when monitoring");
477#ifdef IEEE80211_SUPPORT_TDMA
478	if (ath_hal_macversion(ah) > 0x78) {
479		sc->sc_tdmadbaprep = 2;
480		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
481			"dbaprep", CTLFLAG_RW, &sc->sc_tdmadbaprep, 0,
482			"TDMA DBA preparation time");
483		sc->sc_tdmaswbaprep = 10;
484		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
485			"swbaprep", CTLFLAG_RW, &sc->sc_tdmaswbaprep, 0,
486			"TDMA SWBA preparation time");
487		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
488			"guardtime", CTLFLAG_RW, &sc->sc_tdmaguard, 0,
489			"TDMA slot guard time");
490		SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
491			"superframe", CTLFLAG_RD, &sc->sc_tdmabintval, 0,
492			"TDMA calculated super frame");
493		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
494			"setcca", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
495			ath_sysctl_setcca, "I", "enable CCA control");
496	}
497#endif
498}
499
500static int
501ath_sysctl_clearstats(SYSCTL_HANDLER_ARGS)
502{
503	struct ath_softc *sc = arg1;
504	int val = 0;
505	int error;
506
507	error = sysctl_handle_int(oidp, &val, 0, req);
508	if (error || !req->newptr)
509		return error;
510	if (val == 0)
511		return 0;       /* Not clearing the stats is still valid */
512	memset(&sc->sc_stats, 0, sizeof(sc->sc_stats));
513	val = 0;
514	return 0;
515}
516
517static void
518ath_sysctl_stats_attach_rxphyerr(struct ath_softc *sc, struct sysctl_oid_list *parent)
519{
520	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
521	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
522	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
523	int i;
524	char sn[8];
525
526	tree = SYSCTL_ADD_NODE(ctx, parent, OID_AUTO, "rx_phy_err", CTLFLAG_RD, NULL, "Per-code RX PHY Errors");
527	child = SYSCTL_CHILDREN(tree);
528	for (i = 0; i < 64; i++) {
529		snprintf(sn, sizeof(sn), "%d", i);
530		SYSCTL_ADD_UINT(ctx, child, OID_AUTO, sn, CTLFLAG_RD, &sc->sc_stats.ast_rx_phy[i], 0, "");
531	}
532}
533
534void
535ath_sysctl_stats_attach(struct ath_softc *sc)
536{
537	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
538	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
539	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
540
541	/* Create "clear" node */
542	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
543	    "clear_stats", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
544	    ath_sysctl_clearstats, "I", "clear stats");
545
546	/* Create stats node */
547	tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "stats", CTLFLAG_RD,
548	    NULL, "Statistics");
549	child = SYSCTL_CHILDREN(tree);
550
551	/* This was generated from if_athioctl.h */
552
553	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_watchdog", CTLFLAG_RD,
554	    &sc->sc_stats.ast_watchdog, 0, "device reset by watchdog");
555	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_hardware", CTLFLAG_RD,
556	    &sc->sc_stats.ast_hardware, 0, "fatal hardware error interrupts");
557	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_bmiss", CTLFLAG_RD,
558	    &sc->sc_stats.ast_bmiss, 0, "beacon miss interrupts");
559	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_bmiss_phantom", CTLFLAG_RD,
560	    &sc->sc_stats.ast_bmiss_phantom, 0, "beacon miss interrupts");
561	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_bstuck", CTLFLAG_RD,
562	    &sc->sc_stats.ast_bstuck, 0, "beacon stuck interrupts");
563	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rxorn", CTLFLAG_RD,
564	    &sc->sc_stats.ast_rxorn, 0, "rx overrun interrupts");
565	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rxeol", CTLFLAG_RD,
566	    &sc->sc_stats.ast_rxeol, 0, "rx eol interrupts");
567	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_txurn", CTLFLAG_RD,
568	    &sc->sc_stats.ast_txurn, 0, "tx underrun interrupts");
569	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_mib", CTLFLAG_RD,
570	    &sc->sc_stats.ast_mib, 0, "mib interrupts");
571	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_intrcoal", CTLFLAG_RD,
572	    &sc->sc_stats.ast_intrcoal, 0, "interrupts coalesced");
573	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_packets", CTLFLAG_RD,
574	    &sc->sc_stats.ast_tx_packets, 0, "packet sent on the interface");
575	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_mgmt", CTLFLAG_RD,
576	    &sc->sc_stats.ast_tx_mgmt, 0, "management frames transmitted");
577	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_discard", CTLFLAG_RD,
578	    &sc->sc_stats.ast_tx_discard, 0, "frames discarded prior to assoc");
579	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_qstop", CTLFLAG_RD,
580	    &sc->sc_stats.ast_tx_qstop, 0, "output stopped 'cuz no buffer");
581	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_encap", CTLFLAG_RD,
582	    &sc->sc_stats.ast_tx_encap, 0, "tx encapsulation failed");
583	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nonode", CTLFLAG_RD,
584	    &sc->sc_stats.ast_tx_nonode, 0, "tx failed 'cuz no node");
585	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nombuf", CTLFLAG_RD,
586	    &sc->sc_stats.ast_tx_nombuf, 0, "tx failed 'cuz no mbuf");
587	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nomcl", CTLFLAG_RD,
588	    &sc->sc_stats.ast_tx_nomcl, 0, "tx failed 'cuz no cluster");
589	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_linear", CTLFLAG_RD,
590	    &sc->sc_stats.ast_tx_linear, 0, "tx linearized to cluster");
591	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nodata", CTLFLAG_RD,
592	    &sc->sc_stats.ast_tx_nodata, 0, "tx discarded empty frame");
593	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_busdma", CTLFLAG_RD,
594	    &sc->sc_stats.ast_tx_busdma, 0, "tx failed for dma resrcs");
595	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_xretries", CTLFLAG_RD,
596	    &sc->sc_stats.ast_tx_xretries, 0, "tx failed 'cuz too many retries");
597	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_fifoerr", CTLFLAG_RD,
598	    &sc->sc_stats.ast_tx_fifoerr, 0, "tx failed 'cuz FIFO underrun");
599	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_filtered", CTLFLAG_RD,
600	    &sc->sc_stats.ast_tx_filtered, 0, "tx failed 'cuz xmit filtered");
601	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_shortretry", CTLFLAG_RD,
602	    &sc->sc_stats.ast_tx_shortretry, 0, "tx on-chip retries (short)");
603	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_longretry", CTLFLAG_RD,
604	    &sc->sc_stats.ast_tx_longretry, 0, "tx on-chip retries (long)");
605	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_badrate", CTLFLAG_RD,
606	    &sc->sc_stats.ast_tx_badrate, 0, "tx failed 'cuz bogus xmit rate");
607	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_noack", CTLFLAG_RD,
608	    &sc->sc_stats.ast_tx_noack, 0, "tx frames with no ack marked");
609	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_rts", CTLFLAG_RD,
610	    &sc->sc_stats.ast_tx_rts, 0, "tx frames with rts enabled");
611	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_cts", CTLFLAG_RD,
612	    &sc->sc_stats.ast_tx_cts, 0, "tx frames with cts enabled");
613	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_shortpre", CTLFLAG_RD,
614	    &sc->sc_stats.ast_tx_shortpre, 0, "tx frames with short preamble");
615	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_altrate", CTLFLAG_RD,
616	    &sc->sc_stats.ast_tx_altrate, 0, "tx frames with alternate rate");
617	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_protect", CTLFLAG_RD,
618	    &sc->sc_stats.ast_tx_protect, 0, "tx frames with protection");
619	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_ctsburst", CTLFLAG_RD,
620	    &sc->sc_stats.ast_tx_ctsburst, 0, "tx frames with cts and bursting");
621	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_ctsext", CTLFLAG_RD,
622	    &sc->sc_stats.ast_tx_ctsext, 0, "tx frames with cts extension");
623	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_nombuf", CTLFLAG_RD,
624	    &sc->sc_stats.ast_rx_nombuf, 0, "rx setup failed 'cuz no mbuf");
625	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_busdma", CTLFLAG_RD,
626	    &sc->sc_stats.ast_rx_busdma, 0, "rx setup failed for dma resrcs");
627	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_orn", CTLFLAG_RD,
628	    &sc->sc_stats.ast_rx_orn, 0, "rx failed 'cuz of desc overrun");
629	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_crcerr", CTLFLAG_RD,
630	    &sc->sc_stats.ast_rx_crcerr, 0, "rx failed 'cuz of bad CRC");
631	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_fifoerr", CTLFLAG_RD,
632	    &sc->sc_stats.ast_rx_fifoerr, 0, "rx failed 'cuz of FIFO overrun");
633	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_badcrypt", CTLFLAG_RD,
634	    &sc->sc_stats.ast_rx_badcrypt, 0, "rx failed 'cuz decryption");
635	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_badmic", CTLFLAG_RD,
636	    &sc->sc_stats.ast_rx_badmic, 0, "rx failed 'cuz MIC failure");
637	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_phyerr", CTLFLAG_RD,
638	    &sc->sc_stats.ast_rx_phyerr, 0, "rx failed 'cuz of PHY err");
639	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_tooshort", CTLFLAG_RD,
640	    &sc->sc_stats.ast_rx_tooshort, 0, "rx discarded 'cuz frame too short");
641	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_toobig", CTLFLAG_RD,
642	    &sc->sc_stats.ast_rx_toobig, 0, "rx discarded 'cuz frame too large");
643	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_packets", CTLFLAG_RD,
644	    &sc->sc_stats.ast_rx_packets, 0, "packet recv on the interface");
645	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_mgt", CTLFLAG_RD,
646	    &sc->sc_stats.ast_rx_mgt, 0, "management frames received");
647	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_ctl", CTLFLAG_RD,
648	    &sc->sc_stats.ast_rx_ctl, 0, "rx discarded 'cuz ctl frame");
649	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_be_xmit", CTLFLAG_RD,
650	    &sc->sc_stats.ast_be_xmit, 0, "beacons transmitted");
651	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_be_nombuf", CTLFLAG_RD,
652	    &sc->sc_stats.ast_be_nombuf, 0, "beacon setup failed 'cuz no mbuf");
653	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_per_cal", CTLFLAG_RD,
654	    &sc->sc_stats.ast_per_cal, 0, "periodic calibration calls");
655	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_per_calfail", CTLFLAG_RD,
656	    &sc->sc_stats.ast_per_calfail, 0, "periodic calibration failed");
657	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_per_rfgain", CTLFLAG_RD,
658	    &sc->sc_stats.ast_per_rfgain, 0, "periodic calibration rfgain reset");
659	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rate_calls", CTLFLAG_RD,
660	    &sc->sc_stats.ast_rate_calls, 0, "rate control checks");
661	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rate_raise", CTLFLAG_RD,
662	    &sc->sc_stats.ast_rate_raise, 0, "rate control raised xmit rate");
663	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rate_drop", CTLFLAG_RD,
664	    &sc->sc_stats.ast_rate_drop, 0, "rate control dropped xmit rate");
665	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ant_defswitch", CTLFLAG_RD,
666	    &sc->sc_stats.ast_ant_defswitch, 0, "rx/default antenna switches");
667	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ant_txswitch", CTLFLAG_RD,
668	    &sc->sc_stats.ast_ant_txswitch, 0, "tx antenna switches");
669	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_cabq_xmit", CTLFLAG_RD,
670	    &sc->sc_stats.ast_cabq_xmit, 0, "cabq frames transmitted");
671	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_cabq_busy", CTLFLAG_RD,
672	    &sc->sc_stats.ast_cabq_busy, 0, "cabq found busy");
673	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_raw", CTLFLAG_RD,
674	    &sc->sc_stats.ast_tx_raw, 0, "tx frames through raw api");
675	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_txok", CTLFLAG_RD,
676	    &sc->sc_stats.ast_ff_txok, 0, "fast frames tx'd successfully");
677	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_txerr", CTLFLAG_RD,
678	    &sc->sc_stats.ast_ff_txerr, 0, "fast frames tx'd w/ error");
679	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_rx", CTLFLAG_RD,
680	    &sc->sc_stats.ast_ff_rx, 0, "fast frames rx'd");
681	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ff_flush", CTLFLAG_RD,
682	    &sc->sc_stats.ast_ff_flush, 0, "fast frames flushed from staging q");
683	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_qfull", CTLFLAG_RD,
684	    &sc->sc_stats.ast_tx_qfull, 0, "tx dropped 'cuz of queue limit");
685	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nobuf", CTLFLAG_RD,
686	    &sc->sc_stats.ast_tx_nobuf, 0, "tx dropped 'cuz no ath buffer");
687	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_update", CTLFLAG_RD,
688	    &sc->sc_stats.ast_tdma_update, 0, "TDMA slot timing updates");
689	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_timers", CTLFLAG_RD,
690	    &sc->sc_stats.ast_tdma_timers, 0, "TDMA slot update set beacon timers");
691	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_tsf", CTLFLAG_RD,
692	    &sc->sc_stats.ast_tdma_tsf, 0, "TDMA slot update set TSF");
693	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tdma_ack", CTLFLAG_RD,
694	    &sc->sc_stats.ast_tdma_ack, 0, "TDMA tx failed 'cuz ACK required");
695	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_raw_fail", CTLFLAG_RD,
696	    &sc->sc_stats.ast_tx_raw_fail, 0, "raw tx failed 'cuz h/w down");
697	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_nofrag", CTLFLAG_RD,
698	    &sc->sc_stats.ast_tx_nofrag, 0, "tx dropped 'cuz no ath frag buffer");
699	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_be_missed", CTLFLAG_RD,
700	    &sc->sc_stats.ast_be_missed, 0, "number of -missed- beacons");
701	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_ani_cal", CTLFLAG_RD,
702	    &sc->sc_stats.ast_ani_cal, 0, "number of ANI polls");
703	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_agg", CTLFLAG_RD,
704	    &sc->sc_stats.ast_rx_agg, 0, "number of aggregate frames received");
705
706	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_halfgi", CTLFLAG_RD,
707	    &sc->sc_stats.ast_rx_halfgi, 0, "number of frames received with half-GI");
708	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_2040", CTLFLAG_RD,
709	    &sc->sc_stats.ast_rx_2040, 0, "number of HT/40 frames received");
710	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_pre_crc_err", CTLFLAG_RD,
711	    &sc->sc_stats.ast_rx_pre_crc_err, 0, "number of delimeter-CRC errors detected");
712	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_post_crc_err", CTLFLAG_RD,
713	    &sc->sc_stats.ast_rx_post_crc_err, 0, "number of post-delimiter CRC errors detected");
714	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_decrypt_busy_err", CTLFLAG_RD,
715	    &sc->sc_stats.ast_rx_decrypt_busy_err, 0, "number of frames received w/ busy decrypt engine");
716	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_hi_rx_chain", CTLFLAG_RD,
717	    &sc->sc_stats.ast_rx_hi_rx_chain, 0, "");
718	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_htprotect", CTLFLAG_RD,
719	    &sc->sc_stats.ast_tx_htprotect, 0, "HT tx frames with protection");
720	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_rx_hitqueueend", CTLFLAG_RD,
721	    &sc->sc_stats.ast_rx_hitqueueend, 0, "RX hit queue end");
722	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_timeout", CTLFLAG_RD,
723	    &sc->sc_stats.ast_tx_timeout, 0, "TX Global Timeout");
724	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_cst", CTLFLAG_RD,
725	    &sc->sc_stats.ast_tx_cst, 0, "TX Carrier Sense Timeout");
726	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_xtxop", CTLFLAG_RD,
727	    &sc->sc_stats.ast_tx_xtxop, 0, "TX exceeded TXOP");
728	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_timerexpired", CTLFLAG_RD,
729	    &sc->sc_stats.ast_tx_timerexpired, 0, "TX exceeded TX_TIMER register");
730	SYSCTL_ADD_UINT(ctx, child, OID_AUTO, "ast_tx_desccfgerr", CTLFLAG_RD,
731	    &sc->sc_stats.ast_tx_desccfgerr, 0, "TX Descriptor Cfg Error");
732
733	/* Attach the RX phy error array */
734	ath_sysctl_stats_attach_rxphyerr(sc, child);
735}
736
737/*
738 * This doesn't necessarily belong here (because it's HAL related, not
739 * driver related).
740 */
741void
742ath_sysctl_hal_attach(struct ath_softc *sc)
743{
744	struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev);
745	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev);
746	struct sysctl_oid_list *child = SYSCTL_CHILDREN(tree);
747
748	tree = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hal", CTLFLAG_RD,
749	    NULL, "Atheros HAL parameters");
750	child = SYSCTL_CHILDREN(tree);
751
752	sc->sc_ah->ah_config.ah_debug = 0;
753	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "debug", CTLFLAG_RW,
754	    &sc->sc_ah->ah_config.ah_debug, 0, "Atheros HAL debugging printfs");
755
756	sc->sc_ah->ah_config.ah_ar5416_biasadj = 0;
757	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "ar5416_biasadj", CTLFLAG_RW,
758	    &sc->sc_ah->ah_config.ah_ar5416_biasadj, 0,
759	    "Enable 2GHz AR5416 direction sensitivity bias adjust");
760
761	sc->sc_ah->ah_config.ah_dma_beacon_response_time = 2;
762	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "dma_brt", CTLFLAG_RW,
763	    &sc->sc_ah->ah_config.ah_dma_beacon_response_time, 0,
764	    "Atheros HAL DMA beacon response time");
765
766	sc->sc_ah->ah_config.ah_sw_beacon_response_time = 10;
767	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "sw_brt", CTLFLAG_RW,
768	    &sc->sc_ah->ah_config.ah_sw_beacon_response_time, 0,
769	    "Atheros HAL software beacon response time");
770
771	sc->sc_ah->ah_config.ah_additional_swba_backoff = 0;
772	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "swba_backoff", CTLFLAG_RW,
773	    &sc->sc_ah->ah_config.ah_additional_swba_backoff, 0,
774	    "Atheros HAL additional SWBA backoff time");
775}
776