aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2x00dev.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index c4be2ac4d7a4..0d51f478bcdf 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -61,11 +61,33 @@ EXPORT_SYMBOL_GPL(rt2x00lib_get_ring);
61/* 61/*
62 * Link tuning handlers 62 * Link tuning handlers
63 */ 63 */
64static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev) 64void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
65{ 65{
66 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
67 return;
68
69 /*
70 * Reset link information.
71 * Both the currently active vgc level as well as
72 * the link tuner counter should be reset. Resetting
73 * the counter is important for devices where the
74 * device should only perform link tuning during the
75 * first minute after being enabled.
76 */
66 rt2x00dev->link.count = 0; 77 rt2x00dev->link.count = 0;
67 rt2x00dev->link.vgc_level = 0; 78 rt2x00dev->link.vgc_level = 0;
68 79
80 /*
81 * Reset the link tuner.
82 */
83 rt2x00dev->ops->lib->reset_tuner(rt2x00dev);
84}
85
86static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev)
87{
88 /*
89 * Clear all (possibly) pre-existing quality statistics.
90 */
69 memset(&rt2x00dev->link.qual, 0, sizeof(rt2x00dev->link.qual)); 91 memset(&rt2x00dev->link.qual, 0, sizeof(rt2x00dev->link.qual));
70 92
71 /* 93 /*
@@ -79,10 +101,7 @@ static void rt2x00lib_start_link_tuner(struct rt2x00_dev *rt2x00dev)
79 rt2x00dev->link.qual.rx_percentage = 50; 101 rt2x00dev->link.qual.rx_percentage = 50;
80 rt2x00dev->link.qual.tx_percentage = 50; 102 rt2x00dev->link.qual.tx_percentage = 50;
81 103
82 /* 104 rt2x00lib_reset_link_tuner(rt2x00dev);
83 * Reset the link tuner.
84 */
85 rt2x00dev->ops->lib->reset_tuner(rt2x00dev);
86 105
87 queue_delayed_work(rt2x00dev->hw->workqueue, 106 queue_delayed_work(rt2x00dev->hw->workqueue,
88 &rt2x00dev->link.work, LINK_TUNE_INTERVAL); 107 &rt2x00dev->link.work, LINK_TUNE_INTERVAL);
@@ -93,15 +112,6 @@ static void rt2x00lib_stop_link_tuner(struct rt2x00_dev *rt2x00dev)
93 cancel_delayed_work_sync(&rt2x00dev->link.work); 112 cancel_delayed_work_sync(&rt2x00dev->link.work);
94} 113}
95 114
96void rt2x00lib_reset_link_tuner(struct rt2x00_dev *rt2x00dev)
97{
98 if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
99 return;
100
101 rt2x00lib_stop_link_tuner(rt2x00dev);
102 rt2x00lib_start_link_tuner(rt2x00dev);
103}
104
105/* 115/*
106 * Ring initialization 116 * Ring initialization
107 */ 117 */
@@ -260,19 +270,11 @@ static void rt2x00lib_evaluate_antenna_sample(struct rt2x00_dev *rt2x00dev)
260 if (sample_a == sample_b) 270 if (sample_a == sample_b)
261 return; 271 return;
262 272
263 if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) { 273 if (rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY)
264 if (sample_a > sample_b && rx == ANTENNA_B) 274 rx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B;
265 rx = ANTENNA_A;
266 else if (rx == ANTENNA_A)
267 rx = ANTENNA_B;
268 }
269 275
270 if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY) { 276 if (rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)
271 if (sample_a > sample_b && tx == ANTENNA_B) 277 tx = (sample_a > sample_b) ? ANTENNA_A : ANTENNA_B;
272 tx = ANTENNA_A;
273 else if (tx == ANTENNA_A)
274 tx = ANTENNA_B;
275 }
276 278
277 rt2x00lib_config_antenna(rt2x00dev, rx, tx); 279 rt2x00lib_config_antenna(rt2x00dev, rx, tx);
278} 280}
@@ -293,7 +295,7 @@ static void rt2x00lib_evaluate_antenna_eval(struct rt2x00_dev *rt2x00dev)
293 * sample the rssi from the other antenna to make a valid 295 * sample the rssi from the other antenna to make a valid
294 * comparison between the 2 antennas. 296 * comparison between the 2 antennas.
295 */ 297 */
296 if ((rssi_curr - rssi_old) > -5 || (rssi_curr - rssi_old) < 5) 298 if (abs(rssi_curr - rssi_old) < 5)
297 return; 299 return;
298 300
299 rt2x00dev->link.ant.flags |= ANTENNA_MODE_SAMPLE; 301 rt2x00dev->link.ant.flags |= ANTENNA_MODE_SAMPLE;
@@ -319,15 +321,15 @@ static void rt2x00lib_evaluate_antenna(struct rt2x00_dev *rt2x00dev)
319 rt2x00dev->link.ant.flags &= ~ANTENNA_TX_DIVERSITY; 321 rt2x00dev->link.ant.flags &= ~ANTENNA_TX_DIVERSITY;
320 322
321 if (rt2x00dev->hw->conf.antenna_sel_rx == 0 && 323 if (rt2x00dev->hw->conf.antenna_sel_rx == 0 &&
322 rt2x00dev->default_ant.rx != ANTENNA_SW_DIVERSITY) 324 rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
323 rt2x00dev->link.ant.flags |= ANTENNA_RX_DIVERSITY; 325 rt2x00dev->link.ant.flags |= ANTENNA_RX_DIVERSITY;
324 if (rt2x00dev->hw->conf.antenna_sel_tx == 0 && 326 if (rt2x00dev->hw->conf.antenna_sel_tx == 0 &&
325 rt2x00dev->default_ant.tx != ANTENNA_SW_DIVERSITY) 327 rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
326 rt2x00dev->link.ant.flags |= ANTENNA_TX_DIVERSITY; 328 rt2x00dev->link.ant.flags |= ANTENNA_TX_DIVERSITY;
327 329
328 if (!(rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) && 330 if (!(rt2x00dev->link.ant.flags & ANTENNA_RX_DIVERSITY) &&
329 !(rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)) { 331 !(rt2x00dev->link.ant.flags & ANTENNA_TX_DIVERSITY)) {
330 rt2x00dev->link.ant.flags &= ~ANTENNA_MODE_SAMPLE; 332 rt2x00dev->link.ant.flags = 0;
331 return; 333 return;
332 } 334 }
333 335
@@ -441,17 +443,18 @@ static void rt2x00lib_link_tuner(struct work_struct *work)
441 rt2x00dev->ops->lib->link_tuner(rt2x00dev); 443 rt2x00dev->ops->lib->link_tuner(rt2x00dev);
442 444
443 /* 445 /*
444 * Evaluate antenna setup.
445 */
446 rt2x00lib_evaluate_antenna(rt2x00dev);
447
448 /*
449 * Precalculate a portion of the link signal which is 446 * Precalculate a portion of the link signal which is
450 * in based on the tx/rx success/failure counters. 447 * in based on the tx/rx success/failure counters.
451 */ 448 */
452 rt2x00lib_precalculate_link_signal(&rt2x00dev->link.qual); 449 rt2x00lib_precalculate_link_signal(&rt2x00dev->link.qual);
453 450
454 /* 451 /*
452 * Evaluate antenna setup, make this the last step since this could
453 * possibly reset some statistics.
454 */
455 rt2x00lib_evaluate_antenna(rt2x00dev);
456
457 /*
455 * Increase tuner counter, and reschedule the next link tuner run. 458 * Increase tuner counter, and reschedule the next link tuner run.
456 */ 459 */
457 rt2x00dev->link.count++; 460 rt2x00dev->link.count++;