1 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
2 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
3 @@ -1238,6 +1238,8 @@ void rt2800_watchdog(struct rt2x00_dev *
4 if (test_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags))
7 + rt2800_update_survey(rt2x00dev);
9 queue_for_each(rt2x00dev, queue) {
12 @@ -1274,6 +1276,18 @@ void rt2800_watchdog(struct rt2x00_dev *
14 EXPORT_SYMBOL_GPL(rt2800_watchdog);
16 +void rt2800_update_survey(struct rt2x00_dev *rt2x00dev)
18 + struct ieee80211_channel *chan = rt2x00dev->hw->conf.chandef.chan;
19 + struct rt2x00_chan_survey *chan_survey =
20 + &rt2x00dev->chan_survey[chan->hw_value];
22 + chan_survey->time_idle += rt2800_register_read(rt2x00dev, CH_IDLE_STA);
23 + chan_survey->time_busy += rt2800_register_read(rt2x00dev, CH_BUSY_STA);
24 + chan_survey->time_ext_busy += rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC);
26 +EXPORT_SYMBOL_GPL(rt2800_update_survey);
28 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
31 @@ -12199,26 +12213,30 @@ int rt2800_get_survey(struct ieee80211_h
33 struct rt2x00_dev *rt2x00dev = hw->priv;
34 struct ieee80211_conf *conf = &hw->conf;
35 - u32 idle, busy, busy_ext;
36 + struct rt2x00_chan_survey *chan_survey =
37 + &rt2x00dev->chan_survey[idx];
38 + enum nl80211_band band = NL80211_BAND_2GHZ;
41 + if (idx >= rt2x00dev->bands[band].n_channels) {
42 + idx -= rt2x00dev->bands[band].n_channels;
43 + band = NL80211_BAND_5GHZ;
46 + if (idx >= rt2x00dev->bands[band].n_channels)
49 - survey->channel = conf->chandef.chan;
51 + rt2800_update_survey(rt2x00dev);
53 - idle = rt2800_register_read(rt2x00dev, CH_IDLE_STA);
54 - busy = rt2800_register_read(rt2x00dev, CH_BUSY_STA);
55 - busy_ext = rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC);
56 + survey->channel = &rt2x00dev->bands[band].channels[idx];
59 - survey->filled = SURVEY_INFO_TIME |
60 - SURVEY_INFO_TIME_BUSY |
61 - SURVEY_INFO_TIME_EXT_BUSY;
62 + survey->filled = SURVEY_INFO_TIME |
63 + SURVEY_INFO_TIME_BUSY |
64 + SURVEY_INFO_TIME_EXT_BUSY;
66 - survey->time = (idle + busy) / 1000;
67 - survey->time_busy = busy / 1000;
68 - survey->time_ext_busy = busy_ext / 1000;
70 + survey->time = div_u64(chan_survey->time_idle + chan_survey->time_busy, 1000);
71 + survey->time_busy = div_u64(chan_survey->time_busy, 1000);
72 + survey->time_ext_busy = div_u64(chan_survey->time_ext_busy, 1000);
74 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
75 survey->filled |= SURVEY_INFO_IN_USE;
76 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
77 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
78 @@ -243,6 +243,7 @@ bool rt2800_txstatus_timeout(struct rt2x
79 bool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
81 void rt2800_watchdog(struct rt2x00_dev *rt2x00dev);
82 +void rt2800_update_survey(struct rt2x00_dev *rt2x00dev);
84 void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
85 void rt2800_clear_beacon(struct queue_entry *entry);
86 --- a/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
87 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
88 @@ -360,6 +360,7 @@ static const struct rt2x00lib_ops rt2800
89 .gain_calibration = rt2800_gain_calibration,
90 .vco_calibration = rt2800_vco_calibration,
91 .watchdog = rt2800_watchdog,
92 + .update_survey = rt2800_update_survey,
93 .start_queue = rt2800mmio_start_queue,
94 .kick_queue = rt2800mmio_kick_queue,
95 .stop_queue = rt2800mmio_stop_queue,
96 --- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
97 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
98 @@ -214,6 +214,7 @@ static const struct rt2x00lib_ops rt2800
99 .gain_calibration = rt2800_gain_calibration,
100 .vco_calibration = rt2800_vco_calibration,
101 .watchdog = rt2800_watchdog,
102 + .update_survey = rt2800_update_survey,
103 .start_queue = rt2800mmio_start_queue,
104 .kick_queue = rt2800mmio_kick_queue,
105 .stop_queue = rt2800mmio_stop_queue,
106 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
107 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
108 @@ -183,6 +183,15 @@ struct rf_channel {
112 + * Information structure for channel survey.
114 +struct rt2x00_chan_survey {
121 * Channel information structure
123 struct channel_info {
124 @@ -567,6 +576,7 @@ struct rt2x00lib_ops {
125 * Data queue handlers.
127 void (*watchdog) (struct rt2x00_dev *rt2x00dev);
128 + void (*update_survey) (struct rt2x00_dev *rt2x00dev);
129 void (*start_queue) (struct data_queue *queue);
130 void (*kick_queue) (struct data_queue *queue);
131 void (*stop_queue) (struct data_queue *queue);
132 @@ -755,6 +765,7 @@ struct rt2x00_dev {
134 struct ieee80211_hw *hw;
135 struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
136 + struct rt2x00_chan_survey *chan_survey;
137 enum nl80211_band curr_band;
140 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
141 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
142 @@ -1057,6 +1057,12 @@ static int rt2x00lib_probe_hw_modes(stru
144 goto exit_free_channels;
146 + rt2x00dev->chan_survey =
147 + kcalloc(spec->num_channels, sizeof(struct rt2x00_chan_survey),
149 + if (!rt2x00dev->chan_survey)
150 + goto exit_free_rates;
153 * Initialize Rate list.
155 @@ -1108,6 +1114,8 @@ static int rt2x00lib_probe_hw_modes(stru
163 rt2x00_err(rt2x00dev, "Allocation ieee80211 modes failed\n");
164 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00mac.c
165 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00mac.c
166 @@ -317,6 +317,15 @@ int rt2x00mac_config(struct ieee80211_hw
170 + * To provide correct survey data for survey-based ACS algorithm
171 + * we have to save survey data for current channel before switching.
173 + if (rt2x00dev->ops->lib->update_survey &&
174 + (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
175 + rt2x00dev->ops->lib->update_survey(rt2x00dev);
179 * Some configuration parameters (e.g. channel and antenna values) can
180 * only be set when the radio is enabled, but do require the RX to
181 * be off. During this period we should keep link tuning enabled,