1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2005-2014, 2018-2020 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_AUTHOR(DRV_AUTHOR);
35 MODULE_LICENSE("GPL");
37 #ifdef CONFIG_IWLWIFI_DEBUGFS
38 static struct dentry *iwl_dbgfs_root;
42 * struct iwl_drv - drv common data
43 * @list: list of drv structures using this opmode
44 * @fw: the iwl_fw structure
45 * @op_mode: the running op_mode
46 * @trans: transport layer
47 * @dev: for debug prints only
48 * @fw_index: firmware revision to try loading
49 * @firmware_name: composite filename of ucode file to load
50 * @request_firmware_complete: the firmware has been obtained from user space
51 * @dbgfs_drv: debugfs root directory entry
52 * @dbgfs_trans: debugfs transport directory entry
53 * @dbgfs_op_mode: debugfs op_mode directory entry
56 struct list_head list;
59 struct iwl_op_mode *op_mode;
60 struct iwl_trans *trans;
63 int fw_index; /* firmware we're trying to load */
64 char firmware_name[64]; /* name of firmware file to load */
66 struct completion request_firmware_complete;
68 #ifdef CONFIG_IWLWIFI_DEBUGFS
69 struct dentry *dbgfs_drv;
70 struct dentry *dbgfs_trans;
71 struct dentry *dbgfs_op_mode;
80 /* Protects the table contents, i.e. the ops pointer & drv list */
81 static struct mutex iwlwifi_opmode_table_mtx;
82 static struct iwlwifi_opmode_table {
83 const char *name; /* name: iwldvm, iwlmvm, etc */
84 const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
85 struct list_head drv; /* list of devices using this op_mode */
86 } iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
87 [DVM_OP_MODE] = { .name = "iwldvm", .ops = NULL },
88 [MVM_OP_MODE] = { .name = "iwlmvm", .ops = NULL },
91 #define IWL_DEFAULT_SCAN_CHANNELS 40
94 * struct fw_sec: Just for the image parsing process.
95 * For the fw storage we are using struct fw_desc.
98 const void *data; /* the sec data */
99 size_t size; /* section size */
100 u32 offset; /* offset of writing in the device */
103 static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
110 static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
113 for (i = 0; i < img->num_sec; i++)
114 iwl_free_fw_desc(drv, &img->sec[i]);
118 static void iwl_dealloc_ucode(struct iwl_drv *drv)
122 kfree(drv->fw.dbg.dest_tlv);
123 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++)
124 kfree(drv->fw.dbg.conf_tlv[i]);
125 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++)
126 kfree(drv->fw.dbg.trigger_tlv[i]);
127 kfree(drv->fw.dbg.mem_tlv);
129 kfree(drv->fw.ucode_capa.cmd_versions);
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 #define FW_ADDR_CACHE_CONTROL 0xC0000000
554 static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
555 const struct firmware *ucode_raw,
556 struct iwl_firmware_pieces *pieces,
557 struct iwl_ucode_capabilities *capa,
558 bool *usniffer_images)
560 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
561 struct iwl_ucode_tlv *tlv;
562 size_t len = ucode_raw->size;
566 enum iwl_ucode_tlv_type tlv_type;
569 u32 build, paging_mem_size;
571 bool usniffer_req = false;
573 if (len < sizeof(*ucode)) {
574 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
578 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
579 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
580 le32_to_cpu(ucode->magic));
584 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
585 memcpy(drv->fw.human_readable, ucode->human_readable,
586 sizeof(drv->fw.human_readable));
587 build = le32_to_cpu(ucode->build);
590 sprintf(buildstr, " build %u", build);
594 snprintf(drv->fw.fw_version,
595 sizeof(drv->fw.fw_version),
597 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
598 IWL_UCODE_MINOR(drv->fw.ucode_ver),
599 IWL_UCODE_API(drv->fw.ucode_ver),
600 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
601 buildstr, iwl_reduced_fw_name(drv));
605 len -= sizeof(*ucode);
607 while (len >= sizeof(*tlv)) {
611 tlv_len = le32_to_cpu(tlv->length);
612 tlv_type = le32_to_cpu(tlv->type);
613 tlv_data = tlv->data;
616 IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
620 len -= ALIGN(tlv_len, 4);
621 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
624 case IWL_UCODE_TLV_INST:
625 set_sec_data(pieces, IWL_UCODE_REGULAR,
626 IWL_UCODE_SECTION_INST, tlv_data);
627 set_sec_size(pieces, IWL_UCODE_REGULAR,
628 IWL_UCODE_SECTION_INST, tlv_len);
629 set_sec_offset(pieces, IWL_UCODE_REGULAR,
630 IWL_UCODE_SECTION_INST,
631 IWLAGN_RTC_INST_LOWER_BOUND);
633 case IWL_UCODE_TLV_DATA:
634 set_sec_data(pieces, IWL_UCODE_REGULAR,
635 IWL_UCODE_SECTION_DATA, tlv_data);
636 set_sec_size(pieces, IWL_UCODE_REGULAR,
637 IWL_UCODE_SECTION_DATA, tlv_len);
638 set_sec_offset(pieces, IWL_UCODE_REGULAR,
639 IWL_UCODE_SECTION_DATA,
640 IWLAGN_RTC_DATA_LOWER_BOUND);
642 case IWL_UCODE_TLV_INIT:
643 set_sec_data(pieces, IWL_UCODE_INIT,
644 IWL_UCODE_SECTION_INST, tlv_data);
645 set_sec_size(pieces, IWL_UCODE_INIT,
646 IWL_UCODE_SECTION_INST, tlv_len);
647 set_sec_offset(pieces, IWL_UCODE_INIT,
648 IWL_UCODE_SECTION_INST,
649 IWLAGN_RTC_INST_LOWER_BOUND);
651 case IWL_UCODE_TLV_INIT_DATA:
652 set_sec_data(pieces, IWL_UCODE_INIT,
653 IWL_UCODE_SECTION_DATA, tlv_data);
654 set_sec_size(pieces, IWL_UCODE_INIT,
655 IWL_UCODE_SECTION_DATA, tlv_len);
656 set_sec_offset(pieces, IWL_UCODE_INIT,
657 IWL_UCODE_SECTION_DATA,
658 IWLAGN_RTC_DATA_LOWER_BOUND);
660 case IWL_UCODE_TLV_BOOT:
661 IWL_ERR(drv, "Found unexpected BOOT ucode\n");
663 case IWL_UCODE_TLV_PROBE_MAX_LEN:
664 if (tlv_len != sizeof(u32))
665 goto invalid_tlv_len;
666 capa->max_probe_length =
667 le32_to_cpup((__le32 *)tlv_data);
669 case IWL_UCODE_TLV_PAN:
671 goto invalid_tlv_len;
672 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
674 case IWL_UCODE_TLV_FLAGS:
675 /* must be at least one u32 */
676 if (tlv_len < sizeof(u32))
677 goto invalid_tlv_len;
678 /* and a proper number of u32s */
679 if (tlv_len % sizeof(u32))
680 goto invalid_tlv_len;
682 * This driver only reads the first u32 as
683 * right now no more features are defined,
684 * if that changes then either the driver
685 * will not work with the new firmware, or
686 * it'll not take advantage of new features.
688 capa->flags = le32_to_cpup((__le32 *)tlv_data);
690 case IWL_UCODE_TLV_API_CHANGES_SET:
691 if (tlv_len != sizeof(struct iwl_ucode_api))
692 goto invalid_tlv_len;
693 iwl_set_ucode_api_flags(drv, tlv_data, capa);
695 case IWL_UCODE_TLV_ENABLED_CAPABILITIES:
696 if (tlv_len != sizeof(struct iwl_ucode_capa))
697 goto invalid_tlv_len;
698 iwl_set_ucode_capabilities(drv, tlv_data, capa);
700 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
701 if (tlv_len != sizeof(u32))
702 goto invalid_tlv_len;
703 pieces->init_evtlog_ptr =
704 le32_to_cpup((__le32 *)tlv_data);
706 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
707 if (tlv_len != sizeof(u32))
708 goto invalid_tlv_len;
709 pieces->init_evtlog_size =
710 le32_to_cpup((__le32 *)tlv_data);
712 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
713 if (tlv_len != sizeof(u32))
714 goto invalid_tlv_len;
715 pieces->init_errlog_ptr =
716 le32_to_cpup((__le32 *)tlv_data);
718 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
719 if (tlv_len != sizeof(u32))
720 goto invalid_tlv_len;
721 pieces->inst_evtlog_ptr =
722 le32_to_cpup((__le32 *)tlv_data);
724 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
725 if (tlv_len != sizeof(u32))
726 goto invalid_tlv_len;
727 pieces->inst_evtlog_size =
728 le32_to_cpup((__le32 *)tlv_data);
730 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
731 if (tlv_len != sizeof(u32))
732 goto invalid_tlv_len;
733 pieces->inst_errlog_ptr =
734 le32_to_cpup((__le32 *)tlv_data);
736 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
738 goto invalid_tlv_len;
739 drv->fw.enhance_sensitivity_table = true;
741 case IWL_UCODE_TLV_WOWLAN_INST:
742 set_sec_data(pieces, IWL_UCODE_WOWLAN,
743 IWL_UCODE_SECTION_INST, tlv_data);
744 set_sec_size(pieces, IWL_UCODE_WOWLAN,
745 IWL_UCODE_SECTION_INST, tlv_len);
746 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
747 IWL_UCODE_SECTION_INST,
748 IWLAGN_RTC_INST_LOWER_BOUND);
750 case IWL_UCODE_TLV_WOWLAN_DATA:
751 set_sec_data(pieces, IWL_UCODE_WOWLAN,
752 IWL_UCODE_SECTION_DATA, tlv_data);
753 set_sec_size(pieces, IWL_UCODE_WOWLAN,
754 IWL_UCODE_SECTION_DATA, tlv_len);
755 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
756 IWL_UCODE_SECTION_DATA,
757 IWLAGN_RTC_DATA_LOWER_BOUND);
759 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
760 if (tlv_len != sizeof(u32))
761 goto invalid_tlv_len;
762 capa->standard_phy_calibration_size =
763 le32_to_cpup((__le32 *)tlv_data);
765 case IWL_UCODE_TLV_SEC_RT:
766 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
768 drv->fw.type = IWL_FW_MVM;
770 case IWL_UCODE_TLV_SEC_INIT:
771 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
773 drv->fw.type = IWL_FW_MVM;
775 case IWL_UCODE_TLV_SEC_WOWLAN:
776 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
778 drv->fw.type = IWL_FW_MVM;
780 case IWL_UCODE_TLV_DEF_CALIB:
781 if (tlv_len != sizeof(struct iwl_tlv_calib_data))
782 goto invalid_tlv_len;
783 if (iwl_set_default_calib(drv, tlv_data))
786 case IWL_UCODE_TLV_PHY_SKU:
787 if (tlv_len != sizeof(u32))
788 goto invalid_tlv_len;
789 drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
790 drv->fw.valid_tx_ant = (drv->fw.phy_config &
791 FW_PHY_CFG_TX_CHAIN) >>
792 FW_PHY_CFG_TX_CHAIN_POS;
793 drv->fw.valid_rx_ant = (drv->fw.phy_config &
794 FW_PHY_CFG_RX_CHAIN) >>
795 FW_PHY_CFG_RX_CHAIN_POS;
797 case IWL_UCODE_TLV_SECURE_SEC_RT:
798 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
800 drv->fw.type = IWL_FW_MVM;
802 case IWL_UCODE_TLV_SECURE_SEC_INIT:
803 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
805 drv->fw.type = IWL_FW_MVM;
807 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN:
808 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
810 drv->fw.type = IWL_FW_MVM;
812 case IWL_UCODE_TLV_NUM_OF_CPU:
813 if (tlv_len != sizeof(u32))
814 goto invalid_tlv_len;
816 le32_to_cpup((__le32 *)tlv_data);
818 if (num_of_cpus == 2) {
819 drv->fw.img[IWL_UCODE_REGULAR].is_dual_cpus =
821 drv->fw.img[IWL_UCODE_INIT].is_dual_cpus =
823 drv->fw.img[IWL_UCODE_WOWLAN].is_dual_cpus =
825 } else if ((num_of_cpus > 2) || (num_of_cpus < 1)) {
826 IWL_ERR(drv, "Driver support upto 2 CPUs\n");
830 case IWL_UCODE_TLV_CSCHEME:
831 if (iwl_store_cscheme(&drv->fw, tlv_data, tlv_len))
832 goto invalid_tlv_len;
834 case IWL_UCODE_TLV_N_SCAN_CHANNELS:
835 if (tlv_len != sizeof(u32))
836 goto invalid_tlv_len;
837 capa->n_scan_channels =
838 le32_to_cpup((__le32 *)tlv_data);
840 case IWL_UCODE_TLV_FW_VERSION: {
841 __le32 *ptr = (void *)tlv_data;
845 if (tlv_len != sizeof(u32) * 3)
846 goto invalid_tlv_len;
848 major = le32_to_cpup(ptr++);
849 minor = le32_to_cpup(ptr++);
850 local_comp = le32_to_cpup(ptr);
853 snprintf(drv->fw.fw_version,
854 sizeof(drv->fw.fw_version),
855 "%u.%08x.%u %s", major, minor,
856 local_comp, iwl_reduced_fw_name(drv));
858 snprintf(drv->fw.fw_version,
859 sizeof(drv->fw.fw_version),
860 "%u.%u.%u %s", major, minor,
861 local_comp, iwl_reduced_fw_name(drv));
864 case IWL_UCODE_TLV_FW_DBG_DEST: {
865 struct iwl_fw_dbg_dest_tlv *dest = NULL;
866 struct iwl_fw_dbg_dest_tlv_v1 *dest_v1 = NULL;
869 pieces->dbg_dest_ver = (u8 *)tlv_data;
870 if (*pieces->dbg_dest_ver == 1) {
871 dest = (void *)tlv_data;
872 } else if (*pieces->dbg_dest_ver == 0) {
873 dest_v1 = (void *)tlv_data;
876 "The version is %d, and it is invalid\n",
877 *pieces->dbg_dest_ver);
881 if (pieces->dbg_dest_tlv_init) {
883 "dbg destination ignored, already exists\n");
887 pieces->dbg_dest_tlv_init = true;
890 pieces->dbg_dest_tlv_v1 = dest_v1;
891 mon_mode = dest_v1->monitor_mode;
893 pieces->dbg_dest_tlv = dest;
894 mon_mode = dest->monitor_mode;
897 IWL_INFO(drv, "Found debug destination: %s\n",
898 get_fw_dbg_mode_string(mon_mode));
900 drv->fw.dbg.n_dest_reg = (dest_v1) ?
902 offsetof(struct iwl_fw_dbg_dest_tlv_v1,
905 offsetof(struct iwl_fw_dbg_dest_tlv,
908 drv->fw.dbg.n_dest_reg /=
909 sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]);
913 case IWL_UCODE_TLV_FW_DBG_CONF: {
914 struct iwl_fw_dbg_conf_tlv *conf = (void *)tlv_data;
916 if (!pieces->dbg_dest_tlv_init) {
918 "Ignore dbg config %d - no destination configured\n",
923 if (conf->id >= ARRAY_SIZE(drv->fw.dbg.conf_tlv)) {
925 "Skip unknown configuration: %d\n",
930 if (pieces->dbg_conf_tlv[conf->id]) {
932 "Ignore duplicate dbg config %d\n",
940 IWL_INFO(drv, "Found debug configuration: %d\n",
943 pieces->dbg_conf_tlv[conf->id] = conf;
944 pieces->dbg_conf_tlv_len[conf->id] = tlv_len;
947 case IWL_UCODE_TLV_FW_DBG_TRIGGER: {
948 struct iwl_fw_dbg_trigger_tlv *trigger =
950 u32 trigger_id = le32_to_cpu(trigger->id);
952 if (trigger_id >= ARRAY_SIZE(drv->fw.dbg.trigger_tlv)) {
954 "Skip unknown trigger: %u\n",
959 if (pieces->dbg_trigger_tlv[trigger_id]) {
961 "Ignore duplicate dbg trigger %u\n",
966 IWL_INFO(drv, "Found debug trigger: %u\n", trigger->id);
968 pieces->dbg_trigger_tlv[trigger_id] = trigger;
969 pieces->dbg_trigger_tlv_len[trigger_id] = tlv_len;
972 case IWL_UCODE_TLV_FW_DBG_DUMP_LST: {
973 if (tlv_len != sizeof(u32)) {
975 "dbg lst mask size incorrect, skip\n");
979 drv->fw.dbg.dump_mask =
980 le32_to_cpup((__le32 *)tlv_data);
983 case IWL_UCODE_TLV_SEC_RT_USNIFFER:
984 *usniffer_images = true;
985 iwl_store_ucode_sec(pieces, tlv_data,
986 IWL_UCODE_REGULAR_USNIFFER,
989 case IWL_UCODE_TLV_PAGING:
990 if (tlv_len != sizeof(u32))
991 goto invalid_tlv_len;
992 paging_mem_size = le32_to_cpup((__le32 *)tlv_data);
995 "Paging: paging enabled (size = %u bytes)\n",
998 if (paging_mem_size > MAX_PAGING_IMAGE_SIZE) {
1000 "Paging: driver supports up to %lu bytes for paging image\n",
1001 MAX_PAGING_IMAGE_SIZE);
1005 if (paging_mem_size & (FW_PAGING_SIZE - 1)) {
1007 "Paging: image isn't multiple %lu\n",
1012 drv->fw.img[IWL_UCODE_REGULAR].paging_mem_size =
1014 usniffer_img = IWL_UCODE_REGULAR_USNIFFER;
1015 drv->fw.img[usniffer_img].paging_mem_size =
1018 case IWL_UCODE_TLV_FW_GSCAN_CAPA:
1021 case IWL_UCODE_TLV_FW_MEM_SEG: {
1022 struct iwl_fw_dbg_mem_seg_tlv *dbg_mem =
1025 struct iwl_fw_dbg_mem_seg_tlv *n;
1027 if (tlv_len != (sizeof(*dbg_mem)))
1028 goto invalid_tlv_len;
1030 IWL_DEBUG_INFO(drv, "Found debug memory segment: %u\n",
1031 dbg_mem->data_type);
1033 size = sizeof(*pieces->dbg_mem_tlv) *
1034 (pieces->n_mem_tlv + 1);
1035 n = krealloc(pieces->dbg_mem_tlv, size, GFP_KERNEL);
1038 pieces->dbg_mem_tlv = n;
1039 pieces->dbg_mem_tlv[pieces->n_mem_tlv] = *dbg_mem;
1040 pieces->n_mem_tlv++;
1043 case IWL_UCODE_TLV_IML: {
1044 drv->fw.iml_len = tlv_len;
1045 drv->fw.iml = kmemdup(tlv_data, tlv_len, GFP_KERNEL);
1050 case IWL_UCODE_TLV_FW_RECOVERY_INFO: {
1054 } *recov_info = (void *)tlv_data;
1056 if (tlv_len != sizeof(*recov_info))
1057 goto invalid_tlv_len;
1058 capa->error_log_addr =
1059 le32_to_cpu(recov_info->buf_addr);
1060 capa->error_log_size =
1061 le32_to_cpu(recov_info->buf_size);
1064 case IWL_UCODE_TLV_FW_FSEQ_VERSION: {
1068 } *fseq_ver = (void *)tlv_data;
1070 if (tlv_len != sizeof(*fseq_ver))
1071 goto invalid_tlv_len;
1072 IWL_INFO(drv, "TLV_FW_FSEQ_VERSION: %s\n",
1076 case IWL_UCODE_TLV_FW_NUM_STATIONS:
1077 if (tlv_len != sizeof(u32))
1078 goto invalid_tlv_len;
1079 if (le32_to_cpup((__le32 *)tlv_data) >
1080 IWL_MVM_STATION_COUNT_MAX) {
1082 "%d is an invalid number of station\n",
1083 le32_to_cpup((__le32 *)tlv_data));
1086 capa->num_stations =
1087 le32_to_cpup((__le32 *)tlv_data);
1089 case IWL_UCODE_TLV_UMAC_DEBUG_ADDRS: {
1090 struct iwl_umac_debug_addrs *dbg_ptrs =
1093 if (tlv_len != sizeof(*dbg_ptrs))
1094 goto invalid_tlv_len;
1095 if (drv->trans->trans_cfg->device_family <
1096 IWL_DEVICE_FAMILY_22000)
1098 drv->trans->dbg.umac_error_event_table =
1099 le32_to_cpu(dbg_ptrs->error_info_addr) &
1100 ~FW_ADDR_CACHE_CONTROL;
1101 drv->trans->dbg.error_event_table_tlv_status |=
1102 IWL_ERROR_EVENT_TABLE_UMAC;
1105 case IWL_UCODE_TLV_LMAC_DEBUG_ADDRS: {
1106 struct iwl_lmac_debug_addrs *dbg_ptrs =
1109 if (tlv_len != sizeof(*dbg_ptrs))
1110 goto invalid_tlv_len;
1111 if (drv->trans->trans_cfg->device_family <
1112 IWL_DEVICE_FAMILY_22000)
1114 drv->trans->dbg.lmac_error_event_table[0] =
1115 le32_to_cpu(dbg_ptrs->error_event_table_ptr) &
1116 ~FW_ADDR_CACHE_CONTROL;
1117 drv->trans->dbg.error_event_table_tlv_status |=
1118 IWL_ERROR_EVENT_TABLE_LMAC1;
1121 case IWL_UCODE_TLV_TYPE_DEBUG_INFO:
1122 case IWL_UCODE_TLV_TYPE_BUFFER_ALLOCATION:
1123 case IWL_UCODE_TLV_TYPE_HCMD:
1124 case IWL_UCODE_TLV_TYPE_REGIONS:
1125 case IWL_UCODE_TLV_TYPE_TRIGGERS:
1126 if (iwlwifi_mod_params.enable_ini)
1127 iwl_dbg_tlv_alloc(drv->trans, tlv, false);
1129 case IWL_UCODE_TLV_CMD_VERSIONS:
1130 if (tlv_len % sizeof(struct iwl_fw_cmd_version)) {
1132 "Invalid length for command versions: %u\n",
1134 tlv_len /= sizeof(struct iwl_fw_cmd_version);
1135 tlv_len *= sizeof(struct iwl_fw_cmd_version);
1137 if (WARN_ON(capa->cmd_versions))
1139 capa->cmd_versions = kmemdup(tlv_data, tlv_len,
1141 if (!capa->cmd_versions)
1143 capa->n_cmd_versions =
1144 tlv_len / sizeof(struct iwl_fw_cmd_version);
1147 IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
1152 if (!fw_has_capa(capa, IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED) &&
1153 usniffer_req && !*usniffer_images) {
1155 "user selected to work with usniffer but usniffer image isn't available in ucode package\n");
1160 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
1161 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
1168 IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1170 iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
1175 static int iwl_alloc_ucode(struct iwl_drv *drv,
1176 struct iwl_firmware_pieces *pieces,
1177 enum iwl_ucode_type type)
1180 struct fw_desc *sec;
1182 sec = kcalloc(pieces->img[type].sec_counter, sizeof(*sec), GFP_KERNEL);
1185 drv->fw.img[type].sec = sec;
1186 drv->fw.img[type].num_sec = pieces->img[type].sec_counter;
1188 for (i = 0; i < pieces->img[type].sec_counter; i++)
1189 if (iwl_alloc_fw_desc(drv, &sec[i], get_sec(pieces, type, i)))
1195 static int validate_sec_sizes(struct iwl_drv *drv,
1196 struct iwl_firmware_pieces *pieces,
1197 const struct iwl_cfg *cfg)
1199 IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %zd\n",
1200 get_sec_size(pieces, IWL_UCODE_REGULAR,
1201 IWL_UCODE_SECTION_INST));
1202 IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %zd\n",
1203 get_sec_size(pieces, IWL_UCODE_REGULAR,
1204 IWL_UCODE_SECTION_DATA));
1205 IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %zd\n",
1206 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
1207 IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %zd\n",
1208 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
1210 /* Verify that uCode images will fit in card's SRAM. */
1211 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
1212 cfg->max_inst_size) {
1213 IWL_ERR(drv, "uCode instr len %zd too large to fit in\n",
1214 get_sec_size(pieces, IWL_UCODE_REGULAR,
1215 IWL_UCODE_SECTION_INST));
1219 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
1220 cfg->max_data_size) {
1221 IWL_ERR(drv, "uCode data len %zd too large to fit in\n",
1222 get_sec_size(pieces, IWL_UCODE_REGULAR,
1223 IWL_UCODE_SECTION_DATA));
1227 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
1228 cfg->max_inst_size) {
1229 IWL_ERR(drv, "uCode init instr len %zd too large to fit in\n",
1230 get_sec_size(pieces, IWL_UCODE_INIT,
1231 IWL_UCODE_SECTION_INST));
1235 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
1236 cfg->max_data_size) {
1237 IWL_ERR(drv, "uCode init data len %zd too large to fit in\n",
1238 get_sec_size(pieces, IWL_UCODE_REGULAR,
1239 IWL_UCODE_SECTION_DATA));
1245 static struct iwl_op_mode *
1246 _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
1248 const struct iwl_op_mode_ops *ops = op->ops;
1249 struct dentry *dbgfs_dir = NULL;
1250 struct iwl_op_mode *op_mode = NULL;
1252 #ifdef CONFIG_IWLWIFI_DEBUGFS
1253 drv->dbgfs_op_mode = debugfs_create_dir(op->name,
1255 dbgfs_dir = drv->dbgfs_op_mode;
1258 op_mode = ops->start(drv->trans, drv->trans->cfg, &drv->fw, dbgfs_dir);
1260 #ifdef CONFIG_IWLWIFI_DEBUGFS
1262 debugfs_remove_recursive(drv->dbgfs_op_mode);
1263 drv->dbgfs_op_mode = NULL;
1270 static void _iwl_op_mode_stop(struct iwl_drv *drv)
1272 /* op_mode can be NULL if its start failed */
1274 iwl_op_mode_stop(drv->op_mode);
1275 drv->op_mode = NULL;
1277 #ifdef CONFIG_IWLWIFI_DEBUGFS
1278 debugfs_remove_recursive(drv->dbgfs_op_mode);
1279 drv->dbgfs_op_mode = NULL;
1285 * iwl_req_fw_callback - callback when firmware was loaded
1287 * If loaded successfully, copies the firmware into buffers
1288 * for the card to fetch (via DMA).
1290 static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
1292 struct iwl_drv *drv = context;
1293 struct iwl_fw *fw = &drv->fw;
1294 struct iwl_ucode_header *ucode;
1295 struct iwlwifi_opmode_table *op;
1297 struct iwl_firmware_pieces *pieces;
1298 const unsigned int api_max = drv->trans->cfg->ucode_api_max;
1299 const unsigned int api_min = drv->trans->cfg->ucode_api_min;
1300 size_t trigger_tlv_sz[FW_DBG_TRIGGER_MAX];
1303 bool load_module = false;
1304 bool usniffer_images = false;
1306 fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
1307 fw->ucode_capa.standard_phy_calibration_size =
1308 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1309 fw->ucode_capa.n_scan_channels = IWL_DEFAULT_SCAN_CHANNELS;
1310 fw->ucode_capa.num_stations = IWL_MVM_STATION_COUNT_MAX;
1311 /* dump all fw memory areas by default */
1312 fw->dbg.dump_mask = 0xffffffff;
1314 pieces = kzalloc(sizeof(*pieces), GFP_KERNEL);
1321 IWL_DEBUG_FW_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
1322 drv->firmware_name, ucode_raw->size);
1324 /* Make sure that we got at least the API version number */
1325 if (ucode_raw->size < 4) {
1326 IWL_ERR(drv, "File size way too small!\n");
1330 /* Data from ucode file: header followed by uCode images */
1331 ucode = (struct iwl_ucode_header *)ucode_raw->data;
1334 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, pieces);
1336 err = iwl_parse_tlv_firmware(drv, ucode_raw, pieces,
1337 &fw->ucode_capa, &usniffer_images);
1342 if (fw_has_api(&drv->fw.ucode_capa, IWL_UCODE_TLV_API_NEW_VERSION))
1343 api_ver = drv->fw.ucode_ver;
1345 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
1348 * api_ver should match the api version forming part of the
1349 * firmware filename ... but we don't check for that and only rely
1350 * on the API version read from firmware header from here on forward
1352 if (api_ver < api_min || api_ver > api_max) {
1354 "Driver unable to support your firmware API. "
1355 "Driver supports v%u, firmware is v%u.\n",
1361 * In mvm uCode there is no difference between data and instructions
1364 if (fw->type == IWL_FW_DVM && validate_sec_sizes(drv, pieces,
1368 /* Allocate ucode buffers for card's bus-master loading ... */
1370 /* Runtime instructions and 2 copies of data:
1371 * 1) unmodified from disk
1372 * 2) backup cache for save/restore during power-downs
1374 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
1375 if (iwl_alloc_ucode(drv, pieces, i))
1378 if (pieces->dbg_dest_tlv_init) {
1379 size_t dbg_dest_size = sizeof(*drv->fw.dbg.dest_tlv) +
1380 sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1381 drv->fw.dbg.n_dest_reg;
1383 drv->fw.dbg.dest_tlv = kmalloc(dbg_dest_size, GFP_KERNEL);
1385 if (!drv->fw.dbg.dest_tlv)
1388 if (*pieces->dbg_dest_ver == 0) {
1389 memcpy(drv->fw.dbg.dest_tlv, pieces->dbg_dest_tlv_v1,
1392 struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv =
1393 drv->fw.dbg.dest_tlv;
1395 dest_tlv->version = pieces->dbg_dest_tlv->version;
1396 dest_tlv->monitor_mode =
1397 pieces->dbg_dest_tlv->monitor_mode;
1398 dest_tlv->size_power =
1399 pieces->dbg_dest_tlv->size_power;
1400 dest_tlv->wrap_count =
1401 pieces->dbg_dest_tlv->wrap_count;
1402 dest_tlv->write_ptr_reg =
1403 pieces->dbg_dest_tlv->write_ptr_reg;
1404 dest_tlv->base_shift =
1405 pieces->dbg_dest_tlv->base_shift;
1406 memcpy(dest_tlv->reg_ops,
1407 pieces->dbg_dest_tlv->reg_ops,
1408 sizeof(drv->fw.dbg.dest_tlv->reg_ops[0]) *
1409 drv->fw.dbg.n_dest_reg);
1411 /* In version 1 of the destination tlv, which is
1412 * relevant for internal buffer exclusively,
1413 * the base address is part of given with the length
1414 * of the buffer, and the size shift is give instead of
1415 * end shift. We now store these values in base_reg,
1416 * and end shift, and when dumping the data we'll
1417 * manipulate it for extracting both the length and
1419 dest_tlv->base_reg = pieces->dbg_dest_tlv->cfg_reg;
1420 dest_tlv->end_shift =
1421 pieces->dbg_dest_tlv->size_shift;
1425 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.conf_tlv); i++) {
1426 if (pieces->dbg_conf_tlv[i]) {
1427 drv->fw.dbg.conf_tlv[i] =
1428 kmemdup(pieces->dbg_conf_tlv[i],
1429 pieces->dbg_conf_tlv_len[i],
1431 if (!drv->fw.dbg.conf_tlv[i])
1436 memset(&trigger_tlv_sz, 0xff, sizeof(trigger_tlv_sz));
1438 trigger_tlv_sz[FW_DBG_TRIGGER_MISSED_BEACONS] =
1439 sizeof(struct iwl_fw_dbg_trigger_missed_bcon);
1440 trigger_tlv_sz[FW_DBG_TRIGGER_CHANNEL_SWITCH] = 0;
1441 trigger_tlv_sz[FW_DBG_TRIGGER_FW_NOTIF] =
1442 sizeof(struct iwl_fw_dbg_trigger_cmd);
1443 trigger_tlv_sz[FW_DBG_TRIGGER_MLME] =
1444 sizeof(struct iwl_fw_dbg_trigger_mlme);
1445 trigger_tlv_sz[FW_DBG_TRIGGER_STATS] =
1446 sizeof(struct iwl_fw_dbg_trigger_stats);
1447 trigger_tlv_sz[FW_DBG_TRIGGER_RSSI] =
1448 sizeof(struct iwl_fw_dbg_trigger_low_rssi);
1449 trigger_tlv_sz[FW_DBG_TRIGGER_TXQ_TIMERS] =
1450 sizeof(struct iwl_fw_dbg_trigger_txq_timer);
1451 trigger_tlv_sz[FW_DBG_TRIGGER_TIME_EVENT] =
1452 sizeof(struct iwl_fw_dbg_trigger_time_event);
1453 trigger_tlv_sz[FW_DBG_TRIGGER_BA] =
1454 sizeof(struct iwl_fw_dbg_trigger_ba);
1455 trigger_tlv_sz[FW_DBG_TRIGGER_TDLS] =
1456 sizeof(struct iwl_fw_dbg_trigger_tdls);
1458 for (i = 0; i < ARRAY_SIZE(drv->fw.dbg.trigger_tlv); i++) {
1459 if (pieces->dbg_trigger_tlv[i]) {
1461 * If the trigger isn't long enough, WARN and exit.
1462 * Someone is trying to debug something and he won't
1463 * be able to catch the bug he is trying to chase.
1464 * We'd better be noisy to be sure he knows what's
1467 if (WARN_ON(pieces->dbg_trigger_tlv_len[i] <
1468 (trigger_tlv_sz[i] +
1469 sizeof(struct iwl_fw_dbg_trigger_tlv))))
1471 drv->fw.dbg.trigger_tlv_len[i] =
1472 pieces->dbg_trigger_tlv_len[i];
1473 drv->fw.dbg.trigger_tlv[i] =
1474 kmemdup(pieces->dbg_trigger_tlv[i],
1475 drv->fw.dbg.trigger_tlv_len[i],
1477 if (!drv->fw.dbg.trigger_tlv[i])
1482 /* Now that we can no longer fail, copy information */
1484 drv->fw.dbg.mem_tlv = pieces->dbg_mem_tlv;
1485 pieces->dbg_mem_tlv = NULL;
1486 drv->fw.dbg.n_mem_tlv = pieces->n_mem_tlv;
1489 * The (size - 16) / 12 formula is based on the information recorded
1490 * for each event, which is of mode 1 (including timestamp) for all
1491 * new microcodes that include this information.
1493 fw->init_evtlog_ptr = pieces->init_evtlog_ptr;
1494 if (pieces->init_evtlog_size)
1495 fw->init_evtlog_size = (pieces->init_evtlog_size - 16)/12;
1497 fw->init_evtlog_size =
1498 drv->trans->trans_cfg->base_params->max_event_log_size;
1499 fw->init_errlog_ptr = pieces->init_errlog_ptr;
1500 fw->inst_evtlog_ptr = pieces->inst_evtlog_ptr;
1501 if (pieces->inst_evtlog_size)
1502 fw->inst_evtlog_size = (pieces->inst_evtlog_size - 16)/12;
1504 fw->inst_evtlog_size =
1505 drv->trans->trans_cfg->base_params->max_event_log_size;
1506 fw->inst_errlog_ptr = pieces->inst_errlog_ptr;
1509 * figure out the offset of chain noise reset and gain commands
1510 * base on the size of standard phy calibration commands table size
1512 if (fw->ucode_capa.standard_phy_calibration_size >
1513 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1514 fw->ucode_capa.standard_phy_calibration_size =
1515 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1517 /* We have our copies now, allow OS release its copies */
1518 release_firmware(ucode_raw);
1520 mutex_lock(&iwlwifi_opmode_table_mtx);
1523 op = &iwlwifi_opmode_table[DVM_OP_MODE];
1526 WARN(1, "Invalid fw type %d\n", fw->type);
1529 op = &iwlwifi_opmode_table[MVM_OP_MODE];
1533 IWL_INFO(drv, "loaded firmware version %s op_mode %s\n",
1534 drv->fw.fw_version, op->name);
1536 iwl_dbg_tlv_load_bin(drv->trans->dev, drv->trans);
1538 /* add this device to the list of devices using this op_mode */
1539 list_add_tail(&drv->list, &op->drv);
1542 drv->op_mode = _iwl_op_mode_start(drv, op);
1544 if (!drv->op_mode) {
1545 mutex_unlock(&iwlwifi_opmode_table_mtx);
1551 mutex_unlock(&iwlwifi_opmode_table_mtx);
1554 * Complete the firmware request last so that
1555 * a driver unbind (stop) doesn't run while we
1556 * are doing the start() above.
1558 complete(&drv->request_firmware_complete);
1561 * Load the module last so we don't block anything
1562 * else from proceeding if the module fails to load
1566 request_module("%s", op->name);
1567 #ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
1570 "failed to load module %s (error %d), is dynamic loading enabled?\n",
1577 /* try next, if any */
1578 release_firmware(ucode_raw);
1579 if (iwl_request_firmware(drv, false))
1584 release_firmware(ucode_raw);
1586 complete(&drv->request_firmware_complete);
1587 device_release_driver(drv->trans->dev);
1590 for (i = 0; i < ARRAY_SIZE(pieces->img); i++)
1591 kfree(pieces->img[i].sec);
1592 kfree(pieces->dbg_mem_tlv);
1597 struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
1599 struct iwl_drv *drv;
1602 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
1609 drv->dev = trans->dev;
1611 init_completion(&drv->request_firmware_complete);
1612 INIT_LIST_HEAD(&drv->list);
1614 #ifdef CONFIG_IWLWIFI_DEBUGFS
1615 /* Create the device debugfs entries. */
1616 drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1619 /* Create transport layer debugfs dir */
1620 drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1623 drv->trans->dbg.domains_bitmap = IWL_TRANS_FW_DBG_DOMAIN(drv->trans);
1625 ret = iwl_request_firmware(drv, true);
1627 IWL_ERR(trans, "Couldn't request the fw\n");
1634 #ifdef CONFIG_IWLWIFI_DEBUGFS
1635 debugfs_remove_recursive(drv->dbgfs_drv);
1636 iwl_dbg_tlv_free(drv->trans);
1640 return ERR_PTR(ret);
1643 void iwl_drv_stop(struct iwl_drv *drv)
1645 wait_for_completion(&drv->request_firmware_complete);
1647 _iwl_op_mode_stop(drv);
1649 iwl_dealloc_ucode(drv);
1651 mutex_lock(&iwlwifi_opmode_table_mtx);
1653 * List is empty (this item wasn't added)
1654 * when firmware loading failed -- in that
1655 * case we can't remove it from any list.
1657 if (!list_empty(&drv->list))
1658 list_del(&drv->list);
1659 mutex_unlock(&iwlwifi_opmode_table_mtx);
1661 #ifdef CONFIG_IWLWIFI_DEBUGFS
1662 drv->trans->ops->debugfs_cleanup(drv->trans);
1664 debugfs_remove_recursive(drv->dbgfs_drv);
1667 iwl_dbg_tlv_free(drv->trans);
1673 /* shared module parameters */
1674 struct iwl_mod_params iwlwifi_mod_params = {
1676 .bt_coex_active = true,
1677 .power_level = IWL_POWER_INDEX_1,
1678 .uapsd_disable = IWL_DISABLE_UAPSD_BSS | IWL_DISABLE_UAPSD_P2P_CLIENT,
1680 /* the rest are 0 by default */
1682 IWL_EXPORT_SYMBOL(iwlwifi_mod_params);
1684 int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1687 struct iwl_drv *drv;
1688 struct iwlwifi_opmode_table *op;
1690 mutex_lock(&iwlwifi_opmode_table_mtx);
1691 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1692 op = &iwlwifi_opmode_table[i];
1693 if (strcmp(op->name, name))
1696 /* TODO: need to handle exceptional case */
1697 list_for_each_entry(drv, &op->drv, list)
1698 drv->op_mode = _iwl_op_mode_start(drv, op);
1700 mutex_unlock(&iwlwifi_opmode_table_mtx);
1703 mutex_unlock(&iwlwifi_opmode_table_mtx);
1706 IWL_EXPORT_SYMBOL(iwl_opmode_register);
1708 void iwl_opmode_deregister(const char *name)
1711 struct iwl_drv *drv;
1713 mutex_lock(&iwlwifi_opmode_table_mtx);
1714 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1715 if (strcmp(iwlwifi_opmode_table[i].name, name))
1717 iwlwifi_opmode_table[i].ops = NULL;
1719 /* call the stop routine for all devices */
1720 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1721 _iwl_op_mode_stop(drv);
1723 mutex_unlock(&iwlwifi_opmode_table_mtx);
1726 mutex_unlock(&iwlwifi_opmode_table_mtx);
1728 IWL_EXPORT_SYMBOL(iwl_opmode_deregister);
1730 static int __init iwl_drv_init(void)
1734 mutex_init(&iwlwifi_opmode_table_mtx);
1736 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1737 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1739 pr_info(DRV_DESCRIPTION "\n");
1741 #ifdef CONFIG_IWLWIFI_DEBUGFS
1742 /* Create the root of iwlwifi debugfs subsystem. */
1743 iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1746 err = iwl_pci_register_driver();
1748 goto cleanup_debugfs;
1753 #ifdef CONFIG_IWLWIFI_DEBUGFS
1754 debugfs_remove_recursive(iwl_dbgfs_root);
1758 module_init(iwl_drv_init);
1760 static void __exit iwl_drv_exit(void)
1762 iwl_pci_unregister_driver();
1764 #ifdef CONFIG_IWLWIFI_DEBUGFS
1765 debugfs_remove_recursive(iwl_dbgfs_root);
1768 module_exit(iwl_drv_exit);
1770 #ifdef CONFIG_IWLWIFI_DEBUG
1771 module_param_named(debug, iwlwifi_mod_params.debug_level, uint, 0644);
1772 MODULE_PARM_DESC(debug, "debug output mask");
1775 module_param_named(swcrypto, iwlwifi_mod_params.swcrypto, int, 0444);
1776 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1777 module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, 0444);
1778 MODULE_PARM_DESC(11n_disable,
1779 "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
1780 module_param_named(amsdu_size, iwlwifi_mod_params.amsdu_size, int, 0444);
1781 MODULE_PARM_DESC(amsdu_size,
1782 "amsdu size 0: 12K for multi Rx queue devices, 2K for AX210 devices, "
1783 "4K for other devices 1:4K 2:8K 3:12K (16K buffers) 4: 2K (default 0)");
1784 module_param_named(fw_restart, iwlwifi_mod_params.fw_restart, bool, 0444);
1785 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error (default true)");
1787 module_param_named(nvm_file, iwlwifi_mod_params.nvm_file, charp, 0444);
1788 MODULE_PARM_DESC(nvm_file, "NVM file name");
1790 module_param_named(uapsd_disable, iwlwifi_mod_params.uapsd_disable, uint, 0644);
1791 MODULE_PARM_DESC(uapsd_disable,
1792 "disable U-APSD functionality bitmap 1: BSS 2: P2P Client (default: 3)");
1793 module_param_named(enable_ini, iwlwifi_mod_params.enable_ini,
1794 bool, S_IRUGO | S_IWUSR);
1795 MODULE_PARM_DESC(enable_ini,
1796 "Enable debug INI TLV FW debug infrastructure (default: true");
1799 * set bt_coex_active to true, uCode will do kill/defer
1800 * every time the priority line is asserted (BT is sending signals on the
1801 * priority line in the PCIx).
1802 * set bt_coex_active to false, uCode will ignore the BT activity and
1803 * perform the normal operation
1805 * User might experience transmit issue on some platform due to WiFi/BT
1806 * co-exist problem. The possible behaviors are:
1807 * Able to scan and finding all the available AP
1808 * Not able to associate with any AP
1809 * On those platforms, WiFi communication can be restored by set
1810 * "bt_coex_active" module parameter to "false"
1812 * default: bt_coex_active = true (BT_COEX_ENABLE)
1814 module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1816 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1818 module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, 0444);
1819 MODULE_PARM_DESC(led_mode, "0=system default, "
1820 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1822 module_param_named(power_save, iwlwifi_mod_params.power_save, bool, 0444);
1823 MODULE_PARM_DESC(power_save,
1824 "enable WiFi power management (default: disable)");
1826 module_param_named(power_level, iwlwifi_mod_params.power_level, int, 0444);
1827 MODULE_PARM_DESC(power_level,
1828 "default power save level (range from 1 - 5, default: 1)");
1830 module_param_named(disable_11ac, iwlwifi_mod_params.disable_11ac, bool, 0444);
1831 MODULE_PARM_DESC(disable_11ac, "Disable VHT capabilities (default: false)");
1833 module_param_named(remove_when_gone,
1834 iwlwifi_mod_params.remove_when_gone, bool,
1836 MODULE_PARM_DESC(remove_when_gone,
1837 "Remove dev from PCIe bus if it is deemed inaccessible (default: false)");
1839 module_param_named(disable_11ax, iwlwifi_mod_params.disable_11ax, bool,
1841 MODULE_PARM_DESC(disable_11ax, "Disable HE capabilities (default: false)");