2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
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.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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
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.
61 * @brief This file contains all of the interface methods, macros, structures
62 * that provide general support for SATI. Some methods can be utilized
63 * by a user to construct ATA/ATAPI commands, copy ATA device
64 * structure data, fill in sense data, etc.
67 #include <sys/param.h>
69 #include <dev/isci/scil/sati_types.h>
70 #include <dev/isci/scil/sati_translator_sequence.h>
72 #include <dev/isci/scil/intel_sata.h>
73 #include <dev/isci/scil/intel_sas.h>
76 * This macro allows the translator to be able to handle environments where
77 * the contents of the CDB are of a different endian nature of byte swapped
80 #define sati_get_cdb_byte(the_cdb, index) (the_cdb)[(index)]
82 #define sati_get_ata_status(the_reg_fis) ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->status
83 #define sati_get_ata_error(the_reg_fis) ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->error
85 #define sati_get_ata_command(the_reg_fis) \
86 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command
88 #define sati_get_ata_sector_count(the_reg_fis) \
89 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count
90 #define sati_get_ata_sector_count_exp(the_reg_fis) \
91 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count_exp
92 #define sati_get_ata_lba_low(the_reg_fis) \
93 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_low
94 #define sati_get_ata_lba_mid(the_reg_fis) \
95 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_mid
96 #define sati_get_ata_lba_high(the_reg_fis) \
97 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_high
98 #define sati_get_ata_sector_count_ext(the_reg_fis) \
99 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count_exp
100 #define sati_get_ata_lba_low_ext(the_reg_fis) \
101 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_low_exp
102 #define sati_get_ata_lba_mid_ext(the_reg_fis) \
103 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_mid_exp
104 #define sati_get_ata_lba_high_ext(the_reg_fis) \
105 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_high_exp
106 #define sati_get_ata_device(the_reg_fis) \
107 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->device
109 #define sati_set_ata_status(the_reg_fis, value) \
110 ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->status = (value)
111 #define sati_set_sata_fis_type(the_reg_fis, value) \
112 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->fis_type = (value)
113 #define sati_set_sata_command_flag(the_reg_fis) \
114 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command_flag = 1
115 #define sati_clear_sata_command_flag(the_reg_fis) \
116 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command_flag = 0
118 #define sati_set_ata_command(the_reg_fis, value) \
119 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command = (value)
120 #define sati_set_ata_features(the_reg_fis, value) \
121 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->features = (value)
122 #define sati_set_ata_features_exp(the_reg_fis, value) \
123 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->features_exp = (value)
124 #define sati_set_ata_control(the_reg_fis, value) \
125 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->control = (value)
126 #define sati_set_ata_sector_count(the_reg_fis, value) \
127 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->sector_count = (value)
128 #define sati_set_ata_sector_count_exp(the_reg_fis, value) \
129 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->sector_count_exp = (value)
130 #define sati_set_ata_lba_low(the_reg_fis, value) \
131 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_low = (value)
132 #define sati_set_ata_lba_mid(the_reg_fis, value) \
133 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_mid = (value)
134 #define sati_set_ata_lba_high(the_reg_fis, value) \
135 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_high = (value)
136 #define sati_set_ata_lba_low_exp(the_reg_fis, value) \
137 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_low_exp = (value)
138 #define sati_set_ata_lba_mid_exp(the_reg_fis, value) \
139 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_mid_exp = (value)
140 #define sati_set_ata_lba_high_exp(the_reg_fis, value) \
141 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_high_exp = (value)
142 #define sati_set_ata_device_head(the_reg_fis, value) \
143 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->device = (value)
145 #define ATA_MID_REGISTER_THRESHOLD_EXCEEDED 0xF4
146 #define ATA_HIGH_REGISTER_THRESHOLD_EXCEEDED 0x2C
148 #define ATA_MICROCODE_OFFSET_DOWNLOAD 0x03
149 #define ATA_MICROCODE_DOWNLOAD_SAVE 0x07
151 void sati_ata_non_data_command(
153 SATI_TRANSLATOR_SEQUENCE_T * sequence
156 void sati_ata_identify_device_construct(
158 SATI_TRANSLATOR_SEQUENCE_T * sequence
161 void sati_ata_execute_device_diagnostic_construct(
163 SATI_TRANSLATOR_SEQUENCE_T * sequence
166 void sati_ata_identify_device_copy_data(
167 SATI_TRANSLATOR_SEQUENCE_T * sequence,
168 void * destination_scsi_io,
169 U32 destination_offset,
173 BOOL use_printable_chars
177 SATI_TRANSLATOR_SEQUENCE_T * sequence,
178 void * destination_scsi_io,
179 U32 destination_offset,
184 void sati_ata_identify_device_get_sector_info(
185 ATA_IDENTIFY_DEVICE_DATA_T * identify,
191 void sati_ata_check_power_mode_construct(
193 SATI_TRANSLATOR_SEQUENCE_T * sequence
196 U8 sati_scsi_get_sense_data_length(
197 SATI_TRANSLATOR_SEQUENCE_T * sequence,
201 void sati_scsi_common_response_iu_construct(
202 SCI_SSP_RESPONSE_IU_T * rsp_iu,
204 U8 sense_data_length,
208 void sati_scsi_sense_data_construct(
209 SATI_TRANSLATOR_SEQUENCE_T * sequence,
213 U8 additional_sense_code,
214 U8 additional_sense_code_qualifier
217 void sati_scsi_fixed_sense_data_construct(
218 SATI_TRANSLATOR_SEQUENCE_T * sequence,
223 U8 additional_sense_code,
224 U8 additional_sense_code_qualifier
227 void sati_scsi_descriptor_sense_data_construct(
228 SATI_TRANSLATOR_SEQUENCE_T * sequence,
233 U8 additional_sense_code,
234 U8 additional_sense_code_qualifier
237 void sati_scsi_read_ncq_error_sense_construct(
238 SATI_TRANSLATOR_SEQUENCE_T * sequence,
240 void * ata_input_data,
243 U8 additional_sense_code,
244 U8 additional_sense_code_qualifier
247 void sati_scsi_read_error_sense_construct(
248 SATI_TRANSLATOR_SEQUENCE_T * sequence,
253 U8 additional_sense_code,
254 U8 additional_sense_code_qualifier
257 void sati_scsi_response_data_construct(
258 SATI_TRANSLATOR_SEQUENCE_T * sequence,
263 void sati_get_data_byte(
264 SATI_TRANSLATOR_SEQUENCE_T * sequence,
270 void sati_set_data_byte(
271 SATI_TRANSLATOR_SEQUENCE_T * sequence,
277 void sati_set_data_dword(
278 SATI_TRANSLATOR_SEQUENCE_T * sequence,
284 void sati_set_sense_data_byte(
286 U32 max_sense_data_len,
291 void sati_ata_flush_cache_construct(
293 SATI_TRANSLATOR_SEQUENCE_T * sequence
296 void sati_ata_standby_construct(
298 SATI_TRANSLATOR_SEQUENCE_T * sequence,
302 void sati_ata_standby_immediate_construct(
304 SATI_TRANSLATOR_SEQUENCE_T * sequence
307 void sati_ata_idle_immediate_construct(
309 SATI_TRANSLATOR_SEQUENCE_T * sequence
312 void sati_ata_idle_immediate_unload_construct(
314 SATI_TRANSLATOR_SEQUENCE_T * sequence
317 void sati_ata_idle_construct(
319 SATI_TRANSLATOR_SEQUENCE_T * sequence
322 void sati_ata_media_eject_construct(
324 SATI_TRANSLATOR_SEQUENCE_T * sequence
327 void sati_ata_read_verify_sectors_construct(
329 SATI_TRANSLATOR_SEQUENCE_T * sequence
332 void sati_ata_smart_return_status_construct(
334 SATI_TRANSLATOR_SEQUENCE_T * sequence,
338 void sati_ata_smart_read_log_construct(
340 SATI_TRANSLATOR_SEQUENCE_T * sequence,
345 void sati_ata_write_uncorrectable_construct(
347 SATI_TRANSLATOR_SEQUENCE_T * sequence,
351 void sati_ata_set_features_construct(
353 SATI_TRANSLATOR_SEQUENCE_T * sequence,
357 void sati_ata_read_log_ext_construct(
359 SATI_TRANSLATOR_SEQUENCE_T * sequence,
364 BOOL sati_device_state_stopped(
365 SATI_TRANSLATOR_SEQUENCE_T * sequence,
369 void sati_ata_read_buffer_construct(
371 SATI_TRANSLATOR_SEQUENCE_T * sequence
374 void sati_ata_write_buffer_construct(
376 SATI_TRANSLATOR_SEQUENCE_T * sequence
379 void sati_ata_download_microcode_construct(
381 SATI_TRANSLATOR_SEQUENCE_T * sequence,
387 #endif // _SATI_UTIL_H_