From patchwork Mon Jul 10 10:47:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Austen X-Patchwork-Id: 13306788 X-Patchwork-Delegate: miriam.rachel.korenblit@intel.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69326EB64D9 for ; Mon, 10 Jul 2023 10:47:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbjGJKrN (ORCPT ); Mon, 10 Jul 2023 06:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjGJKrM (ORCPT ); Mon, 10 Jul 2023 06:47:12 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92405B5; Mon, 10 Jul 2023 03:47:10 -0700 (PDT) Date: Mon, 10 Jul 2023 10:47:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1688986028; x=1689245228; bh=JUSxIhlyp5Rsy2QluQCpjPVJMXty3tKlls6ZhMmED8c=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=oGK35t+2jrXUNI7a8SJ7Is0Dge8JAq+HiFi8NW5VHDdxm6M5ZHBMmjd1QYqt27v6x l5TI5rV29lpRsdVb+aDSpjmTyP8ZP7QWFBmlgEmm4IA4OGmNdceNQnME2CH5Qhd6YV tTzMV7HPbfxlhMmcUymsZKC8K5mdWVLpbr5Yy0efHWYhYaw+tybokV5M3ZckKrcnTt o5gD1OKC2QDZrjz71KUtYFIOgWjSvxcMxzcRQzWpQ5GWWUqp/rpQjVmCwMf5VYVBaS GakmffrhJ+lWtDRMLy6VnFV3TZ3iqpF1SLth5ydmVAV6PMAh2gEnqGhFrSfeeEnkg1 45kko/82wvJCg== To: linux-wireless@vger.kernel.org From: Harry Austen Cc: linux-kernel@vger.kernel.org, Gregory Greenman , Kalle Valo , Johannes Berg , Miri Korenblit , Avraham Stern , Daniel Lezcano , Zhang Rui , Harry Austen Subject: [PATCH] wifi: iwlwifi: mvm: enable thermal zone only when firmware is loaded Message-ID: <20230710104626.8399-1-hpausten@protonmail.com> Feedback-ID: 53116287:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In iwl_mvm_thermal_zone_register(), when registering a thermal zone, the thermal subsystem will evaluate its temperature. But iwl_mvm_tzone_get_temp() fails at this time because iwl_mvm_firmware_running() returns false. And that's why many users report that they see "thermal thermal_zoneX: failed to read out thermal zone (-61)" message during wifi driver probing. This patch attempts to fix this by delaying enabling of the thermal zone until after the firmware has been loaded/initialized. It also gets disabled when going into suspend. Signed-off-by: Harry Austen --- .../net/wireless/intel/iwlwifi/mvm/mac80211.c | 18 ++++++++++++++++++ drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 9 +-------- 2 files changed, 19 insertions(+), 8 deletions(-) -- 2.41.0 diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c index ce7905faa08f..a47d29a64dd4 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c @@ -1187,6 +1187,17 @@ int iwl_mvm_mac_start(struct ieee80211_hw *hw) mutex_unlock(&mvm->mutex); +#ifdef CONFIG_THERMAL + /* Needs to be done outside of mutex guarded section to prevent deadlock, since enabling + * the thermal zone calls the .get_temp() callback, which attempts to acquire the mutex. + */ + if (!ret) { + ret = thermal_zone_device_enable(mvm->tz_device.tzone); + if (ret) + IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone (err = %d)\n", ret); + } +#endif + iwl_mvm_mei_set_sw_rfkill_state(mvm); return ret; @@ -1282,6 +1293,7 @@ void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) void iwl_mvm_mac_stop(struct ieee80211_hw *hw) { struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); + int ret; flush_work(&mvm->async_handlers_wk); flush_work(&mvm->add_stream_wk); @@ -1307,6 +1319,12 @@ void iwl_mvm_mac_stop(struct ieee80211_hw *hw) iwl_mvm_mei_set_sw_rfkill_state(mvm); +#ifdef CONFIG_THERMAL + ret = thermal_zone_device_disable(mvm->tz_device.tzone); + if (ret) + IWL_DEBUG_TEMP(mvm, "Failed to disable thermal zone (err = %d)\n", ret); +#endif + mutex_lock(&mvm->mutex); __iwl_mvm_mac_stop(mvm); mutex_unlock(&mvm->mutex); diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 157e96fa23c1..964d2d011c6b 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -680,7 +680,7 @@ static struct thermal_zone_device_ops tzone_ops = { static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) { - int i, ret; + int i; char name[16]; static atomic_t counter = ATOMIC_INIT(0); @@ -707,13 +707,6 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) return; } - ret = thermal_zone_device_enable(mvm->tz_device.tzone); - if (ret) { - IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n"); - thermal_zone_device_unregister(mvm->tz_device.tzone); - return; - } - /* 0 is a valid temperature, * so initialize the array with S16_MIN which invalid temperature */