SCSI子系统基础学习笔记 (之UFS子系统) - 1.1 概述(硬件与协议部分)

1. 前言

本专题我们开始学习SCSI子系统的相关内容。本专题主要参考了《存储技术原理分析》、ULA、ULK的相关内容。本专题主要以硬件UFS,控制器以高通UFS控制器为例,记录SCSI子系统的框架流程。本文是UFS子系统硬件及协议的概述部分。

kernel版本:5.10
平台:arm64

注:
为方便阅读,正文标题采用分级结构标识,每一级用一个"-“表示,如:两级为”|- -", 三级为”|- - -“

2. 总体架构

在这里插入图片描述
UFS总体架构重要包含了ufs host controller部分和ufs device部分,UFS协议对应的也分为两类:UFS HOST CONTROLLER INTERFACE协议和UFS协议。
在这里插入图片描述
无论是ufs host controller部分还是ufs device部分,他们都将遵循统一的UFS规范

  • UFS Application Layer(UAP)应用层
    1.UFS command set (UCS)
    UCS处理命令集,如读、写命令等,.使用的命令是简化的SCSI命令(基于SBC和SPC),也可以扩展UFS本地命令集,目前暂时没有定义
    2.Task Manager
    任务管理器用以管理命令队列中的命令。比如任务管理器可以发Abort命令,终止之前发下去的命令。它也可以清空命令队列中的所有命令

  • device manager(Query Request)
    设备管理器用以管理UFS设备,包括:
    (1)处理设备级操作
    设备功耗管理、数据传输设置、后台操作使能和其它的特定操作
    (2)管理设备级配置
    维护和存储一组描述符,例如查询请求命令允许修改和查询设备的配置信息

  • The UFS Transport Protocol (UTP)传输层
    主要功能在UFS host端和ufs device端传输UPIU,将应用层的命令封装成UPIU,命令的数据、状态等对应不同的UPIU。UPIU是主机和设备进行信息交换的基本数据单元,它使用数据帧可以最小限度的减少HOST的处理时间,同时由device端控制数据传输的节奏,无需host端poll

  • UFS Interconnect Layer(UIC)互联层
    主要包括MIPI UniPro 数据链路层和MIPI M-PHY 物理层。其中,MIPI UniPro 数据链路层负责主机和设备的链接,它本身是一个完整的协议栈; MIPI M-PHY 物理层负责传输实实在在的物理信号,使用8/10编码、差分信号串行数据传输,数据传输分高低速模式,每种模式下又有几种不同的速度档

3. UFS host controller

|- -ufs系统框图

在这里插入图片描述

  1. UFS控制器有如下的接口
  • AHB interface

Used for software access and for programming and initializing the controller; it connects as an AHB slave on the config NOC of the chip operating at 75 MHz.

  • AXI master interface

Used for data transfer to and from the system memory; it connects as an AXI master on the system NOC operating at 200 MHz

  1. UFS host控制器功能
  • Receives clocks from the global clock controller (GCC) of the chip.
  • Maintains a dedicated interrupt output line that is connected to apps QGIC.
  • Connects to M-PHY via standard Reference M-PHY Module Interface (RMMI).
    M-PHY has a differential serial interface to the UFS device. This works as a dual simplex Tx/Rx
    interface with two lanes in each direction.

|- -UFS controller wrapper

在这里插入图片描述
The UTP controller implements a standard Host Controller Interface (HCI) for hardware and software.

  1. For outbound transactions, the UTP controller:
    ■ Receives commands from the software
    ■ Generates outbound UPIU transactions
    ■ Sends them to the UniPro controller via the CPort

  2. For inbound transactions, the UTP controller:
    ■ Receives inbound UPIU transactions from UniPro controller via the CPort
    ■ Moves the received data to buffers in the system memory specified through HCI

|- -UFS HCI

在这里插入图片描述
UFS驱动通过UFS HCI管理UFS host controller.UFS HCI包含如下的模块:

  • CSR
    The CSR module implements software registers via an AHB slave interface that is connected to the
    config NOC. The CSR module:
    (1) Detects software TR via the TR doorbell register and marks the index of the doorbell bit into the
    HCI TR FIFO
    (2) Detects software TMR via the TMR doorbell register and marks the index of the doorbell bit into
    the HCI TMR FIFO
    (3) Allows for control of UniPro controller by generating requests to it through the DME interface unit;
  • Transfer request (TR) FIFO
  • TMR FIFO
  • Interrupt aggregation and generation (IAG) unit

注:上图中绿色的为寄存器

|- -host端数据结构

在这里插入图片描述
UFS host驱动通过分配和使用UTRD描述符和UTMRD描述符来与host控制器硬件通信。host控制器系统内存可以同时接受多达32个UTRD描述符和8个UTMRD描述符。每个UTRD描述符指向了一块内存区域,这块内存区域包含:命令UPIU(UCD),response UPIU,并包含了一块物理区域描述符表(PRDT),表中每一项指向一个数据buffer,存储需要传输的数据(command upiu)或要接收的数据(response upiu)。UCD的command和response将被分别组装成UPIU并通过UTP层进行传输。

  • UTP UTRD
    This section defines Transfer Request Descriptor for UTP commands.
    对应数据结构为struct utp_transfer_req_desc
    在这里插入图片描述

  • UTP command descriptor
    A UTP command descriptor contains the UPIU for the command, offset and length of the data buffer associated with the command, and offset and length of the PRDT.
    对应的数据结构为struct utp_transfer_cmd_desc
    在这里插入图片描述

  • UTP TMR descriptor (UTMRD)
    对应的数据结构为struct utp_task_req_desc
    在这里插入图片描述

4. UTP层

  1. UTP层(可参考总体架构部分),它采用SCSI架构模型(SAM)作为通用架构模型和任务管理功能,该模型使用了SCSI命令集作为命令集。

  2. SAM架构是一个客户-服务模型或通俗说请求-响应架构。client-server 指的是输入是由发起设备的application clent发起,由server来执行,并返回输出和调用状态。client-server不是对称的关系。clent只能作为请求的发起者,server只能响应这个请求。

  3. 任务是一个命令或用来执行一个请求服务的顺序的动作(这些都将封装成UPIU)。一个LU包含了一个任务队列,它支持一个或多个任务的处理。任务队列由LU管理。唯一的Task Tag是由发起设备在创建任务时产生,Task Tag由目标设备和发起设备用来区分多个任务。所有和特定task相关的transactions和sequences都将在对应结构体包含这个Task Tag

  4. 发起设备和目标设备被映射到UFS物理层。

  5. 发起设备可以通过发送请求处理命令服务或任务管理功能服务给目标设备。.目标设备是一个UFS设备,UFS设备包含一个或多个LU.一个LU是设备中一个独立的处理实体。一个发起请求被发送给设备中一个单独的LU。一个LU将接受并处理这个client命令或请求。每个LU在设备中有一个地址叫做LUN.

  6. 命令结构由CDB组成,它包含了一个命令码和相关的参数,标志和属性。CDB的描述参考SAM,SBC,SPC标准

  7. 一个命令事务由命令、可选的数据部分和状态部分构成。这些事务由UPIU表示:
    (1)命令阶段,从发起设备向目标设备发送这些命令信息和支持参数;
    (2)数据阶段,数据传输方向与发起设备有关。数据写时从发起设备到目标设备,数据读是从目标设备到发起设备;
    (3)状态阶段,命令完成时,目标设备将发送一个响应给发起设备,响应信息包含状态和UFS响应状态用来指示命令成功与否,如果失败了,响应信息中会包含一些额外的错误信息

  8. UFS传输是由UPIU组成的,它主要在设备间通过UniPro总线传输。发起设备发起请求给目标设备和LU,目标设备然后用一系列的传输作为响应;所有UPIU由单个基本的头部分,特定域部分,可能一个或多个扩展头部分和0个或多个数据部分组成;一个基本的头部分有一个固定12字节的长度。最小的UPIU大小是32字节,它包含了一个基本的头部分和一个传输域;最大的UPIU大小被定义为65600字节

|- -通用UPIU格式

在这里插入图片描述
所有的UPIU大小必须是32bit对齐,也就是4字节对齐
在这里插入图片描述

|- - -Basic Header Format

在这里插入图片描述

  • transaction Type
    The Transaction Type indicates the type of request or response contained within the data structure.
  • Flags
    The content of the Flags field vary with the Transaction Type opcode
  • LUN
    This field contains the Logical Unit Number to which a request is targeted.
  • Task Tag
    The Task Tag is generated by the Initiator device when creating a task request
  • Initiator ID (IID)
    The Initiator ID field is 4 bits wide, encoded in bits [7:4] of byte 4. This field indicates the identity of the Initiator device who created the task request.
  • Command Set Type
    Command set type field is 4 bits wide, encoded in bits [3:0] of byte 4. This field indicates the command set type the Command and RESPONSE UPIU is associated with
  • Query Function, Task Manag. Function
    This field is used in QUERY REQUEST and QUERY RESPONSE UPIU’s to define the Query function, and in TASK MANAGEMENT REQUEST UPIU to define the task management function.
  • Response
    If a response is required from a Target device, this field indicates whether the requested function succeeded or failed. This field is reserved in UPIU transactions from Initiator device to Target device.
  • Status
    This field contains the SCSI status (as defined in [SAM]) if the transaction is a RESPONSE UPIU for a COMMAND UPIU with Command Set Type = 00h (SCSI Command). Otherwise it contains an opcode specific status or it is reserved.
  • Total Extra Header Segment Length
    This field represents the size in 32‐bit units (DWORDS) of all Extra Header Segments contained within the UPIU.
  • Device Information
    This field provides device level information required by specific UFS functionality in all RESPONSE UPIU.
  • Data Segment Length
    The Data Segment Length field contains the number of valid bytes within the Data Segment of the UPIU

|- - -正文部分

正文部分针对每种特定的UPIU都有自己特定的数据部分。
对于requet upiu的特定数据部分按照flags, descriptor, attribution,又区分成不同的特定数据部分

参考文档

存储技术原理分析

  • 7
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值