1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2007 - 2012 Intel Corporation. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
63 #include <linux/completion.h>
64 #include <linux/dma-mapping.h>
65 #include <linux/firmware.h>
66 #include <linux/module.h>
69 #include "iwl-debug.h"
70 #include "iwl-trans.h"
71 #include "iwl-op-mode.h"
72 #include "iwl-agn-hw.h"
74 #include "iwl-config.h"
75 #include "iwl-modparams.h"
77 /* private includes */
78 #include "iwl-fw-file.h"
80 /******************************************************************************
84 ******************************************************************************/
87 * module name, copyright, version, etc.
89 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
91 #ifdef CONFIG_IWLWIFI_DEBUG
97 #define DRV_VERSION IWLWIFI_VERSION VD
99 MODULE_DESCRIPTION(DRV_DESCRIPTION);
100 MODULE_VERSION(DRV_VERSION);
101 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
102 MODULE_LICENSE("GPL");
104 #ifdef CONFIG_IWLWIFI_DEBUGFS
105 static struct dentry *iwl_dbgfs_root;
109 * struct iwl_drv - drv common data
110 * @list: list of drv structures using this opmode
111 * @fw: the iwl_fw structure
112 * @op_mode: the running op_mode
113 * @trans: transport layer
114 * @dev: for debug prints only
115 * @cfg: configuration struct
116 * @fw_index: firmware revision to try loading
117 * @firmware_name: composite filename of ucode file to load
118 * @request_firmware_complete: the firmware has been obtained from user space
121 struct list_head list;
124 struct iwl_op_mode *op_mode;
125 struct iwl_trans *trans;
127 const struct iwl_cfg *cfg;
129 int fw_index; /* firmware we're trying to load */
130 char firmware_name[25]; /* name of firmware file to load */
132 struct completion request_firmware_complete;
134 #ifdef CONFIG_IWLWIFI_DEBUGFS
135 struct dentry *dbgfs_drv;
136 struct dentry *dbgfs_trans;
137 struct dentry *dbgfs_op_mode;
141 #define DVM_OP_MODE 0
142 #define MVM_OP_MODE 1
144 /* Protects the table contents, i.e. the ops pointer & drv list */
145 static struct mutex iwlwifi_opmode_table_mtx;
146 static struct iwlwifi_opmode_table {
147 const char *name; /* name: iwldvm, iwlmvm, etc */
148 const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
149 struct list_head drv; /* list of devices using this op_mode */
150 } iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
151 { .name = "iwldvm", .ops = NULL },
152 { .name = "iwlmvm", .ops = NULL },
156 * struct fw_sec: Just for the image parsing proccess.
157 * For the fw storage we are using struct fw_desc.
160 const void *data; /* the sec data */
161 size_t size; /* section size */
162 u32 offset; /* offset of writing in the device */
165 static void iwl_free_fw_desc(struct iwl_drv *drv, struct fw_desc *desc)
168 dma_free_coherent(drv->trans->dev, desc->len,
169 desc->v_addr, desc->p_addr);
174 static void iwl_free_fw_img(struct iwl_drv *drv, struct fw_img *img)
177 for (i = 0; i < IWL_UCODE_SECTION_MAX; i++)
178 iwl_free_fw_desc(drv, &img->sec[i]);
181 static void iwl_dealloc_ucode(struct iwl_drv *drv)
184 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
185 iwl_free_fw_img(drv, drv->fw.img + i);
188 static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
191 if (!sec || !sec->size) {
196 desc->v_addr = dma_alloc_coherent(drv->trans->dev, sec->size,
197 &desc->p_addr, GFP_KERNEL);
201 desc->len = sec->size;
202 desc->offset = sec->offset;
203 memcpy(desc->v_addr, sec->data, sec->size);
207 static void iwl_req_fw_callback(const struct firmware *ucode_raw,
210 #define UCODE_EXPERIMENTAL_INDEX 100
211 #define UCODE_EXPERIMENTAL_TAG "exp"
213 static int iwl_request_firmware(struct iwl_drv *drv, bool first)
215 const char *name_pre = drv->cfg->fw_name_pre;
219 #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
220 drv->fw_index = UCODE_EXPERIMENTAL_INDEX;
221 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
222 } else if (drv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
224 drv->fw_index = drv->cfg->ucode_api_max;
225 sprintf(tag, "%d", drv->fw_index);
228 sprintf(tag, "%d", drv->fw_index);
231 if (drv->fw_index < drv->cfg->ucode_api_min) {
232 IWL_ERR(drv, "no suitable firmware found!\n");
236 sprintf(drv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
238 IWL_DEBUG_INFO(drv, "attempting to load firmware %s'%s'\n",
239 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
240 ? "EXPERIMENTAL " : "",
243 return request_firmware_nowait(THIS_MODULE, 1, drv->firmware_name,
245 GFP_KERNEL, drv, iwl_req_fw_callback);
248 struct fw_img_parsing {
249 struct fw_sec sec[IWL_UCODE_SECTION_MAX];
254 * struct fw_sec_parsing: to extract fw section and it's offset from tlv
256 struct fw_sec_parsing {
262 * struct iwl_tlv_calib_data - parse the default calib data from TLV
264 * @ucode_type: the uCode to which the following default calib relates.
265 * @calib: default calibrations.
267 struct iwl_tlv_calib_data {
272 struct iwl_firmware_pieces {
273 struct fw_img_parsing img[IWL_UCODE_TYPE_MAX];
275 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
276 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
280 * These functions are just to extract uCode section data from the pieces
283 static struct fw_sec *get_sec(struct iwl_firmware_pieces *pieces,
284 enum iwl_ucode_type type,
287 return &pieces->img[type].sec[sec];
290 static void set_sec_data(struct iwl_firmware_pieces *pieces,
291 enum iwl_ucode_type type,
295 pieces->img[type].sec[sec].data = data;
298 static void set_sec_size(struct iwl_firmware_pieces *pieces,
299 enum iwl_ucode_type type,
303 pieces->img[type].sec[sec].size = size;
306 static size_t get_sec_size(struct iwl_firmware_pieces *pieces,
307 enum iwl_ucode_type type,
310 return pieces->img[type].sec[sec].size;
313 static void set_sec_offset(struct iwl_firmware_pieces *pieces,
314 enum iwl_ucode_type type,
318 pieces->img[type].sec[sec].offset = offset;
322 * Gets uCode section from tlv.
324 static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
325 const void *data, enum iwl_ucode_type type,
328 struct fw_img_parsing *img;
330 struct fw_sec_parsing *sec_parse;
332 if (WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
335 sec_parse = (struct fw_sec_parsing *)data;
337 img = &pieces->img[type];
338 sec = &img->sec[img->sec_counter];
340 sec->offset = le32_to_cpu(sec_parse->offset);
341 sec->data = sec_parse->data;
342 sec->size = size - sizeof(sec_parse->offset);
349 static int iwl_set_default_calib(struct iwl_drv *drv, const u8 *data)
351 struct iwl_tlv_calib_data *def_calib =
352 (struct iwl_tlv_calib_data *)data;
353 u32 ucode_type = le32_to_cpu(def_calib->ucode_type);
354 if (ucode_type >= IWL_UCODE_TYPE_MAX) {
355 IWL_ERR(drv, "Wrong ucode_type %u for default calibration.\n",
359 drv->fw.default_calib[ucode_type] = le64_to_cpu(def_calib->calib);
363 static int iwl_parse_v1_v2_firmware(struct iwl_drv *drv,
364 const struct firmware *ucode_raw,
365 struct iwl_firmware_pieces *pieces)
367 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
368 u32 api_ver, hdr_size, build;
372 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
373 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
378 if (ucode_raw->size < hdr_size) {
379 IWL_ERR(drv, "File size too small!\n");
382 build = le32_to_cpu(ucode->u.v2.build);
383 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
384 le32_to_cpu(ucode->u.v2.inst_size));
385 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
386 le32_to_cpu(ucode->u.v2.data_size));
387 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
388 le32_to_cpu(ucode->u.v2.init_size));
389 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
390 le32_to_cpu(ucode->u.v2.init_data_size));
391 src = ucode->u.v2.data;
397 if (ucode_raw->size < hdr_size) {
398 IWL_ERR(drv, "File size too small!\n");
402 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
403 le32_to_cpu(ucode->u.v1.inst_size));
404 set_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
405 le32_to_cpu(ucode->u.v1.data_size));
406 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
407 le32_to_cpu(ucode->u.v1.init_size));
408 set_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
409 le32_to_cpu(ucode->u.v1.init_data_size));
410 src = ucode->u.v1.data;
415 sprintf(buildstr, " build %u%s", build,
416 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
421 snprintf(drv->fw.fw_version,
422 sizeof(drv->fw.fw_version),
424 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
425 IWL_UCODE_MINOR(drv->fw.ucode_ver),
426 IWL_UCODE_API(drv->fw.ucode_ver),
427 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
430 /* Verify size of file vs. image size info in file's header */
432 if (ucode_raw->size != hdr_size +
433 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) +
434 get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) +
435 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) +
436 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA)) {
439 "uCode file size %d does not match expected size\n",
440 (int)ucode_raw->size);
445 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST, src);
446 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST);
447 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST,
448 IWLAGN_RTC_INST_LOWER_BOUND);
449 set_sec_data(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA, src);
450 src += get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA);
451 set_sec_offset(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA,
452 IWLAGN_RTC_DATA_LOWER_BOUND);
453 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST, src);
454 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST);
455 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST,
456 IWLAGN_RTC_INST_LOWER_BOUND);
457 set_sec_data(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA, src);
458 src += get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA);
459 set_sec_offset(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA,
460 IWLAGN_RTC_DATA_LOWER_BOUND);
464 static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
465 const struct firmware *ucode_raw,
466 struct iwl_firmware_pieces *pieces,
467 struct iwl_ucode_capabilities *capa)
469 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
470 struct iwl_ucode_tlv *tlv;
471 size_t len = ucode_raw->size;
474 enum iwl_ucode_tlv_type tlv_type;
479 if (len < sizeof(*ucode)) {
480 IWL_ERR(drv, "uCode has invalid length: %zd\n", len);
484 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
485 IWL_ERR(drv, "invalid uCode magic: 0X%x\n",
486 le32_to_cpu(ucode->magic));
490 drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
491 build = le32_to_cpu(ucode->build);
494 sprintf(buildstr, " build %u%s", build,
495 (drv->fw_index == UCODE_EXPERIMENTAL_INDEX)
500 snprintf(drv->fw.fw_version,
501 sizeof(drv->fw.fw_version),
503 IWL_UCODE_MAJOR(drv->fw.ucode_ver),
504 IWL_UCODE_MINOR(drv->fw.ucode_ver),
505 IWL_UCODE_API(drv->fw.ucode_ver),
506 IWL_UCODE_SERIAL(drv->fw.ucode_ver),
511 len -= sizeof(*ucode);
513 while (len >= sizeof(*tlv)) {
517 tlv_len = le32_to_cpu(tlv->length);
518 tlv_type = le32_to_cpu(tlv->type);
519 tlv_data = tlv->data;
522 IWL_ERR(drv, "invalid TLV len: %zd/%u\n",
526 len -= ALIGN(tlv_len, 4);
527 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
530 case IWL_UCODE_TLV_INST:
531 set_sec_data(pieces, IWL_UCODE_REGULAR,
532 IWL_UCODE_SECTION_INST, tlv_data);
533 set_sec_size(pieces, IWL_UCODE_REGULAR,
534 IWL_UCODE_SECTION_INST, tlv_len);
535 set_sec_offset(pieces, IWL_UCODE_REGULAR,
536 IWL_UCODE_SECTION_INST,
537 IWLAGN_RTC_INST_LOWER_BOUND);
539 case IWL_UCODE_TLV_DATA:
540 set_sec_data(pieces, IWL_UCODE_REGULAR,
541 IWL_UCODE_SECTION_DATA, tlv_data);
542 set_sec_size(pieces, IWL_UCODE_REGULAR,
543 IWL_UCODE_SECTION_DATA, tlv_len);
544 set_sec_offset(pieces, IWL_UCODE_REGULAR,
545 IWL_UCODE_SECTION_DATA,
546 IWLAGN_RTC_DATA_LOWER_BOUND);
548 case IWL_UCODE_TLV_INIT:
549 set_sec_data(pieces, IWL_UCODE_INIT,
550 IWL_UCODE_SECTION_INST, tlv_data);
551 set_sec_size(pieces, IWL_UCODE_INIT,
552 IWL_UCODE_SECTION_INST, tlv_len);
553 set_sec_offset(pieces, IWL_UCODE_INIT,
554 IWL_UCODE_SECTION_INST,
555 IWLAGN_RTC_INST_LOWER_BOUND);
557 case IWL_UCODE_TLV_INIT_DATA:
558 set_sec_data(pieces, IWL_UCODE_INIT,
559 IWL_UCODE_SECTION_DATA, tlv_data);
560 set_sec_size(pieces, IWL_UCODE_INIT,
561 IWL_UCODE_SECTION_DATA, tlv_len);
562 set_sec_offset(pieces, IWL_UCODE_INIT,
563 IWL_UCODE_SECTION_DATA,
564 IWLAGN_RTC_DATA_LOWER_BOUND);
566 case IWL_UCODE_TLV_BOOT:
567 IWL_ERR(drv, "Found unexpected BOOT ucode\n");
569 case IWL_UCODE_TLV_PROBE_MAX_LEN:
570 if (tlv_len != sizeof(u32))
571 goto invalid_tlv_len;
572 capa->max_probe_length =
573 le32_to_cpup((__le32 *)tlv_data);
575 case IWL_UCODE_TLV_PAN:
577 goto invalid_tlv_len;
578 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
580 case IWL_UCODE_TLV_FLAGS:
581 /* must be at least one u32 */
582 if (tlv_len < sizeof(u32))
583 goto invalid_tlv_len;
584 /* and a proper number of u32s */
585 if (tlv_len % sizeof(u32))
586 goto invalid_tlv_len;
588 * This driver only reads the first u32 as
589 * right now no more features are defined,
590 * if that changes then either the driver
591 * will not work with the new firmware, or
592 * it'll not take advantage of new features.
594 capa->flags = le32_to_cpup((__le32 *)tlv_data);
596 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
597 if (tlv_len != sizeof(u32))
598 goto invalid_tlv_len;
599 pieces->init_evtlog_ptr =
600 le32_to_cpup((__le32 *)tlv_data);
602 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
603 if (tlv_len != sizeof(u32))
604 goto invalid_tlv_len;
605 pieces->init_evtlog_size =
606 le32_to_cpup((__le32 *)tlv_data);
608 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
609 if (tlv_len != sizeof(u32))
610 goto invalid_tlv_len;
611 pieces->init_errlog_ptr =
612 le32_to_cpup((__le32 *)tlv_data);
614 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
615 if (tlv_len != sizeof(u32))
616 goto invalid_tlv_len;
617 pieces->inst_evtlog_ptr =
618 le32_to_cpup((__le32 *)tlv_data);
620 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
621 if (tlv_len != sizeof(u32))
622 goto invalid_tlv_len;
623 pieces->inst_evtlog_size =
624 le32_to_cpup((__le32 *)tlv_data);
626 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
627 if (tlv_len != sizeof(u32))
628 goto invalid_tlv_len;
629 pieces->inst_errlog_ptr =
630 le32_to_cpup((__le32 *)tlv_data);
632 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
634 goto invalid_tlv_len;
635 drv->fw.enhance_sensitivity_table = true;
637 case IWL_UCODE_TLV_WOWLAN_INST:
638 set_sec_data(pieces, IWL_UCODE_WOWLAN,
639 IWL_UCODE_SECTION_INST, tlv_data);
640 set_sec_size(pieces, IWL_UCODE_WOWLAN,
641 IWL_UCODE_SECTION_INST, tlv_len);
642 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
643 IWL_UCODE_SECTION_INST,
644 IWLAGN_RTC_INST_LOWER_BOUND);
646 case IWL_UCODE_TLV_WOWLAN_DATA:
647 set_sec_data(pieces, IWL_UCODE_WOWLAN,
648 IWL_UCODE_SECTION_DATA, tlv_data);
649 set_sec_size(pieces, IWL_UCODE_WOWLAN,
650 IWL_UCODE_SECTION_DATA, tlv_len);
651 set_sec_offset(pieces, IWL_UCODE_WOWLAN,
652 IWL_UCODE_SECTION_DATA,
653 IWLAGN_RTC_DATA_LOWER_BOUND);
655 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
656 if (tlv_len != sizeof(u32))
657 goto invalid_tlv_len;
658 capa->standard_phy_calibration_size =
659 le32_to_cpup((__le32 *)tlv_data);
661 case IWL_UCODE_TLV_SEC_RT:
662 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_REGULAR,
664 drv->fw.mvm_fw = true;
666 case IWL_UCODE_TLV_SEC_INIT:
667 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_INIT,
669 drv->fw.mvm_fw = true;
671 case IWL_UCODE_TLV_SEC_WOWLAN:
672 iwl_store_ucode_sec(pieces, tlv_data, IWL_UCODE_WOWLAN,
674 drv->fw.mvm_fw = true;
676 case IWL_UCODE_TLV_DEF_CALIB:
677 if (tlv_len != sizeof(struct iwl_tlv_calib_data))
678 goto invalid_tlv_len;
679 if (iwl_set_default_calib(drv, tlv_data))
682 case IWL_UCODE_TLV_PHY_SKU:
683 if (tlv_len != sizeof(u32))
684 goto invalid_tlv_len;
685 drv->fw.phy_config = le32_to_cpup((__le32 *)tlv_data);
688 IWL_DEBUG_INFO(drv, "unknown TLV: %d\n", tlv_type);
694 IWL_ERR(drv, "invalid TLV after parsing: %zd\n", len);
695 iwl_print_hex_dump(drv, IWL_DL_FW, (u8 *)data, len);
702 IWL_ERR(drv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
704 iwl_print_hex_dump(drv, IWL_DL_FW, tlv_data, tlv_len);
709 static int iwl_alloc_ucode(struct iwl_drv *drv,
710 struct iwl_firmware_pieces *pieces,
711 enum iwl_ucode_type type)
715 i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
717 if (iwl_alloc_fw_desc(drv, &(drv->fw.img[type].sec[i]),
718 get_sec(pieces, type, i)))
723 static int validate_sec_sizes(struct iwl_drv *drv,
724 struct iwl_firmware_pieces *pieces,
725 const struct iwl_cfg *cfg)
727 IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
728 get_sec_size(pieces, IWL_UCODE_REGULAR,
729 IWL_UCODE_SECTION_INST));
730 IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
731 get_sec_size(pieces, IWL_UCODE_REGULAR,
732 IWL_UCODE_SECTION_DATA));
733 IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
734 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
735 IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
736 get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
738 /* Verify that uCode images will fit in card's SRAM. */
739 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
740 cfg->max_inst_size) {
741 IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
742 get_sec_size(pieces, IWL_UCODE_REGULAR,
743 IWL_UCODE_SECTION_INST));
747 if (get_sec_size(pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
748 cfg->max_data_size) {
749 IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
750 get_sec_size(pieces, IWL_UCODE_REGULAR,
751 IWL_UCODE_SECTION_DATA));
755 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST) >
756 cfg->max_inst_size) {
757 IWL_ERR(drv, "uCode init instr len %Zd too large to fit in\n",
758 get_sec_size(pieces, IWL_UCODE_INIT,
759 IWL_UCODE_SECTION_INST));
763 if (get_sec_size(pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA) >
764 cfg->max_data_size) {
765 IWL_ERR(drv, "uCode init data len %Zd too large to fit in\n",
766 get_sec_size(pieces, IWL_UCODE_REGULAR,
767 IWL_UCODE_SECTION_DATA));
773 static struct iwl_op_mode *
774 _iwl_op_mode_start(struct iwl_drv *drv, struct iwlwifi_opmode_table *op)
776 const struct iwl_op_mode_ops *ops = op->ops;
777 struct dentry *dbgfs_dir = NULL;
778 struct iwl_op_mode *op_mode = NULL;
780 #ifdef CONFIG_IWLWIFI_DEBUGFS
781 drv->dbgfs_op_mode = debugfs_create_dir(op->name,
783 if (!drv->dbgfs_op_mode) {
785 "failed to create opmode debugfs directory\n");
788 dbgfs_dir = drv->dbgfs_op_mode;
791 op_mode = ops->start(drv->trans, drv->cfg, &drv->fw, dbgfs_dir);
793 #ifdef CONFIG_IWLWIFI_DEBUGFS
795 debugfs_remove_recursive(drv->dbgfs_op_mode);
796 drv->dbgfs_op_mode = NULL;
803 static void _iwl_op_mode_stop(struct iwl_drv *drv)
805 /* op_mode can be NULL if its start failed */
807 iwl_op_mode_stop(drv->op_mode);
810 #ifdef CONFIG_IWLWIFI_DEBUGFS
811 debugfs_remove_recursive(drv->dbgfs_op_mode);
812 drv->dbgfs_op_mode = NULL;
818 * iwl_req_fw_callback - callback when firmware was loaded
820 * If loaded successfully, copies the firmware into buffers
821 * for the card to fetch (via DMA).
823 static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
825 struct iwl_drv *drv = context;
826 struct iwl_fw *fw = &drv->fw;
827 struct iwl_ucode_header *ucode;
828 struct iwlwifi_opmode_table *op;
830 struct iwl_firmware_pieces pieces;
831 const unsigned int api_max = drv->cfg->ucode_api_max;
832 unsigned int api_ok = drv->cfg->ucode_api_ok;
833 const unsigned int api_min = drv->cfg->ucode_api_min;
836 bool load_module = false;
838 fw->ucode_capa.max_probe_length = 200;
839 fw->ucode_capa.standard_phy_calibration_size =
840 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
845 memset(&pieces, 0, sizeof(pieces));
848 if (drv->fw_index <= api_ok)
850 "request for firmware file '%s' failed.\n",
855 IWL_DEBUG_INFO(drv, "Loaded firmware file '%s' (%zd bytes).\n",
856 drv->firmware_name, ucode_raw->size);
858 /* Make sure that we got at least the API version number */
859 if (ucode_raw->size < 4) {
860 IWL_ERR(drv, "File size way too small!\n");
864 /* Data from ucode file: header followed by uCode images */
865 ucode = (struct iwl_ucode_header *)ucode_raw->data;
868 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces);
870 err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces,
876 api_ver = IWL_UCODE_API(drv->fw.ucode_ver);
879 * api_ver should match the api version forming part of the
880 * firmware filename ... but we don't check for that and only rely
881 * on the API version read from firmware header from here on forward
883 /* no api version check required for experimental uCode */
884 if (drv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
885 if (api_ver < api_min || api_ver > api_max) {
887 "Driver unable to support your firmware API. "
888 "Driver supports v%u, firmware is v%u.\n",
893 if (api_ver < api_ok) {
894 if (api_ok != api_max)
895 IWL_ERR(drv, "Firmware has old API version, "
896 "expected v%u through v%u, got v%u.\n",
897 api_ok, api_max, api_ver);
899 IWL_ERR(drv, "Firmware has old API version, "
900 "expected v%u, got v%u.\n",
902 IWL_ERR(drv, "New firmware can be obtained from "
903 "http://www.intellinuxwireless.org/.\n");
907 IWL_INFO(drv, "loaded firmware version %s", drv->fw.fw_version);
910 * In mvm uCode there is no difference between data and instructions
913 if (!fw->mvm_fw && validate_sec_sizes(drv, &pieces, drv->cfg))
916 /* Allocate ucode buffers for card's bus-master loading ... */
918 /* Runtime instructions and 2 copies of data:
919 * 1) unmodified from disk
920 * 2) backup cache for save/restore during power-downs */
921 for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
922 if (iwl_alloc_ucode(drv, &pieces, i))
925 /* Now that we can no longer fail, copy information */
928 * The (size - 16) / 12 formula is based on the information recorded
929 * for each event, which is of mode 1 (including timestamp) for all
930 * new microcodes that include this information.
932 fw->init_evtlog_ptr = pieces.init_evtlog_ptr;
933 if (pieces.init_evtlog_size)
934 fw->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
936 fw->init_evtlog_size =
937 drv->cfg->base_params->max_event_log_size;
938 fw->init_errlog_ptr = pieces.init_errlog_ptr;
939 fw->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
940 if (pieces.inst_evtlog_size)
941 fw->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
943 fw->inst_evtlog_size =
944 drv->cfg->base_params->max_event_log_size;
945 fw->inst_errlog_ptr = pieces.inst_errlog_ptr;
948 * figure out the offset of chain noise reset and gain commands
949 * base on the size of standard phy calibration commands table size
951 if (fw->ucode_capa.standard_phy_calibration_size >
952 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
953 fw->ucode_capa.standard_phy_calibration_size =
954 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
956 /* We have our copies now, allow OS release its copies */
957 release_firmware(ucode_raw);
959 mutex_lock(&iwlwifi_opmode_table_mtx);
960 op = &iwlwifi_opmode_table[DVM_OP_MODE];
962 /* add this device to the list of devices using this op_mode */
963 list_add_tail(&drv->list, &op->drv);
966 drv->op_mode = _iwl_op_mode_start(drv, op);
969 mutex_unlock(&iwlwifi_opmode_table_mtx);
975 mutex_unlock(&iwlwifi_opmode_table_mtx);
978 * Complete the firmware request last so that
979 * a driver unbind (stop) doesn't run while we
980 * are doing the start() above.
982 complete(&drv->request_firmware_complete);
985 * Load the module last so we don't block anything
986 * else from proceeding if the module fails to load
990 request_module("%s", op->name);
994 /* try next, if any */
995 release_firmware(ucode_raw);
996 if (iwl_request_firmware(drv, false))
1001 IWL_ERR(drv, "failed to allocate pci memory\n");
1002 iwl_dealloc_ucode(drv);
1003 release_firmware(ucode_raw);
1005 complete(&drv->request_firmware_complete);
1006 device_release_driver(drv->trans->dev);
1009 struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
1010 const struct iwl_cfg *cfg)
1012 struct iwl_drv *drv;
1015 drv = kzalloc(sizeof(*drv), GFP_KERNEL);
1020 drv->dev = trans->dev;
1023 init_completion(&drv->request_firmware_complete);
1024 INIT_LIST_HEAD(&drv->list);
1026 #ifdef CONFIG_IWLWIFI_DEBUGFS
1027 /* Create the device debugfs entries. */
1028 drv->dbgfs_drv = debugfs_create_dir(dev_name(trans->dev),
1031 if (!drv->dbgfs_drv) {
1032 IWL_ERR(drv, "failed to create debugfs directory\n");
1036 /* Create transport layer debugfs dir */
1037 drv->trans->dbgfs_dir = debugfs_create_dir("trans", drv->dbgfs_drv);
1039 if (!drv->trans->dbgfs_dir) {
1040 IWL_ERR(drv, "failed to create transport debugfs directory\n");
1041 goto err_free_dbgfs;
1045 ret = iwl_request_firmware(drv, true);
1048 IWL_ERR(trans, "Couldn't request the fw\n");
1055 #ifdef CONFIG_IWLWIFI_DEBUGFS
1057 debugfs_remove_recursive(drv->dbgfs_drv);
1066 void iwl_drv_stop(struct iwl_drv *drv)
1068 wait_for_completion(&drv->request_firmware_complete);
1070 _iwl_op_mode_stop(drv);
1072 iwl_dealloc_ucode(drv);
1074 mutex_lock(&iwlwifi_opmode_table_mtx);
1076 * List is empty (this item wasn't added)
1077 * when firmware loading failed -- in that
1078 * case we can't remove it from any list.
1080 if (!list_empty(&drv->list))
1081 list_del(&drv->list);
1082 mutex_unlock(&iwlwifi_opmode_table_mtx);
1084 #ifdef CONFIG_IWLWIFI_DEBUGFS
1085 debugfs_remove_recursive(drv->dbgfs_drv);
1092 /* shared module parameters */
1093 struct iwl_mod_params iwlwifi_mod_params = {
1097 .bt_coex_active = true,
1098 .power_level = IWL_POWER_INDEX_1,
1099 .bt_ch_announce = true,
1102 /* the rest are 0 by default */
1104 EXPORT_SYMBOL_GPL(iwlwifi_mod_params);
1106 int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1109 struct iwl_drv *drv;
1110 struct iwlwifi_opmode_table *op;
1112 mutex_lock(&iwlwifi_opmode_table_mtx);
1113 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1114 op = &iwlwifi_opmode_table[i];
1115 if (strcmp(op->name, name))
1118 /* TODO: need to handle exceptional case */
1119 list_for_each_entry(drv, &op->drv, list)
1120 drv->op_mode = _iwl_op_mode_start(drv, op);
1122 mutex_unlock(&iwlwifi_opmode_table_mtx);
1125 mutex_unlock(&iwlwifi_opmode_table_mtx);
1128 EXPORT_SYMBOL_GPL(iwl_opmode_register);
1130 void iwl_opmode_deregister(const char *name)
1133 struct iwl_drv *drv;
1135 mutex_lock(&iwlwifi_opmode_table_mtx);
1136 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1137 if (strcmp(iwlwifi_opmode_table[i].name, name))
1139 iwlwifi_opmode_table[i].ops = NULL;
1141 /* call the stop routine for all devices */
1142 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1143 _iwl_op_mode_stop(drv);
1145 mutex_unlock(&iwlwifi_opmode_table_mtx);
1148 mutex_unlock(&iwlwifi_opmode_table_mtx);
1150 EXPORT_SYMBOL_GPL(iwl_opmode_deregister);
1152 static int __init iwl_drv_init(void)
1156 mutex_init(&iwlwifi_opmode_table_mtx);
1158 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1159 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1161 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
1162 pr_info(DRV_COPYRIGHT "\n");
1164 #ifdef CONFIG_IWLWIFI_DEBUGFS
1165 /* Create the root of iwlwifi debugfs subsystem. */
1166 iwl_dbgfs_root = debugfs_create_dir(DRV_NAME, NULL);
1168 if (!iwl_dbgfs_root)
1172 return iwl_pci_register_driver();
1174 module_init(iwl_drv_init);
1176 static void __exit iwl_drv_exit(void)
1178 iwl_pci_unregister_driver();
1180 #ifdef CONFIG_IWLWIFI_DEBUGFS
1181 debugfs_remove_recursive(iwl_dbgfs_root);
1184 module_exit(iwl_drv_exit);
1186 #ifdef CONFIG_IWLWIFI_DEBUG
1187 module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
1189 MODULE_PARM_DESC(debug, "debug output mask");
1192 module_param_named(swcrypto, iwlwifi_mod_params.sw_crypto, int, S_IRUGO);
1193 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
1194 module_param_named(11n_disable, iwlwifi_mod_params.disable_11n, uint, S_IRUGO);
1195 MODULE_PARM_DESC(11n_disable,
1196 "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
1197 module_param_named(amsdu_size_8K, iwlwifi_mod_params.amsdu_size_8K,
1199 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
1200 module_param_named(fw_restart, iwlwifi_mod_params.restart_fw, int, S_IRUGO);
1201 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
1203 module_param_named(antenna_coupling, iwlwifi_mod_params.ant_coupling,
1205 MODULE_PARM_DESC(antenna_coupling,
1206 "specify antenna coupling in dB (defualt: 0 dB)");
1208 module_param_named(bt_ch_inhibition, iwlwifi_mod_params.bt_ch_announce,
1210 MODULE_PARM_DESC(bt_ch_inhibition,
1211 "Enable BT channel inhibition (default: enable)");
1213 module_param_named(plcp_check, iwlwifi_mod_params.plcp_check, bool, S_IRUGO);
1214 MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
1216 module_param_named(wd_disable, iwlwifi_mod_params.wd_disable, int, S_IRUGO);
1217 MODULE_PARM_DESC(wd_disable,
1218 "Disable stuck queue watchdog timer 0=system default, "
1219 "1=disable, 2=enable (default: 0)");
1222 * set bt_coex_active to true, uCode will do kill/defer
1223 * every time the priority line is asserted (BT is sending signals on the
1224 * priority line in the PCIx).
1225 * set bt_coex_active to false, uCode will ignore the BT activity and
1226 * perform the normal operation
1228 * User might experience transmit issue on some platform due to WiFi/BT
1229 * co-exist problem. The possible behaviors are:
1230 * Able to scan and finding all the available AP
1231 * Not able to associate with any AP
1232 * On those platforms, WiFi communication can be restored by set
1233 * "bt_coex_active" module parameter to "false"
1235 * default: bt_coex_active = true (BT_COEX_ENABLE)
1237 module_param_named(bt_coex_active, iwlwifi_mod_params.bt_coex_active,
1239 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
1241 module_param_named(led_mode, iwlwifi_mod_params.led_mode, int, S_IRUGO);
1242 MODULE_PARM_DESC(led_mode, "0=system default, "
1243 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1245 module_param_named(power_save, iwlwifi_mod_params.power_save,
1247 MODULE_PARM_DESC(power_save,
1248 "enable WiFi power management (default: disable)");
1250 module_param_named(power_level, iwlwifi_mod_params.power_level,
1252 MODULE_PARM_DESC(power_level,
1253 "default power save level (range from 1 - 5, default: 1)");
1255 module_param_named(auto_agg, iwlwifi_mod_params.auto_agg,
1257 MODULE_PARM_DESC(auto_agg,
1258 "enable agg w/o check traffic load (default: enable)");
1260 module_param_named(5ghz_disable, iwlwifi_mod_params.disable_5ghz,
1262 MODULE_PARM_DESC(5ghz_disable, "disable 5GHz band (default: 0 [enabled])");