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_DESC_HDR_SIZE 2
47#define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \
48 (sizeof(struct utp_upiu_header)))
49#define RESPONSE_UPIU_SENSE_DATA_LENGTH 18
50
51#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
52 cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
53 (byte1 << 8) | (byte0))
54
55
56
57
58
59
60
61
62
63#define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F
64#define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)
65#define UFS_UPIU_WLUN_ID (1 << 7)
66#define UFS_UPIU_MAX_GENERAL_LUN 8
67
68
69enum {
70 UFS_UPIU_REPORT_LUNS_WLUN = 0x81,
71 UFS_UPIU_UFS_DEVICE_WLUN = 0xD0,
72 UFS_UPIU_BOOT_WLUN = 0xB0,
73 UFS_UPIU_RPMB_WLUN = 0xC4,
74};
75
76
77
78
79
80
81enum {
82 UFS_ABORT_TASK = 0x01,
83 UFS_ABORT_TASK_SET = 0x02,
84 UFS_CLEAR_TASK_SET = 0x04,
85 UFS_LOGICAL_RESET = 0x08,
86 UFS_QUERY_TASK = 0x80,
87 UFS_QUERY_TASK_SET = 0x81,
88};
89
90
91enum {
92 UPIU_TRANSACTION_NOP_OUT = 0x00,
93 UPIU_TRANSACTION_COMMAND = 0x01,
94 UPIU_TRANSACTION_DATA_OUT = 0x02,
95 UPIU_TRANSACTION_TASK_REQ = 0x04,
96 UPIU_TRANSACTION_QUERY_REQ = 0x16,
97};
98
99
100enum {
101 UPIU_TRANSACTION_NOP_IN = 0x20,
102 UPIU_TRANSACTION_RESPONSE = 0x21,
103 UPIU_TRANSACTION_DATA_IN = 0x22,
104 UPIU_TRANSACTION_TASK_RSP = 0x24,
105 UPIU_TRANSACTION_READY_XFER = 0x31,
106 UPIU_TRANSACTION_QUERY_RSP = 0x36,
107 UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
108};
109
110
111enum {
112 UPIU_CMD_FLAGS_NONE = 0x00,
113 UPIU_CMD_FLAGS_WRITE = 0x20,
114 UPIU_CMD_FLAGS_READ = 0x40,
115};
116
117
118enum {
119 UPIU_TASK_ATTR_SIMPLE = 0x00,
120 UPIU_TASK_ATTR_ORDERED = 0x01,
121 UPIU_TASK_ATTR_HEADQ = 0x02,
122 UPIU_TASK_ATTR_ACA = 0x03,
123};
124
125
126enum {
127 UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01,
128 UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81,
129};
130
131
132enum flag_idn {
133 QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
134 QUERY_FLAG_IDN_PWR_ON_WPE = 0x03,
135 QUERY_FLAG_IDN_BKOPS_EN = 0x04,
136};
137
138
139enum attr_idn {
140 QUERY_ATTR_IDN_ACTIVE_ICC_LVL = 0x03,
141 QUERY_ATTR_IDN_BKOPS_STATUS = 0x05,
142 QUERY_ATTR_IDN_EE_CONTROL = 0x0D,
143 QUERY_ATTR_IDN_EE_STATUS = 0x0E,
144};
145
146
147enum desc_idn {
148 QUERY_DESC_IDN_DEVICE = 0x0,
149 QUERY_DESC_IDN_CONFIGURATION = 0x1,
150 QUERY_DESC_IDN_UNIT = 0x2,
151 QUERY_DESC_IDN_RFU_0 = 0x3,
152 QUERY_DESC_IDN_INTERCONNECT = 0x4,
153 QUERY_DESC_IDN_STRING = 0x5,
154 QUERY_DESC_IDN_RFU_1 = 0x6,
155 QUERY_DESC_IDN_GEOMETRY = 0x7,
156 QUERY_DESC_IDN_POWER = 0x8,
157 QUERY_DESC_IDN_MAX,
158};
159
160enum desc_header_offset {
161 QUERY_DESC_LENGTH_OFFSET = 0x00,
162 QUERY_DESC_DESC_TYPE_OFFSET = 0x01,
163};
164
165enum ufs_desc_def_size {
166 QUERY_DESC_DEVICE_DEF_SIZE = 0x40,
167 QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90,
168 QUERY_DESC_UNIT_DEF_SIZE = 0x23,
169 QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06,
170 QUERY_DESC_GEOMETRY_DEF_SIZE = 0x44,
171 QUERY_DESC_POWER_DEF_SIZE = 0x62,
172};
173
174
175enum unit_desc_param {
176 UNIT_DESC_PARAM_LEN = 0x0,
177 UNIT_DESC_PARAM_TYPE = 0x1,
178 UNIT_DESC_PARAM_UNIT_INDEX = 0x2,
179 UNIT_DESC_PARAM_LU_ENABLE = 0x3,
180 UNIT_DESC_PARAM_BOOT_LUN_ID = 0x4,
181 UNIT_DESC_PARAM_LU_WR_PROTECT = 0x5,
182 UNIT_DESC_PARAM_LU_Q_DEPTH = 0x6,
183 UNIT_DESC_PARAM_MEM_TYPE = 0x8,
184 UNIT_DESC_PARAM_DATA_RELIABILITY = 0x9,
185 UNIT_DESC_PARAM_LOGICAL_BLK_SIZE = 0xA,
186 UNIT_DESC_PARAM_LOGICAL_BLK_COUNT = 0xB,
187 UNIT_DESC_PARAM_ERASE_BLK_SIZE = 0x13,
188 UNIT_DESC_PARAM_PROVISIONING_TYPE = 0x17,
189 UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT = 0x18,
190 UNIT_DESC_PARAM_CTX_CAPABILITIES = 0x20,
191 UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22,
192};
193
194
195enum device_desc_param {
196 DEVICE_DESC_PARAM_LEN = 0x0,
197 DEVICE_DESC_PARAM_TYPE = 0x1,
198 DEVICE_DESC_PARAM_DEVICE_TYPE = 0x2,
199 DEVICE_DESC_PARAM_DEVICE_CLASS = 0x3,
200 DEVICE_DESC_PARAM_DEVICE_SUB_CLASS = 0x4,
201 DEVICE_DESC_PARAM_PRTCL = 0x5,
202 DEVICE_DESC_PARAM_NUM_LU = 0x6,
203 DEVICE_DESC_PARAM_NUM_WLU = 0x7,
204 DEVICE_DESC_PARAM_BOOT_ENBL = 0x8,
205 DEVICE_DESC_PARAM_DESC_ACCSS_ENBL = 0x9,
206 DEVICE_DESC_PARAM_INIT_PWR_MODE = 0xA,
207 DEVICE_DESC_PARAM_HIGH_PR_LUN = 0xB,
208 DEVICE_DESC_PARAM_SEC_RMV_TYPE = 0xC,
209 DEVICE_DESC_PARAM_SEC_LU = 0xD,
210 DEVICE_DESC_PARAM_BKOP_TERM_LT = 0xE,
211 DEVICE_DESC_PARAM_ACTVE_ICC_LVL = 0xF,
212 DEVICE_DESC_PARAM_SPEC_VER = 0x10,
213 DEVICE_DESC_PARAM_MANF_DATE = 0x12,
214 DEVICE_DESC_PARAM_MANF_NAME = 0x14,
215 DEVICE_DESC_PARAM_PRDCT_NAME = 0x15,
216 DEVICE_DESC_PARAM_SN = 0x16,
217 DEVICE_DESC_PARAM_OEM_ID = 0x17,
218 DEVICE_DESC_PARAM_MANF_ID = 0x18,
219 DEVICE_DESC_PARAM_UD_OFFSET = 0x1A,
220 DEVICE_DESC_PARAM_UD_LEN = 0x1B,
221 DEVICE_DESC_PARAM_RTT_CAP = 0x1C,
222 DEVICE_DESC_PARAM_FRQ_RTC = 0x1D,
223};
224
225
226
227
228
229
230
231enum ufs_lu_wp_type {
232 UFS_LU_NO_WP = 0x00,
233 UFS_LU_POWER_ON_WP = 0x01,
234 UFS_LU_PERM_WP = 0x02,
235};
236
237
238enum {
239 UFSHCD_NANO_AMP = 0,
240 UFSHCD_MICRO_AMP = 1,
241 UFSHCD_MILI_AMP = 2,
242 UFSHCD_AMP = 3,
243};
244
245#define POWER_DESC_MAX_SIZE 0x62
246#define POWER_DESC_MAX_ACTV_ICC_LVLS 16
247
248
249#define ATTR_ICC_LVL_UNIT_OFFSET 14
250#define ATTR_ICC_LVL_UNIT_MASK (0x3 << ATTR_ICC_LVL_UNIT_OFFSET)
251#define ATTR_ICC_LVL_VALUE_MASK 0x3FF
252
253
254enum power_desc_param_offset {
255 PWR_DESC_LEN = 0x0,
256 PWR_DESC_TYPE = 0x1,
257 PWR_DESC_ACTIVE_LVLS_VCC_0 = 0x2,
258 PWR_DESC_ACTIVE_LVLS_VCCQ_0 = 0x22,
259 PWR_DESC_ACTIVE_LVLS_VCCQ2_0 = 0x42,
260};
261
262
263enum {
264 MASK_EE_STATUS = 0xFFFF,
265 MASK_EE_URGENT_BKOPS = (1 << 2),
266};
267
268
269enum bkops_status {
270 BKOPS_STATUS_NO_OP = 0x0,
271 BKOPS_STATUS_NON_CRITICAL = 0x1,
272 BKOPS_STATUS_PERF_IMPACT = 0x2,
273 BKOPS_STATUS_CRITICAL = 0x3,
274 BKOPS_STATUS_MAX = BKOPS_STATUS_CRITICAL,
275};
276
277
278enum query_opcode {
279 UPIU_QUERY_OPCODE_NOP = 0x0,
280 UPIU_QUERY_OPCODE_READ_DESC = 0x1,
281 UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
282 UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
283 UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
284 UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
285 UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
286 UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
287 UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
288};
289
290
291enum {
292 QUERY_RESULT_SUCCESS = 0x00,
293 QUERY_RESULT_NOT_READABLE = 0xF6,
294 QUERY_RESULT_NOT_WRITEABLE = 0xF7,
295 QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
296 QUERY_RESULT_INVALID_LENGTH = 0xF9,
297 QUERY_RESULT_INVALID_VALUE = 0xFA,
298 QUERY_RESULT_INVALID_SELECTOR = 0xFB,
299 QUERY_RESULT_INVALID_INDEX = 0xFC,
300 QUERY_RESULT_INVALID_IDN = 0xFD,
301 QUERY_RESULT_INVALID_OPCODE = 0xFE,
302 QUERY_RESULT_GENERAL_FAILURE = 0xFF,
303};
304
305
306enum {
307 UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
308 UPIU_COMMAND_SET_TYPE_UFS = 0x1,
309 UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
310};
311
312
313#define UPIU_COMMAND_TYPE_OFFSET 28
314
315
316#define UPIU_RSP_CODE_OFFSET 8
317
318enum {
319 MASK_SCSI_STATUS = 0xFF,
320 MASK_TASK_RESPONSE = 0xFF00,
321 MASK_RSP_UPIU_RESULT = 0xFFFF,
322 MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
323 MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF,
324 MASK_RSP_EXCEPTION_EVENT = 0x10000,
325 MASK_TM_SERVICE_RESP = 0xFF,
326};
327
328
329enum {
330 UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
331 UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
332 UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
333 UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
334 UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
335};
336
337
338enum ufs_dev_pwr_mode {
339 UFS_ACTIVE_PWR_MODE = 1,
340 UFS_SLEEP_PWR_MODE = 2,
341 UFS_POWERDOWN_PWR_MODE = 3,
342};
343
344
345
346
347
348
349
350struct utp_upiu_header {
351 __be32 dword_0;
352 __be32 dword_1;
353 __be32 dword_2;
354};
355
356
357
358
359
360
361struct utp_upiu_cmd {
362 __be32 exp_data_transfer_len;
363 u8 cdb[MAX_CDB_SIZE];
364};
365
366
367
368
369
370
371
372
373
374
375
376
377
378struct utp_upiu_query {
379 u8 opcode;
380 u8 idn;
381 u8 index;
382 u8 selector;
383 __be16 reserved_osf;
384 __be16 length;
385 __be32 value;
386 __be32 reserved[2];
387};
388
389
390
391
392
393
394
395struct utp_upiu_req {
396 struct utp_upiu_header header;
397 union {
398 struct utp_upiu_cmd sc;
399 struct utp_upiu_query qr;
400 };
401};
402
403
404
405
406
407
408
409
410struct utp_cmd_rsp {
411 __be32 residual_transfer_count;
412 __be32 reserved[4];
413 __be16 sense_data_len;
414 u8 sense_data[RESPONSE_UPIU_SENSE_DATA_LENGTH];
415};
416
417
418
419
420
421
422
423struct utp_upiu_rsp {
424 struct utp_upiu_header header;
425 union {
426 struct utp_cmd_rsp sr;
427 struct utp_upiu_query qr;
428 };
429};
430
431
432
433
434
435
436
437
438
439struct utp_upiu_task_req {
440 struct utp_upiu_header header;
441 __be32 input_param1;
442 __be32 input_param2;
443 __be32 input_param3;
444 __be32 reserved[2];
445};
446
447
448
449
450
451
452
453
454struct utp_upiu_task_rsp {
455 struct utp_upiu_header header;
456 __be32 output_param1;
457 __be32 output_param2;
458 __be32 reserved[3];
459};
460
461
462
463
464
465
466struct ufs_query_req {
467 u8 query_func;
468 struct utp_upiu_query upiu_req;
469};
470
471
472
473
474
475
476struct ufs_query_res {
477 u8 response;
478 struct utp_upiu_query upiu_res;
479};
480
481#define UFS_VREG_VCC_MIN_UV 2700000
482#define UFS_VREG_VCC_MAX_UV 3600000
483#define UFS_VREG_VCC_1P8_MIN_UV 1700000
484#define UFS_VREG_VCC_1P8_MAX_UV 1950000
485#define UFS_VREG_VCCQ_MIN_UV 1100000
486#define UFS_VREG_VCCQ_MAX_UV 1300000
487#define UFS_VREG_VCCQ2_MIN_UV 1650000
488#define UFS_VREG_VCCQ2_MAX_UV 1950000
489
490
491
492
493
494#define UFS_VREG_LPM_LOAD_UA 1000
495
496struct ufs_vreg {
497 struct regulator *reg;
498 const char *name;
499 bool enabled;
500 bool unused;
501 int min_uV;
502 int max_uV;
503 int min_uA;
504 int max_uA;
505};
506
507struct ufs_vreg_info {
508 struct ufs_vreg *vcc;
509 struct ufs_vreg *vccq;
510 struct ufs_vreg *vccq2;
511 struct ufs_vreg *vdd_hba;
512};
513
514struct ufs_dev_info {
515 bool f_power_on_wp_en;
516
517 bool is_lu_power_on_wp;
518};
519
520#define MAX_MODEL_LEN 16
521
522
523
524
525
526
527struct ufs_dev_desc {
528 u16 wmanufacturerid;
529 char model[MAX_MODEL_LEN + 1];
530};
531
532#endif
533