This article is the first in a series which will discuss how to work with SATA drives, how to retrieve information from the drive which will describe how it is set up. How to issue commands to the drive to change its behavior. We will try cover all of the most-used SATA Feature Sets, their interpretation and use. We will discuss the SCT command transport and compare how SATA commands are evolving. Hopefully all this will instill an interest in learning more about what can and can’t be done with SATA drives.
These articles assumes that the reader has a basic understanding of computer oriented data/numeric concepts, such as Boolean algebra, bit manipulation using hexadecimal numbers, and byte-order-swapping.
ATA documentation will be referred to in this instruction. The most current ATA specification (ATA -8) can be found by doing a web search on the term “D1699r4c”. Having this document handy is essential for working with SATA drives and so it is very importand that you always have it on hand.
Find and download this document for your reference now.
And as a final requirement you will need to have a test computer system with the latest version (8.4 at present) installed and known to be working with your hardware test setup.
Preface – Using SAT
The STB Suite uses a specification called SCSI->ATA Translation (SAT) to issue SATA commands to a SATA disk drive which is connected to the test computer system via an LSI SAS host bus adapter (HBA). SAT allows SATA task register commands to be embedded into a 12-byte SCSI CDB.
All tests and exercises in these articles assume that you are experimenting with a SATA disk drive which is connected to a SAT-Compliant SAS Host Bus Adapter (HBA). Qualified HBA’s are the LSI family of non-RAID cards such as the 3800x, 3801e, and 9200-8e and some ATTO cards.
For more detailed information on how to SAT is implemented in the STB Suite please refer to the document UsingSAT.pdf. It is highly recommended that you study this paper and gain an understanding of what SAT is, how it works, and how it is used testing SATA drives in the STB Suite environment.
These articles will be presented as a series of lessons, this introduction has the following steps or items:
- Preparing for the lessons, getting your ATA background solid
- Using the IDENTIFY command to view drive setup
Preparing for the lessons
We will be using the User Defined CDB function within the original mode of the STB Suite to issue the commands to the disk drive.
- Start your STB Suite and choose “Original Mode”
- Right-Click on your drive in the device display
- Choose the “User Defined CDB’s” choice to enter the User Defined CDB function menu
- This will bring up the User Defined CDB function menu – you will be spending a lot of time using this function to explore your SATA drive!
The IDENTIFY command
The most basic command in dealing with SATA drives is the IDENTIFY command. It is used to read the current settings of the drive under test. Define a 12-byte CDB to issue the IDENTIFY command as follows: (please note – you may contact firstname.lastname@example.org and they will be glad to email you a commands.dat file which has all of the SATA commands we will be using all pre-defined for you.)
Some items to note from the above:
- All SATA commands will have one of three types of data phase –
- No data
- Data in (from drive to computer)
- Data Out –( from computer to drive)
- If there is a data in or data out phase the data transfer length will ALWAYS be 512 bytes. Setting the data direction or transfer length incorrectly will likely blue-screen your system.
- Commands may be freely added to your commands file. First define everything about the command including a unique name, then click “Add CDB”, then click “Save CDB File”
With the CDB defined exactly as show above click the “Send CDB” button to issue the command to the drive.
To view the IDENTIFY data which has just been read into the buffer click the “Buffers” button.
The 512 bytes of IDENTIFY data which the drive sent to the computer in response to the IDENTIFY command is shown in this buffer. The buffer is organized to facilitate easy reading of hexadecimal data. You can maneuver through the buffer using the vertical scroll bar clicking on the bar or on the arrow to move by a few lines at a time. You can also enter the exact buffer address or offset in the “Offset:” field and clicking the Go button.
The buffer data values are displayed in hexadecimal and to the right of the hex display the ASCII characters represented by the data (if any) will be displayed.
You may also save buffer data to files in various formats, and load the buffer from a file as well.
The main buffer options that will be used in these instructions are:
- Fill the buffer with all zeros – click the “Fill Buffer” button with “All Zeros (0)” data pattern selected
- Edit or change the value stored at a specific byte. For instance, click on the edit box at the 0/1 junction (referred to as buffer address 0x01) and enter the value you want stored there. When you click Return to exit the buffer editor you will be asked to confirm that you want to keep any buffer data edits or changes you have made.
Interpreting the Data
It is very important at this point to discuss how to interpret this data. There will be many times when manipulating your SATA drive that you will need to be able to understand how the data which the drive returns relates to the ATA documentation. You will also be called upon to know how to correctly format information to be sent to the drive with various commands.
At this point please refer to section 3.2.9 ATA string convention in your copy of the ATA-8 document.
This section will explain what we mean when we refer to ATA data being “byte-swapped” .
It is very easy to misunderstand byte-swapping and bit numbering conventions used in the ATA documentation so you will want to be certain that you fully understand these concepts.
Now refer to the ATA-8 documentation, section 7.16 IDENTIFY DEVICE. Read this entire section from section 7.16.0 through 126.96.36.199. There is a lot of information and it is vital to understand what information is there and what it means.
This section of the ATA-8 documentation references the IDENTIFY data by word. A word is two bytes. Also note – these words are represented in decimal notation. The STB Suite uses hexadecimal notation and then refers to bytes, which are further broken down into 16 bits. Re-read sections 3.2.5 – 3.2.9 of the ATA-8 doc to solidify this data representation in your mind.
In order to actually reference and use the IDENTIFY data you just read in you will need to convert the ATA-8 documentation numbers from words into bytes, multiply it by 2 and then convert that decimal number into a hex number to view in the STB Buffer Editor.
Or going the other direction, convert the STB buffer address from hex to dec then divide that number by two to get your reference back into the documentation.
Example: Word 88 in the ATA docs in our world is hex byte 0xB0 (decimal 88, times 2, convert to hex)
Once you are looking at byte 0xB0 in the buffer editor you will also have to take into account the byte-ordering or swapping issue that we referred to above in ATA string convention…
To finish covering data representation let’s look at the 16 bits that make up a word. A good example is on page 115 of the ATA document. Looking at word 85 you will see that the ATA document references each of the 16 bits of the word by their bit-position within the word. So the least significant bit is referred to as “0” and the most significant bit is referred to as “15” in the ATA document. Note – this is different than the value or weight of the bit position within the word. The value or weight of bit position “15” if set is actually 16, and the value of bit position “0” if it is set is 1.
In other words if SMART error logging is supported on your drive you will find that bit position zero will equal to 1 in word 85.
So – you have to convert from words to bytes, convert from decimal to hexadecimal, and byte swap the 16 bits of these two bytes and then determine which bit will be set or not…Simple, right? If this actually is simple to you there may a job waiting for you at SCSI Toolbox. No, really, drop us a line!
Once you have read this section a few times over you should be able to explain what each bit of each of the 512 bytes (or 256 words) of IDENTIFY information conveys. Also, with your new understanding of this data representation I recommend that you read sections 3.2.6 – 3.2.9 one more time.
An exercise correlating buffer data with ATA-8 documentation
For example, once you are comfortable with this section you should be able to identify (no pun intended) the way in which your drive will report that the Security feature set is enabled. (Hint – look at word 85 in the ATA-8 doc).
As an exercise to complete your becoming familiar with the way IDENTIFY data is represented I will tell you that the other place where Security enabled is defined is at byte 0x100, bit position one.
Why is it at 0x100? Because 0x100 converted to decimal is 256, and 256 divided by 2 is 128. You want to look at word 128, bit position 1. And word 128 is found on page 120 of the ATA-8 doc –
If you still don’t understand how or why we convert from hex to dec, and why we then divide by 2, and why I said “bit position 1” rather than” bit 2”… – go back and read this section again. It is very important that this become second nature to you if you want to work with raw data and SATA commands. It can be very frustrating to spend hours “troubleshooting” a SATA feature only to discover you forgot about byte-swapping or you were looking for the wrong bit to be set…
Final exam: What does this buffer screen shot tell you about the drive as far as SECURITY feature sets and settings? Is a user password set or not? Is Write CACHE enabled? IS the SMART feature set enabled?
Look at and interpret what the drive put at buffer address 0xAA when we sent the IDENTIFY command. The put the value 0x69 at buffer location 0xAA. What does that tell us?
By now hopefully you understand how to issue an IDENTIFY command to a drive and how to interpret the returned data by correlating it to the ATA-8 documentation. I hope this little exercise gives you an appreciation of how much data the drive will tell us about itself. After all, we have only looked a very few bytes of IDENTIFY data but the drive returns 512 bytes!
Next in the series we will discuss some of the SATA Feature Sets. You can get a head start by reading all of section 4 in the ATA-8 document.