30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/kernel.h>
33 #include <linux/module.h>
35 #include <linux/slab.h>
37 #include <linux/sched.h>
39 #include <linux/netdevice.h>
41 #include <linux/if_arp.h>
45 #include <asm/div64.h>
70 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
72 #ifdef CONFIG_IWLWIFI_DEBUG
78 #define DRV_VERSION IWLWIFI_VERSION VD
111 tim_idx = mgmt->
u.beacon.variable - beacon;
114 while ((tim_idx < (frame_size - 2)) &&
116 tim_idx += beacon[tim_idx+1] + 2;
119 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] ==
WLAN_EID_TIM)) {
121 tx_beacon_cmd->
tim_size = beacon[tim_idx+1];
123 IWL_WARN(priv,
"Unable to find TIM Element in beacon\n");
146 IWL_ERR(priv,
"trying to build beacon w/o beacon context!\n");
164 tx_beacon_cmd->
tx.sta_id = priv->
beacon_ctx->bcast_sta_id;
170 iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->
beacon_skb->data,
181 if (info->
control.rates[0].idx < 0 ||
185 rate = info->
control.rates[0].idx;
189 rate_flags = iwl_ant_idx_to_flags(priv->
mgmt_tx_ant);
197 tx_beacon_cmd->
tx.rate_n_flags =
198 iwl_hw_set_rate_n_flags(rate, rate_flags);
201 cmd.
len[0] =
sizeof(*tx_beacon_cmd);
202 cmd.
data[0] = tx_beacon_cmd;
204 cmd.
len[1] = frame_size;
219 IWL_ERR(priv,
"updating beacon w/o beacon context!\n");
234 beacon = ieee80211_beacon_get(priv->
hw, priv->
beacon_ctx->vif);
236 IWL_ERR(priv,
"update beacon failed -- keeping old\n");
250 static void iwl_bg_bt_runtime_config(
struct work_struct *work)
259 if (!iwl_is_ready_rf(priv))
264 static void iwl_bg_bt_full_concurrency(
struct work_struct *work)
276 if (!iwl_is_ready_rf(priv))
281 "full concurrency" :
"3-wire");
326 static void iwl_bg_statistics_periodic(
unsigned long data)
334 if (!iwl_is_ready_rf(priv))
341 static void iwl_print_cont_event_trace(
struct iwl_priv *priv,
u32 base,
342 u32 start_idx,
u32 num_events,
348 unsigned long reg_flags;
351 ptr = base + (4 *
sizeof(
u32)) + (start_idx * 2 *
sizeof(
u32));
353 ptr = base + (4 *
sizeof(
u32)) + (start_idx * 3 *
sizeof(
u32));
358 spin_unlock_irqrestore(&priv->
trans->reg_lock, reg_flags);
378 for (
i = 0;
i < num_events;
i++) {
382 trace_iwlwifi_dev_ucode_cont_event(
386 trace_iwlwifi_dev_ucode_cont_event(
392 spin_unlock_irqrestore(&priv->
trans->reg_lock, reg_flags);
395 static void iwl_continuous_event_trace(
struct iwl_priv *priv)
412 capacity = read.capacity;
414 num_wraps = read.wrap_counter;
415 next_entry = read.write_counter;
424 if (
unlikely(next_entry == capacity))
434 if (
unlikely(next_entry < priv->event_log.next_entry &&
438 if (num_wraps == priv->
event_log.num_wraps) {
439 iwl_print_cont_event_trace(
446 if (num_wraps - priv->
event_log.num_wraps > 1)
451 trace_iwlwifi_dev_ucode_wrap_event(priv->
trans->dev,
455 if (next_entry < priv->event_log.next_entry) {
456 iwl_print_cont_event_trace(
461 iwl_print_cont_event_trace(
462 priv, base, 0, next_entry, capacity, mode);
464 iwl_print_cont_event_trace(
465 priv, base, next_entry,
466 capacity - next_entry,
469 iwl_print_cont_event_trace(
470 priv, base, 0, next_entry, capacity, mode);
486 static void iwl_bg_ucode_trace(
unsigned long data)
494 iwl_continuous_event_trace(priv);
501 static void iwl_bg_tx_flush(
struct work_struct *work)
510 if (!iwl_is_ready_rf(priv))
521 static const u8 iwlagn_bss_ac_to_fifo[] = {
528 static const u8 iwlagn_bss_ac_to_queue[] = {
532 static const u8 iwlagn_pan_ac_to_fifo[] = {
539 static const u8 iwlagn_pan_ac_to_queue[] = {
543 static void iwl_init_context(
struct iwl_priv *priv,
u32 ucode_flags)
576 iwlagn_bss_ac_to_queue,
sizeof(iwlagn_bss_ac_to_queue));
578 iwlagn_bss_ac_to_fifo,
sizeof(iwlagn_bss_ac_to_fifo));
602 iwlagn_pan_ac_to_queue,
sizeof(iwlagn_pan_ac_to_queue));
604 iwlagn_pan_ac_to_fifo,
sizeof(iwlagn_pan_ac_to_fifo));
610 static void iwl_rf_kill_ct_config(
struct iwl_priv *priv)
621 if (priv->
cfg->base_params->support_ct_kill_exit) {
622 adv_cmd.critical_temperature_enter =
624 adv_cmd.critical_temperature_exit =
629 CMD_SYNC,
sizeof(adv_cmd), &adv_cmd);
631 IWL_ERR(priv,
"REPLY_CT_KILL_CONFIG_CMD failed\n");
634 "succeeded, critical temperature enter is %d,"
639 cmd.critical_temperature_R =
646 IWL_ERR(priv,
"REPLY_CT_KILL_CONFIG_CMD failed\n");
650 "critical temperature is %d\n",
655 static int iwlagn_send_calib_cfg_rt(
struct iwl_priv *priv,
u32 cfg)
661 .data = { &calib_cfg_cmd, },
664 memset(&calib_cfg_cmd, 0,
sizeof(calib_cfg_cmd));
666 calib_cfg_cmd.ucd_calib_cfg.once.start =
cpu_to_le32(cfg);
672 static int iwlagn_send_tx_ant_config(
struct iwl_priv *priv,
u8 valid_tx_ant)
679 IWL_DEBUG_HC(priv,
"select valid tx ant: %u\n", valid_tx_ant);
686 IWL_DEBUG_HC(priv,
"TX_ANT_CONFIGURATION_CMD not supported\n");
691 static void iwl_send_bt_config(
struct iwl_priv *priv)
711 IWL_ERR(priv,
"failed to send BT Coex Config\n");
729 if (iwl_is_rfkill(priv))
738 if (priv->
cfg->bt_params &&
739 priv->
cfg->bt_params->advanced_bt_coexist) {
741 if (priv->
cfg->bt_params->bt_sco_disable)
768 iwl_send_bt_config(priv);
779 iwlagn_send_tx_ant_config(priv, priv->
eeprom_data->valid_tx_ant);
781 if (iwl_is_associated_ctx(ctx) && !priv->
wowlan) {
809 iwl_rf_kill_ct_config(priv);
825 static void iwl_clear_driver_stations(
struct iwl_priv *priv)
873 iwl_clear_driver_stations(priv);
879 if (priv->
cfg->bt_params)
881 priv->
cfg->bt_params->bt_init_traffic_load;
896 iwl_trans_stop_device(priv->
trans);
919 static void iwl_bg_run_time_calib_work(
struct work_struct *work)
986 static void iwl_bg_restart(
struct work_struct *data)
1002 "Cannot request restart before registrating with mac80211");
1033 static void iwlagn_disable_roc_work(
struct work_struct *work)
1049 static void iwl_setup_deferred_work(
struct iwl_priv *priv)
1060 iwlagn_disable_roc_work);
1064 if (priv->
cfg->bt_params)
1078 if (priv->
cfg->bt_params)
1094 static int iwl_init_drv(
struct iwl_priv *priv)
1105 priv->
cfg->base_params->plcp_delta_threshold;
1122 if (priv->
cfg->bt_params &&
1123 priv->
cfg->bt_params->advanced_bt_coexist) {
1135 static void iwl_uninit_drv(
struct iwl_priv *priv)
1141 #ifdef CONFIG_IWLWIFI_DEBUGFS
1142 kfree(priv->wowlan_sram);
1146 static void iwl_set_hw_params(
struct iwl_priv *priv)
1148 if (priv->
cfg->ht_params)
1149 priv->
hw_params.use_rts_for_aggregation =
1150 priv->
cfg->ht_params->use_rts_for_aggregation;
1153 priv->
lib->set_hw_params(priv);
1159 static void iwl_option_config(
struct iwl_priv *priv)
1161 #ifdef CONFIG_IWLWIFI_DEBUG
1162 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEBUG enabled\n");
1164 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEBUG disabled\n");
1167 #ifdef CONFIG_IWLWIFI_DEBUGFS
1168 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEBUGFS enabled\n");
1170 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEBUGFS disabled\n");
1173 #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
1174 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
1176 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
1179 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
1180 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEVICE_TESTMODE enabled\n");
1182 IWL_INFO(priv,
"CONFIG_IWLWIFI_DEVICE_TESTMODE disabled\n");
1185 #ifdef CONFIG_IWLWIFI_P2P
1186 IWL_INFO(priv,
"CONFIG_IWLWIFI_P2P enabled\n");
1188 IWL_INFO(priv,
"CONFIG_IWLWIFI_P2P disabled\n");
1192 static int iwl_eeprom_init_hw_params(
struct iwl_priv *priv)
1199 !priv->
cfg->ht_params) {
1200 IWL_ERR(priv,
"Invalid 11n configuration\n");
1205 IWL_ERR(priv,
"Invalid device sku\n");
1215 if (priv->
cfg->rx_with_siso_diversity)
1221 IWL_INFO(priv,
"Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
1231 struct dentry *dbgfs_dir)
1253 pr_err(
"%s: Cannot allocate network device\n", cfg->
name);
1258 op_mode->
ops = &iwl_dvm_ops;
1265 switch (priv->
cfg->device_family) {
1307 trans_cfg.n_no_reclaim_cmds =
ARRAY_SIZE(no_reclaim_cmds);
1310 trans_cfg.queue_watchdog_timeout =
1311 priv->
cfg->base_params->wd_timeout;
1318 priv->
cfg->base_params->num_of_queues);
1322 #ifndef CONFIG_IWLWIFI_P2P
1326 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
1335 iwl_trans_configure(priv->
trans, &trans_cfg);
1339 SET_IEEE80211_DEV(priv->
hw, priv->
trans->dev);
1341 iwl_option_config(priv);
1364 IWL_INFO(priv,
"Detected %s, REV=0x%X\n",
1365 priv->
cfg->name, priv->
trans->hw_rev);
1367 if (iwl_trans_start_hw(priv->
trans))
1373 IWL_ERR(priv,
"Unable to init EEPROM\n");
1378 iwl_trans_stop_hw(priv->
trans,
false);
1384 goto out_free_eeprom_blob;
1387 goto out_free_eeprom;
1389 if (iwl_eeprom_init_hw_params(priv))
1390 goto out_free_eeprom;
1396 priv->
hw->wiphy->n_addresses = 1;
1402 priv->
hw->wiphy->n_addresses++;
1408 iwl_set_hw_params(priv);
1412 ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
1422 iwl_trans_configure(priv->
trans, &trans_cfg);
1437 if (iwl_init_drv(priv))
1438 goto out_free_eeprom;
1445 iwl_setup_deferred_work(priv);
1453 sizeof(priv->
hw->wiphy->fw_version),
1460 fw->
ucode_capa.standard_phy_calibration_size;
1462 fw->
ucode_capa.standard_phy_calibration_size + 1;
1465 iwl_init_context(priv, ucode_flags);
1473 goto out_destroy_workqueue;
1476 goto out_mac80211_unregister;
1480 out_mac80211_unregister:
1482 out_destroy_workqueue:
1488 iwl_uninit_drv(priv);
1489 out_free_eeprom_blob:
1500 static void iwl_op_mode_dvm_stop(
struct iwl_op_mode *op_mode)
1513 iwl_trans_stop_device(priv->
trans);
1527 iwl_uninit_drv(priv);
1531 iwl_trans_stop_hw(priv->
trans,
true);
1535 static const char *
const desc_lookup_text[] = {
1540 "NMI_INTERRUPT_WDG",
1544 "HW_ERROR_TUNE_LOCK",
1545 "HW_ERROR_TEMPERATURE",
1546 "ILLEGAL_CHAN_FREQ",
1549 "NMI_INTERRUPT_HOST",
1550 "NMI_INTERRUPT_ACTION_PT",
1551 "NMI_INTERRUPT_UNKNOWN",
1552 "UCODE_VERSION_MISMATCH",
1553 "HW_ERROR_ABS_LOCK",
1554 "HW_ERROR_CAL_LOCK_FAIL",
1555 "NMI_INTERRUPT_INST_ACTION_PT",
1556 "NMI_INTERRUPT_DATA_ACTION_PT",
1558 "NMI_INTERRUPT_TRM",
1559 "NMI_INTERRUPT_BREAK_POINT",
1567 {
"NMI_INTERRUPT_WDG", 0x34 },
1568 {
"SYSASSERT", 0x35 },
1569 {
"UCODE_VERSION_MISMATCH", 0x37 },
1570 {
"BAD_COMMAND", 0x38 },
1571 {
"NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1572 {
"FATAL_ERROR", 0x3D },
1573 {
"NMI_TRM_HW_ERR", 0x46 },
1574 {
"NMI_INTERRUPT_TRM", 0x4C },
1575 {
"NMI_INTERRUPT_BREAK_POINT", 0x54 },
1576 {
"NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1577 {
"NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1578 {
"NMI_INTERRUPT_HOST", 0x66 },
1579 {
"NMI_INTERRUPT_ACTION_PT", 0x7C },
1580 {
"NMI_INTERRUPT_UNKNOWN", 0x84 },
1581 {
"NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1582 {
"ADVANCED_SYSASSERT", 0 },
1585 static const char *desc_lookup(
u32 num)
1591 return desc_lookup_text[num];
1594 for (i = 0; i <
max; i++) {
1595 if (advanced_lookup[i].num == num)
1598 return advanced_lookup[
i].name;
1601 #define ERROR_START_OFFSET (1 * sizeof(u32))
1602 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1604 static void iwl_dump_nic_error_log(
struct iwl_priv *priv)
1613 base = priv->
fw->init_errlog_ptr;
1616 base = priv->
fw->inst_errlog_ptr;
1621 "Not valid error log pointer 0x%08X for %s uCode\n",
1632 IWL_ERR(trans,
"Start IWL Error Log Dump:\n");
1633 IWL_ERR(trans,
"Status: 0x%08lX, count: %d\n",
1645 IWL_ERR(priv,
"0x%08X | uPc\n", table.
pc);
1656 IWL_ERR(priv,
"0x%08X | time gp1\n", table.
gp1);
1657 IWL_ERR(priv,
"0x%08X | time gp2\n", table.
gp2);
1658 IWL_ERR(priv,
"0x%08X | time gp3\n", table.
gp3);
1679 #define EVENT_START_OFFSET (4 * sizeof(u32))
1685 static int iwl_print_event_log(
struct iwl_priv *priv,
u32 start_idx,
1686 u32 num_events,
u32 mode,
1687 int pos,
char **
buf,
size_t bufsz)
1694 unsigned long reg_flags;
1698 if (num_events == 0)
1704 base = priv->
fw->init_evtlog_ptr;
1707 base = priv->
fw->inst_evtlog_ptr;
1711 event_size = 2 *
sizeof(
u32);
1713 event_size = 3 *
sizeof(
u32);
1727 for (i = 0; i < num_events; i++) {
1733 pos +=
scnprintf(*buf + pos, bufsz - pos,
1734 "EVT_LOG:0x%08x:%04u\n",
1737 trace_iwlwifi_dev_ucode_event(trans->
dev, 0,
1739 IWL_ERR(priv,
"EVT_LOG:0x%08x:%04u\n",
1745 pos +=
scnprintf(*buf + pos, bufsz - pos,
1746 "EVT_LOGT:%010u:0x%08x:%04u\n",
1749 IWL_ERR(priv,
"EVT_LOGT:%010u:0x%08x:%04u\n",
1751 trace_iwlwifi_dev_ucode_event(trans->
dev, time,
1760 spin_unlock_irqrestore(&trans->
reg_lock, reg_flags);
1767 static int iwl_print_last_event_logs(
struct iwl_priv *priv,
u32 capacity,
1768 u32 num_wraps,
u32 next_entry,
1770 int pos,
char **
buf,
size_t bufsz)
1777 if (next_entry < size) {
1778 pos = iwl_print_event_log(priv,
1779 capacity - (size - next_entry),
1780 size - next_entry, mode,
1782 pos = iwl_print_event_log(priv, 0,
1786 pos = iwl_print_event_log(priv, next_entry - size,
1787 size, mode, pos, buf, bufsz);
1789 if (next_entry < size) {
1790 pos = iwl_print_event_log(priv, 0, next_entry,
1791 mode, pos, buf, bufsz);
1793 pos = iwl_print_event_log(priv, next_entry - size,
1794 size, mode, pos, buf, bufsz);
1800 #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1818 logsize = priv->
fw->init_evtlog_size;
1820 base = priv->
fw->init_evtlog_ptr;
1822 logsize = priv->
fw->inst_evtlog_size;
1824 base = priv->
fw->inst_evtlog_ptr;
1829 "Invalid event log pointer 0x%08X for %s uCode\n",
1842 if (capacity > logsize) {
1843 IWL_ERR(priv,
"Log capacity %d is bogus, limit to %d "
1844 "entries\n", capacity, logsize);
1848 if (next_entry > logsize) {
1849 IWL_ERR(priv,
"Log write index %d is bogus, limit to %d\n",
1850 next_entry, logsize);
1851 next_entry = logsize;
1854 size = num_wraps ? capacity : next_entry;
1858 IWL_ERR(trans,
"Start IWL Event Log Dump: nothing in log\n");
1862 #ifdef CONFIG_IWLWIFI_DEBUG
1870 IWL_ERR(priv,
"Start IWL Event Log Dump: display last %u entries\n",
1873 #ifdef CONFIG_IWLWIFI_DEBUG
1876 bufsz = capacity * 48;
1890 pos = iwl_print_event_log(priv, next_entry,
1891 capacity - next_entry, mode,
1894 pos = iwl_print_event_log(priv, 0,
1895 next_entry, mode, pos, buf, bufsz);
1897 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1898 next_entry, size, mode,
1901 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1902 next_entry, size, mode,
1908 static void iwlagn_fw_error(
struct iwl_priv *priv,
bool ondemand)
1910 unsigned int reload_msec;
1911 unsigned long reload_jiffies;
1913 #ifdef CONFIG_IWLWIFI_DEBUG
1914 if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
1946 IWL_ERR(priv,
"BUG_ON, Stop restarting\n");
1956 "Restarting adapter due to uCode error.\n");
1960 "Detected FW error, but not restarting\n");
1964 static void iwl_nic_error(
struct iwl_op_mode *op_mode)
1968 IWL_ERR(priv,
"Loaded firmware version: %s\n",
1969 priv->
fw->fw_version);
1971 iwl_dump_nic_error_log(priv);
1974 iwlagn_fw_error(priv,
false);
1977 static void iwl_cmd_queue_full(
struct iwl_op_mode *op_mode)
1982 IWL_ERR(priv,
"Restarting adapter queue is full\n");
1983 iwlagn_fw_error(priv,
false);
1987 #define EEPROM_RF_CONFIG_TYPE_MAX 0x3
1989 static void iwl_nic_config(
struct iwl_op_mode *op_mode)
2018 IWL_INFO(priv,
"Radio type=0x%x-0x%x-0x%x\n",
2039 if (priv->
lib->nic_config)
2040 priv->
lib->nic_config(priv);
2043 static void iwl_wimax_active(
struct iwl_op_mode *op_mode)
2048 IWL_ERR(priv,
"RF is used by WiMAX\n");
2061 "queue %d (mac80211 %d) already stopped\n",
2070 static void iwl_wake_sw_queue(
struct iwl_op_mode *op_mode,
int queue)
2080 "queue %d (mac80211 %d) already awake\n",
2115 info = IEEE80211_SKB_CB(skb);
2120 static void iwl_set_hw_rfkill_state(
struct iwl_op_mode *op_mode,
bool state)
2133 .start = iwl_op_mode_dvm_start,
2134 .stop = iwl_op_mode_dvm_stop,
2136 .queue_full = iwl_stop_sw_queue,
2137 .queue_not_full = iwl_wake_sw_queue,
2138 .hw_rf_kill = iwl_set_hw_rfkill_state,
2139 .free_skb = iwl_free_skb,
2140 .nic_error = iwl_nic_error,
2141 .cmd_queue_full = iwl_cmd_queue_full,
2142 .nic_config = iwl_nic_config,
2143 .wimax_active = iwl_wimax_active,
2151 static int __init iwl_init(
void)
2160 pr_err(
"Unable to register rate control algorithm: %d\n", ret);
2166 pr_err(
"Unable to register op_mode: %d\n", ret);
2174 static void __exit iwl_exit(
void)