blob: 84e23844edf5528d143d9bf159b1dd0cc642cbd4 [file] [log] [blame]
Assaf Krauss34cf6ff2008-03-06 10:40:20 -08001/******************************************************************************
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 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08008 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
Assaf Krauss34cf6ff2008-03-06 10:40:20 -08009 *
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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080028 * Intel Linux Wireless <ilw@linux.intel.com>
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080029 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -080033 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080034 * 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090066#include <linux/slab.h>
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080067#include <linux/init.h>
68
69#include <net/mac80211.h>
70
Tomas Winkler5a36ba02008-04-24 11:55:37 -070071#include "iwl-commands.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070072#include "iwl-dev.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080073#include "iwl-core.h"
Tomas Winkler0a6857e2008-03-12 16:58:49 -070074#include "iwl-debug.h"
Wey-Yi Guy701cb092011-09-15 11:46:41 -070075#include "iwl-agn.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080076#include "iwl-eeprom.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070077#include "iwl-io.h"
Johannes Bergeae63b82012-03-06 13:31:06 -080078#include "iwl-prph.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080079
Assaf Kraussbf85ea42008-03-14 10:38:49 -070080/************************** EEPROM BANDS ****************************
81 *
82 * The iwl_eeprom_band definitions below provide the mapping from the
83 * EEPROM contents to the specific channel number supported for each
84 * band.
85 *
86 * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
87 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
88 * The specific geography and calibration information for that channel
89 * is contained in the eeprom map itself.
90 *
91 * During init, we copy the eeprom information and channel map
92 * information into priv->channel_info_24/52 and priv->channel_map_24/52
93 *
94 * channel_map_24/52 provides the index in the channel_info array for a
95 * given channel. We have to have two separate maps as there is channel
96 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
97 * band_2
98 *
99 * A value of 0xff stored in the channel_map indicates that the channel
100 * is not supported by the hardware at all.
101 *
102 * A value of 0xfe in the channel_map indicates that the channel is not
103 * valid for Tx with the current hardware. This means that
104 * while the system can tune and receive on a given channel, it may not
105 * be able to associate or transmit any frames on that
106 * channel. There is no corresponding channel information for that
107 * entry.
108 *
109 *********************************************************************/
110
111/* 2.4 GHz */
112const u8 iwl_eeprom_band_1[14] = {
113 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
114};
115
116/* 5.2 GHz bands */
117static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
118 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
119};
120
121static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
122 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
123};
124
125static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
126 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
127};
128
129static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
130 145, 149, 153, 157, 161, 165
131};
132
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700133static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700134 1, 2, 3, 4, 5, 6, 7
135};
136
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700137static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700138 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
139};
140
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800141/******************************************************************************
142 *
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700143 * generic NVM functions
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800144 *
145******************************************************************************/
146
Don Fry16b80b72011-04-20 15:25:14 -0700147/*
148 * The device's EEPROM semaphore prevents conflicts between driver and uCode
149 * when accessing the EEPROM; each access is a series of pulses to/from the
150 * EEPROM chip, not a single event, so even reads could conflict if they
151 * weren't arbitrated by the semaphore.
152 */
Emmanuel Grumbach90304742012-02-13 11:17:57 +0200153
154#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
155#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
156
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200157static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans)
Don Fry16b80b72011-04-20 15:25:14 -0700158{
159 u16 count;
160 int ret;
161
162 for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
163 /* Request semaphore */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200164 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
Don Fry16b80b72011-04-20 15:25:14 -0700165 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
166
167 /* See if we got it */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200168 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
Don Fry16b80b72011-04-20 15:25:14 -0700169 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
170 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
171 EEPROM_SEM_TIMEOUT);
172 if (ret >= 0) {
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200173 IWL_DEBUG_EEPROM(trans,
Don Fry16b80b72011-04-20 15:25:14 -0700174 "Acquired semaphore after %d tries.\n",
175 count+1);
176 return ret;
177 }
178 }
179
180 return ret;
181}
182
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200183static void iwl_eeprom_release_semaphore(struct iwl_trans *trans)
Don Fry16b80b72011-04-20 15:25:14 -0700184{
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200185 iwl_clear_bit(trans, CSR_HW_IF_CONFIG_REG,
Don Fry16b80b72011-04-20 15:25:14 -0700186 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
187
188}
189
Johannes Berg11483b52012-04-09 17:46:58 -0700190static int iwl_eeprom_verify_signature(struct iwl_priv *priv)
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800191{
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700192 u32 gp = iwl_read32(priv->trans, CSR_EEPROM_GP) &
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200193 CSR_EEPROM_GP_VALID_MSK;
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700194 int ret = 0;
195
Johannes Berg11483b52012-04-09 17:46:58 -0700196 IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700197 switch (gp) {
198 case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
Johannes Berg11483b52012-04-09 17:46:58 -0700199 if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
200 IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700201 gp);
202 ret = -ENOENT;
203 }
204 break;
205 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
206 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
Johannes Berg11483b52012-04-09 17:46:58 -0700207 if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
208 IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700209 ret = -ENOENT;
210 }
211 break;
212 case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
213 default:
Johannes Berg11483b52012-04-09 17:46:58 -0700214 IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700215 "EEPROM_GP=0x%08x\n",
Johannes Berg11483b52012-04-09 17:46:58 -0700216 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700217 ? "OTP" : "EEPROM", gp);
218 ret = -ENOENT;
219 break;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800220 }
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700221 return ret;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800222}
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800223
Johannes Berg11483b52012-04-09 17:46:58 -0700224u16 iwl_eeprom_query16(struct iwl_priv *priv, size_t offset)
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700225{
Johannes Berg11483b52012-04-09 17:46:58 -0700226 if (!priv->eeprom)
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700227 return 0;
Johannes Berg11483b52012-04-09 17:46:58 -0700228 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700229}
230
231int iwl_eeprom_check_version(struct iwl_priv *priv)
232{
233 u16 eeprom_ver;
234 u16 calib_ver;
235
Johannes Berg11483b52012-04-09 17:46:58 -0700236 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
237 calib_ver = iwl_eeprom_calib_version(priv);
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700238
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200239 if (eeprom_ver < priv->cfg->eeprom_ver ||
240 calib_ver < priv->cfg->eeprom_calib_ver)
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700241 goto err;
242
243 IWL_INFO(priv, "device EEPROM VER=0x%x, CALIB=0x%x\n",
244 eeprom_ver, calib_ver);
245
246 return 0;
247err:
248 IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x "
249 "CALIB=0x%x < 0x%x\n",
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200250 eeprom_ver, priv->cfg->eeprom_ver,
251 calib_ver, priv->cfg->eeprom_calib_ver);
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700252 return -EINVAL;
253
254}
255
Johannes Berg54708d82012-03-05 11:24:31 -0800256int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700257{
258 u16 radio_cfg;
259
Johannes Berg11483b52012-04-09 17:46:58 -0700260 priv->hw_params.sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP);
Johannes Berg9e295112012-04-09 17:46:55 -0700261 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE &&
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200262 !priv->cfg->ht_params) {
Johannes Berg54708d82012-03-05 11:24:31 -0800263 IWL_ERR(priv, "Invalid 11n configuration\n");
264 return -EINVAL;
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700265 }
Johannes Berg54708d82012-03-05 11:24:31 -0800266
Johannes Berg9e295112012-04-09 17:46:55 -0700267 if (!priv->hw_params.sku) {
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700268 IWL_ERR(priv, "Invalid device sku\n");
269 return -EINVAL;
270 }
271
Johannes Berg9e295112012-04-09 17:46:55 -0700272 IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku);
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700273
Johannes Berg11483b52012-04-09 17:46:58 -0700274 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
Johannes Berg7e79a392012-03-05 11:24:32 -0800275
Johannes Berg9e295112012-04-09 17:46:55 -0700276 priv->hw_params.valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
277 priv->hw_params.valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg);
Johannes Berg7e79a392012-03-05 11:24:32 -0800278
279 /* check overrides (some devices have wrong EEPROM) */
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200280 if (priv->cfg->valid_tx_ant)
281 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
282 if (priv->cfg->valid_rx_ant)
283 priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
Johannes Berg7e79a392012-03-05 11:24:32 -0800284
Johannes Berg9e295112012-04-09 17:46:55 -0700285 if (!priv->hw_params.valid_tx_ant || !priv->hw_params.valid_rx_ant) {
Johannes Berg7e79a392012-03-05 11:24:32 -0800286 IWL_ERR(priv, "Invalid chain (0x%X, 0x%X)\n",
Johannes Berg9e295112012-04-09 17:46:55 -0700287 priv->hw_params.valid_tx_ant,
288 priv->hw_params.valid_rx_ant);
Johannes Berg7e79a392012-03-05 11:24:32 -0800289 return -EINVAL;
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700290 }
Johannes Berg7e79a392012-03-05 11:24:32 -0800291
292 IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
Johannes Berg9e295112012-04-09 17:46:55 -0700293 priv->hw_params.valid_tx_ant, priv->hw_params.valid_rx_ant);
Johannes Berg7e79a392012-03-05 11:24:32 -0800294
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700295 return 0;
296}
297
Johannes Berg11483b52012-04-09 17:46:58 -0700298u16 iwl_eeprom_calib_version(struct iwl_priv *priv)
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700299{
Johannes Berg11483b52012-04-09 17:46:58 -0700300 struct iwl_eeprom_calib_hdr *hdr;
301
302 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
303 EEPROM_CALIB_ALL);
304 return hdr->version;
305}
306
307static u32 eeprom_indirect_address(struct iwl_priv *priv, u32 address)
308{
309 u16 offset = 0;
310
311 if ((address & INDIRECT_ADDRESS) == 0)
312 return address;
313
314 switch (address & INDIRECT_TYPE_MSK) {
315 case INDIRECT_HOST:
316 offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
317 break;
318 case INDIRECT_GENERAL:
319 offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
320 break;
321 case INDIRECT_REGULATORY:
322 offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
323 break;
324 case INDIRECT_TXP_LIMIT:
325 offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
326 break;
327 case INDIRECT_TXP_LIMIT_SIZE:
328 offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
329 break;
330 case INDIRECT_CALIBRATION:
331 offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
332 break;
333 case INDIRECT_PROCESS_ADJST:
334 offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
335 break;
336 case INDIRECT_OTHERS:
337 offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
338 break;
339 default:
340 IWL_ERR(priv, "illegal indirect type: 0x%X\n",
341 address & INDIRECT_TYPE_MSK);
342 break;
343 }
344
345 /* translate the offset from words to byte */
346 return (address & ADDRESS_MSK) + (offset << 1);
347}
348
349const u8 *iwl_eeprom_query_addr(struct iwl_priv *priv, size_t offset)
350{
351 u32 address = eeprom_indirect_address(priv, offset);
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200352 BUG_ON(address >= priv->cfg->base_params->eeprom_size);
Johannes Berg11483b52012-04-09 17:46:58 -0700353 return &priv->eeprom[address];
354}
355
356void iwl_eeprom_get_mac(struct iwl_priv *priv, u8 *mac)
357{
358 const u8 *addr = iwl_eeprom_query_addr(priv,
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700359 EEPROM_MAC_ADDRESS);
360 memcpy(mac, addr, ETH_ALEN);
361}
362
363/******************************************************************************
364 *
365 * OTP related functions
366 *
367******************************************************************************/
368
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200369static void iwl_set_otp_access(struct iwl_trans *trans,
370 enum iwl_access_mode mode)
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700371{
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200372 iwl_read32(trans, CSR_OTP_GP_REG);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700373
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700374 if (mode == IWL_OTP_ACCESS_ABSOLUTE)
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200375 iwl_clear_bit(trans, CSR_OTP_GP_REG,
Johannes Berg70817b52011-05-11 03:29:25 -0700376 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700377 else
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200378 iwl_set_bit(trans, CSR_OTP_GP_REG,
Johannes Berg70817b52011-05-11 03:29:25 -0700379 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700380}
381
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200382static int iwl_get_nvm_type(struct iwl_trans *trans, u32 hw_rev)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700383{
384 u32 otpgp;
385 int nvm_type;
386
387 /* OTP only valid for CP/PP and after */
Johannes Berge98a1302011-04-05 09:42:08 -0700388 switch (hw_rev & CSR_HW_REV_TYPE_MSK) {
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700389 case CSR_HW_REV_TYPE_NONE:
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200390 IWL_ERR(trans, "Unknown hardware type\n");
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700391 return -ENOENT;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700392 case CSR_HW_REV_TYPE_5300:
393 case CSR_HW_REV_TYPE_5350:
394 case CSR_HW_REV_TYPE_5100:
395 case CSR_HW_REV_TYPE_5150:
396 nvm_type = NVM_DEVICE_TYPE_EEPROM;
397 break;
398 default:
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200399 otpgp = iwl_read32(trans, CSR_OTP_GP_REG);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700400 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
401 nvm_type = NVM_DEVICE_TYPE_OTP;
402 else
403 nvm_type = NVM_DEVICE_TYPE_EEPROM;
404 break;
405 }
406 return nvm_type;
407}
408
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200409static int iwl_init_otp_access(struct iwl_trans *trans)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700410{
411 int ret;
412
413 /* Enable 40MHz radio clock */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200414 iwl_write32(trans, CSR_GP_CNTRL,
415 iwl_read32(trans, CSR_GP_CNTRL) |
Johannes Berg02a7fa02011-04-05 09:42:12 -0700416 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700417
418 /* wait for clock to be ready */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200419 ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700420 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
421 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
422 25000);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700423 if (ret < 0)
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200424 IWL_ERR(trans, "Time out access OTP\n");
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700425 else {
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200426 iwl_set_bits_prph(trans, APMG_PS_CTRL_REG,
Reinette Chatred77b0342009-05-22 14:37:55 -0700427 APMG_PS_CTRL_VAL_RESET_REQ);
428 udelay(5);
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200429 iwl_clear_bits_prph(trans, APMG_PS_CTRL_REG,
Reinette Chatred77b0342009-05-22 14:37:55 -0700430 APMG_PS_CTRL_VAL_RESET_REQ);
Wey-Yi Guy32004ee2009-10-16 14:25:56 -0700431
432 /*
433 * CSR auto clock gate disable bit -
434 * this is only applicable for HW with OTP shadow RAM
435 */
Emmanuel Grumbach035f7ff2012-03-26 08:57:01 -0700436 if (trans->cfg->base_params->shadow_ram_support)
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200437 iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG,
Wey-Yi Guy32004ee2009-10-16 14:25:56 -0700438 CSR_RESET_LINK_PWR_MGMT_DISABLED);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700439 }
440 return ret;
441}
442
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200443static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr,
444 __le16 *eeprom_data)
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700445{
446 int ret = 0;
447 u32 r;
448 u32 otpgp;
449
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200450 iwl_write32(trans, CSR_EEPROM_REG,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700451 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200452 ret = iwl_poll_bit(trans, CSR_EEPROM_REG,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700453 CSR_EEPROM_REG_READ_VALID_MSK,
454 CSR_EEPROM_REG_READ_VALID_MSK,
455 IWL_EEPROM_ACCESS_TIMEOUT);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700456 if (ret < 0) {
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200457 IWL_ERR(trans, "Time out reading OTP[%d]\n", addr);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700458 return ret;
459 }
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200460 r = iwl_read32(trans, CSR_EEPROM_REG);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700461 /* check for ECC errors: */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200462 otpgp = iwl_read32(trans, CSR_OTP_GP_REG);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700463 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
464 /* stop in this case */
465 /* set the uncorrectable OTP ECC bit for acknowledgement */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200466 iwl_set_bit(trans, CSR_OTP_GP_REG,
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700467 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200468 IWL_ERR(trans, "Uncorrectable OTP ECC error, abort OTP read\n");
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700469 return -EINVAL;
470 }
471 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
472 /* continue in this case */
473 /* set the correctable OTP ECC bit for acknowledgement */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200474 iwl_set_bit(trans, CSR_OTP_GP_REG,
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700475 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200476 IWL_ERR(trans, "Correctable OTP ECC error, continue read\n");
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700477 }
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800478 *eeprom_data = cpu_to_le16(r >> 16);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700479 return 0;
480}
481
482/*
483 * iwl_is_otp_empty: check for empty OTP
484 */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200485static bool iwl_is_otp_empty(struct iwl_trans *trans)
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700486{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800487 u16 next_link_addr = 0;
488 __le16 link_value;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700489 bool is_empty = false;
490
491 /* locate the beginning of OTP link list */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200492 if (!iwl_read_otp_word(trans, next_link_addr, &link_value)) {
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700493 if (!link_value) {
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200494 IWL_ERR(trans, "OTP is empty\n");
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700495 is_empty = true;
496 }
497 } else {
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200498 IWL_ERR(trans, "Unable to read first block of OTP list.\n");
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700499 is_empty = true;
500 }
501
502 return is_empty;
503}
504
505
506/*
507 * iwl_find_otp_image: find EEPROM image in OTP
508 * finding the OTP block that contains the EEPROM image.
509 * the last valid block on the link list (the block _before_ the last block)
510 * is the block we should read and used to configure the device.
511 * If all the available OTP blocks are full, the last block will be the block
512 * we should read and used to configure the device.
513 * only perform this operation if shadow RAM is disabled
514 */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200515static int iwl_find_otp_image(struct iwl_trans *trans,
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700516 u16 *validblockaddr)
517{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800518 u16 next_link_addr = 0, valid_addr;
519 __le16 link_value = 0;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700520 int usedblocks = 0;
521
522 /* set addressing mode to absolute to traverse the link list */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200523 iwl_set_otp_access(trans, IWL_OTP_ACCESS_ABSOLUTE);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700524
525 /* checking for empty OTP or error */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200526 if (iwl_is_otp_empty(trans))
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700527 return -EINVAL;
528
529 /*
530 * start traverse link list
531 * until reach the max number of OTP blocks
532 * different devices have different number of OTP blocks
533 */
534 do {
535 /* save current valid block address
536 * check for more block on the link list
537 */
538 valid_addr = next_link_addr;
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800539 next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200540 IWL_DEBUG_EEPROM(trans, "OTP blocks %d addr 0x%x\n",
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700541 usedblocks, next_link_addr);
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200542 if (iwl_read_otp_word(trans, next_link_addr, &link_value))
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700543 return -EINVAL;
544 if (!link_value) {
545 /*
Jay Sternberg2facba72009-10-02 13:43:55 -0700546 * reach the end of link list, return success and
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700547 * set address point to the starting address
548 * of the image
549 */
Jay Sternberg2facba72009-10-02 13:43:55 -0700550 *validblockaddr = valid_addr;
551 /* skip first 2 bytes (link list pointer) */
552 *validblockaddr += 2;
553 return 0;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700554 }
555 /* more in the link list, continue */
556 usedblocks++;
Emmanuel Grumbach035f7ff2012-03-26 08:57:01 -0700557 } while (usedblocks <= trans->cfg->base_params->max_ll_items);
Jay Sternberg2facba72009-10-02 13:43:55 -0700558
559 /* OTP has no valid blocks */
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200560 IWL_DEBUG_EEPROM(trans, "OTP has no valid blocks\n");
Jay Sternberg2facba72009-10-02 13:43:55 -0700561 return -EINVAL;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700562}
563
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700564/******************************************************************************
565 *
566 * Tx Power related functions
567 *
568******************************************************************************/
569/**
570 * iwl_get_max_txpower_avg - get the highest tx power from all chains.
571 * find the highest tx power from all chains for the channel
572 */
Johannes Berg706c4ff2012-03-05 11:24:33 -0800573static s8 iwl_get_max_txpower_avg(const struct iwl_cfg *cfg,
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700574 struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
575 int element, s8 *max_txpower_in_half_dbm)
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700576{
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700577 s8 max_txpower_avg = 0; /* (dBm) */
578
579 /* Take the highest tx power from any valid chains */
Don Fry1431b212011-11-10 06:55:26 -0800580 if ((cfg->valid_tx_ant & ANT_A) &&
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700581 (enhanced_txpower[element].chain_a_max > max_txpower_avg))
582 max_txpower_avg = enhanced_txpower[element].chain_a_max;
Don Fry1431b212011-11-10 06:55:26 -0800583 if ((cfg->valid_tx_ant & ANT_B) &&
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700584 (enhanced_txpower[element].chain_b_max > max_txpower_avg))
585 max_txpower_avg = enhanced_txpower[element].chain_b_max;
Don Fry1431b212011-11-10 06:55:26 -0800586 if ((cfg->valid_tx_ant & ANT_C) &&
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700587 (enhanced_txpower[element].chain_c_max > max_txpower_avg))
588 max_txpower_avg = enhanced_txpower[element].chain_c_max;
Don Fry1431b212011-11-10 06:55:26 -0800589 if (((cfg->valid_tx_ant == ANT_AB) |
590 (cfg->valid_tx_ant == ANT_BC) |
591 (cfg->valid_tx_ant == ANT_AC)) &&
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700592 (enhanced_txpower[element].mimo2_max > max_txpower_avg))
593 max_txpower_avg = enhanced_txpower[element].mimo2_max;
Don Fry1431b212011-11-10 06:55:26 -0800594 if ((cfg->valid_tx_ant == ANT_ABC) &&
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700595 (enhanced_txpower[element].mimo3_max > max_txpower_avg))
596 max_txpower_avg = enhanced_txpower[element].mimo3_max;
597
598 /*
599 * max. tx power in EEPROM is in 1/2 dBm format
600 * convert from 1/2 dBm to dBm (round-up convert)
601 * but we also do not want to loss 1/2 dBm resolution which
602 * will impact performance
603 */
604 *max_txpower_in_half_dbm = max_txpower_avg;
605 return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1);
606}
607
608static void
609iwl_eeprom_enh_txp_read_element(struct iwl_priv *priv,
610 struct iwl_eeprom_enhanced_txpwr *txp,
611 s8 max_txpower_avg)
612{
613 int ch_idx;
614 bool is_ht40 = txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ;
615 enum ieee80211_band band;
616
617 band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ?
618 IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ;
619
620 for (ch_idx = 0; ch_idx < priv->channel_count; ch_idx++) {
621 struct iwl_channel_info *ch_info = &priv->channel_info[ch_idx];
622
623 /* update matching channel or from common data only */
624 if (txp->channel != 0 && ch_info->channel != txp->channel)
625 continue;
626
627 /* update matching band only */
628 if (band != ch_info->band)
629 continue;
630
631 if (ch_info->max_power_avg < max_txpower_avg && !is_ht40) {
632 ch_info->max_power_avg = max_txpower_avg;
633 ch_info->curr_txpow = max_txpower_avg;
634 ch_info->scan_power = max_txpower_avg;
635 }
636
637 if (is_ht40 && ch_info->ht40_max_power_avg < max_txpower_avg)
638 ch_info->ht40_max_power_avg = max_txpower_avg;
639 }
640}
641
642#define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
643#define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
644#define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
645
646#define TXP_CHECK_AND_PRINT(x) ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) \
647 ? # x " " : "")
648
Johannes Berg51dc51d2012-03-07 09:52:20 -0800649static void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv)
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700650{
651 struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
652 int idx, entries;
653 __le16 *txp_len;
654 s8 max_txp_avg, max_txp_avg_halfdbm;
655
656 BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
657
658 /* the length is in 16-bit words, but we want entries */
Johannes Berg11483b52012-04-09 17:46:58 -0700659 txp_len = (__le16 *) iwl_eeprom_query_addr(priv, EEPROM_TXP_SZ_OFFS);
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700660 entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
661
Johannes Berg11483b52012-04-09 17:46:58 -0700662 txp_array = (void *) iwl_eeprom_query_addr(priv, EEPROM_TXP_OFFS);
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700663
664 for (idx = 0; idx < entries; idx++) {
665 txp = &txp_array[idx];
666 /* skip invalid entries */
667 if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID))
668 continue;
669
670 IWL_DEBUG_EEPROM(priv, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n",
671 (txp->channel && (txp->flags &
672 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ?
673 "Common " : (txp->channel) ?
674 "Channel" : "Common",
675 (txp->channel),
676 TXP_CHECK_AND_PRINT(VALID),
677 TXP_CHECK_AND_PRINT(BAND_52G),
678 TXP_CHECK_AND_PRINT(OFDM),
679 TXP_CHECK_AND_PRINT(40MHZ),
680 TXP_CHECK_AND_PRINT(HT_AP),
681 TXP_CHECK_AND_PRINT(RES1),
682 TXP_CHECK_AND_PRINT(RES2),
683 TXP_CHECK_AND_PRINT(COMMON_TYPE),
684 txp->flags);
685 IWL_DEBUG_EEPROM(priv, "\t\t chain_A: 0x%02x "
686 "chain_B: 0X%02x chain_C: 0X%02x\n",
687 txp->chain_a_max, txp->chain_b_max,
688 txp->chain_c_max);
689 IWL_DEBUG_EEPROM(priv, "\t\t MIMO2: 0x%02x "
690 "MIMO3: 0x%02x High 20_on_40: 0x%02x "
691 "Low 20_on_40: 0x%02x\n",
692 txp->mimo2_max, txp->mimo3_max,
693 ((txp->delta_20_in_40 & 0xf0) >> 4),
694 (txp->delta_20_in_40 & 0x0f));
695
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200696 max_txp_avg = iwl_get_max_txpower_avg(priv->cfg, txp_array, idx,
Wey-Yi Guy701cb092011-09-15 11:46:41 -0700697 &max_txp_avg_halfdbm);
698
699 /*
700 * Update the user limit values values to the highest
701 * power supported by any channel
702 */
703 if (max_txp_avg > priv->tx_power_user_lmt)
704 priv->tx_power_user_lmt = max_txp_avg;
705 if (max_txp_avg_halfdbm > priv->tx_power_lmt_in_half_dbm)
706 priv->tx_power_lmt_in_half_dbm = max_txp_avg_halfdbm;
707
708 iwl_eeprom_enh_txp_read_element(priv, txp, max_txp_avg);
709 }
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700710}
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700711
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800712/**
713 * iwl_eeprom_init - read EEPROM contents
714 *
Johannes Berg11483b52012-04-09 17:46:58 -0700715 * Load the EEPROM contents from adapter into priv->eeprom
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800716 *
717 * NOTE: This routine uses the non-debug IO access functions.
718 */
Johannes Berg11483b52012-04-09 17:46:58 -0700719int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev)
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800720{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800721 __le16 *e;
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700722 u32 gp = iwl_read32(priv->trans, CSR_EEPROM_GP);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700723 int sz;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800724 int ret;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800725 u16 addr;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700726 u16 validblockaddr = 0;
727 u16 cache_addr = 0;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700728
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700729 priv->nvm_device_type = iwl_get_nvm_type(priv->trans, hw_rev);
Johannes Berg11483b52012-04-09 17:46:58 -0700730 if (priv->nvm_device_type == -ENOENT)
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700731 return -ENOENT;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700732 /* allocate eeprom */
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200733 sz = priv->cfg->base_params->eeprom_size;
Johannes Berg11483b52012-04-09 17:46:58 -0700734 IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
735 priv->eeprom = kzalloc(sz, GFP_KERNEL);
736 if (!priv->eeprom) {
Tomas Winkler073d3f52008-04-21 15:41:52 -0700737 ret = -ENOMEM;
738 goto alloc_err;
739 }
Johannes Berg11483b52012-04-09 17:46:58 -0700740 e = (__le16 *)priv->eeprom;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800741
Johannes Berg11483b52012-04-09 17:46:58 -0700742 ret = iwl_eeprom_verify_signature(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700743 if (ret < 0) {
Johannes Berg11483b52012-04-09 17:46:58 -0700744 IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700745 ret = -ENOENT;
746 goto err;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800747 }
748
749 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700750 ret = iwl_eeprom_acquire_semaphore(priv->trans);
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800751 if (ret < 0) {
Johannes Berg11483b52012-04-09 17:46:58 -0700752 IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -0700753 ret = -ENOENT;
754 goto err;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800755 }
Ben Cahill88521362009-10-30 14:36:06 -0700756
Johannes Berg11483b52012-04-09 17:46:58 -0700757 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
Ben Cahill88521362009-10-30 14:36:06 -0700758
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700759 ret = iwl_init_otp_access(priv->trans);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700760 if (ret) {
Johannes Berg11483b52012-04-09 17:46:58 -0700761 IWL_ERR(priv, "Failed to initialize OTP access.\n");
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700762 ret = -ENOENT;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700763 goto done;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800764 }
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700765 iwl_write32(priv->trans, CSR_EEPROM_GP,
766 iwl_read32(priv->trans, CSR_EEPROM_GP) &
Johannes Berg02a7fa02011-04-05 09:42:12 -0700767 ~CSR_EEPROM_GP_IF_OWNER_MSK);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700768
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700769 iwl_set_bit(priv->trans, CSR_OTP_GP_REG,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700770 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
771 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700772 /* traversing the linked list if no shadow ram supported */
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200773 if (!priv->cfg->base_params->shadow_ram_support) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700774 if (iwl_find_otp_image(priv->trans, &validblockaddr)) {
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700775 ret = -ENOENT;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700776 goto done;
777 }
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700778 }
779 for (addr = validblockaddr; addr < validblockaddr + sz;
780 addr += sizeof(u16)) {
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800781 __le16 eeprom_data;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700782
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700783 ret = iwl_read_otp_word(priv->trans, addr,
Johannes Berg11483b52012-04-09 17:46:58 -0700784 &eeprom_data);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700785 if (ret)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700786 goto done;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700787 e[cache_addr / 2] = eeprom_data;
788 cache_addr += sizeof(u16);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700789 }
790 } else {
791 /* eeprom is an array of 16bit values */
792 for (addr = 0; addr < sz; addr += sizeof(u16)) {
793 u32 r;
794
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700795 iwl_write32(priv->trans, CSR_EEPROM_REG,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700796 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700797
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700798 ret = iwl_poll_bit(priv->trans, CSR_EEPROM_REG,
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700799 CSR_EEPROM_REG_READ_VALID_MSK,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700800 CSR_EEPROM_REG_READ_VALID_MSK,
801 IWL_EEPROM_ACCESS_TIMEOUT);
802 if (ret < 0) {
Johannes Berg11483b52012-04-09 17:46:58 -0700803 IWL_ERR(priv,
Emmanuel Grumbachca77d532012-02-13 11:24:47 +0200804 "Time out reading EEPROM[%d]\n", addr);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700805 goto done;
806 }
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700807 r = iwl_read32(priv->trans, CSR_EEPROM_REG);
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800808 e[addr / 2] = cpu_to_le16(r >> 16);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700809 }
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800810 }
Johannes Bergd1358f62010-04-28 12:09:15 -0700811
Johannes Berg11483b52012-04-09 17:46:58 -0700812 IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
813 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Johannes Bergd1358f62010-04-28 12:09:15 -0700814 ? "OTP" : "EEPROM",
Johannes Berg11483b52012-04-09 17:46:58 -0700815 iwl_eeprom_query16(priv, EEPROM_VERSION));
Johannes Bergd1358f62010-04-28 12:09:15 -0700816
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800817 ret = 0;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800818done:
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700819 iwl_eeprom_release_semaphore(priv->trans);
Johannes Bergd1358f62010-04-28 12:09:15 -0700820
Tomas Winkler073d3f52008-04-21 15:41:52 -0700821err:
822 if (ret)
Johannes Berg11483b52012-04-09 17:46:58 -0700823 iwl_eeprom_free(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700824alloc_err:
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800825 return ret;
826}
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800827
Johannes Berg11483b52012-04-09 17:46:58 -0700828void iwl_eeprom_free(struct iwl_priv *priv)
Tomas Winkler073d3f52008-04-21 15:41:52 -0700829{
Johannes Berg11483b52012-04-09 17:46:58 -0700830 kfree(priv->eeprom);
831 priv->eeprom = NULL;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700832}
Tomas Winkler073d3f52008-04-21 15:41:52 -0700833
Johannes Berg11483b52012-04-09 17:46:58 -0700834static void iwl_init_band_reference(struct iwl_priv *priv,
Tomas Winkler073d3f52008-04-21 15:41:52 -0700835 int eep_band, int *eeprom_ch_count,
836 const struct iwl_eeprom_channel **eeprom_ch_info,
837 const u8 **eeprom_ch_index)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700838{
Johannes Berge9676692012-04-10 14:10:28 -0700839 u32 offset = priv->lib->
Tomas Winkler073d3f52008-04-21 15:41:52 -0700840 eeprom_ops.regulatory_bands[eep_band - 1];
841 switch (eep_band) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700842 case 1: /* 2.4GHz band */
843 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700844 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700845 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700846 *eeprom_ch_index = iwl_eeprom_band_1;
847 break;
848 case 2: /* 4.9GHz band */
849 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700850 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700851 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700852 *eeprom_ch_index = iwl_eeprom_band_2;
853 break;
854 case 3: /* 5.2GHz band */
855 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700856 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700857 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700858 *eeprom_ch_index = iwl_eeprom_band_3;
859 break;
860 case 4: /* 5.5GHz band */
861 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700862 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700863 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700864 *eeprom_ch_index = iwl_eeprom_band_4;
865 break;
866 case 5: /* 5.7GHz band */
867 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700868 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700869 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700870 *eeprom_ch_index = iwl_eeprom_band_5;
871 break;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700872 case 6: /* 2.4GHz ht40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700873 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700874 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700875 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700876 *eeprom_ch_index = iwl_eeprom_band_6;
877 break;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700878 case 7: /* 5 GHz ht40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700879 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700880 *eeprom_ch_info = (struct iwl_eeprom_channel *)
Johannes Berg11483b52012-04-09 17:46:58 -0700881 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700882 *eeprom_ch_index = iwl_eeprom_band_7;
883 break;
884 default:
885 BUG();
886 return;
887 }
888}
889
890#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
891 ? # x " " : "")
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700892/**
Zhu Yi3b247162009-08-13 13:30:53 -0700893 * iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700894 *
895 * Does not set up a command, or touch hardware.
896 */
Zhu Yi3b247162009-08-13 13:30:53 -0700897static int iwl_mod_ht40_chan_info(struct iwl_priv *priv,
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700898 enum ieee80211_band band, u16 channel,
Tomas Winkler073d3f52008-04-21 15:41:52 -0700899 const struct iwl_eeprom_channel *eeprom_ch,
Zhu Yi3b247162009-08-13 13:30:53 -0700900 u8 clear_ht40_extension_channel)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700901{
902 struct iwl_channel_info *ch_info;
903
904 ch_info = (struct iwl_channel_info *)
Assaf Krauss8622e702008-03-21 13:53:43 -0700905 iwl_get_channel_info(priv, band, channel);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700906
907 if (!is_channel_valid(ch_info))
908 return -1;
909
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800910 IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
Tomas Winkler630fe9b2008-06-12 09:47:08 +0800911 " Ad-Hoc %ssupported\n",
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700912 ch_info->channel,
913 is_channel_a_band(ch_info) ?
914 "5.2" : "2.4",
915 CHECK_AND_PRINT(IBSS),
916 CHECK_AND_PRINT(ACTIVE),
917 CHECK_AND_PRINT(RADAR),
918 CHECK_AND_PRINT(WIDE),
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700919 CHECK_AND_PRINT(DFS),
920 eeprom_ch->flags,
921 eeprom_ch->max_power_avg,
922 ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
923 && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
924 "" : "not ");
925
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700926 ch_info->ht40_eeprom = *eeprom_ch;
927 ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700928 ch_info->ht40_flags = eeprom_ch->flags;
Reinette Chatre6c3069b2009-12-14 14:12:13 -0800929 if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
930 ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700931
932 return 0;
933}
934
935#define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
936 ? # x " " : "")
937
938/**
939 * iwl_init_channel_map - Set up driver's info for all possible channels
940 */
941int iwl_init_channel_map(struct iwl_priv *priv)
942{
943 int eeprom_ch_count = 0;
944 const u8 *eeprom_ch_index = NULL;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700945 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700946 int band, ch;
947 struct iwl_channel_info *ch_info;
948
949 if (priv->channel_count) {
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800950 IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700951 return 0;
952 }
953
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800954 IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700955
956 priv->channel_count =
957 ARRAY_SIZE(iwl_eeprom_band_1) +
958 ARRAY_SIZE(iwl_eeprom_band_2) +
959 ARRAY_SIZE(iwl_eeprom_band_3) +
960 ARRAY_SIZE(iwl_eeprom_band_4) +
961 ARRAY_SIZE(iwl_eeprom_band_5);
962
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800963 IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
964 priv->channel_count);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700965
Emmanuel Grumbach7f90dce2011-09-22 15:14:53 -0700966 priv->channel_info = kcalloc(priv->channel_count,
967 sizeof(struct iwl_channel_info),
968 GFP_KERNEL);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700969 if (!priv->channel_info) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800970 IWL_ERR(priv, "Could not allocate channel_info\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700971 priv->channel_count = 0;
972 return -ENOMEM;
973 }
974
975 ch_info = priv->channel_info;
976
977 /* Loop through the 5 EEPROM bands adding them in order to the
978 * channel map we maintain (that contains additional information than
979 * what just in the EEPROM) */
980 for (band = 1; band <= 5; band++) {
981
982 iwl_init_band_reference(priv, band, &eeprom_ch_count,
983 &eeprom_ch_info, &eeprom_ch_index);
984
985 /* Loop through each band adding each of the channels */
986 for (ch = 0; ch < eeprom_ch_count; ch++) {
987 ch_info->channel = eeprom_ch_index[ch];
988 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
989 IEEE80211_BAND_5GHZ;
990
991 /* permanently store EEPROM's channel regulatory flags
992 * and max power in channel info database. */
993 ch_info->eeprom = eeprom_ch_info[ch];
994
995 /* Copy the run-time flags so they are there even on
996 * invalid channels */
997 ch_info->flags = eeprom_ch_info[ch].flags;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700998 /* First write that ht40 is not enabled, and then enable
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800999 * one by one */
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001000 ch_info->ht40_extension_channel =
Zhu Yi3b247162009-08-13 13:30:53 -07001001 IEEE80211_CHAN_NO_HT40;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001002
1003 if (!(is_channel_valid(ch_info))) {
Wey-Yi Guyd058ff82010-12-03 10:33:35 -08001004 IWL_DEBUG_EEPROM(priv,
1005 "Ch. %d Flags %x [%sGHz] - "
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001006 "No traffic\n",
1007 ch_info->channel,
1008 ch_info->flags,
1009 is_channel_a_band(ch_info) ?
1010 "5.2" : "2.4");
1011 ch_info++;
1012 continue;
1013 }
1014
1015 /* Initialize regulatory-based run-time data */
1016 ch_info->max_power_avg = ch_info->curr_txpow =
1017 eeprom_ch_info[ch].max_power_avg;
1018 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
1019 ch_info->min_power = 0;
1020
Wey-Yi Guyd058ff82010-12-03 10:33:35 -08001021 IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] "
1022 "%s%s%s%s%s%s(0x%02x %ddBm):"
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001023 " Ad-Hoc %ssupported\n",
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001024 ch_info->channel,
1025 is_channel_a_band(ch_info) ?
1026 "5.2" : "2.4",
1027 CHECK_AND_PRINT_I(VALID),
1028 CHECK_AND_PRINT_I(IBSS),
1029 CHECK_AND_PRINT_I(ACTIVE),
1030 CHECK_AND_PRINT_I(RADAR),
1031 CHECK_AND_PRINT_I(WIDE),
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001032 CHECK_AND_PRINT_I(DFS),
1033 eeprom_ch_info[ch].flags,
1034 eeprom_ch_info[ch].max_power_avg,
1035 ((eeprom_ch_info[ch].
1036 flags & EEPROM_CHANNEL_IBSS)
1037 && !(eeprom_ch_info[ch].
1038 flags & EEPROM_CHANNEL_RADAR))
1039 ? "" : "not ");
1040
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001041 ch_info++;
1042 }
1043 }
1044
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001045 /* Check if we do have HT40 channels */
Johannes Berge9676692012-04-10 14:10:28 -07001046 if (priv->lib->eeprom_ops.regulatory_bands[5] ==
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001047 EEPROM_REGULATORY_BAND_NO_HT40 &&
Johannes Berge9676692012-04-10 14:10:28 -07001048 priv->lib->eeprom_ops.regulatory_bands[6] ==
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001049 EEPROM_REGULATORY_BAND_NO_HT40)
Samuel Ortize6148912009-01-23 13:45:15 -08001050 return 0;
1051
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07001052 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001053 for (band = 6; band <= 7; band++) {
1054 enum ieee80211_band ieeeband;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001055
1056 iwl_init_band_reference(priv, band, &eeprom_ch_count,
1057 &eeprom_ch_info, &eeprom_ch_index);
1058
1059 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
1060 ieeeband =
1061 (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
1062
1063 /* Loop through each band adding each of the channels */
1064 for (ch = 0; ch < eeprom_ch_count; ch++) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001065 /* Set up driver's info for lower half */
Zhu Yi3b247162009-08-13 13:30:53 -07001066 iwl_mod_ht40_chan_info(priv, ieeeband,
Tomas Winklerda6833c2008-05-15 13:54:15 +08001067 eeprom_ch_index[ch],
Zhu Yi3b247162009-08-13 13:30:53 -07001068 &eeprom_ch_info[ch],
1069 IEEE80211_CHAN_NO_HT40PLUS);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001070
1071 /* Set up driver's info for upper half */
Zhu Yi3b247162009-08-13 13:30:53 -07001072 iwl_mod_ht40_chan_info(priv, ieeeband,
1073 eeprom_ch_index[ch] + 4,
1074 &eeprom_ch_info[ch],
1075 IEEE80211_CHAN_NO_HT40MINUS);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001076 }
1077 }
1078
Wey-Yi Guyab9fd1b2009-08-21 13:34:23 -07001079 /* for newer device (6000 series and up)
1080 * EEPROM contain enhanced tx power information
1081 * driver need to process addition information
1082 * to determine the max channel tx power limits
1083 */
Johannes Berge9676692012-04-10 14:10:28 -07001084 if (priv->lib->eeprom_ops.enhanced_txpower)
Johannes Berg51dc51d2012-03-07 09:52:20 -08001085 iwl_eeprom_enhanced_txpower(priv);
Wey-Yi Guyab9fd1b2009-08-21 13:34:23 -07001086
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001087 return 0;
1088}
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001089
1090/*
Tomas Winklerda6833c2008-05-15 13:54:15 +08001091 * iwl_free_channel_map - undo allocations in iwl_init_channel_map
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001092 */
1093void iwl_free_channel_map(struct iwl_priv *priv)
1094{
1095 kfree(priv->channel_info);
1096 priv->channel_count = 0;
1097}
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001098
1099/**
1100 * iwl_get_channel_info - Find driver's private channel info
1101 *
1102 * Based on band and channel number.
1103 */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08001104const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
1105 enum ieee80211_band band, u16 channel)
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001106{
1107 int i;
1108
1109 switch (band) {
1110 case IEEE80211_BAND_5GHZ:
1111 for (i = 14; i < priv->channel_count; i++) {
1112 if (priv->channel_info[i].channel == channel)
1113 return &priv->channel_info[i];
1114 }
1115 break;
1116 case IEEE80211_BAND_2GHZ:
1117 if (channel >= 1 && channel <= 14)
1118 return &priv->channel_info[channel - 1];
1119 break;
1120 default:
1121 BUG();
1122 }
1123
1124 return NULL;
1125}
Wey-Yi Guy86cb3b42011-06-14 15:23:39 -07001126
1127void iwl_rf_config(struct iwl_priv *priv)
1128{
1129 u16 radio_cfg;
1130
Johannes Berg11483b52012-04-09 17:46:58 -07001131 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
Wey-Yi Guy86cb3b42011-06-14 15:23:39 -07001132
1133 /* write radio config values to register */
1134 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001135 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
Wey-Yi Guy86cb3b42011-06-14 15:23:39 -07001136 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
1137 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
1138 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
1139 IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
1140 EEPROM_RF_CFG_TYPE_MSK(radio_cfg),
1141 EEPROM_RF_CFG_STEP_MSK(radio_cfg),
1142 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
1143 } else
1144 WARN_ON(1);
1145
1146 /* set CSR_HW_CONFIG_REG for uCode use */
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001147 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
Wey-Yi Guy86cb3b42011-06-14 15:23:39 -07001148 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
1149 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
1150}