2020-03-02 16:16:13 +08:00
|
|
|
.. SPDX-License-Identifier: GPL-2.0
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2020-03-02 16:16:13 +08:00
|
|
|
=======================
|
|
|
|
Universal Flash Storage
|
|
|
|
=======================
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
|
2020-03-02 16:16:13 +08:00
|
|
|
.. Contents
|
|
|
|
|
|
|
|
1. Overview
|
|
|
|
2. UFS Architecture Overview
|
|
|
|
2.1 Application Layer
|
2022-03-07 09:32:24 +08:00
|
|
|
2.2 UFS Transport Protocol (UTP) layer
|
|
|
|
2.3 UFS Interconnect (UIC) Layer
|
2020-03-02 16:16:13 +08:00
|
|
|
3. UFSHCD Overview
|
|
|
|
3.1 UFS controller initialization
|
|
|
|
3.2 UTP Transfer requests
|
|
|
|
3.3 UFS error handling
|
|
|
|
3.4 SCSI Error handling
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
1. Overview
|
2020-03-02 16:16:13 +08:00
|
|
|
===========
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
Universal Flash Storage (UFS) is a storage specification for flash devices.
|
|
|
|
It aims to provide a universal storage interface for both
|
|
|
|
embedded and removable flash memory-based storage in mobile
|
2012-02-29 14:41:50 +08:00
|
|
|
devices such as smart phones and tablet computers. The specification
|
|
|
|
is defined by JEDEC Solid State Technology Association. UFS is based
|
2022-03-07 09:32:24 +08:00
|
|
|
on the MIPI M-PHY physical layer standard. UFS uses MIPI M-PHY as the
|
2012-02-29 14:41:50 +08:00
|
|
|
physical layer and MIPI Unipro as the link layer.
|
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
The main goals of UFS are to provide:
|
2020-03-02 16:16:13 +08:00
|
|
|
|
2012-02-29 14:41:50 +08:00
|
|
|
* Optimized performance:
|
2020-03-02 16:16:13 +08:00
|
|
|
|
|
|
|
For UFS version 1.0 and 1.1 the target performance is as follows:
|
|
|
|
|
|
|
|
- Support for Gear1 is mandatory (rate A: 1248Mbps, rate B: 1457.6Mbps)
|
|
|
|
- Support for Gear2 is optional (rate A: 2496Mbps, rate B: 2915.2Mbps)
|
|
|
|
|
2012-02-29 14:41:50 +08:00
|
|
|
Future version of the standard,
|
2020-03-02 16:16:13 +08:00
|
|
|
|
|
|
|
- Gear3 (rate A: 4992Mbps, rate B: 5830.4Mbps)
|
|
|
|
|
2012-02-29 14:41:50 +08:00
|
|
|
* Low power consumption
|
|
|
|
* High random IOPs and low latency
|
|
|
|
|
|
|
|
|
|
|
|
2. UFS Architecture Overview
|
2020-03-02 16:16:13 +08:00
|
|
|
============================
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
UFS has a layered communication architecture which is based on SCSI
|
|
|
|
SAM-5 architectural model.
|
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
UFS communication architecture consists of the following layers.
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
2.1 Application Layer
|
2020-03-02 16:16:13 +08:00
|
|
|
---------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
The Application layer is composed of the UFS command set layer (UCS),
|
2012-02-29 14:41:50 +08:00
|
|
|
Task Manager and Device manager. The UFS interface is designed to be
|
|
|
|
protocol agnostic, however SCSI has been selected as a baseline
|
2022-03-07 09:32:24 +08:00
|
|
|
protocol for versions 1.0 and 1.1 of the UFS protocol layer.
|
2020-03-02 16:16:13 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
UFS supports a subset of SCSI commands defined by SPC-4 and SBC-3.
|
2020-03-02 16:16:13 +08:00
|
|
|
|
|
|
|
* UCS:
|
|
|
|
It handles SCSI commands supported by UFS specification.
|
|
|
|
* Task manager:
|
|
|
|
It handles task management functions defined by the
|
2012-02-29 14:41:50 +08:00
|
|
|
UFS which are meant for command queue control.
|
2020-03-02 16:16:13 +08:00
|
|
|
* Device manager:
|
|
|
|
It handles device level operations and device
|
2012-02-29 14:41:50 +08:00
|
|
|
configuration operations. Device level operations mainly involve
|
|
|
|
device power management operations and commands to Interconnect
|
|
|
|
layers. Device level configurations involve handling of query
|
|
|
|
requests which are used to modify and retrieve configuration
|
|
|
|
information of the device.
|
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
2.2 UFS Transport Protocol (UTP) layer
|
|
|
|
--------------------------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
The UTP layer provides services for
|
2012-02-29 14:41:50 +08:00
|
|
|
the higher layers through Service Access Points. UTP defines 3
|
|
|
|
service access points for higher layers.
|
2020-03-02 16:16:13 +08:00
|
|
|
|
2012-02-29 14:41:50 +08:00
|
|
|
* UDM_SAP: Device manager service access point is exposed to device
|
|
|
|
manager for device level operations. These device level operations
|
|
|
|
are done through query requests.
|
|
|
|
* UTP_CMD_SAP: Command service access point is exposed to UFS command
|
2022-03-07 09:32:24 +08:00
|
|
|
set layer (UCS) to transport commands.
|
2012-02-29 14:41:50 +08:00
|
|
|
* UTP_TM_SAP: Task management service access point is exposed to task
|
|
|
|
manager to transport task management functions.
|
2020-03-02 16:16:13 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
UTP transports messages through UFS protocol information unit (UPIU).
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
2.3 UFS Interconnect (UIC) Layer
|
|
|
|
--------------------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
UIC is the lowest layer of the UFS layered architecture. It handles
|
|
|
|
the connection between UFS host and UFS device. UIC consists of
|
2012-02-29 14:41:50 +08:00
|
|
|
MIPI UniPro and MIPI M-PHY. UIC provides 2 service access points
|
2022-03-07 09:32:24 +08:00
|
|
|
to upper layer:
|
2020-03-02 16:16:13 +08:00
|
|
|
|
2012-02-29 14:41:50 +08:00
|
|
|
* UIC_SAP: To transport UPIU between UFS host and UFS device.
|
|
|
|
* UIO_SAP: To issue commands to Unipro layers.
|
|
|
|
|
|
|
|
|
|
|
|
3. UFSHCD Overview
|
2020-03-02 16:16:13 +08:00
|
|
|
==================
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
The UFS host controller driver is based on the Linux SCSI Framework.
|
|
|
|
UFSHCD is a low-level device driver which acts as an interface between
|
|
|
|
the SCSI Midlayer and PCIe-based UFS host controllers.
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
The current UFSHCD implementation supports the following functionality:
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
3.1 UFS controller initialization
|
2020-03-02 16:16:13 +08:00
|
|
|
---------------------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
The initialization module brings the UFS host controller to active state
|
|
|
|
and prepares the controller to transfer commands/responses between
|
2012-02-29 14:41:50 +08:00
|
|
|
UFSHCD and UFS device.
|
|
|
|
|
|
|
|
3.2 UTP Transfer requests
|
2020-03-02 16:16:13 +08:00
|
|
|
-------------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
Transfer request handling module of UFSHCD receives SCSI commands
|
2022-03-07 09:32:24 +08:00
|
|
|
from the SCSI Midlayer, forms UPIUs and issues the UPIUs to the UFS Host
|
|
|
|
controller. Also, the module decodes responses received from the UFS
|
2012-02-29 14:41:50 +08:00
|
|
|
host controller in the form of UPIUs and intimates the SCSI Midlayer
|
|
|
|
of the status of the command.
|
|
|
|
|
|
|
|
3.3 UFS error handling
|
2020-03-02 16:16:13 +08:00
|
|
|
----------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
Error handling module handles Host controller fatal errors,
|
2022-03-07 09:32:24 +08:00
|
|
|
Device fatal errors and UIC interconnect layer-related errors.
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
3.4 SCSI Error handling
|
2020-03-02 16:16:13 +08:00
|
|
|
-----------------------
|
2012-02-29 14:41:50 +08:00
|
|
|
|
|
|
|
This is done through UFSHCD SCSI error handling routines registered
|
2022-03-07 09:32:24 +08:00
|
|
|
with the SCSI Midlayer. Examples of some of the error handling commands
|
|
|
|
issues by the SCSI Midlayer are Abort task, LUN reset and host reset.
|
2012-02-29 14:41:50 +08:00
|
|
|
UFSHCD Routines to perform these tasks are registered with
|
|
|
|
SCSI Midlayer through .eh_abort_handler, .eh_device_reset_handler and
|
|
|
|
.eh_host_reset_handler.
|
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
In this version of UFSHCD, Query requests and power management
|
2012-02-29 14:41:50 +08:00
|
|
|
functionality are not implemented.
|
|
|
|
|
scsi: ufs: Add a bsg endpoint that supports UPIUs
For now, just provide an API to allocate and remove ufs-bsg node. We
will use this framework to manage ufs devices by sending UPIU
transactions.
For the time being, implements an empty bsg_request() - will add some
more functionality in coming patches.
Nonetheless, we reveal here the protocol we are planning to use: UFS
Transport Protocol Transactions. UFS transactions consist of packets
called UFS Protocol Information Units (UPIU).
There are UPIU’s defined for UFS SCSI commands, responses, data in and
data out, task management, utility functions, vendor functions,
transaction synchronization and control, and more.
By using UPIUs, we get access to the most fine-grained internals of this
protocol, and able to communicate with the device in ways, that are
sometimes beyond the capacity of the ufs driver.
Moreover and as a result, our core structure - ufs_bsg_node has a pretty
lean structure: using upiu transactions that contains the outmost
detailed info, so we don't really need complex constructs to support it.
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <Bart.VanAssche@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2018-10-07 22:30:35 +08:00
|
|
|
4. BSG Support
|
2020-03-02 16:16:13 +08:00
|
|
|
==============
|
scsi: ufs: Add a bsg endpoint that supports UPIUs
For now, just provide an API to allocate and remove ufs-bsg node. We
will use this framework to manage ufs devices by sending UPIU
transactions.
For the time being, implements an empty bsg_request() - will add some
more functionality in coming patches.
Nonetheless, we reveal here the protocol we are planning to use: UFS
Transport Protocol Transactions. UFS transactions consist of packets
called UFS Protocol Information Units (UPIU).
There are UPIU’s defined for UFS SCSI commands, responses, data in and
data out, task management, utility functions, vendor functions,
transaction synchronization and control, and more.
By using UPIUs, we get access to the most fine-grained internals of this
protocol, and able to communicate with the device in ways, that are
sometimes beyond the capacity of the ufs driver.
Moreover and as a result, our core structure - ufs_bsg_node has a pretty
lean structure: using upiu transactions that contains the outmost
detailed info, so we don't really need complex constructs to support it.
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <Bart.VanAssche@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2018-10-07 22:30:35 +08:00
|
|
|
|
|
|
|
This transport driver supports exchanging UFS protocol information units
|
|
|
|
(UPIUs) with a UFS device. Typically, user space will allocate
|
|
|
|
struct ufs_bsg_request and struct ufs_bsg_reply (see ufs_bsg.h) as
|
|
|
|
request_upiu and reply_upiu respectively. Filling those UPIUs should
|
|
|
|
be done in accordance with JEDEC spec UFS2.1 paragraph 10.7.
|
|
|
|
*Caveat emptor*: The driver makes no further input validations and sends the
|
|
|
|
UPIU to the device as it is. Open the bsg device in /dev/ufs-bsg and
|
2020-03-02 16:16:13 +08:00
|
|
|
send SG_IO with the applicable sg_io_v4::
|
scsi: ufs: Add a bsg endpoint that supports UPIUs
For now, just provide an API to allocate and remove ufs-bsg node. We
will use this framework to manage ufs devices by sending UPIU
transactions.
For the time being, implements an empty bsg_request() - will add some
more functionality in coming patches.
Nonetheless, we reveal here the protocol we are planning to use: UFS
Transport Protocol Transactions. UFS transactions consist of packets
called UFS Protocol Information Units (UPIU).
There are UPIU’s defined for UFS SCSI commands, responses, data in and
data out, task management, utility functions, vendor functions,
transaction synchronization and control, and more.
By using UPIUs, we get access to the most fine-grained internals of this
protocol, and able to communicate with the device in ways, that are
sometimes beyond the capacity of the ufs driver.
Moreover and as a result, our core structure - ufs_bsg_node has a pretty
lean structure: using upiu transactions that contains the outmost
detailed info, so we don't really need complex constructs to support it.
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <Bart.VanAssche@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2018-10-07 22:30:35 +08:00
|
|
|
|
|
|
|
io_hdr_v4.guard = 'Q';
|
|
|
|
io_hdr_v4.protocol = BSG_PROTOCOL_SCSI;
|
|
|
|
io_hdr_v4.subprotocol = BSG_SUB_PROTOCOL_SCSI_TRANSPORT;
|
|
|
|
io_hdr_v4.response = (__u64)reply_upiu;
|
|
|
|
io_hdr_v4.max_response_len = reply_len;
|
|
|
|
io_hdr_v4.request_len = request_len;
|
|
|
|
io_hdr_v4.request = (__u64)request_upiu;
|
2019-02-20 15:11:12 +08:00
|
|
|
if (dir == SG_DXFER_TO_DEV) {
|
|
|
|
io_hdr_v4.dout_xfer_len = (uint32_t)byte_cnt;
|
|
|
|
io_hdr_v4.dout_xferp = (uintptr_t)(__u64)buff;
|
2019-02-20 15:11:14 +08:00
|
|
|
} else {
|
|
|
|
io_hdr_v4.din_xfer_len = (uint32_t)byte_cnt;
|
|
|
|
io_hdr_v4.din_xferp = (uintptr_t)(__u64)buff;
|
2019-02-20 15:11:12 +08:00
|
|
|
}
|
|
|
|
|
2019-02-20 15:11:14 +08:00
|
|
|
If you wish to read or write a descriptor, use the appropriate xferp of
|
|
|
|
sg_io_v4.
|
|
|
|
|
2019-06-25 20:36:00 +08:00
|
|
|
The userspace tool that interacts with the ufs-bsg endpoint and uses its
|
2022-03-07 09:32:24 +08:00
|
|
|
UPIU-based protocol is available at:
|
2019-06-25 20:36:00 +08:00
|
|
|
|
|
|
|
https://github.com/westerndigitalcorporation/ufs-tool
|
|
|
|
|
|
|
|
For more detailed information about the tool and its supported
|
|
|
|
features, please see the tool's README.
|
scsi: ufs: Add a bsg endpoint that supports UPIUs
For now, just provide an API to allocate and remove ufs-bsg node. We
will use this framework to manage ufs devices by sending UPIU
transactions.
For the time being, implements an empty bsg_request() - will add some
more functionality in coming patches.
Nonetheless, we reveal here the protocol we are planning to use: UFS
Transport Protocol Transactions. UFS transactions consist of packets
called UFS Protocol Information Units (UPIU).
There are UPIU’s defined for UFS SCSI commands, responses, data in and
data out, task management, utility functions, vendor functions,
transaction synchronization and control, and more.
By using UPIUs, we get access to the most fine-grained internals of this
protocol, and able to communicate with the device in ways, that are
sometimes beyond the capacity of the ufs driver.
Moreover and as a result, our core structure - ufs_bsg_node has a pretty
lean structure: using upiu transactions that contains the outmost
detailed info, so we don't really need complex constructs to support it.
Signed-off-by: Avri Altman <avri.altman@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <Bart.VanAssche@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2018-10-07 22:30:35 +08:00
|
|
|
|
2022-03-07 09:32:24 +08:00
|
|
|
UFS specifications can be found at:
|
2020-03-02 16:16:13 +08:00
|
|
|
|
|
|
|
- UFS - http://www.jedec.org/sites/default/files/docs/JESD220.pdf
|
|
|
|
- UFSHCI - http://www.jedec.org/sites/default/files/docs/JESD223.pdf
|