scsi: fix u14-34f printk format warnings
[firefly-linux-kernel-4.4.55.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       256
45 #define QUERY_OSF_SIZE            (GENERAL_UPIU_REQUEST_SIZE - \
46                                         (sizeof(struct utp_upiu_header)))
47
48 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
49                         cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
50                          (byte1 << 8) | (byte0))
51
52 /*
53  * UFS Protocol Information Unit related definitions
54  */
55
56 /* Task management functions */
57 enum {
58         UFS_ABORT_TASK          = 0x01,
59         UFS_ABORT_TASK_SET      = 0x02,
60         UFS_CLEAR_TASK_SET      = 0x04,
61         UFS_LOGICAL_RESET       = 0x08,
62         UFS_QUERY_TASK          = 0x80,
63         UFS_QUERY_TASK_SET      = 0x81,
64 };
65
66 /* UTP UPIU Transaction Codes Initiator to Target */
67 enum {
68         UPIU_TRANSACTION_NOP_OUT        = 0x00,
69         UPIU_TRANSACTION_COMMAND        = 0x01,
70         UPIU_TRANSACTION_DATA_OUT       = 0x02,
71         UPIU_TRANSACTION_TASK_REQ       = 0x04,
72         UPIU_TRANSACTION_QUERY_REQ      = 0x16,
73 };
74
75 /* UTP UPIU Transaction Codes Target to Initiator */
76 enum {
77         UPIU_TRANSACTION_NOP_IN         = 0x20,
78         UPIU_TRANSACTION_RESPONSE       = 0x21,
79         UPIU_TRANSACTION_DATA_IN        = 0x22,
80         UPIU_TRANSACTION_TASK_RSP       = 0x24,
81         UPIU_TRANSACTION_READY_XFER     = 0x31,
82         UPIU_TRANSACTION_QUERY_RSP      = 0x36,
83         UPIU_TRANSACTION_REJECT_UPIU    = 0x3F,
84 };
85
86 /* UPIU Read/Write flags */
87 enum {
88         UPIU_CMD_FLAGS_NONE     = 0x00,
89         UPIU_CMD_FLAGS_WRITE    = 0x20,
90         UPIU_CMD_FLAGS_READ     = 0x40,
91 };
92
93 /* UPIU Task Attributes */
94 enum {
95         UPIU_TASK_ATTR_SIMPLE   = 0x00,
96         UPIU_TASK_ATTR_ORDERED  = 0x01,
97         UPIU_TASK_ATTR_HEADQ    = 0x02,
98         UPIU_TASK_ATTR_ACA      = 0x03,
99 };
100
101 /* UPIU Query request function */
102 enum {
103         UPIU_QUERY_FUNC_STANDARD_READ_REQUEST           = 0x01,
104         UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST          = 0x81,
105 };
106
107 /* Flag idn for Query Requests*/
108 enum flag_idn {
109         QUERY_FLAG_IDN_FDEVICEINIT      = 0x01,
110         QUERY_FLAG_IDN_BKOPS_EN         = 0x04,
111 };
112
113 /* Attribute idn for Query requests */
114 enum attr_idn {
115         QUERY_ATTR_IDN_BKOPS_STATUS     = 0x05,
116         QUERY_ATTR_IDN_EE_CONTROL       = 0x0D,
117         QUERY_ATTR_IDN_EE_STATUS        = 0x0E,
118 };
119
120 /* Exception event mask values */
121 enum {
122         MASK_EE_STATUS          = 0xFFFF,
123         MASK_EE_URGENT_BKOPS    = (1 << 2),
124 };
125
126 /* Background operation status */
127 enum {
128         BKOPS_STATUS_NO_OP               = 0x0,
129         BKOPS_STATUS_NON_CRITICAL        = 0x1,
130         BKOPS_STATUS_PERF_IMPACT         = 0x2,
131         BKOPS_STATUS_CRITICAL            = 0x3,
132 };
133
134 /* UTP QUERY Transaction Specific Fields OpCode */
135 enum query_opcode {
136         UPIU_QUERY_OPCODE_NOP           = 0x0,
137         UPIU_QUERY_OPCODE_READ_DESC     = 0x1,
138         UPIU_QUERY_OPCODE_WRITE_DESC    = 0x2,
139         UPIU_QUERY_OPCODE_READ_ATTR     = 0x3,
140         UPIU_QUERY_OPCODE_WRITE_ATTR    = 0x4,
141         UPIU_QUERY_OPCODE_READ_FLAG     = 0x5,
142         UPIU_QUERY_OPCODE_SET_FLAG      = 0x6,
143         UPIU_QUERY_OPCODE_CLEAR_FLAG    = 0x7,
144         UPIU_QUERY_OPCODE_TOGGLE_FLAG   = 0x8,
145 };
146
147 /* Query response result code */
148 enum {
149         QUERY_RESULT_SUCCESS                    = 0x00,
150         QUERY_RESULT_NOT_READABLE               = 0xF6,
151         QUERY_RESULT_NOT_WRITEABLE              = 0xF7,
152         QUERY_RESULT_ALREADY_WRITTEN            = 0xF8,
153         QUERY_RESULT_INVALID_LENGTH             = 0xF9,
154         QUERY_RESULT_INVALID_VALUE              = 0xFA,
155         QUERY_RESULT_INVALID_SELECTOR           = 0xFB,
156         QUERY_RESULT_INVALID_INDEX              = 0xFC,
157         QUERY_RESULT_INVALID_IDN                = 0xFD,
158         QUERY_RESULT_INVALID_OPCODE             = 0xFE,
159         QUERY_RESULT_GENERAL_FAILURE            = 0xFF,
160 };
161
162 /* UTP Transfer Request Command Type (CT) */
163 enum {
164         UPIU_COMMAND_SET_TYPE_SCSI      = 0x0,
165         UPIU_COMMAND_SET_TYPE_UFS       = 0x1,
166         UPIU_COMMAND_SET_TYPE_QUERY     = 0x2,
167 };
168
169 /* UTP Transfer Request Command Offset */
170 #define UPIU_COMMAND_TYPE_OFFSET        28
171
172 /* Offset of the response code in the UPIU header */
173 #define UPIU_RSP_CODE_OFFSET            8
174
175 enum {
176         MASK_SCSI_STATUS                = 0xFF,
177         MASK_TASK_RESPONSE              = 0xFF00,
178         MASK_RSP_UPIU_RESULT            = 0xFFFF,
179         MASK_QUERY_DATA_SEG_LEN         = 0xFFFF,
180         MASK_RSP_UPIU_DATA_SEG_LEN      = 0xFFFF,
181         MASK_RSP_EXCEPTION_EVENT        = 0x10000,
182 };
183
184 /* Task management service response */
185 enum {
186         UPIU_TASK_MANAGEMENT_FUNC_COMPL         = 0x00,
187         UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
188         UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED     = 0x08,
189         UPIU_TASK_MANAGEMENT_FUNC_FAILED        = 0x05,
190         UPIU_INCORRECT_LOGICAL_UNIT_NO          = 0x09,
191 };
192 /**
193  * struct utp_upiu_header - UPIU header structure
194  * @dword_0: UPIU header DW-0
195  * @dword_1: UPIU header DW-1
196  * @dword_2: UPIU header DW-2
197  */
198 struct utp_upiu_header {
199         __be32 dword_0;
200         __be32 dword_1;
201         __be32 dword_2;
202 };
203
204 /**
205  * struct utp_upiu_cmd - Command UPIU structure
206  * @data_transfer_len: Data Transfer Length DW-3
207  * @cdb: Command Descriptor Block CDB DW-4 to DW-7
208  */
209 struct utp_upiu_cmd {
210         __be32 exp_data_transfer_len;
211         u8 cdb[MAX_CDB_SIZE];
212 };
213
214 /**
215  * struct utp_upiu_query - upiu request buffer structure for
216  * query request.
217  * @opcode: command to perform B-0
218  * @idn: a value that indicates the particular type of data B-1
219  * @index: Index to further identify data B-2
220  * @selector: Index to further identify data B-3
221  * @reserved_osf: spec reserved field B-4,5
222  * @length: number of descriptor bytes to read/write B-6,7
223  * @value: Attribute value to be written DW-5
224  * @reserved: spec reserved DW-6,7
225  */
226 struct utp_upiu_query {
227         u8 opcode;
228         u8 idn;
229         u8 index;
230         u8 selector;
231         __be16 reserved_osf;
232         __be16 length;
233         __be32 value;
234         __be32 reserved[2];
235 };
236
237 /**
238  * struct utp_upiu_req - general upiu request structure
239  * @header:UPIU header structure DW-0 to DW-2
240  * @sc: fields structure for scsi command DW-3 to DW-7
241  * @qr: fields structure for query request DW-3 to DW-7
242  */
243 struct utp_upiu_req {
244         struct utp_upiu_header header;
245         union {
246                 struct utp_upiu_cmd sc;
247                 struct utp_upiu_query qr;
248         };
249 };
250
251 /**
252  * struct utp_cmd_rsp - Response UPIU structure
253  * @residual_transfer_count: Residual transfer count DW-3
254  * @reserved: Reserved double words DW-4 to DW-7
255  * @sense_data_len: Sense data length DW-8 U16
256  * @sense_data: Sense data field DW-8 to DW-12
257  */
258 struct utp_cmd_rsp {
259         __be32 residual_transfer_count;
260         __be32 reserved[4];
261         __be16 sense_data_len;
262         u8 sense_data[18];
263 };
264
265 /**
266  * struct utp_upiu_rsp - general upiu response structure
267  * @header: UPIU header structure DW-0 to DW-2
268  * @sr: fields structure for scsi command DW-3 to DW-12
269  * @qr: fields structure for query request DW-3 to DW-7
270  */
271 struct utp_upiu_rsp {
272         struct utp_upiu_header header;
273         union {
274                 struct utp_cmd_rsp sr;
275                 struct utp_upiu_query qr;
276         };
277 };
278
279 /**
280  * struct utp_upiu_task_req - Task request UPIU structure
281  * @header - UPIU header structure DW0 to DW-2
282  * @input_param1: Input parameter 1 DW-3
283  * @input_param2: Input parameter 2 DW-4
284  * @input_param3: Input parameter 3 DW-5
285  * @reserved: Reserved double words DW-6 to DW-7
286  */
287 struct utp_upiu_task_req {
288         struct utp_upiu_header header;
289         __be32 input_param1;
290         __be32 input_param2;
291         __be32 input_param3;
292         __be32 reserved[2];
293 };
294
295 /**
296  * struct utp_upiu_task_rsp - Task Management Response UPIU structure
297  * @header: UPIU header structure DW0-DW-2
298  * @output_param1: Ouput parameter 1 DW3
299  * @output_param2: Output parameter 2 DW4
300  * @reserved: Reserved double words DW-5 to DW-7
301  */
302 struct utp_upiu_task_rsp {
303         struct utp_upiu_header header;
304         __be32 output_param1;
305         __be32 output_param2;
306         __be32 reserved[3];
307 };
308
309 /**
310  * struct ufs_query_req - parameters for building a query request
311  * @query_func: UPIU header query function
312  * @upiu_req: the query request data
313  */
314 struct ufs_query_req {
315         u8 query_func;
316         struct utp_upiu_query upiu_req;
317 };
318
319 /**
320  * struct ufs_query_resp - UPIU QUERY
321  * @response: device response code
322  * @upiu_res: query response data
323  */
324 struct ufs_query_res {
325         u8 response;
326         struct utp_upiu_query upiu_res;
327 };
328
329 #endif /* End of Header */