2019-07-25 07:58:31 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
2018-10-07 14:30:34 +00:00
|
|
|
/*
|
|
|
|
* UFS Transport SGIO v4 BSG Message Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2013 Samsung India Software Operations
|
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 14:30:35 +00:00
|
|
|
* Copyright (C) 2018 Western Digital Corporation
|
2018-10-07 14:30:34 +00:00
|
|
|
*/
|
|
|
|
#ifndef SCSI_BSG_UFS_H
|
|
|
|
#define SCSI_BSG_UFS_H
|
|
|
|
|
2023-07-27 19:41:24 +00:00
|
|
|
#include <asm/byteorder.h>
|
2018-10-12 10:41:28 +00:00
|
|
|
#include <linux/types.h>
|
2018-10-07 14:30:34 +00:00
|
|
|
/*
|
|
|
|
* This file intended to be included by both kernel and user space
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define UFS_CDB_SIZE 16
|
2018-10-07 14:30:39 +00:00
|
|
|
/* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
|
2018-10-12 10:41:28 +00:00
|
|
|
#define UIC_CMD_SIZE (sizeof(__u32) * 4)
|
2018-10-07 14:30:34 +00:00
|
|
|
|
2022-12-01 14:04:37 +00:00
|
|
|
enum ufs_bsg_msg_code {
|
|
|
|
UPIU_TRANSACTION_UIC_CMD = 0x1F,
|
|
|
|
UPIU_TRANSACTION_ARPMB_CMD,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* UFS RPMB Request Message Types */
|
|
|
|
enum ufs_rpmb_op_type {
|
|
|
|
UFS_RPMB_WRITE_KEY = 0x01,
|
|
|
|
UFS_RPMB_READ_CNT = 0x02,
|
|
|
|
UFS_RPMB_WRITE = 0x03,
|
|
|
|
UFS_RPMB_READ = 0x04,
|
|
|
|
UFS_RPMB_READ_RESP = 0x05,
|
|
|
|
UFS_RPMB_SEC_CONF_WRITE = 0x06,
|
|
|
|
UFS_RPMB_SEC_CONF_READ = 0x07,
|
|
|
|
UFS_RPMB_PURGE_ENABLE = 0x08,
|
|
|
|
UFS_RPMB_PURGE_STATUS_READ = 0x09,
|
|
|
|
};
|
|
|
|
|
2018-10-07 14:30:34 +00:00
|
|
|
/**
|
|
|
|
* struct utp_upiu_header - UPIU header structure
|
|
|
|
* @dword_0: UPIU header DW-0
|
|
|
|
* @dword_1: UPIU header DW-1
|
|
|
|
* @dword_2: UPIU header DW-2
|
2023-07-27 19:41:24 +00:00
|
|
|
*
|
|
|
|
* @transaction_code: Type of request or response. See also enum
|
|
|
|
* upiu_request_transaction and enum upiu_response_transaction.
|
|
|
|
* @flags: UPIU flags. The meaning of individual flags depends on the
|
|
|
|
* transaction code.
|
|
|
|
* @lun: Logical unit number.
|
|
|
|
* @task_tag: Task tag.
|
|
|
|
* @iid: Initiator ID.
|
|
|
|
* @command_set_type: 0 for SCSI command set; 1 for UFS specific.
|
|
|
|
* @tm_function: Task management function in case of a task management request
|
|
|
|
* UPIU.
|
|
|
|
* @query_function: Query function in case of a query request UPIU.
|
|
|
|
* @response: 0 for success; 1 for failure.
|
|
|
|
* @status: SCSI status if this is the header of a response to a SCSI command.
|
|
|
|
* @ehs_length: EHS length in units of 32 bytes.
|
|
|
|
* @device_information:
|
|
|
|
* @data_segment_length: data segment length.
|
2018-10-07 14:30:34 +00:00
|
|
|
*/
|
|
|
|
struct utp_upiu_header {
|
2023-07-27 19:41:24 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
__be32 dword_0;
|
|
|
|
__be32 dword_1;
|
|
|
|
__be32 dword_2;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
__u8 transaction_code;
|
|
|
|
__u8 flags;
|
|
|
|
__u8 lun;
|
|
|
|
__u8 task_tag;
|
|
|
|
#if defined(__BIG_ENDIAN)
|
|
|
|
__u8 iid: 4;
|
|
|
|
__u8 command_set_type: 4;
|
|
|
|
#elif defined(__LITTLE_ENDIAN)
|
|
|
|
__u8 command_set_type: 4;
|
|
|
|
__u8 iid: 4;
|
|
|
|
#else
|
|
|
|
#error
|
|
|
|
#endif
|
|
|
|
union {
|
|
|
|
__u8 tm_function;
|
|
|
|
__u8 query_function;
|
2023-08-29 16:35:42 +00:00
|
|
|
} __attribute__((packed));
|
2023-07-27 19:41:24 +00:00
|
|
|
__u8 response;
|
|
|
|
__u8 status;
|
|
|
|
__u8 ehs_length;
|
|
|
|
__u8 device_information;
|
|
|
|
__be16 data_segment_length;
|
|
|
|
};
|
|
|
|
};
|
2018-10-07 14:30:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct utp_upiu_query - upiu request buffer structure for
|
|
|
|
* query request.
|
|
|
|
* @opcode: command to perform B-0
|
|
|
|
* @idn: a value that indicates the particular type of data B-1
|
|
|
|
* @index: Index to further identify data B-2
|
|
|
|
* @selector: Index to further identify data B-3
|
|
|
|
* @reserved_osf: spec reserved field B-4,5
|
|
|
|
* @length: number of descriptor bytes to read/write B-6,7
|
|
|
|
* @value: Attribute value to be written DW-5
|
|
|
|
* @reserved: spec reserved DW-6,7
|
|
|
|
*/
|
|
|
|
struct utp_upiu_query {
|
|
|
|
__u8 opcode;
|
|
|
|
__u8 idn;
|
|
|
|
__u8 index;
|
|
|
|
__u8 selector;
|
|
|
|
__be16 reserved_osf;
|
|
|
|
__be16 length;
|
|
|
|
__be32 value;
|
|
|
|
__be32 reserved[2];
|
|
|
|
};
|
|
|
|
|
2023-06-26 10:33:19 +00:00
|
|
|
/**
|
|
|
|
* struct utp_upiu_query_v4_0 - upiu request buffer structure for
|
|
|
|
* query request >= UFS 4.0 spec.
|
|
|
|
* @opcode: command to perform B-0
|
|
|
|
* @idn: a value that indicates the particular type of data B-1
|
|
|
|
* @index: Index to further identify data B-2
|
|
|
|
* @selector: Index to further identify data B-3
|
2024-04-24 05:53:16 +00:00
|
|
|
* @osf3: spec field B-4
|
2023-06-26 10:33:19 +00:00
|
|
|
* @osf4: spec field B-5
|
|
|
|
* @osf5: spec field B 6,7
|
|
|
|
* @osf6: spec field DW 8,9
|
|
|
|
* @osf7: spec field DW 10,11
|
|
|
|
*/
|
|
|
|
struct utp_upiu_query_v4_0 {
|
|
|
|
__u8 opcode;
|
|
|
|
__u8 idn;
|
|
|
|
__u8 index;
|
|
|
|
__u8 selector;
|
|
|
|
__u8 osf3;
|
|
|
|
__u8 osf4;
|
|
|
|
__be16 osf5;
|
|
|
|
__be32 osf6;
|
|
|
|
__be32 osf7;
|
2024-04-24 05:53:16 +00:00
|
|
|
/* private: */
|
2023-06-26 10:33:19 +00:00
|
|
|
__be32 reserved;
|
|
|
|
};
|
|
|
|
|
2018-10-07 14:30:34 +00:00
|
|
|
/**
|
|
|
|
* struct utp_upiu_cmd - Command UPIU structure
|
2024-04-24 05:53:16 +00:00
|
|
|
* @exp_data_transfer_len: Data Transfer Length DW-3
|
2018-10-07 14:30:34 +00:00
|
|
|
* @cdb: Command Descriptor Block CDB DW-4 to DW-7
|
|
|
|
*/
|
|
|
|
struct utp_upiu_cmd {
|
|
|
|
__be32 exp_data_transfer_len;
|
2018-10-12 10:41:28 +00:00
|
|
|
__u8 cdb[UFS_CDB_SIZE];
|
2018-10-07 14:30:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct utp_upiu_req - general upiu request structure
|
|
|
|
* @header:UPIU header structure DW-0 to DW-2
|
|
|
|
* @sc: fields structure for scsi command DW-3 to DW-7
|
|
|
|
* @qr: fields structure for query request DW-3 to DW-7
|
2019-12-05 22:09:12 +00:00
|
|
|
* @uc: use utp_upiu_query to host the 4 dwords of uic command
|
2018-10-07 14:30:34 +00:00
|
|
|
*/
|
|
|
|
struct utp_upiu_req {
|
|
|
|
struct utp_upiu_header header;
|
|
|
|
union {
|
|
|
|
struct utp_upiu_cmd sc;
|
|
|
|
struct utp_upiu_query qr;
|
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 14:30:35 +00:00
|
|
|
struct utp_upiu_query uc;
|
2018-10-07 14:30:34 +00: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 14:30:35 +00:00
|
|
|
|
2022-12-01 14:04:37 +00:00
|
|
|
struct ufs_arpmb_meta {
|
2023-01-08 22:40:57 +00:00
|
|
|
__be16 req_resp_type;
|
2022-12-01 14:04:37 +00:00
|
|
|
__u8 nonce[16];
|
2023-01-08 22:40:57 +00:00
|
|
|
__be32 write_counter;
|
|
|
|
__be16 addr_lun;
|
|
|
|
__be16 block_count;
|
|
|
|
__be16 result;
|
2022-12-01 14:04:37 +00:00
|
|
|
} __attribute__((__packed__));
|
|
|
|
|
|
|
|
struct ufs_ehs {
|
|
|
|
__u8 length;
|
|
|
|
__u8 ehs_type;
|
2023-01-08 22:40:57 +00:00
|
|
|
__be16 ehssub_type;
|
2022-12-01 14:04:37 +00:00
|
|
|
struct ufs_arpmb_meta meta;
|
|
|
|
__u8 mac_key[32];
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
|
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 14:30:35 +00:00
|
|
|
/* request (CDB) structure of the sg_io_v4 */
|
|
|
|
struct ufs_bsg_request {
|
2018-10-12 10:41:28 +00:00
|
|
|
__u32 msgcode;
|
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 14:30:35 +00:00
|
|
|
struct utp_upiu_req upiu_req;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* response (request sense data) structure of the sg_io_v4 */
|
|
|
|
struct ufs_bsg_reply {
|
|
|
|
/*
|
|
|
|
* The completion result. Result exists in two forms:
|
|
|
|
* if negative, it is an -Exxx system errno value. There will
|
|
|
|
* be no further reply information supplied.
|
|
|
|
* else, it's the 4-byte scsi error result, with driver, host,
|
|
|
|
* msg and status fields. The per-msgcode reply structure
|
|
|
|
* will contain valid data.
|
|
|
|
*/
|
2022-12-01 14:04:31 +00:00
|
|
|
int result;
|
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 14:30:35 +00:00
|
|
|
|
|
|
|
/* If there was reply_payload, how much was received? */
|
2018-10-12 10:41:28 +00:00
|
|
|
__u32 reply_payload_rcv_len;
|
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 14:30:35 +00:00
|
|
|
|
|
|
|
struct utp_upiu_req upiu_rsp;
|
|
|
|
};
|
2022-12-01 14:04:37 +00:00
|
|
|
|
|
|
|
struct ufs_rpmb_request {
|
|
|
|
struct ufs_bsg_request bsg_request;
|
|
|
|
struct ufs_ehs ehs_req;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ufs_rpmb_reply {
|
|
|
|
struct ufs_bsg_reply bsg_reply;
|
|
|
|
struct ufs_ehs ehs_rsp;
|
|
|
|
};
|
2018-10-07 14:30:34 +00:00
|
|
|
#endif /* UFS_BSG_H */
|