1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * SCSI Zoned Block commands
4 *
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>
9 */
10
11 #include <linux/blkdev.h>
12 #include <linux/vmalloc.h>
13 #include <linux/sched/mm.h>
14 #include <linux/mutex.h>
15
16 #include <linux/unaligned.h>
17
18 #include <scsi/scsi.h>
19 #include <scsi/scsi_cmnd.h>
20
21 #include "sd.h"
22
23 #define CREATE_TRACE_POINTS
24 #include "sd_trace.h"
25
26 /* Whether or not a SCSI zone descriptor describes a gap zone. */
sd_zbc_is_gap_zone(const u8 buf[64])27 static bool sd_zbc_is_gap_zone(const u8 buf[64])
28 {
29 return (buf[0] & 0xf) == ZBC_ZONE_TYPE_GAP;
30 }
31
32 /**
33 * sd_zbc_parse_report - Parse a SCSI zone descriptor
34 * @sdkp: SCSI disk pointer.
35 * @buf: SCSI zone descriptor.
36 * @idx: Index of the zone relative to the first zone reported by the current
37 * sd_zbc_report_zones() call.
38 * @cb: Callback function pointer.
39 * @data: Second argument passed to @cb.
40 *
41 * Return: Value returned by @cb.
42 *
43 * Convert a SCSI zone descriptor into struct blk_zone format. Additionally,
44 * call @cb(blk_zone, @data).
45 */
sd_zbc_parse_report(struct scsi_disk * sdkp,const u8 buf[64],unsigned int idx,report_zones_cb cb,void * data)46 static int sd_zbc_parse_report(struct scsi_disk *sdkp, const u8 buf[64],
47 unsigned int idx, report_zones_cb cb, void *data)
48 {
49 struct scsi_device *sdp = sdkp->device;
50 struct blk_zone zone = { 0 };
51 sector_t start_lba, gran;
52 int ret;
53
54 if (WARN_ON_ONCE(sd_zbc_is_gap_zone(buf)))
55 return -EINVAL;
56
57 zone.type = buf[0] & 0x0f;
58 zone.cond = (buf[1] >> 4) & 0xf;
59 if (buf[1] & 0x01)
60 zone.reset = 1;
61 if (buf[1] & 0x02)
62 zone.non_seq = 1;
63
64 start_lba = get_unaligned_be64(&buf[16]);
65 zone.start = logical_to_sectors(sdp, start_lba);
66 zone.capacity = logical_to_sectors(sdp, get_unaligned_be64(&buf[8]));
67 zone.len = zone.capacity;
68 if (sdkp->zone_starting_lba_gran) {
69 gran = logical_to_sectors(sdp, sdkp->zone_starting_lba_gran);
70 if (zone.len > gran) {
71 sd_printk(KERN_ERR, sdkp,
72 "Invalid zone at LBA %llu with capacity %llu and length %llu; granularity = %llu\n",
73 start_lba,
74 sectors_to_logical(sdp, zone.capacity),
75 sectors_to_logical(sdp, zone.len),
76 sectors_to_logical(sdp, gran));
77 return -EINVAL;
78 }
79 /*
80 * Use the starting LBA granularity instead of the zone length
81 * obtained from the REPORT ZONES command.
82 */
83 zone.len = gran;
84 }
85 if (zone.cond == ZBC_ZONE_COND_FULL)
86 zone.wp = zone.start + zone.len;
87 else
88 zone.wp = logical_to_sectors(sdp, get_unaligned_be64(&buf[24]));
89
90 ret = cb(&zone, idx, data);
91 if (ret)
92 return ret;
93
94 return 0;
95 }
96
97 /**
98 * sd_zbc_do_report_zones - Issue a REPORT ZONES scsi command.
99 * @sdkp: The target disk
100 * @buf: vmalloc-ed buffer to use for the reply
101 * @buflen: the buffer size
102 * @lba: Start LBA of the report
103 * @partial: Do partial report
104 *
105 * For internal use during device validation.
106 * Using partial=true can significantly speed up execution of a report zones
107 * command because the disk does not have to count all possible report matching
108 * zones and will only report the count of zones fitting in the command reply
109 * buffer.
110 */
sd_zbc_do_report_zones(struct scsi_disk * sdkp,unsigned char * buf,unsigned int buflen,sector_t lba,bool partial)111 static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
112 unsigned int buflen, sector_t lba,
113 bool partial)
114 {
115 struct scsi_device *sdp = sdkp->device;
116 const int timeout = sdp->request_queue->rq_timeout;
117 struct scsi_sense_hdr sshdr;
118 const struct scsi_exec_args exec_args = {
119 .sshdr = &sshdr,
120 };
121 unsigned char cmd[16];
122 unsigned int rep_len;
123 int result;
124
125 memset(cmd, 0, 16);
126 cmd[0] = ZBC_IN;
127 cmd[1] = ZI_REPORT_ZONES;
128 put_unaligned_be64(lba, &cmd[2]);
129 put_unaligned_be32(buflen, &cmd[10]);
130 if (partial)
131 cmd[14] = ZBC_REPORT_ZONE_PARTIAL;
132
133 result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, buf, buflen,
134 timeout, SD_MAX_RETRIES, &exec_args);
135 if (result) {
136 sd_printk(KERN_ERR, sdkp,
137 "REPORT ZONES start lba %llu failed\n", lba);
138 sd_print_result(sdkp, "REPORT ZONES", result);
139 if (result > 0 && scsi_sense_valid(&sshdr))
140 sd_print_sense_hdr(sdkp, &sshdr);
141 return -EIO;
142 }
143
144 rep_len = get_unaligned_be32(&buf[0]);
145 if (rep_len < 64) {
146 sd_printk(KERN_ERR, sdkp,
147 "REPORT ZONES report invalid length %u\n",
148 rep_len);
149 return -EIO;
150 }
151
152 return 0;
153 }
154
155 /**
156 * sd_zbc_alloc_report_buffer() - Allocate a buffer for report zones reply.
157 * @sdkp: The target disk
158 * @nr_zones: Maximum number of zones to report
159 * @buflen: Size of the buffer allocated
160 *
161 * Try to allocate a reply buffer for the number of requested zones.
162 * The size of the buffer allocated may be smaller than requested to
163 * satify the device constraint (max_hw_sectors, max_segments, etc).
164 *
165 * Return the address of the allocated buffer and update @buflen with
166 * the size of the allocated buffer.
167 */
sd_zbc_alloc_report_buffer(struct scsi_disk * sdkp,unsigned int nr_zones,size_t * buflen)168 static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
169 unsigned int nr_zones, size_t *buflen)
170 {
171 struct request_queue *q = sdkp->disk->queue;
172 unsigned int max_segments;
173 size_t bufsize;
174 void *buf;
175
176 /*
177 * Report zone buffer size should be at most 64B times the number of
178 * zones requested plus the 64B reply header, but should be aligned
179 * to SECTOR_SIZE for ATA devices.
180 * Make sure that this size does not exceed the hardware capabilities.
181 * Furthermore, since the report zone command cannot be split, make
182 * sure that the allocated buffer can always be mapped by limiting the
183 * number of pages allocated to the HBA max segments limit.
184 * Since max segments can be larger than the max inline bio vectors,
185 * further limit the allocated buffer to BIO_MAX_INLINE_VECS.
186 */
187 nr_zones = min(nr_zones, sdkp->zone_info.nr_zones);
188 bufsize = roundup((nr_zones + 1) * 64, SECTOR_SIZE);
189 bufsize = min_t(size_t, bufsize,
190 queue_max_hw_sectors(q) << SECTOR_SHIFT);
191 max_segments = min(BIO_MAX_INLINE_VECS, queue_max_segments(q));
192 bufsize = min_t(size_t, bufsize, max_segments << PAGE_SHIFT);
193
194 while (bufsize >= SECTOR_SIZE) {
195 buf = kvzalloc(bufsize, GFP_KERNEL | __GFP_NORETRY);
196 if (buf) {
197 *buflen = bufsize;
198 return buf;
199 }
200 bufsize = rounddown(bufsize >> 1, SECTOR_SIZE);
201 }
202
203 return NULL;
204 }
205
206 /**
207 * sd_zbc_zone_sectors - Get the device zone size in number of 512B sectors.
208 * @sdkp: The target disk
209 */
sd_zbc_zone_sectors(struct scsi_disk * sdkp)210 static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp)
211 {
212 return logical_to_sectors(sdkp->device, sdkp->zone_info.zone_blocks);
213 }
214
215 /**
216 * sd_zbc_report_zones - SCSI .report_zones() callback.
217 * @disk: Disk to report zones for.
218 * @sector: Start sector.
219 * @nr_zones: Maximum number of zones to report.
220 * @cb: Callback function called to report zone information.
221 * @data: Second argument passed to @cb.
222 *
223 * Called by the block layer to iterate over zone information. See also the
224 * disk->fops->report_zones() calls in block/blk-zoned.c.
225 */
sd_zbc_report_zones(struct gendisk * disk,sector_t sector,unsigned int nr_zones,report_zones_cb cb,void * data)226 int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
227 unsigned int nr_zones, report_zones_cb cb, void *data)
228 {
229 struct scsi_disk *sdkp = scsi_disk(disk);
230 sector_t lba = sectors_to_logical(sdkp->device, sector);
231 unsigned int nr, i;
232 unsigned char *buf;
233 u64 zone_length, start_lba;
234 size_t offset, buflen = 0;
235 int zone_idx = 0;
236 int ret;
237
238 if (sdkp->device->type != TYPE_ZBC)
239 /* Not a zoned device */
240 return -EOPNOTSUPP;
241
242 if (!sdkp->capacity)
243 /* Device gone or invalid */
244 return -ENODEV;
245
246 buf = sd_zbc_alloc_report_buffer(sdkp, nr_zones, &buflen);
247 if (!buf)
248 return -ENOMEM;
249
250 while (zone_idx < nr_zones && lba < sdkp->capacity) {
251 ret = sd_zbc_do_report_zones(sdkp, buf, buflen, lba, true);
252 if (ret)
253 goto out;
254
255 offset = 0;
256 nr = min(nr_zones, get_unaligned_be32(&buf[0]) / 64);
257 if (!nr)
258 break;
259
260 for (i = 0; i < nr && zone_idx < nr_zones; i++) {
261 offset += 64;
262 start_lba = get_unaligned_be64(&buf[offset + 16]);
263 zone_length = get_unaligned_be64(&buf[offset + 8]);
264 if ((zone_idx == 0 &&
265 (lba < start_lba ||
266 lba >= start_lba + zone_length)) ||
267 (zone_idx > 0 && start_lba != lba) ||
268 start_lba + zone_length < start_lba) {
269 sd_printk(KERN_ERR, sdkp,
270 "Zone %d at LBA %llu is invalid: %llu + %llu\n",
271 zone_idx, lba, start_lba, zone_length);
272 ret = -EINVAL;
273 goto out;
274 }
275 lba = start_lba + zone_length;
276 if (sd_zbc_is_gap_zone(&buf[offset])) {
277 if (sdkp->zone_starting_lba_gran)
278 continue;
279 sd_printk(KERN_ERR, sdkp,
280 "Gap zone without constant LBA offsets\n");
281 ret = -EINVAL;
282 goto out;
283 }
284
285 ret = sd_zbc_parse_report(sdkp, buf + offset, zone_idx,
286 cb, data);
287 if (ret)
288 goto out;
289
290 zone_idx++;
291 }
292 }
293
294 ret = zone_idx;
295 out:
296 kvfree(buf);
297 return ret;
298 }
299
sd_zbc_cmnd_checks(struct scsi_cmnd * cmd)300 static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd)
301 {
302 struct request *rq = scsi_cmd_to_rq(cmd);
303 struct scsi_disk *sdkp = scsi_disk(rq->q->disk);
304 sector_t sector = blk_rq_pos(rq);
305
306 if (sdkp->device->type != TYPE_ZBC)
307 /* Not a zoned device */
308 return BLK_STS_IOERR;
309
310 if (sdkp->device->changed)
311 return BLK_STS_IOERR;
312
313 if (sector & (sd_zbc_zone_sectors(sdkp) - 1))
314 /* Unaligned request */
315 return BLK_STS_IOERR;
316
317 return BLK_STS_OK;
318 }
319
320 /**
321 * sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations
322 * can be RESET WRITE POINTER, OPEN, CLOSE or FINISH.
323 * @cmd: the command to setup
324 * @op: Operation to be performed
325 * @all: All zones control
326 *
327 * Called from sd_init_command() for REQ_OP_ZONE_RESET, REQ_OP_ZONE_RESET_ALL,
328 * REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE or REQ_OP_ZONE_FINISH requests.
329 */
sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd * cmd,unsigned char op,bool all)330 blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
331 unsigned char op, bool all)
332 {
333 struct request *rq = scsi_cmd_to_rq(cmd);
334 sector_t sector = blk_rq_pos(rq);
335 struct scsi_disk *sdkp = scsi_disk(rq->q->disk);
336 sector_t block = sectors_to_logical(sdkp->device, sector);
337 blk_status_t ret;
338
339 ret = sd_zbc_cmnd_checks(cmd);
340 if (ret != BLK_STS_OK)
341 return ret;
342
343 cmd->cmd_len = 16;
344 memset(cmd->cmnd, 0, cmd->cmd_len);
345 cmd->cmnd[0] = ZBC_OUT;
346 cmd->cmnd[1] = op;
347 if (all)
348 cmd->cmnd[14] = 0x1;
349 else
350 put_unaligned_be64(block, &cmd->cmnd[2]);
351
352 rq->timeout = SD_TIMEOUT;
353 cmd->sc_data_direction = DMA_NONE;
354 cmd->transfersize = 0;
355 cmd->allowed = 0;
356
357 return BLK_STS_OK;
358 }
359
360 /**
361 * sd_zbc_complete - ZBC command post processing.
362 * @cmd: Completed command
363 * @good_bytes: Command reply bytes
364 * @sshdr: command sense header
365 *
366 * Called from sd_done() to handle zone commands errors and updates to the
367 * device queue zone write pointer offset cahce.
368 */
sd_zbc_complete(struct scsi_cmnd * cmd,unsigned int good_bytes,struct scsi_sense_hdr * sshdr)369 unsigned int sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
370 struct scsi_sense_hdr *sshdr)
371 {
372 int result = cmd->result;
373 struct request *rq = scsi_cmd_to_rq(cmd);
374
375 if (op_is_zone_mgmt(req_op(rq)) &&
376 result &&
377 sshdr->sense_key == ILLEGAL_REQUEST &&
378 sshdr->asc == 0x24) {
379 /*
380 * INVALID FIELD IN CDB error: a zone management command was
381 * attempted on a conventional zone. Nothing to worry about,
382 * so be quiet about the error.
383 */
384 rq->rq_flags |= RQF_QUIET;
385 }
386
387 return good_bytes;
388 }
389
390 /**
391 * sd_zbc_check_zoned_characteristics - Check zoned block device characteristics
392 * @sdkp: Target disk
393 * @buf: Buffer where to store the VPD page data
394 *
395 * Read VPD page B6, get information and check that reads are unconstrained.
396 */
sd_zbc_check_zoned_characteristics(struct scsi_disk * sdkp,unsigned char * buf)397 static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp,
398 unsigned char *buf)
399 {
400 u64 zone_starting_lba_gran;
401
402 if (scsi_get_vpd_page(sdkp->device, 0xb6, buf, 64)) {
403 sd_printk(KERN_NOTICE, sdkp,
404 "Read zoned characteristics VPD page failed\n");
405 return -ENODEV;
406 }
407
408 if (sdkp->device->type != TYPE_ZBC) {
409 /* Host-aware */
410 sdkp->urswrz = 1;
411 sdkp->zones_optimal_open = get_unaligned_be32(&buf[8]);
412 sdkp->zones_optimal_nonseq = get_unaligned_be32(&buf[12]);
413 sdkp->zones_max_open = 0;
414 return 0;
415 }
416
417 /* Host-managed */
418 sdkp->urswrz = buf[4] & 1;
419 sdkp->zones_optimal_open = 0;
420 sdkp->zones_optimal_nonseq = 0;
421 sdkp->zones_max_open = get_unaligned_be32(&buf[16]);
422 /* Check zone alignment method */
423 switch (buf[23] & 0xf) {
424 case 0:
425 case ZBC_CONSTANT_ZONE_LENGTH:
426 /* Use zone length */
427 break;
428 case ZBC_CONSTANT_ZONE_START_OFFSET:
429 zone_starting_lba_gran = get_unaligned_be64(&buf[24]);
430 if (zone_starting_lba_gran == 0 ||
431 !is_power_of_2(zone_starting_lba_gran) ||
432 logical_to_sectors(sdkp->device, zone_starting_lba_gran) >
433 UINT_MAX) {
434 sd_printk(KERN_ERR, sdkp,
435 "Invalid zone starting LBA granularity %llu\n",
436 zone_starting_lba_gran);
437 return -ENODEV;
438 }
439 sdkp->zone_starting_lba_gran = zone_starting_lba_gran;
440 break;
441 default:
442 sd_printk(KERN_ERR, sdkp, "Invalid zone alignment method\n");
443 return -ENODEV;
444 }
445
446 /*
447 * Check for unconstrained reads: host-managed devices with
448 * constrained reads (drives failing read after write pointer)
449 * are not supported.
450 */
451 if (!sdkp->urswrz) {
452 if (sdkp->first_scan)
453 sd_printk(KERN_NOTICE, sdkp,
454 "constrained reads devices are not supported\n");
455 return -ENODEV;
456 }
457
458 return 0;
459 }
460
461 /**
462 * sd_zbc_check_capacity - Check the device capacity
463 * @sdkp: Target disk
464 * @buf: command buffer
465 * @zblocks: zone size in logical blocks
466 *
467 * Get the device zone size and check that the device capacity as reported
468 * by READ CAPACITY matches the max_lba value (plus one) of the report zones
469 * command reply for devices with RC_BASIS == 0.
470 *
471 * Returns 0 upon success or an error code upon failure.
472 */
sd_zbc_check_capacity(struct scsi_disk * sdkp,unsigned char * buf,u32 * zblocks)473 static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
474 u32 *zblocks)
475 {
476 u64 zone_blocks;
477 sector_t max_lba;
478 unsigned char *rec;
479 int ret;
480
481 /* Do a report zone to get max_lba and the size of the first zone */
482 ret = sd_zbc_do_report_zones(sdkp, buf, SD_BUF_SIZE, 0, false);
483 if (ret)
484 return ret;
485
486 if (sdkp->rc_basis == 0) {
487 /* The max_lba field is the capacity of this device */
488 max_lba = get_unaligned_be64(&buf[8]);
489 if (sdkp->capacity != max_lba + 1) {
490 if (sdkp->first_scan)
491 sd_printk(KERN_WARNING, sdkp,
492 "Changing capacity from %llu to max LBA+1 %llu\n",
493 (unsigned long long)sdkp->capacity,
494 (unsigned long long)max_lba + 1);
495 sdkp->capacity = max_lba + 1;
496 }
497 }
498
499 if (sdkp->zone_starting_lba_gran == 0) {
500 /* Get the size of the first reported zone */
501 rec = buf + 64;
502 zone_blocks = get_unaligned_be64(&rec[8]);
503 if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
504 if (sdkp->first_scan)
505 sd_printk(KERN_NOTICE, sdkp,
506 "Zone size too large\n");
507 return -EFBIG;
508 }
509 } else {
510 zone_blocks = sdkp->zone_starting_lba_gran;
511 }
512
513 if (!is_power_of_2(zone_blocks)) {
514 sd_printk(KERN_ERR, sdkp,
515 "Zone size %llu is not a power of two.\n",
516 zone_blocks);
517 return -EINVAL;
518 }
519
520 *zblocks = zone_blocks;
521
522 return 0;
523 }
524
sd_zbc_print_zones(struct scsi_disk * sdkp)525 static void sd_zbc_print_zones(struct scsi_disk *sdkp)
526 {
527 if (sdkp->device->type != TYPE_ZBC || !sdkp->capacity)
528 return;
529
530 if (sdkp->capacity & (sdkp->zone_info.zone_blocks - 1))
531 sd_printk(KERN_NOTICE, sdkp,
532 "%u zones of %u logical blocks + 1 runt zone\n",
533 sdkp->zone_info.nr_zones - 1,
534 sdkp->zone_info.zone_blocks);
535 else
536 sd_printk(KERN_NOTICE, sdkp,
537 "%u zones of %u logical blocks\n",
538 sdkp->zone_info.nr_zones,
539 sdkp->zone_info.zone_blocks);
540 }
541
542 /*
543 * Call blk_revalidate_disk_zones() if any of the zoned disk properties have
544 * changed that make it necessary to call that function. Called by
545 * sd_revalidate_disk() after the gendisk capacity has been set.
546 */
sd_zbc_revalidate_zones(struct scsi_disk * sdkp)547 int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
548 {
549 struct gendisk *disk = sdkp->disk;
550 struct request_queue *q = disk->queue;
551 u32 zone_blocks = sdkp->early_zone_info.zone_blocks;
552 unsigned int nr_zones = sdkp->early_zone_info.nr_zones;
553 unsigned int flags;
554 int ret;
555
556 /*
557 * There is nothing to do for regular disks, including host-aware disks
558 * that have partitions.
559 */
560 if (!blk_queue_is_zoned(q))
561 return 0;
562
563 if (sdkp->zone_info.zone_blocks == zone_blocks &&
564 sdkp->zone_info.nr_zones == nr_zones &&
565 disk->nr_zones == nr_zones)
566 return 0;
567
568 sdkp->zone_info.zone_blocks = zone_blocks;
569 sdkp->zone_info.nr_zones = nr_zones;
570
571 flags = memalloc_noio_save();
572 ret = blk_revalidate_disk_zones(disk);
573 memalloc_noio_restore(flags);
574 if (ret) {
575 sdkp->zone_info = (struct zoned_disk_info){ };
576 sdkp->capacity = 0;
577 return ret;
578 }
579
580 sd_zbc_print_zones(sdkp);
581
582 return 0;
583 }
584
585 /**
586 * sd_zbc_read_zones - Read zone information and update the request queue
587 * @sdkp: SCSI disk pointer.
588 * @lim: queue limits to read into
589 * @buf: 512 byte buffer used for storing SCSI command output.
590 *
591 * Read zone information and update the request queue zone characteristics and
592 * also the zoned device information in *sdkp. Called by sd_revalidate_disk()
593 * before the gendisk capacity has been set.
594 */
sd_zbc_read_zones(struct scsi_disk * sdkp,struct queue_limits * lim,u8 buf[SD_BUF_SIZE])595 int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
596 u8 buf[SD_BUF_SIZE])
597 {
598 unsigned int nr_zones;
599 u32 zone_blocks = 0;
600 int ret;
601
602 if (sdkp->device->type != TYPE_ZBC)
603 return 0;
604
605 lim->features |= BLK_FEAT_ZONED;
606
607 /*
608 * Per ZBC and ZAC specifications, writes in sequential write required
609 * zones of host-managed devices must be aligned to the device physical
610 * block size.
611 */
612 lim->zone_write_granularity = sdkp->physical_block_size;
613
614 /* READ16/WRITE16/SYNC16 is mandatory for ZBC devices */
615 sdkp->device->use_16_for_rw = 1;
616 sdkp->device->use_10_for_rw = 0;
617 sdkp->device->use_16_for_sync = 1;
618
619 /* Check zoned block device characteristics (unconstrained reads) */
620 ret = sd_zbc_check_zoned_characteristics(sdkp, buf);
621 if (ret)
622 goto err;
623
624 /* Check the device capacity reported by report zones */
625 ret = sd_zbc_check_capacity(sdkp, buf, &zone_blocks);
626 if (ret != 0)
627 goto err;
628
629 nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
630 sdkp->early_zone_info.nr_zones = nr_zones;
631 sdkp->early_zone_info.zone_blocks = zone_blocks;
632
633 /* The drive satisfies the kernel restrictions: set it up */
634 if (sdkp->zones_max_open == U32_MAX)
635 lim->max_open_zones = 0;
636 else
637 lim->max_open_zones = sdkp->zones_max_open;
638 lim->max_active_zones = 0;
639 lim->chunk_sectors = logical_to_sectors(sdkp->device, zone_blocks);
640
641 return 0;
642
643 err:
644 sdkp->capacity = 0;
645
646 return ret;
647 }
648