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 | |
88f3b62a DW |
64 | enum scic_remote_device_not_ready_reason_code { |
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 | ||
73 | struct scic_sds_remote_device { | |
88f3b62a DW |
74 | /** |
75 | * This field contains the information for the base remote device state | |
76 | * machine. | |
77 | */ | |
e301370a | 78 | struct sci_base_state_machine sm; |
88f3b62a DW |
79 | |
80 | /** | |
81 | * This field is the programmed device port width. This value is | |
82 | * written to the RCN data structure to tell the SCU how many open | |
83 | * connections this device can have. | |
84 | */ | |
85 | u32 device_port_width; | |
86 | ||
87 | /** | |
88 | * This field is the programmed connection rate for this remote device. It is | |
89 | * used to program the TC with the maximum allowed connection rate. | |
90 | */ | |
91 | enum sas_linkrate connection_rate; | |
92 | ||
88f3b62a DW |
93 | /** |
94 | * This filed is assinged the value of true if the device is directly | |
95 | * attached to the port. | |
96 | */ | |
97 | bool is_direct_attached; | |
98 | ||
88f3b62a DW |
99 | /** |
100 | * This filed contains a pointer back to the port to which this device | |
101 | * is assigned. | |
102 | */ | |
103 | struct scic_sds_port *owning_port; | |
104 | ||
105 | /** | |
106 | * This field contains the SCU silicon remote node context specific | |
107 | * information. | |
108 | */ | |
109 | struct scic_sds_remote_node_context rnc; | |
110 | ||
111 | /** | |
112 | * This field contains the stated request count for the remote device. The | |
e301370a | 113 | * device can not reach the SCI_DEV_STOPPED until all |
88f3b62a DW |
114 | * requests are complete and the rnc_posted value is false. |
115 | */ | |
116 | u32 started_request_count; | |
117 | ||
118 | /** | |
119 | * This field contains a pointer to the working request object. It is only | |
120 | * used only for SATA requests since the unsolicited frames we get from the | |
121 | * hardware have no Tag value to look up the io request object. | |
122 | */ | |
123 | struct scic_sds_request *working_request; | |
124 | ||
125 | /** | |
126 | * This field contains the reason for the remote device going not_ready. It is | |
127 | * assigned in the state handlers and used in the state transition. | |
128 | */ | |
129 | u32 not_ready_reason; | |
88f3b62a | 130 | }; |
6f231dda DW |
131 | |
132 | struct isci_remote_device { | |
6ad31fec DW |
133 | #define IDEV_START_PENDING 0 |
134 | #define IDEV_STOP_PENDING 1 | |
d9c37390 | 135 | #define IDEV_ALLOCATED 2 |
d06b487b | 136 | #define IDEV_EH 3 |
209fae14 | 137 | #define IDEV_GONE 4 |
f2088267 | 138 | #define IDEV_IO_READY 5 |
6ad31fec | 139 | unsigned long flags; |
209fae14 | 140 | struct kref kref; |
6f231dda DW |
141 | struct isci_port *isci_port; |
142 | struct domain_device *domain_dev; | |
6f231dda DW |
143 | struct list_head node; |
144 | struct list_head reqs_in_process; | |
57f20f4e | 145 | struct scic_sds_remote_device sci; |
6f231dda DW |
146 | }; |
147 | ||
6f231dda DW |
148 | #define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000 |
149 | ||
209fae14 DW |
150 | /* device reference routines must be called under scic_lock */ |
151 | static inline struct isci_remote_device *isci_lookup_device(struct domain_device *dev) | |
152 | { | |
153 | struct isci_remote_device *idev = dev->lldd_dev; | |
154 | ||
155 | if (idev && !test_bit(IDEV_GONE, &idev->flags)) { | |
156 | kref_get(&idev->kref); | |
157 | return idev; | |
158 | } | |
159 | ||
160 | return NULL; | |
161 | } | |
162 | ||
163 | void isci_remote_device_release(struct kref *kref); | |
164 | static inline void isci_put_device(struct isci_remote_device *idev) | |
165 | { | |
166 | if (idev) | |
167 | kref_put(&idev->kref, isci_remote_device_release); | |
168 | } | |
169 | ||
6ad31fec DW |
170 | enum sci_status isci_remote_device_stop(struct isci_host *ihost, |
171 | struct isci_remote_device *idev); | |
4393aa4e DW |
172 | void isci_remote_device_nuke_requests(struct isci_host *ihost, |
173 | struct isci_remote_device *idev); | |
4393aa4e DW |
174 | void isci_remote_device_gone(struct domain_device *domain_dev); |
175 | int isci_remote_device_found(struct domain_device *domain_dev); | |
176 | bool isci_device_is_reset_pending(struct isci_host *ihost, | |
177 | struct isci_remote_device *idev); | |
178 | void isci_device_clear_reset_pending(struct isci_host *ihost, | |
179 | struct isci_remote_device *idev); | |
88f3b62a DW |
180 | /** |
181 | * scic_remote_device_stop() - This method will stop both transmission and | |
182 | * reception of link activity for the supplied remote device. This method | |
183 | * disables normal IO requests from flowing through to the remote device. | |
184 | * @remote_device: This parameter specifies the device to be stopped. | |
185 | * @timeout: This parameter specifies the number of milliseconds in which the | |
186 | * stop operation should complete. | |
187 | * | |
188 | * An indication of whether the device was successfully stopped. SCI_SUCCESS | |
189 | * This value is returned if the transmission and reception for the device was | |
190 | * successfully stopped. | |
191 | */ | |
192 | enum sci_status scic_remote_device_stop( | |
193 | struct scic_sds_remote_device *remote_device, | |
194 | u32 timeout); | |
195 | ||
196 | /** | |
197 | * scic_remote_device_reset() - This method will reset the device making it | |
198 | * ready for operation. This method must be called anytime the device is | |
199 | * reset either through a SMP phy control or a port hard reset request. | |
200 | * @remote_device: This parameter specifies the device to be reset. | |
201 | * | |
202 | * This method does not actually cause the device hardware to be reset. This | |
203 | * method resets the software object so that it will be operational after a | |
204 | * device hardware reset completes. An indication of whether the device reset | |
205 | * was accepted. SCI_SUCCESS This value is returned if the device reset is | |
206 | * started. | |
207 | */ | |
208 | enum sci_status scic_remote_device_reset( | |
209 | struct scic_sds_remote_device *remote_device); | |
210 | ||
211 | /** | |
212 | * scic_remote_device_reset_complete() - This method informs the device object | |
213 | * that the reset operation is complete and the device can resume operation | |
214 | * again. | |
215 | * @remote_device: This parameter specifies the device which is to be informed | |
216 | * of the reset complete operation. | |
217 | * | |
218 | * An indication that the device is resuming operation. SCI_SUCCESS the device | |
219 | * is resuming operation. | |
220 | */ | |
221 | enum sci_status scic_remote_device_reset_complete( | |
222 | struct scic_sds_remote_device *remote_device); | |
223 | ||
88f3b62a | 224 | #define scic_remote_device_is_atapi(device_handle) false |
88f3b62a DW |
225 | |
226 | /** | |
227 | * enum scic_sds_remote_device_states - This enumeration depicts all the states | |
228 | * for the common remote device state machine. | |
229 | * | |
230 | * | |
231 | */ | |
232 | enum scic_sds_remote_device_states { | |
233 | /** | |
234 | * Simply the initial state for the base remote device state machine. | |
235 | */ | |
e301370a | 236 | SCI_DEV_INITIAL, |
88f3b62a DW |
237 | |
238 | /** | |
239 | * This state indicates that the remote device has successfully been | |
240 | * stopped. In this state no new IO operations are permitted. | |
241 | * This state is entered from the INITIAL state. | |
242 | * This state is entered from the STOPPING state. | |
243 | */ | |
e301370a | 244 | SCI_DEV_STOPPED, |
88f3b62a DW |
245 | |
246 | /** | |
247 | * This state indicates the the remote device is in the process of | |
248 | * becoming ready (i.e. starting). In this state no new IO operations | |
249 | * are permitted. | |
250 | * This state is entered from the STOPPED state. | |
251 | */ | |
e301370a | 252 | SCI_DEV_STARTING, |
88f3b62a DW |
253 | |
254 | /** | |
255 | * This state indicates the remote device is now ready. Thus, the user | |
256 | * is able to perform IO operations on the remote device. | |
257 | * This state is entered from the STARTING state. | |
258 | */ | |
e301370a | 259 | SCI_DEV_READY, |
88f3b62a | 260 | |
88f3b62a DW |
261 | /** |
262 | * This is the idle substate for the stp remote device. When there are no | |
263 | * active IO for the device it is is in this state. | |
264 | */ | |
e301370a | 265 | SCI_STP_DEV_IDLE, |
88f3b62a DW |
266 | |
267 | /** | |
268 | * This is the command state for for the STP remote device. This state is | |
269 | * entered when the device is processing a non-NCQ command. The device object | |
270 | * will fail any new start IO requests until this command is complete. | |
271 | */ | |
e301370a | 272 | SCI_STP_DEV_CMD, |
88f3b62a DW |
273 | |
274 | /** | |
275 | * This is the NCQ state for the STP remote device. This state is entered | |
276 | * when the device is processing an NCQ reuqest. It will remain in this state | |
277 | * so long as there is one or more NCQ requests being processed. | |
278 | */ | |
e301370a | 279 | SCI_STP_DEV_NCQ, |
88f3b62a DW |
280 | |
281 | /** | |
282 | * This is the NCQ error state for the STP remote device. This state is | |
283 | * entered when an SDB error FIS is received by the device object while in the | |
284 | * NCQ state. The device object will only accept a READ LOG command while in | |
285 | * this state. | |
286 | */ | |
e301370a | 287 | SCI_STP_DEV_NCQ_ERROR, |
88f3b62a | 288 | |
88f3b62a DW |
289 | /** |
290 | * This is the READY substate indicates the device is waiting for the RESET task | |
291 | * coming to be recovered from certain hardware specific error. | |
292 | */ | |
e301370a | 293 | SCI_STP_DEV_AWAIT_RESET, |
88f3b62a | 294 | |
88f3b62a DW |
295 | /** |
296 | * This is the ready operational substate for the remote device. This is the | |
297 | * normal operational state for a remote device. | |
298 | */ | |
e301370a | 299 | SCI_SMP_DEV_IDLE, |
88f3b62a DW |
300 | |
301 | /** | |
302 | * This is the suspended state for the remote device. This is the state that | |
303 | * the device is placed in when a RNC suspend is received by the SCU hardware. | |
304 | */ | |
e301370a | 305 | SCI_SMP_DEV_CMD, |
ab2e8f7d DW |
306 | |
307 | /** | |
308 | * This state indicates that the remote device is in the process of | |
309 | * stopping. In this state no new IO operations are permitted, but | |
310 | * existing IO operations are allowed to complete. | |
311 | * This state is entered from the READY state. | |
312 | * This state is entered from the FAILED state. | |
313 | */ | |
e301370a | 314 | SCI_DEV_STOPPING, |
ab2e8f7d DW |
315 | |
316 | /** | |
317 | * This state indicates that the remote device has failed. | |
318 | * In this state no new IO operations are permitted. | |
319 | * This state is entered from the INITIALIZING state. | |
320 | * This state is entered from the READY state. | |
321 | */ | |
e301370a | 322 | SCI_DEV_FAILED, |
ab2e8f7d DW |
323 | |
324 | /** | |
325 | * This state indicates the device is being reset. | |
326 | * In this state no new IO operations are permitted. | |
327 | * This state is entered from the READY state. | |
328 | */ | |
e301370a | 329 | SCI_DEV_RESETTING, |
ab2e8f7d DW |
330 | |
331 | /** | |
332 | * Simply the final state for the base remote device state machine. | |
333 | */ | |
e301370a | 334 | SCI_DEV_FINAL, |
88f3b62a DW |
335 | }; |
336 | ||
337 | static inline struct scic_sds_remote_device *rnc_to_dev(struct scic_sds_remote_node_context *rnc) | |
338 | { | |
339 | struct scic_sds_remote_device *sci_dev; | |
340 | ||
341 | sci_dev = container_of(rnc, typeof(*sci_dev), rnc); | |
342 | ||
343 | return sci_dev; | |
344 | } | |
345 | ||
5d937e96 | 346 | static inline struct isci_remote_device *sci_dev_to_idev(struct scic_sds_remote_device *sci_dev) |
a1a113b0 DW |
347 | { |
348 | struct isci_remote_device *idev = container_of(sci_dev, typeof(*idev), sci); | |
349 | ||
5d937e96 MP |
350 | return idev; |
351 | } | |
352 | ||
353 | static inline struct domain_device *sci_dev_to_domain(struct scic_sds_remote_device *sci_dev) | |
354 | { | |
355 | return sci_dev_to_idev(sci_dev)->domain_dev; | |
a1a113b0 DW |
356 | } |
357 | ||
358 | static inline bool dev_is_expander(struct domain_device *dev) | |
359 | { | |
360 | return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV; | |
361 | } | |
362 | ||
88f3b62a DW |
363 | /** |
364 | * scic_sds_remote_device_increment_request_count() - | |
365 | * | |
366 | * This macro incrments the request count for this device | |
367 | */ | |
368 | #define scic_sds_remote_device_increment_request_count(sci_dev) \ | |
369 | ((sci_dev)->started_request_count++) | |
370 | ||
371 | /** | |
372 | * scic_sds_remote_device_decrement_request_count() - | |
373 | * | |
374 | * This macro decrements the request count for this device. This count will | |
375 | * never decrment past 0. | |
376 | */ | |
377 | #define scic_sds_remote_device_decrement_request_count(sci_dev) \ | |
378 | ((sci_dev)->started_request_count > 0 ? \ | |
379 | (sci_dev)->started_request_count-- : 0) | |
380 | ||
381 | /** | |
382 | * scic_sds_remote_device_get_request_count() - | |
383 | * | |
384 | * This is a helper macro to return the current device request count. | |
385 | */ | |
386 | #define scic_sds_remote_device_get_request_count(sci_dev) \ | |
387 | ((sci_dev)->started_request_count) | |
388 | ||
389 | /** | |
390 | * scic_sds_remote_device_get_port() - | |
391 | * | |
392 | * This macro returns the owning port of this remote device obejct. | |
393 | */ | |
394 | #define scic_sds_remote_device_get_port(sci_dev) \ | |
395 | ((sci_dev)->owning_port) | |
396 | ||
397 | /** | |
398 | * scic_sds_remote_device_get_controller() - | |
399 | * | |
400 | * This macro returns the controller object that contains this device object | |
401 | */ | |
402 | #define scic_sds_remote_device_get_controller(sci_dev) \ | |
403 | scic_sds_port_get_controller(scic_sds_remote_device_get_port(sci_dev)) | |
404 | ||
88f3b62a DW |
405 | /** |
406 | * scic_sds_remote_device_get_port() - | |
407 | * | |
408 | * This macro returns the owning port of this device | |
409 | */ | |
410 | #define scic_sds_remote_device_get_port(sci_dev) \ | |
411 | ((sci_dev)->owning_port) | |
412 | ||
88f3b62a DW |
413 | /** |
414 | * scic_sds_remote_device_get_controller_peg() - | |
415 | * | |
416 | * This macro returns the controllers protocol engine group | |
417 | */ | |
418 | #define scic_sds_remote_device_get_controller_peg(sci_dev) \ | |
419 | (\ | |
420 | scic_sds_controller_get_protocol_engine_group(\ | |
421 | scic_sds_port_get_controller(\ | |
422 | scic_sds_remote_device_get_port(sci_dev) \ | |
423 | ) \ | |
424 | ) \ | |
425 | ) | |
426 | ||
88f3b62a DW |
427 | /** |
428 | * scic_sds_remote_device_get_index() - | |
429 | * | |
430 | * This macro returns the remote node index for this device object | |
431 | */ | |
432 | #define scic_sds_remote_device_get_index(sci_dev) \ | |
433 | ((sci_dev)->rnc.remote_node_index) | |
434 | ||
435 | /** | |
436 | * scic_sds_remote_device_build_command_context() - | |
437 | * | |
438 | * This macro builds a remote device context for the SCU post request operation | |
439 | */ | |
440 | #define scic_sds_remote_device_build_command_context(device, command) \ | |
441 | ((command) \ | |
442 | | (scic_sds_remote_device_get_controller_peg((device)) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) \ | |
1f4fa1f9 | 443 | | ((device)->owning_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \ |
88f3b62a DW |
444 | | (scic_sds_remote_device_get_index((device))) \ |
445 | ) | |
446 | ||
447 | /** | |
448 | * scic_sds_remote_device_set_working_request() - | |
449 | * | |
450 | * This macro makes the working request assingment for the remote device | |
451 | * object. To clear the working request use this macro with a NULL request | |
452 | * object. | |
453 | */ | |
454 | #define scic_sds_remote_device_set_working_request(device, request) \ | |
455 | ((device)->working_request = (request)) | |
456 | ||
457 | enum sci_status scic_sds_remote_device_frame_handler( | |
458 | struct scic_sds_remote_device *sci_dev, | |
459 | u32 frame_index); | |
460 | ||
461 | enum sci_status scic_sds_remote_device_event_handler( | |
462 | struct scic_sds_remote_device *sci_dev, | |
463 | u32 event_code); | |
464 | ||
465 | enum sci_status scic_sds_remote_device_start_io( | |
466 | struct scic_sds_controller *controller, | |
467 | struct scic_sds_remote_device *sci_dev, | |
468 | struct scic_sds_request *io_request); | |
469 | ||
ab2e8f7d | 470 | enum sci_status scic_sds_remote_device_start_task( |
88f3b62a DW |
471 | struct scic_sds_controller *controller, |
472 | struct scic_sds_remote_device *sci_dev, | |
473 | struct scic_sds_request *io_request); | |
474 | ||
ab2e8f7d DW |
475 | enum sci_status scic_sds_remote_device_complete_io( |
476 | struct scic_sds_controller *controller, | |
477 | struct scic_sds_remote_device *sci_dev, | |
478 | struct scic_sds_request *io_request); | |
88f3b62a DW |
479 | |
480 | enum sci_status scic_sds_remote_device_suspend( | |
481 | struct scic_sds_remote_device *sci_dev, | |
482 | u32 suspend_type); | |
483 | ||
88f3b62a DW |
484 | void scic_sds_remote_device_post_request( |
485 | struct scic_sds_remote_device *sci_dev, | |
486 | u32 request); | |
487 | ||
88f3b62a | 488 | #define scic_sds_remote_device_is_atapi(sci_dev) false |
88f3b62a | 489 | |
6f231dda | 490 | #endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */ |