tizen 2.3.1 release
[external/qemu.git] / roms / ipxe / src / drivers / net / ath / ath9k / ani.h
1 /*
2  * Copyright (c) 2008-2011 Atheros Communications Inc.
3  *
4  * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
5  * Original from Linux kernel 3.0.1
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19
20 #ifndef ANI_H
21 #define ANI_H
22
23 #define HAL_PROCESS_ANI           0x00000001
24
25 #define DO_ANI(ah) (((ah)->proc_phyerr & HAL_PROCESS_ANI) && ah->curchan)
26
27 #define BEACON_RSSI(ahp) (ahp->stats.avgbrssi)
28
29 /* units are errors per second */
30 #define ATH9K_ANI_OFDM_TRIG_HIGH_OLD      500
31 #define ATH9K_ANI_OFDM_TRIG_HIGH_NEW      1000
32
33 /* units are errors per second */
34 #define ATH9K_ANI_OFDM_TRIG_LOW_OLD       200
35 #define ATH9K_ANI_OFDM_TRIG_LOW_NEW       400
36
37 /* units are errors per second */
38 #define ATH9K_ANI_CCK_TRIG_HIGH_OLD       200
39 #define ATH9K_ANI_CCK_TRIG_HIGH_NEW       600
40
41 /* units are errors per second */
42 #define ATH9K_ANI_CCK_TRIG_LOW_OLD        100
43 #define ATH9K_ANI_CCK_TRIG_LOW_NEW        300
44
45 #define ATH9K_ANI_NOISE_IMMUNE_LVL        4
46 #define ATH9K_ANI_USE_OFDM_WEAK_SIG       1
47 #define ATH9K_ANI_CCK_WEAK_SIG_THR        0
48
49 #define ATH9K_ANI_SPUR_IMMUNE_LVL_OLD     7
50 #define ATH9K_ANI_SPUR_IMMUNE_LVL_NEW     3
51
52 #define ATH9K_ANI_FIRSTEP_LVL_OLD         0
53 #define ATH9K_ANI_FIRSTEP_LVL_NEW         2
54
55 #define ATH9K_ANI_RSSI_THR_HIGH           40
56 #define ATH9K_ANI_RSSI_THR_LOW            7
57
58 #define ATH9K_ANI_PERIOD_OLD              100
59 #define ATH9K_ANI_PERIOD_NEW              1000
60
61 /* in ms */
62 #define ATH9K_ANI_POLLINTERVAL_OLD        100
63 #define ATH9K_ANI_POLLINTERVAL_NEW        1000
64
65 #define HAL_NOISE_IMMUNE_MAX              4
66 #define HAL_SPUR_IMMUNE_MAX               7
67 #define HAL_FIRST_STEP_MAX                2
68
69 #define ATH9K_SIG_FIRSTEP_SETTING_MIN     0
70 #define ATH9K_SIG_FIRSTEP_SETTING_MAX     20
71 #define ATH9K_SIG_SPUR_IMM_SETTING_MIN    0
72 #define ATH9K_SIG_SPUR_IMM_SETTING_MAX    22
73
74 #define ATH9K_ANI_ENABLE_MRC_CCK          1
75
76 /* values here are relative to the INI */
77
78 enum ath9k_ani_cmd {
79         ATH9K_ANI_PRESENT = 0x1,
80         ATH9K_ANI_NOISE_IMMUNITY_LEVEL = 0x2,
81         ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION = 0x4,
82         ATH9K_ANI_CCK_WEAK_SIGNAL_THR = 0x8,
83         ATH9K_ANI_FIRSTEP_LEVEL = 0x10,
84         ATH9K_ANI_SPUR_IMMUNITY_LEVEL = 0x20,
85         ATH9K_ANI_MODE = 0x40,
86         ATH9K_ANI_PHYERR_RESET = 0x80,
87         ATH9K_ANI_MRC_CCK = 0x100,
88         ATH9K_ANI_ALL = 0xfff
89 };
90
91 struct ath9k_mib_stats {
92         u32 ackrcv_bad;
93         u32 rts_bad;
94         u32 rts_good;
95         u32 fcs_bad;
96         u32 beacons;
97 };
98
99 /* INI default values for ANI registers */
100 struct ath9k_ani_default {
101         u16 m1ThreshLow;
102         u16 m2ThreshLow;
103         u16 m1Thresh;
104         u16 m2Thresh;
105         u16 m2CountThr;
106         u16 m2CountThrLow;
107         u16 m1ThreshLowExt;
108         u16 m2ThreshLowExt;
109         u16 m1ThreshExt;
110         u16 m2ThreshExt;
111         u16 firstep;
112         u16 firstepLow;
113         u16 cycpwrThr1;
114         u16 cycpwrThr1Ext;
115 };
116
117 struct ar5416AniState {
118         struct ath9k_channel *c;
119         u8 noiseImmunityLevel;
120         u8 ofdmNoiseImmunityLevel;
121         u8 cckNoiseImmunityLevel;
122         int ofdmsTurn;
123         u8 mrcCCKOff;
124         u8 spurImmunityLevel;
125         u8 firstepLevel;
126         u8 ofdmWeakSigDetectOff;
127         u8 cckWeakSigThreshold;
128         u32 listenTime;
129         int32_t rssiThrLow;
130         int32_t rssiThrHigh;
131         u32 noiseFloor;
132         u32 ofdmPhyErrCount;
133         u32 cckPhyErrCount;
134         int16_t pktRssi[2];
135         int16_t ofdmErrRssi[2];
136         int16_t cckErrRssi[2];
137         struct ath9k_ani_default iniDef;
138 };
139
140 struct ar5416Stats {
141         u32 ast_ani_niup;
142         u32 ast_ani_nidown;
143         u32 ast_ani_spurup;
144         u32 ast_ani_spurdown;
145         u32 ast_ani_ofdmon;
146         u32 ast_ani_ofdmoff;
147         u32 ast_ani_cckhigh;
148         u32 ast_ani_ccklow;
149         u32 ast_ani_stepup;
150         u32 ast_ani_stepdown;
151         u32 ast_ani_ofdmerrs;
152         u32 ast_ani_cckerrs;
153         u32 ast_ani_reset;
154         u32 ast_ani_lzero;
155         u32 ast_ani_lneg;
156         u32 avgbrssi;
157         struct ath9k_mib_stats ast_mibstats;
158 };
159 #define ah_mibStats stats.ast_mibstats
160
161 void ath9k_enable_mib_counters(struct ath_hw *ah);
162 void ath9k_hw_disable_mib_counters(struct ath_hw *ah);
163 void ath9k_hw_ani_setup(struct ath_hw *ah);
164 void ath9k_hw_ani_init(struct ath_hw *ah);
165 int ath9k_hw_get_ani_channel_idx(struct ath_hw *ah,
166                                  struct ath9k_channel *chan);
167
168 #endif /* ANI_H */