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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 * @brief This file contains all of the interface methods, macros, structures
60 * that provide general support for SATI. Some methods can be utilized
61 * by a user to construct ATA/ATAPI commands, copy ATA device
62 * structure data, fill in sense data, etc.
65 #include <dev/isci/scil/sati_types.h>
66 #include <dev/isci/scil/sati_translator_sequence.h>
68 #include <dev/isci/scil/intel_sata.h>
69 #include <dev/isci/scil/intel_sas.h>
72 * This macro allows the translator to be able to handle environments where
73 * the contents of the CDB are of a different endian nature of byte swapped
76 #define sati_get_cdb_byte(the_cdb, index) (the_cdb)[(index)]
78 #define sati_get_ata_status(the_reg_fis) ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->status
79 #define sati_get_ata_error(the_reg_fis) ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->error
81 #define sati_get_ata_command(the_reg_fis) \
82 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command
84 #define sati_get_ata_sector_count(the_reg_fis) \
85 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count
86 #define sati_get_ata_sector_count_exp(the_reg_fis) \
87 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count_exp
88 #define sati_get_ata_lba_low(the_reg_fis) \
89 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_low
90 #define sati_get_ata_lba_mid(the_reg_fis) \
91 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_mid
92 #define sati_get_ata_lba_high(the_reg_fis) \
93 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_high
94 #define sati_get_ata_sector_count_ext(the_reg_fis) \
95 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count_exp
96 #define sati_get_ata_lba_low_ext(the_reg_fis) \
97 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_low_exp
98 #define sati_get_ata_lba_mid_ext(the_reg_fis) \
99 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_mid_exp
100 #define sati_get_ata_lba_high_ext(the_reg_fis) \
101 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_high_exp
102 #define sati_get_ata_device(the_reg_fis) \
103 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->device
105 #define sati_set_ata_status(the_reg_fis, value) \
106 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->status = (value)
107 #define sati_set_sata_fis_type(the_reg_fis, value) \
108 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->fis_type = (value)
109 #define sati_set_sata_command_flag(the_reg_fis) \
110 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command_flag = 1
111 #define sati_clear_sata_command_flag(the_reg_fis) \
112 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command_flag = 0
114 #define sati_set_ata_command(the_reg_fis, value) \
115 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command = (value)
116 #define sati_set_ata_features(the_reg_fis, value) \
117 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->features = (value)
118 #define sati_set_ata_features_exp(the_reg_fis, value) \
119 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->features_exp = (value)
120 #define sati_set_ata_control(the_reg_fis, value) \
121 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->control = (value)
122 #define sati_set_ata_sector_count(the_reg_fis, value) \
123 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->sector_count = (value)
124 #define sati_set_ata_sector_count_exp(the_reg_fis, value) \
125 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->sector_count_exp = (value)
126 #define sati_set_ata_lba_low(the_reg_fis, value) \
127 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_low = (value)
128 #define sati_set_ata_lba_mid(the_reg_fis, value) \
129 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_mid = (value)
130 #define sati_set_ata_lba_high(the_reg_fis, value) \
131 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_high = (value)
132 #define sati_set_ata_lba_low_exp(the_reg_fis, value) \
133 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_low_exp = (value)
134 #define sati_set_ata_lba_mid_exp(the_reg_fis, value) \
135 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_mid_exp = (value)
136 #define sati_set_ata_lba_high_exp(the_reg_fis, value) \
137 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_high_exp = (value)
138 #define sati_set_ata_device_head(the_reg_fis, value) \
139 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->device = (value)
141 #define ATA_MID_REGISTER_THRESHOLD_EXCEEDED 0xF4
142 #define ATA_HIGH_REGISTER_THRESHOLD_EXCEEDED 0x2C
144 #define ATA_MICROCODE_OFFSET_DOWNLOAD 0x03
145 #define ATA_MICROCODE_DOWNLOAD_SAVE 0x07
148 #define MIN(x,y) ((x) < (y) ? (x) : (y))
152 #define MAX(x,y) ((x) > (y) ? (x) : (y))
156 void sati_ata_non_data_command(
158 SATI_TRANSLATOR_SEQUENCE_T * sequence
161 void sati_ata_identify_device_construct(
163 SATI_TRANSLATOR_SEQUENCE_T * sequence
166 void sati_ata_execute_device_diagnostic_construct(
168 SATI_TRANSLATOR_SEQUENCE_T * sequence
171 void sati_ata_identify_device_copy_data(
172 SATI_TRANSLATOR_SEQUENCE_T * sequence,
173 void * destination_scsi_io,
174 U32 destination_offset,
178 BOOL use_printable_chars
182 SATI_TRANSLATOR_SEQUENCE_T * sequence,
183 void * destination_scsi_io,
184 U32 destination_offset,
189 void sati_ata_identify_device_get_sector_info(
190 ATA_IDENTIFY_DEVICE_DATA_T * identify,
196 void sati_ata_check_power_mode_construct(
198 SATI_TRANSLATOR_SEQUENCE_T * sequence
201 U8 sati_scsi_get_sense_data_length(
202 SATI_TRANSLATOR_SEQUENCE_T * sequence,
206 void sati_scsi_common_response_iu_construct(
207 SCI_SSP_RESPONSE_IU_T * rsp_iu,
209 U8 sense_data_length,
213 void sati_scsi_sense_data_construct(
214 SATI_TRANSLATOR_SEQUENCE_T * sequence,
218 U8 additional_sense_code,
219 U8 additional_sense_code_qualifier
222 void sati_scsi_fixed_sense_data_construct(
223 SATI_TRANSLATOR_SEQUENCE_T * sequence,
228 U8 additional_sense_code,
229 U8 additional_sense_code_qualifier
232 void sati_scsi_descriptor_sense_data_construct(
233 SATI_TRANSLATOR_SEQUENCE_T * sequence,
238 U8 additional_sense_code,
239 U8 additional_sense_code_qualifier
242 void sati_scsi_read_ncq_error_sense_construct(
243 SATI_TRANSLATOR_SEQUENCE_T * sequence,
245 void * ata_input_data,
248 U8 additional_sense_code,
249 U8 additional_sense_code_qualifier
252 void sati_scsi_read_error_sense_construct(
253 SATI_TRANSLATOR_SEQUENCE_T * sequence,
258 U8 additional_sense_code,
259 U8 additional_sense_code_qualifier
262 void sati_scsi_response_data_construct(
263 SATI_TRANSLATOR_SEQUENCE_T * sequence,
268 void sati_get_data_byte(
269 SATI_TRANSLATOR_SEQUENCE_T * sequence,
275 void sati_set_data_byte(
276 SATI_TRANSLATOR_SEQUENCE_T * sequence,
282 void sati_set_data_dword(
283 SATI_TRANSLATOR_SEQUENCE_T * sequence,
289 void sati_set_sense_data_byte(
291 U32 max_sense_data_len,
296 void sati_ata_flush_cache_construct(
298 SATI_TRANSLATOR_SEQUENCE_T * sequence
301 void sati_ata_standby_construct(
303 SATI_TRANSLATOR_SEQUENCE_T * sequence,
307 void sati_ata_standby_immediate_construct(
309 SATI_TRANSLATOR_SEQUENCE_T * sequence
312 void sati_ata_idle_immediate_construct(
314 SATI_TRANSLATOR_SEQUENCE_T * sequence
317 void sati_ata_idle_immediate_unload_construct(
319 SATI_TRANSLATOR_SEQUENCE_T * sequence
322 void sati_ata_idle_construct(
324 SATI_TRANSLATOR_SEQUENCE_T * sequence
327 void sati_ata_media_eject_construct(
329 SATI_TRANSLATOR_SEQUENCE_T * sequence
332 void sati_ata_read_verify_sectors_construct(
334 SATI_TRANSLATOR_SEQUENCE_T * sequence
337 void sati_ata_smart_return_status_construct(
339 SATI_TRANSLATOR_SEQUENCE_T * sequence,
343 void sati_ata_smart_read_log_construct(
345 SATI_TRANSLATOR_SEQUENCE_T * sequence,
350 void sati_ata_write_uncorrectable_construct(
352 SATI_TRANSLATOR_SEQUENCE_T * sequence,
356 void sati_ata_set_features_construct(
358 SATI_TRANSLATOR_SEQUENCE_T * sequence,
362 void sati_ata_read_log_ext_construct(
364 SATI_TRANSLATOR_SEQUENCE_T * sequence,
369 BOOL sati_device_state_stopped(
370 SATI_TRANSLATOR_SEQUENCE_T * sequence,
374 void sati_ata_read_buffer_construct(
376 SATI_TRANSLATOR_SEQUENCE_T * sequence
379 void sati_ata_write_buffer_construct(
381 SATI_TRANSLATOR_SEQUENCE_T * sequence
384 void sati_ata_download_microcode_construct(
386 SATI_TRANSLATOR_SEQUENCE_T * sequence,
392 #endif // _SATI_UTIL_H_