Support for Open-Channel SSDs
Subsystems (4)
v3 cover Support for Open-Channel SSDs
Hi,
This is an updated version based on the feedback from Paul, Keith and Christoph.
Patches are against v4.0.
Development and further information on LightNVM can be found at:
https://github.com/OpenChannelSSD/linux
Changes since v2:
Feedback from Paul Bolle:
- Fix license to GPLv2, documentation, compilation. Feedback from Keith Busch:
- nvme: Move lightnvm out and into nvme-lightnvm.c.
- nvme: Set controller css on lightnvm command set.
- nvme: Remove OACS.
Feedback from Christoph Hellwig:
- lightnvm: Move out of block layer into /drivers/lightnvm/core.c
- lightnvm: refactor request->phys_sector into device drivers.
- lightnvm: refactor prep/unprep into device drivers.
- lightnvm: move nvm_dev from request_queue to gendisk.
New
- Bad block table support (From Javier).
- Update maintainers file.
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 according to the LightNVM specification changes.
- Added interface to add/remove targets for a block device.
Javier González (1):
nvme: rename and expose nvme_alloc_iod
Matias Bjørling (6):
bio: Introduce LightNVM payload
block: add REQ_NVM_GC for targets gc
lightnvm: Support for Open-Channel SSDs
lightnvm: RRPC target
null_blk: LightNVM support
nvme: LightNVM support
Documentation/block/null_blk.txt | 8 + MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 2 + drivers/block/Makefile | 2 +- drivers/block/null_blk.c | 116 +++- drivers/block/nvme-core.c | 112 +++- drivers/block/nvme-lightnvm.c | 401 +++++++++++++ drivers/lightnvm/Kconfig | 26 + drivers/lightnvm/Makefile | 6 + drivers/lightnvm/core.c | 804 ++++++++++++++++++++++++++ drivers/lightnvm/rrpc.c | 1176 ++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/rrpc.h | 215 +++++++ include/linux/bio.h | 9 + include/linux/blk_types.h | 9 +- include/linux/blkdev.h | 2 + include/linux/genhd.h | 3 + include/linux/lightnvm.h | 312 ++++++++++ include/linux/nvme.h | 8 + include/uapi/linux/lightnvm.h | 70 +++ include/uapi/linux/nvme.h | 132 +++++ 21 files changed, 3400 insertions(+), 23 deletions(-) create mode 100644 drivers/block/nvme-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/rrpc.c create mode 100644 drivers/lightnvm/rrpc.h create mode 100644 include/linux/lightnvm.h create mode 100644 include/uapi/linux/lightnvm.h
Signature · 1 line
1.9.1
PATCH v3 1/7 bio: Introduce LightNVM payload
LightNVM integrates on both sides of the block layer. The lower layer implements mapping of logical to physical addressing, while the layer above can string together multiple LightNVM devices and expose them as a single block device.
Having multiple devices underneath requires a way to resolve where the IO came from when submitted through the block layer. Extending bio with a LightNVM payload solves this problem.
--- include/linux/bio.h | 9 +++++++++ include/linux/blk_types.h | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-)
include/linux/bio.h +9 -0
@@ -354,6 +354,15 @@ static inline void bip_set_seed(struct bio_integrity_payload *bip,#endif /* CONFIG_BLK_DEV_INTEGRITY */ +#if defined(CONFIG_NVM ) + +/* bio open-channel ssd payload */ +struct bio_nvm_payload { +void *private; +}; + +#endif /* CONFIG_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_types.h +3 -1
@@ -83,7 +83,9 @@ struct bio {struct bio_integrity_payload *bi_integrity;/* data integrity */ #endif }; - +#if defined(CONFIG_NVM ) +struct bio_nvm_payload *bi_nvm;/* open-channel ssd backend */ +#endif unsigned short bi_vcnt;/* how many bio_vec's */ /*
Signature · 1 line
1.9.1
Re: [PATCH v3 1/7] bio: Introduce LightNVM payload
Quoted 20 lines · Matias Bj??rling
LightNVM integrates on both sides of the block layer. The lower layer implements mapping of logical to physical addressing, while the layer above can string together multiple LightNVM devices and expose them as a single block device.
Having multiple devices underneath requires a way to resolve where the IO came from when submitted through the block layer. Extending bio with a LightNVM payload solves this problem.
Signed-off-by Matias Bj??rling <m at bjorling.me>--- include/linux/bio.h | 9 +++++++++ include/linux/blk_types.h | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-)include/linux/bio.h +0
-0
include/linux/bio.h static inline void bip_set_seed(struct bio_integrity_payload *bip, · line 362
Quoted 9 lines
include/linux/bio.h +6
-0@@ -354,6 +354,15 @@ static inline void bip_set_seed(struct bio_integrity_payload *bip,#endif /* CONFIG_BLK_DEV_INTEGRITY */ +#if defined(CONFIG_NVM ) + +/* bio open-channel ssd payload */ +struct bio_nvm_payload { +void *private; +};
Can you explain why this needs to be done on a per-bio instead of a per-request level? I don't really think a low-level driver should add fields to struct bio as that can be easily remapped.
On the other hand in th request you can already (ab)use the ->cmd and related fields for your own purposes.
Re: [PATCH v3 1/7] bio: Introduce LightNVM payload
Quoted 24 lines · Christoph Hellwig
Quoted 23 lines · Matias Bj??rling
LightNVM integrates on both sides of the block layer. The lower layer implements mapping of logical to physical addressing, while the layer above can string together multiple LightNVM devices and expose them as a single block device.
Having multiple devices underneath requires a way to resolve where the IO came from when submitted through the block layer. Extending bio with a LightNVM payload solves this problem.
Signed-off-by Matias Bj??rling <[email protected]>--- include/linux/bio.h | 9 +++++++++ include/linux/blk_types.h | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-)include/linux/bio.h +0
-0@@ -354,6 +354,15 @@ static inline void bip_set_seed(struct bio_integrity_payload *bip,#endif /* CONFIG_BLK_DEV_INTEGRITY */
Quoted 10 lines
include/linux/bio.h static inline void bip_set_seed(struct bio_integrity_payload *bip, · line 362
Quoted 6 lines
include/linux/bio.h +6
-0+#if defined(CONFIG_NVM ) + +/* bio open-channel ssd payload */ +struct bio_nvm_payload { +void *private; +};Can you explain why this needs to be done on a per-bio instead of a per-request level? I don't really think a low-level driver should add fields to struct bio as that can be easily remapped.
When a bio is submitted through the block layer, it can be merged/splitted on going through the block layer. Thus, we don't know the number of physical addresses that must be mapped before its on the other side.
There can be multiple targets using a single open-channel SSD. Therefore, when its on the other side, it has to figure out which target it was called from, so it can call the right mapping function.
Re: [PATCH v3 1/7] bio: Introduce LightNVM payload
Quoted 7 lines · Matias Bj?rling
Quoted 3 lines
Can you explain why this needs to be done on a per-bio instead of a per-request level? I don't really think a low-level driver should add fields to struct bio as that can be easily remapped.
When a bio is submitted through the block layer, it can be merged/splitted on going through the block layer. Thus, we don't know the number of physical addresses that must be mapped before its on the other side.
For any sort of passthrough bios that should not be the case. It's not for BLOCK_PC, it's not for my new pass through NVMe commands and I don't think it should be in this case.
PATCH v3 2/7 block: add REQ_NVM_GC for targets gc
In reply to Matias BjørlingIn preparation for Open-Channel SSDs. We introduce a special request for open-channel ssd targets that must perform garbage collection.
Requests are divided into two types. The user and target specific. User IOs are from fs, user-space, etc. While target specific are IOs that are issued in the background by targets. Usually garbage collection actions.
For the target to issue garbage collection requests, it is a requirement that a logical address is locked over two requests. One read and one write. If a write to the logical address comes in from user-space, a race-condition might occur and garbage collection will write out-dated data.
By introducing this flag, the target can manually control locking of logical addresses.
--- include/linux/blk_types.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/blk_types.h +3 -2
@@ -195,6 +195,7 @@ 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_GC,/* request is a nvm gc request */ __REQ_NR_BITS, /* stops here */ };
@@ -215,7 +216,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_GC)#define REQ_CLONE_MASK REQ_COMMON_MASK#define BIO_NO_ADVANCE_ITER_MASK (REQ_DISCARD|REQ_WRITE_SAME)
@@ -249,5 +250,5 @@ 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_GC (1ULL << __REQ_NVM_GC)#endif /* __LINUX_BLK_TYPES_H */
Signature · 1 line
1.9.1
Re: [PATCH v3 2/7] block: add REQ_NVM_GC for targets gc
Quoted 7 lines · Matias Bj??rling
In preparation for Open-Channel SSDs. We introduce a special request for open-channel ssd targets that must perform garbage collection.
Requests are divided into two types. The user and target specific. User IOs are from fs, user-space, etc. While target specific are IOs that are issued in the background by targets. Usually garbage collection actions.
Quoted 8 lines
For the target to issue garbage collection requests, it is a requirement that a logical address is locked over two requests. One read and one write. If a write to the logical address comes in from user-space, a race-condition might occur and garbage collection will write out-dated data.
By introducing this flag, the target can manually control locking of logical addresses.
Seems like this should be a new ->cmd_type instead of a flag.
PATCH v3 3/7 lightnvm: Support for Open-Channel SSDs
In reply to Matias BjørlingOpen-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 <[email protected]>
Jesper Madsen <[email protected]>
--- MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 2 + drivers/lightnvm/Kconfig | 16 + drivers/lightnvm/Makefile | 5 + drivers/lightnvm/core.c | 804 ++++++++++++++++++++++++++++++++++++++++++ include/linux/genhd.h | 3 + include/linux/lightnvm.h | 312 ++++++++++++++++ include/uapi/linux/lightnvm.h | 70 ++++ 9 files changed, 1222 insertions(+) create mode 100644 drivers/lightnvm/Kconfig create mode 100644 drivers/lightnvm/Makefile create mode 100644 drivers/lightnvm/core.c create mode 100644 include/linux/lightnvm.h create mode 100644 include/uapi/linux/lightnvm.h
MAINTAINERS +8 -0
@@ -5852,6 +5852,14 @@ M: Sasha Levin <[email protected]> S: Maintained F: tools/lib/lockdep/ +LIGHTNVM PLATFORM SUPPORT +M: Matias Bjorling <[email protected]> +W: http://github/OpenChannelSSD +S: Maintained +F: drivers/lightnvm/ +F: include/linux/lightnvm.h +F: include/uapi/linux/lightnvm.h + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras <[email protected]> W: http://www.ibm.com/linux/ltc/projects/ppc
drivers/Kconfig +2 -0
@@ -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
@@ -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 +16 -0
@@ -0,0 +1,16 @@ +# +# Open-Channel SSD NVM configuration +# + +menuconfig NVM + bool "Open-Channel SSD target support" + depends on BLOCK + 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. +
drivers/lightnvm/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for Open-Channel SSDs. +# + +obj-$(CONFIG_NVM) := core.o
drivers/lightnvm/core.c new file +804 -0
804 lines not on this page · raw message
include/linux/genhd.h +3 -0
@@ -199,6 +199,9 @@ struct gendisk {#ifdef CONFIG_BLK_DEV_INTEGRITY struct blk_integrity *integrity;#endif +#ifdef CONFIG_NVM +struct nvm_dev *nvm; +#endif int node_id; };
include/linux/lightnvm.h new file +312 -0
312 lines not on this page · raw message
include/uapi/linux/lightnvm.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 4/7 lightnvm: RRPC target
In reply to Matias BjørlingThis 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.
--- drivers/lightnvm/Kconfig | 10 + drivers/lightnvm/Makefile | 1 + drivers/lightnvm/rrpc.c | 1176 +++++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/rrpc.h | 215 +++++++++ include/linux/blkdev.h | 2 + 5 files changed, 1404 insertions(+) create mode 100644 drivers/lightnvm/rrpc.c create mode 100644 drivers/lightnvm/rrpc.h
drivers/lightnvm/Kconfig +10 -0
@@ -14,3 +14,13 @@ menuconfig NVM 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" + ---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. + +endif # NVM
drivers/lightnvm/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_NVM) := core.o +obj-$(CONFIG_NVM_RRPC) += rrpc.o
drivers/lightnvm/rrpc.c new file +1176 -0
1,176 lines not on this page · raw message
drivers/lightnvm/rrpc.h new file +215 -0
215 lines not on this page · raw message
include/linux/blkdev.h +2 -0
@@ -1504,6 +1504,8 @@ extern bool blk_integrity_merge_bio(struct request_queue *, struct request *,static inline struct blk_integrity *bdev_get_integrity (struct block_device *bdev) { +if (unlikely (!bdev)) +return NULL ;return bdev->bd_disk->integrity; }
Signature · 1 line
1.9.1
PATCH v3 5/7 null_blk: LightNVM support
In reply to Matias BjørlingInitial 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 | 116 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 117 insertions(+), 7 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 + +nvm_enable=[x]: Default: 0 + Enable LightNVM for null block devices. Requires blk-mq to be used. + +nvm_num_channels=[x]: Default: 1 + Number of LightNVM channels that is exposed to the LightNVM driver.
drivers/block/null_blk.c +109 -7
184 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 6/7 nvme: rename and expose nvme_alloc_iod
In reply to Matias BjørlingFrom: Javier González <[email protected]>
Users of the kernel interface of the NVMe driver are limited to sending custom commands without iod's.
By renaming __nvme_alloc_iod to nvme_alloc_phys_seg_iod and expose it through the header file, an outside translation layer such as scsi or lightnvm can integrate commands with iod structure.
--- drivers/block/nvme-core.c | 9 ++++----- include/linux/nvme.h | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/block/nvme-core.c +4 -5
@@ -413,9 +413,8 @@ static inline void iod_init(struct nvme_iod *iod, unsigned nbytes, iod->nents =0 ; } -static struct nvme_iod * -__nvme_alloc_iod (unsigned nseg,unsigned bytes,struct nvme_dev *dev, -unsigned long priv,gfp_t gfp) +struct nvme_iod *nvme_alloc_phys_seg_iod (unsigned nseg,unsigned bytes, +struct nvme_dev *dev,unsigned long priv,gfp_t gfp) { struct nvme_iod *iod = kmalloc(sizeof(struct nvme_iod) + sizeof(__le64 *) * nvme_npages(bytes, dev) +
@@ -446,7 +445,7 @@ static struct nvme_iod *nvme_alloc_iod(struct request *rq, struct nvme_dev *dev,return iod; } -return __nvme_alloc_iod (rq->nr_phys_segments, size, dev, +return nvme_alloc_phys_seg_iod (rq->nr_phys_segments, size, dev, (unsigned long ) rq, gfp); }
@@ -1699,7 +1698,7 @@ struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write, } err = -ENOMEM ; - iod =__nvme_alloc_iod (count, length, dev,0 ,GFP_KERNEL ); + iod =nvme_alloc_phys_seg_iod (count, length, dev,0 ,GFP_KERNEL );if (!iod) goto put_pages;
include/linux/nvme.h +2 -0
@@ -168,6 +168,8 @@ int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid, dma_addr_t dma_addr, u32 *result);int nvme_set_features (struct nvme_dev *dev,unsigned fid,unsigned dword11,dma_addr_t dma_addr,u32 *result); +struct nvme_iod *nvme_alloc_phys_seg_iod (unsigned nseg,unsigned bytes, +struct nvme_dev *dev,unsigned long priv,gfp_t gfp);struct sg_io_hdr ;
Signature · 1 line
1.9.1
PATCH v3 7/7 nvme: LightNVM support
In reply to Matias BjørlingThe 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/Makefile | 2 +- drivers/block/nvme-core.c | 103 ++++++++++- drivers/block/nvme-lightnvm.c | 401 ++++++++++++++++++++++++++++++++++++++++++ include/linux/nvme.h | 6 + include/uapi/linux/nvme.h | 132 ++++++++++++++ 5 files changed, 636 insertions(+), 8 deletions(-) create mode 100644 drivers/block/nvme-lightnvm.c
drivers/block/Makefile +1 -1
@@ -44,6 +44,6 @@ obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o obj-$(CONFIG_ZRAM) += zram/ -nvme-y := nvme-core.o nvme-scsi.o +nvme-y := nvme-core.o nvme-scsi.o nvme-lightnvm.o skd-y := skd_main.o swim_mod-y := swim.o swim_asm.o
drivers/block/nvme-core.c +96 -7
206 lines not on this page · raw message
drivers/block/nvme-lightnvm.c new file +401 -0
401 lines not on this page · raw message
include/linux/nvme.h +6 -0
@@ -19,6 +19,7 @@#include <linux/pci.h> #include <linux/kref.h> #include <linux/blk-mq.h> +#include <linux/lightnvm.h> struct nvme_bar {__u64 cap;/* Controller Capabilities */
@@ -39,10 +40,12 @@ 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_LIGHTNVM (cap) (((cap) >> 38) & 0x1)enum {NVME_CC_ENABLE =1 <<0 ,NVME_CC_CSS_NVM =0 <<4 , +NVME_CC_CSS_LIGHTNVM =1 <<4 ,NVME_CC_MPS_SHIFT =7 ,NVME_CC_ARB_RR =0 <<11 ,NVME_CC_ARB_WRRU =1 <<11 ,
@@ -119,6 +122,7 @@ struct nvme_ns {int lba_shift;int ms;int pi_type; +int type;u64 mode_select_num_blocks;u32 mode_select_block_len; };
@@ -136,6 +140,7 @@ struct nvme_iod {int nents;/* Used in scatterlist */ int length;/* Of data, in bytes */ dma_addr_t first_dma; +struct nvm_rq_data nvm_rqdata;/* Physical sectors description of the I/O */ struct scatterlist meta_sg[1 ];/* metadata requires single contiguous buffer */ struct scatterlist sg[0 ]; };
@@ -177,4 +182,5 @@ int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);int nvme_sg_io32 (struct nvme_ns *ns,unsigned long arg);int nvme_sg_get_version_num (int __user *ip); +int nvme_nvm_register (struct request_queue *q,struct gendisk *disk);#endif /* _LINUX_NVME_H */
include/uapi/linux/nvme.h +132 -0
180 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v3 7/7] nvme: LightNVM support
Quoted 11 lines
drivers/block/nvme-core.c +1
-0@@ -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>
drivers/block/nvme-core.c static inline void _nvme_check_size(void) · line 143
Quoted 9 lines
drivers/block/nvme-core.c +5
-0@@ -134,6 +135,11 @@ 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_nvm_hb_rw ) !=64 ); +BUILD_BUG_ON (sizeof (struct nvme_nvm_l2ptbl ) !=64 ); +BUILD_BUG_ON (sizeof (struct nvme_nvm_bbtbl ) !=64 ); +BUILD_BUG_ON (sizeof (struct nvme_nvm_set_resp ) !=64 ); +BUILD_BUG_ON (sizeof (struct nvme_nvm_erase_blk ) !=64 ); }
Keith, should I move the lightnvm definition into the nvme-lightnvm.c file as well?
Quoted 12 lines
drivers/block/nvme-core.c +0
-0static int nvme_submit_iod (struct nvme_queue *nvmeq,struct nvme_iod *iod,struct nvme_ns *ns){drivers/block/nvme-core.c +5
-0@@ -888,12 +937,29 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx, } } +if (ns->type ==NVME_NS_NVM ) { +switch (nvm_prep_rq (req, &iod->nvm_rqdata)) { +case NVM_PREP_DONE : + goto done_cmd; +case NVM_PREP_REQUEUE :
drivers/block/nvme-core.c static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx, · line 954
Quoted 10 lines
drivers/block/nvme-core.c +10
-0+blk_mq_requeue_request (req); +blk_mq_kick_requeue_list (hctx->queue); + goto done_cmd; +case NVM_PREP_BUSY : + goto retry_cmd; +case NVM_PREP_ERROR : + goto error_cmd; + } + } +
Regarding the prep part. I'm not 100% satisfied with it. I can refactor it into a function and clean it up. There is still a need for the jumping, as it depends on the iod.
Another possibility is to only call it on lightnvm capable controllers. With its own queue_rq function. It would be global for all namespaces. The flow would then look like
register -> nvme_nvm_queue_rq
nvme_nvm_queue_rq()
if (ns is normal command set)
return nvme_queue_rq();
__nvme_nvm_queue_rq()
Any thoughts?
Quoted 181 lines
index aef9a81..5292906 100644
include/uapi/linux/nvme.h +125
-0@@ -85,6 +85,35 @@ struct nvme_id_ctrl {__u8 vs[1024 ]; }; +struct nvme_nvm_id_chnl { +__le64 laddr_begin; +__le64 laddr_end; +__le32 oob_size; +__le32 queue_size; +__le32 gran_read; +__le32 gran_write; +__le32 gran_erase; +__le32 t_r; +__le32 t_sqr; +__le32 t_w; +__le32 t_sqw; +__le32 t_e; +__le16 chnl_parallelism; +__u8 io_sched; +__u8 reserved[133 ]; +} __attribute__((packed)); + +struct nvme_nvm_id { +__u8 ver_id; +__u8 nvm_type; +__le16 nchannels; +__u8 reserved[252 ]; +struct nvme_nvm_id_chnl chnls[]; +} __attribute__((packed)); + +#define NVME_NVM_CHNLS_PR_REQ ((4096U - sizeof(struct nvme_nvm_id)) \ + / sizeof(struct nvme_nvm_id_chnl)) +enum {NVME_CTRL_ONCS_COMPARE =1 <<0 ,NVME_CTRL_ONCS_WRITE_UNCORRECTABLE =1 <<1 ,@@ -130,6 +159,7 @@ struct nvme_id_ns {enum {NVME_NS_FEAT_THIN =1 <<0 , +NVME_NS_FEAT_NVM =1 <<3 ,NVME_NS_FLBAS_LBA_MASK =0xf ,NVME_NS_FLBAS_META_EXT =0x10 ,NVME_LBAF_RP_BEST =0 ,@@ -146,6 +176,8 @@ enum {NVME_NS_DPS_PI_TYPE1 =1 ,NVME_NS_DPS_PI_TYPE2 =2 ,NVME_NS_DPS_PI_TYPE3 =3 , + + NVME_NS_NVM = 1, }; struct nvme_smart_log {@@ -229,6 +261,12 @@ enum nvme_opcode { nvme_cmd_resv_report =0x0e , nvme_cmd_resv_acquire =0x11 , nvme_cmd_resv_release =0x15 , + + nvme_nvm_cmd_hb_write =0x81 , + nvme_nvm_cmd_hb_read =0x02 , + nvme_nvm_cmd_phys_write =0x91 , + nvme_nvm_cmd_phys_read =0x92 , + nvme_nvm_cmd_erase = 0x90, }; struct nvme_common_command {@@ -261,6 +299,74 @@ struct nvme_rw_command {__le16 appmask; }; +struct nvme_nvm_hb_rw { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd2; +__le64 metadata; +__le64 prp1; +__le64 prp2; +__le64 slba; +__le16 length; +__le16 control; +__le32 dsmgmt; +__le64 phys_addr; +}; + +struct nvme_nvm_l2ptbl { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__le32 cdw2[4 ]; +__le64 prp1; +__le64 prp2; +__le64 slba; +__le32 nlb; +__u16 prp1_len; +__le16 cdw14[5 ]; +}; + +struct nvme_nvm_bbtbl { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd[2 ]; +__le64 prp1; +__le64 prp2; +__le32 prp1_len; +__le32 prp2_len; +__le32 lbb; +__u32 rsvd11[3 ]; +}; + +struct nvme_nvm_set_resp { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd[2 ]; +__le64 prp1; +__le64 prp2; +__le64 resp; +__u32 rsvd11[4 ]; +}; + +struct nvme_nvm_erase_blk { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd[2 ]; +__le64 prp1; +__le64 prp2; +__le64 blk_addr; +__u32 rsvd11[4 ]; +}; +enum {NVME_RW_LR =1 <<15 ,NVME_RW_FUA =1 <<14 ,@@ -328,6 +434,13 @@ enum nvme_admin_opcode { nvme_admin_format_nvm =0x80 , nvme_admin_security_send =0x81 , nvme_admin_security_recv =0x82 , + + nvme_nvm_admin_identify =0xe2 , + nvme_nvm_admin_get_features =0xe6 , + nvme_nvm_admin_set_resp =0xe5 , + nvme_nvm_admin_get_l2p_tbl =0xea , + nvme_nvm_admin_get_bb_tbl =0xf2 , + nvme_nvm_admin_set_bb_tbl = 0xf1, }; enum {@@ -457,6 +570,18 @@ struct nvme_format_cmd {__u32 rsvd11[5 ]; }; +struct nvme_nvm_identify { +__u8 opcode; +__u8 flags; +__u16 command_id; +__le32 nsid; +__u64 rsvd[2 ]; +__le64 prp1; +__le64 prp2; +__le32 cns; +__u32 rsvd11[5 ]; +}; +struct nvme_command {union {struct nvme_common_command common;@@ -470,6 +595,13 @@ struct nvme_command {struct nvme_format_cmd format;struct nvme_dsm_cmd dsm;struct nvme_abort_cmd abort;
include/uapi/linux/nvme.h struct nvme_command { · line 607
Quoted 10 lines
include/uapi/linux/nvme.h +7
-0+struct nvme_nvm_identify nvm_identify; +struct nvme_nvm_hb_rw nvm_hb_rw; +struct nvme_nvm_l2ptbl nvm_l2p; +struct nvme_nvm_bbtbl nvm_get_bb; +struct nvme_nvm_bbtbl nvm_set_bb; +struct nvme_nvm_set_resp nvm_resp; +struct nvme_nvm_erase_blk nvm_erase; }; };
All these could be moved into the nvme-lightnvm.c file. Taking the previous discussion with Christoph regarding exposing user headers with the protocol. It maybe shouldn't be exposed.
Should I push it into nvme-lightnvm.h? (there is still a need for struct nvme_nvm_hb_rw. The other defs can be moved)
Anything else?