How to Write an ATAport Miniport
Outline Current ATA Environment ATAport Solution ATAport Features ATAport Model Best Known Practices
Industry Activities Many Vendor ATA drivers are Scsiport miniports Creating an inconsistent behavior around ATA command handling Emphasis on consumer RAID The introduction of SATA interconnect Requires new feature support Has a richer host controller interface Still uses ATA, which is a duplicate of a significant portion of the ATA driver infrastructure
ATAport Goals Extensibility Compatibility Flexibility Diagnosability Support innovations in the ATA industry Compatibility Accommodates existing and new hardware Flexibility Enables Vendor value add Diagnosability
ATAport Features ATA/ATAPI 7 support SATA support Command Queuing Forced Unit Access Advanced Power Management SATA support Support for greater than 2 channels/controller Support for greater than 2 devices/channel Command Queuing Channel-based queuing Device-based queuing
ATAport Features Support for Message Signal Interrupts Hotplug Provides greater flexibility and stability in interrupts Hotplug More granular Power Management control ATAport provides a flexible miniport interface for vendor value add
ATAport Model: Port Services Translation of upper OS storage requests into ATA protocol Automatic Generation of Sense Data for ATA devices Push model as opposed to a Pull model Improved IDE Request Block that more accurately maps to the underlying hardware model
ATAport Model: Port Services Asynchronous device reset management Hierarchical reset (device and channel) Asynchronous device power management Per-channel granularity Power, resets, queuing, interrupts I/O is concurrent
ATAport Model: Miniport Capabilities Negotiation of Device parameters Transfer mode Bytes/Sector Sectors/block LBA sectors/disk Removable media Decide on channel- or device-based command queuing Control the timeout on a per-request basis Request the mapping of data buffers on a per request basis Miniport can participate in the queuing policy Selection of depth, freezing,retry
ATAport Interface Illustration Default Miniport ATAport Channel 0 Channel 1 Disk Channel Interface Disk Controller Interface Port IO Pciidex Vendor Miniport Hardware CS BAR
Controller Interface ATAport Miniport Driver Entry AtaPortInitializeEx Start Controller AdapterControl w/ IdeStart AtaControllerIntitialize Enumerate Channels ControllerChannelEnabled AtaControllerChannelEnabled ChannelInitialize
Channel Interface ATAport Miniport Initialize Channel ChannelInitialize ChannelInitialize Start Channel HwControl w/ IdeStart AtaChannelControl Configure Devices AtaHwIntitialize HwIntitialize I/O HwBuildIO AtaHwBuildIO HwStartIO AtaHwStartIO HwInterrupt AtaHwInterrupt
Keep track of extensions in global variables Trick: Extensions Keep track of extensions in global variables Finding Channel Extensions !devstack 0x8245dbf8 !DevObj !DrvObj !DevExt ObjectName 8246a030 \Driver\disk 8246a0e8 disk 8245c478 \Driver\ACPI 8245ac80 0000008a 8245dbf8 \Driver\msahci 8245dcb0 ataport Channel extension is DevExt +0x84 Finding the Controller Extension 8246a030 \Driver\msahci 8246a0e8 PciIde2 8245dbf8 \Driver\pci 8245dcb0 NTPNP_PCI0012 Controller Extension is DevExt +0x88 No device objects during crashdump
Best Known Practices: CrashDump/Hybernate Creates an unused copy of the miniport at boot time Has no driver stack, runs single threaded, processes 1 IO at a time Can be identified by ChannelConfiguration.ChannelMode Cannot touch PCI config space Cannot use more than 30KB of uncached extension per channel
AtaPortStallExecution Trick: Stalling AtaPortStallExecution Spinlocks the CPU for x microseconds Should not be used for greater than 1 millisecond delays AtaPortRequestTimer Causes the port driver to trigger a callback routine after x microseconds Should be used for greater than 1 millisecond delays Best when used with multiphase functions Remember crashdump is single-threaded
Best Known Practices: Memory Allocation Uncached Extension allocation can only be done during Start Channel AtaPortGetPhysicalAddress retrieves physical address for: IRB's data buffer IRB's IrbExtension Miniport's uncached extension SGList Entries and Page Breaks
Best Known Practices: Queuing Per Channel Use IDE_UNTAGGED for TargetID on QueueTag function calls Per Device Use TargetID on QueueTag function calls Always, Always pause the queue with AtaPortDeviceBusy when failing an IRB with IRB_STATUS_BUSY
Best Known Practices: Bus Configuration Changes ChannelEnable is optional and only used to validate the channel Critical hardware operations should not be done in ChannelEnable ChannelEnable will only be called during QueryDeviceRelations Use AtaPortBusChangeDetected to reenumerate a channel Use AtaPortDeviceArrived and AtaPortDeviceRemoved for device hotplug
Best Known Practices: IO Error Reporting STATUS_BUSY Host is busy Make sure to pause the queues with AtaPortDeviceBusy SELECTION_TIMEOUT Device busy Not necessarily retried IRB AtaStatus and Error fields Only valid on Selection_Timeout, and Error
Summary ATAport is an improved port-miniport interface for ATA-based controllers ATAport supports the latest ATA and architecture features
Additional Resources ATA Miniport Interface List of Specifications Documented in the WDK List of Specifications ATA - http://www.t13.org SATA - http://www.serialata.org SCSI - http://www.t10.org AHCI - http://developer.intel.com/technology/serialata/ahci.htm
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.