Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 5 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 19 | * USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/sched.h> |
| 34 | |
| 35 | #include "iwl-dev.h" |
| 36 | #include "iwl-core.h" |
| 37 | #include "iwl-io.h" |
Wey-Yi Guy | 510cb79 | 2010-03-16 12:37:28 -0700 | [diff] [blame] | 38 | #include "iwl-agn.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 39 | #include "iwl-trans.h" |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 40 | |
Shanyu Zhao | 1808972 | 2010-05-06 10:15:21 -0700 | [diff] [blame] | 41 | int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant) |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 42 | { |
| 43 | struct iwl_tx_ant_config_cmd tx_ant_cmd = { |
| 44 | .valid = cpu_to_le32(valid_tx_ant), |
| 45 | }; |
| 46 | |
| 47 | if (IWL_UCODE_API(priv->ucode_ver) > 1) { |
| 48 | IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant); |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 49 | return trans_send_cmd_pdu(priv, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 50 | TX_ANT_CONFIGURATION_CMD, |
| 51 | CMD_SYNC, |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 52 | sizeof(struct iwl_tx_ant_config_cmd), |
| 53 | &tx_ant_cmd); |
| 54 | } else { |
| 55 | IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n"); |
| 56 | return -EOPNOTSUPP; |
| 57 | } |
| 58 | } |
| 59 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 60 | void iwlagn_gain_computation(struct iwl_priv *priv, |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 61 | u32 average_noise[NUM_RX_CHAINS], |
| 62 | u16 min_average_noise_antenna_i, |
| 63 | u32 min_average_noise, |
| 64 | u8 default_chain) |
| 65 | { |
| 66 | int i; |
| 67 | s32 delta_g; |
| 68 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; |
| 69 | |
| 70 | /* |
| 71 | * Find Gain Code for the chains based on "default chain" |
| 72 | */ |
| 73 | for (i = default_chain + 1; i < NUM_RX_CHAINS; i++) { |
| 74 | if ((data->disconn_array[i])) { |
| 75 | data->delta_gain_code[i] = 0; |
| 76 | continue; |
| 77 | } |
| 78 | |
Wey-Yi Guy | 7cb1b08 | 2010-10-06 08:10:00 -0700 | [diff] [blame] | 79 | delta_g = (priv->cfg->base_params->chain_noise_scale * |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 80 | ((s32)average_noise[default_chain] - |
| 81 | (s32)average_noise[i])) / 1500; |
| 82 | |
| 83 | /* bound gain by 2 bits value max, 3rd bit is sign */ |
| 84 | data->delta_gain_code[i] = |
| 85 | min(abs(delta_g), (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE); |
| 86 | |
| 87 | if (delta_g < 0) |
| 88 | /* |
| 89 | * set negative sign ... |
| 90 | * note to Intel developers: This is uCode API format, |
| 91 | * not the format of any internal device registers. |
| 92 | * Do not change this format for e.g. 6050 or similar |
| 93 | * devices. Change format only if more resolution |
| 94 | * (i.e. more than 2 bits magnitude) is needed. |
| 95 | */ |
| 96 | data->delta_gain_code[i] |= (1 << 2); |
| 97 | } |
| 98 | |
| 99 | IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n", |
| 100 | data->delta_gain_code[1], data->delta_gain_code[2]); |
| 101 | |
| 102 | if (!data->radio_write) { |
| 103 | struct iwl_calib_chain_noise_gain_cmd cmd; |
| 104 | |
| 105 | memset(&cmd, 0, sizeof(cmd)); |
| 106 | |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 107 | iwl_set_calib_hdr(&cmd.hdr, |
| 108 | priv->_agn.phy_calib_chain_noise_gain_cmd); |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 109 | cmd.delta_gain_1 = data->delta_gain_code[1]; |
| 110 | cmd.delta_gain_2 = data->delta_gain_code[2]; |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 111 | trans_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 112 | CMD_ASYNC, sizeof(cmd), &cmd); |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 113 | |
| 114 | data->radio_write = 1; |
| 115 | data->state = IWL_CHAIN_NOISE_CALIBRATED; |
| 116 | } |
Wey-Yi Guy | 7dc77db | 2010-03-16 10:23:31 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Wey-Yi Guy | e3f10ce | 2011-07-01 07:59:26 -0700 | [diff] [blame] | 119 | int iwlagn_set_pan_params(struct iwl_priv *priv) |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 120 | { |
| 121 | struct iwl_wipan_params_cmd cmd; |
| 122 | struct iwl_rxon_context *ctx_bss, *ctx_pan; |
| 123 | int slot0 = 300, slot1 = 0; |
| 124 | int ret; |
| 125 | |
| 126 | if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS)) |
| 127 | return 0; |
| 128 | |
| 129 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
| 130 | |
| 131 | lockdep_assert_held(&priv->mutex); |
| 132 | |
| 133 | ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 134 | ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN]; |
| 135 | |
Johannes Berg | 763cc3b | 2010-09-03 06:32:21 -0700 | [diff] [blame] | 136 | /* |
| 137 | * If the PAN context is inactive, then we don't need |
| 138 | * to update the PAN parameters, the last thing we'll |
| 139 | * have done before it goes inactive is making the PAN |
| 140 | * parameters be WLAN-only. |
| 141 | */ |
| 142 | if (!ctx_pan->is_active) |
| 143 | return 0; |
| 144 | |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 145 | memset(&cmd, 0, sizeof(cmd)); |
| 146 | |
| 147 | /* only 2 slots are currently allowed */ |
| 148 | cmd.num_slots = 2; |
| 149 | |
| 150 | cmd.slots[0].type = 0; /* BSS */ |
| 151 | cmd.slots[1].type = 1; /* PAN */ |
| 152 | |
Johannes Berg | 9b9190d | 2011-01-06 08:07:10 -0800 | [diff] [blame] | 153 | if (priv->_agn.hw_roc_channel) { |
| 154 | /* both contexts must be used for this to happen */ |
| 155 | slot1 = priv->_agn.hw_roc_duration; |
Johannes Berg | 9407391 | 2011-01-06 08:07:11 -0800 | [diff] [blame] | 156 | slot0 = IWL_MIN_SLOT_TIME; |
Johannes Berg | 9b9190d | 2011-01-06 08:07:10 -0800 | [diff] [blame] | 157 | } else if (ctx_bss->vif && ctx_pan->vif) { |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 158 | int bcnint = ctx_pan->vif->bss_conf.beacon_int; |
Johannes Berg | efe54db | 2010-11-10 18:25:49 -0800 | [diff] [blame] | 159 | int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1; |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 160 | |
| 161 | /* should be set, but seems unused?? */ |
| 162 | cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE); |
| 163 | |
| 164 | if (ctx_pan->vif->type == NL80211_IFTYPE_AP && |
| 165 | bcnint && |
| 166 | bcnint != ctx_bss->vif->bss_conf.beacon_int) { |
| 167 | IWL_ERR(priv, |
| 168 | "beacon intervals don't match (%d, %d)\n", |
| 169 | ctx_bss->vif->bss_conf.beacon_int, |
| 170 | ctx_pan->vif->bss_conf.beacon_int); |
| 171 | } else |
| 172 | bcnint = max_t(int, bcnint, |
| 173 | ctx_bss->vif->bss_conf.beacon_int); |
| 174 | if (!bcnint) |
Johannes Berg | ea196fd | 2010-09-03 06:30:55 -0700 | [diff] [blame] | 175 | bcnint = DEFAULT_BEACON_INTERVAL; |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 176 | slot0 = bcnint / 2; |
| 177 | slot1 = bcnint - slot0; |
| 178 | |
| 179 | if (test_bit(STATUS_SCAN_HW, &priv->status) || |
| 180 | (!ctx_bss->vif->bss_conf.idle && |
| 181 | !ctx_bss->vif->bss_conf.assoc)) { |
Johannes Berg | 9407391 | 2011-01-06 08:07:11 -0800 | [diff] [blame] | 182 | slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; |
| 183 | slot1 = IWL_MIN_SLOT_TIME; |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 184 | } else if (!ctx_pan->vif->bss_conf.idle && |
Johannes Berg | efe54db | 2010-11-10 18:25:49 -0800 | [diff] [blame] | 185 | !ctx_pan->vif->bss_conf.assoc) { |
Johannes Berg | 9407391 | 2011-01-06 08:07:11 -0800 | [diff] [blame] | 186 | slot1 = bcnint * 3 - IWL_MIN_SLOT_TIME; |
| 187 | slot0 = IWL_MIN_SLOT_TIME; |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 188 | } |
| 189 | } else if (ctx_pan->vif) { |
| 190 | slot0 = 0; |
| 191 | slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) * |
| 192 | ctx_pan->vif->bss_conf.beacon_int; |
Johannes Berg | ea196fd | 2010-09-03 06:30:55 -0700 | [diff] [blame] | 193 | slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1); |
Johannes Berg | 27eafdd | 2010-08-30 06:12:00 -0700 | [diff] [blame] | 194 | |
| 195 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
Johannes Berg | 9407391 | 2011-01-06 08:07:11 -0800 | [diff] [blame] | 196 | slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME; |
| 197 | slot1 = IWL_MIN_SLOT_TIME; |
Johannes Berg | 27eafdd | 2010-08-30 06:12:00 -0700 | [diff] [blame] | 198 | } |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | cmd.slots[0].width = cpu_to_le16(slot0); |
| 202 | cmd.slots[1].width = cpu_to_le16(slot1); |
| 203 | |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 204 | ret = trans_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 205 | sizeof(cmd), &cmd); |
Johannes Berg | 52a02d1 | 2010-08-27 09:44:50 -0700 | [diff] [blame] | 206 | if (ret) |
| 207 | IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret); |
| 208 | |
| 209 | return ret; |
| 210 | } |