요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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
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
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.
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.
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.
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
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.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
문서 범위
1-23GPL-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-51Universal 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다.
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-82UFS는 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를 처리한다.
세 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-111UFS 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를 발행한다.
Application request가 UTP와 UIC를 거쳐 device로 이동한다.
상위 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-155UFS 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가 구현되지 않았다.
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-198BSG 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` 링크에서 확인한다.
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-210Devicetree는 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가 맞는지 확인하고 불일치하면 수정한다.
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.
요약·해설
ufs.rst:1-210UFS의 M-PHY·UniPro 계층, UFSHCD request·error path, BSG UPIU와 reference clock 설정을 설명합니다.