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