Serial ATA Native Command Queuing
The commands also contain a force unit access (FUA) bit for high availability applications. When
the FUA bit is set for a Write FPDMA Queued command, the drive will commit the data to media
before returning success for the command. By using the FUA bit as necessary on writes, the
host can manage the amount of data that has not been committed to media within the drive’s
internal cache.
Register
7 6 5 4 3 2 1
0
Features Sector
Count
7:0
Features (exp)
Sector Count 15:8
Sector Count
TAG
Reserved
Sector Count (exp)
Reserved
Sector Number
LBA 7:0
Sector Number (exp)
LBA 31:24
Cylinder Low
LBA 15:8
Cylinder Low (exp)
LBA 39:32
Cylinder High
LBA 23:16
Cylinder High (exp)
LBA 47:40
Device/Head
FUA 1 Res 0
Reserved
Command 60h
Figure 1
Read FPDMA Queued Command
One interesting field is the TAG field in the Sector Count register. Each queued command issued
has a tag associated with it. The tag is a shorthand mechanism used between the host and the
device to identify a particular outstanding command. Tag values can be between 0 and 31,
although the drive can report support for a queue depth less than 32. In this case, tag values are
limited to the maximum tag value the drive supports. Having tag values limited to be between 0
and 31 has some nice advantages, including that status for all commands can be reported in one
32-bit value. Each outstanding command must have a unique tag value.
The Read and Write FPDMA Queued commands are issued just like any other command would
be, i.e. the taskfile is written with the particular register values and then the Command register is
written with the command opcode. The difference between queued and non-queued commands
is what happens after the command is issued. If a non-queued command was issued, the drive
would transfer the data for that command and then clear the BSY bit in the Status register to tell
the host that the command was completed. When a queued command is issued, the drive will
clear BSY immediately, before any data is transferred to the host. In queuing, the BSY bit is not
used to convey command completion. Instead, the BSY bit is used to convey whether the drive is
ready to accept a new command. As soon as the BSY bit is cleared, the host can issue another
queued command to the drive. In this way a queue of commands can be built within the drive.
Transferring Data
NCQ takes advantage of a feature called First Party DMA to transfer data between the drive and
the host. First Party DMA allows the drive to have control over programming the DMA engine for
a data transfer. This is an important enhancement since only the drive knows the current angular
and rotational position of the drive head. The drive can then select the next data transfer to
minimize both seek and rotational latencies. The First Party DMA mechanism is effectively what
allows the drive to re-order commands in the most optimal way.
As an additional optimization, the drive can also return data out-of-order to further minimize the
rotational latency. First Party DMA allows the drive to return partial data for a command, send
partial data for another command, and then finish sending the data for the first command if this is
the most efficient means for completing the data transfers.
6