xref: /freebsd/sys/dev/isci/scil/scic_sds_stp_request.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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 _SCIC_SDS_STP_REQUEST_T_
55 #define _SCIC_SDS_STP_REQUEST_T_
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif // __cplusplus
60 
61 #include <dev/isci/scil/intel_sata.h>
62 #include <dev/isci/scil/sci_types.h>
63 #include <dev/isci/scil/scic_sds_request.h>
64 
65 /**
66  * @struct
67  *
68  * @brief This structure represents the additional information that is
69  *        required to handle SATA PIO requests.
70  */
71 typedef struct SCIC_SDS_STP_REQUEST
72 {
73    SCIC_SDS_REQUEST_T parent;
74 
75    SATA_FIS_REG_D2H_T d2h_reg_fis;
76 
77    union
78    {
79       U32 ncq;
80 
81       U32 udma;
82 
83       struct
84       {
85          /**
86           * Total transfer for the entire PIO request recorded at request construction
87           * time.
88           *
89           * @todo Should we just decrement this value for each byte of data transitted
90           *       or received to elemenate the current_transfer_bytes field?
91           */
92          U32 total_transfer_bytes;
93 
94          /**
95           * Total number of bytes received/transmitted in data frames since the start
96           * of the IO request.  At the end of the IO request this should equal the
97           * total_transfer_bytes.
98           */
99          U32 current_transfer_bytes;
100 
101          /**
102           * The number of bytes requested in the in the PIO setup.
103           */
104          U32 pio_transfer_bytes;
105 
106          /**
107           * PIO Setup ending status value to tell us if we need to wait for another FIS
108           * or if the transfer is complete. On the receipt of a D2H FIS this will be
109           * the status field of that FIS.
110           */
111          U8  ending_status;
112 
113          /**
114           * On receipt of a D2H FIS this will be the ending error field if the
115           * ending_status has the SATA_STATUS_ERR bit set.
116           */
117          U8  ending_error;
118 
119          /**
120           * Protocol Type. This is filled in by core during IO Request construction type.
121           */
122          U8  sat_protocol;
123 
124          /**
125          * This field keeps track of sgl pair to be retrieved from OS memory for processing.
126          */
127          U8  sgl_pair_index;
128 
129          struct
130          {
131             SCU_SGL_ELEMENT_PAIR_T * sgl_pair;
132             U8                       sgl_set;
133             U32                      sgl_offset;
134          } request_current;
135       } pio;
136 
137       struct
138       {
139          /**
140           * The number of bytes requested in the PIO setup before CDB data frame.
141           */
142          U32 device_preferred_cdb_length;
143       } packet;
144    } type;
145 
146 } SCIC_SDS_STP_REQUEST_T;
147 
148 /**
149  * @enum SCIC_SDS_STP_REQUEST_STARTED_UDMA_SUBSTATES
150  *
151  * @brief This enumeration depicts the various sub-states associated with
152  *        a SATA/STP UDMA protocol operation.
153  */
154 enum SCIC_SDS_STP_REQUEST_STARTED_UDMA_SUBSTATES
155 {
156    SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE,
157    SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE,
158 
159    SCIC_SDS_STP_REQUEST_STARTED_UDMA_MAX_SUBSTATES
160 };
161 
162 /**
163  * @enum SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_SUBSTATES
164  *
165  * @brief This enumeration depicts the various sub-states associated with
166  *        a SATA/STP non-data protocol operation.
167  */
168 enum SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_SUBSTATES
169 {
170    SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE,
171    SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE,
172    SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_MAX_SUBSTATES
173 };
174 
175 /**
176  * @enum SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_SUBSTATES
177  *
178  * @brief THis enumeration depicts the various sub-states associated with a
179  *        SATA/STP soft reset operation.
180  */
181 enum SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_SUBSTATES
182 {
183    SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE,
184    SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE,
185    SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE,
186 
187    SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_MAX_SUBSTATES
188 };
189 
190 extern SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
191    scic_sds_stp_request_started_udma_substate_handler_table
192       [SCIC_SDS_STP_REQUEST_STARTED_UDMA_MAX_SUBSTATES];
193 
194 extern SCI_BASE_STATE_T
195    scic_sds_stp_request_started_udma_substate_table
196       [SCIC_SDS_STP_REQUEST_STARTED_UDMA_MAX_SUBSTATES];
197 
198 extern SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
199    scic_sds_stp_request_started_non_data_substate_handler_table
200       [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_MAX_SUBSTATES];
201 
202 extern SCI_BASE_STATE_T
203    scic_sds_stp_request_started_non_data_substate_table
204       [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_MAX_SUBSTATES];
205 
206 
207 extern SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
208    scic_sds_stp_request_started_soft_reset_substate_handler_table
209       [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_MAX_SUBSTATES];
210 
211 extern SCI_BASE_STATE_T
212    scic_sds_stp_request_started_soft_reset_substate_table
213       [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_MAX_SUBSTATES];
214 
215 // ---------------------------------------------------------------------------
216 
217 U32 scic_sds_stp_request_get_object_size(void);
218 
219 U32 scic_sds_stp_task_request_get_object_size(void);
220 
221 void scu_sata_reqeust_construct_task_context(
222    SCIC_SDS_REQUEST_T * this_request,
223    SCU_TASK_CONTEXT_T * task_context
224 );
225 
226 void scic_sds_stp_non_ncq_request_construct(
227    SCIC_SDS_REQUEST_T *this_request
228 );
229 
230 SCI_STATUS scic_sds_stp_pio_request_construct(
231    SCIC_SDS_REQUEST_T  * scic_io_request,
232    U8                    sat_protocol,
233    BOOL                  copy_rx_frame
234 );
235 
236 SCI_STATUS scic_sds_stp_pio_request_construct_pass_through (
237    SCIC_SDS_REQUEST_T  * scic_io_request,
238    SCIC_STP_PASSTHRU_REQUEST_CALLBACKS_T *passthru_cb
239 );
240 
241 SCI_STATUS scic_sds_stp_udma_request_construct(
242    SCIC_SDS_REQUEST_T * this_request,
243    U32 transfer_length,
244    SCI_IO_REQUEST_DATA_DIRECTION data_direction
245 );
246 
247 SCI_STATUS scic_sds_stp_non_data_request_construct(
248    SCIC_SDS_REQUEST_T * this_request
249 );
250 
251 SCI_STATUS scic_sds_stp_soft_reset_request_construct(
252    SCIC_SDS_REQUEST_T * this_request
253 );
254 
255 SCI_STATUS scic_sds_stp_ncq_request_construct(
256    SCIC_SDS_REQUEST_T * this_request,
257    U32 transfer_length,
258    SCI_IO_REQUEST_DATA_DIRECTION data_direction
259 );
260 
261 void scu_stp_raw_request_construct_task_context(
262    SCIC_SDS_STP_REQUEST_T * this_request,
263    SCU_TASK_CONTEXT_T     * task_context
264 
265 );
266 
267 SCI_STATUS scic_sds_io_request_construct_sata(
268    SCIC_SDS_REQUEST_T          * this_request,
269    U8                            sat_protocol,
270    U32                           transfer_length,
271    SCI_IO_REQUEST_DATA_DIRECTION data_direction,
272    BOOL                          copy_rx_frame,
273    BOOL                          do_translate_sgl
274 );
275 
276 #ifdef __cplusplus
277 }
278 #endif // __cplusplus
279 
280 #endif // _SCIC_SDS_STP_REQUEST_T_
281