Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | #ifndef __UFS_H |
| 3 | #define __UFS_H |
| 4 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 5 | #include <linux/types.h> |
Bhupesh Sharma | 4531d7c | 2024-09-30 14:44:29 +0200 | [diff] [blame] | 6 | #include <asm/io.h> |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 7 | #include "unipro.h" |
| 8 | |
Simon Glass | 0b700eb | 2020-07-19 10:15:54 -0600 | [diff] [blame] | 9 | struct udevice; |
| 10 | |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 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); |
| 699 | int (*hce_enable_notify)(struct ufs_hba *hba, |
| 700 | enum ufs_notify_change_status); |
| 701 | int (*link_startup_notify)(struct ufs_hba *hba, |
| 702 | enum ufs_notify_change_status); |
| 703 | int (*phy_initialization)(struct ufs_hba *hba); |
| 704 | }; |
| 705 | |
Bhupesh Sharma | 6da8289 | 2024-09-30 14:44:31 +0200 | [diff] [blame^] | 706 | enum ufshcd_quirks { |
| 707 | /* Interrupt aggregation support is broken */ |
| 708 | UFSHCD_QUIRK_BROKEN_INTR_AGGR = 1 << 0, |
| 709 | |
| 710 | /* |
| 711 | * delay before each dme command is required as the unipro |
| 712 | * layer has shown instabilities |
| 713 | */ |
| 714 | UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS = 1 << 1, |
| 715 | |
| 716 | /* |
| 717 | * If UFS host controller is having issue in processing LCC (Line |
| 718 | * Control Command) coming from device then enable this quirk. |
| 719 | * When this quirk is enabled, host controller driver should disable |
| 720 | * the LCC transmission on UFS device (by clearing TX_LCC_ENABLE |
| 721 | * attribute of device to 0). |
| 722 | */ |
| 723 | UFSHCD_QUIRK_BROKEN_LCC = 1 << 2, |
| 724 | |
| 725 | /* |
| 726 | * The attribute PA_RXHSUNTERMCAP specifies whether or not the |
| 727 | * inbound Link supports unterminated line in HS mode. Setting this |
| 728 | * attribute to 1 fixes moving to HS gear. |
| 729 | */ |
| 730 | UFSHCD_QUIRK_BROKEN_PA_RXHSUNTERMCAP = 1 << 3, |
| 731 | |
| 732 | /* |
| 733 | * This quirk needs to be enabled if the host controller only allows |
| 734 | * accessing the peer dme attributes in AUTO mode (FAST AUTO or |
| 735 | * SLOW AUTO). |
| 736 | */ |
| 737 | UFSHCD_QUIRK_DME_PEER_ACCESS_AUTO_MODE = 1 << 4, |
| 738 | |
| 739 | /* |
| 740 | * This quirk needs to be enabled if the host controller doesn't |
| 741 | * advertise the correct version in UFS_VER register. If this quirk |
| 742 | * is enabled, standard UFS host driver will call the vendor specific |
| 743 | * ops (get_ufs_hci_version) to get the correct version. |
| 744 | */ |
| 745 | UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION = 1 << 5, |
| 746 | |
| 747 | /* |
| 748 | * Clear handling for transfer/task request list is just opposite. |
| 749 | */ |
| 750 | UFSHCI_QUIRK_BROKEN_REQ_LIST_CLR = 1 << 6, |
| 751 | |
| 752 | /* |
| 753 | * This quirk needs to be enabled if host controller doesn't allow |
| 754 | * that the interrupt aggregation timer and counter are reset by s/w. |
| 755 | */ |
| 756 | UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR = 1 << 7, |
| 757 | |
| 758 | /* |
| 759 | * This quirks needs to be enabled if host controller cannot be |
| 760 | * enabled via HCE register. |
| 761 | */ |
| 762 | UFSHCI_QUIRK_BROKEN_HCE = 1 << 8, |
| 763 | |
| 764 | /* |
| 765 | * This quirk needs to be enabled if the host controller regards |
| 766 | * resolution of the values of PRDTO and PRDTL in UTRD as byte. |
| 767 | */ |
| 768 | UFSHCD_QUIRK_PRDT_BYTE_GRAN = 1 << 9, |
| 769 | |
| 770 | /* |
| 771 | * This quirk needs to be enabled if the host controller reports |
| 772 | * OCS FATAL ERROR with device error through sense data |
| 773 | */ |
| 774 | UFSHCD_QUIRK_BROKEN_OCS_FATAL_ERROR = 1 << 10, |
| 775 | |
| 776 | /* |
| 777 | * This quirk needs to be enabled if the host controller has |
| 778 | * auto-hibernate capability but it doesn't work. |
| 779 | */ |
| 780 | UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8 = 1 << 11, |
| 781 | |
| 782 | /* |
| 783 | * This quirk needs to disable manual flush for write booster |
| 784 | */ |
| 785 | UFSHCI_QUIRK_SKIP_MANUAL_WB_FLUSH_CTRL = 1 << 12, |
| 786 | |
| 787 | /* |
| 788 | * This quirk needs to disable unipro timeout values |
| 789 | * before power mode change |
| 790 | */ |
| 791 | UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING = 1 << 13, |
| 792 | |
| 793 | /* |
| 794 | * This quirk needs to be enabled if the host controller does not |
| 795 | * support UIC command |
| 796 | */ |
| 797 | UFSHCD_QUIRK_BROKEN_UIC_CMD = 1 << 15, |
| 798 | |
| 799 | /* |
| 800 | * This quirk needs to be enabled if the host controller cannot |
| 801 | * support physical host configuration. |
| 802 | */ |
| 803 | UFSHCD_QUIRK_SKIP_PH_CONFIGURATION = 1 << 16, |
| 804 | |
| 805 | /* |
| 806 | * This quirk needs to be enabled if the host controller has |
| 807 | * 64-bit addressing supported capability but it doesn't work. |
| 808 | */ |
| 809 | UFSHCD_QUIRK_BROKEN_64BIT_ADDRESS = 1 << 17, |
| 810 | |
| 811 | /* |
| 812 | * This quirk needs to be enabled if the host controller has |
| 813 | * auto-hibernate capability but it's FASTAUTO only. |
| 814 | */ |
| 815 | UFSHCD_QUIRK_HIBERN_FASTAUTO = 1 << 18, |
| 816 | |
| 817 | /* |
| 818 | * This quirk needs to be enabled if the host controller needs |
| 819 | * to reinit the device after switching to maximum gear. |
| 820 | */ |
| 821 | UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH = 1 << 19, |
| 822 | |
| 823 | /* |
| 824 | * Some host raises interrupt (per queue) in addition to |
| 825 | * CQES (traditional) when ESI is disabled. |
| 826 | * Enable this quirk will disable CQES and use per queue interrupt. |
| 827 | */ |
| 828 | UFSHCD_QUIRK_MCQ_BROKEN_INTR = 1 << 20, |
| 829 | |
| 830 | /* |
| 831 | * Some host does not implement SQ Run Time Command (SQRTC) register |
| 832 | * thus need this quirk to skip related flow. |
| 833 | */ |
| 834 | UFSHCD_QUIRK_MCQ_BROKEN_RTC = 1 << 21, |
| 835 | |
| 836 | /* |
| 837 | * This quirk needs to be enabled if the host controller supports inline |
| 838 | * encryption but it needs to initialize the crypto capabilities in a |
| 839 | * nonstandard way and/or needs to override blk_crypto_ll_ops. If |
| 840 | * enabled, the standard code won't initialize the blk_crypto_profile; |
| 841 | * ufs_hba_variant_ops::init() must do it instead. |
| 842 | */ |
| 843 | UFSHCD_QUIRK_CUSTOM_CRYPTO_PROFILE = 1 << 22, |
| 844 | |
| 845 | /* |
| 846 | * This quirk needs to be enabled if the host controller supports inline |
| 847 | * encryption but does not support the CRYPTO_GENERAL_ENABLE bit, i.e. |
| 848 | * host controller initialization fails if that bit is set. |
| 849 | */ |
| 850 | UFSHCD_QUIRK_BROKEN_CRYPTO_ENABLE = 1 << 23, |
| 851 | |
| 852 | /* |
| 853 | * This quirk needs to be enabled if the host controller driver copies |
| 854 | * cryptographic keys into the PRDT in order to send them to hardware, |
| 855 | * and therefore the PRDT should be zeroized after each request (as per |
| 856 | * the standard best practice for managing keys). |
| 857 | */ |
| 858 | UFSHCD_QUIRK_KEYS_IN_PRDT = 1 << 24, |
| 859 | |
| 860 | /* |
| 861 | * This quirk indicates that the controller reports the value 1 (not |
| 862 | * supported) in the Legacy Single DoorBell Support (LSDBS) bit of the |
| 863 | * Controller Capabilities register although it supports the legacy |
| 864 | * single doorbell mode. |
| 865 | */ |
| 866 | UFSHCD_QUIRK_BROKEN_LSDBS_CAP = 1 << 25, |
| 867 | }; |
| 868 | |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 869 | struct ufs_hba { |
| 870 | struct udevice *dev; |
| 871 | void __iomem *mmio_base; |
| 872 | struct ufs_hba_ops *ops; |
| 873 | struct ufs_desc_size desc_size; |
| 874 | u32 capabilities; |
| 875 | u32 version; |
| 876 | u32 intr_mask; |
Bhupesh Sharma | 6da8289 | 2024-09-30 14:44:31 +0200 | [diff] [blame^] | 877 | enum ufshcd_quirks quirks; |
Marek Vasut | c2403ff | 2024-09-30 14:44:28 +0200 | [diff] [blame] | 878 | |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 879 | /* Virtual memory reference */ |
| 880 | struct utp_transfer_cmd_desc *ucdl; |
| 881 | struct utp_transfer_req_desc *utrdl; |
| 882 | /* TODO: Add Task Manegement Support */ |
| 883 | struct utp_task_req_desc *utmrdl; |
| 884 | |
| 885 | struct utp_upiu_req *ucd_req_ptr; |
| 886 | struct utp_upiu_rsp *ucd_rsp_ptr; |
| 887 | struct ufshcd_sg_entry *ucd_prdt_ptr; |
| 888 | |
| 889 | /* Power Mode information */ |
| 890 | enum ufs_dev_pwr_mode curr_dev_pwr_mode; |
| 891 | struct ufs_pa_layer_attr pwr_info; |
| 892 | struct ufs_pwr_mode_info max_pwr_info; |
| 893 | |
| 894 | struct ufs_dev_cmd dev_cmd; |
| 895 | }; |
| 896 | |
| 897 | static inline int ufshcd_ops_init(struct ufs_hba *hba) |
| 898 | { |
| 899 | if (hba->ops && hba->ops->init) |
| 900 | return hba->ops->init(hba); |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | static inline int ufshcd_ops_hce_enable_notify(struct ufs_hba *hba, |
| 906 | bool status) |
| 907 | { |
| 908 | if (hba->ops && hba->ops->hce_enable_notify) |
| 909 | return hba->ops->hce_enable_notify(hba, status); |
| 910 | |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | static inline int ufshcd_ops_link_startup_notify(struct ufs_hba *hba, |
| 915 | bool status) |
| 916 | { |
| 917 | if (hba->ops && hba->ops->link_startup_notify) |
| 918 | return hba->ops->link_startup_notify(hba, status); |
| 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | /* Controller UFSHCI version */ |
| 924 | enum { |
| 925 | UFSHCI_VERSION_10 = 0x00010000, /* 1.0 */ |
| 926 | UFSHCI_VERSION_11 = 0x00010100, /* 1.1 */ |
| 927 | UFSHCI_VERSION_20 = 0x00000200, /* 2.0 */ |
| 928 | UFSHCI_VERSION_21 = 0x00000210, /* 2.1 */ |
Marek Vasut | 3f21c66 | 2023-08-16 17:05:52 +0200 | [diff] [blame] | 929 | UFSHCI_VERSION_30 = 0x00000300, /* 3.0 */ |
Bin Meng | 3a478f9 | 2023-10-11 21:15:51 +0800 | [diff] [blame] | 930 | UFSHCI_VERSION_31 = 0x00000310, /* 3.1 */ |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 931 | }; |
| 932 | |
| 933 | /* Interrupt disable masks */ |
| 934 | enum { |
| 935 | /* Interrupt disable mask for UFSHCI v1.0 */ |
| 936 | INTERRUPT_MASK_ALL_VER_10 = 0x30FFF, |
| 937 | INTERRUPT_MASK_RW_VER_10 = 0x30000, |
| 938 | |
| 939 | /* Interrupt disable mask for UFSHCI v1.1 */ |
| 940 | INTERRUPT_MASK_ALL_VER_11 = 0x31FFF, |
| 941 | |
| 942 | /* Interrupt disable mask for UFSHCI v2.1 */ |
| 943 | INTERRUPT_MASK_ALL_VER_21 = 0x71FFF, |
| 944 | }; |
| 945 | |
| 946 | /* UFSHCI Registers */ |
| 947 | enum { |
| 948 | REG_CONTROLLER_CAPABILITIES = 0x00, |
| 949 | REG_UFS_VERSION = 0x08, |
| 950 | REG_CONTROLLER_DEV_ID = 0x10, |
| 951 | REG_CONTROLLER_PROD_ID = 0x14, |
| 952 | REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18, |
| 953 | REG_INTERRUPT_STATUS = 0x20, |
| 954 | REG_INTERRUPT_ENABLE = 0x24, |
| 955 | REG_CONTROLLER_STATUS = 0x30, |
| 956 | REG_CONTROLLER_ENABLE = 0x34, |
| 957 | REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38, |
| 958 | REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C, |
| 959 | REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40, |
| 960 | REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44, |
| 961 | REG_UIC_ERROR_CODE_DME = 0x48, |
| 962 | REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C, |
| 963 | REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50, |
| 964 | REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54, |
| 965 | REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58, |
| 966 | REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C, |
| 967 | REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60, |
| 968 | REG_UTP_TASK_REQ_LIST_BASE_L = 0x70, |
| 969 | REG_UTP_TASK_REQ_LIST_BASE_H = 0x74, |
| 970 | REG_UTP_TASK_REQ_DOOR_BELL = 0x78, |
| 971 | REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C, |
| 972 | REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80, |
| 973 | REG_UIC_COMMAND = 0x90, |
| 974 | REG_UIC_COMMAND_ARG_1 = 0x94, |
| 975 | REG_UIC_COMMAND_ARG_2 = 0x98, |
| 976 | REG_UIC_COMMAND_ARG_3 = 0x9C, |
| 977 | |
| 978 | UFSHCI_REG_SPACE_SIZE = 0xA0, |
| 979 | |
| 980 | REG_UFS_CCAP = 0x100, |
| 981 | REG_UFS_CRYPTOCAP = 0x104, |
| 982 | |
| 983 | UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400, |
| 984 | }; |
| 985 | |
| 986 | /* Controller capability masks */ |
| 987 | enum { |
| 988 | MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F, |
| 989 | MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000, |
| 990 | MASK_AUTO_HIBERN8_SUPPORT = 0x00800000, |
| 991 | MASK_64_ADDRESSING_SUPPORT = 0x01000000, |
| 992 | MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000, |
| 993 | MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000, |
| 994 | }; |
| 995 | |
| 996 | /* Interrupt Status 20h */ |
| 997 | #define UTP_TRANSFER_REQ_COMPL 0x1 |
| 998 | #define UIC_DME_END_PT_RESET 0x2 |
| 999 | #define UIC_ERROR 0x4 |
| 1000 | #define UIC_TEST_MODE 0x8 |
| 1001 | #define UIC_POWER_MODE 0x10 |
| 1002 | #define UIC_HIBERNATE_EXIT 0x20 |
| 1003 | #define UIC_HIBERNATE_ENTER 0x40 |
| 1004 | #define UIC_LINK_LOST 0x80 |
| 1005 | #define UIC_LINK_STARTUP 0x100 |
| 1006 | #define UTP_TASK_REQ_COMPL 0x200 |
| 1007 | #define UIC_COMMAND_COMPL 0x400 |
| 1008 | #define DEVICE_FATAL_ERROR 0x800 |
| 1009 | #define CONTROLLER_FATAL_ERROR 0x10000 |
| 1010 | #define SYSTEM_BUS_FATAL_ERROR 0x20000 |
| 1011 | |
| 1012 | #define UFSHCD_UIC_PWR_MASK (UIC_HIBERNATE_ENTER |\ |
| 1013 | UIC_HIBERNATE_EXIT |\ |
| 1014 | UIC_POWER_MODE) |
| 1015 | |
| 1016 | #define UFSHCD_UIC_MASK (UIC_COMMAND_COMPL | UIC_POWER_MODE) |
| 1017 | |
| 1018 | #define UFSHCD_ERROR_MASK (UIC_ERROR |\ |
| 1019 | DEVICE_FATAL_ERROR |\ |
| 1020 | CONTROLLER_FATAL_ERROR |\ |
| 1021 | SYSTEM_BUS_FATAL_ERROR) |
| 1022 | |
| 1023 | #define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\ |
| 1024 | CONTROLLER_FATAL_ERROR |\ |
| 1025 | SYSTEM_BUS_FATAL_ERROR) |
| 1026 | |
| 1027 | /* Host Controller Enable 0x34h */ |
| 1028 | #define CONTROLLER_ENABLE 0x1 |
| 1029 | #define CONTROLLER_DISABLE 0x0 |
| 1030 | /* HCS - Host Controller Status 30h */ |
| 1031 | #define DEVICE_PRESENT 0x1 |
| 1032 | #define UTP_TRANSFER_REQ_LIST_READY 0x2 |
| 1033 | #define UTP_TASK_REQ_LIST_READY 0x4 |
| 1034 | #define UIC_COMMAND_READY 0x8 |
| 1035 | #define HOST_ERROR_INDICATOR 0x10 |
| 1036 | #define DEVICE_ERROR_INDICATOR 0x20 |
| 1037 | #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8) |
| 1038 | |
| 1039 | #define UFSHCD_STATUS_READY (UTP_TRANSFER_REQ_LIST_READY |\ |
| 1040 | UTP_TASK_REQ_LIST_READY |\ |
| 1041 | UIC_COMMAND_READY) |
| 1042 | |
| 1043 | enum { |
| 1044 | PWR_OK = 0x0, |
| 1045 | PWR_LOCAL = 0x01, |
| 1046 | PWR_REMOTE = 0x02, |
| 1047 | PWR_BUSY = 0x03, |
| 1048 | PWR_ERROR_CAP = 0x04, |
| 1049 | PWR_FATAL_ERROR = 0x05, |
| 1050 | }; |
| 1051 | |
| 1052 | /* UICCMD - UIC Command */ |
| 1053 | #define COMMAND_OPCODE_MASK 0xFF |
| 1054 | #define GEN_SELECTOR_INDEX_MASK 0xFFFF |
| 1055 | |
| 1056 | #define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16) |
| 1057 | #define RESET_LEVEL 0xFF |
| 1058 | |
| 1059 | #define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 1060 | #define CFG_RESULT_CODE_MASK 0xFF |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 1061 | #define GENERIC_ERROR_CODE_MASK 0xFF |
| 1062 | |
| 1063 | #define ufshcd_writel(hba, val, reg) \ |
| 1064 | writel((val), (hba)->mmio_base + (reg)) |
| 1065 | #define ufshcd_readl(hba, reg) \ |
| 1066 | readl((hba)->mmio_base + (reg)) |
| 1067 | |
Bhupesh Sharma | 4531d7c | 2024-09-30 14:44:29 +0200 | [diff] [blame] | 1068 | /** |
| 1069 | * ufshcd_rmwl - perform read/modify/write for a controller register |
| 1070 | * @hba: per adapter instance |
| 1071 | * @mask: mask to apply on read value |
| 1072 | * @val: actual value to write |
| 1073 | * @reg: register address |
| 1074 | */ |
| 1075 | static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg) |
| 1076 | { |
| 1077 | u32 tmp; |
| 1078 | |
| 1079 | tmp = ufshcd_readl(hba, reg); |
| 1080 | tmp &= ~mask; |
| 1081 | tmp |= (val & mask); |
| 1082 | ufshcd_writel(hba, tmp, reg); |
| 1083 | } |
| 1084 | |
Faiz Abbas | 5cc5107 | 2019-10-15 18:24:36 +0530 | [diff] [blame] | 1085 | /* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */ |
| 1086 | #define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT 0x1 |
| 1087 | |
| 1088 | /* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */ |
| 1089 | #define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1 |
| 1090 | |
| 1091 | int ufshcd_probe(struct udevice *dev, struct ufs_hba_ops *hba_ops); |
| 1092 | |
| 1093 | #endif |