1 // SPDX-License-Identifier: GPL-2.0
3 * nvme structure declarations and helper functions for the
8 #include "../crc/crc-t10dif.h"
9 #include "../crc/crc64.h"
11 static inline __u64 get_slba(struct nvme_data *data, struct io_u *io_u)
14 return io_u->offset / data->lba_ext;
16 return io_u->offset >> data->lba_shift;
19 static inline __u32 get_nlb(struct nvme_data *data, struct io_u *io_u)
22 return io_u->xfer_buflen / data->lba_ext - 1;
24 return (io_u->xfer_buflen >> data->lba_shift) - 1;
27 static void fio_nvme_generate_pi_16b_guard(struct nvme_data *data,
29 struct nvme_cmd_ext_io_opts *opts)
31 struct nvme_pi_data *pi_data = io_u->engine_data;
32 struct nvme_16b_guard_pif *pi;
33 unsigned char *buf = io_u->xfer_buf;
34 unsigned char *md_buf = io_u->mmap_data;
35 __u64 slba = get_slba(data, io_u);
36 __u32 nlb = get_nlb(data, io_u) + 1;
42 pi_data->interval = data->lba_ext - data->ms;
44 pi_data->interval = 0;
47 pi_data->interval = data->lba_ext - sizeof(struct nvme_16b_guard_pif);
49 pi_data->interval = data->ms - sizeof(struct nvme_16b_guard_pif);
52 if (io_u->ddir != DDIR_WRITE)
55 while (lba_num < nlb) {
57 pi = (struct nvme_16b_guard_pif *)(buf + pi_data->interval);
59 pi = (struct nvme_16b_guard_pif *)(md_buf + pi_data->interval);
61 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_GUARD) {
63 guard = fio_crc_t10dif(0, buf, pi_data->interval);
65 guard = fio_crc_t10dif(0, buf, data->lba_size);
66 guard = fio_crc_t10dif(guard, md_buf, pi_data->interval);
68 pi->guard = cpu_to_be16(guard);
71 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_APP)
72 pi->apptag = cpu_to_be16(pi_data->apptag);
74 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_REF) {
75 switch (data->pi_type) {
76 case NVME_NS_DPS_PI_TYPE1:
77 case NVME_NS_DPS_PI_TYPE2:
78 pi->srtag = cpu_to_be32((__u32)slba + lba_num);
80 case NVME_NS_DPS_PI_TYPE3:
87 buf += data->lba_size;
94 static int fio_nvme_verify_pi_16b_guard(struct nvme_data *data,
97 struct nvme_pi_data *pi_data = io_u->engine_data;
98 struct nvme_16b_guard_pif *pi;
99 struct fio_file *f = io_u->file;
100 unsigned char *buf = io_u->xfer_buf;
101 unsigned char *md_buf = io_u->mmap_data;
102 __u64 slba = get_slba(data, io_u);
103 __u32 nlb = get_nlb(data, io_u) + 1;
105 __u16 unmask_app, unmask_app_exp, guard = 0;
107 while (lba_num < nlb) {
109 pi = (struct nvme_16b_guard_pif *)(buf + pi_data->interval);
111 pi = (struct nvme_16b_guard_pif *)(md_buf + pi_data->interval);
113 if (data->pi_type == NVME_NS_DPS_PI_TYPE3) {
114 if (pi->apptag == NVME_PI_APP_DISABLE &&
115 pi->srtag == NVME_PI_REF_DISABLE)
117 } else if (data->pi_type == NVME_NS_DPS_PI_TYPE1 ||
118 data->pi_type == NVME_NS_DPS_PI_TYPE2) {
119 if (pi->apptag == NVME_PI_APP_DISABLE)
123 if (pi_data->io_flags & NVME_IO_PRINFO_PRCHK_GUARD) {
125 guard = fio_crc_t10dif(0, buf, pi_data->interval);
127 guard = fio_crc_t10dif(0, buf, data->lba_size);
128 guard = fio_crc_t10dif(guard, md_buf, pi_data->interval);
130 if (be16_to_cpu(pi->guard) != guard) {
131 log_err("%s: Guard compare error: LBA: %llu Expected=%x, Actual=%x\n",
132 f->file_name, (unsigned long long)slba,
133 guard, be16_to_cpu(pi->guard));
138 if (pi_data->io_flags & NVME_IO_PRINFO_PRCHK_APP) {
139 unmask_app = be16_to_cpu(pi->apptag) & pi_data->apptag_mask;
140 unmask_app_exp = pi_data->apptag & pi_data->apptag_mask;
141 if (unmask_app != unmask_app_exp) {
142 log_err("%s: APPTAG compare error: LBA: %llu Expected=%x, Actual=%x\n",
143 f->file_name, (unsigned long long)slba,
144 unmask_app_exp, unmask_app);
149 if (pi_data->io_flags & NVME_IO_PRINFO_PRCHK_REF) {
150 switch (data->pi_type) {
151 case NVME_NS_DPS_PI_TYPE1:
152 case NVME_NS_DPS_PI_TYPE2:
153 if (be32_to_cpu(pi->srtag) !=
154 ((__u32)slba + lba_num)) {
155 log_err("%s: REFTAG compare error: LBA: %llu Expected=%x, Actual=%x\n",
156 f->file_name, (unsigned long long)slba,
157 (__u32)slba + lba_num,
158 be32_to_cpu(pi->srtag));
162 case NVME_NS_DPS_PI_TYPE3:
168 buf += data->lba_ext;
170 buf += data->lba_size;
179 static void fio_nvme_generate_pi_64b_guard(struct nvme_data *data,
181 struct nvme_cmd_ext_io_opts *opts)
183 struct nvme_pi_data *pi_data = io_u->engine_data;
184 struct nvme_64b_guard_pif *pi;
185 unsigned char *buf = io_u->xfer_buf;
186 unsigned char *md_buf = io_u->mmap_data;
188 __u64 slba = get_slba(data, io_u);
189 __u32 nlb = get_nlb(data, io_u) + 1;
194 pi_data->interval = data->lba_ext - data->ms;
196 pi_data->interval = 0;
199 pi_data->interval = data->lba_ext - sizeof(struct nvme_64b_guard_pif);
201 pi_data->interval = data->ms - sizeof(struct nvme_64b_guard_pif);
204 if (io_u->ddir != DDIR_WRITE)
207 while (lba_num < nlb) {
209 pi = (struct nvme_64b_guard_pif *)(buf + pi_data->interval);
211 pi = (struct nvme_64b_guard_pif *)(md_buf + pi_data->interval);
213 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_GUARD) {
215 guard = fio_crc64_nvme(0, buf, pi_data->interval);
217 guard = fio_crc64_nvme(0, buf, data->lba_size);
218 guard = fio_crc64_nvme(guard, md_buf, pi_data->interval);
220 pi->guard = cpu_to_be64(guard);
223 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_APP)
224 pi->apptag = cpu_to_be16(pi_data->apptag);
226 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_REF) {
227 switch (data->pi_type) {
228 case NVME_NS_DPS_PI_TYPE1:
229 case NVME_NS_DPS_PI_TYPE2:
230 put_unaligned_be48(slba + lba_num, pi->srtag);
232 case NVME_NS_DPS_PI_TYPE3:
237 buf += data->lba_ext;
239 buf += data->lba_size;
246 static int fio_nvme_verify_pi_64b_guard(struct nvme_data *data,
249 struct nvme_pi_data *pi_data = io_u->engine_data;
250 struct nvme_64b_guard_pif *pi;
251 struct fio_file *f = io_u->file;
252 unsigned char *buf = io_u->xfer_buf;
253 unsigned char *md_buf = io_u->mmap_data;
254 __u64 slba = get_slba(data, io_u);
255 __u64 ref, ref_exp, guard = 0;
256 __u32 nlb = get_nlb(data, io_u) + 1;
258 __u16 unmask_app, unmask_app_exp;
260 while (lba_num < nlb) {
262 pi = (struct nvme_64b_guard_pif *)(buf + pi_data->interval);
264 pi = (struct nvme_64b_guard_pif *)(md_buf + pi_data->interval);
266 if (data->pi_type == NVME_NS_DPS_PI_TYPE3) {
267 if (pi->apptag == NVME_PI_APP_DISABLE &&
268 fio_nvme_pi_ref_escape(pi->srtag))
270 } else if (data->pi_type == NVME_NS_DPS_PI_TYPE1 ||
271 data->pi_type == NVME_NS_DPS_PI_TYPE2) {
272 if (pi->apptag == NVME_PI_APP_DISABLE)
276 if (pi_data->io_flags & NVME_IO_PRINFO_PRCHK_GUARD) {
278 guard = fio_crc64_nvme(0, buf, pi_data->interval);
280 guard = fio_crc64_nvme(0, buf, data->lba_size);
281 guard = fio_crc64_nvme(guard, md_buf, pi_data->interval);
283 if (be64_to_cpu((uint64_t)pi->guard) != guard) {
284 log_err("%s: Guard compare error: LBA: %llu Expected=%llx, Actual=%llx\n",
285 f->file_name, (unsigned long long)slba,
286 guard, be64_to_cpu((uint64_t)pi->guard));
291 if (pi_data->io_flags & NVME_IO_PRINFO_PRCHK_APP) {
292 unmask_app = be16_to_cpu(pi->apptag) & pi_data->apptag_mask;
293 unmask_app_exp = pi_data->apptag & pi_data->apptag_mask;
294 if (unmask_app != unmask_app_exp) {
295 log_err("%s: APPTAG compare error: LBA: %llu Expected=%x, Actual=%x\n",
296 f->file_name, (unsigned long long)slba,
297 unmask_app_exp, unmask_app);
302 if (pi_data->io_flags & NVME_IO_PRINFO_PRCHK_REF) {
303 switch (data->pi_type) {
304 case NVME_NS_DPS_PI_TYPE1:
305 case NVME_NS_DPS_PI_TYPE2:
306 ref = get_unaligned_be48(pi->srtag);
307 ref_exp = (slba + lba_num) & ((1ULL << 48) - 1);
308 if (ref != ref_exp) {
309 log_err("%s: REFTAG compare error: LBA: %llu Expected=%llx, Actual=%llx\n",
310 f->file_name, (unsigned long long)slba,
315 case NVME_NS_DPS_PI_TYPE3:
321 buf += data->lba_ext;
323 buf += data->lba_size;
331 void fio_nvme_uring_cmd_trim_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
332 struct nvme_dsm_range *dsm)
334 struct nvme_data *data = FILE_ENG_DATA(io_u->file);
336 cmd->opcode = nvme_cmd_dsm;
337 cmd->nsid = data->nsid;
339 cmd->cdw11 = NVME_ATTRIBUTE_DEALLOCATE;
340 cmd->addr = (__u64) (uintptr_t) dsm;
341 cmd->data_len = sizeof(*dsm);
343 dsm->slba = get_slba(data, io_u);
344 /* nlb is a 1-based value for deallocate */
345 dsm->nlb = get_nlb(data, io_u) + 1;
348 int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
349 struct iovec *iov, struct nvme_dsm_range *dsm)
351 struct nvme_data *data = FILE_ENG_DATA(io_u->file);
355 memset(cmd, 0, sizeof(struct nvme_uring_cmd));
357 switch (io_u->ddir) {
359 cmd->opcode = nvme_cmd_read;
362 cmd->opcode = nvme_cmd_write;
365 fio_nvme_uring_cmd_trim_prep(cmd, io_u, dsm);
371 slba = get_slba(data, io_u);
372 nlb = get_nlb(data, io_u);
374 /* cdw10 and cdw11 represent starting lba */
375 cmd->cdw10 = slba & 0xffffffff;
376 cmd->cdw11 = slba >> 32;
377 /* cdw12 represent number of lba's for read/write */
378 cmd->cdw12 = nlb | (io_u->dtype << 20);
379 cmd->cdw13 = io_u->dspec << 16;
381 iov->iov_base = io_u->xfer_buf;
382 iov->iov_len = io_u->xfer_buflen;
383 cmd->addr = (__u64)(uintptr_t)iov;
386 cmd->addr = (__u64)(uintptr_t)io_u->xfer_buf;
387 cmd->data_len = io_u->xfer_buflen;
389 if (data->lba_shift && data->ms) {
390 cmd->metadata = (__u64)(uintptr_t)io_u->mmap_data;
391 cmd->metadata_len = (nlb + 1) * data->ms;
393 cmd->nsid = data->nsid;
397 void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,
398 struct nvme_cmd_ext_io_opts *opts)
400 struct nvme_data *data = FILE_ENG_DATA(io_u->file);
403 slba = get_slba(data, io_u);
404 cmd->cdw12 |= opts->io_flags;
406 if (data->pi_type && !(opts->io_flags & NVME_IO_PRINFO_PRACT)) {
407 if (data->guard_type == NVME_NVM_NS_16B_GUARD)
408 fio_nvme_generate_pi_16b_guard(data, io_u, opts);
409 else if (data->guard_type == NVME_NVM_NS_64B_GUARD)
410 fio_nvme_generate_pi_64b_guard(data, io_u, opts);
413 switch (data->pi_type) {
414 case NVME_NS_DPS_PI_TYPE1:
415 case NVME_NS_DPS_PI_TYPE2:
416 switch (data->guard_type) {
417 case NVME_NVM_NS_16B_GUARD:
418 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_REF)
419 cmd->cdw14 = (__u32)slba;
421 case NVME_NVM_NS_64B_GUARD:
422 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_REF) {
423 cmd->cdw14 = (__u32)slba;
424 cmd->cdw3 = ((slba >> 32) & 0xffff);
430 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_APP)
431 cmd->cdw15 = (opts->apptag_mask << 16 | opts->apptag);
433 case NVME_NS_DPS_PI_TYPE3:
434 if (opts->io_flags & NVME_IO_PRINFO_PRCHK_APP)
435 cmd->cdw15 = (opts->apptag_mask << 16 | opts->apptag);
437 case NVME_NS_DPS_PI_NONE:
442 int fio_nvme_pi_verify(struct nvme_data *data, struct io_u *io_u)
446 switch (data->guard_type) {
447 case NVME_NVM_NS_16B_GUARD:
448 ret = fio_nvme_verify_pi_16b_guard(data, io_u);
450 case NVME_NVM_NS_64B_GUARD:
451 ret = fio_nvme_verify_pi_64b_guard(data, io_u);
460 static int nvme_identify(int fd, __u32 nsid, enum nvme_identify_cns cns,
461 enum nvme_csi csi, void *data)
463 struct nvme_passthru_cmd cmd = {
464 .opcode = nvme_admin_identify,
466 .addr = (__u64)(uintptr_t)data,
467 .data_len = NVME_IDENTIFY_DATA_SIZE,
469 .cdw11 = csi << NVME_IDENTIFY_CSI_SHIFT,
470 .timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT,
473 return ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
476 int fio_nvme_get_info(struct fio_file *f, __u64 *nlba, __u32 pi_act,
477 struct nvme_data *data)
479 struct nvme_id_ns ns;
480 struct nvme_id_ctrl ctrl;
481 struct nvme_nvm_id_ns nvm_ns;
484 __u32 format_idx, elbaf;
486 if (f->filetype != FIO_TYPE_CHAR) {
487 log_err("ioengine io_uring_cmd only works with nvme ns "
488 "generic char devices (/dev/ngXnY)\n");
492 fd = open(f->file_name, O_RDONLY);
496 namespace_id = ioctl(fd, NVME_IOCTL_ID);
497 if (namespace_id < 0) {
499 log_err("%s: failed to fetch namespace-id\n", f->file_name);
503 err = nvme_identify(fd, 0, NVME_IDENTIFY_CNS_CTRL, NVME_CSI_NVM, &ctrl);
505 log_err("%s: failed to fetch identify ctrl\n", f->file_name);
510 * Identify namespace to get namespace-id, namespace size in LBA's
513 err = nvme_identify(fd, namespace_id, NVME_IDENTIFY_CNS_NS,
516 log_err("%s: failed to fetch identify namespace\n",
521 data->nsid = namespace_id;
524 * 16 or 64 as maximum number of supported LBA formats.
525 * From flbas bit 0-3 indicates lsb and bit 5-6 indicates msb
526 * of the format index used to format the namespace.
529 format_idx = ns.flbas & 0xf;
531 format_idx = (ns.flbas & 0xf) + (((ns.flbas >> 5) & 0x3) << 4);
533 data->lba_size = 1 << ns.lbaf[format_idx].ds;
534 data->ms = le16_to_cpu(ns.lbaf[format_idx].ms);
536 /* Check for end to end data protection support */
537 if (data->ms && (ns.dps & NVME_NS_DPS_PI_MASK))
538 data->pi_type = (ns.dps & NVME_NS_DPS_PI_MASK);
543 if (ctrl.ctratt & NVME_CTRL_CTRATT_ELBAS) {
544 err = nvme_identify(fd, namespace_id, NVME_IDENTIFY_CNS_CSI_NS,
545 NVME_CSI_NVM, &nvm_ns);
547 log_err("%s: failed to fetch identify nvm namespace\n",
552 elbaf = le32_to_cpu(nvm_ns.elbaf[format_idx]);
554 /* Currently we don't support storage tags */
555 if (elbaf & NVME_ID_NS_NVM_STS_MASK) {
556 log_err("%s: Storage tag not supported\n",
562 data->guard_type = (elbaf >> NVME_ID_NS_NVM_GUARD_SHIFT) &
563 NVME_ID_NS_NVM_GUARD_MASK;
565 /* No 32 bit guard, as storage tag is mandatory for it */
566 switch (data->guard_type) {
567 case NVME_NVM_NS_16B_GUARD:
568 data->pi_size = sizeof(struct nvme_16b_guard_pif);
570 case NVME_NVM_NS_64B_GUARD:
571 data->pi_size = sizeof(struct nvme_64b_guard_pif);
577 data->guard_type = NVME_NVM_NS_16B_GUARD;
578 data->pi_size = sizeof(struct nvme_16b_guard_pif);
582 * when PRACT bit is set to 1, and metadata size is equal to protection
583 * information size, controller inserts and removes PI for write and
584 * read commands respectively.
586 if (pi_act && data->ms == data->pi_size)
589 data->pi_loc = (ns.dps & NVME_NS_DPS_PI_FIRST);
593 * Bit 4 for flbas indicates if metadata is transferred at the end of
594 * logical block creating an extended LBA.
596 if (data->ms && ((ns.flbas >> 4) & 0x1))
597 data->lba_ext = data->lba_size + data->ms;
599 data->lba_shift = ilog2(data->lba_size);
608 int fio_nvme_get_zoned_model(struct thread_data *td, struct fio_file *f,
609 enum zbd_zoned_model *model)
611 struct nvme_data *data = FILE_ENG_DATA(f);
612 struct nvme_id_ns ns;
613 struct nvme_passthru_cmd cmd;
616 if (f->filetype != FIO_TYPE_CHAR)
619 /* File is not yet opened */
620 fd = open(f->file_name, O_RDONLY | O_LARGEFILE);
624 /* Using nvme_id_ns for data as sizes are same */
625 ret = nvme_identify(fd, data->nsid, NVME_IDENTIFY_CNS_CSI_CTRL,
632 memset(&cmd, 0, sizeof(struct nvme_passthru_cmd));
634 /* Using nvme_id_ns for data as sizes are same */
635 ret = nvme_identify(fd, data->nsid, NVME_IDENTIFY_CNS_CSI_NS,
642 *model = ZBD_HOST_MANAGED;
648 static int nvme_report_zones(int fd, __u32 nsid, __u64 slba, __u32 zras_feat,
649 __u32 data_len, void *data)
651 struct nvme_passthru_cmd cmd = {
652 .opcode = nvme_zns_cmd_mgmt_recv,
654 .addr = (__u64)(uintptr_t)data,
655 .data_len = data_len,
656 .cdw10 = slba & 0xffffffff,
658 .cdw12 = (data_len >> 2) - 1,
659 .cdw13 = NVME_ZNS_ZRA_REPORT_ZONES | zras_feat,
660 .timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT,
663 return ioctl(fd, NVME_IOCTL_IO_CMD, &cmd);
666 int fio_nvme_report_zones(struct thread_data *td, struct fio_file *f,
667 uint64_t offset, struct zbd_zone *zbdz,
668 unsigned int nr_zones)
670 struct nvme_data *data = FILE_ENG_DATA(f);
671 struct nvme_zone_report *zr;
672 struct nvme_zns_id_ns zns_ns;
673 struct nvme_id_ns ns;
674 unsigned int i = 0, j, zones_fetched = 0;
675 unsigned int max_zones, zones_chunks = 1024;
680 /* File is not yet opened */
681 fd = open(f->file_name, O_RDONLY | O_LARGEFILE);
686 zr_len = sizeof(*zr) + (zones_chunks * sizeof(struct nvme_zns_desc));
687 zr = calloc(1, zr_len);
693 ret = nvme_identify(fd, data->nsid, NVME_IDENTIFY_CNS_NS,
696 log_err("%s: nvme_identify_ns failed, err=%d\n", f->file_name,
701 ret = nvme_identify(fd, data->nsid, NVME_IDENTIFY_CNS_CSI_NS,
702 NVME_CSI_ZNS, &zns_ns);
704 log_err("%s: nvme_zns_identify_ns failed, err=%d\n",
708 zlen = zns_ns.lbafe[ns.flbas & 0x0f].zsze << data->lba_shift;
710 max_zones = (f->real_file_size - offset) / zlen;
711 if (max_zones < nr_zones)
712 nr_zones = max_zones;
714 if (nr_zones < zones_chunks)
715 zones_chunks = nr_zones;
717 while (zones_fetched < nr_zones) {
718 if (zones_fetched + zones_chunks >= nr_zones) {
719 zones_chunks = nr_zones - zones_fetched;
720 zr_len = sizeof(*zr) + (zones_chunks * sizeof(struct nvme_zns_desc));
722 ret = nvme_report_zones(fd, data->nsid, offset >> data->lba_shift,
723 NVME_ZNS_ZRAS_FEAT_ERZ, zr_len, (void *)zr);
725 log_err("%s: nvme_zns_report_zones failed, err=%d\n",
730 /* Transform the zone-report */
731 for (j = 0; j < zr->nr_zones; j++, i++) {
732 struct nvme_zns_desc *desc = (struct nvme_zns_desc *)&(zr->entries[j]);
734 zbdz[i].start = desc->zslba << data->lba_shift;
736 zbdz[i].wp = desc->wp << data->lba_shift;
737 zbdz[i].capacity = desc->zcap << data->lba_shift;
739 /* Zone Type is stored in first 4 bits. */
740 switch (desc->zt & 0x0f) {
741 case NVME_ZONE_TYPE_SEQWRITE_REQ:
742 zbdz[i].type = ZBD_ZONE_TYPE_SWR;
745 log_err("%s: invalid type for zone at offset %llu.\n",
746 f->file_name, (unsigned long long) desc->zslba);
751 /* Zone State is stored in last 4 bits. */
752 switch (desc->zs >> 4) {
753 case NVME_ZNS_ZS_EMPTY:
754 zbdz[i].cond = ZBD_ZONE_COND_EMPTY;
756 case NVME_ZNS_ZS_IMPL_OPEN:
757 zbdz[i].cond = ZBD_ZONE_COND_IMP_OPEN;
759 case NVME_ZNS_ZS_EXPL_OPEN:
760 zbdz[i].cond = ZBD_ZONE_COND_EXP_OPEN;
762 case NVME_ZNS_ZS_CLOSED:
763 zbdz[i].cond = ZBD_ZONE_COND_CLOSED;
765 case NVME_ZNS_ZS_FULL:
766 zbdz[i].cond = ZBD_ZONE_COND_FULL;
768 case NVME_ZNS_ZS_READ_ONLY:
769 case NVME_ZNS_ZS_OFFLINE:
771 /* Treat all these conditions as offline (don't use!) */
772 zbdz[i].cond = ZBD_ZONE_COND_OFFLINE;
773 zbdz[i].wp = zbdz[i].start;
776 zones_fetched += zr->nr_zones;
777 offset += zr->nr_zones * zlen;
788 int fio_nvme_reset_wp(struct thread_data *td, struct fio_file *f,
789 uint64_t offset, uint64_t length)
791 struct nvme_data *data = FILE_ENG_DATA(f);
792 unsigned int nr_zones;
793 unsigned long long zslba;
796 /* If the file is not yet opened, open it for this function. */
799 fd = open(f->file_name, O_RDWR | O_LARGEFILE);
804 zslba = offset >> data->lba_shift;
805 nr_zones = (length + td->o.zone_size - 1) / td->o.zone_size;
807 for (i = 0; i < nr_zones; i++, zslba += (td->o.zone_size >> data->lba_shift)) {
808 struct nvme_passthru_cmd cmd = {
809 .opcode = nvme_zns_cmd_mgmt_send,
811 .cdw10 = zslba & 0xffffffff,
812 .cdw11 = zslba >> 32,
813 .cdw13 = NVME_ZNS_ZSA_RESET,
814 .addr = (__u64)(uintptr_t)NULL,
816 .timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT,
819 ret = ioctl(fd, NVME_IOCTL_IO_CMD, &cmd);
827 int fio_nvme_get_max_open_zones(struct thread_data *td, struct fio_file *f,
828 unsigned int *max_open_zones)
830 struct nvme_data *data = FILE_ENG_DATA(f);
831 struct nvme_zns_id_ns zns_ns;
834 fd = open(f->file_name, O_RDONLY | O_LARGEFILE);
838 ret = nvme_identify(fd, data->nsid, NVME_IDENTIFY_CNS_CSI_NS,
839 NVME_CSI_ZNS, &zns_ns);
841 log_err("%s: nvme_zns_identify_ns failed, err=%d\n",
846 *max_open_zones = zns_ns.mor + 1;
852 static inline int nvme_fdp_reclaim_unit_handle_status(int fd, __u32 nsid,
853 __u32 data_len, void *data)
855 struct nvme_passthru_cmd cmd = {
856 .opcode = nvme_cmd_io_mgmt_recv,
858 .addr = (__u64)(uintptr_t)data,
859 .data_len = data_len,
861 .cdw11 = (data_len >> 2) - 1,
864 return ioctl(fd, NVME_IOCTL_IO_CMD, &cmd);
867 int fio_nvme_iomgmt_ruhs(struct thread_data *td, struct fio_file *f,
868 struct nvme_fdp_ruh_status *ruhs, __u32 bytes)
870 struct nvme_data *data = FILE_ENG_DATA(f);
873 fd = open(f->file_name, O_RDONLY | O_LARGEFILE);
877 ret = nvme_fdp_reclaim_unit_handle_status(fd, data->nsid, bytes, ruhs);
879 log_err("%s: nvme_fdp_reclaim_unit_handle_status failed, err=%d\n",