ufshci.h 15 KB

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