Lines Matching +full:lbp +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-only
10 * - Drew Eckhardt <drew@colorado.edu> original
11 * - Eric Youngdale <eric@andante.org> add scatter-gather, multiple
13 * Support loadable low-level scsi drivers.
14 * - Jirka Hanika <geo@ff.cuni.cz> support more scsi disks using
16 * - Richard Gooch <rgooch@atnf.csiro.au> support devfs.
17 * - Torben Mathiasen <tmm@image.dk> Resource allocation fixes in
19 * - Alex Davis <letmein@erols.com> Fix problem where partition info
22 * - Douglas Gilbert <dgilbert@interlog.com> cleanup for lk 2.5.x
23 * - Badari Pulavarty <pbadari@us.ibm.com>, Matthew Wilcox
28 * - setting up transfer: SCSI_LOG_HLQUEUE levels 1 and 2
29 * - end of transfer (bh + scsi_lib): SCSI_LOG_HLCOMPLETE level 1
30 * - entering sd_ioctl: SCSI_LOG_IOCTL level 1
31 * - entering other commands: SCSI_LOG_HLQUEUE level 3
48 #include <linux/blk-pm.h>
54 #include <linux/sed-opal.h>
57 #include <linux/t10-pi.h>
137 if (sdkp->WCE) { in sd_set_flush_flag()
139 if (sdkp->DPOFUA) in sd_set_flush_flag()
143 blk_queue_write_cache(sdkp->disk->queue, wc, fua); in sd_set_flush_flag()
152 struct scsi_device *sdp = sdkp->device; in cache_type_store()
160 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in cache_type_store()
164 return -EINVAL; in cache_type_store()
166 if (strncmp(buf, temp, sizeof(temp) - 1) == 0) { in cache_type_store()
167 buf += sizeof(temp) - 1; in cache_type_store()
168 sdkp->cache_override = 1; in cache_type_store()
170 sdkp->cache_override = 0; in cache_type_store()
175 return -EINVAL; in cache_type_store()
178 wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0; in cache_type_store()
180 if (sdkp->cache_override) { in cache_type_store()
181 sdkp->WCE = wce; in cache_type_store()
182 sdkp->RCD = rcd; in cache_type_store()
188 sdkp->max_retries, &data, NULL)) in cache_type_store()
189 return -EINVAL; in cache_type_store()
190 len = min_t(size_t, sizeof(buffer), data.length - data.header_length - in cache_type_store()
206 sdkp->max_retries, &data, &sshdr)) { in cache_type_store()
209 return -EINVAL; in cache_type_store()
211 sd_revalidate_disk(sdkp->disk); in cache_type_store()
220 struct scsi_device *sdp = sdkp->device; in manage_start_stop_show()
222 return sprintf(buf, "%u\n", sdp->manage_start_stop); in manage_start_stop_show()
230 struct scsi_device *sdp = sdkp->device; in manage_start_stop_store()
234 return -EACCES; in manage_start_stop_store()
237 return -EINVAL; in manage_start_stop_store()
239 sdp->manage_start_stop = v; in manage_start_stop_store()
250 return sprintf(buf, "%u\n", sdkp->device->allow_restart); in allow_restart_show()
259 struct scsi_device *sdp = sdkp->device; in allow_restart_store()
262 return -EACCES; in allow_restart_store()
264 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in allow_restart_store()
265 return -EINVAL; in allow_restart_store()
268 return -EINVAL; in allow_restart_store()
270 sdp->allow_restart = v; in allow_restart_store()
280 int ct = sdkp->RCD + 2*sdkp->WCE; in cache_type_show()
291 return sprintf(buf, "%u\n", sdkp->DPOFUA); in FUA_show()
301 return sprintf(buf, "%u\n", sdkp->protection_type); in protection_type_show()
313 return -EACCES; in protection_type_store()
321 sdkp->protection_type = val; in protection_type_store()
332 struct scsi_device *sdp = sdkp->device; in protection_mode_show()
335 dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type); in protection_mode_show()
336 dix = scsi_host_dix_capable(sdp->host, sdkp->protection_type); in protection_mode_show()
338 if (!dix && scsi_host_dix_capable(sdp->host, T10_PI_TYPE0_PROTECTION)) { in protection_mode_show()
355 return sprintf(buf, "%u\n", sdkp->ATO); in app_tag_own_show()
365 return sprintf(buf, "%u\n", sdkp->lbpme); in thin_provisioning_show()
385 return sprintf(buf, "%s\n", lbp_mode[sdkp->provisioning_mode]); in provisioning_mode_show()
393 struct scsi_device *sdp = sdkp->device; in provisioning_mode_store()
397 return -EACCES; in provisioning_mode_store()
404 if (sdp->type != TYPE_DISK) in provisioning_mode_store()
405 return -EINVAL; in provisioning_mode_store()
409 return -EINVAL; in provisioning_mode_store()
431 return sprintf(buf, "%s\n", zeroing_mode[sdkp->zeroing_mode]); in zeroing_mode_show()
442 return -EACCES; in zeroing_mode_store()
446 return -EINVAL; in zeroing_mode_store()
448 sdkp->zeroing_mode = mode; in zeroing_mode_store()
460 return sprintf(buf, "%u\n", sdkp->max_medium_access_timeouts); in max_medium_access_timeouts_show()
472 return -EACCES; in max_medium_access_timeouts_store()
474 err = kstrtouint(buf, 10, &sdkp->max_medium_access_timeouts); in max_medium_access_timeouts_store()
486 return sprintf(buf, "%u\n", sdkp->max_ws_blocks); in max_write_same_blocks_show()
494 struct scsi_device *sdp = sdkp->device; in max_write_same_blocks_store()
499 return -EACCES; in max_write_same_blocks_store()
501 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in max_write_same_blocks_store()
502 return -EINVAL; in max_write_same_blocks_store()
510 sdp->no_write_same = 1; in max_write_same_blocks_store()
512 sdp->no_write_same = 0; in max_write_same_blocks_store()
513 sdkp->max_ws_blocks = max; in max_write_same_blocks_store()
527 if (sdkp->device->type == TYPE_ZBC) in zoned_cap_show()
528 return sprintf(buf, "host-managed\n"); in zoned_cap_show()
529 if (sdkp->zoned == 1) in zoned_cap_show()
530 return sprintf(buf, "host-aware\n"); in zoned_cap_show()
531 if (sdkp->zoned == 2) in zoned_cap_show()
532 return sprintf(buf, "drive-managed\n"); in zoned_cap_show()
542 struct scsi_device *sdev = sdkp->device; in max_retries_store()
550 sdkp->max_retries = retries; in max_retries_store()
554 sdev_printk(KERN_ERR, sdev, "max_retries must be between -1 and %d\n", in max_retries_store()
556 return -EINVAL; in max_retries_store()
565 return sprintf(buf, "%d\n", sdkp->max_retries); in max_retries_show()
635 * |............|.............|....|....| <- dev_t
638 * Inside a major, we have 16k disks, however mapped non-
643 * the well-know SCSI majors 8, 65--71, 136--143.
651 return SCSI_DISK1_MAJOR + major_idx - 1; in sd_major()
653 return SCSI_DISK8_MAJOR + major_idx - 8; in sd_major()
665 struct scsi_device *sdev = sdkp->device; in sd_sec_submit()
675 buffer, len, NULL, NULL, SD_TIMEOUT, sdkp->max_retries, 0, in sd_sec_submit()
677 return ret <= 0 ? ret : -EIO; in sd_sec_submit()
747 struct bio *bio = rq->bio; in sd_setup_protect_cmnd()
753 scmd->prot_flags |= SCSI_PROT_IP_CHECKSUM; in sd_setup_protect_cmnd()
756 scmd->prot_flags |= SCSI_PROT_GUARD_CHECK; in sd_setup_protect_cmnd()
760 scmd->prot_flags |= SCSI_PROT_REF_INCREMENT; in sd_setup_protect_cmnd()
763 scmd->prot_flags |= SCSI_PROT_REF_CHECK; in sd_setup_protect_cmnd()
767 scmd->prot_flags |= SCSI_PROT_TRANSFER_PI; in sd_setup_protect_cmnd()
772 protect = 1 << 5; /* Enable target PI checking */ in sd_setup_protect_cmnd()
777 scmd->prot_flags &= sd_prot_flag_mask(prot_op); in sd_setup_protect_cmnd()
784 struct request_queue *q = sdkp->disk->queue; in sd_config_discard()
785 unsigned int logical_block_size = sdkp->device->sector_size; in sd_config_discard()
788 q->limits.discard_alignment = in sd_config_discard()
789 sdkp->unmap_alignment * logical_block_size; in sd_config_discard()
790 q->limits.discard_granularity = in sd_config_discard()
791 max(sdkp->physical_block_size, in sd_config_discard()
792 sdkp->unmap_granularity * logical_block_size); in sd_config_discard()
793 sdkp->provisioning_mode = mode; in sd_config_discard()
803 max_blocks = min_not_zero(sdkp->max_unmap_blocks, in sd_config_discard()
808 if (sdkp->device->unmap_limit_for_ws) in sd_config_discard()
809 max_blocks = sdkp->max_unmap_blocks; in sd_config_discard()
811 max_blocks = sdkp->max_ws_blocks; in sd_config_discard()
817 if (sdkp->device->unmap_limit_for_ws) in sd_config_discard()
818 max_blocks = sdkp->max_unmap_blocks; in sd_config_discard()
820 max_blocks = sdkp->max_ws_blocks; in sd_config_discard()
826 max_blocks = min_not_zero(sdkp->max_ws_blocks, in sd_config_discard()
836 struct scsi_device *sdp = cmd->device; in sd_setup_unmap_cmnd()
838 struct scsi_disk *sdkp = scsi_disk(rq->q->disk); in sd_setup_unmap_cmnd()
844 rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); in sd_setup_unmap_cmnd()
845 if (!rq->special_vec.bv_page) in sd_setup_unmap_cmnd()
847 clear_highpage(rq->special_vec.bv_page); in sd_setup_unmap_cmnd()
848 rq->special_vec.bv_offset = 0; in sd_setup_unmap_cmnd()
849 rq->special_vec.bv_len = data_len; in sd_setup_unmap_cmnd()
850 rq->rq_flags |= RQF_SPECIAL_PAYLOAD; in sd_setup_unmap_cmnd()
852 cmd->cmd_len = 10; in sd_setup_unmap_cmnd()
853 cmd->cmnd[0] = UNMAP; in sd_setup_unmap_cmnd()
854 cmd->cmnd[8] = 24; in sd_setup_unmap_cmnd()
856 buf = bvec_virt(&rq->special_vec); in sd_setup_unmap_cmnd()
862 cmd->allowed = sdkp->max_retries; in sd_setup_unmap_cmnd()
863 cmd->transfersize = data_len; in sd_setup_unmap_cmnd()
864 rq->timeout = SD_TIMEOUT; in sd_setup_unmap_cmnd()
872 struct scsi_device *sdp = cmd->device; in sd_setup_write_same16_cmnd()
874 struct scsi_disk *sdkp = scsi_disk(rq->q->disk); in sd_setup_write_same16_cmnd()
877 u32 data_len = sdp->sector_size; in sd_setup_write_same16_cmnd()
879 rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); in sd_setup_write_same16_cmnd()
880 if (!rq->special_vec.bv_page) in sd_setup_write_same16_cmnd()
882 clear_highpage(rq->special_vec.bv_page); in sd_setup_write_same16_cmnd()
883 rq->special_vec.bv_offset = 0; in sd_setup_write_same16_cmnd()
884 rq->special_vec.bv_len = data_len; in sd_setup_write_same16_cmnd()
885 rq->rq_flags |= RQF_SPECIAL_PAYLOAD; in sd_setup_write_same16_cmnd()
887 cmd->cmd_len = 16; in sd_setup_write_same16_cmnd()
888 cmd->cmnd[0] = WRITE_SAME_16; in sd_setup_write_same16_cmnd()
890 cmd->cmnd[1] = 0x8; /* UNMAP */ in sd_setup_write_same16_cmnd()
891 put_unaligned_be64(lba, &cmd->cmnd[2]); in sd_setup_write_same16_cmnd()
892 put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); in sd_setup_write_same16_cmnd()
894 cmd->allowed = sdkp->max_retries; in sd_setup_write_same16_cmnd()
895 cmd->transfersize = data_len; in sd_setup_write_same16_cmnd()
896 rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; in sd_setup_write_same16_cmnd()
904 struct scsi_device *sdp = cmd->device; in sd_setup_write_same10_cmnd()
906 struct scsi_disk *sdkp = scsi_disk(rq->q->disk); in sd_setup_write_same10_cmnd()
909 u32 data_len = sdp->sector_size; in sd_setup_write_same10_cmnd()
911 rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); in sd_setup_write_same10_cmnd()
912 if (!rq->special_vec.bv_page) in sd_setup_write_same10_cmnd()
914 clear_highpage(rq->special_vec.bv_page); in sd_setup_write_same10_cmnd()
915 rq->special_vec.bv_offset = 0; in sd_setup_write_same10_cmnd()
916 rq->special_vec.bv_len = data_len; in sd_setup_write_same10_cmnd()
917 rq->rq_flags |= RQF_SPECIAL_PAYLOAD; in sd_setup_write_same10_cmnd()
919 cmd->cmd_len = 10; in sd_setup_write_same10_cmnd()
920 cmd->cmnd[0] = WRITE_SAME; in sd_setup_write_same10_cmnd()
922 cmd->cmnd[1] = 0x8; /* UNMAP */ in sd_setup_write_same10_cmnd()
923 put_unaligned_be32(lba, &cmd->cmnd[2]); in sd_setup_write_same10_cmnd()
924 put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); in sd_setup_write_same10_cmnd()
926 cmd->allowed = sdkp->max_retries; in sd_setup_write_same10_cmnd()
927 cmd->transfersize = data_len; in sd_setup_write_same10_cmnd()
928 rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; in sd_setup_write_same10_cmnd()
936 struct scsi_device *sdp = cmd->device; in sd_setup_write_zeroes_cmnd()
937 struct scsi_disk *sdkp = scsi_disk(rq->q->disk); in sd_setup_write_zeroes_cmnd()
941 if (!(rq->cmd_flags & REQ_NOUNMAP)) { in sd_setup_write_zeroes_cmnd()
942 switch (sdkp->zeroing_mode) { in sd_setup_write_zeroes_cmnd()
950 if (sdp->no_write_same) { in sd_setup_write_zeroes_cmnd()
951 rq->rq_flags |= RQF_QUIET; in sd_setup_write_zeroes_cmnd()
955 if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) in sd_setup_write_zeroes_cmnd()
963 struct request_queue *q = sdkp->disk->queue; in sd_config_write_same()
964 unsigned int logical_block_size = sdkp->device->sector_size; in sd_config_write_same()
966 if (sdkp->device->no_write_same) { in sd_config_write_same()
967 sdkp->max_ws_blocks = 0; in sd_config_write_same()
976 if (sdkp->max_ws_blocks > SD_MAX_WS10_BLOCKS) in sd_config_write_same()
977 sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks, in sd_config_write_same()
979 else if (sdkp->ws16 || sdkp->ws10 || sdkp->device->no_report_opcodes) in sd_config_write_same()
980 sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks, in sd_config_write_same()
983 sdkp->device->no_write_same = 1; in sd_config_write_same()
984 sdkp->max_ws_blocks = 0; in sd_config_write_same()
987 if (sdkp->lbprz && sdkp->lbpws) in sd_config_write_same()
988 sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP; in sd_config_write_same()
989 else if (sdkp->lbprz && sdkp->lbpws10) in sd_config_write_same()
990 sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP; in sd_config_write_same()
991 else if (sdkp->max_ws_blocks) in sd_config_write_same()
992 sdkp->zeroing_mode = SD_ZERO_WS; in sd_config_write_same()
994 sdkp->zeroing_mode = SD_ZERO_WRITE; in sd_config_write_same()
996 if (sdkp->max_ws_blocks && in sd_config_write_same()
997 sdkp->physical_block_size > logical_block_size) { in sd_config_write_same()
1008 * host-managed ZBC disks. in sd_config_write_same()
1010 sdkp->max_ws_blocks = in sd_config_write_same()
1011 round_down(sdkp->max_ws_blocks, in sd_config_write_same()
1012 bytes_to_logical(sdkp->device, in sd_config_write_same()
1013 sdkp->physical_block_size)); in sd_config_write_same()
1017 blk_queue_max_write_zeroes_sectors(q, sdkp->max_ws_blocks * in sd_config_write_same()
1024 struct scsi_disk *sdkp = scsi_disk(rq->q->disk); in sd_setup_flush_cmnd()
1027 memset(&cmd->sdb, 0, sizeof(cmd->sdb)); in sd_setup_flush_cmnd()
1029 cmd->cmnd[0] = SYNCHRONIZE_CACHE; in sd_setup_flush_cmnd()
1030 cmd->cmd_len = 10; in sd_setup_flush_cmnd()
1031 cmd->transfersize = 0; in sd_setup_flush_cmnd()
1032 cmd->allowed = sdkp->max_retries; in sd_setup_flush_cmnd()
1034 rq->timeout = rq->q->rq_timeout * SD_FLUSH_TIMEOUT_MULTIPLIER; in sd_setup_flush_cmnd()
1042 cmd->cmd_len = SD_EXT_CDB_SIZE; in sd_setup_rw32_cmnd()
1043 cmd->cmnd[0] = VARIABLE_LENGTH_CMD; in sd_setup_rw32_cmnd()
1044 cmd->cmnd[7] = 0x18; /* Additional CDB len */ in sd_setup_rw32_cmnd()
1045 cmd->cmnd[9] = write ? WRITE_32 : READ_32; in sd_setup_rw32_cmnd()
1046 cmd->cmnd[10] = flags; in sd_setup_rw32_cmnd()
1047 put_unaligned_be64(lba, &cmd->cmnd[12]); in sd_setup_rw32_cmnd()
1048 put_unaligned_be32(lba, &cmd->cmnd[20]); /* Expected Indirect LBA */ in sd_setup_rw32_cmnd()
1049 put_unaligned_be32(nr_blocks, &cmd->cmnd[28]); in sd_setup_rw32_cmnd()
1058 cmd->cmd_len = 16; in sd_setup_rw16_cmnd()
1059 cmd->cmnd[0] = write ? WRITE_16 : READ_16; in sd_setup_rw16_cmnd()
1060 cmd->cmnd[1] = flags; in sd_setup_rw16_cmnd()
1061 cmd->cmnd[14] = 0; in sd_setup_rw16_cmnd()
1062 cmd->cmnd[15] = 0; in sd_setup_rw16_cmnd()
1063 put_unaligned_be64(lba, &cmd->cmnd[2]); in sd_setup_rw16_cmnd()
1064 put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); in sd_setup_rw16_cmnd()
1073 cmd->cmd_len = 10; in sd_setup_rw10_cmnd()
1074 cmd->cmnd[0] = write ? WRITE_10 : READ_10; in sd_setup_rw10_cmnd()
1075 cmd->cmnd[1] = flags; in sd_setup_rw10_cmnd()
1076 cmd->cmnd[6] = 0; in sd_setup_rw10_cmnd()
1077 cmd->cmnd[9] = 0; in sd_setup_rw10_cmnd()
1078 put_unaligned_be32(lba, &cmd->cmnd[2]); in sd_setup_rw10_cmnd()
1079 put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); in sd_setup_rw10_cmnd()
1102 cmd->cmd_len = 6; in sd_setup_rw6_cmnd()
1103 cmd->cmnd[0] = write ? WRITE_6 : READ_6; in sd_setup_rw6_cmnd()
1104 cmd->cmnd[1] = (lba >> 16) & 0x1f; in sd_setup_rw6_cmnd()
1105 cmd->cmnd[2] = (lba >> 8) & 0xff; in sd_setup_rw6_cmnd()
1106 cmd->cmnd[3] = lba & 0xff; in sd_setup_rw6_cmnd()
1107 cmd->cmnd[4] = nr_blocks; in sd_setup_rw6_cmnd()
1108 cmd->cmnd[5] = 0; in sd_setup_rw6_cmnd()
1116 struct scsi_device *sdp = cmd->device; in sd_setup_read_write_cmnd()
1117 struct scsi_disk *sdkp = scsi_disk(rq->q->disk); in sd_setup_read_write_cmnd()
1121 unsigned int mask = logical_to_sectors(sdp, 1) - 1; in sd_setup_read_write_cmnd()
1133 if (!scsi_device_online(sdp) || sdp->changed) { in sd_setup_read_write_cmnd()
1138 if (blk_rq_pos(rq) + blk_rq_sectors(rq) > get_capacity(rq->q->disk)) { in sd_setup_read_write_cmnd()
1152 threshold = sdkp->capacity - SD_LAST_BUGGY_SECTORS; in sd_setup_read_write_cmnd()
1154 if (unlikely(sdp->last_sector_bug && lba + nr_blocks > threshold)) { in sd_setup_read_write_cmnd()
1157 nr_blocks = threshold - lba; in sd_setup_read_write_cmnd()
1170 fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; in sd_setup_read_write_cmnd()
1172 dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); in sd_setup_read_write_cmnd()
1179 if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { in sd_setup_read_write_cmnd()
1182 } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { in sd_setup_read_write_cmnd()
1186 sdp->use_10_for_rw || protect) { in sd_setup_read_write_cmnd()
1202 cmd->transfersize = sdp->sector_size; in sd_setup_read_write_cmnd()
1203 cmd->underflow = nr_blocks << 9; in sd_setup_read_write_cmnd()
1204 cmd->allowed = sdkp->max_retries; in sd_setup_read_write_cmnd()
1205 cmd->sdb.length = nr_blocks * sdp->sector_size; in sd_setup_read_write_cmnd()
1233 switch (scsi_disk(rq->q->disk)->provisioning_mode) { in sd_init_command()
1275 if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) in sd_uninit_command()
1276 mempool_free(rq->special_vec.bv_page, sd_page_pool); in sd_uninit_command()
1282 if (sdkp->device->removable || sdkp->write_prot) { in sd_need_revalidate()
1292 return test_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state); in sd_need_revalidate()
1296 * sd_open - open a scsi disk device
1308 * Locking: called with bdev->bd_disk->open_mutex held.
1312 struct scsi_disk *sdkp = scsi_disk(bdev->bd_disk); in sd_open()
1313 struct scsi_device *sdev = sdkp->device; in sd_open()
1317 return -ENXIO; in sd_open()
1325 retval = -ENXIO; in sd_open()
1330 sd_revalidate_disk(bdev->bd_disk); in sd_open()
1335 retval = -ENOMEDIUM; in sd_open()
1336 if (sdev->removable && !sdkp->media_present && !(mode & FMODE_NDELAY)) in sd_open()
1343 retval = -EROFS; in sd_open()
1344 if (sdkp->write_prot && (mode & FMODE_WRITE)) in sd_open()
1353 retval = -ENXIO; in sd_open()
1357 if ((atomic_inc_return(&sdkp->openers) == 1) && sdev->removable) { in sd_open()
1370 * sd_release - invoked when the (last) close(2) is called on this
1380 * Locking: called with bdev->bd_disk->open_mutex held.
1385 struct scsi_device *sdev = sdkp->device; in sd_release()
1389 if (atomic_dec_return(&sdkp->openers) == 0 && sdev->removable) { in sd_release()
1399 struct scsi_disk *sdkp = scsi_disk(bdev->bd_disk); in sd_getgeo()
1400 struct scsi_device *sdp = sdkp->device; in sd_getgeo()
1401 struct Scsi_Host *host = sdp->host; in sd_getgeo()
1402 sector_t capacity = logical_to_sectors(sdp, sdkp->capacity); in sd_getgeo()
1411 if (host->hostt->bios_param) in sd_getgeo()
1412 host->hostt->bios_param(sdp, bdev, capacity, diskinfo); in sd_getgeo()
1416 geo->heads = diskinfo[0]; in sd_getgeo()
1417 geo->sectors = diskinfo[1]; in sd_getgeo()
1418 geo->cylinders = diskinfo[2]; in sd_getgeo()
1423 * sd_ioctl - process an ioctl
1439 struct gendisk *disk = bdev->bd_disk; in sd_ioctl()
1441 struct scsi_device *sdp = sdkp->device; in sd_ioctl()
1446 "cmd=0x%x\n", disk->disk_name, cmd)); in sd_ioctl()
1449 return -ENOIOCTLCMD; in sd_ioctl()
1463 return sed_ioctl(sdkp->opal_dev, cmd, p); in sd_ioctl()
1469 if (sdkp->media_present) in set_media_not_present()
1470 sdkp->device->changed = 1; in set_media_not_present()
1472 if (sdkp->device->removable) { in set_media_not_present()
1473 sdkp->media_present = 0; in set_media_not_present()
1474 sdkp->capacity = 0; in set_media_not_present()
1485 switch (sshdr->sense_key) { in media_not_present()
1489 if (sshdr->asc == 0x3A) { in media_not_present()
1498 * sd_check_events - check media events
1508 struct scsi_disk *sdkp = disk->private_data; in sd_check_events()
1516 sdp = sdkp->device; in sd_check_events()
1520 * If the device is offline, don't send any commands - just pretend as in sd_check_events()
1532 * no cartridge loaded - NOT READY, drive with changed cartridge - in sd_check_events()
1533 * UNIT ATTENTION, or with same cartridge - GOOD STATUS. in sd_check_events()
1542 retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, sdkp->max_retries, in sd_check_events()
1559 if (!sdkp->media_present) in sd_check_events()
1560 sdp->changed = 1; in sd_check_events()
1561 sdkp->media_present = 1; in sd_check_events()
1564 * sdp->changed is set under the following conditions: in sd_check_events()
1569 disk_changed = sdp->changed; in sd_check_events()
1570 sdp->changed = 0; in sd_check_events()
1577 struct scsi_device *sdp = sdkp->device; in sd_sync_cache()
1578 const int timeout = sdp->request_queue->rq_timeout in sd_sync_cache()
1583 return -ENODEV; in sd_sync_cache()
1589 for (retries = 3; retries > 0; --retries) { in sd_sync_cache()
1598 timeout, sdkp->max_retries, 0, RQF_PM, NULL); in sd_sync_cache()
1614 if (sshdr->asc == 0x3a || /* medium not present */ in sd_sync_cache()
1615 sshdr->asc == 0x20 || /* invalid command */ in sd_sync_cache()
1616 (sshdr->asc == 0x74 && sshdr->ascq == 0x71)) /* drive is password locked */ in sd_sync_cache()
1631 return -EBUSY; in sd_sync_cache()
1633 return -EIO; in sd_sync_cache()
1643 sd_revalidate_disk(sdkp->disk); in sd_rescan()
1649 struct scsi_device *sdev = scsi_disk(disk)->device; in sd_get_unique_id()
1652 int ret = -ENXIO, len; in sd_get_unique_id()
1655 vpd = rcu_dereference(sdev->vpd_pg83); in sd_get_unique_id()
1659 ret = -EINVAL; in sd_get_unique_id()
1660 for (d = vpd->data + 4; d < vpd->data + vpd->len; d += d[3] + 4) { in sd_get_unique_id()
1668 * Only exit early if a 16-byte descriptor was found. Otherwise in sd_get_unique_id()
1707 struct scsi_disk *sdkp = scsi_disk(bdev->bd_disk); in sd_pr_command()
1708 struct scsi_device *sdev = sdkp->device; in sd_pr_command()
1724 &sshdr, SD_TIMEOUT, sdkp->max_retries, NULL); in sd_pr_command()
1739 return -EOPNOTSUPP; in sd_pr_register()
1749 return -EOPNOTSUPP; in sd_pr_reserve()
1782 put_device(&sdkp->disk_dev); in scsi_disk_free_disk()
1801 * sd_eh_reset - reset error handling callback
1802 * @scmd: sd-issued command that has failed
1814 struct scsi_disk *sdkp = scsi_disk(scsi_cmd_to_rq(scmd)->q->disk); in sd_eh_reset()
1817 sdkp->ignore_medium_access_errors = false; in sd_eh_reset()
1821 * sd_eh_action - error handling callback
1822 * @scmd: sd-issued command that has failed
1834 struct scsi_disk *sdkp = scsi_disk(scsi_cmd_to_rq(scmd)->q->disk); in sd_eh_action()
1835 struct scsi_device *sdev = scmd->device; in sd_eh_action()
1839 host_byte(scmd->result) != DID_TIME_OUT || in sd_eh_action()
1850 if (!sdkp->ignore_medium_access_errors) { in sd_eh_action()
1851 sdkp->medium_access_timed_out++; in sd_eh_action()
1852 sdkp->ignore_medium_access_errors = true; in sd_eh_action()
1860 if (sdkp->medium_access_timed_out >= sdkp->max_medium_access_timeouts) { in sd_eh_action()
1863 mutex_lock(&sdev->state_mutex); in sd_eh_action()
1865 mutex_unlock(&sdev->state_mutex); in sd_eh_action()
1876 struct scsi_device *sdev = scmd->device; in sd_completed_bytes()
1884 if (scsi_bufflen(scmd) <= sdev->sector_size) in sd_completed_bytes()
1888 if (!scsi_get_sense_info_fld(scmd->sense_buffer, in sd_completed_bytes()
1906 transferred = scsi_bufflen(scmd) - scsi_get_resid(scmd); in sd_completed_bytes()
1911 good_bytes = logical_to_bytes(sdev, bad_lba - start_lba); in sd_completed_bytes()
1917 * sd_done - bottom half handler: called when the lower level
1919 * @SCpnt: mid-level's per command structure.
1925 int result = SCpnt->result; in sd_done()
1927 unsigned int sector_size = SCpnt->device->sector_size; in sd_done()
1931 struct scsi_disk *sdkp = scsi_disk(req->q->disk); in sd_done()
1958 if (resid & (sector_size - 1)) { in sd_done()
1974 sdkp->medium_access_timed_out = 0; in sd_done()
1993 SCpnt->result = 0; in sd_done()
1994 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in sd_done()
2007 switch (SCpnt->cmnd[0]) { in sd_done()
2013 if (SCpnt->cmnd[1] & 8) { /* UNMAP */ in sd_done()
2016 sdkp->device->no_write_same = 1; in sd_done()
2018 req->rq_flags |= RQF_QUIET; in sd_done()
2040 * spinup disk - called only in sd_revalidate_disk()
2060 bool media_was_present = sdkp->media_present; in sd_spinup_disk()
2065 the_result = scsi_execute_req(sdkp->device, cmd, in sd_spinup_disk()
2068 sdkp->max_retries, NULL); in sd_spinup_disk()
2102 if (sdkp->device->no_start_on_add) in sd_spinup_disk()
2123 if (sdkp->device->start_stop_pwr_cond) in sd_spinup_disk()
2125 scsi_execute_req(sdkp->device, cmd, DMA_NONE, in sd_spinup_disk()
2127 SD_TIMEOUT, sdkp->max_retries, in sd_spinup_disk()
2175 struct scsi_device *sdp = sdkp->device; in sd_read_protection_type()
2179 sdkp->protection_type = 0; in sd_read_protection_type()
2189 sdkp->protection_type = 0; in sd_read_protection_type()
2190 return -ENODEV; in sd_read_protection_type()
2193 sdkp->protection_type = type; in sd_read_protection_type()
2200 struct scsi_device *sdp = sdkp->device; in sd_config_protection()
2202 if (!sdkp->first_scan) in sd_config_protection()
2207 if (!sdkp->protection_type) in sd_config_protection()
2210 if (!scsi_host_dif_capable(sdp->host, sdkp->protection_type)) { in sd_config_protection()
2213 sdkp->protection_type); in sd_config_protection()
2214 sdkp->protection_type = 0; in sd_config_protection()
2218 sdkp->protection_type); in sd_config_protection()
2231 * Set dirty bit for removable devices if not ready - in read_capacity_error()
2234 if (sdp->removable && in read_capacity_error()
2235 sense_valid && sshdr->sense_key == NOT_READY) in read_capacity_error()
2243 sdkp->capacity = 0; /* unknown mapped to zero - as usual */ in read_capacity_error()
2265 if (sdp->no_read_capacity_16) in read_capacity_16()
2266 return -EINVAL; in read_capacity_16()
2277 SD_TIMEOUT, sdkp->max_retries, NULL); in read_capacity_16()
2280 return -ENODEV; in read_capacity_16()
2291 return -EINVAL; in read_capacity_16()
2297 if (--reset_retries > 0) in read_capacity_16()
2300 retries--; in read_capacity_16()
2307 return -EINVAL; in read_capacity_16()
2314 sdkp->capacity = 0; in read_capacity_16()
2315 return -ENODEV; in read_capacity_16()
2319 sdkp->physical_block_size = (1 << (buffer[13] & 0xf)) * sector_size; in read_capacity_16()
2322 sdkp->rc_basis = (buffer[12] >> 4) & 0x3; in read_capacity_16()
2326 blk_queue_alignment_offset(sdp->request_queue, alignment); in read_capacity_16()
2327 if (alignment && sdkp->first_scan) in read_capacity_16()
2332 sdkp->lbpme = 1; in read_capacity_16()
2335 sdkp->lbprz = 1; in read_capacity_16()
2340 sdkp->capacity = lba + 1; in read_capacity_16()
2362 SD_TIMEOUT, sdkp->max_retries, NULL); in read_capacity_10()
2365 return -ENODEV; in read_capacity_10()
2374 if (--reset_retries > 0) in read_capacity_10()
2377 retries--; in read_capacity_10()
2384 return -EINVAL; in read_capacity_10()
2390 if (sdp->no_read_capacity_16 && (lba == 0xffffffff)) { in read_capacity_10()
2394 sdkp->capacity = 0; in read_capacity_10()
2395 sdkp->physical_block_size = sector_size; in read_capacity_10()
2399 sdkp->capacity = lba + 1; in read_capacity_10()
2400 sdkp->physical_block_size = sector_size; in read_capacity_10()
2406 if (sdp->host->max_cmd_len < 16) in sd_try_rc16_first()
2408 if (sdp->try_rc_10_first) in sd_try_rc16_first()
2410 if (sdp->scsi_level > SCSI_SPC_2) in sd_try_rc16_first()
2424 struct scsi_device *sdp = sdkp->device; in sd_read_capacity()
2428 if (sector_size == -EOVERFLOW) in sd_read_capacity()
2430 if (sector_size == -ENODEV) in sd_read_capacity()
2438 if (sector_size == -EOVERFLOW) in sd_read_capacity()
2442 if ((sizeof(sdkp->capacity) > 4) && in sd_read_capacity()
2443 (sdkp->capacity > 0xffffffffULL)) { in sd_read_capacity()
2451 sdkp->capacity = 1 + (sector_t) 0xffffffff; in sd_read_capacity()
2456 sdp->try_rc_10_first = 0; in sd_read_capacity()
2470 if (sdp->fix_capacity || in sd_read_capacity()
2471 (sdp->guess_capacity && (sdkp->capacity & 0x01))) { in sd_read_capacity()
2474 (unsigned long long) sdkp->capacity); in sd_read_capacity()
2475 --sdkp->capacity; in sd_read_capacity()
2492 * The user might want to re-format the drive with in sd_read_capacity()
2497 sdkp->capacity = 0; in sd_read_capacity()
2506 blk_queue_logical_block_size(sdp->request_queue, sector_size); in sd_read_capacity()
2507 blk_queue_physical_block_size(sdp->request_queue, in sd_read_capacity()
2508 sdkp->physical_block_size); in sd_read_capacity()
2509 sdkp->device->sector_size = sector_size; in sd_read_capacity()
2511 if (sdkp->capacity > 0xffffffff) in sd_read_capacity()
2512 sdp->use_16_for_rw = 1; in sd_read_capacity()
2523 int sector_size = sdkp->device->sector_size; in sd_print_capacity()
2526 if (!sdkp->first_scan && old_capacity == sdkp->capacity) in sd_print_capacity()
2529 string_get_size(sdkp->capacity, sector_size, in sd_print_capacity()
2531 string_get_size(sdkp->capacity, sector_size, in sd_print_capacity()
2535 "%llu %d-byte logical blocks: (%s/%s)\n", in sd_print_capacity()
2536 (unsigned long long)sdkp->capacity, in sd_print_capacity()
2539 if (sdkp->physical_block_size != sector_size) in sd_print_capacity()
2541 "%u-byte physical blocks\n", in sd_print_capacity()
2542 sdkp->physical_block_size); in sd_print_capacity()
2555 if (sdkp->device->use_10_for_ms && len < 8) in sd_do_mode_sense()
2558 return scsi_mode_sense(sdkp->device, dbd, modepage, buffer, len, in sd_do_mode_sense()
2559 SD_TIMEOUT, sdkp->max_retries, data, in sd_do_mode_sense()
2564 * read write protect setting, if possible - called only in sd_revalidate_disk()
2571 struct scsi_device *sdp = sdkp->device; in sd_read_write_protect_flag()
2573 int old_wp = sdkp->write_prot; in sd_read_write_protect_flag()
2575 set_disk_ro(sdkp->disk, 0); in sd_read_write_protect_flag()
2576 if (sdp->skip_ms_page_3f) { in sd_read_write_protect_flag()
2581 if (sdp->use_192_bytes_for_3f) { in sd_read_write_protect_flag()
2612 sdkp->write_prot = ((data.device_specific & 0x80) != 0); in sd_read_write_protect_flag()
2613 set_disk_ro(sdkp->disk, sdkp->write_prot); in sd_read_write_protect_flag()
2614 if (sdkp->first_scan || old_wp != sdkp->write_prot) { in sd_read_write_protect_flag()
2616 sdkp->write_prot ? "on" : "off"); in sd_read_write_protect_flag()
2623 * sd_read_cache_type - called only from sd_revalidate_disk()
2630 struct scsi_device *sdp = sdkp->device; in sd_read_cache_type()
2637 int old_wce = sdkp->WCE; in sd_read_cache_type()
2638 int old_rcd = sdkp->RCD; in sd_read_cache_type()
2639 int old_dpofua = sdkp->DPOFUA; in sd_read_cache_type()
2642 if (sdkp->cache_override) in sd_read_cache_type()
2646 if (sdp->skip_ms_page_8) { in sd_read_cache_type()
2647 if (sdp->type == TYPE_RBC) in sd_read_cache_type()
2650 if (sdp->skip_ms_page_3f) in sd_read_cache_type()
2653 if (sdp->use_192_bytes_for_3f) in sd_read_cache_type()
2657 } else if (sdp->type == TYPE_RBC) { in sd_read_cache_type()
2693 if (modepage == 0x3F && sdp->use_192_bytes_for_3f) in sd_read_cache_type()
2711 if (len - offset <= 2) { in sd_read_cache_type()
2722 if (spf && len - offset > 3) in sd_read_cache_type()
2725 else if (!spf && len - offset > 1) in sd_read_cache_type()
2742 sdkp->WCE = ((buffer[offset + 2] & 0x04) != 0); in sd_read_cache_type()
2743 sdkp->RCD = ((buffer[offset + 2] & 0x01) != 0); in sd_read_cache_type()
2745 sdkp->WCE = ((buffer[offset + 2] & 0x01) == 0); in sd_read_cache_type()
2746 sdkp->RCD = 0; in sd_read_cache_type()
2749 sdkp->DPOFUA = (data.device_specific & 0x10) != 0; in sd_read_cache_type()
2750 if (sdp->broken_fua) { in sd_read_cache_type()
2752 sdkp->DPOFUA = 0; in sd_read_cache_type()
2753 } else if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw && in sd_read_cache_type()
2754 !sdkp->device->use_16_for_rw) { in sd_read_cache_type()
2757 sdkp->DPOFUA = 0; in sd_read_cache_type()
2761 if (sdkp->WCE && sdkp->write_prot) in sd_read_cache_type()
2762 sdkp->WCE = 0; in sd_read_cache_type()
2764 if (sdkp->first_scan || old_wce != sdkp->WCE || in sd_read_cache_type()
2765 old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA) in sd_read_cache_type()
2768 sdkp->WCE ? "enabled" : "disabled", in sd_read_cache_type()
2769 sdkp->RCD ? "disabled" : "enabled", in sd_read_cache_type()
2770 sdkp->DPOFUA ? "supports DPO and FUA" in sd_read_cache_type()
2787 if (sdp->wce_default_on) { in sd_read_cache_type()
2790 sdkp->WCE = 1; in sd_read_cache_type()
2794 sdkp->WCE = 0; in sd_read_cache_type()
2796 sdkp->RCD = 0; in sd_read_cache_type()
2797 sdkp->DPOFUA = 0; in sd_read_cache_type()
2807 struct scsi_device *sdp = sdkp->device; in sd_read_app_tag_own()
2811 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in sd_read_app_tag_own()
2814 if (sdkp->protection_type == 0) in sd_read_app_tag_own()
2818 sdkp->max_retries, &data, &sshdr); in sd_read_app_tag_own()
2841 sdkp->ATO = 1; in sd_read_app_tag_own()
2847 * sd_read_block_limits - Query disk device for preferred I/O sizes.
2856 vpd = rcu_dereference(sdkp->device->vpd_pgb0); in sd_read_block_limits()
2857 if (!vpd || vpd->len < 16) in sd_read_block_limits()
2860 sdkp->min_xfer_blocks = get_unaligned_be16(&vpd->data[6]); in sd_read_block_limits()
2861 sdkp->max_xfer_blocks = get_unaligned_be32(&vpd->data[8]); in sd_read_block_limits()
2862 sdkp->opt_xfer_blocks = get_unaligned_be32(&vpd->data[12]); in sd_read_block_limits()
2864 if (vpd->len >= 64) { in sd_read_block_limits()
2867 sdkp->max_ws_blocks = (u32)get_unaligned_be64(&vpd->data[36]); in sd_read_block_limits()
2869 if (!sdkp->lbpme) in sd_read_block_limits()
2872 lba_count = get_unaligned_be32(&vpd->data[20]); in sd_read_block_limits()
2873 desc_count = get_unaligned_be32(&vpd->data[24]); in sd_read_block_limits()
2876 sdkp->max_unmap_blocks = lba_count; in sd_read_block_limits()
2878 sdkp->unmap_granularity = get_unaligned_be32(&vpd->data[28]); in sd_read_block_limits()
2880 if (vpd->data[32] & 0x80) in sd_read_block_limits()
2881 sdkp->unmap_alignment = in sd_read_block_limits()
2882 get_unaligned_be32(&vpd->data[32]) & ~(1 << 31); in sd_read_block_limits()
2884 if (!sdkp->lbpvpd) { /* LBP VPD page not provided */ in sd_read_block_limits()
2886 if (sdkp->max_unmap_blocks) in sd_read_block_limits()
2891 } else { /* LBP VPD page tells us what to use */ in sd_read_block_limits()
2892 if (sdkp->lbpu && sdkp->max_unmap_blocks) in sd_read_block_limits()
2894 else if (sdkp->lbpws) in sd_read_block_limits()
2896 else if (sdkp->lbpws10) in sd_read_block_limits()
2908 * sd_read_block_characteristics - Query block dev. characteristics
2913 struct request_queue *q = sdkp->disk->queue; in sd_read_block_characteristics()
2919 vpd = rcu_dereference(sdkp->device->vpd_pgb1); in sd_read_block_characteristics()
2921 if (!vpd || vpd->len < 8) { in sd_read_block_characteristics()
2926 rot = get_unaligned_be16(&vpd->data[4]); in sd_read_block_characteristics()
2927 zoned = (vpd->data[8] >> 4) & 3; in sd_read_block_characteristics()
2935 if (sdkp->device->type == TYPE_ZBC) { in sd_read_block_characteristics()
2936 /* Host-managed */ in sd_read_block_characteristics()
2937 disk_set_zoned(sdkp->disk, BLK_ZONED_HM); in sd_read_block_characteristics()
2939 sdkp->zoned = zoned; in sd_read_block_characteristics()
2940 if (sdkp->zoned == 1) { in sd_read_block_characteristics()
2941 /* Host-aware */ in sd_read_block_characteristics()
2942 disk_set_zoned(sdkp->disk, BLK_ZONED_HA); in sd_read_block_characteristics()
2945 disk_set_zoned(sdkp->disk, BLK_ZONED_NONE); in sd_read_block_characteristics()
2949 if (!sdkp->first_scan) in sd_read_block_characteristics()
2953 sd_printk(KERN_NOTICE, sdkp, "Host-%s zoned block device\n", in sd_read_block_characteristics()
2954 q->limits.zoned == BLK_ZONED_HM ? "managed" : "aware"); in sd_read_block_characteristics()
2956 if (sdkp->zoned == 1) in sd_read_block_characteristics()
2958 "Host-aware SMR disk used as regular disk\n"); in sd_read_block_characteristics()
2959 else if (sdkp->zoned == 2) in sd_read_block_characteristics()
2961 "Drive-managed SMR disk\n"); in sd_read_block_characteristics()
2966 * sd_read_block_provisioning - Query provisioning VPD page
2973 if (sdkp->lbpme == 0) in sd_read_block_provisioning()
2977 vpd = rcu_dereference(sdkp->device->vpd_pgb2); in sd_read_block_provisioning()
2979 if (!vpd || vpd->len < 8) { in sd_read_block_provisioning()
2984 sdkp->lbpvpd = 1; in sd_read_block_provisioning()
2985 sdkp->lbpu = (vpd->data[5] >> 7) & 1; /* UNMAP */ in sd_read_block_provisioning()
2986 sdkp->lbpws = (vpd->data[5] >> 6) & 1; /* WRITE SAME(16) w/ UNMAP */ in sd_read_block_provisioning()
2987 sdkp->lbpws10 = (vpd->data[5] >> 5) & 1; /* WRITE SAME(10) w/ UNMAP */ in sd_read_block_provisioning()
2993 struct scsi_device *sdev = sdkp->device; in sd_read_write_same()
2995 if (sdev->host->no_write_same) { in sd_read_write_same()
2996 sdev->no_write_same = 1; in sd_read_write_same()
3004 sdev->no_report_opcodes = 1; in sd_read_write_same()
3011 vpd = rcu_dereference(sdev->vpd_pg89); in sd_read_write_same()
3013 sdev->no_write_same = 1; in sd_read_write_same()
3018 sdkp->ws16 = 1; in sd_read_write_same()
3021 sdkp->ws10 = 1; in sd_read_write_same()
3026 struct scsi_device *sdev = sdkp->device; in sd_read_security()
3028 if (!sdev->security_supported) in sd_read_security()
3035 sdkp->security = 1; in sd_read_security()
3040 return logical_to_sectors(sdkp->device, get_unaligned_be64(buf)); in sd64_to_sectors()
3044 * sd_read_cpr - Query concurrent positioning ranges
3059 if (sdkp->first_scan) in sd_read_cpr()
3062 if (!sdkp->capacity) in sd_read_cpr()
3071 if (!buffer || scsi_get_vpd_page(sdkp->device, 0xb9, buffer, buf_len)) in sd_read_cpr()
3082 nr_cpr = (vpd_len - 64) / 32; in sd_read_cpr()
3088 iars = disk_alloc_independent_access_ranges(sdkp->disk, nr_cpr); in sd_read_cpr()
3103 iars->ia_range[i].sector = sd64_to_sectors(sdkp, desc + 8); in sd_read_cpr()
3104 iars->ia_range[i].nr_sectors = sd64_to_sectors(sdkp, desc + 16); in sd_read_cpr()
3108 disk_set_independent_access_ranges(sdkp->disk, iars); in sd_read_cpr()
3109 if (nr_cpr && sdkp->nr_actuators != nr_cpr) { in sd_read_cpr()
3112 sdkp->nr_actuators = nr_cpr; in sd_read_cpr()
3120 struct scsi_device *sdp = sdkp->device; in sd_validate_min_xfer_size()
3122 logical_to_bytes(sdp, sdkp->min_xfer_blocks); in sd_validate_min_xfer_size()
3124 if (sdkp->min_xfer_blocks == 0) in sd_validate_min_xfer_size()
3127 if (min_xfer_bytes & (sdkp->physical_block_size - 1)) { in sd_validate_min_xfer_size()
3131 min_xfer_bytes, sdkp->physical_block_size); in sd_validate_min_xfer_size()
3132 sdkp->min_xfer_blocks = 0; in sd_validate_min_xfer_size()
3149 struct scsi_device *sdp = sdkp->device; in sd_validate_opt_xfer_size()
3151 logical_to_bytes(sdp, sdkp->opt_xfer_blocks); in sd_validate_opt_xfer_size()
3153 logical_to_bytes(sdp, sdkp->min_xfer_blocks); in sd_validate_opt_xfer_size()
3155 if (sdkp->opt_xfer_blocks == 0) in sd_validate_opt_xfer_size()
3158 if (sdkp->opt_xfer_blocks > dev_max) { in sd_validate_opt_xfer_size()
3162 sdkp->opt_xfer_blocks, dev_max); in sd_validate_opt_xfer_size()
3166 if (sdkp->opt_xfer_blocks > SD_DEF_XFER_BLOCKS) { in sd_validate_opt_xfer_size()
3170 sdkp->opt_xfer_blocks, SD_DEF_XFER_BLOCKS); in sd_validate_opt_xfer_size()
3191 if (opt_xfer_bytes & (sdkp->physical_block_size - 1)) { in sd_validate_opt_xfer_size()
3195 opt_xfer_bytes, sdkp->physical_block_size); in sd_validate_opt_xfer_size()
3205 * sd_revalidate_disk - called the first time a new disk is seen,
3212 struct scsi_device *sdp = sdkp->device; in sd_revalidate_disk()
3213 struct request_queue *q = sdkp->disk->queue; in sd_revalidate_disk()
3214 sector_t old_capacity = sdkp->capacity; in sd_revalidate_disk()
3241 if (sdkp->media_present) { in sd_revalidate_disk()
3245 * set the default to rotational. All non-rotational devices in sd_revalidate_disk()
3278 dev_max = sdp->use_16_for_rw ? SD_MAX_XFER_BLOCKS : SD_DEF_XFER_BLOCKS; in sd_revalidate_disk()
3281 dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks); in sd_revalidate_disk()
3282 q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max); in sd_revalidate_disk()
3285 blk_queue_io_min(sdkp->disk->queue, in sd_revalidate_disk()
3286 logical_to_bytes(sdp, sdkp->min_xfer_blocks)); in sd_revalidate_disk()
3288 blk_queue_io_min(sdkp->disk->queue, 0); in sd_revalidate_disk()
3291 q->limits.io_opt = logical_to_bytes(sdp, sdkp->opt_xfer_blocks); in sd_revalidate_disk()
3292 rw_max = logical_to_sectors(sdp, sdkp->opt_xfer_blocks); in sd_revalidate_disk()
3294 q->limits.io_opt = 0; in sd_revalidate_disk()
3304 rw_max = min_not_zero(rw_max, sdp->host->opt_sectors); in sd_revalidate_disk()
3313 if (sdkp->first_scan || in sd_revalidate_disk()
3314 q->limits.max_sectors > q->limits.max_dev_sectors || in sd_revalidate_disk()
3315 q->limits.max_sectors > q->limits.max_hw_sectors) in sd_revalidate_disk()
3316 q->limits.max_sectors = rw_max; in sd_revalidate_disk()
3318 sdkp->first_scan = 0; in sd_revalidate_disk()
3320 set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity)); in sd_revalidate_disk()
3337 * sd_unlock_native_capacity - unlock native capacity
3342 * implements ->unlock_native_capacity() method, it's invoked to
3350 struct scsi_device *sdev = scsi_disk(disk)->device; in sd_unlock_native_capacity()
3352 if (sdev->host->hostt->unlock_native_capacity) in sd_unlock_native_capacity()
3353 sdev->host->hostt->unlock_native_capacity(sdev); in sd_unlock_native_capacity()
3357 * sd_format_disk_name - format disk name
3358 * @prefix: name prefix - ie. "sd" for SCSI disks
3370 * index shifted -1 after each digit is computed.
3376 * 0 on success, -errno on failure.
3380 const int base = 'z' - 'a' + 1; in sd_format_disk_name()
3386 p = end - 1; in sd_format_disk_name()
3391 return -EINVAL; in sd_format_disk_name()
3392 *--p = 'a' + (index % unit); in sd_format_disk_name()
3393 index = (index / unit) - 1; in sd_format_disk_name()
3396 memmove(begin, p, end - p); in sd_format_disk_name()
3403 * sd_probe - called during driver initialization and whenever a
3411 * Note: this function is invoked from the scsi mid-level.
3417 * Assume sd_probe is not re-entrant (for time being)
3429 error = -ENODEV; in sd_probe()
3430 if (sdp->type != TYPE_DISK && in sd_probe()
3431 sdp->type != TYPE_ZBC && in sd_probe()
3432 sdp->type != TYPE_MOD && in sd_probe()
3433 sdp->type != TYPE_RBC) in sd_probe()
3436 if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) && sdp->type == TYPE_ZBC) { in sd_probe()
3438 "Unsupported ZBC host-managed device.\n"); in sd_probe()
3445 error = -ENOMEM; in sd_probe()
3450 gd = blk_mq_alloc_disk_for_queue(sdp->request_queue, in sd_probe()
3461 error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN); in sd_probe()
3467 sdkp->device = sdp; in sd_probe()
3468 sdkp->disk = gd; in sd_probe()
3469 sdkp->index = index; in sd_probe()
3470 sdkp->max_retries = SD_MAX_RETRIES; in sd_probe()
3471 atomic_set(&sdkp->openers, 0); in sd_probe()
3472 atomic_set(&sdkp->device->ioerr_cnt, 0); in sd_probe()
3474 if (!sdp->request_queue->rq_timeout) { in sd_probe()
3475 if (sdp->type != TYPE_MOD) in sd_probe()
3476 blk_queue_rq_timeout(sdp->request_queue, SD_TIMEOUT); in sd_probe()
3478 blk_queue_rq_timeout(sdp->request_queue, in sd_probe()
3482 device_initialize(&sdkp->disk_dev); in sd_probe()
3483 sdkp->disk_dev.parent = get_device(dev); in sd_probe()
3484 sdkp->disk_dev.class = &sd_disk_class; in sd_probe()
3485 dev_set_name(&sdkp->disk_dev, "%s", dev_name(dev)); in sd_probe()
3487 error = device_add(&sdkp->disk_dev); in sd_probe()
3489 put_device(&sdkp->disk_dev); in sd_probe()
3495 gd->major = sd_major((index & 0xf0) >> 4); in sd_probe()
3496 gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); in sd_probe()
3497 gd->minors = SD_MINORS; in sd_probe()
3499 gd->fops = &sd_fops; in sd_probe()
3500 gd->private_data = sdkp; in sd_probe()
3503 sdp->sector_size = 512; in sd_probe()
3504 sdkp->capacity = 0; in sd_probe()
3505 sdkp->media_present = 1; in sd_probe()
3506 sdkp->write_prot = 0; in sd_probe()
3507 sdkp->cache_override = 0; in sd_probe()
3508 sdkp->WCE = 0; in sd_probe()
3509 sdkp->RCD = 0; in sd_probe()
3510 sdkp->ATO = 0; in sd_probe()
3511 sdkp->first_scan = 1; in sd_probe()
3512 sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; in sd_probe()
3516 if (sdp->removable) { in sd_probe()
3517 gd->flags |= GENHD_FL_REMOVABLE; in sd_probe()
3518 gd->events |= DISK_EVENT_MEDIA_CHANGE; in sd_probe()
3519 gd->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT; in sd_probe()
3522 blk_pm_runtime_init(sdp->request_queue, dev); in sd_probe()
3523 if (sdp->rpm_autosuspend) { in sd_probe()
3525 sdp->host->hostt->rpm_autosuspend_delay); in sd_probe()
3530 put_device(&sdkp->disk_dev); in sd_probe()
3535 if (sdkp->security) { in sd_probe()
3536 sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit); in sd_probe()
3537 if (sdkp->opal_dev) in sd_probe()
3542 sdp->removable ? "removable " : ""); in sd_probe()
3559 * sd_remove - called whenever a scsi disk (previously recognized by
3564 * Note: this function is invoked from the scsi mid-level.
3566 * that could be re-used by a subsequent sd_probe().
3567 * This function is not called when the built-in sd driver is "exit-ed".
3573 scsi_autopm_get_device(sdkp->device); in sd_remove()
3575 device_del(&sdkp->disk_dev); in sd_remove()
3576 del_gendisk(sdkp->disk); in sd_remove()
3579 put_disk(sdkp->disk); in sd_remove()
3587 ida_free(&sd_index_ida, sdkp->index); in scsi_disk_release()
3589 put_device(&sdkp->device->sdev_gendev); in scsi_disk_release()
3590 free_opal_dev(sdkp->opal_dev); in scsi_disk_release()
3599 struct scsi_device *sdp = sdkp->device; in sd_start_stop_device()
3605 if (sdp->start_stop_pwr_cond) in sd_start_stop_device()
3609 return -ENODEV; in sd_start_stop_device()
3612 SD_TIMEOUT, sdkp->max_retries, 0, RQF_PM, NULL); in sd_start_stop_device()
3625 return -EIO; in sd_start_stop_device()
3645 if (sdkp->WCE && sdkp->media_present) { in sd_shutdown()
3650 if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { in sd_shutdown()
3665 if (sdkp->WCE && sdkp->media_present) { in sd_suspend_common()
3666 if (!sdkp->device->silence_suspend) in sd_suspend_common()
3672 if (ret == -ENODEV) in sd_suspend_common()
3688 if (sdkp->device->manage_start_stop) { in sd_suspend_common()
3689 if (!sdkp->device->silence_suspend) in sd_suspend_common()
3721 if (!sdkp->device->manage_start_stop) in sd_resume()
3727 opal_unlock_from_suspend(sdkp->opal_dev); in sd_resume()
3747 sdp = sdkp->device; in sd_resume_runtime()
3749 if (sdp->ignore_media_change) { in sd_resume_runtime()
3754 NULL, sdp->request_queue->rq_timeout, 1, 0, in sd_resume_runtime()
3764 * init_sd - entry point for this driver (both when built in or when
3767 * Note: this function registers this driver with the scsi mid-level.
3782 return -ENODEV; in init_sd()
3792 err = -ENOMEM; in init_sd()
3799 err = -ENOMEM; in init_sd()
3824 * exit_sd - exit point for this driver (when it is a module).
3826 * Note: this function unregisters this driver from the scsi mid-level.
3849 scsi_print_sense_hdr(sdkp->device, in sd_print_sense_hdr()
3850 sdkp->disk ? sdkp->disk->disk_name : NULL, sshdr); in sd_print_sense_hdr()