madwifi: move autochannel idletime decision after radar and phy mode checking
[openwrt.git] / package / madwifi / patches / 330-beaconcal.patch
1 --- a/ath/if_ath.c
2 +++ b/ath/if_ath.c
3 @@ -397,6 +397,7 @@ static int countrycode = -1;
4  static int maxvaps = -1;
5  static int outdoor = -1;
6  static int xchanmode = -1;
7 +static int beacon_cal = 1;
8  
9  static const char *hal_status_desc[] = {
10         "No error",
11 @@ -422,6 +423,7 @@ static struct notifier_block ath_event_b
12  };
13  
14  #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,52))
15 +MODULE_PARM(beacon_cal, "i");
16  MODULE_PARM(countrycode, "i");
17  MODULE_PARM(maxvaps, "i");
18  MODULE_PARM(outdoor, "i");
19 @@ -434,6 +436,7 @@ MODULE_PARM(autocreate, "s");
20  MODULE_PARM(ratectl, "s");
21  #else
22  #include <linux/moduleparam.h>
23 +module_param(beacon_cal, int, 0600);
24  module_param(countrycode, int, 0600);
25  module_param(maxvaps, int, 0600);
26  module_param(outdoor, int, 0600);
27 @@ -2600,7 +2603,8 @@ ath_stop_locked(struct net_device *dev)
28                 }
29                 if (!sc->sc_invalid) {
30                         del_timer_sync(&sc->sc_dfs_cac_timer);
31 -                       del_timer_sync(&sc->sc_cal_ch);
32 +                       if (!sc->sc_beacon_cal)
33 +                               del_timer_sync(&sc->sc_cal_ch);
34                 }
35                 ath_draintxq(sc);
36                 if (!sc->sc_invalid) {
37 @@ -2617,6 +2621,20 @@ ath_stop_locked(struct net_device *dev)
38         return 0;
39  }
40  
41 +static void ath_set_beacon_cal(struct ath_softc *sc, int val)
42 +{
43 +       if (sc->sc_beacon_cal == !!val)
44 +               return;
45 +
46 +       if (val) {
47 +               del_timer_sync(&sc->sc_cal_ch);
48 +       } else {
49 +               sc->sc_cal_ch.expires = jiffies + (ath_calinterval * HZ);
50 +               add_timer(&sc->sc_cal_ch);
51 +       }
52 +       sc->sc_beacon_cal = !!val && beacon_cal;
53 +}
54 +
55  /*
56   * Stop the device, grabbing the top-level lock to protect
57   * against concurrent entry through ath_init (which can happen
58 @@ -2742,6 +2760,12 @@ ath_reset(struct net_device *dev)
59         HAL_STATUS status;
60  
61         /*
62 +        * XXX: starting the calibration too early seems to lead to
63 +        * problems with the beacons.
64 +        */
65 +       sc->sc_lastcal = jiffies;
66 +
67 +       /*
68          * Convert to a HAL channel description with the flags
69          * constrained to reflect the current operating mode.
70          */
71 @@ -5154,6 +5178,8 @@ ath_beacon_send(struct ath_softc *sc, in
72                         "Invoking ath_hal_txstart with sc_bhalq: %d\n",
73                         sc->sc_bhalq);
74                 ath_hal_txstart(ah, sc->sc_bhalq);
75 +               if (sc->sc_beacon_cal && (jiffies > sc->sc_lastcal + (ath_calinterval * HZ)))
76 +                       ath_calibrate((unsigned long) sc->sc_dev);
77  
78                 sc->sc_stats.ast_be_xmit++;             /* XXX per-VAP? */
79         }
80 @@ -5403,6 +5429,7 @@ ath_beacon_config(struct ath_softc *sc, 
81                 ath_hal_beacontimers(ah, &bs);
82                 sc->sc_imask |= HAL_INT_BMISS;
83                 ath_hal_intrset(ah, sc->sc_imask);
84 +               ath_set_beacon_cal(sc, 0);
85         } else {
86                 ath_hal_intrset(ah, 0);
87                 if (reset_tsf)
88 @@ -5414,8 +5441,11 @@ ath_beacon_config(struct ath_softc *sc, 
89                          */
90                         intval |= HAL_BEACON_ENA;
91                         sc->sc_imask |= HAL_INT_SWBA;
92 +                       ath_set_beacon_cal(sc, 1);
93                         ath_beaconq_config(sc);
94 -               }
95 +               } else
96 +                       ath_set_beacon_cal(sc, 0);
97 +
98  #ifdef ATH_SUPERG_DYNTURBO
99                 ath_beacon_dturbo_config(vap, intval &
100                                 ~(HAL_BEACON_RESET_TSF | HAL_BEACON_ENA));
101 @@ -8879,6 +8909,9 @@ ath_chan_set(struct ath_softc *sc, struc
102                         /* Enter DFS wait period */
103                         mod_timer(&sc->sc_dfs_cac_timer,
104                                 jiffies + (sc->sc_dfs_cac_period * HZ));
105 +
106 +                       /* This is a good time to start a calibration */
107 +                       ath_set_beacon_cal(sc, 1);
108                 }
109                 /*
110                  * re configure beacons when it is a turbo mode switch.
111 @@ -8988,8 +9021,11 @@ ath_calibrate(unsigned long arg)
112                 sc->sc_curchan.channel, sc->sc_curchan.channelFlags,
113                 isIQdone ? "done" : "not done");
114  
115 -       sc->sc_cal_ch.expires = jiffies + (ath_calinterval * HZ);
116 -       add_timer(&sc->sc_cal_ch);
117 +       sc->sc_lastcal = jiffies;
118 +       if (!sc->sc_beacon_cal) {
119 +               sc->sc_cal_ch.expires = jiffies + (ath_calinterval * HZ);
120 +               add_timer(&sc->sc_cal_ch);
121 +       }
122  }
123  
124  static void
125 @@ -9096,7 +9132,8 @@ ath_newstate(struct ieee80211vap *vap, e
126                 ieee80211_state_name[vap->iv_state],
127                 ieee80211_state_name[nstate]);
128  
129 -       del_timer(&sc->sc_cal_ch);              /* periodic calibration timer */
130 +       if (!sc->sc_beacon_cal)
131 +               del_timer(&sc->sc_cal_ch);              /* periodic calibration timer */
132  
133         ath_hal_setledstate(ah, leds[nstate]);  /* set LED */
134         netif_stop_queue(dev);                  /* before we do anything else */
135 @@ -9321,7 +9358,8 @@ ath_newstate(struct ieee80211vap *vap, e
136                                 "VAP -> DFSWAIT_PENDING \n");
137                         /* start calibration timer with a really small value 
138                          * 1/10 sec */
139 -                       mod_timer(&sc->sc_cal_ch, jiffies + (HZ/10));
140 +                       if (!sc->sc_beacon_cal)
141 +                               mod_timer(&sc->sc_cal_ch, jiffies + (HZ/10));
142                         /* wake the receiver */
143                         netif_wake_queue(dev);
144                         /* don't do the other usual stuff... */
145 @@ -9364,7 +9402,7 @@ done:
146         error = avp->av_newstate(vap, nstate, arg);
147  
148         /* Finally, start any timers. */
149 -       if (nstate == IEEE80211_S_RUN) {
150 +       if (nstate == IEEE80211_S_RUN && !sc->sc_beacon_cal) {
151                 /* start periodic recalibration timer */
152                 mod_timer(&sc->sc_cal_ch, jiffies + (ath_calinterval * HZ));
153         }
154 --- a/ath/if_athvar.h
155 +++ b/ath/if_athvar.h
156 @@ -778,6 +778,8 @@ struct ath_softc {
157         struct ieee80211vap **sc_bslot;         /* beacon xmit slots */
158         int sc_bnext;                           /* next slot for beacon xmit */
159  
160 +       int sc_beacon_cal;                      /* use beacon timer for calibration */
161 +       u_int64_t sc_lastcal;                   /* last time the calibration was performed */
162         struct timer_list sc_cal_ch;            /* calibration timer */
163         HAL_NODE_STATS sc_halstats;             /* station-mode rssi stats */
164