isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / scsi / isci / core / sci_base_request.h
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.
4  *
5  * GPL LICENSE SUMMARY
6  *
7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8  *
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.
12  *
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.
17  *
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.
23  *
24  * BSD LICENSE
25  *
26  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  *
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.
42  *
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.
54  */
55
56 #ifndef _SCI_BASE_REQUST_H_
57 #define _SCI_BASE_REQUST_H_
58
59 /**
60  * This file contains all of the constants, types, and method declarations for
61  *    the SCI base IO and task request objects.
62  *
63  *
64  */
65
66 #include "sci_base_state_machine.h"
67
68 /**
69  * enum sci_base_request_states - This enumeration depicts all the states for
70  *    the common request state machine.
71  *
72  *
73  */
74 enum sci_base_request_states {
75         /**
76          * Simply the initial state for the base request state machine.
77          */
78         SCI_BASE_REQUEST_STATE_INITIAL,
79
80         /**
81          * This state indicates that the request has been constructed. This state
82          * is entered from the INITIAL state.
83          */
84         SCI_BASE_REQUEST_STATE_CONSTRUCTED,
85
86         /**
87          * This state indicates that the request has been started. This state is
88          * entered from the CONSTRUCTED state.
89          */
90         SCI_BASE_REQUEST_STATE_STARTED,
91
92         /**
93          * This state indicates that the request has completed.
94          * This state is entered from the STARTED state. This state is entered from
95          * the ABORTING state.
96          */
97         SCI_BASE_REQUEST_STATE_COMPLETED,
98
99         /**
100          * This state indicates that the request is in the process of being
101          * terminated/aborted.
102          * This state is entered from the CONSTRUCTED state.
103          * This state is entered from the STARTED state.
104          */
105         SCI_BASE_REQUEST_STATE_ABORTING,
106
107         /**
108          * Simply the final state for the base request state machine.
109          */
110         SCI_BASE_REQUEST_STATE_FINAL,
111 };
112
113 /**
114  * struct sci_base_request - The base request object abstracts the fields
115  *    common to all SCI IO and task request objects.
116  *
117  *
118  */
119 struct sci_base_request {
120         /**
121          * The field specifies that the parent object for the base request is the
122          * base object itself.
123          */
124         struct sci_base_object parent;
125
126         /**
127          * This field contains the information for the base request state machine.
128          */
129         struct sci_base_state_machine state_machine;
130 };
131
132 typedef enum sci_status (*SCI_BASE_REQUEST_HANDLER_T)(
133         struct sci_base_request *this_request
134         );
135
136 /**
137  * struct sci_base_request_state_handler - This structure contains all of the
138  *    state handler methods common to base IO and task request state machines.
139  *    Handler methods provide the ability to change the behavior for user
140  *    requests or transitions depending on the state the machine is in.
141  *
142  *
143  */
144 struct sci_base_request_state_handler {
145         /**
146          * The start_handler specifies the method invoked when a user attempts to
147          * start a request.
148          */
149         SCI_BASE_REQUEST_HANDLER_T start_handler;
150
151         /**
152          * The abort_handler specifies the method invoked when a user attempts to
153          * abort a request.
154          */
155         SCI_BASE_REQUEST_HANDLER_T abort_handler;
156
157         /**
158          * The complete_handler specifies the method invoked when a user attempts to
159          * complete a request.
160          */
161         SCI_BASE_REQUEST_HANDLER_T complete_handler;
162
163         /**
164          * The destruct_handler specifies the method invoked when a user attempts to
165          * destruct a request.
166          */
167         SCI_BASE_REQUEST_HANDLER_T destruct_handler;
168
169 };
170
171 /**
172  * sci_base_request_construct() - Construct the base request.
173  * @this_request: This parameter specifies the base request to be constructed.
174  * @state_table: This parameter specifies the table of state definitions to be
175  *    utilized for the request state machine.
176  *
177  */
178 static inline void sci_base_request_construct(
179         struct sci_base_request *base_req,
180         const struct sci_base_state *my_state_table)
181 {
182         base_req->parent.private = NULL;
183         sci_base_state_machine_construct(
184                 &base_req->state_machine,
185                 &base_req->parent,
186                 my_state_table,
187                 SCI_BASE_REQUEST_STATE_INITIAL
188                 );
189
190         sci_base_state_machine_start(
191                 &base_req->state_machine
192                 );
193 }
194
195 #endif /* _SCI_BASE_REQUST_H_ */