xref: /openbmc/linux/drivers/scsi/isci/request.h (revision c79dd80d73017a88a2c2ae46e7d5303cba6a32e0)
16f231ddaSDan Williams /*
26f231ddaSDan Williams  * This file is provided under a dual BSD/GPLv2 license.  When using or
36f231ddaSDan Williams  * redistributing this file, you may do so under either license.
46f231ddaSDan Williams  *
56f231ddaSDan Williams  * GPL LICENSE SUMMARY
66f231ddaSDan Williams  *
76f231ddaSDan Williams  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
86f231ddaSDan Williams  *
96f231ddaSDan Williams  * This program is free software; you can redistribute it and/or modify
106f231ddaSDan Williams  * it under the terms of version 2 of the GNU General Public License as
116f231ddaSDan Williams  * published by the Free Software Foundation.
126f231ddaSDan Williams  *
136f231ddaSDan Williams  * This program is distributed in the hope that it will be useful, but
146f231ddaSDan Williams  * WITHOUT ANY WARRANTY; without even the implied warranty of
156f231ddaSDan Williams  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
166f231ddaSDan Williams  * General Public License for more details.
176f231ddaSDan Williams  *
186f231ddaSDan Williams  * You should have received a copy of the GNU General Public License
196f231ddaSDan Williams  * along with this program; if not, write to the Free Software
206f231ddaSDan Williams  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
216f231ddaSDan Williams  * The full GNU General Public License is included in this distribution
226f231ddaSDan Williams  * in the file called LICENSE.GPL.
236f231ddaSDan Williams  *
246f231ddaSDan Williams  * BSD LICENSE
256f231ddaSDan Williams  *
266f231ddaSDan Williams  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
276f231ddaSDan Williams  * All rights reserved.
286f231ddaSDan Williams  *
296f231ddaSDan Williams  * Redistribution and use in source and binary forms, with or without
306f231ddaSDan Williams  * modification, are permitted provided that the following conditions
316f231ddaSDan Williams  * are met:
326f231ddaSDan Williams  *
336f231ddaSDan Williams  *   * Redistributions of source code must retain the above copyright
346f231ddaSDan Williams  *     notice, this list of conditions and the following disclaimer.
356f231ddaSDan Williams  *   * Redistributions in binary form must reproduce the above copyright
366f231ddaSDan Williams  *     notice, this list of conditions and the following disclaimer in
376f231ddaSDan Williams  *     the documentation and/or other materials provided with the
386f231ddaSDan Williams  *     distribution.
396f231ddaSDan Williams  *   * Neither the name of Intel Corporation nor the names of its
406f231ddaSDan Williams  *     contributors may be used to endorse or promote products derived
416f231ddaSDan Williams  *     from this software without specific prior written permission.
426f231ddaSDan Williams  *
436f231ddaSDan Williams  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
446f231ddaSDan Williams  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
456f231ddaSDan Williams  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
466f231ddaSDan Williams  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
476f231ddaSDan Williams  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
486f231ddaSDan Williams  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
496f231ddaSDan Williams  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
506f231ddaSDan Williams  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
516f231ddaSDan Williams  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
526f231ddaSDan Williams  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
536f231ddaSDan Williams  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
546f231ddaSDan Williams  */
556f231ddaSDan Williams 
560d84366fSDan Williams #ifndef _ISCI_REQUEST_H_
576f231ddaSDan Williams #define _ISCI_REQUEST_H_
586f231ddaSDan Williams 
596f231ddaSDan Williams #include "isci.h"
60ce2b3261SDan Williams #include "host.h"
61f1f52e75SDan Williams #include "scu_task_context.h"
626f231ddaSDan Williams 
636f231ddaSDan Williams /**
646f231ddaSDan Williams  * struct isci_request_status - This enum defines the possible states of an I/O
656f231ddaSDan Williams  *    request.
666f231ddaSDan Williams  *
676f231ddaSDan Williams  *
686f231ddaSDan Williams  */
696f231ddaSDan Williams enum isci_request_status {
706f231ddaSDan Williams 	unallocated = 0x00,
716f231ddaSDan Williams 	allocated   = 0x01,
726f231ddaSDan Williams 	started     = 0x02,
736f231ddaSDan Williams 	completed   = 0x03,
746f231ddaSDan Williams 	aborting    = 0x04,
756f231ddaSDan Williams 	aborted     = 0x05,
764dc043c4SJeff Skirvin 	terminating = 0x06,
774dc043c4SJeff Skirvin 	dead        = 0x07
786f231ddaSDan Williams };
796f231ddaSDan Williams 
80ba7cb223SDan Williams /**
81ba7cb223SDan Williams  * isci_stp_request - extra request infrastructure to handle pio/atapi protocol
82ba7cb223SDan Williams  * @pio_len - number of bytes requested at PIO setup
83ba7cb223SDan Williams  * @status - pio setup ending status value to tell us if we need
84ba7cb223SDan Williams  *	     to wait for another fis or if the transfer is complete.  Upon
85ba7cb223SDan Williams  *           receipt of a d2h fis this will be the status field of that fis.
86ba7cb223SDan Williams  * @sgl - track pio transfer progress as we iterate through the sgl
875dec6f4eSDan Williams  */
88ba7cb223SDan Williams struct isci_stp_request {
89ba7cb223SDan Williams 	u32 pio_len;
90ba7cb223SDan Williams 	u8 status;
915dec6f4eSDan Williams 
92ba7cb223SDan Williams 	struct isci_stp_pio_sgl {
93ba7cb223SDan Williams 		int index;
94ba7cb223SDan Williams 		u8 set;
95ba7cb223SDan Williams 		u32 offset;
96ba7cb223SDan Williams 	} sgl;
975dec6f4eSDan Williams };
985dec6f4eSDan Williams 
995076a1a9SDan Williams struct isci_request {
1005076a1a9SDan Williams 	enum isci_request_status status;
1015076a1a9SDan Williams 	#define IREQ_COMPLETE_IN_TARGET 0
1025076a1a9SDan Williams 	#define IREQ_TERMINATED 1
1035076a1a9SDan Williams 	#define IREQ_TMF 2
1045076a1a9SDan Williams 	#define IREQ_ACTIVE 3
1055076a1a9SDan Williams 	unsigned long flags;
1065076a1a9SDan Williams 	/* XXX kill ttype and ttype_ptr, allocate full sas_task */
1075076a1a9SDan Williams 	union ttype_ptr_union {
1085076a1a9SDan Williams 		struct sas_task *io_task_ptr;   /* When ttype==io_task  */
1095076a1a9SDan Williams 		struct isci_tmf *tmf_task_ptr;  /* When ttype==tmf_task */
1105076a1a9SDan Williams 	} ttype_ptr;
1115076a1a9SDan Williams 	struct isci_host *isci_host;
1125076a1a9SDan Williams 	/* For use in the requests_to_{complete|abort} lists: */
1135076a1a9SDan Williams 	struct list_head completed_node;
1145076a1a9SDan Williams 	/* For use in the reqs_in_process list: */
1155076a1a9SDan Williams 	struct list_head dev_node;
1165076a1a9SDan Williams 	spinlock_t state_lock;
1175076a1a9SDan Williams 	dma_addr_t request_daddr;
1185076a1a9SDan Williams 	dma_addr_t zero_scatter_daddr;
1195076a1a9SDan Williams 	unsigned int num_sg_entries;
1205076a1a9SDan Williams 	/* Note: "io_request_completion" is completed in two different ways
1215076a1a9SDan Williams 	 * depending on whether this is a TMF or regular request.
1225076a1a9SDan Williams 	 * - TMF requests are completed in the thread that started them;
1235076a1a9SDan Williams 	 * - regular requests are completed in the request completion callback
1245076a1a9SDan Williams 	 *   function.
1255076a1a9SDan Williams 	 * This difference in operation allows the aborter of a TMF request
1265076a1a9SDan Williams 	 * to be sure that once the TMF request completes, the I/O that the
1275076a1a9SDan Williams 	 * TMF was aborting is guaranteed to have completed.
1285076a1a9SDan Williams 	 *
1295076a1a9SDan Williams 	 * XXX kill io_request_completion
130f1f52e75SDan Williams 	 */
1315076a1a9SDan Williams 	struct completion *io_request_completion;
132e301370aSEdmund Nadolski 	struct sci_base_state_machine sm;
133d9dcb4baSDan Williams 	struct isci_host *owning_controller;
13478a6f06eSDan Williams 	struct isci_remote_device *target_device;
135f1f52e75SDan Williams 	u16 io_tag;
136*c79dd80dSDan Williams 	enum sas_protocol protocol;
1375076a1a9SDan Williams 	u32 scu_status; /* hardware result */
1385076a1a9SDan Williams 	u32 sci_status; /* upper layer disposition */
139f1f52e75SDan Williams 	u32 post_context;
140312e0c24SDan Williams 	struct scu_task_context *tc;
141f1f52e75SDan Williams 	/* could be larger with sg chaining */
1427c78da31SDan Williams 	#define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
143f1f52e75SDan Williams 	struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
1445076a1a9SDan Williams 	/* This field is a pointer to the stored rx frame data.  It is used in
145e301370aSEdmund Nadolski 	 * STP internal requests and SMP response frames.  If this field is
146e301370aSEdmund Nadolski 	 * non-NULL the saved frame must be released on IO request completion.
147f1f52e75SDan Williams 	 */
148f1f52e75SDan Williams 	u32 saved_rx_frame_index;
149f1f52e75SDan Williams 
150f1f52e75SDan Williams 	union {
151f1f52e75SDan Williams 		struct {
152f1f52e75SDan Williams 			union {
153f1f52e75SDan Williams 				struct ssp_cmd_iu cmd;
154f1f52e75SDan Williams 				struct ssp_task_iu tmf;
155f1f52e75SDan Williams 			};
156f1f52e75SDan Williams 			union {
157f1f52e75SDan Williams 				struct ssp_response_iu rsp;
158f1f52e75SDan Williams 				u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
159f1f52e75SDan Williams 			};
160f1f52e75SDan Williams 		} ssp;
161f1f52e75SDan Williams 		struct {
162ba7cb223SDan Williams 			struct isci_stp_request req;
163f1f52e75SDan Williams 			struct host_to_dev_fis cmd;
164f1f52e75SDan Williams 			struct dev_to_host_fis rsp;
165f1f52e75SDan Williams 		} stp;
166f1f52e75SDan Williams 	};
167f1f52e75SDan Williams };
168f1f52e75SDan Williams 
1695076a1a9SDan Williams static inline struct isci_request *to_ireq(struct isci_stp_request *stp_req)
170f1f52e75SDan Williams {
1715076a1a9SDan Williams 	struct isci_request *ireq;
172f1f52e75SDan Williams 
1735076a1a9SDan Williams 	ireq = container_of(stp_req, typeof(*ireq), stp.req);
17467ea838dSDan Williams 	return ireq;
17567ea838dSDan Williams }
17667ea838dSDan Williams 
1776f231ddaSDan Williams /**
178d7a0ccddSDan Williams  * enum sci_base_request_states - request state machine states
179f1f52e75SDan Williams  *
180d7a0ccddSDan Williams  * @SCI_REQ_INIT: Simply the initial state for the base request state machine.
181f1f52e75SDan Williams  *
182d7a0ccddSDan Williams  * @SCI_REQ_CONSTRUCTED: This state indicates that the request has been
183d7a0ccddSDan Williams  * constructed.  This state is entered from the INITIAL state.
184d7a0ccddSDan Williams  *
185d7a0ccddSDan Williams  * @SCI_REQ_STARTED: This state indicates that the request has been started.
186f1f52e75SDan Williams  * This state is entered from the CONSTRUCTED state.
187d7a0ccddSDan Williams  *
188d7a0ccddSDan Williams  * @SCI_REQ_STP_UDMA_WAIT_TC_COMP:
189d7a0ccddSDan Williams  * @SCI_REQ_STP_UDMA_WAIT_D2H:
190d7a0ccddSDan Williams  * @SCI_REQ_STP_NON_DATA_WAIT_H2D:
191d7a0ccddSDan Williams  * @SCI_REQ_STP_NON_DATA_WAIT_D2H:
192d7a0ccddSDan Williams  *
193d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_WAIT_H2D: While in this state the IO request object is
194d7a0ccddSDan Williams  * waiting for the TC completion notification for the H2D Register FIS
195d7a0ccddSDan Williams  *
196d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_WAIT_FRAME: While in this state the IO request object is
197d7a0ccddSDan Williams  * waiting for either a PIO Setup FIS or a D2H register FIS.  The type of frame
198d7a0ccddSDan Williams  * received is based on the result of the prior frame and line conditions.
199d7a0ccddSDan Williams  *
200d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_DATA_IN: While in this state the IO request object is
201d7a0ccddSDan Williams  * waiting for a DATA frame from the device.
202d7a0ccddSDan Williams  *
203d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_DATA_OUT: While in this state the IO request object is
204d7a0ccddSDan Williams  * waiting to transmit the next data frame to the device.
205d7a0ccddSDan Williams  *
206d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_H2D: While in this state the IO request object is
207d7a0ccddSDan Williams  * waiting for the TC completion notification for the H2D Register FIS
208d7a0ccddSDan Williams  *
209d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_PIO_SETUP: While in this state the IO request object is
210d7a0ccddSDan Williams  * waiting for either a PIO Setup.
211d7a0ccddSDan Williams  *
212d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_D2H: The non-data IO transit to this state in this state
213d7a0ccddSDan Williams  * after receiving TC completion. While in this state IO request object is
214d7a0ccddSDan Williams  * waiting for D2H status frame as UF.
215d7a0ccddSDan Williams  *
216d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_TC_COMP: When transmitting raw frames hardware reports
217d7a0ccddSDan Williams  * task context completion after every frame submission, so in the
218d7a0ccddSDan Williams  * non-accelerated case we need to expect the completion for the "cdb" frame.
219d7a0ccddSDan Williams  *
220d7a0ccddSDan Williams  * @SCI_REQ_TASK_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
221d7a0ccddSDan Williams  * the started raw task management request is waiting for the transmission of
222d7a0ccddSDan Williams  * the initial frame (i.e. command, task, etc.).
223d7a0ccddSDan Williams  *
224d7a0ccddSDan Williams  * @SCI_REQ_TASK_WAIT_TC_RESP: This sub-state indicates that the started task
225d7a0ccddSDan Williams  * management request is waiting for the reception of an unsolicited frame
226d7a0ccddSDan Williams  * (i.e.  response IU).
227d7a0ccddSDan Williams  *
228d7a0ccddSDan Williams  * @SCI_REQ_SMP_WAIT_RESP: This sub-state indicates that the started task
229d7a0ccddSDan Williams  * management request is waiting for the reception of an unsolicited frame
230d7a0ccddSDan Williams  * (i.e.  response IU).
231d7a0ccddSDan Williams  *
232d7a0ccddSDan Williams  * @SCI_REQ_SMP_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
233d7a0ccddSDan Williams  * the started SMP request is waiting for the transmission of the initial frame
234d7a0ccddSDan Williams  * (i.e.  command, task, etc.).
235d7a0ccddSDan Williams  *
236d7a0ccddSDan Williams  * @SCI_REQ_COMPLETED: This state indicates that the request has completed.
237d7a0ccddSDan Williams  * This state is entered from the STARTED state. This state is entered from the
238d7a0ccddSDan Williams  * ABORTING state.
239d7a0ccddSDan Williams  *
240d7a0ccddSDan Williams  * @SCI_REQ_ABORTING: This state indicates that the request is in the process
241d7a0ccddSDan Williams  * of being terminated/aborted.  This state is entered from the CONSTRUCTED
242d7a0ccddSDan Williams  * state.  This state is entered from the STARTED state.
243d7a0ccddSDan Williams  *
244d7a0ccddSDan Williams  * @SCI_REQ_FINAL: Simply the final state for the base request state machine.
245f1f52e75SDan Williams  */
246d7a0ccddSDan Williams #define REQUEST_STATES {\
247d7a0ccddSDan Williams 	C(REQ_INIT),\
248d7a0ccddSDan Williams 	C(REQ_CONSTRUCTED),\
249d7a0ccddSDan Williams 	C(REQ_STARTED),\
250d7a0ccddSDan Williams 	C(REQ_STP_UDMA_WAIT_TC_COMP),\
251d7a0ccddSDan Williams 	C(REQ_STP_UDMA_WAIT_D2H),\
252d7a0ccddSDan Williams 	C(REQ_STP_NON_DATA_WAIT_H2D),\
253d7a0ccddSDan Williams 	C(REQ_STP_NON_DATA_WAIT_D2H),\
254d7a0ccddSDan Williams 	C(REQ_STP_PIO_WAIT_H2D),\
255d7a0ccddSDan Williams 	C(REQ_STP_PIO_WAIT_FRAME),\
256d7a0ccddSDan Williams 	C(REQ_STP_PIO_DATA_IN),\
257d7a0ccddSDan Williams 	C(REQ_STP_PIO_DATA_OUT),\
258d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_H2D),\
259d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_PIO_SETUP),\
260d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_D2H),\
261d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_TC_COMP),\
262d7a0ccddSDan Williams 	C(REQ_TASK_WAIT_TC_COMP),\
263d7a0ccddSDan Williams 	C(REQ_TASK_WAIT_TC_RESP),\
264d7a0ccddSDan Williams 	C(REQ_SMP_WAIT_RESP),\
265d7a0ccddSDan Williams 	C(REQ_SMP_WAIT_TC_COMP),\
266d7a0ccddSDan Williams 	C(REQ_COMPLETED),\
267d7a0ccddSDan Williams 	C(REQ_ABORTING),\
268d7a0ccddSDan Williams 	C(REQ_FINAL),\
269d7a0ccddSDan Williams 	}
270d7a0ccddSDan Williams #undef C
271d7a0ccddSDan Williams #define C(a) SCI_##a
272d7a0ccddSDan Williams enum sci_base_request_states REQUEST_STATES;
273d7a0ccddSDan Williams #undef C
274d7a0ccddSDan Williams const char *req_state_name(enum sci_base_request_states state);
275f1f52e75SDan Williams 
27689a7301fSDan Williams enum sci_status sci_request_start(struct isci_request *ireq);
27789a7301fSDan Williams enum sci_status sci_io_request_terminate(struct isci_request *ireq);
278e301370aSEdmund Nadolski enum sci_status
27989a7301fSDan Williams sci_io_request_event_handler(struct isci_request *ireq,
280f1f52e75SDan Williams 				  u32 event_code);
281e301370aSEdmund Nadolski enum sci_status
28289a7301fSDan Williams sci_io_request_frame_handler(struct isci_request *ireq,
283f1f52e75SDan Williams 				  u32 frame_index);
284e301370aSEdmund Nadolski enum sci_status
28589a7301fSDan Williams sci_task_request_terminate(struct isci_request *ireq);
286e301370aSEdmund Nadolski extern enum sci_status
28789a7301fSDan Williams sci_request_complete(struct isci_request *ireq);
288e301370aSEdmund Nadolski extern enum sci_status
28989a7301fSDan Williams sci_io_request_tc_completion(struct isci_request *ireq, u32 code);
290f1f52e75SDan Williams 
291f1f52e75SDan Williams /* XXX open code in caller */
292e301370aSEdmund Nadolski static inline dma_addr_t
29389a7301fSDan Williams sci_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr)
294f1f52e75SDan Williams {
295f1f52e75SDan Williams 
296f1f52e75SDan Williams 	char *requested_addr = (char *)virt_addr;
297f1f52e75SDan Williams 	char *base_addr = (char *)ireq;
298f1f52e75SDan Williams 
299f1f52e75SDan Williams 	BUG_ON(requested_addr < base_addr);
300f1f52e75SDan Williams 	BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
301f1f52e75SDan Williams 
302f1f52e75SDan Williams 	return ireq->request_daddr + (requested_addr - base_addr);
303f1f52e75SDan Williams }
304f1f52e75SDan Williams 
305f1f52e75SDan Williams /**
3066f231ddaSDan Williams  * isci_request_change_state() - This function sets the status of the request
3076f231ddaSDan Williams  *    object.
3086f231ddaSDan Williams  * @request: This parameter points to the isci_request object
3096f231ddaSDan Williams  * @status: This Parameter is the new status of the object
3106f231ddaSDan Williams  *
3116f231ddaSDan Williams  */
312e301370aSEdmund Nadolski static inline enum isci_request_status
313e301370aSEdmund Nadolski isci_request_change_state(struct isci_request *isci_request,
3146f231ddaSDan Williams 			  enum isci_request_status status)
3156f231ddaSDan Williams {
3166f231ddaSDan Williams 	enum isci_request_status old_state;
3176f231ddaSDan Williams 	unsigned long flags;
3186f231ddaSDan Williams 
3196f231ddaSDan Williams 	dev_dbg(&isci_request->isci_host->pdev->dev,
3206f231ddaSDan Williams 		"%s: isci_request = %p, state = 0x%x\n",
3216f231ddaSDan Williams 		__func__,
3226f231ddaSDan Williams 		isci_request,
3236f231ddaSDan Williams 		status);
3246f231ddaSDan Williams 
3256f231ddaSDan Williams 	BUG_ON(isci_request == NULL);
3266f231ddaSDan Williams 
3276f231ddaSDan Williams 	spin_lock_irqsave(&isci_request->state_lock, flags);
3286f231ddaSDan Williams 	old_state = isci_request->status;
3296f231ddaSDan Williams 	isci_request->status = status;
3306f231ddaSDan Williams 	spin_unlock_irqrestore(&isci_request->state_lock, flags);
3316f231ddaSDan Williams 
3326f231ddaSDan Williams 	return old_state;
3336f231ddaSDan Williams }
3346f231ddaSDan Williams 
3356f231ddaSDan Williams /**
3366f231ddaSDan Williams  * isci_request_change_started_to_newstate() - This function sets the status of
3376f231ddaSDan Williams  *    the request object.
3386f231ddaSDan Williams  * @request: This parameter points to the isci_request object
3396f231ddaSDan Williams  * @status: This Parameter is the new status of the object
3406f231ddaSDan Williams  *
3416f231ddaSDan Williams  * state previous to any change.
3426f231ddaSDan Williams  */
343e301370aSEdmund Nadolski static inline enum isci_request_status
344e301370aSEdmund Nadolski isci_request_change_started_to_newstate(struct isci_request *isci_request,
3456f231ddaSDan Williams 					struct completion *completion_ptr,
3466f231ddaSDan Williams 					enum isci_request_status newstate)
3476f231ddaSDan Williams {
3486f231ddaSDan Williams 	enum isci_request_status old_state;
3496f231ddaSDan Williams 	unsigned long flags;
3506f231ddaSDan Williams 
3516f231ddaSDan Williams 	spin_lock_irqsave(&isci_request->state_lock, flags);
3526f231ddaSDan Williams 
3536f231ddaSDan Williams 	old_state = isci_request->status;
3546f231ddaSDan Williams 
355f219f010SJeff Skirvin 	if (old_state == started || old_state == aborting) {
3566f231ddaSDan Williams 		BUG_ON(isci_request->io_request_completion != NULL);
3576f231ddaSDan Williams 
3586f231ddaSDan Williams 		isci_request->io_request_completion = completion_ptr;
3596f231ddaSDan Williams 		isci_request->status = newstate;
3606f231ddaSDan Williams 	}
361e301370aSEdmund Nadolski 
3626f231ddaSDan Williams 	spin_unlock_irqrestore(&isci_request->state_lock, flags);
3636f231ddaSDan Williams 
3646f231ddaSDan Williams 	dev_dbg(&isci_request->isci_host->pdev->dev,
3656f231ddaSDan Williams 		"%s: isci_request = %p, old_state = 0x%x\n",
3666f231ddaSDan Williams 		__func__,
3676f231ddaSDan Williams 		isci_request,
3686f231ddaSDan Williams 		old_state);
3696f231ddaSDan Williams 
3706f231ddaSDan Williams 	return old_state;
3716f231ddaSDan Williams }
3726f231ddaSDan Williams 
3736f231ddaSDan Williams /**
3746f231ddaSDan Williams  * isci_request_change_started_to_aborted() - This function sets the status of
3756f231ddaSDan Williams  *    the request object.
3766f231ddaSDan Williams  * @request: This parameter points to the isci_request object
3776f231ddaSDan Williams  * @completion_ptr: This parameter is saved as the kernel completion structure
3786f231ddaSDan Williams  *    signalled when the old request completes.
3796f231ddaSDan Williams  *
3806f231ddaSDan Williams  * state previous to any change.
3816f231ddaSDan Williams  */
382e301370aSEdmund Nadolski static inline enum isci_request_status
383e301370aSEdmund Nadolski isci_request_change_started_to_aborted(struct isci_request *isci_request,
3846f231ddaSDan Williams 				       struct completion *completion_ptr)
3856f231ddaSDan Williams {
386e301370aSEdmund Nadolski 	return isci_request_change_started_to_newstate(isci_request,
387e301370aSEdmund Nadolski 						       completion_ptr,
388e301370aSEdmund Nadolski 						       aborted);
3896f231ddaSDan Williams }
3906f231ddaSDan Williams 
391e301370aSEdmund Nadolski #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
3926f231ddaSDan Williams 
393e301370aSEdmund Nadolski #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
3946f231ddaSDan Williams 
395db056250SDan Williams struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
3966f231ddaSDan Williams 					       struct isci_tmf *isci_tmf,
397db056250SDan Williams 					       u16 tag);
398209fae14SDan Williams int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
399db056250SDan Williams 			 struct sas_task *task, u16 tag);
400ddcc7e34SDan Williams void isci_terminate_pending_requests(struct isci_host *ihost,
401980d3aebSDan Williams 				     struct isci_remote_device *idev);
402e301370aSEdmund Nadolski enum sci_status
40389a7301fSDan Williams sci_task_request_construct(struct isci_host *ihost,
40478a6f06eSDan Williams 			    struct isci_remote_device *idev,
405f1f52e75SDan Williams 			    u16 io_tag,
4065076a1a9SDan Williams 			    struct isci_request *ireq);
40743a5ab15SDan Williams enum sci_status sci_task_request_construct_ssp(struct isci_request *ireq);
40889a7301fSDan Williams void sci_smp_request_copy_response(struct isci_request *ireq);
4099274f45eSJeff Skirvin 
4109274f45eSJeff Skirvin static inline int isci_task_is_ncq_recovery(struct sas_task *task)
4119274f45eSJeff Skirvin {
4129274f45eSJeff Skirvin 	return (sas_protocol_ata(task->task_proto) &&
4139274f45eSJeff Skirvin 		task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
4149274f45eSJeff Skirvin 		task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
4159274f45eSJeff Skirvin 
4169274f45eSJeff Skirvin }
4179274f45eSJeff Skirvin 
4186f231ddaSDan Williams #endif /* !defined(_ISCI_REQUEST_H_) */
419