nvme driver split, the easy part
Christoph Hellwig
maintainerThis series contains the trivial and hopefully uncontroversial part of the nvme driver split to show how I want to get started.
This creates a new core.c with functions sitting on top of the block layer, splits and split a new struct nvme_ctrl out of struct nvme_dev so that the SCSI translation layer is decoupled from the PCI driver internals. A new struct nvme_ctrl_ops is introduced to call into the low level driver, which for now just has a single method to read a 32-bit wide register.
Christoph Hellwig
maintainerPATCH 1/5 nvme: move struct nvme_iod to pci.c
This structure is specific to the PCIe driver internals and should be moved to pci.c.
--- drivers/nvme/host/nvme.h | 17 ----------------- drivers/nvme/host/pci.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-)
drivers/nvme/host/nvme.h +0 -17
@@ -88,23 +88,6 @@ struct nvme_ns {u32 mode_select_block_len; }; -/* -* 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 { -unsigned long 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 meta_sg[1 ];/* metadata requires single contiguous buffer */ -struct scatterlist sg[0 ]; -}; -static inline u64 nvme_block_nr (struct nvme_ns *ns,sector_t sector) {return (sector >> (ns->lba_shift -9 ));
drivers/nvme/host/pci.c +17 -0
@@ -128,6 +128,23 @@ struct nvme_queue { };/* +* 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 { +unsigned long 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 meta_sg[1 ];/* metadata requires single contiguous buffer */ +struct scatterlist sg[0 ]; +}; + +/* * Check we didin't inadvertently grow the command struct */ static inline void _nvme_check_size (void )
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH 2/5 nvme: split command submission helpers out of pci.c
In reply to Christoph HellwigCreate a new core.c and start by adding the command submission helpers to it, which are already abstracted away from the actual hardware queues by the block layer.
--- drivers/nvme/host/Makefile | 2 +- drivers/nvme/host/core.c | 172 +++++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 3 + drivers/nvme/host/pci.c | 153 +--------------------------------------- 4 files changed, 177 insertions(+), 153 deletions(-) create mode 100644 drivers/nvme/host/core.c
drivers/nvme/host/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_BLK_DEV_NVME) += nvme.o -nvme-y += pci.o scsi.o +nvme-y += core.o pci.o scsi.o
drivers/nvme/host/core.c new file +172 -0
172 lines not on this page · raw message
drivers/nvme/host/nvme.h +3 -0
@@ -22,6 +22,9 @@extern unsigned char nvme_io_timeout;#define NVME_IO_TIMEOUT (nvme_io_timeout * HZ) +extern unsigned char admin_timeout; +#define ADMIN_TIMEOUT (admin_timeout * HZ) +/* * Represents an NVM Express device. Each nvme_dev is a PCI function. */
drivers/nvme/host/pci.c +1 -152
173 lines not on this page · raw message
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH 3/5 nvme: add a vendor field to struct nvme_dev
In reply to Christoph HellwigThe SCSI translation layer currently has to poke into the PCI device structure to find a vendor ID for the device identification fallback. We won't nessecarily have a PCI device behind the device structure in the future, so add a new vendor field that can be filled out by the PCIe driver instead.
--- drivers/nvme/host/nvme.h | 1 + drivers/nvme/host/pci.c | 3 +++ drivers/nvme/host/scsi.c | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/host/nvme.h +1 -0
@@ -69,6 +69,7 @@ struct nvme_dev {u16 abort_limit;u8 event_limit;u8 vwc; +u16 vendor; };/*
drivers/nvme/host/pci.c +3 -0
@@ -2996,6 +2996,9 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)INIT_WORK (&dev->reset_work, nvme_reset_work); dev->dev =get_device (&pdev->dev);pci_set_drvdata (pdev, dev); + + dev->vendor = pdev->vendor; + result =nvme_set_instance (dev);if (result) goto put_pci;
drivers/nvme/host/scsi.c +1 -1
@@ -657,7 +657,7 @@ static int nvme_trans_device_id_page(struct nvme_ns *ns, struct sg_io_hdr *hdr, inq_response[6 ] =0x00 ;/* Rsvd */ inq_response[7 ] =0x44 ;/* Designator Length */ -sprintf (&inq_response[8 ],"%04x" ,to_pci_dev (dev->dev)->vendor); +sprintf (&inq_response[8 ],"%04x" , dev->vendor);memcpy (&inq_response[12 ], dev->model,sizeof (dev->model));sprintf (&inq_response[52 ],"%04x" , tmp_id);memcpy (&inq_response[56 ], dev->serial,sizeof (dev->serial));
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH 4/5 nvme: use offset instead of a struct for registers
In reply to Christoph HellwigThis makes life easier for future non-PCI drivers where access to the registers might be more complicated. Note that Linux drivers are pretty evenly split between the two versions, and in fact the NVMe driver already uses offsets for the doorbells.
--- drivers/nvme/host/nvme.h | 2 +- drivers/nvme/host/pci.c | 58 +++++++++++++++++++++++++----------------------- drivers/nvme/host/scsi.c | 6 ++--- include/linux/nvme.h | 27 +++++++++++----------- 4 files changed, 47 insertions(+), 46 deletions(-)
drivers/nvme/host/nvme.h +1 -1
@@ -46,7 +46,7 @@ struct nvme_dev {u32 db_stride;u32 ctrl_config;struct msix_entry *entry; -struct nvme_bar __iomem *bar; +void __iomem *bar;struct list_head namespaces;struct kref kref;struct device *device;
drivers/nvme/host/pci.c +30 -28
181 lines not on this page · raw message
drivers/nvme/host/scsi.c +3 -3
@@ -611,7 +611,7 @@ static int nvme_trans_device_id_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,memset (inq_response,0 , alloc_len); inq_response[1 ] =INQ_DEVICE_IDENTIFICATION_PAGE ;/* Page Code */ -if (readl (&dev->bar->vs) >=NVME_VS (1 ,1 )) { +if (readl (dev->bar +NVME_REG_VS ) >=NVME_VS (1 ,1 )) {struct nvme_id_ns *id_ns;void *eui;int len;
@@ -623,7 +623,7 @@ static int nvme_trans_device_id_page(struct nvme_ns *ns, struct sg_io_hdr *hdr, eui = id_ns->eui64; len =sizeof (id_ns->eui64); -if (readl (&dev->bar->vs) >=NVME_VS (1 ,2 )) { +if (readl (dev->bar +NVME_REG_VS ) >=NVME_VS (1 ,2 )) {if (bitmap_empty (eui, len *8 )) { eui = id_ns->nguid; len =sizeof (id_ns->nguid);
@@ -2297,7 +2297,7 @@ static int nvme_trans_test_unit_ready(struct nvme_ns *ns, {struct nvme_dev *dev = ns->dev; -if (!(readl (&dev->bar->csts) &NVME_CSTS_RDY )) +if (!(readl (dev->bar +NVME_REG_CSTS ) &NVME_CSTS_RDY ))return nvme_trans_completion (hdr,SAM_STAT_CHECK_CONDITION ,NOT_READY ,SCSI_ASC_LUN_NOT_READY ,SCSI_ASCQ_CAUSE_NOT_REPORTABLE );
include/linux/nvme.h +13 -14
@@ -17,20 +17,19 @@#include <linux/types.h> -struct nvme_bar { -__u64 cap;/* Controller Capabilities */ -__u32 vs;/* Version */ -__u32 intms;/* Interrupt Mask Set */ -__u32 intmc;/* Interrupt Mask Clear */ -__u32 cc;/* Controller Configuration */ -__u32 rsvd1;/* Reserved */ -__u32 csts;/* Controller Status */ -__u32 nssr;/* Subsystem Reset */ -__u32 aqa;/* Admin Queue Attributes */ -__u64 asq;/* Admin SQ Base Address */ -__u64 acq;/* Admin CQ Base Address */ -__u32 cmbloc;/* Controller Memory Buffer Location */ -__u32 cmbsz;/* Controller Memory Buffer Size */ +enum { +NVME_REG_CAP =0x0000 ,/* Controller Capabilities */ +NVME_REG_VS =0x0008 ,/* Version */ +NVME_REG_INTMS =0x000c ,/* Interrupt Mask Set */ +NVME_REG_INTMC =0x0010 ,/* Interrupt Mask Set */ +NVME_REG_CC =0x0014 ,/* Controller Configuration */ +NVME_REG_CSTS =0x001c ,/* Controller Status */ +NVME_REG_NSSR =0x0020 ,/* NVM Subsystem Reset */ +NVME_REG_AQA =0x0024 ,/* Admin Queue Attributes */ +NVME_REG_ASQ =0x0028 ,/* Admin SQ Base Address */ +NVME_REG_ACQ =0x0030 ,/* Admin SQ Base Address */ +NVME_REG_CMBLOC =0x0038 ,/* Controller Memory Buffer Location */ +NVME_REG_CMBSZ =0x0040 ,/* Controller Memory Buffer Size */ };#define NVME_CAP_MQES (cap) ((cap) & 0xffff)
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerPATCH 5/5 nvme: split a new struct nvme_ctrl out of struct nvme_dev
In reply to Christoph HellwigThe new struct nvme_ctrl will be used by the common NVMe code that sits on top of struct request_queue and the new nvme_ctrl_ops abstraction. It only contains the bare minimum required, which consists of values sampled during controller probe, the admin queue pointer and a second struct device pointer at the moment, but more will follow later. Only values that are not used in the I/O fast path should be moved to struct nvme_ctrl so that drivers can optimize their cache line usage easily. That's also the reason why we have two device pointers as the struct device is used for DMA mapping purposes.
--- drivers/nvme/host/core.c | 10 +-- drivers/nvme/host/nvme.h | 61 ++++++--------- drivers/nvme/host/pci.c | 190 +++++++++++++++++++++++++++++++---------------- drivers/nvme/host/scsi.c | 85 ++++++++++----------- 4 files changed, 190 insertions(+), 156 deletions(-)
drivers/nvme/host/core.c +5 -5
@@ -78,7 +78,7 @@ int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,return __nvme_submit_sync_cmd (q, cmd, buffer,NULL , bufflen,NULL ,0 ); } -int nvme_identify_ctrl (struct nvme_dev *dev,struct nvme_id_ctrl **id) +int nvme_identify_ctrl (struct nvme_ctrl *dev,struct nvme_id_ctrl **id) {struct nvme_command c = { };int error;
@@ -98,7 +98,7 @@ int nvme_identify_ctrl(struct nvme_dev *dev, struct nvme_id_ctrl **id)return error; } -int nvme_identify_ns (struct nvme_dev *dev,unsigned nsid, +int nvme_identify_ns (struct nvme_ctrl *dev,unsigned nsid,struct nvme_id_ns **id) {struct nvme_command c = { };
@@ -119,7 +119,7 @@ int nvme_identify_ns(struct nvme_dev *dev, unsigned nsid,return error; } -int nvme_get_features (struct nvme_dev *dev,unsigned fid,unsigned nsid, +int nvme_get_features (struct nvme_ctrl *dev,unsigned fid,unsigned nsid,dma_addr_t dma_addr,u32 *result) {struct nvme_command c;
@@ -134,7 +134,7 @@ int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid, result, 0); } -int nvme_set_features (struct nvme_dev *dev,unsigned fid,unsigned dword11, +int nvme_set_features (struct nvme_ctrl *dev,unsigned fid,unsigned dword11,dma_addr_t dma_addr,u32 *result) {struct nvme_command c;
@@ -149,7 +149,7 @@ int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11, result, 0); } -int nvme_get_log_page (struct nvme_dev *dev,struct nvme_smart_log **log) +int nvme_get_log_page (struct nvme_ctrl *dev,struct nvme_smart_log **log) {struct nvme_command c = { };int error;
drivers/nvme/host/nvme.h +22 -39
94 lines not on this page · raw message
drivers/nvme/host/pci.c +125 -65
498 lines not on this page · raw message
drivers/nvme/host/scsi.c +38 -47
320 lines not on this page · raw message
Signature · 1 line
1.9.1
Keith Busch
Acked-byQuoted 8 lines · Christoph Hellwig
This series contains the trivial and hopefully uncontroversial part of the nvme driver split to show how I want to get started.
This creates a new
core.cwith functions sitting on top of the block layer, splits and split a new structnvme_ctrlout of structnvme_devso that the SCSI translation layer is decoupled from the PCI driver internals. A new structnvme_ctrl_opsis introduced to call into the low level driver, which for now just has a single method to read a 32-bit wide register.
Nothing here appears controversial; looks good to me.
for the whole series.
Your second series will take a few days to process, but I can already tell the meta-data patch [2/8] is incomplete. At the least, we need to set cmnd.rw.meta in nvme_submit_priv(), but I'll give a more thorough review later this week.
Christoph Hellwig
maintainerQuoted 4 lines · Keith Busch
Your second series will take a few days to process, but I can already tell the meta-data patch [2/8] is incomplete. At the least, we need to set cmnd.rw.meta in
nvme_submit_priv(), but I'll give a more thorough review later this week.
That's handled by "nvme: refactor nvme_queue_rq" which now uses a common helper to map data and metadata shared by the read/write and passthrough path.
Thanks for the offer for testing!
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Keith Busch
Your second series will take a few days to process, but I can already tell the meta-data patch [2/8] is incomplete. At the least, we need to set cmnd.rw.meta in
nvme_submit_priv(), but I'll give a more thorough review later this week.That's handled by "nvme: refactor
nvme_queue_rq" which now uses a common helper to map data and metadata shared by the read/write and passthrough path.
Aha, so it is. Very cool, I'm still getting used to the recent changes. :)
Quoted 1 line
Thanks for the offer for testing!
No problem!
Christoph Hellwig
maintainerQuoted 5 lines · Keith Busch
Quoted 3 lines
That's handled by "nvme: refactor
nvme_queue_rq" which now uses a common helper to map data and metadata shared by the read/write and passthrough path.Aha, so it is. Very cool, I'm still getting used to the recent changes. :)
I only sent that out late last week, and it still needs a throughout review from you.
Note that only this second series depends on that series, the first one only touches unrelated code.