blob: f0f5f5eada751fb3d07d4f6f9fff2b2acbf30474 [file] [log] [blame]
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07005 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -07006 *
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 Guy510cb792010-03-16 12:37:28 -070038#include "iwl-agn.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070039#include "iwl-trans.h"
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -070040
Shanyu Zhao18089722010-05-06 10:15:21 -070041int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -070042{
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 Grumbachbdfbf092011-07-08 08:46:16 -070049 return trans_send_cmd_pdu(priv,
Emmanuel Grumbache419d622011-07-08 08:46:14 -070050 TX_ANT_CONFIGURATION_CMD,
51 CMD_SYNC,
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -070052 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 Fry5c3d29f2011-07-08 08:46:29 -070060void iwlagn_gain_computation(struct iwl_priv *priv,
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -070061 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 Guy7cb1b082010-10-06 08:10:00 -070079 delta_g = (priv->cfg->base_params->chain_noise_scale *
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -070080 ((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 Guy1f8bf032011-06-06 14:26:43 -0700107 iwl_set_calib_hdr(&cmd.hdr,
108 priv->_agn.phy_calib_chain_noise_gain_cmd);
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -0700109 cmd.delta_gain_1 = data->delta_gain_code[1];
110 cmd.delta_gain_2 = data->delta_gain_code[2];
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -0700111 trans_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700112 CMD_ASYNC, sizeof(cmd), &cmd);
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -0700113
114 data->radio_write = 1;
115 data->state = IWL_CHAIN_NOISE_CALIBRATED;
116 }
Wey-Yi Guy7dc77db2010-03-16 10:23:31 -0700117}
118
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700119int iwlagn_set_pan_params(struct iwl_priv *priv)
Johannes Berg52a02d12010-08-27 09:44:50 -0700120{
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 Berg763cc3b2010-09-03 06:32:21 -0700136 /*
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 Berg52a02d12010-08-27 09:44:50 -0700145 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 Berg9b9190d2011-01-06 08:07:10 -0800153 if (priv->_agn.hw_roc_channel) {
154 /* both contexts must be used for this to happen */
155 slot1 = priv->_agn.hw_roc_duration;
Johannes Berg94073912011-01-06 08:07:11 -0800156 slot0 = IWL_MIN_SLOT_TIME;
Johannes Berg9b9190d2011-01-06 08:07:10 -0800157 } else if (ctx_bss->vif && ctx_pan->vif) {
Johannes Berg52a02d12010-08-27 09:44:50 -0700158 int bcnint = ctx_pan->vif->bss_conf.beacon_int;
Johannes Bergefe54db2010-11-10 18:25:49 -0800159 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
Johannes Berg52a02d12010-08-27 09:44:50 -0700160
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 Bergea196fd2010-09-03 06:30:55 -0700175 bcnint = DEFAULT_BEACON_INTERVAL;
Johannes Berg52a02d12010-08-27 09:44:50 -0700176 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 Berg94073912011-01-06 08:07:11 -0800182 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
183 slot1 = IWL_MIN_SLOT_TIME;
Johannes Berg52a02d12010-08-27 09:44:50 -0700184 } else if (!ctx_pan->vif->bss_conf.idle &&
Johannes Bergefe54db2010-11-10 18:25:49 -0800185 !ctx_pan->vif->bss_conf.assoc) {
Johannes Berg94073912011-01-06 08:07:11 -0800186 slot1 = bcnint * 3 - IWL_MIN_SLOT_TIME;
187 slot0 = IWL_MIN_SLOT_TIME;
Johannes Berg52a02d12010-08-27 09:44:50 -0700188 }
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 Bergea196fd2010-09-03 06:30:55 -0700193 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
Johannes Berg27eafdd2010-08-30 06:12:00 -0700194
195 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Johannes Berg94073912011-01-06 08:07:11 -0800196 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
197 slot1 = IWL_MIN_SLOT_TIME;
Johannes Berg27eafdd2010-08-30 06:12:00 -0700198 }
Johannes Berg52a02d12010-08-27 09:44:50 -0700199 }
200
201 cmd.slots[0].width = cpu_to_le16(slot0);
202 cmd.slots[1].width = cpu_to_le16(slot1);
203
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -0700204 ret = trans_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700205 sizeof(cmd), &cmd);
Johannes Berg52a02d12010-08-27 09:44:50 -0700206 if (ret)
207 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
208
209 return ret;
210}