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