From patchwork Tue May 23 06:19:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kiwoong Kim X-Patchwork-Id: 685857 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 4AA21C77B7A for ; Tue, 23 May 2023 06:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235213AbjEWG2R (ORCPT ); Tue, 23 May 2023 02:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235206AbjEWG2O (ORCPT ); Tue, 23 May 2023 02:28:14 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B89F118 for ; Mon, 22 May 2023 23:28:13 -0700 (PDT) Received: from epcas2p4.samsung.com (unknown [182.195.41.56]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230523062811epoutp020e87b049adcdb27ced55c2bc3b30eb3b~hsdtuwhLo0917409174epoutp02H for ; Tue, 23 May 2023 06:28:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230523062811epoutp020e87b049adcdb27ced55c2bc3b30eb3b~hsdtuwhLo0917409174epoutp02H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684823291; bh=VWsy4krq+w5xTRR2JQYWmpMclIIlq9xss0VH2V+/zjI=; h=From:To:Cc:Subject:Date:In-Reply-To:In-Reply-To:References:From; b=UWjkfyvHasdY0R8RonSvmy47L4m9/PAxpjPZrZ8Tju7RijiZBcaIfP3vfiRBSj+62 b+wDoKB4cMiCT+E4+lZ4+bE+hYPItQh6sLoQvhWQSI9CIglVJT9kakf91IbzlQbC1a VnbIuKF6Gu3/XtZQ/V0JgK1phn2HaAn3BQdqGNG0= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230523062810epcas2p3c5da9748b094856926d45c6a8aba8dd5~hsds1HjML0207802078epcas2p38; Tue, 23 May 2023 06:28:10 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.36.88]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4QQPWs5bHdz4x9Pr; Tue, 23 May 2023 06:28:09 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 4A.5B.44220.9FC5C646; Tue, 23 May 2023 15:28:09 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p1.samsung.com (KnoxPortal) with ESMTPA id 20230523062809epcas2p1a0d5134df7c0f3a40b605326c7ee1987~hsdrY6YSH0164101641epcas2p1N; Tue, 23 May 2023 06:28:09 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230523062809epsmtrp2b37f5ecf9288f722d896e576dd4c97b2~hsdrYGVjP1738517385epsmtrp2a; Tue, 23 May 2023 06:28:09 +0000 (GMT) X-AuditID: b6c32a48-9f1ff7000000acbc-22-646c5cf91e62 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 5A.21.27706.8FC5C646; Tue, 23 May 2023 15:28:09 +0900 (KST) Received: from ubuntu.dsn.sec.samsung.com (unknown [10.229.95.128]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230523062808epsmtip17a13ca00edfecf6715cbc30ce4893fa5~hsdrMnGIe1634916349epsmtip1H; Tue, 23 May 2023 06:28:08 +0000 (GMT) From: Kiwoong Kim To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, bvanassche@acm.org, jejb@linux.ibm.com, martin.petersen@oracle.com, beanhuo@micron.com, adrian.hunter@intel.com, sc.suh@samsung.com, hy50.seo@samsung.com, sh425.lee@samsung.com, kwangwon.min@samsung.com, junwoo80.lee@samsung.com Cc: Kiwoong Kim Subject: [PATCH v1 2/3] ufs: poll HCS.UCRDY before issuing a UIC command Date: Tue, 23 May 2023 15:19:09 +0900 Message-Id: <5cd0088bb9fbd75b75638684f22de9710cf5f2c2.1684822284.git.kwmad.kim@samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: In-Reply-To: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNJsWRmVeSWpSXmKPExsWy7bCmme7PmJwUg5OtahYnn6xhs3gwbxub xcufV9ksDj7sZLGY9uEns8XqxQ9YLBbd2MZksetvM5PF1hs7WSxubjnKYnF51xw2i+7rO9gs lh//x2TRdfcGo8XSf29ZHPg9Ll/x9li85yWTx4RFBxg9vq/vYPP4+PQWi0ffllWMHp83yXm0 H+hmCuCIyrbJSE1MSS1SSM1Lzk/JzEu3VfIOjneONzUzMNQ1tLQwV1LIS8xNtVVy8QnQdcvM ATpeSaEsMacUKBSQWFyspG9nU5RfWpKqkJFfXGKrlFqQklNgXqBXnJhbXJqXrpeXWmJlaGBg ZApUmJCdseh6H1vBO+6Ktj0TmRsY73N2MXJySAiYSPRduMDUxcjFISSwg1Hi9/RzbCAJIYFP jBKP/rJDJL4xSqye95MdpuPO68nMEIm9jBJtG/9DVf1glDi/6xQTSBWbgKbE05tTwWwRgRtM Ek/6RUFsZgF1iV0TToDFhQU8JFo7roLZLAKqEtMetbCA2LwC0RJb/7WyQmyTk7h5rpMZxOYU sJTY8KqZDZXNBVQzl0Piw492JogGF4klXY1sELawxKvjW6DOlpL4/G4vUJwDyM6W2LNQDCJc IbF42lsWCNtYYtazdkaQEmag+9fv0oeoV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mEJtTwFJi w6tmti5GDqBtFhKN3/hwCE9gFFjAyLCKUTK1oDg3PbfYsMAwL7Vcrzgxt7g0L10vOT93EyM4 IrQ0dzBuX/VB7xAjEwfjIUYJDmYlEd4T5dkpQrwpiZVVqUX58UWlOanFhxilOViUxHkvdJ2M FxJITyxJzU5NLUgtgskycXBKNTCtWKeh+38/97GjU+2n1GsmPuk54SK7WuQNu/7uFC7G59mb VWNmMbOduOJx2OJ1Y33DmZuZ0/rn3vru62Fsf0X/7TSVEL85x3SMDeJ5tPt6Tik9N2pYLd6g bbDv+qNa3tUXc0/5SEazTT3rOF86Wsvk4eGdEnvufHnz9uTU9XOm65vP83l2sTT55HRGW9Xy ZqWnP5tObNVztfS/3qsz9ZoZxzO/thVdafYBHMdOHdaMjd9d+qLZMNA/dt7CWMWvD/fZu999 +q7I/HQQi/EB89en00JiTb59KmQWtPlzpydHMbNpb9jL7oizNlIrnJU0J2ZWi/84UeWWWcPw 8UW7svLxA7kF0fmHLlp7TuGVea3EUpyRaKjFXFScCADttpf+9wIAAA== X-CMS-MailID: 20230523062809epcas2p1a0d5134df7c0f3a40b605326c7ee1987 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230523062809epcas2p1a0d5134df7c0f3a40b605326c7ee1987 References: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org v1 -> v2: replace usleep_range with udelay because it's a sleepable period. With auto hibern8 enabled, UIC could be working for a while to process a hibern8 operation and HCI reports UIC not ready for a short term through HCS.UCRDY. And UFS driver can't recognize the operation. UFSHCI spec specifies UCRDY like this: whether the host controller is ready to process UIC COMMAND The 'ready' could be seen as many different meanings. If the meaning includes not processing any request from HCI, processing a hibern8 operation can be 'not ready'. In this situation, the driver needs to wait until the operations is completed. Signed-off-by: Kiwoong Kim --- drivers/ufs/core/ufshcd.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index e096401..a772f92 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -2365,7 +2365,18 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba) */ static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba) { - return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY; + ktime_t timeout = ktime_add_ms(ktime_get(), UIC_CMD_TIMEOUT); + u32 val = 0; + + do { + val = ufshcd_readl(hba, REG_CONTROLLER_STATUS) & + UIC_COMMAND_READY; + if (val) + break; + udelay(500); + } while (ktime_before(ktime_get(), timeout)); + + return val ? true : false; } /** From patchwork Tue May 23 06:19:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kiwoong Kim X-Patchwork-Id: 685856 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 15DA9C77B7A for ; Tue, 23 May 2023 06:28:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235237AbjEWG2U (ORCPT ); Tue, 23 May 2023 02:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234983AbjEWG2Q (ORCPT ); Tue, 23 May 2023 02:28:16 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD183186 for ; Mon, 22 May 2023 23:28:13 -0700 (PDT) Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230523062812epoutp03a8f3b736a4267e375cb5f62d4a238e6e~hsduZRrzb0598905989epoutp03Z for ; Tue, 23 May 2023 06:28:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230523062812epoutp03a8f3b736a4267e375cb5f62d4a238e6e~hsduZRrzb0598905989epoutp03Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684823292; bh=w3jI9nVFjFtaZhjMo1fL28/6y8KVI4J1TL4/ZBRb5RQ=; h=From:To:Cc:Subject:Date:In-Reply-To:In-Reply-To:References:From; b=CqGTIZCKY3kphi1a1vP303d6nre5wwft4XUVfR374W4gHAcIq78sx9RcJC+6I2Tuw pmOCXoBMcuEUr9Pzt6FsvhVK7xAvSgA/ZGpN48gRsZsCnxXYJ/r2g+dJ7BbR/fzPpi tJOuCVAMxJH13d1IhUcJ8WytGHqgpRzxQtu06Y1g= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20230523062811epcas2p243a58112066a5ed5be6622d1b7834f0c~hsdtrWopL3076330763epcas2p2J; Tue, 23 May 2023 06:28:11 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.36.88]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4QQPWt61Vlz4x9Q1; Tue, 23 May 2023 06:28:10 +0000 (GMT) Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id 75.94.07392.AFC5C646; Tue, 23 May 2023 15:28:10 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPA id 20230523062810epcas2p454b203a703524d0ce10577091f63d37d~hsdsnamVU2700227002epcas2p4U; Tue, 23 May 2023 06:28:10 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230523062810epsmtrp2bceb0b6a3856d533250df767142c92bf~hsdsmcIAy1738517385epsmtrp2b; Tue, 23 May 2023 06:28:10 +0000 (GMT) X-AuditID: b6c32a47-eedff70000001ce0-8b-646c5cfaf516 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 30.4F.28392.AFC5C646; Tue, 23 May 2023 15:28:10 +0900 (KST) Received: from ubuntu.dsn.sec.samsung.com (unknown [10.229.95.128]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230523062810epsmtip1d681ab19704a771b00380ebb61bc8738~hsdsYK6cL1521615216epsmtip1p; Tue, 23 May 2023 06:28:10 +0000 (GMT) From: Kiwoong Kim To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, alim.akhtar@samsung.com, avri.altman@wdc.com, bvanassche@acm.org, jejb@linux.ibm.com, martin.petersen@oracle.com, beanhuo@micron.com, adrian.hunter@intel.com, sc.suh@samsung.com, hy50.seo@samsung.com, sh425.lee@samsung.com, kwangwon.min@samsung.com, junwoo80.lee@samsung.com Cc: Kiwoong Kim Subject: [PATCH v1 3/3] ufs: poll pmc until another pa request is completed Date: Tue, 23 May 2023 15:19:10 +0900 Message-Id: <65681553332dda2700c9c2d5760c1b74934dfc70.1684822284.git.kwmad.kim@samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: In-Reply-To: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDJsWRmVeSWpSXmKPExsWy7bCmqe6vmJwUg1Vz9C1OPlnDZvFg3jY2 i5c/r7JZHHzYyWIx7cNPZovVix+wWCy6sY3JYtffZiaLrTd2sljc3HKUxeLyrjlsFt3Xd7BZ LD/+j8mi6+4NRoul/96yOPB7XL7i7bF4z0smjwmLDjB6fF/fwebx8ektFo++LasYPT5vkvNo P9DNFMARlW2TkZqYklqkkJqXnJ+SmZduq+QdHO8cb2pmYKhraGlhrqSQl5ibaqvk4hOg65aZ A3S8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rMLMWRmVeSWpSXmKPExsWy7bCSnO6vmJwUg//vhCxOPlnDZvFg3jY2 i5c/r7JZHHzYyWIx7cNPZovVix+wWCy6sY3JYtffZiaLrTd2sljc3HKUxeLyrjlsFt3Xd7BZ LD/+j8mi6+4NRoul/96yOPB7XL7i7bF4z0smjwmLDjB6fF/fwebx8ektFo++LasYPT5vkvNo P9DNFMARxWWTkpqTWZZapG+XwJWx+PFv9oKHhhUr25azNDDe1Ohi5OSQEDCROHDmEROILSSw g1Hi9nMliLikxImdzxkhbGGJ+y1HWLsYuYBqvjFK7Jr2iwUkwSagKfH05lQmkISIwCsmibn/ T4F1MAuoS+yacAJsqrCAt8Tiv+vAGlgEVCXeXNjMCmLzCkRLTJ+wlglig5zEzXOdzCA2p4Cl xIZXzWxdjBxA2ywkGr/x4RCewCiwgJFhFaNkakFxbnpusWGBUV5quV5xYm5xaV66XnJ+7iZG cDxoae1g3LPqg94hRiYOxkOMEhzMSiK8J8qzU4R4UxIrq1KL8uOLSnNSiw8xSnOwKInzXug6 GS8kkJ5YkpqdmlqQWgSTZeLglGpgOmVsankldGJfpPvpleHvxIsuiZ3muiDt7lUvejp8+8Xk z1unOv6t4Dd83ndwylf3j9EfdPnuMr/cf+XRH8mrNf8639sWc8cF23wzn17F5pRx5MTy0M2l /rOPOD1qV2fbbLR/+QyT+ysuSWQfWVBtoeyxZ8OvBZW+iQfvfFVkmfJnTpvR4g9zb0c+sdom bnCF/2zNzSLFbaUPVafuS316nPlI0j3vK+J20/aWLBTdcCvDLt386tLCKZ8+T7C2Xxz1fk0w QzV/UdSpKVdfzjnTLqyzX/1fIGPCbIFVUmFrwtZ55GbNmLnalP3e2ylyLPzGlxXyHJ5933br Z5BAT8WvJa2v1iSUy7557rrqWOWbWeFKLMUZiYZazEXFiQAAEJVa9gIAAA== X-CMS-MailID: 20230523062810epcas2p454b203a703524d0ce10577091f63d37d X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230523062810epcas2p454b203a703524d0ce10577091f63d37d References: Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org v2 -> v3 1) check time in the loop with jiffies, instead of miliseconds. 2) change a variable's name and fix a typo and wrong alignment. v1 -> v2 1) remove clearing hba->active_uic_cmd at the end of __ufshcd_poll_uic_pwr 2) change commit message on the cited clause: 5.7.12.11 -> 5.7.12.1.1 3) add mdelay to avoid too many issueing 4) change the timeout for the polling to 100ms because I found it sometimes takes much longer than expected. Regarding 5.7.12.1.1 in Unipro v1.8, PA rejects sebsequent requests following the first request from upper layer or remote. In this situation, PA responds w/ BUSY in cases when they come from upper layer and does nothing for the requests. So HCI doesn't receive ind, a.k.a. indicator for its requests and an interrupt, IS.UPMS isn't generated. When LINERESET occurs, the error handler issues PMC which is recognized as a request for PA. If a host's PA gets or raises LINERESET, and a request for PMC, this could be a concurrent situation mentioned above. And I found that situation w/ my environment. [ 222.929539]I[0:DefaultDispatch:20410] exynos-ufs 13500000.ufs: ufshcd_update_uic_error: uecdl : 0x80000002 [ 222.999009]I[0: arch_disk_io_1:20413] exynos-ufs 13500000.ufs: ufshcd_update_uic_error: uecpa : 0x80000010 [ 222.999200] [6: kworker/u16:2: 132] exynos-ufs 13500000.ufs: ufs_pwr_mode_restore_needed : mode = 0x15, pwr_rx = 1, pwr_tx = 1 [ 223.002876]I[0: arch_disk_io_3:20422] exynos-ufs 13500000.ufs: ufshcd_update_uic_error: uecpa : 0x80000010 [ 223.501050] [4: kworker/u16:2: 132] exynos-ufs 13500000.ufs: pwr ctrl cmd 0x2 with mode 0x11 completion timeout [ 223.502305] [4: kworker/u16:2: 132] exynos-ufs 13500000.ufs: ufshcd_change_power_mode: power mode change failed -110 [ 223.502312] [4: kworker/u16:2: 132] exynos-ufs 13500000.ufs: ufshcd_err_handler: Failed to restore power mode, err = -110 [ 223.502392] [4: kworker/u16:2: 132] exynos-ufs 13500000.ufs: ufshcd_is_pwr_mode_restore_needed : mode = 0x11, pwr_rx = 1, pwr_tx = 1 This patch is to poll PMC's result w/o checking its ind until the result is not busy, i.e. 09h, to avoid the rejection. Signed-off-by: Kiwoong Kim --- drivers/ufs/core/ufshcd.c | 93 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index a772f92..3cf2fbe 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -98,6 +98,9 @@ /* Polling time to wait for fDeviceInit */ #define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */ +/* Polling time to wait until PA is ready */ +#define UIC_PA_RDY_TIMEOUT 100 /* millisecs */ + /* UFSHC 4.0 compliant HC support this mode, refer param_set_mcq_mode() */ static bool use_mcq_mode = true; @@ -4146,6 +4149,62 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, } EXPORT_SYMBOL_GPL(ufshcd_dme_get_attr); +static int __ufshcd_poll_uic_pwr(struct ufs_hba *hba, struct uic_command *cmd, + struct completion *cnf) +{ + unsigned long flags; + int ret; + u32 mode = cmd->argument3; + unsigned long deadline = jiffies + + msecs_to_jiffies(UIC_PA_RDY_TIMEOUT); + + do { + spin_lock_irqsave(hba->host->host_lock, flags); + hba->active_uic_cmd = NULL; + if (ufshcd_is_link_broken(hba)) { + spin_unlock_irqrestore(hba->host->host_lock, flags); + ret = -ENOLINK; + goto out; + } + hba->uic_async_done = cnf; + spin_unlock_irqrestore(hba->host->host_lock, flags); + + cmd->argument2 = 0; + cmd->argument3 = mode; + ret = __ufshcd_send_uic_cmd(hba, cmd, true); + if (ret) { + dev_err(hba->dev, + "pwr ctrl cmd 0x%x with mode 0x%x uic error %d\n", + cmd->command, cmd->argument3, ret); + goto out; + } + + /* This value is heuristic */ + if (!wait_for_completion_timeout(&cmd->done, + msecs_to_jiffies(5))) { + ret = -ETIMEDOUT; + dev_err(hba->dev, + "pwr ctrl cmd 0x%x with mode 0x%x timeout\n", + cmd->command, cmd->argument3); + if (cmd->cmd_active) + goto out; + + dev_info(hba->dev, "%s: pwr ctrl cmd has already been completed\n", __func__); + } + + /* retry only for busy cases */ + ret = cmd->argument2 & MASK_UIC_COMMAND_RESULT; + if (ret != UIC_CMD_RESULT_BUSY) + break; + + dev_info(hba->dev, "%s: PA is busy and can't handle a requeest, %d\n", __func__, ret); + mdelay(1); + + } while (time_before(jiffies, deadline)); +out: + return ret; +} + /** * ufshcd_uic_pwr_ctrl - executes UIC commands (which affects the link power * state) and waits for it to take effect. @@ -4168,33 +4227,13 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) unsigned long flags; u8 status; int ret; - bool reenable_intr = false; - mutex_lock(&hba->uic_cmd_mutex); - ufshcd_add_delay_before_dme_cmd(hba); - - spin_lock_irqsave(hba->host->host_lock, flags); - if (ufshcd_is_link_broken(hba)) { - ret = -ENOLINK; - goto out_unlock; - } - hba->uic_async_done = &uic_async_done; - if (ufshcd_readl(hba, REG_INTERRUPT_ENABLE) & UIC_COMMAND_COMPL) { - ufshcd_disable_intr(hba, UIC_COMMAND_COMPL); - /* - * Make sure UIC command completion interrupt is disabled before - * issuing UIC command. - */ - wmb(); - reenable_intr = true; - } - spin_unlock_irqrestore(hba->host->host_lock, flags); - ret = __ufshcd_send_uic_cmd(hba, cmd, false); + ret = __ufshcd_poll_uic_pwr(hba, cmd, &uic_async_done); if (ret) { - dev_err(hba->dev, - "pwr ctrl cmd 0x%x with mode 0x%x uic error %d\n", - cmd->command, cmd->argument3, ret); - goto out; + if (ret == -ENOLINK) + goto out_unlock; + else + goto out; } if (!wait_for_completion_timeout(hba->uic_async_done, @@ -4231,14 +4270,12 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) spin_lock_irqsave(hba->host->host_lock, flags); hba->active_uic_cmd = NULL; hba->uic_async_done = NULL; - if (reenable_intr) - ufshcd_enable_intr(hba, UIC_COMMAND_COMPL); if (ret) { ufshcd_set_link_broken(hba); ufshcd_schedule_eh_work(hba); } -out_unlock: spin_unlock_irqrestore(hba->host->host_lock, flags); +out_unlock: mutex_unlock(&hba->uic_cmd_mutex); return ret;