xref: /openbmc/linux/include/uapi/scsi/scsi_bsg_ufs.h (revision 185c8f33)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * UFS Transport SGIO v4 BSG Message Support
4  *
5  * Copyright (C) 2011-2013 Samsung India Software Operations
6  * Copyright (C) 2018 Western Digital Corporation
7  */
8 #ifndef SCSI_BSG_UFS_H
9 #define SCSI_BSG_UFS_H
10 
11 #include <linux/types.h>
12 /*
13  * This file intended to be included by both kernel and user space
14  */
15 
16 #define UFS_CDB_SIZE	16
17 /* uic commands are 4DW long, per UFSHCI V2.1 paragraph 5.6.1 */
18 #define UIC_CMD_SIZE (sizeof(__u32) * 4)
19 
20 enum ufs_bsg_msg_code {
21 	UPIU_TRANSACTION_UIC_CMD = 0x1F,
22 	UPIU_TRANSACTION_ARPMB_CMD,
23 };
24 
25 /* UFS RPMB Request Message Types */
26 enum ufs_rpmb_op_type {
27 	UFS_RPMB_WRITE_KEY		= 0x01,
28 	UFS_RPMB_READ_CNT		= 0x02,
29 	UFS_RPMB_WRITE			= 0x03,
30 	UFS_RPMB_READ			= 0x04,
31 	UFS_RPMB_READ_RESP		= 0x05,
32 	UFS_RPMB_SEC_CONF_WRITE		= 0x06,
33 	UFS_RPMB_SEC_CONF_READ		= 0x07,
34 	UFS_RPMB_PURGE_ENABLE		= 0x08,
35 	UFS_RPMB_PURGE_STATUS_READ	= 0x09,
36 };
37 
38 /**
39  * struct utp_upiu_header - UPIU header structure
40  * @dword_0: UPIU header DW-0
41  * @dword_1: UPIU header DW-1
42  * @dword_2: UPIU header DW-2
43  */
44 struct utp_upiu_header {
45 	__be32 dword_0;
46 	__be32 dword_1;
47 	__be32 dword_2;
48 };
49 
50 /**
51  * struct utp_upiu_query - upiu request buffer structure for
52  * query request.
53  * @opcode: command to perform B-0
54  * @idn: a value that indicates the particular type of data B-1
55  * @index: Index to further identify data B-2
56  * @selector: Index to further identify data B-3
57  * @reserved_osf: spec reserved field B-4,5
58  * @length: number of descriptor bytes to read/write B-6,7
59  * @value: Attribute value to be written DW-5
60  * @reserved: spec reserved DW-6,7
61  */
62 struct utp_upiu_query {
63 	__u8 opcode;
64 	__u8 idn;
65 	__u8 index;
66 	__u8 selector;
67 	__be16 reserved_osf;
68 	__be16 length;
69 	__be32 value;
70 	__be32 reserved[2];
71 };
72 
73 /**
74  * struct utp_upiu_query_v4_0 - upiu request buffer structure for
75  * query request >= UFS 4.0 spec.
76  * @opcode: command to perform B-0
77  * @idn: a value that indicates the particular type of data B-1
78  * @index: Index to further identify data B-2
79  * @selector: Index to further identify data B-3
80  * @osf4: spec field B-5
81  * @osf5: spec field B 6,7
82  * @osf6: spec field DW 8,9
83  * @osf7: spec field DW 10,11
84  */
85 struct utp_upiu_query_v4_0 {
86 	__u8 opcode;
87 	__u8 idn;
88 	__u8 index;
89 	__u8 selector;
90 	__u8 osf3;
91 	__u8 osf4;
92 	__be16 osf5;
93 	__be32 osf6;
94 	__be32 osf7;
95 	__be32 reserved;
96 };
97 
98 /**
99  * struct utp_upiu_cmd - Command UPIU structure
100  * @data_transfer_len: Data Transfer Length DW-3
101  * @cdb: Command Descriptor Block CDB DW-4 to DW-7
102  */
103 struct utp_upiu_cmd {
104 	__be32 exp_data_transfer_len;
105 	__u8 cdb[UFS_CDB_SIZE];
106 };
107 
108 /**
109  * struct utp_upiu_req - general upiu request structure
110  * @header:UPIU header structure DW-0 to DW-2
111  * @sc: fields structure for scsi command DW-3 to DW-7
112  * @qr: fields structure for query request DW-3 to DW-7
113  * @uc: use utp_upiu_query to host the 4 dwords of uic command
114  */
115 struct utp_upiu_req {
116 	struct utp_upiu_header header;
117 	union {
118 		struct utp_upiu_cmd		sc;
119 		struct utp_upiu_query		qr;
120 		struct utp_upiu_query		uc;
121 	};
122 };
123 
124 struct ufs_arpmb_meta {
125 	__be16	req_resp_type;
126 	__u8	nonce[16];
127 	__be32	write_counter;
128 	__be16	addr_lun;
129 	__be16	block_count;
130 	__be16	result;
131 } __attribute__((__packed__));
132 
133 struct ufs_ehs {
134 	__u8	length;
135 	__u8	ehs_type;
136 	__be16	ehssub_type;
137 	struct ufs_arpmb_meta meta;
138 	__u8	mac_key[32];
139 } __attribute__((__packed__));
140 
141 /* request (CDB) structure of the sg_io_v4 */
142 struct ufs_bsg_request {
143 	__u32 msgcode;
144 	struct utp_upiu_req upiu_req;
145 };
146 
147 /* response (request sense data) structure of the sg_io_v4 */
148 struct ufs_bsg_reply {
149 	/*
150 	 * The completion result. Result exists in two forms:
151 	 * if negative, it is an -Exxx system errno value. There will
152 	 * be no further reply information supplied.
153 	 * else, it's the 4-byte scsi error result, with driver, host,
154 	 * msg and status fields. The per-msgcode reply structure
155 	 * will contain valid data.
156 	 */
157 	int result;
158 
159 	/* If there was reply_payload, how much was received? */
160 	__u32 reply_payload_rcv_len;
161 
162 	struct utp_upiu_req upiu_rsp;
163 };
164 
165 struct ufs_rpmb_request {
166 	struct ufs_bsg_request bsg_request;
167 	struct ufs_ehs ehs_req;
168 };
169 
170 struct ufs_rpmb_reply {
171 	struct ufs_bsg_reply bsg_reply;
172 	struct ufs_ehs ehs_rsp;
173 };
174 #endif /* UFS_BSG_H */
175