Commit | Line | Data |
---|---|---|
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 | 64 | enum 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 | 81 | struct isci_remote_device { |
6ad31fec DW |
82 | #define IDEV_START_PENDING 0 |
83 | #define IDEV_STOP_PENDING 1 | |
d9c37390 | 84 | #define IDEV_ALLOCATED 2 |
d06b487b | 85 | #define IDEV_EH 3 |
209fae14 | 86 | #define IDEV_GONE 4 |
f2088267 | 87 | #define IDEV_IO_READY 5 |
9274f45e | 88 | #define IDEV_IO_NCQERROR 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 DW |
93 | struct list_head node; |
94 | struct list_head reqs_in_process; | |
78a6f06e DW |
95 | 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; | |
89a7301f | 100 | struct sci_remote_node_context rnc; |
78a6f06e DW |
101 | /* XXX unify with device reference counting and delete */ |
102 | u32 started_request_count; | |
103 | struct isci_request *working_request; | |
104 | u32 not_ready_reason; | |
6f231dda DW |
105 | }; |
106 | ||
6f231dda DW |
107 | #define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000 |
108 | ||
89a7301f | 109 | /* device reference routines must be called under sci_lock */ |
209fae14 DW |
110 | static 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 | ||
122 | void isci_remote_device_release(struct kref *kref); | |
123 | static 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 | ||
6ad31fec DW |
129 | enum sci_status isci_remote_device_stop(struct isci_host *ihost, |
130 | struct isci_remote_device *idev); | |
4393aa4e DW |
131 | void isci_remote_device_nuke_requests(struct isci_host *ihost, |
132 | struct isci_remote_device *idev); | |
4393aa4e DW |
133 | void isci_remote_device_gone(struct domain_device *domain_dev); |
134 | int isci_remote_device_found(struct domain_device *domain_dev); | |
5412e25c | 135 | |
88f3b62a | 136 | /** |
89a7301f | 137 | * sci_remote_device_stop() - This method will stop both transmission and |
88f3b62a DW |
138 | * reception of link activity for the supplied remote device. This method |
139 | * disables normal IO requests from flowing through to the remote device. | |
140 | * @remote_device: This parameter specifies the device to be stopped. | |
141 | * @timeout: This parameter specifies the number of milliseconds in which the | |
142 | * stop operation should complete. | |
143 | * | |
144 | * An indication of whether the device was successfully stopped. SCI_SUCCESS | |
145 | * This value is returned if the transmission and reception for the device was | |
146 | * successfully stopped. | |
147 | */ | |
89a7301f | 148 | enum sci_status sci_remote_device_stop( |
78a6f06e | 149 | struct isci_remote_device *idev, |
88f3b62a DW |
150 | u32 timeout); |
151 | ||
152 | /** | |
89a7301f | 153 | * sci_remote_device_reset() - This method will reset the device making it |
88f3b62a DW |
154 | * ready for operation. This method must be called anytime the device is |
155 | * reset either through a SMP phy control or a port hard reset request. | |
156 | * @remote_device: This parameter specifies the device to be reset. | |
157 | * | |
158 | * This method does not actually cause the device hardware to be reset. This | |
159 | * method resets the software object so that it will be operational after a | |
160 | * device hardware reset completes. An indication of whether the device reset | |
161 | * was accepted. SCI_SUCCESS This value is returned if the device reset is | |
162 | * started. | |
163 | */ | |
89a7301f | 164 | enum sci_status sci_remote_device_reset( |
78a6f06e | 165 | struct isci_remote_device *idev); |
88f3b62a DW |
166 | |
167 | /** | |
89a7301f | 168 | * sci_remote_device_reset_complete() - This method informs the device object |
88f3b62a DW |
169 | * that the reset operation is complete and the device can resume operation |
170 | * again. | |
171 | * @remote_device: This parameter specifies the device which is to be informed | |
172 | * of the reset complete operation. | |
173 | * | |
174 | * An indication that the device is resuming operation. SCI_SUCCESS the device | |
175 | * is resuming operation. | |
176 | */ | |
89a7301f | 177 | enum sci_status sci_remote_device_reset_complete( |
78a6f06e | 178 | struct isci_remote_device *idev); |
88f3b62a | 179 | |
88f3b62a | 180 | /** |
89a7301f | 181 | * enum sci_remote_device_states - This enumeration depicts all the states |
88f3b62a DW |
182 | * for the common remote device state machine. |
183 | * | |
184 | * | |
185 | */ | |
89a7301f | 186 | enum sci_remote_device_states { |
88f3b62a DW |
187 | /** |
188 | * Simply the initial state for the base remote device state machine. | |
189 | */ | |
e301370a | 190 | SCI_DEV_INITIAL, |
88f3b62a DW |
191 | |
192 | /** | |
193 | * This state indicates that the remote device has successfully been | |
194 | * stopped. In this state no new IO operations are permitted. | |
195 | * This state is entered from the INITIAL state. | |
196 | * This state is entered from the STOPPING state. | |
197 | */ | |
e301370a | 198 | SCI_DEV_STOPPED, |
88f3b62a DW |
199 | |
200 | /** | |
201 | * This state indicates the the remote device is in the process of | |
202 | * becoming ready (i.e. starting). In this state no new IO operations | |
203 | * are permitted. | |
204 | * This state is entered from the STOPPED state. | |
205 | */ | |
e301370a | 206 | SCI_DEV_STARTING, |
88f3b62a DW |
207 | |
208 | /** | |
209 | * This state indicates the remote device is now ready. Thus, the user | |
210 | * is able to perform IO operations on the remote device. | |
211 | * This state is entered from the STARTING state. | |
212 | */ | |
e301370a | 213 | SCI_DEV_READY, |
88f3b62a | 214 | |
88f3b62a DW |
215 | /** |
216 | * This is the idle substate for the stp remote device. When there are no | |
217 | * active IO for the device it is is in this state. | |
218 | */ | |
e301370a | 219 | SCI_STP_DEV_IDLE, |
88f3b62a DW |
220 | |
221 | /** | |
222 | * This is the command state for for the STP remote device. This state is | |
223 | * entered when the device is processing a non-NCQ command. The device object | |
224 | * will fail any new start IO requests until this command is complete. | |
225 | */ | |
e301370a | 226 | SCI_STP_DEV_CMD, |
88f3b62a DW |
227 | |
228 | /** | |
229 | * This is the NCQ state for the STP remote device. This state is entered | |
230 | * when the device is processing an NCQ reuqest. It will remain in this state | |
231 | * so long as there is one or more NCQ requests being processed. | |
232 | */ | |
e301370a | 233 | SCI_STP_DEV_NCQ, |
88f3b62a DW |
234 | |
235 | /** | |
236 | * This is the NCQ error state for the STP remote device. This state is | |
237 | * entered when an SDB error FIS is received by the device object while in the | |
238 | * NCQ state. The device object will only accept a READ LOG command while in | |
239 | * this state. | |
240 | */ | |
e301370a | 241 | SCI_STP_DEV_NCQ_ERROR, |
88f3b62a | 242 | |
b50102d3 DW |
243 | /** |
244 | * This is the ATAPI error state for the STP ATAPI remote device. | |
245 | * This state is entered when ATAPI device sends error status FIS | |
246 | * without data while the device object is in CMD state. | |
247 | * A suspension event is expected in this state. | |
248 | * The device object will resume right away. | |
249 | */ | |
250 | SCI_STP_DEV_ATAPI_ERROR, | |
251 | ||
88f3b62a DW |
252 | /** |
253 | * This is the READY substate indicates the device is waiting for the RESET task | |
254 | * coming to be recovered from certain hardware specific error. | |
255 | */ | |
e301370a | 256 | SCI_STP_DEV_AWAIT_RESET, |
88f3b62a | 257 | |
88f3b62a DW |
258 | /** |
259 | * This is the ready operational substate for the remote device. This is the | |
260 | * normal operational state for a remote device. | |
261 | */ | |
e301370a | 262 | SCI_SMP_DEV_IDLE, |
88f3b62a DW |
263 | |
264 | /** | |
265 | * This is the suspended state for the remote device. This is the state that | |
266 | * the device is placed in when a RNC suspend is received by the SCU hardware. | |
267 | */ | |
e301370a | 268 | SCI_SMP_DEV_CMD, |
ab2e8f7d DW |
269 | |
270 | /** | |
271 | * This state indicates that the remote device is in the process of | |
272 | * stopping. In this state no new IO operations are permitted, but | |
273 | * existing IO operations are allowed to complete. | |
274 | * This state is entered from the READY state. | |
275 | * This state is entered from the FAILED state. | |
276 | */ | |
e301370a | 277 | SCI_DEV_STOPPING, |
ab2e8f7d DW |
278 | |
279 | /** | |
280 | * This state indicates that the remote device has failed. | |
281 | * In this state no new IO operations are permitted. | |
282 | * This state is entered from the INITIALIZING state. | |
283 | * This state is entered from the READY state. | |
284 | */ | |
e301370a | 285 | SCI_DEV_FAILED, |
ab2e8f7d DW |
286 | |
287 | /** | |
288 | * This state indicates the device is being reset. | |
289 | * In this state no new IO operations are permitted. | |
290 | * This state is entered from the READY state. | |
291 | */ | |
e301370a | 292 | SCI_DEV_RESETTING, |
ab2e8f7d DW |
293 | |
294 | /** | |
295 | * Simply the final state for the base remote device state machine. | |
296 | */ | |
e301370a | 297 | SCI_DEV_FINAL, |
88f3b62a DW |
298 | }; |
299 | ||
89a7301f | 300 | static inline struct isci_remote_device *rnc_to_dev(struct sci_remote_node_context *rnc) |
88f3b62a | 301 | { |
78a6f06e | 302 | struct isci_remote_device *idev; |
88f3b62a | 303 | |
78a6f06e | 304 | idev = container_of(rnc, typeof(*idev), rnc); |
a1a113b0 | 305 | |
5d937e96 MP |
306 | return idev; |
307 | } | |
308 | ||
a1a113b0 DW |
309 | static inline bool dev_is_expander(struct domain_device *dev) |
310 | { | |
311 | return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV; | |
312 | } | |
313 | ||
34a99158 DW |
314 | static inline void sci_remote_device_decrement_request_count(struct isci_remote_device *idev) |
315 | { | |
316 | /* XXX delete this voodoo when converting to the top-level device | |
317 | * reference count | |
318 | */ | |
319 | if (WARN_ONCE(idev->started_request_count == 0, | |
320 | "%s: tried to decrement started_request_count past 0!?", | |
321 | __func__)) | |
322 | /* pass */; | |
323 | else | |
324 | idev->started_request_count--; | |
325 | } | |
88f3b62a | 326 | |
89a7301f | 327 | enum sci_status sci_remote_device_frame_handler( |
78a6f06e | 328 | struct isci_remote_device *idev, |
88f3b62a DW |
329 | u32 frame_index); |
330 | ||
89a7301f | 331 | enum sci_status sci_remote_device_event_handler( |
78a6f06e | 332 | struct isci_remote_device *idev, |
88f3b62a DW |
333 | u32 event_code); |
334 | ||
89a7301f | 335 | enum sci_status sci_remote_device_start_io( |
d9dcb4ba | 336 | struct isci_host *ihost, |
78a6f06e | 337 | struct isci_remote_device *idev, |
5076a1a9 | 338 | struct isci_request *ireq); |
88f3b62a | 339 | |
89a7301f | 340 | enum sci_status sci_remote_device_start_task( |
d9dcb4ba | 341 | struct isci_host *ihost, |
78a6f06e | 342 | struct isci_remote_device *idev, |
5076a1a9 | 343 | struct isci_request *ireq); |
88f3b62a | 344 | |
89a7301f | 345 | enum sci_status sci_remote_device_complete_io( |
d9dcb4ba | 346 | struct isci_host *ihost, |
78a6f06e | 347 | struct isci_remote_device *idev, |
5076a1a9 | 348 | struct isci_request *ireq); |
88f3b62a | 349 | |
89a7301f | 350 | enum sci_status sci_remote_device_suspend( |
78a6f06e | 351 | struct isci_remote_device *idev, |
88f3b62a DW |
352 | u32 suspend_type); |
353 | ||
89a7301f | 354 | void sci_remote_device_post_request( |
78a6f06e | 355 | struct isci_remote_device *idev, |
88f3b62a DW |
356 | u32 request); |
357 | ||
6f231dda | 358 | #endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */ |