mac80211: refresh patches
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / rt2x00 / 992-rt2x00-save-survey-for-every-channel-visited.patch
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))
5 return;
6
7 + rt2800_update_survey(rt2x00dev);
8 +
9 queue_for_each(rt2x00dev, queue) {
10 switch (queue->qid) {
11 case QID_AC_VO:
12 @@ -1274,6 +1276,18 @@ void rt2800_watchdog(struct rt2x00_dev *
13 }
14 EXPORT_SYMBOL_GPL(rt2800_watchdog);
15
16 +void rt2800_update_survey(struct rt2x00_dev *rt2x00dev)
17 +{
18 + struct ieee80211_channel *chan = rt2x00dev->hw->conf.chandef.chan;
19 + struct rt2x00_chan_survey *chan_survey =
20 + &rt2x00dev->chan_survey[chan->hw_value];
21 +
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);
25 +}
26 +EXPORT_SYMBOL_GPL(rt2800_update_survey);
27 +
28 static unsigned int rt2800_hw_beacon_base(struct rt2x00_dev *rt2x00dev,
29 unsigned int index)
30 {
31 @@ -12199,26 +12213,30 @@ int rt2800_get_survey(struct ieee80211_h
32 {
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;
39
40 - if (idx != 0)
41 + if (idx >= rt2x00dev->bands[band].n_channels) {
42 + idx -= rt2x00dev->bands[band].n_channels;
43 + band = NL80211_BAND_5GHZ;
44 + }
45 +
46 + if (idx >= rt2x00dev->bands[band].n_channels)
47 return -ENOENT;
48
49 - survey->channel = conf->chandef.chan;
50 + if (idx == 0)
51 + rt2800_update_survey(rt2x00dev);
52
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];
57
58 - if (idle || busy) {
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;
65
66 - survey->time = (idle + busy) / 1000;
67 - survey->time_busy = busy / 1000;
68 - survey->time_ext_busy = busy_ext / 1000;
69 - }
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);
73
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);
80
81 void rt2800_watchdog(struct rt2x00_dev *rt2x00dev);
82 +void rt2800_update_survey(struct rt2x00_dev *rt2x00dev);
83
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 {
109 };
110
111 /*
112 + * Information structure for channel survey.
113 + */
114 +struct rt2x00_chan_survey {
115 + u64 time_idle;
116 + u64 time_busy;
117 + u64 time_ext_busy;
118 +};
119 +
120 +/*
121 * Channel information structure
122 */
123 struct channel_info {
124 @@ -567,6 +576,7 @@ struct rt2x00lib_ops {
125 * Data queue handlers.
126 */
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 {
133 */
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;
138 int curr_freq;
139
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
143 if (!rates)
144 goto exit_free_channels;
145
146 + rt2x00dev->chan_survey =
147 + kcalloc(spec->num_channels, sizeof(struct rt2x00_chan_survey),
148 + GFP_KERNEL);
149 + if (!rt2x00dev->chan_survey)
150 + goto exit_free_rates;
151 +
152 /*
153 * Initialize Rate list.
154 */
155 @@ -1108,6 +1114,8 @@ static int rt2x00lib_probe_hw_modes(stru
156
157 return 0;
158
159 + exit_free_rates:
160 + kfree(rates);
161 exit_free_channels:
162 kfree(channels);
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
167 return 0;
168
169 /*
170 + * To provide correct survey data for survey-based ACS algorithm
171 + * we have to save survey data for current channel before switching.
172 + */
173 + if (rt2x00dev->ops->lib->update_survey &&
174 + (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
175 + rt2x00dev->ops->lib->update_survey(rt2x00dev);
176 + }
177 +
178 + /*
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,