FreeBSD kernel ATH device code
ar5416_cal.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: ISC
3 *
4 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * $FreeBSD$
20 */
21#include "opt_ah.h"
22
23#include "ah.h"
24#include "ah_internal.h"
25#include "ah_devid.h"
26
27#include "ah_eeprom_v14.h"
28
29#include "ar5212/ar5212.h" /* for NF cal related declarations */
30
31#include "ar5416/ar5416.h"
32#include "ar5416/ar5416reg.h"
33#include "ar5416/ar5416phy.h"
34
35/* Owl specific stuff */
36#define NUM_NOISEFLOOR_READINGS 6 /* 3 chains * (ctl + ext) */
37
38static void ar5416StartNFCal(struct ath_hal *ah);
39static HAL_BOOL ar5416LoadNF(struct ath_hal *ah, const struct ieee80211_channel *);
40static int16_t ar5416GetNf(struct ath_hal *, struct ieee80211_channel *);
41
42static uint16_t ar5416GetDefaultNF(struct ath_hal *ah, const struct ieee80211_channel *chan);
43static void ar5416SanitizeNF(struct ath_hal *ah, int16_t *nf);
44
45/*
46 * Determine if calibration is supported by device and channel flags
47 */
48
49/*
50 * ADC GAIN/DC offset calibration is for calibrating two ADCs that
51 * are acting as one by interleaving incoming symbols. This isn't
52 * relevant for 2.4GHz 20MHz wide modes because, as far as I can tell,
53 * the secondary ADC is never enabled. It is enabled however for
54 * 5GHz modes.
55 *
56 * It hasn't been confirmed whether doing this calibration is needed
57 * at all in the above modes and/or whether it's actually harmful.
58 * So for now, let's leave it enabled and just remember to get
59 * confirmation that it needs to be clarified.
60 *
61 * See US Patent No: US 7,541,952 B1:
62 * " Method and Apparatus for Offset and Gain Compensation for
63 * Analog-to-Digital Converters."
64 */
66ar5416IsCalSupp(struct ath_hal *ah, const struct ieee80211_channel *chan,
67 HAL_CAL_TYPE calType)
68{
69 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
70
71 switch (calType & cal->suppCals) {
72 case IQ_MISMATCH_CAL:
73 /* Run IQ Mismatch for non-CCK only */
74 return !IEEE80211_IS_CHAN_B(chan);
75 case ADC_GAIN_CAL:
76 case ADC_DC_CAL:
77 /*
78 * Run ADC Gain Cal for either 5ghz any or 2ghz HT40.
79 *
80 * Don't run ADC calibrations for 5ghz fast clock mode
81 * in HT20 - only one ADC is used.
82 */
83 if (IEEE80211_IS_CHAN_HT20(chan) &&
84 (IS_5GHZ_FAST_CLOCK_EN(ah, chan)))
85 return AH_FALSE;
86 if (IEEE80211_IS_CHAN_5GHZ(chan))
87 return AH_TRUE;
88 if (IEEE80211_IS_CHAN_HT40(chan))
89 return AH_TRUE;
90 return AH_FALSE;
91 }
92 return AH_FALSE;
93}
94
95/*
96 * Setup HW to collect samples used for current cal
97 */
98static void
100{
101 /* Start calibration w/ 2^(INIT_IQCAL_LOG_COUNT_MAX+1) samples */
104 currCal->calData->calCountMax);
105
106 /* Select calibration to run */
107 switch (currCal->calData->calType) {
108 case IQ_MISMATCH_CAL:
111 "%s: start IQ Mismatch calibration\n", __func__);
112 break;
113 case ADC_GAIN_CAL:
116 "%s: start ADC Gain calibration\n", __func__);
117 break;
118 case ADC_DC_CAL:
121 "%s: start ADC DC calibration\n", __func__);
122 break;
123 case ADC_DC_INIT_CAL:
126 "%s: start Init ADC DC calibration\n", __func__);
127 break;
128 }
129 /* Kick-off cal */
131}
132
133/*
134 * Initialize shared data structures and prepare a cal to be run.
135 */
136static void
138{
139 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
140
141 /* Reset data structures shared between different calibrations */
142 OS_MEMZERO(cal->caldata, sizeof(cal->caldata));
143 cal->calSamples = 0;
144
145 /* Setup HW for new calibration */
146 ar5416SetupMeasurement(ah, currCal);
147
148 /* Change SW state to RUNNING for this calibration */
149 currCal->calState = CAL_RUNNING;
150}
151
152#if 0
153/*
154 * Run non-periodic calibrations.
155 */
156static HAL_BOOL
157ar5416RunInitCals(struct ath_hal *ah, int init_cal_count)
158{
159 struct ath_hal_5416 *ahp = AH5416(ah);
160 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
161 HAL_CHANNEL_INTERNAL ichan; /* XXX bogus */
162 HAL_CAL_LIST *curCal = ahp->ah_cal_curr;
163 HAL_BOOL isCalDone;
164 int i;
165
166 if (curCal == AH_NULL)
167 return AH_FALSE;
168
169 ichan.calValid = 0;
170 for (i = 0; i < init_cal_count; i++) {
171 /* Reset this Cal */
172 ar5416ResetMeasurement(ah, curCal);
173 /* Poll for offset calibration complete */
176 "%s: Cal %d failed to finish in 100ms.\n",
177 __func__, curCal->calData->calType);
178 /* Re-initialize list pointers for periodic cals */
179 cal->cal_list = cal->cal_last = cal->cal_curr = AH_NULL;
180 return AH_FALSE;
181 }
182 /* Run this cal */
183 ar5416DoCalibration(ah, &ichan, ahp->ah_rxchainmask,
184 curCal, &isCalDone);
185 if (!isCalDone)
187 "%s: init cal %d did not complete.\n",
188 __func__, curCal->calData->calType);
189 if (curCal->calNext != AH_NULL)
190 curCal = curCal->calNext;
191 }
192
193 /* Re-initialize list pointers for periodic cals */
194 cal->cal_list = cal->cal_last = cal->cal_curr = AH_NULL;
195 return AH_TRUE;
196}
197#endif
198
199/*
200 * AGC calibration for the AR5416, AR9130, AR9160, AR9280.
201 */
203ar5416InitCalHardware(struct ath_hal *ah, const struct ieee80211_channel *chan)
204{
205
207 /* Disable ADC */
210
211 /* Enable Rx Filter Cal */
214 }
215
216 /* Calibrate the AGC */
218
219 /* Poll for offset calibration complete */
222 "%s: offset calibration did not complete in 1ms; "
223 "noisy environment?\n", __func__);
224 return AH_FALSE;
225 }
226
228 /* Enable ADC */
231
232 /* Disable Rx Filter Cal */
235 }
236
237 return AH_TRUE;
238}
239
240/*
241 * Initialize Calibration infrastructure.
242 */
243#define MAX_CAL_CHECK 32
245ar5416InitCal(struct ath_hal *ah, const struct ieee80211_channel *chan)
246{
247 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
249
250 ichan = ath_hal_checkchannel(ah, chan);
251 HALASSERT(ichan != AH_NULL);
252
253 /* Do initial chipset-specific calibration */
254 if (! AH5416(ah)->ah_cal_initcal(ah, chan)) {
256 "%s: initial chipset calibration did "
257 "not complete in time; noisy environment?\n", __func__);
258 return AH_FALSE;
259 }
260
261 /* If there's PA Cal, do it */
262 if (AH5416(ah)->ah_cal_pacal)
263 AH5416(ah)->ah_cal_pacal(ah, AH_TRUE);
264
265 /*
266 * Do NF calibration after DC offset and other CALs.
267 * Per system engineers, noise floor value can sometimes be 20 dB
268 * higher than normal value if DC offset and noise floor cal are
269 * triggered at the same time.
270 */
272
273 /*
274 * This may take a while to run; make sure subsequent
275 * calibration routines check that this has completed
276 * before reading the value and triggering a subsequent
277 * calibration.
278 */
279
280 /* Initialize list pointers */
281 cal->cal_list = cal->cal_last = cal->cal_curr = AH_NULL;
282
283 /*
284 * Enable IQ, ADC Gain, ADC DC Offset Cals
285 */
286 if (AR_SREV_HOWL(ah) || AR_SREV_SOWL_10_OR_LATER(ah)) {
287 /* Setup all non-periodic, init time only calibrations */
288 /* XXX: Init DC Offset not working yet */
289#if 0
290 if (ar5416IsCalSupp(ah, chan, ADC_DC_INIT_CAL)) {
292 INSERT_CAL(cal, &cal->adcDcCalInitData);
293 }
294 /* Initialize current pointer to first element in list */
295 cal->cal_curr = cal->cal_list;
296
297 if (cal->ah_cal_curr != AH_NULL && !ar5416RunInitCals(ah, 0))
298 return AH_FALSE;
299#endif
300 }
301
302 /* If Cals are supported, add them to list via INIT/INSERT_CAL */
303 if (ar5416IsCalSupp(ah, chan, ADC_GAIN_CAL)) {
305 INSERT_CAL(cal, &cal->adcGainCalData);
307 "%s: enable ADC Gain Calibration.\n", __func__);
308 }
309 if (ar5416IsCalSupp(ah, chan, ADC_DC_CAL)) {
310 INIT_CAL(&cal->adcDcCalData);
311 INSERT_CAL(cal, &cal->adcDcCalData);
313 "%s: enable ADC DC Calibration.\n", __func__);
314 }
315 if (ar5416IsCalSupp(ah, chan, IQ_MISMATCH_CAL)) {
316 INIT_CAL(&cal->iqCalData);
317 INSERT_CAL(cal, &cal->iqCalData);
319 "%s: enable IQ Calibration.\n", __func__);
320 }
321 /* Initialize current pointer to first element in list */
322 cal->cal_curr = cal->cal_list;
323
324 /* Kick off measurements for the first cal */
325 if (cal->cal_curr != AH_NULL)
327
328 /* Mark all calibrations on this channel as being invalid */
329 ichan->calValid = 0;
330
331 return AH_TRUE;
332#undef MAX_CAL_CHECK
333}
334
335/*
336 * Entry point for upper layers to restart current cal.
337 * Reset the calibration valid bit in channel.
338 */
340ar5416ResetCalValid(struct ath_hal *ah, const struct ieee80211_channel *chan)
341{
342 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
344 HAL_CAL_LIST *currCal = cal->cal_curr;
345
347 return AH_FALSE;
348 if (currCal == AH_NULL)
349 return AH_FALSE;
350 if (ichan == AH_NULL) {
352 "%s: invalid channel %u/0x%x; no mapping\n",
353 __func__, chan->ic_freq, chan->ic_flags);
354 return AH_FALSE;
355 }
356 /*
357 * Expected that this calibration has run before, post-reset.
358 * Current state should be done
359 */
360 if (currCal->calState != CAL_DONE) {
362 "%s: Calibration state incorrect, %d\n",
363 __func__, currCal->calState);
364 return AH_FALSE;
365 }
366
367 /* Verify Cal is supported on this channel */
368 if (!ar5416IsCalSupp(ah, chan, currCal->calData->calType))
369 return AH_FALSE;
370
372 "%s: Resetting Cal %d state for channel %u/0x%x\n",
373 __func__, currCal->calData->calType, chan->ic_freq,
374 chan->ic_flags);
375
376 /* Disable cal validity in channel */
377 ichan->calValid &= ~currCal->calData->calType;
378 currCal->calState = CAL_WAITING;
379
380 return AH_TRUE;
381}
382
383/*
384 * Recalibrate the lower PHY chips to account for temperature/environment
385 * changes.
386 */
387static void
389 uint8_t rxchainmask, HAL_CAL_LIST *currCal, HAL_BOOL *isCalDone)
390{
391 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
392
393 /* Cal is assumed not done until explicitly set below */
394 *isCalDone = AH_FALSE;
395
397 "%s: %s Calibration, state %d, calValid 0x%x\n",
398 __func__, currCal->calData->calName, currCal->calState,
399 ichan->calValid);
400
401 /* Calibration in progress. */
402 if (currCal->calState == CAL_RUNNING) {
403 /* Check to see if it has finished. */
406 "%s: sample %d of %d finished\n",
407 __func__, cal->calSamples,
408 currCal->calData->calNumSamples);
409 /*
410 * Collect measurements for active chains.
411 */
412 currCal->calData->calCollect(ah);
413 if (++cal->calSamples >= currCal->calData->calNumSamples) {
414 int i, numChains = 0;
415 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
416 if (rxchainmask & (1 << i))
417 numChains++;
418 }
419 /*
420 * Process accumulated data
421 */
422 currCal->calData->calPostProc(ah, numChains);
423
424 /* Calibration has finished. */
425 ichan->calValid |= currCal->calData->calType;
426 currCal->calState = CAL_DONE;
427 *isCalDone = AH_TRUE;
428 } else {
429 /*
430 * Set-up to collect of another sub-sample.
431 */
432 ar5416SetupMeasurement(ah, currCal);
433 }
434 }
435 } else if (!(ichan->calValid & currCal->calData->calType)) {
436 /* If current cal is marked invalid in channel, kick it off */
437 ar5416ResetMeasurement(ah, currCal);
438 }
439}
440
441/*
442 * Internal interface to schedule periodic calibration work.
443 */
445ar5416PerCalibrationN(struct ath_hal *ah, struct ieee80211_channel *chan,
446 u_int rxchainmask, HAL_BOOL longcal, HAL_BOOL *isCalDone)
447{
448 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
449 HAL_CAL_LIST *currCal = cal->cal_curr;
451 int r;
452
453 OS_MARK(ah, AH_MARK_PERCAL, chan->ic_freq);
454
455 *isCalDone = AH_TRUE;
456
457 /*
458 * Since ath_hal calls the PerCal method with rxchainmask=0x1;
459 * override it with the current chainmask. The upper levels currently
460 * doesn't know about the chainmask.
461 */
462 rxchainmask = AH5416(ah)->ah_rx_chainmask;
463
464 /* Invalid channel check */
465 ichan = ath_hal_checkchannel(ah, chan);
466 if (ichan == AH_NULL) {
468 "%s: invalid channel %u/0x%x; no mapping\n",
469 __func__, chan->ic_freq, chan->ic_flags);
470 return AH_FALSE;
471 }
472
473 /*
474 * For given calibration:
475 * 1. Call generic cal routine
476 * 2. When this cal is done (isCalDone) if we have more cals waiting
477 * (eg after reset), mask this to upper layers by not propagating
478 * isCalDone if it is set to TRUE.
479 * Instead, change isCalDone to FALSE and setup the waiting cal(s)
480 * to be run.
481 */
482 if (currCal != AH_NULL &&
483 (currCal->calState == CAL_RUNNING ||
484 currCal->calState == CAL_WAITING)) {
485 ar5416DoCalibration(ah, ichan, rxchainmask, currCal, isCalDone);
486 if (*isCalDone == AH_TRUE) {
487 cal->cal_curr = currCal = currCal->calNext;
488 if (currCal->calState == CAL_WAITING) {
489 *isCalDone = AH_FALSE;
490 ar5416ResetMeasurement(ah, currCal);
491 }
492 }
493 }
494
495 /* Do NF cal only at longer intervals */
496 if (longcal) {
497 /* Do PA calibration if the chipset supports */
498 if (AH5416(ah)->ah_cal_pacal)
499 AH5416(ah)->ah_cal_pacal(ah, AH_FALSE);
500
501 /* Do open-loop temperature compensation if the chipset needs it */
503 AH5416(ah)->ah_olcTempCompensation(ah);
504
505 /*
506 * Get the value from the previous NF cal
507 * and update the history buffer.
508 */
509 r = ar5416GetNf(ah, chan);
510 if (r == 0 || r == -1) {
511 /* NF calibration result isn't valid */
512 HALDEBUG(ah, HAL_DEBUG_UNMASKABLE, "%s: NF calibration"
513 " didn't finish; delaying CCA\n", __func__);
514 } else {
515 int ret;
516 /*
517 * NF calibration result is valid.
518 *
519 * Load the NF from history buffer of the current channel.
520 * NF is slow time-variant, so it is OK to use a
521 * historical value.
522 */
523 ret = ar5416LoadNF(ah, AH_PRIVATE(ah)->ah_curchan);
524
525 /* start NF calibration, without updating BB NF register*/
527
528 /*
529 * If we failed calibration then tell the driver
530 * we failed and it should do a full chip reset
531 */
532 if (! ret)
533 return AH_FALSE;
534 }
535 }
536 return AH_TRUE;
537}
538
539/*
540 * Recalibrate the lower PHY chips to account for temperature/environment
541 * changes.
542 */
544ar5416PerCalibration(struct ath_hal *ah, struct ieee80211_channel *chan,
545 HAL_BOOL *isIQdone)
546{
547 struct ath_hal_5416 *ahp = AH5416(ah);
548 struct ar5416PerCal *cal = &AH5416(ah)->ah_cal;
549 HAL_CAL_LIST *curCal = cal->cal_curr;
550
551 if (curCal != AH_NULL && curCal->calData->calType == IQ_MISMATCH_CAL) {
552 return ar5416PerCalibrationN(ah, chan, ahp->ah_rx_chainmask,
553 AH_TRUE, isIQdone);
554 } else {
555 HAL_BOOL isCalDone;
556
557 *isIQdone = AH_FALSE;
558 return ar5416PerCalibrationN(ah, chan, ahp->ah_rx_chainmask,
559 AH_TRUE, &isCalDone);
560 }
561}
562
563static HAL_BOOL
565 const struct ieee80211_channel *chan, int16_t *nft)
566{
567 if (IEEE80211_IS_CHAN_5GHZ(chan)) {
569 return AH_TRUE;
570 }
571 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
573 return AH_TRUE;
574 }
575 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",
576 __func__, chan->ic_flags);
577 return AH_FALSE;
578}
579
580static void
582{
586}
587
588static HAL_BOOL
589ar5416LoadNF(struct ath_hal *ah, const struct ieee80211_channel *chan)
590{
591 static const uint32_t ar5416_cca_regs[] = {
598 };
599 struct ar5212NfCalHist *h;
600 int i;
601 int32_t val;
602 uint8_t chainmask;
603 int16_t default_nf = ar5416GetDefaultNF(ah, chan);
604
605 /*
606 * Force NF calibration for all chains.
607 */
608 if (AR_SREV_KITE(ah)) {
609 /* Kite has only one chain */
610 chainmask = 0x9;
611 } else if (AR_SREV_MERLIN(ah) || AR_SREV_KIWI(ah)) {
612 /* Merlin/Kiwi has only two chains */
613 chainmask = 0x1B;
614 } else {
615 chainmask = 0x3F;
616 }
617
618 /*
619 * Write filtered NF values into maxCCApwr register parameter
620 * so we can load below.
621 */
622 h = AH5416(ah)->ah_cal.nfCalHist;
623 HALDEBUG(ah, HAL_DEBUG_NFCAL, "CCA: ");
624 for (i = 0; i < AR5416_NUM_NF_READINGS; i ++) {
625 /* Don't write to EXT radio CCA registers unless in HT/40 mode */
626 /* XXX this check should really be cleaner! */
627 if (i > 2 && !IEEE80211_IS_CHAN_HT40(chan))
628 continue;
629
630 if (chainmask & (1 << i)) {
631 int16_t nf_val;
632
633 if (h)
634 nf_val = h[i].privNF;
635 else
636 nf_val = default_nf;
637
638 val = OS_REG_READ(ah, ar5416_cca_regs[i]);
639 val &= 0xFFFFFE00;
640 val |= (((uint32_t) nf_val << 1) & 0x1ff);
641 HALDEBUG(ah, HAL_DEBUG_NFCAL, "[%d: %d]", i, nf_val);
642 OS_REG_WRITE(ah, ar5416_cca_regs[i], val);
643 }
644 }
645 HALDEBUG(ah, HAL_DEBUG_NFCAL, "\n");
646
647 /* Load software filtered NF value into baseband internal minCCApwr variable. */
651
652 /* Wait for load to complete, should be fast, a few 10s of us. */
653 if (! ar5212WaitNFCalComplete(ah, 1000)) {
654 /*
655 * We timed out waiting for the noisefloor to load, probably due to an
656 * in-progress rx. Simply return here and allow the load plenty of time
657 * to complete before the next calibration interval. We need to avoid
658 * trying to load -50 (which happens below) while the previous load is
659 * still in progress as this can cause rx deafness. Instead by returning
660 * here, the baseband nf cal will just be capped by our present
661 * noisefloor until the next calibration timer.
662 */
663 HALDEBUG(ah, HAL_DEBUG_UNMASKABLE, "Timeout while waiting for "
664 "nf to load: AR_PHY_AGC_CONTROL=0x%x\n",
666 return AH_FALSE;
667 }
668
669 /*
670 * Restore maxCCAPower register parameter again so that we're not capped
671 * by the median we just loaded. This will be initial (and max) value
672 * of next noise floor calibration the baseband does.
673 */
674 for (i = 0; i < AR5416_NUM_NF_READINGS; i ++) {
675 /* Don't write to EXT radio CCA registers unless in HT/40 mode */
676 /* XXX this check should really be cleaner! */
677 if (i > 2 && !IEEE80211_IS_CHAN_HT40(chan))
678 continue;
679
680 if (chainmask & (1 << i)) {
681 val = OS_REG_READ(ah, ar5416_cca_regs[i]);
682 val &= 0xFFFFFE00;
683 val |= (((uint32_t)(-50) << 1) & 0x1ff);
684 OS_REG_WRITE(ah, ar5416_cca_regs[i], val);
685 }
686 }
687 return AH_TRUE;
688}
689
690/*
691 * This just initialises the "good" values for AR5416 which
692 * may not be right; it'lll be overridden by ar5416SanitizeNF()
693 * to nominal values.
694 */
695void
697{
698 int i, j;
699
700 for (i = 0; i < AR5416_NUM_NF_READINGS; i ++) {
701 h[i].currIndex = 0;
704 for (j = 0; j < AR512_NF_CAL_HIST_MAX; j ++)
706 }
707}
708
709/*
710 * Update the noise floor buffer as a ring buffer
711 */
712static void
714 int16_t *nfarray)
715{
716 int i;
717
718 /* XXX TODO: don't record nfarray[] entries for inactive chains */
719 for (i = 0; i < AR5416_NUM_NF_READINGS; i ++) {
720 h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
721
722 if (++h[i].currIndex >= AR512_NF_CAL_HIST_MAX)
723 h[i].currIndex = 0;
724 if (h[i].invalidNFcount > 0) {
725 if (nfarray[i] < AR5416_CCA_MIN_BAD_VALUE ||
726 nfarray[i] > AR5416_CCA_MAX_HIGH_VALUE) {
728 } else {
729 h[i].invalidNFcount--;
730 h[i].privNF = nfarray[i];
731 }
732 } else {
734 }
735 }
736}
737
738static uint16_t
739ar5416GetDefaultNF(struct ath_hal *ah, const struct ieee80211_channel *chan)
740{
741 struct ar5416NfLimits *limit;
742
743 if (!chan || IEEE80211_IS_CHAN_2GHZ(chan))
744 limit = &AH5416(ah)->nf_2g;
745 else
746 limit = &AH5416(ah)->nf_5g;
747
748 return limit->nominal;
749}
750
751static void
752ar5416SanitizeNF(struct ath_hal *ah, int16_t *nf)
753{
754
755 struct ar5416NfLimits *limit;
756 int i;
757
758 if (IEEE80211_IS_CHAN_2GHZ(AH_PRIVATE(ah)->ah_curchan))
759 limit = &AH5416(ah)->nf_2g;
760 else
761 limit = &AH5416(ah)->nf_5g;
762
763 for (i = 0; i < AR5416_NUM_NF_READINGS; i++) {
764 if (!nf[i])
765 continue;
766
767 if (nf[i] > limit->max) {
769 "NF[%d] (%d) > MAX (%d), correcting to MAX\n",
770 i, nf[i], limit->max);
771 nf[i] = limit->max;
772 } else if (nf[i] < limit->min) {
774 "NF[%d] (%d) < MIN (%d), correcting to NOM\n",
775 i, nf[i], limit->min);
776 nf[i] = limit->nominal;
777 }
778 }
779}
780
781/*
782 * Read the NF and check it against the noise floor threshold
783 *
784 * Return 0 if the NF calibration hadn't finished, 0 if it was
785 * invalid, or > 0 for a valid NF reading.
786 */
787static int16_t
788ar5416GetNf(struct ath_hal *ah, struct ieee80211_channel *chan)
789{
790 int16_t nf, nfThresh;
791 int i;
792 int retval = 0;
793
794 if (ar5212IsNFCalInProgress(ah)) {
796 "%s: NF didn't complete in calibration window\n", __func__);
797 nf = 0;
798 retval = -1; /* NF didn't finish */
799 } else {
800 /* Finished NF cal, check against threshold */
801 int16_t nfarray[NUM_NOISEFLOOR_READINGS] = { 0 };
803
804 /* TODO - enhance for multiple chains and ext ch */
805 ath_hal_getNoiseFloor(ah, nfarray);
806 nf = nfarray[0];
807 ar5416SanitizeNF(ah, nfarray);
808 if (ar5416GetEepromNoiseFloorThresh(ah, chan, &nfThresh)) {
809 if (nf > nfThresh) {
811 "%s: noise floor failed detected; "
812 "detected %d, threshold %d\n", __func__,
813 nf, nfThresh);
814 /*
815 * NB: Don't discriminate 2.4 vs 5Ghz, if this
816 * happens it indicates a problem regardless
817 * of the band.
818 */
819 chan->ic_state |= IEEE80211_CHANSTATE_CWINT;
820 nf = 0;
821 retval = 0;
822 }
823 } else {
824 nf = 0;
825 retval = 0;
826 }
827 /* Update MIMO channel statistics, regardless of validity or not (for now) */
828 for (i = 0; i < 3; i++) {
829 ichan->noiseFloorCtl[i] = nfarray[i];
830 ichan->noiseFloorExt[i] = nfarray[i + 3];
831 }
833
834 ar5416UpdateNFHistBuff(ah, AH5416(ah)->ah_cal.nfCalHist, nfarray);
835 ichan->rawNoiseFloor = nf;
836 retval = nf;
837 }
838 return retval;
839}
HAL_BOOL ath_hal_wait(struct ath_hal *ah, u_int reg, uint32_t mask, uint32_t val)
Definition: ah.c:305
HAL_BOOL
Definition: ah.h:93
@ AH_FALSE
Definition: ah.h:94
@ AH_TRUE
Definition: ah.h:95
@ HAL_DEBUG_NFCAL
Definition: ah_debug.h:32
@ HAL_DEBUG_ANY
Definition: ah_debug.h:62
@ HAL_DEBUG_PERCAL
Definition: ah_debug.h:33
@ HAL_DEBUG_UNMASKABLE
Definition: ah_debug.h:61
@ AH_MARK_PERCAL
Definition: ah_decode.h:52
@ AR_EEP_NFTHRESH_2
Definition: ah_eeprom.h:85
@ AR_EEP_NFTHRESH_5
Definition: ah_eeprom.h:84
@ AR_EEP_OL_PWRCTRL
Definition: ah_eeprom.h:100
#define AR5416_MAX_CHAINS
Definition: ah_eeprom_v14.h:84
#define OS_REG_SET_BIT(_a, _r, _f)
Definition: ah_internal.h:594
static OS_INLINE HAL_CHANNEL_INTERNAL * ath_hal_checkchannel(struct ath_hal *ah, const struct ieee80211_channel *c)
Definition: ah_internal.h:711
#define ath_hal_getNoiseFloor(_ah, _nfArray)
Definition: ah_internal.h:466
#define ath_hal_eepromGet(_ah, _param, _val)
Definition: ah_internal.h:486
#define OS_REG_CLR_BIT(_a, _r, _f)
Definition: ah_internal.h:596
#define AH_PRIVATE(_ah)
Definition: ah_internal.h:442
#define CHANNEL_MIMO_NF_VALID
Definition: ah_internal.h:195
#define IS_5GHZ_FAST_CLOCK_EN(_ah, _c)
Definition: ah_internal.h:996
#define OS_REG_RMW_FIELD(_a, _r, _f, _v)
Definition: ah_internal.h:591
#define AH_NULL
Definition: ah_internal.h:28
#define HALASSERT(_x)
Definition: ah_internal.h:683
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
#define ath_hal_eepromGetFlag(_ah, _param)
Definition: ah_internal.h:490
#define OS_MEMZERO(_a, _n)
Definition: ah_osdep.h:72
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_MARK(_ah, _id, _v)
Definition: ah_osdep.h:148
#define OS_INLINE
Definition: ah_osdep.h:71
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
#define AR_PHY_AGC_CONTROL_CAL
Definition: ar5211phy.h:43
#define AR_PHY_AGC_CONTROL_NF
Definition: ar5211phy.h:44
#define AR_PHY_TIMING_CTRL4
Definition: ar5211phy.h:55
#define AR_PHY_AGC_CONTROL
Definition: ar5211phy.h:42
HAL_BOOL ar5212WaitNFCalComplete(struct ath_hal *ah, int i)
Definition: ar5212_misc.c:1152
#define AR512_NF_CAL_HIST_MAX
Definition: ar5212.h:234
int16_t ar5212GetNfHistMid(const int16_t calData[])
HAL_BOOL ar5212IsNFCalInProgress(struct ath_hal *ah)
Definition: ar5212_misc.c:1137
#define AR_PHY_AGC_CONTROL_FLTR_CAL
Definition: ar5212phy.h:117
#define AR_PHY_ADC_CTL_OFF_PWDADC
Definition: ar5212phy.h:67
#define AR_PHY_AGC_CONTROL_ENABLE_NF
Definition: ar5212phy.h:116
#define AR_PHY_ADC_CTL
Definition: ar5212phy.h:62
#define AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX
Definition: ar5212phy.h:169
#define AR_PHY_AGC_CONTROL_NO_UPDATE_NF
Definition: ar5212phy.h:118
#define AH5416(_ah)
Definition: ar5416.h:162
#define AR5416_CCA_MAX_HIGH_VALUE
Definition: ar5416.h:55
#define AR5416_CCA_MAX_GOOD_VALUE
Definition: ar5416.h:54
#define AR5416_CCA_MIN_BAD_VALUE
Definition: ar5416.h:56
#define NUM_NOISEFLOOR_READINGS
Definition: ar5416_cal.c:36
static void ar5416SanitizeNF(struct ath_hal *ah, int16_t *nf)
Definition: ar5416_cal.c:752
HAL_BOOL ar5416PerCalibrationN(struct ath_hal *ah, struct ieee80211_channel *chan, u_int rxchainmask, HAL_BOOL longcal, HAL_BOOL *isCalDone)
Definition: ar5416_cal.c:445
static int16_t ar5416GetNf(struct ath_hal *, struct ieee80211_channel *)
Definition: ar5416_cal.c:788
HAL_BOOL ar5416ResetCalValid(struct ath_hal *ah, const struct ieee80211_channel *chan)
Definition: ar5416_cal.c:340
static HAL_BOOL ar5416LoadNF(struct ath_hal *ah, const struct ieee80211_channel *)
Definition: ar5416_cal.c:589
static void ar5416ResetMeasurement(struct ath_hal *ah, HAL_CAL_LIST *currCal)
Definition: ar5416_cal.c:137
static void ar5416DoCalibration(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *ichan, uint8_t rxchainmask, HAL_CAL_LIST *currCal, HAL_BOOL *isCalDone)
Definition: ar5416_cal.c:388
void ar5416InitNfHistBuff(struct ar5212NfCalHist *h)
Definition: ar5416_cal.c:696
static uint16_t ar5416GetDefaultNF(struct ath_hal *ah, const struct ieee80211_channel *chan)
Definition: ar5416_cal.c:739
static void ar5416UpdateNFHistBuff(struct ath_hal *ah, struct ar5212NfCalHist *h, int16_t *nfarray)
Definition: ar5416_cal.c:713
static OS_INLINE HAL_BOOL ar5416IsCalSupp(struct ath_hal *ah, const struct ieee80211_channel *chan, HAL_CAL_TYPE calType)
Definition: ar5416_cal.c:66
static HAL_BOOL ar5416GetEepromNoiseFloorThresh(struct ath_hal *ah, const struct ieee80211_channel *chan, int16_t *nft)
Definition: ar5416_cal.c:564
static void ar5416SetupMeasurement(struct ath_hal *ah, HAL_CAL_LIST *currCal)
Definition: ar5416_cal.c:99
HAL_BOOL ar5416InitCal(struct ath_hal *ah, const struct ieee80211_channel *chan)
Definition: ar5416_cal.c:245
HAL_BOOL ar5416InitCalHardware(struct ath_hal *ah, const struct ieee80211_channel *chan)
Definition: ar5416_cal.c:203
HAL_BOOL ar5416PerCalibration(struct ath_hal *ah, struct ieee80211_channel *chan, HAL_BOOL *isIQdone)
Definition: ar5416_cal.c:544
static void ar5416StartNFCal(struct ath_hal *ah)
Definition: ar5416_cal.c:581
@ CAL_DONE
Definition: ar5416_cal.h:36
@ CAL_RUNNING
Definition: ar5416_cal.h:35
@ CAL_WAITING
Definition: ar5416_cal.h:34
HAL_CAL_TYPE
Definition: ar5416_cal.h:24
@ ADC_DC_CAL
Definition: ar5416_cal.h:27
@ ADC_DC_INIT_CAL
Definition: ar5416_cal.h:25
@ IQ_MISMATCH_CAL
Definition: ar5416_cal.h:28
@ ADC_GAIN_CAL
Definition: ar5416_cal.h:26
#define AR5416_NUM_NF_READINGS
Definition: ar5416_cal.h:87
#define INSERT_CAL(_cal, _perCal)
Definition: ar5416_cal.h:96
#define INIT_CAL(_perCal)
Definition: ar5416_cal.h:91
#define AR_PHY_CALMODE_IQ
Definition: ar5416phy.h:216
#define AR_PHY_TIMING_CTRL4_DO_CAL
Definition: ar5416phy.h:149
#define AR_PHY_CALMODE_ADC_DC_PER
Definition: ar5416phy.h:218
#define AR_PHY_CALMODE
Definition: ar5416phy.h:214
#define AR_PHY_EXT_CCA
Definition: ar5416phy.h:188
#define AR_PHY_CH1_EXT_CCA
Definition: ar5416phy.h:274
#define AR_PHY_CH2_EXT_CCA
Definition: ar5416phy.h:278
#define AR_PHY_CH1_CCA
Definition: ar5416phy.h:241
#define AR_PHY_CH2_CCA
Definition: ar5416phy.h:249
#define AR_PHY_CALMODE_ADC_DC_INIT
Definition: ar5416phy.h:219
#define AR_PHY_CCA
Definition: ar5416phy.h:233
#define AR_PHY_CALMODE_ADC_GAIN
Definition: ar5416phy.h:217
#define AR_SREV_SOWL_10_OR_LATER(_ah)
Definition: ar5416reg.h:728
#define AR_SREV_KITE(_ah)
Definition: ar5416reg.h:754
#define AR_SREV_KIWI(_ah)
Definition: ar5416reg.h:782
#define AR_SREV_MERLIN_10_OR_LATER(_ah)
Definition: ar5416reg.h:740
#define AR_SREV_HOWL(_ah)
Definition: ar5416reg.h:718
#define AR_SREV_MERLIN(_ah)
Definition: ar5416reg.h:737
int16_t noiseFloorExt[AH_MAX_CHAINS]
Definition: ah_internal.h:202
int16_t noiseFloorCtl[AH_MAX_CHAINS]
Definition: ah_internal.h:201
uint8_t invalidNFcount
Definition: ar5212.h:241
int16_t privNF
Definition: ar5212.h:238
int16_t nfCalBuffer[AR512_NF_CAL_HIST_MAX]
Definition: ar5212.h:237
uint8_t currIndex
Definition: ar5212.h:239
int16_t max
Definition: ar5416.h:62
int16_t nominal
Definition: ar5416.h:64
int16_t min
Definition: ar5416.h:63
HAL_CAL_LIST * cal_last
Definition: ar5416_cal.h:78
HAL_CAL_LIST adcDcCalInitData
Definition: ar5416_cal.h:75
HAL_CAL_LIST * cal_list
Definition: ar5416_cal.h:77
HAL_CAL_LIST * cal_curr
Definition: ar5416_cal.h:79
HAL_CAL_LIST iqCalData
Definition: ar5416_cal.h:73
int calSamples
Definition: ar5416_cal.h:82
HAL_CAL_LIST adcGainCalData
Definition: ar5416_cal.h:74
HAL_CAL_TYPE suppCals
Definition: ar5416_cal.h:72
HAL_CAL_SAMPLE caldata[4][AR5416_MAX_CHAINS]
Definition: ar5416_cal.h:81
HAL_CAL_LIST adcDcCalData
Definition: ar5416_cal.h:76
uint32_t ah_rx_chainmask
Definition: ar5416.h:121
Definition: ah.h:1219
HAL_CAL_STATE calState
Definition: ar5416_cal.h:64
struct cal_list * calNext
Definition: ar5416_cal.h:63
const HAL_PERCAL_DATA * calData
Definition: ar5416_cal.h:65
HAL_CAL_TYPE calType
Definition: ar5416_cal.h:53
void(* calCollect)(struct ath_hal *)
Definition: ar5416_cal.h:56
const char * calName
Definition: ar5416_cal.h:52
uint32_t calNumSamples
Definition: ar5416_cal.h:54
void(* calPostProc)(struct ath_hal *, uint8_t)
Definition: ar5416_cal.h:58
uint32_t calCountMax
Definition: ar5416_cal.h:55