xref: /freebsd/sys/dev/isci/scil/sati_util.h (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
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 #ifndef _SATI_UTIL_H_
55 #define _SATI_UTIL_H_
56 
57 /**
58  * @file
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.
63  */
64 
65 #include <sys/param.h>
66 
67 #include <dev/isci/scil/sati_types.h>
68 #include <dev/isci/scil/sati_translator_sequence.h>
69 
70 #include <dev/isci/scil/intel_sata.h>
71 #include <dev/isci/scil/intel_sas.h>
72 
73 /**
74  * This macro allows the translator to be able to handle environments where
75  * the contents of the CDB are of a different endian nature of byte swapped
76  * in some fashion.
77  */
78 #define sati_get_cdb_byte(the_cdb, index)    (the_cdb)[(index)]
79 
80 #define sati_get_ata_status(the_reg_fis) ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->status
81 #define sati_get_ata_error(the_reg_fis) ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->error
82 
83 #define sati_get_ata_command(the_reg_fis)   \
84    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command
85 
86 #define sati_get_ata_sector_count(the_reg_fis) \
87    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count
88 #define sati_get_ata_sector_count_exp(the_reg_fis) \
89    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count_exp
90 #define sati_get_ata_lba_low(the_reg_fis) \
91    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_low
92 #define sati_get_ata_lba_mid(the_reg_fis) \
93    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_mid
94 #define sati_get_ata_lba_high(the_reg_fis) \
95    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_high
96 #define sati_get_ata_sector_count_ext(the_reg_fis) \
97    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->sector_count_exp
98 #define sati_get_ata_lba_low_ext(the_reg_fis) \
99    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_low_exp
100 #define sati_get_ata_lba_mid_ext(the_reg_fis) \
101    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_mid_exp
102 #define sati_get_ata_lba_high_ext(the_reg_fis) \
103    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->lba_high_exp
104 #define sati_get_ata_device(the_reg_fis) \
105    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->device
106 
107 #define sati_set_ata_status(the_reg_fis, value) \
108    ((SATA_FIS_REG_D2H_T*)(the_reg_fis))->status = (value)
109 #define sati_set_sata_fis_type(the_reg_fis, value) \
110    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->fis_type = (value)
111 #define sati_set_sata_command_flag(the_reg_fis) \
112    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command_flag = 1
113 #define sati_clear_sata_command_flag(the_reg_fis) \
114    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command_flag = 0
115 
116 #define sati_set_ata_command(the_reg_fis, value)          \
117    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command = (value)
118 #define sati_set_ata_features(the_reg_fis, value)         \
119    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->features = (value)
120 #define sati_set_ata_features_exp(the_reg_fis, value)     \
121    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->features_exp = (value)
122 #define sati_set_ata_control(the_reg_fis, value)          \
123    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->control = (value)
124 #define sati_set_ata_sector_count(the_reg_fis, value)     \
125    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->sector_count = (value)
126 #define sati_set_ata_sector_count_exp(the_reg_fis, value) \
127    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->sector_count_exp = (value)
128 #define sati_set_ata_lba_low(the_reg_fis, value)          \
129    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_low = (value)
130 #define sati_set_ata_lba_mid(the_reg_fis, value)          \
131    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_mid = (value)
132 #define sati_set_ata_lba_high(the_reg_fis, value)         \
133    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_high = (value)
134 #define sati_set_ata_lba_low_exp(the_reg_fis, value)      \
135    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_low_exp = (value)
136 #define sati_set_ata_lba_mid_exp(the_reg_fis, value)      \
137    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_mid_exp = (value)
138 #define sati_set_ata_lba_high_exp(the_reg_fis, value)     \
139    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->lba_high_exp = (value)
140 #define sati_set_ata_device_head(the_reg_fis, value)      \
141    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->device = (value)
142 
143 #define ATA_MID_REGISTER_THRESHOLD_EXCEEDED    0xF4
144 #define ATA_HIGH_REGISTER_THRESHOLD_EXCEEDED   0x2C
145 
146 #define ATA_MICROCODE_OFFSET_DOWNLOAD        0x03
147 #define ATA_MICROCODE_DOWNLOAD_SAVE          0x07
148 
149 void sati_ata_non_data_command(
150    void                        * ata_io,
151    SATI_TRANSLATOR_SEQUENCE_T  * sequence
152 );
153 
154 void sati_ata_identify_device_construct(
155    void                       * ata_io,
156    SATI_TRANSLATOR_SEQUENCE_T * sequence
157 );
158 
159 void sati_ata_execute_device_diagnostic_construct(
160    void                       * ata_io,
161    SATI_TRANSLATOR_SEQUENCE_T * sequence
162 );
163 
164 void sati_ata_identify_device_copy_data(
165    SATI_TRANSLATOR_SEQUENCE_T * sequence,
166    void                       * destination_scsi_io,
167    U32                          destination_offset,
168    U8                         * source_buffer,
169    U32                          source_offset,
170    U32                          length,
171    BOOL                         use_printable_chars
172 );
173 
174 void sati_copy_data(
175    SATI_TRANSLATOR_SEQUENCE_T * sequence,
176    void                       * destination_scsi_io,
177    U32                          destination_offset,
178    U8                         * source_buffer,
179    U32                          length
180 );
181 
182 void sati_ata_identify_device_get_sector_info(
183    ATA_IDENTIFY_DEVICE_DATA_T * identify,
184    U32                        * lba_high,
185    U32                        * lba_low,
186    U32                        * sector_size
187 );
188 
189 void sati_ata_check_power_mode_construct(
190    void                       * ata_io,
191    SATI_TRANSLATOR_SEQUENCE_T * sequence
192 );
193 
194 U8 sati_scsi_get_sense_data_length(
195    SATI_TRANSLATOR_SEQUENCE_T * sequence,
196    void * scsi_io
197 );
198 
199 void sati_scsi_common_response_iu_construct(
200    SCI_SSP_RESPONSE_IU_T *      rsp_iu,
201    U8                           scsi_status,
202    U8                           sense_data_length,
203    U8                           data_present
204 );
205 
206 void sati_scsi_sense_data_construct(
207    SATI_TRANSLATOR_SEQUENCE_T * sequence,
208    void                       * scsi_io,
209    U8                           status,
210    U8                           sense_key,
211    U8                           additional_sense_code,
212    U8                           additional_sense_code_qualifier
213 );
214 
215 void sati_scsi_fixed_sense_data_construct(
216    SATI_TRANSLATOR_SEQUENCE_T * sequence,
217    void                       * scsi_io,
218    U8                           response_code,
219    U8                           scsi_status,
220    U8                           sense_key,
221    U8                           additional_sense_code,
222    U8                           additional_sense_code_qualifier
223 );
224 
225 void sati_scsi_descriptor_sense_data_construct(
226    SATI_TRANSLATOR_SEQUENCE_T * sequence,
227    void                       * scsi_io,
228    U8                           response_code,
229    U8                           scsi_status,
230    U8                           sense_key,
231    U8                           additional_sense_code,
232    U8                           additional_sense_code_qualifier
233 );
234 
235 void sati_scsi_read_ncq_error_sense_construct(
236    SATI_TRANSLATOR_SEQUENCE_T * sequence,
237    void                       * scsi_io,
238    void                       * ata_input_data,
239    U8                           scsi_status,
240    U8                           sense_key,
241    U8                           additional_sense_code,
242    U8                           additional_sense_code_qualifier
243 );
244 
245 void sati_scsi_read_error_sense_construct(
246    SATI_TRANSLATOR_SEQUENCE_T * sequence,
247    void                       * scsi_io,
248    void                       * ata_io,
249    U8                           status,
250    U8                           sense_key,
251    U8                           additional_sense_code,
252    U8                           additional_sense_code_qualifier
253 );
254 
255 void sati_scsi_response_data_construct(
256    SATI_TRANSLATOR_SEQUENCE_T * sequence,
257    void                       * scsi_io,
258    U8                           response_data
259 );
260 
261 void sati_get_data_byte(
262    SATI_TRANSLATOR_SEQUENCE_T * sequence,
263    void                       * scsi_io,
264    U32                          byte_offset,
265    U8                         * value
266 );
267 
268 void sati_set_data_byte(
269    SATI_TRANSLATOR_SEQUENCE_T * sequence,
270    void                       * scsi_io,
271    U32                          byte_offset,
272    U8                           value
273 );
274 
275 void sati_set_data_dword(
276    SATI_TRANSLATOR_SEQUENCE_T * sequence,
277    void                       * scsi_io,
278    U32                          byte_offset,
279    U32                          value
280 );
281 
282 void sati_set_sense_data_byte(
283    U8  * sense_data,
284    U32   max_sense_data_len,
285    U32   byte_offset,
286    U8    value
287 );
288 
289 void sati_ata_flush_cache_construct(
290    void                       * ata_io,
291    SATI_TRANSLATOR_SEQUENCE_T * sequence
292 );
293 
294 void sati_ata_standby_construct(
295    void                       * ata_io,
296    SATI_TRANSLATOR_SEQUENCE_T * sequence,
297    U16                          count
298 );
299 
300 void sati_ata_standby_immediate_construct(
301    void                       * ata_io,
302    SATI_TRANSLATOR_SEQUENCE_T * sequence
303 );
304 
305 void sati_ata_idle_immediate_construct(
306    void                       * ata_io,
307    SATI_TRANSLATOR_SEQUENCE_T * sequence
308 );
309 
310 void sati_ata_idle_immediate_unload_construct(
311    void                       * ata_io,
312    SATI_TRANSLATOR_SEQUENCE_T * sequence
313 );
314 
315 void sati_ata_idle_construct(
316    void                       * ata_io,
317    SATI_TRANSLATOR_SEQUENCE_T * sequence
318 );
319 
320 void sati_ata_media_eject_construct(
321    void                       * ata_io,
322    SATI_TRANSLATOR_SEQUENCE_T * sequence
323 );
324 
325 void sati_ata_read_verify_sectors_construct(
326    void                       * ata_io,
327    SATI_TRANSLATOR_SEQUENCE_T * sequence
328 );
329 
330 void sati_ata_smart_return_status_construct(
331    void                       * ata_io,
332    SATI_TRANSLATOR_SEQUENCE_T * sequence,
333    U8                           feature_value
334 );
335 
336 void sati_ata_smart_read_log_construct(
337    void                       * ata_io,
338    SATI_TRANSLATOR_SEQUENCE_T * sequence,
339    U8                           log_address,
340    U32                          transfer_length
341 );
342 
343 void sati_ata_write_uncorrectable_construct(
344    void                       * ata_io,
345    SATI_TRANSLATOR_SEQUENCE_T * sequence,
346    U8                           feature_value
347 );
348 
349 void sati_ata_set_features_construct(
350    void                       * ata_io,
351    SATI_TRANSLATOR_SEQUENCE_T * sequence,
352    U8                           feature
353 );
354 
355 void sati_ata_read_log_ext_construct(
356    void                          * ata_io,
357    SATI_TRANSLATOR_SEQUENCE_T    * sequence,
358    U8                              log_address,
359    U32                             transfer_length
360 );
361 
362 BOOL sati_device_state_stopped(
363    SATI_TRANSLATOR_SEQUENCE_T * sequence,
364    void                       * scsi_io
365 );
366 
367 void sati_ata_read_buffer_construct(
368    void                       * ata_io,
369    SATI_TRANSLATOR_SEQUENCE_T * sequence
370 );
371 
372 void sati_ata_write_buffer_construct(
373    void                       * ata_io,
374    SATI_TRANSLATOR_SEQUENCE_T * sequence
375 );
376 
377 void sati_ata_download_microcode_construct(
378    void                       * ata_io,
379    SATI_TRANSLATOR_SEQUENCE_T * sequence,
380    U8                           mode,
381    U32                          block_count,
382    U32                          buffer_offset
383 );
384 
385 #endif // _SATI_UTIL_H_
386 
387