@@ -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
0 commit comments