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 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 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 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 33 | * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | #include <linux/completion.h> |
Johannes Berg | 15854ef9 | 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> |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 67 | #include <linux/vmalloc.h> |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 68 | |
| 69 | #include "iwl-drv.h" |
Emmanuel Grumbach | c15797e | 2012-04-19 10:29:58 +0300 | [diff] [blame] | 70 | #include "iwl-debug.h" |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 71 | #include "iwl-trans.h" |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 72 | #include "iwl-op-mode.h" |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 73 | #include "iwl-agn-hw.h" |
Johannes Berg | 6238b00 | 2012-04-02 15:04:33 +0200 | [diff] [blame] | 74 | #include "iwl-fw.h" |
| 75 | #include "iwl-config.h" |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 76 | #include "iwl-modparams.h" |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 77 | |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 78 | /* private includes */ |
Johannes Berg | 3995dea | 2012-03-06 13:30:44 -0800 | [diff] [blame] | 79 | #include "iwl-fw-file.h" |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 80 | |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 81 | /****************************************************************************** |
| 82 | * |
| 83 | * module boiler plate |
| 84 | * |
| 85 | ******************************************************************************/ |
| 86 | |
| 87 | /* |
| 88 | * module name, copyright, version, etc. |
| 89 | */ |
| 90 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux" |
| 91 | |
| 92 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 93 | #define VD "d" |
| 94 | #else |
| 95 | #define VD |
| 96 | #endif |
| 97 | |
| 98 | #define DRV_VERSION IWLWIFI_VERSION VD |
| 99 | |
| 100 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 101 | MODULE_VERSION(DRV_VERSION); |
| 102 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
| 103 | MODULE_LICENSE("GPL"); |
| 104 | |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 105 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 106 | static struct dentry *iwl_dbgfs_root; |
| 107 | #endif |
| 108 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 109 | /** |
| 110 | * struct iwl_drv - drv common data |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 111 | * @list: list of drv structures using this opmode |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 112 | * @fw: the iwl_fw structure |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 113 | * @op_mode: the running op_mode |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 114 | * @trans: transport layer |
Emmanuel Grumbach | 4b9844f | 2012-03-22 23:59:52 +0200 | [diff] [blame] | 115 | * @dev: for debug prints only |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 116 | * @cfg: configuration struct |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 117 | * @fw_index: firmware revision to try loading |
| 118 | * @firmware_name: composite filename of ucode file to load |
| 119 | * @request_firmware_complete: the firmware has been obtained from user space |
| 120 | */ |
| 121 | struct iwl_drv { |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 122 | struct list_head list; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 123 | struct iwl_fw fw; |
| 124 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 125 | struct iwl_op_mode *op_mode; |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 126 | struct iwl_trans *trans; |
Emmanuel Grumbach | 4b9844f | 2012-03-22 23:59:52 +0200 | [diff] [blame] | 127 | struct device *dev; |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 128 | const struct iwl_cfg *cfg; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 129 | |
| 130 | int fw_index; /* firmware we're trying to load */ |
Liad Kaufman | 84b0312 | 2014-01-27 16:34:23 +0200 | [diff] [blame] | 131 | char firmware_name[32]; /* name of firmware file to load */ |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 132 | |
| 133 | struct completion request_firmware_complete; |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 134 | |
| 135 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 136 | struct dentry *dbgfs_drv; |
| 137 | struct dentry *dbgfs_trans; |
| 138 | struct dentry *dbgfs_op_mode; |
| 139 | #endif |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 142 | enum { |
| 143 | DVM_OP_MODE = 0, |
| 144 | MVM_OP_MODE = 1, |
| 145 | }; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 146 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 147 | /* Protects the table contents, i.e. the ops pointer & drv list */ |
| 148 | static struct mutex iwlwifi_opmode_table_mtx; |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 149 | static struct iwlwifi_opmode_table { |
| 150 | const char *name; /* name: iwldvm, iwlmvm, etc */ |
| 151 | const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */ |
| 152 | struct list_head drv; /* list of devices using this op_mode */ |
| 153 | } iwlwifi_opmode_table[] = { /* ops set when driver is initialized */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 154 | [DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL }, |
| 155 | [MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL }, |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 156 | }; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 157 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 158 | #define IWL_DEFAULT_SCAN_CHANNELS 40 |
| 159 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 160 | /* |
| 161 | * struct fw_sec: Just for the image parsing proccess. |
| 162 | * For the fw storage we are using struct fw_desc. |
| 163 | */ |
| 164 | struct fw_sec { |
| 165 | const void *data; /* the sec data */ |
| 166 | size_t size; /* section size */ |
| 167 | u32 offset; /* offset of writing in the device */ |
| 168 | }; |
| 169 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 170 | static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 171 | { |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 172 | vfree(desc->data); |
| 173 | desc->data = NULL; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 174 | desc->len = 0; |
| 175 | } |
| 176 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 177 | static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 178 | { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 179 | int i; |
| 180 | for (i = 0; i < IWL_UCODE_SECTION_MAX; i++) |
| 181 | iwl_free_fw_desc(drv, &img->sec[i]); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 184 | static void iwl_dealloc_ucode(struct iwl_drv *drv) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 185 | { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 186 | int i; |
| 187 | for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) |
| 188 | iwl_free_fw_img(drv, drv->fw.img + i); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 191 | static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc, |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 192 | struct fw_sec *sec) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 193 | { |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 194 | void *data; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 195 | |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 196 | desc->data = NULL; |
| 197 | |
| 198 | if (!sec || !sec->size) |
| 199 | return -EINVAL; |
| 200 | |
| 201 | data = vmalloc(sec->size); |
| 202 | if (!data) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 203 | return -ENOMEM; |
| 204 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 205 | desc->len = sec->size; |
| 206 | desc->offset = sec->offset; |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 207 | memcpy(data, sec->data, desc->len); |
| 208 | desc->data = data; |
| 209 | |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
Emmanuel Grumbach | 1c8e11e | 2012-07-16 12:31:28 +0300 | [diff] [blame] | 213 | static void iwl_req_fw_callback(const struct firmware *ucode_raw, |
| 214 | void *context); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 215 | |
| 216 | #define UCODE_EXPERIMENTAL_INDEX 100 |
| 217 | #define UCODE_EXPERIMENTAL_TAG "exp" |
| 218 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 219 | static int iwl_request_firmware(struct iwl_drv *drv, bool first) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 220 | { |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 221 | const char *name_pre = drv->cfg->fw_name_pre; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 222 | char tag[8]; |
| 223 | |
| 224 | if (first) { |
| 225 | #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 226 | drv->fw_index = UCODE_EXPERIMENTAL_INDEX; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 227 | strcpy(tag, UCODE_EXPERIMENTAL_TAG); |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 228 | } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) { |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 229 | #endif |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 230 | drv->fw_index = drv->cfg->ucode_api_max; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 231 | sprintf(tag, "%d", drv->fw_index); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 232 | } else { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 233 | drv->fw_index--; |
| 234 | sprintf(tag, "%d", drv->fw_index); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 237 | if (drv->fw_index < drv->cfg->ucode_api_min) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 238 | IWL_ERR(drv, "no suitable firmware found!\n"); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 239 | return -ENOENT; |
| 240 | } |
| 241 | |
Liad Kaufman | 84b0312 | 2014-01-27 16:34:23 +0200 | [diff] [blame] | 242 | snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s%s.ucode", |
| 243 | name_pre, tag); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 244 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 245 | IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n", |
| 246 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 247 | ? "EXPERIMENTAL " : "", |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 248 | drv->firmware_name); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 249 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 250 | return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name, |
Emmanuel Grumbach | 93faaee | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 251 | drv->trans->dev, |
Emmanuel Grumbach | 1c8e11e | 2012-07-16 12:31:28 +0300 | [diff] [blame] | 252 | GFP_KERNEL, drv, iwl_req_fw_callback); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 253 | } |
| 254 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 255 | struct fw_img_parsing { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 256 | struct fw_sec sec[IWL_UCODE_SECTION_MAX]; |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 257 | int sec_counter; |
| 258 | }; |
| 259 | |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 260 | /* |
| 261 | * struct fw_sec_parsing: to extract fw section and it's offset from tlv |
| 262 | */ |
| 263 | struct fw_sec_parsing { |
| 264 | __le32 offset; |
| 265 | const u8 data[]; |
| 266 | } __packed; |
| 267 | |
| 268 | /** |
| 269 | * struct iwl_tlv_calib_data - parse the default calib data from TLV |
| 270 | * |
| 271 | * @ucode_type: the uCode to which the following default calib relates. |
| 272 | * @calib: default calibrations. |
| 273 | */ |
| 274 | struct iwl_tlv_calib_data { |
| 275 | __le32 ucode_type; |
Johannes Berg | aa2b177 | 2013-01-24 14:12:07 +0100 | [diff] [blame] | 276 | struct iwl_tlv_calib_ctrl calib; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 277 | } __packed; |
| 278 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 279 | struct iwl_firmware_pieces { |
| 280 | struct fw_img_parsing img[IWL_UCODE_TYPE_MAX]; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 281 | |
| 282 | u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr; |
| 283 | u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr; |
| 284 | }; |
| 285 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 286 | /* |
| 287 | * These functions are just to extract uCode section data from the pieces |
| 288 | * structure. |
| 289 | */ |
| 290 | static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces, |
| 291 | enum iwl_ucode_type type, |
| 292 | int sec) |
| 293 | { |
| 294 | return &pieces->img[type].sec[sec]; |
| 295 | } |
| 296 | |
| 297 | static void set_sec_data(struct iwl_firmware_pieces *pieces, |
| 298 | enum iwl_ucode_type type, |
| 299 | int sec, |
| 300 | const void *data) |
| 301 | { |
| 302 | pieces->img[type].sec[sec].data = data; |
| 303 | } |
| 304 | |
| 305 | static void set_sec_size(struct iwl_firmware_pieces *pieces, |
| 306 | enum iwl_ucode_type type, |
| 307 | int sec, |
| 308 | size_t size) |
| 309 | { |
| 310 | pieces->img[type].sec[sec].size = size; |
| 311 | } |
| 312 | |
| 313 | static size_t get_sec_size(struct iwl_firmware_pieces *pieces, |
| 314 | enum iwl_ucode_type type, |
| 315 | int sec) |
| 316 | { |
| 317 | return pieces->img[type].sec[sec].size; |
| 318 | } |
| 319 | |
| 320 | static void set_sec_offset(struct iwl_firmware_pieces *pieces, |
| 321 | enum iwl_ucode_type type, |
| 322 | int sec, |
| 323 | u32 offset) |
| 324 | { |
| 325 | pieces->img[type].sec[sec].offset = offset; |
| 326 | } |
| 327 | |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 328 | static int iwl_store_cscheme(struct iwl_fw *fw, const u8 *data, const u32 len) |
| 329 | { |
| 330 | int i, j; |
| 331 | struct iwl_fw_cscheme_list *l = (struct iwl_fw_cscheme_list *)data; |
| 332 | struct iwl_fw_cipher_scheme *fwcs; |
| 333 | struct ieee80211_cipher_scheme *cs; |
| 334 | u32 cipher; |
| 335 | |
| 336 | if (len < sizeof(*l) || |
| 337 | len < sizeof(l->size) + l->size * sizeof(l->cs[0])) |
| 338 | return -EINVAL; |
| 339 | |
| 340 | for (i = 0, j = 0; i < IWL_UCODE_MAX_CS && i < l->size; i++) { |
| 341 | fwcs = &l->cs[j]; |
| 342 | cipher = le32_to_cpu(fwcs->cipher); |
| 343 | |
| 344 | /* we skip schemes with zero cipher suite selector */ |
| 345 | if (!cipher) |
| 346 | continue; |
| 347 | |
| 348 | cs = &fw->cs[j++]; |
| 349 | cs->cipher = cipher; |
| 350 | cs->iftype = BIT(NL80211_IFTYPE_STATION); |
| 351 | cs->hdr_len = fwcs->hdr_len; |
| 352 | cs->pn_len = fwcs->pn_len; |
| 353 | cs->pn_off = fwcs->pn_off; |
| 354 | cs->key_idx_off = fwcs->key_idx_off; |
| 355 | cs->key_idx_mask = fwcs->key_idx_mask; |
| 356 | cs->key_idx_shift = fwcs->key_idx_shift; |
| 357 | cs->mic_len = fwcs->mic_len; |
| 358 | } |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 363 | /* |
| 364 | * Gets uCode section from tlv. |
| 365 | */ |
| 366 | static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces, |
| 367 | const void *data, enum iwl_ucode_type type, |
| 368 | int size) |
| 369 | { |
| 370 | struct fw_img_parsing *img; |
| 371 | struct fw_sec *sec; |
| 372 | struct fw_sec_parsing *sec_parse; |
| 373 | |
| 374 | if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX)) |
| 375 | return -1; |
| 376 | |
| 377 | sec_parse = (struct fw_sec_parsing *)data; |
| 378 | |
| 379 | img = &pieces->img[type]; |
| 380 | sec = &img->sec[img->sec_counter]; |
| 381 | |
| 382 | sec->offset = le32_to_cpu(sec_parse->offset); |
| 383 | sec->data = sec_parse->data; |
David Spinadel | 1176f43 | 2012-03-13 14:32:48 +0200 | [diff] [blame] | 384 | sec->size = size - sizeof(sec_parse->offset); |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 385 | |
| 386 | ++img->sec_counter; |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data) |
| 392 | { |
| 393 | struct iwl_tlv_calib_data *def_calib = |
| 394 | (struct iwl_tlv_calib_data *)data; |
| 395 | u32 ucode_type = le32_to_cpu(def_calib->ucode_type); |
| 396 | if (ucode_type >= IWL_UCODE_TYPE_MAX) { |
| 397 | IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n", |
| 398 | ucode_type); |
| 399 | return -EINVAL; |
| 400 | } |
Johannes Berg | aa2b177 | 2013-01-24 14:12:07 +0100 | [diff] [blame] | 401 | drv->fw.default_calib[ucode_type].flow_trigger = |
| 402 | def_calib->calib.flow_trigger; |
| 403 | drv->fw.default_calib[ucode_type].event_trigger = |
| 404 | def_calib->calib.event_trigger; |
| 405 | |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
Eran Harary | a2978b1 | 2014-02-20 11:00:01 +0200 | [diff] [blame] | 409 | static int iwl_set_ucode_api_flags(struct iwl_drv *drv, const u8 *data, |
| 410 | struct iwl_ucode_capabilities *capa) |
| 411 | { |
| 412 | const struct iwl_ucode_api *ucode_api = (void *)data; |
| 413 | u32 api_index = le32_to_cpu(ucode_api->api_index); |
| 414 | |
| 415 | if (api_index >= IWL_API_ARRAY_SIZE) { |
| 416 | IWL_ERR(drv, "api_index larger than supported by driver\n"); |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
| 420 | capa->api[api_index] = le32_to_cpu(ucode_api->api_flags); |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static int iwl_set_ucode_capabilities(struct iwl_drv *drv, const u8 *data, |
| 426 | struct iwl_ucode_capabilities *capa) |
| 427 | { |
| 428 | const struct iwl_ucode_capa *ucode_capa = (void *)data; |
| 429 | u32 api_index = le32_to_cpu(ucode_capa->api_index); |
| 430 | |
| 431 | if (api_index >= IWL_CAPABILITIES_ARRAY_SIZE) { |
| 432 | IWL_ERR(drv, "api_index larger than supported by driver\n"); |
| 433 | return -EINVAL; |
| 434 | } |
| 435 | |
| 436 | capa->capa[api_index] = le32_to_cpu(ucode_capa->api_capa); |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 441 | static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv, |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 442 | const struct firmware *ucode_raw, |
| 443 | struct iwl_firmware_pieces *pieces) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 444 | { |
| 445 | struct iwl_ucode_header *ucode = (void *)ucode_raw->data; |
| 446 | u32 api_ver, hdr_size, build; |
| 447 | char buildstr[25]; |
| 448 | const u8 *src; |
| 449 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 450 | drv->fw.ucode_ver = le32_to_cpu(ucode->ver); |
| 451 | api_ver = IWL_UCODE_API(drv->fw.ucode_ver); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 452 | |
| 453 | switch (api_ver) { |
| 454 | default: |
| 455 | hdr_size = 28; |
| 456 | if (ucode_raw->size < hdr_size) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 457 | IWL_ERR(drv, "File size too small!\n"); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 458 | return -EINVAL; |
| 459 | } |
| 460 | build = le32_to_cpu(ucode->u.v2.build); |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 461 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, |
| 462 | le32_to_cpu(ucode->u.v2.inst_size)); |
| 463 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, |
| 464 | le32_to_cpu(ucode->u.v2.data_size)); |
| 465 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, |
| 466 | le32_to_cpu(ucode->u.v2.init_size)); |
| 467 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, |
| 468 | le32_to_cpu(ucode->u.v2.init_data_size)); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 469 | src = ucode->u.v2.data; |
| 470 | break; |
| 471 | case 0: |
| 472 | case 1: |
| 473 | case 2: |
| 474 | hdr_size = 24; |
| 475 | if (ucode_raw->size < hdr_size) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 476 | IWL_ERR(drv, "File size too small!\n"); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 477 | return -EINVAL; |
| 478 | } |
| 479 | build = 0; |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 480 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, |
| 481 | le32_to_cpu(ucode->u.v1.inst_size)); |
| 482 | set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, |
| 483 | le32_to_cpu(ucode->u.v1.data_size)); |
| 484 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, |
| 485 | le32_to_cpu(ucode->u.v1.init_size)); |
| 486 | set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, |
| 487 | le32_to_cpu(ucode->u.v1.init_data_size)); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 488 | src = ucode->u.v1.data; |
| 489 | break; |
| 490 | } |
| 491 | |
| 492 | if (build) |
| 493 | sprintf(buildstr, " build %u%s", build, |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 494 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 495 | ? " (EXP)" : ""); |
| 496 | else |
| 497 | buildstr[0] = '\0'; |
| 498 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 499 | snprintf(drv->fw.fw_version, |
| 500 | sizeof(drv->fw.fw_version), |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 501 | "%u.%u.%u.%u%s", |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 502 | IWL_UCODE_MAJOR(drv->fw.ucode_ver), |
| 503 | IWL_UCODE_MINOR(drv->fw.ucode_ver), |
| 504 | IWL_UCODE_API(drv->fw.ucode_ver), |
| 505 | IWL_UCODE_SERIAL(drv->fw.ucode_ver), |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 506 | buildstr); |
| 507 | |
| 508 | /* Verify size of file vs. image size info in file's header */ |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 509 | |
| 510 | if (ucode_raw->size != hdr_size + |
| 511 | get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) + |
| 512 | get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) + |
| 513 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) + |
| 514 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) { |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 515 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 516 | IWL_ERR(drv, |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 517 | "uCode file size %d does not match expected size\n", |
| 518 | (int)ucode_raw->size); |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 522 | |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 523 | set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src); |
| 524 | src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST); |
| 525 | set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, |
| 526 | IWLAGN_RTC_INST_LOWER_BOUND); |
| 527 | set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src); |
| 528 | src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA); |
| 529 | set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, |
| 530 | IWLAGN_RTC_DATA_LOWER_BOUND); |
| 531 | set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src); |
| 532 | src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST); |
| 533 | set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, |
| 534 | IWLAGN_RTC_INST_LOWER_BOUND); |
| 535 | set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src); |
| 536 | src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA); |
| 537 | set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, |
| 538 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 542 | static int iwl_parse_tlv_firmware(struct iwl_drv *drv, |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 543 | const struct firmware *ucode_raw, |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 544 | struct iwl_firmware_pieces *pieces, |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 545 | struct iwl_ucode_capabilities *capa) |
| 546 | { |
| 547 | struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data; |
| 548 | struct iwl_ucode_tlv *tlv; |
| 549 | size_t len = ucode_raw->size; |
| 550 | const u8 *data; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 551 | u32 tlv_len; |
| 552 | enum iwl_ucode_tlv_type tlv_type; |
| 553 | const u8 *tlv_data; |
| 554 | char buildstr[25]; |
| 555 | u32 build; |
Eran Harary | e2d6f4e | 2013-10-02 13:53:40 +0300 | [diff] [blame] | 556 | int num_of_cpus; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 557 | |
| 558 | if (len < sizeof(*ucode)) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 559 | IWL_ERR(drv, "uCode has invalid length: %zd\n", len); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 560 | return -EINVAL; |
| 561 | } |
| 562 | |
| 563 | if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 564 | IWL_ERR(drv, "invalid uCode magic: 0X%x\n", |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 565 | le32_to_cpu(ucode->magic)); |
| 566 | return -EINVAL; |
| 567 | } |
| 568 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 569 | drv->fw.ucode_ver = le32_to_cpu(ucode->ver); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 570 | build = le32_to_cpu(ucode->build); |
| 571 | |
| 572 | if (build) |
| 573 | sprintf(buildstr, " build %u%s", build, |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 574 | (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 575 | ? " (EXP)" : ""); |
| 576 | else |
| 577 | buildstr[0] = '\0'; |
| 578 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 579 | snprintf(drv->fw.fw_version, |
| 580 | sizeof(drv->fw.fw_version), |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 581 | "%u.%u.%u.%u%s", |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 582 | IWL_UCODE_MAJOR(drv->fw.ucode_ver), |
| 583 | IWL_UCODE_MINOR(drv->fw.ucode_ver), |
| 584 | IWL_UCODE_API(drv->fw.ucode_ver), |
| 585 | IWL_UCODE_SERIAL(drv->fw.ucode_ver), |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 586 | buildstr); |
| 587 | |
| 588 | data = ucode->data; |
| 589 | |
| 590 | len -= sizeof(*ucode); |
| 591 | |
| 592 | while (len >= sizeof(*tlv)) { |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 593 | len -= sizeof(*tlv); |
| 594 | tlv = (void *)data; |
| 595 | |
| 596 | tlv_len = le32_to_cpu(tlv->length); |
Johannes Berg | 0479c19 | 2012-03-09 09:16:35 +0100 | [diff] [blame] | 597 | tlv_type = le32_to_cpu(tlv->type); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 598 | tlv_data = tlv->data; |
| 599 | |
| 600 | if (len < tlv_len) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 601 | IWL_ERR(drv, "invalid TLV len: %zd/%u\n", |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 602 | len, tlv_len); |
| 603 | return -EINVAL; |
| 604 | } |
| 605 | len -= ALIGN(tlv_len, 4); |
| 606 | data += sizeof(*tlv) + ALIGN(tlv_len, 4); |
| 607 | |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 608 | switch (tlv_type) { |
| 609 | case IWL_UCODE_TLV_INST: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 610 | set_sec_data(pieces, IWL_UCODE_REGULAR, |
| 611 | IWL_UCODE_SECTION_INST, tlv_data); |
| 612 | set_sec_size(pieces, IWL_UCODE_REGULAR, |
| 613 | IWL_UCODE_SECTION_INST, tlv_len); |
| 614 | set_sec_offset(pieces, IWL_UCODE_REGULAR, |
| 615 | IWL_UCODE_SECTION_INST, |
| 616 | IWLAGN_RTC_INST_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 617 | break; |
| 618 | case IWL_UCODE_TLV_DATA: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 619 | set_sec_data(pieces, IWL_UCODE_REGULAR, |
| 620 | IWL_UCODE_SECTION_DATA, tlv_data); |
| 621 | set_sec_size(pieces, IWL_UCODE_REGULAR, |
| 622 | IWL_UCODE_SECTION_DATA, tlv_len); |
| 623 | set_sec_offset(pieces, IWL_UCODE_REGULAR, |
| 624 | IWL_UCODE_SECTION_DATA, |
| 625 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 626 | break; |
| 627 | case IWL_UCODE_TLV_INIT: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 628 | set_sec_data(pieces, IWL_UCODE_INIT, |
| 629 | IWL_UCODE_SECTION_INST, tlv_data); |
| 630 | set_sec_size(pieces, IWL_UCODE_INIT, |
| 631 | IWL_UCODE_SECTION_INST, tlv_len); |
| 632 | set_sec_offset(pieces, IWL_UCODE_INIT, |
| 633 | IWL_UCODE_SECTION_INST, |
| 634 | IWLAGN_RTC_INST_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 635 | break; |
| 636 | case IWL_UCODE_TLV_INIT_DATA: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 637 | set_sec_data(pieces, IWL_UCODE_INIT, |
| 638 | IWL_UCODE_SECTION_DATA, tlv_data); |
| 639 | set_sec_size(pieces, IWL_UCODE_INIT, |
| 640 | IWL_UCODE_SECTION_DATA, tlv_len); |
| 641 | set_sec_offset(pieces, IWL_UCODE_INIT, |
| 642 | IWL_UCODE_SECTION_DATA, |
| 643 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 644 | break; |
| 645 | case IWL_UCODE_TLV_BOOT: |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 646 | IWL_ERR(drv, "Found unexpected BOOT ucode\n"); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 647 | break; |
| 648 | case IWL_UCODE_TLV_PROBE_MAX_LEN: |
| 649 | if (tlv_len != sizeof(u32)) |
| 650 | goto invalid_tlv_len; |
| 651 | capa->max_probe_length = |
| 652 | le32_to_cpup((__le32 *)tlv_data); |
| 653 | break; |
| 654 | case IWL_UCODE_TLV_PAN: |
| 655 | if (tlv_len) |
| 656 | goto invalid_tlv_len; |
| 657 | capa->flags |= IWL_UCODE_TLV_FLAGS_PAN; |
| 658 | break; |
| 659 | case IWL_UCODE_TLV_FLAGS: |
| 660 | /* must be at least one u32 */ |
| 661 | if (tlv_len < sizeof(u32)) |
| 662 | goto invalid_tlv_len; |
| 663 | /* and a proper number of u32s */ |
| 664 | if (tlv_len % sizeof(u32)) |
| 665 | goto invalid_tlv_len; |
| 666 | /* |
| 667 | * This driver only reads the first u32 as |
| 668 | * right now no more features are defined, |
| 669 | * if that changes then either the driver |
| 670 | * will not work with the new firmware, or |
| 671 | * it'll not take advantage of new features. |
| 672 | */ |
| 673 | capa->flags = le32_to_cpup((__le32 *)tlv_data); |
| 674 | break; |
Eran Harary | a2978b1 | 2014-02-20 11:00:01 +0200 | [diff] [blame] | 675 | case IWL_UCODE_TLV_API_CHANGES_SET: |
| 676 | if (tlv_len != sizeof(struct iwl_ucode_api)) |
| 677 | goto invalid_tlv_len; |
| 678 | if (iwl_set_ucode_api_flags(drv, tlv_data, capa)) |
| 679 | goto tlv_error; |
| 680 | break; |
| 681 | case IWL_UCODE_TLV_ENABLED_CAPABILITIES: |
| 682 | if (tlv_len != sizeof(struct iwl_ucode_capa)) |
| 683 | goto invalid_tlv_len; |
| 684 | if (iwl_set_ucode_capabilities(drv, tlv_data, capa)) |
| 685 | goto tlv_error; |
| 686 | break; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 687 | case IWL_UCODE_TLV_INIT_EVTLOG_PTR: |
| 688 | if (tlv_len != sizeof(u32)) |
| 689 | goto invalid_tlv_len; |
| 690 | pieces->init_evtlog_ptr = |
| 691 | le32_to_cpup((__le32 *)tlv_data); |
| 692 | break; |
| 693 | case IWL_UCODE_TLV_INIT_EVTLOG_SIZE: |
| 694 | if (tlv_len != sizeof(u32)) |
| 695 | goto invalid_tlv_len; |
| 696 | pieces->init_evtlog_size = |
| 697 | le32_to_cpup((__le32 *)tlv_data); |
| 698 | break; |
| 699 | case IWL_UCODE_TLV_INIT_ERRLOG_PTR: |
| 700 | if (tlv_len != sizeof(u32)) |
| 701 | goto invalid_tlv_len; |
| 702 | pieces->init_errlog_ptr = |
| 703 | le32_to_cpup((__le32 *)tlv_data); |
| 704 | break; |
| 705 | case IWL_UCODE_TLV_RUNT_EVTLOG_PTR: |
| 706 | if (tlv_len != sizeof(u32)) |
| 707 | goto invalid_tlv_len; |
| 708 | pieces->inst_evtlog_ptr = |
| 709 | le32_to_cpup((__le32 *)tlv_data); |
| 710 | break; |
| 711 | case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE: |
| 712 | if (tlv_len != sizeof(u32)) |
| 713 | goto invalid_tlv_len; |
| 714 | pieces->inst_evtlog_size = |
| 715 | le32_to_cpup((__le32 *)tlv_data); |
| 716 | break; |
| 717 | case IWL_UCODE_TLV_RUNT_ERRLOG_PTR: |
| 718 | if (tlv_len != sizeof(u32)) |
| 719 | goto invalid_tlv_len; |
| 720 | pieces->inst_errlog_ptr = |
| 721 | le32_to_cpup((__le32 *)tlv_data); |
| 722 | break; |
| 723 | case IWL_UCODE_TLV_ENHANCE_SENS_TBL: |
| 724 | if (tlv_len) |
| 725 | goto invalid_tlv_len; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 726 | drv->fw.enhance_sensitivity_table = true; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 727 | break; |
| 728 | case IWL_UCODE_TLV_WOWLAN_INST: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 729 | set_sec_data(pieces, IWL_UCODE_WOWLAN, |
| 730 | IWL_UCODE_SECTION_INST, tlv_data); |
| 731 | set_sec_size(pieces, IWL_UCODE_WOWLAN, |
| 732 | IWL_UCODE_SECTION_INST, tlv_len); |
| 733 | set_sec_offset(pieces, IWL_UCODE_WOWLAN, |
| 734 | IWL_UCODE_SECTION_INST, |
| 735 | IWLAGN_RTC_INST_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 736 | break; |
| 737 | case IWL_UCODE_TLV_WOWLAN_DATA: |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 738 | set_sec_data(pieces, IWL_UCODE_WOWLAN, |
| 739 | IWL_UCODE_SECTION_DATA, tlv_data); |
| 740 | set_sec_size(pieces, IWL_UCODE_WOWLAN, |
| 741 | IWL_UCODE_SECTION_DATA, tlv_len); |
| 742 | set_sec_offset(pieces, IWL_UCODE_WOWLAN, |
| 743 | IWL_UCODE_SECTION_DATA, |
| 744 | IWLAGN_RTC_DATA_LOWER_BOUND); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 745 | break; |
| 746 | case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE: |
| 747 | if (tlv_len != sizeof(u32)) |
| 748 | goto invalid_tlv_len; |
| 749 | capa->standard_phy_calibration_size = |
| 750 | le32_to_cpup((__le32 *)tlv_data); |
| 751 | break; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 752 | case IWL_UCODE_TLV_SEC_RT: |
| 753 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR, |
| 754 | tlv_len); |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 755 | drv->fw.mvm_fw = true; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 756 | break; |
| 757 | case IWL_UCODE_TLV_SEC_INIT: |
| 758 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT, |
| 759 | tlv_len); |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 760 | drv->fw.mvm_fw = true; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 761 | break; |
| 762 | case IWL_UCODE_TLV_SEC_WOWLAN: |
| 763 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN, |
| 764 | tlv_len); |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 765 | drv->fw.mvm_fw = true; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 766 | break; |
| 767 | case IWL_UCODE_TLV_DEF_CALIB: |
| 768 | if (tlv_len != sizeof(struct iwl_tlv_calib_data)) |
| 769 | goto invalid_tlv_len; |
| 770 | if (iwl_set_default_calib(drv, tlv_data)) |
| 771 | goto tlv_error; |
| 772 | break; |
| 773 | case IWL_UCODE_TLV_PHY_SKU: |
| 774 | if (tlv_len != sizeof(u32)) |
| 775 | goto invalid_tlv_len; |
| 776 | drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 777 | drv->fw.valid_tx_ant = (drv->fw.phy_config & |
| 778 | FW_PHY_CFG_TX_CHAIN) >> |
| 779 | FW_PHY_CFG_TX_CHAIN_POS; |
| 780 | drv->fw.valid_rx_ant = (drv->fw.phy_config & |
| 781 | FW_PHY_CFG_RX_CHAIN) >> |
| 782 | FW_PHY_CFG_RX_CHAIN_POS; |
David Spinadel | ed8c836 | 2012-03-10 13:00:13 -0800 | [diff] [blame] | 783 | break; |
Eran Harary | e2d6f4e | 2013-10-02 13:53:40 +0300 | [diff] [blame] | 784 | case IWL_UCODE_TLV_SECURE_SEC_RT: |
| 785 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR, |
| 786 | tlv_len); |
| 787 | drv->fw.mvm_fw = true; |
| 788 | drv->fw.img[IWL_UCODE_REGULAR].is_secure = true; |
| 789 | break; |
| 790 | case IWL_UCODE_TLV_SECURE_SEC_INIT: |
| 791 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT, |
| 792 | tlv_len); |
| 793 | drv->fw.mvm_fw = true; |
| 794 | drv->fw.img[IWL_UCODE_INIT].is_secure = true; |
| 795 | break; |
| 796 | case IWL_UCODE_TLV_SECURE_SEC_WOWLAN: |
| 797 | iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN, |
| 798 | tlv_len); |
| 799 | drv->fw.mvm_fw = true; |
| 800 | drv->fw.img[IWL_UCODE_WOWLAN].is_secure = true; |
| 801 | break; |
| 802 | case IWL_UCODE_TLV_NUM_OF_CPU: |
| 803 | if (tlv_len != sizeof(u32)) |
| 804 | goto invalid_tlv_len; |
| 805 | num_of_cpus = |
| 806 | le32_to_cpup((__le32 *)tlv_data); |
| 807 | |
| 808 | if (num_of_cpus == 2) { |
| 809 | drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus = |
| 810 | true; |
| 811 | drv->fw.img[IWL_UCODE_INIT].is_dual_cpus = |
| 812 | true; |
| 813 | drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus = |
| 814 | true; |
| 815 | } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) { |
| 816 | IWL_ERR(drv, "Driver support upto 2 CPUs\n"); |
| 817 | return -EINVAL; |
| 818 | } |
| 819 | break; |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 820 | case IWL_UCODE_TLV_CSCHEME: |
| 821 | if (iwl_store_cscheme(&drv->fw, tlv_data, tlv_len)) |
| 822 | goto invalid_tlv_len; |
| 823 | break; |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 824 | case IWL_UCODE_TLV_N_SCAN_CHANNELS: |
| 825 | if (tlv_len != sizeof(u32)) |
| 826 | goto invalid_tlv_len; |
| 827 | capa->n_scan_channels = |
| 828 | le32_to_cpup((__le32 *)tlv_data); |
| 829 | break; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 830 | default: |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 831 | IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 832 | break; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | if (len) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 837 | IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len); |
| 838 | iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 839 | return -EINVAL; |
| 840 | } |
| 841 | |
| 842 | return 0; |
| 843 | |
| 844 | invalid_tlv_len: |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 845 | 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] | 846 | tlv_error: |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 847 | iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 848 | |
| 849 | return -EINVAL; |
| 850 | } |
| 851 | |
Johannes Berg | 75813bd | 2012-05-16 22:49:49 +0200 | [diff] [blame] | 852 | static int iwl_alloc_ucode(struct iwl_drv *drv, |
| 853 | struct iwl_firmware_pieces *pieces, |
| 854 | enum iwl_ucode_type type) |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 855 | { |
| 856 | int i; |
| 857 | for (i = 0; |
| 858 | i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i); |
| 859 | i++) |
| 860 | if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]), |
Johannes Berg | 75813bd | 2012-05-16 22:49:49 +0200 | [diff] [blame] | 861 | get_sec(pieces, type, i))) |
| 862 | return -ENOMEM; |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static int validate_sec_sizes(struct iwl_drv *drv, |
| 867 | struct iwl_firmware_pieces *pieces, |
| 868 | const struct iwl_cfg *cfg) |
| 869 | { |
| 870 | IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n", |
| 871 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 872 | IWL_UCODE_SECTION_INST)); |
| 873 | IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n", |
| 874 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 875 | IWL_UCODE_SECTION_DATA)); |
| 876 | IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n", |
| 877 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST)); |
| 878 | IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n", |
| 879 | get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)); |
| 880 | |
| 881 | /* Verify that uCode images will fit in card's SRAM. */ |
| 882 | if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) > |
| 883 | cfg->max_inst_size) { |
| 884 | IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n", |
| 885 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 886 | IWL_UCODE_SECTION_INST)); |
| 887 | return -1; |
| 888 | } |
| 889 | |
| 890 | if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) > |
| 891 | cfg->max_data_size) { |
| 892 | IWL_ERR(drv, "uCode data len %Zd too large to fit in\n", |
| 893 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 894 | IWL_UCODE_SECTION_DATA)); |
| 895 | return -1; |
| 896 | } |
| 897 | |
| 898 | if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) > |
| 899 | cfg->max_inst_size) { |
| 900 | IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n", |
| 901 | get_sec_size(pieces, IWL_UCODE_INIT, |
| 902 | IWL_UCODE_SECTION_INST)); |
| 903 | return -1; |
| 904 | } |
| 905 | |
| 906 | if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) > |
| 907 | cfg->max_data_size) { |
| 908 | IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n", |
| 909 | get_sec_size(pieces, IWL_UCODE_REGULAR, |
| 910 | IWL_UCODE_SECTION_DATA)); |
| 911 | return -1; |
| 912 | } |
| 913 | return 0; |
| 914 | } |
| 915 | |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 916 | static struct iwl_op_mode * |
| 917 | _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op) |
| 918 | { |
| 919 | const struct iwl_op_mode_ops *ops = op->ops; |
| 920 | struct dentry *dbgfs_dir = NULL; |
| 921 | struct iwl_op_mode *op_mode = NULL; |
| 922 | |
| 923 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 924 | drv->dbgfs_op_mode = debugfs_create_dir(op->name, |
| 925 | drv->dbgfs_drv); |
| 926 | if (!drv->dbgfs_op_mode) { |
| 927 | IWL_ERR(drv, |
| 928 | "failed to create opmode debugfs directory\n"); |
| 929 | return op_mode; |
| 930 | } |
| 931 | dbgfs_dir = drv->dbgfs_op_mode; |
| 932 | #endif |
| 933 | |
| 934 | op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir); |
| 935 | |
| 936 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 937 | if (!op_mode) { |
| 938 | debugfs_remove_recursive(drv->dbgfs_op_mode); |
| 939 | drv->dbgfs_op_mode = NULL; |
| 940 | } |
| 941 | #endif |
| 942 | |
| 943 | return op_mode; |
| 944 | } |
| 945 | |
| 946 | static void _iwl_op_mode_stop(struct iwl_drv *drv) |
| 947 | { |
| 948 | /* op_mode can be NULL if its start failed */ |
| 949 | if (drv->op_mode) { |
| 950 | iwl_op_mode_stop(drv->op_mode); |
| 951 | drv->op_mode = NULL; |
| 952 | |
| 953 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 954 | debugfs_remove_recursive(drv->dbgfs_op_mode); |
| 955 | drv->dbgfs_op_mode = NULL; |
| 956 | #endif |
| 957 | } |
| 958 | } |
| 959 | |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 960 | /** |
Emmanuel Grumbach | 1c8e11e | 2012-07-16 12:31:28 +0300 | [diff] [blame] | 961 | * iwl_req_fw_callback - callback when firmware was loaded |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 962 | * |
| 963 | * If loaded successfully, copies the firmware into buffers |
| 964 | * for the card to fetch (via DMA). |
| 965 | */ |
Emmanuel Grumbach | 1c8e11e | 2012-07-16 12:31:28 +0300 | [diff] [blame] | 966 | static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 967 | { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 968 | struct iwl_drv *drv = context; |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 969 | struct iwl_fw *fw = &drv->fw; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 970 | struct iwl_ucode_header *ucode; |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 971 | struct iwlwifi_opmode_table *op; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 972 | int err; |
David Spinadel | 0cedacc | 2012-03-10 13:00:12 -0800 | [diff] [blame] | 973 | struct iwl_firmware_pieces pieces; |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 974 | const unsigned int api_max = drv->cfg->ucode_api_max; |
| 975 | unsigned int api_ok = drv->cfg->ucode_api_ok; |
| 976 | const unsigned int api_min = drv->cfg->ucode_api_min; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 977 | u32 api_ver; |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 978 | int i; |
Johannes Berg | d4b1048 | 2012-06-12 19:50:43 +0200 | [diff] [blame] | 979 | bool load_module = false; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 980 | |
Luciano Coelho | 66140ad | 2013-08-12 19:30:21 +0300 | [diff] [blame] | 981 | fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 982 | fw->ucode_capa.standard_phy_calibration_size = |
| 983 | IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 984 | fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 985 | |
| 986 | if (!api_ok) |
| 987 | api_ok = api_max; |
| 988 | |
| 989 | memset(&pieces, 0, sizeof(pieces)); |
| 990 | |
| 991 | if (!ucode_raw) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 992 | if (drv->fw_index <= api_ok) |
| 993 | IWL_ERR(drv, |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 994 | "request for firmware file '%s' failed.\n", |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 995 | drv->firmware_name); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 996 | goto try_again; |
| 997 | } |
| 998 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 999 | IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n", |
| 1000 | drv->firmware_name, ucode_raw->size); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1001 | |
| 1002 | /* Make sure that we got at least the API version number */ |
| 1003 | if (ucode_raw->size < 4) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1004 | IWL_ERR(drv, "File size way too small!\n"); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1005 | goto try_again; |
| 1006 | } |
| 1007 | |
| 1008 | /* Data from ucode file: header followed by uCode images */ |
| 1009 | ucode = (struct iwl_ucode_header *)ucode_raw->data; |
| 1010 | |
| 1011 | if (ucode->ver) |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1012 | err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1013 | else |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1014 | err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces, |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1015 | &fw->ucode_capa); |
| 1016 | |
| 1017 | if (err) |
| 1018 | goto try_again; |
| 1019 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1020 | api_ver = IWL_UCODE_API(drv->fw.ucode_ver); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1021 | |
| 1022 | /* |
| 1023 | * api_ver should match the api version forming part of the |
| 1024 | * firmware filename ... but we don't check for that and only rely |
| 1025 | * on the API version read from firmware header from here on forward |
| 1026 | */ |
| 1027 | /* no api version check required for experimental uCode */ |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1028 | if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) { |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1029 | if (api_ver < api_min || api_ver > api_max) { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1030 | IWL_ERR(drv, |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1031 | "Driver unable to support your firmware API. " |
| 1032 | "Driver supports v%u, firmware is v%u.\n", |
| 1033 | api_max, api_ver); |
| 1034 | goto try_again; |
| 1035 | } |
| 1036 | |
| 1037 | if (api_ver < api_ok) { |
| 1038 | if (api_ok != api_max) |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1039 | IWL_ERR(drv, "Firmware has old API version, " |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1040 | "expected v%u through v%u, got v%u.\n", |
| 1041 | api_ok, api_max, api_ver); |
| 1042 | else |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1043 | IWL_ERR(drv, "Firmware has old API version, " |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1044 | "expected v%u, got v%u.\n", |
| 1045 | api_max, api_ver); |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1046 | IWL_ERR(drv, "New firmware can be obtained from " |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1047 | "http://www.intellinuxwireless.org/.\n"); |
| 1048 | } |
| 1049 | } |
| 1050 | |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1051 | /* |
David Spinadel | 4db2c9a | 2012-03-10 13:00:15 -0800 | [diff] [blame] | 1052 | * In mvm uCode there is no difference between data and instructions |
| 1053 | * sections. |
| 1054 | */ |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1055 | if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg)) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1056 | goto try_again; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1057 | |
| 1058 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 1059 | |
| 1060 | /* Runtime instructions and 2 copies of data: |
| 1061 | * 1) unmodified from disk |
| 1062 | * 2) backup cache for save/restore during power-downs */ |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 1063 | for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) |
Johannes Berg | 75813bd | 2012-05-16 22:49:49 +0200 | [diff] [blame] | 1064 | if (iwl_alloc_ucode(drv, &pieces, i)) |
| 1065 | goto out_free_fw; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1066 | |
| 1067 | /* Now that we can no longer fail, copy information */ |
| 1068 | |
| 1069 | /* |
| 1070 | * The (size - 16) / 12 formula is based on the information recorded |
| 1071 | * for each event, which is of mode 1 (including timestamp) for all |
| 1072 | * new microcodes that include this information. |
| 1073 | */ |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1074 | fw->init_evtlog_ptr = pieces.init_evtlog_ptr; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1075 | if (pieces.init_evtlog_size) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1076 | fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1077 | else |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1078 | fw->init_evtlog_size = |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1079 | drv->cfg->base_params->max_event_log_size; |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1080 | fw->init_errlog_ptr = pieces.init_errlog_ptr; |
| 1081 | fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1082 | if (pieces.inst_evtlog_size) |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1083 | fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1084 | else |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1085 | fw->inst_evtlog_size = |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1086 | drv->cfg->base_params->max_event_log_size; |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 1087 | fw->inst_errlog_ptr = pieces.inst_errlog_ptr; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1088 | |
| 1089 | /* |
| 1090 | * figure out the offset of chain noise reset and gain commands |
| 1091 | * base on the size of standard phy calibration commands table size |
| 1092 | */ |
| 1093 | if (fw->ucode_capa.standard_phy_calibration_size > |
| 1094 | IWL_MAX_PHY_CALIBRATE_TBL_SIZE) |
| 1095 | fw->ucode_capa.standard_phy_calibration_size = |
| 1096 | IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
| 1097 | |
| 1098 | /* We have our copies now, allow OS release its copies */ |
| 1099 | release_firmware(ucode_raw); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1100 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1101 | mutex_lock(&iwlwifi_opmode_table_mtx); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1102 | if (fw->mvm_fw) |
| 1103 | op = &iwlwifi_opmode_table[MVM_OP_MODE]; |
| 1104 | else |
| 1105 | op = &iwlwifi_opmode_table[DVM_OP_MODE]; |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1106 | |
Johannes Berg | 2b2719c | 2013-03-26 11:41:51 +0100 | [diff] [blame] | 1107 | IWL_INFO(drv, "loaded firmware version %s op_mode %s\n", |
| 1108 | drv->fw.fw_version, op->name); |
| 1109 | |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1110 | /* add this device to the list of devices using this op_mode */ |
| 1111 | list_add_tail(&drv->list, &op->drv); |
| 1112 | |
| 1113 | if (op->ops) { |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1114 | drv->op_mode = _iwl_op_mode_start(drv, op); |
John W. Linville | 7c9c46c | 2012-06-06 14:40:06 -0400 | [diff] [blame] | 1115 | |
Dan Carpenter | daf67ce | 2012-06-14 21:35:26 +0300 | [diff] [blame] | 1116 | if (!drv->op_mode) { |
| 1117 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
John W. Linville | 7c9c46c | 2012-06-06 14:40:06 -0400 | [diff] [blame] | 1118 | goto out_unbind; |
Dan Carpenter | daf67ce | 2012-06-14 21:35:26 +0300 | [diff] [blame] | 1119 | } |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1120 | } else { |
Johannes Berg | d4b1048 | 2012-06-12 19:50:43 +0200 | [diff] [blame] | 1121 | load_module = true; |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1122 | } |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1123 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1124 | |
Johannes Berg | f69a23b | 2012-06-05 19:56:06 +0200 | [diff] [blame] | 1125 | /* |
| 1126 | * Complete the firmware request last so that |
| 1127 | * a driver unbind (stop) doesn't run while we |
| 1128 | * are doing the start() above. |
| 1129 | */ |
| 1130 | complete(&drv->request_firmware_complete); |
Johannes Berg | d4b1048 | 2012-06-12 19:50:43 +0200 | [diff] [blame] | 1131 | |
| 1132 | /* |
| 1133 | * Load the module last so we don't block anything |
| 1134 | * else from proceeding if the module fails to load |
| 1135 | * or hangs loading. |
| 1136 | */ |
Johannes Berg | 1618b2b | 2013-04-04 10:35:23 +0200 | [diff] [blame] | 1137 | if (load_module) { |
| 1138 | err = request_module("%s", op->name); |
Johannes Berg | 8edf3fd | 2013-05-28 21:32:47 +0200 | [diff] [blame] | 1139 | #ifdef CONFIG_IWLWIFI_OPMODE_MODULAR |
Johannes Berg | 1618b2b | 2013-04-04 10:35:23 +0200 | [diff] [blame] | 1140 | if (err) |
| 1141 | IWL_ERR(drv, |
| 1142 | "failed to load module %s (error %d), is dynamic loading enabled?\n", |
| 1143 | op->name, err); |
Johannes Berg | 8edf3fd | 2013-05-28 21:32:47 +0200 | [diff] [blame] | 1144 | #endif |
Johannes Berg | 1618b2b | 2013-04-04 10:35:23 +0200 | [diff] [blame] | 1145 | } |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1146 | return; |
| 1147 | |
| 1148 | try_again: |
| 1149 | /* try next, if any */ |
| 1150 | release_firmware(ucode_raw); |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1151 | if (iwl_request_firmware(drv, false)) |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1152 | goto out_unbind; |
| 1153 | return; |
| 1154 | |
Johannes Berg | 75813bd | 2012-05-16 22:49:49 +0200 | [diff] [blame] | 1155 | out_free_fw: |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1156 | IWL_ERR(drv, "failed to allocate pci memory\n"); |
| 1157 | iwl_dealloc_ucode(drv); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1158 | release_firmware(ucode_raw); |
| 1159 | out_unbind: |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1160 | complete(&drv->request_firmware_complete); |
Emmanuel Grumbach | 93faaee | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1161 | device_release_driver(drv->trans->dev); |
Johannes Berg | 15854ef9 | 2012-03-05 11:24:50 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Emmanuel Grumbach | 87ce05a | 2012-03-26 09:03:18 -0700 | [diff] [blame] | 1164 | struct iwl_drv *iwl_drv_start(struct iwl_trans *trans, |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 1165 | const struct iwl_cfg *cfg) |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1166 | { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1167 | struct iwl_drv *drv; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1168 | int ret; |
| 1169 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1170 | drv = kzalloc(sizeof(*drv), GFP_KERNEL); |
Luciano Coelho | eafe25e | 2013-08-13 10:34:55 +0300 | [diff] [blame] | 1171 | if (!drv) { |
| 1172 | ret = -ENOMEM; |
| 1173 | goto err; |
| 1174 | } |
Emmanuel Grumbach | c15797e | 2012-04-19 10:29:58 +0300 | [diff] [blame] | 1175 | |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 1176 | drv->trans = trans; |
Emmanuel Grumbach | 4b9844f | 2012-03-22 23:59:52 +0200 | [diff] [blame] | 1177 | drv->dev = trans->dev; |
Emmanuel Grumbach | 68f360d | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 1178 | drv->cfg = cfg; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1179 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1180 | init_completion(&drv->request_firmware_complete); |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1181 | INIT_LIST_HEAD(&drv->list); |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1182 | |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1183 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1184 | /* Create the device debugfs entries. */ |
| 1185 | drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev), |
| 1186 | iwl_dbgfs_root); |
| 1187 | |
| 1188 | if (!drv->dbgfs_drv) { |
| 1189 | IWL_ERR(drv, "failed to create debugfs directory\n"); |
Emmanuel Grumbach | 59f547a | 2012-11-28 16:42:09 +0200 | [diff] [blame] | 1190 | ret = -ENOMEM; |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1191 | goto err_free_drv; |
| 1192 | } |
| 1193 | |
| 1194 | /* Create transport layer debugfs dir */ |
| 1195 | drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv); |
| 1196 | |
| 1197 | if (!drv->trans->dbgfs_dir) { |
| 1198 | IWL_ERR(drv, "failed to create transport debugfs directory\n"); |
Emmanuel Grumbach | 59f547a | 2012-11-28 16:42:09 +0200 | [diff] [blame] | 1199 | ret = -ENOMEM; |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1200 | goto err_free_dbgfs; |
| 1201 | } |
| 1202 | #endif |
| 1203 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1204 | ret = iwl_request_firmware(drv, true); |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1205 | if (ret) { |
Emmanuel Grumbach | c15797e | 2012-04-19 10:29:58 +0300 | [diff] [blame] | 1206 | IWL_ERR(trans, "Couldn't request the fw\n"); |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1207 | goto err_fw; |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 1210 | return drv; |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1211 | |
| 1212 | err_fw: |
| 1213 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1214 | err_free_dbgfs: |
| 1215 | debugfs_remove_recursive(drv->dbgfs_drv); |
| 1216 | err_free_drv: |
| 1217 | #endif |
| 1218 | kfree(drv); |
Luciano Coelho | eafe25e | 2013-08-13 10:34:55 +0300 | [diff] [blame] | 1219 | err: |
Emmanuel Grumbach | 59f547a | 2012-11-28 16:42:09 +0200 | [diff] [blame] | 1220 | return ERR_PTR(ret); |
Emmanuel Grumbach | 5c58edc | 2012-02-07 14:18:40 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
Emmanuel Grumbach | 9130bab | 2012-03-26 08:51:09 -0700 | [diff] [blame] | 1223 | void iwl_drv_stop(struct iwl_drv *drv) |
Emmanuel Grumbach | 07590f0 | 2012-02-07 14:27:31 +0200 | [diff] [blame] | 1224 | { |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1225 | wait_for_completion(&drv->request_firmware_complete); |
Johannes Berg | 2e7eb11 | 2012-03-05 11:24:51 -0800 | [diff] [blame] | 1226 | |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1227 | _iwl_op_mode_stop(drv); |
Emmanuel Grumbach | 07590f0 | 2012-02-07 14:27:31 +0200 | [diff] [blame] | 1228 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1229 | iwl_dealloc_ucode(drv); |
Johannes Berg | 7db5b98 | 2012-03-05 11:24:48 -0800 | [diff] [blame] | 1230 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1231 | mutex_lock(&iwlwifi_opmode_table_mtx); |
| 1232 | /* |
| 1233 | * List is empty (this item wasn't added) |
| 1234 | * when firmware loading failed -- in that |
| 1235 | * case we can't remove it from any list. |
| 1236 | */ |
| 1237 | if (!list_empty(&drv->list)) |
| 1238 | list_del(&drv->list); |
| 1239 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
| 1240 | |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1241 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1242 | debugfs_remove_recursive(drv->dbgfs_drv); |
| 1243 | #endif |
| 1244 | |
Johannes Berg | 965974a6 | 2012-03-06 13:30:38 -0800 | [diff] [blame] | 1245 | kfree(drv); |
Emmanuel Grumbach | 07590f0 | 2012-02-07 14:27:31 +0200 | [diff] [blame] | 1246 | } |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1247 | |
| 1248 | |
| 1249 | /* shared module parameters */ |
| 1250 | struct iwl_mod_params iwlwifi_mod_params = { |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 1251 | .restart_fw = true, |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1252 | .bt_coex_active = true, |
| 1253 | .power_level = IWL_POWER_INDEX_1, |
Emmanuel Grumbach | 020c876 | 2012-06-24 15:51:59 +0300 | [diff] [blame] | 1254 | .wd_disable = true, |
Matt Chen | 1504f48 | 2014-04-24 18:43:18 +0800 | [diff] [blame] | 1255 | .uapsd_disable = false, |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1256 | /* the rest are 0 by default */ |
| 1257 | }; |
Johannes Berg | 48e2934 | 2013-03-01 00:13:33 +0100 | [diff] [blame] | 1258 | IWL_EXPORT_SYMBOL(iwlwifi_mod_params); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1259 | |
| 1260 | int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops) |
| 1261 | { |
| 1262 | int i; |
| 1263 | struct iwl_drv *drv; |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1264 | struct iwlwifi_opmode_table *op; |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1265 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1266 | mutex_lock(&iwlwifi_opmode_table_mtx); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1267 | for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) { |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1268 | op = &iwlwifi_opmode_table[i]; |
| 1269 | if (strcmp(op->name, name)) |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1270 | continue; |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1271 | op->ops = ops; |
| 1272 | /* TODO: need to handle exceptional case */ |
| 1273 | list_for_each_entry(drv, &op->drv, list) |
| 1274 | drv->op_mode = _iwl_op_mode_start(drv, op); |
| 1275 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1276 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1277 | return 0; |
| 1278 | } |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1279 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1280 | return -EIO; |
| 1281 | } |
Johannes Berg | 48e2934 | 2013-03-01 00:13:33 +0100 | [diff] [blame] | 1282 | IWL_EXPORT_SYMBOL(iwl_opmode_register); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1283 | |
| 1284 | void iwl_opmode_deregister(const char *name) |
| 1285 | { |
| 1286 | int i; |
| 1287 | struct iwl_drv *drv; |
| 1288 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1289 | mutex_lock(&iwlwifi_opmode_table_mtx); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1290 | for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) { |
| 1291 | if (strcmp(iwlwifi_opmode_table[i].name, name)) |
| 1292 | continue; |
| 1293 | iwlwifi_opmode_table[i].ops = NULL; |
| 1294 | |
| 1295 | /* call the stop routine for all devices */ |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1296 | list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list) |
| 1297 | _iwl_op_mode_stop(drv); |
| 1298 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1299 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1300 | return; |
| 1301 | } |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1302 | mutex_unlock(&iwlwifi_opmode_table_mtx); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1303 | } |
Johannes Berg | 48e2934 | 2013-03-01 00:13:33 +0100 | [diff] [blame] | 1304 | IWL_EXPORT_SYMBOL(iwl_opmode_deregister); |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1305 | |
| 1306 | static int __init iwl_drv_init(void) |
| 1307 | { |
| 1308 | int i; |
| 1309 | |
Johannes Berg | ff1ffb8 | 2012-06-06 09:42:57 +0200 | [diff] [blame] | 1310 | mutex_init(&iwlwifi_opmode_table_mtx); |
| 1311 | |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1312 | for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) |
| 1313 | INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv); |
| 1314 | |
| 1315 | pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 1316 | pr_info(DRV_COPYRIGHT "\n"); |
| 1317 | |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1318 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1319 | /* Create the root of iwlwifi debugfs subsystem. */ |
| 1320 | iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL); |
| 1321 | |
| 1322 | if (!iwl_dbgfs_root) |
| 1323 | return -EFAULT; |
| 1324 | #endif |
| 1325 | |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1326 | return iwl_pci_register_driver(); |
| 1327 | } |
| 1328 | module_init(iwl_drv_init); |
| 1329 | |
| 1330 | static void __exit iwl_drv_exit(void) |
| 1331 | { |
| 1332 | iwl_pci_unregister_driver(); |
Meenakshi Venkataraman | 9da987a | 2012-07-16 18:43:56 -0700 | [diff] [blame] | 1333 | |
| 1334 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1335 | debugfs_remove_recursive(iwl_dbgfs_root); |
| 1336 | #endif |
Don Fry | cc5f7e3 | 2012-05-16 22:54:27 +0200 | [diff] [blame] | 1337 | } |
| 1338 | module_exit(iwl_drv_exit); |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1339 | |
| 1340 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1341 | module_param_named(debug, iwlwifi_mod_params.debug_level, uint, |
| 1342 | S_IRUGO | S_IWUSR); |
| 1343 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 1344 | #endif |
| 1345 | |
| 1346 | module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO); |
| 1347 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); |
| 1348 | module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO); |
| 1349 | MODULE_PARM_DESC(11n_disable, |
Emmanuel Grumbach | 205e221 | 2014-02-12 15:15:05 +0200 | [diff] [blame] | 1350 | "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX"); |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1351 | module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K, |
| 1352 | int, S_IRUGO); |
Emmanuel Grumbach | aed7d9a | 2013-02-20 11:33:00 +0200 | [diff] [blame] | 1353 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size (default 0)"); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 1354 | module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, bool, S_IRUGO); |
| 1355 | MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)"); |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1356 | |
| 1357 | module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling, |
| 1358 | int, S_IRUGO); |
| 1359 | MODULE_PARM_DESC(antenna_coupling, |
| 1360 | "specify antenna coupling in dB (defualt: 0 dB)"); |
| 1361 | |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1362 | module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO); |
| 1363 | MODULE_PARM_DESC(wd_disable, |
Eliad Peller | 82b715c | 2014-02-11 16:54:42 +0200 | [diff] [blame] | 1364 | "Disable stuck queue watchdog timer 0=system default, 1=disable (default: 1)"); |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1365 | |
Eran Harary | 1214755 | 2013-05-09 08:07:59 +0300 | [diff] [blame] | 1366 | module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, S_IRUGO); |
| 1367 | MODULE_PARM_DESC(nvm_file, "NVM file name"); |
| 1368 | |
Matt Chen | 1504f48 | 2014-04-24 18:43:18 +0800 | [diff] [blame] | 1369 | module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable, |
| 1370 | bool, S_IRUGO); |
| 1371 | MODULE_PARM_DESC(uapsd_disable, "disable U-APSD functionality (default: N)"); |
| 1372 | |
Johannes Berg | 65de7e8 | 2012-04-17 07:36:30 -0700 | [diff] [blame] | 1373 | /* |
| 1374 | * set bt_coex_active to true, uCode will do kill/defer |
| 1375 | * every time the priority line is asserted (BT is sending signals on the |
| 1376 | * priority line in the PCIx). |
| 1377 | * set bt_coex_active to false, uCode will ignore the BT activity and |
| 1378 | * perform the normal operation |
| 1379 | * |
| 1380 | * User might experience transmit issue on some platform due to WiFi/BT |
| 1381 | * co-exist problem. The possible behaviors are: |
| 1382 | * Able to scan and finding all the available AP |
| 1383 | * Not able to associate with any AP |
| 1384 | * On those platforms, WiFi communication can be restored by set |
| 1385 | * "bt_coex_active" module parameter to "false" |
| 1386 | * |
| 1387 | * default: bt_coex_active = true (BT_COEX_ENABLE) |
| 1388 | */ |
| 1389 | module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active, |
| 1390 | bool, S_IRUGO); |
| 1391 | MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)"); |
| 1392 | |
| 1393 | module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO); |
| 1394 | MODULE_PARM_DESC(led_mode, "0=system default, " |
| 1395 | "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)"); |
| 1396 | |
| 1397 | module_param_named(power_save, iwlwifi_mod_params.power_save, |
| 1398 | bool, S_IRUGO); |
| 1399 | MODULE_PARM_DESC(power_save, |
| 1400 | "enable WiFi power management (default: disable)"); |
| 1401 | |
| 1402 | module_param_named(power_level, iwlwifi_mod_params.power_level, |
| 1403 | int, S_IRUGO); |
| 1404 | MODULE_PARM_DESC(power_level, |
| 1405 | "default power save level (range from 1 - 5, default: 1)"); |