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