blob: bee6dd2d0fe75ed1f8c7efe5f2d98d4ecb5e36e2 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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
Dan Williams88f3b622011-04-22 19:18:03 -070056#ifndef _ISCI_REMOTE_DEVICE_H_
Dan Williams6f231dd2011-07-02 22:56:22 -070057#define _ISCI_REMOTE_DEVICE_H_
Dan Williams88f3b622011-04-22 19:18:03 -070058#include <scsi/libsas.h>
Dan Williams209fae12011-06-13 17:39:44 -070059#include <linux/kref.h>
Dan Williams88f3b622011-04-22 19:18:03 -070060#include "scu_remote_node_context.h"
61#include "remote_node_context.h"
62#include "port.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070063
Dan Williams89a73012011-06-30 19:14:33 -070064enum sci_remote_device_not_ready_reason_code {
Dan Williams88f3b622011-04-22 19:18:03 -070065 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,
Dan Williams88f3b622011-04-22 19:18:03 -070070 SCIC_REMOTE_DEVICE_NOT_READY_REASON_CODE_MAX
Dan Williams88f3b622011-04-22 19:18:03 -070071};
72
Dan Williams78a6f062011-06-30 16:31:37 -070073/**
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 */
Dan Williams6f231dd2011-07-02 22:56:22 -070081struct isci_remote_device {
Dan Williams6ad31fe2011-03-04 12:10:29 -080082 #define IDEV_START_PENDING 0
83 #define IDEV_STOP_PENDING 1
Dan Williamsd9c37392011-03-03 17:59:32 -080084 #define IDEV_ALLOCATED 2
Dan Williamsd06b4872011-05-02 13:59:25 -070085 #define IDEV_EH 3
Dan Williams209fae12011-06-13 17:39:44 -070086 #define IDEV_GONE 4
Dan Williamsf2088262011-06-16 11:26:12 -070087 #define IDEV_IO_READY 5
Jeff Skirvin9274f452011-06-23 17:09:02 -070088 #define IDEV_IO_NCQERROR 6
Dan Williams6ad31fe2011-03-04 12:10:29 -080089 unsigned long flags;
Dan Williams209fae12011-06-13 17:39:44 -070090 struct kref kref;
Dan Williams6f231dd2011-07-02 22:56:22 -070091 struct isci_port *isci_port;
92 struct domain_device *domain_dev;
Dan Williams6f231dd2011-07-02 22:56:22 -070093 struct list_head node;
94 struct list_head reqs_in_process;
Dan Williams78a6f062011-06-30 16:31:37 -070095 struct sci_base_state_machine sm;
96 u32 device_port_width;
97 enum sas_linkrate connection_rate;
98 bool is_direct_attached;
99 struct isci_port *owning_port;
Dan Williams89a73012011-06-30 19:14:33 -0700100 struct sci_remote_node_context rnc;
Dan Williams78a6f062011-06-30 16:31:37 -0700101 /* XXX unify with device reference counting and delete */
102 u32 started_request_count;
103 struct isci_request *working_request;
104 u32 not_ready_reason;
Dan Williams6f231dd2011-07-02 22:56:22 -0700105};
106
Dan Williams6f231dd2011-07-02 22:56:22 -0700107#define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000
108
Dan Williams89a73012011-06-30 19:14:33 -0700109/* device reference routines must be called under sci_lock */
Dan Williams209fae12011-06-13 17:39:44 -0700110static inline struct isci_remote_device *isci_lookup_device(struct domain_device *dev)
111{
112 struct isci_remote_device *idev = dev->lldd_dev;
113
114 if (idev && !test_bit(IDEV_GONE, &idev->flags)) {
115 kref_get(&idev->kref);
116 return idev;
117 }
118
119 return NULL;
120}
121
122void isci_remote_device_release(struct kref *kref);
123static inline void isci_put_device(struct isci_remote_device *idev)
124{
125 if (idev)
126 kref_put(&idev->kref, isci_remote_device_release);
127}
128
Dan Williams6ad31fe2011-03-04 12:10:29 -0800129enum sci_status isci_remote_device_stop(struct isci_host *ihost,
130 struct isci_remote_device *idev);
Dan Williams4393aa42011-03-31 13:10:44 -0700131void isci_remote_device_nuke_requests(struct isci_host *ihost,
132 struct isci_remote_device *idev);
Dan Williams4393aa42011-03-31 13:10:44 -0700133void isci_remote_device_gone(struct domain_device *domain_dev);
134int isci_remote_device_found(struct domain_device *domain_dev);
Dan Williams4393aa42011-03-31 13:10:44 -0700135void isci_device_clear_reset_pending(struct isci_host *ihost,
136 struct isci_remote_device *idev);
Dan Williams88f3b622011-04-22 19:18:03 -0700137/**
Dan Williams89a73012011-06-30 19:14:33 -0700138 * sci_remote_device_stop() - This method will stop both transmission and
Dan Williams88f3b622011-04-22 19:18:03 -0700139 * reception of link activity for the supplied remote device. This method
140 * disables normal IO requests from flowing through to the remote device.
141 * @remote_device: This parameter specifies the device to be stopped.
142 * @timeout: This parameter specifies the number of milliseconds in which the
143 * stop operation should complete.
144 *
145 * An indication of whether the device was successfully stopped. SCI_SUCCESS
146 * This value is returned if the transmission and reception for the device was
147 * successfully stopped.
148 */
Dan Williams89a73012011-06-30 19:14:33 -0700149enum sci_status sci_remote_device_stop(
Dan Williams78a6f062011-06-30 16:31:37 -0700150 struct isci_remote_device *idev,
Dan Williams88f3b622011-04-22 19:18:03 -0700151 u32 timeout);
152
153/**
Dan Williams89a73012011-06-30 19:14:33 -0700154 * sci_remote_device_reset() - This method will reset the device making it
Dan Williams88f3b622011-04-22 19:18:03 -0700155 * ready for operation. This method must be called anytime the device is
156 * reset either through a SMP phy control or a port hard reset request.
157 * @remote_device: This parameter specifies the device to be reset.
158 *
159 * This method does not actually cause the device hardware to be reset. This
160 * method resets the software object so that it will be operational after a
161 * device hardware reset completes. An indication of whether the device reset
162 * was accepted. SCI_SUCCESS This value is returned if the device reset is
163 * started.
164 */
Dan Williams89a73012011-06-30 19:14:33 -0700165enum sci_status sci_remote_device_reset(
Dan Williams78a6f062011-06-30 16:31:37 -0700166 struct isci_remote_device *idev);
Dan Williams88f3b622011-04-22 19:18:03 -0700167
168/**
Dan Williams89a73012011-06-30 19:14:33 -0700169 * sci_remote_device_reset_complete() - This method informs the device object
Dan Williams88f3b622011-04-22 19:18:03 -0700170 * that the reset operation is complete and the device can resume operation
171 * again.
172 * @remote_device: This parameter specifies the device which is to be informed
173 * of the reset complete operation.
174 *
175 * An indication that the device is resuming operation. SCI_SUCCESS the device
176 * is resuming operation.
177 */
Dan Williams89a73012011-06-30 19:14:33 -0700178enum sci_status sci_remote_device_reset_complete(
Dan Williams78a6f062011-06-30 16:31:37 -0700179 struct isci_remote_device *idev);
Dan Williams88f3b622011-04-22 19:18:03 -0700180
Dan Williams88f3b622011-04-22 19:18:03 -0700181/**
Dan Williams89a73012011-06-30 19:14:33 -0700182 * enum sci_remote_device_states - This enumeration depicts all the states
Dan Williams88f3b622011-04-22 19:18:03 -0700183 * for the common remote device state machine.
184 *
185 *
186 */
Dan Williams89a73012011-06-30 19:14:33 -0700187enum sci_remote_device_states {
Dan Williams88f3b622011-04-22 19:18:03 -0700188 /**
189 * Simply the initial state for the base remote device state machine.
190 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000191 SCI_DEV_INITIAL,
Dan Williams88f3b622011-04-22 19:18:03 -0700192
193 /**
194 * This state indicates that the remote device has successfully been
195 * stopped. In this state no new IO operations are permitted.
196 * This state is entered from the INITIAL state.
197 * This state is entered from the STOPPING state.
198 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000199 SCI_DEV_STOPPED,
Dan Williams88f3b622011-04-22 19:18:03 -0700200
201 /**
202 * This state indicates the the remote device is in the process of
203 * becoming ready (i.e. starting). In this state no new IO operations
204 * are permitted.
205 * This state is entered from the STOPPED state.
206 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000207 SCI_DEV_STARTING,
Dan Williams88f3b622011-04-22 19:18:03 -0700208
209 /**
210 * This state indicates the remote device is now ready. Thus, the user
211 * is able to perform IO operations on the remote device.
212 * This state is entered from the STARTING state.
213 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000214 SCI_DEV_READY,
Dan Williams88f3b622011-04-22 19:18:03 -0700215
216 /**
Dan Williams88f3b622011-04-22 19:18:03 -0700217 * This is the idle substate for the stp remote device. When there are no
218 * active IO for the device it is is in this state.
219 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000220 SCI_STP_DEV_IDLE,
Dan Williams88f3b622011-04-22 19:18:03 -0700221
222 /**
223 * This is the command state for for the STP remote device. This state is
224 * entered when the device is processing a non-NCQ command. The device object
225 * will fail any new start IO requests until this command is complete.
226 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000227 SCI_STP_DEV_CMD,
Dan Williams88f3b622011-04-22 19:18:03 -0700228
229 /**
230 * This is the NCQ state for the STP remote device. This state is entered
231 * when the device is processing an NCQ reuqest. It will remain in this state
232 * so long as there is one or more NCQ requests being processed.
233 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000234 SCI_STP_DEV_NCQ,
Dan Williams88f3b622011-04-22 19:18:03 -0700235
236 /**
237 * This is the NCQ error state for the STP remote device. This state is
238 * entered when an SDB error FIS is received by the device object while in the
239 * NCQ state. The device object will only accept a READ LOG command while in
240 * this state.
241 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000242 SCI_STP_DEV_NCQ_ERROR,
Dan Williams88f3b622011-04-22 19:18:03 -0700243
Dan Williams88f3b622011-04-22 19:18:03 -0700244 /**
Dan Williamsb50102d2011-09-30 18:52:19 -0700245 * This is the ATAPI error state for the STP ATAPI remote device.
246 * This state is entered when ATAPI device sends error status FIS
247 * without data while the device object is in CMD state.
248 * A suspension event is expected in this state.
249 * The device object will resume right away.
250 */
251 SCI_STP_DEV_ATAPI_ERROR,
252
253 /**
Dan Williams88f3b622011-04-22 19:18:03 -0700254 * This is the READY substate indicates the device is waiting for the RESET task
255 * coming to be recovered from certain hardware specific error.
256 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000257 SCI_STP_DEV_AWAIT_RESET,
Dan Williams88f3b622011-04-22 19:18:03 -0700258
Dan Williams88f3b622011-04-22 19:18:03 -0700259 /**
260 * This is the ready operational substate for the remote device. This is the
261 * normal operational state for a remote device.
262 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000263 SCI_SMP_DEV_IDLE,
Dan Williams88f3b622011-04-22 19:18:03 -0700264
265 /**
266 * This is the suspended state for the remote device. This is the state that
267 * the device is placed in when a RNC suspend is received by the SCU hardware.
268 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000269 SCI_SMP_DEV_CMD,
Dan Williamsab2e8f72011-04-27 16:32:45 -0700270
271 /**
272 * This state indicates that the remote device is in the process of
273 * stopping. In this state no new IO operations are permitted, but
274 * existing IO operations are allowed to complete.
275 * This state is entered from the READY state.
276 * This state is entered from the FAILED state.
277 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000278 SCI_DEV_STOPPING,
Dan Williamsab2e8f72011-04-27 16:32:45 -0700279
280 /**
281 * This state indicates that the remote device has failed.
282 * In this state no new IO operations are permitted.
283 * This state is entered from the INITIALIZING state.
284 * This state is entered from the READY state.
285 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000286 SCI_DEV_FAILED,
Dan Williamsab2e8f72011-04-27 16:32:45 -0700287
288 /**
289 * This state indicates the device is being reset.
290 * In this state no new IO operations are permitted.
291 * This state is entered from the READY state.
292 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000293 SCI_DEV_RESETTING,
Dan Williamsab2e8f72011-04-27 16:32:45 -0700294
295 /**
296 * Simply the final state for the base remote device state machine.
297 */
Edmund Nadolskie3013702011-06-02 00:10:43 +0000298 SCI_DEV_FINAL,
Dan Williams88f3b622011-04-22 19:18:03 -0700299};
300
Dan Williams89a73012011-06-30 19:14:33 -0700301static inline struct isci_remote_device *rnc_to_dev(struct sci_remote_node_context *rnc)
Dan Williams88f3b622011-04-22 19:18:03 -0700302{
Dan Williams78a6f062011-06-30 16:31:37 -0700303 struct isci_remote_device *idev;
Dan Williams88f3b622011-04-22 19:18:03 -0700304
Dan Williams78a6f062011-06-30 16:31:37 -0700305 idev = container_of(rnc, typeof(*idev), rnc);
Dan Williamsa1a113b2011-04-21 18:44:45 -0700306
Maciej Patelczyk5d937e92011-04-28 22:06:21 +0000307 return idev;
308}
309
Dan Williamsa1a113b2011-04-21 18:44:45 -0700310static inline bool dev_is_expander(struct domain_device *dev)
311{
312 return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV;
313}
314
Dan Williams34a99152011-07-01 02:25:15 -0700315static inline void sci_remote_device_decrement_request_count(struct isci_remote_device *idev)
316{
317 /* XXX delete this voodoo when converting to the top-level device
318 * reference count
319 */
320 if (WARN_ONCE(idev->started_request_count == 0,
321 "%s: tried to decrement started_request_count past 0!?",
322 __func__))
323 /* pass */;
324 else
325 idev->started_request_count--;
326}
Dan Williams88f3b622011-04-22 19:18:03 -0700327
Dan Williams89a73012011-06-30 19:14:33 -0700328enum sci_status sci_remote_device_frame_handler(
Dan Williams78a6f062011-06-30 16:31:37 -0700329 struct isci_remote_device *idev,
Dan Williams88f3b622011-04-22 19:18:03 -0700330 u32 frame_index);
331
Dan Williams89a73012011-06-30 19:14:33 -0700332enum sci_status sci_remote_device_event_handler(
Dan Williams78a6f062011-06-30 16:31:37 -0700333 struct isci_remote_device *idev,
Dan Williams88f3b622011-04-22 19:18:03 -0700334 u32 event_code);
335
Dan Williams89a73012011-06-30 19:14:33 -0700336enum sci_status sci_remote_device_start_io(
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700337 struct isci_host *ihost,
Dan Williams78a6f062011-06-30 16:31:37 -0700338 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700339 struct isci_request *ireq);
Dan Williams88f3b622011-04-22 19:18:03 -0700340
Dan Williams89a73012011-06-30 19:14:33 -0700341enum sci_status sci_remote_device_start_task(
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700342 struct isci_host *ihost,
Dan Williams78a6f062011-06-30 16:31:37 -0700343 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700344 struct isci_request *ireq);
Dan Williamsab2e8f72011-04-27 16:32:45 -0700345
Dan Williams89a73012011-06-30 19:14:33 -0700346enum sci_status sci_remote_device_complete_io(
Dan Williamsd9dcb4b2011-06-30 17:38:32 -0700347 struct isci_host *ihost,
Dan Williams78a6f062011-06-30 16:31:37 -0700348 struct isci_remote_device *idev,
Dan Williams5076a1a2011-06-27 14:57:03 -0700349 struct isci_request *ireq);
Dan Williams88f3b622011-04-22 19:18:03 -0700350
Dan Williams89a73012011-06-30 19:14:33 -0700351enum sci_status sci_remote_device_suspend(
Dan Williams78a6f062011-06-30 16:31:37 -0700352 struct isci_remote_device *idev,
Dan Williams88f3b622011-04-22 19:18:03 -0700353 u32 suspend_type);
354
Dan Williams89a73012011-06-30 19:14:33 -0700355void sci_remote_device_post_request(
Dan Williams78a6f062011-06-30 16:31:37 -0700356 struct isci_remote_device *idev,
Dan Williams88f3b622011-04-22 19:18:03 -0700357 u32 request);
358
Dan Williams6f231dd2011-07-02 22:56:22 -0700359#endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */