blob: fc6b075ad6353ee908675dcf7a89b70c2f7345f7 [file] [log] [blame]
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +05301/*
2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "ath9k.h"
18
19/*
20 * TX polling - checks if the TX engine is stuck somewhere
21 * and issues a chip reset if so.
22 */
23void ath_tx_complete_poll_work(struct work_struct *work)
24{
25 struct ath_softc *sc = container_of(work, struct ath_softc,
26 tx_complete_work.work);
27 struct ath_txq *txq;
28 int i;
29 bool needreset = false;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +053030
31 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
32 if (ATH_TXQ_SETUP(sc, i)) {
33 txq = &sc->tx.txq[i];
34 ath_txq_lock(sc, txq);
35 if (txq->axq_depth) {
36 if (txq->axq_tx_inprogress) {
37 needreset = true;
38 ath_txq_unlock(sc, txq);
39 break;
40 } else {
41 txq->axq_tx_inprogress = true;
42 }
43 }
44 ath_txq_unlock_complete(sc, txq);
45 }
46
47 if (needreset) {
48 ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
49 "tx hung, resetting the chip\n");
Rajkumar Manoharan124b9792012-07-17 17:16:42 +053050 ath9k_queue_reset(sc, RESET_TYPE_TX_HANG);
Sujith Manoharanaf68aba2012-06-04 20:23:43 +053051 return;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +053052 }
53
54 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
55 msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
56}
57
58/*
59 * Checks if the BB/MAC is hung.
60 */
61void ath_hw_check(struct work_struct *work)
62{
63 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
64 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
65 unsigned long flags;
66 int busy;
67 u8 is_alive, nbeacon = 1;
Rajkumar Manoharan124b9792012-07-17 17:16:42 +053068 enum ath_reset_type type;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +053069
70 ath9k_ps_wakeup(sc);
71 is_alive = ath9k_hw_check_alive(sc->sc_ah);
72
73 if (is_alive && !AR_SREV_9300(sc->sc_ah))
74 goto out;
75 else if (!is_alive && AR_SREV_9300(sc->sc_ah)) {
76 ath_dbg(common, RESET,
77 "DCU stuck is detected. Schedule chip reset\n");
Rajkumar Manoharan124b9792012-07-17 17:16:42 +053078 type = RESET_TYPE_MAC_HANG;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +053079 goto sched_reset;
80 }
81
82 spin_lock_irqsave(&common->cc_lock, flags);
83 busy = ath_update_survey_stats(sc);
84 spin_unlock_irqrestore(&common->cc_lock, flags);
85
86 ath_dbg(common, RESET, "Possible baseband hang, busy=%d (try %d)\n",
87 busy, sc->hw_busy_count + 1);
88 if (busy >= 99) {
89 if (++sc->hw_busy_count >= 3) {
Rajkumar Manoharan124b9792012-07-17 17:16:42 +053090 type = RESET_TYPE_BB_HANG;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +053091 goto sched_reset;
92 }
93 } else if (busy >= 0) {
94 sc->hw_busy_count = 0;
95 nbeacon = 3;
96 }
97
98 ath_start_rx_poll(sc, nbeacon);
99 goto out;
100
101sched_reset:
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530102 ath9k_queue_reset(sc, type);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530103out:
104 ath9k_ps_restore(sc);
105}
106
107/*
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530108 * PLL-WAR for AR9485/AR9340
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530109 */
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530110static bool ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530111{
112 static int count;
113 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
114
115 if (pll_sqsum >= 0x40000) {
116 count++;
117 if (count == 3) {
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530118 ath_dbg(common, RESET, "PLL WAR, resetting the chip\n");
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530119 ath9k_queue_reset(sc, RESET_TYPE_PLL_HANG);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530120 count = 0;
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530121 return true;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530122 }
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530123 } else {
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530124 count = 0;
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530125 }
126
127 return false;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530128}
129
130void ath_hw_pll_work(struct work_struct *work)
131{
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530132 u32 pll_sqsum;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530133 struct ath_softc *sc = container_of(work, struct ath_softc,
134 hw_pll_work.work);
Mohammed Shafi Shajakhan64bc1232012-06-12 20:13:43 +0530135 /*
136 * ensure that the PLL WAR is executed only
137 * after the STA is associated (or) if the
138 * beaconing had started in interfaces that
139 * uses beacons.
140 */
141 if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
142 return;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530143
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530144 ath9k_ps_wakeup(sc);
145 pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
146 ath9k_ps_restore(sc);
147 if (ath_hw_pll_rx_hang_check(sc, pll_sqsum))
148 return;
149
150 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
151 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530152}
153
154/*
155 * RX Polling - monitors baseband hangs.
156 */
157void ath_start_rx_poll(struct ath_softc *sc, u8 nbeacon)
158{
159 if (!AR_SREV_9300(sc->sc_ah))
160 return;
161
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530162 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530163 return;
164
165 mod_timer(&sc->rx_poll_timer, jiffies + msecs_to_jiffies
166 (nbeacon * sc->cur_beacon_conf.beacon_interval));
167}
168
169void ath_rx_poll(unsigned long data)
170{
171 struct ath_softc *sc = (struct ath_softc *)data;
172
173 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
174}
175
176/*
177 * PA Pre-distortion.
178 */
179static void ath_paprd_activate(struct ath_softc *sc)
180{
181 struct ath_hw *ah = sc->sc_ah;
182 struct ath9k_hw_cal_data *caldata = ah->caldata;
183 int chain;
184
185 if (!caldata || !caldata->paprd_done)
186 return;
187
188 ath9k_ps_wakeup(sc);
189 ar9003_paprd_enable(ah, false);
190 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
191 if (!(ah->txchainmask & BIT(chain)))
192 continue;
193
194 ar9003_paprd_populate_single_table(ah, caldata, chain);
195 }
196
197 ar9003_paprd_enable(ah, true);
198 ath9k_ps_restore(sc);
199}
200
201static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int chain)
202{
203 struct ieee80211_hw *hw = sc->hw;
204 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
205 struct ath_hw *ah = sc->sc_ah;
206 struct ath_common *common = ath9k_hw_common(ah);
207 struct ath_tx_control txctl;
208 int time_left;
209
210 memset(&txctl, 0, sizeof(txctl));
Sujith Manoharanbea843c2012-11-21 18:13:10 +0530211 txctl.txq = sc->tx.txq_map[IEEE80211_AC_BE];
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530212
213 memset(tx_info, 0, sizeof(*tx_info));
214 tx_info->band = hw->conf.channel->band;
215 tx_info->flags |= IEEE80211_TX_CTL_NO_ACK;
216 tx_info->control.rates[0].idx = 0;
217 tx_info->control.rates[0].count = 1;
218 tx_info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
219 tx_info->control.rates[1].idx = -1;
220
221 init_completion(&sc->paprd_complete);
222 txctl.paprd = BIT(chain);
223
224 if (ath_tx_start(hw, skb, &txctl) != 0) {
225 ath_dbg(common, CALIBRATE, "PAPRD TX failed\n");
226 dev_kfree_skb_any(skb);
227 return false;
228 }
229
230 time_left = wait_for_completion_timeout(&sc->paprd_complete,
231 msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
232
233 if (!time_left)
234 ath_dbg(common, CALIBRATE,
235 "Timeout waiting for paprd training on TX chain %d\n",
236 chain);
237
238 return !!time_left;
239}
240
241void ath_paprd_calibrate(struct work_struct *work)
242{
243 struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
244 struct ieee80211_hw *hw = sc->hw;
245 struct ath_hw *ah = sc->sc_ah;
246 struct ieee80211_hdr *hdr;
247 struct sk_buff *skb = NULL;
248 struct ath9k_hw_cal_data *caldata = ah->caldata;
249 struct ath_common *common = ath9k_hw_common(ah);
250 int ftype;
251 int chain_ok = 0;
252 int chain;
253 int len = 1800;
Felix Fietkau381c7262012-08-27 17:00:05 +0200254 int ret;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530255
Felix Fietkau51dea9b2012-08-27 17:00:07 +0200256 if (!caldata || !caldata->paprd_packet_sent || caldata->paprd_done)
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530257 return;
258
259 ath9k_ps_wakeup(sc);
260
261 if (ar9003_paprd_init_table(ah) < 0)
262 goto fail_paprd;
263
264 skb = alloc_skb(len, GFP_KERNEL);
265 if (!skb)
266 goto fail_paprd;
267
268 skb_put(skb, len);
269 memset(skb->data, 0, len);
270 hdr = (struct ieee80211_hdr *)skb->data;
271 ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
272 hdr->frame_control = cpu_to_le16(ftype);
273 hdr->duration_id = cpu_to_le16(10);
274 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
275 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
276 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
277
278 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
279 if (!(ah->txchainmask & BIT(chain)))
280 continue;
281
282 chain_ok = 0;
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530283 ar9003_paprd_setup_gain_table(ah, chain);
284
285 ath_dbg(common, CALIBRATE,
286 "Sending PAPRD training frame on chain %d\n", chain);
287 if (!ath_paprd_send_frame(sc, skb, chain))
288 goto fail_paprd;
289
290 if (!ar9003_paprd_is_done(ah)) {
291 ath_dbg(common, CALIBRATE,
292 "PAPRD not yet done on chain %d\n", chain);
293 break;
294 }
295
Felix Fietkau381c7262012-08-27 17:00:05 +0200296 ret = ar9003_paprd_create_curve(ah, caldata, chain);
297 if (ret == -EINPROGRESS) {
298 ath_dbg(common, CALIBRATE,
299 "PAPRD curve on chain %d needs to be re-trained\n",
300 chain);
301 break;
302 } else if (ret) {
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530303 ath_dbg(common, CALIBRATE,
304 "PAPRD create curve failed on chain %d\n",
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530305 chain);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530306 break;
307 }
308
309 chain_ok = 1;
310 }
311 kfree_skb(skb);
312
313 if (chain_ok) {
314 caldata->paprd_done = true;
315 ath_paprd_activate(sc);
316 }
317
318fail_paprd:
319 ath9k_ps_restore(sc);
320}
321
322/*
323 * ANI performs periodic noise floor calibration
324 * that is used to adjust and optimize the chip performance. This
325 * takes environmental changes (location, temperature) into account.
326 * When the task is complete, it reschedules itself depending on the
327 * appropriate interval that was calculated.
328 */
329void ath_ani_calibrate(unsigned long data)
330{
331 struct ath_softc *sc = (struct ath_softc *)data;
332 struct ath_hw *ah = sc->sc_ah;
333 struct ath_common *common = ath9k_hw_common(ah);
334 bool longcal = false;
335 bool shortcal = false;
336 bool aniflag = false;
337 unsigned int timestamp = jiffies_to_msecs(jiffies);
338 u32 cal_interval, short_cal_interval, long_cal_interval;
339 unsigned long flags;
340
341 if (ah->caldata && ah->caldata->nfcal_interference)
342 long_cal_interval = ATH_LONG_CALINTERVAL_INT;
343 else
344 long_cal_interval = ATH_LONG_CALINTERVAL;
345
346 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
347 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
348
349 /* Only calibrate if awake */
Rajkumar Manoharan424749c2012-10-10 23:03:02 +0530350 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) {
351 if (++ah->ani_skip_count >= ATH_ANI_MAX_SKIP_COUNT) {
352 spin_lock_irqsave(&sc->sc_pm_lock, flags);
353 sc->ps_flags |= PS_WAIT_FOR_ANI;
354 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
355 }
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530356 goto set_timer;
Rajkumar Manoharan424749c2012-10-10 23:03:02 +0530357 }
358 ah->ani_skip_count = 0;
359 spin_lock_irqsave(&sc->sc_pm_lock, flags);
360 sc->ps_flags &= ~PS_WAIT_FOR_ANI;
361 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530362
363 ath9k_ps_wakeup(sc);
364
365 /* Long calibration runs independently of short calibration. */
366 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
367 longcal = true;
368 common->ani.longcal_timer = timestamp;
369 }
370
371 /* Short calibration applies only while caldone is false */
372 if (!common->ani.caldone) {
373 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
374 shortcal = true;
375 common->ani.shortcal_timer = timestamp;
376 common->ani.resetcal_timer = timestamp;
377 }
378 } else {
379 if ((timestamp - common->ani.resetcal_timer) >=
380 ATH_RESTART_CALINTERVAL) {
381 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
382 if (common->ani.caldone)
383 common->ani.resetcal_timer = timestamp;
384 }
385 }
386
387 /* Verify whether we must check ANI */
388 if (sc->sc_ah->config.enable_ani
389 && (timestamp - common->ani.checkani_timer) >=
390 ah->config.ani_poll_interval) {
391 aniflag = true;
392 common->ani.checkani_timer = timestamp;
393 }
394
395 /* Call ANI routine if necessary */
396 if (aniflag) {
397 spin_lock_irqsave(&common->cc_lock, flags);
398 ath9k_hw_ani_monitor(ah, ah->curchan);
399 ath_update_survey_stats(sc);
400 spin_unlock_irqrestore(&common->cc_lock, flags);
401 }
402
403 /* Perform calibration if necessary */
404 if (longcal || shortcal) {
405 common->ani.caldone =
406 ath9k_hw_calibrate(ah, ah->curchan,
407 ah->rxchainmask, longcal);
408 }
409
410 ath_dbg(common, ANI,
411 "Calibration @%lu finished: %s %s %s, caldone: %s\n",
412 jiffies,
413 longcal ? "long" : "", shortcal ? "short" : "",
414 aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
415
Rajkumar Manoharan5039f382012-06-19 14:50:28 +0530416 ath9k_debug_samp_bb_mac(sc);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530417 ath9k_ps_restore(sc);
418
419set_timer:
420 /*
421 * Set timer interval based on previous results.
422 * The interval must be the shortest necessary to satisfy ANI,
423 * short calibration and long calibration.
424 */
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530425 cal_interval = ATH_LONG_CALINTERVAL;
426 if (sc->sc_ah->config.enable_ani)
427 cal_interval = min(cal_interval,
428 (u32)ah->config.ani_poll_interval);
429 if (!common->ani.caldone)
430 cal_interval = min(cal_interval, (u32)short_cal_interval);
431
432 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Felix Fietkau74673db2012-09-08 15:24:17 +0200433 if (ah->eep_ops->get_eeprom(ah, EEP_PAPRD) && ah->caldata) {
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530434 if (!ah->caldata->paprd_done)
435 ieee80211_queue_work(sc->hw, &sc->paprd_work);
436 else if (!ah->paprd_table_write_done)
437 ath_paprd_activate(sc);
438 }
439}
440
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530441void ath_start_ani(struct ath_softc *sc)
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530442{
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530443 struct ath_hw *ah = sc->sc_ah;
444 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530445 unsigned long timestamp = jiffies_to_msecs(jiffies);
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530446
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530447 if (common->disable_ani ||
448 !test_bit(SC_OP_ANI_RUN, &sc->sc_flags) ||
449 (sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530450 return;
451
452 common->ani.longcal_timer = timestamp;
453 common->ani.shortcal_timer = timestamp;
454 common->ani.checkani_timer = timestamp;
455
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530456 ath_dbg(common, ANI, "Starting ANI\n");
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530457 mod_timer(&common->ani.timer,
458 jiffies + msecs_to_jiffies((u32)ah->config.ani_poll_interval));
459}
460
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530461void ath_stop_ani(struct ath_softc *sc)
462{
463 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
464
465 ath_dbg(common, ANI, "Stopping ANI\n");
466 del_timer_sync(&common->ani.timer);
467}
468
469void ath_check_ani(struct ath_softc *sc)
470{
471 struct ath_hw *ah = sc->sc_ah;
472 struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
473
474 /*
475 * Check for the various conditions in which ANI has to
476 * be stopped.
477 */
478 if (ah->opmode == NL80211_IFTYPE_ADHOC) {
479 if (!cur_conf->enable_beacon)
480 goto stop_ani;
481 } else if (ah->opmode == NL80211_IFTYPE_AP) {
482 if (!cur_conf->enable_beacon) {
483 /*
484 * Disable ANI only when there are no
485 * associated stations.
486 */
487 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
488 goto stop_ani;
489 }
490 } else if (ah->opmode == NL80211_IFTYPE_STATION) {
491 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
492 goto stop_ani;
493 }
494
495 if (!test_bit(SC_OP_ANI_RUN, &sc->sc_flags)) {
496 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
497 ath_start_ani(sc);
498 }
499
500 return;
501
502stop_ani:
503 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
504 ath_stop_ani(sc);
505}
506
Sujith Manoharanef1b6cd2012-06-04 20:23:37 +0530507void ath_update_survey_nf(struct ath_softc *sc, int channel)
508{
509 struct ath_hw *ah = sc->sc_ah;
510 struct ath9k_channel *chan = &ah->channels[channel];
511 struct survey_info *survey = &sc->survey[channel];
512
513 if (chan->noisefloor) {
514 survey->filled |= SURVEY_INFO_NOISE_DBM;
515 survey->noise = ath9k_hw_getchan_noise(ah, chan);
516 }
517}
518
519/*
520 * Updates the survey statistics and returns the busy time since last
521 * update in %, if the measurement duration was long enough for the
522 * result to be useful, -1 otherwise.
523 */
524int ath_update_survey_stats(struct ath_softc *sc)
525{
526 struct ath_hw *ah = sc->sc_ah;
527 struct ath_common *common = ath9k_hw_common(ah);
528 int pos = ah->curchan - &ah->channels[0];
529 struct survey_info *survey = &sc->survey[pos];
530 struct ath_cycle_counters *cc = &common->cc_survey;
531 unsigned int div = common->clockrate * 1000;
532 int ret = 0;
533
534 if (!ah->curchan)
535 return -1;
536
537 if (ah->power_mode == ATH9K_PM_AWAKE)
538 ath_hw_cycle_counters_update(common);
539
540 if (cc->cycles > 0) {
541 survey->filled |= SURVEY_INFO_CHANNEL_TIME |
542 SURVEY_INFO_CHANNEL_TIME_BUSY |
543 SURVEY_INFO_CHANNEL_TIME_RX |
544 SURVEY_INFO_CHANNEL_TIME_TX;
545 survey->channel_time += cc->cycles / div;
546 survey->channel_time_busy += cc->rx_busy / div;
547 survey->channel_time_rx += cc->rx_frame / div;
548 survey->channel_time_tx += cc->tx_frame / div;
549 }
550
551 if (cc->cycles < div)
552 return -1;
553
554 if (cc->cycles > 0)
555 ret = cc->rx_busy * 100 / cc->cycles;
556
557 memset(cc, 0, sizeof(*cc));
558
559 ath_update_survey_nf(sc, pos);
560
561 return ret;
562}