isci: Implement waiting for suspend in the abort path.
[deliverable/linux.git] / drivers / scsi / isci / remote_device.h
CommitLineData
6f231dda
DW
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
88f3b62a 56#ifndef _ISCI_REMOTE_DEVICE_H_
6f231dda 57#define _ISCI_REMOTE_DEVICE_H_
88f3b62a 58#include <scsi/libsas.h>
209fae14 59#include <linux/kref.h>
88f3b62a
DW
60#include "scu_remote_node_context.h"
61#include "remote_node_context.h"
62#include "port.h"
6f231dda 63
89a7301f 64enum sci_remote_device_not_ready_reason_code {
88f3b62a
DW
65 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED,
66 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED,
67 SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED,
68 SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED,
69 SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED,
88f3b62a 70 SCIC_REMOTE_DEVICE_NOT_READY_REASON_CODE_MAX
88f3b62a
DW
71};
72
78a6f06e
DW
73/**
74 * isci_remote_device - isci representation of a sas expander / end point
75 * @device_port_width: hw setting for number of simultaneous connections
76 * @connection_rate: per-taskcontext connection rate for this device
77 * @working_request: SATA requests have no tag we for unaccelerated
78 * protocols we need a method to associate unsolicited
79 * frames with a pending request
80 */
6f231dda 81struct isci_remote_device {
6ad31fec
DW
82 #define IDEV_START_PENDING 0
83 #define IDEV_STOP_PENDING 1
d9c37390 84 #define IDEV_ALLOCATED 2
5a998328
DW
85 #define IDEV_GONE 3
86 #define IDEV_IO_READY 4
87 #define IDEV_IO_NCQERROR 5
9608b640 88 #define IDEV_RNC_LLHANG_ENABLED 6
6ad31fec 89 unsigned long flags;
209fae14 90 struct kref kref;
6f231dda
DW
91 struct isci_port *isci_port;
92 struct domain_device *domain_dev;
6f231dda 93 struct list_head node;
78a6f06e
DW
94 struct sci_base_state_machine sm;
95 u32 device_port_width;
96 enum sas_linkrate connection_rate;
78a6f06e 97 struct isci_port *owning_port;
89a7301f 98 struct sci_remote_node_context rnc;
78a6f06e
DW
99 /* XXX unify with device reference counting and delete */
100 u32 started_request_count;
101 struct isci_request *working_request;
102 u32 not_ready_reason;
6f231dda
DW
103};
104
6f231dda
DW
105#define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000
106
89a7301f 107/* device reference routines must be called under sci_lock */
5b6bf225 108static inline struct isci_remote_device *isci_get_device(
14aaa9f0 109 struct isci_remote_device *idev)
5b6bf225 110{
5b6bf225
JS
111 if (idev)
112 kref_get(&idev->kref);
113 return idev;
114}
115
209fae14
DW
116static inline struct isci_remote_device *isci_lookup_device(struct domain_device *dev)
117{
118 struct isci_remote_device *idev = dev->lldd_dev;
119
120 if (idev && !test_bit(IDEV_GONE, &idev->flags)) {
121 kref_get(&idev->kref);
122 return idev;
123 }
124
125 return NULL;
126}
127
128void isci_remote_device_release(struct kref *kref);
129static inline void isci_put_device(struct isci_remote_device *idev)
130{
131 if (idev)
132 kref_put(&idev->kref, isci_remote_device_release);
133}
134
6ad31fec
DW
135enum sci_status isci_remote_device_stop(struct isci_host *ihost,
136 struct isci_remote_device *idev);
4393aa4e
DW
137void isci_remote_device_nuke_requests(struct isci_host *ihost,
138 struct isci_remote_device *idev);
4393aa4e
DW
139void isci_remote_device_gone(struct domain_device *domain_dev);
140int isci_remote_device_found(struct domain_device *domain_dev);
5412e25c 141
88f3b62a 142/**
89a7301f 143 * sci_remote_device_stop() - This method will stop both transmission and
88f3b62a
DW
144 * reception of link activity for the supplied remote device. This method
145 * disables normal IO requests from flowing through to the remote device.
146 * @remote_device: This parameter specifies the device to be stopped.
147 * @timeout: This parameter specifies the number of milliseconds in which the
148 * stop operation should complete.
149 *
150 * An indication of whether the device was successfully stopped. SCI_SUCCESS
151 * This value is returned if the transmission and reception for the device was
152 * successfully stopped.
153 */
89a7301f 154enum sci_status sci_remote_device_stop(
78a6f06e 155 struct isci_remote_device *idev,
88f3b62a
DW
156 u32 timeout);
157
158/**
89a7301f 159 * sci_remote_device_reset() - This method will reset the device making it
88f3b62a
DW
160 * ready for operation. This method must be called anytime the device is
161 * reset either through a SMP phy control or a port hard reset request.
162 * @remote_device: This parameter specifies the device to be reset.
163 *
164 * This method does not actually cause the device hardware to be reset. This
165 * method resets the software object so that it will be operational after a
166 * device hardware reset completes. An indication of whether the device reset
167 * was accepted. SCI_SUCCESS This value is returned if the device reset is
168 * started.
169 */
89a7301f 170enum sci_status sci_remote_device_reset(
78a6f06e 171 struct isci_remote_device *idev);
88f3b62a
DW
172
173/**
89a7301f 174 * sci_remote_device_reset_complete() - This method informs the device object
88f3b62a
DW
175 * that the reset operation is complete and the device can resume operation
176 * again.
177 * @remote_device: This parameter specifies the device which is to be informed
178 * of the reset complete operation.
179 *
180 * An indication that the device is resuming operation. SCI_SUCCESS the device
181 * is resuming operation.
182 */
89a7301f 183enum sci_status sci_remote_device_reset_complete(
78a6f06e 184 struct isci_remote_device *idev);
88f3b62a 185
88f3b62a 186/**
89a7301f 187 * enum sci_remote_device_states - This enumeration depicts all the states
88f3b62a 188 * for the common remote device state machine.
d7a0ccdd
DW
189 * @SCI_DEV_INITIAL: Simply the initial state for the base remote device
190 * state machine.
88f3b62a 191 *
d7a0ccdd
DW
192 * @SCI_DEV_STOPPED: This state indicates that the remote device has
193 * successfully been stopped. In this state no new IO operations are
194 * permitted. This state is entered from the INITIAL state. This state
195 * is entered from the STOPPING state.
88f3b62a 196 *
d7a0ccdd
DW
197 * @SCI_DEV_STARTING: This state indicates the the remote device is in
198 * the process of becoming ready (i.e. starting). In this state no new
199 * IO operations are permitted. This state is entered from the STOPPED
200 * state.
201 *
202 * @SCI_DEV_READY: This state indicates the remote device is now ready.
203 * Thus, the user is able to perform IO operations on the remote device.
204 * This state is entered from the STARTING state.
205 *
206 * @SCI_STP_DEV_IDLE: This is the idle substate for the stp remote
207 * device. When there are no active IO for the device it is is in this
208 * state.
209 *
210 * @SCI_STP_DEV_CMD: This is the command state for for the STP remote
211 * device. This state is entered when the device is processing a
212 * non-NCQ command. The device object will fail any new start IO
213 * requests until this command is complete.
214 *
215 * @SCI_STP_DEV_NCQ: This is the NCQ state for the STP remote device.
216 * This state is entered when the device is processing an NCQ reuqest.
217 * It will remain in this state so long as there is one or more NCQ
218 * requests being processed.
219 *
220 * @SCI_STP_DEV_NCQ_ERROR: This is the NCQ error state for the STP
221 * remote device. This state is entered when an SDB error FIS is
222 * received by the device object while in the NCQ state. The device
223 * object will only accept a READ LOG command while in this state.
224 *
225 * @SCI_STP_DEV_ATAPI_ERROR: This is the ATAPI error state for the STP
226 * ATAPI remote device. This state is entered when ATAPI device sends
227 * error status FIS without data while the device object is in CMD
228 * state. A suspension event is expected in this state. The device
229 * object will resume right away.
230 *
231 * @SCI_STP_DEV_AWAIT_RESET: This is the READY substate indicates the
232 * device is waiting for the RESET task coming to be recovered from
233 * certain hardware specific error.
234 *
235 * @SCI_SMP_DEV_IDLE: This is the ready operational substate for the
236 * remote device. This is the normal operational state for a remote
237 * device.
238 *
239 * @SCI_SMP_DEV_CMD: This is the suspended state for the remote device.
240 * This is the state that the device is placed in when a RNC suspend is
241 * received by the SCU hardware.
242 *
243 * @SCI_DEV_STOPPING: This state indicates that the remote device is in
244 * the process of stopping. In this state no new IO operations are
245 * permitted, but existing IO operations are allowed to complete. This
246 * state is entered from the READY state. This state is entered from
247 * the FAILED state.
248 *
249 * @SCI_DEV_FAILED: This state indicates that the remote device has
250 * failed. In this state no new IO operations are permitted. This
251 * state is entered from the INITIALIZING state. This state is entered
252 * from the READY state.
253 *
254 * @SCI_DEV_RESETTING: This state indicates the device is being reset.
255 * In this state no new IO operations are permitted. This state is
256 * entered from the READY state.
257 *
258 * @SCI_DEV_FINAL: Simply the final state for the base remote device
259 * state machine.
88f3b62a 260 */
d7a0ccdd
DW
261#define REMOTE_DEV_STATES {\
262 C(DEV_INITIAL),\
263 C(DEV_STOPPED),\
264 C(DEV_STARTING),\
265 C(DEV_READY),\
266 C(STP_DEV_IDLE),\
267 C(STP_DEV_CMD),\
268 C(STP_DEV_NCQ),\
269 C(STP_DEV_NCQ_ERROR),\
270 C(STP_DEV_ATAPI_ERROR),\
271 C(STP_DEV_AWAIT_RESET),\
272 C(SMP_DEV_IDLE),\
273 C(SMP_DEV_CMD),\
274 C(DEV_STOPPING),\
275 C(DEV_FAILED),\
276 C(DEV_RESETTING),\
277 C(DEV_FINAL),\
278 }
279#undef C
280#define C(a) SCI_##a
281enum sci_remote_device_states REMOTE_DEV_STATES;
282#undef C
283const char *dev_state_name(enum sci_remote_device_states state);
88f3b62a 284
89a7301f 285static inline struct isci_remote_device *rnc_to_dev(struct sci_remote_node_context *rnc)
88f3b62a 286{
78a6f06e 287 struct isci_remote_device *idev;
88f3b62a 288
78a6f06e 289 idev = container_of(rnc, typeof(*idev), rnc);
a1a113b0 290
5d937e96
MP
291 return idev;
292}
293
a1a113b0
DW
294static inline bool dev_is_expander(struct domain_device *dev)
295{
296 return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV;
297}
298
34a99158
DW
299static inline void sci_remote_device_decrement_request_count(struct isci_remote_device *idev)
300{
301 /* XXX delete this voodoo when converting to the top-level device
302 * reference count
303 */
304 if (WARN_ONCE(idev->started_request_count == 0,
305 "%s: tried to decrement started_request_count past 0!?",
306 __func__))
307 /* pass */;
308 else
309 idev->started_request_count--;
310}
88f3b62a 311
9608b640 312void isci_dev_set_hang_detection_timeout(struct isci_remote_device *idev, u32 timeout);
6f48844e 313
89a7301f 314enum sci_status sci_remote_device_frame_handler(
78a6f06e 315 struct isci_remote_device *idev,
88f3b62a
DW
316 u32 frame_index);
317
89a7301f 318enum sci_status sci_remote_device_event_handler(
78a6f06e 319 struct isci_remote_device *idev,
88f3b62a
DW
320 u32 event_code);
321
89a7301f 322enum sci_status sci_remote_device_start_io(
d9dcb4ba 323 struct isci_host *ihost,
78a6f06e 324 struct isci_remote_device *idev,
5076a1a9 325 struct isci_request *ireq);
88f3b62a 326
89a7301f 327enum sci_status sci_remote_device_start_task(
d9dcb4ba 328 struct isci_host *ihost,
78a6f06e 329 struct isci_remote_device *idev,
5076a1a9 330 struct isci_request *ireq);
88f3b62a 331
89a7301f 332enum sci_status sci_remote_device_complete_io(
d9dcb4ba 333 struct isci_host *ihost,
78a6f06e 334 struct isci_remote_device *idev,
5076a1a9 335 struct isci_request *ireq);
88f3b62a 336
89a7301f 337void sci_remote_device_post_request(
78a6f06e 338 struct isci_remote_device *idev,
88f3b62a
DW
339 u32 request);
340
726980d5
JS
341enum sci_status sci_remote_device_terminate_requests(
342 struct isci_remote_device *idev);
343
344int isci_remote_device_is_safe_to_abort(
345 struct isci_remote_device *idev);
346
347enum sci_status
348sci_remote_device_abort_requests_pending_abort(
349 struct isci_remote_device *idev);
5b6bf225
JS
350
351enum sci_status isci_remote_device_suspend(
352 struct isci_host *ihost,
353 struct isci_remote_device *idev);
354
355enum sci_status sci_remote_device_resume(
356 struct isci_remote_device *idev,
357 scics_sds_remote_node_context_callback cb_fn,
358 void *cb_p);
359
31a38ef0 360enum sci_status isci_remote_device_resume_from_abort(
5b6bf225 361 struct isci_host *ihost,
31a38ef0 362 struct isci_remote_device *idev);
5b6bf225
JS
363
364enum sci_status isci_remote_device_reset(
365 struct isci_host *ihost,
366 struct isci_remote_device *idev);
367
368enum sci_status isci_remote_device_reset_complete(
369 struct isci_host *ihost,
370 struct isci_remote_device *idev);
14aaa9f0
JS
371
372enum sci_status isci_remote_device_suspend_terminate(
373 struct isci_host *ihost,
374 struct isci_remote_device *idev,
375 struct isci_request *ireq);
376
377enum sci_status isci_remote_device_terminate_requests(
378 struct isci_host *ihost,
379 struct isci_remote_device *idev,
380 struct isci_request *ireq);
6f231dda 381#endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */
This page took 0.100167 seconds and 5 git commands to generate.