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 the implementation of the
60 * SCIF_SAS_INTERNAL_IO_REQUEST object.
64 #include <dev/isci/scil/scic_io_request.h>
65 #include <dev/isci/scil/scic_remote_device.h>
66 #include <dev/isci/scil/scic_user_callback.h>
67 #include <dev/isci/scil/scic_controller.h>
68 #include <dev/isci/scil/scic_task_request.h>
69 #include <dev/isci/scil/scif_user_callback.h>
71 #include <dev/isci/scil/scif_sas_controller.h>
72 #include <dev/isci/scil/scif_sas_domain.h>
73 #include <dev/isci/scil/scif_sas_remote_device.h>
74 #include <dev/isci/scil/scif_sas_io_request.h>
75 #include <dev/isci/scil/scif_sas_internal_io_request.h>
76 #include <dev/isci/scil/scif_sas_task_request.h>
77 #include <dev/isci/scil/scif_sas_stp_io_request.h>
78 #include <dev/isci/scil/scif_sas_logger.h>
79 #include <dev/isci/scil/scif_sas_smp_io_request.h>
80 #include <dev/isci/scil/sci_util.h>
82 //******************************************************************************
83 //* P U B L I C M E T H O D S
84 //******************************************************************************
87 * @brief this routine return all memory needed for an internal request, both
88 * framework and core request.
90 * @return U32 size of all memory needed for an internal request
92 U32 scif_sas_internal_request_get_object_size(
97 (sizeof(SCIF_SAS_INTERNAL_IO_REQUEST_T) + scic_io_request_get_object_size()),
98 (sizeof(SCIF_SAS_TASK_REQUEST_T) + scic_task_request_get_object_size())
104 * @brief This method constructs an internal smp request.
106 * @param[in] fw_controller The framework controller
107 * @param[in] fw_device The smp device that the internal io targets to.
108 * @param[in] internal_io_memory The memory space for the internal io.
109 * @param[in] io_tag The io tag for the internl io to be constructed.
110 * @param[in] smp_command A pointer to the smp request data structure according
113 * @return Indicate if the internal io was successfully constructed.
114 * @retval SCI_SUCCESS This value is returned if the internal io was
115 * successfully constructed.
116 * @retval SCI_FAILURE This value is returned if the internal io was failed to
119 SCI_STATUS scif_sas_internal_io_request_construct_smp(
120 SCIF_SAS_CONTROLLER_T * fw_controller,
121 SCIF_SAS_REMOTE_DEVICE_T * fw_device,
122 void * internal_io_memory,
124 SMP_REQUEST_T * smp_command
127 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io =
128 (SCIF_SAS_INTERNAL_IO_REQUEST_T*)internal_io_memory;
130 SCIF_SAS_IO_REQUEST_T * fw_io =
131 (SCIF_SAS_IO_REQUEST_T*)internal_io_memory;
135 //call common smp request construct routine.
136 status = scif_sas_io_request_construct_smp(
140 (char *)internal_io_memory + sizeof(SCIF_SAS_INTERNAL_IO_REQUEST_T),
141 SCI_CONTROLLER_INVALID_IO_TAG,
143 NULL //there is no associated user io object.
146 //Codes below are all internal io related.
147 if (status == SCI_SUCCESS)
149 //set the is_internal flag
150 fw_io->parent.is_internal = TRUE;
152 if (fw_internal_io->internal_io_timer == NULL)
154 //create the timer for this internal request.
155 fw_internal_io->internal_io_timer =
156 scif_cb_timer_create(
157 (SCI_CONTROLLER_HANDLE_T *)fw_controller,
158 scif_sas_internal_io_request_timeout_handler,
167 //insert into high priority queue
168 if ( !sci_pool_full(fw_controller->hprq.pool) )
171 fw_controller->hprq.pool, (POINTER_UINT) internal_io_memory
177 sci_base_object_get_logger(fw_controller),
178 SCIF_LOG_OBJECT_CONTROLLER | SCIF_LOG_OBJECT_REMOTE_DEVICE,
179 "scif_sas_internal_io_request_construct_smp, high priority queue full!\n"
182 scif_sas_internal_io_request_destruct(fw_controller, fw_internal_io);
184 //return failure status.
185 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
194 * @brief This method constructs an internal smp request.
199 SCI_STATUS scif_sas_internal_io_request_construct_stp(
200 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_io
209 * @brief This method handles the timeout situation for an internal io.
211 * @param[in] fw_internal_io The timed out IO.
215 void scif_sas_internal_io_request_timeout_handler(
216 void * fw_internal_io
219 SCIF_SAS_REQUEST_T * fw_request = (SCIF_SAS_REQUEST_T *)fw_internal_io;
222 sci_base_object_get_logger(fw_request),
223 SCIF_LOG_OBJECT_IO_REQUEST,
224 "scif_sas_internal_io_request_timeout_handler(0x%x) enter\n",
228 fw_request->state_handlers->abort_handler(&fw_request->parent);
233 * @brief This methods takes care of completion of an internal request about its
234 * "internal" related feature, including the memory recycling and timer.
236 * @param[in] fw_controller The framework controller object.
237 * @param[in] fw_internal_io The internal io to be completed.
238 * @param[in] completion_status the completeion status by core and framework so
243 void scif_sas_internal_io_request_complete(
244 SCIF_SAS_CONTROLLER_T * fw_controller,
245 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io,
246 SCI_STATUS completion_status
250 sci_base_object_get_logger(fw_controller),
251 SCIF_LOG_OBJECT_IO_REQUEST,
252 "scif_sas_internal_io_request_complete(0x%x, 0x%x, 0x%x) enter\n",
253 fw_controller, fw_internal_io, completion_status
256 scif_cb_timer_stop(fw_controller, fw_internal_io->internal_io_timer);
257 scif_sas_internal_io_request_destruct(fw_controller, fw_internal_io);
262 * @brief This methods takes care of destruction of an internal request about its
263 * "internal" related feature, including the memory recycling and timer.
265 * @param[in] fw_controller The framework controller object.
266 * @param[in] fw_internal_io The internal io to be completed.
270 void scif_sas_internal_io_request_destruct(
271 SCIF_SAS_CONTROLLER_T * fw_controller,
272 SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io
275 if (fw_internal_io->internal_io_timer != NULL)
277 scif_cb_timer_destroy(fw_controller, fw_internal_io->internal_io_timer);
278 fw_internal_io->internal_io_timer = NULL;
280 scif_sas_controller_free_internal_request(fw_controller, fw_internal_io);