Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55036
  • 博文数量: 8
  • 博客积分: 1598
  • 博客等级: 上尉
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-09 15:35
文章分类

全部博文(8)

文章存档

2010年(1)

2009年(7)

我的朋友

分类: LINUX

2009-12-18 16:59:04

Part 1 - low level IO operation (read/write)

This part mainly focuses on how AHCI controller performs read/write operations
with SATA device. In the following text, host means AHCI controller while device means sata device

After inited, each port in the host is in idle state. They are monitoring the PORT_CMD_ISSUE register, waiting for new commands to be served.

1. When driver receives an IO request, it will find an empty slot (there are 32
slots for each port)in the command table and init the command table slot using the
info from the request. Then it sets the corresponding bit in PORT_CMD_ISSUE
register.

2. The host finds there is a new command comming, it will fetch
the command FIS (H2D FIS) in the command table slot. Then it transmits
the CFIS to the device. The host will first check the BSY bit of
the status register (this bit indicates whether the device is busy now),
if it is set, host will defer the transfer. When the host starting
trasmitting the CFIS, it will set the BSY bit.

3. If it is a DMA read/write command, the device will send a DMA
activate FIS to the host.

4. Once the host receives the DMA activate FIS, it will setup the DMA
engine and start trasmitting/receiving data to/from the deivce.

5. After the data transmission finished, the device will send a D2H FIS
to the host, once the host receives this FIS, it will update the shadow
status register (clear the BSY bit of the shadow status regsiter)
according to the status field of the D2H FIS, and clear the bit in the
PORT_CMD_ISSUE. Then it will generate an interrupt to the CPU if the I
bit is set in the D2H FIS.

The difference between NCQ command and non-queued command is essentially
in step 3.
If it is a queued command, the device will send a D2H FIS to the host,
clearing the BSY bit in the status register. Once the BSY bit is
cleared, then the host can send a new command to the device. Thus the
device can receive serveral commands into its internal command queue,
and determine optimal sequence to serve the commands. So for NCQ, the
BSY bit only means the device has accepted the command (not mean it
finishes the command).
The PORT_CMD_ISSUE is not used to determine whether the command is
finished in NCQ case. The device will send SDB FIS (Set Device Bits) to
tell the host which commands are finished. The host will clear bits in
the SActive register to tell driver which commands are finished.
阅读(2622) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~