Skip to contentSkip to conversation

Support for Open-Channel SSDs

PATCH Superseded Matias Bjørling 6 participants 23 messages Apr 15, 2015 – Apr 19, 2015

Subsystems (4)

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support for Open-Channel SSDs

A problem with SSDs is that they expose a narrow read/write interface, where the host and device must communicate their intent. The narrow interface leaves little information to be carried down from file-systems and applications, and therefore performance guarantees in these devices are best-efforts.

In the case of SSDs, there are various approaches to mitigate it. Examples include trim and multi-streams. However, these approaches are specialized by each vendor, each having their own behavior. More importantly, they do not allow the host to completely control data placement, parallelism and garbage collection.

By exposing the physical characteristics of an SSD to the host, file-systems and applications can directly place data and control when and where garbage collection should be applied. We call the class of SSDs that expose these physical characteristics Open-Channel SSDs.

For this class of SSDs, LightNVM is a specification that defines a common interface. It allows the host to manage data placement, garbage collection, and parallelism. With it, the kernel can expose a building block for further integration into file-systems and applications. Immediate benefits include strict control of access latency and IO response variance.

This patchset wires up support in the block layer, introduces a simple block device target called rrpc, and at last adds support in the null_blk and NVMe drivers.

Patches are against v4.0.

Development and further information on LightNVM can be found at:

https://github.com/OpenChannelSSD/linux

Changes since v1:

- Splitted LightNVM into two parts. A get/put interface for flash blocks and the respective targets that implement flash translation layer logic.
- Updated the patches accordring to the LightNVM specification changes.
- Added interface to add/remove targets for a block device.

Matias Bjørling (5):
blk-mq: Add prep/unprep support
blk-mq: Support for Open-Channel SSDs
lightnvm: RRPC target
null_blk: LightNVM support
nvme: LightNVM support

 Documentation/block/null_blk.txt |    8 +
 block/Kconfig                    |   12 +
 block/Makefile                   |    2 +-
 block/blk-mq.c                   |   40 +-
 block/blk-nvm.c                  |  722 ++++++++++++++++++++++
 block/blk-sysfs.c                |   11 +
 block/blk.h                      |   18 +
 drivers/Kconfig                  |    2 +
 drivers/Makefile                 |    2 +
 drivers/block/null_blk.c         |   89 ++-
 drivers/block/nvme-core.c        |  380 +++++++++++-
 drivers/lightnvm/Kconfig         |   29 +
 drivers/lightnvm/Makefile        |    5 +
 drivers/lightnvm/rrpc.c          | 1222 ++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.h          |  203 +++++++
 include/linux/bio.h              |    9 +
 include/linux/blk-mq.h           |    3 +
 include/linux/blk_types.h        |   12 +-
 include/linux/blkdev.h           |  218 +++++++
 include/linux/lightnvm.h         |   55 ++
 include/linux/nvme.h             |    2 +
 include/uapi/linux/nvm.h         |   70 +++
 include/uapi/linux/nvme.h        |  116 ++++
 23 files changed, 3217 insertions(+), 13 deletions(-)
 create mode 100644 block/blk-nvm.c
 create mode 100644 drivers/lightnvm/Kconfig
 create mode 100644 drivers/lightnvm/Makefile
 create mode 100644 drivers/lightnvm/rrpc.c
 create mode 100644 drivers/lightnvm/rrpc.h
 create mode 100644 include/linux/lightnvm.h
 create mode 100644 include/uapi/linux/nvm.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 1/5 blk-mq: Add prep/unprep support

Allow users to hook into prep/unprep functions just before an IO is dispatched to the device driver. This is necessary for request-based logic to take place at upper layers.

---
 block/blk-mq.c         | 28 ++++++++++++++++++++++++++--
 include/linux/blk-mq.h |  1 +
 2 files changed, 27 insertions(+), 2 deletions(-)
block/blk-mq.c +26 -2
index 33c4285..f3dd028 100644
@@ -338,6 +338,11 @@ EXPORT_SYMBOL(__blk_mq_end_request);
 
 void blk_mq_end_request(struct request *rq, int error)
 {
+	struct request_queue *q = rq->q;
+
+	if (q->unprep_rq_fn)
+		q->unprep_rq_fn(q, rq);
+
 	if (blk_update_request(rq, error, blk_rq_bytes(rq)))
 		BUG();
 	__blk_mq_end_request(rq, error);
@@ -753,6 +758,17 @@ static void flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list)
 	}
 }
 
+static int blk_mq_prep_rq(struct request_queue *q, struct request *rq)
+{
+	if (!q->prep_rq_fn)
+		return 0;
+
+	if (rq->cmd_flags & REQ_DONTPREP)
+		return 0;
+
+	return q->prep_rq_fn(q, rq);
+}
+
 /*
  * Run this hardware queue, pulling any software queues mapped to it in.
  * Note that this function currently has various problems around ordering
@@ -812,11 +828,15 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
 		bd.list = dptr;
 		bd.last = list_empty(&rq_list);
 
-		ret = q->mq_ops->queue_rq(hctx, &bd);
+		ret = blk_mq_prep_rq(q, rq);
+		if (likely(!ret))
+			ret = q->mq_ops->queue_rq(hctx, &bd);
 		switch (ret) {
 		case BLK_MQ_RQ_QUEUE_OK:
 			queued++;
 			continue;
+		case BLK_MQ_RQ_QUEUE_DONE:
+			continue;
 		case BLK_MQ_RQ_QUEUE_BUSY:
 			list_add(&rq->queuelist, &rq_list);
 			__blk_mq_requeue_request(rq);
@@ -1270,10 +1290,14 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		 * error (busy), just add it to our list as we previously
 		 * would have done
 		 */
-		ret = q->mq_ops->queue_rq(data.hctx, &bd);
+		ret = blk_mq_prep_rq(q, rq);
+		if (likely(!ret))
+			ret = q->mq_ops->queue_rq(data.hctx, &bd);
 		if (ret == BLK_MQ_RQ_QUEUE_OK)
 			goto done;
 		else {
+			if (ret == BLK_MQ_RQ_QUEUE_DONE)
+				goto done;
 			__blk_mq_requeue_request(rq);
 
 			if (ret == BLK_MQ_RQ_QUEUE_ERROR) {
include/linux/blk-mq.h +1 -0
index 7aec861..d7b39af 100644
@@ -140,6 +140,7 @@ enum {
 	BLK_MQ_RQ_QUEUE_OK	= 0,	/* queued fine */
 	BLK_MQ_RQ_QUEUE_BUSY	= 1,	/* requeue IO for later */
 	BLK_MQ_RQ_QUEUE_ERROR	= 2,	/* end IO with error */
+	BLK_MQ_RQ_QUEUE_DONE	= 3,	/* IO is already handled */
 
 	BLK_MQ_F_SHOULD_MERGE	= 1 << 0,
 	BLK_MQ_F_TAG_SHARED	= 1 << 1,
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/5 v2] blk-mq: Add prep/unprep support

Quoted 3 lines · Matias Bj??rling

Allow users to hook into prep/unprep functions just before an IO is dispatched to the device driver. This is necessary for request-based logic to take place at upper layers.

I don't think any of this logic belongs into the block layer. All this should be library functions called by the drivers.

#3 lore raw

Re: [PATCH 1/5 v2] blk-mq: Add prep/unprep support

Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Matias Bj??rling

Allow users to hook into prep/unprep functions just before an IO is dispatched to the device driver. This is necessary for request-based logic to take place at upper layers.

I don't think any of this logic belongs into the block layer. All this should be library functions called by the drivers.

Just the prep/unprep, or other pieces as well?

I like that struct request_queue has a ref to struct nvm_dev, and the variables in request and bio to get to the struct is in the block layer.

In the future, applications can have an API to get/put flash block directly. (using the blk_nvm_[get/put]_blk interface).

#4 lore raw

Re: [PATCH 1/5 v2] blk-mq: Add prep/unprep support

Quoted 1 line · Matias Bj?rling

Just the prep/unprep, or other pieces as well?

All of it - it's functionality that lies logically below the block layer, so that's where it should be handled.

In fact it should probably work similar to the mtd subsystem - that is have it's own API for low level drivers, and just export a block driver as one consumer on the top side.

Quoted 2 lines

In the future, applications can have an API to get/put flash block directly. (using the blk_nvm_[get/put]_blk interface).

s/application/filesystem/?

#5 lore raw

Re: [PATCH 1/5 v2] blk-mq: Add prep/unprep support

Den 17-04-2015 kl. 19:46 skrev Christoph Hellwig:

Quoted 9 lines · Matias Bj?rling
Quoted 1 line

Just the prep/unprep, or other pieces as well?

All of it - it's functionality that lies logically below the block layer, so that's where it should be handled.

In fact it should probably work similar to the mtd subsystem - that is have it's own API for low level drivers, and just export a block driver as one consumer on the top side.

The low level drivers will be NVMe and vendor's own PCI-e drivers. It's very generic in their nature. Each driver would duplicate the same work. Both could have normal and open-channel drives attached.

I'll like to keep blk-mq in the loop. I don't think it will be pretty to have two data paths in the drivers. For blk-mq, bios are splitted/merged on the way down. Thus, the actual physical addresses needs aren't known before the IO is diced to the right size.

The reason it shouldn't be under the a single block device, is that a target should be able to provide a global address space. That allows the address space to grow/shrink dynamically with the disks. Allowing a continuously growing address space, where disks can be added/removed as requirements grow or flash ages. Not on a sector level, but on a flash block level.

Quoted 6 lines
Quoted 3 lines

In the future, applications can have an API to get/put flash block directly. (using the blk_nvm_[get/put]_blk interface).

s/application/filesystem/?

Applications. The goal is that key value stores, e.g. RocksDB, Aerospike, Ceph and similar have direct access to flash storage. There won't be a kernel file-system between.

The get/put interface can be seen as a space reservation interface for where a given process is allowed to access the storage media.

It can also be seen in the way that we provide a block allocator in the kernel, while applications implement the rest of "file-system" in user-space, specially optimized for their data structures. This makes a lot of sense for a small subset (LSM, Fractal trees, etc.) of database applications.

#6 lore raw

Re: [PATCH 1/5 v2] blk-mq: Add prep/unprep support

Quoted 3 lines · Matias Bjorling

The low level drivers will be NVMe and vendor's own PCI-e drivers. It's very generic in their nature. Each driver would duplicate the same work. Both could have normal and open-channel drives attached.

I didn't say the work should move into the driver, bur rather that driver should talk to the open channel ssd code directly instead of hooking into the core block code.

Quoted 4 lines

I'll like to keep blk-mq in the loop. I don't think it will be pretty to have two data paths in the drivers. For blk-mq, bios are splitted/merged on the way down. Thus, the actual physical addresses needs aren't known before the IO is diced to the right size.

But you _do_ have two different data path already. Nothing says you can't use blk-mq for your data path, ut it should be a separate entry point. Similar to say how a SCSI disk and MMC device both use the block layer but still use different entry points.

Quoted 6 lines

The reason it shouldn't be under the a single block device, is that a target should be able to provide a global address space.
That allows the address
space to grow/shrink dynamically with the disks. Allowing a continuously growing address space, where disks can be added/removed as requirements grow or flash ages. Not on a sector level, but on a flash block level.

I don't understand what you mean with a single block device here, but I suspect we're talking past each other somehow.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

In the future, applications can have an API to get/put flash block directly. (using the blk_nvm_[get/put]_blk interface).

s/application/filesystem/?

Applications. The goal is that key value stores, e.g. RocksDB, Aerospike, Ceph and similar have direct access to flash storage. There won't be a kernel file-system between.

Quoted 8 lines

The get/put interface can be seen as a space reservation interface for where a given process is allowed to access the storage media.

It can also be seen in the way that we provide a block allocator in the kernel, while applications implement the rest of "file-system" in user-space, specially optimized for their data structures. This makes a lot of sense for a small subset (LSM, Fractal trees, etc.) of database applications.

While we'll need a proper API for that first it's just another reason of why we shouldnt shoe horn the open channel ssd support into the block layer.

#7 lore raw

Re: [PATCH 1/5 v2] blk-mq: Add prep/unprep support

Quoted 1 line · Matias Bjorling

<snip>

Quoted 9 lines
Quoted 6 lines

The reason it shouldn't be under the a single block device, is that a target should be able to provide a global address space.
That allows the address
space to grow/shrink dynamically with the disks. Allowing a continuously growing address space, where disks can be added/removed as requirements grow or flash ages. Not on a sector level, but on a flash block level.

I don't understand what you mean with a single block device here, but I suspect we're talking past each other somehow.

Sorry. I meant that several block devices should form a single address space (exposed as a single block device), consisting of all the flash blocks. Applications could then get/put from that.

Thanks for your feedback. I'll push the pieces around and make the integration self-contained outside of the block layer.

#8 lore raw

PATCH v2 2/5 blk-mq: Support for Open-Channel SSDs

In reply to Matias Bjørling

Open-channel SSDs are devices that share responsibilities with the host in order to implement and maintain features that typical SSDs keep strictly in firmware. These include (i) the Flash Translation Layer (FTL), (ii) bad block management, and (iii) hardware units such as the flash controller, the interface controller, and large amounts of flash chips. In this way, Open-channels SSDs exposes direct access to their physical flash storage, while keeping a subset of the internal features of SSDs.

LightNVM is a specification that gives support to Open-channel SSDs LightNVM allows the host to manage data placement, garbage collection, and parallelism. Device specific responsibilities such as bad block management, FTL extensions to support atomic IOs, or metadata persistence are still handled by the device.

The implementation of LightNVM consists of two parts: core and (multiple) targets. The core implements functionality shared across targets. This is initialization, teardown and statistics. The targets implement the interface that exposes physical flash to user-space applications. Examples of such targets include key-value store, object-store, as well as traditional block devices, which can be application-specific.

Contributions in this patch from:

Javier Gonzalez <javier at paletta.io>
Jesper Madsen <jmad at itu.dk>

Signed-off-by Matias Bj?rling <m at bjorling.me>
---
 block/Kconfig             |  12 +
 block/Makefile            |   2 +-
 block/blk-mq.c            |  12 +-
 block/blk-nvm.c           | 722 ++++++++++++++++++++++++++++++++++++++++++++++
 block/blk-sysfs.c         |  11 +
 block/blk.h               |  18 ++
 include/linux/bio.h       |   9 +
 include/linux/blk-mq.h    |   4 +-
 include/linux/blk_types.h |  12 +-
 include/linux/blkdev.h    | 218 ++++++++++++++
 include/linux/lightnvm.h  |  56 ++++
 include/uapi/linux/nvm.h  |  70 +++++
 12 files changed, 1140 insertions(+), 6 deletions(-)
 create mode 100644 block/blk-nvm.c
 create mode 100644 include/linux/lightnvm.h
 create mode 100644 include/uapi/linux/nvm.h
block/Kconfig +12 -0
index 161491d..a3fca8f 100644
@@ -88,6 +88,18 @@ config BLK_DEV_INTEGRITY
 	T10/SCSI Data Integrity Field or the T13/ATA External Path
 	Protection.  If in doubt, say N.
 
+config BLK_DEV_NVM
+	bool "Block layer Open-Channel SSD support"
+	depends on BLK_DEV
+	default y
+	---help---
+	  Say Y here to get to enable support for Open-channel SSDs.
+
+	  Open-Channel SSDs expose direct access to the underlying non-volatile
+	  memory.
+
+	  This option is required by Open-Channel SSD target drivers.
+
 config BLK_DEV_THROTTLING
 	bool "Block layer bio throttling support"
 	depends on BLK_CGROUP=y
block/Makefile +1 -1
index 00ecc97..66a5826 100644
@@ -22,4 +22,4 @@ obj-$(CONFIG_IOSCHED_CFQ)	+= cfq-iosched.o
 obj-$(CONFIG_BLOCK_COMPAT)	+= compat_ioctl.o
 obj-$(CONFIG_BLK_CMDLINE_PARSER)	+= cmdline-parser.o
 obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o
-
+obj-$(CONFIG_BLK_DEV_NVM)  += blk-nvm.o
block/blk-mq.c +11 -1
index f3dd028..58a8a71 100644
@@ -221,6 +221,9 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
 	rq->end_io = NULL;
 	rq->end_io_data = NULL;
 	rq->next_rq = NULL;
+#if CONFIG_BLK_DEV_NVM
+	rq->phys_sector = 0;
+#endif
 
 	ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
 }
@@ -1445,6 +1448,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,
@@ -1462,11 +1466,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_NVM)
+		cmd_size += sizeof(struct nvm_per_rq);
+
 	/*
 	 * 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;
 
@@ -1978,6 +1985,9 @@ 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_NVM)
+		q->queue_flags |= 1 << QUEUE_FLAG_NVM;
+
 	q->sg_reserved_size = INT_MAX;
 
 	INIT_WORK(&q->requeue_work, blk_mq_requeue_work);
block/blk-nvm.c new file +722 -0

722 lines not on this page · raw message

block/blk-sysfs.c +11 -0
index faaf36a..ad8cf2f 100644
@@ -568,6 +568,12 @@ int blk_register_queue(struct gendisk *disk)
 	if (ret)
 		return ret;
 
+	if (blk_queue_nvm(q)) {
+		ret = blk_nvm_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);
@@ -601,6 +607,11 @@ void blk_unregister_queue(struct gendisk *disk)
 	if (WARN_ON(!q))
 		return;
 
+	if (blk_queue_nvm(q)) {
+		blk_nvm_unregister(q);
+		blk_nvm_remove_sysfs(disk_to_dev(disk));
+	}
+
 	if (q->mq_ops)
 		blk_mq_unregister_disk(disk);
 
block/blk.h +18 -0
index 43b0361..3e4abee 100644
@@ -281,4 +281,22 @@ 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_BLK_DEV_NVM
+struct nvm_target {
+	struct list_head list;
+	struct nvm_target_type *type;
+	struct gendisk *disk;
+};
+
+struct nvm_dev_ops;
+
+extern void blk_nvm_unregister(struct request_queue *);
+extern int blk_nvm_init_sysfs(struct device *);
+extern void blk_nvm_remove_sysfs(struct device *);
+#else
+static void blk_nvm_unregister(struct request_queue *q) { }
+static int blk_nvm_init_sysfs(struct device *) { return 0; }
+static void blk_nvm_remove_sysfs(struct device *) { }
+#endif /* CONFIG_BLK_DEV_NVM */
+
 #endif /* BLK_INTERNAL_H */
include/linux/bio.h +9 -0
index da3a127..ace0b23 100644
@@ -354,6 +354,15 @@ static inline void bip_set_seed(struct bio_integrity_payload *bip,
 
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
+#if defined(CONFIG_BLK_DEV_NVM)
+
+/* bio open-channel ssd payload */
+struct bio_nvm_payload {
+	void *private;
+};
+
+#endif /* CONFIG_BLK_DEV_NVM */
+
 extern void bio_trim(struct bio *bio, int offset, int size);
 extern struct bio *bio_split(struct bio *bio, int sectors,
 			     gfp_t gfp, struct bio_set *bs);
include/linux/blk-mq.h +3 -1
index d7b39af..75e1497 100644
@@ -140,13 +140,15 @@ enum {
 	BLK_MQ_RQ_QUEUE_OK	= 0,	/* queued fine */
 	BLK_MQ_RQ_QUEUE_BUSY	= 1,	/* requeue IO for later */
 	BLK_MQ_RQ_QUEUE_ERROR	= 2,	/* end IO with error */
-	BLK_MQ_RQ_QUEUE_DONE	= 3,	/* IO is already handled */
+	BLK_MQ_RQ_QUEUE_DONE	= 3,	/* IO handled by prep */
 
 	BLK_MQ_F_SHOULD_MERGE	= 1 << 0,
 	BLK_MQ_F_TAG_SHARED	= 1 << 1,
 	BLK_MQ_F_SG_MERGE	= 1 << 2,
 	BLK_MQ_F_SYSFS_UP	= 1 << 3,
 	BLK_MQ_F_DEFER_ISSUE	= 1 << 4,
+	BLK_MQ_F_NVM		= 1 << 5,
+
 	BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
 	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
 
include/linux/blk_types.h +9 -3
index a1b25e3..a619844 100644
@@ -83,7 +83,10 @@ struct bio {
 		struct bio_integrity_payload *bi_integrity; /* data integrity */
 #endif
 	};
-
+#if defined(CONFIG_BLK_DEV_NVM)
+	struct bio_nvm_payload *bi_nvm; /* open-channel ssd
+								     support */
+#endif
 	unsigned short		bi_vcnt;	/* how many bio_vec's */
 
 	/*
@@ -193,6 +196,8 @@ enum rq_flag_bits {
 	__REQ_HASHED,		/* on IO scheduler merge hash */
 	__REQ_MQ_INFLIGHT,	/* track inflight for MQ */
 	__REQ_NO_TIMEOUT,	/* requests may never expire */
+	__REQ_NVM_MAPPED,	/* NVM mapped this request */
+	__REQ_NVM_NO_INFLIGHT,	/* request should not use inflight protection */
 	__REQ_NR_BITS,		/* stops here */
 };
 
@@ -213,7 +218,7 @@ enum rq_flag_bits {
 #define REQ_COMMON_MASK \
 	(REQ_WRITE | REQ_FAILFAST_MASK | REQ_SYNC | REQ_META | REQ_PRIO | \
 	 REQ_DISCARD | REQ_WRITE_SAME | REQ_NOIDLE | REQ_FLUSH | REQ_FUA | \
-	 REQ_SECURE | REQ_INTEGRITY)
+	 REQ_SECURE | REQ_INTEGRITY | REQ_NVM_NO_INFLIGHT)
 #define REQ_CLONE_MASK		REQ_COMMON_MASK
 
 #define BIO_NO_ADVANCE_ITER_MASK	(REQ_DISCARD|REQ_WRITE_SAME)
@@ -247,5 +252,6 @@ enum rq_flag_bits {
 #define REQ_HASHED		(1ULL << __REQ_HASHED)
 #define REQ_MQ_INFLIGHT		(1ULL << __REQ_MQ_INFLIGHT)
 #define REQ_NO_TIMEOUT		(1ULL << __REQ_NO_TIMEOUT)
-
+#define REQ_NVM_MAPPED		(1ULL << __REQ_NVM_MAPPED)
+#define REQ_NVM_NO_INFLIGHT	(1ULL << __REQ_NVM_NO_INFLIGHT)
 #endif /* __LINUX_BLK_TYPES_H */
include/linux/blkdev.h +218 -0

272 lines not on this page · raw message

include/linux/lightnvm.h new file +56 -0

56 lines not on this page · raw message

include/uapi/linux/nvm.h new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
1.9.1
#9 lore raw

Re: [PATCH 2/5 v2] blk-mq: Support for Open-Channel SSDs

A few things I spotted (while actually fiddling with 3/5).

block/blk-mq.c static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx, · line 224

Quoted 8 lines · Matias Bjørling

index f3dd028..58a8a71 100644

block/blk-mq.c +1 -0
@@ -221,6 +221,9 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
 	rq->end_io = NULL;
 	rq->end_io_data = NULL;
 	rq->next_rq = NULL;
+#if CONFIG_BLK_DEV_NVM

I think you meant

    #ifdef CONFIG_BLK_DEV_NVM
Quoted 22 lines
block/blk-mq.c +2 -0
+	rq->phys_sector = 0;
+#endif
 
 	ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
 }
block/blk-nvm.c new file +13 -0
 
+int nvm_register_target(struct nvm_target_type *tt)
+{
+	int ret = 0;
+
+	down_write(&_lock);
+	if (nvm_find_target_type(tt->name))
+		ret = -EEXIST;
+	else
+		list_add(&tt->list, &_targets);
+	up_write(&_lock);
+
+	return ret;
+}

block/blk-nvm.c line 70

Quoted 10 lines
block/blk-nvm.c new file +10 -0
+
+void nvm_unregister_target(struct nvm_target_type *tt)
+{
+	if (!tt)
+		return;
+
+	down_write(&_lock);
+	list_del(&tt->list);
+	up_write(&_lock);
+}

Trying to build rrpc.ko I saw this
WARNING: "nvm_unregister_target" [[...]/drivers/lightnvm/rrpc.ko] undefined!
WARNING: "nvm_register_target" [[...]/drivers/lightnvm/rrpc.ko] undefined!

So I guess you need to export these two functions too.

include/linux/blkdev.h struct request { · line 212

Quoted 7 lines
include/linux/blkdev.h +1 -0
@@ -209,6 +209,9 @@ struct request {
 
 	/* for bidi */
 	struct request *next_rq;
+#if CONFIG_BLK_DEV_NVM

Again, I think

    #ifdef CONFIG_BLK_DEV_NVM

include/linux/blkdev.h struct request { · line 217

Quoted 5 lines
include/linux/blkdev.h +2 -0
+	sector_t phys_sector;
+#endif
 };
 
 static inline unsigned short req_get_ioprio(struct request *req)

Paul Bolle

#10 lore raw

Re: [PATCH 2/5 v2] blk-mq: Support for Open-Channel SSDs

Quoted 1 line · Paul Bolle

A few things I spotted (while actually fiddling with 3/5).

Thanks. I'll fix them up.

Quoted 73 lines · Matias Bj?rling

block/blk-mq.c static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx, · line 224

Quoted 8 lines

index f3dd028..58a8a71 100644

block/blk-mq.c +1 -0
@@ -221,6 +221,9 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
  	rq->end_io = NULL;
  	rq->end_io_data = NULL;
  	rq->next_rq = NULL;
+#if CONFIG_BLK_DEV_NVM

I think you meant

     #ifdef CONFIG_BLK_DEV_NVM
Quoted 22 lines
block/blk-mq.c +2 -0
+	rq->phys_sector = 0;
+#endif
 
  	ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
  }
block/blk-nvm.c new file +13 -0
 
+int nvm_register_target(struct nvm_target_type *tt)
+{
+	int ret = 0;
+
+	down_write(&_lock);
+	if (nvm_find_target_type(tt->name))
+		ret = -EEXIST;
+	else
+		list_add(&tt->list, &_targets);
+	up_write(&_lock);
+
+	return ret;
+}

block/blk-nvm.c line 70

Quoted 10 lines
block/blk-nvm.c new file +10 -0
+
+void nvm_unregister_target(struct nvm_target_type *tt)
+{
+	if (!tt)
+		return;
+
+	down_write(&_lock);
+	list_del(&tt->list);
+	up_write(&_lock);
+}

Trying to build rrpc.ko I saw this
WARNING: "nvm_unregister_target" [[...]/drivers/lightnvm/rrpc.ko] undefined!
WARNING: "nvm_register_target" [[...]/drivers/lightnvm/rrpc.ko] undefined!

So I guess you need to export these two functions too.

include/linux/blkdev.h struct request { · line 212

Quoted 7 lines
include/linux/blkdev.h +1 -0
@@ -209,6 +209,9 @@ struct request {
 
  	/* for bidi */
  	struct request *next_rq;
+#if CONFIG_BLK_DEV_NVM

Again, I think

     #ifdef CONFIG_BLK_DEV_NVM

include/linux/blkdev.h struct request { · line 217

Quoted 5 lines
include/linux/blkdev.h +2 -0
+	sector_t phys_sector;
+#endif
  };
 
  static inline unsigned short req_get_ioprio(struct request *req)

Paul Bolle

#11 lore raw

Re: [PATCH 2/5 v2] blk-mq: Support for Open-Channel SSDs

Quoted 4 lines · Matias Bj?rling
Quoted 1 line · Paul Bolle

A few things I spotted (while actually fiddling with 3/5).

Thanks. I'll fix them up.

Please note that just using #ifdef instead of #if is not all that's needed. See, I had some fun playing whack-a-mole with warnings and errors showing up in the "CONFIG_BLK_DEV_NVM is not set" case (because I was looking into things outside of this series that I don't understand).

After adding the changes pasted at the end of this message (which I gave
almost no thought whatsoever) I ran into:
block/blk-mq.c: In function ?blk_mq_init_rq_map?:
block/blk-mq.c:1473:22: error: invalid application of ?sizeof? to incomplete type ?struct nvm_per_rq?
cmd_size += sizeof(struct nvm_per_rq);
^

Then I admitted defeat.

Have fun with your turn of that game.

Paul Bolle

block/blk-mq.c +1 -1
index 95fbc98307a5..27d4ebf36a80 100644
@@ -223,7 +223,7 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
 	rq->end_io = NULL;
 	rq->end_io_data = NULL;
 	rq->next_rq = NULL;
-#if CONFIG_BLK_DEV_NVM
+#ifdef CONFIG_BLK_DEV_NVM
 	rq->phys_sector = 0;
 #endif
 
block/blk.h +3 -3
index 3e4abee7c194..19c037041006 100644
@@ -294,9 +294,9 @@ extern void blk_nvm_unregister(struct request_queue *);
 extern int blk_nvm_init_sysfs(struct device *);
 extern void blk_nvm_remove_sysfs(struct device *);
 #else
-static void blk_nvm_unregister(struct request_queue *q) { }
-static int blk_nvm_init_sysfs(struct device *) { return 0; }
-static void blk_nvm_remove_sysfs(struct device *) { }
+static inline void blk_nvm_unregister(struct request_queue *q) { }
+static inline int blk_nvm_init_sysfs(struct device *dev) { return 0; }
+static inline void blk_nvm_remove_sysfs(struct device *dev) { }
 #endif /* CONFIG_BLK_DEV_NVM */
 
 #endif /* BLK_INTERNAL_H */
include/linux/blkdev.h +10 -18
index 56f963586112..77d7b35a27c7 100644
@@ -209,7 +209,7 @@ struct request {
 
 	/* for bidi */
 	struct request *next_rq;
-#if CONFIG_BLK_DEV_NVM
+#ifdef CONFIG_BLK_DEV_NVM
 	sector_t phys_sector;
 #endif
 };
@@ -914,11 +914,6 @@ static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
 	return blk_rq_cur_bytes(rq) >> 9;
 }
 
-static inline sector_t blk_rq_phys_pos(const struct request *rq)
-{
-	return rq->phys_sector;
-}
-
 static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
 						     unsigned int cmd_flags)
 {
@@ -1780,35 +1775,32 @@ static inline struct nvm_dev *blk_nvm_get_dev(struct request_queue *q)
 	return q->nvm;
 }
 #else
+struct nvm_dev;
 struct nvm_dev_ops;
 struct nvm_lun;
 struct nvm_block;
 struct nvm_target_type;
 
-struct nvm_target_type *nvm_find_target_type(const char *)
+static inline struct nvm_target_type *nvm_find_target_type(const char *name)
 {
 	return NULL;
 }
-int nvm_register_target(struct nvm_target_type *tt) { return -EINVAL; }
-void nvm_unregister_target(struct nvm_target_type *tt) {}
-static inline int blk_nvm_register(struct request_queue *,
-						struct nvm_dev_ops *)
+static inline int nvm_register_target(struct nvm_target_type *tt) { return -EINVAL; }
+static inline void nvm_unregister_target(struct nvm_target_type *tt) {}
+static inline int blk_nvm_register(struct request_queue *q,
+						struct nvm_dev_ops *ops)
 {
 	return -EINVAL;
 }
-static inline struct nvm_block *blk_nvm_get_blk(struct nvm_lun *, int)
+static inline struct nvm_block *blk_nvm_get_blk(struct nvm_lun *lun, int is_gc)
 {
 	return NULL;
 }
-static inline void blk_nvm_put_blk(struct nvm_block *) {}
-static inline int blk_nvm_erase_blk(struct nvm_dev *, struct nvm_block *)
+static inline void blk_nvm_put_blk(struct nvm_block *block) {}
+static inline int blk_nvm_erase_blk(struct nvm_dev *dev, struct nvm_block *blok)
 {
 	return -EINVAL;
 }
-static inline int blk_nvm_get_dev(struct request_queue *)
-{
-	return NULL;
-}
 static inline sector_t blk_nvm_alloc_addr(struct nvm_block *block)
 {
 	return 0;
#12 lore raw

Re: [PATCH 2/5 v2] blk-mq: Support for Open-Channel SSDs

Quoted 18 lines · Paul Bolle
Quoted 4 lines · Matias Bj?rling
Quoted 1 line · Paul Bolle

A few things I spotted (while actually fiddling with 3/5).

Thanks. I'll fix them up.

Please note that just using #ifdef instead of #if is not all that's needed. See, I had some fun playing whack-a-mole with warnings and errors showing up in the "CONFIG_BLK_DEV_NVM is not set" case (because I was looking into things outside of this series that I don't understand).

After adding the changes pasted at the end of this message (which I gave
almost no thought whatsoever) I ran into:
block/blk-mq.c: In function ?blk_mq_init_rq_map?:
block/blk-mq.c:1473:22: error: invalid application of ?sizeof? to incomplete type ?struct nvm_per_rq?
cmd_size += sizeof(struct nvm_per_rq);
^

Quoted 3 lines

Then I admitted defeat.

Have fun with your turn of that game.

Thanks. Nothing like a good whack-a-mole. I've fixed it up in the master at:

https://github.com/OpenChannelSSD/linux.git

Keith, for the nvme driver, I've packed everything neatly into a #ifdef, so it looks the same as with the #ifdef integrity. It should have been like that from the start.

#13 lore raw

PATCH v2 3/5 lightnvm: RRPC target

In reply to Matias Bjørling

This target implements a simple target to be used by Open-Channel SSDs. It exposes the physical flash a generic sector-based address space.

The FTL implements a round-robin approach for sector allocation, together with a greedy cost-based garbage collector.

Signed-off-by Matias Bj?rling <m at bjorling.me>
---
 drivers/Kconfig           |    2 +
 drivers/Makefile          |    2 +
 drivers/lightnvm/Kconfig  |   29 ++
 drivers/lightnvm/Makefile |    5 +
 drivers/lightnvm/rrpc.c   | 1222 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/lightnvm/rrpc.h   |  203 ++++++++
 include/linux/lightnvm.h  |    1 -
 7 files changed, 1463 insertions(+), 1 deletion(-)
 create mode 100644 drivers/lightnvm/Kconfig
 create mode 100644 drivers/lightnvm/Makefile
 create mode 100644 drivers/lightnvm/rrpc.c
 create mode 100644 drivers/lightnvm/rrpc.h
drivers/Kconfig +2 -0
index c0cc96b..da47047 100644
@@ -42,6 +42,8 @@ source "drivers/net/Kconfig"
 
 source "drivers/isdn/Kconfig"
 
+source "drivers/lightnvm/Kconfig"
+
 # input before char - char/joystick depends on it. As does USB.
 
 source "drivers/input/Kconfig"
drivers/Makefile +2 -0
index 527a6da..6b6928a 100644
@@ -165,3 +165,5 @@ obj-$(CONFIG_RAS)		+= ras/
 obj-$(CONFIG_THUNDERBOLT)	+= thunderbolt/
 obj-$(CONFIG_CORESIGHT)		+= coresight/
 obj-$(CONFIG_ANDROID)		+= android/
+
+obj-$(CONFIG_NVM)		+= lightnvm/
drivers/lightnvm/Kconfig new file +29 -0
new file mode 100644
index 0000000..89fabe1
@@ -0,0 +1,29 @@
+#
+# Open-Channel SSD NVM configuration
+#
+
+menuconfig NVM
+	bool "Open-Channel SSD target support"
+	depends on BLK_DEV_NVM
+	help
+	  Say Y here to get to enable Open-channel SSDs.
+
+	  Open-Channel SSDs implement a set of extension to SSDs, 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.
+
+if NVM
+
+config NVM_RRPC
+	tristate "Round-robin Hybrid Open-Channel SSD"
+	depends on BLK_DEV_NVM
+	---help---
+	Allows an open-channel SSD to be exposed as a block device to the
+	host. The target is implemented using a linear mapping table and
+	cost-based garbage collection. It is optimized for 4K IO sizes.
+
+	See Documentation/nvm-rrpc.txt for details.
+
+endif # NVM
drivers/lightnvm/Makefile new file +5 -0
new file mode 100644
index 0000000..80d75a8
@@ -0,0 +1,5 @@
+#
+# Makefile for Open-Channel SSDs.
+#
+
+obj-$(CONFIG_NVM)		+= rrpc.o
drivers/lightnvm/rrpc.c new file +1222 -0

1,222 lines not on this page · raw message

drivers/lightnvm/rrpc.h new file +203 -0

203 lines not on this page · raw message

include/linux/lightnvm.h +0 -1
index 888d994..5f9f187 100644
@@ -29,7 +29,6 @@
 
 #define NVM_MSG_PREFIX "nvm"
 #define ADDR_EMPTY (~0ULL)
-#define LTOP_POISON 0xD3ADB33F
 
 /* core.c */
 
Signature · 1 line
1.9.1
#14 lore raw

Re: [PATCH 3/5 v2] lightnvm: RRPC target

Quoted 10 lines · Matias Bjørling
drivers/lightnvm/Kconfig new file +7 -0
 
+menuconfig NVM
+	bool "Open-Channel SSD target support"
+	depends on BLK_DEV_NVM
+	help
+	  Say Y here to get to enable Open-channel SSDs.
+
+	  Open-Channel SSDs implement a set of extension to SSDs, that

drivers/lightnvm/Kconfig line 21

Quoted 10 lines
drivers/lightnvm/Kconfig new file +10 -0
+	  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.
+
+if NVM
+
+config NVM_RRPC
+	tristate "Round-robin Hybrid Open-Channel SSD"
+	depends on BLK_DEV_NVM

NVM implies BLK_DEV_NVM so this dependency isn't really needed.

drivers/lightnvm/Kconfig line 27

Quoted 6 lines
drivers/lightnvm/Kconfig new file +6 -0
+	---help---
+	Allows an open-channel SSD to be exposed as a block device to the
+	host. The target is implemented using a linear mapping table and
+	cost-based garbage collection. It is optimized for 4K IO sizes.
+
+	See Documentation/nvm-rrpc.txt for details.

This file isn't part of this series, is it?

drivers/lightnvm/Makefile line 5

Quoted 13 lines
drivers/lightnvm/Kconfig new file +2 -0
+
+endif # NVM
drivers/lightnvm/Makefile new file +5 -0
new file mode 100644
index 0000000..80d75a8
@@ -0,0 +1,5 @@
+#
+# Makefile for Open-Channel SSDs.
+#
+
+obj-$(CONFIG_NVM)		+= rrpc.o

I suppose you meant to use

    obj-$(CONFIG_NVM_RRPC)		+= rrpc.o

because otherwise setting NVM_RRPC has no effect.

drivers/lightnvm/rrpc.c line 12

Quoted 11 lines
drivers/lightnvm/rrpc.c new file +8 -0
 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.

This states the license is GPL v2.

Quoted 1 line

+MODULE_LICENSE("GPL");

And (according to include/linux/module.h) the license ident "GPL" states the license is GPL v2 or later. So either the comment at the top of this file or the license ident needs to change.

Thanks,

Paul Bolle

#15 lore raw

PATCH v2 4/5 null_blk: LightNVM support

In reply to Matias Bjørling

Initial support for LightNVM. The support can be used to benchmark performance of targets and core implementation.

---
 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
index 2f6c6ff..b907ecc 100644
@@ -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

141 lines not on this page · raw message

Signature · 1 line
1.9.1
#16 lore raw

PATCH v2 5/5 nvme: LightNVM support

In reply to Matias Bjørling

The first generation of Open-Channel SSDs will be based on NVMe. The integration requires that a NVMe device exposes itself as a LightNVM device. The way this is done currently is by hooking into the Controller Capabilities (CAP register) and a bit in NSFEAT for each namespace.

After detection, vendor specific codes are used to identify the device and enumerate supported features.

---
 drivers/block/nvme-core.c | 380 +++++++++++++++++++++++++++++++++++++++++++++-
 include/linux/nvme.h      |   2 +
 include/uapi/linux/nvme.h | 116 ++++++++++++++
 3 files changed, 497 insertions(+), 1 deletion(-)
drivers/block/nvme-core.c +379 -1
index e23be20..cbbf728 100644
@@ -39,6 +39,7 @@
 #include <linux/slab.h>
 #include <linux/t10-pi.h>
 #include <linux/types.h>
+#include <linux/lightnvm.h>
 #include <scsi/sg.h>
 #include <asm-generic/io-64-nonatomic-lo-hi.h>
 
@@ -134,6 +135,8 @@ 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_hb_write_command) != 64);
+	BUILD_BUG_ON(sizeof(struct nvme_lnvm_l2ptbl_command) != 64);
 }
 
 typedef void (*nvme_completion_fn)(struct nvme_queue *, void *,
@@ -591,6 +594,30 @@ static void nvme_init_integrity(struct nvme_ns *ns)
 }
 #endif
 
+static struct nvme_iod *nvme_get_dma_iod(struct nvme_dev *dev, void *buf,
+								unsigned length)
+{
+	struct scatterlist *sg;
+	struct nvme_iod *iod;
+	struct device *ddev = &dev->pci_dev->dev;
+
+	if (!length || length > INT_MAX - PAGE_SIZE)
+		return ERR_PTR(-EINVAL);
+
+	iod = __nvme_alloc_iod(1, length, dev, 0, GFP_KERNEL);
+	if (!iod)
+		goto err;
+
+	sg = iod->sg;
+	sg_init_one(sg, buf, length);
+	iod->nents = 1;
+	dma_map_sg(ddev, sg, iod->nents, DMA_FROM_DEVICE);
+
+	return iod;
+err:
+	return ERR_PTR(-ENOMEM);
+}
+
 static void req_completion(struct nvme_queue *nvmeq, void *ctx,
 						struct nvme_completion *cqe)
 {
@@ -760,6 +787,46 @@ static void nvme_submit_flush(struct nvme_queue *nvmeq, struct nvme_ns *ns,
 	writel(nvmeq->sq_tail, nvmeq->q_db);
 }
 
+static int nvme_submit_lnvm_iod(struct nvme_queue *nvmeq, struct nvme_iod *iod,
+							struct nvme_ns *ns)
+{
+	struct request *req = iod_get_private(iod);
+	struct nvme_command *cmnd;
+	u16 control = 0;
+	u32 dsmgmt = 0;
+
+	if (req->cmd_flags & REQ_FUA)
+		control |= NVME_RW_FUA;
+	if (req->cmd_flags & (REQ_FAILFAST_DEV | REQ_RAHEAD))
+		control |= NVME_RW_LR;
+
+	if (req->cmd_flags & REQ_RAHEAD)
+		dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH;
+
+	cmnd = &nvmeq->sq_cmds[nvmeq->sq_tail];
+	memset(cmnd, 0, sizeof(*cmnd));
+
+	cmnd->lnvm_hb_w.opcode = (rq_data_dir(req) ?
+				lnvm_cmd_hybrid_write : lnvm_cmd_hybrid_read);
+	cmnd->lnvm_hb_w.command_id = req->tag;
+	cmnd->lnvm_hb_w.nsid = cpu_to_le32(ns->ns_id);
+	cmnd->lnvm_hb_w.prp1 = cpu_to_le64(sg_dma_address(iod->sg));
+	cmnd->lnvm_hb_w.prp2 = cpu_to_le64(iod->first_dma);
+	cmnd->lnvm_hb_w.slba = cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req)));
+	cmnd->lnvm_hb_w.length = cpu_to_le16(
+			(blk_rq_bytes(req) >> ns->lba_shift) - 1);
+	cmnd->lnvm_hb_w.control = cpu_to_le16(control);
+	cmnd->lnvm_hb_w.dsmgmt = cpu_to_le32(dsmgmt);
+	cmnd->lnvm_hb_w.phys_addr =
+			cpu_to_le64(nvme_block_nr(ns, req->phys_sector));
+
+	if (++nvmeq->sq_tail == nvmeq->q_depth)
+		nvmeq->sq_tail = 0;
+	writel(nvmeq->sq_tail, nvmeq->q_db);
+
+	return 0;
+}
+
 static int nvme_submit_iod(struct nvme_queue *nvmeq, struct nvme_iod *iod,
 							struct nvme_ns *ns)
 {
@@ -895,6 +962,8 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
 		nvme_submit_discard(nvmeq, ns, req, iod);
 	else if (req->cmd_flags & REQ_FLUSH)
 		nvme_submit_flush(nvmeq, ns, req->tag);
+	else if (req->cmd_flags & REQ_NVM_MAPPED)
+		nvme_submit_lnvm_iod(nvmeq, iod, ns);
 	else
 		nvme_submit_iod(nvmeq, iod, ns);
 
@@ -1156,6 +1225,84 @@ static int adapter_delete_sq(struct nvme_dev *dev, u16 sqid)
 	return adapter_delete_queue(dev, nvme_admin_delete_sq, sqid);
 }
 
+int nvme_nvm_identify_cmd(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 nvme_nvm_get_features_cmd(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 nvme_nvm_set_responsibility_cmd(struct nvme_dev *dev, unsigned nsid,
+								u64 resp)
+{
+	struct nvme_command c;
+
+	memset(&c, 0, sizeof(c));
+	c.common.opcode = lnvm_admin_set_responsibility;
+	c.common.nsid = cpu_to_le32(nsid);
+	c.lnvm_resp.resp = cpu_to_le64(resp);
+
+	return nvme_submit_admin_cmd(dev, &c, NULL);
+}
+
+int nvme_nvm_get_l2p_tbl_cmd(struct nvme_dev *dev, unsigned nsid, u64 slba,
+				u32 nlb, u16 dma_npages, struct nvme_iod *iod)
+{
+	struct nvme_command c;
+	unsigned length;
+
+	memset(&c, 0, sizeof(c));
+	c.common.opcode = lnvm_admin_get_l2p_tbl;
+	c.common.nsid = cpu_to_le32(nsid);
+
+	c.lnvm_l2p.slba = cpu_to_le64(slba);
+	c.lnvm_l2p.nlb = cpu_to_le32(nlb);
+	c.lnvm_l2p.prp1_len = cpu_to_le16(dma_npages);
+
+	length = nvme_setup_prps(dev, iod, iod->length, GFP_KERNEL);
+	if ((length >> 12) != dma_npages)
+		return -ENOMEM;
+
+	c.common.prp1 = cpu_to_le64(sg_dma_address(iod->sg));
+	c.common.prp2 = cpu_to_le64(iod->first_dma);
+
+	return nvme_submit_admin_cmd(dev, &c, NULL);
+}
+
+int nvme_nvm_erase_block_cmd(struct nvme_dev *dev, struct nvme_ns *ns,
+						sector_t block_id)
+{
+	struct nvme_command c;
+	int nsid = ns->ns_id;
+	int res;
+
+	memset(&c, 0, sizeof(c));
+	c.common.opcode = lnvm_cmd_erase_sync;
+	c.common.nsid = cpu_to_le32(nsid);
+	c.lnvm_erase.blk_addr = cpu_to_le64(block_id);
+
+	return nvme_submit_io_cmd(dev, ns, &c, &res);
+}
+
 int nvme_identify(struct nvme_dev *dev, unsigned nsid, unsigned cns,
 							dma_addr_t dma_addr)
 {
@@ -1551,6 +1698,185 @@ 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->laddr_begin = le64_to_cpu(src->laddr_begin);
+			dst->laddr_end = le64_to_cpu(src->laddr_end);
+			dst->oob_size = le32_to_cpu(src->oob_size);
+			dst->queue_size = le32_to_cpu(src->queue_size);
+			dst->gran_read = le32_to_cpu(src->gran_read);
+			dst->gran_write = le32_to_cpu(src->gran_write);
+			dst->gran_erase = le32_to_cpu(src->gran_erase);
+			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;
+		}
+
+		len -= end;
+		if (!len)
+			break;
+
+		off += end;
+
+		if (nvme_nvm_identify_cmd(dev, off, dma_addr))
+			return -EIO;
+
+		src = dma_buf->chnls;
+	}
+	return 0;
+}
+
+static int nvme_nvm_identify(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 = nvme_nvm_identify_cmd(dev, 0, dma_addr);
+	if (ret) {
+		ret = -EIO;
+		goto out;
+	}
+
+	nvm_id->ver_id = 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)
+{
+	struct nvme_ns *ns = q->queuedata;
+	struct nvme_dev *dev = ns->dev;
+	struct pci_dev *pdev = dev->pci_dev;
+	dma_addr_t dma_addr;
+	int ret = 0;
+	u64 *mem;
+
+	mem = (u64 *)dma_alloc_coherent(&pdev->dev,
+					sizeof(struct nvm_get_features),
+							&dma_addr, GFP_KERNEL);
+	if (!mem)
+		return -ENOMEM;
+
+	ret = nvme_nvm_get_features_cmd(dev, ns->ns_id, dma_addr);
+	if (ret)
+		goto finish;
+
+	gf->rsp = le64_to_cpu(mem[0]);
+	gf->ext = le64_to_cpu(mem[1]);
+
+finish:
+	dma_free_coherent(&pdev->dev, sizeof(struct nvm_get_features), mem,
+								dma_addr);
+	return ret;
+}
+
+static int nvme_nvm_set_responsibility(struct request_queue *q, u64 resp)
+{
+	struct nvme_ns *ns = q->queuedata;
+	struct nvme_dev *dev = ns->dev;
+
+	return nvme_nvm_set_responsibility_cmd(dev, ns->ns_id, resp);
+}
+
+static int nvme_nvm_get_l2p_tbl(struct request_queue *q, u64 slba, u64 nlb,
+				nvm_l2p_update_fn *update_l2p, void *private)
+{
+	struct nvme_ns *ns = q->queuedata;
+	struct nvme_dev *dev = ns->dev;
+	struct pci_dev *pdev = dev->pci_dev;
+	static const u16 dma_npages = 256U;
+	static const u32 length = dma_npages * PAGE_SIZE;
+	u64 nlb_pr_dma = length / sizeof(u64);
+	struct nvme_iod *iod;
+	u64 cmd_slba = slba;
+	dma_addr_t dma_addr;
+	void *entries;
+	int res = 0;
+
+	entries = dma_alloc_coherent(&pdev->dev, length, &dma_addr, GFP_KERNEL);
+	if (!entries)
+		return -ENOMEM;
+
+	iod = nvme_get_dma_iod(dev, entries, length);
+	if (!iod) {
+		res = -ENOMEM;
+		goto out;
+	}
+
+	while (nlb) {
+		u64 cmd_nlb = min_t(u64, nlb_pr_dma, nlb);
+
+		res = nvme_nvm_get_l2p_tbl_cmd(dev, ns->ns_id, cmd_slba,
+						(u32)cmd_nlb, dma_npages, iod);
+		if (res) {
+			dev_err(&pdev->dev, "L2P table transfer failed (%d)\n",
+									res);
+			res = -EIO;
+			goto free_iod;
+		}
+
+		if (update_l2p(cmd_slba, cmd_nlb, entries, private)) {
+			res = -EINTR;
+			goto free_iod;
+		}
+
+		cmd_slba += cmd_nlb;
+		nlb -= cmd_nlb;
+	}
+
+free_iod:
+	dma_unmap_sg(&pdev->dev, iod->sg, 1, DMA_FROM_DEVICE);
+	nvme_free_iod(dev, iod);
+out:
+	dma_free_coherent(&pdev->dev, PAGE_SIZE * dma_npages, entries,
+								dma_addr);
+	return res;
+}
+
+static int nvme_nvm_erase_block(struct request_queue *q, sector_t block_id)
+{
+	struct nvme_ns *ns = q->queuedata;
+	struct nvme_dev *dev = ns->dev;
+
+	return nvme_nvm_erase_block_cmd(dev, ns, block_id);
+}
+
 static struct blk_mq_ops nvme_mq_admin_ops = {
 	.queue_rq	= nvme_admin_queue_rq,
 	.map_queue	= blk_mq_map_queue,
@@ -1560,6 +1886,14 @@ static struct blk_mq_ops nvme_mq_admin_ops = {
 	.timeout	= nvme_timeout,
 };
 
+static struct nvm_dev_ops nvme_nvm_dev_ops = {
+	.identify		= nvme_nvm_identify,
+	.get_features		= nvme_nvm_get_features,
+	.set_responsibility	= nvme_nvm_set_responsibility,
+	.get_l2p_tbl		= nvme_nvm_get_l2p_tbl,
+	.erase_block		= nvme_nvm_erase_block,
+};
+
 static struct blk_mq_ops nvme_mq_ops = {
 	.queue_rq	= nvme_queue_rq,
 	.map_queue	= blk_mq_map_queue,
@@ -1744,6 +2078,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;
@@ -1769,6 +2123,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;
 	}
@@ -2073,6 +2431,17 @@ static int nvme_revalidate_disk(struct gendisk *disk)
 	if (dev->oncs & NVME_CTRL_ONCS_DSM)
 		nvme_config_discard(ns);
 
+	if (id->nsfeat & NVME_NS_FEAT_NVM) {
+		if (blk_nvm_register(ns->queue, &nvme_nvm_dev_ops)) {
+			dev_warn(&dev->pci_dev->dev,
+				 "%s: LightNVM init failure\n", __func__);
+			return 0;
+		}
+
+		/* FIXME: This will be handled later by ns */
+		ns->queue->nvm->drv_cmd_size = sizeof(struct nvme_cmd_info);
+	}
+
 	dma_free_coherent(&dev->pci_dev->dev, 4096, id, dma_addr);
 	return 0;
 }
@@ -2185,6 +2554,7 @@ static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)
 	if (ns->ms)
 		revalidate_disk(ns->disk);
 	return;
+
  out_free_queue:
 	blk_cleanup_queue(ns->queue);
  out_free_ns:
@@ -2316,7 +2686,9 @@ static int nvme_dev_add(struct nvme_dev *dev)
 	struct nvme_id_ctrl *ctrl;
 	void *mem;
 	dma_addr_t dma_addr;
-	int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
+	u64 cap = readq(&dev->bar->cap);
+	int shift = NVME_CAP_MPSMIN(cap) + 12;
+	int nvm_cmdset = NVME_CAP_NVM(cap);
 
 	mem = dma_alloc_coherent(&pdev->dev, 4096, &dma_addr, GFP_KERNEL);
 	if (!mem)
@@ -2332,6 +2704,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;
 	dev->event_limit = min(ctrl->aerl + 1, 8);
@@ -2364,6 +2737,11 @@ static int nvme_dev_add(struct nvme_dev *dev)
 	dev->tagset.flags = BLK_MQ_F_SHOULD_MERGE;
 	dev->tagset.driver_data = dev;
 
+	if (nvm_cmdset) {
+		dev->tagset.flags &= ~BLK_MQ_F_SHOULD_MERGE;
+		dev->tagset.flags |= BLK_MQ_F_NVM;
+	}
+
 	if (blk_mq_alloc_tag_set(&dev->tagset))
 		return 0;
 
include/linux/nvme.h +2 -0
index 0adad4a..dc9c805 100644
@@ -39,6 +39,7 @@ struct nvme_bar {
 #define NVME_CAP_STRIDE(cap)	(((cap) >> 32) & 0xf)
 #define NVME_CAP_MPSMIN(cap)	(((cap) >> 48) & 0xf)
 #define NVME_CAP_MPSMAX(cap)	(((cap) >> 52) & 0xf)
+#define NVME_CAP_NVM(cap)	(((cap) >> 38) & 0x1)
 
 enum {
 	NVME_CC_ENABLE		= 1 << 0,
@@ -100,6 +101,7 @@ struct nvme_dev {
 	u32 stripe_size;
 	u32 page_size;
 	u16 oncs;
+	u16 oacs;
 	u16 abort_limit;
 	u8 event_limit;
 	u8 vwc;
include/uapi/linux/nvme.h +116 -0

158 lines not on this page · raw message

Signature · 1 line
1.9.1
#17 lore raw

Re: [PATCH 5/5 v2] nvme: LightNVM support

drivers/block/nvme-core.c static int nvme_dev_add(struct nvme_dev *dev) · line 2691

Quoted 8 lines · Matias Bj?rling
drivers/block/nvme-core.c +3 -1
@@ -2316,7 +2686,9 @@ static int nvme_dev_add(struct nvme_dev *dev)
 	struct nvme_id_ctrl *ctrl;
 	void *mem;
 	dma_addr_t dma_addr;
-	int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
+	u64 cap = readq(&dev->bar->cap);
+	int shift = NVME_CAP_MPSMIN(cap) + 12;
+	int nvm_cmdset = NVME_CAP_NVM(cap);

The controller capabilities' command sets supported used here is the right way to key off on support for this new command set, IMHO, but I do not see in this patch the command set being selected when the controller is enabled

Also if we're going this route, I think we need to define this reserved bit in the spec, but I'm not sure how to help with that.

drivers/block/nvme-core.c static int nvme_dev_add(struct nvme_dev *dev) · line 2707

Quoted 5 lines
drivers/block/nvme-core.c +1 -0
@@ -2332,6 +2704,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);

I don't find OACS used anywhere in the rest of the patch. I think this must be left over from v1.

Otherwise it looks pretty good to me, but I think it would be cleaner if the lightnvm stuff is not mixed in the same file with the standard nvme command set. We might end up splitting nvme-core in the future anyway for command sets and transports.

#18 lore raw

Re: [PATCH 5/5 v2] nvme: LightNVM support

Hi,

Quoted 29 lines · Keith Busch

drivers/block/nvme-core.c static int nvme_dev_add(struct nvme_dev *dev) · line 2691

Quoted 8 lines · Matias Bjørling
drivers/block/nvme-core.c +3 -1
@@ -2316,7 +2686,9 @@ static int nvme_dev_add(struct nvme_dev *dev)
 	struct nvme_id_ctrl *ctrl;
 	void *mem;
 	dma_addr_t dma_addr;
-	int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
+	u64 cap = readq(&dev->bar->cap);
+	int shift = NVME_CAP_MPSMIN(cap) + 12;
+	int nvm_cmdset = NVME_CAP_NVM(cap);

The controller capabilities' command sets supported used here is the right way to key off on support for this new command set, IMHO, but I do not see in this patch the command set being selected when the controller is enabled

Also if we're going this route, I think we need to define this reserved bit in the spec, but I'm not sure how to help with that.

drivers/block/nvme-core.c static int nvme_dev_add(struct nvme_dev *dev) · line 2707

Quoted 5 lines
drivers/block/nvme-core.c +1 -0
@@ -2332,6 +2704,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);

I don't find OACS used anywhere in the rest of the patch. I think this must be left over from v1.

Quoted 4 lines

Otherwise it looks pretty good to me, but I think it would be cleaner if the lightnvm stuff is not mixed in the same file with the standard nvme command set. We might end up splitting nvme-core in the future anyway for command sets and transports.

Would you be ok with having nvme-lightnvm for LightNVM specific commands?

Javier.

#19 lore raw

Re: [PATCH 5/5 v2] nvme: LightNVM support

Quoted 9 lines · Javier Gonz?lez
Quoted 6 lines · Keith Busch

Otherwise it looks pretty good to me, but I think it would be cleaner if the lightnvm stuff is not mixed in the same file with the standard nvme command set. We might end up splitting nvme-core in the future anyway for command sets and transports.

Would you be ok with having nvme-lightnvm for LightNVM specific commands?

Sounds good to me, but I don't really have a dog in this fight. :)

#20 lore raw

RE: [PATCH 5/5 v2] nvme: LightNVM support

My two cents worth is that it's (always) better to put ALL the commands into one place so that the entire set can be viewed at once and thus avoid inadvertent overloading of an opcode. Otherwise you don't know what you don't know.

-----Original Message-----
From: Linux-nvme [mailto:[email protected]] On Behalf Of Keith Busch
Sent: Thursday, April 16, 2015 8:52 AM
To: Javier Gonz?lez
Cc: hch at infradead.org; Matias Bj?rling; axboe at fb.com; linux-kernel at vger.kernel.org; linux-nvme at lists.infradead.org; Keith Busch; linux-fsdevel at vger.kernel.org
Subject: Re: [PATCH 5/5 v2] nvme: LightNVM support

Quoted 9 lines · Javier Gonz?lez
Quoted 6 lines · Keith Busch

Otherwise it looks pretty good to me, but I think it would be cleaner if the lightnvm stuff is not mixed in the same file with the standard nvme command set. We might end up splitting nvme-core in the future anyway for command sets and transports.

Would you be ok with having nvme-lightnvm for LightNVM specific commands?

Sounds good to me, but I don't really have a dog in this fight. :)

#21 lore raw

RE: [PATCH 5/5 v2] nvme: LightNVM support

Quoted 4 lines · James R. Bergsten

My two cents worth is that it's (always) better to put ALL the commands into one place so that the entire set can be viewed at once and thus avoid inadvertent overloading of an opcode. Otherwise you don't know what you don't know.

Yes, but these are two different command sets.

#22 lore raw

Re: [PATCH 5/5 v2] nvme: LightNVM support

In reply to Keith Busch

Den 16-04-2015 kl. 16:55 skrev Keith Busch:

Quoted 6 lines · Matias Bj?rling
Quoted 5 lines
drivers/block/nvme-core.c +0 -1
@@ -2316,7 +2686,9 @@ static int nvme_dev_add(struct nvme_dev *dev)
    struct nvme_id_ctrl *ctrl;
    void *mem;
    dma_addr_t dma_addr;
-    int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
Quoted 8 lines

drivers/block/nvme-core.c static int nvme_dev_add(struct nvme_dev *dev) · line 2691

Quoted 3 lines
drivers/block/nvme-core.c +3 -0
+    u64 cap = readq(&dev->bar->cap);
+    int shift = NVME_CAP_MPSMIN(cap) + 12;
+    int nvm_cmdset = NVME_CAP_NVM(cap);

The controller capabilities' command sets supported used here is the right way to key off on support for this new command set, IMHO, but I do not see in this patch the command set being selected when the controller is enabled

I'll get that added. Wouldn't it just be that the command set always is selected? A NVMe controller can expose both normal and lightnvm namespaces. So we would always enable it, if CAP bit is set.

Quoted 3 lines

Also if we're going this route, I think we need to define this reserved bit in the spec, but I'm not sure how to help with that.

Agree, we'll see how it can be proposed.

Quoted 9 lines

drivers/block/nvme-core.c static int nvme_dev_add(struct nvme_dev *dev) · line 2707

Quoted 6 lines
drivers/block/nvme-core.c +1 -0
@@ -2332,6 +2704,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);

I don't find OACS used anywhere in the rest of the patch. I think this must be left over from v1.

Oops, yes, that's just a left over.

Quoted 5 lines

Otherwise it looks pretty good to me, but I think it would be cleaner if the lightnvm stuff is not mixed in the same file with the standard nvme command set. We might end up splitting nvme-core in the future anyway for command sets and transports.

Will do. Thanks.