blob: 7628decbd535621897944777f59debbe6985519d [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 /*
Edmund Nadolskie3013702011-06-02 00:10:43 +0000213 * This field is a pointer to the stored rx frame data. It is used in
214 * STP internal requests and SMP response frames. If this field is
215 * non-NULL the saved frame must be released on IO request completion.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700216 *
217 * @todo In the future do we want to keep a list of RX frame buffers?
218 */
219 u32 saved_rx_frame_index;
220
Dan Williamsf1f52e72011-05-10 02:28:45 -0700221 union {
222 struct {
223 union {
224 struct ssp_cmd_iu cmd;
225 struct ssp_task_iu tmf;
226 };
227 union {
228 struct ssp_response_iu rsp;
229 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
230 };
231 } ssp;
232
233 struct {
Dan Williamsf1f52e72011-05-10 02:28:45 -0700234 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 };
Dan Williamsf1f52e72011-05-10 02:28:45 -0700243};
244
245static inline struct scic_sds_request *to_sci_req(struct scic_sds_stp_request *stp_req)
246{
247 struct scic_sds_request *sci_req;
248
249 sci_req = container_of(stp_req, typeof(*sci_req), stp.req);
250 return sci_req;
251}
252
Dan Williams6f231dd2011-07-02 22:56:22 -0700253struct isci_request {
Dan Williams6f231dd2011-07-02 22:56:22 -0700254 enum isci_request_status status;
255 enum task_type ttype;
256 unsigned short io_tag;
Dan Williams38d88792011-06-23 14:33:48 -0700257 #define IREQ_COMPLETE_IN_TARGET 0
258 #define IREQ_TERMINATED 1
259 #define IREQ_TMF 2
Dan Williamsdb056252011-06-17 14:18:39 -0700260 #define IREQ_ACTIVE 3
Dan Williams38d88792011-06-23 14:33:48 -0700261 unsigned long flags;
Dan Williams6f231dd2011-07-02 22:56:22 -0700262
263 union ttype_ptr_union {
264 struct sas_task *io_task_ptr; /* When ttype==io_task */
265 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
266 } ttype_ptr;
267 struct isci_host *isci_host;
Dan Williams6f231dd2011-07-02 22:56:22 -0700268 /* For use in the requests_to_{complete|abort} lists: */
269 struct list_head completed_node;
270 /* For use in the reqs_in_process list: */
271 struct list_head dev_node;
Dan Williams6f231dd2011-07-02 22:56:22 -0700272 spinlock_t state_lock;
273 dma_addr_t request_daddr;
274 dma_addr_t zero_scatter_daddr;
275
Edmund Nadolskie3013702011-06-02 00:10:43 +0000276 unsigned int num_sg_entries; /* returned by pci_alloc_sg */
Dan Williams6f231dd2011-07-02 22:56:22 -0700277
278 /** Note: "io_request_completion" is completed in two different ways
279 * depending on whether this is a TMF or regular request.
280 * - TMF requests are completed in the thread that started them;
281 * - regular requests are completed in the request completion callback
282 * function.
283 * This difference in operation allows the aborter of a TMF request
284 * to be sure that once the TMF request completes, the I/O that the
285 * TMF was aborting is guaranteed to have completed.
286 */
287 struct completion *io_request_completion;
Dan Williams67ea8382011-05-08 11:47:15 -0700288 struct scic_sds_request sci;
Dan Williams6f231dd2011-07-02 22:56:22 -0700289};
290
Dan Williams67ea8382011-05-08 11:47:15 -0700291static inline struct isci_request *sci_req_to_ireq(struct scic_sds_request *sci_req)
292{
293 struct isci_request *ireq = container_of(sci_req, typeof(*ireq), sci);
294
295 return ireq;
296}
297
Dan Williams6f231dd2011-07-02 22:56:22 -0700298/**
Dan Williamsf1f52e72011-05-10 02:28:45 -0700299 * enum sci_base_request_states - This enumeration depicts all the states for
300 * the common request state machine.
301 *
302 *
303 */
304enum sci_base_request_states {
Edmund Nadolskie3013702011-06-02 00:10:43 +0000305 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700306 * Simply the initial state for the base request state machine.
307 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000308 SCI_REQ_INIT,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700309
Edmund Nadolskie3013702011-06-02 00:10:43 +0000310 /*
311 * This state indicates that the request has been constructed.
312 * This state is entered from the INITIAL state.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700313 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000314 SCI_REQ_CONSTRUCTED,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700315
Edmund Nadolskie3013702011-06-02 00:10:43 +0000316 /*
317 * This state indicates that the request has been started. This state
318 * is entered from the CONSTRUCTED state.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700319 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000320 SCI_REQ_STARTED,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700321
Edmund Nadolskie3013702011-06-02 00:10:43 +0000322 SCI_REQ_STP_UDMA_WAIT_TC_COMP,
323 SCI_REQ_STP_UDMA_WAIT_D2H,
Dan Williams5dec6f42011-05-10 02:28:49 -0700324
Edmund Nadolskie3013702011-06-02 00:10:43 +0000325 SCI_REQ_STP_NON_DATA_WAIT_H2D,
326 SCI_REQ_STP_NON_DATA_WAIT_D2H,
Dan Williams5dec6f42011-05-10 02:28:49 -0700327
Edmund Nadolskie3013702011-06-02 00:10:43 +0000328 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED,
329 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG,
330 SCI_REQ_STP_SOFT_RESET_WAIT_D2H,
Dan Williams5dec6f42011-05-10 02:28:49 -0700331
Edmund Nadolskie3013702011-06-02 00:10:43 +0000332 /*
333 * While in this state the IO request object is waiting for the TC
334 * completion notification for the H2D Register FIS
Dan Williams5dec6f42011-05-10 02:28:49 -0700335 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000336 SCI_REQ_STP_PIO_WAIT_H2D,
Dan Williams5dec6f42011-05-10 02:28:49 -0700337
Edmund Nadolskie3013702011-06-02 00:10:43 +0000338 /*
339 * While in this state the IO request object is waiting for either a
340 * PIO Setup FIS or a D2H register FIS. The type of frame received is
341 * based on the result of the prior frame and line conditions.
Dan Williams5dec6f42011-05-10 02:28:49 -0700342 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000343 SCI_REQ_STP_PIO_WAIT_FRAME,
Dan Williams5dec6f42011-05-10 02:28:49 -0700344
Edmund Nadolskie3013702011-06-02 00:10:43 +0000345 /*
346 * While in this state the IO request object is waiting for a DATA
347 * frame from the device.
Dan Williams5dec6f42011-05-10 02:28:49 -0700348 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000349 SCI_REQ_STP_PIO_DATA_IN,
Dan Williams5dec6f42011-05-10 02:28:49 -0700350
Edmund Nadolskie3013702011-06-02 00:10:43 +0000351 /*
352 * While in this state the IO request object is waiting to transmit
353 * the next data frame to the device.
Dan Williams5dec6f42011-05-10 02:28:49 -0700354 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000355 SCI_REQ_STP_PIO_DATA_OUT,
Dan Williams5dec6f42011-05-10 02:28:49 -0700356
Edmund Nadolskie3013702011-06-02 00:10:43 +0000357 /*
Dan Williamsf1393032011-05-10 02:28:47 -0700358 * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
359 * task management request is waiting for the transmission of the
360 * initial frame (i.e. command, task, etc.).
361 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000362 SCI_REQ_TASK_WAIT_TC_COMP,
Dan Williamsf1393032011-05-10 02:28:47 -0700363
Edmund Nadolskie3013702011-06-02 00:10:43 +0000364 /*
Dan Williamsf1393032011-05-10 02:28:47 -0700365 * This sub-state indicates that the started task management request
366 * is waiting for the reception of an unsolicited frame
367 * (i.e. response IU).
368 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000369 SCI_REQ_TASK_WAIT_TC_RESP,
Dan Williamsf1393032011-05-10 02:28:47 -0700370
Edmund Nadolskie3013702011-06-02 00:10:43 +0000371 /*
Dan Williamsc72086e2011-05-10 02:28:48 -0700372 * This sub-state indicates that the started task management request
373 * is waiting for the reception of an unsolicited frame
374 * (i.e. response IU).
375 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000376 SCI_REQ_SMP_WAIT_RESP,
Dan Williamsc72086e2011-05-10 02:28:48 -0700377
Edmund Nadolskie3013702011-06-02 00:10:43 +0000378 /*
379 * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP
380 * request is waiting for the transmission of the initial frame
381 * (i.e. command, task, etc.).
Dan Williamsc72086e2011-05-10 02:28:48 -0700382 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000383 SCI_REQ_SMP_WAIT_TC_COMP,
Dan Williamsc72086e2011-05-10 02:28:48 -0700384
Edmund Nadolskie3013702011-06-02 00:10:43 +0000385 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700386 * This state indicates that the request has completed.
Edmund Nadolskie3013702011-06-02 00:10:43 +0000387 * This state is entered from the STARTED state. This state is entered
388 * from the ABORTING state.
Dan Williamsf1f52e72011-05-10 02:28:45 -0700389 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000390 SCI_REQ_COMPLETED,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700391
Edmund Nadolskie3013702011-06-02 00:10:43 +0000392 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700393 * This state indicates that the request is in the process of being
394 * terminated/aborted.
395 * This state is entered from the CONSTRUCTED state.
396 * This state is entered from the STARTED state.
397 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000398 SCI_REQ_ABORTING,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700399
Edmund Nadolskie3013702011-06-02 00:10:43 +0000400 /*
Dan Williamsf1f52e72011-05-10 02:28:45 -0700401 * Simply the final state for the base request state machine.
402 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000403 SCI_REQ_FINAL,
Dan Williamsf1f52e72011-05-10 02:28:45 -0700404};
405
Dan Williamsf1f52e72011-05-10 02:28:45 -0700406/**
407 * scic_sds_request_get_controller() -
408 *
409 * This macro will return the controller for this io request object
410 */
411#define scic_sds_request_get_controller(sci_req) \
412 ((sci_req)->owning_controller)
413
414/**
415 * scic_sds_request_get_device() -
416 *
417 * This macro will return the device for this io request object
418 */
419#define scic_sds_request_get_device(sci_req) \
420 ((sci_req)->target_device)
421
422/**
423 * scic_sds_request_get_port() -
424 *
425 * This macro will return the port for this io request object
426 */
427#define scic_sds_request_get_port(sci_req) \
428 scic_sds_remote_device_get_port(scic_sds_request_get_device(sci_req))
429
430/**
431 * scic_sds_request_get_post_context() -
432 *
433 * This macro returns the constructed post context result for the io request.
434 */
435#define scic_sds_request_get_post_context(sci_req) \
436 ((sci_req)->post_context)
437
438/**
439 * scic_sds_request_get_task_context() -
440 *
441 * This is a helper macro to return the os handle for this request object.
442 */
443#define scic_sds_request_get_task_context(request) \
444 ((request)->task_context_buffer)
445
446/**
447 * scic_sds_request_set_status() -
448 *
449 * This macro will set the scu hardware status and sci request completion
450 * status for an io request.
451 */
452#define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \
453 { \
454 (request)->scu_status = (scu_status_code); \
455 (request)->sci_status = (sci_status_code); \
456 }
457
Dan Williamsf1f52e72011-05-10 02:28:45 -0700458enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req);
459enum sci_status scic_sds_io_request_terminate(struct scic_sds_request *sci_req);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000460enum sci_status
461scic_sds_io_request_event_handler(struct scic_sds_request *sci_req,
462 u32 event_code);
463enum sci_status
464scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req,
465 u32 frame_index);
466enum sci_status
467scic_sds_task_request_terminate(struct scic_sds_request *sci_req);
468extern enum sci_status
469scic_sds_request_complete(struct scic_sds_request *sci_req);
470extern enum sci_status
471scic_sds_io_request_tc_completion(struct scic_sds_request *sci_req, u32 code);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700472
Dan Williamsf1f52e72011-05-10 02:28:45 -0700473/* XXX open code in caller */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000474static inline dma_addr_t
475scic_io_request_get_dma_addr(struct scic_sds_request *sci_req, void *virt_addr)
Dan Williamsf1f52e72011-05-10 02:28:45 -0700476{
477 struct isci_request *ireq = sci_req_to_ireq(sci_req);
478
479 char *requested_addr = (char *)virt_addr;
480 char *base_addr = (char *)ireq;
481
482 BUG_ON(requested_addr < base_addr);
483 BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
484
485 return ireq->request_daddr + (requested_addr - base_addr);
486}
487
488/**
Dan Williams6f231dd2011-07-02 22:56:22 -0700489 * This function gets the status of the request object.
490 * @request: This parameter points to the isci_request object
491 *
492 * status of the object as a isci_request_status enum.
493 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000494static inline enum isci_request_status
495isci_request_get_state(struct isci_request *isci_request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700496{
497 BUG_ON(isci_request == NULL);
498
499 /*probably a bad sign... */
500 if (isci_request->status == unallocated)
501 dev_warn(&isci_request->isci_host->pdev->dev,
502 "%s: isci_request->status == unallocated\n",
503 __func__);
504
505 return isci_request->status;
506}
507
508
509/**
510 * isci_request_change_state() - This function sets the status of the request
511 * object.
512 * @request: This parameter points to the isci_request object
513 * @status: This Parameter is the new status of the object
514 *
515 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000516static inline enum isci_request_status
517isci_request_change_state(struct isci_request *isci_request,
518 enum isci_request_status status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700519{
520 enum isci_request_status old_state;
521 unsigned long flags;
522
523 dev_dbg(&isci_request->isci_host->pdev->dev,
524 "%s: isci_request = %p, state = 0x%x\n",
525 __func__,
526 isci_request,
527 status);
528
529 BUG_ON(isci_request == NULL);
530
531 spin_lock_irqsave(&isci_request->state_lock, flags);
532 old_state = isci_request->status;
533 isci_request->status = status;
534 spin_unlock_irqrestore(&isci_request->state_lock, flags);
535
536 return old_state;
537}
538
539/**
540 * isci_request_change_started_to_newstate() - This function sets the status of
541 * the request object.
542 * @request: This parameter points to the isci_request object
543 * @status: This Parameter is the new status of the object
544 *
545 * state previous to any change.
546 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000547static inline enum isci_request_status
548isci_request_change_started_to_newstate(struct isci_request *isci_request,
549 struct completion *completion_ptr,
550 enum isci_request_status newstate)
Dan Williams6f231dd2011-07-02 22:56:22 -0700551{
552 enum isci_request_status old_state;
553 unsigned long flags;
554
Dan Williams6f231dd2011-07-02 22:56:22 -0700555 spin_lock_irqsave(&isci_request->state_lock, flags);
556
557 old_state = isci_request->status;
558
Jeff Skirvinf219f012011-03-31 13:10:34 -0700559 if (old_state == started || old_state == aborting) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700560 BUG_ON(isci_request->io_request_completion != NULL);
561
562 isci_request->io_request_completion = completion_ptr;
563 isci_request->status = newstate;
564 }
Edmund Nadolskie3013702011-06-02 00:10:43 +0000565
Dan Williams6f231dd2011-07-02 22:56:22 -0700566 spin_unlock_irqrestore(&isci_request->state_lock, flags);
567
568 dev_dbg(&isci_request->isci_host->pdev->dev,
569 "%s: isci_request = %p, old_state = 0x%x\n",
570 __func__,
571 isci_request,
572 old_state);
573
574 return old_state;
575}
576
577/**
578 * isci_request_change_started_to_aborted() - This function sets the status of
579 * the request object.
580 * @request: This parameter points to the isci_request object
581 * @completion_ptr: This parameter is saved as the kernel completion structure
582 * signalled when the old request completes.
583 *
584 * state previous to any change.
585 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000586static inline enum isci_request_status
587isci_request_change_started_to_aborted(struct isci_request *isci_request,
588 struct completion *completion_ptr)
Dan Williams6f231dd2011-07-02 22:56:22 -0700589{
Edmund Nadolskie3013702011-06-02 00:10:43 +0000590 return isci_request_change_started_to_newstate(isci_request,
591 completion_ptr,
592 aborted);
Dan Williams6f231dd2011-07-02 22:56:22 -0700593}
Dan Williams6f231dd2011-07-02 22:56:22 -0700594
Edmund Nadolskie3013702011-06-02 00:10:43 +0000595#define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
Dan Williams6f231dd2011-07-02 22:56:22 -0700596
Edmund Nadolskie3013702011-06-02 00:10:43 +0000597#define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
Dan Williams6f231dd2011-07-02 22:56:22 -0700598
Dan Williamsdb056252011-06-17 14:18:39 -0700599struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
600 struct isci_tmf *isci_tmf,
601 u16 tag);
Dan Williams209fae12011-06-13 17:39:44 -0700602int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
Dan Williamsdb056252011-06-17 14:18:39 -0700603 struct sas_task *task, u16 tag);
Dan Williamsddcc7e32011-06-17 10:40:43 -0700604void isci_terminate_pending_requests(struct isci_host *ihost,
605 struct isci_remote_device *idev);
Edmund Nadolskie3013702011-06-02 00:10:43 +0000606enum sci_status
607scic_task_request_construct(struct scic_sds_controller *scic,
608 struct scic_sds_remote_device *sci_dev,
609 u16 io_tag,
610 struct scic_sds_request *sci_req);
611enum sci_status
612scic_task_request_construct_ssp(struct scic_sds_request *sci_req);
613enum sci_status
614scic_task_request_construct_sata(struct scic_sds_request *sci_req);
615void
616scic_stp_io_request_set_ncq_tag(struct scic_sds_request *sci_req, u16 ncq_tag);
Dan Williamsf1f52e72011-05-10 02:28:45 -0700617void scic_sds_smp_request_copy_response(struct scic_sds_request *sci_req);
Jeff Skirvin9274f452011-06-23 17:09:02 -0700618
619static inline int isci_task_is_ncq_recovery(struct sas_task *task)
620{
621 return (sas_protocol_ata(task->task_proto) &&
622 task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
623 task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
624
625}
626
Dan Williams6f231dd2011-07-02 22:56:22 -0700627#endif /* !defined(_ISCI_REQUEST_H_) */