blob: 086ff0363a2d1d4d15acf58b800dbbe110533225 [file] [log] [blame]
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +05301/*
2 * Universal Flash Storage Host controller driver
3 *
4 * This code is based on drivers/scsi/ufs/ufs.h
Vinayak Holikattidcfca1e2013-02-25 21:44:32 +05305 * Copyright (C) 2011-2013 Samsung India Software Operations
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +05306 *
Vinayak Holikattidcfca1e2013-02-25 21:44:32 +05307 * Authors:
8 * Santosh Yaraganavi <santosh.sy@samsung.com>
9 * Vinayak Holikatti <h.vinayak@samsung.com>
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053010 *
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.
Vinayak Holikattidcfca1e2013-02-25 21:44:32 +053015 * See the COPYING file in the top-level directory or visit
16 * <http://www.gnu.org/licenses/gpl-2.0.html>
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053017 *
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 *
Vinayak Holikattidcfca1e2013-02-25 21:44:32 +053023 * 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.
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053034 */
35
36#ifndef _UFS_H
37#define _UFS_H
38
Dolev Raviv4ad9c652013-04-25 17:27:08 +030039#include <linux/mutex.h>
40#include <linux/types.h>
41
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053042#define MAX_CDB_SIZE 16
Dolev Raviv4ad9c652013-04-25 17:27:08 +030043#define GENERAL_UPIU_REQUEST_SIZE 32
44#define UPIU_HEADER_DATA_SEGMENT_MAX_SIZE ((ALIGNED_UPIU_SIZE) - \
45 (GENERAL_UPIU_REQUEST_SIZE))
46#define QUERY_OSF_SIZE ((GENERAL_UPIU_REQUEST_SIZE) - \
47 (sizeof(struct utp_upiu_header)))
48#define UFS_QUERY_RESERVED_SCSI_CMD 0xCC
49#define UFS_QUERY_CMD_SIZE 10
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053050
51#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
Dolev Raviv4ad9c652013-04-25 17:27:08 +030052 cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053053 (byte1 << 8) | (byte0))
54
55/*
56 * UFS Protocol Information Unit related definitions
57 */
58
59/* Task management functions */
60enum {
61 UFS_ABORT_TASK = 0x01,
62 UFS_ABORT_TASK_SET = 0x02,
63 UFS_CLEAR_TASK_SET = 0x04,
64 UFS_LOGICAL_RESET = 0x08,
65 UFS_QUERY_TASK = 0x80,
66 UFS_QUERY_TASK_SET = 0x81,
67};
68
69/* UTP UPIU Transaction Codes Initiator to Target */
70enum {
71 UPIU_TRANSACTION_NOP_OUT = 0x00,
72 UPIU_TRANSACTION_COMMAND = 0x01,
73 UPIU_TRANSACTION_DATA_OUT = 0x02,
74 UPIU_TRANSACTION_TASK_REQ = 0x04,
Dolev Raviv4ad9c652013-04-25 17:27:08 +030075 UPIU_TRANSACTION_QUERY_REQ = 0x16,
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053076};
77
78/* UTP UPIU Transaction Codes Target to Initiator */
79enum {
80 UPIU_TRANSACTION_NOP_IN = 0x20,
81 UPIU_TRANSACTION_RESPONSE = 0x21,
82 UPIU_TRANSACTION_DATA_IN = 0x22,
83 UPIU_TRANSACTION_TASK_RSP = 0x24,
84 UPIU_TRANSACTION_READY_XFER = 0x31,
85 UPIU_TRANSACTION_QUERY_RSP = 0x36,
Dolev Raviv4ad9c652013-04-25 17:27:08 +030086 UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053087};
88
89/* UPIU Read/Write flags */
90enum {
91 UPIU_CMD_FLAGS_NONE = 0x00,
92 UPIU_CMD_FLAGS_WRITE = 0x20,
93 UPIU_CMD_FLAGS_READ = 0x40,
94};
95
96/* UPIU Task Attributes */
97enum {
98 UPIU_TASK_ATTR_SIMPLE = 0x00,
99 UPIU_TASK_ATTR_ORDERED = 0x01,
100 UPIU_TASK_ATTR_HEADQ = 0x02,
101 UPIU_TASK_ATTR_ACA = 0x03,
102};
103
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300104/* UPIU Query request function */
105enum {
106 UPIU_QUERY_FUNC_STANDARD_READ_REQUEST = 0x01,
107 UPIU_QUERY_FUNC_STANDARD_WRITE_REQUEST = 0x81,
108};
109
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530110/* UTP QUERY Transaction Specific Fields OpCode */
111enum {
112 UPIU_QUERY_OPCODE_NOP = 0x0,
113 UPIU_QUERY_OPCODE_READ_DESC = 0x1,
114 UPIU_QUERY_OPCODE_WRITE_DESC = 0x2,
115 UPIU_QUERY_OPCODE_READ_ATTR = 0x3,
116 UPIU_QUERY_OPCODE_WRITE_ATTR = 0x4,
117 UPIU_QUERY_OPCODE_READ_FLAG = 0x5,
118 UPIU_QUERY_OPCODE_SET_FLAG = 0x6,
119 UPIU_QUERY_OPCODE_CLEAR_FLAG = 0x7,
120 UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8,
121};
122
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300123/* Query response result code */
124enum {
125 QUERY_RESULT_SUCCESS = 0x00,
126 QUERY_RESULT_NOT_READABLE = 0xF6,
127 QUERY_RESULT_NOT_WRITEABLE = 0xF7,
128 QUERY_RESULT_ALREADY_WRITTEN = 0xF8,
129 QUERY_RESULT_INVALID_LENGTH = 0xF9,
130 QUERY_RESULT_INVALID_VALUE = 0xFA,
131 QUERY_RESULT_INVALID_SELECTOR = 0xFB,
132 QUERY_RESULT_INVALID_INDEX = 0xFC,
133 QUERY_RESULT_INVALID_IDN = 0xFD,
134 QUERY_RESULT_INVALID_OPCODE = 0xFE,
135 QUERY_RESULT_GENERAL_FAILURE = 0xFF,
136};
137
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530138/* UTP Transfer Request Command Type (CT) */
139enum {
140 UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
141 UPIU_COMMAND_SET_TYPE_UFS = 0x1,
142 UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
143};
144
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300145/* UTP Transfer Request Command Offset */
146#define UPIU_COMMAND_TYPE_OFFSET 28
147
148/* Offset of the response code in the UPIU header */
149#define UPIU_RSP_CODE_OFFSET 8
150
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530151enum {
152 MASK_SCSI_STATUS = 0xFF,
153 MASK_TASK_RESPONSE = 0xFF00,
154 MASK_RSP_UPIU_RESULT = 0xFFFF,
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300155 MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530156};
157
158/* Task management service response */
159enum {
160 UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
161 UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
162 UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
163 UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
164 UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
165};
166/**
167 * struct utp_upiu_header - UPIU header structure
168 * @dword_0: UPIU header DW-0
169 * @dword_1: UPIU header DW-1
170 * @dword_2: UPIU header DW-2
171 */
172struct utp_upiu_header {
173 u32 dword_0;
174 u32 dword_1;
175 u32 dword_2;
176};
177
178/**
179 * struct utp_upiu_cmd - Command UPIU structure
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530180 * @data_transfer_len: Data Transfer Length DW-3
181 * @cdb: Command Descriptor Block CDB DW-4 to DW-7
182 */
183struct utp_upiu_cmd {
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530184 u32 exp_data_transfer_len;
185 u8 cdb[MAX_CDB_SIZE];
186};
187
188/**
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300189 * struct utp_upiu_query - upiu request buffer structure for
190 * query request.
191 * @opcode: command to perform B-0
192 * @idn: a value that indicates the particular type of data B-1
193 * @index: Index to further identify data B-2
194 * @selector: Index to further identify data B-3
195 * @reserved_osf: spec reserved field B-4,5
196 * @length: number of descriptor bytes to read/write B-6,7
197 * @value: Attribute value to be written DW-6
198 * @reserved: spec reserved DW-7,8
199 */
200struct utp_upiu_query {
201 u8 opcode;
202 u8 idn;
203 u8 index;
204 u8 selector;
205 u16 reserved_osf;
206 u16 length;
207 u32 value;
208 u32 reserved[2];
209};
210
211/**
212 * struct utp_upiu_req - general upiu request structure
213 * @header:UPIU header structure DW-0 to DW-2
214 * @sc: fields structure for scsi command
215 * @qr: fields structure for query request
216 */
217struct utp_upiu_req {
218 struct utp_upiu_header header;
219 union {
220 struct utp_upiu_cmd sc;
221 struct utp_upiu_query qr;
222 };
223};
224
225/**
226 * struct utp_cmd_rsp - Response UPIU structure
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530227 * @residual_transfer_count: Residual transfer count DW-3
228 * @reserved: Reserved double words DW-4 to DW-7
229 * @sense_data_len: Sense data length DW-8 U16
230 * @sense_data: Sense data field DW-8 to DW-12
231 */
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300232struct utp_cmd_rsp {
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530233 u32 residual_transfer_count;
234 u32 reserved[4];
235 u16 sense_data_len;
236 u8 sense_data[18];
237};
238
239/**
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300240 * struct utp_upiu_rsp - general upiu response structure
241 * @header: UPIU header structure DW-0 to DW-2
242 * @sc: fields structure for scsi command
243 * @qr: fields structure for query request
244 */
245struct utp_upiu_rsp {
246 struct utp_upiu_header header;
247 union {
248 struct utp_cmd_rsp sc;
249 struct utp_upiu_query qr;
250 };
251};
252
253/**
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530254 * struct utp_upiu_task_req - Task request UPIU structure
255 * @header - UPIU header structure DW0 to DW-2
256 * @input_param1: Input parameter 1 DW-3
257 * @input_param2: Input parameter 2 DW-4
258 * @input_param3: Input parameter 3 DW-5
259 * @reserved: Reserved double words DW-6 to DW-7
260 */
261struct utp_upiu_task_req {
262 struct utp_upiu_header header;
263 u32 input_param1;
264 u32 input_param2;
265 u32 input_param3;
266 u32 reserved[2];
267};
268
269/**
270 * struct utp_upiu_task_rsp - Task Management Response UPIU structure
271 * @header: UPIU header structure DW0-DW-2
272 * @output_param1: Ouput parameter 1 DW3
273 * @output_param2: Output parameter 2 DW4
274 * @reserved: Reserved double words DW-5 to DW-7
275 */
276struct utp_upiu_task_rsp {
277 struct utp_upiu_header header;
278 u32 output_param1;
279 u32 output_param2;
280 u32 reserved[3];
281};
282
Dolev Raviv4ad9c652013-04-25 17:27:08 +0300283/**
284 * struct ufs_query_req - parameters for building a query request
285 * @query_func: UPIU header query function
286 * @upiu_req: the query request data
287 */
288struct ufs_query_req {
289 u8 query_func;
290 struct utp_upiu_query upiu_req;
291};
292
293/**
294 * struct ufs_query_resp - UPIU QUERY
295 * @response: device response code
296 * @upiu_res: query response data
297 */
298struct ufs_query_res {
299 u8 response;
300 struct utp_upiu_query upiu_res;
301};
302
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530303#endif /* End of Header */