xref: /freebsd/sys/dev/isci/scil/scic_sds_remote_device.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1f11c7f63SJim Harris /*-
2718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3718cf2ccSPedro F. Giffuni  *
4f11c7f63SJim Harris  * This file is provided under a dual BSD/GPLv2 license.  When using or
5f11c7f63SJim Harris  * redistributing this file, you may do so under either license.
6f11c7f63SJim Harris  *
7f11c7f63SJim Harris  * GPL LICENSE SUMMARY
8f11c7f63SJim Harris  *
9f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
10f11c7f63SJim Harris  *
11f11c7f63SJim Harris  * This program is free software; you can redistribute it and/or modify
12f11c7f63SJim Harris  * it under the terms of version 2 of the GNU General Public License as
13f11c7f63SJim Harris  * published by the Free Software Foundation.
14f11c7f63SJim Harris  *
15f11c7f63SJim Harris  * This program is distributed in the hope that it will be useful, but
16f11c7f63SJim Harris  * WITHOUT ANY WARRANTY; without even the implied warranty of
17f11c7f63SJim Harris  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18f11c7f63SJim Harris  * General Public License for more details.
19f11c7f63SJim Harris  *
20f11c7f63SJim Harris  * You should have received a copy of the GNU General Public License
21f11c7f63SJim Harris  * along with this program; if not, write to the Free Software
22f11c7f63SJim Harris  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23f11c7f63SJim Harris  * The full GNU General Public License is included in this distribution
24f11c7f63SJim Harris  * in the file called LICENSE.GPL.
25f11c7f63SJim Harris  *
26f11c7f63SJim Harris  * BSD LICENSE
27f11c7f63SJim Harris  *
28f11c7f63SJim Harris  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29f11c7f63SJim Harris  * All rights reserved.
30f11c7f63SJim Harris  *
31f11c7f63SJim Harris  * Redistribution and use in source and binary forms, with or without
32f11c7f63SJim Harris  * modification, are permitted provided that the following conditions
33f11c7f63SJim Harris  * are met:
34f11c7f63SJim Harris  *
35f11c7f63SJim Harris  *   * Redistributions of source code must retain the above copyright
36f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer.
37f11c7f63SJim Harris  *   * Redistributions in binary form must reproduce the above copyright
38f11c7f63SJim Harris  *     notice, this list of conditions and the following disclaimer in
39f11c7f63SJim Harris  *     the documentation and/or other materials provided with the
40f11c7f63SJim Harris  *     distribution.
41f11c7f63SJim Harris  *
42f11c7f63SJim Harris  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43f11c7f63SJim Harris  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44f11c7f63SJim Harris  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45f11c7f63SJim Harris  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46f11c7f63SJim Harris  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47f11c7f63SJim Harris  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48f11c7f63SJim Harris  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49f11c7f63SJim Harris  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50f11c7f63SJim Harris  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51f11c7f63SJim Harris  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52f11c7f63SJim Harris  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53f11c7f63SJim Harris  */
54f11c7f63SJim Harris #ifndef _SCIC_SDS_REMOTE_DEVICE_H_
55f11c7f63SJim Harris #define _SCIC_SDS_REMOTE_DEVICE_H_
56f11c7f63SJim Harris 
57f11c7f63SJim Harris /**
58f11c7f63SJim Harris  * @file
59f11c7f63SJim Harris  *
60f11c7f63SJim Harris  * @brief This file contains the structures, constants, and prototypes for the
61f11c7f63SJim Harris  *        SCIC_SDS_REMOTE_DEVICE object.
62f11c7f63SJim Harris  */
63f11c7f63SJim Harris 
64f11c7f63SJim Harris #ifdef __cplusplus
65f11c7f63SJim Harris extern "C" {
66f11c7f63SJim Harris #endif // __cplusplus
67f11c7f63SJim Harris 
68f11c7f63SJim Harris #include <dev/isci/scil/intel_sas.h>
69f11c7f63SJim Harris #include <dev/isci/scil/sci_base_remote_device.h>
70f11c7f63SJim Harris #include <dev/isci/scil/sci_base_request.h>
71f11c7f63SJim Harris #include <dev/isci/scil/sci_base_state_machine_logger.h>
72f11c7f63SJim Harris #include <dev/isci/scil/scu_remote_node_context.h>
73f11c7f63SJim Harris #include <dev/isci/scil/scic_sds_remote_node_context.h>
74f11c7f63SJim Harris 
75f11c7f63SJim Harris struct SCIC_SDS_CONTROLLER;
76f11c7f63SJim Harris struct SCIC_SDS_PORT;
77f11c7f63SJim Harris struct SCIC_SDS_REQUEST;
78f11c7f63SJim Harris struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER;
79f11c7f63SJim Harris 
80f11c7f63SJim Harris /**
81f11c7f63SJim Harris  * @enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES
82f11c7f63SJim Harris  *
83f11c7f63SJim Harris  * This is the enumeration of the ready substates for the
84f11c7f63SJim Harris  * SCIC_SDS_REMOTE_DEVICE.
85f11c7f63SJim Harris  */
86f11c7f63SJim Harris enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES
87f11c7f63SJim Harris {
88f11c7f63SJim Harris    /**
89f11c7f63SJim Harris     * This is the initial state for the remote device ready substate.
90f11c7f63SJim Harris     */
91f11c7f63SJim Harris    SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_INITIAL,
92f11c7f63SJim Harris 
93f11c7f63SJim Harris    /**
94f11c7f63SJim Harris     * This is the ready operational substate for the remote device.  This is the
95f11c7f63SJim Harris     * normal operational state for a remote device.
96f11c7f63SJim Harris     */
97f11c7f63SJim Harris    SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_OPERATIONAL,
98f11c7f63SJim Harris 
99f11c7f63SJim Harris    /**
100f11c7f63SJim Harris     * This is the suspended state for the remote device.  This is the state that
101f11c7f63SJim Harris     * the device is placed in when a RNC suspend is received by the SCU hardware.
102f11c7f63SJim Harris     */
103f11c7f63SJim Harris    SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_SUSPENDED,
104f11c7f63SJim Harris 
105f11c7f63SJim Harris    /**
106f11c7f63SJim Harris     * This is the final state that the device is placed in before a change to the
107f11c7f63SJim Harris     * base state machine.
108f11c7f63SJim Harris     */
109f11c7f63SJim Harris    SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_FINAL,
110f11c7f63SJim Harris 
111f11c7f63SJim Harris    SCIC_SDS_SSP_REMOTE_DEVICE_READY_MAX_SUBSTATES
112f11c7f63SJim Harris };
113f11c7f63SJim Harris 
114f11c7f63SJim Harris /**
115f11c7f63SJim Harris  * @enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES
116f11c7f63SJim Harris  *
117f11c7f63SJim Harris  * This is the enumeration for the SCIC_SDS_REMOTE_DEVICE ready substates for
118f11c7f63SJim Harris  * the STP remote device.
119f11c7f63SJim Harris  */
120f11c7f63SJim Harris enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES
121f11c7f63SJim Harris {
122f11c7f63SJim Harris    /**
123f11c7f63SJim Harris     * This is the idle substate for the stp remote device.  When there are no
1240af1b472SEitan Adler     * active IO for the device it is in this state.
125f11c7f63SJim Harris     */
126f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
127f11c7f63SJim Harris 
128f11c7f63SJim Harris    /**
12910df4dc7SGordon Bergling     * This is the command state for the STP remote device.  This state is
130f11c7f63SJim Harris     * entered when the device is processing a non-NCQ command.  The device object
131f11c7f63SJim Harris     * will fail any new start IO requests until this command is complete.
132f11c7f63SJim Harris     */
133f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
134f11c7f63SJim Harris 
135f11c7f63SJim Harris    /**
136f11c7f63SJim Harris     * This is the NCQ state for the STP remote device.  This state is entered
137*be51810fSGordon Bergling     * when the device is processing an NCQ request.  It will remain in this state
138f11c7f63SJim Harris     * so long as there is one or more NCQ requests being processed.
139f11c7f63SJim Harris     */
140f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ,
141f11c7f63SJim Harris 
142f11c7f63SJim Harris    /**
143f11c7f63SJim Harris     * This is the NCQ error state for the STP remote device.  This state is
144f11c7f63SJim Harris     * entered when an SDB error FIS is received by the device object while in the
145f11c7f63SJim Harris     * NCQ state.  The device object will only accept a READ LOG command while in
146f11c7f63SJim Harris     * this state.
147f11c7f63SJim Harris     */
148f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR,
149f11c7f63SJim Harris 
150f11c7f63SJim Harris #if !defined(DISABLE_ATAPI)
151f11c7f63SJim Harris    /**
152f11c7f63SJim Harris     * This is the ATAPI error state for the STP ATAPI remote device.  This state is
153f11c7f63SJim Harris     * entered when ATAPI device sends error status FIS without data while the device
154f11c7f63SJim Harris     * object is in CMD state. A suspension event is expected in this state. The device
155f11c7f63SJim Harris     * object will resume right away.
156f11c7f63SJim Harris     */
157f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR,
158f11c7f63SJim Harris #endif
159f11c7f63SJim Harris 
160f11c7f63SJim Harris    /**
161f11c7f63SJim Harris     * This is the READY substate indicates the device is waiting for the RESET task
162f11c7f63SJim Harris     * coming to be recovered from certain hardware specific error.
163f11c7f63SJim Harris     */
164f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET,
165f11c7f63SJim Harris 
166f11c7f63SJim Harris    SCIC_SDS_STP_REMOTE_DEVICE_READY_MAX_SUBSTATES
167f11c7f63SJim Harris };
168f11c7f63SJim Harris 
169f11c7f63SJim Harris 
170f11c7f63SJim Harris /**
171f11c7f63SJim Harris  * @enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES
172f11c7f63SJim Harris  *
173f11c7f63SJim Harris  * This is the enumeration of the ready substates for the SMP REMOTE DEVICE.
174f11c7f63SJim Harris  */
175f11c7f63SJim Harris 
176f11c7f63SJim Harris enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES
177f11c7f63SJim Harris {
178f11c7f63SJim Harris    /**
179f11c7f63SJim Harris     * This is the ready operational substate for the remote device.  This is the
180f11c7f63SJim Harris     * normal operational state for a remote device.
181f11c7f63SJim Harris     */
182f11c7f63SJim Harris    SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
183f11c7f63SJim Harris 
184f11c7f63SJim Harris    /**
185f11c7f63SJim Harris     * This is the suspended state for the remote device.  This is the state that
186f11c7f63SJim Harris     * the device is placed in when a RNC suspend is received by the SCU hardware.
187f11c7f63SJim Harris     */
188f11c7f63SJim Harris    SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
189f11c7f63SJim Harris 
190f11c7f63SJim Harris    SCIC_SDS_SMP_REMOTE_DEVICE_READY_MAX_SUBSTATES
191f11c7f63SJim Harris };
192f11c7f63SJim Harris 
193f11c7f63SJim Harris 
194f11c7f63SJim Harris 
195f11c7f63SJim Harris 
196f11c7f63SJim Harris /**
197f11c7f63SJim Harris  * @struct SCIC_SDS_REMOTE_DEVICE
198f11c7f63SJim Harris  *
199f11c7f63SJim Harris  * @brief  This structure contains the data for an SCU implementation of
200f11c7f63SJim Harris  *         the SCU Core device data.
201f11c7f63SJim Harris  */
202f11c7f63SJim Harris typedef struct SCIC_SDS_REMOTE_DEVICE
203f11c7f63SJim Harris {
204f11c7f63SJim Harris    /**
205f11c7f63SJim Harris     * This field is the common base for all remote device objects.
206f11c7f63SJim Harris     */
207f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T parent;
208f11c7f63SJim Harris 
209f11c7f63SJim Harris    /**
210f11c7f63SJim Harris     * This field is the programmed device port width.  This value is written to
211f11c7f63SJim Harris     * the RCN data structure to tell the SCU how many open connections this
212f11c7f63SJim Harris     * device can have.
213f11c7f63SJim Harris     */
214f11c7f63SJim Harris    U32 device_port_width;
215f11c7f63SJim Harris 
216f11c7f63SJim Harris    /**
217f11c7f63SJim Harris     * This field is the programmed connection rate for this remote device.  It is
218f11c7f63SJim Harris     * used to program the TC with the maximum allowed connection rate.
219f11c7f63SJim Harris     */
220f11c7f63SJim Harris    SCI_SAS_LINK_RATE connection_rate;
221f11c7f63SJim Harris 
222f11c7f63SJim Harris    /**
223f11c7f63SJim Harris     * This field contains the allowed target protocols for this remote device.
224f11c7f63SJim Harris     */
225f11c7f63SJim Harris    SMP_DISCOVER_RESPONSE_PROTOCOLS_T target_protocols;
226f11c7f63SJim Harris 
227f11c7f63SJim Harris    /**
228f11c7f63SJim Harris     * This field contains the device SAS address.
229f11c7f63SJim Harris     */
230f11c7f63SJim Harris    SCI_SAS_ADDRESS_T device_address;
231f11c7f63SJim Harris 
232f11c7f63SJim Harris    /**
233816d5c1eSGordon Bergling     * This filed is assigned the value of TRUE if the device is directly attached
234f11c7f63SJim Harris     * to the port.
235f11c7f63SJim Harris     */
236f11c7f63SJim Harris    BOOL is_direct_attached;
237f11c7f63SJim Harris 
238f11c7f63SJim Harris #if !defined(DISABLE_ATAPI)
239f11c7f63SJim Harris    /**
240816d5c1eSGordon Bergling     * This filed is assigned the value of TRUE if the device is an ATAPI device.
241f11c7f63SJim Harris     */
242f11c7f63SJim Harris    BOOL is_atapi;
243f11c7f63SJim Harris #endif
244f11c7f63SJim Harris 
245f11c7f63SJim Harris    /**
246f11c7f63SJim Harris     * This filed contains a pointer back to the port to which this device is
247f11c7f63SJim Harris     * assigned.
248f11c7f63SJim Harris     */
249f11c7f63SJim Harris    struct SCIC_SDS_PORT *owning_port;
250f11c7f63SJim Harris 
251f11c7f63SJim Harris    /**
252f11c7f63SJim Harris     * This field contains the SCU silicon remote node context specific
253f11c7f63SJim Harris     * information.
254f11c7f63SJim Harris     */
255f11c7f63SJim Harris    struct SCIC_SDS_REMOTE_NODE_CONTEXT * rnc;
256f11c7f63SJim Harris 
257f11c7f63SJim Harris    /**
258f11c7f63SJim Harris     * This field contains the stated request count for the remote device.  The
259f11c7f63SJim Harris     * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all
260f11c7f63SJim Harris     * requests are complete and the rnc_posted value is FALSE.
261f11c7f63SJim Harris     */
262f11c7f63SJim Harris    U32 started_request_count;
263f11c7f63SJim Harris 
264f11c7f63SJim Harris    /**
265f11c7f63SJim Harris     * This field contains a pointer to the working request object.  It is only
266f11c7f63SJim Harris     * used only for SATA requests since the unsolicited frames we get from the
267f11c7f63SJim Harris     * hardware have no Tag value to look up the io request object.
268f11c7f63SJim Harris     */
269f11c7f63SJim Harris    struct SCIC_SDS_REQUEST * working_request;
270f11c7f63SJim Harris 
271f11c7f63SJim Harris    /**
272f11c7f63SJim Harris     * This field contains the reason for the remote device going not_ready.  It is
273f11c7f63SJim Harris     * assigned in the state handlers and used in the state transition.
274f11c7f63SJim Harris     */
275f11c7f63SJim Harris    U32 not_ready_reason;
276f11c7f63SJim Harris 
277f11c7f63SJim Harris    /**
278b61c7c2dSGordon Bergling     * This field is TRUE if this remote device has an initialized ready substate
279f11c7f63SJim Harris     * machine. SSP devices do not have a ready substate machine and STP devices
280f11c7f63SJim Harris     * have a ready substate machine.
281f11c7f63SJim Harris     */
282f11c7f63SJim Harris    BOOL has_ready_substate_machine;
283f11c7f63SJim Harris 
284f11c7f63SJim Harris    /**
285f11c7f63SJim Harris     * This field contains the state machine for the ready substate machine for
286f11c7f63SJim Harris     * this SCIC_SDS_REMOTE_DEVICE object.
287f11c7f63SJim Harris     */
288f11c7f63SJim Harris    SCI_BASE_STATE_MACHINE_T ready_substate_machine;
289f11c7f63SJim Harris 
290f11c7f63SJim Harris    /**
291f11c7f63SJim Harris     * This field maintains the set of state handlers for the remote device
292f11c7f63SJim Harris     * object.  These are changed each time the remote device enters a new state.
293f11c7f63SJim Harris     */
294f11c7f63SJim Harris    struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER *state_handlers;
295f11c7f63SJim Harris 
296f11c7f63SJim Harris    #ifdef SCI_LOGGING
297f11c7f63SJim Harris    /**
298f11c7f63SJim Harris     * This field conatins the ready substate machine logger.  The logger will
299f11c7f63SJim Harris     * emit a message each time the ready substate machine changes state.
300f11c7f63SJim Harris     */
301f11c7f63SJim Harris    SCI_BASE_STATE_MACHINE_LOGGER_T ready_substate_machine_logger;
302f11c7f63SJim Harris    #endif
303f11c7f63SJim Harris 
304f11c7f63SJim Harris } SCIC_SDS_REMOTE_DEVICE_T;
305f11c7f63SJim Harris 
306f11c7f63SJim Harris 
307f11c7f63SJim Harris typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_HANDLER_T)(
308f11c7f63SJim Harris                                  SCIC_SDS_REMOTE_DEVICE_T *this_device);
309f11c7f63SJim Harris 
310f11c7f63SJim Harris typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T)(
311f11c7f63SJim Harris                                  SCIC_SDS_REMOTE_DEVICE_T *this_device,
312f11c7f63SJim Harris                                  U32                       suspend_type);
313f11c7f63SJim Harris 
314f11c7f63SJim Harris typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T)(
315f11c7f63SJim Harris                                  SCIC_SDS_REMOTE_DEVICE_T *this_device);
316f11c7f63SJim Harris 
317f11c7f63SJim Harris typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T)(
318f11c7f63SJim Harris                                   SCIC_SDS_REMOTE_DEVICE_T *this_device,
319f11c7f63SJim Harris                                   U32                       frame_index);
320f11c7f63SJim Harris 
321f11c7f63SJim Harris typedef SCI_STATUS (*SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T)(
322f11c7f63SJim Harris                                   SCIC_SDS_REMOTE_DEVICE_T *this_device,
323f11c7f63SJim Harris                                   U32                       event_code);
324f11c7f63SJim Harris 
325f11c7f63SJim Harris typedef void (*SCIC_SDS_REMOTE_DEVICE_READY_NOT_READY_HANDLER_T)(
326f11c7f63SJim Harris                                   SCIC_SDS_REMOTE_DEVICE_T *this_device);
327f11c7f63SJim Harris 
328f11c7f63SJim Harris /**
329f11c7f63SJim Harris  * @struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER
330f11c7f63SJim Harris  * @brief This structure conains the state handlers that are needed to
331f11c7f63SJim Harris  *        process requests for the SCU remote device objects.
332f11c7f63SJim Harris  */
333f11c7f63SJim Harris typedef struct SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER
334f11c7f63SJim Harris {
335f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_STATE_HANDLER_T parent;
336f11c7f63SJim Harris 
337f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T suspend_handler;
338f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T  resume_handler;
339f11c7f63SJim Harris 
340f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T event_handler;
341f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T frame_handler;
342f11c7f63SJim Harris 
343f11c7f63SJim Harris } SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T;
344f11c7f63SJim Harris 
345f11c7f63SJim Harris 
346f11c7f63SJim Harris extern SCI_BASE_STATE_T scic_sds_remote_device_state_table[];
347f11c7f63SJim Harris extern SCI_BASE_STATE_T scic_sds_ssp_remote_device_ready_substate_table[];
348f11c7f63SJim Harris extern SCI_BASE_STATE_T scic_sds_stp_remote_device_ready_substate_table[];
349f11c7f63SJim Harris extern SCI_BASE_STATE_T scic_sds_smp_remote_device_ready_substate_table[];
350f11c7f63SJim Harris 
351f11c7f63SJim Harris extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
352f11c7f63SJim Harris                scic_sds_remote_device_state_handler_table[];
353f11c7f63SJim Harris extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
354f11c7f63SJim Harris                scic_sds_ssp_remote_device_ready_substate_handler_table[];
355f11c7f63SJim Harris extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
356f11c7f63SJim Harris                scic_sds_stp_remote_device_ready_substate_handler_table[];
357f11c7f63SJim Harris extern SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
358f11c7f63SJim Harris                scic_sds_smp_remote_device_ready_substate_handler_table[];
359f11c7f63SJim Harris 
360f11c7f63SJim Harris /**
361f11c7f63SJim Harris  * This macro incrments the request count for this device
362f11c7f63SJim Harris  */
363f11c7f63SJim Harris #define scic_sds_remote_device_increment_request_count(this_device) \
364f11c7f63SJim Harris    ((this_device)->started_request_count++)
365f11c7f63SJim Harris 
366f11c7f63SJim Harris /**
367f11c7f63SJim Harris  * This macro decrements the request count for this device.  This count
368f11c7f63SJim Harris  * will never decrment past 0.
369f11c7f63SJim Harris  */
370f11c7f63SJim Harris #define scic_sds_remote_device_decrement_request_count(this_device) \
371f11c7f63SJim Harris    ((this_device)->started_request_count > 0 ? \
372f11c7f63SJim Harris       (this_device)->started_request_count-- : 0)
373f11c7f63SJim Harris 
374f11c7f63SJim Harris /**
375f11c7f63SJim Harris  * This is a helper macro to return the current device request count.
376f11c7f63SJim Harris  */
377f11c7f63SJim Harris #define scic_sds_remote_device_get_request_count(this_device) \
378f11c7f63SJim Harris    ((this_device)->started_request_count)
379f11c7f63SJim Harris 
380f11c7f63SJim Harris /**
381f11c7f63SJim Harris  * This macro returns the owning port of this remote device obejct.
382f11c7f63SJim Harris  */
383f11c7f63SJim Harris #define scic_sds_remote_device_get_port(this_device) \
384f11c7f63SJim Harris    ((this_device)->owning_port)
385f11c7f63SJim Harris 
386f11c7f63SJim Harris /**
387f11c7f63SJim Harris  * This macro returns the controller object that contains this device
388f11c7f63SJim Harris  * object
389f11c7f63SJim Harris  */
390f11c7f63SJim Harris #define scic_sds_remote_device_get_controller(this_device) \
391f11c7f63SJim Harris    scic_sds_port_get_controller(scic_sds_remote_device_get_port(this_device))
392f11c7f63SJim Harris 
393f11c7f63SJim Harris /**
394f11c7f63SJim Harris  * This macro sets the remote device state handlers pointer and is set on
395f11c7f63SJim Harris  * entry to each device state.
396f11c7f63SJim Harris  */
397f11c7f63SJim Harris #define scic_sds_remote_device_set_state_handlers(this_device, handlers) \
398f11c7f63SJim Harris    ((this_device)->state_handlers = (handlers))
399f11c7f63SJim Harris 
400f11c7f63SJim Harris /**
401f11c7f63SJim Harris  * This macro returns the base sate machine object for the remote device.
402f11c7f63SJim Harris  */
403f11c7f63SJim Harris #define scic_sds_remote_device_get_base_state_machine(this_device) \
404f11c7f63SJim Harris    (&(this_device)->parent.state_machine)
405f11c7f63SJim Harris 
406f11c7f63SJim Harris /**
407f11c7f63SJim Harris  * This macro returns the remote device ready substate machine
408f11c7f63SJim Harris  */
409f11c7f63SJim Harris #define scic_sds_remote_device_get_ready_substate_machine(this_device) \
410f11c7f63SJim Harris    (&(this_device)->ready_substate_machine)
411f11c7f63SJim Harris 
412f11c7f63SJim Harris /**
413f11c7f63SJim Harris  * This macro returns the owning port of this device
414f11c7f63SJim Harris  */
415f11c7f63SJim Harris #define scic_sds_remote_device_get_port(this_device) \
416f11c7f63SJim Harris    ((this_device)->owning_port)
417f11c7f63SJim Harris 
418f11c7f63SJim Harris /**
419f11c7f63SJim Harris  * This macro returns the remote device sequence value
420f11c7f63SJim Harris  */
421f11c7f63SJim Harris #define scic_sds_remote_device_get_sequence(this_device) \
422f11c7f63SJim Harris    ( \
423f11c7f63SJim Harris       scic_sds_remote_device_get_controller(this_device)->\
424f11c7f63SJim Harris          remote_device_sequence[(this_device)->rnc->remote_node_index] \
425f11c7f63SJim Harris    )
426f11c7f63SJim Harris 
427f11c7f63SJim Harris /**
428f11c7f63SJim Harris  * This macro returns the controllers protocol engine group
429f11c7f63SJim Harris  */
430f11c7f63SJim Harris #define scic_sds_remote_device_get_controller_peg(this_device) \
431f11c7f63SJim Harris    ( \
432f11c7f63SJim Harris       scic_sds_controller_get_protocol_engine_group( \
433f11c7f63SJim Harris          scic_sds_port_get_controller( \
434f11c7f63SJim Harris             scic_sds_remote_device_get_port(this_device) \
435f11c7f63SJim Harris          ) \
436f11c7f63SJim Harris       ) \
437f11c7f63SJim Harris    )
438f11c7f63SJim Harris 
439f11c7f63SJim Harris /**
440f11c7f63SJim Harris  * This macro returns the port index for the devices owning port
441f11c7f63SJim Harris  */
442f11c7f63SJim Harris #define scic_sds_remote_device_get_port_index(this_device) \
443f11c7f63SJim Harris    (scic_sds_port_get_index(scic_sds_remote_device_get_port(this_device)))
444f11c7f63SJim Harris 
445f11c7f63SJim Harris /**
446f11c7f63SJim Harris  * This macro returns the remote node index for this device object
447f11c7f63SJim Harris  */
448f11c7f63SJim Harris #define scic_sds_remote_device_get_index(this_device) \
449f11c7f63SJim Harris    ((this_device)->rnc->remote_node_index)
450f11c7f63SJim Harris 
451f11c7f63SJim Harris /**
452f11c7f63SJim Harris  * This macro builds a remote device context for the SCU post request
453f11c7f63SJim Harris  * operation
454f11c7f63SJim Harris  */
455f11c7f63SJim Harris #define scic_sds_remote_device_build_command_context(device, command) \
456f11c7f63SJim Harris    (   (command) \
457f11c7f63SJim Harris      | ((U32)(scic_sds_remote_device_get_controller_peg((device))) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT)\
458f11c7f63SJim Harris      | ((U32)(scic_sds_remote_device_get_port_index((device))) << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
459f11c7f63SJim Harris      | (scic_sds_remote_device_get_index((device))) \
460f11c7f63SJim Harris    )
461f11c7f63SJim Harris 
462f11c7f63SJim Harris /**
463f11c7f63SJim Harris  * This macro makes the working request assingment for the remote device
464f11c7f63SJim Harris  * object. To clear the working request use this macro with a NULL request
465f11c7f63SJim Harris  * object.
466f11c7f63SJim Harris  */
467f11c7f63SJim Harris #define scic_sds_remote_device_set_working_request(device, request) \
468f11c7f63SJim Harris    ((device)->working_request = (request))
469f11c7f63SJim Harris 
470f11c7f63SJim Harris // ---------------------------------------------------------------------------
471f11c7f63SJim Harris 
472f11c7f63SJim Harris U32 scic_sds_remote_device_get_min_timer_count(void);
473f11c7f63SJim Harris 
474f11c7f63SJim Harris U32 scic_sds_remote_device_get_max_timer_count(void);
475f11c7f63SJim Harris 
476f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_frame_handler(
477f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
478f11c7f63SJim Harris    U32                       frame_index
479f11c7f63SJim Harris );
480f11c7f63SJim Harris 
481f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_event_handler(
482f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
483f11c7f63SJim Harris    U32                       event_code
484f11c7f63SJim Harris );
485f11c7f63SJim Harris 
486f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_start_io(
487f11c7f63SJim Harris    struct SCIC_SDS_CONTROLLER *controller,
488f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T   *this_device,
489f11c7f63SJim Harris    struct SCIC_SDS_REQUEST    *io_request
490f11c7f63SJim Harris );
491f11c7f63SJim Harris 
492f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_complete_io(
493f11c7f63SJim Harris    struct SCIC_SDS_CONTROLLER *controller,
494f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T   *this_device,
495f11c7f63SJim Harris    struct SCIC_SDS_REQUEST    *io_request
496f11c7f63SJim Harris );
497f11c7f63SJim Harris 
498f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_resume(
499f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device
500f11c7f63SJim Harris );
501f11c7f63SJim Harris 
502f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_suspend(
503f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
504f11c7f63SJim Harris    U32                       suspend_type
505f11c7f63SJim Harris );
506f11c7f63SJim Harris 
507f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_start_task(
508f11c7f63SJim Harris    struct SCIC_SDS_CONTROLLER  *controller,
509f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T    *this_device,
510f11c7f63SJim Harris    struct SCIC_SDS_REQUEST     *io_request
511f11c7f63SJim Harris );
512f11c7f63SJim Harris 
513f11c7f63SJim Harris void scic_sds_remote_device_post_request(
514f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T * this_device,
515f11c7f63SJim Harris    U32                        request
516f11c7f63SJim Harris );
517f11c7f63SJim Harris 
518f11c7f63SJim Harris #if !defined(DISABLE_ATAPI)
519f11c7f63SJim Harris BOOL scic_sds_remote_device_is_atapi(
520f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T    *this_device
521f11c7f63SJim Harris );
522f11c7f63SJim Harris #else // !defined(DISABLE_ATAPI)
523f11c7f63SJim Harris #define scic_sds_remote_device_is_atapi(this_device) FALSE
524f11c7f63SJim Harris #endif // !defined(DISABLE_ATAPI)
525f11c7f63SJim Harris 
526f11c7f63SJim Harris // ---------------------------------------------------------------------------
527f11c7f63SJim Harris 
528f11c7f63SJim Harris #ifdef SCI_LOGGING
529f11c7f63SJim Harris void scic_sds_remote_device_initialize_state_logging(
530f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device
531f11c7f63SJim Harris );
532f11c7f63SJim Harris 
533f11c7f63SJim Harris void scic_sds_remote_device_deinitialize_state_logging(
534f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device
535f11c7f63SJim Harris );
536f11c7f63SJim Harris #else // SCI_LOGGING
537f11c7f63SJim Harris #define scic_sds_remote_device_initialize_state_logging(x)
538f11c7f63SJim Harris #define scic_sds_remote_device_deinitialize_state_logging(x)
539f11c7f63SJim Harris #endif // SCI_LOGGING
540f11c7f63SJim Harris 
541f11c7f63SJim Harris // ---------------------------------------------------------------------------
542f11c7f63SJim Harris 
543f11c7f63SJim Harris void scic_sds_remote_device_start_request(
544f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T * this_device,
545f11c7f63SJim Harris    struct SCIC_SDS_REQUEST  * the_request,
546f11c7f63SJim Harris    SCI_STATUS                 status
547f11c7f63SJim Harris );
548f11c7f63SJim Harris 
549f11c7f63SJim Harris void scic_sds_remote_device_continue_request(
550f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T * this_device
551f11c7f63SJim Harris );
552f11c7f63SJim Harris 
553f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_start_handler(
554f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *this_device
555f11c7f63SJim Harris );
556f11c7f63SJim Harris 
557f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_stop_handler(
558f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *this_device
559f11c7f63SJim Harris );
560f11c7f63SJim Harris 
561f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_fail_handler(
562f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *this_device
563f11c7f63SJim Harris );
564f11c7f63SJim Harris 
565f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_destruct_handler(
566f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *this_device
567f11c7f63SJim Harris );
568f11c7f63SJim Harris 
569f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_reset_handler(
570f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device
571f11c7f63SJim Harris );
572f11c7f63SJim Harris 
573f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_reset_complete_handler(
574f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device
575f11c7f63SJim Harris );
576f11c7f63SJim Harris 
577f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_start_request_handler(
578f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device,
579f11c7f63SJim Harris    SCI_BASE_REQUEST_T       *request
580f11c7f63SJim Harris );
581f11c7f63SJim Harris 
582f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_complete_request_handler(
583f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device,
584f11c7f63SJim Harris    SCI_BASE_REQUEST_T       *request
585f11c7f63SJim Harris );
586f11c7f63SJim Harris 
587f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_continue_request_handler(
588f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device,
589f11c7f63SJim Harris    SCI_BASE_REQUEST_T       *request
590f11c7f63SJim Harris );
591f11c7f63SJim Harris 
592f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_suspend_handler(
593f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
594f11c7f63SJim Harris    U32                       suspend_type
595f11c7f63SJim Harris );
596f11c7f63SJim Harris 
597f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_resume_handler(
598f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device
599f11c7f63SJim Harris );
600f11c7f63SJim Harris 
601f11c7f63SJim Harris SCI_STATUS  scic_sds_remote_device_default_event_handler(
602f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
603f11c7f63SJim Harris    U32                       event_code
604f11c7f63SJim Harris );
605f11c7f63SJim Harris 
606f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_default_frame_handler(
607f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
608f11c7f63SJim Harris    U32                       frame_index
609f11c7f63SJim Harris );
610f11c7f63SJim Harris 
611f11c7f63SJim Harris // ---------------------------------------------------------------------------
612f11c7f63SJim Harris 
613f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_ready_state_stop_handler(
614f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device
615f11c7f63SJim Harris );
616f11c7f63SJim Harris 
617f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_ready_state_reset_handler(
618f11c7f63SJim Harris    SCI_BASE_REMOTE_DEVICE_T *device
619f11c7f63SJim Harris );
620f11c7f63SJim Harris 
621f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_general_frame_handler(
622f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
623f11c7f63SJim Harris    U32                       frame_index
624f11c7f63SJim Harris );
625f11c7f63SJim Harris 
626f11c7f63SJim Harris SCI_STATUS scic_sds_remote_device_general_event_handler(
627f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device,
628f11c7f63SJim Harris    U32                       event_code
629f11c7f63SJim Harris );
630f11c7f63SJim Harris 
631f11c7f63SJim Harris SCI_STATUS scic_sds_ssp_remote_device_ready_suspended_substate_resume_handler(
632f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T *this_device
633f11c7f63SJim Harris );
634f11c7f63SJim Harris 
635f11c7f63SJim Harris // ---------------------------------------------------------------------------
636f11c7f63SJim Harris 
637f11c7f63SJim Harris void scic_sds_remote_device_get_info_from_smp_discover_response(
638f11c7f63SJim Harris    SCIC_SDS_REMOTE_DEVICE_T    * this_device,
639f11c7f63SJim Harris    SMP_RESPONSE_DISCOVER_T     * discover_response
640f11c7f63SJim Harris );
641f11c7f63SJim Harris 
642f11c7f63SJim Harris #ifdef __cplusplus
643f11c7f63SJim Harris }
644f11c7f63SJim Harris #endif // __cplusplus
645f11c7f63SJim Harris 
646f11c7f63SJim Harris #endif // _SCIC_SDS_REMOTE_DEVICE_H_
647