isci: unify request data structures
[deliverable/linux.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 #include "scic_io_request.h"
60 #include "sci_base_state_machine.h"
61 #include "scu_task_context.h"
62 #include "scic_sds_stp_request.h"
63 #include "scu_constants.h"
64 #include "sas.h"
65
66 struct scic_sds_controller;
67 struct scic_sds_remote_device;
68 struct scic_sds_io_request_state_handler;
69
70 /**
71 * enum _scic_sds_io_request_started_task_mgmt_substates - This enumeration
72 * depicts all of the substates for a task management request to be
73 * performed in the STARTED super-state.
74 *
75 *
76 */
77 enum scic_sds_raw_request_started_task_mgmt_substates {
78 /**
79 * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
80 * task management request is waiting for the transmission of the
81 * initial frame (i.e. command, task, etc.).
82 */
83 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION,
84
85 /**
86 * This sub-state indicates that the started task management request
87 * is waiting for the reception of an unsolicited frame
88 * (i.e. response IU).
89 */
90 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE,
91 };
92
93
94 /**
95 * enum _scic_sds_smp_request_started_substates - This enumeration depicts all
96 * of the substates for a SMP request to be performed in the STARTED
97 * super-state.
98 *
99 *
100 */
101 enum scic_sds_smp_request_started_substates {
102 /**
103 * This sub-state indicates that the started task management request
104 * is waiting for the reception of an unsolicited frame
105 * (i.e. response IU).
106 */
107 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE,
108
109 /**
110 * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP request is
111 * waiting for the transmission of the initial frame (i.e. command, task, etc.).
112 */
113 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION,
114 };
115
116 struct scic_sds_request {
117 /**
118 * This field contains the information for the base request state machine.
119 */
120 struct sci_base_state_machine state_machine;
121
122 /**
123 * This field simply points to the controller to which this IO request
124 * is associated.
125 */
126 struct scic_sds_controller *owning_controller;
127
128 /**
129 * This field simply points to the remote device to which this IO request
130 * is associated.
131 */
132 struct scic_sds_remote_device *target_device;
133
134 /**
135 * This field is utilized to determine if the SCI user is managing
136 * the IO tag for this request or if the core is managing it.
137 */
138 bool was_tag_assigned_by_user;
139
140 /**
141 * This field indicates the IO tag for this request. The IO tag is
142 * comprised of the task_index and a sequence count. The sequence count
143 * is utilized to help identify tasks from one life to another.
144 */
145 u16 io_tag;
146
147 /**
148 * This field specifies the protocol being utilized for this
149 * IO request.
150 */
151 SCIC_TRANSPORT_PROTOCOL protocol;
152
153 /**
154 * This field indicates the completion status taken from the SCUs
155 * completion code. It indicates the completion result for the SCU hardware.
156 */
157 u32 scu_status;
158
159 /**
160 * This field indicates the completion status returned to the SCI user. It
161 * indicates the users view of the io request completion.
162 */
163 u32 sci_status;
164
165 /**
166 * This field contains the value to be utilized when posting (e.g. Post_TC,
167 * Post_TC_Abort) this request to the silicon.
168 */
169 u32 post_context;
170
171 struct scu_task_context *task_context_buffer;
172 struct scu_task_context tc ____cacheline_aligned;
173
174 /* could be larger with sg chaining */
175 #define SCU_SGL_SIZE ((SCU_IO_REQUEST_SGE_COUNT + 1) / 2)
176 struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
177
178 /**
179 * This field indicates if this request is a task management request or
180 * normal IO request.
181 */
182 bool is_task_management_request;
183
184 /**
185 * This field indicates that this request contains an initialized started
186 * substate machine.
187 */
188 bool has_started_substate_machine;
189
190 /**
191 * This field is a pointer to the stored rx frame data. It is used in STP
192 * internal requests and SMP response frames. If this field is non-NULL the
193 * saved frame must be released on IO request completion.
194 *
195 * @todo In the future do we want to keep a list of RX frame buffers?
196 */
197 u32 saved_rx_frame_index;
198
199 /**
200 * This field specifies the data necessary to manage the sub-state
201 * machine executed while in the SCI_BASE_REQUEST_STATE_STARTED state.
202 */
203 struct sci_base_state_machine started_substate_machine;
204
205 /**
206 * This field specifies the current state handlers in place for this
207 * IO Request object. This field is updated each time the request
208 * changes state.
209 */
210 const struct scic_sds_io_request_state_handler *state_handlers;
211
212 /**
213 * This field in the recorded device sequence for the io request. This is
214 * recorded during the build operation and is compared in the start
215 * operation. If the sequence is different then there was a change of
216 * devices from the build to start operations.
217 */
218 u8 device_sequence;
219
220 union {
221 struct {
222 union {
223 struct ssp_cmd_iu cmd;
224 struct ssp_task_iu tmf;
225 };
226 union {
227 struct ssp_response_iu rsp;
228 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
229 };
230 } ssp;
231
232 struct {
233 struct smp_req cmd;
234 struct smp_resp rsp;
235 } smp;
236
237 struct {
238 struct scic_sds_stp_request req;
239 struct host_to_dev_fis cmd;
240 struct dev_to_host_fis rsp;
241 } stp;
242 };
243
244 };
245
246 static inline struct scic_sds_request *to_sci_req(struct scic_sds_stp_request *stp_req)
247 {
248 struct scic_sds_request *sci_req;
249
250 sci_req = container_of(stp_req, typeof(*sci_req), stp.req);
251 return sci_req;
252 }
253
254 /**
255 * enum sci_base_request_states - This enumeration depicts all the states for
256 * the common request state machine.
257 *
258 *
259 */
260 enum sci_base_request_states {
261 /**
262 * Simply the initial state for the base request state machine.
263 */
264 SCI_BASE_REQUEST_STATE_INITIAL,
265
266 /**
267 * This state indicates that the request has been constructed. This state
268 * is entered from the INITIAL state.
269 */
270 SCI_BASE_REQUEST_STATE_CONSTRUCTED,
271
272 /**
273 * This state indicates that the request has been started. This state is
274 * entered from the CONSTRUCTED state.
275 */
276 SCI_BASE_REQUEST_STATE_STARTED,
277
278 /**
279 * This state indicates that the request has completed.
280 * This state is entered from the STARTED state. This state is entered from
281 * the ABORTING state.
282 */
283 SCI_BASE_REQUEST_STATE_COMPLETED,
284
285 /**
286 * This state indicates that the request is in the process of being
287 * terminated/aborted.
288 * This state is entered from the CONSTRUCTED state.
289 * This state is entered from the STARTED state.
290 */
291 SCI_BASE_REQUEST_STATE_ABORTING,
292
293 /**
294 * Simply the final state for the base request state machine.
295 */
296 SCI_BASE_REQUEST_STATE_FINAL,
297 };
298
299 typedef enum sci_status (*scic_sds_io_request_handler_t)
300 (struct scic_sds_request *request);
301 typedef enum sci_status (*scic_sds_io_request_frame_handler_t)
302 (struct scic_sds_request *req, u32 frame);
303 typedef enum sci_status (*scic_sds_io_request_event_handler_t)
304 (struct scic_sds_request *req, u32 event);
305 typedef enum sci_status (*scic_sds_io_request_task_completion_handler_t)
306 (struct scic_sds_request *req, u32 completion_code);
307
308 /**
309 * struct scic_sds_io_request_state_handler - This is the SDS core definition
310 * of the state handlers.
311 *
312 *
313 */
314 struct scic_sds_io_request_state_handler {
315 /**
316 * The start_handler specifies the method invoked when a user attempts to
317 * start a request.
318 */
319 scic_sds_io_request_handler_t start_handler;
320
321 /**
322 * The abort_handler specifies the method invoked when a user attempts to
323 * abort a request.
324 */
325 scic_sds_io_request_handler_t abort_handler;
326
327 /**
328 * The complete_handler specifies the method invoked when a user attempts to
329 * complete a request.
330 */
331 scic_sds_io_request_handler_t complete_handler;
332
333 scic_sds_io_request_task_completion_handler_t tc_completion_handler;
334 scic_sds_io_request_event_handler_t event_handler;
335 scic_sds_io_request_frame_handler_t frame_handler;
336
337 };
338
339 extern const struct sci_base_state scic_sds_io_request_started_task_mgmt_substate_table[];
340
341 /**
342 * scic_sds_request_get_controller() -
343 *
344 * This macro will return the controller for this io request object
345 */
346 #define scic_sds_request_get_controller(sci_req) \
347 ((sci_req)->owning_controller)
348
349 /**
350 * scic_sds_request_get_device() -
351 *
352 * This macro will return the device for this io request object
353 */
354 #define scic_sds_request_get_device(sci_req) \
355 ((sci_req)->target_device)
356
357 /**
358 * scic_sds_request_get_port() -
359 *
360 * This macro will return the port for this io request object
361 */
362 #define scic_sds_request_get_port(sci_req) \
363 scic_sds_remote_device_get_port(scic_sds_request_get_device(sci_req))
364
365 /**
366 * scic_sds_request_get_post_context() -
367 *
368 * This macro returns the constructed post context result for the io request.
369 */
370 #define scic_sds_request_get_post_context(sci_req) \
371 ((sci_req)->post_context)
372
373 /**
374 * scic_sds_request_get_task_context() -
375 *
376 * This is a helper macro to return the os handle for this request object.
377 */
378 #define scic_sds_request_get_task_context(request) \
379 ((request)->task_context_buffer)
380
381 /**
382 * scic_sds_request_set_status() -
383 *
384 * This macro will set the scu hardware status and sci request completion
385 * status for an io request.
386 */
387 #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \
388 { \
389 (request)->scu_status = (scu_status_code); \
390 (request)->sci_status = (sci_status_code); \
391 }
392
393 #define scic_sds_request_complete(a_request) \
394 ((a_request)->state_handlers->complete_handler(a_request))
395
396
397 extern enum sci_status
398 scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code);
399
400 /**
401 * SCU_SGL_ZERO() -
402 *
403 * This macro zeros the hardware SGL element data
404 */
405 #define SCU_SGL_ZERO(scu_sge) \
406 { \
407 (scu_sge).length = 0; \
408 (scu_sge).address_lower = 0; \
409 (scu_sge).address_upper = 0; \
410 (scu_sge).address_modifier = 0; \
411 }
412
413 /**
414 * SCU_SGL_COPY() -
415 *
416 * This macro copys the SGL Element data from the host os to the hardware SGL
417 * elment data
418 */
419 #define SCU_SGL_COPY(scu_sge, os_sge) \
420 { \
421 (scu_sge).length = sg_dma_len(sg); \
422 (scu_sge).address_upper = \
423 upper_32_bits(sg_dma_address(sg)); \
424 (scu_sge).address_lower = \
425 lower_32_bits(sg_dma_address(sg)); \
426 (scu_sge).address_modifier = 0; \
427 }
428
429 /**
430 * scic_sds_request_get_user_request() -
431 *
432 * This is a helper macro to return the os handle for this request object.
433 */
434 #define scic_sds_request_get_user_request(request) \
435 ((request)->user_request)
436
437 /*
438 * *****************************************************************************
439 * * CORE REQUEST PROTOTYPES
440 * ***************************************************************************** */
441
442 void scic_sds_request_build_sgl(
443 struct scic_sds_request *sci_req);
444
445
446
447 void scic_sds_stp_request_assign_buffers(
448 struct scic_sds_request *sci_req);
449
450 void scic_sds_smp_request_assign_buffers(
451 struct scic_sds_request *sci_req);
452
453 /* --------------------------------------------------------------------------- */
454
455 enum sci_status scic_sds_request_start(
456 struct scic_sds_request *sci_req);
457
458 enum sci_status scic_sds_io_request_terminate(
459 struct scic_sds_request *sci_req);
460
461 enum sci_status scic_sds_io_request_complete(
462 struct scic_sds_request *sci_req);
463
464 void scic_sds_io_request_copy_response(
465 struct scic_sds_request *sci_req);
466
467 enum sci_status scic_sds_io_request_event_handler(
468 struct scic_sds_request *sci_req,
469 u32 event_code);
470
471 enum sci_status scic_sds_io_request_frame_handler(
472 struct scic_sds_request *sci_req,
473 u32 frame_index);
474
475
476 enum sci_status scic_sds_task_request_terminate(
477 struct scic_sds_request *sci_req);
478
479 /*
480 * *****************************************************************************
481 * * STARTED STATE HANDLERS
482 * ***************************************************************************** */
483
484 enum sci_status scic_sds_request_started_state_abort_handler(
485 struct scic_sds_request *sci_req);
486
487 enum sci_status scic_sds_request_started_state_tc_completion_handler(
488 struct scic_sds_request *sci_req,
489 u32 completion_code);
490
491 #endif /* _SCIC_SDS_IO_REQUEST_H_ */
This page took 0.055169 seconds and 5 git commands to generate.