Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Universal Flash Storage Host controller driver |
| 3 | * |
| 4 | * This code is based on drivers/scsi/ufs/ufshci.h |
Vinayak Holikatti | 3b1d058 | 2013-02-25 21:44:32 +0530 | [diff] [blame] | 5 | * Copyright (C) 2011-2013 Samsung India Software Operations |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 6 | * |
Vinayak Holikatti | 3b1d058 | 2013-02-25 21:44:32 +0530 | [diff] [blame] | 7 | * Authors: |
| 8 | * Santosh Yaraganavi <santosh.sy@samsung.com> |
| 9 | * Vinayak Holikatti <h.vinayak@samsung.com> |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version 2 |
| 14 | * of the License, or (at your option) any later version. |
Vinayak Holikatti | 3b1d058 | 2013-02-25 21:44:32 +0530 | [diff] [blame] | 15 | * See the COPYING file in the top-level directory or visit |
| 16 | * <http://www.gnu.org/licenses/gpl-2.0.html> |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
Vinayak Holikatti | 3b1d058 | 2013-02-25 21:44:32 +0530 | [diff] [blame] | 23 | * This program is provided "AS IS" and "WITH ALL FAULTS" and |
| 24 | * without warranty of any kind. You are solely responsible for |
| 25 | * determining the appropriateness of using and distributing |
| 26 | * the program and assume all risks associated with your exercise |
| 27 | * of rights with respect to the program, including but not limited |
| 28 | * to infringement of third party rights, the risks and costs of |
| 29 | * program errors, damage to or loss of data, programs or equipment, |
| 30 | * and unavailability or interruption of operations. Under no |
| 31 | * circumstances will the contributor of this Program be liable for |
| 32 | * any damages of any kind arising from your use or distribution of |
| 33 | * this program. |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | #ifndef _UFSHCI_H |
| 37 | #define _UFSHCI_H |
| 38 | |
| 39 | enum { |
| 40 | TASK_REQ_UPIU_SIZE_DWORDS = 8, |
| 41 | TASK_RSP_UPIU_SIZE_DWORDS = 8, |
Dolev Raviv | 68078d5 | 2013-07-30 00:35:58 +0530 | [diff] [blame] | 42 | ALIGNED_UPIU_SIZE = 512, |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /* UFSHCI Registers */ |
| 46 | enum { |
| 47 | REG_CONTROLLER_CAPABILITIES = 0x00, |
| 48 | REG_UFS_VERSION = 0x08, |
| 49 | REG_CONTROLLER_DEV_ID = 0x10, |
| 50 | REG_CONTROLLER_PROD_ID = 0x14, |
Tomohiro Kusumi | f6b2545 | 2017-03-28 16:49:27 +0300 | [diff] [blame] | 51 | REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18, |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 52 | REG_INTERRUPT_STATUS = 0x20, |
| 53 | REG_INTERRUPT_ENABLE = 0x24, |
| 54 | REG_CONTROLLER_STATUS = 0x30, |
| 55 | REG_CONTROLLER_ENABLE = 0x34, |
| 56 | REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38, |
| 57 | REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C, |
| 58 | REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40, |
| 59 | REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44, |
| 60 | REG_UIC_ERROR_CODE_DME = 0x48, |
| 61 | REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C, |
| 62 | REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50, |
| 63 | REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54, |
| 64 | REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58, |
| 65 | REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C, |
| 66 | REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60, |
| 67 | REG_UTP_TASK_REQ_LIST_BASE_L = 0x70, |
| 68 | REG_UTP_TASK_REQ_LIST_BASE_H = 0x74, |
| 69 | REG_UTP_TASK_REQ_DOOR_BELL = 0x78, |
| 70 | REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C, |
| 71 | REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80, |
| 72 | REG_UIC_COMMAND = 0x90, |
| 73 | REG_UIC_COMMAND_ARG_1 = 0x94, |
| 74 | REG_UIC_COMMAND_ARG_2 = 0x98, |
| 75 | REG_UIC_COMMAND_ARG_3 = 0x9C, |
Dolev Raviv | 66cc820 | 2016-12-22 18:39:42 -0800 | [diff] [blame] | 76 | |
| 77 | UFSHCI_REG_SPACE_SIZE = 0xA0, |
| 78 | |
Yaniv Gardi | c01848c | 2016-12-05 19:25:02 -0800 | [diff] [blame] | 79 | REG_UFS_CCAP = 0x100, |
| 80 | REG_UFS_CRYPTOCAP = 0x104, |
| 81 | |
| 82 | UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400, |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* Controller capability masks */ |
| 86 | enum { |
| 87 | MASK_TRANSFER_REQUESTS_SLOTS = 0x0000001F, |
| 88 | MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000, |
| 89 | MASK_64_ADDRESSING_SUPPORT = 0x01000000, |
| 90 | MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000, |
| 91 | MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000, |
| 92 | }; |
| 93 | |
Santosh Y | 679882a | 2016-11-24 12:58:51 +0800 | [diff] [blame] | 94 | #define UFS_MASK(mask, offset) ((mask) << (offset)) |
| 95 | |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 96 | /* UFS Version 08h */ |
| 97 | #define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0) |
| 98 | #define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16) |
| 99 | |
| 100 | /* Controller UFSHCI version */ |
| 101 | enum { |
Yaniv Gardi | 9949e70 | 2015-05-17 18:55:05 +0300 | [diff] [blame] | 102 | UFSHCI_VERSION_10 = 0x00010000, /* 1.0 */ |
| 103 | UFSHCI_VERSION_11 = 0x00010100, /* 1.1 */ |
| 104 | UFSHCI_VERSION_20 = 0x00000200, /* 2.0 */ |
Yaniv Gardi | 3711310 | 2016-03-10 17:37:16 +0200 | [diff] [blame] | 105 | UFSHCI_VERSION_21 = 0x00000210, /* 2.1 */ |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | /* |
| 109 | * HCDDID - Host Controller Identification Descriptor |
| 110 | * - Device ID and Device Class 10h |
| 111 | */ |
| 112 | #define DEVICE_CLASS UFS_MASK(0xFFFF, 0) |
| 113 | #define DEVICE_ID UFS_MASK(0xFF, 24) |
| 114 | |
| 115 | /* |
| 116 | * HCPMID - Host Controller Identification Descriptor |
| 117 | * - Product/Manufacturer ID 14h |
| 118 | */ |
| 119 | #define MANUFACTURE_ID_MASK UFS_MASK(0xFFFF, 0) |
| 120 | #define PRODUCT_ID_MASK UFS_MASK(0xFFFF, 16) |
| 121 | |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 122 | /* |
| 123 | * IS - Interrupt Status - 20h |
| 124 | */ |
| 125 | #define UTP_TRANSFER_REQ_COMPL 0x1 |
| 126 | #define UIC_DME_END_PT_RESET 0x2 |
| 127 | #define UIC_ERROR 0x4 |
| 128 | #define UIC_TEST_MODE 0x8 |
| 129 | #define UIC_POWER_MODE 0x10 |
| 130 | #define UIC_HIBERNATE_EXIT 0x20 |
| 131 | #define UIC_HIBERNATE_ENTER 0x40 |
| 132 | #define UIC_LINK_LOST 0x80 |
| 133 | #define UIC_LINK_STARTUP 0x100 |
| 134 | #define UTP_TASK_REQ_COMPL 0x200 |
| 135 | #define UIC_COMMAND_COMPL 0x400 |
| 136 | #define DEVICE_FATAL_ERROR 0x800 |
| 137 | #define CONTROLLER_FATAL_ERROR 0x10000 |
| 138 | #define SYSTEM_BUS_FATAL_ERROR 0x20000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 139 | |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 140 | #define UFSHCD_UIC_PWR_MASK (UIC_HIBERNATE_ENTER |\ |
| 141 | UIC_HIBERNATE_EXIT |\ |
| 142 | UIC_POWER_MODE) |
| 143 | |
| 144 | #define UFSHCD_UIC_MASK (UIC_COMMAND_COMPL | UFSHCD_UIC_PWR_MASK) |
Seungwon Jeon | 53b3d9c | 2013-08-31 21:40:22 +0530 | [diff] [blame] | 145 | |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 146 | #define UFSHCD_ERROR_MASK (UIC_ERROR |\ |
| 147 | DEVICE_FATAL_ERROR |\ |
| 148 | CONTROLLER_FATAL_ERROR |\ |
| 149 | SYSTEM_BUS_FATAL_ERROR) |
| 150 | |
| 151 | #define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\ |
| 152 | CONTROLLER_FATAL_ERROR |\ |
| 153 | SYSTEM_BUS_FATAL_ERROR) |
| 154 | |
| 155 | /* HCS - Host Controller Status 30h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 156 | #define DEVICE_PRESENT 0x1 |
| 157 | #define UTP_TRANSFER_REQ_LIST_READY 0x2 |
| 158 | #define UTP_TASK_REQ_LIST_READY 0x4 |
| 159 | #define UIC_COMMAND_READY 0x8 |
kwmad.kim@samsung.com | cffe3ff | 2017-11-28 14:35:29 +0900 | [diff] [blame] | 160 | #define HOST_ERROR_INDICATOR 0x10 |
| 161 | #define DEVICE_ERROR_INDICATOR 0x20 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 162 | #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8) |
| 163 | |
Tomohiro Kusumi | 6cf1611 | 2017-04-26 20:28:58 +0300 | [diff] [blame] | 164 | #define UFSHCD_STATUS_READY (UTP_TRANSFER_REQ_LIST_READY |\ |
| 165 | UTP_TASK_REQ_LIST_READY |\ |
| 166 | UIC_COMMAND_READY) |
| 167 | |
Seungwon Jeon | 53b3d9c | 2013-08-31 21:40:22 +0530 | [diff] [blame] | 168 | enum { |
| 169 | PWR_OK = 0x0, |
| 170 | PWR_LOCAL = 0x01, |
| 171 | PWR_REMOTE = 0x02, |
| 172 | PWR_BUSY = 0x03, |
| 173 | PWR_ERROR_CAP = 0x04, |
| 174 | PWR_FATAL_ERROR = 0x05, |
| 175 | }; |
| 176 | |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 177 | /* HCE - Host Controller Enable 34h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 178 | #define CONTROLLER_ENABLE 0x1 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 179 | #define CONTROLLER_DISABLE 0x0 |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 180 | #define CRYPTO_GENERAL_ENABLE 0x2 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 181 | |
| 182 | /* UECPA - Host UIC Error Code PHY Adapter Layer 38h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 183 | #define UIC_PHY_ADAPTER_LAYER_ERROR 0x80000000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 184 | #define UIC_PHY_ADAPTER_LAYER_ERROR_CODE_MASK 0x1F |
Dolev Raviv | fb7b45f | 2016-11-23 16:32:32 -0800 | [diff] [blame] | 185 | #define UIC_PHY_ADAPTER_LAYER_LANE_ERR_MASK 0xF |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 186 | |
| 187 | /* UECDL - Host UIC Error Code Data Link Layer 3Ch */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 188 | #define UIC_DATA_LINK_LAYER_ERROR 0x80000000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 189 | #define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0x7FFF |
kwmad.kim@samsung.com | cffe3ff | 2017-11-28 14:35:29 +0900 | [diff] [blame] | 190 | #define UIC_DATA_LINK_LAYER_ERROR_TCX_REP_TIMER_EXP 0x2 |
| 191 | #define UIC_DATA_LINK_LAYER_ERROR_AFCX_REQ_TIMER_EXP 0x4 |
| 192 | #define UIC_DATA_LINK_LAYER_ERROR_FCX_PRO_TIMER_EXP 0x8 |
| 193 | #define UIC_DATA_LINK_LAYER_ERROR_RX_BUF_OF 0x20 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 194 | #define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000 |
Yaniv Gardi | 583fa62 | 2016-03-10 17:37:13 +0200 | [diff] [blame] | 195 | #define UIC_DATA_LINK_LAYER_ERROR_NAC_RECEIVED 0x0001 |
| 196 | #define UIC_DATA_LINK_LAYER_ERROR_TCx_REPLAY_TIMEOUT 0x0002 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 197 | |
| 198 | /* UECN - Host UIC Error Code Network Layer 40h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 199 | #define UIC_NETWORK_LAYER_ERROR 0x80000000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 200 | #define UIC_NETWORK_LAYER_ERROR_CODE_MASK 0x7 |
kwmad.kim@samsung.com | cffe3ff | 2017-11-28 14:35:29 +0900 | [diff] [blame] | 201 | #define UIC_NETWORK_UNSUPPORTED_HEADER_TYPE 0x1 |
| 202 | #define UIC_NETWORK_BAD_DEVICEID_ENC 0x2 |
| 203 | #define UIC_NETWORK_LHDR_TRAP_PACKET_DROPPING 0x4 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 204 | |
| 205 | /* UECT - Host UIC Error Code Transport Layer 44h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 206 | #define UIC_TRANSPORT_LAYER_ERROR 0x80000000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 207 | #define UIC_TRANSPORT_LAYER_ERROR_CODE_MASK 0x7F |
kwmad.kim@samsung.com | cffe3ff | 2017-11-28 14:35:29 +0900 | [diff] [blame] | 208 | #define UIC_TRANSPORT_UNSUPPORTED_HEADER_TYPE 0x1 |
| 209 | #define UIC_TRANSPORT_UNKNOWN_CPORTID 0x2 |
| 210 | #define UIC_TRANSPORT_NO_CONNECTION_RX 0x4 |
| 211 | #define UIC_TRANSPORT_CONTROLLED_SEGMENT_DROPPING 0x8 |
| 212 | #define UIC_TRANSPORT_BAD_TC 0x10 |
| 213 | #define UIC_TRANSPORT_E2E_CREDIT_OVERFOW 0x20 |
| 214 | #define UIC_TRANSPORT_SAFETY_VALUE_DROPPING 0x40 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 215 | |
| 216 | /* UECDME - Host UIC Error Code DME 48h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 217 | #define UIC_DME_ERROR 0x80000000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 218 | #define UIC_DME_ERROR_CODE_MASK 0x1 |
| 219 | |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 220 | /* UTRIACR - Interrupt Aggregation control register - 0x4Ch */ |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 221 | #define INT_AGGR_TIMEOUT_VAL_MASK 0xFF |
| 222 | #define INT_AGGR_COUNTER_THRESHOLD_MASK UFS_MASK(0x1F, 8) |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 223 | #define INT_AGGR_COUNTER_AND_TIMER_RESET 0x10000 |
| 224 | #define INT_AGGR_STATUS_BIT 0x100000 |
| 225 | #define INT_AGGR_PARAM_WRITE 0x1000000 |
| 226 | #define INT_AGGR_ENABLE 0x80000000 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 227 | |
| 228 | /* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 229 | #define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT 0x1 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 230 | |
| 231 | /* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */ |
Alim Akhtar | cc81641 | 2017-10-03 20:51:22 +0530 | [diff] [blame] | 232 | #define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1 |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 233 | |
| 234 | /* UICCMD - UIC Command */ |
| 235 | #define COMMAND_OPCODE_MASK 0xFF |
| 236 | #define GEN_SELECTOR_INDEX_MASK 0xFFFF |
| 237 | |
| 238 | #define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16) |
| 239 | #define RESET_LEVEL 0xFF |
| 240 | |
| 241 | #define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16) |
| 242 | #define CONFIG_RESULT_CODE_MASK 0xFF |
| 243 | #define GENERIC_ERROR_CODE_MASK 0xFF |
| 244 | |
Yaniv Gardi | 7ca38cf | 2015-05-17 18:54:59 +0300 | [diff] [blame] | 245 | /* GenSelectorIndex calculation macros for M-PHY attributes */ |
| 246 | #define UIC_ARG_MPHY_TX_GEN_SEL_INDEX(lane) (lane) |
Yaniv Gardi | 3711310 | 2016-03-10 17:37:16 +0200 | [diff] [blame] | 247 | #define UIC_ARG_MPHY_RX_GEN_SEL_INDEX(lane) (PA_MAXDATALANES + (lane)) |
Yaniv Gardi | 7ca38cf | 2015-05-17 18:54:59 +0300 | [diff] [blame] | 248 | |
Seungwon Jeon | 12b4fdb | 2013-08-31 21:40:21 +0530 | [diff] [blame] | 249 | #define UIC_ARG_MIB_SEL(attr, sel) ((((attr) & 0xFFFF) << 16) |\ |
| 250 | ((sel) & 0xFFFF)) |
| 251 | #define UIC_ARG_MIB(attr) UIC_ARG_MIB_SEL(attr, 0) |
| 252 | #define UIC_ARG_ATTR_TYPE(t) (((t) & 0xFF) << 16) |
| 253 | #define UIC_GET_ATTR_ID(v) (((v) >> 16) & 0xFFFF) |
| 254 | |
Joao Pinto | 79fcc03 | 2016-05-11 12:21:29 +0100 | [diff] [blame] | 255 | /* Link Status*/ |
| 256 | enum link_status { |
| 257 | UFSHCD_LINK_IS_DOWN = 1, |
| 258 | UFSHCD_LINK_IS_UP = 2, |
| 259 | }; |
| 260 | |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 261 | /* UIC Commands */ |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 262 | enum uic_cmd_dme { |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 263 | UIC_CMD_DME_GET = 0x01, |
| 264 | UIC_CMD_DME_SET = 0x02, |
| 265 | UIC_CMD_DME_PEER_GET = 0x03, |
| 266 | UIC_CMD_DME_PEER_SET = 0x04, |
| 267 | UIC_CMD_DME_POWERON = 0x10, |
| 268 | UIC_CMD_DME_POWEROFF = 0x11, |
| 269 | UIC_CMD_DME_ENABLE = 0x12, |
| 270 | UIC_CMD_DME_RESET = 0x14, |
| 271 | UIC_CMD_DME_END_PT_RST = 0x15, |
| 272 | UIC_CMD_DME_LINK_STARTUP = 0x16, |
| 273 | UIC_CMD_DME_HIBER_ENTER = 0x17, |
| 274 | UIC_CMD_DME_HIBER_EXIT = 0x18, |
| 275 | UIC_CMD_DME_TEST_MODE = 0x1A, |
| 276 | }; |
| 277 | |
| 278 | /* UIC Config result code / Generic error code */ |
| 279 | enum { |
| 280 | UIC_CMD_RESULT_SUCCESS = 0x00, |
| 281 | UIC_CMD_RESULT_INVALID_ATTR = 0x01, |
| 282 | UIC_CMD_RESULT_FAILURE = 0x01, |
| 283 | UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02, |
| 284 | UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03, |
| 285 | UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04, |
| 286 | UIC_CMD_RESULT_BAD_INDEX = 0x05, |
| 287 | UIC_CMD_RESULT_LOCKED_ATTR = 0x06, |
| 288 | UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07, |
| 289 | UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08, |
| 290 | UIC_CMD_RESULT_BUSY = 0x09, |
| 291 | UIC_CMD_RESULT_DME_FAILURE = 0x0A, |
| 292 | }; |
| 293 | |
| 294 | #define MASK_UIC_COMMAND_RESULT 0xFF |
| 295 | |
Seungwon Jeon | 7d56865 | 2013-08-31 21:40:20 +0530 | [diff] [blame] | 296 | #define INT_AGGR_COUNTER_THLD_VAL(c) (((c) & 0x1F) << 8) |
| 297 | #define INT_AGGR_TIMEOUT_VAL(t) (((t) & 0xFF) << 0) |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 298 | |
| 299 | /* Interrupt disable masks */ |
| 300 | enum { |
| 301 | /* Interrupt disable mask for UFSHCI v1.0 */ |
Seungwon Jeon | 2fbd009 | 2013-06-26 22:39:27 +0530 | [diff] [blame] | 302 | INTERRUPT_MASK_ALL_VER_10 = 0x30FFF, |
| 303 | INTERRUPT_MASK_RW_VER_10 = 0x30000, |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 304 | |
| 305 | /* Interrupt disable mask for UFSHCI v1.1 */ |
Seungwon Jeon | 2fbd009 | 2013-06-26 22:39:27 +0530 | [diff] [blame] | 306 | INTERRUPT_MASK_ALL_VER_11 = 0x31FFF, |
Yaniv Gardi | c01848c | 2016-12-05 19:25:02 -0800 | [diff] [blame] | 307 | |
| 308 | /* Interrupt disable mask for UFSHCI v2.1 */ |
| 309 | INTERRUPT_MASK_ALL_VER_21 = 0x71FFF, |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | /* |
| 313 | * Request Descriptor Definitions |
| 314 | */ |
| 315 | |
| 316 | /* Transfer request command type */ |
| 317 | enum { |
| 318 | UTP_CMD_TYPE_SCSI = 0x0, |
| 319 | UTP_CMD_TYPE_UFS = 0x1, |
| 320 | UTP_CMD_TYPE_DEV_MANAGE = 0x2, |
| 321 | }; |
| 322 | |
Joao Pinto | 300bb13 | 2016-05-11 12:21:27 +0100 | [diff] [blame] | 323 | /* To accommodate UFS2.0 required Command type */ |
| 324 | enum { |
| 325 | UTP_CMD_TYPE_UFS_STORAGE = 0x1, |
| 326 | }; |
| 327 | |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 328 | enum { |
| 329 | UTP_SCSI_COMMAND = 0x00000000, |
| 330 | UTP_NATIVE_UFS_COMMAND = 0x10000000, |
| 331 | UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000, |
| 332 | UTP_REQ_DESC_INT_CMD = 0x01000000, |
| 333 | }; |
| 334 | |
| 335 | /* UTP Transfer Request Data Direction (DD) */ |
| 336 | enum { |
| 337 | UTP_NO_DATA_TRANSFER = 0x00000000, |
| 338 | UTP_HOST_TO_DEVICE = 0x02000000, |
| 339 | UTP_DEVICE_TO_HOST = 0x04000000, |
| 340 | }; |
| 341 | |
| 342 | /* Overall command status values */ |
| 343 | enum { |
| 344 | OCS_SUCCESS = 0x0, |
| 345 | OCS_INVALID_CMD_TABLE_ATTR = 0x1, |
| 346 | OCS_INVALID_PRDT_ATTR = 0x2, |
| 347 | OCS_MISMATCH_DATA_BUF_SIZE = 0x3, |
| 348 | OCS_MISMATCH_RESP_UPIU_SIZE = 0x4, |
| 349 | OCS_PEER_COMM_FAILURE = 0x5, |
| 350 | OCS_ABORTED = 0x6, |
| 351 | OCS_FATAL_ERROR = 0x7, |
| 352 | OCS_INVALID_COMMAND_STATUS = 0x0F, |
| 353 | MASK_OCS = 0x0F, |
| 354 | }; |
| 355 | |
Akinobu Mita | eeda474 | 2014-07-01 23:00:32 +0900 | [diff] [blame] | 356 | /* The maximum length of the data byte count field in the PRDT is 256KB */ |
| 357 | #define PRDT_DATA_BYTE_COUNT_MAX (256 * 1024) |
| 358 | /* The granularity of the data byte count field in the PRDT is 32-bit */ |
| 359 | #define PRDT_DATA_BYTE_COUNT_PAD 4 |
| 360 | |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 361 | /** |
| 362 | * struct ufshcd_sg_entry - UFSHCI PRD Entry |
| 363 | * @base_addr: Lower 32bit physical address DW-0 |
| 364 | * @upper_addr: Upper 32bit physical address DW-1 |
| 365 | * @reserved: Reserved for future use DW-2 |
| 366 | * @size: size of physical segment DW-3 |
| 367 | */ |
| 368 | struct ufshcd_sg_entry { |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 369 | __le32 base_addr; |
| 370 | __le32 upper_addr; |
| 371 | __le32 reserved; |
| 372 | __le32 size; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | /** |
| 376 | * struct utp_transfer_cmd_desc - UFS Command Descriptor structure |
| 377 | * @command_upiu: Command UPIU Frame address |
| 378 | * @response_upiu: Response UPIU Frame address |
| 379 | * @prd_table: Physical Region Descriptor |
| 380 | */ |
| 381 | struct utp_transfer_cmd_desc { |
| 382 | u8 command_upiu[ALIGNED_UPIU_SIZE]; |
| 383 | u8 response_upiu[ALIGNED_UPIU_SIZE]; |
| 384 | struct ufshcd_sg_entry prd_table[SG_ALL]; |
| 385 | }; |
| 386 | |
| 387 | /** |
| 388 | * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD |
| 389 | * @dword0: Descriptor Header DW0 |
| 390 | * @dword1: Descriptor Header DW1 |
| 391 | * @dword2: Descriptor Header DW2 |
| 392 | * @dword3: Descriptor Header DW3 |
| 393 | */ |
| 394 | struct request_desc_header { |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 395 | __le32 dword_0; |
| 396 | __le32 dword_1; |
| 397 | __le32 dword_2; |
| 398 | __le32 dword_3; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | /** |
| 402 | * struct utp_transfer_req_desc - UTRD structure |
| 403 | * @header: UTRD header DW-0 to DW-3 |
| 404 | * @command_desc_base_addr_lo: UCD base address low DW-4 |
| 405 | * @command_desc_base_addr_hi: UCD base address high DW-5 |
| 406 | * @response_upiu_length: response UPIU length DW-6 |
| 407 | * @response_upiu_offset: response UPIU offset DW-6 |
| 408 | * @prd_table_length: Physical region descriptor length DW-7 |
| 409 | * @prd_table_offset: Physical region descriptor offset DW-7 |
| 410 | */ |
| 411 | struct utp_transfer_req_desc { |
| 412 | |
| 413 | /* DW 0-3 */ |
| 414 | struct request_desc_header header; |
| 415 | |
| 416 | /* DW 4-5*/ |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 417 | __le32 command_desc_base_addr_lo; |
| 418 | __le32 command_desc_base_addr_hi; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 419 | |
| 420 | /* DW 6 */ |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 421 | __le16 response_upiu_length; |
| 422 | __le16 response_upiu_offset; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 423 | |
| 424 | /* DW 7 */ |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 425 | __le16 prd_table_length; |
| 426 | __le16 prd_table_offset; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | /** |
| 430 | * struct utp_task_req_desc - UTMRD structure |
| 431 | * @header: UTMRD header DW-0 to DW-3 |
| 432 | * @task_req_upiu: Pointer to task request UPIU DW-4 to DW-11 |
| 433 | * @task_rsp_upiu: Pointer to task response UPIU DW12 to DW-19 |
| 434 | */ |
| 435 | struct utp_task_req_desc { |
| 436 | |
| 437 | /* DW 0-3 */ |
| 438 | struct request_desc_header header; |
| 439 | |
| 440 | /* DW 4-11 */ |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 441 | __le32 task_req_upiu[TASK_REQ_UPIU_SIZE_DWORDS]; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 442 | |
| 443 | /* DW 12-19 */ |
Sujit Reddy Thumma | e8c8e82 | 2014-05-26 10:59:10 +0530 | [diff] [blame] | 444 | __le32 task_rsp_upiu[TASK_RSP_UPIU_SIZE_DWORDS]; |
Santosh Yaraganavi | 7a3e97b | 2012-02-29 12:11:50 +0530 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | #endif /* End of Header */ |