xref: /freebsd/sys/dev/isci/scil/intel_sata.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
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 - 2010 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 _SATA_H_
55 #define _SATA_H_
56 
57 #include <dev/isci/types.h>
58 
59 /**
60  * @file
61  *
62  * @brief This file defines all of the SATA releated constants, enumerations,
63  *        and types. Please note that this file does not necessarily contain
64  *        an exhaustive list of all contants and commands.
65  */
66 
67 /**
68  * @name SATA FIS Types
69  *
70  * These constants depict the various SATA FIS types devined in the serial ATA
71  * specification.
72  */
73 /*@{*/
74 #define SATA_FIS_TYPE_REGH2D          0x27
75 #define SATA_FIS_TYPE_REGD2H          0x34
76 #define SATA_FIS_TYPE_SETDEVBITS      0xA1
77 #define SATA_FIS_TYPE_DMA_ACTIVATE    0x39
78 #define SATA_FIS_TYPE_DMA_SETUP       0x41
79 #define SATA_FIS_TYPE_BIST_ACTIVATE   0x58
80 #define SATA_FIS_TYPE_PIO_SETUP       0x5F
81 #define SATA_FIS_TYPE_DATA            0x46
82 /*@}*/
83 
84 #define SATA_REGISTER_FIS_SIZE 0x20
85 
86 /**
87  * @struct  SATA_FIS_HEADER
88  *
89  * @brief This is the common definition for a SATA FIS Header word.  A
90  *        different header word is defined for any FIS type that does not use
91  *        the standard header.
92  */
93 typedef struct SATA_FIS_HEADER
94 {
95    U32 fis_type         :8;   // word 0
96    U32 pm_port          :4;
97    U32 reserved         :1;
98    U32 direction_flag   :1;   // direction
99    U32 interrupt_flag   :1;
100    U32 command_flag     :1;   // command, auto_activate, or notification
101    U32 status           :8;
102    U32 error            :8;
103 } SATA_FIS_HEADER_T;
104 
105 
106 /**
107  * @struct SATA_FIS_REG_H2D
108  *
109  * @brief This is the definition for a SATA Host to Device Register FIS.
110  */
111 typedef struct SATA_FIS_REG_H2D
112 {
113    U32 fis_type         :8;     // word 0
114    U32 pm_port          :4;
115    U32 reserved0        :3;
116    U32 command_flag     :1;
117    U32 command          :8;
118    U32 features         :8;
119    U32 lba_low          :8;     // word 1
120    U32 lba_mid          :8;
121    U32 lba_high         :8;
122    U32 device           :8;
123    U32 lba_low_exp      :8;     // word 2
124    U32 lba_mid_exp      :8;
125    U32 lba_high_exp     :8;
126    U32 features_exp     :8;
127    U32 sector_count     :8;     // word 3
128    U32 sector_count_exp :8;
129    U32 reserved1        :8;
130    U32 control          :8;
131    U32 reserved2;               // word 4
132 } SATA_FIS_REG_H2D_T;
133 
134 /**
135  * @struct SATA_FIS_REG_D2H
136  *
137  * @brief SATA Device To Host FIS
138  */
139 typedef struct SATA_FIS_REG_D2H
140 {
141    U32 fis_type   :8;         // word 0
142    U32 pm_port    :4;
143    U32 reserved0  :2;
144    U32 irq        :1;
145    U32 reserved1  :1;
146    U32 status     :8;
147    U32 error      :8;
148    U8 lba_low;               // word 1
149    U8 lba_mid;
150    U8 lba_high;
151    U8 device;
152    U8 lba_low_exp;           // word 2
153    U8 lba_mid_exp;
154    U8 lba_high_exp;
155    U8 reserved;
156    U8 sector_count;          // word 3
157    U8 sector_count_exp;
158    U16 reserved2;
159    U32 reserved3;
160 } SATA_FIS_REG_D2H_T;
161 
162 /**
163  *  Status field bit definitions
164  */
165 #define SATA_FIS_STATUS_DEVBITS_MASK  (0x77)
166 
167 /**
168  * @struct SATA_FIS_SET_DEV_BITS
169  *
170  * @brief SATA Set Device Bits FIS
171  */
172 typedef struct SATA_FIS_SET_DEV_BITS
173 {
174    U32 fis_type      :8;   // word 0
175    U32 pm_port       :4;
176    U32 reserved0     :2;
177    U32 irq           :1;
178    U32 notification  :1;
179    U32 status_low    :4;
180    U32 status_high   :4;
181    U32 error         :8;
182    U32 s_active;           // word 1
183 } SATA_FIS_SET_DEV_BITS_T;
184 
185 /**
186  * @struct SATA_FIS_DMA_ACTIVATE
187  *
188  * @brief SATA DMA Activate FIS
189  */
190 typedef struct SATA_FIS_DMA_ACTIVATE
191 {
192    U32 fis_type      :8;   // word 0
193    U32 pm_port       :4;
194    U32 reserved0     :24;
195 } SATA_FIS_DMA_ACTIVATE_T;
196 
197 /**
198  * The lower 5 bits in the DMA Buffer ID Low field of the DMA Setup
199  * are used to communicate the command tag.
200  */
201 #define SATA_DMA_SETUP_TAG_ENABLE      0x1F
202 
203 #define SATA_DMA_SETUP_AUTO_ACT_ENABLE 0x80
204 
205 /**
206  * @struct SATA_FIS_DMA_SETUP
207  *
208  * @brief SATA DMA Setup FIS
209  */
210 typedef struct SATA_FIS_DMA_SETUP
211 {
212    U32 fis_type            :8;   // word 0
213    U32 pm_port             :4;
214    U32 reserved_00         :1;
215    U32 direction           :1;
216    U32 irq                 :1;
217    U32 auto_activate       :1;
218    U32 reserved_01         :16;
219    U32 dma_buffer_id_low;        // word 1
220    U32 dma_buffer_id_high;       // word 2
221    U32 reserved0;                // word 3
222    U32 dma_buffer_offset;        // word 4
223    U32 dma_transfer_count;       // word 5
224    U32 reserved1;                // word 6
225 } SATA_FIS_DMA_SETUP_T;
226 
227 /**
228  *  @struct SATA_FIS_BIST_ACTIVATE
229  *
230  *  @brief SATA BIST Activate FIS
231  */
232 typedef struct SATA_FIS_BIST_ACTIVATE
233 {
234    U32 fis_type               :8;   // word 0
235    U32 reserved0              :8;
236    U32 pattern_definition     :8;
237    U32 reserved1              :8;
238    U32 data1;                       // word 1
239    U32 data2;                       // word 1
240 } SATA_FIS_BIST_ACTIVATE_T;
241 
242 /*
243  *  SATA PIO Setup FIS
244  */
245 typedef struct SATA_FIS_PIO_SETUP
246 {
247    U32 fis_type         :8;   // word 0
248    U32 pm_port          :4;
249    U32 reserved_00      :1;
250    U32 direction        :1;
251    U32 irq              :1;
252    U32 reserved_01      :1;
253    U32 status           :8;
254    U32 error            :8;
255    U32 lba_low          :8;   // word 1
256    U32 lba_mid          :8;
257    U32 lba_high         :8;
258    U32 device           :8;
259    U32 lba_low_exp      :8;   // word 2
260    U32 lba_mid_exp      :8;
261    U32 lba_high_exp     :8;
262    U32 reserved         :8;
263    U32 sector_count     :8;   // word 3
264    U32 sector_count_exp :8;
265    U32 reserved1        :8;
266    U32 ending_status    :8;
267    U32 transfter_count  :16;  // word 4
268    U32 reserved3        :16;
269 } SATA_FIS_PIO_SETUP_T;
270 
271 /**
272  * @struct SATA_FIS_DATA
273  *
274  * @brief SATA Data FIS
275  */
276 typedef struct SATA_FIS_DATA
277 {
278    U32 fis_type      :8;   // word 0
279    U32 pm_port       :4;
280    U32 reserved0     :24;
281    U8  data[4];            // word 1
282 } SATA_FIS_DATA_T;
283 
284 #endif // _SATA_H_
285