Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [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 | * |
Johannes Berg | 128e63e | 2013-01-21 21:39:26 +0100 | [diff] [blame] | 8 | * Copyright(c) 2008 - 2013 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 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 |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
Johannes Berg | 128e63e | 2013-01-21 21:39:26 +0100 | [diff] [blame] | 33 | * Copyright(c) 2005 - 2013 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 63 | #include <linux/slab.h> |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 64 | #include <net/mac80211.h> |
| 65 | |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 66 | #include "iwl-trans.h" |
Johannes Berg | 1023fdc | 2012-05-15 12:16:34 +0200 | [diff] [blame] | 67 | |
| 68 | #include "dev.h" |
| 69 | #include "calib.h" |
| 70 | #include "agn.h" |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 71 | |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 72 | /***************************************************************************** |
| 73 | * INIT calibrations framework |
| 74 | *****************************************************************************/ |
| 75 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 76 | /* Opaque calibration results */ |
| 77 | struct iwl_calib_result { |
| 78 | struct list_head list; |
| 79 | size_t cmd_len; |
| 80 | struct iwl_calib_hdr hdr; |
| 81 | /* data follows */ |
| 82 | }; |
| 83 | |
Winkler, Tomas | 34c22cf | 2008-12-17 16:52:27 +0800 | [diff] [blame] | 84 | struct statistics_general_data { |
| 85 | u32 beacon_silence_rssi_a; |
| 86 | u32 beacon_silence_rssi_b; |
| 87 | u32 beacon_silence_rssi_c; |
| 88 | u32 beacon_energy_a; |
| 89 | u32 beacon_energy_b; |
| 90 | u32 beacon_energy_c; |
| 91 | }; |
| 92 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 93 | int iwl_send_calib_results(struct iwl_priv *priv) |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 94 | { |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 95 | struct iwl_host_cmd hcmd = { |
| 96 | .id = REPLY_PHY_CALIBRATION_CMD, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 97 | .flags = CMD_SYNC, |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 98 | }; |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 99 | struct iwl_calib_result *res; |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 100 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 101 | list_for_each_entry(res, &priv->calib_results, list) { |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 102 | int ret; |
| 103 | |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 104 | hcmd.len[0] = res->cmd_len; |
| 105 | hcmd.data[0] = &res->hdr; |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 106 | hcmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 107 | ret = iwl_dvm_send_cmd(priv, &hcmd); |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 108 | if (ret) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 109 | IWL_ERR(priv, "Error %d on calib cmd %d\n", |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 110 | ret, res->hdr.op_code); |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 111 | return ret; |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 112 | } |
Tomas Winkler | be5d56e | 2008-10-08 09:37:27 +0800 | [diff] [blame] | 113 | } |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 114 | |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 115 | return 0; |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 116 | } |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 117 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 118 | int iwl_calib_set(struct iwl_priv *priv, |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 119 | const struct iwl_calib_hdr *cmd, int len) |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 120 | { |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 121 | struct iwl_calib_result *res, *tmp; |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 122 | |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 123 | res = kmalloc(sizeof(*res) + len - sizeof(struct iwl_calib_hdr), |
| 124 | GFP_ATOMIC); |
| 125 | if (!res) |
| 126 | return -ENOMEM; |
| 127 | memcpy(&res->hdr, cmd, len); |
| 128 | res->cmd_len = len; |
| 129 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 130 | list_for_each_entry(tmp, &priv->calib_results, list) { |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 131 | if (tmp->hdr.op_code == res->hdr.op_code) { |
| 132 | list_replace(&tmp->list, &res->list); |
| 133 | kfree(tmp); |
| 134 | return 0; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* wasn't in list already */ |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 139 | list_add_tail(&res->list, &priv->calib_results); |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 140 | |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 141 | return 0; |
| 142 | } |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 143 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 144 | void iwl_calib_free_results(struct iwl_priv *priv) |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 145 | { |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 146 | struct iwl_calib_result *res, *tmp; |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 147 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 148 | list_for_each_entry_safe(res, tmp, &priv->calib_results, list) { |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 149 | list_del(&res->list); |
| 150 | kfree(res); |
Tomas Winkler | 6e21f2c | 2008-09-03 11:26:37 +0800 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | /***************************************************************************** |
| 155 | * RUNTIME calibrations framework |
| 156 | *****************************************************************************/ |
| 157 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 158 | /* "false alarms" are signals that our DSP tries to lock onto, |
| 159 | * but then determines that they are either noise, or transmissions |
| 160 | * from a distant wireless network (also "noise", really) that get |
| 161 | * "stepped on" by stronger transmissions within our own network. |
| 162 | * This algorithm attempts to set a sensitivity level that is high |
| 163 | * enough to receive all of our own network traffic, but not so |
| 164 | * high that our DSP gets too busy trying to lock onto non-network |
| 165 | * activity/noise. */ |
| 166 | static int iwl_sens_energy_cck(struct iwl_priv *priv, |
| 167 | u32 norm_fa, |
| 168 | u32 rx_enable_time, |
| 169 | struct statistics_general_data *rx_info) |
| 170 | { |
| 171 | u32 max_nrg_cck = 0; |
| 172 | int i = 0; |
| 173 | u8 max_silence_rssi = 0; |
| 174 | u32 silence_ref = 0; |
| 175 | u8 silence_rssi_a = 0; |
| 176 | u8 silence_rssi_b = 0; |
| 177 | u8 silence_rssi_c = 0; |
| 178 | u32 val; |
| 179 | |
| 180 | /* "false_alarms" values below are cross-multiplications to assess the |
| 181 | * numbers of false alarms within the measured period of actual Rx |
| 182 | * (Rx is off when we're txing), vs the min/max expected false alarms |
| 183 | * (some should be expected if rx is sensitive enough) in a |
| 184 | * hypothetical listening period of 200 time units (TU), 204.8 msec: |
| 185 | * |
| 186 | * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time |
| 187 | * |
| 188 | * */ |
| 189 | u32 false_alarms = norm_fa * 200 * 1024; |
| 190 | u32 max_false_alarms = MAX_FA_CCK * rx_enable_time; |
| 191 | u32 min_false_alarms = MIN_FA_CCK * rx_enable_time; |
| 192 | struct iwl_sensitivity_data *data = NULL; |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 193 | const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 194 | |
| 195 | data = &(priv->sensitivity_data); |
| 196 | |
| 197 | data->nrg_auto_corr_silence_diff = 0; |
| 198 | |
| 199 | /* Find max silence rssi among all 3 receivers. |
| 200 | * This is background noise, which may include transmissions from other |
| 201 | * networks, measured during silence before our network's beacon */ |
| 202 | silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a & |
| 203 | ALL_BAND_FILTER) >> 8); |
| 204 | silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b & |
| 205 | ALL_BAND_FILTER) >> 8); |
| 206 | silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c & |
| 207 | ALL_BAND_FILTER) >> 8); |
| 208 | |
| 209 | val = max(silence_rssi_b, silence_rssi_c); |
| 210 | max_silence_rssi = max(silence_rssi_a, (u8) val); |
| 211 | |
| 212 | /* Store silence rssi in 20-beacon history table */ |
| 213 | data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi; |
| 214 | data->nrg_silence_idx++; |
| 215 | if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L) |
| 216 | data->nrg_silence_idx = 0; |
| 217 | |
| 218 | /* Find max silence rssi across 20 beacon history */ |
| 219 | for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) { |
| 220 | val = data->nrg_silence_rssi[i]; |
| 221 | silence_ref = max(silence_ref, val); |
| 222 | } |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 223 | IWL_DEBUG_CALIB(priv, "silence a %u, b %u, c %u, 20-bcn max %u\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 224 | silence_rssi_a, silence_rssi_b, silence_rssi_c, |
| 225 | silence_ref); |
| 226 | |
| 227 | /* Find max rx energy (min value!) among all 3 receivers, |
| 228 | * measured during beacon frame. |
| 229 | * Save it in 10-beacon history table. */ |
| 230 | i = data->nrg_energy_idx; |
| 231 | val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c); |
| 232 | data->nrg_value[i] = min(rx_info->beacon_energy_a, val); |
| 233 | |
| 234 | data->nrg_energy_idx++; |
| 235 | if (data->nrg_energy_idx >= 10) |
| 236 | data->nrg_energy_idx = 0; |
| 237 | |
| 238 | /* Find min rx energy (max value) across 10 beacon history. |
| 239 | * This is the minimum signal level that we want to receive well. |
| 240 | * Add backoff (margin so we don't miss slightly lower energy frames). |
| 241 | * This establishes an upper bound (min value) for energy threshold. */ |
| 242 | max_nrg_cck = data->nrg_value[0]; |
| 243 | for (i = 1; i < 10; i++) |
| 244 | max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i])); |
| 245 | max_nrg_cck += 6; |
| 246 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 247 | IWL_DEBUG_CALIB(priv, "rx energy a %u, b %u, c %u, 10-bcn max/min %u\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 248 | rx_info->beacon_energy_a, rx_info->beacon_energy_b, |
| 249 | rx_info->beacon_energy_c, max_nrg_cck - 6); |
| 250 | |
| 251 | /* Count number of consecutive beacons with fewer-than-desired |
| 252 | * false alarms. */ |
| 253 | if (false_alarms < min_false_alarms) |
| 254 | data->num_in_cck_no_fa++; |
| 255 | else |
| 256 | data->num_in_cck_no_fa = 0; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 257 | IWL_DEBUG_CALIB(priv, "consecutive bcns with few false alarms = %u\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 258 | data->num_in_cck_no_fa); |
| 259 | |
| 260 | /* If we got too many false alarms this time, reduce sensitivity */ |
| 261 | if ((false_alarms > max_false_alarms) && |
| 262 | (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 263 | IWL_DEBUG_CALIB(priv, "norm FA %u > max FA %u\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 264 | false_alarms, max_false_alarms); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 265 | IWL_DEBUG_CALIB(priv, "... reducing sensitivity\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 266 | data->nrg_curr_state = IWL_FA_TOO_MANY; |
| 267 | /* Store for "fewer than desired" on later beacon */ |
| 268 | data->nrg_silence_ref = silence_ref; |
| 269 | |
| 270 | /* increase energy threshold (reduce nrg value) |
| 271 | * to decrease sensitivity */ |
Wey-Yi Guy | fe6efb4 | 2009-06-12 13:22:54 -0700 | [diff] [blame] | 272 | data->nrg_th_cck = data->nrg_th_cck - NRG_STEP_CCK; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 273 | /* Else if we got fewer than desired, increase sensitivity */ |
| 274 | } else if (false_alarms < min_false_alarms) { |
| 275 | data->nrg_curr_state = IWL_FA_TOO_FEW; |
| 276 | |
| 277 | /* Compare silence level with silence level for most recent |
| 278 | * healthy number or too many false alarms */ |
| 279 | data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref - |
| 280 | (s32)silence_ref; |
| 281 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 282 | IWL_DEBUG_CALIB(priv, "norm FA %u < min FA %u, silence diff %d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 283 | false_alarms, min_false_alarms, |
| 284 | data->nrg_auto_corr_silence_diff); |
| 285 | |
| 286 | /* Increase value to increase sensitivity, but only if: |
| 287 | * 1a) previous beacon did *not* have *too many* false alarms |
| 288 | * 1b) AND there's a significant difference in Rx levels |
| 289 | * from a previous beacon with too many, or healthy # FAs |
| 290 | * OR 2) We've seen a lot of beacons (100) with too few |
| 291 | * false alarms */ |
| 292 | if ((data->nrg_prev_state != IWL_FA_TOO_MANY) && |
| 293 | ((data->nrg_auto_corr_silence_diff > NRG_DIFF) || |
| 294 | (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) { |
| 295 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 296 | IWL_DEBUG_CALIB(priv, "... increasing sensitivity\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 297 | /* Increase nrg value to increase sensitivity */ |
| 298 | val = data->nrg_th_cck + NRG_STEP_CCK; |
| 299 | data->nrg_th_cck = min((u32)ranges->min_nrg_cck, val); |
| 300 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 301 | IWL_DEBUG_CALIB(priv, "... but not changing sensitivity\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* Else we got a healthy number of false alarms, keep status quo */ |
| 305 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 306 | IWL_DEBUG_CALIB(priv, " FA in safe zone\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 307 | data->nrg_curr_state = IWL_FA_GOOD_RANGE; |
| 308 | |
| 309 | /* Store for use in "fewer than desired" with later beacon */ |
| 310 | data->nrg_silence_ref = silence_ref; |
| 311 | |
| 312 | /* If previous beacon had too many false alarms, |
| 313 | * give it some extra margin by reducing sensitivity again |
| 314 | * (but don't go below measured energy of desired Rx) */ |
| 315 | if (IWL_FA_TOO_MANY == data->nrg_prev_state) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 316 | IWL_DEBUG_CALIB(priv, "... increasing margin\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 317 | if (data->nrg_th_cck > (max_nrg_cck + NRG_MARGIN)) |
| 318 | data->nrg_th_cck -= NRG_MARGIN; |
| 319 | else |
| 320 | data->nrg_th_cck = max_nrg_cck; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /* Make sure the energy threshold does not go above the measured |
| 325 | * energy of the desired Rx signals (reduced by backoff margin), |
| 326 | * or else we might start missing Rx frames. |
| 327 | * Lower value is higher energy, so we use max()! |
| 328 | */ |
| 329 | data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 330 | IWL_DEBUG_CALIB(priv, "new nrg_th_cck %u\n", data->nrg_th_cck); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 331 | |
| 332 | data->nrg_prev_state = data->nrg_curr_state; |
| 333 | |
| 334 | /* Auto-correlation CCK algorithm */ |
| 335 | if (false_alarms > min_false_alarms) { |
| 336 | |
| 337 | /* increase auto_corr values to decrease sensitivity |
| 338 | * so the DSP won't be disturbed by the noise |
| 339 | */ |
| 340 | if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK) |
| 341 | data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1; |
| 342 | else { |
| 343 | val = data->auto_corr_cck + AUTO_CORR_STEP_CCK; |
| 344 | data->auto_corr_cck = |
| 345 | min((u32)ranges->auto_corr_max_cck, val); |
| 346 | } |
| 347 | val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK; |
| 348 | data->auto_corr_cck_mrc = |
| 349 | min((u32)ranges->auto_corr_max_cck_mrc, val); |
| 350 | } else if ((false_alarms < min_false_alarms) && |
| 351 | ((data->nrg_auto_corr_silence_diff > NRG_DIFF) || |
| 352 | (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) { |
| 353 | |
| 354 | /* Decrease auto_corr values to increase sensitivity */ |
| 355 | val = data->auto_corr_cck - AUTO_CORR_STEP_CCK; |
| 356 | data->auto_corr_cck = |
| 357 | max((u32)ranges->auto_corr_min_cck, val); |
| 358 | val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK; |
| 359 | data->auto_corr_cck_mrc = |
| 360 | max((u32)ranges->auto_corr_min_cck_mrc, val); |
| 361 | } |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | static int iwl_sens_auto_corr_ofdm(struct iwl_priv *priv, |
| 368 | u32 norm_fa, |
| 369 | u32 rx_enable_time) |
| 370 | { |
| 371 | u32 val; |
| 372 | u32 false_alarms = norm_fa * 200 * 1024; |
| 373 | u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time; |
| 374 | u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time; |
| 375 | struct iwl_sensitivity_data *data = NULL; |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 376 | const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 377 | |
| 378 | data = &(priv->sensitivity_data); |
| 379 | |
| 380 | /* If we got too many false alarms this time, reduce sensitivity */ |
| 381 | if (false_alarms > max_false_alarms) { |
| 382 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 383 | IWL_DEBUG_CALIB(priv, "norm FA %u > max FA %u)\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 384 | false_alarms, max_false_alarms); |
| 385 | |
| 386 | val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM; |
| 387 | data->auto_corr_ofdm = |
| 388 | min((u32)ranges->auto_corr_max_ofdm, val); |
| 389 | |
| 390 | val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM; |
| 391 | data->auto_corr_ofdm_mrc = |
| 392 | min((u32)ranges->auto_corr_max_ofdm_mrc, val); |
| 393 | |
| 394 | val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM; |
| 395 | data->auto_corr_ofdm_x1 = |
| 396 | min((u32)ranges->auto_corr_max_ofdm_x1, val); |
| 397 | |
| 398 | val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM; |
| 399 | data->auto_corr_ofdm_mrc_x1 = |
| 400 | min((u32)ranges->auto_corr_max_ofdm_mrc_x1, val); |
| 401 | } |
| 402 | |
| 403 | /* Else if we got fewer than desired, increase sensitivity */ |
| 404 | else if (false_alarms < min_false_alarms) { |
| 405 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 406 | IWL_DEBUG_CALIB(priv, "norm FA %u < min FA %u\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 407 | false_alarms, min_false_alarms); |
| 408 | |
| 409 | val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM; |
| 410 | data->auto_corr_ofdm = |
| 411 | max((u32)ranges->auto_corr_min_ofdm, val); |
| 412 | |
| 413 | val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM; |
| 414 | data->auto_corr_ofdm_mrc = |
| 415 | max((u32)ranges->auto_corr_min_ofdm_mrc, val); |
| 416 | |
| 417 | val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM; |
| 418 | data->auto_corr_ofdm_x1 = |
| 419 | max((u32)ranges->auto_corr_min_ofdm_x1, val); |
| 420 | |
| 421 | val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM; |
| 422 | data->auto_corr_ofdm_mrc_x1 = |
| 423 | max((u32)ranges->auto_corr_min_ofdm_mrc_x1, val); |
| 424 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 425 | IWL_DEBUG_CALIB(priv, "min FA %u < norm FA %u < max FA %u OK\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 426 | min_false_alarms, false_alarms, max_false_alarms); |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 431 | static void iwl_prepare_legacy_sensitivity_tbl(struct iwl_priv *priv, |
| 432 | struct iwl_sensitivity_data *data, |
| 433 | __le16 *tbl) |
| 434 | { |
| 435 | tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] = |
| 436 | cpu_to_le16((u16)data->auto_corr_ofdm); |
| 437 | tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] = |
| 438 | cpu_to_le16((u16)data->auto_corr_ofdm_mrc); |
| 439 | tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] = |
| 440 | cpu_to_le16((u16)data->auto_corr_ofdm_x1); |
| 441 | tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] = |
| 442 | cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1); |
| 443 | |
| 444 | tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] = |
| 445 | cpu_to_le16((u16)data->auto_corr_cck); |
| 446 | tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] = |
| 447 | cpu_to_le16((u16)data->auto_corr_cck_mrc); |
| 448 | |
| 449 | tbl[HD_MIN_ENERGY_CCK_DET_INDEX] = |
| 450 | cpu_to_le16((u16)data->nrg_th_cck); |
| 451 | tbl[HD_MIN_ENERGY_OFDM_DET_INDEX] = |
| 452 | cpu_to_le16((u16)data->nrg_th_ofdm); |
| 453 | |
| 454 | tbl[HD_BARKER_CORR_TH_ADD_MIN_INDEX] = |
| 455 | cpu_to_le16(data->barker_corr_th_min); |
| 456 | tbl[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] = |
| 457 | cpu_to_le16(data->barker_corr_th_min_mrc); |
| 458 | tbl[HD_OFDM_ENERGY_TH_IN_INDEX] = |
| 459 | cpu_to_le16(data->nrg_th_cca); |
| 460 | |
| 461 | IWL_DEBUG_CALIB(priv, "ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n", |
| 462 | data->auto_corr_ofdm, data->auto_corr_ofdm_mrc, |
| 463 | data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1, |
| 464 | data->nrg_th_ofdm); |
| 465 | |
| 466 | IWL_DEBUG_CALIB(priv, "cck: ac %u mrc %u thresh %u\n", |
| 467 | data->auto_corr_cck, data->auto_corr_cck_mrc, |
| 468 | data->nrg_th_cck); |
| 469 | } |
| 470 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 471 | /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */ |
| 472 | static int iwl_sensitivity_write(struct iwl_priv *priv) |
| 473 | { |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 474 | struct iwl_sensitivity_cmd cmd; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 475 | struct iwl_sensitivity_data *data = NULL; |
| 476 | struct iwl_host_cmd cmd_out = { |
| 477 | .id = SENSITIVITY_CMD, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 478 | .len = { sizeof(struct iwl_sensitivity_cmd), }, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 479 | .flags = CMD_ASYNC, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 480 | .data = { &cmd, }, |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | data = &(priv->sensitivity_data); |
| 484 | |
| 485 | memset(&cmd, 0, sizeof(cmd)); |
| 486 | |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 487 | iwl_prepare_legacy_sensitivity_tbl(priv, data, &cmd.table[0]); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 488 | |
| 489 | /* Update uCode's "work" table, and copy it to DSP */ |
| 490 | cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE; |
| 491 | |
| 492 | /* Don't send command to uCode if nothing has changed */ |
| 493 | if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]), |
| 494 | sizeof(u16)*HD_TABLE_SIZE)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 495 | IWL_DEBUG_CALIB(priv, "No change in SENSITIVITY_CMD\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | /* Copy table for comparison next time */ |
| 500 | memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]), |
| 501 | sizeof(u16)*HD_TABLE_SIZE); |
| 502 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 503 | return iwl_dvm_send_cmd(priv, &cmd_out); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 506 | /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */ |
| 507 | static int iwl_enhance_sensitivity_write(struct iwl_priv *priv) |
| 508 | { |
| 509 | struct iwl_enhance_sensitivity_cmd cmd; |
| 510 | struct iwl_sensitivity_data *data = NULL; |
| 511 | struct iwl_host_cmd cmd_out = { |
| 512 | .id = SENSITIVITY_CMD, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 513 | .len = { sizeof(struct iwl_enhance_sensitivity_cmd), }, |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 514 | .flags = CMD_ASYNC, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 515 | .data = { &cmd, }, |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 516 | }; |
| 517 | |
| 518 | data = &(priv->sensitivity_data); |
| 519 | |
| 520 | memset(&cmd, 0, sizeof(cmd)); |
| 521 | |
| 522 | iwl_prepare_legacy_sensitivity_tbl(priv, data, &cmd.enhance_table[0]); |
| 523 | |
Johannes Berg | 0d8877a | 2013-05-17 10:36:29 +0200 | [diff] [blame] | 524 | if (priv->lib->hd_v2) { |
Wey-Yi Guy | ae7f9a7 | 2011-07-23 10:24:50 -0700 | [diff] [blame] | 525 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX] = |
| 526 | HD_INA_NON_SQUARE_DET_OFDM_DATA_V2; |
| 527 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_CCK_INDEX] = |
| 528 | HD_INA_NON_SQUARE_DET_CCK_DATA_V2; |
| 529 | cmd.enhance_table[HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX] = |
| 530 | HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA_V2; |
| 531 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX] = |
| 532 | HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA_V2; |
| 533 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = |
| 534 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V2; |
| 535 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX] = |
| 536 | HD_OFDM_NON_SQUARE_DET_SLOPE_DATA_V2; |
| 537 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX] = |
| 538 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA_V2; |
| 539 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX] = |
| 540 | HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA_V2; |
| 541 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = |
| 542 | HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V2; |
| 543 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_INDEX] = |
| 544 | HD_CCK_NON_SQUARE_DET_SLOPE_DATA_V2; |
| 545 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX] = |
| 546 | HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA_V2; |
| 547 | } else { |
| 548 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX] = |
| 549 | HD_INA_NON_SQUARE_DET_OFDM_DATA_V1; |
| 550 | cmd.enhance_table[HD_INA_NON_SQUARE_DET_CCK_INDEX] = |
| 551 | HD_INA_NON_SQUARE_DET_CCK_DATA_V1; |
| 552 | cmd.enhance_table[HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX] = |
| 553 | HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA_V1; |
| 554 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX] = |
| 555 | HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA_V1; |
| 556 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = |
| 557 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V1; |
| 558 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX] = |
| 559 | HD_OFDM_NON_SQUARE_DET_SLOPE_DATA_V1; |
| 560 | cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX] = |
| 561 | HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA_V1; |
| 562 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX] = |
| 563 | HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA_V1; |
| 564 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] = |
| 565 | HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA_V1; |
| 566 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_INDEX] = |
| 567 | HD_CCK_NON_SQUARE_DET_SLOPE_DATA_V1; |
| 568 | cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX] = |
| 569 | HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA_V1; |
| 570 | } |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 571 | |
| 572 | /* Update uCode's "work" table, and copy it to DSP */ |
| 573 | cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE; |
| 574 | |
| 575 | /* Don't send command to uCode if nothing has changed */ |
| 576 | if (!memcmp(&cmd.enhance_table[0], &(priv->sensitivity_tbl[0]), |
| 577 | sizeof(u16)*HD_TABLE_SIZE) && |
| 578 | !memcmp(&cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX], |
| 579 | &(priv->enhance_sensitivity_tbl[0]), |
| 580 | sizeof(u16)*ENHANCE_HD_TABLE_ENTRIES)) { |
| 581 | IWL_DEBUG_CALIB(priv, "No change in SENSITIVITY_CMD\n"); |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | /* Copy table for comparison next time */ |
| 586 | memcpy(&(priv->sensitivity_tbl[0]), &(cmd.enhance_table[0]), |
| 587 | sizeof(u16)*HD_TABLE_SIZE); |
| 588 | memcpy(&(priv->enhance_sensitivity_tbl[0]), |
| 589 | &(cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX]), |
| 590 | sizeof(u16)*ENHANCE_HD_TABLE_ENTRIES); |
| 591 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 592 | return iwl_dvm_send_cmd(priv, &cmd_out); |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 595 | void iwl_init_sensitivity(struct iwl_priv *priv) |
| 596 | { |
| 597 | int ret = 0; |
| 598 | int i; |
| 599 | struct iwl_sensitivity_data *data = NULL; |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 600 | const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 601 | |
Dor Shaish | bfb45f5 | 2012-03-26 08:20:55 -0700 | [diff] [blame] | 602 | if (priv->calib_disabled & IWL_SENSITIVITY_CALIB_DISABLED) |
Tomas Winkler | 445c2df | 2008-05-15 13:54:16 +0800 | [diff] [blame] | 603 | return; |
| 604 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 605 | IWL_DEBUG_CALIB(priv, "Start iwl_init_sensitivity\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 606 | |
| 607 | /* Clear driver's sensitivity algo data */ |
| 608 | data = &(priv->sensitivity_data); |
| 609 | |
| 610 | if (ranges == NULL) |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 611 | return; |
| 612 | |
| 613 | memset(data, 0, sizeof(struct iwl_sensitivity_data)); |
| 614 | |
| 615 | data->num_in_cck_no_fa = 0; |
| 616 | data->nrg_curr_state = IWL_FA_TOO_MANY; |
| 617 | data->nrg_prev_state = IWL_FA_TOO_MANY; |
| 618 | data->nrg_silence_ref = 0; |
| 619 | data->nrg_silence_idx = 0; |
| 620 | data->nrg_energy_idx = 0; |
| 621 | |
| 622 | for (i = 0; i < 10; i++) |
| 623 | data->nrg_value[i] = 0; |
| 624 | |
| 625 | for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) |
| 626 | data->nrg_silence_rssi[i] = 0; |
| 627 | |
Wey-Yi Guy | f3a2a42 | 2009-09-11 10:38:11 -0700 | [diff] [blame] | 628 | data->auto_corr_ofdm = ranges->auto_corr_min_ofdm; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 629 | data->auto_corr_ofdm_mrc = ranges->auto_corr_min_ofdm_mrc; |
| 630 | data->auto_corr_ofdm_x1 = ranges->auto_corr_min_ofdm_x1; |
| 631 | data->auto_corr_ofdm_mrc_x1 = ranges->auto_corr_min_ofdm_mrc_x1; |
| 632 | data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF; |
| 633 | data->auto_corr_cck_mrc = ranges->auto_corr_min_cck_mrc; |
| 634 | data->nrg_th_cck = ranges->nrg_th_cck; |
| 635 | data->nrg_th_ofdm = ranges->nrg_th_ofdm; |
Wey-Yi Guy | 55036d6 | 2009-10-09 13:20:24 -0700 | [diff] [blame] | 636 | data->barker_corr_th_min = ranges->barker_corr_th_min; |
| 637 | data->barker_corr_th_min_mrc = ranges->barker_corr_th_min_mrc; |
| 638 | data->nrg_th_cca = ranges->nrg_th_cca; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 639 | |
| 640 | data->last_bad_plcp_cnt_ofdm = 0; |
| 641 | data->last_fa_cnt_ofdm = 0; |
| 642 | data->last_bad_plcp_cnt_cck = 0; |
| 643 | data->last_fa_cnt_cck = 0; |
| 644 | |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 645 | if (priv->fw->enhance_sensitivity_table) |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 646 | ret |= iwl_enhance_sensitivity_write(priv); |
| 647 | else |
| 648 | ret |= iwl_sensitivity_write(priv); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 649 | IWL_DEBUG_CALIB(priv, "<<return 0x%X\n", ret); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 650 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 651 | |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 652 | void iwl_sensitivity_calibration(struct iwl_priv *priv) |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 653 | { |
| 654 | u32 rx_enable_time; |
| 655 | u32 fa_cck; |
| 656 | u32 fa_ofdm; |
| 657 | u32 bad_plcp_cck; |
| 658 | u32 bad_plcp_ofdm; |
| 659 | u32 norm_fa_ofdm; |
| 660 | u32 norm_fa_cck; |
| 661 | struct iwl_sensitivity_data *data = NULL; |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 662 | struct statistics_rx_non_phy *rx_info; |
| 663 | struct statistics_rx_phy *ofdm, *cck; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 664 | struct statistics_general_data statis; |
| 665 | |
Dor Shaish | bfb45f5 | 2012-03-26 08:20:55 -0700 | [diff] [blame] | 666 | if (priv->calib_disabled & IWL_SENSITIVITY_CALIB_DISABLED) |
Tomas Winkler | 445c2df | 2008-05-15 13:54:16 +0800 | [diff] [blame] | 667 | return; |
| 668 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 669 | data = &(priv->sensitivity_data); |
| 670 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 671 | if (!iwl_is_any_associated(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 672 | IWL_DEBUG_CALIB(priv, "<< - not associated\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 676 | spin_lock_bh(&priv->statistics.lock); |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 677 | rx_info = &priv->statistics.rx_non_phy; |
| 678 | ofdm = &priv->statistics.rx_ofdm; |
| 679 | cck = &priv->statistics.rx_cck; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 680 | if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 681 | IWL_DEBUG_CALIB(priv, "<< invalid data.\n"); |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 682 | spin_unlock_bh(&priv->statistics.lock); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 683 | return; |
| 684 | } |
| 685 | |
| 686 | /* Extract Statistics: */ |
| 687 | rx_enable_time = le32_to_cpu(rx_info->channel_load); |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 688 | fa_cck = le32_to_cpu(cck->false_alarm_cnt); |
| 689 | fa_ofdm = le32_to_cpu(ofdm->false_alarm_cnt); |
| 690 | bad_plcp_cck = le32_to_cpu(cck->plcp_err); |
| 691 | bad_plcp_ofdm = le32_to_cpu(ofdm->plcp_err); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 692 | |
| 693 | statis.beacon_silence_rssi_a = |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 694 | le32_to_cpu(rx_info->beacon_silence_rssi_a); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 695 | statis.beacon_silence_rssi_b = |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 696 | le32_to_cpu(rx_info->beacon_silence_rssi_b); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 697 | statis.beacon_silence_rssi_c = |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 698 | le32_to_cpu(rx_info->beacon_silence_rssi_c); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 699 | statis.beacon_energy_a = |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 700 | le32_to_cpu(rx_info->beacon_energy_a); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 701 | statis.beacon_energy_b = |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 702 | le32_to_cpu(rx_info->beacon_energy_b); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 703 | statis.beacon_energy_c = |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 704 | le32_to_cpu(rx_info->beacon_energy_c); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 705 | |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 706 | spin_unlock_bh(&priv->statistics.lock); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 707 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 708 | IWL_DEBUG_CALIB(priv, "rx_enable_time = %u usecs\n", rx_enable_time); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 709 | |
| 710 | if (!rx_enable_time) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 711 | IWL_DEBUG_CALIB(priv, "<< RX Enable Time == 0!\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
| 715 | /* These statistics increase monotonically, and do not reset |
| 716 | * at each beacon. Calculate difference from last value, or just |
| 717 | * use the new statistics value if it has reset or wrapped around. */ |
| 718 | if (data->last_bad_plcp_cnt_cck > bad_plcp_cck) |
| 719 | data->last_bad_plcp_cnt_cck = bad_plcp_cck; |
| 720 | else { |
| 721 | bad_plcp_cck -= data->last_bad_plcp_cnt_cck; |
| 722 | data->last_bad_plcp_cnt_cck += bad_plcp_cck; |
| 723 | } |
| 724 | |
| 725 | if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm) |
| 726 | data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm; |
| 727 | else { |
| 728 | bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm; |
| 729 | data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm; |
| 730 | } |
| 731 | |
| 732 | if (data->last_fa_cnt_ofdm > fa_ofdm) |
| 733 | data->last_fa_cnt_ofdm = fa_ofdm; |
| 734 | else { |
| 735 | fa_ofdm -= data->last_fa_cnt_ofdm; |
| 736 | data->last_fa_cnt_ofdm += fa_ofdm; |
| 737 | } |
| 738 | |
| 739 | if (data->last_fa_cnt_cck > fa_cck) |
| 740 | data->last_fa_cnt_cck = fa_cck; |
| 741 | else { |
| 742 | fa_cck -= data->last_fa_cnt_cck; |
| 743 | data->last_fa_cnt_cck += fa_cck; |
| 744 | } |
| 745 | |
| 746 | /* Total aborted signal locks */ |
| 747 | norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm; |
| 748 | norm_fa_cck = fa_cck + bad_plcp_cck; |
| 749 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 750 | IWL_DEBUG_CALIB(priv, "cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck, |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 751 | bad_plcp_cck, fa_ofdm, bad_plcp_ofdm); |
| 752 | |
| 753 | iwl_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time); |
| 754 | iwl_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis); |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 755 | if (priv->fw->enhance_sensitivity_table) |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 756 | iwl_enhance_sensitivity_write(priv); |
| 757 | else |
| 758 | iwl_sensitivity_write(priv); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 759 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 760 | |
Wey-Yi Guy | d8c07e7 | 2009-09-25 14:24:26 -0700 | [diff] [blame] | 761 | static inline u8 find_first_chain(u8 mask) |
| 762 | { |
| 763 | if (mask & ANT_A) |
| 764 | return CHAIN_A; |
| 765 | if (mask & ANT_B) |
| 766 | return CHAIN_B; |
| 767 | return CHAIN_C; |
| 768 | } |
| 769 | |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 770 | /** |
| 771 | * Run disconnected antenna algorithm to find out which antennas are |
| 772 | * disconnected. |
| 773 | */ |
| 774 | static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig, |
| 775 | struct iwl_chain_noise_data *data) |
| 776 | { |
| 777 | u32 active_chains = 0; |
| 778 | u32 max_average_sig; |
| 779 | u16 max_average_sig_antenna_i; |
| 780 | u8 num_tx_chains; |
| 781 | u8 first_chain; |
| 782 | u16 i = 0; |
| 783 | |
Fry, Donald H | b8c2b05 | 2011-09-15 11:46:38 -0700 | [diff] [blame] | 784 | average_sig[0] = data->chain_signal_a / IWL_CAL_NUM_BEACONS; |
| 785 | average_sig[1] = data->chain_signal_b / IWL_CAL_NUM_BEACONS; |
| 786 | average_sig[2] = data->chain_signal_c / IWL_CAL_NUM_BEACONS; |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 787 | |
| 788 | if (average_sig[0] >= average_sig[1]) { |
| 789 | max_average_sig = average_sig[0]; |
| 790 | max_average_sig_antenna_i = 0; |
| 791 | active_chains = (1 << max_average_sig_antenna_i); |
| 792 | } else { |
| 793 | max_average_sig = average_sig[1]; |
| 794 | max_average_sig_antenna_i = 1; |
| 795 | active_chains = (1 << max_average_sig_antenna_i); |
| 796 | } |
| 797 | |
| 798 | if (average_sig[2] >= max_average_sig) { |
| 799 | max_average_sig = average_sig[2]; |
| 800 | max_average_sig_antenna_i = 2; |
| 801 | active_chains = (1 << max_average_sig_antenna_i); |
| 802 | } |
| 803 | |
| 804 | IWL_DEBUG_CALIB(priv, "average_sig: a %d b %d c %d\n", |
| 805 | average_sig[0], average_sig[1], average_sig[2]); |
| 806 | IWL_DEBUG_CALIB(priv, "max_average_sig = %d, antenna %d\n", |
| 807 | max_average_sig, max_average_sig_antenna_i); |
| 808 | |
| 809 | /* Compare signal strengths for all 3 receivers. */ |
| 810 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 811 | if (i != max_average_sig_antenna_i) { |
| 812 | s32 rssi_delta = (max_average_sig - average_sig[i]); |
| 813 | |
| 814 | /* If signal is very weak, compared with |
| 815 | * strongest, mark it as disconnected. */ |
| 816 | if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS) |
| 817 | data->disconn_array[i] = 1; |
| 818 | else |
| 819 | active_chains |= (1 << i); |
| 820 | IWL_DEBUG_CALIB(priv, "i = %d rssiDelta = %d " |
| 821 | "disconn_array[i] = %d\n", |
| 822 | i, rssi_delta, data->disconn_array[i]); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | /* |
| 827 | * The above algorithm sometimes fails when the ucode |
| 828 | * reports 0 for all chains. It's not clear why that |
| 829 | * happens to start with, but it is then causing trouble |
| 830 | * because this can make us enable more chains than the |
| 831 | * hardware really has. |
| 832 | * |
| 833 | * To be safe, simply mask out any chains that we know |
| 834 | * are not on the device. |
| 835 | */ |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 836 | active_chains &= priv->nvm_data->valid_rx_ant; |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 837 | |
| 838 | num_tx_chains = 0; |
| 839 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 840 | /* loops on all the bits of |
| 841 | * priv->hw_setting.valid_tx_ant */ |
| 842 | u8 ant_msk = (1 << i); |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 843 | if (!(priv->nvm_data->valid_tx_ant & ant_msk)) |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 844 | continue; |
| 845 | |
| 846 | num_tx_chains++; |
| 847 | if (data->disconn_array[i] == 0) |
| 848 | /* there is a Tx antenna connected */ |
| 849 | break; |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 850 | if (num_tx_chains == priv->hw_params.tx_chains_num && |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 851 | data->disconn_array[i]) { |
| 852 | /* |
| 853 | * If all chains are disconnected |
| 854 | * connect the first valid tx chain |
| 855 | */ |
| 856 | first_chain = |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 857 | find_first_chain(priv->nvm_data->valid_tx_ant); |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 858 | data->disconn_array[first_chain] = 0; |
| 859 | active_chains |= BIT(first_chain); |
Joe Perches | 85ee7a1 | 2011-04-23 20:38:19 -0700 | [diff] [blame] | 860 | IWL_DEBUG_CALIB(priv, |
| 861 | "All Tx chains are disconnected W/A - declare %d as connected\n", |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 862 | first_chain); |
| 863 | break; |
| 864 | } |
| 865 | } |
| 866 | |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 867 | if (active_chains != priv->nvm_data->valid_rx_ant && |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 868 | active_chains != priv->chain_noise_data.active_chains) |
| 869 | IWL_DEBUG_CALIB(priv, |
| 870 | "Detected that not all antennas are connected! " |
| 871 | "Connected: %#x, valid: %#x.\n", |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 872 | active_chains, |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 873 | priv->nvm_data->valid_rx_ant); |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 874 | |
| 875 | /* Save for use within RXON, TX, SCAN commands, etc. */ |
| 876 | data->active_chains = active_chains; |
| 877 | IWL_DEBUG_CALIB(priv, "active_chains (bitwise) = 0x%x\n", |
| 878 | active_chains); |
| 879 | } |
| 880 | |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 881 | static void iwlagn_gain_computation(struct iwl_priv *priv, |
Johannes Berg | fdeff46 | 2012-03-07 09:52:10 -0800 | [diff] [blame] | 882 | u32 average_noise[NUM_RX_CHAINS], |
| 883 | u8 default_chain) |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 884 | { |
| 885 | int i; |
| 886 | s32 delta_g; |
| 887 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; |
| 888 | |
| 889 | /* |
| 890 | * Find Gain Code for the chains based on "default chain" |
| 891 | */ |
| 892 | for (i = default_chain + 1; i < NUM_RX_CHAINS; i++) { |
| 893 | if ((data->disconn_array[i])) { |
| 894 | data->delta_gain_code[i] = 0; |
| 895 | continue; |
| 896 | } |
| 897 | |
Johannes Berg | 0d8877a | 2013-05-17 10:36:29 +0200 | [diff] [blame] | 898 | delta_g = (priv->lib->chain_noise_scale * |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 899 | ((s32)average_noise[default_chain] - |
| 900 | (s32)average_noise[i])) / 1500; |
| 901 | |
| 902 | /* bound gain by 2 bits value max, 3rd bit is sign */ |
| 903 | data->delta_gain_code[i] = |
| 904 | min(abs(delta_g), |
| 905 | (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE); |
| 906 | |
| 907 | if (delta_g < 0) |
| 908 | /* |
| 909 | * set negative sign ... |
| 910 | * note to Intel developers: This is uCode API format, |
| 911 | * not the format of any internal device registers. |
| 912 | * Do not change this format for e.g. 6050 or similar |
| 913 | * devices. Change format only if more resolution |
| 914 | * (i.e. more than 2 bits magnitude) is needed. |
| 915 | */ |
| 916 | data->delta_gain_code[i] |= (1 << 2); |
| 917 | } |
| 918 | |
| 919 | IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n", |
| 920 | data->delta_gain_code[1], data->delta_gain_code[2]); |
| 921 | |
| 922 | if (!data->radio_write) { |
| 923 | struct iwl_calib_chain_noise_gain_cmd cmd; |
| 924 | |
| 925 | memset(&cmd, 0, sizeof(cmd)); |
| 926 | |
| 927 | iwl_set_calib_hdr(&cmd.hdr, |
Wey-Yi Guy | 898ed67 | 2011-07-13 08:38:57 -0700 | [diff] [blame] | 928 | priv->phy_calib_chain_noise_gain_cmd); |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 929 | cmd.delta_gain_1 = data->delta_gain_code[1]; |
| 930 | cmd.delta_gain_2 = data->delta_gain_code[2]; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 931 | iwl_dvm_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, |
Wey-Yi Guy | e505c43 | 2011-07-07 08:27:41 -0700 | [diff] [blame] | 932 | CMD_ASYNC, sizeof(cmd), &cmd); |
| 933 | |
| 934 | data->radio_write = 1; |
| 935 | data->state = IWL_CHAIN_NOISE_CALIBRATED; |
| 936 | } |
| 937 | } |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 938 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 939 | /* |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 940 | * Accumulate 16 beacons of signal and noise statistics for each of |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 941 | * 3 receivers/antennas/rx-chains, then figure out: |
| 942 | * 1) Which antennas are connected. |
| 943 | * 2) Differential rx gain settings to balance the 3 receivers. |
| 944 | */ |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 945 | void iwl_chain_noise_calibration(struct iwl_priv *priv) |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 946 | { |
| 947 | struct iwl_chain_noise_data *data = NULL; |
| 948 | |
| 949 | u32 chain_noise_a; |
| 950 | u32 chain_noise_b; |
| 951 | u32 chain_noise_c; |
| 952 | u32 chain_sig_a; |
| 953 | u32 chain_sig_b; |
| 954 | u32 chain_sig_c; |
| 955 | u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE}; |
| 956 | u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE}; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 957 | u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE; |
| 958 | u16 min_average_noise_antenna_i = INITIALIZATION_VALUE; |
| 959 | u16 i = 0; |
| 960 | u16 rxon_chnum = INITIALIZATION_VALUE; |
| 961 | u16 stat_chnum = INITIALIZATION_VALUE; |
| 962 | u8 rxon_band24; |
| 963 | u8 stat_band24; |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 964 | struct statistics_rx_non_phy *rx_info; |
Shanyu Zhao | 3031242 | 2010-11-10 09:56:48 -0800 | [diff] [blame] | 965 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 966 | /* |
| 967 | * MULTI-FIXME: |
| 968 | * When we support multiple interfaces on different channels, |
| 969 | * this must be modified/fixed. |
| 970 | */ |
| 971 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 972 | |
Dor Shaish | bfb45f5 | 2012-03-26 08:20:55 -0700 | [diff] [blame] | 973 | if (priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED) |
Tomas Winkler | 445c2df | 2008-05-15 13:54:16 +0800 | [diff] [blame] | 974 | return; |
| 975 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 976 | data = &(priv->chain_noise_data); |
| 977 | |
Wey-Yi Guy | d8c07e7 | 2009-09-25 14:24:26 -0700 | [diff] [blame] | 978 | /* |
| 979 | * Accumulate just the first "chain_noise_num_beacons" after |
| 980 | * the first association, then we're done forever. |
| 981 | */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 982 | if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) { |
| 983 | if (data->state == IWL_CHAIN_NOISE_ALIVE) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 984 | IWL_DEBUG_CALIB(priv, "Wait for noise calib reset\n"); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 985 | return; |
| 986 | } |
| 987 | |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 988 | spin_lock_bh(&priv->statistics.lock); |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 989 | |
| 990 | rx_info = &priv->statistics.rx_non_phy; |
| 991 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 992 | if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 993 | IWL_DEBUG_CALIB(priv, " << Interference data unavailable\n"); |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 994 | spin_unlock_bh(&priv->statistics.lock); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 995 | return; |
| 996 | } |
| 997 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 998 | rxon_band24 = !!(ctx->staging.flags & RXON_FLG_BAND_24G_MSK); |
| 999 | rxon_chnum = le16_to_cpu(ctx->staging.channel); |
Johannes Berg | 0da0e5b | 2011-04-08 08:14:56 -0700 | [diff] [blame] | 1000 | stat_band24 = |
| 1001 | !!(priv->statistics.flag & STATISTICS_REPLY_FLG_BAND_24G_MSK); |
| 1002 | stat_chnum = le32_to_cpu(priv->statistics.flag) >> 16; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1003 | |
| 1004 | /* Make sure we accumulate data for just the associated channel |
| 1005 | * (even if scanning). */ |
| 1006 | if ((rxon_chnum != stat_chnum) || (rxon_band24 != stat_band24)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1007 | IWL_DEBUG_CALIB(priv, "Stats not from chan=%d, band24=%d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1008 | rxon_chnum, rxon_band24); |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 1009 | spin_unlock_bh(&priv->statistics.lock); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1010 | return; |
| 1011 | } |
| 1012 | |
Wey-Yi Guy | d8c07e7 | 2009-09-25 14:24:26 -0700 | [diff] [blame] | 1013 | /* |
| 1014 | * Accumulate beacon statistics values across |
| 1015 | * "chain_noise_num_beacons" |
| 1016 | */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1017 | chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) & |
| 1018 | IN_BAND_FILTER; |
| 1019 | chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) & |
| 1020 | IN_BAND_FILTER; |
| 1021 | chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) & |
| 1022 | IN_BAND_FILTER; |
| 1023 | |
| 1024 | chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER; |
| 1025 | chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER; |
| 1026 | chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER; |
| 1027 | |
Johannes Berg | 4ff70fc | 2012-03-05 11:24:26 -0800 | [diff] [blame] | 1028 | spin_unlock_bh(&priv->statistics.lock); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1029 | |
| 1030 | data->beacon_count++; |
| 1031 | |
| 1032 | data->chain_noise_a = (chain_noise_a + data->chain_noise_a); |
| 1033 | data->chain_noise_b = (chain_noise_b + data->chain_noise_b); |
| 1034 | data->chain_noise_c = (chain_noise_c + data->chain_noise_c); |
| 1035 | |
| 1036 | data->chain_signal_a = (chain_sig_a + data->chain_signal_a); |
| 1037 | data->chain_signal_b = (chain_sig_b + data->chain_signal_b); |
| 1038 | data->chain_signal_c = (chain_sig_c + data->chain_signal_c); |
| 1039 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1040 | IWL_DEBUG_CALIB(priv, "chan=%d, band24=%d, beacon=%d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1041 | rxon_chnum, rxon_band24, data->beacon_count); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1042 | IWL_DEBUG_CALIB(priv, "chain_sig: a %d b %d c %d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1043 | chain_sig_a, chain_sig_b, chain_sig_c); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1044 | IWL_DEBUG_CALIB(priv, "chain_noise: a %d b %d c %d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1045 | chain_noise_a, chain_noise_b, chain_noise_c); |
| 1046 | |
Wey-Yi Guy | d8c07e7 | 2009-09-25 14:24:26 -0700 | [diff] [blame] | 1047 | /* If this is the "chain_noise_num_beacons", determine: |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1048 | * 1) Disconnected antennas (using signal strengths) |
| 1049 | * 2) Differential gain (using silence noise) to balance receivers */ |
Fry, Donald H | b8c2b05 | 2011-09-15 11:46:38 -0700 | [diff] [blame] | 1050 | if (data->beacon_count != IWL_CAL_NUM_BEACONS) |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1051 | return; |
| 1052 | |
| 1053 | /* Analyze signal for disconnected antenna */ |
Johannes Berg | 0d8877a | 2013-05-17 10:36:29 +0200 | [diff] [blame] | 1054 | if (priv->lib->bt_params && |
| 1055 | priv->lib->bt_params->advanced_bt_coexist) { |
Shanyu Zhao | 6fe8efb | 2010-11-10 09:56:49 -0800 | [diff] [blame] | 1056 | /* Disable disconnected antenna algorithm for advanced |
| 1057 | bt coex, assuming valid antennas are connected */ |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 1058 | data->active_chains = priv->nvm_data->valid_rx_ant; |
Shanyu Zhao | 6fe8efb | 2010-11-10 09:56:49 -0800 | [diff] [blame] | 1059 | for (i = 0; i < NUM_RX_CHAINS; i++) |
| 1060 | if (!(data->active_chains & (1<<i))) |
| 1061 | data->disconn_array[i] = 1; |
| 1062 | } else |
| 1063 | iwl_find_disconn_antenna(priv, average_sig, data); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1064 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1065 | /* Analyze noise for rx balance */ |
Fry, Donald H | b8c2b05 | 2011-09-15 11:46:38 -0700 | [diff] [blame] | 1066 | average_noise[0] = data->chain_noise_a / IWL_CAL_NUM_BEACONS; |
| 1067 | average_noise[1] = data->chain_noise_b / IWL_CAL_NUM_BEACONS; |
| 1068 | average_noise[2] = data->chain_noise_c / IWL_CAL_NUM_BEACONS; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1069 | |
| 1070 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 1071 | if (!(data->disconn_array[i]) && |
| 1072 | (average_noise[i] <= min_average_noise)) { |
| 1073 | /* This means that chain i is active and has |
| 1074 | * lower noise values so far: */ |
| 1075 | min_average_noise = average_noise[i]; |
| 1076 | min_average_noise_antenna_i = i; |
| 1077 | } |
| 1078 | } |
| 1079 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1080 | IWL_DEBUG_CALIB(priv, "average_noise: a %d b %d c %d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1081 | average_noise[0], average_noise[1], |
| 1082 | average_noise[2]); |
| 1083 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1084 | IWL_DEBUG_CALIB(priv, "min_average_noise = %d, antenna %d\n", |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1085 | min_average_noise, min_average_noise_antenna_i); |
| 1086 | |
Johannes Berg | 26a7ca9 | 2012-05-21 11:55:54 +0200 | [diff] [blame] | 1087 | iwlagn_gain_computation( |
| 1088 | priv, average_noise, |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame] | 1089 | find_first_chain(priv->nvm_data->valid_rx_ant)); |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 1090 | |
| 1091 | /* Some power changes may have been made during the calibration. |
| 1092 | * Update and commit the RXON |
| 1093 | */ |
Fry, Donald H | 6b6db91 | 2011-07-08 08:46:17 -0700 | [diff] [blame] | 1094 | iwl_update_chain_flags(priv); |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 1095 | |
| 1096 | data->state = IWL_CHAIN_NOISE_DONE; |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 1097 | iwl_power_update_mode(priv, false); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1098 | } |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 1099 | |
| 1100 | void iwl_reset_run_time_calib(struct iwl_priv *priv) |
| 1101 | { |
| 1102 | int i; |
| 1103 | memset(&(priv->sensitivity_data), 0, |
| 1104 | sizeof(struct iwl_sensitivity_data)); |
| 1105 | memset(&(priv->chain_noise_data), 0, |
| 1106 | sizeof(struct iwl_chain_noise_data)); |
| 1107 | for (i = 0; i < NUM_RX_CHAINS; i++) |
| 1108 | priv->chain_noise_data.delta_gain_code[i] = |
| 1109 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL; |
| 1110 | |
| 1111 | /* Ask for statistics now, the uCode will send notification |
| 1112 | * periodically after association */ |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 1113 | iwl_send_statistics_request(priv, CMD_ASYNC, true); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 1114 | } |