Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2020 Western Digital Corporation or its affiliates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "nvme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) int nvme_revalidate_zones(struct nvme_ns *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	struct request_queue *q = ns->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	ret = blk_revalidate_disk_zones(ns->disk, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 		blk_queue_max_zone_append_sectors(q, ns->ctrl->max_zone_append);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int nvme_set_max_append(struct nvme_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct nvme_command c = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct nvme_id_ctrl_zns *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	id = kzalloc(sizeof(*id), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	c.identify.opcode = nvme_admin_identify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	c.identify.cns = NVME_ID_CNS_CS_CTRL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	c.identify.csi = NVME_CSI_ZNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	status = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (id->zasl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		ctrl->max_zone_append = 1 << (id->zasl + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		ctrl->max_zone_append = ctrl->max_hw_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct nvme_effects_log *log = ns->head->effects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct request_queue *q = ns->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct nvme_command c = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct nvme_id_ns_zns *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* Driver requires zone append support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (!(le32_to_cpu(log->iocs[nvme_cmd_zone_append]) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			NVME_CMD_EFFECTS_CSUPP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		dev_warn(ns->ctrl->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			"append not supported for zoned namespace:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			ns->head->ns_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* Lazily query controller append limit for the first zoned namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (!ns->ctrl->max_zone_append) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		status = nvme_set_max_append(ns->ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	id = kzalloc(sizeof(*id), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	c.identify.opcode = nvme_admin_identify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	c.identify.nsid = cpu_to_le32(ns->head->ns_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	c.identify.cns = NVME_ID_CNS_CS_NS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	c.identify.csi = NVME_CSI_ZNS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	status = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, id, sizeof(*id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		goto free_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * We currently do not handle devices requiring any of the zoned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * operation characteristics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (id->zoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		dev_warn(ns->ctrl->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			"zone operations:%x not supported for namespace:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			le16_to_cpu(id->zoc), ns->head->ns_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		goto free_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ns->zsze = nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (!is_power_of_2(ns->zsze)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		dev_warn(ns->ctrl->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			"invalid zone size:%llu for namespace:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			ns->zsze, ns->head->ns_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		goto free_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	q->limits.zoned = BLK_ZONED_HM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	blk_queue_max_open_zones(q, le32_to_cpu(id->mor) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	blk_queue_max_active_zones(q, le32_to_cpu(id->mar) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) free_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					  unsigned int nr_zones, size_t *buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct request_queue *q = ns->disk->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	size_t bufsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	const size_t min_bufsize = sizeof(struct nvme_zone_report) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				   sizeof(struct nvme_zone_descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	nr_zones = min_t(unsigned int, nr_zones,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			 get_capacity(ns->disk) >> ilog2(ns->zsze));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	bufsize = sizeof(struct nvme_zone_report) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		nr_zones * sizeof(struct nvme_zone_descriptor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	bufsize = min_t(size_t, bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			queue_max_hw_sectors(q) << SECTOR_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	while (bufsize >= min_bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		buf = __vmalloc(bufsize, GFP_KERNEL | __GFP_NORETRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			*buflen = bufsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		bufsize >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int nvme_zone_parse_entry(struct nvme_ns *ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				 struct nvme_zone_descriptor *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				 unsigned int idx, report_zones_cb cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				 void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct blk_zone zone = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if ((entry->zt & 0xf) != NVME_ZONE_TYPE_SEQWRITE_REQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		dev_err(ns->ctrl->device, "invalid zone type %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				entry->zt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	zone.type = BLK_ZONE_TYPE_SEQWRITE_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	zone.cond = entry->zs >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	zone.len = ns->zsze;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	zone.capacity = nvme_lba_to_sect(ns, le64_to_cpu(entry->zcap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	zone.start = nvme_lba_to_sect(ns, le64_to_cpu(entry->zslba));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	zone.wp = nvme_lba_to_sect(ns, le64_to_cpu(entry->wp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return cb(&zone, idx, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			unsigned int nr_zones, report_zones_cb cb, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct nvme_zone_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct nvme_command c = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int ret, zone_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	unsigned int nz, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	size_t buflen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	report = nvme_zns_alloc_report_buffer(ns, nr_zones, &buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!report)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	c.zmr.zra = NVME_ZRA_ZONE_REPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	sector &= ~(ns->zsze - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		memset(report, 0, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (!nz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		for (i = 0; i < nz && zone_idx < nr_zones; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			ret = nvme_zone_parse_entry(ns, &report->entries[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 						    zone_idx, cb, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			zone_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		sector += ns->zsze * nz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (zone_idx > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		ret = zone_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	kvfree(report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int nvme_report_zones(struct gendisk *disk, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		      unsigned int nr_zones, report_zones_cb cb, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct nvme_ns_head *head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct nvme_ns *ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	int srcu_idx, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	ns = nvme_get_ns_from_disk(disk, &head, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (unlikely(!ns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return -EWOULDBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (ns->head->ids.csi == NVME_CSI_ZNS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		ret = nvme_ns_report_zones(ns, sector, nr_zones, cb, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	nvme_put_ns_from_disk(head, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		struct nvme_command *c, enum nvme_zone_mgmt_action action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	c->zms.opcode = nvme_cmd_zone_mgmt_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	c->zms.nsid = cpu_to_le32(ns->head->ns_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	c->zms.slba = cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	c->zms.zsa = action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (req_op(req) == REQ_OP_ZONE_RESET_ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		c->zms.select_all = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }