]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/scsi/ufs/ufs.h
Merge tag 'dm-3.12-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device...
[mirror_ubuntu-artful-kernel.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,
66ec6d59
SRT
110 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,
68078d5c
DR
132};
133
134/* UTP QUERY Transaction Specific Fields OpCode */
135enum query_opcode {
7a3e97b0
SY
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
68078d5c
DR
147/* 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
7a3e97b0
SY
162/* 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
5a0b0cb9
SRT
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
7a3e97b0 175enum {
68078d5c
DR
176 MASK_SCSI_STATUS = 0xFF,
177 MASK_TASK_RESPONSE = 0xFF00,
178 MASK_RSP_UPIU_RESULT = 0xFFFF,
179 MASK_QUERY_DATA_SEG_LEN = 0xFFFF,
66ec6d59 180 MASK_RSP_EXCEPTION_EVENT = 0x10000,
7a3e97b0
SY
181};
182
183/* Task management service response */
184enum {
185 UPIU_TASK_MANAGEMENT_FUNC_COMPL = 0x00,
186 UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
187 UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED = 0x08,
188 UPIU_TASK_MANAGEMENT_FUNC_FAILED = 0x05,
189 UPIU_INCORRECT_LOGICAL_UNIT_NO = 0x09,
190};
191/**
192 * struct utp_upiu_header - UPIU header structure
193 * @dword_0: UPIU header DW-0
194 * @dword_1: UPIU header DW-1
195 * @dword_2: UPIU header DW-2
196 */
197struct utp_upiu_header {
198 u32 dword_0;
199 u32 dword_1;
200 u32 dword_2;
201};
202
203/**
204 * struct utp_upiu_cmd - Command UPIU structure
7a3e97b0
SY
205 * @data_transfer_len: Data Transfer Length DW-3
206 * @cdb: Command Descriptor Block CDB DW-4 to DW-7
207 */
208struct utp_upiu_cmd {
7a3e97b0
SY
209 u32 exp_data_transfer_len;
210 u8 cdb[MAX_CDB_SIZE];
211};
212
68078d5c
DR
213/**
214 * struct utp_upiu_query - upiu request buffer structure for
215 * query request.
216 * @opcode: command to perform B-0
217 * @idn: a value that indicates the particular type of data B-1
218 * @index: Index to further identify data B-2
219 * @selector: Index to further identify data B-3
220 * @reserved_osf: spec reserved field B-4,5
221 * @length: number of descriptor bytes to read/write B-6,7
222 * @value: Attribute value to be written DW-5
223 * @reserved: spec reserved DW-6,7
224 */
225struct utp_upiu_query {
226 u8 opcode;
227 u8 idn;
228 u8 index;
229 u8 selector;
230 u16 reserved_osf;
231 u16 length;
232 u32 value;
233 u32 reserved[2];
234};
235
7a3e97b0 236/**
5a0b0cb9
SRT
237 * struct utp_upiu_req - general upiu request structure
238 * @header:UPIU header structure DW-0 to DW-2
239 * @sc: fields structure for scsi command DW-3 to DW-7
68078d5c 240 * @qr: fields structure for query request DW-3 to DW-7
5a0b0cb9
SRT
241 */
242struct utp_upiu_req {
243 struct utp_upiu_header header;
68078d5c
DR
244 union {
245 struct utp_upiu_cmd sc;
246 struct utp_upiu_query qr;
247 };
5a0b0cb9
SRT
248};
249
250/**
251 * struct utp_cmd_rsp - Response UPIU structure
7a3e97b0
SY
252 * @residual_transfer_count: Residual transfer count DW-3
253 * @reserved: Reserved double words DW-4 to DW-7
254 * @sense_data_len: Sense data length DW-8 U16
255 * @sense_data: Sense data field DW-8 to DW-12
256 */
5a0b0cb9 257struct utp_cmd_rsp {
7a3e97b0
SY
258 u32 residual_transfer_count;
259 u32 reserved[4];
260 u16 sense_data_len;
261 u8 sense_data[18];
262};
263
5a0b0cb9
SRT
264/**
265 * struct utp_upiu_rsp - general upiu response structure
266 * @header: UPIU header structure DW-0 to DW-2
267 * @sr: fields structure for scsi command DW-3 to DW-12
68078d5c 268 * @qr: fields structure for query request DW-3 to DW-7
5a0b0cb9
SRT
269 */
270struct utp_upiu_rsp {
271 struct utp_upiu_header header;
68078d5c
DR
272 union {
273 struct utp_cmd_rsp sr;
274 struct utp_upiu_query qr;
275 };
5a0b0cb9
SRT
276};
277
7a3e97b0
SY
278/**
279 * struct utp_upiu_task_req - Task request UPIU structure
280 * @header - UPIU header structure DW0 to DW-2
281 * @input_param1: Input parameter 1 DW-3
282 * @input_param2: Input parameter 2 DW-4
283 * @input_param3: Input parameter 3 DW-5
284 * @reserved: Reserved double words DW-6 to DW-7
285 */
286struct utp_upiu_task_req {
287 struct utp_upiu_header header;
288 u32 input_param1;
289 u32 input_param2;
290 u32 input_param3;
291 u32 reserved[2];
292};
293
294/**
295 * struct utp_upiu_task_rsp - Task Management Response UPIU structure
296 * @header: UPIU header structure DW0-DW-2
297 * @output_param1: Ouput parameter 1 DW3
298 * @output_param2: Output parameter 2 DW4
299 * @reserved: Reserved double words DW-5 to DW-7
300 */
301struct utp_upiu_task_rsp {
302 struct utp_upiu_header header;
303 u32 output_param1;
304 u32 output_param2;
305 u32 reserved[3];
306};
307
68078d5c
DR
308/**
309 * struct ufs_query_req - parameters for building a query request
310 * @query_func: UPIU header query function
311 * @upiu_req: the query request data
312 */
313struct ufs_query_req {
314 u8 query_func;
315 struct utp_upiu_query upiu_req;
316};
317
318/**
319 * struct ufs_query_resp - UPIU QUERY
320 * @response: device response code
321 * @upiu_res: query response data
322 */
323struct ufs_query_res {
324 u8 response;
325 struct utp_upiu_query upiu_res;
326};
327
7a3e97b0 328#endif /* End of Header */