Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17941038ybl; Thu, 2 Jan 2020 15:14:19 -0800 (PST) X-Google-Smtp-Source: APXvYqzcA2snEhFqk45QxX1x4fNc7R3T6CMjlE+gmC4gTzAGb1IOtq7sFWz1ShaCeQbcKpO4yIKX X-Received: by 2002:a9d:242:: with SMTP id 60mr80055836otb.253.1578006859137; Thu, 02 Jan 2020 15:14:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006859; cv=none; d=google.com; s=arc-20160816; b=td/+18wFqb+DxPSrKoZQcS2uI2v98VLGe3AIV2s6X1IPnPYJjWm2HNKAjfsA7Ueii6 rr8qx1UXVVNxtkyV4jGbWHlg3Il2OLlv89Raqb6Oa7HrAR41cRZkjjpLB/+q3Tm4Bibh 5OUfOm7x2B6Ucw5XYR7IqPHVTGXSETWYKrdDeHOw7dtTzGxh2WlJ9hmqBhRvBD5bYZ6r /oKP2aaii0gywBjJRMQDK8D/TUzFkaeHZQF0aFpYMGzuJuAdI25i+Y/T+JAx7/ZkW71H 37nh2F72FDTBgIZpBjeA+Nyt7NQN0Ktii6CBuhtWHitjeds8wtyM+B9rRIs5iJ95d/u1 M5Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=n1QFKwCsWFT2/EGeR3REs6piLtoEpVr8ax1xUqCybzc=; b=U42kxsfhwUNPx2EsKDiYTdmKkWcGLMky2k7Im+kuRPdgziWIEWVgWnJh4W7MzWOVeV UCpVkIvhQkUWeeqdA1jtT30Oqcuieng0aKJu+WBFnGTl/Wx4s+SsHuvvuGLjKpYIcD3c thhXKC6HuLzTUylSpvnc/tmbGIsL8lgRXyldjEW44gQ81WBB0tDQRO1oHbNzyMJOXl3D zeYDEf4Gs437gQ9SdYI7Wyfyjby/mBag9bsS/d1yJE0TfNu8UOVQXqxbR9e5smWlONC6 x8U0/i6b3mRtSbWExhbp5NYvWmPGFpYmX0hh9fD1622v1tb9fhfmC6dfH5lN0wc2bCFU It/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yg+Rf7sm; 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 h138si26309431oib.6.2020.01.02.15.14.07; Thu, 02 Jan 2020 15:14:19 -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=@kernel.org header.s=default header.b=Yg+Rf7sm; 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 S1728762AbgABWxg (ORCPT + 99 others); Thu, 2 Jan 2020 17:53:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:40978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729020AbgABWVh (ORCPT ); Thu, 2 Jan 2020 17:21:37 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6E5E820863; Thu, 2 Jan 2020 22:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003696; bh=CMzUwSsyVQSqBUOiejZscCQQm1OBmrt+0022tPOxSKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yg+Rf7smd0Iuw/CYS2Jw8v/FIh+Kgcvs7eUYzRHGl8syJU3zJ8l2xScofcK7dXUp8 texujMJo5oioCPEnh4D3NtJ6ixbZU8C7jbM2meT5N0AMpLoO1J9Ar0X2f3OlTC0OPd 5HktiMckqDq7VR4vN2KomQTYZi1rwHsiTUPYYdWQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avri Altman , Bean Huo , Subhash Jadavani , Can Guo , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 053/114] scsi: ufs: Fix error handing during hibern8 enter Date: Thu, 2 Jan 2020 23:07:05 +0100 Message-Id: <20200102220034.406463258@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Subhash Jadavani [ Upstream commit 6d303e4b19d694cdbebf76bcdb51ada664ee953d ] During clock gating (ufshcd_gate_work()), we first put the link hibern8 by calling ufshcd_uic_hibern8_enter() and if ufshcd_uic_hibern8_enter() returns success (0) then we gate all the clocks. Now let’s zoom in to what ufshcd_uic_hibern8_enter() does internally: It calls __ufshcd_uic_hibern8_enter() and if failure is encountered, link recovery shall put the link back to the highest HS gear and returns success (0) to ufshcd_uic_hibern8_enter() which is the issue as link is still in active state due to recovery! Now ufshcd_uic_hibern8_enter() returns success to ufshcd_gate_work() and hence it goes ahead with gating the UFS clock while link is still in active state hence I believe controller would raise UIC error interrupts. But when we service the interrupt, clocks might have already been disabled! This change fixes for this by returning failure from __ufshcd_uic_hibern8_enter() if recovery succeeds as link is still not in hibern8, upon receiving the error ufshcd_hibern8_enter() would initiate retry to put the link state back into hibern8. Link: https://lore.kernel.org/r/1573798172-20534-8-git-send-email-cang@codeaurora.org Reviewed-by: Avri Altman Reviewed-by: Bean Huo Signed-off-by: Subhash Jadavani Signed-off-by: Can Guo Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 7510d8328d4d..3601e770da16 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -3875,15 +3875,24 @@ static int __ufshcd_uic_hibern8_enter(struct ufs_hba *hba) ktime_to_us(ktime_sub(ktime_get(), start)), ret); if (ret) { + int err; + dev_err(hba->dev, "%s: hibern8 enter failed. ret = %d\n", __func__, ret); /* - * If link recovery fails then return error so that caller - * don't retry the hibern8 enter again. + * If link recovery fails then return error code returned from + * ufshcd_link_recovery(). + * If link recovery succeeds then return -EAGAIN to attempt + * hibern8 enter retry again. */ - if (ufshcd_link_recovery(hba)) - ret = -ENOLINK; + err = ufshcd_link_recovery(hba); + if (err) { + dev_err(hba->dev, "%s: link recovery failed", __func__); + ret = err; + } else { + ret = -EAGAIN; + } } else ufshcd_vops_hibern8_notify(hba, UIC_CMD_DME_HIBER_ENTER, POST_CHANGE); @@ -3897,7 +3906,7 @@ static int ufshcd_uic_hibern8_enter(struct ufs_hba *hba) for (retries = UIC_HIBERN8_ENTER_RETRIES; retries > 0; retries--) { ret = __ufshcd_uic_hibern8_enter(hba); - if (!ret || ret == -ENOLINK) + if (!ret) goto out; } out: -- 2.20.1