iwlagn: remove old EEPROM TX power reading
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-agn-eeprom.c
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 - 2010 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 - 2010 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
64 #include <linux/kernel.h>
65 #include <linux/module.h>
66 #include <linux/slab.h>
67 #include <linux/init.h>
68
69 #include <net/mac80211.h>
70
71 #include "iwl-commands.h"
72 #include "iwl-dev.h"
73 #include "iwl-core.h"
74 #include "iwl-debug.h"
75 #include "iwl-agn.h"
76 #include "iwl-io.h"
77
78 /******************************************************************************
79 *
80 * EEPROM related functions
81 *
82 ******************************************************************************/
83
84 /*
85 * The device's EEPROM semaphore prevents conflicts between driver and uCode
86 * when accessing the EEPROM; each access is a series of pulses to/from the
87 * EEPROM chip, not a single event, so even reads could conflict if they
88 * weren't arbitrated by the semaphore.
89 */
90 int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv)
91 {
92 u16 count;
93 int ret;
94
95 for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
96 /* Request semaphore */
97 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
98 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
99
100 /* See if we got it */
101 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
102 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
103 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
104 EEPROM_SEM_TIMEOUT);
105 if (ret >= 0) {
106 IWL_DEBUG_IO(priv,
107 "Acquired semaphore after %d tries.\n",
108 count+1);
109 return ret;
110 }
111 }
112
113 return ret;
114 }
115
116 void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
117 {
118 iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
119 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
120
121 }
122
123 int iwl_eeprom_check_version(struct iwl_priv *priv)
124 {
125 u16 eeprom_ver;
126 u16 calib_ver;
127
128 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
129 calib_ver = priv->cfg->ops->lib->eeprom_ops.calib_version(priv);
130
131 if (eeprom_ver < priv->cfg->eeprom_ver ||
132 calib_ver < priv->cfg->eeprom_calib_ver)
133 goto err;
134
135 IWL_INFO(priv, "device EEPROM VER=0x%x, CALIB=0x%x\n",
136 eeprom_ver, calib_ver);
137
138 return 0;
139 err:
140 IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x "
141 "CALIB=0x%x < 0x%x\n",
142 eeprom_ver, priv->cfg->eeprom_ver,
143 calib_ver, priv->cfg->eeprom_calib_ver);
144 return -EINVAL;
145
146 }
147
148 int iwl_eeprom_check_sku(struct iwl_priv *priv)
149 {
150 u16 eeprom_sku;
151 u16 radio_cfg;
152
153 eeprom_sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP);
154
155 priv->cfg->sku = ((eeprom_sku & EEPROM_SKU_CAP_BAND_SELECTION) >>
156 EEPROM_SKU_CAP_BAND_POS);
157 if (eeprom_sku & EEPROM_SKU_CAP_11N_ENABLE)
158 priv->cfg->sku |= IWL_SKU_N;
159
160 if (!priv->cfg->sku) {
161 IWL_ERR(priv, "Invalid device sku\n");
162 return -EINVAL;
163 }
164
165 IWL_INFO(priv, "Device SKU: 0X%x\n", priv->cfg->sku);
166
167 if (!priv->cfg->valid_tx_ant && !priv->cfg->valid_rx_ant) {
168 /* not using .cfg overwrite */
169 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
170 priv->cfg->valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
171 priv->cfg->valid_rx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
172 if (!priv->cfg->valid_tx_ant || !priv->cfg->valid_rx_ant) {
173 IWL_ERR(priv, "Invalid chain (0X%x, 0X%x)\n",
174 priv->cfg->valid_tx_ant,
175 priv->cfg->valid_rx_ant);
176 return -EINVAL;
177 }
178 IWL_INFO(priv, "Valid Tx ant: 0X%x, Valid Rx ant: 0X%x\n",
179 priv->cfg->valid_tx_ant, priv->cfg->valid_rx_ant);
180 }
181 /*
182 * for some special cases,
183 * EEPROM did not reflect the correct antenna setting
184 * so overwrite the valid tx/rx antenna from .cfg
185 */
186 return 0;
187 }
188
189 void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
190 {
191 const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
192 EEPROM_MAC_ADDRESS);
193 memcpy(mac, addr, ETH_ALEN);
194 }
195
196 /**
197 * iwl_get_max_txpower_avg - get the highest tx power from all chains.
198 * find the highest tx power from all chains for the channel
199 */
200 static s8 iwl_get_max_txpower_avg(struct iwl_priv *priv,
201 struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
202 int element, s8 *max_txpower_in_half_dbm)
203 {
204 s8 max_txpower_avg = 0; /* (dBm) */
205
206 IWL_DEBUG_INFO(priv, "%d - "
207 "chain_a: %d dB chain_b: %d dB "
208 "chain_c: %d dB mimo2: %d dB mimo3: %d dB\n",
209 element,
210 enhanced_txpower[element].chain_a_max >> 1,
211 enhanced_txpower[element].chain_b_max >> 1,
212 enhanced_txpower[element].chain_c_max >> 1,
213 enhanced_txpower[element].mimo2_max >> 1,
214 enhanced_txpower[element].mimo3_max >> 1);
215 /* Take the highest tx power from any valid chains */
216 if ((priv->cfg->valid_tx_ant & ANT_A) &&
217 (enhanced_txpower[element].chain_a_max > max_txpower_avg))
218 max_txpower_avg = enhanced_txpower[element].chain_a_max;
219 if ((priv->cfg->valid_tx_ant & ANT_B) &&
220 (enhanced_txpower[element].chain_b_max > max_txpower_avg))
221 max_txpower_avg = enhanced_txpower[element].chain_b_max;
222 if ((priv->cfg->valid_tx_ant & ANT_C) &&
223 (enhanced_txpower[element].chain_c_max > max_txpower_avg))
224 max_txpower_avg = enhanced_txpower[element].chain_c_max;
225 if (((priv->cfg->valid_tx_ant == ANT_AB) |
226 (priv->cfg->valid_tx_ant == ANT_BC) |
227 (priv->cfg->valid_tx_ant == ANT_AC)) &&
228 (enhanced_txpower[element].mimo2_max > max_txpower_avg))
229 max_txpower_avg = enhanced_txpower[element].mimo2_max;
230 if ((priv->cfg->valid_tx_ant == ANT_ABC) &&
231 (enhanced_txpower[element].mimo3_max > max_txpower_avg))
232 max_txpower_avg = enhanced_txpower[element].mimo3_max;
233
234 /*
235 * max. tx power in EEPROM is in 1/2 dBm format
236 * convert from 1/2 dBm to dBm (round-up convert)
237 * but we also do not want to loss 1/2 dBm resolution which
238 * will impact performance
239 */
240 *max_txpower_in_half_dbm = max_txpower_avg;
241 return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1);
242 }
243
244 static void
245 iwlcore_eeprom_enh_txp_read_element(struct iwl_priv *priv,
246 struct iwl_eeprom_enhanced_txpwr *txp,
247 s8 max_txpower_avg)
248 {
249 int ch_idx;
250 bool is_ht40 = txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ;
251 enum ieee80211_band band;
252
253 band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ?
254 IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ;
255
256 for (ch_idx = 0; ch_idx < priv->channel_count; ch_idx++) {
257 struct iwl_channel_info *ch_info = &priv->channel_info[ch_idx];
258
259 /* update matching channel or from common data only */
260 if (txp->channel != 0 && ch_info->channel != txp->channel)
261 continue;
262
263 /* update matching band only */
264 if (band != ch_info->band)
265 continue;
266
267 if (ch_info->max_power_avg < max_txpower_avg && !is_ht40) {
268 ch_info->max_power_avg = max_txpower_avg;
269 ch_info->curr_txpow = max_txpower_avg;
270 ch_info->scan_power = max_txpower_avg;
271 }
272
273 if (is_ht40 && ch_info->ht40_max_power_avg < max_txpower_avg)
274 ch_info->ht40_max_power_avg = max_txpower_avg;
275 }
276 }
277
278 #define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
279 #define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
280 #define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
281
282 void iwlcore_eeprom_enhanced_txpower(struct iwl_priv *priv)
283 {
284 struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
285 int idx, entries;
286 __le16 *txp_len;
287 s8 max_txp_avg, max_txp_avg_halfdbm;
288
289 BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
290
291 /* the length is in 16-bit words, but we want entries */
292 txp_len = (__le16 *) iwlagn_eeprom_query_addr(priv, EEPROM_TXP_SZ_OFFS);
293 entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
294
295 txp_array = (void *) iwlagn_eeprom_query_addr(priv, EEPROM_TXP_OFFS);
296 for (idx = 0; idx < entries; idx++) {
297 txp = &txp_array[idx];
298
299 /* skip invalid entries */
300 if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID))
301 continue;
302
303 max_txp_avg = iwl_get_max_txpower_avg(priv, txp_array, idx,
304 &max_txp_avg_halfdbm);
305
306 /*
307 * Update the user limit values values to the highest
308 * power supported by any channel
309 */
310 if (max_txp_avg > priv->tx_power_user_lmt)
311 priv->tx_power_user_lmt = max_txp_avg;
312 if (max_txp_avg_halfdbm > priv->tx_power_lmt_in_half_dbm)
313 priv->tx_power_lmt_in_half_dbm = max_txp_avg_halfdbm;
314
315 iwlcore_eeprom_enh_txp_read_element(priv, txp, max_txp_avg);
316 }
317 }
This page took 0.038445 seconds and 6 git commands to generate.