ufshci.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Universal Flash Storage Host controller driver
  4. * Copyright (C) 2011-2013 Samsung India Software Operations
  5. *
  6. * Authors:
  7. * Santosh Yaraganavi <santosh.sy@samsung.com>
  8. * Vinayak Holikatti <h.vinayak@samsung.com>
  9. */
  10. #ifndef _UFSHCI_H
  11. #define _UFSHCI_H
  12. #include <linux/types.h>
  13. #include <ufs/ufs.h>
  14. enum {
  15. TASK_REQ_UPIU_SIZE_DWORDS = 8,
  16. TASK_RSP_UPIU_SIZE_DWORDS = 8,
  17. ALIGNED_UPIU_SIZE = 512,
  18. };
  19. /* UFSHCI Registers */
  20. enum {
  21. REG_CONTROLLER_CAPABILITIES = 0x00,
  22. REG_MCQCAP = 0x04,
  23. REG_UFS_VERSION = 0x08,
  24. REG_EXT_CONTROLLER_CAPABILITIES = 0x0C,
  25. REG_CONTROLLER_PID = 0x10,
  26. REG_CONTROLLER_MID = 0x14,
  27. REG_AUTO_HIBERNATE_IDLE_TIMER = 0x18,
  28. REG_INTERRUPT_STATUS = 0x20,
  29. REG_INTERRUPT_ENABLE = 0x24,
  30. REG_CONTROLLER_STATUS = 0x30,
  31. REG_CONTROLLER_ENABLE = 0x34,
  32. REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER = 0x38,
  33. REG_UIC_ERROR_CODE_DATA_LINK_LAYER = 0x3C,
  34. REG_UIC_ERROR_CODE_NETWORK_LAYER = 0x40,
  35. REG_UIC_ERROR_CODE_TRANSPORT_LAYER = 0x44,
  36. REG_UIC_ERROR_CODE_DME = 0x48,
  37. REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL = 0x4C,
  38. REG_UTP_TRANSFER_REQ_LIST_BASE_L = 0x50,
  39. REG_UTP_TRANSFER_REQ_LIST_BASE_H = 0x54,
  40. REG_UTP_TRANSFER_REQ_DOOR_BELL = 0x58,
  41. REG_UTP_TRANSFER_REQ_LIST_CLEAR = 0x5C,
  42. REG_UTP_TRANSFER_REQ_LIST_RUN_STOP = 0x60,
  43. REG_UTP_TASK_REQ_LIST_BASE_L = 0x70,
  44. REG_UTP_TASK_REQ_LIST_BASE_H = 0x74,
  45. REG_UTP_TASK_REQ_DOOR_BELL = 0x78,
  46. REG_UTP_TASK_REQ_LIST_CLEAR = 0x7C,
  47. REG_UTP_TASK_REQ_LIST_RUN_STOP = 0x80,
  48. REG_UIC_COMMAND = 0x90,
  49. REG_UIC_COMMAND_ARG_1 = 0x94,
  50. REG_UIC_COMMAND_ARG_2 = 0x98,
  51. REG_UIC_COMMAND_ARG_3 = 0x9C,
  52. UFSHCI_REG_SPACE_SIZE = 0xA0,
  53. REG_UFS_CCAP = 0x100,
  54. REG_UFS_CRYPTOCAP = 0x104,
  55. REG_UFS_MEM_CFG = 0x300,
  56. REG_UFS_MCQ_CFG = 0x380,
  57. REG_UFS_ESILBA = 0x384,
  58. REG_UFS_ESIUBA = 0x388,
  59. UFSHCI_CRYPTO_REG_SPACE_SIZE = 0x400,
  60. };
  61. /* Controller capability masks */
  62. enum {
  63. MASK_TRANSFER_REQUESTS_SLOTS_SDB = 0x0000001F,
  64. MASK_TRANSFER_REQUESTS_SLOTS_MCQ = 0x000000FF,
  65. MASK_NUMBER_OUTSTANDING_RTT = 0x0000FF00,
  66. MASK_TASK_MANAGEMENT_REQUEST_SLOTS = 0x00070000,
  67. MASK_EHSLUTRD_SUPPORTED = 0x00400000,
  68. MASK_AUTO_HIBERN8_SUPPORT = 0x00800000,
  69. MASK_64_ADDRESSING_SUPPORT = 0x01000000,
  70. MASK_OUT_OF_ORDER_DATA_DELIVERY_SUPPORT = 0x02000000,
  71. MASK_UIC_DME_TEST_MODE_SUPPORT = 0x04000000,
  72. MASK_CRYPTO_SUPPORT = 0x10000000,
  73. MASK_LSDB_SUPPORT = 0x20000000,
  74. MASK_MCQ_SUPPORT = 0x40000000,
  75. };
  76. enum {
  77. /* Submission Queue (SQ) Configuration Registers */
  78. REG_SQATTR = 0x0,
  79. REG_SQLBA = 0x4,
  80. REG_SQUBA = 0x8,
  81. REG_SQDAO = 0xC,
  82. REG_SQISAO = 0x10,
  83. /* Completion Queue (CQ) Configuration Registers */
  84. REG_CQATTR = 0x20,
  85. REG_CQLBA = 0x24,
  86. REG_CQUBA = 0x28,
  87. REG_CQDAO = 0x2C,
  88. REG_CQISAO = 0x30,
  89. };
  90. /* Operation and Runtime Registers - Submission Queues and Completion Queues */
  91. enum {
  92. REG_SQHP = 0x0,
  93. REG_SQTP = 0x4,
  94. REG_SQRTC = 0x8,
  95. REG_SQCTI = 0xC,
  96. REG_SQRTS = 0x10,
  97. };
  98. enum {
  99. REG_CQHP = 0x0,
  100. REG_CQTP = 0x4,
  101. };
  102. enum {
  103. REG_CQIS = 0x0,
  104. REG_CQIE = 0x4,
  105. };
  106. enum {
  107. SQ_START = 0x0,
  108. SQ_STOP = 0x1,
  109. SQ_ICU = 0x2,
  110. };
  111. enum {
  112. SQ_STS = 0x1,
  113. SQ_CUS = 0x2,
  114. };
  115. #define SQ_ICU_ERR_CODE_MASK GENMASK(7, 4)
  116. #define UFS_MASK(mask, offset) ((mask) << (offset))
  117. /* UFS Version 08h */
  118. #define MINOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 0)
  119. #define MAJOR_VERSION_NUM_MASK UFS_MASK(0xFFFF, 16)
  120. #define UFSHCD_NUM_RESERVED 1
  121. /*
  122. * Controller UFSHCI version
  123. * - 2.x and newer use the following scheme:
  124. * major << 8 + minor << 4
  125. * - 1.x has been converted to match this in
  126. * ufshcd_get_ufs_version()
  127. */
  128. static inline u32 ufshci_version(u32 major, u32 minor)
  129. {
  130. return (major << 8) + (minor << 4);
  131. }
  132. /*
  133. * HCDDID - Host Controller Identification Descriptor
  134. * - Device ID and Device Class 10h
  135. */
  136. #define DEVICE_CLASS UFS_MASK(0xFFFF, 0)
  137. #define DEVICE_ID UFS_MASK(0xFF, 24)
  138. /*
  139. * HCPMID - Host Controller Identification Descriptor
  140. * - Product/Manufacturer ID 14h
  141. */
  142. #define MANUFACTURE_ID_MASK UFS_MASK(0xFFFF, 0)
  143. #define PRODUCT_ID_MASK UFS_MASK(0xFFFF, 16)
  144. /* AHIT - Auto-Hibernate Idle Timer */
  145. #define UFSHCI_AHIBERN8_TIMER_MASK GENMASK(9, 0)
  146. #define UFSHCI_AHIBERN8_SCALE_MASK GENMASK(12, 10)
  147. #define UFSHCI_AHIBERN8_SCALE_FACTOR 10
  148. #define UFSHCI_AHIBERN8_MAX (1023 * 100000)
  149. /*
  150. * IS - Interrupt Status - 20h
  151. */
  152. #define UTP_TRANSFER_REQ_COMPL 0x1
  153. #define UIC_DME_END_PT_RESET 0x2
  154. #define UIC_ERROR 0x4
  155. #define UIC_TEST_MODE 0x8
  156. #define UIC_POWER_MODE 0x10
  157. #define UIC_HIBERNATE_EXIT 0x20
  158. #define UIC_HIBERNATE_ENTER 0x40
  159. #define UIC_LINK_LOST 0x80
  160. #define UIC_LINK_STARTUP 0x100
  161. #define UTP_TASK_REQ_COMPL 0x200
  162. #define UIC_COMMAND_COMPL 0x400
  163. #define DEVICE_FATAL_ERROR 0x800
  164. #define UTP_ERROR 0x1000
  165. #define CONTROLLER_FATAL_ERROR 0x10000
  166. #define SYSTEM_BUS_FATAL_ERROR 0x20000
  167. #define CRYPTO_ENGINE_FATAL_ERROR 0x40000
  168. #define MCQ_CQ_EVENT_STATUS 0x100000
  169. #define UFSHCD_UIC_HIBERN8_MASK (UIC_HIBERNATE_ENTER |\
  170. UIC_HIBERNATE_EXIT)
  171. #define UFSHCD_UIC_PWR_MASK (UFSHCD_UIC_HIBERN8_MASK |\
  172. UIC_POWER_MODE)
  173. #define UFSHCD_UIC_MASK (UIC_COMMAND_COMPL | UFSHCD_UIC_PWR_MASK)
  174. #define UFSHCD_ERROR_MASK (UIC_ERROR | INT_FATAL_ERRORS)
  175. #define INT_FATAL_ERRORS (DEVICE_FATAL_ERROR |\
  176. CONTROLLER_FATAL_ERROR |\
  177. SYSTEM_BUS_FATAL_ERROR |\
  178. CRYPTO_ENGINE_FATAL_ERROR |\
  179. UIC_LINK_LOST |\
  180. UTP_ERROR)
  181. /* HCS - Host Controller Status 30h */
  182. #define DEVICE_PRESENT 0x1
  183. #define UTP_TRANSFER_REQ_LIST_READY 0x2
  184. #define UTP_TASK_REQ_LIST_READY 0x4
  185. #define UIC_COMMAND_READY 0x8
  186. #define HOST_ERROR_INDICATOR 0x10
  187. #define DEVICE_ERROR_INDICATOR 0x20
  188. #define UIC_POWER_MODE_CHANGE_REQ_STATUS_MASK UFS_MASK(0x7, 8)
  189. #define UFSHCD_STATUS_READY (UTP_TRANSFER_REQ_LIST_READY |\
  190. UTP_TASK_REQ_LIST_READY |\
  191. UIC_COMMAND_READY)
  192. enum {
  193. PWR_OK = 0x0,
  194. PWR_LOCAL = 0x01,
  195. PWR_REMOTE = 0x02,
  196. PWR_BUSY = 0x03,
  197. PWR_ERROR_CAP = 0x04,
  198. PWR_FATAL_ERROR = 0x05,
  199. };
  200. /* HCE - Host Controller Enable 34h */
  201. #define CONTROLLER_ENABLE 0x1
  202. #define CONTROLLER_DISABLE 0x0
  203. #define CRYPTO_GENERAL_ENABLE 0x2
  204. /* UECPA - Host UIC Error Code PHY Adapter Layer 38h */
  205. #define UIC_PHY_ADAPTER_LAYER_ERROR 0x80000000
  206. #define UIC_PHY_ADAPTER_LAYER_ERROR_CODE_MASK 0x1F
  207. #define UIC_PHY_ADAPTER_LAYER_LANE_ERR_MASK 0xF
  208. #define UIC_PHY_ADAPTER_LAYER_GENERIC_ERROR 0x10
  209. /* UECDL - Host UIC Error Code Data Link Layer 3Ch */
  210. #define UIC_DATA_LINK_LAYER_ERROR 0x80000000
  211. #define UIC_DATA_LINK_LAYER_ERROR_CODE_MASK 0xFFFF
  212. #define UIC_DATA_LINK_LAYER_ERROR_TCX_REP_TIMER_EXP 0x2
  213. #define UIC_DATA_LINK_LAYER_ERROR_AFCX_REQ_TIMER_EXP 0x4
  214. #define UIC_DATA_LINK_LAYER_ERROR_FCX_PRO_TIMER_EXP 0x8
  215. #define UIC_DATA_LINK_LAYER_ERROR_RX_BUF_OF 0x20
  216. #define UIC_DATA_LINK_LAYER_ERROR_PA_INIT 0x2000
  217. #define UIC_DATA_LINK_LAYER_ERROR_NAC_RECEIVED 0x0001
  218. #define UIC_DATA_LINK_LAYER_ERROR_TCx_REPLAY_TIMEOUT 0x0002
  219. /* UECN - Host UIC Error Code Network Layer 40h */
  220. #define UIC_NETWORK_LAYER_ERROR 0x80000000
  221. #define UIC_NETWORK_LAYER_ERROR_CODE_MASK 0x7
  222. #define UIC_NETWORK_UNSUPPORTED_HEADER_TYPE 0x1
  223. #define UIC_NETWORK_BAD_DEVICEID_ENC 0x2
  224. #define UIC_NETWORK_LHDR_TRAP_PACKET_DROPPING 0x4
  225. /* UECT - Host UIC Error Code Transport Layer 44h */
  226. #define UIC_TRANSPORT_LAYER_ERROR 0x80000000
  227. #define UIC_TRANSPORT_LAYER_ERROR_CODE_MASK 0x7F
  228. #define UIC_TRANSPORT_UNSUPPORTED_HEADER_TYPE 0x1
  229. #define UIC_TRANSPORT_UNKNOWN_CPORTID 0x2
  230. #define UIC_TRANSPORT_NO_CONNECTION_RX 0x4
  231. #define UIC_TRANSPORT_CONTROLLED_SEGMENT_DROPPING 0x8
  232. #define UIC_TRANSPORT_BAD_TC 0x10
  233. #define UIC_TRANSPORT_E2E_CREDIT_OVERFOW 0x20
  234. #define UIC_TRANSPORT_SAFETY_VALUE_DROPPING 0x40
  235. /* UECDME - Host UIC Error Code DME 48h */
  236. #define UIC_DME_ERROR 0x80000000
  237. #define UIC_DME_ERROR_CODE_MASK 0x1
  238. /* UTRIACR - Interrupt Aggregation control register - 0x4Ch */
  239. #define INT_AGGR_TIMEOUT_VAL_MASK 0xFF
  240. #define INT_AGGR_COUNTER_THRESHOLD_MASK UFS_MASK(0x1F, 8)
  241. #define INT_AGGR_COUNTER_AND_TIMER_RESET 0x10000
  242. #define INT_AGGR_STATUS_BIT 0x100000
  243. #define INT_AGGR_PARAM_WRITE 0x1000000
  244. #define INT_AGGR_ENABLE 0x80000000
  245. /* UTRLRSR - UTP Transfer Request Run-Stop Register 60h */
  246. #define UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT 0x1
  247. /* UTMRLRSR - UTP Task Management Request Run-Stop Register 80h */
  248. #define UTP_TASK_REQ_LIST_RUN_STOP_BIT 0x1
  249. /* REG_UFS_MEM_CFG - Global Config Registers 300h */
  250. #define MCQ_MODE_SELECT BIT(0)
  251. #define ESI_ENABLE BIT(1)
  252. /* CQISy - CQ y Interrupt Status Register */
  253. #define UFSHCD_MCQ_CQIS_TAIL_ENT_PUSH_STS 0x1
  254. /* UICCMD - UIC Command */
  255. #define COMMAND_OPCODE_MASK 0xFF
  256. #define GEN_SELECTOR_INDEX_MASK 0xFFFF
  257. #define MIB_ATTRIBUTE_MASK UFS_MASK(0xFFFF, 16)
  258. #define RESET_LEVEL 0xFF
  259. #define ATTR_SET_TYPE_MASK UFS_MASK(0xFF, 16)
  260. #define CONFIG_RESULT_CODE_MASK 0xFF
  261. #define GENERIC_ERROR_CODE_MASK 0xFF
  262. /* GenSelectorIndex calculation macros for M-PHY attributes */
  263. #define UIC_ARG_MPHY_TX_GEN_SEL_INDEX(lane) (lane)
  264. #define UIC_ARG_MPHY_RX_GEN_SEL_INDEX(lane) (PA_MAXDATALANES + (lane))
  265. #define UIC_ARG_MIB_SEL(attr, sel) ((((attr) & 0xFFFF) << 16) |\
  266. ((sel) & 0xFFFF))
  267. #define UIC_ARG_MIB(attr) UIC_ARG_MIB_SEL(attr, 0)
  268. #define UIC_ARG_ATTR_TYPE(t) (((t) & 0xFF) << 16)
  269. #define UIC_GET_ATTR_ID(v) (((v) >> 16) & 0xFFFF)
  270. /* Link Status*/
  271. enum link_status {
  272. UFSHCD_LINK_IS_DOWN = 1,
  273. UFSHCD_LINK_IS_UP = 2,
  274. };
  275. /* UIC Commands */
  276. enum uic_cmd_dme {
  277. UIC_CMD_DME_GET = 0x01,
  278. UIC_CMD_DME_SET = 0x02,
  279. UIC_CMD_DME_PEER_GET = 0x03,
  280. UIC_CMD_DME_PEER_SET = 0x04,
  281. UIC_CMD_DME_POWERON = 0x10,
  282. UIC_CMD_DME_POWEROFF = 0x11,
  283. UIC_CMD_DME_ENABLE = 0x12,
  284. UIC_CMD_DME_RESET = 0x14,
  285. UIC_CMD_DME_END_PT_RST = 0x15,
  286. UIC_CMD_DME_LINK_STARTUP = 0x16,
  287. UIC_CMD_DME_HIBER_ENTER = 0x17,
  288. UIC_CMD_DME_HIBER_EXIT = 0x18,
  289. UIC_CMD_DME_TEST_MODE = 0x1A,
  290. };
  291. /* UIC Config result code / Generic error code */
  292. enum {
  293. UIC_CMD_RESULT_SUCCESS = 0x00,
  294. UIC_CMD_RESULT_INVALID_ATTR = 0x01,
  295. UIC_CMD_RESULT_FAILURE = 0x01,
  296. UIC_CMD_RESULT_INVALID_ATTR_VALUE = 0x02,
  297. UIC_CMD_RESULT_READ_ONLY_ATTR = 0x03,
  298. UIC_CMD_RESULT_WRITE_ONLY_ATTR = 0x04,
  299. UIC_CMD_RESULT_BAD_INDEX = 0x05,
  300. UIC_CMD_RESULT_LOCKED_ATTR = 0x06,
  301. UIC_CMD_RESULT_BAD_TEST_FEATURE_INDEX = 0x07,
  302. UIC_CMD_RESULT_PEER_COMM_FAILURE = 0x08,
  303. UIC_CMD_RESULT_BUSY = 0x09,
  304. UIC_CMD_RESULT_DME_FAILURE = 0x0A,
  305. };
  306. #define MASK_UIC_COMMAND_RESULT 0xFF
  307. #define INT_AGGR_COUNTER_THLD_VAL(c) (((c) & 0x1F) << 8)
  308. #define INT_AGGR_TIMEOUT_VAL(t) (((t) & 0xFF) << 0)
  309. /* Interrupt disable masks */
  310. enum {
  311. /* Interrupt disable mask for UFSHCI v1.1 */
  312. INTERRUPT_MASK_ALL_VER_11 = 0x31FFF,
  313. /* Interrupt disable mask for UFSHCI v2.1 */
  314. INTERRUPT_MASK_ALL_VER_21 = 0x71FFF,
  315. };
  316. /* CCAP - Crypto Capability 100h */
  317. union ufs_crypto_capabilities {
  318. __le32 reg_val;
  319. struct {
  320. u8 num_crypto_cap;
  321. u8 config_count;
  322. u8 reserved;
  323. u8 config_array_ptr;
  324. };
  325. };
  326. enum ufs_crypto_key_size {
  327. UFS_CRYPTO_KEY_SIZE_INVALID = 0x0,
  328. UFS_CRYPTO_KEY_SIZE_128 = 0x1,
  329. UFS_CRYPTO_KEY_SIZE_192 = 0x2,
  330. UFS_CRYPTO_KEY_SIZE_256 = 0x3,
  331. UFS_CRYPTO_KEY_SIZE_512 = 0x4,
  332. };
  333. enum ufs_crypto_alg {
  334. UFS_CRYPTO_ALG_AES_XTS = 0x0,
  335. UFS_CRYPTO_ALG_BITLOCKER_AES_CBC = 0x1,
  336. UFS_CRYPTO_ALG_AES_ECB = 0x2,
  337. UFS_CRYPTO_ALG_ESSIV_AES_CBC = 0x3,
  338. };
  339. /* x-CRYPTOCAP - Crypto Capability X */
  340. union ufs_crypto_cap_entry {
  341. __le32 reg_val;
  342. struct {
  343. u8 algorithm_id;
  344. u8 sdus_mask; /* Supported data unit size mask */
  345. u8 key_size;
  346. u8 reserved;
  347. };
  348. };
  349. #define UFS_CRYPTO_CONFIGURATION_ENABLE (1 << 7)
  350. #define UFS_CRYPTO_KEY_MAX_SIZE 64
  351. /* x-CRYPTOCFG - Crypto Configuration X */
  352. union ufs_crypto_cfg_entry {
  353. __le32 reg_val[32];
  354. struct {
  355. u8 crypto_key[UFS_CRYPTO_KEY_MAX_SIZE];
  356. u8 data_unit_size;
  357. u8 crypto_cap_idx;
  358. u8 reserved_1;
  359. u8 config_enable;
  360. u8 reserved_multi_host;
  361. u8 reserved_2;
  362. u8 vsb[2];
  363. u8 reserved_3[56];
  364. };
  365. };
  366. /*
  367. * Request Descriptor Definitions
  368. */
  369. /* To accommodate UFS2.0 required Command type */
  370. enum {
  371. UTP_CMD_TYPE_UFS_STORAGE = 0x1,
  372. };
  373. enum {
  374. UTP_SCSI_COMMAND = 0x00000000,
  375. UTP_NATIVE_UFS_COMMAND = 0x10000000,
  376. UTP_DEVICE_MANAGEMENT_FUNCTION = 0x20000000,
  377. };
  378. /* UTP Transfer Request Data Direction (DD) */
  379. enum utp_data_direction {
  380. UTP_NO_DATA_TRANSFER = 0,
  381. UTP_HOST_TO_DEVICE = 1,
  382. UTP_DEVICE_TO_HOST = 2,
  383. };
  384. /* Overall command status values */
  385. enum utp_ocs {
  386. OCS_SUCCESS = 0x0,
  387. OCS_INVALID_CMD_TABLE_ATTR = 0x1,
  388. OCS_INVALID_PRDT_ATTR = 0x2,
  389. OCS_MISMATCH_DATA_BUF_SIZE = 0x3,
  390. OCS_MISMATCH_RESP_UPIU_SIZE = 0x4,
  391. OCS_PEER_COMM_FAILURE = 0x5,
  392. OCS_ABORTED = 0x6,
  393. OCS_FATAL_ERROR = 0x7,
  394. OCS_DEVICE_FATAL_ERROR = 0x8,
  395. OCS_INVALID_CRYPTO_CONFIG = 0x9,
  396. OCS_GENERAL_CRYPTO_ERROR = 0xA,
  397. OCS_INVALID_COMMAND_STATUS = 0x0F,
  398. };
  399. enum {
  400. MASK_OCS = 0x0F,
  401. };
  402. /* The maximum length of the data byte count field in the PRDT is 256KB */
  403. #define PRDT_DATA_BYTE_COUNT_MAX SZ_256K
  404. /* The granularity of the data byte count field in the PRDT is 32-bit */
  405. #define PRDT_DATA_BYTE_COUNT_PAD 4
  406. /**
  407. * struct ufshcd_sg_entry - UFSHCI PRD Entry
  408. * @addr: Physical address; DW-0 and DW-1.
  409. * @reserved: Reserved for future use DW-2
  410. * @size: size of physical segment DW-3
  411. */
  412. struct ufshcd_sg_entry {
  413. __le64 addr;
  414. __le32 reserved;
  415. __le32 size;
  416. /*
  417. * followed by variant-specific fields if
  418. * CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE has been defined.
  419. */
  420. };
  421. /**
  422. * struct utp_transfer_cmd_desc - UTP Command Descriptor (UCD)
  423. * @command_upiu: Command UPIU Frame address
  424. * @response_upiu: Response UPIU Frame address
  425. * @prd_table: Physical Region Descriptor: an array of SG_ALL struct
  426. * ufshcd_sg_entry's. Variant-specific fields may be present after each.
  427. */
  428. struct utp_transfer_cmd_desc {
  429. u8 command_upiu[ALIGNED_UPIU_SIZE];
  430. u8 response_upiu[ALIGNED_UPIU_SIZE];
  431. u8 prd_table[];
  432. };
  433. /**
  434. * struct request_desc_header - Descriptor Header common to both UTRD and UTMRD
  435. */
  436. struct request_desc_header {
  437. u8 cci;
  438. u8 ehs_length;
  439. #if defined(__BIG_ENDIAN)
  440. u8 enable_crypto:1;
  441. u8 reserved2:7;
  442. u8 command_type:4;
  443. u8 reserved1:1;
  444. u8 data_direction:2;
  445. u8 interrupt:1;
  446. #elif defined(__LITTLE_ENDIAN)
  447. u8 reserved2:7;
  448. u8 enable_crypto:1;
  449. u8 interrupt:1;
  450. u8 data_direction:2;
  451. u8 reserved1:1;
  452. u8 command_type:4;
  453. #else
  454. #error
  455. #endif
  456. __le32 dunl;
  457. u8 ocs;
  458. u8 cds;
  459. __le16 ldbc;
  460. __le32 dunu;
  461. };
  462. static_assert(sizeof(struct request_desc_header) == 16);
  463. /**
  464. * struct utp_transfer_req_desc - UTP Transfer Request Descriptor (UTRD)
  465. * @header: UTRD header DW-0 to DW-3
  466. * @command_desc_base_addr: UCD base address DW 4-5
  467. * @response_upiu_length: response UPIU length DW-6
  468. * @response_upiu_offset: response UPIU offset DW-6
  469. * @prd_table_length: Physical region descriptor length DW-7
  470. * @prd_table_offset: Physical region descriptor offset DW-7
  471. */
  472. struct utp_transfer_req_desc {
  473. /* DW 0-3 */
  474. struct request_desc_header header;
  475. /* DW 4-5*/
  476. __le64 command_desc_base_addr;
  477. /* DW 6 */
  478. __le16 response_upiu_length;
  479. __le16 response_upiu_offset;
  480. /* DW 7 */
  481. __le16 prd_table_length;
  482. __le16 prd_table_offset;
  483. };
  484. /* MCQ Completion Queue Entry */
  485. struct cq_entry {
  486. /* DW 0-1 */
  487. __le64 command_desc_base_addr;
  488. /* DW 2 */
  489. __le16 response_upiu_length;
  490. __le16 response_upiu_offset;
  491. /* DW 3 */
  492. __le16 prd_table_length;
  493. __le16 prd_table_offset;
  494. /* DW 4 */
  495. u8 overall_status;
  496. u8 extended_error_code;
  497. __le16 reserved_1;
  498. /* DW 5 */
  499. u8 task_tag;
  500. u8 lun;
  501. #if defined(__BIG_ENDIAN)
  502. u8 ext_iid:4;
  503. u8 iid:4;
  504. #elif defined(__LITTLE_ENDIAN)
  505. u8 iid:4;
  506. u8 ext_iid:4;
  507. #else
  508. #error
  509. #endif
  510. u8 reserved_2;
  511. /* DW 6-7 */
  512. __le32 reserved_3[2];
  513. };
  514. static_assert(sizeof(struct cq_entry) == 32);
  515. /*
  516. * UTMRD structure.
  517. */
  518. struct utp_task_req_desc {
  519. /* DW 0-3 */
  520. struct request_desc_header header;
  521. /* DW 4-11 - Task request UPIU structure */
  522. struct {
  523. struct utp_upiu_header req_header;
  524. __be32 input_param1;
  525. __be32 input_param2;
  526. __be32 input_param3;
  527. __be32 __reserved1[2];
  528. } upiu_req;
  529. /* DW 12-19 - Task Management Response UPIU structure */
  530. struct {
  531. struct utp_upiu_header rsp_header;
  532. __be32 output_param1;
  533. __be32 output_param2;
  534. __be32 __reserved2[3];
  535. } upiu_rsp;
  536. };
  537. #endif /* End of Header */