Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 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 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 17 | #include "hw.h" |
Felix Fietkau | 641d992 | 2010-04-15 17:38:49 -0400 | [diff] [blame] | 18 | #include "hw-ops.h" |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 19 | #include <linux/export.h> |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 20 | |
Luis R. Rodriguez | 795f5e2 | 2010-04-15 17:39:00 -0400 | [diff] [blame] | 21 | /* Common calibration code */ |
| 22 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 23 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 24 | static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer) |
| 25 | { |
| 26 | int16_t nfval; |
| 27 | int16_t sort[ATH9K_NF_CAL_HIST_MAX]; |
| 28 | int i, j; |
| 29 | |
| 30 | for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++) |
| 31 | sort[i] = nfCalBuffer[i]; |
| 32 | |
| 33 | for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) { |
| 34 | for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) { |
| 35 | if (sort[j] > sort[j - 1]) { |
| 36 | nfval = sort[j]; |
| 37 | sort[j] = sort[j - 1]; |
| 38 | sort[j - 1] = nfval; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1]; |
| 43 | |
| 44 | return nfval; |
| 45 | } |
| 46 | |
Felix Fietkau | 2292ca6 | 2010-08-02 15:53:13 +0200 | [diff] [blame] | 47 | static struct ath_nf_limits *ath9k_hw_get_nf_limits(struct ath_hw *ah, |
| 48 | struct ath9k_channel *chan) |
| 49 | { |
| 50 | struct ath_nf_limits *limit; |
| 51 | |
| 52 | if (!chan || IS_CHAN_2GHZ(chan)) |
| 53 | limit = &ah->nf_2g; |
| 54 | else |
| 55 | limit = &ah->nf_5g; |
| 56 | |
| 57 | return limit; |
| 58 | } |
| 59 | |
| 60 | static s16 ath9k_hw_get_default_nf(struct ath_hw *ah, |
| 61 | struct ath9k_channel *chan) |
| 62 | { |
| 63 | return ath9k_hw_get_nf_limits(ah, chan)->nominal; |
| 64 | } |
| 65 | |
Lorenzo Bianconi | 5bc225a | 2013-10-11 14:09:54 +0200 | [diff] [blame] | 66 | s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan, |
| 67 | s16 nf) |
Felix Fietkau | f23fba4 | 2011-07-28 14:08:56 +0200 | [diff] [blame] | 68 | { |
| 69 | s8 noise = ATH_DEFAULT_NOISE_FLOOR; |
| 70 | |
Lorenzo Bianconi | 5bc225a | 2013-10-11 14:09:54 +0200 | [diff] [blame] | 71 | if (nf) { |
| 72 | s8 delta = nf - ATH9K_NF_CAL_NOISE_THRESH - |
Felix Fietkau | f23fba4 | 2011-07-28 14:08:56 +0200 | [diff] [blame] | 73 | ath9k_hw_get_default_nf(ah, chan); |
| 74 | if (delta > 0) |
| 75 | noise += delta; |
| 76 | } |
| 77 | return noise; |
| 78 | } |
| 79 | EXPORT_SYMBOL(ath9k_hw_getchan_noise); |
Felix Fietkau | 2292ca6 | 2010-08-02 15:53:13 +0200 | [diff] [blame] | 80 | |
| 81 | static void ath9k_hw_update_nfcal_hist_buffer(struct ath_hw *ah, |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 82 | struct ath9k_hw_cal_data *cal, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 83 | int16_t *nfarray) |
| 84 | { |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 85 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 2292ca6 | 2010-08-02 15:53:13 +0200 | [diff] [blame] | 86 | struct ath_nf_limits *limit; |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 87 | struct ath9k_nfcal_hist *h; |
| 88 | bool high_nf_mid = false; |
Rajkumar Manoharan | 28ef645 | 2011-05-04 19:37:17 +0530 | [diff] [blame] | 89 | u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 90 | int i; |
| 91 | |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 92 | h = cal->nfCalHist; |
Felix Fietkau | 2292ca6 | 2010-08-02 15:53:13 +0200 | [diff] [blame] | 93 | limit = ath9k_hw_get_nf_limits(ah, ah->curchan); |
| 94 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 95 | for (i = 0; i < NUM_NF_READINGS; i++) { |
Rajkumar Manoharan | 28ef645 | 2011-05-04 19:37:17 +0530 | [diff] [blame] | 96 | if (!(chainmask & (1 << i)) || |
Rajkumar Manoharan | 6b3d348 | 2011-08-13 10:28:16 +0530 | [diff] [blame] | 97 | ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(ah->curchan))) |
Rajkumar Manoharan | 28ef645 | 2011-05-04 19:37:17 +0530 | [diff] [blame] | 98 | continue; |
| 99 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 100 | h[i].nfCalBuffer[h[i].currIndex] = nfarray[i]; |
| 101 | |
| 102 | if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX) |
| 103 | h[i].currIndex = 0; |
| 104 | |
| 105 | if (h[i].invalidNFcount > 0) { |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 106 | h[i].invalidNFcount--; |
| 107 | h[i].privNF = nfarray[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 108 | } else { |
| 109 | h[i].privNF = |
| 110 | ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer); |
| 111 | } |
Felix Fietkau | 2292ca6 | 2010-08-02 15:53:13 +0200 | [diff] [blame] | 112 | |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 113 | if (!h[i].privNF) |
| 114 | continue; |
| 115 | |
| 116 | if (h[i].privNF > limit->max) { |
| 117 | high_nf_mid = true; |
| 118 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 119 | ath_dbg(common, CALIBRATE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 120 | "NFmid[%d] (%d) > MAX (%d), %s\n", |
| 121 | i, h[i].privNF, limit->max, |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 122 | (test_bit(NFCAL_INTF, &cal->cal_flags) ? |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 123 | "not corrected (due to interference)" : |
| 124 | "correcting to MAX")); |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * Normally we limit the average noise floor by the |
| 128 | * hardware specific maximum here. However if we have |
| 129 | * encountered stuck beacons because of interference, |
| 130 | * we bypass this limit here in order to better deal |
| 131 | * with our environment. |
| 132 | */ |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 133 | if (!test_bit(NFCAL_INTF, &cal->cal_flags)) |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 134 | h[i].privNF = limit->max; |
| 135 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 136 | } |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * If the noise floor seems normal for all chains, assume that |
| 140 | * there is no significant interference in the environment anymore. |
| 141 | * Re-enable the enforcement of the NF maximum again. |
| 142 | */ |
| 143 | if (!high_nf_mid) |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 144 | clear_bit(NFCAL_INTF, &cal->cal_flags); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 145 | } |
| 146 | |
Luis R. Rodriguez | b43d59f | 2010-04-15 17:38:58 -0400 | [diff] [blame] | 147 | static bool ath9k_hw_get_nf_thresh(struct ath_hw *ah, |
| 148 | enum ieee80211_band band, |
| 149 | int16_t *nft) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 150 | { |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 151 | switch (band) { |
| 152 | case IEEE80211_BAND_5GHZ: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 153 | *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_5); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 154 | break; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 155 | case IEEE80211_BAND_2GHZ: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 156 | *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 157 | break; |
| 158 | default: |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 159 | BUG_ON(1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 160 | return false; |
| 161 | } |
| 162 | |
| 163 | return true; |
| 164 | } |
| 165 | |
Luis R. Rodriguez | 795f5e2 | 2010-04-15 17:39:00 -0400 | [diff] [blame] | 166 | void ath9k_hw_reset_calibration(struct ath_hw *ah, |
| 167 | struct ath9k_cal_list *currCal) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 168 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 169 | int i; |
| 170 | |
| 171 | ath9k_hw_setup_calibration(ah, currCal); |
| 172 | |
| 173 | currCal->calState = CAL_RUNNING; |
| 174 | |
| 175 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 176 | ah->meas0.sign[i] = 0; |
| 177 | ah->meas1.sign[i] = 0; |
| 178 | ah->meas2.sign[i] = 0; |
| 179 | ah->meas3.sign[i] = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 180 | } |
| 181 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 182 | ah->cal_samples = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 183 | } |
| 184 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 185 | /* This is done for the currently configured channel */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 186 | bool ath9k_hw_reset_calvalid(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 187 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 188 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 189 | struct ath9k_cal_list *currCal = ah->cal_list_curr; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 190 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 191 | if (!ah->caldata) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 192 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 193 | |
| 194 | if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah)) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 195 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 196 | |
| 197 | if (currCal == NULL) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 198 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 199 | |
| 200 | if (currCal->calState != CAL_DONE) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 201 | ath_dbg(common, CALIBRATE, "Calibration state incorrect, %d\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 202 | currCal->calState); |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 203 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 204 | } |
| 205 | |
Felix Fietkau | 6497827 | 2010-10-03 19:07:16 +0200 | [diff] [blame] | 206 | if (!(ah->supp_cals & currCal->calData->calType)) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 207 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 208 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 209 | ath_dbg(common, CALIBRATE, "Resetting Cal %d state for channel %u\n", |
Felix Fietkau | e4744ec | 2013-10-11 23:31:01 +0200 | [diff] [blame] | 210 | currCal->calData->calType, ah->curchan->chan->center_freq); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 211 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 212 | ah->caldata->CalValid &= ~currCal->calData->calType; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 213 | currCal->calState = CAL_WAITING; |
| 214 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 215 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 216 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 217 | EXPORT_SYMBOL(ath9k_hw_reset_calvalid); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 218 | |
Felix Fietkau | 00c8659 | 2010-07-30 21:02:09 +0200 | [diff] [blame] | 219 | void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 220 | { |
Felix Fietkau | 4254bc1 | 2010-07-31 00:12:01 +0200 | [diff] [blame] | 221 | if (ah->caldata) |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 222 | set_bit(NFCAL_PENDING, &ah->caldata->cal_flags); |
Felix Fietkau | 4254bc1 | 2010-07-31 00:12:01 +0200 | [diff] [blame] | 223 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 224 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 225 | AR_PHY_AGC_CONTROL_ENABLE_NF); |
Felix Fietkau | 00c8659 | 2010-07-30 21:02:09 +0200 | [diff] [blame] | 226 | |
| 227 | if (update) |
| 228 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 229 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
Felix Fietkau | 00c8659 | 2010-07-30 21:02:09 +0200 | [diff] [blame] | 230 | else |
| 231 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 232 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
| 233 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 234 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); |
| 235 | } |
| 236 | |
Felix Fietkau | 7b8aaea | 2014-10-25 17:19:30 +0200 | [diff] [blame] | 237 | int ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan) |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 238 | { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 239 | struct ath9k_nfcal_hist *h = NULL; |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 240 | unsigned i, j; |
Felix Fietkau | 487f0e0 | 2010-07-23 04:31:56 +0200 | [diff] [blame] | 241 | u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask; |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 242 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 243 | s16 default_nf = ath9k_hw_get_default_nf(ah, chan); |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 244 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 245 | if (ah->caldata) |
| 246 | h = ah->caldata->nfCalHist; |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 247 | |
Oleksij Rempel | 9830ba6 | 2015-03-22 19:29:54 +0100 | [diff] [blame^] | 248 | ENABLE_REG_RMW_BUFFER(ah); |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 249 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 250 | if (chainmask & (1 << i)) { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 251 | s16 nfval; |
| 252 | |
Felix Fietkau | e4744ec | 2013-10-11 23:31:01 +0200 | [diff] [blame] | 253 | if ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(chan)) |
Rajkumar Manoharan | 28ef645 | 2011-05-04 19:37:17 +0530 | [diff] [blame] | 254 | continue; |
| 255 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 256 | if (h) |
| 257 | nfval = h[i].privNF; |
| 258 | else |
| 259 | nfval = default_nf; |
| 260 | |
Oleksij Rempel | 9830ba6 | 2015-03-22 19:29:54 +0100 | [diff] [blame^] | 261 | REG_RMW(ah, ah->nf_regs[i], |
| 262 | (((u32) nfval << 1) & 0x1ff), 0x1ff); |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Load software filtered NF value into baseband internal minCCApwr |
| 268 | * variable. |
| 269 | */ |
| 270 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 271 | AR_PHY_AGC_CONTROL_ENABLE_NF); |
| 272 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 273 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
| 274 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); |
Oleksij Rempel | 9830ba6 | 2015-03-22 19:29:54 +0100 | [diff] [blame^] | 275 | REG_RMW_BUFFER_FLUSH(ah); |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 276 | |
| 277 | /* |
| 278 | * Wait for load to complete, should be fast, a few 10s of us. |
| 279 | * The max delay was changed from an original 250us to 10000us |
| 280 | * since 250us often results in NF load timeout and causes deaf |
| 281 | * condition during stress testing 12/12/2009 |
| 282 | */ |
Vivek Natarajan | 23952ec | 2011-03-10 11:05:43 +0530 | [diff] [blame] | 283 | for (j = 0; j < 10000; j++) { |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 284 | if ((REG_READ(ah, AR_PHY_AGC_CONTROL) & |
| 285 | AR_PHY_AGC_CONTROL_NF) == 0) |
| 286 | break; |
| 287 | udelay(10); |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * We timed out waiting for the noisefloor to load, probably due to an |
| 292 | * in-progress rx. Simply return here and allow the load plenty of time |
| 293 | * to complete before the next calibration interval. We need to avoid |
| 294 | * trying to load -50 (which happens below) while the previous load is |
| 295 | * still in progress as this can cause rx deafness. Instead by returning |
| 296 | * here, the baseband nf cal will just be capped by our present |
| 297 | * noisefloor until the next calibration timer. |
| 298 | */ |
Vivek Natarajan | 23952ec | 2011-03-10 11:05:43 +0530 | [diff] [blame] | 299 | if (j == 10000) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 300 | ath_dbg(common, ANY, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 301 | "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n", |
| 302 | REG_READ(ah, AR_PHY_AGC_CONTROL)); |
Felix Fietkau | 7b8aaea | 2014-10-25 17:19:30 +0200 | [diff] [blame] | 303 | return -ETIMEDOUT; |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* |
| 307 | * Restore maxCCAPower register parameter again so that we're not capped |
| 308 | * by the median we just loaded. This will be initial (and max) value |
| 309 | * of next noise floor calibration the baseband does. |
| 310 | */ |
Oleksij Rempel | 9830ba6 | 2015-03-22 19:29:54 +0100 | [diff] [blame^] | 311 | ENABLE_REG_RMW_BUFFER(ah); |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 312 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 313 | if (chainmask & (1 << i)) { |
Felix Fietkau | e4744ec | 2013-10-11 23:31:01 +0200 | [diff] [blame] | 314 | if ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(chan)) |
Rajkumar Manoharan | 28ef645 | 2011-05-04 19:37:17 +0530 | [diff] [blame] | 315 | continue; |
| 316 | |
Oleksij Rempel | 9830ba6 | 2015-03-22 19:29:54 +0100 | [diff] [blame^] | 317 | REG_RMW(ah, ah->nf_regs[i], |
| 318 | (((u32) (-50) << 1) & 0x1ff), 0x1ff); |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 319 | } |
| 320 | } |
Oleksij Rempel | 9830ba6 | 2015-03-22 19:29:54 +0100 | [diff] [blame^] | 321 | REG_RMW_BUFFER_FLUSH(ah); |
Felix Fietkau | 7b8aaea | 2014-10-25 17:19:30 +0200 | [diff] [blame] | 322 | |
| 323 | return 0; |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 327 | static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf) |
| 328 | { |
| 329 | struct ath_common *common = ath9k_hw_common(ah); |
| 330 | struct ath_nf_limits *limit; |
| 331 | int i; |
| 332 | |
| 333 | if (IS_CHAN_2GHZ(ah->curchan)) |
| 334 | limit = &ah->nf_2g; |
| 335 | else |
| 336 | limit = &ah->nf_5g; |
| 337 | |
| 338 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 339 | if (!nf[i]) |
| 340 | continue; |
| 341 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 342 | ath_dbg(common, CALIBRATE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 343 | "NF calibrated [%s] [chain %d] is %d\n", |
| 344 | (i >= 3 ? "ext" : "ctl"), i % 3, nf[i]); |
Felix Fietkau | 54bd500 | 2010-07-02 00:09:51 +0200 | [diff] [blame] | 345 | |
Rajkumar Manoharan | 2ee0a07 | 2012-03-15 06:08:04 +0530 | [diff] [blame] | 346 | if (nf[i] > limit->max) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 347 | ath_dbg(common, CALIBRATE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 348 | "NF[%d] (%d) > MAX (%d), correcting to MAX\n", |
Rajkumar Manoharan | 2ee0a07 | 2012-03-15 06:08:04 +0530 | [diff] [blame] | 349 | i, nf[i], limit->max); |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 350 | nf[i] = limit->max; |
| 351 | } else if (nf[i] < limit->min) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 352 | ath_dbg(common, CALIBRATE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 353 | "NF[%d] (%d) < MIN (%d), correcting to NOM\n", |
| 354 | i, nf[i], limit->min); |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 355 | nf[i] = limit->nominal; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
Felix Fietkau | 4254bc1 | 2010-07-31 00:12:01 +0200 | [diff] [blame] | 360 | bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 361 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 362 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 363 | int16_t nf, nfThresh; |
| 364 | int16_t nfarray[NUM_NF_READINGS] = { 0 }; |
| 365 | struct ath9k_nfcal_hist *h; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 366 | struct ieee80211_channel *c = chan->chan; |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 367 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
| 368 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 369 | if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 370 | ath_dbg(common, CALIBRATE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 371 | "NF did not complete in calibration window\n"); |
Felix Fietkau | 4254bc1 | 2010-07-31 00:12:01 +0200 | [diff] [blame] | 372 | return false; |
Felix Fietkau | d9891c7 | 2010-09-29 17:15:27 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | ath9k_hw_do_getnf(ah, nfarray); |
| 376 | ath9k_hw_nf_sanitize(ah, nfarray); |
| 377 | nf = nfarray[0]; |
| 378 | if (ath9k_hw_get_nf_thresh(ah, c->band, &nfThresh) |
| 379 | && nf > nfThresh) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 380 | ath_dbg(common, CALIBRATE, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 381 | "noise floor failed detected; detected %d, threshold %d\n", |
| 382 | nf, nfThresh); |
Felix Fietkau | d9891c7 | 2010-09-29 17:15:27 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | if (!caldata) { |
| 386 | chan->noisefloor = nf; |
| 387 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 388 | } |
| 389 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 390 | h = caldata->nfCalHist; |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 391 | clear_bit(NFCAL_PENDING, &caldata->cal_flags); |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 392 | ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray); |
Felix Fietkau | d9891c7 | 2010-09-29 17:15:27 +0200 | [diff] [blame] | 393 | chan->noisefloor = h[0].privNF; |
Lorenzo Bianconi | 5bc225a | 2013-10-11 14:09:54 +0200 | [diff] [blame] | 394 | ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor); |
Felix Fietkau | 4254bc1 | 2010-07-31 00:12:01 +0200 | [diff] [blame] | 395 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 396 | } |
Rajkumar Manoharan | 1a19f77 | 2012-01-09 15:37:53 +0530 | [diff] [blame] | 397 | EXPORT_SYMBOL(ath9k_hw_getnf); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 398 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 399 | void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah, |
| 400 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 401 | { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 402 | struct ath9k_nfcal_hist *h; |
| 403 | s16 default_nf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 404 | int i, j; |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 405 | |
Rajkumar Manoharan | bdd196a | 2011-01-15 01:01:22 +0530 | [diff] [blame] | 406 | ah->caldata->channel = chan->channel; |
Sujith Manoharan | fcb9a3d | 2013-03-04 12:42:52 +0530 | [diff] [blame] | 407 | ah->caldata->channelFlags = chan->channelFlags; |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 408 | h = ah->caldata->nfCalHist; |
| 409 | default_nf = ath9k_hw_get_default_nf(ah, chan); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 410 | for (i = 0; i < NUM_NF_READINGS; i++) { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 411 | h[i].currIndex = 0; |
| 412 | h[i].privNF = default_nf; |
| 413 | h[i].invalidNFcount = AR_PHY_CCA_FILTERWINDOW_LENGTH; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 414 | for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) { |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 415 | h[i].nfCalBuffer[j] = default_nf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 416 | } |
| 417 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 418 | } |
| 419 | |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 420 | |
| 421 | void ath9k_hw_bstuck_nfcal(struct ath_hw *ah) |
| 422 | { |
| 423 | struct ath9k_hw_cal_data *caldata = ah->caldata; |
| 424 | |
| 425 | if (unlikely(!caldata)) |
| 426 | return; |
| 427 | |
| 428 | /* |
| 429 | * If beacons are stuck, the most likely cause is interference. |
| 430 | * Triggering a noise floor calibration at this point helps the |
| 431 | * hardware adapt to a noisy environment much faster. |
| 432 | * To ensure that we recover from stuck beacons quickly, let |
| 433 | * the baseband update the internal NF value itself, similar to |
| 434 | * what is being done after a full reset. |
| 435 | */ |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 436 | if (!test_bit(NFCAL_PENDING, &caldata->cal_flags)) |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 437 | ath9k_hw_start_nfcal(ah, true); |
| 438 | else if (!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF)) |
| 439 | ath9k_hw_getnf(ah, ah->curchan); |
| 440 | |
Sujith Manoharan | 4b9b42b | 2013-09-11 16:36:31 +0530 | [diff] [blame] | 441 | set_bit(NFCAL_INTF, &caldata->cal_flags); |
Felix Fietkau | 70cf153 | 2010-08-02 15:53:14 +0200 | [diff] [blame] | 442 | } |
| 443 | EXPORT_SYMBOL(ath9k_hw_bstuck_nfcal); |
| 444 | |