Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [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 | * |
| 8 | * Copyright(c) 2007 - 2012 Intel Corporation. All rights reserved. |
| 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: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
| 33 | * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved. |
| 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 | #include <linux/completion.h> |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 64 | #include <linux/dma-mapping.h> |
| 65 | #include <linux/firmware.h> |
| 66 | #include <linux/module.h> |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 67 | |
| 68 | #include "iwl-drv.h" |
| 69 | #include "iwl-trans.h" |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 70 | #include "iwl-op-mode.h" |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 71 | #include "iwl-agn-hw.h" |
Johannes Berg | 6238b00 | 2012-04-02 15:04:33 +0200 | [diff] [blame] | 72 | #include "iwl-fw.h" |
| 73 | #include "iwl-config.h" |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 74 | #include "iwl-modparams.h" |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 75 | |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 76 | /* private includes */ |
Johannes Berg | 3995dea | 2012-03-06 13:30:44 -0800 | [diff] [blame] | 77 | #include "iwl-fw-file.h" |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 78 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 79 | /** |
| 80 | * struct iwl_drv - drv common data |
| 81 | * @fw: the iwl_fw structure |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 82 | * @op_mode: the running op_mode |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 83 | * @trans: transport layer |
Emmanuel Grumbach | 4b9844f | 2012-03-22 23:59:52 +0200 | [diff] [blame] | 84 | * @dev: for debug prints only |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 85 | * @cfg: configuration struct |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 86 | * @fw_index: firmware revision to try loading |
| 87 | * @firmware_name: composite filename of ucode file to load |
| 88 | * @request_firmware_complete: the firmware has been obtained from user space |
| 89 | */ |
| 90 | struct iwl_drv { |
| 91 | struct iwl_fw fw; |
| 92 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 93 | struct iwl_op_mode *op_mode; |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 94 | struct iwl_trans *trans; |
Emmanuel Grumbach | 4b9844f | 2012-03-22 23:59:52 +0200 | [diff] [blame] | 95 | struct device *dev; |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 96 | const struct iwl_cfg *cfg; |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 97 | |
| 98 | int fw_index; /* firmware we're trying to load */ |
| 99 | char firmware_name[25]; /* name of firmware file to load */ |
| 100 | |
| 101 | struct completion request_firmware_complete; |
| 102 | }; |
| 103 | |
| 104 | |
| 105 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 106 | /* |
| 107 | * struct fw_sec: Just for the image parsing proccess. |
| 108 | * For the fw storage we are using struct fw_desc. |
| 109 | */ |
| 110 | struct fw_sec { |
| 111 | const void *data; /* the sec data */ |
| 112 | size_t size; /* section size */ |
| 113 | u32 offset; /* offset of writing in the device */ |
| 114 | }; |
| 115 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 116 | static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 117 | { |
| 118 | if (desc->v_addr) |
Emmanuel Grumbach | 93faaee | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 119 | dma_free_coherent(drv->trans->dev, desc->len, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 120 | desc->v_addr, desc->p_addr); |
| 121 | desc->v_addr = NULL; |
| 122 | desc->len = 0; |
| 123 | } |
| 124 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 125 | static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 126 | { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 127 | int i; |
| 128 | for (i = 0; i < IWL_UCODE_SECTION_MAX; i++) |
| 129 | iwl_free_fw_desc(drv, &img->sec[i]); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 132 | static void iwl_dealloc_ucode(struct iwl_drv *drv) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 133 | { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 134 | int i; |
| 135 | for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) |
| 136 | iwl_free_fw_img(drv, drv->fw.img + i); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 139 | static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc, |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 140 | struct fw_sec *sec) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 141 | { |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 142 | if (!sec || !sec->size) { |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 143 | desc->v_addr = NULL; |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
Emmanuel Grumbach | 93faaee | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 147 | desc->v_addr = dma_alloc_coherent(drv->trans->dev, sec->size, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 148 | &desc->p_addr, GFP_KERNEL); |
| 149 | if (!desc->v_addr) |
| 150 | return -ENOMEM; |
| 151 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 152 | desc->len = sec->size; |
| 153 | desc->offset = sec->offset; |
| 154 | memcpy(desc->v_addr, sec->data, sec->size); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context); |
| 159 | |
| 160 | #define UCODE_EXPERIMENTAL_INDEX 100 |
| 161 | #define UCODE_EXPERIMENTAL_TAG "exp" |
| 162 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 163 | static int iwl_request_firmware(struct iwl_drv *drv, bool first) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 164 | { |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 165 | const char *name_pre = drv->cfg->fw_name_pre; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 166 | char tag[8]; |
| 167 | |
| 168 | if (first) { |
| 169 | #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 170 | drv->fw_index = UCODE_EXPERIMENTAL_INDEX; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 171 | strcpy(tag, UCODE_EXPERIMENTAL_TAG); |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 172 | } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) { |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 173 | #endif |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 174 | drv->fw_index = drv->cfg->ucode_api_max; |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 175 | sprintf(tag, "%d", drv->fw_index); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 176 | } else { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 177 | drv->fw_index--; |
| 178 | sprintf(tag, "%d", drv->fw_index); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 181 | if (drv->fw_index < drv->cfg->ucode_api_min) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 182 | IWL_ERR(drv, "no suitable firmware found!\n"); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 183 | return -ENOENT; |
| 184 | } |
| 185 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 186 | sprintf(drv->firmware_name, "%s%s%s", name_pre, tag, ".ucode"); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 187 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 188 | IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n", |
| 189 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 190 | ? "EXPERIMENTAL " : "", |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 191 | drv->firmware_name); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 192 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 193 | return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name, |
Emmanuel Grumbach | 93faaee | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 194 | drv->trans->dev, |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 195 | GFP_KERNEL, drv, iwl_ucode_callback); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 196 | } |
| 197 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 198 | struct fw_img_parsing { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 199 | struct fw_sec sec[IWL_UCODE_SECTION_MAX]; |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 200 | int sec_counter; |
| 201 | }; |
| 202 | |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 203 | /* |
| 204 | * struct fw_sec_parsing: to extract fw section and it's offset from tlv |
| 205 | */ |
| 206 | struct fw_sec_parsing { |
| 207 | __le32 offset; |
| 208 | const u8 data[]; |
| 209 | } __packed; |
| 210 | |
| 211 | /** |
| 212 | * struct iwl_tlv_calib_data - parse the default calib data from TLV |
| 213 | * |
| 214 | * @ucode_type: the uCode to which the following default calib relates. |
| 215 | * @calib: default calibrations. |
| 216 | */ |
| 217 | struct iwl_tlv_calib_data { |
| 218 | __le32 ucode_type; |
| 219 | __le64 calib; |
| 220 | } __packed; |
| 221 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 222 | struct iwl_firmware_pieces { |
| 223 | struct fw_img_parsing img[IWL_UCODE_TYPE_MAX]; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 224 | |
| 225 | u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr; |
| 226 | u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr; |
| 227 | }; |
| 228 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 229 | /* |
| 230 | * These functions are just to extract uCode section data from the pieces |
| 231 | * structure. |
| 232 | */ |
| 233 | static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces, |
| 234 | enum iwl_ucode_type type, |
| 235 | int sec) |
| 236 | { |
| 237 | return &pieces->img[type].sec[sec]; |
| 238 | } |
| 239 | |
| 240 | static void set_sec_data(struct iwl_firmware_pieces *pieces, |
| 241 | enum iwl_ucode_type type, |
| 242 | int sec, |
| 243 | const void *data) |
| 244 | { |
| 245 | pieces->img[type].sec[sec].data = data; |
| 246 | } |
| 247 | |
| 248 | static void set_sec_size(struct iwl_firmware_pieces *pieces, |
| 249 | enum iwl_ucode_type type, |
| 250 | int sec, |
| 251 | size_t size) |
| 252 | { |
| 253 | pieces->img[type].sec[sec].size = size; |
| 254 | } |
| 255 | |
| 256 | static size_t get_sec_size(struct iwl_firmware_pieces *pieces, |
| 257 | enum iwl_ucode_type type, |
| 258 | int sec) |
| 259 | { |
| 260 | return pieces->img[type].sec[sec].size; |
| 261 | } |
| 262 | |
| 263 | static void set_sec_offset(struct iwl_firmware_pieces *pieces, |
| 264 | enum iwl_ucode_type type, |
| 265 | int sec, |
| 266 | u32 offset) |
| 267 | { |
| 268 | pieces->img[type].sec[sec].offset = offset; |
| 269 | } |
| 270 | |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 271 | /* |
| 272 | * Gets uCode section from tlv. |
| 273 | */ |
| 274 | static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces, |
| 275 | const void *data, enum iwl_ucode_type type, |
| 276 | int size) |
| 277 | { |
| 278 | struct fw_img_parsing *img; |
| 279 | struct fw_sec *sec; |
| 280 | struct fw_sec_parsing *sec_parse; |
| 281 | |
| 282 | if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX)) |
| 283 | return -1; |
| 284 | |
| 285 | sec_parse = (struct fw_sec_parsing *)data; |
| 286 | |
| 287 | img = &pieces->img[type]; |
| 288 | sec = &img->sec[img->sec_counter]; |
| 289 | |
| 290 | sec->offset = le32_to_cpu(sec_parse->offset); |
| 291 | sec->data = sec_parse->data; |
David Spinadel | 1176f43 | 2012-03-13 14:32:48 +0200 | [diff] [blame] | 292 | sec->size = size - sizeof(sec_parse->offset); |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 293 | |
| 294 | ++img->sec_counter; |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data) |
| 300 | { |
| 301 | struct iwl_tlv_calib_data *def_calib = |
| 302 | (struct iwl_tlv_calib_data *)data; |
| 303 | u32 ucode_type = le32_to_cpu(def_calib->ucode_type); |
| 304 | if (ucode_type >= IWL_UCODE_TYPE_MAX) { |
| 305 | IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n", |
| 306 | ucode_type); |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | drv->fw.default_calib[ucode_type] = le64_to_cpu(def_calib->calib); |
| 310 | return 0; |
| 311 | } |
| 312 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 313 | static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv, |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 314 | const struct firmware *ucode_raw, |
| 315 | struct iwl_firmware_pieces *pieces) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 316 | { |
| 317 | struct iwl_ucode_header *ucode = (void *)ucode_raw->data; |
| 318 | u32 api_ver, hdr_size, build; |
| 319 | char buildstr[25]; |
| 320 | const u8 *src; |
| 321 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 322 | drv->fw.ucode_ver = le32_to_cpu(ucode->ver); |
| 323 | api_ver = IWL_UCODE_API(drv->fw.ucode_ver); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 324 | |
| 325 | switch (api_ver) { |
| 326 | default: |
| 327 | hdr_size = 28; |
| 328 | if (ucode_raw->size < hdr_size) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 329 | IWL_ERR(drv, "File size too small!\n"); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 330 | return -EINVAL; |
| 331 | } |
| 332 | build = le32_to_cpu(ucode->u.v2.build); |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 333 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, |
| 334 | le32_to_cpu(ucode->u.v2.inst_size)); |
| 335 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, |
| 336 | le32_to_cpu(ucode->u.v2.data_size)); |
| 337 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, |
| 338 | le32_to_cpu(ucode->u.v2.init_size)); |
| 339 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, |
| 340 | le32_to_cpu(ucode->u.v2.init_data_size)); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 341 | src = ucode->u.v2.data; |
| 342 | break; |
| 343 | case 0: |
| 344 | case 1: |
| 345 | case 2: |
| 346 | hdr_size = 24; |
| 347 | if (ucode_raw->size < hdr_size) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 348 | IWL_ERR(drv, "File size too small!\n"); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 349 | return -EINVAL; |
| 350 | } |
| 351 | build = 0; |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 352 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, |
| 353 | le32_to_cpu(ucode->u.v1.inst_size)); |
| 354 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, |
| 355 | le32_to_cpu(ucode->u.v1.data_size)); |
| 356 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, |
| 357 | le32_to_cpu(ucode->u.v1.init_size)); |
| 358 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, |
| 359 | le32_to_cpu(ucode->u.v1.init_data_size)); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 360 | src = ucode->u.v1.data; |
| 361 | break; |
| 362 | } |
| 363 | |
| 364 | if (build) |
| 365 | sprintf(buildstr, " build %u%s", build, |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 366 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 367 | ? " (EXP)" : ""); |
| 368 | else |
| 369 | buildstr[0] = '\0'; |
| 370 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 371 | snprintf(drv->fw.fw_version, |
| 372 | sizeof(drv->fw.fw_version), |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 373 | "%u.%u.%u.%u%s", |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 374 | IWL_UCODE_MAJOR(drv->fw.ucode_ver), |
| 375 | IWL_UCODE_MINOR(drv->fw.ucode_ver), |
| 376 | IWL_UCODE_API(drv->fw.ucode_ver), |
| 377 | IWL_UCODE_SERIAL(drv->fw.ucode_ver), |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 378 | buildstr); |
| 379 | |
| 380 | /* Verify size of file vs. image size info in file's header */ |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 381 | |
| 382 | if (ucode_raw->size != hdr_size + |
| 383 | get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) + |
| 384 | get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) + |
| 385 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) + |
| 386 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) { |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 387 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 388 | IWL_ERR(drv, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 389 | "uCode file size %d does not match expected size\n", |
| 390 | (int)ucode_raw->size); |
| 391 | return -EINVAL; |
| 392 | } |
| 393 | |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 394 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 395 | set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src); |
| 396 | src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST); |
| 397 | set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, |
| 398 | IWLAGN_RTC_INST_LOWER_BOUND); |
| 399 | set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src); |
| 400 | src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA); |
| 401 | set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, |
| 402 | IWLAGN_RTC_DATA_LOWER_BOUND); |
| 403 | set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src); |
| 404 | src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST); |
| 405 | set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, |
| 406 | IWLAGN_RTC_INST_LOWER_BOUND); |
| 407 | set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src); |
| 408 | src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA); |
| 409 | set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, |
| 410 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 414 | static int iwl_parse_tlv_firmware(struct iwl_drv *drv, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 415 | const struct firmware *ucode_raw, |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 416 | struct iwl_firmware_pieces *pieces, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 417 | struct iwl_ucode_capabilities *capa) |
| 418 | { |
| 419 | struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data; |
| 420 | struct iwl_ucode_tlv *tlv; |
| 421 | size_t len = ucode_raw->size; |
| 422 | const u8 *data; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 423 | u32 tlv_len; |
| 424 | enum iwl_ucode_tlv_type tlv_type; |
| 425 | const u8 *tlv_data; |
| 426 | char buildstr[25]; |
| 427 | u32 build; |
| 428 | |
| 429 | if (len < sizeof(*ucode)) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 430 | IWL_ERR(drv, "uCode has invalid length: %zd\n", len); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 431 | return -EINVAL; |
| 432 | } |
| 433 | |
| 434 | if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 435 | IWL_ERR(drv, "invalid uCode magic: 0X%x\n", |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 436 | le32_to_cpu(ucode->magic)); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 440 | drv->fw.ucode_ver = le32_to_cpu(ucode->ver); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 441 | build = le32_to_cpu(ucode->build); |
| 442 | |
| 443 | if (build) |
| 444 | sprintf(buildstr, " build %u%s", build, |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 445 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 446 | ? " (EXP)" : ""); |
| 447 | else |
| 448 | buildstr[0] = '\0'; |
| 449 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 450 | snprintf(drv->fw.fw_version, |
| 451 | sizeof(drv->fw.fw_version), |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 452 | "%u.%u.%u.%u%s", |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 453 | IWL_UCODE_MAJOR(drv->fw.ucode_ver), |
| 454 | IWL_UCODE_MINOR(drv->fw.ucode_ver), |
| 455 | IWL_UCODE_API(drv->fw.ucode_ver), |
| 456 | IWL_UCODE_SERIAL(drv->fw.ucode_ver), |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 457 | buildstr); |
| 458 | |
| 459 | data = ucode->data; |
| 460 | |
| 461 | len -= sizeof(*ucode); |
| 462 | |
| 463 | while (len >= sizeof(*tlv)) { |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 464 | len -= sizeof(*tlv); |
| 465 | tlv = (void *)data; |
| 466 | |
| 467 | tlv_len = le32_to_cpu(tlv->length); |
Johannes Berg | 0479c19 | 2012-03-09 09:16:35 +0100 | [diff] [blame] | 468 | tlv_type = le32_to_cpu(tlv->type); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 469 | tlv_data = tlv->data; |
| 470 | |
| 471 | if (len < tlv_len) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 472 | IWL_ERR(drv, "invalid TLV len: %zd/%u\n", |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 473 | len, tlv_len); |
| 474 | return -EINVAL; |
| 475 | } |
| 476 | len -= ALIGN(tlv_len, 4); |
| 477 | data += sizeof(*tlv) + ALIGN(tlv_len, 4); |
| 478 | |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 479 | switch (tlv_type) { |
| 480 | case IWL_UCODE_TLV_INST: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 481 | set_sec_data(pieces, IWL_UCODE_REGULAR, |
| 482 | IWL_UCODE_SECTION_INST, tlv_data); |
| 483 | set_sec_size(pieces, IWL_UCODE_REGULAR, |
| 484 | IWL_UCODE_SECTION_INST, tlv_len); |
| 485 | set_sec_offset(pieces, IWL_UCODE_REGULAR, |
| 486 | IWL_UCODE_SECTION_INST, |
| 487 | IWLAGN_RTC_INST_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 488 | break; |
| 489 | case IWL_UCODE_TLV_DATA: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 490 | set_sec_data(pieces, IWL_UCODE_REGULAR, |
| 491 | IWL_UCODE_SECTION_DATA, tlv_data); |
| 492 | set_sec_size(pieces, IWL_UCODE_REGULAR, |
| 493 | IWL_UCODE_SECTION_DATA, tlv_len); |
| 494 | set_sec_offset(pieces, IWL_UCODE_REGULAR, |
| 495 | IWL_UCODE_SECTION_DATA, |
| 496 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 497 | break; |
| 498 | case IWL_UCODE_TLV_INIT: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 499 | set_sec_data(pieces, IWL_UCODE_INIT, |
| 500 | IWL_UCODE_SECTION_INST, tlv_data); |
| 501 | set_sec_size(pieces, IWL_UCODE_INIT, |
| 502 | IWL_UCODE_SECTION_INST, tlv_len); |
| 503 | set_sec_offset(pieces, IWL_UCODE_INIT, |
| 504 | IWL_UCODE_SECTION_INST, |
| 505 | IWLAGN_RTC_INST_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 506 | break; |
| 507 | case IWL_UCODE_TLV_INIT_DATA: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 508 | set_sec_data(pieces, IWL_UCODE_INIT, |
| 509 | IWL_UCODE_SECTION_DATA, tlv_data); |
| 510 | set_sec_size(pieces, IWL_UCODE_INIT, |
| 511 | IWL_UCODE_SECTION_DATA, tlv_len); |
| 512 | set_sec_offset(pieces, IWL_UCODE_INIT, |
| 513 | IWL_UCODE_SECTION_DATA, |
| 514 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 515 | break; |
| 516 | case IWL_UCODE_TLV_BOOT: |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 517 | IWL_ERR(drv, "Found unexpected BOOT ucode\n"); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 518 | break; |
| 519 | case IWL_UCODE_TLV_PROBE_MAX_LEN: |
| 520 | if (tlv_len != sizeof(u32)) |
| 521 | goto invalid_tlv_len; |
| 522 | capa->max_probe_length = |
| 523 | le32_to_cpup((__le32 *)tlv_data); |
| 524 | break; |
| 525 | case IWL_UCODE_TLV_PAN: |
| 526 | if (tlv_len) |
| 527 | goto invalid_tlv_len; |
| 528 | capa->flags |= IWL_UCODE_TLV_FLAGS_PAN; |
| 529 | break; |
| 530 | case IWL_UCODE_TLV_FLAGS: |
| 531 | /* must be at least one u32 */ |
| 532 | if (tlv_len < sizeof(u32)) |
| 533 | goto invalid_tlv_len; |
| 534 | /* and a proper number of u32s */ |
| 535 | if (tlv_len % sizeof(u32)) |
| 536 | goto invalid_tlv_len; |
| 537 | /* |
| 538 | * This driver only reads the first u32 as |
| 539 | * right now no more features are defined, |
| 540 | * if that changes then either the driver |
| 541 | * will not work with the new firmware, or |
| 542 | * it'll not take advantage of new features. |
| 543 | */ |
| 544 | capa->flags = le32_to_cpup((__le32 *)tlv_data); |
| 545 | break; |
| 546 | case IWL_UCODE_TLV_INIT_EVTLOG_PTR: |
| 547 | if (tlv_len != sizeof(u32)) |
| 548 | goto invalid_tlv_len; |
| 549 | pieces->init_evtlog_ptr = |
| 550 | le32_to_cpup((__le32 *)tlv_data); |
| 551 | break; |
| 552 | case IWL_UCODE_TLV_INIT_EVTLOG_SIZE: |
| 553 | if (tlv_len != sizeof(u32)) |
| 554 | goto invalid_tlv_len; |
| 555 | pieces->init_evtlog_size = |
| 556 | le32_to_cpup((__le32 *)tlv_data); |
| 557 | break; |
| 558 | case IWL_UCODE_TLV_INIT_ERRLOG_PTR: |
| 559 | if (tlv_len != sizeof(u32)) |
| 560 | goto invalid_tlv_len; |
| 561 | pieces->init_errlog_ptr = |
| 562 | le32_to_cpup((__le32 *)tlv_data); |
| 563 | break; |
| 564 | case IWL_UCODE_TLV_RUNT_EVTLOG_PTR: |
| 565 | if (tlv_len != sizeof(u32)) |
| 566 | goto invalid_tlv_len; |
| 567 | pieces->inst_evtlog_ptr = |
| 568 | le32_to_cpup((__le32 *)tlv_data); |
| 569 | break; |
| 570 | case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE: |
| 571 | if (tlv_len != sizeof(u32)) |
| 572 | goto invalid_tlv_len; |
| 573 | pieces->inst_evtlog_size = |
| 574 | le32_to_cpup((__le32 *)tlv_data); |
| 575 | break; |
| 576 | case IWL_UCODE_TLV_RUNT_ERRLOG_PTR: |
| 577 | if (tlv_len != sizeof(u32)) |
| 578 | goto invalid_tlv_len; |
| 579 | pieces->inst_errlog_ptr = |
| 580 | le32_to_cpup((__le32 *)tlv_data); |
| 581 | break; |
| 582 | case IWL_UCODE_TLV_ENHANCE_SENS_TBL: |
| 583 | if (tlv_len) |
| 584 | goto invalid_tlv_len; |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 585 | drv->fw.enhance_sensitivity_table = true; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 586 | break; |
| 587 | case IWL_UCODE_TLV_WOWLAN_INST: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 588 | set_sec_data(pieces, IWL_UCODE_WOWLAN, |
| 589 | IWL_UCODE_SECTION_INST, tlv_data); |
| 590 | set_sec_size(pieces, IWL_UCODE_WOWLAN, |
| 591 | IWL_UCODE_SECTION_INST, tlv_len); |
| 592 | set_sec_offset(pieces, IWL_UCODE_WOWLAN, |
| 593 | IWL_UCODE_SECTION_INST, |
| 594 | IWLAGN_RTC_INST_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 595 | break; |
| 596 | case IWL_UCODE_TLV_WOWLAN_DATA: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 597 | set_sec_data(pieces, IWL_UCODE_WOWLAN, |
| 598 | IWL_UCODE_SECTION_DATA, tlv_data); |
| 599 | set_sec_size(pieces, IWL_UCODE_WOWLAN, |
| 600 | IWL_UCODE_SECTION_DATA, tlv_len); |
| 601 | set_sec_offset(pieces, IWL_UCODE_WOWLAN, |
| 602 | IWL_UCODE_SECTION_DATA, |
| 603 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 604 | break; |
| 605 | case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE: |
| 606 | if (tlv_len != sizeof(u32)) |
| 607 | goto invalid_tlv_len; |
| 608 | capa->standard_phy_calibration_size = |
| 609 | le32_to_cpup((__le32 *)tlv_data); |
| 610 | break; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 611 | case IWL_UCODE_TLV_SEC_RT: |
| 612 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR, |
| 613 | tlv_len); |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 614 | drv->fw.mvm_fw = true; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 615 | break; |
| 616 | case IWL_UCODE_TLV_SEC_INIT: |
| 617 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT, |
| 618 | tlv_len); |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 619 | drv->fw.mvm_fw = true; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 620 | break; |
| 621 | case IWL_UCODE_TLV_SEC_WOWLAN: |
| 622 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN, |
| 623 | tlv_len); |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 624 | drv->fw.mvm_fw = true; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 625 | break; |
| 626 | case IWL_UCODE_TLV_DEF_CALIB: |
| 627 | if (tlv_len != sizeof(struct iwl_tlv_calib_data)) |
| 628 | goto invalid_tlv_len; |
| 629 | if (iwl_set_default_calib(drv, tlv_data)) |
| 630 | goto tlv_error; |
| 631 | break; |
| 632 | case IWL_UCODE_TLV_PHY_SKU: |
| 633 | if (tlv_len != sizeof(u32)) |
| 634 | goto invalid_tlv_len; |
| 635 | drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data); |
| 636 | break; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 637 | default: |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 638 | IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 639 | break; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | if (len) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 644 | IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len); |
| 645 | iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 646 | return -EINVAL; |
| 647 | } |
| 648 | |
| 649 | return 0; |
| 650 | |
| 651 | invalid_tlv_len: |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 652 | IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len); |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 653 | tlv_error: |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 654 | iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 655 | |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 659 | static int alloc_pci_desc(struct iwl_drv *drv, |
| 660 | struct iwl_firmware_pieces *pieces, |
| 661 | enum iwl_ucode_type type) |
| 662 | { |
| 663 | int i; |
| 664 | for (i = 0; |
| 665 | i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i); |
| 666 | i++) |
| 667 | if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]), |
| 668 | get_sec(pieces, type, i))) |
| 669 | return -1; |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | static int validate_sec_sizes(struct iwl_drv *drv, |
| 674 | struct iwl_firmware_pieces *pieces, |
| 675 | const struct iwl_cfg *cfg) |
| 676 | { |
| 677 | IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n", |
| 678 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 679 | IWL_UCODE_SECTION_INST)); |
| 680 | IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n", |
| 681 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 682 | IWL_UCODE_SECTION_DATA)); |
| 683 | IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n", |
| 684 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST)); |
| 685 | IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n", |
| 686 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)); |
| 687 | |
| 688 | /* Verify that uCode images will fit in card's SRAM. */ |
| 689 | if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) > |
| 690 | cfg->max_inst_size) { |
| 691 | IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n", |
| 692 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 693 | IWL_UCODE_SECTION_INST)); |
| 694 | return -1; |
| 695 | } |
| 696 | |
| 697 | if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) > |
| 698 | cfg->max_data_size) { |
| 699 | IWL_ERR(drv, "uCode data len %Zd too large to fit in\n", |
| 700 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 701 | IWL_UCODE_SECTION_DATA)); |
| 702 | return -1; |
| 703 | } |
| 704 | |
| 705 | if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) > |
| 706 | cfg->max_inst_size) { |
| 707 | IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n", |
| 708 | get_sec_size(pieces, IWL_UCODE_INIT, |
| 709 | IWL_UCODE_SECTION_INST)); |
| 710 | return -1; |
| 711 | } |
| 712 | |
| 713 | if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) > |
| 714 | cfg->max_data_size) { |
| 715 | IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n", |
| 716 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 717 | IWL_UCODE_SECTION_DATA)); |
| 718 | return -1; |
| 719 | } |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 724 | /** |
| 725 | * iwl_ucode_callback - callback when firmware was loaded |
| 726 | * |
| 727 | * If loaded successfully, copies the firmware into buffers |
| 728 | * for the card to fetch (via DMA). |
| 729 | */ |
| 730 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) |
| 731 | { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 732 | struct iwl_drv *drv = context; |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 733 | struct iwl_fw *fw = &drv->fw; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 734 | struct iwl_ucode_header *ucode; |
| 735 | int err; |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 736 | struct iwl_firmware_pieces pieces; |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 737 | const unsigned int api_max = drv->cfg->ucode_api_max; |
| 738 | unsigned int api_ok = drv->cfg->ucode_api_ok; |
| 739 | const unsigned int api_min = drv->cfg->ucode_api_min; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 740 | u32 api_ver; |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 741 | int i; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 742 | |
| 743 | fw->ucode_capa.max_probe_length = 200; |
| 744 | fw->ucode_capa.standard_phy_calibration_size = |
| 745 | IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
| 746 | |
| 747 | if (!api_ok) |
| 748 | api_ok = api_max; |
| 749 | |
| 750 | memset(&pieces, 0, sizeof(pieces)); |
| 751 | |
| 752 | if (!ucode_raw) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 753 | if (drv->fw_index <= api_ok) |
| 754 | IWL_ERR(drv, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 755 | "request for firmware file '%s' failed.\n", |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 756 | drv->firmware_name); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 757 | goto try_again; |
| 758 | } |
| 759 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 760 | IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n", |
| 761 | drv->firmware_name, ucode_raw->size); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 762 | |
| 763 | /* Make sure that we got at least the API version number */ |
| 764 | if (ucode_raw->size < 4) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 765 | IWL_ERR(drv, "File size way too small!\n"); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 766 | goto try_again; |
| 767 | } |
| 768 | |
| 769 | /* Data from ucode file: header followed by uCode images */ |
| 770 | ucode = (struct iwl_ucode_header *)ucode_raw->data; |
| 771 | |
| 772 | if (ucode->ver) |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 773 | err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 774 | else |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 775 | err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 776 | &fw->ucode_capa); |
| 777 | |
| 778 | if (err) |
| 779 | goto try_again; |
| 780 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 781 | api_ver = IWL_UCODE_API(drv->fw.ucode_ver); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 782 | |
| 783 | /* |
| 784 | * api_ver should match the api version forming part of the |
| 785 | * firmware filename ... but we don't check for that and only rely |
| 786 | * on the API version read from firmware header from here on forward |
| 787 | */ |
| 788 | /* no api version check required for experimental uCode */ |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 789 | if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) { |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 790 | if (api_ver < api_min || api_ver > api_max) { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 791 | IWL_ERR(drv, |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 792 | "Driver unable to support your firmware API. " |
| 793 | "Driver supports v%u, firmware is v%u.\n", |
| 794 | api_max, api_ver); |
| 795 | goto try_again; |
| 796 | } |
| 797 | |
| 798 | if (api_ver < api_ok) { |
| 799 | if (api_ok != api_max) |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 800 | IWL_ERR(drv, "Firmware has old API version, " |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 801 | "expected v%u through v%u, got v%u.\n", |
| 802 | api_ok, api_max, api_ver); |
| 803 | else |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 804 | IWL_ERR(drv, "Firmware has old API version, " |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 805 | "expected v%u, got v%u.\n", |
| 806 | api_max, api_ver); |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 807 | IWL_ERR(drv, "New firmware can be obtained from " |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 808 | "http://www.intellinuxwireless.org/.\n"); |
| 809 | } |
| 810 | } |
| 811 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 812 | IWL_INFO(drv, "loaded firmware version %s", drv->fw.fw_version); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 813 | |
| 814 | /* |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 815 | * In mvm uCode there is no difference between data and instructions |
| 816 | * sections. |
| 817 | */ |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 818 | if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg)) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 819 | goto try_again; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 820 | |
| 821 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 822 | |
| 823 | /* Runtime instructions and 2 copies of data: |
| 824 | * 1) unmodified from disk |
| 825 | * 2) backup cache for save/restore during power-downs */ |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 826 | for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) |
| 827 | if (alloc_pci_desc(drv, &pieces, i)) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 828 | goto err_pci_alloc; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 829 | |
| 830 | /* Now that we can no longer fail, copy information */ |
| 831 | |
| 832 | /* |
| 833 | * The (size - 16) / 12 formula is based on the information recorded |
| 834 | * for each event, which is of mode 1 (including timestamp) for all |
| 835 | * new microcodes that include this information. |
| 836 | */ |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 837 | fw->init_evtlog_ptr = pieces.init_evtlog_ptr; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 838 | if (pieces.init_evtlog_size) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 839 | fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 840 | else |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 841 | fw->init_evtlog_size = |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 842 | drv->cfg->base_params->max_event_log_size; |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 843 | fw->init_errlog_ptr = pieces.init_errlog_ptr; |
| 844 | fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 845 | if (pieces.inst_evtlog_size) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 846 | fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 847 | else |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 848 | fw->inst_evtlog_size = |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 849 | drv->cfg->base_params->max_event_log_size; |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 850 | fw->inst_errlog_ptr = pieces.inst_errlog_ptr; |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * figure out the offset of chain noise reset and gain commands |
| 854 | * base on the size of standard phy calibration commands table size |
| 855 | */ |
| 856 | if (fw->ucode_capa.standard_phy_calibration_size > |
| 857 | IWL_MAX_PHY_CALIBRATE_TBL_SIZE) |
| 858 | fw->ucode_capa.standard_phy_calibration_size = |
| 859 | IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
| 860 | |
| 861 | /* We have our copies now, allow OS release its copies */ |
| 862 | release_firmware(ucode_raw); |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 863 | complete(&drv->request_firmware_complete); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 864 | |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 865 | drv->op_mode = iwl_dvm_ops.start(drv->trans, drv->cfg, &drv->fw); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 866 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 867 | if (!drv->op_mode) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 868 | goto out_unbind; |
| 869 | |
| 870 | return; |
| 871 | |
| 872 | try_again: |
| 873 | /* try next, if any */ |
| 874 | release_firmware(ucode_raw); |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 875 | if (iwl_request_firmware(drv, false)) |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 876 | goto out_unbind; |
| 877 | return; |
| 878 | |
| 879 | err_pci_alloc: |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 880 | IWL_ERR(drv, "failed to allocate pci memory\n"); |
| 881 | iwl_dealloc_ucode(drv); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 882 | release_firmware(ucode_raw); |
| 883 | out_unbind: |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 884 | complete(&drv->request_firmware_complete); |
Emmanuel Grumbach | 93faaee | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 885 | device_release_driver(drv->trans->dev); |
Johannes Berg | 15854ef | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 886 | } |
| 887 | |
Emmanuel Grumbach | 87ce05a | 2012-03-26 09:03:18 -0700 | [diff] [blame] | 888 | struct iwl_drv *iwl_drv_start(struct iwl_trans *trans, |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 889 | const struct iwl_cfg *cfg) |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 890 | { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 891 | struct iwl_drv *drv; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 892 | int ret; |
| 893 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 894 | drv = kzalloc(sizeof(*drv), GFP_KERNEL); |
| 895 | if (!drv) { |
| 896 | dev_printk(KERN_ERR, trans->dev, "Couldn't allocate iwl_drv"); |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 897 | return NULL; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 898 | } |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 899 | drv->trans = trans; |
Emmanuel Grumbach | 4b9844f | 2012-03-22 23:59:52 +0200 | [diff] [blame] | 900 | drv->dev = trans->dev; |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 901 | drv->cfg = cfg; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 902 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 903 | init_completion(&drv->request_firmware_complete); |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 904 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 905 | ret = iwl_request_firmware(drv, true); |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 906 | |
| 907 | if (ret) { |
| 908 | dev_printk(KERN_ERR, trans->dev, "Couldn't request the fw"); |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 909 | kfree(drv); |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 910 | drv = NULL; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 911 | } |
| 912 | |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 913 | return drv; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 914 | } |
| 915 | |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 916 | void iwl_drv_stop(struct iwl_drv *drv) |
Emmanuel Grumbach | 07590f0 | 2012-02-07 14:27:31 +0200 | [diff] [blame] | 917 | { |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 918 | wait_for_completion(&drv->request_firmware_complete); |
Johannes Berg | 2e7eb11 | 2012-03-05 11:24:51 -0800 | [diff] [blame] | 919 | |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 920 | /* op_mode can be NULL if its start failed */ |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 921 | if (drv->op_mode) |
| 922 | iwl_op_mode_stop(drv->op_mode); |
Emmanuel Grumbach | 07590f0 | 2012-02-07 14:27:31 +0200 | [diff] [blame] | 923 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 924 | iwl_dealloc_ucode(drv); |
Johannes Berg | 7db5b98 | 2012-03-05 11:24:48 -0800 | [diff] [blame] | 925 | |
Johannes Berg | 965974a | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 926 | kfree(drv); |
Emmanuel Grumbach | 07590f0 | 2012-02-07 14:27:31 +0200 | [diff] [blame] | 927 | } |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 928 | |
| 929 | |
| 930 | /* shared module parameters */ |
| 931 | struct iwl_mod_params iwlwifi_mod_params = { |
| 932 | .amsdu_size_8K = 1, |
| 933 | .restart_fw = 1, |
| 934 | .plcp_check = true, |
| 935 | .bt_coex_active = true, |
| 936 | .power_level = IWL_POWER_INDEX_1, |
| 937 | .bt_ch_announce = true, |
| 938 | .auto_agg = true, |
| 939 | /* the rest are 0 by default */ |
| 940 | }; |
| 941 | |
| 942 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 943 | module_param_named(debug, iwlwifi_mod_params.debug_level, uint, |
| 944 | S_IRUGO | S_IWUSR); |
| 945 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 946 | #endif |
| 947 | |
| 948 | module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO); |
| 949 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); |
| 950 | module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO); |
| 951 | MODULE_PARM_DESC(11n_disable, |
| 952 | "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX"); |
| 953 | module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K, |
| 954 | int, S_IRUGO); |
| 955 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
| 956 | module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, int, S_IRUGO); |
| 957 | MODULE_PARM_DESC(fw_restart, "restart firmware in case of error"); |
| 958 | |
| 959 | module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling, |
| 960 | int, S_IRUGO); |
| 961 | MODULE_PARM_DESC(antenna_coupling, |
| 962 | "specify antenna coupling in dB (defualt: 0 dB)"); |
| 963 | |
| 964 | module_param_named(bt_ch_inhibition, iwlwifi_mod_params.bt_ch_announce, |
| 965 | bool, S_IRUGO); |
| 966 | MODULE_PARM_DESC(bt_ch_inhibition, |
| 967 | "Enable BT channel inhibition (default: enable)"); |
| 968 | |
| 969 | module_param_named(plcp_check, iwlwifi_mod_params.plcp_check, bool, S_IRUGO); |
| 970 | MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])"); |
| 971 | |
| 972 | module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO); |
| 973 | MODULE_PARM_DESC(wd_disable, |
| 974 | "Disable stuck queue watchdog timer 0=system default, " |
| 975 | "1=disable, 2=enable (default: 0)"); |
| 976 | |
| 977 | /* |
| 978 | * set bt_coex_active to true, uCode will do kill/defer |
| 979 | * every time the priority line is asserted (BT is sending signals on the |
| 980 | * priority line in the PCIx). |
| 981 | * set bt_coex_active to false, uCode will ignore the BT activity and |
| 982 | * perform the normal operation |
| 983 | * |
| 984 | * User might experience transmit issue on some platform due to WiFi/BT |
| 985 | * co-exist problem. The possible behaviors are: |
| 986 | * Able to scan and finding all the available AP |
| 987 | * Not able to associate with any AP |
| 988 | * On those platforms, WiFi communication can be restored by set |
| 989 | * "bt_coex_active" module parameter to "false" |
| 990 | * |
| 991 | * default: bt_coex_active = true (BT_COEX_ENABLE) |
| 992 | */ |
| 993 | module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active, |
| 994 | bool, S_IRUGO); |
| 995 | MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)"); |
| 996 | |
| 997 | module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO); |
| 998 | MODULE_PARM_DESC(led_mode, "0=system default, " |
| 999 | "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)"); |
| 1000 | |
| 1001 | module_param_named(power_save, iwlwifi_mod_params.power_save, |
| 1002 | bool, S_IRUGO); |
| 1003 | MODULE_PARM_DESC(power_save, |
| 1004 | "enable WiFi power management (default: disable)"); |
| 1005 | |
| 1006 | module_param_named(power_level, iwlwifi_mod_params.power_level, |
| 1007 | int, S_IRUGO); |
| 1008 | MODULE_PARM_DESC(power_level, |
| 1009 | "default power save level (range from 1 - 5, default: 1)"); |
| 1010 | |
| 1011 | module_param_named(auto_agg, iwlwifi_mod_params.auto_agg, |
| 1012 | bool, S_IRUGO); |
| 1013 | MODULE_PARM_DESC(auto_agg, |
| 1014 | "enable agg w/o check traffic load (default: enable)"); |