Linux-libre 3.10.98-gnu
[librecmc/linux-libre.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 #define MAX_CDB_SIZE    16
40
41 #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
42                         ((byte3 << 24) | (byte2 << 16) |\
43                          (byte1 << 8) | (byte0))
44
45 /*
46  * UFS Protocol Information Unit related definitions
47  */
48
49 /* Task management functions */
50 enum {
51         UFS_ABORT_TASK          = 0x01,
52         UFS_ABORT_TASK_SET      = 0x02,
53         UFS_CLEAR_TASK_SET      = 0x04,
54         UFS_LOGICAL_RESET       = 0x08,
55         UFS_QUERY_TASK          = 0x80,
56         UFS_QUERY_TASK_SET      = 0x81,
57 };
58
59 /* UTP UPIU Transaction Codes Initiator to Target */
60 enum {
61         UPIU_TRANSACTION_NOP_OUT        = 0x00,
62         UPIU_TRANSACTION_COMMAND        = 0x01,
63         UPIU_TRANSACTION_DATA_OUT       = 0x02,
64         UPIU_TRANSACTION_TASK_REQ       = 0x04,
65         UPIU_TRANSACTION_QUERY_REQ      = 0x26,
66 };
67
68 /* UTP UPIU Transaction Codes Target to Initiator */
69 enum {
70         UPIU_TRANSACTION_NOP_IN         = 0x20,
71         UPIU_TRANSACTION_RESPONSE       = 0x21,
72         UPIU_TRANSACTION_DATA_IN        = 0x22,
73         UPIU_TRANSACTION_TASK_RSP       = 0x24,
74         UPIU_TRANSACTION_READY_XFER     = 0x31,
75         UPIU_TRANSACTION_QUERY_RSP      = 0x36,
76 };
77
78 /* UPIU Read/Write flags */
79 enum {
80         UPIU_CMD_FLAGS_NONE     = 0x00,
81         UPIU_CMD_FLAGS_WRITE    = 0x20,
82         UPIU_CMD_FLAGS_READ     = 0x40,
83 };
84
85 /* UPIU Task Attributes */
86 enum {
87         UPIU_TASK_ATTR_SIMPLE   = 0x00,
88         UPIU_TASK_ATTR_ORDERED  = 0x01,
89         UPIU_TASK_ATTR_HEADQ    = 0x02,
90         UPIU_TASK_ATTR_ACA      = 0x03,
91 };
92
93 /* UTP QUERY Transaction Specific Fields OpCode */
94 enum {
95         UPIU_QUERY_OPCODE_NOP           = 0x0,
96         UPIU_QUERY_OPCODE_READ_DESC     = 0x1,
97         UPIU_QUERY_OPCODE_WRITE_DESC    = 0x2,
98         UPIU_QUERY_OPCODE_READ_ATTR     = 0x3,
99         UPIU_QUERY_OPCODE_WRITE_ATTR    = 0x4,
100         UPIU_QUERY_OPCODE_READ_FLAG     = 0x5,
101         UPIU_QUERY_OPCODE_SET_FLAG      = 0x6,
102         UPIU_QUERY_OPCODE_CLEAR_FLAG    = 0x7,
103         UPIU_QUERY_OPCODE_TOGGLE_FLAG   = 0x8,
104 };
105
106 /* UTP Transfer Request Command Type (CT) */
107 enum {
108         UPIU_COMMAND_SET_TYPE_SCSI      = 0x0,
109         UPIU_COMMAND_SET_TYPE_UFS       = 0x1,
110         UPIU_COMMAND_SET_TYPE_QUERY     = 0x2,
111 };
112
113 enum {
114         MASK_SCSI_STATUS        = 0xFF,
115         MASK_TASK_RESPONSE      = 0xFF00,
116         MASK_RSP_UPIU_RESULT    = 0xFFFF,
117 };
118
119 /* Task management service response */
120 enum {
121         UPIU_TASK_MANAGEMENT_FUNC_COMPL         = 0x00,
122         UPIU_TASK_MANAGEMENT_FUNC_NOT_SUPPORTED = 0x04,
123         UPIU_TASK_MANAGEMENT_FUNC_SUCCEEDED     = 0x08,
124         UPIU_TASK_MANAGEMENT_FUNC_FAILED        = 0x05,
125         UPIU_INCORRECT_LOGICAL_UNIT_NO          = 0x09,
126 };
127 /**
128  * struct utp_upiu_header - UPIU header structure
129  * @dword_0: UPIU header DW-0
130  * @dword_1: UPIU header DW-1
131  * @dword_2: UPIU header DW-2
132  */
133 struct utp_upiu_header {
134         u32 dword_0;
135         u32 dword_1;
136         u32 dword_2;
137 };
138
139 /**
140  * struct utp_upiu_cmd - Command UPIU structure
141  * @header: UPIU header structure DW-0 to DW-2
142  * @data_transfer_len: Data Transfer Length DW-3
143  * @cdb: Command Descriptor Block CDB DW-4 to DW-7
144  */
145 struct utp_upiu_cmd {
146         struct utp_upiu_header header;
147         u32 exp_data_transfer_len;
148         u8 cdb[MAX_CDB_SIZE];
149 };
150
151 /**
152  * struct utp_upiu_rsp - Response UPIU structure
153  * @header: UPIU header DW-0 to DW-2
154  * @residual_transfer_count: Residual transfer count DW-3
155  * @reserved: Reserved double words DW-4 to DW-7
156  * @sense_data_len: Sense data length DW-8 U16
157  * @sense_data: Sense data field DW-8 to DW-12
158  */
159 struct utp_upiu_rsp {
160         struct utp_upiu_header header;
161         u32 residual_transfer_count;
162         u32 reserved[4];
163         u16 sense_data_len;
164         u8 sense_data[18];
165 };
166
167 /**
168  * struct utp_upiu_task_req - Task request UPIU structure
169  * @header - UPIU header structure DW0 to DW-2
170  * @input_param1: Input parameter 1 DW-3
171  * @input_param2: Input parameter 2 DW-4
172  * @input_param3: Input parameter 3 DW-5
173  * @reserved: Reserved double words DW-6 to DW-7
174  */
175 struct utp_upiu_task_req {
176         struct utp_upiu_header header;
177         u32 input_param1;
178         u32 input_param2;
179         u32 input_param3;
180         u32 reserved[2];
181 };
182
183 /**
184  * struct utp_upiu_task_rsp - Task Management Response UPIU structure
185  * @header: UPIU header structure DW0-DW-2
186  * @output_param1: Ouput parameter 1 DW3
187  * @output_param2: Output parameter 2 DW4
188  * @reserved: Reserved double words DW-5 to DW-7
189  */
190 struct utp_upiu_task_rsp {
191         struct utp_upiu_header header;
192         u32 output_param1;
193         u32 output_param2;
194         u32 reserved[3];
195 };
196
197 #endif /* End of Header */