Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp285834pxb; Mon, 2 Nov 2020 22:28:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9+Dtco0U0mTNjS3YVspQRYnRMFlcGd/AvnRCsIH/t84jgFefxEax7dezY/rbgDt+vtJuc X-Received: by 2002:a50:d616:: with SMTP id x22mr19990842edi.221.1604384923706; Mon, 02 Nov 2020 22:28:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604384923; cv=none; d=google.com; s=arc-20160816; b=bshUF4fKfWqSfwCnQI6jGvgA4RG0EPPgUCJDI6l3vzvtH3X/9iAY+g+SuZf4iOACum 53cz9PjZsOFudio1FTLLJWB2KS8947ZLoeIEMhwR63NqRZRErkST2bWKLwGct7mPkAis JsqWTKqziT5802IGMRPWsizM4SlBdLrwctp/fjwQp5ED3LRq9Kya/c2ILJ+V1XRcBDYk 8SAqa/gG8UE+r/VIB+kHBqDrsBN5D9xGNIr8H9mNZFHDHyIuI83bYQq0qWghPF59P9AU jHwbF3HVGlzgtyEPla9mCT2ld417BT2AP/zxKFb0V8Jj9Zmz79syHId3U+hqRy79d385 DsBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr; bh=tnGYAJhsIrBNx34UCUTf38SVhu6PuvKRPnVj/7Zr9I8=; b=eNA8w94JklPAnV/tZhG11PAIYjbDGLLJmypTdYC6VNYx38Iok6Am+2xuT3kX0NDrz/ 9mFAaQsP1jkU7kxmy49sFQAWuMnjywiwVdWMqZrmb8B1jxoWwvhQhD/DBNVqyK1eXqpS ZqlpCPePBUf9J8CQ19Ry0BM5aGz6ETr3hsfhuFe1eQ01gHQfRiY1MO9A7LC0TQiCSxNg MyLWnZH9U66kKt/vrL1rndahcMTCJIAJo+AFJdXz3nJiOxsZ1GYpY1k9u8ezKTbPQZkv IbVxQUSGWUmeX/p/Xsecjwr2PuxffRNz2gvCp5cd4U+4h+AoTN+gScsvrnoZPqOYBf3V ouOg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si11761924edw.7.2020.11.02.22.28.20; Mon, 02 Nov 2020 22:28:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727641AbgKCGZR (ORCPT + 99 others); Tue, 3 Nov 2020 01:25:17 -0500 Received: from labrats.qualcomm.com ([199.106.110.90]:30196 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbgKCGZQ (ORCPT ); Tue, 3 Nov 2020 01:25:16 -0500 IronPort-SDR: JXv9Q1UC6ry6FSYnDYrn5ErYovILaWn2Flo2uexVjBxoNm++K9c664ft/tbDLylpVurzn9J0GV N2nREYpNgxbSo/1hPNDPgVmc6Z4NBbsu9OUyGdoW6H+tROIafPc318T9C3ImrE2Ybuz61Z5Jkk msUv4IChlk4ENwmPLyr3dbdAemDShzBknqOM1jRNbp5zb4ETwu3Bi3KyOeXu02Yi407AXtGu/5 6VwIOkOwSjTHNSNXwIxf+f63TSqCDJr92yT/FMGAHzoWo7VebzLodY+IL7vAcLIyEvvQhwutX1 iTI= X-IronPort-AV: E=Sophos;i="5.77,447,1596524400"; d="scan'208";a="29256947" Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by labrats.qualcomm.com with ESMTP; 02 Nov 2020 22:25:14 -0800 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg04-sd.qualcomm.com with ESMTP; 02 Nov 2020 22:25:03 -0800 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id 07731217C9; Mon, 2 Nov 2020 22:25:02 -0800 (PST) From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@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 , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] scsi: ufs: Try to save power mode change and UIC cmd completion timeout Date: Mon, 2 Nov 2020 22:24:41 -0800 Message-Id: <1604384682-15837-4-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1604384682-15837-1-git-send-email-cang@codeaurora.org> References: <1604384682-15837-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the uic_cmd->cmd_active as a flag to track the lifecycle of an UIC cmd. The flag is set before send the UIC cmd and cleared after the completion is raised in IRQ handler. For a power mode change operation, including hibern8 enter/exit, the flag is cleared only after hba->uic_async_done completion is raised. When completion timeout happens, if the flag is cleared, instead of returning timeout error, simply ignore it. Change-Id: Ie3cd6ae6221a44619925fb2cf78136a5617fdd5d Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 252e022..8b291c3 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2131,10 +2131,20 @@ ufshcd_wait_for_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) unsigned long flags; if (wait_for_completion_timeout(&uic_cmd->done, - msecs_to_jiffies(UIC_CMD_TIMEOUT))) + msecs_to_jiffies(UIC_CMD_TIMEOUT))) { ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; - else + } else { ret = -ETIMEDOUT; + dev_err(hba->dev, + "uic cmd 0x%x with arg3 0x%x completion timeout\n", + uic_cmd->command, uic_cmd->argument3); + + if (!uic_cmd->cmd_active) { + dev_err(hba->dev, "%s: UIC cmd has been completed, return the result\n", + __func__); + ret = uic_cmd->argument2 & MASK_UIC_COMMAND_RESULT; + } + } spin_lock_irqsave(hba->host->host_lock, flags); hba->active_uic_cmd = NULL; @@ -2166,6 +2176,7 @@ __ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd, if (completion) init_completion(&uic_cmd->done); + uic_cmd->cmd_active = 1; ufshcd_dispatch_uic_cmd(hba, uic_cmd); return 0; @@ -3944,10 +3955,18 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) dev_err(hba->dev, "pwr ctrl cmd 0x%x with mode 0x%x completion timeout\n", cmd->command, cmd->argument3); + + if (!cmd->cmd_active) { + dev_err(hba->dev, "%s: Power Mode Change operation has been completed, go check UPMCRS\n", + __func__); + goto check_upmcrs; + } + ret = -ETIMEDOUT; goto out; } +check_upmcrs: status = ufshcd_get_upmcrs(hba); if (status != PWR_LOCAL) { dev_err(hba->dev, @@ -5060,11 +5079,14 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status) hba->active_uic_cmd->argument3 = ufshcd_get_dme_attr_val(hba); complete(&hba->active_uic_cmd->done); + if (!hba->uic_async_done) + hba->active_uic_cmd->cmd_active = 0; retval = IRQ_HANDLED; } if ((intr_status & UFSHCD_UIC_PWR_MASK) && hba->uic_async_done) { complete(hba->uic_async_done); + hba->active_uic_cmd->cmd_active = 0; retval = IRQ_HANDLED; } return retval; -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.