History

Merge branch 'for-3.20' of git://git.infradead.org/users/kbusch/linux-nvme into for-linus

Merge 3.20 NVMe changes from Keith.

Jens Axboe committed 11 years ago

Commit decf6d72 parents 045c47c 0c0f9b94 files · +414 −213Browse files

Unified · Split

4 files
  1. drivers/block/nvme-core.c +331 −165
  2. drivers/block/nvme-scsi.c +54 −42
  3. include/linux/nvme.h +4 −5
  4. include/uapi/linux/nvme.h +25 −1
drivers/block/nvme-core.c+331−165
@@ -37,17 +37,18 @@ · 36 unmodified lines
3737 #include <linux/ptrace.h>
3838 #include <linux/sched.h>
3939 #include <linux/slab.h>
40+#include <linux/t10-pi.h>
4041 #include <linux/types.h>
4142 #include <scsi/sg.h>
4243 #include <asm-generic/io-64-nonatomic-lo-hi.h>
4344
45+#define NVME_MINORS (1U << MINORBITS)
4446 #define NVME_Q_DEPTH 1024
4547 #define NVME_AQ_DEPTH 64
4648 #define SQ_SIZE(depth) (depth * sizeof(struct nvme_command))
4749 #define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion))
4850 #define ADMIN_TIMEOUT (admin_timeout * HZ)
4951 #define SHUTDOWN_TIMEOUT (shutdown_timeout * HZ)
50−#define IOD_TIMEOUT (retry_time * HZ)
5152
5253 static unsigned char admin_timeout = 60;
5354 module_param(admin_timeout, byte, 0644);
@@ -57,10 +58,6 @@ unsigned char nvme_io_timeout = 30; · 3 unmodified lines
5758 module_param_named(io_timeout, nvme_io_timeout, byte, 0644);
5859 MODULE_PARM_DESC(io_timeout, "timeout in seconds for I/O");
5960
60−static unsigned char retry_time = 30;
61−module_param(retry_time, byte, 0644);
62−MODULE_PARM_DESC(retry_time, "time in seconds to retry failed I/O");
63−
6461 static unsigned char shutdown_timeout = 5;
6562 module_param(shutdown_timeout, byte, 0644);
6663 MODULE_PARM_DESC(shutdown_timeout, "timeout in seconds for controller shutdown");
@@ -68,6 +65,9 @@ MODULE_PARM_DESC(shutdown_timeout, "timeout in seconds for controller shutdown") · 1 unmodified line
6865 static int nvme_major;
6966 module_param(nvme_major, int, 0);
7067
68+static int nvme_char_major;
69+module_param(nvme_char_major, int, 0);
70+
7171 static int use_threaded_interrupts;
7272 module_param(use_threaded_interrupts, int, 0);
7373
@@ -76,7 +76,8 @@ static LIST_HEAD(dev_list); · 2 unmodified lines
7676 static struct task_struct *nvme_thread;
7777 static struct workqueue_struct *nvme_workq;
7878 static wait_queue_head_t nvme_kthread_wait;
79−static struct notifier_block nvme_nb;
79+
80+static struct class *nvme_class;
8081
8182 static void nvme_reset_failed_dev(struct work_struct *ws);
8283 static int nvme_process_cq(struct nvme_queue *nvmeq);
@@ -95,7 +96,6 @@ struct async_cmd_info { · 12 unmodified lines
9596 * commands and one for I/O commands).
9697 */
9798 struct nvme_queue {
98− struct llist_node node;
9999 struct device *q_dmadev;
100100 struct nvme_dev *dev;
101101 char irqname[24]; /* nvme4294967295-65535\0 */
@@ -482,6 +482,62 @@ static int nvme_error_status(u16 status) · 380 unmodified lines
482482 }
483483 }
484484
485+static void nvme_dif_prep(u32 p, u32 v, struct t10_pi_tuple *pi)
486+{
487+ if (be32_to_cpu(pi->ref_tag) == v)
488+ pi->ref_tag = cpu_to_be32(p);
489+}
490+
491+static void nvme_dif_complete(u32 p, u32 v, struct t10_pi_tuple *pi)
492+{
493+ if (be32_to_cpu(pi->ref_tag) == p)
494+ pi->ref_tag = cpu_to_be32(v);
495+}
496+
497+/**
498+ * nvme_dif_remap - remaps ref tags to bip seed and physical lba
499+ *
500+ * The virtual start sector is the one that was originally submitted by the
501+ * block layer. Due to partitioning, MD/DM cloning, etc. the actual physical
502+ * start sector may be different. Remap protection information to match the
503+ * physical LBA on writes, and back to the original seed on reads.
504+ *
505+ * Type 0 and 3 do not have a ref tag, so no remapping required.
506+ */
507+static void nvme_dif_remap(struct request *req,
508+ void (*dif_swap)(u32 p, u32 v, struct t10_pi_tuple *pi))
509+{
510+ struct nvme_ns *ns = req->rq_disk->private_data;
511+ struct bio_integrity_payload *bip;
512+ struct t10_pi_tuple *pi;
513+ void *p, *pmap;
514+ u32 i, nlb, ts, phys, virt;
515+
516+ if (!ns->pi_type || ns->pi_type == NVME_NS_DPS_PI_TYPE3)
517+ return;
518+
519+ bip = bio_integrity(req->bio);
520+ if (!bip)
521+ return;
522+
523+ pmap = kmap_atomic(bip->bip_vec->bv_page) + bip->bip_vec->bv_offset;
524+ if (!pmap)
525+ return;
526+
527+ p = pmap;
528+ virt = bip_get_seed(bip);
529+ phys = nvme_block_nr(ns, blk_rq_pos(req));
530+ nlb = (blk_rq_bytes(req) >> ns->lba_shift);
531+ ts = ns->disk->integrity->tuple_size;
532+
533+ for (i = 0; i < nlb; i++, virt++, phys++) {
534+ pi = (struct t10_pi_tuple *)p;
535+ dif_swap(phys, virt, pi);
536+ p += ts;
537+ }
538+ kunmap_atomic(pmap);
539+}
540+
485541 static void req_completion(struct nvme_queue *nvmeq, void *ctx,
486542 struct nvme_completion *cqe)
487543 {
@@ -512,9 +568,16 @@ static void req_completion(struct nvme_queue *nvmeq, void *ctx, · 24 unmodified lines
512568 "completing aborted command with status:%04x\n",
513569 status);
514570
515− if (iod->nents)
571+ if (iod->nents) {
516572 dma_unmap_sg(&nvmeq->dev->pci_dev->dev, iod->sg, iod->nents,
517573 rq_data_dir(req) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
574+ if (blk_integrity_rq(req)) {
575+ if (!rq_data_dir(req))
576+ nvme_dif_remap(req, nvme_dif_complete);
577+ dma_unmap_sg(&nvmeq->dev->pci_dev->dev, iod->meta_sg, 1,
578+ rq_data_dir(req) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
579+ }
580+ }
518581 nvme_free_iod(nvmeq->dev, iod);
519582
520583 blk_mq_complete_request(req);
@@ -670,6 +733,24 @@ static int nvme_submit_iod(struct nvme_queue *nvmeq, struct nvme_iod *iod, · 149 unmodified lines
670733 cmnd->rw.prp2 = cpu_to_le64(iod->first_dma);
671734 cmnd->rw.slba = cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req)));
672735 cmnd->rw.length = cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
736+
737+ if (blk_integrity_rq(req)) {
738+ cmnd->rw.metadata = cpu_to_le64(sg_dma_address(iod->meta_sg));
739+ switch (ns->pi_type) {
740+ case NVME_NS_DPS_PI_TYPE3:
741+ control |= NVME_RW_PRINFO_PRCHK_GUARD;
742+ break;
743+ case NVME_NS_DPS_PI_TYPE1:
744+ case NVME_NS_DPS_PI_TYPE2:
745+ control |= NVME_RW_PRINFO_PRCHK_GUARD |
746+ NVME_RW_PRINFO_PRCHK_REF;
747+ cmnd->rw.reftag = cpu_to_le32(
748+ nvme_block_nr(ns, blk_rq_pos(req)));
749+ break;
750+ }
751+ } else if (ns->ms)
752+ control |= NVME_RW_PRINFO_PRACT;
753+
673754 cmnd->rw.control = cpu_to_le16(control);
674755 cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt);
675756
@@ -690,6 +771,19 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx, · 14 unmodified lines
690771 struct nvme_iod *iod;
691772 enum dma_data_direction dma_dir;
692773
774+ /*
775+ * If formated with metadata, require the block layer provide a buffer
776+ * unless this namespace is formated such that the metadata can be
777+ * stripped/generated by the controller with PRACT=1.
778+ */
779+ if (ns->ms && !blk_integrity_rq(req)) {
780+ if (!(ns->pi_type && ns->ms == 8)) {
781+ req->errors = -EFAULT;
782+ blk_mq_complete_request(req);
783+ return BLK_MQ_RQ_QUEUE_OK;
784+ }
785+ }
786+
693787 iod = nvme_alloc_iod(req, ns->dev, GFP_ATOMIC);
694788 if (!iod)
695789 return BLK_MQ_RQ_QUEUE_BUSY;
@@ -725,6 +819,21 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx, · 29 unmodified lines
725819 iod->nents, dma_dir);
726820 goto retry_cmd;
727821 }
822+ if (blk_integrity_rq(req)) {
823+ if (blk_rq_count_integrity_sg(req->q, req->bio) != 1)
824+ goto error_cmd;
825+
826+ sg_init_table(iod->meta_sg, 1);
827+ if (blk_rq_map_integrity_sg(
828+ req->q, req->bio, iod->meta_sg) != 1)
829+ goto error_cmd;
830+
831+ if (rq_data_dir(req))
832+ nvme_dif_remap(req, nvme_dif_prep);
833+
834+ if (!dma_map_sg(nvmeq->q_dmadev, iod->meta_sg, 1, dma_dir))
835+ goto error_cmd;
836+ }
728837 }
729838
730839 nvme_set_info(cmd, iod, req_completion);
@@ -817,14 +926,6 @@ static irqreturn_t nvme_irq_check(int irq, void *data) · 86 unmodified lines
817926 return IRQ_WAKE_THREAD;
818927 }
819928
820−static void nvme_abort_cmd_info(struct nvme_queue *nvmeq, struct nvme_cmd_info *
821− cmd_info)
822−{
823− spin_lock_irq(&nvmeq->q_lock);
824− cancel_cmd_info(cmd_info, NULL);
825− spin_unlock_irq(&nvmeq->q_lock);
826−}
827−
828929 struct sync_cmd_info {
829930 struct task_struct *task;
830931 u32 result;
@@ -847,7 +948,6 @@ static void sync_completion(struct nvme_queue *nvmeq, void *ctx, · 16 unmodified lines
847948 static int nvme_submit_sync_cmd(struct request *req, struct nvme_command *cmd,
848949 u32 *result, unsigned timeout)
849950 {
850− int ret;
851951 struct sync_cmd_info cmdinfo;
852952 struct nvme_cmd_info *cmd_rq = blk_mq_rq_to_pdu(req);
853953 struct nvme_queue *nvmeq = cmd_rq->nvmeq;
@@ -859,29 +959,12 @@ static int nvme_submit_sync_cmd(struct request *req, struct nvme_command *cmd, · 5 unmodified lines
859959
860960 nvme_set_info(cmd_rq, &cmdinfo, sync_completion);
861961
862− set_current_state(TASK_KILLABLE);
863− ret = nvme_submit_cmd(nvmeq, cmd);
864− if (ret) {
865− nvme_finish_cmd(nvmeq, req->tag, NULL);
866− set_current_state(TASK_RUNNING);
867− }
868− ret = schedule_timeout(timeout);
869−
870− /*
871− * Ensure that sync_completion has either run, or that it will
872− * never run.
873− */
874− nvme_abort_cmd_info(nvmeq, blk_mq_rq_to_pdu(req));
875−
876− /*
877− * We never got the completion
878− */
879− if (cmdinfo.status == -EINTR)
880− return -EINTR;
962+ set_current_state(TASK_UNINTERRUPTIBLE);
963+ nvme_submit_cmd(nvmeq, cmd);
964+ schedule();
881965
882966 if (result)
883967 *result = cmdinfo.result;
884−
885968 return cmdinfo.status;
886969 }
887970
@@ -1158,29 +1241,18 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) · 270 unmodified lines
11581241 struct nvme_cmd_info *cmd = blk_mq_rq_to_pdu(req);
11591242 struct nvme_queue *nvmeq = cmd->nvmeq;
11601243
1161− /*
1162− * The aborted req will be completed on receiving the abort req.
1163− * We enable the timer again. If hit twice, it'll cause a device reset,
1164− * as the device then is in a faulty state.
1165− */
1166− int ret = BLK_EH_RESET_TIMER;
1167−
11681244 dev_warn(nvmeq->q_dmadev, "Timeout I/O %d QID %d\n", req->tag,
11691245 nvmeq->qid);
1170−
11711246 spin_lock_irq(&nvmeq->q_lock);
1172− if (!nvmeq->dev->initialized) {
1173− /*
1174− * Force cancelled command frees the request, which requires we
1175− * return BLK_EH_NOT_HANDLED.
1176− */
1177− nvme_cancel_queue_ios(nvmeq->hctx, req, nvmeq, reserved);
1178− ret = BLK_EH_NOT_HANDLED;
1179− } else
1180− nvme_abort_req(req);
1247+ nvme_abort_req(req);
11811248 spin_unlock_irq(&nvmeq->q_lock);
11821249
1183− return ret;
1250+ /*
1251+ * The aborted req will be completed on receiving the abort req.
1252+ * We enable the timer again. If hit twice, it'll cause a device reset,
1253+ * as the device then is in a faulty state.
1254+ */
1255+ return BLK_EH_RESET_TIMER;
11841256 }
11851257
11861258 static void nvme_free_queue(struct nvme_queue *nvmeq)
@@ -1233,7 +1305,6 @@ static void nvme_clear_queue(struct nvme_queue *nvmeq) · 46 unmodified lines
12331305 struct blk_mq_hw_ctx *hctx = nvmeq->hctx;
12341306
12351307 spin_lock_irq(&nvmeq->q_lock);
1236− nvme_process_cq(nvmeq);
12371308 if (hctx && hctx->tags)
12381309 blk_mq_tag_busy_iter(hctx, nvme_cancel_queue_ios, nvmeq);
12391310 spin_unlock_irq(&nvmeq->q_lock);
@@ -1256,7 +1327,10 @@ static void nvme_disable_queue(struct nvme_dev *dev, int qid) · 16 unmodified lines
12561327 }
12571328 if (!qid && dev->admin_q)
12581329 blk_mq_freeze_queue_start(dev->admin_q);
1259− nvme_clear_queue(nvmeq);
1330+
1331+ spin_lock_irq(&nvmeq->q_lock);
1332+ nvme_process_cq(nvmeq);
1333+ spin_unlock_irq(&nvmeq->q_lock);
12601334 }
12611335
12621336 static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
@@ -1875,13 +1949,61 @@ static int nvme_getgeo(struct block_device *bd, struct hd_geometry *geo) · 612 unmodified lines
18751949 return 0;
18761950 }
18771951
1952+static void nvme_config_discard(struct nvme_ns *ns)
1953+{
1954+ u32 logical_block_size = queue_logical_block_size(ns->queue);
1955+ ns->queue->limits.discard_zeroes_data = 0;
1956+ ns->queue->limits.discard_alignment = logical_block_size;
1957+ ns->queue->limits.discard_granularity = logical_block_size;
1958+ ns->queue->limits.max_discard_sectors = 0xffffffff;
1959+ queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, ns->queue);
1960+}
1961+
1962+static int nvme_noop_verify(struct blk_integrity_iter *iter)
1963+{
1964+ return 0;
1965+}
1966+
1967+static int nvme_noop_generate(struct blk_integrity_iter *iter)
1968+{
1969+ return 0;
1970+}
1971+
1972+struct blk_integrity nvme_meta_noop = {
1973+ .name = "NVME_META_NOOP",
1974+ .generate_fn = nvme_noop_generate,
1975+ .verify_fn = nvme_noop_verify,
1976+};
1977+
1978+static void nvme_init_integrity(struct nvme_ns *ns)
1979+{
1980+ struct blk_integrity integrity;
1981+
1982+ switch (ns->pi_type) {
1983+ case NVME_NS_DPS_PI_TYPE3:
1984+ integrity = t10_pi_type3_crc;
1985+ break;
1986+ case NVME_NS_DPS_PI_TYPE1:
1987+ case NVME_NS_DPS_PI_TYPE2:
1988+ integrity = t10_pi_type1_crc;
1989+ break;
1990+ default:
1991+ integrity = nvme_meta_noop;
1992+ break;
1993+ }
1994+ integrity.tuple_size = ns->ms;
1995+ blk_integrity_register(ns->disk, &integrity);
1996+ blk_queue_max_integrity_segments(ns->queue, 1);
1997+}
1998+
18781999 static int nvme_revalidate_disk(struct gendisk *disk)
18792000 {
18802001 struct nvme_ns *ns = disk->private_data;
18812002 struct nvme_dev *dev = ns->dev;
18822003 struct nvme_id_ns *id;
18832004 dma_addr_t dma_addr;
1884− int lbaf;
2005+ int lbaf, pi_type, old_ms;
2006+ unsigned short bs;
18852007
18862008 id = dma_alloc_coherent(&dev->pci_dev->dev, 4096, &dma_addr,
18872009 GFP_KERNEL);
@@ -1890,16 +2012,50 @@ static int nvme_revalidate_disk(struct gendisk *disk) · 2 unmodified lines
18902012 __func__);
18912013 return 0;
18922014 }
2015+ if (nvme_identify(dev, ns->ns_id, 0, dma_addr)) {
2016+ dev_warn(&dev->pci_dev->dev,
2017+ "identify failed ns:%d, setting capacity to 0\n",
2018+ ns->ns_id);
2019+ memset(id, 0, sizeof(*id));
2020+ }
18932021
1894− if (nvme_identify(dev, ns->ns_id, 0, dma_addr))
1895− goto free;
1896−
1897− lbaf = id->flbas & 0xf;
2022+ old_ms = ns->ms;
2023+ lbaf = id->flbas & NVME_NS_FLBAS_LBA_MASK;
18982024 ns->lba_shift = id->lbaf[lbaf].ds;
2025+ ns->ms = le16_to_cpu(id->lbaf[lbaf].ms);
2026+
2027+ /*
2028+ * If identify namespace failed, use default 512 byte block size so
2029+ * block layer can use before failing read/write for 0 capacity.
2030+ */
2031+ if (ns->lba_shift == 0)
2032+ ns->lba_shift = 9;
2033+ bs = 1 << ns->lba_shift;
2034+
2035+ /* XXX: PI implementation requires metadata equal t10 pi tuple size */
2036+ pi_type = ns->ms == sizeof(struct t10_pi_tuple) ?
2037+ id->dps & NVME_NS_DPS_PI_MASK : 0;
2038+
2039+ if (disk->integrity && (ns->pi_type != pi_type || ns->ms != old_ms ||
2040+ bs != queue_logical_block_size(disk->queue) ||
2041+ (ns->ms && id->flbas & NVME_NS_FLBAS_META_EXT)))
2042+ blk_integrity_unregister(disk);
2043+
2044+ ns->pi_type = pi_type;
2045+ blk_queue_logical_block_size(ns->queue, bs);
2046+
2047+ if (ns->ms && !disk->integrity && (disk->flags & GENHD_FL_UP) &&
2048+ !(id->flbas & NVME_NS_FLBAS_META_EXT))
2049+ nvme_init_integrity(ns);
2050+
2051+ if (id->ncap == 0 || (ns->ms && !disk->integrity))
2052+ set_capacity(disk, 0);
2053+ else
2054+ set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9));
2055+
2056+ if (dev->oncs & NVME_CTRL_ONCS_DSM)
2057+ nvme_config_discard(ns);
18992058
1900− blk_queue_logical_block_size(ns->queue, 1 << ns->lba_shift);
1901− set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9));
1902− free:
19032059 dma_free_coherent(&dev->pci_dev->dev, 4096, id, dma_addr);
19042060 return 0;
19052061 }
@@ -1923,8 +2079,7 @@ static int nvme_kthread(void *data) · 17 unmodified lines
19232079 spin_lock(&dev_list_lock);
19242080 list_for_each_entry_safe(dev, next, &dev_list, node) {
19252081 int i;
1926− if (readl(&dev->bar->csts) & NVME_CSTS_CFS &&
1927− dev->initialized) {
2082+ if (readl(&dev->bar->csts) & NVME_CSTS_CFS) {
19282083 if (work_busy(&dev->reset_work))
19292084 continue;
19302085 list_del_init(&dev->node);
@@ -1956,30 +2111,16 @@ static int nvme_kthread(void *data) · 25 unmodified lines
19562111 return 0;
19572112 }
19582113
1959−static void nvme_config_discard(struct nvme_ns *ns)
1960−{
1961− u32 logical_block_size = queue_logical_block_size(ns->queue);
1962− ns->queue->limits.discard_zeroes_data = 0;
1963− ns->queue->limits.discard_alignment = logical_block_size;
1964− ns->queue->limits.discard_granularity = logical_block_size;
1965− ns->queue->limits.max_discard_sectors = 0xffffffff;
1966− queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, ns->queue);
1967−}
1968−
1969−static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1970− struct nvme_id_ns *id, struct nvme_lba_range_type *rt)
2114+static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)
19712115 {
19722116 struct nvme_ns *ns;
19732117 struct gendisk *disk;
19742118 int node = dev_to_node(&dev->pci_dev->dev);
1975− int lbaf;
1976−
1977− if (rt->attributes & NVME_LBART_ATTRIB_HIDE)
1978− return NULL;
19792119
19802120 ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node);
19812121 if (!ns)
1982− return NULL;
2122+ return;
2123+
19832124 ns->queue = blk_mq_init_queue(&dev->tagset);
19842125 if (IS_ERR(ns->queue))
19852126 goto out_free_ns;
@@ -1995,9 +2136,9 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid, · 9 unmodified lines
19952136
19962137 ns->ns_id = nsid;
19972138 ns->disk = disk;
1998− lbaf = id->flbas & 0xf;
1999− ns->lba_shift = id->lbaf[lbaf].ds;
2000− ns->ms = le16_to_cpu(id->lbaf[lbaf].ms);
2139+ ns->lba_shift = 9; /* set to a default value for 512 until disk is validated */
2140+ list_add_tail(&ns->list, &dev->namespaces);
2141+
20012142 blk_queue_logical_block_size(ns->queue, 1 << ns->lba_shift);
20022143 if (dev->max_hw_sectors)
20032144 blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors);
@@ -2011,21 +2152,26 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid, · 7 unmodified lines
20112152 disk->fops = &nvme_fops;
20122153 disk->private_data = ns;
20132154 disk->queue = ns->queue;
2014− disk->driverfs_dev = &dev->pci_dev->dev;
2155+ disk->driverfs_dev = dev->device;
20152156 disk->flags = GENHD_FL_EXT_DEVT;
20162157 sprintf(disk->disk_name, "nvme%dn%d", dev->instance, nsid);
2017− set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9));
2018−
2019− if (dev->oncs & NVME_CTRL_ONCS_DSM)
2020− nvme_config_discard(ns);
2021−
2022− return ns;
20232158
2159+ /*
2160+ * Initialize capacity to 0 until we establish the namespace format and
2161+ * setup integrity extentions if necessary. The revalidate_disk after
2162+ * add_disk allows the driver to register with integrity if the format
2163+ * requires it.
2164+ */
2165+ set_capacity(disk, 0);
2166+ nvme_revalidate_disk(ns->disk);
2167+ add_disk(ns->disk);
2168+ if (ns->ms)
2169+ revalidate_disk(ns->disk);
2170+ return;
20242171 out_free_queue:
20252172 blk_cleanup_queue(ns->queue);
20262173 out_free_ns:
20272174 kfree(ns);
2028− return NULL;
20292175 }
20302176
20312177 static void nvme_create_io_queues(struct nvme_dev *dev)
@@ -2150,22 +2296,20 @@ static int nvme_dev_add(struct nvme_dev *dev) · 118 unmodified lines
21502296 struct pci_dev *pdev = dev->pci_dev;
21512297 int res;
21522298 unsigned nn, i;
2153− struct nvme_ns *ns;
21542299 struct nvme_id_ctrl *ctrl;
2155− struct nvme_id_ns *id_ns;
21562300 void *mem;
21572301 dma_addr_t dma_addr;
21582302 int shift = NVME_CAP_MPSMIN(readq(&dev->bar->cap)) + 12;
21592303
2160− mem = dma_alloc_coherent(&pdev->dev, 8192, &dma_addr, GFP_KERNEL);
2304+ mem = dma_alloc_coherent(&pdev->dev, 4096, &dma_addr, GFP_KERNEL);
21612305 if (!mem)
21622306 return -ENOMEM;
21632307
21642308 res = nvme_identify(dev, 0, 1, dma_addr);
21652309 if (res) {
21662310 dev_err(&pdev->dev, "Identify Controller failed (%d)\n", res);
2167− res = -EIO;
2168− goto out;
2311+ dma_free_coherent(&dev->pci_dev->dev, 4096, mem, dma_addr);
2312+ return -EIO;
21692313 }
21702314
21712315 ctrl = mem;
@@ -2191,6 +2335,7 @@ static int nvme_dev_add(struct nvme_dev *dev) · 19 unmodified lines
21912335 } else
21922336 dev->max_hw_sectors = max_hw_sectors;
21932337 }
2338+ dma_free_coherent(&dev->pci_dev->dev, 4096, mem, dma_addr);
21942339
21952340 dev->tagset.ops = &nvme_mq_ops;
21962341 dev->tagset.nr_hw_queues = dev->online_queues - 1;
@@ -2203,33 +2348,12 @@ static int nvme_dev_add(struct nvme_dev *dev) · 6 unmodified lines
22032348 dev->tagset.driver_data = dev;
22042349
22052350 if (blk_mq_alloc_tag_set(&dev->tagset))
2206− goto out;
2207−
2208− id_ns = mem;
2209− for (i = 1; i <= nn; i++) {
2210− res = nvme_identify(dev, i, 0, dma_addr);
2211− if (res)
2212− continue;
2213−
2214− if (id_ns->ncap == 0)
2215− continue;
2216−
2217− res = nvme_get_features(dev, NVME_FEAT_LBA_RANGE, i,
2218− dma_addr + 4096, NULL);
2219− if (res)
2220− memset(mem + 4096, 0, 4096);
2351+ return 0;
22212352
2222− ns = nvme_alloc_ns(dev, i, mem, mem + 4096);
2223− if (ns)
2224− list_add_tail(&ns->list, &dev->namespaces);
2225− }
2226− list_for_each_entry(ns, &dev->namespaces, list)
2227− add_disk(ns->disk);
2228− res = 0;
2353+ for (i = 1; i <= nn; i++)
2354+ nvme_alloc_ns(dev, i);
22292355
2230− out:
2231− dma_free_coherent(&dev->pci_dev->dev, 8192, mem, dma_addr);
2232− return res;
2356+ return 0;
22332357 }
22342358
22352359 static int nvme_dev_map(struct nvme_dev *dev)
@@ -2358,8 +2482,6 @@ static struct nvme_delq_ctx *nvme_get_dq(struct nvme_delq_ctx *dq) · 122 unmodified lines
23582482 static void nvme_del_queue_end(struct nvme_queue *nvmeq)
23592483 {
23602484 struct nvme_delq_ctx *dq = nvmeq->cmdinfo.ctx;
2361−
2362− nvme_clear_queue(nvmeq);
23632485 nvme_put_dq(dq);
23642486 }
23652487
@@ -2502,7 +2624,6 @@ static void nvme_dev_shutdown(struct nvme_dev *dev) · 136 unmodified lines
25022624 int i;
25032625 u32 csts = -1;
25042626
2505− dev->initialized = 0;
25062627 nvme_dev_list_remove(dev);
25072628
25082629 if (dev->bar) {
@@ -2513,7 +2634,6 @@ static void nvme_dev_shutdown(struct nvme_dev *dev) · 4 unmodified lines
25132634 for (i = dev->queue_count - 1; i >= 0; i--) {
25142635 struct nvme_queue *nvmeq = dev->queues[i];
25152636 nvme_suspend_queue(nvmeq);
2516− nvme_clear_queue(nvmeq);
25172637 }
25182638 } else {
25192639 nvme_disable_io_queues(dev);
@@ -2521,6 +2641,9 @@ static void nvme_dev_shutdown(struct nvme_dev *dev) · 1 unmodified line
25212641 nvme_disable_queue(dev, 0);
25222642 }
25232643 nvme_dev_unmap(dev);
2644+
2645+ for (i = dev->queue_count - 1; i >= 0; i--)
2646+ nvme_clear_queue(dev->queues[i]);
25242647 }
25252648
25262649 static void nvme_dev_remove(struct nvme_dev *dev)
@@ -2528,8 +2651,11 @@ static void nvme_dev_remove(struct nvme_dev *dev) · 1 unmodified line
25282651 struct nvme_ns *ns;
25292652
25302653 list_for_each_entry(ns, &dev->namespaces, list) {
2531− if (ns->disk->flags & GENHD_FL_UP)
2654+ if (ns->disk->flags & GENHD_FL_UP) {
2655+ if (ns->disk->integrity)
2656+ blk_integrity_unregister(ns->disk);
25322657 del_gendisk(ns->disk);
2658+ }
25332659 if (!blk_queue_dying(ns->queue)) {
25342660 blk_mq_abort_requeue_list(ns->queue);
25352661 blk_cleanup_queue(ns->queue);
@@ -2611,6 +2737,7 @@ static void nvme_free_dev(struct kref *kref) · 75 unmodified lines
26112737 struct nvme_dev *dev = container_of(kref, struct nvme_dev, kref);
26122738
26132739 pci_dev_put(dev->pci_dev);
2740+ put_device(dev->device);
26142741 nvme_free_namespaces(dev);
26152742 nvme_release_instance(dev);
26162743 blk_mq_free_tag_set(&dev->tagset);
@@ -2622,11 +2749,27 @@ static void nvme_free_dev(struct kref *kref) · 5 unmodified lines
26222749
26232750 static int nvme_dev_open(struct inode *inode, struct file *f)
26242751 {
2625− struct nvme_dev *dev = container_of(f->private_data, struct nvme_dev,
2626− miscdev);
2627− kref_get(&dev->kref);
2628− f->private_data = dev;
2629− return 0;
2752+ struct nvme_dev *dev;
2753+ int instance = iminor(inode);
2754+ int ret = -ENODEV;
2755+
2756+ spin_lock(&dev_list_lock);
2757+ list_for_each_entry(dev, &dev_list, node) {
2758+ if (dev->instance == instance) {
2759+ if (!dev->admin_q) {
2760+ ret = -EWOULDBLOCK;
2761+ break;
2762+ }
2763+ if (!kref_get_unless_zero(&dev->kref))
2764+ break;
2765+ f->private_data = dev;
2766+ ret = 0;
2767+ break;
2768+ }
2769+ }
2770+ spin_unlock(&dev_list_lock);
2771+
2772+ return ret;
26302773 }
26312774
26322775 static int nvme_dev_release(struct inode *inode, struct file *f)
@@ -2768,7 +2911,6 @@ static int nvme_dev_resume(struct nvme_dev *dev) · 135 unmodified lines
27682911 nvme_unfreeze_queues(dev);
27692912 nvme_set_irq_hints(dev);
27702913 }
2771− dev->initialized = 1;
27722914 return 0;
27732915 }
27742916
@@ -2799,6 +2941,7 @@ static void nvme_reset_workfn(struct work_struct *work) · 24 unmodified lines
27992941 dev->reset_workfn(work);
28002942 }
28012943
2944+static void nvme_async_probe(struct work_struct *work);
28022945 static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
28032946 {
28042947 int node, result = -ENOMEM;
@@ -2834,37 +2977,20 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) · 29 unmodified lines
28342977 goto release;
28352978
28362979 kref_init(&dev->kref);
2837− result = nvme_dev_start(dev);
2838− if (result)
2980+ dev->device = device_create(nvme_class, &pdev->dev,
2981+ MKDEV(nvme_char_major, dev->instance),
2982+ dev, "nvme%d", dev->instance);
2983+ if (IS_ERR(dev->device)) {
2984+ result = PTR_ERR(dev->device);
28392985 goto release_pools;
2986+ }
2987+ get_device(dev->device);
28402988
2841− if (dev->online_queues > 1)
2842− result = nvme_dev_add(dev);
2843− if (result)
2844− goto shutdown;
2845−
2846− scnprintf(dev->name, sizeof(dev->name), "nvme%d", dev->instance);
2847− dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2848− dev->miscdev.parent = &pdev->dev;
2849− dev->miscdev.name = dev->name;
2850− dev->miscdev.fops = &nvme_dev_fops;
2851− result = misc_register(&dev->miscdev);
2852− if (result)
2853− goto remove;
2854−
2855− nvme_set_irq_hints(dev);
2856−
2857− dev->initialized = 1;
2989+ INIT_WORK(&dev->probe_work, nvme_async_probe);
2990+ schedule_work(&dev->probe_work);
28582991 return 0;
28592992
2860− remove:
2861− nvme_dev_remove(dev);
2862− nvme_dev_remove_admin(dev);
2863− nvme_free_namespaces(dev);
2864− shutdown:
2865− nvme_dev_shutdown(dev);
28662993 release_pools:
2867− nvme_free_queues(dev, 0);
28682994 nvme_release_prp_pools(dev);
28692995 release:
28702996 nvme_release_instance(dev);
@@ -2877,6 +3003,29 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) · 6 unmodified lines
28773003 return result;
28783004 }
28793005
3006+static void nvme_async_probe(struct work_struct *work)
3007+{
3008+ struct nvme_dev *dev = container_of(work, struct nvme_dev, probe_work);
3009+ int result;
3010+
3011+ result = nvme_dev_start(dev);
3012+ if (result)
3013+ goto reset;
3014+
3015+ if (dev->online_queues > 1)
3016+ result = nvme_dev_add(dev);
3017+ if (result)
3018+ goto reset;
3019+
3020+ nvme_set_irq_hints(dev);
3021+ return;
3022+ reset:
3023+ if (!work_busy(&dev->reset_work)) {
3024+ dev->reset_workfn = nvme_reset_failed_dev;
3025+ queue_work(nvme_workq, &dev->reset_work);
3026+ }
3027+}
3028+
28803029 static void nvme_reset_notify(struct pci_dev *pdev, bool prepare)
28813030 {
28823031 struct nvme_dev *dev = pci_get_drvdata(pdev);
@@ -2902,11 +3051,12 @@ static void nvme_remove(struct pci_dev *pdev) · 19 unmodified lines
29023051 spin_unlock(&dev_list_lock);
29033052
29043053 pci_set_drvdata(pdev, NULL);
3054+ flush_work(&dev->probe_work);
29053055 flush_work(&dev->reset_work);
2906− misc_deregister(&dev->miscdev);
29073056 nvme_dev_shutdown(dev);
29083057 nvme_dev_remove(dev);
29093058 nvme_dev_remove_admin(dev);
3059+ device_destroy(nvme_class, MKDEV(nvme_char_major, dev->instance));
29103060 nvme_free_queues(dev, 0);
29113061 nvme_release_prp_pools(dev);
29123062 kref_put(&dev->kref, nvme_free_dev);
@@ -2990,11 +3140,26 @@ static int __init nvme_init(void) · 77 unmodified lines
29903140 else if (result > 0)
29913141 nvme_major = result;
29923142
3143+ result = __register_chrdev(nvme_char_major, 0, NVME_MINORS, "nvme",
3144+ &nvme_dev_fops);
3145+ if (result < 0)
3146+ goto unregister_blkdev;
3147+ else if (result > 0)
3148+ nvme_char_major = result;
3149+
3150+ nvme_class = class_create(THIS_MODULE, "nvme");
3151+ if (!nvme_class)
3152+ goto unregister_chrdev;
3153+
29933154 result = pci_register_driver(&nvme_driver);
29943155 if (result)
2995− goto unregister_blkdev;
3156+ goto destroy_class;
29963157 return 0;
29973158
3159+ destroy_class:
3160+ class_destroy(nvme_class);
3161+ unregister_chrdev:
3162+ __unregister_chrdev(nvme_char_major, 0, NVME_MINORS, "nvme");
29983163 unregister_blkdev:
29993164 unregister_blkdev(nvme_major, "nvme");
30003165 kill_workq:
@@ -3005,9 +3170,10 @@ static int __init nvme_init(void) · 4 unmodified lines
30053170 static void __exit nvme_exit(void)
30063171 {
30073172 pci_unregister_driver(&nvme_driver);
3008− unregister_hotcpu_notifier(&nvme_nb);
30093173 unregister_blkdev(nvme_major, "nvme");
30103174 destroy_workqueue(nvme_workq);
3175+ class_destroy(nvme_class);
3176+ __unregister_chrdev(nvme_char_major, 0, NVME_MINORS, "nvme");
30113177 BUG_ON(nvme_thread && !IS_ERR(nvme_thread));
30123178 _nvme_check_size();
30133179 }
drivers/block/nvme-scsi.c+54−42
@@ -779,10 +779,8 @@ static int nvme_trans_device_id_page(struct nvme_ns *ns, struct sg_io_hdr *hdr, · 778 unmodified lines
779779 struct nvme_dev *dev = ns->dev;
780780 dma_addr_t dma_addr;
781781 void *mem;
782− struct nvme_id_ctrl *id_ctrl;
783782 int res = SNTI_TRANSLATION_SUCCESS;
784783 int nvme_sc;
785− u8 ieee[4];
786784 int xfer_len;
787785 __be32 tmp_id = cpu_to_be32(ns->ns_id);
788786
@@ -793,46 +791,60 @@ static int nvme_trans_device_id_page(struct nvme_ns *ns, struct sg_io_hdr *hdr, · 4 unmodified lines
793791 goto out_dma;
794792 }
795793
796− /* nvme controller identify */
797− nvme_sc = nvme_identify(dev, 0, 1, dma_addr);
798− res = nvme_trans_status_code(hdr, nvme_sc);
799− if (res)
800− goto out_free;
801− if (nvme_sc) {
802− res = nvme_sc;
803− goto out_free;
804− }
805− id_ctrl = mem;
806−
807− /* Since SCSI tried to save 4 bits... [SPC-4(r34) Table 591] */
808− ieee[0] = id_ctrl->ieee[0] << 4;
809− ieee[1] = id_ctrl->ieee[0] >> 4 | id_ctrl->ieee[1] << 4;
810− ieee[2] = id_ctrl->ieee[1] >> 4 | id_ctrl->ieee[2] << 4;
811− ieee[3] = id_ctrl->ieee[2] >> 4;
812−
813− memset(inq_response, 0, STANDARD_INQUIRY_LENGTH);
794+ memset(inq_response, 0, alloc_len);
814795 inq_response[1] = INQ_DEVICE_IDENTIFICATION_PAGE; /* Page Code */
815− inq_response[3] = 20; /* Page Length */
816− /* Designation Descriptor start */
817− inq_response[4] = 0x01; /* Proto ID=0h | Code set=1h */
818− inq_response[5] = 0x03; /* PIV=0b | Asso=00b | Designator Type=3h */
819− inq_response[6] = 0x00; /* Rsvd */
820− inq_response[7] = 16; /* Designator Length */
821− /* Designator start */
822− inq_response[8] = 0x60 | ieee[3]; /* NAA=6h | IEEE ID MSB, High nibble*/
823− inq_response[9] = ieee[2]; /* IEEE ID */
824− inq_response[10] = ieee[1]; /* IEEE ID */
825− inq_response[11] = ieee[0]; /* IEEE ID| Vendor Specific ID... */
826− inq_response[12] = (dev->pci_dev->vendor & 0xFF00) >> 8;
827− inq_response[13] = (dev->pci_dev->vendor & 0x00FF);
828− inq_response[14] = dev->serial[0];
829− inq_response[15] = dev->serial[1];
830− inq_response[16] = dev->model[0];
831− inq_response[17] = dev->model[1];
832− memcpy(&inq_response[18], &tmp_id, sizeof(u32));
833− /* Last 2 bytes are zero */
796+ if (readl(&dev->bar->vs) >= NVME_VS(1, 1)) {
797+ struct nvme_id_ns *id_ns = mem;
798+ void *eui = id_ns->eui64;
799+ int len = sizeof(id_ns->eui64);
834800
835− xfer_len = min(alloc_len, STANDARD_INQUIRY_LENGTH);
801+ nvme_sc = nvme_identify(dev, ns->ns_id, 0, dma_addr);
802+ res = nvme_trans_status_code(hdr, nvme_sc);
803+ if (res)
804+ goto out_free;
805+ if (nvme_sc) {
806+ res = nvme_sc;
807+ goto out_free;
808+ }
809+
810+ if (readl(&dev->bar->vs) >= NVME_VS(1, 2)) {
811+ if (bitmap_empty(eui, len * 8)) {
812+ eui = id_ns->nguid;
813+ len = sizeof(id_ns->nguid);
814+ }
815+ }
816+ if (bitmap_empty(eui, len * 8))
817+ goto scsi_string;
818+
819+ inq_response[3] = 4 + len; /* Page Length */
820+ /* Designation Descriptor start */
821+ inq_response[4] = 0x01; /* Proto ID=0h | Code set=1h */
822+ inq_response[5] = 0x02; /* PIV=0b | Asso=00b | Designator Type=2h */
823+ inq_response[6] = 0x00; /* Rsvd */
824+ inq_response[7] = len; /* Designator Length */
825+ memcpy(&inq_response[8], eui, len);
826+ } else {
827+ scsi_string:
828+ if (alloc_len < 72) {
829+ res = nvme_trans_completion(hdr,
830+ SAM_STAT_CHECK_CONDITION,
831+ ILLEGAL_REQUEST, SCSI_ASC_INVALID_CDB,
832+ SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
833+ goto out_free;
834+ }
835+ inq_response[3] = 0x48; /* Page Length */
836+ /* Designation Descriptor start */
837+ inq_response[4] = 0x03; /* Proto ID=0h | Code set=3h */
838+ inq_response[5] = 0x08; /* PIV=0b | Asso=00b | Designator Type=8h */
839+ inq_response[6] = 0x00; /* Rsvd */
840+ inq_response[7] = 0x44; /* Designator Length */
841+
842+ sprintf(&inq_response[8], "%04x", dev->pci_dev->vendor);
843+ memcpy(&inq_response[12], dev->model, sizeof(dev->model));
844+ sprintf(&inq_response[52], "%04x", tmp_id);
845+ memcpy(&inq_response[56], dev->serial, sizeof(dev->serial));
846+ }
847+ xfer_len = alloc_len;
836848 res = nvme_trans_copy_to_user(hdr, inq_response, xfer_len);
837849
838850 out_free:
@@ -1600,7 +1612,7 @@ static inline void nvme_trans_modesel_get_bd_len(u8 *parm_list, u8 cdb10, · 761 unmodified lines
16001612 /* 10 Byte CDB */
16011613 *bd_len = (parm_list[MODE_SELECT_10_BD_OFFSET] << 8) +
16021614 parm_list[MODE_SELECT_10_BD_OFFSET + 1];
1603− *llbaa = parm_list[MODE_SELECT_10_LLBAA_OFFSET] &&
1615+ *llbaa = parm_list[MODE_SELECT_10_LLBAA_OFFSET] &
16041616 MODE_SELECT_10_LLBAA_MASK;
16051617 } else {
16061618 /* 6 Byte CDB */
@@ -2222,7 +2234,7 @@ static int nvme_trans_inquiry(struct nvme_ns *ns, struct sg_io_hdr *hdr, · 615 unmodified lines
22222234 page_code = GET_INQ_PAGE_CODE(cmd);
22232235 alloc_len = GET_INQ_ALLOC_LENGTH(cmd);
22242236
2225− inq_response = kmalloc(STANDARD_INQUIRY_LENGTH, GFP_KERNEL);
2237+ inq_response = kmalloc(alloc_len, GFP_KERNEL);
22262238 if (inq_response == NULL) {
22272239 res = -ENOMEM;
22282240 goto out_mem;
include/linux/nvme.h+4−5
@@ -17,7 +17,6 @@ · 16 unmodified lines
1717
1818 #include <uapi/linux/nvme.h>
1919 #include <linux/pci.h>
20−#include <linux/miscdevice.h>
2120 #include <linux/kref.h>
2221 #include <linux/blk-mq.h>
2322
@@ -62,8 +61,6 @@ enum { · 38 unmodified lines
6261 NVME_CSTS_SHST_MASK = 3 << 2,
6362 };
6463
65−#define NVME_VS(major, minor) (major << 16 | minor)
66−
6764 extern unsigned char nvme_io_timeout;
6865 #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
6966
@@ -91,9 +88,10 @@ struct nvme_dev { · 21 unmodified lines
9188 struct nvme_bar __iomem *bar;
9289 struct list_head namespaces;
9390 struct kref kref;
94− struct miscdevice miscdev;
91+ struct device *device;
9592 work_func_t reset_workfn;
9693 struct work_struct reset_work;
94+ struct work_struct probe_work;
9795 char name[12];
9896 char serial[20];
9997 char model[40];
@@ -105,7 +103,6 @@ struct nvme_dev { · 5 unmodified lines
105103 u16 abort_limit;
106104 u8 event_limit;
107105 u8 vwc;
108− u8 initialized;
109106 };
110107
111108 /*
@@ -121,6 +118,7 @@ struct nvme_ns { · 9 unmodified lines
121118 unsigned ns_id;
122119 int lba_shift;
123120 int ms;
121+ int pi_type;
124122 u64 mode_select_num_blocks;
125123 u32 mode_select_block_len;
126124 };
@@ -138,6 +136,7 @@ struct nvme_iod { · 11 unmodified lines
138136 int nents; /* Used in scatterlist */
139137 int length; /* Of data, in bytes */
140138 dma_addr_t first_dma;
139+ struct scatterlist meta_sg[1]; /* metadata requires single contiguous buffer */
141140 struct scatterlist sg[0];
142141 };
143142
include/uapi/linux/nvme.h+25−1
@@ -115,7 +115,13 @@ struct nvme_id_ns { · 114 unmodified lines
115115 __le16 nawun;
116116 __le16 nawupf;
117117 __le16 nacwu;
118− __u8 rsvd40[80];
118+ __le16 nabsn;
119+ __le16 nabo;
120+ __le16 nabspf;
121+ __u16 rsvd46;
122+ __le64 nvmcap[2];
123+ __u8 rsvd64[40];
124+ __u8 nguid[16];
119125 __u8 eui64[8];
120126 struct nvme_lbaf lbaf[16];
121127 __u8 rsvd192[192];
@@ -124,10 +130,22 @@ struct nvme_id_ns { · 2 unmodified lines
124130
125131 enum {
126132 NVME_NS_FEAT_THIN = 1 << 0,
133+ NVME_NS_FLBAS_LBA_MASK = 0xf,
134+ NVME_NS_FLBAS_META_EXT = 0x10,
127135 NVME_LBAF_RP_BEST = 0,
128136 NVME_LBAF_RP_BETTER = 1,
129137 NVME_LBAF_RP_GOOD = 2,
130138 NVME_LBAF_RP_DEGRADED = 3,
139+ NVME_NS_DPC_PI_LAST = 1 << 4,
140+ NVME_NS_DPC_PI_FIRST = 1 << 3,
141+ NVME_NS_DPC_PI_TYPE3 = 1 << 2,
142+ NVME_NS_DPC_PI_TYPE2 = 1 << 1,
143+ NVME_NS_DPC_PI_TYPE1 = 1 << 0,
144+ NVME_NS_DPS_PI_FIRST = 1 << 3,
145+ NVME_NS_DPS_PI_MASK = 0x7,
146+ NVME_NS_DPS_PI_TYPE1 = 1,
147+ NVME_NS_DPS_PI_TYPE2 = 2,
148+ NVME_NS_DPS_PI_TYPE3 = 3,
131149 };
132150
133151 struct nvme_smart_log {
@@ -261,6 +279,10 @@ enum { · 127 unmodified lines
261279 NVME_RW_DSM_LATENCY_LOW = 3 << 4,
262280 NVME_RW_DSM_SEQ_REQ = 1 << 6,
263281 NVME_RW_DSM_COMPRESSED = 1 << 7,
282+ NVME_RW_PRINFO_PRCHK_REF = 1 << 10,
283+ NVME_RW_PRINFO_PRCHK_APP = 1 << 11,
284+ NVME_RW_PRINFO_PRCHK_GUARD = 1 << 12,
285+ NVME_RW_PRINFO_PRACT = 1 << 13,
264286 };
265287
266288 struct nvme_dsm_cmd {
@@ -549,6 +571,8 @@ struct nvme_passthru_cmd { · 282 unmodified lines
549571 __u32 result;
550572 };
551573
574+#define NVME_VS(major, minor) (((major) << 16) | ((minor) << 8))
575+
552576 #define nvme_admin_cmd nvme_passthru_cmd
553577
554578 #define NVME_IOCTL_ID _IO('N', 0x40)