From patchwork Wed Nov 10 00:44:30 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: 12611219 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62242C433EF for ; Wed, 10 Nov 2021 00:45:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3ECE061184 for ; Wed, 10 Nov 2021 00:45:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbhKJArs (ORCPT ); Tue, 9 Nov 2021 19:47:48 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]:39788 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKJArr (ORCPT ); Tue, 9 Nov 2021 19:47:47 -0500 Received: by mail-pg1-f178.google.com with SMTP id g184so634297pgc.6 for ; Tue, 09 Nov 2021 16:45:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mRkJNMhTrXc4dm3oK22XOgQhWgx38cXwyseM6/UIDOc=; b=eW7toWgsssrYK3cpRXcTaQmuzAIl7z34bAgcroyMjfiY/HlR1ej3JynH/W0l3MJNyU rbnuPL112x1r306Nusy6Q9Uk/oxVJpKbQWEyzEeBnDznSkkUWOlPV4xiPSLqFc4FIuxq NjfGRMtHJXqz73ptTijmtNSa65vNgwdfuekfso26qdmuOh3ry73LpTH9jaGuJyU3kqhA J9lWV5kUUVyrs/l2f4NPTNYyw/ejv7cggU3bWWL0AAYI3pR5NZUKowxW/vgniCXFyzIf whnCViLVvOTFfV0JgLExgqoP2u6v8Qrtc1nuUGXult+T64KNHHpItIkVChZILVS8QkUJ 7Z+w== X-Gm-Message-State: AOAM530lKchYl2gTlrYu71dsdnssDbLKjU6qBNN+bW09X9fypTsSEsnz QVtgH8fAU+I6OZLxzq8V1vU= X-Google-Smtp-Source: ABdhPJxsnKQLxpx/QOPHLGtTgQDkpG34IqI8h5htbXGzC0nwkY8Go3B0GJu/Hp0Tdu5o2Nr5cw97DA== X-Received: by 2002:a05:6a00:1817:b0:49f:b893:6be0 with SMTP id y23-20020a056a00181700b0049fb8936be0mr12666795pfa.48.1636505100718; Tue, 09 Nov 2021 16:45:00 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:00 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Krzysztof Kozlowski , Alim Akhtar , Bean Huo , Avri Altman , Kiwoong Kim , Yue Hu , Peter Wang , Chanho Park , Stanley Chu , Can Guo , Asutosh Das , Keoseong Park Subject: [PATCH 01/11] scsi: ufs: Rename a function argument Date: Tue, 9 Nov 2021 16:44:30 -0800 Message-Id: <20211110004440.3389311-2-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The new name makes it clear what the meaning of the function argument is. Signed-off-by: Bart Van Assche Reviewed-by: Chanho Park Reviewed-by: Keoseong Park Acked-by: Alim Akhtar --- drivers/scsi/ufs/ufs-exynos.c | 4 ++-- drivers/scsi/ufs/ufshcd.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c index cd26bc82462e..474a4a064a68 100644 --- a/drivers/scsi/ufs/ufs-exynos.c +++ b/drivers/scsi/ufs/ufs-exynos.c @@ -853,14 +853,14 @@ static int exynos_ufs_post_pwr_mode(struct ufs_hba *hba, } static void exynos_ufs_specify_nexus_t_xfer_req(struct ufs_hba *hba, - int tag, bool op) + int tag, bool is_scsi_cmd) { struct exynos_ufs *ufs = ufshcd_get_variant(hba); u32 type; type = hci_readl(ufs, HCI_UTRL_NEXUS_TYPE); - if (op) + if (is_scsi_cmd) hci_writel(ufs, type | (1 << tag), HCI_UTRL_NEXUS_TYPE); else hci_writel(ufs, type & ~(1 << tag), HCI_UTRL_NEXUS_TYPE); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 4ceb3c7e65b4..a911ad72de7a 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -338,7 +338,8 @@ struct ufs_hba_variant_ops { enum ufs_notify_change_status status, struct ufs_pa_layer_attr *, struct ufs_pa_layer_attr *); - void (*setup_xfer_req)(struct ufs_hba *, int, bool); + void (*setup_xfer_req)(struct ufs_hba *hba, int tag, + bool is_scsi_cmd); void (*setup_task_mgmt)(struct ufs_hba *, int, u8); void (*hibern8_notify)(struct ufs_hba *, enum uic_cmd_dme, enum ufs_notify_change_status); From patchwork Wed Nov 10 00:44:31 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: 12611221 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03A9CC433EF for ; Wed, 10 Nov 2021 00:45:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E169461181 for ; Wed, 10 Nov 2021 00:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231343AbhKJAry (ORCPT ); Tue, 9 Nov 2021 19:47:54 -0500 Received: from mail-pf1-f174.google.com ([209.85.210.174]:37576 "EHLO mail-pf1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKJArx (ORCPT ); Tue, 9 Nov 2021 19:47:53 -0500 Received: by mail-pf1-f174.google.com with SMTP id y5so1047160pfb.4 for ; Tue, 09 Nov 2021 16:45:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wR7KU/viebny4nR2Y59jGd7p6vnccW0oeSt9hsxVM+I=; b=cPPWtr6++7XFnpmB5ILGt19UZ+Kg+n1URYGJRPns7H+hPd9XHpztwth91NOu/iX3X3 FYz1TaCmdqLMBprcyztdQPVGQH9iM+M6K2WJ1IS4JZQYflhditCcjEpq/TB1DAdOGL34 NXzQ5OQGi4pJIWVSN0bhbRwNopzMgwjHy8+O8u9Iwg7Fh7M+FSufzdg1DP4B4wZDk5S4 lWIXwUFzwR4dUzIRpoC+gcvhdI/HTB6Aj1UkvMIVO+pzRnqyXYeDUvzrfYziz09wxhQy RfP2Eakl/88g9CNQGF9pG8LmVjW/trFp+Mf89Iac06Pi9OYy+nhJOryGCA7BFS8QuL4G qcNg== X-Gm-Message-State: AOAM531lNfXjJHGLwFM2/XVmQrlu4B8Ta9a7V+6O28V0g+uGu+Ar2SHS coWFReSptHmIoD+E9eV4+qE= X-Google-Smtp-Source: ABdhPJxyugkn8DUWE+KCwE68ZOdsTZTP8tVL5VauFsCOXxNWQnmMX1z3LJZP7N1JCJ3c8ifI5geAkA== X-Received: by 2002:a63:874a:: with SMTP id i71mr9227320pge.81.1636505106278; Tue, 09 Nov 2021 16:45:06 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:05 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , kernel test robot , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Asutosh Das Subject: [PATCH 02/11] scsi: ufs: Remove is_rpmb_wlun() Date: Tue, 9 Nov 2021 16:44:31 -0800 Message-Id: <20211110004440.3389311-3-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Commit edc0596cc04b ("scsi: ufs: core: Stop clearing UNIT ATTENTIONS") removed all callers of is_rpmb_wlun(). Hence also remove the function itself. Reported-by: kernel test robot Signed-off-by: Bart Van Assche Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar --- drivers/scsi/ufs/ufshcd.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index dac8fbf221f7..d18685d080d7 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2650,11 +2650,6 @@ static inline u16 ufshcd_upiu_wlun_to_scsi_wlun(u8 upiu_wlun_id) return (upiu_wlun_id & ~UFS_UPIU_WLUN_ID) | SCSI_W_LUN_BASE; } -static inline bool is_rpmb_wlun(struct scsi_device *sdev) -{ - return sdev->lun == ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN); -} - static inline bool is_device_wlun(struct scsi_device *sdev) { return sdev->lun == From patchwork Wed Nov 10 00:44:32 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: 12611223 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD71C433F5 for ; Wed, 10 Nov 2021 00:45:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 586E561184 for ; Wed, 10 Nov 2021 00:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbhKJAsE (ORCPT ); Tue, 9 Nov 2021 19:48:04 -0500 Received: from mail-pg1-f173.google.com ([209.85.215.173]:45657 "EHLO mail-pg1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230338AbhKJAsC (ORCPT ); Tue, 9 Nov 2021 19:48:02 -0500 Received: by mail-pg1-f173.google.com with SMTP id f5so610666pgc.12 for ; Tue, 09 Nov 2021 16:45:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wws/JzFdGi/vBUm8yYarEhegVfr1+J0nCcGQ/Nh3upE=; b=PRQSHXdMvo2zLrmW2hPN5E4Zp1jV8YtdWlknrNfJYmdhDwbAuhH9+CwM6JK8NexuaT QYY85QGrjvzNc/VwJEq1dAEjqHGwzkvnJ1Se1ZjT2HuzxuCnaXsLivcm7ND34hWUR7Gk kn8VX70U8pzaNF0xkaE2TYY9ZzteN1DuiDsUc1Uq+p3efQ2N8ekrak+y1kNDYldY/qjF IOCzbzSqP4YfuJpDDP2A9+uFoOp0WeJKj2j9qd/ClXthEBz24yPLxEBVZHLo9xUO3oRi THBOjVLPcC6JMDVNoyISskgSNMxNOXh4DF0qFsivgUq+VQBU9KoFPPOr/auZ77C2gllY zuog== X-Gm-Message-State: AOAM530EsIf32E5pw6uwW+SpVKx+aCZhZnvRWV0i7y06liiYDPuAkqsg QaE1IqKRo6O47GFPqtr7Qmc3HXw8njq2BA== X-Google-Smtp-Source: ABdhPJzRkBgpVglPZdl19Mb86f6U6yKyGCb3nIpy2mD9o/4vDPd0uAkWqx1zffUVAGE45ZSfsHgy+g== X-Received: by 2002:a63:5646:: with SMTP id g6mr9065278pgm.216.1636505115202; Tue, 09 Nov 2021 16:45:15 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:14 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Avri Altman , Asutosh Das , Keoseong Park Subject: [PATCH 03/11] scsi: ufs: Remove the sdev_rpmb member Date: Tue, 9 Nov 2021 16:44:32 -0800 Message-Id: <20211110004440.3389311-4-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Since the sdev_rpmb member of struct ufs_hba is only used inside ufshcd_scsi_add_wlus(), convert it into a local variable. Suggested-by: Jaegeuk Kim Signed-off-by: Bart Van Assche Reviewed-by: Asutosh Das Reviewed-by: Alim Akhtar --- drivers/scsi/ufs/ufshcd.c | 12 ++++++------ drivers/scsi/ufs/ufshcd.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index d18685d080d7..dff76b1a0d5d 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7407,7 +7407,7 @@ static inline void ufshcd_blk_pm_runtime_init(struct scsi_device *sdev) static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) { int ret = 0; - struct scsi_device *sdev_boot; + struct scsi_device *sdev_boot, *sdev_rpmb; hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN), NULL); @@ -7418,14 +7418,14 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) } scsi_device_put(hba->sdev_ufs_device); - hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0, + sdev_rpmb = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL); - if (IS_ERR(hba->sdev_rpmb)) { - ret = PTR_ERR(hba->sdev_rpmb); + if (IS_ERR(sdev_rpmb)) { + ret = PTR_ERR(sdev_rpmb); goto remove_sdev_ufs_device; } - ufshcd_blk_pm_runtime_init(hba->sdev_rpmb); - scsi_device_put(hba->sdev_rpmb); + ufshcd_blk_pm_runtime_init(sdev_rpmb); + scsi_device_put(sdev_rpmb); sdev_boot = __scsi_add_device(hba->host, 0, 0, ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index a911ad72de7a..65178487adf3 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -809,7 +809,6 @@ struct ufs_hba { * "UFS device" W-LU. */ struct scsi_device *sdev_ufs_device; - struct scsi_device *sdev_rpmb; #ifdef CONFIG_SCSI_UFS_HWMON struct device *hwmon_device; From patchwork Wed Nov 10 00:44:33 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: 12611225 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAD12C433F5 for ; Wed, 10 Nov 2021 00:45:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2707611AD for ; Wed, 10 Nov 2021 00:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbhKJAsJ (ORCPT ); Tue, 9 Nov 2021 19:48:09 -0500 Received: from mail-pg1-f173.google.com ([209.85.215.173]:44023 "EHLO mail-pg1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbhKJAsH (ORCPT ); Tue, 9 Nov 2021 19:48:07 -0500 Received: by mail-pg1-f173.google.com with SMTP id b4so621528pgh.10 for ; Tue, 09 Nov 2021 16:45:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rzKl88Ka49hata7BwU6FTR9dOdQKrE4RB1z4nPi+Pbc=; b=4t/tLIuw/JO7Sw2yroPER1Rr7ngQOX6X0y9xjSCtgGtoFkQ6xYmtfW/K5U3/kdiso/ IrYdZMrTAW3t68mxn9w7JU6aTD8vIhz4ysGgjVKZUldd5Ziprpx9gOCUjMydyYG4z9+3 WRkc0d7M70YpDcQx75z1EClra1kiFK9hWILf/dLKsiR54AbzyIvcPCwC13fbXCslxgAa 60s2Ery6kIpPT7slk+NITPIzt8eMen6w0KuhZW5hjjOXgI0HNlJYqWpEj/OamUHncK8p M4oFGddCnTmUAxIxBxZavIVxGalZlZKTXbsMm3M7BeYF1MNIqMbSiLw8KizhvPR2DnX0 NG5A== X-Gm-Message-State: AOAM532Zrk79JEFwybsGdlgKg9fiyzUDQJ6oQqxb+i7Md6V0wy5YWJYc Km4+9tKSF79rutjjqy6axag= X-Google-Smtp-Source: ABdhPJxzM7njQCOa9pK4QLehOZKgin3NdTP4ZzNkZGPeyjzg3acOJDvFFyBXhPM3gFLn2ZnGsQnmtg== X-Received: by 2002:a63:e214:: with SMTP id q20mr9248959pgh.442.1636505120506; Tue, 09 Nov 2021 16:45:20 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:20 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Asutosh Das Subject: [PATCH 04/11] scsi: ufs: Remove dead code Date: Tue, 9 Nov 2021 16:44:33 -0800 Message-Id: <20211110004440.3389311-5-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Commit 7252a3603015 ("scsi: ufs: Avoid busy-waiting by eliminating tag conflicts") guarantees that 'tag' is not in use by any SCSI command. Remove the check that returns early if a conflict occurs. Signed-off-by: Bart Van Assche Acked-by: Avri Altman Reviewed-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index dff76b1a0d5d..312e8a5b7733 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6724,11 +6724,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, tag = req->tag; WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); - if (unlikely(test_bit(tag, &hba->outstanding_reqs))) { - err = -EBUSY; - goto out; - } - lrbp = &hba->lrb[tag]; WARN_ON(lrbp->cmd); lrbp->cmd = NULL; @@ -6796,7 +6791,6 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba *hba, ufshcd_add_query_upiu_trace(hba, err ? UFS_QUERY_ERR : UFS_QUERY_COMP, (struct utp_upiu_req *)lrbp->ucd_rsp_ptr); -out: blk_put_request(req); out_unlock: up_read(&hba->clk_scaling_lock); From patchwork Wed Nov 10 00:44:34 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: 12611227 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E8AEC433EF for ; Wed, 10 Nov 2021 00:45:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 487FB61181 for ; Wed, 10 Nov 2021 00:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbhKJAsK (ORCPT ); Tue, 9 Nov 2021 19:48:10 -0500 Received: from mail-pl1-f177.google.com ([209.85.214.177]:37398 "EHLO mail-pl1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231460AbhKJAsI (ORCPT ); Tue, 9 Nov 2021 19:48:08 -0500 Received: by mail-pl1-f177.google.com with SMTP id n8so1585698plf.4 for ; Tue, 09 Nov 2021 16:45:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g9s1fzRS+y58TYUG44MoMeeUMyJBoFAmA9RoI8sssXo=; b=JfhNtGmMJhsyZBdyFICpaSe+z9ueJN80/3EZO7TjTCoW0wXfLE9nh3yP3nH0LOh0xa GrpJ6iN4U54al6omjfjMk/eS6UNp4dWXjBy2hp+GTY7rmV8ZPDNh4xpaHcxzpJyJA9qd 68MNhYdK4YbOk3BmmfSMevxvJwQRggn0UlWyvFUHwkQ/lgc3pzI/ls/6eyEUr4aZHUHz f/QLtticpNfcA2e2FBxkZtsQN1TIdNarg/SD/huQNOBJawmscNLxoyjy00i66P+RLUqS WLkk6gP9ICcgr2xb1WsIyQ0BRL8H+11OIUEcjLaSjEW7gTdyjKwzzEzbIlzXEjXdpKQC AVLw== X-Gm-Message-State: AOAM531OzLz9Ai97NTUw0y0B290HEN/qbEFKtGBfhY8Otj3MrvwmNJ0E 0pJx9iEEzTyU9y+ZyQReinw= X-Google-Smtp-Source: ABdhPJzd4HO7rBuSn15ojw/93qYaB60qTTifenBH2awP8z421A7Fip9KjHvD2Fx3Tx0aqiIr+v3Lwg== X-Received: by 2002:a17:90a:ccb:: with SMTP id 11mr11983721pjt.121.1636505121892; Tue, 09 Nov 2021 16:45:21 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:21 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , Hannes Reinecke , John Garry , "James E.J. Bottomley" Subject: [PATCH 05/11] scsi: core: Add support for reserved tags Date: Tue, 9 Nov 2021 16:44:34 -0800 Message-Id: <20211110004440.3389311-6-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allow SCSI LLDs to allocate reserved tags by passing the BLK_MQ_REQ_RESERVED flag to blk_mq_alloc_request(). Cc: Hannes Reinecke Cc: John Garry Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 4 +++- include/scsi/scsi_host.h | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 43151e5d07ab..51d4ae1a5b16 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1916,6 +1916,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) { unsigned int cmd_size, sgl_size; struct blk_mq_tag_set *tag_set = &shost->tag_set; + unsigned int reserved_tags = shost->hostt->reserved_tags; sgl_size = max_t(unsigned int, sizeof(struct scatterlist), scsi_mq_inline_sgl_size(shost)); @@ -1931,7 +1932,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) tag_set->ops = &scsi_mq_ops_no_commit; tag_set->nr_hw_queues = shost->nr_hw_queues ? : 1; tag_set->nr_maps = shost->nr_maps ? : 1; - tag_set->queue_depth = shost->can_queue; + tag_set->queue_depth = shost->can_queue + reserved_tags; + tag_set->reserved_tags = reserved_tags; tag_set->cmd_size = cmd_size; tag_set->numa_node = NUMA_NO_NODE; tag_set->flags = BLK_MQ_F_SHOULD_MERGE; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index ebe059badba0..0fa3ee73501a 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -367,10 +367,17 @@ struct scsi_host_template { /* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number - * of simultaneous commands a single hw queue in HBA will accept. + * of simultaneous commands a single hw queue in HBA will accept. Does + * not include @reserved_tags. */ int can_queue; + /* + * Number of tags to reserve. A reserved tag can be allocated by passing + * the BLK_MQ_REQ_RESERVED flag to blk_get_request(). + */ + unsigned reserved_tags; + /* * In many instances, especially where disconnect / reconnect are * supported, our host also has an ID on the SCSI bus. If this is From patchwork Wed Nov 10 00:44:35 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: 12611229 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1AFCC433F5 for ; Wed, 10 Nov 2021 00:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA3AB61181 for ; Wed, 10 Nov 2021 00:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231383AbhKJAsO (ORCPT ); Tue, 9 Nov 2021 19:48:14 -0500 Received: from mail-pg1-f179.google.com ([209.85.215.179]:35405 "EHLO mail-pg1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231363AbhKJAsO (ORCPT ); Tue, 9 Nov 2021 19:48:14 -0500 Received: by mail-pg1-f179.google.com with SMTP id p17so652198pgj.2 for ; Tue, 09 Nov 2021 16:45:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cQqliRW2U5s6ay6ypy18/ZV7ufFIxagKVNHCjyhE7JY=; b=3Phhs6kNPAk+9jPaaA9jYXTV08ZoXGzqg68nwWEDc6+cFGy4rPB5wt6EtWG+ln4Dy7 JhP5YeKKJH+elQHwMORIfv5lDyOwjBgOk8w/0m0sy+oFB8AXpR25+aZwoly5/oYSybQD NvTOQQmxhHtVEqObay4V859cYsZQLra+Eg05HVihE4ndWzvmGgwpLG7y0NMBI2bLjoYD +8D3P40YYLCcU/+wCgHorfxg2UBJiIJqdaraGK4TSWspHmRsC1o2Wey3o/2ccRaXZ5yW hBwZfZXsUXaFwf+9PVjZQ5Lcv37g19aDQYk1+Nf/DDUzD+qoaTVV8W2BZWfmGjVS/A24 C6ag== X-Gm-Message-State: AOAM531FHZ4BvrOyejEbXehkEpGUFiRij0mYbh+kLATD30D5SsVsc8ue ndpYRFRA09GY0U+Boa4dsLo= X-Google-Smtp-Source: ABdhPJxIBX5KouKIsxdNuQHr+Qz7JRSez0tP7HJ81l+EH7Wfr9oeTGCEMPoddRyvSASz54SpdTMmZw== X-Received: by 2002:a63:4610:: with SMTP id t16mr4082126pga.224.1636505127154; Tue, 09 Nov 2021 16:45:27 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:26 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Asutosh Das Subject: [PATCH 06/11] scsi: ufs: Rework ufshcd_change_queue_depth() Date: Tue, 9 Nov 2021 16:44:35 -0800 Message-Id: <20211110004440.3389311-7-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for making sdev->host->can_queue less than hba->nutrs. This patch does not change any functionality. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 312e8a5b7733..8400d8e9a6f7 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4955,11 +4955,7 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev) */ static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth) { - struct ufs_hba *hba = shost_priv(sdev->host); - - if (depth > hba->nutrs) - depth = hba->nutrs; - return scsi_change_queue_depth(sdev, depth); + return scsi_change_queue_depth(sdev, min(depth, sdev->host->can_queue)); } static void ufshcd_hpb_destroy(struct ufs_hba *hba, struct scsi_device *sdev) From patchwork Wed Nov 10 00:44:36 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: 12611231 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A958C433EF for ; Wed, 10 Nov 2021 00:45:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D2B361181 for ; Wed, 10 Nov 2021 00:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbhKJAsU (ORCPT ); Tue, 9 Nov 2021 19:48:20 -0500 Received: from mail-pf1-f169.google.com ([209.85.210.169]:36848 "EHLO mail-pf1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKJAsT (ORCPT ); Tue, 9 Nov 2021 19:48:19 -0500 Received: by mail-pf1-f169.google.com with SMTP id m26so1050761pff.3 for ; Tue, 09 Nov 2021 16:45:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iFIfS0QH8F29Gihs4bJQA8uWnffYK0FxBrRaCfEbcdc=; b=fSeToTlLCU96scgWxirS6El8GaNTEcah5hG1BRZjXllj0Mk5ACS0BL3BE3iyY+OsR4 JFxTTk9tf7EmkZA+SRFD/tbyerMdhAcSeXkMag/mdA1JFMrSIyN0McZbai4KpsxOyoea 3/oe2vg+WWDkbfZyAKKi6aJnnbT8qFtk7tW9yZKwh/f0Zz7TFNgcop4bSyUO01FOPBhx 8NGiW+4LxWcaOiTxHXTv/gPhElvFAekZSy7h2nCKaAh2fUOoLlNe4DUFHOjG7Sijqz+3 CqsZt6ZO/MWD8ZAJue9Zc4OgjhArIoEz0Q7s/sSF0ceWD8Nncla8BGvy68tsdj2DCjV1 RB7A== X-Gm-Message-State: AOAM531EJA5rmvqJMbqLkUxJi6fqJKzstuIbixnYU+5gW4+ans0jTb70 ql4kjKJ0kYwbXB4LgLjqXh4= X-Google-Smtp-Source: ABdhPJy83AJSCnFJ4gP40DT+6BokCsClKjeSj6olB8tQIZM18PyQw0PKRGEo6c8lbP+DMWJ0dt0YZw== X-Received: by 2002:a63:950f:: with SMTP id p15mr9098808pgd.265.1636505132543; Tue, 09 Nov 2021 16:45:32 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:32 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Asutosh Das Subject: [PATCH 07/11] scsi: ufs: Fix a deadlock in the error handler Date: Tue, 9 Nov 2021 16:44:36 -0800 Message-Id: <20211110004440.3389311-8-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The following deadlock has been observed on a test setup: * All tags allocated. * The SCSI error handler calls ufshcd_eh_host_reset_handler() * ufshcd_eh_host_reset_handler() queues work that calls ufshcd_err_handler() * ufshcd_err_handler() locks up as follows: Workqueue: ufs_eh_wq_0 ufshcd_err_handler.cfi_jt Call trace: __switch_to+0x298/0x5d8 __schedule+0x6cc/0xa94 schedule+0x12c/0x298 blk_mq_get_tag+0x210/0x480 __blk_mq_alloc_request+0x1c8/0x284 blk_get_request+0x74/0x134 ufshcd_exec_dev_cmd+0x68/0x640 ufshcd_verify_dev_init+0x68/0x35c ufshcd_probe_hba+0x12c/0x1cb8 ufshcd_host_reset_and_restore+0x88/0x254 ufshcd_reset_and_restore+0xd0/0x354 ufshcd_err_handler+0x408/0xc58 process_one_work+0x24c/0x66c worker_thread+0x3e8/0xa4c kthread+0x150/0x1b4 ret_from_fork+0x10/0x30 Fix this lockup by making ufshcd_exec_dev_cmd() allocate a reserved request. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8400d8e9a6f7..8f5640647054 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2940,12 +2940,7 @@ static int ufshcd_exec_dev_cmd(struct ufs_hba *hba, down_read(&hba->clk_scaling_lock); - /* - * Get free slot, sleep if slots are unavailable. - * Even though we use wait_event() which sleeps indefinitely, - * the maximum wait time is bounded by SCSI request timeout. - */ - req = blk_get_request(q, REQ_OP_DRV_OUT, 0); + req = blk_mq_alloc_request(q, REQ_OP_DRV_OUT, BLK_MQ_REQ_RESERVED); if (IS_ERR(req)) { err = PTR_ERR(req); goto out_unlock; @@ -8152,7 +8147,8 @@ static struct scsi_host_template ufshcd_driver_template = { .this_id = -1, .sg_tablesize = SG_ALL, .cmd_per_lun = UFSHCD_CMD_PER_LUN, - .can_queue = UFSHCD_CAN_QUEUE, + .can_queue = UFSHCD_CAN_QUEUE - 1, + .reserved_tags = 1, .max_segment_size = PRDT_DATA_BYTE_COUNT_MAX, .max_host_blocked = 1, .track_queue_depth = 1, @@ -9513,8 +9509,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) /* Configure LRB */ ufshcd_host_memory_configure(hba); - host->can_queue = hba->nutrs; - host->cmd_per_lun = hba->nutrs; + host->can_queue = hba->nutrs - 1; + host->cmd_per_lun = hba->nutrs - 1; host->max_id = UFSHCD_MAX_ID; host->max_lun = UFS_MAX_LUNS; host->max_channel = UFSHCD_MAX_CHANNEL; From patchwork Wed Nov 10 00:44:37 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: 12611233 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9C6EC433EF for ; Wed, 10 Nov 2021 00:45:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1379611CA for ; Wed, 10 Nov 2021 00:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbhKJAsZ (ORCPT ); Tue, 9 Nov 2021 19:48:25 -0500 Received: from mail-pj1-f52.google.com ([209.85.216.52]:46796 "EHLO mail-pj1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKJAsY (ORCPT ); Tue, 9 Nov 2021 19:48:24 -0500 Received: by mail-pj1-f52.google.com with SMTP id f20-20020a17090a639400b001a772f524d1so127348pjj.5 for ; Tue, 09 Nov 2021 16:45:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gPm9jvo2dQ97h1ECFHAf5oFx5mwjgZ3vxFaLaNSKiNY=; b=t1ImWJfcs8x2JY9OYuHEkoS3pgIQm/OsIh2xSNJ5hQplunlnuCYbLLEGS2IOml38IF 4CGKSxyWhF9NBY0wWWyYAjxkO+2Gw+FcelvylqxcsRiaiwd7KSYqB7+Gu3dnEu8AbnrP 2H0P1Zw+m3pt1bBnAM13PW9t8ka2Bv9pxQZBhKYl6u2SUsFP+snHv+5VIaQDyGg0RUR+ kPmnjO4hixtNG04+TkvmqLit+rt3J7ZrnXzPpxFO9nLnRvQgX/dZOGkEPKqjxs0cveaE 6VpXQlT6sjN7UAXFZSEewUzy7Df+zlA3E9tYJumv7+YiOGHAPuTK/4LFt4IGAlTRDvfl D0jw== X-Gm-Message-State: AOAM531lc3DSp1Q2V8lMHlYxGoyJcyrp4XAjrAi2TFc5ppurWWJZFlQs HjGff0A0UpDB8DLenZJ4/Mc= X-Google-Smtp-Source: ABdhPJxNHq3fhlpXdRt7S/MGSFFnRgbHgDFou5jiHt9dE3OV2KSLmFm8cf7KL3MEGOklGDxQS/qehQ== X-Received: by 2002:a17:90b:4a50:: with SMTP id lb16mr12208949pjb.147.1636505138007; Tue, 09 Nov 2021 16:45:38 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:37 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Asutosh Das , James Bottomley , Santosh Yaraganavi , Arnd Bergmann , Vishak G Subject: [PATCH 08/11] scsi: ufs: Improve SCSI abort handling further Date: Tue, 9 Nov 2021 16:44:37 -0800 Message-Id: <20211110004440.3389311-9-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make sure that aborted commands are completed once by clearing the corresponding tag bit from hba->outstanding_reqs. This patch is a follow-up for commit cd892096c940 ("scsi: ufs: core: Improve SCSI abort handling"). Fixes: 7a3e97b0dc4b ("[SCSI] ufshcd: UFS Host controller driver") Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 8f5640647054..1e15ed1f639f 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -7090,6 +7090,15 @@ static int ufshcd_abort(struct scsi_cmnd *cmd) goto release; } + /* + * ufshcd_try_to_abort_task() cleared the 'tag' bit in the doorbell + * register. Clear the corresponding bit from outstanding_reqs to + * prevent early completion. + */ + spin_lock_irqsave(&hba->outstanding_lock, flags); + __clear_bit(tag, &hba->outstanding_reqs); + spin_unlock_irqrestore(&hba->outstanding_lock, flags); + lrbp->cmd = NULL; err = SUCCESS; From patchwork Wed Nov 10 00:44:38 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: 12611235 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5BB8C433F5 for ; Wed, 10 Nov 2021 00:45:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8921A61184 for ; Wed, 10 Nov 2021 00:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbhKJAsb (ORCPT ); Tue, 9 Nov 2021 19:48:31 -0500 Received: from mail-pl1-f169.google.com ([209.85.214.169]:39498 "EHLO mail-pl1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKJAsa (ORCPT ); Tue, 9 Nov 2021 19:48:30 -0500 Received: by mail-pl1-f169.google.com with SMTP id t21so1570464plr.6 for ; Tue, 09 Nov 2021 16:45:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8OTrU3GYFu3CL1REgFDh5Hbm8EDgLqeuKAhDQBFGAlg=; b=V5zBxGJa3BCnLnDmNpjdp2lo+DwC5LYNBxaHu+yGeyg6PS8nGfqtawrjfi6iTFJcf0 qRUM8IcaFyaD/psCD97IJ0D2P9zTzz/wKTPUofLuBogUezqZ0t6yYa7vdNhLyEsDfpD5 KUK4N7L/9qs9m97GKI+cFJgfHuEO88/7byVJ1QCsa56eFwVrtP0Q3ACxWXNYOSpxakIn kcm94ZSngJU8ZD/sEfetbwFfuuBvz7aLyFVZ5tqFMmoTAN+MNCenSxtvvFROI4ufb57b WUTQzWk0IgvVLSxillQxbLXCTbJfdl6/IIzPPhoTunVaYVaw5oM3qzQCFi9PezxK+4g9 Bfcw== X-Gm-Message-State: AOAM533FsYnAp5TL9f1WbDZv4YrI045bS3sNCBjwYCqP2uWm1LrJn2Jr zz5IRLIdq2dm8BciaY5QbZA= X-Google-Smtp-Source: ABdhPJxNUtCMwwPH0g400aI1MxFryurjCF9pzxgO+ctxtxCy+J/yVxyHQvrObDMV4H4MqaYTIHghFg== X-Received: by 2002:a17:902:c404:b0:142:28c5:5416 with SMTP id k4-20020a170902c40400b0014228c55416mr11989508plk.62.1636505143330; Tue, 09 Nov 2021 16:45:43 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:42 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Avri Altman , Asutosh Das Subject: [PATCH 09/11] scsi: ufs: Fix a kernel crash during shutdown Date: Tue, 9 Nov 2021 16:44:38 -0800 Message-Id: <20211110004440.3389311-10-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Fix the following kernel crash: Unable to handle kernel paging request at virtual address ffffffc91e735000 Call trace: __queue_work+0x26c/0x624 queue_work_on+0x6c/0xf0 ufshcd_hold+0x12c/0x210 __ufshcd_wl_suspend+0xc0/0x400 ufshcd_wl_shutdown+0xb8/0xcc device_shutdown+0x184/0x224 kernel_restart+0x4c/0x124 __arm64_sys_reboot+0x194/0x264 el0_svc_common+0xc8/0x1d4 do_el0_svc+0x30/0x8c el0_svc+0x20/0x30 el0_sync_handler+0x84/0xe4 el0_sync+0x1bc/0x1c0 Fix this crash by ungating the clock before destroying the work queue on which clock gating work is queued. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1e15ed1f639f..13848e93cda8 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1666,7 +1666,8 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) bool flush_result; unsigned long flags; - if (!ufshcd_is_clkgating_allowed(hba)) + if (!ufshcd_is_clkgating_allowed(hba) || + !hba->clk_gating.is_initialized) goto out; spin_lock_irqsave(hba->host->host_lock, flags); hba->clk_gating.active_reqs++; @@ -1826,7 +1827,7 @@ static void __ufshcd_release(struct ufs_hba *hba) if (hba->clk_gating.active_reqs || hba->clk_gating.is_suspended || hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL || - hba->outstanding_tasks || + hba->outstanding_tasks || !hba->clk_gating.is_initialized || hba->active_uic_cmd || hba->uic_async_done || hba->clk_gating.state == CLKS_OFF) return; @@ -1961,11 +1962,15 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba) { if (!hba->clk_gating.is_initialized) return; + ufshcd_remove_clk_gating_sysfs(hba); - cancel_work_sync(&hba->clk_gating.ungate_work); - cancel_delayed_work_sync(&hba->clk_gating.gate_work); - destroy_workqueue(hba->clk_gating.clk_gating_workq); + + /* Ungate the clock if necessary. */ + ufshcd_hold(hba, false); hba->clk_gating.is_initialized = false; + ufshcd_release(hba); + + destroy_workqueue(hba->clk_gating.clk_gating_workq); } /* Must be called with host lock acquired */ From patchwork Wed Nov 10 00:44:39 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: 12611237 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EB31C433F5 for ; Wed, 10 Nov 2021 00:45:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E88A761186 for ; Wed, 10 Nov 2021 00:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbhKJAsj (ORCPT ); Tue, 9 Nov 2021 19:48:39 -0500 Received: from mail-pj1-f54.google.com ([209.85.216.54]:39748 "EHLO mail-pj1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhKJAsj (ORCPT ); Tue, 9 Nov 2021 19:48:39 -0500 Received: by mail-pj1-f54.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so303746pjc.4 for ; Tue, 09 Nov 2021 16:45:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vcopxjIJAsx605lA2hzu0wTuKoBsdX+3qInjC3qG5IQ=; b=GVbf/faA48w59XKYQLaaJeZSJxkkCwnX+uLO2x+haIzYeUVK0KMwQBAP/sQVoxsd4I u2OsZyi5oNp/ntxv09PHbQcDvLcnjVNObOI6rgHa4x2dZ/SJ66+MZN6qOd0AxlNXSA5e tKtSc8jP7a3q+uied2ImSyyketpXD1b+QiKVXp0QlryYEe8ZzJRLJf+/5zrwDoKdceld 4VtG2tEDJ3F16mQrChXmFZXKl8pmHHFJ6RdIDgehxDV5QlmwdQH8dhxpS3n/fAw9B6J0 MvYTnUzTBieBY7R/epMY7u1F2yIMHjXkxbEds0K6ugOrw3urY7oIOI9vtoT8wQGG8NTV Y/PQ== X-Gm-Message-State: AOAM530HVTrlSCPAz1n+T0aJv3zIEaWcgWVAa6YQKzvtjGPJRciVXV8K 757ToK9JkzlIdhfiWjMZccoUB2+nFCRlZA== X-Google-Smtp-Source: ABdhPJwgz8vrEcZ53li7dre7TClEp1PgD05Ims/ZkjG17jTB72DEVxdHzXoueRVED/ltjDF7BrXlPQ== X-Received: by 2002:a17:90a:bf0b:: with SMTP id c11mr12122825pjs.208.1636505152174; Tue, 09 Nov 2021 16:45:52 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:51 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Avri Altman , Asutosh Das , Keoseong Park Subject: [PATCH 10/11] scsi: ufs: Optimize the command queueing code Date: Tue, 9 Nov 2021 16:44:39 -0800 Message-Id: <20211110004440.3389311-11-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Remove the clock scaling lock from ufshcd_queuecommand() since it is a performance bottleneck. As requested by Asutosh Das, change the behavior of ufshcd_clock_scaling_prepare() from waiting until all pending commands have finished into quiescing request queues. Insert a rcu_read_lock() / rcu_read_unlock() pair in ufshcd_queuecommand() and also in __ufshcd_issue_tm_cmd(). Use synchronize_rcu_expedited() to wait for ongoing command and TMF queueing. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 121 +++++++++++++------------------------- drivers/scsi/ufs/ufshcd.h | 1 + 2 files changed, 42 insertions(+), 80 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 13848e93cda8..36df89e8a575 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1069,65 +1069,6 @@ static bool ufshcd_is_devfreq_scaling_required(struct ufs_hba *hba, return false; } -static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, - u64 wait_timeout_us) -{ - unsigned long flags; - int ret = 0; - u32 tm_doorbell; - u32 tr_doorbell; - bool timeout = false, do_last_check = false; - ktime_t start; - - ufshcd_hold(hba, false); - spin_lock_irqsave(hba->host->host_lock, flags); - /* - * Wait for all the outstanding tasks/transfer requests. - * Verify by checking the doorbell registers are clear. - */ - start = ktime_get(); - do { - if (hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL) { - ret = -EBUSY; - goto out; - } - - tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL); - tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); - if (!tm_doorbell && !tr_doorbell) { - timeout = false; - break; - } else if (do_last_check) { - break; - } - - spin_unlock_irqrestore(hba->host->host_lock, flags); - schedule(); - if (ktime_to_us(ktime_sub(ktime_get(), start)) > - wait_timeout_us) { - timeout = true; - /* - * We might have scheduled out for long time so make - * sure to check if doorbells are cleared by this time - * or not. - */ - do_last_check = true; - } - spin_lock_irqsave(hba->host->host_lock, flags); - } while (tm_doorbell || tr_doorbell); - - if (timeout) { - dev_err(hba->dev, - "%s: timedout waiting for doorbell to clear (tm=0x%x, tr=0x%x)\n", - __func__, tm_doorbell, tr_doorbell); - ret = -EBUSY; - } -out: - spin_unlock_irqrestore(hba->host->host_lock, flags); - ufshcd_release(hba); - return ret; -} - /** * ufshcd_scale_gear - scale up/down UFS gear * @hba: per adapter instance @@ -1175,37 +1116,51 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up) static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) { - #define DOORBELL_CLR_TOUT_US (1000 * 1000) /* 1 sec */ - int ret = 0; + struct scsi_device *sdev; + /* - * make sure that there are no outstanding requests when - * clock scaling is in progress + * Make sure that no commands are being queued while clock scaling + * is in progress. + * + * Since ufshcd_exec_dev_cmd() and ufshcd_issue_devman_upiu_cmd() lock + * the clk_scaling_lock before calling blk_get_request(), lock + * clk_scaling_lock before freezing the request queues to prevent lock + * inversion. */ - ufshcd_scsi_block_requests(hba); down_write(&hba->clk_scaling_lock); - - if (!hba->clk_scaling.is_allowed || - ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { - ret = -EBUSY; + if (!hba->clk_scaling.is_allowed) { up_write(&hba->clk_scaling_lock); - ufshcd_scsi_unblock_requests(hba); - goto out; + return -EBUSY; } - + blk_mq_quiesce_queue_nowait(hba->tmf_queue); + blk_mq_quiesce_queue_nowait(hba->cmd_queue); + shost_for_each_device(sdev, hba->host) + blk_mq_quiesce_queue_nowait(sdev->request_queue); + /* + * Calling synchronize_rcu_expedited() reduces the time required to + * quiesce request queues from milliseconds to microseconds. + * + * See also the rcu_read_lock() and rcu_read_unlock() calls in + * ufshcd_queuecommand() and also in __ufshcd_issue_tm_cmd(). + */ + synchronize_rcu_expedited(); /* let's not get into low power until clock scaling is completed */ ufshcd_hold(hba, false); - -out: - return ret; + return 0; } static void ufshcd_clock_scaling_unprepare(struct ufs_hba *hba, bool writelock) { + struct scsi_device *sdev; + + shost_for_each_device(sdev, hba->host) + blk_mq_unquiesce_queue(sdev->request_queue); + blk_mq_unquiesce_queue(hba->cmd_queue); + blk_mq_unquiesce_queue(hba->tmf_queue); if (writelock) up_write(&hba->clk_scaling_lock); else up_read(&hba->clk_scaling_lock); - ufshcd_scsi_unblock_requests(hba); ufshcd_release(hba); } @@ -2698,8 +2653,11 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) WARN_ONCE(tag < 0, "Invalid tag %d\n", tag); - if (!down_read_trylock(&hba->clk_scaling_lock)) - return SCSI_MLQUEUE_HOST_BUSY; + /* + * Allows ufshcd_clock_scaling_prepare() and also the UFS error handler + * to wait for prior ufshcd_queuecommand() calls. + */ + rcu_read_lock(); switch (hba->ufshcd_state) { case UFSHCD_STATE_OPERATIONAL: @@ -2780,7 +2738,7 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) ufshcd_send_command(hba, tag); out: - up_read(&hba->clk_scaling_lock); + rcu_read_unlock(); if (ufs_trigger_eh()) { unsigned long flags; @@ -5977,8 +5935,7 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba) } ufshcd_scsi_block_requests(hba); /* Drain ufshcd_queuecommand() */ - down_write(&hba->clk_scaling_lock); - up_write(&hba->clk_scaling_lock); + synchronize_rcu(); cancel_work_sync(&hba->eeh_work); } @@ -6582,6 +6539,8 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba, req->end_io_data = &wait; ufshcd_hold(hba, false); + rcu_read_lock(); + spin_lock_irqsave(host->host_lock, flags); task_tag = req->tag; @@ -6600,6 +6559,8 @@ static int __ufshcd_issue_tm_cmd(struct ufs_hba *hba, spin_unlock_irqrestore(host->host_lock, flags); + rcu_read_unlock(); + ufshcd_add_tm_upiu_trace(hba, task_tag, UFS_TM_SEND); /* wait until the task management command is completed */ diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 65178487adf3..7afe818ab1e3 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -778,6 +778,7 @@ struct ufs_hba_monitor { * @clk_list_head: UFS host controller clocks list node head * @pwr_info: holds current power mode * @max_pwr_info: keeps the device max valid pwm + * @clk_scaling_lock: used to serialize device commands and clock scaling * @desc_size: descriptor sizes reported by device * @urgent_bkops_lvl: keeps track of urgent bkops level for device * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops level for From patchwork Wed Nov 10 00:44:40 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: 12611239 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8C0AC433F5 for ; Wed, 10 Nov 2021 00:45:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A2DB61186 for ; Wed, 10 Nov 2021 00:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231431AbhKJAsp (ORCPT ); Tue, 9 Nov 2021 19:48:45 -0500 Received: from mail-pg1-f177.google.com ([209.85.215.177]:39846 "EHLO mail-pg1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231405AbhKJAso (ORCPT ); Tue, 9 Nov 2021 19:48:44 -0500 Received: by mail-pg1-f177.google.com with SMTP id g184so635840pgc.6 for ; Tue, 09 Nov 2021 16:45:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DXgDe1+Dztca8AnvzuiNKtcmsU9O3EaaKYEgt6dr/+c=; b=PMMor+AedtF7rI58ujm3mg/SmZgyBqiDw2/wJWytuPiWebu1SNabk8rqoGVIig8SnJ c/UtspkrDuR+CM8omo9UQ9GpELcumXe9PaN5/B/Hv46pGiKG+0HPmMva+sXmlWfnrlqt IWQAz4XGoxgN+RQ2uFUwdU06FuxDOPOCQ5GcRVFf366jvxR9YZi/c4hEMumjc/9JeVs7 9gXb2UlY4+ZpDXZ+qqFSj4HjncUOSVmwMkkhen+f99xxxRs5sOsgbJaisZVPeJhj8EU1 QI4sEwCXHGhO7R4ci6S6EzGfYvu4QA7b9Td3SKNqoH08tlEqoQY7ic3IlVUVQ8PodKi+ MARw== X-Gm-Message-State: AOAM530+b7Hk6mKQWZrmP2TpcE8sQ9ouA0oiCLqrEq605ABvvsl90iUq +TcEgVsxuKtP9ZHGr5N7RpA= X-Google-Smtp-Source: ABdhPJyu5jkWq5iVhRipJo4YYw8hDv6DrxXDVvzXNo2p2uGES7wY5AHhr9W3z2hd+G9ybL4pGLkVAA== X-Received: by 2002:a62:31c5:0:b0:447:cd37:61f8 with SMTP id x188-20020a6231c5000000b00447cd3761f8mr95464562pfx.29.1636505157524; Tue, 09 Nov 2021 16:45:57 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a582:6939:6a97:9cbf]) by smtp.gmail.com with ESMTPSA id l17sm21868826pfc.94.2021.11.09.16.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 16:45:57 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Can Guo , Stanley Chu , Avri Altman , Asutosh Das Subject: [PATCH 11/11] scsi: ufs: Implement polling support Date: Tue, 9 Nov 2021 16:44:40 -0800 Message-Id: <20211110004440.3389311-12-bvanassche@acm.org> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog In-Reply-To: <20211110004440.3389311-1-bvanassche@acm.org> References: <20211110004440.3389311-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The time spent in io_schedule() is significant when submitting direct I/O to a UFS device. Hence this patch that implements polling support. User space software can enable polling by passing the RWF_HIPRI flag to the preadv2() system call or the IORING_SETUP_IOPOLL flag to the io_uring interface. Signed-off-by: Bart Van Assche --- drivers/scsi/ufs/ufshcd.c | 45 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 36df89e8a575..70f128f12445 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -5250,6 +5250,31 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, } } +/* + * Returns > 0 if one or more commands have been completed or 0 if no + * requests have been completed. + */ +static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) +{ + struct ufs_hba *hba = shost_priv(shost); + unsigned long completed_reqs, flags; + u32 tr_doorbell; + + spin_lock_irqsave(&hba->outstanding_lock, flags); + tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); + completed_reqs = ~tr_doorbell & hba->outstanding_reqs; + WARN_ONCE(completed_reqs & ~hba->outstanding_reqs, + "completed: %#lx; outstanding: %#lx\n", completed_reqs, + hba->outstanding_reqs); + hba->outstanding_reqs &= ~completed_reqs; + spin_unlock_irqrestore(&hba->outstanding_lock, flags); + + if (completed_reqs) + __ufshcd_transfer_req_compl(hba, completed_reqs); + + return completed_reqs; +} + /** * ufshcd_transfer_req_compl - handle SCSI and query command completion * @hba: per adapter instance @@ -5260,9 +5285,6 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba, */ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba) { - unsigned long completed_reqs, flags; - u32 tr_doorbell; - /* Resetting interrupt aggregation counters first and reading the * DOOR_BELL afterward allows us to handle all the completed requests. * In order to prevent other interrupts starvation the DB is read once @@ -5277,21 +5299,7 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba) if (ufs_fail_completion()) return IRQ_HANDLED; - spin_lock_irqsave(&hba->outstanding_lock, flags); - tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); - completed_reqs = ~tr_doorbell & hba->outstanding_reqs; - WARN_ONCE(completed_reqs & ~hba->outstanding_reqs, - "completed: %#lx; outstanding: %#lx\n", completed_reqs, - hba->outstanding_reqs); - hba->outstanding_reqs &= ~completed_reqs; - spin_unlock_irqrestore(&hba->outstanding_lock, flags); - - if (completed_reqs) { - __ufshcd_transfer_req_compl(hba, completed_reqs); - return IRQ_HANDLED; - } else { - return IRQ_NONE; - } + return ufshcd_poll(hba->host, 0) ? IRQ_HANDLED : IRQ_NONE; } int __ufshcd_write_ee_control(struct ufs_hba *hba, u32 ee_ctrl_mask) @@ -8112,6 +8120,7 @@ static struct scsi_host_template ufshcd_driver_template = { .name = UFSHCD, .proc_name = UFSHCD, .queuecommand = ufshcd_queuecommand, + .mq_poll = ufshcd_poll, .slave_alloc = ufshcd_slave_alloc, .slave_configure = ufshcd_slave_configure, .slave_destroy = ufshcd_slave_destroy,