1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#ifndef _UFS_H
37#define _UFS_H
38
39#include <linux/mutex.h>
40#include <linux/types.h>
41
42#define MAX_CDB_SIZE 16
43#define GENERAL_UPIU_REQUEST_SIZE 32
44#define QUERY_DESC_MAX_SIZE 255
45#define QUERY_DESC_MIN_SIZE 2
46#define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \
47 (sizeof(struct utp_upiu_header)))
48
49#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
50 cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
51 (byte1 << 8) | (byte0))
52
53
54
55
56
57
58enum {
59 UFS_ABORT_TASK = 0x01,
60 UFS_ABORT_TASK_SET = 0x02,
61 UFS_CLEAR_TASK_SET = 0x04,
62 UFS_LOGICAL_RESET = 0x08,
63 UFS_QUERY_TASK = 0x80,
64 UFS_QUERY_TASK_SET = 0x81,
65};
66
67
68enum {
69 UPIU_TRANSACTION_NOP_OUT = 0x00,
70 UPIU_TRANSACTION_COMMAND = 0x01,
71 UPIU_TRANSACTION_DATA_OUT = 0x02,
72 UPIU_TRANSACTION_TASK_REQ = 0x04,
73 UPIU_TRANSACTION_QUERY_REQ = 0x16,
74};
75
76
77enum {
78 UPIU_TRANSACTION_NOP_IN = 0x20,
79 UPIU_TRANSACTION_RESPONSE = 0x21,
80 UPIU_TRANSACTION_DATA_IN = 0x22,
81 UPIU_TRANSACTION_TASK_RSP = 0x24,
82 UPIU_TRANSACTION_READY_XFER = 0x31,
83 UPIU_TRANSACTION_QUERY_RSP = 0x36,
84 UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
85};
86
87
88enum {
89 UPIU_CMD_FLAGS_NONE = 0x00,
90 UPIU_CMD_FLAGS_WRITE = 0x20,
91 UPIU_CMD_FLAGS_READ = 0x40,
92};
93
94
95enum {
96 UPIU_TASK_ATTR_SIMPLE = 0x00,
97 UPIU_TASK_ATTR_ORDERED = 0x01,
98 UPIU_TASK_ATTR_HEADQ = 0x02,
99 UPIU_TASK_ATTR_ACA = 0x03,
100};
101
102
103enum {
104 UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01,
105 UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81,
106};
107
108
109enum flag_idn {
110 QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
111 QUERY_FLAG_IDN_BKOPS_EN = 0x04,
112};
113
114
115enum attr_idn {
116 QUERY_ATTR_IDN_BKOPS_STATUS = 0x05,
117 QUERY_ATTR_IDN_EE_CONTROL = 0x0D,
118 QUERY_ATTR_IDN_EE_STATUS = 0x0E,
119};
120
121
122enum desc_idn {
123 QUERY_DESC_IDN_DEVICE = 0x0,
124 QUERY_DESC_IDN_CONFIGURAION = 0x1,
125 QUERY_DESC_IDN_UNIT = 0x2,
126 QUERY_DESC_IDN_RFU_0 = 0x3,
127 QUERY_DESC_IDN_INTERCONNECT = 0x4,
128 QUERY_DESC_IDN_STRING = 0x5,
129 QUERY_DESC_IDN_RFU_1 = 0x6,
130 QUERY_DESC_IDN_GEOMETRY = 0x7,
131 QUERY_DESC_IDN_POWER = 0x8,
132 QUERY_DESC_IDN_RFU_2 = 0x9,
133};
134
135#define UNIT_DESC_MAX_SIZE 0x22
136
137enum unit_desc_param {
138 UNIT_DESC_PARAM_LEN = 0x0,
139 UNIT_DESC_PARAM_TYPE = 0x1,
140 UNIT_DESC_PARAM_UNIT_INDEX = 0x2,
141 UNIT_DESC_PARAM_LU_ENABLE = 0x3,
142 UNIT_DESC_PARAM_BOOT_LUN_ID = 0x4,
143 UNIT_DESC_PARAM_LU_WR_PROTECT = 0x5,
144 UNIT_DESC_PARAM_LU_Q_DEPTH = 0x6,
145 UNIT_DESC_PARAM_MEM_TYPE = 0x8,
146 UNIT_DESC_PARAM_DATA_RELIABILITY = 0x9,
147 UNIT_DESC_PARAM_LOGICAL_BLK_SIZE = 0xA,
148 UNIT_DESC_PARAM_LOGICAL_BLK_COUNT = 0xB,
149 UNIT_DESC_PARAM_ERASE_BLK_SIZE = 0x13,
150 UNIT_DESC_PARAM_PROVISIONING_TYPE = 0x17,
151 UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT = 0x18,
152 UNIT_DESC_PARAM_CTX_CAPABILITIES = 0x20,
153 UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22,
154};
155
156
157enum {
158 MASK_EE_STATUS = 0xFFFF,
159 MASK_EE_URGENT_BKOPS = (1 << 2),
160};
161
162
163enum {
164 BKOPS_STATUS_NO_OP = 0x0,
165 BKOPS_STATUS_NON_CRITICAL = 0x1,
166 BKOPS_STATUS_PERF_IMPACT = 0x2,
167 BKOPS_STATUS_CRITICAL = 0x3,
168};
169
170
171enum query_opcode {
172 UPIU_QUERY_OPCODE_NOP = 0x0,
173 UPIU_QUERY_OPCODE_READ_DESC = 0x1,
174 UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
175 UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
176 UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
177 UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
178 UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
179 UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
180 UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
181};
182
183
184enum {
185 QUERY_RESULT_SUCCESS = 0x00,
186 QUERY_RESULT_NOT_READABLE = 0xF6,
187 QUERY_RESULT_NOT_WRITEABLE = 0xF7,
188 QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
189 QUERY_RESULT_INVALID_LENGTH = 0xF9,
190 QUERY_RESULT_INVALID_VALUE = 0xFA,
191 QUERY_RESULT_INVALID_SELECTOR = 0xFB,
192 QUERY_RESULT_INVALID_INDEX = 0xFC,
193 QUERY_RESULT_INVALID_IDN = 0xFD,
194 QUERY_RESULT_INVALID_OPCODE = 0xFE,
195 QUERY_RESULT_GENERAL_FAILURE = 0xFF,
196};
197
198
199enum {
200 UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
201 UPIU_COMMAND_SET_TYPE_UFS = 0x1,
202 UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
203};
204
205
206#define UPIU_COMMAND_TYPE_OFFSET 28
207
208
209#define UPIU_RSP_CODE_OFFSET 8
210
211enum {
212 MASK_SCSI_STATUS = 0xFF,
213 MASK_TASK_RESPONSE = 0xFF00,
214 MASK_RSP_UPIU_RESULT = 0xFFFF,
215 MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
216 MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF,
217 MASK_RSP_EXCEPTION_EVENT = 0x10000,
218};
219
220
221enum {
222 UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
223 UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
224 UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
225 UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
226 UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
227};
228
229
230
231
232
233
234struct utp_upiu_header {
235 __be32 dword_0;
236 __be32 dword_1;
237 __be32 dword_2;
238};
239
240
241
242
243
244
245struct utp_upiu_cmd {
246 __be32 exp_data_transfer_len;
247 u8 cdb[MAX_CDB_SIZE];
248};
249
250
251
252
253
254
255
256
257
258
259
260
261
262struct utp_upiu_query {
263 u8 opcode;
264 u8 idn;
265 u8 index;
266 u8 selector;
267 __be16 reserved_osf;
268 __be16 length;
269 __be32 value;
270 __be32 reserved[2];
271};
272
273
274
275
276
277
278
279struct utp_upiu_req {
280 struct utp_upiu_header header;
281 union {
282 struct utp_upiu_cmd sc;
283 struct utp_upiu_query qr;
284 };
285};
286
287
288
289
290
291
292
293
294struct utp_cmd_rsp {
295 __be32 residual_transfer_count;
296 __be32 reserved[4];
297 __be16 sense_data_len;
298 u8 sense_data[18];
299};
300
301
302
303
304
305
306
307struct utp_upiu_rsp {
308 struct utp_upiu_header header;
309 union {
310 struct utp_cmd_rsp sr;
311 struct utp_upiu_query qr;
312 };
313};
314
315
316
317
318
319
320
321
322
323struct utp_upiu_task_req {
324 struct utp_upiu_header header;
325 __be32 input_param1;
326 __be32 input_param2;
327 __be32 input_param3;
328 __be32 reserved[2];
329};
330
331
332
333
334
335
336
337
338struct utp_upiu_task_rsp {
339 struct utp_upiu_header header;
340 __be32 output_param1;
341 __be32 output_param2;
342 __be32 reserved[3];
343};
344
345
346
347
348
349
350struct ufs_query_req {
351 u8 query_func;
352 struct utp_upiu_query upiu_req;
353};
354
355
356
357
358
359
360struct ufs_query_res {
361 u8 response;
362 struct utp_upiu_query upiu_res;
363};
364
365#endif
366