Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1 | /* |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 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" |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 19 | |
Luis R. Rodriguez | 795f5e2 | 2010-04-15 17:39:00 -0400 | [diff] [blame] | 20 | /* Common calibration code */ |
| 21 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 22 | /* We can tune this as we go by monitoring really low values */ |
| 23 | #define ATH9K_NF_TOO_LOW -60 |
| 24 | |
| 25 | /* AR5416 may return very high value (like -31 dBm), in those cases the nf |
| 26 | * is incorrect and we should use the static NF value. Later we can try to |
| 27 | * find out why they are reporting these values */ |
| 28 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 29 | static bool ath9k_hw_nf_in_range(struct ath_hw *ah, s16 nf) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 30 | { |
| 31 | if (nf > ATH9K_NF_TOO_LOW) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 32 | ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE, |
| 33 | "noise floor value detected (%d) is " |
| 34 | "lower than what we think is a " |
| 35 | "reasonable value (%d)\n", |
| 36 | nf, ATH9K_NF_TOO_LOW); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 37 | return false; |
| 38 | } |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer) |
| 43 | { |
| 44 | int16_t nfval; |
| 45 | int16_t sort[ATH9K_NF_CAL_HIST_MAX]; |
| 46 | int i, j; |
| 47 | |
| 48 | for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++) |
| 49 | sort[i] = nfCalBuffer[i]; |
| 50 | |
| 51 | for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) { |
| 52 | for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) { |
| 53 | if (sort[j] > sort[j - 1]) { |
| 54 | nfval = sort[j]; |
| 55 | sort[j] = sort[j - 1]; |
| 56 | sort[j - 1] = nfval; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1]; |
| 61 | |
| 62 | return nfval; |
| 63 | } |
| 64 | |
| 65 | static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h, |
| 66 | int16_t *nfarray) |
| 67 | { |
| 68 | int i; |
| 69 | |
| 70 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 71 | h[i].nfCalBuffer[h[i].currIndex] = nfarray[i]; |
| 72 | |
| 73 | if (++h[i].currIndex >= ATH9K_NF_CAL_HIST_MAX) |
| 74 | h[i].currIndex = 0; |
| 75 | |
| 76 | if (h[i].invalidNFcount > 0) { |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 77 | h[i].invalidNFcount--; |
| 78 | h[i].privNF = nfarray[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 79 | } else { |
| 80 | h[i].privNF = |
| 81 | ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer); |
| 82 | } |
| 83 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Luis R. Rodriguez | b43d59f | 2010-04-15 17:38:58 -0400 | [diff] [blame] | 86 | static bool ath9k_hw_get_nf_thresh(struct ath_hw *ah, |
| 87 | enum ieee80211_band band, |
| 88 | int16_t *nft) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 89 | { |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 90 | switch (band) { |
| 91 | case IEEE80211_BAND_5GHZ: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 92 | *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_5); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 93 | break; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 94 | case IEEE80211_BAND_2GHZ: |
Sujith | f74df6f | 2009-02-09 13:27:24 +0530 | [diff] [blame] | 95 | *nft = (int8_t)ah->eep_ops->get_eeprom(ah, EEP_NFTHRESH_2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 96 | break; |
| 97 | default: |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 98 | BUG_ON(1); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | |
| 102 | return true; |
| 103 | } |
| 104 | |
Luis R. Rodriguez | 795f5e2 | 2010-04-15 17:39:00 -0400 | [diff] [blame] | 105 | void ath9k_hw_reset_calibration(struct ath_hw *ah, |
| 106 | struct ath9k_cal_list *currCal) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 107 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 108 | int i; |
| 109 | |
| 110 | ath9k_hw_setup_calibration(ah, currCal); |
| 111 | |
| 112 | currCal->calState = CAL_RUNNING; |
| 113 | |
| 114 | for (i = 0; i < AR5416_MAX_CHAINS; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 115 | ah->meas0.sign[i] = 0; |
| 116 | ah->meas1.sign[i] = 0; |
| 117 | ah->meas2.sign[i] = 0; |
| 118 | ah->meas3.sign[i] = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 119 | } |
| 120 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 121 | ah->cal_samples = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 122 | } |
| 123 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 124 | /* This is done for the currently configured channel */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 125 | bool ath9k_hw_reset_calvalid(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 126 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 127 | struct ath_common *common = ath9k_hw_common(ah); |
| 128 | struct ieee80211_conf *conf = &common->hw->conf; |
Sujith | cbfe946 | 2009-04-13 21:56:56 +0530 | [diff] [blame] | 129 | struct ath9k_cal_list *currCal = ah->cal_list_curr; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 130 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 131 | if (!ah->curchan) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 132 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 133 | |
| 134 | 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] | 135 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 136 | |
| 137 | if (currCal == NULL) |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 138 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 139 | |
| 140 | if (currCal->calState != CAL_DONE) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 141 | ath_print(common, ATH_DBG_CALIBRATE, |
| 142 | "Calibration state incorrect, %d\n", |
| 143 | currCal->calState); |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 144 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 145 | } |
| 146 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 147 | if (!ath9k_hw_iscal_supported(ah, currCal->calData->calType)) |
| 148 | return true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 149 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 150 | ath_print(common, ATH_DBG_CALIBRATE, |
| 151 | "Resetting Cal %d state for channel %u\n", |
| 152 | currCal->calData->calType, conf->channel->center_freq); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 153 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 154 | ah->curchan->CalValid &= ~currCal->calData->calType; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 155 | currCal->calState = CAL_WAITING; |
| 156 | |
Luis R. Rodriguez | c9e27d9 | 2008-12-23 15:58:42 -0800 | [diff] [blame] | 157 | return false; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 158 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 159 | EXPORT_SYMBOL(ath9k_hw_reset_calvalid); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 160 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 161 | void ath9k_hw_start_nfcal(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 162 | { |
| 163 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 164 | AR_PHY_AGC_CONTROL_ENABLE_NF); |
| 165 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, |
| 166 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
| 167 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); |
| 168 | } |
| 169 | |
Felix Fietkau | bbacee1 | 2010-07-11 15:44:42 +0200 | [diff] [blame] | 170 | void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan) |
| 171 | { |
| 172 | struct ath9k_nfcal_hist *h; |
| 173 | unsigned i, j; |
| 174 | int32_t val; |
| 175 | u8 chainmask; |
| 176 | struct ath_common *common = ath9k_hw_common(ah); |
| 177 | |
| 178 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 179 | chainmask = 0x3F; |
| 180 | else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) |
| 181 | chainmask = 0x9; |
| 182 | else if (AR_SREV_9280(ah) || AR_SREV_9287(ah)) { |
| 183 | if ((ah->rxchainmask & 0x2) || (ah->rxchainmask & 0x4)) |
| 184 | chainmask = 0x1B; |
| 185 | else |
| 186 | chainmask = 0x09; |
| 187 | } else { |
| 188 | if (ah->rxchainmask & 0x4) |
| 189 | chainmask = 0x3F; |
| 190 | else if (ah->rxchainmask & 0x2) |
| 191 | chainmask = 0x1B; |
| 192 | else |
| 193 | chainmask = 0x09; |
| 194 | } |
| 195 | h = ah->nfCalHist; |
| 196 | |
| 197 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 198 | if (chainmask & (1 << i)) { |
| 199 | val = REG_READ(ah, ah->nf_regs[i]); |
| 200 | val &= 0xFFFFFE00; |
| 201 | val |= (((u32) (h[i].privNF) << 1) & 0x1ff); |
| 202 | REG_WRITE(ah, ah->nf_regs[i], val); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Load software filtered NF value into baseband internal minCCApwr |
| 208 | * variable. |
| 209 | */ |
| 210 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 211 | AR_PHY_AGC_CONTROL_ENABLE_NF); |
| 212 | REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, |
| 213 | AR_PHY_AGC_CONTROL_NO_UPDATE_NF); |
| 214 | REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); |
| 215 | |
| 216 | /* |
| 217 | * Wait for load to complete, should be fast, a few 10s of us. |
| 218 | * The max delay was changed from an original 250us to 10000us |
| 219 | * since 250us often results in NF load timeout and causes deaf |
| 220 | * condition during stress testing 12/12/2009 |
| 221 | */ |
| 222 | for (j = 0; j < 1000; j++) { |
| 223 | if ((REG_READ(ah, AR_PHY_AGC_CONTROL) & |
| 224 | AR_PHY_AGC_CONTROL_NF) == 0) |
| 225 | break; |
| 226 | udelay(10); |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * We timed out waiting for the noisefloor to load, probably due to an |
| 231 | * in-progress rx. Simply return here and allow the load plenty of time |
| 232 | * to complete before the next calibration interval. We need to avoid |
| 233 | * trying to load -50 (which happens below) while the previous load is |
| 234 | * still in progress as this can cause rx deafness. Instead by returning |
| 235 | * here, the baseband nf cal will just be capped by our present |
| 236 | * noisefloor until the next calibration timer. |
| 237 | */ |
| 238 | if (j == 1000) { |
| 239 | ath_print(common, ATH_DBG_ANY, "Timeout while waiting for nf " |
| 240 | "to load: AR_PHY_AGC_CONTROL=0x%x\n", |
| 241 | REG_READ(ah, AR_PHY_AGC_CONTROL)); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * Restore maxCCAPower register parameter again so that we're not capped |
| 247 | * by the median we just loaded. This will be initial (and max) value |
| 248 | * of next noise floor calibration the baseband does. |
| 249 | */ |
| 250 | ENABLE_REGWRITE_BUFFER(ah); |
| 251 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 252 | if (chainmask & (1 << i)) { |
| 253 | val = REG_READ(ah, ah->nf_regs[i]); |
| 254 | val &= 0xFFFFFE00; |
| 255 | val |= (((u32) (-50) << 1) & 0x1ff); |
| 256 | REG_WRITE(ah, ah->nf_regs[i], val); |
| 257 | } |
| 258 | } |
| 259 | REGWRITE_BUFFER_FLUSH(ah); |
| 260 | DISABLE_REGWRITE_BUFFER(ah); |
| 261 | } |
| 262 | |
| 263 | |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 264 | static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf) |
| 265 | { |
| 266 | struct ath_common *common = ath9k_hw_common(ah); |
| 267 | struct ath_nf_limits *limit; |
| 268 | int i; |
| 269 | |
| 270 | if (IS_CHAN_2GHZ(ah->curchan)) |
| 271 | limit = &ah->nf_2g; |
| 272 | else |
| 273 | limit = &ah->nf_5g; |
| 274 | |
| 275 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 276 | if (!nf[i]) |
| 277 | continue; |
| 278 | |
Felix Fietkau | 54bd500 | 2010-07-02 00:09:51 +0200 | [diff] [blame] | 279 | ath_print(common, ATH_DBG_CALIBRATE, |
| 280 | "NF calibrated [%s] [chain %d] is %d\n", |
| 281 | (i > 3 ? "ext" : "ctl"), i % 3, nf[i]); |
| 282 | |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 283 | if (nf[i] > limit->max) { |
| 284 | ath_print(common, ATH_DBG_CALIBRATE, |
| 285 | "NF[%d] (%d) > MAX (%d), correcting to MAX", |
| 286 | i, nf[i], limit->max); |
| 287 | nf[i] = limit->max; |
| 288 | } else if (nf[i] < limit->min) { |
| 289 | ath_print(common, ATH_DBG_CALIBRATE, |
| 290 | "NF[%d] (%d) < MIN (%d), correcting to NOM", |
| 291 | i, nf[i], limit->min); |
| 292 | nf[i] = limit->nominal; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 297 | int16_t ath9k_hw_getnf(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 298 | struct ath9k_channel *chan) |
| 299 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 300 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 301 | int16_t nf, nfThresh; |
| 302 | int16_t nfarray[NUM_NF_READINGS] = { 0 }; |
| 303 | struct ath9k_nfcal_hist *h; |
Luis R. Rodriguez | 76061ab | 2008-12-23 15:58:41 -0800 | [diff] [blame] | 304 | struct ieee80211_channel *c = chan->chan; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 305 | |
| 306 | chan->channelFlags &= (~CHANNEL_CW_INT); |
| 307 | if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 308 | ath_print(common, ATH_DBG_CALIBRATE, |
| 309 | "NF did not complete in calibration window\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 310 | nf = 0; |
| 311 | chan->rawNoiseFloor = nf; |
| 312 | return chan->rawNoiseFloor; |
| 313 | } else { |
| 314 | ath9k_hw_do_getnf(ah, nfarray); |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 315 | ath9k_hw_nf_sanitize(ah, nfarray); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 316 | nf = nfarray[0]; |
Luis R. Rodriguez | b43d59f | 2010-04-15 17:38:58 -0400 | [diff] [blame] | 317 | if (ath9k_hw_get_nf_thresh(ah, c->band, &nfThresh) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 318 | && nf > nfThresh) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 319 | ath_print(common, ATH_DBG_CALIBRATE, |
| 320 | "noise floor failed detected; " |
| 321 | "detected %d, threshold %d\n", |
| 322 | nf, nfThresh); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 323 | chan->channelFlags |= CHANNEL_CW_INT; |
| 324 | } |
| 325 | } |
| 326 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 327 | h = ah->nfCalHist; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 328 | |
| 329 | ath9k_hw_update_nfcal_hist_buffer(h, nfarray); |
| 330 | chan->rawNoiseFloor = h[0].privNF; |
| 331 | |
| 332 | return chan->rawNoiseFloor; |
| 333 | } |
| 334 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 335 | void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 336 | { |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 337 | struct ath_nf_limits *limit; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 338 | int i, j; |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 339 | |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 340 | if (!ah->curchan || IS_CHAN_2GHZ(ah->curchan)) |
| 341 | limit = &ah->nf_2g; |
Senthil Balasubramanian | a59b5a5 | 2009-07-14 20:17:07 -0400 | [diff] [blame] | 342 | else |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 343 | limit = &ah->nf_5g; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 344 | |
| 345 | for (i = 0; i < NUM_NF_READINGS; i++) { |
| 346 | ah->nfCalHist[i].currIndex = 0; |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 347 | ah->nfCalHist[i].privNF = limit->nominal; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 348 | ah->nfCalHist[i].invalidNFcount = |
| 349 | AR_PHY_CCA_FILTERWINDOW_LENGTH; |
| 350 | for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) { |
Felix Fietkau | f2552e2 | 2010-07-02 00:09:50 +0200 | [diff] [blame] | 351 | ah->nfCalHist[i].nfCalBuffer[j] = limit->nominal; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 352 | } |
| 353 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 354 | } |
| 355 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 356 | s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 357 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 358 | s16 nf; |
| 359 | |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 360 | if (chan->rawNoiseFloor == 0) |
Luis R. Rodriguez | e56db71 | 2008-12-23 15:58:47 -0800 | [diff] [blame] | 361 | nf = -96; |
| 362 | else |
Luis R. Rodriguez | 5f8e077 | 2009-01-22 15:16:48 -0800 | [diff] [blame] | 363 | nf = chan->rawNoiseFloor; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 364 | |
| 365 | if (!ath9k_hw_nf_in_range(ah, nf)) |
| 366 | nf = ATH_DEFAULT_NOISE_FLOOR; |
| 367 | |
| 368 | return nf; |
| 369 | } |
Luis R. Rodriguez | 7322fd1 | 2009-09-23 23:07:00 -0400 | [diff] [blame] | 370 | EXPORT_SYMBOL(ath9k_hw_getchan_noise); |