Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 =======================
0004 Universal Flash Storage
0005 =======================
0006 
0007 
0008 .. Contents
0009 
0010    1. Overview
0011    2. UFS Architecture Overview
0012      2.1 Application Layer
0013      2.2 UFS Transport Protocol (UTP) layer
0014      2.3 UFS Interconnect (UIC) Layer
0015    3. UFSHCD Overview
0016      3.1 UFS controller initialization
0017      3.2 UTP Transfer requests
0018      3.3 UFS error handling
0019      3.4 SCSI Error handling
0020    4. BSG Support
0021    5. UFS Reference Clock Frequency configuration
0022 
0023 
0024 1. Overview
0025 ===========
0026 
0027 Universal Flash Storage (UFS) is a storage specification for flash devices.
0028 It aims to provide a universal storage interface for both
0029 embedded and removable flash memory-based storage in mobile
0030 devices such as smart phones and tablet computers. The specification
0031 is defined by JEDEC Solid State Technology Association. UFS is based
0032 on the MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
0033 physical layer and MIPI Unipro as the link layer.
0034 
0035 The main goals of UFS are to provide:
0036 
0037  * Optimized performance:
0038 
0039    For UFS version 1.0 and 1.1 the target performance is as follows:
0040 
0041    - Support for Gear1 is mandatory (rate A: 1248Mbps, rate B: 1457.6Mbps)
0042    - Support for Gear2 is optional (rate A: 2496Mbps, rate B: 2915.2Mbps)
0043 
0044    Future version of the standard,
0045 
0046    - Gear3 (rate A: 4992Mbps, rate B: 5830.4Mbps)
0047 
0048  * Low power consumption
0049  * High random IOPs and low latency
0050 
0051 
0052 2. UFS Architecture Overview
0053 ============================
0054 
0055 UFS has a layered communication architecture which is based on SCSI
0056 SAM-5 architectural model.
0057 
0058 UFS communication architecture consists of the following layers.
0059 
0060 2.1 Application Layer
0061 ---------------------
0062 
0063   The Application layer is composed of the UFS command set layer (UCS),
0064   Task Manager and Device manager. The UFS interface is designed to be
0065   protocol agnostic, however SCSI has been selected as a baseline
0066   protocol for versions 1.0 and 1.1 of the UFS protocol layer.
0067 
0068   UFS supports a subset of SCSI commands defined by SPC-4 and SBC-3.
0069 
0070   * UCS:
0071      It handles SCSI commands supported by UFS specification.
0072   * Task manager:
0073      It handles task management functions defined by the
0074      UFS which are meant for command queue control.
0075   * Device manager:
0076      It handles device level operations and device
0077      configuration operations. Device level operations mainly involve
0078      device power management operations and commands to Interconnect
0079      layers. Device level configurations involve handling of query
0080      requests which are used to modify and retrieve configuration
0081      information of the device.
0082 
0083 2.2 UFS Transport Protocol (UTP) layer
0084 --------------------------------------
0085 
0086   The UTP layer provides services for
0087   the higher layers through Service Access Points. UTP defines 3
0088   service access points for higher layers.
0089 
0090   * UDM_SAP: Device manager service access point is exposed to device
0091     manager for device level operations. These device level operations
0092     are done through query requests.
0093   * UTP_CMD_SAP: Command service access point is exposed to UFS command
0094     set layer (UCS) to transport commands.
0095   * UTP_TM_SAP: Task management service access point is exposed to task
0096     manager to transport task management functions.
0097 
0098   UTP transports messages through UFS protocol information unit (UPIU).
0099 
0100 2.3 UFS Interconnect (UIC) Layer
0101 --------------------------------
0102 
0103   UIC is the lowest layer of the UFS layered architecture. It handles
0104   the connection between UFS host and UFS device. UIC consists of
0105   MIPI UniPro and MIPI M-PHY. UIC provides 2 service access points
0106   to upper layer:
0107 
0108   * UIC_SAP: To transport UPIU between UFS host and UFS device.
0109   * UIO_SAP: To issue commands to Unipro layers.
0110 
0111 
0112 3. UFSHCD Overview
0113 ==================
0114 
0115 The UFS host controller driver is based on the Linux SCSI Framework.
0116 UFSHCD is a low-level device driver which acts as an interface between
0117 the SCSI Midlayer and PCIe-based UFS host controllers.
0118 
0119 The current UFSHCD implementation supports the following functionality:
0120 
0121 3.1 UFS controller initialization
0122 ---------------------------------
0123 
0124   The initialization module brings the UFS host controller to active state
0125   and prepares the controller to transfer commands/responses between
0126   UFSHCD and UFS device.
0127 
0128 3.2 UTP Transfer requests
0129 -------------------------
0130 
0131   Transfer request handling module of UFSHCD receives SCSI commands
0132   from the SCSI Midlayer, forms UPIUs and issues the UPIUs to the UFS Host
0133   controller. Also, the module decodes responses received from the UFS
0134   host controller in the form of UPIUs and intimates the SCSI Midlayer
0135   of the status of the command.
0136 
0137 3.3 UFS error handling
0138 ----------------------
0139 
0140   Error handling module handles Host controller fatal errors,
0141   Device fatal errors and UIC interconnect layer-related errors.
0142 
0143 3.4 SCSI Error handling
0144 -----------------------
0145 
0146   This is done through UFSHCD SCSI error handling routines registered
0147   with the SCSI Midlayer. Examples of some of the error handling commands
0148   issues by the SCSI Midlayer are Abort task, LUN reset and host reset.
0149   UFSHCD Routines to perform these tasks are registered with
0150   SCSI Midlayer through .eh_abort_handler, .eh_device_reset_handler and
0151   .eh_host_reset_handler.
0152 
0153 In this version of UFSHCD, Query requests and power management
0154 functionality are not implemented.
0155 
0156 4. BSG Support
0157 ==============
0158 
0159 This transport driver supports exchanging UFS protocol information units
0160 (UPIUs) with a UFS device. Typically, user space will allocate
0161 struct ufs_bsg_request and struct ufs_bsg_reply (see ufs_bsg.h) as
0162 request_upiu and reply_upiu respectively.  Filling those UPIUs should
0163 be done in accordance with JEDEC spec UFS2.1 paragraph 10.7.
0164 *Caveat emptor*: The driver makes no further input validations and sends the
0165 UPIU to the device as it is.  Open the bsg device in /dev/ufs-bsg and
0166 send SG_IO with the applicable sg_io_v4::
0167 
0168         io_hdr_v4.guard = 'Q';
0169         io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;
0170         io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
0171         io_hdr_v4.response = (__u64)reply_upiu;
0172         io_hdr_v4.max_response_len = reply_len;
0173         io_hdr_v4.request_len = request_len;
0174         io_hdr_v4.request = (__u64)request_upiu;
0175         if (dir == SG_DXFER_TO_DEV) {
0176                 io_hdr_v4.dout_xfer_len = (uint32_t)byte_cnt;
0177                 io_hdr_v4.dout_xferp = (uintptr_t)(__u64)buff;
0178         } else {
0179                 io_hdr_v4.din_xfer_len = (uint32_t)byte_cnt;
0180                 io_hdr_v4.din_xferp = (uintptr_t)(__u64)buff;
0181         }
0182 
0183 If you wish to read or write a descriptor, use the appropriate xferp of
0184 sg_io_v4.
0185 
0186 The userspace tool that interacts with the ufs-bsg endpoint and uses its
0187 UPIU-based protocol is available at:
0188 
0189         https://github.com/westerndigitalcorporation/ufs-tool
0190 
0191 For more detailed information about the tool and its supported
0192 features, please see the tool's README.
0193 
0194 UFS specifications can be found at:
0195 
0196 - UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
0197 - UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf
0198 
0199 5. UFS Reference Clock Frequency configuration
0200 ==============================================
0201 
0202 Devicetree can define a clock named "ref_clk" under the UFS controller node
0203 to specify the intended reference clock frequency for the UFS storage
0204 parts. ACPI-based system can specify the frequency using ACPI
0205 Device-Specific Data property named "ref-clk-freq". In both ways the value
0206 is interpreted as frequency in Hz and must match one of the values given in
0207 the UFS specification. UFS subsystem will attempt to read the value when
0208 executing common controller initialization. If the value is available, UFS
0209 subsytem will ensure the bRefClkFreq attribute of the UFS storage device is
0210 set accordingly and will modify it if there is a mismatch.