Lines Matching +full:assoc +full:- +full:select

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-scsi.c - helper library for ATA
5 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2004 Jeff Garzik
9 * as Documentation/driver-api/libata.rst
12 * - http://www.t10.org/
13 * - http://www.t13.org/
38 #include "libata-transport.h"
62 RW_RECOVERY_MPAGE_LEN - 2,
72 CACHE_MPAGE_LEN - 2,
81 CONTROL_MPAGE_LEN - 2,
83 0, /* [QAM+QERR may be 1, see 05-359r1] */
85 0, 30 /* extended self test time, see 05-359r1 */
99 ap = ata_shost_to_port(sdev->host); in ata_scsi_park_show()
101 spin_lock_irq(ap->lock); in ata_scsi_park_show()
104 rc = -ENODEV; in ata_scsi_park_show()
107 if (dev->flags & ATA_DFLAG_NO_UNLOAD) { in ata_scsi_park_show()
108 rc = -EOPNOTSUPP; in ata_scsi_park_show()
112 link = dev->link; in ata_scsi_park_show()
114 if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS && in ata_scsi_park_show()
115 link->eh_context.unloaded_mask & (1 << dev->devno) && in ata_scsi_park_show()
116 time_after(dev->unpark_deadline, now)) in ata_scsi_park_show()
117 msecs = jiffies_to_msecs(dev->unpark_deadline - now); in ata_scsi_park_show()
122 spin_unlock_irq(ap->lock); in ata_scsi_park_show()
141 if (input < -2) in ata_scsi_park_store()
142 return -EINVAL; in ata_scsi_park_store()
144 rc = -EOVERFLOW; in ata_scsi_park_store()
148 ap = ata_shost_to_port(sdev->host); in ata_scsi_park_store()
150 spin_lock_irqsave(ap->lock, flags); in ata_scsi_park_store()
153 rc = -ENODEV; in ata_scsi_park_store()
156 if (dev->class != ATA_DEV_ATA && in ata_scsi_park_store()
157 dev->class != ATA_DEV_ZAC) { in ata_scsi_park_store()
158 rc = -EOPNOTSUPP; in ata_scsi_park_store()
163 if (dev->flags & ATA_DFLAG_NO_UNLOAD) { in ata_scsi_park_store()
164 rc = -EOPNOTSUPP; in ata_scsi_park_store()
168 dev->unpark_deadline = ata_deadline(jiffies, input); in ata_scsi_park_store()
169 dev->link->eh_info.dev_action[dev->devno] |= ATA_EH_PARK; in ata_scsi_park_store()
171 complete(&ap->park_req_pending); in ata_scsi_park_store()
174 case -1: in ata_scsi_park_store()
175 dev->flags &= ~ATA_DFLAG_NO_UNLOAD; in ata_scsi_park_store()
177 case -2: in ata_scsi_park_store()
178 dev->flags |= ATA_DFLAG_NO_UNLOAD; in ata_scsi_park_store()
183 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_park_store()
194 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); in ata_scsi_set_sense()
199 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; in ata_scsi_set_sense()
201 scsi_build_sense_buffer(d_sense, cmd->sense_buffer, sk, asc, ascq); in ata_scsi_set_sense()
217 scsi_set_sense_information(cmd->sense_buffer, in ata_scsi_set_sense_information()
226 scsi_set_sense_field_pointer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, in ata_scsi_set_invalid_field()
235 scsi_set_sense_field_pointer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, in ata_scsi_set_invalid_parameter()
246 * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd.
276 * ata_scsi_unlock_native_capacity - unlock native capacity
287 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_unlock_native_capacity()
291 spin_lock_irqsave(ap->lock, flags); in ata_scsi_unlock_native_capacity()
294 if (dev && dev->n_sectors < dev->n_native_sectors) { in ata_scsi_unlock_native_capacity()
295 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_scsi_unlock_native_capacity()
296 dev->link->eh_info.action |= ATA_EH_RESET; in ata_scsi_unlock_native_capacity()
300 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_unlock_native_capacity()
306 * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl
325 return -ENOMSG; in ata_get_identity()
327 if (copy_to_user(dst, dev->id, ATA_ID_WORDS * sizeof(u16))) in ata_get_identity()
328 return -EFAULT; in ata_get_identity()
330 ata_id_string(dev->id, buf, ATA_ID_PROD, ATA_ID_PROD_LEN); in ata_get_identity()
332 return -EFAULT; in ata_get_identity()
334 ata_id_string(dev->id, buf, ATA_ID_FW_REV, ATA_ID_FW_REV_LEN); in ata_get_identity()
336 return -EFAULT; in ata_get_identity()
338 ata_id_string(dev->id, buf, ATA_ID_SERNO, ATA_ID_SERNO_LEN); in ata_get_identity()
340 return -EFAULT; in ata_get_identity()
346 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
368 return -EINVAL; in ata_cmd_ioctl()
371 return -EFAULT; in ata_cmd_ioctl()
380 rc = -ENOMEM; in ata_cmd_ioctl()
384 scsi_cmd[1] = (4 << 1); /* PIO Data-in */ in ata_cmd_ioctl()
389 scsi_cmd[1] = (3 << 1); /* Non-data */ in ata_cmd_ioctl()
397 if (args[0] == ATA_CMD_SMART) { /* hack -- ide driver does this too */ in ata_cmd_ioctl()
416 /* If we set cc then ATA pass-through will cause a in ata_cmd_ioctl()
431 rc = -EFAULT; in ata_cmd_ioctl()
437 rc = -EIO; in ata_cmd_ioctl()
443 rc = -EFAULT; in ata_cmd_ioctl()
450 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
470 return -EINVAL; in ata_task_ioctl()
473 return -EFAULT; in ata_task_ioctl()
478 scsi_cmd[1] = (3 << 1); /* Non-data */ in ata_task_ioctl()
497 /* If we set cc then ATA pass-through will cause a in ata_task_ioctl()
514 args[6] = desc[12]; /* select */ in ata_task_ioctl()
516 rc = -EFAULT; in ata_task_ioctl()
521 rc = -EIO; in ata_task_ioctl()
531 if (ap->flags & ATA_FLAG_PIO_DMA) in ata_ioc32()
533 if (ap->pflags & ATA_PFLAG_PIO32) in ata_ioc32()
546 int rc = -EINVAL; in ata_sas_scsi_ioctl()
551 spin_lock_irqsave(ap->lock, flags); in ata_sas_scsi_ioctl()
553 spin_unlock_irqrestore(ap->lock, flags); in ata_sas_scsi_ioctl()
563 spin_lock_irqsave(ap->lock, flags); in ata_sas_scsi_ioctl()
564 if (ap->pflags & ATA_PFLAG_PIO32CHANGE) { in ata_sas_scsi_ioctl()
566 ap->pflags |= ATA_PFLAG_PIO32; in ata_sas_scsi_ioctl()
568 ap->pflags &= ~ATA_PFLAG_PIO32; in ata_sas_scsi_ioctl()
571 rc = -EINVAL; in ata_sas_scsi_ioctl()
573 spin_unlock_irqrestore(ap->lock, flags); in ata_sas_scsi_ioctl()
581 return -EACCES; in ata_sas_scsi_ioctl()
586 return -EACCES; in ata_sas_scsi_ioctl()
590 rc = -ENOTTY; in ata_sas_scsi_ioctl()
601 return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host), in ata_scsi_ioctl()
607 * ata_scsi_qc_new - acquire new ata_queued_cmd reference
615 * If a command was available, fill in the SCSI-specific
630 qc = ata_qc_new_init(dev, cmd->request->tag); in ata_scsi_qc_new()
632 qc->scsicmd = cmd; in ata_scsi_qc_new()
633 qc->scsidone = cmd->scsi_done; in ata_scsi_qc_new()
635 qc->sg = scsi_sglist(cmd); in ata_scsi_qc_new()
636 qc->n_elem = scsi_sg_count(cmd); in ata_scsi_qc_new()
638 if (cmd->request->rq_flags & RQF_QUIET) in ata_scsi_qc_new()
639 qc->flags |= ATA_QCFLAG_QUIET; in ata_scsi_qc_new()
641 cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1); in ata_scsi_qc_new()
642 cmd->scsi_done(cmd); in ata_scsi_qc_new()
650 struct scsi_cmnd *scmd = qc->scsicmd; in ata_qc_set_pc_nbytes()
652 qc->extrabytes = scmd->extra_len; in ata_qc_set_pc_nbytes()
653 qc->nbytes = scsi_bufflen(scmd) + qc->extrabytes; in ata_qc_set_pc_nbytes()
657 * ata_dump_status - user friendly display of error info
663 * make-believe layer.
670 u8 stat = tf->command, err = tf->feature; in ata_dump_status()
703 * ata_to_sense_error - convert ATA error to SCSI error
747 /* TRK0 - Track 0 not found */ in ata_to_sense_error()
754 /* SRV/IDNF - ID not found */ in ata_to_sense_error()
757 /* MC - Media Changed */ in ata_to_sense_error()
760 /* ECC - Uncorrectable ECC error */ in ata_to_sense_error()
763 /* BBD - block marked bad */ in ata_to_sense_error()
834 * ata_gen_passthru_sense - Generate check condition sense block.
844 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE
852 struct scsi_cmnd *cmd = qc->scsicmd; in ata_gen_passthru_sense()
853 struct ata_taskfile *tf = &qc->result_tf; in ata_gen_passthru_sense()
854 unsigned char *sb = cmd->sense_buffer; in ata_gen_passthru_sense()
856 int verbose = qc->ap->ops->error_handler == NULL; in ata_gen_passthru_sense()
861 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; in ata_gen_passthru_sense()
867 if (qc->err_mask || in ata_gen_passthru_sense()
868 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { in ata_gen_passthru_sense()
869 ata_to_sense_error(qc->ap->print_id, tf->command, tf->feature, in ata_gen_passthru_sense()
871 ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq); in ata_gen_passthru_sense()
874 * ATA PASS-THROUGH INFORMATION AVAILABLE in ata_gen_passthru_sense()
877 scsi_build_sense_buffer(1, cmd->sense_buffer, in ata_gen_passthru_sense()
881 if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { in ata_gen_passthru_sense()
899 desc[3] = tf->feature; /* == error reg */ in ata_gen_passthru_sense()
900 desc[5] = tf->nsect; in ata_gen_passthru_sense()
901 desc[7] = tf->lbal; in ata_gen_passthru_sense()
902 desc[9] = tf->lbam; in ata_gen_passthru_sense()
903 desc[11] = tf->lbah; in ata_gen_passthru_sense()
904 desc[12] = tf->device; in ata_gen_passthru_sense()
905 desc[13] = tf->command; /* == status reg */ in ata_gen_passthru_sense()
911 if (tf->flags & ATA_TFLAG_LBA48) { in ata_gen_passthru_sense()
913 desc[4] = tf->hob_nsect; in ata_gen_passthru_sense()
914 desc[6] = tf->hob_lbal; in ata_gen_passthru_sense()
915 desc[8] = tf->hob_lbam; in ata_gen_passthru_sense()
916 desc[10] = tf->hob_lbah; in ata_gen_passthru_sense()
920 desc[0] = tf->feature; in ata_gen_passthru_sense()
921 desc[1] = tf->command; /* status */ in ata_gen_passthru_sense()
922 desc[2] = tf->device; in ata_gen_passthru_sense()
923 desc[3] = tf->nsect; in ata_gen_passthru_sense()
925 if (tf->flags & ATA_TFLAG_LBA48) { in ata_gen_passthru_sense()
927 if (tf->hob_nsect) in ata_gen_passthru_sense()
929 if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) in ata_gen_passthru_sense()
932 desc[9] = tf->lbal; in ata_gen_passthru_sense()
933 desc[10] = tf->lbam; in ata_gen_passthru_sense()
934 desc[11] = tf->lbah; in ata_gen_passthru_sense()
939 * ata_gen_ata_sense - generate a SCSI fixed sense block
950 struct ata_device *dev = qc->dev; in ata_gen_ata_sense()
951 struct scsi_cmnd *cmd = qc->scsicmd; in ata_gen_ata_sense()
952 struct ata_taskfile *tf = &qc->result_tf; in ata_gen_ata_sense()
953 unsigned char *sb = cmd->sense_buffer; in ata_gen_ata_sense()
954 int verbose = qc->ap->ops->error_handler == NULL; in ata_gen_ata_sense()
960 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; in ata_gen_ata_sense()
971 if (qc->err_mask || in ata_gen_ata_sense()
972 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { in ata_gen_ata_sense()
973 ata_to_sense_error(qc->ap->print_id, tf->command, tf->feature, in ata_gen_ata_sense()
979 tf->command, qc->err_mask); in ata_gen_ata_sense()
984 block = ata_tf_read_block(&qc->result_tf, dev); in ata_gen_ata_sense()
993 sdev->use_10_for_rw = 1; in ata_scsi_sdev_config()
994 sdev->use_10_for_ms = 1; in ata_scsi_sdev_config()
995 sdev->no_write_same = 1; in ata_scsi_sdev_config()
997 /* Schedule policy is determined by ->qc_defer() callback and in ata_scsi_sdev_config()
1002 sdev->max_device_blocked = 1; in ata_scsi_sdev_config()
1006 * ata_scsi_dma_need_drain - Check whether data transfer may overflow
1022 return atapi_cmd_type(scsi_req(rq)->cmd[0]) == ATAPI_MISC; in ata_scsi_dma_need_drain()
1028 struct request_queue *q = sdev->request_queue; in ata_scsi_dev_config()
1030 if (!ata_id_has_unload(dev->id)) in ata_scsi_dev_config()
1031 dev->flags |= ATA_DFLAG_NO_UNLOAD; in ata_scsi_dev_config()
1034 blk_queue_max_hw_sectors(q, dev->max_sectors); in ata_scsi_dev_config()
1036 if (dev->class == ATA_DEV_ATAPI) { in ata_scsi_dev_config()
1037 sdev->sector_size = ATA_SECT_SIZE; in ata_scsi_dev_config()
1040 blk_queue_update_dma_pad(q, ATA_DMA_PAD_SZ - 1); in ata_scsi_dev_config()
1043 blk_queue_max_segments(q, queue_max_segments(q) - 1); in ata_scsi_dev_config()
1045 sdev->dma_drain_len = ATAPI_MAX_DRAIN; in ata_scsi_dev_config()
1046 sdev->dma_drain_buf = kmalloc(sdev->dma_drain_len, in ata_scsi_dev_config()
1047 q->bounce_gfp | GFP_KERNEL); in ata_scsi_dev_config()
1048 if (!sdev->dma_drain_buf) { in ata_scsi_dev_config()
1050 return -ENOMEM; in ata_scsi_dev_config()
1053 sdev->sector_size = ata_id_logical_sector_size(dev->id); in ata_scsi_dev_config()
1054 sdev->manage_start_stop = 1; in ata_scsi_dev_config()
1064 if (sdev->sector_size > PAGE_SIZE) in ata_scsi_dev_config()
1067 sdev->sector_size); in ata_scsi_dev_config()
1069 blk_queue_update_dma_alignment(q, sdev->sector_size - 1); in ata_scsi_dev_config()
1071 if (dev->flags & ATA_DFLAG_AN) in ata_scsi_dev_config()
1072 set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events); in ata_scsi_dev_config()
1074 if (dev->flags & ATA_DFLAG_NCQ) { in ata_scsi_dev_config()
1077 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); in ata_scsi_dev_config()
1082 if (dev->flags & ATA_DFLAG_TRUSTED) in ata_scsi_dev_config()
1083 sdev->security_supported = 1; in ata_scsi_dev_config()
1085 dev->sdev = sdev; in ata_scsi_dev_config()
1090 * ata_scsi_slave_config - Set SCSI device attributes
1095 * SCSI mid-layer behaviors.
1103 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_config()
1117 * ata_scsi_slave_destroy - SCSI device is about to be destroyed
1122 * dev->sdev, this function doesn't have to do anything.
1123 * Otherwise, SCSI layer initiated warm-unplug is in progress.
1124 * Clear dev->sdev, schedule the device for ATA detach and invoke
1132 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_destroy()
1136 if (!ap->ops->error_handler) in ata_scsi_slave_destroy()
1139 spin_lock_irqsave(ap->lock, flags); in ata_scsi_slave_destroy()
1141 if (dev && dev->sdev) { in ata_scsi_slave_destroy()
1143 dev->sdev = NULL; in ata_scsi_slave_destroy()
1144 dev->flags |= ATA_DFLAG_DETACH; in ata_scsi_slave_destroy()
1147 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_slave_destroy()
1149 kfree(sdev->dma_drain_buf); in ata_scsi_slave_destroy()
1154 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
1166 * Zero on success, non-zero on error.
1170 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_start_stop_xlat()
1171 struct ata_taskfile *tf = &qc->tf; in ata_scsi_start_stop_xlat()
1172 const u8 *cdb = scmd->cmnd; in ata_scsi_start_stop_xlat()
1176 if (scmd->cmd_len < 5) { in ata_scsi_start_stop_xlat()
1181 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_scsi_start_stop_xlat()
1182 tf->protocol = ATA_PROT_NODATA; in ata_scsi_start_stop_xlat()
1184 ; /* ignore IMMED bit, violates sat-r05 */ in ata_scsi_start_stop_xlat()
1198 tf->nsect = 1; /* 1 sector, lba=0 */ in ata_scsi_start_stop_xlat()
1200 if (qc->dev->flags & ATA_DFLAG_LBA) { in ata_scsi_start_stop_xlat()
1201 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_start_stop_xlat()
1203 tf->lbah = 0x0; in ata_scsi_start_stop_xlat()
1204 tf->lbam = 0x0; in ata_scsi_start_stop_xlat()
1205 tf->lbal = 0x0; in ata_scsi_start_stop_xlat()
1206 tf->device |= ATA_LBA; in ata_scsi_start_stop_xlat()
1209 tf->lbal = 0x1; /* sect */ in ata_scsi_start_stop_xlat()
1210 tf->lbam = 0x0; /* cyl low */ in ata_scsi_start_stop_xlat()
1211 tf->lbah = 0x0; /* cyl high */ in ata_scsi_start_stop_xlat()
1214 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ in ata_scsi_start_stop_xlat()
1219 if ((qc->ap->flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && in ata_scsi_start_stop_xlat()
1223 if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && in ata_scsi_start_stop_xlat()
1228 tf->command = ATA_CMD_STANDBYNOW1; in ata_scsi_start_stop_xlat()
1235 * MODE SELECT to be implemented. in ata_scsi_start_stop_xlat()
1241 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_start_stop_xlat()
1244 scmd->result = SAM_STAT_GOOD; in ata_scsi_start_stop_xlat()
1250 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command
1260 * Zero on success, non-zero on error.
1264 struct ata_taskfile *tf = &qc->tf; in ata_scsi_flush_xlat()
1266 tf->flags |= ATA_TFLAG_DEVICE; in ata_scsi_flush_xlat()
1267 tf->protocol = ATA_PROT_NODATA; in ata_scsi_flush_xlat()
1269 if (qc->dev->flags & ATA_DFLAG_FLUSH_EXT) in ata_scsi_flush_xlat()
1270 tf->command = ATA_CMD_FLUSH_EXT; in ata_scsi_flush_xlat()
1272 tf->command = ATA_CMD_FLUSH; in ata_scsi_flush_xlat()
1275 qc->flags |= ATA_QCFLAG_IO; in ata_scsi_flush_xlat()
1281 * scsi_6_lba_len - Get LBA and transfer length
1284 * Calculate LBA and transfer length for 6-byte commands.
1295 VPRINTK("six-byte command\n"); in scsi_6_lba_len()
1308 * scsi_10_lba_len - Get LBA and transfer length
1311 * Calculate LBA and transfer length for 10-byte commands.
1322 VPRINTK("ten-byte command\n"); in scsi_10_lba_len()
1337 * scsi_16_lba_len - Get LBA and transfer length
1340 * Calculate LBA and transfer length for 16-byte commands.
1351 VPRINTK("sixteen-byte command\n"); in scsi_16_lba_len()
1372 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
1381 * Zero on success, non-zero on error.
1385 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_verify_xlat()
1386 struct ata_taskfile *tf = &qc->tf; in ata_scsi_verify_xlat()
1387 struct ata_device *dev = qc->dev; in ata_scsi_verify_xlat()
1388 u64 dev_sectors = qc->dev->n_sectors; in ata_scsi_verify_xlat()
1389 const u8 *cdb = scmd->cmnd; in ata_scsi_verify_xlat()
1394 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_scsi_verify_xlat()
1395 tf->protocol = ATA_PROT_NODATA; in ata_scsi_verify_xlat()
1398 if (scmd->cmd_len < 10) { in ata_scsi_verify_xlat()
1404 if (scmd->cmd_len < 16) { in ata_scsi_verify_xlat()
1421 if (dev->flags & ATA_DFLAG_LBA) { in ata_scsi_verify_xlat()
1422 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_verify_xlat()
1426 tf->command = ATA_CMD_VERIFY; in ata_scsi_verify_xlat()
1427 tf->device |= (block >> 24) & 0xf; in ata_scsi_verify_xlat()
1429 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_scsi_verify_xlat()
1433 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_verify_xlat()
1434 tf->command = ATA_CMD_VERIFY_EXT; in ata_scsi_verify_xlat()
1436 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_scsi_verify_xlat()
1438 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_verify_xlat()
1439 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_verify_xlat()
1440 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_verify_xlat()
1445 tf->nsect = n_block & 0xff; in ata_scsi_verify_xlat()
1447 tf->lbah = (block >> 16) & 0xff; in ata_scsi_verify_xlat()
1448 tf->lbam = (block >> 8) & 0xff; in ata_scsi_verify_xlat()
1449 tf->lbal = block & 0xff; in ata_scsi_verify_xlat()
1451 tf->device |= ATA_LBA; in ata_scsi_verify_xlat()
1460 track = (u32)block / dev->sectors; in ata_scsi_verify_xlat()
1461 cyl = track / dev->heads; in ata_scsi_verify_xlat()
1462 head = track % dev->heads; in ata_scsi_verify_xlat()
1463 sect = (u32)block % dev->sectors + 1; in ata_scsi_verify_xlat()
1469 Cylinder: 0-65535 in ata_scsi_verify_xlat()
1470 Head: 0-15 in ata_scsi_verify_xlat()
1471 Sector: 1-255*/ in ata_scsi_verify_xlat()
1475 tf->command = ATA_CMD_VERIFY; in ata_scsi_verify_xlat()
1476 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_scsi_verify_xlat()
1477 tf->lbal = sect; in ata_scsi_verify_xlat()
1478 tf->lbam = cyl; in ata_scsi_verify_xlat()
1479 tf->lbah = cyl >> 8; in ata_scsi_verify_xlat()
1480 tf->device |= head; in ata_scsi_verify_xlat()
1486 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_verify_xlat()
1490 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x21, 0x0); in ata_scsi_verify_xlat()
1495 scmd->result = SAM_STAT_GOOD; in ata_scsi_verify_xlat()
1501 struct request *rq = scmd->request; in ata_check_nblocks()
1507 req_blocks = blk_rq_bytes(rq) / scmd->device->sector_size; in ata_check_nblocks()
1515 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one
1530 * Zero on success, non-zero on error.
1534 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_rw_xlat()
1535 const u8 *cdb = scmd->cmnd; in ata_scsi_rw_xlat()
1536 struct request *rq = scmd->request; in ata_scsi_rw_xlat()
1551 if (unlikely(scmd->cmd_len < 10)) { in ata_scsi_rw_xlat()
1563 if (unlikely(scmd->cmd_len < 6)) { in ata_scsi_rw_xlat()
1569 /* for 6-byte r/w commands, transfer length 0 in ata_scsi_rw_xlat()
1579 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_rw_xlat()
1590 DPRINTK("no-byte command\n"); in ata_scsi_rw_xlat()
1597 /* For 10-byte and 16-byte SCSI R/W commands, transfer in ata_scsi_rw_xlat()
1606 qc->flags |= ATA_QCFLAG_IO; in ata_scsi_rw_xlat()
1607 qc->nbytes = n_block * scmd->device->sector_size; in ata_scsi_rw_xlat()
1609 rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, in ata_scsi_rw_xlat()
1610 qc->hw_tag, class); in ata_scsi_rw_xlat()
1615 if (rc == -ERANGE) in ata_scsi_rw_xlat()
1617 /* treat all other errors as -EINVAL, fall through */ in ata_scsi_rw_xlat()
1619 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_rw_xlat()
1623 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x21, 0x0); in ata_scsi_rw_xlat()
1628 scmd->result = SAM_STAT_GOOD; in ata_scsi_rw_xlat()
1634 struct scsi_cmnd *cmd = qc->scsicmd; in ata_qc_done()
1635 void (*done)(struct scsi_cmnd *) = qc->scsidone; in ata_qc_done()
1643 struct ata_port *ap = qc->ap; in ata_scsi_qc_complete()
1644 struct scsi_cmnd *cmd = qc->scsicmd; in ata_scsi_qc_complete()
1645 u8 *cdb = cmd->cmnd; in ata_scsi_qc_complete()
1646 int need_sense = (qc->err_mask != 0); in ata_scsi_qc_complete()
1655 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE in ata_scsi_qc_complete()
1660 else if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_scsi_qc_complete()
1661 cmd->result = SAM_STAT_CHECK_CONDITION; in ata_scsi_qc_complete()
1665 cmd->result = SAM_STAT_GOOD; in ata_scsi_qc_complete()
1667 if (need_sense && !ap->ops->error_handler) in ata_scsi_qc_complete()
1668 ata_dump_status(ap->print_id, &qc->result_tf); in ata_scsi_qc_complete()
1674 * ata_scsi_translate - Translate then issue SCSI command to ATA device
1679 * Our ->queuecommand() function has decided that the SCSI
1688 * then cmd->result (and possibly cmd->sense_buffer) are assumed
1702 struct ata_port *ap = dev->link->ap; in ata_scsi_translate()
1712 /* data is present; dma-map it */ in ata_scsi_translate()
1713 if (cmd->sc_data_direction == DMA_FROM_DEVICE || in ata_scsi_translate()
1714 cmd->sc_data_direction == DMA_TO_DEVICE) { in ata_scsi_translate()
1722 qc->dma_dir = cmd->sc_data_direction; in ata_scsi_translate()
1725 qc->complete_fn = ata_scsi_qc_complete; in ata_scsi_translate()
1730 if (ap->ops->qc_defer) { in ata_scsi_translate()
1731 if ((rc = ap->ops->qc_defer(qc))) in ata_scsi_translate()
1735 /* select device, send command to hardware */ in ata_scsi_translate()
1743 cmd->scsi_done(cmd); in ata_scsi_translate()
1744 DPRINTK("EXIT - early finish (good or error)\n"); in ata_scsi_translate()
1749 cmd->result = (DID_ERROR << 16); in ata_scsi_translate()
1750 cmd->scsi_done(cmd); in ata_scsi_translate()
1752 DPRINTK("EXIT - internal\n"); in ata_scsi_translate()
1757 DPRINTK("EXIT - defer\n"); in ata_scsi_translate()
1771 * ata_scsi_rbuf_get - Map response buffer.
1797 * ata_scsi_rbuf_put - Unmap response buffer.
1818 * ata_scsi_rbuf_fill - wrapper for SCSI command simulators
1826 * completed successfully (0), or not (in which case cmd->result
1837 struct scsi_cmnd *cmd = args->cmd; in ata_scsi_rbuf_fill()
1845 cmd->result = SAM_STAT_GOOD; in ata_scsi_rbuf_fill()
1849 * ata_scsiop_inq_std - Simulate INQUIRY command
1854 * with non-VPD INQUIRY command output.
1863 0x60, /* SAM-3 (no version claimed) */ in ata_scsiop_inq_std()
1866 0x20, /* SBC-2 (no version claimed) */ in ata_scsiop_inq_std()
1869 0x00 /* SPC-3 (no version claimed) */ in ata_scsiop_inq_std()
1873 0xA0, /* SAM-5 (no version claimed) */ in ata_scsiop_inq_std()
1876 0x00, /* SBC-4 (no version claimed) */ in ata_scsiop_inq_std()
1879 0xC0, /* SPC-5 (no version claimed) */ in ata_scsiop_inq_std()
1888 0x5, /* claim SPC-3 version compatibility */ in ata_scsiop_inq_std()
1890 95 - 4, in ata_scsiop_inq_std()
1899 * AHCI port says it's external (Hotplug-capable, eSATA). in ata_scsiop_inq_std()
1901 if (ata_id_removable(args->id) || in ata_scsiop_inq_std()
1902 (args->dev->link->ap->pflags & ATA_PFLAG_EXTERNAL)) in ata_scsiop_inq_std()
1905 if (args->dev->class == ATA_DEV_ZAC) { in ata_scsiop_inq_std()
1907 hdr[2] = 0x7; /* claim SPC-5 version compatibility */ in ata_scsiop_inq_std()
1912 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16); in ata_scsiop_inq_std()
1915 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV + 2, 4); in ata_scsiop_inq_std()
1917 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4); in ata_scsiop_inq_std()
1922 if (ata_id_zoned_cap(args->id) || args->dev->class == ATA_DEV_ZAC) in ata_scsiop_inq_std()
1931 * ata_scsiop_inq_00 - Simulate INQUIRY VPD page 0, list of pages
1955 if (!(args->dev->flags & ATA_DFLAG_ZAC)) in ata_scsiop_inq_00()
1956 num_pages--; in ata_scsiop_inq_00()
1963 * ata_scsiop_inq_80 - Simulate INQUIRY VPD page 80, device serial number
1982 ata_id_string(args->id, (unsigned char *) &rbuf[4], in ata_scsiop_inq_80()
1988 * ata_scsiop_inq_83 - Simulate INQUIRY VPD page 83, device identity
1993 * - vendor specific ASCII containing the ATA serial number
1994 * - SAT defined "t10 vendor id based" containing ASCII vendor
2008 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */ in ata_scsiop_inq_83()
2012 ata_id_string(args->id, (unsigned char *) rbuf + num, in ata_scsiop_inq_83()
2017 /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */ in ata_scsiop_inq_83()
2024 ata_id_string(args->id, (unsigned char *) rbuf + num, ATA_ID_PROD, in ata_scsiop_inq_83()
2027 ata_id_string(args->id, (unsigned char *) rbuf + num, ATA_ID_SERNO, in ata_scsiop_inq_83()
2031 if (ata_id_has_wwn(args->id)) { in ata_scsiop_inq_83()
2033 /* piv=0, assoc=lu, code_set=binary, designator=NAA */ in ata_scsiop_inq_83()
2038 ata_id_string(args->id, (unsigned char *) rbuf + num, in ata_scsiop_inq_83()
2042 rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */ in ata_scsiop_inq_83()
2047 * ata_scsiop_inq_89 - Simulate INQUIRY VPD page 89, ATA info
2051 * Yields SAT-specified ATA VPD page.
2077 memcpy(&rbuf[60], &args->id[0], 512); in ata_scsiop_inq_89()
2083 struct ata_device *dev = args->dev; in ata_scsiop_inq_b0()
2096 min_io_sectors = 1 << ata_id_log2_per_physical_sector(args->id); in ata_scsiop_inq_b0()
2105 * that we support some form of unmap - in thise case via WRITE SAME in ata_scsiop_inq_b0()
2108 if (ata_id_has_trim(args->id)) { in ata_scsiop_inq_b0()
2111 if (dev->horkage & ATA_HORKAGE_MAX_TRIM_128M) in ata_scsiop_inq_b0()
2112 max_blocks = 128 << (20 - SECTOR_SHIFT); in ata_scsiop_inq_b0()
2123 int form_factor = ata_id_form_factor(args->id); in ata_scsiop_inq_b1()
2124 int media_rotation_rate = ata_id_rotation_rate(args->id); in ata_scsiop_inq_b1()
2125 u8 zoned = ata_id_zoned_cap(args->id); in ata_scsiop_inq_b1()
2140 /* SCSI Thin Provisioning VPD page: SBC-3 rev 22 or later */ in ata_scsiop_inq_b2()
2151 * zbc-r05 SCSI Zoned Block device characteristics VPD page in ata_scsiop_inq_b6()
2157 * URSWRZ bit is only meaningful for host-managed ZAC drives in ata_scsiop_inq_b6()
2159 if (args->dev->zac_zoned_cap & 1) in ata_scsiop_inq_b6()
2161 put_unaligned_be32(args->dev->zac_zones_optimal_open, &rbuf[8]); in ata_scsiop_inq_b6()
2162 put_unaligned_be32(args->dev->zac_zones_optimal_nonseq, &rbuf[12]); in ata_scsiop_inq_b6()
2163 put_unaligned_be32(args->dev->zac_zones_max_open, &rbuf[16]); in ata_scsiop_inq_b6()
2169 * modecpy - Prepare response for MODE SENSE
2185 memset(dest + 2, 0, n - 2); in modecpy()
2192 * ata_msense_caching - Simulate MODE SENSE caching info page
2217 * ata_msense_control - Simulate MODE SENSE control mode page
2234 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); in ata_msense_control()
2242 * ata_msense_rw_recovery - Simulate MODE SENSE r/w error recovery page
2283 * ata_scsiop_mode_sense - Simulate MODE SENSE 6, 10 commands
2296 struct ata_device *dev = args->dev; in ata_scsiop_mode_sense()
2297 u8 *scsicmd = args->cmd->cmnd, *p = rbuf; in ata_scsiop_mode_sense()
2352 p += ata_msense_caching(args->id, p, page_control == 1); in ata_scsiop_mode_sense()
2356 p += ata_msense_control(args->dev, p, page_control == 1); in ata_scsiop_mode_sense()
2361 p += ata_msense_caching(args->id, p, page_control == 1); in ata_scsiop_mode_sense()
2362 p += ata_msense_control(args->dev, p, page_control == 1); in ata_scsiop_mode_sense()
2371 if (ata_dev_supports_fua(args->id) && (dev->flags & ATA_DFLAG_LBA48) && in ata_scsiop_mode_sense()
2372 (!(dev->flags & ATA_DFLAG_PIO) || dev->multi_count)) in ata_scsiop_mode_sense()
2376 rbuf[0] = p - rbuf - 1; in ata_scsiop_mode_sense()
2383 unsigned int output_len = p - rbuf - 2; in ata_scsiop_mode_sense()
2396 ata_scsi_set_invalid_field(dev, args->cmd, fp, bp); in ata_scsiop_mode_sense()
2400 ata_scsi_set_sense(dev, args->cmd, ILLEGAL_REQUEST, 0x39, 0x0); in ata_scsiop_mode_sense()
2406 * ata_scsiop_read_cap - Simulate READ CAPACITY[ 16] commands
2417 struct ata_device *dev = args->dev; in ata_scsiop_read_cap()
2418 u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */ in ata_scsiop_read_cap()
2423 sector_size = ata_id_logical_sector_size(dev->id); in ata_scsiop_read_cap()
2424 log2_per_phys = ata_id_log2_per_physical_sector(dev->id); in ata_scsiop_read_cap()
2425 lowest_aligned = ata_id_logical_sector_offset(dev->id, log2_per_phys); in ata_scsiop_read_cap()
2429 if (args->cmd->cmnd[0] == READ_CAPACITY) { in ata_scsiop_read_cap()
2433 /* sector count, 32-bit */ in ata_scsiop_read_cap()
2445 /* sector count, 64-bit */ in ata_scsiop_read_cap()
2466 if (ata_id_has_trim(args->id) && in ata_scsiop_read_cap()
2467 !(dev->horkage & ATA_HORKAGE_NOTRIM)) { in ata_scsiop_read_cap()
2470 if (ata_id_has_zero_after_trim(args->id) && in ata_scsiop_read_cap()
2471 dev->horkage & ATA_HORKAGE_ZERO_AFTER_TRIM) { in ata_scsiop_read_cap()
2476 if (ata_id_zoned_cap(args->id) || in ata_scsiop_read_cap()
2477 args->dev->class == ATA_DEV_ZAC) in ata_scsiop_read_cap()
2484 * ata_scsiop_report_luns - Simulate REPORT LUNS command
2503 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) { in atapi_sense_complete()
2518 return (ap->flags & ATA_FLAG_PIO_DMA); in ata_pio_use_silly()
2523 struct ata_port *ap = qc->ap; in atapi_request_sense()
2524 struct scsi_cmnd *cmd = qc->scsicmd; in atapi_request_sense()
2528 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in atapi_request_sense()
2531 if (ap->ops->sff_tf_read) in atapi_request_sense()
2532 ap->ops->sff_tf_read(ap, &qc->tf); in atapi_request_sense()
2535 /* fill these in, for the case where they are -not- overwritten */ in atapi_request_sense()
2536 cmd->sense_buffer[0] = 0x70; in atapi_request_sense()
2537 cmd->sense_buffer[2] = qc->tf.feature >> 4; in atapi_request_sense()
2542 sg_init_one(&qc->sgent, cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); in atapi_request_sense()
2543 ata_sg_init(qc, &qc->sgent, 1); in atapi_request_sense()
2544 qc->dma_dir = DMA_FROM_DEVICE; in atapi_request_sense()
2546 memset(&qc->cdb, 0, qc->dev->cdb_len); in atapi_request_sense()
2547 qc->cdb[0] = REQUEST_SENSE; in atapi_request_sense()
2548 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; in atapi_request_sense()
2550 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in atapi_request_sense()
2551 qc->tf.command = ATA_CMD_PACKET; in atapi_request_sense()
2554 qc->tf.protocol = ATAPI_PROT_DMA; in atapi_request_sense()
2555 qc->tf.feature |= ATAPI_PKT_DMA; in atapi_request_sense()
2557 qc->tf.protocol = ATAPI_PROT_PIO; in atapi_request_sense()
2558 qc->tf.lbam = SCSI_SENSE_BUFFERSIZE; in atapi_request_sense()
2559 qc->tf.lbah = 0; in atapi_request_sense()
2561 qc->nbytes = SCSI_SENSE_BUFFERSIZE; in atapi_request_sense()
2563 qc->complete_fn = atapi_sense_complete; in atapi_request_sense()
2574 * 1) Fake MMC-5 version, to indicate to the Linux scsi midlayer this is a
2592 struct scsi_cmnd *cmd = qc->scsicmd; in atapi_qc_complete()
2593 unsigned int err_mask = qc->err_mask; in atapi_qc_complete()
2598 if (unlikely(qc->ap->ops->error_handler && in atapi_qc_complete()
2599 (err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID))) { in atapi_qc_complete()
2601 if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) { in atapi_qc_complete()
2610 /* SCSI EH automatically locks door if sdev->locked is in atapi_qc_complete()
2613 * creates a loop - SCSI EH issues door lock which in atapi_qc_complete()
2617 * If door lock fails, always clear sdev->locked to in atapi_qc_complete()
2621 * sure qc->dev->sdev isn't NULL before dereferencing. in atapi_qc_complete()
2623 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev) in atapi_qc_complete()
2624 qc->dev->sdev->locked = 0; in atapi_qc_complete()
2626 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; in atapi_qc_complete()
2633 cmd->result = SAM_STAT_CHECK_CONDITION; in atapi_qc_complete()
2644 if (cmd->cmnd[0] == INQUIRY && (cmd->cmnd[1] & 0x03) == 0) in atapi_qc_complete()
2646 cmd->result = SAM_STAT_GOOD; in atapi_qc_complete()
2652 * atapi_xlat - Initialize PACKET taskfile
2659 * Zero on success, non-zero on failure.
2663 struct scsi_cmnd *scmd = qc->scsicmd; in atapi_xlat()
2664 struct ata_device *dev = qc->dev; in atapi_xlat()
2665 int nodata = (scmd->sc_data_direction == DMA_NONE); in atapi_xlat()
2666 int using_pio = !nodata && (dev->flags & ATA_DFLAG_PIO); in atapi_xlat()
2669 memset(qc->cdb, 0, dev->cdb_len); in atapi_xlat()
2670 memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len); in atapi_xlat()
2672 qc->complete_fn = atapi_qc_complete; in atapi_xlat()
2674 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in atapi_xlat()
2675 if (scmd->sc_data_direction == DMA_TO_DEVICE) { in atapi_xlat()
2676 qc->tf.flags |= ATA_TFLAG_WRITE; in atapi_xlat()
2680 qc->tf.command = ATA_CMD_PACKET; in atapi_xlat()
2721 qc->tf.lbam = (nbytes & 0xFF); in atapi_xlat()
2722 qc->tf.lbah = (nbytes >> 8); in atapi_xlat()
2725 qc->tf.protocol = ATAPI_PROT_NODATA; in atapi_xlat()
2727 qc->tf.protocol = ATAPI_PROT_PIO; in atapi_xlat()
2730 qc->tf.protocol = ATAPI_PROT_DMA; in atapi_xlat()
2731 qc->tf.feature |= ATAPI_PKT_DMA; in atapi_xlat()
2733 if ((dev->flags & ATA_DFLAG_DMADIR) && in atapi_xlat()
2734 (scmd->sc_data_direction != DMA_TO_DEVICE)) in atapi_xlat()
2736 qc->tf.feature |= ATAPI_DMADIR; in atapi_xlat()
2749 devno < ata_link_max_devices(&ap->link))) in ata_find_dev()
2750 return &ap->link.device[devno]; in ata_find_dev()
2753 devno < ap->nr_pmp_links)) in ata_find_dev()
2754 return &ap->pmp_link[devno].device[0]; in ata_find_dev()
2767 if (unlikely(scsidev->channel || scsidev->lun)) in __ata_scsi_find_dev()
2769 devno = scsidev->id; in __ata_scsi_find_dev()
2771 if (unlikely(scsidev->id || scsidev->lun)) in __ata_scsi_find_dev()
2773 devno = scsidev->channel; in __ata_scsi_find_dev()
2780 * ata_scsi_find_dev - lookup ata_device from scsi_cmnd
2807 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
2808 * @byte1: Byte 1 from pass-thru CDB.
2817 case 3: /* Non-data */ in ata_scsi_map_proto()
2821 case 10: /* UDMA Data-in */ in ata_scsi_map_proto()
2822 case 11: /* UDMA Data-Out */ in ata_scsi_map_proto()
2825 case 4: /* PIO Data-in */ in ata_scsi_map_proto()
2826 case 5: /* PIO Data-out */ in ata_scsi_map_proto()
2846 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2849 * Handles either 12, 16, or 32-byte versions of the CDB.
2852 * Zero on success, non-zero on failure.
2856 struct ata_taskfile *tf = &(qc->tf); in ata_scsi_pass_thru()
2857 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_pass_thru()
2858 struct ata_device *dev = qc->dev; in ata_scsi_pass_thru()
2859 const u8 *cdb = scmd->cmnd; in ata_scsi_pass_thru()
2863 /* 7Fh variable length cmd means a ata pass-thru(32) */ in ata_scsi_pass_thru()
2867 tf->protocol = ata_scsi_map_proto(cdb[1 + cdb_offset]); in ata_scsi_pass_thru()
2868 if (tf->protocol == ATA_PROT_UNKNOWN) { in ata_scsi_pass_thru()
2873 if (ata_is_ncq(tf->protocol) && (cdb[2 + cdb_offset] & 0x3) == 0) in ata_scsi_pass_thru()
2874 tf->protocol = ATA_PROT_NCQ_NODATA; in ata_scsi_pass_thru()
2877 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_pass_thru()
2885 * 16-byte CDB - may contain extended commands. in ata_scsi_pass_thru()
2890 tf->hob_feature = cdb[3]; in ata_scsi_pass_thru()
2891 tf->hob_nsect = cdb[5]; in ata_scsi_pass_thru()
2892 tf->hob_lbal = cdb[7]; in ata_scsi_pass_thru()
2893 tf->hob_lbam = cdb[9]; in ata_scsi_pass_thru()
2894 tf->hob_lbah = cdb[11]; in ata_scsi_pass_thru()
2895 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2897 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2902 tf->feature = cdb[4]; in ata_scsi_pass_thru()
2903 tf->nsect = cdb[6]; in ata_scsi_pass_thru()
2904 tf->lbal = cdb[8]; in ata_scsi_pass_thru()
2905 tf->lbam = cdb[10]; in ata_scsi_pass_thru()
2906 tf->lbah = cdb[12]; in ata_scsi_pass_thru()
2907 tf->device = cdb[13]; in ata_scsi_pass_thru()
2908 tf->command = cdb[14]; in ata_scsi_pass_thru()
2911 * 12-byte CDB - incapable of extended commands. in ata_scsi_pass_thru()
2913 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2915 tf->feature = cdb[3]; in ata_scsi_pass_thru()
2916 tf->nsect = cdb[4]; in ata_scsi_pass_thru()
2917 tf->lbal = cdb[5]; in ata_scsi_pass_thru()
2918 tf->lbam = cdb[6]; in ata_scsi_pass_thru()
2919 tf->lbah = cdb[7]; in ata_scsi_pass_thru()
2920 tf->device = cdb[8]; in ata_scsi_pass_thru()
2921 tf->command = cdb[9]; in ata_scsi_pass_thru()
2924 * 32-byte CDB - may contain extended command fields. in ata_scsi_pass_thru()
2929 tf->hob_feature = cdb[20]; in ata_scsi_pass_thru()
2930 tf->hob_nsect = cdb[22]; in ata_scsi_pass_thru()
2931 tf->hob_lbal = cdb[16]; in ata_scsi_pass_thru()
2932 tf->hob_lbam = cdb[15]; in ata_scsi_pass_thru()
2933 tf->hob_lbah = cdb[14]; in ata_scsi_pass_thru()
2934 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2936 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2938 tf->feature = cdb[21]; in ata_scsi_pass_thru()
2939 tf->nsect = cdb[23]; in ata_scsi_pass_thru()
2940 tf->lbal = cdb[19]; in ata_scsi_pass_thru()
2941 tf->lbam = cdb[18]; in ata_scsi_pass_thru()
2942 tf->lbah = cdb[17]; in ata_scsi_pass_thru()
2943 tf->device = cdb[24]; in ata_scsi_pass_thru()
2944 tf->command = cdb[25]; in ata_scsi_pass_thru()
2945 tf->auxiliary = get_unaligned_be32(&cdb[28]); in ata_scsi_pass_thru()
2949 if (ata_is_ncq(tf->protocol)) in ata_scsi_pass_thru()
2950 tf->nsect = qc->hw_tag << 3; in ata_scsi_pass_thru()
2953 tf->device = dev->devno ? in ata_scsi_pass_thru()
2954 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; in ata_scsi_pass_thru()
2956 switch (tf->command) { in ata_scsi_pass_thru()
2957 /* READ/WRITE LONG use a non-standard sect_size */ in ata_scsi_pass_thru()
2962 if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1) { in ata_scsi_pass_thru()
2966 qc->sect_size = scsi_bufflen(scmd); in ata_scsi_pass_thru()
3000 qc->sect_size = scmd->device->sector_size; in ata_scsi_pass_thru()
3005 qc->sect_size = ATA_SECT_SIZE; in ata_scsi_pass_thru()
3013 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_scsi_pass_thru()
3014 if (scmd->sc_data_direction == DMA_TO_DEVICE) in ata_scsi_pass_thru()
3015 tf->flags |= ATA_TFLAG_WRITE; in ata_scsi_pass_thru()
3017 qc->flags |= ATA_QCFLAG_RESULT_TF | ATA_QCFLAG_QUIET; in ata_scsi_pass_thru()
3028 if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0) { in ata_scsi_pass_thru()
3034 if (ata_is_ncq(tf->protocol) && !ata_ncq_enabled(dev)) { in ata_scsi_pass_thru()
3051 if (multi_count != dev->multi_count) in ata_scsi_pass_thru()
3057 * Filter SET_FEATURES - XFER MODE command -- otherwise, in ata_scsi_pass_thru()
3058 * SET_FEATURES - XFER MODE must be preceded/succeeded in ata_scsi_pass_thru()
3059 * by an update to hardware-specific registers for each in ata_scsi_pass_thru()
3060 * controller (i.e. the reason for ->set_piomode(), in ata_scsi_pass_thru()
3061 * ->set_dmamode(), and ->post_set_mode() hooks). in ata_scsi_pass_thru()
3063 if (tf->command == ATA_CMD_SET_FEATURES && in ata_scsi_pass_thru()
3064 tf->feature == SETFEATURES_XFER) { in ata_scsi_pass_thru()
3084 if (tf->command >= 0x5C && tf->command <= 0x5F && !libata_allow_tpm) { in ata_scsi_pass_thru()
3097 * ata_format_dsm_trim_descr() - SATL Write Same to DSM Trim
3103 * Rewrite the WRITE SAME descriptor to be a DSM TRIM little-endian formatted
3120 struct scsi_device *sdp = cmd->device; in ata_format_dsm_trim_descr()
3121 size_t len = sdp->sector_size; in ata_format_dsm_trim_descr()
3141 count -= 0xffff; in ata_format_dsm_trim_descr()
3151 * ata_scsi_write_same_xlat() - SATL Write Same to ATA SCT Write Same
3158 * - When set translate to DSM TRIM
3159 * - When clear translate to SCT Write Same
3163 struct ata_taskfile *tf = &qc->tf; in ata_scsi_write_same_xlat()
3164 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_write_same_xlat()
3165 struct scsi_device *sdp = scmd->device; in ata_scsi_write_same_xlat()
3166 size_t len = sdp->sector_size; in ata_scsi_write_same_xlat()
3167 struct ata_device *dev = qc->dev; in ata_scsi_write_same_xlat()
3168 const u8 *cdb = scmd->cmnd; in ata_scsi_write_same_xlat()
3178 if (unlikely(!dev->dma_mode)) in ata_scsi_write_same_xlat()
3186 if (unlikely(blk_rq_is_passthrough(scmd->request))) in ata_scsi_write_same_xlat()
3189 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_write_same_xlat()
3196 (dev->horkage & ATA_HORKAGE_NOTRIM) || in ata_scsi_write_same_xlat()
3197 !ata_id_has_trim(dev->id)) { in ata_scsi_write_same_xlat()
3217 * For DATA SET MANAGEMENT TRIM in ACS-2 nsect (aka count) in ata_scsi_write_same_xlat()
3227 tf->protocol = ATA_PROT_NCQ; in ata_scsi_write_same_xlat()
3228 tf->command = ATA_CMD_FPDMA_SEND; in ata_scsi_write_same_xlat()
3229 tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f; in ata_scsi_write_same_xlat()
3230 tf->nsect = qc->hw_tag << 3; in ata_scsi_write_same_xlat()
3231 tf->hob_feature = (size / 512) >> 8; in ata_scsi_write_same_xlat()
3232 tf->feature = size / 512; in ata_scsi_write_same_xlat()
3234 tf->auxiliary = 1; in ata_scsi_write_same_xlat()
3236 tf->protocol = ATA_PROT_DMA; in ata_scsi_write_same_xlat()
3237 tf->hob_feature = 0; in ata_scsi_write_same_xlat()
3238 tf->feature = ATA_DSM_TRIM; in ata_scsi_write_same_xlat()
3239 tf->hob_nsect = (size / 512) >> 8; in ata_scsi_write_same_xlat()
3240 tf->nsect = size / 512; in ata_scsi_write_same_xlat()
3241 tf->command = ATA_CMD_DSM; in ata_scsi_write_same_xlat()
3244 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | in ata_scsi_write_same_xlat()
3265 * ata_scsiop_maint_in - Simulate a subset of MAINTENANCE_IN
3276 struct ata_device *dev = args->dev; in ata_scsiop_maint_in()
3277 u8 *cdb = args->cmd->cmnd; in ata_scsiop_maint_in()
3318 if (ata_id_zoned_cap(dev->id) || in ata_scsiop_maint_in()
3319 dev->class == ATA_DEV_ZAC) in ata_scsiop_maint_in()
3324 if (dev->flags & ATA_DFLAG_TRUSTED) in ata_scsiop_maint_in()
3336 * ata_scsi_report_zones_complete - convert ATA output
3339 * Convert T-13 little-endian field representation into
3340 * T-10 big-endian field representation.
3345 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_report_zones_complete()
3408 struct ata_taskfile *tf = &qc->tf; in ata_scsi_zbc_in_xlat()
3409 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_zbc_in_xlat()
3410 const u8 *cdb = scmd->cmnd; in ata_scsi_zbc_in_xlat()
3411 u16 sect, fp = (u16)-1; in ata_scsi_zbc_in_xlat()
3416 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_zbc_in_xlat()
3417 ata_dev_warn(qc->dev, "invalid cdb length %d\n", in ata_scsi_zbc_in_xlat()
3418 scmd->cmd_len); in ata_scsi_zbc_in_xlat()
3424 ata_dev_warn(qc->dev, "non-matching transfer count (%d/%d)\n", in ata_scsi_zbc_in_xlat()
3430 ata_dev_warn(qc->dev, "invalid service action %d\n", sa); in ata_scsi_zbc_in_xlat()
3439 ata_dev_warn(qc->dev, "invalid transfer count %d\n", n_block); in ata_scsi_zbc_in_xlat()
3445 if (ata_ncq_enabled(qc->dev) && in ata_scsi_zbc_in_xlat()
3446 ata_fpdma_zac_mgmt_in_supported(qc->dev)) { in ata_scsi_zbc_in_xlat()
3447 tf->protocol = ATA_PROT_NCQ; in ata_scsi_zbc_in_xlat()
3448 tf->command = ATA_CMD_FPDMA_RECV; in ata_scsi_zbc_in_xlat()
3449 tf->hob_nsect = ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN & 0x1f; in ata_scsi_zbc_in_xlat()
3450 tf->nsect = qc->hw_tag << 3; in ata_scsi_zbc_in_xlat()
3451 tf->feature = sect & 0xff; in ata_scsi_zbc_in_xlat()
3452 tf->hob_feature = (sect >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3453 tf->auxiliary = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES | (options << 8); in ata_scsi_zbc_in_xlat()
3455 tf->command = ATA_CMD_ZAC_MGMT_IN; in ata_scsi_zbc_in_xlat()
3456 tf->feature = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES; in ata_scsi_zbc_in_xlat()
3457 tf->protocol = ATA_PROT_DMA; in ata_scsi_zbc_in_xlat()
3458 tf->hob_feature = options; in ata_scsi_zbc_in_xlat()
3459 tf->hob_nsect = (sect >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3460 tf->nsect = sect & 0xff; in ata_scsi_zbc_in_xlat()
3462 tf->device = ATA_LBA; in ata_scsi_zbc_in_xlat()
3463 tf->lbah = (block >> 16) & 0xff; in ata_scsi_zbc_in_xlat()
3464 tf->lbam = (block >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3465 tf->lbal = block & 0xff; in ata_scsi_zbc_in_xlat()
3466 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_zbc_in_xlat()
3467 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_zbc_in_xlat()
3468 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_zbc_in_xlat()
3470 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48; in ata_scsi_zbc_in_xlat()
3471 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_scsi_zbc_in_xlat()
3475 qc->complete_fn = ata_scsi_report_zones_complete; in ata_scsi_zbc_in_xlat()
3480 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_zbc_in_xlat()
3485 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_zbc_in_xlat()
3491 struct ata_taskfile *tf = &qc->tf; in ata_scsi_zbc_out_xlat()
3492 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_zbc_out_xlat()
3493 struct ata_device *dev = qc->dev; in ata_scsi_zbc_out_xlat()
3494 const u8 *cdb = scmd->cmnd; in ata_scsi_zbc_out_xlat()
3498 u16 fp = (u16)-1; in ata_scsi_zbc_out_xlat()
3500 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_zbc_out_xlat()
3526 } else if (block >= dev->n_sectors) { in ata_scsi_zbc_out_xlat()
3534 if (ata_ncq_enabled(qc->dev) && in ata_scsi_zbc_out_xlat()
3535 ata_fpdma_zac_mgmt_out_supported(qc->dev)) { in ata_scsi_zbc_out_xlat()
3536 tf->protocol = ATA_PROT_NCQ_NODATA; in ata_scsi_zbc_out_xlat()
3537 tf->command = ATA_CMD_NCQ_NON_DATA; in ata_scsi_zbc_out_xlat()
3538 tf->feature = ATA_SUBCMD_NCQ_NON_DATA_ZAC_MGMT_OUT; in ata_scsi_zbc_out_xlat()
3539 tf->nsect = qc->hw_tag << 3; in ata_scsi_zbc_out_xlat()
3540 tf->auxiliary = sa | ((u16)all << 8); in ata_scsi_zbc_out_xlat()
3542 tf->protocol = ATA_PROT_NODATA; in ata_scsi_zbc_out_xlat()
3543 tf->command = ATA_CMD_ZAC_MGMT_OUT; in ata_scsi_zbc_out_xlat()
3544 tf->feature = sa; in ata_scsi_zbc_out_xlat()
3545 tf->hob_feature = all; in ata_scsi_zbc_out_xlat()
3547 tf->lbah = (block >> 16) & 0xff; in ata_scsi_zbc_out_xlat()
3548 tf->lbam = (block >> 8) & 0xff; in ata_scsi_zbc_out_xlat()
3549 tf->lbal = block & 0xff; in ata_scsi_zbc_out_xlat()
3550 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_zbc_out_xlat()
3551 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_zbc_out_xlat()
3552 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_zbc_out_xlat()
3553 tf->device = ATA_LBA; in ata_scsi_zbc_out_xlat()
3554 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48; in ata_scsi_zbc_out_xlat()
3559 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_zbc_out_xlat()
3563 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_zbc_out_xlat()
3568 * ata_mselect_caching - Simulate MODE SELECT for caching info page
3582 struct ata_taskfile *tf = &qc->tf; in ata_mselect_caching()
3583 struct ata_device *dev = qc->dev; in ata_mselect_caching()
3593 if (len != CACHE_MPAGE_LEN - 2) { in ata_mselect_caching()
3594 if (len < CACHE_MPAGE_LEN - 2) in ata_mselect_caching()
3597 *fp = CACHE_MPAGE_LEN - 2; in ata_mselect_caching()
3598 return -EINVAL; in ata_mselect_caching()
3604 * Check that read-only bits are not modified. in ata_mselect_caching()
3606 ata_msense_caching(dev->id, mpage, false); in ata_mselect_caching()
3607 for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) { in ata_mselect_caching()
3612 return -EINVAL; in ata_mselect_caching()
3616 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_mselect_caching()
3617 tf->protocol = ATA_PROT_NODATA; in ata_mselect_caching()
3618 tf->nsect = 0; in ata_mselect_caching()
3619 tf->command = ATA_CMD_SET_FEATURES; in ata_mselect_caching()
3620 tf->feature = wce ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF; in ata_mselect_caching()
3625 * ata_mselect_control - Simulate MODE SELECT for control page
3639 struct ata_device *dev = qc->dev; in ata_mselect_control()
3649 if (len != CONTROL_MPAGE_LEN - 2) { in ata_mselect_control()
3650 if (len < CONTROL_MPAGE_LEN - 2) in ata_mselect_control()
3653 *fp = CONTROL_MPAGE_LEN - 2; in ata_mselect_control()
3654 return -EINVAL; in ata_mselect_control()
3660 * Check that read-only bits are not modified. in ata_mselect_control()
3663 for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) { in ata_mselect_control()
3668 return -EINVAL; in ata_mselect_control()
3672 dev->flags |= ATA_DFLAG_D_SENSE; in ata_mselect_control()
3674 dev->flags &= ~ATA_DFLAG_D_SENSE; in ata_mselect_control()
3679 * ata_scsi_mode_select_xlat - Simulate MODE SELECT 6, 10 commands
3682 * Converts a MODE SELECT command to an ATA SET FEATURES taskfile.
3691 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_mode_select_xlat()
3692 const u8 *cdb = scmd->cmnd; in ata_scsi_mode_select_xlat()
3696 u16 fp = (u16)-1; in ata_scsi_mode_select_xlat()
3705 if (scmd->cmd_len < 5) { in ata_scsi_mode_select_xlat()
3713 if (scmd->cmd_len < 9) { in ata_scsi_mode_select_xlat()
3730 if (!scsi_sg_count(scmd) || scsi_sglist(scmd)->length < len) in ata_scsi_mode_select_xlat()
3746 len -= hdr_len; in ata_scsi_mode_select_xlat()
3756 len -= bd_len; in ata_scsi_mode_select_xlat()
3770 len -= 4; in ata_scsi_mode_select_xlat()
3778 len -= 2; in ata_scsi_mode_select_xlat()
3823 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_mode_select_xlat()
3827 ata_scsi_set_invalid_parameter(qc->dev, scmd, fp); in ata_scsi_mode_select_xlat()
3832 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_mode_select_xlat()
3836 scmd->result = SAM_STAT_GOOD; in ata_scsi_mode_select_xlat()
3852 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_security_inout_xlat()
3853 const u8 *cdb = scmd->cmnd; in ata_scsi_security_inout_xlat()
3854 struct ata_taskfile *tf = &qc->tf; in ata_scsi_security_inout_xlat()
3859 bool dma = !(qc->dev->flags & ATA_DFLAG_PIO); in ata_scsi_security_inout_xlat()
3865 ata_scsi_set_invalid_field(qc->dev, scmd, 1, 0); in ata_scsi_security_inout_xlat()
3871 ata_scsi_set_invalid_field(qc->dev, scmd, 6, 0); in ata_scsi_security_inout_xlat()
3876 ata_scsi_set_invalid_field(qc->dev, scmd, 6, 0); in ata_scsi_security_inout_xlat()
3880 /* convert to the sector-based ATA addressing */ in ata_scsi_security_inout_xlat()
3884 tf->protocol = dma ? ATA_PROT_DMA : ATA_PROT_PIO; in ata_scsi_security_inout_xlat()
3885 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR | ATA_TFLAG_LBA; in ata_scsi_security_inout_xlat()
3887 tf->flags |= ATA_TFLAG_WRITE; in ata_scsi_security_inout_xlat()
3888 tf->command = ata_scsi_trusted_op(len, send, dma); in ata_scsi_security_inout_xlat()
3889 tf->feature = secp; in ata_scsi_security_inout_xlat()
3890 tf->lbam = spsp & 0xff; in ata_scsi_security_inout_xlat()
3891 tf->lbah = spsp >> 8; in ata_scsi_security_inout_xlat()
3894 tf->nsect = len & 0xff; in ata_scsi_security_inout_xlat()
3895 tf->lbal = len >> 8; in ata_scsi_security_inout_xlat()
3898 tf->lbah = (1 << 7); in ata_scsi_security_inout_xlat()
3906 * ata_scsi_var_len_cdb_xlat - SATL variable length CDB to Handler
3913 * Zero on success, non-zero on failure
3918 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_var_len_cdb_xlat()
3919 const u8 *cdb = scmd->cmnd; in ata_scsi_var_len_cdb_xlat()
3923 * if service action represents a ata pass-thru(32) command, in ata_scsi_var_len_cdb_xlat()
3934 * ata_get_xlat_func - check if SCSI to ATA translation is possible
3989 if (!(dev->flags & ATA_DFLAG_TRUSTED)) in ata_get_xlat_func()
4001 * ata_scsi_dump_cdb - dump SCSI command contents to dmesg
4011 struct scsi_device *scsidev = cmd->device; in ata_scsi_dump_cdb()
4014 ap->print_id, in ata_scsi_dump_cdb()
4015 scsidev->channel, scsidev->id, scsidev->lun, in ata_scsi_dump_cdb()
4016 cmd->cmnd); in ata_scsi_dump_cdb()
4022 u8 scsi_op = scmd->cmnd[0]; in __ata_scsi_queuecmd()
4026 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in __ata_scsi_queuecmd()
4027 if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) in __ata_scsi_queuecmd()
4032 if (unlikely(!scmd->cmd_len)) in __ata_scsi_queuecmd()
4039 if (unlikely(len > scmd->cmd_len || in __ata_scsi_queuecmd()
4040 len > dev->cdb_len || in __ata_scsi_queuecmd()
4041 scmd->cmd_len > ATAPI_CDB_LEN)) in __ata_scsi_queuecmd()
4047 if (unlikely(scmd->cmd_len > 16)) in __ata_scsi_queuecmd()
4063 scmd->cmd_len, scsi_op, dev->cdb_len); in __ata_scsi_queuecmd()
4064 scmd->result = DID_ERROR << 16; in __ata_scsi_queuecmd()
4065 scmd->scsi_done(scmd); in __ata_scsi_queuecmd()
4070 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
4092 struct scsi_device *scsidev = cmd->device; in ata_scsi_queuecmd()
4098 spin_lock_irqsave(ap->lock, irq_flags); in ata_scsi_queuecmd()
4106 cmd->result = (DID_BAD_TARGET << 16); in ata_scsi_queuecmd()
4107 cmd->scsi_done(cmd); in ata_scsi_queuecmd()
4110 spin_unlock_irqrestore(ap->lock, irq_flags); in ata_scsi_queuecmd()
4117 * ata_scsi_simulate - simulate SCSI command on ATA device
4121 * Interprets and directly executes a select list of SCSI commands
4131 const u8 *scsicmd = cmd->cmnd; in ata_scsi_simulate()
4135 args.id = dev->id; in ata_scsi_simulate()
4167 if (dev->flags & ATA_DFLAG_ZAC) { in ata_scsi_simulate()
4200 cmd->result = (DRIVER_SENSE << 24); in ata_scsi_simulate()
4204 * turning this into a no-op. in ata_scsi_simulate()
4209 /* no-op's, complete with success */ in ata_scsi_simulate()
4236 cmd->scsi_done(cmd); in ata_scsi_simulate()
4243 for (i = 0; i < host->n_ports; i++) { in ata_scsi_add_hosts()
4244 struct ata_port *ap = host->ports[i]; in ata_scsi_add_hosts()
4247 rc = -ENOMEM; in ata_scsi_add_hosts()
4252 shost->eh_noresume = 1; in ata_scsi_add_hosts()
4253 *(struct ata_port **)&shost->hostdata[0] = ap; in ata_scsi_add_hosts()
4254 ap->scsi_host = shost; in ata_scsi_add_hosts()
4256 shost->transportt = ata_scsi_transport_template; in ata_scsi_add_hosts()
4257 shost->unique_id = ap->print_id; in ata_scsi_add_hosts()
4258 shost->max_id = 16; in ata_scsi_add_hosts()
4259 shost->max_lun = 1; in ata_scsi_add_hosts()
4260 shost->max_channel = 1; in ata_scsi_add_hosts()
4261 shost->max_cmd_len = 32; in ata_scsi_add_hosts()
4263 /* Schedule policy is determined by ->qc_defer() in ata_scsi_add_hosts()
4268 shost->max_host_blocked = 1; in ata_scsi_add_hosts()
4270 rc = scsi_add_host_with_dma(shost, &ap->tdev, ap->host->dev); in ata_scsi_add_hosts()
4278 while (--i >= 0) { in ata_scsi_add_hosts()
4279 struct Scsi_Host *shost = host->ports[i]->scsi_host; in ata_scsi_add_hosts()
4290 struct scsi_device *sdev = dev->sdev; in ata_scsi_assign_ofnode()
4291 struct device *d = ap->host->dev; in ata_scsi_assign_ofnode()
4292 struct device_node *np = d->of_node; in ata_scsi_assign_ofnode()
4302 if (val == dev->devno) { in ata_scsi_assign_ofnode()
4304 sdev->sdev_gendev.of_node = child; in ata_scsi_assign_ofnode()
4328 if (dev->sdev) in ata_scsi_scan_host()
4332 id = dev->devno; in ata_scsi_scan_host()
4334 channel = link->pmp; in ata_scsi_scan_host()
4336 sdev = __scsi_add_device(ap->scsi_host, channel, id, 0, in ata_scsi_scan_host()
4339 dev->sdev = sdev; in ata_scsi_scan_host()
4343 dev->sdev = NULL; in ata_scsi_scan_host()
4354 if (!dev->sdev) in ata_scsi_scan_host()
4376 if (--tries) { in ata_scsi_scan_host()
4385 queue_delayed_work(system_long_wq, &ap->hotplug_task, in ata_scsi_scan_host()
4390 * ata_scsi_offline_dev - offline attached SCSI device
4395 * function is called with host lock which protects dev->sdev
4406 if (dev->sdev) { in ata_scsi_offline_dev()
4407 scsi_device_set_state(dev->sdev, SDEV_OFFLINE); in ata_scsi_offline_dev()
4414 * ata_scsi_remove_dev - remove attached SCSI device
4425 struct ata_port *ap = dev->link->ap; in ata_scsi_remove_dev()
4435 mutex_lock(&ap->scsi_host->scan_mutex); in ata_scsi_remove_dev()
4436 spin_lock_irqsave(ap->lock, flags); in ata_scsi_remove_dev()
4438 /* clearing dev->sdev is protected by host lock */ in ata_scsi_remove_dev()
4439 sdev = dev->sdev; in ata_scsi_remove_dev()
4440 dev->sdev = NULL; in ata_scsi_remove_dev()
4460 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_remove_dev()
4461 mutex_unlock(&ap->scsi_host->scan_mutex); in ata_scsi_remove_dev()
4465 dev_name(&sdev->sdev_gendev)); in ata_scsi_remove_dev()
4474 struct ata_port *ap = link->ap; in ata_scsi_handle_link_detach()
4480 if (!(dev->flags & ATA_DFLAG_DETACHED)) in ata_scsi_handle_link_detach()
4483 spin_lock_irqsave(ap->lock, flags); in ata_scsi_handle_link_detach()
4484 dev->flags &= ~ATA_DFLAG_DETACHED; in ata_scsi_handle_link_detach()
4485 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_handle_link_detach()
4495 * ata_scsi_media_change_notify - send media change event
4506 if (dev->sdev) in ata_scsi_media_change_notify()
4507 sdev_evt_send_simple(dev->sdev, SDEV_EVT_MEDIA_CHANGE, in ata_scsi_media_change_notify()
4512 * ata_scsi_hotplug - SCSI part of hotplug
4529 if (ap->pflags & ATA_PFLAG_UNLOADING) { in ata_scsi_hotplug()
4530 DPRINTK("ENTER/EXIT - unloading\n"); in ata_scsi_hotplug()
4535 mutex_lock(&ap->scsi_scan_mutex); in ata_scsi_hotplug()
4541 ata_scsi_handle_link_detach(&ap->link); in ata_scsi_hotplug()
4542 if (ap->pmp_link) in ata_scsi_hotplug()
4544 ata_scsi_handle_link_detach(&ap->pmp_link[i]); in ata_scsi_hotplug()
4549 mutex_unlock(&ap->scsi_scan_mutex); in ata_scsi_hotplug()
4554 * ata_scsi_user_scan - indication for user-initiated bus scan
4576 if (!ap->ops->error_handler) in ata_scsi_user_scan()
4577 return -EOPNOTSUPP; in ata_scsi_user_scan()
4580 return -EINVAL; in ata_scsi_user_scan()
4584 return -EINVAL; in ata_scsi_user_scan()
4588 return -EINVAL; in ata_scsi_user_scan()
4592 spin_lock_irqsave(ap->lock, flags); in ata_scsi_user_scan()
4598 struct ata_eh_info *ehi = &link->eh_info; in ata_scsi_user_scan()
4599 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_scsi_user_scan()
4600 ehi->action |= ATA_EH_RESET; in ata_scsi_user_scan()
4606 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_scsi_user_scan()
4607 ehi->probe_mask |= 1 << dev->devno; in ata_scsi_user_scan()
4608 ehi->action |= ATA_EH_RESET; in ata_scsi_user_scan()
4610 rc = -EINVAL; in ata_scsi_user_scan()
4615 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_user_scan()
4618 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_user_scan()
4624 * ata_scsi_dev_rescan - initiate scsi_rescan_device()
4641 mutex_lock(&ap->scsi_scan_mutex); in ata_scsi_dev_rescan()
4642 spin_lock_irqsave(ap->lock, flags); in ata_scsi_dev_rescan()
4646 struct scsi_device *sdev = dev->sdev; in ata_scsi_dev_rescan()
4653 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_dev_rescan()
4654 scsi_rescan_device(&(sdev->sdev_gendev)); in ata_scsi_dev_rescan()
4656 spin_lock_irqsave(ap->lock, flags); in ata_scsi_dev_rescan()
4660 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_dev_rescan()
4661 mutex_unlock(&ap->scsi_scan_mutex); in ata_scsi_dev_rescan()