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 @@ -2579,6 +2580,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,37 @@ 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);
42 + return; /* wraparound */
44 + if (sc->sc_last_chan)
45 + sc->sc_last_chan->ic_idletime = 100 * (cc - rx) / cc;
46 + sc->sc_last_chan = ic->ic_curchan;
48 + OS_REG_WRITE(ah, AR5K_RXCLEAR, 0);
49 + OS_REG_WRITE(ah, AR5K_CYCLES, 0);
55 * Reset the hardware w/o losing operational state. This is
56 * basically a more efficient way of doing ath_stop, ath_init,
57 @@ -2939,6 +2972,7 @@ ath_reset(struct net_device *dev)
58 * Convert to a HAL channel description with the flags
59 * constrained to reflect the current operating mode.
61 + ath_fetch_idle_time(sc);
63 sc->sc_curchan.channel = c->ic_freq;
64 sc->sc_curchan.channelFlags = ath_chan2flags(c);
65 @@ -9019,6 +9053,7 @@ ath_chan_set(struct ath_softc *sc, struc
66 u_int8_t channel_change_required = 0;
69 + ath_fetch_idle_time(sc);
71 * Convert to a HAL channel description with
72 * the flags constrained to reflect the current
75 @@ -773,6 +773,7 @@ struct ath_softc {
76 struct ieee80211vap **sc_bslot; /* beacon xmit slots */
77 int sc_bnext; /* next slot for beacon xmit */
79 + struct ieee80211_channel *sc_last_chan;
80 int sc_beacon_cal; /* use beacon timer for calibration */
81 u_int64_t sc_lastcal; /* last time the calibration was performed */
82 struct timer_list sc_cal_ch; /* calibration timer */
83 --- a/net80211/_ieee80211.h
84 +++ b/net80211/_ieee80211.h
85 @@ -148,6 +148,7 @@ struct ieee80211_channel {
86 int8_t ic_maxpower; /* maximum tx power in dBm */
87 int8_t ic_minpower; /* minimum tx power in dBm */
88 u_int8_t ic_scanflags;
89 + u_int8_t ic_idletime; /* phy idle time in % */
92 #define IEEE80211_CHAN_MAX 255
93 --- a/net80211/ieee80211_scan_ap.c
94 +++ b/net80211/ieee80211_scan_ap.c
95 @@ -423,6 +423,19 @@ pc_cmp_rssi(struct ap_state *as, struct
97 /* This function must be invoked with locks acquired */
99 +pc_cmp_idletime(struct ieee80211_channel *a,
100 + struct ieee80211_channel *b)
102 + if (!a->ic_idletime || !b->ic_idletime)
105 + /* a is better than b (return < 0) when a has more idle time than b */
106 + return b->ic_idletime - a->ic_idletime;
110 +/* This function must be invoked with locks acquired */
112 pc_cmp_samechan(struct ieee80211com *ic, struct ieee80211_channel *a,
113 struct ieee80211_channel *b)
115 @@ -455,6 +468,7 @@ pc_cmp(const void *_a, const void *_b)
119 + EVALUATE_CRITERION(idletime, a, b);
120 EVALUATE_CRITERION(radar, a, b);
121 EVALUATE_CRITERION(keepmode, params, a, b);
122 EVALUATE_CRITERION(sc, ic, a, b);