Upload
kerry-page
View
214
Download
2
Embed Size (px)
Citation preview
AHCI: ATAport Miniport Example
OutlineOutline
AHCI FeaturesGoals
Basics
AHCI ATA Miniport Design PhilosophyMemory Structures and Resources
Enumeration
IO Creation
Error Handling
Role of AHCIRole of AHCI
Industry transitioning to SATA, AHCI provides a standard interface and is facilitating adoption
Implementing AHCI interface in a controller doesn’t prevent the controller from implementing 8038i/PCIIDE
AHCI follows advancements in PCIPCI 2.3, power management, MSI, etc.
AHCI comprehends SATA features
Feature BasicsFeature Basics
8038i/PCIIDE (PATA)
Controller ResourcesIO Port
2 channel per controller
2 devices per channel
Interrupt CapabilitiesInterrupt per channel
No hot plug
No power management
No notification
IO CapabilitiesPIO interrupt per DRQ
Software queuing
Tagged Command Queuing
AHCI 1.0 (SATA)
Controller ResourcesMemory Mapped
32 channels per controller
15 devices per channel
Interrupt CapabilitiesSelective interrupt hierarchy
Hot plug supported
Link power management
Asynchronous notification
IO CapabilitiesPIO through DMA
Hardware queuing
Native Command Queueing
AHCI Design: Memory Structures and ResourcesAHCI Design: Memory Structures and Resources
Controller Extension ABAR
AdapterControl w/ IdeStart receives ABAR as part of ControllerConfiguration->ControllerResources
Channel ExtensionOne per channel
Uncached ExtensionOne per channelPage alignedContains Command List and FIS Receive Buffer
IRB ExtensionContains Command TableFirst IRB’s Extension is Page aligned, all other IRB Extensions are IRB Extension size aligned
AHCI Design: SynchronizationAHCI Design: Synchronization
Per channel, only one channel entry point will be running at a time
AdapterControlThe port driver ensures that there is no outstanding I/O on the adapter before invoking this routine.
Interrupts are enabled just before the HwControl w/ IdeStart is called. If Interrupts are enabled, the Interrupt routine may be called after this.
AHCI Design: IRB Return ValuesAHCI Design: IRB Return Values
If the IRB status is not IRB_STATUS_DEVICE_ERROR, the port assumes that the miniport has done the error translation already and so the Error register is ignored.IRB_STATUS_PENDING is used internally to signal ‘waiting on interrupt’. The miniport should not complete IRB if it is still waiting on an interrupt. IRB_STATUS_DATALENGTH_MISMATCH
Return the actual byteCountIrb->DataTransferLength -= GetBytesLeft(ChannelExtension, Irb);Don’t set this on RequestSense IRBs, as the amount of data expected is unknown
AHCI Design: IRB Return Values (con’t)AHCI Design: IRB Return Values (con’t)
IRB_STATUS_BUSY should be used when device is busy and the miniport wants the ATAport driver to retry the command.
Use BUSY with AtaPortCompleteAllActiveRequests
Always pause ATAport queues with AtaPortDeviceBusy() when returning BUSY
IRB_STATUS_SELECTION_TIMEOUT should be used when the controller is not capable of handling IO. The ATAport driver will not retry the command.
IRB_STATUS_BUS_RESET
IRB_STATUS_INVALID_REQUEST
IRB_STATUS_SUCCESS
AHCI Design: EnumerationAHCI Design: Enumeration
Port sends ID_DEVICE, then ID_PACKET_DEVICE (or vice versa)
IRBs completed with IRB_STATUS_BUSY will be retried
All other IRB status values will be interpreted as enumeration failure
Status 0xFF, 0xFE will be interpreted as no device
Enabling an AHCI channel (CMD.ST) may take milliseconds. Pausing ATAport queues can be an effective StallTimer if attempts to move the controller to P:Running are made from StartIo.
AHCI Design: Creating IOAHCI Design: Creating IO
Miniport’s create IRBs only in uncommon circumstances
Request SenseAtaPortBuildRequestSenseIrb (ChannelExtension, root IRB)
Request Sense IrbExtension is the same as the Request Sense root IRB’s IrbExtension
Don’t use SGList, use IRB Data Buffer
Read Log ExtUsed to determine NCQ failures
Set FeaturesHwInitialize
AtaPortCompleteAllActiveRequests do not complete miniport created IRBs
… however it will complete Request Sense root IRBs
AHCI Design: CrashdumpAHCI Design: Crashdump
Must be handled at any time
The miniport driver is reloaded
Only kernel, ATAport and miniport are running, therefore initialization is very fast
The port driver will only enable the channel that contains the device with the page file
The controller is very likely enabled (AE = 1) and handling IO, in which case it must be stopped and restarted
AHCI Design: MiscellaneousAHCI Design: Miscellaneous
HotplugInterrupt routine should use AtaPortDeviceArrived and AtaPortDeviceRemoved for hotplug events
Causes ATAport to invalidate device relations appropriately
Reset/Error HandlingAtaPortCompleteAllActiveRequests is very handy. Complete everything with BUSY, restore stability, and let the ATAport driver handle retrying commands
Additional ResourcesAdditional Resources
ATA Miniport InterfaceDocumented in the WDK
List of SpecificationsATA: http://www.t13.org
SATA: http://www.serialata.org
SCSI: http://www.t10.org
AHCI: http://developer.intel.com/technology/serialata/ahci.htm
WhitePapersATA Miniport Design Guide
MSI Guidance http://download.microsoft.com/download/5/7/7/577a5684-8a83-43ae-9272-ff260a9c20e2/MSI.doc
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.