diff options
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-power.c')
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-power.c | 809 |
1 files changed, 143 insertions, 666 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c index cda6a94d6cc9..595c930b28ae 100644 --- a/drivers/net/wireless/iwlwifi/iwl-power.c +++ b/drivers/net/wireless/iwlwifi/iwl-power.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | * |
3 | * Copyright(c) 2007 - 2010 Intel Corporation. All rights reserved. | 3 | * Copyright(c) 2007 - 2011 Intel Corporation. All rights reserved. |
4 | * | 4 | * |
5 | * Portions of this file are derived from the ipw3945 project, as well | 5 | * Portions of this file are derived from the ipw3945 project, as well |
6 | * as portions of the ieee80211 subsystem header files. | 6 | * as portions of the ieee80211 subsystem header files. |
@@ -75,6 +75,10 @@ struct iwl_power_vec_entry { | |||
75 | 75 | ||
76 | #define NOSLP cpu_to_le16(0), 0, 0 | 76 | #define NOSLP cpu_to_le16(0), 0, 0 |
77 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 | 77 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
78 | #define ASLP (IWL_POWER_POWER_SAVE_ENA_MSK | \ | ||
79 | IWL_POWER_POWER_MANAGEMENT_ENA_MSK | \ | ||
80 | IWL_POWER_ADVANCE_PM_ENA_MSK) | ||
81 | #define ASLP_TOUT(T) cpu_to_le32(T) | ||
78 | #define TU_TO_USEC 1024 | 82 | #define TU_TO_USEC 1024 |
79 | #define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC) | 83 | #define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC) |
80 | #define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \ | 84 | #define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \ |
@@ -114,6 +118,52 @@ static const struct iwl_power_vec_entry range_2[IWL_POWER_NUM] = { | |||
114 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} | 118 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
115 | }; | 119 | }; |
116 | 120 | ||
121 | /* advance power management */ | ||
122 | /* DTIM 0 - 2 */ | ||
123 | static const struct iwl_power_vec_entry apm_range_0[IWL_POWER_NUM] = { | ||
124 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
125 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
126 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
127 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
128 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
129 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
130 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
131 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
132 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
133 | SLP_VEC(1, 2, 6, 8, 0xFF), ASLP_TOUT(2)}, 2} | ||
134 | }; | ||
135 | |||
136 | |||
137 | /* for DTIM period IWL_DTIM_RANGE_0_MAX + 1 through IWL_DTIM_RANGE_1_MAX */ | ||
138 | /* DTIM 3 - 10 */ | ||
139 | static const struct iwl_power_vec_entry apm_range_1[IWL_POWER_NUM] = { | ||
140 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
141 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
142 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
143 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
144 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
145 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
146 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
147 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
148 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
149 | SLP_VEC(1, 2, 6, 8, 0xFF), 0}, 2} | ||
150 | }; | ||
151 | |||
152 | /* for DTIM period > IWL_DTIM_RANGE_1_MAX */ | ||
153 | /* DTIM 11 - */ | ||
154 | static const struct iwl_power_vec_entry apm_range_2[IWL_POWER_NUM] = { | ||
155 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
156 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
157 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
158 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
159 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
160 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
161 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
162 | SLP_VEC(1, 2, 4, 6, 0xFF), 0}, 0}, | ||
163 | {{ASLP, 0, 0, ASLP_TOUT(50), ASLP_TOUT(50), | ||
164 | SLP_VEC(1, 2, 6, 8, 0xFF), ASLP_TOUT(2)}, 2} | ||
165 | }; | ||
166 | |||
117 | static void iwl_static_sleep_cmd(struct iwl_priv *priv, | 167 | static void iwl_static_sleep_cmd(struct iwl_priv *priv, |
118 | struct iwl_powertable_cmd *cmd, | 168 | struct iwl_powertable_cmd *cmd, |
119 | enum iwl_power_level lvl, int period) | 169 | enum iwl_power_level lvl, int period) |
@@ -124,15 +174,24 @@ static void iwl_static_sleep_cmd(struct iwl_priv *priv, | |||
124 | u8 skip; | 174 | u8 skip; |
125 | u32 slp_itrvl; | 175 | u32 slp_itrvl; |
126 | 176 | ||
127 | table = range_2; | 177 | if (priv->cfg->adv_pm) { |
128 | if (period <= IWL_DTIM_RANGE_1_MAX) | 178 | table = apm_range_2; |
129 | table = range_1; | 179 | if (period <= IWL_DTIM_RANGE_1_MAX) |
130 | if (period <= IWL_DTIM_RANGE_0_MAX) | 180 | table = apm_range_1; |
131 | table = range_0; | 181 | if (period <= IWL_DTIM_RANGE_0_MAX) |
132 | 182 | table = apm_range_0; | |
133 | BUG_ON(lvl < 0 || lvl >= IWL_POWER_NUM); | 183 | } else { |
184 | table = range_2; | ||
185 | if (period <= IWL_DTIM_RANGE_1_MAX) | ||
186 | table = range_1; | ||
187 | if (period <= IWL_DTIM_RANGE_0_MAX) | ||
188 | table = range_0; | ||
189 | } | ||
134 | 190 | ||
135 | *cmd = table[lvl].cmd; | 191 | if (WARN_ON(lvl < 0 || lvl >= IWL_POWER_NUM)) |
192 | memset(cmd, 0, sizeof(*cmd)); | ||
193 | else | ||
194 | *cmd = table[lvl].cmd; | ||
136 | 195 | ||
137 | if (period == 0) { | 196 | if (period == 0) { |
138 | skip = 0; | 197 | skip = 0; |
@@ -163,6 +222,19 @@ static void iwl_static_sleep_cmd(struct iwl_priv *priv, | |||
163 | else | 222 | else |
164 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; | 223 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
165 | 224 | ||
225 | if (priv->cfg->base_params->shadow_reg_enable) | ||
226 | cmd->flags |= IWL_POWER_SHADOW_REG_ENA; | ||
227 | else | ||
228 | cmd->flags &= ~IWL_POWER_SHADOW_REG_ENA; | ||
229 | |||
230 | if (iwl_advanced_bt_coexist(priv)) { | ||
231 | if (!priv->cfg->bt_params->bt_sco_disable) | ||
232 | cmd->flags |= IWL_POWER_BT_SCO_ENA; | ||
233 | else | ||
234 | cmd->flags &= ~IWL_POWER_BT_SCO_ENA; | ||
235 | } | ||
236 | |||
237 | |||
166 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); | 238 | slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]); |
167 | if (slp_itrvl > IWL_CONN_MAX_LISTEN_INTERVAL) | 239 | if (slp_itrvl > IWL_CONN_MAX_LISTEN_INTERVAL) |
168 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = | 240 | cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] = |
@@ -192,47 +264,6 @@ static void iwl_static_sleep_cmd(struct iwl_priv *priv, | |||
192 | IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); | 264 | IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1); |
193 | } | 265 | } |
194 | 266 | ||
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 | */ | ||
206 | static 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 | }; | ||
211 | static 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 | }; | ||
216 | static 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 | }; | ||
221 | static 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 */ | ||
228 | static 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 | |||
236 | static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, | 267 | static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv, |
237 | struct iwl_powertable_cmd *cmd) | 268 | struct iwl_powertable_cmd *cmd) |
238 | { | 269 | { |
@@ -277,6 +308,18 @@ static void iwl_power_fill_sleep_cmd(struct iwl_priv *priv, | |||
277 | if (priv->power_data.pci_pm) | 308 | if (priv->power_data.pci_pm) |
278 | cmd->flags |= IWL_POWER_PCI_PM_MSK; | 309 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
279 | 310 | ||
311 | if (priv->cfg->base_params->shadow_reg_enable) | ||
312 | cmd->flags |= IWL_POWER_SHADOW_REG_ENA; | ||
313 | else | ||
314 | cmd->flags &= ~IWL_POWER_SHADOW_REG_ENA; | ||
315 | |||
316 | if (iwl_advanced_bt_coexist(priv)) { | ||
317 | if (!priv->cfg->bt_params->bt_sco_disable) | ||
318 | cmd->flags |= IWL_POWER_BT_SCO_ENA; | ||
319 | else | ||
320 | cmd->flags &= ~IWL_POWER_BT_SCO_ENA; | ||
321 | } | ||
322 | |||
280 | cmd->rx_data_timeout = cpu_to_le32(1000 * dynps_ms); | 323 | cmd->rx_data_timeout = cpu_to_le32(1000 * dynps_ms); |
281 | cmd->tx_data_timeout = cpu_to_le32(1000 * dynps_ms); | 324 | cmd->tx_data_timeout = cpu_to_le32(1000 * dynps_ms); |
282 | 325 | ||
@@ -304,654 +347,89 @@ static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd) | |||
304 | sizeof(struct iwl_powertable_cmd), cmd); | 347 | sizeof(struct iwl_powertable_cmd), cmd); |
305 | } | 348 | } |
306 | 349 | ||
307 | /* priv->mutex must be held */ | 350 | static void iwl_power_build_cmd(struct iwl_priv *priv, |
308 | int iwl_power_update_mode(struct iwl_priv *priv, bool force) | 351 | struct iwl_powertable_cmd *cmd) |
309 | { | 352 | { |
310 | int ret = 0; | ||
311 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | ||
312 | bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS; | 353 | bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS; |
313 | bool update_chains; | ||
314 | struct iwl_powertable_cmd cmd; | ||
315 | int dtimper; | 354 | int dtimper; |
316 | 355 | ||
317 | /* Don't update the RX chain when chain noise calibration is running */ | ||
318 | update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || | ||
319 | priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; | ||
320 | |||
321 | dtimper = priv->hw->conf.ps_dtim_period ?: 1; | 356 | dtimper = priv->hw->conf.ps_dtim_period ?: 1; |
322 | 357 | ||
323 | if (priv->cfg->broken_powersave) | 358 | if (priv->hw->conf.flags & IEEE80211_CONF_IDLE) |
324 | iwl_power_sleep_cam_cmd(priv, &cmd); | 359 | iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_5, 20); |
325 | else if (priv->cfg->supports_idle && | 360 | else if (iwl_tt_is_low_power_state(priv)) { |
326 | priv->hw->conf.flags & IEEE80211_CONF_IDLE) | 361 | /* in thermal throttling low power state */ |
327 | iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_5, 20); | 362 | iwl_static_sleep_cmd(priv, cmd, |
328 | else if (tt->state >= IWL_TI_1) | 363 | iwl_tt_current_power_mode(priv), dtimper); |
329 | iwl_static_sleep_cmd(priv, &cmd, tt->tt_power_mode, dtimper); | 364 | } else if (!enabled) |
330 | else if (!enabled) | 365 | iwl_power_sleep_cam_cmd(priv, cmd); |
331 | iwl_power_sleep_cam_cmd(priv, &cmd); | ||
332 | else if (priv->power_data.debug_sleep_level_override >= 0) | 366 | else if (priv->power_data.debug_sleep_level_override >= 0) |
333 | iwl_static_sleep_cmd(priv, &cmd, | 367 | iwl_static_sleep_cmd(priv, cmd, |
334 | priv->power_data.debug_sleep_level_override, | 368 | priv->power_data.debug_sleep_level_override, |
335 | dtimper); | 369 | dtimper); |
336 | else if (no_sleep_autoadjust) | 370 | else if (no_sleep_autoadjust) |
337 | iwl_static_sleep_cmd(priv, &cmd, IWL_POWER_INDEX_1, dtimper); | 371 | iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_1, dtimper); |
338 | else | 372 | else |
339 | iwl_power_fill_sleep_cmd(priv, &cmd, | 373 | iwl_power_fill_sleep_cmd(priv, cmd, |
340 | priv->hw->conf.dynamic_ps_timeout, | 374 | priv->hw->conf.dynamic_ps_timeout, |
341 | priv->hw->conf.max_sleep_period); | 375 | priv->hw->conf.max_sleep_period); |
342 | |||
343 | if (iwl_is_ready_rf(priv) && | ||
344 | (memcmp(&priv->power_data.sleep_cmd, &cmd, sizeof(cmd)) || force)) { | ||
345 | if (cmd.flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK) | ||
346 | set_bit(STATUS_POWER_PMI, &priv->status); | ||
347 | |||
348 | ret = iwl_set_power(priv, &cmd); | ||
349 | if (!ret) { | ||
350 | if (!(cmd.flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK)) | ||
351 | clear_bit(STATUS_POWER_PMI, &priv->status); | ||
352 | |||
353 | if (priv->cfg->ops->lib->update_chain_flags && | ||
354 | update_chains) | ||
355 | priv->cfg->ops->lib->update_chain_flags(priv); | ||
356 | else if (priv->cfg->ops->lib->update_chain_flags) | ||
357 | IWL_DEBUG_POWER(priv, | ||
358 | "Cannot update the power, chain noise " | ||
359 | "calibration running: %d\n", | ||
360 | priv->chain_noise_data.state); | ||
361 | memcpy(&priv->power_data.sleep_cmd, &cmd, sizeof(cmd)); | ||
362 | } else | ||
363 | IWL_ERR(priv, "set power fail, ret = %d", ret); | ||
364 | } | ||
365 | |||
366 | return ret; | ||
367 | } | ||
368 | EXPORT_SYMBOL(iwl_power_update_mode); | ||
369 | |||
370 | bool 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 | } | ||
380 | EXPORT_SYMBOL(iwl_ht_enabled); | ||
381 | |||
382 | bool 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 | } | 376 | } |
398 | 377 | ||
399 | enum iwl_antenna_ok iwl_tx_ant_restriction(struct iwl_priv *priv) | 378 | int iwl_power_set_mode(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd, |
379 | bool force) | ||
400 | { | 380 | { |
401 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | 381 | int ret; |
402 | struct iwl_tt_restriction *restriction; | 382 | bool update_chains; |
403 | 383 | ||
404 | if (!priv->thermal_throttle.advanced_tt) | 384 | lockdep_assert_held(&priv->mutex); |
405 | return IWL_ANT_OK_MULTI; | ||
406 | restriction = tt->restriction + tt->state; | ||
407 | return restriction->tx_stream; | ||
408 | } | ||
409 | EXPORT_SYMBOL(iwl_tx_ant_restriction); | ||
410 | 385 | ||
411 | enum iwl_antenna_ok iwl_rx_ant_restriction(struct iwl_priv *priv) | 386 | /* Don't update the RX chain when chain noise calibration is running */ |
412 | { | 387 | update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || |
413 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | 388 | priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; |
414 | struct iwl_tt_restriction *restriction; | ||
415 | 389 | ||
416 | if (!priv->thermal_throttle.advanced_tt) | 390 | if (!memcmp(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)) && !force) |
417 | return IWL_ANT_OK_MULTI; | 391 | return 0; |
418 | restriction = tt->restriction + tt->state; | ||
419 | return restriction->rx_stream; | ||
420 | } | ||
421 | 392 | ||
422 | #define CT_KILL_EXIT_DURATION (5) /* 5 seconds duration */ | 393 | if (!iwl_is_ready_rf(priv)) |
423 | #define CT_KILL_WAITING_DURATION (300) /* 300ms duration */ | 394 | return -EIO; |
424 | 395 | ||
425 | /* | 396 | /* scan complete use sleep_power_next, need to be updated */ |
426 | * toggle the bit to wake up uCode and check the temperature | 397 | memcpy(&priv->power_data.sleep_cmd_next, cmd, sizeof(*cmd)); |
427 | * if the temperature is below CT, uCode will stay awake and send card | 398 | if (test_bit(STATUS_SCANNING, &priv->status) && !force) { |
428 | * state notification with CT_KILL bit clear to inform Thermal Throttling | 399 | IWL_DEBUG_INFO(priv, "Defer power set mode while scanning\n"); |
429 | * Management to change state. Otherwise, uCode will go back to sleep | 400 | return 0; |
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 | */ | ||
433 | static 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 | } | 401 | } |
465 | } | ||
466 | 402 | ||
467 | static void iwl_perform_ct_kill_task(struct iwl_priv *priv, | 403 | if (cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK) |
468 | bool stop) | 404 | set_bit(STATUS_POWER_PMI, &priv->status); |
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 | |||
485 | static 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 | |||
502 | static 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 | 405 | ||
516 | /* | 406 | ret = iwl_set_power(priv, cmd); |
517 | * Legacy thermal throttling | 407 | if (!ret) { |
518 | * 1) Avoid NIC destruction due to high temperatures | 408 | if (!(cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK)) |
519 | * Chip will identify dangerously high temperatures that can | 409 | clear_bit(STATUS_POWER_PMI, &priv->status); |
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 | */ | ||
525 | static 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 | 410 | ||
609 | /* | 411 | if (priv->cfg->ops->lib->update_chain_flags && update_chains) |
610 | * Advance thermal throttling | 412 | priv->cfg->ops->lib->update_chain_flags(priv); |
611 | * 1) Avoid NIC destruction due to high temperatures | 413 | else if (priv->cfg->ops->lib->update_chain_flags) |
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 | */ | ||
630 | static 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, | 414 | IWL_DEBUG_POWER(priv, |
722 | "Thermal Throttling to new state: %u\n", | 415 | "Cannot update the power, chain noise " |
723 | tt->state); | 416 | "calibration running: %d\n", |
724 | if (old_state != IWL_TI_CT_KILL && | 417 | priv->chain_noise_data.state); |
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 | */ | ||
755 | static 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 | */ | ||
784 | static 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 | |||
817 | void 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 | } | ||
825 | EXPORT_SYMBOL(iwl_tt_enter_ct_kill); | ||
826 | |||
827 | void 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 | } | ||
835 | EXPORT_SYMBOL(iwl_tt_exit_ct_kill); | ||
836 | |||
837 | static 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 | 418 | ||
854 | void iwl_tt_handler(struct iwl_priv *priv) | 419 | memcpy(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)); |
855 | { | 420 | } else |
856 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | 421 | IWL_ERR(priv, "set power fail, ret = %d", ret); |
857 | return; | ||
858 | 422 | ||
859 | IWL_DEBUG_POWER(priv, "Queueing thermal throttling work.\n"); | 423 | return ret; |
860 | queue_work(priv->workqueue, &priv->tt_work); | ||
861 | } | 424 | } |
862 | EXPORT_SYMBOL(iwl_tt_handler); | ||
863 | 425 | ||
864 | /* Thermal throttling initialization | 426 | int iwl_power_update_mode(struct iwl_priv *priv, bool force) |
865 | * For advance thermal throttling: | ||
866 | * Initialize Thermal Index and temperature threshold table | ||
867 | * Initialize thermal throttling restriction table | ||
868 | */ | ||
869 | void iwl_tt_initialize(struct iwl_priv *priv) | ||
870 | { | 427 | { |
871 | struct iwl_tt_mgmt *tt = &priv->thermal_throttle; | 428 | struct iwl_powertable_cmd cmd; |
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 | } | ||
931 | EXPORT_SYMBOL(iwl_tt_initialize); | ||
932 | 429 | ||
933 | /* cleanup thermal throttling management related memory and timer */ | 430 | iwl_power_build_cmd(priv, &cmd); |
934 | void iwl_tt_exit(struct iwl_priv *priv) | 431 | return iwl_power_set_mode(priv, &cmd, force); |
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 | } | 432 | } |
954 | EXPORT_SYMBOL(iwl_tt_exit); | ||
955 | 433 | ||
956 | /* initialize to default */ | 434 | /* initialize to default */ |
957 | void iwl_power_initialize(struct iwl_priv *priv) | 435 | void iwl_power_initialize(struct iwl_priv *priv) |
@@ -965,4 +443,3 @@ void iwl_power_initialize(struct iwl_priv *priv) | |||
965 | memset(&priv->power_data.sleep_cmd, 0, | 443 | memset(&priv->power_data.sleep_cmd, 0, |
966 | sizeof(priv->power_data.sleep_cmd)); | 444 | sizeof(priv->power_data.sleep_cmd)); |
967 | } | 445 | } |
968 | EXPORT_SYMBOL(iwl_power_initialize); | ||