Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Wey-Yi Guy | 4e31826 | 2011-12-27 11:21:32 -0800 | [diff] [blame] | 8 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
| 25 | * in the file called LICENSE.GPL. |
| 26 | * |
| 27 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
Wey-Yi Guy | 4e31826 | 2011-12-27 11:21:32 -0800 | [diff] [blame] | 33 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | *****************************************************************************/ |
| 62 | |
| 63 | |
| 64 | #include <linux/kernel.h> |
| 65 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 66 | #include <linux/slab.h> |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 67 | #include <linux/init.h> |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 68 | #include <net/mac80211.h> |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 69 | #include "iwl-io.h" |
Johannes Berg | eae63b8 | 2012-03-06 13:31:06 -0800 | [diff] [blame] | 70 | #include "iwl-prph.h" |
Johannes Berg | 1023fdc | 2012-05-15 12:16:34 +0200 | [diff] [blame] | 71 | #include "iwl-debug.h" |
| 72 | #include "dev.h" |
| 73 | #include "agn.h" |
| 74 | #include "eeprom.h" |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 75 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 76 | /************************** EEPROM BANDS **************************** |
| 77 | * |
| 78 | * The iwl_eeprom_band definitions below provide the mapping from the |
| 79 | * EEPROM contents to the specific channel number supported for each |
| 80 | * band. |
| 81 | * |
| 82 | * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3 |
| 83 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 84 | * The specific geography and calibration information for that channel |
| 85 | * is contained in the eeprom map itself. |
| 86 | * |
| 87 | * During init, we copy the eeprom information and channel map |
| 88 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 89 | * |
| 90 | * channel_map_24/52 provides the index in the channel_info array for a |
| 91 | * given channel. We have to have two separate maps as there is channel |
| 92 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 93 | * band_2 |
| 94 | * |
| 95 | * A value of 0xff stored in the channel_map indicates that the channel |
| 96 | * is not supported by the hardware at all. |
| 97 | * |
| 98 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 99 | * valid for Tx with the current hardware. This means that |
| 100 | * while the system can tune and receive on a given channel, it may not |
| 101 | * be able to associate or transmit any frames on that |
| 102 | * channel. There is no corresponding channel information for that |
| 103 | * entry. |
| 104 | * |
| 105 | *********************************************************************/ |
| 106 | |
| 107 | /* 2.4 GHz */ |
| 108 | const u8 iwl_eeprom_band_1[14] = { |
| 109 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 110 | }; |
| 111 | |
| 112 | /* 5.2 GHz bands */ |
| 113 | static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */ |
| 114 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 115 | }; |
| 116 | |
| 117 | static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */ |
| 118 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 119 | }; |
| 120 | |
| 121 | static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */ |
| 122 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 123 | }; |
| 124 | |
| 125 | static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */ |
| 126 | 145, 149, 153, 157, 161, 165 |
| 127 | }; |
| 128 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 129 | static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 130 | 1, 2, 3, 4, 5, 6, 7 |
| 131 | }; |
| 132 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 133 | static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 134 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 135 | }; |
| 136 | |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 137 | /****************************************************************************** |
| 138 | * |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 139 | * generic NVM functions |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 140 | * |
| 141 | ******************************************************************************/ |
| 142 | |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 143 | /* |
| 144 | * The device's EEPROM semaphore prevents conflicts between driver and uCode |
| 145 | * when accessing the EEPROM; each access is a series of pulses to/from the |
| 146 | * EEPROM chip, not a single event, so even reads could conflict if they |
| 147 | * weren't arbitrated by the semaphore. |
| 148 | */ |
Emmanuel Grumbach | 9030474 | 2012-02-13 11:17:57 +0200 | [diff] [blame] | 149 | |
| 150 | #define EEPROM_SEM_TIMEOUT 10 /* milliseconds */ |
| 151 | #define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */ |
| 152 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 153 | static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans) |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 154 | { |
| 155 | u16 count; |
| 156 | int ret; |
| 157 | |
| 158 | for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) { |
| 159 | /* Request semaphore */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 160 | iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 161 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 162 | |
| 163 | /* See if we got it */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 164 | ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG, |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 165 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, |
| 166 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, |
| 167 | EEPROM_SEM_TIMEOUT); |
| 168 | if (ret >= 0) { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 169 | IWL_DEBUG_EEPROM(trans, |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 170 | "Acquired semaphore after %d tries.\n", |
| 171 | count+1); |
| 172 | return ret; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | return ret; |
| 177 | } |
| 178 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 179 | static void iwl_eeprom_release_semaphore(struct iwl_trans *trans) |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 180 | { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 181 | iwl_clear_bit(trans, CSR_HW_IF_CONFIG_REG, |
Don Fry | 16b80b7 | 2011-04-20 15:25:14 -0700 | [diff] [blame] | 182 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 183 | |
| 184 | } |
| 185 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 186 | static int iwl_eeprom_verify_signature(struct iwl_priv *priv) |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 187 | { |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 188 | u32 gp = iwl_read32(priv->trans, CSR_EEPROM_GP) & |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 189 | CSR_EEPROM_GP_VALID_MSK; |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 190 | int ret = 0; |
| 191 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 192 | IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp); |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 193 | switch (gp) { |
| 194 | case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP: |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 195 | if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) { |
| 196 | IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n", |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 197 | gp); |
| 198 | ret = -ENOENT; |
| 199 | } |
| 200 | break; |
| 201 | case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K: |
| 202 | case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K: |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 203 | if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) { |
| 204 | IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp); |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 205 | ret = -ENOENT; |
| 206 | } |
| 207 | break; |
| 208 | case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP: |
| 209 | default: |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 210 | IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, " |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 211 | "EEPROM_GP=0x%08x\n", |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 212 | (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 213 | ? "OTP" : "EEPROM", gp); |
| 214 | ret = -ENOENT; |
| 215 | break; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 216 | } |
Wey-Yi Guy | f41bb89 | 2009-10-02 13:44:06 -0700 | [diff] [blame] | 217 | return ret; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 218 | } |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 219 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 220 | u16 iwl_eeprom_query16(struct iwl_priv *priv, size_t offset) |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 221 | { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 222 | if (!priv->eeprom) |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 223 | return 0; |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 224 | return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8); |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | int iwl_eeprom_check_version(struct iwl_priv *priv) |
| 228 | { |
| 229 | u16 eeprom_ver; |
| 230 | u16 calib_ver; |
| 231 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 232 | eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); |
| 233 | calib_ver = iwl_eeprom_calib_version(priv); |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 234 | |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 235 | if (eeprom_ver < priv->cfg->eeprom_ver || |
| 236 | calib_ver < priv->cfg->eeprom_calib_ver) |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 237 | goto err; |
| 238 | |
| 239 | IWL_INFO(priv, "device EEPROM VER=0x%x, CALIB=0x%x\n", |
| 240 | eeprom_ver, calib_ver); |
| 241 | |
| 242 | return 0; |
| 243 | err: |
| 244 | IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x " |
| 245 | "CALIB=0x%x < 0x%x\n", |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 246 | eeprom_ver, priv->cfg->eeprom_ver, |
| 247 | calib_ver, priv->cfg->eeprom_calib_ver); |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | |
| 250 | } |
| 251 | |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 252 | int iwl_eeprom_init_hw_params(struct iwl_priv *priv) |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 253 | { |
| 254 | u16 radio_cfg; |
| 255 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 256 | priv->hw_params.sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP); |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 257 | if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE && |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 258 | !priv->cfg->ht_params) { |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 259 | IWL_ERR(priv, "Invalid 11n configuration\n"); |
| 260 | return -EINVAL; |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 261 | } |
Johannes Berg | 54708d8 | 2012-03-05 11:24:31 -0800 | [diff] [blame] | 262 | |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 263 | if (!priv->hw_params.sku) { |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 264 | IWL_ERR(priv, "Invalid device sku\n"); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 268 | IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku); |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 269 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 270 | radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG); |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 271 | |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 272 | priv->hw_params.valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg); |
| 273 | priv->hw_params.valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg); |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 274 | |
| 275 | /* check overrides (some devices have wrong EEPROM) */ |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 276 | if (priv->cfg->valid_tx_ant) |
| 277 | priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant; |
| 278 | if (priv->cfg->valid_rx_ant) |
| 279 | priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant; |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 280 | |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 281 | if (!priv->hw_params.valid_tx_ant || !priv->hw_params.valid_rx_ant) { |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 282 | IWL_ERR(priv, "Invalid chain (0x%X, 0x%X)\n", |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 283 | priv->hw_params.valid_tx_ant, |
| 284 | priv->hw_params.valid_rx_ant); |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 285 | return -EINVAL; |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 286 | } |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 287 | |
Johannes Berg | 2587d36 | 2012-05-21 20:18:19 +0200 | [diff] [blame] | 288 | priv->hw_params.tx_chains_num = |
| 289 | num_of_ant(priv->hw_params.valid_tx_ant); |
| 290 | if (priv->cfg->rx_with_siso_diversity) |
| 291 | priv->hw_params.rx_chains_num = 1; |
| 292 | else |
| 293 | priv->hw_params.rx_chains_num = |
| 294 | num_of_ant(priv->hw_params.valid_rx_ant); |
| 295 | |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 296 | IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n", |
Johannes Berg | 9e29511 | 2012-04-09 17:46:55 -0700 | [diff] [blame] | 297 | priv->hw_params.valid_tx_ant, priv->hw_params.valid_rx_ant); |
Johannes Berg | 7e79a39 | 2012-03-05 11:24:32 -0800 | [diff] [blame] | 298 | |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 302 | u16 iwl_eeprom_calib_version(struct iwl_priv *priv) |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 303 | { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 304 | struct iwl_eeprom_calib_hdr *hdr; |
| 305 | |
| 306 | hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv, |
| 307 | EEPROM_CALIB_ALL); |
| 308 | return hdr->version; |
| 309 | } |
| 310 | |
| 311 | static u32 eeprom_indirect_address(struct iwl_priv *priv, u32 address) |
| 312 | { |
| 313 | u16 offset = 0; |
| 314 | |
| 315 | if ((address & INDIRECT_ADDRESS) == 0) |
| 316 | return address; |
| 317 | |
| 318 | switch (address & INDIRECT_TYPE_MSK) { |
| 319 | case INDIRECT_HOST: |
| 320 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST); |
| 321 | break; |
| 322 | case INDIRECT_GENERAL: |
| 323 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL); |
| 324 | break; |
| 325 | case INDIRECT_REGULATORY: |
| 326 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY); |
| 327 | break; |
| 328 | case INDIRECT_TXP_LIMIT: |
| 329 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT); |
| 330 | break; |
| 331 | case INDIRECT_TXP_LIMIT_SIZE: |
| 332 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE); |
| 333 | break; |
| 334 | case INDIRECT_CALIBRATION: |
| 335 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION); |
| 336 | break; |
| 337 | case INDIRECT_PROCESS_ADJST: |
| 338 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST); |
| 339 | break; |
| 340 | case INDIRECT_OTHERS: |
| 341 | offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS); |
| 342 | break; |
| 343 | default: |
| 344 | IWL_ERR(priv, "illegal indirect type: 0x%X\n", |
| 345 | address & INDIRECT_TYPE_MSK); |
| 346 | break; |
| 347 | } |
| 348 | |
| 349 | /* translate the offset from words to byte */ |
| 350 | return (address & ADDRESS_MSK) + (offset << 1); |
| 351 | } |
| 352 | |
| 353 | const u8 *iwl_eeprom_query_addr(struct iwl_priv *priv, size_t offset) |
| 354 | { |
| 355 | u32 address = eeprom_indirect_address(priv, offset); |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 356 | BUG_ON(address >= priv->cfg->base_params->eeprom_size); |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 357 | return &priv->eeprom[address]; |
| 358 | } |
| 359 | |
| 360 | void iwl_eeprom_get_mac(struct iwl_priv *priv, u8 *mac) |
| 361 | { |
| 362 | const u8 *addr = iwl_eeprom_query_addr(priv, |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 363 | EEPROM_MAC_ADDRESS); |
| 364 | memcpy(mac, addr, ETH_ALEN); |
| 365 | } |
| 366 | |
| 367 | /****************************************************************************** |
| 368 | * |
| 369 | * OTP related functions |
| 370 | * |
| 371 | ******************************************************************************/ |
| 372 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 373 | static void iwl_set_otp_access(struct iwl_trans *trans, |
| 374 | enum iwl_access_mode mode) |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 375 | { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 376 | iwl_read32(trans, CSR_OTP_GP_REG); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 377 | |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 378 | if (mode == IWL_OTP_ACCESS_ABSOLUTE) |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 379 | iwl_clear_bit(trans, CSR_OTP_GP_REG, |
Johannes Berg | 70817b5 | 2011-05-11 03:29:25 -0700 | [diff] [blame] | 380 | CSR_OTP_GP_REG_OTP_ACCESS_MODE); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 381 | else |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 382 | iwl_set_bit(trans, CSR_OTP_GP_REG, |
Johannes Berg | 70817b5 | 2011-05-11 03:29:25 -0700 | [diff] [blame] | 383 | CSR_OTP_GP_REG_OTP_ACCESS_MODE); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 386 | static int iwl_get_nvm_type(struct iwl_trans *trans, u32 hw_rev) |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 387 | { |
| 388 | u32 otpgp; |
| 389 | int nvm_type; |
| 390 | |
| 391 | /* OTP only valid for CP/PP and after */ |
Johannes Berg | e98a130 | 2011-04-05 09:42:08 -0700 | [diff] [blame] | 392 | switch (hw_rev & CSR_HW_REV_TYPE_MSK) { |
Wey-Yi Guy | b23a052 | 2009-07-17 09:30:21 -0700 | [diff] [blame] | 393 | case CSR_HW_REV_TYPE_NONE: |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 394 | IWL_ERR(trans, "Unknown hardware type\n"); |
Wey-Yi Guy | b23a052 | 2009-07-17 09:30:21 -0700 | [diff] [blame] | 395 | return -ENOENT; |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 396 | case CSR_HW_REV_TYPE_5300: |
| 397 | case CSR_HW_REV_TYPE_5350: |
| 398 | case CSR_HW_REV_TYPE_5100: |
| 399 | case CSR_HW_REV_TYPE_5150: |
| 400 | nvm_type = NVM_DEVICE_TYPE_EEPROM; |
| 401 | break; |
| 402 | default: |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 403 | otpgp = iwl_read32(trans, CSR_OTP_GP_REG); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 404 | if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT) |
| 405 | nvm_type = NVM_DEVICE_TYPE_OTP; |
| 406 | else |
| 407 | nvm_type = NVM_DEVICE_TYPE_EEPROM; |
| 408 | break; |
| 409 | } |
| 410 | return nvm_type; |
| 411 | } |
| 412 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 413 | static int iwl_init_otp_access(struct iwl_trans *trans) |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 414 | { |
| 415 | int ret; |
| 416 | |
| 417 | /* Enable 40MHz radio clock */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 418 | iwl_write32(trans, CSR_GP_CNTRL, |
| 419 | iwl_read32(trans, CSR_GP_CNTRL) | |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 420 | CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 421 | |
| 422 | /* wait for clock to be ready */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 423 | ret = iwl_poll_bit(trans, CSR_GP_CNTRL, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 424 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 425 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 426 | 25000); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 427 | if (ret < 0) |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 428 | IWL_ERR(trans, "Time out access OTP\n"); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 429 | else { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 430 | iwl_set_bits_prph(trans, APMG_PS_CTRL_REG, |
Reinette Chatre | d77b034 | 2009-05-22 14:37:55 -0700 | [diff] [blame] | 431 | APMG_PS_CTRL_VAL_RESET_REQ); |
| 432 | udelay(5); |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 433 | iwl_clear_bits_prph(trans, APMG_PS_CTRL_REG, |
Reinette Chatre | d77b034 | 2009-05-22 14:37:55 -0700 | [diff] [blame] | 434 | APMG_PS_CTRL_VAL_RESET_REQ); |
Wey-Yi Guy | 32004ee | 2009-10-16 14:25:56 -0700 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * CSR auto clock gate disable bit - |
| 438 | * this is only applicable for HW with OTP shadow RAM |
| 439 | */ |
Emmanuel Grumbach | 035f7ff | 2012-03-26 08:57:01 -0700 | [diff] [blame] | 440 | if (trans->cfg->base_params->shadow_ram_support) |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 441 | iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG, |
Wey-Yi Guy | 32004ee | 2009-10-16 14:25:56 -0700 | [diff] [blame] | 442 | CSR_RESET_LINK_PWR_MGMT_DISABLED); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 443 | } |
| 444 | return ret; |
| 445 | } |
| 446 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 447 | static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr, |
| 448 | __le16 *eeprom_data) |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 449 | { |
| 450 | int ret = 0; |
| 451 | u32 r; |
| 452 | u32 otpgp; |
| 453 | |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 454 | iwl_write32(trans, CSR_EEPROM_REG, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 455 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 456 | ret = iwl_poll_bit(trans, CSR_EEPROM_REG, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 457 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 458 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 459 | IWL_EEPROM_ACCESS_TIMEOUT); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 460 | if (ret < 0) { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 461 | IWL_ERR(trans, "Time out reading OTP[%d]\n", addr); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 462 | return ret; |
| 463 | } |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 464 | r = iwl_read32(trans, CSR_EEPROM_REG); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 465 | /* check for ECC errors: */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 466 | otpgp = iwl_read32(trans, CSR_OTP_GP_REG); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 467 | if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) { |
| 468 | /* stop in this case */ |
| 469 | /* set the uncorrectable OTP ECC bit for acknowledgement */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 470 | iwl_set_bit(trans, CSR_OTP_GP_REG, |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 471 | CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 472 | IWL_ERR(trans, "Uncorrectable OTP ECC error, abort OTP read\n"); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 473 | return -EINVAL; |
| 474 | } |
| 475 | if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) { |
| 476 | /* continue in this case */ |
| 477 | /* set the correctable OTP ECC bit for acknowledgement */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 478 | iwl_set_bit(trans, CSR_OTP_GP_REG, |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 479 | CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK); |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 480 | IWL_ERR(trans, "Correctable OTP ECC error, continue read\n"); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 481 | } |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 482 | *eeprom_data = cpu_to_le16(r >> 16); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | /* |
| 487 | * iwl_is_otp_empty: check for empty OTP |
| 488 | */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 489 | static bool iwl_is_otp_empty(struct iwl_trans *trans) |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 490 | { |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 491 | u16 next_link_addr = 0; |
| 492 | __le16 link_value; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 493 | bool is_empty = false; |
| 494 | |
| 495 | /* locate the beginning of OTP link list */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 496 | if (!iwl_read_otp_word(trans, next_link_addr, &link_value)) { |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 497 | if (!link_value) { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 498 | IWL_ERR(trans, "OTP is empty\n"); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 499 | is_empty = true; |
| 500 | } |
| 501 | } else { |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 502 | IWL_ERR(trans, "Unable to read first block of OTP list.\n"); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 503 | is_empty = true; |
| 504 | } |
| 505 | |
| 506 | return is_empty; |
| 507 | } |
| 508 | |
| 509 | |
| 510 | /* |
| 511 | * iwl_find_otp_image: find EEPROM image in OTP |
| 512 | * finding the OTP block that contains the EEPROM image. |
| 513 | * the last valid block on the link list (the block _before_ the last block) |
| 514 | * is the block we should read and used to configure the device. |
| 515 | * If all the available OTP blocks are full, the last block will be the block |
| 516 | * we should read and used to configure the device. |
| 517 | * only perform this operation if shadow RAM is disabled |
| 518 | */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 519 | static int iwl_find_otp_image(struct iwl_trans *trans, |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 520 | u16 *validblockaddr) |
| 521 | { |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 522 | u16 next_link_addr = 0, valid_addr; |
| 523 | __le16 link_value = 0; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 524 | int usedblocks = 0; |
| 525 | |
| 526 | /* set addressing mode to absolute to traverse the link list */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 527 | iwl_set_otp_access(trans, IWL_OTP_ACCESS_ABSOLUTE); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 528 | |
| 529 | /* checking for empty OTP or error */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 530 | if (iwl_is_otp_empty(trans)) |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 531 | return -EINVAL; |
| 532 | |
| 533 | /* |
| 534 | * start traverse link list |
| 535 | * until reach the max number of OTP blocks |
| 536 | * different devices have different number of OTP blocks |
| 537 | */ |
| 538 | do { |
| 539 | /* save current valid block address |
| 540 | * check for more block on the link list |
| 541 | */ |
| 542 | valid_addr = next_link_addr; |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 543 | next_link_addr = le16_to_cpu(link_value) * sizeof(u16); |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 544 | IWL_DEBUG_EEPROM(trans, "OTP blocks %d addr 0x%x\n", |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 545 | usedblocks, next_link_addr); |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 546 | if (iwl_read_otp_word(trans, next_link_addr, &link_value)) |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 547 | return -EINVAL; |
| 548 | if (!link_value) { |
| 549 | /* |
Jay Sternberg | 2facba7 | 2009-10-02 13:43:55 -0700 | [diff] [blame] | 550 | * reach the end of link list, return success and |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 551 | * set address point to the starting address |
| 552 | * of the image |
| 553 | */ |
Jay Sternberg | 2facba7 | 2009-10-02 13:43:55 -0700 | [diff] [blame] | 554 | *validblockaddr = valid_addr; |
| 555 | /* skip first 2 bytes (link list pointer) */ |
| 556 | *validblockaddr += 2; |
| 557 | return 0; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 558 | } |
| 559 | /* more in the link list, continue */ |
| 560 | usedblocks++; |
Emmanuel Grumbach | 035f7ff | 2012-03-26 08:57:01 -0700 | [diff] [blame] | 561 | } while (usedblocks <= trans->cfg->base_params->max_ll_items); |
Jay Sternberg | 2facba7 | 2009-10-02 13:43:55 -0700 | [diff] [blame] | 562 | |
| 563 | /* OTP has no valid blocks */ |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 564 | IWL_DEBUG_EEPROM(trans, "OTP has no valid blocks\n"); |
Jay Sternberg | 2facba7 | 2009-10-02 13:43:55 -0700 | [diff] [blame] | 565 | return -EINVAL; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 568 | /****************************************************************************** |
| 569 | * |
| 570 | * Tx Power related functions |
| 571 | * |
| 572 | ******************************************************************************/ |
| 573 | /** |
| 574 | * iwl_get_max_txpower_avg - get the highest tx power from all chains. |
| 575 | * find the highest tx power from all chains for the channel |
| 576 | */ |
Johannes Berg | 706c4ff | 2012-03-05 11:24:33 -0800 | [diff] [blame] | 577 | static s8 iwl_get_max_txpower_avg(const struct iwl_cfg *cfg, |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 578 | struct iwl_eeprom_enhanced_txpwr *enhanced_txpower, |
| 579 | int element, s8 *max_txpower_in_half_dbm) |
Wey-Yi Guy | 3be63ff | 2010-10-08 16:05:19 -0700 | [diff] [blame] | 580 | { |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 581 | s8 max_txpower_avg = 0; /* (dBm) */ |
| 582 | |
| 583 | /* Take the highest tx power from any valid chains */ |
Don Fry | 1431b21 | 2011-11-10 06:55:26 -0800 | [diff] [blame] | 584 | if ((cfg->valid_tx_ant & ANT_A) && |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 585 | (enhanced_txpower[element].chain_a_max > max_txpower_avg)) |
| 586 | max_txpower_avg = enhanced_txpower[element].chain_a_max; |
Don Fry | 1431b21 | 2011-11-10 06:55:26 -0800 | [diff] [blame] | 587 | if ((cfg->valid_tx_ant & ANT_B) && |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 588 | (enhanced_txpower[element].chain_b_max > max_txpower_avg)) |
| 589 | max_txpower_avg = enhanced_txpower[element].chain_b_max; |
Don Fry | 1431b21 | 2011-11-10 06:55:26 -0800 | [diff] [blame] | 590 | if ((cfg->valid_tx_ant & ANT_C) && |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 591 | (enhanced_txpower[element].chain_c_max > max_txpower_avg)) |
| 592 | max_txpower_avg = enhanced_txpower[element].chain_c_max; |
Don Fry | 1431b21 | 2011-11-10 06:55:26 -0800 | [diff] [blame] | 593 | if (((cfg->valid_tx_ant == ANT_AB) | |
| 594 | (cfg->valid_tx_ant == ANT_BC) | |
| 595 | (cfg->valid_tx_ant == ANT_AC)) && |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 596 | (enhanced_txpower[element].mimo2_max > max_txpower_avg)) |
| 597 | max_txpower_avg = enhanced_txpower[element].mimo2_max; |
Don Fry | 1431b21 | 2011-11-10 06:55:26 -0800 | [diff] [blame] | 598 | if ((cfg->valid_tx_ant == ANT_ABC) && |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 599 | (enhanced_txpower[element].mimo3_max > max_txpower_avg)) |
| 600 | max_txpower_avg = enhanced_txpower[element].mimo3_max; |
| 601 | |
| 602 | /* |
| 603 | * max. tx power in EEPROM is in 1/2 dBm format |
| 604 | * convert from 1/2 dBm to dBm (round-up convert) |
| 605 | * but we also do not want to loss 1/2 dBm resolution which |
| 606 | * will impact performance |
| 607 | */ |
| 608 | *max_txpower_in_half_dbm = max_txpower_avg; |
| 609 | return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1); |
| 610 | } |
| 611 | |
| 612 | static void |
| 613 | iwl_eeprom_enh_txp_read_element(struct iwl_priv *priv, |
| 614 | struct iwl_eeprom_enhanced_txpwr *txp, |
| 615 | s8 max_txpower_avg) |
| 616 | { |
| 617 | int ch_idx; |
| 618 | bool is_ht40 = txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ; |
| 619 | enum ieee80211_band band; |
| 620 | |
| 621 | band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ? |
| 622 | IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ; |
| 623 | |
| 624 | for (ch_idx = 0; ch_idx < priv->channel_count; ch_idx++) { |
| 625 | struct iwl_channel_info *ch_info = &priv->channel_info[ch_idx]; |
| 626 | |
| 627 | /* update matching channel or from common data only */ |
| 628 | if (txp->channel != 0 && ch_info->channel != txp->channel) |
| 629 | continue; |
| 630 | |
| 631 | /* update matching band only */ |
| 632 | if (band != ch_info->band) |
| 633 | continue; |
| 634 | |
| 635 | if (ch_info->max_power_avg < max_txpower_avg && !is_ht40) { |
| 636 | ch_info->max_power_avg = max_txpower_avg; |
| 637 | ch_info->curr_txpow = max_txpower_avg; |
| 638 | ch_info->scan_power = max_txpower_avg; |
| 639 | } |
| 640 | |
| 641 | if (is_ht40 && ch_info->ht40_max_power_avg < max_txpower_avg) |
| 642 | ch_info->ht40_max_power_avg = max_txpower_avg; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | #define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT) |
| 647 | #define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr) |
| 648 | #define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE) |
| 649 | |
| 650 | #define TXP_CHECK_AND_PRINT(x) ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) \ |
| 651 | ? # x " " : "") |
| 652 | |
Johannes Berg | 51dc51d | 2012-03-07 09:52:20 -0800 | [diff] [blame] | 653 | static void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv) |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 654 | { |
| 655 | struct iwl_eeprom_enhanced_txpwr *txp_array, *txp; |
| 656 | int idx, entries; |
| 657 | __le16 *txp_len; |
| 658 | s8 max_txp_avg, max_txp_avg_halfdbm; |
| 659 | |
| 660 | BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8); |
| 661 | |
| 662 | /* the length is in 16-bit words, but we want entries */ |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 663 | txp_len = (__le16 *) iwl_eeprom_query_addr(priv, EEPROM_TXP_SZ_OFFS); |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 664 | entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN; |
| 665 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 666 | txp_array = (void *) iwl_eeprom_query_addr(priv, EEPROM_TXP_OFFS); |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 667 | |
| 668 | for (idx = 0; idx < entries; idx++) { |
| 669 | txp = &txp_array[idx]; |
| 670 | /* skip invalid entries */ |
| 671 | if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID)) |
| 672 | continue; |
| 673 | |
| 674 | IWL_DEBUG_EEPROM(priv, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n", |
| 675 | (txp->channel && (txp->flags & |
| 676 | IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ? |
| 677 | "Common " : (txp->channel) ? |
| 678 | "Channel" : "Common", |
| 679 | (txp->channel), |
| 680 | TXP_CHECK_AND_PRINT(VALID), |
| 681 | TXP_CHECK_AND_PRINT(BAND_52G), |
| 682 | TXP_CHECK_AND_PRINT(OFDM), |
| 683 | TXP_CHECK_AND_PRINT(40MHZ), |
| 684 | TXP_CHECK_AND_PRINT(HT_AP), |
| 685 | TXP_CHECK_AND_PRINT(RES1), |
| 686 | TXP_CHECK_AND_PRINT(RES2), |
| 687 | TXP_CHECK_AND_PRINT(COMMON_TYPE), |
| 688 | txp->flags); |
| 689 | IWL_DEBUG_EEPROM(priv, "\t\t chain_A: 0x%02x " |
| 690 | "chain_B: 0X%02x chain_C: 0X%02x\n", |
| 691 | txp->chain_a_max, txp->chain_b_max, |
| 692 | txp->chain_c_max); |
| 693 | IWL_DEBUG_EEPROM(priv, "\t\t MIMO2: 0x%02x " |
| 694 | "MIMO3: 0x%02x High 20_on_40: 0x%02x " |
| 695 | "Low 20_on_40: 0x%02x\n", |
| 696 | txp->mimo2_max, txp->mimo3_max, |
| 697 | ((txp->delta_20_in_40 & 0xf0) >> 4), |
| 698 | (txp->delta_20_in_40 & 0x0f)); |
| 699 | |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 700 | max_txp_avg = iwl_get_max_txpower_avg(priv->cfg, txp_array, idx, |
Wey-Yi Guy | 701cb09 | 2011-09-15 11:46:41 -0700 | [diff] [blame] | 701 | &max_txp_avg_halfdbm); |
| 702 | |
| 703 | /* |
| 704 | * Update the user limit values values to the highest |
| 705 | * power supported by any channel |
| 706 | */ |
| 707 | if (max_txp_avg > priv->tx_power_user_lmt) |
| 708 | priv->tx_power_user_lmt = max_txp_avg; |
| 709 | if (max_txp_avg_halfdbm > priv->tx_power_lmt_in_half_dbm) |
| 710 | priv->tx_power_lmt_in_half_dbm = max_txp_avg_halfdbm; |
| 711 | |
| 712 | iwl_eeprom_enh_txp_read_element(priv, txp, max_txp_avg); |
| 713 | } |
Wey-Yi Guy | 3be63ff | 2010-10-08 16:05:19 -0700 | [diff] [blame] | 714 | } |
Wey-Yi Guy | 3be63ff | 2010-10-08 16:05:19 -0700 | [diff] [blame] | 715 | |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 716 | /** |
| 717 | * iwl_eeprom_init - read EEPROM contents |
| 718 | * |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 719 | * Load the EEPROM contents from adapter into priv->eeprom |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 720 | * |
| 721 | * NOTE: This routine uses the non-debug IO access functions. |
| 722 | */ |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 723 | int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev) |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 724 | { |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 725 | __le16 *e; |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 726 | u32 gp = iwl_read32(priv->trans, CSR_EEPROM_GP); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 727 | int sz; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 728 | int ret; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 729 | u16 addr; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 730 | u16 validblockaddr = 0; |
| 731 | u16 cache_addr = 0; |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 732 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 733 | priv->nvm_device_type = iwl_get_nvm_type(priv->trans, hw_rev); |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 734 | if (priv->nvm_device_type == -ENOENT) |
Wey-Yi Guy | b23a052 | 2009-07-17 09:30:21 -0700 | [diff] [blame] | 735 | return -ENOENT; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 736 | /* allocate eeprom */ |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 737 | sz = priv->cfg->base_params->eeprom_size; |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 738 | IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz); |
| 739 | priv->eeprom = kzalloc(sz, GFP_KERNEL); |
| 740 | if (!priv->eeprom) { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 741 | ret = -ENOMEM; |
| 742 | goto alloc_err; |
| 743 | } |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 744 | e = (__le16 *)priv->eeprom; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 745 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 746 | ret = iwl_eeprom_verify_signature(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 747 | if (ret < 0) { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 748 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 749 | ret = -ENOENT; |
| 750 | goto err; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 754 | ret = iwl_eeprom_acquire_semaphore(priv->trans); |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 755 | if (ret < 0) { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 756 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 757 | ret = -ENOENT; |
| 758 | goto err; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 759 | } |
Ben Cahill | 8852136 | 2009-10-30 14:36:06 -0700 | [diff] [blame] | 760 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 761 | if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) { |
Ben Cahill | 8852136 | 2009-10-30 14:36:06 -0700 | [diff] [blame] | 762 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 763 | ret = iwl_init_otp_access(priv->trans); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 764 | if (ret) { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 765 | IWL_ERR(priv, "Failed to initialize OTP access.\n"); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 766 | ret = -ENOENT; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 767 | goto done; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 768 | } |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 769 | iwl_write32(priv->trans, CSR_EEPROM_GP, |
| 770 | iwl_read32(priv->trans, CSR_EEPROM_GP) & |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 771 | ~CSR_EEPROM_GP_IF_OWNER_MSK); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 772 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 773 | iwl_set_bit(priv->trans, CSR_OTP_GP_REG, |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 774 | CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK | |
| 775 | CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 776 | /* traversing the linked list if no shadow ram supported */ |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 777 | if (!priv->cfg->base_params->shadow_ram_support) { |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 778 | if (iwl_find_otp_image(priv->trans, &validblockaddr)) { |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 779 | ret = -ENOENT; |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 780 | goto done; |
| 781 | } |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 782 | } |
| 783 | for (addr = validblockaddr; addr < validblockaddr + sz; |
| 784 | addr += sizeof(u16)) { |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 785 | __le16 eeprom_data; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 786 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 787 | ret = iwl_read_otp_word(priv->trans, addr, |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 788 | &eeprom_data); |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 789 | if (ret) |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 790 | goto done; |
Wey-Yi Guy | 415e499 | 2009-08-13 13:30:54 -0700 | [diff] [blame] | 791 | e[cache_addr / 2] = eeprom_data; |
| 792 | cache_addr += sizeof(u16); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 793 | } |
| 794 | } else { |
| 795 | /* eeprom is an array of 16bit values */ |
| 796 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
| 797 | u32 r; |
| 798 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 799 | iwl_write32(priv->trans, CSR_EEPROM_REG, |
Johannes Berg | 02a7fa0 | 2011-04-05 09:42:12 -0700 | [diff] [blame] | 800 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 801 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 802 | ret = iwl_poll_bit(priv->trans, CSR_EEPROM_REG, |
Abhijeet Kolekar | 1739d33 | 2009-10-02 13:44:05 -0700 | [diff] [blame] | 803 | CSR_EEPROM_REG_READ_VALID_MSK, |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 804 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 805 | IWL_EEPROM_ACCESS_TIMEOUT); |
| 806 | if (ret < 0) { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 807 | IWL_ERR(priv, |
Emmanuel Grumbach | ca77d53 | 2012-02-13 11:24:47 +0200 | [diff] [blame] | 808 | "Time out reading EEPROM[%d]\n", addr); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 809 | goto done; |
| 810 | } |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 811 | r = iwl_read32(priv->trans, CSR_EEPROM_REG); |
Johannes Berg | af6b8ee | 2009-12-14 14:12:08 -0800 | [diff] [blame] | 812 | e[addr / 2] = cpu_to_le16(r >> 16); |
Wey-Yi Guy | 0848e29 | 2009-05-22 11:01:46 -0700 | [diff] [blame] | 813 | } |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 814 | } |
Johannes Berg | d1358f6 | 2010-04-28 12:09:15 -0700 | [diff] [blame] | 815 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 816 | IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n", |
| 817 | (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) |
Johannes Berg | d1358f6 | 2010-04-28 12:09:15 -0700 | [diff] [blame] | 818 | ? "OTP" : "EEPROM", |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 819 | iwl_eeprom_query16(priv, EEPROM_VERSION)); |
Johannes Berg | d1358f6 | 2010-04-28 12:09:15 -0700 | [diff] [blame] | 820 | |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 821 | ret = 0; |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 822 | done: |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 823 | iwl_eeprom_release_semaphore(priv->trans); |
Johannes Berg | d1358f6 | 2010-04-28 12:09:15 -0700 | [diff] [blame] | 824 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 825 | err: |
| 826 | if (ret) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 827 | iwl_eeprom_free(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 828 | alloc_err: |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 829 | return ret; |
| 830 | } |
Assaf Krauss | 34cf6ff | 2008-03-06 10:40:20 -0800 | [diff] [blame] | 831 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 832 | void iwl_eeprom_free(struct iwl_priv *priv) |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 833 | { |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 834 | kfree(priv->eeprom); |
| 835 | priv->eeprom = NULL; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 836 | } |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 837 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 838 | static void iwl_init_band_reference(struct iwl_priv *priv, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 839 | int eep_band, int *eeprom_ch_count, |
| 840 | const struct iwl_eeprom_channel **eeprom_ch_info, |
| 841 | const u8 **eeprom_ch_index) |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 842 | { |
Johannes Berg | e967669 | 2012-04-10 14:10:28 -0700 | [diff] [blame] | 843 | u32 offset = priv->lib-> |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 844 | eeprom_ops.regulatory_bands[eep_band - 1]; |
| 845 | switch (eep_band) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 846 | case 1: /* 2.4GHz band */ |
| 847 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 848 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 849 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 850 | *eeprom_ch_index = iwl_eeprom_band_1; |
| 851 | break; |
| 852 | case 2: /* 4.9GHz band */ |
| 853 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 854 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 855 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 856 | *eeprom_ch_index = iwl_eeprom_band_2; |
| 857 | break; |
| 858 | case 3: /* 5.2GHz band */ |
| 859 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 860 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 861 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 862 | *eeprom_ch_index = iwl_eeprom_band_3; |
| 863 | break; |
| 864 | case 4: /* 5.5GHz band */ |
| 865 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 866 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 867 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 868 | *eeprom_ch_index = iwl_eeprom_band_4; |
| 869 | break; |
| 870 | case 5: /* 5.7GHz band */ |
| 871 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 872 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 873 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 874 | *eeprom_ch_index = iwl_eeprom_band_5; |
| 875 | break; |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 876 | case 6: /* 2.4GHz ht40 channels */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 877 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 878 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 879 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 880 | *eeprom_ch_index = iwl_eeprom_band_6; |
| 881 | break; |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 882 | case 7: /* 5 GHz ht40 channels */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 883 | *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 884 | *eeprom_ch_info = (struct iwl_eeprom_channel *) |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 885 | iwl_eeprom_query_addr(priv, offset); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 886 | *eeprom_ch_index = iwl_eeprom_band_7; |
| 887 | break; |
| 888 | default: |
| 889 | BUG(); |
| 890 | return; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \ |
| 895 | ? # x " " : "") |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 896 | /** |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 897 | * iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv. |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 898 | * |
| 899 | * Does not set up a command, or touch hardware. |
| 900 | */ |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 901 | static int iwl_mod_ht40_chan_info(struct iwl_priv *priv, |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 902 | enum ieee80211_band band, u16 channel, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 903 | const struct iwl_eeprom_channel *eeprom_ch, |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 904 | u8 clear_ht40_extension_channel) |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 905 | { |
| 906 | struct iwl_channel_info *ch_info; |
| 907 | |
| 908 | ch_info = (struct iwl_channel_info *) |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 909 | iwl_get_channel_info(priv, band, channel); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 910 | |
| 911 | if (!is_channel_valid(ch_info)) |
| 912 | return -1; |
| 913 | |
Wey-Yi Guy | d058ff8 | 2010-12-03 10:33:35 -0800 | [diff] [blame] | 914 | IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):" |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 915 | " Ad-Hoc %ssupported\n", |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 916 | ch_info->channel, |
| 917 | is_channel_a_band(ch_info) ? |
| 918 | "5.2" : "2.4", |
| 919 | CHECK_AND_PRINT(IBSS), |
| 920 | CHECK_AND_PRINT(ACTIVE), |
| 921 | CHECK_AND_PRINT(RADAR), |
| 922 | CHECK_AND_PRINT(WIDE), |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 923 | CHECK_AND_PRINT(DFS), |
| 924 | eeprom_ch->flags, |
| 925 | eeprom_ch->max_power_avg, |
| 926 | ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS) |
| 927 | && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ? |
| 928 | "" : "not "); |
| 929 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 930 | ch_info->ht40_eeprom = *eeprom_ch; |
| 931 | ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg; |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 932 | ch_info->ht40_flags = eeprom_ch->flags; |
Reinette Chatre | 6c3069b | 2009-12-14 14:12:13 -0800 | [diff] [blame] | 933 | if (eeprom_ch->flags & EEPROM_CHANNEL_VALID) |
| 934 | ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 940 | ? # x " " : "") |
| 941 | |
| 942 | /** |
| 943 | * iwl_init_channel_map - Set up driver's info for all possible channels |
| 944 | */ |
| 945 | int iwl_init_channel_map(struct iwl_priv *priv) |
| 946 | { |
| 947 | int eeprom_ch_count = 0; |
| 948 | const u8 *eeprom_ch_index = NULL; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 949 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 950 | int band, ch; |
| 951 | struct iwl_channel_info *ch_info; |
| 952 | |
| 953 | if (priv->channel_count) { |
Wey-Yi Guy | d058ff8 | 2010-12-03 10:33:35 -0800 | [diff] [blame] | 954 | IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n"); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 955 | return 0; |
| 956 | } |
| 957 | |
Wey-Yi Guy | d058ff8 | 2010-12-03 10:33:35 -0800 | [diff] [blame] | 958 | IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n"); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 959 | |
| 960 | priv->channel_count = |
| 961 | ARRAY_SIZE(iwl_eeprom_band_1) + |
| 962 | ARRAY_SIZE(iwl_eeprom_band_2) + |
| 963 | ARRAY_SIZE(iwl_eeprom_band_3) + |
| 964 | ARRAY_SIZE(iwl_eeprom_band_4) + |
| 965 | ARRAY_SIZE(iwl_eeprom_band_5); |
| 966 | |
Wey-Yi Guy | d058ff8 | 2010-12-03 10:33:35 -0800 | [diff] [blame] | 967 | IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n", |
| 968 | priv->channel_count); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 969 | |
Emmanuel Grumbach | 7f90dce | 2011-09-22 15:14:53 -0700 | [diff] [blame] | 970 | priv->channel_info = kcalloc(priv->channel_count, |
| 971 | sizeof(struct iwl_channel_info), |
| 972 | GFP_KERNEL); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 973 | if (!priv->channel_info) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 974 | IWL_ERR(priv, "Could not allocate channel_info\n"); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 975 | priv->channel_count = 0; |
| 976 | return -ENOMEM; |
| 977 | } |
| 978 | |
| 979 | ch_info = priv->channel_info; |
| 980 | |
| 981 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 982 | * channel map we maintain (that contains additional information than |
| 983 | * what just in the EEPROM) */ |
| 984 | for (band = 1; band <= 5; band++) { |
| 985 | |
| 986 | iwl_init_band_reference(priv, band, &eeprom_ch_count, |
| 987 | &eeprom_ch_info, &eeprom_ch_index); |
| 988 | |
| 989 | /* Loop through each band adding each of the channels */ |
| 990 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 991 | ch_info->channel = eeprom_ch_index[ch]; |
| 992 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 993 | IEEE80211_BAND_5GHZ; |
| 994 | |
| 995 | /* permanently store EEPROM's channel regulatory flags |
| 996 | * and max power in channel info database. */ |
| 997 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 998 | |
| 999 | /* Copy the run-time flags so they are there even on |
| 1000 | * invalid channels */ |
| 1001 | ch_info->flags = eeprom_ch_info[ch].flags; |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1002 | /* First write that ht40 is not enabled, and then enable |
Emmanuel Grumbach | 963f551 | 2008-06-12 09:47:00 +0800 | [diff] [blame] | 1003 | * one by one */ |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1004 | ch_info->ht40_extension_channel = |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 1005 | IEEE80211_CHAN_NO_HT40; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1006 | |
| 1007 | if (!(is_channel_valid(ch_info))) { |
Wey-Yi Guy | d058ff8 | 2010-12-03 10:33:35 -0800 | [diff] [blame] | 1008 | IWL_DEBUG_EEPROM(priv, |
| 1009 | "Ch. %d Flags %x [%sGHz] - " |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1010 | "No traffic\n", |
| 1011 | ch_info->channel, |
| 1012 | ch_info->flags, |
| 1013 | is_channel_a_band(ch_info) ? |
| 1014 | "5.2" : "2.4"); |
| 1015 | ch_info++; |
| 1016 | continue; |
| 1017 | } |
| 1018 | |
| 1019 | /* Initialize regulatory-based run-time data */ |
| 1020 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 1021 | eeprom_ch_info[ch].max_power_avg; |
| 1022 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 1023 | ch_info->min_power = 0; |
| 1024 | |
Wey-Yi Guy | d058ff8 | 2010-12-03 10:33:35 -0800 | [diff] [blame] | 1025 | IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] " |
| 1026 | "%s%s%s%s%s%s(0x%02x %ddBm):" |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 1027 | " Ad-Hoc %ssupported\n", |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1028 | ch_info->channel, |
| 1029 | is_channel_a_band(ch_info) ? |
| 1030 | "5.2" : "2.4", |
| 1031 | CHECK_AND_PRINT_I(VALID), |
| 1032 | CHECK_AND_PRINT_I(IBSS), |
| 1033 | CHECK_AND_PRINT_I(ACTIVE), |
| 1034 | CHECK_AND_PRINT_I(RADAR), |
| 1035 | CHECK_AND_PRINT_I(WIDE), |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1036 | CHECK_AND_PRINT_I(DFS), |
| 1037 | eeprom_ch_info[ch].flags, |
| 1038 | eeprom_ch_info[ch].max_power_avg, |
| 1039 | ((eeprom_ch_info[ch]. |
| 1040 | flags & EEPROM_CHANNEL_IBSS) |
| 1041 | && !(eeprom_ch_info[ch]. |
| 1042 | flags & EEPROM_CHANNEL_RADAR)) |
| 1043 | ? "" : "not "); |
| 1044 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1045 | ch_info++; |
| 1046 | } |
| 1047 | } |
| 1048 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1049 | /* Check if we do have HT40 channels */ |
Johannes Berg | e967669 | 2012-04-10 14:10:28 -0700 | [diff] [blame] | 1050 | if (priv->lib->eeprom_ops.regulatory_bands[5] == |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1051 | EEPROM_REGULATORY_BAND_NO_HT40 && |
Johannes Berg | e967669 | 2012-04-10 14:10:28 -0700 | [diff] [blame] | 1052 | priv->lib->eeprom_ops.regulatory_bands[6] == |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1053 | EEPROM_REGULATORY_BAND_NO_HT40) |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 1054 | return 0; |
| 1055 | |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 1056 | /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1057 | for (band = 6; band <= 7; band++) { |
| 1058 | enum ieee80211_band ieeeband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1059 | |
| 1060 | iwl_init_band_reference(priv, band, &eeprom_ch_count, |
| 1061 | &eeprom_ch_info, &eeprom_ch_index); |
| 1062 | |
| 1063 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ |
| 1064 | ieeeband = |
| 1065 | (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
| 1066 | |
| 1067 | /* Loop through each band adding each of the channels */ |
| 1068 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1069 | /* Set up driver's info for lower half */ |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 1070 | iwl_mod_ht40_chan_info(priv, ieeeband, |
Tomas Winkler | da6833c | 2008-05-15 13:54:15 +0800 | [diff] [blame] | 1071 | eeprom_ch_index[ch], |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 1072 | &eeprom_ch_info[ch], |
| 1073 | IEEE80211_CHAN_NO_HT40PLUS); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1074 | |
| 1075 | /* Set up driver's info for upper half */ |
Zhu Yi | 3b24716 | 2009-08-13 13:30:53 -0700 | [diff] [blame] | 1076 | iwl_mod_ht40_chan_info(priv, ieeeband, |
| 1077 | eeprom_ch_index[ch] + 4, |
| 1078 | &eeprom_ch_info[ch], |
| 1079 | IEEE80211_CHAN_NO_HT40MINUS); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
Wey-Yi Guy | ab9fd1b | 2009-08-21 13:34:23 -0700 | [diff] [blame] | 1083 | /* for newer device (6000 series and up) |
| 1084 | * EEPROM contain enhanced tx power information |
| 1085 | * driver need to process addition information |
| 1086 | * to determine the max channel tx power limits |
| 1087 | */ |
Johannes Berg | e967669 | 2012-04-10 14:10:28 -0700 | [diff] [blame] | 1088 | if (priv->lib->eeprom_ops.enhanced_txpower) |
Johannes Berg | 51dc51d | 2012-03-07 09:52:20 -0800 | [diff] [blame] | 1089 | iwl_eeprom_enhanced_txpower(priv); |
Wey-Yi Guy | ab9fd1b | 2009-08-21 13:34:23 -0700 | [diff] [blame] | 1090 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1091 | return 0; |
| 1092 | } |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1093 | |
| 1094 | /* |
Tomas Winkler | da6833c | 2008-05-15 13:54:15 +0800 | [diff] [blame] | 1095 | * iwl_free_channel_map - undo allocations in iwl_init_channel_map |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1096 | */ |
| 1097 | void iwl_free_channel_map(struct iwl_priv *priv) |
| 1098 | { |
| 1099 | kfree(priv->channel_info); |
| 1100 | priv->channel_count = 0; |
| 1101 | } |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1102 | |
| 1103 | /** |
| 1104 | * iwl_get_channel_info - Find driver's private channel info |
| 1105 | * |
| 1106 | * Based on band and channel number. |
| 1107 | */ |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 1108 | const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv, |
| 1109 | enum ieee80211_band band, u16 channel) |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1110 | { |
| 1111 | int i; |
| 1112 | |
| 1113 | switch (band) { |
| 1114 | case IEEE80211_BAND_5GHZ: |
| 1115 | for (i = 14; i < priv->channel_count; i++) { |
| 1116 | if (priv->channel_info[i].channel == channel) |
| 1117 | return &priv->channel_info[i]; |
| 1118 | } |
| 1119 | break; |
| 1120 | case IEEE80211_BAND_2GHZ: |
| 1121 | if (channel >= 1 && channel <= 14) |
| 1122 | return &priv->channel_info[channel - 1]; |
| 1123 | break; |
| 1124 | default: |
| 1125 | BUG(); |
| 1126 | } |
| 1127 | |
| 1128 | return NULL; |
| 1129 | } |
Wey-Yi Guy | 86cb3b4 | 2011-06-14 15:23:39 -0700 | [diff] [blame] | 1130 | |
| 1131 | void iwl_rf_config(struct iwl_priv *priv) |
| 1132 | { |
| 1133 | u16 radio_cfg; |
| 1134 | |
Johannes Berg | 11483b5 | 2012-04-09 17:46:58 -0700 | [diff] [blame] | 1135 | radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG); |
Wey-Yi Guy | 86cb3b4 | 2011-06-14 15:23:39 -0700 | [diff] [blame] | 1136 | |
| 1137 | /* write radio config values to register */ |
| 1138 | if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) { |
Emmanuel Grumbach | 7b6a2be | 2012-05-29 17:30:43 +0300 | [diff] [blame] | 1139 | u32 reg_val = |
| 1140 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg) << |
| 1141 | CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE | |
| 1142 | EEPROM_RF_CFG_STEP_MSK(radio_cfg) << |
| 1143 | CSR_HW_IF_CONFIG_REG_POS_PHY_STEP | |
| 1144 | EEPROM_RF_CFG_DASH_MSK(radio_cfg) << |
| 1145 | CSR_HW_IF_CONFIG_REG_POS_PHY_DASH; |
| 1146 | |
| 1147 | iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG, |
| 1148 | CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE | |
| 1149 | CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP | |
| 1150 | CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH, reg_val); |
| 1151 | |
Wey-Yi Guy | 86cb3b4 | 2011-06-14 15:23:39 -0700 | [diff] [blame] | 1152 | IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n", |
| 1153 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg), |
| 1154 | EEPROM_RF_CFG_STEP_MSK(radio_cfg), |
| 1155 | EEPROM_RF_CFG_DASH_MSK(radio_cfg)); |
| 1156 | } else |
| 1157 | WARN_ON(1); |
| 1158 | |
| 1159 | /* set CSR_HW_CONFIG_REG for uCode use */ |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 1160 | iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG, |
Wey-Yi Guy | 86cb3b4 | 2011-06-14 15:23:39 -0700 | [diff] [blame] | 1161 | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | |
| 1162 | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); |
| 1163 | } |