Merge tag 'dt-for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[pandora-kernel.git] / drivers / scsi / ufs / ufs.h
1 /*
2  * Universal Flash Storage Host controller driver
3  *
4  * This code is based on drivers/scsi/ufs/ufs.h
5  * Copyright (C) 2011-2013 Samsung India Software Operations
6  *
7  * Authors:
8  *      Santosh Yaraganavi <santosh.sy@samsung.com>
9  *      Vinayak Holikatti <h.vinayak@samsung.com>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * See the COPYING file in the top-level directory or visit
16  * <http://www.gnu.org/licenses/gpl-2.0.html>
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * This program is provided "AS IS" and "WITH ALL FAULTS" and
24  * without warranty of any kind. You are solely responsible for
25  * determining the appropriateness of using and distributing
26  * the program and assume all risks associated with your exercise
27  * of rights with respect to the program, including but not limited
28  * to infringement of third party rights, the risks and costs of
29  * program errors, damage to or loss of data, programs or equipment,
30  * and unavailability or interruption of operations. Under no
31  * circumstances will the contributor of this Program be liable for
32  * any damages of any kind arising from your use or distribution of
33  * this program.
34  */
35
36 #ifndef _UFS_H
37 #define _UFS_H
38
39 #include <linux/mutex.h>
40 #include <linux/types.h>
41
42 #define MAX_CDB_SIZE    16
43 #define GENERAL_UPIU_REQUEST_SIZE 32
44 #define QUERY_DESC_MAX_SIZE       255
45 #define QUERY_DESC_MIN_SIZE       2
46 #define QUERY_OSF_SIZE            (GENERAL_UPIU_REQUEST_SIZE - \
47                                         (sizeof(struct utp_upiu_header)))
48
49 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
50                         cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
51                          (byte1 << 8) | (byte0))
52
53 /*
54  * UFS Protocol Information Unit related definitions
55  */
56
57 /* Task management functions */
58 enum {
59         UFS_ABORT_TASK          = 0x01,
60         UFS_ABORT_TASK_SET      = 0x02,
61         UFS_CLEAR_TASK_SET      = 0x04,
62         UFS_LOGICAL_RESET       = 0x08,
63         UFS_QUERY_TASK          = 0x80,
64         UFS_QUERY_TASK_SET      = 0x81,
65 };
66
67 /* UTP UPIU Transaction Codes Initiator to Target */
68 enum {
69         UPIU_TRANSACTION_NOP_OUT        = 0x00,
70         UPIU_TRANSACTION_COMMAND        = 0x01,
71         UPIU_TRANSACTION_DATA_OUT       = 0x02,
72         UPIU_TRANSACTION_TASK_REQ       = 0x04,
73         UPIU_TRANSACTION_QUERY_REQ      = 0x16,
74 };
75
76 /* UTP UPIU Transaction Codes Target to Initiator */
77 enum {
78         UPIU_TRANSACTION_NOP_IN         = 0x20,
79         UPIU_TRANSACTION_RESPONSE       = 0x21,
80         UPIU_TRANSACTION_DATA_IN        = 0x22,
81         UPIU_TRANSACTION_TASK_RSP       = 0x24,
82         UPIU_TRANSACTION_READY_XFER     = 0x31,
83         UPIU_TRANSACTION_QUERY_RSP      = 0x36,
84         UPIU_TRANSACTION_REJECT_UPIU    = 0x3F,
85 };
86
87 /* UPIU Read/Write flags */
88 enum {
89         UPIU_CMD_FLAGS_NONE     = 0x00,
90         UPIU_CMD_FLAGS_WRITE    = 0x20,
91         UPIU_CMD_FLAGS_READ     = 0x40,
92 };
93
94 /* UPIU Task Attributes */
95 enum {
96         UPIU_TASK_ATTR_SIMPLE   = 0x00,
97         UPIU_TASK_ATTR_ORDERED  = 0x01,
98         UPIU_TASK_ATTR_HEADQ    = 0x02,
99         UPIU_TASK_ATTR_ACA      = 0x03,
100 };
101
102 /* UPIU Query request function */
103 enum {
104         UPIU_QUERY_FUNC_STANDARD_READ_REQUEST           = 0x01,
105         UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST          = 0x81,
106 };
107
108 /* Flag idn for Query Requests*/
109 enum flag_idn {
110         QUERY_FLAG_IDN_FDEVICEINIT      = 0x01,
111         QUERY_FLAG_IDN_BKOPS_EN         = 0x04,
112 };
113
114 /* Attribute idn for Query requests */
115 enum attr_idn {
116         QUERY_ATTR_IDN_BKOPS_STATUS     = 0x05,
117         QUERY_ATTR_IDN_EE_CONTROL       = 0x0D,
118         QUERY_ATTR_IDN_EE_STATUS        = 0x0E,
119 };
120
121 /* Descriptor idn for Query requests */
122 enum desc_idn {
123         QUERY_DESC_IDN_DEVICE           = 0x0,
124         QUERY_DESC_IDN_CONFIGURAION     = 0x1,
125         QUERY_DESC_IDN_UNIT             = 0x2,
126         QUERY_DESC_IDN_RFU_0            = 0x3,
127         QUERY_DESC_IDN_INTERCONNECT     = 0x4,
128         QUERY_DESC_IDN_STRING           = 0x5,
129         QUERY_DESC_IDN_RFU_1            = 0x6,
130         QUERY_DESC_IDN_GEOMETRY         = 0x7,
131         QUERY_DESC_IDN_POWER            = 0x8,
132         QUERY_DESC_IDN_RFU_2            = 0x9,
133 };
134
135 #define UNIT_DESC_MAX_SIZE       0x22
136 /* Unit descriptor parameters offsets in bytes*/
137 enum unit_desc_param {
138         UNIT_DESC_PARAM_LEN                     = 0x0,
139         UNIT_DESC_PARAM_TYPE                    = 0x1,
140         UNIT_DESC_PARAM_UNIT_INDEX              = 0x2,
141         UNIT_DESC_PARAM_LU_ENABLE               = 0x3,
142         UNIT_DESC_PARAM_BOOT_LUN_ID             = 0x4,
143         UNIT_DESC_PARAM_LU_WR_PROTECT           = 0x5,
144         UNIT_DESC_PARAM_LU_Q_DEPTH              = 0x6,
145         UNIT_DESC_PARAM_MEM_TYPE                = 0x8,
146         UNIT_DESC_PARAM_DATA_RELIABILITY        = 0x9,
147         UNIT_DESC_PARAM_LOGICAL_BLK_SIZE        = 0xA,
148         UNIT_DESC_PARAM_LOGICAL_BLK_COUNT       = 0xB,
149         UNIT_DESC_PARAM_ERASE_BLK_SIZE          = 0x13,
150         UNIT_DESC_PARAM_PROVISIONING_TYPE       = 0x17,
151         UNIT_DESC_PARAM_PHY_MEM_RSRC_CNT        = 0x18,
152         UNIT_DESC_PARAM_CTX_CAPABILITIES        = 0x20,
153         UNIT_DESC_PARAM_LARGE_UNIT_SIZE_M1      = 0x22,
154 };
155
156 /* Exception event mask values */
157 enum {
158         MASK_EE_STATUS          = 0xFFFF,
159         MASK_EE_URGENT_BKOPS    = (1 << 2),
160 };
161
162 /* Background operation status */
163 enum {
164         BKOPS_STATUS_NO_OP               = 0x0,
165         BKOPS_STATUS_NON_CRITICAL        = 0x1,
166         BKOPS_STATUS_PERF_IMPACT         = 0x2,
167         BKOPS_STATUS_CRITICAL            = 0x3,
168 };
169
170 /* UTP QUERY Transaction Specific Fields OpCode */
171 enum query_opcode {
172         UPIU_QUERY_OPCODE_NOP           = 0x0,
173         UPIU_QUERY_OPCODE_READ_DESC     = 0x1,
174         UPIU_QUERY_OPCODE_WRITE_DESC    = 0x2,
175         UPIU_QUERY_OPCODE_READ_ATTR     = 0x3,
176         UPIU_QUERY_OPCODE_WRITE_ATTR    = 0x4,
177         UPIU_QUERY_OPCODE_READ_FLAG     = 0x5,
178         UPIU_QUERY_OPCODE_SET_FLAG      = 0x6,
179         UPIU_QUERY_OPCODE_CLEAR_FLAG    = 0x7,
180         UPIU_QUERY_OPCODE_TOGGLE_FLAG   = 0x8,
181 };
182
183 /* Query response result code */
184 enum {
185         QUERY_RESULT_SUCCESS                    = 0x00,
186         QUERY_RESULT_NOT_READABLE               = 0xF6,
187         QUERY_RESULT_NOT_WRITEABLE              = 0xF7,
188         QUERY_RESULT_ALREADY_WRITTEN            = 0xF8,
189         QUERY_RESULT_INVALID_LENGTH             = 0xF9,
190         QUERY_RESULT_INVALID_VALUE              = 0xFA,
191         QUERY_RESULT_INVALID_SELECTOR           = 0xFB,
192         QUERY_RESULT_INVALID_INDEX              = 0xFC,
193         QUERY_RESULT_INVALID_IDN                = 0xFD,
194         QUERY_RESULT_INVALID_OPCODE             = 0xFE,
195         QUERY_RESULT_GENERAL_FAILURE            = 0xFF,
196 };
197
198 /* UTP Transfer Request Command Type (CT) */
199 enum {
200         UPIU_COMMAND_SET_TYPE_SCSI      = 0x0,
201         UPIU_COMMAND_SET_TYPE_UFS       = 0x1,
202         UPIU_COMMAND_SET_TYPE_QUERY     = 0x2,
203 };
204
205 /* UTP Transfer Request Command Offset */
206 #define UPIU_COMMAND_TYPE_OFFSET        28
207
208 /* Offset of the response code in the UPIU header */
209 #define UPIU_RSP_CODE_OFFSET            8
210
211 enum {
212         MASK_SCSI_STATUS                = 0xFF,
213         MASK_TASK_RESPONSE              = 0xFF00,
214         MASK_RSP_UPIU_RESULT            = 0xFFFF,
215         MASK_QUERY_DATA_SEG_LEN         = 0xFFFF,
216         MASK_RSP_UPIU_DATA_SEG_LEN      = 0xFFFF,
217         MASK_RSP_EXCEPTION_EVENT        = 0x10000,
218 };
219
220 /* Task management service response */
221 enum {
222         UPIU_TASK_MANAGEMENT_FUNC_COMPL         = 0x00,
223         UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
224         UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED     = 0x08,
225         UPIU_TASK_MANAGEMENT_FUNC_FAILED        = 0x05,
226         UPIU_INCORRECT_LOGICAL_UNIT_NO          = 0x09,
227 };
228 /**
229  * struct utp_upiu_header - UPIU header structure
230  * @dword_0: UPIU header DW-0
231  * @dword_1: UPIU header DW-1
232  * @dword_2: UPIU header DW-2
233  */
234 struct utp_upiu_header {
235         __be32 dword_0;
236         __be32 dword_1;
237         __be32 dword_2;
238 };
239
240 /**
241  * struct utp_upiu_cmd - Command UPIU structure
242  * @data_transfer_len: Data Transfer Length DW-3
243  * @cdb: Command Descriptor Block CDB DW-4 to DW-7
244  */
245 struct utp_upiu_cmd {
246         __be32 exp_data_transfer_len;
247         u8 cdb[MAX_CDB_SIZE];
248 };
249
250 /**
251  * struct utp_upiu_query - upiu request buffer structure for
252  * query request.
253  * @opcode: command to perform B-0
254  * @idn: a value that indicates the particular type of data B-1
255  * @index: Index to further identify data B-2
256  * @selector: Index to further identify data B-3
257  * @reserved_osf: spec reserved field B-4,5
258  * @length: number of descriptor bytes to read/write B-6,7
259  * @value: Attribute value to be written DW-5
260  * @reserved: spec reserved DW-6,7
261  */
262 struct utp_upiu_query {
263         u8 opcode;
264         u8 idn;
265         u8 index;
266         u8 selector;
267         __be16 reserved_osf;
268         __be16 length;
269         __be32 value;
270         __be32 reserved[2];
271 };
272
273 /**
274  * struct utp_upiu_req - general upiu request structure
275  * @header:UPIU header structure DW-0 to DW-2
276  * @sc: fields structure for scsi command DW-3 to DW-7
277  * @qr: fields structure for query request DW-3 to DW-7
278  */
279 struct utp_upiu_req {
280         struct utp_upiu_header header;
281         union {
282                 struct utp_upiu_cmd sc;
283                 struct utp_upiu_query qr;
284         };
285 };
286
287 /**
288  * struct utp_cmd_rsp - Response UPIU structure
289  * @residual_transfer_count: Residual transfer count DW-3
290  * @reserved: Reserved double words DW-4 to DW-7
291  * @sense_data_len: Sense data length DW-8 U16
292  * @sense_data: Sense data field DW-8 to DW-12
293  */
294 struct utp_cmd_rsp {
295         __be32 residual_transfer_count;
296         __be32 reserved[4];
297         __be16 sense_data_len;
298         u8 sense_data[18];
299 };
300
301 /**
302  * struct utp_upiu_rsp - general upiu response structure
303  * @header: UPIU header structure DW-0 to DW-2
304  * @sr: fields structure for scsi command DW-3 to DW-12
305  * @qr: fields structure for query request DW-3 to DW-7
306  */
307 struct utp_upiu_rsp {
308         struct utp_upiu_header header;
309         union {
310                 struct utp_cmd_rsp sr;
311                 struct utp_upiu_query qr;
312         };
313 };
314
315 /**
316  * struct utp_upiu_task_req - Task request UPIU structure
317  * @header - UPIU header structure DW0 to DW-2
318  * @input_param1: Input parameter 1 DW-3
319  * @input_param2: Input parameter 2 DW-4
320  * @input_param3: Input parameter 3 DW-5
321  * @reserved: Reserved double words DW-6 to DW-7
322  */
323 struct utp_upiu_task_req {
324         struct utp_upiu_header header;
325         __be32 input_param1;
326         __be32 input_param2;
327         __be32 input_param3;
328         __be32 reserved[2];
329 };
330
331 /**
332  * struct utp_upiu_task_rsp - Task Management Response UPIU structure
333  * @header: UPIU header structure DW0-DW-2
334  * @output_param1: Ouput parameter 1 DW3
335  * @output_param2: Output parameter 2 DW4
336  * @reserved: Reserved double words DW-5 to DW-7
337  */
338 struct utp_upiu_task_rsp {
339         struct utp_upiu_header header;
340         __be32 output_param1;
341         __be32 output_param2;
342         __be32 reserved[3];
343 };
344
345 /**
346  * struct ufs_query_req - parameters for building a query request
347  * @query_func: UPIU header query function
348  * @upiu_req: the query request data
349  */
350 struct ufs_query_req {
351         u8 query_func;
352         struct utp_upiu_query upiu_req;
353 };
354
355 /**
356  * struct ufs_query_resp - UPIU QUERY
357  * @response: device response code
358  * @upiu_res: query response data
359  */
360 struct ufs_query_res {
361         u8 response;
362         struct utp_upiu_query upiu_res;
363 };
364
365 #endif /* End of Header */