From 0e5e4f0e56aca0df1d5648db0be9028bd573b25c Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Fri, 9 Nov 2012 16:33:05 -0700 Subject: NVMe: Add discard support for capable devices This adds discard support to block queues if the nvme device is capable of deallocating blocks as indicated by the controller's optional command support. A discard flagged bio request will submit an NVMe deallocate Data Set Management command for the requested blocks. Signed-off-by: Keith Busch Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 4fa3b0b9b071..bde44c1fd213 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -107,6 +107,12 @@ struct nvme_id_ctrl { __u8 vs[1024]; }; +enum { + NVME_CTRL_ONCS_COMPARE = 1 << 0, + NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1, + NVME_CTRL_ONCS_DSM = 1 << 2, +}; + struct nvme_lbaf { __le16 ms; __u8 ds; @@ -246,6 +252,31 @@ enum { NVME_RW_DSM_COMPRESSED = 1 << 7, }; +struct nvme_dsm_cmd { + __u8 opcode; + __u8 flags; + __u16 command_id; + __le32 nsid; + __u64 rsvd2[2]; + __le64 prp1; + __le64 prp2; + __le32 nr; + __le32 attributes; + __u32 rsvd12[4]; +}; + +enum { + NVME_DSMGMT_IDR = 1 << 0, + NVME_DSMGMT_IDW = 1 << 1, + NVME_DSMGMT_AD = 1 << 2, +}; + +struct nvme_dsm_range { + __le32 cattr; + __le32 nlb; + __le64 slba; +}; + /* Admin commands */ enum nvme_admin_opcode { @@ -372,6 +403,7 @@ struct nvme_command { struct nvme_create_sq create_sq; struct nvme_delete_queue delete_queue; struct nvme_download_firmware dlfw; + struct nvme_dsm_cmd dsm; }; }; -- cgit v1.2.3 From 13c3b0fcc8e33ba49f252378f6e7290b146042af Mon Sep 17 00:00:00 2001 From: Vishal Verma Date: Mon, 4 Mar 2013 18:40:57 -0700 Subject: NVMe: Move structures & definitions to header file nvme-scsi.c uses several data structures and definitions that were previously private to nvme-core.c. Move the definitions to nvme.h, protected by __KERNEL__. Signed-off-by: Vishal Verma Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index bde44c1fd213..6f899add14ab 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -493,4 +493,64 @@ struct nvme_admin_cmd { #define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_admin_cmd) #define NVME_IOCTL_SUBMIT_IO _IOW('N', 0x42, struct nvme_user_io) +#ifdef __KERNEL__ +#include + +#define NVME_IO_TIMEOUT (5 * HZ) + +/* + * Represents an NVM Express device. Each nvme_dev is a PCI function. + */ +struct nvme_dev { + struct list_head node; + struct nvme_queue **queues; + u32 __iomem *dbs; + struct pci_dev *pci_dev; + struct dma_pool *prp_page_pool; + struct dma_pool *prp_small_pool; + int instance; + int queue_count; + int db_stride; + u32 ctrl_config; + struct msix_entry *entry; + struct nvme_bar __iomem *bar; + struct list_head namespaces; + char serial[20]; + char model[40]; + char firmware_rev[8]; + u32 max_hw_sectors; + u16 oncs; +}; + +/* + * An NVM Express namespace is equivalent to a SCSI LUN + */ +struct nvme_ns { + struct list_head list; + + struct nvme_dev *dev; + struct request_queue *queue; + struct gendisk *disk; + + int ns_id; + int lba_shift; +}; + +/* + * The nvme_iod describes the data in an I/O, including the list of PRP + * entries. You can't see it in this data structure because C doesn't let + * me express that. Use nvme_alloc_iod to ensure there's enough space + * allocated to store the PRP list. + */ +struct nvme_iod { + void *private; /* For the use of the submitter of the I/O */ + int npages; /* In the PRP list. 0 means small pool in use */ + int offset; /* Of PRP list */ + int nents; /* Used in scatterlist */ + int length; /* Of data, in bytes */ + dma_addr_t first_dma; + struct scatterlist sg[0]; +}; +#endif + #endif /* _LINUX_NVME_H */ -- cgit v1.2.3 From f8ebf8409abfdaeeb8c847381629a2a8b8e3d816 Mon Sep 17 00:00:00 2001 From: Vishal Verma Date: Wed, 27 Mar 2013 07:13:41 -0400 Subject: NVMe: Add definitions for format command The SCSI emulation has the ability to send format commands, so we need to add the definition of the command. Also add a missing error code. Signed-off-by: Vishal Verma Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 6f899add14ab..f1974cab60cf 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -393,6 +393,16 @@ struct nvme_download_firmware { __u32 rsvd12[4]; }; +struct nvme_format_cmd { + __u8 opcode; + __u8 flags; + __u16 command_id; + __le32 nsid; + __u64 rsvd2[4]; + __le32 cdw10; + __u32 rsvd11[5]; +}; + struct nvme_command { union { struct nvme_common_command common; @@ -403,6 +413,7 @@ struct nvme_command { struct nvme_create_sq create_sq; struct nvme_delete_queue delete_queue; struct nvme_download_firmware dlfw; + struct nvme_format_cmd format; struct nvme_dsm_cmd dsm; }; }; @@ -420,6 +431,7 @@ enum { NVME_SC_FUSED_FAIL = 0x9, NVME_SC_FUSED_MISSING = 0xa, NVME_SC_INVALID_NS = 0xb, + NVME_SC_CMD_SEQ_ERROR = 0xc, NVME_SC_LBA_RANGE = 0x80, NVME_SC_CAP_EXCEEDED = 0x81, NVME_SC_NS_NOT_READY = 0x82, -- cgit v1.2.3 From 5d0f6131a79adfa1fb51309c5f81a2a4ef879dd4 Mon Sep 17 00:00:00 2001 From: Vishal Verma Date: Mon, 4 Mar 2013 18:40:58 -0700 Subject: NVMe: Add nvme-scsi.c Translates SCSI commands in SG_IO ioctl to NVMe commands. Uses the scsi-nvme translation spec from nvmexpress.org as reference. Signed-off-by: Vishal Verma Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index f1974cab60cf..aa575033dbe7 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -546,6 +546,8 @@ struct nvme_ns { int ns_id; int lba_shift; + u64 mode_select_num_blocks; + u32 mode_select_block_len; }; /* @@ -563,6 +565,39 @@ struct nvme_iod { dma_addr_t first_dma; struct scatterlist sg[0]; }; + +/** + * nvme_free_iod - frees an nvme_iod + * @dev: The device that the I/O was submitted to + * @iod: The memory to free + */ +void nvme_free_iod(struct nvme_dev *dev, struct nvme_iod *iod); + +int nvme_setup_prps(struct nvme_dev *dev, struct nvme_common_command *cmd, + struct nvme_iod *iod, int total_len, gfp_t gfp); +struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write, + unsigned long addr, unsigned length); +void nvme_unmap_user_pages(struct nvme_dev *dev, int write, + struct nvme_iod *iod); +struct nvme_queue *get_nvmeq(struct nvme_dev *dev); +void put_nvmeq(struct nvme_queue *nvmeq); +int nvme_submit_sync_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd, + u32 *result, unsigned timeout); +int nvme_submit_flush_data(struct nvme_queue *nvmeq, struct nvme_ns *ns); +int nvme_submit_admin_cmd(struct nvme_dev *, struct nvme_command *, + u32 *result); +int nvme_identify(struct nvme_dev *, unsigned nsid, unsigned cns, + dma_addr_t dma_addr); +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 sg_io_hdr; + +int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr); +int nvme_sg_get_version_num(int __user *ip); + #endif #endif /* _LINUX_NVME_H */ -- cgit v1.2.3 From 063cc6d5591ea9c0631b81ac5c7b829d99738b2f Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Wed, 27 Mar 2013 21:28:22 -0400 Subject: NVMe: Abstract out sector to block number conversion Introduce nvme_block_nr() to help convert sectors to block numbers. This fixes an integer overflow in the SCSI conversion layer, and it's slightly less typing than opencoding it. Signed-off-by: Matthew Wilcox Acked-by: Keith Busch --- include/linux/nvme.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index aa575033dbe7..09f419d4da4e 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -566,6 +566,11 @@ struct nvme_iod { struct scatterlist sg[0]; }; +static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector) +{ + return (sector >> (ns->lba_shift - 9)); +} + /** * nvme_free_iod - frees an nvme_iod * @dev: The device that the I/O was submitted to -- cgit v1.2.3 From 1c9b52651dad0ff1fa71fc6205c86d972f25bcc0 Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Tue, 16 Apr 2013 15:21:06 -0400 Subject: NVMe: Fix endian-related problems in user I/O submission path When constructing the command, dsmgmt needs to be treated as a 32-bit value, not a 16-bit value. reftag, apptag and appmask all need to be converted from native-endian to little-endian. Again, sparse's bitwise warnings caught this problem. Thanks to Keith for pointing out the correct way to fix the reftag. Signed-off-by: Matthew Wilcox Acked-by: Keith Busch --- include/linux/nvme.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 09f419d4da4e..7ae7ecfc0947 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -207,11 +207,11 @@ struct nvme_common_command { __u8 flags; __u16 command_id; __le32 nsid; - __u32 cdw2[2]; + __le32 cdw2[2]; __le64 metadata; __le64 prp1; __le64 prp2; - __u32 cdw10[6]; + __le32 cdw10[6]; }; struct nvme_rw_command { -- cgit v1.2.3 From 5e82e952f04681c10f35e02ee0a4a43ec027137a Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Tue, 19 Feb 2013 10:17:58 -0700 Subject: NVMe: Add a character device for each nvme device Registers a miscellaneous device for each nvme controller probed. This creates character device files as /dev/nvmeN, where N is the device instance, and supports nvme admin ioctl commands so devices without namespaces can be managed. Signed-off-by: Keith Busch Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 7ae7ecfc0947..9b6fba872f47 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -507,6 +507,8 @@ struct nvme_admin_cmd { #ifdef __KERNEL__ #include +#include +#include #define NVME_IO_TIMEOUT (5 * HZ) @@ -527,6 +529,9 @@ struct nvme_dev { struct msix_entry *entry; struct nvme_bar __iomem *bar; struct list_head namespaces; + struct kref kref; + struct miscdevice miscdev; + char name[12]; char serial[20]; char model[40]; char firmware_rev[8]; -- cgit v1.2.3 From 159b67d7aefe3902df91075be5d80943c1570aa8 Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Tue, 9 Apr 2013 17:13:20 -0600 Subject: NVMe: Device specific stripe size handling We have an nvme device that has a concept of a stripe size. IO requests that do not transfer data crossing a stripe boundary has greater performance compared to IO that does cross it. This patch sets the stripe size for the device if the device and vendor ids match one with this feature and splits IO requests that cross the stripe boundary. Signed-off-by: Keith Busch Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 9b6fba872f47..af29b0e0b092 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -536,6 +536,7 @@ struct nvme_dev { char model[40]; char firmware_rev[8]; u32 max_hw_sectors; + u32 stripe_size; u16 oncs; }; -- cgit v1.2.3 From f410c680b5344f1cb63ff011c6ae3d4963f45c30 Mon Sep 17 00:00:00 2001 From: Keith Busch Date: Tue, 23 Apr 2013 17:23:59 -0600 Subject: NVMe: Meta-data support in NVME_IOCTL_SUBMIT_IO This adds support for namespaces with separate meta-data formats in the submit io ioctl. The meta-data buffer has to be a contiguous, so such a buffer is allocated and the mapped user pages are copied to/from this buffer for write/read commands. Signed-off-by: Keith Busch Signed-off-by: Matthew Wilcox --- include/linux/nvme.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index af29b0e0b092..971ef086ed63 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -552,6 +552,7 @@ struct nvme_ns { int ns_id; int lba_shift; + int ms; u64 mode_select_num_blocks; u32 mode_select_block_len; }; -- cgit v1.2.3 From ab3ea5bf37e7189e843e19e500e7af50e802b5f6 Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Mon, 6 May 2013 08:22:18 -0400 Subject: NVMe: Simplify Firmware Activate code slightly Add definitions for the three Firmware Activate actions, and change the SCSI translation code to construct the command into a temporary variable instead of translating the endianness back-and-forth. Signed-off-by: Matthew Wilcox Reviewed-by: Vishal Verma --- include/linux/nvme.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/linux') diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 971ef086ed63..f451c8d6e231 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -316,6 +316,9 @@ enum { NVME_FEAT_WRITE_ATOMIC = 0x0a, NVME_FEAT_ASYNC_EVENT = 0x0b, NVME_FEAT_SW_PROGRESS = 0x0c, + NVME_FWACT_REPL = (0 << 3), + NVME_FWACT_REPL_ACTV = (1 << 3), + NVME_FWACT_ACTV = (2 << 3), }; struct nvme_identify { -- cgit v1.2.3