1 .. SPDX-License-Identifier: GPL-2.0
3 =======================
4 Universal Flash Storage
5 =======================
11 2. UFS Architecture Overview
13 2.2 UFS Transport Protocol(UTP) layer
14 2.3 UFS Interconnect(UIC) Layer
16 3.1 UFS controller initialization
17 3.2 UTP Transfer requests
18 3.3 UFS error handling
19 3.4 SCSI Error handling
25 Universal Flash Storage(UFS) is a storage specification for flash devices.
26 It is aimed to provide a universal storage interface for both
27 embedded and removable flash memory based storage in mobile
28 devices such as smart phones and tablet computers. The specification
29 is defined by JEDEC Solid State Technology Association. UFS is based
30 on MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
31 physical layer and MIPI Unipro as the link layer.
33 The main goals of UFS is to provide:
35 * Optimized performance:
37 For UFS version 1.0 and 1.1 the target performance is as follows:
39 - Support for Gear1 is mandatory (rate A: 1248Mbps, rate B: 1457.6Mbps)
40 - Support for Gear2 is optional (rate A: 2496Mbps, rate B: 2915.2Mbps)
42 Future version of the standard,
44 - Gear3 (rate A: 4992Mbps, rate B: 5830.4Mbps)
46 * Low power consumption
47 * High random IOPs and low latency
50 2. UFS Architecture Overview
51 ============================
53 UFS has a layered communication architecture which is based on SCSI
54 SAM-5 architectural model.
56 UFS communication architecture consists of following layers,
61 The Application layer is composed of UFS command set layer(UCS),
62 Task Manager and Device manager. The UFS interface is designed to be
63 protocol agnostic, however SCSI has been selected as a baseline
64 protocol for versions 1.0 and 1.1 of UFS protocol layer.
66 UFS supports subset of SCSI commands defined by SPC-4 and SBC-3.
69 It handles SCSI commands supported by UFS specification.
71 It handles task management functions defined by the
72 UFS which are meant for command queue control.
74 It handles device level operations and device
75 configuration operations. Device level operations mainly involve
76 device power management operations and commands to Interconnect
77 layers. Device level configurations involve handling of query
78 requests which are used to modify and retrieve configuration
79 information of the device.
81 2.2 UFS Transport Protocol(UTP) layer
82 -------------------------------------
84 UTP layer provides services for
85 the higher layers through Service Access Points. UTP defines 3
86 service access points for higher layers.
88 * UDM_SAP: Device manager service access point is exposed to device
89 manager for device level operations. These device level operations
90 are done through query requests.
91 * UTP_CMD_SAP: Command service access point is exposed to UFS command
92 set layer(UCS) to transport commands.
93 * UTP_TM_SAP: Task management service access point is exposed to task
94 manager to transport task management functions.
96 UTP transports messages through UFS protocol information unit(UPIU).
98 2.3 UFS Interconnect(UIC) Layer
99 -------------------------------
101 UIC is the lowest layer of UFS layered architecture. It handles
102 connection between UFS host and UFS device. UIC consists of
103 MIPI UniPro and MIPI M-PHY. UIC provides 2 service access points
106 * UIC_SAP: To transport UPIU between UFS host and UFS device.
107 * UIO_SAP: To issue commands to Unipro layers.
113 The UFS host controller driver is based on Linux SCSI Framework.
114 UFSHCD is a low level device driver which acts as an interface between
115 SCSI Midlayer and PCIe based UFS host controllers.
117 The current UFSHCD implementation supports following functionality,
119 3.1 UFS controller initialization
120 ---------------------------------
122 The initialization module brings UFS host controller to active state
123 and prepares the controller to transfer commands/response between
124 UFSHCD and UFS device.
126 3.2 UTP Transfer requests
127 -------------------------
129 Transfer request handling module of UFSHCD receives SCSI commands
130 from SCSI Midlayer, forms UPIUs and issues the UPIUs to UFS Host
131 controller. Also, the module decodes, responses received from UFS
132 host controller in the form of UPIUs and intimates the SCSI Midlayer
133 of the status of the command.
135 3.3 UFS error handling
136 ----------------------
138 Error handling module handles Host controller fatal errors,
139 Device fatal errors and UIC interconnect layer related errors.
141 3.4 SCSI Error handling
142 -----------------------
144 This is done through UFSHCD SCSI error handling routines registered
145 with SCSI Midlayer. Examples of some of the error handling commands
146 issues by SCSI Midlayer are Abort task, Lun reset and host reset.
147 UFSHCD Routines to perform these tasks are registered with
148 SCSI Midlayer through .eh_abort_handler, .eh_device_reset_handler and
149 .eh_host_reset_handler.
151 In this version of UFSHCD Query requests and power management
152 functionality are not implemented.
157 This transport driver supports exchanging UFS protocol information units
158 (UPIUs) with a UFS device. Typically, user space will allocate
159 struct ufs_bsg_request and struct ufs_bsg_reply (see ufs_bsg.h) as
160 request_upiu and reply_upiu respectively. Filling those UPIUs should
161 be done in accordance with JEDEC spec UFS2.1 paragraph 10.7.
162 *Caveat emptor*: The driver makes no further input validations and sends the
163 UPIU to the device as it is. Open the bsg device in /dev/ufs-bsg and
164 send SG_IO with the applicable sg_io_v4::
166 io_hdr_v4.guard = 'Q';
167 io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;
168 io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
169 io_hdr_v4.response = (__u64)reply_upiu;
170 io_hdr_v4.max_response_len = reply_len;
171 io_hdr_v4.request_len = request_len;
172 io_hdr_v4.request = (__u64)request_upiu;
173 if (dir == SG_DXFER_TO_DEV) {
174 io_hdr_v4.dout_xfer_len = (uint32_t)byte_cnt;
175 io_hdr_v4.dout_xferp = (uintptr_t)(__u64)buff;
177 io_hdr_v4.din_xfer_len = (uint32_t)byte_cnt;
178 io_hdr_v4.din_xferp = (uintptr_t)(__u64)buff;
181 If you wish to read or write a descriptor, use the appropriate xferp of
184 The userspace tool that interacts with the ufs-bsg endpoint and uses its
185 upiu-based protocol is available at:
187 https://github.com/westerndigitalcorporation/ufs-tool
189 For more detailed information about the tool and its supported
190 features, please see the tool's README.
192 UFS Specifications can be found at:
194 - UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
195 - UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf