@@ -838,6 +838,19 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
return BLK_STS_OK;
}
+static inline blk_status_t nvme_setup_verify(struct nvme_ns *ns,
+ struct request *req, struct nvme_command *cmnd)
+{
+ cmnd->verify.opcode = nvme_cmd_verify;
+ cmnd->verify.nsid = cpu_to_le32(ns->head->ns_id);
+ cmnd->verify.slba =
+ cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
+ cmnd->verify.length =
+ cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
+ cmnd->verify.control = 0;
+ return BLK_STS_OK;
+}
+
static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
struct request *req, struct nvme_command *cmnd,
enum nvme_opcode op)
@@ -943,6 +956,9 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
case REQ_OP_WRITE_ZEROES:
ret = nvme_setup_write_zeroes(ns, req, cmd);
break;
+ case REQ_OP_VERIFY:
+ ret = nvme_setup_verify(ns, req, cmd);
+ break;
case REQ_OP_DISCARD:
ret = nvme_setup_discard(ns, req, cmd);
break;
@@ -1672,6 +1688,17 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
blk_queue_max_write_zeroes_sectors(queue, UINT_MAX);
}
+static void nvme_config_verify(struct gendisk *disk, struct nvme_ns *ns)
+{
+ unsigned int sects = ns->ctrl->max_verify_sectors;
+
+ if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_VERIFY))
+ return;
+
+ /* in case controller supports verify but vsl is 0 just use UINT_MAX */
+ blk_queue_max_verify_sectors(disk->queue, sects ? sects : UINT_MAX);
+}
+
static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
{
return uuid_equal(&a->uuid, &b->uuid) &&
@@ -1871,6 +1898,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
set_capacity_and_notify(disk, capacity);
nvme_config_discard(disk, ns);
+ nvme_config_verify(disk, ns);
blk_queue_max_write_zeroes_sectors(disk->queue,
ns->ctrl->max_zeroes_sectors);
}
@@ -2971,6 +2999,9 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
if (id->wzsl)
ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl);
+ if (id->vsl)
+ ctrl->max_verify_sectors = nvme_mps_to_sectors(ctrl, id->vsl);
+
free_data:
kfree(id);
return ret;
@@ -279,6 +279,7 @@ struct nvme_ctrl {
u32 max_discard_sectors;
u32 max_discard_segments;
u32 max_zeroes_sectors;
+ u32 max_verify_sectors;
#ifdef CONFIG_BLK_DEV_ZONED
u32 max_zone_append;
#endif
@@ -363,6 +363,7 @@ enum {
NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3,
NVME_CTRL_ONCS_RESERVATIONS = 1 << 5,
NVME_CTRL_ONCS_TIMESTAMP = 1 << 6,
+ NVME_CTRL_ONCS_VERIFY = 1 << 7,
NVME_CTRL_VWC_PRESENT = 1 << 0,
NVME_CTRL_OACS_SEC_SUPP = 1 << 0,
NVME_CTRL_OACS_NS_MNGT_SUPP = 1 << 3,
@@ -1003,6 +1004,23 @@ struct nvme_write_zeroes_cmd {
__le16 appmask;
};
+struct nvme_verify_cmd {
+ __u8 opcode;
+ __u8 flags;
+ __u16 command_id;
+ __le32 nsid;
+ __u64 rsvd2;
+ __le64 metadata;
+ union nvme_data_ptr dptr;
+ __le64 slba;
+ __le16 length;
+ __le16 control;
+ __le32 rsvd3;
+ __le32 reftag;
+ __le16 eapptag;
+ __le16 eappmask;
+};
+
enum nvme_zone_mgmt_action {
NVME_ZONE_CLOSE = 0x1,
NVME_ZONE_FINISH = 0x2,
@@ -1541,6 +1559,7 @@ struct nvme_command {
struct nvme_format_cmd format;
struct nvme_dsm_cmd dsm;
struct nvme_write_zeroes_cmd write_zeroes;
+ struct nvme_verify_cmd verify;
struct nvme_zone_mgmt_send_cmd zms;
struct nvme_zone_mgmt_recv_cmd zmr;
struct nvme_abort_cmd abort;
Allow verify operations (REQ_OP_VERIFY) on the block device, if the device supports optional command bit set for verify. Add support to setup verify command. Set maximum possible verify sectors in one verify command according to maximum hardware sectors supported by the controller. Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com> --- drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 1 + include/linux/nvme.h | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+)