isci: kill sci_phy_protocol and sci_request_protocol
[linux-2.6.git] / drivers / scsi / isci / request.h
blob4961f9fbf70fec8ea706d6a464b6da356170bba5
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 /**
81 * isci_stp_request - extra request infrastructure to handle pio/atapi protocol
82 * @pio_len - number of bytes requested at PIO setup
83 * @status - pio setup ending status value to tell us if we need
84 * to wait for another fis or if the transfer is complete. Upon
85 * receipt of a d2h fis this will be the status field of that fis.
86 * @sgl - track pio transfer progress as we iterate through the sgl
88 struct isci_stp_request {
89 u32 pio_len;
90 u8 status;
92 struct isci_stp_pio_sgl {
93 int index;
94 u8 set;
95 u32 offset;
96 } sgl;
99 struct isci_request {
100 enum isci_request_status status;
101 #define IREQ_COMPLETE_IN_TARGET 0
102 #define IREQ_TERMINATED 1
103 #define IREQ_TMF 2
104 #define IREQ_ACTIVE 3
105 unsigned long flags;
106 /* XXX kill ttype and ttype_ptr, allocate full sas_task */
107 union ttype_ptr_union {
108 struct sas_task *io_task_ptr; /* When ttype==io_task */
109 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
110 } ttype_ptr;
111 struct isci_host *isci_host;
112 /* For use in the requests_to_{complete|abort} lists: */
113 struct list_head completed_node;
114 /* For use in the reqs_in_process list: */
115 struct list_head dev_node;
116 spinlock_t state_lock;
117 dma_addr_t request_daddr;
118 dma_addr_t zero_scatter_daddr;
119 unsigned int num_sg_entries;
120 /* Note: "io_request_completion" is completed in two different ways
121 * depending on whether this is a TMF or regular request.
122 * - TMF requests are completed in the thread that started them;
123 * - regular requests are completed in the request completion callback
124 * function.
125 * This difference in operation allows the aborter of a TMF request
126 * to be sure that once the TMF request completes, the I/O that the
127 * TMF was aborting is guaranteed to have completed.
129 * XXX kill io_request_completion
131 struct completion *io_request_completion;
132 struct sci_base_state_machine sm;
133 struct isci_host *owning_controller;
134 struct isci_remote_device *target_device;
135 u16 io_tag;
136 enum sas_protocol protocol;
137 u32 scu_status; /* hardware result */
138 u32 sci_status; /* upper layer disposition */
139 u32 post_context;
140 struct scu_task_context *tc;
141 /* could be larger with sg chaining */
142 #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
143 struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
144 /* This field is a pointer to the stored rx frame data. It is used in
145 * STP internal requests and SMP response frames. If this field is
146 * non-NULL the saved frame must be released on IO request completion.
148 u32 saved_rx_frame_index;
150 union {
151 struct {
152 union {
153 struct ssp_cmd_iu cmd;
154 struct ssp_task_iu tmf;
156 union {
157 struct ssp_response_iu rsp;
158 u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
160 } ssp;
161 struct {
162 struct isci_stp_request req;
163 struct host_to_dev_fis cmd;
164 struct dev_to_host_fis rsp;
165 } stp;
169 static inline struct isci_request *to_ireq(struct isci_stp_request *stp_req)
171 struct isci_request *ireq;
173 ireq = container_of(stp_req, typeof(*ireq), stp.req);
174 return ireq;
178 * enum sci_base_request_states - request state machine states
180 * @SCI_REQ_INIT: Simply the initial state for the base request state machine.
182 * @SCI_REQ_CONSTRUCTED: This state indicates that the request has been
183 * constructed. This state is entered from the INITIAL state.
185 * @SCI_REQ_STARTED: This state indicates that the request has been started.
186 * This state is entered from the CONSTRUCTED state.
188 * @SCI_REQ_STP_UDMA_WAIT_TC_COMP:
189 * @SCI_REQ_STP_UDMA_WAIT_D2H:
190 * @SCI_REQ_STP_NON_DATA_WAIT_H2D:
191 * @SCI_REQ_STP_NON_DATA_WAIT_D2H:
193 * @SCI_REQ_STP_PIO_WAIT_H2D: While in this state the IO request object is
194 * waiting for the TC completion notification for the H2D Register FIS
196 * @SCI_REQ_STP_PIO_WAIT_FRAME: While in this state the IO request object is
197 * waiting for either a PIO Setup FIS or a D2H register FIS. The type of frame
198 * received is based on the result of the prior frame and line conditions.
200 * @SCI_REQ_STP_PIO_DATA_IN: While in this state the IO request object is
201 * waiting for a DATA frame from the device.
203 * @SCI_REQ_STP_PIO_DATA_OUT: While in this state the IO request object is
204 * waiting to transmit the next data frame to the device.
206 * @SCI_REQ_ATAPI_WAIT_H2D: While in this state the IO request object is
207 * waiting for the TC completion notification for the H2D Register FIS
209 * @SCI_REQ_ATAPI_WAIT_PIO_SETUP: While in this state the IO request object is
210 * waiting for either a PIO Setup.
212 * @SCI_REQ_ATAPI_WAIT_D2H: The non-data IO transit to this state in this state
213 * after receiving TC completion. While in this state IO request object is
214 * waiting for D2H status frame as UF.
216 * @SCI_REQ_ATAPI_WAIT_TC_COMP: When transmitting raw frames hardware reports
217 * task context completion after every frame submission, so in the
218 * non-accelerated case we need to expect the completion for the "cdb" frame.
220 * @SCI_REQ_TASK_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
221 * the started raw task management request is waiting for the transmission of
222 * the initial frame (i.e. command, task, etc.).
224 * @SCI_REQ_TASK_WAIT_TC_RESP: This sub-state indicates that the started task
225 * management request is waiting for the reception of an unsolicited frame
226 * (i.e. response IU).
228 * @SCI_REQ_SMP_WAIT_RESP: This sub-state indicates that the started task
229 * management request is waiting for the reception of an unsolicited frame
230 * (i.e. response IU).
232 * @SCI_REQ_SMP_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
233 * the started SMP request is waiting for the transmission of the initial frame
234 * (i.e. command, task, etc.).
236 * @SCI_REQ_COMPLETED: This state indicates that the request has completed.
237 * This state is entered from the STARTED state. This state is entered from the
238 * ABORTING state.
240 * @SCI_REQ_ABORTING: This state indicates that the request is in the process
241 * of being terminated/aborted. This state is entered from the CONSTRUCTED
242 * state. This state is entered from the STARTED state.
244 * @SCI_REQ_FINAL: Simply the final state for the base request state machine.
246 #define REQUEST_STATES {\
247 C(REQ_INIT),\
248 C(REQ_CONSTRUCTED),\
249 C(REQ_STARTED),\
250 C(REQ_STP_UDMA_WAIT_TC_COMP),\
251 C(REQ_STP_UDMA_WAIT_D2H),\
252 C(REQ_STP_NON_DATA_WAIT_H2D),\
253 C(REQ_STP_NON_DATA_WAIT_D2H),\
254 C(REQ_STP_PIO_WAIT_H2D),\
255 C(REQ_STP_PIO_WAIT_FRAME),\
256 C(REQ_STP_PIO_DATA_IN),\
257 C(REQ_STP_PIO_DATA_OUT),\
258 C(REQ_ATAPI_WAIT_H2D),\
259 C(REQ_ATAPI_WAIT_PIO_SETUP),\
260 C(REQ_ATAPI_WAIT_D2H),\
261 C(REQ_ATAPI_WAIT_TC_COMP),\
262 C(REQ_TASK_WAIT_TC_COMP),\
263 C(REQ_TASK_WAIT_TC_RESP),\
264 C(REQ_SMP_WAIT_RESP),\
265 C(REQ_SMP_WAIT_TC_COMP),\
266 C(REQ_COMPLETED),\
267 C(REQ_ABORTING),\
268 C(REQ_FINAL),\
270 #undef C
271 #define C(a) SCI_##a
272 enum sci_base_request_states REQUEST_STATES;
273 #undef C
274 const char *req_state_name(enum sci_base_request_states state);
276 enum sci_status sci_request_start(struct isci_request *ireq);
277 enum sci_status sci_io_request_terminate(struct isci_request *ireq);
278 enum sci_status
279 sci_io_request_event_handler(struct isci_request *ireq,
280 u32 event_code);
281 enum sci_status
282 sci_io_request_frame_handler(struct isci_request *ireq,
283 u32 frame_index);
284 enum sci_status
285 sci_task_request_terminate(struct isci_request *ireq);
286 extern enum sci_status
287 sci_request_complete(struct isci_request *ireq);
288 extern enum sci_status
289 sci_io_request_tc_completion(struct isci_request *ireq, u32 code);
291 /* XXX open code in caller */
292 static inline dma_addr_t
293 sci_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr)
296 char *requested_addr = (char *)virt_addr;
297 char *base_addr = (char *)ireq;
299 BUG_ON(requested_addr < base_addr);
300 BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
302 return ireq->request_daddr + (requested_addr - base_addr);
306 * isci_request_change_state() - This function sets the status of the request
307 * object.
308 * @request: This parameter points to the isci_request object
309 * @status: This Parameter is the new status of the object
312 static inline enum isci_request_status
313 isci_request_change_state(struct isci_request *isci_request,
314 enum isci_request_status status)
316 enum isci_request_status old_state;
317 unsigned long flags;
319 dev_dbg(&isci_request->isci_host->pdev->dev,
320 "%s: isci_request = %p, state = 0x%x\n",
321 __func__,
322 isci_request,
323 status);
325 BUG_ON(isci_request == NULL);
327 spin_lock_irqsave(&isci_request->state_lock, flags);
328 old_state = isci_request->status;
329 isci_request->status = status;
330 spin_unlock_irqrestore(&isci_request->state_lock, flags);
332 return old_state;
336 * isci_request_change_started_to_newstate() - This function sets the status of
337 * the request object.
338 * @request: This parameter points to the isci_request object
339 * @status: This Parameter is the new status of the object
341 * state previous to any change.
343 static inline enum isci_request_status
344 isci_request_change_started_to_newstate(struct isci_request *isci_request,
345 struct completion *completion_ptr,
346 enum isci_request_status newstate)
348 enum isci_request_status old_state;
349 unsigned long flags;
351 spin_lock_irqsave(&isci_request->state_lock, flags);
353 old_state = isci_request->status;
355 if (old_state == started || old_state == aborting) {
356 BUG_ON(isci_request->io_request_completion != NULL);
358 isci_request->io_request_completion = completion_ptr;
359 isci_request->status = newstate;
362 spin_unlock_irqrestore(&isci_request->state_lock, flags);
364 dev_dbg(&isci_request->isci_host->pdev->dev,
365 "%s: isci_request = %p, old_state = 0x%x\n",
366 __func__,
367 isci_request,
368 old_state);
370 return old_state;
374 * isci_request_change_started_to_aborted() - This function sets the status of
375 * the request object.
376 * @request: This parameter points to the isci_request object
377 * @completion_ptr: This parameter is saved as the kernel completion structure
378 * signalled when the old request completes.
380 * state previous to any change.
382 static inline enum isci_request_status
383 isci_request_change_started_to_aborted(struct isci_request *isci_request,
384 struct completion *completion_ptr)
386 return isci_request_change_started_to_newstate(isci_request,
387 completion_ptr,
388 aborted);
391 #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
393 #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
395 struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
396 struct isci_tmf *isci_tmf,
397 u16 tag);
398 int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
399 struct sas_task *task, u16 tag);
400 void isci_terminate_pending_requests(struct isci_host *ihost,
401 struct isci_remote_device *idev);
402 enum sci_status
403 sci_task_request_construct(struct isci_host *ihost,
404 struct isci_remote_device *idev,
405 u16 io_tag,
406 struct isci_request *ireq);
407 enum sci_status sci_task_request_construct_ssp(struct isci_request *ireq);
408 void sci_smp_request_copy_response(struct isci_request *ireq);
410 static inline int isci_task_is_ncq_recovery(struct sas_task *task)
412 return (sas_protocol_ata(task->task_proto) &&
413 task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
414 task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
418 #endif /* !defined(_ISCI_REQUEST_H_) */