18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Universal Flash Storage Host controller driver 48c2ecf20Sopenharmony_ci * Copyright (C) 2011-2013 Samsung India Software Operations 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Authors: 78c2ecf20Sopenharmony_ci * Santosh Yaraganavi <santosh.sy@samsung.com> 88c2ecf20Sopenharmony_ci * Vinayak Holikatti <h.vinayak@samsung.com> 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef _UFSHCI_H 128c2ecf20Sopenharmony_ci#define _UFSHCI_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cienum { 158c2ecf20Sopenharmony_ci TASK_REQ_UPIU_SIZE_DWORDS = 8, 168c2ecf20Sopenharmony_ci TASK_RSP_UPIU_SIZE_DWORDS = 8, 178c2ecf20Sopenharmony_ci ALIGNED_UPIU_SIZE = 512, 188c2ecf20Sopenharmony_ci}; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* UFSHCI Registers */ 218c2ecf20Sopenharmony_cienum { 228c2ecf20Sopenharmony_ci REG_CONTROLLER_CAPABILITIES = 0x00, 238c2ecf20Sopenharmony_ci REG_UFS_VERSION = 0x08, 248c2ecf20Sopenharmony_ci REG_CONTROLLER_DEV_ID = 0x10, 258c2ecf20Sopenharmony_ci REG_CONTROLLER_PROD_ID = 0x14, 268c2ecf20Sopenharmony_ci REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18, 278c2ecf20Sopenharmony_ci REG_INTERRUPT_STATUS = 0x20, 288c2ecf20Sopenharmony_ci REG_INTERRUPT_ENABLE = 0x24, 298c2ecf20Sopenharmony_ci REG_CONTROLLER_STATUS = 0x30, 308c2ecf20Sopenharmony_ci REG_CONTROLLER_ENABLE = 0x34, 318c2ecf20Sopenharmony_ci REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38, 328c2ecf20Sopenharmony_ci REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C, 338c2ecf20Sopenharmony_ci REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40, 348c2ecf20Sopenharmony_ci REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44, 358c2ecf20Sopenharmony_ci REG_UIC_ERROR_CODE_DME = 0x48, 368c2ecf20Sopenharmony_ci REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C, 378c2ecf20Sopenharmony_ci REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50, 388c2ecf20Sopenharmony_ci REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54, 398c2ecf20Sopenharmony_ci REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58, 408c2ecf20Sopenharmony_ci REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C, 418c2ecf20Sopenharmony_ci REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60, 428c2ecf20Sopenharmony_ci REG_UTP_TASK_REQ_LIST_BASE_L = 0x70, 438c2ecf20Sopenharmony_ci REG_UTP_TASK_REQ_LIST_BASE_H = 0x74, 448c2ecf20Sopenharmony_ci REG_UTP_TASK_REQ_DOOR_BELL = 0x78, 458c2ecf20Sopenharmony_ci REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C, 468c2ecf20Sopenharmony_ci REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80, 478c2ecf20Sopenharmony_ci REG_UIC_COMMAND = 0x90, 488c2ecf20Sopenharmony_ci REG_UIC_COMMAND_ARG_1 = 0x94, 498c2ecf20Sopenharmony_ci REG_UIC_COMMAND_ARG_2 = 0x98, 508c2ecf20Sopenharmony_ci REG_UIC_COMMAND_ARG_3 = 0x9C, 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci UFSHCI_REG_SPACE_SIZE = 0xA0, 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci REG_UFS_CCAP = 0x100, 558c2ecf20Sopenharmony_ci REG_UFS_CRYPTOCAP = 0x104, 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400, 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* Controller capability masks */ 618c2ecf20Sopenharmony_cienum { 628c2ecf20Sopenharmony_ci MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F, 638c2ecf20Sopenharmony_ci MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000, 648c2ecf20Sopenharmony_ci MASK_AUTO_HIBERN8_SUPPORT = 0x00800000, 658c2ecf20Sopenharmony_ci MASK_64_ADDRESSING_SUPPORT = 0x01000000, 668c2ecf20Sopenharmony_ci MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000, 678c2ecf20Sopenharmony_ci MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000, 688c2ecf20Sopenharmony_ci MASK_CRYPTO_SUPPORT = 0x10000000, 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define UFS_MASK(mask, offset) ((mask) << (offset)) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* UFS Version 08h */ 748c2ecf20Sopenharmony_ci#define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0) 758c2ecf20Sopenharmony_ci#define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* Controller UFSHCI version */ 788c2ecf20Sopenharmony_cienum { 798c2ecf20Sopenharmony_ci UFSHCI_VERSION_10 = 0x00010000, /* 1.0 */ 808c2ecf20Sopenharmony_ci UFSHCI_VERSION_11 = 0x00010100, /* 1.1 */ 818c2ecf20Sopenharmony_ci UFSHCI_VERSION_20 = 0x00000200, /* 2.0 */ 828c2ecf20Sopenharmony_ci UFSHCI_VERSION_21 = 0x00000210, /* 2.1 */ 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* 868c2ecf20Sopenharmony_ci * HCDDID - Host Controller Identification Descriptor 878c2ecf20Sopenharmony_ci * - Device ID and Device Class 10h 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_ci#define DEVICE_CLASS UFS_MASK(0xFFFF, 0) 908c2ecf20Sopenharmony_ci#define DEVICE_ID UFS_MASK(0xFF, 24) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* 938c2ecf20Sopenharmony_ci * HCPMID - Host Controller Identification Descriptor 948c2ecf20Sopenharmony_ci * - Product/Manufacturer ID 14h 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci#define MANUFACTURE_ID_MASK UFS_MASK(0xFFFF, 0) 978c2ecf20Sopenharmony_ci#define PRODUCT_ID_MASK UFS_MASK(0xFFFF, 16) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* AHIT - Auto-Hibernate Idle Timer */ 1008c2ecf20Sopenharmony_ci#define UFSHCI_AHIBERN8_TIMER_MASK GENMASK(9, 0) 1018c2ecf20Sopenharmony_ci#define UFSHCI_AHIBERN8_SCALE_MASK GENMASK(12, 10) 1028c2ecf20Sopenharmony_ci#define UFSHCI_AHIBERN8_SCALE_FACTOR 10 1038c2ecf20Sopenharmony_ci#define UFSHCI_AHIBERN8_MAX (1023 * 100000) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* 1068c2ecf20Sopenharmony_ci * IS - Interrupt Status - 20h 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_ci#define UTP_TRANSFER_REQ_COMPL 0x1 1098c2ecf20Sopenharmony_ci#define UIC_DME_END_PT_RESET 0x2 1108c2ecf20Sopenharmony_ci#define UIC_ERROR 0x4 1118c2ecf20Sopenharmony_ci#define UIC_TEST_MODE 0x8 1128c2ecf20Sopenharmony_ci#define UIC_POWER_MODE 0x10 1138c2ecf20Sopenharmony_ci#define UIC_HIBERNATE_EXIT 0x20 1148c2ecf20Sopenharmony_ci#define UIC_HIBERNATE_ENTER 0x40 1158c2ecf20Sopenharmony_ci#define UIC_LINK_LOST 0x80 1168c2ecf20Sopenharmony_ci#define UIC_LINK_STARTUP 0x100 1178c2ecf20Sopenharmony_ci#define UTP_TASK_REQ_COMPL 0x200 1188c2ecf20Sopenharmony_ci#define UIC_COMMAND_COMPL 0x400 1198c2ecf20Sopenharmony_ci#define DEVICE_FATAL_ERROR 0x800 1208c2ecf20Sopenharmony_ci#define CONTROLLER_FATAL_ERROR 0x10000 1218c2ecf20Sopenharmony_ci#define SYSTEM_BUS_FATAL_ERROR 0x20000 1228c2ecf20Sopenharmony_ci#define CRYPTO_ENGINE_FATAL_ERROR 0x40000 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define UFSHCD_UIC_HIBERN8_MASK (UIC_HIBERNATE_ENTER |\ 1258c2ecf20Sopenharmony_ci UIC_HIBERNATE_EXIT) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define UFSHCD_UIC_PWR_MASK (UFSHCD_UIC_HIBERN8_MASK |\ 1288c2ecf20Sopenharmony_ci UIC_POWER_MODE) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define UFSHCD_UIC_MASK (UIC_COMMAND_COMPL | UFSHCD_UIC_PWR_MASK) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#define UFSHCD_ERROR_MASK (UIC_ERROR | INT_FATAL_ERRORS) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\ 1358c2ecf20Sopenharmony_ci CONTROLLER_FATAL_ERROR |\ 1368c2ecf20Sopenharmony_ci SYSTEM_BUS_FATAL_ERROR |\ 1378c2ecf20Sopenharmony_ci CRYPTO_ENGINE_FATAL_ERROR |\ 1388c2ecf20Sopenharmony_ci UIC_LINK_LOST) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/* HCS - Host Controller Status 30h */ 1418c2ecf20Sopenharmony_ci#define DEVICE_PRESENT 0x1 1428c2ecf20Sopenharmony_ci#define UTP_TRANSFER_REQ_LIST_READY 0x2 1438c2ecf20Sopenharmony_ci#define UTP_TASK_REQ_LIST_READY 0x4 1448c2ecf20Sopenharmony_ci#define UIC_COMMAND_READY 0x8 1458c2ecf20Sopenharmony_ci#define HOST_ERROR_INDICATOR 0x10 1468c2ecf20Sopenharmony_ci#define DEVICE_ERROR_INDICATOR 0x20 1478c2ecf20Sopenharmony_ci#define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci#define UFSHCD_STATUS_READY (UTP_TRANSFER_REQ_LIST_READY |\ 1508c2ecf20Sopenharmony_ci UTP_TASK_REQ_LIST_READY |\ 1518c2ecf20Sopenharmony_ci UIC_COMMAND_READY) 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cienum { 1548c2ecf20Sopenharmony_ci PWR_OK = 0x0, 1558c2ecf20Sopenharmony_ci PWR_LOCAL = 0x01, 1568c2ecf20Sopenharmony_ci PWR_REMOTE = 0x02, 1578c2ecf20Sopenharmony_ci PWR_BUSY = 0x03, 1588c2ecf20Sopenharmony_ci PWR_ERROR_CAP = 0x04, 1598c2ecf20Sopenharmony_ci PWR_FATAL_ERROR = 0x05, 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* HCE - Host Controller Enable 34h */ 1638c2ecf20Sopenharmony_ci#define CONTROLLER_ENABLE 0x1 1648c2ecf20Sopenharmony_ci#define CONTROLLER_DISABLE 0x0 1658c2ecf20Sopenharmony_ci#define CRYPTO_GENERAL_ENABLE 0x2 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/* UECPA - Host UIC Error Code PHY Adapter Layer 38h */ 1688c2ecf20Sopenharmony_ci#define UIC_PHY_ADAPTER_LAYER_ERROR 0x80000000 1698c2ecf20Sopenharmony_ci#define UIC_PHY_ADAPTER_LAYER_ERROR_CODE_MASK 0x1F 1708c2ecf20Sopenharmony_ci#define UIC_PHY_ADAPTER_LAYER_LANE_ERR_MASK 0xF 1718c2ecf20Sopenharmony_ci#define UIC_PHY_ADAPTER_LAYER_GENERIC_ERROR 0x10 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci/* UECDL - Host UIC Error Code Data Link Layer 3Ch */ 1748c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR 0x80000000 1758c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0xFFFF 1768c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_TCX_REP_TIMER_EXP 0x2 1778c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_AFCX_REQ_TIMER_EXP 0x4 1788c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_FCX_PRO_TIMER_EXP 0x8 1798c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_RX_BUF_OF 0x20 1808c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000 1818c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_NAC_RECEIVED 0x0001 1828c2ecf20Sopenharmony_ci#define UIC_DATA_LINK_LAYER_ERROR_TCx_REPLAY_TIMEOUT 0x0002 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci/* UECN - Host UIC Error Code Network Layer 40h */ 1858c2ecf20Sopenharmony_ci#define UIC_NETWORK_LAYER_ERROR 0x80000000 1868c2ecf20Sopenharmony_ci#define UIC_NETWORK_LAYER_ERROR_CODE_MASK 0x7 1878c2ecf20Sopenharmony_ci#define UIC_NETWORK_UNSUPPORTED_HEADER_TYPE 0x1 1888c2ecf20Sopenharmony_ci#define UIC_NETWORK_BAD_DEVICEID_ENC 0x2 1898c2ecf20Sopenharmony_ci#define UIC_NETWORK_LHDR_TRAP_PACKET_DROPPING 0x4 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci/* UECT - Host UIC Error Code Transport Layer 44h */ 1928c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_LAYER_ERROR 0x80000000 1938c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_LAYER_ERROR_CODE_MASK 0x7F 1948c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_UNSUPPORTED_HEADER_TYPE 0x1 1958c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_UNKNOWN_CPORTID 0x2 1968c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_NO_CONNECTION_RX 0x4 1978c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_CONTROLLED_SEGMENT_DROPPING 0x8 1988c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_BAD_TC 0x10 1998c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_E2E_CREDIT_OVERFOW 0x20 2008c2ecf20Sopenharmony_ci#define UIC_TRANSPORT_SAFETY_VALUE_DROPPING 0x40 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci/* UECDME - Host UIC Error Code DME 48h */ 2038c2ecf20Sopenharmony_ci#define UIC_DME_ERROR 0x80000000 2048c2ecf20Sopenharmony_ci#define UIC_DME_ERROR_CODE_MASK 0x1 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci/* UTRIACR - Interrupt Aggregation control register - 0x4Ch */ 2078c2ecf20Sopenharmony_ci#define INT_AGGR_TIMEOUT_VAL_MASK 0xFF 2088c2ecf20Sopenharmony_ci#define INT_AGGR_COUNTER_THRESHOLD_MASK UFS_MASK(0x1F, 8) 2098c2ecf20Sopenharmony_ci#define INT_AGGR_COUNTER_AND_TIMER_RESET 0x10000 2108c2ecf20Sopenharmony_ci#define INT_AGGR_STATUS_BIT 0x100000 2118c2ecf20Sopenharmony_ci#define INT_AGGR_PARAM_WRITE 0x1000000 2128c2ecf20Sopenharmony_ci#define INT_AGGR_ENABLE 0x80000000 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci/* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */ 2158c2ecf20Sopenharmony_ci#define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT 0x1 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci/* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */ 2188c2ecf20Sopenharmony_ci#define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci/* UICCMD - UIC Command */ 2218c2ecf20Sopenharmony_ci#define COMMAND_OPCODE_MASK 0xFF 2228c2ecf20Sopenharmony_ci#define GEN_SELECTOR_INDEX_MASK 0xFFFF 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci#define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16) 2258c2ecf20Sopenharmony_ci#define RESET_LEVEL 0xFF 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci#define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16) 2288c2ecf20Sopenharmony_ci#define CONFIG_RESULT_CODE_MASK 0xFF 2298c2ecf20Sopenharmony_ci#define GENERIC_ERROR_CODE_MASK 0xFF 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci/* GenSelectorIndex calculation macros for M-PHY attributes */ 2328c2ecf20Sopenharmony_ci#define UIC_ARG_MPHY_TX_GEN_SEL_INDEX(lane) (lane) 2338c2ecf20Sopenharmony_ci#define UIC_ARG_MPHY_RX_GEN_SEL_INDEX(lane) (PA_MAXDATALANES + (lane)) 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci#define UIC_ARG_MIB_SEL(attr, sel) ((((attr) & 0xFFFF) << 16) |\ 2368c2ecf20Sopenharmony_ci ((sel) & 0xFFFF)) 2378c2ecf20Sopenharmony_ci#define UIC_ARG_MIB(attr) UIC_ARG_MIB_SEL(attr, 0) 2388c2ecf20Sopenharmony_ci#define UIC_ARG_ATTR_TYPE(t) (((t) & 0xFF) << 16) 2398c2ecf20Sopenharmony_ci#define UIC_GET_ATTR_ID(v) (((v) >> 16) & 0xFFFF) 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci/* Link Status*/ 2428c2ecf20Sopenharmony_cienum link_status { 2438c2ecf20Sopenharmony_ci UFSHCD_LINK_IS_DOWN = 1, 2448c2ecf20Sopenharmony_ci UFSHCD_LINK_IS_UP = 2, 2458c2ecf20Sopenharmony_ci}; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci/* UIC Commands */ 2488c2ecf20Sopenharmony_cienum uic_cmd_dme { 2498c2ecf20Sopenharmony_ci UIC_CMD_DME_GET = 0x01, 2508c2ecf20Sopenharmony_ci UIC_CMD_DME_SET = 0x02, 2518c2ecf20Sopenharmony_ci UIC_CMD_DME_PEER_GET = 0x03, 2528c2ecf20Sopenharmony_ci UIC_CMD_DME_PEER_SET = 0x04, 2538c2ecf20Sopenharmony_ci UIC_CMD_DME_POWERON = 0x10, 2548c2ecf20Sopenharmony_ci UIC_CMD_DME_POWEROFF = 0x11, 2558c2ecf20Sopenharmony_ci UIC_CMD_DME_ENABLE = 0x12, 2568c2ecf20Sopenharmony_ci UIC_CMD_DME_RESET = 0x14, 2578c2ecf20Sopenharmony_ci UIC_CMD_DME_END_PT_RST = 0x15, 2588c2ecf20Sopenharmony_ci UIC_CMD_DME_LINK_STARTUP = 0x16, 2598c2ecf20Sopenharmony_ci UIC_CMD_DME_HIBER_ENTER = 0x17, 2608c2ecf20Sopenharmony_ci UIC_CMD_DME_HIBER_EXIT = 0x18, 2618c2ecf20Sopenharmony_ci UIC_CMD_DME_TEST_MODE = 0x1A, 2628c2ecf20Sopenharmony_ci}; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci/* UIC Config result code / Generic error code */ 2658c2ecf20Sopenharmony_cienum { 2668c2ecf20Sopenharmony_ci UIC_CMD_RESULT_SUCCESS = 0x00, 2678c2ecf20Sopenharmony_ci UIC_CMD_RESULT_INVALID_ATTR = 0x01, 2688c2ecf20Sopenharmony_ci UIC_CMD_RESULT_FAILURE = 0x01, 2698c2ecf20Sopenharmony_ci UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02, 2708c2ecf20Sopenharmony_ci UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03, 2718c2ecf20Sopenharmony_ci UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04, 2728c2ecf20Sopenharmony_ci UIC_CMD_RESULT_BAD_INDEX = 0x05, 2738c2ecf20Sopenharmony_ci UIC_CMD_RESULT_LOCKED_ATTR = 0x06, 2748c2ecf20Sopenharmony_ci UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07, 2758c2ecf20Sopenharmony_ci UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08, 2768c2ecf20Sopenharmony_ci UIC_CMD_RESULT_BUSY = 0x09, 2778c2ecf20Sopenharmony_ci UIC_CMD_RESULT_DME_FAILURE = 0x0A, 2788c2ecf20Sopenharmony_ci}; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci#define MASK_UIC_COMMAND_RESULT 0xFF 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci#define INT_AGGR_COUNTER_THLD_VAL(c) (((c) & 0x1F) << 8) 2838c2ecf20Sopenharmony_ci#define INT_AGGR_TIMEOUT_VAL(t) (((t) & 0xFF) << 0) 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci/* Interrupt disable masks */ 2868c2ecf20Sopenharmony_cienum { 2878c2ecf20Sopenharmony_ci /* Interrupt disable mask for UFSHCI v1.0 */ 2888c2ecf20Sopenharmony_ci INTERRUPT_MASK_ALL_VER_10 = 0x30FFF, 2898c2ecf20Sopenharmony_ci INTERRUPT_MASK_RW_VER_10 = 0x30000, 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* Interrupt disable mask for UFSHCI v1.1 */ 2928c2ecf20Sopenharmony_ci INTERRUPT_MASK_ALL_VER_11 = 0x31FFF, 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci /* Interrupt disable mask for UFSHCI v2.1 */ 2958c2ecf20Sopenharmony_ci INTERRUPT_MASK_ALL_VER_21 = 0x71FFF, 2968c2ecf20Sopenharmony_ci}; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci/* CCAP - Crypto Capability 100h */ 2998c2ecf20Sopenharmony_ciunion ufs_crypto_capabilities { 3008c2ecf20Sopenharmony_ci __le32 reg_val; 3018c2ecf20Sopenharmony_ci struct { 3028c2ecf20Sopenharmony_ci u8 num_crypto_cap; 3038c2ecf20Sopenharmony_ci u8 config_count; 3048c2ecf20Sopenharmony_ci u8 reserved; 3058c2ecf20Sopenharmony_ci u8 config_array_ptr; 3068c2ecf20Sopenharmony_ci }; 3078c2ecf20Sopenharmony_ci}; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cienum ufs_crypto_key_size { 3108c2ecf20Sopenharmony_ci UFS_CRYPTO_KEY_SIZE_INVALID = 0x0, 3118c2ecf20Sopenharmony_ci UFS_CRYPTO_KEY_SIZE_128 = 0x1, 3128c2ecf20Sopenharmony_ci UFS_CRYPTO_KEY_SIZE_192 = 0x2, 3138c2ecf20Sopenharmony_ci UFS_CRYPTO_KEY_SIZE_256 = 0x3, 3148c2ecf20Sopenharmony_ci UFS_CRYPTO_KEY_SIZE_512 = 0x4, 3158c2ecf20Sopenharmony_ci}; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_cienum ufs_crypto_alg { 3188c2ecf20Sopenharmony_ci UFS_CRYPTO_ALG_AES_XTS = 0x0, 3198c2ecf20Sopenharmony_ci UFS_CRYPTO_ALG_BITLOCKER_AES_CBC = 0x1, 3208c2ecf20Sopenharmony_ci UFS_CRYPTO_ALG_AES_ECB = 0x2, 3218c2ecf20Sopenharmony_ci UFS_CRYPTO_ALG_ESSIV_AES_CBC = 0x3, 3228c2ecf20Sopenharmony_ci}; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci/* x-CRYPTOCAP - Crypto Capability X */ 3258c2ecf20Sopenharmony_ciunion ufs_crypto_cap_entry { 3268c2ecf20Sopenharmony_ci __le32 reg_val; 3278c2ecf20Sopenharmony_ci struct { 3288c2ecf20Sopenharmony_ci u8 algorithm_id; 3298c2ecf20Sopenharmony_ci u8 sdus_mask; /* Supported data unit size mask */ 3308c2ecf20Sopenharmony_ci u8 key_size; 3318c2ecf20Sopenharmony_ci u8 reserved; 3328c2ecf20Sopenharmony_ci }; 3338c2ecf20Sopenharmony_ci}; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci#define UFS_CRYPTO_CONFIGURATION_ENABLE (1 << 7) 3368c2ecf20Sopenharmony_ci#define UFS_CRYPTO_KEY_MAX_SIZE 64 3378c2ecf20Sopenharmony_ci/* x-CRYPTOCFG - Crypto Configuration X */ 3388c2ecf20Sopenharmony_ciunion ufs_crypto_cfg_entry { 3398c2ecf20Sopenharmony_ci __le32 reg_val[32]; 3408c2ecf20Sopenharmony_ci struct { 3418c2ecf20Sopenharmony_ci u8 crypto_key[UFS_CRYPTO_KEY_MAX_SIZE]; 3428c2ecf20Sopenharmony_ci u8 data_unit_size; 3438c2ecf20Sopenharmony_ci u8 crypto_cap_idx; 3448c2ecf20Sopenharmony_ci u8 reserved_1; 3458c2ecf20Sopenharmony_ci u8 config_enable; 3468c2ecf20Sopenharmony_ci u8 reserved_multi_host; 3478c2ecf20Sopenharmony_ci u8 reserved_2; 3488c2ecf20Sopenharmony_ci u8 vsb[2]; 3498c2ecf20Sopenharmony_ci u8 reserved_3[56]; 3508c2ecf20Sopenharmony_ci }; 3518c2ecf20Sopenharmony_ci}; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci/* 3548c2ecf20Sopenharmony_ci * Request Descriptor Definitions 3558c2ecf20Sopenharmony_ci */ 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci/* Transfer request command type */ 3588c2ecf20Sopenharmony_cienum { 3598c2ecf20Sopenharmony_ci UTP_CMD_TYPE_SCSI = 0x0, 3608c2ecf20Sopenharmony_ci UTP_CMD_TYPE_UFS = 0x1, 3618c2ecf20Sopenharmony_ci UTP_CMD_TYPE_DEV_MANAGE = 0x2, 3628c2ecf20Sopenharmony_ci}; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci/* To accommodate UFS2.0 required Command type */ 3658c2ecf20Sopenharmony_cienum { 3668c2ecf20Sopenharmony_ci UTP_CMD_TYPE_UFS_STORAGE = 0x1, 3678c2ecf20Sopenharmony_ci}; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_cienum { 3708c2ecf20Sopenharmony_ci UTP_SCSI_COMMAND = 0x00000000, 3718c2ecf20Sopenharmony_ci UTP_NATIVE_UFS_COMMAND = 0x10000000, 3728c2ecf20Sopenharmony_ci UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000, 3738c2ecf20Sopenharmony_ci UTP_REQ_DESC_INT_CMD = 0x01000000, 3748c2ecf20Sopenharmony_ci UTP_REQ_DESC_CRYPTO_ENABLE_CMD = 0x00800000, 3758c2ecf20Sopenharmony_ci}; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci/* UTP Transfer Request Data Direction (DD) */ 3788c2ecf20Sopenharmony_cienum { 3798c2ecf20Sopenharmony_ci UTP_NO_DATA_TRANSFER = 0x00000000, 3808c2ecf20Sopenharmony_ci UTP_HOST_TO_DEVICE = 0x02000000, 3818c2ecf20Sopenharmony_ci UTP_DEVICE_TO_HOST = 0x04000000, 3828c2ecf20Sopenharmony_ci}; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci/* Overall command status values */ 3858c2ecf20Sopenharmony_cienum { 3868c2ecf20Sopenharmony_ci OCS_SUCCESS = 0x0, 3878c2ecf20Sopenharmony_ci OCS_INVALID_CMD_TABLE_ATTR = 0x1, 3888c2ecf20Sopenharmony_ci OCS_INVALID_PRDT_ATTR = 0x2, 3898c2ecf20Sopenharmony_ci OCS_MISMATCH_DATA_BUF_SIZE = 0x3, 3908c2ecf20Sopenharmony_ci OCS_MISMATCH_RESP_UPIU_SIZE = 0x4, 3918c2ecf20Sopenharmony_ci OCS_PEER_COMM_FAILURE = 0x5, 3928c2ecf20Sopenharmony_ci OCS_ABORTED = 0x6, 3938c2ecf20Sopenharmony_ci OCS_FATAL_ERROR = 0x7, 3948c2ecf20Sopenharmony_ci OCS_DEVICE_FATAL_ERROR = 0x8, 3958c2ecf20Sopenharmony_ci OCS_INVALID_CRYPTO_CONFIG = 0x9, 3968c2ecf20Sopenharmony_ci OCS_GENERAL_CRYPTO_ERROR = 0xA, 3978c2ecf20Sopenharmony_ci OCS_INVALID_COMMAND_STATUS = 0x0F, 3988c2ecf20Sopenharmony_ci MASK_OCS = 0x0F, 3998c2ecf20Sopenharmony_ci}; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci/* The maximum length of the data byte count field in the PRDT is 256KB */ 4028c2ecf20Sopenharmony_ci#define PRDT_DATA_BYTE_COUNT_MAX (256 * 1024) 4038c2ecf20Sopenharmony_ci/* The granularity of the data byte count field in the PRDT is 32-bit */ 4048c2ecf20Sopenharmony_ci#define PRDT_DATA_BYTE_COUNT_PAD 4 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci/** 4078c2ecf20Sopenharmony_ci * struct ufshcd_sg_entry - UFSHCI PRD Entry 4088c2ecf20Sopenharmony_ci * @base_addr: Lower 32bit physical address DW-0 4098c2ecf20Sopenharmony_ci * @upper_addr: Upper 32bit physical address DW-1 4108c2ecf20Sopenharmony_ci * @reserved: Reserved for future use DW-2 4118c2ecf20Sopenharmony_ci * @size: size of physical segment DW-3 4128c2ecf20Sopenharmony_ci */ 4138c2ecf20Sopenharmony_cistruct ufshcd_sg_entry { 4148c2ecf20Sopenharmony_ci __le32 base_addr; 4158c2ecf20Sopenharmony_ci __le32 upper_addr; 4168c2ecf20Sopenharmony_ci __le32 reserved; 4178c2ecf20Sopenharmony_ci __le32 size; 4188c2ecf20Sopenharmony_ci}; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci/** 4218c2ecf20Sopenharmony_ci * struct utp_transfer_cmd_desc - UFS Command Descriptor structure 4228c2ecf20Sopenharmony_ci * @command_upiu: Command UPIU Frame address 4238c2ecf20Sopenharmony_ci * @response_upiu: Response UPIU Frame address 4248c2ecf20Sopenharmony_ci * @prd_table: Physical Region Descriptor 4258c2ecf20Sopenharmony_ci */ 4268c2ecf20Sopenharmony_cistruct utp_transfer_cmd_desc { 4278c2ecf20Sopenharmony_ci u8 command_upiu[ALIGNED_UPIU_SIZE]; 4288c2ecf20Sopenharmony_ci u8 response_upiu[ALIGNED_UPIU_SIZE]; 4298c2ecf20Sopenharmony_ci struct ufshcd_sg_entry prd_table[SG_ALL]; 4308c2ecf20Sopenharmony_ci}; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci/** 4338c2ecf20Sopenharmony_ci * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD 4348c2ecf20Sopenharmony_ci * @dword0: Descriptor Header DW0 4358c2ecf20Sopenharmony_ci * @dword1: Descriptor Header DW1 4368c2ecf20Sopenharmony_ci * @dword2: Descriptor Header DW2 4378c2ecf20Sopenharmony_ci * @dword3: Descriptor Header DW3 4388c2ecf20Sopenharmony_ci */ 4398c2ecf20Sopenharmony_cistruct request_desc_header { 4408c2ecf20Sopenharmony_ci __le32 dword_0; 4418c2ecf20Sopenharmony_ci __le32 dword_1; 4428c2ecf20Sopenharmony_ci __le32 dword_2; 4438c2ecf20Sopenharmony_ci __le32 dword_3; 4448c2ecf20Sopenharmony_ci}; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci/** 4478c2ecf20Sopenharmony_ci * struct utp_transfer_req_desc - UTRD structure 4488c2ecf20Sopenharmony_ci * @header: UTRD header DW-0 to DW-3 4498c2ecf20Sopenharmony_ci * @command_desc_base_addr_lo: UCD base address low DW-4 4508c2ecf20Sopenharmony_ci * @command_desc_base_addr_hi: UCD base address high DW-5 4518c2ecf20Sopenharmony_ci * @response_upiu_length: response UPIU length DW-6 4528c2ecf20Sopenharmony_ci * @response_upiu_offset: response UPIU offset DW-6 4538c2ecf20Sopenharmony_ci * @prd_table_length: Physical region descriptor length DW-7 4548c2ecf20Sopenharmony_ci * @prd_table_offset: Physical region descriptor offset DW-7 4558c2ecf20Sopenharmony_ci */ 4568c2ecf20Sopenharmony_cistruct utp_transfer_req_desc { 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci /* DW 0-3 */ 4598c2ecf20Sopenharmony_ci struct request_desc_header header; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci /* DW 4-5*/ 4628c2ecf20Sopenharmony_ci __le32 command_desc_base_addr_lo; 4638c2ecf20Sopenharmony_ci __le32 command_desc_base_addr_hi; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci /* DW 6 */ 4668c2ecf20Sopenharmony_ci __le16 response_upiu_length; 4678c2ecf20Sopenharmony_ci __le16 response_upiu_offset; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci /* DW 7 */ 4708c2ecf20Sopenharmony_ci __le16 prd_table_length; 4718c2ecf20Sopenharmony_ci __le16 prd_table_offset; 4728c2ecf20Sopenharmony_ci}; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci/* 4758c2ecf20Sopenharmony_ci * UTMRD structure. 4768c2ecf20Sopenharmony_ci */ 4778c2ecf20Sopenharmony_cistruct utp_task_req_desc { 4788c2ecf20Sopenharmony_ci /* DW 0-3 */ 4798c2ecf20Sopenharmony_ci struct request_desc_header header; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci /* DW 4-11 - Task request UPIU structure */ 4828c2ecf20Sopenharmony_ci struct utp_upiu_header req_header; 4838c2ecf20Sopenharmony_ci __be32 input_param1; 4848c2ecf20Sopenharmony_ci __be32 input_param2; 4858c2ecf20Sopenharmony_ci __be32 input_param3; 4868c2ecf20Sopenharmony_ci __be32 __reserved1[2]; 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci /* DW 12-19 - Task Management Response UPIU structure */ 4898c2ecf20Sopenharmony_ci struct utp_upiu_header rsp_header; 4908c2ecf20Sopenharmony_ci __be32 output_param1; 4918c2ecf20Sopenharmony_ci __be32 output_param2; 4928c2ecf20Sopenharmony_ci __be32 __reserved2[3]; 4938c2ecf20Sopenharmony_ci}; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci#endif /* End of Header */ 496