From patchwork Fri Sep 8 14:53:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 721258 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 6C9DCEE8012 for ; Fri, 8 Sep 2023 14:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235045AbjIHOyu (ORCPT ); Fri, 8 Sep 2023 10:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232487AbjIHOyu (ORCPT ); Fri, 8 Sep 2023 10:54:50 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AB5C1BF1 for ; Fri, 8 Sep 2023 07:54:27 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68c0cb00fb3so1984777b3a.2 for ; Fri, 08 Sep 2023 07:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694184867; x=1694789667; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v0/IfcD+bVp+TwfTl9BonGyGe+3MQ6GUS3Cq64UrgTs=; b=i/prfLoQBAJv5JeNcRoJ0k7D8scN144PeGCyyS0LqUMlyJwGCJ9Toh40FXN1kjxNpS 0xFIQ8REKv/o6Qe8uxTEjjBwPTYXxORatEKbKfTpTOINPzclQoMh6E3eHxvsXd/xDWK0 GGBM0/SyY0sCKHkWQzvk5KGrjEySG+kWQm7QQ8LNU7IeTi1WBcWTeVj1etOWpAOLAb9d GoqCbVcINuwhPyBOIXU/Afqw5FLsBySQT+g1QzaEMnAuTHlHsPTjKm3O+kLw409svJDv 8drIGiIpHrOI53of/ec616ewcAq+GaufzLAfjfN5dR8ACp/3ovufiAfRfXADcFEKFj1O PUow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694184867; x=1694789667; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v0/IfcD+bVp+TwfTl9BonGyGe+3MQ6GUS3Cq64UrgTs=; b=iFTlNLGvEYVCefej/RoFYNaJd8ExLFACIN/6AcAzOO5KKASRfL/BEFa5Kt74RLSo1V 1nXJInm71UGyV0Fe94+rAfCkHhVeqCkHb7m7qB1FlpUfYf++hlcKAEOBI3i+qCxmQZF8 MoG47AV0LsXLFWoZVlOezJ6UkrcuFZLsJagtt5Q+GmIWS8tiqGsZ4/s4lKrX0VhMaefO qKqj0Hkqr4B41QaM7JAv6eW0i2fCqOsTfVoXUh+nZP+kjYkJI3mPPPI+wc4Zb+c2NFg6 e39rdD1E8kh8WlVVT5aLR6VeEQDsmAOv6Ap6egceCJtjKPtDCeWfY8cNr8jW2CSNnI4h 6/Mw== X-Gm-Message-State: AOJu0Yyjkbtqti/RHLVMojqtJiWYzBRP8b2HSikoHoRUiK58X5gBt9Uf 9vk5gBVlCOeM/93DDfcAIKuLpeI3XN9YvCvdZg== X-Google-Smtp-Source: AGHT+IHYIFo3OMAOQfRI0s5oC0CJ3wzrb/Rkg+Xten7sB/lRtfVzRDXX2fUj57YnJVr4eUxM1qFMjg== X-Received: by 2002:a05:6a00:1825:b0:68e:2dad:13a5 with SMTP id y37-20020a056a00182500b0068e2dad13a5mr2811724pfa.10.1694184866738; Fri, 08 Sep 2023 07:54:26 -0700 (PDT) Received: from localhost.localdomain ([117.193.215.15]) by smtp.gmail.com with ESMTPSA id t4-20020a62ea04000000b0068a30f6cf32sm1463212pfh.143.2023.09.08.07.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 07:54:26 -0700 (PDT) From: Manivannan Sadhasivam To: jejb@linux.ibm.com, martin.petersen@oracle.com Cc: bvanassche@acm.org, avri.altman@wdc.com, alim.akhtar@samsung.com, andersson@kernel.org, konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, quic_cang@quicinc.com, quic_nitirawa@quicinc.com, Manivannan Sadhasivam , stable@vger.kernel.org Subject: [PATCH 1/2] scsi: ufs: ufs-qcom: Update PHY settings only when scaling to higher gears Date: Fri, 8 Sep 2023 20:23:28 +0530 Message-Id: <20230908145329.154024-1-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The "hs_gear" variable is used to program the PHY settings (submode) during ufs_qcom_power_up_sequence(). Currently, it is being updated every time the agreed gear changes. Due to this, if the gear got downscaled before suspend (runtime/system), then while resuming, the PHY settings for the lower gear will be applied first and later when scaling to max gear with REINIT, the PHY settings for the max gear will be applied. This adds a latency while resuming and also really not needed as the PHY gear settings are backwards compatible i.e., we can continue using the PHY settings for max gear with lower gear speed. So let's update the "hs_gear" variable _only_ when the agreed gear is greater than the current one. This guarantees that the PHY settings will be changed only during probe time and fatal error condition. Due to this, UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH can now be skipped when the PM operation is in progress. Cc: stable@vger.kernel.org Fixes: 96a7141da332 ("scsi: ufs: core: Add support for reinitializing the UFS device") Reported-by: Can Guo Signed-off-by: Manivannan Sadhasivam Reviewed-by: Can Guo Tested-by: Can Guo --- drivers/ufs/core/ufshcd.c | 3 ++- drivers/ufs/host/ufs-qcom.c | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 34472871610d..1f0a9d96e613 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -8782,7 +8782,8 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) if (ret) goto out; - if (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH) { + if (!hba->pm_op_in_progress && + (hba->quirks & UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH)) { /* Reset the device and controller before doing reinit */ ufshcd_device_reset(hba); ufshcd_hba_stop(hba); diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index 78689d3479e4..ebb8054a3b3e 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -909,8 +909,13 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba, return ret; } - /* Use the agreed gear */ - host->hs_gear = dev_req_params->gear_tx; + /* + * Update hs_gear only when the gears are scaled to a higher value. This is because, + * the PHY gear settings are backwards compatible and we only need to change the PHY + * settings while scaling to higher gears. + */ + if (dev_req_params->gear_tx > host->hs_gear) + host->hs_gear = dev_req_params->gear_tx; /* enable the device ref clock before changing to HS mode */ if (!ufshcd_is_hs_mode(&hba->pwr_info) && From patchwork Fri Sep 8 14:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 720876 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 3DFC6EE8013 for ; Fri, 8 Sep 2023 14:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244217AbjIHOyz (ORCPT ); Fri, 8 Sep 2023 10:54:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244051AbjIHOyw (ORCPT ); Fri, 8 Sep 2023 10:54:52 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96B3F1FC4 for ; Fri, 8 Sep 2023 07:54:31 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68a3b66f350so1975382b3a.3 for ; Fri, 08 Sep 2023 07:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694184871; x=1694789671; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=86VDfrxrf9fXsAcuShAF/QBfIIcppRCopsc3REU8feU=; b=foYCpmudpOYOEyOlgjd/H4GRfBJvwfcvv/eP/3Do/94gnOGy7hQkR/nqa5IKjULOah QWSCNRURaRseVKm2OgfPlMjgGuCw0XQXD0mVgTMdxGw+dYwV5kl4HvtGj37l3NVxK6Zt wZmTs8vcyEsd9t4sQFsZ4CGKMnu4upyzdAEepMP6AEEwjk7VHWOCVRchGIrwebDTbUP9 QhB5VwZF30rERCgUwIf+HMGLtOQcI+6HGTVWz5aKB9bZkxWkO1rR8lFhvoyH+THBMHQt siVEORQKc3XCxBb/yrOTCgepICeOsYR/d5yAvzOPR4MwYvujibDHdfm/JUmTuSTH6ciR TS5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694184871; x=1694789671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=86VDfrxrf9fXsAcuShAF/QBfIIcppRCopsc3REU8feU=; b=FOpGqw5y6w8quwopY86THL/7yfbPtjBMZbESPJIWXsRfcIFTNVOcb0IVEdJEttxl1O jR4AAglGV3GSx+rUapAOB/xm15bVVfonkX9uRSAPaIikatWoJxZUjLJqpgJmdth4r3Mw KThqPdU3d4oM1KOvMN2y+R83FK+gWTSzSv1O95J+vHNm9TVppDkBU8rbFemuoWvP2gvV rVIdsdw7HE6tejY7hJKcmODIuUm0btqyJ7up894T5L1U0a+Kt+6Hz5EtrRwh+zJLDhdD gYJz1qooPGA5bcAILVm6hIOv9/Ji/cnmDzouMfKCP9VtRBvNEvc4nRcqRnazB4v+qJxn LNQA== X-Gm-Message-State: AOJu0Yy1VbvgGMu/X1FvyhuHD4nNRjxUTWFdUz/KW3CZdeNrKeOVHrWr ahTjj7aZwYMT2rjpBR7+lFdv X-Google-Smtp-Source: AGHT+IErgGYrFaXUzuw9fd5J4Q7ecSPBMtyBIW0tnDf6+Q6dpLwMXGDBzf1+DEzVXwJkB0T+g/zxqA== X-Received: by 2002:a05:6a20:7b03:b0:131:a21:9f96 with SMTP id s3-20020a056a207b0300b001310a219f96mr2266797pzh.6.1694184871044; Fri, 08 Sep 2023 07:54:31 -0700 (PDT) Received: from localhost.localdomain ([117.193.215.15]) by smtp.gmail.com with ESMTPSA id t4-20020a62ea04000000b0068a30f6cf32sm1463212pfh.143.2023.09.08.07.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 07:54:30 -0700 (PDT) From: Manivannan Sadhasivam To: jejb@linux.ibm.com, martin.petersen@oracle.com Cc: bvanassche@acm.org, avri.altman@wdc.com, alim.akhtar@samsung.com, andersson@kernel.org, konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, quic_cang@quicinc.com, quic_nitirawa@quicinc.com, Manivannan Sadhasivam Subject: [PATCH 2/2] scsi: ufs: ufs-qcom: Rename "hs_gear" to "phy_gear" Date: Fri, 8 Sep 2023 20:23:29 +0530 Message-Id: <20230908145329.154024-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230908145329.154024-1-manivannan.sadhasivam@linaro.org> References: <20230908145329.154024-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The "hs_gear" variable is used to cache the gear setting for the PHY that will be used during ufs_qcom_power_up_sequence(). But it creates ambiguity with the gear setting used by the ufshcd driver. So let's rename it to "phy_gear" to make it explicit that this variable caches the gear setting for the PHY. Signed-off-by: Manivannan Sadhasivam Reviewed-by: Can Guo Tested-by: Can Guo --- drivers/ufs/host/ufs-qcom.c | 14 +++++++------- drivers/ufs/host/ufs-qcom.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index ebb8054a3b3e..93a72d0a1751 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -460,7 +460,7 @@ static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) return ret; } - phy_set_mode_ext(phy, PHY_MODE_UFS_HS_B, host->hs_gear); + phy_set_mode_ext(phy, PHY_MODE_UFS_HS_B, host->phy_gear); /* power on phy - start serdes and phy's power and clocks */ ret = phy_power_on(phy); @@ -910,12 +910,12 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba, } /* - * Update hs_gear only when the gears are scaled to a higher value. This is because, - * the PHY gear settings are backwards compatible and we only need to change the PHY - * settings while scaling to higher gears. + * Update phy_gear only when the gears are scaled to a higher value. This is + * because, the PHY gear settings are backwards compatible and we only need to + * change the PHY gear settings while scaling to higher gears. */ - if (dev_req_params->gear_tx > host->hs_gear) - host->hs_gear = dev_req_params->gear_tx; + if (dev_req_params->gear_tx > host->phy_gear) + host->phy_gear = dev_req_params->gear_tx; /* enable the device ref clock before changing to HS mode */ if (!ufshcd_is_hs_mode(&hba->pwr_info) && @@ -1282,7 +1282,7 @@ static int ufs_qcom_init(struct ufs_hba *hba) * Power up the PHY using the minimum supported gear (UFS_HS_G2). * Switching to max gear will be performed during reinit if supported. */ - host->hs_gear = UFS_HS_G2; + host->phy_gear = UFS_HS_G2; return 0; diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index dc27395ecba1..8d8613eff959 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -227,7 +227,7 @@ struct ufs_qcom_host { struct gpio_desc *device_reset; - u32 hs_gear; + u32 phy_gear; int esi_base; bool esi_enabled;