aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00dev.c
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-12-20 04:53:29 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-01-29 15:58:34 -0500
commit84e3196ff867c623056eea02c11a45e046490d89 (patch)
treea2f5c1d69a63b22f202713a501762a777e04d19a /drivers/net/wireless/rt2x00/rt2x00dev.c
parent7d7f19ccb777946df0a8fb7c83189ba2ae08b02e (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/net/wireless/rt2x00/rt2x00dev.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c303
1 files changed, 8 insertions, 295 deletions
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 */
35void 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
57static 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
81static 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 */
89int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev) 35int 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
176static 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
211static 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
242static 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
276static 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
295static 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
317static 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
347static 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
398static void rt2x00lib_packetfilter_scheduled(struct work_struct *work) 121static 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);