Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1609409pxb; Mon, 13 Sep 2021 01:14:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzPfHWQgfgXdx3/NwKScCEjwxrdM9YwQpgMnUT4ihljccJlzl+Pi/jL7f42QyThXjlxer8 X-Received: by 2002:a05:6e02:f13:: with SMTP id x19mr7122387ilj.216.1631520870110; Mon, 13 Sep 2021 01:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631520870; cv=none; d=google.com; s=arc-20160816; b=OTfTKyZ0bpKCY3tTDYFyYO1yeHeyfJrlAJGGYwq/w1DRaeEUmYqqhHM9upLii6Zjgc 0zOXj/fRH5Z/PuaDUrO6k8NZkElq0SJopGCtJuXimxqBW909m0LtXHXqvxpe8Sm2wOAB ftRs5itBlS2ysd1X5rsUoPFivfYAqyDB/mBHxD7DVqZBL7bfDlS1dTxqhoE+DtL+cwaQ 0JwazkXk80SZ3672Z1cDEtrt+hVjZVq01PysEYf0odSAOC5V+a631fBiOV2jVkFe/5cL YzUh7QuOYvG2rMTtnZLI869KKQtlej+0C52OcBWOA4257NBOyhHAsvKUUyRgygKsEqrm duow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type:in-reply-to :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=swn3c0mDNJ/0hlD7Do34gPFEkYMDRPAATDWWj2Pi0sc=; b=aFqWQWm5FEVIH5fiWcDABSqD9g3qTi9r5DDLCn9NflVsrQ7WtjYoH25AOj1qk+/ZyI uBkO/BOR1pRliY8h/+Y/N78YspZAwWYnG7Y6DNUfovTNZYHjVNkMS7bdul3XkcBN2OUs X2WuyEjfHf4FHjzMi4vM4ReexWKgoJBIv083cy0C2GSbmCNt9CS3lhVjPaSNac+6+BrN Wxit49vUKpHGDQ2BYnjq/WGCf2/cm/UYtTV05sdUrE0+eGT8g4JLcB4jQzvwbr/GOr9O WfVhJP1VVj2DLnQK9J8L2vjl9k284ukPUksug4U/2DTl1YEp39XfPy3cUhIANG1BHlGi UQDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=K9uTRG+3; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h22si5934493jal.57.2021.09.13.01.14.19; Mon, 13 Sep 2021 01:14:30 -0700 (PDT) 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=@samsung.com header.s=mail20170921 header.b=K9uTRG+3; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237941AbhIMINa (ORCPT + 99 others); Mon, 13 Sep 2021 04:13:30 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:15388 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237930AbhIMINN (ORCPT ); Mon, 13 Sep 2021 04:13:13 -0400 Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210913081156epoutp0165e6d31db80f8f0f9304a3028160e11a~kU3KI62Hd1432614326epoutp01h for ; Mon, 13 Sep 2021 08:11:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210913081156epoutp0165e6d31db80f8f0f9304a3028160e11a~kU3KI62Hd1432614326epoutp01h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1631520716; bh=swn3c0mDNJ/0hlD7Do34gPFEkYMDRPAATDWWj2Pi0sc=; h=From:To:Cc:Subject:Date:In-Reply-To:In-Reply-To:References:From; b=K9uTRG+3Z5Lt98nKtKeYTioJnmTIxZg8UqM+3V3g9nx+56j2JzsPUI2qR6nYtG/+Y pzdfRwV9SnxCyO9+Dnm+Jk14PWNJI7agRC7GklI23VnfzSIoh/2Tl7YbiCwDOvoEwl KZ4XdHoE8zzPGG4OVd19LBuOGpsfD26SUjGkHkzg= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20210913081155epcas2p18d703a2887b2f6211a5a913f6325c751~kU3JjJjoa0434804348epcas2p1M; Mon, 13 Sep 2021 08:11:55 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.40.190]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4H7K2K6W12z4x9Px; Mon, 13 Sep 2021 08:11:53 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id DD.AC.09472.8C70F316; Mon, 13 Sep 2021 17:11:52 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20210913081152epcas2p2eac4a8dbef33164a150dccf2e282dcce~kU3GHqJtB0641906419epcas2p2p; Mon, 13 Sep 2021 08:11:52 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210913081152epsmtrp1ea874e3c703c9ee8bcef2e0ff1377e2e~kU3GG30sr1354313543epsmtrp1K; Mon, 13 Sep 2021 08:11:52 +0000 (GMT) X-AuditID: b6c32a48-d75ff70000002500-fd-613f07c85b0a Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id C0.DE.08750.7C70F316; Mon, 13 Sep 2021 17:11:52 +0900 (KST) Received: from ubuntu.dsn.sec.samsung.com (unknown [12.36.155.120]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20210913081151epsmtip17921edbefd78aeeede98be637d1dedc1~kU3F8Z8Qr0411604116epsmtip1x; Mon, 13 Sep 2021 08:11:51 +0000 (GMT) From: Kiwoong Kim To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, beanhuo@micron.com, cang@codeaurora.org, adrian.hunter@intel.com, sc.suh@samsung.com, hy50.seo@samsung.com, sh425.lee@samsung.com, bhoon95.kim@samsung.com Cc: Kiwoong Kim Subject: [PATCH v2 3/3] scsi: ufs: ufs-exynos: implement exynos isr Date: Mon, 13 Sep 2021 16:55:55 +0900 Message-Id: <746e059782953fca6c21945297151d2bb73d3370.1631519695.git.kwmad.kim@samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: In-Reply-To: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNJsWRmVeSWpSXmKPExsWy7bCmhe4JdvtEg3071S1OPlnDZvFg3jY2 i5c/r7JZHHzYyWLxdekzVotP65exWqxe/IDFYtGNbUwWN7ccZbG4vGsOm0X39R1sFsuP/2Oy 6Lp7g9Fi6b+3LA58Hpf7epk8Fu95yeQxYdEBRo/v6zvYPD4+vcXi0bdlFaPH501yHu0HupkC OKJybDJSE1NSixRS85LzUzLz0m2VvIPjneNNzQwMdQ0tLcyVFPISc1NtlVx8AnTdMnOADldS KEvMKQUKBSQWFyvp29kU5ZeWpCpk5BeX2CqlFqTkFBgaFugVJ+YWl+al6yXn51oZGhgYmQJV JuRkLDney1Qw36Ri3tLnrA2Mk7S6GDk5JARMJLYfeMXSxcjFISSwg1Hi6vRPTBDOJ0aJrwsf sUI4nxkl/n59zgbT8vnxO6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um5TUnMyy1CJ9uwSujCXHe5kK5ptUzFv6nLWBcZJWFyMnh4SAicTnx+9YQWwhgR2MElf/ S0HEJSVO7HzOCGELS9xvOQJUwwVU841R4tnHF8wgCTYBTYmnN6cygSREBM4xSUy9vJQJJMEs oC6xa8IJMFtYwFniflsXkM3BwSKgKjGtRxMkzCsQLbFp3hRWiAVyEjfPdYLN5BSwlLj/F6JV SMBCon/zJkZc4hMYBRYwMqxilEwtKM5Nzy02LDDKSy3XK07MLS7NS9dLzs/dxAiOBC2tHYx7 Vn3QO8TIxMF4iFGCg1lJhHfbG9tEId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rwXuk7GCwmkJ5ak ZqemFqQWwWSZODilGpiY1AtY9/nZ3Gr5WMaXcvj3N/383OBtt2ffvMZ/Jjiyj+MoF9eTA7dL 49qTLt+JjeYJ6FeY+VG3aMnKnjMeF+Jilx7q8178my/7z9dqNwmnhSe7vp6fwSzwpLt0e1cU 93we36SpymlK+4PZw7tOCLLZFtz13mn9IbpoYe20oNnNroE2+/56zpUJ4BRUN737V8Pdbsez irdlQcv8Pa7I7LWRtH0iK9V7cc6GX7cfpa2fL+Gs2jjBJOywy5wX2XcWip9covH6jbB3+4rp czi1orcxTKr6d1HwyMqSskZ5m/Q/uY8YpqSYLPA/dpdr+iLr3CtvXU5vtOPMTdNdGFg4v/nr bYuNi6TucrCzp0yozlRiKc5INNRiLipOBACl7xX+8wIAAA== X-CMS-MailID: 20210913081152epcas2p2eac4a8dbef33164a150dccf2e282dcce X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20210913081152epcas2p2eac4a8dbef33164a150dccf2e282dcce References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is to raise recovery in some abnormal conditions using an vendor specific interrupt for some cases, such as a situation that some contexts of a pending request in the host isn't the same with those of its corresponding UPIUs if they should have been the same exactly. The representative case is shown like below. In the case, a broken UTRD entry, for internal coherent problem or whatever, that had smaller value of PRDT length than expected was transferred to the host. So, the host raised an interrupt of transfer complete even if device didn't finish its data transfer because the host sees a fetched version of UTRD to determine if data tranfer is over or not. Then the application level seemed to recogize this as a sort of corruption and this symptom led to boot failure. [5: init: 1] init: Failed to copy /avb into /metadata/gsi/dsu/avb/: No such file or directory [5: init: 1] init: [libfs_mgr]Created logical partition system on device /dev/block/dm-0 [4: init: 1] init: [libfs_mgr]Created logical partition vendor on device /dev/block/dm-1 [4: init: 1] init: [libfs_avb]total vbmeta size mismatch: 13504 (expected: 15616) [4: init: 1] init: [libfs_avb]VerifyVbmetaImages failed [4: init: 1] init: Failed to open AvbHandle: No such file or directory If the issued command would be write, it could be a disaster because some parts of its entire data chunk may be not written or more than the chunk may be written. Using the VENDOR_SPECIFIC_IS.RX_UPIU_HIT_ERROR, the host can detect the abnormal condition right when an DATA IN for offset bigger than expected for the broken value (i.e. PRDT length in this case) is received, do something for recovery and system will keep going safe. Signed-off-by: Kiwoong Kim --- drivers/scsi/ufs/ufs-exynos.c | 84 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c index a14dd8c..b0c8843 100644 --- a/drivers/scsi/ufs/ufs-exynos.c +++ b/drivers/scsi/ufs/ufs-exynos.c @@ -21,6 +21,7 @@ #include "unipro.h" #include "ufs-exynos.h" +#include "../scsi_transport_api.h" /* * Exynos's Vendor specific registers for UFSHCI @@ -31,6 +32,8 @@ #define HCI_RXPRDT_ENTRY_SIZE 0x04 #define HCI_1US_TO_CNT_VAL 0x0C #define CNT_VAL_1US_MASK 0x3FF +#define VENDOR_SPECIFIC_IS 0x38 +#define VENDOR_SPECIFIC_IE 0x3C #define HCI_UTRL_NEXUS_TYPE 0x40 #define HCI_UTMRL_NEXUS_TYPE 0x44 #define HCI_SW_RST 0x50 @@ -74,6 +77,18 @@ UIC_TRANSPORT_NO_CONNECTION_RX |\ UIC_TRANSPORT_BAD_TC) +enum exynos_ufs_vs_interrupt { + /* + * This occurs when information of a pending request isn't + * the same with incoming UPIU for the request. For example, + * if UFS driver rings with task tag #1, subsequential UPIUs + * for this must have one as the value of task tag. But if + * it's corrutped until the host receives it or incoming UPIUs + * has an unexpected value for task tag, this raises. + */ + RX_UPIU_HIT_ERROR = 1 << 19, +}; + enum { UNIPRO_L1_5 = 0,/* PHY Adapter */ UNIPRO_L2, /* Data Link */ @@ -996,6 +1011,10 @@ static int exynos_ufs_init(struct ufs_hba *hba) goto out; exynos_ufs_specify_phy_time_attr(ufs); exynos_ufs_config_smu(ufs); + + /* enable vendor interrupts */ + hci_writel(ufs, VENDOR_SPECIFIC_IE, RX_UPIU_HIT_ERROR); + return 0; phy_off: @@ -1005,26 +1024,34 @@ static int exynos_ufs_init(struct ufs_hba *hba) return ret; } -static int exynos_ufs_host_reset(struct ufs_hba *hba) +static int exynos_ufs_host_reset(struct exynos_ufs *ufs) { - struct exynos_ufs *ufs = ufshcd_get_variant(hba); unsigned long timeout = jiffies + msecs_to_jiffies(1); - u32 val; - int ret = 0; - - exynos_ufs_disable_auto_ctrl_hcc_save(ufs, &val); + /* host reset */ hci_writel(ufs, UFS_SW_RST_MASK, HCI_SW_RST); - do { if (!(hci_readl(ufs, HCI_SW_RST) & UFS_SW_RST_MASK)) - goto out; + return 0; + cpu_relax(); } while (time_before(jiffies, timeout)); - dev_err(hba->dev, "timeout host sw-reset\n"); - ret = -ETIMEDOUT; + pr_err("timeout host sw-reset\n"); + return -ETIMEDOUT; +} + +static int exynos_ufs_host_init(struct ufs_hba *hba) +{ + struct exynos_ufs *ufs = ufshcd_get_variant(hba); + u32 val; + int ret; + + exynos_ufs_disable_auto_ctrl_hcc_save(ufs, &val); + + ret = exynos_ufs_host_reset(ufs); + if (ret) + return ret; -out: exynos_ufs_auto_ctrl_hcc_restore(ufs, &val); return ret; } @@ -1110,7 +1137,7 @@ static int exynos_ufs_hce_enable_notify(struct ufs_hba *hba, switch (status) { case PRE_CHANGE: - ret = exynos_ufs_host_reset(hba); + ret = exynos_ufs_host_init(hba); if (ret) return ret; exynos_ufs_dev_hw_reset(hba); @@ -1198,6 +1225,38 @@ static int exynos_ufs_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) return 0; } +static irqreturn_t exynos_ufs_isr(struct ufs_hba *hba) +{ + struct exynos_ufs *ufs = ufshcd_get_variant(hba); + u32 status; + unsigned long flags; + + if (!hba->priv) return IRQ_HANDLED; + status = hci_readl(ufs, VENDOR_SPECIFIC_IS); + hci_writel(ufs, status, VENDOR_SPECIFIC_IS); + /* + * If host doesn't guarantee integrity of UTP transmission, + * it needs to be reset immediately to make it unable to + * proceed requests. Because w/o this, if UTP functions + * in host doesn't work properly for such system power margins, + * DATA IN from broken devices or whatever in the real world, + * some unexpected events could happen, such as transferring + * a broken DATA IN to a device. It could be various types of + * problems on the level of file system. In this case, I think + * blocking the host's functionality is the best strategy. + * Perhaps, if its root cause is temporary, system could recover. + */ + if (status & RX_UPIU_HIT_ERROR) { + pr_err("%s: status: 0x%08x\n", __func__, status); + hba->force_reset = true; + hba->force_requeue = true; + scsi_schedule_eh(hba->host); + spin_unlock_irqrestore(hba->host->host_lock, flags); + return IRQ_HANDLED; + } + return IRQ_NONE; +} + static struct ufs_hba_variant_ops ufs_hba_exynos_ops = { .name = "exynos_ufs", .init = exynos_ufs_init, @@ -1209,6 +1268,7 @@ static struct ufs_hba_variant_ops ufs_hba_exynos_ops = { .hibern8_notify = exynos_ufs_hibern8_notify, .suspend = exynos_ufs_suspend, .resume = exynos_ufs_resume, + .intr = exynos_ufs_isr, }; static int exynos_ufs_probe(struct platform_device *pdev) -- 2.7.4