MdeModulePkg/AtaBus&ScsiBus: Dynamically calculate how long shall we wait for the finish of a read/write operation according to the actual transfer length

Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Elvin Li <elvin.li@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14028 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
erictian 2013-01-04 06:03:52 +00:00
parent e8a50d1b44
commit 9690325d1e
2 changed files with 90 additions and 3 deletions

View File

@ -524,7 +524,36 @@ TransferAtaDevice (
Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsWrite]; Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsWrite];
Packet->Length = EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT; Packet->Length = EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT;
Packet->Timeout = ATA_TIMEOUT; //
// |------------------------|-----------------|------------------------|-----------------|
// | ATA PIO Transfer Mode | Transfer Rate | ATA DMA Transfer Mode | Transfer Rate |
// |------------------------|-----------------|------------------------|-----------------|
// | PIO Mode 0 | 3.3Mbytes/sec | Single-word DMA Mode 0 | 2.1Mbytes/sec |
// |------------------------|-----------------|------------------------|-----------------|
// | PIO Mode 1 | 5.2Mbytes/sec | Single-word DMA Mode 1 | 4.2Mbytes/sec |
// |------------------------|-----------------|------------------------|-----------------|
// | PIO Mode 2 | 8.3Mbytes/sec | Single-word DMA Mode 2 | 8.4Mbytes/sec |
// |------------------------|-----------------|------------------------|-----------------|
// | PIO Mode 3 | 11.1Mbytes/sec | Multi-word DMA Mode 0 | 4.2Mbytes/sec |
// |------------------------|-----------------|------------------------|-----------------|
// | PIO Mode 4 | 16.6Mbytes/sec | Multi-word DMA Mode 1 | 13.3Mbytes/sec |
// |------------------------|-----------------|------------------------|-----------------|
//
// As AtaBus is used to manage ATA devices, we have to use the lowest transfer rate to
// calculate the possible maximum timeout value for each read/write operation.
//
if (AtaDevice->UdmaValid) {
//
// Calculate the maximum timeout value for DMA read/write operation.
//
Packet->Timeout = EFI_TIMER_PERIOD_SECONDS ((TransferLength * AtaDevice->BlockMedia.BlockSize) / 2100000 + 1);
} else {
//
// Calculate the maximum timeout value for PIO read/write operation
//
Packet->Timeout = EFI_TIMER_PERIOD_SECONDS ((TransferLength * AtaDevice->BlockMedia.BlockSize) / 3300000 + 1);
}
return AtaDevicePassThru (AtaDevice, TaskPacket, Event); return AtaDevicePassThru (AtaDevice, TaskPacket, Event);
} }

View File

@ -1815,7 +1815,36 @@ ScsiDiskReadSectors (
} }
ByteCount = SectorCount * BlockSize; ByteCount = SectorCount * BlockSize;
Timeout = EFI_TIMER_PERIOD_SECONDS (2); //
// |------------------------|-----------------|------------------|-----------------|
// | ATA Transfer Mode | Transfer Rate | SCSI Interface | Transfer Rate |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 0 | 3.3Mbytes/sec | SCSI-1 | 5Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 1 | 5.2Mbytes/sec | Fast SCSI | 10Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 2 | 8.3Mbytes/sec | Fast-Wide SCSI | 20Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 3 | 11.1Mbytes/sec | Ultra SCSI | 20Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 4 | 16.6Mbytes/sec | Ultra Wide SCSI | 40Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Single-word DMA Mode 0 | 2.1Mbytes/sec | Ultra2 SCSI | 40Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Single-word DMA Mode 1 | 4.2Mbytes/sec | Ultra2 Wide SCSI | 80Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Single-word DMA Mode 2 | 8.4Mbytes/sec | Ultra3 SCSI | 160Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Multi-word DMA Mode 0 | 4.2Mbytes/sec | Ultra-320 SCSI | 320Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Multi-word DMA Mode 1 | 13.3Mbytes/sec | Ultra-640 SCSI | 640Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
//
// As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, we have to use
// the lowest transfer rate to calculate the possible maximum timeout value for each operation.
// From the above table, we could know 2.1Mbytes per second is lowest one.
//
Timeout = EFI_TIMER_PERIOD_SECONDS (ByteCount / 2100000 + 1);
MaxRetry = 2; MaxRetry = 2;
for (Index = 0; Index < MaxRetry; Index++) { for (Index = 0; Index < MaxRetry; Index++) {
@ -1937,7 +1966,36 @@ ScsiDiskWriteSectors (
} }
ByteCount = SectorCount * BlockSize; ByteCount = SectorCount * BlockSize;
Timeout = EFI_TIMER_PERIOD_SECONDS (2); //
// |------------------------|-----------------|------------------|-----------------|
// | ATA Transfer Mode | Transfer Rate | SCSI Interface | Transfer Rate |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 0 | 3.3Mbytes/sec | SCSI-1 | 5Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 1 | 5.2Mbytes/sec | Fast SCSI | 10Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 2 | 8.3Mbytes/sec | Fast-Wide SCSI | 20Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 3 | 11.1Mbytes/sec | Ultra SCSI | 20Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | PIO Mode 4 | 16.6Mbytes/sec | Ultra Wide SCSI | 40Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Single-word DMA Mode 0 | 2.1Mbytes/sec | Ultra2 SCSI | 40Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Single-word DMA Mode 1 | 4.2Mbytes/sec | Ultra2 Wide SCSI | 80Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Single-word DMA Mode 2 | 8.4Mbytes/sec | Ultra3 SCSI | 160Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Multi-word DMA Mode 0 | 4.2Mbytes/sec | Ultra-320 SCSI | 320Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
// | Multi-word DMA Mode 1 | 13.3Mbytes/sec | Ultra-640 SCSI | 640Mbytes/sec |
// |------------------------|-----------------|------------------|-----------------|
//
// As ScsiDisk and ScsiBus driver are used to manage SCSI or ATAPI devices, we have to use
// the lowest transfer rate to calculate the possible maximum timeout value for each operation.
// From the above table, we could know 2.1Mbytes per second is lowest one.
//
Timeout = EFI_TIMER_PERIOD_SECONDS (ByteCount / 2100000 + 1);
MaxRetry = 2; MaxRetry = 2;
for (Index = 0; Index < MaxRetry; Index++) { for (Index = 0; Index < MaxRetry; Index++) {
if (!ScsiDiskDevice->Cdb16Byte) { if (!ScsiDiskDevice->Cdb16Byte) {