1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2005-2014, 2018-2021 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
7 #include <linux/completion.h>
8 #include <linux/dma-mapping.h>
9 #include <linux/firmware.h>
10 #include <linux/module.h>
11 #include <linux/vmalloc.h>
15 #include "iwl-debug.h"
16 #include "iwl-trans.h"
17 #include "iwl-op-mode.h"
18 #include "iwl-agn-hw.h"
20 #include "iwl-dbg-tlv.h"
21 #include "iwl-config.h"
22 #include "iwl-modparams.h"
23 #include "fw/api/alive.h"
24 #include "fw/api/mac.h"
26 /******************************************************************************
30 ******************************************************************************/
32 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
33 MODULE_DESCRIPTION(DRV_DESCRIPTION);
34 MODULE_LICENSE("GPL");
36 #ifdef CONFIG_IWLWIFI_DEBUGFS
37 static struct dentry *iwl_dbgfs_root;
41 * struct iwl_drv - drv common data
42 * @list: list of drv structures using this opmode
43 * @fw: the iwl_fw structure
44 * @op_mode: the running op_mode
45 * @trans: transport layer
46 * @dev: for debug prints only
47 * @fw_index: firmware revision to try loading
48 * @firmware_name: composite filename of ucode file to load
49 * @request_firmware_complete: the firmware has been obtained from user space
50 * @dbgfs_drv: debugfs root directory entry
51 * @dbgfs_trans: debugfs transport directory entry
52 * @dbgfs_op_mode: debugfs op_mode directory entry
55 struct list_head list;
58 struct iwl_op_mode *op_mode;
59 struct iwl_trans *trans;
62 int fw_index; /* firmware we're trying to load */
63 char firmware_name[64]; /* name of firmware file to load */
65 struct completion request_firmware_complete;
67 #ifdef CONFIG_IWLWIFI_DEBUGFS
68 struct dentry *dbgfs_drv;
69 struct dentry *dbgfs_trans;
70 struct dentry *dbgfs_op_mode;
79 /* Protects the table contents, i.e. the ops pointer & drv list */
80 static DEFINE_MUTEX(iwlwifi_opmode_table_mtx);
81 static struct iwlwifi_opmode_table {
82 const char *name; /* name: iwldvm, iwlmvm, etc */
83 const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
84 struct list_head drv; /* list of devices using this op_mode */
85 } iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
86 [DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL },
87 [MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL },
90 #define IWL_DEFAULT_SCAN_CHANNELS 40
93 * struct fw_sec: Just for the image parsing process.
94 * For the fw storage we are using struct fw_desc.
97 const void *data; /* the sec data */
98 size_t size; /* section size */
99 u32 offset; /* offset of writing in the device */
102 static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
109 static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
112 for (i = 0; i < img->num_sec; i++)
113 iwl_free_fw_desc(drv, &img->sec[i]);
117 static void iwl_dealloc_ucode(struct iwl_drv *drv)
121 kfree(drv->fw.dbg.dest_tlv);
122 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++)
123 kfree(drv->fw.dbg.conf_tlv[i]);
124 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++)
125 kfree(drv->fw.dbg.trigger_tlv[i]);
126 kfree(drv->fw.dbg.mem_tlv);
128 kfree(drv->fw.ucode_capa.cmd_versions);
129 kfree(drv->fw.phy_integration_ver);
131 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
132 iwl_free_fw_img(drv, drv->fw.img + i);
135 static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
142 if (!sec || !sec->size)
145 data = vmalloc(sec->size);
149 desc->len = sec->size;
150 desc->offset = sec->offset;
151 memcpy(data, sec->data, desc->len);
157 static void iwl_req_fw_callback(const struct firmware *ucode_raw,
160 static int iwl_request_firmware(struct iwl_drv *drv, bool first)
162 const struct iwl_cfg *cfg = drv->trans->cfg;
165 if (drv->trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_9000 &&
166 (CSR_HW_REV_STEP(drv->trans->hw_rev) != SILICON_B_STEP &&
167 CSR_HW_REV_STEP(drv->trans->hw_rev) != SILICON_C_STEP)) {
169 "Only HW steps B and C are currently supported (0x%0x)\n",
175 drv->fw_index = cfg->ucode_api_max;
176 sprintf(tag, "%d", drv->fw_index);
179 sprintf(tag, "%d", drv->fw_index);
182 if (drv->fw_index < cfg->ucode_api_min) {
183 IWL_ERR(drv, "no suitable firmware found!\n");
185 if (cfg->ucode_api_min == cfg->ucode_api_max) {
186 IWL_ERR(drv, "%s%d is required\n", cfg->fw_name_pre,
189 IWL_ERR(drv, "minimum version required: %s%d\n",
190 cfg->fw_name_pre, cfg->ucode_api_min);
191 IWL_ERR(drv, "maximum version supported: %s%d\n",
192 cfg->fw_name_pre, cfg->ucode_api_max);
196 "check git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git\n");
200 snprintf(drv->firmware_name, sizeof(drv->firmware_name), "%s%s.ucode",
201 cfg->fw_name_pre, tag);
203 IWL_DEBUG_FW_INFO(drv, "attempting to load firmware '%s'\n",
206 return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
208 GFP_KERNEL, drv, iwl_req_fw_callback);
211 struct fw_img_parsing {
217 * struct fw_sec_parsing: to extract fw section and it's offset from tlv
219 struct fw_sec_parsing {
225 * struct iwl_tlv_calib_data - parse the default calib data from TLV
227 * @ucode_type: the uCode to which the following default calib relates.
228 * @calib: default calibrations.
230 struct iwl_tlv_calib_data {
232 struct iwl_tlv_calib_ctrl calib;
235 struct iwl_firmware_pieces {
236 struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
238 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
239 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
241 /* FW debug data parsed for driver usage */
242 bool dbg_dest_tlv_init;
245 struct iwl_fw_dbg_dest_tlv *dbg_dest_tlv;
246 struct iwl_fw_dbg_dest_tlv_v1 *dbg_dest_tlv_v1;
248 struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
249 size_t dbg_conf_tlv_len[FW_DBG_CONF_MAX];
250 struct iwl_fw_dbg_trigger_tlv *dbg_trigger_tlv[FW_DBG_TRIGGER_MAX];
251 size_t dbg_trigger_tlv_len[FW_DBG_TRIGGER_MAX];
252 struct iwl_fw_dbg_mem_seg_tlv *dbg_mem_tlv;
257 * These functions are just to extract uCode section data from the pieces
260 static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
261 enum iwl_ucode_type type,
264 return &pieces->img[type].sec[sec];
267 static void alloc_sec_data(struct iwl_firmware_pieces *pieces,
268 enum iwl_ucode_type type,
271 struct fw_img_parsing *img = &pieces->img[type];
272 struct fw_sec *sec_memory;
274 size_t alloc_size = sizeof(*img->sec) * size;
276 if (img->sec && img->sec_counter >= size)
279 sec_memory = krealloc(img->sec, alloc_size, GFP_KERNEL);
283 img->sec = sec_memory;
284 img->sec_counter = size;
287 static void set_sec_data(struct iwl_firmware_pieces *pieces,
288 enum iwl_ucode_type type,
292 alloc_sec_data(pieces, type, sec);
294 pieces->img[type].sec[sec].data = data;
297 static void set_sec_size(struct iwl_firmware_pieces *pieces,
298 enum iwl_ucode_type type,
302 alloc_sec_data(pieces, type, sec);
304 pieces->img[type].sec[sec].size = size;
307 static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
308 enum iwl_ucode_type type,
311 return pieces->img[type].sec[sec].size;
314 static void set_sec_offset(struct iwl_firmware_pieces *pieces,
315 enum iwl_ucode_type type,
319 alloc_sec_data(pieces, type, sec);
321 pieces->img[type].sec[sec].offset = offset;
324 static int iwl_store_cscheme(struct iwl_fw *fw, const u8 *data, const u32 len)
327 struct iwl_fw_cscheme_list *l = (struct iwl_fw_cscheme_list *)data;
328 struct iwl_fw_cipher_scheme *fwcs;
330 if (len < sizeof(*l) ||
331 len < sizeof(l->size) + l->size * sizeof(l->cs[0]))
334 for (i = 0, j = 0; i < IWL_UCODE_MAX_CS && i < l->size; i++) {
337 /* we skip schemes with zero cipher suite selector */
348 * Gets uCode section from tlv.
350 static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
351 const void *data, enum iwl_ucode_type type,
354 struct fw_img_parsing *img;
356 struct fw_sec_parsing *sec_parse;
359 if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
362 sec_parse = (struct fw_sec_parsing *)data;
364 img = &pieces->img[type];
366 alloc_size = sizeof(*img->sec) * (img->sec_counter + 1);
367 sec = krealloc(img->sec, alloc_size, GFP_KERNEL);
372 sec = &img->sec[img->sec_counter];
374 sec->offset = le32_to_cpu(sec_parse->offset);
375 sec->data = sec_parse->data;
376 sec->size = size - sizeof(sec_parse->offset);
383 static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
385 struct iwl_tlv_calib_data *def_calib =
386 (struct iwl_tlv_calib_data *)data;
387 u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
388 if (ucode_type >= IWL_UCODE_TYPE_MAX) {
389 IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
393 drv->fw.default_calib[ucode_type].flow_trigger =
394 def_calib->calib.flow_trigger;
395 drv->fw.default_calib[ucode_type].event_trigger =
396 def_calib->calib.event_trigger;
401 static void iwl_set_ucode_api_flags(struct iwl_drv *drv, const u8 *data,
402 struct iwl_ucode_capabilities *capa)
404 const struct iwl_ucode_api *ucode_api = (void *)data;
405 u32 api_index = le32_to_cpu(ucode_api->api_index);
406 u32 api_flags = le32_to_cpu(ucode_api->api_flags);
409 if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_API, 32)) {
411 "api flags index %d larger than supported by driver\n",
416 for (i = 0; i < 32; i++) {
417 if (api_flags & BIT(i))
418 __set_bit(i + 32 * api_index, capa->_api);
422 static void iwl_set_ucode_capabilities(struct iwl_drv *drv, const u8 *data,
423 struct iwl_ucode_capabilities *capa)
425 const struct iwl_ucode_capa *ucode_capa = (void *)data;
426 u32 api_index = le32_to_cpu(ucode_capa->api_index);
427 u32 api_flags = le32_to_cpu(ucode_capa->api_capa);
430 if (api_index >= DIV_ROUND_UP(NUM_IWL_UCODE_TLV_CAPA, 32)) {
432 "capa flags index %d larger than supported by driver\n",
437 for (i = 0; i < 32; i++) {
438 if (api_flags & BIT(i))
439 __set_bit(i + 32 * api_index, capa->_capa);
443 static const char *iwl_reduced_fw_name(struct iwl_drv *drv)
445 const char *name = drv->firmware_name;
447 if (strncmp(name, "iwlwifi-", 8) == 0)
453 static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
454 const struct firmware *ucode_raw,
455 struct iwl_firmware_pieces *pieces)
457 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
458 u32 api_ver, hdr_size, build;
462 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
463 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
468 if (ucode_raw->size < hdr_size) {
469 IWL_ERR(drv, "File size too small!\n");
472 build = le32_to_cpu(ucode->u.v2.build);
473 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
474 le32_to_cpu(ucode->u.v2.inst_size));
475 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
476 le32_to_cpu(ucode->u.v2.data_size));
477 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
478 le32_to_cpu(ucode->u.v2.init_size));
479 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
480 le32_to_cpu(ucode->u.v2.init_data_size));
481 src = ucode->u.v2.data;
487 if (ucode_raw->size < hdr_size) {
488 IWL_ERR(drv, "File size too small!\n");
492 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
493 le32_to_cpu(ucode->u.v1.inst_size));
494 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
495 le32_to_cpu(ucode->u.v1.data_size));
496 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
497 le32_to_cpu(ucode->u.v1.init_size));
498 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
499 le32_to_cpu(ucode->u.v1.init_data_size));
500 src = ucode->u.v1.data;
505 sprintf(buildstr, " build %u", build);
509 snprintf(drv->fw.fw_version,
510 sizeof(drv->fw.fw_version),
512 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
513 IWL_UCODE_MINOR(drv->fw.ucode_ver),
514 IWL_UCODE_API(drv->fw.ucode_ver),
515 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
516 buildstr, iwl_reduced_fw_name(drv));
518 /* Verify size of file vs. image size info in file's header */
520 if (ucode_raw->size != hdr_size +
521 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
522 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
523 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
524 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
527 "uCode file size %d does not match expected size\n",
528 (int)ucode_raw->size);
533 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
534 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
535 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
536 IWLAGN_RTC_INST_LOWER_BOUND);
537 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
538 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
539 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
540 IWLAGN_RTC_DATA_LOWER_BOUND);
541 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
542 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
543 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
544 IWLAGN_RTC_INST_LOWER_BOUND);
545 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
546 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
547 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
548 IWLAGN_RTC_DATA_LOWER_BOUND);
552 static void iwl_drv_set_dump_exclude(struct iwl_drv *drv,
553 enum iwl_ucode_tlv_type tlv_type,
554 const void *tlv_data, u32 tlv_len)
556 const struct iwl_fw_dump_exclude *fw = tlv_data;
557 struct iwl_dump_exclude *excl;
559 if (tlv_len < sizeof(*fw))
562 if (tlv_type == IWL_UCODE_TLV_SEC_TABLE_ADDR) {
563 excl = &drv->fw.dump_excl[0];
565 /* second time we find this, it's for WoWLAN */
567 excl = &drv->fw.dump_excl_wowlan[0];
568 } else if (fw_has_capa(&drv->fw.ucode_capa,
569 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG)) {
570 /* IWL_UCODE_TLV_D3_KEK_KCK_ADDR is regular image */
571 excl = &drv->fw.dump_excl[0];
573 /* IWL_UCODE_TLV_D3_KEK_KCK_ADDR is WoWLAN image */
574 excl = &drv->fw.dump_excl_wowlan[0];
581 IWL_DEBUG_FW_INFO(drv, "found too many excludes in fw file\n");
585 excl->addr = le32_to_cpu(fw->addr) & ~FW_ADDR_CACHE_CONTROL;
586 excl->size = le32_to_cpu(fw->size);
589 static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
590 const struct firmware *ucode_raw,
591 struct iwl_firmware_pieces *pieces,
592 struct iwl_ucode_capabilities *capa,
593 bool *usniffer_images)
595 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
596 const struct iwl_ucode_tlv *tlv;
597 size_t len = ucode_raw->size;
601 enum iwl_ucode_tlv_type tlv_type;
604 u32 build, paging_mem_size;
606 bool usniffer_req = false;
608 if (len < sizeof(*ucode)) {
609 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
613 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
614 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
615 le32_to_cpu(ucode->magic));
619 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
620 memcpy(drv->fw.human_readable, ucode->human_readable,
621 sizeof(drv->fw.human_readable));
622 build = le32_to_cpu(ucode->build);
625 sprintf(buildstr, " build %u", build);
629 snprintf(drv->fw.fw_version,
630 sizeof(drv->fw.fw_version),
632 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
633 IWL_UCODE_MINOR(drv->fw.ucode_ver),
634 IWL_UCODE_API(drv->fw.ucode_ver),
635 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
636 buildstr, iwl_reduced_fw_name(drv));
640 len -= sizeof(*ucode);
642 while (len >= sizeof(*tlv)) {
646 tlv_len = le32_to_cpu(tlv->length);
647 tlv_type = le32_to_cpu(tlv->type);
648 tlv_data = tlv->data;
651 IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
655 len -= ALIGN(tlv_len, 4);
656 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
659 case IWL_UCODE_TLV_INST:
660 set_sec_data(pieces, IWL_UCODE_REGULAR,
661 IWL_UCODE_SECTION_INST, tlv_data);
662 set_sec_size(pieces, IWL_UCODE_REGULAR,
663 IWL_UCODE_SECTION_INST, tlv_len);
664 set_sec_offset(pieces, IWL_UCODE_REGULAR,
665 IWL_UCODE_SECTION_INST,
666 IWLAGN_RTC_INST_LOWER_BOUND);
668 case IWL_UCODE_TLV_DATA:
669 set_sec_data(pieces, IWL_UCODE_REGULAR,
670 IWL_UCODE_SECTION_DATA, tlv_data);
671 set_sec_size(pieces, IWL_UCODE_REGULAR,
672 IWL_UCODE_SECTION_DATA, tlv_len);
673 set_sec_offset(pieces, IWL_UCODE_REGULAR,
674 IWL_UCODE_SECTION_DATA,
675 IWLAGN_RTC_DATA_LOWER_BOUND);
677 case IWL_UCODE_TLV_INIT:
678 set_sec_data(pieces, IWL_UCODE_INIT,
679 IWL_UCODE_SECTION_INST, tlv_data);
680 set_sec_size(pieces, IWL_UCODE_INIT,
681 IWL_UCODE_SECTION_INST, tlv_len);
682 set_sec_offset(pieces, IWL_UCODE_INIT,
683 IWL_UCODE_SECTION_INST,
684 IWLAGN_RTC_INST_LOWER_BOUND);
686 case IWL_UCODE_TLV_INIT_DATA:
687 set_sec_data(pieces, IWL_UCODE_INIT,
688 IWL_UCODE_SECTION_DATA, tlv_data);
689 set_sec_size(pieces, IWL_UCODE_INIT,
690 IWL_UCODE_SECTION_DATA, tlv_len);
691 set_sec_offset(pieces, IWL_UCODE_INIT,
692 IWL_UCODE_SECTION_DATA,
693 IWLAGN_RTC_DATA_LOWER_BOUND);
695 case IWL_UCODE_TLV_BOOT:
696 IWL_ERR(drv, "Found unexpected BOOT ucode\n");
698 case IWL_UCODE_TLV_PROBE_MAX_LEN:
699 if (tlv_len != sizeof(u32))
700 goto invalid_tlv_len;
701 capa->max_probe_length =
702 le32_to_cpup((__le32 *)tlv_data);
704 case IWL_UCODE_TLV_PAN:
706 goto invalid_tlv_len;
707 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
709 case IWL_UCODE_TLV_FLAGS:
710 /* must be at least one u32 */
711 if (tlv_len < sizeof(u32))
712 goto invalid_tlv_len;
713 /* and a proper number of u32s */
714 if (tlv_len % sizeof(u32))
715 goto invalid_tlv_len;
717 * This driver only reads the first u32 as
718 * right now no more features are defined,
719 * if that changes then either the driver
720 * will not work with the new firmware, or
721 * it'll not take advantage of new features.
723 capa->flags = le32_to_cpup((__le32 *)tlv_data);
725 case IWL_UCODE_TLV_API_CHANGES_SET:
726 if (tlv_len != sizeof(struct iwl_ucode_api))
727 goto invalid_tlv_len;
728 iwl_set_ucode_api_flags(drv, tlv_data, capa);
730 case IWL_UCODE_TLV_ENABLED_CAPABILITIES:
731 if (tlv_len != sizeof(struct iwl_ucode_capa))
732 goto invalid_tlv_len;
733 iwl_set_ucode_capabilities(drv, tlv_data, capa);
735 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
736 if (tlv_len != sizeof(u32))
737 goto invalid_tlv_len;
738 pieces->init_evtlog_ptr =
739 le32_to_cpup((__le32 *)tlv_data);
741 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
742 if (tlv_len != sizeof(u32))
743 goto invalid_tlv_len;
744 pieces->init_evtlog_size =
745 le32_to_cpup((__le32 *)tlv_data);
747 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
748 if (tlv_len != sizeof(u32))
749 goto invalid_tlv_len;
750 pieces->init_errlog_ptr =
751 le32_to_cpup((__le32 *)tlv_data);
753 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
754 if (tlv_len != sizeof(u32))
755 goto invalid_tlv_len;
756 pieces->inst_evtlog_ptr =
757 le32_to_cpup((__le32 *)tlv_data);
759 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
760 if (tlv_len != sizeof(u32))
761 goto invalid_tlv_len;
762 pieces->inst_evtlog_size =
763 le32_to_cpup((__le32 *)tlv_data);
765 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
766 if (tlv_len != sizeof(u32))
767 goto invalid_tlv_len;
768 pieces->inst_errlog_ptr =
769 le32_to_cpup((__le32 *)tlv_data);
771 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
773 goto invalid_tlv_len;
774 drv->fw.enhance_sensitivity_table = true;
776 case IWL_UCODE_TLV_WOWLAN_INST:
777 set_sec_data(pieces, IWL_UCODE_WOWLAN,
778 IWL_UCODE_SECTION_INST, tlv_data);
779 set_sec_size(pieces, IWL_UCODE_WOWLAN,
780 IWL_UCODE_SECTION_INST, tlv_len);
781 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
782 IWL_UCODE_SECTION_INST,
783 IWLAGN_RTC_INST_LOWER_BOUND);
785 case IWL_UCODE_TLV_WOWLAN_DATA:
786 set_sec_data(pieces, IWL_UCODE_WOWLAN,
787 IWL_UCODE_SECTION_DATA, tlv_data);
788 set_sec_size(pieces, IWL_UCODE_WOWLAN,
789 IWL_UCODE_SECTION_DATA, tlv_len);
790 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
791 IWL_UCODE_SECTION_DATA,
792 IWLAGN_RTC_DATA_LOWER_BOUND);
794 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
795 if (tlv_len != sizeof(u32))
796 goto invalid_tlv_len;
797 capa->standard_phy_calibration_size =
798 le32_to_cpup((__le32 *)tlv_data);
800 case IWL_UCODE_TLV_SEC_RT:
801 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
803 drv->fw.type = IWL_FW_MVM;
805 case IWL_UCODE_TLV_SEC_INIT:
806 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
808 drv->fw.type = IWL_FW_MVM;
810 case IWL_UCODE_TLV_SEC_WOWLAN:
811 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
813 drv->fw.type = IWL_FW_MVM;
815 case IWL_UCODE_TLV_DEF_CALIB:
816 if (tlv_len != sizeof(struct iwl_tlv_calib_data))
817 goto invalid_tlv_len;
818 if (iwl_set_default_calib(drv, tlv_data))
821 case IWL_UCODE_TLV_PHY_SKU:
822 if (tlv_len != sizeof(u32))
823 goto invalid_tlv_len;
824 drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
825 drv->fw.valid_tx_ant = (drv->fw.phy_config &
826 FW_PHY_CFG_TX_CHAIN) >>
827 FW_PHY_CFG_TX_CHAIN_POS;
828 drv->fw.valid_rx_ant = (drv->fw.phy_config &
829 FW_PHY_CFG_RX_CHAIN) >>
830 FW_PHY_CFG_RX_CHAIN_POS;
832 case IWL_UCODE_TLV_SECURE_SEC_RT:
833 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
835 drv->fw.type = IWL_FW_MVM;
837 case IWL_UCODE_TLV_SECURE_SEC_INIT:
838 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
840 drv->fw.type = IWL_FW_MVM;
842 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
843 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
845 drv->fw.type = IWL_FW_MVM;
847 case IWL_UCODE_TLV_NUM_OF_CPU:
848 if (tlv_len != sizeof(u32))
849 goto invalid_tlv_len;
851 le32_to_cpup((__le32 *)tlv_data);
853 if (num_of_cpus == 2) {
854 drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
856 drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
858 drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
860 } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
861 IWL_ERR(drv, "Driver support upto 2 CPUs\n");
865 case IWL_UCODE_TLV_CSCHEME:
866 if (iwl_store_cscheme(&drv->fw, tlv_data, tlv_len))
867 goto invalid_tlv_len;
869 case IWL_UCODE_TLV_N_SCAN_CHANNELS:
870 if (tlv_len != sizeof(u32))
871 goto invalid_tlv_len;
872 capa->n_scan_channels =
873 le32_to_cpup((__le32 *)tlv_data);
875 case IWL_UCODE_TLV_FW_VERSION: {
876 __le32 *ptr = (void *)tlv_data;
880 if (tlv_len != sizeof(u32) * 3)
881 goto invalid_tlv_len;
883 major = le32_to_cpup(ptr++);
884 minor = le32_to_cpup(ptr++);
885 local_comp = le32_to_cpup(ptr);
888 snprintf(drv->fw.fw_version,
889 sizeof(drv->fw.fw_version),
890 "%u.%08x.%u %s", major, minor,
891 local_comp, iwl_reduced_fw_name(drv));
893 snprintf(drv->fw.fw_version,
894 sizeof(drv->fw.fw_version),
895 "%u.%u.%u %s", major, minor,
896 local_comp, iwl_reduced_fw_name(drv));
899 case IWL_UCODE_TLV_FW_DBG_DEST: {
900 struct iwl_fw_dbg_dest_tlv *dest = NULL;
901 struct iwl_fw_dbg_dest_tlv_v1 *dest_v1 = NULL;
904 pieces->dbg_dest_ver = (u8 *)tlv_data;
905 if (*pieces->dbg_dest_ver == 1) {
906 dest = (void *)tlv_data;
907 } else if (*pieces->dbg_dest_ver == 0) {
908 dest_v1 = (void *)tlv_data;
911 "The version is %d, and it is invalid\n",
912 *pieces->dbg_dest_ver);
916 if (pieces->dbg_dest_tlv_init) {
918 "dbg destination ignored, already exists\n");
922 pieces->dbg_dest_tlv_init = true;
925 pieces->dbg_dest_tlv_v1 = dest_v1;
926 mon_mode = dest_v1->monitor_mode;
928 pieces->dbg_dest_tlv = dest;
929 mon_mode = dest->monitor_mode;
932 IWL_INFO(drv, "Found debug destination: %s\n",
933 get_fw_dbg_mode_string(mon_mode));
935 drv->fw.dbg.n_dest_reg = (dest_v1) ?
937 offsetof(struct iwl_fw_dbg_dest_tlv_v1,
940 offsetof(struct iwl_fw_dbg_dest_tlv,
943 drv->fw.dbg.n_dest_reg /=
944 sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]);
948 case IWL_UCODE_TLV_FW_DBG_CONF: {
949 struct iwl_fw_dbg_conf_tlv *conf = (void *)tlv_data;
951 if (!pieces->dbg_dest_tlv_init) {
953 "Ignore dbg config %d - no destination configured\n",
958 if (conf->id >= ARRAY_SIZE(drv->fw.dbg.conf_tlv)) {
960 "Skip unknown configuration: %d\n",
965 if (pieces->dbg_conf_tlv[conf->id]) {
967 "Ignore duplicate dbg config %d\n",
975 IWL_INFO(drv, "Found debug configuration: %d\n",
978 pieces->dbg_conf_tlv[conf->id] = conf;
979 pieces->dbg_conf_tlv_len[conf->id] = tlv_len;
982 case IWL_UCODE_TLV_FW_DBG_TRIGGER: {
983 struct iwl_fw_dbg_trigger_tlv *trigger =
985 u32 trigger_id = le32_to_cpu(trigger->id);
987 if (trigger_id >= ARRAY_SIZE(drv->fw.dbg.trigger_tlv)) {
989 "Skip unknown trigger: %u\n",
994 if (pieces->dbg_trigger_tlv[trigger_id]) {
996 "Ignore duplicate dbg trigger %u\n",
1001 IWL_INFO(drv, "Found debug trigger: %u\n", trigger->id);
1003 pieces->dbg_trigger_tlv[trigger_id] = trigger;
1004 pieces->dbg_trigger_tlv_len[trigger_id] = tlv_len;
1007 case IWL_UCODE_TLV_FW_DBG_DUMP_LST: {
1008 if (tlv_len != sizeof(u32)) {
1010 "dbg lst mask size incorrect, skip\n");
1014 drv->fw.dbg.dump_mask =
1015 le32_to_cpup((__le32 *)tlv_data);
1018 case IWL_UCODE_TLV_SEC_RT_USNIFFER:
1019 *usniffer_images = true;
1020 iwl_store_ucode_sec(pieces, tlv_data,
1021 IWL_UCODE_REGULAR_USNIFFER,
1024 case IWL_UCODE_TLV_PAGING:
1025 if (tlv_len != sizeof(u32))
1026 goto invalid_tlv_len;
1027 paging_mem_size = le32_to_cpup((__le32 *)tlv_data);
1030 "Paging: paging enabled (size = %u bytes)\n",
1033 if (paging_mem_size > MAX_PAGING_IMAGE_SIZE) {
1035 "Paging: driver supports up to %lu bytes for paging image\n",
1036 MAX_PAGING_IMAGE_SIZE);
1040 if (paging_mem_size & (FW_PAGING_SIZE - 1)) {
1042 "Paging: image isn't multiple %lu\n",
1047 drv->fw.img[IWL_UCODE_REGULAR].paging_mem_size =
1049 usniffer_img = IWL_UCODE_REGULAR_USNIFFER;
1050 drv->fw.img[usniffer_img].paging_mem_size =
1053 case IWL_UCODE_TLV_FW_GSCAN_CAPA:
1056 case IWL_UCODE_TLV_FW_MEM_SEG: {
1057 struct iwl_fw_dbg_mem_seg_tlv *dbg_mem =
1060 struct iwl_fw_dbg_mem_seg_tlv *n;
1062 if (tlv_len != (sizeof(*dbg_mem)))
1063 goto invalid_tlv_len;
1065 IWL_DEBUG_INFO(drv, "Found debug memory segment: %u\n",
1066 dbg_mem->data_type);
1068 size = sizeof(*pieces->dbg_mem_tlv) *
1069 (pieces->n_mem_tlv + 1);
1070 n = krealloc(pieces->dbg_mem_tlv, size, GFP_KERNEL);
1073 pieces->dbg_mem_tlv = n;
1074 pieces->dbg_mem_tlv[pieces->n_mem_tlv] = *dbg_mem;
1075 pieces->n_mem_tlv++;
1078 case IWL_UCODE_TLV_IML: {
1079 drv->fw.iml_len = tlv_len;
1080 drv->fw.iml = kmemdup(tlv_data, tlv_len, GFP_KERNEL);
1085 case IWL_UCODE_TLV_FW_RECOVERY_INFO: {
1089 } *recov_info = (void *)tlv_data;
1091 if (tlv_len != sizeof(*recov_info))
1092 goto invalid_tlv_len;
1093 capa->error_log_addr =
1094 le32_to_cpu(recov_info->buf_addr);
1095 capa->error_log_size =
1096 le32_to_cpu(recov_info->buf_size);
1099 case IWL_UCODE_TLV_FW_FSEQ_VERSION: {
1103 } *fseq_ver = (void *)tlv_data;
1105 if (tlv_len != sizeof(*fseq_ver))
1106 goto invalid_tlv_len;
1107 IWL_INFO(drv, "TLV_FW_FSEQ_VERSION: %s\n",
1111 case IWL_UCODE_TLV_FW_NUM_STATIONS:
1112 if (tlv_len != sizeof(u32))
1113 goto invalid_tlv_len;
1114 if (le32_to_cpup((__le32 *)tlv_data) >
1115 IWL_MVM_STATION_COUNT_MAX) {
1117 "%d is an invalid number of station\n",
1118 le32_to_cpup((__le32 *)tlv_data));
1121 capa->num_stations =
1122 le32_to_cpup((__le32 *)tlv_data);
1124 case IWL_UCODE_TLV_UMAC_DEBUG_ADDRS: {
1125 struct iwl_umac_debug_addrs *dbg_ptrs =
1128 if (tlv_len != sizeof(*dbg_ptrs))
1129 goto invalid_tlv_len;
1130 if (drv->trans->trans_cfg->device_family <
1131 IWL_DEVICE_FAMILY_22000)
1133 drv->trans->dbg.umac_error_event_table =
1134 le32_to_cpu(dbg_ptrs->error_info_addr) &
1135 ~FW_ADDR_CACHE_CONTROL;
1136 drv->trans->dbg.error_event_table_tlv_status |=
1137 IWL_ERROR_EVENT_TABLE_UMAC;
1140 case IWL_UCODE_TLV_LMAC_DEBUG_ADDRS: {
1141 struct iwl_lmac_debug_addrs *dbg_ptrs =
1144 if (tlv_len != sizeof(*dbg_ptrs))
1145 goto invalid_tlv_len;
1146 if (drv->trans->trans_cfg->device_family <
1147 IWL_DEVICE_FAMILY_22000)
1149 drv->trans->dbg.lmac_error_event_table[0] =
1150 le32_to_cpu(dbg_ptrs->error_event_table_ptr) &
1151 ~FW_ADDR_CACHE_CONTROL;
1152 drv->trans->dbg.error_event_table_tlv_status |=
1153 IWL_ERROR_EVENT_TABLE_LMAC1;
1156 case IWL_UCODE_TLV_TCM_DEBUG_ADDRS: {
1157 struct iwl_fw_tcm_error_addr *ptr = (void *)tlv_data;
1159 if (tlv_len != sizeof(*ptr))
1160 goto invalid_tlv_len;
1161 drv->trans->dbg.tcm_error_event_table =
1162 le32_to_cpu(ptr->addr) & ~FW_ADDR_CACHE_CONTROL;
1163 drv->trans->dbg.error_event_table_tlv_status |=
1164 IWL_ERROR_EVENT_TABLE_TCM;
1167 case IWL_UCODE_TLV_TYPE_DEBUG_INFO:
1168 case IWL_UCODE_TLV_TYPE_BUFFER_ALLOCATION:
1169 case IWL_UCODE_TLV_TYPE_HCMD:
1170 case IWL_UCODE_TLV_TYPE_REGIONS:
1171 case IWL_UCODE_TLV_TYPE_TRIGGERS:
1172 case IWL_UCODE_TLV_TYPE_CONF_SET:
1173 if (iwlwifi_mod_params.enable_ini)
1174 iwl_dbg_tlv_alloc(drv->trans, tlv, false);
1176 case IWL_UCODE_TLV_CMD_VERSIONS:
1177 if (tlv_len % sizeof(struct iwl_fw_cmd_version)) {
1179 "Invalid length for command versions: %u\n",
1181 tlv_len /= sizeof(struct iwl_fw_cmd_version);
1182 tlv_len *= sizeof(struct iwl_fw_cmd_version);
1184 if (WARN_ON(capa->cmd_versions))
1186 capa->cmd_versions = kmemdup(tlv_data, tlv_len,
1188 if (!capa->cmd_versions)
1190 capa->n_cmd_versions =
1191 tlv_len / sizeof(struct iwl_fw_cmd_version);
1193 case IWL_UCODE_TLV_PHY_INTEGRATION_VERSION:
1194 if (drv->fw.phy_integration_ver) {
1196 "phy integration str ignored, already exists\n");
1200 drv->fw.phy_integration_ver =
1201 kmemdup(tlv_data, tlv_len, GFP_KERNEL);
1202 if (!drv->fw.phy_integration_ver)
1204 drv->fw.phy_integration_ver_len = tlv_len;
1206 case IWL_UCODE_TLV_SEC_TABLE_ADDR:
1207 case IWL_UCODE_TLV_D3_KEK_KCK_ADDR:
1208 iwl_drv_set_dump_exclude(drv, tlv_type,
1212 IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
1217 if (!fw_has_capa(capa, IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED) &&
1218 usniffer_req && !*usniffer_images) {
1220 "user selected to work with usniffer but usniffer image isn't available in ucode package\n");
1225 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
1226 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
1233 IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1235 iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
1240 static int iwl_alloc_ucode(struct iwl_drv *drv,
1241 struct iwl_firmware_pieces *pieces,
1242 enum iwl_ucode_type type)
1245 struct fw_desc *sec;
1247 sec = kcalloc(pieces->img[type].sec_counter, sizeof(*sec), GFP_KERNEL);
1250 drv->fw.img[type].sec = sec;
1251 drv->fw.img[type].num_sec = pieces->img[type].sec_counter;
1253 for (i = 0; i < pieces->img[type].sec_counter; i++)
1254 if (iwl_alloc_fw_desc(drv, &sec[i], get_sec(pieces, type, i)))
1260 static int validate_sec_sizes(struct iwl_drv *drv,
1261 struct iwl_firmware_pieces *pieces,
1262 const struct iwl_cfg *cfg)
1264 IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %zd\n",
1265 get_sec_size(pieces, IWL_UCODE_REGULAR,
1266 IWL_UCODE_SECTION_INST));
1267 IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %zd\n",
1268 get_sec_size(pieces, IWL_UCODE_REGULAR,
1269 IWL_UCODE_SECTION_DATA));
1270 IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %zd\n",
1271 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
1272 IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %zd\n",
1273 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
1275 /* Verify that uCode images will fit in card's SRAM. */
1276 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
1277 cfg->max_inst_size) {
1278 IWL_ERR(drv, "uCode instr len %zd too large to fit in\n",
1279 get_sec_size(pieces, IWL_UCODE_REGULAR,
1280 IWL_UCODE_SECTION_INST));
1284 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
1285 cfg->max_data_size) {
1286 IWL_ERR(drv, "uCode data len %zd too large to fit in\n",
1287 get_sec_size(pieces, IWL_UCODE_REGULAR,
1288 IWL_UCODE_SECTION_DATA));
1292 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
1293 cfg->max_inst_size) {
1294 IWL_ERR(drv, "uCode init instr len %zd too large to fit in\n",
1295 get_sec_size(pieces, IWL_UCODE_INIT,
1296 IWL_UCODE_SECTION_INST));
1300 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
1301 cfg->max_data_size) {
1302 IWL_ERR(drv, "uCode init data len %zd too large to fit in\n",
1303 get_sec_size(pieces, IWL_UCODE_REGULAR,
1304 IWL_UCODE_SECTION_DATA));
1310 static struct iwl_op_mode *
1311 _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
1313 const struct iwl_op_mode_ops *ops = op->ops;
1314 struct dentry *dbgfs_dir = NULL;
1315 struct iwl_op_mode *op_mode = NULL;
1317 #ifdef CONFIG_IWLWIFI_DEBUGFS
1318 drv->dbgfs_op_mode = debugfs_create_dir(op->name,
1320 dbgfs_dir = drv->dbgfs_op_mode;
1323 op_mode = ops->start(drv->trans, drv->trans->cfg, &drv->fw, dbgfs_dir);
1325 #ifdef CONFIG_IWLWIFI_DEBUGFS
1327 debugfs_remove_recursive(drv->dbgfs_op_mode);
1328 drv->dbgfs_op_mode = NULL;
1335 static void _iwl_op_mode_stop(struct iwl_drv *drv)
1337 /* op_mode can be NULL if its start failed */
1339 iwl_op_mode_stop(drv->op_mode);
1340 drv->op_mode = NULL;
1342 #ifdef CONFIG_IWLWIFI_DEBUGFS
1343 debugfs_remove_recursive(drv->dbgfs_op_mode);
1344 drv->dbgfs_op_mode = NULL;
1350 * iwl_req_fw_callback - callback when firmware was loaded
1352 * If loaded successfully, copies the firmware into buffers
1353 * for the card to fetch (via DMA).
1355 static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
1357 struct iwl_drv *drv = context;
1358 struct iwl_fw *fw = &drv->fw;
1359 struct iwl_ucode_header *ucode;
1360 struct iwlwifi_opmode_table *op;
1362 struct iwl_firmware_pieces *pieces;
1363 const unsigned int api_max = drv->trans->cfg->ucode_api_max;
1364 const unsigned int api_min = drv->trans->cfg->ucode_api_min;
1365 size_t trigger_tlv_sz[FW_DBG_TRIGGER_MAX];
1368 bool load_module = false;
1369 bool usniffer_images = false;
1371 fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
1372 fw->ucode_capa.standard_phy_calibration_size =
1373 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1374 fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS;
1375 fw->ucode_capa.num_stations = IWL_MVM_STATION_COUNT_MAX;
1376 /* dump all fw memory areas by default */
1377 fw->dbg.dump_mask = 0xffffffff;
1379 pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
1386 IWL_DEBUG_FW_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
1387 drv->firmware_name, ucode_raw->size);
1389 /* Make sure that we got at least the API version number */
1390 if (ucode_raw->size < 4) {
1391 IWL_ERR(drv, "File size way too small!\n");
1395 /* Data from ucode file: header followed by uCode images */
1396 ucode = (struct iwl_ucode_header *)ucode_raw->data;
1399 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, pieces);
1401 err = iwl_parse_tlv_firmware(drv, ucode_raw, pieces,
1402 &fw->ucode_capa, &usniffer_images);
1407 if (fw_has_api(&drv->fw.ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION))
1408 api_ver = drv->fw.ucode_ver;
1410 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
1413 * api_ver should match the api version forming part of the
1414 * firmware filename ... but we don't check for that and only rely
1415 * on the API version read from firmware header from here on forward
1417 if (api_ver < api_min || api_ver > api_max) {
1419 "Driver unable to support your firmware API. "
1420 "Driver supports v%u, firmware is v%u.\n",
1426 * In mvm uCode there is no difference between data and instructions
1429 if (fw->type == IWL_FW_DVM && validate_sec_sizes(drv, pieces,
1433 /* Allocate ucode buffers for card's bus-master loading ... */
1435 /* Runtime instructions and 2 copies of data:
1436 * 1) unmodified from disk
1437 * 2) backup cache for save/restore during power-downs
1439 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
1440 if (iwl_alloc_ucode(drv, pieces, i))
1443 if (pieces->dbg_dest_tlv_init) {
1444 size_t dbg_dest_size = sizeof(*drv->fw.dbg.dest_tlv) +
1445 sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1446 drv->fw.dbg.n_dest_reg;
1448 drv->fw.dbg.dest_tlv = kmalloc(dbg_dest_size, GFP_KERNEL);
1450 if (!drv->fw.dbg.dest_tlv)
1453 if (*pieces->dbg_dest_ver == 0) {
1454 memcpy(drv->fw.dbg.dest_tlv, pieces->dbg_dest_tlv_v1,
1457 struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv =
1458 drv->fw.dbg.dest_tlv;
1460 dest_tlv->version = pieces->dbg_dest_tlv->version;
1461 dest_tlv->monitor_mode =
1462 pieces->dbg_dest_tlv->monitor_mode;
1463 dest_tlv->size_power =
1464 pieces->dbg_dest_tlv->size_power;
1465 dest_tlv->wrap_count =
1466 pieces->dbg_dest_tlv->wrap_count;
1467 dest_tlv->write_ptr_reg =
1468 pieces->dbg_dest_tlv->write_ptr_reg;
1469 dest_tlv->base_shift =
1470 pieces->dbg_dest_tlv->base_shift;
1471 memcpy(dest_tlv->reg_ops,
1472 pieces->dbg_dest_tlv->reg_ops,
1473 sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1474 drv->fw.dbg.n_dest_reg);
1476 /* In version 1 of the destination tlv, which is
1477 * relevant for internal buffer exclusively,
1478 * the base address is part of given with the length
1479 * of the buffer, and the size shift is give instead of
1480 * end shift. We now store these values in base_reg,
1481 * and end shift, and when dumping the data we'll
1482 * manipulate it for extracting both the length and
1484 dest_tlv->base_reg = pieces->dbg_dest_tlv->cfg_reg;
1485 dest_tlv->end_shift =
1486 pieces->dbg_dest_tlv->size_shift;
1490 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++) {
1491 if (pieces->dbg_conf_tlv[i]) {
1492 drv->fw.dbg.conf_tlv[i] =
1493 kmemdup(pieces->dbg_conf_tlv[i],
1494 pieces->dbg_conf_tlv_len[i],
1496 if (!drv->fw.dbg.conf_tlv[i])
1501 memset(&trigger_tlv_sz, 0xff, sizeof(trigger_tlv_sz));
1503 trigger_tlv_sz[FW_DBG_TRIGGER_MISSED_BEACONS] =
1504 sizeof(struct iwl_fw_dbg_trigger_missed_bcon);
1505 trigger_tlv_sz[FW_DBG_TRIGGER_CHANNEL_SWITCH] = 0;
1506 trigger_tlv_sz[FW_DBG_TRIGGER_FW_NOTIF] =
1507 sizeof(struct iwl_fw_dbg_trigger_cmd);
1508 trigger_tlv_sz[FW_DBG_TRIGGER_MLME] =
1509 sizeof(struct iwl_fw_dbg_trigger_mlme);
1510 trigger_tlv_sz[FW_DBG_TRIGGER_STATS] =
1511 sizeof(struct iwl_fw_dbg_trigger_stats);
1512 trigger_tlv_sz[FW_DBG_TRIGGER_RSSI] =
1513 sizeof(struct iwl_fw_dbg_trigger_low_rssi);
1514 trigger_tlv_sz[FW_DBG_TRIGGER_TXQ_TIMERS] =
1515 sizeof(struct iwl_fw_dbg_trigger_txq_timer);
1516 trigger_tlv_sz[FW_DBG_TRIGGER_TIME_EVENT] =
1517 sizeof(struct iwl_fw_dbg_trigger_time_event);
1518 trigger_tlv_sz[FW_DBG_TRIGGER_BA] =
1519 sizeof(struct iwl_fw_dbg_trigger_ba);
1520 trigger_tlv_sz[FW_DBG_TRIGGER_TDLS] =
1521 sizeof(struct iwl_fw_dbg_trigger_tdls);
1523 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++) {
1524 if (pieces->dbg_trigger_tlv[i]) {
1526 * If the trigger isn't long enough, WARN and exit.
1527 * Someone is trying to debug something and he won't
1528 * be able to catch the bug he is trying to chase.
1529 * We'd better be noisy to be sure he knows what's
1532 if (WARN_ON(pieces->dbg_trigger_tlv_len[i] <
1533 (trigger_tlv_sz[i] +
1534 sizeof(struct iwl_fw_dbg_trigger_tlv))))
1536 drv->fw.dbg.trigger_tlv_len[i] =
1537 pieces->dbg_trigger_tlv_len[i];
1538 drv->fw.dbg.trigger_tlv[i] =
1539 kmemdup(pieces->dbg_trigger_tlv[i],
1540 drv->fw.dbg.trigger_tlv_len[i],
1542 if (!drv->fw.dbg.trigger_tlv[i])
1547 /* Now that we can no longer fail, copy information */
1549 drv->fw.dbg.mem_tlv = pieces->dbg_mem_tlv;
1550 pieces->dbg_mem_tlv = NULL;
1551 drv->fw.dbg.n_mem_tlv = pieces->n_mem_tlv;
1554 * The (size - 16) / 12 formula is based on the information recorded
1555 * for each event, which is of mode 1 (including timestamp) for all
1556 * new microcodes that include this information.
1558 fw->init_evtlog_ptr = pieces->init_evtlog_ptr;
1559 if (pieces->init_evtlog_size)
1560 fw->init_evtlog_size = (pieces->init_evtlog_size - 16)/12;
1562 fw->init_evtlog_size =
1563 drv->trans->trans_cfg->base_params->max_event_log_size;
1564 fw->init_errlog_ptr = pieces->init_errlog_ptr;
1565 fw->inst_evtlog_ptr = pieces->inst_evtlog_ptr;
1566 if (pieces->inst_evtlog_size)
1567 fw->inst_evtlog_size = (pieces->inst_evtlog_size - 16)/12;
1569 fw->inst_evtlog_size =
1570 drv->trans->trans_cfg->base_params->max_event_log_size;
1571 fw->inst_errlog_ptr = pieces->inst_errlog_ptr;
1574 * figure out the offset of chain noise reset and gain commands
1575 * base on the size of standard phy calibration commands table size
1577 if (fw->ucode_capa.standard_phy_calibration_size >
1578 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1579 fw->ucode_capa.standard_phy_calibration_size =
1580 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1582 /* We have our copies now, allow OS release its copies */
1583 release_firmware(ucode_raw);
1585 mutex_lock(&iwlwifi_opmode_table_mtx);
1588 op = &iwlwifi_opmode_table[DVM_OP_MODE];
1591 WARN(1, "Invalid fw type %d\n", fw->type);
1594 op = &iwlwifi_opmode_table[MVM_OP_MODE];
1598 IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1599 drv->fw.fw_version, op->name);
1601 iwl_dbg_tlv_load_bin(drv->trans->dev, drv->trans);
1603 /* add this device to the list of devices using this op_mode */
1604 list_add_tail(&drv->list, &op->drv);
1607 drv->op_mode = _iwl_op_mode_start(drv, op);
1609 if (!drv->op_mode) {
1610 mutex_unlock(&iwlwifi_opmode_table_mtx);
1616 mutex_unlock(&iwlwifi_opmode_table_mtx);
1619 * Complete the firmware request last so that
1620 * a driver unbind (stop) doesn't run while we
1621 * are doing the start() above.
1623 complete(&drv->request_firmware_complete);
1626 * Load the module last so we don't block anything
1627 * else from proceeding if the module fails to load
1631 request_module("%s", op->name);
1632 #ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
1635 "failed to load module %s (error %d), is dynamic loading enabled?\n",
1642 /* try next, if any */
1643 release_firmware(ucode_raw);
1644 if (iwl_request_firmware(drv, false))
1649 release_firmware(ucode_raw);
1651 complete(&drv->request_firmware_complete);
1652 device_release_driver(drv->trans->dev);
1655 for (i = 0; i < ARRAY_SIZE(pieces->img); i++)
1656 kfree(pieces->img[i].sec);
1657 kfree(pieces->dbg_mem_tlv);
1662 struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
1664 struct iwl_drv *drv;
1667 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
1674 drv->dev = trans->dev;
1676 init_completion(&drv->request_firmware_complete);
1677 INIT_LIST_HEAD(&drv->list);
1679 #ifdef CONFIG_IWLWIFI_DEBUGFS
1680 /* Create the device debugfs entries. */
1681 drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1684 /* Create transport layer debugfs dir */
1685 drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1688 drv->trans->dbg.domains_bitmap = IWL_TRANS_FW_DBG_DOMAIN(drv->trans);
1690 ret = iwl_request_firmware(drv, true);
1692 IWL_ERR(trans, "Couldn't request the fw\n");
1699 #ifdef CONFIG_IWLWIFI_DEBUGFS
1700 debugfs_remove_recursive(drv->dbgfs_drv);
1701 iwl_dbg_tlv_free(drv->trans);
1705 return ERR_PTR(ret);
1708 void iwl_drv_stop(struct iwl_drv *drv)
1710 wait_for_completion(&drv->request_firmware_complete);
1712 _iwl_op_mode_stop(drv);
1714 iwl_dealloc_ucode(drv);
1716 mutex_lock(&iwlwifi_opmode_table_mtx);
1718 * List is empty (this item wasn't added)
1719 * when firmware loading failed -- in that
1720 * case we can't remove it from any list.
1722 if (!list_empty(&drv->list))
1723 list_del(&drv->list);
1724 mutex_unlock(&iwlwifi_opmode_table_mtx);
1726 #ifdef CONFIG_IWLWIFI_DEBUGFS
1727 drv->trans->ops->debugfs_cleanup(drv->trans);
1729 debugfs_remove_recursive(drv->dbgfs_drv);
1732 iwl_dbg_tlv_free(drv->trans);
1738 /* shared module parameters */
1739 struct iwl_mod_params iwlwifi_mod_params = {
1741 .bt_coex_active = true,
1742 .power_level = IWL_POWER_INDEX_1,
1743 .uapsd_disable = IWL_DISABLE_UAPSD_BSS | IWL_DISABLE_UAPSD_P2P_CLIENT,
1745 /* the rest are 0 by default */
1747 IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
1749 int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1752 struct iwl_drv *drv;
1753 struct iwlwifi_opmode_table *op;
1755 mutex_lock(&iwlwifi_opmode_table_mtx);
1756 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1757 op = &iwlwifi_opmode_table[i];
1758 if (strcmp(op->name, name))
1761 /* TODO: need to handle exceptional case */
1762 list_for_each_entry(drv, &op->drv, list)
1763 drv->op_mode = _iwl_op_mode_start(drv, op);
1765 mutex_unlock(&iwlwifi_opmode_table_mtx);
1768 mutex_unlock(&iwlwifi_opmode_table_mtx);
1771 IWL_EXPORT_SYMBOL(iwl_opmode_register);
1773 void iwl_opmode_deregister(const char *name)
1776 struct iwl_drv *drv;
1778 mutex_lock(&iwlwifi_opmode_table_mtx);
1779 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1780 if (strcmp(iwlwifi_opmode_table[i].name, name))
1782 iwlwifi_opmode_table[i].ops = NULL;
1784 /* call the stop routine for all devices */
1785 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1786 _iwl_op_mode_stop(drv);
1788 mutex_unlock(&iwlwifi_opmode_table_mtx);
1791 mutex_unlock(&iwlwifi_opmode_table_mtx);
1793 IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
1795 static int __init iwl_drv_init(void)
1799 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1800 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1802 pr_info(DRV_DESCRIPTION "\n");
1804 #ifdef CONFIG_IWLWIFI_DEBUGFS
1805 /* Create the root of iwlwifi debugfs subsystem. */
1806 iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1809 err = iwl_pci_register_driver();
1811 goto cleanup_debugfs;
1816 #ifdef CONFIG_IWLWIFI_DEBUGFS
1817 debugfs_remove_recursive(iwl_dbgfs_root);
1821 module_init(iwl_drv_init);
1823 static void __exit iwl_drv_exit(void)
1825 iwl_pci_unregister_driver();
1827 #ifdef CONFIG_IWLWIFI_DEBUGFS
1828 debugfs_remove_recursive(iwl_dbgfs_root);
1831 module_exit(iwl_drv_exit);
1833 #ifdef CONFIG_IWLWIFI_DEBUG
1834 module_param_named(debug, iwlwifi_mod_params.debug_level, uint, 0644);
1835 MODULE_PARM_DESC(debug, "debug output mask");
1838 module_param_named(swcrypto, iwlwifi_mod_params.swcrypto, int, 0444);
1839 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1840 module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, 0444);
1841 MODULE_PARM_DESC(11n_disable,
1842 "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
1843 module_param_named(amsdu_size, iwlwifi_mod_params.amsdu_size, int, 0444);
1844 MODULE_PARM_DESC(amsdu_size,
1845 "amsdu size 0: 12K for multi Rx queue devices, 2K for AX210 devices, "
1846 "4K for other devices 1:4K 2:8K 3:12K (16K buffers) 4: 2K (default 0)");
1847 module_param_named(fw_restart, iwlwifi_mod_params.fw_restart, bool, 0444);
1848 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
1850 module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, 0444);
1851 MODULE_PARM_DESC(nvm_file, "NVM file name");
1853 module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable, uint, 0644);
1854 MODULE_PARM_DESC(uapsd_disable,
1855 "disable U-APSD functionality bitmap 1: BSS 2: P2P Client (default: 3)");
1856 module_param_named(enable_ini, iwlwifi_mod_params.enable_ini,
1857 bool, S_IRUGO | S_IWUSR);
1858 MODULE_PARM_DESC(enable_ini,
1859 "Enable debug INI TLV FW debug infrastructure (default: true");
1862 * set bt_coex_active to true, uCode will do kill/defer
1863 * every time the priority line is asserted (BT is sending signals on the
1864 * priority line in the PCIx).
1865 * set bt_coex_active to false, uCode will ignore the BT activity and
1866 * perform the normal operation
1868 * User might experience transmit issue on some platform due to WiFi/BT
1869 * co-exist problem. The possible behaviors are:
1870 * Able to scan and finding all the available AP
1871 * Not able to associate with any AP
1872 * On those platforms, WiFi communication can be restored by set
1873 * "bt_coex_active" module parameter to "false"
1875 * default: bt_coex_active = true (BT_COEX_ENABLE)
1877 module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1879 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1881 module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, 0444);
1882 MODULE_PARM_DESC(led_mode, "0=system default, "
1883 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1885 module_param_named(power_save, iwlwifi_mod_params.power_save, bool, 0444);
1886 MODULE_PARM_DESC(power_save,
1887 "enable WiFi power management (default: disable)");
1889 module_param_named(power_level, iwlwifi_mod_params.power_level, int, 0444);
1890 MODULE_PARM_DESC(power_level,
1891 "default power save level (range from 1 - 5, default: 1)");
1893 module_param_named(disable_11ac, iwlwifi_mod_params.disable_11ac, bool, 0444);
1894 MODULE_PARM_DESC(disable_11ac, "Disable VHT capabilities (default: false)");
1896 module_param_named(remove_when_gone,
1897 iwlwifi_mod_params.remove_when_gone, bool,
1899 MODULE_PARM_DESC(remove_when_gone,
1900 "Remove dev from PCIe bus if it is deemed inaccessible (default: false)");
1902 module_param_named(disable_11ax, iwlwifi_mod_params.disable_11ax, bool,
1904 MODULE_PARM_DESC(disable_11ax, "Disable HE capabilities (default: false)");