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