Support for Open-Channel SSDs
Subsystems (5)
cover Support for Open-Channel SSDs
Hi,
Here is an updated patchset of LightNVM. It is now integrated directly into the block layer when using blk-mq. I'll like to get some feedback on how it is plugged in.
The block layer integration is as follows:
block/blk-lightnvm.c holds the setup/teardown functions and calls in to the lightnvm code.
Extendied the request queue flags with QUEUE_FLAG_LIGHTNVM when the queue is a LightNVM queue.
The struct request structure is extended with a ->phys_sector, that holds the physical address that a logical address is mapped to. The ->phys_sector is set by blk_lightnvm_map, that calls into lightnvm and allocate new address on writes, and similarly look up an address on reads.
A request has a NVM_MAP flag set when it has been mapped. This is used to know if completion logic should be run on blk-mq completion. It might now be for some targets.
The request cmd_size field is extended to hold any per-request information that lightnvm requires for its bookkeeping.
A branch with the patches can be found here:
https://github.com/OpenChannelSSD/linux.git lkml_v1
It is currently based on 3.17 on top of the NVMe blk-mq conversion.
For testing, the null_blk driver can be instantiated with:
lightnvm_enable=1 gb=4 bs=4096 nr_devices=1
or by using the qemu branch at:
https://github.com/OpenChannelSSD/qemu-nvme.git master
and booting qemu with:
-drive file=filepath,if=none,id=mynvme \
-device nvme,drive=mynvme,serial=deadbeef,namespaces=1,lver=1,lchannels=1, \
nlbaf=5,lba_index=3Todo:
Multi-page accesses. Currently limited to sector size IO accesses. Retrieval of mapping table from device. Mapping table is forgot on module unload.
Bad block handling. No method to handle flash blocks there are marked bad.
Thanks,
Matias
Jesper Madsen (1):
block: extend rq_flag_bits
Matias Bjørling (4):
block: expose init_request_from_bio
lightnvm: Support for Open-Channel SSDs
nvme: LightNVM integration
null_blk: LightNVM integration
Documentation/block/null_blk.txt | 8 + block/Makefile | 1 + block/blk-core.c | 6 + block/blk-lightnvm.c | 81 ++++++ block/blk-mq.c | 35 ++- block/blk-sysfs.c | 13 + block/blk.h | 14 + block/ioctl.c | 1 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/block/null_blk.c | 89 +++++- drivers/block/nvme-core.c | 187 ++++++++++++- drivers/lightnvm/Kconfig | 20 ++ drivers/lightnvm/Makefile | 5 + drivers/lightnvm/core.c | 208 ++++++++++++++ drivers/lightnvm/gc.c | 370 ++++++++++++++++++++++++ drivers/lightnvm/nvm.c | 460 ++++++++++++++++++++++++++++++ drivers/lightnvm/nvm.h | 588 +++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/sysfs.c | 68 +++++ drivers/lightnvm/targets.c | 244 ++++++++++++++++ include/linux/blk-mq.h | 1 + include/linux/blk_types.h | 4 + include/linux/blkdev.h | 24 ++ include/linux/lightnvm.h | 112 ++++++++ include/linux/nvme.h | 1 + include/trace/events/nvm.h | 70 +++++ include/uapi/linux/nvme.h | 74 +++++ 27 files changed, 2677 insertions(+), 10 deletions(-) create mode 100644 block/blk-lightnvm.c create mode 100644 drivers/lightnvm/Kconfig create mode 100644 drivers/lightnvm/Makefile create mode 100644 drivers/lightnvm/core.c create mode 100644 drivers/lightnvm/gc.c create mode 100644 drivers/lightnvm/nvm.c create mode 100644 drivers/lightnvm/nvm.h create mode 100644 drivers/lightnvm/sysfs.c create mode 100644 drivers/lightnvm/targets.c create mode 100644 include/linux/lightnvm.h create mode 100644 include/trace/events/nvm.h
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/5 block: expose init_request_from_bio
When doing internal commands within LightNVM, we may form it as a bio. It can then use the existing infrastructure for handling bio's. Expose init_request_from_bio as blk_init_request_from_bio and allow requests to initialized from bio's.
--- block/blk-core.c | 6 ++++++ include/linux/blkdev.h | 1 + 2 files changed, 7 insertions(+)
block/blk-core.c +6 -0
@@ -1546,6 +1546,12 @@ void init_request_from_bio(struct request *req, struct bio *bio)blk_rq_bio_prep (req->q, req, bio); } +void blk_init_request_from_bio (struct request *req,struct bio *bio) +{ +init_request_from_bio (req, bio); +} +EXPORT_SYMBOL (blk_init_request_from_bio); +void blk_queue_bio (struct request_queue *q,struct bio *bio) {const bool sync = !!(bio->bi_rw &REQ_SYNC );
include/linux/blkdev.h +1 -0
@@ -823,6 +823,7 @@ extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t, struct scsi_ioctl_command __user *);extern void blk_queue_bio (struct request_queue *q,struct bio *bio); +extern void blk_init_request_from_bio (struct request *req,struct bio *bio);/* * A queue has just exitted congestion. Note this in the global counter of
Signature · 1 line
1.9.1
PATCH 2/5 block: extend rq_flag_bits
In reply to Matias BjørlingFrom: Jesper Madsen <[email protected]>
The rq_flag_bits is extended by REQ_NVM and REQ_NVM_MAPPED
REQ_NVM is used to detect request have through LightNVM on submission, and can be detected on completion.
REQ_NVM_MAPPED is used to detect if request have mapped appropriately through LightNVM.
The latter is added temponarily to debug LightNVM targets and will be removed later.
--- include/linux/blk_types.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/blk_types.h +4 -0
@@ -191,6 +191,8 @@ enum rq_flag_bits { __REQ_END,/* last of chain of requests */ __REQ_HASHED,/* on IO scheduler merge hash */ __REQ_MQ_INFLIGHT,/* track inflight for MQ */ + __REQ_NVM,/* request is queued via lightnvm */ + __REQ_NVM_MAPPED,/* lightnvm mapped this request */ __REQ_NR_BITS, /* stops here */ };
@@ -245,5 +247,7 @@ enum rq_flag_bits {#define REQ_END (1ULL << __REQ_END)#define REQ_HASHED (1ULL << __REQ_HASHED)#define REQ_MQ_INFLIGHT (1ULL << __REQ_MQ_INFLIGHT) +#define REQ_NVM (1ULL << __REQ_NVM) +#define REQ_NVM_MAPPED (1ULL << __REQ_NVM_MAPPED)#endif /* __LINUX_BLK_TYPES_H */
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC PATCH 3/5 lightnvm: Support for Open-Channel SSDs
In reply to Matias BjørlingOpen-channel SSDs are devices exposes direct access to its physical flash storage, while keeping a subset of the internal features of SSDs.
A common SSD consists of a flash translation layer (FTL), bad block management, and hardware units such as flash controller and host interface controller and a large amount of flash chips.
LightNVM moves part of the FTL responsibility into the host, allowing the host to manage data placement, garbage collection and parallelism. The device continues to maintain information about bad block management, implements a simpler FTL, that allows extensions such as atomic IOs, metadata persistence and similar to be implemented.
The architecture of LightNVM consists of a core and multiple targets. The core has the part of the driver that is shared across targets, initialization and teardown and statistics. The other part is targets. They are how physical flash are exposed to user-land. This can be as the block device, key-value store, object-store, or anything else.
Contributions in this patch from:
Jesper Madsen <[email protected]>
--- block/Makefile | 1 + block/blk-lightnvm.c | 81 +++++++ block/blk-mq.c | 35 ++- block/blk-sysfs.c | 13 + block/blk.h | 14 ++ block/ioctl.c | 1 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/lightnvm/Kconfig | 20 ++ drivers/lightnvm/Makefile | 5 + drivers/lightnvm/core.c | 208 ++++++++++++++++ drivers/lightnvm/gc.c | 370 ++++++++++++++++++++++++++++ drivers/lightnvm/nvm.c | 460 +++++++++++++++++++++++++++++++++++ drivers/lightnvm/nvm.h | 588 +++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/sysfs.c | 68 ++++++ drivers/lightnvm/targets.c | 244 +++++++++++++++++++ include/linux/blk-mq.h | 1 + include/linux/blkdev.h | 23 ++ include/linux/lightnvm.h | 112 +++++++++ include/trace/events/nvm.h | 70 ++++++ 20 files changed, 2313 insertions(+), 4 deletions(-) create mode 100644 block/blk-lightnvm.c create mode 100644 drivers/lightnvm/Kconfig create mode 100644 drivers/lightnvm/Makefile create mode 100644 drivers/lightnvm/core.c create mode 100644 drivers/lightnvm/gc.c create mode 100644 drivers/lightnvm/nvm.c create mode 100644 drivers/lightnvm/nvm.h create mode 100644 drivers/lightnvm/sysfs.c create mode 100644 drivers/lightnvm/targets.c create mode 100644 include/linux/lightnvm.h create mode 100644 include/trace/events/nvm.h
block/Makefile +1 -0
@@ -23,3 +23,4 @@ obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += blk-integrity.o obj-$(CONFIG_BLK_CMDLINE_PARSER) += cmdline-parser.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o +obj-$(CONFIG_LIGHTNVM) += blk-lightnvm.o
block/blk-lightnvm.c new file +81 -0
81 lines not on this page · raw message
block/blk-mq.c +31 -4
@@ -20,6 +20,7 @@#include <linux/cache.h> #include <linux/sched/sysctl.h> #include <linux/delay.h> +#include <linux/lightnvm.h> #include <trace/events/block.h>
@@ -199,6 +200,9 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx, rq->end_io_data =NULL ; rq->next_rq =NULL ; +#if CONFIG_LIGHTNVM + rq->phys_sector =0 ; +#endif ctx->rq_dispatched[rw_is_sync (rw_flags)]++; }
@@ -307,6 +311,11 @@ void blk_mq_clone_flush_request(struct request *flush_rq,inline void __blk_mq_end_io (struct request *rq,int error) { +struct request_queue *q = rq->q; + +if (blk_queue_lightnvm (q)) +nvm_complete_request (q->nvm, rq, error); +blk_account_io_done (rq);if (rq->end_io) {
@@ -1082,10 +1091,16 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)static void blk_mq_bio_to_request (struct request *rq,struct bio *bio) { +struct request_queue *q = rq->q; +init_request_from_bio (rq, bio);if (blk_do_io_stat (rq))blk_account_io_start (rq,1 ); + +/* TODO: error handling */ +if (blk_queue_lightnvm (q)) +blk_lightnvm_map (q->nvm, rq); }static inline bool hctx_allow_merges (struct blk_mq_hw_ctx *hctx)
@@ -1361,6 +1376,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,struct blk_mq_tags *tags;unsigned int i, j, entries_per_page, max_order =4 ;size_t rq_size, left; +unsigned int cmd_size = set->cmd_size; tags =blk_mq_init_tags (set->queue_depth, set->reserved_tags, set->numa_node);
@@ -1377,11 +1393,14 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,return NULL ; } +if (set->flags &BLK_MQ_F_LIGHTNVM ) + cmd_size +=nvm_cmd_size (); +/* * rq_size is the size of the request plus driver payload, rounded * to the cacheline size */ - rq_size =round_up (sizeof (struct request ) + set->cmd_size, + rq_size =round_up (sizeof (struct request ) + cmd_size,cache_line_size ()); left = rq_size * set->queue_depth;
@@ -1597,7 +1616,10 @@ static int blk_mq_init_hw_queues(struct request_queue *q, hctx->queue = q; hctx->queue_num = i; hctx->flags = set->flags; - hctx->cmd_size = set->cmd_size; +if (set->flags &BLK_MQ_F_LIGHTNVM ) + hctx->cmd_size = set->cmd_size +nvm_cmd_size (); +else + hctx->cmd_size = set->cmd_size;blk_mq_init_cpu_notifier (&hctx->cpu_notifier, blk_mq_hctx_notify, hctx);
@@ -1769,6 +1791,7 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)struct request_queue *q;unsigned int *map;int i; +unsigned int cmd_size = set->cmd_size; ctx = alloc_percpu(struct blk_mq_ctx);if (!ctx)
@@ -1823,6 +1846,11 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)if (!(set->flags &BLK_MQ_F_SG_MERGE )) q->queue_flags |=1 <<QUEUE_FLAG_NO_SG_MERGE ; +if (set->flags &BLK_MQ_F_LIGHTNVM ) { + q->queue_flags |=1 <<QUEUE_FLAG_LIGHTNVM ; + cmd_size +=nvm_cmd_size (); + } + q->sg_reserved_size =INT_MAX ;INIT_WORK (&q->requeue_work, blk_mq_requeue_work);
@@ -1850,8 +1878,7 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)blk_mq_init_cpu_queues (q, set->nr_hw_queues); q->flush_rq =kzalloc (round_up (sizeof (struct request ) + - set->cmd_size,cache_line_size ()), -GFP_KERNEL ); + cmd_size,cache_line_size ()),GFP_KERNEL );if (!q->flush_rq) goto err_hw;
block/blk-sysfs.c +13 -0
@@ -7,6 +7,7 @@#include <linux/bio.h> #include <linux/blkdev.h> #include <linux/blktrace_api.h> +#include <linux/lightnvm.h> #include <linux/blk-mq.h> #include "blk.h"
@@ -550,6 +551,10 @@ int blk_register_queue(struct gendisk *disk)if (WARN_ON (!q))return -ENXIO ; +/* FIXME: How to get from queue to disk (used by lightnvm gc)? */ +if (q->nvm) + q->nvm->disk = disk; +/* * Initialization must be complete by now. Finish the initial * bypass from queue allocation.
@@ -563,6 +568,10 @@ int blk_register_queue(struct gendisk *disk)if (ret)return ret; + ret =blk_lightnvm_init_sysfs (dev); +if (ret) +return ret; + ret =kobject_add (&q->kobj,kobject_get (&dev->kobj),"%s" ,"queue" );if (ret <0 ) {blk_trace_remove_sysfs (dev);
@@ -596,6 +605,9 @@ void blk_unregister_queue(struct gendisk *disk)if (WARN_ON (!q))return ; +if (q->nvm) +blk_lightnvm_unregister (q); +if (q->mq_ops)blk_mq_unregister_disk (disk);
@@ -604,6 +616,7 @@ void blk_unregister_queue(struct gendisk *disk)kobject_uevent (&q->kobj,KOBJ_REMOVE );kobject_del (&q->kobj); +blk_lightnvm_remove_sysfs (disk_to_dev (disk));blk_trace_remove_sysfs (disk_to_dev (disk));kobject_put (&disk_to_dev (disk)->kobj); }
block/blk.h +14 -0
@@ -252,4 +252,18 @@ static inline int blk_throtl_init(struct request_queue *q) { return 0; }static inline void blk_throtl_exit (struct request_queue *q) { }#endif /* CONFIG_BLK_DEV_THROTTLING */ +#ifdef CONFIG_LIGHTNVM +struct lightnvm_dev_ops ; + +extern void blk_lightnvm_unregister (struct request_queue *); +extern int blk_lightnvm_map (struct nvm_dev *nvm,struct request *rq); +extern int blk_lightnvm_init_sysfs (struct device *); +extern void blk_lightnvm_remove_sysfs (struct device *); +#else +static void blk_lightnvm_unregister (struct request_queue *q) { } +static int blk_lightnvm_map (struct nvm_dev *nvm,struct request *rq) {return -EINVAL ; } +static int blk_lightnvm_init_sysfs (struct device *) {return 0 ; } +static void blk_lightnvm_remove_sysfs (struct device *) { } +#endif /* CONFIG_LIGHTNVM */ +#endif /* BLK_INTERNAL_H */
block/ioctl.c +1 -0
@@ -7,6 +7,7 @@#include <linux/backing-dev.h> #include <linux/fs.h> #include <linux/blktrace_api.h> +#include <linux/lightnvm.h> #include <asm/uaccess.h> static int blkpg_ioctl (struct block_device *bdev,struct blkpg_ioctl_arg __user *arg)
drivers/Kconfig +2 -0
@@ -38,6 +38,8 @@ source "drivers/message/i2o/Kconfig" source "drivers/macintosh/Kconfig" +source "drivers/lightnvm/Kconfig" + source "drivers/net/Kconfig" source "drivers/isdn/Kconfig"
drivers/Makefile +1 -0
@@ -72,6 +72,7 @@ obj-$(CONFIG_MTD) += mtd/ obj-$(CONFIG_SPI) += spi/ obj-$(CONFIG_SPMI) += spmi/ obj-y += hsi/ +obj-$(CONFIG_LIGHTNVM) += lightnvm/ obj-y += net/ obj-$(CONFIG_ATM) += atm/ obj-$(CONFIG_FUSION) += message/
drivers/lightnvm/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# +# LightNVM configuration +# + +menuconfig LIGHTNVM + bool "LightNVM support" + depends on BLK_DEV + default y + ---help--- + Say Y here to get to enable Open-channel SSDs compatible with LightNVM + to be recognized. + + LightNVM implements some internals of SSDs within the host. + Devices are required to support LightNVM, and allow them to managed by + the host. LightNVM is used together with an open-channel firmware, that + exposes direct access to the underlying non-volatile memory. + + If you say N, all options in this submenu will be skipped and disabled; + only do this if you know what you are doing. +
drivers/lightnvm/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for LightNVM. +# + +obj-$(CONFIG_LIGHTNVM) += nvm.o core.o gc.o sysfs.o targets.o
drivers/lightnvm/core.c new file +208 -0
208 lines not on this page · raw message
drivers/lightnvm/gc.c new file +370 -0
370 lines not on this page · raw message
drivers/lightnvm/nvm.c new file +460 -0
460 lines not on this page · raw message
drivers/lightnvm/nvm.h new file +588 -0
588 lines not on this page · raw message
drivers/lightnvm/sysfs.c new file +68 -0
68 lines not on this page · raw message
drivers/lightnvm/targets.c new file +244 -0
244 lines not on this page · raw message
include/linux/blk-mq.h +1 -0
@@ -130,6 +130,7 @@ enum {BLK_MQ_F_TAG_SHARED =1 <<1 ,BLK_MQ_F_SG_MERGE =1 <<2 ,BLK_MQ_F_SYSFS_UP =1 <<3 , +BLK_MQ_F_LIGHTNVM =1 <<4 ,BLK_MQ_S_STOPPED =0 , BLK_MQ_S_TAG_ACTIVE = 1,
include/linux/blkdev.h +23 -0
@@ -208,6 +208,9 @@ struct request {/* for bidi */ struct request *next_rq; +#if CONFIG_LIGHTNVM +sector_t phys_sector; +#endif };static inline unsigned short req_get_ioprio (struct request *req)
@@ -304,6 +307,10 @@ struct queue_limits {unsigned char raid_partial_stripes_expensive; }; +#ifdef CONFIG_LIGHTNVM +#include <linux/lightnvm.h> +#endif +struct request_queue {/* * Together with queue_head for cacheline sharing
@@ -450,6 +457,9 @@ struct request_queue {#ifdef CONFIG_BLK_DEV_IO_TRACE struct blk_trace *blk_trace;#endif +#ifdef CONFIG_LIGHTNVM +struct nvm_dev *nvm; +#endif /* * for flush operations */
@@ -515,6 +525,7 @@ struct request_queue {#define QUEUE_FLAG_INIT_DONE 20/* queue is initialized */ #define QUEUE_FLAG_NO_SG_MERGE 21/* don't attempt to merge SG segments*/ #define QUEUE_FLAG_SG_GAPS 22/* queue doesn't support SG gaps */ +#define QUEUE_FLAG_LIGHTNVM 23/* lightnvm managed queue */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_STACKABLE) | \
@@ -602,6 +613,7 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)#define blk_queue_discard (q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)#define blk_queue_secdiscard (q) (blk_queue_discard(q) && \ test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags)) +#define blk_queue_lightnvm (q) test_bit(QUEUE_FLAG_LIGHTNVM, &(q)->queue_flags)#define blk_noretry_request (rq) \ ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
@@ -1610,6 +1622,17 @@ static inline bool blk_integrity_is_initialized(struct gendisk *g)#endif /* CONFIG_BLK_DEV_INTEGRITY */ +#ifdef CONFIG_LIGHTNVM +struct lightnvm_dev_ops ; +extern int blk_lightnvm_register (struct request_queue *,struct lightnvm_dev_ops *); +#else +struct lightnvm_dev_ops ; +static int blk_lightnvm_register (struct request_queue *q,struct lightnvm_dev_ops *ops) +{ +return -EINVAL ; +} +#endif /* CONFIG_LIGHTNVM */ +struct block_device_operations {int (*open) (struct block_device *,fmode_t );void (*release) (struct gendisk *,fmode_t );
include/linux/lightnvm.h new file +112 -0
112 lines not on this page · raw message
include/trace/events/nvm.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH 4/5 nvme: LightNVM integration
In reply to Matias BjørlingNVMe devices are identified by the vendor specific bits:
Bit 3 in OACS (device-wide). Currently made per device, as the nvme namespace is missing in the completion path. This is _not_ to be kept and only added temponarily. Only added to hint blk-mq that it should reserve space in the per-request private data field for LightNVM.
Bit 1 in DSM (per-namespace).
From there, the NVMe specification is extended with the following commands:
LightNVM Identify
LightNVM Get Features
LightNVM Set Responsibility
LightNVM Synchronious/Asynchronious erase
LightNVM Get Logical to Physical map
The NVMe integration can be tested using Keith Busch NVMe qemu simulator with LightNVM patches on top. This can be found at:
https://github.com/OpenChannelSSD/qemu-nvme
Contributions in this patch from:
Jesper Madsen <[email protected]>
--- drivers/block/nvme-core.c | 187 +++++++++++++++++++++++++++++++++++++++++++++- include/linux/nvme.h | 1 + include/uapi/linux/nvme.h | 74 ++++++++++++++++++ 3 files changed, 261 insertions(+), 1 deletion(-)
drivers/block/nvme-core.c +186 -1
@@ -38,6 +38,7 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/lightnvm.h> #include <scsi/sg.h> #include <asm-generic/io-64-nonatomic-lo-hi.h>
@@ -129,6 +130,7 @@ static inline void _nvme_check_size(void)BUILD_BUG_ON (sizeof (struct nvme_id_ns ) !=4096 );BUILD_BUG_ON (sizeof (struct nvme_lba_range_type ) !=64 );BUILD_BUG_ON (sizeof (struct nvme_smart_log ) !=512 ); +BUILD_BUG_ON (sizeof (struct nvme_lnvm_rw_command ) !=64 ); } typedef void (*nvme_completion_fn)(struct nvme_queue *, void *,
@@ -560,6 +562,9 @@ static int nvme_submit_iod(struct nvme_queue *nvmeq, struct nvme_iod *iod, cmnd->rw.control =cpu_to_le16 (control); cmnd->rw.dsmgmt =cpu_to_le32 (dsmgmt); +if (req->cmd_flags &REQ_NVM_MAPPED ) + cmnd->lnvm_rw.phys_addr =cpu_to_le64 (req->phys_sector +1 ); +if (++nvmeq->sq_tail == nvmeq->q_depth) nvmeq->sq_tail =0 ;writel (nvmeq->sq_tail, nvmeq->q_db);
@@ -576,6 +581,7 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)enum dma_data_direction dma_dir;int psegs = req->nr_phys_segments;int result =BLK_MQ_RQ_QUEUE_BUSY ; +/* * Requeued IO has already been prepped */
@@ -895,6 +901,43 @@ static int adapter_delete_sq(struct nvme_dev *dev, u16 sqid)return adapter_delete_queue (dev, nvme_admin_delete_sq, sqid); } +int lnvm_identify (struct nvme_dev *dev,u32 chnl_off,dma_addr_t dma_addr) +{ +struct nvme_command c; + +memset (&c,0 ,sizeof (c)); + c.common.opcode = lnvm_admin_identify; + c.common.nsid =cpu_to_le32 (chnl_off); + c.common.prp1 =cpu_to_le64 (dma_addr); + +return nvme_submit_admin_cmd (dev, &c,NULL ); +} + +int lnvm_get_features (struct nvme_dev *dev,unsigned nsid,dma_addr_t dma_addr) +{ +struct nvme_command c; + +memset (&c,0 ,sizeof (c)); + c.common.opcode = lnvm_admin_get_features; + c.common.nsid =cpu_to_le32 (nsid); + c.common.prp1 =cpu_to_le64 (dma_addr); + +return nvme_submit_admin_cmd (dev, &c,NULL ); +} + +int lnvm_set_responsibility (struct nvme_dev *dev,unsigned nsid, +dma_addr_t dma_addr) +{ +struct nvme_command c; + +memset (&c,0 ,sizeof (c)); + c.common.opcode = lnvm_admin_set_responsibility; + c.common.nsid =cpu_to_le32 (nsid); + c.common.prp1 =cpu_to_le64 (dma_addr); + +return nvme_submit_admin_cmd (dev, &c,NULL ); +} +int nvme_identify (struct nvme_dev *dev,unsigned nsid,unsigned cns,dma_addr_t dma_addr) {
@@ -1282,6 +1325,99 @@ static int nvme_shutdown_ctrl(struct nvme_dev *dev)return 0 ; } +static int init_chnls (struct nvme_dev *dev,struct nvm_id *nvm_id, +struct nvme_lnvm_id *dma_buf,dma_addr_t dma_addr) +{ +struct nvme_lnvm_id_chnl *src = dma_buf->chnls; +struct nvm_id_chnl *dst = nvm_id->chnls; +unsigned int len = nvm_id->nchannels; +int i, end, off =0 ; + +while (len) { + end =min_t (u32,NVME_LNVM_CHNLS_PR_REQ , len); + +for (i =0 ; i < end; i++, dst++, src++) { + dst->queue_size =le64_to_cpu (src->queue_size); + dst->gran_read =le64_to_cpu (src->gran_read); + dst->gran_write =le64_to_cpu (src->gran_write); + dst->gran_erase =le64_to_cpu (src->gran_erase); + dst->oob_size =le64_to_cpu (src->oob_size); + dst->t_r =le32_to_cpu (src->t_r); + dst->t_sqr =le32_to_cpu (src->t_sqr); + dst->t_w =le32_to_cpu (src->t_w); + dst->t_sqw =le32_to_cpu (src->t_sqw); + dst->t_e =le32_to_cpu (src->t_e); + dst->io_sched = src->io_sched; + dst->laddr_begin =le64_to_cpu (src->laddr_begin); + dst->laddr_end =le64_to_cpu (src->laddr_end); + } + + len -= end; +if (!len) +break ; + + off += end; + +if (lnvm_identify (dev, off, dma_addr)) +return -EIO ; + + src = dma_buf->chnls; + } +return 0 ; +} + +static int nvme_nvm_id (struct request_queue *q,struct nvm_id *nvm_id) +{ +struct nvme_ns *ns = q->queuedata; +struct nvme_dev *dev = ns->dev; +struct pci_dev *pdev = dev->pci_dev; +struct nvme_lnvm_id *ctrl; +dma_addr_t dma_addr; +unsigned int ret; + + ctrl =dma_alloc_coherent (&pdev->dev,4096 , &dma_addr,GFP_KERNEL ); +if (!ctrl) +return -ENOMEM ; + + ret =lnvm_identify (dev,0 , dma_addr); +if (ret) { + ret = -EIO ; + goto out; + } + + nvm_id->ver_id =le16_to_cpu (ctrl->ver_id); + nvm_id->nvm_type = ctrl->nvm_type; + nvm_id->nchannels =le16_to_cpu (ctrl->nchannels); + +if (!nvm_id->chnls) + nvm_id->chnls =kmalloc (sizeof (struct nvm_id_chnl ) + * nvm_id->nchannels,GFP_KERNEL ); + +if (!nvm_id->chnls) { + ret = -ENOMEM ; + goto out; + } + + ret =init_chnls (dev, nvm_id, ctrl, dma_addr); +out: +dma_free_coherent (&pdev->dev,4096 , ctrl, dma_addr); +return ret; +} + +static int nvme_nvm_get_features (struct request_queue *q, +struct nvm_get_features *gf) +{ + gf->rsp[0 ] = (1 <<NVM_RSP_L2P ); + gf->rsp[0 ] |= (1 <<NVM_RSP_P2L ); + gf->rsp[0 ] |= (1 <<NVM_RSP_GC ); +return 0 ; +} + +static int nvme_nvm_set_rsp (struct request_queue *q,u8 rsp,u8 val) +{ +return NVM_RID_NOT_CHANGEABLE |NVM_DNR ; +} +static struct blk_mq_ops nvme_mq_admin_ops = { .queue_rq = nvme_admin_queue_rq, .map_queue = blk_mq_map_queue,
@@ -1290,6 +1426,12 @@ static struct blk_mq_ops nvme_mq_admin_ops = { .timeout = nvme_timeout, }; +static struct lightnvm_dev_ops nvme_nvm_dev_ops = { + .identify = nvme_nvm_id, + .get_features = nvme_nvm_get_features, + .set_responsibility = nvme_nvm_set_rsp, +}; +static struct blk_mq_ops nvme_mq_ops = { .queue_rq = nvme_queue_rq, .map_queue = blk_mq_map_queue,
@@ -1455,6 +1597,26 @@ void nvme_unmap_user_pages(struct nvme_dev *dev, int write,put_page (sg_page (&iod->sg[i])); } +static int nvme_nvm_submit_io (struct nvme_ns *ns,struct nvme_user_io *io) +{ +struct nvme_command c; +struct nvme_dev *dev = ns->dev; + +memset (&c,0 ,sizeof (c)); + c.rw.opcode = io->opcode; + c.rw.flags = io->flags; + c.rw.nsid =cpu_to_le32 (ns->ns_id); + c.rw.slba =cpu_to_le64 (io->slba); + c.rw.length =cpu_to_le16 (io->nblocks); + c.rw.control =cpu_to_le16 (io->control); + c.rw.dsmgmt =cpu_to_le32 (io->dsmgmt); + c.rw.reftag =cpu_to_le32 (io->reftag); + c.rw.apptag =cpu_to_le16 (io->apptag); + c.rw.appmask =cpu_to_le16 (io->appmask); + +return nvme_submit_io_cmd (dev, ns, &c,NULL ); +} +static int nvme_submit_io (struct nvme_ns *ns,struct nvme_user_io __user *uio) {struct nvme_dev *dev = ns->dev;
@@ -1480,6 +1642,10 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)case nvme_cmd_compare: iod =nvme_map_user_pages (dev, io.opcode &1 , io.addr, length);break ; +case lnvm_admin_identify: +case lnvm_admin_get_features: +case lnvm_admin_set_responsibility: +return nvme_nvm_submit_io (ns, &io);default :return -EINVAL ; }
@@ -1769,7 +1935,6 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid, ns->queue =blk_mq_init_queue (&dev->tagset);if (!ns->queue) goto out_free_ns; -queue_flag_set_unlocked (QUEUE_FLAG_DEFAULT , ns->queue);queue_flag_set_unlocked (QUEUE_FLAG_NOMERGES , ns->queue);queue_flag_set_unlocked (QUEUE_FLAG_NONROT , ns->queue);queue_flag_set_unlocked (QUEUE_FLAG_SG_GAPS , ns->queue);
@@ -1807,8 +1972,18 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,if (dev->oncs &NVME_CTRL_ONCS_DSM )nvme_config_discard (ns); +if (id->nsfeat &NVME_NS_FEAT_LIGHTNVM ) { +if (blk_lightnvm_register (ns->queue, &nvme_nvm_dev_ops)) + goto out_put_disk; + +/* FIXME: This will be handled later by ns */ + ns->queue->nvm->drv_cmd_size =sizeof (struct nvme_cmd_info ); + } +return ns; + out_put_disk: +put_disk (disk); out_free_queue:blk_cleanup_queue (ns->queue); out_free_ns:
@@ -1954,6 +2129,7 @@ static int nvme_dev_add(struct nvme_dev *dev) ctrl = mem; nn =le32_to_cpup (&ctrl->nn); dev->oncs =le16_to_cpup (&ctrl->oncs); + dev->oacs =le16_to_cpup (&ctrl->oacs); dev->abort_limit = ctrl->acl +1 ; dev->vwc = ctrl->vwc;memcpy (dev->serial, ctrl->sn,sizeof (ctrl->sn));
@@ -1983,6 +2159,15 @@ static int nvme_dev_add(struct nvme_dev *dev) dev->tagset.flags =BLK_MQ_F_SHOULD_MERGE ; dev->tagset.driver_data = dev; +/* LightNVM is actually per ns, but as the tagset is defined with a set +* of operations for the whole device. It currently is either all or +* no lightnvm compatible name-spaces for a given device. +*/ +if (dev->oacs &NVME_CTRL_OACS_LIGHTNVM ) { + dev->tagset.flags &= ~BLK_MQ_F_SHOULD_MERGE ; + dev->tagset.flags |=BLK_MQ_F_LIGHTNVM ; + } +if (blk_mq_alloc_tag_set (&dev->tagset)) goto out;
include/linux/nvme.h +1 -0
@@ -100,6 +100,7 @@ struct nvme_dev {u32 max_hw_sectors;u32 stripe_size;u16 oncs; +u16 oacs;u16 abort_limit;u8 vwc;u8 initialized;
include/uapi/linux/nvme.h +74 -0
117 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH 5/5 null_blk: LightNVM integration
In reply to Matias BjørlingAllows the null_blk driver to hook into LightNVM for performance evaluation.
It is activated by passing lightnvm_enable parameter at module load.
The number of channels exposed to LightNVM can be configured through the lightnvm_num_channels module parameter.
Contributions in this patch from:
Jesper Madsen <[email protected]>
--- Documentation/block/null_blk.txt | 8 ++++ drivers/block/null_blk.c | 89 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 92 insertions(+), 5 deletions(-)
Documentation/block/null_blk.txt +8 -0
@@ -70,3 +70,11 @@ use_per_node_hctx=[0/1]: Default: 0 parameter. 1: The multi-queue block layer is instantiated with a hardware dispatch queue for each CPU node in the system. + +IV: LightNVM specific parameters + +lightnvm_enable=[x]: Default: 0 + Enable LightNVM for null block devices. Requires blk-mq to be used. + +lightnvm_num_channels=[x]: Default: 1 + Number of LightNVM channels that are exposed to the LightNVM driver.
drivers/block/null_blk.c +84 -5
135 lines not on this page · raw message
Signature · 1 line
1.9.1