Lines Matching +full:bp +full:- +full:disabled +full:- +full:ports

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"
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 */
103 ap = ata_shost_to_port(sdev->host); in ata_scsi_park_show()
105 spin_lock_irq(ap->lock); in ata_scsi_park_show()
108 rc = -ENODEV; in ata_scsi_park_show()
111 if (dev->flags & ATA_DFLAG_NO_UNLOAD) { in ata_scsi_park_show()
112 rc = -EOPNOTSUPP; in ata_scsi_park_show()
116 link = dev->link; in ata_scsi_park_show()
118 if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS && in ata_scsi_park_show()
119 link->eh_context.unloaded_mask & (1 << dev->devno) && in ata_scsi_park_show()
120 time_after(dev->unpark_deadline, now)) in ata_scsi_park_show()
121 msecs = jiffies_to_msecs(dev->unpark_deadline - now); in ata_scsi_park_show()
126 spin_unlock_irq(ap->lock); in ata_scsi_park_show()
145 if (input < -2) in ata_scsi_park_store()
146 return -EINVAL; in ata_scsi_park_store()
148 rc = -EOVERFLOW; in ata_scsi_park_store()
152 ap = ata_shost_to_port(sdev->host); in ata_scsi_park_store()
154 spin_lock_irqsave(ap->lock, flags); in ata_scsi_park_store()
157 rc = -ENODEV; in ata_scsi_park_store()
160 if (dev->class != ATA_DEV_ATA && in ata_scsi_park_store()
161 dev->class != ATA_DEV_ZAC) { in ata_scsi_park_store()
162 rc = -EOPNOTSUPP; in ata_scsi_park_store()
167 if (dev->flags & ATA_DFLAG_NO_UNLOAD) { in ata_scsi_park_store()
168 rc = -EOPNOTSUPP; in ata_scsi_park_store()
172 dev->unpark_deadline = ata_deadline(jiffies, input); in ata_scsi_park_store()
173 dev->link->eh_info.dev_action[dev->devno] |= ATA_EH_PARK; in ata_scsi_park_store()
175 complete(&ap->park_req_pending); in ata_scsi_park_store()
178 case -1: in ata_scsi_park_store()
179 dev->flags &= ~ATA_DFLAG_NO_UNLOAD; in ata_scsi_park_store()
181 case -2: in ata_scsi_park_store()
182 dev->flags |= ATA_DFLAG_NO_UNLOAD; in ata_scsi_park_store()
187 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_park_store()
214 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); in ata_scsi_set_sense()
229 scsi_set_sense_information(cmd->sense_buffer, in ata_scsi_set_sense_information()
238 scsi_set_sense_field_pointer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, in ata_scsi_set_invalid_field()
247 scsi_set_sense_field_pointer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, in ata_scsi_set_invalid_parameter()
267 * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd.
297 * ata_scsi_unlock_native_capacity - unlock native capacity
308 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_unlock_native_capacity()
312 spin_lock_irqsave(ap->lock, flags); in ata_scsi_unlock_native_capacity()
315 if (dev && dev->n_sectors < dev->n_native_sectors) { in ata_scsi_unlock_native_capacity()
316 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_scsi_unlock_native_capacity()
317 dev->link->eh_info.action |= ATA_EH_RESET; in ata_scsi_unlock_native_capacity()
321 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_unlock_native_capacity()
327 * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl
346 return -ENOMSG; in ata_get_identity()
348 if (copy_to_user(dst, dev->id, ATA_ID_WORDS * sizeof(u16))) in ata_get_identity()
349 return -EFAULT; in ata_get_identity()
351 ata_id_string(dev->id, buf, ATA_ID_PROD, ATA_ID_PROD_LEN); in ata_get_identity()
353 return -EFAULT; in ata_get_identity()
355 ata_id_string(dev->id, buf, ATA_ID_FW_REV, ATA_ID_FW_REV_LEN); in ata_get_identity()
357 return -EFAULT; in ata_get_identity()
359 ata_id_string(dev->id, buf, ATA_ID_SERNO, ATA_ID_SERNO_LEN); in ata_get_identity()
361 return -EFAULT; in ata_get_identity()
367 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
393 return -EINVAL; in ata_cmd_ioctl()
396 return -EFAULT; in ata_cmd_ioctl()
405 rc = -ENOMEM; in ata_cmd_ioctl()
409 scsi_cmd[1] = (4 << 1); /* PIO Data-in */ in ata_cmd_ioctl()
413 scsi_cmd[1] = (3 << 1); /* Non-data */ in ata_cmd_ioctl()
420 if (args[0] == ATA_CMD_SMART) { /* hack -- ide driver does this too */ in ata_cmd_ioctl()
441 /* If we set cc then ATA pass-through will cause a in ata_cmd_ioctl()
456 rc = -EFAULT; in ata_cmd_ioctl()
462 rc = -EIO; in ata_cmd_ioctl()
468 rc = -EFAULT; in ata_cmd_ioctl()
475 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
500 return -EINVAL; in ata_task_ioctl()
503 return -EFAULT; in ata_task_ioctl()
508 scsi_cmd[1] = (3 << 1); /* Non-data */ in ata_task_ioctl()
529 /* If we set cc then ATA pass-through will cause a in ata_task_ioctl()
548 rc = -EFAULT; in ata_task_ioctl()
553 rc = -EIO; in ata_task_ioctl()
563 if (ap->flags & ATA_FLAG_PIO_DMA) in ata_ioc32()
565 if (ap->pflags & ATA_PFLAG_PIO32) in ata_ioc32()
578 int rc = -EINVAL; in ata_sas_scsi_ioctl()
583 spin_lock_irqsave(ap->lock, flags); in ata_sas_scsi_ioctl()
585 spin_unlock_irqrestore(ap->lock, flags); in ata_sas_scsi_ioctl()
595 spin_lock_irqsave(ap->lock, flags); in ata_sas_scsi_ioctl()
596 if (ap->pflags & ATA_PFLAG_PIO32CHANGE) { in ata_sas_scsi_ioctl()
598 ap->pflags |= ATA_PFLAG_PIO32; in ata_sas_scsi_ioctl()
600 ap->pflags &= ~ATA_PFLAG_PIO32; in ata_sas_scsi_ioctl()
603 rc = -EINVAL; in ata_sas_scsi_ioctl()
605 spin_unlock_irqrestore(ap->lock, flags); in ata_sas_scsi_ioctl()
613 return -EACCES; in ata_sas_scsi_ioctl()
618 return -EACCES; in ata_sas_scsi_ioctl()
622 rc = -ENOTTY; in ata_sas_scsi_ioctl()
633 return ata_sas_scsi_ioctl(ata_shost_to_port(scsidev->host), in ata_scsi_ioctl()
639 * ata_scsi_qc_new - acquire new ata_queued_cmd reference
647 * If a command was available, fill in the SCSI-specific
660 struct ata_port *ap = dev->link->ap; in ata_scsi_qc_new()
667 if (ap->flags & ATA_FLAG_SAS_HOST) { in ata_scsi_qc_new()
670 * unique per-device budget token as a tag. in ata_scsi_qc_new()
672 if (WARN_ON_ONCE(cmd->budget_token >= ATA_MAX_QUEUE)) in ata_scsi_qc_new()
674 tag = cmd->budget_token; in ata_scsi_qc_new()
676 tag = scsi_cmd_to_rq(cmd)->tag; in ata_scsi_qc_new()
680 qc->tag = qc->hw_tag = tag; in ata_scsi_qc_new()
681 qc->ap = ap; in ata_scsi_qc_new()
682 qc->dev = dev; in ata_scsi_qc_new()
686 qc->scsicmd = cmd; in ata_scsi_qc_new()
687 qc->scsidone = scsi_done; in ata_scsi_qc_new()
689 qc->sg = scsi_sglist(cmd); in ata_scsi_qc_new()
690 qc->n_elem = scsi_sg_count(cmd); in ata_scsi_qc_new()
692 if (scsi_cmd_to_rq(cmd)->rq_flags & RQF_QUIET) in ata_scsi_qc_new()
693 qc->flags |= ATA_QCFLAG_QUIET; in ata_scsi_qc_new()
706 struct scsi_cmnd *scmd = qc->scsicmd; in ata_qc_set_pc_nbytes()
708 qc->extrabytes = scmd->extra_len; in ata_qc_set_pc_nbytes()
709 qc->nbytes = scsi_bufflen(scmd) + qc->extrabytes; in ata_qc_set_pc_nbytes()
713 * ata_to_sense_error - convert ATA error to SCSI error
756 /* TRK0 - Track 0 not found */ in ata_to_sense_error()
763 /* SRV/IDNF - ID not found */ in ata_to_sense_error()
766 /* MC - Media Changed */ in ata_to_sense_error()
769 /* ECC - Uncorrectable ECC error */ in ata_to_sense_error()
772 /* BBD - block marked bad */ in ata_to_sense_error()
837 * ata_gen_passthru_sense - Generate check condition sense block.
847 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE
855 struct scsi_cmnd *cmd = qc->scsicmd; in ata_gen_passthru_sense()
856 struct ata_taskfile *tf = &qc->result_tf; in ata_gen_passthru_sense()
857 unsigned char *sb = cmd->sense_buffer; in ata_gen_passthru_sense()
867 if (qc->err_mask || in ata_gen_passthru_sense()
868 tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { in ata_gen_passthru_sense()
869 ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, 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()
880 if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { in ata_gen_passthru_sense()
898 desc[3] = tf->error; in ata_gen_passthru_sense()
899 desc[5] = tf->nsect; in ata_gen_passthru_sense()
900 desc[7] = tf->lbal; in ata_gen_passthru_sense()
901 desc[9] = tf->lbam; in ata_gen_passthru_sense()
902 desc[11] = tf->lbah; in ata_gen_passthru_sense()
903 desc[12] = tf->device; in ata_gen_passthru_sense()
904 desc[13] = tf->status; in ata_gen_passthru_sense()
910 if (tf->flags & ATA_TFLAG_LBA48) { in ata_gen_passthru_sense()
912 desc[4] = tf->hob_nsect; in ata_gen_passthru_sense()
913 desc[6] = tf->hob_lbal; in ata_gen_passthru_sense()
914 desc[8] = tf->hob_lbam; in ata_gen_passthru_sense()
915 desc[10] = tf->hob_lbah; in ata_gen_passthru_sense()
919 desc[0] = tf->error; in ata_gen_passthru_sense()
920 desc[1] = tf->status; in ata_gen_passthru_sense()
921 desc[2] = tf->device; in ata_gen_passthru_sense()
922 desc[3] = tf->nsect; in ata_gen_passthru_sense()
924 if (tf->flags & ATA_TFLAG_LBA48) { in ata_gen_passthru_sense()
926 if (tf->hob_nsect) in ata_gen_passthru_sense()
928 if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) in ata_gen_passthru_sense()
931 desc[9] = tf->lbal; in ata_gen_passthru_sense()
932 desc[10] = tf->lbam; in ata_gen_passthru_sense()
933 desc[11] = tf->lbah; in ata_gen_passthru_sense()
938 * ata_gen_ata_sense - generate a SCSI fixed sense block
949 struct ata_device *dev = qc->dev; in ata_gen_ata_sense()
950 struct scsi_cmnd *cmd = qc->scsicmd; in ata_gen_ata_sense()
951 struct ata_taskfile *tf = &qc->result_tf; in ata_gen_ata_sense()
952 unsigned char *sb = cmd->sense_buffer; in ata_gen_ata_sense()
959 /* Device disabled after error recovery */ in ata_gen_ata_sense()
967 if (qc->err_mask || in ata_gen_ata_sense()
968 tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { in ata_gen_ata_sense()
969 ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, in ata_gen_ata_sense()
975 tf->status, qc->err_mask); in ata_gen_ata_sense()
980 block = ata_tf_read_block(&qc->result_tf, dev); in ata_gen_ata_sense()
989 sdev->use_10_for_rw = 1; in ata_scsi_sdev_config()
990 sdev->use_10_for_ms = 1; in ata_scsi_sdev_config()
991 sdev->no_write_same = 1; in ata_scsi_sdev_config()
993 /* Schedule policy is determined by ->qc_defer() callback and in ata_scsi_sdev_config()
998 sdev->max_device_blocked = 1; in ata_scsi_sdev_config()
1002 * ata_scsi_dma_need_drain - Check whether data transfer may overflow
1020 return atapi_cmd_type(scmd->cmnd[0]) == ATAPI_MISC; in ata_scsi_dma_need_drain()
1026 struct request_queue *q = sdev->request_queue; in ata_scsi_dev_config()
1029 if (!ata_id_has_unload(dev->id)) in ata_scsi_dev_config()
1030 dev->flags |= ATA_DFLAG_NO_UNLOAD; in ata_scsi_dev_config()
1033 dev->max_sectors = min(dev->max_sectors, sdev->host->max_sectors); 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, GFP_NOIO); in ata_scsi_dev_config()
1047 if (!sdev->dma_drain_buf) { in ata_scsi_dev_config()
1049 return -ENOMEM; in ata_scsi_dev_config()
1052 sdev->sector_size = ata_id_logical_sector_size(dev->id); in ata_scsi_dev_config()
1059 sdev->manage_runtime_start_stop = true; in ata_scsi_dev_config()
1060 sdev->manage_shutdown = true; in ata_scsi_dev_config()
1070 if (sdev->sector_size > PAGE_SIZE) in ata_scsi_dev_config()
1073 sdev->sector_size); in ata_scsi_dev_config()
1075 blk_queue_update_dma_alignment(q, sdev->sector_size - 1); in ata_scsi_dev_config()
1077 if (dev->flags & ATA_DFLAG_AN) in ata_scsi_dev_config()
1078 set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events); in ata_scsi_dev_config()
1081 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); in ata_scsi_dev_config()
1085 if (dev->flags & ATA_DFLAG_TRUSTED) in ata_scsi_dev_config()
1086 sdev->security_supported = 1; in ata_scsi_dev_config()
1088 dev->sdev = sdev; in ata_scsi_dev_config()
1093 * ata_scsi_slave_alloc - Early setup of SCSI device
1105 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_alloc()
1115 link = device_link_add(&sdev->sdev_gendev, &ap->tdev, in ata_scsi_slave_alloc()
1120 dev_name(&sdev->sdev_gendev)); in ata_scsi_slave_alloc()
1121 return -ENODEV; in ata_scsi_slave_alloc()
1129 * ata_scsi_slave_config - Set SCSI device attributes
1134 * SCSI mid-layer behaviors.
1142 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_config()
1153 * ata_scsi_slave_destroy - SCSI device is about to be destroyed
1158 * dev->sdev, this function doesn't have to do anything.
1159 * Otherwise, SCSI layer initiated warm-unplug is in progress.
1160 * Clear dev->sdev, schedule the device for ATA detach and invoke
1168 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_slave_destroy()
1172 device_link_remove(&sdev->sdev_gendev, &ap->tdev); in ata_scsi_slave_destroy()
1174 spin_lock_irqsave(ap->lock, flags); in ata_scsi_slave_destroy()
1176 if (dev && dev->sdev) { in ata_scsi_slave_destroy()
1178 dev->sdev = NULL; in ata_scsi_slave_destroy()
1179 dev->flags |= ATA_DFLAG_DETACH; in ata_scsi_slave_destroy()
1182 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_slave_destroy()
1184 kfree(sdev->dma_drain_buf); in ata_scsi_slave_destroy()
1189 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
1201 * Zero on success, non-zero on error.
1205 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_start_stop_xlat()
1206 struct ata_taskfile *tf = &qc->tf; in ata_scsi_start_stop_xlat()
1207 const u8 *cdb = scmd->cmnd; in ata_scsi_start_stop_xlat()
1209 u8 bp = 0xff; in ata_scsi_start_stop_xlat() local
1211 if (scmd->cmd_len < 5) { in ata_scsi_start_stop_xlat()
1216 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_scsi_start_stop_xlat()
1217 tf->protocol = ATA_PROT_NODATA; in ata_scsi_start_stop_xlat()
1219 ; /* ignore IMMED bit, violates sat-r05 */ in ata_scsi_start_stop_xlat()
1223 bp = 1; in ata_scsi_start_stop_xlat()
1228 bp = 3; in ata_scsi_start_stop_xlat()
1233 tf->nsect = 1; /* 1 sector, lba=0 */ in ata_scsi_start_stop_xlat()
1235 if (qc->dev->flags & ATA_DFLAG_LBA) { in ata_scsi_start_stop_xlat()
1236 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_start_stop_xlat()
1238 tf->lbah = 0x0; in ata_scsi_start_stop_xlat()
1239 tf->lbam = 0x0; in ata_scsi_start_stop_xlat()
1240 tf->lbal = 0x0; in ata_scsi_start_stop_xlat()
1241 tf->device |= ATA_LBA; in ata_scsi_start_stop_xlat()
1244 tf->lbal = 0x1; /* sect */ in ata_scsi_start_stop_xlat()
1245 tf->lbam = 0x0; /* cyl low */ in ata_scsi_start_stop_xlat()
1246 tf->lbah = 0x0; /* cyl high */ in ata_scsi_start_stop_xlat()
1249 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ in ata_scsi_start_stop_xlat()
1254 if ((qc->ap->flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && in ata_scsi_start_stop_xlat()
1258 if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && in ata_scsi_start_stop_xlat()
1263 tf->command = ATA_CMD_STANDBYNOW1; in ata_scsi_start_stop_xlat()
1276 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_start_stop_xlat()
1279 scmd->result = SAM_STAT_GOOD; in ata_scsi_start_stop_xlat()
1285 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command
1295 * Zero on success, non-zero on error.
1299 struct ata_taskfile *tf = &qc->tf; in ata_scsi_flush_xlat()
1301 tf->flags |= ATA_TFLAG_DEVICE; in ata_scsi_flush_xlat()
1302 tf->protocol = ATA_PROT_NODATA; in ata_scsi_flush_xlat()
1304 if (qc->dev->flags & ATA_DFLAG_FLUSH_EXT) in ata_scsi_flush_xlat()
1305 tf->command = ATA_CMD_FLUSH_EXT; in ata_scsi_flush_xlat()
1307 tf->command = ATA_CMD_FLUSH; in ata_scsi_flush_xlat()
1310 qc->flags |= ATA_QCFLAG_IO; in ata_scsi_flush_xlat()
1316 * scsi_6_lba_len - Get LBA and transfer length
1319 * Calculate LBA and transfer length for 6-byte commands.
1341 * scsi_10_lba_len - Get LBA and transfer length
1344 * Calculate LBA and transfer length for 10-byte commands.
1357 * scsi_16_lba_len - Get LBA and transfer length
1360 * Calculate LBA and transfer length for 16-byte commands.
1373 * scsi_dld - Get duration limit descriptor index
1385 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
1394 * Zero on success, non-zero on error.
1398 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_verify_xlat()
1399 struct ata_taskfile *tf = &qc->tf; in ata_scsi_verify_xlat()
1400 struct ata_device *dev = qc->dev; in ata_scsi_verify_xlat()
1401 u64 dev_sectors = qc->dev->n_sectors; in ata_scsi_verify_xlat()
1402 const u8 *cdb = scmd->cmnd; in ata_scsi_verify_xlat()
1407 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_scsi_verify_xlat()
1408 tf->protocol = ATA_PROT_NODATA; in ata_scsi_verify_xlat()
1412 if (scmd->cmd_len < 10) { in ata_scsi_verify_xlat()
1419 if (scmd->cmd_len < 16) { in ata_scsi_verify_xlat()
1437 if (dev->flags & ATA_DFLAG_LBA) { in ata_scsi_verify_xlat()
1438 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_verify_xlat()
1442 tf->command = ATA_CMD_VERIFY; in ata_scsi_verify_xlat()
1443 tf->device |= (block >> 24) & 0xf; in ata_scsi_verify_xlat()
1445 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_scsi_verify_xlat()
1449 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_verify_xlat()
1450 tf->command = ATA_CMD_VERIFY_EXT; in ata_scsi_verify_xlat()
1452 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_scsi_verify_xlat()
1454 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_verify_xlat()
1455 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_verify_xlat()
1456 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_verify_xlat()
1461 tf->nsect = n_block & 0xff; in ata_scsi_verify_xlat()
1463 tf->lbah = (block >> 16) & 0xff; in ata_scsi_verify_xlat()
1464 tf->lbam = (block >> 8) & 0xff; in ata_scsi_verify_xlat()
1465 tf->lbal = block & 0xff; in ata_scsi_verify_xlat()
1467 tf->device |= ATA_LBA; in ata_scsi_verify_xlat()
1476 track = (u32)block / dev->sectors; in ata_scsi_verify_xlat()
1477 cyl = track / dev->heads; in ata_scsi_verify_xlat()
1478 head = track % dev->heads; in ata_scsi_verify_xlat()
1479 sect = (u32)block % dev->sectors + 1; in ata_scsi_verify_xlat()
1482 Cylinder: 0-65535 in ata_scsi_verify_xlat()
1483 Head: 0-15 in ata_scsi_verify_xlat()
1484 Sector: 1-255*/ in ata_scsi_verify_xlat()
1488 tf->command = ATA_CMD_VERIFY; in ata_scsi_verify_xlat()
1489 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_scsi_verify_xlat()
1490 tf->lbal = sect; in ata_scsi_verify_xlat()
1491 tf->lbam = cyl; in ata_scsi_verify_xlat()
1492 tf->lbah = cyl >> 8; in ata_scsi_verify_xlat()
1493 tf->device |= head; in ata_scsi_verify_xlat()
1499 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_verify_xlat()
1503 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x21, 0x0); in ata_scsi_verify_xlat()
1508 scmd->result = SAM_STAT_GOOD; in ata_scsi_verify_xlat()
1520 req_blocks = blk_rq_bytes(rq) / scmd->device->sector_size; in ata_check_nblocks()
1528 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one
1543 * Zero on success, non-zero on error.
1547 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_rw_xlat()
1548 const u8 *cdb = scmd->cmnd; in ata_scsi_rw_xlat()
1570 if (unlikely(scmd->cmd_len < 10)) { in ata_scsi_rw_xlat()
1582 if (unlikely(scmd->cmd_len < 6)) { in ata_scsi_rw_xlat()
1588 /* for 6-byte r/w commands, transfer length 0 in ata_scsi_rw_xlat()
1598 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_rw_xlat()
1616 /* For 10-byte and 16-byte SCSI R/W commands, transfer in ata_scsi_rw_xlat()
1625 qc->flags |= ATA_QCFLAG_IO; in ata_scsi_rw_xlat()
1626 qc->nbytes = n_block * scmd->device->sector_size; in ata_scsi_rw_xlat()
1632 if (rc == -ERANGE) in ata_scsi_rw_xlat()
1634 /* treat all other errors as -EINVAL, fall through */ in ata_scsi_rw_xlat()
1636 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_rw_xlat()
1640 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x21, 0x0); in ata_scsi_rw_xlat()
1645 scmd->result = SAM_STAT_GOOD; in ata_scsi_rw_xlat()
1651 struct scsi_cmnd *cmd = qc->scsicmd; in ata_qc_done()
1652 void (*done)(struct scsi_cmnd *) = qc->scsidone; in ata_qc_done()
1660 struct scsi_cmnd *cmd = qc->scsicmd; in ata_scsi_qc_complete()
1661 u8 *cdb = cmd->cmnd; in ata_scsi_qc_complete()
1662 int need_sense = (qc->err_mask != 0) && in ata_scsi_qc_complete()
1663 !(qc->flags & ATA_QCFLAG_SENSE_VALID); in ata_scsi_qc_complete()
1672 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE in ata_scsi_qc_complete()
1681 cmd->result &= 0x0000ffff; in ata_scsi_qc_complete()
1687 * ata_scsi_translate - Translate then issue SCSI command to ATA device
1692 * Our ->queuecommand() function has decided that the SCSI
1701 * then cmd->result (and possibly cmd->sense_buffer) are assumed
1715 struct ata_port *ap = dev->link->ap; in ata_scsi_translate()
1723 /* data is present; dma-map it */ in ata_scsi_translate()
1724 if (cmd->sc_data_direction == DMA_FROM_DEVICE || in ata_scsi_translate()
1725 cmd->sc_data_direction == DMA_TO_DEVICE) { in ata_scsi_translate()
1733 qc->dma_dir = cmd->sc_data_direction; in ata_scsi_translate()
1736 qc->complete_fn = ata_scsi_qc_complete; in ata_scsi_translate()
1741 if (ap->ops->qc_defer) { in ata_scsi_translate()
1742 if ((rc = ap->ops->qc_defer(qc))) in ata_scsi_translate()
1758 cmd->result = (DID_ERROR << 16); in ata_scsi_translate()
1778 * ata_scsi_rbuf_fill - wrapper for SCSI command simulators
1786 * completed successfully (0), or not (in which case cmd->result
1796 struct scsi_cmnd *cmd = args->cmd; in ata_scsi_rbuf_fill()
1810 cmd->result = SAM_STAT_GOOD; in ata_scsi_rbuf_fill()
1814 * ata_scsiop_inq_std - Simulate INQUIRY command
1819 * with non-VPD INQUIRY command output.
1828 0x60, /* SAM-3 (no version claimed) */ in ata_scsiop_inq_std()
1831 0x20, /* SBC-2 (no version claimed) */ in ata_scsiop_inq_std()
1834 0x00 /* SPC-3 (no version claimed) */ in ata_scsiop_inq_std()
1838 0xA0, /* SAM-5 (no version claimed) */ in ata_scsiop_inq_std()
1841 0x00, /* SBC-4 (no version claimed) */ in ata_scsiop_inq_std()
1844 0xC0, /* SPC-5 (no version claimed) */ in ata_scsiop_inq_std()
1853 0x5, /* claim SPC-3 version compatibility */ in ata_scsiop_inq_std()
1855 95 - 4, in ata_scsiop_inq_std()
1862 * AHCI port says it's external (Hotplug-capable, eSATA). in ata_scsiop_inq_std()
1864 if (ata_id_removable(args->id) || in ata_scsiop_inq_std()
1865 (args->dev->link->ap->pflags & ATA_PFLAG_EXTERNAL)) in ata_scsiop_inq_std()
1868 if (args->dev->class == ATA_DEV_ZAC) { in ata_scsiop_inq_std()
1870 hdr[2] = 0x7; /* claim SPC-5 version compatibility */ in ata_scsiop_inq_std()
1873 if (args->dev->flags & ATA_DFLAG_CDL) in ata_scsiop_inq_std()
1874 hdr[2] = 0xd; /* claim SPC-6 version compatibility */ in ata_scsiop_inq_std()
1878 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16); in ata_scsiop_inq_std()
1881 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV + 2, 4); in ata_scsiop_inq_std()
1883 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4); in ata_scsiop_inq_std()
1888 if (ata_id_zoned_cap(args->id) || args->dev->class == ATA_DEV_ZAC) in ata_scsiop_inq_std()
1897 * ata_scsiop_inq_00 - Simulate INQUIRY VPD page 0, list of pages
1923 !(args->dev->flags & ATA_DFLAG_ZAC)) in ata_scsiop_inq_00()
1933 * ata_scsiop_inq_80 - Simulate INQUIRY VPD page 80, device serial number
1952 ata_id_string(args->id, (unsigned char *) &rbuf[4], in ata_scsiop_inq_80()
1958 * ata_scsiop_inq_83 - Simulate INQUIRY VPD page 83, device identity
1963 * - vendor specific ASCII containing the ATA serial number
1964 * - SAT defined "t10 vendor id based" containing ASCII vendor
1982 ata_id_string(args->id, (unsigned char *) rbuf + num, in ata_scsiop_inq_83()
1994 ata_id_string(args->id, (unsigned char *) rbuf + num, ATA_ID_PROD, in ata_scsiop_inq_83()
1997 ata_id_string(args->id, (unsigned char *) rbuf + num, ATA_ID_SERNO, in ata_scsiop_inq_83()
2001 if (ata_id_has_wwn(args->id)) { in ata_scsiop_inq_83()
2008 ata_id_string(args->id, (unsigned char *) rbuf + num, in ata_scsiop_inq_83()
2012 rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */ in ata_scsiop_inq_83()
2017 * ata_scsiop_inq_89 - Simulate INQUIRY VPD page 89, ATA info
2021 * Yields SAT-specified ATA VPD page.
2047 memcpy(&rbuf[60], &args->id[0], 512); in ata_scsiop_inq_89()
2053 struct ata_device *dev = args->dev; in ata_scsiop_inq_b0()
2066 min_io_sectors = 1 << ata_id_log2_per_physical_sector(args->id); in ata_scsiop_inq_b0()
2075 * that we support some form of unmap - in thise case via WRITE SAME in ata_scsiop_inq_b0()
2078 if (ata_id_has_trim(args->id)) { in ata_scsiop_inq_b0()
2081 if (dev->horkage & ATA_HORKAGE_MAX_TRIM_128M) in ata_scsiop_inq_b0()
2082 max_blocks = 128 << (20 - SECTOR_SHIFT); in ata_scsiop_inq_b0()
2093 int form_factor = ata_id_form_factor(args->id); in ata_scsiop_inq_b1()
2094 int media_rotation_rate = ata_id_rotation_rate(args->id); in ata_scsiop_inq_b1()
2095 u8 zoned = ata_id_zoned_cap(args->id); in ata_scsiop_inq_b1()
2110 /* SCSI Thin Provisioning VPD page: SBC-3 rev 22 or later */ in ata_scsiop_inq_b2()
2121 * zbc-r05 SCSI Zoned Block device characteristics VPD page in ata_scsiop_inq_b6()
2127 * URSWRZ bit is only meaningful for host-managed ZAC drives in ata_scsiop_inq_b6()
2129 if (args->dev->zac_zoned_cap & 1) in ata_scsiop_inq_b6()
2131 put_unaligned_be32(args->dev->zac_zones_optimal_open, &rbuf[8]); in ata_scsiop_inq_b6()
2132 put_unaligned_be32(args->dev->zac_zones_optimal_nonseq, &rbuf[12]); in ata_scsiop_inq_b6()
2133 put_unaligned_be32(args->dev->zac_zones_max_open, &rbuf[16]); in ata_scsiop_inq_b6()
2140 struct ata_cpr_log *cpr_log = args->dev->cpr_log; in ata_scsiop_inq_b9()
2144 /* SCSI Concurrent Positioning Ranges VPD page: SBC-5 rev 1 or later */ in ata_scsiop_inq_b9()
2146 put_unaligned_be16(64 + (int)cpr_log->nr_cpr * 32 - 4, &rbuf[2]); in ata_scsiop_inq_b9()
2148 for (i = 0; i < cpr_log->nr_cpr; i++, desc += 32) { in ata_scsiop_inq_b9()
2149 desc[0] = cpr_log->cpr[i].num; in ata_scsiop_inq_b9()
2150 desc[1] = cpr_log->cpr[i].num_storage_elements; in ata_scsiop_inq_b9()
2151 put_unaligned_be64(cpr_log->cpr[i].start_lba, &desc[8]); in ata_scsiop_inq_b9()
2152 put_unaligned_be64(cpr_log->cpr[i].num_lbas, &desc[16]); in ata_scsiop_inq_b9()
2159 * modecpy - Prepare response for MODE SENSE
2175 memset(dest + 2, 0, n - 2); in modecpy()
2182 * ata_msense_caching - Simulate MODE SENSE caching info page
2207 * Simulate MODE SENSE control mode page, sub-page 0.
2218 bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); in ata_msense_control_spg0()
2229 * using the t2cdlunits 0xa (10ms). Since the SCSI duration limits are 2-bytes
2240 * Simulate MODE SENSE control mode page, sub-pages 07h and 08h
2246 u8 *b, *cdl = dev->cdl, *desc; in ata_msense_control_spgt2()
2257 put_unaligned_be16(CDL_T2_SUB_MPAGE_LEN - 4, &buf[2]); in ata_msense_control_spgt2()
2294 * Simulate MODE SENSE control mode page, sub-page f2h
2308 put_unaligned_be16(ATA_FEATURE_SUB_MPAGE_LEN - 4, &buf[2]); in ata_msense_control_ata_feature()
2310 if (dev->flags & ATA_DFLAG_CDL) in ata_msense_control_ata_feature()
2319 * ata_msense_control - Simulate MODE SENSE control mode page
2322 * @spg: sub-page code
2355 * ata_msense_rw_recovery - Simulate MODE SENSE r/w error recovery page
2372 * ata_scsiop_mode_sense - Simulate MODE SENSE 6, 10 commands
2385 struct ata_device *dev = args->dev; in ata_scsiop_mode_sense()
2386 u8 *scsicmd = args->cmd->cmnd, *p = rbuf; in ata_scsiop_mode_sense()
2394 u8 dpofua = 0, bp = 0xff; in ata_scsiop_mode_sense() local
2413 bp = 6; in ata_scsiop_mode_sense()
2426 * Supported subpages: all subpages and sub-pages 07h, 08h and f2h of in ata_scsiop_mode_sense()
2436 if (dev->flags & ATA_DFLAG_CDL && pg == CONTROL_MPAGE) in ata_scsiop_mode_sense()
2451 p += ata_msense_caching(args->id, p, page_control == 1); in ata_scsiop_mode_sense()
2455 p += ata_msense_control(args->dev, p, spg, page_control == 1); in ata_scsiop_mode_sense()
2460 p += ata_msense_caching(args->id, p, page_control == 1); in ata_scsiop_mode_sense()
2461 p += ata_msense_control(args->dev, p, spg, page_control == 1); in ata_scsiop_mode_sense()
2469 if (dev->flags & ATA_DFLAG_FUA) in ata_scsiop_mode_sense()
2473 rbuf[0] = p - rbuf - 1; in ata_scsiop_mode_sense()
2480 put_unaligned_be16(p - rbuf - 2, &rbuf[0]); in ata_scsiop_mode_sense()
2490 ata_scsi_set_invalid_field(dev, args->cmd, fp, bp); in ata_scsiop_mode_sense()
2494 ata_scsi_set_sense(dev, args->cmd, ILLEGAL_REQUEST, 0x39, 0x0); in ata_scsiop_mode_sense()
2500 * ata_scsiop_read_cap - Simulate READ CAPACITY[ 16] commands
2511 struct ata_device *dev = args->dev; in ata_scsiop_read_cap()
2512 u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */ in ata_scsiop_read_cap()
2517 sector_size = ata_id_logical_sector_size(dev->id); in ata_scsiop_read_cap()
2518 log2_per_phys = ata_id_log2_per_physical_sector(dev->id); in ata_scsiop_read_cap()
2519 lowest_aligned = ata_id_logical_sector_offset(dev->id, log2_per_phys); in ata_scsiop_read_cap()
2521 if (args->cmd->cmnd[0] == READ_CAPACITY) { in ata_scsiop_read_cap()
2525 /* sector count, 32-bit */ in ata_scsiop_read_cap()
2537 /* sector count, 64-bit */ in ata_scsiop_read_cap()
2558 if (ata_id_has_trim(args->id) && in ata_scsiop_read_cap()
2559 !(dev->horkage & ATA_HORKAGE_NOTRIM)) { in ata_scsiop_read_cap()
2562 if (ata_id_has_zero_after_trim(args->id) && in ata_scsiop_read_cap()
2563 dev->horkage & ATA_HORKAGE_ZERO_AFTER_TRIM) { in ata_scsiop_read_cap()
2568 if (ata_id_zoned_cap(args->id) || in ata_scsiop_read_cap()
2569 args->dev->class == ATA_DEV_ZAC) in ata_scsiop_read_cap()
2576 * ata_scsiop_report_luns - Simulate REPORT LUNS command
2596 * 1) Fake MMC-5 version, to indicate to the Linux scsi midlayer this is a
2614 struct scsi_cmnd *cmd = qc->scsicmd; in atapi_qc_complete()
2615 unsigned int err_mask = qc->err_mask; in atapi_qc_complete()
2618 if (unlikely(err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID)) { in atapi_qc_complete()
2620 if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) { in atapi_qc_complete()
2629 /* SCSI EH automatically locks door if sdev->locked is in atapi_qc_complete()
2632 * creates a loop - SCSI EH issues door lock which in atapi_qc_complete()
2636 * If door lock fails, always clear sdev->locked to in atapi_qc_complete()
2640 * sure qc->dev->sdev isn't NULL before dereferencing. in atapi_qc_complete()
2642 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev) in atapi_qc_complete()
2643 qc->dev->sdev->locked = 0; in atapi_qc_complete()
2645 qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; in atapi_qc_complete()
2651 if (cmd->cmnd[0] == INQUIRY && (cmd->cmnd[1] & 0x03) == 0) in atapi_qc_complete()
2653 cmd->result = SAM_STAT_GOOD; in atapi_qc_complete()
2658 * atapi_xlat - Initialize PACKET taskfile
2665 * Zero on success, non-zero on failure.
2669 struct scsi_cmnd *scmd = qc->scsicmd; in atapi_xlat()
2670 struct ata_device *dev = qc->dev; in atapi_xlat()
2671 int nodata = (scmd->sc_data_direction == DMA_NONE); in atapi_xlat()
2672 int using_pio = !nodata && (dev->flags & ATA_DFLAG_PIO); in atapi_xlat()
2675 memset(qc->cdb, 0, dev->cdb_len); in atapi_xlat()
2676 memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len); in atapi_xlat()
2678 qc->complete_fn = atapi_qc_complete; in atapi_xlat()
2680 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in atapi_xlat()
2681 if (scmd->sc_data_direction == DMA_TO_DEVICE) { in atapi_xlat()
2682 qc->tf.flags |= ATA_TFLAG_WRITE; in atapi_xlat()
2685 qc->tf.command = ATA_CMD_PACKET; in atapi_xlat()
2726 qc->tf.lbam = (nbytes & 0xFF); in atapi_xlat()
2727 qc->tf.lbah = (nbytes >> 8); in atapi_xlat()
2730 qc->tf.protocol = ATAPI_PROT_NODATA; in atapi_xlat()
2732 qc->tf.protocol = ATAPI_PROT_PIO; in atapi_xlat()
2735 qc->tf.protocol = ATAPI_PROT_DMA; in atapi_xlat()
2736 qc->tf.feature |= ATAPI_PKT_DMA; in atapi_xlat()
2738 if ((dev->flags & ATA_DFLAG_DMADIR) && in atapi_xlat()
2739 (scmd->sc_data_direction != DMA_TO_DEVICE)) in atapi_xlat()
2741 qc->tf.feature |= ATAPI_DMADIR; in atapi_xlat()
2753 * For the non-PMP case, ata_link_max_devices() returns 1 (SATA case), in ata_find_dev()
2761 int link_max_devices = ata_link_max_devices(&ap->link); in ata_find_dev()
2764 return &ap->link.device[0]; in ata_find_dev()
2767 return &ap->link.device[devno]; in ata_find_dev()
2773 * For PMP-attached devices, the device number corresponds to C in ata_find_dev()
2777 if (devno < ap->nr_pmp_links) in ata_find_dev()
2778 return &ap->pmp_link[devno].device[0]; in ata_find_dev()
2790 if (unlikely(scsidev->channel || scsidev->lun)) in __ata_scsi_find_dev()
2792 devno = scsidev->id; in __ata_scsi_find_dev()
2794 if (unlikely(scsidev->id || scsidev->lun)) in __ata_scsi_find_dev()
2796 devno = scsidev->channel; in __ata_scsi_find_dev()
2803 * ata_scsi_find_dev - lookup ata_device from scsi_cmnd
2830 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
2831 * @byte1: Byte 1 from pass-thru CDB.
2840 case 3: /* Non-data */ in ata_scsi_map_proto()
2844 case 10: /* UDMA Data-in */ in ata_scsi_map_proto()
2845 case 11: /* UDMA Data-Out */ in ata_scsi_map_proto()
2848 case 4: /* PIO Data-in */ in ata_scsi_map_proto()
2849 case 5: /* PIO Data-out */ in ata_scsi_map_proto()
2869 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2872 * Handles either 12, 16, or 32-byte versions of the CDB.
2875 * Zero on success, non-zero on failure.
2879 struct ata_taskfile *tf = &(qc->tf); in ata_scsi_pass_thru()
2880 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_pass_thru()
2881 struct ata_device *dev = qc->dev; in ata_scsi_pass_thru()
2882 const u8 *cdb = scmd->cmnd; in ata_scsi_pass_thru()
2886 /* 7Fh variable length cmd means a ata pass-thru(32) */ in ata_scsi_pass_thru()
2890 tf->protocol = ata_scsi_map_proto(cdb[1 + cdb_offset]); in ata_scsi_pass_thru()
2891 if (tf->protocol == ATA_PROT_UNKNOWN) { in ata_scsi_pass_thru()
2901 if (scmd->sc_data_direction != DMA_NONE) { in ata_scsi_pass_thru()
2906 if (ata_is_ncq(tf->protocol)) in ata_scsi_pass_thru()
2907 tf->protocol = ATA_PROT_NCQ_NODATA; in ata_scsi_pass_thru()
2911 tf->flags |= ATA_TFLAG_LBA; in ata_scsi_pass_thru()
2920 * 16-byte CDB - may contain extended commands. in ata_scsi_pass_thru()
2925 tf->hob_feature = cdb[3]; in ata_scsi_pass_thru()
2926 tf->hob_nsect = cdb[5]; in ata_scsi_pass_thru()
2927 tf->hob_lbal = cdb[7]; in ata_scsi_pass_thru()
2928 tf->hob_lbam = cdb[9]; in ata_scsi_pass_thru()
2929 tf->hob_lbah = cdb[11]; in ata_scsi_pass_thru()
2930 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2932 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2937 tf->feature = cdb[4]; in ata_scsi_pass_thru()
2938 tf->nsect = cdb[6]; in ata_scsi_pass_thru()
2939 tf->lbal = cdb[8]; in ata_scsi_pass_thru()
2940 tf->lbam = cdb[10]; in ata_scsi_pass_thru()
2941 tf->lbah = cdb[12]; in ata_scsi_pass_thru()
2942 tf->device = cdb[13]; in ata_scsi_pass_thru()
2943 tf->command = cdb[14]; in ata_scsi_pass_thru()
2947 * 12-byte CDB - incapable of extended commands. in ata_scsi_pass_thru()
2949 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2951 tf->feature = cdb[3]; in ata_scsi_pass_thru()
2952 tf->nsect = cdb[4]; in ata_scsi_pass_thru()
2953 tf->lbal = cdb[5]; in ata_scsi_pass_thru()
2954 tf->lbam = cdb[6]; in ata_scsi_pass_thru()
2955 tf->lbah = cdb[7]; in ata_scsi_pass_thru()
2956 tf->device = cdb[8]; in ata_scsi_pass_thru()
2957 tf->command = cdb[9]; in ata_scsi_pass_thru()
2961 * 32-byte CDB - may contain extended command fields. in ata_scsi_pass_thru()
2966 tf->hob_feature = cdb[20]; in ata_scsi_pass_thru()
2967 tf->hob_nsect = cdb[22]; in ata_scsi_pass_thru()
2968 tf->hob_lbal = cdb[16]; in ata_scsi_pass_thru()
2969 tf->hob_lbam = cdb[15]; in ata_scsi_pass_thru()
2970 tf->hob_lbah = cdb[14]; in ata_scsi_pass_thru()
2971 tf->flags |= ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2973 tf->flags &= ~ATA_TFLAG_LBA48; in ata_scsi_pass_thru()
2975 tf->feature = cdb[21]; in ata_scsi_pass_thru()
2976 tf->nsect = cdb[23]; in ata_scsi_pass_thru()
2977 tf->lbal = cdb[19]; in ata_scsi_pass_thru()
2978 tf->lbam = cdb[18]; in ata_scsi_pass_thru()
2979 tf->lbah = cdb[17]; in ata_scsi_pass_thru()
2980 tf->device = cdb[24]; in ata_scsi_pass_thru()
2981 tf->command = cdb[25]; in ata_scsi_pass_thru()
2982 tf->auxiliary = get_unaligned_be32(&cdb[28]); in ata_scsi_pass_thru()
2987 if (ata_is_ncq(tf->protocol)) in ata_scsi_pass_thru()
2988 tf->nsect = qc->hw_tag << 3; in ata_scsi_pass_thru()
2991 tf->device = dev->devno ? in ata_scsi_pass_thru()
2992 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; in ata_scsi_pass_thru()
2994 switch (tf->command) { in ata_scsi_pass_thru()
2995 /* READ/WRITE LONG use a non-standard sect_size */ in ata_scsi_pass_thru()
3000 if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1) { in ata_scsi_pass_thru()
3004 qc->sect_size = scsi_bufflen(scmd); in ata_scsi_pass_thru()
3038 qc->sect_size = scmd->device->sector_size; in ata_scsi_pass_thru()
3043 qc->sect_size = ATA_SECT_SIZE; in ata_scsi_pass_thru()
3051 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_scsi_pass_thru()
3052 if (scmd->sc_data_direction == DMA_TO_DEVICE) in ata_scsi_pass_thru()
3053 tf->flags |= ATA_TFLAG_WRITE; in ata_scsi_pass_thru()
3055 qc->flags |= ATA_QCFLAG_RESULT_TF | ATA_QCFLAG_QUIET; in ata_scsi_pass_thru()
3066 if (tf->protocol == ATA_PROT_DMA && !ata_dma_enabled(dev)) { in ata_scsi_pass_thru()
3072 if (ata_is_ncq(tf->protocol) && !ata_ncq_enabled(dev)) { in ata_scsi_pass_thru()
3089 if (multi_count != dev->multi_count) in ata_scsi_pass_thru()
3095 * Filter SET_FEATURES - XFER MODE command -- otherwise, in ata_scsi_pass_thru()
3096 * SET_FEATURES - XFER MODE must be preceded/succeeded in ata_scsi_pass_thru()
3097 * by an update to hardware-specific registers for each in ata_scsi_pass_thru()
3098 * controller (i.e. the reason for ->set_piomode(), in ata_scsi_pass_thru()
3099 * ->set_dmamode(), and ->post_set_mode() hooks). in ata_scsi_pass_thru()
3101 if (tf->command == ATA_CMD_SET_FEATURES && in ata_scsi_pass_thru()
3102 tf->feature == SETFEATURES_XFER) { in ata_scsi_pass_thru()
3122 if (tf->command >= 0x5C && tf->command <= 0x5F && !libata_allow_tpm) { in ata_scsi_pass_thru()
3135 * ata_format_dsm_trim_descr() - SATL Write Same to DSM Trim
3141 * Rewrite the WRITE SAME descriptor to be a DSM TRIM little-endian formatted
3158 struct scsi_device *sdp = cmd->device; in ata_format_dsm_trim_descr()
3159 size_t len = sdp->sector_size; in ata_format_dsm_trim_descr()
3179 count -= 0xffff; in ata_format_dsm_trim_descr()
3189 * ata_scsi_write_same_xlat() - SATL Write Same to ATA SCT Write Same
3196 * - When set translate to DSM TRIM
3197 * - When clear translate to SCT Write Same
3201 struct ata_taskfile *tf = &qc->tf; in ata_scsi_write_same_xlat()
3202 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_write_same_xlat()
3203 struct scsi_device *sdp = scmd->device; in ata_scsi_write_same_xlat()
3204 size_t len = sdp->sector_size; in ata_scsi_write_same_xlat()
3205 struct ata_device *dev = qc->dev; in ata_scsi_write_same_xlat()
3206 const u8 *cdb = scmd->cmnd; in ata_scsi_write_same_xlat()
3212 u8 bp = 0xff; in ata_scsi_write_same_xlat() local
3227 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_write_same_xlat()
3234 (dev->horkage & ATA_HORKAGE_NOTRIM) || in ata_scsi_write_same_xlat()
3235 !ata_id_has_trim(dev->id)) { in ata_scsi_write_same_xlat()
3237 bp = 3; in ata_scsi_write_same_xlat()
3255 * For DATA SET MANAGEMENT TRIM in ACS-2 nsect (aka count) in ata_scsi_write_same_xlat()
3265 tf->protocol = ATA_PROT_NCQ; in ata_scsi_write_same_xlat()
3266 tf->command = ATA_CMD_FPDMA_SEND; in ata_scsi_write_same_xlat()
3267 tf->hob_nsect = ATA_SUBCMD_FPDMA_SEND_DSM & 0x1f; in ata_scsi_write_same_xlat()
3268 tf->nsect = qc->hw_tag << 3; in ata_scsi_write_same_xlat()
3269 tf->hob_feature = (size / 512) >> 8; in ata_scsi_write_same_xlat()
3270 tf->feature = size / 512; in ata_scsi_write_same_xlat()
3272 tf->auxiliary = 1; in ata_scsi_write_same_xlat()
3274 tf->protocol = ATA_PROT_DMA; in ata_scsi_write_same_xlat()
3275 tf->hob_feature = 0; in ata_scsi_write_same_xlat()
3276 tf->feature = ATA_DSM_TRIM; in ata_scsi_write_same_xlat()
3277 tf->hob_nsect = (size / 512) >> 8; in ata_scsi_write_same_xlat()
3278 tf->nsect = size / 512; in ata_scsi_write_same_xlat()
3279 tf->command = ATA_CMD_DSM; in ata_scsi_write_same_xlat()
3282 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | in ata_scsi_write_same_xlat()
3290 ata_scsi_set_invalid_field(dev, scmd, fp, bp); in ata_scsi_write_same_xlat()
3303 * ata_scsiop_maint_in - Simulate a subset of MAINTENANCE_IN
3314 struct ata_device *dev = args->dev; in ata_scsiop_maint_in()
3315 u8 *cdb = args->cmd->cmnd; in ata_scsiop_maint_in()
3356 if (dev->flags & ATA_DFLAG_CDL) { in ata_scsiop_maint_in()
3367 if (dev->flags & ATA_DFLAG_CDL) { in ata_scsiop_maint_in()
3378 if (ata_id_zoned_cap(dev->id) || in ata_scsiop_maint_in()
3379 dev->class == ATA_DEV_ZAC) in ata_scsiop_maint_in()
3384 if (dev->flags & ATA_DFLAG_TRUSTED) in ata_scsiop_maint_in()
3398 * ata_scsi_report_zones_complete - convert ATA output
3401 * Convert T-13 little-endian field representation into
3402 * T-10 big-endian field representation.
3407 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_report_zones_complete()
3470 struct ata_taskfile *tf = &qc->tf; in ata_scsi_zbc_in_xlat()
3471 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_zbc_in_xlat()
3472 const u8 *cdb = scmd->cmnd; in ata_scsi_zbc_in_xlat()
3473 u16 sect, fp = (u16)-1; in ata_scsi_zbc_in_xlat()
3474 u8 sa, options, bp = 0xff; in ata_scsi_zbc_in_xlat() local
3478 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_zbc_in_xlat()
3479 ata_dev_warn(qc->dev, "invalid cdb length %d\n", in ata_scsi_zbc_in_xlat()
3480 scmd->cmd_len); in ata_scsi_zbc_in_xlat()
3486 ata_dev_warn(qc->dev, "non-matching transfer count (%d/%d)\n", in ata_scsi_zbc_in_xlat()
3492 ata_dev_warn(qc->dev, "invalid service action %d\n", sa); in ata_scsi_zbc_in_xlat()
3501 ata_dev_warn(qc->dev, "invalid transfer count %d\n", n_block); in ata_scsi_zbc_in_xlat()
3507 if (ata_ncq_enabled(qc->dev) && in ata_scsi_zbc_in_xlat()
3508 ata_fpdma_zac_mgmt_in_supported(qc->dev)) { in ata_scsi_zbc_in_xlat()
3509 tf->protocol = ATA_PROT_NCQ; in ata_scsi_zbc_in_xlat()
3510 tf->command = ATA_CMD_FPDMA_RECV; in ata_scsi_zbc_in_xlat()
3511 tf->hob_nsect = ATA_SUBCMD_FPDMA_RECV_ZAC_MGMT_IN & 0x1f; in ata_scsi_zbc_in_xlat()
3512 tf->nsect = qc->hw_tag << 3; in ata_scsi_zbc_in_xlat()
3513 tf->feature = sect & 0xff; in ata_scsi_zbc_in_xlat()
3514 tf->hob_feature = (sect >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3515 tf->auxiliary = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES | (options << 8); in ata_scsi_zbc_in_xlat()
3517 tf->command = ATA_CMD_ZAC_MGMT_IN; in ata_scsi_zbc_in_xlat()
3518 tf->feature = ATA_SUBCMD_ZAC_MGMT_IN_REPORT_ZONES; in ata_scsi_zbc_in_xlat()
3519 tf->protocol = ATA_PROT_DMA; in ata_scsi_zbc_in_xlat()
3520 tf->hob_feature = options; in ata_scsi_zbc_in_xlat()
3521 tf->hob_nsect = (sect >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3522 tf->nsect = sect & 0xff; in ata_scsi_zbc_in_xlat()
3524 tf->device = ATA_LBA; in ata_scsi_zbc_in_xlat()
3525 tf->lbah = (block >> 16) & 0xff; in ata_scsi_zbc_in_xlat()
3526 tf->lbam = (block >> 8) & 0xff; in ata_scsi_zbc_in_xlat()
3527 tf->lbal = block & 0xff; in ata_scsi_zbc_in_xlat()
3528 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_zbc_in_xlat()
3529 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_zbc_in_xlat()
3530 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_zbc_in_xlat()
3532 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48; in ata_scsi_zbc_in_xlat()
3533 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_scsi_zbc_in_xlat()
3537 qc->complete_fn = ata_scsi_report_zones_complete; in ata_scsi_zbc_in_xlat()
3542 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_zbc_in_xlat()
3547 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_zbc_in_xlat()
3553 struct ata_taskfile *tf = &qc->tf; in ata_scsi_zbc_out_xlat()
3554 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_zbc_out_xlat()
3555 struct ata_device *dev = qc->dev; in ata_scsi_zbc_out_xlat()
3556 const u8 *cdb = scmd->cmnd; in ata_scsi_zbc_out_xlat()
3560 u16 fp = (u16)-1; in ata_scsi_zbc_out_xlat()
3562 if (unlikely(scmd->cmd_len < 16)) { in ata_scsi_zbc_out_xlat()
3588 } else if (block >= dev->n_sectors) { in ata_scsi_zbc_out_xlat()
3596 if (ata_ncq_enabled(qc->dev) && in ata_scsi_zbc_out_xlat()
3597 ata_fpdma_zac_mgmt_out_supported(qc->dev)) { in ata_scsi_zbc_out_xlat()
3598 tf->protocol = ATA_PROT_NCQ_NODATA; in ata_scsi_zbc_out_xlat()
3599 tf->command = ATA_CMD_NCQ_NON_DATA; in ata_scsi_zbc_out_xlat()
3600 tf->feature = ATA_SUBCMD_NCQ_NON_DATA_ZAC_MGMT_OUT; in ata_scsi_zbc_out_xlat()
3601 tf->nsect = qc->hw_tag << 3; in ata_scsi_zbc_out_xlat()
3602 tf->auxiliary = sa | ((u16)all << 8); in ata_scsi_zbc_out_xlat()
3604 tf->protocol = ATA_PROT_NODATA; in ata_scsi_zbc_out_xlat()
3605 tf->command = ATA_CMD_ZAC_MGMT_OUT; in ata_scsi_zbc_out_xlat()
3606 tf->feature = sa; in ata_scsi_zbc_out_xlat()
3607 tf->hob_feature = all; in ata_scsi_zbc_out_xlat()
3609 tf->lbah = (block >> 16) & 0xff; in ata_scsi_zbc_out_xlat()
3610 tf->lbam = (block >> 8) & 0xff; in ata_scsi_zbc_out_xlat()
3611 tf->lbal = block & 0xff; in ata_scsi_zbc_out_xlat()
3612 tf->hob_lbah = (block >> 40) & 0xff; in ata_scsi_zbc_out_xlat()
3613 tf->hob_lbam = (block >> 32) & 0xff; in ata_scsi_zbc_out_xlat()
3614 tf->hob_lbal = (block >> 24) & 0xff; in ata_scsi_zbc_out_xlat()
3615 tf->device = ATA_LBA; in ata_scsi_zbc_out_xlat()
3616 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48; in ata_scsi_zbc_out_xlat()
3621 ata_scsi_set_invalid_field(qc->dev, scmd, fp, 0xff); in ata_scsi_zbc_out_xlat()
3625 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_zbc_out_xlat()
3630 * ata_mselect_caching - Simulate MODE SELECT for caching info page
3644 struct ata_taskfile *tf = &qc->tf; in ata_mselect_caching()
3645 struct ata_device *dev = qc->dev; in ata_mselect_caching()
3655 if (len != CACHE_MPAGE_LEN - 2) { in ata_mselect_caching()
3656 *fp = min(len, CACHE_MPAGE_LEN - 2); in ata_mselect_caching()
3657 return -EINVAL; in ata_mselect_caching()
3663 * Check that read-only bits are not modified. in ata_mselect_caching()
3665 ata_msense_caching(dev->id, mpage, false); in ata_mselect_caching()
3666 for (i = 0; i < CACHE_MPAGE_LEN - 2; i++) { in ata_mselect_caching()
3671 return -EINVAL; in ata_mselect_caching()
3675 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_mselect_caching()
3676 tf->protocol = ATA_PROT_NODATA; in ata_mselect_caching()
3677 tf->nsect = 0; in ata_mselect_caching()
3678 tf->command = ATA_CMD_SET_FEATURES; in ata_mselect_caching()
3679 tf->feature = wce ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF; in ata_mselect_caching()
3684 * Simulate MODE SELECT control mode page, sub-page 0.
3689 struct ata_device *dev = qc->dev; in ata_mselect_control_spg0()
3699 if (len != CONTROL_MPAGE_LEN - 2) { in ata_mselect_control_spg0()
3700 *fp = min(len, CONTROL_MPAGE_LEN - 2); in ata_mselect_control_spg0()
3701 return -EINVAL; in ata_mselect_control_spg0()
3707 * Check that read-only bits are not modified. in ata_mselect_control_spg0()
3710 for (i = 0; i < CONTROL_MPAGE_LEN - 2; i++) { in ata_mselect_control_spg0()
3715 return -EINVAL; in ata_mselect_control_spg0()
3719 dev->flags |= ATA_DFLAG_D_SENSE; in ata_mselect_control_spg0()
3721 dev->flags &= ~ATA_DFLAG_D_SENSE; in ata_mselect_control_spg0()
3726 * Translate MODE SELECT control mode page, sub-pages f2h (ATA feature mode
3733 struct ata_device *dev = qc->dev; in ata_mselect_control_ata_feature()
3734 struct ata_taskfile *tf = &qc->tf; in ata_mselect_control_ata_feature()
3741 if (len != ATA_FEATURE_SUB_MPAGE_LEN - 4) { in ata_mselect_control_ata_feature()
3742 *fp = min(len, ATA_FEATURE_SUB_MPAGE_LEN - 4); in ata_mselect_control_ata_feature()
3743 return -EINVAL; in ata_mselect_control_ata_feature()
3751 dev->flags &= ~ATA_DFLAG_CDL_ENABLED; in ata_mselect_control_ata_feature()
3754 /* Enable CDL T2A/T2B: NCQ priority must be disabled */ in ata_mselect_control_ata_feature()
3755 if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED) { in ata_mselect_control_ata_feature()
3757 "NCQ priority must be disabled to enable CDL\n"); in ata_mselect_control_ata_feature()
3758 return -EINVAL; in ata_mselect_control_ata_feature()
3761 dev->flags |= ATA_DFLAG_CDL_ENABLED; in ata_mselect_control_ata_feature()
3765 return -EINVAL; in ata_mselect_control_ata_feature()
3768 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_mselect_control_ata_feature()
3769 tf->protocol = ATA_PROT_NODATA; in ata_mselect_control_ata_feature()
3770 tf->command = ATA_CMD_SET_FEATURES; in ata_mselect_control_ata_feature()
3771 tf->feature = SETFEATURES_CDL; in ata_mselect_control_ata_feature()
3772 tf->nsect = cdl_action; in ata_mselect_control_ata_feature()
3778 * ata_mselect_control - Simulate MODE SELECT for control page
3780 * @spg: target sub-page of the control page
3799 return -EINVAL; in ata_mselect_control()
3804 * ata_scsi_mode_select_xlat - Simulate MODE SELECT 6, 10 commands
3816 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_mode_select_xlat()
3817 const u8 *cdb = scmd->cmnd; in ata_scsi_mode_select_xlat()
3821 u16 fp = (u16)-1; in ata_scsi_mode_select_xlat()
3822 u8 bp = 0xff; in ata_scsi_mode_select_xlat() local
3828 if (scmd->cmd_len < 5) { in ata_scsi_mode_select_xlat()
3836 if (scmd->cmd_len < 9) { in ata_scsi_mode_select_xlat()
3848 bp = (cdb[1] & 0x01) ? 1 : 5; in ata_scsi_mode_select_xlat()
3853 if (!scsi_sg_count(scmd) || scsi_sglist(scmd)->length < len) in ata_scsi_mode_select_xlat()
3869 len -= hdr_len; in ata_scsi_mode_select_xlat()
3879 len -= bd_len; in ata_scsi_mode_select_xlat()
3893 len -= 4; in ata_scsi_mode_select_xlat()
3901 len -= 2; in ata_scsi_mode_select_xlat()
3905 * Supported subpages: all subpages and ATA feature sub-page f2h of in ata_scsi_mode_select_xlat()
3919 if (qc->dev->flags & ATA_DFLAG_CDL && in ata_scsi_mode_select_xlat()
3964 ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); in ata_scsi_mode_select_xlat()
3968 ata_scsi_set_invalid_parameter(qc->dev, scmd, fp); in ata_scsi_mode_select_xlat()
3973 ata_scsi_set_sense(qc->dev, scmd, ILLEGAL_REQUEST, 0x1a, 0x0); in ata_scsi_mode_select_xlat()
3977 scmd->result = SAM_STAT_GOOD; in ata_scsi_mode_select_xlat()
3993 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_security_inout_xlat()
3994 const u8 *cdb = scmd->cmnd; in ata_scsi_security_inout_xlat()
3995 struct ata_taskfile *tf = &qc->tf; in ata_scsi_security_inout_xlat()
4000 bool dma = !(qc->dev->flags & ATA_DFLAG_PIO); in ata_scsi_security_inout_xlat()
4006 ata_scsi_set_invalid_field(qc->dev, scmd, 1, 0); in ata_scsi_security_inout_xlat()
4012 ata_scsi_set_invalid_field(qc->dev, scmd, 6, 0); in ata_scsi_security_inout_xlat()
4017 ata_scsi_set_invalid_field(qc->dev, scmd, 6, 0); in ata_scsi_security_inout_xlat()
4021 /* convert to the sector-based ATA addressing */ in ata_scsi_security_inout_xlat()
4025 tf->protocol = dma ? ATA_PROT_DMA : ATA_PROT_PIO; in ata_scsi_security_inout_xlat()
4026 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR | ATA_TFLAG_LBA; in ata_scsi_security_inout_xlat()
4028 tf->flags |= ATA_TFLAG_WRITE; in ata_scsi_security_inout_xlat()
4029 tf->command = ata_scsi_trusted_op(len, send, dma); in ata_scsi_security_inout_xlat()
4030 tf->feature = secp; in ata_scsi_security_inout_xlat()
4031 tf->lbam = spsp & 0xff; in ata_scsi_security_inout_xlat()
4032 tf->lbah = spsp >> 8; in ata_scsi_security_inout_xlat()
4035 tf->nsect = len & 0xff; in ata_scsi_security_inout_xlat()
4036 tf->lbal = len >> 8; in ata_scsi_security_inout_xlat()
4039 tf->lbah = (1 << 7); in ata_scsi_security_inout_xlat()
4047 * ata_scsi_var_len_cdb_xlat - SATL variable length CDB to Handler
4054 * Zero on success, non-zero on failure
4059 struct scsi_cmnd *scmd = qc->scsicmd; in ata_scsi_var_len_cdb_xlat()
4060 const u8 *cdb = scmd->cmnd; in ata_scsi_var_len_cdb_xlat()
4064 * if service action represents a ata pass-thru(32) command, in ata_scsi_var_len_cdb_xlat()
4075 * ata_get_xlat_func - check if SCSI to ATA translation is possible
4130 if (!(dev->flags & ATA_DFLAG_TRUSTED)) in ata_get_xlat_func()
4143 struct ata_port *ap = dev->link->ap; in __ata_scsi_queuecmd()
4144 u8 scsi_op = scmd->cmnd[0]; in __ata_scsi_queuecmd()
4149 * However, this check is done without holding the ap->lock (a libata in __ata_scsi_queuecmd()
4151 * therefore we must check if EH is pending, while holding ap->lock. in __ata_scsi_queuecmd()
4153 if (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) in __ata_scsi_queuecmd()
4156 if (unlikely(!scmd->cmd_len)) in __ata_scsi_queuecmd()
4159 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in __ata_scsi_queuecmd()
4160 if (unlikely(scmd->cmd_len > dev->cdb_len)) in __ata_scsi_queuecmd()
4168 if (unlikely(len > scmd->cmd_len || in __ata_scsi_queuecmd()
4169 len > dev->cdb_len || in __ata_scsi_queuecmd()
4170 scmd->cmd_len > ATAPI_CDB_LEN)) in __ata_scsi_queuecmd()
4176 if (unlikely(scmd->cmd_len > 16)) in __ata_scsi_queuecmd()
4190 scmd->result = DID_ERROR << 16; in __ata_scsi_queuecmd()
4196 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
4218 struct scsi_device *scsidev = cmd->device; in ata_scsi_queuecmd()
4224 spin_lock_irqsave(ap->lock, irq_flags); in ata_scsi_queuecmd()
4230 cmd->result = (DID_BAD_TARGET << 16); in ata_scsi_queuecmd()
4234 spin_unlock_irqrestore(ap->lock, irq_flags); in ata_scsi_queuecmd()
4241 * ata_scsi_simulate - simulate SCSI command on ATA device
4255 const u8 *scsicmd = cmd->cmnd; in ata_scsi_simulate()
4259 args.id = dev->id; in ata_scsi_simulate()
4291 if (dev->flags & ATA_DFLAG_ZAC) in ata_scsi_simulate()
4297 if (dev->cpr_log) in ata_scsi_simulate()
4332 /* if we reach this, then writeback caching is disabled, in ata_scsi_simulate()
4333 * turning this into a no-op. in ata_scsi_simulate()
4339 /* no-op's, complete with success */ in ata_scsi_simulate()
4373 for (i = 0; i < host->n_ports; i++) { in ata_scsi_add_hosts()
4374 struct ata_port *ap = host->ports[i]; in ata_scsi_add_hosts()
4377 rc = -ENOMEM; in ata_scsi_add_hosts()
4382 shost->eh_noresume = 1; in ata_scsi_add_hosts()
4383 *(struct ata_port **)&shost->hostdata[0] = ap; in ata_scsi_add_hosts()
4384 ap->scsi_host = shost; in ata_scsi_add_hosts()
4386 shost->transportt = ata_scsi_transport_template; in ata_scsi_add_hosts()
4387 shost->unique_id = ap->print_id; in ata_scsi_add_hosts()
4388 shost->max_id = 16; in ata_scsi_add_hosts()
4389 shost->max_lun = 1; in ata_scsi_add_hosts()
4390 shost->max_channel = 1; in ata_scsi_add_hosts()
4391 shost->max_cmd_len = 32; in ata_scsi_add_hosts()
4393 /* Schedule policy is determined by ->qc_defer() in ata_scsi_add_hosts()
4398 shost->max_host_blocked = 1; in ata_scsi_add_hosts()
4400 rc = scsi_add_host_with_dma(shost, &ap->tdev, ap->host->dev); in ata_scsi_add_hosts()
4408 while (--i >= 0) { in ata_scsi_add_hosts()
4409 struct Scsi_Host *shost = host->ports[i]->scsi_host; in ata_scsi_add_hosts()
4420 struct scsi_device *sdev = dev->sdev; in ata_scsi_assign_ofnode()
4421 struct device *d = ap->host->dev; in ata_scsi_assign_ofnode()
4422 struct device_node *np = d->of_node; in ata_scsi_assign_ofnode()
4432 if (val == dev->devno) { in ata_scsi_assign_ofnode()
4434 sdev->sdev_gendev.of_node = child; in ata_scsi_assign_ofnode()
4458 if (dev->sdev) in ata_scsi_scan_host()
4462 id = dev->devno; in ata_scsi_scan_host()
4464 channel = link->pmp; in ata_scsi_scan_host()
4466 sdev = __scsi_add_device(ap->scsi_host, channel, id, 0, in ata_scsi_scan_host()
4469 dev->sdev = sdev; in ata_scsi_scan_host()
4473 dev->sdev = NULL; in ata_scsi_scan_host()
4484 if (!dev->sdev) in ata_scsi_scan_host()
4506 if (--tries) { in ata_scsi_scan_host()
4515 queue_delayed_work(system_long_wq, &ap->hotplug_task, in ata_scsi_scan_host()
4520 * ata_scsi_offline_dev - offline attached SCSI device
4525 * function is called with host lock which protects dev->sdev
4536 if (dev->sdev) { in ata_scsi_offline_dev()
4537 scsi_device_set_state(dev->sdev, SDEV_OFFLINE); in ata_scsi_offline_dev()
4544 * ata_scsi_remove_dev - remove attached SCSI device
4555 struct ata_port *ap = dev->link->ap; in ata_scsi_remove_dev()
4565 mutex_lock(&ap->scsi_host->scan_mutex); in ata_scsi_remove_dev()
4566 spin_lock_irqsave(ap->lock, flags); in ata_scsi_remove_dev()
4568 /* clearing dev->sdev is protected by host lock */ in ata_scsi_remove_dev()
4569 sdev = dev->sdev; in ata_scsi_remove_dev()
4570 dev->sdev = NULL; in ata_scsi_remove_dev()
4590 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_remove_dev()
4591 mutex_unlock(&ap->scsi_host->scan_mutex); in ata_scsi_remove_dev()
4595 dev_name(&sdev->sdev_gendev)); in ata_scsi_remove_dev()
4604 struct ata_port *ap = link->ap; in ata_scsi_handle_link_detach()
4610 if (!(dev->flags & ATA_DFLAG_DETACHED)) in ata_scsi_handle_link_detach()
4613 spin_lock_irqsave(ap->lock, flags); in ata_scsi_handle_link_detach()
4614 dev->flags &= ~ATA_DFLAG_DETACHED; in ata_scsi_handle_link_detach()
4615 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_handle_link_detach()
4625 * ata_scsi_media_change_notify - send media change event
4636 if (dev->sdev) in ata_scsi_media_change_notify()
4637 sdev_evt_send_simple(dev->sdev, SDEV_EVT_MEDIA_CHANGE, in ata_scsi_media_change_notify()
4642 * ata_scsi_hotplug - SCSI part of hotplug
4659 if (ap->pflags & ATA_PFLAG_UNLOADING) in ata_scsi_hotplug()
4662 mutex_lock(&ap->scsi_scan_mutex); in ata_scsi_hotplug()
4668 ata_scsi_handle_link_detach(&ap->link); in ata_scsi_hotplug()
4669 if (ap->pmp_link) in ata_scsi_hotplug()
4671 ata_scsi_handle_link_detach(&ap->pmp_link[i]); in ata_scsi_hotplug()
4676 mutex_unlock(&ap->scsi_scan_mutex); in ata_scsi_hotplug()
4680 * ata_scsi_user_scan - indication for user-initiated bus scan
4703 return -EINVAL; in ata_scsi_user_scan()
4707 return -EINVAL; in ata_scsi_user_scan()
4711 return -EINVAL; in ata_scsi_user_scan()
4715 spin_lock_irqsave(ap->lock, flags); in ata_scsi_user_scan()
4721 struct ata_eh_info *ehi = &link->eh_info; in ata_scsi_user_scan()
4722 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_scsi_user_scan()
4723 ehi->action |= ATA_EH_RESET; in ata_scsi_user_scan()
4729 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_scsi_user_scan()
4730 ehi->probe_mask |= 1 << dev->devno; in ata_scsi_user_scan()
4731 ehi->action |= ATA_EH_RESET; in ata_scsi_user_scan()
4733 rc = -EINVAL; in ata_scsi_user_scan()
4738 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_user_scan()
4741 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_user_scan()
4747 * ata_scsi_dev_rescan - initiate scsi_rescan_device()
4765 mutex_lock(&ap->scsi_scan_mutex); in ata_scsi_dev_rescan()
4766 spin_lock_irqsave(ap->lock, flags); in ata_scsi_dev_rescan()
4770 struct scsi_device *sdev = dev->sdev; in ata_scsi_dev_rescan()
4776 if (ap->pflags & ATA_PFLAG_SUSPENDED) in ata_scsi_dev_rescan()
4784 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_dev_rescan()
4787 spin_lock_irqsave(ap->lock, flags); in ata_scsi_dev_rescan()
4795 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_dev_rescan()
4796 mutex_unlock(&ap->scsi_scan_mutex); in ata_scsi_dev_rescan()
4800 schedule_delayed_work(&ap->scsi_rescan_task, in ata_scsi_dev_rescan()