mach-ux500: enable ARM errata 764369
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / request.h
blobbe38933dd6dff5a2362a2f9074a7b9491f542354
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.
5 * GPL LICENSE SUMMARY
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.
24 * BSD LICENSE
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
31 * are met:
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.
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_
59 #include "isci.h"
60 #include "host.h"
61 #include "scu_task_context.h"
63 /**
64 * struct isci_request_status - This enum defines the possible states of an I/O
65 * request.
69 enum isci_request_status {
70 unallocated = 0x00,
71 allocated = 0x01,
72 started = 0x02,
73 completed = 0x03,
74 aborting = 0x04,
75 aborted = 0x05,
76 terminating = 0x06,
77 dead = 0x07
80 enum sci_request_protocol {
81 SCIC_NO_PROTOCOL,
82 SCIC_SMP_PROTOCOL,
83 SCIC_SSP_PROTOCOL,
84 SCIC_STP_PROTOCOL
85 }; /* XXX remove me, use sas_task.{dev|task_proto} instead */;
87 /**
88 * isci_stp_request - extra request infrastructure to handle pio/atapi protocol
89 * @pio_len - number of bytes requested at PIO setup
90 * @status - pio setup ending status value to tell us if we need
91 * to wait for another fis or if the transfer is complete. Upon
92 * receipt of a d2h fis this will be the status field of that fis.
93 * @sgl - track pio transfer progress as we iterate through the sgl
95 struct isci_stp_request {
96 u32 pio_len;
97 u8 status;
99 struct isci_stp_pio_sgl {
100 int index;
101 u8 set;
102 u32 offset;
103 } sgl;
106 struct isci_request {
107 enum isci_request_status status;
108 #define IREQ_COMPLETE_IN_TARGET 0
109 #define IREQ_TERMINATED 1
110 #define IREQ_TMF 2
111 #define IREQ_ACTIVE 3
112 unsigned long flags;
113 /* XXX kill ttype and ttype_ptr, allocate full sas_task */
114 union ttype_ptr_union {
115 struct sas_task *io_task_ptr; /* When ttype==io_task */
116 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
117 } ttype_ptr;
118 struct isci_host *isci_host;
119 /* For use in the requests_to_{complete|abort} lists: */
120 struct list_head completed_node;
121 /* For use in the reqs_in_process list: */
122 struct list_head dev_node;
123 spinlock_t state_lock;
124 dma_addr_t request_daddr;
125 dma_addr_t zero_scatter_daddr;
126 unsigned int num_sg_entries;
127 /* Note: "io_request_completion" is completed in two different ways
128 * depending on whether this is a TMF or regular request.
129 * - TMF requests are completed in the thread that started them;
130 * - regular requests are completed in the request completion callback
131 * function.
132 * This difference in operation allows the aborter of a TMF request
133 * to be sure that once the TMF request completes, the I/O that the
134 * TMF was aborting is guaranteed to have completed.
136 * XXX kill io_request_completion
138 struct completion *io_request_completion;
139 struct sci_base_state_machine sm;
140 struct isci_host *owning_controller;
141 struct isci_remote_device *target_device;
142 u16 io_tag;
143 enum sci_request_protocol protocol;
144 u32 scu_status; /* hardware result */
145 u32 sci_status; /* upper layer disposition */
146 u32 post_context;
147 struct scu_task_context *tc;
148 /* could be larger with sg chaining */
149 #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
150 struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
151 /* This field is a pointer to the stored rx frame data. It is used in
152 * STP internal requests and SMP response frames. If this field is
153 * non-NULL the saved frame must be released on IO request completion.
155 u32 saved_rx_frame_index;
157 union {
158 struct {
159 union {
160 struct ssp_cmd_iu cmd;
161 struct ssp_task_iu tmf;
163 union {
164 struct ssp_response_iu rsp;
165 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
167 } ssp;
168 struct {
169 struct isci_stp_request req;
170 struct host_to_dev_fis cmd;
171 struct dev_to_host_fis rsp;
172 } stp;
176 static inline struct isci_request *to_ireq(struct isci_stp_request *stp_req)
178 struct isci_request *ireq;
180 ireq = container_of(stp_req, typeof(*ireq), stp.req);
181 return ireq;
185 * enum sci_base_request_states - This enumeration depicts all the states for
186 * the common request state machine.
190 enum sci_base_request_states {
192 * Simply the initial state for the base request state machine.
194 SCI_REQ_INIT,
197 * This state indicates that the request has been constructed.
198 * This state is entered from the INITIAL state.
200 SCI_REQ_CONSTRUCTED,
203 * This state indicates that the request has been started. This state
204 * is entered from the CONSTRUCTED state.
206 SCI_REQ_STARTED,
208 SCI_REQ_STP_UDMA_WAIT_TC_COMP,
209 SCI_REQ_STP_UDMA_WAIT_D2H,
211 SCI_REQ_STP_NON_DATA_WAIT_H2D,
212 SCI_REQ_STP_NON_DATA_WAIT_D2H,
214 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED,
215 SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG,
216 SCI_REQ_STP_SOFT_RESET_WAIT_D2H,
219 * While in this state the IO request object is waiting for the TC
220 * completion notification for the H2D Register FIS
222 SCI_REQ_STP_PIO_WAIT_H2D,
225 * While in this state the IO request object is waiting for either a
226 * PIO Setup FIS or a D2H register FIS. The type of frame received is
227 * based on the result of the prior frame and line conditions.
229 SCI_REQ_STP_PIO_WAIT_FRAME,
232 * While in this state the IO request object is waiting for a DATA
233 * frame from the device.
235 SCI_REQ_STP_PIO_DATA_IN,
238 * While in this state the IO request object is waiting to transmit
239 * the next data frame to the device.
241 SCI_REQ_STP_PIO_DATA_OUT,
244 * While in this state the IO request object is waiting for the TC
245 * completion notification for the H2D Register FIS
247 SCI_REQ_ATAPI_WAIT_H2D,
250 * While in this state the IO request object is waiting for either a
251 * PIO Setup.
253 SCI_REQ_ATAPI_WAIT_PIO_SETUP,
256 * The non-data IO transit to this state in this state after receiving
257 * TC completion. While in this state IO request object is waiting for
258 * D2H status frame as UF.
260 SCI_REQ_ATAPI_WAIT_D2H,
263 * When transmitting raw frames hardware reports task context completion
264 * after every frame submission, so in the non-accelerated case we need
265 * to expect the completion for the "cdb" frame.
267 SCI_REQ_ATAPI_WAIT_TC_COMP,
270 * The AWAIT_TC_COMPLETION sub-state indicates that the started raw
271 * task management request is waiting for the transmission of the
272 * initial frame (i.e. command, task, etc.).
274 SCI_REQ_TASK_WAIT_TC_COMP,
277 * This sub-state indicates that the started task management request
278 * is waiting for the reception of an unsolicited frame
279 * (i.e. response IU).
281 SCI_REQ_TASK_WAIT_TC_RESP,
284 * This sub-state indicates that the started task management request
285 * is waiting for the reception of an unsolicited frame
286 * (i.e. response IU).
288 SCI_REQ_SMP_WAIT_RESP,
291 * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP
292 * request is waiting for the transmission of the initial frame
293 * (i.e. command, task, etc.).
295 SCI_REQ_SMP_WAIT_TC_COMP,
298 * This state indicates that the request has completed.
299 * This state is entered from the STARTED state. This state is entered
300 * from the ABORTING state.
302 SCI_REQ_COMPLETED,
305 * This state indicates that the request is in the process of being
306 * terminated/aborted.
307 * This state is entered from the CONSTRUCTED state.
308 * This state is entered from the STARTED state.
310 SCI_REQ_ABORTING,
313 * Simply the final state for the base request state machine.
315 SCI_REQ_FINAL,
318 enum sci_status sci_request_start(struct isci_request *ireq);
319 enum sci_status sci_io_request_terminate(struct isci_request *ireq);
320 enum sci_status
321 sci_io_request_event_handler(struct isci_request *ireq,
322 u32 event_code);
323 enum sci_status
324 sci_io_request_frame_handler(struct isci_request *ireq,
325 u32 frame_index);
326 enum sci_status
327 sci_task_request_terminate(struct isci_request *ireq);
328 extern enum sci_status
329 sci_request_complete(struct isci_request *ireq);
330 extern enum sci_status
331 sci_io_request_tc_completion(struct isci_request *ireq, u32 code);
333 /* XXX open code in caller */
334 static inline dma_addr_t
335 sci_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr)
338 char *requested_addr = (char *)virt_addr;
339 char *base_addr = (char *)ireq;
341 BUG_ON(requested_addr < base_addr);
342 BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
344 return ireq->request_daddr + (requested_addr - base_addr);
348 * isci_request_change_state() - This function sets the status of the request
349 * object.
350 * @request: This parameter points to the isci_request object
351 * @status: This Parameter is the new status of the object
354 static inline enum isci_request_status
355 isci_request_change_state(struct isci_request *isci_request,
356 enum isci_request_status status)
358 enum isci_request_status old_state;
359 unsigned long flags;
361 dev_dbg(&isci_request->isci_host->pdev->dev,
362 "%s: isci_request = %p, state = 0x%x\n",
363 __func__,
364 isci_request,
365 status);
367 BUG_ON(isci_request == NULL);
369 spin_lock_irqsave(&isci_request->state_lock, flags);
370 old_state = isci_request->status;
371 isci_request->status = status;
372 spin_unlock_irqrestore(&isci_request->state_lock, flags);
374 return old_state;
378 * isci_request_change_started_to_newstate() - This function sets the status of
379 * the request object.
380 * @request: This parameter points to the isci_request object
381 * @status: This Parameter is the new status of the object
383 * state previous to any change.
385 static inline enum isci_request_status
386 isci_request_change_started_to_newstate(struct isci_request *isci_request,
387 struct completion *completion_ptr,
388 enum isci_request_status newstate)
390 enum isci_request_status old_state;
391 unsigned long flags;
393 spin_lock_irqsave(&isci_request->state_lock, flags);
395 old_state = isci_request->status;
397 if (old_state == started || old_state == aborting) {
398 BUG_ON(isci_request->io_request_completion != NULL);
400 isci_request->io_request_completion = completion_ptr;
401 isci_request->status = newstate;
404 spin_unlock_irqrestore(&isci_request->state_lock, flags);
406 dev_dbg(&isci_request->isci_host->pdev->dev,
407 "%s: isci_request = %p, old_state = 0x%x\n",
408 __func__,
409 isci_request,
410 old_state);
412 return old_state;
416 * isci_request_change_started_to_aborted() - This function sets the status of
417 * the request object.
418 * @request: This parameter points to the isci_request object
419 * @completion_ptr: This parameter is saved as the kernel completion structure
420 * signalled when the old request completes.
422 * state previous to any change.
424 static inline enum isci_request_status
425 isci_request_change_started_to_aborted(struct isci_request *isci_request,
426 struct completion *completion_ptr)
428 return isci_request_change_started_to_newstate(isci_request,
429 completion_ptr,
430 aborted);
433 #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
435 #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
437 struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
438 struct isci_tmf *isci_tmf,
439 u16 tag);
440 int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
441 struct sas_task *task, u16 tag);
442 void isci_terminate_pending_requests(struct isci_host *ihost,
443 struct isci_remote_device *idev);
444 enum sci_status
445 sci_task_request_construct(struct isci_host *ihost,
446 struct isci_remote_device *idev,
447 u16 io_tag,
448 struct isci_request *ireq);
449 enum sci_status
450 sci_task_request_construct_ssp(struct isci_request *ireq);
451 enum sci_status
452 sci_task_request_construct_sata(struct isci_request *ireq);
453 void sci_smp_request_copy_response(struct isci_request *ireq);
455 static inline int isci_task_is_ncq_recovery(struct sas_task *task)
457 return (sas_protocol_ata(task->task_proto) &&
458 task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
459 task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
463 #endif /* !defined(_ISCI_REQUEST_H_) */