isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / scsi / isci / core / sati_translator_sequence.h
1 /*
2  * This file is provided under a dual BSD/GPLv2 license.  When using or
3  * redistributing this file, you may do so under either license.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of version 2 of the GNU General Public License as
11  * published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21  * The full GNU General Public License is included in this distribution
22  * in the file called LICENSE.GPL.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
33  *   * Redistributions of source code must retain the above copyright
34  *     notice, this list of conditions and the following disclaimer.
35  *   * Redistributions in binary form must reproduce the above copyright
36  *     notice, this list of conditions and the following disclaimer in
37  *     the documentation and/or other materials provided with the
38  *     distribution.
39  *   * Neither the name of Intel Corporation nor the names of its
40  *     contributors may be used to endorse or promote products derived
41  *     from this software without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  */
55
56 #ifndef _SATI_TRANSLATOR_SEQUENCE_H_
57 #define _SATI_TRANSLATOR_SEQUENCE_H_
58
59 /**
60  * This file contains all of the defintions for the SATI translator sequence.
61  *    A translator sequence is simply a defintion for the various sequences of
62  *    commands that occur in this translator.
63  *
64  *
65  */
66
67 #include "sati_device.h"
68
69 /**
70  * enum _SATI_TRANSLATOR_SEQUENCE_TYPE - This enumeration defines the possible
71  *    sequence types for the translator.
72  *
73  *
74  */
75 enum sati_translator_sequence_type {
76         /* SCSI Primary Command (SPC) sequences. */
77         SATI_SEQUENCE_REPORT_LUNS,
78         SATI_SEQUENCE_TEST_UNIT_READY,
79         SATI_SEQUENCE_INQUIRY_STANDARD,
80         SATI_SEQUENCE_INQUIRY_SUPPORTED_PAGES,
81         SATI_SEQUENCE_INQUIRY_SERIAL_NUMBER,
82         SATI_SEQUENCE_INQUIRY_DEVICE_ID,
83         SATI_SEQUENCE_INQUIRY_BLOCK_DEVICE,
84         SATI_SEQUENCE_MODE_SENSE_6_CACHING,
85         SATI_SEQUENCE_MODE_SENSE_6_INFORMATIONAL_EXCP_CONTROL,
86         SATI_SEQUENCE_MODE_SENSE_6_READ_WRITE_ERROR,
87         SATI_SEQUENCE_MODE_SENSE_6_DISCONNECT_RECONNECT,
88         SATI_SEQUENCE_MODE_SENSE_6_CONTROL,
89         SATI_SEQUENCE_MODE_SENSE_6_ALL_PAGES,
90         SATI_SEQUENCE_MODE_SENSE_10_CACHING,
91         SATI_SEQUENCE_MODE_SENSE_10_INFORMATIONAL_EXCP_CONTROL,
92         SATI_SEQUENCE_MODE_SENSE_10_READ_WRITE_ERROR,
93         SATI_SEQUENCE_MODE_SENSE_10_DISCONNECT_RECONNECT,
94         SATI_SEQUENCE_MODE_SENSE_10_CONTROL,
95         SATI_SEQUENCE_MODE_SENSE_10_ALL_PAGES,
96         SATI_SEQUENCE_MODE_SELECT_MODE_PAGE_CACHING,
97         SATI_SEQUENCE_MODE_SELECT_MODE_POWER_CONDITION,
98         SATI_SEQUENCE_MODE_SELECT_MODE_INFORMATION_EXCEPT_CONTROL,
99
100         /* Log Sense Sequences */
101         SATI_SEQUENCE_LOG_SENSE_SELF_TEST_LOG_PAGE,
102         SATI_SEQUENCE_LOG_SENSE_EXTENDED_SELF_TEST_LOG_PAGE,
103         SATI_SEQUENCE_LOG_SENSE_SUPPORTED_LOG_PAGE,
104         SATI_SEQUENCE_LOG_SENSE_INFO_EXCEPTION_LOG_PAGE,
105
106         /* SCSI Block Command (SBC) sequences. */
107
108         SATI_SEQUENCE_READ_6,
109         SATI_SEQUENCE_READ_10,
110         SATI_SEQUENCE_READ_12,
111         SATI_SEQUENCE_READ_16,
112
113         SATI_SEQUENCE_READ_CAPACITY_10,
114         SATI_SEQUENCE_READ_CAPACITY_16,
115
116         SATI_SEQUENCE_SYNCHRONIZE_CACHE,
117
118         SATI_SEQUENCE_VERIFY_10,
119         SATI_SEQUENCE_VERIFY_12,
120         SATI_SEQUENCE_VERIFY_16,
121
122         SATI_SEQUENCE_WRITE_6,
123         SATI_SEQUENCE_WRITE_10,
124         SATI_SEQUENCE_WRITE_12,
125         SATI_SEQUENCE_WRITE_16,
126
127         SATI_SEQUENCE_START_STOP_UNIT,
128
129         SATI_SEQUENCE_REASSIGN_BLOCKS,
130
131         /* SCSI Task Requests sequences */
132
133         SATI_SEQUENCE_LUN_RESET,
134
135         SATI_SEQUENCE_REQUEST_SENSE_SMART_RETURN_STATUS,
136         SATI_SEQUENCE_REQUEST_SENSE_CHECK_POWER_MODE,
137
138         SATI_SEQUENCE_WRITE_LONG
139
140 };
141
142 #define SATI_SEQUENCE_TYPE_READ_MIN SATI_SEQUENCE_READ_6
143 #define SATI_SEQUENCE_TYPE_READ_MAX SATI_SEQUENCE_READ_16
144
145 /**
146  *
147  *
148  * SATI_SEQUENCE_STATES These constants depict the various state values
149  * associated with a translation sequence.
150  */
151 #define SATI_SEQUENCE_STATE_INITIAL        0
152 #define SATI_SEQUENCE_STATE_TRANSLATE_DATA 1
153 #define SATI_SEQUENCE_STATE_AWAIT_RESPONSE 2
154 #define SATI_SEQUENCE_STATE_FINAL          3
155 #define SATI_SEQUENCE_STATE_INCOMPLETE     4
156
157 /**
158  *
159  *
160  * SATI_DATA_DIRECTIONS These constants depict the various types of data
161  * directions for a translation sequence.  Data can flow in/out (read/write) or
162  * no data at all.
163  */
164 #define SATI_DATA_DIRECTION_NONE 0
165 #define SATI_DATA_DIRECTION_IN   1
166 #define SATI_DATA_DIRECTION_OUT  2
167
168 /**
169  * struct SATI_MODE_SELECT_PROCESSING_STATE - This structure contains all of
170  *    the current processing states for processing mode select 6 and 10
171  *    commands' parameter fields.
172  *
173  *
174  */
175 typedef  struct SATI_MODE_SELECT_PROCESSING_STATE {
176         u8 *mode_pages;
177         u32 mode_page_offset;
178         u32 mode_pages_size;
179         u32 size_of_data_processed;
180         u32 total_ata_command_sent;
181         u32 ata_command_sent_for_cmp; /* cmp: current mode page */
182         bool current_mode_page_processed;
183
184 } SATI_MODE_SELECT_PROCESSING_STATE_T;
185
186
187 enum SATI_REASSIGN_BLOCKS_ATA_COMMAND_STATUS {
188         SATI_REASSIGN_BLOCKS_READY_TO_SEND,
189         SATI_REASSIGN_BLOCKS_COMMAND_FAIL,
190         SATI_REASSIGN_BLOCKS_COMMAND_SUCCESS,
191 };
192
193 /**
194  * struct sati_reassign_blocks_processing_state - This structure contains all
195  *    of the current processing states for processing reassign block command's
196  *    parameter fields.
197  *
198  *
199  */
200 struct sati_reassign_blocks_processing_state {
201         u32 lba_offset;
202         u32 block_lists_size;
203         u8 lba_size;
204         u32 size_of_data_processed;
205         u32 ata_command_sent_for_current_lba;
206         bool current_lba_processed;
207         enum     SATI_REASSIGN_BLOCKS_ATA_COMMAND_STATUS ata_command_status;
208
209 };
210
211 #define SATI_ATAPI_REQUEST_SENSE_CDB_LENGTH 12
212
213 /**
214  * struct sati_atapi_data - The SATI_ATAPI_DATA structure is for sati atapi IO
215  *    specific data.
216  *
217  *
218  */
219 struct sati_atapi_data {
220         u8 request_sense_cdb[SATI_ATAPI_REQUEST_SENSE_CDB_LENGTH];
221 };
222
223 /**
224  * struct sati_translator_sequence - This structure contains all of the
225  *    translation information associated with a particular request.
226  *
227  *
228  */
229 struct sati_translator_sequence {
230         /**
231          * This field contains the sequence type determined by the SATI.
232          */
233         u8 type;
234
235         /**
236          * This field indicates the current state for the sequence.
237          */
238         u8 state;
239
240         /**
241          * This field indicates the data direction (none, read, or write) for
242          * the translated request.
243          */
244         u8 data_direction;
245
246         /**
247          * This field contains the SATA/ATA protocol to be utilized during
248          * the IO transfer.
249          */
250         u8 protocol;
251
252         /**
253          * This field is utilized for sequences requiring data translation.
254          * It specifies the amount of data requested by the caller from the
255          * operation.  It's necessary, because at times the user requests less
256          * data than is available.  Thus, we need to avoid overrunning the
257          * buffer.
258          */
259         u32 allocation_length;
260
261         /**
262          * This field specifies the amount of data that will actually be
263          * transfered across the wire for this ATA request.
264          */
265         u32 ata_transfer_length;
266
267         /**
268          * This field specifies the amount of data bytes that have been
269          * set in a translation sequence. It will be incremented every time
270          * a data byte has been set by a sati translation.
271          */
272         u16 number_data_bytes_set;
273
274         /**
275          * This field indicates whether or not the sense response has been set
276          * by the translation sequence.
277          */
278         bool is_sense_response_set;
279
280         /**
281          * This field specifies the remote device context for which this
282          * translator sequence is destined.
283          */
284         struct sati_device *device;
285
286         /**
287          * This field is utilized to provide the translator with memory space
288          * required for translations that utilize multiple requests.
289          */
290         union {
291                 u32 translated_command;
292                 u32 move_sector_count;
293                 u32 scratch;
294                 struct sati_reassign_blocks_processing_state reassign_blocks_process_state;
295                 SATI_MODE_SELECT_PROCESSING_STATE_T process_state;
296                 struct sati_atapi_data sati_atapi_data;
297         } command_specific_data;
298
299 };
300
301
302
303 #endif /* _SATI_TRANSLATOR_SEQUENCE_H_ */
304