Skip to content

Commit fe7173c

Browse files
hreineckehtejun
authored andcommitted
libata: Implement support for sense data reporting
ACS-4 defines a sense data reporting feature set. This patch implements support for it. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 42b966f commit fe7173c

3 files changed

Lines changed: 120 additions & 4 deletions

File tree

‎drivers/ata/libata-core.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,24 @@ static int ata_dev_config_ncq(struct ata_device *dev,
21442144
return 0;
21452145
}
21462146

2147+
static void ata_dev_config_sense_reporting(struct ata_device *dev)
2148+
{
2149+
unsigned int err_mask;
2150+
2151+
if (!ata_id_has_sense_reporting(dev->id))
2152+
return;
2153+
2154+
if (ata_id_sense_reporting_enabled(dev->id))
2155+
return;
2156+
2157+
err_mask = ata_dev_set_feature(dev, SETFEATURE_SENSE_DATA, 0x1);
2158+
if (err_mask) {
2159+
ata_dev_dbg(dev,
2160+
"failed to enable Sense Data Reporting, Emask 0x%x\n",
2161+
err_mask);
2162+
}
2163+
}
2164+
21472165
/**
21482166
* ata_dev_configure - Configure the specified ATA/ATAPI device
21492167
* @dev: Target device to configure
@@ -2366,7 +2384,7 @@ int ata_dev_configure(struct ata_device *dev)
23662384
dev->devslp_timing[i] = sata_setting[j];
23672385
}
23682386
}
2369-
2387+
ata_dev_config_sense_reporting(dev);
23702388
dev->cdb_len = 16;
23712389
}
23722390

‎drivers/ata/libata-eh.c‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,70 @@ unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
16171617
return err_mask;
16181618
}
16191619

1620+
/**
1621+
* ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
1622+
* @dev: device to perform REQUEST_SENSE_SENSE_DATA_EXT to
1623+
* @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
1624+
* @dfl_sense_key: default sense key to use
1625+
*
1626+
* Perform REQUEST_SENSE_DATA_EXT after the device reported CHECK
1627+
* SENSE. This function is EH helper.
1628+
*
1629+
* LOCKING:
1630+
* Kernel thread context (may sleep).
1631+
*
1632+
* RETURNS:
1633+
* encoded sense data on success, 0 on failure or if sense data
1634+
* is not available.
1635+
*/
1636+
static u32 ata_eh_request_sense(struct ata_queued_cmd *qc,
1637+
struct scsi_cmnd *cmd)
1638+
{
1639+
struct ata_device *dev = qc->dev;
1640+
struct ata_taskfile tf;
1641+
unsigned int err_mask;
1642+
1643+
if (!cmd)
1644+
return 0;
1645+
1646+
DPRINTK("ATA request sense\n");
1647+
ata_dev_warn(dev, "request sense\n");
1648+
if (!ata_id_sense_reporting_enabled(dev->id)) {
1649+
ata_dev_warn(qc->dev, "sense data reporting disabled\n");
1650+
return 0;
1651+
}
1652+
ata_tf_init(dev, &tf);
1653+
1654+
tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1655+
tf.flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
1656+
tf.command = ATA_CMD_REQ_SENSE_DATA;
1657+
tf.protocol = ATA_PROT_NODATA;
1658+
1659+
err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
1660+
/*
1661+
* ACS-4 states:
1662+
* The device may set the SENSE DATA AVAILABLE bit to one in the
1663+
* STATUS field and clear the ERROR bit to zero in the STATUS field
1664+
* to indicate that the command returned completion without an error
1665+
* and the sense data described in table 306 is available.
1666+
*
1667+
* IOW the 'ATA_SENSE' bit might not be set even though valid
1668+
* sense data is available.
1669+
* So check for both.
1670+
*/
1671+
if ((tf.command & ATA_SENSE) ||
1672+
tf.lbah != 0 || tf.lbam != 0 || tf.lbal != 0) {
1673+
ata_scsi_set_sense(cmd, tf.lbah, tf.lbam, tf.lbal);
1674+
qc->flags |= ATA_QCFLAG_SENSE_VALID;
1675+
ata_dev_warn(dev, "sense data %02x/%02x/%02x\n",
1676+
tf.lbah, tf.lbam, tf.lbal);
1677+
} else {
1678+
ata_dev_warn(dev, "request sense failed stat %02x emask %x\n",
1679+
tf.command, err_mask);
1680+
}
1681+
return err_mask;
1682+
}
1683+
16201684
/**
16211685
* atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
16221686
* @dev: device to perform REQUEST_SENSE to
@@ -1820,7 +1884,22 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
18201884
return ATA_EH_RESET;
18211885
}
18221886

1823-
/* Set by NCQ autosense */
1887+
/*
1888+
* Sense data reporting does not work if the
1889+
* device fault bit is set.
1890+
*/
1891+
if ((stat & ATA_SENSE) && !(stat & ATA_DF) &&
1892+
!(qc->flags & ATA_QCFLAG_SENSE_VALID)) {
1893+
if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) {
1894+
tmp = ata_eh_request_sense(qc, qc->scsicmd);
1895+
if (tmp)
1896+
qc->err_mask |= tmp;
1897+
} else {
1898+
ata_dev_warn(qc->dev, "sense data available but port frozen\n");
1899+
}
1900+
}
1901+
1902+
/* Set by NCQ autosense or request sense above */
18241903
if (qc->flags & ATA_QCFLAG_SENSE_VALID)
18251904
return 0;
18261905

@@ -2566,14 +2645,15 @@ static void ata_eh_link_report(struct ata_link *link)
25662645

25672646
#ifdef CONFIG_ATA_VERBOSE_ERROR
25682647
if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ |
2569-
ATA_ERR)) {
2648+
ATA_SENSE | ATA_ERR)) {
25702649
if (res->command & ATA_BUSY)
25712650
ata_dev_err(qc->dev, "status: { Busy }\n");
25722651
else
2573-
ata_dev_err(qc->dev, "status: { %s%s%s%s}\n",
2652+
ata_dev_err(qc->dev, "status: { %s%s%s%s%s}\n",
25742653
res->command & ATA_DRDY ? "DRDY " : "",
25752654
res->command & ATA_DF ? "DF " : "",
25762655
res->command & ATA_DRQ ? "DRQ " : "",
2656+
res->command & ATA_SENSE ? "SENSE " : "",
25772657
res->command & ATA_ERR ? "ERR " : "");
25782658
}
25792659

‎include/linux/ata.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ enum {
9494
ATA_ID_SECTOR_SIZE = 106,
9595
ATA_ID_WWN = 108,
9696
ATA_ID_LOGICAL_SECTOR_SIZE = 117, /* and 118 */
97+
ATA_ID_COMMAND_SET_3 = 119,
98+
ATA_ID_COMMAND_SET_4 = 120,
9799
ATA_ID_LAST_LUN = 126,
98100
ATA_ID_DLF = 128,
99101
ATA_ID_CSFO = 129,
@@ -382,6 +384,8 @@ enum {
382384
SATA_SSP = 0x06, /* Software Settings Preservation */
383385
SATA_DEVSLP = 0x09, /* Device Sleep */
384386

387+
SETFEATURE_SENSE_DATA = 0xC3, /* Sense Data Reporting feature */
388+
385389
/* feature values for SET_MAX */
386390
ATA_SET_MAX_ADDR = 0x00,
387391
ATA_SET_MAX_PASSWD = 0x01,
@@ -705,6 +709,20 @@ static inline bool ata_id_has_read_log_dma_ext(const u16 *id)
705709
return id[ATA_ID_COMMAND_SET_3] & (1 << 3);
706710
}
707711

712+
static inline bool ata_id_has_sense_reporting(const u16 *id)
713+
{
714+
if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15)))
715+
return false;
716+
return id[ATA_ID_COMMAND_SET_3] & (1 << 6);
717+
}
718+
719+
static inline bool ata_id_sense_reporting_enabled(const u16 *id)
720+
{
721+
if (!(id[ATA_ID_CFS_ENABLE_2] & (1 << 15)))
722+
return false;
723+
return id[ATA_ID_COMMAND_SET_4] & (1 << 6);
724+
}
725+
708726
/**
709727
* ata_id_major_version - get ATA level of drive
710728
* @id: Identify data

0 commit comments

Comments
 (0)