STB Suite

Issuing ATA Commands

What are ATA commands?

ATA commands, also referred to as ATA task register commands, are commands issued to ATA or SATA interface storage devices. From now on in this article when we refer to ATA we mean this to include both ATA and SATA devices.

ATA commands are used to write and read data from ATA drives, as well as to set various device parameters and to read device health data.

Task registers refers to the original hardware interface to these devices which consisted of seven separate registers. These seven registers were loaded with the appropriate values and were then transferred to the drive, where the drive would interpret from the registers what it was being asked to do, and would then (hopefully) complete the command.

All aspects of the ATA commands are described in the T13 documents, in particular you should download and study the file http://www.t13.org/Documents/UploadedDocuments/docs2008/D1699r6-ATA8-ACS.pdf

Important Issues for dealing with ATA drives!

Requirements

Hardware Requirements

To run the example STB ATA and SATA commands you will need a computer system running Windows operating system. If you need to test 48-bit ATA or SATA commands you need to be sure that the operating system drivers support these operations. The drivers in Windows Server 2003 do support 48-bit operations, other OS’s will need testing to see if they support these commands.

You will also need an ATA or SATA controller which the operating system recognizes as a true ATA Task Register type of controller. Most add-in PCI SATA controllers are seen by Windows as if they are a SCSI host bus adapter rather than an ATA controller.

You can confirm how your operating system views your controller scheme by using Device Manager as shown below – note that drives that will be able to be issued ATA or SATA commands must be attached to a controller that Windows sees as an IDE ATA/ATAPI controller

Note regarding 48-bit commands:

Also, be aware that at this time the Windows operating systems that do support 48-bit operations have a bug in ATA PASS THROUGH. After a 48-bit command completes, only the FIRST task file is returned (HOB=0), but not the second one (HOB=1). Thus, READ NATIVE MAX ADDRESS EXT can get the low LBA bits 0..23, but not the high LBA bits 24..47.

Once you have disk drives attached to the proper controller you can run the example STB ATA/SATA Command Compliance Test

User Requirements

It is essential that the user of this test be familiar with the ATA and SATA specifications. Documentation can be found at www.t13.org

And in particular

http://www.t13.org/Documents/UploadedDocuments/docs2008/D1699r6-ATA8-ACS.pdf

Issuing ATA commands using the STB Suite

In the top menu of the STB Suite select ATA/SATA->Commands->User Defined Commands to bring up this dialog:

 

Choosing a pre-defined Command

Click on the pull-down arrow at the right of the Command window to display and scroll through the pre-defined commands. Double-click on a command to load the task registers with the command bytes

 

 

Here we see the ATA IDENTIFY command has been loaded into the task registers, the data direction and data transfer length have been specified, we have set the command timeout to abort the command if it is not completed within 5 seconds, we have selected a drive, and we have specified to send the command just once.

 

Look at command results

Upon issuing an ATA command the ATA drive will return status information which will be displayed in the Command Results area. The status bytes are displayed along with the broken-out individual status bits. In this case we can see that the Status register contains the value 0x50 which tells us the command was completed successfully.

 

Command Results History

All command results details are temporarily stored in a history list which can be viewed by clicking the View Results button. This result history may be saved to a text file

 

If an error occurs

If the command you issued does not complete successfully the drive will return status information in the status registers. In the case shown below we have issued a MEDIA EJECT command to a fixed media disk drive. Since this in an illegal command for this drive the command fails and the status may be read. In most cases of failure the command STATUS register will contain 0x51. The specific error bits are decoded – showing a command abort:

Looking at returned data

Data returned by the drive is viewable by clicking the Buffer button. The STB Suite displays the data as it is returned by the drive, which in the case of ATA devices will be byte-swapped.

The File Operations button will allow you to save the contents of the data buffer to a file. You may specify how many bytes to write to the file, and you may specify the data format, either “raw” binary data, or as a text file.

 

Defining a custom command

Any byte values may be placed into the task registers, allowing you to issue any command. This capability does not check for any type of validity. This means that you can use the User Defined Command function to issue legal as well as illegal or “broken” commands to a device.

Keep in mind that the Windows ATA drivers are not particularly robust – it is easy to hang the system if you issue an illegal command. Example of illegal commands includes task register values which are illegal, as well as data transfer lengths or data direction which is incorrect. As an example, if you issue a command which will return 512 bytes of data but you specify a data transfer length of 1024 bytes the command will probably abort after the specified command timeout has passed.

Adding commands to the command list

By clicking the Add Command To List button you may store your own custom command into the command file where they can be selected later from the command pulldown. If you make a mistake you can remove a command from the list using the Delete Command from List button.