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