2008-03-07 02:40:20 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This file is provided under a dual BSD/GPLv2 license. When using or
|
|
|
|
* redistributing this file, you may do so under either license.
|
|
|
|
*
|
|
|
|
* GPL LICENSE SUMMARY
|
|
|
|
*
|
2010-01-16 05:43:41 +08:00
|
|
|
* Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
|
2008-03-07 02:40:20 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* The full GNU General Public License is included in this distribution
|
|
|
|
* in the file called LICENSE.GPL.
|
|
|
|
*
|
|
|
|
* Contact Information:
|
2008-12-10 03:28:58 +08:00
|
|
|
* Intel Linux Wireless <ilw@linux.intel.com>
|
2008-03-07 02:40:20 +08:00
|
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
*
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2010-01-16 05:43:41 +08:00
|
|
|
* Copyright(c) 2005 - 2010 Intel Corporation. All rights reserved.
|
2008-03-07 02:40:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-03-07 02:40:20 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
|
2008-04-25 02:55:37 +08:00
|
|
|
#include "iwl-commands.h"
|
2008-04-25 02:55:38 +08:00
|
|
|
#include "iwl-dev.h"
|
2008-03-07 02:40:20 +08:00
|
|
|
#include "iwl-core.h"
|
2008-03-13 07:58:49 +08:00
|
|
|
#include "iwl-debug.h"
|
2008-03-07 02:40:20 +08:00
|
|
|
#include "iwl-eeprom.h"
|
2008-03-26 07:33:37 +08:00
|
|
|
#include "iwl-io.h"
|
2008-03-07 02:40:20 +08:00
|
|
|
|
2008-03-15 01:38:49 +08:00
|
|
|
/************************** EEPROM BANDS ****************************
|
|
|
|
*
|
|
|
|
* The iwl_eeprom_band definitions below provide the mapping from the
|
|
|
|
* EEPROM contents to the specific channel number supported for each
|
|
|
|
* band.
|
|
|
|
*
|
|
|
|
* For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
|
|
|
|
* definition below maps to physical channel 42 in the 5.2GHz spectrum.
|
|
|
|
* The specific geography and calibration information for that channel
|
|
|
|
* is contained in the eeprom map itself.
|
|
|
|
*
|
|
|
|
* During init, we copy the eeprom information and channel map
|
|
|
|
* information into priv->channel_info_24/52 and priv->channel_map_24/52
|
|
|
|
*
|
|
|
|
* channel_map_24/52 provides the index in the channel_info array for a
|
|
|
|
* given channel. We have to have two separate maps as there is channel
|
|
|
|
* overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
|
|
|
|
* band_2
|
|
|
|
*
|
|
|
|
* A value of 0xff stored in the channel_map indicates that the channel
|
|
|
|
* is not supported by the hardware at all.
|
|
|
|
*
|
|
|
|
* A value of 0xfe in the channel_map indicates that the channel is not
|
|
|
|
* valid for Tx with the current hardware. This means that
|
|
|
|
* while the system can tune and receive on a given channel, it may not
|
|
|
|
* be able to associate or transmit any frames on that
|
|
|
|
* channel. There is no corresponding channel information for that
|
|
|
|
* entry.
|
|
|
|
*
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/* 2.4 GHz */
|
|
|
|
const u8 iwl_eeprom_band_1[14] = {
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 5.2 GHz bands */
|
|
|
|
static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
|
|
|
|
183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
|
|
|
|
34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
|
|
|
|
100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
|
|
|
|
145, 149, 153, 157, 161, 165
|
|
|
|
};
|
|
|
|
|
2009-08-08 06:41:38 +08:00
|
|
|
static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
|
2008-03-15 01:38:49 +08:00
|
|
|
1, 2, 3, 4, 5, 6, 7
|
|
|
|
};
|
|
|
|
|
2009-08-08 06:41:38 +08:00
|
|
|
static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
|
2008-03-15 01:38:49 +08:00
|
|
|
36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
|
|
|
|
};
|
|
|
|
|
2008-03-07 02:40:20 +08:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* EEPROM related functions
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2010-09-23 00:02:00 +08:00
|
|
|
static int iwl_eeprom_verify_signature(struct iwl_priv *priv)
|
2008-03-07 02:40:20 +08:00
|
|
|
{
|
2009-10-03 04:44:06 +08:00
|
|
|
u32 gp = iwl_read32(priv, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
|
|
|
|
int ret = 0;
|
|
|
|
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
|
2009-10-03 04:44:06 +08:00
|
|
|
switch (gp) {
|
|
|
|
case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
|
|
|
|
if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
|
|
|
|
IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
|
|
|
|
gp);
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
|
|
|
|
case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
|
|
|
|
if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
|
|
|
|
IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
|
|
|
|
default:
|
|
|
|
IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
|
|
|
|
"EEPROM_GP=0x%08x\n",
|
|
|
|
(priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
|
|
|
|
? "OTP" : "EEPROM", gp);
|
|
|
|
ret = -ENOENT;
|
|
|
|
break;
|
2008-03-07 02:40:20 +08:00
|
|
|
}
|
2009-10-03 04:44:06 +08:00
|
|
|
return ret;
|
2008-03-07 02:40:20 +08:00
|
|
|
}
|
|
|
|
|
2009-08-14 04:30:54 +08:00
|
|
|
static void iwl_set_otp_access(struct iwl_priv *priv, enum iwl_access_mode mode)
|
|
|
|
{
|
|
|
|
u32 otpgp;
|
|
|
|
|
|
|
|
otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
|
|
|
|
if (mode == IWL_OTP_ACCESS_ABSOLUTE)
|
|
|
|
iwl_clear_bit(priv, CSR_OTP_GP_REG,
|
|
|
|
CSR_OTP_GP_REG_OTP_ACCESS_MODE);
|
|
|
|
else
|
|
|
|
iwl_set_bit(priv, CSR_OTP_GP_REG,
|
|
|
|
CSR_OTP_GP_REG_OTP_ACCESS_MODE);
|
|
|
|
}
|
|
|
|
|
2009-05-23 02:01:46 +08:00
|
|
|
static int iwlcore_get_nvm_type(struct iwl_priv *priv)
|
|
|
|
{
|
|
|
|
u32 otpgp;
|
|
|
|
int nvm_type;
|
|
|
|
|
|
|
|
/* OTP only valid for CP/PP and after */
|
|
|
|
switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
|
2009-07-18 00:30:21 +08:00
|
|
|
case CSR_HW_REV_TYPE_NONE:
|
|
|
|
IWL_ERR(priv, "Unknown hardware type\n");
|
|
|
|
return -ENOENT;
|
2009-05-23 02:01:46 +08:00
|
|
|
case CSR_HW_REV_TYPE_3945:
|
|
|
|
case CSR_HW_REV_TYPE_4965:
|
|
|
|
case CSR_HW_REV_TYPE_5300:
|
|
|
|
case CSR_HW_REV_TYPE_5350:
|
|
|
|
case CSR_HW_REV_TYPE_5100:
|
|
|
|
case CSR_HW_REV_TYPE_5150:
|
|
|
|
nvm_type = NVM_DEVICE_TYPE_EEPROM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
|
|
|
|
if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
|
|
|
|
nvm_type = NVM_DEVICE_TYPE_OTP;
|
|
|
|
else
|
|
|
|
nvm_type = NVM_DEVICE_TYPE_EEPROM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nvm_type;
|
|
|
|
}
|
|
|
|
|
2008-04-22 06:41:52 +08:00
|
|
|
const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
|
|
|
|
{
|
2010-10-06 23:10:00 +08:00
|
|
|
BUG_ON(offset >= priv->cfg->base_params->eeprom_size);
|
2008-04-22 06:41:52 +08:00
|
|
|
return &priv->eeprom[offset];
|
|
|
|
}
|
2008-03-07 02:40:20 +08:00
|
|
|
|
2009-05-23 02:01:46 +08:00
|
|
|
static int iwl_init_otp_access(struct iwl_priv *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Enable 40MHz radio clock */
|
|
|
|
_iwl_write32(priv, CSR_GP_CNTRL,
|
|
|
|
_iwl_read32(priv, CSR_GP_CNTRL) |
|
|
|
|
CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
|
|
|
|
|
|
|
|
/* wait for clock to be ready */
|
2009-10-03 04:44:05 +08:00
|
|
|
ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
|
|
|
|
CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
|
2009-05-23 02:01:46 +08:00
|
|
|
CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
|
|
|
|
25000);
|
|
|
|
if (ret < 0)
|
|
|
|
IWL_ERR(priv, "Time out access OTP\n");
|
|
|
|
else {
|
2009-05-23 05:37:55 +08:00
|
|
|
iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
|
|
|
|
APMG_PS_CTRL_VAL_RESET_REQ);
|
|
|
|
udelay(5);
|
|
|
|
iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
|
|
|
|
APMG_PS_CTRL_VAL_RESET_REQ);
|
2009-10-17 05:25:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CSR auto clock gate disable bit -
|
|
|
|
* this is only applicable for HW with OTP shadow RAM
|
|
|
|
*/
|
2010-10-06 23:10:00 +08:00
|
|
|
if (priv->cfg->base_params->shadow_ram_support)
|
2009-10-17 05:25:56 +08:00
|
|
|
iwl_set_bit(priv, CSR_DBG_LINK_PWR_MGMT_REG,
|
|
|
|
CSR_RESET_LINK_PWR_MGMT_DISABLED);
|
2009-05-23 02:01:46 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, __le16 *eeprom_data)
|
2009-08-14 04:30:54 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
u32 r;
|
|
|
|
u32 otpgp;
|
|
|
|
|
|
|
|
_iwl_write32(priv, CSR_EEPROM_REG,
|
|
|
|
CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
|
2009-10-03 04:44:05 +08:00
|
|
|
ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
|
|
|
|
CSR_EEPROM_REG_READ_VALID_MSK,
|
2009-08-14 04:30:54 +08:00
|
|
|
CSR_EEPROM_REG_READ_VALID_MSK,
|
|
|
|
IWL_EEPROM_ACCESS_TIMEOUT);
|
|
|
|
if (ret < 0) {
|
|
|
|
IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
|
|
|
|
/* check for ECC errors: */
|
|
|
|
otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
|
|
|
|
if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
|
|
|
|
/* stop in this case */
|
|
|
|
/* set the uncorrectable OTP ECC bit for acknowledgement */
|
|
|
|
iwl_set_bit(priv, CSR_OTP_GP_REG,
|
|
|
|
CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
|
|
|
|
IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
|
|
|
|
/* continue in this case */
|
|
|
|
/* set the correctable OTP ECC bit for acknowledgement */
|
|
|
|
iwl_set_bit(priv, CSR_OTP_GP_REG,
|
|
|
|
CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
|
|
|
|
IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
|
|
|
|
}
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
*eeprom_data = cpu_to_le16(r >> 16);
|
2009-08-14 04:30:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* iwl_is_otp_empty: check for empty OTP
|
|
|
|
*/
|
|
|
|
static bool iwl_is_otp_empty(struct iwl_priv *priv)
|
|
|
|
{
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
u16 next_link_addr = 0;
|
|
|
|
__le16 link_value;
|
2009-08-14 04:30:54 +08:00
|
|
|
bool is_empty = false;
|
|
|
|
|
|
|
|
/* locate the beginning of OTP link list */
|
|
|
|
if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
|
|
|
|
if (!link_value) {
|
|
|
|
IWL_ERR(priv, "OTP is empty\n");
|
|
|
|
is_empty = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
IWL_ERR(priv, "Unable to read first block of OTP list.\n");
|
|
|
|
is_empty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* iwl_find_otp_image: find EEPROM image in OTP
|
|
|
|
* finding the OTP block that contains the EEPROM image.
|
|
|
|
* the last valid block on the link list (the block _before_ the last block)
|
|
|
|
* is the block we should read and used to configure the device.
|
|
|
|
* If all the available OTP blocks are full, the last block will be the block
|
|
|
|
* we should read and used to configure the device.
|
|
|
|
* only perform this operation if shadow RAM is disabled
|
|
|
|
*/
|
|
|
|
static int iwl_find_otp_image(struct iwl_priv *priv,
|
|
|
|
u16 *validblockaddr)
|
|
|
|
{
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
u16 next_link_addr = 0, valid_addr;
|
|
|
|
__le16 link_value = 0;
|
2009-08-14 04:30:54 +08:00
|
|
|
int usedblocks = 0;
|
|
|
|
|
|
|
|
/* set addressing mode to absolute to traverse the link list */
|
|
|
|
iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
|
|
|
|
|
|
|
|
/* checking for empty OTP or error */
|
|
|
|
if (iwl_is_otp_empty(priv))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start traverse link list
|
|
|
|
* until reach the max number of OTP blocks
|
|
|
|
* different devices have different number of OTP blocks
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
/* save current valid block address
|
|
|
|
* check for more block on the link list
|
|
|
|
*/
|
|
|
|
valid_addr = next_link_addr;
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "OTP blocks %d addr 0x%x\n",
|
2009-08-14 04:30:54 +08:00
|
|
|
usedblocks, next_link_addr);
|
|
|
|
if (iwl_read_otp_word(priv, next_link_addr, &link_value))
|
|
|
|
return -EINVAL;
|
|
|
|
if (!link_value) {
|
|
|
|
/*
|
2009-10-03 04:43:55 +08:00
|
|
|
* reach the end of link list, return success and
|
2009-08-14 04:30:54 +08:00
|
|
|
* set address point to the starting address
|
|
|
|
* of the image
|
|
|
|
*/
|
2009-10-03 04:43:55 +08:00
|
|
|
*validblockaddr = valid_addr;
|
|
|
|
/* skip first 2 bytes (link list pointer) */
|
|
|
|
*validblockaddr += 2;
|
|
|
|
return 0;
|
2009-08-14 04:30:54 +08:00
|
|
|
}
|
|
|
|
/* more in the link list, continue */
|
|
|
|
usedblocks++;
|
2010-10-06 23:10:00 +08:00
|
|
|
} while (usedblocks <= priv->cfg->base_params->max_ll_items);
|
2009-10-03 04:43:55 +08:00
|
|
|
|
|
|
|
/* OTP has no valid blocks */
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "OTP has no valid blocks\n");
|
2009-10-03 04:43:55 +08:00
|
|
|
return -EINVAL;
|
2009-08-14 04:30:54 +08:00
|
|
|
}
|
|
|
|
|
2010-10-09 07:05:19 +08:00
|
|
|
const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
|
|
|
|
{
|
|
|
|
return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
|
|
|
|
{
|
|
|
|
if (!priv->eeprom)
|
|
|
|
return 0;
|
|
|
|
return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
|
|
|
|
}
|
|
|
|
|
2008-03-07 02:40:20 +08:00
|
|
|
/**
|
|
|
|
* iwl_eeprom_init - read EEPROM contents
|
|
|
|
*
|
|
|
|
* Load the EEPROM contents from adapter into priv->eeprom
|
|
|
|
*
|
|
|
|
* NOTE: This routine uses the non-debug IO access functions.
|
|
|
|
*/
|
2008-03-13 07:58:50 +08:00
|
|
|
int iwl_eeprom_init(struct iwl_priv *priv)
|
2008-03-07 02:40:20 +08:00
|
|
|
{
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
__le16 *e;
|
2008-03-26 07:33:37 +08:00
|
|
|
u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
|
2009-05-23 02:01:46 +08:00
|
|
|
int sz;
|
2008-03-07 02:40:20 +08:00
|
|
|
int ret;
|
|
|
|
u16 addr;
|
2009-08-14 04:30:54 +08:00
|
|
|
u16 validblockaddr = 0;
|
|
|
|
u16 cache_addr = 0;
|
2009-05-23 02:01:46 +08:00
|
|
|
|
|
|
|
priv->nvm_device_type = iwlcore_get_nvm_type(priv);
|
2009-07-18 00:30:21 +08:00
|
|
|
if (priv->nvm_device_type == -ENOENT)
|
|
|
|
return -ENOENT;
|
2008-04-22 06:41:52 +08:00
|
|
|
/* allocate eeprom */
|
2010-10-06 23:10:00 +08:00
|
|
|
sz = priv->cfg->base_params->eeprom_size;
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
|
2008-04-22 06:41:52 +08:00
|
|
|
priv->eeprom = kzalloc(sz, GFP_KERNEL);
|
|
|
|
if (!priv->eeprom) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto alloc_err;
|
|
|
|
}
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
e = (__le16 *)priv->eeprom;
|
2008-03-07 02:40:20 +08:00
|
|
|
|
2009-12-11 06:37:22 +08:00
|
|
|
priv->cfg->ops->lib->apm_ops.init(priv);
|
2009-11-14 03:56:32 +08:00
|
|
|
|
2010-09-23 00:02:00 +08:00
|
|
|
ret = iwl_eeprom_verify_signature(priv);
|
2008-04-22 06:41:52 +08:00
|
|
|
if (ret < 0) {
|
2008-12-19 10:37:33 +08:00
|
|
|
IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
|
2008-04-22 06:41:52 +08:00
|
|
|
ret = -ENOENT;
|
|
|
|
goto err;
|
2008-03-07 02:40:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure driver (instead of uCode) is allowed to read EEPROM */
|
|
|
|
ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
|
|
|
|
if (ret < 0) {
|
2008-12-19 10:37:33 +08:00
|
|
|
IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
|
2008-04-22 06:41:52 +08:00
|
|
|
ret = -ENOENT;
|
|
|
|
goto err;
|
2008-03-07 02:40:20 +08:00
|
|
|
}
|
2009-10-31 05:36:06 +08:00
|
|
|
|
2009-11-14 03:56:32 +08:00
|
|
|
if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
|
2009-10-31 05:36:06 +08:00
|
|
|
|
2009-05-23 02:01:46 +08:00
|
|
|
ret = iwl_init_otp_access(priv);
|
|
|
|
if (ret) {
|
|
|
|
IWL_ERR(priv, "Failed to initialize OTP access.\n");
|
|
|
|
ret = -ENOENT;
|
2009-08-14 04:30:54 +08:00
|
|
|
goto done;
|
2009-05-23 02:01:46 +08:00
|
|
|
}
|
|
|
|
_iwl_write32(priv, CSR_EEPROM_GP,
|
|
|
|
iwl_read32(priv, CSR_EEPROM_GP) &
|
|
|
|
~CSR_EEPROM_GP_IF_OWNER_MSK);
|
2009-08-14 04:30:54 +08:00
|
|
|
|
|
|
|
iwl_set_bit(priv, CSR_OTP_GP_REG,
|
2009-05-23 02:01:46 +08:00
|
|
|
CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
|
|
|
|
CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
|
2009-08-14 04:30:54 +08:00
|
|
|
/* traversing the linked list if no shadow ram supported */
|
2010-10-06 23:10:00 +08:00
|
|
|
if (!priv->cfg->base_params->shadow_ram_support) {
|
2009-08-14 04:30:54 +08:00
|
|
|
if (iwl_find_otp_image(priv, &validblockaddr)) {
|
|
|
|
ret = -ENOENT;
|
2009-05-23 02:01:46 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2009-08-14 04:30:54 +08:00
|
|
|
}
|
|
|
|
for (addr = validblockaddr; addr < validblockaddr + sz;
|
|
|
|
addr += sizeof(u16)) {
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
__le16 eeprom_data;
|
2009-08-14 04:30:54 +08:00
|
|
|
|
|
|
|
ret = iwl_read_otp_word(priv, addr, &eeprom_data);
|
|
|
|
if (ret)
|
2009-05-23 02:01:46 +08:00
|
|
|
goto done;
|
2009-08-14 04:30:54 +08:00
|
|
|
e[cache_addr / 2] = eeprom_data;
|
|
|
|
cache_addr += sizeof(u16);
|
2009-05-23 02:01:46 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* eeprom is an array of 16bit values */
|
|
|
|
for (addr = 0; addr < sz; addr += sizeof(u16)) {
|
|
|
|
u32 r;
|
|
|
|
|
|
|
|
_iwl_write32(priv, CSR_EEPROM_REG,
|
|
|
|
CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
|
|
|
|
|
2009-10-03 04:44:05 +08:00
|
|
|
ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
|
|
|
|
CSR_EEPROM_REG_READ_VALID_MSK,
|
2009-05-23 02:01:46 +08:00
|
|
|
CSR_EEPROM_REG_READ_VALID_MSK,
|
|
|
|
IWL_EEPROM_ACCESS_TIMEOUT);
|
|
|
|
if (ret < 0) {
|
|
|
|
IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
|
iwlwifi: fix EEPROM/OTP reading endian annotations and a bug
The construct "le16_to_cpu((__force __le16)(r >> 16))" has
always bothered me when looking through the iwlwifi code,
it shouldn't be necessary to __force anything, and before
this code, "r" was obtained with an ioread32, which swaps
each of the two u16 values in it properly when swapping the
entire u32 value. I've had arguments about this code with
people before, but always conceded they were right because
removing it only made things not work at all on big endian
platforms.
However, analysing a failure of the OTP reading code, I now
finally figured out what is going on, and why my intuition
about that code being wrong was right all along.
It turns out that the 'priv->eeprom' u8 array really wants
to have the data in it in little endian. So the force code
above and all really converts *to* little endian, not from
it. Cf., for instance, the function iwl_eeprom_query16() --
it reads two u8 values and combines them into a u16, in a
little-endian way. And considering it more, it makes sense
to have the eeprom array as on the device, after all not
all values really are 16-bit values, the MAC address for
instance is not.
Now, what this really means is that all the annotations are
completely wrong. The eeprom reading code should fill the
priv->eeprom array as a __le16 array, with __le16 values.
This also means that iwl_read_otp_word() should really have
a __le16 pointer as the data argument, since it should be
filling that in a format suitable for priv->eeprom.
Propagating these changes throughout, iwl_find_otp_image()
is found to be, now obviously visible, defective -- it uses
the data returned by iwl_read_otp_word() directly as if it
was CPU endianness. Fixing that, which is this hunk of the
patch:
- next_link_addr = link_value * sizeof(u16);
+ next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
is the only real change of this patch. Everything else is
just fixing the sparse annotations.
Also, the bug only shows up on big endian platforms with a
1000 series card. 5000 and previous series do not use OTP,
and 6000 series has shadow RAM support which means we don't
ever use the defective code on any cards but 1000.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: stable@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2009-12-15 06:12:08 +08:00
|
|
|
e[addr / 2] = cpu_to_le16(r >> 16);
|
2008-03-07 02:40:20 +08:00
|
|
|
}
|
|
|
|
}
|
2010-04-29 03:09:15 +08:00
|
|
|
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
|
2010-04-29 03:09:15 +08:00
|
|
|
(priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
|
|
|
|
? "OTP" : "EEPROM",
|
|
|
|
iwl_eeprom_query16(priv, EEPROM_VERSION));
|
|
|
|
|
2008-03-07 02:40:20 +08:00
|
|
|
ret = 0;
|
|
|
|
done:
|
|
|
|
priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
|
2010-04-29 03:09:15 +08:00
|
|
|
|
2008-04-22 06:41:52 +08:00
|
|
|
err:
|
|
|
|
if (ret)
|
2009-05-23 02:01:46 +08:00
|
|
|
iwl_eeprom_free(priv);
|
2009-12-11 06:37:22 +08:00
|
|
|
/* Reset chip to save power until we load uCode during "up". */
|
2010-09-23 00:02:10 +08:00
|
|
|
iwl_apm_stop(priv);
|
2008-04-22 06:41:52 +08:00
|
|
|
alloc_err:
|
2008-03-07 02:40:20 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-22 06:41:52 +08:00
|
|
|
void iwl_eeprom_free(struct iwl_priv *priv)
|
|
|
|
{
|
2008-07-21 07:40:14 +08:00
|
|
|
kfree(priv->eeprom);
|
2008-04-22 06:41:52 +08:00
|
|
|
priv->eeprom = NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-15 01:38:49 +08:00
|
|
|
static void iwl_init_band_reference(const struct iwl_priv *priv,
|
2008-04-22 06:41:52 +08:00
|
|
|
int eep_band, int *eeprom_ch_count,
|
|
|
|
const struct iwl_eeprom_channel **eeprom_ch_info,
|
|
|
|
const u8 **eeprom_ch_index)
|
2008-03-15 01:38:49 +08:00
|
|
|
{
|
2008-04-22 06:41:52 +08:00
|
|
|
u32 offset = priv->cfg->ops->lib->
|
|
|
|
eeprom_ops.regulatory_bands[eep_band - 1];
|
|
|
|
switch (eep_band) {
|
2008-03-15 01:38:49 +08:00
|
|
|
case 1: /* 2.4GHz band */
|
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_1;
|
|
|
|
break;
|
|
|
|
case 2: /* 4.9GHz band */
|
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_2;
|
|
|
|
break;
|
|
|
|
case 3: /* 5.2GHz band */
|
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_3;
|
|
|
|
break;
|
|
|
|
case 4: /* 5.5GHz band */
|
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_4;
|
|
|
|
break;
|
|
|
|
case 5: /* 5.7GHz band */
|
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_5;
|
|
|
|
break;
|
2009-08-08 06:41:38 +08:00
|
|
|
case 6: /* 2.4GHz ht40 channels */
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_6;
|
|
|
|
break;
|
2009-08-08 06:41:38 +08:00
|
|
|
case 7: /* 5 GHz ht40 channels */
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
|
2008-04-22 06:41:52 +08:00
|
|
|
*eeprom_ch_info = (struct iwl_eeprom_channel *)
|
|
|
|
iwl_eeprom_query_addr(priv, offset);
|
2008-03-15 01:38:49 +08:00
|
|
|
*eeprom_ch_index = iwl_eeprom_band_7;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
|
|
|
|
? # x " " : "")
|
|
|
|
/**
|
2009-08-14 04:30:53 +08:00
|
|
|
* iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
|
2008-03-15 01:38:49 +08:00
|
|
|
*
|
|
|
|
* Does not set up a command, or touch hardware.
|
|
|
|
*/
|
2009-08-14 04:30:53 +08:00
|
|
|
static int iwl_mod_ht40_chan_info(struct iwl_priv *priv,
|
2008-03-15 01:38:49 +08:00
|
|
|
enum ieee80211_band band, u16 channel,
|
2008-04-22 06:41:52 +08:00
|
|
|
const struct iwl_eeprom_channel *eeprom_ch,
|
2009-08-14 04:30:53 +08:00
|
|
|
u8 clear_ht40_extension_channel)
|
2008-03-15 01:38:49 +08:00
|
|
|
{
|
|
|
|
struct iwl_channel_info *ch_info;
|
|
|
|
|
|
|
|
ch_info = (struct iwl_channel_info *)
|
2008-03-22 04:53:43 +08:00
|
|
|
iwl_get_channel_info(priv, band, channel);
|
2008-03-15 01:38:49 +08:00
|
|
|
|
|
|
|
if (!is_channel_valid(ch_info))
|
|
|
|
return -1;
|
|
|
|
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
|
2008-06-12 09:47:08 +08:00
|
|
|
" Ad-Hoc %ssupported\n",
|
2008-03-15 01:38:49 +08:00
|
|
|
ch_info->channel,
|
|
|
|
is_channel_a_band(ch_info) ?
|
|
|
|
"5.2" : "2.4",
|
|
|
|
CHECK_AND_PRINT(IBSS),
|
|
|
|
CHECK_AND_PRINT(ACTIVE),
|
|
|
|
CHECK_AND_PRINT(RADAR),
|
|
|
|
CHECK_AND_PRINT(WIDE),
|
|
|
|
CHECK_AND_PRINT(DFS),
|
|
|
|
eeprom_ch->flags,
|
|
|
|
eeprom_ch->max_power_avg,
|
|
|
|
((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
|
|
|
|
&& !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
|
|
|
|
"" : "not ");
|
|
|
|
|
2009-08-08 06:41:38 +08:00
|
|
|
ch_info->ht40_eeprom = *eeprom_ch;
|
|
|
|
ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
|
|
|
|
ch_info->ht40_flags = eeprom_ch->flags;
|
2009-12-15 06:12:13 +08:00
|
|
|
if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
|
|
|
|
ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel;
|
2008-03-15 01:38:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
|
|
|
|
? # x " " : "")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iwl_init_channel_map - Set up driver's info for all possible channels
|
|
|
|
*/
|
|
|
|
int iwl_init_channel_map(struct iwl_priv *priv)
|
|
|
|
{
|
|
|
|
int eeprom_ch_count = 0;
|
|
|
|
const u8 *eeprom_ch_index = NULL;
|
2008-04-22 06:41:52 +08:00
|
|
|
const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
|
2008-03-15 01:38:49 +08:00
|
|
|
int band, ch;
|
|
|
|
struct iwl_channel_info *ch_info;
|
|
|
|
|
|
|
|
if (priv->channel_count) {
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n");
|
2008-03-15 01:38:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n");
|
2008-03-15 01:38:49 +08:00
|
|
|
|
|
|
|
priv->channel_count =
|
|
|
|
ARRAY_SIZE(iwl_eeprom_band_1) +
|
|
|
|
ARRAY_SIZE(iwl_eeprom_band_2) +
|
|
|
|
ARRAY_SIZE(iwl_eeprom_band_3) +
|
|
|
|
ARRAY_SIZE(iwl_eeprom_band_4) +
|
|
|
|
ARRAY_SIZE(iwl_eeprom_band_5);
|
|
|
|
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
|
|
|
|
priv->channel_count);
|
2008-03-15 01:38:49 +08:00
|
|
|
|
|
|
|
priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
|
|
|
|
priv->channel_count, GFP_KERNEL);
|
|
|
|
if (!priv->channel_info) {
|
2008-12-19 10:37:33 +08:00
|
|
|
IWL_ERR(priv, "Could not allocate channel_info\n");
|
2008-03-15 01:38:49 +08:00
|
|
|
priv->channel_count = 0;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch_info = priv->channel_info;
|
|
|
|
|
|
|
|
/* Loop through the 5 EEPROM bands adding them in order to the
|
|
|
|
* channel map we maintain (that contains additional information than
|
|
|
|
* what just in the EEPROM) */
|
|
|
|
for (band = 1; band <= 5; band++) {
|
|
|
|
|
|
|
|
iwl_init_band_reference(priv, band, &eeprom_ch_count,
|
|
|
|
&eeprom_ch_info, &eeprom_ch_index);
|
|
|
|
|
|
|
|
/* Loop through each band adding each of the channels */
|
|
|
|
for (ch = 0; ch < eeprom_ch_count; ch++) {
|
|
|
|
ch_info->channel = eeprom_ch_index[ch];
|
|
|
|
ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
|
|
|
|
IEEE80211_BAND_5GHZ;
|
|
|
|
|
|
|
|
/* permanently store EEPROM's channel regulatory flags
|
|
|
|
* and max power in channel info database. */
|
|
|
|
ch_info->eeprom = eeprom_ch_info[ch];
|
|
|
|
|
|
|
|
/* Copy the run-time flags so they are there even on
|
|
|
|
* invalid channels */
|
|
|
|
ch_info->flags = eeprom_ch_info[ch].flags;
|
2009-08-08 06:41:38 +08:00
|
|
|
/* First write that ht40 is not enabled, and then enable
|
2008-06-12 09:47:00 +08:00
|
|
|
* one by one */
|
2009-08-08 06:41:38 +08:00
|
|
|
ch_info->ht40_extension_channel =
|
2009-08-14 04:30:53 +08:00
|
|
|
IEEE80211_CHAN_NO_HT40;
|
2008-03-15 01:38:49 +08:00
|
|
|
|
|
|
|
if (!(is_channel_valid(ch_info))) {
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv,
|
|
|
|
"Ch. %d Flags %x [%sGHz] - "
|
2008-03-15 01:38:49 +08:00
|
|
|
"No traffic\n",
|
|
|
|
ch_info->channel,
|
|
|
|
ch_info->flags,
|
|
|
|
is_channel_a_band(ch_info) ?
|
|
|
|
"5.2" : "2.4");
|
|
|
|
ch_info++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize regulatory-based run-time data */
|
|
|
|
ch_info->max_power_avg = ch_info->curr_txpow =
|
|
|
|
eeprom_ch_info[ch].max_power_avg;
|
|
|
|
ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
|
|
|
|
ch_info->min_power = 0;
|
|
|
|
|
2010-12-04 02:33:35 +08:00
|
|
|
IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] "
|
|
|
|
"%s%s%s%s%s%s(0x%02x %ddBm):"
|
2008-06-12 09:47:08 +08:00
|
|
|
" Ad-Hoc %ssupported\n",
|
2008-03-15 01:38:49 +08:00
|
|
|
ch_info->channel,
|
|
|
|
is_channel_a_band(ch_info) ?
|
|
|
|
"5.2" : "2.4",
|
|
|
|
CHECK_AND_PRINT_I(VALID),
|
|
|
|
CHECK_AND_PRINT_I(IBSS),
|
|
|
|
CHECK_AND_PRINT_I(ACTIVE),
|
|
|
|
CHECK_AND_PRINT_I(RADAR),
|
|
|
|
CHECK_AND_PRINT_I(WIDE),
|
|
|
|
CHECK_AND_PRINT_I(DFS),
|
|
|
|
eeprom_ch_info[ch].flags,
|
|
|
|
eeprom_ch_info[ch].max_power_avg,
|
|
|
|
((eeprom_ch_info[ch].
|
|
|
|
flags & EEPROM_CHANNEL_IBSS)
|
|
|
|
&& !(eeprom_ch_info[ch].
|
|
|
|
flags & EEPROM_CHANNEL_RADAR))
|
|
|
|
? "" : "not ");
|
|
|
|
|
2009-01-20 07:30:29 +08:00
|
|
|
/* Set the tx_power_user_lmt to the highest power
|
2008-03-15 01:38:49 +08:00
|
|
|
* supported by any channel */
|
|
|
|
if (eeprom_ch_info[ch].max_power_avg >
|
2008-06-12 09:47:08 +08:00
|
|
|
priv->tx_power_user_lmt)
|
|
|
|
priv->tx_power_user_lmt =
|
2008-03-15 01:38:49 +08:00
|
|
|
eeprom_ch_info[ch].max_power_avg;
|
|
|
|
|
|
|
|
ch_info++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-08 06:41:38 +08:00
|
|
|
/* Check if we do have HT40 channels */
|
2009-02-11 07:19:04 +08:00
|
|
|
if (priv->cfg->ops->lib->eeprom_ops.regulatory_bands[5] ==
|
2009-08-08 06:41:38 +08:00
|
|
|
EEPROM_REGULATORY_BAND_NO_HT40 &&
|
2009-02-11 07:19:04 +08:00
|
|
|
priv->cfg->ops->lib->eeprom_ops.regulatory_bands[6] ==
|
2009-08-08 06:41:38 +08:00
|
|
|
EEPROM_REGULATORY_BAND_NO_HT40)
|
2009-01-24 05:45:15 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-08-08 06:41:38 +08:00
|
|
|
/* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
|
2008-03-15 01:38:49 +08:00
|
|
|
for (band = 6; band <= 7; band++) {
|
|
|
|
enum ieee80211_band ieeeband;
|
|
|
|
|
|
|
|
iwl_init_band_reference(priv, band, &eeprom_ch_count,
|
|
|
|
&eeprom_ch_info, &eeprom_ch_index);
|
|
|
|
|
|
|
|
/* EEPROM band 6 is 2.4, band 7 is 5 GHz */
|
|
|
|
ieeeband =
|
|
|
|
(band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
|
|
|
|
|
|
|
|
/* Loop through each band adding each of the channels */
|
|
|
|
for (ch = 0; ch < eeprom_ch_count; ch++) {
|
|
|
|
/* Set up driver's info for lower half */
|
2009-08-14 04:30:53 +08:00
|
|
|
iwl_mod_ht40_chan_info(priv, ieeeband,
|
2008-05-15 13:54:15 +08:00
|
|
|
eeprom_ch_index[ch],
|
2009-08-14 04:30:53 +08:00
|
|
|
&eeprom_ch_info[ch],
|
|
|
|
IEEE80211_CHAN_NO_HT40PLUS);
|
2008-03-15 01:38:49 +08:00
|
|
|
|
|
|
|
/* Set up driver's info for upper half */
|
2009-08-14 04:30:53 +08:00
|
|
|
iwl_mod_ht40_chan_info(priv, ieeeband,
|
|
|
|
eeprom_ch_index[ch] + 4,
|
|
|
|
&eeprom_ch_info[ch],
|
|
|
|
IEEE80211_CHAN_NO_HT40MINUS);
|
2008-03-15 01:38:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-22 04:34:23 +08:00
|
|
|
/* for newer device (6000 series and up)
|
|
|
|
* EEPROM contain enhanced tx power information
|
|
|
|
* driver need to process addition information
|
|
|
|
* to determine the max channel tx power limits
|
|
|
|
*/
|
|
|
|
if (priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower)
|
|
|
|
priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower(priv);
|
|
|
|
|
2008-03-15 01:38:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-05-15 13:54:15 +08:00
|
|
|
* iwl_free_channel_map - undo allocations in iwl_init_channel_map
|
2008-03-15 01:38:49 +08:00
|
|
|
*/
|
|
|
|
void iwl_free_channel_map(struct iwl_priv *priv)
|
|
|
|
{
|
|
|
|
kfree(priv->channel_info);
|
|
|
|
priv->channel_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iwl_get_channel_info - Find driver's private channel info
|
|
|
|
*
|
|
|
|
* Based on band and channel number.
|
|
|
|
*/
|
2008-05-29 16:35:28 +08:00
|
|
|
const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
|
|
|
|
enum ieee80211_band band, u16 channel)
|
2008-03-15 01:38:49 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (band) {
|
|
|
|
case IEEE80211_BAND_5GHZ:
|
|
|
|
for (i = 14; i < priv->channel_count; i++) {
|
|
|
|
if (priv->channel_info[i].channel == channel)
|
|
|
|
return &priv->channel_info[i];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE80211_BAND_2GHZ:
|
|
|
|
if (channel >= 1 && channel <= 14)
|
|
|
|
return &priv->channel_info[channel - 1];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|