generic NVMe over Fabrics library support V2
Subsystems (3)
Christoph Hellwig
maintainerThis patch set adds the necessary infrastructure for the NVMe over Fabrics functionality and the NVMe over Fabrics library itself.
First we add some needed parameters to NVMe request allocation such as flags (for reserved commands - connect and keep-alive), also support tag allocation of a given queue ID (for connect to be executed per-queue) and allow request to be queued at the head of the request queue (so reconnects can pass in flight I/O).
Second, we add support for additional sysfs attributes that are needed or useful for the Fabrics driver.
Third we add the NVMe over Fabrics related header definitions and the Fabrics library itself which is transport independent and handles Fabrics specific commands and variables.
Last, we add support for periodic keep-alive mechanism which is mandatory for Fabrics.
Changes from V1:
- don't directly free host->opts on connect failure (Sagi)
- blk_mq_alloc_request_hctx improvements (Ming and me)
- keep alive should not use blk_mq_alloc_request_hctx (me)
Christoph Hellwig
maintainerPATCH 1/8 blk-mq: add blk_mq_alloc_request_hctx
From: Ming Lin <[email protected]>
For some protocols like NVMe over Fabrics we need to be able to send initialization commands to a specific queue.
Based on an earlier patch from Christoph Hellwig <[email protected]>.
--- block/blk-mq.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 2 ++ 2 files changed, 41 insertions(+)
block/blk-mq.c +39 -0
@@ -267,6 +267,45 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw, }EXPORT_SYMBOL (blk_mq_alloc_request); +struct request *blk_mq_alloc_request_hctx (struct request_queue *q,int rw, +unsigned int flags,unsigned int hctx_idx) +{ +struct blk_mq_hw_ctx *hctx; +struct blk_mq_ctx *ctx; +struct request *rq; +struct blk_mq_alloc_data alloc_data; +int ret; + +/* +* If the tag allocator sleeps we could get an allocation for a +* different hardware context. No need to complicate the low level +* allocator for this for the rare use case of a command tied to +* a specific queue. +*/ +if (WARN_ON_ONCE (!(flags &BLK_MQ_REQ_NOWAIT ))) +return ERR_PTR (-EINVAL ); + +if (hctx_idx >= q->nr_hw_queues) +return ERR_PTR (-EIO ); + + ret =blk_queue_enter (q, true); +if (ret) +return ERR_PTR (ret); + + hctx = q->queue_hw_ctx[hctx_idx]; + ctx =__blk_mq_get_ctx (q,cpumask_first (hctx->cpumask)); + +blk_mq_set_alloc_data (&alloc_data, q, flags, ctx, hctx); + rq =__blk_mq_alloc_request (&alloc_data, rw,0 ); +if (!rq) { +blk_queue_exit (q); +return ERR_PTR (-EWOULDBLOCK ); + } + +return rq; +} +EXPORT_SYMBOL_GPL (blk_mq_alloc_request_hctx); +static void __blk_mq_free_request (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx,struct request *rq) {
include/linux/blk-mq.h +2 -0
@@ -196,6 +196,8 @@ enum {struct request *blk_mq_alloc_request (struct request_queue *q,int rw,unsigned int flags); +struct request *blk_mq_alloc_request_hctx (struct request_queue *q,int op, +unsigned int flags,unsigned int hctx_idx);struct request *blk_mq_tag_to_rq (struct blk_mq_tags *tags,unsigned int tag);struct cpumask *blk_mq_tags_cpumask (struct blk_mq_tags *tags);
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 2/8 nvme: allow transitioning from NEW to LIVE state
In reply to Christoph HellwigFor Fabrics we're not going through an intermediate reset state (at least for now).
--- drivers/nvme/host/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/core.c +1 -0
@@ -85,6 +85,7 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,switch (new_state) {case NVME_CTRL_LIVE :switch (old_state) { +case NVME_CTRL_NEW :case NVME_CTRL_RESETTING : changed = true;/* FALLTHRU */
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 3/8 nvme: Modify and export sync command submission for fabrics
In reply to Christoph HellwigNVMe over fabrics will use __nvme_submit_sync_cmd in the the transport and require a few tweaks to it. For that we export it and add a few more paramters:
1. allow passing a queue ID to the block layer
For the NVMe over Fabrics connect command we need to able to specify a queue ID that we want to send the command on. Add a qid parameter to the relevant functions to enable this behavior.
2. allow submitting at_head commands
In cases where we want to (re)connect to a controller where we have inflight queued commands we want to first connect and only then allow the other queued commands to be kicked. This will prevents failures in controller resets and reconnects.
3. allow passing flags to blk_mq_allocate_request
Both for Fabrics connect the the keep-alive feature in NVMe 1.2.1 we want to be able to use reserved requests.
--- drivers/nvme/host/core.c | 27 ++++++++++++++++++--------- drivers/nvme/host/nvme.h | 5 +++-- drivers/nvme/host/pci.c | 4 ++-- 3 files changed, 23 insertions(+), 13 deletions(-)
drivers/nvme/host/core.c +18 -9
@@ -192,11 +192,16 @@ void nvme_requeue_req(struct request *req)EXPORT_SYMBOL_GPL (nvme_requeue_req);struct request *nvme_alloc_request (struct request_queue *q, -struct nvme_command *cmd,unsigned int flags) +struct nvme_command *cmd,unsigned int flags,int qid) {struct request *req; - req =blk_mq_alloc_request (q,nvme_is_write (cmd), flags); +if (qid ==NVME_QID_ANY ) { + req =blk_mq_alloc_request (q,nvme_is_write (cmd), flags); + }else { + req =blk_mq_alloc_request_hctx (q,nvme_is_write (cmd), flags, + qid ? qid -1 :0 ); + }if (IS_ERR (req))return req;
@@ -324,12 +329,12 @@ EXPORT_SYMBOL_GPL(nvme_setup_cmd);*/ int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,struct nvme_completion *cqe,void *buffer,unsigned bufflen, -unsigned timeout) +unsigned timeout,int qid,int at_head,int flags) {struct request *req;int ret; - req =nvme_alloc_request (q, cmd,0 ); + req =nvme_alloc_request (q, cmd, flags, qid);if (IS_ERR (req))return PTR_ERR (req);
@@ -342,17 +347,19 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, goto out; } -blk_execute_rq (req->q,NULL , req,0 ); +blk_execute_rq (req->q,NULL , req, at_head); ret = req->errors; out:blk_mq_free_request (req);return ret; } +EXPORT_SYMBOL_GPL (__nvme_submit_sync_cmd);int nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,void *buffer,unsigned bufflen) { -return __nvme_submit_sync_cmd (q, cmd,NULL , buffer, bufflen,0 ); +return __nvme_submit_sync_cmd (q, cmd,NULL , buffer, bufflen,0 , +NVME_QID_ANY ,0 ,0 ); }EXPORT_SYMBOL_GPL (nvme_submit_sync_cmd);
@@ -370,7 +377,7 @@ int __nvme_submit_user_cmd(struct request_queue *q, struct nvme_command *cmd,void *meta =NULL ;int ret; - req =nvme_alloc_request (q, cmd,0 ); + req =nvme_alloc_request (q, cmd,0 ,NVME_QID_ANY );if (IS_ERR (req))return PTR_ERR (req);
@@ -520,7 +527,8 @@ int nvme_get_features(struct nvme_ctrl *dev, unsigned fid, unsigned nsid, c.features.prp1 =cpu_to_le64 (dma_addr); c.features.fid =cpu_to_le32 (fid); - ret =__nvme_submit_sync_cmd (dev->admin_q, &c, &cqe,NULL ,0 ,0 ); + ret =__nvme_submit_sync_cmd (dev->admin_q, &c, &cqe,NULL ,0 ,0 , +NVME_QID_ANY ,0 ,0 );if (ret >=0 ) *result =le32_to_cpu (cqe.result);return ret;
@@ -539,7 +547,8 @@ int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword11, c.features.fid =cpu_to_le32 (fid); c.features.dword11 =cpu_to_le32 (dword11); - ret =__nvme_submit_sync_cmd (dev->admin_q, &c, &cqe,NULL ,0 ,0 ); + ret =__nvme_submit_sync_cmd (dev->admin_q, &c, &cqe,NULL ,0 ,0 , +NVME_QID_ANY ,0 ,0 );if (ret >=0 ) *result =le32_to_cpu (cqe.result);return ret;
drivers/nvme/host/nvme.h +3 -2
@@ -231,8 +231,9 @@ void nvme_stop_queues(struct nvme_ctrl *ctrl);void nvme_start_queues (struct nvme_ctrl *ctrl);void nvme_kill_queues (struct nvme_ctrl *ctrl); +#define NVME_QID_ANY -1struct request *nvme_alloc_request (struct request_queue *q, -struct nvme_command *cmd,unsigned int flags); +struct nvme_command *cmd,unsigned int flags,int qid);void nvme_requeue_req (struct request *req);int nvme_setup_cmd (struct nvme_ns *ns,struct request *req,struct nvme_command *cmd);
@@ -240,7 +241,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, void *buf, unsigned bufflen);int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,struct nvme_completion *cqe,void *buffer,unsigned bufflen, -unsigned timeout); +unsigned timeout,int qid,int at_head,int flags);int nvme_submit_user_cmd (struct request_queue *q,struct nvme_command *cmd,void __user *ubuffer,unsigned bufflen,u32 *result,unsigned timeout);
drivers/nvme/host/pci.c +2 -2
@@ -901,7 +901,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) req->tag, nvmeq->qid); abort_req =nvme_alloc_request (dev->ctrl.admin_q, &cmd, -BLK_MQ_REQ_NOWAIT ); +BLK_MQ_REQ_NOWAIT ,NVME_QID_ANY );if (IS_ERR (abort_req)) {atomic_inc (&dev->ctrl.abort_limit);return BLK_EH_RESET_TIMER ;
@@ -1512,7 +1512,7 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode) cmd.delete_queue.opcode = opcode; cmd.delete_queue.qid =cpu_to_le16 (nvmeq->qid); - req =nvme_alloc_request (q, &cmd,BLK_MQ_REQ_NOWAIT ); + req =nvme_alloc_request (q, &cmd,BLK_MQ_REQ_NOWAIT ,NVME_QID_ANY );if (IS_ERR (req))return PTR_ERR (req);
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 4/8 nvme: add fabrics sysfs attributes
In reply to Christoph HellwigFrom: Ming Lin <[email protected]>
- delete_controller: This attribute allows to delete a controller. A driver is not obligated to support it (pci doesn't) so it is created only if the driver supports it. The new fabrics drivers will support it (essentialy a disconnect operation).
Usage:
echo > /sys/class/nvme/nvme0/delete_controller
- subsysnqn: This attribute shows the subsystem nqn of the configured device. If a driver does not implement the get_subsysnqn method, the file will not appear in sysfs.
- transport: This attribute shows the transport name. Added a "name" field to struct nvme_ctrl_ops.
For loop,
cat /sys/class/nvme/nvme0/transport
loop
For RDMA,
cat /sys/class/nvme/nvme0/transport
rdma
For PCIe,
cat /sys/class/nvme/nvme0/transport
pcie
- address: This attributes shows the controller address. The fabrics drivers that will implement get_address can show the address of the connected controller.
example:
cat /sys/class/nvme/nvme0/address
traddr=192.168.2.2,trsvcid=1023
--- drivers/nvme/host/core.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++-- drivers/nvme/host/nvme.h | 4 +++ drivers/nvme/host/pci.c | 1 + 3 files changed, 78 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +73 -3
@@ -1362,7 +1362,7 @@ static struct attribute *nvme_ns_attrs[] = { NULL, }; -static umode_t nvme_attrs_are_visible (struct kobject *kobj, +static umode_t nvme_ns_attrs_are_visible (struct kobject *kobj,struct attribute *a,int n) { struct device *dev = container_of(kobj, struct device, kobj);
@@ -1381,7 +1381,7 @@ static umode_t nvme_attrs_are_visible(struct kobject *kobj,static const struct attribute_group nvme_ns_attr_group = { .attrs = nvme_ns_attrs, - .is_visible = nvme_attrs_are_visible, + .is_visible = nvme_ns_attrs_are_visible, };#define nvme_show_str_function (field) \
@@ -1407,6 +1407,49 @@ nvme_show_str_function(serial);nvme_show_str_function (firmware_rev);nvme_show_int_function (cntlid); +static ssize_t nvme_sysfs_delete (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); + +if (device_remove_file_self (dev, attr)) + ctrl->ops->delete_ctrl (ctrl); +return count; +} +static DEVICE_ATTR(delete_controller, S_IWUSR, NULL, nvme_sysfs_delete); + +static ssize_t nvme_sysfs_show_transport (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); + +return snprintf (buf,PAGE_SIZE ,"%s\n" , ctrl->ops->name); +} +static DEVICE_ATTR(transport, S_IRUGO, nvme_sysfs_show_transport, NULL); + +static ssize_t nvme_sysfs_show_subsysnqn (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); + +return snprintf (buf,PAGE_SIZE ,"%s\n" , + ctrl->ops->get_subsysnqn (ctrl)); +} +static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL); + +static ssize_t nvme_sysfs_show_address (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); + +return ctrl->ops->get_address (ctrl, buf,PAGE_SIZE ); +} +static DEVICE_ATTR(address, S_IRUGO, nvme_sysfs_show_address, NULL); +static struct attribute *nvme_dev_attrs[] = { &dev_attr_reset_controller.attr, &dev_attr_rescan_controller.attr,
@@ -1414,11 +1457,38 @@ static struct attribute *nvme_dev_attrs[] = { &dev_attr_serial.attr, &dev_attr_firmware_rev.attr, &dev_attr_cntlid.attr, + &dev_attr_delete_controller.attr, + &dev_attr_transport.attr, + &dev_attr_subsysnqn.attr, + &dev_attr_address.attr,NULL }; +#define CHECK_ATTR (ctrl, a, name) \ + if ((a) == &dev_attr_##name.attr && \ + !(ctrl)->ops->get_##name) \ + return 0 + +static umode_t nvme_dev_attrs_are_visible (struct kobject *kobj, +struct attribute *a,int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); + +if (a == &dev_attr_delete_controller.attr) { +if (!ctrl->ops->delete_ctrl) +return 0 ; + } + +CHECK_ATTR (ctrl, a, subsysnqn); +CHECK_ATTR (ctrl, a, address); + +return a->mode; +} +static struct attribute_group nvme_dev_attrs_group = { - .attrs = nvme_dev_attrs, + .attrs = nvme_dev_attrs, + .is_visible = nvme_dev_attrs_are_visible, }; static const struct attribute_group *nvme_dev_attr_groups[] = {
drivers/nvme/host/nvme.h +4 -0
@@ -144,6 +144,7 @@ struct nvme_ns { };struct nvme_ctrl_ops { +const char *name;struct module *module;int (*reg_read32)(struct nvme_ctrl *ctrl,u32 off,u32 *val);int (*reg_write32)(struct nvme_ctrl *ctrl,u32 off,u32 val);
@@ -152,6 +153,9 @@ struct nvme_ctrl_ops {void (*free_ctrl)(struct nvme_ctrl *ctrl);void (*post_scan)(struct nvme_ctrl *ctrl);void (*submit_async_event)(struct nvme_ctrl *ctrl,int aer_idx); +int (*delete_ctrl)(struct nvme_ctrl *ctrl); +const char *(*get_subsysnqn)(struct nvme_ctrl *ctrl); +int (*get_address)(struct nvme_ctrl *ctrl,char *buf,int size); };static inline bool nvme_ctrl_ready (struct nvme_ctrl *ctrl)
drivers/nvme/host/pci.c +1 -0
@@ -1873,6 +1873,7 @@ static int nvme_pci_reset_ctrl(struct nvme_ctrl *ctrl) }static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = { + .name ="pcie" , .module =THIS_MODULE , .reg_read32 = nvme_pci_reg_read32, .reg_write32 = nvme_pci_reg_write32,
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 5/8 nvme.h: add NVMe over Fabrics definitions
In reply to Christoph HellwigThe NVMe over Fabrics specification defines a protocol interface and related extensions to NVMe that enable operation over network protocols. The NVMe over Fabrics specification has an NVMe Transport binding for each NVMe Transport.
This patch adds the fabrics related definitions:
- fabric specific command set and error codes
- transport addressing and binding definitions
- fabrics sgl extensions
- controller identification fabrics enhancements
- discovery log page definition
--- drivers/nvme/host/core.c | 4 +- drivers/nvme/host/pci.c | 4 +- include/linux/nvme.h | 337 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 322 insertions(+), 23 deletions(-)
drivers/nvme/host/core.c +2 -2
@@ -524,7 +524,7 @@ int nvme_get_features(struct nvme_ctrl *dev, unsigned fid, unsigned nsid,memset (&c,0 ,sizeof (c)); c.features.opcode = nvme_admin_get_features; c.features.nsid =cpu_to_le32 (nsid); - c.features.prp1 =cpu_to_le64 (dma_addr); + c.features.dptr.prp1 =cpu_to_le64 (dma_addr); c.features.fid =cpu_to_le32 (fid); ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &cqe, NULL, 0, 0,
@@ -543,7 +543,7 @@ int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword11,memset (&c,0 ,sizeof (c)); c.features.opcode = nvme_admin_set_features; - c.features.prp1 =cpu_to_le64 (dma_addr); + c.features.dptr.prp1 =cpu_to_le64 (dma_addr); c.features.fid =cpu_to_le32 (fid); c.features.dword11 =cpu_to_le32 (dword11);
drivers/nvme/host/pci.c +2 -2
@@ -520,8 +520,8 @@ static int nvme_map_data(struct nvme_dev *dev, struct request *req, goto out_unmap; } - cmnd->rw.prp1 =cpu_to_le64 (sg_dma_address (iod->sg)); - cmnd->rw.prp2 =cpu_to_le64 (iod->first_dma); + cmnd->rw.dptr.prp1 =cpu_to_le64 (sg_dma_address (iod->sg)); + cmnd->rw.dptr.prp2 =cpu_to_le64 (iod->first_dma);if (blk_integrity_rq (req)) cmnd->rw.metadata =cpu_to_le64 (sg_dma_address (&iod->meta_sg));return BLK_MQ_RQ_QUEUE_OK ;
include/linux/nvme.h +318 -19
465 lines not on this page · raw message
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 6/8 nvme-fabrics: add a generic NVMe over Fabrics library
In reply to Christoph HellwigThe NVMe over Fabrics library provides an interface for both transports and the nvme core to handle fabrics specific commands and attributes independent of the underlying transport.
In addition, the fabrics library adds a misc device interface that allow actually creating a fabrics controller, as we can't just autodiscover it like in the PCI case. The nvme-cli utility has been enhanced to use this interface to support fabric connect and discovery.
--- drivers/nvme/host/Kconfig | 3 + drivers/nvme/host/Makefile | 3 + drivers/nvme/host/core.c | 19 +- drivers/nvme/host/fabrics.c | 931 ++++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/fabrics.h | 132 +++++++ drivers/nvme/host/nvme.h | 11 + 6 files changed, 1098 insertions(+), 1 deletion(-) create mode 100644 drivers/nvme/host/fabrics.c create mode 100644 drivers/nvme/host/fabrics.h
drivers/nvme/host/Kconfig +3 -0
@@ -24,3 +24,6 @@ config BLK_DEV_NVME_SCSI to say N here, unless you run a distro that abuses the SCSI emulation to provide stable device names for mount by id, like some OpenSuSE and SLES versions. + +config NVME_FABRICS + tristate
drivers/nvme/host/Makefile +3 -0
@@ -1,8 +1,11 @@ obj-$(CONFIG_NVME_CORE) += nvme-core.o obj-$(CONFIG_BLK_DEV_NVME) += nvme.o +obj-$(CONFIG_NVME_FABRICS) += nvme-fabrics.o nvme-core-y := core.o nvme-core-$(CONFIG_BLK_DEV_NVME_SCSI) += scsi.o nvme-core-$(CONFIG_NVM) += lightnvm.o nvme-y += pci.o + +nvme-fabrics-y += fabrics.o
drivers/nvme/host/core.c +18 -1
@@ -1178,9 +1178,26 @@ int nvme_init_identify(struct nvme_ctrl *ctrl) }nvme_set_queue_limits (ctrl, ctrl->admin_q); + ctrl->sgls =le32_to_cpu (id->sgls); + +if (ctrl->ops->is_fabrics) { + ctrl->icdoff =le16_to_cpu (id->icdoff); + ctrl->ioccsz =le32_to_cpu (id->ioccsz); + ctrl->iorcsz =le32_to_cpu (id->iorcsz); + ctrl->maxcmd =le16_to_cpu (id->maxcmd); + +/* +* In fabrics we need to verify the cntlid matches the +* admin connect +*/ +if (ctrl->cntlid !=le16_to_cpu (id->cntlid)) + ret = -EINVAL ; + }else { + ctrl->cntlid =le16_to_cpu (id->cntlid); + }kfree (id); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (nvme_init_identify);
drivers/nvme/host/fabrics.c new file +931 -0
931 lines not on this page · raw message
drivers/nvme/host/fabrics.h new file +132 -0
132 lines not on this page · raw message
drivers/nvme/host/nvme.h +11 -0
@@ -80,6 +80,7 @@ struct nvme_ctrl {spinlock_t lock;const struct nvme_ctrl_ops *ops;struct request_queue *admin_q; +struct request_queue *connect_q;struct device *dev;struct kref kref;int instance;
@@ -107,10 +108,19 @@ struct nvme_ctrl {u8 event_limit;u8 vwc;u32 vs; +u32 sgls;bool subsystem;unsigned long quirks;struct work_struct scan_work;struct work_struct async_event_work; + +/* Fabrics only */ +u16 sqsize; +u32 ioccsz; +u32 iorcsz; +u16 icdoff; +u16 maxcmd; +struct nvmf_ctrl_options *opts; };/*
@@ -146,6 +156,7 @@ struct nvme_ns {struct nvme_ctrl_ops {const char *name;struct module *module; +bool is_fabrics;int (*reg_read32)(struct nvme_ctrl *ctrl,u32 off,u32 *val);int (*reg_write32)(struct nvme_ctrl *ctrl,u32 off,u32 val);int (*reg_read64)(struct nvme_ctrl *ctrl,u32 off,u64 *val);
Signature · 1 line
2.1.4
Re: [PATCH 6/8] nvme-fabrics: add a generic NVMe over Fabrics library
Quoted 8 lines · Christoph Hellwig
drivers/nvme/host/nvme.h +1
-0@@ -107,10 +108,19 @@ struct nvme_ctrl {u8 event_limit;u8 vwc;u32 vs; +u32 sgls;bool subsystem;unsigned long quirks;struct work_struct scan_work;
drivers/nvme/host/nvme.h struct nvme_ctrl { · line 124
Quoted 10 lines
drivers/nvme/host/nvme.h +8
-0struct work_struct async_event_work; + +/* Fabrics only */ +u16 sqsize; +u32 ioccsz; +u32 iorcsz; +u16 icdoff; +u16 maxcmd; +struct nvmf_ctrl_options *opts; };
The pci only stuff goes in 'struct nvme_dev' and embeds 'struct nvme_ctrl', but fabrics gets to use nvme_ctrl directly?
If we need transport specifics for anything, like you have during nvme_init_identify, I think we should add function callbacks to nvme_ctrl_ops to set up those specifics, then we don't need 'is_fabrics' checks.
Sagi Grimberg
maintainerRe: [PATCH 6/8] nvme-fabrics: add a generic NVMe over Fabrics library
Quoted 23 lines
Quoted 9 lines
drivers/nvme/host/nvme.h +1
-0@@ -107,10 +108,19 @@ struct nvme_ctrl {u8 event_limit;u8 vwc;u32 vs; +u32 sgls;bool subsystem;unsigned long quirks;struct work_struct scan_work;drivers/nvme/host/nvme.h struct nvme_ctrl { · line 124
Quoted 10 lines
drivers/nvme/host/nvme.h +8
-0struct work_struct async_event_work; + +/* Fabrics only */ +u16 sqsize; +u32 ioccsz; +u32 iorcsz; +u16 icdoff; +u16 maxcmd; +struct nvmf_ctrl_options *opts; };The pci only stuff goes in 'struct
nvme_dev' and embeds 'structnvme_ctrl', but fabrics gets to usenvme_ctrldirectly?
Quoted 4 lines
If we need transport specifics for anything, like you have during
nvme_init_identify, I think we should add function callbacks tonvme_ctrl_opsto set up those specifics, then we don't need 'is_fabrics' checks.
That's where we started off from :)
But we got to a point where it started getting convoluted for generic nvme optional features which are mandatory for fabrics (like keep-alive support) that are detected in different forms (controller identify and fabric admin connect). Anyway we thought it'd be cleaner to have it directly in nvme_ctrl and centralize their assignments in a single location.
Christoph Hellwig
maintainerPATCH 7/8 nvme.h: Add keep-alive opcode and identify controller attribute
In reply to Christoph HellwigFrom: Sagi Grimberg <[email protected]>
KAS: keep-alive support and granularity of kato in units of 100 ms nvme_admin_keep_alive opcode: 0x18
--- include/linux/nvme.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/nvme.h +5 -1
@@ -202,7 +202,9 @@ struct nvme_id_ctrl {__u8 apsta;__le16 wctemp;__le16 cctemp; -__u8 rsvd270[242 ]; +__u8 rsvd270[50 ]; +__le16 kas; +__u8 rsvd322[190 ];__u8 sqes;__u8 cqes;__le16 maxcmd;
@@ -556,6 +558,7 @@ enum nvme_admin_opcode { nvme_admin_async_event =0x0c , nvme_admin_activate_fw =0x10 , nvme_admin_download_fw =0x11 , + nvme_admin_keep_alive =0x18 , nvme_admin_format_nvm =0x80 , nvme_admin_security_send =0x81 , nvme_admin_security_recv = 0x82,
@@ -580,6 +583,7 @@ enum {NVME_FEAT_WRITE_ATOMIC =0x0a ,NVME_FEAT_ASYNC_EVENT =0x0b ,NVME_FEAT_AUTO_PST =0x0c , +NVME_FEAT_KATO =0x0f ,NVME_FEAT_SW_PROGRESS =0x80 ,NVME_FEAT_HOST_ID =0x81 , NVME_FEAT_RESV_MASK = 0x82,
Signature · 1 line
2.1.4
Christoph Hellwig
maintainerPATCH 8/8 nvme: add keep-alive support
In reply to Christoph HellwigFrom: Sagi Grimberg <[email protected]>
Periodic keep-alive is a mandatory feature in NVMe over Fabrics, and optional in NVMe 1.2.1 for PCIe. This patch adds periodic keep-alive sent from the host to verify that the controller is still responsive and vice-versa. The keep-alive timeout is user-defined (with keep_alive_tmo connection parameter) and defaults to 5 seconds.
In order to avoid a race condition where the host sends a keep-alive competing with the target side keep-alive timeout expiration, the host adds a grace period of 10 seconds when publishing the keep-alive timeout to the target.
In case a keep-alive failed (or timed out), a transport specific error recovery kicks in.
For now only NVMe over Fabrics is wired up to support keep alive, but we can add PCIe support easily once controllers actually supporting it become available.
--- drivers/nvme/host/core.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/fabrics.c | 33 +++++++++++++++++++- drivers/nvme/host/fabrics.h | 3 ++ drivers/nvme/host/nvme.h | 8 +++++ 4 files changed, 119 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +76 -0
@@ -30,6 +30,7 @@#include <asm/unaligned.h> #include "nvme.h" +#include "fabrics.h" #define NVME_MINORS (1U << MINORBITS)
@@ -463,6 +464,74 @@ int nvme_submit_user_cmd(struct request_queue *q, struct nvme_command *cmd, result, timeout); } +static void nvme_keep_alive_end_io (struct request *rq,int error) +{ +struct nvme_ctrl *ctrl = rq->end_io_data; + +blk_mq_free_request (rq); + +if (error) { +dev_err (ctrl->device, +"failed nvme_keep_alive_end_io error=%d\n" , error); +return ; + } + +schedule_delayed_work (&ctrl->ka_work, ctrl->kato *HZ ); +} + +static int nvme_keep_alive (struct nvme_ctrl *ctrl) +{ +struct nvme_command c; +struct request *rq; + +memset (&c,0 ,sizeof (c)); + c.common.opcode = nvme_admin_keep_alive; + + rq =nvme_alloc_request (ctrl->admin_q, &c,BLK_MQ_REQ_RESERVED , +NVME_QID_ANY ); +if (IS_ERR (rq)) +return PTR_ERR (rq); + + rq->timeout = ctrl->kato *HZ ; + rq->end_io_data = ctrl; + +blk_execute_rq_nowait (rq->q,NULL , rq,0 , nvme_keep_alive_end_io); + +return 0 ; +} + +static void nvme_keep_alive_work (struct work_struct *work) +{ +struct nvme_ctrl *ctrl =container_of (to_delayed_work (work), + struct nvme_ctrl, ka_work); + +if (nvme_keep_alive (ctrl)) { +/* allocation failure, reset the controller */ +dev_err (ctrl->device,"keep-alive failed\n" ); + ctrl->ops->reset_ctrl (ctrl); +return ; + } +} + +void nvme_start_keep_alive (struct nvme_ctrl *ctrl) +{ +if (unlikely (ctrl->kato ==0 )) +return ; + +INIT_DELAYED_WORK (&ctrl->ka_work, nvme_keep_alive_work); +schedule_delayed_work (&ctrl->ka_work, ctrl->kato *HZ ); +} +EXPORT_SYMBOL_GPL (nvme_start_keep_alive); + +void nvme_stop_keep_alive (struct nvme_ctrl *ctrl) +{ +if (unlikely (ctrl->kato ==0 )) +return ; + +cancel_delayed_work_sync (&ctrl->ka_work); +} +EXPORT_SYMBOL_GPL (nvme_stop_keep_alive); +int nvme_identify_ctrl (struct nvme_ctrl *dev,struct nvme_id_ctrl **id) {struct nvme_command c = { };
@@ -1179,6 +1248,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)nvme_set_queue_limits (ctrl, ctrl->admin_q); ctrl->sgls =le32_to_cpu (id->sgls); + ctrl->kas =le16_to_cpu (id->kas);if (ctrl->ops->is_fabrics) { ctrl->icdoff =le16_to_cpu (id->icdoff);
@@ -1192,6 +1262,12 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)*/ if (ctrl->cntlid !=le16_to_cpu (id->cntlid)) ret = -EINVAL ; + +if (!ctrl->opts->discovery_nqn && !ctrl->kas) { +dev_err (ctrl->dev, +"keep-alive support is mandatory for fabrics\n" ); + ret = -EINVAL ; + } }else { ctrl->cntlid =le16_to_cpu (id->cntlid); }
drivers/nvme/host/fabrics.c +32 -1
@@ -360,6 +360,12 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) cmd.connect.fctype = nvme_fabrics_type_connect; cmd.connect.qid =0 ; cmd.connect.sqsize =cpu_to_le16 (ctrl->sqsize); +/* +* Set keep-alive timeout in seconds granularity (ms * 1000) +* and add a grace period for controller kato enforcement +*/ + cmd.connect.kato = ctrl->opts->discovery_nqn ?0 : +cpu_to_le32 ((ctrl->kato +NVME_KATO_GRACE ) *1000 ); data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data)
@@ -499,6 +505,7 @@ static const match_table_t opt_tokens = { { NVMF_OPT_NR_IO_QUEUES, "nr_io_queues=%d" }, { NVMF_OPT_TL_RETRY_COUNT, "tl_retry_count=%d" }, { NVMF_OPT_RECONNECT_DELAY, "reconnect_delay=%d" }, + { NVMF_OPT_KATO, "keep_alive_tmo=%d" }, { NVMF_OPT_HOSTNQN, "hostnqn=%s" }, { NVMF_OPT_ERR, NULL } };
@@ -610,6 +617,28 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, } opts->tl_retry_count = token;break ; +case NVMF_OPT_KATO : +if (match_int (args, &token)) { + ret = -EINVAL ; + goto out; + } + +if (opts->discovery_nqn) { +pr_err ("Discovery controllers cannot accept keep_alive_tmo != 0\n" ); + ret = -EINVAL ; + goto out; + } + +if (token <0 ) { +pr_err ("Invalid keep_alive_tmo %d\n" , token); + ret = -EINVAL ; + goto out; + }else if (token ==0 ) { +/* Allowed for debug */ +pr_warn ("keep_alive_tmo 0 won't execute keep alives!!!\n" ); + } + opts->kato = token; +break ;case NVMF_OPT_HOSTNQN :if (opts->host) { pr_err("hostnqn already user-assigned: %s\n",
@@ -661,6 +690,8 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, } out: +if (!opts->discovery_nqn && !opts->kato) + opts->kato =NVME_DEFAULT_KATO ;kfree (options);return ret; }
@@ -717,7 +748,7 @@ EXPORT_SYMBOL_GPL(nvmf_free_options);#define NVMF_REQUIRED_OPTS (NVMF_OPT_TRANSPORT | NVMF_OPT_NQN)#define NVMF_ALLOWED_OPTS (NVMF_OPT_QUEUE_SIZE | NVMF_OPT_NR_IO_QUEUES | \ - NVMF_OPT_HOSTNQN) + NVMF_OPT_KATO | NVMF_OPT_HOSTNQN)static struct nvme_ctrl *nvmf_create_ctrl (struct device *dev,const char *buf,size_t count)
drivers/nvme/host/fabrics.h +3 -0
@@ -49,6 +49,7 @@ enum {NVMF_OPT_QUEUE_SIZE =1 <<4 ,NVMF_OPT_NR_IO_QUEUES =1 <<5 ,NVMF_OPT_TL_RETRY_COUNT =1 <<6 , +NVMF_OPT_KATO =1 <<7 ,NVMF_OPT_HOSTNQN =1 <<8 , NVMF_OPT_RECONNECT_DELAY = 1 << 9, };
@@ -72,6 +73,7 @@ enum {* kicking upper layer(s) error recovery. * @reconnect_delay: Time between two consecutive reconnect attempts. * @discovery_nqn: indicates if the subsysnqn is the well-known discovery NQN. +* @kato: Keep-alive timeout. * @host: Virtual NVMe host, contains the NQN and Host ID. */ struct nvmf_ctrl_options {
@@ -85,6 +87,7 @@ struct nvmf_ctrl_options {unsigned short tl_retry_count;unsigned int reconnect_delay;bool discovery_nqn; +unsigned int kato;struct nvmf_host *host; };
drivers/nvme/host/nvme.h +8 -0
@@ -38,6 +38,9 @@ extern unsigned char admin_timeout;extern unsigned char shutdown_timeout;#define SHUTDOWN_TIMEOUT (shutdown_timeout * HZ) +#define NVME_DEFAULT_KATO 5 +#define NVME_KATO_GRACE 10 +enum {NVME_NS_LBA =0 ,NVME_NS_LIGHTNVM =1 ,
@@ -109,10 +112,13 @@ struct nvme_ctrl {u8 vwc;u32 vs;u32 sgls; +u16 kas; +unsigned int kato;bool subsystem;unsigned long quirks;struct work_struct scan_work;struct work_struct async_event_work; +struct delayed_work ka_work;/* Fabrics only */ u16 sqsize;
@@ -273,6 +279,8 @@ int nvme_get_features(struct nvme_ctrl *dev, unsigned fid, unsigned nsid,int nvme_set_features (struct nvme_ctrl *dev,unsigned fid,unsigned dword11,dma_addr_t dma_addr,u32 *result);int nvme_set_queue_count (struct nvme_ctrl *ctrl,int *count); +void nvme_start_keep_alive (struct nvme_ctrl *ctrl); +void nvme_stop_keep_alive (struct nvme_ctrl *ctrl);struct sg_io_hdr ;
Signature · 1 line
2.1.4
Keith Busch
Reviewed-byQuoted 16 lines · Christoph Hellwig
This patch set adds the necessary infrastructure for the NVMe over Fabrics functionality and the NVMe over Fabrics library itself.
First we add some needed parameters to NVMe request allocation such as flags (for reserved commands - connect and keep-alive), also support tag allocation of a given queue ID (for connect to be executed per-queue) and allow request to be queued at the head of the request queue (so reconnects can pass in flight I/O).
Second, we add support for additional sysfs attributes that are needed or useful for the Fabrics driver.
Third we add the NVMe over Fabrics related header definitions and the Fabrics library itself which is transport independent and handles Fabrics specific commands and variables.
Quoted 7 lines
Last, we add support for periodic keep-alive mechanism which is mandatory for Fabrics.
Changes from V1:
- don't directly freehost->optson connect failure (Sagi)
-blk_mq_alloc_request_hctximprovements (Ming and me)
- keep alive should not useblk_mq_alloc_request_hctx(me)
I only had the one comment, and Sagi says you guys already considered it but was more complicated than it was worth. Looking at the patches that follow, I tend to agree.
The rest looks great, and passes all the sanity tests I can run. This time with correct email spelling: