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 @@ -2914,6 +2916,40 @@ ath_hw_check_atim(struct ath_softc *sc,
23 +#define AR5K_RXCLEAR 0x80f4
24 +#define AR5K_CYCLES 0x80f8
26 +ath_fetch_idle_time(struct ath_softc *sc)
28 + struct ieee80211com *ic = &sc->sc_ic;
29 + struct ath_hal *ah = sc->sc_ah;
33 + if (sc->sc_ah->ah_macType < 5212)
36 + if (!ic->ic_curchan || (ic->ic_curchan == IEEE80211_CHAN_ANYC))
39 + rx = OS_REG_READ(ah, AR5K_RXCLEAR);
40 + cc = OS_REG_READ(ah, AR5K_CYCLES);
45 + return; /* wraparound */
47 + if (sc->sc_last_chan)
48 + sc->sc_last_chan->ic_idletime = 100 * (cc - rx) / cc;
49 + sc->sc_last_chan = ic->ic_curchan;
51 + OS_REG_WRITE(ah, AR5K_RXCLEAR, 0);
52 + OS_REG_WRITE(ah, AR5K_CYCLES, 0);
58 * Reset the hardware w/o losing operational state. This is
59 * basically a more efficient way of doing ath_stop, ath_init,
60 @@ -2940,6 +2976,7 @@ ath_reset(struct net_device *dev)
61 * Convert to a HAL channel description with the flags
62 * constrained to reflect the current operating mode.
64 + ath_fetch_idle_time(sc);
66 sc->sc_curchan.channel = c->ic_freq;
67 sc->sc_curchan.channelFlags = ath_chan2flags(c);
68 @@ -9020,6 +9057,7 @@ ath_chan_set(struct ath_softc *sc, struc
69 u_int8_t channel_change_required = 0;
72 + ath_fetch_idle_time(sc);
74 * Convert to a HAL channel description with
75 * the flags constrained to reflect the current
78 @@ -773,6 +773,7 @@ struct ath_softc {
79 struct ieee80211vap **sc_bslot; /* beacon xmit slots */
80 int sc_bnext; /* next slot for beacon xmit */
82 + struct ieee80211_channel *sc_last_chan;
83 int sc_beacon_cal; /* use beacon timer for calibration */
84 u_int64_t sc_lastcal; /* last time the calibration was performed */
85 struct timer_list sc_cal_ch; /* calibration timer */
86 --- a/net80211/_ieee80211.h
87 +++ b/net80211/_ieee80211.h
88 @@ -148,6 +148,7 @@ struct ieee80211_channel {
89 int8_t ic_maxpower; /* maximum tx power in dBm */
90 int8_t ic_minpower; /* minimum tx power in dBm */
91 u_int8_t ic_scanflags;
92 + u_int8_t ic_idletime; /* phy idle time in % */
95 #define IEEE80211_CHAN_MAX 255
96 --- a/net80211/ieee80211_scan_ap.c
97 +++ b/net80211/ieee80211_scan_ap.c
98 @@ -423,6 +423,19 @@ pc_cmp_rssi(struct ap_state *as, struct
100 /* This function must be invoked with locks acquired */
102 +pc_cmp_idletime(struct ieee80211_channel *a,
103 + struct ieee80211_channel *b)
105 + if (!a->ic_idletime || !b->ic_idletime)
108 + /* a is better than b (return < 0) when a has more idle time than b */
109 + return b->ic_idletime - a->ic_idletime;
113 +/* This function must be invoked with locks acquired */
115 pc_cmp_samechan(struct ieee80211com *ic, struct ieee80211_channel *a,
116 struct ieee80211_channel *b)
118 @@ -457,6 +470,7 @@ pc_cmp(const void *_a, const void *_b)
120 EVALUATE_CRITERION(radar, a, b);
121 EVALUATE_CRITERION(keepmode, params, a, b);
122 + EVALUATE_CRITERION(idletime, a, b);
123 EVALUATE_CRITERION(sc, ic, a, b);
124 /* XXX: rssi useless? pick_channel evaluates it anyway */
125 EVALUATE_CRITERION(rssi, params->ss->ss_priv, a, b);