isci: remove base_request abstraction
[firefly-linux-kernel-4.4.55.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 "scu_remote_node_context.h"
69 #include "scic_sds_remote_node_context.h"
70
71 struct scic_sds_controller;
72 struct scic_sds_port;
73 struct scic_sds_request;
74 struct scic_sds_remote_device_state_handler;
75
76 /**
77  * enum scic_sds_ssp_remote_device_ready_substates -
78  *
79  * This is the enumeration of the ready substates for the
80  * struct scic_sds_remote_device.
81  */
82 enum scic_sds_ssp_remote_device_ready_substates {
83         /**
84          * This is the initial state for the remote device ready substate.
85          */
86         SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_INITIAL,
87
88         /**
89          * This is the ready operational substate for the remote device.
90          * This is the normal operational state for a remote device.
91          */
92         SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_OPERATIONAL,
93
94         /**
95          * This is the suspended state for the remote device. This is the state
96          * that the device is placed in when a RNC suspend is received by
97          * 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
103          * to the 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
114  * for 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
162 /**
163  * enum scic_sds_smp_remote_device_ready_substates -
164  *
165  * This is the enumeration of the ready substates for the SMP REMOTE DEVICE.
166  */
167 enum scic_sds_smp_remote_device_ready_substates {
168         /**
169          * This is the ready operational substate for the remote device.  This is the
170          * normal operational state for a remote device.
171          */
172         SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE,
173
174         /**
175          * This is the suspended state for the remote device.  This is the state that
176          * the device is placed in when a RNC suspend is received by the SCU hardware.
177          */
178         SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD,
179 };
180
181 /**
182  * struct scic_sds_remote_device - This structure contains the data for an SCU
183  *    implementation of the SCU Core device data.
184  *
185  *
186  */
187 struct scic_sds_remote_device {
188         /**
189          * This field is the common base for all remote device objects.
190          */
191         struct sci_base_remote_device parent;
192
193         /**
194          * This field is the programmed device port width.  This value is written to
195          * the RCN data structure to tell the SCU how many open connections this
196          * device can have.
197          */
198         u32 device_port_width;
199
200         /**
201          * This field is the programmed connection rate for this remote device.  It is
202          * used to program the TC with the maximum allowed connection rate.
203          */
204         enum sci_sas_link_rate connection_rate;
205
206         /**
207          * This field contains the allowed target protocols for this remote device.
208          */
209         struct smp_discover_response_protocols target_protocols;
210
211         /**
212          * This field contains the device SAS address.
213          */
214         struct sci_sas_address device_address;
215
216         /**
217          * This filed is assinged the value of true if the device is directly
218          * attached to the port.
219          */
220         bool is_direct_attached;
221
222 #if !defined(DISABLE_ATAPI)
223         /**
224          * This filed is assinged the value of true if the device is an ATAPI
225          * device.
226          */
227         bool is_atapi;
228 #endif
229
230         /**
231          * This filed contains a pointer back to the port to which this device
232          * is assigned.
233          */
234         struct scic_sds_port *owning_port;
235
236         /**
237          * This field contains the SCU silicon remote node context specific
238          * information.
239          */
240         struct scic_sds_remote_node_context *rnc;
241
242         /**
243          * This field contains the stated request count for the remote device.  The
244          * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all
245          * requests are complete and the rnc_posted value is false.
246          */
247         u32 started_request_count;
248
249         /**
250          * This field contains a pointer to the working request object.  It is only
251          * used only for SATA requests since the unsolicited frames we get from the
252          * hardware have no Tag value to look up the io request object.
253          */
254         struct scic_sds_request *working_request;
255
256         /**
257          * This field contains the reason for the remote device going not_ready.  It is
258          * assigned in the state handlers and used in the state transition.
259          */
260         u32 not_ready_reason;
261
262         /**
263          * This field is true if this remote device has an initialzied ready substate
264          * machine. SSP devices do not have a ready substate machine and STP devices
265          * have a ready substate machine.
266          */
267         bool has_ready_substate_machine;
268
269         /**
270          * This field contains the state machine for the ready substate machine for
271          * this struct scic_sds_remote_device object.
272          */
273         struct sci_base_state_machine ready_substate_machine;
274
275         /**
276          * This field maintains the set of state handlers for the remote device
277          * object.  These are changed each time the remote device enters a new state.
278          */
279         const struct scic_sds_remote_device_state_handler *state_handlers;
280 };
281
282 typedef enum sci_status (*scic_sds_remote_device_handler_t)(
283         struct scic_sds_remote_device *this_device);
284
285 typedef enum sci_status (*scic_sds_remote_device_suspend_handler_t)(
286         struct scic_sds_remote_device *this_device,
287         u32 suspend_type);
288
289 typedef enum sci_status (*scic_sds_remote_device_resume_handler_t)(
290         struct scic_sds_remote_device *this_device);
291
292 typedef enum sci_status (*scic_sds_remote_device_frame_handler_t)(
293         struct scic_sds_remote_device *this_device,
294         u32 frame_index);
295
296 typedef enum sci_status (*scic_sds_remote_device_event_handler_t)(
297         struct scic_sds_remote_device *this_device,
298         u32 event_code);
299
300 typedef void (*scic_sds_remote_device_ready_not_ready_handler_t)(
301         struct scic_sds_remote_device *this_device);
302
303 /**
304  * struct scic_sds_remote_device_state_handler - This structure conains the
305  *    state handlers that are needed to process requests for the SCU remote
306  *    device objects.
307  *
308  *
309  */
310 struct scic_sds_remote_device_state_handler {
311         struct sci_base_remote_device_state_handler parent;
312         scic_sds_remote_device_suspend_handler_t suspend_handler;
313         scic_sds_remote_device_resume_handler_t resume_handler;
314         scic_sds_remote_device_event_handler_t event_handler;
315         scic_sds_remote_device_frame_handler_t frame_handler;
316 };
317
318 extern const struct sci_base_state scic_sds_ssp_remote_device_ready_substate_table[];
319 extern const struct sci_base_state scic_sds_stp_remote_device_ready_substate_table[];
320 extern const struct sci_base_state scic_sds_smp_remote_device_ready_substate_table[];
321
322 /**
323  * scic_sds_remote_device_increment_request_count() -
324  *
325  * This macro incrments the request count for this device
326  */
327 #define scic_sds_remote_device_increment_request_count(this_device) \
328         ((this_device)->started_request_count++)
329
330 /**
331  * scic_sds_remote_device_decrement_request_count() -
332  *
333  * This macro decrements the request count for this device.  This count will
334  * never decrment past 0.
335  */
336 #define scic_sds_remote_device_decrement_request_count(this_device) \
337         ((this_device)->started_request_count > 0 ? \
338          (this_device)->started_request_count-- : 0)
339
340 /**
341  * scic_sds_remote_device_get_request_count() -
342  *
343  * This is a helper macro to return the current device request count.
344  */
345 #define scic_sds_remote_device_get_request_count(this_device) \
346         ((this_device)->started_request_count)
347
348 /**
349  * scic_sds_remote_device_get_port() -
350  *
351  * This macro returns the owning port of this remote device obejct.
352  */
353 #define scic_sds_remote_device_get_port(this_device) \
354         ((this_device)->owning_port)
355
356 /**
357  * scic_sds_remote_device_get_controller() -
358  *
359  * This macro returns the controller object that contains this device object
360  */
361 #define scic_sds_remote_device_get_controller(this_device) \
362         scic_sds_port_get_controller(scic_sds_remote_device_get_port(this_device))
363
364 /**
365  * scic_sds_remote_device_set_state_handlers() -
366  *
367  * This macro sets the remote device state handlers pointer and is set on entry
368  * to each device state.
369  */
370 #define scic_sds_remote_device_set_state_handlers(this_device, handlers) \
371         ((this_device)->state_handlers = (handlers))
372
373 /**
374  * scic_sds_remote_device_get_port() -
375  *
376  * This macro returns the owning port of this device
377  */
378 #define scic_sds_remote_device_get_port(this_device) \
379         ((this_device)->owning_port)
380
381 /**
382  * scic_sds_remote_device_get_sequence() -
383  *
384  * This macro returns the remote device sequence value
385  */
386 #define scic_sds_remote_device_get_sequence(this_device) \
387         (\
388                 scic_sds_remote_device_get_controller(this_device)-> \
389                 remote_device_sequence[(this_device)->rnc->remote_node_index] \
390         )
391
392 /**
393  * scic_sds_remote_device_get_controller_peg() -
394  *
395  * This macro returns the controllers protocol engine group
396  */
397 #define scic_sds_remote_device_get_controller_peg(this_device) \
398         (\
399                 scic_sds_controller_get_protocol_engine_group(\
400                         scic_sds_port_get_controller(\
401                                 scic_sds_remote_device_get_port(this_device) \
402                                 ) \
403                         ) \
404         )
405
406 /**
407  * scic_sds_remote_device_get_port_index() -
408  *
409  * This macro returns the port index for the devices owning port
410  */
411 #define scic_sds_remote_device_get_port_index(this_device) \
412         (scic_sds_port_get_index(scic_sds_remote_device_get_port(this_device)))
413
414 /**
415  * scic_sds_remote_device_get_index() -
416  *
417  * This macro returns the remote node index for this device object
418  */
419 #define scic_sds_remote_device_get_index(this_device) \
420         ((this_device)->rnc->remote_node_index)
421
422 /**
423  * scic_sds_remote_device_build_command_context() -
424  *
425  * This macro builds a remote device context for the SCU post request operation
426  */
427 #define scic_sds_remote_device_build_command_context(device, command) \
428         ((command) \
429          | (scic_sds_remote_device_get_controller_peg((device)) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) \
430          | (scic_sds_remote_device_get_port_index((device)) << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \
431          | (scic_sds_remote_device_get_index((device))) \
432         )
433
434 /**
435  * scic_sds_remote_device_set_working_request() -
436  *
437  * This macro makes the working request assingment for the remote device
438  * object. To clear the working request use this macro with a NULL request
439  * object.
440  */
441 #define scic_sds_remote_device_set_working_request(device, request) \
442         ((device)->working_request = (request))
443
444 enum sci_status scic_sds_remote_device_frame_handler(
445         struct scic_sds_remote_device *this_device,
446         u32 frame_index);
447
448 enum sci_status scic_sds_remote_device_event_handler(
449         struct scic_sds_remote_device *this_device,
450         u32 event_code);
451
452 enum sci_status scic_sds_remote_device_start_io(
453         struct scic_sds_controller *controller,
454         struct scic_sds_remote_device *this_device,
455         struct scic_sds_request *io_request);
456
457 enum sci_status scic_sds_remote_device_complete_io(
458         struct scic_sds_controller *controller,
459         struct scic_sds_remote_device *this_device,
460         struct scic_sds_request *io_request);
461
462 enum sci_status scic_sds_remote_device_resume(
463         struct scic_sds_remote_device *this_device);
464
465 enum sci_status scic_sds_remote_device_suspend(
466         struct scic_sds_remote_device *this_device,
467         u32 suspend_type);
468
469 enum sci_status scic_sds_remote_device_start_task(
470         struct scic_sds_controller *controller,
471         struct scic_sds_remote_device *this_device,
472         struct scic_sds_request *io_request);
473
474 void scic_sds_remote_device_post_request(
475         struct scic_sds_remote_device *this_device,
476         u32 request);
477
478 #if !defined(DISABLE_ATAPI)
479 bool scic_sds_remote_device_is_atapi(
480         struct scic_sds_remote_device *this_device);
481 #else /* !defined(DISABLE_ATAPI) */
482 #define scic_sds_remote_device_is_atapi(this_device) false
483 #endif /* !defined(DISABLE_ATAPI) */
484
485 void scic_sds_remote_device_start_request(
486         struct scic_sds_remote_device *this_device,
487         struct scic_sds_request *the_request,
488         enum sci_status status);
489
490 void scic_sds_remote_device_continue_request(void *sci_dev);
491
492 enum sci_status scic_sds_remote_device_default_start_handler(
493         struct sci_base_remote_device *this_device);
494
495 enum sci_status scic_sds_remote_device_default_fail_handler(
496         struct sci_base_remote_device *this_device);
497
498 enum sci_status scic_sds_remote_device_default_destruct_handler(
499         struct sci_base_remote_device *this_device);
500
501 enum sci_status scic_sds_remote_device_default_reset_handler(
502         struct sci_base_remote_device *device);
503
504 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
505         struct sci_base_remote_device *device);
506
507 enum sci_status scic_sds_remote_device_default_start_request_handler(
508         struct sci_base_remote_device *device,
509         struct scic_sds_request *request);
510
511 enum sci_status scic_sds_remote_device_default_complete_request_handler(
512         struct sci_base_remote_device *device,
513         struct scic_sds_request *request);
514
515 enum sci_status scic_sds_remote_device_default_continue_request_handler(
516         struct sci_base_remote_device *device,
517         struct scic_sds_request *request);
518
519 enum sci_status scic_sds_remote_device_default_suspend_handler(
520         struct scic_sds_remote_device *this_device,
521         u32 suspend_type);
522
523 enum sci_status scic_sds_remote_device_default_resume_handler(
524         struct scic_sds_remote_device *this_device);
525
526
527 enum sci_status scic_sds_remote_device_default_frame_handler(
528         struct scic_sds_remote_device *this_device,
529         u32 frame_index);
530
531 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
532         struct sci_base_remote_device *device);
533
534 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
535         struct sci_base_remote_device *device);
536
537 enum sci_status scic_sds_remote_device_general_frame_handler(
538         struct scic_sds_remote_device *this_device,
539         u32 frame_index);
540
541 enum sci_status scic_sds_remote_device_general_event_handler(
542         struct scic_sds_remote_device *this_device,
543         u32 event_code);
544
545 enum sci_status scic_sds_ssp_remote_device_ready_suspended_substate_resume_handler(
546         struct scic_sds_remote_device *this_device);
547
548 #endif /* _SCIC_SDS_REMOTE_DEVICE_H_ */