]>
Commit | Line | Data |
---|---|---|
7feafb0a FA |
1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
2 | #ifndef __UFS_H | |
3 | #define __UFS_H | |
4 | ||
03de305e | 5 | #include <linux/types.h> |
fdd33a7f | 6 | #include <asm/io.h> |
7feafb0a FA |
7 | #include "unipro.h" |
8 | ||
98eb4ce5 SG |
9 | struct udevice; |
10 | ||
7feafb0a FA |
11 | #define UFS_CDB_SIZE 16 |
12 | #define UPIU_TRANSACTION_UIC_CMD 0x1F | |
13 | #define UIC_CMD_SIZE (sizeof(u32) * 4) | |
14 | #define RESPONSE_UPIU_SENSE_DATA_LENGTH 18 | |
15 | #define UFS_MAX_LUNS 0x7F | |
16 | ||
17 | enum { | |
18 | TASK_REQ_UPIU_SIZE_DWORDS = 8, | |
19 | TASK_RSP_UPIU_SIZE_DWORDS = 8, | |
20 | ALIGNED_UPIU_SIZE = 512, | |
21 | }; | |
22 | ||
23 | /* UFS device power modes */ | |
24 | enum ufs_dev_pwr_mode { | |
25 | UFS_ACTIVE_PWR_MODE = 1, | |
26 | UFS_SLEEP_PWR_MODE = 2, | |
27 | UFS_POWERDOWN_PWR_MODE = 3, | |
28 | }; | |
29 | ||
30 | enum ufs_notify_change_status { | |
31 | PRE_CHANGE, | |
32 | POST_CHANGE, | |
33 | }; | |
34 | ||
35 | struct ufs_pa_layer_attr { | |
36 | u32 gear_rx; | |
37 | u32 gear_tx; | |
38 | u32 lane_rx; | |
39 | u32 lane_tx; | |
40 | u32 pwr_rx; | |
41 | u32 pwr_tx; | |
42 | u32 hs_rate; | |
43 | }; | |
44 | ||
45 | struct ufs_pwr_mode_info { | |
46 | bool is_valid; | |
47 | struct ufs_pa_layer_attr info; | |
48 | }; | |
49 | ||
50 | enum ufs_desc_def_size { | |
51 | QUERY_DESC_DEVICE_DEF_SIZE = 0x40, | |
52 | QUERY_DESC_CONFIGURATION_DEF_SIZE = 0x90, | |
53 | QUERY_DESC_UNIT_DEF_SIZE = 0x23, | |
54 | QUERY_DESC_INTERCONNECT_DEF_SIZE = 0x06, | |
55 | QUERY_DESC_GEOMETRY_DEF_SIZE = 0x48, | |
56 | QUERY_DESC_POWER_DEF_SIZE = 0x62, | |
57 | QUERY_DESC_HEALTH_DEF_SIZE = 0x25, | |
58 | }; | |
59 | ||
60 | struct ufs_desc_size { | |
61 | int dev_desc; | |
62 | int pwr_desc; | |
63 | int geom_desc; | |
64 | int interc_desc; | |
65 | int unit_desc; | |
66 | int conf_desc; | |
67 | int hlth_desc; | |
68 | }; | |
69 | ||
70 | /* | |
71 | * Request Descriptor Definitions | |
72 | */ | |
73 | ||
74 | /* Transfer request command type */ | |
75 | enum { | |
76 | UTP_CMD_TYPE_SCSI = 0x0, | |
77 | UTP_CMD_TYPE_UFS = 0x1, | |
78 | UTP_CMD_TYPE_DEV_MANAGE = 0x2, | |
79 | }; | |
80 | ||
81 | /* UTP Transfer Request Command Offset */ | |
82 | #define UPIU_COMMAND_TYPE_OFFSET 28 | |
83 | ||
84 | /* Offset of the response code in the UPIU header */ | |
85 | #define UPIU_RSP_CODE_OFFSET 8 | |
86 | ||
87 | /* To accommodate UFS2.0 required Command type */ | |
88 | enum { | |
89 | UTP_CMD_TYPE_UFS_STORAGE = 0x1, | |
90 | }; | |
91 | ||
92 | enum { | |
93 | UTP_SCSI_COMMAND = 0x00000000, | |
94 | UTP_NATIVE_UFS_COMMAND = 0x10000000, | |
95 | UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000, | |
96 | UTP_REQ_DESC_INT_CMD = 0x01000000, | |
97 | }; | |
98 | ||
99 | /* UTP Transfer Request Data Direction (DD) */ | |
100 | enum { | |
101 | UTP_NO_DATA_TRANSFER = 0x00000000, | |
102 | UTP_HOST_TO_DEVICE = 0x02000000, | |
103 | UTP_DEVICE_TO_HOST = 0x04000000, | |
104 | }; | |
105 | ||
106 | /* Overall command status values */ | |
107 | enum { | |
108 | OCS_SUCCESS = 0x0, | |
109 | OCS_INVALID_CMD_TABLE_ATTR = 0x1, | |
110 | OCS_INVALID_PRDT_ATTR = 0x2, | |
111 | OCS_MISMATCH_DATA_BUF_SIZE = 0x3, | |
112 | OCS_MISMATCH_RESP_UPIU_SIZE = 0x4, | |
113 | OCS_PEER_COMM_FAILURE = 0x5, | |
114 | OCS_ABORTED = 0x6, | |
115 | OCS_FATAL_ERROR = 0x7, | |
116 | OCS_INVALID_COMMAND_STATUS = 0x0F, | |
117 | MASK_OCS = 0x0F, | |
118 | }; | |
119 | ||
120 | /* The maximum length of the data byte count field in the PRDT is 256KB */ | |
121 | #define PRDT_DATA_BYTE_COUNT_MAX (256 * 1024) | |
122 | /* The granularity of the data byte count field in the PRDT is 32-bit */ | |
123 | #define PRDT_DATA_BYTE_COUNT_PAD 4 | |
124 | ||
125 | #define GENERAL_UPIU_REQUEST_SIZE (sizeof(struct utp_upiu_req)) | |
126 | #define QUERY_DESC_MAX_SIZE 255 | |
127 | #define QUERY_DESC_MIN_SIZE 2 | |
128 | #define QUERY_DESC_HDR_SIZE 2 | |
129 | #define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \ | |
130 | (sizeof(struct utp_upiu_header))) | |
131 | #define RESPONSE_UPIU_SENSE_DATA_LENGTH 18 | |
132 | #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\ | |
133 | cpu_to_be32((byte3 << 24) | (byte2 << 16) |\ | |
134 | (byte1 << 8) | (byte0)) | |
135 | /* | |
136 | * UFS Protocol Information Unit related definitions | |
137 | */ | |
138 | ||
139 | /* Task management functions */ | |
140 | enum { | |
141 | UFS_ABORT_TASK = 0x01, | |
142 | UFS_ABORT_TASK_SET = 0x02, | |
143 | UFS_CLEAR_TASK_SET = 0x04, | |
144 | UFS_LOGICAL_RESET = 0x08, | |
145 | UFS_QUERY_TASK = 0x80, | |
146 | UFS_QUERY_TASK_SET = 0x81, | |
147 | }; | |
148 | ||
149 | /* UTP UPIU Transaction Codes Initiator to Target */ | |
150 | enum { | |
151 | UPIU_TRANSACTION_NOP_OUT = 0x00, | |
152 | UPIU_TRANSACTION_COMMAND = 0x01, | |
153 | UPIU_TRANSACTION_DATA_OUT = 0x02, | |
154 | UPIU_TRANSACTION_TASK_REQ = 0x04, | |
155 | UPIU_TRANSACTION_QUERY_REQ = 0x16, | |
156 | }; | |
157 | ||
158 | /* UTP UPIU Transaction Codes Target to Initiator */ | |
159 | enum { | |
160 | UPIU_TRANSACTION_NOP_IN = 0x20, | |
161 | UPIU_TRANSACTION_RESPONSE = 0x21, | |
162 | UPIU_TRANSACTION_DATA_IN = 0x22, | |
163 | UPIU_TRANSACTION_TASK_RSP = 0x24, | |
164 | UPIU_TRANSACTION_READY_XFER = 0x31, | |
165 | UPIU_TRANSACTION_QUERY_RSP = 0x36, | |
166 | UPIU_TRANSACTION_REJECT_UPIU = 0x3F, | |
167 | }; | |
168 | ||
169 | /* UPIU Read/Write flags */ | |
170 | enum { | |
171 | UPIU_CMD_FLAGS_NONE = 0x00, | |
172 | UPIU_CMD_FLAGS_WRITE = 0x20, | |
173 | UPIU_CMD_FLAGS_READ = 0x40, | |
174 | }; | |
175 | ||
176 | /* UPIU Task Attributes */ | |
177 | enum { | |
178 | UPIU_TASK_ATTR_SIMPLE = 0x00, | |
179 | UPIU_TASK_ATTR_ORDERED = 0x01, | |
180 | UPIU_TASK_ATTR_HEADQ = 0x02, | |
181 | UPIU_TASK_ATTR_ACA = 0x03, | |
182 | }; | |
183 | ||
184 | /* UPIU Query request function */ | |
185 | enum { | |
186 | UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01, | |
187 | UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81, | |
188 | }; | |
189 | ||
190 | /* Offset of the response code in the UPIU header */ | |
191 | #define UPIU_RSP_CODE_OFFSET 8 | |
192 | ||
193 | enum { | |
194 | MASK_SCSI_STATUS = 0xFF, | |
195 | MASK_TASK_RESPONSE = 0xFF00, | |
196 | MASK_RSP_UPIU_RESULT = 0xFFFF, | |
197 | MASK_QUERY_DATA_SEG_LEN = 0xFFFF, | |
198 | MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF, | |
199 | MASK_RSP_EXCEPTION_EVENT = 0x10000, | |
200 | MASK_TM_SERVICE_RESP = 0xFF, | |
201 | MASK_TM_FUNC = 0xFF, | |
202 | }; | |
203 | ||
204 | /* UTP QUERY Transaction Specific Fields OpCode */ | |
205 | enum query_opcode { | |
206 | UPIU_QUERY_OPCODE_NOP = 0x0, | |
207 | UPIU_QUERY_OPCODE_READ_DESC = 0x1, | |
208 | UPIU_QUERY_OPCODE_WRITE_DESC = 0x2, | |
209 | UPIU_QUERY_OPCODE_READ_ATTR = 0x3, | |
210 | UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4, | |
211 | UPIU_QUERY_OPCODE_READ_FLAG = 0x5, | |
212 | UPIU_QUERY_OPCODE_SET_FLAG = 0x6, | |
213 | UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7, | |
214 | UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8, | |
215 | }; | |
216 | ||
217 | /* Query response result code */ | |
218 | enum { | |
219 | QUERY_RESULT_SUCCESS = 0x00, | |
220 | QUERY_RESULT_NOT_READABLE = 0xF6, | |
221 | QUERY_RESULT_NOT_WRITEABLE = 0xF7, | |
222 | QUERY_RESULT_ALREADY_WRITTEN = 0xF8, | |
223 | QUERY_RESULT_INVALID_LENGTH = 0xF9, | |
224 | QUERY_RESULT_INVALID_VALUE = 0xFA, | |
225 | QUERY_RESULT_INVALID_SELECTOR = 0xFB, | |
226 | QUERY_RESULT_INVALID_INDEX = 0xFC, | |
227 | QUERY_RESULT_INVALID_IDN = 0xFD, | |
228 | QUERY_RESULT_INVALID_OPCODE = 0xFE, | |
229 | QUERY_RESULT_GENERAL_FAILURE = 0xFF, | |
230 | }; | |
231 | ||
232 | enum { | |
233 | UPIU_COMMAND_SET_TYPE_SCSI = 0x0, | |
234 | UPIU_COMMAND_SET_TYPE_UFS = 0x1, | |
235 | UPIU_COMMAND_SET_TYPE_QUERY = 0x2, | |
236 | }; | |
237 | ||
238 | /* Flag idn for Query Requests*/ | |
239 | enum flag_idn { | |
240 | QUERY_FLAG_IDN_FDEVICEINIT = 0x01, | |
241 | QUERY_FLAG_IDN_PERMANENT_WPE = 0x02, | |
242 | QUERY_FLAG_IDN_PWR_ON_WPE = 0x03, | |
243 | QUERY_FLAG_IDN_BKOPS_EN = 0x04, | |
244 | QUERY_FLAG_IDN_LIFE_SPAN_MODE_ENABLE = 0x05, | |
245 | QUERY_FLAG_IDN_PURGE_ENABLE = 0x06, | |
246 | QUERY_FLAG_IDN_RESERVED2 = 0x07, | |
247 | QUERY_FLAG_IDN_FPHYRESOURCEREMOVAL = 0x08, | |
248 | QUERY_FLAG_IDN_BUSY_RTC = 0x09, | |
249 | QUERY_FLAG_IDN_RESERVED3 = 0x0A, | |
250 | QUERY_FLAG_IDN_PERMANENTLY_DISABLE_FW_UPDATE = 0x0B, | |
251 | }; | |
252 | ||
253 | /* Attribute idn for Query requests */ | |
254 | enum attr_idn { | |
255 | QUERY_ATTR_IDN_BOOT_LU_EN = 0x00, | |
256 | QUERY_ATTR_IDN_RESERVED = 0x01, | |
257 | QUERY_ATTR_IDN_POWER_MODE = 0x02, | |
258 | QUERY_ATTR_IDN_ACTIVE_ICC_LVL = 0x03, | |
259 | QUERY_ATTR_IDN_OOO_DATA_EN = 0x04, | |
260 | QUERY_ATTR_IDN_BKOPS_STATUS = 0x05, | |
261 | QUERY_ATTR_IDN_PURGE_STATUS = 0x06, | |
262 | QUERY_ATTR_IDN_MAX_DATA_IN = 0x07, | |
263 | QUERY_ATTR_IDN_MAX_DATA_OUT = 0x08, | |
264 | QUERY_ATTR_IDN_DYN_CAP_NEEDED = 0x09, | |
265 | QUERY_ATTR_IDN_REF_CLK_FREQ = 0x0A, | |
266 | QUERY_ATTR_IDN_CONF_DESC_LOCK = 0x0B, | |
267 | QUERY_ATTR_IDN_MAX_NUM_OF_RTT = 0x0C, | |
268 | QUERY_ATTR_IDN_EE_CONTROL = 0x0D, | |
269 | QUERY_ATTR_IDN_EE_STATUS = 0x0E, | |
270 | QUERY_ATTR_IDN_SECONDS_PASSED = 0x0F, | |
271 | QUERY_ATTR_IDN_CNTX_CONF = 0x10, | |
272 | QUERY_ATTR_IDN_CORR_PRG_BLK_NUM = 0x11, | |
273 | QUERY_ATTR_IDN_RESERVED2 = 0x12, | |
274 | QUERY_ATTR_IDN_RESERVED3 = 0x13, | |
275 | QUERY_ATTR_IDN_FFU_STATUS = 0x14, | |
276 | QUERY_ATTR_IDN_PSA_STATE = 0x15, | |
277 | QUERY_ATTR_IDN_PSA_DATA_SIZE = 0x16, | |
278 | }; | |
279 | ||
280 | /* Descriptor idn for Query requests */ | |
281 | enum desc_idn { | |
282 | QUERY_DESC_IDN_DEVICE = 0x0, | |
283 | QUERY_DESC_IDN_CONFIGURATION = 0x1, | |
284 | QUERY_DESC_IDN_UNIT = 0x2, | |
285 | QUERY_DESC_IDN_RFU_0 = 0x3, | |
286 | QUERY_DESC_IDN_INTERCONNECT = 0x4, | |
287 | QUERY_DESC_IDN_STRING = 0x5, | |
288 | QUERY_DESC_IDN_RFU_1 = 0x6, | |
289 | QUERY_DESC_IDN_GEOMETRY = 0x7, | |
290 | QUERY_DESC_IDN_POWER = 0x8, | |
291 | QUERY_DESC_IDN_HEALTH = 0x9, | |
292 | QUERY_DESC_IDN_MAX, | |
293 | }; | |
294 | ||
295 | enum desc_header_offset { | |
296 | QUERY_DESC_LENGTH_OFFSET = 0x00, | |
297 | QUERY_DESC_DESC_TYPE_OFFSET = 0x01, | |
298 | }; | |
299 | ||
300 | struct ufshcd_sg_entry { | |
301 | __le32 base_addr; | |
302 | __le32 upper_addr; | |
303 | __le32 reserved; | |
304 | __le32 size; | |
305 | }; | |
306 | ||
307 | #define MAX_BUFF 128 | |
308 | /** | |
309 | * struct utp_transfer_cmd_desc - UFS Command Descriptor structure | |
310 | * @command_upiu: Command UPIU Frame address | |
311 | * @response_upiu: Response UPIU Frame address | |
312 | * @prd_table: Physical Region Descriptor | |
313 | */ | |
314 | struct utp_transfer_cmd_desc { | |
315 | u8 command_upiu[ALIGNED_UPIU_SIZE]; | |
316 | u8 response_upiu[ALIGNED_UPIU_SIZE]; | |
317 | struct ufshcd_sg_entry prd_table[MAX_BUFF]; | |
318 | }; | |
319 | ||
320 | /** | |
321 | * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD | |
322 | * @dword0: Descriptor Header DW0 | |
323 | * @dword1: Descriptor Header DW1 | |
324 | * @dword2: Descriptor Header DW2 | |
325 | * @dword3: Descriptor Header DW3 | |
326 | */ | |
327 | struct request_desc_header { | |
328 | __le32 dword_0; | |
329 | __le32 dword_1; | |
330 | __le32 dword_2; | |
331 | __le32 dword_3; | |
332 | }; | |
333 | ||
334 | /** | |
335 | * struct utp_transfer_req_desc - UTRD structure | |
336 | * @header: UTRD header DW-0 to DW-3 | |
337 | * @command_desc_base_addr_lo: UCD base address low DW-4 | |
338 | * @command_desc_base_addr_hi: UCD base address high DW-5 | |
339 | * @response_upiu_length: response UPIU length DW-6 | |
340 | * @response_upiu_offset: response UPIU offset DW-6 | |
341 | * @prd_table_length: Physical region descriptor length DW-7 | |
342 | * @prd_table_offset: Physical region descriptor offset DW-7 | |
343 | */ | |
344 | struct utp_transfer_req_desc { | |
345 | /* DW 0-3 */ | |
346 | struct request_desc_header header; | |
347 | ||
348 | /* DW 4-5*/ | |
349 | __le32 command_desc_base_addr_lo; | |
350 | __le32 command_desc_base_addr_hi; | |
351 | ||
352 | /* DW 6 */ | |
353 | __le16 response_upiu_length; | |
354 | __le16 response_upiu_offset; | |
355 | ||
356 | /* DW 7 */ | |
357 | __le16 prd_table_length; | |
358 | __le16 prd_table_offset; | |
359 | }; | |
360 | ||
361 | /** | |
362 | * struct utp_upiu_header - UPIU header structure | |
363 | * @dword_0: UPIU header DW-0 | |
364 | * @dword_1: UPIU header DW-1 | |
365 | * @dword_2: UPIU header DW-2 | |
366 | */ | |
367 | struct utp_upiu_header { | |
368 | __be32 dword_0; | |
369 | __be32 dword_1; | |
370 | __be32 dword_2; | |
371 | }; | |
372 | ||
373 | /** | |
374 | * struct utp_upiu_query - upiu request buffer structure for | |
375 | * query request. | |
376 | * @opcode: command to perform B-0 | |
377 | * @idn: a value that indicates the particular type of data B-1 | |
378 | * @index: Index to further identify data B-2 | |
379 | * @selector: Index to further identify data B-3 | |
380 | * @reserved_osf: spec reserved field B-4,5 | |
381 | * @length: number of descriptor bytes to read/write B-6,7 | |
382 | * @value: Attribute value to be written DW-5 | |
383 | * @reserved: spec reserved DW-6,7 | |
384 | */ | |
385 | struct utp_upiu_query { | |
386 | __u8 opcode; | |
387 | __u8 idn; | |
388 | __u8 index; | |
389 | __u8 selector; | |
390 | __be16 reserved_osf; | |
391 | __be16 length; | |
392 | __be32 value; | |
393 | __be32 reserved[2]; | |
394 | }; | |
395 | ||
396 | /** | |
397 | * struct utp_upiu_cmd - Command UPIU structure | |
398 | * @data_transfer_len: Data Transfer Length DW-3 | |
399 | * @cdb: Command Descriptor Block CDB DW-4 to DW-7 | |
400 | */ | |
401 | struct utp_upiu_cmd { | |
402 | __be32 exp_data_transfer_len; | |
403 | u8 cdb[UFS_CDB_SIZE]; | |
404 | }; | |
405 | ||
406 | /* | |
407 | * UTMRD structure. | |
408 | */ | |
409 | struct utp_task_req_desc { | |
410 | /* DW 0-3 */ | |
411 | struct request_desc_header header; | |
412 | ||
413 | /* DW 4-11 - Task request UPIU structure */ | |
414 | struct utp_upiu_header req_header; | |
415 | __be32 input_param1; | |
416 | __be32 input_param2; | |
417 | __be32 input_param3; | |
418 | __be32 __reserved1[2]; | |
419 | ||
420 | /* DW 12-19 - Task Management Response UPIU structure */ | |
421 | struct utp_upiu_header rsp_header; | |
422 | __be32 output_param1; | |
423 | __be32 output_param2; | |
424 | __be32 __reserved2[3]; | |
425 | }; | |
426 | ||
427 | /** | |
428 | * struct utp_upiu_req - general upiu request structure | |
429 | * @header:UPIU header structure DW-0 to DW-2 | |
430 | * @sc: fields structure for scsi command DW-3 to DW-7 | |
431 | * @qr: fields structure for query request DW-3 to DW-7 | |
432 | */ | |
433 | struct utp_upiu_req { | |
434 | struct utp_upiu_header header; | |
435 | union { | |
436 | struct utp_upiu_cmd sc; | |
437 | struct utp_upiu_query qr; | |
438 | struct utp_upiu_query tr; | |
439 | /* use utp_upiu_query to host the 4 dwords of uic command */ | |
440 | struct utp_upiu_query uc; | |
441 | }; | |
442 | }; | |
443 | ||
444 | /** | |
445 | * struct utp_cmd_rsp - Response UPIU structure | |
446 | * @residual_transfer_count: Residual transfer count DW-3 | |
447 | * @reserved: Reserved double words DW-4 to DW-7 | |
448 | * @sense_data_len: Sense data length DW-8 U16 | |
449 | * @sense_data: Sense data field DW-8 to DW-12 | |
450 | */ | |
451 | struct utp_cmd_rsp { | |
452 | __be32 residual_transfer_count; | |
453 | __be32 reserved[4]; | |
454 | __be16 sense_data_len; | |
455 | u8 sense_data[RESPONSE_UPIU_SENSE_DATA_LENGTH]; | |
456 | }; | |
457 | ||
458 | /** | |
459 | * struct utp_upiu_rsp - general upiu response structure | |
460 | * @header: UPIU header structure DW-0 to DW-2 | |
461 | * @sr: fields structure for scsi command DW-3 to DW-12 | |
462 | * @qr: fields structure for query request DW-3 to DW-7 | |
463 | */ | |
464 | struct utp_upiu_rsp { | |
465 | struct utp_upiu_header header; | |
466 | union { | |
467 | struct utp_cmd_rsp sr; | |
468 | struct utp_upiu_query qr; | |
469 | }; | |
470 | }; | |
471 | ||
472 | #define MAX_MODEL_LEN 16 | |
473 | /** | |
474 | * ufs_dev_desc - ufs device details from the device descriptor | |
475 | * | |
476 | * @wmanufacturerid: card details | |
477 | * @model: card model | |
478 | */ | |
479 | struct ufs_dev_desc { | |
480 | u16 wmanufacturerid; | |
481 | char model[MAX_MODEL_LEN + 1]; | |
482 | }; | |
483 | ||
484 | /* Device descriptor parameters offsets in bytes*/ | |
485 | enum device_desc_param { | |
486 | DEVICE_DESC_PARAM_LEN = 0x0, | |
487 | DEVICE_DESC_PARAM_TYPE = 0x1, | |
488 | DEVICE_DESC_PARAM_DEVICE_TYPE = 0x2, | |
489 | DEVICE_DESC_PARAM_DEVICE_CLASS = 0x3, | |
490 | DEVICE_DESC_PARAM_DEVICE_SUB_CLASS = 0x4, | |
491 | DEVICE_DESC_PARAM_PRTCL = 0x5, | |
492 | DEVICE_DESC_PARAM_NUM_LU = 0x6, | |
493 | DEVICE_DESC_PARAM_NUM_WLU = 0x7, | |
494 | DEVICE_DESC_PARAM_BOOT_ENBL = 0x8, | |
495 | DEVICE_DESC_PARAM_DESC_ACCSS_ENBL = 0x9, | |
496 | DEVICE_DESC_PARAM_INIT_PWR_MODE = 0xA, | |
497 | DEVICE_DESC_PARAM_HIGH_PR_LUN = 0xB, | |
498 | DEVICE_DESC_PARAM_SEC_RMV_TYPE = 0xC, | |
499 | DEVICE_DESC_PARAM_SEC_LU = 0xD, | |
500 | DEVICE_DESC_PARAM_BKOP_TERM_LT = 0xE, | |
501 | DEVICE_DESC_PARAM_ACTVE_ICC_LVL = 0xF, | |
502 | DEVICE_DESC_PARAM_SPEC_VER = 0x10, | |
503 | DEVICE_DESC_PARAM_MANF_DATE = 0x12, | |
504 | DEVICE_DESC_PARAM_MANF_NAME = 0x14, | |
505 | DEVICE_DESC_PARAM_PRDCT_NAME = 0x15, | |
506 | DEVICE_DESC_PARAM_SN = 0x16, | |
507 | DEVICE_DESC_PARAM_OEM_ID = 0x17, | |
508 | DEVICE_DESC_PARAM_MANF_ID = 0x18, | |
509 | DEVICE_DESC_PARAM_UD_OFFSET = 0x1A, | |
510 | DEVICE_DESC_PARAM_UD_LEN = 0x1B, | |
511 | DEVICE_DESC_PARAM_RTT_CAP = 0x1C, | |
512 | DEVICE_DESC_PARAM_FRQ_RTC = 0x1D, | |
513 | DEVICE_DESC_PARAM_UFS_FEAT = 0x1F, | |
514 | DEVICE_DESC_PARAM_FFU_TMT = 0x20, | |
515 | DEVICE_DESC_PARAM_Q_DPTH = 0x21, | |
516 | DEVICE_DESC_PARAM_DEV_VER = 0x22, | |
517 | DEVICE_DESC_PARAM_NUM_SEC_WPA = 0x24, | |
518 | DEVICE_DESC_PARAM_PSA_MAX_DATA = 0x25, | |
519 | DEVICE_DESC_PARAM_PSA_TMT = 0x29, | |
520 | DEVICE_DESC_PARAM_PRDCT_REV = 0x2A, | |
521 | }; | |
522 | ||
523 | struct ufs_hba; | |
524 | ||
525 | enum { | |
526 | UFSHCD_MAX_CHANNEL = 0, | |
527 | UFSHCD_MAX_ID = 1, | |
528 | }; | |
529 | ||
530 | enum dev_cmd_type { | |
531 | DEV_CMD_TYPE_NOP = 0x0, | |
532 | DEV_CMD_TYPE_QUERY = 0x1, | |
533 | }; | |
534 | ||
535 | /** | |
536 | * struct uic_command - UIC command structure | |
537 | * @command: UIC command | |
538 | * @argument1: UIC command argument 1 | |
539 | * @argument2: UIC command argument 2 | |
540 | * @argument3: UIC command argument 3 | |
541 | * @cmd_active: Indicate if UIC command is outstanding | |
542 | * @result: UIC command result | |
543 | * @done: UIC command completion | |
544 | */ | |
545 | struct uic_command { | |
546 | u32 command; | |
547 | u32 argument1; | |
548 | u32 argument2; | |
549 | u32 argument3; | |
550 | int cmd_active; | |
551 | int result; | |
552 | }; | |
553 | ||
554 | /* GenSelectorIndex calculation macros for M-PHY attributes */ | |
555 | #define UIC_ARG_MPHY_TX_GEN_SEL_INDEX(lane) (lane) | |
556 | #define UIC_ARG_MPHY_RX_GEN_SEL_INDEX(lane) (PA_MAXDATALANES + (lane)) | |
557 | ||
558 | #define UIC_ARG_MIB_SEL(attr, sel) ((((attr) & 0xFFFF) << 16) |\ | |
559 | ((sel) & 0xFFFF)) | |
560 | #define UIC_ARG_MIB(attr) UIC_ARG_MIB_SEL(attr, 0) | |
561 | #define UIC_ARG_ATTR_TYPE(t) (((t) & 0xFF) << 16) | |
562 | #define UIC_GET_ATTR_ID(v) (((v) >> 16) & 0xFFFF) | |
563 | ||
564 | /* Link Status*/ | |
565 | enum link_status { | |
566 | UFSHCD_LINK_IS_DOWN = 1, | |
567 | UFSHCD_LINK_IS_UP = 2, | |
568 | }; | |
569 | ||
570 | #define UIC_ARG_MIB_SEL(attr, sel) ((((attr) & 0xFFFF) << 16) |\ | |
571 | ((sel) & 0xFFFF)) | |
572 | #define UIC_ARG_MIB(attr) UIC_ARG_MIB_SEL(attr, 0) | |
573 | #define UIC_ARG_ATTR_TYPE(t) (((t) & 0xFF) << 16) | |
574 | #define UIC_GET_ATTR_ID(v) (((v) >> 16) & 0xFFFF) | |
575 | ||
576 | /* UIC Commands */ | |
577 | enum uic_cmd_dme { | |
578 | UIC_CMD_DME_GET = 0x01, | |
579 | UIC_CMD_DME_SET = 0x02, | |
580 | UIC_CMD_DME_PEER_GET = 0x03, | |
581 | UIC_CMD_DME_PEER_SET = 0x04, | |
582 | UIC_CMD_DME_POWERON = 0x10, | |
583 | UIC_CMD_DME_POWEROFF = 0x11, | |
584 | UIC_CMD_DME_ENABLE = 0x12, | |
585 | UIC_CMD_DME_RESET = 0x14, | |
586 | UIC_CMD_DME_END_PT_RST = 0x15, | |
587 | UIC_CMD_DME_LINK_STARTUP = 0x16, | |
588 | UIC_CMD_DME_HIBER_ENTER = 0x17, | |
589 | UIC_CMD_DME_HIBER_EXIT = 0x18, | |
590 | UIC_CMD_DME_TEST_MODE = 0x1A, | |
591 | }; | |
592 | ||
593 | /* UIC Config result code / Generic error code */ | |
594 | enum { | |
595 | UIC_CMD_RESULT_SUCCESS = 0x00, | |
596 | UIC_CMD_RESULT_INVALID_ATTR = 0x01, | |
597 | UIC_CMD_RESULT_FAILURE = 0x01, | |
598 | UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02, | |
599 | UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03, | |
600 | UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04, | |
601 | UIC_CMD_RESULT_BAD_INDEX = 0x05, | |
602 | UIC_CMD_RESULT_LOCKED_ATTR = 0x06, | |
603 | UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07, | |
604 | UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08, | |
605 | UIC_CMD_RESULT_BUSY = 0x09, | |
606 | UIC_CMD_RESULT_DME_FAILURE = 0x0A, | |
607 | }; | |
608 | ||
609 | #define MASK_UIC_COMMAND_RESULT 0xFF | |
610 | ||
611 | /* Host <-> Device UniPro Link state */ | |
612 | enum uic_link_state { | |
613 | UIC_LINK_OFF_STATE = 0, /* Link powered down or disabled */ | |
614 | UIC_LINK_ACTIVE_STATE = 1, /* Link is in Fast/Slow/Sleep state */ | |
615 | UIC_LINK_HIBERN8_STATE = 2, /* Link is in Hibernate state */ | |
616 | }; | |
617 | ||
618 | /* UIC command interfaces for DME primitives */ | |
619 | #define DME_LOCAL 0 | |
620 | #define DME_PEER 1 | |
621 | #define ATTR_SET_NOR 0 /* NORMAL */ | |
622 | #define ATTR_SET_ST 1 /* STATIC */ | |
623 | ||
624 | int ufshcd_dme_set_attr(struct ufs_hba *hba, u32 attr_sel, | |
625 | u8 attr_set, u32 mib_val, u8 peer); | |
626 | int ufshcd_dme_get_attr(struct ufs_hba *hba, u32 attr_sel, | |
627 | u32 *mib_val, u8 peer); | |
628 | ||
629 | static inline int ufshcd_dme_set(struct ufs_hba *hba, u32 attr_sel, | |
630 | u32 mib_val) | |
631 | { | |
632 | return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR, | |
633 | mib_val, DME_LOCAL); | |
634 | } | |
635 | ||
636 | static inline int ufshcd_dme_get(struct ufs_hba *hba, | |
637 | u32 attr_sel, u32 *mib_val) | |
638 | { | |
639 | return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_LOCAL); | |
640 | } | |
641 | ||
642 | static inline int ufshcd_dme_peer_get(struct ufs_hba *hba, | |
643 | u32 attr_sel, u32 *mib_val) | |
644 | { | |
645 | return ufshcd_dme_get_attr(hba, attr_sel, mib_val, DME_PEER); | |
646 | } | |
647 | ||
648 | static inline int ufshcd_dme_peer_set(struct ufs_hba *hba, u32 attr_sel, | |
649 | u32 mib_val) | |
650 | { | |
651 | return ufshcd_dme_set_attr(hba, attr_sel, ATTR_SET_NOR, | |
652 | mib_val, DME_PEER); | |
653 | } | |
654 | ||
655 | /** | |
656 | * struct ufs_query_req - parameters for building a query request | |
657 | * @query_func: UPIU header query function | |
658 | * @upiu_req: the query request data | |
659 | */ | |
660 | struct ufs_query_req { | |
661 | u8 query_func; | |
662 | struct utp_upiu_query upiu_req; | |
663 | }; | |
664 | ||
665 | /** | |
666 | * struct ufs_query_resp - UPIU QUERY | |
667 | * @response: device response code | |
668 | * @upiu_res: query response data | |
669 | */ | |
670 | struct ufs_query_res { | |
671 | u8 response; | |
672 | struct utp_upiu_query upiu_res; | |
673 | }; | |
674 | ||
675 | /** | |
676 | * struct ufs_query - holds relevant data structures for query request | |
677 | * @request: request upiu and function | |
678 | * @descriptor: buffer for sending/receiving descriptor | |
679 | * @response: response upiu and response | |
680 | */ | |
681 | struct ufs_query { | |
682 | struct ufs_query_req request; | |
683 | u8 *descriptor; | |
684 | struct ufs_query_res response; | |
685 | }; | |
686 | ||
687 | /** | |
688 | * struct ufs_dev_cmd - all assosiated fields with device management commands | |
689 | * @type: device management command type - Query, NOP OUT | |
690 | * @tag_wq: wait queue until free command slot is available | |
691 | */ | |
692 | struct ufs_dev_cmd { | |
693 | enum dev_cmd_type type; | |
694 | struct ufs_query query; | |
695 | }; | |
696 | ||
697 | struct ufs_hba_ops { | |
698 | int (*init)(struct ufs_hba *hba); | |
b3f89c1d NA |
699 | int (*get_max_pwr_mode)(struct ufs_hba *hba, |
700 | struct ufs_pwr_mode_info *max_pwr_info); | |
7feafb0a FA |
701 | int (*hce_enable_notify)(struct ufs_hba *hba, |
702 | enum ufs_notify_change_status); | |
703 | int (*link_startup_notify)(struct ufs_hba *hba, | |
704 | enum ufs_notify_change_status); | |
705 | int (*phy_initialization)(struct ufs_hba *hba); | |
182e1922 | 706 | int (*device_reset)(struct ufs_hba *hba); |
7feafb0a FA |
707 | }; |
708 | ||
00c54af3 BS |
709 | enum ufshcd_quirks { |
710 | /* Interrupt aggregation support is broken */ | |
711 | UFSHCD_QUIRK_BROKEN_INTR_AGGR = 1 << 0, | |
712 | ||
713 | /* | |
714 | * delay before each dme command is required as the unipro | |
715 | * layer has shown instabilities | |
716 | */ | |
717 | UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS = 1 << 1, | |
718 | ||
719 | /* | |
720 | * If UFS host controller is having issue in processing LCC (Line | |
721 | * Control Command) coming from device then enable this quirk. | |
722 | * When this quirk is enabled, host controller driver should disable | |
723 | * the LCC transmission on UFS device (by clearing TX_LCC_ENABLE | |
724 | * attribute of device to 0). | |
725 | */ | |
726 | UFSHCD_QUIRK_BROKEN_LCC = 1 << 2, | |
727 | ||
728 | /* | |
729 | * The attribute PA_RXHSUNTERMCAP specifies whether or not the | |
730 | * inbound Link supports unterminated line in HS mode. Setting this | |
731 | * attribute to 1 fixes moving to HS gear. | |
732 | */ | |
733 | UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP = 1 << 3, | |
734 | ||
735 | /* | |
736 | * This quirk needs to be enabled if the host controller only allows | |
737 | * accessing the peer dme attributes in AUTO mode (FAST AUTO or | |
738 | * SLOW AUTO). | |
739 | */ | |
740 | UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE = 1 << 4, | |
741 | ||
742 | /* | |
743 | * This quirk needs to be enabled if the host controller doesn't | |
744 | * advertise the correct version in UFS_VER register. If this quirk | |
745 | * is enabled, standard UFS host driver will call the vendor specific | |
746 | * ops (get_ufs_hci_version) to get the correct version. | |
747 | */ | |
748 | UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION = 1 << 5, | |
749 | ||
750 | /* | |
751 | * Clear handling for transfer/task request list is just opposite. | |
752 | */ | |
753 | UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR = 1 << 6, | |
754 | ||
755 | /* | |
756 | * This quirk needs to be enabled if host controller doesn't allow | |
757 | * that the interrupt aggregation timer and counter are reset by s/w. | |
758 | */ | |
759 | UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR = 1 << 7, | |
760 | ||
761 | /* | |
762 | * This quirks needs to be enabled if host controller cannot be | |
763 | * enabled via HCE register. | |
764 | */ | |
765 | UFSHCI_QUIRK_BROKEN_HCE = 1 << 8, | |
766 | ||
767 | /* | |
768 | * This quirk needs to be enabled if the host controller regards | |
769 | * resolution of the values of PRDTO and PRDTL in UTRD as byte. | |
770 | */ | |
771 | UFSHCD_QUIRK_PRDT_BYTE_GRAN = 1 << 9, | |
772 | ||
773 | /* | |
774 | * This quirk needs to be enabled if the host controller reports | |
775 | * OCS FATAL ERROR with device error through sense data | |
776 | */ | |
777 | UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR = 1 << 10, | |
778 | ||
779 | /* | |
780 | * This quirk needs to be enabled if the host controller has | |
781 | * auto-hibernate capability but it doesn't work. | |
782 | */ | |
783 | UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8 = 1 << 11, | |
784 | ||
785 | /* | |
786 | * This quirk needs to disable manual flush for write booster | |
787 | */ | |
788 | UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL = 1 << 12, | |
789 | ||
790 | /* | |
791 | * This quirk needs to disable unipro timeout values | |
792 | * before power mode change | |
793 | */ | |
794 | UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13, | |
795 | ||
796 | /* | |
797 | * This quirk needs to be enabled if the host controller does not | |
798 | * support UIC command | |
799 | */ | |
800 | UFSHCD_QUIRK_BROKEN_UIC_CMD = 1 << 15, | |
801 | ||
802 | /* | |
803 | * This quirk needs to be enabled if the host controller cannot | |
804 | * support physical host configuration. | |
805 | */ | |
806 | UFSHCD_QUIRK_SKIP_PH_CONFIGURATION = 1 << 16, | |
807 | ||
808 | /* | |
809 | * This quirk needs to be enabled if the host controller has | |
810 | * 64-bit addressing supported capability but it doesn't work. | |
811 | */ | |
812 | UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS = 1 << 17, | |
813 | ||
814 | /* | |
815 | * This quirk needs to be enabled if the host controller has | |
816 | * auto-hibernate capability but it's FASTAUTO only. | |
817 | */ | |
818 | UFSHCD_QUIRK_HIBERN_FASTAUTO = 1 << 18, | |
819 | ||
820 | /* | |
821 | * This quirk needs to be enabled if the host controller needs | |
822 | * to reinit the device after switching to maximum gear. | |
823 | */ | |
824 | UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH = 1 << 19, | |
825 | ||
826 | /* | |
827 | * Some host raises interrupt (per queue) in addition to | |
828 | * CQES (traditional) when ESI is disabled. | |
829 | * Enable this quirk will disable CQES and use per queue interrupt. | |
830 | */ | |
831 | UFSHCD_QUIRK_MCQ_BROKEN_INTR = 1 << 20, | |
832 | ||
833 | /* | |
834 | * Some host does not implement SQ Run Time Command (SQRTC) register | |
835 | * thus need this quirk to skip related flow. | |
836 | */ | |
837 | UFSHCD_QUIRK_MCQ_BROKEN_RTC = 1 << 21, | |
838 | ||
839 | /* | |
840 | * This quirk needs to be enabled if the host controller supports inline | |
841 | * encryption but it needs to initialize the crypto capabilities in a | |
842 | * nonstandard way and/or needs to override blk_crypto_ll_ops. If | |
843 | * enabled, the standard code won't initialize the blk_crypto_profile; | |
844 | * ufs_hba_variant_ops::init() must do it instead. | |
845 | */ | |
846 | UFSHCD_QUIRK_CUSTOM_CRYPTO_PROFILE = 1 << 22, | |
847 | ||
848 | /* | |
849 | * This quirk needs to be enabled if the host controller supports inline | |
850 | * encryption but does not support the CRYPTO_GENERAL_ENABLE bit, i.e. | |
851 | * host controller initialization fails if that bit is set. | |
852 | */ | |
853 | UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE = 1 << 23, | |
854 | ||
855 | /* | |
856 | * This quirk needs to be enabled if the host controller driver copies | |
857 | * cryptographic keys into the PRDT in order to send them to hardware, | |
858 | * and therefore the PRDT should be zeroized after each request (as per | |
859 | * the standard best practice for managing keys). | |
860 | */ | |
861 | UFSHCD_QUIRK_KEYS_IN_PRDT = 1 << 24, | |
862 | ||
863 | /* | |
864 | * This quirk indicates that the controller reports the value 1 (not | |
865 | * supported) in the Legacy Single DoorBell Support (LSDBS) bit of the | |
866 | * Controller Capabilities register although it supports the legacy | |
867 | * single doorbell mode. | |
868 | */ | |
869 | UFSHCD_QUIRK_BROKEN_LSDBS_CAP = 1 << 25, | |
870 | }; | |
871 | ||
7feafb0a FA |
872 | struct ufs_hba { |
873 | struct udevice *dev; | |
874 | void __iomem *mmio_base; | |
875 | struct ufs_hba_ops *ops; | |
876 | struct ufs_desc_size desc_size; | |
877 | u32 capabilities; | |
878 | u32 version; | |
879 | u32 intr_mask; | |
00c54af3 | 880 | enum ufshcd_quirks quirks; |
03c6f9b6 | 881 | |
7feafb0a FA |
882 | /* Virtual memory reference */ |
883 | struct utp_transfer_cmd_desc *ucdl; | |
884 | struct utp_transfer_req_desc *utrdl; | |
885 | /* TODO: Add Task Manegement Support */ | |
886 | struct utp_task_req_desc *utmrdl; | |
887 | ||
888 | struct utp_upiu_req *ucd_req_ptr; | |
889 | struct utp_upiu_rsp *ucd_rsp_ptr; | |
890 | struct ufshcd_sg_entry *ucd_prdt_ptr; | |
891 | ||
892 | /* Power Mode information */ | |
893 | enum ufs_dev_pwr_mode curr_dev_pwr_mode; | |
894 | struct ufs_pa_layer_attr pwr_info; | |
895 | struct ufs_pwr_mode_info max_pwr_info; | |
896 | ||
897 | struct ufs_dev_cmd dev_cmd; | |
898 | }; | |
899 | ||
900 | static inline int ufshcd_ops_init(struct ufs_hba *hba) | |
901 | { | |
902 | if (hba->ops && hba->ops->init) | |
903 | return hba->ops->init(hba); | |
904 | ||
905 | return 0; | |
906 | } | |
907 | ||
b3f89c1d NA |
908 | static inline int ufshcd_ops_get_max_pwr_mode(struct ufs_hba *hba, |
909 | struct ufs_pwr_mode_info *max_pwr_info) | |
910 | { | |
911 | if (hba->ops && hba->ops->get_max_pwr_mode) | |
912 | return hba->ops->get_max_pwr_mode(hba, max_pwr_info); | |
913 | ||
914 | return 0; | |
915 | } | |
916 | ||
7feafb0a FA |
917 | static inline int ufshcd_ops_hce_enable_notify(struct ufs_hba *hba, |
918 | bool status) | |
919 | { | |
920 | if (hba->ops && hba->ops->hce_enable_notify) | |
921 | return hba->ops->hce_enable_notify(hba, status); | |
922 | ||
923 | return 0; | |
924 | } | |
925 | ||
926 | static inline int ufshcd_ops_link_startup_notify(struct ufs_hba *hba, | |
927 | bool status) | |
928 | { | |
929 | if (hba->ops && hba->ops->link_startup_notify) | |
930 | return hba->ops->link_startup_notify(hba, status); | |
931 | ||
932 | return 0; | |
933 | } | |
934 | ||
182e1922 NA |
935 | static inline int ufshcd_vops_device_reset(struct ufs_hba *hba) |
936 | { | |
937 | if (hba->ops && hba->ops->device_reset) | |
938 | return hba->ops->device_reset(hba); | |
939 | ||
940 | return 0; | |
941 | } | |
942 | ||
7feafb0a FA |
943 | /* Controller UFSHCI version */ |
944 | enum { | |
945 | UFSHCI_VERSION_10 = 0x00010000, /* 1.0 */ | |
946 | UFSHCI_VERSION_11 = 0x00010100, /* 1.1 */ | |
947 | UFSHCI_VERSION_20 = 0x00000200, /* 2.0 */ | |
948 | UFSHCI_VERSION_21 = 0x00000210, /* 2.1 */ | |
2ff810ae | 949 | UFSHCI_VERSION_30 = 0x00000300, /* 3.0 */ |
5b2d25a2 | 950 | UFSHCI_VERSION_31 = 0x00000310, /* 3.1 */ |
7feafb0a FA |
951 | }; |
952 | ||
953 | /* Interrupt disable masks */ | |
954 | enum { | |
955 | /* Interrupt disable mask for UFSHCI v1.0 */ | |
956 | INTERRUPT_MASK_ALL_VER_10 = 0x30FFF, | |
957 | INTERRUPT_MASK_RW_VER_10 = 0x30000, | |
958 | ||
959 | /* Interrupt disable mask for UFSHCI v1.1 */ | |
960 | INTERRUPT_MASK_ALL_VER_11 = 0x31FFF, | |
961 | ||
962 | /* Interrupt disable mask for UFSHCI v2.1 */ | |
963 | INTERRUPT_MASK_ALL_VER_21 = 0x71FFF, | |
964 | }; | |
965 | ||
966 | /* UFSHCI Registers */ | |
967 | enum { | |
968 | REG_CONTROLLER_CAPABILITIES = 0x00, | |
969 | REG_UFS_VERSION = 0x08, | |
970 | REG_CONTROLLER_DEV_ID = 0x10, | |
971 | REG_CONTROLLER_PROD_ID = 0x14, | |
972 | REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18, | |
973 | REG_INTERRUPT_STATUS = 0x20, | |
974 | REG_INTERRUPT_ENABLE = 0x24, | |
975 | REG_CONTROLLER_STATUS = 0x30, | |
976 | REG_CONTROLLER_ENABLE = 0x34, | |
977 | REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38, | |
978 | REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C, | |
979 | REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40, | |
980 | REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44, | |
981 | REG_UIC_ERROR_CODE_DME = 0x48, | |
982 | REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C, | |
983 | REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50, | |
984 | REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54, | |
985 | REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58, | |
986 | REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C, | |
987 | REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60, | |
988 | REG_UTP_TASK_REQ_LIST_BASE_L = 0x70, | |
989 | REG_UTP_TASK_REQ_LIST_BASE_H = 0x74, | |
990 | REG_UTP_TASK_REQ_DOOR_BELL = 0x78, | |
991 | REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C, | |
992 | REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80, | |
993 | REG_UIC_COMMAND = 0x90, | |
994 | REG_UIC_COMMAND_ARG_1 = 0x94, | |
995 | REG_UIC_COMMAND_ARG_2 = 0x98, | |
996 | REG_UIC_COMMAND_ARG_3 = 0x9C, | |
997 | ||
998 | UFSHCI_REG_SPACE_SIZE = 0xA0, | |
999 | ||
1000 | REG_UFS_CCAP = 0x100, | |
1001 | REG_UFS_CRYPTOCAP = 0x104, | |
1002 | ||
1003 | UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400, | |
1004 | }; | |
1005 | ||
1006 | /* Controller capability masks */ | |
1007 | enum { | |
1008 | MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F, | |
1009 | MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000, | |
1010 | MASK_AUTO_HIBERN8_SUPPORT = 0x00800000, | |
1011 | MASK_64_ADDRESSING_SUPPORT = 0x01000000, | |
1012 | MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000, | |
1013 | MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000, | |
1014 | }; | |
1015 | ||
1016 | /* Interrupt Status 20h */ | |
1017 | #define UTP_TRANSFER_REQ_COMPL 0x1 | |
1018 | #define UIC_DME_END_PT_RESET 0x2 | |
1019 | #define UIC_ERROR 0x4 | |
1020 | #define UIC_TEST_MODE 0x8 | |
1021 | #define UIC_POWER_MODE 0x10 | |
1022 | #define UIC_HIBERNATE_EXIT 0x20 | |
1023 | #define UIC_HIBERNATE_ENTER 0x40 | |
1024 | #define UIC_LINK_LOST 0x80 | |
1025 | #define UIC_LINK_STARTUP 0x100 | |
1026 | #define UTP_TASK_REQ_COMPL 0x200 | |
1027 | #define UIC_COMMAND_COMPL 0x400 | |
1028 | #define DEVICE_FATAL_ERROR 0x800 | |
1029 | #define CONTROLLER_FATAL_ERROR 0x10000 | |
1030 | #define SYSTEM_BUS_FATAL_ERROR 0x20000 | |
1031 | ||
1032 | #define UFSHCD_UIC_PWR_MASK (UIC_HIBERNATE_ENTER |\ | |
1033 | UIC_HIBERNATE_EXIT |\ | |
1034 | UIC_POWER_MODE) | |
1035 | ||
1036 | #define UFSHCD_UIC_MASK (UIC_COMMAND_COMPL | UIC_POWER_MODE) | |
1037 | ||
1038 | #define UFSHCD_ERROR_MASK (UIC_ERROR |\ | |
1039 | DEVICE_FATAL_ERROR |\ | |
1040 | CONTROLLER_FATAL_ERROR |\ | |
1041 | SYSTEM_BUS_FATAL_ERROR) | |
1042 | ||
1043 | #define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\ | |
1044 | CONTROLLER_FATAL_ERROR |\ | |
1045 | SYSTEM_BUS_FATAL_ERROR) | |
1046 | ||
1047 | /* Host Controller Enable 0x34h */ | |
1048 | #define CONTROLLER_ENABLE 0x1 | |
1049 | #define CONTROLLER_DISABLE 0x0 | |
1050 | /* HCS - Host Controller Status 30h */ | |
1051 | #define DEVICE_PRESENT 0x1 | |
1052 | #define UTP_TRANSFER_REQ_LIST_READY 0x2 | |
1053 | #define UTP_TASK_REQ_LIST_READY 0x4 | |
1054 | #define UIC_COMMAND_READY 0x8 | |
1055 | #define HOST_ERROR_INDICATOR 0x10 | |
1056 | #define DEVICE_ERROR_INDICATOR 0x20 | |
1057 | #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8) | |
1058 | ||
1059 | #define UFSHCD_STATUS_READY (UTP_TRANSFER_REQ_LIST_READY |\ | |
1060 | UTP_TASK_REQ_LIST_READY |\ | |
1061 | UIC_COMMAND_READY) | |
1062 | ||
1063 | enum { | |
1064 | PWR_OK = 0x0, | |
1065 | PWR_LOCAL = 0x01, | |
1066 | PWR_REMOTE = 0x02, | |
1067 | PWR_BUSY = 0x03, | |
1068 | PWR_ERROR_CAP = 0x04, | |
1069 | PWR_FATAL_ERROR = 0x05, | |
1070 | }; | |
1071 | ||
1072 | /* UICCMD - UIC Command */ | |
1073 | #define COMMAND_OPCODE_MASK 0xFF | |
1074 | #define GEN_SELECTOR_INDEX_MASK 0xFFFF | |
1075 | ||
1076 | #define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16) | |
1077 | #define RESET_LEVEL 0xFF | |
1078 | ||
1079 | #define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16) | |
6e7df1d1 | 1080 | #define CFG_RESULT_CODE_MASK 0xFF |
7feafb0a FA |
1081 | #define GENERIC_ERROR_CODE_MASK 0xFF |
1082 | ||
1083 | #define ufshcd_writel(hba, val, reg) \ | |
1084 | writel((val), (hba)->mmio_base + (reg)) | |
1085 | #define ufshcd_readl(hba, reg) \ | |
1086 | readl((hba)->mmio_base + (reg)) | |
1087 | ||
fdd33a7f BS |
1088 | /** |
1089 | * ufshcd_rmwl - perform read/modify/write for a controller register | |
1090 | * @hba: per adapter instance | |
1091 | * @mask: mask to apply on read value | |
1092 | * @val: actual value to write | |
1093 | * @reg: register address | |
1094 | */ | |
1095 | static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg) | |
1096 | { | |
1097 | u32 tmp; | |
1098 | ||
1099 | tmp = ufshcd_readl(hba, reg); | |
1100 | tmp &= ~mask; | |
1101 | tmp |= (val & mask); | |
1102 | ufshcd_writel(hba, tmp, reg); | |
1103 | } | |
1104 | ||
7feafb0a FA |
1105 | /* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */ |
1106 | #define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT 0x1 | |
1107 | ||
1108 | /* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */ | |
1109 | #define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1 | |
1110 | ||
1111 | int ufshcd_probe(struct udevice *dev, struct ufs_hba_ops *hba_ops); | |
1112 | ||
1113 | #endif |