scif_sas_remote_device_starting_substate_handlers.c revision 230557
1275988Sngie/*- 2240116Smarcel * This file is provided under a dual BSD/GPLv2 license. When using or 3240116Smarcel * redistributing this file, you may do so under either license. 4240116Smarcel * 5240116Smarcel * GPL LICENSE SUMMARY 6240116Smarcel * 7240116Smarcel * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 8240116Smarcel * 9240116Smarcel * This program is free software; you can redistribute it and/or modify 10240116Smarcel * it under the terms of version 2 of the GNU General Public License as 11240116Smarcel * published by the Free Software Foundation. 12240116Smarcel * 13240116Smarcel * This program is distributed in the hope that it will be useful, but 14240116Smarcel * WITHOUT ANY WARRANTY; without even the implied warranty of 15240116Smarcel * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16240116Smarcel * General Public License for more details. 17240116Smarcel * 18240116Smarcel * You should have received a copy of the GNU General Public License 19240116Smarcel * along with this program; if not, write to the Free Software 20240116Smarcel * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 21240116Smarcel * The full GNU General Public License is included in this distribution 22240116Smarcel * in the file called LICENSE.GPL. 23240116Smarcel * 24275988Sngie * BSD LICENSE 25240116Smarcel * 26275988Sngie * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 27240116Smarcel * All rights reserved. 28240116Smarcel * 29275988Sngie * Redistribution and use in source and binary forms, with or without 30240116Smarcel * modification, are permitted provided that the following conditions 31240116Smarcel * are met: 32240116Smarcel * 33240116Smarcel * * Redistributions of source code must retain the above copyright 34240116Smarcel * notice, this list of conditions and the following disclaimer. 35240116Smarcel * * Redistributions in binary form must reproduce the above copyright 36240116Smarcel * notice, this list of conditions and the following disclaimer in 37240116Smarcel * the documentation and/or other materials provided with the 38240116Smarcel * distribution. 39240116Smarcel * 40240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 41240116Smarcel * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 42240116Smarcel * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 43240116Smarcel * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 44240116Smarcel * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45240116Smarcel * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46240116Smarcel * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47240116Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48240116Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49240116Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 50240116Smarcel * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51240116Smarcel */ 52240116Smarcel 53240116Smarcel#include <sys/cdefs.h> 54240116Smarcel__FBSDID("$FreeBSD$"); 55240116Smarcel 56240116Smarcel/** 57240116Smarcel * @file 58240116Smarcel * 59240116Smarcel * @brief This file contains all of the method implementations pertaining 60240116Smarcel * to the framework remote device STARTING sub-state handler methods. 61240116Smarcel * The STARTING sub-state machine is responsible for ensuring that 62240116Smarcel * all initialization and configuration for a particular remote 63240116Smarcel * device is complete before transitioning to the READY state 64240116Smarcel * (i.e. before allowing normal host IO). 65240116Smarcel */ 66240116Smarcel 67240116Smarcel#include <dev/isci/scil/scic_remote_device.h> 68240116Smarcel 69240116Smarcel#include <dev/isci/scil/scif_sas_logger.h> 70240116Smarcel#include <dev/isci/scil/scif_sas_remote_device.h> 71240116Smarcel#include <dev/isci/scil/scif_sas_domain.h> 72240116Smarcel#include <dev/isci/scil/scif_sas_task_request.h> 73240116Smarcel 74240116Smarcel//****************************************************************************** 75240116Smarcel//* G E N E R A L S T O P H A N D L E R S 76240116Smarcel//****************************************************************************** 77240116Smarcel 78240116Smarcel/** 79240116Smarcel * @brief This method provides startig sub-state specific handling for 80240116Smarcel * when the remote device is requested to stop. This will occur 81240116Smarcel * when there is a link failure during the starting operation. 82240116Smarcel * 83240116Smarcel * @param[in] remote_device This parameter specifies the remote device 84240116Smarcel * object for which the failure condition occurred. 85240116Smarcel * 86240116Smarcel * @return This method returns an indication as to whether the failure 87240116Smarcel * operation completed successfully. 88240116Smarcel */ 89240116Smarcelstatic 90240116SmarcelSCI_STATUS 91240116Smarcelscif_sas_remote_device_starting_state_general_stop_handler( 92240116Smarcel SCI_BASE_REMOTE_DEVICE_T * remote_device 93240116Smarcel) 94240116Smarcel{ 95240116Smarcel SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *) 96240116Smarcel remote_device; 97240116Smarcel 98240116Smarcel SCIF_LOG_INFO(( 99240116Smarcel sci_base_object_get_logger(fw_device), 100240116Smarcel SCIF_LOG_OBJECT_REMOTE_DEVICE, 101240116Smarcel "RemoteDevice:0x%x starting device requested to stop\n", 102240116Smarcel fw_device 103240116Smarcel )); 104240116Smarcel 105240116Smarcel fw_device->domain->device_start_in_progress_count--; 106240116Smarcel 107240116Smarcel sci_base_state_machine_change_state( 108240116Smarcel &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_STOPPING 109240116Smarcel ); 110240116Smarcel 111240116Smarcel return SCI_SUCCESS; 112240116Smarcel} 113240116Smarcel 114240116Smarcel//****************************************************************************** 115240116Smarcel//* A W A I T C O M P L E T E H A N D L E R S 116240116Smarcel//****************************************************************************** 117240116Smarcel 118240116Smarcel/** 119240116Smarcel * @brief This method provides AWAIT START COMPLETE sub-state specific 120240116Smarcel * handling for when the remote device undergoes a failure 121240116Smarcel * condition. 122240116Smarcel * 123240116Smarcel * @param[in] remote_device This parameter specifies the remote device 124240116Smarcel * object for which the failure condition occurred. 125240116Smarcel * 126240116Smarcel * @return This method returns an indication as to whether the failure 127240116Smarcel * operation completed successfully. 128240116Smarcel */ 129240116Smarcelstatic 130240116SmarcelSCI_STATUS scif_sas_remote_device_starting_await_complete_fail_handler( 131240116Smarcel SCI_BASE_REMOTE_DEVICE_T * remote_device 132240116Smarcel) 133240116Smarcel{ 134240116Smarcel SCIF_SAS_REMOTE_DEVICE_T * fw_device = (SCIF_SAS_REMOTE_DEVICE_T *) 135240116Smarcel remote_device; 136240116Smarcel 137240116Smarcel SCIF_LOG_WARNING(( 138240116Smarcel sci_base_object_get_logger(fw_device), 139240116Smarcel SCIF_LOG_OBJECT_REMOTE_DEVICE, 140240116Smarcel "RemoteDevice:0x%x starting device failed, start complete not received\n", 141240116Smarcel fw_device 142240116Smarcel )); 143240116Smarcel 144240116Smarcel sci_base_state_machine_change_state( 145240116Smarcel &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_FAILED 146240116Smarcel ); 147240116Smarcel 148240116Smarcel return SCI_SUCCESS; 149240116Smarcel} 150240116Smarcel 151240116Smarcel/** 152240116Smarcel * @brief This method provides AWAIT COMPLETE state specific handling for 153240116Smarcel * when the core remote device object issues a device not ready 154240116Smarcel * notification. In the AWAIT COMPLETE state we do not inform 155240116Smarcel * the framework user of the state change of the device, since the 156240116Smarcel * user is unaware of the remote device start process. 157240116Smarcel * 158240116Smarcel * @param[in] remote_device This parameter specifies the remote device 159240116Smarcel * object for which the notification occurred. 160240116Smarcel * 161240116Smarcel * @return none. 162240116Smarcel */ 163240116Smarcelstatic 164240116Smarcelvoid scif_sas_remote_device_starting_await_complete_not_ready_handler( 165240116Smarcel SCIF_SAS_REMOTE_DEVICE_T * fw_device, 166240116Smarcel U32 reason_code 167240116Smarcel) 168240116Smarcel{ 169240116Smarcel} 170240116Smarcel 171240116Smarcel/** 172240116Smarcel * @brief This method provides AWAIT START COMPLETE sub-state specific 173240116Smarcel * handling for when the core provides a start complete notification 174240116Smarcel * for the remote device. If the start completion status indicates 175240116Smarcel * a successful start, then the device is transitioned into the 176240116Smarcel * READY state. All other status cause a transition to the 177240116Smarcel * FAILED state and a scif_cb_controller_error() notification 178240116Smarcel * message to the framework user. 179240116Smarcel * 180240116Smarcel * @param[in] fw_device This parameter specifies the remote device 181240116Smarcel * object for which the notification has occurred. 182240116Smarcel * 183240116Smarcel * @return none. 184240116Smarcel */ 185240116Smarcelstatic 186240116Smarcelvoid scif_sas_remote_device_starting_await_complete_start_complete_handler( 187240116Smarcel SCIF_SAS_REMOTE_DEVICE_T * fw_device, 188240116Smarcel SCI_STATUS completion_status 189240116Smarcel) 190240116Smarcel{ 191240116Smarcel if (completion_status == SCI_SUCCESS) 192240116Smarcel { 193240116Smarcel /** @todo need to add support for resetting the device first. This can 194240116Smarcel wait until 1.3. */ 195240116Smarcel /** @todo Update to comprehend situations (i.e. SATA) where config is 196240116Smarcel needed. */ 197240116Smarcel 198240116Smarcel sci_base_state_machine_change_state( 199240116Smarcel &fw_device->starting_substate_machine, 200240116Smarcel SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY 201240116Smarcel ); 202240116Smarcel } 203240116Smarcel else 204240116Smarcel { 205240116Smarcel SCIF_LOG_WARNING(( 206240116Smarcel sci_base_object_get_logger(fw_device), 207240116Smarcel SCIF_LOG_OBJECT_REMOTE_DEVICE | SCIF_LOG_OBJECT_REMOTE_DEVICE_CONFIG, 208240116Smarcel "Device:0x%x Status:0x%x failed to start core device\n", 209240116Smarcel fw_device 210240116Smarcel )); 211240116Smarcel 212240116Smarcel sci_base_state_machine_change_state( 213240116Smarcel &fw_device->parent.state_machine, 214240116Smarcel SCI_BASE_REMOTE_DEVICE_STATE_FAILED 215240116Smarcel ); 216240116Smarcel 217240116Smarcel // Something is seriously wrong. Starting the core remote device 218240116Smarcel // shouldn't fail in anyway in this state. 219240116Smarcel scif_cb_controller_error(fw_device->domain->controller, 220240116Smarcel SCI_CONTROLLER_REMOTE_DEVICE_ERROR); 221240116Smarcel } 222240116Smarcel} 223240116Smarcel 224240116Smarcel//****************************************************************************** 225240116Smarcel//* C O M P L E T E H A N D L E R S 226240116Smarcel//****************************************************************************** 227240116Smarcel 228240116Smarcel/** 229240116Smarcel * @brief This method provides STARTING AWAIT READY sub-state specific 230240116Smarcel * handling for when the core provides a device ready notification 231240116Smarcel * for the remote device. This essentially, causes a transition 232240116Smarcel * of the framework remote device into the READY state. 233240116Smarcel * 234240116Smarcel * @param[in] fw_device This parameter specifies the remote device 235240116Smarcel * object for which the notification has occurred. 236240116Smarcel * 237240116Smarcel * @return none. 238240116Smarcel */ 239240116Smarcelstatic 240240116Smarcelvoid scif_sas_remote_device_starting_await_ready_ready_handler( 241240116Smarcel SCIF_SAS_REMOTE_DEVICE_T * fw_device 242240116Smarcel) 243240116Smarcel{ 244240116Smarcel#if !defined(DISABLE_WIDE_PORTED_TARGETS) 245240116Smarcel if (fw_device->destination_state == 246240116Smarcel SCIF_SAS_REMOTE_DEVICE_DESTINATION_STATE_UPDATING_PORT_WIDTH) 247240116Smarcel { 248240116Smarcel { 249240116Smarcel sci_base_state_machine_change_state( 250240116Smarcel &fw_device->parent.state_machine, 251240116Smarcel SCI_BASE_REMOTE_DEVICE_STATE_UPDATING_PORT_WIDTH 252240116Smarcel ); 253240116Smarcel } 254240116Smarcel } 255240116Smarcel else 256240116Smarcel#endif 257240116Smarcel { 258240116Smarcel sci_base_state_machine_change_state( 259240116Smarcel &fw_device->parent.state_machine, SCI_BASE_REMOTE_DEVICE_STATE_READY 260240116Smarcel ); 261240116Smarcel } 262240116Smarcel 263240116Smarcel#if !defined(DISABLE_WIDE_PORTED_TARGETS) 264240116Smarcel scif_sas_domain_remote_device_start_complete(fw_device->domain,fw_device); 265240116Smarcel#endif 266240116Smarcel} 267240116Smarcel 268240116Smarcel 269240116SmarcelSCIF_SAS_REMOTE_DEVICE_STATE_HANDLER_T 270240116Smarcelscif_sas_remote_device_starting_substate_handler_table[] = 271240116Smarcel{ 272240116Smarcel // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_COMPLETE 273240116Smarcel { 274240116Smarcel { 275240116Smarcel scif_sas_remote_device_default_start_handler, 276240116Smarcel scif_sas_remote_device_starting_state_general_stop_handler, 277240116Smarcel scif_sas_remote_device_starting_await_complete_fail_handler, 278240116Smarcel scif_sas_remote_device_default_destruct_handler, 279240116Smarcel scif_sas_remote_device_default_reset_handler, 280240116Smarcel scif_sas_remote_device_default_reset_complete_handler, 281240116Smarcel scif_sas_remote_device_default_start_io_handler, 282240116Smarcel scif_sas_remote_device_default_complete_io_handler, 283240116Smarcel scif_sas_remote_device_default_continue_io_handler, 284240116Smarcel scif_sas_remote_device_default_start_task_handler, 285240116Smarcel scif_sas_remote_device_default_complete_task_handler 286240116Smarcel }, 287240116Smarcel scif_sas_remote_device_starting_await_complete_start_complete_handler, 288240116Smarcel scif_sas_remote_device_default_stop_complete_handler, 289240116Smarcel scif_sas_remote_device_default_ready_handler, 290240116Smarcel scif_sas_remote_device_starting_await_complete_not_ready_handler, 291240116Smarcel scif_sas_remote_device_default_start_io_handler, 292240116Smarcel scif_sas_remote_device_default_complete_high_priority_io_handler 293240116Smarcel }, 294240116Smarcel // SCIF_SAS_REMOTE_DEVICE_STARTING_SUBSTATE_AWAIT_READY 295240116Smarcel { 296240116Smarcel { 297240116Smarcel scif_sas_remote_device_default_start_handler, 298240116Smarcel scif_sas_remote_device_starting_state_general_stop_handler, 299240116Smarcel scif_sas_remote_device_starting_await_complete_fail_handler, 300240116Smarcel scif_sas_remote_device_default_destruct_handler, 301240116Smarcel scif_sas_remote_device_default_reset_handler, 302240116Smarcel scif_sas_remote_device_default_reset_complete_handler, 303240116Smarcel scif_sas_remote_device_default_start_io_handler, 304240116Smarcel scif_sas_remote_device_default_complete_io_handler, 305240116Smarcel scif_sas_remote_device_default_continue_io_handler, 306240116Smarcel scif_sas_remote_device_default_start_task_handler, 307240116Smarcel scif_sas_remote_device_default_complete_task_handler 308240116Smarcel }, 309240116Smarcel scif_sas_remote_device_default_start_complete_handler, 310240116Smarcel scif_sas_remote_device_default_stop_complete_handler, 311240116Smarcel scif_sas_remote_device_starting_await_ready_ready_handler, 312240116Smarcel scif_sas_remote_device_default_not_ready_handler, 313240116Smarcel scif_sas_remote_device_default_start_io_handler, 314240116Smarcel scif_sas_remote_device_default_complete_high_priority_io_handler 315240116Smarcel } 316240116Smarcel}; 317240116Smarcel 318240116Smarcel