• Niklas Cassel's avatar
    ata: libata: fix NCQ autosense logic · 7390896b
    Niklas Cassel authored
    Currently, the logic if we should call ata_scsi_set_sense()
    (and set flag ATA_QCFLAG_SENSE_VALID to indicate that we have
    successfully added sense data to the struct ata_queued_cmd)
    looks like this:
    
    if (dev->class == ATA_DEV_ZAC &&
        ((qc->result_tf.status & ATA_SENSE) || qc->result_tf.auxiliary))
    
    The problem with this is that a drive can support the NCQ command
    error log without supporting NCQ autosense.
    
    On such a drive, if the failing command has sense data, the status
    field in the NCQ command error log will have the ATA_SENSE bit set.
    
    It is just that this sense data is not included in the NCQ command
    error log when NCQ autosense is not supported. Instead the sense
    data has to be fetched using the REQUEST SENSE DATA EXT command.
    
    Therefore, we should only add the sense data if the drive supports
    NCQ autosense AND the ATA_SENSE bit is set in the status field.
    
    Fix this, and at the same time, remove the duplicated ATA_DEV_ZAC
    check. The struct ata_taskfile supplied to ata_eh_read_log_10h()
    is memset:ed before calling the function, so simply checking if
    qc->result_tf.auxiliary is set is sufficient to tell us that the
    log actually contained sense data.
    
    Fixes: d238ffd5 ("libata: do not attempt to retrieve sense code twice")
    Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
    Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
    7390896b
libata-sata.c 37.4 KB