2 * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
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.
9 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
28 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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
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.
55 #include <sys/cdefs.h>
56 __FBSDID("$FreeBSD$");
61 * @brief This file contains the implementation of the
62 * SCIF_SAS_INTERNAL_IO_REQUEST object.
66 #include <dev/isci/scil/scic_io_request.h>
67 #include <dev/isci/scil/scic_remote_device.h>
68 #include <dev/isci/scil/scic_user_callback.h>
69 #include <dev/isci/scil/scic_controller.h>
70 #include <dev/isci/scil/scic_task_request.h>
71 #include <dev/isci/scil/scif_user_callback.h>
73 #include <dev/isci/scil/scif_sas_controller.h>
74 #include <dev/isci/scil/scif_sas_domain.h>
75 #include <dev/isci/scil/scif_sas_remote_device.h>
76 #include <dev/isci/scil/scif_sas_io_request.h>
77 #include <dev/isci/scil/scif_sas_internal_io_request.h>
78 #include <dev/isci/scil/scif_sas_task_request.h>
79 #include <dev/isci/scil/scif_sas_stp_io_request.h>
80 #include <dev/isci/scil/scif_sas_logger.h>
81 #include <dev/isci/scil/scif_sas_smp_io_request.h>
82 #include <dev/isci/scil/sci_util.h>
84 //******************************************************************************
85 //* P U B L I C M E T H O D S
86 //******************************************************************************
89 * @brief this routine return all memory needed for an internal request, both
90 * framework and core request.
92 * @return U32 size of all memory needed for an internal request
94 U32 scif_sas_internal_request_get_object_size(
99 (sizeof(SCIF_SAS_INTERNAL_IO_REQUEST_T) + scic_io_request_get_object_size()),
100 (sizeof(SCIF_SAS_TASK_REQUEST_T) + scic_task_request_get_object_size())
106 * @brief This method constructs an internal smp request.
108 * @param[in] fw_controller The framework controller
109 * @param[in] fw_device The smp device that the internal io targets to.
110 * @param[in] internal_io_memory The memory space for the internal io.
111 * @param[in] io_tag The io tag for the internl io to be constructed.
112 * @param[in] smp_command A pointer to the smp request data structure according
115 * @return Indicate if the internal io was successfully constructed.
116 * @retval SCI_SUCCESS This value is returned if the internal io was
117 * successfully constructed.
118 * @retval SCI_FAILURE This value is returned if the internal io was failed to
121 SCI_STATUS scif_sas_internal_io_request_construct_smp(
122 SCIF_SAS_CONTROLLER_T * fw_controller,
123 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
124 void * internal_io_memory,
126 SMP_REQUEST_T * smp_command
129 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io =
130 (SCIF_SAS_INTERNAL_IO_REQUEST_T*)internal_io_memory;
132 SCIF_SAS_IO_REQUEST_T * fw_io =
133 (SCIF_SAS_IO_REQUEST_T*)internal_io_memory;
137 //call common smp request construct routine.
138 status = scif_sas_io_request_construct_smp(
142 (char *)internal_io_memory + sizeof(SCIF_SAS_INTERNAL_IO_REQUEST_T),
143 SCI_CONTROLLER_INVALID_IO_TAG,
145 NULL //there is no associated user io object.
148 //Codes below are all internal io related.
149 if (status == SCI_SUCCESS)
151 //set the is_internal flag
152 fw_io->parent.is_internal = TRUE;
154 if (fw_internal_io->internal_io_timer == NULL)
156 //create the timer for this internal request.
157 fw_internal_io->internal_io_timer =
158 scif_cb_timer_create(
159 (SCI_CONTROLLER_HANDLE_T *)fw_controller,
160 scif_sas_internal_io_request_timeout_handler,
169 //insert into high priority queue
170 if ( !sci_pool_full(fw_controller->hprq.pool) )
173 fw_controller->hprq.pool, (POINTER_UINT) internal_io_memory
179 sci_base_object_get_logger(fw_controller),
180 SCIF_LOG_OBJECT_CONTROLLER | SCIF_LOG_OBJECT_REMOTE_DEVICE,
181 "scif_sas_internal_io_request_construct_smp, high priority queue full!\n"
184 scif_sas_internal_io_request_destruct(fw_controller, fw_internal_io);
186 //return failure status.
187 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
196 * @brief This method constructs an internal smp request.
201 SCI_STATUS scif_sas_internal_io_request_construct_stp(
202 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_io
211 * @brief This method handles the timeout situation for an internal io.
213 * @param[in] fw_internal_io The timed out IO.
217 void scif_sas_internal_io_request_timeout_handler(
218 void * fw_internal_io
221 SCIF_SAS_REQUEST_T * fw_request = (SCIF_SAS_REQUEST_T *)fw_internal_io;
224 sci_base_object_get_logger(fw_request),
225 SCIF_LOG_OBJECT_IO_REQUEST,
226 "scif_sas_internal_io_request_timeout_handler(0x%x) enter\n",
230 fw_request->state_handlers->abort_handler(&fw_request->parent);
235 * @brief This methods takes care of completion of an internal request about its
236 * "internal" related feature, including the memory recycling and timer.
238 * @param[in] fw_controller The framework controller object.
239 * @param[in] fw_internal_io The internal io to be completed.
240 * @param[in] completion_status the completeion status by core and framework so
245 void scif_sas_internal_io_request_complete(
246 SCIF_SAS_CONTROLLER_T * fw_controller,
247 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io,
248 SCI_STATUS completion_status
252 sci_base_object_get_logger(fw_controller),
253 SCIF_LOG_OBJECT_IO_REQUEST,
254 "scif_sas_internal_io_request_complete(0x%x, 0x%x, 0x%x) enter\n",
255 fw_controller, fw_internal_io, completion_status
258 scif_cb_timer_stop(fw_controller, fw_internal_io->internal_io_timer);
259 scif_sas_internal_io_request_destruct(fw_controller, fw_internal_io);
264 * @brief This methods takes care of destruction of an internal request about its
265 * "internal" related feature, including the memory recycling and timer.
267 * @param[in] fw_controller The framework controller object.
268 * @param[in] fw_internal_io The internal io to be completed.
272 void scif_sas_internal_io_request_destruct(
273 SCIF_SAS_CONTROLLER_T * fw_controller,
274 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io
277 if (fw_internal_io->internal_io_timer != NULL)
279 scif_cb_timer_destroy(fw_controller, fw_internal_io->internal_io_timer);
280 fw_internal_io->internal_io_timer = NULL;
282 scif_sas_controller_free_internal_request(fw_controller, fw_internal_io);