Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1490483ybc; Tue, 12 Nov 2019 22:48:00 -0800 (PST) X-Google-Smtp-Source: APXvYqw/fVKSwCLY0iSh2KWd7y/jgANl76BEK4yd/2tyKb9+Fjv2lbF3ZPkictf17XWZb3HNlXxZ X-Received: by 2002:a17:907:1114:: with SMTP id qu20mr1311011ejb.42.1573627680449; Tue, 12 Nov 2019 22:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573627680; cv=none; d=google.com; s=arc-20160816; b=dfCBTWofM9DjXRJHA0i+XTZdqaWInbCGuIsHNjvWPv2j81LtvQbQEW+pabRGEJmS79 V87IQ4LdCSIWaoZnNj6qguz2X6/Onv6J6GWtKognIvDR5mf99y5uqceAA/H8kAa08hZI QBOe86zP6TfaNJh5W6axrKZx6H5XbzEUvdlPI6ekToXAZ2iQzcHy4DgWVoOvyYlD5yWs qRgoYdC/kNf5ZABN3Q6mX10iq3vS2U+JwoIS+38sL80SzGY+wKgnb0WaFB8RNRQVRMJX VVnJUzhrnQy3PXm2EfFH1ZQ6OXtErrLcv7/v/Ck9uaPHdbOHx8yWZT1dDoxtGoXuEUmf kHXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=IUS/siexDWKYE8vvcFJA+n53fmS+aq+VQUXa/RYnAqk=; b=I+Iu5QjTsVt5fU/sXOe/BXsqTAzp7Bkw2OTrktOt8e0UG1EnQ2GyqImKLIeSwNBifY ILyua3cyswBrx4BkNdV1w2hCG1kIaG5ykX0coGhTf1m+tzDCN5M09WkPuPy1Oyg+WcOl NIew1bG+Z/oUFnw28rA6q94eXmOP3vrcT8bLjbrBw29xvtnTF2XO4REbiGErNJM56nH+ 9aQ9cfgciAH0IE3UT6DfWG5HFeRJp5RdJ96JLAzp6FykWRazzW3/AYr8Ivjou4GOAd5g vGh1218ZppQz4G5rLPJ+AeSjk67pyVxZMPUK5WIqxDm29UoqGR8nfdh1Q8ayrOcXt8e/ zPvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=UKVgShuZ; dkim=pass header.i=@codeaurora.org header.s=default header.b=cxiTgREj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x50si783217eda.155.2019.11.12.22.47.34; Tue, 12 Nov 2019 22:48:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=UKVgShuZ; dkim=pass header.i=@codeaurora.org header.s=default header.b=cxiTgREj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbfKMGqp (ORCPT + 99 others); Wed, 13 Nov 2019 01:46:45 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:44548 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725866AbfKMGqp (ORCPT ); Wed, 13 Nov 2019 01:46:45 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id D84626078A; Wed, 13 Nov 2019 06:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1573627603; bh=9wd/SNKdJgzdMez2m/ydyczwe4kRopp2y+JbvFH5OOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UKVgShuZJgJh7a+pxm66NixWUcLhHMpO4RvwnICljriNlg5n99TwVimUKBf+IQLNh iVcK43yfxKgPHUrZ+u4n7ZQYVr0Fqn1gKOZnHOVmpXuFcxNkL368ZF1S5W1wUn2pAO hhtQnGtn/GP5BqPQ5kAZL/hFmaWXFyte+Sla8zYk= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 82ED76078A; Wed, 13 Nov 2019 06:46:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1573627602; bh=9wd/SNKdJgzdMez2m/ydyczwe4kRopp2y+JbvFH5OOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cxiTgREj2IX6ppLbDBMgvvWnvE/Kc+qHREZsK9gmpqLXZRb7Qjkbk4z9b4QBY+mJx LIRvebstN4HqfWNIErXuQVwMEPpqQaJ9OlYapa+nbtBA5CIx0iX5D+CFokDPoXjL6S /b1aJycB50pDo+LITL5Urbn+BZFtYc/trJGtlJuM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 82ED76078A Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Bean Huo , Tomas Winkler , Stanley Chu , Venkat Gopalakrishnan , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 3/7] scsi: ufs: Fix up auto hibern8 enablement Date: Tue, 12 Nov 2019 22:45:47 -0800 Message-Id: <1573627552-12615-4-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1573627552-12615-1-git-send-email-cang@codeaurora.org> References: <1573627552-12615-1-git-send-email-cang@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix up possible unclocked register access to auto hibern8 register in resume path and through sysfs entry. Meanwhile, enable auto hibern8 only after device is fully initialized in probe path. Signed-off-by: Can Guo --- drivers/scsi/ufs/ufs-sysfs.c | 17 +++++++++++------ drivers/scsi/ufs/ufshcd.c | 12 ++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 969a36b..6c2f19e 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -126,13 +126,18 @@ static void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) return; spin_lock_irqsave(hba->host->host_lock, flags); - if (hba->ahit == ahit) - goto out_unlock; - hba->ahit = ahit; - if (!pm_runtime_suspended(hba->dev)) - ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); -out_unlock: + if (hba->ahit != ahit) + hba->ahit = ahit; spin_unlock_irqrestore(hba->host->host_lock, flags); + if (!pm_runtime_suspended(hba->dev)) { + pm_runtime_get_sync(hba->dev); + ufshcd_hold(hba, false); + spin_lock_irqsave(hba->host->host_lock, flags); + ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); + spin_unlock_irqrestore(hba->host->host_lock, flags); + ufshcd_release(hba); + pm_runtime_put(hba->dev); + } } /* Convert Auto-Hibernate Idle Timer register value to microseconds */ diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 525f8e6..f12f5a7 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6892,9 +6892,6 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) /* UniPro link is active now */ ufshcd_set_link_active(hba); - /* Enable Auto-Hibernate if configured */ - ufshcd_auto_hibern8_enable(hba); - ret = ufshcd_verify_dev_init(hba); if (ret) goto out; @@ -6945,6 +6942,9 @@ static int ufshcd_probe_hba(struct ufs_hba *hba) /* set the state as operational after switching to desired gear */ hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL; + /* Enable Auto-Hibernate if configured */ + ufshcd_auto_hibern8_enable(hba); + /* * If we are in error handling context or in power management callbacks * context, no need to scan the host @@ -7962,12 +7962,12 @@ static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) if (hba->clk_scaling.is_allowed) ufshcd_resume_clkscaling(hba); - /* Schedule clock gating in case of no access to UFS device yet */ - ufshcd_release(hba); - /* Enable Auto-Hibernate if configured */ ufshcd_auto_hibern8_enable(hba); + /* Schedule clock gating in case of no access to UFS device yet */ + ufshcd_release(hba); + goto out; set_old_link_state: -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project