scif_sas_internal_io_request.c revision 231134
16866Sstefank/*-
211833Sctornqvi * This file is provided under a dual BSD/GPLv2 license.  When using or
36866Sstefank * redistributing this file, you may do so under either license.
46866Sstefank *
56866Sstefank * GPL LICENSE SUMMARY
66866Sstefank *
76866Sstefank * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
86866Sstefank *
96866Sstefank * This program is free software; you can redistribute it and/or modify
106866Sstefank * it under the terms of version 2 of the GNU General Public License as
116866Sstefank * published by the Free Software Foundation.
126866Sstefank *
136866Sstefank * This program is distributed in the hope that it will be useful, but
146866Sstefank * WITHOUT ANY WARRANTY; without even the implied warranty of
156866Sstefank * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
166866Sstefank * General Public License for more details.
176866Sstefank *
186866Sstefank * You should have received a copy of the GNU General Public License
196866Sstefank * along with this program; if not, write to the Free Software
206866Sstefank * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
216866Sstefank * The full GNU General Public License is included in this distribution
226866Sstefank * in the file called LICENSE.GPL.
236866Sstefank *
246866Sstefank * BSD LICENSE
256866Sstefank *
266866Sstefank * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
2711833Sctornqvi * All rights reserved.
2810551Schegar *
298013Sykantser * Redistribution and use in source and binary forms, with or without
3011833Sctornqvi * modification, are permitted provided that the following conditions
316866Sstefank * are met:
326866Sstefank *
336866Sstefank *   * Redistributions of source code must retain the above copyright
346866Sstefank *     notice, this list of conditions and the following disclaimer.
356866Sstefank *   * Redistributions in binary form must reproduce the above copyright
368359Sykantser *     notice, this list of conditions and the following disclaimer in
376866Sstefank *     the documentation and/or other materials provided with the
386866Sstefank *     distribution.
396866Sstefank *
406866Sstefank * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
416866Sstefank * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
426866Sstefank * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
436866Sstefank * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
446866Sstefank * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
456866Sstefank * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
466866Sstefank * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
476866Sstefank * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
486866Sstefank * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
496866Sstefank * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
506866Sstefank * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
516866Sstefank */
526866Sstefank
53#include <sys/cdefs.h>
54__FBSDID("$FreeBSD$");
55
56/**
57 * @file
58 *
59 * @brief This file contains the implementation of the
60 *        SCIF_SAS_INTERNAL_IO_REQUEST object.
61 */
62
63
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>
70
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>
81
82//******************************************************************************
83//* P U B L I C   M E T H O D S
84//******************************************************************************
85
86/**
87 * @brief this routine return all memory needed for an internal request, both
88 *        framework and core request.
89 *
90 * @return U32 size of all memory needed for an internal request
91 */
92U32 scif_sas_internal_request_get_object_size(
93   void
94)
95{
96   return MAX(
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())
99             );
100}
101
102
103/**
104 * @brief This method constructs an internal smp request.
105 *
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
111 *       to SAS protocol.
112 *
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
117 *         be constructed.
118 */
119SCI_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,
123   U16                           io_tag,
124   SMP_REQUEST_T               * smp_command
125)
126{
127   SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io  =
128     (SCIF_SAS_INTERNAL_IO_REQUEST_T*)internal_io_memory;
129
130   SCIF_SAS_IO_REQUEST_T * fw_io =
131     (SCIF_SAS_IO_REQUEST_T*)internal_io_memory;
132
133   SCI_STATUS status;
134
135   //call common smp request construct routine.
136   status = scif_sas_io_request_construct_smp(
137               fw_controller,
138               fw_device,
139               internal_io_memory,
140               (char *)internal_io_memory + sizeof(SCIF_SAS_INTERNAL_IO_REQUEST_T),
141               SCI_CONTROLLER_INVALID_IO_TAG,
142               smp_command,
143               NULL //there is no associated user io object.
144            );
145
146   //Codes below are all internal io related.
147   if (status == SCI_SUCCESS)
148   {
149      //set the is_internal flag
150      fw_io->parent.is_internal = TRUE;
151
152      if (fw_internal_io->internal_io_timer == NULL)
153      {
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,
159               (void*)fw_io
160            );
161      }
162      else
163      {
164         ASSERT (0);
165      }
166
167      //insert into high priority queue
168      if ( !sci_pool_full(fw_controller->hprq.pool) )
169      {
170         sci_pool_put(
171            fw_controller->hprq.pool, (POINTER_UINT) internal_io_memory
172         );
173      }
174      else
175      {
176         SCIF_LOG_ERROR((
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"
180         ));
181
182         scif_sas_internal_io_request_destruct(fw_controller, fw_internal_io);
183
184         //return failure status.
185         return SCI_FAILURE_INSUFFICIENT_RESOURCES;
186      }
187   }
188
189   return status;
190}
191
192
193/**
194 * @brief This method constructs an internal smp request.
195 * @param[in] fw_io
196 *
197 * @return SCI_STATUS
198 */
199SCI_STATUS scif_sas_internal_io_request_construct_stp(
200   SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_io
201)
202{
203   //TBD
204   return SCI_SUCCESS;
205}
206
207
208/**
209 * @brief This method handles the timeout situation for an internal io.
210 *
211 * @param[in] fw_internal_io The timed out IO.
212 *
213 * @return none
214 */
215void scif_sas_internal_io_request_timeout_handler(
216   void * fw_internal_io
217)
218{
219   SCIF_SAS_REQUEST_T * fw_request = (SCIF_SAS_REQUEST_T *)fw_internal_io;
220
221   SCIF_LOG_TRACE((
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",
225      fw_internal_io
226   ));
227
228   fw_request->state_handlers->abort_handler(&fw_request->parent);
229}
230
231
232/**
233 * @brief This methods takes care of completion of an internal request about its
234 *        "internal" related feature, including the memory recycling and timer.
235 *
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
239 *       far.
240 *
241 * @return none
242 */
243void 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
247)
248{
249   SCIF_LOG_TRACE((
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
254   ));
255
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);
258}
259
260
261/**
262 * @brief This methods takes care of destruction of an internal request about its
263 *        "internal" related feature, including the memory recycling and timer.
264 *
265 * @param[in] fw_controller The framework controller object.
266 * @param[in] fw_internal_io The internal io to be completed.
267 *
268 * @return none
269 */
270void scif_sas_internal_io_request_destruct(
271   SCIF_SAS_CONTROLLER_T          * fw_controller,
272   SCIF_SAS_INTERNAL_IO_REQUEST_T * fw_internal_io
273)
274{
275   if (fw_internal_io->internal_io_timer != NULL)
276   {
277      scif_cb_timer_destroy(fw_controller, fw_internal_io->internal_io_timer);
278      fw_internal_io->internal_io_timer = NULL;
279   }
280   scif_sas_controller_free_internal_request(fw_controller, fw_internal_io);
281}
282
283