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