blob: 358cfd7e5af190bf8c17cf059329d73d279e71a6 [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 *
Reinette Chatre1f447802010-01-15 13:43:41 -08008 * Copyright(c) 2008 - 2010 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 *
Reinette Chatre1f447802010-01-15 13:43:41 -080033 * Copyright(c) 2005 - 2010 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"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080075#include "iwl-eeprom.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070076#include "iwl-io.h"
Assaf Krauss34cf6ff2008-03-06 10:40:20 -080077
Assaf Kraussbf85ea42008-03-14 10:38:49 -070078/************************** EEPROM BANDS ****************************
79 *
80 * The iwl_eeprom_band definitions below provide the mapping from the
81 * EEPROM contents to the specific channel number supported for each
82 * band.
83 *
84 * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
85 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
86 * The specific geography and calibration information for that channel
87 * is contained in the eeprom map itself.
88 *
89 * During init, we copy the eeprom information and channel map
90 * information into priv->channel_info_24/52 and priv->channel_map_24/52
91 *
92 * channel_map_24/52 provides the index in the channel_info array for a
93 * given channel. We have to have two separate maps as there is channel
94 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
95 * band_2
96 *
97 * A value of 0xff stored in the channel_map indicates that the channel
98 * is not supported by the hardware at all.
99 *
100 * A value of 0xfe in the channel_map indicates that the channel is not
101 * valid for Tx with the current hardware. This means that
102 * while the system can tune and receive on a given channel, it may not
103 * be able to associate or transmit any frames on that
104 * channel. There is no corresponding channel information for that
105 * entry.
106 *
107 *********************************************************************/
108
109/* 2.4 GHz */
110const u8 iwl_eeprom_band_1[14] = {
111 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
112};
113
114/* 5.2 GHz bands */
115static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
116 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
117};
118
119static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
120 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
121};
122
123static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
124 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
125};
126
127static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
128 145, 149, 153, 157, 161, 165
129};
130
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700131static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700132 1, 2, 3, 4, 5, 6, 7
133};
134
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700135static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700136 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
137};
138
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800139/******************************************************************************
140 *
141 * EEPROM related functions
142 *
143******************************************************************************/
144
Johannes Bergd3f5ba92010-09-22 18:02:00 +0200145static int iwl_eeprom_verify_signature(struct iwl_priv *priv)
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800146{
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700147 u32 gp = iwl_read32(priv, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
148 int ret = 0;
149
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800150 IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700151 switch (gp) {
152 case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
153 if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
154 IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
155 gp);
156 ret = -ENOENT;
157 }
158 break;
159 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
160 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
161 if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
162 IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
163 ret = -ENOENT;
164 }
165 break;
166 case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
167 default:
168 IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
169 "EEPROM_GP=0x%08x\n",
170 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
171 ? "OTP" : "EEPROM", gp);
172 ret = -ENOENT;
173 break;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800174 }
Wey-Yi Guyf41bb892009-10-02 13:44:06 -0700175 return ret;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800176}
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800177
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700178static void iwl_set_otp_access(struct iwl_priv *priv, enum iwl_access_mode mode)
179{
180 u32 otpgp;
181
182 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
183 if (mode == IWL_OTP_ACCESS_ABSOLUTE)
184 iwl_clear_bit(priv, CSR_OTP_GP_REG,
185 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
186 else
187 iwl_set_bit(priv, CSR_OTP_GP_REG,
188 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
189}
190
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700191static int iwlcore_get_nvm_type(struct iwl_priv *priv)
192{
193 u32 otpgp;
194 int nvm_type;
195
196 /* OTP only valid for CP/PP and after */
197 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700198 case CSR_HW_REV_TYPE_NONE:
199 IWL_ERR(priv, "Unknown hardware type\n");
200 return -ENOENT;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700201 case CSR_HW_REV_TYPE_3945:
202 case CSR_HW_REV_TYPE_4965:
203 case CSR_HW_REV_TYPE_5300:
204 case CSR_HW_REV_TYPE_5350:
205 case CSR_HW_REV_TYPE_5100:
206 case CSR_HW_REV_TYPE_5150:
207 nvm_type = NVM_DEVICE_TYPE_EEPROM;
208 break;
209 default:
210 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
211 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
212 nvm_type = NVM_DEVICE_TYPE_OTP;
213 else
214 nvm_type = NVM_DEVICE_TYPE_EEPROM;
215 break;
216 }
217 return nvm_type;
218}
219
Tomas Winkler073d3f52008-04-21 15:41:52 -0700220const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
221{
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700222 BUG_ON(offset >= priv->cfg->base_params->eeprom_size);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700223 return &priv->eeprom[offset];
224}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800225EXPORT_SYMBOL(iwlcore_eeprom_query_addr);
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800226
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700227static int iwl_init_otp_access(struct iwl_priv *priv)
228{
229 int ret;
230
231 /* Enable 40MHz radio clock */
232 _iwl_write32(priv, CSR_GP_CNTRL,
233 _iwl_read32(priv, CSR_GP_CNTRL) |
234 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
235
236 /* wait for clock to be ready */
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700237 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
238 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700239 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
240 25000);
241 if (ret < 0)
242 IWL_ERR(priv, "Time out access OTP\n");
243 else {
Reinette Chatred77b0342009-05-22 14:37:55 -0700244 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
245 APMG_PS_CTRL_VAL_RESET_REQ);
246 udelay(5);
247 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
248 APMG_PS_CTRL_VAL_RESET_REQ);
Wey-Yi Guy32004ee2009-10-16 14:25:56 -0700249
250 /*
251 * CSR auto clock gate disable bit -
252 * this is only applicable for HW with OTP shadow RAM
253 */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700254 if (priv->cfg->base_params->shadow_ram_support)
Wey-Yi Guy32004ee2009-10-16 14:25:56 -0700255 iwl_set_bit(priv, CSR_DBG_LINK_PWR_MGMT_REG,
256 CSR_RESET_LINK_PWR_MGMT_DISABLED);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700257 }
258 return ret;
259}
260
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800261static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, __le16 *eeprom_data)
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700262{
263 int ret = 0;
264 u32 r;
265 u32 otpgp;
266
267 _iwl_write32(priv, CSR_EEPROM_REG,
268 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700269 ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
270 CSR_EEPROM_REG_READ_VALID_MSK,
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700271 CSR_EEPROM_REG_READ_VALID_MSK,
272 IWL_EEPROM_ACCESS_TIMEOUT);
273 if (ret < 0) {
274 IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
275 return ret;
276 }
277 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
278 /* check for ECC errors: */
279 otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
280 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
281 /* stop in this case */
282 /* set the uncorrectable OTP ECC bit for acknowledgement */
283 iwl_set_bit(priv, CSR_OTP_GP_REG,
284 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
285 IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
286 return -EINVAL;
287 }
288 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
289 /* continue in this case */
290 /* set the correctable OTP ECC bit for acknowledgement */
291 iwl_set_bit(priv, CSR_OTP_GP_REG,
292 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
293 IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
294 }
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800295 *eeprom_data = cpu_to_le16(r >> 16);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700296 return 0;
297}
298
299/*
300 * iwl_is_otp_empty: check for empty OTP
301 */
302static bool iwl_is_otp_empty(struct iwl_priv *priv)
303{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800304 u16 next_link_addr = 0;
305 __le16 link_value;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700306 bool is_empty = false;
307
308 /* locate the beginning of OTP link list */
309 if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
310 if (!link_value) {
311 IWL_ERR(priv, "OTP is empty\n");
312 is_empty = true;
313 }
314 } else {
315 IWL_ERR(priv, "Unable to read first block of OTP list.\n");
316 is_empty = true;
317 }
318
319 return is_empty;
320}
321
322
323/*
324 * iwl_find_otp_image: find EEPROM image in OTP
325 * finding the OTP block that contains the EEPROM image.
326 * the last valid block on the link list (the block _before_ the last block)
327 * is the block we should read and used to configure the device.
328 * If all the available OTP blocks are full, the last block will be the block
329 * we should read and used to configure the device.
330 * only perform this operation if shadow RAM is disabled
331 */
332static int iwl_find_otp_image(struct iwl_priv *priv,
333 u16 *validblockaddr)
334{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800335 u16 next_link_addr = 0, valid_addr;
336 __le16 link_value = 0;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700337 int usedblocks = 0;
338
339 /* set addressing mode to absolute to traverse the link list */
340 iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
341
342 /* checking for empty OTP or error */
343 if (iwl_is_otp_empty(priv))
344 return -EINVAL;
345
346 /*
347 * start traverse link list
348 * until reach the max number of OTP blocks
349 * different devices have different number of OTP blocks
350 */
351 do {
352 /* save current valid block address
353 * check for more block on the link list
354 */
355 valid_addr = next_link_addr;
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800356 next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800357 IWL_DEBUG_EEPROM(priv, "OTP blocks %d addr 0x%x\n",
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700358 usedblocks, next_link_addr);
359 if (iwl_read_otp_word(priv, next_link_addr, &link_value))
360 return -EINVAL;
361 if (!link_value) {
362 /*
Jay Sternberg2facba72009-10-02 13:43:55 -0700363 * reach the end of link list, return success and
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700364 * set address point to the starting address
365 * of the image
366 */
Jay Sternberg2facba72009-10-02 13:43:55 -0700367 *validblockaddr = valid_addr;
368 /* skip first 2 bytes (link list pointer) */
369 *validblockaddr += 2;
370 return 0;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700371 }
372 /* more in the link list, continue */
373 usedblocks++;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700374 } while (usedblocks <= priv->cfg->base_params->max_ll_items);
Jay Sternberg2facba72009-10-02 13:43:55 -0700375
376 /* OTP has no valid blocks */
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800377 IWL_DEBUG_EEPROM(priv, "OTP has no valid blocks\n");
Jay Sternberg2facba72009-10-02 13:43:55 -0700378 return -EINVAL;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700379}
380
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700381const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
382{
383 return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
384}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800385EXPORT_SYMBOL(iwl_eeprom_query_addr);
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700386
387u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
388{
389 if (!priv->eeprom)
390 return 0;
391 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
392}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800393EXPORT_SYMBOL(iwl_eeprom_query16);
Wey-Yi Guy3be63ff2010-10-08 16:05:19 -0700394
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800395/**
396 * iwl_eeprom_init - read EEPROM contents
397 *
398 * Load the EEPROM contents from adapter into priv->eeprom
399 *
400 * NOTE: This routine uses the non-debug IO access functions.
401 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700402int iwl_eeprom_init(struct iwl_priv *priv)
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800403{
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800404 __le16 *e;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700405 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700406 int sz;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800407 int ret;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800408 u16 addr;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700409 u16 validblockaddr = 0;
410 u16 cache_addr = 0;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700411
412 priv->nvm_device_type = iwlcore_get_nvm_type(priv);
Wey-Yi Guyb23a0522009-07-17 09:30:21 -0700413 if (priv->nvm_device_type == -ENOENT)
414 return -ENOENT;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700415 /* allocate eeprom */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700416 sz = priv->cfg->base_params->eeprom_size;
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800417 IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700418 priv->eeprom = kzalloc(sz, GFP_KERNEL);
419 if (!priv->eeprom) {
420 ret = -ENOMEM;
421 goto alloc_err;
422 }
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800423 e = (__le16 *)priv->eeprom;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800424
Reinette Chatref8701fe2009-12-10 14:37:22 -0800425 priv->cfg->ops->lib->apm_ops.init(priv);
Reinette Chatree43ab942009-11-13 11:56:32 -0800426
Johannes Bergd3f5ba92010-09-22 18:02:00 +0200427 ret = iwl_eeprom_verify_signature(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700428 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800429 IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700430 ret = -ENOENT;
431 goto err;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800432 }
433
434 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
435 ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
436 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800437 IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -0700438 ret = -ENOENT;
439 goto err;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800440 }
Ben Cahill88521362009-10-30 14:36:06 -0700441
Reinette Chatree43ab942009-11-13 11:56:32 -0800442 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
Ben Cahill88521362009-10-30 14:36:06 -0700443
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700444 ret = iwl_init_otp_access(priv);
445 if (ret) {
446 IWL_ERR(priv, "Failed to initialize OTP access.\n");
447 ret = -ENOENT;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700448 goto done;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800449 }
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700450 _iwl_write32(priv, CSR_EEPROM_GP,
451 iwl_read32(priv, CSR_EEPROM_GP) &
452 ~CSR_EEPROM_GP_IF_OWNER_MSK);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700453
454 iwl_set_bit(priv, CSR_OTP_GP_REG,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700455 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
456 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700457 /* traversing the linked list if no shadow ram supported */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700458 if (!priv->cfg->base_params->shadow_ram_support) {
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700459 if (iwl_find_otp_image(priv, &validblockaddr)) {
460 ret = -ENOENT;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700461 goto done;
462 }
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700463 }
464 for (addr = validblockaddr; addr < validblockaddr + sz;
465 addr += sizeof(u16)) {
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800466 __le16 eeprom_data;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700467
468 ret = iwl_read_otp_word(priv, addr, &eeprom_data);
469 if (ret)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700470 goto done;
Wey-Yi Guy415e4992009-08-13 13:30:54 -0700471 e[cache_addr / 2] = eeprom_data;
472 cache_addr += sizeof(u16);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700473 }
474 } else {
475 /* eeprom is an array of 16bit values */
476 for (addr = 0; addr < sz; addr += sizeof(u16)) {
477 u32 r;
478
479 _iwl_write32(priv, CSR_EEPROM_REG,
480 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
481
Abhijeet Kolekar1739d332009-10-02 13:44:05 -0700482 ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
483 CSR_EEPROM_REG_READ_VALID_MSK,
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700484 CSR_EEPROM_REG_READ_VALID_MSK,
485 IWL_EEPROM_ACCESS_TIMEOUT);
486 if (ret < 0) {
487 IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
488 goto done;
489 }
490 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
Johannes Bergaf6b8ee2009-12-14 14:12:08 -0800491 e[addr / 2] = cpu_to_le16(r >> 16);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700492 }
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800493 }
Johannes Bergd1358f62010-04-28 12:09:15 -0700494
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800495 IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
Johannes Bergd1358f62010-04-28 12:09:15 -0700496 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
497 ? "OTP" : "EEPROM",
498 iwl_eeprom_query16(priv, EEPROM_VERSION));
499
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800500 ret = 0;
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800501done:
502 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
Johannes Bergd1358f62010-04-28 12:09:15 -0700503
Tomas Winkler073d3f52008-04-21 15:41:52 -0700504err:
505 if (ret)
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700506 iwl_eeprom_free(priv);
Reinette Chatref8701fe2009-12-10 14:37:22 -0800507 /* Reset chip to save power until we load uCode during "up". */
Johannes Berg14e8e4a2010-09-22 18:02:10 +0200508 iwl_apm_stop(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700509alloc_err:
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800510 return ret;
511}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800512EXPORT_SYMBOL(iwl_eeprom_init);
Assaf Krauss34cf6ff2008-03-06 10:40:20 -0800513
Tomas Winkler073d3f52008-04-21 15:41:52 -0700514void iwl_eeprom_free(struct iwl_priv *priv)
515{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300516 kfree(priv->eeprom);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700517 priv->eeprom = NULL;
518}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800519EXPORT_SYMBOL(iwl_eeprom_free);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700520
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700521static void iwl_init_band_reference(const struct iwl_priv *priv,
Tomas Winkler073d3f52008-04-21 15:41:52 -0700522 int eep_band, int *eeprom_ch_count,
523 const struct iwl_eeprom_channel **eeprom_ch_info,
524 const u8 **eeprom_ch_index)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700525{
Tomas Winkler073d3f52008-04-21 15:41:52 -0700526 u32 offset = priv->cfg->ops->lib->
527 eeprom_ops.regulatory_bands[eep_band - 1];
528 switch (eep_band) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700529 case 1: /* 2.4GHz band */
530 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700531 *eeprom_ch_info = (struct iwl_eeprom_channel *)
532 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700533 *eeprom_ch_index = iwl_eeprom_band_1;
534 break;
535 case 2: /* 4.9GHz band */
536 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700537 *eeprom_ch_info = (struct iwl_eeprom_channel *)
538 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700539 *eeprom_ch_index = iwl_eeprom_band_2;
540 break;
541 case 3: /* 5.2GHz band */
542 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700543 *eeprom_ch_info = (struct iwl_eeprom_channel *)
544 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700545 *eeprom_ch_index = iwl_eeprom_band_3;
546 break;
547 case 4: /* 5.5GHz band */
548 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700549 *eeprom_ch_info = (struct iwl_eeprom_channel *)
550 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700551 *eeprom_ch_index = iwl_eeprom_band_4;
552 break;
553 case 5: /* 5.7GHz band */
554 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700555 *eeprom_ch_info = (struct iwl_eeprom_channel *)
556 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700557 *eeprom_ch_index = iwl_eeprom_band_5;
558 break;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700559 case 6: /* 2.4GHz ht40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700560 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700561 *eeprom_ch_info = (struct iwl_eeprom_channel *)
562 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700563 *eeprom_ch_index = iwl_eeprom_band_6;
564 break;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700565 case 7: /* 5 GHz ht40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700566 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
Tomas Winkler073d3f52008-04-21 15:41:52 -0700567 *eeprom_ch_info = (struct iwl_eeprom_channel *)
568 iwl_eeprom_query_addr(priv, offset);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700569 *eeprom_ch_index = iwl_eeprom_band_7;
570 break;
571 default:
572 BUG();
573 return;
574 }
575}
576
577#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
578 ? # x " " : "")
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700579/**
Zhu Yi3b247162009-08-13 13:30:53 -0700580 * iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700581 *
582 * Does not set up a command, or touch hardware.
583 */
Zhu Yi3b247162009-08-13 13:30:53 -0700584static int iwl_mod_ht40_chan_info(struct iwl_priv *priv,
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700585 enum ieee80211_band band, u16 channel,
Tomas Winkler073d3f52008-04-21 15:41:52 -0700586 const struct iwl_eeprom_channel *eeprom_ch,
Zhu Yi3b247162009-08-13 13:30:53 -0700587 u8 clear_ht40_extension_channel)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700588{
589 struct iwl_channel_info *ch_info;
590
591 ch_info = (struct iwl_channel_info *)
Assaf Krauss8622e702008-03-21 13:53:43 -0700592 iwl_get_channel_info(priv, band, channel);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700593
594 if (!is_channel_valid(ch_info))
595 return -1;
596
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800597 IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
Tomas Winkler630fe9b2008-06-12 09:47:08 +0800598 " Ad-Hoc %ssupported\n",
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700599 ch_info->channel,
600 is_channel_a_band(ch_info) ?
601 "5.2" : "2.4",
602 CHECK_AND_PRINT(IBSS),
603 CHECK_AND_PRINT(ACTIVE),
604 CHECK_AND_PRINT(RADAR),
605 CHECK_AND_PRINT(WIDE),
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700606 CHECK_AND_PRINT(DFS),
607 eeprom_ch->flags,
608 eeprom_ch->max_power_avg,
609 ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
610 && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
611 "" : "not ");
612
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700613 ch_info->ht40_eeprom = *eeprom_ch;
614 ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700615 ch_info->ht40_flags = eeprom_ch->flags;
Reinette Chatre6c3069b2009-12-14 14:12:13 -0800616 if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
617 ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700618
619 return 0;
620}
621
622#define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
623 ? # x " " : "")
624
625/**
626 * iwl_init_channel_map - Set up driver's info for all possible channels
627 */
628int iwl_init_channel_map(struct iwl_priv *priv)
629{
630 int eeprom_ch_count = 0;
631 const u8 *eeprom_ch_index = NULL;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700632 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700633 int band, ch;
634 struct iwl_channel_info *ch_info;
635
636 if (priv->channel_count) {
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800637 IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700638 return 0;
639 }
640
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800641 IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700642
643 priv->channel_count =
644 ARRAY_SIZE(iwl_eeprom_band_1) +
645 ARRAY_SIZE(iwl_eeprom_band_2) +
646 ARRAY_SIZE(iwl_eeprom_band_3) +
647 ARRAY_SIZE(iwl_eeprom_band_4) +
648 ARRAY_SIZE(iwl_eeprom_band_5);
649
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800650 IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
651 priv->channel_count);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700652
653 priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
654 priv->channel_count, GFP_KERNEL);
655 if (!priv->channel_info) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800656 IWL_ERR(priv, "Could not allocate channel_info\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700657 priv->channel_count = 0;
658 return -ENOMEM;
659 }
660
661 ch_info = priv->channel_info;
662
663 /* Loop through the 5 EEPROM bands adding them in order to the
664 * channel map we maintain (that contains additional information than
665 * what just in the EEPROM) */
666 for (band = 1; band <= 5; band++) {
667
668 iwl_init_band_reference(priv, band, &eeprom_ch_count,
669 &eeprom_ch_info, &eeprom_ch_index);
670
671 /* Loop through each band adding each of the channels */
672 for (ch = 0; ch < eeprom_ch_count; ch++) {
673 ch_info->channel = eeprom_ch_index[ch];
674 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
675 IEEE80211_BAND_5GHZ;
676
677 /* permanently store EEPROM's channel regulatory flags
678 * and max power in channel info database. */
679 ch_info->eeprom = eeprom_ch_info[ch];
680
681 /* Copy the run-time flags so they are there even on
682 * invalid channels */
683 ch_info->flags = eeprom_ch_info[ch].flags;
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700684 /* First write that ht40 is not enabled, and then enable
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800685 * one by one */
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700686 ch_info->ht40_extension_channel =
Zhu Yi3b247162009-08-13 13:30:53 -0700687 IEEE80211_CHAN_NO_HT40;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700688
689 if (!(is_channel_valid(ch_info))) {
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800690 IWL_DEBUG_EEPROM(priv,
691 "Ch. %d Flags %x [%sGHz] - "
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700692 "No traffic\n",
693 ch_info->channel,
694 ch_info->flags,
695 is_channel_a_band(ch_info) ?
696 "5.2" : "2.4");
697 ch_info++;
698 continue;
699 }
700
701 /* Initialize regulatory-based run-time data */
702 ch_info->max_power_avg = ch_info->curr_txpow =
703 eeprom_ch_info[ch].max_power_avg;
704 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
705 ch_info->min_power = 0;
706
Wey-Yi Guyd058ff82010-12-03 10:33:35 -0800707 IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] "
708 "%s%s%s%s%s%s(0x%02x %ddBm):"
Tomas Winkler630fe9b2008-06-12 09:47:08 +0800709 " Ad-Hoc %ssupported\n",
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700710 ch_info->channel,
711 is_channel_a_band(ch_info) ?
712 "5.2" : "2.4",
713 CHECK_AND_PRINT_I(VALID),
714 CHECK_AND_PRINT_I(IBSS),
715 CHECK_AND_PRINT_I(ACTIVE),
716 CHECK_AND_PRINT_I(RADAR),
717 CHECK_AND_PRINT_I(WIDE),
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700718 CHECK_AND_PRINT_I(DFS),
719 eeprom_ch_info[ch].flags,
720 eeprom_ch_info[ch].max_power_avg,
721 ((eeprom_ch_info[ch].
722 flags & EEPROM_CHANNEL_IBSS)
723 && !(eeprom_ch_info[ch].
724 flags & EEPROM_CHANNEL_RADAR))
725 ? "" : "not ");
726
Winkler, Tomas62ea9c52009-01-19 15:30:29 -0800727 /* Set the tx_power_user_lmt to the highest power
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700728 * supported by any channel */
729 if (eeprom_ch_info[ch].max_power_avg >
Tomas Winkler630fe9b2008-06-12 09:47:08 +0800730 priv->tx_power_user_lmt)
731 priv->tx_power_user_lmt =
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700732 eeprom_ch_info[ch].max_power_avg;
733
734 ch_info++;
735 }
736 }
737
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700738 /* Check if we do have HT40 channels */
Reinette Chatrea89d03c2009-02-10 15:19:04 -0800739 if (priv->cfg->ops->lib->eeprom_ops.regulatory_bands[5] ==
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700740 EEPROM_REGULATORY_BAND_NO_HT40 &&
Reinette Chatrea89d03c2009-02-10 15:19:04 -0800741 priv->cfg->ops->lib->eeprom_ops.regulatory_bands[6] ==
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700742 EEPROM_REGULATORY_BAND_NO_HT40)
Samuel Ortize6148912009-01-23 13:45:15 -0800743 return 0;
744
Wey-Yi Guy7aafef12009-08-07 15:41:38 -0700745 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700746 for (band = 6; band <= 7; band++) {
747 enum ieee80211_band ieeeband;
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700748
749 iwl_init_band_reference(priv, band, &eeprom_ch_count,
750 &eeprom_ch_info, &eeprom_ch_index);
751
752 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
753 ieeeband =
754 (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
755
756 /* Loop through each band adding each of the channels */
757 for (ch = 0; ch < eeprom_ch_count; ch++) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700758 /* Set up driver's info for lower half */
Zhu Yi3b247162009-08-13 13:30:53 -0700759 iwl_mod_ht40_chan_info(priv, ieeeband,
Tomas Winklerda6833cb2008-05-15 13:54:15 +0800760 eeprom_ch_index[ch],
Zhu Yi3b247162009-08-13 13:30:53 -0700761 &eeprom_ch_info[ch],
762 IEEE80211_CHAN_NO_HT40PLUS);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700763
764 /* Set up driver's info for upper half */
Zhu Yi3b247162009-08-13 13:30:53 -0700765 iwl_mod_ht40_chan_info(priv, ieeeband,
766 eeprom_ch_index[ch] + 4,
767 &eeprom_ch_info[ch],
768 IEEE80211_CHAN_NO_HT40MINUS);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700769 }
770 }
771
Wey-Yi Guyab9fd1b2009-08-21 13:34:23 -0700772 /* for newer device (6000 series and up)
773 * EEPROM contain enhanced tx power information
774 * driver need to process addition information
775 * to determine the max channel tx power limits
776 */
777 if (priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower)
778 priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower(priv);
779
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700780 return 0;
781}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800782EXPORT_SYMBOL(iwl_init_channel_map);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700783
784/*
Tomas Winklerda6833cb2008-05-15 13:54:15 +0800785 * iwl_free_channel_map - undo allocations in iwl_init_channel_map
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700786 */
787void iwl_free_channel_map(struct iwl_priv *priv)
788{
789 kfree(priv->channel_info);
790 priv->channel_count = 0;
791}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800792EXPORT_SYMBOL(iwl_free_channel_map);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700793
794/**
795 * iwl_get_channel_info - Find driver's private channel info
796 *
797 * Based on band and channel number.
798 */
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800799const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
800 enum ieee80211_band band, u16 channel)
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700801{
802 int i;
803
804 switch (band) {
805 case IEEE80211_BAND_5GHZ:
806 for (i = 14; i < priv->channel_count; i++) {
807 if (priv->channel_info[i].channel == channel)
808 return &priv->channel_info[i];
809 }
810 break;
811 case IEEE80211_BAND_2GHZ:
812 if (channel >= 1 && channel <= 14)
813 return &priv->channel_info[channel - 1];
814 break;
815 default:
816 BUG();
817 }
818
819 return NULL;
820}
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800821EXPORT_SYMBOL(iwl_get_channel_info);