xref: /openbmc/linux/include/ufs/ufs.h (revision 078b39c9)
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 
11 #ifndef _UFS_H
12 #define _UFS_H
13 
14 #include <linux/mutex.h>
15 #include <linux/types.h>
16 #include <uapi/scsi/scsi_bsg_ufs.h>
17 
18 #define GENERAL_UPIU_REQUEST_SIZE (sizeof(struct utp_upiu_req))
19 #define QUERY_DESC_MAX_SIZE       255
20 #define QUERY_DESC_MIN_SIZE       2
21 #define QUERY_DESC_HDR_SIZE       2
22 #define QUERY_OSF_SIZE            (GENERAL_UPIU_REQUEST_SIZE - \
23 					(sizeof(struct utp_upiu_header)))
24 #define UFS_SENSE_SIZE	18
25 
26 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
27 			cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
28 			 (byte1 << 8) | (byte0))
29 /*
30  * UFS device may have standard LUs and LUN id could be from 0x00 to
31  * 0x7F. Standard LUs use "Peripheral Device Addressing Format".
32  * UFS device may also have the Well Known LUs (also referred as W-LU)
33  * which again could be from 0x00 to 0x7F. For W-LUs, device only use
34  * the "Extended Addressing Format" which means the W-LUNs would be
35  * from 0xc100 (SCSI_W_LUN_BASE) onwards.
36  * This means max. LUN number reported from UFS device could be 0xC17F.
37  */
38 #define UFS_UPIU_MAX_UNIT_NUM_ID	0x7F
39 #define UFS_MAX_LUNS		(SCSI_W_LUN_BASE + UFS_UPIU_MAX_UNIT_NUM_ID)
40 #define UFS_UPIU_WLUN_ID	(1 << 7)
41 
42 /* WriteBooster buffer is available only for the logical unit from 0 to 7 */
43 #define UFS_UPIU_MAX_WB_LUN_ID	8
44 
45 /*
46  * WriteBooster buffer lifetime has a limit setted by vendor.
47  * If it is over the limit, WriteBooster feature will be disabled.
48  */
49 #define UFS_WB_EXCEED_LIFETIME		0x0B
50 
51 /*
52  * In UFS Spec, the Extra Header Segment (EHS) starts from byte 32 in UPIU request/response packet
53  */
54 #define EHS_OFFSET_IN_RESPONSE 32
55 
56 /* Well known logical unit id in LUN field of UPIU */
57 enum {
58 	UFS_UPIU_REPORT_LUNS_WLUN	= 0x81,
59 	UFS_UPIU_UFS_DEVICE_WLUN	= 0xD0,
60 	UFS_UPIU_BOOT_WLUN		= 0xB0,
61 	UFS_UPIU_RPMB_WLUN		= 0xC4,
62 };
63 
64 /*
65  * UFS Protocol Information Unit related definitions
66  */
67 
68 /* Task management functions */
69 enum {
70 	UFS_ABORT_TASK		= 0x01,
71 	UFS_ABORT_TASK_SET	= 0x02,
72 	UFS_CLEAR_TASK_SET	= 0x04,
73 	UFS_LOGICAL_RESET	= 0x08,
74 	UFS_QUERY_TASK		= 0x80,
75 	UFS_QUERY_TASK_SET	= 0x81,
76 };
77 
78 /* UTP UPIU Transaction Codes Initiator to Target */
79 enum {
80 	UPIU_TRANSACTION_NOP_OUT	= 0x00,
81 	UPIU_TRANSACTION_COMMAND	= 0x01,
82 	UPIU_TRANSACTION_DATA_OUT	= 0x02,
83 	UPIU_TRANSACTION_TASK_REQ	= 0x04,
84 	UPIU_TRANSACTION_QUERY_REQ	= 0x16,
85 };
86 
87 /* UTP UPIU Transaction Codes Target to Initiator */
88 enum {
89 	UPIU_TRANSACTION_NOP_IN		= 0x20,
90 	UPIU_TRANSACTION_RESPONSE	= 0x21,
91 	UPIU_TRANSACTION_DATA_IN	= 0x22,
92 	UPIU_TRANSACTION_TASK_RSP	= 0x24,
93 	UPIU_TRANSACTION_READY_XFER	= 0x31,
94 	UPIU_TRANSACTION_QUERY_RSP	= 0x36,
95 	UPIU_TRANSACTION_REJECT_UPIU	= 0x3F,
96 };
97 
98 /* UPIU Read/Write flags */
99 enum {
100 	UPIU_CMD_FLAGS_NONE	= 0x00,
101 	UPIU_CMD_FLAGS_WRITE	= 0x20,
102 	UPIU_CMD_FLAGS_READ	= 0x40,
103 };
104 
105 /* UPIU Task Attributes */
106 enum {
107 	UPIU_TASK_ATTR_SIMPLE	= 0x00,
108 	UPIU_TASK_ATTR_ORDERED	= 0x01,
109 	UPIU_TASK_ATTR_HEADQ	= 0x02,
110 	UPIU_TASK_ATTR_ACA	= 0x03,
111 };
112 
113 /* UPIU Query request function */
114 enum {
115 	UPIU_QUERY_FUNC_STANDARD_READ_REQUEST           = 0x01,
116 	UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST          = 0x81,
117 };
118 
119 /* Flag idn for Query Requests*/
120 enum flag_idn {
121 	QUERY_FLAG_IDN_FDEVICEINIT			= 0x01,
122 	QUERY_FLAG_IDN_PERMANENT_WPE			= 0x02,
123 	QUERY_FLAG_IDN_PWR_ON_WPE			= 0x03,
124 	QUERY_FLAG_IDN_BKOPS_EN				= 0x04,
125 	QUERY_FLAG_IDN_LIFE_SPAN_MODE_ENABLE		= 0x05,
126 	QUERY_FLAG_IDN_PURGE_ENABLE			= 0x06,
127 	QUERY_FLAG_IDN_RESERVED2			= 0x07,
128 	QUERY_FLAG_IDN_FPHYRESOURCEREMOVAL		= 0x08,
129 	QUERY_FLAG_IDN_BUSY_RTC				= 0x09,
130 	QUERY_FLAG_IDN_RESERVED3			= 0x0A,
131 	QUERY_FLAG_IDN_PERMANENTLY_DISABLE_FW_UPDATE	= 0x0B,
132 	QUERY_FLAG_IDN_WB_EN                            = 0x0E,
133 	QUERY_FLAG_IDN_WB_BUFF_FLUSH_EN                 = 0x0F,
134 	QUERY_FLAG_IDN_WB_BUFF_FLUSH_DURING_HIBERN8     = 0x10,
135 	QUERY_FLAG_IDN_HPB_RESET                        = 0x11,
136 	QUERY_FLAG_IDN_HPB_EN				= 0x12,
137 };
138 
139 /* Attribute idn for Query requests */
140 enum attr_idn {
141 	QUERY_ATTR_IDN_BOOT_LU_EN		= 0x00,
142 	QUERY_ATTR_IDN_MAX_HPB_SINGLE_CMD	= 0x01,
143 	QUERY_ATTR_IDN_POWER_MODE		= 0x02,
144 	QUERY_ATTR_IDN_ACTIVE_ICC_LVL		= 0x03,
145 	QUERY_ATTR_IDN_OOO_DATA_EN		= 0x04,
146 	QUERY_ATTR_IDN_BKOPS_STATUS		= 0x05,
147 	QUERY_ATTR_IDN_PURGE_STATUS		= 0x06,
148 	QUERY_ATTR_IDN_MAX_DATA_IN		= 0x07,
149 	QUERY_ATTR_IDN_MAX_DATA_OUT		= 0x08,
150 	QUERY_ATTR_IDN_DYN_CAP_NEEDED		= 0x09,
151 	QUERY_ATTR_IDN_REF_CLK_FREQ		= 0x0A,
152 	QUERY_ATTR_IDN_CONF_DESC_LOCK		= 0x0B,
153 	QUERY_ATTR_IDN_MAX_NUM_OF_RTT		= 0x0C,
154 	QUERY_ATTR_IDN_EE_CONTROL		= 0x0D,
155 	QUERY_ATTR_IDN_EE_STATUS		= 0x0E,
156 	QUERY_ATTR_IDN_SECONDS_PASSED		= 0x0F,
157 	QUERY_ATTR_IDN_CNTX_CONF		= 0x10,
158 	QUERY_ATTR_IDN_CORR_PRG_BLK_NUM		= 0x11,
159 	QUERY_ATTR_IDN_RESERVED2		= 0x12,
160 	QUERY_ATTR_IDN_RESERVED3		= 0x13,
161 	QUERY_ATTR_IDN_FFU_STATUS		= 0x14,
162 	QUERY_ATTR_IDN_PSA_STATE		= 0x15,
163 	QUERY_ATTR_IDN_PSA_DATA_SIZE		= 0x16,
164 	QUERY_ATTR_IDN_REF_CLK_GATING_WAIT_TIME	= 0x17,
165 	QUERY_ATTR_IDN_CASE_ROUGH_TEMP          = 0x18,
166 	QUERY_ATTR_IDN_HIGH_TEMP_BOUND          = 0x19,
167 	QUERY_ATTR_IDN_LOW_TEMP_BOUND           = 0x1A,
168 	QUERY_ATTR_IDN_WB_FLUSH_STATUS	        = 0x1C,
169 	QUERY_ATTR_IDN_AVAIL_WB_BUFF_SIZE       = 0x1D,
170 	QUERY_ATTR_IDN_WB_BUFF_LIFE_TIME_EST    = 0x1E,
171 	QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE        = 0x1F,
172 	QUERY_ATTR_IDN_EXT_IID_EN		= 0x2A,
173 	QUERY_ATTR_IDN_TIMESTAMP		= 0x30
174 };
175 
176 /* Descriptor idn for Query requests */
177 enum desc_idn {
178 	QUERY_DESC_IDN_DEVICE		= 0x0,
179 	QUERY_DESC_IDN_CONFIGURATION	= 0x1,
180 	QUERY_DESC_IDN_UNIT		= 0x2,
181 	QUERY_DESC_IDN_RFU_0		= 0x3,
182 	QUERY_DESC_IDN_INTERCONNECT	= 0x4,
183 	QUERY_DESC_IDN_STRING		= 0x5,
184 	QUERY_DESC_IDN_RFU_1		= 0x6,
185 	QUERY_DESC_IDN_GEOMETRY		= 0x7,
186 	QUERY_DESC_IDN_POWER		= 0x8,
187 	QUERY_DESC_IDN_HEALTH           = 0x9,
188 	QUERY_DESC_IDN_MAX,
189 };
190 
191 enum desc_header_offset {
192 	QUERY_DESC_LENGTH_OFFSET	= 0x00,
193 	QUERY_DESC_DESC_TYPE_OFFSET	= 0x01,
194 };
195 
196 /* Unit descriptor parameters offsets in bytes*/
197 enum unit_desc_param {
198 	UNIT_DESC_PARAM_LEN			= 0x0,
199 	UNIT_DESC_PARAM_TYPE			= 0x1,
200 	UNIT_DESC_PARAM_UNIT_INDEX		= 0x2,
201 	UNIT_DESC_PARAM_LU_ENABLE		= 0x3,
202 	UNIT_DESC_PARAM_BOOT_LUN_ID		= 0x4,
203 	UNIT_DESC_PARAM_LU_WR_PROTECT		= 0x5,
204 	UNIT_DESC_PARAM_LU_Q_DEPTH		= 0x6,
205 	UNIT_DESC_PARAM_PSA_SENSITIVE		= 0x7,
206 	UNIT_DESC_PARAM_MEM_TYPE		= 0x8,
207 	UNIT_DESC_PARAM_DATA_RELIABILITY	= 0x9,
208 	UNIT_DESC_PARAM_LOGICAL_BLK_SIZE	= 0xA,
209 	UNIT_DESC_PARAM_LOGICAL_BLK_COUNT	= 0xB,
210 	UNIT_DESC_PARAM_ERASE_BLK_SIZE		= 0x13,
211 	UNIT_DESC_PARAM_PROVISIONING_TYPE	= 0x17,
212 	UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT	= 0x18,
213 	UNIT_DESC_PARAM_CTX_CAPABILITIES	= 0x20,
214 	UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1	= 0x22,
215 	UNIT_DESC_PARAM_HPB_LU_MAX_ACTIVE_RGNS	= 0x23,
216 	UNIT_DESC_PARAM_HPB_PIN_RGN_START_OFF	= 0x25,
217 	UNIT_DESC_PARAM_HPB_NUM_PIN_RGNS	= 0x27,
218 	UNIT_DESC_PARAM_WB_BUF_ALLOC_UNITS	= 0x29,
219 };
220 
221 /* RPMB Unit descriptor parameters offsets in bytes*/
222 enum rpmb_unit_desc_param {
223 	RPMB_UNIT_DESC_PARAM_LEN		= 0x0,
224 	RPMB_UNIT_DESC_PARAM_TYPE		= 0x1,
225 	RPMB_UNIT_DESC_PARAM_UNIT_INDEX		= 0x2,
226 	RPMB_UNIT_DESC_PARAM_LU_ENABLE		= 0x3,
227 	RPMB_UNIT_DESC_PARAM_BOOT_LUN_ID	= 0x4,
228 	RPMB_UNIT_DESC_PARAM_LU_WR_PROTECT	= 0x5,
229 	RPMB_UNIT_DESC_PARAM_LU_Q_DEPTH		= 0x6,
230 	RPMB_UNIT_DESC_PARAM_PSA_SENSITIVE	= 0x7,
231 	RPMB_UNIT_DESC_PARAM_MEM_TYPE		= 0x8,
232 	RPMB_UNIT_DESC_PARAM_REGION_EN		= 0x9,
233 	RPMB_UNIT_DESC_PARAM_LOGICAL_BLK_SIZE	= 0xA,
234 	RPMB_UNIT_DESC_PARAM_LOGICAL_BLK_COUNT	= 0xB,
235 	RPMB_UNIT_DESC_PARAM_REGION0_SIZE	= 0x13,
236 	RPMB_UNIT_DESC_PARAM_REGION1_SIZE	= 0x14,
237 	RPMB_UNIT_DESC_PARAM_REGION2_SIZE	= 0x15,
238 	RPMB_UNIT_DESC_PARAM_REGION3_SIZE	= 0x16,
239 	RPMB_UNIT_DESC_PARAM_PROVISIONING_TYPE	= 0x17,
240 	RPMB_UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT	= 0x18,
241 };
242 
243 /* Device descriptor parameters offsets in bytes*/
244 enum device_desc_param {
245 	DEVICE_DESC_PARAM_LEN			= 0x0,
246 	DEVICE_DESC_PARAM_TYPE			= 0x1,
247 	DEVICE_DESC_PARAM_DEVICE_TYPE		= 0x2,
248 	DEVICE_DESC_PARAM_DEVICE_CLASS		= 0x3,
249 	DEVICE_DESC_PARAM_DEVICE_SUB_CLASS	= 0x4,
250 	DEVICE_DESC_PARAM_PRTCL			= 0x5,
251 	DEVICE_DESC_PARAM_NUM_LU		= 0x6,
252 	DEVICE_DESC_PARAM_NUM_WLU		= 0x7,
253 	DEVICE_DESC_PARAM_BOOT_ENBL		= 0x8,
254 	DEVICE_DESC_PARAM_DESC_ACCSS_ENBL	= 0x9,
255 	DEVICE_DESC_PARAM_INIT_PWR_MODE		= 0xA,
256 	DEVICE_DESC_PARAM_HIGH_PR_LUN		= 0xB,
257 	DEVICE_DESC_PARAM_SEC_RMV_TYPE		= 0xC,
258 	DEVICE_DESC_PARAM_SEC_LU		= 0xD,
259 	DEVICE_DESC_PARAM_BKOP_TERM_LT		= 0xE,
260 	DEVICE_DESC_PARAM_ACTVE_ICC_LVL		= 0xF,
261 	DEVICE_DESC_PARAM_SPEC_VER		= 0x10,
262 	DEVICE_DESC_PARAM_MANF_DATE		= 0x12,
263 	DEVICE_DESC_PARAM_MANF_NAME		= 0x14,
264 	DEVICE_DESC_PARAM_PRDCT_NAME		= 0x15,
265 	DEVICE_DESC_PARAM_SN			= 0x16,
266 	DEVICE_DESC_PARAM_OEM_ID		= 0x17,
267 	DEVICE_DESC_PARAM_MANF_ID		= 0x18,
268 	DEVICE_DESC_PARAM_UD_OFFSET		= 0x1A,
269 	DEVICE_DESC_PARAM_UD_LEN		= 0x1B,
270 	DEVICE_DESC_PARAM_RTT_CAP		= 0x1C,
271 	DEVICE_DESC_PARAM_FRQ_RTC		= 0x1D,
272 	DEVICE_DESC_PARAM_UFS_FEAT		= 0x1F,
273 	DEVICE_DESC_PARAM_FFU_TMT		= 0x20,
274 	DEVICE_DESC_PARAM_Q_DPTH		= 0x21,
275 	DEVICE_DESC_PARAM_DEV_VER		= 0x22,
276 	DEVICE_DESC_PARAM_NUM_SEC_WPA		= 0x24,
277 	DEVICE_DESC_PARAM_PSA_MAX_DATA		= 0x25,
278 	DEVICE_DESC_PARAM_PSA_TMT		= 0x29,
279 	DEVICE_DESC_PARAM_PRDCT_REV		= 0x2A,
280 	DEVICE_DESC_PARAM_HPB_VER		= 0x40,
281 	DEVICE_DESC_PARAM_HPB_CONTROL		= 0x42,
282 	DEVICE_DESC_PARAM_EXT_UFS_FEATURE_SUP	= 0x4F,
283 	DEVICE_DESC_PARAM_WB_PRESRV_USRSPC_EN	= 0x53,
284 	DEVICE_DESC_PARAM_WB_TYPE		= 0x54,
285 	DEVICE_DESC_PARAM_WB_SHARED_ALLOC_UNITS = 0x55,
286 };
287 
288 /* Interconnect descriptor parameters offsets in bytes*/
289 enum interconnect_desc_param {
290 	INTERCONNECT_DESC_PARAM_LEN		= 0x0,
291 	INTERCONNECT_DESC_PARAM_TYPE		= 0x1,
292 	INTERCONNECT_DESC_PARAM_UNIPRO_VER	= 0x2,
293 	INTERCONNECT_DESC_PARAM_MPHY_VER	= 0x4,
294 };
295 
296 /* Geometry descriptor parameters offsets in bytes*/
297 enum geometry_desc_param {
298 	GEOMETRY_DESC_PARAM_LEN			= 0x0,
299 	GEOMETRY_DESC_PARAM_TYPE		= 0x1,
300 	GEOMETRY_DESC_PARAM_DEV_CAP		= 0x4,
301 	GEOMETRY_DESC_PARAM_MAX_NUM_LUN		= 0xC,
302 	GEOMETRY_DESC_PARAM_SEG_SIZE		= 0xD,
303 	GEOMETRY_DESC_PARAM_ALLOC_UNIT_SIZE	= 0x11,
304 	GEOMETRY_DESC_PARAM_MIN_BLK_SIZE	= 0x12,
305 	GEOMETRY_DESC_PARAM_OPT_RD_BLK_SIZE	= 0x13,
306 	GEOMETRY_DESC_PARAM_OPT_WR_BLK_SIZE	= 0x14,
307 	GEOMETRY_DESC_PARAM_MAX_IN_BUF_SIZE	= 0x15,
308 	GEOMETRY_DESC_PARAM_MAX_OUT_BUF_SIZE	= 0x16,
309 	GEOMETRY_DESC_PARAM_RPMB_RW_SIZE	= 0x17,
310 	GEOMETRY_DESC_PARAM_DYN_CAP_RSRC_PLC	= 0x18,
311 	GEOMETRY_DESC_PARAM_DATA_ORDER		= 0x19,
312 	GEOMETRY_DESC_PARAM_MAX_NUM_CTX		= 0x1A,
313 	GEOMETRY_DESC_PARAM_TAG_UNIT_SIZE	= 0x1B,
314 	GEOMETRY_DESC_PARAM_TAG_RSRC_SIZE	= 0x1C,
315 	GEOMETRY_DESC_PARAM_SEC_RM_TYPES	= 0x1D,
316 	GEOMETRY_DESC_PARAM_MEM_TYPES		= 0x1E,
317 	GEOMETRY_DESC_PARAM_SCM_MAX_NUM_UNITS	= 0x20,
318 	GEOMETRY_DESC_PARAM_SCM_CAP_ADJ_FCTR	= 0x24,
319 	GEOMETRY_DESC_PARAM_NPM_MAX_NUM_UNITS	= 0x26,
320 	GEOMETRY_DESC_PARAM_NPM_CAP_ADJ_FCTR	= 0x2A,
321 	GEOMETRY_DESC_PARAM_ENM1_MAX_NUM_UNITS	= 0x2C,
322 	GEOMETRY_DESC_PARAM_ENM1_CAP_ADJ_FCTR	= 0x30,
323 	GEOMETRY_DESC_PARAM_ENM2_MAX_NUM_UNITS	= 0x32,
324 	GEOMETRY_DESC_PARAM_ENM2_CAP_ADJ_FCTR	= 0x36,
325 	GEOMETRY_DESC_PARAM_ENM3_MAX_NUM_UNITS	= 0x38,
326 	GEOMETRY_DESC_PARAM_ENM3_CAP_ADJ_FCTR	= 0x3C,
327 	GEOMETRY_DESC_PARAM_ENM4_MAX_NUM_UNITS	= 0x3E,
328 	GEOMETRY_DESC_PARAM_ENM4_CAP_ADJ_FCTR	= 0x42,
329 	GEOMETRY_DESC_PARAM_OPT_LOG_BLK_SIZE	= 0x44,
330 	GEOMETRY_DESC_PARAM_HPB_REGION_SIZE	= 0x48,
331 	GEOMETRY_DESC_PARAM_HPB_NUMBER_LU	= 0x49,
332 	GEOMETRY_DESC_PARAM_HPB_SUBREGION_SIZE	= 0x4A,
333 	GEOMETRY_DESC_PARAM_HPB_MAX_ACTIVE_REGS	= 0x4B,
334 	GEOMETRY_DESC_PARAM_WB_MAX_ALLOC_UNITS	= 0x4F,
335 	GEOMETRY_DESC_PARAM_WB_MAX_WB_LUNS	= 0x53,
336 	GEOMETRY_DESC_PARAM_WB_BUFF_CAP_ADJ	= 0x54,
337 	GEOMETRY_DESC_PARAM_WB_SUP_RED_TYPE	= 0x55,
338 	GEOMETRY_DESC_PARAM_WB_SUP_WB_TYPE	= 0x56,
339 };
340 
341 /* Health descriptor parameters offsets in bytes*/
342 enum health_desc_param {
343 	HEALTH_DESC_PARAM_LEN			= 0x0,
344 	HEALTH_DESC_PARAM_TYPE			= 0x1,
345 	HEALTH_DESC_PARAM_EOL_INFO		= 0x2,
346 	HEALTH_DESC_PARAM_LIFE_TIME_EST_A	= 0x3,
347 	HEALTH_DESC_PARAM_LIFE_TIME_EST_B	= 0x4,
348 };
349 
350 /* WriteBooster buffer mode */
351 enum {
352 	WB_BUF_MODE_LU_DEDICATED	= 0x0,
353 	WB_BUF_MODE_SHARED		= 0x1,
354 };
355 
356 /*
357  * Logical Unit Write Protect
358  * 00h: LU not write protected
359  * 01h: LU write protected when fPowerOnWPEn =1
360  * 02h: LU permanently write protected when fPermanentWPEn =1
361  */
362 enum ufs_lu_wp_type {
363 	UFS_LU_NO_WP		= 0x00,
364 	UFS_LU_POWER_ON_WP	= 0x01,
365 	UFS_LU_PERM_WP		= 0x02,
366 };
367 
368 /* bActiveICCLevel parameter current units */
369 enum {
370 	UFSHCD_NANO_AMP		= 0,
371 	UFSHCD_MICRO_AMP	= 1,
372 	UFSHCD_MILI_AMP		= 2,
373 	UFSHCD_AMP		= 3,
374 };
375 
376 /* Possible values for dExtendedUFSFeaturesSupport */
377 enum {
378 	UFS_DEV_LOW_TEMP_NOTIF		= BIT(4),
379 	UFS_DEV_HIGH_TEMP_NOTIF		= BIT(5),
380 	UFS_DEV_EXT_TEMP_NOTIF		= BIT(6),
381 	UFS_DEV_HPB_SUPPORT		= BIT(7),
382 	UFS_DEV_WRITE_BOOSTER_SUP	= BIT(8),
383 	UFS_DEV_EXT_IID_SUP		= BIT(16),
384 };
385 #define UFS_DEV_HPB_SUPPORT_VERSION		0x310
386 
387 #define POWER_DESC_MAX_ACTV_ICC_LVLS		16
388 
389 /* Attribute  bActiveICCLevel parameter bit masks definitions */
390 #define ATTR_ICC_LVL_UNIT_OFFSET	14
391 #define ATTR_ICC_LVL_UNIT_MASK		(0x3 << ATTR_ICC_LVL_UNIT_OFFSET)
392 #define ATTR_ICC_LVL_VALUE_MASK		0x3FF
393 
394 /* Power descriptor parameters offsets in bytes */
395 enum power_desc_param_offset {
396 	PWR_DESC_LEN			= 0x0,
397 	PWR_DESC_TYPE			= 0x1,
398 	PWR_DESC_ACTIVE_LVLS_VCC_0	= 0x2,
399 	PWR_DESC_ACTIVE_LVLS_VCCQ_0	= 0x22,
400 	PWR_DESC_ACTIVE_LVLS_VCCQ2_0	= 0x42,
401 };
402 
403 /* Exception event mask values */
404 enum {
405 	MASK_EE_STATUS			= 0xFFFF,
406 	MASK_EE_DYNCAP_EVENT		= BIT(0),
407 	MASK_EE_SYSPOOL_EVENT		= BIT(1),
408 	MASK_EE_URGENT_BKOPS		= BIT(2),
409 	MASK_EE_TOO_HIGH_TEMP		= BIT(3),
410 	MASK_EE_TOO_LOW_TEMP		= BIT(4),
411 	MASK_EE_WRITEBOOSTER_EVENT	= BIT(5),
412 	MASK_EE_PERFORMANCE_THROTTLING	= BIT(6),
413 };
414 #define MASK_EE_URGENT_TEMP (MASK_EE_TOO_HIGH_TEMP | MASK_EE_TOO_LOW_TEMP)
415 
416 /* Background operation status */
417 enum bkops_status {
418 	BKOPS_STATUS_NO_OP               = 0x0,
419 	BKOPS_STATUS_NON_CRITICAL        = 0x1,
420 	BKOPS_STATUS_PERF_IMPACT         = 0x2,
421 	BKOPS_STATUS_CRITICAL            = 0x3,
422 	BKOPS_STATUS_MAX		 = BKOPS_STATUS_CRITICAL,
423 };
424 
425 /* UTP QUERY Transaction Specific Fields OpCode */
426 enum query_opcode {
427 	UPIU_QUERY_OPCODE_NOP		= 0x0,
428 	UPIU_QUERY_OPCODE_READ_DESC	= 0x1,
429 	UPIU_QUERY_OPCODE_WRITE_DESC	= 0x2,
430 	UPIU_QUERY_OPCODE_READ_ATTR	= 0x3,
431 	UPIU_QUERY_OPCODE_WRITE_ATTR	= 0x4,
432 	UPIU_QUERY_OPCODE_READ_FLAG	= 0x5,
433 	UPIU_QUERY_OPCODE_SET_FLAG	= 0x6,
434 	UPIU_QUERY_OPCODE_CLEAR_FLAG	= 0x7,
435 	UPIU_QUERY_OPCODE_TOGGLE_FLAG	= 0x8,
436 };
437 
438 /* bRefClkFreq attribute values */
439 enum ufs_ref_clk_freq {
440 	REF_CLK_FREQ_19_2_MHZ	= 0,
441 	REF_CLK_FREQ_26_MHZ	= 1,
442 	REF_CLK_FREQ_38_4_MHZ	= 2,
443 	REF_CLK_FREQ_52_MHZ	= 3,
444 	REF_CLK_FREQ_INVAL	= -1,
445 };
446 
447 /* Query response result code */
448 enum {
449 	QUERY_RESULT_SUCCESS                    = 0x00,
450 	QUERY_RESULT_NOT_READABLE               = 0xF6,
451 	QUERY_RESULT_NOT_WRITEABLE              = 0xF7,
452 	QUERY_RESULT_ALREADY_WRITTEN            = 0xF8,
453 	QUERY_RESULT_INVALID_LENGTH             = 0xF9,
454 	QUERY_RESULT_INVALID_VALUE              = 0xFA,
455 	QUERY_RESULT_INVALID_SELECTOR           = 0xFB,
456 	QUERY_RESULT_INVALID_INDEX              = 0xFC,
457 	QUERY_RESULT_INVALID_IDN                = 0xFD,
458 	QUERY_RESULT_INVALID_OPCODE             = 0xFE,
459 	QUERY_RESULT_GENERAL_FAILURE            = 0xFF,
460 };
461 
462 /* UTP Transfer Request Command Type (CT) */
463 enum {
464 	UPIU_COMMAND_SET_TYPE_SCSI	= 0x0,
465 	UPIU_COMMAND_SET_TYPE_UFS	= 0x1,
466 	UPIU_COMMAND_SET_TYPE_QUERY	= 0x2,
467 };
468 
469 /* UTP Transfer Request Command Offset */
470 #define UPIU_COMMAND_TYPE_OFFSET	28
471 
472 /* Offset of the response code in the UPIU header */
473 #define UPIU_RSP_CODE_OFFSET		8
474 
475 enum {
476 	MASK_SCSI_STATUS		= 0xFF,
477 	MASK_TASK_RESPONSE              = 0xFF00,
478 	MASK_RSP_UPIU_RESULT            = 0xFFFF,
479 	MASK_QUERY_DATA_SEG_LEN         = 0xFFFF,
480 	MASK_RSP_UPIU_DATA_SEG_LEN	= 0xFFFF,
481 	MASK_RSP_EXCEPTION_EVENT        = 0x10000,
482 	MASK_TM_SERVICE_RESP		= 0xFF,
483 	MASK_TM_FUNC			= 0xFF,
484 };
485 
486 /* Task management service response */
487 enum {
488 	UPIU_TASK_MANAGEMENT_FUNC_COMPL		= 0x00,
489 	UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
490 	UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED	= 0x08,
491 	UPIU_TASK_MANAGEMENT_FUNC_FAILED	= 0x05,
492 	UPIU_INCORRECT_LOGICAL_UNIT_NO		= 0x09,
493 };
494 
495 /* UFS device power modes */
496 enum ufs_dev_pwr_mode {
497 	UFS_ACTIVE_PWR_MODE	= 1,
498 	UFS_SLEEP_PWR_MODE	= 2,
499 	UFS_POWERDOWN_PWR_MODE	= 3,
500 	UFS_DEEPSLEEP_PWR_MODE	= 4,
501 };
502 
503 #define UFS_WB_BUF_REMAIN_PERCENT(val) ((val) / 10)
504 
505 /**
506  * struct utp_cmd_rsp - Response UPIU structure
507  * @residual_transfer_count: Residual transfer count DW-3
508  * @reserved: Reserved double words DW-4 to DW-7
509  * @sense_data_len: Sense data length DW-8 U16
510  * @sense_data: Sense data field DW-8 to DW-12
511  */
512 struct utp_cmd_rsp {
513 	__be32 residual_transfer_count;
514 	__be32 reserved[4];
515 	__be16 sense_data_len;
516 	u8 sense_data[UFS_SENSE_SIZE];
517 };
518 
519 struct ufshpb_active_field {
520 	__be16 active_rgn;
521 	__be16 active_srgn;
522 };
523 #define HPB_ACT_FIELD_SIZE 4
524 
525 /**
526  * struct utp_hpb_rsp - Response UPIU structure
527  * @residual_transfer_count: Residual transfer count DW-3
528  * @reserved1: Reserved double words DW-4 to DW-7
529  * @sense_data_len: Sense data length DW-8 U16
530  * @desc_type: Descriptor type of sense data
531  * @additional_len: Additional length of sense data
532  * @hpb_op: HPB operation type
533  * @lun: LUN of response UPIU
534  * @active_rgn_cnt: Active region count
535  * @inactive_rgn_cnt: Inactive region count
536  * @hpb_active_field: Recommended to read HPB region and subregion
537  * @hpb_inactive_field: To be inactivated HPB region and subregion
538  */
539 struct utp_hpb_rsp {
540 	__be32 residual_transfer_count;
541 	__be32 reserved1[4];
542 	__be16 sense_data_len;
543 	u8 desc_type;
544 	u8 additional_len;
545 	u8 hpb_op;
546 	u8 lun;
547 	u8 active_rgn_cnt;
548 	u8 inactive_rgn_cnt;
549 	struct ufshpb_active_field hpb_active_field[2];
550 	__be16 hpb_inactive_field[2];
551 };
552 #define UTP_HPB_RSP_SIZE 40
553 
554 /**
555  * struct utp_upiu_rsp - general upiu response structure
556  * @header: UPIU header structure DW-0 to DW-2
557  * @sr: fields structure for scsi command DW-3 to DW-12
558  * @qr: fields structure for query request DW-3 to DW-7
559  */
560 struct utp_upiu_rsp {
561 	struct utp_upiu_header header;
562 	union {
563 		struct utp_cmd_rsp sr;
564 		struct utp_hpb_rsp hr;
565 		struct utp_upiu_query qr;
566 	};
567 };
568 
569 /**
570  * struct ufs_query_req - parameters for building a query request
571  * @query_func: UPIU header query function
572  * @upiu_req: the query request data
573  */
574 struct ufs_query_req {
575 	u8 query_func;
576 	struct utp_upiu_query upiu_req;
577 };
578 
579 /**
580  * struct ufs_query_resp - UPIU QUERY
581  * @response: device response code
582  * @upiu_res: query response data
583  */
584 struct ufs_query_res {
585 	u8 response;
586 	struct utp_upiu_query upiu_res;
587 };
588 
589 /*
590  * VCCQ & VCCQ2 current requirement when UFS device is in sleep state
591  * and link is in Hibern8 state.
592  */
593 #define UFS_VREG_LPM_LOAD_UA	1000 /* uA */
594 
595 struct ufs_vreg {
596 	struct regulator *reg;
597 	const char *name;
598 	bool always_on;
599 	bool enabled;
600 	int max_uA;
601 };
602 
603 struct ufs_vreg_info {
604 	struct ufs_vreg *vcc;
605 	struct ufs_vreg *vccq;
606 	struct ufs_vreg *vccq2;
607 	struct ufs_vreg *vdd_hba;
608 };
609 
610 struct ufs_dev_info {
611 	bool	f_power_on_wp_en;
612 	/* Keeps information if any of the LU is power on write protected */
613 	bool	is_lu_power_on_wp;
614 	/* Maximum number of general LU supported by the UFS device */
615 	u8	max_lu_supported;
616 	u16	wmanufacturerid;
617 	/*UFS device Product Name */
618 	u8	*model;
619 	u16	wspecversion;
620 	u32	clk_gating_wait_us;
621 	/* Stores the depth of queue in UFS device */
622 	u8	bqueuedepth;
623 
624 	/* UFS HPB related flag */
625 	bool	hpb_enabled;
626 
627 	/* UFS WB related flags */
628 	bool    wb_enabled;
629 	bool    wb_buf_flush_enabled;
630 	u8	wb_dedicated_lu;
631 	u8      wb_buffer_type;
632 
633 	bool	b_rpm_dev_flush_capable;
634 	u8	b_presrv_uspc_en;
635 
636 	bool    b_advanced_rpmb_en;
637 
638 	/* UFS EXT_IID Enable */
639 	bool	b_ext_iid_en;
640 };
641 
642 /*
643  * This enum is used in string mapping in include/trace/events/ufs.h.
644  */
645 enum ufs_trace_str_t {
646 	UFS_CMD_SEND, UFS_CMD_COMP, UFS_DEV_COMP,
647 	UFS_QUERY_SEND, UFS_QUERY_COMP, UFS_QUERY_ERR,
648 	UFS_TM_SEND, UFS_TM_COMP, UFS_TM_ERR
649 };
650 
651 /*
652  * Transaction Specific Fields (TSF) type in the UPIU package, this enum is
653  * used in include/trace/events/ufs.h for UFS command trace.
654  */
655 enum ufs_trace_tsf_t {
656 	UFS_TSF_CDB, UFS_TSF_OSF, UFS_TSF_TM_INPUT, UFS_TSF_TM_OUTPUT
657 };
658 
659 #endif /* End of Header */
660