1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Rockchip UFS Host Controller driver 4 * 5 * Copyright (C) 2024 Rockchip Electronics Co.Ltd. 6 */ 7 8 #define WELL_BOOT_LU_A 0x01 9 #define WELL_BOOT_LU_B 0x02 10 11 #define DEFAULT_BOOT_LUN WELL_BOOT_LU_A 12 #define DEFAULT_ACTIVE_LUN 0 13 14 #define CONFIGURATION_DESC_V31_LENGTH 0xE6 15 #define CONFIGURATION_DESC_V22_LENGTH 0x90 16 #define UNIT_DESCS_COUNT 8 17 18 /* Byte swap u16 */ 19 static inline uint16_t swap_16(uint16_t val) 20 { 21 return (uint16_t)((val << 8) | (val >> 8)); /* shift 8 */ 22 } 23 24 /* Byte swap unsigned int */ 25 static inline uint32_t swap_32(uint32_t val) 26 { 27 val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); /* shift 8 */ 28 return (uint32_t)((val << 16) | (val >> 16)); /* shift 16 */ 29 } 30 31 static inline uint16_t to_bigendian16(uint16_t val) 32 { 33 #ifdef HOST_BIG_ENDIAN 34 return val; 35 #else 36 return swap_16(val); 37 #endif 38 } 39 40 static inline uint32_t to_bigendian32(uint32_t val) 41 { 42 #ifdef HOST_BIG_ENDIAN 43 return val; 44 #else 45 return swap_32(val); 46 #endif 47 } 48 49 enum attr_id { 50 B_BOOT_LUNEN = 0x0, 51 B_CURRENT_PM = 0x2, 52 B_ACTIV_ICC_LEVEL = 0x3, 53 B_OUT_OF_ORDER_DATAEN = 0x4, 54 B_BCKGND_OPS_STATUS = 0x5, 55 B_PURGE_STATUS = 0x6, 56 B_MAX_DATA_IN_SIZE = 0x7, 57 B_MAX_DATA_OUT_SIZE = 0x8, 58 D_DYN_CAP_NEEDED = 0x9, 59 B_REFCLK_FREQ = 0xA, 60 B_CONFIG_DESC_LOCK = 0xB, 61 B_MAX_NUM_OF_RTT = 0xC, 62 W_EXCEPTION_EVENT_CONTROL = 0xD, 63 W_EXCEPTION_EVENT_STATUS = 0xE, 64 D_SECONDS_PASSED = 0xF, 65 W_CONTEXT_CONF = 0x10, 66 D_CORR_PRG_BLKNUM = 0x11 67 }; 68 69 struct ufs_dev_desc_configuration_param { 70 uint8_t b_length; 71 uint8_t b_descriptor_idn; 72 uint8_t b_conf_desc_continue; 73 uint8_t b_boot_enable; 74 uint8_t b_descr_access_en; 75 uint8_t b_init_power_mode; 76 uint8_t b_high_priority_lun; 77 uint8_t b_secure_removal_type; 78 uint8_t b_init_active_icc_level; 79 uint16_t w_periodic_rtc_update; 80 uint8_t reserved[5]; /* 5 reserved, 11 in ufs3.1 */ 81 uint8_t b_write_booster_buffer_reserve_user_space_en; 82 uint8_t b_write_booster_buffer_type; 83 uint32_t d_num_shared_write_booster_buffer_alloc_units; 84 } __attribute__ ((packed)); 85 86 struct ufs_unit_desc_configuration_param { 87 uint8_t b_lu_enable; 88 uint8_t b_boot_lun_id; 89 uint8_t b_lu_write_protect; 90 uint8_t b_memory_type; 91 uint32_t d_num_alloc_units; 92 uint8_t b_data_reliability; 93 uint8_t b_logical_block_size; 94 uint8_t b_provisioning_type; 95 uint16_t w_context_capabilities; 96 uint8_t reserved[13]; /* 3 reserved, 13 in ufs3.1 */ 97 } __attribute__ ((packed)); 98 99 struct ufs_configuration_descriptor { 100 struct ufs_dev_desc_configuration_param dev_desc_conf_param; 101 struct ufs_unit_desc_configuration_param unit_desc_conf_param[UNIT_DESCS_COUNT]; 102 } __attribute__ ((packed)); 103 104 struct ufs_geometry_descriptor { 105 uint8_t b_length; 106 uint8_t b_descriptor_idn; 107 uint8_t b_media_technology; 108 uint8_t reserved; 109 uint64_t q_total_raw_device_capacity; 110 uint8_t b_max_number_lu; 111 uint32_t d_segment_size; 112 uint8_t b_allocation_unit_size; 113 uint8_t b_min_addr_block_size; 114 uint8_t b_optimal_read_block_size; 115 uint8_t b_optimal_write_block_size; 116 uint8_t b_max_in_buffer_size; 117 uint8_t b_max_out_buffer_size; 118 uint8_t b_rpmb_read_write_size; 119 uint8_t b_dynamic_capacity_resource_policy; 120 uint8_t b_data_ordering; 121 uint8_t b_max_contex_id_number; 122 uint8_t b_sys_data_tag_unit_size; 123 uint8_t b_sys_data_tag_res_size; 124 uint8_t b_supported_sec_rtypes; 125 uint16_t w_supported_memory_types; 126 uint32_t d_system_code_max_alloc_u; 127 uint16_t w_system_code_cap_adj_fac; 128 uint32_t d_non_persist_max_alloc_u; 129 uint16_t w_non_persist_cap_adj_fac; 130 uint32_t d_enhanced1_max_alloc_u; 131 uint16_t w_enhanced1_cap_adj_fac; 132 uint32_t d_enhanced2_max_alloc_u; 133 uint16_t w_enhanced2_cap_adj_fac; 134 uint32_t d_enhanced3_max_alloc_u; 135 uint16_t w_enhanced3_cap_adj_fac; 136 uint32_t d_enhanced4_max_alloc_u; 137 uint16_t w_enhanced4_cap_adj_fac; 138 uint32_t d_optimal_logical_block_size; 139 /* 15 reserved in ufs3.1 */ 140 uint8_t b_hpb_region_size; 141 uint8_t b_hpb_number_lu; 142 uint8_t b_hpb_sub_region_size; 143 uint16_t w_device_max_active_hpb_regions; 144 uint16_t w_eserved; 145 uint32_t d_write_booster_buffer_max_alloc_units; 146 uint8_t b_device_max_write_booster_lus; 147 uint8_t b_write_booster_buffer_cap_adj_fac; 148 uint8_t b_supported_write_booster_buffer_user_space_reduction_types; 149 uint8_t b_supported_write_booster_buffer_types; 150 } __attribute__ ((packed)); 151