Lines Matching +full:usb +full:- +full:sdp

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
49 #include <linux/blk-pm.h>
55 #include <linux/sed-opal.h>
58 #include <linux/t10-pi.h>
128 /* This semaphore is used to mediate the 0->1 reference get in the
146 if (sdkp->WCE) { in sd_set_flush_flag()
148 if (sdkp->DPOFUA) in sd_set_flush_flag()
152 blk_queue_write_cache(sdkp->disk->queue, wc, fua); in sd_set_flush_flag()
161 struct scsi_device *sdp = sdkp->device; in cache_type_store() local
169 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in cache_type_store()
173 return -EINVAL; in cache_type_store()
175 if (strncmp(buf, temp, sizeof(temp) - 1) == 0) { in cache_type_store()
176 buf += sizeof(temp) - 1; in cache_type_store()
177 sdkp->cache_override = 1; in cache_type_store()
179 sdkp->cache_override = 0; in cache_type_store()
184 return -EINVAL; in cache_type_store()
187 wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0; in cache_type_store()
189 if (sdkp->cache_override) { in cache_type_store()
190 sdkp->WCE = wce; in cache_type_store()
191 sdkp->RCD = rcd; in cache_type_store()
196 if (scsi_mode_sense(sdp, 0x08, 8, buffer, sizeof(buffer), SD_TIMEOUT, in cache_type_store()
197 sdkp->max_retries, &data, NULL)) in cache_type_store()
198 return -EINVAL; in cache_type_store()
199 len = min_t(size_t, sizeof(buffer), data.length - data.header_length - in cache_type_store()
214 if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT, in cache_type_store()
215 sdkp->max_retries, &data, &sshdr)) { in cache_type_store()
218 return -EINVAL; in cache_type_store()
220 sd_revalidate_disk(sdkp->disk); in cache_type_store()
229 struct scsi_device *sdp = sdkp->device; in manage_start_stop_show() local
231 return sprintf(buf, "%u\n", sdp->manage_start_stop); in manage_start_stop_show()
239 struct scsi_device *sdp = sdkp->device; in manage_start_stop_store() local
243 return -EACCES; in manage_start_stop_store()
246 return -EINVAL; in manage_start_stop_store()
248 sdp->manage_start_stop = v; in manage_start_stop_store()
259 return sprintf(buf, "%u\n", sdkp->device->allow_restart); in allow_restart_show()
268 struct scsi_device *sdp = sdkp->device; in allow_restart_store() local
271 return -EACCES; in allow_restart_store()
273 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in allow_restart_store()
274 return -EINVAL; in allow_restart_store()
277 return -EINVAL; in allow_restart_store()
279 sdp->allow_restart = v; in allow_restart_store()
289 int ct = sdkp->RCD + 2*sdkp->WCE; in cache_type_show()
300 return sprintf(buf, "%u\n", sdkp->DPOFUA); in FUA_show()
310 return sprintf(buf, "%u\n", sdkp->protection_type); in protection_type_show()
322 return -EACCES; in protection_type_store()
330 sdkp->protection_type = val; in protection_type_store()
341 struct scsi_device *sdp = sdkp->device; in protection_mode_show() local
344 dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type); in protection_mode_show()
345 dix = scsi_host_dix_capable(sdp->host, sdkp->protection_type); in protection_mode_show()
347 if (!dix && scsi_host_dix_capable(sdp->host, T10_PI_TYPE0_PROTECTION)) { in protection_mode_show()
364 return sprintf(buf, "%u\n", sdkp->ATO); in app_tag_own_show()
374 return sprintf(buf, "%u\n", sdkp->lbpme); in thin_provisioning_show()
394 return sprintf(buf, "%s\n", lbp_mode[sdkp->provisioning_mode]); in provisioning_mode_show()
402 struct scsi_device *sdp = sdkp->device; in provisioning_mode_store() local
406 return -EACCES; in provisioning_mode_store()
413 if (sdp->type != TYPE_DISK) in provisioning_mode_store()
414 return -EINVAL; in provisioning_mode_store()
418 return -EINVAL; in provisioning_mode_store()
440 return sprintf(buf, "%s\n", zeroing_mode[sdkp->zeroing_mode]); in zeroing_mode_show()
451 return -EACCES; in zeroing_mode_store()
455 return -EINVAL; in zeroing_mode_store()
457 sdkp->zeroing_mode = mode; in zeroing_mode_store()
469 return sprintf(buf, "%u\n", sdkp->max_medium_access_timeouts); in max_medium_access_timeouts_show()
481 return -EACCES; in max_medium_access_timeouts_store()
483 err = kstrtouint(buf, 10, &sdkp->max_medium_access_timeouts); in max_medium_access_timeouts_store()
495 return sprintf(buf, "%u\n", sdkp->max_ws_blocks); in max_write_same_blocks_show()
503 struct scsi_device *sdp = sdkp->device; in max_write_same_blocks_store() local
508 return -EACCES; in max_write_same_blocks_store()
510 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in max_write_same_blocks_store()
511 return -EINVAL; in max_write_same_blocks_store()
519 sdp->no_write_same = 1; in max_write_same_blocks_store()
521 sdp->no_write_same = 0; in max_write_same_blocks_store()
522 sdkp->max_ws_blocks = max; in max_write_same_blocks_store()
536 if (sdkp->device->type == TYPE_ZBC) in zoned_cap_show()
537 return sprintf(buf, "host-managed\n"); in zoned_cap_show()
538 if (sdkp->zoned == 1) in zoned_cap_show()
539 return sprintf(buf, "host-aware\n"); in zoned_cap_show()
540 if (sdkp->zoned == 2) in zoned_cap_show()
541 return sprintf(buf, "drive-managed\n"); in zoned_cap_show()
551 struct scsi_device *sdev = sdkp->device; in max_retries_store()
559 sdkp->max_retries = retries; in max_retries_store()
563 sdev_printk(KERN_ERR, sdev, "max_retries must be between -1 and %d\n", in max_retries_store()
565 return -EINVAL; in max_retries_store()
574 return sprintf(buf, "%d\n", sdkp->max_retries); in max_retries_show()
633 * Dummy kobj_map->probe function.
634 * The default ->probe function will call modprobe, which is
646 * |............|.............|....|....| <- dev_t
649 * Inside a major, we have 16k disks, however mapped non-
654 * the well-know SCSI majors 8, 65--71, 136--143.
662 return SCSI_DISK1_MAJOR + major_idx - 1; in sd_major()
664 return SCSI_DISK8_MAJOR + major_idx - 8; in sd_major()
677 if (disk->private_data) { in scsi_disk_get()
679 if (scsi_device_get(sdkp->device) == 0) in scsi_disk_get()
680 get_device(&sdkp->dev); in scsi_disk_get()
690 struct scsi_device *sdev = sdkp->device; in scsi_disk_put()
693 put_device(&sdkp->dev); in scsi_disk_put()
703 struct scsi_device *sdev = sdkp->device; in sd_sec_submit()
714 buffer, len, NULL, SD_TIMEOUT, sdkp->max_retries, NULL); in sd_sec_submit()
715 return ret <= 0 ? ret : -EIO; in sd_sec_submit()
784 struct bio *bio = scmd->request->bio; in sd_setup_protect_cmnd()
785 unsigned int prot_op = sd_prot_op(rq_data_dir(scmd->request), dix, dif); in sd_setup_protect_cmnd()
790 scmd->prot_flags |= SCSI_PROT_IP_CHECKSUM; in sd_setup_protect_cmnd()
793 scmd->prot_flags |= SCSI_PROT_GUARD_CHECK; in sd_setup_protect_cmnd()
797 scmd->prot_flags |= SCSI_PROT_REF_INCREMENT; in sd_setup_protect_cmnd()
800 scmd->prot_flags |= SCSI_PROT_REF_CHECK; in sd_setup_protect_cmnd()
804 scmd->prot_flags |= SCSI_PROT_TRANSFER_PI; in sd_setup_protect_cmnd()
814 scmd->prot_flags &= sd_prot_flag_mask(prot_op); in sd_setup_protect_cmnd()
821 struct request_queue *q = sdkp->disk->queue; in sd_config_discard()
822 unsigned int logical_block_size = sdkp->device->sector_size; in sd_config_discard()
825 q->limits.discard_alignment = in sd_config_discard()
826 sdkp->unmap_alignment * logical_block_size; in sd_config_discard()
827 q->limits.discard_granularity = in sd_config_discard()
828 max(sdkp->physical_block_size, in sd_config_discard()
829 sdkp->unmap_granularity * logical_block_size); in sd_config_discard()
830 sdkp->provisioning_mode = mode; in sd_config_discard()
841 max_blocks = min_not_zero(sdkp->max_unmap_blocks, in sd_config_discard()
846 if (sdkp->device->unmap_limit_for_ws) in sd_config_discard()
847 max_blocks = sdkp->max_unmap_blocks; in sd_config_discard()
849 max_blocks = sdkp->max_ws_blocks; in sd_config_discard()
855 if (sdkp->device->unmap_limit_for_ws) in sd_config_discard()
856 max_blocks = sdkp->max_unmap_blocks; in sd_config_discard()
858 max_blocks = sdkp->max_ws_blocks; in sd_config_discard()
864 max_blocks = min_not_zero(sdkp->max_ws_blocks, in sd_config_discard()
875 struct scsi_device *sdp = cmd->device; in sd_setup_unmap_cmnd() local
876 struct request *rq = cmd->request; in sd_setup_unmap_cmnd()
877 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_unmap_cmnd()
878 u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); in sd_setup_unmap_cmnd()
879 u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); in sd_setup_unmap_cmnd()
883 rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); in sd_setup_unmap_cmnd()
884 if (!rq->special_vec.bv_page) in sd_setup_unmap_cmnd()
886 clear_highpage(rq->special_vec.bv_page); in sd_setup_unmap_cmnd()
887 rq->special_vec.bv_offset = 0; in sd_setup_unmap_cmnd()
888 rq->special_vec.bv_len = data_len; in sd_setup_unmap_cmnd()
889 rq->rq_flags |= RQF_SPECIAL_PAYLOAD; in sd_setup_unmap_cmnd()
891 cmd->cmd_len = 10; in sd_setup_unmap_cmnd()
892 cmd->cmnd[0] = UNMAP; in sd_setup_unmap_cmnd()
893 cmd->cmnd[8] = 24; in sd_setup_unmap_cmnd()
895 buf = page_address(rq->special_vec.bv_page); in sd_setup_unmap_cmnd()
901 cmd->allowed = sdkp->max_retries; in sd_setup_unmap_cmnd()
902 cmd->transfersize = data_len; in sd_setup_unmap_cmnd()
903 rq->timeout = SD_TIMEOUT; in sd_setup_unmap_cmnd()
911 struct scsi_device *sdp = cmd->device; in sd_setup_write_same16_cmnd() local
912 struct request *rq = cmd->request; in sd_setup_write_same16_cmnd()
913 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_write_same16_cmnd()
914 u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); in sd_setup_write_same16_cmnd()
915 u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); in sd_setup_write_same16_cmnd()
916 u32 data_len = sdp->sector_size; in sd_setup_write_same16_cmnd()
918 rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); in sd_setup_write_same16_cmnd()
919 if (!rq->special_vec.bv_page) in sd_setup_write_same16_cmnd()
921 clear_highpage(rq->special_vec.bv_page); in sd_setup_write_same16_cmnd()
922 rq->special_vec.bv_offset = 0; in sd_setup_write_same16_cmnd()
923 rq->special_vec.bv_len = data_len; in sd_setup_write_same16_cmnd()
924 rq->rq_flags |= RQF_SPECIAL_PAYLOAD; in sd_setup_write_same16_cmnd()
926 cmd->cmd_len = 16; in sd_setup_write_same16_cmnd()
927 cmd->cmnd[0] = WRITE_SAME_16; in sd_setup_write_same16_cmnd()
929 cmd->cmnd[1] = 0x8; /* UNMAP */ in sd_setup_write_same16_cmnd()
930 put_unaligned_be64(lba, &cmd->cmnd[2]); in sd_setup_write_same16_cmnd()
931 put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); in sd_setup_write_same16_cmnd()
933 cmd->allowed = sdkp->max_retries; in sd_setup_write_same16_cmnd()
934 cmd->transfersize = data_len; in sd_setup_write_same16_cmnd()
935 rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; in sd_setup_write_same16_cmnd()
943 struct scsi_device *sdp = cmd->device; in sd_setup_write_same10_cmnd() local
944 struct request *rq = cmd->request; in sd_setup_write_same10_cmnd()
945 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_write_same10_cmnd()
946 u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); in sd_setup_write_same10_cmnd()
947 u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); in sd_setup_write_same10_cmnd()
948 u32 data_len = sdp->sector_size; in sd_setup_write_same10_cmnd()
950 rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC); in sd_setup_write_same10_cmnd()
951 if (!rq->special_vec.bv_page) in sd_setup_write_same10_cmnd()
953 clear_highpage(rq->special_vec.bv_page); in sd_setup_write_same10_cmnd()
954 rq->special_vec.bv_offset = 0; in sd_setup_write_same10_cmnd()
955 rq->special_vec.bv_len = data_len; in sd_setup_write_same10_cmnd()
956 rq->rq_flags |= RQF_SPECIAL_PAYLOAD; in sd_setup_write_same10_cmnd()
958 cmd->cmd_len = 10; in sd_setup_write_same10_cmnd()
959 cmd->cmnd[0] = WRITE_SAME; in sd_setup_write_same10_cmnd()
961 cmd->cmnd[1] = 0x8; /* UNMAP */ in sd_setup_write_same10_cmnd()
962 put_unaligned_be32(lba, &cmd->cmnd[2]); in sd_setup_write_same10_cmnd()
963 put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); in sd_setup_write_same10_cmnd()
965 cmd->allowed = sdkp->max_retries; in sd_setup_write_same10_cmnd()
966 cmd->transfersize = data_len; in sd_setup_write_same10_cmnd()
967 rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; in sd_setup_write_same10_cmnd()
974 struct request *rq = cmd->request; in sd_setup_write_zeroes_cmnd()
975 struct scsi_device *sdp = cmd->device; in sd_setup_write_zeroes_cmnd() local
976 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_write_zeroes_cmnd()
977 u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); in sd_setup_write_zeroes_cmnd()
978 u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); in sd_setup_write_zeroes_cmnd()
980 if (!(rq->cmd_flags & REQ_NOUNMAP)) { in sd_setup_write_zeroes_cmnd()
981 switch (sdkp->zeroing_mode) { in sd_setup_write_zeroes_cmnd()
989 if (sdp->no_write_same) in sd_setup_write_zeroes_cmnd()
992 if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) in sd_setup_write_zeroes_cmnd()
1000 struct request_queue *q = sdkp->disk->queue; in sd_config_write_same()
1001 unsigned int logical_block_size = sdkp->device->sector_size; in sd_config_write_same()
1003 if (sdkp->device->no_write_same) { in sd_config_write_same()
1004 sdkp->max_ws_blocks = 0; in sd_config_write_same()
1013 if (sdkp->max_ws_blocks > SD_MAX_WS10_BLOCKS) in sd_config_write_same()
1014 sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks, in sd_config_write_same()
1016 else if (sdkp->ws16 || sdkp->ws10 || sdkp->device->no_report_opcodes) in sd_config_write_same()
1017 sdkp->max_ws_blocks = min_not_zero(sdkp->max_ws_blocks, in sd_config_write_same()
1020 sdkp->device->no_write_same = 1; in sd_config_write_same()
1021 sdkp->max_ws_blocks = 0; in sd_config_write_same()
1024 if (sdkp->lbprz && sdkp->lbpws) in sd_config_write_same()
1025 sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP; in sd_config_write_same()
1026 else if (sdkp->lbprz && sdkp->lbpws10) in sd_config_write_same()
1027 sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP; in sd_config_write_same()
1028 else if (sdkp->max_ws_blocks) in sd_config_write_same()
1029 sdkp->zeroing_mode = SD_ZERO_WS; in sd_config_write_same()
1031 sdkp->zeroing_mode = SD_ZERO_WRITE; in sd_config_write_same()
1033 if (sdkp->max_ws_blocks && in sd_config_write_same()
1034 sdkp->physical_block_size > logical_block_size) { in sd_config_write_same()
1045 * sequential write required zones of host-managed ZBC disks. in sd_config_write_same()
1047 sdkp->max_ws_blocks = in sd_config_write_same()
1048 round_down(sdkp->max_ws_blocks, in sd_config_write_same()
1049 bytes_to_logical(sdkp->device, in sd_config_write_same()
1050 sdkp->physical_block_size)); in sd_config_write_same()
1054 blk_queue_max_write_same_sectors(q, sdkp->max_ws_blocks * in sd_config_write_same()
1056 blk_queue_max_write_zeroes_sectors(q, sdkp->max_ws_blocks * in sd_config_write_same()
1061 * sd_setup_write_same_cmnd - write the same data to multiple blocks
1069 struct request *rq = cmd->request; in sd_setup_write_same_cmnd()
1070 struct scsi_device *sdp = cmd->device; in sd_setup_write_same_cmnd() local
1071 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_write_same_cmnd()
1072 struct bio *bio = rq->bio; in sd_setup_write_same_cmnd()
1073 u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); in sd_setup_write_same_cmnd()
1074 u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); in sd_setup_write_same_cmnd()
1077 if (sdkp->device->no_write_same) in sd_setup_write_same_cmnd()
1080 BUG_ON(bio_offset(bio) || bio_iovec(bio).bv_len != sdp->sector_size); in sd_setup_write_same_cmnd()
1082 rq->timeout = SD_WRITE_SAME_TIMEOUT; in sd_setup_write_same_cmnd()
1084 if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) { in sd_setup_write_same_cmnd()
1085 cmd->cmd_len = 16; in sd_setup_write_same_cmnd()
1086 cmd->cmnd[0] = WRITE_SAME_16; in sd_setup_write_same_cmnd()
1087 put_unaligned_be64(lba, &cmd->cmnd[2]); in sd_setup_write_same_cmnd()
1088 put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); in sd_setup_write_same_cmnd()
1090 cmd->cmd_len = 10; in sd_setup_write_same_cmnd()
1091 cmd->cmnd[0] = WRITE_SAME; in sd_setup_write_same_cmnd()
1092 put_unaligned_be32(lba, &cmd->cmnd[2]); in sd_setup_write_same_cmnd()
1093 put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); in sd_setup_write_same_cmnd()
1096 cmd->transfersize = sdp->sector_size; in sd_setup_write_same_cmnd()
1097 cmd->allowed = sdkp->max_retries; in sd_setup_write_same_cmnd()
1109 rq->__data_len = sdp->sector_size; in sd_setup_write_same_cmnd()
1111 rq->__data_len = blk_rq_bytes(rq); in sd_setup_write_same_cmnd()
1118 struct request *rq = cmd->request; in sd_setup_flush_cmnd()
1119 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_flush_cmnd()
1122 memset(&cmd->sdb, 0, sizeof(cmd->sdb)); in sd_setup_flush_cmnd()
1124 cmd->cmnd[0] = SYNCHRONIZE_CACHE; in sd_setup_flush_cmnd()
1125 cmd->cmd_len = 10; in sd_setup_flush_cmnd()
1126 cmd->transfersize = 0; in sd_setup_flush_cmnd()
1127 cmd->allowed = sdkp->max_retries; in sd_setup_flush_cmnd()
1129 rq->timeout = rq->q->rq_timeout * SD_FLUSH_TIMEOUT_MULTIPLIER; in sd_setup_flush_cmnd()
1137 cmd->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC); in sd_setup_rw32_cmnd()
1138 if (unlikely(cmd->cmnd == NULL)) in sd_setup_rw32_cmnd()
1141 cmd->cmd_len = SD_EXT_CDB_SIZE; in sd_setup_rw32_cmnd()
1142 memset(cmd->cmnd, 0, cmd->cmd_len); in sd_setup_rw32_cmnd()
1144 cmd->cmnd[0] = VARIABLE_LENGTH_CMD; in sd_setup_rw32_cmnd()
1145 cmd->cmnd[7] = 0x18; /* Additional CDB len */ in sd_setup_rw32_cmnd()
1146 cmd->cmnd[9] = write ? WRITE_32 : READ_32; in sd_setup_rw32_cmnd()
1147 cmd->cmnd[10] = flags; in sd_setup_rw32_cmnd()
1148 put_unaligned_be64(lba, &cmd->cmnd[12]); in sd_setup_rw32_cmnd()
1149 put_unaligned_be32(lba, &cmd->cmnd[20]); /* Expected Indirect LBA */ in sd_setup_rw32_cmnd()
1150 put_unaligned_be32(nr_blocks, &cmd->cmnd[28]); in sd_setup_rw32_cmnd()
1159 cmd->cmd_len = 16; in sd_setup_rw16_cmnd()
1160 cmd->cmnd[0] = write ? WRITE_16 : READ_16; in sd_setup_rw16_cmnd()
1161 cmd->cmnd[1] = flags; in sd_setup_rw16_cmnd()
1162 cmd->cmnd[14] = 0; in sd_setup_rw16_cmnd()
1163 cmd->cmnd[15] = 0; in sd_setup_rw16_cmnd()
1164 put_unaligned_be64(lba, &cmd->cmnd[2]); in sd_setup_rw16_cmnd()
1165 put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); in sd_setup_rw16_cmnd()
1174 cmd->cmd_len = 10; in sd_setup_rw10_cmnd()
1175 cmd->cmnd[0] = write ? WRITE_10 : READ_10; in sd_setup_rw10_cmnd()
1176 cmd->cmnd[1] = flags; in sd_setup_rw10_cmnd()
1177 cmd->cmnd[6] = 0; in sd_setup_rw10_cmnd()
1178 cmd->cmnd[9] = 0; in sd_setup_rw10_cmnd()
1179 put_unaligned_be32(lba, &cmd->cmnd[2]); in sd_setup_rw10_cmnd()
1180 put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); in sd_setup_rw10_cmnd()
1203 cmd->cmd_len = 6; in sd_setup_rw6_cmnd()
1204 cmd->cmnd[0] = write ? WRITE_6 : READ_6; in sd_setup_rw6_cmnd()
1205 cmd->cmnd[1] = (lba >> 16) & 0x1f; in sd_setup_rw6_cmnd()
1206 cmd->cmnd[2] = (lba >> 8) & 0xff; in sd_setup_rw6_cmnd()
1207 cmd->cmnd[3] = lba & 0xff; in sd_setup_rw6_cmnd()
1208 cmd->cmnd[4] = nr_blocks; in sd_setup_rw6_cmnd()
1209 cmd->cmnd[5] = 0; in sd_setup_rw6_cmnd()
1216 struct request *rq = cmd->request; in sd_setup_read_write_cmnd()
1217 struct scsi_device *sdp = cmd->device; in sd_setup_read_write_cmnd() local
1218 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); in sd_setup_read_write_cmnd()
1219 sector_t lba = sectors_to_logical(sdp, blk_rq_pos(rq)); in sd_setup_read_write_cmnd()
1221 unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); in sd_setup_read_write_cmnd()
1222 unsigned int mask = logical_to_sectors(sdp, 1) - 1; in sd_setup_read_write_cmnd()
1234 if (!scsi_device_online(sdp) || sdp->changed) { in sd_setup_read_write_cmnd()
1239 if (blk_rq_pos(rq) + blk_rq_sectors(rq) > get_capacity(rq->rq_disk)) { in sd_setup_read_write_cmnd()
1253 threshold = sdkp->capacity - SD_LAST_BUGGY_SECTORS; in sd_setup_read_write_cmnd()
1255 if (unlikely(sdp->last_sector_bug && lba + nr_blocks > threshold)) { in sd_setup_read_write_cmnd()
1258 nr_blocks = threshold - lba; in sd_setup_read_write_cmnd()
1271 fua = rq->cmd_flags & REQ_FUA ? 0x8 : 0; in sd_setup_read_write_cmnd()
1273 dif = scsi_host_dif_capable(cmd->device->host, sdkp->protection_type); in sd_setup_read_write_cmnd()
1280 if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { in sd_setup_read_write_cmnd()
1283 } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { in sd_setup_read_write_cmnd()
1287 sdp->use_10_for_rw || protect) { in sd_setup_read_write_cmnd()
1303 cmd->transfersize = sdp->sector_size; in sd_setup_read_write_cmnd()
1304 cmd->underflow = nr_blocks << 9; in sd_setup_read_write_cmnd()
1305 cmd->allowed = sdkp->max_retries; in sd_setup_read_write_cmnd()
1306 cmd->sdb.length = nr_blocks * sdp->sector_size; in sd_setup_read_write_cmnd()
1330 struct request *rq = cmd->request; in sd_init_command()
1334 switch (scsi_disk(rq->rq_disk)->provisioning_mode) { in sd_init_command()
1376 struct request *rq = SCpnt->request; in sd_uninit_command()
1379 if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) in sd_uninit_command()
1380 mempool_free(rq->special_vec.bv_page, sd_page_pool); in sd_uninit_command()
1382 if (SCpnt->cmnd != scsi_req(rq)->cmd) { in sd_uninit_command()
1383 cmnd = SCpnt->cmnd; in sd_uninit_command()
1384 SCpnt->cmnd = NULL; in sd_uninit_command()
1385 SCpnt->cmd_len = 0; in sd_uninit_command()
1391 * sd_open - open a scsi disk device
1403 * Locking: called with bdev->bd_mutex held.
1407 struct scsi_disk *sdkp = scsi_disk_get(bdev->bd_disk); in sd_open()
1412 return -ENXIO; in sd_open()
1416 sdev = sdkp->device; in sd_open()
1422 retval = -ENXIO; in sd_open()
1426 if (sdev->removable || sdkp->write_prot) { in sd_open()
1428 sd_revalidate_disk(bdev->bd_disk); in sd_open()
1434 retval = -ENOMEDIUM; in sd_open()
1435 if (sdev->removable && !sdkp->media_present && !(mode & FMODE_NDELAY)) in sd_open()
1442 retval = -EROFS; in sd_open()
1443 if (sdkp->write_prot && (mode & FMODE_WRITE)) in sd_open()
1452 retval = -ENXIO; in sd_open()
1456 if ((atomic_inc_return(&sdkp->openers) == 1) && sdev->removable) { in sd_open()
1469 * sd_release - invoked when the (last) close(2) is called on this
1479 * Locking: called with bdev->bd_mutex held.
1484 struct scsi_device *sdev = sdkp->device; in sd_release()
1488 if (atomic_dec_return(&sdkp->openers) == 0 && sdev->removable) { in sd_release()
1498 struct scsi_disk *sdkp = scsi_disk(bdev->bd_disk); in sd_getgeo()
1499 struct scsi_device *sdp = sdkp->device; in sd_getgeo() local
1500 struct Scsi_Host *host = sdp->host; in sd_getgeo()
1501 sector_t capacity = logical_to_sectors(sdp, sdkp->capacity); in sd_getgeo()
1510 if (host->hostt->bios_param) in sd_getgeo()
1511 host->hostt->bios_param(sdp, bdev, capacity, diskinfo); in sd_getgeo()
1515 geo->heads = diskinfo[0]; in sd_getgeo()
1516 geo->sectors = diskinfo[1]; in sd_getgeo()
1517 geo->cylinders = diskinfo[2]; in sd_getgeo()
1522 * sd_ioctl - process an ioctl
1538 struct gendisk *disk = bdev->bd_disk; in sd_ioctl_common()
1540 struct scsi_device *sdp = sdkp->device; in sd_ioctl_common() local
1544 "cmd=0x%x\n", disk->disk_name, cmd)); in sd_ioctl_common()
1556 error = scsi_ioctl_block_when_processing_errors(sdp, cmd, in sd_ioctl_common()
1562 return sed_ioctl(sdkp->opal_dev, cmd, p); in sd_ioctl_common()
1572 error = scsi_ioctl(sdp, cmd, p); in sd_ioctl_common()
1584 if (sdkp->media_present) in set_media_not_present()
1585 sdkp->device->changed = 1; in set_media_not_present()
1587 if (sdkp->device->removable) { in set_media_not_present()
1588 sdkp->media_present = 0; in set_media_not_present()
1589 sdkp->capacity = 0; in set_media_not_present()
1600 switch (sshdr->sense_key) { in media_not_present()
1604 if (sshdr->asc == 0x3A) { in media_not_present()
1613 * sd_check_events - check media events
1624 struct scsi_device *sdp; in sd_check_events() local
1630 sdp = sdkp->device; in sd_check_events()
1634 * If the device is offline, don't send any commands - just pretend as in sd_check_events()
1639 if (!scsi_device_online(sdp)) { in sd_check_events()
1646 * no cartridge loaded - NOT READY, drive with changed cartridge - in sd_check_events()
1647 * UNIT ATTENTION, or with same cartridge - GOOD STATUS. in sd_check_events()
1653 if (scsi_block_when_processing_errors(sdp)) { in sd_check_events()
1656 retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, sdkp->max_retries, in sd_check_events()
1673 if (!sdkp->media_present) in sd_check_events()
1674 sdp->changed = 1; in sd_check_events()
1675 sdkp->media_present = 1; in sd_check_events()
1678 * sdp->changed is set under the following conditions: in sd_check_events()
1683 retval = sdp->changed ? DISK_EVENT_MEDIA_CHANGE : 0; in sd_check_events()
1684 sdp->changed = 0; in sd_check_events()
1692 struct scsi_device *sdp = sdkp->device; in sd_sync_cache() local
1693 const int timeout = sdp->request_queue->rq_timeout in sd_sync_cache()
1697 if (!scsi_device_online(sdp)) in sd_sync_cache()
1698 return -ENODEV; in sd_sync_cache()
1704 for (retries = 3; retries > 0; --retries) { in sd_sync_cache()
1712 res = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, sshdr, in sd_sync_cache()
1713 timeout, sdkp->max_retries, 0, RQF_PM, NULL); in sd_sync_cache()
1726 (sshdr->asc == 0x3a || /* medium not present */ in sd_sync_cache()
1727 sshdr->asc == 0x20 || /* invalid command */ in sd_sync_cache()
1728 (sshdr->asc == 0x74 && sshdr->ascq == 0x71))) /* drive is password locked */ in sd_sync_cache()
1742 return -EBUSY; in sd_sync_cache()
1744 return -EIO; in sd_sync_cache()
1755 ret = sd_revalidate_disk(sdkp->disk); in sd_rescan()
1756 revalidate_disk_size(sdkp->disk, ret == 0); in sd_rescan()
1766 if (ret != -ENOTTY) in sd_ioctl()
1769 return scsi_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p); in sd_ioctl()
1780 if (ret != -ENOTTY) in sd_compat_ioctl()
1783 return scsi_compat_ioctl(scsi_disk(bdev->bd_disk)->device, cmd, p); in sd_compat_ioctl()
1810 struct scsi_disk *sdkp = scsi_disk(bdev->bd_disk); in sd_pr_command()
1811 struct scsi_device *sdev = sdkp->device; in sd_pr_command()
1827 &sshdr, SD_TIMEOUT, sdkp->max_retries, NULL); in sd_pr_command()
1842 return -EOPNOTSUPP; in sd_pr_register()
1852 return -EOPNOTSUPP; in sd_pr_reserve()
1897 * sd_eh_reset - reset error handling callback
1898 * @scmd: sd-issued command that has failed
1910 struct scsi_disk *sdkp = scsi_disk(scmd->request->rq_disk); in sd_eh_reset()
1913 sdkp->ignore_medium_access_errors = false; in sd_eh_reset()
1917 * sd_eh_action - error handling callback
1918 * @scmd: sd-issued command that has failed
1930 struct scsi_disk *sdkp = scsi_disk(scmd->request->rq_disk); in sd_eh_action()
1931 struct scsi_device *sdev = scmd->device; in sd_eh_action()
1935 host_byte(scmd->result) != DID_TIME_OUT || in sd_eh_action()
1946 if (!sdkp->ignore_medium_access_errors) { in sd_eh_action()
1947 sdkp->medium_access_timed_out++; in sd_eh_action()
1948 sdkp->ignore_medium_access_errors = true; in sd_eh_action()
1956 if (sdkp->medium_access_timed_out >= sdkp->max_medium_access_timeouts) { in sd_eh_action()
1959 mutex_lock(&sdev->state_mutex); in sd_eh_action()
1961 mutex_unlock(&sdev->state_mutex); in sd_eh_action()
1971 struct request *req = scmd->request; in sd_completed_bytes()
1972 struct scsi_device *sdev = scmd->device; in sd_completed_bytes()
1980 if (scsi_bufflen(scmd) <= sdev->sector_size) in sd_completed_bytes()
1984 if (!scsi_get_sense_info_fld(scmd->sense_buffer, in sd_completed_bytes()
2002 transferred = scsi_bufflen(scmd) - scsi_get_resid(scmd); in sd_completed_bytes()
2007 good_bytes = logical_to_bytes(sdev, bad_lba - start_lba); in sd_completed_bytes()
2013 * sd_done - bottom half handler: called when the lower level
2015 * @SCpnt: mid-level's per command structure.
2021 int result = SCpnt->result; in sd_done()
2023 unsigned int sector_size = SCpnt->device->sector_size; in sd_done()
2026 struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk); in sd_done()
2027 struct request *req = SCpnt->request; in sd_done()
2055 if (resid & (sector_size - 1)) { in sd_done()
2071 sdkp->medium_access_timed_out = 0; in sd_done()
2090 SCpnt->result = 0; in sd_done()
2091 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in sd_done()
2104 switch (SCpnt->cmnd[0]) { in sd_done()
2110 if (SCpnt->cmnd[1] & 8) { /* UNMAP */ in sd_done()
2113 sdkp->device->no_write_same = 1; in sd_done()
2115 req->rq_flags |= RQF_QUIET; in sd_done()
2137 * spinup disk - called only in sd_revalidate_disk()
2160 the_result = scsi_execute_req(sdkp->device, cmd, in sd_spinup_disk()
2163 sdkp->max_retries, NULL); in sd_spinup_disk()
2194 if (sdkp->device->no_start_on_add) in sd_spinup_disk()
2215 if (sdkp->device->start_stop_pwr_cond) in sd_spinup_disk()
2217 scsi_execute_req(sdkp->device, cmd, DMA_NONE, in sd_spinup_disk()
2219 SD_TIMEOUT, sdkp->max_retries, in sd_spinup_disk()
2229 * Wait for USB flash devices with slow firmware. in sd_spinup_disk()
2267 struct scsi_device *sdp = sdkp->device; in sd_read_protection_type() local
2271 if (scsi_device_protection(sdp) == 0 || (buffer[12] & 1) == 0) { in sd_read_protection_type()
2272 sdkp->protection_type = 0; in sd_read_protection_type()
2279 ret = -ENODEV; in sd_read_protection_type()
2280 else if (scsi_host_dif_capable(sdp->host, type)) in sd_read_protection_type()
2283 if (sdkp->first_scan || type != sdkp->protection_type) in sd_read_protection_type()
2285 case -ENODEV: in sd_read_protection_type()
2300 sdkp->protection_type = type; in sd_read_protection_type()
2305 static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp, in read_capacity_error() argument
2315 * Set dirty bit for removable devices if not ready - in read_capacity_error()
2318 if (sdp->removable && in read_capacity_error()
2319 sense_valid && sshdr->sense_key == NOT_READY) in read_capacity_error()
2327 sdkp->capacity = 0; /* unknown mapped to zero - as usual */ in read_capacity_error()
2337 static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, in read_capacity_16() argument
2349 if (sdp->no_read_capacity_16) in read_capacity_16()
2350 return -EINVAL; in read_capacity_16()
2359 the_result = scsi_execute_req(sdp, cmd, DMA_FROM_DEVICE, in read_capacity_16()
2361 SD_TIMEOUT, sdkp->max_retries, NULL); in read_capacity_16()
2364 return -ENODEV; in read_capacity_16()
2375 return -EINVAL; in read_capacity_16()
2381 if (--reset_retries > 0) in read_capacity_16()
2384 retries--; in read_capacity_16()
2390 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result); in read_capacity_16()
2391 return -EINVAL; in read_capacity_16()
2398 sdkp->capacity = 0; in read_capacity_16()
2399 return -ENODEV; in read_capacity_16()
2403 sdkp->physical_block_size = (1 << (buffer[13] & 0xf)) * sector_size; in read_capacity_16()
2406 sdkp->rc_basis = (buffer[12] >> 4) & 0x3; in read_capacity_16()
2410 blk_queue_alignment_offset(sdp->request_queue, alignment); in read_capacity_16()
2411 if (alignment && sdkp->first_scan) in read_capacity_16()
2416 sdkp->lbpme = 1; in read_capacity_16()
2419 sdkp->lbprz = 1; in read_capacity_16()
2424 sdkp->capacity = lba + 1; in read_capacity_16()
2428 static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, in read_capacity_10() argument
2444 the_result = scsi_execute_req(sdp, cmd, DMA_FROM_DEVICE, in read_capacity_10()
2446 SD_TIMEOUT, sdkp->max_retries, NULL); in read_capacity_10()
2449 return -ENODEV; in read_capacity_10()
2458 if (--reset_retries > 0) in read_capacity_10()
2461 retries--; in read_capacity_10()
2467 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result); in read_capacity_10()
2468 return -EINVAL; in read_capacity_10()
2474 if (sdp->no_read_capacity_16 && (lba == 0xffffffff)) { in read_capacity_10()
2475 /* Some buggy (usb cardreader) devices return an lba of in read_capacity_10()
2478 sdkp->capacity = 0; in read_capacity_10()
2479 sdkp->physical_block_size = sector_size; in read_capacity_10()
2483 sdkp->capacity = lba + 1; in read_capacity_10()
2484 sdkp->physical_block_size = sector_size; in read_capacity_10()
2488 static int sd_try_rc16_first(struct scsi_device *sdp) in sd_try_rc16_first() argument
2490 if (sdp->host->max_cmd_len < 16) in sd_try_rc16_first()
2492 if (sdp->try_rc_10_first) in sd_try_rc16_first()
2494 if (sdp->scsi_level > SCSI_SPC_2) in sd_try_rc16_first()
2496 if (scsi_device_protection(sdp)) in sd_try_rc16_first()
2508 struct scsi_device *sdp = sdkp->device; in sd_read_capacity() local
2510 if (sd_try_rc16_first(sdp)) { in sd_read_capacity()
2511 sector_size = read_capacity_16(sdkp, sdp, buffer); in sd_read_capacity()
2512 if (sector_size == -EOVERFLOW) in sd_read_capacity()
2514 if (sector_size == -ENODEV) in sd_read_capacity()
2517 sector_size = read_capacity_10(sdkp, sdp, buffer); in sd_read_capacity()
2521 sector_size = read_capacity_10(sdkp, sdp, buffer); in sd_read_capacity()
2522 if (sector_size == -EOVERFLOW) in sd_read_capacity()
2526 if ((sizeof(sdkp->capacity) > 4) && in sd_read_capacity()
2527 (sdkp->capacity > 0xffffffffULL)) { in sd_read_capacity()
2531 sector_size = read_capacity_16(sdkp, sdp, buffer); in sd_read_capacity()
2535 sdkp->capacity = 1 + (sector_t) 0xffffffff; in sd_read_capacity()
2540 sdp->try_rc_10_first = 0; in sd_read_capacity()
2554 if (sdp->fix_capacity || in sd_read_capacity()
2555 (sdp->guess_capacity && (sdkp->capacity & 0x01))) { in sd_read_capacity()
2558 (unsigned long long) sdkp->capacity); in sd_read_capacity()
2559 --sdkp->capacity; in sd_read_capacity()
2576 * The user might want to re-format the drive with in sd_read_capacity()
2581 sdkp->capacity = 0; in sd_read_capacity()
2590 blk_queue_logical_block_size(sdp->request_queue, sector_size); in sd_read_capacity()
2591 blk_queue_physical_block_size(sdp->request_queue, in sd_read_capacity()
2592 sdkp->physical_block_size); in sd_read_capacity()
2593 sdkp->device->sector_size = sector_size; in sd_read_capacity()
2595 if (sdkp->capacity > 0xffffffff) in sd_read_capacity()
2596 sdp->use_16_for_rw = 1; in sd_read_capacity()
2607 int sector_size = sdkp->device->sector_size; in sd_print_capacity()
2610 if (!sdkp->first_scan && old_capacity == sdkp->capacity) in sd_print_capacity()
2613 string_get_size(sdkp->capacity, sector_size, in sd_print_capacity()
2615 string_get_size(sdkp->capacity, sector_size, in sd_print_capacity()
2619 "%llu %d-byte logical blocks: (%s/%s)\n", in sd_print_capacity()
2620 (unsigned long long)sdkp->capacity, in sd_print_capacity()
2623 if (sdkp->physical_block_size != sector_size) in sd_print_capacity()
2625 "%u-byte physical blocks\n", in sd_print_capacity()
2626 sdkp->physical_block_size); in sd_print_capacity()
2635 return scsi_mode_sense(sdkp->device, dbd, modepage, buffer, len, in sd_do_mode_sense()
2636 SD_TIMEOUT, sdkp->max_retries, data, in sd_do_mode_sense()
2641 * read write protect setting, if possible - called only in sd_revalidate_disk()
2648 struct scsi_device *sdp = sdkp->device; in sd_read_write_protect_flag() local
2650 int old_wp = sdkp->write_prot; in sd_read_write_protect_flag()
2652 set_disk_ro(sdkp->disk, 0); in sd_read_write_protect_flag()
2653 if (sdp->skip_ms_page_3f) { in sd_read_write_protect_flag()
2658 if (sdp->use_192_bytes_for_3f) { in sd_read_write_protect_flag()
2689 sdkp->write_prot = ((data.device_specific & 0x80) != 0); in sd_read_write_protect_flag()
2690 set_disk_ro(sdkp->disk, sdkp->write_prot); in sd_read_write_protect_flag()
2691 if (sdkp->first_scan || old_wp != sdkp->write_prot) { in sd_read_write_protect_flag()
2693 sdkp->write_prot ? "on" : "off"); in sd_read_write_protect_flag()
2700 * sd_read_cache_type - called only from sd_revalidate_disk()
2707 struct scsi_device *sdp = sdkp->device; in sd_read_cache_type() local
2714 int old_wce = sdkp->WCE; in sd_read_cache_type()
2715 int old_rcd = sdkp->RCD; in sd_read_cache_type()
2716 int old_dpofua = sdkp->DPOFUA; in sd_read_cache_type()
2719 if (sdkp->cache_override) in sd_read_cache_type()
2723 if (sdp->skip_ms_page_8) { in sd_read_cache_type()
2724 if (sdp->type == TYPE_RBC) in sd_read_cache_type()
2727 if (sdp->skip_ms_page_3f) in sd_read_cache_type()
2730 if (sdp->use_192_bytes_for_3f) in sd_read_cache_type()
2734 } else if (sdp->type == TYPE_RBC) { in sd_read_cache_type()
2770 if (modepage == 0x3F && sdp->use_192_bytes_for_3f) in sd_read_cache_type()
2788 if (len - offset <= 2) { in sd_read_cache_type()
2799 if (spf && len - offset > 3) in sd_read_cache_type()
2802 else if (!spf && len - offset > 1) in sd_read_cache_type()
2818 sdkp->WCE = ((buffer[offset + 2] & 0x04) != 0); in sd_read_cache_type()
2819 sdkp->RCD = ((buffer[offset + 2] & 0x01) != 0); in sd_read_cache_type()
2821 sdkp->WCE = ((buffer[offset + 2] & 0x01) == 0); in sd_read_cache_type()
2822 sdkp->RCD = 0; in sd_read_cache_type()
2825 sdkp->DPOFUA = (data.device_specific & 0x10) != 0; in sd_read_cache_type()
2826 if (sdp->broken_fua) { in sd_read_cache_type()
2828 sdkp->DPOFUA = 0; in sd_read_cache_type()
2829 } else if (sdkp->DPOFUA && !sdkp->device->use_10_for_rw && in sd_read_cache_type()
2830 !sdkp->device->use_16_for_rw) { in sd_read_cache_type()
2833 sdkp->DPOFUA = 0; in sd_read_cache_type()
2837 if (sdkp->WCE && sdkp->write_prot) in sd_read_cache_type()
2838 sdkp->WCE = 0; in sd_read_cache_type()
2840 if (sdkp->first_scan || old_wce != sdkp->WCE || in sd_read_cache_type()
2841 old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA) in sd_read_cache_type()
2844 sdkp->WCE ? "enabled" : "disabled", in sd_read_cache_type()
2845 sdkp->RCD ? "disabled" : "enabled", in sd_read_cache_type()
2846 sdkp->DPOFUA ? "supports DPO and FUA" in sd_read_cache_type()
2863 if (sdp->wce_default_on) { in sd_read_cache_type()
2866 sdkp->WCE = 1; in sd_read_cache_type()
2870 sdkp->WCE = 0; in sd_read_cache_type()
2872 sdkp->RCD = 0; in sd_read_cache_type()
2873 sdkp->DPOFUA = 0; in sd_read_cache_type()
2883 struct scsi_device *sdp = sdkp->device; in sd_read_app_tag_own() local
2887 if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) in sd_read_app_tag_own()
2890 if (sdkp->protection_type == 0) in sd_read_app_tag_own()
2893 res = scsi_mode_sense(sdp, 1, 0x0a, buffer, 36, SD_TIMEOUT, in sd_read_app_tag_own()
2894 sdkp->max_retries, &data, &sshdr); in sd_read_app_tag_own()
2917 sdkp->ATO = 1; in sd_read_app_tag_own()
2923 * sd_read_block_limits - Query disk device for preferred I/O sizes.
2928 unsigned int sector_sz = sdkp->device->sector_size; in sd_read_block_limits()
2934 scsi_get_vpd_page(sdkp->device, 0xb0, buffer, vpd_len)) in sd_read_block_limits()
2937 blk_queue_io_min(sdkp->disk->queue, in sd_read_block_limits()
2940 sdkp->max_xfer_blocks = get_unaligned_be32(&buffer[8]); in sd_read_block_limits()
2941 sdkp->opt_xfer_blocks = get_unaligned_be32(&buffer[12]); in sd_read_block_limits()
2946 sdkp->max_ws_blocks = (u32)get_unaligned_be64(&buffer[36]); in sd_read_block_limits()
2948 if (!sdkp->lbpme) in sd_read_block_limits()
2955 sdkp->max_unmap_blocks = lba_count; in sd_read_block_limits()
2957 sdkp->unmap_granularity = get_unaligned_be32(&buffer[28]); in sd_read_block_limits()
2960 sdkp->unmap_alignment = in sd_read_block_limits()
2963 if (!sdkp->lbpvpd) { /* LBP VPD page not provided */ in sd_read_block_limits()
2965 if (sdkp->max_unmap_blocks) in sd_read_block_limits()
2971 if (sdkp->lbpu && sdkp->max_unmap_blocks) in sd_read_block_limits()
2973 else if (sdkp->lbpws) in sd_read_block_limits()
2975 else if (sdkp->lbpws10) in sd_read_block_limits()
2987 * sd_read_block_characteristics - Query block dev. characteristics
2992 struct request_queue *q = sdkp->disk->queue; in sd_read_block_characteristics()
3001 scsi_get_vpd_page(sdkp->device, 0xb1, buffer, vpd_len)) in sd_read_block_characteristics()
3011 if (sdkp->device->type == TYPE_ZBC) { in sd_read_block_characteristics()
3012 /* Host-managed */ in sd_read_block_characteristics()
3013 blk_queue_set_zoned(sdkp->disk, BLK_ZONED_HM); in sd_read_block_characteristics()
3015 sdkp->zoned = (buffer[8] >> 4) & 3; in sd_read_block_characteristics()
3016 if (sdkp->zoned == 1) { in sd_read_block_characteristics()
3017 /* Host-aware */ in sd_read_block_characteristics()
3018 blk_queue_set_zoned(sdkp->disk, BLK_ZONED_HA); in sd_read_block_characteristics()
3021 blk_queue_set_zoned(sdkp->disk, BLK_ZONED_NONE); in sd_read_block_characteristics()
3025 if (!sdkp->first_scan) in sd_read_block_characteristics()
3029 sd_printk(KERN_NOTICE, sdkp, "Host-%s zoned block device\n", in sd_read_block_characteristics()
3030 q->limits.zoned == BLK_ZONED_HM ? "managed" : "aware"); in sd_read_block_characteristics()
3032 if (sdkp->zoned == 1) in sd_read_block_characteristics()
3034 "Host-aware SMR disk used as regular disk\n"); in sd_read_block_characteristics()
3035 else if (sdkp->zoned == 2) in sd_read_block_characteristics()
3037 "Drive-managed SMR disk\n"); in sd_read_block_characteristics()
3045 * sd_read_block_provisioning - Query provisioning VPD page
3053 if (sdkp->lbpme == 0) in sd_read_block_provisioning()
3058 if (!buffer || scsi_get_vpd_page(sdkp->device, 0xb2, buffer, vpd_len)) in sd_read_block_provisioning()
3061 sdkp->lbpvpd = 1; in sd_read_block_provisioning()
3062 sdkp->lbpu = (buffer[5] >> 7) & 1; /* UNMAP */ in sd_read_block_provisioning()
3063 sdkp->lbpws = (buffer[5] >> 6) & 1; /* WRITE SAME(16) with UNMAP */ in sd_read_block_provisioning()
3064 sdkp->lbpws10 = (buffer[5] >> 5) & 1; /* WRITE SAME(10) with UNMAP */ in sd_read_block_provisioning()
3072 struct scsi_device *sdev = sdkp->device; in sd_read_write_same()
3074 if (sdev->host->no_write_same) { in sd_read_write_same()
3075 sdev->no_write_same = 1; in sd_read_write_same()
3084 sdev->no_report_opcodes = 1; in sd_read_write_same()
3091 sdev->no_write_same = 1; in sd_read_write_same()
3095 sdkp->ws16 = 1; in sd_read_write_same()
3098 sdkp->ws10 = 1; in sd_read_write_same()
3103 struct scsi_device *sdev = sdkp->device; in sd_read_security()
3105 if (!sdev->security_supported) in sd_read_security()
3112 sdkp->security = 1; in sd_read_security()
3123 struct scsi_device *sdp = sdkp->device; in sd_validate_opt_xfer_size() local
3125 logical_to_bytes(sdp, sdkp->opt_xfer_blocks); in sd_validate_opt_xfer_size()
3127 if (sdkp->opt_xfer_blocks == 0) in sd_validate_opt_xfer_size()
3130 if (sdkp->opt_xfer_blocks > dev_max) { in sd_validate_opt_xfer_size()
3134 sdkp->opt_xfer_blocks, dev_max); in sd_validate_opt_xfer_size()
3138 if (sdkp->opt_xfer_blocks > SD_DEF_XFER_BLOCKS) { in sd_validate_opt_xfer_size()
3142 sdkp->opt_xfer_blocks, SD_DEF_XFER_BLOCKS); in sd_validate_opt_xfer_size()
3154 if (opt_xfer_bytes & (sdkp->physical_block_size - 1)) { in sd_validate_opt_xfer_size()
3158 opt_xfer_bytes, sdkp->physical_block_size); in sd_validate_opt_xfer_size()
3168 * sd_revalidate_disk - called the first time a new disk is seen,
3175 struct scsi_device *sdp = sdkp->device; in sd_revalidate_disk() local
3176 struct request_queue *q = sdkp->disk->queue; in sd_revalidate_disk()
3177 sector_t old_capacity = sdkp->capacity; in sd_revalidate_disk()
3188 if (!scsi_device_online(sdp)) in sd_revalidate_disk()
3204 if (sdkp->media_present) { in sd_revalidate_disk()
3208 * set the default to rotational. All non-rotational devices in sd_revalidate_disk()
3216 if (scsi_device_supports_vpd(sdp)) { in sd_revalidate_disk()
3239 dev_max = sdp->use_16_for_rw ? SD_MAX_XFER_BLOCKS : SD_DEF_XFER_BLOCKS; in sd_revalidate_disk()
3242 dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks); in sd_revalidate_disk()
3243 q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max); in sd_revalidate_disk()
3246 q->limits.io_opt = logical_to_bytes(sdp, sdkp->opt_xfer_blocks); in sd_revalidate_disk()
3247 rw_max = logical_to_sectors(sdp, sdkp->opt_xfer_blocks); in sd_revalidate_disk()
3249 q->limits.io_opt = 0; in sd_revalidate_disk()
3250 rw_max = min_not_zero(logical_to_sectors(sdp, dev_max), in sd_revalidate_disk()
3261 if (sdkp->first_scan || in sd_revalidate_disk()
3262 q->limits.max_sectors > q->limits.max_dev_sectors || in sd_revalidate_disk()
3263 q->limits.max_sectors > q->limits.max_hw_sectors) in sd_revalidate_disk()
3264 q->limits.max_sectors = rw_max; in sd_revalidate_disk()
3266 sdkp->first_scan = 0; in sd_revalidate_disk()
3269 logical_to_sectors(sdp, sdkp->capacity), false); in sd_revalidate_disk()
3286 * sd_unlock_native_capacity - unlock native capacity
3291 * implements ->unlock_native_capacity() method, it's invoked to
3299 struct scsi_device *sdev = scsi_disk(disk)->device; in sd_unlock_native_capacity()
3301 if (sdev->host->hostt->unlock_native_capacity) in sd_unlock_native_capacity()
3302 sdev->host->hostt->unlock_native_capacity(sdev); in sd_unlock_native_capacity()
3306 * sd_format_disk_name - format disk name
3307 * @prefix: name prefix - ie. "sd" for SCSI disks
3319 * index shifted -1 after each digit is computed.
3325 * 0 on success, -errno on failure.
3329 const int base = 'z' - 'a' + 1; in sd_format_disk_name()
3335 p = end - 1; in sd_format_disk_name()
3340 return -EINVAL; in sd_format_disk_name()
3341 *--p = 'a' + (index % unit); in sd_format_disk_name()
3342 index = (index / unit) - 1; in sd_format_disk_name()
3345 memmove(begin, p, end - p); in sd_format_disk_name()
3352 * sd_probe - called during driver initialization and whenever a
3360 * Note: this function is invoked from the scsi mid-level.
3362 * <host,channel,id,lun> (found in sdp) and new device name
3366 * Assume sd_probe is not re-entrant (for time being)
3371 struct scsi_device *sdp = to_scsi_device(dev); in sd_probe() local
3377 scsi_autopm_get_device(sdp); in sd_probe()
3378 error = -ENODEV; in sd_probe()
3379 if (sdp->type != TYPE_DISK && in sd_probe()
3380 sdp->type != TYPE_ZBC && in sd_probe()
3381 sdp->type != TYPE_MOD && in sd_probe()
3382 sdp->type != TYPE_RBC) in sd_probe()
3386 if (sdp->type == TYPE_ZBC) in sd_probe()
3389 SCSI_LOG_HLQUEUE(3, sdev_printk(KERN_INFO, sdp, in sd_probe()
3392 error = -ENOMEM; in sd_probe()
3403 sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n"); in sd_probe()
3407 error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN); in sd_probe()
3409 sdev_printk(KERN_WARNING, sdp, "SCSI disk (sd) name length exceeded.\n"); in sd_probe()
3413 sdkp->device = sdp; in sd_probe()
3414 sdkp->driver = &sd_template; in sd_probe()
3415 sdkp->disk = gd; in sd_probe()
3416 sdkp->index = index; in sd_probe()
3417 sdkp->max_retries = SD_MAX_RETRIES; in sd_probe()
3418 atomic_set(&sdkp->openers, 0); in sd_probe()
3419 atomic_set(&sdkp->device->ioerr_cnt, 0); in sd_probe()
3421 if (!sdp->request_queue->rq_timeout) { in sd_probe()
3422 if (sdp->type != TYPE_MOD) in sd_probe()
3423 blk_queue_rq_timeout(sdp->request_queue, SD_TIMEOUT); in sd_probe()
3425 blk_queue_rq_timeout(sdp->request_queue, in sd_probe()
3429 device_initialize(&sdkp->dev); in sd_probe()
3430 sdkp->dev.parent = dev; in sd_probe()
3431 sdkp->dev.class = &sd_disk_class; in sd_probe()
3432 dev_set_name(&sdkp->dev, "%s", dev_name(dev)); in sd_probe()
3434 error = device_add(&sdkp->dev); in sd_probe()
3441 gd->major = sd_major((index & 0xf0) >> 4); in sd_probe()
3442 gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); in sd_probe()
3444 gd->fops = &sd_fops; in sd_probe()
3445 gd->private_data = &sdkp->driver; in sd_probe()
3446 gd->queue = sdkp->device->request_queue; in sd_probe()
3449 sdp->sector_size = 512; in sd_probe()
3450 sdkp->capacity = 0; in sd_probe()
3451 sdkp->media_present = 1; in sd_probe()
3452 sdkp->write_prot = 0; in sd_probe()
3453 sdkp->cache_override = 0; in sd_probe()
3454 sdkp->WCE = 0; in sd_probe()
3455 sdkp->RCD = 0; in sd_probe()
3456 sdkp->ATO = 0; in sd_probe()
3457 sdkp->first_scan = 1; in sd_probe()
3458 sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; in sd_probe()
3462 gd->flags = GENHD_FL_EXT_DEVT; in sd_probe()
3463 if (sdp->removable) { in sd_probe()
3464 gd->flags |= GENHD_FL_REMOVABLE; in sd_probe()
3465 gd->events |= DISK_EVENT_MEDIA_CHANGE; in sd_probe()
3466 gd->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT; in sd_probe()
3469 blk_pm_runtime_init(sdp->request_queue, dev); in sd_probe()
3470 if (sdp->rpm_autosuspend) { in sd_probe()
3472 sdp->host->hostt->rpm_autosuspend_delay); in sd_probe()
3475 if (sdkp->capacity) in sd_probe()
3480 if (sdkp->security) { in sd_probe()
3481 sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit); in sd_probe()
3482 if (sdkp->opal_dev) in sd_probe()
3487 sdp->removable ? "removable " : ""); in sd_probe()
3488 scsi_autopm_put_device(sdp); in sd_probe()
3500 scsi_autopm_put_device(sdp); in sd_probe()
3505 * sd_remove - called whenever a scsi disk (previously recognized by
3510 * Note: this function is invoked from the scsi mid-level.
3512 * that could be re-used by a subsequent sd_probe().
3513 * This function is not called when the built-in sd driver is "exit-ed".
3521 devt = disk_devt(sdkp->disk); in sd_remove()
3522 scsi_autopm_get_device(sdkp->device); in sd_remove()
3525 device_del(&sdkp->dev); in sd_remove()
3526 del_gendisk(sdkp->disk); in sd_remove()
3529 free_opal_dev(sdkp->opal_dev); in sd_remove()
3536 put_device(&sdkp->dev); in sd_remove()
3543 * scsi_disk_release - Called to free the scsi_disk structure
3554 struct gendisk *disk = sdkp->disk; in scsi_disk_release()
3555 struct request_queue *q = disk->queue; in scsi_disk_release()
3557 ida_free(&sd_index_ida, sdkp->index); in scsi_disk_release()
3562 * due to clearing the disk->private_data pointer. Wait from inside in scsi_disk_release()
3570 disk->private_data = NULL; in scsi_disk_release()
3572 put_device(&sdkp->device->sdev_gendev); in scsi_disk_release()
3583 struct scsi_device *sdp = sdkp->device; in sd_start_stop_device() local
3589 if (sdp->start_stop_pwr_cond) in sd_start_stop_device()
3592 if (!scsi_device_online(sdp)) in sd_start_stop_device()
3593 return -ENODEV; in sd_start_stop_device()
3595 res = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, &sshdr, in sd_start_stop_device()
3596 SD_TIMEOUT, sdkp->max_retries, 0, RQF_PM, NULL); in sd_start_stop_device()
3609 return -EIO; in sd_start_stop_device()
3629 if (sdkp->WCE && sdkp->media_present) { in sd_shutdown()
3634 if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { in sd_shutdown()
3649 if (sdkp->WCE && sdkp->media_present) { in sd_suspend_common()
3655 if (ret == -ENODEV) in sd_suspend_common()
3671 if (sdkp->device->manage_start_stop) { in sd_suspend_common()
3700 if (!sdkp->device->manage_start_stop) in sd_resume()
3706 opal_unlock_from_suspend(sdkp->opal_dev); in sd_resume()
3711 * init_sd - entry point for this driver (both when built in or when
3714 * Note: this function registers this driver with the scsi mid-level.
3731 return -ENODEV; in init_sd()
3741 err = -ENOMEM; in init_sd()
3748 err = -ENOMEM; in init_sd()
3755 err = -ENOMEM; in init_sd()
3783 * exit_sd - exit point for this driver (when it is a module).
3785 * Note: this function unregisters this driver from the scsi mid-level.
3811 scsi_print_sense_hdr(sdkp->device, in sd_print_sense_hdr()
3812 sdkp->disk ? sdkp->disk->disk_name : NULL, sshdr); in sd_print_sense_hdr()