ufs_aio.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #ifndef _UFS_AIO_H
  32. #define _UFS_AIO_H
  33. #include "ufs_aio_cfg.h"
  34. #include "ufs_aio_types.h"
  35. extern struct ufs_hba g_ufs_hba;
  36. extern struct ufs_platform_info ufs_platform;
  37. #define UFS_AIO_MAX_DEVICE (1)
  38. #define MAX_CDB_SIZE 16
  39. #define GENERAL_UPIU_REQUEST_SIZE 32
  40. #define QUERY_DESC_MAX_SIZE 255
  41. #define QUERY_DESC_MIN_SIZE 2
  42. #define QUERY_DESC_HDR_SIZE 2
  43. #define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \
  44. (sizeof(struct utp_upiu_header)))
  45. #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
  46. cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
  47. (byte1 << 8) | (byte0))
  48. /*
  49. * UFS device may have standard LUs and LUN id could be from 0x00 to
  50. * 0x7F. Standard LUs use "Peripheral Device Addressing Format".
  51. * UFS device may also have the Well Known LUs (also referred as W-LU)
  52. * which again could be from 0x00 to 0x7F. For W-LUs, device only use
  53. * the "Extended Addressing Format" which means the W-LUNs would be
  54. * from 0xc100 (SCSI_W_LUN_BASE) onwards.
  55. * This means max. LUN number reported from UFS device could be 0xC17F.
  56. */
  57. #define UFS_UPIU_MAX_UNIT_NUM_ID 0x7F
  58. //#define UFS_MAX_LUNS (SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)
  59. #define UFS_UPIU_WLUN_ID (1 << 7)
  60. #define UFS_UPIU_MAX_GENERAL_LUN 3
  61. /* default UFS host ID */
  62. #define UFS_DEFAULT_HOST_ID 0
  63. /* default LU number */
  64. #define UFS_DEFAULT_LUN 0
  65. /* default transfer request slot number */
  66. #define UFS_DEFAULT_TAG 0
  67. /* SCSI command opcodes */
  68. #define TEST_UNIT_READY 0x00
  69. /* SCSI related definitions */
  70. #define SCSI_SENSE_BUFFERSIZE 96
  71. /* Well known logical unit id in LUN field of UPIU */
  72. enum {
  73. UFS_UPIU_REPORT_LUNS_WLUN = 0x81,
  74. UFS_UPIU_UFS_DEVICE_WLUN = 0xD0,
  75. UFS_UPIU_BOOT_WLUN = 0xB0,
  76. UFS_UPIU_RPMB_WLUN = 0xC4,
  77. };
  78. /*
  79. * UFS Protocol Information Unit related definitions
  80. */
  81. /* Task management functions */
  82. enum {
  83. UFS_ABORT_TASK = 0x01,
  84. UFS_ABORT_TASK_SET = 0x02,
  85. UFS_CLEAR_TASK_SET = 0x04,
  86. UFS_LOGICAL_RESET = 0x08,
  87. UFS_QUERY_TASK = 0x80,
  88. UFS_QUERY_TASK_SET = 0x81,
  89. };
  90. /* UTP UPIU Transaction Codes Initiator to Target */
  91. enum {
  92. UPIU_TRANSACTION_NOP_OUT = 0x00,
  93. UPIU_TRANSACTION_COMMAND = 0x01,
  94. UPIU_TRANSACTION_DATA_OUT = 0x02,
  95. UPIU_TRANSACTION_TASK_REQ = 0x04,
  96. UPIU_TRANSACTION_QUERY_REQ = 0x16,
  97. };
  98. /* UTP UPIU Transaction Codes Target to Initiator */
  99. enum {
  100. UPIU_TRANSACTION_NOP_IN = 0x20,
  101. UPIU_TRANSACTION_RESPONSE = 0x21,
  102. UPIU_TRANSACTION_DATA_IN = 0x22,
  103. UPIU_TRANSACTION_TASK_RSP = 0x24,
  104. UPIU_TRANSACTION_READY_XFER = 0x31,
  105. UPIU_TRANSACTION_QUERY_RSP = 0x36,
  106. UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
  107. };
  108. /* UPIU Read/Write flags */
  109. enum {
  110. UPIU_CMD_FLAGS_NONE = 0x00,
  111. UPIU_CMD_FLAGS_WRITE = 0x20,
  112. UPIU_CMD_FLAGS_READ = 0x40,
  113. };
  114. /* UPIU Task Attributes */
  115. enum {
  116. UPIU_TASK_ATTR_SIMPLE = 0x00,
  117. UPIU_TASK_ATTR_ORDERED = 0x01,
  118. UPIU_TASK_ATTR_HEADQ = 0x02,
  119. UPIU_TASK_ATTR_ACA = 0x03,
  120. };
  121. /* UPIU Query request function */
  122. enum {
  123. UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01,
  124. UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81,
  125. };
  126. /* Flag idn for Query Requests*/
  127. enum flag_idn {
  128. QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
  129. QUERY_FLAG_IDN_PWR_ON_WPE = 0x03,
  130. QUERY_FLAG_IDN_BKOPS_EN = 0x04,
  131. };
  132. /* Attribute idn for Query requests */
  133. enum attr_idn {
  134. QUERY_ATTR_IDN_ACTIVE_ICC_LVL = 0x03,
  135. QUERY_ATTR_IDN_BKOPS_STATUS = 0x05,
  136. QUERY_ATTR_IDN_REF_CLK_FREQ = 0x0A,
  137. QUERY_ATTR_IDN_EE_CONTROL = 0x0D,
  138. QUERY_ATTR_IDN_EE_STATUS = 0x0E,
  139. };
  140. /* Descriptor idn for Query requests */
  141. enum desc_idn {
  142. QUERY_DESC_IDN_DEVICE = 0x0,
  143. QUERY_DESC_IDN_CONFIGURATION = 0x1,
  144. QUERY_DESC_IDN_UNIT = 0x2,
  145. QUERY_DESC_IDN_RFU_0 = 0x3,
  146. QUERY_DESC_IDN_INTERCONNECT = 0x4,
  147. QUERY_DESC_IDN_STRING = 0x5,
  148. QUERY_DESC_IDN_RFU_1 = 0x6,
  149. QUERY_DESC_IDN_GEOMETRY = 0x7,
  150. QUERY_DESC_IDN_POWER = 0x8,
  151. QUERY_DESC_IDN_HEALTH = 0x9,
  152. QUERY_DESC_IDN_MAX,
  153. };
  154. enum desc_header_offset {
  155. QUERY_DESC_LENGTH_OFFSET = 0x00,
  156. QUERY_DESC_DESC_TYPE_OFFSET = 0x01,
  157. };
  158. enum ufs_desc_max_size {
  159. QUERY_DESC_DEVICE_MAX_SIZE = 0x40, /* HPB 1.0: 0x48, HPB 2.0 & TW: 0x57 */
  160. QUERY_DESC_CONFIGURAION_MAX_SIZE = 0x90,
  161. QUERY_DESC_CONFIGURAION_MAX_SIZE_HPB = 0xD0, /* HPB 1.0: 0xD0 */
  162. QUERY_DESC_CONFIGURAION_MAX_SIZE_HPB_20 = 0xE2, /* HPB 2.0: 0xE2 */
  163. QUERY_DESC_UNIT_MAX_SIZE = 0x23,
  164. QUERY_DESC_INTERCONNECT_MAX_SIZE = 0x06,
  165. /*
  166. * Max. 126 UNICODE characters (2 bytes per character) plus 2 bytes
  167. * of descriptor header.
  168. */
  169. QUERY_DESC_STRING_MAX_SIZE = 0xFE,
  170. QUERY_DESC_GEOMETRY_MAX_SIZE = 0x44, /* UFS 2.0: 0x44, UFS 2.1: 0x48, HPB 1.0: 0x50, HPB 2.0: 0x58 */
  171. QUERY_DESC_POWER_MAX_SIZE = 0x62,
  172. QUERY_DESC_HEALTH_MAX_SIZE = 0x2D, /* UFS 3.0: 0x2D */
  173. QUERY_DESC_RFU_MAX_SIZE = 0x00,
  174. };
  175. /* Geometry descriptor parameters offsets in bytes */
  176. enum geometry_desc_param {
  177. GEOMETRY_DESC_PARAM_RPMB_READ_WRITE_SIZE = 0x17,
  178. };
  179. /* Unit descriptor parameters offsets in bytes*/
  180. enum unit_desc_param {
  181. UNIT_DESC_PARAM_LEN = 0x0,
  182. UNIT_DESC_PARAM_TYPE = 0x1,
  183. UNIT_DESC_PARAM_UNIT_INDEX = 0x2,
  184. UNIT_DESC_PARAM_LU_ENABLE = 0x3,
  185. UNIT_DESC_PARAM_BOOT_LUN_ID = 0x4,
  186. UNIT_DESC_PARAM_LU_WR_PROTECT = 0x5,
  187. UNIT_DESC_PARAM_LU_Q_DEPTH = 0x6,
  188. UNIT_DESC_PARAM_MEM_TYPE = 0x8,
  189. UNIT_DESC_PARAM_DATA_RELIABILITY = 0x9,
  190. UNIT_DESC_PARAM_LOGICAL_BLK_SIZE = 0xA,
  191. UNIT_DESC_PARAM_LOGICAL_BLK_COUNT = 0xB,
  192. UNIT_DESC_PARAM_ERASE_BLK_SIZE = 0x13,
  193. UNIT_DESC_PARAM_PROVISIONING_TYPE = 0x17,
  194. UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT = 0x18,
  195. UNIT_DESC_PARAM_CTX_CAPABILITIES = 0x20,
  196. UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1 = 0x22,
  197. };
  198. /* Device descriptor parameters offsets in bytes*/
  199. enum device_desc_param {
  200. DEVICE_DESC_PARAM_LEN = 0x0,
  201. DEVICE_DESC_PARAM_TYPE = 0x1,
  202. DEVICE_DESC_PARAM_DEVICE_TYPE = 0x2,
  203. DEVICE_DESC_PARAM_DEVICE_CLASS = 0x3,
  204. DEVICE_DESC_PARAM_DEVICE_SUB_CLASS = 0x4,
  205. DEVICE_DESC_PARAM_PRTCL = 0x5,
  206. DEVICE_DESC_PARAM_NUM_LU = 0x6,
  207. DEVICE_DESC_PARAM_NUM_WLU = 0x7,
  208. DEVICE_DESC_PARAM_BOOT_ENBL = 0x8,
  209. DEVICE_DESC_PARAM_DESC_ACCSS_ENBL = 0x9,
  210. DEVICE_DESC_PARAM_INIT_PWR_MODE = 0xA,
  211. DEVICE_DESC_PARAM_HIGH_PR_LUN = 0xB,
  212. DEVICE_DESC_PARAM_SEC_RMV_TYPE = 0xC,
  213. DEVICE_DESC_PARAM_SEC_LU = 0xD,
  214. DEVICE_DESC_PARAM_BKOP_TERM_LT = 0xE,
  215. DEVICE_DESC_PARAM_ACTVE_ICC_LVL = 0xF,
  216. DEVICE_DESC_PARAM_SPEC_VER = 0x10,
  217. DEVICE_DESC_PARAM_MANF_DATE = 0x12,
  218. DEVICE_DESC_PARAM_MANF_NAME = 0x14,
  219. DEVICE_DESC_PARAM_PRDCT_NAME = 0x15,
  220. DEVICE_DESC_PARAM_SN = 0x16,
  221. DEVICE_DESC_PARAM_OEM_ID = 0x17,
  222. DEVICE_DESC_PARAM_MANF_ID = 0x18,
  223. DEVICE_DESC_PARAM_UD_OFFSET = 0x1A,
  224. DEVICE_DESC_PARAM_UD_LEN = 0x1B,
  225. DEVICE_DESC_PARAM_RTT_CAP = 0x1C,
  226. DEVICE_DESC_PARAM_FRQ_RTC = 0x1D,
  227. DEVICE_DESC_PARAM_FEAT_SUP = 0x1F,
  228. DEVICE_DESC_PARAM_HPB_VER = 0x40,
  229. DEVICE_DESC_PARAM_EXT_FEAT_SUP = 0x4F,
  230. DEVICE_DESC_PARAM_TW_BUF_USER_REDUCED = 0x53,
  231. DEVICE_DESC_PARAM_TW_BUF_TYPE = 0x54,
  232. DEVICE_DESC_PARAM_TW_VER = 0x55, /* Sasmung version */
  233. DEVICE_DESC_PARAM_NUM_SHARED_WB_BUF_AU = 0x55, /* JEDEC version */
  234. };
  235. /* Configuration descriptor offsets in bytes */
  236. enum conf_desc_param {
  237. CONF_DESC_B_LENGTH = 0x0,
  238. CONF_DESC_B_DESCRIPTOR_TYPE = 0x1,
  239. CONF_DESC_B_BOOT_ENABLE = 0x3,
  240. CONF_DESC_B_DESCR_ACCESS_EN = 0x4,
  241. CONF_DESC_B_INIT_POWER_MODE = 0x5,
  242. CONF_DESC_B_HIGH_PRIORITY_LUN = 0x6,
  243. CONF_DESC_B_SECURE_REMOVAL_TYPE = 0x7,
  244. CONF_DESC_B_INIT_ACTIVE_ICC_LEVEL = 0x8,
  245. CONF_DESC_W_PERIOIDIC_RTC_UPDATE = 0x9,
  246. CONF_DESC_B_HPB_CINTROL = 0xB, /* JEDEC version */
  247. CONF_DESC_B_TW_BUF_NO_RED_EN = 0x10,
  248. CONF_DESC_B_TW_BUF_TYPE = 0x11,
  249. CONF_DESC_D_NUM_SHARED_WB_BUF_AU = 0x12, /* JEDEC version */
  250. CONF_DESC_UNIT_B_LU_ENABLE = 0x0,
  251. CONF_DESC_UNIT_B_BOOT_LUN_ID = 0x1,
  252. CONF_DESC_UNIT_B_LU_WRITE_PROTECT = 0x2,
  253. CONF_DESC_UNIT_B_MEMORY_TYPE = 0x3,
  254. CONF_DESC_UNIT_D_NUM_ALLOC_UNITS = 0x4,
  255. CONF_DESC_UNIT_B_DATA_RELIABILITY = 0x8,
  256. CONF_DESC_UNIT_B_LOGICAL_BLOCK_SIZE = 0x9,
  257. CONF_DESC_UNIT_B_PROVISIONING_TYPE = 0xA,
  258. CONF_DESC_UNIT_W_CONTEXT_CAPABILITY = 0xB,
  259. CONF_DESC_UNIT_W_MAX_ACTIVE_HPB_REGIONS = 0x10,
  260. CONF_DESC_UNIT_W_HPB_PINNED_REGION_START_IDX = 0x12,
  261. CONF_DESC_UNIT_W_NUM_HPB_PINNED_REGIONS = 0x14,
  262. CONF_DESC_UNIT_D_NUM_TW_BUF_AU = 0x16
  263. };
  264. enum helath_desc_param {
  265. HEALTH_DESC_B_LENGTH = 0x0,
  266. HEALTH_DESC_B_DESCRIPTOR_IDN = 0x1,
  267. HEALTH_DESC_B_PRE_EOL_INFO = 0x2,
  268. HEALTH_DESC_B_DEVICE_LIFE_TIME_EST_A = 0x3,
  269. HEALTH_DESC_B_DEVICE_LIFE_TIME_EST_B = 0x4,
  270. };
  271. #define UFS_MEMORY_TYPE_NORMAL (0)
  272. #define UFS_MEMORY_TYPE_SYSTEM_CODE (1)
  273. #define UFS_MEMORY_TYPE_NON_PERSISTENT (2)
  274. #define UFS_MEMORY_TYPE_ENHANCED_1 (3)
  275. #define UFS_MEMORY_TYPE_ENHANCED_2 (4)
  276. #define UFS_MEMORY_TYPE_ENHANCED_3 (5)
  277. #define UFS_MEMORY_TYPE_ENHANCED_4 (6)
  278. #define UFS_BOOT_LU_SIZE_BYTE (4 * 1024 * 1024) // 4 MB
  279. #define UFS_BOOT_LU_SIZE_BYTE_DEC (16 * 1024 * 1024) // 16 MB
  280. /*
  281. * Logical Unit Write Protect
  282. * 00h: LU not write protected
  283. * 01h: LU write protected when fPowerOnWPEn =1
  284. * 02h: LU permanently write protected when fPermanentWPEn =1
  285. */
  286. enum ufs_lu_wp_type {
  287. UFS_LU_NO_WP = 0x00,
  288. UFS_LU_POWER_ON_WP = 0x01,
  289. UFS_LU_PERM_WP = 0x02,
  290. };
  291. /* bActiveICCLevel parameter current units */
  292. enum {
  293. UFSHCD_NANO_AMP = 0,
  294. UFSHCD_MICRO_AMP = 1,
  295. UFSHCD_MILI_AMP = 2,
  296. UFSHCD_AMP = 3,
  297. };
  298. #define POWER_DESC_MAX_SIZE 0x62
  299. #define POWER_DESC_MAX_ACTV_ICC_LVLS 16
  300. /* Attribute bActiveICCLevel parameter bit masks definitions */
  301. #define ATTR_ICC_LVL_UNIT_OFFSET 14
  302. #define ATTR_ICC_LVL_UNIT_MASK (0x3 << ATTR_ICC_LVL_UNIT_OFFSET)
  303. #define ATTR_ICC_LVL_VALUE_MASK 0x3FF
  304. /* Power descriptor parameters offsets in bytes */
  305. enum power_desc_param_offset {
  306. PWR_DESC_LEN = 0x0,
  307. PWR_DESC_TYPE = 0x1,
  308. PWR_DESC_ACTIVE_LVLS_VCC_0 = 0x2,
  309. PWR_DESC_ACTIVE_LVLS_VCCQ_0 = 0x22,
  310. PWR_DESC_ACTIVE_LVLS_VCCQ2_0 = 0x42,
  311. };
  312. #define ATTR_B_BOOT_LUN_EN (0x0)
  313. #define ATTR_B_REF_CLK_FREQ (0xA)
  314. #define ATTR_B_CONFIG_DESCR_LOCK (0xB)
  315. #define ATTR_B_BOOT_LUN_EN_BOOT_DISABLED (0) //00h: Boot disabled (default)
  316. #define ATTR_B_BOOT_LUN_EN_BOOT_LU_A (1) //01h: Enabled boot from Boot LU A
  317. #define ATTR_B_BOOT_LUN_EN_BOOT_LU_B (2) //02h: Enabled boot from Boot LU B
  318. /* Exception event mask values */
  319. enum {
  320. MASK_EE_STATUS = 0xFFFF,
  321. MASK_EE_URGENT_BKOPS = (1 << 2),
  322. };
  323. /* Background operation status */
  324. enum bkops_status {
  325. BKOPS_STATUS_NO_OP = 0x0,
  326. BKOPS_STATUS_NON_CRITICAL = 0x1,
  327. BKOPS_STATUS_PERF_IMPACT = 0x2,
  328. BKOPS_STATUS_CRITICAL = 0x3,
  329. BKOPS_STATUS_MAX = BKOPS_STATUS_CRITICAL,
  330. };
  331. /* UTP QUERY Transaction Specific Fields OpCode */
  332. enum query_opcode {
  333. UPIU_QUERY_OPCODE_NOP = 0x0,
  334. UPIU_QUERY_OPCODE_READ_DESC = 0x1,
  335. UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
  336. UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
  337. UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
  338. UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
  339. UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
  340. UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
  341. UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
  342. };
  343. /* Query response result code */
  344. enum {
  345. QUERY_RESULT_SUCCESS = 0x00,
  346. QUERY_RESULT_NOT_READABLE = 0xF6,
  347. QUERY_RESULT_NOT_WRITEABLE = 0xF7,
  348. QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
  349. QUERY_RESULT_INVALID_LENGTH = 0xF9,
  350. QUERY_RESULT_INVALID_VALUE = 0xFA,
  351. QUERY_RESULT_INVALID_SELECTOR = 0xFB,
  352. QUERY_RESULT_INVALID_INDEX = 0xFC,
  353. QUERY_RESULT_INVALID_IDN = 0xFD,
  354. QUERY_RESULT_INVALID_OPCODE = 0xFE,
  355. QUERY_RESULT_GENERAL_FAILURE = 0xFF,
  356. };
  357. /* UTP Transfer Request Command Type (CT) */
  358. enum {
  359. UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
  360. UPIU_COMMAND_SET_TYPE_UFS = 0x1,
  361. UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
  362. };
  363. /* UTP Transfer Request Command Offset */
  364. #define UPIU_COMMAND_TYPE_OFFSET 28
  365. /* Offset of the response code in the UPIU header */
  366. #define UPIU_RSP_CODE_OFFSET 8
  367. enum {
  368. MASK_SCSI_STATUS = 0xFF,
  369. MASK_TASK_RESPONSE = 0xFF00,
  370. MASK_RSP_UPIU_RESULT = 0xFFFF,
  371. MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
  372. MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF,
  373. MASK_RSP_EXCEPTION_EVENT = 0x10000,
  374. };
  375. /* Task management service response */
  376. enum {
  377. UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
  378. UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
  379. UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
  380. UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
  381. UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
  382. };
  383. /* UFS device power modes */
  384. enum ufs_dev_pwr_mode {
  385. UFS_ACTIVE_PWR_MODE = 1,
  386. UFS_SLEEP_PWR_MODE = 2,
  387. UFS_POWERDOWN_PWR_MODE = 3,
  388. };
  389. struct ufs_ocs_error {
  390. const char * name;
  391. u8 err;
  392. };
  393. /**
  394. * struct utp_upiu_header - UPIU header structure
  395. * @dword_0: UPIU header DW-0
  396. * @dword_1: UPIU header DW-1
  397. * @dword_2: UPIU header DW-2
  398. */
  399. struct utp_upiu_header {
  400. __be32 dword_0;
  401. __be32 dword_1;
  402. __be32 dword_2;
  403. };
  404. /**
  405. * struct utp_upiu_cmd - Command UPIU structure
  406. * @data_transfer_len: Data Transfer Length DW-3
  407. * @cdb: Command Descriptor Block CDB DW-4 to DW-7
  408. */
  409. struct utp_upiu_cmd {
  410. __be32 exp_data_transfer_len;
  411. u8 cdb[MAX_CDB_SIZE];
  412. };
  413. /**
  414. * struct utp_upiu_query - upiu request buffer structure for
  415. * query request.
  416. * @opcode: command to perform B-0
  417. * @idn: a value that indicates the particular type of data B-1
  418. * @index: Index to further identify data B-2
  419. * @selector: Index to further identify data B-3
  420. * @reserved_osf: spec reserved field B-4,5
  421. * @length: number of descriptor bytes to read/write B-6,7
  422. * @value: Attribute value to be written DW-5
  423. * @reserved: spec reserved DW-6,7
  424. */
  425. struct utp_upiu_query {
  426. u8 opcode;
  427. u8 idn;
  428. u8 index;
  429. u8 selector;
  430. __be16 reserved_osf;
  431. __be16 length;
  432. __be32 value;
  433. __be32 reserved[2];
  434. };
  435. /**
  436. * struct utp_upiu_req - general upiu request structure
  437. * @header:UPIU header structure DW-0 to DW-2
  438. * @sc: fields structure for scsi command DW-3 to DW-7
  439. * @qr: fields structure for query request DW-3 to DW-7
  440. */
  441. struct utp_upiu_req {
  442. struct utp_upiu_header header;
  443. union {
  444. struct utp_upiu_cmd sc;
  445. struct utp_upiu_query qr;
  446. };
  447. };
  448. /**
  449. * struct utp_cmd_rsp - Response UPIU structure
  450. * @residual_transfer_count: Residual transfer count DW-3
  451. * @reserved: Reserved double words DW-4 to DW-7
  452. * @sense_data_len: Sense data length DW-8 U16
  453. * @sense_data: Sense data field DW-8 to DW-12
  454. */
  455. struct utp_cmd_rsp {
  456. __be32 residual_transfer_count;
  457. __be32 reserved[4];
  458. __be16 sense_data_len;
  459. u8 sense_data[18];
  460. };
  461. /**
  462. * struct utp_upiu_rsp - general upiu response structure
  463. * @header: UPIU header structure DW-0 to DW-2
  464. * @sr: fields structure for scsi command DW-3 to DW-12
  465. * @qr: fields structure for query request DW-3 to DW-7
  466. */
  467. struct utp_upiu_rsp {
  468. struct utp_upiu_header header;
  469. union {
  470. struct utp_cmd_rsp sr;
  471. struct utp_upiu_query qr;
  472. };
  473. };
  474. /**
  475. * struct utp_upiu_task_req - Task request UPIU structure
  476. * @header - UPIU header structure DW0 to DW-2
  477. * @input_param1: Input parameter 1 DW-3
  478. * @input_param2: Input parameter 2 DW-4
  479. * @input_param3: Input parameter 3 DW-5
  480. * @reserved: Reserved double words DW-6 to DW-7
  481. */
  482. struct utp_upiu_task_req {
  483. struct utp_upiu_header header;
  484. __be32 input_param1;
  485. __be32 input_param2;
  486. __be32 input_param3;
  487. __be32 reserved[2];
  488. };
  489. /**
  490. * struct utp_upiu_task_rsp - Task Management Response UPIU structure
  491. * @header: UPIU header structure DW0-DW-2
  492. * @output_param1: Ouput parameter 1 DW3
  493. * @output_param2: Output parameter 2 DW4
  494. * @reserved: Reserved double words DW-5 to DW-7
  495. */
  496. struct utp_upiu_task_rsp {
  497. struct utp_upiu_header header;
  498. __be32 output_param1;
  499. __be32 output_param2;
  500. __be32 reserved[3];
  501. };
  502. /**
  503. * struct ufs_query_req - parameters for building a query request
  504. * @query_func: UPIU header query function
  505. * @upiu_req: the query request data
  506. */
  507. struct ufs_query_req {
  508. u8 query_func;
  509. struct utp_upiu_query upiu_req;
  510. };
  511. /**
  512. * struct ufs_query_resp - UPIU QUERY
  513. * @response: device response code
  514. * @upiu_res: query response data
  515. */
  516. struct ufs_query_res {
  517. u8 response;
  518. struct utp_upiu_query upiu_res;
  519. };
  520. /**
  521. * PIO mode related definitions
  522. */
  523. // UPIU cmds buffer size
  524. #define UFS_AIO_PIO_UPIU_CMD_BUF_SIZE (0x20)
  525. // HCI registers settings
  526. #define UFS_HCI_REGISTER_FLAG_CDARES (0x3 << 20)
  527. #define UFS_HCI_REGISTER_FLAG_CDABUSY (0x1 << 19)
  528. #define UFS_HCI_REGISTER_FLAG_CDASTA (0x1 << 18)
  529. //Length Macros
  530. #define LEN_10 (10)
  531. #define LEN_30 (30)
  532. #define LEN_32 (32)
  533. #define LEN_64 (64)
  534. #define LEN_100 (100)
  535. #define LEN_1000 (1000)
  536. #define LEN_3000 (3000)
  537. #define LEN_10000 (10000)
  538. #define LEN_1000000 (1000000)
  539. //UPIU cmds Response
  540. #define UPIU_RESPONSE_SUCCESS (0x0)
  541. #define UPIU_CMD_STATUS_GOOD (0x0)
  542. #define UPIU_CMD_STATUS_CHECK_COND (0x2)
  543. //UPIU cmds buffer size
  544. #define UPIU_CMD_BUF_SIZE (0x20)
  545. //UPIU data buffer size, max usage 0x40 for Read Device Descriptor, keep some buffer here
  546. #define UFS_TEMP_BUF_SIZE (0x100)
  547. #endif /* End of Header */