From patchwork Thu Apr 30 06:32:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11519217 X-Patchwork-Delegate: miriam.rachel.korenblit@intel.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C241805 for ; Thu, 30 Apr 2020 06:29:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC1F8214D8 for ; Thu, 30 Apr 2020 06:29:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726543AbgD3G3F (ORCPT ); Thu, 30 Apr 2020 02:29:05 -0400 Received: from mga11.intel.com ([192.55.52.93]:25173 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbgD3G3F (ORCPT ); Thu, 30 Apr 2020 02:29:05 -0400 IronPort-SDR: 8tJ0NoLQMLiptGC6qo8SoCnIRiIFXL4wpfSDgkEYvlKQB57lhpTLxVqKqpNm22oRTWoc5tUhk8 mXy0HuPLVrog== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 23:29:05 -0700 IronPort-SDR: X/uXpcJX/nLM4/qqgTQfQC2PsJvrP7P9FeQKTnEo1xLkEnceo/HygM82/K6sZ7VzTZEtRoCAeU DVuNucgxLpag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="282751610" Received: from power-sh.sh.intel.com ([10.239.48.5]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2020 23:29:03 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: linux-wireless@vger.kernel.org, daniel.lezcano@linaro.org, andrzej.p@collabora.com, b.zolnierkie@samsung.com, luca@coelho.fi, rui.zhang@intel.com Subject: [PATCH 1/6] iwlwifi: use thermal_zone_device_update() for temperature change Date: Thu, 30 Apr 2020 14:32:24 +0800 Message-Id: <20200430063229.6182-2-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430063229.6182-1-rui.zhang@intel.com> References: <20200430063229.6182-1-rui.zhang@intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org thermal_notify_framework() is an obsolete API, and iwlwifi is the only user of it. Convert iwlwifi driver to use thermal_zone_device_update() instead. Note that, thermal_zone_device_update() is able to handle the crossed threshold by comparing the current temperature with every trip point, so ths_crossed variant in iwl_mvm_temp_notif() is probably not needed. It is still left there in this patch, in case the debug information is still needed. Signed-off-by: Zhang Rui --- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 418e59b..6344b6b 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -203,9 +203,8 @@ void iwl_mvm_temp_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) if (mvm->tz_device.tzone) { struct iwl_mvm_thermal_device *tz_dev = &mvm->tz_device; - - thermal_notify_framework(tz_dev->tzone, - tz_dev->fw_trips_index[ths_crossed]); + thermal_zone_device_update(tz_dev->tzone, + THERMAL_EVENT_UNSPECIFIED); } #endif /* CONFIG_THERMAL */ } From patchwork Thu Apr 30 06:32:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11519221 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61A4E1805 for ; Thu, 30 Apr 2020 06:29:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B09D214D8 for ; Thu, 30 Apr 2020 06:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726573AbgD3G3K (ORCPT ); Thu, 30 Apr 2020 02:29:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:25173 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbgD3G3K (ORCPT ); Thu, 30 Apr 2020 02:29:10 -0400 IronPort-SDR: B2gc6N67tj/5Ur54FfietNw2Jy3C0b3oJjQ1qtVGzmatVybx77LMl/givGS8T3ATwEAZWM07Tc 2p2JDX9wC5+Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 23:29:09 -0700 IronPort-SDR: yRht2i5q3LHB7zEda3YGrnPrMdcEI1pIxnCASg5/7zOOewg2RwrLpiyEf42qgIgyzs3zmQWQUC 2pVAy3jw/8IQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="282751632" Received: from power-sh.sh.intel.com ([10.239.48.5]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2020 23:29:08 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: linux-wireless@vger.kernel.org, daniel.lezcano@linaro.org, andrzej.p@collabora.com, b.zolnierkie@samsung.com, luca@coelho.fi, rui.zhang@intel.com Subject: [PATCH 2/6] thermal: core: delete thermal_notify_framework() Date: Thu, 30 Apr 2020 14:32:25 +0800 Message-Id: <20200430063229.6182-3-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430063229.6182-1-rui.zhang@intel.com> References: <20200430063229.6182-1-rui.zhang@intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Delete thermal_notify_framework() as there is no user of it. Signed-off-by: Zhang Rui Tested-by: Andrzej Pietrasiewicz Reviewed-by: Andrzej Pietrasiewicz --- drivers/thermal/thermal_core.c | 18 ------------------ include/linux/thermal.h | 4 ---- 2 files changed, 22 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 03c4d8d..ac70545 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -532,24 +532,6 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, } EXPORT_SYMBOL_GPL(thermal_zone_device_update); -/** - * thermal_notify_framework - Sensor drivers use this API to notify framework - * @tz: thermal zone device - * @trip: indicates which trip point has been crossed - * - * This function handles the trip events from sensor drivers. It starts - * throttling the cooling devices according to the policy configured. - * For CRITICAL and HOT trip points, this notifies the respective drivers, - * and does actual throttling for other trip points i.e ACTIVE and PASSIVE. - * The throttling policy is based on the configured platform data; if no - * platform data is provided, this uses the step_wise throttling policy. - */ -void thermal_notify_framework(struct thermal_zone_device *tz, int trip) -{ - handle_thermal_trip(tz, trip); -} -EXPORT_SYMBOL_GPL(thermal_notify_framework); - static void thermal_zone_device_check(struct work_struct *work) { struct thermal_zone_device *tz = container_of(work, struct diff --git a/include/linux/thermal.h b/include/linux/thermal.h index c789d4f..a87fbaf 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -420,7 +420,6 @@ int thermal_zone_get_slope(struct thermal_zone_device *tz); int thermal_zone_get_offset(struct thermal_zone_device *tz); void thermal_cdev_update(struct thermal_cooling_device *); -void thermal_notify_framework(struct thermal_zone_device *, int); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata, @@ -468,9 +467,6 @@ static inline int thermal_zone_get_offset( static inline void thermal_cdev_update(struct thermal_cooling_device *cdev) { } -static inline void thermal_notify_framework(struct thermal_zone_device *tz, - int trip) -{ } #endif /* CONFIG_THERMAL */ static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) From patchwork Thu Apr 30 06:32:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11519225 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 685921805 for ; Thu, 30 Apr 2020 06:29:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50B61214D8 for ; Thu, 30 Apr 2020 06:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726583AbgD3G3N (ORCPT ); Thu, 30 Apr 2020 02:29:13 -0400 Received: from mga11.intel.com ([192.55.52.93]:25173 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbgD3G3M (ORCPT ); Thu, 30 Apr 2020 02:29:12 -0400 IronPort-SDR: k+tvPD/Goz5oDj1HNmqISglCXRSdJv59qSit0lFpRVkPO0izxtv5eossUpTZzWK3ezEg0Wlg7e Ok/qPOcuuHHA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 23:29:12 -0700 IronPort-SDR: /w7bQ4FpjCNO8fbnM+vD3pMN7d6DOItzX+qaeYekxqCZLPCwIA3pShhJUt7BmW7FruTi2LKbrg 1Icl50AWdWfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="282751640" Received: from power-sh.sh.intel.com ([10.239.48.5]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2020 23:29:11 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: linux-wireless@vger.kernel.org, daniel.lezcano@linaro.org, andrzej.p@collabora.com, b.zolnierkie@samsung.com, luca@coelho.fi, rui.zhang@intel.com Subject: [PATCH 3/6] thermal: core: update polling after all trips handled Date: Thu, 30 Apr 2020 14:32:26 +0800 Message-Id: <20200430063229.6182-4-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430063229.6182-1-rui.zhang@intel.com> References: <20200430063229.6182-1-rui.zhang@intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Move monitor_thermal_zone() from handle_thermal_trip() to thermal_zone_device_update() because updating the polling timers after all trips handled is sufficient. Signed-off-by: Zhang Rui Reviewed-by: Bartlomiej Zolnierkiewicz --- drivers/thermal/thermal_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index ac70545..04a16a9 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -430,11 +430,6 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) handle_critical_trips(tz, trip, type); else handle_non_critical_trips(tz, trip); - /* - * Alright, we handled this trip successfully. - * So, start monitoring again. - */ - monitor_thermal_zone(tz); } static void update_temperature(struct thermal_zone_device *tz) @@ -529,6 +524,12 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, for (count = 0; count < tz->trips; count++) handle_thermal_trip(tz, count); + + /* + * Alright, we handled all the trips successfully. + * So, start monitoring again. + */ + monitor_thermal_zone(tz); } EXPORT_SYMBOL_GPL(thermal_zone_device_update); From patchwork Thu Apr 30 06:32:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11519229 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2EC81805 for ; Thu, 30 Apr 2020 06:29:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6FAA2173E for ; Thu, 30 Apr 2020 06:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbgD3G3R (ORCPT ); Thu, 30 Apr 2020 02:29:17 -0400 Received: from mga11.intel.com ([192.55.52.93]:25173 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbgD3G3R (ORCPT ); Thu, 30 Apr 2020 02:29:17 -0400 IronPort-SDR: ImxQP1EXWC1F7IPeT+1R0+ViOYItEY9Rq5OzmMS4QkIDErLO2X6MkZD0cr/QS3mttSFFP7C09+ eDCTSeHY0afA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 23:29:17 -0700 IronPort-SDR: wzMJDO1b/btSHr77ZofDNCBAXUMeubVWXwUmu4Fri9L1ngPDyrTw7zy8ljrLmA/R8+yPQTgyyA WOFXvnYo6v+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="282751654" Received: from power-sh.sh.intel.com ([10.239.48.5]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2020 23:29:14 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: linux-wireless@vger.kernel.org, daniel.lezcano@linaro.org, andrzej.p@collabora.com, b.zolnierkie@samsung.com, luca@coelho.fi, rui.zhang@intel.com Subject: [PATCH 4/6] thermal: core: stop polling timer for disabled thermal zone Date: Thu, 30 Apr 2020 14:32:27 +0800 Message-Id: <20200430063229.6182-5-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430063229.6182-1-rui.zhang@intel.com> References: <20200430063229.6182-1-rui.zhang@intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org For a disabled thermal zone, thermal_zone_device_update() should do nothing but cancelling the polling timer. Signed-off-by: Zhang Rui Reviewed-by: Bartlomiej Zolnierkiewicz --- drivers/thermal/thermal_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 04a16a9..5f7a867 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -508,7 +508,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, int count; if (should_stop_polling(tz)) - return; + goto update_polling; if (atomic_read(&in_suspend)) return; @@ -525,6 +525,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, for (count = 0; count < tz->trips; count++) handle_thermal_trip(tz, count); +update_polling: /* * Alright, we handled all the trips successfully. * So, start monitoring again. From patchwork Thu Apr 30 06:32:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11519233 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA34314DD for ; Thu, 30 Apr 2020 06:29:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C30532173E for ; Thu, 30 Apr 2020 06:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbgD3G3U (ORCPT ); Thu, 30 Apr 2020 02:29:20 -0400 Received: from mga11.intel.com ([192.55.52.93]:25173 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726358AbgD3G3U (ORCPT ); Thu, 30 Apr 2020 02:29:20 -0400 IronPort-SDR: xLOt+9/8epBFdLnHNdY1ndA6eD5rAQqKHaDitJDQvEP3F9LKUJCY+pQ0m9ybB8lfkVtwsS5rUd sjxS/34YL9WA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 23:29:20 -0700 IronPort-SDR: I7K1TkccSnlXnj2XU381CfWXGH4whQ968NBWcCrH9BOge+PJGtP5GtPpT3bX9JjjEKoemRqzeQ vYgk5qkmkqTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="282751674" Received: from power-sh.sh.intel.com ([10.239.48.5]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2020 23:29:18 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: linux-wireless@vger.kernel.org, daniel.lezcano@linaro.org, andrzej.p@collabora.com, b.zolnierkie@samsung.com, luca@coelho.fi, rui.zhang@intel.com Subject: [PATCH 5/6] thermal: core: introduce tz_disabled() helper function Date: Thu, 30 Apr 2020 14:32:28 +0800 Message-Id: <20200430063229.6182-6-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430063229.6182-1-rui.zhang@intel.com> References: <20200430063229.6182-1-rui.zhang@intel.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Rename should_stop_polling() to tz_disabled(), and make it global. Because there are platform thermal drivers which also need this. Signed-off-by: Zhang Rui Reviewed-by: Bartlomiej Zolnierkiewicz --- drivers/thermal/thermal_core.c | 17 ++++++++--------- include/linux/thermal.h | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5f7a867..1cd5d5d0 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -305,16 +305,9 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, cancel_delayed_work(&tz->poll_queue); } -static inline bool should_stop_polling(struct thermal_zone_device *tz) -{ - return thermal_zone_device_get_mode(tz) == THERMAL_DEVICE_DISABLED; -} - static void monitor_thermal_zone(struct thermal_zone_device *tz) { - bool stop; - - stop = should_stop_polling(tz); + bool stop = tz_disabled(tz); mutex_lock(&tz->lock); @@ -502,12 +495,18 @@ int thermal_zone_device_set_mode(struct thermal_zone_device *tz, } EXPORT_SYMBOL_GPL(thermal_zone_device_set_mode); +bool tz_disabled(struct thermal_zone_device *tz) +{ + return thermal_zone_device_get_mode(tz) == THERMAL_DEVICE_DISABLED; +} +EXPORT_SYMBOL(tz_disabled); + void thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { int count; - if (should_stop_polling(tz)) + if (tz_disabled(tz)) goto update_polling; if (atomic_read(&in_suspend)) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index a87fbaf..0bc62ee 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -479,4 +479,6 @@ static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED); } +bool tz_disabled(struct thermal_zone_device *tz); + #endif /* __THERMAL_H__ */ From patchwork Thu Apr 30 06:32:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 11519237 X-Patchwork-Delegate: miriam.rachel.korenblit@intel.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA77E1805 for ; Thu, 30 Apr 2020 06:29:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDB5D2173E for ; Thu, 30 Apr 2020 06:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbgD3G3X (ORCPT ); Thu, 30 Apr 2020 02:29:23 -0400 Received: from mga11.intel.com ([192.55.52.93]:25173 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726358AbgD3G3X (ORCPT ); Thu, 30 Apr 2020 02:29:23 -0400 IronPort-SDR: humlRVR2/wG9kZkf4ty1L8fxdPQ7h+ZnCJQn1jDoOQ4WnBTNEWB9hJSLgnMj/eXWbCWc+Riok8 JETJzOBTbXuw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 23:29:23 -0700 IronPort-SDR: +wKeSGww6JJPXvbSKLDQ+YoYIinGq8FxPE5drQ1kzWax6Iuc8J7HyVspAyOlefGZJ90jj/8IL1 Lm5hl2FN4q7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="282751693" Received: from power-sh.sh.intel.com ([10.239.48.5]) by fmsmga004.fm.intel.com with ESMTP; 29 Apr 2020 23:29:21 -0700 From: Zhang Rui To: linux-pm@vger.kernel.org Cc: linux-wireless@vger.kernel.org, daniel.lezcano@linaro.org, andrzej.p@collabora.com, b.zolnierkie@samsung.com, luca@coelho.fi, rui.zhang@intel.com Subject: [PATCH RFC 6/6] iwlwifi: enable thermal zone only when firmware loaded Date: Thu, 30 Apr 2020 14:32:29 +0800 Message-Id: <20200430063229.6182-7-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430063229.6182-1-rui.zhang@intel.com> References: <20200430063229.6182-1-rui.zhang@intel.com> Sender: linux-wireless-owner@vger.kernel.org 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. With the changes made earlier in this patch series, the problem can be solved by registering the iwlwifi thermal zone as disabled, and enable it later when the firmware is ready. *NOTE* This is just a prototype patch to illustrate the problem and how we can fix it based on the new thermal changes. I'm not sure what is the proper place to enable/disable the thermal zone. The solution in this patch causes a deadlock issue because a) thermal_zone_device_enable() is invoked with mvm->mutex locked. b) .get_temp() callback is invoked when enabling the thermal zone. c) iwl_mvm_tzone_get_temp() also needs to hold mvm->mutex. And that's why I hacked iwl_mvm_tzone_get_temp() to avoid this. So if you have ideas on how to fix this, please feel free to propose it. Link: https://bugzilla.kernel.org/show_bug.cgi?id=201761 Signed-off-by: Zhang Rui --- drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 2 ++ drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 4 ++++ drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 12 +++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c index a4038f2..ff47fc6 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c @@ -1222,6 +1222,8 @@ int iwl_mvm_up(struct iwl_mvm *mvm) #ifdef CONFIG_THERMAL /* TODO: read the budget from BIOS / Platform NVM */ + if (mvm->tz_device.tzone && tz_disabled(mvm->tz_device.tzone)) + thermal_zone_device_enable(mvm->tz_device.tzone); /* * In case there is no budget from BIOS / Platform NVM the default * budget should be 2000mW (cooling state 0). diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h index afcf2b9..b964c01 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h @@ -1946,6 +1946,10 @@ static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm) static inline void iwl_mvm_stop_device(struct iwl_mvm *mvm) { +#ifdef CONFIG_THERMAL + if (mvm->tz_device.tzone && !tz_disabled(mvm->tz_device.tzone)) + thermal_zone_device_disable(mvm->tz_device.tzone); +#endif lockdep_assert_held(&mvm->mutex); iwl_fw_cancel_timestamp(&mvm->fwrt); clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 6344b6b..819dcaf 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -620,8 +620,9 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device, struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata; int ret; int temp; + int locked; - mutex_lock(&mvm->mutex); + locked = mutex_trylock(&mvm->mutex); if (!iwl_mvm_firmware_running(mvm) || mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) { @@ -636,7 +637,8 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device, *temperature = temp * 1000; out: - mutex_unlock(&mvm->mutex); + if (locked) + mutex_unlock(&mvm->mutex); return ret; } @@ -730,6 +732,10 @@ static struct thermal_zone_device_ops tzone_ops = { /* make all trips writable */ #define IWL_WRITABLE_TRIPS_MSK (BIT(IWL_MAX_DTS_TRIPS) - 1) +static struct thermal_zone_params tz_params = { + .initial_mode = THERMAL_DEVICE_DISABLED, +}; + static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) { int i; @@ -749,7 +755,7 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) IWL_MAX_DTS_TRIPS, IWL_WRITABLE_TRIPS_MSK, mvm, &tzone_ops, - NULL, 0, 0); + &tz_params, 0, 0); if (IS_ERR(mvm->tz_device.tzone)) { IWL_DEBUG_TEMP(mvm, "Failed to register to thermal zone (err = %ld)\n",