From patchwork Thu Jul 1 21:12:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C220C11F67 for ; Thu, 1 Jul 2021 21:12:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61F246128A for ; Thu, 1 Jul 2021 21:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234053AbhGAVPK (ORCPT ); Thu, 1 Jul 2021 17:15:10 -0400 Received: from mail-pg1-f182.google.com ([209.85.215.182]:36416 "EHLO mail-pg1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233922AbhGAVPK (ORCPT ); Thu, 1 Jul 2021 17:15:10 -0400 Received: by mail-pg1-f182.google.com with SMTP id e33so7394621pgm.3 for ; Thu, 01 Jul 2021 14:12:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s20zXO0dLIDFGzVBLRtuSwjiyxrUNmAGgZq5yA2U39M=; b=MccNjE8f+loY61qCDuOIz7IhfXl/fCczzb/XAZZq0Ifrf7TaaMo0OH7RvZpyNfXsxA yNmCkFr7RJeBjG9QCkhtYCDu5fhAXoZpR1cTDr7kXwMAUKQQjFhBJFJHnNHLELnY3ZIj pPaEbRsbjvL3Y8zfFPJYJkpnhxamk5ZQxoOj2hjLG44VvbyxcpEq3xo9UfmrD14rlIvN p++XNu0ZbfsxNT5HhxGJ/apQb19NIzMQfxSdUnO8my5iimXMbkg1TeH9rmf56/jSiBsA z29XrB38NksMYETFOWWVLQeaWfZpgD8EIKAQXbX1vJFtVzG7prAH3CL5un/mWuNga1gM GAYA== X-Gm-Message-State: AOAM531/uaMxRb/dniW5/XytNzSV9ycTFroQ14BHw/EMbFP9JnXIg3P3 oIMAeAsUSNlJKtXd6WMkZvw= X-Google-Smtp-Source: ABdhPJxKgRZUPe9yrFe+fJvoKpleYJw/mdVEzUKw+oCTTzB3WkhRN0gsJvIiIN8D3NiIKkQS53ol+w== X-Received: by 2002:a65:6658:: with SMTP id z24mr1493619pgv.266.1625173958262; Thu, 01 Jul 2021 14:12:38 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:12:37 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Ming Lei , John Garry , Yves-Alexis Perez , "James E.J. Bottomley" , Jason Yan , "Gustavo A. R. Silva" , Yufen Yu Subject: [PATCH 02/21] libsas: Only abort commands from inside the error handler Date: Thu, 1 Jul 2021 14:12:05 -0700 Message-Id: <20210701211224.17070-3-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org According to the information I found in patch commit descriptions, for SATA devices commands must be aborted from inside the libsas error handler. Check host->ehandler to determine whether or not running inside the error handler since host->host_eh_scheduled != 0 indicates that the SCSI error handler has been scheduled but does not mean that is already running. This patch restores code that was removed by commit 909657615d9b ("scsi: libsas: allow async aborts"). Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Ming Lei Cc: John Garry Cc: Yves-Alexis Perez Fixes: c9f926000fe3 ("scsi: libsas: Disable asynchronous aborts for SATA devices") Signed-off-by: Bart Van Assche --- drivers/scsi/libsas/sas_scsi_host.c | 5 ++++- include/scsi/libsas.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index ee44a0d7730b..95e4d58ab9d4 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -462,6 +462,7 @@ int sas_eh_abort_handler(struct scsi_cmnd *cmd) int res = TMF_RESP_FUNC_FAILED; struct sas_task *task = TO_SAS_TASK(cmd); struct Scsi_Host *host = cmd->device->host; + struct sas_ha_struct *ha = SHOST_TO_SAS_HA(host); struct domain_device *dev = cmd_to_domain_dev(cmd); struct sas_internal *i = to_sas_internal(host->transportt); unsigned long flags; @@ -471,7 +472,7 @@ int sas_eh_abort_handler(struct scsi_cmnd *cmd) spin_lock_irqsave(host->host_lock, flags); /* We cannot do async aborts for SATA devices */ - if (dev_is_sata(dev) && !host->host_eh_scheduled) { + if (dev_is_sata(dev) && !ha->eh_running) { spin_unlock_irqrestore(host->host_lock, flags); return FAILED; } @@ -731,6 +732,7 @@ void sas_scsi_recover_host(struct Scsi_Host *shost) tries++; retry = true; spin_lock_irq(shost->host_lock); + ha->eh_running = true; list_splice_init(&shost->eh_cmd_q, &eh_work_q); spin_unlock_irq(shost->host_lock); @@ -767,6 +769,7 @@ void sas_scsi_recover_host(struct Scsi_Host *shost) /* check if any new eh work was scheduled during the last run */ spin_lock_irq(&ha->lock); + ha->eh_running = false; if (ha->eh_active == 0) { shost->host_eh_scheduled = 0; retry = false; diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 6fe125a71b60..4a8fb324140e 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -364,6 +364,7 @@ struct sas_ha_struct { struct mutex drain_mutex; unsigned long state; spinlock_t lock; + bool eh_running; int eh_active; wait_queue_head_t eh_wait_q; struct list_head eh_dev_q; From patchwork Thu Jul 1 21:12:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B810C11F69 for ; Thu, 1 Jul 2021 21:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2400361410 for ; Thu, 1 Jul 2021 21:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234083AbhGAVPP (ORCPT ); Thu, 1 Jul 2021 17:15:15 -0400 Received: from mail-pg1-f181.google.com ([209.85.215.181]:47004 "EHLO mail-pg1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233916AbhGAVPP (ORCPT ); Thu, 1 Jul 2021 17:15:15 -0400 Received: by mail-pg1-f181.google.com with SMTP id w15so7342741pgk.13 for ; Thu, 01 Jul 2021 14:12:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oqPM4lNZ6z54UNmi+AdbSSWncdPGPDnM588q5GCDzpw=; b=e9f5VxKYjUlyB64D7wgFW0+8ajAUb7y7/pNhARRlvmHyj6NA9pbH89pIgKrFkZk3Du nirrru+lXIAU/9ck9xG6nvLlnp2ahdHIkjNEjZ7uSdbFzeiTftHWS7vnaB/siAdB/qyQ SCJ01xYy/gAhvsez1ELxP3NZTJ5DiJvfJ3eg7NxBMRWV0RFMGQZB36Er2gag/6rfFbmu aluAqmscrIZHvft9VrzaGC6RAm9LEsAiDNo33Q4qEg2wEocIahOdPZmH7+fvbTW3kTUZ hYhBIIPK7/ClPETRb7T3opxoe+loOj3vO5yNZndMWaJfPPzLZNUc5ZB7oX5zV0tbDv0h oLpA== X-Gm-Message-State: AOAM532OX/C3DhpcRlwQcy+3y0lhG8+ZL5mOGoiIuqPO+VtOo4dLSSxb A2bsv3Z6DLN2y2mnw4OVyIY= X-Google-Smtp-Source: ABdhPJy0Uu+gI/2keVNCazT7x3fsRkxlVo45fFYO8z+mciR2DneOQtxbszm5Gn2w7+ftqs2l2AKgXg== X-Received: by 2002:a63:a45:: with SMTP id z5mr1445917pgk.227.1625173963477; Thu, 01 Jul 2021 14:12:43 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:12:42 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Hannes Reinecke , Ming Lei , John Garry , "James E.J. Bottomley" , Yufen Yu , "Gustavo A. R. Silva" Subject: [PATCH 04/21] libsas: Stop clearing host_eh_scheduled from the error handler Date: Thu, 1 Jul 2021 14:12:07 -0700 Message-Id: <20210701211224.17070-5-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Now that the caller of sas_scsi_recover_host(), namely scsi_error_handler(), clears host_eh_scheduled, remove the assignment from sas_scsi_recover_host() that clears this member variable. Cc: Hannes Reinecke Cc: Ming Lei Cc: John Garry Signed-off-by: Bart Van Assche --- drivers/scsi/libsas/sas_scsi_host.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 95e4d58ab9d4..ae6c273e743e 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -770,10 +770,8 @@ void sas_scsi_recover_host(struct Scsi_Host *shost) /* check if any new eh work was scheduled during the last run */ spin_lock_irq(&ha->lock); ha->eh_running = false; - if (ha->eh_active == 0) { - shost->host_eh_scheduled = 0; + if (ha->eh_active == 0) retry = false; - } spin_unlock_irq(&ha->lock); if (retry) From patchwork Thu Jul 1 21:12:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77869C11F67 for ; Thu, 1 Jul 2021 21:12:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59AE361405 for ; Thu, 1 Jul 2021 21:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233663AbhGAVP2 (ORCPT ); Thu, 1 Jul 2021 17:15:28 -0400 Received: from mail-pl1-f175.google.com ([209.85.214.175]:41719 "EHLO mail-pl1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbhGAVP2 (ORCPT ); Thu, 1 Jul 2021 17:15:28 -0400 Received: by mail-pl1-f175.google.com with SMTP id z4so4412012plg.8 for ; Thu, 01 Jul 2021 14:12:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nHyFy4iEYNI06JKzg9bSk9GilHncFw7tlMl0BSofy4A=; b=s2R+QJdLv7SzycEN5TTuzoFww6AyjKlOdM6VaRSSCAX/902LZ8r3mC1zlHi+nM0Qpw Zsh9IWPylXBg3Rlr1LfA9ivy0neboN5Tjnp3mMiVzroYBEzGRWTsd3GN6ADNihCgJ5LL t5/xYyFtbXF/Ue+vOJOsdYgMCTIpeEfJK90+h5Xq6lqYP+spOMnYvb/yuCmoJCeYQWtC e63aLqJE/psZNS7o9tcMA69v+AKhKFj/eW3/eYBAej2hcqv2QdgmOf1XGrTFTX1N9EL5 vd1TUmXmhwuMHZpzredzney1BWjgnVRirVIF33cOtlQ2ZKGBaE5dQGIVPXFTX73JGaAI sroA== X-Gm-Message-State: AOAM530J65o4YJDdsBTMsAALiz9RYk2uzdv/bUGX2mRPfNKAKAkc+9nF LAqeEiyDGg3Ke0X2DKmP40U= X-Google-Smtp-Source: ABdhPJzDkI/Po/UaYX4xRw8T4yIdrBassLIxPuhAED/krnfVfwpo+V5amf+kMqVnKryNJtaY8WAVXg== X-Received: by 2002:a17:902:8c83:b029:129:17e5:a1cc with SMTP id t3-20020a1709028c83b029012917e5a1ccmr1546360plo.49.1625173977050; Thu, 01 Jul 2021 14:12:57 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:12:56 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Adrian Hunter , Stanley Chu , Can Guo , Asutosh Das , Avri Altman , "James E.J. Bottomley" , Pedro Sousa , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Matthias Brugger , Lee Jones , Kiwoong Kim , Alim Akhtar , Bean Huo , Yue Hu , Sergey Shtylyov Subject: [PATCH 06/21] ufs: Reduce power management code duplication Date: Thu, 1 Jul 2021 14:12:09 -0700 Message-Id: <20210701211224.17070-7-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Move the dev_get_drvdata() calls into the ufshcd_{system,runtime}_*() functions. Remove ufshcd_runtime_idle() since it is empty. This patch does not change any functionality. Cc: Adrian Hunter Cc: Stanley Chu Cc: Can Guo Cc: Asutosh Das Cc: Avri Altman Signed-off-by: Bart Van Assche Reviewed-by: Avri Altman --- drivers/scsi/ufs/cdns-pltfrm.c | 7 ++-- drivers/scsi/ufs/tc-dwc-g210-pci.c | 32 ++---------------- drivers/scsi/ufs/tc-dwc-g210-pltfrm.c | 7 ++-- drivers/scsi/ufs/ufs-exynos.c | 7 ++-- drivers/scsi/ufs/ufs-hisi.c | 7 ++-- drivers/scsi/ufs/ufs-mediatek.c | 7 ++-- drivers/scsi/ufs/ufs-qcom.c | 7 ++-- drivers/scsi/ufs/ufshcd-pci.c | 48 ++------------------------- drivers/scsi/ufs/ufshcd-pltfrm.c | 47 -------------------------- drivers/scsi/ufs/ufshcd-pltfrm.h | 18 ---------- drivers/scsi/ufs/ufshcd.c | 41 ++++++++++++----------- drivers/scsi/ufs/ufshcd.h | 9 +++-- 12 files changed, 41 insertions(+), 196 deletions(-) diff --git a/drivers/scsi/ufs/cdns-pltfrm.c b/drivers/scsi/ufs/cdns-pltfrm.c index 908ff39c4856..7da8be2f35c4 100644 --- a/drivers/scsi/ufs/cdns-pltfrm.c +++ b/drivers/scsi/ufs/cdns-pltfrm.c @@ -318,11 +318,8 @@ static int cdns_ufs_pltfrm_remove(struct platform_device *pdev) } static const struct dev_pm_ops cdns_ufs_dev_pm_ops = { - .suspend = ufshcd_pltfrm_suspend, - .resume = ufshcd_pltfrm_resume, - .runtime_suspend = ufshcd_pltfrm_runtime_suspend, - .runtime_resume = ufshcd_pltfrm_runtime_resume, - .runtime_idle = ufshcd_pltfrm_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, }; diff --git a/drivers/scsi/ufs/tc-dwc-g210-pci.c b/drivers/scsi/ufs/tc-dwc-g210-pci.c index ec4589afbc13..679289e1a78e 100644 --- a/drivers/scsi/ufs/tc-dwc-g210-pci.c +++ b/drivers/scsi/ufs/tc-dwc-g210-pci.c @@ -23,31 +23,6 @@ static int tc_type = TC_G210_INV; module_param(tc_type, int, 0); MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)"); -static int tc_dwc_g210_pci_suspend(struct device *dev) -{ - return ufshcd_system_suspend(dev_get_drvdata(dev)); -} - -static int tc_dwc_g210_pci_resume(struct device *dev) -{ - return ufshcd_system_resume(dev_get_drvdata(dev)); -} - -static int tc_dwc_g210_pci_runtime_suspend(struct device *dev) -{ - return ufshcd_runtime_suspend(dev_get_drvdata(dev)); -} - -static int tc_dwc_g210_pci_runtime_resume(struct device *dev) -{ - return ufshcd_runtime_resume(dev_get_drvdata(dev)); -} - -static int tc_dwc_g210_pci_runtime_idle(struct device *dev) -{ - return ufshcd_runtime_idle(dev_get_drvdata(dev)); -} - /* * struct ufs_hba_dwc_vops - UFS DWC specific variant operations */ @@ -143,11 +118,8 @@ tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) } static const struct dev_pm_ops tc_dwc_g210_pci_pm_ops = { - .suspend = tc_dwc_g210_pci_suspend, - .resume = tc_dwc_g210_pci_resume, - .runtime_suspend = tc_dwc_g210_pci_runtime_suspend, - .runtime_resume = tc_dwc_g210_pci_runtime_resume, - .runtime_idle = tc_dwc_g210_pci_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, }; diff --git a/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c b/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c index a1268e4f44d6..783ec43efa78 100644 --- a/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c +++ b/drivers/scsi/ufs/tc-dwc-g210-pltfrm.c @@ -84,11 +84,8 @@ static int tc_dwc_g210_pltfm_remove(struct platform_device *pdev) } static const struct dev_pm_ops tc_dwc_g210_pltfm_pm_ops = { - .suspend = ufshcd_pltfrm_suspend, - .resume = ufshcd_pltfrm_resume, - .runtime_suspend = ufshcd_pltfrm_runtime_suspend, - .runtime_resume = ufshcd_pltfrm_runtime_resume, - .runtime_idle = ufshcd_pltfrm_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) }; static struct platform_driver tc_dwc_g210_pltfm_driver = { diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c index cf46d6f86e0e..5aa096e5b6cc 100644 --- a/drivers/scsi/ufs/ufs-exynos.c +++ b/drivers/scsi/ufs/ufs-exynos.c @@ -1287,11 +1287,8 @@ static const struct of_device_id exynos_ufs_of_match[] = { }; static const struct dev_pm_ops exynos_ufs_pm_ops = { - .suspend = ufshcd_pltfrm_suspend, - .resume = ufshcd_pltfrm_resume, - .runtime_suspend = ufshcd_pltfrm_runtime_suspend, - .runtime_resume = ufshcd_pltfrm_runtime_resume, - .runtime_idle = ufshcd_pltfrm_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, }; diff --git a/drivers/scsi/ufs/ufs-hisi.c b/drivers/scsi/ufs/ufs-hisi.c index 526b911655fe..3b4117ddb3c8 100644 --- a/drivers/scsi/ufs/ufs-hisi.c +++ b/drivers/scsi/ufs/ufs-hisi.c @@ -569,11 +569,8 @@ static int ufs_hisi_remove(struct platform_device *pdev) } static const struct dev_pm_ops ufs_hisi_pm_ops = { - .suspend = ufshcd_pltfrm_suspend, - .resume = ufshcd_pltfrm_resume, - .runtime_suspend = ufshcd_pltfrm_runtime_suspend, - .runtime_resume = ufshcd_pltfrm_runtime_resume, - .runtime_idle = ufshcd_pltfrm_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, }; diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c index 32ae67e40086..fe6e678faa2c 100644 --- a/drivers/scsi/ufs/ufs-mediatek.c +++ b/drivers/scsi/ufs/ufs-mediatek.c @@ -1123,11 +1123,8 @@ static int ufs_mtk_remove(struct platform_device *pdev) } static const struct dev_pm_ops ufs_mtk_pm_ops = { - .suspend = ufshcd_pltfrm_suspend, - .resume = ufshcd_pltfrm_resume, - .runtime_suspend = ufshcd_pltfrm_runtime_suspend, - .runtime_resume = ufshcd_pltfrm_runtime_resume, - .runtime_idle = ufshcd_pltfrm_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, }; diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c index 9b1d18d7c9bb..9d9770f1db4f 100644 --- a/drivers/scsi/ufs/ufs-qcom.c +++ b/drivers/scsi/ufs/ufs-qcom.c @@ -1546,11 +1546,8 @@ MODULE_DEVICE_TABLE(acpi, ufs_qcom_acpi_match); #endif static const struct dev_pm_ops ufs_qcom_pm_ops = { - .suspend = ufshcd_pltfrm_suspend, - .resume = ufshcd_pltfrm_resume, - .runtime_suspend = ufshcd_pltfrm_runtime_suspend, - .runtime_resume = ufshcd_pltfrm_runtime_resume, - .runtime_idle = ufshcd_pltfrm_runtime_idle, + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, }; diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c index e6c334bfb4c2..b3bcc5c882da 100644 --- a/drivers/scsi/ufs/ufshcd-pci.c +++ b/drivers/scsi/ufs/ufshcd-pci.c @@ -385,48 +385,6 @@ static struct ufs_hba_variant_ops ufs_intel_lkf_hba_vops = { .device_reset = ufs_intel_device_reset, }; -#ifdef CONFIG_PM_SLEEP -/** - * ufshcd_pci_suspend - suspend power management function - * @dev: pointer to PCI device handle - * - * Returns 0 if successful - * Returns non-zero otherwise - */ -static int ufshcd_pci_suspend(struct device *dev) -{ - return ufshcd_system_suspend(dev_get_drvdata(dev)); -} - -/** - * ufshcd_pci_resume - resume power management function - * @dev: pointer to PCI device handle - * - * Returns 0 if successful - * Returns non-zero otherwise - */ -static int ufshcd_pci_resume(struct device *dev) -{ - return ufshcd_system_resume(dev_get_drvdata(dev)); -} - -#endif /* !CONFIG_PM_SLEEP */ - -#ifdef CONFIG_PM -static int ufshcd_pci_runtime_suspend(struct device *dev) -{ - return ufshcd_runtime_suspend(dev_get_drvdata(dev)); -} -static int ufshcd_pci_runtime_resume(struct device *dev) -{ - return ufshcd_runtime_resume(dev_get_drvdata(dev)); -} -static int ufshcd_pci_runtime_idle(struct device *dev) -{ - return ufshcd_runtime_idle(dev_get_drvdata(dev)); -} -#endif /* !CONFIG_PM */ - /** * ufshcd_pci_shutdown - main function to put the controller in reset state * @pdev: pointer to PCI device handle @@ -510,10 +468,8 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) } static const struct dev_pm_ops ufshcd_pci_pm_ops = { - SET_RUNTIME_PM_OPS(ufshcd_pci_runtime_suspend, - ufshcd_pci_runtime_resume, - ufshcd_pci_runtime_idle) - SET_SYSTEM_SLEEP_PM_OPS(ufshcd_pci_suspend, ufshcd_pci_resume) + SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume) + SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL) #ifdef CONFIG_PM_SLEEP .prepare = ufshcd_suspend_prepare, .complete = ufshcd_resume_complete, diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c index 298e22ef907e..8859c13f4e09 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -170,53 +170,6 @@ static int ufshcd_parse_regulator_info(struct ufs_hba *hba) return err; } -#ifdef CONFIG_PM -/** - * ufshcd_pltfrm_suspend - suspend power management function - * @dev: pointer to device handle - * - * Returns 0 if successful - * Returns non-zero otherwise - */ -int ufshcd_pltfrm_suspend(struct device *dev) -{ - return ufshcd_system_suspend(dev_get_drvdata(dev)); -} -EXPORT_SYMBOL_GPL(ufshcd_pltfrm_suspend); - -/** - * ufshcd_pltfrm_resume - resume power management function - * @dev: pointer to device handle - * - * Returns 0 if successful - * Returns non-zero otherwise - */ -int ufshcd_pltfrm_resume(struct device *dev) -{ - return ufshcd_system_resume(dev_get_drvdata(dev)); -} -EXPORT_SYMBOL_GPL(ufshcd_pltfrm_resume); - -int ufshcd_pltfrm_runtime_suspend(struct device *dev) -{ - return ufshcd_runtime_suspend(dev_get_drvdata(dev)); -} -EXPORT_SYMBOL_GPL(ufshcd_pltfrm_runtime_suspend); - -int ufshcd_pltfrm_runtime_resume(struct device *dev) -{ - return ufshcd_runtime_resume(dev_get_drvdata(dev)); -} -EXPORT_SYMBOL_GPL(ufshcd_pltfrm_runtime_resume); - -int ufshcd_pltfrm_runtime_idle(struct device *dev) -{ - return ufshcd_runtime_idle(dev_get_drvdata(dev)); -} -EXPORT_SYMBOL_GPL(ufshcd_pltfrm_runtime_idle); - -#endif /* CONFIG_PM */ - void ufshcd_pltfrm_shutdown(struct platform_device *pdev) { ufshcd_shutdown((struct ufs_hba *)platform_get_drvdata(pdev)); diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.h b/drivers/scsi/ufs/ufshcd-pltfrm.h index 772a8e848098..c33e28ac6ef6 100644 --- a/drivers/scsi/ufs/ufshcd-pltfrm.h +++ b/drivers/scsi/ufs/ufshcd-pltfrm.h @@ -33,22 +33,4 @@ int ufshcd_pltfrm_init(struct platform_device *pdev, const struct ufs_hba_variant_ops *vops); void ufshcd_pltfrm_shutdown(struct platform_device *pdev); -#ifdef CONFIG_PM - -int ufshcd_pltfrm_suspend(struct device *dev); -int ufshcd_pltfrm_resume(struct device *dev); -int ufshcd_pltfrm_runtime_suspend(struct device *dev); -int ufshcd_pltfrm_runtime_resume(struct device *dev); -int ufshcd_pltfrm_runtime_idle(struct device *dev); - -#else /* !CONFIG_PM */ - -#define ufshcd_pltfrm_suspend NULL -#define ufshcd_pltfrm_resume NULL -#define ufshcd_pltfrm_runtime_suspend NULL -#define ufshcd_pltfrm_runtime_resume NULL -#define ufshcd_pltfrm_runtime_idle NULL - -#endif /* CONFIG_PM */ - #endif /* UFSHCD_PLTFRM_H_ */ diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 5b31de83a63a..a34aa6d486c7 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -9204,15 +9204,17 @@ static int ufshcd_resume(struct ufs_hba *hba) } /** - * ufshcd_system_suspend - system suspend routine - * @hba: per adapter instance + * ufshcd_system_suspend - system suspend callback + * @dev: Device associated with the UFS controller. * - * Check the description of ufshcd_suspend() function for more details. + * Executed before putting the system into a sleep state in which the contents + * of main memory are preserved. * * Returns 0 for success and non-zero for failure */ -int ufshcd_system_suspend(struct ufs_hba *hba) +int ufshcd_system_suspend(struct device *dev) { + struct ufs_hba *hba = dev_get_drvdata(dev); int ret = 0; ktime_t start = ktime_get(); @@ -9229,16 +9231,19 @@ int ufshcd_system_suspend(struct ufs_hba *hba) EXPORT_SYMBOL(ufshcd_system_suspend); /** - * ufshcd_system_resume - system resume routine - * @hba: per adapter instance + * ufshcd_system_resume - system resume callback + * @dev: Device associated with the UFS controller. + * + * Executed after waking the system up from a sleep state in which the contents + * of main memory were preserved. * * Returns 0 for success and non-zero for failure */ - -int ufshcd_system_resume(struct ufs_hba *hba) +int ufshcd_system_resume(struct device *dev) { - int ret = 0; + struct ufs_hba *hba = dev_get_drvdata(dev); ktime_t start = ktime_get(); + int ret = 0; if (pm_runtime_suspended(hba->dev)) goto out; @@ -9255,15 +9260,16 @@ int ufshcd_system_resume(struct ufs_hba *hba) EXPORT_SYMBOL(ufshcd_system_resume); /** - * ufshcd_runtime_suspend - runtime suspend routine - * @hba: per adapter instance + * ufshcd_runtime_suspend - runtime suspend callback + * @dev: Device associated with the UFS controller. * * Check the description of ufshcd_suspend() function for more details. * * Returns 0 for success and non-zero for failure */ -int ufshcd_runtime_suspend(struct ufs_hba *hba) +int ufshcd_runtime_suspend(struct device *dev) { + struct ufs_hba *hba = dev_get_drvdata(dev); int ret; ktime_t start = ktime_get(); @@ -9278,7 +9284,7 @@ EXPORT_SYMBOL(ufshcd_runtime_suspend); /** * ufshcd_runtime_resume - runtime resume routine - * @hba: per adapter instance + * @dev: Device associated with the UFS controller. * * This function basically brings controller * to active state. Following operations are done in this function: @@ -9286,8 +9292,9 @@ EXPORT_SYMBOL(ufshcd_runtime_suspend); * 1. Turn on all the controller related clocks * 2. Turn ON VCC rail */ -int ufshcd_runtime_resume(struct ufs_hba *hba) +int ufshcd_runtime_resume(struct device *dev) { + struct ufs_hba *hba = dev_get_drvdata(dev); int ret; ktime_t start = ktime_get(); @@ -9300,12 +9307,6 @@ int ufshcd_runtime_resume(struct ufs_hba *hba) } EXPORT_SYMBOL(ufshcd_runtime_resume); -int ufshcd_runtime_idle(struct ufs_hba *hba) -{ - return 0; -} -EXPORT_SYMBOL(ufshcd_runtime_idle); - /** * ufshcd_shutdown - shutdown routine * @hba: per adapter instance diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index c98d540ac044..dc75426c609f 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -1009,11 +1009,10 @@ static inline u8 ufshcd_wb_get_query_index(struct ufs_hba *hba) return 0; } -extern int ufshcd_runtime_suspend(struct ufs_hba *hba); -extern int ufshcd_runtime_resume(struct ufs_hba *hba); -extern int ufshcd_runtime_idle(struct ufs_hba *hba); -extern int ufshcd_system_suspend(struct ufs_hba *hba); -extern int ufshcd_system_resume(struct ufs_hba *hba); +extern int ufshcd_runtime_suspend(struct device *dev); +extern int ufshcd_runtime_resume(struct device *dev); +extern int ufshcd_system_suspend(struct device *dev); +extern int ufshcd_system_resume(struct device *dev); extern int ufshcd_shutdown(struct ufs_hba *hba); extern int ufshcd_dme_configure_adapt(struct ufs_hba *hba, int agreed_gear, From patchwork Thu Jul 1 21:12:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 299F1C11F67 for ; Thu, 1 Jul 2021 21:13:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 146EA6128A for ; Thu, 1 Jul 2021 21:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234163AbhGAVPi (ORCPT ); Thu, 1 Jul 2021 17:15:38 -0400 Received: from mail-pl1-f180.google.com ([209.85.214.180]:44023 "EHLO mail-pl1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234178AbhGAVPh (ORCPT ); Thu, 1 Jul 2021 17:15:37 -0400 Received: by mail-pl1-f180.google.com with SMTP id i13so4372738plb.10 for ; Thu, 01 Jul 2021 14:13:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MMdVnriU+0MznJ/BnQqiwR0VpVYruaB3sRdsHxBFvEc=; b=UxQpNPxbrLqI2CkSk+NZWUpBRo9/fXm5i7oKZg7lK5VQwRPQtM83sJ40J6zmLkYz+W kGj4dCQBrJ5TLHKS0mCwMAIs26ksbhtn1LlEUgzgZ23bwq9qFsma7SIYUdy0QEo/pyhH eLphvWDj75rbDX2YyDf7Vvrlhd/Xq4RbO9X87DfKxIXygYYFZMXX0NwBUmKVsjEb6eLw E7PfnF5N2OOTl+O+xyc1c/gJ6tzn6dZvdaaKiCV5tCjYHbdjljXCnqh3o/VMOhYL3Yvt glD+2USd4O+tDQVHXbAdWV2tDXZH9U3xGtBJy/cy0U3Up7KL3GwGf5Grmh521QPtws8u MYJg== X-Gm-Message-State: AOAM533sBBXl8o6O08Owm+ecYBoXaYwhr4ntcddbs5EQE5OC0SHuqkBY fn7VIS39ZlXlOByfpCOxN70= X-Google-Smtp-Source: ABdhPJwMCznoVHxu3yu56oxQyadp6o3C5smyx5a+V1HZm0PA3lwv7RtvNeXp49vo+SULK6jSYuTLjg== X-Received: by 2002:a17:902:8308:b029:129:220a:c455 with SMTP id bd8-20020a1709028308b0290129220ac455mr1533640plb.74.1625173985815; Thu, 01 Jul 2021 14:13:05 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:04 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Avri Altman , Bean Huo , Asutosh Das , Can Guo , "James E.J. Bottomley" , Stanley Chu Subject: [PATCH 08/21] ufs: Rename the second ufshcd_probe_hba() argument Date: Thu, 1 Jul 2021 14:12:11 -0700 Message-Id: <20210701211224.17070-9-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Rename the second argument of ufshcd_probe_hba() such that the name of that argument reflects its purpose instead of how the function is called. See also commit 1b9e21412f72 ("scsi: ufs: Split ufshcd_probe_hba() based on its called flow"). Reviewed-by: Avri Altman Reviewed-by: Bean Huo Cc: Asutosh Das Cc: Can Guo Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 37302a8b3937..86ca9e1ce5aa 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7964,13 +7964,13 @@ static int ufshcd_clear_ua_wluns(struct ufs_hba *hba) } /** - * ufshcd_probe_hba - probe hba to detect device and initialize + * ufshcd_probe_hba - probe hba to detect device and initialize it * @hba: per-adapter instance - * @async: asynchronous execution or not + * @init_dev_params: whether or not to call ufshcd_device_params_init(). * * Execute link-startup and verify device initialization */ -static int ufshcd_probe_hba(struct ufs_hba *hba, bool async) +static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) { int ret; unsigned long flags; @@ -8002,7 +8002,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool async) * Initialize UFS device parameters used by driver, these * parameters are associated with UFS descriptors. */ - if (async) { + if (init_dev_params) { ret = ufshcd_device_params_init(hba); if (ret) goto out; From patchwork Thu Jul 1 21:12:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52B30C11F67 for ; Thu, 1 Jul 2021 21:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CC0561406 for ; Thu, 1 Jul 2021 21:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234192AbhGAVPq (ORCPT ); Thu, 1 Jul 2021 17:15:46 -0400 Received: from mail-pf1-f175.google.com ([209.85.210.175]:34329 "EHLO mail-pf1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234195AbhGAVPp (ORCPT ); Thu, 1 Jul 2021 17:15:45 -0400 Received: by mail-pf1-f175.google.com with SMTP id i6so7120407pfq.1 for ; Thu, 01 Jul 2021 14:13:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0drnNsVJoLJiccixGTNQuPcT/+TAKcMCOuCLxgLYqWs=; b=Sokklv6dUI12Iym9PP8hV1x9NzqQX3kDpDTwSxQ0GnHwB/xnYUfRU7phvoyldf0HoM MEy9b3pBF6kQizTMQ5QHOmdKBXBBTD0FFhdbwi3XqGev7nmN9dOUs0nKTONyrsAmOMsB Ru8LE3wsFd8Z1VTngdwY5q/CKFBcs2UbMxX/gYLvd4xPqN1A7kgipXFnA3GCiYMroROc r3fTaZu002498STsGiXcDb3QAzaaqK2LGnBk6j3fjYm4aHcCexa4Wp/qsYfVeB5J5bCD st+SzOVhCuQLP2Kg1jpp4TNZMuLWUpuPTA5n0pxjnOtpLfMZk2S+0VSN72TC6/jf/H9y LX8w== X-Gm-Message-State: AOAM530VhpLvACflxqqynCq7rDUDxcZ3tDind3BCrMKTb/6YRRjHhSXX pUP0gX1LlISiSPhQ/4lDRiU= X-Google-Smtp-Source: ABdhPJzvrq1gTQ/D+xtpxuBxOAHETvgjBvQPeKBkcsZ5399BEkfsFxbfkdX2Yyfy+oEYmT8bHqPebA== X-Received: by 2002:a63:4002:: with SMTP id n2mr1492562pga.124.1625173993280; Thu, 01 Jul 2021 14:13:13 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:12 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Alim Akhtar , Avri Altman , "James E.J. Bottomley" , Can Guo , Stanley Chu , Bean Huo , Asutosh Das Subject: [PATCH 10/21] ufs: Remove ufshcd_valid_tag() Date: Thu, 1 Jul 2021 14:12:13 -0700 Message-Id: <20210701211224.17070-11-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org scsi_add_host() allocates shost->can_queue tags. ufshcd_init() sets shost->can_queue to hba->nutrs. In other words, we know that tag values will be in the range [0, hba->nutrs). Hence remove the checks that verify that blk_get_request() returns a tag in this range. This check was introduced by commit 14497328b6a6 ("scsi: ufs: verify command tag validity"). Cc: Alim Akhtar Cc: Avri Altman Signed-off-by: Bart Van Assche Reviewed-by: Avri Altman --- drivers/scsi/ufs/ufshcd.c | 40 ++++++--------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 2148e123e9db..2e6aa614e3f5 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -253,11 +253,6 @@ static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable); static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba); static void ufshcd_hba_vreg_set_hpm(struct ufs_hba *hba); -static inline bool ufshcd_valid_tag(struct ufs_hba *hba, int tag) -{ - return tag >= 0 && tag < hba->nutrs; -} - static inline void ufshcd_enable_irq(struct ufs_hba *hba) { if (!hba->is_irq_enabled) { @@ -2701,21 +2696,11 @@ static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i) */ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) { + struct ufs_hba *hba = shost_priv(host); + int tag = cmd->request->tag; struct ufshcd_lrb *lrbp; - struct ufs_hba *hba; - int tag; int err = 0; - hba = shost_priv(host); - - tag = cmd->request->tag; - if (!ufshcd_valid_tag(hba, tag)) { - dev_err(hba->dev, - "%s: invalid command tag %d: cmd=0x%p, cmd->request=0x%p", - __func__, tag, cmd, cmd->request); - BUG(); - } - if (!down_read_trylock(&hba->clk_scaling_lock)) return SCSI_MLQUEUE_HOST_BUSY; @@ -2968,7 +2953,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, goto out_unlock; } tag = req->tag; - WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag)); if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { err = -EBUSY; @@ -6673,7 +6657,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, goto out_unlock; } tag = req->tag; - WARN_ON_ONCE(!ufshcd_valid_tag(hba, tag)); if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { err = -EBUSY; @@ -6975,25 +6958,14 @@ static int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag) */ static int ufshcd_abort(struct scsi_cmnd *cmd) { - struct Scsi_Host *host; - struct ufs_hba *hba; + struct Scsi_Host *host = cmd->device->host; + struct ufs_hba *hba = shost_priv(host); + unsigned int tag = cmd->request->tag; + struct ufshcd_lrb *lrbp = &hba->lrb[tag]; unsigned long flags; - unsigned int tag; int err = 0; - struct ufshcd_lrb *lrbp; u32 reg; - host = cmd->device->host; - hba = shost_priv(host); - tag = cmd->request->tag; - lrbp = &hba->lrb[tag]; - if (!ufshcd_valid_tag(hba, tag)) { - dev_err(hba->dev, - "%s: invalid command tag %d: cmd=0x%p, cmd->request=0x%p", - __func__, tag, cmd, cmd->request); - BUG(); - } - ufshcd_hold(hba, false); reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); /* If command is already aborted/completed, return SUCCESS */ From patchwork Thu Jul 1 21:12:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E15F7C11F67 for ; Thu, 1 Jul 2021 21:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C849F61405 for ; Thu, 1 Jul 2021 21:13:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233811AbhGAVPz (ORCPT ); Thu, 1 Jul 2021 17:15:55 -0400 Received: from mail-pl1-f172.google.com ([209.85.214.172]:42755 "EHLO mail-pl1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbhGAVPy (ORCPT ); Thu, 1 Jul 2021 17:15:54 -0400 Received: by mail-pl1-f172.google.com with SMTP id v13so4408694ple.9 for ; Thu, 01 Jul 2021 14:13:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BcLOumkWjxXSrw0lsUXBmNDTMMbqTdhadkQZCqHLM0E=; b=GbSLSOrg/i3VxUpwLSWEVMN9w4UDVy2in+hsq/yl6YWJ6Jh5Xl9UVEuCx9jS4EFKmu xmKjLdsn5fxAogvoD3VA1uFZ2Qy6l4+lwjIfuCR6OaYxt4Nt2sc8pwFd+zEkyfiELDtQ u20rE1JDSvnNWSR/VniblMip1uegFzjpD/3XQ/DdXbN5Grh32zxbgItsJ01UCGEjCthm u+qbzQgEtt4yByYnJTgg+AlxOXFPKskyE0ek66o8rBHcpc+2316RRde89OjRAYz7uXHK ZN4AFBgfQdL6xudC6INefZC7vtG5jt0ec9B6lOfj1x7ndcLkK9ledX4oIU8XthGr585i xhKQ== X-Gm-Message-State: AOAM532gZ/8dIMDZ1zuzxKtRIExleAHyYuBpyWFczV55wTpzwO/bA4XY NL7KU4Fz13/zC+TKnGTyu2g= X-Google-Smtp-Source: ABdhPJz71KQhzol1wszhKrVmxktdSJTIPZpVmatCr2qumz0F/u6o+KE+vSBqvZV0E0MMMDpleZ8h0A== X-Received: by 2002:a17:90a:db8a:: with SMTP id h10mr12059040pjv.50.1625174002823; Thu, 01 Jul 2021 14:13:22 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:22 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Avri Altman , Can Guo , "James E.J. Bottomley" , Stanley Chu , Bean Huo , Asutosh Das , Adrian Hunter Subject: [PATCH 12/21] ufs: Improve static type checking for the host controller state Date: Thu, 1 Jul 2021 14:12:15 -0700 Message-Id: <20210701211224.17070-13-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Assign a name to the enumeration type for UFS host controller states and remove the default clause from switch statements on this enumeration type to make the compiler warn about unhandled enumeration labels. Reviewed-by: Avri Altman Cc: Can Guo Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 15 --------------- drivers/scsi/ufs/ufshcd.h | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1262f1a63e0b..7091798e6245 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -128,15 +128,6 @@ enum { UFSHCD_CAN_QUEUE = 32, }; -/* UFSHCD states */ -enum { - UFSHCD_STATE_RESET, - UFSHCD_STATE_ERROR, - UFSHCD_STATE_OPERATIONAL, - UFSHCD_STATE_EH_SCHEDULED_FATAL, - UFSHCD_STATE_EH_SCHEDULED_NON_FATAL, -}; - /* UFSHCD error handling flags */ enum { UFSHCD_EH_IN_PROGRESS = (1 << 0), @@ -2735,12 +2726,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) set_host_byte(cmd, DID_ERROR); cmd->scsi_done(cmd); goto out; - default: - dev_WARN_ONCE(hba->dev, 1, "%s: invalid state %d\n", - __func__, hba->ufshcd_state); - set_host_byte(cmd, DID_BAD_TARGET); - cmd->scsi_done(cmd); - goto out; } hba->req_abort_count = 0; diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 0dfb5e97ec0d..f8766e8f3cac 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -476,6 +476,27 @@ struct ufs_stats { struct ufs_event_hist event[UFS_EVT_CNT]; }; +/** + * enum ufshcd_state - UFS host controller state + * @UFSHCD_STATE_RESET: Link is not operational. Postpone SCSI command + * processing. + * @UFSHCD_STATE_OPERATIONAL: The host controller is operational and can process + * SCSI commands. + * @UFSHCD_STATE_EH_SCHEDULED_NON_FATAL: The error handler has been scheduled. + * SCSI commands may be submitted to the controller. + * @UFSHCD_STATE_EH_SCHEDULED_FATAL: The error handler has been scheduled. Fail + * newly submitted SCSI commands with error code DID_BAD_TARGET. + * @UFSHCD_STATE_ERROR: An unrecoverable error occurred, e.g. link recovery + * failed. Fail all SCSI commands with error code DID_ERROR. + */ +enum ufshcd_state { + UFSHCD_STATE_RESET, + UFSHCD_STATE_OPERATIONAL, + UFSHCD_STATE_EH_SCHEDULED_NON_FATAL, + UFSHCD_STATE_EH_SCHEDULED_FATAL, + UFSHCD_STATE_ERROR, +}; + enum ufshcd_quirks { /* Interrupt aggregation support is broken */ UFSHCD_QUIRK_BROKEN_INTR_AGGR = 1 << 0, @@ -687,7 +708,7 @@ struct ufs_hba_monitor { * @tmf_tag_set: TMF tag set. * @tmf_queue: Used to allocate TMF tags. * @pwr_done: completion for power mode change - * @ufshcd_state: UFSHCD states + * @ufshcd_state: UFSHCD state * @eh_flags: Error handling flags * @intr_mask: Interrupt Mask Bits * @ee_ctrl_mask: Exception event control mask @@ -785,7 +806,7 @@ struct ufs_hba { struct mutex uic_cmd_mutex; struct completion *uic_async_done; - u32 ufshcd_state; + enum ufshcd_state ufshcd_state; u32 eh_flags; u32 intr_mask; u16 ee_ctrl_mask; /* Exception event mask */ From patchwork Thu Jul 1 21:12:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2E73C11F67 for ; Thu, 1 Jul 2021 21:13:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A52F961406 for ; Thu, 1 Jul 2021 21:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234178AbhGAVQD (ORCPT ); Thu, 1 Jul 2021 17:16:03 -0400 Received: from mail-pl1-f179.google.com ([209.85.214.179]:41750 "EHLO mail-pl1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233920AbhGAVQC (ORCPT ); Thu, 1 Jul 2021 17:16:02 -0400 Received: by mail-pl1-f179.google.com with SMTP id z4so4412935plg.8 for ; Thu, 01 Jul 2021 14:13:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4LheHc3SC4FF3EChZEnCuOOXPXJ1BYmbcTjoKho4cIc=; b=hNVyu+7sV2AT0MgjXFm0yYhVhOYDKi4NLyk9An4OBoPqgoIrrXjoI3K6WdSkJC1PGK BJ+vQVj53DZxj+0Laqc8V7S6vgJ5ODv9y52Z4MOssD9hAOACnaTwiUtLky84vHZeUtez ywvrbONmVA4RTzdBPHCWQvDA1Uim2Pg2fANpleizFLIRg2x3RuvSXD307o8sOjlutV/d URw1jabPpfkyYMSEdxZ+77p3uHapAlwfiiZ+vpd/zXXyDrkBhAqIevaNSY5Xx1WEu2/o b1glSG+6rc78KSBAF6aeBBIMemcGYn7Moz6StUnuz+HqX6FlXLiT2LtWt17s8b+alEYM mD+w== X-Gm-Message-State: AOAM533WqUim/u79l9ddLKHNl85k6k02i0y4iTt6PmwYN6E6K5saeRWT rr/cpjZSIpEpJKCSlLQtqf0= X-Google-Smtp-Source: ABdhPJy6hP1GN9JMMasnoLevJAODeetD73VM5Lr93biUpv2cg+O+8LR3L1v5CNqJbYKqVWJHS9er/Q== X-Received: by 2002:a17:902:d213:b029:127:9520:7649 with SMTP id t19-20020a170902d213b029012795207649mr1586856ply.10.1625174010143; Thu, 01 Jul 2021 14:13:30 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:29 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Adrian Hunter , Stanley Chu , Can Guo , Asutosh Das , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , Bean Huo Subject: [PATCH 14/21] ufs: Inline ufshcd_outstanding_req_clear() Date: Thu, 1 Jul 2021 14:12:17 -0700 Message-Id: <20210701211224.17070-15-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Inline ufshcd_outstanding_req_clear() since it only has one caller and since its body is only one line long. Cc: Adrian Hunter Cc: Stanley Chu Cc: Can Guo Cc: Asutosh Das Cc: Avri Altman Signed-off-by: Bart Van Assche Reviewed-by: Avri Altman --- drivers/scsi/ufs/ufshcd.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 25ab603acad1..2acf168bc339 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -743,16 +743,6 @@ static inline void ufshcd_utmrl_clear(struct ufs_hba *hba, u32 pos) ufshcd_writel(hba, ~(1 << pos), REG_UTP_TASK_REQ_LIST_CLEAR); } -/** - * ufshcd_outstanding_req_clear - Clear a bit in outstanding request field - * @hba: per adapter instance - * @tag: position of the bit to be cleared - */ -static inline void ufshcd_outstanding_req_clear(struct ufs_hba *hba, int tag) -{ - clear_bit(tag, &hba->outstanding_reqs); -} - /** * ufshcd_get_lists_status - Check UCRDY, UTRLRDY and UTMRLRDY * @reg: Register value of host controller status @@ -2898,7 +2888,7 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, * we also need to clear the outstanding_request * field in hba */ - ufshcd_outstanding_req_clear(hba, lrbp->task_tag); + clear_bit(lrbp->task_tag, &hba->outstanding_reqs); } return err; From patchwork Thu Jul 1 21:12:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4441CC11F67 for ; Thu, 1 Jul 2021 21:13:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B35A61405 for ; Thu, 1 Jul 2021 21:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234198AbhGAVQK (ORCPT ); Thu, 1 Jul 2021 17:16:10 -0400 Received: from mail-pf1-f177.google.com ([209.85.210.177]:40693 "EHLO mail-pf1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233894AbhGAVQJ (ORCPT ); Thu, 1 Jul 2021 17:16:09 -0400 Received: by mail-pf1-f177.google.com with SMTP id j199so6636090pfd.7 for ; Thu, 01 Jul 2021 14:13:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QZctrWOqBlKW5P0weHpPimaB9jxJRb4pcRR3+7sSIW8=; b=R9RcRg36uwZW3GV+xbebw4LFH/+gqz5PfAA/1cHmDAYbYNbgtRzBCufjItqSZXvBX0 pJmgywgFc21Ul8Ol2tHJS+Zu7d14JXf1mnD847bRK3gQ3BafKwmPrSDYoVBEYag5Fzqp /s6YoZ7fMF6lOFq9/4YiQSkyIfghO/ihiCncGopXX8iS6fZJTHOl2cS8OE2Kd4fQIaiq xJhQSlAWXTz7hY4DK/Ii/GZWsPpunPoKkuzHXGMiIgxnbpkOQDCTCnT4OJmRqXDr0P0L DmrMfGIN2W417O4CMo+n393U1GlQJINeqoxK71tln9g/HCa5ovCzXhE3ZAO8b0PezRhy j2zQ== X-Gm-Message-State: AOAM533n8BeVu/E78w8mjTR3VWsgSK7Z5KSnAbtYVyecWzB1/gD3MYEu FpsAslQLpUyQTzTq59J4GNI= X-Google-Smtp-Source: ABdhPJyyD7KL/5IsPSWreEE6cAlhA9dUG6ZBnYR4Ay+mUe5cab/HkZXU9CG6atfHAtdEOrLC1UavMw== X-Received: by 2002:a62:de83:0:b029:30f:eac:88ef with SMTP id h125-20020a62de830000b029030f0eac88efmr1970097pfg.18.1625174018051; Thu, 01 Jul 2021 14:13:38 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:37 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Adrian Hunter , Stanley Chu , Can Guo , Asutosh Das , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , Bean Huo Subject: [PATCH 16/21] ufs: Fix the SCSI abort handler Date: Thu, 1 Jul 2021 14:12:19 -0700 Message-Id: <20210701211224.17070-17-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make the following changes in ufshcd_abort(): - Return FAILED instead of SUCCESS if the abort handler notices that a SCSI command has already been completed. Returning SUCCESS in this case triggers a use-after-free and may trigger a kernel crash. - Fix the code for aborting SCSI commands submitted to a WLUN. The current approach for aborting SCSI commands that have been submitted to a WLUN and that timed out is as follows: - Report to the SCSI core that the command has completed successfully. Let the block layer free any data buffers associated with the command. - Mark the command as outstanding in 'outstanding_reqs'. - If the block layer tries to reuse the tag associated with the aborted command, busy-wait until the tag is freed. This approach can result in: - Memory corruption if the controller accesses the data buffer after the block layer has freed the associated data buffers. - A race condition if ufshcd_queuecommand() or ufshcd_exec_dev_cmd() checks the bit that corresponds to an aborted command in 'outstanding_reqs' after it has been cleared and before it is reset. - High energy consumption if ufshcd_queuecommand() repeatedly returns SCSI_MLQUEUE_HOST_BUSY. Fix this by reporting to the SCSI error handler that aborting a SCSI command failed if the SCSI command was submitted to a WLUN. Cc: Adrian Hunter Cc: Stanley Chu Cc: Can Guo Cc: Asutosh Das Cc: Avri Altman Fixes: 7a7e66c65d41 ("scsi: ufs: Fix a race condition between ufshcd_abort() and eh_work()") Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 57 +++++++++++++-------------------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 0b7359e0b445..aa23fe6f5ddd 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2728,15 +2728,6 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) WARN_ON(ufshcd_is_clkgating_allowed(hba) && (hba->clk_gating.state != CLKS_ON)); - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { - if (hba->pm_op_in_progress) - set_host_byte(cmd, DID_BAD_TARGET); - else - err = SCSI_MLQUEUE_HOST_BUSY; - ufshcd_release(hba); - goto out; - } - lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); lrbp->cmd = cmd; @@ -2926,12 +2917,6 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, goto out_unlock; } tag = req->tag; - - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { - err = -EBUSY; - goto out; - } - lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); err = ufshcd_compose_dev_cmd(hba, lrbp, cmd_type, tag); @@ -6929,17 +6914,17 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) unsigned int tag = cmd->request->tag; struct ufshcd_lrb *lrbp = &hba->lrb[tag]; unsigned long flags; - int err = 0; + int err = FAILED, res; u32 reg; ufshcd_hold(hba, false); reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); - /* If command is already aborted/completed, return SUCCESS */ + /* If command is already aborted/completed, return FAILED. */ if (!(test_bit(tag, &hba->outstanding_reqs))) { dev_err(hba->dev, "%s: cmd at tag %d already completed, outstanding=0x%lx, doorbell=0x%x\n", __func__, tag, hba->outstanding_reqs, reg); - goto out; + goto release; } /* Print Transfer Request of aborted task */ @@ -6968,7 +6953,8 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) dev_err(hba->dev, "%s: cmd was completed, but without a notifying intr, tag = %d", __func__, tag); - goto cleanup; + ufshcd_transfer_req_compl(hba, 1UL << tag); + goto release; } /* @@ -6981,36 +6967,29 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) */ if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) { ufshcd_update_evt_hist(hba, UFS_EVT_ABORT, lrbp->lun); - ufshcd_transfer_req_compl(hba, 1UL << tag); - set_bit(tag, &hba->outstanding_reqs); + spin_lock_irqsave(host->host_lock, flags); hba->force_reset = true; ufshcd_schedule_eh_work(hba); spin_unlock_irqrestore(host->host_lock, flags); - goto out; + goto release; } /* Skip task abort in case previous aborts failed and report failure */ - if (lrbp->req_abort_skip) - err = -EIO; - else - err = ufshcd_try_to_abort_task(hba, tag); - - if (!err) { -cleanup: - ufshcd_transfer_req_compl(hba, 1UL << tag); -out: - err = SUCCESS; - } else { - dev_err(hba->dev, "%s: failed with err %d\n", __func__, err); + if (lrbp->req_abort_skip) { + dev_err(hba->dev, "%s: failed\n", __func__); ufshcd_set_req_abort_skip(hba, hba->outstanding_reqs); - err = FAILED; + goto release; } - /* - * This ufshcd_release() corresponds to the original scsi cmd that got - * aborted here (as we won't get any IRQ for it). - */ + res = ufshcd_try_to_abort_task(hba, tag); + if (res) + goto release; + + err = SUCCESS; + +release: + /* Matches the ufshcd_hold() call at the start of this function. */ ufshcd_release(hba); return err; } From patchwork Thu Jul 1 21:12:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8842AC11F67 for ; Thu, 1 Jul 2021 21:13:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FAD361406 for ; Thu, 1 Jul 2021 21:13:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234222AbhGAVQU (ORCPT ); Thu, 1 Jul 2021 17:16:20 -0400 Received: from mail-pl1-f176.google.com ([209.85.214.176]:46847 "EHLO mail-pl1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233894AbhGAVQU (ORCPT ); Thu, 1 Jul 2021 17:16:20 -0400 Received: by mail-pl1-f176.google.com with SMTP id c15so4388903pls.13 for ; Thu, 01 Jul 2021 14:13:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5gxaktirlzpH8KBULMzt0ysZVe1zdPmJjZ584Id3FDY=; b=FsjPxwXuvVmPXA7OW7Wh80ZWGpST2dQZUBoUIiezi61Ud2K4DUQTV9QkwGVVrFRrQS dNVADiUmlFx7Ceo+T8ro9wPzHFRRvdzxmBS1mWlbg2KoIWBevT1KYHexr5OnshNDrWCD cecPL/gYe4UjmgJ0OrDQVmbf1NoqYNAgBF7k5HS5qtyEj4z2bhPUxa/HI3SVDAlY6CEy mXS6KEJqdVgxn2wd9/A1iQ/NJTOCBN40zoMT7OYHnOeCCYE4xIo4t9TrdYm1Wi/rpThz 0BVsAg7RLrpqbDEHRyiwoqauUiZ58vK7X3ecqjfhFyRgKxN1Wdp5iqkU9CzHCfjcEWxA tC3w== X-Gm-Message-State: AOAM531AiMC0wknYn9Z4exeRUsij9/p4/PgsrfTvvAuPHxYD0t4vq2V2 ULdpiz9wfn/nndssEzXg2rg= X-Google-Smtp-Source: ABdhPJxxaHGeZyZiQ6/AwkUYmYQg2JbmpCMQ1i7s9mtknQCkjaFxi5eLvERQTO0J3iFnfLzrTUOJJw== X-Received: by 2002:a17:90a:e98f:: with SMTP id v15mr1536079pjy.144.1625174028637; Thu, 01 Jul 2021 14:13:48 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:47 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Adrian Hunter , Stanley Chu , Can Guo , Asutosh Das , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , Bean Huo , Kiwoong Kim Subject: [PATCH 18/21] ufs: Use the doorbell register instead of the UTRLCNR register Date: Thu, 1 Jul 2021 14:12:21 -0700 Message-Id: <20210701211224.17070-19-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Using the UTRLCNR register implies performing two MMIO accesses in the hot path while reading the doorbell register only involves a single MMIO operation. Hence do not use the UTRLNCR register. Cc: Adrian Hunter Cc: Stanley Chu Cc: Can Guo Cc: Asutosh Das Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 2 +- drivers/scsi/ufs/ufshcd.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 71db56c72af6..250d46ab3584 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6370,7 +6370,7 @@ static irqreturn_t ufshcd_sl_intr(struct ufs_hba *hba, u32 intr_status) retval |= ufshcd_tmc_handler(hba); if (intr_status & UTP_TRANSFER_REQ_COMPL) - retval |= ufshcd_trc_handler(hba, ufshcd_has_utrlcnr(hba)); + retval |= ufshcd_trc_handler(hba, ufshcd_use_utrlcnr(hba)); return retval; } diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index f8766e8f3cac..b3d9b487846f 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -1184,9 +1184,9 @@ static inline u32 ufshcd_vops_get_ufs_hci_version(struct ufs_hba *hba) return ufshcd_readl(hba, REG_UFS_VERSION); } -static inline bool ufshcd_has_utrlcnr(struct ufs_hba *hba) +static inline bool ufshcd_use_utrlcnr(struct ufs_hba *hba) { - return (hba->ufs_version >= ufshci_version(3, 0)); + return false; } static inline int ufshcd_vops_clk_scale_notify(struct ufs_hba *hba, From patchwork Thu Jul 1 21:12:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 469354 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 082D8C11F67 for ; Thu, 1 Jul 2021 21:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFD5661403 for ; Thu, 1 Jul 2021 21:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233980AbhGAVQ3 (ORCPT ); Thu, 1 Jul 2021 17:16:29 -0400 Received: from mail-pf1-f177.google.com ([209.85.210.177]:37409 "EHLO mail-pf1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233894AbhGAVQ2 (ORCPT ); Thu, 1 Jul 2021 17:16:28 -0400 Received: by mail-pf1-f177.google.com with SMTP id 17so6865127pfz.4 for ; Thu, 01 Jul 2021 14:13:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B5rqlyQfz0+9MS6IH1prMrDBK5a+AvarhTHXskz5VN8=; b=Ea+thM90HaBTR94GF+N0t+l6farT3p2XenfwOGDDUQv4tPfqK6SU1d/HbvhNiZk7CK ywj6zEFbVl9exfz2VaQe/YxxdOGG1Tfjs5VTLLWpQQkFCE7SkJ03DEYQNKd68nXqsbqt IuYY1ZoEcMx98/UuRYR27khLJzBGwG1QF9+Zlk7RrJGyQAZMYvnOFO/ORPm2QLIP5T8v aYnZfY2kwiqI8NP/KZGTnmZifokTe+hnZVJBKdAAI8+BnJDC7F0ygs1XpEfv+S/l0sqa TUHR0FTKII18zBmCm6r95HdM6N5PTZih4mThj73BWK47lwcoWDoP50Ap5uKsTc+kwjBi K9nw== X-Gm-Message-State: AOAM5304onZK6vTiAswWFpqioZ3nPPvoJ54GHi7oE1KNlipFcR7NsZTM jrp5CYRafptNcRbULxVe0FM= X-Google-Smtp-Source: ABdhPJy2XnjkRqMjNv7lmID+7G/aS2xXqFCVeyfYvzGUUFBWkicL1/vVu+x9ndgjz6jaB2j8UGMLXw== X-Received: by 2002:a63:a45:: with SMTP id z5mr1450014pgk.227.1625174037673; Thu, 01 Jul 2021 14:13:57 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:6a75:b07:a0d:8bd5]) by smtp.gmail.com with ESMTPSA id k25sm900832pfa.213.2021.07.01.14.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 14:13:56 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Bart Van Assche , Adrian Hunter , Stanley Chu , Can Guo , Asutosh Das , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , Bean Huo Subject: [PATCH 20/21] ufs: Synchronize SCSI and UFS error handling Date: Thu, 1 Jul 2021 14:12:23 -0700 Message-Id: <20210701211224.17070-21-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701211224.17070-1-bvanassche@acm.org> References: <20210701211224.17070-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use the SCSI error handler instead of a custom error handling strategy. This change reduces the number of potential races in the UFS drivers since the UFS error handler and the SCSI error handler no longer run concurrently. Cc: Adrian Hunter Cc: Stanley Chu Cc: Can Guo Cc: Asutosh Das Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 101 ++++++++++++++++++++------------------ drivers/scsi/ufs/ufshcd.h | 4 -- 2 files changed, 54 insertions(+), 51 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index a74862813140..cfb2d00c325c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include "../scsi_transport_api.h" #include "ufshcd.h" #include "ufs_quirks.h" #include "unipro.h" @@ -233,7 +235,6 @@ static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up); static irqreturn_t ufshcd_intr(int irq, void *__hba); static int ufshcd_change_power_mode(struct ufs_hba *hba, struct ufs_pa_layer_attr *pwr_mode); -static void ufshcd_schedule_eh_work(struct ufs_hba *hba); static int ufshcd_setup_hba_vreg(struct ufs_hba *hba, bool on); static int ufshcd_setup_vreg(struct ufs_hba *hba, bool on); static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba, @@ -3897,6 +3898,35 @@ int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, } EXPORT_SYMBOL_GPL(ufshcd_dme_get_attr); +static inline bool ufshcd_is_saved_err_fatal(struct ufs_hba *hba) +{ + lockdep_assert_held(hba->host->host_lock); + + return (hba->saved_uic_err & UFSHCD_UIC_DL_PA_INIT_ERROR) || + (hba->saved_err & (INT_FATAL_ERRORS | UFSHCD_UIC_HIBERN8_MASK)); +} + +static void ufshcd_schedule_eh(struct ufs_hba *hba) +{ + bool schedule_eh = false; + unsigned long flags; + + spin_lock_irqsave(hba->host->host_lock, flags); + /* handle fatal errors only when link is not in error state */ + if (hba->ufshcd_state != UFSHCD_STATE_ERROR) { + if (hba->force_reset || ufshcd_is_link_broken(hba) || + ufshcd_is_saved_err_fatal(hba)) + hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_FATAL; + else + hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_NON_FATAL; + schedule_eh = true; + } + spin_unlock_irqrestore(hba->host->host_lock, flags); + + if (schedule_eh) + scsi_schedule_eh(hba->host); +} + /** * ufshcd_uic_pwr_ctrl - executes UIC commands (which affects the link power * state) and waits for it to take effect. @@ -3917,6 +3947,7 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) { DECLARE_COMPLETION_ONSTACK(uic_async_done); unsigned long flags; + bool schedule_eh = false; u8 status; int ret; bool reenable_intr = false; @@ -3986,10 +4017,14 @@ static int ufshcd_uic_pwr_ctrl(struct ufs_hba *hba, struct uic_command *cmd) ufshcd_enable_intr(hba, UIC_COMMAND_COMPL); if (ret) { ufshcd_set_link_broken(hba); - ufshcd_schedule_eh_work(hba); + schedule_eh = true; } + out_unlock: spin_unlock_irqrestore(hba->host->host_lock, flags); + + if (schedule_eh) + ufshcd_schedule_eh(hba); mutex_unlock(&hba->uic_cmd_mutex); return ret; @@ -5804,27 +5839,6 @@ static bool ufshcd_quirk_dl_nac_errors(struct ufs_hba *hba) return err_handling; } -/* host lock must be held before calling this func */ -static inline bool ufshcd_is_saved_err_fatal(struct ufs_hba *hba) -{ - return (hba->saved_uic_err & UFSHCD_UIC_DL_PA_INIT_ERROR) || - (hba->saved_err & (INT_FATAL_ERRORS | UFSHCD_UIC_HIBERN8_MASK)); -} - -/* host lock must be held before calling this func */ -static inline void ufshcd_schedule_eh_work(struct ufs_hba *hba) -{ - /* handle fatal errors only when link is not in error state */ - if (hba->ufshcd_state != UFSHCD_STATE_ERROR) { - if (hba->force_reset || ufshcd_is_link_broken(hba) || - ufshcd_is_saved_err_fatal(hba)) - hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_FATAL; - else - hba->ufshcd_state = UFSHCD_STATE_EH_SCHEDULED_NON_FATAL; - queue_work(hba->eh_wq, &hba->eh_work); - } -} - static void ufshcd_clk_scaling_allow(struct ufs_hba *hba, bool allow) { down_write(&hba->clk_scaling_lock); @@ -5958,11 +5972,11 @@ static bool ufshcd_is_pwr_mode_restore_needed(struct ufs_hba *hba) /** * ufshcd_err_handler - handle UFS errors that require s/w attention - * @work: pointer to work structure + * @host: SCSI host pointer */ -static void ufshcd_err_handler(struct work_struct *work) +static void ufshcd_err_handler(struct Scsi_Host *host) { - struct ufs_hba *hba; + struct ufs_hba *hba = shost_priv(host); unsigned long flags; bool err_xfer = false; bool err_tm = false; @@ -5970,8 +5984,6 @@ static void ufshcd_err_handler(struct work_struct *work) int tag; bool needs_reset = false, needs_restore = false; - hba = container_of(work, struct ufs_hba, eh_work); - down(&hba->host_sem); spin_lock_irqsave(hba->host->host_lock, flags); if (ufshcd_err_handling_should_stop(hba)) { @@ -6287,7 +6299,6 @@ static irqreturn_t ufshcd_check_errors(struct ufs_hba *hba, u32 intr_status) "host_regs: "); ufshcd_print_pwr_info(hba); } - ufshcd_schedule_eh_work(hba); retval |= IRQ_HANDLED; } /* @@ -6299,6 +6310,10 @@ static irqreturn_t ufshcd_check_errors(struct ufs_hba *hba, u32 intr_status) hba->errors = 0; hba->uic_error = 0; spin_unlock(hba->host->host_lock); + + if (queue_eh_work) + ufshcd_schedule_eh(hba); + return retval; } @@ -6958,15 +6973,17 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) * will be to send LU reset which, again, is a spec violation. * To avoid these unnecessary/illegal steps, first we clean up * the lrb taken by this cmd and re-set it in outstanding_reqs, - * then queue the eh_work and bail. + * then queue the error handler and bail. */ if (lrbp->lun == UFS_UPIU_UFS_DEVICE_WLUN) { ufshcd_update_evt_hist(hba, UFS_EVT_ABORT, lrbp->lun); spin_lock_irqsave(host->host_lock, flags); hba->force_reset = true; - ufshcd_schedule_eh_work(hba); spin_unlock_irqrestore(host->host_lock, flags); + + ufshcd_schedule_eh(hba); + goto release; } @@ -7094,11 +7111,10 @@ static int ufshcd_eh_host_reset_handler(struct scsi_cmnd *cmd) spin_lock_irqsave(hba->host->host_lock, flags); hba->force_reset = true; - ufshcd_schedule_eh_work(hba); dev_err(hba->dev, "%s: reset in progress - 1\n", __func__); spin_unlock_irqrestore(hba->host->host_lock, flags); - flush_work(&hba->eh_work); + ufshcd_err_handler(hba->host); spin_lock_irqsave(hba->host->host_lock, flags); if (hba->ufshcd_state == UFSHCD_STATE_ERROR) @@ -8458,8 +8474,6 @@ static void ufshcd_hba_exit(struct ufs_hba *hba) if (hba->is_powered) { ufshcd_exit_clk_scaling(hba); ufshcd_exit_clk_gating(hba); - if (hba->eh_wq) - destroy_workqueue(hba->eh_wq); ufs_debugfs_hba_exit(hba); ufshcd_variant_hba_exit(hba); ufshcd_setup_vreg(hba, false); @@ -9298,6 +9312,10 @@ static int ufshcd_set_dma_mask(struct ufs_hba *hba) return dma_set_mask_and_coherent(hba->dev, DMA_BIT_MASK(32)); } +static struct scsi_transport_template ufshcd_transport_template = { + .eh_strategy_handler = ufshcd_err_handler, +}; + /** * ufshcd_alloc_host - allocate Host Bus Adapter (HBA) * @dev: pointer to device handle @@ -9324,6 +9342,7 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle) err = -ENOMEM; goto out_error; } + host->transportt = &ufshcd_transport_template; hba = shost_priv(host); hba->host = host; hba->dev = dev; @@ -9361,7 +9380,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) int err; struct Scsi_Host *host = hba->host; struct device *dev = hba->dev; - char eh_wq_name[sizeof("ufs_eh_wq_00")]; if (!mmio_base) { dev_err(hba->dev, @@ -9415,17 +9433,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) hba->max_pwr_info.is_valid = false; - /* Initialize work queues */ - snprintf(eh_wq_name, sizeof(eh_wq_name), "ufs_eh_wq_%d", - hba->host->host_no); - hba->eh_wq = create_singlethread_workqueue(eh_wq_name); - if (!hba->eh_wq) { - dev_err(hba->dev, "%s: failed to create eh workqueue\n", - __func__); - err = -ENOMEM; - goto out_disable; - } - INIT_WORK(&hba->eh_work, ufshcd_err_handler); INIT_WORK(&hba->eeh_work, ufshcd_exception_event_handler); sema_init(&hba->host_sem, 1); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index b3d9b487846f..b821851a62eb 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -715,8 +715,6 @@ struct ufs_hba_monitor { * @is_powered: flag to check if HBA is powered * @shutting_down: flag to check if shutdown has been invoked * @host_sem: semaphore used to serialize concurrent contexts - * @eh_wq: Workqueue that eh_work works on - * @eh_work: Worker to handle UFS errors that require s/w attention * @eeh_work: Worker to handle exception events * @errors: HBA errors * @uic_error: UFS interconnect layer error status @@ -818,8 +816,6 @@ struct ufs_hba { struct semaphore host_sem; /* Work Queues */ - struct workqueue_struct *eh_wq; - struct work_struct eh_work; struct work_struct eeh_work; /* HBA Errors */