aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ata/libata-core.c20
-rw-r--r--drivers/ata/libata-eh.c86
-rw-r--r--include/linux/ata.h18
3 files changed, 120 insertions, 4 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 4c35f0822d06..aebb7e305874 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2144,6 +2144,24 @@ static int ata_dev_config_ncq(struct ata_device *dev,
2144 return 0; 2144 return 0;
2145} 2145}
2146 2146
2147static 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
2147/** 2165/**
2148 * ata_dev_configure - Configure the specified ATA/ATAPI device 2166 * ata_dev_configure - Configure the specified ATA/ATAPI device
2149 * @dev: Target device to configure 2167 * @dev: Target device to configure
@@ -2366,7 +2384,7 @@ int ata_dev_configure(struct ata_device *dev)
2366 dev->devslp_timing[i] = sata_setting[j]; 2384 dev->devslp_timing[i] = sata_setting[j];
2367 } 2385 }
2368 } 2386 }
2369 2387 ata_dev_config_sense_reporting(dev);
2370 dev->cdb_len = 16; 2388 dev->cdb_len = 16;
2371 } 2389 }
2372 2390
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index c9b19949708c..9fa81d91f6ad 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1618,6 +1618,70 @@ unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
1618} 1618}
1619 1619
1620/** 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 */
1636static 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
1684/**
1621 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE 1685 * atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
1622 * @dev: device to perform REQUEST_SENSE to 1686 * @dev: device to perform REQUEST_SENSE to
1623 * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long) 1687 * @sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
@@ -1820,7 +1884,22 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1820 return ATA_EH_RESET; 1884 return ATA_EH_RESET;
1821 } 1885 }
1822 1886
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 */
1824 if (qc->flags & ATA_QCFLAG_SENSE_VALID) 1903 if (qc->flags & ATA_QCFLAG_SENSE_VALID)
1825 return 0; 1904 return 0;
1826 1905
@@ -2566,14 +2645,15 @@ static void ata_eh_link_report(struct ata_link *link)
2566 2645
2567#ifdef CONFIG_ATA_VERBOSE_ERROR 2646#ifdef CONFIG_ATA_VERBOSE_ERROR
2568 if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | 2647 if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ |
2569 ATA_ERR)) { 2648 ATA_SENSE | ATA_ERR)) {
2570 if (res->command & ATA_BUSY) 2649 if (res->command & ATA_BUSY)
2571 ata_dev_err(qc->dev, "status: { Busy }\n"); 2650 ata_dev_err(qc->dev, "status: { Busy }\n");
2572 else 2651 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",
2574 res->command & ATA_DRDY ? "DRDY " : "", 2653 res->command & ATA_DRDY ? "DRDY " : "",
2575 res->command & ATA_DF ? "DF " : "", 2654 res->command & ATA_DF ? "DF " : "",
2576 res->command & ATA_DRQ ? "DRQ " : "", 2655 res->command & ATA_DRQ ? "DRQ " : "",
2656 res->command & ATA_SENSE ? "SENSE " : "",
2577 res->command & ATA_ERR ? "ERR " : ""); 2657 res->command & ATA_ERR ? "ERR " : "");
2578 } 2658 }
2579 2659
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 0c65526e9295..b666b773e111 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -94,6 +94,8 @@ enum {
94 ATA_ID_SECTOR_SIZE = 106, 94 ATA_ID_SECTOR_SIZE = 106,
95 ATA_ID_WWN = 108, 95 ATA_ID_WWN = 108,
96 ATA_ID_LOGICAL_SECTOR_SIZE = 117, /* and 118 */ 96 ATA_ID_LOGICAL_SECTOR_SIZE = 117, /* and 118 */
97 ATA_ID_COMMAND_SET_3 = 119,
98 ATA_ID_COMMAND_SET_4 = 120,
97 ATA_ID_LAST_LUN = 126, 99 ATA_ID_LAST_LUN = 126,
98 ATA_ID_DLF = 128, 100 ATA_ID_DLF = 128,
99 ATA_ID_CSFO = 129, 101 ATA_ID_CSFO = 129,
@@ -382,6 +384,8 @@ enum {
382 SATA_SSP = 0x06, /* Software Settings Preservation */ 384 SATA_SSP = 0x06, /* Software Settings Preservation */
383 SATA_DEVSLP = 0x09, /* Device Sleep */ 385 SATA_DEVSLP = 0x09, /* Device Sleep */
384 386
387 SETFEATURE_SENSE_DATA = 0xC3, /* Sense Data Reporting feature */
388
385 /* feature values for SET_MAX */ 389 /* feature values for SET_MAX */
386 ATA_SET_MAX_ADDR = 0x00, 390 ATA_SET_MAX_ADDR = 0x00,
387 ATA_SET_MAX_PASSWD = 0x01, 391 ATA_SET_MAX_PASSWD = 0x01,
@@ -705,6 +709,20 @@ static inline bool ata_id_has_read_log_dma_ext(const u16 *id)
705 return id[ATA_ID_COMMAND_SET_3] & (1 << 3); 709 return id[ATA_ID_COMMAND_SET_3] & (1 << 3);
706} 710}
707 711
712static 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
719static 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
708/** 726/**
709 * ata_id_major_version - get ATA level of drive 727 * ata_id_major_version - get ATA level of drive
710 * @id: Identify data 728 * @id: Identify data