isci: Remove event_* calls as they are just wrappers
[linux-2.6-microblaze.git] / drivers / scsi / isci / core / scic_sds_request.h
1 /*
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.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
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.
12  *
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.
17  *
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.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
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
38  *     distribution.
39  *   * Neither the name of Intel Corporation nor the names of its
40  *     contributors may be used to endorse or promote products derived
41  *     from this software without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  */
55
56 #ifndef _SCIC_SDS_IO_REQUEST_H_
57 #define _SCIC_SDS_IO_REQUEST_H_
58
59 /**
60  * This file contains the structures, constants and prototypes for the
61  *    SCIC_SDS_IO_REQUEST object.
62  *
63  *
64  */
65
66 #include "scic_io_request.h"
67
68 #include "sci_base_request.h"
69 #include "scu_task_context.h"
70 #include "intel_sas.h"
71
72 struct scic_sds_controller;
73 struct scic_sds_remote_device;
74 struct scic_sds_io_request_state_handler;
75
76 /**
77  * enum _SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATES - This enumeration
78  *    depicts all of the substates for a task management request to be
79  *    performed in the STARTED super-state.
80  *
81  *
82  */
83 enum scic_sds_raw_request_started_task_mgmt_substates {
84         /**
85          * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
86          * task management request is waiting for the transmission of the
87          * initial frame (i.e. command, task, etc.).
88          */
89         SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION,
90
91         /**
92          * This sub-state indicates that the started task management request
93          * is waiting for the reception of an unsolicited frame
94          * (i.e. response IU).
95          */
96         SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE,
97 };
98
99
100 /**
101  * enum _SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATES - This enumeration depicts all
102  *    of the substates for a SMP request to be performed in the STARTED
103  *    super-state.
104  *
105  *
106  */
107 enum scic_sds_smp_request_started_substates {
108         /**
109          * This sub-state indicates that the started task management request
110          * is waiting for the reception of an unsolicited frame
111          * (i.e. response IU).
112          */
113         SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE,
114
115         /**
116          * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP request is
117          * waiting for the transmission of the initial frame (i.e. command, task, etc.).
118          */
119         SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION,
120 };
121
122 /**
123  * struct SCIC_SDS_IO_REQUEST - This structure contains or references all of
124  *    the data necessary to process a task management or normal IO request.
125  *
126  *
127  */
128 struct scic_sds_request {
129         /**
130          * This field indictes the parent object of the request.
131          */
132         struct sci_base_request parent;
133
134         void *user_request;
135
136         /**
137          * This field simply points to the controller to which this IO request
138          * is associated.
139          */
140         struct scic_sds_controller *owning_controller;
141
142         /**
143          * This field simply points to the remote device to which this IO request
144          * is associated.
145          */
146         struct scic_sds_remote_device *target_device;
147
148         /**
149          * This field is utilized to determine if the SCI user is managing
150          * the IO tag for this request or if the core is managing it.
151          */
152         bool was_tag_assigned_by_user;
153
154         /**
155          * This field indicates the IO tag for this request.  The IO tag is
156          * comprised of the task_index and a sequence count. The sequence count
157          * is utilized to help identify tasks from one life to another.
158          */
159         u16 io_tag;
160
161         /**
162          * This field specifies the protocol being utilized for this
163          * IO request.
164          */
165         SCIC_TRANSPORT_PROTOCOL protocol;
166
167         /**
168          * This field indicates the completion status taken from the SCUs
169          * completion code.  It indicates the completion result for the SCU hardware.
170          */
171         u32 scu_status;
172
173         /**
174          * This field indicates the completion status returned to the SCI user.  It
175          * indicates the users view of the io request completion.
176          */
177         u32 sci_status;
178
179         /**
180          * This field contains the value to be utilized when posting (e.g. Post_TC,
181          * Post_TC_Abort) this request to the silicon.
182          */
183         u32 post_context;
184
185         void *command_buffer;
186         void *response_buffer;
187         struct scu_task_context *task_context_buffer;
188         struct scu_sgl_element_pair *sgl_element_pair_buffer;
189
190         /**
191          * This field indicates if this request is a task management request or
192          * normal IO request.
193          */
194         bool is_task_management_request;
195
196         /**
197          * This field indicates that this request contains an initialized started
198          * substate machine.
199          */
200         bool has_started_substate_machine;
201
202         /**
203          * This field is a pointer to the stored rx frame data.  It is used in STP
204          * internal requests and SMP response frames.  If this field is non-NULL the
205          * saved frame must be released on IO request completion.
206          *
207          * @todo In the future do we want to keep a list of RX frame buffers?
208          */
209         u32 saved_rx_frame_index;
210
211         /**
212          * This field specifies the data necessary to manage the sub-state
213          * machine executed while in the SCI_BASE_REQUEST_STATE_STARTED state.
214          */
215         struct sci_base_state_machine started_substate_machine;
216
217         /**
218          * This field specifies the current state handlers in place for this
219          * IO Request object.  This field is updated each time the request
220          * changes state.
221          */
222         const struct scic_sds_io_request_state_handler *state_handlers;
223
224         /**
225          * This field in the recorded device sequence for the io request.  This is
226          * recorded during the build operation and is compared in the start
227          * operation.  If the sequence is different then there was a change of
228          * devices from the build to start operations.
229          */
230         u8 device_sequence;
231
232 };
233
234
235 typedef enum sci_status
236 (*scic_sds_io_request_frame_handler_t)(struct scic_sds_request *req, u32 frame);
237
238 typedef enum sci_status
239 (*scic_sds_io_request_event_handler_t)(struct scic_sds_request *req, u32 event);
240
241 typedef enum sci_status
242 (*scic_sds_io_request_task_completion_handler_t)(struct scic_sds_request *req, u32 completion_code);
243
244 /**
245  * struct scic_sds_io_request_state_handler - This is the SDS core definition
246  *    of the state handlers.
247  *
248  *
249  */
250 struct scic_sds_io_request_state_handler {
251         struct sci_base_request_state_handler parent;
252
253         scic_sds_io_request_task_completion_handler_t tc_completion_handler;
254         scic_sds_io_request_event_handler_t event_handler;
255         scic_sds_io_request_frame_handler_t frame_handler;
256
257 };
258
259 extern const struct sci_base_state scic_sds_request_state_table[];
260 extern const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[];
261
262 extern const struct sci_base_state scic_sds_io_request_started_task_mgmt_substate_table[];
263 extern const struct scic_sds_io_request_state_handler scic_sds_ssp_task_request_started_substate_handler_table[];
264
265 extern const struct sci_base_state scic_sds_smp_request_started_substate_table[];
266 extern const struct scic_sds_io_request_state_handler scic_sds_smp_request_started_substate_handler_table[];
267
268 /**
269  *
270  *
271  * This macro returns the maximum number of SGL element paris that we will
272  * support in a single IO request.
273  */
274 #define SCU_MAX_SGL_ELEMENT_PAIRS ((SCU_IO_REQUEST_SGE_COUNT + 1) / 2)
275
276 /**
277  * scic_sds_request_get_controller() -
278  *
279  * This macro will return the controller for this io request object
280  */
281 #define scic_sds_request_get_controller(this_request) \
282         ((this_request)->owning_controller)
283
284 /**
285  * scic_sds_request_get_device() -
286  *
287  * This macro will return the device for this io request object
288  */
289 #define scic_sds_request_get_device(this_request) \
290         ((this_request)->target_device)
291
292 /**
293  * scic_sds_request_get_port() -
294  *
295  * This macro will return the port for this io request object
296  */
297 #define scic_sds_request_get_port(this_request) \
298         scic_sds_remote_device_get_port(scic_sds_request_get_device(this_request))
299
300 /**
301  * scic_sds_request_get_post_context() -
302  *
303  * This macro returns the constructed post context result for the io request.
304  */
305 #define scic_sds_request_get_post_context(this_request) \
306         ((this_request)->post_context)
307
308 /**
309  * scic_sds_request_get_task_context() -
310  *
311  * This is a helper macro to return the os handle for this request object.
312  */
313 #define scic_sds_request_get_task_context(request) \
314         ((request)->task_context_buffer)
315
316 /**
317  * scic_sds_request_set_status() -
318  *
319  * This macro will set the scu hardware status and sci request completion
320  * status for an io request.
321  */
322 #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \
323         { \
324                 (request)->scu_status = (scu_status_code); \
325                 (request)->sci_status = (sci_status_code); \
326         }
327
328 #define scic_sds_request_complete(a_request) \
329         ((a_request)->state_handlers->parent.complete_handler(&(a_request)->parent))
330
331
332
333
334 /**
335  * scic_sds_io_request_tc_completion() -
336  *
337  * This macro invokes the core state task completion handler for the
338  * SCIC_SDS_IO_REQUEST_T object.
339  */
340 #define scic_sds_io_request_tc_completion(this_request, completion_code) \
341         { \
342                 if (this_request->parent.state_machine.current_state_id  \
343                     == SCI_BASE_REQUEST_STATE_STARTED \
344                     && this_request->has_started_substate_machine \
345                     == false) \
346                         scic_sds_request_started_state_tc_completion_handler(this_request, completion_code); \
347                 else \
348                         this_request->state_handlers->tc_completion_handler(this_request, completion_code); \
349         }
350
351 /**
352  * SCU_SGL_ZERO() -
353  *
354  * This macro zeros the hardware SGL element data
355  */
356 #define SCU_SGL_ZERO(scu_sge) \
357         { \
358                 (scu_sge).length = 0; \
359                 (scu_sge).address_lower = 0; \
360                 (scu_sge).address_upper = 0; \
361                 (scu_sge).address_modifier = 0; \
362         }
363
364 /**
365  * SCU_SGL_COPY() -
366  *
367  * This macro copys the SGL Element data from the host os to the hardware SGL
368  * elment data
369  */
370 #define SCU_SGL_COPY(scu_sge, os_sge) \
371         { \
372                 (scu_sge).length = sg_dma_len(sg); \
373                 (scu_sge).address_upper = \
374                         upper_32_bits(sg_dma_address(sg)); \
375                 (scu_sge).address_lower = \
376                         lower_32_bits(sg_dma_address(sg)); \
377                 (scu_sge).address_modifier = 0; \
378         }
379
380 /**
381  * scic_sds_request_get_user_request() -
382  *
383  * This is a helper macro to return the os handle for this request object.
384  */
385 #define scic_sds_request_get_user_request(request) \
386         ((request)->user_request)
387
388 /*
389  * *****************************************************************************
390  * * CORE REQUEST PROTOTYPES
391  * ***************************************************************************** */
392
393 void scic_sds_request_build_sgl(
394         struct scic_sds_request *this_request);
395
396
397
398 void scic_sds_stp_request_assign_buffers(
399         struct scic_sds_request *this_request);
400
401 void scic_sds_smp_request_assign_buffers(
402         struct scic_sds_request *this_request);
403
404 /* --------------------------------------------------------------------------- */
405
406 enum sci_status scic_sds_request_start(
407         struct scic_sds_request *this_request);
408
409 enum sci_status scic_sds_io_request_terminate(
410         struct scic_sds_request *this_request);
411
412 enum sci_status scic_sds_io_request_complete(
413         struct scic_sds_request *this_request);
414
415 void scic_sds_io_request_copy_response(
416         struct scic_sds_request *this_request);
417
418 enum sci_status scic_sds_io_request_event_handler(
419         struct scic_sds_request *this_request,
420         u32 event_code);
421
422 enum sci_status scic_sds_io_request_frame_handler(
423         struct scic_sds_request *this_request,
424         u32 frame_index);
425
426
427 enum sci_status scic_sds_task_request_terminate(
428         struct scic_sds_request *this_request);
429
430 /*
431  * *****************************************************************************
432  * * DEFAULT STATE HANDLERS
433  * ***************************************************************************** */
434
435 enum sci_status scic_sds_request_default_start_handler(
436         struct sci_base_request *this_request);
437
438
439 enum sci_status scic_sds_request_default_complete_handler(
440         struct sci_base_request *this_request);
441
442 enum sci_status scic_sds_request_default_destruct_handler(
443         struct sci_base_request *this_request);
444
445 enum sci_status scic_sds_request_default_tc_completion_handler(
446         struct scic_sds_request *this_request,
447         u32 completion_code);
448
449 enum sci_status scic_sds_request_default_event_handler(
450         struct scic_sds_request *this_request,
451         u32 event_code);
452
453 enum sci_status scic_sds_request_default_frame_handler(
454         struct scic_sds_request *this_request,
455         u32 frame_index);
456
457 /*
458  * *****************************************************************************
459  * * STARTED STATE HANDLERS
460  * ***************************************************************************** */
461
462 enum sci_status scic_sds_request_started_state_abort_handler(
463         struct sci_base_request *this_request);
464
465 enum sci_status scic_sds_request_started_state_tc_completion_handler(
466         struct scic_sds_request *this_request,
467         u32 completion_code);
468
469 #endif /* _SCIC_SDS_IO_REQUEST_H_ */