xref: /openbmc/linux/drivers/scsi/isci/request.h (revision d7a0ccdd9bd78b5b74d2963ec7ab67c9d896902a)
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 
80f1f52e75SDan Williams enum sci_request_protocol {
81f1f52e75SDan Williams 	SCIC_NO_PROTOCOL,
82f1f52e75SDan Williams 	SCIC_SMP_PROTOCOL,
83f1f52e75SDan Williams 	SCIC_SSP_PROTOCOL,
84f1f52e75SDan Williams 	SCIC_STP_PROTOCOL
85c72086e3SDan Williams }; /* XXX remove me, use sas_task.{dev|task_proto} instead */;
86f1f52e75SDan Williams 
87ba7cb223SDan Williams /**
88ba7cb223SDan Williams  * isci_stp_request - extra request infrastructure to handle pio/atapi protocol
89ba7cb223SDan Williams  * @pio_len - number of bytes requested at PIO setup
90ba7cb223SDan Williams  * @status - pio setup ending status value to tell us if we need
91ba7cb223SDan Williams  *	     to wait for another fis or if the transfer is complete.  Upon
92ba7cb223SDan Williams  *           receipt of a d2h fis this will be the status field of that fis.
93ba7cb223SDan Williams  * @sgl - track pio transfer progress as we iterate through the sgl
945dec6f4eSDan Williams  */
95ba7cb223SDan Williams struct isci_stp_request {
96ba7cb223SDan Williams 	u32 pio_len;
97ba7cb223SDan Williams 	u8 status;
985dec6f4eSDan Williams 
99ba7cb223SDan Williams 	struct isci_stp_pio_sgl {
100ba7cb223SDan Williams 		int index;
101ba7cb223SDan Williams 		u8 set;
102ba7cb223SDan Williams 		u32 offset;
103ba7cb223SDan Williams 	} sgl;
1045dec6f4eSDan Williams };
1055dec6f4eSDan Williams 
1065076a1a9SDan Williams struct isci_request {
1075076a1a9SDan Williams 	enum isci_request_status status;
1085076a1a9SDan Williams 	#define IREQ_COMPLETE_IN_TARGET 0
1095076a1a9SDan Williams 	#define IREQ_TERMINATED 1
1105076a1a9SDan Williams 	#define IREQ_TMF 2
1115076a1a9SDan Williams 	#define IREQ_ACTIVE 3
1125076a1a9SDan Williams 	unsigned long flags;
1135076a1a9SDan Williams 	/* XXX kill ttype and ttype_ptr, allocate full sas_task */
1145076a1a9SDan Williams 	union ttype_ptr_union {
1155076a1a9SDan Williams 		struct sas_task *io_task_ptr;   /* When ttype==io_task  */
1165076a1a9SDan Williams 		struct isci_tmf *tmf_task_ptr;  /* When ttype==tmf_task */
1175076a1a9SDan Williams 	} ttype_ptr;
1185076a1a9SDan Williams 	struct isci_host *isci_host;
1195076a1a9SDan Williams 	/* For use in the requests_to_{complete|abort} lists: */
1205076a1a9SDan Williams 	struct list_head completed_node;
1215076a1a9SDan Williams 	/* For use in the reqs_in_process list: */
1225076a1a9SDan Williams 	struct list_head dev_node;
1235076a1a9SDan Williams 	spinlock_t state_lock;
1245076a1a9SDan Williams 	dma_addr_t request_daddr;
1255076a1a9SDan Williams 	dma_addr_t zero_scatter_daddr;
1265076a1a9SDan Williams 	unsigned int num_sg_entries;
1275076a1a9SDan Williams 	/* Note: "io_request_completion" is completed in two different ways
1285076a1a9SDan Williams 	 * depending on whether this is a TMF or regular request.
1295076a1a9SDan Williams 	 * - TMF requests are completed in the thread that started them;
1305076a1a9SDan Williams 	 * - regular requests are completed in the request completion callback
1315076a1a9SDan Williams 	 *   function.
1325076a1a9SDan Williams 	 * This difference in operation allows the aborter of a TMF request
1335076a1a9SDan Williams 	 * to be sure that once the TMF request completes, the I/O that the
1345076a1a9SDan Williams 	 * TMF was aborting is guaranteed to have completed.
1355076a1a9SDan Williams 	 *
1365076a1a9SDan Williams 	 * XXX kill io_request_completion
137f1f52e75SDan Williams 	 */
1385076a1a9SDan Williams 	struct completion *io_request_completion;
139e301370aSEdmund Nadolski 	struct sci_base_state_machine sm;
140d9dcb4baSDan Williams 	struct isci_host *owning_controller;
14178a6f06eSDan Williams 	struct isci_remote_device *target_device;
142f1f52e75SDan Williams 	u16 io_tag;
143f1f52e75SDan Williams 	enum sci_request_protocol protocol;
1445076a1a9SDan Williams 	u32 scu_status; /* hardware result */
1455076a1a9SDan Williams 	u32 sci_status; /* upper layer disposition */
146f1f52e75SDan Williams 	u32 post_context;
147312e0c24SDan Williams 	struct scu_task_context *tc;
148f1f52e75SDan Williams 	/* could be larger with sg chaining */
1497c78da31SDan Williams 	#define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
150f1f52e75SDan Williams 	struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
1515076a1a9SDan Williams 	/* This field is a pointer to the stored rx frame data.  It is used in
152e301370aSEdmund Nadolski 	 * STP internal requests and SMP response frames.  If this field is
153e301370aSEdmund Nadolski 	 * non-NULL the saved frame must be released on IO request completion.
154f1f52e75SDan Williams 	 */
155f1f52e75SDan Williams 	u32 saved_rx_frame_index;
156f1f52e75SDan Williams 
157f1f52e75SDan Williams 	union {
158f1f52e75SDan Williams 		struct {
159f1f52e75SDan Williams 			union {
160f1f52e75SDan Williams 				struct ssp_cmd_iu cmd;
161f1f52e75SDan Williams 				struct ssp_task_iu tmf;
162f1f52e75SDan Williams 			};
163f1f52e75SDan Williams 			union {
164f1f52e75SDan Williams 				struct ssp_response_iu rsp;
165f1f52e75SDan Williams 				u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
166f1f52e75SDan Williams 			};
167f1f52e75SDan Williams 		} ssp;
168f1f52e75SDan Williams 		struct {
169ba7cb223SDan Williams 			struct isci_stp_request req;
170f1f52e75SDan Williams 			struct host_to_dev_fis cmd;
171f1f52e75SDan Williams 			struct dev_to_host_fis rsp;
172f1f52e75SDan Williams 		} stp;
173f1f52e75SDan Williams 	};
174f1f52e75SDan Williams };
175f1f52e75SDan Williams 
1765076a1a9SDan Williams static inline struct isci_request *to_ireq(struct isci_stp_request *stp_req)
177f1f52e75SDan Williams {
1785076a1a9SDan Williams 	struct isci_request *ireq;
179f1f52e75SDan Williams 
1805076a1a9SDan Williams 	ireq = container_of(stp_req, typeof(*ireq), stp.req);
18167ea838dSDan Williams 	return ireq;
18267ea838dSDan Williams }
18367ea838dSDan Williams 
1846f231ddaSDan Williams /**
185*d7a0ccddSDan Williams  * enum sci_base_request_states - request state machine states
186f1f52e75SDan Williams  *
187*d7a0ccddSDan Williams  * @SCI_REQ_INIT: Simply the initial state for the base request state machine.
188f1f52e75SDan Williams  *
189*d7a0ccddSDan Williams  * @SCI_REQ_CONSTRUCTED: This state indicates that the request has been
190*d7a0ccddSDan Williams  * constructed.  This state is entered from the INITIAL state.
191*d7a0ccddSDan Williams  *
192*d7a0ccddSDan Williams  * @SCI_REQ_STARTED: This state indicates that the request has been started.
193f1f52e75SDan Williams  * This state is entered from the CONSTRUCTED state.
194*d7a0ccddSDan Williams  *
195*d7a0ccddSDan Williams  * @SCI_REQ_STP_UDMA_WAIT_TC_COMP:
196*d7a0ccddSDan Williams  * @SCI_REQ_STP_UDMA_WAIT_D2H:
197*d7a0ccddSDan Williams  * @SCI_REQ_STP_NON_DATA_WAIT_H2D:
198*d7a0ccddSDan Williams  * @SCI_REQ_STP_NON_DATA_WAIT_D2H:
199*d7a0ccddSDan Williams  *
200*d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_WAIT_H2D: While in this state the IO request object is
201*d7a0ccddSDan Williams  * waiting for the TC completion notification for the H2D Register FIS
202*d7a0ccddSDan Williams  *
203*d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_WAIT_FRAME: While in this state the IO request object is
204*d7a0ccddSDan Williams  * waiting for either a PIO Setup FIS or a D2H register FIS.  The type of frame
205*d7a0ccddSDan Williams  * received is based on the result of the prior frame and line conditions.
206*d7a0ccddSDan Williams  *
207*d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_DATA_IN: While in this state the IO request object is
208*d7a0ccddSDan Williams  * waiting for a DATA frame from the device.
209*d7a0ccddSDan Williams  *
210*d7a0ccddSDan Williams  * @SCI_REQ_STP_PIO_DATA_OUT: While in this state the IO request object is
211*d7a0ccddSDan Williams  * waiting to transmit the next data frame to the device.
212*d7a0ccddSDan Williams  *
213*d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_H2D: While in this state the IO request object is
214*d7a0ccddSDan Williams  * waiting for the TC completion notification for the H2D Register FIS
215*d7a0ccddSDan Williams  *
216*d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_PIO_SETUP: While in this state the IO request object is
217*d7a0ccddSDan Williams  * waiting for either a PIO Setup.
218*d7a0ccddSDan Williams  *
219*d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_D2H: The non-data IO transit to this state in this state
220*d7a0ccddSDan Williams  * after receiving TC completion. While in this state IO request object is
221*d7a0ccddSDan Williams  * waiting for D2H status frame as UF.
222*d7a0ccddSDan Williams  *
223*d7a0ccddSDan Williams  * @SCI_REQ_ATAPI_WAIT_TC_COMP: When transmitting raw frames hardware reports
224*d7a0ccddSDan Williams  * task context completion after every frame submission, so in the
225*d7a0ccddSDan Williams  * non-accelerated case we need to expect the completion for the "cdb" frame.
226*d7a0ccddSDan Williams  *
227*d7a0ccddSDan Williams  * @SCI_REQ_TASK_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
228*d7a0ccddSDan Williams  * the started raw task management request is waiting for the transmission of
229*d7a0ccddSDan Williams  * the initial frame (i.e. command, task, etc.).
230*d7a0ccddSDan Williams  *
231*d7a0ccddSDan Williams  * @SCI_REQ_TASK_WAIT_TC_RESP: This sub-state indicates that the started task
232*d7a0ccddSDan Williams  * management request is waiting for the reception of an unsolicited frame
233*d7a0ccddSDan Williams  * (i.e.  response IU).
234*d7a0ccddSDan Williams  *
235*d7a0ccddSDan Williams  * @SCI_REQ_SMP_WAIT_RESP: This sub-state indicates that the started task
236*d7a0ccddSDan Williams  * management request is waiting for the reception of an unsolicited frame
237*d7a0ccddSDan Williams  * (i.e.  response IU).
238*d7a0ccddSDan Williams  *
239*d7a0ccddSDan Williams  * @SCI_REQ_SMP_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
240*d7a0ccddSDan Williams  * the started SMP request is waiting for the transmission of the initial frame
241*d7a0ccddSDan Williams  * (i.e.  command, task, etc.).
242*d7a0ccddSDan Williams  *
243*d7a0ccddSDan Williams  * @SCI_REQ_COMPLETED: This state indicates that the request has completed.
244*d7a0ccddSDan Williams  * This state is entered from the STARTED state. This state is entered from the
245*d7a0ccddSDan Williams  * ABORTING state.
246*d7a0ccddSDan Williams  *
247*d7a0ccddSDan Williams  * @SCI_REQ_ABORTING: This state indicates that the request is in the process
248*d7a0ccddSDan Williams  * of being terminated/aborted.  This state is entered from the CONSTRUCTED
249*d7a0ccddSDan Williams  * state.  This state is entered from the STARTED state.
250*d7a0ccddSDan Williams  *
251*d7a0ccddSDan Williams  * @SCI_REQ_FINAL: Simply the final state for the base request state machine.
252f1f52e75SDan Williams  */
253*d7a0ccddSDan Williams #define REQUEST_STATES {\
254*d7a0ccddSDan Williams 	C(REQ_INIT),\
255*d7a0ccddSDan Williams 	C(REQ_CONSTRUCTED),\
256*d7a0ccddSDan Williams 	C(REQ_STARTED),\
257*d7a0ccddSDan Williams 	C(REQ_STP_UDMA_WAIT_TC_COMP),\
258*d7a0ccddSDan Williams 	C(REQ_STP_UDMA_WAIT_D2H),\
259*d7a0ccddSDan Williams 	C(REQ_STP_NON_DATA_WAIT_H2D),\
260*d7a0ccddSDan Williams 	C(REQ_STP_NON_DATA_WAIT_D2H),\
261*d7a0ccddSDan Williams 	C(REQ_STP_PIO_WAIT_H2D),\
262*d7a0ccddSDan Williams 	C(REQ_STP_PIO_WAIT_FRAME),\
263*d7a0ccddSDan Williams 	C(REQ_STP_PIO_DATA_IN),\
264*d7a0ccddSDan Williams 	C(REQ_STP_PIO_DATA_OUT),\
265*d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_H2D),\
266*d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_PIO_SETUP),\
267*d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_D2H),\
268*d7a0ccddSDan Williams 	C(REQ_ATAPI_WAIT_TC_COMP),\
269*d7a0ccddSDan Williams 	C(REQ_TASK_WAIT_TC_COMP),\
270*d7a0ccddSDan Williams 	C(REQ_TASK_WAIT_TC_RESP),\
271*d7a0ccddSDan Williams 	C(REQ_SMP_WAIT_RESP),\
272*d7a0ccddSDan Williams 	C(REQ_SMP_WAIT_TC_COMP),\
273*d7a0ccddSDan Williams 	C(REQ_COMPLETED),\
274*d7a0ccddSDan Williams 	C(REQ_ABORTING),\
275*d7a0ccddSDan Williams 	C(REQ_FINAL),\
276*d7a0ccddSDan Williams 	}
277*d7a0ccddSDan Williams #undef C
278*d7a0ccddSDan Williams #define C(a) SCI_##a
279*d7a0ccddSDan Williams enum sci_base_request_states REQUEST_STATES;
280*d7a0ccddSDan Williams #undef C
281*d7a0ccddSDan Williams const char *req_state_name(enum sci_base_request_states state);
282f1f52e75SDan Williams 
28389a7301fSDan Williams enum sci_status sci_request_start(struct isci_request *ireq);
28489a7301fSDan Williams enum sci_status sci_io_request_terminate(struct isci_request *ireq);
285e301370aSEdmund Nadolski enum sci_status
28689a7301fSDan Williams sci_io_request_event_handler(struct isci_request *ireq,
287f1f52e75SDan Williams 				  u32 event_code);
288e301370aSEdmund Nadolski enum sci_status
28989a7301fSDan Williams sci_io_request_frame_handler(struct isci_request *ireq,
290f1f52e75SDan Williams 				  u32 frame_index);
291e301370aSEdmund Nadolski enum sci_status
29289a7301fSDan Williams sci_task_request_terminate(struct isci_request *ireq);
293e301370aSEdmund Nadolski extern enum sci_status
29489a7301fSDan Williams sci_request_complete(struct isci_request *ireq);
295e301370aSEdmund Nadolski extern enum sci_status
29689a7301fSDan Williams sci_io_request_tc_completion(struct isci_request *ireq, u32 code);
297f1f52e75SDan Williams 
298f1f52e75SDan Williams /* XXX open code in caller */
299e301370aSEdmund Nadolski static inline dma_addr_t
30089a7301fSDan Williams sci_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr)
301f1f52e75SDan Williams {
302f1f52e75SDan Williams 
303f1f52e75SDan Williams 	char *requested_addr = (char *)virt_addr;
304f1f52e75SDan Williams 	char *base_addr = (char *)ireq;
305f1f52e75SDan Williams 
306f1f52e75SDan Williams 	BUG_ON(requested_addr < base_addr);
307f1f52e75SDan Williams 	BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
308f1f52e75SDan Williams 
309f1f52e75SDan Williams 	return ireq->request_daddr + (requested_addr - base_addr);
310f1f52e75SDan Williams }
311f1f52e75SDan Williams 
312f1f52e75SDan Williams /**
3136f231ddaSDan Williams  * isci_request_change_state() - This function sets the status of the request
3146f231ddaSDan Williams  *    object.
3156f231ddaSDan Williams  * @request: This parameter points to the isci_request object
3166f231ddaSDan Williams  * @status: This Parameter is the new status of the object
3176f231ddaSDan Williams  *
3186f231ddaSDan Williams  */
319e301370aSEdmund Nadolski static inline enum isci_request_status
320e301370aSEdmund Nadolski isci_request_change_state(struct isci_request *isci_request,
3216f231ddaSDan Williams 			  enum isci_request_status status)
3226f231ddaSDan Williams {
3236f231ddaSDan Williams 	enum isci_request_status old_state;
3246f231ddaSDan Williams 	unsigned long flags;
3256f231ddaSDan Williams 
3266f231ddaSDan Williams 	dev_dbg(&isci_request->isci_host->pdev->dev,
3276f231ddaSDan Williams 		"%s: isci_request = %p, state = 0x%x\n",
3286f231ddaSDan Williams 		__func__,
3296f231ddaSDan Williams 		isci_request,
3306f231ddaSDan Williams 		status);
3316f231ddaSDan Williams 
3326f231ddaSDan Williams 	BUG_ON(isci_request == NULL);
3336f231ddaSDan Williams 
3346f231ddaSDan Williams 	spin_lock_irqsave(&isci_request->state_lock, flags);
3356f231ddaSDan Williams 	old_state = isci_request->status;
3366f231ddaSDan Williams 	isci_request->status = status;
3376f231ddaSDan Williams 	spin_unlock_irqrestore(&isci_request->state_lock, flags);
3386f231ddaSDan Williams 
3396f231ddaSDan Williams 	return old_state;
3406f231ddaSDan Williams }
3416f231ddaSDan Williams 
3426f231ddaSDan Williams /**
3436f231ddaSDan Williams  * isci_request_change_started_to_newstate() - This function sets the status of
3446f231ddaSDan Williams  *    the request object.
3456f231ddaSDan Williams  * @request: This parameter points to the isci_request object
3466f231ddaSDan Williams  * @status: This Parameter is the new status of the object
3476f231ddaSDan Williams  *
3486f231ddaSDan Williams  * state previous to any change.
3496f231ddaSDan Williams  */
350e301370aSEdmund Nadolski static inline enum isci_request_status
351e301370aSEdmund Nadolski isci_request_change_started_to_newstate(struct isci_request *isci_request,
3526f231ddaSDan Williams 					struct completion *completion_ptr,
3536f231ddaSDan Williams 					enum isci_request_status newstate)
3546f231ddaSDan Williams {
3556f231ddaSDan Williams 	enum isci_request_status old_state;
3566f231ddaSDan Williams 	unsigned long flags;
3576f231ddaSDan Williams 
3586f231ddaSDan Williams 	spin_lock_irqsave(&isci_request->state_lock, flags);
3596f231ddaSDan Williams 
3606f231ddaSDan Williams 	old_state = isci_request->status;
3616f231ddaSDan Williams 
362f219f010SJeff Skirvin 	if (old_state == started || old_state == aborting) {
3636f231ddaSDan Williams 		BUG_ON(isci_request->io_request_completion != NULL);
3646f231ddaSDan Williams 
3656f231ddaSDan Williams 		isci_request->io_request_completion = completion_ptr;
3666f231ddaSDan Williams 		isci_request->status = newstate;
3676f231ddaSDan Williams 	}
368e301370aSEdmund Nadolski 
3696f231ddaSDan Williams 	spin_unlock_irqrestore(&isci_request->state_lock, flags);
3706f231ddaSDan Williams 
3716f231ddaSDan Williams 	dev_dbg(&isci_request->isci_host->pdev->dev,
3726f231ddaSDan Williams 		"%s: isci_request = %p, old_state = 0x%x\n",
3736f231ddaSDan Williams 		__func__,
3746f231ddaSDan Williams 		isci_request,
3756f231ddaSDan Williams 		old_state);
3766f231ddaSDan Williams 
3776f231ddaSDan Williams 	return old_state;
3786f231ddaSDan Williams }
3796f231ddaSDan Williams 
3806f231ddaSDan Williams /**
3816f231ddaSDan Williams  * isci_request_change_started_to_aborted() - This function sets the status of
3826f231ddaSDan Williams  *    the request object.
3836f231ddaSDan Williams  * @request: This parameter points to the isci_request object
3846f231ddaSDan Williams  * @completion_ptr: This parameter is saved as the kernel completion structure
3856f231ddaSDan Williams  *    signalled when the old request completes.
3866f231ddaSDan Williams  *
3876f231ddaSDan Williams  * state previous to any change.
3886f231ddaSDan Williams  */
389e301370aSEdmund Nadolski static inline enum isci_request_status
390e301370aSEdmund Nadolski isci_request_change_started_to_aborted(struct isci_request *isci_request,
3916f231ddaSDan Williams 				       struct completion *completion_ptr)
3926f231ddaSDan Williams {
393e301370aSEdmund Nadolski 	return isci_request_change_started_to_newstate(isci_request,
394e301370aSEdmund Nadolski 						       completion_ptr,
395e301370aSEdmund Nadolski 						       aborted);
3966f231ddaSDan Williams }
3976f231ddaSDan Williams 
398e301370aSEdmund Nadolski #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
3996f231ddaSDan Williams 
400e301370aSEdmund Nadolski #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
4016f231ddaSDan Williams 
402db056250SDan Williams struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
4036f231ddaSDan Williams 					       struct isci_tmf *isci_tmf,
404db056250SDan Williams 					       u16 tag);
405209fae14SDan Williams int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
406db056250SDan Williams 			 struct sas_task *task, u16 tag);
407ddcc7e34SDan Williams void isci_terminate_pending_requests(struct isci_host *ihost,
408980d3aebSDan Williams 				     struct isci_remote_device *idev);
409e301370aSEdmund Nadolski enum sci_status
41089a7301fSDan Williams sci_task_request_construct(struct isci_host *ihost,
41178a6f06eSDan Williams 			    struct isci_remote_device *idev,
412f1f52e75SDan Williams 			    u16 io_tag,
4135076a1a9SDan Williams 			    struct isci_request *ireq);
41443a5ab15SDan Williams enum sci_status sci_task_request_construct_ssp(struct isci_request *ireq);
41589a7301fSDan Williams void sci_smp_request_copy_response(struct isci_request *ireq);
4169274f45eSJeff Skirvin 
4179274f45eSJeff Skirvin static inline int isci_task_is_ncq_recovery(struct sas_task *task)
4189274f45eSJeff Skirvin {
4199274f45eSJeff Skirvin 	return (sas_protocol_ata(task->task_proto) &&
4209274f45eSJeff Skirvin 		task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
4219274f45eSJeff Skirvin 		task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
4229274f45eSJeff Skirvin 
4239274f45eSJeff Skirvin }
4249274f45eSJeff Skirvin 
4256f231ddaSDan Williams #endif /* !defined(_ISCI_REQUEST_H_) */
426