diff options
author | Ivo van Doorn <ivdoorn@gmail.com> | 2008-12-20 04:53:29 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-01-29 15:58:34 -0500 |
commit | 84e3196ff867c623056eea02c11a45e046490d89 (patch) | |
tree | a2f5c1d69a63b22f202713a501762a777e04d19a /drivers | |
parent | 7d7f19ccb777946df0a8fb7c83189ba2ae08b02e (diff) |
rt2x00: Move link tuning into seperate file
Move link and antenna tuning into a seperate file named rt2x00link.c,
this makes the interface to the link tuner a lot cleaner.
Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/wireless/rt2x00/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00.h | 29 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00config.c | 5 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00debug.c | 4 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00dev.c | 303 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00lib.h | 81 | ||||
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2x00link.c | 402 |
7 files changed, 494 insertions, 331 deletions
diff --git a/drivers/net/wireless/rt2x00/Makefile b/drivers/net/wireless/rt2x00/Makefile index 917cb4f3b038..f22d808d8c51 100644 --- a/drivers/net/wireless/rt2x00/Makefile +++ b/drivers/net/wireless/rt2x00/Makefile | |||
@@ -2,6 +2,7 @@ rt2x00lib-y += rt2x00dev.o | |||
2 | rt2x00lib-y += rt2x00mac.o | 2 | rt2x00lib-y += rt2x00mac.o |
3 | rt2x00lib-y += rt2x00config.o | 3 | rt2x00lib-y += rt2x00config.o |
4 | rt2x00lib-y += rt2x00queue.o | 4 | rt2x00lib-y += rt2x00queue.o |
5 | rt2x00lib-y += rt2x00link.o | ||
5 | rt2x00lib-$(CONFIG_RT2X00_LIB_DEBUGFS) += rt2x00debug.o | 6 | rt2x00lib-$(CONFIG_RT2X00_LIB_DEBUGFS) += rt2x00debug.o |
6 | rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o | 7 | rt2x00lib-$(CONFIG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o |
7 | rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o | 8 | rt2x00lib-$(CONFIG_RT2X00_LIB_RFKILL) += rt2x00rfkill.o |
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h index 39ecf3b82ca1..19c068727a85 100644 --- a/drivers/net/wireless/rt2x00/rt2x00.h +++ b/drivers/net/wireless/rt2x00/rt2x00.h | |||
@@ -212,7 +212,7 @@ struct link_qual { | |||
212 | * (WEIGHT_TX * tx_percentage) + | 212 | * (WEIGHT_TX * tx_percentage) + |
213 | * (WEIGHT_RX * rx_percentage)) / 100 | 213 | * (WEIGHT_RX * rx_percentage)) / 100 |
214 | * | 214 | * |
215 | * This value should then be checked to not be greated then 100. | 215 | * This value should then be checked to not be greater then 100. |
216 | */ | 216 | */ |
217 | int rx_percentage; | 217 | int rx_percentage; |
218 | int rx_success; | 218 | int rx_success; |
@@ -318,33 +318,6 @@ static inline int rt2x00_get_link_rssi(struct link *link) | |||
318 | return DEFAULT_RSSI; | 318 | return DEFAULT_RSSI; |
319 | } | 319 | } |
320 | 320 | ||
321 | static inline int rt2x00_get_link_ant_rssi(struct link *link) | ||
322 | { | ||
323 | if (link->ant.rssi_ant && link->qual.rx_success) | ||
324 | return link->ant.rssi_ant; | ||
325 | return DEFAULT_RSSI; | ||
326 | } | ||
327 | |||
328 | static inline void rt2x00_reset_link_ant_rssi(struct link *link) | ||
329 | { | ||
330 | link->ant.rssi_ant = 0; | ||
331 | } | ||
332 | |||
333 | static inline int rt2x00_get_link_ant_rssi_history(struct link *link, | ||
334 | enum antenna ant) | ||
335 | { | ||
336 | if (link->ant.rssi_history[ant - ANTENNA_A]) | ||
337 | return link->ant.rssi_history[ant - ANTENNA_A]; | ||
338 | return DEFAULT_RSSI; | ||
339 | } | ||
340 | |||
341 | static inline int rt2x00_update_ant_rssi(struct link *link, int rssi) | ||
342 | { | ||
343 | int old_rssi = link->ant.rssi_history[link->ant.active.rx - ANTENNA_A]; | ||
344 | link->ant.rssi_history[link->ant.active.rx - ANTENNA_A] = rssi; | ||
345 | return old_rssi; | ||
346 | } | ||
347 | |||
348 | /* | 321 | /* |
349 | * Interface structure | 322 | * Interface structure |
350 | * Per interface configuration details, this structure | 323 | * Per interface configuration details, this structure |
diff --git a/drivers/net/wireless/rt2x00/rt2x00config.c b/drivers/net/wireless/rt2x00/rt2x00config.c index e66fb316cd61..2f4cb8de9981 100644 --- a/drivers/net/wireless/rt2x00/rt2x00config.c +++ b/drivers/net/wireless/rt2x00/rt2x00config.c | |||
@@ -152,8 +152,7 @@ void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev, | |||
152 | */ | 152 | */ |
153 | rt2x00dev->ops->lib->config_ant(rt2x00dev, ant); | 153 | rt2x00dev->ops->lib->config_ant(rt2x00dev, ant); |
154 | 154 | ||
155 | rt2x00lib_reset_link_tuner(rt2x00dev); | 155 | rt2x00link_reset_tuner(rt2x00dev, true); |
156 | rt2x00_reset_link_ant_rssi(&rt2x00dev->link); | ||
157 | 156 | ||
158 | memcpy(active, ant, sizeof(*ant)); | 157 | memcpy(active, ant, sizeof(*ant)); |
159 | 158 | ||
@@ -191,7 +190,7 @@ void rt2x00lib_config(struct rt2x00_dev *rt2x00dev, | |||
191 | * which means we need to reset the link tuner. | 190 | * which means we need to reset the link tuner. |
192 | */ | 191 | */ |
193 | if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) | 192 | if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) |
194 | rt2x00lib_reset_link_tuner(rt2x00dev); | 193 | rt2x00link_reset_tuner(rt2x00dev, false); |
195 | 194 | ||
196 | rt2x00dev->curr_band = conf->channel->band; | 195 | rt2x00dev->curr_band = conf->channel->band; |
197 | rt2x00dev->tx_power = conf->power_level; | 196 | rt2x00dev->tx_power = conf->power_level; |
diff --git a/drivers/net/wireless/rt2x00/rt2x00debug.c b/drivers/net/wireless/rt2x00/rt2x00debug.c index 54dd10060bf1..cc1940605349 100644 --- a/drivers/net/wireless/rt2x00/rt2x00debug.c +++ b/drivers/net/wireless/rt2x00/rt2x00debug.c | |||
@@ -130,9 +130,11 @@ struct rt2x00debug_intf { | |||
130 | }; | 130 | }; |
131 | 131 | ||
132 | void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, | 132 | void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, |
133 | enum cipher cipher, enum rx_crypto status) | 133 | struct rxdone_entry_desc *rxdesc) |
134 | { | 134 | { |
135 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; | 135 | struct rt2x00debug_intf *intf = rt2x00dev->debugfs_intf; |
136 | enum cipher cipher = rxdesc->cipher; | ||
137 | enum rx_crypto status = rxdesc->cipher_status; | ||
136 | 138 | ||
137 | if (cipher == CIPHER_TKIP_NO_MIC) | 139 | if (cipher == CIPHER_TKIP_NO_MIC) |
138 | cipher = CIPHER_TKIP; | 140 | cipher = CIPHER_TKIP; |
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c index 87c0f2c83077..81d7fc8635d3 100644 --- a/drivers/net/wireless/rt2x00/rt2x00dev.c +++ b/drivers/net/wireless/rt2x00/rt2x00dev.c | |||
@@ -30,60 +30,6 @@ | |||
30 | #include "rt2x00lib.h" | 30 | #include "rt2x00lib.h" |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Link tuning handlers | ||
34 | */ | ||
35 | void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev) | ||
36 | { | ||
37 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) | ||
38 | return; | ||
39 | |||
40 | /* | ||
41 | * Reset link information. | ||
42 | * Both the currently active vgc level as well as | ||
43 | * the link tuner counter should be reset. Resetting | ||
44 | * the counter is important for devices where the | ||
45 | * device should only perform link tuning during the | ||
46 | * first minute after being enabled. | ||
47 | */ | ||
48 | rt2x00dev->link.count = 0; | ||
49 | rt2x00dev->link.vgc_level = 0; | ||
50 | |||
51 | /* | ||
52 | * Reset the link tuner. | ||
53 | */ | ||
54 | rt2x00dev->ops->lib->reset_tuner(rt2x00dev); | ||
55 | } | ||
56 | |||
57 | static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev) | ||
58 | { | ||
59 | /* | ||
60 | * Clear all (possibly) pre-existing quality statistics. | ||
61 | */ | ||
62 | memset(&rt2x00dev->link.qual, 0, sizeof(rt2x00dev->link.qual)); | ||
63 | |||
64 | /* | ||
65 | * The RX and TX percentage should start at 50% | ||
66 | * this will assure we will get at least get some | ||
67 | * decent value when the link tuner starts. | ||
68 | * The value will be dropped and overwritten with | ||
69 | * the correct (measured )value anyway during the | ||
70 | * first run of the link tuner. | ||
71 | */ | ||
72 | rt2x00dev->link.qual.rx_percentage = 50; | ||
73 | rt2x00dev->link.qual.tx_percentage = 50; | ||
74 | |||
75 | rt2x00lib_reset_link_tuner(rt2x00dev); | ||
76 | |||
77 | queue_delayed_work(rt2x00dev->hw->workqueue, | ||
78 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); | ||
79 | } | ||
80 | |||
81 | static void rt2x00lib_stop_link_tuner(struct rt2x00_dev *rt2x00dev) | ||
82 | { | ||
83 | cancel_delayed_work_sync(&rt2x00dev->link.work); | ||
84 | } | ||
85 | |||
86 | /* | ||
87 | * Radio control handlers. | 33 | * Radio control handlers. |
88 | */ | 34 | */ |
89 | int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev) | 35 | int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev) |
@@ -161,238 +107,15 @@ void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state) | |||
161 | * When we are disabling the RX, we should also stop the link tuner. | 107 | * When we are disabling the RX, we should also stop the link tuner. |
162 | */ | 108 | */ |
163 | if (state == STATE_RADIO_RX_OFF) | 109 | if (state == STATE_RADIO_RX_OFF) |
164 | rt2x00lib_stop_link_tuner(rt2x00dev); | 110 | rt2x00link_stop_tuner(rt2x00dev); |
165 | 111 | ||
166 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); | 112 | rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); |
167 | 113 | ||
168 | /* | 114 | /* |
169 | * When we are enabling the RX, we should also start the link tuner. | 115 | * When we are enabling the RX, we should also start the link tuner. |
170 | */ | 116 | */ |
171 | if (state == STATE_RADIO_RX_ON && | 117 | if (state == STATE_RADIO_RX_ON) |
172 | (rt2x00dev->intf_ap_count || rt2x00dev->intf_sta_count)) | 118 | rt2x00link_start_tuner(rt2x00dev); |
173 | rt2x00lib_start_link_tuner(rt2x00dev); | ||
174 | } | ||
175 | |||
176 | static void rt2x00lib_evaluate_antenna_sample(struct rt2x00_dev *rt2x00dev) | ||
177 | { | ||
178 | struct antenna_setup ant; | ||
179 | int sample_a = | ||
180 | rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_A); | ||
181 | int sample_b = | ||
182 | rt2x00_get_link_ant_rssi_history(&rt2x00dev->link, ANTENNA_B); | ||
183 | |||
184 | memcpy(&ant, &rt2x00dev->link.ant.active, sizeof(ant)); | ||
185 | |||
186 | /* | ||
187 | * We are done sampling. Now we should evaluate the results. | ||
188 | */ | ||
189 | rt2x00dev->link.ant.flags &= ~ANTENNA_MODE_SAMPLE; | ||
190 | |||
191 | /* | ||
192 | * During the last period we have sampled the RSSI | ||
193 | * from both antenna's. It now is time to determine | ||
194 | * which antenna demonstrated the best performance. | ||
195 | * When we are already on the antenna with the best | ||
196 | * performance, then there really is nothing for us | ||
197 | * left to do. | ||
198 | */ | ||
199 | if (sample_a == sample_b) | ||
200 | return; | ||
201 | |||
202 | if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) | ||
203 | ant.rx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B; | ||
204 | |||
205 | if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY) | ||
206 | ant.tx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B; | ||
207 | |||
208 | rt2x00lib_config_antenna(rt2x00dev, &ant); | ||
209 | } | ||
210 | |||
211 | static void rt2x00lib_evaluate_antenna_eval(struct rt2x00_dev *rt2x00dev) | ||
212 | { | ||
213 | struct antenna_setup ant; | ||
214 | int rssi_curr = rt2x00_get_link_ant_rssi(&rt2x00dev->link); | ||
215 | int rssi_old = rt2x00_update_ant_rssi(&rt2x00dev->link, rssi_curr); | ||
216 | |||
217 | memcpy(&ant, &rt2x00dev->link.ant.active, sizeof(ant)); | ||
218 | |||
219 | /* | ||
220 | * Legacy driver indicates that we should swap antenna's | ||
221 | * when the difference in RSSI is greater that 5. This | ||
222 | * also should be done when the RSSI was actually better | ||
223 | * then the previous sample. | ||
224 | * When the difference exceeds the threshold we should | ||
225 | * sample the rssi from the other antenna to make a valid | ||
226 | * comparison between the 2 antennas. | ||
227 | */ | ||
228 | if (abs(rssi_curr - rssi_old) < 5) | ||
229 | return; | ||
230 | |||
231 | rt2x00dev->link.ant.flags |= ANTENNA_MODE_SAMPLE; | ||
232 | |||
233 | if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) | ||
234 | ant.rx = (ant.rx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A; | ||
235 | |||
236 | if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY) | ||
237 | ant.tx = (ant.tx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A; | ||
238 | |||
239 | rt2x00lib_config_antenna(rt2x00dev, &ant); | ||
240 | } | ||
241 | |||
242 | static void rt2x00lib_evaluate_antenna(struct rt2x00_dev *rt2x00dev) | ||
243 | { | ||
244 | /* | ||
245 | * Determine if software diversity is enabled for | ||
246 | * either the TX or RX antenna (or both). | ||
247 | * Always perform this check since within the link | ||
248 | * tuner interval the configuration might have changed. | ||
249 | */ | ||
250 | rt2x00dev->link.ant.flags &= ~ANTENNA_RX_DIVERSITY; | ||
251 | rt2x00dev->link.ant.flags &= ~ANTENNA_TX_DIVERSITY; | ||
252 | |||
253 | if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY) | ||
254 | rt2x00dev->link.ant.flags |= ANTENNA_RX_DIVERSITY; | ||
255 | if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY) | ||
256 | rt2x00dev->link.ant.flags |= ANTENNA_TX_DIVERSITY; | ||
257 | |||
258 | if (!(rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) && | ||
259 | !(rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)) { | ||
260 | rt2x00dev->link.ant.flags = 0; | ||
261 | return; | ||
262 | } | ||
263 | |||
264 | /* | ||
265 | * If we have only sampled the data over the last period | ||
266 | * we should now harvest the data. Otherwise just evaluate | ||
267 | * the data. The latter should only be performed once | ||
268 | * every 2 seconds. | ||
269 | */ | ||
270 | if (rt2x00dev->link.ant.flags & ANTENNA_MODE_SAMPLE) | ||
271 | rt2x00lib_evaluate_antenna_sample(rt2x00dev); | ||
272 | else if (rt2x00dev->link.count & 1) | ||
273 | rt2x00lib_evaluate_antenna_eval(rt2x00dev); | ||
274 | } | ||
275 | |||
276 | static void rt2x00lib_update_link_stats(struct link *link, int rssi) | ||
277 | { | ||
278 | int avg_rssi = rssi; | ||
279 | |||
280 | /* | ||
281 | * Update global RSSI | ||
282 | */ | ||
283 | if (link->qual.avg_rssi) | ||
284 | avg_rssi = MOVING_AVERAGE(link->qual.avg_rssi, rssi, 8); | ||
285 | link->qual.avg_rssi = avg_rssi; | ||
286 | |||
287 | /* | ||
288 | * Update antenna RSSI | ||
289 | */ | ||
290 | if (link->ant.rssi_ant) | ||
291 | rssi = MOVING_AVERAGE(link->ant.rssi_ant, rssi, 8); | ||
292 | link->ant.rssi_ant = rssi; | ||
293 | } | ||
294 | |||
295 | static void rt2x00lib_precalculate_link_signal(struct link_qual *qual) | ||
296 | { | ||
297 | if (qual->rx_failed || qual->rx_success) | ||
298 | qual->rx_percentage = | ||
299 | (qual->rx_success * 100) / | ||
300 | (qual->rx_failed + qual->rx_success); | ||
301 | else | ||
302 | qual->rx_percentage = 50; | ||
303 | |||
304 | if (qual->tx_failed || qual->tx_success) | ||
305 | qual->tx_percentage = | ||
306 | (qual->tx_success * 100) / | ||
307 | (qual->tx_failed + qual->tx_success); | ||
308 | else | ||
309 | qual->tx_percentage = 50; | ||
310 | |||
311 | qual->rx_success = 0; | ||
312 | qual->rx_failed = 0; | ||
313 | qual->tx_success = 0; | ||
314 | qual->tx_failed = 0; | ||
315 | } | ||
316 | |||
317 | static int rt2x00lib_calculate_link_signal(struct rt2x00_dev *rt2x00dev, | ||
318 | int rssi) | ||
319 | { | ||
320 | int rssi_percentage = 0; | ||
321 | int signal; | ||
322 | |||
323 | /* | ||
324 | * We need a positive value for the RSSI. | ||
325 | */ | ||
326 | if (rssi < 0) | ||
327 | rssi += rt2x00dev->rssi_offset; | ||
328 | |||
329 | /* | ||
330 | * Calculate the different percentages, | ||
331 | * which will be used for the signal. | ||
332 | */ | ||
333 | if (rt2x00dev->rssi_offset) | ||
334 | rssi_percentage = (rssi * 100) / rt2x00dev->rssi_offset; | ||
335 | |||
336 | /* | ||
337 | * Add the individual percentages and use the WEIGHT | ||
338 | * defines to calculate the current link signal. | ||
339 | */ | ||
340 | signal = ((WEIGHT_RSSI * rssi_percentage) + | ||
341 | (WEIGHT_TX * rt2x00dev->link.qual.tx_percentage) + | ||
342 | (WEIGHT_RX * rt2x00dev->link.qual.rx_percentage)) / 100; | ||
343 | |||
344 | return (signal > 100) ? 100 : signal; | ||
345 | } | ||
346 | |||
347 | static void rt2x00lib_link_tuner(struct work_struct *work) | ||
348 | { | ||
349 | struct rt2x00_dev *rt2x00dev = | ||
350 | container_of(work, struct rt2x00_dev, link.work.work); | ||
351 | |||
352 | /* | ||
353 | * When the radio is shutting down we should | ||
354 | * immediately cease all link tuning. | ||
355 | */ | ||
356 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) | ||
357 | return; | ||
358 | |||
359 | /* | ||
360 | * Update statistics. | ||
361 | */ | ||
362 | rt2x00dev->ops->lib->link_stats(rt2x00dev, &rt2x00dev->link.qual); | ||
363 | rt2x00dev->low_level_stats.dot11FCSErrorCount += | ||
364 | rt2x00dev->link.qual.rx_failed; | ||
365 | |||
366 | /* | ||
367 | * Only perform the link tuning when Link tuning | ||
368 | * has been enabled (This could have been disabled from the EEPROM). | ||
369 | */ | ||
370 | if (!test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags)) | ||
371 | rt2x00dev->ops->lib->link_tuner(rt2x00dev); | ||
372 | |||
373 | /* | ||
374 | * Precalculate a portion of the link signal which is | ||
375 | * in based on the tx/rx success/failure counters. | ||
376 | */ | ||
377 | rt2x00lib_precalculate_link_signal(&rt2x00dev->link.qual); | ||
378 | |||
379 | /* | ||
380 | * Send a signal to the led to update the led signal strength. | ||
381 | */ | ||
382 | rt2x00leds_led_quality(rt2x00dev, rt2x00dev->link.qual.avg_rssi); | ||
383 | |||
384 | /* | ||
385 | * Evaluate antenna setup, make this the last step since this could | ||
386 | * possibly reset some statistics. | ||
387 | */ | ||
388 | rt2x00lib_evaluate_antenna(rt2x00dev); | ||
389 | |||
390 | /* | ||
391 | * Increase tuner counter, and reschedule the next link tuner run. | ||
392 | */ | ||
393 | rt2x00dev->link.count++; | ||
394 | queue_delayed_work(rt2x00dev->hw->workqueue, | ||
395 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); | ||
396 | } | 119 | } |
397 | 120 | ||
398 | static void rt2x00lib_packetfilter_scheduled(struct work_struct *work) | 121 | static void rt2x00lib_packetfilter_scheduled(struct work_struct *work) |
@@ -597,7 +320,6 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev, | |||
597 | struct sk_buff *skb; | 320 | struct sk_buff *skb; |
598 | struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status; | 321 | struct ieee80211_rx_status *rx_status = &rt2x00dev->rx_status; |
599 | struct ieee80211_supported_band *sband; | 322 | struct ieee80211_supported_band *sband; |
600 | struct ieee80211_hdr *hdr; | ||
601 | const struct rt2x00_rate *rate; | 323 | const struct rt2x00_rate *rate; |
602 | unsigned int header_length; | 324 | unsigned int header_length; |
603 | unsigned int align; | 325 | unsigned int align; |
@@ -674,23 +396,14 @@ void rt2x00lib_rxdone(struct rt2x00_dev *rt2x00dev, | |||
674 | } | 396 | } |
675 | 397 | ||
676 | /* | 398 | /* |
677 | * Only update link status if this is a beacon frame carrying our bssid. | 399 | * Update extra components |
678 | */ | 400 | */ |
679 | hdr = (struct ieee80211_hdr *)entry->skb->data; | 401 | rt2x00link_update_stats(rt2x00dev, entry->skb, &rxdesc); |
680 | if (ieee80211_is_beacon(hdr->frame_control) && | 402 | rt2x00debug_update_crypto(rt2x00dev, &rxdesc); |
681 | (rxdesc.dev_flags & RXDONE_MY_BSS)) | ||
682 | rt2x00lib_update_link_stats(&rt2x00dev->link, rxdesc.rssi); | ||
683 | |||
684 | rt2x00debug_update_crypto(rt2x00dev, | ||
685 | rxdesc.cipher, | ||
686 | rxdesc.cipher_status); | ||
687 | |||
688 | rt2x00dev->link.qual.rx_success++; | ||
689 | 403 | ||
690 | rx_status->mactime = rxdesc.timestamp; | 404 | rx_status->mactime = rxdesc.timestamp; |
691 | rx_status->rate_idx = idx; | 405 | rx_status->rate_idx = idx; |
692 | rx_status->qual = | 406 | rx_status->qual = rt2x00link_calculate_signal(rt2x00dev, rxdesc.rssi); |
693 | rt2x00lib_calculate_link_signal(rt2x00dev, rxdesc.rssi); | ||
694 | rx_status->signal = rxdesc.rssi; | 407 | rx_status->signal = rxdesc.rssi; |
695 | rx_status->flag = rxdesc.flags; | 408 | rx_status->flag = rxdesc.flags; |
696 | rx_status->antenna = rt2x00dev->link.ant.active.rx; | 409 | rx_status->antenna = rt2x00dev->link.ant.active.rx; |
@@ -1083,7 +796,6 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev) | |||
1083 | */ | 796 | */ |
1084 | INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled); | 797 | INIT_WORK(&rt2x00dev->intf_work, rt2x00lib_intf_scheduled); |
1085 | INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled); | 798 | INIT_WORK(&rt2x00dev->filter_work, rt2x00lib_packetfilter_scheduled); |
1086 | INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00lib_link_tuner); | ||
1087 | 799 | ||
1088 | /* | 800 | /* |
1089 | * Allocate queue array. | 801 | * Allocate queue array. |
@@ -1104,6 +816,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev) | |||
1104 | /* | 816 | /* |
1105 | * Register extra components. | 817 | * Register extra components. |
1106 | */ | 818 | */ |
819 | rt2x00link_register(rt2x00dev); | ||
1107 | rt2x00leds_register(rt2x00dev); | 820 | rt2x00leds_register(rt2x00dev); |
1108 | rt2x00rfkill_allocate(rt2x00dev); | 821 | rt2x00rfkill_allocate(rt2x00dev); |
1109 | rt2x00debug_register(rt2x00dev); | 822 | rt2x00debug_register(rt2x00dev); |
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h index 86cd26fbf769..fccaffde6f55 100644 --- a/drivers/net/wireless/rt2x00/rt2x00lib.h +++ b/drivers/net/wireless/rt2x00/rt2x00lib.h | |||
@@ -63,7 +63,6 @@ static inline const struct rt2x00_rate *rt2x00_get_rate(const u16 hw_value) | |||
63 | int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev); | 63 | int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev); |
64 | void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev); | 64 | void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev); |
65 | void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state); | 65 | void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state); |
66 | void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev); | ||
67 | 66 | ||
68 | /* | 67 | /* |
69 | * Initialization handlers. | 68 | * Initialization handlers. |
@@ -154,6 +153,81 @@ void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev); | |||
154 | int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev); | 153 | int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev); |
155 | void rt2x00queue_free(struct rt2x00_dev *rt2x00dev); | 154 | void rt2x00queue_free(struct rt2x00_dev *rt2x00dev); |
156 | 155 | ||
156 | /** | ||
157 | * rt2x00link_update_stats - Update link statistics from RX frame | ||
158 | * @rt2x00dev: Pointer to &struct rt2x00_dev. | ||
159 | * @skb: Received frame | ||
160 | * @rxdesc: Received frame descriptor | ||
161 | * | ||
162 | * Update link statistics based on the information from the | ||
163 | * received frame descriptor. | ||
164 | */ | ||
165 | void rt2x00link_update_stats(struct rt2x00_dev *rt2x00dev, | ||
166 | struct sk_buff *skb, | ||
167 | struct rxdone_entry_desc *rxdesc); | ||
168 | |||
169 | /** | ||
170 | * rt2x00link_calculate_signal - Calculate signal quality | ||
171 | * @rt2x00dev: Pointer to &struct rt2x00_dev. | ||
172 | * @rssi: RX Frame RSSI | ||
173 | * | ||
174 | * Calculate the signal quality of a frame based on the rssi | ||
175 | * measured during the receiving of the frame and the global | ||
176 | * link quality statistics measured since the start of the | ||
177 | * link tuning. The result is a value between 0 and 100 which | ||
178 | * is an indication of the signal quality. | ||
179 | */ | ||
180 | int rt2x00link_calculate_signal(struct rt2x00_dev *rt2x00dev, int rssi); | ||
181 | |||
182 | /** | ||
183 | * rt2x00link_start_tuner - Start periodic link tuner work | ||
184 | * @rt2x00dev: Pointer to &struct rt2x00_dev. | ||
185 | * | ||
186 | * This start the link tuner periodic work, this work will | ||
187 | * be executed periodically until &rt2x00link_stop_tuner has | ||
188 | * been called. | ||
189 | */ | ||
190 | void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev); | ||
191 | |||
192 | /** | ||
193 | * rt2x00link_stop_tuner - Stop periodic link tuner work | ||
194 | * @rt2x00dev: Pointer to &struct rt2x00_dev. | ||
195 | * | ||
196 | * After this function completed the link tuner will not | ||
197 | * be running until &rt2x00link_start_tuner is called. | ||
198 | */ | ||
199 | void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev); | ||
200 | |||
201 | /** | ||
202 | * rt2x00link_reset_tuner - Reset periodic link tuner work | ||
203 | * @rt2x00dev: Pointer to &struct rt2x00_dev. | ||
204 | * @antenna: Should the antenna tuning also be reset | ||
205 | * | ||
206 | * The VGC limit configured in the hardware will be reset to 0 | ||
207 | * which forces the driver to rediscover the correct value for | ||
208 | * the current association. This is needed when configuration | ||
209 | * options have changed which could drastically change the | ||
210 | * SNR level or link quality (i.e. changing the antenna setting). | ||
211 | * | ||
212 | * Resetting the link tuner will also cause the periodic work counter | ||
213 | * to be reset. Any driver which has a fixed limit on the number | ||
214 | * of rounds the link tuner is supposed to work will accept the | ||
215 | * tuner actions again if this limit was previously reached. | ||
216 | * | ||
217 | * If @antenna is set to true a the software antenna diversity | ||
218 | * tuning will also be reset. | ||
219 | */ | ||
220 | void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna); | ||
221 | |||
222 | /** | ||
223 | * rt2x00link_register - Initialize link tuning functionality | ||
224 | * @rt2x00dev: Pointer to &struct rt2x00_dev. | ||
225 | * | ||
226 | * Initialize work structure and all link tuning related | ||
227 | * paramters. This will not start the link tuning process itself. | ||
228 | */ | ||
229 | void rt2x00link_register(struct rt2x00_dev *rt2x00dev); | ||
230 | |||
157 | /* | 231 | /* |
158 | * Firmware handlers. | 232 | * Firmware handlers. |
159 | */ | 233 | */ |
@@ -179,7 +253,7 @@ void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev); | |||
179 | void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, | 253 | void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, |
180 | enum rt2x00_dump_type type, struct sk_buff *skb); | 254 | enum rt2x00_dump_type type, struct sk_buff *skb); |
181 | void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, | 255 | void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, |
182 | enum cipher cipher, enum rx_crypto status); | 256 | struct rxdone_entry_desc *rxdesc); |
183 | #else | 257 | #else |
184 | static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev) | 258 | static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev) |
185 | { | 259 | { |
@@ -196,8 +270,7 @@ static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev, | |||
196 | } | 270 | } |
197 | 271 | ||
198 | static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, | 272 | static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev, |
199 | enum cipher cipher, | 273 | struct rxdone_entry_desc *rxdesc) |
200 | enum rx_crypto status) | ||
201 | { | 274 | { |
202 | } | 275 | } |
203 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ | 276 | #endif /* CONFIG_RT2X00_LIB_DEBUGFS */ |
diff --git a/drivers/net/wireless/rt2x00/rt2x00link.c b/drivers/net/wireless/rt2x00/rt2x00link.c new file mode 100644 index 000000000000..0462d5ab6e97 --- /dev/null +++ b/drivers/net/wireless/rt2x00/rt2x00link.c | |||
@@ -0,0 +1,402 @@ | |||
1 | /* | ||
2 | Copyright (C) 2004 - 2008 rt2x00 SourceForge Project | ||
3 | <http://rt2x00.serialmonkey.com> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the | ||
17 | Free Software Foundation, Inc., | ||
18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Module: rt2x00lib | ||
23 | Abstract: rt2x00 generic link tuning routines. | ||
24 | */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/module.h> | ||
28 | |||
29 | #include "rt2x00.h" | ||
30 | #include "rt2x00lib.h" | ||
31 | |||
32 | static int rt2x00link_antenna_get_link_rssi(struct rt2x00_dev *rt2x00dev) | ||
33 | { | ||
34 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
35 | |||
36 | if (ant->rssi_ant && rt2x00dev->link.qual.rx_success) | ||
37 | return ant->rssi_ant; | ||
38 | return DEFAULT_RSSI; | ||
39 | } | ||
40 | |||
41 | static int rt2x00link_antenna_get_rssi_history(struct rt2x00_dev *rt2x00dev, | ||
42 | enum antenna antenna) | ||
43 | { | ||
44 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
45 | |||
46 | if (ant->rssi_history[antenna - ANTENNA_A]) | ||
47 | return ant->rssi_history[antenna - ANTENNA_A]; | ||
48 | return DEFAULT_RSSI; | ||
49 | } | ||
50 | /* Small wrapper for rt2x00link_antenna_get_rssi_history() */ | ||
51 | #define rt2x00link_antenna_get_rssi_rx_history(__dev) \ | ||
52 | rt2x00link_antenna_get_rssi_history((__dev), \ | ||
53 | (__dev)->link.ant.active.rx) | ||
54 | #define rt2x00link_antenna_get_rssi_tx_history(__dev) \ | ||
55 | rt2x00link_antenna_get_rssi_history((__dev), \ | ||
56 | (__dev)->link.ant.active.tx) | ||
57 | |||
58 | static void rt2x00link_antenna_update_rssi_history(struct rt2x00_dev *rt2x00dev, | ||
59 | enum antenna antenna, | ||
60 | int rssi) | ||
61 | { | ||
62 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
63 | ant->rssi_history[ant->active.rx - ANTENNA_A] = rssi; | ||
64 | } | ||
65 | /* Small wrapper for rt2x00link_antenna_get_rssi_history() */ | ||
66 | #define rt2x00link_antenna_update_rssi_rx_history(__dev, __rssi) \ | ||
67 | rt2x00link_antenna_update_rssi_history((__dev), \ | ||
68 | (__dev)->link.ant.active.rx, \ | ||
69 | (__rssi)) | ||
70 | #define rt2x00link_antenna_update_rssi_tx_history(__dev, __rssi) \ | ||
71 | rt2x00link_antenna_update_rssi_history((__dev), \ | ||
72 | (__dev)->link.ant.active.tx, \ | ||
73 | (__rssi)) | ||
74 | |||
75 | static void rt2x00link_antenna_reset(struct rt2x00_dev *rt2x00dev) | ||
76 | { | ||
77 | rt2x00dev->link.ant.rssi_ant = 0; | ||
78 | } | ||
79 | |||
80 | static void rt2x00lib_antenna_diversity_sample(struct rt2x00_dev *rt2x00dev) | ||
81 | { | ||
82 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
83 | struct antenna_setup new_ant; | ||
84 | int sample_a = rt2x00link_antenna_get_rssi_history(rt2x00dev, ANTENNA_A); | ||
85 | int sample_b = rt2x00link_antenna_get_rssi_history(rt2x00dev, ANTENNA_B); | ||
86 | |||
87 | memcpy(&new_ant, &ant->active, sizeof(new_ant)); | ||
88 | |||
89 | /* | ||
90 | * We are done sampling. Now we should evaluate the results. | ||
91 | */ | ||
92 | ant->flags &= ~ANTENNA_MODE_SAMPLE; | ||
93 | |||
94 | /* | ||
95 | * During the last period we have sampled the RSSI | ||
96 | * from both antenna's. It now is time to determine | ||
97 | * which antenna demonstrated the best performance. | ||
98 | * When we are already on the antenna with the best | ||
99 | * performance, then there really is nothing for us | ||
100 | * left to do. | ||
101 | */ | ||
102 | if (sample_a == sample_b) | ||
103 | return; | ||
104 | |||
105 | if (ant->flags & ANTENNA_RX_DIVERSITY) | ||
106 | new_ant.rx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B; | ||
107 | |||
108 | if (ant->flags & ANTENNA_TX_DIVERSITY) | ||
109 | new_ant.tx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B; | ||
110 | |||
111 | rt2x00lib_config_antenna(rt2x00dev, &new_ant); | ||
112 | } | ||
113 | |||
114 | static void rt2x00lib_antenna_diversity_eval(struct rt2x00_dev *rt2x00dev) | ||
115 | { | ||
116 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
117 | struct antenna_setup new_ant; | ||
118 | int rssi_curr; | ||
119 | int rssi_old; | ||
120 | |||
121 | memcpy(&new_ant, &ant->active, sizeof(new_ant)); | ||
122 | |||
123 | /* | ||
124 | * Get current RSSI value along with the historical value, | ||
125 | * after that update the history with the current value. | ||
126 | */ | ||
127 | rssi_curr = rt2x00link_antenna_get_link_rssi(rt2x00dev); | ||
128 | rssi_old = rt2x00link_antenna_get_rssi_rx_history(rt2x00dev); | ||
129 | rt2x00link_antenna_update_rssi_rx_history(rt2x00dev, rssi_curr); | ||
130 | |||
131 | /* | ||
132 | * Legacy driver indicates that we should swap antenna's | ||
133 | * when the difference in RSSI is greater that 5. This | ||
134 | * also should be done when the RSSI was actually better | ||
135 | * then the previous sample. | ||
136 | * When the difference exceeds the threshold we should | ||
137 | * sample the rssi from the other antenna to make a valid | ||
138 | * comparison between the 2 antennas. | ||
139 | */ | ||
140 | if (abs(rssi_curr - rssi_old) < 5) | ||
141 | return; | ||
142 | |||
143 | ant->flags |= ANTENNA_MODE_SAMPLE; | ||
144 | |||
145 | if (ant->flags & ANTENNA_RX_DIVERSITY) | ||
146 | new_ant.rx = (new_ant.rx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A; | ||
147 | |||
148 | if (ant->flags & ANTENNA_TX_DIVERSITY) | ||
149 | new_ant.tx = (new_ant.tx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A; | ||
150 | |||
151 | rt2x00lib_config_antenna(rt2x00dev, &new_ant); | ||
152 | } | ||
153 | |||
154 | static void rt2x00lib_antenna_diversity(struct rt2x00_dev *rt2x00dev) | ||
155 | { | ||
156 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
157 | |||
158 | /* | ||
159 | * Determine if software diversity is enabled for | ||
160 | * either the TX or RX antenna (or both). | ||
161 | * Always perform this check since within the link | ||
162 | * tuner interval the configuration might have changed. | ||
163 | */ | ||
164 | ant->flags &= ~ANTENNA_RX_DIVERSITY; | ||
165 | ant->flags &= ~ANTENNA_TX_DIVERSITY; | ||
166 | |||
167 | if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY) | ||
168 | ant->flags |= ANTENNA_RX_DIVERSITY; | ||
169 | if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY) | ||
170 | ant->flags |= ANTENNA_TX_DIVERSITY; | ||
171 | |||
172 | if (!(ant->flags & ANTENNA_RX_DIVERSITY) && | ||
173 | !(ant->flags & ANTENNA_TX_DIVERSITY)) { | ||
174 | ant->flags = 0; | ||
175 | return; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * If we have only sampled the data over the last period | ||
180 | * we should now harvest the data. Otherwise just evaluate | ||
181 | * the data. The latter should only be performed once | ||
182 | * every 2 seconds. | ||
183 | */ | ||
184 | if (ant->flags & ANTENNA_MODE_SAMPLE) | ||
185 | rt2x00lib_antenna_diversity_sample(rt2x00dev); | ||
186 | else if (rt2x00dev->link.count & 1) | ||
187 | rt2x00lib_antenna_diversity_eval(rt2x00dev); | ||
188 | } | ||
189 | |||
190 | void rt2x00link_update_stats(struct rt2x00_dev *rt2x00dev, | ||
191 | struct sk_buff *skb, | ||
192 | struct rxdone_entry_desc *rxdesc) | ||
193 | { | ||
194 | struct link_qual *qual = &rt2x00dev->link.qual; | ||
195 | struct link_ant *ant = &rt2x00dev->link.ant; | ||
196 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | ||
197 | int avg_rssi = rxdesc->rssi; | ||
198 | int ant_rssi = rxdesc->rssi; | ||
199 | |||
200 | /* | ||
201 | * Frame was received successfully since non-succesfull | ||
202 | * frames would have been dropped by the hardware. | ||
203 | */ | ||
204 | qual->rx_success++; | ||
205 | |||
206 | /* | ||
207 | * We are only interested in quality statistics from | ||
208 | * beacons which came from the BSS which we are | ||
209 | * associated with. | ||
210 | */ | ||
211 | if (!ieee80211_is_beacon(hdr->frame_control) || | ||
212 | !(rxdesc->dev_flags & RXDONE_MY_BSS)) | ||
213 | return; | ||
214 | |||
215 | /* | ||
216 | * Update global RSSI | ||
217 | */ | ||
218 | if (qual->avg_rssi) | ||
219 | avg_rssi = MOVING_AVERAGE(qual->avg_rssi, rxdesc->rssi, 8); | ||
220 | qual->avg_rssi = avg_rssi; | ||
221 | |||
222 | /* | ||
223 | * Update antenna RSSI | ||
224 | */ | ||
225 | if (ant->rssi_ant) | ||
226 | ant_rssi = MOVING_AVERAGE(ant->rssi_ant, rxdesc->rssi, 8); | ||
227 | ant->rssi_ant = ant_rssi; | ||
228 | } | ||
229 | |||
230 | static void rt2x00link_precalculate_signal(struct rt2x00_dev *rt2x00dev) | ||
231 | { | ||
232 | struct link_qual *qual = &rt2x00dev->link.qual; | ||
233 | |||
234 | if (qual->rx_failed || qual->rx_success) | ||
235 | qual->rx_percentage = | ||
236 | (qual->rx_success * 100) / | ||
237 | (qual->rx_failed + qual->rx_success); | ||
238 | else | ||
239 | qual->rx_percentage = 50; | ||
240 | |||
241 | if (qual->tx_failed || qual->tx_success) | ||
242 | qual->tx_percentage = | ||
243 | (qual->tx_success * 100) / | ||
244 | (qual->tx_failed + qual->tx_success); | ||
245 | else | ||
246 | qual->tx_percentage = 50; | ||
247 | |||
248 | qual->rx_success = 0; | ||
249 | qual->rx_failed = 0; | ||
250 | qual->tx_success = 0; | ||
251 | qual->tx_failed = 0; | ||
252 | } | ||
253 | |||
254 | int rt2x00link_calculate_signal(struct rt2x00_dev *rt2x00dev, int rssi) | ||
255 | { | ||
256 | struct link_qual *qual = &rt2x00dev->link.qual; | ||
257 | int rssi_percentage = 0; | ||
258 | int signal; | ||
259 | |||
260 | /* | ||
261 | * We need a positive value for the RSSI. | ||
262 | */ | ||
263 | if (rssi < 0) | ||
264 | rssi += rt2x00dev->rssi_offset; | ||
265 | |||
266 | /* | ||
267 | * Calculate the different percentages, | ||
268 | * which will be used for the signal. | ||
269 | */ | ||
270 | rssi_percentage = (rssi * 100) / rt2x00dev->rssi_offset; | ||
271 | |||
272 | /* | ||
273 | * Add the individual percentages and use the WEIGHT | ||
274 | * defines to calculate the current link signal. | ||
275 | */ | ||
276 | signal = ((WEIGHT_RSSI * rssi_percentage) + | ||
277 | (WEIGHT_TX * qual->tx_percentage) + | ||
278 | (WEIGHT_RX * qual->rx_percentage)) / 100; | ||
279 | |||
280 | return max_t(int, signal, 100); | ||
281 | } | ||
282 | |||
283 | void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev) | ||
284 | { | ||
285 | struct link_qual *qual = &rt2x00dev->link.qual; | ||
286 | |||
287 | /* | ||
288 | * Link tuning should only be performed when | ||
289 | * an active sta or master interface exists. | ||
290 | * Single monitor mode interfaces should never have | ||
291 | * work with link tuners. | ||
292 | */ | ||
293 | if (!rt2x00dev->intf_ap_count && !rt2x00dev->intf_sta_count) | ||
294 | return; | ||
295 | |||
296 | /* | ||
297 | * Clear all (possibly) pre-existing quality statistics. | ||
298 | */ | ||
299 | memset(qual, 0, sizeof(*qual)); | ||
300 | |||
301 | /* | ||
302 | * The RX and TX percentage should start at 50% | ||
303 | * this will assure we will get at least get some | ||
304 | * decent value when the link tuner starts. | ||
305 | * The value will be dropped and overwritten with | ||
306 | * the correct (measured) value anyway during the | ||
307 | * first run of the link tuner. | ||
308 | */ | ||
309 | qual->rx_percentage = 50; | ||
310 | qual->tx_percentage = 50; | ||
311 | |||
312 | rt2x00link_reset_tuner(rt2x00dev, false); | ||
313 | |||
314 | queue_delayed_work(rt2x00dev->hw->workqueue, | ||
315 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); | ||
316 | } | ||
317 | |||
318 | void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev) | ||
319 | { | ||
320 | cancel_delayed_work_sync(&rt2x00dev->link.work); | ||
321 | } | ||
322 | |||
323 | void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna) | ||
324 | { | ||
325 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) | ||
326 | return; | ||
327 | |||
328 | /* | ||
329 | * Reset link information. | ||
330 | * Both the currently active vgc level as well as | ||
331 | * the link tuner counter should be reset. Resetting | ||
332 | * the counter is important for devices where the | ||
333 | * device should only perform link tuning during the | ||
334 | * first minute after being enabled. | ||
335 | */ | ||
336 | rt2x00dev->link.count = 0; | ||
337 | rt2x00dev->link.vgc_level = 0; | ||
338 | |||
339 | /* | ||
340 | * Reset the link tuner. | ||
341 | */ | ||
342 | rt2x00dev->ops->lib->reset_tuner(rt2x00dev); | ||
343 | |||
344 | if (antenna) | ||
345 | rt2x00link_antenna_reset(rt2x00dev); | ||
346 | } | ||
347 | |||
348 | static void rt2x00link_tuner(struct work_struct *work) | ||
349 | { | ||
350 | struct rt2x00_dev *rt2x00dev = | ||
351 | container_of(work, struct rt2x00_dev, link.work.work); | ||
352 | struct link_qual *qual = &rt2x00dev->link.qual; | ||
353 | |||
354 | /* | ||
355 | * When the radio is shutting down we should | ||
356 | * immediately cease all link tuning. | ||
357 | */ | ||
358 | if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) | ||
359 | return; | ||
360 | |||
361 | /* | ||
362 | * Update statistics. | ||
363 | */ | ||
364 | rt2x00dev->ops->lib->link_stats(rt2x00dev, qual); | ||
365 | rt2x00dev->low_level_stats.dot11FCSErrorCount += qual->rx_failed; | ||
366 | |||
367 | /* | ||
368 | * Only perform the link tuning when Link tuning | ||
369 | * has been enabled (This could have been disabled from the EEPROM). | ||
370 | */ | ||
371 | if (!test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags)) | ||
372 | rt2x00dev->ops->lib->link_tuner(rt2x00dev); | ||
373 | |||
374 | /* | ||
375 | * Precalculate a portion of the link signal which is | ||
376 | * in based on the tx/rx success/failure counters. | ||
377 | */ | ||
378 | rt2x00link_precalculate_signal(rt2x00dev); | ||
379 | |||
380 | /* | ||
381 | * Send a signal to the led to update the led signal strength. | ||
382 | */ | ||
383 | rt2x00leds_led_quality(rt2x00dev, qual->avg_rssi); | ||
384 | |||
385 | /* | ||
386 | * Evaluate antenna setup, make this the last step since this could | ||
387 | * possibly reset some statistics. | ||
388 | */ | ||
389 | rt2x00lib_antenna_diversity(rt2x00dev); | ||
390 | |||
391 | /* | ||
392 | * Increase tuner counter, and reschedule the next link tuner run. | ||
393 | */ | ||
394 | rt2x00dev->link.count++; | ||
395 | queue_delayed_work(rt2x00dev->hw->workqueue, | ||
396 | &rt2x00dev->link.work, LINK_TUNE_INTERVAL); | ||
397 | } | ||
398 | |||
399 | void rt2x00link_register(struct rt2x00_dev *rt2x00dev) | ||
400 | { | ||
401 | INIT_DELAYED_WORK(&rt2x00dev->link.work, rt2x00link_tuner); | ||
402 | } | ||