Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 1 | /* |
| 2 | * SCSI Zoned Block commands |
| 3 | * |
| 4 | * Copyright (C) 2014-2015 SUSE Linux GmbH |
| 5 | * Written by: Hannes Reinecke <hare@suse.de> |
| 6 | * Modified by: Damien Le Moal <damien.lemoal@hgst.com> |
| 7 | * Modified by: Shaun Tancheff <shaun.tancheff@seagate.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License version |
| 11 | * 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; see the file COPYING. If not, write to |
| 20 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, |
| 21 | * USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/blkdev.h> |
| 26 | |
| 27 | #include <asm/unaligned.h> |
| 28 | |
| 29 | #include <scsi/scsi.h> |
| 30 | #include <scsi/scsi_cmnd.h> |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 31 | |
| 32 | #include "sd.h" |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 33 | |
| 34 | /** |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 35 | * sd_zbc_parse_report - Convert a zone descriptor to a struct blk_zone, |
| 36 | * @sdkp: The disk the report originated from |
| 37 | * @buf: Address of the report zone descriptor |
| 38 | * @zone: the destination zone structure |
| 39 | * |
| 40 | * All LBA sized values are converted to 512B sectors unit. |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 41 | */ |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 42 | static void sd_zbc_parse_report(struct scsi_disk *sdkp, u8 *buf, |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 43 | struct blk_zone *zone) |
| 44 | { |
| 45 | struct scsi_device *sdp = sdkp->device; |
| 46 | |
| 47 | memset(zone, 0, sizeof(struct blk_zone)); |
| 48 | |
| 49 | zone->type = buf[0] & 0x0f; |
| 50 | zone->cond = (buf[1] >> 4) & 0xf; |
| 51 | if (buf[1] & 0x01) |
| 52 | zone->reset = 1; |
| 53 | if (buf[1] & 0x02) |
| 54 | zone->non_seq = 1; |
| 55 | |
| 56 | zone->len = logical_to_sectors(sdp, get_unaligned_be64(&buf[8])); |
| 57 | zone->start = logical_to_sectors(sdp, get_unaligned_be64(&buf[16])); |
| 58 | zone->wp = logical_to_sectors(sdp, get_unaligned_be64(&buf[24])); |
| 59 | if (zone->type != ZBC_ZONE_TYPE_CONV && |
| 60 | zone->cond == ZBC_ZONE_COND_FULL) |
| 61 | zone->wp = zone->start + zone->len; |
| 62 | } |
| 63 | |
| 64 | /** |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 65 | * sd_zbc_do_report_zones - Issue a REPORT ZONES scsi command. |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 66 | * @sdkp: The target disk |
| 67 | * @buf: Buffer to use for the reply |
| 68 | * @buflen: the buffer size |
| 69 | * @lba: Start LBA of the report |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 70 | * @partial: Do partial report |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 71 | * |
| 72 | * For internal use during device validation. |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 73 | * Using partial=true can significantly speed up execution of a report zones |
| 74 | * command because the disk does not have to count all possible report matching |
| 75 | * zones and will only report the count of zones fitting in the command reply |
| 76 | * buffer. |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 77 | */ |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 78 | static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf, |
| 79 | unsigned int buflen, sector_t lba, |
| 80 | bool partial) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 81 | { |
| 82 | struct scsi_device *sdp = sdkp->device; |
| 83 | const int timeout = sdp->request_queue->rq_timeout; |
| 84 | struct scsi_sense_hdr sshdr; |
| 85 | unsigned char cmd[16]; |
| 86 | unsigned int rep_len; |
| 87 | int result; |
| 88 | |
| 89 | memset(cmd, 0, 16); |
| 90 | cmd[0] = ZBC_IN; |
| 91 | cmd[1] = ZI_REPORT_ZONES; |
| 92 | put_unaligned_be64(lba, &cmd[2]); |
| 93 | put_unaligned_be32(buflen, &cmd[10]); |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 94 | if (partial) |
| 95 | cmd[14] = ZBC_REPORT_ZONE_PARTIAL; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 96 | memset(buf, 0, buflen); |
| 97 | |
| 98 | result = scsi_execute_req(sdp, cmd, DMA_FROM_DEVICE, |
| 99 | buf, buflen, &sshdr, |
| 100 | timeout, SD_MAX_RETRIES, NULL); |
| 101 | if (result) { |
| 102 | sd_printk(KERN_ERR, sdkp, |
| 103 | "REPORT ZONES lba %llu failed with %d/%d\n", |
| 104 | (unsigned long long)lba, |
| 105 | host_byte(result), driver_byte(result)); |
| 106 | return -EIO; |
| 107 | } |
| 108 | |
| 109 | rep_len = get_unaligned_be32(&buf[0]); |
| 110 | if (rep_len < 64) { |
| 111 | sd_printk(KERN_ERR, sdkp, |
| 112 | "REPORT ZONES report invalid length %u\n", |
| 113 | rep_len); |
| 114 | return -EIO; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 120 | /** |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 121 | * sd_zbc_report_zones - Disk report zones operation. |
| 122 | * @disk: The target disk |
| 123 | * @sector: Start 512B sector of the report |
| 124 | * @zones: Array of zone descriptors |
| 125 | * @nr_zones: Number of descriptors in the array |
| 126 | * @gfp_mask: Memory allocation mask |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 127 | * |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 128 | * Execute a report zones command on the target disk. |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 129 | */ |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 130 | int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, |
| 131 | struct blk_zone *zones, unsigned int *nr_zones, |
| 132 | gfp_t gfp_mask) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 133 | { |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 134 | struct scsi_disk *sdkp = scsi_disk(disk); |
| 135 | unsigned int i, buflen, nrz = *nr_zones; |
| 136 | unsigned char *buf; |
| 137 | size_t offset = 0; |
| 138 | int ret = 0; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 139 | |
| 140 | if (!sd_is_zoned(sdkp)) |
| 141 | /* Not a zoned device */ |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 142 | return -EOPNOTSUPP; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 143 | |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 144 | /* |
| 145 | * Get a reply buffer for the number of requested zones plus a header. |
| 146 | * For ATA, buffers must be aligned to 512B. |
| 147 | */ |
| 148 | buflen = roundup((nrz + 1) * 64, 512); |
| 149 | buf = kmalloc(buflen, gfp_mask); |
| 150 | if (!buf) |
| 151 | return -ENOMEM; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 152 | |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 153 | ret = sd_zbc_do_report_zones(sdkp, buf, buflen, |
| 154 | sectors_to_logical(sdkp->device, sector), true); |
| 155 | if (ret) |
| 156 | goto out_free_buf; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 157 | |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 158 | nrz = min(nrz, get_unaligned_be32(&buf[0]) / 64); |
| 159 | for (i = 0; i < nrz; i++) { |
| 160 | offset += 64; |
| 161 | sd_zbc_parse_report(sdkp, buf + offset, zones); |
| 162 | zones++; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 163 | } |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 164 | |
| 165 | *nr_zones = nrz; |
| 166 | |
| 167 | out_free_buf: |
| 168 | kfree(buf); |
| 169 | |
| 170 | return ret; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 171 | } |
| 172 | |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 173 | /** |
| 174 | * sd_zbc_zone_sectors - Get the device zone size in number of 512B sectors. |
| 175 | * @sdkp: The target disk |
| 176 | */ |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 177 | static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp) |
| 178 | { |
| 179 | return logical_to_sectors(sdkp->device, sdkp->zone_blocks); |
| 180 | } |
| 181 | |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 182 | /** |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 183 | * sd_zbc_setup_reset_cmnd - Prepare a RESET WRITE POINTER scsi command. |
| 184 | * @cmd: the command to setup |
| 185 | * |
| 186 | * Called from sd_init_command() for a REQ_OP_ZONE_RESET request. |
| 187 | */ |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 188 | int sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd) |
| 189 | { |
| 190 | struct request *rq = cmd->request; |
| 191 | struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); |
| 192 | sector_t sector = blk_rq_pos(rq); |
| 193 | sector_t block = sectors_to_logical(sdkp->device, sector); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 194 | |
| 195 | if (!sd_is_zoned(sdkp)) |
| 196 | /* Not a zoned device */ |
| 197 | return BLKPREP_KILL; |
| 198 | |
| 199 | if (sdkp->device->changed) |
| 200 | return BLKPREP_KILL; |
| 201 | |
| 202 | if (sector & (sd_zbc_zone_sectors(sdkp) - 1)) |
| 203 | /* Unaligned request */ |
| 204 | return BLKPREP_KILL; |
| 205 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 206 | cmd->cmd_len = 16; |
| 207 | memset(cmd->cmnd, 0, cmd->cmd_len); |
| 208 | cmd->cmnd[0] = ZBC_OUT; |
| 209 | cmd->cmnd[1] = ZO_RESET_WRITE_POINTER; |
| 210 | put_unaligned_be64(block, &cmd->cmnd[2]); |
| 211 | |
| 212 | rq->timeout = SD_TIMEOUT; |
| 213 | cmd->sc_data_direction = DMA_NONE; |
| 214 | cmd->transfersize = 0; |
| 215 | cmd->allowed = 0; |
| 216 | |
| 217 | return BLKPREP_OK; |
| 218 | } |
| 219 | |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 220 | /** |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 221 | * sd_zbc_complete - ZBC command post processing. |
| 222 | * @cmd: Completed command |
| 223 | * @good_bytes: Command reply bytes |
| 224 | * @sshdr: command sense header |
| 225 | * |
| 226 | * Called from sd_done(). Process report zones reply and handle reset zone |
| 227 | * and write commands errors. |
| 228 | */ |
| 229 | void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes, |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 230 | struct scsi_sense_hdr *sshdr) |
| 231 | { |
| 232 | int result = cmd->result; |
| 233 | struct request *rq = cmd->request; |
| 234 | |
| 235 | switch (req_op(rq)) { |
Damien Le Moal | 868ed5a | 2017-04-24 16:51:15 +0900 | [diff] [blame] | 236 | case REQ_OP_ZONE_RESET: |
| 237 | |
| 238 | if (result && |
| 239 | sshdr->sense_key == ILLEGAL_REQUEST && |
| 240 | sshdr->asc == 0x24) |
| 241 | /* |
| 242 | * INVALID FIELD IN CDB error: reset of a conventional |
| 243 | * zone was attempted. Nothing to worry about, so be |
| 244 | * quiet about the error. |
| 245 | */ |
| 246 | rq->rq_flags |= RQF_QUIET; |
| 247 | break; |
| 248 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 249 | case REQ_OP_WRITE: |
Christoph Hellwig | 02d2610 | 2017-04-05 19:21:02 +0200 | [diff] [blame] | 250 | case REQ_OP_WRITE_ZEROES: |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 251 | case REQ_OP_WRITE_SAME: |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 252 | break; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | /** |
Damien Le Moal | 7f9d35d | 2018-10-12 19:08:40 +0900 | [diff] [blame] | 257 | * sd_zbc_check_zoned_characteristics - Check zoned block device characteristics |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 258 | * @sdkp: Target disk |
| 259 | * @buf: Buffer where to store the VPD page data |
| 260 | * |
Damien Le Moal | 7f9d35d | 2018-10-12 19:08:40 +0900 | [diff] [blame] | 261 | * Read VPD page B6, get information and check that reads are unconstrained. |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 262 | */ |
Damien Le Moal | 7f9d35d | 2018-10-12 19:08:40 +0900 | [diff] [blame] | 263 | static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp, |
| 264 | unsigned char *buf) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 265 | { |
| 266 | |
| 267 | if (scsi_get_vpd_page(sdkp->device, 0xb6, buf, 64)) { |
| 268 | sd_printk(KERN_NOTICE, sdkp, |
Damien Le Moal | 7f9d35d | 2018-10-12 19:08:40 +0900 | [diff] [blame] | 269 | "Read zoned characteristics VPD page failed\n"); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 270 | return -ENODEV; |
| 271 | } |
| 272 | |
| 273 | if (sdkp->device->type != TYPE_ZBC) { |
| 274 | /* Host-aware */ |
| 275 | sdkp->urswrz = 1; |
Damien Le Moal | 4a10903 | 2017-10-11 05:54:25 +0900 | [diff] [blame] | 276 | sdkp->zones_optimal_open = get_unaligned_be32(&buf[8]); |
| 277 | sdkp->zones_optimal_nonseq = get_unaligned_be32(&buf[12]); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 278 | sdkp->zones_max_open = 0; |
| 279 | } else { |
| 280 | /* Host-managed */ |
| 281 | sdkp->urswrz = buf[4] & 1; |
| 282 | sdkp->zones_optimal_open = 0; |
| 283 | sdkp->zones_optimal_nonseq = 0; |
Damien Le Moal | 4a10903 | 2017-10-11 05:54:25 +0900 | [diff] [blame] | 284 | sdkp->zones_max_open = get_unaligned_be32(&buf[16]); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 285 | } |
| 286 | |
Damien Le Moal | 7f9d35d | 2018-10-12 19:08:40 +0900 | [diff] [blame] | 287 | /* |
| 288 | * Check for unconstrained reads: host-managed devices with |
| 289 | * constrained reads (drives failing read after write pointer) |
| 290 | * are not supported. |
| 291 | */ |
| 292 | if (!sdkp->urswrz) { |
| 293 | if (sdkp->first_scan) |
| 294 | sd_printk(KERN_NOTICE, sdkp, |
| 295 | "constrained reads devices are not supported\n"); |
| 296 | return -ENODEV; |
| 297 | } |
| 298 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
Damien Le Moal | e8c77ec | 2017-10-11 05:54:24 +0900 | [diff] [blame] | 302 | #define SD_ZBC_BUF_SIZE 131072U |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 303 | |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 304 | /** |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 305 | * sd_zbc_check_zones - Check the device capacity and zone sizes |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 306 | * @sdkp: Target disk |
| 307 | * |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 308 | * Check that the device capacity as reported by READ CAPACITY matches the |
| 309 | * max_lba value (plus one)of the report zones command reply. Also check that |
| 310 | * all zones of the device have an equal size, only allowing the last zone of |
| 311 | * the disk to have a smaller size (runt zone). The zone size must also be a |
| 312 | * power of two. |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 313 | * |
Damien Le Moal | f13cff6 | 2018-07-03 15:23:58 +0900 | [diff] [blame] | 314 | * Returns the zone size in number of blocks upon success or an error code |
| 315 | * upon failure. |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 316 | */ |
Damien Le Moal | 5f832a3 | 2018-10-12 19:08:42 +0900 | [diff] [blame] | 317 | static int sd_zbc_check_zones(struct scsi_disk *sdkp, u32 *zblocks) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 318 | { |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 319 | u64 zone_blocks = 0; |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 320 | sector_t max_lba, block = 0; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 321 | unsigned char *buf; |
| 322 | unsigned char *rec; |
| 323 | unsigned int buf_len; |
| 324 | unsigned int list_length; |
Damien Le Moal | 5f832a3 | 2018-10-12 19:08:42 +0900 | [diff] [blame] | 325 | int ret; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 326 | u8 same; |
| 327 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 328 | /* Get a buffer */ |
| 329 | buf = kmalloc(SD_ZBC_BUF_SIZE, GFP_KERNEL); |
| 330 | if (!buf) |
| 331 | return -ENOMEM; |
| 332 | |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 333 | /* Do a report zone to get max_lba and the same field */ |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 334 | ret = sd_zbc_do_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0, false); |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 335 | if (ret) |
| 336 | goto out_free; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 337 | |
Damien Le Moal | d2e428e | 2018-10-12 19:08:41 +0900 | [diff] [blame] | 338 | if (sdkp->rc_basis == 0) { |
| 339 | /* The max_lba field is the capacity of this device */ |
| 340 | max_lba = get_unaligned_be64(&buf[8]); |
| 341 | if (sdkp->capacity != max_lba + 1) { |
| 342 | if (sdkp->first_scan) |
| 343 | sd_printk(KERN_WARNING, sdkp, |
| 344 | "Changing capacity from %llu to max LBA+1 %llu\n", |
| 345 | (unsigned long long)sdkp->capacity, |
| 346 | (unsigned long long)max_lba + 1); |
| 347 | sdkp->capacity = max_lba + 1; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /* |
| 352 | * Check same field: for any value other than 0, we know that all zones |
| 353 | * have the same size. |
| 354 | */ |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 355 | same = buf[4] & 0x0f; |
| 356 | if (same > 0) { |
| 357 | rec = &buf[64]; |
| 358 | zone_blocks = get_unaligned_be64(&rec[8]); |
| 359 | goto out; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Check the size of all zones: all zones must be of |
| 364 | * equal size, except the last zone which can be smaller |
| 365 | * than other zones. |
| 366 | */ |
| 367 | do { |
| 368 | |
| 369 | /* Parse REPORT ZONES header */ |
| 370 | list_length = get_unaligned_be32(&buf[0]) + 64; |
| 371 | rec = buf + 64; |
Damien Le Moal | e8c77ec | 2017-10-11 05:54:24 +0900 | [diff] [blame] | 372 | buf_len = min(list_length, SD_ZBC_BUF_SIZE); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 373 | |
| 374 | /* Parse zone descriptors */ |
| 375 | while (rec < buf + buf_len) { |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 376 | u64 this_zone_blocks = get_unaligned_be64(&rec[8]); |
| 377 | |
| 378 | if (zone_blocks == 0) { |
| 379 | zone_blocks = this_zone_blocks; |
| 380 | } else if (this_zone_blocks != zone_blocks && |
| 381 | (block + this_zone_blocks < sdkp->capacity |
| 382 | || this_zone_blocks > zone_blocks)) { |
Damien Le Moal | 3aadbe2 | 2018-05-31 17:42:40 +0900 | [diff] [blame] | 383 | zone_blocks = 0; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 384 | goto out; |
| 385 | } |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 386 | block += this_zone_blocks; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 387 | rec += 64; |
| 388 | } |
| 389 | |
| 390 | if (block < sdkp->capacity) { |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 391 | ret = sd_zbc_do_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, |
| 392 | block, true); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 393 | if (ret) |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 394 | goto out_free; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | } while (block < sdkp->capacity); |
| 398 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 399 | out: |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 400 | if (!zone_blocks) { |
| 401 | if (sdkp->first_scan) |
| 402 | sd_printk(KERN_NOTICE, sdkp, |
| 403 | "Devices with non constant zone " |
| 404 | "size are not supported\n"); |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 405 | ret = -ENODEV; |
| 406 | } else if (!is_power_of_2(zone_blocks)) { |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 407 | if (sdkp->first_scan) |
| 408 | sd_printk(KERN_NOTICE, sdkp, |
| 409 | "Devices with non power of 2 zone " |
| 410 | "size are not supported\n"); |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 411 | ret = -ENODEV; |
| 412 | } else if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) { |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 413 | if (sdkp->first_scan) |
| 414 | sd_printk(KERN_NOTICE, sdkp, |
| 415 | "Zone size too large\n"); |
Damien Le Moal | 5f832a3 | 2018-10-12 19:08:42 +0900 | [diff] [blame] | 416 | ret = -EFBIG; |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 417 | } else { |
Damien Le Moal | 5f832a3 | 2018-10-12 19:08:42 +0900 | [diff] [blame] | 418 | *zblocks = zone_blocks; |
| 419 | ret = 0; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 420 | } |
| 421 | |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 422 | out_free: |
| 423 | kfree(buf); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 424 | |
Damien Le Moal | 4b43392 | 2018-03-02 07:19:28 +0900 | [diff] [blame] | 425 | return ret; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 426 | } |
| 427 | |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 428 | /** |
| 429 | * sd_zbc_alloc_zone_bitmap - Allocate a zone bitmap (one bit per zone). |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 430 | * @nr_zones: Number of zones to allocate space for. |
| 431 | * @numa_node: NUMA node to allocate the memory from. |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 432 | */ |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 433 | static inline unsigned long * |
| 434 | sd_zbc_alloc_zone_bitmap(u32 nr_zones, int numa_node) |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 435 | { |
Kees Cook | 590b5b7 | 2018-06-12 14:04:20 -0700 | [diff] [blame] | 436 | return kcalloc_node(BITS_TO_LONGS(nr_zones), sizeof(unsigned long), |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 437 | GFP_KERNEL, numa_node); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
| 441 | * sd_zbc_get_seq_zones - Parse report zones reply to identify sequential zones |
| 442 | * @sdkp: disk used |
| 443 | * @buf: report reply buffer |
Bart Van Assche | e0b14a4 | 2018-03-01 15:07:19 -0800 | [diff] [blame] | 444 | * @buflen: length of @buf |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 445 | * @zone_shift: logarithm base 2 of the number of blocks in a zone |
Bart Van Assche | e0b14a4 | 2018-03-01 15:07:19 -0800 | [diff] [blame] | 446 | * @seq_zones_bitmap: bitmap of sequential zones to set |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 447 | * |
| 448 | * Parse reported zone descriptors in @buf to identify sequential zones and |
| 449 | * set the reported zone bit in @seq_zones_bitmap accordingly. |
| 450 | * Since read-only and offline zones cannot be written, do not |
| 451 | * mark them as sequential in the bitmap. |
| 452 | * Return the LBA after the last zone reported. |
| 453 | */ |
| 454 | static sector_t sd_zbc_get_seq_zones(struct scsi_disk *sdkp, unsigned char *buf, |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 455 | unsigned int buflen, u32 zone_shift, |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 456 | unsigned long *seq_zones_bitmap) |
| 457 | { |
| 458 | sector_t lba, next_lba = sdkp->capacity; |
| 459 | unsigned int buf_len, list_length; |
| 460 | unsigned char *rec; |
| 461 | u8 type, cond; |
| 462 | |
| 463 | list_length = get_unaligned_be32(&buf[0]) + 64; |
| 464 | buf_len = min(list_length, buflen); |
| 465 | rec = buf + 64; |
| 466 | |
| 467 | while (rec < buf + buf_len) { |
| 468 | type = rec[0] & 0x0f; |
| 469 | cond = (rec[1] >> 4) & 0xf; |
| 470 | lba = get_unaligned_be64(&rec[16]); |
| 471 | if (type != ZBC_ZONE_TYPE_CONV && |
| 472 | cond != ZBC_ZONE_COND_READONLY && |
| 473 | cond != ZBC_ZONE_COND_OFFLINE) |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 474 | set_bit(lba >> zone_shift, seq_zones_bitmap); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 475 | next_lba = lba + get_unaligned_be64(&rec[8]); |
| 476 | rec += 64; |
| 477 | } |
| 478 | |
| 479 | return next_lba; |
| 480 | } |
| 481 | |
| 482 | /** |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 483 | * sd_zbc_setup_seq_zones_bitmap - Initialize a seq zone bitmap. |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 484 | * @sdkp: target disk |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 485 | * @zone_shift: logarithm base 2 of the number of blocks in a zone |
| 486 | * @nr_zones: number of zones to set up a seq zone bitmap for |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 487 | * |
| 488 | * Allocate a zone bitmap and initialize it by identifying sequential zones. |
| 489 | */ |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 490 | static unsigned long * |
| 491 | sd_zbc_setup_seq_zones_bitmap(struct scsi_disk *sdkp, u32 zone_shift, |
| 492 | u32 nr_zones) |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 493 | { |
| 494 | struct request_queue *q = sdkp->disk->queue; |
| 495 | unsigned long *seq_zones_bitmap; |
| 496 | sector_t lba = 0; |
| 497 | unsigned char *buf; |
| 498 | int ret = -ENOMEM; |
| 499 | |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 500 | seq_zones_bitmap = sd_zbc_alloc_zone_bitmap(nr_zones, q->node); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 501 | if (!seq_zones_bitmap) |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 502 | return ERR_PTR(-ENOMEM); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 503 | |
| 504 | buf = kmalloc(SD_ZBC_BUF_SIZE, GFP_KERNEL); |
| 505 | if (!buf) |
| 506 | goto out; |
| 507 | |
| 508 | while (lba < sdkp->capacity) { |
Christoph Hellwig | e76239a | 2018-10-12 19:08:49 +0900 | [diff] [blame^] | 509 | ret = sd_zbc_do_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, lba, |
| 510 | true); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 511 | if (ret) |
| 512 | goto out; |
| 513 | lba = sd_zbc_get_seq_zones(sdkp, buf, SD_ZBC_BUF_SIZE, |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 514 | zone_shift, seq_zones_bitmap); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | if (lba != sdkp->capacity) { |
| 518 | /* Something went wrong */ |
| 519 | ret = -EIO; |
| 520 | } |
| 521 | |
| 522 | out: |
| 523 | kfree(buf); |
| 524 | if (ret) { |
| 525 | kfree(seq_zones_bitmap); |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 526 | return ERR_PTR(ret); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 527 | } |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 528 | return seq_zones_bitmap; |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static void sd_zbc_cleanup(struct scsi_disk *sdkp) |
| 532 | { |
| 533 | struct request_queue *q = sdkp->disk->queue; |
| 534 | |
| 535 | kfree(q->seq_zones_bitmap); |
| 536 | q->seq_zones_bitmap = NULL; |
| 537 | |
| 538 | kfree(q->seq_zones_wlock); |
| 539 | q->seq_zones_wlock = NULL; |
| 540 | |
| 541 | q->nr_zones = 0; |
| 542 | } |
| 543 | |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 544 | static int sd_zbc_setup(struct scsi_disk *sdkp, u32 zone_blocks) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 545 | { |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 546 | struct request_queue *q = sdkp->disk->queue; |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 547 | u32 zone_shift = ilog2(zone_blocks); |
| 548 | u32 nr_zones; |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 549 | int ret; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 550 | |
| 551 | /* chunk_sectors indicates the zone size */ |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 552 | blk_queue_chunk_sectors(q, |
| 553 | logical_to_sectors(sdkp->device, zone_blocks)); |
| 554 | nr_zones = round_up(sdkp->capacity, zone_blocks) >> zone_shift; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 555 | |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 556 | /* |
| 557 | * Initialize the device request queue information if the number |
| 558 | * of zones changed. |
| 559 | */ |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 560 | if (nr_zones != sdkp->nr_zones || nr_zones != q->nr_zones) { |
| 561 | unsigned long *seq_zones_wlock = NULL, *seq_zones_bitmap = NULL; |
| 562 | size_t zone_bitmap_size; |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 563 | |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 564 | if (nr_zones) { |
| 565 | seq_zones_wlock = sd_zbc_alloc_zone_bitmap(nr_zones, |
| 566 | q->node); |
| 567 | if (!seq_zones_wlock) { |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 568 | ret = -ENOMEM; |
| 569 | goto err; |
| 570 | } |
| 571 | |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 572 | seq_zones_bitmap = sd_zbc_setup_seq_zones_bitmap(sdkp, |
| 573 | zone_shift, nr_zones); |
| 574 | if (IS_ERR(seq_zones_bitmap)) { |
| 575 | ret = PTR_ERR(seq_zones_bitmap); |
| 576 | kfree(seq_zones_wlock); |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 577 | goto err; |
| 578 | } |
| 579 | } |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 580 | zone_bitmap_size = BITS_TO_LONGS(nr_zones) * |
| 581 | sizeof(unsigned long); |
| 582 | blk_mq_freeze_queue(q); |
| 583 | if (q->nr_zones != nr_zones) { |
| 584 | /* READ16/WRITE16 is mandatory for ZBC disks */ |
| 585 | sdkp->device->use_16_for_rw = 1; |
| 586 | sdkp->device->use_10_for_rw = 0; |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 587 | |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 588 | sdkp->zone_blocks = zone_blocks; |
| 589 | sdkp->zone_shift = zone_shift; |
| 590 | sdkp->nr_zones = nr_zones; |
| 591 | q->nr_zones = nr_zones; |
| 592 | swap(q->seq_zones_wlock, seq_zones_wlock); |
| 593 | swap(q->seq_zones_bitmap, seq_zones_bitmap); |
| 594 | } else if (memcmp(q->seq_zones_bitmap, seq_zones_bitmap, |
| 595 | zone_bitmap_size) != 0) { |
| 596 | memcpy(q->seq_zones_bitmap, seq_zones_bitmap, |
| 597 | zone_bitmap_size); |
| 598 | } |
| 599 | blk_mq_unfreeze_queue(q); |
| 600 | kfree(seq_zones_wlock); |
| 601 | kfree(seq_zones_bitmap); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | return 0; |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 605 | |
| 606 | err: |
| 607 | sd_zbc_cleanup(sdkp); |
| 608 | return ret; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 609 | } |
| 610 | |
Damien Le Moal | e98f42b | 2017-10-11 05:54:22 +0900 | [diff] [blame] | 611 | int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 612 | { |
Damien Le Moal | 5f832a3 | 2018-10-12 19:08:42 +0900 | [diff] [blame] | 613 | u32 zone_blocks; |
Bart Van Assche | f705324 | 2017-04-24 16:51:14 +0900 | [diff] [blame] | 614 | int ret; |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 615 | |
| 616 | if (!sd_is_zoned(sdkp)) |
| 617 | /* |
| 618 | * Device managed or normal SCSI disk, |
| 619 | * no special handling required |
| 620 | */ |
| 621 | return 0; |
| 622 | |
Damien Le Moal | 7f9d35d | 2018-10-12 19:08:40 +0900 | [diff] [blame] | 623 | /* Check zoned block device characteristics (unconstrained reads) */ |
| 624 | ret = sd_zbc_check_zoned_characteristics(sdkp, buf); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 625 | if (ret) |
| 626 | goto err; |
| 627 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 628 | /* |
| 629 | * Check zone size: only devices with a constant zone size (except |
| 630 | * an eventual last runt zone) that is a power of 2 are supported. |
| 631 | */ |
Damien Le Moal | 5f832a3 | 2018-10-12 19:08:42 +0900 | [diff] [blame] | 632 | ret = sd_zbc_check_zones(sdkp, &zone_blocks); |
| 633 | if (ret != 0) |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 634 | goto err; |
| 635 | |
| 636 | /* The drive satisfies the kernel restrictions: set it up */ |
Bart Van Assche | ccce20f | 2018-04-16 18:04:41 -0700 | [diff] [blame] | 637 | ret = sd_zbc_setup(sdkp, zone_blocks); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 638 | if (ret) |
| 639 | goto err; |
| 640 | |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 641 | return 0; |
| 642 | |
| 643 | err: |
| 644 | sdkp->capacity = 0; |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 645 | sd_zbc_cleanup(sdkp); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 646 | |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | void sd_zbc_remove(struct scsi_disk *sdkp) |
| 651 | { |
Damien Le Moal | 23349ca | 2017-12-21 15:43:43 +0900 | [diff] [blame] | 652 | sd_zbc_cleanup(sdkp); |
Hannes Reinecke | 89d9475 | 2016-10-18 15:40:34 +0900 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | void sd_zbc_print_zones(struct scsi_disk *sdkp) |
| 656 | { |
| 657 | if (!sd_is_zoned(sdkp) || !sdkp->capacity) |
| 658 | return; |
| 659 | |
| 660 | if (sdkp->capacity & (sdkp->zone_blocks - 1)) |
| 661 | sd_printk(KERN_NOTICE, sdkp, |
| 662 | "%u zones of %u logical blocks + 1 runt zone\n", |
| 663 | sdkp->nr_zones - 1, |
| 664 | sdkp->zone_blocks); |
| 665 | else |
| 666 | sd_printk(KERN_NOTICE, sdkp, |
| 667 | "%u zones of %u logical blocks\n", |
| 668 | sdkp->nr_zones, |
| 669 | sdkp->zone_blocks); |
| 670 | } |