← Documents Documentation/scsi/ufs.rst GitHub 원문 ↗

Linux 6.18.37 · SCSI

Universal Flash Storage(UFS) architecture와 UFSHCD

UFS의 M-PHY·UniPro 계층, UFSHCD request·error path, BSG UPIU와 reference clock 설정을 설명합니다.

Source pathDocumentation/scsi/ufs.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

ufs.rst:1-210

UFS의 M-PHY·UniPro 계층, UFSHCD request·error path, BSG UPIU와 reference clock 설정을 설명합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =======================
4 Universal Flash Storage
5 =======================
6
7
8 .. Contents
9
10 1. Overview
11 2. UFS Architecture Overview
12 2.1 Application Layer
13 2.2 UFS Transport Protocol (UTP) layer
14 2.3 UFS Interconnect (UIC) Layer
15 3. UFSHCD Overview
16 3.1 UFS controller initialization
17 3.2 UTP Transfer requests
18 3.3 UFS error handling
19 3.4 SCSI Error handling
20 4. BSG Support
21 5. UFS Reference Clock Frequency configuration
22
23
24 1. Overview
25 ===========
26
27 Universal Flash Storage (UFS) is a storage specification for flash devices.
28 It aims to provide a universal storage interface for both
29 embedded and removable flash memory-based storage in mobile
30 devices such as smart phones and tablet computers. The specification
31 is defined by JEDEC Solid State Technology Association. UFS is based
32 on the MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
33 physical layer and MIPI Unipro as the link layer.
34
35 The main goals of UFS are to provide:
36
37 * Optimized performance:
38
39 For UFS version 1.0 and 1.1 the target performance is as follows:
40
41 - Support for Gear1 is mandatory (rate A: 1248Mbps, rate B: 1457.6Mbps)
42 - Support for Gear2 is optional (rate A: 2496Mbps, rate B: 2915.2Mbps)
43
44 Future version of the standard,
45
46 - Gear3 (rate A: 4992Mbps, rate B: 5830.4Mbps)
47
48 * Low power consumption
49 * High random IOPs and low latency
50
51
52 2. UFS Architecture Overview
53 ============================
54
55 UFS has a layered communication architecture which is based on SCSI
56 SAM-5 architectural model.
57
58 UFS communication architecture consists of the following layers.
59
60 2.1 Application Layer
61 ---------------------
62
63 The Application layer is composed of the UFS command set layer (UCS),
64 Task Manager and Device manager. The UFS interface is designed to be
65 protocol agnostic, however SCSI has been selected as a baseline
66 protocol for versions 1.0 and 1.1 of the UFS protocol layer.
67
68 UFS supports a subset of SCSI commands defined by SPC-4 and SBC-3.
69
70 * UCS:
71 It handles SCSI commands supported by UFS specification.
72 * Task manager:
73 It handles task management functions defined by the
74 UFS which are meant for command queue control.
75 * Device manager:
76 It handles device level operations and device
77 configuration operations. Device level operations mainly involve
78 device power management operations and commands to Interconnect
79 layers. Device level configurations involve handling of query
80 requests which are used to modify and retrieve configuration
81 information of the device.
82
83 2.2 UFS Transport Protocol (UTP) layer
84 --------------------------------------
85
86 The UTP layer provides services for
87 the higher layers through Service Access Points. UTP defines 3
88 service access points for higher layers.
89
90 * UDM_SAP: Device manager service access point is exposed to device
91 manager for device level operations. These device level operations
92 are done through query requests.
93 * UTP_CMD_SAP: Command service access point is exposed to UFS command
94 set layer (UCS) to transport commands.
95 * UTP_TM_SAP: Task management service access point is exposed to task
96 manager to transport task management functions.
97
98 UTP transports messages through UFS protocol information unit (UPIU).
99
100 2.3 UFS Interconnect (UIC) Layer
101 --------------------------------
102
103 UIC is the lowest layer of the UFS layered architecture. It handles
104 the connection between UFS host and UFS device. UIC consists of
105 MIPI UniPro and MIPI M-PHY. UIC provides 2 service access points
106 to upper layer:
107
108 * UIC_SAP: To transport UPIU between UFS host and UFS device.
109 * UIO_SAP: To issue commands to Unipro layers.
110
111
112 3. UFSHCD Overview
113 ==================
114
115 The UFS host controller driver is based on the Linux SCSI Framework.
116 UFSHCD is a low-level device driver which acts as an interface between
117 the SCSI Midlayer and PCIe-based UFS host controllers.
118
119 The current UFSHCD implementation supports the following functionality:
120
121 3.1 UFS controller initialization
122 ---------------------------------
123
124 The initialization module brings the UFS host controller to active state
125 and prepares the controller to transfer commands/responses between
126 UFSHCD and UFS device.
127
128 3.2 UTP Transfer requests
129 -------------------------
130
131 Transfer request handling module of UFSHCD receives SCSI commands
132 from the SCSI Midlayer, forms UPIUs and issues the UPIUs to the UFS Host
133 controller. Also, the module decodes responses received from the UFS
134 host controller in the form of UPIUs and intimates the SCSI Midlayer
135 of the status of the command.
136
137 3.3 UFS error handling
138 ----------------------
139
140 Error handling module handles Host controller fatal errors,
141 Device fatal errors and UIC interconnect layer-related errors.
142
143 3.4 SCSI Error handling
144 -----------------------
145
146 This is done through UFSHCD SCSI error handling routines registered
147 with the SCSI Midlayer. Examples of some of the error handling commands
148 issues by the SCSI Midlayer are Abort task, LUN reset and host reset.
149 UFSHCD Routines to perform these tasks are registered with
150 SCSI Midlayer through .eh_abort_handler, .eh_device_reset_handler and
151 .eh_host_reset_handler.
152
153 In this version of UFSHCD, Query requests and power management
154 functionality are not implemented.
155
156 4. BSG Support
157 ==============
158
159 This transport driver supports exchanging UFS protocol information units
160 (UPIUs) with a UFS device. Typically, user space will allocate
161 struct ufs_bsg_request and struct ufs_bsg_reply (see ufs_bsg.h) as
162 request_upiu and reply_upiu respectively. Filling those UPIUs should
163 be done in accordance with JEDEC spec UFS2.1 paragraph 10.7.
164 *Caveat emptor*: The driver makes no further input validations and sends the
165 UPIU to the device as it is. Open the bsg device in /dev/ufs-bsg and
166 send SG_IO with the applicable sg_io_v4::
167
168 io_hdr_v4.guard = 'Q';
169 io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;
170 io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
171 io_hdr_v4.response = (__u64)reply_upiu;
172 io_hdr_v4.max_response_len = reply_len;
173 io_hdr_v4.request_len = request_len;
174 io_hdr_v4.request = (__u64)request_upiu;
175 if (dir == SG_DXFER_TO_DEV) {
176 io_hdr_v4.dout_xfer_len = (uint32_t)byte_cnt;
177 io_hdr_v4.dout_xferp = (uintptr_t)(__u64)buff;
178 } else {
179 io_hdr_v4.din_xfer_len = (uint32_t)byte_cnt;
180 io_hdr_v4.din_xferp = (uintptr_t)(__u64)buff;
181 }
182
183 If you wish to read or write a descriptor, use the appropriate xferp of
184 sg_io_v4.
185
186 The userspace tool that interacts with the ufs-bsg endpoint and uses its
187 UPIU-based protocol is available at:
188
189 https://github.com/westerndigitalcorporation/ufs-tool
190
191 For more detailed information about the tool and its supported
192 features, please see the tool's README.
193
194 UFS specifications can be found at:
195
196 - UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
197 - UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf
198
199 5. UFS Reference Clock Frequency configuration
200 ==============================================
201
202 Devicetree can define a clock named "ref_clk" under the UFS controller node
203 to specify the intended reference clock frequency for the UFS storage
204 parts. ACPI-based system can specify the frequency using ACPI
205 Device-Specific Data property named "ref-clk-freq". In both ways the value
206 is interpreted as frequency in Hz and must match one of the values given in
207 the UFS specification. UFS subsystem will attempt to read the value when
208 executing common controller initialization. If the value is available, UFS
209 subsystem will ensure the bRefClkFreq attribute of the UFS storage device is
210 set accordingly and will modify it if there is a mismatch.
211

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

문서 범위

1-23

GPL-2.0 UFS 문서는 overview, Application·UTP·UIC의 layered architecture, UFSHCD 초기화·transfer·error handling, BSG interface와 reference clock frequency 설정을 설명한다.

.. SPDX-License-Identifier: GPL-2.0

=======================
Universal Flash Storage
=======================


.. Contents

   1. Overview
   2. UFS Architecture Overview
     2.1 Application Layer
     2.2 UFS Transport Protocol (UTP) layer
     2.3 UFS Interconnect (UIC) Layer
   3. UFSHCD Overview
     3.1 UFS controller initialization
     3.2 UTP Transfer requests
     3.3 UFS error handling
     3.4 SCSI Error handling
   4. BSG Support
   5. UFS Reference Clock Frequency configuration

UFS 목표와 M-PHY·UniPro 기반

24-51

Universal Flash Storage(UFS)는 flash device용 storage specification이다. Smartphone과 tablet 같은 mobile device의 embedded·removable flash storage에 공통 interface를 제공하며 JEDEC Solid State Technology Association이 정의한다. Physical layer는 MIPI M-PHY, link layer는 MIPI UniPro다.

주요 목표는 최적화된 성능, 낮은 power consumption, 높은 random IOPS와 낮은 latency다. UFS 1.0·1.1에서 Gear1은 필수이며 rate A 1248 Mbps, rate B 1457.6 Mbps다. Gear2는 선택이며 2496·2915.2 Mbps다. 이후 standard의 Gear3 목표는 4992·5830.4 Mbps다.

UFS gear 목표 속도
Gear지원Rate ARate B
Gear1필수1248 Mbps1457.6 Mbps
Gear2선택2496 Mbps2915.2 Mbps
Gear3Future4992 Mbps5830.4 Mbps

Version 1.0·1.1과 future Gear3의 rate A·B를 보존했다.

1. Overview
===========

Universal Flash Storage (UFS) is a storage specification for flash devices.
It aims to provide a universal storage interface for both
embedded and removable flash memory-based storage in mobile
devices such as smart phones and tablet computers. The specification
is defined by JEDEC Solid State Technology Association. UFS is based
on the MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
physical layer and MIPI Unipro as the link layer.

The main goals of UFS are to provide:

 * Optimized performance:

   For UFS version 1.0 and 1.1 the target performance is as follows:

   - Support for Gear1 is mandatory (rate A: 1248Mbps, rate B: 1457.6Mbps)
   - Support for Gear2 is optional (rate A: 2496Mbps, rate B: 2915.2Mbps)

   Future version of the standard,

   - Gear3 (rate A: 4992Mbps, rate B: 5830.4Mbps)

 * Low power consumption
 * High random IOPs and low latency

SCSI SAM-5 기반 architecture와 Application layer

52-82

UFS는 SCSI SAM-5 architectural model에 기반한 layered communication architecture다. Application layer는 UFS Command Set(UCS), Task Manager와 Device Manager로 구성된다. Interface 자체는 protocol-agnostic으로 설계됐지만 UFS protocol layer 1.0·1.1의 baseline은 SCSI다. UFS는 SPC-4와 SBC-3가 정의한 SCSI command 일부를 지원한다.

UCS는 UFS specification이 지원하는 SCSI command를 처리한다. Task Manager는 command queue control을 위한 UFS task management function을 처리한다. Device Manager는 device-level operation과 configuration을 담당한다. Operation에는 주로 power management와 interconnect layer command가 포함되고, configuration은 device 정보를 수정·조회하는 query request를 처리한다.

UFS Application layer
Component역할
UCS지원 SCSI command 처리
Task ManagerCommand queue용 task management
Device ManagerPower·interconnect operation과 query configuration

세 component의 책임을 분리했다.

2. UFS Architecture Overview
============================

UFS has a layered communication architecture which is based on SCSI
SAM-5 architectural model.

UFS communication architecture consists of the following layers.

2.1 Application Layer
---------------------

  The Application layer is composed of the UFS command set layer (UCS),
  Task Manager and Device manager. The UFS interface is designed to be
  protocol agnostic, however SCSI has been selected as a baseline
  protocol for versions 1.0 and 1.1 of the UFS protocol layer.

  UFS supports a subset of SCSI commands defined by SPC-4 and SBC-3.

  * UCS:
     It handles SCSI commands supported by UFS specification.
  * Task manager:
     It handles task management functions defined by the
     UFS which are meant for command queue control.
  * Device manager:
     It handles device level operations and device
     configuration operations. Device level operations mainly involve
     device power management operations and commands to Interconnect
     layers. Device level configurations involve handling of query
     requests which are used to modify and retrieve configuration
     information of the device.

UTP service access point와 UIC

83-111

UFS Transport Protocol(UTP) layer는 Service Access Point로 상위 layer에 service를 제공한다. `UDM_SAP`은 Device Manager가 query request로 device-level operation을 수행하는 접점이다. `UTP_CMD_SAP`은 UCS가 command를 transport하는 접점이고 `UTP_TM_SAP`은 Task Manager가 task management function을 transport하는 접점이다. UTP는 UFS Protocol Information Unit(UPIU)으로 message를 운반한다.

UFS Interconnect(UIC)는 architecture의 최하위 layer로 host와 device 사이 connection을 처리한다. MIPI UniPro와 MIPI M-PHY로 구성된다. `UIC_SAP`은 UFS host·device 사이 UPIU를 transport하고 `UIO_SAP`은 UniPro layer에 command를 발행한다.

UFS communication stack
UCS / Task Manager / Device ManagerUDM_SAP · UTP_CMD_SAP · UTP_TM_SAPUPIU를 운반하는 UTPUIC_SAP · UIO_SAPUniPro + M-PHY

Application request가 UTP와 UIC를 거쳐 device로 이동한다.

Service Access Point
SAP사용자목적
UDM_SAPDevice ManagerQuery 기반 device operation
UTP_CMD_SAPUCSCommand transport
UTP_TM_SAPTask ManagerTask management transport
UIC_SAPUTPHost·device UPIU transport
UIO_SAP상위 layerUniPro command

상위 component와 transport 목적의 대응이다.

2.2 UFS Transport Protocol (UTP) layer
--------------------------------------

  The UTP layer provides services for
  the higher layers through Service Access Points. UTP defines 3
  service access points for higher layers.

  * UDM_SAP: Device manager service access point is exposed to device
    manager for device level operations. These device level operations
    are done through query requests.
  * UTP_CMD_SAP: Command service access point is exposed to UFS command
    set layer (UCS) to transport commands.
  * UTP_TM_SAP: Task management service access point is exposed to task
    manager to transport task management functions.

  UTP transports messages through UFS protocol information unit (UPIU).

2.3 UFS Interconnect (UIC) Layer
--------------------------------

  UIC is the lowest layer of the UFS layered architecture. It handles
  the connection between UFS host and UFS device. UIC consists of
  MIPI UniPro and MIPI M-PHY. UIC provides 2 service access points
  to upper layer:

  * UIC_SAP: To transport UPIU between UFS host and UFS device.
  * UIO_SAP: To issue commands to Unipro layers.

UFSHCD 초기화·transfer·error handling

112-155

UFS Host Controller Driver(UFSHCD)는 Linux SCSI Framework에 기반한 low-level device driver로, SCSI Midlayer와 PCIe 기반 UFS host controller 사이 interface다. Initialization module은 controller를 active state로 만들고 UFSHCD와 device 사이 command·response 전송을 준비한다.

Transfer request module은 SCSI Midlayer에서 command를 받아 UPIU를 만들고 host controller에 발행한다. Controller가 UPIU로 보낸 response를 decode해 command status를 SCSI Midlayer에 알린다. UFS error handling module은 host-controller fatal error, device fatal error와 UIC interconnect error를 처리한다.

SCSI error handling은 Midlayer에 등록한 UFSHCD routine으로 수행한다. Abort task, LUN reset, host reset을 각각 `.eh_abort_handler`, `.eh_device_reset_handler`, `.eh_host_reset_handler`로 등록한다. 이 version의 UFSHCD에는 query request와 power management가 구현되지 않았다.

UFSHCD command path
SCSI Midlayer commandUFSHCD가 UPIU 작성UFS host controller·deviceResponse UPIU decodeSCSI Midlayer status 통지

SCSI command가 UPIU로 변환되고 status가 돌아오는 경로다.

3. UFSHCD Overview
==================

The UFS host controller driver is based on the Linux SCSI Framework.
UFSHCD is a low-level device driver which acts as an interface between
the SCSI Midlayer and PCIe-based UFS host controllers.

The current UFSHCD implementation supports the following functionality:

3.1 UFS controller initialization
---------------------------------

  The initialization module brings the UFS host controller to active state
  and prepares the controller to transfer commands/responses between
  UFSHCD and UFS device.

3.2 UTP Transfer requests
-------------------------

  Transfer request handling module of UFSHCD receives SCSI commands
  from the SCSI Midlayer, forms UPIUs and issues the UPIUs to the UFS Host
  controller. Also, the module decodes responses received from the UFS
  host controller in the form of UPIUs and intimates the SCSI Midlayer
  of the status of the command.

3.3 UFS error handling
----------------------

  Error handling module handles Host controller fatal errors,
  Device fatal errors and UIC interconnect layer-related errors.

3.4 SCSI Error handling
-----------------------

  This is done through UFSHCD SCSI error handling routines registered
  with the SCSI Midlayer. Examples of some of the error handling commands
  issues by the SCSI Midlayer are Abort task, LUN reset and host reset.
  UFSHCD Routines to perform these tasks are registered with
  SCSI Midlayer through .eh_abort_handler, .eh_device_reset_handler and
  .eh_host_reset_handler.

In this version of UFSHCD, Query requests and power management
functionality are not implemented.

BSG UPIU 교환과 SG_IO

156-198

BSG transport driver는 UFS device와 UPIU를 교환한다. User space는 보통 `ufs_bsg.h`의 `struct ufs_bsg_request`와 `struct ufs_bsg_reply`를 각각 `request_upiu`, `reply_upiu`로 할당하고 JEDEC UFS 2.1 specification 10.7에 맞춰 채운다. Driver는 추가 input validation 없이 UPIU를 그대로 device에 보내므로 호출자가 정확성을 책임져야 한다.

`/dev/ufs-bsg`의 bsg device를 열고 적절한 `sg_io_v4`로 `SG_IO`를 보낸다. `guard='Q'`, protocol은 `BSG_PROTOCOL_SCSI`, subprotocol은 `BSG_SUB_PROTOCOL_SCSI_TRANSPORT`다. Request·response pointer와 길이를 채우고 direction이 `SG_DXFER_TO_DEV`이면 `dout_xfer_len`·`dout_xferp`, 아니면 `din_xfer_len`·`din_xferp`를 사용한다. Descriptor read·write에는 `sg_io_v4`의 적절한 `xferp`를 사용한다. 원문의 전체 C code를 보존한다.

UPIU protocol로 ufs-bsg endpoint를 사용하는 userspace tool은 `https://github.com/westerndigitalcorporation/ufs-tool`에 있고 자세한 기능은 README를 본다. UFS specification은 `JESD220.pdf`, UFSHCI는 `JESD223.pdf` 링크에서 확인한다.

sg_io_v4 핵심 field
Field값·역할
guard'Q'
protocolBSG_PROTOCOL_SCSI
subprotocolBSG_SUB_PROTOCOL_SCSI_TRANSPORT
request / responseUPIU pointer와 length
dout_*Host→device data
din_*Device→host data

UPIU request·reply와 data direction field를 구분한다.

4. BSG Support
==============

This transport driver supports exchanging UFS protocol information units
(UPIUs) with a UFS device. Typically, user space will allocate
struct ufs_bsg_request and struct ufs_bsg_reply (see ufs_bsg.h) as
request_upiu and reply_upiu respectively.  Filling those UPIUs should
be done in accordance with JEDEC spec UFS2.1 paragraph 10.7.
*Caveat emptor*: The driver makes no further input validations and sends the
UPIU to the device as it is.  Open the bsg device in /dev/ufs-bsg and
send SG_IO with the applicable sg_io_v4::

        io_hdr_v4.guard = 'Q';
        io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;
        io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
        io_hdr_v4.response = (__u64)reply_upiu;
        io_hdr_v4.max_response_len = reply_len;
        io_hdr_v4.request_len = request_len;
        io_hdr_v4.request = (__u64)request_upiu;
        if (dir == SG_DXFER_TO_DEV) {
                io_hdr_v4.dout_xfer_len = (uint32_t)byte_cnt;
                io_hdr_v4.dout_xferp = (uintptr_t)(__u64)buff;
        } else {
                io_hdr_v4.din_xfer_len = (uint32_t)byte_cnt;
                io_hdr_v4.din_xferp = (uintptr_t)(__u64)buff;
        }

If you wish to read or write a descriptor, use the appropriate xferp of
sg_io_v4.

The userspace tool that interacts with the ufs-bsg endpoint and uses its
UPIU-based protocol is available at:

        https://github.com/westerndigitalcorporation/ufs-tool

For more detailed information about the tool and its supported
features, please see the tool's README.

UFS specifications can be found at:

- UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
- UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf

Devicetree·ACPI reference clock 설정

199-210

Devicetree는 UFS controller node 아래 `ref_clk` clock으로 storage part의 의도한 reference clock frequency를 정의한다. ACPI system은 Device-Specific Data property `ref-clk-freq`로 지정한다. 두 값 모두 Hz로 해석하며 UFS specification의 허용값 중 하나와 일치해야 한다.

UFS subsystem은 common controller initialization 때 이 값을 읽는다. 값이 있으면 UFS storage device의 `bRefClkFreq` attribute가 맞는지 확인하고 불일치하면 수정한다.

Reference clock source
Firmware이름단위
Devicetreeref_clkHz
ACPI DSDref-clk-freqHz

Firmware interface별 property 이름은 다르지만 결과는 같다.

5. UFS Reference Clock Frequency configuration
==============================================

Devicetree can define a clock named "ref_clk" under the UFS controller node
to specify the intended reference clock frequency for the UFS storage
parts. ACPI-based system can specify the frequency using ACPI
Device-Specific Data property named "ref-clk-freq". In both ways the value
is interpreted as frequency in Hz and must match one of the values given in
the UFS specification. UFS subsystem will attempt to read the value when
executing common controller initialization. If the value is available, UFS
subsystem will ensure the bRefClkFreq attribute of the UFS storage device is
set accordingly and will modify it if there is a mismatch.