1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -594,6 +594,8 @@ struct ath_softc {
4 struct delayed_work wiphy_work;
5 unsigned long wiphy_scheduler_int;
6 int wiphy_scheduler_index;
7 + struct survey_info *cur_survey;
8 + struct survey_info survey[ATH9K_NUM_CHANNELS];
10 struct tasklet_struct intr_tq;
11 struct tasklet_struct bcon_tasklet;
12 --- a/drivers/net/wireless/ath/ath9k/main.c
13 +++ b/drivers/net/wireless/ath/ath9k/main.c
14 @@ -176,6 +176,49 @@ static void ath_start_ani(struct ath_com
15 msecs_to_jiffies((u32)ah->config.ani_poll_interval));
18 +static void ath_update_survey_nf(struct ath_softc *sc, int channel)
20 + struct ath_hw *ah = sc->sc_ah;
21 + struct ath9k_channel *chan = &ah->channels[channel];
22 + struct survey_info *survey = &sc->survey[channel];
24 + if (chan->noisefloor) {
25 + survey->filled |= SURVEY_INFO_NOISE_DBM;
26 + survey->noise = chan->noisefloor;
30 +static void ath_update_survey_stats(struct ath_softc *sc)
32 + struct ath_hw *ah = sc->sc_ah;
33 + struct ath_common *common = ath9k_hw_common(ah);
34 + int pos = ah->curchan - &ah->channels[0];
35 + struct survey_info *survey = &sc->survey[pos];
36 + struct ath_cycle_counters *cc = &common->cc_survey;
37 + unsigned long flags;
38 + unsigned int div = common->clockrate * 1000;
40 + spin_lock_irqsave(&common->cc_lock, flags);
42 + ath_hw_cycle_counters_update(common);
44 + if (cc->cycles > 0) {
45 + survey->filled |= SURVEY_INFO_CHANNEL_TIME |
46 + SURVEY_INFO_CHANNEL_TIME_BUSY |
47 + SURVEY_INFO_CHANNEL_TIME_RX |
48 + SURVEY_INFO_CHANNEL_TIME_TX;
49 + survey->channel_time += cc->cycles / div;
50 + survey->channel_time_busy += cc->rx_busy / div;
51 + survey->channel_time_rx += cc->rx_frame / div;
52 + survey->channel_time_tx += cc->tx_frame / div;
54 + memset(cc, 0, sizeof(*cc));
56 + ath_update_survey_nf(sc, pos);
58 + spin_unlock_irqrestore(&common->cc_lock, flags);
62 * Set/change channels. If the channel is really being changed, it's done
63 * by reseting the chip. To accomplish this we must first cleanup any pending
64 @@ -1533,7 +1576,8 @@ static int ath9k_config(struct ieee80211
66 struct ath_wiphy *aphy = hw->priv;
67 struct ath_softc *sc = aphy->sc;
68 - struct ath_common *common = ath9k_hw_common(sc->sc_ah);
69 + struct ath_hw *ah = sc->sc_ah;
70 + struct ath_common *common = ath9k_hw_common(ah);
71 struct ieee80211_conf *conf = &hw->conf;
74 @@ -1599,6 +1643,10 @@ static int ath9k_config(struct ieee80211
75 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
76 struct ieee80211_channel *curchan = hw->conf.channel;
77 int pos = curchan->hw_value;
81 + old_pos = ah->curchan - &ah->channels[0];
84 aphy->chan_is_ht = conf_is_ht(conf);
85 @@ -1626,12 +1674,43 @@ static int ath9k_config(struct ieee80211
87 ath_update_chainmask(sc, conf_is_ht(conf));
89 + /* update survey stats for the old channel before switching */
90 + ath_update_survey_stats(sc);
93 + * If the operating channel changes, change the survey in-use flags
95 + * Reset the survey data for the new channel, unless we're switching
96 + * back to the operating channel from an off-channel operation.
98 + if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
99 + sc->cur_survey != &sc->survey[pos]) {
101 + if (sc->cur_survey)
102 + sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
104 + sc->cur_survey = &sc->survey[pos];
106 + memset(sc->cur_survey, 0, sizeof(struct survey_info));
107 + sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
108 + } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
109 + memset(&sc->survey[pos], 0, sizeof(struct survey_info));
112 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
113 ath_print(common, ATH_DBG_FATAL,
114 "Unable to set channel\n");
115 mutex_unlock(&sc->mutex);
120 + * The most recent snapshot of channel->noisefloor for the old
121 + * channel is only available after the hardware reset. Copy it to
122 + * the survey stats now.
125 + ath_update_survey_nf(sc, old_pos);
129 @@ -2001,9 +2080,12 @@ static int ath9k_get_survey(struct ieee8
131 struct ath_wiphy *aphy = hw->priv;
132 struct ath_softc *sc = aphy->sc;
133 - struct ath_hw *ah = sc->sc_ah;
134 struct ieee80211_supported_band *sband;
135 - struct ath9k_channel *chan;
136 + struct ieee80211_channel *chan;
140 + ath_update_survey_stats(sc);
142 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
143 if (sband && idx >= sband->n_channels) {
144 @@ -2017,17 +2099,10 @@ static int ath9k_get_survey(struct ieee8
145 if (!sband || idx >= sband->n_channels)
148 - survey->channel = &sband->channels[idx];
149 - chan = &ah->channels[survey->channel->hw_value];
150 - survey->filled = 0;
152 - if (chan == ah->curchan)
153 - survey->filled |= SURVEY_INFO_IN_USE;
155 - if (chan->noisefloor) {
156 - survey->filled |= SURVEY_INFO_NOISE_DBM;
157 - survey->noise = chan->noisefloor;
159 + chan = &sband->channels[idx];
160 + pos = chan->hw_value;
161 + memcpy(survey, &sc->survey[pos], sizeof(*survey));
162 + survey->channel = chan;