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_UTIL_H_ 57 #define _SATI_UTIL_H_ 58 59 /** 60 * @file 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. 65 */ 66 67 #include <sys/param.h> 68 69 #include <dev/isci/scil/sati_types.h> 70 #include <dev/isci/scil/sati_translator_sequence.h> 71 72 #include <dev/isci/scil/intel_sata.h> 73 #include <dev/isci/scil/intel_sas.h> 74 75 /** 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 78 * in some fashion. 79 */ 80 #define sati_get_cdb_byte(the_cdb, index) (the_cdb)[(index)] 81 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 84 85 #define sati_get_ata_command(the_reg_fis) \ 86 ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command 87 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 108 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 117 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) 144 145 #define ATA_MID_REGISTER_THRESHOLD_EXCEEDED 0xF4 146 #define ATA_HIGH_REGISTER_THRESHOLD_EXCEEDED 0x2C 147 148 #define ATA_MICROCODE_OFFSET_DOWNLOAD 0x03 149 #define ATA_MICROCODE_DOWNLOAD_SAVE 0x07 150 151 void sati_ata_non_data_command( 152 void * ata_io, 153 SATI_TRANSLATOR_SEQUENCE_T * sequence 154 ); 155 156 void sati_ata_identify_device_construct( 157 void * ata_io, 158 SATI_TRANSLATOR_SEQUENCE_T * sequence 159 ); 160 161 void sati_ata_execute_device_diagnostic_construct( 162 void * ata_io, 163 SATI_TRANSLATOR_SEQUENCE_T * sequence 164 ); 165 166 void sati_ata_identify_device_copy_data( 167 SATI_TRANSLATOR_SEQUENCE_T * sequence, 168 void * destination_scsi_io, 169 U32 destination_offset, 170 U8 * source_buffer, 171 U32 source_offset, 172 U32 length, 173 BOOL use_printable_chars 174 ); 175 176 void sati_copy_data( 177 SATI_TRANSLATOR_SEQUENCE_T * sequence, 178 void * destination_scsi_io, 179 U32 destination_offset, 180 U8 * source_buffer, 181 U32 length 182 ); 183 184 void sati_ata_identify_device_get_sector_info( 185 ATA_IDENTIFY_DEVICE_DATA_T * identify, 186 U32 * lba_high, 187 U32 * lba_low, 188 U32 * sector_size 189 ); 190 191 void sati_ata_check_power_mode_construct( 192 void * ata_io, 193 SATI_TRANSLATOR_SEQUENCE_T * sequence 194 ); 195 196 U8 sati_scsi_get_sense_data_length( 197 SATI_TRANSLATOR_SEQUENCE_T * sequence, 198 void * scsi_io 199 ); 200 201 void sati_scsi_common_response_iu_construct( 202 SCI_SSP_RESPONSE_IU_T * rsp_iu, 203 U8 scsi_status, 204 U8 sense_data_length, 205 U8 data_present 206 ); 207 208 void sati_scsi_sense_data_construct( 209 SATI_TRANSLATOR_SEQUENCE_T * sequence, 210 void * scsi_io, 211 U8 status, 212 U8 sense_key, 213 U8 additional_sense_code, 214 U8 additional_sense_code_qualifier 215 ); 216 217 void sati_scsi_fixed_sense_data_construct( 218 SATI_TRANSLATOR_SEQUENCE_T * sequence, 219 void * scsi_io, 220 U8 response_code, 221 U8 scsi_status, 222 U8 sense_key, 223 U8 additional_sense_code, 224 U8 additional_sense_code_qualifier 225 ); 226 227 void sati_scsi_descriptor_sense_data_construct( 228 SATI_TRANSLATOR_SEQUENCE_T * sequence, 229 void * scsi_io, 230 U8 response_code, 231 U8 scsi_status, 232 U8 sense_key, 233 U8 additional_sense_code, 234 U8 additional_sense_code_qualifier 235 ); 236 237 void sati_scsi_read_ncq_error_sense_construct( 238 SATI_TRANSLATOR_SEQUENCE_T * sequence, 239 void * scsi_io, 240 void * ata_input_data, 241 U8 scsi_status, 242 U8 sense_key, 243 U8 additional_sense_code, 244 U8 additional_sense_code_qualifier 245 ); 246 247 void sati_scsi_read_error_sense_construct( 248 SATI_TRANSLATOR_SEQUENCE_T * sequence, 249 void * scsi_io, 250 void * ata_io, 251 U8 status, 252 U8 sense_key, 253 U8 additional_sense_code, 254 U8 additional_sense_code_qualifier 255 ); 256 257 void sati_scsi_response_data_construct( 258 SATI_TRANSLATOR_SEQUENCE_T * sequence, 259 void * scsi_io, 260 U8 response_data 261 ); 262 263 void sati_get_data_byte( 264 SATI_TRANSLATOR_SEQUENCE_T * sequence, 265 void * scsi_io, 266 U32 byte_offset, 267 U8 * value 268 ); 269 270 void sati_set_data_byte( 271 SATI_TRANSLATOR_SEQUENCE_T * sequence, 272 void * scsi_io, 273 U32 byte_offset, 274 U8 value 275 ); 276 277 void sati_set_data_dword( 278 SATI_TRANSLATOR_SEQUENCE_T * sequence, 279 void * scsi_io, 280 U32 byte_offset, 281 U32 value 282 ); 283 284 void sati_set_sense_data_byte( 285 U8 * sense_data, 286 U32 max_sense_data_len, 287 U32 byte_offset, 288 U8 value 289 ); 290 291 void sati_ata_flush_cache_construct( 292 void * ata_io, 293 SATI_TRANSLATOR_SEQUENCE_T * sequence 294 ); 295 296 void sati_ata_standby_construct( 297 void * ata_io, 298 SATI_TRANSLATOR_SEQUENCE_T * sequence, 299 U16 count 300 ); 301 302 void sati_ata_standby_immediate_construct( 303 void * ata_io, 304 SATI_TRANSLATOR_SEQUENCE_T * sequence 305 ); 306 307 void sati_ata_idle_immediate_construct( 308 void * ata_io, 309 SATI_TRANSLATOR_SEQUENCE_T * sequence 310 ); 311 312 void sati_ata_idle_immediate_unload_construct( 313 void * ata_io, 314 SATI_TRANSLATOR_SEQUENCE_T * sequence 315 ); 316 317 void sati_ata_idle_construct( 318 void * ata_io, 319 SATI_TRANSLATOR_SEQUENCE_T * sequence 320 ); 321 322 void sati_ata_media_eject_construct( 323 void * ata_io, 324 SATI_TRANSLATOR_SEQUENCE_T * sequence 325 ); 326 327 void sati_ata_read_verify_sectors_construct( 328 void * ata_io, 329 SATI_TRANSLATOR_SEQUENCE_T * sequence 330 ); 331 332 void sati_ata_smart_return_status_construct( 333 void * ata_io, 334 SATI_TRANSLATOR_SEQUENCE_T * sequence, 335 U8 feature_value 336 ); 337 338 void sati_ata_smart_read_log_construct( 339 void * ata_io, 340 SATI_TRANSLATOR_SEQUENCE_T * sequence, 341 U8 log_address, 342 U32 transfer_length 343 ); 344 345 void sati_ata_write_uncorrectable_construct( 346 void * ata_io, 347 SATI_TRANSLATOR_SEQUENCE_T * sequence, 348 U8 feature_value 349 ); 350 351 void sati_ata_set_features_construct( 352 void * ata_io, 353 SATI_TRANSLATOR_SEQUENCE_T * sequence, 354 U8 feature 355 ); 356 357 void sati_ata_read_log_ext_construct( 358 void * ata_io, 359 SATI_TRANSLATOR_SEQUENCE_T * sequence, 360 U8 log_address, 361 U32 transfer_length 362 ); 363 364 BOOL sati_device_state_stopped( 365 SATI_TRANSLATOR_SEQUENCE_T * sequence, 366 void * scsi_io 367 ); 368 369 void sati_ata_read_buffer_construct( 370 void * ata_io, 371 SATI_TRANSLATOR_SEQUENCE_T * sequence 372 ); 373 374 void sati_ata_write_buffer_construct( 375 void * ata_io, 376 SATI_TRANSLATOR_SEQUENCE_T * sequence 377 ); 378 379 void sati_ata_download_microcode_construct( 380 void * ata_io, 381 SATI_TRANSLATOR_SEQUENCE_T * sequence, 382 U8 mode, 383 U32 block_count, 384 U32 buffer_offset 385 ); 386 387 #endif // _SATI_UTIL_H_ 388 389