• Niklas Cassel's avatar
    ata: libahci: read correct status and error field for NCQ commands · 4ba09d20
    Niklas Cassel authored
    
    
    Currently, for PIO commands, ahci_qc_fill_rtf() reads the status and
    error fields from the PIO Setup FIS area of the Received FIS Structure.
    
    For any non-PIO command, ahci_qc_fill_rtf() currently reads the status
    and error fields from the D2H Register FIS area of the Received FIS
    Structure. This is simply not correct.
    
    According to the SATA 3.5a specification:
    11.10 DMA DATA-IN command protocol and 11.11 DMA DATA-OUT command
    protocol: READ DMA and WRITE DMA (non-NCQ commands) will end with
    the Send_status state, which transmits a Register D2H FIS.
    
    Likewise, in:
    11.15 FPDMA QUEUED command protocol: READ FPDMA QUEUED and WRITE FPDMA
    QUEUED (NCQ commands) will end with the SendStatus state, which
    transmits a Set Device Bits FIS.
    
    So, for NCQ commands, there is never a D2H Register FIS sent.
    Reading the status and error fields from the D2H Register FIS area
    for a NCQ command, will result in us returning the status and error
    values for the last non-NCQ command, which is incorrect.
    
    Update ahci_qc_fill_rtf() to read the status and error fields from
    the correct area in the Received FIS Structure for NCQ commands.
    
    Once reason why this has not been detected before, could be because,
    in case of an NCQ error, ata_eh_analyze_ncq_error() will overwrite
    the (incorrect) status and error values set by ahci_qc_fill_rtf().
    
    However, even successful NCQ commands can have bits set in the status
    field (e.g. the sense data available bit), so it is mandatory to read
    the status from the correct area also for NCQ commands.
    Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
    Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
    4ba09d20
libahci.c 69.5 KB