Lines Matching +full:non +full:- +full:descriptive

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-scsi.c - helper library for ATA
6 * Please ALWAYS copy linux-ide@vger.kernel.org
9 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
10 * Copyright 2003-2004 Jeff Garzik
13 * as Documentation/driver-api/libata.rst
16 * - http://www.t10.org/
17 * - http://www.t13.org/
40 #include "libata-transport.h"
66 RW_RECOVERY_MPAGE_LEN - 2,
76 CACHE_MPAGE_LEN - 2,
85 CONTROL_MPAGE_LEN - 2,
87 0, /* [QAM+QERR may be 1, see 05-359r1] */
89 0, 30 /* extended self test time, see 05-359r1 */
121 return -EINVAL; in ata_scsi_lpm_store()
123 spin_lock_irqsave(ap->lock, flags); in ata_scsi_lpm_store()
126 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_scsi_lpm_store()
127 if (dev->horkage & ATA_HORKAGE_NOLPM) { in ata_scsi_lpm_store()
128 count = -EOPNOTSUPP; in ata_scsi_lpm_store()
134 ap->target_lpm_policy = policy; in ata_scsi_lpm_store()
137 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_lpm_store()
147 if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names)) in ata_scsi_lpm_show()
148 return -EINVAL; in ata_scsi_lpm_show()
151 ata_lpm_policy_names[ap->target_lpm_policy]); in ata_scsi_lpm_show()
168 ap = ata_shost_to_port(sdev->host); in ata_scsi_park_show()
170 spin_lock_irq(ap->lock); in ata_scsi_park_show()
173 rc = -ENODEV; in ata_scsi_park_show()
176 if (dev->flags & ATA_DFLAG_NO_UNLOAD) { in ata_scsi_park_show()
177 rc = -EOPNOTSUPP; in ata_scsi_park_show()
181 link = dev->link; in ata_scsi_park_show()
183 if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS && in ata_scsi_park_show()
184 link->eh_context.unloaded_mask & (1 << dev->devno) && in ata_scsi_park_show()
185 time_after(dev->unpark_deadline, now)) in ata_scsi_park_show()
186 msecs = jiffies_to_msecs(dev->unpark_deadline - now); in ata_scsi_park_show()
191 spin_unlock_irq(ap->lock); in ata_scsi_park_show()
210 if (input < -2) in ata_scsi_park_store()
211 return -EINVAL; in ata_scsi_park_store()
213 rc = -EOVERFLOW; in ata_scsi_park_store()
217 ap = ata_shost_to_port(sdev->host); in ata_scsi_park_store()
219 spin_lock_irqsave(ap->lock, flags); in ata_scsi_park_store()
222 rc = -ENODEV; in ata_scsi_park_store()
225 if (dev->class != ATA_DEV_ATA && in ata_scsi_park_store()
226 dev->class != ATA_DEV_ZAC) { in ata_scsi_park_store()
227 rc = -EOPNOTSUPP; in ata_scsi_park_store()
232 if (dev->flags & ATA_DFLAG_NO_UNLOAD) { in ata_scsi_park_store()
233 rc = -EOPNOTSUPP; in ata_scsi_park_store()
237 dev->unpark_deadline = ata_deadline(jiffies, input); in ata_scsi_park_store()
238 dev->link->eh_info.dev_action[dev->devno] |= ATA_EH_PARK; in ata_scsi_park_store()
240 complete(&ap->park_req_pending); in ata_scsi_park_store()
243 case -1: in ata_scsi_park_store()
244 dev->flags &= ~ATA_DFLAG_NO_UNLOAD; in ata_scsi_park_store()
246 case -2: in ata_scsi_park_store()
247 dev->flags |= ATA_DFLAG_NO_UNLOAD; in ata_scsi_park_store()
252 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_park_store()
270 ap = ata_shost_to_port(sdev->host); in ata_ncq_prio_enable_show()
272 spin_lock_irq(ap->lock); in ata_ncq_prio_enable_show()
275 rc = -ENODEV; in ata_ncq_prio_enable_show()
279 ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_show()
282 spin_unlock_irq(ap->lock); in ata_ncq_prio_enable_show()
301 return -EINVAL; in ata_ncq_prio_enable_store()
303 ap = ata_shost_to_port(sdev->host); in ata_ncq_prio_enable_store()
306 return -ENODEV; in ata_ncq_prio_enable_store()
308 spin_lock_irq(ap->lock); in ata_ncq_prio_enable_store()
310 dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_store()
312 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_store()
314 dev->link->eh_info.action |= ATA_EH_REVALIDATE; in ata_ncq_prio_enable_store()
315 dev->link->eh_info.flags |= ATA_EHI_QUIET; in ata_ncq_prio_enable_store()
317 spin_unlock_irq(ap->lock); in ata_ncq_prio_enable_store()
322 spin_lock_irq(ap->lock); in ata_ncq_prio_enable_store()
323 if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) { in ata_ncq_prio_enable_store()
324 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_store()
325 rc = -EIO; in ata_ncq_prio_enable_store()
327 spin_unlock_irq(ap->lock); in ata_ncq_prio_enable_store()
340 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); in ata_scsi_set_sense()
345 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; in ata_scsi_set_sense()
347 scsi_build_sense_buffer(d_sense, cmd->sense_buffer, sk, asc, ascq); in ata_scsi_set_sense()
363 scsi_set_sense_information(cmd->sense_buffer, in ata_scsi_set_sense_information()
372 scsi_set_sense_field_pointer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, in ata_scsi_set_invalid_field()
381 scsi_set_sense_field_pointer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, in ata_scsi_set_invalid_parameter()
391 if (ap->ops->em_store && (ap->flags & ATA_FLAG_EM)) in ata_scsi_em_message_store()
392 return ap->ops->em_store(ap, buf, count); in ata_scsi_em_message_store()
393 return -EINVAL; in ata_scsi_em_message_store()
403 if (ap->ops->em_show && (ap->flags & ATA_FLAG_EM)) in ata_scsi_em_message_show()
404 return ap->ops->em_show(ap, buf); in ata_scsi_em_message_show()
405 return -EINVAL; in ata_scsi_em_message_show()
418 return snprintf(buf, 23, "%d\n", ap->em_message_type); in ata_scsi_em_message_type_show()
429 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_activity_show()
432 if (atadev && ap->ops->sw_activity_show && in ata_scsi_activity_show()
433 (ap->flags & ATA_FLAG_SW_ACTIVITY)) in ata_scsi_activity_show()
434 return ap->ops->sw_activity_show(atadev, buf); in ata_scsi_activity_show()
435 return -EINVAL; in ata_scsi_activity_show()
443 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_activity_store()
448 if (atadev && ap->ops->sw_activity_store && in ata_scsi_activity_store()
449 (ap->flags & ATA_FLAG_SW_ACTIVITY)) { in ata_scsi_activity_store()
453 rc = ap->ops->sw_activity_store(atadev, val); in ata_scsi_activity_store()
460 return -EINVAL; in ata_scsi_activity_store()
474 * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd.
503 * ata_scsi_unlock_native_capacity - unlock native capacity
514 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_unlock_native_capacity()
518 spin_lock_irqsave(ap->lock, flags); in ata_scsi_unlock_native_capacity()
521 if (dev && dev->n_sectors < dev->n_native_sectors) { in ata_scsi_unlock_native_capacity()
522 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_scsi_unlock_native_capacity()
523 dev->link->eh_info.action |= ATA_EH_RESET; in ata_scsi_unlock_native_capacity()
527 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_unlock_native_capacity()
532 * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl
551 return -ENOMSG; in ata_get_identity()
553 if (copy_to_user(dst, dev->id, ATA_ID_WORDS * sizeof(u16))) in ata_get_identity()
554 return -EFAULT; in ata_get_identity()
556 ata_id_string(dev->id, buf, ATA_ID_PROD, ATA_ID_PROD_LEN); in ata_get_identity()
558 return -EFAULT; in ata_get_identity()
560 ata_id_string(dev->id, buf, ATA_ID_FW_REV, ATA_ID_FW_REV_LEN); in ata_get_identity()
562 return -EFAULT; in ata_get_identity()
564 ata_id_string(dev->id, buf, ATA_ID_SERNO, ATA_ID_SERNO_LEN); in ata_get_identity()
566 return -EFAULT; in ata_get_identity()
572 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
594 return -EINVAL; in ata_cmd_ioctl()
597 return -EFAULT; in ata_cmd_ioctl()
606 rc = -ENOMEM; in ata_cmd_ioctl()
610 scsi_cmd[1] = (4 << 1); /* PIO Data-in */ in ata_cmd_ioctl()
615 scsi_cmd[1] = (3 << 1); /* Non-data */ in ata_cmd_ioctl()
623 if (args[0] == ATA_CMD_SMART) { /* hack -- ide driver does this too */ in ata_cmd_ioctl()
642 /* If we set cc then ATA pass-through will cause a in ata_cmd_ioctl()
657 rc = -EFAULT; in ata_cmd_ioctl()
663 rc = -EIO; in ata_cmd_ioctl()
669 rc = -EFAULT; in ata_cmd_ioctl()
676 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
696 return -EINVAL; in ata_task_ioctl()
699 return -EFAULT; in ata_task_ioctl()
704 scsi_cmd[1] = (3 << 1); /* Non-data */ in ata_task_ioctl()
723 /* If we set cc then ATA pass-through will cause a in ata_task_ioctl()
742 rc = -EFAULT; in ata_task_ioctl()
747 rc = -EIO; in ata_task_ioctl()
757 if (ap->flags & ATA_FLAG_PIO_DMA) in ata_ioc32()
759 if (ap->pflags & ATA_PFLAG_PIO32) in ata_ioc32()
768 int rc = -EINVAL; in ata_sas_scsi_ioctl()
773 spin_lock_irqsave(ap->lock, flags); in ata_sas_scsi_ioctl()
775 spin_unlock_irqrestore(ap->lock, flags); in ata_sas_scsi_ioctl()
781 spin_lock_irqsave(ap->lock, flags); in ata_sas_scsi_ioctl()
782 if (ap->pflags & ATA_PFLAG_PIO32CHANGE) { in ata_sas_scsi_ioctl()
784 ap->pflags |= ATA_PFLAG_PIO32; in ata_sas_scsi_ioctl()
786 ap->pflags &= ~ATA_PFLAG_PIO32; in ata_sas_scsi_ioctl()
789 rc = -EINVAL; in ata_sas_scsi_ioctl()
791 spin_unlock_irqrestore(ap->lock, flags); in ata_sas_scsi_ioctl()
799 return -EACCES; in ata_sas_scsi_ioctl()
804 return -EACCES; in ata_sas_scsi_ioctl()
808 rc = -ENOTTY; in ata_sas_scsi_ioctl()
819 return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host), in ata_scsi_ioctl()
825 * ata_scsi_qc_new - acquire new ata_queued_cmd reference
833 * If a command was available, fill in the SCSI-specific
848 qc = ata_qc_new_init(dev, cmd->request->tag); in ata_scsi_qc_new()
850 qc->scsicmd = cmd; in ata_scsi_qc_new()
851 qc->scsidone = cmd->scsi_done; in ata_scsi_qc_new()
853 qc->sg = scsi_sglist(cmd); in ata_scsi_qc_new()
854 qc->n_elem = scsi_sg_count(cmd); in ata_scsi_qc_new()
856 if (cmd->request->rq_flags & RQF_QUIET) in ata_scsi_qc_new()
857 qc->flags |= ATA_QCFLAG_QUIET; in ata_scsi_qc_new()
859 cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1); in ata_scsi_qc_new()
860 cmd->scsi_done(cmd); in ata_scsi_qc_new()
868 struct scsi_cmnd *scmd = qc->scsicmd; in ata_qc_set_pc_nbytes()
870 qc->extrabytes = scmd->request->extra_len; in ata_qc_set_pc_nbytes()
871 qc->nbytes = scsi_bufflen(scmd) + qc->extrabytes; in ata_qc_set_pc_nbytes()
875 * ata_dump_status - user friendly display of error info
880 * that they have some idea what really happened at the non
881 * make-believe layer.
888 u8 stat = tf->command, err = tf->feature; in ata_dump_status()
921 * ata_to_sense_error - convert ATA error to SCSI error
965 /* TRK0 - Track 0 not found */ in ata_to_sense_error()
972 /* SRV/IDNF - ID not found */ in ata_to_sense_error()
975 /* MC - Media Changed */ in ata_to_sense_error()
978 /* ECC - Uncorrectable ECC error */ in ata_to_sense_error()
981 /* BBD - block marked bad */ in ata_to_sense_error()
1025 * is not descriptive enough. in ata_to_sense_error()
1052 * ata_gen_passthru_sense - Generate check condition sense block.
1062 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE
1070 struct scsi_cmnd *cmd = qc->scsicmd; in ata_gen_passthru_sense()
1071 struct ata_taskfile *tf = &qc->result_tf; in ata_gen_passthru_sense()
1072 unsigned char *sb = cmd->sense_buffer; in ata_gen_passthru_sense()
1074 int verbose = qc->ap->ops->error_handler == NULL; in ata_gen_passthru_sense()
1079 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; in ata_gen_passthru_sense()
1085 if (qc->err_mask || in ata_gen_passthru_sense()
1086 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { in ata_gen_passthru_sense()
1087 ata_to_sense_error(qc->ap->print_id, tf->command, tf->feature, in ata_gen_passthru_sense()
1089 ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq); in ata_gen_passthru_sense()
1092 * ATA PASS-THROUGH INFORMATION AVAILABLE in ata_gen_passthru_sense()
1095 scsi_build_sense_buffer(1, cmd->sense_buffer, in ata_gen_passthru_sense()
1099 if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { in ata_gen_passthru_sense()
1117 desc[3] = tf->feature; /* == error reg */ in ata_gen_passthru_sense()
1118 desc[5] = tf->nsect; in ata_gen_passthru_sense()
1119 desc[7] = tf->lbal; in ata_gen_passthru_sense()
1120 desc[9] = tf->lbam; in ata_gen_passthru_sense()
1121 desc[11] = tf->lbah; in ata_gen_passthru_sense()
1122 desc[12] = tf->device; in ata_gen_passthru_sense()
1123 desc[13] = tf->command; /* == status reg */ in ata_gen_passthru_sense()
1129 if (tf->flags & ATA_TFLAG_LBA48) { in ata_gen_passthru_sense()
1131 desc[4] = tf->hob_nsect; in ata_gen_passthru_sense()
1132 desc[6] = tf->hob_lbal; in ata_gen_passthru_sense()
1133 desc[8] = tf->hob_lbam; in ata_gen_passthru_sense()
1134 desc[10] = tf->hob_lbah; in ata_gen_passthru_sense()
1138 desc[0] = tf->feature; in ata_gen_passthru_sense()
1139 desc[1] = tf->command; /* status */ in ata_gen_passthru_sense()
1140 desc[2] = tf->device; in ata_gen_passthru_sense()
1141 desc[3] = tf->nsect; in ata_gen_passthru_sense()
1143 if (tf->flags & ATA_TFLAG_LBA48) { in ata_gen_passthru_sense()
1145 if (tf->hob_nsect) in ata_gen_passthru_sense()
1147 if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) in ata_gen_passthru_sense()
1150 desc[9] = tf->lbal; in ata_gen_passthru_sense()
1151 desc[10] = tf->lbam; in ata_gen_passthru_sense()
1152 desc[11] = tf->lbah; in ata_gen_passthru_sense()
1157 * ata_gen_ata_sense - generate a SCSI fixed sense block
1168 struct ata_device *dev = qc->dev; in ata_gen_ata_sense()
1169 struct scsi_cmnd *cmd = qc->scsicmd; in ata_gen_ata_sense()
1170 struct ata_taskfile *tf = &qc->result_tf; in ata_gen_ata_sense()
1171 unsigned char *sb = cmd->sense_buffer; in ata_gen_ata_sense()
1172 int verbose = qc->ap->ops->error_handler == NULL; in ata_gen_ata_sense()
1178 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; in ata_gen_ata_sense()
1189 if (qc->err_mask || in ata_gen_ata_sense()
1190 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { in ata_gen_ata_sense()
1191 ata_to_sense_error(qc->ap->print_id, tf->command, tf->feature, in ata_gen_ata_sense()
1197 tf->command, qc->err_mask); in ata_gen_ata_sense()
1202 block = ata_tf_read_block(&qc->result_tf, dev); in ata_gen_ata_sense()
1211 sdev->use_10_for_rw = 1; in ata_scsi_sdev_config()
1212 sdev->use_10_for_ms = 1; in ata_scsi_sdev_config()
1213 sdev->no_write_same = 1; in ata_scsi_sdev_config()
1215 /* Schedule policy is determined by ->qc_defer() callback and in ata_scsi_sdev_config()
1220 sdev->max_device_blocked = 1; in ata_scsi_sdev_config()
1224 * atapi_drain_needed - Check whether data transfer may overflow
1246 return atapi_cmd_type(scsi_req(rq)->cmd[0]) == ATAPI_MISC; in atapi_drain_needed()
1252 struct request_queue *q = sdev->request_queue; in ata_scsi_dev_config()
1254 if (!ata_id_has_unload(dev->id)) in ata_scsi_dev_config()
1255 dev->flags |= ATA_DFLAG_NO_UNLOAD; in ata_scsi_dev_config()
1258 blk_queue_max_hw_sectors(q, dev->max_sectors); in ata_scsi_dev_config()
1260 if (dev->class == ATA_DEV_ATAPI) { in ata_scsi_dev_config()
1263 sdev->sector_size = ATA_SECT_SIZE; in ata_scsi_dev_config()
1266 blk_queue_update_dma_pad(q, ATA_DMA_PAD_SZ - 1); in ata_scsi_dev_config()
1269 buf = kmalloc(ATAPI_MAX_DRAIN, q->bounce_gfp | GFP_KERNEL); in ata_scsi_dev_config()
1272 return -ENOMEM; in ata_scsi_dev_config()
1277 sdev->sector_size = ata_id_logical_sector_size(dev->id); in ata_scsi_dev_config()
1278 sdev->manage_start_stop = 1; in ata_scsi_dev_config()
1288 if (sdev->sector_size > PAGE_SIZE) in ata_scsi_dev_config()
1291 sdev->sector_size); in ata_scsi_dev_config()
1293 blk_queue_update_dma_alignment(q, sdev->sector_size - 1); in ata_scsi_dev_config()
1295 if (dev->flags & ATA_DFLAG_AN) in ata_scsi_dev_config()
1296 set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events); in ata_scsi_dev_config()
1298 if (dev->flags & ATA_DFLAG_NCQ) { in ata_scsi_dev_config()
1301 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); in ata_scsi_dev_config()
1306 if (dev->flags & ATA_DFLAG_TRUSTED) in ata_scsi_dev_config()
1307 sdev->security_supported = 1; in ata_scsi_dev_config()
1309 dev->sdev = sdev; in ata_scsi_dev_config()
1314 * ata_scsi_slave_config - Set SCSI device attributes
1319 * SCSI mid-layer behaviors.
1327 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_config()
1340 * ata_scsi_slave_destroy - SCSI device is about to be destroyed
1345 * dev->sdev, this function doesn't have to do anything.
1346 * Otherwise, SCSI layer initiated warm-unplug is in progress.
1347 * Clear dev->sdev, schedule the device for ATA detach and invoke
1355 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_destroy()
1356 struct request_queue *q = sdev->request_queue; in ata_scsi_slave_destroy()
1360 if (!ap->ops->error_handler) in ata_scsi_slave_destroy()
1363 spin_lock_irqsave(ap->lock, flags); in ata_scsi_slave_destroy()
1365 if (dev && dev->sdev) { in ata_scsi_slave_destroy()
1367 dev->sdev = NULL; in ata_scsi_slave_destroy()
1368 dev->flags |= ATA_DFLAG_DETACH; in ata_scsi_slave_destroy()
1371 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_slave_destroy()
1373 kfree(q->dma_drain_buffer); in ata_scsi_slave_destroy()
1374 q->dma_drain_buffer = NULL; in ata_scsi_slave_destroy()
1375 q->dma_drain_size = 0; in ata_scsi_slave_destroy()
1379 * __ata_change_queue_depth - helper for ata_scsi_change_queue_depth
1394 if (queue_depth < 1 || queue_depth == sdev->queue_depth) in __ata_change_queue_depth()
1395 return sdev->queue_depth; in __ata_change_queue_depth()
1399 return sdev->queue_depth; in __ata_change_queue_depth()
1402 spin_lock_irqsave(ap->lock, flags); in __ata_change_queue_depth()
1403 dev->flags &= ~ATA_DFLAG_NCQ_OFF; in __ata_change_queue_depth()
1405 dev->flags |= ATA_DFLAG_NCQ_OFF; in __ata_change_queue_depth()
1408 spin_unlock_irqrestore(ap->lock, flags); in __ata_change_queue_depth()
1411 queue_depth = min(queue_depth, sdev->host->can_queue); in __ata_change_queue_depth()
1412 queue_depth = min(queue_depth, ata_id_queue_depth(dev->id)); in __ata_change_queue_depth()
1415 if (sdev->queue_depth == queue_depth) in __ata_change_queue_depth()
1416 return -EINVAL; in __ata_change_queue_depth()
1422 * ata_scsi_change_queue_depth - SCSI callback for queue depth config
1426 * This is libata standard hostt->change_queue_depth callback.
1438 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_change_queue_depth()
1444 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
1456 * Zero on success, non-zero on error.
1460 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_start_stop_xlat()
1461 struct ata_taskfile *tf = &qc->tf; in ata_scsi_start_stop_xlat()
1462 const u8 *cdb = scmd->cmnd; in ata_scsi_start_stop_xlat()
1466 if (scmd->cmd_len < 5) { in ata_scsi_start_stop_xlat()
1471 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_scsi_start_stop_xlat()
1472 tf->protocol = ATA_PROT_NODATA; in ata_scsi_start_stop_xlat()
1474 ; /* ignore IMMED bit, violates sat-r05 */ in ata_scsi_start_stop_xlat()
1488 tf->nsect = 1; /* 1 sector, lba=0 */ in ata_scsi_start_stop_xlat()
1490 if (qc->dev->flags & ATA_DFLAG_LBA) { in ata_scsi_start_stop_xlat()
1491 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_start_stop_xlat()
1493 tf->lbah = 0x0; in ata_scsi_start_stop_xlat()
1494 tf->lbam = 0x0; in ata_scsi_start_stop_xlat()
1495 tf->lbal = 0x0; in ata_scsi_start_stop_xlat()
1496 tf->device |= ATA_LBA; in ata_scsi_start_stop_xlat()
1499 tf->lbal = 0x1; /* sect */ in ata_scsi_start_stop_xlat()
1500 tf->lbam = 0x0; /* cyl low */ in ata_scsi_start_stop_xlat()
1501 tf->lbah = 0x0; /* cyl high */ in ata_scsi_start_stop_xlat()
1504 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ in ata_scsi_start_stop_xlat()
1509 if ((qc->ap->flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && in ata_scsi_start_stop_xlat()
1513 if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && in ata_scsi_start_stop_xlat()
1518 tf->command = ATA_CMD_STANDBYNOW1; in ata_scsi_start_stop_xlat()
1531 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_start_stop_xlat()
1534 scmd->result = SAM_STAT_GOOD; in ata_scsi_start_stop_xlat()
1540 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command
1550 * Zero on success, non-zero on error.
1554 struct ata_taskfile *tf = &qc->tf; in ata_scsi_flush_xlat()
1556 tf->flags |= ATA_TFLAG_DEVICE; in ata_scsi_flush_xlat()
1557 tf->protocol = ATA_PROT_NODATA; in ata_scsi_flush_xlat()
1559 if (qc->dev->flags & ATA_DFLAG_FLUSH_EXT) in ata_scsi_flush_xlat()
1560 tf->command = ATA_CMD_FLUSH_EXT; in ata_scsi_flush_xlat()
1562 tf->command = ATA_CMD_FLUSH; in ata_scsi_flush_xlat()
1565 qc->flags |= ATA_QCFLAG_IO; in ata_scsi_flush_xlat()
1571 * scsi_6_lba_len - Get LBA and transfer length
1574 * Calculate LBA and transfer length for 6-byte commands.
1585 VPRINTK("six-byte command\n"); in scsi_6_lba_len()
1598 * scsi_10_lba_len - Get LBA and transfer length
1601 * Calculate LBA and transfer length for 10-byte commands.
1612 VPRINTK("ten-byte command\n"); in scsi_10_lba_len()
1627 * scsi_16_lba_len - Get LBA and transfer length
1630 * Calculate LBA and transfer length for 16-byte commands.
1641 VPRINTK("sixteen-byte command\n"); in scsi_16_lba_len()
1662 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
1671 * Zero on success, non-zero on error.
1675 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_verify_xlat()
1676 struct ata_taskfile *tf = &qc->tf; in ata_scsi_verify_xlat()
1677 struct ata_device *dev = qc->dev; in ata_scsi_verify_xlat()
1678 u64 dev_sectors = qc->dev->n_sectors; in ata_scsi_verify_xlat()
1679 const u8 *cdb = scmd->cmnd; in ata_scsi_verify_xlat()
1684 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_scsi_verify_xlat()
1685 tf->protocol = ATA_PROT_NODATA; in ata_scsi_verify_xlat()
1688 if (scmd->cmd_len < 10) { in ata_scsi_verify_xlat()
1694 if (scmd->cmd_len < 16) { in ata_scsi_verify_xlat()
1711 if (dev->flags & ATA_DFLAG_LBA) { in ata_scsi_verify_xlat()
1712 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_verify_xlat()
1716 tf->command = ATA_CMD_VERIFY; in ata_scsi_verify_xlat()
1717 tf->device |= (block >> 24) & 0xf; in ata_scsi_verify_xlat()
1719 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_scsi_verify_xlat()
1723 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_verify_xlat()
1724 tf->command = ATA_CMD_VERIFY_EXT; in ata_scsi_verify_xlat()
1726 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_scsi_verify_xlat()
1728 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_verify_xlat()
1729 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_verify_xlat()
1730 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_verify_xlat()
1735 tf->nsect = n_block & 0xff; in ata_scsi_verify_xlat()
1737 tf->lbah = (block >> 16) & 0xff; in ata_scsi_verify_xlat()
1738 tf->lbam = (block >> 8) & 0xff; in ata_scsi_verify_xlat()
1739 tf->lbal = block & 0xff; in ata_scsi_verify_xlat()
1741 tf->device |= ATA_LBA; in ata_scsi_verify_xlat()
1750 track = (u32)block / dev->sectors; in ata_scsi_verify_xlat()
1751 cyl = track / dev->heads; in ata_scsi_verify_xlat()
1752 head = track % dev->heads; in ata_scsi_verify_xlat()
1753 sect = (u32)block % dev->sectors + 1; in ata_scsi_verify_xlat()
1759 Cylinder: 0-65535 in ata_scsi_verify_xlat()
1760 Head: 0-15 in ata_scsi_verify_xlat()
1761 Sector: 1-255*/ in ata_scsi_verify_xlat()
1765 tf->command = ATA_CMD_VERIFY; in ata_scsi_verify_xlat()
1766 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_scsi_verify_xlat()
1767 tf->lbal = sect; in ata_scsi_verify_xlat()
1768 tf->lbam = cyl; in ata_scsi_verify_xlat()
1769 tf->lbah = cyl >> 8; in ata_scsi_verify_xlat()
1770 tf->device |= head; in ata_scsi_verify_xlat()
1776 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_verify_xlat()
1780 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x21, 0x0); in ata_scsi_verify_xlat()
1785 scmd->result = SAM_STAT_GOOD; in ata_scsi_verify_xlat()
1791 struct request *rq = scmd->request; in ata_check_nblocks()
1797 req_blocks = blk_rq_bytes(rq) / scmd->device->sector_size; in ata_check_nblocks()
1805 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one
1820 * Zero on success, non-zero on error.
1824 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_rw_xlat()
1825 const u8 *cdb = scmd->cmnd; in ata_scsi_rw_xlat()
1826 struct request *rq = scmd->request; in ata_scsi_rw_xlat()
1841 if (unlikely(scmd->cmd_len < 10)) { in ata_scsi_rw_xlat()
1853 if (unlikely(scmd->cmd_len < 6)) { in ata_scsi_rw_xlat()
1859 /* for 6-byte r/w commands, transfer length 0 in ata_scsi_rw_xlat()
1869 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_rw_xlat()
1880 DPRINTK("no-byte command\n"); in ata_scsi_rw_xlat()
1887 /* For 10-byte and 16-byte SCSI R/W commands, transfer in ata_scsi_rw_xlat()
1896 qc->flags |= ATA_QCFLAG_IO; in ata_scsi_rw_xlat()
1897 qc->nbytes = n_block * scmd->device->sector_size; in ata_scsi_rw_xlat()
1899 rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, in ata_scsi_rw_xlat()
1900 qc->hw_tag, class); in ata_scsi_rw_xlat()
1905 if (rc == -ERANGE) in ata_scsi_rw_xlat()
1907 /* treat all other errors as -EINVAL, fall through */ in ata_scsi_rw_xlat()
1909 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_rw_xlat()
1913 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x21, 0x0); in ata_scsi_rw_xlat()
1918 scmd->result = SAM_STAT_GOOD; in ata_scsi_rw_xlat()
1924 struct scsi_cmnd *cmd = qc->scsicmd; in ata_qc_done()
1925 void (*done)(struct scsi_cmnd *) = qc->scsidone; in ata_qc_done()
1933 struct ata_port *ap = qc->ap; in ata_scsi_qc_complete()
1934 struct scsi_cmnd *cmd = qc->scsicmd; in ata_scsi_qc_complete()
1935 u8 *cdb = cmd->cmnd; in ata_scsi_qc_complete()
1936 int need_sense = (qc->err_mask != 0); in ata_scsi_qc_complete()
1945 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE in ata_scsi_qc_complete()
1950 else if (qc->flags & ATA_QCFLAG_SENSE_VALID) in ata_scsi_qc_complete()
1951 cmd->result = SAM_STAT_CHECK_CONDITION; in ata_scsi_qc_complete()
1955 cmd->result = SAM_STAT_GOOD; in ata_scsi_qc_complete()
1957 if (need_sense && !ap->ops->error_handler) in ata_scsi_qc_complete()
1958 ata_dump_status(ap->print_id, &qc->result_tf); in ata_scsi_qc_complete()
1964 * ata_scsi_translate - Translate then issue SCSI command to ATA device
1969 * Our ->queuecommand() function has decided that the SCSI
1978 * then cmd->result (and possibly cmd->sense_buffer) are assumed
1992 struct ata_port *ap = dev->link->ap; in ata_scsi_translate()
2002 /* data is present; dma-map it */ in ata_scsi_translate()
2003 if (cmd->sc_data_direction == DMA_FROM_DEVICE || in ata_scsi_translate()
2004 cmd->sc_data_direction == DMA_TO_DEVICE) { in ata_scsi_translate()
2012 qc->dma_dir = cmd->sc_data_direction; in ata_scsi_translate()
2015 qc->complete_fn = ata_scsi_qc_complete; in ata_scsi_translate()
2020 if (ap->ops->qc_defer) { in ata_scsi_translate()
2021 if ((rc = ap->ops->qc_defer(qc))) in ata_scsi_translate()
2033 cmd->scsi_done(cmd); in ata_scsi_translate()
2034 DPRINTK("EXIT - early finish (good or error)\n"); in ata_scsi_translate()
2039 cmd->result = (DID_ERROR << 16); in ata_scsi_translate()
2040 cmd->scsi_done(cmd); in ata_scsi_translate()
2042 DPRINTK("EXIT - internal\n"); in ata_scsi_translate()
2047 DPRINTK("EXIT - defer\n"); in ata_scsi_translate()
2061 * ata_scsi_rbuf_get - Map response buffer.
2087 * ata_scsi_rbuf_put - Unmap response buffer.
2108 * ata_scsi_rbuf_fill - wrapper for SCSI command simulators
2116 * completed successfully (0), or not (in which case cmd->result
2127 struct scsi_cmnd *cmd = args->cmd; in ata_scsi_rbuf_fill()
2135 cmd->result = SAM_STAT_GOOD; in ata_scsi_rbuf_fill()
2139 * ata_scsiop_inq_std - Simulate INQUIRY command
2144 * with non-VPD INQUIRY command output.
2153 0x60, /* SAM-3 (no version claimed) */ in ata_scsiop_inq_std()
2156 0x20, /* SBC-2 (no version claimed) */ in ata_scsiop_inq_std()
2159 0x00 /* SPC-3 (no version claimed) */ in ata_scsiop_inq_std()
2163 0xA0, /* SAM-5 (no version claimed) */ in ata_scsiop_inq_std()
2166 0x00, /* SBC-4 (no version claimed) */ in ata_scsiop_inq_std()
2169 0xC0, /* SPC-5 (no version claimed) */ in ata_scsiop_inq_std()
2178 0x5, /* claim SPC-3 version compatibility */ in ata_scsiop_inq_std()
2180 95 - 4, in ata_scsiop_inq_std()
2189 * AHCI port says it's external (Hotplug-capable, eSATA). in ata_scsiop_inq_std()
2191 if (ata_id_removable(args->id) || in ata_scsiop_inq_std()
2192 (args->dev->link->ap->pflags & ATA_PFLAG_EXTERNAL)) in ata_scsiop_inq_std()
2195 if (args->dev->class == ATA_DEV_ZAC) { in ata_scsiop_inq_std()
2197 hdr[2] = 0x7; /* claim SPC-5 version compatibility */ in ata_scsiop_inq_std()
2202 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16); in ata_scsiop_inq_std()
2205 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV + 2, 4); in ata_scsiop_inq_std()
2207 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4); in ata_scsiop_inq_std()
2212 if (ata_id_zoned_cap(args->id) || args->dev->class == ATA_DEV_ZAC) in ata_scsiop_inq_std()
2221 * ata_scsiop_inq_00 - Simulate INQUIRY VPD page 0, list of pages
2245 if (!(args->dev->flags & ATA_DFLAG_ZAC)) in ata_scsiop_inq_00()
2246 num_pages--; in ata_scsiop_inq_00()
2253 * ata_scsiop_inq_80 - Simulate INQUIRY VPD page 80, device serial number
2272 ata_id_string(args->id, (unsigned char *) &rbuf[4], in ata_scsiop_inq_80()
2278 * ata_scsiop_inq_83 - Simulate INQUIRY VPD page 83, device identity
2283 * - vendor specific ASCII containing the ATA serial number
2284 * - SAT defined "t10 vendor id based" containing ASCII vendor
2302 ata_id_string(args->id, (unsigned char *) rbuf + num, in ata_scsiop_inq_83()
2314 ata_id_string(args->id, (unsigned char *) rbuf + num, ATA_ID_PROD, in ata_scsiop_inq_83()
2317 ata_id_string(args->id, (unsigned char *) rbuf + num, ATA_ID_SERNO, in ata_scsiop_inq_83()
2321 if (ata_id_has_wwn(args->id)) { in ata_scsiop_inq_83()
2328 ata_id_string(args->id, (unsigned char *) rbuf + num, in ata_scsiop_inq_83()
2332 rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */ in ata_scsiop_inq_83()
2337 * ata_scsiop_inq_89 - Simulate INQUIRY VPD page 89, ATA info
2341 * Yields SAT-specified ATA VPD page.
2371 memcpy(&rbuf[60], &args->id[0], 512); in ata_scsiop_inq_89()
2389 min_io_sectors = 1 << ata_id_log2_per_physical_sector(args->id); in ata_scsiop_inq_b0()
2398 * that we support some form of unmap - in thise case via WRITE SAME in ata_scsiop_inq_b0()
2401 if (ata_id_has_trim(args->id)) { in ata_scsiop_inq_b0()
2411 int form_factor = ata_id_form_factor(args->id); in ata_scsiop_inq_b1()
2412 int media_rotation_rate = ata_id_rotation_rate(args->id); in ata_scsiop_inq_b1()
2413 u8 zoned = ata_id_zoned_cap(args->id); in ata_scsiop_inq_b1()
2428 /* SCSI Thin Provisioning VPD page: SBC-3 rev 22 or later */ in ata_scsiop_inq_b2()
2439 * zbc-r05 SCSI Zoned Block device characteristics VPD page in ata_scsiop_inq_b6()
2445 * URSWRZ bit is only meaningful for host-managed ZAC drives in ata_scsiop_inq_b6()
2447 if (args->dev->zac_zoned_cap & 1) in ata_scsiop_inq_b6()
2449 put_unaligned_be32(args->dev->zac_zones_optimal_open, &rbuf[8]); in ata_scsiop_inq_b6()
2450 put_unaligned_be32(args->dev->zac_zones_optimal_nonseq, &rbuf[12]); in ata_scsiop_inq_b6()
2451 put_unaligned_be32(args->dev->zac_zones_max_open, &rbuf[16]); in ata_scsiop_inq_b6()
2457 * modecpy - Prepare response for MODE SENSE
2473 memset(dest + 2, 0, n - 2); in modecpy()
2480 * ata_msense_caching - Simulate MODE SENSE caching info page
2505 * ata_msense_control - Simulate MODE SENSE control mode page
2522 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); in ata_msense_control()
2530 * ata_msense_rw_recovery - Simulate MODE SENSE r/w error recovery page
2571 * ata_scsiop_mode_sense - Simulate MODE SENSE 6, 10 commands
2584 struct ata_device *dev = args->dev; in ata_scsiop_mode_sense()
2585 u8 *scsicmd = args->cmd->cmnd, *p = rbuf; in ata_scsiop_mode_sense()
2640 p += ata_msense_caching(args->id, p, page_control == 1); in ata_scsiop_mode_sense()
2644 p += ata_msense_control(args->dev, p, page_control == 1); in ata_scsiop_mode_sense()
2649 p += ata_msense_caching(args->id, p, page_control == 1); in ata_scsiop_mode_sense()
2650 p += ata_msense_control(args->dev, p, page_control == 1); in ata_scsiop_mode_sense()
2659 if (ata_dev_supports_fua(args->id) && (dev->flags & ATA_DFLAG_LBA48) && in ata_scsiop_mode_sense()
2660 (!(dev->flags & ATA_DFLAG_PIO) || dev->multi_count)) in ata_scsiop_mode_sense()
2664 rbuf[0] = p - rbuf - 1; in ata_scsiop_mode_sense()
2671 unsigned int output_len = p - rbuf - 2; in ata_scsiop_mode_sense()
2684 ata_scsi_set_invalid_field(dev, args->cmd, fp, bp); in ata_scsiop_mode_sense()
2688 ata_scsi_set_sense(dev, args->cmd, ILLEGAL_REQUEST, 0x39, 0x0); in ata_scsiop_mode_sense()
2694 * ata_scsiop_read_cap - Simulate READ CAPACITY[ 16] commands
2705 struct ata_device *dev = args->dev; in ata_scsiop_read_cap()
2706 u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */ in ata_scsiop_read_cap()
2711 sector_size = ata_id_logical_sector_size(dev->id); in ata_scsiop_read_cap()
2712 log2_per_phys = ata_id_log2_per_physical_sector(dev->id); in ata_scsiop_read_cap()
2713 lowest_aligned = ata_id_logical_sector_offset(dev->id, log2_per_phys); in ata_scsiop_read_cap()
2717 if (args->cmd->cmnd[0] == READ_CAPACITY) { in ata_scsiop_read_cap()
2721 /* sector count, 32-bit */ in ata_scsiop_read_cap()
2733 /* sector count, 64-bit */ in ata_scsiop_read_cap()
2754 if (ata_id_has_trim(args->id) && in ata_scsiop_read_cap()
2755 !(dev->horkage & ATA_HORKAGE_NOTRIM)) { in ata_scsiop_read_cap()
2758 if (ata_id_has_zero_after_trim(args->id) && in ata_scsiop_read_cap()
2759 dev->horkage & ATA_HORKAGE_ZERO_AFTER_TRIM) { in ata_scsiop_read_cap()
2764 if (ata_id_zoned_cap(args->id) || in ata_scsiop_read_cap()
2765 args->dev->class == ATA_DEV_ZAC) in ata_scsiop_read_cap()
2772 * ata_scsiop_report_luns - Simulate REPORT LUNS command
2791 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) { in atapi_sense_complete()
2806 return (ap->flags & ATA_FLAG_PIO_DMA); in ata_pio_use_silly()
2811 struct ata_port *ap = qc->ap; in atapi_request_sense()
2812 struct scsi_cmnd *cmd = qc->scsicmd; in atapi_request_sense()
2816 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); in atapi_request_sense()
2819 if (ap->ops->sff_tf_read) in atapi_request_sense()
2820 ap->ops->sff_tf_read(ap, &qc->tf); in atapi_request_sense()
2823 /* fill these in, for the case where they are -not- overwritten */ in atapi_request_sense()
2824 cmd->sense_buffer[0] = 0x70; in atapi_request_sense()
2825 cmd->sense_buffer[2] = qc->tf.feature >> 4; in atapi_request_sense()
2830 sg_init_one(&qc->sgent, cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); in atapi_request_sense()
2831 ata_sg_init(qc, &qc->sgent, 1); in atapi_request_sense()
2832 qc->dma_dir = DMA_FROM_DEVICE; in atapi_request_sense()
2834 memset(&qc->cdb, 0, qc->dev->cdb_len); in atapi_request_sense()
2835 qc->cdb[0] = REQUEST_SENSE; in atapi_request_sense()
2836 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; in atapi_request_sense()
2838 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in atapi_request_sense()
2839 qc->tf.command = ATA_CMD_PACKET; in atapi_request_sense()
2842 qc->tf.protocol = ATAPI_PROT_DMA; in atapi_request_sense()
2843 qc->tf.feature |= ATAPI_PKT_DMA; in atapi_request_sense()
2845 qc->tf.protocol = ATAPI_PROT_PIO; in atapi_request_sense()
2846 qc->tf.lbam = SCSI_SENSE_BUFFERSIZE; in atapi_request_sense()
2847 qc->tf.lbah = 0; in atapi_request_sense()
2849 qc->nbytes = SCSI_SENSE_BUFFERSIZE; in atapi_request_sense()
2851 qc->complete_fn = atapi_sense_complete; in atapi_request_sense()
2862 * 1) Fake MMC-5 version, to indicate to the Linux scsi midlayer this is a
2880 struct scsi_cmnd *cmd = qc->scsicmd; in atapi_qc_complete()
2881 unsigned int err_mask = qc->err_mask; in atapi_qc_complete()
2886 if (unlikely(qc->ap->ops->error_handler && in atapi_qc_complete()
2887 (err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID))) { in atapi_qc_complete()
2889 if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) { in atapi_qc_complete()
2898 /* SCSI EH automatically locks door if sdev->locked is in atapi_qc_complete()
2901 * creates a loop - SCSI EH issues door lock which in atapi_qc_complete()
2905 * If door lock fails, always clear sdev->locked to in atapi_qc_complete()
2909 * sure qc->dev->sdev isn't NULL before dereferencing. in atapi_qc_complete()
2911 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev) in atapi_qc_complete()
2912 qc->dev->sdev->locked = 0; in atapi_qc_complete()
2914 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; in atapi_qc_complete()
2921 cmd->result = SAM_STAT_CHECK_CONDITION; in atapi_qc_complete()
2932 if (cmd->cmnd[0] == INQUIRY && (cmd->cmnd[1] & 0x03) == 0) in atapi_qc_complete()
2934 cmd->result = SAM_STAT_GOOD; in atapi_qc_complete()
2940 * atapi_xlat - Initialize PACKET taskfile
2947 * Zero on success, non-zero on failure.
2951 struct scsi_cmnd *scmd = qc->scsicmd; in atapi_xlat()
2952 struct ata_device *dev = qc->dev; in atapi_xlat()
2953 int nodata = (scmd->sc_data_direction == DMA_NONE); in atapi_xlat()
2954 int using_pio = !nodata && (dev->flags & ATA_DFLAG_PIO); in atapi_xlat()
2957 memset(qc->cdb, 0, dev->cdb_len); in atapi_xlat()
2958 memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len); in atapi_xlat()
2960 qc->complete_fn = atapi_qc_complete; in atapi_xlat()
2962 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in atapi_xlat()
2963 if (scmd->sc_data_direction == DMA_TO_DEVICE) { in atapi_xlat()
2964 qc->tf.flags |= ATA_TFLAG_WRITE; in atapi_xlat()
2968 qc->tf.command = ATA_CMD_PACKET; in atapi_xlat()
3009 qc->tf.lbam = (nbytes & 0xFF); in atapi_xlat()
3010 qc->tf.lbah = (nbytes >> 8); in atapi_xlat()
3013 qc->tf.protocol = ATAPI_PROT_NODATA; in atapi_xlat()
3015 qc->tf.protocol = ATAPI_PROT_PIO; in atapi_xlat()
3018 qc->tf.protocol = ATAPI_PROT_DMA; in atapi_xlat()
3019 qc->tf.feature |= ATAPI_PKT_DMA; in atapi_xlat()
3021 if ((dev->flags & ATA_DFLAG_DMADIR) && in atapi_xlat()
3022 (scmd->sc_data_direction != DMA_TO_DEVICE)) in atapi_xlat()
3024 qc->tf.feature |= ATAPI_DMADIR; in atapi_xlat()
3037 devno < ata_link_max_devices(&ap->link))) in ata_find_dev()
3038 return &ap->link.device[devno]; in ata_find_dev()
3041 devno < ap->nr_pmp_links)) in ata_find_dev()
3042 return &ap->pmp_link[devno].device[0]; in ata_find_dev()
3055 if (unlikely(scsidev->channel || scsidev->lun)) in __ata_scsi_find_dev()
3057 devno = scsidev->id; in __ata_scsi_find_dev()
3059 if (unlikely(scsidev->id || scsidev->lun)) in __ata_scsi_find_dev()
3061 devno = scsidev->channel; in __ata_scsi_find_dev()
3068 * ata_scsi_find_dev - lookup ata_device from scsi_cmnd
3095 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
3096 * @byte1: Byte 1 from pass-thru CDB.
3105 case 3: /* Non-data */ in ata_scsi_map_proto()
3109 case 10: /* UDMA Data-in */ in ata_scsi_map_proto()
3110 case 11: /* UDMA Data-Out */ in ata_scsi_map_proto()
3113 case 4: /* PIO Data-in */ in ata_scsi_map_proto()
3114 case 5: /* PIO Data-out */ in ata_scsi_map_proto()
3134 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
3137 * Handles either 12, 16, or 32-byte versions of the CDB.
3140 * Zero on success, non-zero on failure.
3144 struct ata_taskfile *tf = &(qc->tf); in ata_scsi_pass_thru()
3145 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_pass_thru()
3146 struct ata_device *dev = qc->dev; in ata_scsi_pass_thru()
3147 const u8 *cdb = scmd->cmnd; in ata_scsi_pass_thru()
3151 /* 7Fh variable length cmd means a ata pass-thru(32) */ in ata_scsi_pass_thru()
3155 tf->protocol = ata_scsi_map_proto(cdb[1 + cdb_offset]); in ata_scsi_pass_thru()
3156 if (tf->protocol == ATA_PROT_UNKNOWN) { in ata_scsi_pass_thru()
3161 if (ata_is_ncq(tf->protocol) && (cdb[2 + cdb_offset] & 0x3) == 0) in ata_scsi_pass_thru()
3162 tf->protocol = ATA_PROT_NCQ_NODATA; in ata_scsi_pass_thru()
3165 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_pass_thru()
3173 * 16-byte CDB - may contain extended commands. in ata_scsi_pass_thru()
3178 tf->hob_feature = cdb[3]; in ata_scsi_pass_thru()
3179 tf->hob_nsect = cdb[5]; in ata_scsi_pass_thru()
3180 tf->hob_lbal = cdb[7]; in ata_scsi_pass_thru()
3181 tf->hob_lbam = cdb[9]; in ata_scsi_pass_thru()
3182 tf->hob_lbah = cdb[11]; in ata_scsi_pass_thru()
3183 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
3185 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
3190 tf->feature = cdb[4]; in ata_scsi_pass_thru()
3191 tf->nsect = cdb[6]; in ata_scsi_pass_thru()
3192 tf->lbal = cdb[8]; in ata_scsi_pass_thru()
3193 tf->lbam = cdb[10]; in ata_scsi_pass_thru()
3194 tf->lbah = cdb[12]; in ata_scsi_pass_thru()
3195 tf->device = cdb[13]; in ata_scsi_pass_thru()
3196 tf->command = cdb[14]; in ata_scsi_pass_thru()
3199 * 12-byte CDB - incapable of extended commands. in ata_scsi_pass_thru()
3201 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
3203 tf->feature = cdb[3]; in ata_scsi_pass_thru()
3204 tf->nsect = cdb[4]; in ata_scsi_pass_thru()
3205 tf->lbal = cdb[5]; in ata_scsi_pass_thru()
3206 tf->lbam = cdb[6]; in ata_scsi_pass_thru()
3207 tf->lbah = cdb[7]; in ata_scsi_pass_thru()
3208 tf->device = cdb[8]; in ata_scsi_pass_thru()
3209 tf->command = cdb[9]; in ata_scsi_pass_thru()
3212 * 32-byte CDB - may contain extended command fields. in ata_scsi_pass_thru()
3217 tf->hob_feature = cdb[20]; in ata_scsi_pass_thru()
3218 tf->hob_nsect = cdb[22]; in ata_scsi_pass_thru()
3219 tf->hob_lbal = cdb[16]; in ata_scsi_pass_thru()
3220 tf->hob_lbam = cdb[15]; in ata_scsi_pass_thru()
3221 tf->hob_lbah = cdb[14]; in ata_scsi_pass_thru()
3222 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
3224 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
3226 tf->feature = cdb[21]; in ata_scsi_pass_thru()
3227 tf->nsect = cdb[23]; in ata_scsi_pass_thru()
3228 tf->lbal = cdb[19]; in ata_scsi_pass_thru()
3229 tf->lbam = cdb[18]; in ata_scsi_pass_thru()
3230 tf->lbah = cdb[17]; in ata_scsi_pass_thru()
3231 tf->device = cdb[24]; in ata_scsi_pass_thru()
3232 tf->command = cdb[25]; in ata_scsi_pass_thru()
3233 tf->auxiliary = get_unaligned_be32(&cdb[28]); in ata_scsi_pass_thru()
3237 if (ata_is_ncq(tf->protocol)) in ata_scsi_pass_thru()
3238 tf->nsect = qc->hw_tag << 3; in ata_scsi_pass_thru()
3241 tf->device = dev->devno ? in ata_scsi_pass_thru()
3242 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; in ata_scsi_pass_thru()
3244 switch (tf->command) { in ata_scsi_pass_thru()
3245 /* READ/WRITE LONG use a non-standard sect_size */ in ata_scsi_pass_thru()
3250 if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1) { in ata_scsi_pass_thru()
3254 qc->sect_size = scsi_bufflen(scmd); in ata_scsi_pass_thru()
3288 qc->sect_size = scmd->device->sector_size; in ata_scsi_pass_thru()
3293 qc->sect_size = ATA_SECT_SIZE; in ata_scsi_pass_thru()
3301 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_scsi_pass_thru()
3302 if (scmd->sc_data_direction == DMA_TO_DEVICE) in ata_scsi_pass_thru()
3303 tf->flags |= ATA_TFLAG_WRITE; in ata_scsi_pass_thru()
3305 qc->flags |= ATA_QCFLAG_RESULT_TF | ATA_QCFLAG_QUIET; in ata_scsi_pass_thru()
3316 if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0) { in ata_scsi_pass_thru()
3322 if (ata_is_ncq(tf->protocol) && !ata_ncq_enabled(dev)) { in ata_scsi_pass_thru()
3339 if (multi_count != dev->multi_count) in ata_scsi_pass_thru()
3345 * Filter SET_FEATURES - XFER MODE command -- otherwise, in ata_scsi_pass_thru()
3346 * SET_FEATURES - XFER MODE must be preceded/succeeded in ata_scsi_pass_thru()
3347 * by an update to hardware-specific registers for each in ata_scsi_pass_thru()
3348 * controller (i.e. the reason for ->set_piomode(), in ata_scsi_pass_thru()
3349 * ->set_dmamode(), and ->post_set_mode() hooks). in ata_scsi_pass_thru()
3351 if (tf->command == ATA_CMD_SET_FEATURES && in ata_scsi_pass_thru()
3352 tf->feature == SETFEATURES_XFER) { in ata_scsi_pass_thru()
3372 if (tf->command >= 0x5C && tf->command <= 0x5F && !libata_allow_tpm) { in ata_scsi_pass_thru()
3385 * ata_format_dsm_trim_descr() - SATL Write Same to DSM Trim
3391 * Rewrite the WRITE SAME descriptor to be a DSM TRIM little-endian formatted
3408 struct scsi_device *sdp = cmd->device; in ata_format_dsm_trim_descr()
3409 size_t len = sdp->sector_size; in ata_format_dsm_trim_descr()
3429 count -= 0xffff; in ata_format_dsm_trim_descr()
3439 * ata_scsi_write_same_xlat() - SATL Write Same to ATA SCT Write Same
3446 * - When set translate to DSM TRIM
3447 * - When clear translate to SCT Write Same
3451 struct ata_taskfile *tf = &qc->tf; in ata_scsi_write_same_xlat()
3452 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_write_same_xlat()
3453 struct scsi_device *sdp = scmd->device; in ata_scsi_write_same_xlat()
3454 size_t len = sdp->sector_size; in ata_scsi_write_same_xlat()
3455 struct ata_device *dev = qc->dev; in ata_scsi_write_same_xlat()
3456 const u8 *cdb = scmd->cmnd; in ata_scsi_write_same_xlat()
3466 if (unlikely(!dev->dma_mode)) in ata_scsi_write_same_xlat()
3474 if (unlikely(blk_rq_is_passthrough(scmd->request))) in ata_scsi_write_same_xlat()
3477 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_write_same_xlat()
3484 (dev->horkage & ATA_HORKAGE_NOTRIM) || in ata_scsi_write_same_xlat()
3485 !ata_id_has_trim(dev->id)) { in ata_scsi_write_same_xlat()
3505 * For DATA SET MANAGEMENT TRIM in ACS-2 nsect (aka count) in ata_scsi_write_same_xlat()
3515 tf->protocol = ATA_PROT_NCQ; in ata_scsi_write_same_xlat()
3516 tf->command = ATA_CMD_FPDMA_SEND; in ata_scsi_write_same_xlat()
3517 tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f; in ata_scsi_write_same_xlat()
3518 tf->nsect = qc->hw_tag << 3; in ata_scsi_write_same_xlat()
3519 tf->hob_feature = (size / 512) >> 8; in ata_scsi_write_same_xlat()
3520 tf->feature = size / 512; in ata_scsi_write_same_xlat()
3522 tf->auxiliary = 1; in ata_scsi_write_same_xlat()
3524 tf->protocol = ATA_PROT_DMA; in ata_scsi_write_same_xlat()
3525 tf->hob_feature = 0; in ata_scsi_write_same_xlat()
3526 tf->feature = ATA_DSM_TRIM; in ata_scsi_write_same_xlat()
3527 tf->hob_nsect = (size / 512) >> 8; in ata_scsi_write_same_xlat()
3528 tf->nsect = size / 512; in ata_scsi_write_same_xlat()
3529 tf->command = ATA_CMD_DSM; in ata_scsi_write_same_xlat()
3532 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | in ata_scsi_write_same_xlat()
3553 * ata_scsiop_maint_in - Simulate a subset of MAINTENANCE_IN
3564 struct ata_device *dev = args->dev; in ata_scsiop_maint_in()
3565 u8 *cdb = args->cmd->cmnd; in ata_scsiop_maint_in()
3606 if (ata_id_zoned_cap(dev->id) || in ata_scsiop_maint_in()
3607 dev->class == ATA_DEV_ZAC) in ata_scsiop_maint_in()
3612 if (dev->flags & ATA_DFLAG_TRUSTED) in ata_scsiop_maint_in()
3624 * ata_scsi_report_zones_complete - convert ATA output
3627 * Convert T-13 little-endian field representation into
3628 * T-10 big-endian field representation.
3633 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_report_zones_complete()
3696 struct ata_taskfile *tf = &qc->tf; in ata_scsi_zbc_in_xlat()
3697 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_zbc_in_xlat()
3698 const u8 *cdb = scmd->cmnd; in ata_scsi_zbc_in_xlat()
3699 u16 sect, fp = (u16)-1; in ata_scsi_zbc_in_xlat()
3704 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_zbc_in_xlat()
3705 ata_dev_warn(qc->dev, "invalid cdb length %d\n", in ata_scsi_zbc_in_xlat()
3706 scmd->cmd_len); in ata_scsi_zbc_in_xlat()
3712 ata_dev_warn(qc->dev, "non-matching transfer count (%d/%d)\n", in ata_scsi_zbc_in_xlat()
3718 ata_dev_warn(qc->dev, "invalid service action %d\n", sa); in ata_scsi_zbc_in_xlat()
3727 ata_dev_warn(qc->dev, "invalid transfer count %d\n", n_block); in ata_scsi_zbc_in_xlat()
3733 if (ata_ncq_enabled(qc->dev) && in ata_scsi_zbc_in_xlat()
3734 ata_fpdma_zac_mgmt_in_supported(qc->dev)) { in ata_scsi_zbc_in_xlat()
3735 tf->protocol = ATA_PROT_NCQ; in ata_scsi_zbc_in_xlat()
3736 tf->command = ATA_CMD_FPDMA_RECV; in ata_scsi_zbc_in_xlat()
3737 tf->hob_nsect = ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN & 0x1f; in ata_scsi_zbc_in_xlat()
3738 tf->nsect = qc->hw_tag << 3; in ata_scsi_zbc_in_xlat()
3739 tf->feature = sect & 0xff; in ata_scsi_zbc_in_xlat()
3740 tf->hob_feature = (sect >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3741 tf->auxiliary = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES | (options << 8); in ata_scsi_zbc_in_xlat()
3743 tf->command = ATA_CMD_ZAC_MGMT_IN; in ata_scsi_zbc_in_xlat()
3744 tf->feature = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES; in ata_scsi_zbc_in_xlat()
3745 tf->protocol = ATA_PROT_DMA; in ata_scsi_zbc_in_xlat()
3746 tf->hob_feature = options; in ata_scsi_zbc_in_xlat()
3747 tf->hob_nsect = (sect >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3748 tf->nsect = sect & 0xff; in ata_scsi_zbc_in_xlat()
3750 tf->device = ATA_LBA; in ata_scsi_zbc_in_xlat()
3751 tf->lbah = (block >> 16) & 0xff; in ata_scsi_zbc_in_xlat()
3752 tf->lbam = (block >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3753 tf->lbal = block & 0xff; in ata_scsi_zbc_in_xlat()
3754 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_zbc_in_xlat()
3755 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_zbc_in_xlat()
3756 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_zbc_in_xlat()
3758 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48; in ata_scsi_zbc_in_xlat()
3759 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_scsi_zbc_in_xlat()
3763 qc->complete_fn = ata_scsi_report_zones_complete; in ata_scsi_zbc_in_xlat()
3768 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_zbc_in_xlat()
3773 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_zbc_in_xlat()
3779 struct ata_taskfile *tf = &qc->tf; in ata_scsi_zbc_out_xlat()
3780 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_zbc_out_xlat()
3781 struct ata_device *dev = qc->dev; in ata_scsi_zbc_out_xlat()
3782 const u8 *cdb = scmd->cmnd; in ata_scsi_zbc_out_xlat()
3786 u16 fp = (u16)-1; in ata_scsi_zbc_out_xlat()
3788 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_zbc_out_xlat()
3814 } else if (block >= dev->n_sectors) { in ata_scsi_zbc_out_xlat()
3822 if (ata_ncq_enabled(qc->dev) && in ata_scsi_zbc_out_xlat()
3823 ata_fpdma_zac_mgmt_out_supported(qc->dev)) { in ata_scsi_zbc_out_xlat()
3824 tf->protocol = ATA_PROT_NCQ_NODATA; in ata_scsi_zbc_out_xlat()
3825 tf->command = ATA_CMD_NCQ_NON_DATA; in ata_scsi_zbc_out_xlat()
3826 tf->feature = ATA_SUBCMD_NCQ_NON_DATA_ZAC_MGMT_OUT; in ata_scsi_zbc_out_xlat()
3827 tf->nsect = qc->hw_tag << 3; in ata_scsi_zbc_out_xlat()
3828 tf->auxiliary = sa | ((u16)all << 8); in ata_scsi_zbc_out_xlat()
3830 tf->protocol = ATA_PROT_NODATA; in ata_scsi_zbc_out_xlat()
3831 tf->command = ATA_CMD_ZAC_MGMT_OUT; in ata_scsi_zbc_out_xlat()
3832 tf->feature = sa; in ata_scsi_zbc_out_xlat()
3833 tf->hob_feature = all; in ata_scsi_zbc_out_xlat()
3835 tf->lbah = (block >> 16) & 0xff; in ata_scsi_zbc_out_xlat()
3836 tf->lbam = (block >> 8) & 0xff; in ata_scsi_zbc_out_xlat()
3837 tf->lbal = block & 0xff; in ata_scsi_zbc_out_xlat()
3838 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_zbc_out_xlat()
3839 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_zbc_out_xlat()
3840 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_zbc_out_xlat()
3841 tf->device = ATA_LBA; in ata_scsi_zbc_out_xlat()
3842 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48; in ata_scsi_zbc_out_xlat()
3847 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_zbc_out_xlat()
3851 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_zbc_out_xlat()
3856 * ata_mselect_caching - Simulate MODE SELECT for caching info page
3870 struct ata_taskfile *tf = &qc->tf; in ata_mselect_caching()
3871 struct ata_device *dev = qc->dev; in ata_mselect_caching()
3881 if (len != CACHE_MPAGE_LEN - 2) { in ata_mselect_caching()
3882 if (len < CACHE_MPAGE_LEN - 2) in ata_mselect_caching()
3885 *fp = CACHE_MPAGE_LEN - 2; in ata_mselect_caching()
3886 return -EINVAL; in ata_mselect_caching()
3892 * Check that read-only bits are not modified. in ata_mselect_caching()
3894 ata_msense_caching(dev->id, mpage, false); in ata_mselect_caching()
3895 for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) { in ata_mselect_caching()
3900 return -EINVAL; in ata_mselect_caching()
3904 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_mselect_caching()
3905 tf->protocol = ATA_PROT_NODATA; in ata_mselect_caching()
3906 tf->nsect = 0; in ata_mselect_caching()
3907 tf->command = ATA_CMD_SET_FEATURES; in ata_mselect_caching()
3908 tf->feature = wce ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF; in ata_mselect_caching()
3913 * ata_mselect_control - Simulate MODE SELECT for control page
3927 struct ata_device *dev = qc->dev; in ata_mselect_control()
3937 if (len != CONTROL_MPAGE_LEN - 2) { in ata_mselect_control()
3938 if (len < CONTROL_MPAGE_LEN - 2) in ata_mselect_control()
3941 *fp = CONTROL_MPAGE_LEN - 2; in ata_mselect_control()
3942 return -EINVAL; in ata_mselect_control()
3948 * Check that read-only bits are not modified. in ata_mselect_control()
3951 for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) { in ata_mselect_control()
3956 return -EINVAL; in ata_mselect_control()
3960 dev->flags |= ATA_DFLAG_D_SENSE; in ata_mselect_control()
3962 dev->flags &= ~ATA_DFLAG_D_SENSE; in ata_mselect_control()
3967 * ata_scsi_mode_select_xlat - Simulate MODE SELECT 6, 10 commands
3979 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_mode_select_xlat()
3980 const u8 *cdb = scmd->cmnd; in ata_scsi_mode_select_xlat()
3985 u16 fp = (u16)-1; in ata_scsi_mode_select_xlat()
3992 if (scmd->cmd_len < 5) { in ata_scsi_mode_select_xlat()
4000 if (scmd->cmd_len < 9) { in ata_scsi_mode_select_xlat()
4017 if (!scsi_sg_count(scmd) || scsi_sglist(scmd)->length < len) in ata_scsi_mode_select_xlat()
4031 len -= hdr_len; in ata_scsi_mode_select_xlat()
4041 len -= bd_len; in ata_scsi_mode_select_xlat()
4055 len -= 4; in ata_scsi_mode_select_xlat()
4063 len -= 2; in ata_scsi_mode_select_xlat()
4108 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_mode_select_xlat()
4112 ata_scsi_set_invalid_parameter(qc->dev, scmd, fp); in ata_scsi_mode_select_xlat()
4117 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_mode_select_xlat()
4121 scmd->result = SAM_STAT_GOOD; in ata_scsi_mode_select_xlat()
4137 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_security_inout_xlat()
4138 const u8 *cdb = scmd->cmnd; in ata_scsi_security_inout_xlat()
4139 struct ata_taskfile *tf = &qc->tf; in ata_scsi_security_inout_xlat()
4144 bool dma = !(qc->dev->flags & ATA_DFLAG_PIO); in ata_scsi_security_inout_xlat()
4150 ata_scsi_set_invalid_field(qc->dev, scmd, 1, 0); in ata_scsi_security_inout_xlat()
4156 ata_scsi_set_invalid_field(qc->dev, scmd, 6, 0); in ata_scsi_security_inout_xlat()
4161 ata_scsi_set_invalid_field(qc->dev, scmd, 6, 0); in ata_scsi_security_inout_xlat()
4165 /* convert to the sector-based ATA addressing */ in ata_scsi_security_inout_xlat()
4169 tf->protocol = dma ? ATA_PROT_DMA : ATA_PROT_PIO; in ata_scsi_security_inout_xlat()
4170 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR | ATA_TFLAG_LBA; in ata_scsi_security_inout_xlat()
4172 tf->flags |= ATA_TFLAG_WRITE; in ata_scsi_security_inout_xlat()
4173 tf->command = ata_scsi_trusted_op(len, send, dma); in ata_scsi_security_inout_xlat()
4174 tf->feature = secp; in ata_scsi_security_inout_xlat()
4175 tf->lbam = spsp & 0xff; in ata_scsi_security_inout_xlat()
4176 tf->lbah = spsp >> 8; in ata_scsi_security_inout_xlat()
4179 tf->nsect = len & 0xff; in ata_scsi_security_inout_xlat()
4180 tf->lbal = len >> 8; in ata_scsi_security_inout_xlat()
4183 tf->lbah = (1 << 7); in ata_scsi_security_inout_xlat()
4191 * ata_scsi_var_len_cdb_xlat - SATL variable length CDB to Handler
4198 * Zero on success, non-zero on failure
4203 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_var_len_cdb_xlat()
4204 const u8 *cdb = scmd->cmnd; in ata_scsi_var_len_cdb_xlat()
4208 * if service action represents a ata pass-thru(32) command, in ata_scsi_var_len_cdb_xlat()
4219 * ata_get_xlat_func - check if SCSI to ATA translation is possible
4274 if (!(dev->flags & ATA_DFLAG_TRUSTED)) in ata_get_xlat_func()
4286 * ata_scsi_dump_cdb - dump SCSI command contents to dmesg
4297 struct scsi_device *scsidev = cmd->device; in ata_scsi_dump_cdb()
4300 ap->print_id, in ata_scsi_dump_cdb()
4301 scsidev->channel, scsidev->id, scsidev->lun, in ata_scsi_dump_cdb()
4302 cmd->cmnd); in ata_scsi_dump_cdb()
4309 u8 scsi_op = scmd->cmnd[0]; in __ata_scsi_queuecmd()
4313 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in __ata_scsi_queuecmd()
4314 if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len)) in __ata_scsi_queuecmd()
4319 if (unlikely(!scmd->cmd_len)) in __ata_scsi_queuecmd()
4326 if (unlikely(len > scmd->cmd_len || in __ata_scsi_queuecmd()
4327 len > dev->cdb_len || in __ata_scsi_queuecmd()
4328 scmd->cmd_len > ATAPI_CDB_LEN)) in __ata_scsi_queuecmd()
4334 if (unlikely(scmd->cmd_len > 16)) in __ata_scsi_queuecmd()
4350 scmd->cmd_len, scsi_op, dev->cdb_len); in __ata_scsi_queuecmd()
4351 scmd->result = DID_ERROR << 16; in __ata_scsi_queuecmd()
4352 scmd->scsi_done(scmd); in __ata_scsi_queuecmd()
4357 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
4379 struct scsi_device *scsidev = cmd->device; in ata_scsi_queuecmd()
4385 spin_lock_irqsave(ap->lock, irq_flags); in ata_scsi_queuecmd()
4393 cmd->result = (DID_BAD_TARGET << 16); in ata_scsi_queuecmd()
4394 cmd->scsi_done(cmd); in ata_scsi_queuecmd()
4397 spin_unlock_irqrestore(ap->lock, irq_flags); in ata_scsi_queuecmd()
4403 * ata_scsi_simulate - simulate SCSI command on ATA device
4417 const u8 *scsicmd = cmd->cmnd; in ata_scsi_simulate()
4421 args.id = dev->id; in ata_scsi_simulate()
4453 if (dev->flags & ATA_DFLAG_ZAC) { in ata_scsi_simulate()
4486 cmd->result = (DRIVER_SENSE << 24); in ata_scsi_simulate()
4490 * turning this into a no-op. in ata_scsi_simulate()
4495 /* no-op's, complete with success */ in ata_scsi_simulate()
4522 cmd->scsi_done(cmd); in ata_scsi_simulate()
4529 for (i = 0; i < host->n_ports; i++) { in ata_scsi_add_hosts()
4530 struct ata_port *ap = host->ports[i]; in ata_scsi_add_hosts()
4533 rc = -ENOMEM; in ata_scsi_add_hosts()
4538 shost->eh_noresume = 1; in ata_scsi_add_hosts()
4539 *(struct ata_port **)&shost->hostdata[0] = ap; in ata_scsi_add_hosts()
4540 ap->scsi_host = shost; in ata_scsi_add_hosts()
4542 shost->transportt = ata_scsi_transport_template; in ata_scsi_add_hosts()
4543 shost->unique_id = ap->print_id; in ata_scsi_add_hosts()
4544 shost->max_id = 16; in ata_scsi_add_hosts()
4545 shost->max_lun = 1; in ata_scsi_add_hosts()
4546 shost->max_channel = 1; in ata_scsi_add_hosts()
4547 shost->max_cmd_len = 32; in ata_scsi_add_hosts()
4549 /* Schedule policy is determined by ->qc_defer() in ata_scsi_add_hosts()
4554 shost->max_host_blocked = 1; in ata_scsi_add_hosts()
4556 rc = scsi_add_host_with_dma(ap->scsi_host, in ata_scsi_add_hosts()
4557 &ap->tdev, ap->host->dev); in ata_scsi_add_hosts()
4565 scsi_host_put(host->ports[i]->scsi_host); in ata_scsi_add_hosts()
4567 while (--i >= 0) { in ata_scsi_add_hosts()
4568 struct Scsi_Host *shost = host->ports[i]->scsi_host; in ata_scsi_add_hosts()
4589 if (dev->sdev) in ata_scsi_scan_host()
4593 id = dev->devno; in ata_scsi_scan_host()
4595 channel = link->pmp; in ata_scsi_scan_host()
4597 sdev = __scsi_add_device(ap->scsi_host, channel, id, 0, in ata_scsi_scan_host()
4600 dev->sdev = sdev; in ata_scsi_scan_host()
4603 dev->sdev = NULL; in ata_scsi_scan_host()
4614 if (!dev->sdev) in ata_scsi_scan_host()
4636 if (--tries) { in ata_scsi_scan_host()
4645 queue_delayed_work(system_long_wq, &ap->hotplug_task, in ata_scsi_scan_host()
4650 * ata_scsi_offline_dev - offline attached SCSI device
4655 * function is called with host lock which protects dev->sdev
4666 if (dev->sdev) { in ata_scsi_offline_dev()
4667 scsi_device_set_state(dev->sdev, SDEV_OFFLINE); in ata_scsi_offline_dev()
4674 * ata_scsi_remove_dev - remove attached SCSI device
4685 struct ata_port *ap = dev->link->ap; in ata_scsi_remove_dev()
4695 mutex_lock(&ap->scsi_host->scan_mutex); in ata_scsi_remove_dev()
4696 spin_lock_irqsave(ap->lock, flags); in ata_scsi_remove_dev()
4698 /* clearing dev->sdev is protected by host lock */ in ata_scsi_remove_dev()
4699 sdev = dev->sdev; in ata_scsi_remove_dev()
4700 dev->sdev = NULL; in ata_scsi_remove_dev()
4720 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_remove_dev()
4721 mutex_unlock(&ap->scsi_host->scan_mutex); in ata_scsi_remove_dev()
4725 dev_name(&sdev->sdev_gendev)); in ata_scsi_remove_dev()
4734 struct ata_port *ap = link->ap; in ata_scsi_handle_link_detach()
4740 if (!(dev->flags & ATA_DFLAG_DETACHED)) in ata_scsi_handle_link_detach()
4743 spin_lock_irqsave(ap->lock, flags); in ata_scsi_handle_link_detach()
4744 dev->flags &= ~ATA_DFLAG_DETACHED; in ata_scsi_handle_link_detach()
4745 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_handle_link_detach()
4755 * ata_scsi_media_change_notify - send media change event
4766 if (dev->sdev) in ata_scsi_media_change_notify()
4767 sdev_evt_send_simple(dev->sdev, SDEV_EVT_MEDIA_CHANGE, in ata_scsi_media_change_notify()
4772 * ata_scsi_hotplug - SCSI part of hotplug
4789 if (ap->pflags & ATA_PFLAG_UNLOADING) { in ata_scsi_hotplug()
4790 DPRINTK("ENTER/EXIT - unloading\n"); in ata_scsi_hotplug()
4795 mutex_lock(&ap->scsi_scan_mutex); in ata_scsi_hotplug()
4801 ata_scsi_handle_link_detach(&ap->link); in ata_scsi_hotplug()
4802 if (ap->pmp_link) in ata_scsi_hotplug()
4804 ata_scsi_handle_link_detach(&ap->pmp_link[i]); in ata_scsi_hotplug()
4809 mutex_unlock(&ap->scsi_scan_mutex); in ata_scsi_hotplug()
4814 * ata_scsi_user_scan - indication for user-initiated bus scan
4836 if (!ap->ops->error_handler) in ata_scsi_user_scan()
4837 return -EOPNOTSUPP; in ata_scsi_user_scan()
4840 return -EINVAL; in ata_scsi_user_scan()
4844 return -EINVAL; in ata_scsi_user_scan()
4848 return -EINVAL; in ata_scsi_user_scan()
4852 spin_lock_irqsave(ap->lock, flags); in ata_scsi_user_scan()
4858 struct ata_eh_info *ehi = &link->eh_info; in ata_scsi_user_scan()
4859 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_scsi_user_scan()
4860 ehi->action |= ATA_EH_RESET; in ata_scsi_user_scan()
4866 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_scsi_user_scan()
4867 ehi->probe_mask |= 1 << dev->devno; in ata_scsi_user_scan()
4868 ehi->action |= ATA_EH_RESET; in ata_scsi_user_scan()
4870 rc = -EINVAL; in ata_scsi_user_scan()
4875 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_user_scan()
4878 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_user_scan()
4884 * ata_scsi_dev_rescan - initiate scsi_rescan_device()
4901 mutex_lock(&ap->scsi_scan_mutex); in ata_scsi_dev_rescan()
4902 spin_lock_irqsave(ap->lock, flags); in ata_scsi_dev_rescan()
4906 struct scsi_device *sdev = dev->sdev; in ata_scsi_dev_rescan()
4913 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_dev_rescan()
4914 scsi_rescan_device(&(sdev->sdev_gendev)); in ata_scsi_dev_rescan()
4916 spin_lock_irqsave(ap->lock, flags); in ata_scsi_dev_rescan()
4920 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_dev_rescan()
4921 mutex_unlock(&ap->scsi_scan_mutex); in ata_scsi_dev_rescan()
4925 * ata_sas_port_alloc - Allocate port for a SAS attached SATA device
4927 * @port_info: Information from low-level host driver
4947 ap->port_no = 0; in ata_sas_port_alloc()
4948 ap->lock = &host->lock; in ata_sas_port_alloc()
4949 ap->pio_mask = port_info->pio_mask; in ata_sas_port_alloc()
4950 ap->mwdma_mask = port_info->mwdma_mask; in ata_sas_port_alloc()
4951 ap->udma_mask = port_info->udma_mask; in ata_sas_port_alloc()
4952 ap->flags |= port_info->flags; in ata_sas_port_alloc()
4953 ap->ops = port_info->port_ops; in ata_sas_port_alloc()
4954 ap->cbl = ATA_CBL_SATA; in ata_sas_port_alloc()
4961 * ata_sas_port_start - Set port up for dma.
4978 if (!ap->ops->error_handler) in ata_sas_port_start()
4979 ap->pflags &= ~ATA_PFLAG_FROZEN; in ata_sas_port_start()
4985 * ata_port_stop - Undo ata_sas_port_start()
5000 * ata_sas_async_probe - simply schedule probing and return
5020 * ata_sas_port_init - Initialize a SATA device
5027 * Zero on success, non-zero on error.
5032 int rc = ap->ops->port_start(ap); in ata_sas_port_init()
5036 ap->print_id = atomic_inc_return(&ata_print_id); in ata_sas_port_init()
5054 * ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc
5061 if (ap->ops->port_stop) in ata_sas_port_destroy()
5062 ap->ops->port_stop(ap); in ata_sas_port_destroy()
5068 * ata_sas_slave_configure - Default slave_config routine for libata devices
5079 ata_scsi_dev_config(sdev, ap->link.device); in ata_sas_slave_configure()
5085 * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
5100 if (likely(ata_dev_enabled(ap->link.device))) in ata_sas_queuecmd()
5101 rc = __ata_scsi_queuecmd(cmd, ap->link.device); in ata_sas_queuecmd()
5103 cmd->result = (DID_BAD_TARGET << 16); in ata_sas_queuecmd()
5104 cmd->scsi_done(cmd); in ata_sas_queuecmd()
5112 unsigned int max_queue = ap->host->n_tags; in ata_sas_allocate_tag()
5115 for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) { in ata_sas_allocate_tag()
5122 if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { in ata_sas_allocate_tag()
5123 ap->sas_last_tag = tag; in ata_sas_allocate_tag()
5127 return -1; in ata_sas_allocate_tag()
5132 clear_bit(tag, &ap->sas_tag_allocated); in ata_sas_free_tag()