1/*- 2 * This file is provided under a dual BSD/GPLv2 license. When using or 3 * redistributing this file, you may do so under either license. 4 * 5 * GPL LICENSE SUMMARY 6 * 7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of version 2 of the GNU General Public License as 11 * published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 21 * The full GNU General Public License is included in this distribution 22 * in the file called LICENSE.GPL. 23 * 24 * BSD LICENSE 25 * 26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 27 * All rights reserved. 28 * 29 * Redistribution and use in source and binary forms, with or without 30 * modification, are permitted provided that the following conditions 31 * are met: 32 * 33 * * Redistributions of source code must retain the above copyright 34 * notice, this list of conditions and the following disclaimer. 35 * * Redistributions in binary form must reproduce the above copyright 36 * notice, this list of conditions and the following disclaimer in 37 * the documentation and/or other materials provided with the 38 * distribution. 39 * 40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 */ 52 53#include <sys/cdefs.h> 54__FBSDID("$FreeBSD$"); 55 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 */ 88static 89SCIF_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 */ 129void 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 */ 193void 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 */ 240void 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