1 // SPDX-License-Identifier: GPL-2.0-only
3 * SCSI Zoned Block commands
5 * Copyright (C) 2014-2015 SUSE Linux GmbH
6 * Written by: Hannes Reinecke <hare@suse.de>
7 * Modified by: Damien Le Moal <damien.lemoal@hgst.com>
8 * Modified by: Shaun Tancheff <shaun.tancheff@seagate.com>
11 #include <linux/blkdev.h>
12 #include <linux/vmalloc.h>
13 #include <linux/sched/mm.h>
14 #include <linux/mutex.h>
16 #include <asm/unaligned.h>
18 #include <scsi/scsi.h>
19 #include <scsi/scsi_cmnd.h>
23 static unsigned int sd_zbc_get_zone_wp_offset(struct blk_zone *zone)
25 if (zone->type == ZBC_ZONE_TYPE_CONV)
29 case BLK_ZONE_COND_IMP_OPEN:
30 case BLK_ZONE_COND_EXP_OPEN:
31 case BLK_ZONE_COND_CLOSED:
32 return zone->wp - zone->start;
33 case BLK_ZONE_COND_FULL:
35 case BLK_ZONE_COND_EMPTY:
36 case BLK_ZONE_COND_OFFLINE:
37 case BLK_ZONE_COND_READONLY:
40 * Offline and read-only zones do not have a valid
41 * write pointer. Use 0 as for an empty zone.
47 static int sd_zbc_parse_report(struct scsi_disk *sdkp, u8 *buf,
48 unsigned int idx, report_zones_cb cb, void *data)
50 struct scsi_device *sdp = sdkp->device;
51 struct blk_zone zone = { 0 };
54 zone.type = buf[0] & 0x0f;
55 zone.cond = (buf[1] >> 4) & 0xf;
61 zone.len = logical_to_sectors(sdp, get_unaligned_be64(&buf[8]));
62 zone.capacity = zone.len;
63 zone.start = logical_to_sectors(sdp, get_unaligned_be64(&buf[16]));
64 zone.wp = logical_to_sectors(sdp, get_unaligned_be64(&buf[24]));
65 if (zone.type != ZBC_ZONE_TYPE_CONV &&
66 zone.cond == ZBC_ZONE_COND_FULL)
67 zone.wp = zone.start + zone.len;
69 ret = cb(&zone, idx, data);
73 if (sdkp->rev_wp_offset)
74 sdkp->rev_wp_offset[idx] = sd_zbc_get_zone_wp_offset(&zone);
80 * sd_zbc_do_report_zones - Issue a REPORT ZONES scsi command.
81 * @sdkp: The target disk
82 * @buf: vmalloc-ed buffer to use for the reply
83 * @buflen: the buffer size
84 * @lba: Start LBA of the report
85 * @partial: Do partial report
87 * For internal use during device validation.
88 * Using partial=true can significantly speed up execution of a report zones
89 * command because the disk does not have to count all possible report matching
90 * zones and will only report the count of zones fitting in the command reply
93 static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
94 unsigned int buflen, sector_t lba,
97 struct scsi_device *sdp = sdkp->device;
98 const int timeout = sdp->request_queue->rq_timeout;
99 struct scsi_sense_hdr sshdr;
100 unsigned char cmd[16];
101 unsigned int rep_len;
106 cmd[1] = ZI_REPORT_ZONES;
107 put_unaligned_be64(lba, &cmd[2]);
108 put_unaligned_be32(buflen, &cmd[10]);
110 cmd[14] = ZBC_REPORT_ZONE_PARTIAL;
112 result = scsi_execute_req(sdp, cmd, DMA_FROM_DEVICE,
114 timeout, SD_MAX_RETRIES, NULL);
116 sd_printk(KERN_ERR, sdkp,
117 "REPORT ZONES start lba %llu failed\n", lba);
118 sd_print_result(sdkp, "REPORT ZONES", result);
119 if (driver_byte(result) == DRIVER_SENSE &&
120 scsi_sense_valid(&sshdr))
121 sd_print_sense_hdr(sdkp, &sshdr);
125 rep_len = get_unaligned_be32(&buf[0]);
127 sd_printk(KERN_ERR, sdkp,
128 "REPORT ZONES report invalid length %u\n",
137 * sd_zbc_alloc_report_buffer() - Allocate a buffer for report zones reply.
138 * @sdkp: The target disk
139 * @nr_zones: Maximum number of zones to report
140 * @buflen: Size of the buffer allocated
142 * Try to allocate a reply buffer for the number of requested zones.
143 * The size of the buffer allocated may be smaller than requested to
144 * satify the device constraint (max_hw_sectors, max_segments, etc).
146 * Return the address of the allocated buffer and update @buflen with
147 * the size of the allocated buffer.
149 static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
150 unsigned int nr_zones, size_t *buflen)
152 struct request_queue *q = sdkp->disk->queue;
157 * Report zone buffer size should be at most 64B times the number of
158 * zones requested plus the 64B reply header, but should be at least
159 * SECTOR_SIZE for ATA devices.
160 * Make sure that this size does not exceed the hardware capabilities.
161 * Furthermore, since the report zone command cannot be split, make
162 * sure that the allocated buffer can always be mapped by limiting the
163 * number of pages allocated to the HBA max segments limit.
165 nr_zones = min(nr_zones, sdkp->nr_zones);
166 bufsize = roundup((nr_zones + 1) * 64, SECTOR_SIZE);
167 bufsize = min_t(size_t, bufsize,
168 queue_max_hw_sectors(q) << SECTOR_SHIFT);
169 bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
171 while (bufsize >= SECTOR_SIZE) {
172 buf = __vmalloc(bufsize,
173 GFP_KERNEL | __GFP_ZERO | __GFP_NORETRY);
185 * sd_zbc_zone_sectors - Get the device zone size in number of 512B sectors.
186 * @sdkp: The target disk
188 static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp)
190 return logical_to_sectors(sdkp->device, sdkp->zone_blocks);
193 int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
194 unsigned int nr_zones, report_zones_cb cb, void *data)
196 struct scsi_disk *sdkp = scsi_disk(disk);
197 sector_t capacity = logical_to_sectors(sdkp->device, sdkp->capacity);
200 size_t offset, buflen = 0;
204 if (!sd_is_zoned(sdkp))
205 /* Not a zoned device */
209 /* Device gone or invalid */
212 buf = sd_zbc_alloc_report_buffer(sdkp, nr_zones, &buflen);
216 while (zone_idx < nr_zones && sector < capacity) {
217 ret = sd_zbc_do_report_zones(sdkp, buf, buflen,
218 sectors_to_logical(sdkp->device, sector), true);
223 nr = min(nr_zones, get_unaligned_be32(&buf[0]) / 64);
227 for (i = 0; i < nr && zone_idx < nr_zones; i++) {
229 ret = sd_zbc_parse_report(sdkp, buf + offset, zone_idx,
236 sector += sd_zbc_zone_sectors(sdkp) * i;
245 static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd)
247 struct request *rq = cmd->request;
248 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
249 sector_t sector = blk_rq_pos(rq);
251 if (!sd_is_zoned(sdkp))
252 /* Not a zoned device */
253 return BLK_STS_IOERR;
255 if (sdkp->device->changed)
256 return BLK_STS_IOERR;
258 if (sector & (sd_zbc_zone_sectors(sdkp) - 1))
259 /* Unaligned request */
260 return BLK_STS_IOERR;
265 #define SD_ZBC_INVALID_WP_OFST (~0u)
266 #define SD_ZBC_UPDATING_WP_OFST (SD_ZBC_INVALID_WP_OFST - 1)
268 static int sd_zbc_update_wp_offset_cb(struct blk_zone *zone, unsigned int idx,
271 struct scsi_disk *sdkp = data;
273 lockdep_assert_held(&sdkp->zones_wp_offset_lock);
275 sdkp->zones_wp_offset[idx] = sd_zbc_get_zone_wp_offset(zone);
280 static void sd_zbc_update_wp_offset_workfn(struct work_struct *work)
282 struct scsi_disk *sdkp;
287 sdkp = container_of(work, struct scsi_disk, zone_wp_offset_work);
289 spin_lock_irqsave(&sdkp->zones_wp_offset_lock, flags);
290 for (zno = 0; zno < sdkp->nr_zones; zno++) {
291 if (sdkp->zones_wp_offset[zno] != SD_ZBC_UPDATING_WP_OFST)
294 spin_unlock_irqrestore(&sdkp->zones_wp_offset_lock, flags);
295 ret = sd_zbc_do_report_zones(sdkp, sdkp->zone_wp_update_buf,
297 zno * sdkp->zone_blocks, true);
298 spin_lock_irqsave(&sdkp->zones_wp_offset_lock, flags);
300 sd_zbc_parse_report(sdkp, sdkp->zone_wp_update_buf + 64,
301 zno, sd_zbc_update_wp_offset_cb,
304 spin_unlock_irqrestore(&sdkp->zones_wp_offset_lock, flags);
306 scsi_device_put(sdkp->device);
310 * sd_zbc_prepare_zone_append() - Prepare an emulated ZONE_APPEND command.
311 * @cmd: the command to setup
312 * @lba: the LBA to patch
313 * @nr_blocks: the number of LBAs to be written
315 * Called from sd_setup_read_write_cmnd() for REQ_OP_ZONE_APPEND.
316 * @sd_zbc_prepare_zone_append() handles the necessary zone wrote locking and
317 * patching of the lba for an emulated ZONE_APPEND command.
319 * In case the cached write pointer offset is %SD_ZBC_INVALID_WP_OFST it will
320 * schedule a REPORT ZONES command and return BLK_STS_IOERR.
322 blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, sector_t *lba,
323 unsigned int nr_blocks)
325 struct request *rq = cmd->request;
326 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
327 unsigned int wp_offset, zno = blk_rq_zone_no(rq);
331 ret = sd_zbc_cmnd_checks(cmd);
332 if (ret != BLK_STS_OK)
335 if (!blk_rq_zone_is_seq(rq))
336 return BLK_STS_IOERR;
338 /* Unlock of the write lock will happen in sd_zbc_complete() */
339 if (!blk_req_zone_write_trylock(rq))
340 return BLK_STS_ZONE_RESOURCE;
342 spin_lock_irqsave(&sdkp->zones_wp_offset_lock, flags);
343 wp_offset = sdkp->zones_wp_offset[zno];
345 case SD_ZBC_INVALID_WP_OFST:
347 * We are about to schedule work to update a zone write pointer
348 * offset, which will cause the zone append command to be
349 * requeued. So make sure that the scsi device does not go away
350 * while the work is being processed.
352 if (scsi_device_get(sdkp->device)) {
356 sdkp->zones_wp_offset[zno] = SD_ZBC_UPDATING_WP_OFST;
357 schedule_work(&sdkp->zone_wp_offset_work);
359 case SD_ZBC_UPDATING_WP_OFST:
360 ret = BLK_STS_DEV_RESOURCE;
363 wp_offset = sectors_to_logical(sdkp->device, wp_offset);
364 if (wp_offset + nr_blocks > sdkp->zone_blocks) {
371 spin_unlock_irqrestore(&sdkp->zones_wp_offset_lock, flags);
373 blk_req_zone_write_unlock(rq);
378 * sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations
379 * can be RESET WRITE POINTER, OPEN, CLOSE or FINISH.
380 * @cmd: the command to setup
381 * @op: Operation to be performed
382 * @all: All zones control
384 * Called from sd_init_command() for REQ_OP_ZONE_RESET, REQ_OP_ZONE_RESET_ALL,
385 * REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE or REQ_OP_ZONE_FINISH requests.
387 blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
388 unsigned char op, bool all)
390 struct request *rq = cmd->request;
391 sector_t sector = blk_rq_pos(rq);
392 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
393 sector_t block = sectors_to_logical(sdkp->device, sector);
396 ret = sd_zbc_cmnd_checks(cmd);
397 if (ret != BLK_STS_OK)
401 memset(cmd->cmnd, 0, cmd->cmd_len);
402 cmd->cmnd[0] = ZBC_OUT;
407 put_unaligned_be64(block, &cmd->cmnd[2]);
409 rq->timeout = SD_TIMEOUT;
410 cmd->sc_data_direction = DMA_NONE;
411 cmd->transfersize = 0;
417 static bool sd_zbc_need_zone_wp_update(struct request *rq)
419 switch (req_op(rq)) {
420 case REQ_OP_ZONE_APPEND:
421 case REQ_OP_ZONE_FINISH:
422 case REQ_OP_ZONE_RESET:
423 case REQ_OP_ZONE_RESET_ALL:
426 case REQ_OP_WRITE_ZEROES:
427 case REQ_OP_WRITE_SAME:
428 return blk_rq_zone_is_seq(rq);
435 * sd_zbc_zone_wp_update - Update cached zone write pointer upon cmd completion
436 * @cmd: Completed command
437 * @good_bytes: Command reply bytes
439 * Called from sd_zbc_complete() to handle the update of the cached zone write
440 * pointer value in case an update is needed.
442 static unsigned int sd_zbc_zone_wp_update(struct scsi_cmnd *cmd,
443 unsigned int good_bytes)
445 int result = cmd->result;
446 struct request *rq = cmd->request;
447 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
448 unsigned int zno = blk_rq_zone_no(rq);
449 enum req_opf op = req_op(rq);
453 * If we got an error for a command that needs updating the write
454 * pointer offset cache, we must mark the zone wp offset entry as
455 * invalid to force an update from disk the next time a zone append
458 spin_lock_irqsave(&sdkp->zones_wp_offset_lock, flags);
460 if (result && op != REQ_OP_ZONE_RESET_ALL) {
461 if (op == REQ_OP_ZONE_APPEND) {
462 /* Force complete completion (no retry) */
464 scsi_set_resid(cmd, blk_rq_bytes(rq));
468 * Force an update of the zone write pointer offset on
469 * the next zone append access.
471 if (sdkp->zones_wp_offset[zno] != SD_ZBC_UPDATING_WP_OFST)
472 sdkp->zones_wp_offset[zno] = SD_ZBC_INVALID_WP_OFST;
473 goto unlock_wp_offset;
477 case REQ_OP_ZONE_APPEND:
478 rq->__sector += sdkp->zones_wp_offset[zno];
480 case REQ_OP_WRITE_ZEROES:
481 case REQ_OP_WRITE_SAME:
483 if (sdkp->zones_wp_offset[zno] < sd_zbc_zone_sectors(sdkp))
484 sdkp->zones_wp_offset[zno] +=
485 good_bytes >> SECTOR_SHIFT;
487 case REQ_OP_ZONE_RESET:
488 sdkp->zones_wp_offset[zno] = 0;
490 case REQ_OP_ZONE_FINISH:
491 sdkp->zones_wp_offset[zno] = sd_zbc_zone_sectors(sdkp);
493 case REQ_OP_ZONE_RESET_ALL:
494 memset(sdkp->zones_wp_offset, 0,
495 sdkp->nr_zones * sizeof(unsigned int));
502 spin_unlock_irqrestore(&sdkp->zones_wp_offset_lock, flags);
508 * sd_zbc_complete - ZBC command post processing.
509 * @cmd: Completed command
510 * @good_bytes: Command reply bytes
511 * @sshdr: command sense header
513 * Called from sd_done() to handle zone commands errors and updates to the
514 * device queue zone write pointer offset cahce.
516 unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
517 struct scsi_sense_hdr *sshdr)
519 int result = cmd->result;
520 struct request *rq = cmd->request;
522 if (op_is_zone_mgmt(req_op(rq)) &&
524 sshdr->sense_key == ILLEGAL_REQUEST &&
525 sshdr->asc == 0x24) {
527 * INVALID FIELD IN CDB error: a zone management command was
528 * attempted on a conventional zone. Nothing to worry about,
529 * so be quiet about the error.
531 rq->rq_flags |= RQF_QUIET;
532 } else if (sd_zbc_need_zone_wp_update(rq))
533 good_bytes = sd_zbc_zone_wp_update(cmd, good_bytes);
535 if (req_op(rq) == REQ_OP_ZONE_APPEND)
536 blk_req_zone_write_unlock(rq);
542 * sd_zbc_check_zoned_characteristics - Check zoned block device characteristics
544 * @buf: Buffer where to store the VPD page data
546 * Read VPD page B6, get information and check that reads are unconstrained.
548 static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp,
552 if (scsi_get_vpd_page(sdkp->device, 0xb6, buf, 64)) {
553 sd_printk(KERN_NOTICE, sdkp,
554 "Read zoned characteristics VPD page failed\n");
558 if (sdkp->device->type != TYPE_ZBC) {
561 sdkp->zones_optimal_open = get_unaligned_be32(&buf[8]);
562 sdkp->zones_optimal_nonseq = get_unaligned_be32(&buf[12]);
563 sdkp->zones_max_open = 0;
566 sdkp->urswrz = buf[4] & 1;
567 sdkp->zones_optimal_open = 0;
568 sdkp->zones_optimal_nonseq = 0;
569 sdkp->zones_max_open = get_unaligned_be32(&buf[16]);
573 * Check for unconstrained reads: host-managed devices with
574 * constrained reads (drives failing read after write pointer)
578 if (sdkp->first_scan)
579 sd_printk(KERN_NOTICE, sdkp,
580 "constrained reads devices are not supported\n");
588 * sd_zbc_check_capacity - Check the device capacity
590 * @buf: command buffer
591 * @zblocks: zone size in number of blocks
593 * Get the device zone size and check that the device capacity as reported
594 * by READ CAPACITY matches the max_lba value (plus one) of the report zones
595 * command reply for devices with RC_BASIS == 0.
597 * Returns 0 upon success or an error code upon failure.
599 static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
607 /* Do a report zone to get max_lba and the size of the first zone */
608 ret = sd_zbc_do_report_zones(sdkp, buf, SD_BUF_SIZE, 0, false);
612 if (sdkp->rc_basis == 0) {
613 /* The max_lba field is the capacity of this device */
614 max_lba = get_unaligned_be64(&buf[8]);
615 if (sdkp->capacity != max_lba + 1) {
616 if (sdkp->first_scan)
617 sd_printk(KERN_WARNING, sdkp,
618 "Changing capacity from %llu to max LBA+1 %llu\n",
619 (unsigned long long)sdkp->capacity,
620 (unsigned long long)max_lba + 1);
621 sdkp->capacity = max_lba + 1;
625 /* Get the size of the first reported zone */
627 zone_blocks = get_unaligned_be64(&rec[8]);
628 if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
629 if (sdkp->first_scan)
630 sd_printk(KERN_NOTICE, sdkp,
631 "Zone size too large\n");
635 *zblocks = zone_blocks;
640 static void sd_zbc_print_zones(struct scsi_disk *sdkp)
642 if (!sd_is_zoned(sdkp) || !sdkp->capacity)
645 if (sdkp->capacity & (sdkp->zone_blocks - 1))
646 sd_printk(KERN_NOTICE, sdkp,
647 "%u zones of %u logical blocks + 1 runt zone\n",
651 sd_printk(KERN_NOTICE, sdkp,
652 "%u zones of %u logical blocks\n",
657 static int sd_zbc_init_disk(struct scsi_disk *sdkp)
659 sdkp->zones_wp_offset = NULL;
660 spin_lock_init(&sdkp->zones_wp_offset_lock);
661 sdkp->rev_wp_offset = NULL;
662 mutex_init(&sdkp->rev_mutex);
663 INIT_WORK(&sdkp->zone_wp_offset_work, sd_zbc_update_wp_offset_workfn);
664 sdkp->zone_wp_update_buf = kzalloc(SD_BUF_SIZE, GFP_KERNEL);
665 if (!sdkp->zone_wp_update_buf)
671 static void sd_zbc_clear_zone_info(struct scsi_disk *sdkp)
673 /* Serialize against revalidate zones */
674 mutex_lock(&sdkp->rev_mutex);
676 kvfree(sdkp->zones_wp_offset);
677 sdkp->zones_wp_offset = NULL;
678 kfree(sdkp->zone_wp_update_buf);
679 sdkp->zone_wp_update_buf = NULL;
682 sdkp->rev_nr_zones = 0;
683 sdkp->zone_blocks = 0;
684 sdkp->rev_zone_blocks = 0;
686 mutex_unlock(&sdkp->rev_mutex);
689 void sd_zbc_release_disk(struct scsi_disk *sdkp)
691 if (sd_is_zoned(sdkp))
692 sd_zbc_clear_zone_info(sdkp);
695 static void sd_zbc_revalidate_zones_cb(struct gendisk *disk)
697 struct scsi_disk *sdkp = scsi_disk(disk);
699 swap(sdkp->zones_wp_offset, sdkp->rev_wp_offset);
702 int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
704 struct gendisk *disk = sdkp->disk;
705 struct request_queue *q = disk->queue;
706 u32 zone_blocks = sdkp->rev_zone_blocks;
707 unsigned int nr_zones = sdkp->rev_nr_zones;
713 * For all zoned disks, initialize zone append emulation data if not
714 * already done. This is necessary also for host-aware disks used as
715 * regular disks due to the presence of partitions as these partitions
716 * may be deleted and the disk zoned model changed back from
717 * BLK_ZONED_NONE to BLK_ZONED_HA.
719 if (sd_is_zoned(sdkp) && !sdkp->zone_wp_update_buf) {
720 ret = sd_zbc_init_disk(sdkp);
726 * There is nothing to do for regular disks, including host-aware disks
727 * that have partitions.
729 if (!blk_queue_is_zoned(q))
733 * Make sure revalidate zones are serialized to ensure exclusive
734 * updates of the scsi disk data.
736 mutex_lock(&sdkp->rev_mutex);
738 if (sdkp->zone_blocks == zone_blocks &&
739 sdkp->nr_zones == nr_zones &&
740 disk->queue->nr_zones == nr_zones)
743 flags = memalloc_noio_save();
744 sdkp->zone_blocks = zone_blocks;
745 sdkp->nr_zones = nr_zones;
746 sdkp->rev_wp_offset = kvcalloc(nr_zones, sizeof(u32), GFP_KERNEL);
747 if (!sdkp->rev_wp_offset) {
749 memalloc_noio_restore(flags);
753 ret = blk_revalidate_disk_zones(disk, sd_zbc_revalidate_zones_cb);
755 memalloc_noio_restore(flags);
756 kvfree(sdkp->rev_wp_offset);
757 sdkp->rev_wp_offset = NULL;
760 sdkp->zone_blocks = 0;
766 max_append = min_t(u32, logical_to_sectors(sdkp->device, zone_blocks),
767 q->limits.max_segments << (PAGE_SHIFT - 9));
768 max_append = min_t(u32, max_append, queue_max_hw_sectors(q));
770 blk_queue_max_zone_append_sectors(q, max_append);
772 sd_zbc_print_zones(sdkp);
775 mutex_unlock(&sdkp->rev_mutex);
780 int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf)
782 struct gendisk *disk = sdkp->disk;
783 struct request_queue *q = disk->queue;
784 unsigned int nr_zones;
788 if (!sd_is_zoned(sdkp))
790 * Device managed or normal SCSI disk,
791 * no special handling required
795 /* READ16/WRITE16 is mandatory for ZBC disks */
796 sdkp->device->use_16_for_rw = 1;
797 sdkp->device->use_10_for_rw = 0;
799 if (!blk_queue_is_zoned(q)) {
801 * This can happen for a host aware disk with partitions.
802 * The block device zone information was already cleared
803 * by blk_queue_set_zoned(). Only clear the scsi disk zone
804 * information and exit early.
806 sd_zbc_clear_zone_info(sdkp);
810 /* Check zoned block device characteristics (unconstrained reads) */
811 ret = sd_zbc_check_zoned_characteristics(sdkp, buf);
815 /* Check the device capacity reported by report zones */
816 ret = sd_zbc_check_capacity(sdkp, buf, &zone_blocks);
820 /* The drive satisfies the kernel restrictions: set it up */
821 blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
822 blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE);
823 if (sdkp->zones_max_open == U32_MAX)
824 blk_queue_max_open_zones(q, 0);
826 blk_queue_max_open_zones(q, sdkp->zones_max_open);
827 blk_queue_max_active_zones(q, 0);
828 nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
831 * Per ZBC and ZAC specifications, writes in sequential write required
832 * zones of host-managed devices must be aligned to the device physical
835 if (blk_queue_zoned_model(q) == BLK_ZONED_HM)
836 blk_queue_zone_write_granularity(q, sdkp->physical_block_size);
838 sdkp->rev_nr_zones = nr_zones;
839 sdkp->rev_zone_blocks = zone_blocks;