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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
53 #include <sys/cdefs.h>
54 __FBSDID("$FreeBSD$");
59 * @brief This file contains This file contains the SMP remote device
60 * object methods and it's state machines.
63 #include <dev/isci/scil/scic_user_callback.h>
64 #include <dev/isci/scil/scic_sds_logger.h>
65 #include <dev/isci/scil/scic_sds_remote_device.h>
66 #include <dev/isci/scil/scic_sds_controller.h>
67 #include <dev/isci/scil/scic_sds_port.h>
68 #include <dev/isci/scil/scic_sds_request.h>
69 #include <dev/isci/scil/scu_event_codes.h>
70 #include <dev/isci/scil/scu_task_context.h>
71 #include <dev/isci/scil/scic_remote_device.h>
73 //*****************************************************************************
74 //* SMP REMOTE DEVICE READY IDLE SUBSTATE HANDLERS
75 //*****************************************************************************
78 * This method will handle the start io operation for a SMP device that is in
81 * @param [in] device The device the io is sent to.
82 * @param [in] request The io to start.
87 SCI_STATUS scic_sds_smp_remote_device_ready_idle_substate_start_io_handler(
88 SCI_BASE_REMOTE_DEVICE_T * device,
89 SCI_BASE_REQUEST_T * request
93 SCIC_SDS_REMOTE_DEVICE_T * this_device = (SCIC_SDS_REMOTE_DEVICE_T *)device;
94 SCIC_SDS_REQUEST_T * io_request = (SCIC_SDS_REQUEST_T *)request;
96 // Will the port allow the io request to start?
97 status = this_device->owning_port->state_handlers->start_io_handler(
98 this_device->owning_port,
103 if (status == SCI_SUCCESS)
106 scic_sds_remote_node_context_start_io(this_device->rnc, io_request);
108 if (status == SCI_SUCCESS)
110 status = scic_sds_request_start(io_request);
113 if (status == SCI_SUCCESS)
115 this_device->working_request = io_request;
117 sci_base_state_machine_change_state(
118 &this_device->ready_substate_machine,
119 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
123 scic_sds_remote_device_start_request(this_device, io_request, status);
130 //******************************************************************************
131 //* SMP REMOTE DEVICE READY SUBSTATE CMD HANDLERS
132 //******************************************************************************
134 * This device is already handling a command it can not accept new commands
135 * until this one is complete.
137 * @param[in] device This is the device object that is receiving the IO.
139 * @param[in] request The io to start.
144 SCI_STATUS scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler(
145 SCI_BASE_REMOTE_DEVICE_T * device,
146 SCI_BASE_REQUEST_T * request
149 return SCI_FAILURE_INVALID_STATE;
154 * @brief this is the complete_io_handler for smp device at ready cmd substate.
156 * @param[in] device This is the device object that is receiving the IO.
157 * @param[in] request The io to start.
162 SCI_STATUS scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler(
163 SCI_BASE_REMOTE_DEVICE_T * device,
164 SCI_BASE_REQUEST_T * request
168 SCIC_SDS_REMOTE_DEVICE_T * this_device;
169 SCIC_SDS_REQUEST_T * the_request;
171 this_device = (SCIC_SDS_REMOTE_DEVICE_T *)device;
172 the_request = (SCIC_SDS_REQUEST_T *)request;
174 status = scic_sds_io_request_complete(the_request);
176 if (status == SCI_SUCCESS)
178 status = scic_sds_port_complete_io(
179 this_device->owning_port, this_device, the_request);
181 if (status == SCI_SUCCESS)
183 scic_sds_remote_device_decrement_request_count(this_device);
184 sci_base_state_machine_change_state(
185 &this_device->ready_substate_machine,
186 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
192 sci_base_object_get_logger(this_device),
193 SCIC_LOG_OBJECT_SMP_REMOTE_TARGET,
194 "SCIC SDS Remote Device 0x%x io request 0x%x could not be completd on the port 0x%x failed with status %d.\n",
195 this_device, the_request, this_device->owning_port, status
204 * @brief This is frame handler for smp device ready cmd substate.
206 * @param[in] this_device This is the device object that is receiving the frame.
207 * @param[in] frame_index The index for the frame received.
212 SCI_STATUS scic_sds_smp_remote_device_ready_cmd_substate_frame_handler(
213 SCIC_SDS_REMOTE_DEVICE_T * this_device,
219 /// The device does not process any UF received from the hardware while
220 /// in this state. All unsolicited frames are forwarded to the io request
222 status = scic_sds_io_request_frame_handler(
223 this_device->working_request,
230 // ---------------------------------------------------------------------------
232 SCIC_SDS_REMOTE_DEVICE_STATE_HANDLER_T
233 scic_sds_smp_remote_device_ready_substate_handler_table[
234 SCIC_SDS_SMP_REMOTE_DEVICE_READY_MAX_SUBSTATES] =
236 // SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
239 scic_sds_remote_device_default_start_handler,
240 scic_sds_remote_device_ready_state_stop_handler,
241 scic_sds_remote_device_default_fail_handler,
242 scic_sds_remote_device_default_destruct_handler,
243 scic_sds_remote_device_default_reset_handler,
244 scic_sds_remote_device_default_reset_complete_handler,
245 scic_sds_smp_remote_device_ready_idle_substate_start_io_handler,
246 scic_sds_remote_device_default_complete_request_handler,
247 scic_sds_remote_device_default_continue_request_handler,
248 scic_sds_remote_device_default_start_request_handler,
249 scic_sds_remote_device_default_complete_request_handler
251 scic_sds_remote_device_default_suspend_handler,
252 scic_sds_remote_device_default_resume_handler,
253 scic_sds_remote_device_general_event_handler,
254 scic_sds_remote_device_default_frame_handler
256 // SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
259 scic_sds_remote_device_default_start_handler,
260 scic_sds_remote_device_ready_state_stop_handler,
261 scic_sds_remote_device_default_fail_handler,
262 scic_sds_remote_device_default_destruct_handler,
263 scic_sds_remote_device_default_reset_handler,
264 scic_sds_remote_device_default_reset_complete_handler,
265 scic_sds_smp_remote_device_ready_cmd_substate_start_io_handler,
266 scic_sds_smp_remote_device_ready_cmd_substate_complete_io_handler,
267 scic_sds_remote_device_default_continue_request_handler,
268 scic_sds_remote_device_default_start_request_handler,
269 scic_sds_remote_device_default_complete_request_handler
271 scic_sds_remote_device_default_suspend_handler,
272 scic_sds_remote_device_default_resume_handler,
273 scic_sds_remote_device_general_event_handler,
274 scic_sds_smp_remote_device_ready_cmd_substate_frame_handler
279 * This is the SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE enter method. This
280 * method sets the ready cmd substate handlers and reports the device as ready.
282 * @param[in] object This is the SCI_BASE_OBJECT which is cast into a
283 * SCIC_SDS_REMOTE_DEVICE.
288 void scic_sds_smp_remote_device_ready_idle_substate_enter(
289 SCI_BASE_OBJECT_T *object
292 SCIC_SDS_REMOTE_DEVICE_T *this_device = (SCIC_SDS_REMOTE_DEVICE_T *)object;
296 scic_sds_smp_remote_device_ready_substate_handler_table,
297 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE
300 scic_cb_remote_device_ready(
301 scic_sds_remote_device_get_controller(this_device), this_device);
305 * This is the SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD enter method. This
306 * method sets the remote device objects ready cmd substate handlers, and notify
307 * core user that the device is not ready.
309 * @param[in] object This is the SCI_BASE_OBJECT which is cast into a
310 * SCIC_SDS_REMOTE_DEVICE.
315 void scic_sds_smp_remote_device_ready_cmd_substate_enter(
316 SCI_BASE_OBJECT_T *object
319 SCIC_SDS_REMOTE_DEVICE_T *this_device = (SCIC_SDS_REMOTE_DEVICE_T *)object;
321 ASSERT(this_device->working_request != NULL);
325 scic_sds_smp_remote_device_ready_substate_handler_table,
326 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD
329 scic_cb_remote_device_not_ready(
330 scic_sds_remote_device_get_controller(this_device),
332 SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED
337 * This is the SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_CMD exit method.
339 * @param[in] object This is the SCI_BASE_OBJECT which is cast into a
340 * SCIC_SDS_REMOTE_DEVICE.
345 void scic_sds_smp_remote_device_ready_cmd_substate_exit(
346 SCI_BASE_OBJECT_T *object
349 SCIC_SDS_REMOTE_DEVICE_T * this_device = (SCIC_SDS_REMOTE_DEVICE_T *)object;
351 this_device->working_request = NULL;
354 // ---------------------------------------------------------------------------
357 scic_sds_smp_remote_device_ready_substate_table[
358 SCIC_SDS_SMP_REMOTE_DEVICE_READY_MAX_SUBSTATES] =
361 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
362 scic_sds_smp_remote_device_ready_idle_substate_enter,
366 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
367 scic_sds_smp_remote_device_ready_cmd_substate_enter,
368 scic_sds_smp_remote_device_ready_cmd_substate_exit