huge madwifi update (work in progress, disabled by default, compiles but breaks at...
[librecmc/librecmc.git] / package / madwifi / patches-r3776 / 316-ani_fix.patch
1 Index: madwifi-trunk-r3776/ath/if_ath.c
2 ===================================================================
3 --- madwifi-trunk-r3776.orig/ath/if_ath.c       2008-07-17 03:06:03.000000000 +0200
4 +++ madwifi-trunk-r3776/ath/if_ath.c    2008-07-17 03:53:09.000000000 +0200
5 @@ -343,6 +343,8 @@
6                 unsigned int param, unsigned int value);
7  
8  static u_int32_t ath_get_real_maxtxpower(struct ath_softc *sc);
9 +static int ath_setintmit(struct ath_softc *sc);
10 +static u_int32_t ath_calcrxfilter(struct ath_softc *sc);
11  
12  #ifdef AR_DEBUG
13  static int ath_txq_check(struct ath_softc *sc, struct ath_txq *txq, const char *msg);
14 @@ -356,7 +358,6 @@
15  static char *ratectl = DEF_RATE_CTL;
16  static int rfkill = 0;
17  static int hal_tpc = 0;
18 -static int intmit = 0;
19  static int countrycode = CTRY_DEFAULT;
20  static int maxvaps = ATH_MAXVAPS_DEFAULT;
21  static int outdoor = 0;
22 @@ -398,7 +399,6 @@
23  #endif
24  MODULE_PARM(autocreate, "s");
25  MODULE_PARM(ratectl, "s");
26 -MODULE_PARM(intmit, "i");
27  #else
28  #include <linux/moduleparam.h>
29  module_param(beacon_cal, int, 0600);
30 @@ -412,7 +412,6 @@
31  #endif
32  module_param(autocreate, charp, 0600);
33  module_param(ratectl, charp, 0600);
34 -module_param(intmit, int, 0600);
35  #endif
36  MODULE_PARM_DESC(countrycode, "Override default country code.  Default is 0.");
37  MODULE_PARM_DESC(maxvaps, "Maximum VAPs.  Default is 4.");
38 @@ -428,7 +427,6 @@
39                 "'none' to disable");
40  MODULE_PARM_DESC(ratectl, "Rate control algorithm [amrr|minstrel|onoe|sample], "
41                 "defaults to '" DEF_RATE_CTL "'");
42 -MODULE_PARM_DESC(intmit, "Enable interference mitigation by default.  Default is 0.");
43  
44  #ifdef AR_DEBUG
45  static int     ath_debug = 0;
46 @@ -585,23 +583,13 @@
47         if (ath_hal_hastxpowlimit(ah)) {
48                 ic->ic_caps |= IEEE80211_C_TXPMGT;
49         }
50 -       /* Interference mitigation/ambient noise immunity (ANI).
51 -        * In modes other than HAL_M_STA, it causes receive sensitivity
52 -        * problems for OFDM. */
53 +       /* Interference mitigation/ambient noise immunity (ANI). */
54         sc->sc_hasintmit = ath_hal_hasintmit(ah);
55 -       sc->sc_useintmit = (intmit && sc->sc_hasintmit);
56 -       if (!sc->sc_hasintmit && intmit) {
57 -               WPRINTF(sc, "Interference mitigation was requested, but is not"
58 -                               "supported by the HAL/hardware.\n");
59 -               intmit = 0; /* Stop use in future ath_attach(). */
60 -       }
61 -       else {
62 -               ath_hal_setintmit(ah, sc->sc_useintmit);
63 -               DPRINTF(sc, ATH_DEBUG_ANY, "Interference mitigation is "
64 -                       "supported.  Currently %s.\n",
65 -                       (sc->sc_useintmit ? "enabled" : "disabled"));
66 -       }
67  
68 +       /* auto, mode dependent */
69 +       sc->sc_useintmit = -1;
70 +       sc->sc_noise_immunity = -1;
71 +       sc->sc_ofdm_weak_det = -1;
72         sc->sc_dmasize_stomp = 0;
73  
74         /*
75 @@ -614,15 +602,6 @@
76         sc->sc_mrretry = ath_hal_setupxtxdesc(ah, NULL, 0,0, 0,0, 0,0);
77  
78         /*
79 -        * Check if the device has hardware counters for PHY
80 -        * errors.  If so we need to enable the MIB interrupt
81 -        * so we can act on stat triggers.
82 -        */
83 -       sc->sc_needmib = ath_hal_hwphycounters(ah) && 
84 -               sc->sc_hasintmit && 
85 -               sc->sc_useintmit;
86 -
87 -       /*
88          * Get the hardware key cache size.
89          */
90         sc->sc_keymax = ath_hal_keycachesize(ah);
91 @@ -1593,37 +1572,6 @@
92         ath_init(dev);
93  }
94  
95 -/* NB: Int. mit. was not implemented so that it could be enabled/disabled,
96 - * and actually in 0.9.30.13 HAL it really can't even be disabled because
97 - * it will start adjusting registers even when we turn off the capability
98 - * in the HAL.
99 - *
100 - * NB: This helper function basically clobbers all the related registers
101 - * if we have disabled int. mit. cap, allowing us to turn it on and off and
102 - * work around the bug preventing it from being disabled. */
103 -static inline void ath_override_intmit_if_disabled(struct ath_softc *sc) {
104 -       /* Restore int. mit. registers if they were turned off. */
105 -       if (sc->sc_hasintmit && !sc->sc_useintmit)
106 -               ath_hal_restore_default_intmit(sc->sc_ah);
107 -       /* Sanity check... remove later. */
108 -       if (!sc->sc_useintmit) {
109 -               ath_hal_verify_default_intmit(sc->sc_ah);
110 -               /* If we don't have int. mit. and we don't have DFS on channel,
111 -                * it is safe to filter error packets. */
112 -               if (!ath_radar_is_dfs_required(sc, &sc->sc_curchan)) {
113 -                       ath_hal_setrxfilter(sc->sc_ah,
114 -                               ath_hal_getrxfilter(sc->sc_ah) & 
115 -                               ~HAL_RX_FILTER_PHYERR);
116 -               }
117 -       }
118 -       else {
119 -               /* Make sure that we have errors in RX filter because ANI needs
120 -                * them. */
121 -               ath_hal_setrxfilter(sc->sc_ah, 
122 -                       ath_hal_getrxfilter(sc->sc_ah) | HAL_RX_FILTER_PHYERR);
123 -       }
124 -}
125 -
126  static HAL_BOOL ath_hw_reset(struct ath_softc *sc, HAL_OPMODE opmode,
127                 HAL_CHANNEL *channel, HAL_BOOL bChannelChange,
128                 HAL_STATUS *status)
129 @@ -1698,11 +1646,7 @@
130                 ath_hal_settpc(sc->sc_ah, hal_tpc);
131         }
132  #endif
133 -#if 0 /* Setting via HAL does not work, so it is done manually below. */
134 -       if (sc->sc_hasintmit)
135 -               ath_hal_setintmit(sc->sc_ah, sc->sc_useintmit);
136 -#endif
137 -       ath_override_intmit_if_disabled(sc);
138 +       ath_setintmit(sc);
139         if (sc->sc_dmasize_stomp)
140                 ath_hal_set_dmasize_pcie(sc->sc_ah);
141         if (sc->sc_softled)
142 @@ -2496,7 +2440,6 @@
143  
144                         /* Let the HAL handle the event. */
145                         ath_hal_mibevent(ah, &sc->sc_halstats);
146 -                       ath_override_intmit_if_disabled(sc);
147                 }
148         }
149         if (needmark)
150 @@ -2564,6 +2507,55 @@
151         return flags;
152  }
153  
154 +static int ath_setintmit(struct ath_softc *sc)
155 +{
156 +       struct ath_hal *ah = sc->sc_ah;
157 +       int ret;
158 +       int val;
159 +
160 +       if (!sc->sc_hasintmit)
161 +               return 0;
162 +
163 +       switch(sc->sc_useintmit) {
164 +               case 0: /* disabled */
165 +               case 1: /* enabled */
166 +                       val = sc->sc_useintmit;
167 +                       break;
168 +               default:
169 +                       if (sc->sc_opmode != IEEE80211_M_MONITOR)
170 +                               val = 1;
171 +                       else
172 +                               val = 0;
173 +                       break;
174 +       }
175 +       ret = ath_hal_setintmit(ah, val);
176 +       if (val)
177 +               goto done;
178 +
179 +       /* manual settings */
180 +       if ((sc->sc_noise_immunity >= 0) && (sc->sc_noise_immunity <= 5))
181 +               ath_hal_setcapability(ah, HAL_CAP_INTMIT, 2, sc->sc_noise_immunity, NULL);
182 +       if ((sc->sc_ofdm_weak_det == 0) || (sc->sc_ofdm_weak_det == 1))
183 +               ath_hal_setcapability(ah, HAL_CAP_INTMIT, 3, sc->sc_ofdm_weak_det, NULL);
184 +
185 +done:
186 +       if (!sc->sc_imask)
187 +               goto out;
188 +
189 +       /* MIB interrupt handling */
190 +       sc->sc_needmib = ath_hal_hwphycounters(ah) &&
191 +               sc->sc_useintmit;
192 +       if (sc->sc_needmib)
193 +               sc->sc_imask |= HAL_INT_MIB;
194 +       else
195 +               sc->sc_imask &= ~HAL_INT_MIB;
196 +       ath_hal_intrset(sc->sc_ah, sc->sc_imask);
197 +       ath_calcrxfilter(sc);
198 +
199 +out:
200 +       return ret;
201 +}
202 +
203  /*
204   * Context: process context
205   */
206 @@ -4248,8 +4240,7 @@
207         u_int32_t rfilt;
208  
209         /* Preserve the current Phy. radar and err. filters. */
210 -       rfilt = (ath_hal_getrxfilter(ah) &
211 -                       (HAL_RX_FILTER_PHYERR | HAL_RX_FILTER_PHYRADAR)) |
212 +       rfilt = (ath_hal_getrxfilter(ah) & HAL_RX_FILTER_PHYRADAR) |
213                  HAL_RX_FILTER_UCAST | HAL_RX_FILTER_BCAST |
214                  HAL_RX_FILTER_MCAST;
215         if (ic->ic_opmode != IEEE80211_M_STA)
216 @@ -4265,6 +4256,8 @@
217         if (sc->sc_nmonvaps > 0)
218                 rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
219                           HAL_RX_FILTER_PROBEREQ | HAL_RX_FILTER_PROM);
220 +       if (sc->sc_hasintmit && !sc->sc_needmib && ath_hal_getintmit(ah, NULL))
221 +               rfilt |= HAL_RX_FILTER_PHYERR;
222         if (sc->sc_curchan.privFlags & CHANNEL_DFS)
223                 rfilt |= (HAL_RX_FILTER_PHYERR | HAL_RX_FILTER_PHYRADAR);
224         return rfilt;
225 @@ -6809,8 +6802,7 @@
226         dev->quota -= bf_processed;
227  #endif
228  
229 -       if (sc->sc_useintmit) 
230 -               ath_hal_rxmonitor(ah, &sc->sc_halstats, &sc->sc_curchan);
231 +       ath_hal_rxmonitor(ah, &sc->sc_halstats, &sc->sc_curchan);
232         if (!bf_processed)
233                 DPRINTF(sc, ATH_DEBUG_RX_PROC,
234                         "Warning: %s got scheduled when no receive "
235 @@ -8726,7 +8718,6 @@
236         ath_hal_rxena(ah);              /* enable recv descriptors */
237         ath_mode_init(dev);             /* set filters, etc. */
238         ath_hal_startpcurecv(ah);       /* re-enable PCU/DMA engine */
239 -       ath_override_intmit_if_disabled(sc);
240         return 0;
241  }
242  
243 @@ -10632,8 +10623,10 @@
244         ATH_RP_IGNORED          = 24,
245         ATH_RADAR_IGNORED       = 25,
246         ATH_MAXVAPS             = 26,
247 -        ATH_INTMIT             = 27,
248 -       ATH_DISTANCE            = 28,
249 +       ATH_DISTANCE            = 27,
250 +       ATH_INTMIT                      = 28,
251 +       ATH_NOISE_IMMUNITY      = 29,
252 +       ATH_OFDM_WEAK_DET       = 30
253  };
254  
255  static inline int 
256 @@ -10695,6 +10688,48 @@
257  }
258  
259  static int
260 +ath_sysctl_set_intmit(struct ath_softc *sc, long ctl, u_int val)
261 +{
262 +       int ret;
263 +
264 +       switch(ctl) {
265 +       case ATH_INTMIT:
266 +               sc->sc_intmit = val;
267 +               break;
268 +       case ATH_NOISE_IMMUNITY:
269 +               sc->sc_noise_immunity = val;
270 +               break;
271 +       case ATH_OFDM_WEAK_DET:
272 +               sc->sc_ofdm_weak_det = val;
273 +               break;
274 +       default:
275 +               return -EINVAL;
276 +       }
277 +       ret = ath_setintmit(sc);
278 +       return ret;
279 +}
280 +
281 +static int
282 +ath_sysctl_get_intmit(struct ath_softc *sc, long ctl, u_int *val)
283 +{
284 +       struct ath_hal *ah = sc->sc_ah;
285 +
286 +       switch(ctl) {
287 +       case ATH_INTMIT:
288 +               *val = (ath_hal_getcapability(ah, HAL_CAP_INTMIT, 1, NULL) == HAL_OK);
289 +               break;
290 +       case ATH_NOISE_IMMUNITY:
291 +               return ath_hal_getcapability(ah, HAL_CAP_INTMIT, 2, val);
292 +       case ATH_OFDM_WEAK_DET:
293 +               return ath_hal_getcapability(ah, HAL_CAP_INTMIT, 3, val);
294 +       default:
295 +               return -EINVAL;
296 +       }
297 +       return 0;
298 +}
299 +
300 +
301 +static int
302  ATH_SYSCTL_DECL(ath_sysctl_halparam, ctl, write, filp, buffer, lenp, ppos)
303  {
304         struct ath_softc *sc = ctl->extra1;
305 @@ -10933,30 +10968,13 @@
306                                 sc->sc_radar_ignored = val;
307                                 break;
308                         case ATH_INTMIT:
309 -                               if (!sc->sc_hasintmit) {
310 +                       case ATH_NOISE_IMMUNITY:
311 +                       case ATH_OFDM_WEAK_DET:
312 +                               if (!sc->sc_hasintmit)
313                                         ret = -EOPNOTSUPP;
314 -                                       break;
315 -                               }
316 -                               if (sc->sc_useintmit == val)
317 -                                       break;
318 -                               sc->sc_useintmit = val; 
319 -                               sc->sc_needmib = ath_hal_hwphycounters(ah) && 
320 -                                       sc->sc_useintmit;
321 -                               /* Update the HAL and MIB interrupt mask bits */
322 -                               ath_hal_setintmit(ah, !!val); 
323 -                               sc->sc_imask = (sc->sc_imask & ~HAL_INT_MIB) | 
324 -                                       (sc->sc_needmib ? HAL_INT_MIB : 0);
325 -                               ath_hal_intrset(sc->sc_ah, sc->sc_imask);
326 -                               /* Only do a reset if device is valid and UP 
327 -                                * and we just made a change to the settings. */
328 -                               if (sc->sc_dev && !sc->sc_invalid &&
329 -                                   (sc->sc_dev->flags & IFF_RUNNING))
330 -                                       ath_reset(sc->sc_dev); 
331 -                               /* NB: Run this step to cleanup if HAL doesn't 
332 -                                * obey capability flags and hangs onto ANI
333 -                                * settings. */
334 -                               ath_override_intmit_if_disabled(sc);
335 -                                break; 
336 +                               else
337 +                                       ret = ath_sysctl_set_intmit(sc, (long)ctl->extra2, val);
338 +                               break;
339                         default:
340                                 ret = -EINVAL;
341                                 break;
342 @@ -11028,9 +11046,14 @@
343                 case ATH_RADAR_IGNORED:
344                         val = sc->sc_radar_ignored;
345                         break;
346 -                case ATH_INTMIT: 
347 -                       val = sc->sc_useintmit; 
348 -                       break; 
349 +               case ATH_INTMIT:
350 +               case ATH_NOISE_IMMUNITY:
351 +               case ATH_OFDM_WEAK_DET:
352 +                       if (!sc->sc_hasintmit)
353 +                               ret = -EOPNOTSUPP;
354 +                       else
355 +                               ret = ath_sysctl_get_intmit(sc, (long)ctl->extra2, &val);
356 +                       break;
357                 default:
358                         ret = -EINVAL;
359                         break;
360 @@ -11412,6 +11435,24 @@
361           .maxlen       = sizeof(ath_xchanmode),
362           .proc_handler = proc_dointvec
363         },
364 +       { .ctl_name     = CTL_AUTO,
365 +         .procname     = "intmit",
366 +         .mode         = 0644,
367 +         .proc_handler = ath_sysctl_halparam,
368 +         .extra2       = (void *)ATH_INTMIT,
369 +       },
370 +       { .ctl_name     = CTL_AUTO,
371 +         .procname     = "noise_immunity",
372 +         .mode         = 0644,
373 +         .proc_handler = ath_sysctl_halparam,
374 +         .extra2       = (void *)ATH_NOISE_IMMUNITY,
375 +       },
376 +       { .ctl_name     = CTL_AUTO,
377 +         .procname     = "ofdm_weak_det",
378 +         .mode         = 0644,
379 +         .proc_handler = ath_sysctl_halparam,
380 +         .extra2       = (void *)ATH_OFDM_WEAK_DET,
381 +       },
382         { 0 }
383  };
384  static ctl_table ath_ath_table[] = {
385 Index: madwifi-trunk-r3776/ath/if_athvar.h
386 ===================================================================
387 --- madwifi-trunk-r3776.orig/ath/if_athvar.h    2008-07-17 03:04:02.000000000 +0200
388 +++ madwifi-trunk-r3776/ath/if_athvar.h 2008-07-17 03:12:36.000000000 +0200
389 @@ -712,6 +712,10 @@
390         unsigned int sc_txcont_power; /* Continuous transmit power in 0.5dBm units */
391         unsigned int sc_txcont_rate;  /* Continuous transmit rate in Mbps */
392  
393 +       int8_t sc_intmit; /* Interference mitigation enabled, -1 = auto, based on mode, 0/1 = off/on */
394 +       int8_t sc_noise_immunity; /* Noise immunity level, 0-4, -1 == auto) */
395 +       int8_t sc_ofdm_weak_det; /* OFDM weak frames detection, -1 == auto */
396 +
397         /* rate tables */
398         const HAL_RATE_TABLE *sc_rates[IEEE80211_MODE_MAX];
399         const HAL_RATE_TABLE *sc_currates;      /* current rate table */
400 Index: madwifi-trunk-r3776/ath/if_ath_hal_extensions.h
401 ===================================================================
402 --- madwifi-trunk-r3776.orig/ath/if_ath_hal_extensions.h        2008-07-17 00:21:39.000000000 +0200
403 +++ madwifi-trunk-r3776/ath/if_ath_hal_extensions.h     2008-07-17 03:50:03.000000000 +0200
404 @@ -237,296 +237,18 @@
405         AR5K_DMASIZE_512B
406  };
407  
408 -
409 -int ath_set_ack_bitrate(struct ath_softc *sc, int);
410 -int ar_device(int devid);
411 -const char * ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val);
412 -
413 -static inline unsigned long field_width(unsigned long mask, unsigned long shift)
414 -{
415 -       unsigned long r = 0;
416 -       unsigned long x = mask >> shift;
417 -       if ( 0 == mask )  return  0;
418 -#if  BITS_PER_LONG >= 64
419 -       if ( x & (~0UL<<32) )  { x >>= 32;  r += 32; }
420 -#endif
421 -       if ( x & 0xffff0000 )  { x >>= 16;  r += 16; }
422 -       if ( x & 0x0000ff00 )  { x >>=  8;  r +=  8; }
423 -       if ( x & 0x000000f0 )  { x >>=  4;  r +=  4; }
424 -       if ( x & 0x0000000c )  { x >>=  2;  r +=  2; }
425 -       if ( x & 0x00000002 )  {            r +=  1; }
426 -       return r+1;
427 -}
428 -
429 -static inline u_int32_t get_field(struct ath_hal *ah, u_int32_t reg, u_int32_t mask, u_int32_t shift, int is_signed) {
430 -       unsigned long x = ((OS_REG_READ(ah, reg) & mask) >> shift);
431 -       if (is_signed) {
432 -               unsigned long c =(-1) << (field_width(mask, shift)-1);
433 -               return (x + c) ^ c;
434 -       }
435 -       return x;
436 -}
437 -
438  static inline void set_field(struct ath_hal *ah, u_int32_t reg, u_int32_t mask, u_int32_t shift, u_int32_t value) {
439         OS_REG_WRITE(ah, reg, 
440                           (OS_REG_READ(ah, reg) & ~mask) | 
441                           ((value << shift) & mask));
442  }
443  
444 -static inline u_int32_t field_eq(struct ath_hal *ah, u_int32_t reg, 
445 -                                u_int32_t mask, u_int32_t shift, 
446 -                                u_int32_t value, int is_signed) {
447 -       return  (get_field(ah, reg, mask, shift, is_signed) & (mask >> shift)) == 
448 -               (value & (mask >> shift));
449 -}
450 -
451 -static inline void override_warning(struct ath_hal *ah, const char *name,
452 -                                   u_int32_t reg, u_int32_t mask,
453 -                                   u_int32_t shift, u_int32_t expected, int is_signed) {
454 -
455 -       if (!field_eq(ah, reg, mask, shift, expected, is_signed)) 
456 -               printk("%s: Correcting 0x%04x[%s] from 0x%x (%d) to 0x%x (%d).\n", 
457 -                      SC_DEV_NAME(ah->ah_sc),
458 -                      reg,
459 -                      name, 
460 -                      (get_field(ah, reg, mask, shift, is_signed) & (mask >> shift)),
461 -                      get_field(ah, reg, mask, shift, is_signed), 
462 -                      (expected & (mask >> shift)), /* not sign extended */
463 -                      expected);
464 -#if 0 /* NB: For checking to see if HAL is fixed or not */
465 -       else {
466 -                       printk("%s: Keeping 0x%04x[%s] - 0x%x (%d).\n",
467 -                              SC_DEV_NAME(ah->ah_sc),
468 -                              reg,
469 -                              name, 
470 -                              (get_field(ah, reg, mask, shift, is_signed) & (mask >> shift)),
471 -                              get_field(ah, reg, mask, shift, is_signed));
472 -       }
473 -#endif
474 -}
475 -
476 -static inline void verification_warning(struct ath_hal *ah, const char *name,
477 -    u_int32_t reg, u_int32_t mask, 
478 -    u_int32_t shift, u_int32_t expected, int is_signed) {
479 -
480 -       int ret = field_eq(ah, reg, mask, shift, expected, is_signed);
481 -       if (!ret) {
482 -               printk("%s: %s verification of %s default value "
483 -                      "[found=0x%x (%d) expected=0x%x (%d)].\n", 
484 -                      SC_DEV_NAME(ah->ah_sc),
485 -                      (ret ? "PASSED" : "FAILED"),
486 -                       name, 
487 -                      (get_field(ah, reg, mask, shift, is_signed) & (mask >> shift)), 
488 -                      get_field(ah, reg, mask, shift, is_signed), 
489 -                      (expected & (mask >> shift)), /* not sign extended */
490 -                      expected);
491 -               ath_hal_print_decoded_register(ah, NULL, reg, 
492 -                                              OS_REG_READ(ah, reg), OS_REG_READ(ah, reg), 0);
493 -       }
494 -}
495 -
496 -#define GET_FIELD(ah, __reg, __mask, __signed) \
497 -       get_field(ah, __reg, __mask, __mask ## _S, __signed)
498  #define SET_FIELD(ah, __reg, __mask, __value) \
499         set_field(ah, __reg, __mask, __mask ## _S, __value);
500 -#define FIELD_EQ(ah, __reg, __mask, __value, __signed) \
501 -       field_eq(ah, __reg, __mask, __mask ## _S, __value, __signed)
502 -
503 -#if 0 /* NB: These are working at this point, and HAL tweaks them a lot */
504 -#define OVERRIDE_WARNING(ah, __reg, __mask, __expected, __signed) \
505 -       override_warning(ah, #__mask, __reg, __mask, __mask ## _S, __expected, __signed)
506 -#else
507 -#define OVERRIDE_WARNING(ah, __reg, __mask, __expected, __signed) 
508 -#endif
509 -       
510 -#define VERIFICATION_WARNING(ah, __reg, __mask, __signed) \
511 -       verification_warning(ah, #__mask, __reg, __mask, __mask ## _S, DEFAULT_ ## __mask, __signed)
512 -#define VERIFICATION_WARNING_SW(ah, __reg, __mask, __signed) \
513 -       verification_warning(ah, #__mask, __reg, __mask, __mask ## _S, DEFAULT_ENABLE_ ## __reg ? __mask ## _ON : __mask ## _OFF, __signed)
514 -
515 -static inline void ath_hal_set_noise_immunity(struct ath_hal *ah,
516 -                                             int agc_desired_size, 
517 -                                             int agc_coarse_hi,
518 -                                             int agc_coarse_lo, 
519 -                                             int sig_firpwr) 
520 -{
521 -       ATH_HAL_LOCK_IRQ(ah->ah_sc);
522 -       ath_hal_set_function(__func__);
523 -       ath_hal_set_device(SC_DEV_NAME(ah->ah_sc));
524 -
525 -#if 0 /* NB: These are working at this point, and HAL tweaks them a lot */
526 -       OVERRIDE_WARNING(ah, AR5K_PHY_AGCSIZE, AR5K_PHY_AGCSIZE_DESIRED, agc_desired_size, 1);
527 -       OVERRIDE_WARNING(ah, AR5K_PHY_AGCCOARSE, AR5K_PHY_AGCCOARSE_LO, agc_coarse_lo, 1);
528 -       OVERRIDE_WARNING(ah, AR5K_PHY_AGCCOARSE, AR5K_PHY_AGCCOARSE_HI, agc_coarse_hi, 1);
529 -       OVERRIDE_WARNING(ah, AR5K_PHY_SIG, AR5K_PHY_SIG_FIRPWR, sig_firpwr, 1);
530 -#endif
531 -
532 -       SET_FIELD(ah, AR5K_PHY_AGCSIZE, AR5K_PHY_AGCSIZE_DESIRED, agc_desired_size);
533 -       SET_FIELD(ah, AR5K_PHY_AGCCOARSE, AR5K_PHY_AGCCOARSE_LO, agc_coarse_lo);
534 -       SET_FIELD(ah, AR5K_PHY_AGCCOARSE, AR5K_PHY_AGCCOARSE_HI, agc_coarse_hi);
535 -       SET_FIELD(ah, AR5K_PHY_SIG, AR5K_PHY_SIG_FIRPWR, sig_firpwr);
536 -
537 -       ath_hal_set_function(NULL);
538 -       ath_hal_set_device(NULL);
539 -       ATH_HAL_UNLOCK_IRQ(ah->ah_sc);
540 -}
541 -
542 -static inline void ath_hal_set_ofdm_weak_det(struct ath_hal *ah, 
543 -       int low_m1, int low_m2, int low_m2_count, int low_self_corr,
544 -       int high_m1, int high_m2, int high_m2_count)
545 -{
546 -       ATH_HAL_LOCK_IRQ(ah->ah_sc);
547 -       ath_hal_set_function(__func__);
548 -       ath_hal_set_device(SC_DEV_NAME(ah->ah_sc));
549 -
550 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M1, low_m1, 0);
551 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M2, low_m2, 0);
552 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M2_COUNT, low_m2_count, 0);
553 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_SELFCOR, low_self_corr, 0);
554 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M1, high_m1, 0);
555 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M2, high_m2, 0);
556 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M2_COUNT, high_m2_count, 0);
557 -
558 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M1, low_m1);
559 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M2, low_m2);
560 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M2_COUNT, low_m2_count);
561 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_SELFCOR, low_self_corr);
562 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M1, high_m1);
563 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M2, high_m2);
564 -       SET_FIELD(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M2_COUNT, high_m2_count);
565 -
566 -       ath_hal_set_function(NULL);
567 -       ath_hal_set_device(NULL);
568 -       ATH_HAL_UNLOCK_IRQ(ah->ah_sc);
569 -}
570 -
571 -static inline void ath_hal_set_cck_weak_det(struct ath_hal *ah, int thresh)
572 -{
573 -       ATH_HAL_LOCK_IRQ(ah->ah_sc);
574 -       ath_hal_set_function(__func__);
575 -       ath_hal_set_device(SC_DEV_NAME(ah->ah_sc));
576 -
577 -       OVERRIDE_WARNING(ah, AR5K_PHY_WEAK_CCK, AR5K_PHY_WEAK_CCK_THRESH, thresh, 0);
578 -
579 -       SET_FIELD(ah, AR5K_PHY_WEAK_CCK, AR5K_PHY_WEAK_CCK_THRESH, thresh);
580 -
581 -       ath_hal_set_function(NULL);
582 -       ath_hal_set_device(NULL);
583 -       ATH_HAL_UNLOCK_IRQ(ah->ah_sc);
584 -}
585 -
586 -static inline void ath_hal_set_sig_firstep(struct ath_hal *ah, int firstep)
587 -{
588 -       ATH_HAL_LOCK_IRQ(ah->ah_sc);
589 -       ath_hal_set_function(__func__);
590 -       ath_hal_set_device(SC_DEV_NAME(ah->ah_sc));
591  
592 -       OVERRIDE_WARNING(ah, AR5K_PHY_SIG, AR5K_PHY_SIG_FIRSTEP, firstep, 0);
593 -
594 -       SET_FIELD(ah, AR5K_PHY_SIG, AR5K_PHY_SIG_FIRSTEP, firstep);
595 -
596 -       ath_hal_set_function(NULL);
597 -       ath_hal_set_device(NULL);
598 -       ATH_HAL_UNLOCK_IRQ(ah->ah_sc);
599 -}
600 -
601 -static inline void ath_hal_set_spur_immunity(struct ath_hal *ah, int thresh)
602 -{
603 -       ATH_HAL_LOCK_IRQ(ah->ah_sc);
604 -       ath_hal_set_function(__func__);
605 -       ath_hal_set_device(SC_DEV_NAME(ah->ah_sc));
606 -
607 -       OVERRIDE_WARNING(ah, AR5K_PHY_SPUR, AR5K_PHY_SPUR_THRESH, thresh, 0);
608 -
609 -       SET_FIELD(ah, AR5K_PHY_SPUR, AR5K_PHY_SPUR_THRESH, thresh);
610 -
611 -       ath_hal_set_function(NULL);
612 -       ath_hal_set_device(NULL);
613 -       ATH_HAL_UNLOCK_IRQ(ah->ah_sc);
614 -}
615 -
616 -static inline void ath_hal_restore_default_noise_immunity(struct ath_hal *ah) {
617 -
618 -       ath_hal_set_noise_immunity(ah, 
619 -               DEFAULT_AR5K_PHY_AGCSIZE_DESIRED, 
620 -               DEFAULT_AR5K_PHY_AGCCOARSE_HI,
621 -               DEFAULT_AR5K_PHY_AGCCOARSE_LO,
622 -               DEFAULT_AR5K_PHY_SIG_FIRPWR);
623 -}
624 -
625 -static inline void ath_hal_enable_ofdm_weak_det(struct ath_hal *ah, int enable) {
626 -       if (enable)
627 -               ath_hal_set_ofdm_weak_det(ah, 
628 -                       AR5K_PHY_WEAK_OFDM_LOW_M1_ON,
629 -                       AR5K_PHY_WEAK_OFDM_LOW_M2_ON,
630 -                       AR5K_PHY_WEAK_OFDM_LOW_M2_COUNT_ON,
631 -                       AR5K_PHY_WEAK_OFDM_LOW_SELFCOR_ON,
632 -                       AR5K_PHY_WEAK_OFDM_HIGH_M1_ON,
633 -                       AR5K_PHY_WEAK_OFDM_HIGH_M2_ON,
634 -                       AR5K_PHY_WEAK_OFDM_HIGH_M2_COUNT_ON);
635 -       else
636 -               ath_hal_set_ofdm_weak_det(ah, 
637 -                       AR5K_PHY_WEAK_OFDM_LOW_M1_OFF,
638 -                       AR5K_PHY_WEAK_OFDM_LOW_M2_OFF,
639 -                       AR5K_PHY_WEAK_OFDM_LOW_M2_COUNT_OFF,
640 -                       AR5K_PHY_WEAK_OFDM_LOW_SELFCOR_OFF,
641 -                       AR5K_PHY_WEAK_OFDM_HIGH_M1_OFF,
642 -                       AR5K_PHY_WEAK_OFDM_HIGH_M2_OFF,
643 -                       AR5K_PHY_WEAK_OFDM_HIGH_M2_COUNT_OFF);
644 -}
645 -
646 -static inline void ath_hal_enable_cck_weak_det(struct ath_hal *ah, int enable) {
647 -       ath_hal_set_cck_weak_det(ah, enable 
648 -                                ? AR5K_PHY_WEAK_CCK_THRESH_ON 
649 -                                : AR5K_PHY_WEAK_CCK_THRESH_OFF);
650 -}
651 -
652 -static inline void ath_hal_restore_default_ofdm_weak_det(struct ath_hal *ah) {
653 -       ath_hal_enable_ofdm_weak_det(ah, DEFAULT_ENABLE_AR5K_PHY_WEAK_OFDM);
654 -}
655 -
656 -static inline void ath_hal_restore_default_cck_weak_det(struct ath_hal *ah) {
657 -       ath_hal_enable_cck_weak_det(ah, DEFAULT_ENABLE_AR5K_PHY_WEAK_CCK);
658 -}
659 -
660 -static inline void ath_hal_restore_default_sig_firstep(struct ath_hal *ah) {
661 -
662 -       ath_hal_set_sig_firstep(ah, 
663 -               DEFAULT_AR5K_PHY_SIG_FIRSTEP);
664 -}
665 -
666 -static inline void ath_hal_restore_default_spur_immunity(struct ath_hal *ah) {
667 -
668 -       ath_hal_set_spur_immunity(ah, 
669 -               DEFAULT_AR5K_PHY_SPUR_THRESH);
670 -}
671 -
672 -static inline void ath_hal_restore_default_intmit(struct ath_hal *ah) {
673 -       ath_hal_restore_default_noise_immunity(ah);
674 -       ath_hal_restore_default_ofdm_weak_det(ah);
675 -       ath_hal_restore_default_cck_weak_det(ah);
676 -       ath_hal_restore_default_sig_firstep(ah);
677 -       ath_hal_restore_default_spur_immunity(ah);
678 -
679 -}
680 -
681 -static inline void ath_hal_verify_default_intmit(struct ath_hal *ah) {
682 -       /* Just a list of all the fields above, for sanity checks... */
683 -       VERIFICATION_WARNING(ah, AR5K_PHY_AGCSIZE, AR5K_PHY_AGCSIZE_DESIRED, 1);
684 -       VERIFICATION_WARNING(ah, AR5K_PHY_AGCCOARSE, AR5K_PHY_AGCCOARSE_LO, 1);
685 -       VERIFICATION_WARNING(ah, AR5K_PHY_AGCCOARSE, AR5K_PHY_AGCCOARSE_HI, 1);
686 -       VERIFICATION_WARNING(ah, AR5K_PHY_SIG, AR5K_PHY_SIG_FIRPWR, 1);
687 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M1, 0);
688 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M2, 0);
689 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_M2_COUNT, 0);
690 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_LOW, AR5K_PHY_WEAK_OFDM_LOW_SELFCOR, 0);
691 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M1, 0);
692 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M2, 0);
693 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_OFDM_HIGH, AR5K_PHY_WEAK_OFDM_HIGH_M2_COUNT, 0);
694 -       VERIFICATION_WARNING_SW(ah, AR5K_PHY_WEAK_CCK, AR5K_PHY_WEAK_CCK_THRESH, 0);
695 -       VERIFICATION_WARNING(ah, AR5K_PHY_SIG, AR5K_PHY_SIG_FIRSTEP, 0);
696 -       VERIFICATION_WARNING(ah, AR5K_PHY_SPUR, AR5K_PHY_SPUR_THRESH, 0);
697 -}
698 +int ath_set_ack_bitrate(struct ath_softc *sc, int);
699 +int ar_device(int devid);
700 +const char * ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val);
701  
702  static inline void ath_hal_set_dmasize_pcie(struct ath_hal *ah) {
703         SET_FIELD(ah, AR5K_TXCFG, AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
704 Index: madwifi-trunk-r3776/ath/if_ath_hal.h
705 ===================================================================
706 --- madwifi-trunk-r3776.orig/ath/if_ath_hal.h   2008-07-17 00:53:20.000000000 +0200
707 +++ madwifi-trunk-r3776/ath/if_ath_hal.h        2008-07-17 03:41:25.000000000 +0200
708 @@ -79,7 +79,7 @@
709         ath_hal_set_function(__func__);
710         ath_hal_set_device(SC_DEV_NAME(ah->ah_sc));
711         ret =
712 -           ah->ah_getDiagState(ah, request, args, argsize, *result,
713 +           ah->ah_getDiagState(ah, request, args, argsize, result,
714                                 resultsize);
715         ath_hal_set_function(NULL);
716         ath_hal_set_device(NULL);
717 Index: madwifi-trunk-r3776/scripts/if_ath_hal_generator.pl
718 ===================================================================
719 --- madwifi-trunk-r3776.orig/scripts/if_ath_hal_generator.pl    2008-07-17 00:21:30.000000000 +0200
720 +++ madwifi-trunk-r3776/scripts/if_ath_hal_generator.pl 2008-07-17 03:46:30.000000000 +0200
721 @@ -145,7 +145,9 @@
722      "ah_waitForBeaconDone"        => "ath_hal_waitforbeacon",
723      "ah_writeAssocid"             => "ath_hal_setassocid",
724      "ah_clrMulticastFilterIndex"  => "ath_hal_clearmcastfilter",
725 -    "ah_detectCardPresent"        => "ath_hal_detectcardpresent"
726 +    "ah_detectCardPresent"        => "ath_hal_detectcardpresent",
727 +    "ah_setSifsTime"              => "ath_hal_setsifstime",
728 +    "ah_getSifsTime"              => "ath_hal_getsifstime"
729  );
730  
731  #
732 @@ -254,7 +256,7 @@
733  
734      foreach (@parameters) {
735          s/ \*/\* /;
736 -        /^((?:(?:const|struct|\*)\s*)*)([^\s]+\*?)\s*([^\s]*)\s*/;
737 +        /^((?:(?:const|struct|\*)\s*)*)([^\s]+\**)\s*([^\s]*)\s*/;
738          my $type = "$1$2";
739          my $name = "$3";
740          if ( 0 == length($name) ) {