Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
| 8 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
| 25 | * in the file called LICENSE.GPL. |
| 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
| 33 | * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved. |
| 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | *****************************************************************************/ |
| 62 | |
| 63 | #include <linux/slab.h> |
| 64 | #include <net/mac80211.h> |
| 65 | |
Stanislaw Gruszka | 98613be | 2011-11-15 14:19:34 +0100 | [diff] [blame] | 66 | #include "common.h" |
Stanislaw Gruszka | af038f4 | 2011-08-30 13:58:27 +0200 | [diff] [blame] | 67 | #include "4965.h" |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 68 | |
| 69 | /***************************************************************************** |
| 70 | * INIT calibrations framework |
| 71 | *****************************************************************************/ |
| 72 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 73 | struct stats_general_data { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 74 | u32 beacon_silence_rssi_a; |
| 75 | u32 beacon_silence_rssi_b; |
| 76 | u32 beacon_silence_rssi_c; |
| 77 | u32 beacon_energy_a; |
| 78 | u32 beacon_energy_b; |
| 79 | u32 beacon_energy_c; |
| 80 | }; |
| 81 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 82 | void |
| 83 | il4965_calib_free_results(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 84 | { |
| 85 | int i; |
| 86 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 87 | for (i = 0; i < IL_CALIB_MAX; i++) { |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 88 | kfree(il->calib_results[i].buf); |
| 89 | il->calib_results[i].buf = NULL; |
| 90 | il->calib_results[i].buf_len = 0; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | /***************************************************************************** |
| 95 | * RUNTIME calibrations framework |
| 96 | *****************************************************************************/ |
| 97 | |
| 98 | /* "false alarms" are signals that our DSP tries to lock onto, |
| 99 | * but then determines that they are either noise, or transmissions |
| 100 | * from a distant wireless network (also "noise", really) that get |
| 101 | * "stepped on" by stronger transmissions within our own network. |
| 102 | * This algorithm attempts to set a sensitivity level that is high |
| 103 | * enough to receive all of our own network traffic, but not so |
| 104 | * high that our DSP gets too busy trying to lock onto non-network |
| 105 | * activity/noise. */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 106 | static int |
| 107 | il4965_sens_energy_cck(struct il_priv *il, u32 norm_fa, u32 rx_enable_time, |
| 108 | struct stats_general_data *rx_info) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 109 | { |
| 110 | u32 max_nrg_cck = 0; |
| 111 | int i = 0; |
| 112 | u8 max_silence_rssi = 0; |
| 113 | u32 silence_ref = 0; |
| 114 | u8 silence_rssi_a = 0; |
| 115 | u8 silence_rssi_b = 0; |
| 116 | u8 silence_rssi_c = 0; |
| 117 | u32 val; |
| 118 | |
| 119 | /* "false_alarms" values below are cross-multiplications to assess the |
| 120 | * numbers of false alarms within the measured period of actual Rx |
| 121 | * (Rx is off when we're txing), vs the min/max expected false alarms |
| 122 | * (some should be expected if rx is sensitive enough) in a |
| 123 | * hypothetical listening period of 200 time units (TU), 204.8 msec: |
| 124 | * |
| 125 | * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time |
| 126 | * |
| 127 | * */ |
| 128 | u32 false_alarms = norm_fa * 200 * 1024; |
| 129 | u32 max_false_alarms = MAX_FA_CCK * rx_enable_time; |
| 130 | u32 min_false_alarms = MIN_FA_CCK * rx_enable_time; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 131 | struct il_sensitivity_data *data = NULL; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 132 | const struct il_sensitivity_ranges *ranges = il->hw_params.sens; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 133 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 134 | data = &(il->sensitivity_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 135 | |
| 136 | data->nrg_auto_corr_silence_diff = 0; |
| 137 | |
| 138 | /* Find max silence rssi among all 3 receivers. |
| 139 | * This is background noise, which may include transmissions from other |
| 140 | * networks, measured during silence before our network's beacon */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 141 | silence_rssi_a = |
| 142 | (u8) ((rx_info->beacon_silence_rssi_a & ALL_BAND_FILTER) >> 8); |
| 143 | silence_rssi_b = |
| 144 | (u8) ((rx_info->beacon_silence_rssi_b & ALL_BAND_FILTER) >> 8); |
| 145 | silence_rssi_c = |
| 146 | (u8) ((rx_info->beacon_silence_rssi_c & ALL_BAND_FILTER) >> 8); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 147 | |
| 148 | val = max(silence_rssi_b, silence_rssi_c); |
| 149 | max_silence_rssi = max(silence_rssi_a, (u8) val); |
| 150 | |
| 151 | /* Store silence rssi in 20-beacon history table */ |
| 152 | data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi; |
| 153 | data->nrg_silence_idx++; |
| 154 | if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L) |
| 155 | data->nrg_silence_idx = 0; |
| 156 | |
| 157 | /* Find max silence rssi across 20 beacon history */ |
| 158 | for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) { |
| 159 | val = data->nrg_silence_rssi[i]; |
| 160 | silence_ref = max(silence_ref, val); |
| 161 | } |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 162 | D_CALIB("silence a %u, b %u, c %u, 20-bcn max %u\n", silence_rssi_a, |
| 163 | silence_rssi_b, silence_rssi_c, silence_ref); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 164 | |
| 165 | /* Find max rx energy (min value!) among all 3 receivers, |
| 166 | * measured during beacon frame. |
| 167 | * Save it in 10-beacon history table. */ |
| 168 | i = data->nrg_energy_idx; |
| 169 | val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c); |
| 170 | data->nrg_value[i] = min(rx_info->beacon_energy_a, val); |
| 171 | |
| 172 | data->nrg_energy_idx++; |
| 173 | if (data->nrg_energy_idx >= 10) |
| 174 | data->nrg_energy_idx = 0; |
| 175 | |
| 176 | /* Find min rx energy (max value) across 10 beacon history. |
| 177 | * This is the minimum signal level that we want to receive well. |
| 178 | * Add backoff (margin so we don't miss slightly lower energy frames). |
| 179 | * This establishes an upper bound (min value) for energy threshold. */ |
| 180 | max_nrg_cck = data->nrg_value[0]; |
| 181 | for (i = 1; i < 10; i++) |
| 182 | max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i])); |
| 183 | max_nrg_cck += 6; |
| 184 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 185 | D_CALIB("rx energy a %u, b %u, c %u, 10-bcn max/min %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 186 | rx_info->beacon_energy_a, rx_info->beacon_energy_b, |
| 187 | rx_info->beacon_energy_c, max_nrg_cck - 6); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 188 | |
| 189 | /* Count number of consecutive beacons with fewer-than-desired |
| 190 | * false alarms. */ |
| 191 | if (false_alarms < min_false_alarms) |
| 192 | data->num_in_cck_no_fa++; |
| 193 | else |
| 194 | data->num_in_cck_no_fa = 0; |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 195 | D_CALIB("consecutive bcns with few false alarms = %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 196 | data->num_in_cck_no_fa); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 197 | |
| 198 | /* If we got too many false alarms this time, reduce sensitivity */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 199 | if (false_alarms > max_false_alarms && |
| 200 | data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 201 | D_CALIB("norm FA %u > max FA %u\n", false_alarms, |
| 202 | max_false_alarms); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 203 | D_CALIB("... reducing sensitivity\n"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 204 | data->nrg_curr_state = IL_FA_TOO_MANY; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 205 | /* Store for "fewer than desired" on later beacon */ |
| 206 | data->nrg_silence_ref = silence_ref; |
| 207 | |
| 208 | /* increase energy threshold (reduce nrg value) |
| 209 | * to decrease sensitivity */ |
| 210 | data->nrg_th_cck = data->nrg_th_cck - NRG_STEP_CCK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 211 | /* Else if we got fewer than desired, increase sensitivity */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 212 | } else if (false_alarms < min_false_alarms) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 213 | data->nrg_curr_state = IL_FA_TOO_FEW; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 214 | |
| 215 | /* Compare silence level with silence level for most recent |
| 216 | * healthy number or too many false alarms */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 217 | data->nrg_auto_corr_silence_diff = |
| 218 | (s32) data->nrg_silence_ref - (s32) silence_ref; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 219 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 220 | D_CALIB("norm FA %u < min FA %u, silence diff %d\n", |
| 221 | false_alarms, min_false_alarms, |
| 222 | data->nrg_auto_corr_silence_diff); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 223 | |
| 224 | /* Increase value to increase sensitivity, but only if: |
| 225 | * 1a) previous beacon did *not* have *too many* false alarms |
| 226 | * 1b) AND there's a significant difference in Rx levels |
| 227 | * from a previous beacon with too many, or healthy # FAs |
| 228 | * OR 2) We've seen a lot of beacons (100) with too few |
| 229 | * false alarms */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 230 | if (data->nrg_prev_state != IL_FA_TOO_MANY && |
| 231 | (data->nrg_auto_corr_silence_diff > NRG_DIFF || |
| 232 | data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 233 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 234 | D_CALIB("... increasing sensitivity\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 235 | /* Increase nrg value to increase sensitivity */ |
| 236 | val = data->nrg_th_cck + NRG_STEP_CCK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 237 | data->nrg_th_cck = min((u32) ranges->min_nrg_cck, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 238 | } else { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 239 | D_CALIB("... but not changing sensitivity\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 242 | /* Else we got a healthy number of false alarms, keep status quo */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 243 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 244 | D_CALIB(" FA in safe zone\n"); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 245 | data->nrg_curr_state = IL_FA_GOOD_RANGE; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 246 | |
| 247 | /* Store for use in "fewer than desired" with later beacon */ |
| 248 | data->nrg_silence_ref = silence_ref; |
| 249 | |
| 250 | /* If previous beacon had too many false alarms, |
| 251 | * give it some extra margin by reducing sensitivity again |
| 252 | * (but don't go below measured energy of desired Rx) */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 253 | if (IL_FA_TOO_MANY == data->nrg_prev_state) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 254 | D_CALIB("... increasing margin\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 255 | if (data->nrg_th_cck > (max_nrg_cck + NRG_MARGIN)) |
| 256 | data->nrg_th_cck -= NRG_MARGIN; |
| 257 | else |
| 258 | data->nrg_th_cck = max_nrg_cck; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /* Make sure the energy threshold does not go above the measured |
| 263 | * energy of the desired Rx signals (reduced by backoff margin), |
| 264 | * or else we might start missing Rx frames. |
| 265 | * Lower value is higher energy, so we use max()! |
| 266 | */ |
| 267 | data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 268 | D_CALIB("new nrg_th_cck %u\n", data->nrg_th_cck); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 269 | |
| 270 | data->nrg_prev_state = data->nrg_curr_state; |
| 271 | |
| 272 | /* Auto-correlation CCK algorithm */ |
| 273 | if (false_alarms > min_false_alarms) { |
| 274 | |
| 275 | /* increase auto_corr values to decrease sensitivity |
| 276 | * so the DSP won't be disturbed by the noise |
| 277 | */ |
| 278 | if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK) |
| 279 | data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1; |
| 280 | else { |
| 281 | val = data->auto_corr_cck + AUTO_CORR_STEP_CCK; |
| 282 | data->auto_corr_cck = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 283 | min((u32) ranges->auto_corr_max_cck, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 284 | } |
| 285 | val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK; |
| 286 | data->auto_corr_cck_mrc = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 287 | min((u32) ranges->auto_corr_max_cck_mrc, val); |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 288 | } else if (false_alarms < min_false_alarms && |
| 289 | (data->nrg_auto_corr_silence_diff > NRG_DIFF || |
| 290 | data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA)) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 291 | |
| 292 | /* Decrease auto_corr values to increase sensitivity */ |
| 293 | val = data->auto_corr_cck - AUTO_CORR_STEP_CCK; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 294 | data->auto_corr_cck = max((u32) ranges->auto_corr_min_cck, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 295 | val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK; |
| 296 | data->auto_corr_cck_mrc = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 297 | max((u32) ranges->auto_corr_min_cck_mrc, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 303 | static int |
| 304 | il4965_sens_auto_corr_ofdm(struct il_priv *il, u32 norm_fa, u32 rx_enable_time) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 305 | { |
| 306 | u32 val; |
| 307 | u32 false_alarms = norm_fa * 200 * 1024; |
| 308 | u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time; |
| 309 | u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 310 | struct il_sensitivity_data *data = NULL; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 311 | const struct il_sensitivity_ranges *ranges = il->hw_params.sens; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 312 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 313 | data = &(il->sensitivity_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 314 | |
| 315 | /* If we got too many false alarms this time, reduce sensitivity */ |
| 316 | if (false_alarms > max_false_alarms) { |
| 317 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 318 | D_CALIB("norm FA %u > max FA %u)\n", false_alarms, |
| 319 | max_false_alarms); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 320 | |
| 321 | val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM; |
| 322 | data->auto_corr_ofdm = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 323 | min((u32) ranges->auto_corr_max_ofdm, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 324 | |
| 325 | val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM; |
| 326 | data->auto_corr_ofdm_mrc = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 327 | min((u32) ranges->auto_corr_max_ofdm_mrc, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 328 | |
| 329 | val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM; |
| 330 | data->auto_corr_ofdm_x1 = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 331 | min((u32) ranges->auto_corr_max_ofdm_x1, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 332 | |
| 333 | val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM; |
| 334 | data->auto_corr_ofdm_mrc_x1 = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 335 | min((u32) ranges->auto_corr_max_ofdm_mrc_x1, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /* Else if we got fewer than desired, increase sensitivity */ |
| 339 | else if (false_alarms < min_false_alarms) { |
| 340 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 341 | D_CALIB("norm FA %u < min FA %u\n", false_alarms, |
| 342 | min_false_alarms); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 343 | |
| 344 | val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM; |
| 345 | data->auto_corr_ofdm = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 346 | max((u32) ranges->auto_corr_min_ofdm, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 347 | |
| 348 | val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM; |
| 349 | data->auto_corr_ofdm_mrc = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 350 | max((u32) ranges->auto_corr_min_ofdm_mrc, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 351 | |
| 352 | val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM; |
| 353 | data->auto_corr_ofdm_x1 = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 354 | max((u32) ranges->auto_corr_min_ofdm_x1, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 355 | |
| 356 | val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM; |
| 357 | data->auto_corr_ofdm_mrc_x1 = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 358 | max((u32) ranges->auto_corr_min_ofdm_mrc_x1, val); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 359 | } else { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 360 | D_CALIB("min FA %u < norm FA %u < max FA %u OK\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 361 | min_false_alarms, false_alarms, max_false_alarms); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 366 | static void |
| 367 | il4965_prepare_legacy_sensitivity_tbl(struct il_priv *il, |
| 368 | struct il_sensitivity_data *data, |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 369 | __le16 *tbl) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 370 | { |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 371 | tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 372 | cpu_to_le16((u16) data->auto_corr_ofdm); |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 373 | tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 374 | cpu_to_le16((u16) data->auto_corr_ofdm_mrc); |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 375 | tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 376 | cpu_to_le16((u16) data->auto_corr_ofdm_x1); |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 377 | tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 378 | cpu_to_le16((u16) data->auto_corr_ofdm_mrc_x1); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 379 | |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 380 | tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 381 | cpu_to_le16((u16) data->auto_corr_cck); |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 382 | tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 383 | cpu_to_le16((u16) data->auto_corr_cck_mrc); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 384 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 385 | tbl[HD_MIN_ENERGY_CCK_DET_IDX] = cpu_to_le16((u16) data->nrg_th_cck); |
| 386 | tbl[HD_MIN_ENERGY_OFDM_DET_IDX] = cpu_to_le16((u16) data->nrg_th_ofdm); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 387 | |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 388 | tbl[HD_BARKER_CORR_TH_ADD_MIN_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 389 | cpu_to_le16(data->barker_corr_th_min); |
Stanislaw Gruszka | 2d09b06 | 2011-08-26 16:10:40 +0200 | [diff] [blame] | 390 | tbl[HD_BARKER_CORR_TH_ADD_MIN_MRC_IDX] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 391 | cpu_to_le16(data->barker_corr_th_min_mrc); |
| 392 | tbl[HD_OFDM_ENERGY_TH_IN_IDX] = cpu_to_le16(data->nrg_th_cca); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 393 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 394 | D_CALIB("ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n", |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 395 | data->auto_corr_ofdm, data->auto_corr_ofdm_mrc, |
| 396 | data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1, |
| 397 | data->nrg_th_ofdm); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 398 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 399 | D_CALIB("cck: ac %u mrc %u thresh %u\n", data->auto_corr_cck, |
| 400 | data->auto_corr_cck_mrc, data->nrg_th_cck); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 403 | /* Prepare a C_SENSITIVITY, send to uCode if values have changed */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 404 | static int |
| 405 | il4965_sensitivity_write(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 406 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 407 | struct il_sensitivity_cmd cmd; |
| 408 | struct il_sensitivity_data *data = NULL; |
| 409 | struct il_host_cmd cmd_out = { |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 410 | .id = C_SENSITIVITY, |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 411 | .len = sizeof(struct il_sensitivity_cmd), |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 412 | .flags = CMD_ASYNC, |
| 413 | .data = &cmd, |
| 414 | }; |
| 415 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 416 | data = &(il->sensitivity_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 417 | |
| 418 | memset(&cmd, 0, sizeof(cmd)); |
| 419 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 420 | il4965_prepare_legacy_sensitivity_tbl(il, data, &cmd.table[0]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 421 | |
| 422 | /* Update uCode's "work" table, and copy it to DSP */ |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 423 | cmd.control = C_SENSITIVITY_CONTROL_WORK_TBL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 424 | |
| 425 | /* Don't send command to uCode if nothing has changed */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 426 | if (!memcmp |
| 427 | (&cmd.table[0], &(il->sensitivity_tbl[0]), |
| 428 | sizeof(u16) * HD_TBL_SIZE)) { |
Stanislaw Gruszka | 4d69c75 | 2011-08-30 15:26:35 +0200 | [diff] [blame] | 429 | D_CALIB("No change in C_SENSITIVITY\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | /* Copy table for comparison next time */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 434 | memcpy(&(il->sensitivity_tbl[0]), &(cmd.table[0]), |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 435 | sizeof(u16) * HD_TBL_SIZE); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 436 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 437 | return il_send_cmd(il, &cmd_out); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 440 | void |
| 441 | il4965_init_sensitivity(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 442 | { |
| 443 | int ret = 0; |
| 444 | int i; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 445 | struct il_sensitivity_data *data = NULL; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 446 | const struct il_sensitivity_ranges *ranges = il->hw_params.sens; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 447 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 448 | if (il->disable_sens_cal) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 449 | return; |
| 450 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 451 | D_CALIB("Start il4965_init_sensitivity\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 452 | |
| 453 | /* Clear driver's sensitivity algo data */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 454 | data = &(il->sensitivity_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 455 | |
| 456 | if (ranges == NULL) |
| 457 | return; |
| 458 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 459 | memset(data, 0, sizeof(struct il_sensitivity_data)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 460 | |
| 461 | data->num_in_cck_no_fa = 0; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 462 | data->nrg_curr_state = IL_FA_TOO_MANY; |
| 463 | data->nrg_prev_state = IL_FA_TOO_MANY; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 464 | data->nrg_silence_ref = 0; |
| 465 | data->nrg_silence_idx = 0; |
| 466 | data->nrg_energy_idx = 0; |
| 467 | |
| 468 | for (i = 0; i < 10; i++) |
| 469 | data->nrg_value[i] = 0; |
| 470 | |
| 471 | for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) |
| 472 | data->nrg_silence_rssi[i] = 0; |
| 473 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 474 | data->auto_corr_ofdm = ranges->auto_corr_min_ofdm; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 475 | data->auto_corr_ofdm_mrc = ranges->auto_corr_min_ofdm_mrc; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 476 | data->auto_corr_ofdm_x1 = ranges->auto_corr_min_ofdm_x1; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 477 | data->auto_corr_ofdm_mrc_x1 = ranges->auto_corr_min_ofdm_mrc_x1; |
| 478 | data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF; |
| 479 | data->auto_corr_cck_mrc = ranges->auto_corr_min_cck_mrc; |
| 480 | data->nrg_th_cck = ranges->nrg_th_cck; |
| 481 | data->nrg_th_ofdm = ranges->nrg_th_ofdm; |
| 482 | data->barker_corr_th_min = ranges->barker_corr_th_min; |
| 483 | data->barker_corr_th_min_mrc = ranges->barker_corr_th_min_mrc; |
| 484 | data->nrg_th_cca = ranges->nrg_th_cca; |
| 485 | |
| 486 | data->last_bad_plcp_cnt_ofdm = 0; |
| 487 | data->last_fa_cnt_ofdm = 0; |
| 488 | data->last_bad_plcp_cnt_cck = 0; |
| 489 | data->last_fa_cnt_cck = 0; |
| 490 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 491 | ret |= il4965_sensitivity_write(il); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 492 | D_CALIB("<<return 0x%X\n", ret); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 495 | void |
| 496 | il4965_sensitivity_calibration(struct il_priv *il, void *resp) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 497 | { |
| 498 | u32 rx_enable_time; |
| 499 | u32 fa_cck; |
| 500 | u32 fa_ofdm; |
| 501 | u32 bad_plcp_cck; |
| 502 | u32 bad_plcp_ofdm; |
| 503 | u32 norm_fa_ofdm; |
| 504 | u32 norm_fa_cck; |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 505 | struct il_sensitivity_data *data = NULL; |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 506 | struct stats_rx_non_phy *rx_info; |
| 507 | struct stats_rx_phy *ofdm, *cck; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 508 | unsigned long flags; |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 509 | struct stats_general_data statis; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 510 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 511 | if (il->disable_sens_cal) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 512 | return; |
| 513 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 514 | data = &(il->sensitivity_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 515 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 516 | if (!il_is_any_associated(il)) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 517 | D_CALIB("<< - not associated\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 518 | return; |
| 519 | } |
| 520 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 521 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 522 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 523 | rx_info = &(((struct il_notif_stats *)resp)->rx.general); |
| 524 | ofdm = &(((struct il_notif_stats *)resp)->rx.ofdm); |
| 525 | cck = &(((struct il_notif_stats *)resp)->rx.cck); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 526 | |
| 527 | if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 528 | D_CALIB("<< invalid data.\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 529 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 530 | return; |
| 531 | } |
| 532 | |
| 533 | /* Extract Statistics: */ |
| 534 | rx_enable_time = le32_to_cpu(rx_info->channel_load); |
| 535 | fa_cck = le32_to_cpu(cck->false_alarm_cnt); |
| 536 | fa_ofdm = le32_to_cpu(ofdm->false_alarm_cnt); |
| 537 | bad_plcp_cck = le32_to_cpu(cck->plcp_err); |
| 538 | bad_plcp_ofdm = le32_to_cpu(ofdm->plcp_err); |
| 539 | |
| 540 | statis.beacon_silence_rssi_a = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 541 | le32_to_cpu(rx_info->beacon_silence_rssi_a); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 542 | statis.beacon_silence_rssi_b = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 543 | le32_to_cpu(rx_info->beacon_silence_rssi_b); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 544 | statis.beacon_silence_rssi_c = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 545 | le32_to_cpu(rx_info->beacon_silence_rssi_c); |
| 546 | statis.beacon_energy_a = le32_to_cpu(rx_info->beacon_energy_a); |
| 547 | statis.beacon_energy_b = le32_to_cpu(rx_info->beacon_energy_b); |
| 548 | statis.beacon_energy_c = le32_to_cpu(rx_info->beacon_energy_c); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 549 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 550 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 551 | |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 552 | D_CALIB("rx_enable_time = %u usecs\n", rx_enable_time); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 553 | |
| 554 | if (!rx_enable_time) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 555 | D_CALIB("<< RX Enable Time == 0!\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 556 | return; |
| 557 | } |
| 558 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 559 | /* These stats increase monotonically, and do not reset |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 560 | * at each beacon. Calculate difference from last value, or just |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 561 | * use the new stats value if it has reset or wrapped around. */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 562 | if (data->last_bad_plcp_cnt_cck > bad_plcp_cck) |
| 563 | data->last_bad_plcp_cnt_cck = bad_plcp_cck; |
| 564 | else { |
| 565 | bad_plcp_cck -= data->last_bad_plcp_cnt_cck; |
| 566 | data->last_bad_plcp_cnt_cck += bad_plcp_cck; |
| 567 | } |
| 568 | |
| 569 | if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm) |
| 570 | data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm; |
| 571 | else { |
| 572 | bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm; |
| 573 | data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm; |
| 574 | } |
| 575 | |
| 576 | if (data->last_fa_cnt_ofdm > fa_ofdm) |
| 577 | data->last_fa_cnt_ofdm = fa_ofdm; |
| 578 | else { |
| 579 | fa_ofdm -= data->last_fa_cnt_ofdm; |
| 580 | data->last_fa_cnt_ofdm += fa_ofdm; |
| 581 | } |
| 582 | |
| 583 | if (data->last_fa_cnt_cck > fa_cck) |
| 584 | data->last_fa_cnt_cck = fa_cck; |
| 585 | else { |
| 586 | fa_cck -= data->last_fa_cnt_cck; |
| 587 | data->last_fa_cnt_cck += fa_cck; |
| 588 | } |
| 589 | |
| 590 | /* Total aborted signal locks */ |
| 591 | norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm; |
| 592 | norm_fa_cck = fa_cck + bad_plcp_cck; |
| 593 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 594 | D_CALIB("cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck, |
| 595 | bad_plcp_cck, fa_ofdm, bad_plcp_ofdm); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 596 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 597 | il4965_sens_auto_corr_ofdm(il, norm_fa_ofdm, rx_enable_time); |
| 598 | il4965_sens_energy_cck(il, norm_fa_cck, rx_enable_time, &statis); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 599 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 600 | il4965_sensitivity_write(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 601 | } |
| 602 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 603 | static inline u8 |
| 604 | il4965_find_first_chain(u8 mask) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 605 | { |
| 606 | if (mask & ANT_A) |
| 607 | return CHAIN_A; |
| 608 | if (mask & ANT_B) |
| 609 | return CHAIN_B; |
| 610 | return CHAIN_C; |
| 611 | } |
| 612 | |
| 613 | /** |
| 614 | * Run disconnected antenna algorithm to find out which antennas are |
| 615 | * disconnected. |
| 616 | */ |
| 617 | static void |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 618 | il4965_find_disconn_antenna(struct il_priv *il, u32 * average_sig, |
| 619 | struct il_chain_noise_data *data) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 620 | { |
| 621 | u32 active_chains = 0; |
| 622 | u32 max_average_sig; |
| 623 | u16 max_average_sig_antenna_i; |
| 624 | u8 num_tx_chains; |
| 625 | u8 first_chain; |
| 626 | u16 i = 0; |
| 627 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 628 | average_sig[0] = |
| 629 | data->chain_signal_a / |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 630 | il->cfg->chain_noise_num_beacons; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 631 | average_sig[1] = |
| 632 | data->chain_signal_b / |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 633 | il->cfg->chain_noise_num_beacons; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 634 | average_sig[2] = |
| 635 | data->chain_signal_c / |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 636 | il->cfg->chain_noise_num_beacons; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 637 | |
| 638 | if (average_sig[0] >= average_sig[1]) { |
| 639 | max_average_sig = average_sig[0]; |
| 640 | max_average_sig_antenna_i = 0; |
| 641 | active_chains = (1 << max_average_sig_antenna_i); |
| 642 | } else { |
| 643 | max_average_sig = average_sig[1]; |
| 644 | max_average_sig_antenna_i = 1; |
| 645 | active_chains = (1 << max_average_sig_antenna_i); |
| 646 | } |
| 647 | |
| 648 | if (average_sig[2] >= max_average_sig) { |
| 649 | max_average_sig = average_sig[2]; |
| 650 | max_average_sig_antenna_i = 2; |
| 651 | active_chains = (1 << max_average_sig_antenna_i); |
| 652 | } |
| 653 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 654 | D_CALIB("average_sig: a %d b %d c %d\n", average_sig[0], average_sig[1], |
| 655 | average_sig[2]); |
| 656 | D_CALIB("max_average_sig = %d, antenna %d\n", max_average_sig, |
| 657 | max_average_sig_antenna_i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 658 | |
| 659 | /* Compare signal strengths for all 3 receivers. */ |
| 660 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 661 | if (i != max_average_sig_antenna_i) { |
| 662 | s32 rssi_delta = (max_average_sig - average_sig[i]); |
| 663 | |
| 664 | /* If signal is very weak, compared with |
| 665 | * strongest, mark it as disconnected. */ |
| 666 | if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS) |
| 667 | data->disconn_array[i] = 1; |
| 668 | else |
| 669 | active_chains |= (1 << i); |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 670 | D_CALIB("i = %d rssiDelta = %d " |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 671 | "disconn_array[i] = %d\n", i, rssi_delta, |
| 672 | data->disconn_array[i]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | * The above algorithm sometimes fails when the ucode |
| 678 | * reports 0 for all chains. It's not clear why that |
| 679 | * happens to start with, but it is then causing trouble |
| 680 | * because this can make us enable more chains than the |
| 681 | * hardware really has. |
| 682 | * |
| 683 | * To be safe, simply mask out any chains that we know |
| 684 | * are not on the device. |
| 685 | */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 686 | active_chains &= il->hw_params.valid_rx_ant; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 687 | |
| 688 | num_tx_chains = 0; |
| 689 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 690 | /* loops on all the bits of |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 691 | * il->hw_setting.valid_tx_ant */ |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 692 | u8 ant_msk = (1 << i); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 693 | if (!(il->hw_params.valid_tx_ant & ant_msk)) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 694 | continue; |
| 695 | |
| 696 | num_tx_chains++; |
| 697 | if (data->disconn_array[i] == 0) |
| 698 | /* there is a Tx antenna connected */ |
| 699 | break; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 700 | if (num_tx_chains == il->hw_params.tx_chains_num && |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 701 | data->disconn_array[i]) { |
| 702 | /* |
| 703 | * If all chains are disconnected |
| 704 | * connect the first valid tx chain |
| 705 | */ |
| 706 | first_chain = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 707 | il4965_find_first_chain(il->cfg->valid_tx_ant); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 708 | data->disconn_array[first_chain] = 0; |
| 709 | active_chains |= BIT(first_chain); |
Stanislaw Gruszka | 1722f8e | 2011-11-15 14:51:01 +0100 | [diff] [blame] | 710 | D_CALIB("All Tx chains are disconnected" |
| 711 | "- declare %d as connected\n", first_chain); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 712 | break; |
| 713 | } |
| 714 | } |
| 715 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 716 | if (active_chains != il->hw_params.valid_rx_ant && |
| 717 | active_chains != il->chain_noise_data.active_chains) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 718 | D_CALIB("Detected that not all antennas are connected! " |
| 719 | "Connected: %#x, valid: %#x.\n", active_chains, |
| 720 | il->hw_params.valid_rx_ant); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 721 | |
| 722 | /* Save for use within RXON, TX, SCAN commands, etc. */ |
| 723 | data->active_chains = active_chains; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 724 | D_CALIB("active_chains (bitwise) = 0x%x\n", active_chains); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 727 | static void |
| 728 | il4965_gain_computation(struct il_priv *il, u32 * average_noise, |
| 729 | u16 min_average_noise_antenna_i, u32 min_average_noise, |
| 730 | u8 default_chain) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 731 | { |
| 732 | int i, ret; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 733 | struct il_chain_noise_data *data = &il->chain_noise_data; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 734 | |
| 735 | data->delta_gain_code[min_average_noise_antenna_i] = 0; |
| 736 | |
| 737 | for (i = default_chain; i < NUM_RX_CHAINS; i++) { |
| 738 | s32 delta_g = 0; |
| 739 | |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 740 | if (!data->disconn_array[i] && |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 741 | data->delta_gain_code[i] == |
| 742 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 743 | delta_g = average_noise[i] - min_average_noise; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 744 | data->delta_gain_code[i] = (u8) ((delta_g * 10) / 15); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 745 | data->delta_gain_code[i] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 746 | min(data->delta_gain_code[i], |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 747 | (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE); |
| 748 | |
| 749 | data->delta_gain_code[i] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 750 | (data->delta_gain_code[i] | (1 << 2)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 751 | } else { |
| 752 | data->delta_gain_code[i] = 0; |
| 753 | } |
| 754 | } |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 755 | D_CALIB("delta_gain_codes: a %d b %d c %d\n", data->delta_gain_code[0], |
| 756 | data->delta_gain_code[1], data->delta_gain_code[2]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 757 | |
| 758 | /* Differential gain gets sent to uCode only once */ |
| 759 | if (!data->radio_write) { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 760 | struct il_calib_diff_gain_cmd cmd; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 761 | data->radio_write = 1; |
| 762 | |
| 763 | memset(&cmd, 0, sizeof(cmd)); |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 764 | cmd.hdr.op_code = IL_PHY_CALIBRATE_DIFF_GAIN_CMD; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 765 | cmd.diff_gain_a = data->delta_gain_code[0]; |
| 766 | cmd.diff_gain_b = data->delta_gain_code[1]; |
| 767 | cmd.diff_gain_c = data->delta_gain_code[2]; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 768 | ret = il_send_cmd_pdu(il, C_PHY_CALIBRATION, sizeof(cmd), &cmd); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 769 | if (ret) |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 770 | D_CALIB("fail sending cmd " "C_PHY_CALIBRATION\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 771 | |
| 772 | /* TODO we might want recalculate |
| 773 | * rx_chain in rxon cmd */ |
| 774 | |
| 775 | /* Mark so we run this algo only once! */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 776 | data->state = IL_CHAIN_NOISE_CALIBRATED; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 780 | /* |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 781 | * Accumulate 16 beacons of signal and noise stats for each of |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 782 | * 3 receivers/antennas/rx-chains, then figure out: |
| 783 | * 1) Which antennas are connected. |
| 784 | * 2) Differential rx gain settings to balance the 3 receivers. |
| 785 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 786 | void |
| 787 | il4965_chain_noise_calibration(struct il_priv *il, void *stat_resp) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 788 | { |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 789 | struct il_chain_noise_data *data = NULL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 790 | |
| 791 | u32 chain_noise_a; |
| 792 | u32 chain_noise_b; |
| 793 | u32 chain_noise_c; |
| 794 | u32 chain_sig_a; |
| 795 | u32 chain_sig_b; |
| 796 | u32 chain_sig_c; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 797 | u32 average_sig[NUM_RX_CHAINS] = { INITIALIZATION_VALUE }; |
| 798 | u32 average_noise[NUM_RX_CHAINS] = { INITIALIZATION_VALUE }; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 799 | u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE; |
| 800 | u16 min_average_noise_antenna_i = INITIALIZATION_VALUE; |
| 801 | u16 i = 0; |
| 802 | u16 rxon_chnum = INITIALIZATION_VALUE; |
| 803 | u16 stat_chnum = INITIALIZATION_VALUE; |
| 804 | u8 rxon_band24; |
| 805 | u8 stat_band24; |
| 806 | unsigned long flags; |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 807 | struct stats_rx_non_phy *rx_info; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 808 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 809 | if (il->disable_chain_noise_cal) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 810 | return; |
| 811 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 812 | data = &(il->chain_noise_data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 813 | |
| 814 | /* |
| 815 | * Accumulate just the first "chain_noise_num_beacons" after |
| 816 | * the first association, then we're done forever. |
| 817 | */ |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 818 | if (data->state != IL_CHAIN_NOISE_ACCUMULATE) { |
| 819 | if (data->state == IL_CHAIN_NOISE_ALIVE) |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 820 | D_CALIB("Wait for noise calib reset\n"); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 824 | spin_lock_irqsave(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 825 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 826 | rx_info = &(((struct il_notif_stats *)stat_resp)->rx.general); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 827 | |
| 828 | if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { |
Stanislaw Gruszka | 58de00a | 2011-11-15 11:21:01 +0100 | [diff] [blame] | 829 | D_CALIB(" << Interference data unavailable\n"); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 830 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 831 | return; |
| 832 | } |
| 833 | |
Stanislaw Gruszka | c8b0395 | 2012-02-03 17:31:37 +0100 | [diff] [blame] | 834 | rxon_band24 = !!(il->staging.flags & RXON_FLG_BAND_24G_MSK); |
| 835 | rxon_chnum = le16_to_cpu(il->staging.channel); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 836 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 837 | stat_band24 = |
| 838 | !!(((struct il_notif_stats *)stat_resp)-> |
| 839 | flag & STATS_REPLY_FLG_BAND_24G_MSK); |
| 840 | stat_chnum = |
| 841 | le32_to_cpu(((struct il_notif_stats *)stat_resp)->flag) >> 16; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 842 | |
| 843 | /* Make sure we accumulate data for just the associated channel |
| 844 | * (even if scanning). */ |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 845 | if (rxon_chnum != stat_chnum || rxon_band24 != stat_band24) { |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 846 | D_CALIB("Stats not from chan=%d, band24=%d\n", rxon_chnum, |
| 847 | rxon_band24); |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 848 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 849 | return; |
| 850 | } |
| 851 | |
| 852 | /* |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 853 | * Accumulate beacon stats values across |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 854 | * "chain_noise_num_beacons" |
| 855 | */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 856 | chain_noise_a = |
| 857 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
| 858 | chain_noise_b = |
| 859 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
| 860 | chain_noise_c = |
| 861 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 862 | |
| 863 | chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER; |
| 864 | chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER; |
| 865 | chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER; |
| 866 | |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 867 | spin_unlock_irqrestore(&il->lock, flags); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 868 | |
| 869 | data->beacon_count++; |
| 870 | |
| 871 | data->chain_noise_a = (chain_noise_a + data->chain_noise_a); |
| 872 | data->chain_noise_b = (chain_noise_b + data->chain_noise_b); |
| 873 | data->chain_noise_c = (chain_noise_c + data->chain_noise_c); |
| 874 | |
| 875 | data->chain_signal_a = (chain_sig_a + data->chain_signal_a); |
| 876 | data->chain_signal_b = (chain_sig_b + data->chain_signal_b); |
| 877 | data->chain_signal_c = (chain_sig_c + data->chain_signal_c); |
| 878 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 879 | D_CALIB("chan=%d, band24=%d, beacon=%d\n", rxon_chnum, rxon_band24, |
| 880 | data->beacon_count); |
| 881 | D_CALIB("chain_sig: a %d b %d c %d\n", chain_sig_a, chain_sig_b, |
| 882 | chain_sig_c); |
| 883 | D_CALIB("chain_noise: a %d b %d c %d\n", chain_noise_a, chain_noise_b, |
| 884 | chain_noise_c); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 885 | |
| 886 | /* If this is the "chain_noise_num_beacons", determine: |
| 887 | * 1) Disconnected antennas (using signal strengths) |
| 888 | * 2) Differential gain (using silence noise) to balance receivers */ |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 889 | if (data->beacon_count != il->cfg->chain_noise_num_beacons) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 890 | return; |
| 891 | |
| 892 | /* Analyze signal for disconnected antenna */ |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 893 | il4965_find_disconn_antenna(il, average_sig, data); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 894 | |
| 895 | /* Analyze noise for rx balance */ |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 896 | average_noise[0] = |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 897 | data->chain_noise_a / il->cfg->chain_noise_num_beacons; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 898 | average_noise[1] = |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 899 | data->chain_noise_b / il->cfg->chain_noise_num_beacons; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 900 | average_noise[2] = |
Stanislaw Gruszka | 89ef1ed | 2012-02-03 17:31:59 +0100 | [diff] [blame] | 901 | data->chain_noise_c / il->cfg->chain_noise_num_beacons; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 902 | |
| 903 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
Stanislaw Gruszka | 232913b | 2011-08-26 10:45:16 +0200 | [diff] [blame] | 904 | if (!data->disconn_array[i] && |
| 905 | average_noise[i] <= min_average_noise) { |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 906 | /* This means that chain i is active and has |
| 907 | * lower noise values so far: */ |
| 908 | min_average_noise = average_noise[i]; |
| 909 | min_average_noise_antenna_i = i; |
| 910 | } |
| 911 | } |
| 912 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 913 | D_CALIB("average_noise: a %d b %d c %d\n", average_noise[0], |
| 914 | average_noise[1], average_noise[2]); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 915 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 916 | D_CALIB("min_average_noise = %d, antenna %d\n", min_average_noise, |
| 917 | min_average_noise_antenna_i); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 918 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 919 | il4965_gain_computation(il, average_noise, min_average_noise_antenna_i, |
| 920 | min_average_noise, |
| 921 | il4965_find_first_chain(il->cfg->valid_rx_ant)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 922 | |
| 923 | /* Some power changes may have been made during the calibration. |
| 924 | * Update and commit the RXON |
| 925 | */ |
Stanislaw Gruszka | c39ae9f | 2012-02-03 17:31:58 +0100 | [diff] [blame] | 926 | if (il->ops->lib->update_chain_flags) |
| 927 | il->ops->lib->update_chain_flags(il); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 928 | |
Stanislaw Gruszka | e2ebc83 | 2011-10-24 15:41:30 +0200 | [diff] [blame] | 929 | data->state = IL_CHAIN_NOISE_DONE; |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 930 | il_power_update_mode(il, false); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 931 | } |
| 932 | |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 933 | void |
| 934 | il4965_reset_run_time_calib(struct il_priv *il) |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 935 | { |
| 936 | int i; |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 937 | memset(&(il->sensitivity_data), 0, sizeof(struct il_sensitivity_data)); |
| 938 | memset(&(il->chain_noise_data), 0, sizeof(struct il_chain_noise_data)); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 939 | for (i = 0; i < NUM_RX_CHAINS; i++) |
Stanislaw Gruszka | 46bc8d4 | 2011-10-24 16:49:25 +0200 | [diff] [blame] | 940 | il->chain_noise_data.delta_gain_code[i] = |
Stanislaw Gruszka | e739236 | 2011-11-15 14:45:59 +0100 | [diff] [blame] | 941 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL; |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 942 | |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 943 | /* Ask for stats now, the uCode will send notification |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 944 | * periodically after association */ |
Stanislaw Gruszka | ebf0d90 | 2011-08-26 15:43:47 +0200 | [diff] [blame] | 945 | il_send_stats_request(il, CMD_ASYNC, true); |
Wey-Yi Guy | be663ab | 2011-02-21 11:27:26 -0800 | [diff] [blame] | 946 | } |