isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / scsi / isci / core / scic_sds_remote_device.h
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
56 #ifndef _SCIC_SDS_REMOTE_DEVICE_H_
57 #define _SCIC_SDS_REMOTE_DEVICE_H_
58
59 /**
60  * This file contains the structures, constants, and prototypes for the
61  *    struct scic_sds_remote_device object.
62  *
63  *
64  */
65
66 #include "intel_sas.h"
67 #include "sci_base_remote_device.h"
68 #include "sci_base_request.h"
69 #include "scu_remote_node_context.h"
70 #include "scic_sds_remote_node_context.h"
71
72 struct scic_sds_controller;
73 struct scic_sds_port;
74 struct scic_sds_request;
75 struct scic_sds_remote_device_state_handler;
76
77 /**
78  * enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES -
79  *
80  * This is the enumeration of the ready substates for the
81  * struct scic_sds_remote_device.
82  */
83 enum SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATES {
84         /**
85          * This is the initial state for the remote device ready substate.
86          */
87         SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_INITIAL,
88
89         /**
90          * This is the ready operational substate for the remote device.  This is the
91          * normal operational state for a remote device.
92          */
93         SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_OPERATIONAL,
94
95         /**
96          * This is the suspended state for the remote device.  This is the state that
97          * the device is placed in when a RNC suspend is received by the SCU hardware.
98          */
99         SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_SUSPENDED,
100
101         /**
102          * This is the final state that the device is placed in before a change to the
103          * base state machine.
104          */
105         SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_FINAL,
106
107         SCIC_SDS_SSP_REMOTE_DEVICE_READY_MAX_SUBSTATES
108 };
109
110 /**
111  * enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES -
112  *
113  * This is the enumeration for the struct scic_sds_remote_device ready substates for
114  * the STP remote device.
115  */
116 enum SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATES {
117         /**
118          * This is the idle substate for the stp remote device.  When there are no
119          * active IO for the device it is is in this state.
120          */
121         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
122
123         /**
124          * This is the command state for for the STP remote device.  This state is
125          * entered when the device is processing a non-NCQ command.  The device object
126          * will fail any new start IO requests until this command is complete.
127          */
128         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
129
130         /**
131          * This is the NCQ state for the STP remote device.  This state is entered
132          * when the device is processing an NCQ reuqest.  It will remain in this state
133          * so long as there is one or more NCQ requests being processed.
134          */
135         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ,
136
137         /**
138          * This is the NCQ error state for the STP remote device.  This state is
139          * entered when an SDB error FIS is received by the device object while in the
140          * NCQ state.  The device object will only accept a READ LOG command while in
141          * this state.
142          */
143         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR,
144
145 #if !defined(DISABLE_ATAPI)
146         /**
147          * This is the ATAPI error state for the STP ATAPI remote device.  This state is
148          * entered when ATAPI device sends error status FIS without data while the device
149          * object is in CMD state. A suspension event is expected in this state. The device
150          * object will resume right away.
151          */
152         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR,
153 #endif
154
155         /**
156          * This is the READY substate indicates the device is waiting for the RESET task
157          * coming to be recovered from certain hardware specific error.
158          */
159         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET,
160
161         SCIC_SDS_STP_REMOTE_DEVICE_READY_MAX_SUBSTATES
162 };
163
164
165 /**
166  * enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES -
167  *
168  * This is the enumeration of the ready substates for the SMP REMOTE DEVICE.
169  */
170
171 enum SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATES {
172         /**
173          * This is the ready operational substate for the remote device.  This is the
174          * normal operational state for a remote device.
175          */
176         SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
177
178         /**
179          * This is the suspended state for the remote device.  This is the state that
180          * the device is placed in when a RNC suspend is received by the SCU hardware.
181          */
182         SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
183
184         SCIC_SDS_SMP_REMOTE_DEVICE_READY_MAX_SUBSTATES
185 };
186
187
188
189
190 /**
191  * struct scic_sds_remote_device - This structure contains the data for an SCU
192  *    implementation of the SCU Core device data.
193  *
194  *
195  */
196 struct scic_sds_remote_device {
197         /**
198          * This field is the common base for all remote device objects.
199          */
200         struct sci_base_remote_device parent;
201
202         /**
203          * This field is the programmed device port width.  This value is written to
204          * the RCN data structure to tell the SCU how many open connections this
205          * device can have.
206          */
207         u32 device_port_width;
208
209         /**
210          * This field is the programmed connection rate for this remote device.  It is
211          * used to program the TC with the maximum allowed connection rate.
212          */
213         enum sci_sas_link_rate connection_rate;
214
215         /**
216          * This field contains the allowed target protocols for this remote device.
217          */
218         struct smp_discover_response_protocols target_protocols;
219
220         /**
221          * This field contains the device SAS address.
222          */
223         struct sci_sas_address device_address;
224
225         /**
226          * This filed is assinged the value of true if the device is directly attached
227          * to the port.
228          */
229         bool is_direct_attached;
230
231 #if !defined(DISABLE_ATAPI)
232         /**
233          * This filed is assinged the value of true if the device is an ATAPI device.
234          */
235         bool is_atapi;
236 #endif
237
238         /**
239          * This filed contains a pointer back to the port to which this device is
240          * assigned.
241          */
242         struct scic_sds_port *owning_port;
243
244         /**
245          * This field contains the SCU silicon remote node context specific
246          * information.
247          */
248         struct scic_sds_remote_node_context *rnc;
249
250         /**
251          * This field contains the stated request count for the remote device.  The
252          * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all
253          * requests are complete and the rnc_posted value is false.
254          */
255         u32 started_request_count;
256
257         /**
258          * This field contains a pointer to the working request object.  It is only
259          * used only for SATA requests since the unsolicited frames we get from the
260          * hardware have no Tag value to look up the io request object.
261          */
262         struct scic_sds_request *working_request;
263
264         /**
265          * This field contains the reason for the remote device going not_ready.  It is
266          * assigned in the state handlers and used in the state transition.
267          */
268         u32 not_ready_reason;
269
270         /**
271          * This field is true if this remote device has an initialzied ready substate
272          * machine. SSP devices do not have a ready substate machine and STP devices
273          * have a ready substate machine.
274          */
275         bool has_ready_substate_machine;
276
277         /**
278          * This field contains the state machine for the ready substate machine for
279          * this struct scic_sds_remote_device object.
280          */
281         struct sci_base_state_machine ready_substate_machine;
282
283         /**
284          * This field maintains the set of state handlers for the remote device
285          * object.  These are changed each time the remote device enters a new state.
286          */
287         struct scic_sds_remote_device_state_handler *state_handlers;
288 };
289
290
291 typedef enum sci_status (*SCIC_SDS_REMOTE_DEVICE_HANDLER_T)(
292         struct scic_sds_remote_device *this_device);
293
294 typedef enum sci_status (*SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T)(
295         struct scic_sds_remote_device *this_device,
296         u32 suspend_type);
297
298 typedef enum sci_status (*SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T)(
299         struct scic_sds_remote_device *this_device);
300
301 typedef enum sci_status (*SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T)(
302         struct scic_sds_remote_device *this_device,
303         u32 frame_index);
304
305 typedef enum sci_status (*SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T)(
306         struct scic_sds_remote_device *this_device,
307         u32 event_code);
308
309 typedef void (*SCIC_SDS_REMOTE_DEVICE_READY_NOT_READY_HANDLER_T)(
310         struct scic_sds_remote_device *this_device);
311
312 /**
313  * struct scic_sds_remote_device_state_handler - This structure conains the
314  *    state handlers that are needed to process requests for the SCU remote
315  *    device objects.
316  *
317  *
318  */
319 struct scic_sds_remote_device_state_handler {
320         struct sci_base_remote_device_state_handler parent;
321
322         SCIC_SDS_REMOTE_DEVICE_SUSPEND_HANDLER_T suspend_handler;
323         SCIC_SDS_REMOTE_DEVICE_RESUME_HANDLER_T resume_handler;
324
325         SCIC_SDS_REMOTE_DEVICE_EVENT_HANDLER_T event_handler;
326         SCIC_SDS_REMOTE_DEVICE_FRAME_HANDLER_T frame_handler;
327
328 };
329
330
331 extern const struct sci_base_state scic_sds_remote_device_state_table[];
332 extern const struct sci_base_state scic_sds_ssp_remote_device_ready_substate_table[];
333 extern const struct sci_base_state scic_sds_stp_remote_device_ready_substate_table[];
334 extern const struct sci_base_state scic_sds_smp_remote_device_ready_substate_table[];
335
336 extern struct scic_sds_remote_device_state_handler
337         scic_sds_remote_device_state_handler_table[];
338 extern struct scic_sds_remote_device_state_handler
339         scic_sds_ssp_remote_device_ready_substate_handler_table[];
340 extern struct scic_sds_remote_device_state_handler
341         scic_sds_stp_remote_device_ready_substate_handler_table[];
342 extern struct scic_sds_remote_device_state_handler
343         scic_sds_smp_remote_device_ready_substate_handler_table[];
344
345 /**
346  * scic_sds_remote_device_increment_request_count() -
347  *
348  * This macro incrments the request count for this device
349  */
350 #define scic_sds_remote_device_increment_request_count(this_device) \
351         ((this_device)->started_request_count++)
352
353 /**
354  * scic_sds_remote_device_decrement_request_count() -
355  *
356  * This macro decrements the request count for this device.  This count will
357  * never decrment past 0.
358  */
359 #define scic_sds_remote_device_decrement_request_count(this_device) \
360         ((this_device)->started_request_count > 0 ? \
361          (this_device)->started_request_count-- : 0)
362
363 /**
364  * scic_sds_remote_device_get_request_count() -
365  *
366  * This is a helper macro to return the current device request count.
367  */
368 #define scic_sds_remote_device_get_request_count(this_device) \
369         ((this_device)->started_request_count)
370
371 /**
372  * scic_sds_remote_device_get_port() -
373  *
374  * This macro returns the owning port of this remote device obejct.
375  */
376 #define scic_sds_remote_device_get_port(this_device) \
377         ((this_device)->owning_port)
378
379 /**
380  * scic_sds_remote_device_get_controller() -
381  *
382  * This macro returns the controller object that contains this device object
383  */
384 #define scic_sds_remote_device_get_controller(this_device) \
385         scic_sds_port_get_controller(scic_sds_remote_device_get_port(this_device))
386
387 /**
388  * scic_sds_remote_device_set_state_handlers() -
389  *
390  * This macro sets the remote device state handlers pointer and is set on entry
391  * to each device state.
392  */
393 #define scic_sds_remote_device_set_state_handlers(this_device, handlers) \
394         ((this_device)->state_handlers = (handlers))
395
396 /**
397  * scic_sds_remote_device_get_base_state_machine() -
398  *
399  * This macro returns the base sate machine object for the remote device.
400  */
401 #define scic_sds_remote_device_get_base_state_machine(this_device) \
402         (&(this_device)->parent.state_machine)
403
404 /**
405  * scic_sds_remote_device_get_ready_substate_machine() -
406  *
407  * This macro returns the remote device ready substate machine
408  */
409 #define scic_sds_remote_device_get_ready_substate_machine(this_device) \
410         (&(this_device)->ready_substate_machine)
411
412 /**
413  * scic_sds_remote_device_get_port() -
414  *
415  * This macro returns the owning port of this device
416  */
417 #define scic_sds_remote_device_get_port(this_device) \
418         ((this_device)->owning_port)
419
420 /**
421  * scic_sds_remote_device_get_sequence() -
422  *
423  * This macro returns the remote device sequence value
424  */
425 #define scic_sds_remote_device_get_sequence(this_device) \
426         (\
427                 scic_sds_remote_device_get_controller(this_device)-> \
428                 remote_device_sequence[(this_device)->rnc->remote_node_index] \
429         )
430
431 /**
432  * scic_sds_remote_device_get_controller_peg() -
433  *
434  * This macro returns the controllers protocol engine group
435  */
436 #define scic_sds_remote_device_get_controller_peg(this_device) \
437         (\
438                 scic_sds_controller_get_protocol_engine_group(\
439                         scic_sds_port_get_controller(\
440                                 scic_sds_remote_device_get_port(this_device) \
441                                 ) \
442                         ) \
443         )
444
445 /**
446  * scic_sds_remote_device_get_port_index() -
447  *
448  * This macro returns the port index for the devices owning port
449  */
450 #define scic_sds_remote_device_get_port_index(this_device) \
451         (scic_sds_port_get_index(scic_sds_remote_device_get_port(this_device)))
452
453 /**
454  * scic_sds_remote_device_get_index() -
455  *
456  * This macro returns the remote node index for this device object
457  */
458 #define scic_sds_remote_device_get_index(this_device) \
459         ((this_device)->rnc->remote_node_index)
460
461 /**
462  * scic_sds_remote_device_build_command_context() -
463  *
464  * This macro builds a remote device context for the SCU post request operation
465  */
466 #define scic_sds_remote_device_build_command_context(device, command) \
467         ((command) \
468          | (scic_sds_remote_device_get_controller_peg((device)) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) \
469          | (scic_sds_remote_device_get_port_index((device)) << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
470          | (scic_sds_remote_device_get_index((device))) \
471         )
472
473 /**
474  * scic_sds_remote_device_set_working_request() -
475  *
476  * This macro makes the working request assingment for the remote device
477  * object. To clear the working request use this macro with a NULL request
478  * object.
479  */
480 #define scic_sds_remote_device_set_working_request(device, request) \
481         ((device)->working_request = (request))
482
483 /* --------------------------------------------------------------------------- */
484
485
486
487 enum sci_status scic_sds_remote_device_frame_handler(
488         struct scic_sds_remote_device *this_device,
489         u32 frame_index);
490
491 enum sci_status scic_sds_remote_device_event_handler(
492         struct scic_sds_remote_device *this_device,
493         u32 event_code);
494
495 enum sci_status scic_sds_remote_device_start_io(
496         struct scic_sds_controller *controller,
497         struct scic_sds_remote_device *this_device,
498         struct scic_sds_request *io_request);
499
500 enum sci_status scic_sds_remote_device_complete_io(
501         struct scic_sds_controller *controller,
502         struct scic_sds_remote_device *this_device,
503         struct scic_sds_request *io_request);
504
505 enum sci_status scic_sds_remote_device_resume(
506         struct scic_sds_remote_device *this_device);
507
508 enum sci_status scic_sds_remote_device_suspend(
509         struct scic_sds_remote_device *this_device,
510         u32 suspend_type);
511
512 enum sci_status scic_sds_remote_device_start_task(
513         struct scic_sds_controller *controller,
514         struct scic_sds_remote_device *this_device,
515         struct scic_sds_request *io_request);
516
517 void scic_sds_remote_device_post_request(
518         struct scic_sds_remote_device *this_device,
519         u32 request);
520
521 #if !defined(DISABLE_ATAPI)
522 bool scic_sds_remote_device_is_atapi(
523         struct scic_sds_remote_device *this_device);
524 #else /* !defined(DISABLE_ATAPI) */
525 #define scic_sds_remote_device_is_atapi(this_device) false
526 #endif /* !defined(DISABLE_ATAPI) */
527
528 /* --------------------------------------------------------------------------- */
529
530 /* --------------------------------------------------------------------------- */
531
532 void scic_sds_remote_device_start_request(
533         struct scic_sds_remote_device *this_device,
534         struct scic_sds_request *the_request,
535         enum sci_status status);
536
537 void scic_sds_remote_device_continue_request(
538         struct scic_sds_remote_device *this_device);
539
540 enum sci_status scic_sds_remote_device_default_start_handler(
541         struct sci_base_remote_device *this_device);
542
543
544 enum sci_status scic_sds_remote_device_default_fail_handler(
545         struct sci_base_remote_device *this_device);
546
547 enum sci_status scic_sds_remote_device_default_destruct_handler(
548         struct sci_base_remote_device *this_device);
549
550 enum sci_status scic_sds_remote_device_default_reset_handler(
551         struct sci_base_remote_device *device);
552
553 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
554         struct sci_base_remote_device *device);
555
556 enum sci_status scic_sds_remote_device_default_start_request_handler(
557         struct sci_base_remote_device *device,
558         struct sci_base_request *request);
559
560 enum sci_status scic_sds_remote_device_default_complete_request_handler(
561         struct sci_base_remote_device *device,
562         struct sci_base_request *request);
563
564 enum sci_status scic_sds_remote_device_default_continue_request_handler(
565         struct sci_base_remote_device *device,
566         struct sci_base_request *request);
567
568 enum sci_status scic_sds_remote_device_default_suspend_handler(
569         struct scic_sds_remote_device *this_device,
570         u32 suspend_type);
571
572 enum sci_status scic_sds_remote_device_default_resume_handler(
573         struct scic_sds_remote_device *this_device);
574
575
576 enum sci_status scic_sds_remote_device_default_frame_handler(
577         struct scic_sds_remote_device *this_device,
578         u32 frame_index);
579
580 /* --------------------------------------------------------------------------- */
581
582 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
583         struct sci_base_remote_device *device);
584
585 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
586         struct sci_base_remote_device *device);
587
588 enum sci_status scic_sds_remote_device_general_frame_handler(
589         struct scic_sds_remote_device *this_device,
590         u32 frame_index);
591
592 enum sci_status scic_sds_remote_device_general_event_handler(
593         struct scic_sds_remote_device *this_device,
594         u32 event_code);
595
596 enum sci_status scic_sds_ssp_remote_device_ready_suspended_substate_resume_handler(
597         struct scic_sds_remote_device *this_device);
598
599 /* --------------------------------------------------------------------------- */
600
601
602 #endif /* _SCIC_SDS_REMOTE_DEVICE_H_ */