aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi')
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig10
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c21
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c42
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tt.c696
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tt.h129
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tx.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c141
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h48
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c154
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h29
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h20
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.c638
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.h93
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c18
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c24
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c69
24 files changed, 1200 insertions, 992 deletions
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index a51e4da1bdfc..b82364258dc5 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -3,6 +3,9 @@ config IWLWIFI
3 depends on PCI && MAC80211 3 depends on PCI && MAC80211
4 select FW_LOADER 4 select FW_LOADER
5 5
6menu "Debugging Options"
7 depends on IWLWIFI
8
6config IWLWIFI_DEBUG 9config IWLWIFI_DEBUG
7 bool "Enable full debugging output in iwlagn and iwl3945 drivers" 10 bool "Enable full debugging output in iwlagn and iwl3945 drivers"
8 depends on IWLWIFI 11 depends on IWLWIFI
@@ -36,6 +39,12 @@ config IWLWIFI_DEBUGFS
36 is a low-impact option that allows getting insight into the 39 is a low-impact option that allows getting insight into the
37 driver's state at runtime. 40 driver's state at runtime.
38 41
42config IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
43 bool "Experimental uCode support"
44 depends on IWLWIFI && IWLWIFI_DEBUG
45 ---help---
46 Enable use of experimental ucode for testing and debugging.
47
39config IWLWIFI_DEVICE_TRACING 48config IWLWIFI_DEVICE_TRACING
40 bool "iwlwifi device access tracing" 49 bool "iwlwifi device access tracing"
41 depends on IWLWIFI 50 depends on IWLWIFI
@@ -53,6 +62,7 @@ config IWLWIFI_DEVICE_TRACING
53 62
54 If unsure, say Y so we can help you better when problems 63 If unsure, say Y so we can help you better when problems
55 occur. 64 occur.
65endmenu
56 66
57config IWLAGN 67config IWLAGN
58 tristate "Intel Wireless WiFi Next Gen AGN (iwlagn)" 68 tristate "Intel Wireless WiFi Next Gen AGN (iwlagn)"
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index 728bb858ba97..493163925a45 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_IWLAGN) += iwlagn.o
12iwlagn-objs := iwl-agn.o iwl-agn-rs.o iwl-agn-led.o iwl-agn-ict.o 12iwlagn-objs := iwl-agn.o iwl-agn-rs.o iwl-agn-led.o iwl-agn-ict.o
13iwlagn-objs += iwl-agn-ucode.o iwl-agn-hcmd.o iwl-agn-tx.o 13iwlagn-objs += iwl-agn-ucode.o iwl-agn-hcmd.o iwl-agn-tx.o
14iwlagn-objs += iwl-agn-lib.o iwl-agn-rx.o iwl-agn-calib.o 14iwlagn-objs += iwl-agn-lib.o iwl-agn-rx.o iwl-agn-calib.o
15iwlagn-objs += iwl-agn-tt.o
15iwlagn-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-agn-debugfs.o 16iwlagn-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-agn-debugfs.o
16 17
17iwlagn-$(CONFIG_IWL4965) += iwl-4965.o 18iwlagn-$(CONFIG_IWL4965) += iwl-4965.o
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 0b779a41a142..3bf5a30828be 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -229,6 +229,11 @@ static struct iwl_lib_ops iwl1000_lib = {
229 .check_ack_health = iwl_good_ack_health, 229 .check_ack_health = iwl_good_ack_health,
230 .txfifo_flush = iwlagn_txfifo_flush, 230 .txfifo_flush = iwlagn_txfifo_flush,
231 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 231 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
232 .tt_ops = {
233 .lower_power_detection = iwl_tt_is_low_power_state,
234 .tt_power_mode = iwl_tt_current_power_mode,
235 .ct_kill_check = iwl_check_for_ct_kill,
236 }
232}; 237};
233 238
234static const struct iwl_ops iwl1000_ops = { 239static const struct iwl_ops iwl1000_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index d92b72909233..f0a47f42d4b8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -1470,7 +1470,7 @@ static int iwl4965_hw_channel_switch(struct iwl_priv *priv,
1470 1470
1471 cmd.band = band; 1471 cmd.band = band;
1472 cmd.expect_beacon = 0; 1472 cmd.expect_beacon = 0;
1473 ch = ieee80211_frequency_to_channel(ch_switch->channel->center_freq); 1473 ch = ch_switch->channel->hw_value;
1474 cmd.channel = cpu_to_le16(ch); 1474 cmd.channel = cpu_to_le16(ch);
1475 cmd.rxon_flags = priv->staging_rxon.flags; 1475 cmd.rxon_flags = priv->staging_rxon.flags;
1476 cmd.rxon_filter_flags = priv->staging_rxon.filter_flags; 1476 cmd.rxon_filter_flags = priv->staging_rxon.filter_flags;
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 48bdcd8d2e94..013f3dae69f1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -291,7 +291,7 @@ static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
291 }; 291 };
292 292
293 cmd.band = priv->band == IEEE80211_BAND_2GHZ; 293 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
294 ch = ieee80211_frequency_to_channel(ch_switch->channel->center_freq); 294 ch = ch_switch->channel->hw_value;
295 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n", 295 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
296 priv->active_rxon.channel, ch); 296 priv->active_rxon.channel, ch);
297 cmd.channel = cpu_to_le16(ch); 297 cmd.channel = cpu_to_le16(ch);
@@ -405,6 +405,11 @@ static struct iwl_lib_ops iwl5000_lib = {
405 .check_ack_health = iwl_good_ack_health, 405 .check_ack_health = iwl_good_ack_health,
406 .txfifo_flush = iwlagn_txfifo_flush, 406 .txfifo_flush = iwlagn_txfifo_flush,
407 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 407 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
408 .tt_ops = {
409 .lower_power_detection = iwl_tt_is_low_power_state,
410 .tt_power_mode = iwl_tt_current_power_mode,
411 .ct_kill_check = iwl_check_for_ct_kill,
412 }
408}; 413};
409 414
410static struct iwl_lib_ops iwl5150_lib = { 415static struct iwl_lib_ops iwl5150_lib = {
@@ -470,6 +475,11 @@ static struct iwl_lib_ops iwl5150_lib = {
470 .check_ack_health = iwl_good_ack_health, 475 .check_ack_health = iwl_good_ack_health,
471 .txfifo_flush = iwlagn_txfifo_flush, 476 .txfifo_flush = iwlagn_txfifo_flush,
472 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 477 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
478 .tt_ops = {
479 .lower_power_detection = iwl_tt_is_low_power_state,
480 .tt_power_mode = iwl_tt_current_power_mode,
481 .ct_kill_check = iwl_check_for_ct_kill,
482 }
473}; 483};
474 484
475static const struct iwl_ops iwl5000_ops = { 485static const struct iwl_ops iwl5000_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index cee06b968de8..9e390f698641 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -214,7 +214,7 @@ static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
214 }; 214 };
215 215
216 cmd.band = priv->band == IEEE80211_BAND_2GHZ; 216 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
217 ch = ieee80211_frequency_to_channel(ch_switch->channel->center_freq); 217 ch = ch_switch->channel->hw_value;
218 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n", 218 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
219 priv->active_rxon.channel, ch); 219 priv->active_rxon.channel, ch);
220 cmd.channel = cpu_to_le16(ch); 220 cmd.channel = cpu_to_le16(ch);
@@ -330,6 +330,11 @@ static struct iwl_lib_ops iwl6000_lib = {
330 .check_ack_health = iwl_good_ack_health, 330 .check_ack_health = iwl_good_ack_health,
331 .txfifo_flush = iwlagn_txfifo_flush, 331 .txfifo_flush = iwlagn_txfifo_flush,
332 .dev_txfifo_flush = iwlagn_dev_txfifo_flush, 332 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
333 .tt_ops = {
334 .lower_power_detection = iwl_tt_is_low_power_state,
335 .tt_power_mode = iwl_tt_current_power_mode,
336 .ct_kill_check = iwl_check_for_ct_kill,
337 }
333}; 338};
334 339
335static const struct iwl_ops iwl6000_ops = { 340static const struct iwl_ops iwl6000_ops = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
index 75b901b3eb1e..84939763d178 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
@@ -235,13 +235,13 @@ static int iwlagn_calc_rssi(struct iwl_priv *priv,
235 /* data from PHY/DSP regarding signal strength, etc., 235 /* data from PHY/DSP regarding signal strength, etc.,
236 * contents are always there, not configurable by host 236 * contents are always there, not configurable by host
237 */ 237 */
238 struct iwl5000_non_cfg_phy *ncphy = 238 struct iwlagn_non_cfg_phy *ncphy =
239 (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf; 239 (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
240 u32 val, rssi_a, rssi_b, rssi_c, max_rssi; 240 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
241 u8 agc; 241 u8 agc;
242 242
243 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]); 243 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]);
244 agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS; 244 agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS;
245 245
246 /* Find max rssi among 3 possible receivers. 246 /* Find max rssi among 3 possible receivers.
247 * These values are measured by the digital signal processor (DSP). 247 * These values are measured by the digital signal processor (DSP).
@@ -249,11 +249,14 @@ static int iwlagn_calc_rssi(struct iwl_priv *priv,
249 * if the radio's automatic gain control (AGC) is working right. 249 * if the radio's automatic gain control (AGC) is working right.
250 * AGC value (see below) will provide the "interesting" info. 250 * AGC value (see below) will provide the "interesting" info.
251 */ 251 */
252 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]); 252 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]);
253 rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS; 253 rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >>
254 rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS; 254 IWLAGN_OFDM_RSSI_A_BIT_POS;
255 val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]); 255 rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >>
256 rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS; 256 IWLAGN_OFDM_RSSI_B_BIT_POS;
257 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]);
258 rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >>
259 IWLAGN_OFDM_RSSI_C_BIT_POS;
257 260
258 max_rssi = max_t(u32, rssi_a, rssi_b); 261 max_rssi = max_t(u32, rssi_a, rssi_b);
259 max_rssi = max_t(u32, max_rssi, rssi_c); 262 max_rssi = max_t(u32, max_rssi, rssi_c);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index 9dd9e64c2b0b..eedd71f5506b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -1098,7 +1098,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
1098 if (chan->band != band) 1098 if (chan->band != band)
1099 continue; 1099 continue;
1100 1100
1101 channel = ieee80211_frequency_to_channel(chan->center_freq); 1101 channel = chan->hw_value;
1102 scan_ch->channel = cpu_to_le16(channel); 1102 scan_ch->channel = cpu_to_le16(channel);
1103 1103
1104 ch_info = iwl_get_channel_info(priv, band, channel); 1104 ch_info = iwl_get_channel_info(priv, band, channel);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 23e5c42e7d7e..a4563389bad0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -82,6 +82,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
82 struct iwl_lq_sta *lq_sta); 82 struct iwl_lq_sta *lq_sta);
83static void rs_fill_link_cmd(struct iwl_priv *priv, 83static void rs_fill_link_cmd(struct iwl_priv *priv,
84 struct iwl_lq_sta *lq_sta, u32 rate_n_flags); 84 struct iwl_lq_sta *lq_sta, u32 rate_n_flags);
85static void rs_stay_in_table(struct iwl_lq_sta *lq_sta);
85 86
86 87
87#ifdef CONFIG_MAC80211_DEBUGFS 88#ifdef CONFIG_MAC80211_DEBUGFS
@@ -502,6 +503,7 @@ static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
502 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags); 503 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
503 u8 mcs; 504 u8 mcs;
504 505
506 memset(tbl, 0, sizeof(struct iwl_scale_tbl_info));
505 *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags); 507 *rate_idx = iwl_hwrate_to_plcp_idx(rate_n_flags);
506 508
507 if (*rate_idx == IWL_RATE_INVALID) { 509 if (*rate_idx == IWL_RATE_INVALID) {
@@ -848,7 +850,20 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
848 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); 850 other_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
849 } else { 851 } else {
850 IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n"); 852 IWL_DEBUG_RATE(priv, "Neither active nor search matches tx rate\n");
851 return; 853 tmp_tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
854 IWL_DEBUG_RATE(priv, "active- lq:%x, ant:%x, SGI:%d\n",
855 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
856 tmp_tbl = &(lq_sta->lq_info[1 - lq_sta->active_tbl]);
857 IWL_DEBUG_RATE(priv, "search- lq:%x, ant:%x, SGI:%d\n",
858 tmp_tbl->lq_type, tmp_tbl->ant_type, tmp_tbl->is_SGI);
859 IWL_DEBUG_RATE(priv, "actual- lq:%x, ant:%x, SGI:%d\n",
860 tbl_type.lq_type, tbl_type.ant_type, tbl_type.is_SGI);
861 /*
862 * no matching table found, let's by-pass the data collection
863 * and continue to perform rate scale to find the rate table
864 */
865 rs_stay_in_table(lq_sta);
866 goto done;
852 } 867 }
853 868
854 /* 869 /*
@@ -909,7 +924,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
909 } 924 }
910 /* The last TX rate is cached in lq_sta; it's set in if/else above */ 925 /* The last TX rate is cached in lq_sta; it's set in if/else above */
911 lq_sta->last_rate_n_flags = tx_rate; 926 lq_sta->last_rate_n_flags = tx_rate;
912 927done:
913 /* See if there's a better rate or modulation mode to try. */ 928 /* See if there's a better rate or modulation mode to try. */
914 if (sta && sta->supp_rates[sband->band]) 929 if (sta && sta->supp_rates[sband->band])
915 rs_rate_scale_perform(priv, skb, sta, lq_sta); 930 rs_rate_scale_perform(priv, skb, sta, lq_sta);
@@ -1265,7 +1280,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1265 struct iwl_rate_scale_data *window = &(tbl->win[index]); 1280 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1266 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1281 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1267 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1282 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1268 u8 start_action = tbl->action; 1283 u8 start_action;
1269 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1284 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1270 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1285 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1271 int ret = 0; 1286 int ret = 0;
@@ -1277,6 +1292,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1277 else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE && 1292 else if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_SINGLE &&
1278 tbl->action > IWL_LEGACY_SWITCH_SISO) 1293 tbl->action > IWL_LEGACY_SWITCH_SISO)
1279 tbl->action = IWL_LEGACY_SWITCH_SISO; 1294 tbl->action = IWL_LEGACY_SWITCH_SISO;
1295 start_action = tbl->action;
1280 for (; ;) { 1296 for (; ;) {
1281 lq_sta->action_counter++; 1297 lq_sta->action_counter++;
1282 switch (tbl->action) { 1298 switch (tbl->action) {
@@ -1403,7 +1419,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1403 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; 1419 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1404 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1420 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1405 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1421 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1406 u8 start_action = tbl->action; 1422 u8 start_action;
1407 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1423 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1408 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1424 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1409 u8 update_search_tbl_counter = 0; 1425 u8 update_search_tbl_counter = 0;
@@ -1414,6 +1430,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1414 /* stay in SISO */ 1430 /* stay in SISO */
1415 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1431 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1416 } 1432 }
1433 start_action = tbl->action;
1417 for (;;) { 1434 for (;;) {
1418 lq_sta->action_counter++; 1435 lq_sta->action_counter++;
1419 switch (tbl->action) { 1436 switch (tbl->action) {
@@ -1541,7 +1558,7 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
1541 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; 1558 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1542 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1559 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1543 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1560 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1544 u8 start_action = tbl->action; 1561 u8 start_action;
1545 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1562 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1546 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1563 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1547 u8 update_search_tbl_counter = 0; 1564 u8 update_search_tbl_counter = 0;
@@ -1553,6 +1570,7 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
1553 /* switch in SISO */ 1570 /* switch in SISO */
1554 tbl->action = IWL_MIMO2_SWITCH_SISO_A; 1571 tbl->action = IWL_MIMO2_SWITCH_SISO_A;
1555 } 1572 }
1573 start_action = tbl->action;
1556 for (;;) { 1574 for (;;) {
1557 lq_sta->action_counter++; 1575 lq_sta->action_counter++;
1558 switch (tbl->action) { 1576 switch (tbl->action) {
@@ -1682,7 +1700,7 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1682 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; 1700 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1683 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1701 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1684 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1702 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1685 u8 start_action = tbl->action; 1703 u8 start_action;
1686 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1704 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1687 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1705 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1688 int ret; 1706 int ret;
@@ -1694,6 +1712,7 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1694 /* switch in SISO */ 1712 /* switch in SISO */
1695 tbl->action = IWL_MIMO3_SWITCH_SISO_A; 1713 tbl->action = IWL_MIMO3_SWITCH_SISO_A;
1696 } 1714 }
1715 start_action = tbl->action;
1697 for (;;) { 1716 for (;;) {
1698 lq_sta->action_counter++; 1717 lq_sta->action_counter++;
1699 switch (tbl->action) { 1718 switch (tbl->action) {
@@ -2594,7 +2613,6 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
2594 rs_dbgfs_set_mcs(lq_sta, &new_rate, index); 2613 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2595 2614
2596 /* Interpret new_rate (rate_n_flags) */ 2615 /* Interpret new_rate (rate_n_flags) */
2597 memset(&tbl_type, 0, sizeof(tbl_type));
2598 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, 2616 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
2599 &tbl_type, &rate_idx); 2617 &tbl_type, &rate_idx);
2600 2618
@@ -2694,8 +2712,18 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
2694 2712
2695 lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF; 2713 lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2696 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; 2714 lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
2715
2697 lq_cmd->agg_params.agg_time_limit = 2716 lq_cmd->agg_params.agg_time_limit =
2698 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); 2717 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
2718 /*
2719 * overwrite if needed, pass aggregation time limit
2720 * to uCode in uSec
2721 */
2722 if (priv && priv->cfg->agg_time_limit &&
2723 priv->cfg->agg_time_limit >= LINK_QUAL_AGG_TIME_LIMIT_MIN &&
2724 priv->cfg->agg_time_limit <= LINK_QUAL_AGG_TIME_LIMIT_MAX)
2725 lq_cmd->agg_params.agg_time_limit =
2726 cpu_to_le16(priv->cfg->agg_time_limit);
2699} 2727}
2700 2728
2701static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) 2729static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
new file mode 100644
index 000000000000..30298ea56a24
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
@@ -0,0 +1,696 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/slab.h>
33#include <linux/init.h>
34
35#include <net/mac80211.h>
36
37#include "iwl-eeprom.h"
38#include "iwl-dev.h"
39#include "iwl-core.h"
40#include "iwl-io.h"
41#include "iwl-commands.h"
42#include "iwl-debug.h"
43#include "iwl-agn-tt.h"
44
45/* default Thermal Throttling transaction table
46 * Current state | Throttling Down | Throttling Up
47 *=============================================================================
48 * Condition Nxt State Condition Nxt State Condition Nxt State
49 *-----------------------------------------------------------------------------
50 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
51 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
52 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
53 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
54 *=============================================================================
55 */
56static const struct iwl_tt_trans tt_range_0[IWL_TI_STATE_MAX - 1] = {
57 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 104},
58 {IWL_TI_1, 105, CT_KILL_THRESHOLD - 1},
59 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
60};
61static const struct iwl_tt_trans tt_range_1[IWL_TI_STATE_MAX - 1] = {
62 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 95},
63 {IWL_TI_2, 110, CT_KILL_THRESHOLD - 1},
64 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
65};
66static const struct iwl_tt_trans tt_range_2[IWL_TI_STATE_MAX - 1] = {
67 {IWL_TI_1, IWL_ABSOLUTE_ZERO, 100},
68 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX},
69 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
70};
71static const struct iwl_tt_trans tt_range_3[IWL_TI_STATE_MAX - 1] = {
72 {IWL_TI_0, IWL_ABSOLUTE_ZERO, CT_KILL_EXIT_THRESHOLD},
73 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX},
74 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX}
75};
76
77/* Advance Thermal Throttling default restriction table */
78static const struct iwl_tt_restriction restriction_range[IWL_TI_STATE_MAX] = {
79 {IWL_ANT_OK_MULTI, IWL_ANT_OK_MULTI, true },
80 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_MULTI, true },
81 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_SINGLE, false },
82 {IWL_ANT_OK_NONE, IWL_ANT_OK_NONE, false }
83};
84
85bool iwl_tt_is_low_power_state(struct iwl_priv *priv)
86{
87 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
88
89 if (tt->state >= IWL_TI_1)
90 return true;
91 return false;
92}
93
94u8 iwl_tt_current_power_mode(struct iwl_priv *priv)
95{
96 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
97
98 return tt->tt_power_mode;
99}
100
101bool iwl_ht_enabled(struct iwl_priv *priv)
102{
103 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
104 struct iwl_tt_restriction *restriction;
105
106 if (!priv->thermal_throttle.advanced_tt)
107 return true;
108 restriction = tt->restriction + tt->state;
109 return restriction->is_ht;
110}
111
112static bool iwl_within_ct_kill_margin(struct iwl_priv *priv)
113{
114 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
115 bool within_margin = false;
116
117 if (priv->cfg->temperature_kelvin)
118 temp = KELVIN_TO_CELSIUS(priv->temperature);
119
120 if (!priv->thermal_throttle.advanced_tt)
121 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
122 CT_KILL_THRESHOLD_LEGACY) ? true : false;
123 else
124 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
125 CT_KILL_THRESHOLD) ? true : false;
126 return within_margin;
127}
128
129bool iwl_check_for_ct_kill(struct iwl_priv *priv)
130{
131 bool is_ct_kill = false;
132
133 if (iwl_within_ct_kill_margin(priv)) {
134 iwl_tt_enter_ct_kill(priv);
135 is_ct_kill = true;
136 }
137 return is_ct_kill;
138}
139
140enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv)
141{
142 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
143 struct iwl_tt_restriction *restriction;
144
145 if (!priv->thermal_throttle.advanced_tt)
146 return IWL_ANT_OK_MULTI;
147 restriction = tt->restriction + tt->state;
148 return restriction->tx_stream;
149}
150
151enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv)
152{
153 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
154 struct iwl_tt_restriction *restriction;
155
156 if (!priv->thermal_throttle.advanced_tt)
157 return IWL_ANT_OK_MULTI;
158 restriction = tt->restriction + tt->state;
159 return restriction->rx_stream;
160}
161
162#define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */
163#define CT_KILL_WAITING_DURATION (300) /* 300ms duration */
164
165/*
166 * toggle the bit to wake up uCode and check the temperature
167 * if the temperature is below CT, uCode will stay awake and send card
168 * state notification with CT_KILL bit clear to inform Thermal Throttling
169 * Management to change state. Otherwise, uCode will go back to sleep
170 * without doing anything, driver should continue the 5 seconds timer
171 * to wake up uCode for temperature check until temperature drop below CT
172 */
173static void iwl_tt_check_exit_ct_kill(unsigned long data)
174{
175 struct iwl_priv *priv = (struct iwl_priv *)data;
176 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
177 unsigned long flags;
178
179 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
180 return;
181
182 if (tt->state == IWL_TI_CT_KILL) {
183 if (priv->thermal_throttle.ct_kill_toggle) {
184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
185 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
186 priv->thermal_throttle.ct_kill_toggle = false;
187 } else {
188 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
189 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
190 priv->thermal_throttle.ct_kill_toggle = true;
191 }
192 iwl_read32(priv, CSR_UCODE_DRV_GP1);
193 spin_lock_irqsave(&priv->reg_lock, flags);
194 if (!iwl_grab_nic_access(priv))
195 iwl_release_nic_access(priv);
196 spin_unlock_irqrestore(&priv->reg_lock, flags);
197
198 /* Reschedule the ct_kill timer to occur in
199 * CT_KILL_EXIT_DURATION seconds to ensure we get a
200 * thermal update */
201 IWL_DEBUG_POWER(priv, "schedule ct_kill exit timer\n");
202 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm,
203 jiffies + CT_KILL_EXIT_DURATION * HZ);
204 }
205}
206
207static void iwl_perform_ct_kill_task(struct iwl_priv *priv,
208 bool stop)
209{
210 if (stop) {
211 IWL_DEBUG_POWER(priv, "Stop all queues\n");
212 if (priv->mac80211_registered)
213 ieee80211_stop_queues(priv->hw);
214 IWL_DEBUG_POWER(priv,
215 "Schedule 5 seconds CT_KILL Timer\n");
216 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm,
217 jiffies + CT_KILL_EXIT_DURATION * HZ);
218 } else {
219 IWL_DEBUG_POWER(priv, "Wake all queues\n");
220 if (priv->mac80211_registered)
221 ieee80211_wake_queues(priv->hw);
222 }
223}
224
225static void iwl_tt_ready_for_ct_kill(unsigned long data)
226{
227 struct iwl_priv *priv = (struct iwl_priv *)data;
228 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
229
230 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
231 return;
232
233 /* temperature timer expired, ready to go into CT_KILL state */
234 if (tt->state != IWL_TI_CT_KILL) {
235 IWL_DEBUG_POWER(priv, "entering CT_KILL state when "
236 "temperature timer expired\n");
237 tt->state = IWL_TI_CT_KILL;
238 set_bit(STATUS_CT_KILL, &priv->status);
239 iwl_perform_ct_kill_task(priv, true);
240 }
241}
242
243static void iwl_prepare_ct_kill_task(struct iwl_priv *priv)
244{
245 IWL_DEBUG_POWER(priv, "Prepare to enter IWL_TI_CT_KILL\n");
246 /* make request to retrieve statistics information */
247 iwl_send_statistics_request(priv, CMD_SYNC, false);
248 /* Reschedule the ct_kill wait timer */
249 mod_timer(&priv->thermal_throttle.ct_kill_waiting_tm,
250 jiffies + msecs_to_jiffies(CT_KILL_WAITING_DURATION));
251}
252
253#define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY)
254#define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100)
255#define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90)
256
257/*
258 * Legacy thermal throttling
259 * 1) Avoid NIC destruction due to high temperatures
260 * Chip will identify dangerously high temperatures that can
261 * harm the device and will power down
262 * 2) Avoid the NIC power down due to high temperature
263 * Throttle early enough to lower the power consumption before
264 * drastic steps are needed
265 */
266static void iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
267{
268 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
269 enum iwl_tt_state old_state;
270
271#ifdef CONFIG_IWLWIFI_DEBUG
272 if ((tt->tt_previous_temp) &&
273 (temp > tt->tt_previous_temp) &&
274 ((temp - tt->tt_previous_temp) >
275 IWL_TT_INCREASE_MARGIN)) {
276 IWL_DEBUG_POWER(priv,
277 "Temperature increase %d degree Celsius\n",
278 (temp - tt->tt_previous_temp));
279 }
280#endif
281 old_state = tt->state;
282 /* in Celsius */
283 if (temp >= IWL_MINIMAL_POWER_THRESHOLD)
284 tt->state = IWL_TI_CT_KILL;
285 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_2)
286 tt->state = IWL_TI_2;
287 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_1)
288 tt->state = IWL_TI_1;
289 else
290 tt->state = IWL_TI_0;
291
292#ifdef CONFIG_IWLWIFI_DEBUG
293 tt->tt_previous_temp = temp;
294#endif
295 /* stop ct_kill_waiting_tm timer */
296 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
297 if (tt->state != old_state) {
298 switch (tt->state) {
299 case IWL_TI_0:
300 /*
301 * When the system is ready to go back to IWL_TI_0
302 * we only have to call iwl_power_update_mode() to
303 * do so.
304 */
305 break;
306 case IWL_TI_1:
307 tt->tt_power_mode = IWL_POWER_INDEX_3;
308 break;
309 case IWL_TI_2:
310 tt->tt_power_mode = IWL_POWER_INDEX_4;
311 break;
312 default:
313 tt->tt_power_mode = IWL_POWER_INDEX_5;
314 break;
315 }
316 mutex_lock(&priv->mutex);
317 if (old_state == IWL_TI_CT_KILL)
318 clear_bit(STATUS_CT_KILL, &priv->status);
319 if (tt->state != IWL_TI_CT_KILL &&
320 iwl_power_update_mode(priv, true)) {
321 /* TT state not updated
322 * try again during next temperature read
323 */
324 if (old_state == IWL_TI_CT_KILL)
325 set_bit(STATUS_CT_KILL, &priv->status);
326 tt->state = old_state;
327 IWL_ERR(priv, "Cannot update power mode, "
328 "TT state not updated\n");
329 } else {
330 if (tt->state == IWL_TI_CT_KILL) {
331 if (force) {
332 set_bit(STATUS_CT_KILL, &priv->status);
333 iwl_perform_ct_kill_task(priv, true);
334 } else {
335 iwl_prepare_ct_kill_task(priv);
336 tt->state = old_state;
337 }
338 } else if (old_state == IWL_TI_CT_KILL &&
339 tt->state != IWL_TI_CT_KILL)
340 iwl_perform_ct_kill_task(priv, false);
341 IWL_DEBUG_POWER(priv, "Temperature state changed %u\n",
342 tt->state);
343 IWL_DEBUG_POWER(priv, "Power Index change to %u\n",
344 tt->tt_power_mode);
345 }
346 mutex_unlock(&priv->mutex);
347 }
348}
349
350/*
351 * Advance thermal throttling
352 * 1) Avoid NIC destruction due to high temperatures
353 * Chip will identify dangerously high temperatures that can
354 * harm the device and will power down
355 * 2) Avoid the NIC power down due to high temperature
356 * Throttle early enough to lower the power consumption before
357 * drastic steps are needed
358 * Actions include relaxing the power down sleep thresholds and
359 * decreasing the number of TX streams
360 * 3) Avoid throughput performance impact as much as possible
361 *
362 *=============================================================================
363 * Condition Nxt State Condition Nxt State Condition Nxt State
364 *-----------------------------------------------------------------------------
365 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
366 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
367 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
368 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
369 *=============================================================================
370 */
371static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
372{
373 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
374 int i;
375 bool changed = false;
376 enum iwl_tt_state old_state;
377 struct iwl_tt_trans *transaction;
378
379 old_state = tt->state;
380 for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) {
381 /* based on the current TT state,
382 * find the curresponding transaction table
383 * each table has (IWL_TI_STATE_MAX - 1) entries
384 * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1))
385 * will advance to the correct table.
386 * then based on the current temperature
387 * find the next state need to transaction to
388 * go through all the possible (IWL_TI_STATE_MAX - 1) entries
389 * in the current table to see if transaction is needed
390 */
391 transaction = tt->transaction +
392 ((old_state * (IWL_TI_STATE_MAX - 1)) + i);
393 if (temp >= transaction->tt_low &&
394 temp <= transaction->tt_high) {
395#ifdef CONFIG_IWLWIFI_DEBUG
396 if ((tt->tt_previous_temp) &&
397 (temp > tt->tt_previous_temp) &&
398 ((temp - tt->tt_previous_temp) >
399 IWL_TT_INCREASE_MARGIN)) {
400 IWL_DEBUG_POWER(priv,
401 "Temperature increase %d "
402 "degree Celsius\n",
403 (temp - tt->tt_previous_temp));
404 }
405 tt->tt_previous_temp = temp;
406#endif
407 if (old_state !=
408 transaction->next_state) {
409 changed = true;
410 tt->state =
411 transaction->next_state;
412 }
413 break;
414 }
415 }
416 /* stop ct_kill_waiting_tm timer */
417 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
418 if (changed) {
419 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
420
421 if (tt->state >= IWL_TI_1) {
422 /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */
423 tt->tt_power_mode = IWL_POWER_INDEX_5;
424 if (!iwl_ht_enabled(priv))
425 /* disable HT */
426 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
427 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
428 RXON_FLG_HT40_PROT_MSK |
429 RXON_FLG_HT_PROT_MSK);
430 else {
431 /* check HT capability and set
432 * according to the system HT capability
433 * in case get disabled before */
434 iwl_set_rxon_ht(priv, &priv->current_ht_config);
435 }
436
437 } else {
438 /*
439 * restore system power setting -- it will be
440 * recalculated automatically.
441 */
442
443 /* check HT capability and set
444 * according to the system HT capability
445 * in case get disabled before */
446 iwl_set_rxon_ht(priv, &priv->current_ht_config);
447 }
448 mutex_lock(&priv->mutex);
449 if (old_state == IWL_TI_CT_KILL)
450 clear_bit(STATUS_CT_KILL, &priv->status);
451 if (tt->state != IWL_TI_CT_KILL &&
452 iwl_power_update_mode(priv, true)) {
453 /* TT state not updated
454 * try again during next temperature read
455 */
456 IWL_ERR(priv, "Cannot update power mode, "
457 "TT state not updated\n");
458 if (old_state == IWL_TI_CT_KILL)
459 set_bit(STATUS_CT_KILL, &priv->status);
460 tt->state = old_state;
461 } else {
462 IWL_DEBUG_POWER(priv,
463 "Thermal Throttling to new state: %u\n",
464 tt->state);
465 if (old_state != IWL_TI_CT_KILL &&
466 tt->state == IWL_TI_CT_KILL) {
467 if (force) {
468 IWL_DEBUG_POWER(priv,
469 "Enter IWL_TI_CT_KILL\n");
470 set_bit(STATUS_CT_KILL, &priv->status);
471 iwl_perform_ct_kill_task(priv, true);
472 } else {
473 iwl_prepare_ct_kill_task(priv);
474 tt->state = old_state;
475 }
476 } else if (old_state == IWL_TI_CT_KILL &&
477 tt->state != IWL_TI_CT_KILL) {
478 IWL_DEBUG_POWER(priv, "Exit IWL_TI_CT_KILL\n");
479 iwl_perform_ct_kill_task(priv, false);
480 }
481 }
482 mutex_unlock(&priv->mutex);
483 }
484}
485
486/* Card State Notification indicated reach critical temperature
487 * if PSP not enable, no Thermal Throttling function will be performed
488 * just set the GP1 bit to acknowledge the event
489 * otherwise, go into IWL_TI_CT_KILL state
490 * since Card State Notification will not provide any temperature reading
491 * for Legacy mode
492 * so just pass the CT_KILL temperature to iwl_legacy_tt_handler()
493 * for advance mode
494 * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state
495 */
496static void iwl_bg_ct_enter(struct work_struct *work)
497{
498 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter);
499 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
500
501 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
502 return;
503
504 if (!iwl_is_ready(priv))
505 return;
506
507 if (tt->state != IWL_TI_CT_KILL) {
508 IWL_ERR(priv, "Device reached critical temperature "
509 "- ucode going to sleep!\n");
510 if (!priv->thermal_throttle.advanced_tt)
511 iwl_legacy_tt_handler(priv,
512 IWL_MINIMAL_POWER_THRESHOLD,
513 true);
514 else
515 iwl_advance_tt_handler(priv,
516 CT_KILL_THRESHOLD + 1, true);
517 }
518}
519
520/* Card State Notification indicated out of critical temperature
521 * since Card State Notification will not provide any temperature reading
522 * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature
523 * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state
524 */
525static void iwl_bg_ct_exit(struct work_struct *work)
526{
527 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit);
528 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
529
530 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
531 return;
532
533 if (!iwl_is_ready(priv))
534 return;
535
536 /* stop ct_kill_exit_tm timer */
537 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
538
539 if (tt->state == IWL_TI_CT_KILL) {
540 IWL_ERR(priv,
541 "Device temperature below critical"
542 "- ucode awake!\n");
543 /*
544 * exit from CT_KILL state
545 * reset the current temperature reading
546 */
547 priv->temperature = 0;
548 if (!priv->thermal_throttle.advanced_tt)
549 iwl_legacy_tt_handler(priv,
550 IWL_REDUCED_PERFORMANCE_THRESHOLD_2,
551 true);
552 else
553 iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD,
554 true);
555 }
556}
557
558void iwl_tt_enter_ct_kill(struct iwl_priv *priv)
559{
560 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
561 return;
562
563 IWL_DEBUG_POWER(priv, "Queueing critical temperature enter.\n");
564 queue_work(priv->workqueue, &priv->ct_enter);
565}
566EXPORT_SYMBOL(iwl_tt_enter_ct_kill);
567
568void iwl_tt_exit_ct_kill(struct iwl_priv *priv)
569{
570 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
571 return;
572
573 IWL_DEBUG_POWER(priv, "Queueing critical temperature exit.\n");
574 queue_work(priv->workqueue, &priv->ct_exit);
575}
576EXPORT_SYMBOL(iwl_tt_exit_ct_kill);
577
578static void iwl_bg_tt_work(struct work_struct *work)
579{
580 struct iwl_priv *priv = container_of(work, struct iwl_priv, tt_work);
581 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
582
583 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
584 return;
585
586 if (priv->cfg->temperature_kelvin)
587 temp = KELVIN_TO_CELSIUS(priv->temperature);
588
589 if (!priv->thermal_throttle.advanced_tt)
590 iwl_legacy_tt_handler(priv, temp, false);
591 else
592 iwl_advance_tt_handler(priv, temp, false);
593}
594
595void iwl_tt_handler(struct iwl_priv *priv)
596{
597 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
598 return;
599
600 IWL_DEBUG_POWER(priv, "Queueing thermal throttling work.\n");
601 queue_work(priv->workqueue, &priv->tt_work);
602}
603EXPORT_SYMBOL(iwl_tt_handler);
604
605/* Thermal throttling initialization
606 * For advance thermal throttling:
607 * Initialize Thermal Index and temperature threshold table
608 * Initialize thermal throttling restriction table
609 */
610void iwl_tt_initialize(struct iwl_priv *priv)
611{
612 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
613 int size = sizeof(struct iwl_tt_trans) * (IWL_TI_STATE_MAX - 1);
614 struct iwl_tt_trans *transaction;
615
616 IWL_DEBUG_POWER(priv, "Initialize Thermal Throttling\n");
617
618 memset(tt, 0, sizeof(struct iwl_tt_mgmt));
619
620 tt->state = IWL_TI_0;
621 init_timer(&priv->thermal_throttle.ct_kill_exit_tm);
622 priv->thermal_throttle.ct_kill_exit_tm.data = (unsigned long)priv;
623 priv->thermal_throttle.ct_kill_exit_tm.function =
624 iwl_tt_check_exit_ct_kill;
625 init_timer(&priv->thermal_throttle.ct_kill_waiting_tm);
626 priv->thermal_throttle.ct_kill_waiting_tm.data =
627 (unsigned long)priv;
628 priv->thermal_throttle.ct_kill_waiting_tm.function =
629 iwl_tt_ready_for_ct_kill;
630 /* setup deferred ct kill work */
631 INIT_WORK(&priv->tt_work, iwl_bg_tt_work);
632 INIT_WORK(&priv->ct_enter, iwl_bg_ct_enter);
633 INIT_WORK(&priv->ct_exit, iwl_bg_ct_exit);
634
635 if (priv->cfg->adv_thermal_throttle) {
636 IWL_DEBUG_POWER(priv, "Advanced Thermal Throttling\n");
637 tt->restriction = kzalloc(sizeof(struct iwl_tt_restriction) *
638 IWL_TI_STATE_MAX, GFP_KERNEL);
639 tt->transaction = kzalloc(sizeof(struct iwl_tt_trans) *
640 IWL_TI_STATE_MAX * (IWL_TI_STATE_MAX - 1),
641 GFP_KERNEL);
642 if (!tt->restriction || !tt->transaction) {
643 IWL_ERR(priv, "Fallback to Legacy Throttling\n");
644 priv->thermal_throttle.advanced_tt = false;
645 kfree(tt->restriction);
646 tt->restriction = NULL;
647 kfree(tt->transaction);
648 tt->transaction = NULL;
649 } else {
650 transaction = tt->transaction +
651 (IWL_TI_0 * (IWL_TI_STATE_MAX - 1));
652 memcpy(transaction, &tt_range_0[0], size);
653 transaction = tt->transaction +
654 (IWL_TI_1 * (IWL_TI_STATE_MAX - 1));
655 memcpy(transaction, &tt_range_1[0], size);
656 transaction = tt->transaction +
657 (IWL_TI_2 * (IWL_TI_STATE_MAX - 1));
658 memcpy(transaction, &tt_range_2[0], size);
659 transaction = tt->transaction +
660 (IWL_TI_CT_KILL * (IWL_TI_STATE_MAX - 1));
661 memcpy(transaction, &tt_range_3[0], size);
662 size = sizeof(struct iwl_tt_restriction) *
663 IWL_TI_STATE_MAX;
664 memcpy(tt->restriction,
665 &restriction_range[0], size);
666 priv->thermal_throttle.advanced_tt = true;
667 }
668 } else {
669 IWL_DEBUG_POWER(priv, "Legacy Thermal Throttling\n");
670 priv->thermal_throttle.advanced_tt = false;
671 }
672}
673EXPORT_SYMBOL(iwl_tt_initialize);
674
675/* cleanup thermal throttling management related memory and timer */
676void iwl_tt_exit(struct iwl_priv *priv)
677{
678 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
679
680 /* stop ct_kill_exit_tm timer if activated */
681 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
682 /* stop ct_kill_waiting_tm timer if activated */
683 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
684 cancel_work_sync(&priv->tt_work);
685 cancel_work_sync(&priv->ct_enter);
686 cancel_work_sync(&priv->ct_exit);
687
688 if (priv->thermal_throttle.advanced_tt) {
689 /* free advance thermal throttling memory */
690 kfree(tt->restriction);
691 tt->restriction = NULL;
692 kfree(tt->transaction);
693 tt->transaction = NULL;
694 }
695}
696EXPORT_SYMBOL(iwl_tt_exit);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.h b/drivers/net/wireless/iwlwifi/iwl-agn-tt.h
new file mode 100644
index 000000000000..d55060427cac
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tt.h
@@ -0,0 +1,129 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2010 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#ifndef __iwl_tt_setting_h__
29#define __iwl_tt_setting_h__
30
31#include "iwl-commands.h"
32
33#define IWL_ABSOLUTE_ZERO 0
34#define IWL_ABSOLUTE_MAX 0xFFFFFFFF
35#define IWL_TT_INCREASE_MARGIN 5
36#define IWL_TT_CT_KILL_MARGIN 3
37
38enum iwl_antenna_ok {
39 IWL_ANT_OK_NONE,
40 IWL_ANT_OK_SINGLE,
41 IWL_ANT_OK_MULTI,
42};
43
44/* Thermal Throttling State Machine states */
45enum iwl_tt_state {
46 IWL_TI_0, /* normal temperature, system power state */
47 IWL_TI_1, /* high temperature detect, low power state */
48 IWL_TI_2, /* higher temperature detected, lower power state */
49 IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */
50 IWL_TI_STATE_MAX
51};
52
53/**
54 * struct iwl_tt_restriction - Thermal Throttling restriction table
55 * @tx_stream: number of tx stream allowed
56 * @is_ht: ht enable/disable
57 * @rx_stream: number of rx stream allowed
58 *
59 * This table is used by advance thermal throttling management
60 * based on the current thermal throttling state, and determines
61 * the number of tx/rx streams and the status of HT operation.
62 */
63struct iwl_tt_restriction {
64 enum iwl_antenna_ok tx_stream;
65 enum iwl_antenna_ok rx_stream;
66 bool is_ht;
67};
68
69/**
70 * struct iwl_tt_trans - Thermal Throttling transaction table
71 * @next_state: next thermal throttling mode
72 * @tt_low: low temperature threshold to change state
73 * @tt_high: high temperature threshold to change state
74 *
75 * This is used by the advanced thermal throttling algorithm
76 * to determine the next thermal state to go based on the
77 * current temperature.
78 */
79struct iwl_tt_trans {
80 enum iwl_tt_state next_state;
81 u32 tt_low;
82 u32 tt_high;
83};
84
85/**
86 * struct iwl_tt_mgnt - Thermal Throttling Management structure
87 * @advanced_tt: advanced thermal throttle required
88 * @state: current Thermal Throttling state
89 * @tt_power_mode: Thermal Throttling power mode index
90 * being used to set power level when
91 * when thermal throttling state != IWL_TI_0
92 * the tt_power_mode should set to different
93 * power mode based on the current tt state
94 * @tt_previous_temperature: last measured temperature
95 * @iwl_tt_restriction: ptr to restriction tbl, used by advance
96 * thermal throttling to determine how many tx/rx streams
97 * should be used in tt state; and can HT be enabled or not
98 * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling
99 * state transaction
100 * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature
101 * @ct_kill_exit_tm: timer to exit thermal kill
102 */
103struct iwl_tt_mgmt {
104 enum iwl_tt_state state;
105 bool advanced_tt;
106 u8 tt_power_mode;
107 bool ct_kill_toggle;
108#ifdef CONFIG_IWLWIFI_DEBUG
109 s32 tt_previous_temp;
110#endif
111 struct iwl_tt_restriction *restriction;
112 struct iwl_tt_trans *transaction;
113 struct timer_list ct_kill_exit_tm;
114 struct timer_list ct_kill_waiting_tm;
115};
116
117u8 iwl_tt_current_power_mode(struct iwl_priv *priv);
118bool iwl_tt_is_low_power_state(struct iwl_priv *priv);
119bool iwl_ht_enabled(struct iwl_priv *priv);
120bool iwl_check_for_ct_kill(struct iwl_priv *priv);
121enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv);
122enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv);
123void iwl_tt_enter_ct_kill(struct iwl_priv *priv);
124void iwl_tt_exit_ct_kill(struct iwl_priv *priv);
125void iwl_tt_handler(struct iwl_priv *priv);
126void iwl_tt_initialize(struct iwl_priv *priv);
127void iwl_tt_exit(struct iwl_priv *priv);
128
129#endif /* __iwl_tt_setting_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
index 69155aa448fb..3fc982e87921 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
@@ -470,8 +470,8 @@ static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
470{ 470{
471 struct ieee80211_key_conf *keyconf = info->control.hw_key; 471 struct ieee80211_key_conf *keyconf = info->control.hw_key;
472 472
473 switch (keyconf->alg) { 473 switch (keyconf->cipher) {
474 case ALG_CCMP: 474 case WLAN_CIPHER_SUITE_CCMP:
475 tx_cmd->sec_ctl = TX_CMD_SEC_CCM; 475 tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
476 memcpy(tx_cmd->key, keyconf->key, keyconf->keylen); 476 memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
477 if (info->flags & IEEE80211_TX_CTL_AMPDU) 477 if (info->flags & IEEE80211_TX_CTL_AMPDU)
@@ -479,20 +479,20 @@ static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
479 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n"); 479 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
480 break; 480 break;
481 481
482 case ALG_TKIP: 482 case WLAN_CIPHER_SUITE_TKIP:
483 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; 483 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
484 ieee80211_get_tkip_key(keyconf, skb_frag, 484 ieee80211_get_tkip_key(keyconf, skb_frag,
485 IEEE80211_TKIP_P2_KEY, tx_cmd->key); 485 IEEE80211_TKIP_P2_KEY, tx_cmd->key);
486 IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n"); 486 IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
487 break; 487 break;
488 488
489 case ALG_WEP: 489 case WLAN_CIPHER_SUITE_WEP104:
490 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
491 /* fall through */
492 case WLAN_CIPHER_SUITE_WEP40:
490 tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP | 493 tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
491 (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); 494 (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
492 495
493 if (keyconf->keylen == WEP_KEY_LEN_128)
494 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
495
496 memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); 496 memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
497 497
498 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption " 498 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
@@ -500,7 +500,7 @@ static void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv,
500 break; 500 break;
501 501
502 default: 502 default:
503 IWL_ERR(priv, "Unknown encode alg %d\n", keyconf->alg); 503 IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher);
504 break; 504 break;
505 } 505 }
506} 506}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 10d7b9b7f064..3ced9ea9c5fe 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci-aspm.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
38#include <linux/delay.h> 39#include <linux/delay.h>
@@ -763,10 +764,10 @@ static void iwl_bg_ucode_trace(unsigned long data)
763static void iwl_rx_beacon_notif(struct iwl_priv *priv, 764static void iwl_rx_beacon_notif(struct iwl_priv *priv,
764 struct iwl_rx_mem_buffer *rxb) 765 struct iwl_rx_mem_buffer *rxb)
765{ 766{
766#ifdef CONFIG_IWLWIFI_DEBUG
767 struct iwl_rx_packet *pkt = rxb_addr(rxb); 767 struct iwl_rx_packet *pkt = rxb_addr(rxb);
768 struct iwl4965_beacon_notif *beacon = 768 struct iwl4965_beacon_notif *beacon =
769 (struct iwl4965_beacon_notif *)pkt->u.raw; 769 (struct iwl4965_beacon_notif *)pkt->u.raw;
770#ifdef CONFIG_IWLWIFI_DEBUG
770 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); 771 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
771 772
772 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d " 773 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
@@ -778,6 +779,8 @@ static void iwl_rx_beacon_notif(struct iwl_priv *priv,
778 le32_to_cpu(beacon->low_tsf), rate); 779 le32_to_cpu(beacon->low_tsf), rate);
779#endif 780#endif
780 781
782 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
783
781 if ((priv->iw_mode == NL80211_IFTYPE_AP) && 784 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
782 (!test_bit(STATUS_EXIT_PENDING, &priv->status))) 785 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
783 queue_work(priv->workqueue, &priv->beacon_update); 786 queue_work(priv->workqueue, &priv->beacon_update);
@@ -1656,24 +1659,37 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
1656static int iwl_mac_setup_register(struct iwl_priv *priv, 1659static int iwl_mac_setup_register(struct iwl_priv *priv,
1657 struct iwlagn_ucode_capabilities *capa); 1660 struct iwlagn_ucode_capabilities *capa);
1658 1661
1662#define UCODE_EXPERIMENTAL_INDEX 100
1663#define UCODE_EXPERIMENTAL_TAG "exp"
1664
1659static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first) 1665static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
1660{ 1666{
1661 const char *name_pre = priv->cfg->fw_name_pre; 1667 const char *name_pre = priv->cfg->fw_name_pre;
1668 char tag[8];
1662 1669
1663 if (first) 1670 if (first) {
1671#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
1672 priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
1673 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
1674 } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
1675#endif
1664 priv->fw_index = priv->cfg->ucode_api_max; 1676 priv->fw_index = priv->cfg->ucode_api_max;
1665 else 1677 sprintf(tag, "%d", priv->fw_index);
1678 } else {
1666 priv->fw_index--; 1679 priv->fw_index--;
1680 sprintf(tag, "%d", priv->fw_index);
1681 }
1667 1682
1668 if (priv->fw_index < priv->cfg->ucode_api_min) { 1683 if (priv->fw_index < priv->cfg->ucode_api_min) {
1669 IWL_ERR(priv, "no suitable firmware found!\n"); 1684 IWL_ERR(priv, "no suitable firmware found!\n");
1670 return -ENOENT; 1685 return -ENOENT;
1671 } 1686 }
1672 1687
1673 sprintf(priv->firmware_name, "%s%d%s", 1688 sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
1674 name_pre, priv->fw_index, ".ucode");
1675 1689
1676 IWL_DEBUG_INFO(priv, "attempting to load firmware '%s'\n", 1690 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
1691 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1692 ? "EXPERIMENTAL " : "",
1677 priv->firmware_name); 1693 priv->firmware_name);
1678 1694
1679 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name, 1695 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
@@ -1968,8 +1984,10 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
1968 memset(&pieces, 0, sizeof(pieces)); 1984 memset(&pieces, 0, sizeof(pieces));
1969 1985
1970 if (!ucode_raw) { 1986 if (!ucode_raw) {
1971 IWL_ERR(priv, "request for firmware file '%s' failed.\n", 1987 if (priv->fw_index <= priv->cfg->ucode_api_max)
1972 priv->firmware_name); 1988 IWL_ERR(priv,
1989 "request for firmware file '%s' failed.\n",
1990 priv->firmware_name);
1973 goto try_again; 1991 goto try_again;
1974 } 1992 }
1975 1993
@@ -2016,7 +2034,9 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
2016 api_max, api_ver); 2034 api_max, api_ver);
2017 2035
2018 if (build) 2036 if (build)
2019 sprintf(buildstr, " build %u", build); 2037 sprintf(buildstr, " build %u%s", build,
2038 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
2039 ? " (EXP)" : "");
2020 else 2040 else
2021 buildstr[0] = '\0'; 2041 buildstr[0] = '\0';
2022 2042
@@ -2589,6 +2609,52 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
2589 return pos; 2609 return pos;
2590} 2610}
2591 2611
2612static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2613{
2614 struct iwl_ct_kill_config cmd;
2615 struct iwl_ct_kill_throttling_config adv_cmd;
2616 unsigned long flags;
2617 int ret = 0;
2618
2619 spin_lock_irqsave(&priv->lock, flags);
2620 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2621 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2622 spin_unlock_irqrestore(&priv->lock, flags);
2623 priv->thermal_throttle.ct_kill_toggle = false;
2624
2625 if (priv->cfg->support_ct_kill_exit) {
2626 adv_cmd.critical_temperature_enter =
2627 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2628 adv_cmd.critical_temperature_exit =
2629 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2630
2631 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2632 sizeof(adv_cmd), &adv_cmd);
2633 if (ret)
2634 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2635 else
2636 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2637 "succeeded, "
2638 "critical temperature enter is %d,"
2639 "exit is %d\n",
2640 priv->hw_params.ct_kill_threshold,
2641 priv->hw_params.ct_kill_exit_threshold);
2642 } else {
2643 cmd.critical_temperature_R =
2644 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2645
2646 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2647 sizeof(cmd), &cmd);
2648 if (ret)
2649 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2650 else
2651 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2652 "succeeded, "
2653 "critical temperature is %d\n",
2654 priv->hw_params.ct_kill_threshold);
2655 }
2656}
2657
2592/** 2658/**
2593 * iwl_alive_start - called after REPLY_ALIVE notification received 2659 * iwl_alive_start - called after REPLY_ALIVE notification received
2594 * from protocol/runtime uCode (initialization uCode's 2660 * from protocol/runtime uCode (initialization uCode's
@@ -3060,9 +3126,7 @@ void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3060 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3126 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3061 iwlcore_commit_rxon(priv); 3127 iwlcore_commit_rxon(priv);
3062 3128
3063 iwl_setup_rxon_timing(priv, vif); 3129 ret = iwl_send_rxon_timing(priv, vif);
3064 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3065 sizeof(priv->rxon_timing), &priv->rxon_timing);
3066 if (ret) 3130 if (ret)
3067 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3131 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3068 "Attempting to continue.\n"); 3132 "Attempting to continue.\n");
@@ -3298,9 +3362,7 @@ void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
3298 iwlcore_commit_rxon(priv); 3362 iwlcore_commit_rxon(priv);
3299 3363
3300 /* RXON Timing */ 3364 /* RXON Timing */
3301 iwl_setup_rxon_timing(priv, vif); 3365 ret = iwl_send_rxon_timing(priv, vif);
3302 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3303 sizeof(priv->rxon_timing), &priv->rxon_timing);
3304 if (ret) 3366 if (ret)
3305 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3367 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3306 "Attempting to continue.\n"); 3368 "Attempting to continue.\n");
@@ -3386,7 +3448,9 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3386 * in 1X mode. 3448 * in 1X mode.
3387 * In legacy wep mode, we use another host command to the uCode. 3449 * In legacy wep mode, we use another host command to the uCode.
3388 */ 3450 */
3389 if (key->alg == ALG_WEP && !sta && vif->type != NL80211_IFTYPE_AP) { 3451 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3452 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
3453 !sta) {
3390 if (cmd == SET_KEY) 3454 if (cmd == SET_KEY)
3391 is_default_wep_key = !priv->key_mapping_key; 3455 is_default_wep_key = !priv->key_mapping_key;
3392 else 3456 else
@@ -3581,6 +3645,7 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3581 struct iwl_priv *priv = hw->priv; 3645 struct iwl_priv *priv = hw->priv;
3582 const struct iwl_channel_info *ch_info; 3646 const struct iwl_channel_info *ch_info;
3583 struct ieee80211_conf *conf = &hw->conf; 3647 struct ieee80211_conf *conf = &hw->conf;
3648 struct ieee80211_channel *channel = ch_switch->channel;
3584 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 3649 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
3585 u16 ch; 3650 u16 ch;
3586 unsigned long flags = 0; 3651 unsigned long flags = 0;
@@ -3604,11 +3669,10 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3604 mutex_lock(&priv->mutex); 3669 mutex_lock(&priv->mutex);
3605 if (priv->cfg->ops->lib->set_channel_switch) { 3670 if (priv->cfg->ops->lib->set_channel_switch) {
3606 3671
3607 ch = ieee80211_frequency_to_channel( 3672 ch = channel->hw_value;
3608 ch_switch->channel->center_freq);
3609 if (le16_to_cpu(priv->active_rxon.channel) != ch) { 3673 if (le16_to_cpu(priv->active_rxon.channel) != ch) {
3610 ch_info = iwl_get_channel_info(priv, 3674 ch_info = iwl_get_channel_info(priv,
3611 conf->channel->band, 3675 channel->band,
3612 ch); 3676 ch);
3613 if (!is_channel_valid(ch_info)) { 3677 if (!is_channel_valid(ch_info)) {
3614 IWL_DEBUG_MAC80211(priv, "invalid channel\n"); 3678 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
@@ -3637,15 +3701,12 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3637 } else 3701 } else
3638 ht_conf->is_40mhz = false; 3702 ht_conf->is_40mhz = false;
3639 3703
3640 /* if we are switching from ht to 2.4 clear flags 3704 if (le16_to_cpu(priv->staging_rxon.channel) != ch)
3641 * from any ht related info since 2.4 does not
3642 * support ht */
3643 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
3644 priv->staging_rxon.flags = 0; 3705 priv->staging_rxon.flags = 0;
3645 3706
3646 iwl_set_rxon_channel(priv, conf->channel); 3707 iwl_set_rxon_channel(priv, channel);
3647 iwl_set_rxon_ht(priv, ht_conf); 3708 iwl_set_rxon_ht(priv, ht_conf);
3648 iwl_set_flags_for_band(priv, conf->channel->band, 3709 iwl_set_flags_for_band(priv, channel->band,
3649 priv->vif); 3710 priv->vif);
3650 spin_unlock_irqrestore(&priv->lock, flags); 3711 spin_unlock_irqrestore(&priv->lock, flags);
3651 3712
@@ -3923,8 +3984,35 @@ static struct ieee80211_ops iwl_hw_ops = {
3923 .sta_remove = iwl_mac_sta_remove, 3984 .sta_remove = iwl_mac_sta_remove,
3924 .channel_switch = iwl_mac_channel_switch, 3985 .channel_switch = iwl_mac_channel_switch,
3925 .flush = iwl_mac_flush, 3986 .flush = iwl_mac_flush,
3987 .tx_last_beacon = iwl_mac_tx_last_beacon,
3926}; 3988};
3927 3989
3990static void iwl_hw_detect(struct iwl_priv *priv)
3991{
3992 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
3993 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
3994 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
3995 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", priv->rev_id);
3996}
3997
3998static int iwl_set_hw_params(struct iwl_priv *priv)
3999{
4000 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
4001 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
4002 if (priv->cfg->mod_params->amsdu_size_8K)
4003 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
4004 else
4005 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
4006
4007 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
4008
4009 if (priv->cfg->mod_params->disable_11n)
4010 priv->cfg->sku &= ~IWL_SKU_N;
4011
4012 /* Device-specific setup */
4013 return priv->cfg->ops->lib->set_hw_params(priv);
4014}
4015
3928static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 4016static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3929{ 4017{
3930 int err = 0; 4018 int err = 0;
@@ -3968,6 +4056,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3968 /************************** 4056 /**************************
3969 * 2. Initializing PCI bus 4057 * 2. Initializing PCI bus
3970 **************************/ 4058 **************************/
4059 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
4060 PCIE_LINK_STATE_CLKPM);
4061
3971 if (pci_enable_device(pdev)) { 4062 if (pci_enable_device(pdev)) {
3972 err = -ENODEV; 4063 err = -ENODEV;
3973 goto out_ieee80211_free_hw; 4064 goto out_ieee80211_free_hw;
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 60725a5c1b69..4083e4430827 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -1367,21 +1367,24 @@ struct iwl4965_rx_non_cfg_phy {
1367} __packed; 1367} __packed;
1368 1368
1369 1369
1370#define IWL50_RX_RES_PHY_CNT 8 1370#define IWLAGN_RX_RES_PHY_CNT 8
1371#define IWL50_RX_RES_AGC_IDX 1 1371#define IWLAGN_RX_RES_AGC_IDX 1
1372#define IWL50_RX_RES_RSSI_AB_IDX 2 1372#define IWLAGN_RX_RES_RSSI_AB_IDX 2
1373#define IWL50_RX_RES_RSSI_C_IDX 3 1373#define IWLAGN_RX_RES_RSSI_C_IDX 3
1374#define IWL50_OFDM_AGC_MSK 0xfe00 1374#define IWLAGN_OFDM_AGC_MSK 0xfe00
1375#define IWL50_OFDM_AGC_BIT_POS 9 1375#define IWLAGN_OFDM_AGC_BIT_POS 9
1376#define IWL50_OFDM_RSSI_A_MSK 0x00ff 1376#define IWLAGN_OFDM_RSSI_INBAND_A_BITMSK 0x00ff
1377#define IWL50_OFDM_RSSI_A_BIT_POS 0 1377#define IWLAGN_OFDM_RSSI_ALLBAND_A_BITMSK 0xff00
1378#define IWL50_OFDM_RSSI_B_MSK 0xff0000 1378#define IWLAGN_OFDM_RSSI_A_BIT_POS 0
1379#define IWL50_OFDM_RSSI_B_BIT_POS 16 1379#define IWLAGN_OFDM_RSSI_INBAND_B_BITMSK 0xff0000
1380#define IWL50_OFDM_RSSI_C_MSK 0x00ff 1380#define IWLAGN_OFDM_RSSI_ALLBAND_B_BITMSK 0xff000000
1381#define IWL50_OFDM_RSSI_C_BIT_POS 0 1381#define IWLAGN_OFDM_RSSI_B_BIT_POS 16
1382#define IWLAGN_OFDM_RSSI_INBAND_C_BITMSK 0x00ff
1383#define IWLAGN_OFDM_RSSI_ALLBAND_C_BITMSK 0xff00
1384#define IWLAGN_OFDM_RSSI_C_BIT_POS 0
1382 1385
1383struct iwl5000_non_cfg_phy { 1386struct iwlagn_non_cfg_phy {
1384 __le32 non_cfg_phy[IWL50_RX_RES_PHY_CNT]; /* up to 8 phy entries */ 1387 __le32 non_cfg_phy[IWLAGN_RX_RES_PHY_CNT]; /* up to 8 phy entries */
1385} __packed; 1388} __packed;
1386 1389
1387 1390
@@ -1401,7 +1404,7 @@ struct iwl_rx_phy_res {
1401 u8 non_cfg_phy_buf[32]; /* for various implementations of non_cfg_phy */ 1404 u8 non_cfg_phy_buf[32]; /* for various implementations of non_cfg_phy */
1402 __le32 rate_n_flags; /* RATE_MCS_* */ 1405 __le32 rate_n_flags; /* RATE_MCS_* */
1403 __le16 byte_count; /* frame's byte-count */ 1406 __le16 byte_count; /* frame's byte-count */
1404 __le16 reserved3; 1407 __le16 frame_time; /* frame's time on the air */
1405} __packed; 1408} __packed;
1406 1409
1407struct iwl_rx_mpdu_res_start { 1410struct iwl_rx_mpdu_res_start {
@@ -2092,8 +2095,8 @@ struct iwl_link_qual_general_params {
2092} __packed; 2095} __packed;
2093 2096
2094#define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */ 2097#define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */
2095#define LINK_QUAL_AGG_TIME_LIMIT_MAX (65535) 2098#define LINK_QUAL_AGG_TIME_LIMIT_MAX (8000)
2096#define LINK_QUAL_AGG_TIME_LIMIT_MIN (0) 2099#define LINK_QUAL_AGG_TIME_LIMIT_MIN (100)
2097 2100
2098#define LINK_QUAL_AGG_DISABLE_START_DEF (3) 2101#define LINK_QUAL_AGG_DISABLE_START_DEF (3)
2099#define LINK_QUAL_AGG_DISABLE_START_MAX (255) 2102#define LINK_QUAL_AGG_DISABLE_START_MAX (255)
@@ -2110,8 +2113,10 @@ struct iwl_link_qual_general_params {
2110 */ 2113 */
2111struct iwl_link_qual_agg_params { 2114struct iwl_link_qual_agg_params {
2112 2115
2113 /* Maximum number of uSec in aggregation. 2116 /*
2114 * Driver should set this to 4000 (4 milliseconds). */ 2117 *Maximum number of uSec in aggregation.
2118 * default set to 4000 (4 milliseconds) if not configured in .cfg
2119 */
2115 __le16 agg_time_limit; 2120 __le16 agg_time_limit;
2116 2121
2117 /* 2122 /*
@@ -2919,6 +2924,11 @@ struct iwl_scancomplete_notification {
2919 * 2924 *
2920 *****************************************************************************/ 2925 *****************************************************************************/
2921 2926
2927enum iwl_ibss_manager {
2928 IWL_NOT_IBSS_MANAGER = 0,
2929 IWL_IBSS_MANAGER = 1,
2930};
2931
2922/* 2932/*
2923 * BEACON_NOTIFICATION = 0x90 (notification only, not a command) 2933 * BEACON_NOTIFICATION = 0x90 (notification only, not a command)
2924 */ 2934 */
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 07dbc2796448..3d9443b9bec1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -183,14 +183,6 @@ out:
183} 183}
184EXPORT_SYMBOL(iwl_alloc_all); 184EXPORT_SYMBOL(iwl_alloc_all);
185 185
186void iwl_hw_detect(struct iwl_priv *priv)
187{
188 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
189 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
190 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
191}
192EXPORT_SYMBOL(iwl_hw_detect);
193
194/* 186/*
195 * QoS support 187 * QoS support
196*/ 188*/
@@ -247,7 +239,11 @@ static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
247 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU; 239 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
248 240
249 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; 241 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
242 if (priv->cfg->ampdu_factor)
243 ht_info->ampdu_factor = priv->cfg->ampdu_factor;
250 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF; 244 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
245 if (priv->cfg->ampdu_density)
246 ht_info->ampdu_density = priv->cfg->ampdu_density;
251 247
252 ht_info->mcs.rx_mask[0] = 0xFF; 248 ht_info->mcs.rx_mask[0] = 0xFF;
253 if (rx_chains_num >= 2) 249 if (rx_chains_num >= 2)
@@ -499,17 +495,19 @@ static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
499 return new_val; 495 return new_val;
500} 496}
501 497
502void iwl_setup_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif) 498int iwl_send_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif)
503{ 499{
504 u64 tsf; 500 u64 tsf;
505 s32 interval_tm, rem; 501 s32 interval_tm, rem;
506 unsigned long flags;
507 struct ieee80211_conf *conf = NULL; 502 struct ieee80211_conf *conf = NULL;
508 u16 beacon_int; 503 u16 beacon_int;
509 504
510 conf = ieee80211_get_hw_conf(priv->hw); 505 conf = ieee80211_get_hw_conf(priv->hw);
511 506
512 spin_lock_irqsave(&priv->lock, flags); 507 lockdep_assert_held(&priv->mutex);
508
509 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
510
513 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); 511 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
514 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval); 512 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
515 513
@@ -532,14 +530,16 @@ void iwl_setup_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif)
532 rem = do_div(tsf, interval_tm); 530 rem = do_div(tsf, interval_tm);
533 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem); 531 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
534 532
535 spin_unlock_irqrestore(&priv->lock, flags);
536 IWL_DEBUG_ASSOC(priv, 533 IWL_DEBUG_ASSOC(priv,
537 "beacon interval %d beacon timer %d beacon tim %d\n", 534 "beacon interval %d beacon timer %d beacon tim %d\n",
538 le16_to_cpu(priv->rxon_timing.beacon_interval), 535 le16_to_cpu(priv->rxon_timing.beacon_interval),
539 le32_to_cpu(priv->rxon_timing.beacon_init_val), 536 le32_to_cpu(priv->rxon_timing.beacon_init_val),
540 le16_to_cpu(priv->rxon_timing.atim_window)); 537 le16_to_cpu(priv->rxon_timing.atim_window));
538
539 return iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
540 sizeof(priv->rxon_timing), &priv->rxon_timing);
541} 541}
542EXPORT_SYMBOL(iwl_setup_rxon_timing); 542EXPORT_SYMBOL(iwl_send_rxon_timing);
543 543
544void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) 544void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
545{ 545{
@@ -912,25 +912,18 @@ u8 iwl_get_single_channel_number(struct iwl_priv *priv,
912EXPORT_SYMBOL(iwl_get_single_channel_number); 912EXPORT_SYMBOL(iwl_get_single_channel_number);
913 913
914/** 914/**
915 * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON 915 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
916 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz 916 * @ch: requested channel as a pointer to struct ieee80211_channel
917 * @channel: Any channel valid for the requested phymode
918 917
919 * In addition to setting the staging RXON, priv->phymode is also set. 918 * In addition to setting the staging RXON, priv->band is also set.
920 * 919 *
921 * NOTE: Does not commit to the hardware; it sets appropriate bit fields 920 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
922 * in the staging RXON flag structure based on the phymode 921 * in the staging RXON flag structure based on the ch->band
923 */ 922 */
924int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch) 923int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
925{ 924{
926 enum ieee80211_band band = ch->band; 925 enum ieee80211_band band = ch->band;
927 u16 channel = ieee80211_frequency_to_channel(ch->center_freq); 926 u16 channel = ch->hw_value;
928
929 if (!iwl_get_channel_info(priv, band, channel)) {
930 IWL_DEBUG_INFO(priv, "Could not set channel to %d [%d]\n",
931 channel, band);
932 return -EINVAL;
933 }
934 927
935 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && 928 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
936 (priv->band == band)) 929 (priv->band == band))
@@ -1328,25 +1321,6 @@ out:
1328EXPORT_SYMBOL(iwl_apm_init); 1321EXPORT_SYMBOL(iwl_apm_init);
1329 1322
1330 1323
1331int iwl_set_hw_params(struct iwl_priv *priv)
1332{
1333 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1334 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1335 if (priv->cfg->mod_params->amsdu_size_8K)
1336 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
1337 else
1338 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
1339
1340 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
1341
1342 if (priv->cfg->mod_params->disable_11n)
1343 priv->cfg->sku &= ~IWL_SKU_N;
1344
1345 /* Device-specific setup */
1346 return priv->cfg->ops->lib->set_hw_params(priv);
1347}
1348EXPORT_SYMBOL(iwl_set_hw_params);
1349
1350int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) 1324int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1351{ 1325{
1352 int ret = 0; 1326 int ret = 0;
@@ -1496,76 +1470,6 @@ int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
1496} 1470}
1497EXPORT_SYMBOL(iwl_send_statistics_request); 1471EXPORT_SYMBOL(iwl_send_statistics_request);
1498 1472
1499void iwl_rf_kill_ct_config(struct iwl_priv *priv)
1500{
1501 struct iwl_ct_kill_config cmd;
1502 struct iwl_ct_kill_throttling_config adv_cmd;
1503 unsigned long flags;
1504 int ret = 0;
1505
1506 spin_lock_irqsave(&priv->lock, flags);
1507 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1508 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1509 spin_unlock_irqrestore(&priv->lock, flags);
1510 priv->thermal_throttle.ct_kill_toggle = false;
1511
1512 if (priv->cfg->support_ct_kill_exit) {
1513 adv_cmd.critical_temperature_enter =
1514 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1515 adv_cmd.critical_temperature_exit =
1516 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
1517
1518 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1519 sizeof(adv_cmd), &adv_cmd);
1520 if (ret)
1521 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1522 else
1523 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1524 "succeeded, "
1525 "critical temperature enter is %d,"
1526 "exit is %d\n",
1527 priv->hw_params.ct_kill_threshold,
1528 priv->hw_params.ct_kill_exit_threshold);
1529 } else {
1530 cmd.critical_temperature_R =
1531 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1532
1533 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1534 sizeof(cmd), &cmd);
1535 if (ret)
1536 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1537 else
1538 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1539 "succeeded, "
1540 "critical temperature is %d\n",
1541 priv->hw_params.ct_kill_threshold);
1542 }
1543}
1544EXPORT_SYMBOL(iwl_rf_kill_ct_config);
1545
1546
1547/*
1548 * CARD_STATE_CMD
1549 *
1550 * Use: Sets the device's internal card state to enable, disable, or halt
1551 *
1552 * When in the 'enable' state the card operates as normal.
1553 * When in the 'disable' state, the card enters into a low power mode.
1554 * When in the 'halt' state, the card is shut down and must be fully
1555 * restarted to come back on.
1556 */
1557int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
1558{
1559 struct iwl_host_cmd cmd = {
1560 .id = REPLY_CARD_STATE_CMD,
1561 .len = sizeof(u32),
1562 .data = &flags,
1563 .flags = meta_flag,
1564 };
1565
1566 return iwl_send_cmd(priv, &cmd);
1567}
1568
1569void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, 1473void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
1570 struct iwl_rx_mem_buffer *rxb) 1474 struct iwl_rx_mem_buffer *rxb)
1571{ 1475{
@@ -1648,6 +1552,14 @@ int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1648} 1552}
1649EXPORT_SYMBOL(iwl_mac_conf_tx); 1553EXPORT_SYMBOL(iwl_mac_conf_tx);
1650 1554
1555int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
1556{
1557 struct iwl_priv *priv = hw->priv;
1558
1559 return priv->ibss_manager == IWL_IBSS_MANAGER;
1560}
1561EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
1562
1651static void iwl_ht_conf(struct iwl_priv *priv, 1563static void iwl_ht_conf(struct iwl_priv *priv,
1652 struct ieee80211_vif *vif) 1564 struct ieee80211_vif *vif)
1653{ 1565{
@@ -2014,6 +1926,7 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2014 struct iwl_priv *priv = hw->priv; 1926 struct iwl_priv *priv = hw->priv;
2015 const struct iwl_channel_info *ch_info; 1927 const struct iwl_channel_info *ch_info;
2016 struct ieee80211_conf *conf = &hw->conf; 1928 struct ieee80211_conf *conf = &hw->conf;
1929 struct ieee80211_channel *channel = conf->channel;
2017 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 1930 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
2018 unsigned long flags = 0; 1931 unsigned long flags = 0;
2019 int ret = 0; 1932 int ret = 0;
@@ -2023,7 +1936,7 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2023 mutex_lock(&priv->mutex); 1936 mutex_lock(&priv->mutex);
2024 1937
2025 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n", 1938 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2026 conf->channel->hw_value, changed); 1939 channel->hw_value, changed);
2027 1940
2028 if (unlikely(!priv->cfg->mod_params->disable_hw_scan && 1941 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2029 test_bit(STATUS_SCANNING, &priv->status))) { 1942 test_bit(STATUS_SCANNING, &priv->status))) {
@@ -2054,8 +1967,8 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2054 if (scan_active) 1967 if (scan_active)
2055 goto set_ch_out; 1968 goto set_ch_out;
2056 1969
2057 ch = ieee80211_frequency_to_channel(conf->channel->center_freq); 1970 ch = channel->hw_value;
2058 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch); 1971 ch_info = iwl_get_channel_info(priv, channel->band, ch);
2059 if (!is_channel_valid(ch_info)) { 1972 if (!is_channel_valid(ch_info)) {
2060 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n"); 1973 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2061 ret = -EINVAL; 1974 ret = -EINVAL;
@@ -2086,16 +1999,13 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2086 * from BSS config in iwl_ht_conf */ 1999 * from BSS config in iwl_ht_conf */
2087 ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 2000 ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2088 2001
2089 /* if we are switching from ht to 2.4 clear flags
2090 * from any ht related info since 2.4 does not
2091 * support ht */
2092 if ((le16_to_cpu(priv->staging_rxon.channel) != ch)) 2002 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2093 priv->staging_rxon.flags = 0; 2003 priv->staging_rxon.flags = 0;
2094 2004
2095 iwl_set_rxon_channel(priv, conf->channel); 2005 iwl_set_rxon_channel(priv, channel);
2096 iwl_set_rxon_ht(priv, ht_conf); 2006 iwl_set_rxon_ht(priv, ht_conf);
2097 2007
2098 iwl_set_flags_for_band(priv, conf->channel->band, priv->vif); 2008 iwl_set_flags_for_band(priv, channel->band, priv->vif);
2099 spin_unlock_irqrestore(&priv->lock, flags); 2009 spin_unlock_irqrestore(&priv->lock, flags);
2100 2010
2101 if (priv->cfg->ops->lib->update_bcast_station) 2011 if (priv->cfg->ops->lib->update_bcast_station)
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index 5e6ee3da6bbf..7b1e832bae56 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -136,6 +136,12 @@ struct iwl_temp_ops {
136 void (*set_calib_version)(struct iwl_priv *priv); 136 void (*set_calib_version)(struct iwl_priv *priv);
137}; 137};
138 138
139struct iwl_tt_ops {
140 bool (*lower_power_detection)(struct iwl_priv *priv);
141 u8 (*tt_power_mode)(struct iwl_priv *priv);
142 bool (*ct_kill_check)(struct iwl_priv *priv);
143};
144
139struct iwl_lib_ops { 145struct iwl_lib_ops {
140 /* set hw dependent parameters */ 146 /* set hw dependent parameters */
141 int (*set_hw_params)(struct iwl_priv *priv); 147 int (*set_hw_params)(struct iwl_priv *priv);
@@ -212,6 +218,9 @@ struct iwl_lib_ops {
212 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control); 218 void (*dev_txfifo_flush)(struct iwl_priv *priv, u16 flush_control);
213 219
214 struct iwl_debugfs_ops debugfs_ops; 220 struct iwl_debugfs_ops debugfs_ops;
221
222 /* thermal throttling */
223 struct iwl_tt_ops tt_ops;
215}; 224};
216 225
217struct iwl_led_ops { 226struct iwl_led_ops {
@@ -269,6 +278,11 @@ struct iwl_mod_params {
269 * @chain_noise_calib_by_driver: driver has the capability to perform 278 * @chain_noise_calib_by_driver: driver has the capability to perform
270 * chain noise calibration operation 279 * chain noise calibration operation
271 * @scan_antennas: available antenna for scan operation 280 * @scan_antennas: available antenna for scan operation
281 * @need_dc_calib: need to perform init dc calibration
282 * @bt_statistics: use BT version of statistics notification
283 * @agg_time_limit: maximum number of uSec in aggregation
284 * @ampdu_factor: Maximum A-MPDU length factor
285 * @ampdu_density: Minimum A-MPDU spacing
272 * 286 *
273 * We enable the driver to be backward compatible wrt API version. The 287 * We enable the driver to be backward compatible wrt API version. The
274 * driver specifies which APIs it supports (with @ucode_api_max being the 288 * driver specifies which APIs it supports (with @ucode_api_max being the
@@ -339,6 +353,9 @@ struct iwl_cfg {
339 u8 scan_tx_antennas[IEEE80211_NUM_BANDS]; 353 u8 scan_tx_antennas[IEEE80211_NUM_BANDS];
340 const bool need_dc_calib; 354 const bool need_dc_calib;
341 const bool bt_statistics; 355 const bool bt_statistics;
356 u16 agg_time_limit;
357 u8 ampdu_factor;
358 u8 ampdu_density;
342}; 359};
343 360
344/*************************** 361/***************************
@@ -347,10 +364,10 @@ struct iwl_cfg {
347 364
348struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, 365struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
349 struct ieee80211_ops *hw_ops); 366 struct ieee80211_ops *hw_ops);
350void iwl_hw_detect(struct iwl_priv *priv);
351void iwl_activate_qos(struct iwl_priv *priv); 367void iwl_activate_qos(struct iwl_priv *priv);
352int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, 368int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
353 const struct ieee80211_tx_queue_params *params); 369 const struct ieee80211_tx_queue_params *params);
370int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw);
354void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt); 371void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt);
355int iwl_check_rxon_cmd(struct iwl_priv *priv); 372int iwl_check_rxon_cmd(struct iwl_priv *priv);
356int iwl_full_rxon_required(struct iwl_priv *priv); 373int iwl_full_rxon_required(struct iwl_priv *priv);
@@ -372,7 +389,6 @@ int iwl_set_decrypted_flag(struct iwl_priv *priv,
372 u32 decrypt_res, 389 u32 decrypt_res,
373 struct ieee80211_rx_status *stats); 390 struct ieee80211_rx_status *stats);
374void iwl_irq_handle_error(struct iwl_priv *priv); 391void iwl_irq_handle_error(struct iwl_priv *priv);
375int iwl_set_hw_params(struct iwl_priv *priv);
376void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif); 392void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif);
377void iwl_bss_info_changed(struct ieee80211_hw *hw, 393void iwl_bss_info_changed(struct ieee80211_hw *hw,
378 struct ieee80211_vif *vif, 394 struct ieee80211_vif *vif,
@@ -527,7 +543,6 @@ int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
527int iwl_mac_hw_scan(struct ieee80211_hw *hw, 543int iwl_mac_hw_scan(struct ieee80211_hw *hw,
528 struct ieee80211_vif *vif, 544 struct ieee80211_vif *vif,
529 struct cfg80211_scan_request *req); 545 struct cfg80211_scan_request *req);
530void iwl_bg_start_internal_scan(struct work_struct *work);
531void iwl_internal_short_hw_scan(struct iwl_priv *priv); 546void iwl_internal_short_hw_scan(struct iwl_priv *priv);
532int iwl_force_reset(struct iwl_priv *priv, int mode, bool external); 547int iwl_force_reset(struct iwl_priv *priv, int mode, bool external);
533u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, 548u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
@@ -539,9 +554,6 @@ u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
539u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, 554u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
540 enum ieee80211_band band, 555 enum ieee80211_band band,
541 struct ieee80211_vif *vif); 556 struct ieee80211_vif *vif);
542void iwl_bg_scan_check(struct work_struct *data);
543void iwl_bg_abort_scan(struct work_struct *work);
544void iwl_bg_scan_completed(struct work_struct *work);
545void iwl_setup_scan_deferred_work(struct iwl_priv *priv); 557void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
546 558
547/* For faster active scanning, scan will move to the next channel if fewer than 559/* For faster active scanning, scan will move to the next channel if fewer than
@@ -580,8 +592,6 @@ int iwl_send_cmd_pdu_async(struct iwl_priv *priv, u8 id, u16 len,
580 592
581int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd); 593int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
582 594
583int iwl_send_card_state(struct iwl_priv *priv, u32 flags,
584 u8 meta_flag);
585 595
586/***************************************************** 596/*****************************************************
587 * PCI * 597 * PCI *
@@ -695,7 +705,6 @@ static inline int iwl_is_ready_rf(struct iwl_priv *priv)
695 return iwl_is_ready(priv); 705 return iwl_is_ready(priv);
696} 706}
697 707
698extern void iwl_rf_kill_ct_config(struct iwl_priv *priv);
699extern void iwl_send_bt_config(struct iwl_priv *priv); 708extern void iwl_send_bt_config(struct iwl_priv *priv);
700extern int iwl_send_statistics_request(struct iwl_priv *priv, 709extern int iwl_send_statistics_request(struct iwl_priv *priv,
701 u8 flags, bool clear); 710 u8 flags, bool clear);
@@ -704,7 +713,7 @@ extern int iwl_send_lq_cmd(struct iwl_priv *priv,
704void iwl_apm_stop(struct iwl_priv *priv); 713void iwl_apm_stop(struct iwl_priv *priv);
705int iwl_apm_init(struct iwl_priv *priv); 714int iwl_apm_init(struct iwl_priv *priv);
706 715
707void iwl_setup_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif); 716int iwl_send_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif);
708static inline int iwl_send_rxon_assoc(struct iwl_priv *priv) 717static inline int iwl_send_rxon_assoc(struct iwl_priv *priv)
709{ 718{
710 return priv->cfg->ops->hcmd->rxon_assoc(priv); 719 return priv->cfg->ops->hcmd->rxon_assoc(priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index e96a1bb12783..d3acdae72381 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -467,8 +467,7 @@ static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
467 for (i = 0; i < supp_band->n_channels; i++) 467 for (i = 0; i < supp_band->n_channels; i++)
468 pos += scnprintf(buf + pos, bufsz - pos, 468 pos += scnprintf(buf + pos, bufsz - pos,
469 "%d: %ddBm: BSS%s%s, %s.\n", 469 "%d: %ddBm: BSS%s%s, %s.\n",
470 ieee80211_frequency_to_channel( 470 channels[i].hw_value,
471 channels[i].center_freq),
472 channels[i].max_power, 471 channels[i].max_power,
473 channels[i].flags & IEEE80211_CHAN_RADAR ? 472 channels[i].flags & IEEE80211_CHAN_RADAR ?
474 " (IEEE 802.11h required)" : "", 473 " (IEEE 802.11h required)" : "",
@@ -491,8 +490,7 @@ static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
491 for (i = 0; i < supp_band->n_channels; i++) 490 for (i = 0; i < supp_band->n_channels; i++)
492 pos += scnprintf(buf + pos, bufsz - pos, 491 pos += scnprintf(buf + pos, bufsz - pos,
493 "%d: %ddBm: BSS%s%s, %s.\n", 492 "%d: %ddBm: BSS%s%s, %s.\n",
494 ieee80211_frequency_to_channel( 493 channels[i].hw_value,
495 channels[i].center_freq),
496 channels[i].max_power, 494 channels[i].max_power,
497 channels[i].flags & IEEE80211_CHAN_RADAR ? 495 channels[i].flags & IEEE80211_CHAN_RADAR ?
498 " (IEEE 802.11h required)" : "", 496 " (IEEE 802.11h required)" : "",
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 2e97cd2fa98a..1ad330342ffc 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -47,6 +47,7 @@
47#include "iwl-led.h" 47#include "iwl-led.h"
48#include "iwl-power.h" 48#include "iwl-power.h"
49#include "iwl-agn-rs.h" 49#include "iwl-agn-rs.h"
50#include "iwl-agn-tt.h"
50 51
51struct iwl_tx_queue; 52struct iwl_tx_queue;
52 53
@@ -420,7 +421,7 @@ struct iwl_tid_data {
420}; 421};
421 422
422struct iwl_hw_key { 423struct iwl_hw_key {
423 enum ieee80211_key_alg alg; 424 u32 cipher;
424 int keylen; 425 int keylen;
425 u8 keyidx; 426 u8 keyidx;
426 u8 key[32]; 427 u8 key[32];
@@ -434,7 +435,13 @@ union iwl_ht_rate_supp {
434 }; 435 };
435}; 436};
436 437
437#define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3) 438#define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
439#define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
440#define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
441#define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
442#define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
443#define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
444#define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
438 445
439/* 446/*
440 * Maximal MPDU density for TX aggregation 447 * Maximal MPDU density for TX aggregation
@@ -443,8 +450,13 @@ union iwl_ht_rate_supp {
443 * 6 - 8us density 450 * 6 - 8us density
444 * 7 - 16us density 451 * 7 - 16us density
445 */ 452 */
453#define CFG_HT_MPDU_DENSITY_2USEC (0x4)
446#define CFG_HT_MPDU_DENSITY_4USEC (0x5) 454#define CFG_HT_MPDU_DENSITY_4USEC (0x5)
455#define CFG_HT_MPDU_DENSITY_8USEC (0x6)
456#define CFG_HT_MPDU_DENSITY_16USEC (0x7)
447#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC 457#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
458#define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
459#define CFG_HT_MPDU_DENSITY_MIN (0x1)
448 460
449struct iwl_ht_config { 461struct iwl_ht_config {
450 /* self configuration data */ 462 /* self configuration data */
@@ -1052,7 +1064,6 @@ struct iwl_event_log {
1052#define IWL_DEF_MONITORING_PERIOD (1000) 1064#define IWL_DEF_MONITORING_PERIOD (1000)
1053#define IWL_LONG_MONITORING_PERIOD (5000) 1065#define IWL_LONG_MONITORING_PERIOD (5000)
1054#define IWL_ONE_HUNDRED_MSECS (100) 1066#define IWL_ONE_HUNDRED_MSECS (100)
1055#define IWL_SIXTY_SECS (60000)
1056 1067
1057enum iwl_reset { 1068enum iwl_reset {
1058 IWL_RF_RESET = 0, 1069 IWL_RF_RESET = 0,
@@ -1110,6 +1121,9 @@ struct iwl_priv {
1110 u32 ucode_beacon_time; 1121 u32 ucode_beacon_time;
1111 int missed_beacon_threshold; 1122 int missed_beacon_threshold;
1112 1123
1124 /* track IBSS manager (last beacon) status */
1125 u32 ibss_manager;
1126
1113 /* storing the jiffies when the plcp error rate is received */ 1127 /* storing the jiffies when the plcp error rate is received */
1114 unsigned long plcp_jiffies; 1128 unsigned long plcp_jiffies;
1115 1129
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c
index cda6a94d6cc9..63c0ab46261f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.c
+++ b/drivers/net/wireless/iwlwifi/iwl-power.c
@@ -192,47 +192,6 @@ static void iwl_static_sleep_cmd(struct iwl_priv *priv,
192 IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); 192 IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1);
193} 193}
194 194
195/* default Thermal Throttling transaction table
196 * Current state | Throttling Down | Throttling Up
197 *=============================================================================
198 * Condition Nxt State Condition Nxt State Condition Nxt State
199 *-----------------------------------------------------------------------------
200 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
201 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
202 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
203 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
204 *=============================================================================
205 */
206static const struct iwl_tt_trans tt_range_0[IWL_TI_STATE_MAX - 1] = {
207 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 104},
208 {IWL_TI_1, 105, CT_KILL_THRESHOLD - 1},
209 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
210};
211static const struct iwl_tt_trans tt_range_1[IWL_TI_STATE_MAX - 1] = {
212 {IWL_TI_0, IWL_ABSOLUTE_ZERO, 95},
213 {IWL_TI_2, 110, CT_KILL_THRESHOLD - 1},
214 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
215};
216static const struct iwl_tt_trans tt_range_2[IWL_TI_STATE_MAX - 1] = {
217 {IWL_TI_1, IWL_ABSOLUTE_ZERO, 100},
218 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX},
219 {IWL_TI_CT_KILL, CT_KILL_THRESHOLD, IWL_ABSOLUTE_MAX}
220};
221static const struct iwl_tt_trans tt_range_3[IWL_TI_STATE_MAX - 1] = {
222 {IWL_TI_0, IWL_ABSOLUTE_ZERO, CT_KILL_EXIT_THRESHOLD},
223 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX},
224 {IWL_TI_CT_KILL, CT_KILL_EXIT_THRESHOLD + 1, IWL_ABSOLUTE_MAX}
225};
226
227/* Advance Thermal Throttling default restriction table */
228static const struct iwl_tt_restriction restriction_range[IWL_TI_STATE_MAX] = {
229 {IWL_ANT_OK_MULTI, IWL_ANT_OK_MULTI, true },
230 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_MULTI, true },
231 {IWL_ANT_OK_SINGLE, IWL_ANT_OK_SINGLE, false },
232 {IWL_ANT_OK_NONE, IWL_ANT_OK_NONE, false }
233};
234
235
236static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, 195static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv,
237 struct iwl_powertable_cmd *cmd) 196 struct iwl_powertable_cmd *cmd)
238{ 197{
@@ -308,7 +267,6 @@ static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd)
308int iwl_power_update_mode(struct iwl_priv *priv, bool force) 267int iwl_power_update_mode(struct iwl_priv *priv, bool force)
309{ 268{
310 int ret = 0; 269 int ret = 0;
311 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
312 bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS; 270 bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS;
313 bool update_chains; 271 bool update_chains;
314 struct iwl_powertable_cmd cmd; 272 struct iwl_powertable_cmd cmd;
@@ -325,9 +283,13 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
325 else if (priv->cfg->supports_idle && 283 else if (priv->cfg->supports_idle &&
326 priv->hw->conf.flags & IEEE80211_CONF_IDLE) 284 priv->hw->conf.flags & IEEE80211_CONF_IDLE)
327 iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_5, 20); 285 iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_5, 20);
328 else if (tt->state >= IWL_TI_1) 286 else if (priv->cfg->ops->lib->tt_ops.lower_power_detection &&
329 iwl_static_sleep_cmd(priv, &cmd, tt->tt_power_mode, dtimper); 287 priv->cfg->ops->lib->tt_ops.tt_power_mode &&
330 else if (!enabled) 288 priv->cfg->ops->lib->tt_ops.lower_power_detection(priv)) {
289 /* in thermal throttling low power state */
290 iwl_static_sleep_cmd(priv, &cmd,
291 priv->cfg->ops->lib->tt_ops.tt_power_mode(priv), dtimper);
292 } else if (!enabled)
331 iwl_power_sleep_cam_cmd(priv, &cmd); 293 iwl_power_sleep_cam_cmd(priv, &cmd);
332 else if (priv->power_data.debug_sleep_level_override >= 0) 294 else if (priv->power_data.debug_sleep_level_override >= 0)
333 iwl_static_sleep_cmd(priv, &cmd, 295 iwl_static_sleep_cmd(priv, &cmd,
@@ -367,592 +329,6 @@ int iwl_power_update_mode(struct iwl_priv *priv, bool force)
367} 329}
368EXPORT_SYMBOL(iwl_power_update_mode); 330EXPORT_SYMBOL(iwl_power_update_mode);
369 331
370bool iwl_ht_enabled(struct iwl_priv *priv)
371{
372 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
373 struct iwl_tt_restriction *restriction;
374
375 if (!priv->thermal_throttle.advanced_tt)
376 return true;
377 restriction = tt->restriction + tt->state;
378 return restriction->is_ht;
379}
380EXPORT_SYMBOL(iwl_ht_enabled);
381
382bool iwl_within_ct_kill_margin(struct iwl_priv *priv)
383{
384 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
385 bool within_margin = false;
386
387 if (priv->cfg->temperature_kelvin)
388 temp = KELVIN_TO_CELSIUS(priv->temperature);
389
390 if (!priv->thermal_throttle.advanced_tt)
391 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
392 CT_KILL_THRESHOLD_LEGACY) ? true : false;
393 else
394 within_margin = ((temp + IWL_TT_CT_KILL_MARGIN) >=
395 CT_KILL_THRESHOLD) ? true : false;
396 return within_margin;
397}
398
399enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv)
400{
401 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
402 struct iwl_tt_restriction *restriction;
403
404 if (!priv->thermal_throttle.advanced_tt)
405 return IWL_ANT_OK_MULTI;
406 restriction = tt->restriction + tt->state;
407 return restriction->tx_stream;
408}
409EXPORT_SYMBOL(iwl_tx_ant_restriction);
410
411enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv)
412{
413 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
414 struct iwl_tt_restriction *restriction;
415
416 if (!priv->thermal_throttle.advanced_tt)
417 return IWL_ANT_OK_MULTI;
418 restriction = tt->restriction + tt->state;
419 return restriction->rx_stream;
420}
421
422#define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */
423#define CT_KILL_WAITING_DURATION (300) /* 300ms duration */
424
425/*
426 * toggle the bit to wake up uCode and check the temperature
427 * if the temperature is below CT, uCode will stay awake and send card
428 * state notification with CT_KILL bit clear to inform Thermal Throttling
429 * Management to change state. Otherwise, uCode will go back to sleep
430 * without doing anything, driver should continue the 5 seconds timer
431 * to wake up uCode for temperature check until temperature drop below CT
432 */
433static void iwl_tt_check_exit_ct_kill(unsigned long data)
434{
435 struct iwl_priv *priv = (struct iwl_priv *)data;
436 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
437 unsigned long flags;
438
439 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
440 return;
441
442 if (tt->state == IWL_TI_CT_KILL) {
443 if (priv->thermal_throttle.ct_kill_toggle) {
444 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
445 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
446 priv->thermal_throttle.ct_kill_toggle = false;
447 } else {
448 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
449 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
450 priv->thermal_throttle.ct_kill_toggle = true;
451 }
452 iwl_read32(priv, CSR_UCODE_DRV_GP1);
453 spin_lock_irqsave(&priv->reg_lock, flags);
454 if (!iwl_grab_nic_access(priv))
455 iwl_release_nic_access(priv);
456 spin_unlock_irqrestore(&priv->reg_lock, flags);
457
458 /* Reschedule the ct_kill timer to occur in
459 * CT_KILL_EXIT_DURATION seconds to ensure we get a
460 * thermal update */
461 IWL_DEBUG_POWER(priv, "schedule ct_kill exit timer\n");
462 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, jiffies +
463 CT_KILL_EXIT_DURATION * HZ);
464 }
465}
466
467static void iwl_perform_ct_kill_task(struct iwl_priv *priv,
468 bool stop)
469{
470 if (stop) {
471 IWL_DEBUG_POWER(priv, "Stop all queues\n");
472 if (priv->mac80211_registered)
473 ieee80211_stop_queues(priv->hw);
474 IWL_DEBUG_POWER(priv,
475 "Schedule 5 seconds CT_KILL Timer\n");
476 mod_timer(&priv->thermal_throttle.ct_kill_exit_tm, jiffies +
477 CT_KILL_EXIT_DURATION * HZ);
478 } else {
479 IWL_DEBUG_POWER(priv, "Wake all queues\n");
480 if (priv->mac80211_registered)
481 ieee80211_wake_queues(priv->hw);
482 }
483}
484
485static void iwl_tt_ready_for_ct_kill(unsigned long data)
486{
487 struct iwl_priv *priv = (struct iwl_priv *)data;
488 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
489
490 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
491 return;
492
493 /* temperature timer expired, ready to go into CT_KILL state */
494 if (tt->state != IWL_TI_CT_KILL) {
495 IWL_DEBUG_POWER(priv, "entering CT_KILL state when temperature timer expired\n");
496 tt->state = IWL_TI_CT_KILL;
497 set_bit(STATUS_CT_KILL, &priv->status);
498 iwl_perform_ct_kill_task(priv, true);
499 }
500}
501
502static void iwl_prepare_ct_kill_task(struct iwl_priv *priv)
503{
504 IWL_DEBUG_POWER(priv, "Prepare to enter IWL_TI_CT_KILL\n");
505 /* make request to retrieve statistics information */
506 iwl_send_statistics_request(priv, CMD_SYNC, false);
507 /* Reschedule the ct_kill wait timer */
508 mod_timer(&priv->thermal_throttle.ct_kill_waiting_tm,
509 jiffies + msecs_to_jiffies(CT_KILL_WAITING_DURATION));
510}
511
512#define IWL_MINIMAL_POWER_THRESHOLD (CT_KILL_THRESHOLD_LEGACY)
513#define IWL_REDUCED_PERFORMANCE_THRESHOLD_2 (100)
514#define IWL_REDUCED_PERFORMANCE_THRESHOLD_1 (90)
515
516/*
517 * Legacy thermal throttling
518 * 1) Avoid NIC destruction due to high temperatures
519 * Chip will identify dangerously high temperatures that can
520 * harm the device and will power down
521 * 2) Avoid the NIC power down due to high temperature
522 * Throttle early enough to lower the power consumption before
523 * drastic steps are needed
524 */
525static void iwl_legacy_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
526{
527 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
528 enum iwl_tt_state old_state;
529
530#ifdef CONFIG_IWLWIFI_DEBUG
531 if ((tt->tt_previous_temp) &&
532 (temp > tt->tt_previous_temp) &&
533 ((temp - tt->tt_previous_temp) >
534 IWL_TT_INCREASE_MARGIN)) {
535 IWL_DEBUG_POWER(priv,
536 "Temperature increase %d degree Celsius\n",
537 (temp - tt->tt_previous_temp));
538 }
539#endif
540 old_state = tt->state;
541 /* in Celsius */
542 if (temp >= IWL_MINIMAL_POWER_THRESHOLD)
543 tt->state = IWL_TI_CT_KILL;
544 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_2)
545 tt->state = IWL_TI_2;
546 else if (temp >= IWL_REDUCED_PERFORMANCE_THRESHOLD_1)
547 tt->state = IWL_TI_1;
548 else
549 tt->state = IWL_TI_0;
550
551#ifdef CONFIG_IWLWIFI_DEBUG
552 tt->tt_previous_temp = temp;
553#endif
554 /* stop ct_kill_waiting_tm timer */
555 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
556 if (tt->state != old_state) {
557 switch (tt->state) {
558 case IWL_TI_0:
559 /*
560 * When the system is ready to go back to IWL_TI_0
561 * we only have to call iwl_power_update_mode() to
562 * do so.
563 */
564 break;
565 case IWL_TI_1:
566 tt->tt_power_mode = IWL_POWER_INDEX_3;
567 break;
568 case IWL_TI_2:
569 tt->tt_power_mode = IWL_POWER_INDEX_4;
570 break;
571 default:
572 tt->tt_power_mode = IWL_POWER_INDEX_5;
573 break;
574 }
575 mutex_lock(&priv->mutex);
576 if (old_state == IWL_TI_CT_KILL)
577 clear_bit(STATUS_CT_KILL, &priv->status);
578 if (tt->state != IWL_TI_CT_KILL &&
579 iwl_power_update_mode(priv, true)) {
580 /* TT state not updated
581 * try again during next temperature read
582 */
583 if (old_state == IWL_TI_CT_KILL)
584 set_bit(STATUS_CT_KILL, &priv->status);
585 tt->state = old_state;
586 IWL_ERR(priv, "Cannot update power mode, "
587 "TT state not updated\n");
588 } else {
589 if (tt->state == IWL_TI_CT_KILL) {
590 if (force) {
591 set_bit(STATUS_CT_KILL, &priv->status);
592 iwl_perform_ct_kill_task(priv, true);
593 } else {
594 iwl_prepare_ct_kill_task(priv);
595 tt->state = old_state;
596 }
597 } else if (old_state == IWL_TI_CT_KILL &&
598 tt->state != IWL_TI_CT_KILL)
599 iwl_perform_ct_kill_task(priv, false);
600 IWL_DEBUG_POWER(priv, "Temperature state changed %u\n",
601 tt->state);
602 IWL_DEBUG_POWER(priv, "Power Index change to %u\n",
603 tt->tt_power_mode);
604 }
605 mutex_unlock(&priv->mutex);
606 }
607}
608
609/*
610 * Advance thermal throttling
611 * 1) Avoid NIC destruction due to high temperatures
612 * Chip will identify dangerously high temperatures that can
613 * harm the device and will power down
614 * 2) Avoid the NIC power down due to high temperature
615 * Throttle early enough to lower the power consumption before
616 * drastic steps are needed
617 * Actions include relaxing the power down sleep thresholds and
618 * decreasing the number of TX streams
619 * 3) Avoid throughput performance impact as much as possible
620 *
621 *=============================================================================
622 * Condition Nxt State Condition Nxt State Condition Nxt State
623 *-----------------------------------------------------------------------------
624 * IWL_TI_0 T >= 114 CT_KILL 114>T>=105 TI_1 N/A N/A
625 * IWL_TI_1 T >= 114 CT_KILL 114>T>=110 TI_2 T<=95 TI_0
626 * IWL_TI_2 T >= 114 CT_KILL T<=100 TI_1
627 * IWL_CT_KILL N/A N/A N/A N/A T<=95 TI_0
628 *=============================================================================
629 */
630static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
631{
632 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
633 int i;
634 bool changed = false;
635 enum iwl_tt_state old_state;
636 struct iwl_tt_trans *transaction;
637
638 old_state = tt->state;
639 for (i = 0; i < IWL_TI_STATE_MAX - 1; i++) {
640 /* based on the current TT state,
641 * find the curresponding transaction table
642 * each table has (IWL_TI_STATE_MAX - 1) entries
643 * tt->transaction + ((old_state * (IWL_TI_STATE_MAX - 1))
644 * will advance to the correct table.
645 * then based on the current temperature
646 * find the next state need to transaction to
647 * go through all the possible (IWL_TI_STATE_MAX - 1) entries
648 * in the current table to see if transaction is needed
649 */
650 transaction = tt->transaction +
651 ((old_state * (IWL_TI_STATE_MAX - 1)) + i);
652 if (temp >= transaction->tt_low &&
653 temp <= transaction->tt_high) {
654#ifdef CONFIG_IWLWIFI_DEBUG
655 if ((tt->tt_previous_temp) &&
656 (temp > tt->tt_previous_temp) &&
657 ((temp - tt->tt_previous_temp) >
658 IWL_TT_INCREASE_MARGIN)) {
659 IWL_DEBUG_POWER(priv,
660 "Temperature increase %d "
661 "degree Celsius\n",
662 (temp - tt->tt_previous_temp));
663 }
664 tt->tt_previous_temp = temp;
665#endif
666 if (old_state !=
667 transaction->next_state) {
668 changed = true;
669 tt->state =
670 transaction->next_state;
671 }
672 break;
673 }
674 }
675 /* stop ct_kill_waiting_tm timer */
676 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
677 if (changed) {
678 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
679
680 if (tt->state >= IWL_TI_1) {
681 /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */
682 tt->tt_power_mode = IWL_POWER_INDEX_5;
683 if (!iwl_ht_enabled(priv))
684 /* disable HT */
685 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
686 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
687 RXON_FLG_HT40_PROT_MSK |
688 RXON_FLG_HT_PROT_MSK);
689 else {
690 /* check HT capability and set
691 * according to the system HT capability
692 * in case get disabled before */
693 iwl_set_rxon_ht(priv, &priv->current_ht_config);
694 }
695
696 } else {
697 /*
698 * restore system power setting -- it will be
699 * recalculated automatically.
700 */
701
702 /* check HT capability and set
703 * according to the system HT capability
704 * in case get disabled before */
705 iwl_set_rxon_ht(priv, &priv->current_ht_config);
706 }
707 mutex_lock(&priv->mutex);
708 if (old_state == IWL_TI_CT_KILL)
709 clear_bit(STATUS_CT_KILL, &priv->status);
710 if (tt->state != IWL_TI_CT_KILL &&
711 iwl_power_update_mode(priv, true)) {
712 /* TT state not updated
713 * try again during next temperature read
714 */
715 IWL_ERR(priv, "Cannot update power mode, "
716 "TT state not updated\n");
717 if (old_state == IWL_TI_CT_KILL)
718 set_bit(STATUS_CT_KILL, &priv->status);
719 tt->state = old_state;
720 } else {
721 IWL_DEBUG_POWER(priv,
722 "Thermal Throttling to new state: %u\n",
723 tt->state);
724 if (old_state != IWL_TI_CT_KILL &&
725 tt->state == IWL_TI_CT_KILL) {
726 if (force) {
727 IWL_DEBUG_POWER(priv,
728 "Enter IWL_TI_CT_KILL\n");
729 set_bit(STATUS_CT_KILL, &priv->status);
730 iwl_perform_ct_kill_task(priv, true);
731 } else {
732 iwl_prepare_ct_kill_task(priv);
733 tt->state = old_state;
734 }
735 } else if (old_state == IWL_TI_CT_KILL &&
736 tt->state != IWL_TI_CT_KILL) {
737 IWL_DEBUG_POWER(priv, "Exit IWL_TI_CT_KILL\n");
738 iwl_perform_ct_kill_task(priv, false);
739 }
740 }
741 mutex_unlock(&priv->mutex);
742 }
743}
744
745/* Card State Notification indicated reach critical temperature
746 * if PSP not enable, no Thermal Throttling function will be performed
747 * just set the GP1 bit to acknowledge the event
748 * otherwise, go into IWL_TI_CT_KILL state
749 * since Card State Notification will not provide any temperature reading
750 * for Legacy mode
751 * so just pass the CT_KILL temperature to iwl_legacy_tt_handler()
752 * for advance mode
753 * pass CT_KILL_THRESHOLD+1 to make sure move into IWL_TI_CT_KILL state
754 */
755static void iwl_bg_ct_enter(struct work_struct *work)
756{
757 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_enter);
758 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
759
760 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
761 return;
762
763 if (!iwl_is_ready(priv))
764 return;
765
766 if (tt->state != IWL_TI_CT_KILL) {
767 IWL_ERR(priv, "Device reached critical temperature "
768 "- ucode going to sleep!\n");
769 if (!priv->thermal_throttle.advanced_tt)
770 iwl_legacy_tt_handler(priv,
771 IWL_MINIMAL_POWER_THRESHOLD,
772 true);
773 else
774 iwl_advance_tt_handler(priv,
775 CT_KILL_THRESHOLD + 1, true);
776 }
777}
778
779/* Card State Notification indicated out of critical temperature
780 * since Card State Notification will not provide any temperature reading
781 * so pass the IWL_REDUCED_PERFORMANCE_THRESHOLD_2 temperature
782 * to iwl_legacy_tt_handler() to get out of IWL_CT_KILL state
783 */
784static void iwl_bg_ct_exit(struct work_struct *work)
785{
786 struct iwl_priv *priv = container_of(work, struct iwl_priv, ct_exit);
787 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
788
789 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
790 return;
791
792 if (!iwl_is_ready(priv))
793 return;
794
795 /* stop ct_kill_exit_tm timer */
796 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
797
798 if (tt->state == IWL_TI_CT_KILL) {
799 IWL_ERR(priv,
800 "Device temperature below critical"
801 "- ucode awake!\n");
802 /*
803 * exit from CT_KILL state
804 * reset the current temperature reading
805 */
806 priv->temperature = 0;
807 if (!priv->thermal_throttle.advanced_tt)
808 iwl_legacy_tt_handler(priv,
809 IWL_REDUCED_PERFORMANCE_THRESHOLD_2,
810 true);
811 else
812 iwl_advance_tt_handler(priv, CT_KILL_EXIT_THRESHOLD,
813 true);
814 }
815}
816
817void iwl_tt_enter_ct_kill(struct iwl_priv *priv)
818{
819 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
820 return;
821
822 IWL_DEBUG_POWER(priv, "Queueing critical temperature enter.\n");
823 queue_work(priv->workqueue, &priv->ct_enter);
824}
825EXPORT_SYMBOL(iwl_tt_enter_ct_kill);
826
827void iwl_tt_exit_ct_kill(struct iwl_priv *priv)
828{
829 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
830 return;
831
832 IWL_DEBUG_POWER(priv, "Queueing critical temperature exit.\n");
833 queue_work(priv->workqueue, &priv->ct_exit);
834}
835EXPORT_SYMBOL(iwl_tt_exit_ct_kill);
836
837static void iwl_bg_tt_work(struct work_struct *work)
838{
839 struct iwl_priv *priv = container_of(work, struct iwl_priv, tt_work);
840 s32 temp = priv->temperature; /* degrees CELSIUS except specified */
841
842 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
843 return;
844
845 if (priv->cfg->temperature_kelvin)
846 temp = KELVIN_TO_CELSIUS(priv->temperature);
847
848 if (!priv->thermal_throttle.advanced_tt)
849 iwl_legacy_tt_handler(priv, temp, false);
850 else
851 iwl_advance_tt_handler(priv, temp, false);
852}
853
854void iwl_tt_handler(struct iwl_priv *priv)
855{
856 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
857 return;
858
859 IWL_DEBUG_POWER(priv, "Queueing thermal throttling work.\n");
860 queue_work(priv->workqueue, &priv->tt_work);
861}
862EXPORT_SYMBOL(iwl_tt_handler);
863
864/* Thermal throttling initialization
865 * For advance thermal throttling:
866 * Initialize Thermal Index and temperature threshold table
867 * Initialize thermal throttling restriction table
868 */
869void iwl_tt_initialize(struct iwl_priv *priv)
870{
871 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
872 int size = sizeof(struct iwl_tt_trans) * (IWL_TI_STATE_MAX - 1);
873 struct iwl_tt_trans *transaction;
874
875 IWL_DEBUG_POWER(priv, "Initialize Thermal Throttling\n");
876
877 memset(tt, 0, sizeof(struct iwl_tt_mgmt));
878
879 tt->state = IWL_TI_0;
880 init_timer(&priv->thermal_throttle.ct_kill_exit_tm);
881 priv->thermal_throttle.ct_kill_exit_tm.data = (unsigned long)priv;
882 priv->thermal_throttle.ct_kill_exit_tm.function =
883 iwl_tt_check_exit_ct_kill;
884 init_timer(&priv->thermal_throttle.ct_kill_waiting_tm);
885 priv->thermal_throttle.ct_kill_waiting_tm.data = (unsigned long)priv;
886 priv->thermal_throttle.ct_kill_waiting_tm.function =
887 iwl_tt_ready_for_ct_kill;
888 /* setup deferred ct kill work */
889 INIT_WORK(&priv->tt_work, iwl_bg_tt_work);
890 INIT_WORK(&priv->ct_enter, iwl_bg_ct_enter);
891 INIT_WORK(&priv->ct_exit, iwl_bg_ct_exit);
892
893 if (priv->cfg->adv_thermal_throttle) {
894 IWL_DEBUG_POWER(priv, "Advanced Thermal Throttling\n");
895 tt->restriction = kzalloc(sizeof(struct iwl_tt_restriction) *
896 IWL_TI_STATE_MAX, GFP_KERNEL);
897 tt->transaction = kzalloc(sizeof(struct iwl_tt_trans) *
898 IWL_TI_STATE_MAX * (IWL_TI_STATE_MAX - 1),
899 GFP_KERNEL);
900 if (!tt->restriction || !tt->transaction) {
901 IWL_ERR(priv, "Fallback to Legacy Throttling\n");
902 priv->thermal_throttle.advanced_tt = false;
903 kfree(tt->restriction);
904 tt->restriction = NULL;
905 kfree(tt->transaction);
906 tt->transaction = NULL;
907 } else {
908 transaction = tt->transaction +
909 (IWL_TI_0 * (IWL_TI_STATE_MAX - 1));
910 memcpy(transaction, &tt_range_0[0], size);
911 transaction = tt->transaction +
912 (IWL_TI_1 * (IWL_TI_STATE_MAX - 1));
913 memcpy(transaction, &tt_range_1[0], size);
914 transaction = tt->transaction +
915 (IWL_TI_2 * (IWL_TI_STATE_MAX - 1));
916 memcpy(transaction, &tt_range_2[0], size);
917 transaction = tt->transaction +
918 (IWL_TI_CT_KILL * (IWL_TI_STATE_MAX - 1));
919 memcpy(transaction, &tt_range_3[0], size);
920 size = sizeof(struct iwl_tt_restriction) *
921 IWL_TI_STATE_MAX;
922 memcpy(tt->restriction,
923 &restriction_range[0], size);
924 priv->thermal_throttle.advanced_tt = true;
925 }
926 } else {
927 IWL_DEBUG_POWER(priv, "Legacy Thermal Throttling\n");
928 priv->thermal_throttle.advanced_tt = false;
929 }
930}
931EXPORT_SYMBOL(iwl_tt_initialize);
932
933/* cleanup thermal throttling management related memory and timer */
934void iwl_tt_exit(struct iwl_priv *priv)
935{
936 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
937
938 /* stop ct_kill_exit_tm timer if activated */
939 del_timer_sync(&priv->thermal_throttle.ct_kill_exit_tm);
940 /* stop ct_kill_waiting_tm timer if activated */
941 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
942 cancel_work_sync(&priv->tt_work);
943 cancel_work_sync(&priv->ct_enter);
944 cancel_work_sync(&priv->ct_exit);
945
946 if (priv->thermal_throttle.advanced_tt) {
947 /* free advance thermal throttling memory */
948 kfree(tt->restriction);
949 tt->restriction = NULL;
950 kfree(tt->transaction);
951 tt->transaction = NULL;
952 }
953}
954EXPORT_SYMBOL(iwl_tt_exit);
955
956/* initialize to default */ 332/* initialize to default */
957void iwl_power_initialize(struct iwl_priv *priv) 333void iwl_power_initialize(struct iwl_priv *priv)
958{ 334{
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.h b/drivers/net/wireless/iwlwifi/iwl-power.h
index 5db91c10dcc8..df81565a7cc4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.h
+++ b/drivers/net/wireless/iwlwifi/iwl-power.h
@@ -30,90 +30,6 @@
30 30
31#include "iwl-commands.h" 31#include "iwl-commands.h"
32 32
33#define IWL_ABSOLUTE_ZERO 0
34#define IWL_ABSOLUTE_MAX 0xFFFFFFFF
35#define IWL_TT_INCREASE_MARGIN 5
36#define IWL_TT_CT_KILL_MARGIN 3
37
38enum iwl_antenna_ok {
39 IWL_ANT_OK_NONE,
40 IWL_ANT_OK_SINGLE,
41 IWL_ANT_OK_MULTI,
42};
43
44/* Thermal Throttling State Machine states */
45enum iwl_tt_state {
46 IWL_TI_0, /* normal temperature, system power state */
47 IWL_TI_1, /* high temperature detect, low power state */
48 IWL_TI_2, /* higher temperature detected, lower power state */
49 IWL_TI_CT_KILL, /* critical temperature detected, lowest power state */
50 IWL_TI_STATE_MAX
51};
52
53/**
54 * struct iwl_tt_restriction - Thermal Throttling restriction table
55 * @tx_stream: number of tx stream allowed
56 * @is_ht: ht enable/disable
57 * @rx_stream: number of rx stream allowed
58 *
59 * This table is used by advance thermal throttling management
60 * based on the current thermal throttling state, and determines
61 * the number of tx/rx streams and the status of HT operation.
62 */
63struct iwl_tt_restriction {
64 enum iwl_antenna_ok tx_stream;
65 enum iwl_antenna_ok rx_stream;
66 bool is_ht;
67};
68
69/**
70 * struct iwl_tt_trans - Thermal Throttling transaction table
71 * @next_state: next thermal throttling mode
72 * @tt_low: low temperature threshold to change state
73 * @tt_high: high temperature threshold to change state
74 *
75 * This is used by the advanced thermal throttling algorithm
76 * to determine the next thermal state to go based on the
77 * current temperature.
78 */
79struct iwl_tt_trans {
80 enum iwl_tt_state next_state;
81 u32 tt_low;
82 u32 tt_high;
83};
84
85/**
86 * struct iwl_tt_mgnt - Thermal Throttling Management structure
87 * @advanced_tt: advanced thermal throttle required
88 * @state: current Thermal Throttling state
89 * @tt_power_mode: Thermal Throttling power mode index
90 * being used to set power level when
91 * when thermal throttling state != IWL_TI_0
92 * the tt_power_mode should set to different
93 * power mode based on the current tt state
94 * @tt_previous_temperature: last measured temperature
95 * @iwl_tt_restriction: ptr to restriction tbl, used by advance
96 * thermal throttling to determine how many tx/rx streams
97 * should be used in tt state; and can HT be enabled or not
98 * @iwl_tt_trans: ptr to adv trans table, used by advance thermal throttling
99 * state transaction
100 * @ct_kill_toggle: used to toggle the CSR bit when checking uCode temperature
101 * @ct_kill_exit_tm: timer to exit thermal kill
102 */
103struct iwl_tt_mgmt {
104 enum iwl_tt_state state;
105 bool advanced_tt;
106 u8 tt_power_mode;
107 bool ct_kill_toggle;
108#ifdef CONFIG_IWLWIFI_DEBUG
109 s32 tt_previous_temp;
110#endif
111 struct iwl_tt_restriction *restriction;
112 struct iwl_tt_trans *transaction;
113 struct timer_list ct_kill_exit_tm;
114 struct timer_list ct_kill_waiting_tm;
115};
116
117enum iwl_power_level { 33enum iwl_power_level {
118 IWL_POWER_INDEX_1, 34 IWL_POWER_INDEX_1,
119 IWL_POWER_INDEX_2, 35 IWL_POWER_INDEX_2,
@@ -130,15 +46,6 @@ struct iwl_power_mgr {
130}; 46};
131 47
132int iwl_power_update_mode(struct iwl_priv *priv, bool force); 48int iwl_power_update_mode(struct iwl_priv *priv, bool force);
133bool iwl_ht_enabled(struct iwl_priv *priv);
134bool iwl_within_ct_kill_margin(struct iwl_priv *priv);
135enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv);
136enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv);
137void iwl_tt_enter_ct_kill(struct iwl_priv *priv);
138void iwl_tt_exit_ct_kill(struct iwl_priv *priv);
139void iwl_tt_handler(struct iwl_priv *priv);
140void iwl_tt_initialize(struct iwl_priv *priv);
141void iwl_tt_exit(struct iwl_priv *priv);
142void iwl_power_initialize(struct iwl_priv *priv); 49void iwl_power_initialize(struct iwl_priv *priv);
143 50
144extern bool no_sleep_autoadjust; 51extern bool no_sleep_autoadjust;
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index a4b3663a262f..8d7fa59364fe 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -378,7 +378,7 @@ void iwl_internal_short_hw_scan(struct iwl_priv *priv)
378 queue_work(priv->workqueue, &priv->start_internal_scan); 378 queue_work(priv->workqueue, &priv->start_internal_scan);
379} 379}
380 380
381void iwl_bg_start_internal_scan(struct work_struct *work) 381static void iwl_bg_start_internal_scan(struct work_struct *work)
382{ 382{
383 struct iwl_priv *priv = 383 struct iwl_priv *priv =
384 container_of(work, struct iwl_priv, start_internal_scan); 384 container_of(work, struct iwl_priv, start_internal_scan);
@@ -418,9 +418,8 @@ void iwl_bg_start_internal_scan(struct work_struct *work)
418 unlock: 418 unlock:
419 mutex_unlock(&priv->mutex); 419 mutex_unlock(&priv->mutex);
420} 420}
421EXPORT_SYMBOL(iwl_bg_start_internal_scan);
422 421
423void iwl_bg_scan_check(struct work_struct *data) 422static void iwl_bg_scan_check(struct work_struct *data)
424{ 423{
425 struct iwl_priv *priv = 424 struct iwl_priv *priv =
426 container_of(data, struct iwl_priv, scan_check.work); 425 container_of(data, struct iwl_priv, scan_check.work);
@@ -439,7 +438,6 @@ void iwl_bg_scan_check(struct work_struct *data)
439 } 438 }
440 mutex_unlock(&priv->mutex); 439 mutex_unlock(&priv->mutex);
441} 440}
442EXPORT_SYMBOL(iwl_bg_scan_check);
443 441
444/** 442/**
445 * iwl_fill_probe_req - fill in all required fields and IE for probe request 443 * iwl_fill_probe_req - fill in all required fields and IE for probe request
@@ -489,7 +487,7 @@ u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
489} 487}
490EXPORT_SYMBOL(iwl_fill_probe_req); 488EXPORT_SYMBOL(iwl_fill_probe_req);
491 489
492void iwl_bg_abort_scan(struct work_struct *work) 490static void iwl_bg_abort_scan(struct work_struct *work)
493{ 491{
494 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); 492 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
495 493
@@ -504,13 +502,13 @@ void iwl_bg_abort_scan(struct work_struct *work)
504 iwl_send_scan_abort(priv); 502 iwl_send_scan_abort(priv);
505 mutex_unlock(&priv->mutex); 503 mutex_unlock(&priv->mutex);
506} 504}
507EXPORT_SYMBOL(iwl_bg_abort_scan);
508 505
509void iwl_bg_scan_completed(struct work_struct *work) 506static void iwl_bg_scan_completed(struct work_struct *work)
510{ 507{
511 struct iwl_priv *priv = 508 struct iwl_priv *priv =
512 container_of(work, struct iwl_priv, scan_completed); 509 container_of(work, struct iwl_priv, scan_completed);
513 bool internal = false; 510 bool internal = false;
511 bool scan_completed = false;
514 512
515 IWL_DEBUG_SCAN(priv, "SCAN complete scan\n"); 513 IWL_DEBUG_SCAN(priv, "SCAN complete scan\n");
516 514
@@ -521,7 +519,8 @@ void iwl_bg_scan_completed(struct work_struct *work)
521 priv->is_internal_short_scan = false; 519 priv->is_internal_short_scan = false;
522 IWL_DEBUG_SCAN(priv, "internal short scan completed\n"); 520 IWL_DEBUG_SCAN(priv, "internal short scan completed\n");
523 internal = true; 521 internal = true;
524 } else { 522 } else if (priv->scan_request) {
523 scan_completed = true;
525 priv->scan_request = NULL; 524 priv->scan_request = NULL;
526 priv->scan_vif = NULL; 525 priv->scan_vif = NULL;
527 } 526 }
@@ -552,10 +551,9 @@ void iwl_bg_scan_completed(struct work_struct *work)
552 * into driver again into functions that will attempt to take 551 * into driver again into functions that will attempt to take
553 * mutex. 552 * mutex.
554 */ 553 */
555 if (!internal) 554 if (scan_completed)
556 ieee80211_scan_completed(priv->hw, false); 555 ieee80211_scan_completed(priv->hw, false);
557} 556}
558EXPORT_SYMBOL(iwl_bg_scan_completed);
559 557
560void iwl_setup_scan_deferred_work(struct iwl_priv *priv) 558void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
561{ 559{
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 7e0829be5e78..d5e8db37b86e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -818,7 +818,7 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
818 818
819 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 819 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
820 keyconf->hw_key_idx = HW_KEY_DEFAULT; 820 keyconf->hw_key_idx = HW_KEY_DEFAULT;
821 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; 821 priv->stations[IWL_AP_ID].keyinfo.cipher = keyconf->cipher;
822 822
823 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; 823 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
824 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, 824 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
@@ -856,7 +856,7 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
856 856
857 spin_lock_irqsave(&priv->sta_lock, flags); 857 spin_lock_irqsave(&priv->sta_lock, flags);
858 858
859 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 859 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
860 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; 860 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
861 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; 861 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
862 862
@@ -906,7 +906,7 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
906 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 906 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
907 907
908 spin_lock_irqsave(&priv->sta_lock, flags); 908 spin_lock_irqsave(&priv->sta_lock, flags);
909 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 909 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
910 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; 910 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
911 911
912 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 912 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
@@ -955,7 +955,7 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
955 955
956 spin_lock_irqsave(&priv->sta_lock, flags); 956 spin_lock_irqsave(&priv->sta_lock, flags);
957 957
958 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 958 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
959 priv->stations[sta_id].keyinfo.keylen = 16; 959 priv->stations[sta_id].keyinfo.keylen = 16;
960 960
961 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) 961 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
@@ -1090,24 +1090,26 @@ int iwl_set_dynamic_key(struct iwl_priv *priv,
1090 priv->key_mapping_key++; 1090 priv->key_mapping_key++;
1091 keyconf->hw_key_idx = HW_KEY_DYNAMIC; 1091 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1092 1092
1093 switch (keyconf->alg) { 1093 switch (keyconf->cipher) {
1094 case ALG_CCMP: 1094 case WLAN_CIPHER_SUITE_CCMP:
1095 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); 1095 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
1096 break; 1096 break;
1097 case ALG_TKIP: 1097 case WLAN_CIPHER_SUITE_TKIP:
1098 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); 1098 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
1099 break; 1099 break;
1100 case ALG_WEP: 1100 case WLAN_CIPHER_SUITE_WEP40:
1101 case WLAN_CIPHER_SUITE_WEP104:
1101 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); 1102 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
1102 break; 1103 break;
1103 default: 1104 default:
1104 IWL_ERR(priv, 1105 IWL_ERR(priv,
1105 "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); 1106 "Unknown alg: %s cipher = %x\n", __func__,
1107 keyconf->cipher);
1106 ret = -EINVAL; 1108 ret = -EINVAL;
1107 } 1109 }
1108 1110
1109 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", 1111 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
1110 keyconf->alg, keyconf->keylen, keyconf->keyidx, 1112 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
1111 sta_id, ret); 1113 sta_id, ret);
1112 1114
1113 return ret; 1115 return ret;
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index a81989c06983..c308dab14673 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -422,6 +422,7 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
422 int len; 422 int len;
423 u32 idx; 423 u32 idx;
424 u16 fix_size; 424 u16 fix_size;
425 bool is_ct_kill = false;
425 426
426 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len); 427 cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
427 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); 428 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
@@ -443,9 +444,11 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
443 444
444 if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) { 445 if (iwl_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
445 IWL_ERR(priv, "No space in command queue\n"); 446 IWL_ERR(priv, "No space in command queue\n");
446 if (iwl_within_ct_kill_margin(priv)) 447 if (priv->cfg->ops->lib->tt_ops.ct_kill_check) {
447 iwl_tt_enter_ct_kill(priv); 448 is_ct_kill =
448 else { 449 priv->cfg->ops->lib->tt_ops.ct_kill_check(priv);
450 }
451 if (!is_ct_kill) {
449 IWL_ERR(priv, "Restarting adapter due to queue full\n"); 452 IWL_ERR(priv, "Restarting adapter due to queue full\n");
450 queue_work(priv->workqueue, &priv->restart); 453 queue_work(priv->workqueue, &priv->restart);
451 } 454 }
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 59a308b02f95..94d7e6e1323d 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci-aspm.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
38#include <linux/delay.h> 39#include <linux/delay.h>
@@ -151,7 +152,7 @@ static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
151 key_flags &= ~STA_KEY_FLG_INVALID; 152 key_flags &= ~STA_KEY_FLG_INVALID;
152 153
153 spin_lock_irqsave(&priv->sta_lock, flags); 154 spin_lock_irqsave(&priv->sta_lock, flags);
154 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 155 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
155 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; 156 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
156 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 157 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
157 keyconf->keylen); 158 keyconf->keylen);
@@ -222,23 +223,25 @@ static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
222 223
223 keyconf->hw_key_idx = HW_KEY_DYNAMIC; 224 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
224 225
225 switch (keyconf->alg) { 226 switch (keyconf->cipher) {
226 case ALG_CCMP: 227 case WLAN_CIPHER_SUITE_CCMP:
227 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); 228 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
228 break; 229 break;
229 case ALG_TKIP: 230 case WLAN_CIPHER_SUITE_TKIP:
230 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id); 231 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
231 break; 232 break;
232 case ALG_WEP: 233 case WLAN_CIPHER_SUITE_WEP40:
234 case WLAN_CIPHER_SUITE_WEP104:
233 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id); 235 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
234 break; 236 break;
235 default: 237 default:
236 IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); 238 IWL_ERR(priv, "Unknown alg: %s alg=%x\n", __func__,
239 keyconf->cipher);
237 ret = -EINVAL; 240 ret = -EINVAL;
238 } 241 }
239 242
240 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", 243 IWL_DEBUG_WEP(priv, "Set dynamic key: alg=%x len=%d idx=%d sta=%d ret=%d\n",
241 keyconf->alg, keyconf->keylen, keyconf->keyidx, 244 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
242 sta_id, ret); 245 sta_id, ret);
243 246
244 return ret; 247 return ret;
@@ -254,10 +257,11 @@ static int iwl3945_remove_static_key(struct iwl_priv *priv)
254static int iwl3945_set_static_key(struct iwl_priv *priv, 257static int iwl3945_set_static_key(struct iwl_priv *priv,
255 struct ieee80211_key_conf *key) 258 struct ieee80211_key_conf *key)
256{ 259{
257 if (key->alg == ALG_WEP) 260 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
261 key->cipher == WLAN_CIPHER_SUITE_WEP104)
258 return -EOPNOTSUPP; 262 return -EOPNOTSUPP;
259 263
260 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg); 264 IWL_ERR(priv, "Static key invalid: cipher %x\n", key->cipher);
261 return -EINVAL; 265 return -EINVAL;
262} 266}
263 267
@@ -369,23 +373,25 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
369 struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload; 373 struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
370 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; 374 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
371 375
372 switch (keyinfo->alg) { 376 tx_cmd->sec_ctl = 0;
373 case ALG_CCMP: 377
378 switch (keyinfo->cipher) {
379 case WLAN_CIPHER_SUITE_CCMP:
374 tx_cmd->sec_ctl = TX_CMD_SEC_CCM; 380 tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
375 memcpy(tx_cmd->key, keyinfo->key, keyinfo->keylen); 381 memcpy(tx_cmd->key, keyinfo->key, keyinfo->keylen);
376 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n"); 382 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
377 break; 383 break;
378 384
379 case ALG_TKIP: 385 case WLAN_CIPHER_SUITE_TKIP:
380 break; 386 break;
381 387
382 case ALG_WEP: 388 case WLAN_CIPHER_SUITE_WEP104:
383 tx_cmd->sec_ctl = TX_CMD_SEC_WEP | 389 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
390 /* fall through */
391 case WLAN_CIPHER_SUITE_WEP40:
392 tx_cmd->sec_ctl |= TX_CMD_SEC_WEP |
384 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; 393 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
385 394
386 if (keyinfo->keylen == 13)
387 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
388
389 memcpy(&tx_cmd->key[3], keyinfo->key, keyinfo->keylen); 395 memcpy(&tx_cmd->key[3], keyinfo->key, keyinfo->keylen);
390 396
391 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption " 397 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
@@ -393,7 +399,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
393 break; 399 break;
394 400
395 default: 401 default:
396 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); 402 IWL_ERR(priv, "Unknown encode cipher %x\n", keyinfo->cipher);
397 break; 403 break;
398 } 404 }
399} 405}
@@ -813,9 +819,9 @@ static void iwl3945_bg_beacon_update(struct work_struct *work)
813static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, 819static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
814 struct iwl_rx_mem_buffer *rxb) 820 struct iwl_rx_mem_buffer *rxb)
815{ 821{
816#ifdef CONFIG_IWLWIFI_DEBUG
817 struct iwl_rx_packet *pkt = rxb_addr(rxb); 822 struct iwl_rx_packet *pkt = rxb_addr(rxb);
818 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); 823 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
824#ifdef CONFIG_IWLWIFI_DEBUG
819 u8 rate = beacon->beacon_notify_hdr.rate; 825 u8 rate = beacon->beacon_notify_hdr.rate;
820 826
821 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d " 827 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
@@ -827,6 +833,8 @@ static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
827 le32_to_cpu(beacon->low_tsf), rate); 833 le32_to_cpu(beacon->low_tsf), rate);
828#endif 834#endif
829 835
836 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
837
830 if ((priv->iw_mode == NL80211_IFTYPE_AP) && 838 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
831 (!test_bit(STATUS_EXIT_PENDING, &priv->status))) 839 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
832 queue_work(priv->workqueue, &priv->beacon_update); 840 queue_work(priv->workqueue, &priv->beacon_update);
@@ -3086,10 +3094,7 @@ void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3086 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3094 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3087 iwlcore_commit_rxon(priv); 3095 iwlcore_commit_rxon(priv);
3088 3096
3089 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3097 rc = iwl_send_rxon_timing(priv, vif);
3090 iwl_setup_rxon_timing(priv, vif);
3091 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3092 sizeof(priv->rxon_timing), &priv->rxon_timing);
3093 if (rc) 3098 if (rc)
3094 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3099 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3095 "Attempting to continue.\n"); 3100 "Attempting to continue.\n");
@@ -3263,11 +3268,7 @@ void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
3263 iwlcore_commit_rxon(priv); 3268 iwlcore_commit_rxon(priv);
3264 3269
3265 /* RXON Timing */ 3270 /* RXON Timing */
3266 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3271 rc = iwl_send_rxon_timing(priv, vif);
3267 iwl_setup_rxon_timing(priv, vif);
3268 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3269 sizeof(priv->rxon_timing),
3270 &priv->rxon_timing);
3271 if (rc) 3272 if (rc)
3272 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3273 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3273 "Attempting to continue.\n"); 3274 "Attempting to continue.\n");
@@ -3785,10 +3786,8 @@ static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
3785 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); 3786 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
3786 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); 3787 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
3787 INIT_DELAYED_WORK(&priv->_3945.rfkill_poll, iwl3945_rfkill_poll); 3788 INIT_DELAYED_WORK(&priv->_3945.rfkill_poll, iwl3945_rfkill_poll);
3788 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); 3789
3789 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); 3790 iwl_setup_scan_deferred_work(priv);
3790 INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan);
3791 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
3792 3791
3793 iwl3945_hw_setup_deferred_work(priv); 3792 iwl3945_hw_setup_deferred_work(priv);
3794 3793
@@ -3853,6 +3852,7 @@ static struct ieee80211_ops iwl3945_hw_ops = {
3853 .hw_scan = iwl_mac_hw_scan, 3852 .hw_scan = iwl_mac_hw_scan,
3854 .sta_add = iwl3945_mac_sta_add, 3853 .sta_add = iwl3945_mac_sta_add,
3855 .sta_remove = iwl_mac_sta_remove, 3854 .sta_remove = iwl_mac_sta_remove,
3855 .tx_last_beacon = iwl_mac_tx_last_beacon,
3856}; 3856};
3857 3857
3858static int iwl3945_init_drv(struct iwl_priv *priv) 3858static int iwl3945_init_drv(struct iwl_priv *priv)
@@ -4009,6 +4009,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4009 /*************************** 4009 /***************************
4010 * 2. Initializing PCI bus 4010 * 2. Initializing PCI bus
4011 * *************************/ 4011 * *************************/
4012 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
4013 PCIE_LINK_STATE_CLKPM);
4014
4012 if (pci_enable_device(pdev)) { 4015 if (pci_enable_device(pdev)) {
4013 err = -ENODEV; 4016 err = -ENODEV;
4014 goto out_ieee80211_free_hw; 4017 goto out_ieee80211_free_hw;