]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/iwlwifi/iwl-drv.c
iwlwifi: Add max TX aggregation size for 8260 SDIO devices series
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / iwlwifi / iwl-drv.c
CommitLineData
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 *
51368bf7 8 * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
4203263d 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
5c58edc6
EG
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
410dc5aa 26 * in the file called COPYING.
5c58edc6
EG
27 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
51368bf7 34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
4203263d 35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
5c58edc6
EG
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <linux/completion.h>
15854ef9
JB
66#include <linux/dma-mapping.h>
67#include <linux/firmware.h>
68#include <linux/module.h>
83f84d7b 69#include <linux/vmalloc.h>
5c58edc6
EG
70
71#include "iwl-drv.h"
2bf65081 72#include "iwl-csr.h"
c15797e6 73#include "iwl-debug.h"
5c58edc6 74#include "iwl-trans.h"
d0f76d68 75#include "iwl-op-mode.h"
0cedacc5 76#include "iwl-agn-hw.h"
6238b008
JB
77#include "iwl-fw.h"
78#include "iwl-config.h"
65de7e84 79#include "iwl-modparams.h"
5c58edc6 80
cc5f7e39
DF
81/******************************************************************************
82 *
83 * module boiler plate
84 *
85 ******************************************************************************/
86
cc5f7e39 87#define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
cc5f7e39 88MODULE_DESCRIPTION(DRV_DESCRIPTION);
cc5f7e39
DF
89MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
90MODULE_LICENSE("GPL");
91
9da987ac
MV
92#ifdef CONFIG_IWLWIFI_DEBUGFS
93static struct dentry *iwl_dbgfs_root;
94#endif
95
965974a6
JB
96/**
97 * struct iwl_drv - drv common data
cc5f7e39 98 * @list: list of drv structures using this opmode
965974a6 99 * @fw: the iwl_fw structure
965974a6 100 * @op_mode: the running op_mode
68f360dc 101 * @trans: transport layer
4b9844f5 102 * @dev: for debug prints only
68f360dc 103 * @cfg: configuration struct
965974a6
JB
104 * @fw_index: firmware revision to try loading
105 * @firmware_name: composite filename of ucode file to load
106 * @request_firmware_complete: the firmware has been obtained from user space
107 */
108struct iwl_drv {
cc5f7e39 109 struct list_head list;
965974a6
JB
110 struct iwl_fw fw;
111
965974a6 112 struct iwl_op_mode *op_mode;
9130bab1 113 struct iwl_trans *trans;
4b9844f5 114 struct device *dev;
68f360dc 115 const struct iwl_cfg *cfg;
965974a6
JB
116
117 int fw_index; /* firmware we're trying to load */
84b0312e 118 char firmware_name[32]; /* name of firmware file to load */
965974a6
JB
119
120 struct completion request_firmware_complete;
9da987ac
MV
121
122#ifdef CONFIG_IWLWIFI_DEBUGFS
123 struct dentry *dbgfs_drv;
124 struct dentry *dbgfs_trans;
125 struct dentry *dbgfs_op_mode;
126#endif
965974a6
JB
127};
128
8ca151b5
JB
129enum {
130 DVM_OP_MODE = 0,
131 MVM_OP_MODE = 1,
132};
965974a6 133
ff1ffb85
JB
134/* Protects the table contents, i.e. the ops pointer & drv list */
135static struct mutex iwlwifi_opmode_table_mtx;
cc5f7e39
DF
136static struct iwlwifi_opmode_table {
137 const char *name; /* name: iwldvm, iwlmvm, etc */
138 const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
139 struct list_head drv; /* list of devices using this op_mode */
140} iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
8ca151b5
JB
141 [DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL },
142 [MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL },
cc5f7e39 143};
965974a6 144
762533ba
DS
145#define IWL_DEFAULT_SCAN_CHANNELS 40
146
0cedacc5 147/*
0d365ae5 148 * struct fw_sec: Just for the image parsing process.
0cedacc5
DS
149 * For the fw storage we are using struct fw_desc.
150 */
151struct fw_sec {
152 const void *data; /* the sec data */
153 size_t size; /* section size */
154 u32 offset; /* offset of writing in the device */
155};
156
965974a6 157static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
15854ef9 158{
83f84d7b
JB
159 vfree(desc->data);
160 desc->data = NULL;
15854ef9
JB
161 desc->len = 0;
162}
163
965974a6 164static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
15854ef9 165{
6dfa8d01
DS
166 int i;
167 for (i = 0; i < IWL_UCODE_SECTION_MAX; i++)
168 iwl_free_fw_desc(drv, &img->sec[i]);
15854ef9
JB
169}
170
965974a6 171static void iwl_dealloc_ucode(struct iwl_drv *drv)
15854ef9 172{
6dfa8d01 173 int i;
490fefeb
LK
174
175 kfree(drv->fw.dbg_dest_tlv);
176 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_conf_tlv); i++)
177 kfree(drv->fw.dbg_conf_tlv[i]);
d2709ad7
EG
178 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_trigger_tlv); i++)
179 kfree(drv->fw.dbg_trigger_tlv[i]);
490fefeb 180
6dfa8d01
DS
181 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
182 iwl_free_fw_img(drv, drv->fw.img + i);
15854ef9
JB
183}
184
965974a6 185static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
83f84d7b 186 struct fw_sec *sec)
15854ef9 187{
83f84d7b
JB
188 void *data;
189
190 desc->data = NULL;
191
192 if (!sec || !sec->size)
15854ef9 193 return -EINVAL;
15854ef9 194
83f84d7b
JB
195 data = vmalloc(sec->size);
196 if (!data)
15854ef9
JB
197 return -ENOMEM;
198
0cedacc5
DS
199 desc->len = sec->size;
200 desc->offset = sec->offset;
83f84d7b
JB
201 memcpy(data, sec->data, desc->len);
202 desc->data = data;
203
15854ef9
JB
204 return 0;
205}
206
1c8e11e1
EG
207static void iwl_req_fw_callback(const struct firmware *ucode_raw,
208 void *context);
15854ef9
JB
209
210#define UCODE_EXPERIMENTAL_INDEX 100
211#define UCODE_EXPERIMENTAL_TAG "exp"
212
965974a6 213static int iwl_request_firmware(struct iwl_drv *drv, bool first)
15854ef9 214{
68f360dc 215 const char *name_pre = drv->cfg->fw_name_pre;
15854ef9
JB
216 char tag[8];
217
218 if (first) {
219#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
965974a6 220 drv->fw_index = UCODE_EXPERIMENTAL_INDEX;
15854ef9 221 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
965974a6 222 } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
15854ef9 223#endif
68f360dc 224 drv->fw_index = drv->cfg->ucode_api_max;
965974a6 225 sprintf(tag, "%d", drv->fw_index);
15854ef9 226 } else {
965974a6
JB
227 drv->fw_index--;
228 sprintf(tag, "%d", drv->fw_index);
15854ef9
JB
229 }
230
68f360dc 231 if (drv->fw_index < drv->cfg->ucode_api_min) {
965974a6 232 IWL_ERR(drv, "no suitable firmware found!\n");
15854ef9
JB
233 return -ENOENT;
234 }
235
84b0312e
LK
236 snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s%s.ucode",
237 name_pre, tag);
15854ef9 238
2bf65081
LK
239 /*
240 * Starting 8000B - FW name format has changed. This overwrites the
241 * previous name and uses the new format.
242 */
243 if (drv->trans->cfg->device_family == IWL_DEVICE_FAMILY_8000) {
5dd9c68a 244 char rev_step = 'A' + CSR_HW_REV_STEP(drv->trans->hw_rev);
2bf65081
LK
245
246 snprintf(drv->firmware_name, sizeof(drv->firmware_name),
5dd9c68a 247 "%s%c-%s.ucode", name_pre, rev_step, tag);
2bf65081
LK
248 }
249
965974a6
JB
250 IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n",
251 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
15854ef9 252 ? "EXPERIMENTAL " : "",
965974a6 253 drv->firmware_name);
15854ef9 254
965974a6 255 return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
93faaeea 256 drv->trans->dev,
1c8e11e1 257 GFP_KERNEL, drv, iwl_req_fw_callback);
15854ef9
JB
258}
259
0cedacc5 260struct fw_img_parsing {
6dfa8d01 261 struct fw_sec sec[IWL_UCODE_SECTION_MAX];
0cedacc5
DS
262 int sec_counter;
263};
264
ed8c8365
DS
265/*
266 * struct fw_sec_parsing: to extract fw section and it's offset from tlv
267 */
268struct fw_sec_parsing {
269 __le32 offset;
270 const u8 data[];
271} __packed;
272
273/**
274 * struct iwl_tlv_calib_data - parse the default calib data from TLV
275 *
276 * @ucode_type: the uCode to which the following default calib relates.
277 * @calib: default calibrations.
278 */
279struct iwl_tlv_calib_data {
280 __le32 ucode_type;
aa2b1770 281 struct iwl_tlv_calib_ctrl calib;
ed8c8365
DS
282} __packed;
283
0cedacc5
DS
284struct iwl_firmware_pieces {
285 struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
15854ef9
JB
286
287 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
288 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
490fefeb
LK
289
290 /* FW debug data parsed for driver usage */
291 struct iwl_fw_dbg_dest_tlv *dbg_dest_tlv;
d2709ad7
EG
292 struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
293 size_t dbg_conf_tlv_len[FW_DBG_CONF_MAX];
294 struct iwl_fw_dbg_trigger_tlv *dbg_trigger_tlv[FW_DBG_TRIGGER_MAX];
295 size_t dbg_trigger_tlv_len[FW_DBG_TRIGGER_MAX];
15854ef9
JB
296};
297
0cedacc5
DS
298/*
299 * These functions are just to extract uCode section data from the pieces
300 * structure.
301 */
302static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
303 enum iwl_ucode_type type,
304 int sec)
305{
306 return &pieces->img[type].sec[sec];
307}
308
309static void set_sec_data(struct iwl_firmware_pieces *pieces,
310 enum iwl_ucode_type type,
311 int sec,
312 const void *data)
313{
314 pieces->img[type].sec[sec].data = data;
315}
316
317static void set_sec_size(struct iwl_firmware_pieces *pieces,
318 enum iwl_ucode_type type,
319 int sec,
320 size_t size)
321{
322 pieces->img[type].sec[sec].size = size;
323}
324
325static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
326 enum iwl_ucode_type type,
327 int sec)
328{
329 return pieces->img[type].sec[sec].size;
330}
331
332static void set_sec_offset(struct iwl_firmware_pieces *pieces,
333 enum iwl_ucode_type type,
334 int sec,
335 u32 offset)
336{
337 pieces->img[type].sec[sec].offset = offset;
338}
339
e36e5433
MS
340static int iwl_store_cscheme(struct iwl_fw *fw, const u8 *data, const u32 len)
341{
342 int i, j;
343 struct iwl_fw_cscheme_list *l = (struct iwl_fw_cscheme_list *)data;
344 struct iwl_fw_cipher_scheme *fwcs;
345 struct ieee80211_cipher_scheme *cs;
346 u32 cipher;
347
348 if (len < sizeof(*l) ||
349 len < sizeof(l->size) + l->size * sizeof(l->cs[0]))
350 return -EINVAL;
351
352 for (i = 0, j = 0; i < IWL_UCODE_MAX_CS && i < l->size; i++) {
353 fwcs = &l->cs[j];
354 cipher = le32_to_cpu(fwcs->cipher);
355
356 /* we skip schemes with zero cipher suite selector */
357 if (!cipher)
358 continue;
359
360 cs = &fw->cs[j++];
361 cs->cipher = cipher;
362 cs->iftype = BIT(NL80211_IFTYPE_STATION);
363 cs->hdr_len = fwcs->hdr_len;
364 cs->pn_len = fwcs->pn_len;
365 cs->pn_off = fwcs->pn_off;
366 cs->key_idx_off = fwcs->key_idx_off;
367 cs->key_idx_mask = fwcs->key_idx_mask;
368 cs->key_idx_shift = fwcs->key_idx_shift;
369 cs->mic_len = fwcs->mic_len;
370 }
371
372 return 0;
373}
374
ed8c8365
DS
375/*
376 * Gets uCode section from tlv.
377 */
378static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
379 const void *data, enum iwl_ucode_type type,
380 int size)
381{
382 struct fw_img_parsing *img;
383 struct fw_sec *sec;
384 struct fw_sec_parsing *sec_parse;
385
386 if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
387 return -1;
388
389 sec_parse = (struct fw_sec_parsing *)data;
390
391 img = &pieces->img[type];
392 sec = &img->sec[img->sec_counter];
393
394 sec->offset = le32_to_cpu(sec_parse->offset);
395 sec->data = sec_parse->data;
1176f431 396 sec->size = size - sizeof(sec_parse->offset);
ed8c8365
DS
397
398 ++img->sec_counter;
399
400 return 0;
401}
402
403static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
404{
405 struct iwl_tlv_calib_data *def_calib =
406 (struct iwl_tlv_calib_data *)data;
407 u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
408 if (ucode_type >= IWL_UCODE_TYPE_MAX) {
409 IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
410 ucode_type);
411 return -EINVAL;
412 }
aa2b1770
JB
413 drv->fw.default_calib[ucode_type].flow_trigger =
414 def_calib->calib.flow_trigger;
415 drv->fw.default_calib[ucode_type].event_trigger =
416 def_calib->calib.event_trigger;
417
ed8c8365
DS
418 return 0;
419}
420
a2978b11
EH
421static int iwl_set_ucode_api_flags(struct iwl_drv *drv, const u8 *data,
422 struct iwl_ucode_capabilities *capa)
423{
424 const struct iwl_ucode_api *ucode_api = (void *)data;
425 u32 api_index = le32_to_cpu(ucode_api->api_index);
859d914c
JB
426 u32 api_flags = le32_to_cpu(ucode_api->api_flags);
427 int i;
a2978b11 428
859d914c 429 if (api_index >= IWL_API_MAX_BITS / 32) {
a2978b11 430 IWL_ERR(drv, "api_index larger than supported by driver\n");
859d914c
JB
431 /* don't return an error so we can load FW that has more bits */
432 return 0;
a2978b11
EH
433 }
434
859d914c
JB
435 for (i = 0; i < 32; i++) {
436 if (api_flags & BIT(i))
437 __set_bit(i + 32 * api_index, capa->_api);
438 }
a2978b11
EH
439
440 return 0;
441}
442
443static int iwl_set_ucode_capabilities(struct iwl_drv *drv, const u8 *data,
444 struct iwl_ucode_capabilities *capa)
445{
446 const struct iwl_ucode_capa *ucode_capa = (void *)data;
447 u32 api_index = le32_to_cpu(ucode_capa->api_index);
859d914c
JB
448 u32 api_flags = le32_to_cpu(ucode_capa->api_capa);
449 int i;
a2978b11 450
859d914c 451 if (api_index >= IWL_CAPABILITIES_MAX_BITS / 32) {
a2978b11 452 IWL_ERR(drv, "api_index larger than supported by driver\n");
859d914c
JB
453 /* don't return an error so we can load FW that has more bits */
454 return 0;
a2978b11
EH
455 }
456
859d914c
JB
457 for (i = 0; i < 32; i++) {
458 if (api_flags & BIT(i))
459 __set_bit(i + 32 * api_index, capa->_capa);
460 }
a2978b11
EH
461
462 return 0;
463}
464
965974a6 465static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
0cedacc5
DS
466 const struct firmware *ucode_raw,
467 struct iwl_firmware_pieces *pieces)
15854ef9
JB
468{
469 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
470 u32 api_ver, hdr_size, build;
471 char buildstr[25];
472 const u8 *src;
473
965974a6
JB
474 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
475 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
15854ef9
JB
476
477 switch (api_ver) {
478 default:
479 hdr_size = 28;
480 if (ucode_raw->size < hdr_size) {
965974a6 481 IWL_ERR(drv, "File size too small!\n");
15854ef9
JB
482 return -EINVAL;
483 }
484 build = le32_to_cpu(ucode->u.v2.build);
0cedacc5
DS
485 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
486 le32_to_cpu(ucode->u.v2.inst_size));
487 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
488 le32_to_cpu(ucode->u.v2.data_size));
489 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
490 le32_to_cpu(ucode->u.v2.init_size));
491 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
492 le32_to_cpu(ucode->u.v2.init_data_size));
15854ef9
JB
493 src = ucode->u.v2.data;
494 break;
495 case 0:
496 case 1:
497 case 2:
498 hdr_size = 24;
499 if (ucode_raw->size < hdr_size) {
965974a6 500 IWL_ERR(drv, "File size too small!\n");
15854ef9
JB
501 return -EINVAL;
502 }
503 build = 0;
0cedacc5
DS
504 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
505 le32_to_cpu(ucode->u.v1.inst_size));
506 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
507 le32_to_cpu(ucode->u.v1.data_size));
508 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
509 le32_to_cpu(ucode->u.v1.init_size));
510 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
511 le32_to_cpu(ucode->u.v1.init_data_size));
15854ef9
JB
512 src = ucode->u.v1.data;
513 break;
514 }
515
516 if (build)
517 sprintf(buildstr, " build %u%s", build,
965974a6 518 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
15854ef9
JB
519 ? " (EXP)" : "");
520 else
521 buildstr[0] = '\0';
522
965974a6
JB
523 snprintf(drv->fw.fw_version,
524 sizeof(drv->fw.fw_version),
15854ef9 525 "%u.%u.%u.%u%s",
965974a6
JB
526 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
527 IWL_UCODE_MINOR(drv->fw.ucode_ver),
528 IWL_UCODE_API(drv->fw.ucode_ver),
529 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
15854ef9
JB
530 buildstr);
531
532 /* Verify size of file vs. image size info in file's header */
0cedacc5
DS
533
534 if (ucode_raw->size != hdr_size +
535 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
536 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
537 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
538 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
15854ef9 539
965974a6 540 IWL_ERR(drv,
15854ef9
JB
541 "uCode file size %d does not match expected size\n",
542 (int)ucode_raw->size);
543 return -EINVAL;
544 }
545
15854ef9 546
0cedacc5
DS
547 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
548 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
549 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
550 IWLAGN_RTC_INST_LOWER_BOUND);
551 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
552 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
553 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
554 IWLAGN_RTC_DATA_LOWER_BOUND);
555 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
556 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
557 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
558 IWLAGN_RTC_INST_LOWER_BOUND);
559 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
560 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
561 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
562 IWLAGN_RTC_DATA_LOWER_BOUND);
15854ef9
JB
563 return 0;
564}
565
965974a6 566static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
15854ef9 567 const struct firmware *ucode_raw,
0cedacc5 568 struct iwl_firmware_pieces *pieces,
15854ef9
JB
569 struct iwl_ucode_capabilities *capa)
570{
571 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
572 struct iwl_ucode_tlv *tlv;
573 size_t len = ucode_raw->size;
574 const u8 *data;
15854ef9 575 u32 tlv_len;
a6c4fb44 576 u32 usniffer_img;
15854ef9
JB
577 enum iwl_ucode_tlv_type tlv_type;
578 const u8 *tlv_data;
579 char buildstr[25];
a6c4fb44 580 u32 build, paging_mem_size;
e2d6f4e7 581 int num_of_cpus;
61df750c
EH
582 bool usniffer_images = false;
583 bool usniffer_req = false;
15854ef9
JB
584
585 if (len < sizeof(*ucode)) {
965974a6 586 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
15854ef9
JB
587 return -EINVAL;
588 }
589
590 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
965974a6 591 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
15854ef9
JB
592 le32_to_cpu(ucode->magic));
593 return -EINVAL;
594 }
595
965974a6 596 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
06ddbf5a
EG
597 memcpy(drv->fw.human_readable, ucode->human_readable,
598 sizeof(drv->fw.human_readable));
15854ef9
JB
599 build = le32_to_cpu(ucode->build);
600
601 if (build)
602 sprintf(buildstr, " build %u%s", build,
965974a6 603 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
15854ef9
JB
604 ? " (EXP)" : "");
605 else
606 buildstr[0] = '\0';
607
965974a6
JB
608 snprintf(drv->fw.fw_version,
609 sizeof(drv->fw.fw_version),
15854ef9 610 "%u.%u.%u.%u%s",
965974a6
JB
611 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
612 IWL_UCODE_MINOR(drv->fw.ucode_ver),
613 IWL_UCODE_API(drv->fw.ucode_ver),
614 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
15854ef9
JB
615 buildstr);
616
617 data = ucode->data;
618
619 len -= sizeof(*ucode);
620
621 while (len >= sizeof(*tlv)) {
15854ef9
JB
622 len -= sizeof(*tlv);
623 tlv = (void *)data;
624
625 tlv_len = le32_to_cpu(tlv->length);
0479c19d 626 tlv_type = le32_to_cpu(tlv->type);
15854ef9
JB
627 tlv_data = tlv->data;
628
629 if (len < tlv_len) {
965974a6 630 IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
15854ef9
JB
631 len, tlv_len);
632 return -EINVAL;
633 }
634 len -= ALIGN(tlv_len, 4);
635 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
636
15854ef9
JB
637 switch (tlv_type) {
638 case IWL_UCODE_TLV_INST:
0cedacc5
DS
639 set_sec_data(pieces, IWL_UCODE_REGULAR,
640 IWL_UCODE_SECTION_INST, tlv_data);
641 set_sec_size(pieces, IWL_UCODE_REGULAR,
642 IWL_UCODE_SECTION_INST, tlv_len);
643 set_sec_offset(pieces, IWL_UCODE_REGULAR,
644 IWL_UCODE_SECTION_INST,
645 IWLAGN_RTC_INST_LOWER_BOUND);
15854ef9
JB
646 break;
647 case IWL_UCODE_TLV_DATA:
0cedacc5
DS
648 set_sec_data(pieces, IWL_UCODE_REGULAR,
649 IWL_UCODE_SECTION_DATA, tlv_data);
650 set_sec_size(pieces, IWL_UCODE_REGULAR,
651 IWL_UCODE_SECTION_DATA, tlv_len);
652 set_sec_offset(pieces, IWL_UCODE_REGULAR,
653 IWL_UCODE_SECTION_DATA,
654 IWLAGN_RTC_DATA_LOWER_BOUND);
15854ef9
JB
655 break;
656 case IWL_UCODE_TLV_INIT:
0cedacc5
DS
657 set_sec_data(pieces, IWL_UCODE_INIT,
658 IWL_UCODE_SECTION_INST, tlv_data);
659 set_sec_size(pieces, IWL_UCODE_INIT,
660 IWL_UCODE_SECTION_INST, tlv_len);
661 set_sec_offset(pieces, IWL_UCODE_INIT,
662 IWL_UCODE_SECTION_INST,
663 IWLAGN_RTC_INST_LOWER_BOUND);
15854ef9
JB
664 break;
665 case IWL_UCODE_TLV_INIT_DATA:
0cedacc5
DS
666 set_sec_data(pieces, IWL_UCODE_INIT,
667 IWL_UCODE_SECTION_DATA, tlv_data);
668 set_sec_size(pieces, IWL_UCODE_INIT,
669 IWL_UCODE_SECTION_DATA, tlv_len);
670 set_sec_offset(pieces, IWL_UCODE_INIT,
671 IWL_UCODE_SECTION_DATA,
672 IWLAGN_RTC_DATA_LOWER_BOUND);
15854ef9
JB
673 break;
674 case IWL_UCODE_TLV_BOOT:
965974a6 675 IWL_ERR(drv, "Found unexpected BOOT ucode\n");
15854ef9
JB
676 break;
677 case IWL_UCODE_TLV_PROBE_MAX_LEN:
678 if (tlv_len != sizeof(u32))
679 goto invalid_tlv_len;
680 capa->max_probe_length =
681 le32_to_cpup((__le32 *)tlv_data);
682 break;
683 case IWL_UCODE_TLV_PAN:
684 if (tlv_len)
685 goto invalid_tlv_len;
686 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
687 break;
688 case IWL_UCODE_TLV_FLAGS:
689 /* must be at least one u32 */
690 if (tlv_len < sizeof(u32))
691 goto invalid_tlv_len;
692 /* and a proper number of u32s */
693 if (tlv_len % sizeof(u32))
694 goto invalid_tlv_len;
695 /*
696 * This driver only reads the first u32 as
697 * right now no more features are defined,
698 * if that changes then either the driver
699 * will not work with the new firmware, or
700 * it'll not take advantage of new features.
701 */
702 capa->flags = le32_to_cpup((__le32 *)tlv_data);
703 break;
a2978b11
EH
704 case IWL_UCODE_TLV_API_CHANGES_SET:
705 if (tlv_len != sizeof(struct iwl_ucode_api))
706 goto invalid_tlv_len;
707 if (iwl_set_ucode_api_flags(drv, tlv_data, capa))
708 goto tlv_error;
709 break;
710 case IWL_UCODE_TLV_ENABLED_CAPABILITIES:
711 if (tlv_len != sizeof(struct iwl_ucode_capa))
712 goto invalid_tlv_len;
713 if (iwl_set_ucode_capabilities(drv, tlv_data, capa))
714 goto tlv_error;
715 break;
15854ef9
JB
716 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
717 if (tlv_len != sizeof(u32))
718 goto invalid_tlv_len;
719 pieces->init_evtlog_ptr =
720 le32_to_cpup((__le32 *)tlv_data);
721 break;
722 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
723 if (tlv_len != sizeof(u32))
724 goto invalid_tlv_len;
725 pieces->init_evtlog_size =
726 le32_to_cpup((__le32 *)tlv_data);
727 break;
728 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
729 if (tlv_len != sizeof(u32))
730 goto invalid_tlv_len;
731 pieces->init_errlog_ptr =
732 le32_to_cpup((__le32 *)tlv_data);
733 break;
734 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
735 if (tlv_len != sizeof(u32))
736 goto invalid_tlv_len;
737 pieces->inst_evtlog_ptr =
738 le32_to_cpup((__le32 *)tlv_data);
739 break;
740 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
741 if (tlv_len != sizeof(u32))
742 goto invalid_tlv_len;
743 pieces->inst_evtlog_size =
744 le32_to_cpup((__le32 *)tlv_data);
745 break;
746 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
747 if (tlv_len != sizeof(u32))
748 goto invalid_tlv_len;
749 pieces->inst_errlog_ptr =
750 le32_to_cpup((__le32 *)tlv_data);
751 break;
752 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
753 if (tlv_len)
754 goto invalid_tlv_len;
965974a6 755 drv->fw.enhance_sensitivity_table = true;
15854ef9
JB
756 break;
757 case IWL_UCODE_TLV_WOWLAN_INST:
0cedacc5
DS
758 set_sec_data(pieces, IWL_UCODE_WOWLAN,
759 IWL_UCODE_SECTION_INST, tlv_data);
760 set_sec_size(pieces, IWL_UCODE_WOWLAN,
761 IWL_UCODE_SECTION_INST, tlv_len);
762 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
763 IWL_UCODE_SECTION_INST,
764 IWLAGN_RTC_INST_LOWER_BOUND);
15854ef9
JB
765 break;
766 case IWL_UCODE_TLV_WOWLAN_DATA:
0cedacc5
DS
767 set_sec_data(pieces, IWL_UCODE_WOWLAN,
768 IWL_UCODE_SECTION_DATA, tlv_data);
769 set_sec_size(pieces, IWL_UCODE_WOWLAN,
770 IWL_UCODE_SECTION_DATA, tlv_len);
771 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
772 IWL_UCODE_SECTION_DATA,
773 IWLAGN_RTC_DATA_LOWER_BOUND);
15854ef9
JB
774 break;
775 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
776 if (tlv_len != sizeof(u32))
777 goto invalid_tlv_len;
778 capa->standard_phy_calibration_size =
779 le32_to_cpup((__le32 *)tlv_data);
780 break;
ed8c8365
DS
781 case IWL_UCODE_TLV_SEC_RT:
782 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
783 tlv_len);
4db2c9ae 784 drv->fw.mvm_fw = true;
ed8c8365
DS
785 break;
786 case IWL_UCODE_TLV_SEC_INIT:
787 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
788 tlv_len);
4db2c9ae 789 drv->fw.mvm_fw = true;
ed8c8365
DS
790 break;
791 case IWL_UCODE_TLV_SEC_WOWLAN:
792 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
793 tlv_len);
4db2c9ae 794 drv->fw.mvm_fw = true;
ed8c8365
DS
795 break;
796 case IWL_UCODE_TLV_DEF_CALIB:
797 if (tlv_len != sizeof(struct iwl_tlv_calib_data))
798 goto invalid_tlv_len;
799 if (iwl_set_default_calib(drv, tlv_data))
800 goto tlv_error;
801 break;
802 case IWL_UCODE_TLV_PHY_SKU:
803 if (tlv_len != sizeof(u32))
804 goto invalid_tlv_len;
805 drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
77db0a3c
EH
806 drv->fw.valid_tx_ant = (drv->fw.phy_config &
807 FW_PHY_CFG_TX_CHAIN) >>
808 FW_PHY_CFG_TX_CHAIN_POS;
809 drv->fw.valid_rx_ant = (drv->fw.phy_config &
810 FW_PHY_CFG_RX_CHAIN) >>
811 FW_PHY_CFG_RX_CHAIN_POS;
ed8c8365 812 break;
e2d6f4e7
EH
813 case IWL_UCODE_TLV_SECURE_SEC_RT:
814 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
815 tlv_len);
816 drv->fw.mvm_fw = true;
e2d6f4e7
EH
817 break;
818 case IWL_UCODE_TLV_SECURE_SEC_INIT:
819 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
820 tlv_len);
821 drv->fw.mvm_fw = true;
e2d6f4e7
EH
822 break;
823 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
824 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
825 tlv_len);
826 drv->fw.mvm_fw = true;
e2d6f4e7
EH
827 break;
828 case IWL_UCODE_TLV_NUM_OF_CPU:
829 if (tlv_len != sizeof(u32))
830 goto invalid_tlv_len;
831 num_of_cpus =
832 le32_to_cpup((__le32 *)tlv_data);
833
834 if (num_of_cpus == 2) {
835 drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
836 true;
837 drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
838 true;
839 drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
840 true;
841 } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
842 IWL_ERR(drv, "Driver support upto 2 CPUs\n");
843 return -EINVAL;
844 }
845 break;
e36e5433
MS
846 case IWL_UCODE_TLV_CSCHEME:
847 if (iwl_store_cscheme(&drv->fw, tlv_data, tlv_len))
848 goto invalid_tlv_len;
849 break;
762533ba
DS
850 case IWL_UCODE_TLV_N_SCAN_CHANNELS:
851 if (tlv_len != sizeof(u32))
852 goto invalid_tlv_len;
853 capa->n_scan_channels =
854 le32_to_cpup((__le32 *)tlv_data);
855 break;
7e1223b5
EG
856 case IWL_UCODE_TLV_FW_VERSION: {
857 __le32 *ptr = (void *)tlv_data;
858 u32 major, minor;
859 u8 local_comp;
860
861 if (tlv_len != sizeof(u32) * 3)
862 goto invalid_tlv_len;
863
864 major = le32_to_cpup(ptr++);
865 minor = le32_to_cpup(ptr++);
866 local_comp = le32_to_cpup(ptr);
867
868 snprintf(drv->fw.fw_version,
869 sizeof(drv->fw.fw_version), "%u.%u.%u",
870 major, minor, local_comp);
871 break;
872 }
490fefeb
LK
873 case IWL_UCODE_TLV_FW_DBG_DEST: {
874 struct iwl_fw_dbg_dest_tlv *dest = (void *)tlv_data;
875
876 if (pieces->dbg_dest_tlv) {
877 IWL_ERR(drv,
878 "dbg destination ignored, already exists\n");
879 break;
880 }
881
882 pieces->dbg_dest_tlv = dest;
883 IWL_INFO(drv, "Found debug destination: %s\n",
884 get_fw_dbg_mode_string(dest->monitor_mode));
885
886 drv->fw.dbg_dest_reg_num =
887 tlv_len - offsetof(struct iwl_fw_dbg_dest_tlv,
888 reg_ops);
889 drv->fw.dbg_dest_reg_num /=
890 sizeof(drv->fw.dbg_dest_tlv->reg_ops[0]);
891
892 break;
893 }
894 case IWL_UCODE_TLV_FW_DBG_CONF: {
895 struct iwl_fw_dbg_conf_tlv *conf = (void *)tlv_data;
896
897 if (!pieces->dbg_dest_tlv) {
898 IWL_ERR(drv,
899 "Ignore dbg config %d - no destination configured\n",
900 conf->id);
901 break;
902 }
903
904 if (conf->id >= ARRAY_SIZE(drv->fw.dbg_conf_tlv)) {
905 IWL_ERR(drv,
906 "Skip unknown configuration: %d\n",
907 conf->id);
908 break;
909 }
910
911 if (pieces->dbg_conf_tlv[conf->id]) {
912 IWL_ERR(drv,
913 "Ignore duplicate dbg config %d\n",
914 conf->id);
915 break;
916 }
917
61df750c
EH
918 if (conf->usniffer)
919 usniffer_req = true;
920
490fefeb
LK
921 IWL_INFO(drv, "Found debug configuration: %d\n",
922 conf->id);
923
924 pieces->dbg_conf_tlv[conf->id] = conf;
925 pieces->dbg_conf_tlv_len[conf->id] = tlv_len;
926 break;
927 }
d2709ad7
EG
928 case IWL_UCODE_TLV_FW_DBG_TRIGGER: {
929 struct iwl_fw_dbg_trigger_tlv *trigger =
930 (void *)tlv_data;
931 u32 trigger_id = le32_to_cpu(trigger->id);
932
933 if (trigger_id >= ARRAY_SIZE(drv->fw.dbg_trigger_tlv)) {
934 IWL_ERR(drv,
935 "Skip unknown trigger: %u\n",
936 trigger->id);
937 break;
938 }
939
940 if (pieces->dbg_trigger_tlv[trigger_id]) {
941 IWL_ERR(drv,
942 "Ignore duplicate dbg trigger %u\n",
943 trigger->id);
944 break;
945 }
946
947 IWL_INFO(drv, "Found debug trigger: %u\n", trigger->id);
948
949 pieces->dbg_trigger_tlv[trigger_id] = trigger;
950 pieces->dbg_trigger_tlv_len[trigger_id] = tlv_len;
951 break;
952 }
61df750c
EH
953 case IWL_UCODE_TLV_SEC_RT_USNIFFER:
954 usniffer_images = true;
955 iwl_store_ucode_sec(pieces, tlv_data,
956 IWL_UCODE_REGULAR_USNIFFER,
957 tlv_len);
958 break;
a6c4fb44
MG
959 case IWL_UCODE_TLV_PAGING:
960 if (tlv_len != sizeof(u32))
961 goto invalid_tlv_len;
962 paging_mem_size = le32_to_cpup((__le32 *)tlv_data);
963
964 IWL_DEBUG_FW(drv,
965 "Paging: paging enabled (size = %u bytes)\n",
966 paging_mem_size);
967
968 if (paging_mem_size > MAX_PAGING_IMAGE_SIZE) {
969 IWL_ERR(drv,
970 "Paging: driver supports up to %lu bytes for paging image\n",
971 MAX_PAGING_IMAGE_SIZE);
972 return -EINVAL;
973 }
974
975 if (paging_mem_size & (FW_PAGING_SIZE - 1)) {
976 IWL_ERR(drv,
977 "Paging: image isn't multiple %lu\n",
978 FW_PAGING_SIZE);
979 return -EINVAL;
980 }
981
982 drv->fw.img[IWL_UCODE_REGULAR].paging_mem_size =
983 paging_mem_size;
984 usniffer_img = IWL_UCODE_REGULAR_USNIFFER;
985 drv->fw.img[usniffer_img].paging_mem_size =
986 paging_mem_size;
987 break;
b4821767
LK
988 case IWL_UCODE_TLV_SDIO_ADMA_ADDR:
989 if (tlv_len != sizeof(u32))
990 goto invalid_tlv_len;
991 drv->fw.sdio_adma_addr =
992 le32_to_cpup((__le32 *)tlv_data);
993 break;
15854ef9 994 default:
965974a6 995 IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
15854ef9
JB
996 break;
997 }
998 }
999
61df750c
EH
1000 if (usniffer_req && !usniffer_images) {
1001 IWL_ERR(drv,
1002 "user selected to work with usniffer but usniffer image isn't available in ucode package\n");
1003 return -EINVAL;
1004 }
1005
15854ef9 1006 if (len) {
965974a6
JB
1007 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
1008 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
15854ef9
JB
1009 return -EINVAL;
1010 }
1011
1012 return 0;
1013
1014 invalid_tlv_len:
965974a6 1015 IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
ed8c8365 1016 tlv_error:
965974a6 1017 iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
15854ef9
JB
1018
1019 return -EINVAL;
1020}
1021
75813bde
JB
1022static int iwl_alloc_ucode(struct iwl_drv *drv,
1023 struct iwl_firmware_pieces *pieces,
1024 enum iwl_ucode_type type)
6dfa8d01
DS
1025{
1026 int i;
1027 for (i = 0;
1028 i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
1029 i++)
1030 if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
75813bde
JB
1031 get_sec(pieces, type, i)))
1032 return -ENOMEM;
6dfa8d01
DS
1033 return 0;
1034}
1035
1036static int validate_sec_sizes(struct iwl_drv *drv,
1037 struct iwl_firmware_pieces *pieces,
1038 const struct iwl_cfg *cfg)
1039{
1040 IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
1041 get_sec_size(pieces, IWL_UCODE_REGULAR,
1042 IWL_UCODE_SECTION_INST));
1043 IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
1044 get_sec_size(pieces, IWL_UCODE_REGULAR,
1045 IWL_UCODE_SECTION_DATA));
1046 IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
1047 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
1048 IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
1049 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
1050
1051 /* Verify that uCode images will fit in card's SRAM. */
1052 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
e70fe7eb 1053 cfg->max_inst_size) {
6dfa8d01
DS
1054 IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
1055 get_sec_size(pieces, IWL_UCODE_REGULAR,
e70fe7eb 1056 IWL_UCODE_SECTION_INST));
6dfa8d01
DS
1057 return -1;
1058 }
1059
1060 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
e70fe7eb 1061 cfg->max_data_size) {
6dfa8d01
DS
1062 IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
1063 get_sec_size(pieces, IWL_UCODE_REGULAR,
e70fe7eb 1064 IWL_UCODE_SECTION_DATA));
6dfa8d01
DS
1065 return -1;
1066 }
1067
e70fe7eb
EG
1068 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
1069 cfg->max_inst_size) {
6dfa8d01
DS
1070 IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
1071 get_sec_size(pieces, IWL_UCODE_INIT,
e70fe7eb 1072 IWL_UCODE_SECTION_INST));
6dfa8d01
DS
1073 return -1;
1074 }
1075
1076 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
e70fe7eb 1077 cfg->max_data_size) {
6dfa8d01
DS
1078 IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
1079 get_sec_size(pieces, IWL_UCODE_REGULAR,
e70fe7eb 1080 IWL_UCODE_SECTION_DATA));
6dfa8d01
DS
1081 return -1;
1082 }
1083 return 0;
1084}
1085
9da987ac
MV
1086static struct iwl_op_mode *
1087_iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
1088{
1089 const struct iwl_op_mode_ops *ops = op->ops;
1090 struct dentry *dbgfs_dir = NULL;
1091 struct iwl_op_mode *op_mode = NULL;
1092
1093#ifdef CONFIG_IWLWIFI_DEBUGFS
1094 drv->dbgfs_op_mode = debugfs_create_dir(op->name,
1095 drv->dbgfs_drv);
1096 if (!drv->dbgfs_op_mode) {
1097 IWL_ERR(drv,
1098 "failed to create opmode debugfs directory\n");
1099 return op_mode;
1100 }
1101 dbgfs_dir = drv->dbgfs_op_mode;
1102#endif
1103
1104 op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
1105
1106#ifdef CONFIG_IWLWIFI_DEBUGFS
1107 if (!op_mode) {
1108 debugfs_remove_recursive(drv->dbgfs_op_mode);
1109 drv->dbgfs_op_mode = NULL;
1110 }
1111#endif
1112
1113 return op_mode;
1114}
1115
1116static void _iwl_op_mode_stop(struct iwl_drv *drv)
1117{
1118 /* op_mode can be NULL if its start failed */
1119 if (drv->op_mode) {
1120 iwl_op_mode_stop(drv->op_mode);
1121 drv->op_mode = NULL;
1122
1123#ifdef CONFIG_IWLWIFI_DEBUGFS
1124 debugfs_remove_recursive(drv->dbgfs_op_mode);
1125 drv->dbgfs_op_mode = NULL;
1126#endif
1127 }
1128}
1129
15854ef9 1130/**
1c8e11e1 1131 * iwl_req_fw_callback - callback when firmware was loaded
15854ef9
JB
1132 *
1133 * If loaded successfully, copies the firmware into buffers
1134 * for the card to fetch (via DMA).
1135 */
1c8e11e1 1136static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
15854ef9 1137{
965974a6 1138 struct iwl_drv *drv = context;
965974a6 1139 struct iwl_fw *fw = &drv->fw;
15854ef9 1140 struct iwl_ucode_header *ucode;
cc5f7e39 1141 struct iwlwifi_opmode_table *op;
15854ef9 1142 int err;
490fefeb 1143 struct iwl_firmware_pieces *pieces;
68f360dc
EG
1144 const unsigned int api_max = drv->cfg->ucode_api_max;
1145 unsigned int api_ok = drv->cfg->ucode_api_ok;
1146 const unsigned int api_min = drv->cfg->ucode_api_min;
2841a2d3 1147 size_t trigger_tlv_sz[FW_DBG_TRIGGER_MAX];
15854ef9 1148 u32 api_ver;
6dfa8d01 1149 int i;
d4b10483 1150 bool load_module = false;
15854ef9 1151
66140adc 1152 fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
15854ef9
JB
1153 fw->ucode_capa.standard_phy_calibration_size =
1154 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
762533ba 1155 fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS;
15854ef9
JB
1156
1157 if (!api_ok)
1158 api_ok = api_max;
1159
490fefeb
LK
1160 pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
1161 if (!pieces)
1162 return;
15854ef9
JB
1163
1164 if (!ucode_raw) {
965974a6
JB
1165 if (drv->fw_index <= api_ok)
1166 IWL_ERR(drv,
15854ef9 1167 "request for firmware file '%s' failed.\n",
965974a6 1168 drv->firmware_name);
15854ef9
JB
1169 goto try_again;
1170 }
1171
965974a6
JB
1172 IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
1173 drv->firmware_name, ucode_raw->size);
15854ef9
JB
1174
1175 /* Make sure that we got at least the API version number */
1176 if (ucode_raw->size < 4) {
965974a6 1177 IWL_ERR(drv, "File size way too small!\n");
15854ef9
JB
1178 goto try_again;
1179 }
1180
1181 /* Data from ucode file: header followed by uCode images */
1182 ucode = (struct iwl_ucode_header *)ucode_raw->data;
1183
1184 if (ucode->ver)
490fefeb 1185 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, pieces);
15854ef9 1186 else
490fefeb
LK
1187 err = iwl_parse_tlv_firmware(drv, ucode_raw, pieces,
1188 &fw->ucode_capa);
15854ef9
JB
1189
1190 if (err)
1191 goto try_again;
1192
859d914c 1193 if (fw_has_api(&drv->fw.ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION))
7e1223b5
EG
1194 api_ver = drv->fw.ucode_ver;
1195 else
1196 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
15854ef9
JB
1197
1198 /*
1199 * api_ver should match the api version forming part of the
1200 * firmware filename ... but we don't check for that and only rely
1201 * on the API version read from firmware header from here on forward
1202 */
1203 /* no api version check required for experimental uCode */
965974a6 1204 if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
15854ef9 1205 if (api_ver < api_min || api_ver > api_max) {
965974a6 1206 IWL_ERR(drv,
15854ef9
JB
1207 "Driver unable to support your firmware API. "
1208 "Driver supports v%u, firmware is v%u.\n",
1209 api_max, api_ver);
1210 goto try_again;
1211 }
1212
1213 if (api_ver < api_ok) {
1214 if (api_ok != api_max)
965974a6 1215 IWL_ERR(drv, "Firmware has old API version, "
15854ef9
JB
1216 "expected v%u through v%u, got v%u.\n",
1217 api_ok, api_max, api_ver);
1218 else
965974a6 1219 IWL_ERR(drv, "Firmware has old API version, "
15854ef9
JB
1220 "expected v%u, got v%u.\n",
1221 api_max, api_ver);
965974a6 1222 IWL_ERR(drv, "New firmware can be obtained from "
15854ef9
JB
1223 "http://www.intellinuxwireless.org/.\n");
1224 }
1225 }
1226
4db2c9ae
DS
1227 /*
1228 * In mvm uCode there is no difference between data and instructions
1229 * sections.
1230 */
490fefeb 1231 if (!fw->mvm_fw && validate_sec_sizes(drv, pieces, drv->cfg))
15854ef9 1232 goto try_again;
15854ef9
JB
1233
1234 /* Allocate ucode buffers for card's bus-master loading ... */
1235
1236 /* Runtime instructions and 2 copies of data:
1237 * 1) unmodified from disk
1238 * 2) backup cache for save/restore during power-downs */
6dfa8d01 1239 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
490fefeb 1240 if (iwl_alloc_ucode(drv, pieces, i))
75813bde 1241 goto out_free_fw;
15854ef9 1242
490fefeb
LK
1243 if (pieces->dbg_dest_tlv) {
1244 drv->fw.dbg_dest_tlv =
1245 kmemdup(pieces->dbg_dest_tlv,
1246 sizeof(*pieces->dbg_dest_tlv) +
1247 sizeof(pieces->dbg_dest_tlv->reg_ops[0]) *
1248 drv->fw.dbg_dest_reg_num, GFP_KERNEL);
1249
1250 if (!drv->fw.dbg_dest_tlv)
1251 goto out_free_fw;
1252 }
1253
1254 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_conf_tlv); i++) {
1255 if (pieces->dbg_conf_tlv[i]) {
1256 drv->fw.dbg_conf_tlv_len[i] =
1257 pieces->dbg_conf_tlv_len[i];
1258 drv->fw.dbg_conf_tlv[i] =
1259 kmemdup(pieces->dbg_conf_tlv[i],
1260 drv->fw.dbg_conf_tlv_len[i],
1261 GFP_KERNEL);
1262 if (!drv->fw.dbg_conf_tlv[i])
1263 goto out_free_fw;
1264 }
1265 }
1266
2841a2d3
EG
1267 memset(&trigger_tlv_sz, 0xff, sizeof(trigger_tlv_sz));
1268
1269 trigger_tlv_sz[FW_DBG_TRIGGER_MISSED_BEACONS] =
1270 sizeof(struct iwl_fw_dbg_trigger_missed_bcon);
1271 trigger_tlv_sz[FW_DBG_TRIGGER_CHANNEL_SWITCH] = 0;
1272 trigger_tlv_sz[FW_DBG_TRIGGER_FW_NOTIF] =
1273 sizeof(struct iwl_fw_dbg_trigger_cmd);
1274 trigger_tlv_sz[FW_DBG_TRIGGER_MLME] =
1275 sizeof(struct iwl_fw_dbg_trigger_mlme);
1276 trigger_tlv_sz[FW_DBG_TRIGGER_STATS] =
1277 sizeof(struct iwl_fw_dbg_trigger_stats);
1278 trigger_tlv_sz[FW_DBG_TRIGGER_RSSI] =
1279 sizeof(struct iwl_fw_dbg_trigger_low_rssi);
1280 trigger_tlv_sz[FW_DBG_TRIGGER_TXQ_TIMERS] =
1281 sizeof(struct iwl_fw_dbg_trigger_txq_timer);
874c174e
EG
1282 trigger_tlv_sz[FW_DBG_TRIGGER_TIME_EVENT] =
1283 sizeof(struct iwl_fw_dbg_trigger_time_event);
4203263d
EG
1284 trigger_tlv_sz[FW_DBG_TRIGGER_BA] =
1285 sizeof(struct iwl_fw_dbg_trigger_ba);
2841a2d3 1286
d2709ad7
EG
1287 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg_trigger_tlv); i++) {
1288 if (pieces->dbg_trigger_tlv[i]) {
2841a2d3
EG
1289 /*
1290 * If the trigger isn't long enough, WARN and exit.
1291 * Someone is trying to debug something and he won't
1292 * be able to catch the bug he is trying to chase.
1293 * We'd better be noisy to be sure he knows what's
1294 * going on.
1295 */
1296 if (WARN_ON(pieces->dbg_trigger_tlv_len[i] <
1297 (trigger_tlv_sz[i] +
1298 sizeof(struct iwl_fw_dbg_trigger_tlv))))
1299 goto out_free_fw;
d2709ad7
EG
1300 drv->fw.dbg_trigger_tlv_len[i] =
1301 pieces->dbg_trigger_tlv_len[i];
1302 drv->fw.dbg_trigger_tlv[i] =
1303 kmemdup(pieces->dbg_trigger_tlv[i],
1304 drv->fw.dbg_trigger_tlv_len[i],
1305 GFP_KERNEL);
1306 if (!drv->fw.dbg_trigger_tlv[i])
1307 goto out_free_fw;
1308 }
1309 }
1310
15854ef9
JB
1311 /* Now that we can no longer fail, copy information */
1312
1313 /*
1314 * The (size - 16) / 12 formula is based on the information recorded
1315 * for each event, which is of mode 1 (including timestamp) for all
1316 * new microcodes that include this information.
1317 */
490fefeb
LK
1318 fw->init_evtlog_ptr = pieces->init_evtlog_ptr;
1319 if (pieces->init_evtlog_size)
1320 fw->init_evtlog_size = (pieces->init_evtlog_size - 16)/12;
15854ef9 1321 else
0692fe41 1322 fw->init_evtlog_size =
68f360dc 1323 drv->cfg->base_params->max_event_log_size;
490fefeb
LK
1324 fw->init_errlog_ptr = pieces->init_errlog_ptr;
1325 fw->inst_evtlog_ptr = pieces->inst_evtlog_ptr;
1326 if (pieces->inst_evtlog_size)
1327 fw->inst_evtlog_size = (pieces->inst_evtlog_size - 16)/12;
15854ef9 1328 else
0692fe41 1329 fw->inst_evtlog_size =
68f360dc 1330 drv->cfg->base_params->max_event_log_size;
490fefeb 1331 fw->inst_errlog_ptr = pieces->inst_errlog_ptr;
15854ef9
JB
1332
1333 /*
1334 * figure out the offset of chain noise reset and gain commands
1335 * base on the size of standard phy calibration commands table size
1336 */
1337 if (fw->ucode_capa.standard_phy_calibration_size >
1338 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1339 fw->ucode_capa.standard_phy_calibration_size =
1340 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1341
1342 /* We have our copies now, allow OS release its copies */
1343 release_firmware(ucode_raw);
15854ef9 1344
ff1ffb85 1345 mutex_lock(&iwlwifi_opmode_table_mtx);
8ca151b5
JB
1346 if (fw->mvm_fw)
1347 op = &iwlwifi_opmode_table[MVM_OP_MODE];
1348 else
1349 op = &iwlwifi_opmode_table[DVM_OP_MODE];
15854ef9 1350
2b2719c7
JB
1351 IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1352 drv->fw.fw_version, op->name);
1353
cc5f7e39
DF
1354 /* add this device to the list of devices using this op_mode */
1355 list_add_tail(&drv->list, &op->drv);
1356
1357 if (op->ops) {
9da987ac 1358 drv->op_mode = _iwl_op_mode_start(drv, op);
7c9c46c1 1359
daf67ce8
DC
1360 if (!drv->op_mode) {
1361 mutex_unlock(&iwlwifi_opmode_table_mtx);
7c9c46c1 1362 goto out_unbind;
daf67ce8 1363 }
cc5f7e39 1364 } else {
d4b10483 1365 load_module = true;
cc5f7e39 1366 }
ff1ffb85 1367 mutex_unlock(&iwlwifi_opmode_table_mtx);
15854ef9 1368
f69a23b7
JB
1369 /*
1370 * Complete the firmware request last so that
1371 * a driver unbind (stop) doesn't run while we
1372 * are doing the start() above.
1373 */
1374 complete(&drv->request_firmware_complete);
d4b10483
JB
1375
1376 /*
1377 * Load the module last so we don't block anything
1378 * else from proceeding if the module fails to load
1379 * or hangs loading.
1380 */
1618b2b0
JB
1381 if (load_module) {
1382 err = request_module("%s", op->name);
8edf3fd6 1383#ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
1618b2b0
JB
1384 if (err)
1385 IWL_ERR(drv,
1386 "failed to load module %s (error %d), is dynamic loading enabled?\n",
1387 op->name, err);
8edf3fd6 1388#endif
1618b2b0 1389 }
a71aaf66 1390 kfree(pieces);
15854ef9
JB
1391 return;
1392
1393 try_again:
1394 /* try next, if any */
1395 release_firmware(ucode_raw);
965974a6 1396 if (iwl_request_firmware(drv, false))
15854ef9 1397 goto out_unbind;
31a5a09c 1398 kfree(pieces);
15854ef9
JB
1399 return;
1400
75813bde 1401 out_free_fw:
965974a6
JB
1402 IWL_ERR(drv, "failed to allocate pci memory\n");
1403 iwl_dealloc_ucode(drv);
15854ef9
JB
1404 release_firmware(ucode_raw);
1405 out_unbind:
490fefeb 1406 kfree(pieces);
965974a6 1407 complete(&drv->request_firmware_complete);
93faaeea 1408 device_release_driver(drv->trans->dev);
15854ef9
JB
1409}
1410
87ce05a2 1411struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
9130bab1 1412 const struct iwl_cfg *cfg)
5c58edc6 1413{
965974a6 1414 struct iwl_drv *drv;
5c58edc6
EG
1415 int ret;
1416
965974a6 1417 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
eafe25e0
LC
1418 if (!drv) {
1419 ret = -ENOMEM;
1420 goto err;
1421 }
c15797e6 1422
9130bab1 1423 drv->trans = trans;
4b9844f5 1424 drv->dev = trans->dev;
68f360dc 1425 drv->cfg = cfg;
5c58edc6 1426
965974a6 1427 init_completion(&drv->request_firmware_complete);
ff1ffb85 1428 INIT_LIST_HEAD(&drv->list);
5c58edc6 1429
9da987ac
MV
1430#ifdef CONFIG_IWLWIFI_DEBUGFS
1431 /* Create the device debugfs entries. */
1432 drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1433 iwl_dbgfs_root);
1434
1435 if (!drv->dbgfs_drv) {
1436 IWL_ERR(drv, "failed to create debugfs directory\n");
59f547ac 1437 ret = -ENOMEM;
9da987ac
MV
1438 goto err_free_drv;
1439 }
1440
1441 /* Create transport layer debugfs dir */
1442 drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1443
1444 if (!drv->trans->dbgfs_dir) {
1445 IWL_ERR(drv, "failed to create transport debugfs directory\n");
59f547ac 1446 ret = -ENOMEM;
9da987ac
MV
1447 goto err_free_dbgfs;
1448 }
1449#endif
1450
965974a6 1451 ret = iwl_request_firmware(drv, true);
5c58edc6 1452 if (ret) {
c15797e6 1453 IWL_ERR(trans, "Couldn't request the fw\n");
9da987ac 1454 goto err_fw;
5c58edc6
EG
1455 }
1456
9da987ac
MV
1457 return drv;
1458
1459err_fw:
1460#ifdef CONFIG_IWLWIFI_DEBUGFS
1461err_free_dbgfs:
1462 debugfs_remove_recursive(drv->dbgfs_drv);
1463err_free_drv:
1464#endif
1465 kfree(drv);
eafe25e0 1466err:
59f547ac 1467 return ERR_PTR(ret);
5c58edc6
EG
1468}
1469
9130bab1 1470void iwl_drv_stop(struct iwl_drv *drv)
07590f08 1471{
965974a6 1472 wait_for_completion(&drv->request_firmware_complete);
2e7eb117 1473
9da987ac 1474 _iwl_op_mode_stop(drv);
07590f08 1475
965974a6 1476 iwl_dealloc_ucode(drv);
7db5b989 1477
ff1ffb85
JB
1478 mutex_lock(&iwlwifi_opmode_table_mtx);
1479 /*
1480 * List is empty (this item wasn't added)
1481 * when firmware loading failed -- in that
1482 * case we can't remove it from any list.
1483 */
1484 if (!list_empty(&drv->list))
1485 list_del(&drv->list);
1486 mutex_unlock(&iwlwifi_opmode_table_mtx);
1487
9da987ac
MV
1488#ifdef CONFIG_IWLWIFI_DEBUGFS
1489 debugfs_remove_recursive(drv->dbgfs_drv);
1490#endif
1491
965974a6 1492 kfree(drv);
07590f08 1493}
65de7e84
JB
1494
1495
1496/* shared module parameters */
1497struct iwl_mod_params iwlwifi_mod_params = {
490953ac 1498 .restart_fw = true,
65de7e84
JB
1499 .bt_coex_active = true,
1500 .power_level = IWL_POWER_INDEX_1,
7616f334 1501 .d0i3_disable = true,
d6ca18de
JB
1502#ifndef CONFIG_IWLWIFI_UAPSD
1503 .uapsd_disable = true,
1504#endif /* CONFIG_IWLWIFI_UAPSD */
65de7e84
JB
1505 /* the rest are 0 by default */
1506};
48e29340 1507IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
cc5f7e39
DF
1508
1509int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1510{
1511 int i;
1512 struct iwl_drv *drv;
9da987ac 1513 struct iwlwifi_opmode_table *op;
cc5f7e39 1514
ff1ffb85 1515 mutex_lock(&iwlwifi_opmode_table_mtx);
cc5f7e39 1516 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
9da987ac
MV
1517 op = &iwlwifi_opmode_table[i];
1518 if (strcmp(op->name, name))
cc5f7e39 1519 continue;
9da987ac
MV
1520 op->ops = ops;
1521 /* TODO: need to handle exceptional case */
1522 list_for_each_entry(drv, &op->drv, list)
1523 drv->op_mode = _iwl_op_mode_start(drv, op);
1524
ff1ffb85 1525 mutex_unlock(&iwlwifi_opmode_table_mtx);
cc5f7e39
DF
1526 return 0;
1527 }
ff1ffb85 1528 mutex_unlock(&iwlwifi_opmode_table_mtx);
cc5f7e39
DF
1529 return -EIO;
1530}
48e29340 1531IWL_EXPORT_SYMBOL(iwl_opmode_register);
cc5f7e39
DF
1532
1533void iwl_opmode_deregister(const char *name)
1534{
1535 int i;
1536 struct iwl_drv *drv;
1537
ff1ffb85 1538 mutex_lock(&iwlwifi_opmode_table_mtx);
cc5f7e39
DF
1539 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1540 if (strcmp(iwlwifi_opmode_table[i].name, name))
1541 continue;
1542 iwlwifi_opmode_table[i].ops = NULL;
1543
1544 /* call the stop routine for all devices */
9da987ac
MV
1545 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1546 _iwl_op_mode_stop(drv);
1547
ff1ffb85 1548 mutex_unlock(&iwlwifi_opmode_table_mtx);
cc5f7e39
DF
1549 return;
1550 }
ff1ffb85 1551 mutex_unlock(&iwlwifi_opmode_table_mtx);
cc5f7e39 1552}
48e29340 1553IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
cc5f7e39
DF
1554
1555static int __init iwl_drv_init(void)
1556{
1557 int i;
1558
ff1ffb85
JB
1559 mutex_init(&iwlwifi_opmode_table_mtx);
1560
cc5f7e39
DF
1561 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1562 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1563
e32ec12f 1564 pr_info(DRV_DESCRIPTION "\n");
cc5f7e39
DF
1565 pr_info(DRV_COPYRIGHT "\n");
1566
9da987ac
MV
1567#ifdef CONFIG_IWLWIFI_DEBUGFS
1568 /* Create the root of iwlwifi debugfs subsystem. */
1569 iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1570
1571 if (!iwl_dbgfs_root)
1572 return -EFAULT;
1573#endif
1574
cc5f7e39
DF
1575 return iwl_pci_register_driver();
1576}
1577module_init(iwl_drv_init);
1578
1579static void __exit iwl_drv_exit(void)
1580{
1581 iwl_pci_unregister_driver();
9da987ac
MV
1582
1583#ifdef CONFIG_IWLWIFI_DEBUGFS
1584 debugfs_remove_recursive(iwl_dbgfs_root);
1585#endif
cc5f7e39
DF
1586}
1587module_exit(iwl_drv_exit);
65de7e84
JB
1588
1589#ifdef CONFIG_IWLWIFI_DEBUG
1590module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
1591 S_IRUGO | S_IWUSR);
1592MODULE_PARM_DESC(debug, "debug output mask");
1593#endif
1594
1595module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
1596MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1597module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
1598MODULE_PARM_DESC(11n_disable,
205e2210 1599 "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
65de7e84
JB
1600module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
1601 int, S_IRUGO);
aed7d9ac 1602MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size (default 0)");
490953ac
EG
1603module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, bool, S_IRUGO);
1604MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
65de7e84
JB
1605
1606module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
1607 int, S_IRUGO);
1608MODULE_PARM_DESC(antenna_coupling,
ad25c1ee 1609 "specify antenna coupling in dB (default: 0 dB)");
65de7e84 1610
1214755c
EH
1611module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, S_IRUGO);
1612MODULE_PARM_DESC(nvm_file, "NVM file name");
1613
7616f334
EP
1614module_param_named(d0i3_disable, iwlwifi_mod_params.d0i3_disable,
1615 bool, S_IRUGO);
1616MODULE_PARM_DESC(d0i3_disable, "disable d0i3 functionality (default: Y)");
1617
5711cac4
AN
1618module_param_named(lar_disable, iwlwifi_mod_params.lar_disable,
1619 bool, S_IRUGO);
1620MODULE_PARM_DESC(lar_disable, "disable LAR functionality (default: N)");
1621
1504f48d 1622module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable,
bd1ba664 1623 bool, S_IRUGO | S_IWUSR);
d6ca18de 1624#ifdef CONFIG_IWLWIFI_UAPSD
1504f48d 1625MODULE_PARM_DESC(uapsd_disable, "disable U-APSD functionality (default: N)");
d6ca18de
JB
1626#else
1627MODULE_PARM_DESC(uapsd_disable, "disable U-APSD functionality (default: Y)");
1628#endif
1504f48d 1629
65de7e84
JB
1630/*
1631 * set bt_coex_active to true, uCode will do kill/defer
1632 * every time the priority line is asserted (BT is sending signals on the
1633 * priority line in the PCIx).
1634 * set bt_coex_active to false, uCode will ignore the BT activity and
1635 * perform the normal operation
1636 *
1637 * User might experience transmit issue on some platform due to WiFi/BT
1638 * co-exist problem. The possible behaviors are:
1639 * Able to scan and finding all the available AP
1640 * Not able to associate with any AP
1641 * On those platforms, WiFi communication can be restored by set
1642 * "bt_coex_active" module parameter to "false"
1643 *
1644 * default: bt_coex_active = true (BT_COEX_ENABLE)
1645 */
1646module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1647 bool, S_IRUGO);
1648MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1649
1650module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
1651MODULE_PARM_DESC(led_mode, "0=system default, "
1652 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1653
1654module_param_named(power_save, iwlwifi_mod_params.power_save,
1655 bool, S_IRUGO);
1656MODULE_PARM_DESC(power_save,
1657 "enable WiFi power management (default: disable)");
1658
1659module_param_named(power_level, iwlwifi_mod_params.power_level,
1660 int, S_IRUGO);
1661MODULE_PARM_DESC(power_level,
1662 "default power save level (range from 1 - 5, default: 1)");
c2d20201
EG
1663
1664module_param_named(fw_monitor, iwlwifi_mod_params.fw_monitor, bool, S_IRUGO);
6d6a4751 1665MODULE_PARM_DESC(fw_monitor,
c2d20201 1666 "firmware monitor - to debug FW (default: false - needs lots of memory)");