From patchwork Wed Nov 21 16:23:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10692791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A835314BD for ; Wed, 21 Nov 2018 16:24:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9911C2C1D7 for ; Wed, 21 Nov 2018 16:24:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 977A82C30A; Wed, 21 Nov 2018 16:24:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B19C2C1D7 for ; Wed, 21 Nov 2018 16:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731716AbeKVC7U (ORCPT ); Wed, 21 Nov 2018 21:59:20 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:36796 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730375AbeKVC7T (ORCPT ); Wed, 21 Nov 2018 21:59:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gcpcUN0krZCHJ2SUEqt3nNSAu1yTmINktXWfQh7vZMc=; b=Ae2OH0mfQ3SuAzRaDCx7hMk4+5 17Q4BG5X8fIWmB/TgbEhd2w/AzF1JQZ4eLMU+v9tBdQpTzZ8jOZZDO0TPvv8ibT0Z/NkqACHxBDir ttaVlA6pGp51wgsRdUsBXnK1IATaUFdbkJamKIRQ9Y/zf4hA6r9U7paTvXRpQuSb6BVTvY+U2OR9K dznpLZRnQ3Pu9JK2RsQzgpZAEIN6+snjfUA3DeIaQAVBKunVgNVY4Ge75UXtg1ChmNyQkHaiIrBgA Jcmu8Fkio2tX69gPQ47UvToZXzkyhZa695EbMFsW9dAUP+I+21hMqcEyAsZ0+a/m8i1Bz09I/Bb7T 5M4ZRAkw==; Received: from 089144201193.atnat0010.highway.a1.net ([89.144.201.193] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPVIM-00033n-Ou; Wed, 21 Nov 2018 16:24:07 +0000 From: Christoph Hellwig To: Jens Axboe , Keith Busch , Sagi Grimberg Cc: Max Gurtovoy , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 06/13] nvme-pci: refactor nvme_disable_io_queues Date: Wed, 21 Nov 2018 17:23:40 +0100 Message-Id: <20181121162347.17430-7-hch@lst.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181121162347.17430-1-hch@lst.de> References: <20181121162347.17430-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Pass the opcode for the delete SQ/CQ command as an argument instead of the somewhat confusing pass loop. Signed-off-by: Christoph Hellwig --- drivers/nvme/host/pci.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 2965e4bb4e41..29072ad0a268 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2213,31 +2213,29 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode) return 0; } -static void nvme_disable_io_queues(struct nvme_dev *dev) +static bool nvme_disable_io_queues(struct nvme_dev *dev, u8 opcode) { - int pass, queues = dev->online_queues - 1; + int nr_queues = dev->online_queues - 1, sent = 0; unsigned long timeout; - u8 opcode = nvme_admin_delete_sq; - for (pass = 0; pass < 2; pass++) { - int sent = 0, i = queues; - - reinit_completion(&dev->ioq_wait); + reinit_completion(&dev->ioq_wait); retry: - timeout = ADMIN_TIMEOUT; - for (; i > 0; i--, sent++) - if (nvme_delete_queue(&dev->queues[i], opcode)) - break; - - while (sent--) { - timeout = wait_for_completion_io_timeout(&dev->ioq_wait, timeout); - if (timeout == 0) - return; - if (i) - goto retry; - } - opcode = nvme_admin_delete_cq; + timeout = ADMIN_TIMEOUT; + while (nr_queues > 0) { + if (nvme_delete_queue(&dev->queues[nr_queues], opcode)) + break; + nr_queues--; + sent++; } + while (sent--) { + timeout = wait_for_completion_io_timeout(&dev->ioq_wait, + timeout); + if (timeout == 0) + return false; + if (nr_queues) + goto retry; + } + return true; } /* @@ -2397,7 +2395,8 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown) nvme_stop_queues(&dev->ctrl); if (!dead && dev->ctrl.queue_count > 0) { - nvme_disable_io_queues(dev); + if (nvme_disable_io_queues(dev, nvme_admin_delete_sq)) + nvme_disable_io_queues(dev, nvme_admin_delete_cq); nvme_disable_admin_queue(dev, shutdown); } for (i = dev->ctrl.queue_count - 1; i >= 0; i--)