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
55 #include <sys/cdefs.h>
56 /**
57 * @file
58 *
59 * @brief This file contains the methods for the SCIF_SAS_SMP_REMMOTE object's
60 * clear affiliation activity.
61 */
62 #include <dev/isci/scil/sci_controller.h>
63 #include <dev/isci/scil/scif_sas_controller.h>
64 #include <dev/isci/scil/scif_sas_remote_device.h>
65 #include <dev/isci/scil/scif_sas_logger.h>
66
67 #include <dev/isci/scil/scif_sas_smp_remote_device.h>
68 #include <dev/isci/scil/scif_sas_smp_io_request.h>
69 #include <dev/isci/scil/intel_sas.h>
70 #include <dev/isci/scil/scic_io_request.h>
71 #include <dev/isci/scil/scic_remote_device.h>
72 #include <dev/isci/scil/scif_sas_smp_phy.h>
73
74 //******************************************************************************
75 //* P R I V A T E M E T H O D S
76 //******************************************************************************
77
78 /**
79 * @brief This method finds the next smp phy (from the anchor_phy) that link to
80 * a SATA end device.
81 *
82 * @param[in] fw_device the framework SMP device that is clearing affiliation for
83 * its remote SATA devices'
84 *
85 * @return SCIF_SAS_SMP_PHY_T a smp phy, to which clear affiliation phy control command
86 * is to be sent.
87 */
88 static
scif_sas_smp_remote_device_find_next_smp_phy_link_to_sata(SCIF_SAS_SMP_PHY_T * anchor_phy)89 SCIF_SAS_SMP_PHY_T * scif_sas_smp_remote_device_find_next_smp_phy_link_to_sata(
90 SCIF_SAS_SMP_PHY_T * anchor_phy
91 )
92 {
93 SCI_FAST_LIST_ELEMENT_T * element = &anchor_phy->list_element;
94 SCIF_SAS_SMP_PHY_T * curr_smp_phy = NULL;
95
96 while (element != NULL)
97 {
98 curr_smp_phy = (SCIF_SAS_SMP_PHY_T*) sci_fast_list_get_object(element);
99 element = sci_fast_list_get_next(element);
100
101 if (curr_smp_phy->attached_device_type == SMP_END_DEVICE_ONLY
102 && curr_smp_phy->u.end_device != NULL)
103 {
104 SMP_DISCOVER_RESPONSE_PROTOCOLS_T dev_protocols;
105 scic_remote_device_get_protocols(
106 curr_smp_phy->u.end_device->core_object, &dev_protocols);
107
108 if (dev_protocols.u.bits.attached_stp_target)
109 return curr_smp_phy;
110 }
111 }
112
113 return NULL;
114 }
115
116 //******************************************************************************
117 //* P U B L I C M E T H O D S
118 //******************************************************************************
119
120 /**
121 * @brief This method starts the clear affiliation activity for a
122 * smp device's remote SATA devices.
123 *
124 * @param[in] fw_device the framework SMP device that is clearing affiliation for
125 * its remote SATA devices.
126 *
127 * @return none
128 */
scif_sas_smp_remote_device_start_clear_affiliation(SCIF_SAS_REMOTE_DEVICE_T * fw_device)129 void scif_sas_smp_remote_device_start_clear_affiliation(
130 SCIF_SAS_REMOTE_DEVICE_T * fw_device
131 )
132 {
133 SCIF_SAS_SMP_REMOTE_DEVICE_T * smp_device =
134 &fw_device->protocol_device.smp_device;
135
136 SCIF_SAS_SMP_PHY_T * phy_to_clear_affiliation = NULL;
137
138 if (smp_device->smp_phy_list.list_head != NULL)
139 {
140 phy_to_clear_affiliation =
141 scif_sas_smp_remote_device_find_next_smp_phy_link_to_sata(
142 (SCIF_SAS_SMP_PHY_T *)smp_device->smp_phy_list.list_head->object
143 );
144 }
145
146 if (phy_to_clear_affiliation != NULL)
147 {
148 smp_device->curr_clear_affiliation_phy = phy_to_clear_affiliation;
149
150 //set current activity
151 fw_device->protocol_device.smp_device.current_activity =
152 SCIF_SAS_SMP_REMOTE_DEVICE_ACTIVITY_CLEAR_AFFILIATION;
153
154 //Set current_smp_request to PHY CONTROL.
155 fw_device->protocol_device.smp_device.current_smp_request =
156 SMP_FUNCTION_PHY_CONTROL;
157
158 //reset discover_to_start flag.
159 fw_device->protocol_device.smp_device.scheduled_activity =
160 SCIF_SAS_SMP_REMOTE_DEVICE_ACTIVITY_NONE;
161
162 //build PHY Control (clear affiliation) to the phy.
163 scif_sas_smp_request_construct_phy_control(
164 fw_device->domain->controller,
165 fw_device,
166 PHY_OPERATION_CLEAR_AFFILIATION,
167 phy_to_clear_affiliation->phy_identifier,
168 NULL,
169 NULL
170 );
171
172 //issue DPC to start this request.
173 scif_cb_start_internal_io_task_schedule(
174 fw_device->domain->controller,
175 scif_sas_controller_start_high_priority_io,
176 fw_device->domain->controller
177 );
178 }
179 else
180 scif_sas_smp_remote_device_finish_clear_affiliation(fw_device);
181 }
182
183
184 /**
185 * @brief This method continues the clear affiliation activity for a
186 * smp device's remote SATA devices.
187 *
188 * @param[in] fw_device the framework SMP device that is clearing affiliation for
189 * its remote SATA devices.
190 *
191 * @return none
192 */
scif_sas_smp_remote_device_continue_clear_affiliation(SCIF_SAS_REMOTE_DEVICE_T * fw_device)193 void scif_sas_smp_remote_device_continue_clear_affiliation(
194 SCIF_SAS_REMOTE_DEVICE_T * fw_device
195 )
196 {
197 SCIF_SAS_SMP_REMOTE_DEVICE_T * smp_device =
198 &fw_device->protocol_device.smp_device;
199
200 //search from next immediate smp phy.
201 SCIF_SAS_SMP_PHY_T * phy_to_clear_affiliation = NULL;
202
203 if (smp_device->curr_clear_affiliation_phy->list_element.next != NULL)
204 {
205 phy_to_clear_affiliation =
206 scif_sas_smp_remote_device_find_next_smp_phy_link_to_sata(
207 smp_device->curr_clear_affiliation_phy->list_element.next->object
208 );
209 }
210
211 if (phy_to_clear_affiliation != NULL)
212 {
213 smp_device->curr_clear_affiliation_phy = phy_to_clear_affiliation;
214
215 //build PHY Control (clear affiliation) to the phy.
216 scif_sas_smp_request_construct_phy_control(
217 fw_device->domain->controller,
218 fw_device,
219 PHY_OPERATION_CLEAR_AFFILIATION,
220 phy_to_clear_affiliation->phy_identifier,
221 NULL,
222 NULL
223 );
224 }
225 else
226 scif_sas_smp_remote_device_finish_clear_affiliation(fw_device);
227 }
228
229
230 /**
231 * @brief This method finishes the clear affiliation activity for a
232 * smp device's remote SATA devices. It then notify the domain it fihishes
233 * the clear affiliation activity.
234 *
235 * @param[in] fw_device the framework SMP device that is clearing affiliation for
236 * its remote SATA devices.
237 *
238 * @return none
239 */
scif_sas_smp_remote_device_finish_clear_affiliation(SCIF_SAS_REMOTE_DEVICE_T * fw_device)240 void scif_sas_smp_remote_device_finish_clear_affiliation(
241 SCIF_SAS_REMOTE_DEVICE_T * fw_device
242 )
243 {
244 SCIF_SAS_DOMAIN_T * fw_domain = fw_device->domain;
245
246 scif_sas_smp_remote_device_clear(fw_device);
247
248 //let domain continue to clear affiliation on other smp devices.
249 scif_sas_domain_continue_clear_affiliation(fw_domain);
250 }
251
252
253