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