public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
	James Smart <james.smart@broadcom.com>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 01/13] nvme: add common helpers to allocate and free tagsets
Date: Tue, 20 Sep 2022 19:15:59 +0200	[thread overview]
Message-ID: <20220920171611.1289361-2-hch@lst.de> (raw)
In-Reply-To: <20220920171611.1289361-1-hch@lst.de>

Add common helpers to allocate and tear down the admin and I/O tag sets,
including the special queues allocated with them.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/host/core.c | 100 +++++++++++++++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h |   8 ++++
 2 files changed, 108 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 8c9c1176624da..f8d9f32adc87c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4800,6 +4800,106 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 }
 EXPORT_SYMBOL_GPL(nvme_complete_async_event);
 
+int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
+		const struct blk_mq_ops *ops, unsigned int flags,
+		unsigned int cmd_size)
+{
+	int ret;
+
+	memset(set, 0, sizeof(*set));
+	set->ops = ops;
+	set->queue_depth = NVME_AQ_MQ_TAG_DEPTH;
+	if (ctrl->ops->flags & NVME_F_FABRICS)
+		set->reserved_tags = NVMF_RESERVED_TAGS;
+	set->numa_node = ctrl->numa_node;
+	set->flags = flags;
+	set->cmd_size = cmd_size;
+	set->driver_data = ctrl;
+	set->nr_hw_queues = 1;
+	set->timeout = NVME_ADMIN_TIMEOUT;
+	ret = blk_mq_alloc_tag_set(set);
+	if (ret)
+		return ret;
+
+	ctrl->admin_q = blk_mq_init_queue(set);
+	if (IS_ERR(ctrl->admin_q)) {
+		ret = PTR_ERR(ctrl->admin_q);
+		goto out_free_tagset;
+	}
+
+	if (ctrl->ops->flags & NVME_F_FABRICS) {
+		ctrl->fabrics_q = blk_mq_init_queue(set);
+		if (IS_ERR(ctrl->fabrics_q)) {
+			ret = PTR_ERR(ctrl->fabrics_q);
+			goto out_cleanup_admin_q;
+		}
+	}
+
+	ctrl->admin_tagset = set;
+	return 0;
+
+out_cleanup_admin_q:
+	blk_mq_destroy_queue(ctrl->fabrics_q);
+out_free_tagset:
+	blk_mq_free_tag_set(ctrl->admin_tagset);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(nvme_alloc_admin_tag_set);
+
+void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl)
+{
+	blk_mq_destroy_queue(ctrl->admin_q);
+	if (ctrl->ops->flags & NVME_F_FABRICS)
+		blk_mq_destroy_queue(ctrl->fabrics_q);
+	blk_mq_free_tag_set(ctrl->admin_tagset);
+}
+EXPORT_SYMBOL_GPL(nvme_remove_admin_tag_set);
+
+int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
+		const struct blk_mq_ops *ops, unsigned int flags,
+		unsigned int cmd_size)
+{
+	int ret;
+
+	memset(set, 0, sizeof(*set));
+	set->ops = ops;
+	set->queue_depth = ctrl->sqsize + 1;
+	set->reserved_tags = NVMF_RESERVED_TAGS;
+	set->numa_node = ctrl->numa_node;
+	set->flags = flags;
+	set->cmd_size = cmd_size,
+	set->driver_data = ctrl;
+	set->nr_hw_queues = ctrl->queue_count - 1;
+	set->timeout = NVME_IO_TIMEOUT;
+	if (ops->map_queues)
+		set->nr_maps = ctrl->opts->nr_poll_queues ? HCTX_MAX_TYPES : 2;
+	ret = blk_mq_alloc_tag_set(set);
+	if (ret)
+		return ret;
+
+	ctrl->connect_q = blk_mq_init_queue(set);
+        if (IS_ERR(ctrl->connect_q)) {
+		ret = PTR_ERR(ctrl->connect_q);
+		goto out_free_tag_set;
+	}
+
+	ctrl->tagset = set;
+	return 0;
+
+out_free_tag_set:
+	blk_mq_free_tag_set(set);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(nvme_alloc_io_tag_set);
+
+void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl)
+{
+	if (ctrl->ops->flags & NVME_F_FABRICS)
+		blk_mq_destroy_queue(ctrl->connect_q);
+	blk_mq_free_tag_set(ctrl->tagset);
+}
+EXPORT_SYMBOL_GPL(nvme_remove_io_tag_set);
+
 void nvme_stop_ctrl(struct nvme_ctrl *ctrl)
 {
 	nvme_mpath_stop(ctrl);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 1bdf714dcd9e4..6dec8a3bef1aa 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -722,6 +722,14 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);
 void nvme_start_ctrl(struct nvme_ctrl *ctrl);
 void nvme_stop_ctrl(struct nvme_ctrl *ctrl);
 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl);
+int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
+		const struct blk_mq_ops *ops, unsigned int flags,
+		unsigned int cmd_size);
+void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl);
+int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
+		const struct blk_mq_ops *ops, unsigned int flags,
+		unsigned int cmd_size);
+void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl);
 
 void nvme_remove_namespaces(struct nvme_ctrl *ctrl);
 
-- 
2.30.2



  reply	other threads:[~2022-09-20 17:16 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 17:15 consolidate tagset / misc request_queue allocation Christoph Hellwig
2022-09-20 17:15 ` Christoph Hellwig [this message]
2022-09-20 21:42   ` [PATCH 01/13] nvme: add common helpers to allocate and free tagsets Chaitanya Kulkarni
2022-09-21  3:37   ` Chao Leng
2022-09-22  5:45     ` Christoph Hellwig
2022-09-22  8:02       ` Chao Leng
2022-09-22 14:18         ` Christoph Hellwig
2022-09-21  8:25   ` Sagi Grimberg
2022-09-22  5:48     ` Christoph Hellwig
2022-09-22  8:09       ` Chao Leng
2022-09-22 14:19         ` Christoph Hellwig
2022-09-20 17:16 ` [PATCH 02/13] nvme-tcp: remove the unused queue_size member in nvme_tcp_queue Christoph Hellwig
2022-09-20 21:43   ` Chaitanya Kulkarni
2022-09-21  9:24   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 03/13] nvme-tcp: store the generic nvme_ctrl in set->driver_data Christoph Hellwig
2022-09-20 21:43   ` Chaitanya Kulkarni
2022-09-21  9:25   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 04/13] nvme-tcp: use the tagset alloc/free helpers Christoph Hellwig
2022-09-20 21:44   ` Chaitanya Kulkarni
2022-09-21  9:26   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 05/13] nvme-rdma: store the generic nvme_ctrl in set->driver_data Christoph Hellwig
2022-09-20 21:44   ` Chaitanya Kulkarni
2022-09-21  9:26   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 06/13] nvme-rdma: use the tagset alloc/free helpers Christoph Hellwig
2022-09-20 21:45   ` Chaitanya Kulkarni
2022-09-21  9:29   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 07/13] nvme-fc: keep ctrl->sqsize in sync with opts->queue_size Christoph Hellwig
2022-09-21  9:30   ` Sagi Grimberg
2022-09-22 22:48   ` James Smart
2022-09-20 17:16 ` [PATCH 08/13] nvme-fc: store the generic nvme_ctrl in set->driver_data Christoph Hellwig
2022-09-21  9:32   ` Sagi Grimberg
2022-09-22 22:51   ` James Smart
2022-09-20 17:16 ` [PATCH 09/13] nvme-fc: use the tagset alloc/free helpers Christoph Hellwig
2022-09-21  9:33   ` Sagi Grimberg
2022-09-22 22:56   ` James Smart
2022-09-20 17:16 ` [PATCH 10/13] nvme-loop: initialize sqsize later Christoph Hellwig
2022-09-20 21:45   ` Chaitanya Kulkarni
2022-09-21  9:33   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 11/13] nvme-loop: store the generic nvme_ctrl in set->driver_data Christoph Hellwig
2022-09-20 21:46   ` Chaitanya Kulkarni
2022-09-21  9:34   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 12/13] nvme-loop: use the tagset alloc/free helpers Christoph Hellwig
2022-09-20 21:46   ` Chaitanya Kulkarni
2022-09-21  9:34   ` Sagi Grimberg
2022-09-20 17:16 ` [PATCH 13/13] nvme: remove nvme_ctrl_init_connect_q Christoph Hellwig
2022-09-20 21:46   ` Chaitanya Kulkarni
2022-09-21  9:34   ` Sagi Grimberg
2022-09-27  7:27 ` consolidate tagset / misc request_queue allocation Christoph Hellwig
2022-09-28  6:47   ` Sagi Grimberg

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=20220920171611.1289361-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox