|
@@ -925,6 +925,29 @@ static int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INTEGRITY
|
|
#ifdef CONFIG_BLK_DEV_INTEGRITY
|
|
|
|
+static void nvme_prep_integrity(struct gendisk *disk, struct nvme_id_ns *id,
|
|
|
|
+ u16 bs)
|
|
|
|
+{
|
|
|
|
+ struct nvme_ns *ns = disk->private_data;
|
|
|
|
+ u16 old_ms = ns->ms;
|
|
|
|
+ u8 pi_type = 0;
|
|
|
|
+
|
|
|
|
+ ns->ms = le16_to_cpu(id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ms);
|
|
|
|
+ ns->ext = ns->ms && (id->flbas & NVME_NS_FLBAS_META_EXT);
|
|
|
|
+
|
|
|
|
+ /* PI implementation requires metadata equal t10 pi tuple size */
|
|
|
|
+ if (ns->ms == sizeof(struct t10_pi_tuple))
|
|
|
|
+ pi_type = id->dps & NVME_NS_DPS_PI_MASK;
|
|
|
|
+
|
|
|
|
+ if (blk_get_integrity(disk) &&
|
|
|
|
+ (ns->pi_type != pi_type || ns->ms != old_ms ||
|
|
|
|
+ bs != queue_logical_block_size(disk->queue) ||
|
|
|
|
+ (ns->ms && ns->ext)))
|
|
|
|
+ blk_integrity_unregister(disk);
|
|
|
|
+
|
|
|
|
+ ns->pi_type = pi_type;
|
|
|
|
+}
|
|
|
|
+
|
|
static void nvme_init_integrity(struct nvme_ns *ns)
|
|
static void nvme_init_integrity(struct nvme_ns *ns)
|
|
{
|
|
{
|
|
struct blk_integrity integrity;
|
|
struct blk_integrity integrity;
|
|
@@ -951,6 +974,10 @@ static void nvme_init_integrity(struct nvme_ns *ns)
|
|
blk_queue_max_integrity_segments(ns->queue, 1);
|
|
blk_queue_max_integrity_segments(ns->queue, 1);
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
|
|
+static void nvme_prep_integrity(struct gendisk *disk, struct nvme_id_ns *id,
|
|
|
|
+ u16 bs)
|
|
|
|
+{
|
|
|
|
+}
|
|
static void nvme_init_integrity(struct nvme_ns *ns)
|
|
static void nvme_init_integrity(struct nvme_ns *ns)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
@@ -997,37 +1024,22 @@ static int nvme_revalidate_ns(struct nvme_ns *ns, struct nvme_id_ns **id)
|
|
static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
|
|
static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
|
|
{
|
|
{
|
|
struct nvme_ns *ns = disk->private_data;
|
|
struct nvme_ns *ns = disk->private_data;
|
|
- u8 lbaf, pi_type;
|
|
|
|
- u16 old_ms;
|
|
|
|
- unsigned short bs;
|
|
|
|
-
|
|
|
|
- old_ms = ns->ms;
|
|
|
|
- lbaf = id->flbas & NVME_NS_FLBAS_LBA_MASK;
|
|
|
|
- ns->lba_shift = id->lbaf[lbaf].ds;
|
|
|
|
- ns->ms = le16_to_cpu(id->lbaf[lbaf].ms);
|
|
|
|
- ns->ext = ns->ms && (id->flbas & NVME_NS_FLBAS_META_EXT);
|
|
|
|
|
|
+ u16 bs;
|
|
|
|
|
|
/*
|
|
/*
|
|
* If identify namespace failed, use default 512 byte block size so
|
|
* If identify namespace failed, use default 512 byte block size so
|
|
* block layer can use before failing read/write for 0 capacity.
|
|
* block layer can use before failing read/write for 0 capacity.
|
|
*/
|
|
*/
|
|
|
|
+ ns->lba_shift = id->lbaf[id->flbas & NVME_NS_FLBAS_LBA_MASK].ds;
|
|
if (ns->lba_shift == 0)
|
|
if (ns->lba_shift == 0)
|
|
ns->lba_shift = 9;
|
|
ns->lba_shift = 9;
|
|
bs = 1 << ns->lba_shift;
|
|
bs = 1 << ns->lba_shift;
|
|
- /* XXX: PI implementation requires metadata equal t10 pi tuple size */
|
|
|
|
- pi_type = ns->ms == sizeof(struct t10_pi_tuple) ?
|
|
|
|
- id->dps & NVME_NS_DPS_PI_MASK : 0;
|
|
|
|
|
|
|
|
blk_mq_freeze_queue(disk->queue);
|
|
blk_mq_freeze_queue(disk->queue);
|
|
- if (blk_get_integrity(disk) && (ns->pi_type != pi_type ||
|
|
|
|
- ns->ms != old_ms ||
|
|
|
|
- bs != queue_logical_block_size(disk->queue) ||
|
|
|
|
- (ns->ms && ns->ext)))
|
|
|
|
- blk_integrity_unregister(disk);
|
|
|
|
|
|
|
|
- ns->pi_type = pi_type;
|
|
|
|
|
|
+ if (ns->ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)
|
|
|
|
+ nvme_prep_integrity(disk, id, bs);
|
|
blk_queue_logical_block_size(ns->queue, bs);
|
|
blk_queue_logical_block_size(ns->queue, bs);
|
|
-
|
|
|
|
if (ns->ms && !blk_get_integrity(disk) && !ns->ext)
|
|
if (ns->ms && !blk_get_integrity(disk) && !ns->ext)
|
|
nvme_init_integrity(ns);
|
|
nvme_init_integrity(ns);
|
|
if (ns->ms && !(ns->ms == 8 && ns->pi_type) && !blk_get_integrity(disk))
|
|
if (ns->ms && !(ns->ms == 8 && ns->pi_type) && !blk_get_integrity(disk))
|