From patchwork Sun Feb 2 07:41:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 11361531 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 B0BF5112B for ; Sun, 2 Feb 2020 07:42:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E2B72082E for ; Sun, 2 Feb 2020 07:42:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="kwlxNrAo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726893AbgBBHmB (ORCPT ); Sun, 2 Feb 2020 02:42:01 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:6569 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbgBBHmB (ORCPT ); Sun, 2 Feb 2020 02:42:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580629321; x=1612165321; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=lNOO5Udnox8UueU9OsAy/v2Bl4hcavFqwHrzqwFRzzg=; b=kwlxNrAoUpzUlW09LBppA5JaMRwWNRHNyUaFYAg++pi/vQbQwvrRyNkD 4CO0gvmFurOWq8Cs0x/mb1QsvtaLJADJrCKZCRaENbs4F0WOSq8VsSqUb R+WrahE3Spuf7KlWzGMvyizGMDM4xCMb5QM2Lu0gclE7f91oWZc0yS1yh KCtE2Vub6SB8yT4qHKLF1+qbbORV5M6odJCS2QKPvVSM00Txr+2x1Y0GI wFVSTCx5oKDIPmqSEZVX8nTyWcGSPZC1SJzPXcgrAaA7SSKVxn5LQFEsh 2K1Ig4VO/R4Ks26VW8VWoD4YRhQMjS1oNQw+4NTqqdOEGcgZs00eJYaK/ w==; IronPort-SDR: cSjsVFfFOVhcw7xtfKe5I8oSYS81HBXLgvWTtak2ttNFdvAg3mOHl5S99dBihh9ZbzuvJjU5Qb +NEjQuCW7XkxaYJndUU195k2NTqmC4O2yWSCKd30heuPwwhw9P3zI/8NGzjKvnMAIXdp8ajJbw F8vFgobFkcfSbSYKf1PlwnOFTOrIZlRxaDhiJjZj5jMssM+PtTkEzfV3C4akmTvuQJj1Dvw4O7 5EIot+qLusiYPi1pdmeDxAqtFPiPielQcbBN8KWFRj4SH4wOqpAEd8YN9eqH9WRO4pXkFBw1PD tXA= X-IronPort-AV: E=Sophos;i="5.70,393,1574092800"; d="scan'208";a="130383376" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 02 Feb 2020 15:42:00 +0800 IronPort-SDR: AQzhWpD47nyzwzjwqKQUrSLwGpcUGbOT+QxufDcF3FLsOIQjvctKwbov2X/w1BWjKqU+pEdeLW UcIYq21M/NbKANRf8E9EfNvJ5HeCeEXdf77JGTAk6y6AduPof4+EDe4qeViu/7R4DdHVfKbSOl kat/7+manF5xEStXHFOxoQ7IHRJAIqagoEYE0uaYKYKvJOsNQdxACjUQ2SounoRhGpBSdR+aF9 94rBNdRMR+u0h/ZU+xJgIjza1tpDvBYAS4AY1hDF10oUmP720KkTCvoFrYluG7qEtEV1feczPj 8t2SXnn9AHTYyL/S9BA8u4D6 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2020 23:35:07 -0800 IronPort-SDR: EcNTpQrtQGi9WltdoarEBLQMbvtaM95DklqVHKhETbVFDdWYnV88iA1Nr8FcsBT9MxUX9qsjgf GmRfAJsUUY0yjGJTGtU1DfgrVLh//oQi2CV7KDLvlbcb59Z3lE1uRSWQyvSD1rAVTsXT0YwMzE uoM7mjxUuuH2DHyQvYdfhIhcvatos6FsMmoyCEmHuPw8WxjB1GWrwgrOvY27ilwc94BGzTmxb9 EmLMS9EcUQUNhn71Ahp2SuX6iU/BrPP5wOvka205Wksj+jxEB/NCPrxdbyIXDCS1RDrHMbiO3j tsM= WDCIronportException: Internal Received: from kfae419068.sdcorp.global.sandisk.com ([10.0.231.195]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Feb 2020 23:41:58 -0800 From: Avi Shchislowski To: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Avi Shchislowski , Uri Yanai Subject: [PATCH 1/5] scsi: ufs: Add ufs thermal support Date: Sun, 2 Feb 2020 09:41:49 +0200 Message-Id: <1580629313-20078-2-git-send-email-avi.shchislowski@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> References: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Avi Shchislowski Support the new temperature notification attributes introduced in UFSv3.0. Add exception event mask, and ufs features attributes. Signed-off-by: Uri Yanai Signed-off-by: Avi Shchislowski --- drivers/scsi/ufs/Kconfig | 11 ++++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-thermal.c | 123 +++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufs-thermal.h | 19 +++++++ drivers/scsi/ufs/ufs.h | 11 ++++ drivers/scsi/ufs/ufshcd.c | 3 + drivers/scsi/ufs/ufshcd.h | 10 ++++ 7 files changed, 178 insertions(+) create mode 100644 drivers/scsi/ufs/ufs-thermal.c create mode 100644 drivers/scsi/ufs/ufs-thermal.h diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig index d14c224..bed56ee 100644 --- a/drivers/scsi/ufs/Kconfig +++ b/drivers/scsi/ufs/Kconfig @@ -160,3 +160,14 @@ config SCSI_UFS_BSG Select this if you need a bsg device node for your UFS controller. If unsure, say N. + +config THERMAL_UFS + bool "Thermal UFS" + depends on THERMAL && SCSI_UFSHCD + help + A UFS3.0 feature that allows using the ufs device as a temperature + sensor. it provide notification to the host when the UFS device + case temperature approaches its pre-defined boundaries. + + Select Y to enable this feature, otherwise say N. + If unsure, say N. \ No newline at end of file diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile index 94c6c5d..fd35941 100644 --- a/drivers/scsi/ufs/Makefile +++ b/drivers/scsi/ufs/Makefile @@ -12,3 +12,4 @@ obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o obj-$(CONFIG_SCSI_UFS_MEDIATEK) += ufs-mediatek.o obj-$(CONFIG_SCSI_UFS_TI_J721E) += ti-j721e-ufs.o +obj-$(CONFIG_THERMAL_UFS) += ufs-thermal.o diff --git a/drivers/scsi/ufs/ufs-thermal.c b/drivers/scsi/ufs/ufs-thermal.c new file mode 100644 index 0000000..469c1ed --- /dev/null +++ b/drivers/scsi/ufs/ufs-thermal.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * thermal ufs + * + * Copyright (C) 2020 Western Digital Corporation + */ +#include +#include "ufs-thermal.h" + +enum { + UFS_THERM_MAX_TEMP, + UFS_THERM_HIGH_TEMP, + UFS_THERM_LOW_TEMP, + UFS_THERM_MIN_TEMP, + + /* keep last */ + UFS_THERM_MAX_TRIPS +}; + +/** + *struct ufs_thermal - thermal zone related data + * @tzone: thermal zone device data + */ +static struct ufs_thermal { + struct thermal_zone_device *zone; +} thermal; + +static struct thermal_zone_device_ops ufs_thermal_ops = { + .get_temp = NULL, + .get_trip_temp = NULL, + .get_trip_type = NULL, +}; + +static int ufs_thermal_enable_ee(struct ufs_hba *hba) +{ + /* later */ + return -EINVAL; +} + +static void ufs_thermal_zone_unregister(struct ufs_hba *hba) +{ + if (thermal.zone) { + dev_dbg(hba->dev, "Thermal zone device unregister\n"); + thermal_zone_device_unregister(thermal.zone); + thermal.zone = NULL; + } +} + +static int ufs_thermal_register(struct ufs_hba *hba) +{ + int err = 0; + char name[THERMAL_NAME_LENGTH] = {}; + + snprintf(name, THERMAL_NAME_LENGTH, "ufs_storage_%d", + hba->host->host_no); + + thermal.zone = thermal_zone_device_register(name, UFS_THERM_MAX_TRIPS, + 0, hba, &ufs_thermal_ops, NULL, 0, 0); + if (IS_ERR(thermal.zone)) { + err = PTR_ERR(thermal.zone); + dev_err(hba->dev, "Failed to register to thermal zone, err %d\n", + err); + thermal.zone = NULL; + goto out; + } + + /* thermal support is enabled only after successful + * enablement of thermal exception + */ + if (ufs_thermal_enable_ee(hba)) { + dev_info(hba->dev, "Failed to enable thermal exception\n"); + ufs_thermal_zone_unregister(hba); + err = -EINVAL; + } + +out: + return err; +} + +int ufs_thermal_probe(struct ufs_hba *hba) +{ + u8 ufs_features; + u8 *desc_buf = NULL; + int err = -EINVAL; + + if (!ufshcd_thermal_management_enabled(hba)) + goto out; + + desc_buf = kzalloc(hba->desc_size.dev_desc, GFP_KERNEL); + if (!desc_buf) { + err = -ENOMEM; + goto out; + } + + if (ufshcd_read_desc_param(hba, QUERY_DESC_IDN_DEVICE, 0, 0, desc_buf, + hba->desc_size.dev_desc)) + goto out; + + + ufs_features = desc_buf[DEVICE_DESC_PARAM_UFS_FEAT] & + (UFS_FEATURE_HTEMP | UFS_FEATURE_LTEMP); + if (!ufs_features) + goto out; + + err = ufs_thermal_register(hba); + if (err) + goto out; + + hba->thermal_features = ufs_features; + +out: + kfree(desc_buf); + return err; +} + +void ufs_thermal_remove(struct ufs_hba *hba) +{ + if (!ufshcd_thermal_management_enabled(hba)) + return; + + ufs_thermal_zone_unregister(hba); + hba->thermal_features = 0; +} diff --git a/drivers/scsi/ufs/ufs-thermal.h b/drivers/scsi/ufs/ufs-thermal.h new file mode 100644 index 0000000..7c0fcbe --- /dev/null +++ b/drivers/scsi/ufs/ufs-thermal.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2018 Western Digital Corporation + */ +#ifndef UFS_THERMAL_H +#define UFS_THERMAL_H + +#include "ufshcd.h" +#include "ufs.h" + +#ifdef CONFIG_THERMAL_UFS +void ufs_thermal_remove(struct ufs_hba *hba); +int ufs_thermal_probe(struct ufs_hba *hba); +#else +static inline void ufs_thermal_remove(struct ufs_hba *hba) {} +static inline int ufs_thermal_probe(struct ufs_hba *hba) {return 0; } +#endif /* CONFIG_THERMAL_UFS */ + +#endif /* UFS_THERMAL_H */ diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index dde2eb0..eb729cc 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -332,6 +332,17 @@ enum { UFSHCD_AMP = 3, }; +/* UFS Features - to decode bUFSFeaturesSupport */ +enum { + UFS_FEATURE_FFU = BIT(0), + UFS_FEATURE_PSA = BIT(1), + UFS_FEATURE_LIFE = BIT(2), + UFS_FEATURE_REFRESH = BIT(3), + UFS_FEATURE_HTEMP = BIT(4), + UFS_FEATURE_LTEMP = BIT(5), + UFS_FEATURE_ETEMP = BIT(6), +}; + #define POWER_DESC_MAX_SIZE 0x62 #define POWER_DESC_MAX_ACTV_ICC_LVLS 16 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index abd0e6b..099d2de 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -47,6 +47,7 @@ #include "unipro.h" #include "ufs-sysfs.h" #include "ufs_bsg.h" +#include "ufs-thermal.h" #define CREATE_TRACE_POINTS #include @@ -7111,6 +7112,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool async) /* Enable Auto-Hibernate if configured */ ufshcd_auto_hibern8_enable(hba); + ufs_thermal_probe(hba); out: @@ -8278,6 +8280,7 @@ int ufshcd_shutdown(struct ufs_hba *hba) */ void ufshcd_remove(struct ufs_hba *hba) { + ufs_thermal_remove(hba); ufs_bsg_remove(hba); ufs_sysfs_remove_nodes(hba->dev); blk_cleanup_queue(hba->tmf_queue); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 2ae6c7c..28c0063 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -730,6 +730,11 @@ struct ufs_hba { struct device bsg_dev; struct request_queue *bsg_queue; + +#define UFSHCD_CAP_THERMAL_MANAGEMENT (1 << 7) + + u8 thermal_features; + }; /* Returns true if clocks can be gated. Otherwise false */ @@ -754,6 +759,11 @@ static inline bool ufshcd_is_rpm_autosuspend_allowed(struct ufs_hba *hba) return hba->caps & UFSHCD_CAP_RPM_AUTOSUSPEND; } +static inline bool ufshcd_thermal_management_enabled(struct ufs_hba *hba) +{ + return hba->caps & UFSHCD_CAP_THERMAL_MANAGEMENT; +} + static inline bool ufshcd_is_intr_aggr_allowed(struct ufs_hba *hba) { /* DWC UFS Core has the Interrupt aggregation feature but is not detectable*/ From patchwork Sun Feb 2 07:41:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 11361539 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 77FF792A for ; Sun, 2 Feb 2020 07:42:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54EC72082E for ; Sun, 2 Feb 2020 07:42:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rX5MtnkR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbgBBHmE (ORCPT ); Sun, 2 Feb 2020 02:42:04 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:6569 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbgBBHmE (ORCPT ); Sun, 2 Feb 2020 02:42:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580629323; x=1612165323; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=tS/zpN89ukOZa4e+YcelECEdpkMXtQtYyDQ8RTM+CYs=; b=rX5MtnkRMHRXIwEn5xHjZ1S4qC3fxevtSOYlC6KO0M/W5Qx6vIBdtVJ6 5MdDv3ajSEi5E/3O+CAwOW+6CaNeKZYGWraq/mvIAcBjc7u6gav/ABbvd zmEUADR+rGm6z88TXQepUyNTXV7ZhCJ5HONdLzMSaV1fzQXMAA2Nu8XHp jMYq2Fv0RvBXZnpa8fAmb6mnqFMyQlBzbOn9WQVy+5N9HjYyg49s8yWVW LdoXv3yZjjYJZuOZc5Rlg0MTsGu8ImY3BxmnxDBPw96zaMdP6jrNkNtrQ YMLAQtoYvi0jDpRaN383FO7LN0726zKbtC8KOVigcXUC3mgi/MxX75p0M A==; IronPort-SDR: Gjc9tCTlNudzYc9hOnzbTqAjeDzs7IiUwGs0Wrz+9O9m4Uf6+9MsMYqQxlZMN/wRmbc38Dquh6 9pEcr+AxNAqF9ggX2H87+AKGGHOavaCElt+8aC8vuoPKhczqx7HvpMX7M9JyItmI6ggbWDfGxH 6hlcM89UKcxZi4A76kwhBKDYzvq3brI56WxtafjDQOpa5s+5SJGcuGYZYb6b/223hfH+CXvSIH pIwIh3Wf4IknfT3+11Fbo/tO18jWERXuitGfX8OAvnfR0IyMu8hM69L7swxCk1XP6ETzv1N7H2 R3A= X-IronPort-AV: E=Sophos;i="5.70,393,1574092800"; d="scan'208";a="130383378" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 02 Feb 2020 15:42:03 +0800 IronPort-SDR: bxmnbggNot3gHffxN3HR0fChifAST/0gakBuznbzSGA88fyBHr9RvhMxWZtJb0mdnYdA5hJITM WdCJyrtef8q3+zsZu47hxlNu411ZlPoe7M0QZgzjadp177zUavO1aSkXlfW/GoYeXyiFz9vU9x l1EeTzzlaZmw76YuXV9/Z5u6I1OkbMKJTL/zjLfx+Z66MfWsljzAjDvrCaHgHr3sb2oQJB89IM n2Sx3MuzUyeW26DAUOFztQ4zJLl3QXiaxsY3tlDLv+VKtAdfY8FMvboF1QH2alYlYNyT3s0xa/ mCqnYpdYMDMiF1qvAEGsXJA0 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2020 23:35:10 -0800 IronPort-SDR: Ty/bDUXdKqVqms2jNwOyl5ZdRjKsJjPyR2HoRdTIXp4YL5qFQcDablti20COwmhDSeHT+YZetl ipjBmE+hOFpSMMxBdZLXIpMsYze/2FcCqB/Z/+CpdZdTiqM2ap1AYKvYqUDAOOKx8cK5hwBFSt 2CDAWKb6a+0QCIhr0O0jyB8lTRWmmZeVR0MM03S7igloGp4RH+naykWUHCnpYdikOjug/605tO xaMUKKoqGHBlhT4YFQUyxNVRGxJ0246h5vLju5IUdc0WPbxoyBXtQqJ4o5OObQkhkoikuysDIi AtQ= WDCIronportException: Internal Received: from kfae419068.sdcorp.global.sandisk.com ([10.0.231.195]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Feb 2020 23:42:01 -0800 From: Avi Shchislowski To: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Avi Shchislowski , Uri Yanai Subject: [PATCH 2/5] scsi: ufs: export ufshcd_enable_ee Date: Sun, 2 Feb 2020 09:41:50 +0200 Message-Id: <1580629313-20078-3-git-send-email-avi.shchislowski@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> References: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Avi Shchislowski export ufshcd_enable_ee so that other modules can use it. this will come handy in the next patch where we will need it to enable thermal support Signed-off-by: Uri Yanai Signed-off-by: Avi Shchislowski --- drivers/scsi/ufs/ufshcd.c | 2 +- drivers/scsi/ufs/ufshcd.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 099d2de..f25b93c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4923,7 +4923,7 @@ static int ufshcd_disable_ee(struct ufs_hba *hba, u16 mask) * * Returns zero on success, non-zero error value on failure. */ -static int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask) +int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask) { int err = 0; u32 val; diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 28c0063..6d2a5fd 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -960,6 +960,8 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, u8 *desc_buff, int *buff_len, enum query_opcode desc_op); +int ufshcd_enable_ee(struct ufs_hba *hba, u16 mask); + /* Wrapper functions for safely calling variant operations */ static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) { From patchwork Sun Feb 2 07:41:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 11361537 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 7E26792A for ; Sun, 2 Feb 2020 07:42:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 51804206D3 for ; Sun, 2 Feb 2020 07:42:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nhSHxYZL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbgBBHmG (ORCPT ); Sun, 2 Feb 2020 02:42:06 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:6569 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbgBBHmG (ORCPT ); Sun, 2 Feb 2020 02:42:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580629326; x=1612165326; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bHc+Jw1mnzdI08P+HjK+2LM4U1g7w+7hIcYFHLqcN+M=; b=nhSHxYZL5lcg0T+CbXirjjo38pAMUutLyAZ0q9bVCZzysvILLZksxoAn T17bqJrBgff6StCAxjc9Mb81V9gDLPozHSsMppKXFeBylGkq3S01//VaU lRsBnKxN8uqFBf4XOxbCuknzzkEnzj8vmh/V2WOFlT4xDp/d1y4qplYaj /Ps3ARxGv64AnZMaJZtRLrhUd/E33YZABihio20nn6Jrt82ZjlLd+E3Hl JtAp7ULZaCCxpCVh0bhMy4lLcaiN0HggxYg1JTEAyWwgF9BGtsnrqK3va 0byJ/as7gQGAqxLO7jIOG3FNYW8lifu5Kk5FoeQAWrsAXeNBvtweXkJsi Q==; IronPort-SDR: 9mtTgpORPEBHum22fanWPZxDrFaCQTuNsQ3zNcTaSFq3YEUgYg6GQUuTaRKFE4xUSCpm/AZniQ 64JQjc6yRzYKLN3p8V3N4j5jBjYtGTp5CeMqW2aDEAMSG6wk16IsJBgZ8Vz0E/druoM4MAa9oH 6i72wJQpQOQt+dEpR85QFuGkoOil4geu0l7LeHP9vT++5lnrfejd0jflu7vwMjxyJMWhDY7Lki QVYBUqRAvxELtsEfRRJtwGPbmH9qFZq7eOn6gIMO+/VLzSOaTCjnSF+xKtGxdtzBQXALDtK0ZF oaY= X-IronPort-AV: E=Sophos;i="5.70,393,1574092800"; d="scan'208";a="130383379" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 02 Feb 2020 15:42:06 +0800 IronPort-SDR: NVUrWjLW519BWaTvhGXdF3WKiceC2bUHKs9yJrXhMqhsiYhGQVGn7yBflAPG8at9N/XVsfLCLs ueSlutf/Sd7IEwbcGltvsRHkqeHha/NoqvjlNSUH66lqJes/BJpL1PltOKPPdWqBoWa/hHsHFj TrWWBESg8kY3jXVVyByC0OVczTqqI8S6h4bcmfSeBHYxFWiDb8Pu61C9yAr3pe4iUkpzBesNTe HEKAzSLg7VoLTxF+K0P4qnP95n7rdmjiu2+avmVQqhakynZzZkxNwNBvltjNO0LqhBPsF7RAtz qh80FgeMuT9n7b9klUqdO2EL Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2020 23:35:12 -0800 IronPort-SDR: 3oyFRByKiRDBgSe9mpaN+GpNE1fHDiQOX0xRM04Fv+kbTjo9XFnK4Zyj6HiZVPr+LcD2drWTtf 4hFwPs1bNZOJ4mcPhbm1rFv61e4/Xb1rLfbBlMxKozw4ABXdgsdTWxO94b1yGk3x2+NE/VHHEy KaUkdqidN00za7wKeLxKWbgUNELxm5YzKmF6GvsVM2Bn4s+5avMDM/d2pCHyf7usWgj5BDEC7M aG3YGj64hafO83k+fA1F8I+PCxJjwcZEfKrKJ68dNaGCr6xGER6TpQ/UdbTPNUxAPYofPyz/6n qkQ= WDCIronportException: Internal Received: from kfae419068.sdcorp.global.sandisk.com ([10.0.231.195]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Feb 2020 23:42:04 -0800 From: Avi Shchislowski To: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Avi Shchislowski , Uri Yanai Subject: [PATCH 3/5] scsi: ufs: enable thermal exception event Date: Sun, 2 Feb 2020 09:41:51 +0200 Message-Id: <1580629313-20078-4-git-send-email-avi.shchislowski@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> References: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Avi Shchislowski The host might need to be aware of the device's temperature, when it's too high or too low. Should such event occur, the device is expected to notify it to the host by using the exception event mechanism. E.g. when TOO_HIGH_TEMP in wExceptionEventStatus is raised, it is recommended to perform thermal throttling or other cooling activities for lowering the device Tcase temperature. Similarly, when TOO_LOW_TEMP is raised, it is recommended to take an applicable actions to increase the device’s Tcase temperature. Signed-off-by: Uri Yanai Signed-off-by: Avi Shchislowski --- drivers/scsi/ufs/ufs-thermal.c | 28 ++++++++++++++++++++++++---- drivers/scsi/ufs/ufs-thermal.h | 6 ++++++ drivers/scsi/ufs/ufs.h | 6 +++++- drivers/scsi/ufs/ufshcd.c | 4 ++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufs-thermal.c b/drivers/scsi/ufs/ufs-thermal.c index 469c1ed..dfa5d68 100644 --- a/drivers/scsi/ufs/ufs-thermal.c +++ b/drivers/scsi/ufs/ufs-thermal.c @@ -19,11 +19,32 @@ enum { /** *struct ufs_thermal - thermal zone related data - * @tzone: thermal zone device data + * @trip: trip array */ static struct ufs_thermal { struct thermal_zone_device *zone; -} thermal; + int trip[UFS_THERM_MAX_TRIPS]; +} thermal = { + .trip = { + [UFS_THERM_MAX_TEMP] = 170 * 1000, + [UFS_THERM_MIN_TEMP] = -79 * 1000 + } +}; + +void ufs_thermal_exception_event_handler(struct ufs_hba *hba, + u32 exception_status) +{ + if (WARN_ON_ONCE(!hba->thermal_features)) + return; + + if (exception_status & MASK_EE_TOO_HIGH_TEMP) { + thermal_notify_framework(thermal.zone, UFS_THERM_HIGH_TEMP); + dev_info(hba->dev, "High temperature raised\n"); + } else if (exception_status & MASK_EE_TOO_LOW_TEMP) { + thermal_notify_framework(thermal.zone, UFS_THERM_LOW_TEMP); + dev_info(hba->dev, "Low temperature raised\n"); + } +} static struct thermal_zone_device_ops ufs_thermal_ops = { .get_temp = NULL, @@ -33,8 +54,7 @@ enum { static int ufs_thermal_enable_ee(struct ufs_hba *hba) { - /* later */ - return -EINVAL; + return ufshcd_enable_ee(hba, MASK_EE_URGENT_TEMP); } static void ufs_thermal_zone_unregister(struct ufs_hba *hba) diff --git a/drivers/scsi/ufs/ufs-thermal.h b/drivers/scsi/ufs/ufs-thermal.h index 7c0fcbe..285049e 100644 --- a/drivers/scsi/ufs/ufs-thermal.h +++ b/drivers/scsi/ufs/ufs-thermal.h @@ -11,9 +11,15 @@ #ifdef CONFIG_THERMAL_UFS void ufs_thermal_remove(struct ufs_hba *hba); int ufs_thermal_probe(struct ufs_hba *hba); +void ufs_thermal_exception_event_handler(struct ufs_hba *hba, + u32 exception_status); #else static inline void ufs_thermal_remove(struct ufs_hba *hba) {} static inline int ufs_thermal_probe(struct ufs_hba *hba) {return 0; } +void ufs_thermal_exception_event_handler(struct ufs_hba *hba, + u32 exception_status) +{ +} #endif /* CONFIG_THERMAL_UFS */ #endif /* UFS_THERMAL_H */ diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index eb729cc..8fc0b0c 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -363,7 +363,9 @@ enum power_desc_param_offset { /* Exception event mask values */ enum { MASK_EE_STATUS = 0xFFFF, - MASK_EE_URGENT_BKOPS = (1 << 2), + MASK_EE_URGENT_BKOPS = BIT(2), + MASK_EE_TOO_HIGH_TEMP = BIT(3), + MASK_EE_TOO_LOW_TEMP = BIT(4), }; /* Background operation status */ @@ -375,6 +377,8 @@ enum bkops_status { BKOPS_STATUS_MAX = BKOPS_STATUS_CRITICAL, }; +#define MASK_EE_URGENT_TEMP (MASK_EE_TOO_HIGH_TEMP | MASK_EE_TOO_LOW_TEMP) + /* UTP QUERY Transaction Specific Fields OpCode */ enum query_opcode { UPIU_QUERY_OPCODE_NOP = 0x0, diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index f25b93c..45fb52d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "ufshcd.h" #include "ufs_quirks.h" #include "unipro.h" @@ -5183,6 +5184,9 @@ static void ufshcd_exception_event_handler(struct work_struct *work) if (status & MASK_EE_URGENT_BKOPS) ufshcd_bkops_exception_event_handler(hba); + if (status & MASK_EE_URGENT_TEMP) + ufs_thermal_exception_event_handler(hba, status); + out: ufshcd_scsi_unblock_requests(hba); pm_runtime_put_sync(hba->dev); From patchwork Sun Feb 2 07:41:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 11361535 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 059B017E0 for ; Sun, 2 Feb 2020 07:42:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D81C4206D3 for ; Sun, 2 Feb 2020 07:42:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="r8g9gdBv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727145AbgBBHmN (ORCPT ); Sun, 2 Feb 2020 02:42:13 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:6569 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727134AbgBBHmM (ORCPT ); Sun, 2 Feb 2020 02:42:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580629331; x=1612165331; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=b5vpGURk2FU4BR4h+azmFWcVTABZu/RmGJq2GqpVcf4=; b=r8g9gdBvqE7r4j7eYNTANagzW1dEir/u7YP4Um/7R8Vmn7631LHSFgWn 5G9bFpnIUXBOPOVLjsMJvTU1K7CHomCbhfa/zTajf4Sh/swpoAMZPn+pq /xBKpxTv6OnVM9MYc07PwTIXoyYqmL1eu1bNpE4jjXmWTMlEqjGrBResM yvME+5VC10pS45Rqkjj9D/q7gfHAQCGVEpwTNa3zfvISZnsxrPeOr2ics or04BuHX6U5hyRuLR84ee9wegvR8cF8aJeKLPYE6djEbFN2iXuQF/GNCo QC1veYDT0gRgZsiy/DUm4HFX8kQqDp0chwDdujZYrTyl1N+xAoMH1h8dH A==; IronPort-SDR: juxvMsncY6TzjujqmMW+0VcMoTmcRF4SvAky9m7jdd/TqzOhMYQaPC/tZh014/Bp8bW4n5SawE bZv8QPaBnnFBocogkBMqWeUh0nBARAMvsvjrcU7DbvVYheIcySvIfkBUHUXk54FEMDaAEtEynb aMY4RlHjXk0M6NLVK6H6ESRfRItyUXcZm4mo0nOd/XEYmpLy/BhgH7a3mxyJ3/pnocbLddgOry W7ShC1Nfmad0PgoiUpM65qgTziNZayLEhkcls8UDr8xnO6kMC26XptBGvNkNqho1ki8Oyt/1eu n9A= X-IronPort-AV: E=Sophos;i="5.70,393,1574092800"; d="scan'208";a="130383381" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 02 Feb 2020 15:42:11 +0800 IronPort-SDR: 0qq/XOef7hjvsm2woabK44tycI2xn12x77Mq7d4RNFuehOkgL/Pm5rph9Jx/jAyOnrW6+qrAv+ 54Waj+c+8JeZz+SG+yamVN3yCKkRDRCRjmH9GslZZwAKQOYbhonblPomSKjBuO9r/Gxm+S/Stg Y33L7Kp/e4ByHId85rVFvFjjxbxEbk+7b31k7MmeUFKmxHrc2kfDMDn2HKuZ47MRuvC0JHYkJU 0zZN7cTRpdvkBh9c1Q6yvPcrxQWjUuKYB5HA6shuacw/4CAuNOJHu+VJTM9OFQrSpLdNnGRCIw ezpPpkBazwu6a7PMLpUHznH1 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2020 23:35:17 -0800 IronPort-SDR: nGpJs+ohfdqfADBNn7KA2aNQ+dVJm9zrDnay7hG//l9vc+6hVQwxLSUA7Wj5BLEJqh31QZoUXJ eFr50Ih+uCDCIvR6Ih4Z783HeMwDB67sTqPv3Qji67KnnuAAQj6yD7QXa1o5yWQIFg1rSzKzsM ujLFV4jkw4OdJXR3tSLt37kjVWDQwvkY19fKmCPTRnSAAnZKEDKv3D0/59PnmiAaYDoIY76psM 4HBpywpQdFE++vmWB3MA9hWAz7v6yNeYE44DrDs2ljmqylwEjWT53T7U7He9dpGWTFR+zxdcl9 skc= WDCIronportException: Internal Received: from kfae419068.sdcorp.global.sandisk.com ([10.0.231.195]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Feb 2020 23:42:09 -0800 From: Avi Shchislowski To: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Avi Shchislowski , Uri Yanai Subject: [PATCH 5/5] scsi: ufs: temperature atrributes add to ufs_sysfs Date: Sun, 2 Feb 2020 09:41:53 +0200 Message-Id: <1580629313-20078-6-git-send-email-avi.shchislowski@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> References: <1580629313-20078-1-git-send-email-avi.shchislowski@wdc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Avi Shchislowski Signed-off-by: Uri Yanai Signed-off-by: Avi Shchislowski --- drivers/scsi/ufs/ufs-sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index dbdf8b0..180f4db 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -667,6 +667,9 @@ static DEVICE_ATTR_RO(_name) UFS_ATTRIBUTE(ffu_status, _FFU_STATUS); UFS_ATTRIBUTE(psa_state, _PSA_STATE); UFS_ATTRIBUTE(psa_data_size, _PSA_DATA_SIZE); +UFS_ATTRIBUTE(rough_temp, _ROUGH_TEMP); +UFS_ATTRIBUTE(too_high_temp, _TOO_HIGH_TEMP); +UFS_ATTRIBUTE(too_low_temp, _TOO_LOW_TEMP); static struct attribute *ufs_sysfs_attributes[] = { &dev_attr_boot_lun_enabled.attr, @@ -685,6 +688,9 @@ static DEVICE_ATTR_RO(_name) &dev_attr_ffu_status.attr, &dev_attr_psa_state.attr, &dev_attr_psa_data_size.attr, + &dev_attr_rough_temp.attr, + &dev_attr_too_high_temp.attr, + &dev_attr_too_low_temp.attr, NULL, };