Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless
[cascardo/linux.git] / drivers / net / wireless / ath / ath9k / ani.h
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef ANI_H
18 #define ANI_H
19
20 #define BEACON_RSSI(ahp) (ahp->stats.avgbrssi)
21
22 /* units are errors per second */
23 #define ATH9K_ANI_OFDM_TRIG_HIGH          3500
24 #define ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI 1000
25
26 /* units are errors per second */
27 #define ATH9K_ANI_OFDM_TRIG_LOW           400
28 #define ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI 900
29
30 /* units are errors per second */
31 #define ATH9K_ANI_CCK_TRIG_HIGH           600
32
33 /* units are errors per second */
34 #define ATH9K_ANI_CCK_TRIG_LOW            300
35
36 #define ATH9K_ANI_NOISE_IMMUNE_LVL        4
37 #define ATH9K_ANI_SPUR_IMMUNE_LVL         3
38 #define ATH9K_ANI_FIRSTEP_LVL             2
39
40 #define ATH9K_ANI_RSSI_THR_HIGH           40
41 #define ATH9K_ANI_RSSI_THR_LOW            7
42
43 #define ATH9K_ANI_PERIOD                  300
44
45 /* in ms */
46 #define ATH9K_ANI_POLLINTERVAL            1000
47
48 #define HAL_NOISE_IMMUNE_MAX              4
49 #define HAL_SPUR_IMMUNE_MAX               7
50 #define HAL_FIRST_STEP_MAX                2
51
52 #define ATH9K_SIG_FIRSTEP_SETTING_MIN     0
53 #define ATH9K_SIG_FIRSTEP_SETTING_MAX     20
54 #define ATH9K_SIG_SPUR_IMM_SETTING_MIN    0
55 #define ATH9K_SIG_SPUR_IMM_SETTING_MAX    22
56
57 /* values here are relative to the INI */
58
59 enum ath9k_ani_cmd {
60         ATH9K_ANI_PRESENT = 0x1,
61         ATH9K_ANI_NOISE_IMMUNITY_LEVEL = 0x2,
62         ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION = 0x4,
63         ATH9K_ANI_CCK_WEAK_SIGNAL_THR = 0x8,
64         ATH9K_ANI_FIRSTEP_LEVEL = 0x10,
65         ATH9K_ANI_SPUR_IMMUNITY_LEVEL = 0x20,
66         ATH9K_ANI_MODE = 0x40,
67         ATH9K_ANI_PHYERR_RESET = 0x80,
68         ATH9K_ANI_MRC_CCK = 0x100,
69         ATH9K_ANI_ALL = 0xfff
70 };
71
72 struct ath9k_mib_stats {
73         u32 ackrcv_bad;
74         u32 rts_bad;
75         u32 rts_good;
76         u32 fcs_bad;
77         u32 beacons;
78 };
79
80 /* INI default values for ANI registers */
81 struct ath9k_ani_default {
82         u16 m1ThreshLow;
83         u16 m2ThreshLow;
84         u16 m1Thresh;
85         u16 m2Thresh;
86         u16 m2CountThr;
87         u16 m2CountThrLow;
88         u16 m1ThreshLowExt;
89         u16 m2ThreshLowExt;
90         u16 m1ThreshExt;
91         u16 m2ThreshExt;
92         u16 firstep;
93         u16 firstepLow;
94         u16 cycpwrThr1;
95         u16 cycpwrThr1Ext;
96 };
97
98 struct ar5416AniState {
99         u8 noiseImmunityLevel;
100         u8 ofdmNoiseImmunityLevel;
101         u8 cckNoiseImmunityLevel;
102         bool ofdmsTurn;
103         u8 mrcCCK;
104         u8 spurImmunityLevel;
105         u8 firstepLevel;
106         bool ofdmWeakSigDetect;
107         u32 listenTime;
108         u32 ofdmPhyErrCount;
109         u32 cckPhyErrCount;
110         struct ath9k_ani_default iniDef;
111 };
112
113 struct ar5416Stats {
114         u32 ast_ani_spurup;
115         u32 ast_ani_spurdown;
116         u32 ast_ani_ofdmon;
117         u32 ast_ani_ofdmoff;
118         u32 ast_ani_cckhigh;
119         u32 ast_ani_ccklow;
120         u32 ast_ani_stepup;
121         u32 ast_ani_stepdown;
122         u32 ast_ani_ofdmerrs;
123         u32 ast_ani_cckerrs;
124         u32 ast_ani_reset;
125         u32 ast_ani_lneg_or_lzero;
126         u32 avgbrssi;
127         struct ath9k_mib_stats ast_mibstats;
128 };
129 #define ah_mibStats stats.ast_mibstats
130
131 void ath9k_enable_mib_counters(struct ath_hw *ah);
132 void ath9k_hw_disable_mib_counters(struct ath_hw *ah);
133 void ath9k_hw_ani_init(struct ath_hw *ah);
134
135 #endif /* ANI_H */