Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4009876pxb; Tue, 17 Nov 2020 09:02:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWB0pUSoIyTbG33PrkhbGz2f13qi5X/tGnalqnxwuHN5oR6T3cOvRxhQUkfQKyQiXnuZ1D X-Received: by 2002:a17:906:27c2:: with SMTP id k2mr3636290ejc.211.1605632575055; Tue, 17 Nov 2020 09:02:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605632575; cv=none; d=google.com; s=arc-20160816; b=WX7lgdTXqq5RjyBQRWRLytOAM8UnJ3LA4EicDHZ1wdL4CC3NuJx+gRcm/RTJE2A0eW 7S7uXO6GcLT95j209Dv/Eg/1QleUhcpy4zlP5yR2kUSPhxYhYxoNABOVJsDNx8k+ded8 pvWFu6GcJLyoLlVA16PEcbjzmQg51bdfwLj/7FQ0OsxGjz6tMulC8Sz3Lt8vq9l1HS2A DfkWnbhX4e8JSAKNIY3qjzJOke52E5wI9zZlCCUyozEZs97AaEECdu3Fu4gwe+I5XCYs zXQAL/DmjpZa5jfjrGZDwElFQejzXk59rUNHtlUH8kkhBnDfCS9Q9wSuiM2zhuGjG62A AIbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1ufmmukNplsFog6L0EfHCS2WdAKYzS06H8vwzfUz4Aw=; b=NuVx9dsVIrUFp/A4u1uu0QMBzswurvkAeeOQc6W8JKlwHpDGKOuABX8hNqKgPjw6Hp UxoX56GAcfs72wIv8AqaI8NQy6XM953tsLdyMd7o0tsGdRQtC7FwhOOZA4hmBJ4KpLTL e2Ba+80+HJdQ9n89vdGiSb97j6h0kSJEN/EPVntak6i9AxY52eJ2HWtHq2qVg5BO4O5n ngz00XwmfHbqsp72yywfQCgKtvrS4sVSuitnXLGbcfLcfA1qRsHFQK7eHEUddSLicCJL rwYNeC7WI80sLhpSHDcuakRIDV0e1drv0/T7lwbiYRLX3nUCPjd2pf4n0YsFFuDp7RcU DFvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jWLdUvZQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d11si7048434ejt.527.2020.11.17.09.02.28; Tue, 17 Nov 2020 09:02:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jWLdUvZQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbgKQQ6s (ORCPT + 99 others); Tue, 17 Nov 2020 11:58:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:43838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728330AbgKQQ6s (ORCPT ); Tue, 17 Nov 2020 11:58:48 -0500 Received: from localhost (unknown [104.132.1.66]) (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 4895B2466D; Tue, 17 Nov 2020 16:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605632327; bh=kicS4tzR+Z+1NqfDkwWxTmUjLJz1UsouESdl9kc6obo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWLdUvZQIG7KYttKbbMAKWmlBkdq2DMRtr+lp7Jad4wJId2/lIBAW7qPUAltQgpW8 PMOxJltFiaxBNk0X+M4kKpNen09MV/OJC0dGlYeKAwJX2Xx/dUkgKYxd6xxsUJZSXK 3T2e9lTR6mvvPN5eSrSEIqp2yjyRUdYUofE3GIdM= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, kernel-team@android.com Cc: cang@codeaurora.org, alim.akhtar@samsung.com, avri.altman@wdc.com, bvanassche@acm.org, martin.petersen@oracle.com, stanley.chu@mediatek.com, Jaegeuk Kim Subject: [PATCH v5 3/7] scsi: ufs: clear UAC for FFU and RPMB LUNs Date: Tue, 17 Nov 2020 08:58:35 -0800 Message-Id: <20201117165839.1643377-4-jaegeuk@kernel.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201117165839.1643377-1-jaegeuk@kernel.org> References: <20201117165839.1643377-1-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jaegeuk Kim In order to conduct FFU or RPMB operations, UFS needs to clear UAC. This patch clears it explicitly, so that we could get no failure given early execution. Signed-off-by: Jaegeuk Kim --- drivers/scsi/ufs/ufshcd.c | 70 +++++++++++++++++++++++++++++++++++---- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 6c9269bffcbd..8e696ca79b40 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7058,7 +7058,6 @@ static inline void ufshcd_blk_pm_runtime_init(struct scsi_device *sdev) static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) { int ret = 0; - struct scsi_device *sdev_rpmb; struct scsi_device *sdev_boot; hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0, @@ -7071,14 +7070,14 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) ufshcd_blk_pm_runtime_init(hba->sdev_ufs_device); scsi_device_put(hba->sdev_ufs_device); - sdev_rpmb = __scsi_add_device(hba->host, 0, 0, + hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL); - if (IS_ERR(sdev_rpmb)) { - ret = PTR_ERR(sdev_rpmb); + if (IS_ERR(hba->sdev_rpmb)) { + ret = PTR_ERR(hba->sdev_rpmb); goto remove_sdev_ufs_device; } - ufshcd_blk_pm_runtime_init(sdev_rpmb); - scsi_device_put(sdev_rpmb); + ufshcd_blk_pm_runtime_init(hba->sdev_rpmb); + scsi_device_put(hba->sdev_rpmb); sdev_boot = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL); @@ -7602,6 +7601,63 @@ static int ufshcd_add_lus(struct ufs_hba *hba) return ret; } +static int +ufshcd_send_request_sense(struct ufs_hba *hba, struct scsi_device *sdp); + +static int ufshcd_clear_ua_wlun(struct ufs_hba *hba, u8 wlun) +{ + struct scsi_device *sdp; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(hba->host->host_lock, flags); + if (wlun == UFS_UPIU_UFS_DEVICE_WLUN) + sdp = hba->sdev_ufs_device; + else if (wlun == UFS_UPIU_RPMB_WLUN) + sdp = hba->sdev_rpmb; + else + BUG_ON(1); + if (sdp) { + ret = scsi_device_get(sdp); + if (!ret && !scsi_device_online(sdp)) { + ret = -ENODEV; + scsi_device_put(sdp); + } + } else { + ret = -ENODEV; + } + spin_unlock_irqrestore(hba->host->host_lock, flags); + if (ret) + goto out_err; + + ret = ufshcd_send_request_sense(hba, sdp); + scsi_device_put(sdp); +out_err: + if (ret) + dev_err(hba->dev, "%s: UAC clear LU=%x ret = %d\n", + __func__, wlun, ret); + return ret; +} + +static int ufshcd_clear_ua_wluns(struct ufs_hba *hba) +{ + int ret = 0; + + if (!hba->wlun_dev_clr_ua) + goto out; + + ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_UFS_DEVICE_WLUN); + if (!ret) + ret = ufshcd_clear_ua_wlun(hba, UFS_UPIU_RPMB_WLUN); + if (!ret) + hba->wlun_dev_clr_ua = false; +out: + if (ret) + dev_err(hba->dev, "%s: Failed to clear UAC WLUNS ret = %d\n", + __func__, ret); + return ret; +} + /** * ufshcd_probe_hba - probe hba to detect device and initialize * @hba: per-adapter instance @@ -7721,6 +7777,8 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) pm_runtime_put_sync(hba->dev); ufshcd_exit_clk_scaling(hba); ufshcd_hba_exit(hba); + } else { + ufshcd_clear_ua_wluns(hba); } } diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 47eb1430274c..718881d038f5 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -681,6 +681,7 @@ struct ufs_hba { * "UFS device" W-LU. */ struct scsi_device *sdev_ufs_device; + struct scsi_device *sdev_rpmb; enum ufs_dev_pwr_mode curr_dev_pwr_mode; enum uic_link_state uic_link_state; -- 2.29.2.299.gdc1121823c-goog