xref: /openbmc/linux/Documentation/scsi/ufs.rst (revision e6e8c6c2)
1.. SPDX-License-Identifier: GPL-2.0
2
3=======================
4Universal 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
241. Overview
25===========
26
27Universal Flash Storage (UFS) is a storage specification for flash devices.
28It aims to provide a universal storage interface for both
29embedded and removable flash memory-based storage in mobile
30devices such as smart phones and tablet computers. The specification
31is defined by JEDEC Solid State Technology Association. UFS is based
32on the MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
33physical layer and MIPI Unipro as the link layer.
34
35The 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
522. UFS Architecture Overview
53============================
54
55UFS has a layered communication architecture which is based on SCSI
56SAM-5 architectural model.
57
58UFS communication architecture consists of the following layers.
59
602.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
832.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
1002.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
1123. UFSHCD Overview
113==================
114
115The UFS host controller driver is based on the Linux SCSI Framework.
116UFSHCD is a low-level device driver which acts as an interface between
117the SCSI Midlayer and PCIe-based UFS host controllers.
118
119The current UFSHCD implementation supports the following functionality:
120
1213.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
1283.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
1373.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
1433.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
153In this version of UFSHCD, Query requests and power management
154functionality are not implemented.
155
1564. BSG Support
157==============
158
159This transport driver supports exchanging UFS protocol information units
160(UPIUs) with a UFS device. Typically, user space will allocate
161struct ufs_bsg_request and struct ufs_bsg_reply (see ufs_bsg.h) as
162request_upiu and reply_upiu respectively.  Filling those UPIUs should
163be done in accordance with JEDEC spec UFS2.1 paragraph 10.7.
164*Caveat emptor*: The driver makes no further input validations and sends the
165UPIU to the device as it is.  Open the bsg device in /dev/ufs-bsg and
166send 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
183If you wish to read or write a descriptor, use the appropriate xferp of
184sg_io_v4.
185
186The userspace tool that interacts with the ufs-bsg endpoint and uses its
187UPIU-based protocol is available at:
188
189	https://github.com/westerndigitalcorporation/ufs-tool
190
191For more detailed information about the tool and its supported
192features, please see the tool's README.
193
194UFS 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
1995. UFS Reference Clock Frequency configuration
200==============================================
201
202Devicetree can define a clock named "ref_clk" under the UFS controller node
203to specify the intended reference clock frequency for the UFS storage
204parts. ACPI-based system can specify the frequency using ACPI
205Device-Specific Data property named "ref-clk-freq". In both ways the value
206is interpreted as frequency in Hz and must match one of the values given in
207the UFS specification. UFS subsystem will attempt to read the value when
208executing common controller initialization. If the value is available, UFS
209subsytem will ensure the bRefClkFreq attribute of the UFS storage device is
210set accordingly and will modify it if there is a mismatch.
211