[SCSI] ufs: Set fDeviceInit flag to initiate device initialization
[linux-block.git] / drivers / scsi / ufs / ufs.h
CommitLineData
7a3e97b0
SY
1/*
2 * Universal Flash Storage Host controller driver
3 *
4 * This code is based on drivers/scsi/ufs/ufs.h
3b1d0580 5 * Copyright (C) 2011-2013 Samsung India Software Operations
7a3e97b0 6 *
3b1d0580
VH
7 * Authors:
8 * Santosh Yaraganavi <santosh.sy@samsung.com>
9 * Vinayak Holikatti <h.vinayak@samsung.com>
7a3e97b0
SY
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.
3b1d0580
VH
15 * See the COPYING file in the top-level directory or visit
16 * <http://www.gnu.org/licenses/gpl-2.0.html>
7a3e97b0
SY
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 *
3b1d0580
VH
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.
7a3e97b0
SY
34 */
35
36#ifndef _UFS_H
37#define _UFS_H
38
5a0b0cb9
SRT
39#include <linux/mutex.h>
40#include <linux/types.h>
41
7a3e97b0 42#define MAX_CDB_SIZE 16
68078d5c
DR
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)))
7a3e97b0
SY
47
48#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
5a0b0cb9 49 cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
7a3e97b0
SY
50 (byte1 << 8) | (byte0))
51
52/*
53 * UFS Protocol Information Unit related definitions
54 */
55
56/* Task management functions */
57enum {
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 */
67enum {
68 UPIU_TRANSACTION_NOP_OUT = 0x00,
69 UPIU_TRANSACTION_COMMAND = 0x01,
70 UPIU_TRANSACTION_DATA_OUT = 0x02,
71 UPIU_TRANSACTION_TASK_REQ = 0x04,
68078d5c 72 UPIU_TRANSACTION_QUERY_REQ = 0x16,
7a3e97b0
SY
73};
74
75/* UTP UPIU Transaction Codes Target to Initiator */
76enum {
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,
5a0b0cb9 83 UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
7a3e97b0
SY
84};
85
86/* UPIU Read/Write flags */
87enum {
88 UPIU_CMD_FLAGS_NONE = 0x00,
89 UPIU_CMD_FLAGS_WRITE = 0x20,
90 UPIU_CMD_FLAGS_READ = 0x40,
91};
92
93/* UPIU Task Attributes */
94enum {
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
68078d5c 101/* UPIU Query request function */
7a3e97b0 102enum {
68078d5c
DR
103 UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01,
104 UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81,
105};
106
107/* Flag idn for Query Requests*/
108enum flag_idn {
109 QUERY_FLAG_IDN_FDEVICEINIT = 0x01,
110};
111
112/* UTP QUERY Transaction Specific Fields OpCode */
113enum query_opcode {
7a3e97b0
SY
114 UPIU_QUERY_OPCODE_NOP = 0x0,
115 UPIU_QUERY_OPCODE_READ_DESC = 0x1,
116 UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
117 UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
118 UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
119 UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
120 UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
121 UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
122 UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
123};
124
68078d5c
DR
125/* Query response result code */
126enum {
127 QUERY_RESULT_SUCCESS = 0x00,
128 QUERY_RESULT_NOT_READABLE = 0xF6,
129 QUERY_RESULT_NOT_WRITEABLE = 0xF7,
130 QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
131 QUERY_RESULT_INVALID_LENGTH = 0xF9,
132 QUERY_RESULT_INVALID_VALUE = 0xFA,
133 QUERY_RESULT_INVALID_SELECTOR = 0xFB,
134 QUERY_RESULT_INVALID_INDEX = 0xFC,
135 QUERY_RESULT_INVALID_IDN = 0xFD,
136 QUERY_RESULT_INVALID_OPCODE = 0xFE,
137 QUERY_RESULT_GENERAL_FAILURE = 0xFF,
138};
139
7a3e97b0
SY
140/* UTP Transfer Request Command Type (CT) */
141enum {
142 UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
143 UPIU_COMMAND_SET_TYPE_UFS = 0x1,
144 UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
145};
146
5a0b0cb9
SRT
147/* UTP Transfer Request Command Offset */
148#define UPIU_COMMAND_TYPE_OFFSET 28
149
150/* Offset of the response code in the UPIU header */
151#define UPIU_RSP_CODE_OFFSET 8
152
7a3e97b0 153enum {
68078d5c
DR
154 MASK_SCSI_STATUS = 0xFF,
155 MASK_TASK_RESPONSE = 0xFF00,
156 MASK_RSP_UPIU_RESULT = 0xFFFF,
157 MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
7a3e97b0
SY
158};
159
160/* Task management service response */
161enum {
162 UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
163 UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
164 UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
165 UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
166 UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
167};
168/**
169 * struct utp_upiu_header - UPIU header structure
170 * @dword_0: UPIU header DW-0
171 * @dword_1: UPIU header DW-1
172 * @dword_2: UPIU header DW-2
173 */
174struct utp_upiu_header {
175 u32 dword_0;
176 u32 dword_1;
177 u32 dword_2;
178};
179
180/**
181 * struct utp_upiu_cmd - Command UPIU structure
7a3e97b0
SY
182 * @data_transfer_len: Data Transfer Length DW-3
183 * @cdb: Command Descriptor Block CDB DW-4 to DW-7
184 */
185struct utp_upiu_cmd {
7a3e97b0
SY
186 u32 exp_data_transfer_len;
187 u8 cdb[MAX_CDB_SIZE];
188};
189
68078d5c
DR
190/**
191 * struct utp_upiu_query - upiu request buffer structure for
192 * query request.
193 * @opcode: command to perform B-0
194 * @idn: a value that indicates the particular type of data B-1
195 * @index: Index to further identify data B-2
196 * @selector: Index to further identify data B-3
197 * @reserved_osf: spec reserved field B-4,5
198 * @length: number of descriptor bytes to read/write B-6,7
199 * @value: Attribute value to be written DW-5
200 * @reserved: spec reserved DW-6,7
201 */
202struct utp_upiu_query {
203 u8 opcode;
204 u8 idn;
205 u8 index;
206 u8 selector;
207 u16 reserved_osf;
208 u16 length;
209 u32 value;
210 u32 reserved[2];
211};
212
7a3e97b0 213/**
5a0b0cb9
SRT
214 * struct utp_upiu_req - general upiu request structure
215 * @header:UPIU header structure DW-0 to DW-2
216 * @sc: fields structure for scsi command DW-3 to DW-7
68078d5c 217 * @qr: fields structure for query request DW-3 to DW-7
5a0b0cb9
SRT
218 */
219struct utp_upiu_req {
220 struct utp_upiu_header header;
68078d5c
DR
221 union {
222 struct utp_upiu_cmd sc;
223 struct utp_upiu_query qr;
224 };
5a0b0cb9
SRT
225};
226
227/**
228 * struct utp_cmd_rsp - Response UPIU structure
7a3e97b0
SY
229 * @residual_transfer_count: Residual transfer count DW-3
230 * @reserved: Reserved double words DW-4 to DW-7
231 * @sense_data_len: Sense data length DW-8 U16
232 * @sense_data: Sense data field DW-8 to DW-12
233 */
5a0b0cb9 234struct utp_cmd_rsp {
7a3e97b0
SY
235 u32 residual_transfer_count;
236 u32 reserved[4];
237 u16 sense_data_len;
238 u8 sense_data[18];
239};
240
5a0b0cb9
SRT
241/**
242 * struct utp_upiu_rsp - general upiu response structure
243 * @header: UPIU header structure DW-0 to DW-2
244 * @sr: fields structure for scsi command DW-3 to DW-12
68078d5c 245 * @qr: fields structure for query request DW-3 to DW-7
5a0b0cb9
SRT
246 */
247struct utp_upiu_rsp {
248 struct utp_upiu_header header;
68078d5c
DR
249 union {
250 struct utp_cmd_rsp sr;
251 struct utp_upiu_query qr;
252 };
5a0b0cb9
SRT
253};
254
7a3e97b0
SY
255/**
256 * struct utp_upiu_task_req - Task request UPIU structure
257 * @header - UPIU header structure DW0 to DW-2
258 * @input_param1: Input parameter 1 DW-3
259 * @input_param2: Input parameter 2 DW-4
260 * @input_param3: Input parameter 3 DW-5
261 * @reserved: Reserved double words DW-6 to DW-7
262 */
263struct utp_upiu_task_req {
264 struct utp_upiu_header header;
265 u32 input_param1;
266 u32 input_param2;
267 u32 input_param3;
268 u32 reserved[2];
269};
270
271/**
272 * struct utp_upiu_task_rsp - Task Management Response UPIU structure
273 * @header: UPIU header structure DW0-DW-2
274 * @output_param1: Ouput parameter 1 DW3
275 * @output_param2: Output parameter 2 DW4
276 * @reserved: Reserved double words DW-5 to DW-7
277 */
278struct utp_upiu_task_rsp {
279 struct utp_upiu_header header;
280 u32 output_param1;
281 u32 output_param2;
282 u32 reserved[3];
283};
284
68078d5c
DR
285/**
286 * struct ufs_query_req - parameters for building a query request
287 * @query_func: UPIU header query function
288 * @upiu_req: the query request data
289 */
290struct ufs_query_req {
291 u8 query_func;
292 struct utp_upiu_query upiu_req;
293};
294
295/**
296 * struct ufs_query_resp - UPIU QUERY
297 * @response: device response code
298 * @upiu_res: query response data
299 */
300struct ufs_query_res {
301 u8 response;
302 struct utp_upiu_query upiu_res;
303};
304
7a3e97b0 305#endif /* End of Header */