Gerd Hoffmann wrote:
When binding AHCI controller to virtual machine, the attached ATA device cannot be recognized for the following reason: The first Identify PACKET CMD will be failed without dobut which will lead PORT_IRQ_TF_ERR be set in PxIS due to ERR bit set to 1 in D2H Register FIS(PxTFD.STS.ERR=1). In this case, the first CMD will be timeout for seabios only polling PORT_IRQ_D2H_REG_FIS & PORT_IRQ_PIOS_FIS before triggering error handling which leads AHCI controller is an error state, then the second IDENTIFY CMD cannot be issued by AHCI controller, no ATA device will be detected.
In AHCI spec HBA Port State Machine section(22.214.171.124 and 126.96.36.199), we can see this sequence: RegFIS:Entry --> ERR:FatalTaskfile (PxTFD.STS.ERR=1) --> ERR:WaitForClear, no entry for PORT_IRQ_D2H_REG_FIS/PORT_IRQ_PIOS_FIS to be set at this time. May be we can also add PORT_IRQ_TF_ERR bit check when polling command completion status?
Patch looks reasonable. I'm wondering how to reproduce the bug? When booting guests in qemu using the q35 machine (with built-in ahci controller) seabios detects everything just fine in my testing.
Thank you for your reply. My opinion, From SATA Protocol Analyzer, when ATA device received an ATAPI cmd, AHCI controller will received an D2H Register FIS with ERR bit set to 1. Form AHCI spec，I have not yet found any evidences for HW to set the PxIS（bit0/1）in this case while seabios only polling these bits. Zhaoxin AHCI controller can be used to reproduce this issue, I think its design conforms to the AHCI spec specification.