isci: unify remote_device start_io_handlers
[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
DW
58#include <scsi/libsas.h>
59#include "sci_status.h"
60#include "intel_sas.h"
61#include "scu_remote_node_context.h"
62#include "remote_node_context.h"
63#include "port.h"
6f231dda 64
88f3b62a
DW
65enum scic_remote_device_not_ready_reason_code {
66 SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED,
67 SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED,
68 SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED,
69 SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED,
70 SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED,
88f3b62a 71 SCIC_REMOTE_DEVICE_NOT_READY_REASON_CODE_MAX
88f3b62a
DW
72};
73
74struct scic_sds_remote_device {
88f3b62a
DW
75 /**
76 * This field contains the information for the base remote device state
77 * machine.
78 */
79 struct sci_base_state_machine state_machine;
80
81 /**
82 * This field is the programmed device port width. This value is
83 * written to the RCN data structure to tell the SCU how many open
84 * connections this device can have.
85 */
86 u32 device_port_width;
87
88 /**
89 * This field is the programmed connection rate for this remote device. It is
90 * used to program the TC with the maximum allowed connection rate.
91 */
92 enum sas_linkrate connection_rate;
93
88f3b62a
DW
94 /**
95 * This filed is assinged the value of true if the device is directly
96 * attached to the port.
97 */
98 bool is_direct_attached;
99
88f3b62a
DW
100 /**
101 * This filed contains a pointer back to the port to which this device
102 * is assigned.
103 */
104 struct scic_sds_port *owning_port;
105
106 /**
107 * This field contains the SCU silicon remote node context specific
108 * information.
109 */
110 struct scic_sds_remote_node_context rnc;
111
112 /**
113 * This field contains the stated request count for the remote device. The
114 * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all
115 * requests are complete and the rnc_posted value is false.
116 */
117 u32 started_request_count;
118
119 /**
120 * This field contains a pointer to the working request object. It is only
121 * used only for SATA requests since the unsolicited frames we get from the
122 * hardware have no Tag value to look up the io request object.
123 */
124 struct scic_sds_request *working_request;
125
126 /**
127 * This field contains the reason for the remote device going not_ready. It is
128 * assigned in the state handlers and used in the state transition.
129 */
130 u32 not_ready_reason;
131
88f3b62a
DW
132 /**
133 * This field maintains the set of state handlers for the remote device
134 * object. These are changed each time the remote device enters a new state.
135 */
136 const struct scic_sds_remote_device_state_handler *state_handlers;
137};
6f231dda
DW
138
139struct isci_remote_device {
6f231dda 140 enum isci_status status;
6ad31fec
DW
141 #define IDEV_START_PENDING 0
142 #define IDEV_STOP_PENDING 1
d9c37390 143 #define IDEV_ALLOCATED 2
6ad31fec 144 unsigned long flags;
6f231dda
DW
145 struct isci_port *isci_port;
146 struct domain_device *domain_dev;
6f231dda
DW
147 struct list_head node;
148 struct list_head reqs_in_process;
6f231dda 149 spinlock_t state_lock;
57f20f4e 150 struct scic_sds_remote_device sci;
6f231dda
DW
151};
152
6f231dda
DW
153#define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000
154
6ad31fec
DW
155enum sci_status isci_remote_device_stop(struct isci_host *ihost,
156 struct isci_remote_device *idev);
4393aa4e
DW
157void isci_remote_device_nuke_requests(struct isci_host *ihost,
158 struct isci_remote_device *idev);
4393aa4e
DW
159void isci_remote_device_gone(struct domain_device *domain_dev);
160int isci_remote_device_found(struct domain_device *domain_dev);
161bool isci_device_is_reset_pending(struct isci_host *ihost,
162 struct isci_remote_device *idev);
163void isci_device_clear_reset_pending(struct isci_host *ihost,
164 struct isci_remote_device *idev);
165void isci_remote_device_change_state(struct isci_remote_device *idev,
166 enum isci_status status);
88f3b62a
DW
167/**
168 * scic_remote_device_stop() - This method will stop both transmission and
169 * reception of link activity for the supplied remote device. This method
170 * disables normal IO requests from flowing through to the remote device.
171 * @remote_device: This parameter specifies the device to be stopped.
172 * @timeout: This parameter specifies the number of milliseconds in which the
173 * stop operation should complete.
174 *
175 * An indication of whether the device was successfully stopped. SCI_SUCCESS
176 * This value is returned if the transmission and reception for the device was
177 * successfully stopped.
178 */
179enum sci_status scic_remote_device_stop(
180 struct scic_sds_remote_device *remote_device,
181 u32 timeout);
182
183/**
184 * scic_remote_device_reset() - This method will reset the device making it
185 * ready for operation. This method must be called anytime the device is
186 * reset either through a SMP phy control or a port hard reset request.
187 * @remote_device: This parameter specifies the device to be reset.
188 *
189 * This method does not actually cause the device hardware to be reset. This
190 * method resets the software object so that it will be operational after a
191 * device hardware reset completes. An indication of whether the device reset
192 * was accepted. SCI_SUCCESS This value is returned if the device reset is
193 * started.
194 */
195enum sci_status scic_remote_device_reset(
196 struct scic_sds_remote_device *remote_device);
197
198/**
199 * scic_remote_device_reset_complete() - This method informs the device object
200 * that the reset operation is complete and the device can resume operation
201 * again.
202 * @remote_device: This parameter specifies the device which is to be informed
203 * of the reset complete operation.
204 *
205 * An indication that the device is resuming operation. SCI_SUCCESS the device
206 * is resuming operation.
207 */
208enum sci_status scic_remote_device_reset_complete(
209 struct scic_sds_remote_device *remote_device);
210
88f3b62a 211#define scic_remote_device_is_atapi(device_handle) false
88f3b62a
DW
212
213/**
214 * enum scic_sds_remote_device_states - This enumeration depicts all the states
215 * for the common remote device state machine.
216 *
217 *
218 */
219enum scic_sds_remote_device_states {
220 /**
221 * Simply the initial state for the base remote device state machine.
222 */
223 SCI_BASE_REMOTE_DEVICE_STATE_INITIAL,
224
225 /**
226 * This state indicates that the remote device has successfully been
227 * stopped. In this state no new IO operations are permitted.
228 * This state is entered from the INITIAL state.
229 * This state is entered from the STOPPING state.
230 */
231 SCI_BASE_REMOTE_DEVICE_STATE_STOPPED,
232
233 /**
234 * This state indicates the the remote device is in the process of
235 * becoming ready (i.e. starting). In this state no new IO operations
236 * are permitted.
237 * This state is entered from the STOPPED state.
238 */
239 SCI_BASE_REMOTE_DEVICE_STATE_STARTING,
240
241 /**
242 * This state indicates the remote device is now ready. Thus, the user
243 * is able to perform IO operations on the remote device.
244 * This state is entered from the STARTING state.
245 */
246 SCI_BASE_REMOTE_DEVICE_STATE_READY,
247
88f3b62a
DW
248 /**
249 * This is the idle substate for the stp remote device. When there are no
250 * active IO for the device it is is in this state.
251 */
252 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
253
254 /**
255 * This is the command state for for the STP remote device. This state is
256 * entered when the device is processing a non-NCQ command. The device object
257 * will fail any new start IO requests until this command is complete.
258 */
259 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
260
261 /**
262 * This is the NCQ state for the STP remote device. This state is entered
263 * when the device is processing an NCQ reuqest. It will remain in this state
264 * so long as there is one or more NCQ requests being processed.
265 */
266 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ,
267
268 /**
269 * This is the NCQ error state for the STP remote device. This state is
270 * entered when an SDB error FIS is received by the device object while in the
271 * NCQ state. The device object will only accept a READ LOG command while in
272 * this state.
273 */
274 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR,
275
88f3b62a
DW
276 /**
277 * This is the READY substate indicates the device is waiting for the RESET task
278 * coming to be recovered from certain hardware specific error.
279 */
280 SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET,
88f3b62a 281
88f3b62a
DW
282 /**
283 * This is the ready operational substate for the remote device. This is the
284 * normal operational state for a remote device.
285 */
286 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
287
288 /**
289 * This is the suspended state for the remote device. This is the state that
290 * the device is placed in when a RNC suspend is received by the SCU hardware.
291 */
292 SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
ab2e8f7d
DW
293
294 /**
295 * This state indicates that the remote device is in the process of
296 * stopping. In this state no new IO operations are permitted, but
297 * existing IO operations are allowed to complete.
298 * This state is entered from the READY state.
299 * This state is entered from the FAILED state.
300 */
301 SCI_BASE_REMOTE_DEVICE_STATE_STOPPING,
302
303 /**
304 * This state indicates that the remote device has failed.
305 * In this state no new IO operations are permitted.
306 * This state is entered from the INITIALIZING state.
307 * This state is entered from the READY state.
308 */
309 SCI_BASE_REMOTE_DEVICE_STATE_FAILED,
310
311 /**
312 * This state indicates the device is being reset.
313 * In this state no new IO operations are permitted.
314 * This state is entered from the READY state.
315 */
316 SCI_BASE_REMOTE_DEVICE_STATE_RESETTING,
317
318 /**
319 * Simply the final state for the base remote device state machine.
320 */
321 SCI_BASE_REMOTE_DEVICE_STATE_FINAL,
88f3b62a
DW
322};
323
324static inline struct scic_sds_remote_device *rnc_to_dev(struct scic_sds_remote_node_context *rnc)
325{
326 struct scic_sds_remote_device *sci_dev;
327
328 sci_dev = container_of(rnc, typeof(*sci_dev), rnc);
329
330 return sci_dev;
331}
332
5d937e96 333static inline struct isci_remote_device *sci_dev_to_idev(struct scic_sds_remote_device *sci_dev)
a1a113b0
DW
334{
335 struct isci_remote_device *idev = container_of(sci_dev, typeof(*idev), sci);
336
5d937e96
MP
337 return idev;
338}
339
340static inline struct domain_device *sci_dev_to_domain(struct scic_sds_remote_device *sci_dev)
341{
342 return sci_dev_to_idev(sci_dev)->domain_dev;
a1a113b0
DW
343}
344
345static inline bool dev_is_expander(struct domain_device *dev)
346{
347 return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV;
348}
349
88f3b62a
DW
350typedef enum sci_status (*scic_sds_remote_device_request_handler_t)(
351 struct scic_sds_remote_device *device,
352 struct scic_sds_request *request);
353
354typedef enum sci_status (*scic_sds_remote_device_high_priority_request_complete_handler_t)(
355 struct scic_sds_remote_device *device,
356 struct scic_sds_request *request,
357 void *,
358 enum sci_io_status);
359
360typedef enum sci_status (*scic_sds_remote_device_handler_t)(
361 struct scic_sds_remote_device *sci_dev);
362
363typedef enum sci_status (*scic_sds_remote_device_suspend_handler_t)(
364 struct scic_sds_remote_device *sci_dev,
365 u32 suspend_type);
366
367typedef enum sci_status (*scic_sds_remote_device_resume_handler_t)(
368 struct scic_sds_remote_device *sci_dev);
369
370typedef enum sci_status (*scic_sds_remote_device_frame_handler_t)(
371 struct scic_sds_remote_device *sci_dev,
372 u32 frame_index);
373
374typedef enum sci_status (*scic_sds_remote_device_event_handler_t)(
375 struct scic_sds_remote_device *sci_dev,
376 u32 event_code);
377
378typedef void (*scic_sds_remote_device_ready_not_ready_handler_t)(
379 struct scic_sds_remote_device *sci_dev);
380
381/**
382 * struct scic_sds_remote_device_state_handler - This structure conains the
383 * state handlers that are needed to process requests for the SCU remote
384 * device objects.
385 *
386 *
387 */
388struct scic_sds_remote_device_state_handler {
88f3b62a
DW
389 /**
390 * The complete_io_handler specifies the method invoked when a user
391 * attempts to complete an IO request for a remote device.
392 */
393 scic_sds_remote_device_request_handler_t complete_io_handler;
394
395 /**
396 * The continue_io_handler specifies the method invoked when a user
397 * attempts to continue an IO request for a remote device.
398 */
399 scic_sds_remote_device_request_handler_t continue_io_handler;
400
401 /**
402 * The start_task_handler specifies the method invoked when a user
403 * attempts to start a task management request for a remote device.
404 */
405 scic_sds_remote_device_request_handler_t start_task_handler;
406
407 /**
408 * The complete_task_handler specifies the method invoked when a user
409 * attempts to complete a task management request for a remote device.
410 */
411 scic_sds_remote_device_request_handler_t complete_task_handler;
412
413
414 scic_sds_remote_device_suspend_handler_t suspend_handler;
415 scic_sds_remote_device_resume_handler_t resume_handler;
416 scic_sds_remote_device_event_handler_t event_handler;
417 scic_sds_remote_device_frame_handler_t frame_handler;
418};
419
88f3b62a
DW
420/**
421 * scic_sds_remote_device_increment_request_count() -
422 *
423 * This macro incrments the request count for this device
424 */
425#define scic_sds_remote_device_increment_request_count(sci_dev) \
426 ((sci_dev)->started_request_count++)
427
428/**
429 * scic_sds_remote_device_decrement_request_count() -
430 *
431 * This macro decrements the request count for this device. This count will
432 * never decrment past 0.
433 */
434#define scic_sds_remote_device_decrement_request_count(sci_dev) \
435 ((sci_dev)->started_request_count > 0 ? \
436 (sci_dev)->started_request_count-- : 0)
437
438/**
439 * scic_sds_remote_device_get_request_count() -
440 *
441 * This is a helper macro to return the current device request count.
442 */
443#define scic_sds_remote_device_get_request_count(sci_dev) \
444 ((sci_dev)->started_request_count)
445
446/**
447 * scic_sds_remote_device_get_port() -
448 *
449 * This macro returns the owning port of this remote device obejct.
450 */
451#define scic_sds_remote_device_get_port(sci_dev) \
452 ((sci_dev)->owning_port)
453
454/**
455 * scic_sds_remote_device_get_controller() -
456 *
457 * This macro returns the controller object that contains this device object
458 */
459#define scic_sds_remote_device_get_controller(sci_dev) \
460 scic_sds_port_get_controller(scic_sds_remote_device_get_port(sci_dev))
461
462/**
463 * scic_sds_remote_device_set_state_handlers() -
464 *
465 * This macro sets the remote device state handlers pointer and is set on entry
466 * to each device state.
467 */
468#define scic_sds_remote_device_set_state_handlers(sci_dev, handlers) \
469 ((sci_dev)->state_handlers = (handlers))
470
471/**
472 * scic_sds_remote_device_get_port() -
473 *
474 * This macro returns the owning port of this device
475 */
476#define scic_sds_remote_device_get_port(sci_dev) \
477 ((sci_dev)->owning_port)
478
479/**
480 * scic_sds_remote_device_get_sequence() -
481 *
482 * This macro returns the remote device sequence value
483 */
484#define scic_sds_remote_device_get_sequence(sci_dev) \
485 (\
486 scic_sds_remote_device_get_controller(sci_dev)-> \
487 remote_device_sequence[(sci_dev)->rnc.remote_node_index] \
488 )
489
490/**
491 * scic_sds_remote_device_get_controller_peg() -
492 *
493 * This macro returns the controllers protocol engine group
494 */
495#define scic_sds_remote_device_get_controller_peg(sci_dev) \
496 (\
497 scic_sds_controller_get_protocol_engine_group(\
498 scic_sds_port_get_controller(\
499 scic_sds_remote_device_get_port(sci_dev) \
500 ) \
501 ) \
502 )
503
88f3b62a
DW
504/**
505 * scic_sds_remote_device_get_index() -
506 *
507 * This macro returns the remote node index for this device object
508 */
509#define scic_sds_remote_device_get_index(sci_dev) \
510 ((sci_dev)->rnc.remote_node_index)
511
512/**
513 * scic_sds_remote_device_build_command_context() -
514 *
515 * This macro builds a remote device context for the SCU post request operation
516 */
517#define scic_sds_remote_device_build_command_context(device, command) \
518 ((command) \
519 | (scic_sds_remote_device_get_controller_peg((device)) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) \
1f4fa1f9 520 | ((device)->owning_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
88f3b62a
DW
521 | (scic_sds_remote_device_get_index((device))) \
522 )
523
524/**
525 * scic_sds_remote_device_set_working_request() -
526 *
527 * This macro makes the working request assingment for the remote device
528 * object. To clear the working request use this macro with a NULL request
529 * object.
530 */
531#define scic_sds_remote_device_set_working_request(device, request) \
532 ((device)->working_request = (request))
533
534enum sci_status scic_sds_remote_device_frame_handler(
535 struct scic_sds_remote_device *sci_dev,
536 u32 frame_index);
537
538enum sci_status scic_sds_remote_device_event_handler(
539 struct scic_sds_remote_device *sci_dev,
540 u32 event_code);
541
542enum sci_status scic_sds_remote_device_start_io(
543 struct scic_sds_controller *controller,
544 struct scic_sds_remote_device *sci_dev,
545 struct scic_sds_request *io_request);
546
ab2e8f7d 547enum sci_status scic_sds_remote_device_start_task(
88f3b62a
DW
548 struct scic_sds_controller *controller,
549 struct scic_sds_remote_device *sci_dev,
550 struct scic_sds_request *io_request);
551
ab2e8f7d
DW
552enum sci_status scic_sds_remote_device_complete_io(
553 struct scic_sds_controller *controller,
554 struct scic_sds_remote_device *sci_dev,
555 struct scic_sds_request *io_request);
88f3b62a
DW
556
557enum sci_status scic_sds_remote_device_suspend(
558 struct scic_sds_remote_device *sci_dev,
559 u32 suspend_type);
560
88f3b62a
DW
561void scic_sds_remote_device_post_request(
562 struct scic_sds_remote_device *sci_dev,
563 u32 request);
564
88f3b62a 565#define scic_sds_remote_device_is_atapi(sci_dev) false
88f3b62a 566
6f231dda 567#endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */
This page took 0.05333 seconds and 5 git commands to generate.