All of lore.kernel.org
 help / color / mirror / Atom feed
From: aaron.ma@canonical.com (Aaron Ma)
Subject: [PATCH] nvme: determine the number of IO queues
Date: Wed, 17 Apr 2019 22:12:59 +0800	[thread overview]
Message-ID: <1555510379-20199-1-git-send-email-aaron.ma@canonical.com> (raw)

Some controllers support limited IO queues, when over set
the number, it will return invalid field error.
Then NVME will be removed by driver.

Find the max number of IO queues that controller supports.
When it still got invalid result, set 1 IO queue at least to
bring NVME online.

Signed-off-by: Aaron Ma <aaron.ma at canonical.com>
---
 drivers/nvme/host/core.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2c43e12b70af..fb7f05c310c8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1134,14 +1134,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword
 
 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)
 {
-	u32 q_count = (*count - 1) | ((*count - 1) << 16);
+	u32 q_count;
 	u32 result;
-	int status, nr_io_queues;
-
-	status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0,
-			&result);
-	if (status < 0)
-		return status;
+	int status = -1;
+	int nr_io_queues;
+	int try_count;
+
+	for (try_count = *count; try_count > 0; try_count--) {
+		q_count = (try_count - 1) | ((try_count - 1) << 16);
+		status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES,
+				q_count, NULL, 0, &result);
+		if (status < 0)
+			return status;
+		else if (status == 0) {
+			nr_io_queues = min(result & 0xffff, result >> 16) + 1;
+			*count = min(try_count, nr_io_queues);
+			break;
+		}
+	}
 
 	/*
 	 * Degraded controllers might return an error when setting the queue
@@ -1150,10 +1160,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)
 	 */
 	if (status > 0) {
 		dev_err(ctrl->device, "Could not set queue count (%d)\n", status);
-		*count = 0;
-	} else {
-		nr_io_queues = min(result & 0xffff, result >> 16) + 1;
-		*count = min(*count, nr_io_queues);
+		*count = 1;
 	}
 
 	return 0;
-- 
2.20.1

WARNING: multiple messages have this Message-ID (diff)
From: Aaron Ma <aaron.ma@canonical.com>
To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org,
	keith.busch@intel.com, axboe@fb.com, aaron.ma@canonical.com
Subject: [PATCH] nvme: determine the number of IO queues
Date: Wed, 17 Apr 2019 22:12:59 +0800	[thread overview]
Message-ID: <1555510379-20199-1-git-send-email-aaron.ma@canonical.com> (raw)

Some controllers support limited IO queues, when over set
the number, it will return invalid field error.
Then NVME will be removed by driver.

Find the max number of IO queues that controller supports.
When it still got invalid result, set 1 IO queue at least to
bring NVME online.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/nvme/host/core.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2c43e12b70af..fb7f05c310c8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1134,14 +1134,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword
 
 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)
 {
-	u32 q_count = (*count - 1) | ((*count - 1) << 16);
+	u32 q_count;
 	u32 result;
-	int status, nr_io_queues;
-
-	status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0,
-			&result);
-	if (status < 0)
-		return status;
+	int status = -1;
+	int nr_io_queues;
+	int try_count;
+
+	for (try_count = *count; try_count > 0; try_count--) {
+		q_count = (try_count - 1) | ((try_count - 1) << 16);
+		status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES,
+				q_count, NULL, 0, &result);
+		if (status < 0)
+			return status;
+		else if (status == 0) {
+			nr_io_queues = min(result & 0xffff, result >> 16) + 1;
+			*count = min(try_count, nr_io_queues);
+			break;
+		}
+	}
 
 	/*
 	 * Degraded controllers might return an error when setting the queue
@@ -1150,10 +1160,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)
 	 */
 	if (status > 0) {
 		dev_err(ctrl->device, "Could not set queue count (%d)\n", status);
-		*count = 0;
-	} else {
-		nr_io_queues = min(result & 0xffff, result >> 16) + 1;
-		*count = min(*count, nr_io_queues);
+		*count = 1;
 	}
 
 	return 0;
-- 
2.20.1


             reply	other threads:[~2019-04-17 14:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-17 14:12 Aaron Ma [this message]
2019-04-17 14:12 ` [PATCH] nvme: determine the number of IO queues Aaron Ma
2019-04-17 17:32 ` Maxim Levitsky
2019-04-17 17:32   ` Maxim Levitsky
2019-04-17 17:33   ` Maxim Levitsky
2019-04-17 17:33     ` Maxim Levitsky
2019-04-18  6:21     ` Aaron Ma
2019-04-18  6:21       ` Aaron Ma
2019-04-18  7:25       ` Maxim Levitsky
2019-04-18  7:25         ` Maxim Levitsky
2019-04-18 12:13       ` Minwoo Im
2019-04-18 12:13         ` Minwoo Im
2019-04-18 12:52         ` Aaron Ma
2019-04-18 12:52           ` Aaron Ma
2019-04-18 13:33           ` Minwoo Im
2019-04-18 13:33             ` Minwoo Im
2019-04-18 13:38             ` Aaron Ma
2019-04-18 13:38               ` Aaron Ma
2019-04-18 13:58               ` Minwoo Im
2019-04-18 13:58                 ` Minwoo Im
2019-04-18 13:48       ` Keith Busch
2019-04-18 13:48         ` Keith Busch
2019-04-18 14:21         ` Aaron Ma
2019-04-18 14:21           ` Aaron Ma
2019-04-25 14:39           ` Christoph Hellwig
2019-04-25 14:39             ` Christoph Hellwig
2019-04-26  5:27             ` Aaron Ma
2019-04-26  5:27               ` Aaron Ma
2019-04-17 21:30 ` Edmund Nadolski (Microsoft)
2019-04-17 21:30   ` Edmund Nadolski (Microsoft)
2019-04-18  6:24   ` Aaron Ma
2019-04-18  6:24     ` Aaron Ma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1555510379-20199-1-git-send-email-aaron.ma@canonical.com \
    --to=aaron.ma@canonical.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.