1 /******************************************************************************
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.
8 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/module.h>
66 #include <linux/slab.h>
67 #include <linux/init.h>
69 #include <net/mac80211.h>
71 #include "iwl-commands.h"
74 #include "iwl-debug.h"
78 /******************************************************************************
80 * EEPROM related functions
82 ******************************************************************************/
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.
90 int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv)
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);
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,
106 IWL_DEBUG_EEPROM(priv,
107 "Acquired semaphore after %d tries.\n",
116 void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
118 iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
119 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
123 int iwl_eeprom_check_version(struct iwl_priv *priv)
128 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
129 calib_ver = priv->cfg->ops->lib->eeprom_ops.calib_version(priv);
131 if (eeprom_ver < priv->cfg->eeprom_ver ||
132 calib_ver < priv->cfg->eeprom_calib_ver)
135 IWL_INFO(priv, "device EEPROM VER=0x%x, CALIB=0x%x\n",
136 eeprom_ver, calib_ver);
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);
148 int iwl_eeprom_check_sku(struct iwl_priv *priv)
153 eeprom_sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP);
155 if (!priv->cfg->sku) {
156 /* not using sku overwrite */
158 ((eeprom_sku & EEPROM_SKU_CAP_BAND_SELECTION) >>
159 EEPROM_SKU_CAP_BAND_POS);
160 if (eeprom_sku & EEPROM_SKU_CAP_11N_ENABLE)
161 priv->cfg->sku |= IWL_SKU_N;
163 if (!priv->cfg->sku) {
164 IWL_ERR(priv, "Invalid device sku\n");
168 IWL_INFO(priv, "Device SKU: 0X%x\n", priv->cfg->sku);
170 if (!priv->cfg->valid_tx_ant && !priv->cfg->valid_rx_ant) {
171 /* not using .cfg overwrite */
172 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
173 priv->cfg->valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
174 priv->cfg->valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg);
175 if (!priv->cfg->valid_tx_ant || !priv->cfg->valid_rx_ant) {
176 IWL_ERR(priv, "Invalid chain (0X%x, 0X%x)\n",
177 priv->cfg->valid_tx_ant,
178 priv->cfg->valid_rx_ant);
181 IWL_INFO(priv, "Valid Tx ant: 0X%x, Valid Rx ant: 0X%x\n",
182 priv->cfg->valid_tx_ant, priv->cfg->valid_rx_ant);
185 * for some special cases,
186 * EEPROM did not reflect the correct antenna setting
187 * so overwrite the valid tx/rx antenna from .cfg
192 void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
194 const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
196 memcpy(mac, addr, ETH_ALEN);
200 * iwl_get_max_txpower_avg - get the highest tx power from all chains.
201 * find the highest tx power from all chains for the channel
203 static s8 iwl_get_max_txpower_avg(struct iwl_priv *priv,
204 struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
205 int element, s8 *max_txpower_in_half_dbm)
207 s8 max_txpower_avg = 0; /* (dBm) */
209 /* Take the highest tx power from any valid chains */
210 if ((priv->cfg->valid_tx_ant & ANT_A) &&
211 (enhanced_txpower[element].chain_a_max > max_txpower_avg))
212 max_txpower_avg = enhanced_txpower[element].chain_a_max;
213 if ((priv->cfg->valid_tx_ant & ANT_B) &&
214 (enhanced_txpower[element].chain_b_max > max_txpower_avg))
215 max_txpower_avg = enhanced_txpower[element].chain_b_max;
216 if ((priv->cfg->valid_tx_ant & ANT_C) &&
217 (enhanced_txpower[element].chain_c_max > max_txpower_avg))
218 max_txpower_avg = enhanced_txpower[element].chain_c_max;
219 if (((priv->cfg->valid_tx_ant == ANT_AB) |
220 (priv->cfg->valid_tx_ant == ANT_BC) |
221 (priv->cfg->valid_tx_ant == ANT_AC)) &&
222 (enhanced_txpower[element].mimo2_max > max_txpower_avg))
223 max_txpower_avg = enhanced_txpower[element].mimo2_max;
224 if ((priv->cfg->valid_tx_ant == ANT_ABC) &&
225 (enhanced_txpower[element].mimo3_max > max_txpower_avg))
226 max_txpower_avg = enhanced_txpower[element].mimo3_max;
229 * max. tx power in EEPROM is in 1/2 dBm format
230 * convert from 1/2 dBm to dBm (round-up convert)
231 * but we also do not want to loss 1/2 dBm resolution which
232 * will impact performance
234 *max_txpower_in_half_dbm = max_txpower_avg;
235 return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1);
239 iwlcore_eeprom_enh_txp_read_element(struct iwl_priv *priv,
240 struct iwl_eeprom_enhanced_txpwr *txp,
244 bool is_ht40 = txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ;
245 enum ieee80211_band band;
247 band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ?
248 IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ;
250 for (ch_idx = 0; ch_idx < priv->channel_count; ch_idx++) {
251 struct iwl_channel_info *ch_info = &priv->channel_info[ch_idx];
253 /* update matching channel or from common data only */
254 if (txp->channel != 0 && ch_info->channel != txp->channel)
257 /* update matching band only */
258 if (band != ch_info->band)
261 if (ch_info->max_power_avg < max_txpower_avg && !is_ht40) {
262 ch_info->max_power_avg = max_txpower_avg;
263 ch_info->curr_txpow = max_txpower_avg;
264 ch_info->scan_power = max_txpower_avg;
267 if (is_ht40 && ch_info->ht40_max_power_avg < max_txpower_avg)
268 ch_info->ht40_max_power_avg = max_txpower_avg;
272 #define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
273 #define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
274 #define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
276 #define TXP_CHECK_AND_PRINT(x) ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) \
279 void iwlcore_eeprom_enhanced_txpower(struct iwl_priv *priv)
281 struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
284 s8 max_txp_avg, max_txp_avg_halfdbm;
286 BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
288 /* the length is in 16-bit words, but we want entries */
289 txp_len = (__le16 *) iwlagn_eeprom_query_addr(priv, EEPROM_TXP_SZ_OFFS);
290 entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
292 txp_array = (void *) iwlagn_eeprom_query_addr(priv, EEPROM_TXP_OFFS);
294 for (idx = 0; idx < entries; idx++) {
295 txp = &txp_array[idx];
296 /* skip invalid entries */
297 if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID))
300 IWL_DEBUG_EEPROM(priv, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n",
301 (txp->channel && (txp->flags &
302 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ?
303 "Common " : (txp->channel) ?
304 "Channel" : "Common",
306 TXP_CHECK_AND_PRINT(VALID),
307 TXP_CHECK_AND_PRINT(BAND_52G),
308 TXP_CHECK_AND_PRINT(OFDM),
309 TXP_CHECK_AND_PRINT(40MHZ),
310 TXP_CHECK_AND_PRINT(HT_AP),
311 TXP_CHECK_AND_PRINT(RES1),
312 TXP_CHECK_AND_PRINT(RES2),
313 TXP_CHECK_AND_PRINT(COMMON_TYPE),
315 IWL_DEBUG_EEPROM(priv, "\t\t chain_A: 0x%02x "
316 "chain_B: 0X%02x chain_C: 0X%02x\n",
317 txp->chain_a_max, txp->chain_b_max,
319 IWL_DEBUG_EEPROM(priv, "\t\t MIMO2: 0x%02x "
320 "MIMO3: 0x%02x High 20_on_40: 0x%02x "
321 "Low 20_on_40: 0x%02x\n",
322 txp->mimo2_max, txp->mimo3_max,
323 ((txp->delta_20_in_40 & 0xf0) >> 4),
324 (txp->delta_20_in_40 & 0x0f));
326 max_txp_avg = iwl_get_max_txpower_avg(priv, txp_array, idx,
327 &max_txp_avg_halfdbm);
330 * Update the user limit values values to the highest
331 * power supported by any channel
333 if (max_txp_avg > priv->tx_power_user_lmt)
334 priv->tx_power_user_lmt = max_txp_avg;
335 if (max_txp_avg_halfdbm > priv->tx_power_lmt_in_half_dbm)
336 priv->tx_power_lmt_in_half_dbm = max_txp_avg_halfdbm;
338 iwlcore_eeprom_enh_txp_read_element(priv, txp, max_txp_avg);