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 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65 #include <linux/completion.h>
66 #include <linux/dma-mapping.h>
67 #include <linux/firmware.h>
68 #include <linux/module.h>
69 #include <linux/vmalloc.h>
73 #include "iwl-debug.h"
74 #include "iwl-trans.h"
75 #include "iwl-op-mode.h"
76 #include "iwl-agn-hw.h"
78 #include "iwl-config.h"
79 #include "iwl-modparams.h"
81 /******************************************************************************
85 ******************************************************************************/
88 * module name, copyright, version, etc.
90 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
92 #ifdef CONFIG_IWLWIFI_DEBUG
98 #define DRV_VERSION IWLWIFI_VERSION VD
100 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
101 MODULE_VERSION(DRV_VERSION
);
102 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
103 MODULE_LICENSE("GPL");
105 #ifdef CONFIG_IWLWIFI_DEBUGFS
106 static struct dentry
*iwl_dbgfs_root
;
110 * struct iwl_drv - drv common data
111 * @list: list of drv structures using this opmode
112 * @fw: the iwl_fw structure
113 * @op_mode: the running op_mode
114 * @trans: transport layer
115 * @dev: for debug prints only
116 * @cfg: configuration struct
117 * @fw_index: firmware revision to try loading
118 * @firmware_name: composite filename of ucode file to load
119 * @request_firmware_complete: the firmware has been obtained from user space
122 struct list_head list
;
125 struct iwl_op_mode
*op_mode
;
126 struct iwl_trans
*trans
;
128 const struct iwl_cfg
*cfg
;
130 int fw_index
; /* firmware we're trying to load */
131 char firmware_name
[32]; /* name of firmware file to load */
133 struct completion request_firmware_complete
;
135 #ifdef CONFIG_IWLWIFI_DEBUGFS
136 struct dentry
*dbgfs_drv
;
137 struct dentry
*dbgfs_trans
;
138 struct dentry
*dbgfs_op_mode
;
147 /* Protects the table contents, i.e. the ops pointer & drv list */
148 static struct mutex iwlwifi_opmode_table_mtx
;
149 static struct iwlwifi_opmode_table
{
150 const char *name
; /* name: iwldvm, iwlmvm, etc */
151 const struct iwl_op_mode_ops
*ops
; /* pointer to op_mode ops */
152 struct list_head drv
; /* list of devices using this op_mode */
153 } iwlwifi_opmode_table
[] = { /* ops set when driver is initialized */
154 [DVM_OP_MODE
] = { .name
= "iwldvm", .ops
= NULL
},
155 [MVM_OP_MODE
] = { .name
= "iwlmvm", .ops
= NULL
},
158 #define IWL_DEFAULT_SCAN_CHANNELS 40
161 * struct fw_sec: Just for the image parsing proccess.
162 * For the fw storage we are using struct fw_desc.
165 const void *data
; /* the sec data */
166 size_t size
; /* section size */
167 u32 offset
; /* offset of writing in the device */
170 static void iwl_free_fw_desc(struct iwl_drv
*drv
, struct fw_desc
*desc
)
177 static void iwl_free_fw_img(struct iwl_drv
*drv
, struct fw_img
*img
)
180 for (i
= 0; i
< IWL_UCODE_SECTION_MAX
; i
++)
181 iwl_free_fw_desc(drv
, &img
->sec
[i
]);
184 static void iwl_dealloc_ucode(struct iwl_drv
*drv
)
187 for (i
= 0; i
< IWL_UCODE_TYPE_MAX
; i
++)
188 iwl_free_fw_img(drv
, drv
->fw
.img
+ i
);
191 static int iwl_alloc_fw_desc(struct iwl_drv
*drv
, struct fw_desc
*desc
,
198 if (!sec
|| !sec
->size
)
201 data
= vmalloc(sec
->size
);
205 desc
->len
= sec
->size
;
206 desc
->offset
= sec
->offset
;
207 memcpy(data
, sec
->data
, desc
->len
);
213 static void iwl_req_fw_callback(const struct firmware
*ucode_raw
,
216 #define UCODE_EXPERIMENTAL_INDEX 100
217 #define UCODE_EXPERIMENTAL_TAG "exp"
219 static int iwl_request_firmware(struct iwl_drv
*drv
, bool first
)
221 const char *name_pre
= drv
->cfg
->fw_name_pre
;
225 #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
226 drv
->fw_index
= UCODE_EXPERIMENTAL_INDEX
;
227 strcpy(tag
, UCODE_EXPERIMENTAL_TAG
);
228 } else if (drv
->fw_index
== UCODE_EXPERIMENTAL_INDEX
) {
230 drv
->fw_index
= drv
->cfg
->ucode_api_max
;
231 sprintf(tag
, "%d", drv
->fw_index
);
234 sprintf(tag
, "%d", drv
->fw_index
);
237 if (drv
->fw_index
< drv
->cfg
->ucode_api_min
) {
238 IWL_ERR(drv
, "no suitable firmware found!\n");
242 snprintf(drv
->firmware_name
, sizeof(drv
->firmware_name
), "%s%s.ucode",
246 * Starting 8000B - FW name format has changed. This overwrites the
247 * previous name and uses the new format.
250 * Once there is only one supported step for 8000 family - delete this!
252 if (drv
->trans
->cfg
->device_family
== IWL_DEVICE_FAMILY_8000
) {
254 'A' + CSR_HW_REV_STEP(drv
->trans
->hw_rev
), 0
257 /* A-step doesn't have an indication */
258 if (CSR_HW_REV_STEP(drv
->trans
->hw_rev
) == SILICON_A_STEP
)
262 * If hw_rev wasn't set yet - default as B-step. If it IS A-step
263 * we'll reload that FW later instead.
265 if (drv
->trans
->hw_rev
== 0)
268 snprintf(drv
->firmware_name
, sizeof(drv
->firmware_name
),
269 "%s%s-%s.ucode", name_pre
, rev_step
, tag
);
272 IWL_DEBUG_INFO(drv
, "attempting to load firmware %s'%s'\n",
273 (drv
->fw_index
== UCODE_EXPERIMENTAL_INDEX
)
274 ? "EXPERIMENTAL " : "",
277 return request_firmware_nowait(THIS_MODULE
, 1, drv
->firmware_name
,
279 GFP_KERNEL
, drv
, iwl_req_fw_callback
);
282 struct fw_img_parsing
{
283 struct fw_sec sec
[IWL_UCODE_SECTION_MAX
];
288 * struct fw_sec_parsing: to extract fw section and it's offset from tlv
290 struct fw_sec_parsing
{
296 * struct iwl_tlv_calib_data - parse the default calib data from TLV
298 * @ucode_type: the uCode to which the following default calib relates.
299 * @calib: default calibrations.
301 struct iwl_tlv_calib_data
{
303 struct iwl_tlv_calib_ctrl calib
;
306 struct iwl_firmware_pieces
{
307 struct fw_img_parsing img
[IWL_UCODE_TYPE_MAX
];
309 u32 init_evtlog_ptr
, init_evtlog_size
, init_errlog_ptr
;
310 u32 inst_evtlog_ptr
, inst_evtlog_size
, inst_errlog_ptr
;
314 * These functions are just to extract uCode section data from the pieces
317 static struct fw_sec
*get_sec(struct iwl_firmware_pieces
*pieces
,
318 enum iwl_ucode_type type
,
321 return &pieces
->img
[type
].sec
[sec
];
324 static void set_sec_data(struct iwl_firmware_pieces
*pieces
,
325 enum iwl_ucode_type type
,
329 pieces
->img
[type
].sec
[sec
].data
= data
;
332 static void set_sec_size(struct iwl_firmware_pieces
*pieces
,
333 enum iwl_ucode_type type
,
337 pieces
->img
[type
].sec
[sec
].size
= size
;
340 static size_t get_sec_size(struct iwl_firmware_pieces
*pieces
,
341 enum iwl_ucode_type type
,
344 return pieces
->img
[type
].sec
[sec
].size
;
347 static void set_sec_offset(struct iwl_firmware_pieces
*pieces
,
348 enum iwl_ucode_type type
,
352 pieces
->img
[type
].sec
[sec
].offset
= offset
;
355 static int iwl_store_cscheme(struct iwl_fw
*fw
, const u8
*data
, const u32 len
)
358 struct iwl_fw_cscheme_list
*l
= (struct iwl_fw_cscheme_list
*)data
;
359 struct iwl_fw_cipher_scheme
*fwcs
;
360 struct ieee80211_cipher_scheme
*cs
;
363 if (len
< sizeof(*l
) ||
364 len
< sizeof(l
->size
) + l
->size
* sizeof(l
->cs
[0]))
367 for (i
= 0, j
= 0; i
< IWL_UCODE_MAX_CS
&& i
< l
->size
; i
++) {
369 cipher
= le32_to_cpu(fwcs
->cipher
);
371 /* we skip schemes with zero cipher suite selector */
377 cs
->iftype
= BIT(NL80211_IFTYPE_STATION
);
378 cs
->hdr_len
= fwcs
->hdr_len
;
379 cs
->pn_len
= fwcs
->pn_len
;
380 cs
->pn_off
= fwcs
->pn_off
;
381 cs
->key_idx_off
= fwcs
->key_idx_off
;
382 cs
->key_idx_mask
= fwcs
->key_idx_mask
;
383 cs
->key_idx_shift
= fwcs
->key_idx_shift
;
384 cs
->mic_len
= fwcs
->mic_len
;
391 * Gets uCode section from tlv.
393 static int iwl_store_ucode_sec(struct iwl_firmware_pieces
*pieces
,
394 const void *data
, enum iwl_ucode_type type
,
397 struct fw_img_parsing
*img
;
399 struct fw_sec_parsing
*sec_parse
;
401 if (WARN_ON(!pieces
|| !data
|| type
>= IWL_UCODE_TYPE_MAX
))
404 sec_parse
= (struct fw_sec_parsing
*)data
;
406 img
= &pieces
->img
[type
];
407 sec
= &img
->sec
[img
->sec_counter
];
409 sec
->offset
= le32_to_cpu(sec_parse
->offset
);
410 sec
->data
= sec_parse
->data
;
411 sec
->size
= size
- sizeof(sec_parse
->offset
);
418 static int iwl_set_default_calib(struct iwl_drv
*drv
, const u8
*data
)
420 struct iwl_tlv_calib_data
*def_calib
=
421 (struct iwl_tlv_calib_data
*)data
;
422 u32 ucode_type
= le32_to_cpu(def_calib
->ucode_type
);
423 if (ucode_type
>= IWL_UCODE_TYPE_MAX
) {
424 IWL_ERR(drv
, "Wrong ucode_type %u for default calibration.\n",
428 drv
->fw
.default_calib
[ucode_type
].flow_trigger
=
429 def_calib
->calib
.flow_trigger
;
430 drv
->fw
.default_calib
[ucode_type
].event_trigger
=
431 def_calib
->calib
.event_trigger
;
436 static int iwl_set_ucode_api_flags(struct iwl_drv
*drv
, const u8
*data
,
437 struct iwl_ucode_capabilities
*capa
)
439 const struct iwl_ucode_api
*ucode_api
= (void *)data
;
440 u32 api_index
= le32_to_cpu(ucode_api
->api_index
);
442 if (api_index
>= IWL_API_ARRAY_SIZE
) {
443 IWL_ERR(drv
, "api_index larger than supported by driver\n");
447 capa
->api
[api_index
] = le32_to_cpu(ucode_api
->api_flags
);
452 static int iwl_set_ucode_capabilities(struct iwl_drv
*drv
, const u8
*data
,
453 struct iwl_ucode_capabilities
*capa
)
455 const struct iwl_ucode_capa
*ucode_capa
= (void *)data
;
456 u32 api_index
= le32_to_cpu(ucode_capa
->api_index
);
458 if (api_index
>= IWL_CAPABILITIES_ARRAY_SIZE
) {
459 IWL_ERR(drv
, "api_index larger than supported by driver\n");
463 capa
->capa
[api_index
] = le32_to_cpu(ucode_capa
->api_capa
);
468 static int iwl_parse_v1_v2_firmware(struct iwl_drv
*drv
,
469 const struct firmware
*ucode_raw
,
470 struct iwl_firmware_pieces
*pieces
)
472 struct iwl_ucode_header
*ucode
= (void *)ucode_raw
->data
;
473 u32 api_ver
, hdr_size
, build
;
477 drv
->fw
.ucode_ver
= le32_to_cpu(ucode
->ver
);
478 api_ver
= IWL_UCODE_API(drv
->fw
.ucode_ver
);
483 if (ucode_raw
->size
< hdr_size
) {
484 IWL_ERR(drv
, "File size too small!\n");
487 build
= le32_to_cpu(ucode
->u
.v2
.build
);
488 set_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
,
489 le32_to_cpu(ucode
->u
.v2
.inst_size
));
490 set_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
,
491 le32_to_cpu(ucode
->u
.v2
.data_size
));
492 set_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
,
493 le32_to_cpu(ucode
->u
.v2
.init_size
));
494 set_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
,
495 le32_to_cpu(ucode
->u
.v2
.init_data_size
));
496 src
= ucode
->u
.v2
.data
;
502 if (ucode_raw
->size
< hdr_size
) {
503 IWL_ERR(drv
, "File size too small!\n");
507 set_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
,
508 le32_to_cpu(ucode
->u
.v1
.inst_size
));
509 set_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
,
510 le32_to_cpu(ucode
->u
.v1
.data_size
));
511 set_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
,
512 le32_to_cpu(ucode
->u
.v1
.init_size
));
513 set_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
,
514 le32_to_cpu(ucode
->u
.v1
.init_data_size
));
515 src
= ucode
->u
.v1
.data
;
520 sprintf(buildstr
, " build %u%s", build
,
521 (drv
->fw_index
== UCODE_EXPERIMENTAL_INDEX
)
526 snprintf(drv
->fw
.fw_version
,
527 sizeof(drv
->fw
.fw_version
),
529 IWL_UCODE_MAJOR(drv
->fw
.ucode_ver
),
530 IWL_UCODE_MINOR(drv
->fw
.ucode_ver
),
531 IWL_UCODE_API(drv
->fw
.ucode_ver
),
532 IWL_UCODE_SERIAL(drv
->fw
.ucode_ver
),
535 /* Verify size of file vs. image size info in file's header */
537 if (ucode_raw
->size
!= hdr_size
+
538 get_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
) +
539 get_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
) +
540 get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
) +
541 get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
)) {
544 "uCode file size %d does not match expected size\n",
545 (int)ucode_raw
->size
);
550 set_sec_data(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
, src
);
551 src
+= get_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
);
552 set_sec_offset(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
,
553 IWLAGN_RTC_INST_LOWER_BOUND
);
554 set_sec_data(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
, src
);
555 src
+= get_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
);
556 set_sec_offset(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
,
557 IWLAGN_RTC_DATA_LOWER_BOUND
);
558 set_sec_data(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
, src
);
559 src
+= get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
);
560 set_sec_offset(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
,
561 IWLAGN_RTC_INST_LOWER_BOUND
);
562 set_sec_data(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
, src
);
563 src
+= get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
);
564 set_sec_offset(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
,
565 IWLAGN_RTC_DATA_LOWER_BOUND
);
569 static int iwl_parse_tlv_firmware(struct iwl_drv
*drv
,
570 const struct firmware
*ucode_raw
,
571 struct iwl_firmware_pieces
*pieces
,
572 struct iwl_ucode_capabilities
*capa
)
574 struct iwl_tlv_ucode_header
*ucode
= (void *)ucode_raw
->data
;
575 struct iwl_ucode_tlv
*tlv
;
576 size_t len
= ucode_raw
->size
;
579 enum iwl_ucode_tlv_type tlv_type
;
585 if (len
< sizeof(*ucode
)) {
586 IWL_ERR(drv
, "uCode has invalid length: %zd\n", len
);
590 if (ucode
->magic
!= cpu_to_le32(IWL_TLV_UCODE_MAGIC
)) {
591 IWL_ERR(drv
, "invalid uCode magic: 0X%x\n",
592 le32_to_cpu(ucode
->magic
));
596 drv
->fw
.ucode_ver
= le32_to_cpu(ucode
->ver
);
597 memcpy(drv
->fw
.human_readable
, ucode
->human_readable
,
598 sizeof(drv
->fw
.human_readable
));
599 build
= le32_to_cpu(ucode
->build
);
602 sprintf(buildstr
, " build %u%s", build
,
603 (drv
->fw_index
== UCODE_EXPERIMENTAL_INDEX
)
608 snprintf(drv
->fw
.fw_version
,
609 sizeof(drv
->fw
.fw_version
),
611 IWL_UCODE_MAJOR(drv
->fw
.ucode_ver
),
612 IWL_UCODE_MINOR(drv
->fw
.ucode_ver
),
613 IWL_UCODE_API(drv
->fw
.ucode_ver
),
614 IWL_UCODE_SERIAL(drv
->fw
.ucode_ver
),
619 len
-= sizeof(*ucode
);
621 while (len
>= sizeof(*tlv
)) {
625 tlv_len
= le32_to_cpu(tlv
->length
);
626 tlv_type
= le32_to_cpu(tlv
->type
);
627 tlv_data
= tlv
->data
;
630 IWL_ERR(drv
, "invalid TLV len: %zd/%u\n",
634 len
-= ALIGN(tlv_len
, 4);
635 data
+= sizeof(*tlv
) + ALIGN(tlv_len
, 4);
638 case IWL_UCODE_TLV_INST
:
639 set_sec_data(pieces
, IWL_UCODE_REGULAR
,
640 IWL_UCODE_SECTION_INST
, tlv_data
);
641 set_sec_size(pieces
, IWL_UCODE_REGULAR
,
642 IWL_UCODE_SECTION_INST
, tlv_len
);
643 set_sec_offset(pieces
, IWL_UCODE_REGULAR
,
644 IWL_UCODE_SECTION_INST
,
645 IWLAGN_RTC_INST_LOWER_BOUND
);
647 case IWL_UCODE_TLV_DATA
:
648 set_sec_data(pieces
, IWL_UCODE_REGULAR
,
649 IWL_UCODE_SECTION_DATA
, tlv_data
);
650 set_sec_size(pieces
, IWL_UCODE_REGULAR
,
651 IWL_UCODE_SECTION_DATA
, tlv_len
);
652 set_sec_offset(pieces
, IWL_UCODE_REGULAR
,
653 IWL_UCODE_SECTION_DATA
,
654 IWLAGN_RTC_DATA_LOWER_BOUND
);
656 case IWL_UCODE_TLV_INIT
:
657 set_sec_data(pieces
, IWL_UCODE_INIT
,
658 IWL_UCODE_SECTION_INST
, tlv_data
);
659 set_sec_size(pieces
, IWL_UCODE_INIT
,
660 IWL_UCODE_SECTION_INST
, tlv_len
);
661 set_sec_offset(pieces
, IWL_UCODE_INIT
,
662 IWL_UCODE_SECTION_INST
,
663 IWLAGN_RTC_INST_LOWER_BOUND
);
665 case IWL_UCODE_TLV_INIT_DATA
:
666 set_sec_data(pieces
, IWL_UCODE_INIT
,
667 IWL_UCODE_SECTION_DATA
, tlv_data
);
668 set_sec_size(pieces
, IWL_UCODE_INIT
,
669 IWL_UCODE_SECTION_DATA
, tlv_len
);
670 set_sec_offset(pieces
, IWL_UCODE_INIT
,
671 IWL_UCODE_SECTION_DATA
,
672 IWLAGN_RTC_DATA_LOWER_BOUND
);
674 case IWL_UCODE_TLV_BOOT
:
675 IWL_ERR(drv
, "Found unexpected BOOT ucode\n");
677 case IWL_UCODE_TLV_PROBE_MAX_LEN
:
678 if (tlv_len
!= sizeof(u32
))
679 goto invalid_tlv_len
;
680 capa
->max_probe_length
=
681 le32_to_cpup((__le32
*)tlv_data
);
683 case IWL_UCODE_TLV_PAN
:
685 goto invalid_tlv_len
;
686 capa
->flags
|= IWL_UCODE_TLV_FLAGS_PAN
;
688 case IWL_UCODE_TLV_FLAGS
:
689 /* must be at least one u32 */
690 if (tlv_len
< sizeof(u32
))
691 goto invalid_tlv_len
;
692 /* and a proper number of u32s */
693 if (tlv_len
% sizeof(u32
))
694 goto invalid_tlv_len
;
696 * This driver only reads the first u32 as
697 * right now no more features are defined,
698 * if that changes then either the driver
699 * will not work with the new firmware, or
700 * it'll not take advantage of new features.
702 capa
->flags
= le32_to_cpup((__le32
*)tlv_data
);
704 case IWL_UCODE_TLV_API_CHANGES_SET
:
705 if (tlv_len
!= sizeof(struct iwl_ucode_api
))
706 goto invalid_tlv_len
;
707 if (iwl_set_ucode_api_flags(drv
, tlv_data
, capa
))
710 case IWL_UCODE_TLV_ENABLED_CAPABILITIES
:
711 if (tlv_len
!= sizeof(struct iwl_ucode_capa
))
712 goto invalid_tlv_len
;
713 if (iwl_set_ucode_capabilities(drv
, tlv_data
, capa
))
716 case IWL_UCODE_TLV_INIT_EVTLOG_PTR
:
717 if (tlv_len
!= sizeof(u32
))
718 goto invalid_tlv_len
;
719 pieces
->init_evtlog_ptr
=
720 le32_to_cpup((__le32
*)tlv_data
);
722 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE
:
723 if (tlv_len
!= sizeof(u32
))
724 goto invalid_tlv_len
;
725 pieces
->init_evtlog_size
=
726 le32_to_cpup((__le32
*)tlv_data
);
728 case IWL_UCODE_TLV_INIT_ERRLOG_PTR
:
729 if (tlv_len
!= sizeof(u32
))
730 goto invalid_tlv_len
;
731 pieces
->init_errlog_ptr
=
732 le32_to_cpup((__le32
*)tlv_data
);
734 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR
:
735 if (tlv_len
!= sizeof(u32
))
736 goto invalid_tlv_len
;
737 pieces
->inst_evtlog_ptr
=
738 le32_to_cpup((__le32
*)tlv_data
);
740 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE
:
741 if (tlv_len
!= sizeof(u32
))
742 goto invalid_tlv_len
;
743 pieces
->inst_evtlog_size
=
744 le32_to_cpup((__le32
*)tlv_data
);
746 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR
:
747 if (tlv_len
!= sizeof(u32
))
748 goto invalid_tlv_len
;
749 pieces
->inst_errlog_ptr
=
750 le32_to_cpup((__le32
*)tlv_data
);
752 case IWL_UCODE_TLV_ENHANCE_SENS_TBL
:
754 goto invalid_tlv_len
;
755 drv
->fw
.enhance_sensitivity_table
= true;
757 case IWL_UCODE_TLV_WOWLAN_INST
:
758 set_sec_data(pieces
, IWL_UCODE_WOWLAN
,
759 IWL_UCODE_SECTION_INST
, tlv_data
);
760 set_sec_size(pieces
, IWL_UCODE_WOWLAN
,
761 IWL_UCODE_SECTION_INST
, tlv_len
);
762 set_sec_offset(pieces
, IWL_UCODE_WOWLAN
,
763 IWL_UCODE_SECTION_INST
,
764 IWLAGN_RTC_INST_LOWER_BOUND
);
766 case IWL_UCODE_TLV_WOWLAN_DATA
:
767 set_sec_data(pieces
, IWL_UCODE_WOWLAN
,
768 IWL_UCODE_SECTION_DATA
, tlv_data
);
769 set_sec_size(pieces
, IWL_UCODE_WOWLAN
,
770 IWL_UCODE_SECTION_DATA
, tlv_len
);
771 set_sec_offset(pieces
, IWL_UCODE_WOWLAN
,
772 IWL_UCODE_SECTION_DATA
,
773 IWLAGN_RTC_DATA_LOWER_BOUND
);
775 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE
:
776 if (tlv_len
!= sizeof(u32
))
777 goto invalid_tlv_len
;
778 capa
->standard_phy_calibration_size
=
779 le32_to_cpup((__le32
*)tlv_data
);
781 case IWL_UCODE_TLV_SEC_RT
:
782 iwl_store_ucode_sec(pieces
, tlv_data
, IWL_UCODE_REGULAR
,
784 drv
->fw
.mvm_fw
= true;
786 case IWL_UCODE_TLV_SEC_INIT
:
787 iwl_store_ucode_sec(pieces
, tlv_data
, IWL_UCODE_INIT
,
789 drv
->fw
.mvm_fw
= true;
791 case IWL_UCODE_TLV_SEC_WOWLAN
:
792 iwl_store_ucode_sec(pieces
, tlv_data
, IWL_UCODE_WOWLAN
,
794 drv
->fw
.mvm_fw
= true;
796 case IWL_UCODE_TLV_DEF_CALIB
:
797 if (tlv_len
!= sizeof(struct iwl_tlv_calib_data
))
798 goto invalid_tlv_len
;
799 if (iwl_set_default_calib(drv
, tlv_data
))
802 case IWL_UCODE_TLV_PHY_SKU
:
803 if (tlv_len
!= sizeof(u32
))
804 goto invalid_tlv_len
;
805 drv
->fw
.phy_config
= le32_to_cpup((__le32
*)tlv_data
);
806 drv
->fw
.valid_tx_ant
= (drv
->fw
.phy_config
&
807 FW_PHY_CFG_TX_CHAIN
) >>
808 FW_PHY_CFG_TX_CHAIN_POS
;
809 drv
->fw
.valid_rx_ant
= (drv
->fw
.phy_config
&
810 FW_PHY_CFG_RX_CHAIN
) >>
811 FW_PHY_CFG_RX_CHAIN_POS
;
813 case IWL_UCODE_TLV_SECURE_SEC_RT
:
814 iwl_store_ucode_sec(pieces
, tlv_data
, IWL_UCODE_REGULAR
,
816 drv
->fw
.mvm_fw
= true;
818 case IWL_UCODE_TLV_SECURE_SEC_INIT
:
819 iwl_store_ucode_sec(pieces
, tlv_data
, IWL_UCODE_INIT
,
821 drv
->fw
.mvm_fw
= true;
823 case IWL_UCODE_TLV_SECURE_SEC_WOWLAN
:
824 iwl_store_ucode_sec(pieces
, tlv_data
, IWL_UCODE_WOWLAN
,
826 drv
->fw
.mvm_fw
= true;
828 case IWL_UCODE_TLV_NUM_OF_CPU
:
829 if (tlv_len
!= sizeof(u32
))
830 goto invalid_tlv_len
;
832 le32_to_cpup((__le32
*)tlv_data
);
834 if (num_of_cpus
== 2) {
835 drv
->fw
.img
[IWL_UCODE_REGULAR
].is_dual_cpus
=
837 drv
->fw
.img
[IWL_UCODE_INIT
].is_dual_cpus
=
839 drv
->fw
.img
[IWL_UCODE_WOWLAN
].is_dual_cpus
=
841 } else if ((num_of_cpus
> 2) || (num_of_cpus
< 1)) {
842 IWL_ERR(drv
, "Driver support upto 2 CPUs\n");
846 case IWL_UCODE_TLV_CSCHEME
:
847 if (iwl_store_cscheme(&drv
->fw
, tlv_data
, tlv_len
))
848 goto invalid_tlv_len
;
850 case IWL_UCODE_TLV_N_SCAN_CHANNELS
:
851 if (tlv_len
!= sizeof(u32
))
852 goto invalid_tlv_len
;
853 capa
->n_scan_channels
=
854 le32_to_cpup((__le32
*)tlv_data
);
857 IWL_DEBUG_INFO(drv
, "unknown TLV: %d\n", tlv_type
);
863 IWL_ERR(drv
, "invalid TLV after parsing: %zd\n", len
);
864 iwl_print_hex_dump(drv
, IWL_DL_FW
, (u8
*)data
, len
);
871 IWL_ERR(drv
, "TLV %d has invalid size: %u\n", tlv_type
, tlv_len
);
873 iwl_print_hex_dump(drv
, IWL_DL_FW
, tlv_data
, tlv_len
);
878 static int iwl_alloc_ucode(struct iwl_drv
*drv
,
879 struct iwl_firmware_pieces
*pieces
,
880 enum iwl_ucode_type type
)
884 i
< IWL_UCODE_SECTION_MAX
&& get_sec_size(pieces
, type
, i
);
886 if (iwl_alloc_fw_desc(drv
, &(drv
->fw
.img
[type
].sec
[i
]),
887 get_sec(pieces
, type
, i
)))
892 static int validate_sec_sizes(struct iwl_drv
*drv
,
893 struct iwl_firmware_pieces
*pieces
,
894 const struct iwl_cfg
*cfg
)
896 IWL_DEBUG_INFO(drv
, "f/w package hdr runtime inst size = %Zd\n",
897 get_sec_size(pieces
, IWL_UCODE_REGULAR
,
898 IWL_UCODE_SECTION_INST
));
899 IWL_DEBUG_INFO(drv
, "f/w package hdr runtime data size = %Zd\n",
900 get_sec_size(pieces
, IWL_UCODE_REGULAR
,
901 IWL_UCODE_SECTION_DATA
));
902 IWL_DEBUG_INFO(drv
, "f/w package hdr init inst size = %Zd\n",
903 get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
));
904 IWL_DEBUG_INFO(drv
, "f/w package hdr init data size = %Zd\n",
905 get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
));
907 /* Verify that uCode images will fit in card's SRAM. */
908 if (get_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_INST
) >
909 cfg
->max_inst_size
) {
910 IWL_ERR(drv
, "uCode instr len %Zd too large to fit in\n",
911 get_sec_size(pieces
, IWL_UCODE_REGULAR
,
912 IWL_UCODE_SECTION_INST
));
916 if (get_sec_size(pieces
, IWL_UCODE_REGULAR
, IWL_UCODE_SECTION_DATA
) >
917 cfg
->max_data_size
) {
918 IWL_ERR(drv
, "uCode data len %Zd too large to fit in\n",
919 get_sec_size(pieces
, IWL_UCODE_REGULAR
,
920 IWL_UCODE_SECTION_DATA
));
924 if (get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_INST
) >
925 cfg
->max_inst_size
) {
926 IWL_ERR(drv
, "uCode init instr len %Zd too large to fit in\n",
927 get_sec_size(pieces
, IWL_UCODE_INIT
,
928 IWL_UCODE_SECTION_INST
));
932 if (get_sec_size(pieces
, IWL_UCODE_INIT
, IWL_UCODE_SECTION_DATA
) >
933 cfg
->max_data_size
) {
934 IWL_ERR(drv
, "uCode init data len %Zd too large to fit in\n",
935 get_sec_size(pieces
, IWL_UCODE_REGULAR
,
936 IWL_UCODE_SECTION_DATA
));
942 static struct iwl_op_mode
*
943 _iwl_op_mode_start(struct iwl_drv
*drv
, struct iwlwifi_opmode_table
*op
)
945 const struct iwl_op_mode_ops
*ops
= op
->ops
;
946 struct dentry
*dbgfs_dir
= NULL
;
947 struct iwl_op_mode
*op_mode
= NULL
;
949 #ifdef CONFIG_IWLWIFI_DEBUGFS
950 drv
->dbgfs_op_mode
= debugfs_create_dir(op
->name
,
952 if (!drv
->dbgfs_op_mode
) {
954 "failed to create opmode debugfs directory\n");
957 dbgfs_dir
= drv
->dbgfs_op_mode
;
960 op_mode
= ops
->start(drv
->trans
, drv
->cfg
, &drv
->fw
, dbgfs_dir
);
962 #ifdef CONFIG_IWLWIFI_DEBUGFS
964 debugfs_remove_recursive(drv
->dbgfs_op_mode
);
965 drv
->dbgfs_op_mode
= NULL
;
972 static void _iwl_op_mode_stop(struct iwl_drv
*drv
)
974 /* op_mode can be NULL if its start failed */
976 iwl_op_mode_stop(drv
->op_mode
);
979 #ifdef CONFIG_IWLWIFI_DEBUGFS
980 debugfs_remove_recursive(drv
->dbgfs_op_mode
);
981 drv
->dbgfs_op_mode
= NULL
;
987 * iwl_req_fw_callback - callback when firmware was loaded
989 * If loaded successfully, copies the firmware into buffers
990 * for the card to fetch (via DMA).
992 static void iwl_req_fw_callback(const struct firmware
*ucode_raw
, void *context
)
994 struct iwl_drv
*drv
= context
;
995 struct iwl_fw
*fw
= &drv
->fw
;
996 struct iwl_ucode_header
*ucode
;
997 struct iwlwifi_opmode_table
*op
;
999 struct iwl_firmware_pieces pieces
;
1000 const unsigned int api_max
= drv
->cfg
->ucode_api_max
;
1001 unsigned int api_ok
= drv
->cfg
->ucode_api_ok
;
1002 const unsigned int api_min
= drv
->cfg
->ucode_api_min
;
1005 bool load_module
= false;
1006 u32 hw_rev
= drv
->trans
->hw_rev
;
1008 fw
->ucode_capa
.max_probe_length
= IWL_DEFAULT_MAX_PROBE_LENGTH
;
1009 fw
->ucode_capa
.standard_phy_calibration_size
=
1010 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE
;
1011 fw
->ucode_capa
.n_scan_channels
= IWL_DEFAULT_SCAN_CHANNELS
;
1016 memset(&pieces
, 0, sizeof(pieces
));
1019 if (drv
->fw_index
<= api_ok
)
1021 "request for firmware file '%s' failed.\n",
1022 drv
->firmware_name
);
1026 IWL_DEBUG_INFO(drv
, "Loaded firmware file '%s' (%zd bytes).\n",
1027 drv
->firmware_name
, ucode_raw
->size
);
1029 /* Make sure that we got at least the API version number */
1030 if (ucode_raw
->size
< 4) {
1031 IWL_ERR(drv
, "File size way too small!\n");
1035 /* Data from ucode file: header followed by uCode images */
1036 ucode
= (struct iwl_ucode_header
*)ucode_raw
->data
;
1039 err
= iwl_parse_v1_v2_firmware(drv
, ucode_raw
, &pieces
);
1041 err
= iwl_parse_tlv_firmware(drv
, ucode_raw
, &pieces
,
1047 api_ver
= IWL_UCODE_API(drv
->fw
.ucode_ver
);
1050 * api_ver should match the api version forming part of the
1051 * firmware filename ... but we don't check for that and only rely
1052 * on the API version read from firmware header from here on forward
1054 /* no api version check required for experimental uCode */
1055 if (drv
->fw_index
!= UCODE_EXPERIMENTAL_INDEX
) {
1056 if (api_ver
< api_min
|| api_ver
> api_max
) {
1058 "Driver unable to support your firmware API. "
1059 "Driver supports v%u, firmware is v%u.\n",
1064 if (api_ver
< api_ok
) {
1065 if (api_ok
!= api_max
)
1066 IWL_ERR(drv
, "Firmware has old API version, "
1067 "expected v%u through v%u, got v%u.\n",
1068 api_ok
, api_max
, api_ver
);
1070 IWL_ERR(drv
, "Firmware has old API version, "
1071 "expected v%u, got v%u.\n",
1073 IWL_ERR(drv
, "New firmware can be obtained from "
1074 "http://www.intellinuxwireless.org/.\n");
1079 * In mvm uCode there is no difference between data and instructions
1082 if (!fw
->mvm_fw
&& validate_sec_sizes(drv
, &pieces
, drv
->cfg
))
1085 /* Allocate ucode buffers for card's bus-master loading ... */
1087 /* Runtime instructions and 2 copies of data:
1088 * 1) unmodified from disk
1089 * 2) backup cache for save/restore during power-downs */
1090 for (i
= 0; i
< IWL_UCODE_TYPE_MAX
; i
++)
1091 if (iwl_alloc_ucode(drv
, &pieces
, i
))
1094 /* Now that we can no longer fail, copy information */
1097 * The (size - 16) / 12 formula is based on the information recorded
1098 * for each event, which is of mode 1 (including timestamp) for all
1099 * new microcodes that include this information.
1101 fw
->init_evtlog_ptr
= pieces
.init_evtlog_ptr
;
1102 if (pieces
.init_evtlog_size
)
1103 fw
->init_evtlog_size
= (pieces
.init_evtlog_size
- 16)/12;
1105 fw
->init_evtlog_size
=
1106 drv
->cfg
->base_params
->max_event_log_size
;
1107 fw
->init_errlog_ptr
= pieces
.init_errlog_ptr
;
1108 fw
->inst_evtlog_ptr
= pieces
.inst_evtlog_ptr
;
1109 if (pieces
.inst_evtlog_size
)
1110 fw
->inst_evtlog_size
= (pieces
.inst_evtlog_size
- 16)/12;
1112 fw
->inst_evtlog_size
=
1113 drv
->cfg
->base_params
->max_event_log_size
;
1114 fw
->inst_errlog_ptr
= pieces
.inst_errlog_ptr
;
1117 * figure out the offset of chain noise reset and gain commands
1118 * base on the size of standard phy calibration commands table size
1120 if (fw
->ucode_capa
.standard_phy_calibration_size
>
1121 IWL_MAX_PHY_CALIBRATE_TBL_SIZE
)
1122 fw
->ucode_capa
.standard_phy_calibration_size
=
1123 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE
;
1125 /* We have our copies now, allow OS release its copies */
1126 release_firmware(ucode_raw
);
1128 mutex_lock(&iwlwifi_opmode_table_mtx
);
1130 op
= &iwlwifi_opmode_table
[MVM_OP_MODE
];
1132 op
= &iwlwifi_opmode_table
[DVM_OP_MODE
];
1134 IWL_INFO(drv
, "loaded firmware version %s op_mode %s\n",
1135 drv
->fw
.fw_version
, op
->name
);
1137 /* add this device to the list of devices using this op_mode */
1138 list_add_tail(&drv
->list
, &op
->drv
);
1141 drv
->op_mode
= _iwl_op_mode_start(drv
, op
);
1143 if (!drv
->op_mode
) {
1144 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1150 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1153 * Complete the firmware request last so that
1154 * a driver unbind (stop) doesn't run while we
1155 * are doing the start() above.
1157 complete(&drv
->request_firmware_complete
);
1160 * Load the module last so we don't block anything
1161 * else from proceeding if the module fails to load
1165 err
= request_module("%s", op
->name
);
1166 #ifdef CONFIG_IWLWIFI_OPMODE_MODULAR
1169 "failed to load module %s (error %d), is dynamic loading enabled?\n",
1175 * We may have loaded the wrong FW file in 8000 HW family if it is an
1176 * A-step card, and if drv->trans->hw_rev wasn't properly read when
1177 * the FW file had been loaded. (This might happen in SDIO.) In such a
1178 * case - unload and reload the correct file.
1181 * Once there is only one supported step for 8000 family - delete this!
1183 if (drv
->trans
->cfg
->device_family
== IWL_DEVICE_FAMILY_8000
&&
1184 CSR_HW_REV_STEP(drv
->trans
->hw_rev
) == SILICON_A_STEP
&&
1185 drv
->trans
->hw_rev
!= hw_rev
) {
1186 char firmware_name
[32];
1188 /* Free previous FW resources */
1190 _iwl_op_mode_stop(drv
);
1191 iwl_dealloc_ucode(drv
);
1193 /* Build name of correct-step FW */
1194 snprintf(firmware_name
, sizeof(firmware_name
),
1195 strrchr(drv
->firmware_name
, '-'));
1196 snprintf(drv
->firmware_name
, sizeof(drv
->firmware_name
),
1197 "%s%s", drv
->cfg
->fw_name_pre
, firmware_name
);
1199 /* Clear data before loading correct FW */
1200 list_del(&drv
->list
);
1202 /* Request correct FW file this time */
1203 IWL_DEBUG_INFO(drv
, "attempting to load A-step FW %s\n",
1204 drv
->firmware_name
);
1205 err
= request_firmware(&ucode_raw
, drv
->firmware_name
,
1208 IWL_ERR(drv
, "Failed swapping FW!\n");
1212 /* Redo callback function - this time with right FW */
1213 iwl_req_fw_callback(ucode_raw
, context
);
1219 /* try next, if any */
1220 release_firmware(ucode_raw
);
1221 if (iwl_request_firmware(drv
, false))
1226 IWL_ERR(drv
, "failed to allocate pci memory\n");
1227 iwl_dealloc_ucode(drv
);
1228 release_firmware(ucode_raw
);
1230 complete(&drv
->request_firmware_complete
);
1231 device_release_driver(drv
->trans
->dev
);
1234 struct iwl_drv
*iwl_drv_start(struct iwl_trans
*trans
,
1235 const struct iwl_cfg
*cfg
)
1237 struct iwl_drv
*drv
;
1240 drv
= kzalloc(sizeof(*drv
), GFP_KERNEL
);
1247 drv
->dev
= trans
->dev
;
1250 init_completion(&drv
->request_firmware_complete
);
1251 INIT_LIST_HEAD(&drv
->list
);
1253 #ifdef CONFIG_IWLWIFI_DEBUGFS
1254 /* Create the device debugfs entries. */
1255 drv
->dbgfs_drv
= debugfs_create_dir(dev_name(trans
->dev
),
1258 if (!drv
->dbgfs_drv
) {
1259 IWL_ERR(drv
, "failed to create debugfs directory\n");
1264 /* Create transport layer debugfs dir */
1265 drv
->trans
->dbgfs_dir
= debugfs_create_dir("trans", drv
->dbgfs_drv
);
1267 if (!drv
->trans
->dbgfs_dir
) {
1268 IWL_ERR(drv
, "failed to create transport debugfs directory\n");
1270 goto err_free_dbgfs
;
1274 ret
= iwl_request_firmware(drv
, true);
1276 IWL_ERR(trans
, "Couldn't request the fw\n");
1283 #ifdef CONFIG_IWLWIFI_DEBUGFS
1285 debugfs_remove_recursive(drv
->dbgfs_drv
);
1290 return ERR_PTR(ret
);
1293 void iwl_drv_stop(struct iwl_drv
*drv
)
1295 wait_for_completion(&drv
->request_firmware_complete
);
1297 _iwl_op_mode_stop(drv
);
1299 iwl_dealloc_ucode(drv
);
1301 mutex_lock(&iwlwifi_opmode_table_mtx
);
1303 * List is empty (this item wasn't added)
1304 * when firmware loading failed -- in that
1305 * case we can't remove it from any list.
1307 if (!list_empty(&drv
->list
))
1308 list_del(&drv
->list
);
1309 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1311 #ifdef CONFIG_IWLWIFI_DEBUGFS
1312 debugfs_remove_recursive(drv
->dbgfs_drv
);
1319 /* shared module parameters */
1320 struct iwl_mod_params iwlwifi_mod_params
= {
1322 .bt_coex_active
= true,
1323 .power_level
= IWL_POWER_INDEX_1
,
1325 #ifndef CONFIG_IWLWIFI_UAPSD
1326 .uapsd_disable
= true,
1327 #endif /* CONFIG_IWLWIFI_UAPSD */
1328 /* the rest are 0 by default */
1330 IWL_EXPORT_SYMBOL(iwlwifi_mod_params
);
1332 int iwl_opmode_register(const char *name
, const struct iwl_op_mode_ops
*ops
)
1335 struct iwl_drv
*drv
;
1336 struct iwlwifi_opmode_table
*op
;
1338 mutex_lock(&iwlwifi_opmode_table_mtx
);
1339 for (i
= 0; i
< ARRAY_SIZE(iwlwifi_opmode_table
); i
++) {
1340 op
= &iwlwifi_opmode_table
[i
];
1341 if (strcmp(op
->name
, name
))
1344 /* TODO: need to handle exceptional case */
1345 list_for_each_entry(drv
, &op
->drv
, list
)
1346 drv
->op_mode
= _iwl_op_mode_start(drv
, op
);
1348 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1351 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1354 IWL_EXPORT_SYMBOL(iwl_opmode_register
);
1356 void iwl_opmode_deregister(const char *name
)
1359 struct iwl_drv
*drv
;
1361 mutex_lock(&iwlwifi_opmode_table_mtx
);
1362 for (i
= 0; i
< ARRAY_SIZE(iwlwifi_opmode_table
); i
++) {
1363 if (strcmp(iwlwifi_opmode_table
[i
].name
, name
))
1365 iwlwifi_opmode_table
[i
].ops
= NULL
;
1367 /* call the stop routine for all devices */
1368 list_for_each_entry(drv
, &iwlwifi_opmode_table
[i
].drv
, list
)
1369 _iwl_op_mode_stop(drv
);
1371 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1374 mutex_unlock(&iwlwifi_opmode_table_mtx
);
1376 IWL_EXPORT_SYMBOL(iwl_opmode_deregister
);
1378 static int __init
iwl_drv_init(void)
1382 mutex_init(&iwlwifi_opmode_table_mtx
);
1384 for (i
= 0; i
< ARRAY_SIZE(iwlwifi_opmode_table
); i
++)
1385 INIT_LIST_HEAD(&iwlwifi_opmode_table
[i
].drv
);
1387 pr_info(DRV_DESCRIPTION
", " DRV_VERSION
"\n");
1388 pr_info(DRV_COPYRIGHT
"\n");
1390 #ifdef CONFIG_IWLWIFI_DEBUGFS
1391 /* Create the root of iwlwifi debugfs subsystem. */
1392 iwl_dbgfs_root
= debugfs_create_dir(DRV_NAME
, NULL
);
1394 if (!iwl_dbgfs_root
)
1398 return iwl_pci_register_driver();
1400 module_init(iwl_drv_init
);
1402 static void __exit
iwl_drv_exit(void)
1404 iwl_pci_unregister_driver();
1406 #ifdef CONFIG_IWLWIFI_DEBUGFS
1407 debugfs_remove_recursive(iwl_dbgfs_root
);
1410 module_exit(iwl_drv_exit
);
1412 #ifdef CONFIG_IWLWIFI_DEBUG
1413 module_param_named(debug
, iwlwifi_mod_params
.debug_level
, uint
,
1415 MODULE_PARM_DESC(debug
, "debug output mask");
1418 module_param_named(swcrypto
, iwlwifi_mod_params
.sw_crypto
, int, S_IRUGO
);
1419 MODULE_PARM_DESC(swcrypto
, "using crypto in software (default 0 [hardware])");
1420 module_param_named(11n_disable
, iwlwifi_mod_params
.disable_11n
, uint
, S_IRUGO
);
1421 MODULE_PARM_DESC(11n_disable
,
1422 "disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX");
1423 module_param_named(amsdu_size_8K
, iwlwifi_mod_params
.amsdu_size_8K
,
1425 MODULE_PARM_DESC(amsdu_size_8K
, "enable 8K amsdu size (default 0)");
1426 module_param_named(fw_restart
, iwlwifi_mod_params
.restart_fw
, bool, S_IRUGO
);
1427 MODULE_PARM_DESC(fw_restart
, "restart firmware in case of error (default true)");
1429 module_param_named(antenna_coupling
, iwlwifi_mod_params
.ant_coupling
,
1431 MODULE_PARM_DESC(antenna_coupling
,
1432 "specify antenna coupling in dB (default: 0 dB)");
1434 module_param_named(wd_disable
, iwlwifi_mod_params
.wd_disable
, int, S_IRUGO
);
1435 MODULE_PARM_DESC(wd_disable
,
1436 "Disable stuck queue watchdog timer 0=system default, 1=disable (default: 1)");
1438 module_param_named(nvm_file
, iwlwifi_mod_params
.nvm_file
, charp
, S_IRUGO
);
1439 MODULE_PARM_DESC(nvm_file
, "NVM file name");
1441 module_param_named(uapsd_disable
, iwlwifi_mod_params
.uapsd_disable
,
1443 #ifdef CONFIG_IWLWIFI_UAPSD
1444 MODULE_PARM_DESC(uapsd_disable
, "disable U-APSD functionality (default: N)");
1446 MODULE_PARM_DESC(uapsd_disable
, "disable U-APSD functionality (default: Y)");
1450 * set bt_coex_active to true, uCode will do kill/defer
1451 * every time the priority line is asserted (BT is sending signals on the
1452 * priority line in the PCIx).
1453 * set bt_coex_active to false, uCode will ignore the BT activity and
1454 * perform the normal operation
1456 * User might experience transmit issue on some platform due to WiFi/BT
1457 * co-exist problem. The possible behaviors are:
1458 * Able to scan and finding all the available AP
1459 * Not able to associate with any AP
1460 * On those platforms, WiFi communication can be restored by set
1461 * "bt_coex_active" module parameter to "false"
1463 * default: bt_coex_active = true (BT_COEX_ENABLE)
1465 module_param_named(bt_coex_active
, iwlwifi_mod_params
.bt_coex_active
,
1467 MODULE_PARM_DESC(bt_coex_active
, "enable wifi/bt co-exist (default: enable)");
1469 module_param_named(led_mode
, iwlwifi_mod_params
.led_mode
, int, S_IRUGO
);
1470 MODULE_PARM_DESC(led_mode
, "0=system default, "
1471 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1473 module_param_named(power_save
, iwlwifi_mod_params
.power_save
,
1475 MODULE_PARM_DESC(power_save
,
1476 "enable WiFi power management (default: disable)");
1478 module_param_named(power_level
, iwlwifi_mod_params
.power_level
,
1480 MODULE_PARM_DESC(power_level
,
1481 "default power save level (range from 1 - 5, default: 1)");
1483 module_param_named(fw_monitor
, iwlwifi_mod_params
.fw_monitor
, bool, S_IRUGO
);
1484 MODULE_PARM_DESC(fw_monitor
,
1485 "firmware monitor - to debug FW (default: false - needs lots of memory)");