Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
| 26 | * in the file called COPYING. |
| 27 | * |
| 28 | * Contact Information: |
| 29 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | |
| 66 | #include "mvm.h" |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 67 | |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 68 | #define IWL_MVM_TEMP_NOTIF_WAIT_TIMEOUT HZ |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 69 | |
| 70 | static void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm) |
| 71 | { |
| 72 | u32 duration = mvm->thermal_throttle.params->ct_kill_duration; |
| 73 | |
Luciano Coelho | b689fa7 | 2014-08-20 17:26:58 +0300 | [diff] [blame] | 74 | if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) |
| 75 | return; |
| 76 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 77 | IWL_ERR(mvm, "Enter CT Kill\n"); |
| 78 | iwl_mvm_set_hw_ctkill_state(mvm, true); |
Luciano Coelho | efc36db | 2014-08-20 17:58:20 +0300 | [diff] [blame] | 79 | |
| 80 | /* Don't schedule an exit work if we're in test mode, since |
| 81 | * the temperature will not change unless we manually set it |
| 82 | * again (or disable testing). |
| 83 | */ |
| 84 | if (!mvm->temperature_test) |
| 85 | schedule_delayed_work(&mvm->thermal_throttle.ct_kill_exit, |
| 86 | round_jiffies_relative(duration * HZ)); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static void iwl_mvm_exit_ctkill(struct iwl_mvm *mvm) |
| 90 | { |
Luciano Coelho | b689fa7 | 2014-08-20 17:26:58 +0300 | [diff] [blame] | 91 | if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) |
| 92 | return; |
| 93 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 94 | IWL_ERR(mvm, "Exit CT Kill\n"); |
| 95 | iwl_mvm_set_hw_ctkill_state(mvm, false); |
| 96 | } |
| 97 | |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 98 | void iwl_mvm_tt_temp_changed(struct iwl_mvm *mvm, u32 temp) |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 99 | { |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 100 | /* ignore the notification if we are in test mode */ |
| 101 | if (mvm->temperature_test) |
| 102 | return; |
| 103 | |
| 104 | if (mvm->temperature == temp) |
| 105 | return; |
| 106 | |
| 107 | mvm->temperature = temp; |
| 108 | iwl_mvm_tt_handler(mvm); |
| 109 | } |
| 110 | |
| 111 | static int iwl_mvm_temp_notif_parse(struct iwl_mvm *mvm, |
| 112 | struct iwl_rx_packet *pkt) |
| 113 | { |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 114 | struct iwl_dts_measurement_notif *notif; |
| 115 | int len = iwl_rx_packet_payload_len(pkt); |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 116 | int temp; |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 117 | |
| 118 | if (WARN_ON_ONCE(len != sizeof(*notif))) { |
| 119 | IWL_ERR(mvm, "Invalid DTS_MEASUREMENT_NOTIFICATION\n"); |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 120 | return -EINVAL; |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | notif = (void *)pkt->data; |
| 124 | |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 125 | temp = le32_to_cpu(notif->temp); |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 126 | |
| 127 | /* shouldn't be negative, but since it's s32, make sure it isn't */ |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 128 | if (WARN_ON_ONCE(temp < 0)) |
| 129 | temp = 0; |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 130 | |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 131 | IWL_DEBUG_TEMP(mvm, "DTS_MEASUREMENT_NOTIFICATION - %d\n", temp); |
| 132 | |
| 133 | return temp; |
| 134 | } |
| 135 | |
| 136 | static bool iwl_mvm_temp_notif_wait(struct iwl_notif_wait_data *notif_wait, |
| 137 | struct iwl_rx_packet *pkt, void *data) |
| 138 | { |
| 139 | struct iwl_mvm *mvm = |
| 140 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 141 | int *temp = data; |
| 142 | int ret; |
| 143 | |
| 144 | ret = iwl_mvm_temp_notif_parse(mvm, pkt); |
| 145 | if (ret < 0) |
| 146 | return true; |
| 147 | |
| 148 | *temp = ret; |
| 149 | |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | |
Luciano Coelho | ea9af24 | 2014-11-06 10:34:49 +0200 | [diff] [blame] | 153 | int iwl_mvm_temp_notif(struct iwl_mvm *mvm, |
| 154 | struct iwl_rx_cmd_buffer *rxb, |
| 155 | struct iwl_device_cmd *cmd) |
| 156 | { |
| 157 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 158 | int temp; |
| 159 | |
| 160 | /* the notification is handled synchronously in ctkill, so skip here */ |
| 161 | if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) |
| 162 | return 0; |
| 163 | |
| 164 | temp = iwl_mvm_temp_notif_parse(mvm, pkt); |
| 165 | if (temp < 0) |
| 166 | return 0; |
| 167 | |
| 168 | iwl_mvm_tt_temp_changed(mvm, temp); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 173 | static int iwl_mvm_get_temp_cmd(struct iwl_mvm *mvm) |
| 174 | { |
| 175 | struct iwl_dts_measurement_cmd cmd = { |
| 176 | .flags = cpu_to_le32(DTS_TRIGGER_CMD_FLAGS_TEMP), |
| 177 | }; |
| 178 | |
| 179 | return iwl_mvm_send_cmd_pdu(mvm, CMD_DTS_MEASUREMENT_TRIGGER, 0, |
| 180 | sizeof(cmd), &cmd); |
| 181 | } |
| 182 | |
Luciano Coelho | c549e39 | 2014-09-04 15:58:47 +0300 | [diff] [blame] | 183 | int iwl_mvm_get_temp(struct iwl_mvm *mvm) |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 184 | { |
| 185 | struct iwl_notification_wait wait_temp_notif; |
| 186 | static const u8 temp_notif[] = { DTS_MEASUREMENT_NOTIFICATION }; |
| 187 | int ret, temp; |
| 188 | |
| 189 | lockdep_assert_held(&mvm->mutex); |
| 190 | |
| 191 | iwl_init_notification_wait(&mvm->notif_wait, &wait_temp_notif, |
| 192 | temp_notif, ARRAY_SIZE(temp_notif), |
Luciano Coelho | fd1f755 | 2014-11-04 16:17:46 +0200 | [diff] [blame] | 193 | iwl_mvm_temp_notif_wait, &temp); |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 194 | |
| 195 | ret = iwl_mvm_get_temp_cmd(mvm); |
| 196 | if (ret) { |
| 197 | IWL_ERR(mvm, "Failed to get the temperature (err=%d)\n", ret); |
| 198 | iwl_remove_notification(&mvm->notif_wait, &wait_temp_notif); |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_temp_notif, |
| 203 | IWL_MVM_TEMP_NOTIF_WAIT_TIMEOUT); |
| 204 | if (ret) { |
| 205 | IWL_ERR(mvm, "Getting the temperature timed out\n"); |
| 206 | return ret; |
| 207 | } |
| 208 | |
| 209 | return temp; |
| 210 | } |
| 211 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 212 | static void check_exit_ctkill(struct work_struct *work) |
| 213 | { |
| 214 | struct iwl_mvm_tt_mgmt *tt; |
| 215 | struct iwl_mvm *mvm; |
| 216 | u32 duration; |
| 217 | s32 temp; |
| 218 | |
| 219 | tt = container_of(work, struct iwl_mvm_tt_mgmt, ct_kill_exit.work); |
| 220 | mvm = container_of(tt, struct iwl_mvm, thermal_throttle); |
| 221 | |
| 222 | duration = tt->params->ct_kill_duration; |
| 223 | |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 224 | mutex_lock(&mvm->mutex); |
| 225 | |
| 226 | if (__iwl_mvm_mac_start(mvm)) |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 227 | goto reschedule; |
| 228 | |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 229 | /* make sure the device is available for direct read/writes */ |
| 230 | if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_CHECK_CTKILL)) { |
| 231 | __iwl_mvm_mac_stop(mvm); |
| 232 | goto reschedule; |
| 233 | } |
| 234 | |
| 235 | temp = iwl_mvm_get_temp(mvm); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 236 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 237 | iwl_mvm_unref(mvm, IWL_MVM_REF_CHECK_CTKILL); |
| 238 | |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 239 | __iwl_mvm_mac_stop(mvm); |
| 240 | |
| 241 | if (temp < 0) |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 242 | goto reschedule; |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 243 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 244 | IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", temp); |
| 245 | |
| 246 | if (temp <= tt->params->ct_kill_exit) { |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 247 | mutex_unlock(&mvm->mutex); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 248 | iwl_mvm_exit_ctkill(mvm); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | reschedule: |
Luciano Coelho | a0a09243 | 2014-09-04 12:29:15 +0300 | [diff] [blame] | 253 | mutex_unlock(&mvm->mutex); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 254 | schedule_delayed_work(&mvm->thermal_throttle.ct_kill_exit, |
| 255 | round_jiffies(duration * HZ)); |
| 256 | } |
| 257 | |
| 258 | static void iwl_mvm_tt_smps_iterator(void *_data, u8 *mac, |
| 259 | struct ieee80211_vif *vif) |
| 260 | { |
| 261 | struct iwl_mvm *mvm = _data; |
| 262 | enum ieee80211_smps_mode smps_mode; |
| 263 | |
| 264 | lockdep_assert_held(&mvm->mutex); |
| 265 | |
| 266 | if (mvm->thermal_throttle.dynamic_smps) |
| 267 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
| 268 | else |
| 269 | smps_mode = IEEE80211_SMPS_AUTOMATIC; |
| 270 | |
Eytan Lifshitz | fded313 | 2013-06-04 12:28:51 +0300 | [diff] [blame] | 271 | if (vif->type != NL80211_IFTYPE_STATION) |
| 272 | return; |
| 273 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 274 | iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, smps_mode); |
| 275 | } |
| 276 | |
| 277 | static void iwl_mvm_tt_tx_protection(struct iwl_mvm *mvm, bool enable) |
| 278 | { |
| 279 | struct ieee80211_sta *sta; |
| 280 | struct iwl_mvm_sta *mvmsta; |
| 281 | int i, err; |
| 282 | |
| 283 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 284 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 285 | lockdep_is_held(&mvm->mutex)); |
| 286 | if (IS_ERR_OR_NULL(sta)) |
| 287 | continue; |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 288 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 289 | if (enable == mvmsta->tt_tx_protection) |
| 290 | continue; |
Johannes Berg | e126b5d | 2013-06-28 13:39:18 +0200 | [diff] [blame] | 291 | err = iwl_mvm_tx_protection(mvm, mvmsta, enable); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 292 | if (err) { |
| 293 | IWL_ERR(mvm, "Failed to %s Tx protection\n", |
| 294 | enable ? "enable" : "disable"); |
| 295 | } else { |
| 296 | IWL_DEBUG_TEMP(mvm, "%s Tx protection\n", |
| 297 | enable ? "Enable" : "Disable"); |
| 298 | mvmsta->tt_tx_protection = enable; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame] | 303 | void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff) |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 304 | { |
| 305 | struct iwl_host_cmd cmd = { |
| 306 | .id = REPLY_THERMAL_MNG_BACKOFF, |
| 307 | .len = { sizeof(u32), }, |
| 308 | .data = { &backoff, }, |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 309 | }; |
| 310 | |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame] | 311 | backoff = max(backoff, mvm->thermal_throttle.min_backoff); |
| 312 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 313 | if (iwl_mvm_send_cmd(mvm, &cmd) == 0) { |
| 314 | IWL_DEBUG_TEMP(mvm, "Set Thermal Tx backoff to: %u\n", |
| 315 | backoff); |
| 316 | mvm->thermal_throttle.tx_backoff = backoff; |
| 317 | } else { |
| 318 | IWL_ERR(mvm, "Failed to change Thermal Tx backoff\n"); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | void iwl_mvm_tt_handler(struct iwl_mvm *mvm) |
| 323 | { |
| 324 | const struct iwl_tt_params *params = mvm->thermal_throttle.params; |
| 325 | struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle; |
| 326 | s32 temperature = mvm->temperature; |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 327 | bool throttle_enable = false; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 328 | int i; |
| 329 | u32 tx_backoff; |
| 330 | |
| 331 | IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", mvm->temperature); |
| 332 | |
| 333 | if (params->support_ct_kill && temperature >= params->ct_kill_entry) { |
| 334 | iwl_mvm_enter_ctkill(mvm); |
| 335 | return; |
| 336 | } |
| 337 | |
Luciano Coelho | b689fa7 | 2014-08-20 17:26:58 +0300 | [diff] [blame] | 338 | if (params->support_ct_kill && |
| 339 | temperature <= tt->params->ct_kill_exit) { |
| 340 | iwl_mvm_exit_ctkill(mvm); |
| 341 | return; |
| 342 | } |
| 343 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 344 | if (params->support_dynamic_smps) { |
| 345 | if (!tt->dynamic_smps && |
| 346 | temperature >= params->dynamic_smps_entry) { |
| 347 | IWL_DEBUG_TEMP(mvm, "Enable dynamic SMPS\n"); |
| 348 | tt->dynamic_smps = true; |
| 349 | ieee80211_iterate_active_interfaces_atomic( |
| 350 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 351 | iwl_mvm_tt_smps_iterator, mvm); |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 352 | throttle_enable = true; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 353 | } else if (tt->dynamic_smps && |
| 354 | temperature <= params->dynamic_smps_exit) { |
| 355 | IWL_DEBUG_TEMP(mvm, "Disable dynamic SMPS\n"); |
| 356 | tt->dynamic_smps = false; |
| 357 | ieee80211_iterate_active_interfaces_atomic( |
| 358 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 359 | iwl_mvm_tt_smps_iterator, mvm); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (params->support_tx_protection) { |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 364 | if (temperature >= params->tx_protection_entry) { |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 365 | iwl_mvm_tt_tx_protection(mvm, true); |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 366 | throttle_enable = true; |
| 367 | } else if (temperature <= params->tx_protection_exit) { |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 368 | iwl_mvm_tt_tx_protection(mvm, false); |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 369 | } |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (params->support_tx_backoff) { |
Eytan Lifshitz | 1b8ebbd | 2014-04-01 16:44:21 +0300 | [diff] [blame] | 373 | tx_backoff = tt->min_backoff; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 374 | for (i = 0; i < TT_TX_BACKOFF_SIZE; i++) { |
| 375 | if (temperature < params->tx_backoff[i].temperature) |
| 376 | break; |
Eytan Lifshitz | 1b8ebbd | 2014-04-01 16:44:21 +0300 | [diff] [blame] | 377 | tx_backoff = max(tt->min_backoff, |
| 378 | params->tx_backoff[i].backoff); |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 379 | } |
Eytan Lifshitz | 1b8ebbd | 2014-04-01 16:44:21 +0300 | [diff] [blame] | 380 | if (tx_backoff != tt->min_backoff) |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 381 | throttle_enable = true; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 382 | if (tt->tx_backoff != tx_backoff) |
| 383 | iwl_mvm_tt_tx_backoff(mvm, tx_backoff); |
| 384 | } |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 385 | |
| 386 | if (!tt->throttle && throttle_enable) { |
| 387 | IWL_WARN(mvm, |
| 388 | "Due to high temperature thermal throttling initiated\n"); |
| 389 | tt->throttle = true; |
Eytan Lifshitz | 19a04bd | 2014-04-02 21:37:57 +0300 | [diff] [blame] | 390 | } else if (tt->throttle && !tt->dynamic_smps && |
| 391 | tt->tx_backoff == tt->min_backoff && |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 392 | temperature <= params->tx_protection_exit) { |
| 393 | IWL_WARN(mvm, |
| 394 | "Temperature is back to normal thermal throttling stopped\n"); |
| 395 | tt->throttle = false; |
| 396 | } |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static const struct iwl_tt_params iwl7000_tt_params = { |
| 400 | .ct_kill_entry = 118, |
| 401 | .ct_kill_exit = 96, |
| 402 | .ct_kill_duration = 5, |
| 403 | .dynamic_smps_entry = 114, |
| 404 | .dynamic_smps_exit = 110, |
| 405 | .tx_protection_entry = 114, |
| 406 | .tx_protection_exit = 108, |
| 407 | .tx_backoff = { |
| 408 | {.temperature = 112, .backoff = 200}, |
| 409 | {.temperature = 113, .backoff = 600}, |
| 410 | {.temperature = 114, .backoff = 1200}, |
| 411 | {.temperature = 115, .backoff = 2000}, |
| 412 | {.temperature = 116, .backoff = 4000}, |
| 413 | {.temperature = 117, .backoff = 10000}, |
| 414 | }, |
| 415 | .support_ct_kill = true, |
| 416 | .support_dynamic_smps = true, |
| 417 | .support_tx_protection = true, |
| 418 | .support_tx_backoff = true, |
| 419 | }; |
| 420 | |
Eytan Lifshitz | 6be497f | 2013-07-24 14:49:18 +0300 | [diff] [blame] | 421 | static const struct iwl_tt_params iwl7000_high_temp_tt_params = { |
| 422 | .ct_kill_entry = 118, |
| 423 | .ct_kill_exit = 96, |
| 424 | .ct_kill_duration = 5, |
| 425 | .dynamic_smps_entry = 114, |
| 426 | .dynamic_smps_exit = 110, |
| 427 | .tx_protection_entry = 114, |
| 428 | .tx_protection_exit = 108, |
| 429 | .tx_backoff = { |
| 430 | {.temperature = 112, .backoff = 300}, |
| 431 | {.temperature = 113, .backoff = 800}, |
| 432 | {.temperature = 114, .backoff = 1500}, |
| 433 | {.temperature = 115, .backoff = 3000}, |
| 434 | {.temperature = 116, .backoff = 5000}, |
| 435 | {.temperature = 117, .backoff = 10000}, |
| 436 | }, |
| 437 | .support_ct_kill = true, |
| 438 | .support_dynamic_smps = true, |
| 439 | .support_tx_protection = true, |
| 440 | .support_tx_backoff = true, |
| 441 | }; |
| 442 | |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame] | 443 | void iwl_mvm_tt_initialize(struct iwl_mvm *mvm, u32 min_backoff) |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 444 | { |
| 445 | struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle; |
| 446 | |
| 447 | IWL_DEBUG_TEMP(mvm, "Initialize Thermal Throttling\n"); |
Eytan Lifshitz | 6be497f | 2013-07-24 14:49:18 +0300 | [diff] [blame] | 448 | |
| 449 | if (mvm->cfg->high_temp) |
| 450 | tt->params = &iwl7000_high_temp_tt_params; |
| 451 | else |
| 452 | tt->params = &iwl7000_tt_params; |
| 453 | |
eytan lifshitz | dafe6c4 | 2013-06-18 14:28:56 +0300 | [diff] [blame] | 454 | tt->throttle = false; |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame] | 455 | tt->min_backoff = min_backoff; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 456 | INIT_DELAYED_WORK(&tt->ct_kill_exit, check_exit_ctkill); |
| 457 | } |
| 458 | |
| 459 | void iwl_mvm_tt_exit(struct iwl_mvm *mvm) |
| 460 | { |
| 461 | cancel_delayed_work_sync(&mvm->thermal_throttle.ct_kill_exit); |
| 462 | IWL_DEBUG_TEMP(mvm, "Exit Thermal Throttling\n"); |
| 463 | } |