blob: 7210500905207e0b7ef343beff02a7195c6bfb23 [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 Holikatti3b1d0582013-02-25 21:44:32 +05305 * Copyright (C) 2011-2013 Samsung India Software Operations
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +05306 *
Vinayak Holikatti3b1d0582013-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 Holikatti3b1d0582013-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 Holikatti3b1d0582013-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
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053039#include <linux/mutex.h>
40#include <linux/types.h>
41
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053042#define MAX_CDB_SIZE 16
Dolev Raviv68078d52013-07-30 00:35:58 +053043#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)))
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053047
48#define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053049 cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053050 (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,
Dolev Raviv68078d52013-07-30 00:35:58 +053072 UPIU_TRANSACTION_QUERY_REQ = 0x16,
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053073};
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,
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +053083 UPIU_TRANSACTION_REJECT_UPIU = 0x3F,
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +053084};
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
Dolev Raviv68078d52013-07-30 00:35:58 +0530101/* UPIU Query request function */
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530102enum {
Dolev Raviv68078d52013-07-30 00:35:58 +0530103 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,
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530110 QUERY_FLAG_IDN_BKOPS_EN = 0x04,
111};
112
113/* Attribute idn for Query requests */
114enum 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 */
121enum {
122 MASK_EE_STATUS = 0xFFFF,
123 MASK_EE_URGENT_BKOPS = (1 << 2),
124};
125
126/* Background operation status */
127enum {
128 BKOPS_STATUS_NO_OP = 0x0,
129 BKOPS_STATUS_NON_CRITICAL = 0x1,
130 BKOPS_STATUS_PERF_IMPACT = 0x2,
131 BKOPS_STATUS_CRITICAL = 0x3,
Dolev Raviv68078d52013-07-30 00:35:58 +0530132};
133
134/* UTP QUERY Transaction Specific Fields OpCode */
135enum query_opcode {
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530136 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
Dolev Raviv68078d52013-07-30 00:35:58 +0530147/* Query response result code */
148enum {
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
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530162/* UTP Transfer Request Command Type (CT) */
163enum {
164 UPIU_COMMAND_SET_TYPE_SCSI = 0x0,
165 UPIU_COMMAND_SET_TYPE_UFS = 0x1,
166 UPIU_COMMAND_SET_TYPE_QUERY = 0x2,
167};
168
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530169/* 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
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530175enum {
Dolev Raviv68078d52013-07-30 00:35:58 +0530176 MASK_SCSI_STATUS = 0xFF,
177 MASK_TASK_RESPONSE = 0xFF00,
178 MASK_RSP_UPIU_RESULT = 0xFFFF,
179 MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
Seungwon Jeon1c2623c2013-08-31 21:40:19 +0530180 MASK_RSP_UPIU_DATA_SEG_LEN = 0xFFFF,
Sujit Reddy Thumma66ec6d52013-07-30 00:35:59 +0530181 MASK_RSP_EXCEPTION_EVENT = 0x10000,
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530182};
183
184/* Task management service response */
185enum {
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 */
198struct utp_upiu_header {
199 u32 dword_0;
200 u32 dword_1;
201 u32 dword_2;
202};
203
204/**
205 * struct utp_upiu_cmd - Command UPIU structure
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530206 * @data_transfer_len: Data Transfer Length DW-3
207 * @cdb: Command Descriptor Block CDB DW-4 to DW-7
208 */
209struct utp_upiu_cmd {
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530210 u32 exp_data_transfer_len;
211 u8 cdb[MAX_CDB_SIZE];
212};
213
214/**
Dolev Raviv68078d52013-07-30 00:35:58 +0530215 * 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 */
226struct utp_upiu_query {
227 u8 opcode;
228 u8 idn;
229 u8 index;
230 u8 selector;
231 u16 reserved_osf;
232 u16 length;
233 u32 value;
234 u32 reserved[2];
235};
236
237/**
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530238 * 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
Dolev Raviv68078d52013-07-30 00:35:58 +0530241 * @qr: fields structure for query request DW-3 to DW-7
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530242 */
243struct utp_upiu_req {
244 struct utp_upiu_header header;
Dolev Raviv68078d52013-07-30 00:35:58 +0530245 union {
246 struct utp_upiu_cmd sc;
247 struct utp_upiu_query qr;
248 };
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530249};
250
251/**
252 * struct utp_cmd_rsp - Response UPIU structure
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530253 * @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 */
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530258struct utp_cmd_rsp {
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530259 u32 residual_transfer_count;
260 u32 reserved[4];
261 u16 sense_data_len;
262 u8 sense_data[18];
263};
264
265/**
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530266 * 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
Dolev Raviv68078d52013-07-30 00:35:58 +0530269 * @qr: fields structure for query request DW-3 to DW-7
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530270 */
271struct utp_upiu_rsp {
272 struct utp_upiu_header header;
Dolev Raviv68078d52013-07-30 00:35:58 +0530273 union {
274 struct utp_cmd_rsp sr;
275 struct utp_upiu_query qr;
276 };
Sujit Reddy Thumma5a0b0cb2013-07-30 00:35:57 +0530277};
278
279/**
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530280 * 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 */
287struct utp_upiu_task_req {
288 struct utp_upiu_header header;
289 u32 input_param1;
290 u32 input_param2;
291 u32 input_param3;
292 u32 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 */
302struct utp_upiu_task_rsp {
303 struct utp_upiu_header header;
304 u32 output_param1;
305 u32 output_param2;
306 u32 reserved[3];
307};
308
Dolev Raviv68078d52013-07-30 00:35:58 +0530309/**
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 */
314struct 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 */
324struct ufs_query_res {
325 u8 response;
326 struct utp_upiu_query upiu_res;
327};
328
Santosh Yaraganavi7a3e97b2012-02-29 12:11:50 +0530329#endif /* End of Header */