Skip to content

Commit 5b01e4b

Browse files
hreineckehtejun
authored andcommitted
libata: Implement NCQ autosense
Some newer devices support NCQ autosense (cf ACS-4), so we should be using it to retrieve the sense code and speed up recovery. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent d991c87 commit 5b01e4b

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎drivers/ata/libata-eh.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,8 @@ static int ata_eh_read_log_10h(struct ata_device *dev,
16001600
tf->hob_lbah = buf[10];
16011601
tf->nsect = buf[12];
16021602
tf->hob_nsect = buf[13];
1603+
if (ata_id_has_ncq_autosense(dev->id))
1604+
tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
16031605

16041606
return 0;
16051607
}
@@ -1797,6 +1799,16 @@ void ata_eh_analyze_ncq_error(struct ata_link *link)
17971799
memcpy(&qc->result_tf, &tf, sizeof(tf));
17981800
qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
17991801
qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
1802+
if (qc->result_tf.auxiliary) {
1803+
char sense_key, asc, ascq;
1804+
1805+
sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
1806+
asc = (qc->result_tf.auxiliary >> 8) & 0xff;
1807+
ascq = qc->result_tf.auxiliary & 0xff;
1808+
ata_scsi_set_sense(qc->scsicmd, sense_key, asc, ascq);
1809+
qc->flags |= ATA_QCFLAG_SENSE_VALID;
1810+
}
1811+
18001812
ehc->i.err_mask &= ~AC_ERR_DEV;
18011813
}
18021814

‎drivers/ata/libata-scsi.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,11 @@ DEVICE_ATTR(unload_heads, S_IRUGO | S_IWUSR,
270270
ata_scsi_park_show, ata_scsi_park_store);
271271
EXPORT_SYMBOL_GPL(dev_attr_unload_heads);
272272

273-
static void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
273+
void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
274274
{
275+
if (!cmd)
276+
return;
277+
275278
cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
276279

277280
scsi_build_sense_buffer(0, cmd->sense_buffer, sk, asc, ascq);
@@ -1784,6 +1787,8 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17841787
if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) &&
17851788
((cdb[2] & 0x20) || need_sense))
17861789
ata_gen_passthru_sense(qc);
1790+
else if (qc->flags & ATA_QCFLAG_SENSE_VALID)
1791+
cmd->result = SAM_STAT_CHECK_CONDITION;
17871792
else if (need_sense)
17881793
ata_gen_ata_sense(qc);
17891794
else

‎drivers/ata/libata.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ extern int ata_scsi_add_hosts(struct ata_host *host,
137137
struct scsi_host_template *sht);
138138
extern void ata_scsi_scan_host(struct ata_port *ap, int sync);
139139
extern int ata_scsi_offline_dev(struct ata_device *dev);
140+
extern void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq);
140141
extern void ata_scsi_media_change_notify(struct ata_device *dev);
141142
extern void ata_scsi_hotplug(struct work_struct *work);
142143
extern void ata_schedule_scsi_eh(struct Scsi_Host *shost);

‎include/linux/ata.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ struct ata_bmdma_prd {
528528
#define ata_id_cdb_intr(id) (((id)[ATA_ID_CONFIG] & 0x60) == 0x20)
529529
#define ata_id_has_da(id) ((id)[ATA_ID_SATA_CAPABILITY_2] & (1 << 4))
530530
#define ata_id_has_devslp(id) ((id)[ATA_ID_FEATURE_SUPP] & (1 << 8))
531+
#define ata_id_has_ncq_autosense(id) \
532+
((id)[ATA_ID_FEATURE_SUPP] & (1 << 7))
531533

532534
static inline bool ata_id_has_hipm(const u16 *id)
533535
{

0 commit comments

Comments
 (0)