Lines Matching +full:tuning +full:- +full:step

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
10 Abstract: rt2x00 generic link tuning routines.
20 * When we lack RSSI information return something less then -80 to
23 #define DEFAULT_RSSI -128
31 return -avg; in rt2x00link_get_avg_rssi()
38 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00link_antenna_get_link_rssi()
40 if (rt2x00dev->link.qual.rx_success) in rt2x00link_antenna_get_link_rssi()
41 return rt2x00link_get_avg_rssi(&ant->rssi_ant); in rt2x00link_antenna_get_link_rssi()
48 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00link_antenna_get_rssi_history()
50 if (ant->rssi_history) in rt2x00link_antenna_get_rssi_history()
51 return ant->rssi_history; in rt2x00link_antenna_get_rssi_history()
58 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00link_antenna_update_rssi_history()
59 ant->rssi_history = rssi; in rt2x00link_antenna_update_rssi_history()
64 ewma_rssi_init(&rt2x00dev->link.ant.rssi_ant); in rt2x00link_antenna_reset()
69 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00lib_antenna_diversity_sample()
76 memcpy(&new_ant, &ant->active, sizeof(new_ant)); in rt2x00lib_antenna_diversity_sample()
81 ant->flags &= ~ANTENNA_MODE_SAMPLE; in rt2x00lib_antenna_diversity_sample()
97 other_antenna = (ant->active.rx == ANTENNA_A) ? ANTENNA_B : ANTENNA_A; in rt2x00lib_antenna_diversity_sample()
99 if (ant->flags & ANTENNA_RX_DIVERSITY) in rt2x00lib_antenna_diversity_sample()
102 if (ant->flags & ANTENNA_TX_DIVERSITY) in rt2x00lib_antenna_diversity_sample()
110 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00lib_antenna_diversity_eval()
115 memcpy(&new_ant, &ant->active, sizeof(new_ant)); in rt2x00lib_antenna_diversity_eval()
134 if (abs(rssi_curr - rssi_old) < 5) in rt2x00lib_antenna_diversity_eval()
137 ant->flags |= ANTENNA_MODE_SAMPLE; in rt2x00lib_antenna_diversity_eval()
139 if (ant->flags & ANTENNA_RX_DIVERSITY) in rt2x00lib_antenna_diversity_eval()
142 if (ant->flags & ANTENNA_TX_DIVERSITY) in rt2x00lib_antenna_diversity_eval()
150 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00lib_antenna_diversity()
156 if (!(ant->flags & ANTENNA_RX_DIVERSITY) && in rt2x00lib_antenna_diversity()
157 !(ant->flags & ANTENNA_TX_DIVERSITY)) { in rt2x00lib_antenna_diversity()
158 ant->flags = 0; in rt2x00lib_antenna_diversity()
168 if (ant->flags & ANTENNA_MODE_SAMPLE) { in rt2x00lib_antenna_diversity()
171 } else if (rt2x00dev->link.count & 1) { in rt2x00lib_antenna_diversity()
183 struct link *link = &rt2x00dev->link; in rt2x00link_update_stats()
184 struct link_qual *qual = &rt2x00dev->link.qual; in rt2x00link_update_stats()
185 struct link_ant *ant = &rt2x00dev->link.ant; in rt2x00link_update_stats()
186 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; in rt2x00link_update_stats()
191 if (!rt2x00dev->intf_sta_count) in rt2x00link_update_stats()
195 * Frame was received successfully since non-successful in rt2x00link_update_stats()
198 qual->rx_success++; in rt2x00link_update_stats()
205 if (!ieee80211_is_beacon(hdr->frame_control) || in rt2x00link_update_stats()
206 !(rxdesc->dev_flags & RXDONE_MY_BSS)) in rt2x00link_update_stats()
212 ewma_rssi_add(&link->avg_rssi, -rxdesc->rssi); in rt2x00link_update_stats()
217 ewma_rssi_add(&ant->rssi_ant, -rxdesc->rssi); in rt2x00link_update_stats()
222 struct link *link = &rt2x00dev->link; in rt2x00link_start_tuner()
228 if (!rt2x00dev->intf_ap_count && !rt2x00dev->intf_sta_count) in rt2x00link_start_tuner()
232 * While scanning, link tuning is disabled. By default in rt2x00link_start_tuner()
237 if (test_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags)) in rt2x00link_start_tuner()
242 if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags)) in rt2x00link_start_tuner()
243 ieee80211_queue_delayed_work(rt2x00dev->hw, in rt2x00link_start_tuner()
244 &link->work, LINK_TUNE_INTERVAL); in rt2x00link_start_tuner()
249 cancel_delayed_work_sync(&rt2x00dev->link.work); in rt2x00link_stop_tuner()
254 struct link_qual *qual = &rt2x00dev->link.qual; in rt2x00link_reset_tuner()
255 u8 vgc_level = qual->vgc_level_reg; in rt2x00link_reset_tuner()
257 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) in rt2x00link_reset_tuner()
265 * device should only perform link tuning during the in rt2x00link_reset_tuner()
268 rt2x00dev->link.count = 0; in rt2x00link_reset_tuner()
270 ewma_rssi_init(&rt2x00dev->link.avg_rssi); in rt2x00link_reset_tuner()
277 qual->vgc_level_reg = vgc_level; in rt2x00link_reset_tuner()
282 rt2x00dev->ops->lib->reset_tuner(rt2x00dev, qual); in rt2x00link_reset_tuner()
290 struct link_qual *qual = &rt2x00dev->link.qual; in rt2x00link_reset_qual()
292 qual->rx_success = 0; in rt2x00link_reset_qual()
293 qual->rx_failed = 0; in rt2x00link_reset_qual()
294 qual->tx_success = 0; in rt2x00link_reset_qual()
295 qual->tx_failed = 0; in rt2x00link_reset_qual()
300 struct link_qual *qual = &rt2x00dev->link.qual; in rt2x00link_tuner_sta()
305 rt2x00dev->ops->lib->link_stats(rt2x00dev, qual); in rt2x00link_tuner_sta()
306 rt2x00dev->low_level_stats.dot11FCSErrorCount += qual->rx_failed; in rt2x00link_tuner_sta()
309 * Update quality RSSI for link tuning, in rt2x00link_tuner_sta()
314 if (!qual->rx_success) in rt2x00link_tuner_sta()
315 qual->rssi = DEFAULT_RSSI; in rt2x00link_tuner_sta()
317 qual->rssi = rt2x00link_get_avg_rssi(&link->avg_rssi); in rt2x00link_tuner_sta()
320 * Check if link tuning is supported by the hardware, some hardware in rt2x00link_tuner_sta()
321 * do not support link tuning at all, while other devices can disable in rt2x00link_tuner_sta()
325 rt2x00dev->ops->lib->link_tuner(rt2x00dev, qual, link->count); in rt2x00link_tuner_sta()
330 rt2x00leds_led_quality(rt2x00dev, qual->rssi); in rt2x00link_tuner_sta()
333 * Evaluate antenna setup, make this the last step when in rt2x00link_tuner_sta()
345 struct link *link = &rt2x00dev->link; in rt2x00link_tuner()
349 * immediately cease all link tuning. in rt2x00link_tuner()
351 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags) || in rt2x00link_tuner()
352 test_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags)) in rt2x00link_tuner()
356 mutex_lock(&rt2x00dev->conf_mutex); in rt2x00link_tuner()
358 if (rt2x00dev->intf_sta_count) in rt2x00link_tuner()
361 if (rt2x00dev->ops->lib->gain_calibration && in rt2x00link_tuner()
362 (link->count % (AGC_SECONDS / LINK_TUNE_SECONDS)) == 0) in rt2x00link_tuner()
363 rt2x00dev->ops->lib->gain_calibration(rt2x00dev); in rt2x00link_tuner()
365 if (rt2x00dev->ops->lib->vco_calibration && in rt2x00link_tuner()
367 (link->count % (VCO_SECONDS / LINK_TUNE_SECONDS)) == 0) in rt2x00link_tuner()
368 rt2x00dev->ops->lib->vco_calibration(rt2x00dev); in rt2x00link_tuner()
370 mutex_unlock(&rt2x00dev->conf_mutex); in rt2x00link_tuner()
375 link->count++; in rt2x00link_tuner()
377 if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags)) in rt2x00link_tuner()
378 ieee80211_queue_delayed_work(rt2x00dev->hw, in rt2x00link_tuner()
379 &link->work, LINK_TUNE_INTERVAL); in rt2x00link_tuner()
384 struct link *link = &rt2x00dev->link; in rt2x00link_start_watchdog()
386 if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags) && in rt2x00link_start_watchdog()
387 rt2x00dev->ops->lib->watchdog && link->watchdog) in rt2x00link_start_watchdog()
388 ieee80211_queue_delayed_work(rt2x00dev->hw, in rt2x00link_start_watchdog()
389 &link->watchdog_work, in rt2x00link_start_watchdog()
390 link->watchdog_interval); in rt2x00link_start_watchdog()
395 cancel_delayed_work_sync(&rt2x00dev->link.watchdog_work); in rt2x00link_stop_watchdog()
402 struct link *link = &rt2x00dev->link; in rt2x00link_watchdog()
408 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) in rt2x00link_watchdog()
411 rt2x00dev->ops->lib->watchdog(rt2x00dev); in rt2x00link_watchdog()
413 if (test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags)) in rt2x00link_watchdog()
414 ieee80211_queue_delayed_work(rt2x00dev->hw, in rt2x00link_watchdog()
415 &link->watchdog_work, in rt2x00link_watchdog()
416 link->watchdog_interval); in rt2x00link_watchdog()
421 struct link *link = &rt2x00dev->link; in rt2x00link_register()
423 INIT_DELAYED_WORK(&link->work, rt2x00link_tuner); in rt2x00link_register()
424 INIT_DELAYED_WORK(&link->watchdog_work, rt2x00link_watchdog); in rt2x00link_register()
426 if (link->watchdog_interval == 0) in rt2x00link_register()
427 link->watchdog_interval = WATCHDOG_INTERVAL; in rt2x00link_register()