ufs.rst 7.5 KB

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