1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * UFS Transport SGIO v4 BSG Message Support
5 * Copyright (C) 2011-2013 Samsung India Software Operations
6 * Copyright (C) 2018 Western Digital Corporation
11 #include <asm/byteorder.h>
12 #include <linux/types.h>
14 * This file intended to be included by both kernel and user space
17 #define UFS_CDB_SIZE 16
18 /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
19 #define UIC_CMD_SIZE (sizeof(__u32) * 4)
21 enum ufs_bsg_msg_code {
22 UPIU_TRANSACTION_UIC_CMD = 0x1F,
23 UPIU_TRANSACTION_ARPMB_CMD,
26 /* UFS RPMB Request Message Types */
27 enum ufs_rpmb_op_type {
28 UFS_RPMB_WRITE_KEY = 0x01,
29 UFS_RPMB_READ_CNT = 0x02,
30 UFS_RPMB_WRITE = 0x03,
32 UFS_RPMB_READ_RESP = 0x05,
33 UFS_RPMB_SEC_CONF_WRITE = 0x06,
34 UFS_RPMB_SEC_CONF_READ = 0x07,
35 UFS_RPMB_PURGE_ENABLE = 0x08,
36 UFS_RPMB_PURGE_STATUS_READ = 0x09,
40 * struct utp_upiu_header - UPIU header structure
41 * @dword_0: UPIU header DW-0
42 * @dword_1: UPIU header DW-1
43 * @dword_2: UPIU header DW-2
45 * @transaction_code: Type of request or response. See also enum
46 * upiu_request_transaction and enum upiu_response_transaction.
47 * @flags: UPIU flags. The meaning of individual flags depends on the
49 * @lun: Logical unit number.
50 * @task_tag: Task tag.
52 * @command_set_type: 0 for SCSI command set; 1 for UFS specific.
53 * @tm_function: Task management function in case of a task management request
55 * @query_function: Query function in case of a query request UPIU.
56 * @response: 0 for success; 1 for failure.
57 * @status: SCSI status if this is the header of a response to a SCSI command.
58 * @ehs_length: EHS length in units of 32 bytes.
59 * @device_information:
60 * @data_segment_length: data segment length.
62 struct utp_upiu_header {
70 __u8 transaction_code;
74 #if defined(__BIG_ENDIAN)
76 __u8 command_set_type: 4;
77 #elif defined(__LITTLE_ENDIAN)
78 __u8 command_set_type: 4;
86 } __attribute__((packed));
90 __u8 device_information;
91 __be16 data_segment_length;
97 * struct utp_upiu_query - upiu request buffer structure for
99 * @opcode: command to perform B-0
100 * @idn: a value that indicates the particular type of data B-1
101 * @index: Index to further identify data B-2
102 * @selector: Index to further identify data B-3
103 * @reserved_osf: spec reserved field B-4,5
104 * @length: number of descriptor bytes to read/write B-6,7
105 * @value: Attribute value to be written DW-5
106 * @reserved: spec reserved DW-6,7
108 struct utp_upiu_query {
120 * struct utp_upiu_query_v4_0 - upiu request buffer structure for
121 * query request >= UFS 4.0 spec.
122 * @opcode: command to perform B-0
123 * @idn: a value that indicates the particular type of data B-1
124 * @index: Index to further identify data B-2
125 * @selector: Index to further identify data B-3
126 * @osf4: spec field B-5
127 * @osf5: spec field B 6,7
128 * @osf6: spec field DW 8,9
129 * @osf7: spec field DW 10,11
131 struct utp_upiu_query_v4_0 {
145 * struct utp_upiu_cmd - Command UPIU structure
146 * @data_transfer_len: Data Transfer Length DW-3
147 * @cdb: Command Descriptor Block CDB DW-4 to DW-7
149 struct utp_upiu_cmd {
150 __be32 exp_data_transfer_len;
151 __u8 cdb[UFS_CDB_SIZE];
155 * struct utp_upiu_req - general upiu request structure
156 * @header:UPIU header structure DW-0 to DW-2
157 * @sc: fields structure for scsi command DW-3 to DW-7
158 * @qr: fields structure for query request DW-3 to DW-7
159 * @uc: use utp_upiu_query to host the 4 dwords of uic command
161 struct utp_upiu_req {
162 struct utp_upiu_header header;
164 struct utp_upiu_cmd sc;
165 struct utp_upiu_query qr;
166 struct utp_upiu_query uc;
170 struct ufs_arpmb_meta {
171 __be16 req_resp_type;
173 __be32 write_counter;
177 } __attribute__((__packed__));
183 struct ufs_arpmb_meta meta;
185 } __attribute__((__packed__));
187 /* request (CDB) structure of the sg_io_v4 */
188 struct ufs_bsg_request {
190 struct utp_upiu_req upiu_req;
193 /* response (request sense data) structure of the sg_io_v4 */
194 struct ufs_bsg_reply {
196 * The completion result. Result exists in two forms:
197 * if negative, it is an -Exxx system errno value. There will
198 * be no further reply information supplied.
199 * else, it's the 4-byte scsi error result, with driver, host,
200 * msg and status fields. The per-msgcode reply structure
201 * will contain valid data.
205 /* If there was reply_payload, how much was received? */
206 __u32 reply_payload_rcv_len;
208 struct utp_upiu_req upiu_rsp;
211 struct ufs_rpmb_request {
212 struct ufs_bsg_request bsg_request;
213 struct ufs_ehs ehs_req;
216 struct ufs_rpmb_reply {
217 struct ufs_bsg_reply bsg_reply;
218 struct ufs_ehs ehs_rsp;
220 #endif /* UFS_BSG_H */