Skip to content

Commit a1524f2

Browse files
hreineckehtejun
authored andcommitted
libata-eh: Set 'information' field for autosense
If NCQ autosense or the sense data reporting feature is enabled the LBA of the offending command should be stored in the sense data 'information' field. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent fe7173c commit a1524f2

6 files changed

Lines changed: 53 additions & 3 deletions

File tree

‎drivers/ata/libata-core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,11 @@ static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev)
691691
* RETURNS:
692692
* Block address read from @tf.
693693
*/
694-
u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
694+
u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev)
695695
{
696696
u64 block = 0;
697697

698-
if (tf->flags & ATA_TFLAG_LBA) {
698+
if (!dev || tf->flags & ATA_TFLAG_LBA) {
699699
if (tf->flags & ATA_TFLAG_LBA48) {
700700
block |= (u64)tf->hob_lbah << 40;
701701
block |= (u64)tf->hob_lbam << 32;

‎drivers/ata/libata-eh.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,7 @@ void ata_eh_analyze_ncq_error(struct ata_link *link)
18521852
ata_dev_dbg(dev, "NCQ Autosense %02x/%02x/%02x\n",
18531853
sense_key, asc, ascq);
18541854
ata_scsi_set_sense(qc->scsicmd, sense_key, asc, ascq);
1855+
ata_scsi_set_sense_information(qc->scsicmd, &qc->result_tf);
18551856
qc->flags |= ATA_QCFLAG_SENSE_VALID;
18561857
}
18571858

@@ -1894,6 +1895,8 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
18941895
tmp = ata_eh_request_sense(qc, qc->scsicmd);
18951896
if (tmp)
18961897
qc->err_mask |= tmp;
1898+
else
1899+
ata_scsi_set_sense_information(qc->scsicmd, tf);
18971900
} else {
18981901
ata_dev_warn(qc->dev, "sense data available but port frozen\n");
18991902
}

‎drivers/ata/libata-scsi.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
280280
scsi_build_sense_buffer(0, cmd->sense_buffer, sk, asc, ascq);
281281
}
282282

283+
void ata_scsi_set_sense_information(struct scsi_cmnd *cmd,
284+
const struct ata_taskfile *tf)
285+
{
286+
u64 information;
287+
288+
if (!cmd)
289+
return;
290+
291+
information = ata_tf_read_block(tf, NULL);
292+
scsi_set_sense_information(cmd->sense_buffer, information);
293+
}
294+
283295
static ssize_t
284296
ata_scsi_em_message_store(struct device *dev, struct device_attribute *attr,
285297
const char *buf, size_t count)

‎drivers/ata/libata.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
6767
extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
6868
u64 block, u32 n_block, unsigned int tf_flags,
6969
unsigned int tag);
70-
extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev);
70+
extern u64 ata_tf_read_block(const struct ata_taskfile *tf,
71+
struct ata_device *dev);
7172
extern unsigned ata_exec_internal(struct ata_device *dev,
7273
struct ata_taskfile *tf, const u8 *cdb,
7374
int dma_dir, void *buf, unsigned int buflen,
@@ -138,6 +139,8 @@ extern int ata_scsi_add_hosts(struct ata_host *host,
138139
extern void ata_scsi_scan_host(struct ata_port *ap, int sync);
139140
extern int ata_scsi_offline_dev(struct ata_device *dev);
140141
extern void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq);
142+
extern void ata_scsi_set_sense_information(struct scsi_cmnd *cmd,
143+
const struct ata_taskfile *tf);
141144
extern void ata_scsi_media_change_notify(struct ata_device *dev);
142145
extern void ata_scsi_hotplug(struct work_struct *work);
143146
extern void ata_schedule_scsi_eh(struct Scsi_Host *shost);

‎drivers/scsi/scsi_error.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/blkdev.h>
2727
#include <linux/delay.h>
2828
#include <linux/jiffies.h>
29+
#include <asm/unaligned.h>
2930

3031
#include <scsi/scsi.h>
3132
#include <scsi/scsi_cmnd.h>
@@ -2586,3 +2587,33 @@ void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq)
25862587
}
25872588
}
25882589
EXPORT_SYMBOL(scsi_build_sense_buffer);
2590+
2591+
/**
2592+
* scsi_set_sense_information - set the information field in a
2593+
* formatted sense data buffer
2594+
* @buf: Where to build sense data
2595+
* @info: 64-bit information value to be set
2596+
*
2597+
**/
2598+
void scsi_set_sense_information(u8 *buf, u64 info)
2599+
{
2600+
if ((buf[0] & 0x7f) == 0x72) {
2601+
u8 *ucp, len;
2602+
2603+
len = buf[7];
2604+
ucp = (char *)scsi_sense_desc_find(buf, len + 8, 0);
2605+
if (!ucp) {
2606+
buf[7] = len + 0xa;
2607+
ucp = buf + 8 + len;
2608+
}
2609+
ucp[0] = 0;
2610+
ucp[1] = 0xa;
2611+
ucp[2] = 0x80; /* Valid bit */
2612+
ucp[3] = 0;
2613+
put_unaligned_be64(info, &ucp[4]);
2614+
} else if ((buf[0] & 0x7f) == 0x70) {
2615+
buf[0] |= 0x80;
2616+
put_unaligned_be64(info, &buf[3]);
2617+
}
2618+
}
2619+
EXPORT_SYMBOL(scsi_set_sense_information);

‎include/scsi/scsi_eh.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len,
5959
u64 * info_out);
6060

6161
extern void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq);
62+
extern void scsi_set_sense_information(u8 *buf, u64 info);
6263

6364
extern int scsi_ioctl_reset(struct scsi_device *, int __user *);
6465

0 commit comments

Comments
 (0)