ata miniport nuts and bolts michael xing sde ii device and storage technologies...

21

Upload: maryann-quinn

Post on 12-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com
Page 2: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

ATA Miniport Nuts and Bolts

Michael XingSDE II Device and Storage Technologies

[email protected]

Page 3: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Agenda

• Why ATA Miniport?

• ATA Port / Miniport Model

• ATA Port / Miniport Interfaces

• New Interfaces in Windows 7

• Best Practices

Page 4: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Why ATA miniport? Do I need an miniport driver?

• Controllers supported by inbox drivers

• Microsoft inbox ATA miniport drivers:

• atapi.sys – developed for legacy PATA controllers

• msahci.sys – developed for SATA controllers

• Consider options other than a driver

• Special requirements that are not covered by inbox drivers:

• Your hardware uses ATA protocol but has a different transfer layer or exposes special feature(s)

• Contact us about feature support before developing your own miniport driver

Page 5: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Why ATA miniport? Which port driver model should I use?

• Windows versions support

• ATAport: Vista and later

• Storport: Server 2003 and later

• Command protocol selection

• ATAport / miniport command protocol: ATA

• Storport / miniport command protocol: SCSI

• Common ATA functionalities implemented in ATA port driver

• Such as set device attributes, set transfer mode, etc.

• Less code in miniport

Page 6: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

ATA Port/Miniport Model – Driver Stack

PCI Driver

Class Driver

ATA Miniport Driver

ATA Port DLLs- ATAport.sys- PCIIDEx.sys

Page 7: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

ATA Port/Miniport Model – Loading Sequence

ATA Controller

PCI Driver

CreateController PDO

Load ATA Miniport

LoadPCIIDEx.sys

LoadATAport.sys

CreateController FDO

EnumerateChannels

CreateChannel PDO

Create Channel FDO

CreateDevice PDO

CreateDevice FDO

LoadClass Driver

EnumerateDevices

Page 8: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

ATA Port/Miniport Model – Role of ATA Port Driver

• I/O translation into ATA protocol

• I/O queuing with prioritization considered

• Sense Data generation for ATA devices

• PnP and power request handling

• Request to miniport driver in push mode

Page 9: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

ATA Port/Miniport Model – Role of ATA Miniport Driver

• Convert ATA command into final transfer layer package if necessary

• Send final command to device

• Monitor interrupt for command completion

• Negotiate for channel and device parameters

• Select queue depth

• Freeze/unfreeze queue according to device status

Page 10: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Port / Miniport Interfaces – General

ATA Miniport Driver

ATA Port DLLs- ATAport.sys- PCIidex.sys

I/O

ATA ControllerVendor Miniport

Channel Interface

ATAport

PCIidex

Default Miniport

Controller Interface

Page 11: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Port / Miniport Interfaces – Miniport Major Routines

• Controller Interface Routines

• DriverEntry()

• AtaAdapterControl() – PnP, power operations

• AtaControllerChannelEnabled() – Channel is usable or not

• Channel Interface Routines

• AtaChannelInitRoutine() – Set routine pointers for channel

• IdeHwControl() – PnP, power operations

• IdeHwInitialize() – Device initialization

• IdeHwBuildIo() – I/O preparation

• IdeHwStartIo() – Execute the I/O

• IdeHwInterrupt() – Monitor hardware activities; process I/O completion

Page 12: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Port / Miniport Interfaces - Controller Interfaces

ATA Port ProcessesMiniport Interfaces

AtaPortInitializeEx()

Start Device (Controller)

AtaAdapterControl() with IdeStart

AtaControllerChannelEnabled()

Load ATA Miniport

LoadPCIIDEx.sys

LoadATAport.sys

Add Device - Create Controller FDO

EnumerateChannels

CreateChannel PDO

DriverEntry()(Set callback function pointers)

Page 13: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Port / Miniport Interfaces - Channel Interfaces

ATA Port ProcessesMiniport Interfaces

Add Device – Create Channel FDO

CreateDevice PDO

EnumerateDevices

AtaChannelInitRoutine()

IdeHwControl() with IdeStart

IdeHwInitialize()

IdeHwBuildIo()

IdeHwStartIo()

IdeHwInterrupt()

Start Channel

Configure Devices

I/O

Page 14: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Port / Miniport Interfaces – I/O Interface

• IDE_REQUEST_BLOCK • Contains

• Structure for ATA TaskFile• I/O execute mode – PIO or DMA• Data buffer for the I/O• Other information needed by

Miniport driver to execute the command

• Status and Error field

• Usage• I/O request• Miniport action, such as power

down the device

// 0x100 - 0x1FF indicate ATA commands#define IRB_FUNCTION_ATA_COMMAND 0x100#define IRB_FUNCTION_ATA_IDENTIFY 0x101#define IRB_FUNCTION_ATA_READ 0x102#define IRB_FUNCTION_ATA_WRITE 0x103#define IRB_FUNCTION_ATA_FLUSH 0x104#define IRB_FUNCTION_ATA_SMART 0x105

// 0x200 - 0x2FF indicate ATAPI commands#define IRB_FUNCTION_ATAPI_COMMAND 0x200#define IRB_FUNCTION_REQUEST_SENSE 0x201

// 0x400-0x4FF indicate miniport commands#define IRB_FUNCTION_MINIPORT_COMMAND 0x400#define IRB_FUNCTION_ADAPTER_FLUSH 0x401#define IRB_FUNCTION_SHUTDOWN 0x402#define IRB_FUNCTION_POWER_CHANGE 0x403#define IRB_FUNCTION_LUN_RESET 0x404#define IRB_FUNCTION_MINIPORT_IOCTL 0x405#define IRB_FUNCTION_POWER_REBOOT 0x406

Page 15: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

New Interfaces in Windows 7

• System Reboot Notification • IRB_FUNCTION_POWER_REBOOT

• Vendor-Defined Power Management• IDE_CONTROL_ACTION – IdeVendorDefined

• Device Parameter Flags• Removable Device Flag – DFLAGS_REMOVABLE_DEVICE• FUA Support Flag – DFLAGS_FUA_SUPPORT

Page 16: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Best Practices - Device Parameter Changes• Changing removable device flag in Microsoft Miniport driver for

SATA controller

BOOLEAN AhciHwInitialize ( IN PVOID ChannelExtension, IN OUT PIDE_DEVICE_PARAMETERS DeviceParameters, IN PIDENTIFY_DEVICE_DATA IdentifyData ){ … … // 3.1 Removable Device Detect if ((channelExtension->Px->CMD.HPCP) || ((channelExtension->CAP.SXS) && (channelExtension->Px->CMD.ESP))) {

// Px->CMD.HPCP indicates that the port is hot-pluggable. (both signal and power cable) // CAP.SXS && Px->CMD.ESP indicates that it's an ESATA port. (only signal cable)

DeviceParameters->DeviceCharacteristics |= DFLAGS_REMOVABLE_DEVICE; } … …

return TRUE;}

Page 17: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Best Practices – Pause Process

• AtaPortStallExecution()• Spin locks the CPU for x microseconds• Less than one millisecond delays• Should be used during hibernate or crash dump

• AtaPortRequestTimer()• Causes the port driver to trigger a callback routine after x

microseconds• Greater than one millisecond delays• Best when used with multiphase functions

Page 18: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Best Practices – I/O Error Reporting

• IRB_STATUS_DEVICE_ERROR• Most common I/O error code

• IRB_STATUS_BUSY• Host is busy• Make sure to pause the queues with AtaPortDeviceBusy()

• IRB_STATUS_SELECTION_TIMEOUT• Not necessarily retried• Port driver may reset the device

• IRB AtaStatus and Error fields• Only valid on IRB_STATUS_DEVICE_ERROR or

IRB_STATUS_SELECTION_TIMEOUT

Page 19: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Calls to Action

• Read “ATA Miniport Drivers” in MSDN• http://msdn.microsoft.com/en-us/library/aa508877.aspx

• Refer to sample code• Microsoft Miniport driver for AHCI controller in WDK at src\storage\

msahci

• Ask questions at ATA Miniport Driver Development Forum• http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1837&

SiteID=1

• Contact us about feature support: [email protected]

Page 20: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Resources

• Related Specifications• ATA - http://www.t13.org• SATA - http://www.serialata.org• AHCI -

http://developer.intel.com/technology/serialata/ahci.htm

• Related SessionsSession Day / Time

Storport Drivers from the Ground Up Tues. 8:30-9:30 and Wed. 9:45-10:45

Storport Smorgasboard Tues. 4-5 andWed. 11-12

Page 21: ATA Miniport Nuts and Bolts Michael Xing SDE II Device and Storage Technologies xiaoxing@microsoft.com

Questions ?