nvme: implement NS Optimal IO Boundary from 1.3 Spec
authorScott Bauer <scott.bauer@intel.com>
Thu, 15 Jun 2017 16:44:30 +0000 (10:44 -0600)
committerChristoph Hellwig <hch@lst.de>
Fri, 16 Jun 2017 06:25:54 +0000 (08:25 +0200)
The NVMe 1.3 spec introduces Namespace Optimal IO Boundaries (NOIOB),
which standardizes the stripe mechanism we currently have quirks for.
This patch implements the necessary logic to handle this new feature.

Signed-off-by: Scott Bauer <scott.bauer@intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
include/linux/nvme.h

index 4ff5114f467d7f5663782645e73cd1e2e6901e1b..0ddd6b9af7fc5afada061e5ca8f79191a778a99f 100644 (file)
@@ -1080,6 +1080,12 @@ static void nvme_init_integrity(struct nvme_ns *ns)
 }
 #endif /* CONFIG_BLK_DEV_INTEGRITY */
 
+static void nvme_set_chunk_size(struct nvme_ns *ns)
+{
+       u32 chunk_size = (((u32)ns->noiob) << (ns->lba_shift - 9));
+       blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size));
+}
+
 static void nvme_config_discard(struct nvme_ns *ns)
 {
        struct nvme_ctrl *ctrl = ns->ctrl;
@@ -1139,12 +1145,15 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
        if (ns->lba_shift == 0)
                ns->lba_shift = 9;
        bs = 1 << ns->lba_shift;
+       ns->noiob = le16_to_cpu(id->noiob);
 
        blk_mq_freeze_queue(disk->queue);
 
        if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)
                nvme_prep_integrity(disk, id, bs);
        blk_queue_logical_block_size(ns->queue, bs);
+       if (ns->noiob)
+               nvme_set_chunk_size(ns);
        if (ns->ms && !blk_get_integrity(disk) && !ns->ext)
                nvme_init_integrity(ns);
        if (ns->ms && !(ns->ms == 8 && ns->pi_type) && !blk_get_integrity(disk))
index f27c58b860f41037b6ef28157a228aa3c6b1a2e6..ec8c7363934dd03ba508beefe074f216879ebfc7 100644 (file)
@@ -202,6 +202,7 @@ struct nvme_ns {
        bool ext;
        u8 pi_type;
        unsigned long flags;
+       u16 noiob;
 
 #define NVME_NS_REMOVING 0
 #define NVME_NS_DEAD     1
index 6d476f242ee60f5c3a6bbd3e6c52363e06795d6f..291587a0743f88673c0b021c9256f8199d058776 100644 (file)
@@ -282,7 +282,7 @@ struct nvme_id_ns {
        __le16                  nabsn;
        __le16                  nabo;
        __le16                  nabspf;
-       __u16                   rsvd46;
+       __le16                  noiob;
        __u8                    nvmcap[16];
        __u8                    rsvd64[40];
        __u8                    nguid[16];