]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/isci/scil/sati_util.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / isci / scil / sati_util.h
1 /*-
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.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
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.
12  *
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.
17  *
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.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
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
38  *     distribution.
39  *
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.
51  *
52  * $FreeBSD$
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 <dev/isci/scil/sati_types.h>
66 #include <dev/isci/scil/sati_translator_sequence.h>
67
68 #include <dev/isci/scil/intel_sata.h>
69 #include <dev/isci/scil/intel_sas.h>
70
71 /**
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
74  * in some fashion.
75  */
76 #define sati_get_cdb_byte(the_cdb, index)    (the_cdb)[(index)]
77
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
80
81 #define sati_get_ata_command(the_reg_fis)   \
82    ((SATA_FIS_REG_H2D_T*)(the_reg_fis))->command
83
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
104
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
113
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)
140
141 #define ATA_MID_REGISTER_THRESHOLD_EXCEEDED    0xF4
142 #define ATA_HIGH_REGISTER_THRESHOLD_EXCEEDED   0x2C
143
144 #define ATA_MICROCODE_OFFSET_DOWNLOAD        0x03
145 #define ATA_MICROCODE_DOWNLOAD_SAVE          0x07
146
147 #ifndef MIN
148 #define MIN(x,y) ((x) < (y) ? (x) : (y))
149 #endif
150
151 #ifndef MAX
152 #define MAX(x,y) ((x) > (y) ? (x) : (y))
153 #endif
154
155
156 void sati_ata_non_data_command(
157    void                        * ata_io,
158    SATI_TRANSLATOR_SEQUENCE_T  * sequence
159 );
160
161 void sati_ata_identify_device_construct(
162    void                       * ata_io,
163    SATI_TRANSLATOR_SEQUENCE_T * sequence
164 );
165
166 void sati_ata_execute_device_diagnostic_construct(
167    void                       * ata_io,
168    SATI_TRANSLATOR_SEQUENCE_T * sequence
169 );
170
171 void sati_ata_identify_device_copy_data(
172    SATI_TRANSLATOR_SEQUENCE_T * sequence,
173    void                       * destination_scsi_io,
174    U32                          destination_offset,
175    U8                         * source_buffer,
176    U32                          source_offset,
177    U32                          length,
178    BOOL                         use_printable_chars
179 );
180
181 void sati_copy_data(
182    SATI_TRANSLATOR_SEQUENCE_T * sequence,
183    void                       * destination_scsi_io,
184    U32                          destination_offset,
185    U8                         * source_buffer,
186    U32                          length
187 );
188
189 void sati_ata_identify_device_get_sector_info(
190    ATA_IDENTIFY_DEVICE_DATA_T * identify,
191    U32                        * lba_high,
192    U32                        * lba_low,
193    U32                        * sector_size
194 );
195
196 void sati_ata_check_power_mode_construct(
197    void                       * ata_io,
198    SATI_TRANSLATOR_SEQUENCE_T * sequence
199 );
200
201 U8 sati_scsi_get_sense_data_length(
202    SATI_TRANSLATOR_SEQUENCE_T * sequence,
203    void * scsi_io
204 );
205
206 void sati_scsi_common_response_iu_construct(
207    SCI_SSP_RESPONSE_IU_T *      rsp_iu,
208    U8                           scsi_status,
209    U8                           sense_data_length,
210    U8                           data_present
211 );
212
213 void sati_scsi_sense_data_construct(
214    SATI_TRANSLATOR_SEQUENCE_T * sequence,
215    void                       * scsi_io,
216    U8                           status,
217    U8                           sense_key,
218    U8                           additional_sense_code,
219    U8                           additional_sense_code_qualifier
220 );
221
222 void sati_scsi_fixed_sense_data_construct(
223    SATI_TRANSLATOR_SEQUENCE_T * sequence,
224    void                       * scsi_io,
225    U8                           response_code,
226    U8                           scsi_status,
227    U8                           sense_key,
228    U8                           additional_sense_code,
229    U8                           additional_sense_code_qualifier
230 );
231
232 void sati_scsi_descriptor_sense_data_construct(
233    SATI_TRANSLATOR_SEQUENCE_T * sequence,
234    void                       * scsi_io,
235    U8                           response_code,
236    U8                           scsi_status,
237    U8                           sense_key,
238    U8                           additional_sense_code,
239    U8                           additional_sense_code_qualifier
240 );
241
242 void sati_scsi_read_ncq_error_sense_construct(
243    SATI_TRANSLATOR_SEQUENCE_T * sequence,
244    void                       * scsi_io,
245    void                       * ata_input_data,
246    U8                           scsi_status,
247    U8                           sense_key,
248    U8                           additional_sense_code,
249    U8                           additional_sense_code_qualifier
250 );
251
252 void sati_scsi_read_error_sense_construct(
253    SATI_TRANSLATOR_SEQUENCE_T * sequence,
254    void                       * scsi_io,
255    void                       * ata_io,
256    U8                           status,
257    U8                           sense_key,
258    U8                           additional_sense_code,
259    U8                           additional_sense_code_qualifier
260 );
261
262 void sati_scsi_response_data_construct(
263    SATI_TRANSLATOR_SEQUENCE_T * sequence,
264    void                       * scsi_io,
265    U8                           response_data
266 );
267
268 void sati_get_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_byte(
276    SATI_TRANSLATOR_SEQUENCE_T * sequence,
277    void                       * scsi_io,
278    U32                          byte_offset,
279    U8                           value
280 );
281
282 void sati_set_data_dword(
283    SATI_TRANSLATOR_SEQUENCE_T * sequence,
284    void                       * scsi_io,
285    U32                          byte_offset,
286    U32                          value
287 );
288
289 void sati_set_sense_data_byte(
290    U8  * sense_data,
291    U32   max_sense_data_len,
292    U32   byte_offset,
293    U8    value
294 );
295
296 void sati_ata_flush_cache_construct(
297    void                       * ata_io,
298    SATI_TRANSLATOR_SEQUENCE_T * sequence
299 );
300
301 void sati_ata_standby_construct(
302    void                       * ata_io,
303    SATI_TRANSLATOR_SEQUENCE_T * sequence,
304    U16                          count
305 );
306
307 void sati_ata_standby_immediate_construct(
308    void                       * ata_io,
309    SATI_TRANSLATOR_SEQUENCE_T * sequence
310 );
311
312 void sati_ata_idle_immediate_construct(
313    void                       * ata_io,
314    SATI_TRANSLATOR_SEQUENCE_T * sequence
315 );
316
317 void sati_ata_idle_immediate_unload_construct(
318    void                       * ata_io,
319    SATI_TRANSLATOR_SEQUENCE_T * sequence
320 );
321
322 void sati_ata_idle_construct(
323    void                       * ata_io,
324    SATI_TRANSLATOR_SEQUENCE_T * sequence
325 );
326
327 void sati_ata_media_eject_construct(
328    void                       * ata_io,
329    SATI_TRANSLATOR_SEQUENCE_T * sequence
330 );
331
332 void sati_ata_read_verify_sectors_construct(
333    void                       * ata_io,
334    SATI_TRANSLATOR_SEQUENCE_T * sequence
335 );
336
337 void sati_ata_smart_return_status_construct(
338    void                       * ata_io,
339    SATI_TRANSLATOR_SEQUENCE_T * sequence,
340    U8                           feature_value
341 );
342
343 void sati_ata_smart_read_log_construct(
344    void                       * ata_io,
345    SATI_TRANSLATOR_SEQUENCE_T * sequence,
346    U8                           log_address,
347    U32                          transfer_length
348 );
349
350 void sati_ata_write_uncorrectable_construct(
351    void                       * ata_io,
352    SATI_TRANSLATOR_SEQUENCE_T * sequence,
353    U8                           feature_value
354 );
355
356 void sati_ata_set_features_construct(
357    void                       * ata_io,
358    SATI_TRANSLATOR_SEQUENCE_T * sequence,
359    U8                           feature
360 );
361
362 void sati_ata_read_log_ext_construct(
363    void                          * ata_io,
364    SATI_TRANSLATOR_SEQUENCE_T    * sequence,
365    U8                              log_address,
366    U32                             transfer_length
367 );
368
369 BOOL sati_device_state_stopped(
370    SATI_TRANSLATOR_SEQUENCE_T * sequence,
371    void                       * scsi_io
372 );
373
374 void sati_ata_read_buffer_construct(
375    void                       * ata_io,
376    SATI_TRANSLATOR_SEQUENCE_T * sequence
377 );
378
379 void sati_ata_write_buffer_construct(
380    void                       * ata_io,
381    SATI_TRANSLATOR_SEQUENCE_T * sequence
382 );
383
384 void sati_ata_download_microcode_construct(
385    void                       * ata_io,
386    SATI_TRANSLATOR_SEQUENCE_T * sequence,
387    U8                           mode,
388    U32                          block_count,
389    U32                          buffer_offset
390 );
391
392 #endif // _SATI_UTIL_H_
393