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
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.
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.
56 #ifndef _ISCI_REQUEST_H_
57 #define _ISCI_REQUEST_H_
61 #include "scu_task_context.h"
64 * struct isci_request_status - This enum defines the possible states of an I/O
69 enum isci_request_status
{
85 enum sci_request_protocol
{
90 }; /* XXX remove me, use sas_task.{dev|task_proto} instead */;
93 * isci_stp_request - extra request infrastructure to handle pio/atapi protocol
94 * @pio_len - number of bytes requested at PIO setup
95 * @status - pio setup ending status value to tell us if we need
96 * to wait for another fis or if the transfer is complete. Upon
97 * receipt of a d2h fis this will be the status field of that fis.
98 * @sgl - track pio transfer progress as we iterate through the sgl
99 * @device_cdb_len - atapi device advertises it's transfer constraints at setup
101 struct isci_stp_request
{
105 struct isci_stp_pio_sgl
{
113 struct isci_request
{
114 enum isci_request_status status
;
115 #define IREQ_COMPLETE_IN_TARGET 0
116 #define IREQ_TERMINATED 1
118 #define IREQ_ACTIVE 3
120 /* XXX kill ttype and ttype_ptr, allocate full sas_task */
121 enum task_type ttype
;
122 union ttype_ptr_union
{
123 struct sas_task
*io_task_ptr
; /* When ttype==io_task */
124 struct isci_tmf
*tmf_task_ptr
; /* When ttype==tmf_task */
126 struct isci_host
*isci_host
;
127 /* For use in the requests_to_{complete|abort} lists: */
128 struct list_head completed_node
;
129 /* For use in the reqs_in_process list: */
130 struct list_head dev_node
;
131 spinlock_t state_lock
;
132 dma_addr_t request_daddr
;
133 dma_addr_t zero_scatter_daddr
;
134 unsigned int num_sg_entries
;
135 /* Note: "io_request_completion" is completed in two different ways
136 * depending on whether this is a TMF or regular request.
137 * - TMF requests are completed in the thread that started them;
138 * - regular requests are completed in the request completion callback
140 * This difference in operation allows the aborter of a TMF request
141 * to be sure that once the TMF request completes, the I/O that the
142 * TMF was aborting is guaranteed to have completed.
144 * XXX kill io_request_completion
146 struct completion
*io_request_completion
;
147 struct sci_base_state_machine sm
;
148 struct isci_host
*owning_controller
;
149 struct isci_remote_device
*target_device
;
151 enum sci_request_protocol protocol
;
152 u32 scu_status
; /* hardware result */
153 u32 sci_status
; /* upper layer disposition */
155 struct scu_task_context
*tc
;
156 /* could be larger with sg chaining */
157 #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
158 struct scu_sgl_element_pair sg_table
[SCU_SGL_SIZE
] __attribute__ ((aligned(32)));
159 /* This field is a pointer to the stored rx frame data. It is used in
160 * STP internal requests and SMP response frames. If this field is
161 * non-NULL the saved frame must be released on IO request completion.
163 u32 saved_rx_frame_index
;
168 struct ssp_cmd_iu cmd
;
169 struct ssp_task_iu tmf
;
172 struct ssp_response_iu rsp
;
173 u8 rsp_buf
[SSP_RESP_IU_MAX_SIZE
];
177 struct isci_stp_request req
;
178 struct host_to_dev_fis cmd
;
179 struct dev_to_host_fis rsp
;
184 static inline struct isci_request
*to_ireq(struct isci_stp_request
*stp_req
)
186 struct isci_request
*ireq
;
188 ireq
= container_of(stp_req
, typeof(*ireq
), stp
.req
);
193 * enum sci_base_request_states - This enumeration depicts all the states for
194 * the common request state machine.
198 enum sci_base_request_states
{
200 * Simply the initial state for the base request state machine.
205 * This state indicates that the request has been constructed.
206 * This state is entered from the INITIAL state.
211 * This state indicates that the request has been started. This state
212 * is entered from the CONSTRUCTED state.
216 SCI_REQ_STP_UDMA_WAIT_TC_COMP
,
217 SCI_REQ_STP_UDMA_WAIT_D2H
,
219 SCI_REQ_STP_NON_DATA_WAIT_H2D
,
220 SCI_REQ_STP_NON_DATA_WAIT_D2H
,
222 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED
,
223 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG
,
224 SCI_REQ_STP_SOFT_RESET_WAIT_D2H
,
227 * While in this state the IO request object is waiting for the TC
228 * completion notification for the H2D Register FIS
230 SCI_REQ_STP_PIO_WAIT_H2D
,
233 * While in this state the IO request object is waiting for either a
234 * PIO Setup FIS or a D2H register FIS. The type of frame received is
235 * based on the result of the prior frame and line conditions.
237 SCI_REQ_STP_PIO_WAIT_FRAME
,
240 * While in this state the IO request object is waiting for a DATA
241 * frame from the device.
243 SCI_REQ_STP_PIO_DATA_IN
,
246 * While in this state the IO request object is waiting to transmit
247 * the next data frame to the device.
249 SCI_REQ_STP_PIO_DATA_OUT
,
252 * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
253 * task management request is waiting for the transmission of the
254 * initial frame (i.e. command, task, etc.).
256 SCI_REQ_TASK_WAIT_TC_COMP
,
259 * This sub-state indicates that the started task management request
260 * is waiting for the reception of an unsolicited frame
261 * (i.e. response IU).
263 SCI_REQ_TASK_WAIT_TC_RESP
,
266 * This sub-state indicates that the started task management request
267 * is waiting for the reception of an unsolicited frame
268 * (i.e. response IU).
270 SCI_REQ_SMP_WAIT_RESP
,
273 * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP
274 * request is waiting for the transmission of the initial frame
275 * (i.e. command, task, etc.).
277 SCI_REQ_SMP_WAIT_TC_COMP
,
280 * This state indicates that the request has completed.
281 * This state is entered from the STARTED state. This state is entered
282 * from the ABORTING state.
287 * This state indicates that the request is in the process of being
288 * terminated/aborted.
289 * This state is entered from the CONSTRUCTED state.
290 * This state is entered from the STARTED state.
295 * Simply the final state for the base request state machine.
300 enum sci_status
sci_request_start(struct isci_request
*ireq
);
301 enum sci_status
sci_io_request_terminate(struct isci_request
*ireq
);
303 sci_io_request_event_handler(struct isci_request
*ireq
,
306 sci_io_request_frame_handler(struct isci_request
*ireq
,
309 sci_task_request_terminate(struct isci_request
*ireq
);
310 extern enum sci_status
311 sci_request_complete(struct isci_request
*ireq
);
312 extern enum sci_status
313 sci_io_request_tc_completion(struct isci_request
*ireq
, u32 code
);
315 /* XXX open code in caller */
316 static inline dma_addr_t
317 sci_io_request_get_dma_addr(struct isci_request
*ireq
, void *virt_addr
)
320 char *requested_addr
= (char *)virt_addr
;
321 char *base_addr
= (char *)ireq
;
323 BUG_ON(requested_addr
< base_addr
);
324 BUG_ON((requested_addr
- base_addr
) >= sizeof(*ireq
));
326 return ireq
->request_daddr
+ (requested_addr
- base_addr
);
330 * isci_request_change_state() - This function sets the status of the request
332 * @request: This parameter points to the isci_request object
333 * @status: This Parameter is the new status of the object
336 static inline enum isci_request_status
337 isci_request_change_state(struct isci_request
*isci_request
,
338 enum isci_request_status status
)
340 enum isci_request_status old_state
;
343 dev_dbg(&isci_request
->isci_host
->pdev
->dev
,
344 "%s: isci_request = %p, state = 0x%x\n",
349 BUG_ON(isci_request
== NULL
);
351 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
352 old_state
= isci_request
->status
;
353 isci_request
->status
= status
;
354 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
360 * isci_request_change_started_to_newstate() - This function sets the status of
361 * the request object.
362 * @request: This parameter points to the isci_request object
363 * @status: This Parameter is the new status of the object
365 * state previous to any change.
367 static inline enum isci_request_status
368 isci_request_change_started_to_newstate(struct isci_request
*isci_request
,
369 struct completion
*completion_ptr
,
370 enum isci_request_status newstate
)
372 enum isci_request_status old_state
;
375 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
377 old_state
= isci_request
->status
;
379 if (old_state
== started
|| old_state
== aborting
) {
380 BUG_ON(isci_request
->io_request_completion
!= NULL
);
382 isci_request
->io_request_completion
= completion_ptr
;
383 isci_request
->status
= newstate
;
386 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
388 dev_dbg(&isci_request
->isci_host
->pdev
->dev
,
389 "%s: isci_request = %p, old_state = 0x%x\n",
398 * isci_request_change_started_to_aborted() - This function sets the status of
399 * the request object.
400 * @request: This parameter points to the isci_request object
401 * @completion_ptr: This parameter is saved as the kernel completion structure
402 * signalled when the old request completes.
404 * state previous to any change.
406 static inline enum isci_request_status
407 isci_request_change_started_to_aborted(struct isci_request
*isci_request
,
408 struct completion
*completion_ptr
)
410 return isci_request_change_started_to_newstate(isci_request
,
415 #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
417 #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
419 struct isci_request
*isci_tmf_request_from_tag(struct isci_host
*ihost
,
420 struct isci_tmf
*isci_tmf
,
422 int isci_request_execute(struct isci_host
*ihost
, struct isci_remote_device
*idev
,
423 struct sas_task
*task
, u16 tag
);
424 void isci_terminate_pending_requests(struct isci_host
*ihost
,
425 struct isci_remote_device
*idev
);
427 sci_task_request_construct(struct isci_host
*ihost
,
428 struct isci_remote_device
*idev
,
430 struct isci_request
*ireq
);
432 sci_task_request_construct_ssp(struct isci_request
*ireq
);
434 sci_task_request_construct_sata(struct isci_request
*ireq
);
435 void sci_smp_request_copy_response(struct isci_request
*ireq
);
437 static inline int isci_task_is_ncq_recovery(struct sas_task
*task
)
439 return (sas_protocol_ata(task
->task_proto
) &&
440 task
->ata_task
.fis
.command
== ATA_CMD_READ_LOG_EXT
&&
441 task
->ata_task
.fis
.lbal
== ATA_LOG_SATA_NCQ
);
445 #endif /* !defined(_ISCI_REQUEST_H_) */