3 @@ -384,6 +384,7 @@ static u_int32_t ath_get_real_maxtxpower
5 static void ath_poll_disable(struct net_device *dev);
6 static void ath_poll_enable(struct net_device *dev);
7 +static void ath_fetch_idle_time(struct ath_softc *sc);
9 /* calibrate every 30 secs in steady state but check every second at first. */
10 static int ath_calinterval = ATH_SHORT_CALINTERVAL;
11 @@ -2580,6 +2581,7 @@ ath_init(struct net_device *dev)
12 * be followed by initialization of the appropriate bits
13 * and then setup of the interrupt mask.
15 + ath_fetch_idle_time(sc);
16 sc->sc_curchan.channel = ic->ic_curchan->ic_freq;
17 sc->sc_curchan.channelFlags = ath_chan2flags(ic->ic_curchan);
18 if (!ath_hal_reset(ah, sc->sc_opmode, &sc->sc_curchan, AH_FALSE, &status)) {
19 @@ -2913,6 +2915,48 @@ ath_hw_check_atim(struct ath_softc *sc,
23 +#define AR5K_MIBC 0x0040
24 +#define AR5K_MIBC_FREEZE (1 << 1)
25 +#define AR5K_TXFC 0x80ec
26 +#define AR5K_RXFC 0x80f0
27 +#define AR5K_RXCLEAR 0x80f4
28 +#define AR5K_CYCLES 0x80f8
30 +ath_fetch_idle_time(struct ath_softc *sc)
32 + struct ieee80211com *ic = &sc->sc_ic;
33 + struct ath_hal *ah = sc->sc_ah;
37 + if (sc->sc_ah->ah_macType < 5212)
40 + if (!ic->ic_curchan || (ic->ic_curchan == IEEE80211_CHAN_ANYC))
43 + OS_REG_WRITE(ah, AR5K_MIBC, AR5K_MIBC_FREEZE);
44 + rx = OS_REG_READ(ah, AR5K_RXCLEAR);
45 + cc = OS_REG_READ(ah, AR5K_CYCLES);
51 + return; /* should not happen */
53 + if (sc->sc_last_chan)
54 + sc->sc_last_chan->ic_idletime = 100 * (cc - rx) / cc;
55 + sc->sc_last_chan = ic->ic_curchan;
57 + OS_REG_WRITE(ah, AR5K_RXCLEAR, 0);
58 + OS_REG_WRITE(ah, AR5K_CYCLES, 0);
59 + OS_REG_WRITE(ah, AR5K_TXFC, 0);
60 + OS_REG_WRITE(ah, AR5K_RXFC, 0);
61 + OS_REG_WRITE(ah, AR5K_MIBC, 0);
67 * Reset the hardware w/o losing operational state. This is
68 @@ -2940,6 +2984,7 @@ ath_reset(struct net_device *dev)
69 * Convert to a HAL channel description with the flags
70 * constrained to reflect the current operating mode.
72 + ath_fetch_idle_time(sc);
74 sc->sc_curchan.channel = c->ic_freq;
75 sc->sc_curchan.channelFlags = ath_chan2flags(c);
76 @@ -9022,6 +9067,7 @@ ath_chan_set(struct ath_softc *sc, struc
77 u_int8_t channel_change_required = 0;
82 * Convert to a HAL channel description with
83 * the flags constrained to reflect the current
84 @@ -9030,6 +9076,14 @@ ath_chan_set(struct ath_softc *sc, struc
85 memset(&hchan, 0, sizeof(HAL_CHANNEL));
86 hchan.channel = chan->ic_freq;
87 hchan.channelFlags = ath_chan2flags(chan);
89 + /* don't do duplicate channel changes, but do
90 + * store the available idle time */
91 + ath_fetch_idle_time(sc);
92 + if ((sc->sc_curchan.channel == hchan.channel) &&
93 + (sc->sc_curchan.channelFlags == hchan.channelFlags))
96 KASSERT(hchan.channel != 0,
97 ("bogus channel %u/0x%x", hchan.channel, hchan.channelFlags));
100 +++ b/ath/if_athvar.h
101 @@ -773,6 +773,7 @@ struct ath_softc {
102 struct ieee80211vap **sc_bslot; /* beacon xmit slots */
103 int sc_bnext; /* next slot for beacon xmit */
105 + struct ieee80211_channel *sc_last_chan;
106 int sc_beacon_cal; /* use beacon timer for calibration */
107 u_int64_t sc_lastcal; /* last time the calibration was performed */
108 struct timer_list sc_cal_ch; /* calibration timer */
109 --- a/net80211/_ieee80211.h
110 +++ b/net80211/_ieee80211.h
111 @@ -148,6 +148,7 @@ struct ieee80211_channel {
112 int8_t ic_maxpower; /* maximum tx power in dBm */
113 int8_t ic_minpower; /* minimum tx power in dBm */
114 u_int8_t ic_scanflags;
115 + u_int8_t ic_idletime; /* phy idle time in % */
118 #define IEEE80211_CHAN_MAX 255
119 --- a/net80211/ieee80211_scan_ap.c
120 +++ b/net80211/ieee80211_scan_ap.c
121 @@ -417,6 +417,19 @@ pc_cmp_rssi(struct ap_state *as, struct
123 /* This function must be invoked with locks acquired */
125 +pc_cmp_idletime(struct ieee80211_channel *a,
126 + struct ieee80211_channel *b)
128 + if (!a->ic_idletime || !b->ic_idletime)
131 + /* a is better than b (return < 0) when a has more idle time than b */
132 + return b->ic_idletime - a->ic_idletime;
136 +/* This function must be invoked with locks acquired */
138 pc_cmp_samechan(struct ieee80211com *ic, struct ieee80211_channel *a,
139 struct ieee80211_channel *b)
141 @@ -451,6 +464,7 @@ pc_cmp(const void *_a, const void *_b)
143 EVALUATE_CRITERION(radar, a, b);
144 EVALUATE_CRITERION(keepmode, params, a, b);
145 + EVALUATE_CRITERION(idletime, a, b);
146 EVALUATE_CRITERION(sc, ic, a, b);
147 /* XXX: rssi useless? pick_channel evaluates it anyway */
148 EVALUATE_CRITERION(rssi, params->ss->ss_priv, a, b);
149 @@ -519,16 +533,9 @@ pick_channel(struct ieee80211_scan_state
153 - best_rssi = 0xff; /* If signal is bigger than 0xff, we'd be melting. */
155 for (i = 0; i < ss_last; i++) {
157 - benefit = best_rssi - as->as_maxrssi[c->chan->ic_ieee];
158 - sta_assoc = ic->ic_sta_assoc;
160 - /* Don't switch... */
164 /* Verify channel is not marked for non-occupancy */
165 if (IEEE80211_IS_CHAN_RADAR(c->chan))
166 @@ -546,31 +553,8 @@ pick_channel(struct ieee80211_scan_state
170 - if (sta_assoc != 0) {
171 - int sl = ic->ic_cn_total -
172 - ic->ic_chan_nodes[c->chan->ic_ieee]; /* count */
173 - if (ic->ic_sc_algorithm == IEEE80211_SC_LOOSE) {
174 - int sl_max = ic->ic_sc_sldg * benefit;
175 - sl = 1000 * sl / sta_assoc; /* permil */
176 - IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
177 - "%s: chan %d, dB gained: %d, "
178 - "STAs lost: %d permil (max %d)\n",
179 - __func__, c->chan->ic_ieee,
180 - benefit, sl, sl_max);
183 - } else if (((ic->ic_sc_algorithm ==
184 - IEEE80211_SC_TIGHT) ||
185 - (ic->ic_sc_algorithm ==
186 - IEEE80211_SC_STRICT)) &&
188 - /* Break the loop as the subsequent chans
189 - * won't be better. */
194 - best_rssi = as->as_maxrssi[best->ic_ieee];
199 @@ -599,6 +583,9 @@ ap_end(struct ieee80211_scan_state *ss,
200 ("wrong opmode %u", vap->iv_opmode));
204 + /* record stats for the channel that was scanned last */
205 + ic->ic_set_channel(ic);
206 bestchan = pick_channel(ss, vap, flags);
207 if (bestchan == NULL) {
208 if (ss->ss_last > 0) {
209 --- a/net80211/ieee80211_scan.c
210 +++ b/net80211/ieee80211_scan.c
211 @@ -1002,20 +1002,33 @@ ieee80211_scan_add_channels(struct ieee8
213 struct ieee80211_channel *c, *cg;
215 + int has_non_turbo = 0;
218 KASSERT(mode < ARRAY_SIZE(chanflags), ("Unexpected mode %u", mode));
219 modeflags = chanflags[mode];
220 for (i = 0; i < ic->ic_nchans; i++) {
221 + if (c->ic_flags & (IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO))
227 + for (i = 0; i < ic->ic_nchans; i++) {
228 c = &ic->ic_channels[i];
229 if (c == NULL || isclr(ic->ic_chan_active, c->ic_ieee))
231 if (c->ic_scanflags & IEEE80211_NOSCAN_SET)
234 - ((c->ic_flags & IEEE80211_CHAN_ALLTURBO) !=
235 - (modeflags & IEEE80211_CHAN_ALLTURBO)))
238 + if ((c->ic_flags & IEEE80211_CHAN_ALLTURBO) !=
239 + (modeflags & IEEE80211_CHAN_ALLTURBO))
241 + } else if (has_non_turbo) {
242 + if ((ss->ss_vap->iv_opmode == IEEE80211_M_HOSTAP) &&
243 + (c->ic_flags & (IEEE80211_CHAN_TURBO | IEEE80211_CHAN_STURBO)))
246 if (mode == IEEE80211_MODE_AUTO) {
248 * XXX special-case 11b/g channels so we select