bd21ea33d094b018502e710e64795a59630971ef
[openwrt/openwrt.git] / package / madwifi / patches / 352-ani_fix.patch
1 Index: madwifi-trunk-r3314/ath/if_ath.c
2 ===================================================================
3 --- madwifi-trunk-r3314.orig/ath/if_ath.c 2008-06-13 09:28:25.000000000 +0200
4 +++ madwifi-trunk-r3314/ath/if_ath.c 2008-06-13 09:29:00.000000000 +0200
5 @@ -1014,9 +1014,7 @@
6 */
7 sc->sc_hasveol = ath_hal_hasveol(ah);
8
9 - /* Interference mitigation/ambient noise immunity (ANI).
10 - * In modes other than HAL_M_STA, it causes receive sensitivity
11 - * problems for OFDM. */
12 + /* Interference mitigation/ambient noise immunity (ANI). */
13 sc->sc_hasintmit = ath_hal_hasintmit(ah);
14
15 /* get mac address from hardware */
16 @@ -1144,6 +1142,11 @@
17 sc->sc_rp_lasttsf = 0;
18 sc->sc_last_tsf = 0;
19
20 + /* set all 3 to auto */
21 + sc->sc_intmit = -1;
22 + sc->sc_noise_immunity = -1;
23 + sc->sc_ofdm_weak_det = -1;
24 +
25 return 0;
26 bad3:
27 ieee80211_ifdetach(ic);
28 @@ -2347,16 +2350,6 @@
29 }
30 if (status & HAL_INT_MIB) {
31 sc->sc_stats.ast_mib++;
32 - /* When the card receives lots of PHY errors, the MIB
33 - * interrupt will fire at a very rapid rate. We will use
34 - * a timer to enforce at least 1 jiffy delay between
35 - * MIB interrupts. This should be unproblematic, since
36 - * the hardware will continue to update the counters in
37 - * the mean time. */
38 - sc->sc_imask &= ~HAL_INT_MIB;
39 - ath_hal_intrset(ah, sc->sc_imask);
40 - mod_timer(&sc->sc_mib_enable, jiffies + 1);
41 -
42 /* Let the HAL handle the event. */
43 ath_hal_mibevent(ah, &sc->sc_halstats);
44 }
45 @@ -2426,6 +2419,43 @@
46 return flags;
47 }
48
49 +static int ath_setintmit(struct ath_softc *sc)
50 +{
51 + struct ath_hal *ah = sc->sc_ah;
52 + int ret;
53 + int val;
54 +
55 + if (!sc->sc_hasintmit)
56 + return 0;
57 +
58 + switch(sc->sc_intmit) {
59 + case -1:
60 + if (sc->sc_opmode != IEEE80211_M_MONITOR)
61 + val = 1;
62 + else
63 + val = 0;
64 + break;
65 + case 0: /* disabled */
66 + case 1: /* enabled */
67 + val = sc->sc_intmit;
68 + break;
69 + default:
70 + return 0;
71 + }
72 + ret = ath_hal_setintmit(ah, val);
73 + if (val)
74 + goto done;
75 +
76 + /* manual settings */
77 + if ((sc->sc_noise_immunity >= 0) && (sc->sc_noise_immunity <= 5))
78 + ath_hal_setcapability(ah, HAL_CAP_INTMIT, 2, sc->sc_noise_immunity, NULL);
79 + if ((sc->sc_ofdm_weak_det == 0) || (sc->sc_ofdm_weak_det == 1))
80 + ath_hal_setcapability(ah, HAL_CAP_INTMIT, 3, sc->sc_ofdm_weak_det, NULL);
81 +
82 +done:
83 + return ret;
84 +}
85 +
86 /*
87 * Context: process context
88 */
89 @@ -2491,8 +2521,7 @@
90 if (sc->sc_softled)
91 ath_hal_gpioCfgOutput(ah, sc->sc_ledpin);
92
93 - if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit)
94 - ath_hal_setintmit(ah, 0);
95 + ath_setintmit(sc);
96
97 /*
98 * This is needed only to setup initial state
99 @@ -2528,7 +2557,7 @@
100 * Enable MIB interrupts when there are hardware phy counters.
101 * Note we only do this (at the moment) for station mode.
102 */
103 - if (sc->sc_needmib)
104 + if (sc->sc_needmib && ath_hal_getintmit(ah, NULL))
105 sc->sc_imask |= HAL_INT_MIB;
106 ath_hal_intrset(ah, sc->sc_imask);
107
108 @@ -2785,9 +2814,7 @@
109 EPRINTF(sc, "Unable to reset hardware: '%s' (HAL status %u)\n",
110 ath_get_hal_status_desc(status), status);
111
112 - if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit)
113 - ath_hal_setintmit(ah, 0);
114 -
115 + ath_setintmit(sc);
116 ath_update_txpow(sc); /* update tx power state */
117 ath_radar_update(sc);
118 ath_setdefantenna(sc, sc->sc_defant);
119 @@ -4165,6 +4192,8 @@
120 if (sc->sc_nmonvaps > 0)
121 rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
122 HAL_RX_FILTER_PROBEREQ | HAL_RX_FILTER_PROM);
123 + if (sc->sc_hasintmit && !sc->sc_needmib && ath_hal_getintmit(ah, NULL))
124 + rfilt |= HAL_RX_FILTER_PHYERR;
125 if (sc->sc_curchan.privFlags & CHANNEL_DFS)
126 rfilt |= (HAL_RX_FILTER_PHYERR | HAL_RX_FILTER_PHYRADAR);
127 return rfilt;
128 @@ -6513,9 +6542,6 @@
129 rs->rs_rssi = 0;
130
131 len = rs->rs_datalen;
132 - /* DMA sync. dies spectacularly if len == 0 */
133 - if (len == 0)
134 - goto rx_next;
135
136 if (rs->rs_more) {
137 /*
138 @@ -8865,9 +8891,7 @@
139 if (sc->sc_softled)
140 ath_hal_gpioCfgOutput(ah, sc->sc_ledpin);
141
142 - if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit)
143 - ath_hal_setintmit(ah, 0);
144 -
145 + ath_setintmit(sc);
146 sc->sc_curchan = hchan;
147 ath_update_txpow(sc); /* update tx power state */
148 ath_radar_update(sc);
149 @@ -10644,9 +10668,54 @@
150 ATH_RP_IGNORED = 24,
151 ATH_RADAR_IGNORED = 25,
152 ATH_MAXVAPS = 26,
153 + ATH_INTMIT = 27,
154 + ATH_NOISE_IMMUNITY = 28,
155 + ATH_OFDM_WEAK_DET = 29
156 };
157
158 static int
159 +ath_sysctl_set_intmit(struct ath_softc *sc, long ctl, u_int val)
160 +{
161 + int ret;
162 +
163 + switch(ctl) {
164 + case ATH_INTMIT:
165 + sc->sc_intmit = val;
166 + break;
167 + case ATH_NOISE_IMMUNITY:
168 + sc->sc_noise_immunity = val;
169 + break;
170 + case ATH_OFDM_WEAK_DET:
171 + sc->sc_ofdm_weak_det = val;
172 + break;
173 + default:
174 + return -EINVAL;
175 + }
176 + ret = ath_setintmit(sc);
177 + ath_calcrxfilter(sc);
178 + return ret;
179 +}
180 +
181 +static int
182 +ath_sysctl_get_intmit(struct ath_softc *sc, long ctl, u_int *val)
183 +{
184 + struct ath_hal *ah = sc->sc_ah;
185 +
186 + switch(ctl) {
187 + case ATH_INTMIT:
188 + *val = (ath_hal_getcapability(ah, HAL_CAP_INTMIT, 1, NULL) == HAL_OK);
189 + break;
190 + case ATH_NOISE_IMMUNITY:
191 + return ath_hal_getcapability(ah, HAL_CAP_INTMIT, 2, val);
192 + case ATH_OFDM_WEAK_DET:
193 + return ath_hal_getcapability(ah, HAL_CAP_INTMIT, 3, val);
194 + default:
195 + return -EINVAL;
196 + }
197 + return 0;
198 +}
199 +
200 +static int
201 ATH_SYSCTL_DECL(ath_sysctl_halparam, ctl, write, filp, buffer, lenp, ppos)
202 {
203 struct ath_softc *sc = ctl->extra1;
204 @@ -10832,6 +10901,11 @@
205 case ATH_RADAR_IGNORED:
206 sc->sc_radar_ignored = val;
207 break;
208 + case ATH_INTMIT:
209 + case ATH_NOISE_IMMUNITY:
210 + case ATH_OFDM_WEAK_DET:
211 + ret = ath_sysctl_set_intmit(sc, (long)ctl->extra2, val);
212 + break;
213 default:
214 ret = -EINVAL;
215 break;
216 @@ -10898,6 +10972,11 @@
217 case ATH_RADAR_IGNORED:
218 val = sc->sc_radar_ignored;
219 break;
220 + case ATH_INTMIT:
221 + case ATH_NOISE_IMMUNITY:
222 + case ATH_OFDM_WEAK_DET:
223 + ret = ath_sysctl_get_intmit(sc, (long)ctl->extra2, &val);
224 + break;
225 default:
226 ret = -EINVAL;
227 break;
228 @@ -11075,6 +11154,24 @@
229 .proc_handler = ath_sysctl_halparam,
230 .extra2 = (void *)ATH_RADAR_IGNORED,
231 },
232 + { .ctl_name = CTL_AUTO,
233 + .procname = "intmit",
234 + .mode = 0644,
235 + .proc_handler = ath_sysctl_halparam,
236 + .extra2 = (void *)ATH_INTMIT,
237 + },
238 + { .ctl_name = CTL_AUTO,
239 + .procname = "noise_immunity",
240 + .mode = 0644,
241 + .proc_handler = ath_sysctl_halparam,
242 + .extra2 = (void *)ATH_NOISE_IMMUNITY,
243 + },
244 + { .ctl_name = CTL_AUTO,
245 + .procname = "ofdm_weak_det",
246 + .mode = 0644,
247 + .proc_handler = ath_sysctl_halparam,
248 + .extra2 = (void *)ATH_OFDM_WEAK_DET,
249 + },
250 { 0 }
251 };
252
253 Index: madwifi-trunk-r3314/ath/if_athvar.h
254 ===================================================================
255 --- madwifi-trunk-r3314.orig/ath/if_athvar.h 2008-06-13 09:28:25.000000000 +0200
256 +++ madwifi-trunk-r3314/ath/if_athvar.h 2008-06-13 09:29:00.000000000 +0200
257 @@ -693,6 +693,10 @@
258 unsigned int sc_txcont_power; /* Continuous transmit power in 0.5dBm units */
259 unsigned int sc_txcont_rate; /* Continuous transmit rate in Mbps */
260
261 + int8_t sc_intmit; /* Interference mitigation enabled, -1 = auto, based on mode, 0/1 = off/on */
262 + int8_t sc_noise_immunity; /* Noise immunity level, 0-4, -1 == auto) */
263 + int8_t sc_ofdm_weak_det; /* OFDM weak frames detection, -1 == auto */
264 +
265 /* rate tables */
266 const HAL_RATE_TABLE *sc_rates[IEEE80211_MODE_MAX];
267 const HAL_RATE_TABLE *sc_currates; /* current rate table */
268 Index: madwifi-trunk-r3314/ath/if_ath_hal.h
269 ===================================================================
270 --- madwifi-trunk-r3314.orig/ath/if_ath_hal.h 2008-06-13 09:28:25.000000000 +0200
271 +++ madwifi-trunk-r3314/ath/if_ath_hal.h 2008-06-13 09:29:00.000000000 +0200
272 @@ -67,14 +67,14 @@
273
274 static inline HAL_BOOL ath_hal_getdiagstate(struct ath_hal *ah, int request,
275 const void *args, u_int32_t argsize,
276 - void **result,
277 + void *result,
278 u_int32_t *resultsize)
279 {
280 HAL_BOOL ret;
281 ATH_HAL_LOCK_IRQ(ah->ah_sc);
282 ath_hal_set_function(__func__);
283 ret =
284 - ah->ah_getDiagState(ah, request, args, argsize, *result,
285 + ah->ah_getDiagState(ah, request, args, argsize, result,
286 resultsize);
287 ath_hal_set_function(NULL);
288 ATH_HAL_UNLOCK_IRQ(ah->ah_sc);