xref: /freebsd/sys/dev/isci/scil/scif_sas_domain.h (revision 718cf2ccb9956613756ab15d7a0e28f2c8e91cab)
1f11c7f63SJim Harris /*-
2*718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3*718cf2ccSPedro 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  * $FreeBSD$
55f11c7f63SJim Harris  */
56f11c7f63SJim Harris #ifndef _SCIF_SAS_DOMAIN_H_
57f11c7f63SJim Harris #define _SCIF_SAS_DOMAIN_H_
58f11c7f63SJim Harris 
59f11c7f63SJim Harris /**
60f11c7f63SJim Harris  * @file
61f11c7f63SJim Harris  *
62f11c7f63SJim Harris  * @brief This file contains the protected interface structures, constants,
63f11c7f63SJim Harris  *        and methods for the SCIF_SAS_DOMAIN object.
64f11c7f63SJim Harris  */
65f11c7f63SJim Harris 
66f11c7f63SJim Harris #ifdef __cplusplus
67f11c7f63SJim Harris extern "C" {
68f11c7f63SJim Harris #endif // __cplusplus
69f11c7f63SJim Harris 
70f11c7f63SJim Harris #include <dev/isci/scil/sci_abstract_list.h>
71f11c7f63SJim Harris #include <dev/isci/scil/sci_fast_list.h>
72f11c7f63SJim Harris #include <dev/isci/scil/scif_domain.h>
73f11c7f63SJim Harris 
74f11c7f63SJim Harris #include <dev/isci/scil/sci_base_domain.h>
75f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_request.h>
76f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_task_request.h>
77f11c7f63SJim Harris #include <dev/isci/scil/scif_sas_remote_device.h>
78f11c7f63SJim Harris 
79f11c7f63SJim Harris 
80f11c7f63SJim Harris extern SCI_BASE_DOMAIN_STATE_HANDLER_T scif_sas_domain_state_handler_table[];
81f11c7f63SJim Harris extern SCI_BASE_STATE_T scif_sas_domain_state_table[];
82f11c7f63SJim Harris 
83f11c7f63SJim Harris #define PORT_HARD_RESET_TIMEOUT 1000 //1000 miliseconds
84f11c7f63SJim Harris 
85f11c7f63SJim Harris #define SCIF_DOMAIN_DISCOVER_TIMEOUT 20000 // miliseconds
86f11c7f63SJim Harris 
87f11c7f63SJim Harris /**
88f11c7f63SJim Harris  * @struct SCIF_SAS_DOMAIN
89f11c7f63SJim Harris  *
90f11c7f63SJim Harris  * @brief The SCI SAS Framework domain object abstracts the SAS domain
91f11c7f63SJim Harris  *        level behavior for the framework component.  Additionally,
92f11c7f63SJim Harris  *        it provides a higher level of abstraction for the core port
93f11c7f63SJim Harris  *        object.  There is a 1:1 correspondance between core ports and
94f11c7f63SJim Harris  *        framework domain objects.  Essentially, each core port provides
95f11c7f63SJim Harris  *        the access to the remote devices in the domain.
96f11c7f63SJim Harris  */
97f11c7f63SJim Harris typedef struct SCIF_SAS_DOMAIN
98f11c7f63SJim Harris {
99f11c7f63SJim Harris    /**
100f11c7f63SJim Harris     * The SCI_BASE_DOMAIN is the parent object for the SCIF_SAS_DOMAIN
101f11c7f63SJim Harris     * object.
102f11c7f63SJim Harris     */
103f11c7f63SJim Harris    SCI_BASE_DOMAIN_T  parent;
104f11c7f63SJim Harris 
105f11c7f63SJim Harris    /**
106f11c7f63SJim Harris     * This field contains the handle for the SCI Core port object that
107f11c7f63SJim Harris     * is managed by this framework domain object.
108f11c7f63SJim Harris     */
109f11c7f63SJim Harris    SCI_PORT_HANDLE_T  core_object;
110f11c7f63SJim Harris 
111f11c7f63SJim Harris    /**
112f11c7f63SJim Harris     * This field specifies the controller containing this domain object.
113f11c7f63SJim Harris     */
114f11c7f63SJim Harris    struct SCIF_SAS_CONTROLLER * controller;
115f11c7f63SJim Harris 
116f11c7f63SJim Harris    /**
117f11c7f63SJim Harris     * This field references the list of state specific handler methods to
118f11c7f63SJim Harris     * be utilized for this domain instance.
119f11c7f63SJim Harris     */
120f11c7f63SJim Harris    SCI_BASE_DOMAIN_STATE_HANDLER_T * state_handlers;
121f11c7f63SJim Harris 
122f11c7f63SJim Harris    /**
123f11c7f63SJim Harris     * This field contains references to all of the devices contained in
124f11c7f63SJim Harris     * this domain.
125f11c7f63SJim Harris     */
126f11c7f63SJim Harris    SCI_ABSTRACT_LIST_T  remote_device_list;
127f11c7f63SJim Harris 
128f11c7f63SJim Harris    /**
129f11c7f63SJim Harris     * This field contains the list of all outstanding request (IO or
130f11c7f63SJim Harris     * management) in this domain.
131f11c7f63SJim Harris     */
132f11c7f63SJim Harris    SCI_FAST_LIST_T  request_list;
133f11c7f63SJim Harris 
134f11c7f63SJim Harris    /**
135f11c7f63SJim Harris     * This field indicates whether the core port object is in a ready state
136f11c7f63SJim Harris     * or not.
137f11c7f63SJim Harris     */
138f11c7f63SJim Harris    BOOL  is_port_ready;
139f11c7f63SJim Harris 
140f11c7f63SJim Harris    /**
141f11c7f63SJim Harris     * This field indicates the number of remote devices that have been
142f11c7f63SJim Harris     * started in this domain.
143f11c7f63SJim Harris     */
144f11c7f63SJim Harris    U32  device_start_count;
145f11c7f63SJim Harris 
146f11c7f63SJim Harris    /**
147f11c7f63SJim Harris     * This field indicates the number of remote devices that are currently
148f11c7f63SJim Harris     * in the process of becoming ready.  This field is utilized to gate
149f11c7f63SJim Harris     * the transition back to the READY state for the domain.
150f11c7f63SJim Harris     */
151f11c7f63SJim Harris    U32  device_start_in_progress_count;
152f11c7f63SJim Harris 
153f11c7f63SJim Harris    /**
154f11c7f63SJim Harris     * This field records how many broadcast change primitve are
155f11c7f63SJim Harris     * received and not processed yet.
156f11c7f63SJim Harris     */
157f11c7f63SJim Harris    U32  broadcast_change_count;
158f11c7f63SJim Harris 
159f11c7f63SJim Harris    /**
160f11c7f63SJim Harris     * This fields indicates whether the expanders in this domain need to
161f11c7f63SJim Harris     * have there config route table configured by our driver. For expample,
162f11c7f63SJim Harris     * if we found the top level expander is a self-configuring expander and
163f11c7f63SJim Harris     * it is able to config others, all the expanders in this domain don't
164f11c7f63SJim Harris     * need to configure route table.
165f11c7f63SJim Harris     */
166f11c7f63SJim Harris    BOOL is_config_route_table_needed;
167f11c7f63SJim Harris 
168f11c7f63SJim Harris    struct
169f11c7f63SJim Harris    {
170f11c7f63SJim Harris       /**
171f11c7f63SJim Harris        * This field provides the domain object a scratch area to indicate
172f11c7f63SJim Harris        * status of an ongoing operation.
173f11c7f63SJim Harris        */
174f11c7f63SJim Harris       SCI_STATUS  status;
175f11c7f63SJim Harris 
176f11c7f63SJim Harris       /**
177f11c7f63SJim Harris        * This is the timer handle that is utilized to time the discovery
178f11c7f63SJim Harris        * or domain reset operations.
179f11c7f63SJim Harris        */
180f11c7f63SJim Harris       void * timer;
181f11c7f63SJim Harris 
182f11c7f63SJim Harris       /**
183f11c7f63SJim Harris        * This field specifies the timeout value, in milliseconds, for the
184f11c7f63SJim Harris        * entire operation (discovery or reset).
185f11c7f63SJim Harris        */
186f11c7f63SJim Harris       U32 timeout;
187f11c7f63SJim Harris 
188f11c7f63SJim Harris       /**
189f11c7f63SJim Harris        * This field specifies the timeout value, in milliseconds, for a
190f11c7f63SJim Harris        * single device.
191f11c7f63SJim Harris        */
192f11c7f63SJim Harris       U32 device_timeout;
193f11c7f63SJim Harris 
194f11c7f63SJim Harris    } operation;
195f11c7f63SJim Harris 
196f11c7f63SJim Harris } SCIF_SAS_DOMAIN_T;
197f11c7f63SJim Harris 
198f11c7f63SJim Harris void scif_sas_domain_construct(
199f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T          * fw_domain,
200f11c7f63SJim Harris    U8                           domain_id,
201f11c7f63SJim Harris    struct SCIF_SAS_CONTROLLER * fw_controller
202f11c7f63SJim Harris );
203f11c7f63SJim Harris 
204f11c7f63SJim Harris void scif_sas_domain_terminate_requests(
205f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain,
206f11c7f63SJim Harris    SCIF_SAS_REMOTE_DEVICE_T * fw_device,
207f11c7f63SJim Harris    SCIF_SAS_REQUEST_T       * fw_request,
208f11c7f63SJim Harris    SCIF_SAS_TASK_REQUEST_T  * fw_requestor
209f11c7f63SJim Harris );
210f11c7f63SJim Harris 
211f11c7f63SJim Harris SCIF_SAS_REQUEST_T * scif_sas_domain_get_request_by_io_tag(
212f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain,
213f11c7f63SJim Harris    U16                 io_tag
214f11c7f63SJim Harris );
215f11c7f63SJim Harris 
216f11c7f63SJim Harris void scif_sas_domain_transition_to_stopped_state(
217f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
218f11c7f63SJim Harris );
219f11c7f63SJim Harris 
220f11c7f63SJim Harris void scif_sas_domain_initialize(
221f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
222f11c7f63SJim Harris );
223f11c7f63SJim Harris 
224f11c7f63SJim Harris void scif_sas_domain_remote_device_start_complete(
225f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain,
226f11c7f63SJim Harris    SCIF_SAS_REMOTE_DEVICE_T * fw_device
227f11c7f63SJim Harris );
228f11c7f63SJim Harris 
229f11c7f63SJim Harris BOOL scif_sas_domain_is_in_smp_activity(
230f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain
231f11c7f63SJim Harris );
232f11c7f63SJim Harris 
233f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * scif_sas_domain_get_device_by_containing_device(
234f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain,
235f11c7f63SJim Harris    SCIF_SAS_REMOTE_DEVICE_T * containing_device,
236f11c7f63SJim Harris    U8                         expander_phy_id
237f11c7f63SJim Harris );
238f11c7f63SJim Harris 
239f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * scif_sas_domain_find_device_in_spinup_hold(
240f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain
241f11c7f63SJim Harris );
242f11c7f63SJim Harris 
243f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * scif_sas_domain_find_device_has_scheduled_activity(
244f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain,
245f11c7f63SJim Harris    U8                         smp_activity
246f11c7f63SJim Harris );
247f11c7f63SJim Harris 
248f11c7f63SJim Harris void scif_sas_domain_start_smp_activity(
249f11c7f63SJim Harris   SCIF_SAS_DOMAIN_T        * fw_domain
250f11c7f63SJim Harris );
251f11c7f63SJim Harris 
252f11c7f63SJim Harris void scif_sas_domain_remove_expander_device(
253f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain,
254f11c7f63SJim Harris    SCIF_SAS_REMOTE_DEVICE_T * fw_device
255f11c7f63SJim Harris );
256f11c7f63SJim Harris 
257f11c7f63SJim Harris void scif_sas_domain_start_smp_discover(
258f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T        * fw_domain,
259f11c7f63SJim Harris    SCIF_SAS_REMOTE_DEVICE_T * top_expander
260f11c7f63SJim Harris );
261f11c7f63SJim Harris 
262f11c7f63SJim Harris void scif_sas_domain_continue_discover(
263f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
264f11c7f63SJim Harris );
265f11c7f63SJim Harris 
266f11c7f63SJim Harris void scif_sas_domain_finish_discover(
267f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
268f11c7f63SJim Harris );
269f11c7f63SJim Harris 
270f11c7f63SJim Harris void scif_sas_domain_transition_to_discovering_state(
271f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
272f11c7f63SJim Harris );
273f11c7f63SJim Harris 
274f11c7f63SJim Harris void scif_sas_domain_cancel_smp_activities(
275f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
276f11c7f63SJim Harris );
277f11c7f63SJim Harris 
278f11c7f63SJim Harris U8 scif_sas_domain_get_smp_request_count(
279f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
280f11c7f63SJim Harris );
281f11c7f63SJim Harris 
282f11c7f63SJim Harris void scif_sas_domain_schedule_clear_affiliation(
283f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
284f11c7f63SJim Harris );
285f11c7f63SJim Harris 
286f11c7f63SJim Harris void scif_sas_domain_start_clear_affiliation(
287f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
288f11c7f63SJim Harris );
289f11c7f63SJim Harris 
290f11c7f63SJim Harris void scif_sas_domain_continue_clear_affiliation(
291f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
292f11c7f63SJim Harris );
293f11c7f63SJim Harris 
294f11c7f63SJim Harris void scif_sas_domain_release_resource(
295f11c7f63SJim Harris    struct SCIF_SAS_CONTROLLER * fw_controller,
296f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T     * fw_domain
297f11c7f63SJim Harris );
298f11c7f63SJim Harris 
299f11c7f63SJim Harris SCIF_SAS_REMOTE_DEVICE_T * scif_sas_domain_find_next_ea_target_reset(
300f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T * fw_domain
301f11c7f63SJim Harris );
302f11c7f63SJim Harris 
303f11c7f63SJim Harris #if !defined(DISABLE_WIDE_PORTED_TARGETS)
304f11c7f63SJim Harris void scif_sas_domain_update_device_port_width(
305f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T     * fw_domain,
306f11c7f63SJim Harris    SCI_PORT_HANDLE_T      port
307f11c7f63SJim Harris );
308f11c7f63SJim Harris #else  //!defined(DISABLE_WIDE_PORTED_TARGETS)
309f11c7f63SJim Harris #define scif_sas_domain_update_device_port_width(domain, port)
310f11c7f63SJim Harris #endif //!defined(DISABLE_WIDE_PORTED_TARGETS)
311f11c7f63SJim Harris 
312f11c7f63SJim Harris #ifdef SCI_LOGGING
313f11c7f63SJim Harris void scif_sas_domain_initialize_state_logging(
314f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T *fw_domain
315f11c7f63SJim Harris );
316f11c7f63SJim Harris 
317f11c7f63SJim Harris void scif_sas_domain_deinitialize_state_logging(
318f11c7f63SJim Harris    SCIF_SAS_DOMAIN_T *fw_domain
319f11c7f63SJim Harris );
320f11c7f63SJim Harris #else // SCI_LOGGING
321f11c7f63SJim Harris #define scif_sas_domain_initialize_state_logging(x)
322f11c7f63SJim Harris #define scif_sas_domain_deinitialize_state_logging(x)
323f11c7f63SJim Harris #endif // SCI_LOGGING
324f11c7f63SJim Harris 
325f11c7f63SJim Harris #ifdef __cplusplus
326f11c7f63SJim Harris }
327f11c7f63SJim Harris #endif // __cplusplus
328f11c7f63SJim Harris 
329f11c7f63SJim Harris #endif // _SCIF_SAS_DOMAIN_H_
330f11c7f63SJim Harris 
331