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.
54 #ifndef _SCIC_SDS_IO_REQUEST_H_
55 #define _SCIC_SDS_IO_REQUEST_H_
60 * @brief This file contains the structures, constants and prototypes for the
61 * SCIC_SDS_IO_REQUEST object.
68 #include <sys/param.h>
70 #include <dev/isci/scil/scic_io_request.h>
72 #include <dev/isci/scil/sci_base_request.h>
73 #include <dev/isci/scil/sci_base_state_machine_logger.h>
74 #include <dev/isci/scil/scu_task_context.h>
75 #include <dev/isci/scil/intel_sas.h>
77 struct SCIC_SDS_CONTROLLER;
78 struct SCIC_SDS_REMOTE_DEVICE;
79 struct SCIC_SDS_IO_REQUEST_STATE_HANDLER;
82 * @enum _SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATES
84 * @brief This enumeration depicts all of the substates for a task
85 * management request to be performed in the STARTED super-state.
87 typedef enum _SCIC_SDS_RAW_REQUEST_STARTED_TASK_MGMT_SUBSTATES
90 * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
91 * task management request is waiting for the transmission of the
92 * initial frame (i.e. command, task, etc.).
94 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION,
97 * This sub-state indicates that the started task management request
98 * is waiting for the reception of an unsolicited frame
101 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE,
103 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_MAX_SUBSTATES
105 } SCIC_SDS_RAW_REQUEST_STARTED_TASK_MGMT_SUBSTATES;
109 * @enum _SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATES
111 * @brief This enumeration depicts all of the substates for a SMP
112 * request to be performed in the STARTED super-state.
114 typedef enum _SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATES
117 * This sub-state indicates that the started task management request
118 * is waiting for the reception of an unsolicited frame
119 * (i.e. response IU).
121 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE,
124 * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP request is
125 * waiting for the transmission of the initial frame (i.e. command, task, etc.).
127 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION,
129 SCIC_SDS_SMP_REQUEST_STARTED_MAX_SUBSTATES
131 } SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATES;
134 * @struct SCIC_SDS_IO_REQUEST
136 * @brief This structure contains or references all of the data necessary
137 * to process a task management or normal IO request.
139 typedef struct SCIC_SDS_REQUEST
142 * This field indictes the parent object of the request.
144 SCI_BASE_REQUEST_T parent;
149 * This field simply points to the controller to which this IO request
152 struct SCIC_SDS_CONTROLLER *owning_controller;
155 * This field simply points to the remote device to which this IO request
158 struct SCIC_SDS_REMOTE_DEVICE *target_device;
161 * This field is utilized to determine if the SCI user is managing
162 * the IO tag for this request or if the core is managing it.
164 BOOL was_tag_assigned_by_user;
167 * This field indicates the IO tag for this request. The IO tag is
168 * comprised of the task_index and a sequence count. The sequence count
169 * is utilized to help identify tasks from one life to another.
174 * This field specifies the sat protocol being utilized for this
175 * IO request, such as SAT_PROTOCOL_PIO_DATA_IN, SAT_PROTOCOL_FPDMA etc.
180 * This field specifies the protocol being utilized for this
183 SCIC_TRANSPORT_PROTOCOL protocol;
186 * This field indicates the completion status taken from the SCUs
187 * completion code. It indicates the completion result for the SCU hardware.
192 * This field indicates the completion status returned to the SCI user. It
193 * indicates the users view of the io request completion.
198 * This field contains the value to be utilized when posting (e.g. Post_TC,
199 * Post_TC_Abort) this request to the silicon.
203 void *command_buffer;
204 void *response_buffer;
205 SCU_TASK_CONTEXT_T *task_context_buffer;
206 SCU_SGL_ELEMENT_PAIR_T *sgl_element_pair_buffer;
209 * This field indicates if this request is a task management request or
212 BOOL is_task_management_request;
215 * This field indicates that this request contains an initialized started
218 BOOL has_started_substate_machine;
221 * This field is a pointer to the stored rx frame data. It is used in STP
222 * internal requests and SMP response frames. If this field is non-NULL the
223 * saved frame must be released on IO request completion.
225 * @todo In the future do we want to keep a list of RX frame buffers?
227 U32 saved_rx_frame_index;
230 * This field specifies the data necessary to manage the sub-state
231 * machine executed while in the SCI_BASE_REQUEST_STATE_STARTED state.
233 SCI_BASE_STATE_MACHINE_T started_substate_machine;
236 * This field specifies the current state handlers in place for this
237 * IO Request object. This field is updated each time the request
240 struct SCIC_SDS_IO_REQUEST_STATE_HANDLER *state_handlers;
244 * This field is the observer of the started subsate machine
246 SCI_BASE_STATE_MACHINE_LOGGER_T started_substate_machine_logger;
250 * This field in the recorded device sequence for the io request. This is
251 * recorded during the build operation and is compared in the start
252 * operation. If the sequence is different then there was a change of
253 * devices from the build to start operations.
257 } SCIC_SDS_REQUEST_T;
260 typedef SCI_STATUS (*SCIC_SDS_IO_REQUEST_FRAME_HANDLER_T)(
261 SCIC_SDS_REQUEST_T * this_request,
264 typedef SCI_STATUS (*SCIC_SDS_IO_REQUEST_EVENT_HANDLER_T)(
265 SCIC_SDS_REQUEST_T * this_request,
268 typedef SCI_STATUS (*SCIC_SDS_IO_REQUEST_TASK_COMPLETION_HANDLER_T)(
269 SCIC_SDS_REQUEST_T * this_request,
270 U32 completion_code);
273 * @struct SCIC_SDS_IO_REQUEST_STATE_HANDLER
275 * @brief This is the SDS core definition of the state handlers.
277 typedef struct SCIC_SDS_IO_REQUEST_STATE_HANDLER
279 SCI_BASE_REQUEST_STATE_HANDLER_T parent;
281 SCIC_SDS_IO_REQUEST_TASK_COMPLETION_HANDLER_T tc_completion_handler;
282 SCIC_SDS_IO_REQUEST_EVENT_HANDLER_T event_handler;
283 SCIC_SDS_IO_REQUEST_FRAME_HANDLER_T frame_handler;
285 } SCIC_SDS_IO_REQUEST_STATE_HANDLER_T;
287 extern SCI_BASE_STATE_T scic_sds_request_state_table[];
288 extern SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
289 scic_sds_request_state_handler_table[];
291 extern SCI_BASE_STATE_T scic_sds_io_request_started_task_mgmt_substate_table[];
292 extern SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
293 scic_sds_ssp_task_request_started_substate_handler_table[];
295 extern SCI_BASE_STATE_T scic_sds_smp_request_started_substate_table[];
296 extern SCIC_SDS_IO_REQUEST_STATE_HANDLER_T
297 scic_sds_smp_request_started_substate_handler_table[];
300 * This macro returns the maximum number of SGL element paris that we will
301 * support in a single IO request.
303 #define SCU_MAX_SGL_ELEMENT_PAIRS ((SCU_IO_REQUEST_SGE_COUNT + 1) / 2)
306 * This macro will return the controller for this io request object
308 #define scic_sds_request_get_controller(this_request) \
309 ((this_request)->owning_controller)
312 * This macro will return the device for this io request object
314 #define scic_sds_request_get_device(this_request) \
315 ((this_request)->target_device)
318 * This macro will return the port for this io request object
320 #define scic_sds_request_get_port(this_request) \
321 scic_sds_remote_device_get_port(scic_sds_request_get_device(this_request))
324 * This macro returns the constructed post context result for the io
327 #define scic_sds_request_get_post_context(this_request) \
328 ((this_request)->post_context)
331 * This is a helper macro to return the os handle for this request object.
333 #define scic_sds_request_get_task_context(request) \
334 ((request)->task_context_buffer)
336 #define scic_sds_request_align_task_context_buffer(address) \
337 ((SCU_TASK_CONTEXT_T *)( \
338 (((POINTER_UINT)(address)) + (CACHE_LINE_SIZE - 1)) \
339 & ~(CACHE_LINE_SIZE - 1) \
343 * This macro will align the memory address so that it is correct for the SCU
344 * hardware to DMA the SGL element pairs.
346 #define scic_sds_request_align_sgl_element_buffer(address) \
347 ((SCU_SGL_ELEMENT_PAIR_T *)( \
348 ((char *)(address)) \
350 ((~(POINTER_UINT)(address)) + 1) \
351 & (sizeof(SCU_SGL_ELEMENT_PAIR_T) - 1) \
356 * This macro will set the scu hardware status and sci request completion
357 * status for an io request.
359 #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \
361 (request)->scu_status = (scu_status_code); \
362 (request)->sci_status = (sci_status_code); \
365 #define scic_sds_request_complete(a_request) \
366 ((a_request)->state_handlers->parent.complete_handler(&(a_request)->parent))
368 U32 scic_sds_request_get_min_timer_count(void);
370 U32 scic_sds_request_get_max_timer_count(void);
374 * This macro invokes the core state task completion handler for the
375 * SCIC_SDS_IO_REQUEST_T object.
377 #define scic_sds_io_request_tc_completion(this_request, completion_code) \
379 if (this_request->parent.state_machine.current_state_id \
380 == SCI_BASE_REQUEST_STATE_STARTED \
381 && this_request->has_started_substate_machine \
383 scic_sds_request_started_state_tc_completion_handler(this_request, completion_code); \
385 this_request->state_handlers->tc_completion_handler(this_request, completion_code); \
389 * This macro zeros the hardware SGL element data
391 #define SCU_SGL_ZERO(scu_sge) \
393 (scu_sge).length = 0; \
394 (scu_sge).address_lower = 0; \
395 (scu_sge).address_upper = 0; \
396 (scu_sge).address_modifier = 0; \
400 * This macro copys the SGL Element data from the host os to the hardware SGL
403 #define SCU_SGL_COPY(os_handle, scu_sge, os_sge) \
406 scic_cb_sge_get_length_field(os_handle, os_sge); \
407 (scu_sge).address_upper = \
408 sci_cb_physical_address_upper(scic_cb_sge_get_address_field(os_handle, os_sge)); \
409 (scu_sge).address_lower = \
410 sci_cb_physical_address_lower(scic_cb_sge_get_address_field(os_handle, os_sge)); \
411 (scu_sge).address_modifier = 0; \
414 //*****************************************************************************
415 //* CORE REQUEST PROTOTYPES
416 //*****************************************************************************
418 SCU_SGL_ELEMENT_PAIR_T *scic_sds_request_get_sgl_element_pair(
419 SCIC_SDS_REQUEST_T *this_request,
423 void scic_sds_request_build_sgl(
424 SCIC_SDS_REQUEST_T *this_request
427 void scic_sds_ssp_io_request_assign_buffers(
428 SCIC_SDS_REQUEST_T *this_request
431 void scic_sds_ssp_task_request_assign_buffers(
432 SCIC_SDS_REQUEST_T *this_request
435 void scic_sds_stp_request_assign_buffers(
436 SCIC_SDS_REQUEST_T * this_request
439 void scic_sds_smp_request_assign_buffers(
440 SCIC_SDS_REQUEST_T * this_request
443 // ---------------------------------------------------------------------------
445 SCI_STATUS scic_sds_request_start(
446 SCIC_SDS_REQUEST_T *this_request
449 SCI_STATUS scic_sds_io_request_terminate(
450 SCIC_SDS_REQUEST_T *this_request
453 SCI_STATUS scic_sds_io_request_complete(
454 SCIC_SDS_REQUEST_T *this_request
457 void scic_sds_io_request_copy_response(
458 SCIC_SDS_REQUEST_T *this_request
461 SCI_STATUS scic_sds_io_request_event_handler(
462 SCIC_SDS_REQUEST_T *this_request,
466 SCI_STATUS scic_sds_io_request_frame_handler(
467 SCIC_SDS_REQUEST_T *this_request,
471 SCI_STATUS scic_sds_task_request_complete(
472 SCIC_SDS_REQUEST_T *this_request
475 SCI_STATUS scic_sds_task_request_terminate(
476 SCIC_SDS_REQUEST_T *this_request
480 void scic_sds_request_initialize_state_logging(
481 SCIC_SDS_REQUEST_T *this_request
484 void scic_sds_request_deinitialize_state_logging(
485 SCIC_SDS_REQUEST_T *this_request
488 #define scic_sds_request_initialize_state_logging(x)
489 #define scic_sds_request_deinitialize_state_logging(x)
490 #endif // SCI_LOGGING
492 //*****************************************************************************
493 //* DEFAULT STATE HANDLERS
494 //*****************************************************************************
496 SCI_STATUS scic_sds_request_default_start_handler(
497 SCI_BASE_REQUEST_T *this_request
500 SCI_STATUS scic_sds_request_default_abort_handler(
501 SCI_BASE_REQUEST_T *this_request
504 SCI_STATUS scic_sds_request_default_complete_handler(
505 SCI_BASE_REQUEST_T *this_request
508 SCI_STATUS scic_sds_request_default_destruct_handler(
509 SCI_BASE_REQUEST_T *this_request
512 SCI_STATUS scic_sds_request_default_tc_completion_handler(
513 SCIC_SDS_REQUEST_T * this_request,
517 SCI_STATUS scic_sds_request_default_event_handler(
518 SCIC_SDS_REQUEST_T * this_request,
522 SCI_STATUS scic_sds_request_default_frame_handler(
523 SCIC_SDS_REQUEST_T * this_request,
527 //*****************************************************************************
528 //* STARTED STATE HANDLERS
529 //*****************************************************************************
531 SCI_STATUS scic_sds_request_started_state_abort_handler(
532 SCI_BASE_REQUEST_T *this_request
535 SCI_STATUS scic_sds_request_started_state_tc_completion_handler(
536 SCIC_SDS_REQUEST_T * this_request,
542 #endif // __cplusplus
544 #endif // _SCIC_SDS_IO_REQUEST_H_