Lines Matching refs:mvm

11 #include "mvm.h"
15 void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm)
17 struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
20 if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
23 IWL_ERR(mvm, "Enter CT Kill\n");
24 iwl_mvm_set_hw_ctkill_state(mvm, true);
26 if (!iwl_mvm_is_tt_in_fw(mvm)) {
35 if (!mvm->temperature_test)
40 static void iwl_mvm_exit_ctkill(struct iwl_mvm *mvm)
42 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
45 IWL_ERR(mvm, "Exit CT Kill\n");
46 iwl_mvm_set_hw_ctkill_state(mvm, false);
49 static void iwl_mvm_tt_temp_changed(struct iwl_mvm *mvm, u32 temp)
52 if (mvm->temperature_test)
55 if (mvm->temperature == temp)
58 mvm->temperature = temp;
59 iwl_mvm_tt_handler(mvm);
62 static int iwl_mvm_temp_notif_parse(struct iwl_mvm *mvm,
73 IWL_ERR(mvm, "Invalid DTS_MEASUREMENT_NOTIFICATION\n");
85 IWL_DEBUG_TEMP(mvm, "DTS_MEASUREMENT_NOTIFICATION - %d\n", temp);
93 struct iwl_mvm *mvm =
98 ret = iwl_mvm_temp_notif_parse(mvm, pkt);
107 void iwl_mvm_temp_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
116 if (test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status))
119 temp = iwl_mvm_temp_notif_parse(mvm, pkt);
121 if (!iwl_mvm_is_tt_in_fw(mvm)) {
123 iwl_mvm_tt_temp_changed(mvm, temp);
128 IWL_ERR(mvm, "Invalid DTS_MEASUREMENT_NOTIFICATION\n");
141 IWL_DEBUG_TEMP(mvm, "Temp = %d Threshold crossed = %d\n",
148 if (mvm->tz_device.tzone) {
149 struct iwl_mvm_thermal_device *tz_dev = &mvm->tz_device;
157 void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
163 IWL_DEBUG_TEMP(mvm, "CT Kill notification temperature = %d\n",
165 if (iwl_fw_lookup_notif_ver(mvm->fw, PHY_OPS_GROUP,
167 IWL_DEBUG_TEMP(mvm,
171 iwl_mvm_enter_ctkill(mvm);
178 static int iwl_mvm_send_temp_cmd(struct iwl_mvm *mvm, bool response, s32 *temp)
194 if (fw_has_capa(&mvm->fw->ucode_capa,
213 IWL_DEBUG_TEMP(mvm,
216 ret = iwl_mvm_send_cmd(mvm, &cmd);
219 IWL_ERR(mvm,
228 IWL_DEBUG_TEMP(mvm,
237 int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp)
250 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
254 return iwl_mvm_send_temp_cmd(mvm, true, temp);
256 lockdep_assert_held(&mvm->mutex);
258 iwl_init_notification_wait(&mvm->notif_wait, &wait_temp_notif,
262 ret = iwl_mvm_send_temp_cmd(mvm, false, temp);
264 iwl_remove_notification(&mvm->notif_wait, &wait_temp_notif);
268 ret = iwl_wait_notification(&mvm->notif_wait, &wait_temp_notif,
271 IWL_WARN(mvm, "Getting the temperature timed out\n");
279 struct iwl_mvm *mvm;
285 mvm = container_of(tt, struct iwl_mvm, thermal_throttle);
287 if (iwl_mvm_is_tt_in_fw(mvm)) {
288 iwl_mvm_exit_ctkill(mvm);
295 flush_work(&mvm->roc_done_wk);
297 mutex_lock(&mvm->mutex);
299 if (__iwl_mvm_mac_start(mvm))
302 ret = iwl_mvm_get_temp(mvm, &temp);
304 __iwl_mvm_mac_stop(mvm, false);
309 IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", temp);
312 mutex_unlock(&mvm->mutex);
313 iwl_mvm_exit_ctkill(mvm);
318 mutex_unlock(&mvm->mutex);
319 schedule_delayed_work(&mvm->thermal_throttle.ct_kill_exit,
326 struct iwl_mvm *mvm = _data;
329 lockdep_assert_held(&mvm->mutex);
331 if (mvm->thermal_throttle.dynamic_smps)
339 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, smps_mode, 0);
342 static void iwl_mvm_tt_tx_protection(struct iwl_mvm *mvm, bool enable)
347 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
348 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, i);
354 err = iwl_mvm_tx_protection(mvm, mvmsta, enable);
356 IWL_ERR(mvm, "Failed to %s Tx protection\n",
359 IWL_DEBUG_TEMP(mvm, "%s Tx protection\n",
366 void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff)
374 backoff = max(backoff, mvm->thermal_throttle.min_backoff);
376 if (iwl_mvm_send_cmd(mvm, &cmd) == 0) {
377 IWL_DEBUG_TEMP(mvm, "Set Thermal Tx backoff to: %u\n",
379 mvm->thermal_throttle.tx_backoff = backoff;
381 IWL_ERR(mvm, "Failed to change Thermal Tx backoff\n");
385 void iwl_mvm_tt_handler(struct iwl_mvm *mvm)
387 struct iwl_tt_params *params = &mvm->thermal_throttle.params;
388 struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
389 s32 temperature = mvm->temperature;
394 IWL_DEBUG_TEMP(mvm, "NIC temperature: %d\n", mvm->temperature);
397 iwl_mvm_enter_ctkill(mvm);
403 iwl_mvm_exit_ctkill(mvm);
410 IWL_DEBUG_TEMP(mvm, "Enable dynamic SMPS\n");
413 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
414 iwl_mvm_tt_smps_iterator, mvm);
418 IWL_DEBUG_TEMP(mvm, "Disable dynamic SMPS\n");
421 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
422 iwl_mvm_tt_smps_iterator, mvm);
428 iwl_mvm_tt_tx_protection(mvm, true);
431 iwl_mvm_tt_tx_protection(mvm, false);
446 iwl_mvm_tt_tx_backoff(mvm, tx_backoff);
450 IWL_WARN(mvm,
456 IWL_WARN(mvm,
509 int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 state)
519 lockdep_assert_held(&mvm->mutex);
522 ret = iwl_mvm_send_cmd_pdu_status(mvm, WIDE_ID(PHY_OPS_GROUP,
527 IWL_ERR(mvm, "cTDP command failed (err=%d)\n", ret);
534 mvm->cooling_dev.cur_state = state;
538 IWL_DEBUG_TEMP(mvm, "cTDP avg energy in mWatt = %d\n", status);
547 IWL_DEBUG_TEMP(mvm, "cTDP stopped successfully\n");
578 int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm)
585 lockdep_assert_held(&mvm->mutex);
587 if (!mvm->tz_device.tzone)
597 for_each_thermal_trip(mvm->tz_device.tzone, iwl_trip_temp_cb, &twd);
605 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(PHY_OPS_GROUP,
609 IWL_ERR(mvm, "TEMP_REPORT_THS_CMD command failed (err=%d)\n",
619 struct iwl_mvm *mvm = thermal_zone_device_priv(device);
623 guard(mvm)(mvm);
625 if (!iwl_mvm_firmware_running(mvm) ||
626 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) {
635 ret = iwl_mvm_get_temp(mvm, &temp);
646 struct iwl_mvm *mvm = thermal_zone_device_priv(device);
648 guard(mvm)(mvm);
650 if (!iwl_mvm_firmware_running(mvm) ||
651 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
657 return iwl_mvm_send_temp_report_ths_cmd(mvm);
665 static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm)
671 if (!iwl_mvm_is_tt_in_fw(mvm)) {
672 mvm->tz_device.tzone = NULL;
685 mvm->tz_device.trips[i].temperature = THERMAL_TEMP_INVALID;
686 mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE;
687 mvm->tz_device.trips[i].flags = THERMAL_TRIP_FLAG_RW_TEMP;
689 mvm->tz_device.tzone = thermal_zone_device_register_with_trips(name,
690 mvm->tz_device.trips,
692 mvm, &tzone_ops,
694 if (IS_ERR(mvm->tz_device.tzone)) {
695 IWL_DEBUG_TEMP(mvm,
697 PTR_ERR(mvm->tz_device.tzone));
698 mvm->tz_device.tzone = NULL;
702 ret = thermal_zone_device_enable(mvm->tz_device.tzone);
704 IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n");
705 thermal_zone_device_unregister(mvm->tz_device.tzone);
720 struct iwl_mvm *mvm = (struct iwl_mvm *)(cdev->devdata);
722 *state = mvm->cooling_dev.cur_state;
730 struct iwl_mvm *mvm = (struct iwl_mvm *)(cdev->devdata);
732 guard(mvm)(mvm);
734 if (!iwl_mvm_firmware_running(mvm) ||
735 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
741 return iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
751 static void iwl_mvm_cooling_device_register(struct iwl_mvm *mvm)
755 if (!iwl_mvm_is_ctdp_supported(mvm))
760 mvm->cooling_dev.cdev =
762 mvm,
765 if (IS_ERR(mvm->cooling_dev.cdev)) {
766 IWL_DEBUG_TEMP(mvm,
768 PTR_ERR(mvm->cooling_dev.cdev));
769 mvm->cooling_dev.cdev = NULL;
774 static void iwl_mvm_thermal_zone_unregister(struct iwl_mvm *mvm)
776 if (!iwl_mvm_is_tt_in_fw(mvm) || !mvm->tz_device.tzone)
779 IWL_DEBUG_TEMP(mvm, "Thermal zone device unregister\n");
780 if (mvm->tz_device.tzone) {
781 thermal_zone_device_unregister(mvm->tz_device.tzone);
782 mvm->tz_device.tzone = NULL;
786 static void iwl_mvm_cooling_device_unregister(struct iwl_mvm *mvm)
788 if (!iwl_mvm_is_ctdp_supported(mvm) || !mvm->cooling_dev.cdev)
791 IWL_DEBUG_TEMP(mvm, "Cooling device unregister\n");
792 if (mvm->cooling_dev.cdev) {
793 thermal_cooling_device_unregister(mvm->cooling_dev.cdev);
794 mvm->cooling_dev.cdev = NULL;
799 void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff)
801 struct iwl_mvm_tt_mgmt *tt = &mvm->thermal_throttle;
803 IWL_DEBUG_TEMP(mvm, "Initialize Thermal Throttling\n");
805 if (mvm->cfg->thermal_params)
806 tt->params = *mvm->cfg->thermal_params;
816 iwl_mvm_cooling_device_register(mvm);
817 iwl_mvm_thermal_zone_register(mvm);
819 mvm->init_status |= IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE;
822 void iwl_mvm_thermal_exit(struct iwl_mvm *mvm)
824 if (!(mvm->init_status & IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE))
827 cancel_delayed_work_sync(&mvm->thermal_throttle.ct_kill_exit);
828 IWL_DEBUG_TEMP(mvm, "Exit Thermal Throttling\n");
831 iwl_mvm_cooling_device_unregister(mvm);
832 iwl_mvm_thermal_zone_unregister(mvm);
834 mvm->init_status &= ~IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE;