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_
60 #include "scic_sds_request.h"
63 * struct isci_request_status - This enum defines the possible states of an I/O
68 enum isci_request_status
{
85 struct scic_sds_request
*sci_request_handle
;
86 enum isci_request_status status
;
88 unsigned short io_tag
;
89 bool complete_in_target
;
91 union ttype_ptr_union
{
92 struct sas_task
*io_task_ptr
; /* When ttype==io_task */
93 struct isci_tmf
*tmf_task_ptr
; /* When ttype==tmf_task */
95 struct isci_host
*isci_host
;
96 struct isci_remote_device
*isci_device
;
97 /* For use in the requests_to_{complete|abort} lists: */
98 struct list_head completed_node
;
99 /* For use in the reqs_in_process list: */
100 struct list_head dev_node
;
101 spinlock_t state_lock
;
102 dma_addr_t request_daddr
;
103 dma_addr_t zero_scatter_daddr
;
105 unsigned int num_sg_entries
; /* returned by pci_alloc_sg */
106 unsigned int request_alloc_size
; /* size of block from dma_pool_alloc */
108 /** Note: "io_request_completion" is completed in two different ways
109 * depending on whether this is a TMF or regular request.
110 * - TMF requests are completed in the thread that started them;
111 * - regular requests are completed in the request completion callback
113 * This difference in operation allows the aborter of a TMF request
114 * to be sure that once the TMF request completes, the I/O that the
115 * TMF was aborting is guaranteed to have completed.
117 struct completion
*io_request_completion
;
118 struct scic_sds_request sci_req
[0] ____cacheline_aligned
;
122 * This function gets the status of the request object.
123 * @request: This parameter points to the isci_request object
125 * status of the object as a isci_request_status enum.
128 enum isci_request_status
isci_request_get_state(
129 struct isci_request
*isci_request
)
131 BUG_ON(isci_request
== NULL
);
133 /*probably a bad sign... */
134 if (isci_request
->status
== unallocated
)
135 dev_warn(&isci_request
->isci_host
->pdev
->dev
,
136 "%s: isci_request->status == unallocated\n",
139 return isci_request
->status
;
144 * isci_request_change_state() - This function sets the status of the request
146 * @request: This parameter points to the isci_request object
147 * @status: This Parameter is the new status of the object
150 static inline enum isci_request_status
isci_request_change_state(
151 struct isci_request
*isci_request
,
152 enum isci_request_status status
)
154 enum isci_request_status old_state
;
157 dev_dbg(&isci_request
->isci_host
->pdev
->dev
,
158 "%s: isci_request = %p, state = 0x%x\n",
163 BUG_ON(isci_request
== NULL
);
165 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
166 old_state
= isci_request
->status
;
167 isci_request
->status
= status
;
168 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
174 * isci_request_change_started_to_newstate() - This function sets the status of
175 * the request object.
176 * @request: This parameter points to the isci_request object
177 * @status: This Parameter is the new status of the object
179 * state previous to any change.
181 static inline enum isci_request_status
isci_request_change_started_to_newstate(
182 struct isci_request
*isci_request
,
183 struct completion
*completion_ptr
,
184 enum isci_request_status newstate
)
186 enum isci_request_status old_state
;
189 spin_lock_irqsave(&isci_request
->state_lock
, flags
);
191 old_state
= isci_request
->status
;
193 if (old_state
== started
|| old_state
== aborting
) {
194 BUG_ON(isci_request
->io_request_completion
!= NULL
);
196 isci_request
->io_request_completion
= completion_ptr
;
197 isci_request
->status
= newstate
;
199 spin_unlock_irqrestore(&isci_request
->state_lock
, flags
);
201 dev_dbg(&isci_request
->isci_host
->pdev
->dev
,
202 "%s: isci_request = %p, old_state = 0x%x\n",
211 * isci_request_change_started_to_aborted() - This function sets the status of
212 * the request object.
213 * @request: This parameter points to the isci_request object
214 * @completion_ptr: This parameter is saved as the kernel completion structure
215 * signalled when the old request completes.
217 * state previous to any change.
219 static inline enum isci_request_status
isci_request_change_started_to_aborted(
220 struct isci_request
*isci_request
,
221 struct completion
*completion_ptr
)
223 return isci_request_change_started_to_newstate(
224 isci_request
, completion_ptr
, aborted
228 * isci_request_free() - This function frees the request object.
229 * @isci_host: This parameter specifies the ISCI host object
230 * @isci_request: This parameter points to the isci_request object
233 static inline void isci_request_free(
234 struct isci_host
*isci_host
,
235 struct isci_request
*isci_request
)
240 /* release the dma memory if we fail. */
241 dma_pool_free(isci_host
->dma_pool
, isci_request
,
242 isci_request
->request_daddr
);
246 /* #define ISCI_REQUEST_VALIDATE_ACCESS
249 #ifdef ISCI_REQUEST_VALIDATE_ACCESS
252 struct sas_task
*isci_request_access_task(struct isci_request
*isci_request
)
254 BUG_ON(isci_request
->ttype
!= io_task
);
255 return isci_request
->ttype_ptr
.io_task_ptr
;
259 struct isci_tmf
*isci_request_access_tmf(struct isci_request
*isci_request
)
261 BUG_ON(isci_request
->ttype
!= tmf_task
);
262 return isci_request
->ttype_ptr
.tmf_task_ptr
;
265 #else /* not ISCI_REQUEST_VALIDATE_ACCESS */
267 #define isci_request_access_task(RequestPtr) \
268 ((RequestPtr)->ttype_ptr.io_task_ptr)
270 #define isci_request_access_tmf(RequestPtr) \
271 ((RequestPtr)->ttype_ptr.tmf_task_ptr)
273 #endif /* not ISCI_REQUEST_VALIDATE_ACCESS */
276 int isci_request_alloc_tmf(
277 struct isci_host
*isci_host
,
278 struct isci_tmf
*isci_tmf
,
279 struct isci_request
**isci_request
,
280 struct isci_remote_device
*isci_device
,
284 int isci_request_execute(
285 struct isci_host
*isci_host
,
286 struct sas_task
*task
,
287 struct isci_request
**request
,
291 * isci_request_unmap_sgl() - This function unmaps the DMA address of a given
293 * @request: This parameter points to the isci_request object
294 * @*pdev: This Parameter is the pci_device struct for the controller
297 static inline void isci_request_unmap_sgl(
298 struct isci_request
*request
,
299 struct pci_dev
*pdev
)
301 struct sas_task
*task
= isci_request_access_task(request
);
303 dev_dbg(&request
->isci_host
->pdev
->dev
,
304 "%s: request = %p, task = %p,\n"
305 "task->data_dir = %d, is_sata = %d\n ",
310 sas_protocol_ata(task
->task_proto
));
312 if ((task
->data_dir
!= PCI_DMA_NONE
) &&
313 !sas_protocol_ata(task
->task_proto
)) {
314 if (task
->num_scatter
== 0)
315 /* 0 indicates a single dma address */
318 request
->zero_scatter_daddr
,
319 task
->total_xfer_len
,
323 else /* unmap the sgl dma addresses */
327 request
->num_sg_entries
,
334 void isci_request_io_request_complete(
335 struct isci_host
*isci_host
,
336 struct isci_request
*request
,
337 enum sci_io_status completion_status
);
340 * isci_request_io_request_get_next_sge() - This function is called by the sci
341 * core to retrieve the next sge for a given request.
342 * @request: This parameter is the isci_request object.
343 * @current_sge_address: This parameter is the last sge retrieved by the sci
344 * core for this request.
346 * pointer to the next sge for specified request.
348 static inline void *isci_request_io_request_get_next_sge(
349 struct isci_request
*request
,
350 void *current_sge_address
)
352 struct sas_task
*task
= isci_request_access_task(request
);
355 dev_dbg(&request
->isci_host
->pdev
->dev
,
357 "current_sge_address = %p, "
358 "num_scatter = %d\n",
364 if (!current_sge_address
) /* First time through.. */
365 ret
= task
->scatter
; /* always task->scatter */
366 else if (task
->num_scatter
== 0) /* Next element, if num_scatter == 0 */
367 ret
= NULL
; /* there is only one element. */
369 ret
= sg_next(current_sge_address
); /* sg_next returns NULL
370 * for the last element
373 dev_dbg(&request
->isci_host
->pdev
->dev
,
374 "%s: next sge address = %p\n",
382 void isci_terminate_pending_requests(
383 struct isci_host
*isci_host
,
384 struct isci_remote_device
*isci_device
,
385 enum isci_request_status new_request_state
);
390 #endif /* !defined(_ISCI_REQUEST_H_) */