66 #include <linux/module.h>
90 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
92 #ifdef CONFIG_IWLWIFI_DEBUG
98 #define DRV_VERSION IWLWIFI_VERSION VD
105 #ifdef CONFIG_IWLWIFI_DEBUGFS
106 static struct dentry *iwl_dbgfs_root;
135 #ifdef CONFIG_IWLWIFI_DEBUGFS
137 struct dentry *dbgfs_trans;
138 struct dentry *dbgfs_op_mode;
142 #define DVM_OP_MODE 0
143 #define MVM_OP_MODE 1
146 static struct mutex iwlwifi_opmode_table_mtx;
147 static struct iwlwifi_opmode_table {
151 } iwlwifi_opmode_table[] = {
152 { .name =
"iwldvm", .ops =
NULL },
153 { .name =
"iwlmvm", .ops =
NULL },
173 static void iwl_free_fw_img(
struct iwl_drv *drv,
struct fw_img *img)
177 iwl_free_fw_desc(drv, &img->
sec[i]);
180 static void iwl_dealloc_ucode(
struct iwl_drv *drv)
184 iwl_free_fw_img(drv, drv->
fw.img + i);
194 if (!sec || !sec->
size)
209 static void iwl_req_fw_callback(
const struct firmware *ucode_raw,
212 #define UCODE_EXPERIMENTAL_INDEX 100
213 #define UCODE_EXPERIMENTAL_TAG "exp"
215 static int iwl_request_firmware(
struct iwl_drv *drv,
bool first)
217 const char *name_pre = drv->
cfg->fw_name_pre;
221 #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
234 IWL_ERR(drv,
"no suitable firmware found!\n");
242 ?
"EXPERIMENTAL " :
"",
251 struct fw_sec sec[IWL_UCODE_SECTION_MAX];
334 if (
WARN_ON(!pieces || !data || type >= IWL_UCODE_TYPE_MAX))
351 static int iwl_set_default_calib(
struct iwl_drv *drv,
const u8 *data)
356 if (ucode_type >= IWL_UCODE_TYPE_MAX) {
357 IWL_ERR(drv,
"Wrong ucode_type %u for default calibration.\n",
365 static int iwl_parse_v1_v2_firmware(
struct iwl_drv *drv,
381 IWL_ERR(drv,
"File size too small!\n");
400 IWL_ERR(drv,
"File size too small!\n");
424 sizeof(drv->
fw.fw_version),
441 "uCode file size %d does not match expected size\n",
442 (
int)ucode_raw->
size);
466 static int iwl_parse_tlv_firmware(
struct iwl_drv *drv,
473 size_t len = ucode_raw->
size;
481 if (len <
sizeof(*ucode)) {
482 IWL_ERR(drv,
"uCode has invalid length: %zd\n", len);
487 IWL_ERR(drv,
"invalid uCode magic: 0X%x\n",
503 sizeof(drv->
fw.fw_version),
513 len -=
sizeof(*ucode);
515 while (len >=
sizeof(*
tlv)) {
521 tlv_data =
tlv->data;
524 IWL_ERR(drv,
"invalid TLV len: %zd/%u\n",
569 IWL_ERR(drv,
"Found unexpected BOOT ucode\n");
573 goto invalid_tlv_len;
579 goto invalid_tlv_len;
585 goto invalid_tlv_len;
588 goto invalid_tlv_len;
600 goto invalid_tlv_len;
606 goto invalid_tlv_len;
612 goto invalid_tlv_len;
618 goto invalid_tlv_len;
624 goto invalid_tlv_len;
630 goto invalid_tlv_len;
636 goto invalid_tlv_len;
637 drv->
fw.enhance_sensitivity_table =
true;
659 goto invalid_tlv_len;
666 drv->
fw.mvm_fw =
true;
671 drv->
fw.mvm_fw =
true;
676 drv->
fw.mvm_fw =
true;
680 goto invalid_tlv_len;
681 if (iwl_set_default_calib(drv, tlv_data))
686 goto invalid_tlv_len;
696 IWL_ERR(drv,
"invalid TLV after parsing: %zd\n", len);
711 static int iwl_alloc_ucode(
struct iwl_drv *drv,
717 i < IWL_UCODE_SECTION_MAX && get_sec_size(pieces, type, i);
719 if (iwl_alloc_fw_desc(drv, &(drv->
fw.img[type].sec[i]),
720 get_sec(pieces, type, i)))
725 static int validate_sec_sizes(
struct iwl_drv *drv,
743 IWL_ERR(drv,
"uCode instr len %Zd too large to fit in\n",
751 IWL_ERR(drv,
"uCode data len %Zd too large to fit in\n",
759 IWL_ERR(drv,
"uCode init instr len %Zd too large to fit in\n",
767 IWL_ERR(drv,
"uCode init data len %Zd too large to fit in\n",
776 _iwl_op_mode_start(
struct iwl_drv *drv,
struct iwlwifi_opmode_table *
op)
782 #ifdef CONFIG_IWLWIFI_DEBUGFS
785 if (!drv->dbgfs_op_mode) {
787 "failed to create opmode debugfs directory\n");
790 dbgfs_dir = drv->dbgfs_op_mode;
795 #ifdef CONFIG_IWLWIFI_DEBUGFS
798 drv->dbgfs_op_mode =
NULL;
805 static void _iwl_op_mode_stop(
struct iwl_drv *drv)
809 iwl_op_mode_stop(drv->
op_mode);
812 #ifdef CONFIG_IWLWIFI_DEBUGFS
814 drv->dbgfs_op_mode =
NULL;
825 static void iwl_req_fw_callback(
const struct firmware *ucode_raw,
void *
context)
830 struct iwlwifi_opmode_table *
op;
833 const unsigned int api_max = drv->
cfg->ucode_api_max;
834 unsigned int api_ok = drv->
cfg->ucode_api_ok;
835 const unsigned int api_min = drv->
cfg->ucode_api_min;
838 bool load_module =
false;
841 fw->
ucode_capa.standard_phy_calibration_size =
847 memset(&pieces, 0,
sizeof(pieces));
852 "request for firmware file '%s' failed.\n",
861 if (ucode_raw->
size < 4) {
862 IWL_ERR(drv,
"File size way too small!\n");
870 err = iwl_parse_v1_v2_firmware(drv, ucode_raw, &pieces);
872 err = iwl_parse_tlv_firmware(drv, ucode_raw, &pieces,
887 if (api_ver < api_min || api_ver > api_max) {
889 "Driver unable to support your firmware API. "
890 "Driver supports v%u, firmware is v%u.\n",
895 if (api_ver < api_ok) {
896 if (api_ok != api_max)
897 IWL_ERR(drv,
"Firmware has old API version, "
898 "expected v%u through v%u, got v%u.\n",
899 api_ok, api_max, api_ver);
901 IWL_ERR(drv,
"Firmware has old API version, "
902 "expected v%u, got v%u.\n",
904 IWL_ERR(drv,
"New firmware can be obtained from "
905 "http://www.intellinuxwireless.org/.\n");
909 IWL_INFO(drv,
"loaded firmware version %s", drv->
fw.fw_version);
915 if (!fw->
mvm_fw && validate_sec_sizes(drv, &pieces, drv->
cfg))
924 if (iwl_alloc_ucode(drv, &pieces, i))
939 drv->
cfg->base_params->max_event_log_size;
946 drv->
cfg->base_params->max_event_log_size;
953 if (fw->
ucode_capa.standard_phy_calibration_size >
955 fw->
ucode_capa.standard_phy_calibration_size =
968 drv->
op_mode = _iwl_op_mode_start(drv, op);
992 request_module(
"%s", op->name);
998 if (iwl_request_firmware(drv,
false))
1003 IWL_ERR(drv,
"failed to allocate pci memory\n");
1004 iwl_dealloc_ucode(drv);
1026 INIT_LIST_HEAD(&drv->
list);
1028 #ifdef CONFIG_IWLWIFI_DEBUGFS
1033 if (!drv->dbgfs_drv) {
1034 IWL_ERR(drv,
"failed to create debugfs directory\n");
1041 if (!drv->
trans->dbgfs_dir) {
1042 IWL_ERR(drv,
"failed to create transport debugfs directory\n");
1043 goto err_free_dbgfs;
1047 ret = iwl_request_firmware(drv,
true);
1050 IWL_ERR(trans,
"Couldn't request the fw\n");
1057 #ifdef CONFIG_IWLWIFI_DEBUGFS
1072 _iwl_op_mode_stop(drv);
1074 iwl_dealloc_ucode(drv);
1082 if (!list_empty(&drv->
list))
1086 #ifdef CONFIG_IWLWIFI_DEBUGFS
1099 .bt_coex_active =
true,
1101 .bt_ch_announce =
true,
1112 struct iwlwifi_opmode_table *
op;
1115 for (i = 0; i <
ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1116 op = &iwlwifi_opmode_table[
i];
1117 if (
strcmp(op->name, name))
1122 drv->
op_mode = _iwl_op_mode_start(drv, op);
1138 for (i = 0; i <
ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1139 if (
strcmp(iwlwifi_opmode_table[i].name, name))
1141 iwlwifi_opmode_table[
i].ops =
NULL;
1145 _iwl_op_mode_stop(drv);
1154 static int __init iwl_drv_init(
void)
1160 for (i = 0; i <
ARRAY_SIZE(iwlwifi_opmode_table); i++)
1161 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1166 #ifdef CONFIG_IWLWIFI_DEBUGFS
1170 if (!iwl_dbgfs_root)
1178 static void __exit iwl_drv_exit(
void)
1182 #ifdef CONFIG_IWLWIFI_DEBUGFS
1188 #ifdef CONFIG_IWLWIFI_DEBUG
1195 MODULE_PARM_DESC(swcrypto,
"using crypto in software (default 0 [hardware])");
1198 "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
1208 "specify antenna coupling in dB (defualt: 0 dB)");
1213 "Enable BT channel inhibition (default: enable)");
1220 "Disable stuck queue watchdog timer 0=system default, "
1221 "1=disable, 2=enable (default: 0)");
1241 MODULE_PARM_DESC(bt_coex_active,
"enable wifi/bt co-exist (default: enable)");
1245 "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
1250 "enable WiFi power management (default: disable)");
1255 "default power save level (range from 1 - 5, default: 1)");
1260 "enable agg w/o check traffic load (default: enable)");
1264 MODULE_PARM_DESC(5ghz_disable,
"disable 5GHz band (default: 0 [enabled])");