12c3d2faaSYifeng Zhao // SPDX-License-Identifier: GPL-2.0+ 22c3d2faaSYifeng Zhao /* 32c3d2faaSYifeng Zhao * Rockchip UFS Host Controller driver 42c3d2faaSYifeng Zhao * 52c3d2faaSYifeng Zhao * Copyright (C) 2024 Rockchip Electronics Co.Ltd. 62c3d2faaSYifeng Zhao */ 72c3d2faaSYifeng Zhao 82c3d2faaSYifeng Zhao #define WELL_BOOT_LU_A 0x01 92c3d2faaSYifeng Zhao #define WELL_BOOT_LU_B 0x02 102c3d2faaSYifeng Zhao 112c3d2faaSYifeng Zhao #define DEFAULT_BOOT_LUN WELL_BOOT_LU_A 122c3d2faaSYifeng Zhao #define DEFAULT_ACTIVE_LUN 0 132c3d2faaSYifeng Zhao 142c3d2faaSYifeng Zhao #define CONFIGURATION_DESC_V31_LENGTH 0xE6 152c3d2faaSYifeng Zhao #define CONFIGURATION_DESC_V22_LENGTH 0x90 162c3d2faaSYifeng Zhao #define UNIT_DESCS_COUNT 8 172c3d2faaSYifeng Zhao 182c3d2faaSYifeng Zhao /* Byte swap u16 */ 192c3d2faaSYifeng Zhao static inline uint16_t swap_16(uint16_t val) 202c3d2faaSYifeng Zhao { 212c3d2faaSYifeng Zhao return (uint16_t)((val << 8) | (val >> 8)); /* shift 8 */ 222c3d2faaSYifeng Zhao } 232c3d2faaSYifeng Zhao 242c3d2faaSYifeng Zhao /* Byte swap unsigned int */ 252c3d2faaSYifeng Zhao static inline uint32_t swap_32(uint32_t val) 262c3d2faaSYifeng Zhao { 272c3d2faaSYifeng Zhao val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); /* shift 8 */ 282c3d2faaSYifeng Zhao return (uint32_t)((val << 16) | (val >> 16)); /* shift 16 */ 292c3d2faaSYifeng Zhao } 302c3d2faaSYifeng Zhao 312c3d2faaSYifeng Zhao static inline uint16_t to_bigendian16(uint16_t val) 322c3d2faaSYifeng Zhao { 332c3d2faaSYifeng Zhao #ifdef HOST_BIG_ENDIAN 342c3d2faaSYifeng Zhao return val; 352c3d2faaSYifeng Zhao #else 362c3d2faaSYifeng Zhao return swap_16(val); 372c3d2faaSYifeng Zhao #endif 382c3d2faaSYifeng Zhao } 392c3d2faaSYifeng Zhao 402c3d2faaSYifeng Zhao static inline uint32_t to_bigendian32(uint32_t val) 412c3d2faaSYifeng Zhao { 422c3d2faaSYifeng Zhao #ifdef HOST_BIG_ENDIAN 432c3d2faaSYifeng Zhao return val; 442c3d2faaSYifeng Zhao #else 452c3d2faaSYifeng Zhao return swap_32(val); 462c3d2faaSYifeng Zhao #endif 472c3d2faaSYifeng Zhao } 482c3d2faaSYifeng Zhao 492c3d2faaSYifeng Zhao enum attr_id { 502c3d2faaSYifeng Zhao B_BOOT_LUNEN = 0x0, 512c3d2faaSYifeng Zhao B_CURRENT_PM = 0x2, 522c3d2faaSYifeng Zhao B_ACTIV_ICC_LEVEL = 0x3, 532c3d2faaSYifeng Zhao B_OUT_OF_ORDER_DATAEN = 0x4, 542c3d2faaSYifeng Zhao B_BCKGND_OPS_STATUS = 0x5, 552c3d2faaSYifeng Zhao B_PURGE_STATUS = 0x6, 562c3d2faaSYifeng Zhao B_MAX_DATA_IN_SIZE = 0x7, 572c3d2faaSYifeng Zhao B_MAX_DATA_OUT_SIZE = 0x8, 582c3d2faaSYifeng Zhao D_DYN_CAP_NEEDED = 0x9, 592c3d2faaSYifeng Zhao B_REFCLK_FREQ = 0xA, 602c3d2faaSYifeng Zhao B_CONFIG_DESC_LOCK = 0xB, 612c3d2faaSYifeng Zhao B_MAX_NUM_OF_RTT = 0xC, 622c3d2faaSYifeng Zhao W_EXCEPTION_EVENT_CONTROL = 0xD, 632c3d2faaSYifeng Zhao W_EXCEPTION_EVENT_STATUS = 0xE, 642c3d2faaSYifeng Zhao D_SECONDS_PASSED = 0xF, 652c3d2faaSYifeng Zhao W_CONTEXT_CONF = 0x10, 662c3d2faaSYifeng Zhao D_CORR_PRG_BLKNUM = 0x11 672c3d2faaSYifeng Zhao }; 682c3d2faaSYifeng Zhao 692c3d2faaSYifeng Zhao struct ufs_dev_desc_configuration_param { 702c3d2faaSYifeng Zhao uint8_t b_length; 712c3d2faaSYifeng Zhao uint8_t b_descriptor_idn; 722c3d2faaSYifeng Zhao uint8_t b_conf_desc_continue; 732c3d2faaSYifeng Zhao uint8_t b_boot_enable; 742c3d2faaSYifeng Zhao uint8_t b_descr_access_en; 752c3d2faaSYifeng Zhao uint8_t b_init_power_mode; 762c3d2faaSYifeng Zhao uint8_t b_high_priority_lun; 772c3d2faaSYifeng Zhao uint8_t b_secure_removal_type; 782c3d2faaSYifeng Zhao uint8_t b_init_active_icc_level; 792c3d2faaSYifeng Zhao uint16_t w_periodic_rtc_update; 80*1865a7e4SYifeng Zhao uint8_t reserved[5]; /* 5 reserved, 11 in ufs3.1 */ 81*1865a7e4SYifeng Zhao uint8_t b_write_booster_buffer_reserve_user_space_en; 82*1865a7e4SYifeng Zhao uint8_t b_write_booster_buffer_type; 83*1865a7e4SYifeng Zhao uint32_t d_num_shared_write_booster_buffer_alloc_units; 842c3d2faaSYifeng Zhao } __attribute__ ((packed)); 852c3d2faaSYifeng Zhao 862c3d2faaSYifeng Zhao struct ufs_unit_desc_configuration_param { 872c3d2faaSYifeng Zhao uint8_t b_lu_enable; 882c3d2faaSYifeng Zhao uint8_t b_boot_lun_id; 892c3d2faaSYifeng Zhao uint8_t b_lu_write_protect; 902c3d2faaSYifeng Zhao uint8_t b_memory_type; 912c3d2faaSYifeng Zhao uint32_t d_num_alloc_units; 922c3d2faaSYifeng Zhao uint8_t b_data_reliability; 932c3d2faaSYifeng Zhao uint8_t b_logical_block_size; 942c3d2faaSYifeng Zhao uint8_t b_provisioning_type; 952c3d2faaSYifeng Zhao uint16_t w_context_capabilities; 962c3d2faaSYifeng Zhao uint8_t reserved[13]; /* 3 reserved, 13 in ufs3.1 */ 972c3d2faaSYifeng Zhao } __attribute__ ((packed)); 982c3d2faaSYifeng Zhao 992c3d2faaSYifeng Zhao struct ufs_configuration_descriptor { 1002c3d2faaSYifeng Zhao struct ufs_dev_desc_configuration_param dev_desc_conf_param; 1012c3d2faaSYifeng Zhao struct ufs_unit_desc_configuration_param unit_desc_conf_param[UNIT_DESCS_COUNT]; 1022c3d2faaSYifeng Zhao } __attribute__ ((packed)); 1032c3d2faaSYifeng Zhao 1042c3d2faaSYifeng Zhao struct ufs_geometry_descriptor { 1052c3d2faaSYifeng Zhao uint8_t b_length; 1062c3d2faaSYifeng Zhao uint8_t b_descriptor_idn; 1072c3d2faaSYifeng Zhao uint8_t b_media_technology; 1082c3d2faaSYifeng Zhao uint8_t reserved; 1092c3d2faaSYifeng Zhao uint64_t q_total_raw_device_capacity; 1102c3d2faaSYifeng Zhao uint8_t b_max_number_lu; 1112c3d2faaSYifeng Zhao uint32_t d_segment_size; 1122c3d2faaSYifeng Zhao uint8_t b_allocation_unit_size; 1132c3d2faaSYifeng Zhao uint8_t b_min_addr_block_size; 1142c3d2faaSYifeng Zhao uint8_t b_optimal_read_block_size; 1152c3d2faaSYifeng Zhao uint8_t b_optimal_write_block_size; 1162c3d2faaSYifeng Zhao uint8_t b_max_in_buffer_size; 1172c3d2faaSYifeng Zhao uint8_t b_max_out_buffer_size; 1182c3d2faaSYifeng Zhao uint8_t b_rpmb_read_write_size; 1192c3d2faaSYifeng Zhao uint8_t b_dynamic_capacity_resource_policy; 1202c3d2faaSYifeng Zhao uint8_t b_data_ordering; 1212c3d2faaSYifeng Zhao uint8_t b_max_contex_id_number; 1222c3d2faaSYifeng Zhao uint8_t b_sys_data_tag_unit_size; 1232c3d2faaSYifeng Zhao uint8_t b_sys_data_tag_res_size; 1242c3d2faaSYifeng Zhao uint8_t b_supported_sec_rtypes; 1252c3d2faaSYifeng Zhao uint16_t w_supported_memory_types; 1262c3d2faaSYifeng Zhao uint32_t d_system_code_max_alloc_u; 1272c3d2faaSYifeng Zhao uint16_t w_system_code_cap_adj_fac; 1282c3d2faaSYifeng Zhao uint32_t d_non_persist_max_alloc_u; 1292c3d2faaSYifeng Zhao uint16_t w_non_persist_cap_adj_fac; 1302c3d2faaSYifeng Zhao uint32_t d_enhanced1_max_alloc_u; 1312c3d2faaSYifeng Zhao uint16_t w_enhanced1_cap_adj_fac; 1322c3d2faaSYifeng Zhao uint32_t d_enhanced2_max_alloc_u; 1332c3d2faaSYifeng Zhao uint16_t w_enhanced2_cap_adj_fac; 1342c3d2faaSYifeng Zhao uint32_t d_enhanced3_max_alloc_u; 1352c3d2faaSYifeng Zhao uint16_t w_enhanced3_cap_adj_fac; 1362c3d2faaSYifeng Zhao uint32_t d_enhanced4_max_alloc_u; 1372c3d2faaSYifeng Zhao uint16_t w_enhanced4_cap_adj_fac; 1382c3d2faaSYifeng Zhao uint32_t d_optimal_logical_block_size; 139*1865a7e4SYifeng Zhao /* 15 reserved in ufs3.1 */ 140*1865a7e4SYifeng Zhao uint8_t b_hpb_region_size; 141*1865a7e4SYifeng Zhao uint8_t b_hpb_number_lu; 142*1865a7e4SYifeng Zhao uint8_t b_hpb_sub_region_size; 143*1865a7e4SYifeng Zhao uint16_t w_device_max_active_hpb_regions; 144*1865a7e4SYifeng Zhao uint16_t w_eserved; 145*1865a7e4SYifeng Zhao uint32_t d_write_booster_buffer_max_alloc_units; 146*1865a7e4SYifeng Zhao uint8_t b_device_max_write_booster_lus; 147*1865a7e4SYifeng Zhao uint8_t b_write_booster_buffer_cap_adj_fac; 148*1865a7e4SYifeng Zhao uint8_t b_supported_write_booster_buffer_user_space_reduction_types; 149*1865a7e4SYifeng Zhao uint8_t b_supported_write_booster_buffer_types; 1502c3d2faaSYifeng Zhao } __attribute__ ((packed)); 151