blob: 8c77c4cbe04a8b5c889926602cc6aa5369180351 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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
Dan Williams0d843662011-05-08 01:56:57 -070056#ifndef _ISCI_REQUEST_H_
Dan Williams6f231dd2011-07-02 22:56:22 -070057#define _ISCI_REQUEST_H_
58
59#include "isci.h"
Dan Williamsce2b3262011-05-08 15:49:15 -070060#include "host.h"
Dan Williamsf1f52e72011-05-10 02:28:45 -070061#include "scu_task_context.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070062
63/**
64 * struct isci_request_status - This enum defines the possible states of an I/O
65 * request.
66 *
67 *
68 */
69enum isci_request_status {
70 unallocated = 0x00,
71 allocated = 0x01,
72 started = 0x02,
73 completed = 0x03,
74 aborting = 0x04,
75 aborted = 0x05,
Jeff Skirvin4dc043c2011-03-04 14:06:52 -080076 terminating = 0x06,
77 dead = 0x07
Dan Williams6f231dd2011-07-02 22:56:22 -070078};
79
80enum task_type {
81 io_task = 0,
82 tmf_task = 1
83};
84
Dan Williamsf1f52e72011-05-10 02:28:45 -070085enum sci_request_protocol {
86 SCIC_NO_PROTOCOL,
87 SCIC_SMP_PROTOCOL,
88 SCIC_SSP_PROTOCOL,
89 SCIC_STP_PROTOCOL
Dan Williamsc72086e2011-05-10 02:28:48 -070090}; /* XXX remove me, use sas_task.{dev|task_proto} instead */;
Dan Williamsf1f52e72011-05-10 02:28:45 -070091
Dan Williams5dec6f42011-05-10 02:28:49 -070092struct scic_sds_stp_request {
93 union {
94 u32 ncq;
95
96 u32 udma;
97
98 struct scic_sds_stp_pio_request {
Edmund Nadolskie3013702011-06-02 00:10:43 +000099 /*
100 * Total transfer for the entire PIO request recorded
101 * at request constuction time.
Dan Williams5dec6f42011-05-10 02:28:49 -0700102 *
Edmund Nadolskie3013702011-06-02 00:10:43 +0000103 * @todo Should we just decrement this value for each
104 * byte of data transitted or received to elemenate
105 * the current_transfer_bytes field?
Dan Williams5dec6f42011-05-10 02:28:49 -0700106 */
107 u32 total_transfer_bytes;
108
Edmund Nadolskie3013702011-06-02 00:10:43 +0000109 /*
110 * Total number of bytes received/transmitted in data
111 * frames since the start of the IO request. At the
112 * end of the IO request this should equal the
Dan Williams5dec6f42011-05-10 02:28:49 -0700113 * total_transfer_bytes.
114 */
115 u32 current_transfer_bytes;
116
Edmund Nadolskie3013702011-06-02 00:10:43 +0000117 /*
118 * The number of bytes requested in the in the PIO
119 * setup.
Dan Williams5dec6f42011-05-10 02:28:49 -0700120 */
121 u32 pio_transfer_bytes;
122
Edmund Nadolskie3013702011-06-02 00:10:43 +0000123 /*
124 * PIO Setup ending status value to tell us if we need
125 * to wait for another FIS or if the transfer is
126 * complete. On the receipt of a D2H FIS this will be
Dan Williams5dec6f42011-05-10 02:28:49 -0700127 * the status field of that FIS.
128 */
129 u8 ending_status;
130
Edmund Nadolskie3013702011-06-02 00:10:43 +0000131 /*
132 * On receipt of a D2H FIS this will be the ending
133 * error field if the ending_status has the
134 * SATA_STATUS_ERR bit set.
Dan Williams5dec6f42011-05-10 02:28:49 -0700135 */
136 u8 ending_error;
137
138 struct scic_sds_request_pio_sgl {
Dan Williams312e0c22011-06-28 13:47:09 -0700139 int sgl_index;
Dan Williams5dec6f42011-05-10 02:28:49 -0700140 u8 sgl_set;
141 u32 sgl_offset;
142 } request_current;
143 } pio;
144
145 struct {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000146 /*
147 * The number of bytes requested in the PIO setup
148 * before CDB data frame.
Dan Williams5dec6f42011-05-10 02:28:49 -0700149 */
150 u32 device_preferred_cdb_length;
151 } packet;
152 } type;
153};
154
Dan Williamsf1f52e72011-05-10 02:28:45 -0700155struct scic_sds_request {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000156 /*
157 * This field contains the information for the base request state
158 * machine.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700159 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000160 struct sci_base_state_machine sm;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700161
Edmund Nadolskie3013702011-06-02 00:10:43 +0000162 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700163 * This field simply points to the controller to which this IO request
164 * is associated.
165 */
166 struct scic_sds_controller *owning_controller;
167
Edmund Nadolskie3013702011-06-02 00:10:43 +0000168 /*
169 * This field simply points to the remote device to which this IO
170 * request is associated.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700171 */
172 struct scic_sds_remote_device *target_device;
173
Edmund Nadolskie3013702011-06-02 00:10:43 +0000174 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700175 * This field indicates the IO tag for this request. The IO tag is
176 * comprised of the task_index and a sequence count. The sequence count
177 * is utilized to help identify tasks from one life to another.
178 */
179 u16 io_tag;
180
Edmund Nadolskie3013702011-06-02 00:10:43 +0000181 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700182 * This field specifies the protocol being utilized for this
183 * IO request.
184 */
185 enum sci_request_protocol protocol;
186
Edmund Nadolskie3013702011-06-02 00:10:43 +0000187 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700188 * This field indicates the completion status taken from the SCUs
Edmund Nadolskie3013702011-06-02 00:10:43 +0000189 * completion code. It indicates the completion result for the SCU
190 * hardware.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700191 */
192 u32 scu_status;
193
Edmund Nadolskie3013702011-06-02 00:10:43 +0000194 /*
195 * This field indicates the completion status returned to the SCI user.
196 * It indicates the users view of the io request completion.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700197 */
198 u32 sci_status;
199
Edmund Nadolskie3013702011-06-02 00:10:43 +0000200 /*
201 * This field contains the value to be utilized when posting
202 * (e.g. Post_TC, * Post_TC_Abort) this request to the silicon.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700203 */
204 u32 post_context;
205
Dan Williams312e0c22011-06-28 13:47:09 -0700206 struct scu_task_context *tc;
Dan Williamsf1f52e72011-05-10 02:28:45 -0700207
208 /* could be larger with sg chaining */
Dan Williams7c78da32011-06-01 16:00:01 -0700209 #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700210 struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
211
Edmund Nadolskie3013702011-06-02 00:10:43 +0000212 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700213 * This field indicates if this request is a task management request or
214 * normal IO request.
215 */
216 bool is_task_management_request;
217
Edmund Nadolskie3013702011-06-02 00:10:43 +0000218 /*
219 * This field is a pointer to the stored rx frame data. It is used in
220 * STP internal requests and SMP response frames. If this field is
221 * non-NULL the saved frame must be released on IO request completion.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700222 *
223 * @todo In the future do we want to keep a list of RX frame buffers?
224 */
225 u32 saved_rx_frame_index;
226
Dan Williamsf1f52e72011-05-10 02:28:45 -0700227 union {
228 struct {
229 union {
230 struct ssp_cmd_iu cmd;
231 struct ssp_task_iu tmf;
232 };
233 union {
234 struct ssp_response_iu rsp;
235 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
236 };
237 } ssp;
238
239 struct {
Dan Williamsf1f52e72011-05-10 02:28:45 -0700240 struct smp_resp rsp;
241 } smp;
242
243 struct {
244 struct scic_sds_stp_request req;
245 struct host_to_dev_fis cmd;
246 struct dev_to_host_fis rsp;
247 } stp;
248 };
Dan Williamsf1f52e72011-05-10 02:28:45 -0700249};
250
251static inline struct scic_sds_request *to_sci_req(struct scic_sds_stp_request *stp_req)
252{
253 struct scic_sds_request *sci_req;
254
255 sci_req = container_of(stp_req, typeof(*sci_req), stp.req);
256 return sci_req;
257}
258
Dan Williams6f231dd2011-07-02 22:56:22 -0700259struct isci_request {
Dan Williams6f231dd2011-07-02 22:56:22 -0700260 enum isci_request_status status;
261 enum task_type ttype;
262 unsigned short io_tag;
263 bool complete_in_target;
Dan Williams67ea8382011-05-08 11:47:15 -0700264 bool terminated;
Dan Williams6f231dd2011-07-02 22:56:22 -0700265
266 union ttype_ptr_union {
267 struct sas_task *io_task_ptr; /* When ttype==io_task */
268 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
269 } ttype_ptr;
270 struct isci_host *isci_host;
Dan Williams6f231dd2011-07-02 22:56:22 -0700271 /* For use in the requests_to_{complete|abort} lists: */
272 struct list_head completed_node;
273 /* For use in the reqs_in_process list: */
274 struct list_head dev_node;
Dan Williams6f231dd2011-07-02 22:56:22 -0700275 spinlock_t state_lock;
276 dma_addr_t request_daddr;
277 dma_addr_t zero_scatter_daddr;
278
Edmund Nadolskie3013702011-06-02 00:10:43 +0000279 unsigned int num_sg_entries; /* returned by pci_alloc_sg */
Dan Williams6f231dd2011-07-02 22:56:22 -0700280
281 /** Note: "io_request_completion" is completed in two different ways
282 * depending on whether this is a TMF or regular request.
283 * - TMF requests are completed in the thread that started them;
284 * - regular requests are completed in the request completion callback
285 * function.
286 * This difference in operation allows the aborter of a TMF request
287 * to be sure that once the TMF request completes, the I/O that the
288 * TMF was aborting is guaranteed to have completed.
289 */
290 struct completion *io_request_completion;
Dan Williams67ea8382011-05-08 11:47:15 -0700291 struct scic_sds_request sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700292};
293
Dan Williams67ea8382011-05-08 11:47:15 -0700294static inline struct isci_request *sci_req_to_ireq(struct scic_sds_request *sci_req)
295{
296 struct isci_request *ireq = container_of(sci_req, typeof(*ireq), sci);
297
298 return ireq;
299}
300
Dan Williams6f231dd2011-07-02 22:56:22 -0700301/**
Dan Williamsf1f52e72011-05-10 02:28:45 -0700302 * enum sci_base_request_states - This enumeration depicts all the states for
303 * the common request state machine.
304 *
305 *
306 */
307enum sci_base_request_states {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000308 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700309 * Simply the initial state for the base request state machine.
310 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000311 SCI_REQ_INIT,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700312
Edmund Nadolskie3013702011-06-02 00:10:43 +0000313 /*
314 * This state indicates that the request has been constructed.
315 * This state is entered from the INITIAL state.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700316 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000317 SCI_REQ_CONSTRUCTED,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700318
Edmund Nadolskie3013702011-06-02 00:10:43 +0000319 /*
320 * This state indicates that the request has been started. This state
321 * is entered from the CONSTRUCTED state.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700322 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000323 SCI_REQ_STARTED,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700324
Edmund Nadolskie3013702011-06-02 00:10:43 +0000325 SCI_REQ_STP_UDMA_WAIT_TC_COMP,
326 SCI_REQ_STP_UDMA_WAIT_D2H,
Dan Williams5dec6f42011-05-10 02:28:49 -0700327
Edmund Nadolskie3013702011-06-02 00:10:43 +0000328 SCI_REQ_STP_NON_DATA_WAIT_H2D,
329 SCI_REQ_STP_NON_DATA_WAIT_D2H,
Dan Williams5dec6f42011-05-10 02:28:49 -0700330
Edmund Nadolskie3013702011-06-02 00:10:43 +0000331 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED,
332 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG,
333 SCI_REQ_STP_SOFT_RESET_WAIT_D2H,
Dan Williams5dec6f42011-05-10 02:28:49 -0700334
Edmund Nadolskie3013702011-06-02 00:10:43 +0000335 /*
336 * While in this state the IO request object is waiting for the TC
337 * completion notification for the H2D Register FIS
Dan Williams5dec6f42011-05-10 02:28:49 -0700338 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000339 SCI_REQ_STP_PIO_WAIT_H2D,
Dan Williams5dec6f42011-05-10 02:28:49 -0700340
Edmund Nadolskie3013702011-06-02 00:10:43 +0000341 /*
342 * While in this state the IO request object is waiting for either a
343 * PIO Setup FIS or a D2H register FIS. The type of frame received is
344 * based on the result of the prior frame and line conditions.
Dan Williams5dec6f42011-05-10 02:28:49 -0700345 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000346 SCI_REQ_STP_PIO_WAIT_FRAME,
Dan Williams5dec6f42011-05-10 02:28:49 -0700347
Edmund Nadolskie3013702011-06-02 00:10:43 +0000348 /*
349 * While in this state the IO request object is waiting for a DATA
350 * frame from the device.
Dan Williams5dec6f42011-05-10 02:28:49 -0700351 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000352 SCI_REQ_STP_PIO_DATA_IN,
Dan Williams5dec6f42011-05-10 02:28:49 -0700353
Edmund Nadolskie3013702011-06-02 00:10:43 +0000354 /*
355 * While in this state the IO request object is waiting to transmit
356 * the next data frame to the device.
Dan Williams5dec6f42011-05-10 02:28:49 -0700357 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000358 SCI_REQ_STP_PIO_DATA_OUT,
Dan Williams5dec6f42011-05-10 02:28:49 -0700359
Edmund Nadolskie3013702011-06-02 00:10:43 +0000360 /*
Dan Williamsf1393032011-05-10 02:28:47 -0700361 * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
362 * task management request is waiting for the transmission of the
363 * initial frame (i.e. command, task, etc.).
364 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000365 SCI_REQ_TASK_WAIT_TC_COMP,
Dan Williamsf1393032011-05-10 02:28:47 -0700366
Edmund Nadolskie3013702011-06-02 00:10:43 +0000367 /*
Dan Williamsf1393032011-05-10 02:28:47 -0700368 * This sub-state indicates that the started task management request
369 * is waiting for the reception of an unsolicited frame
370 * (i.e. response IU).
371 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000372 SCI_REQ_TASK_WAIT_TC_RESP,
Dan Williamsf1393032011-05-10 02:28:47 -0700373
Edmund Nadolskie3013702011-06-02 00:10:43 +0000374 /*
Dan Williamsc72086e2011-05-10 02:28:48 -0700375 * This sub-state indicates that the started task management request
376 * is waiting for the reception of an unsolicited frame
377 * (i.e. response IU).
378 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000379 SCI_REQ_SMP_WAIT_RESP,
Dan Williamsc72086e2011-05-10 02:28:48 -0700380
Edmund Nadolskie3013702011-06-02 00:10:43 +0000381 /*
382 * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP
383 * request is waiting for the transmission of the initial frame
384 * (i.e. command, task, etc.).
Dan Williamsc72086e2011-05-10 02:28:48 -0700385 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000386 SCI_REQ_SMP_WAIT_TC_COMP,
Dan Williamsc72086e2011-05-10 02:28:48 -0700387
Edmund Nadolskie3013702011-06-02 00:10:43 +0000388 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700389 * This state indicates that the request has completed.
Edmund Nadolskie3013702011-06-02 00:10:43 +0000390 * This state is entered from the STARTED state. This state is entered
391 * from the ABORTING state.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700392 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000393 SCI_REQ_COMPLETED,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700394
Edmund Nadolskie3013702011-06-02 00:10:43 +0000395 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700396 * This state indicates that the request is in the process of being
397 * terminated/aborted.
398 * This state is entered from the CONSTRUCTED state.
399 * This state is entered from the STARTED state.
400 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000401 SCI_REQ_ABORTING,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700402
Edmund Nadolskie3013702011-06-02 00:10:43 +0000403 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700404 * Simply the final state for the base request state machine.
405 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000406 SCI_REQ_FINAL,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700407};
408
Dan Williamsf1f52e72011-05-10 02:28:45 -0700409/**
410 * scic_sds_request_get_controller() -
411 *
412 * This macro will return the controller for this io request object
413 */
414#define scic_sds_request_get_controller(sci_req) \
415 ((sci_req)->owning_controller)
416
417/**
418 * scic_sds_request_get_device() -
419 *
420 * This macro will return the device for this io request object
421 */
422#define scic_sds_request_get_device(sci_req) \
423 ((sci_req)->target_device)
424
425/**
426 * scic_sds_request_get_port() -
427 *
428 * This macro will return the port for this io request object
429 */
430#define scic_sds_request_get_port(sci_req) \
431 scic_sds_remote_device_get_port(scic_sds_request_get_device(sci_req))
432
433/**
434 * scic_sds_request_get_post_context() -
435 *
436 * This macro returns the constructed post context result for the io request.
437 */
438#define scic_sds_request_get_post_context(sci_req) \
439 ((sci_req)->post_context)
440
441/**
442 * scic_sds_request_get_task_context() -
443 *
444 * This is a helper macro to return the os handle for this request object.
445 */
446#define scic_sds_request_get_task_context(request) \
447 ((request)->task_context_buffer)
448
449/**
450 * scic_sds_request_set_status() -
451 *
452 * This macro will set the scu hardware status and sci request completion
453 * status for an io request.
454 */
455#define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \
456 { \
457 (request)->scu_status = (scu_status_code); \
458 (request)->sci_status = (sci_status_code); \
459 }
460
Dan Williamsf1f52e72011-05-10 02:28:45 -0700461enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req);
462enum sci_status scic_sds_io_request_terminate(struct scic_sds_request *sci_req);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000463enum sci_status
464scic_sds_io_request_event_handler(struct scic_sds_request *sci_req,
465 u32 event_code);
466enum sci_status
467scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req,
468 u32 frame_index);
469enum sci_status
470scic_sds_task_request_terminate(struct scic_sds_request *sci_req);
471extern enum sci_status
472scic_sds_request_complete(struct scic_sds_request *sci_req);
473extern enum sci_status
474scic_sds_io_request_tc_completion(struct scic_sds_request *sci_req, u32 code);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700475
Dan Williamsf1f52e72011-05-10 02:28:45 -0700476/* XXX open code in caller */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000477static inline dma_addr_t
478scic_io_request_get_dma_addr(struct scic_sds_request *sci_req, void *virt_addr)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700479{
480 struct isci_request *ireq = sci_req_to_ireq(sci_req);
481
482 char *requested_addr = (char *)virt_addr;
483 char *base_addr = (char *)ireq;
484
485 BUG_ON(requested_addr < base_addr);
486 BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
487
488 return ireq->request_daddr + (requested_addr - base_addr);
489}
490
491/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700492 * This function gets the status of the request object.
493 * @request: This parameter points to the isci_request object
494 *
495 * status of the object as a isci_request_status enum.
496 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000497static inline enum isci_request_status
498isci_request_get_state(struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700499{
500 BUG_ON(isci_request == NULL);
501
502 /*probably a bad sign... */
503 if (isci_request->status == unallocated)
504 dev_warn(&isci_request->isci_host->pdev->dev,
505 "%s: isci_request->status == unallocated\n",
506 __func__);
507
508 return isci_request->status;
509}
510
511
512/**
513 * isci_request_change_state() - This function sets the status of the request
514 * object.
515 * @request: This parameter points to the isci_request object
516 * @status: This Parameter is the new status of the object
517 *
518 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000519static inline enum isci_request_status
520isci_request_change_state(struct isci_request *isci_request,
521 enum isci_request_status status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700522{
523 enum isci_request_status old_state;
524 unsigned long flags;
525
526 dev_dbg(&isci_request->isci_host->pdev->dev,
527 "%s: isci_request = %p, state = 0x%x\n",
528 __func__,
529 isci_request,
530 status);
531
532 BUG_ON(isci_request == NULL);
533
534 spin_lock_irqsave(&isci_request->state_lock, flags);
535 old_state = isci_request->status;
536 isci_request->status = status;
537 spin_unlock_irqrestore(&isci_request->state_lock, flags);
538
539 return old_state;
540}
541
542/**
543 * isci_request_change_started_to_newstate() - This function sets the status of
544 * the request object.
545 * @request: This parameter points to the isci_request object
546 * @status: This Parameter is the new status of the object
547 *
548 * state previous to any change.
549 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000550static inline enum isci_request_status
551isci_request_change_started_to_newstate(struct isci_request *isci_request,
552 struct completion *completion_ptr,
553 enum isci_request_status newstate)
Dan Williams6f231dd2011-07-02 22:56:22 -0700554{
555 enum isci_request_status old_state;
556 unsigned long flags;
557
Dan Williams6f231dd2011-07-02 22:56:22 -0700558 spin_lock_irqsave(&isci_request->state_lock, flags);
559
560 old_state = isci_request->status;
561
Jeff Skirvinf219f012011-03-31 13:10:34 -0700562 if (old_state == started || old_state == aborting) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700563 BUG_ON(isci_request->io_request_completion != NULL);
564
565 isci_request->io_request_completion = completion_ptr;
566 isci_request->status = newstate;
567 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000568
Dan Williams6f231dd2011-07-02 22:56:22 -0700569 spin_unlock_irqrestore(&isci_request->state_lock, flags);
570
571 dev_dbg(&isci_request->isci_host->pdev->dev,
572 "%s: isci_request = %p, old_state = 0x%x\n",
573 __func__,
574 isci_request,
575 old_state);
576
577 return old_state;
578}
579
580/**
581 * isci_request_change_started_to_aborted() - This function sets the status of
582 * the request object.
583 * @request: This parameter points to the isci_request object
584 * @completion_ptr: This parameter is saved as the kernel completion structure
585 * signalled when the old request completes.
586 *
587 * state previous to any change.
588 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000589static inline enum isci_request_status
590isci_request_change_started_to_aborted(struct isci_request *isci_request,
591 struct completion *completion_ptr)
Dan Williams6f231dd2011-07-02 22:56:22 -0700592{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000593 return isci_request_change_started_to_newstate(isci_request,
594 completion_ptr,
595 aborted);
Dan Williams6f231dd2011-07-02 22:56:22 -0700596}
597/**
598 * isci_request_free() - This function frees the request object.
599 * @isci_host: This parameter specifies the ISCI host object
600 * @isci_request: This parameter points to the isci_request object
601 *
602 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000603static inline void isci_request_free(struct isci_host *isci_host,
604 struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700605{
Bartosz Barcinski6cb4d6b2011-04-12 17:28:43 -0700606 if (!isci_request)
607 return;
Dan Williams6f231dd2011-07-02 22:56:22 -0700608
609 /* release the dma memory if we fail. */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000610 dma_pool_free(isci_host->dma_pool,
611 isci_request,
Dan Williams6f231dd2011-07-02 22:56:22 -0700612 isci_request->request_daddr);
613}
614
Edmund Nadolskie3013702011-06-02 00:10:43 +0000615#define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
Dan Williams6f231dd2011-07-02 22:56:22 -0700616
Edmund Nadolskie3013702011-06-02 00:10:43 +0000617#define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
Dan Williams6f231dd2011-07-02 22:56:22 -0700618
Dan Williams0d0cf142011-06-13 00:51:30 -0700619struct isci_request *isci_request_alloc_tmf(struct isci_host *ihost,
620 struct isci_tmf *isci_tmf,
Dan Williams0d0cf142011-06-13 00:51:30 -0700621 gfp_t gfp_flags);
Dan Williams209fae12011-06-13 17:39:44 -0700622int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
Dan Williams312e0c22011-06-28 13:47:09 -0700623 struct sas_task *task, u16 tag, gfp_t gfp_flags);
Dan Williamsddcc7e32011-06-17 10:40:43 -0700624void isci_terminate_pending_requests(struct isci_host *ihost,
625 struct isci_remote_device *idev);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000626enum sci_status
627scic_task_request_construct(struct scic_sds_controller *scic,
628 struct scic_sds_remote_device *sci_dev,
629 u16 io_tag,
630 struct scic_sds_request *sci_req);
631enum sci_status
632scic_task_request_construct_ssp(struct scic_sds_request *sci_req);
633enum sci_status
634scic_task_request_construct_sata(struct scic_sds_request *sci_req);
635void
636scic_stp_io_request_set_ncq_tag(struct scic_sds_request *sci_req, u16 ncq_tag);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700637void scic_sds_smp_request_copy_response(struct scic_sds_request *sci_req);
Jeff Skirvin9274f452011-06-23 17:09:02 -0700638
639static inline int isci_task_is_ncq_recovery(struct sas_task *task)
640{
641 return (sas_protocol_ata(task->task_proto) &&
642 task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
643 task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
644
645}
646
Dan Williams6f231dd2011-07-02 22:56:22 -0700647#endif /* !defined(_ISCI_REQUEST_H_) */