isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[linux-flexiantxendom0-3.2.10.git] / drivers / scsi / isci / core / scic_sds_phy.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_PHY_H_
57 #define _SCIC_SDS_PHY_H_
58
59 /**
60  * This file contains the structures, constants and prototypes for the
61  *    struct scic_sds_phy object.
62  *
63  *
64  */
65
66 #include "intel_sata.h"
67 #include "intel_sas.h"
68 #include "sci_base_phy.h"
69 #include "scu_registers.h"
70
71 struct scic_sds_port;
72 /**
73  *
74  *
75  * This is the timeout value for the SATA phy to wait for a SIGNATURE FIS
76  * before restarting the starting state machine.  Technically, the old parallel
77  * ATA specification required up to 30 seconds for a device to issue its
78  * signature FIS as a result of a soft reset.  Now we see that devices respond
79  * generally within 15 seconds, but we'll use 25 for now.
80  */
81 #define SCIC_SDS_SIGNATURE_FIS_TIMEOUT    25000
82
83 /**
84  *
85  *
86  * This is the timeout for the SATA OOB/SN because the hardware does not
87  * recognize a hot plug after OOB signal but before the SN signals.  We need to
88  * make sure after a hotplug timeout if we have not received the speed event
89  * notification from the hardware that we restart the hardware OOB state
90  * machine.
91  */
92 #define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT  250
93
94 /**
95  * enum SCIC_SDS_PHY_STARTING_SUBSTATES -
96  *
97  *
98  */
99 enum SCIC_SDS_PHY_STARTING_SUBSTATES {
100         /**
101          * Initial state
102          */
103         SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL,
104
105         /**
106          * Wait state for the hardware OSSP event type notification
107          */
108         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN,
109
110         /**
111          * Wait state for the PHY speed notification
112          */
113         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN,
114
115         /**
116          * Wait state for the IAF Unsolicited frame notification
117          */
118         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF,
119
120         /**
121          * Wait state for the request to consume power
122          */
123         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER,
124
125         /**
126          * Wait state for request to consume power
127          */
128         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER,
129
130         /**
131          * Wait state for the SATA PHY notification
132          */
133         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN,
134
135         /**
136          * Wait for the SATA PHY speed notification
137          */
138         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN,
139
140         /**
141          * Wait state for the SIGNATURE FIS unsolicited frame notification
142          */
143         SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF,
144
145         /**
146          * Exit state for this state machine
147          */
148         SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL,
149
150         /**
151          * Maximum number of substates for the STARTING state machine
152          */
153         SCIC_SDS_PHY_STARTING_MAX_SUBSTATES
154 };
155
156 struct scic_sds_port;
157 struct scic_sds_controller;
158
159 #ifdef SCIC_DEBUG_ENABLED
160 #define MAX_STATE_TRANSITION_RECORD    (256)
161
162 /**
163  *
164  *
165  * Debug code to record the state transitions for the phy object
166  */
167 struct scic_sds_phy_state_record {
168         struct sci_base_observer base_state_observer;
169         struct sci_base_observer starting_state_observer;
170
171         u16 index;
172
173         u32 state_transition_table[MAX_STATE_TRANSITION_RECORD];
174
175 };
176 #endif /* SCIC_DEBUG_ENABLED */
177
178 /**
179  * This enumeration provides a named phy type for the state machine
180  *
181  *
182  */
183 enum SCIC_SDS_PHY_PROTOCOL {
184         /**
185          * This is an unknown phy type since there is either nothing on the other
186          * end or we have not detected the phy type as yet.
187          */
188         SCIC_SDS_PHY_PROTOCOL_UNKNOWN,
189
190         /**
191          * This is a SAS PHY
192          */
193         SCIC_SDS_PHY_PROTOCOL_SAS,
194
195         /**
196          * This is a SATA PHY
197          */
198         SCIC_SDS_PHY_PROTOCOL_SATA,
199
200         SCIC_SDS_MAX_PHY_PROTOCOLS
201 };
202
203 /**
204  * struct scic_sds_phy - This structure  contains or references all of the data
205  *    necessary to represent the core phy object and SCU harware protocol
206  *    engine.
207  *
208  *
209  */
210 struct scic_sds_phy {
211         struct sci_base_phy parent;
212
213         /**
214          * This field specifies the port object that owns/contains this phy.
215          */
216         struct scic_sds_port *owning_port;
217
218         /**
219          * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
220          * or 6.0 Gb/s operation.
221          */
222         enum sci_sas_link_rate max_negotiated_speed;
223
224         /**
225          * This member specifies the protocol being utilized on this phy.  This
226          * field contains a legitamite value once the PHY has link trained with
227          * a remote phy.
228          */
229         enum SCIC_SDS_PHY_PROTOCOL protocol;
230
231         /**
232          * This field specifies the index with which this phy is associated (0-3).
233          */
234         u8 phy_index;
235
236         /**
237          * This member indicates if this particular PHY has received a BCN while
238          * it had no port assignement.  This BCN will be reported once the phy is
239          * assigned to a port.
240          */
241         bool bcn_received_while_port_unassigned;
242
243         /**
244          * This field indicates if this PHY is currently in the process of
245          * link training (i.e. it has started OOB, but has yet to perform
246          * IAF exchange/Signature FIS reception).
247          */
248         bool is_in_link_training;
249
250         union {
251                 struct {
252                         struct sci_sas_identify_address_frame identify_address_frame_buffer;
253
254                 } sas;
255
256                 struct {
257                         struct sata_fis_reg_d2h signature_fis_buffer;
258
259                 } sata;
260
261         } phy_type;
262
263         /**
264          * This field contains a reference to the timer utilized in detecting
265          * when a signature FIS timeout has occurred.  The signature FIS is the
266          * first FIS sent by an attached SATA device after OOB/SN.
267          */
268         void *sata_timeout_timer;
269
270         struct scic_sds_phy_state_handler *state_handlers;
271
272         struct sci_base_state_machine starting_substate_machine;
273
274    #ifdef SCIC_DEBUG_ENABLED
275         struct scic_sds_phy_state_record state_record;
276    #endif /* SCIC_DEBUG_ENABLED */
277
278         /**
279          * This field points to the link layer register set within the SCU.
280          */
281         struct scu_link_layer_registers *link_layer_registers;
282
283 };
284
285
286 typedef enum sci_status (*SCIC_SDS_PHY_EVENT_HANDLER_T)(struct scic_sds_phy *, u32);
287 typedef enum sci_status (*SCIC_SDS_PHY_FRAME_HANDLER_T)(struct scic_sds_phy *, u32);
288 typedef enum sci_status (*SCIC_SDS_PHY_POWER_HANDLER_T)(struct scic_sds_phy *);
289
290 /**
291  * struct scic_sds_phy_state_handler -
292  *
293  *
294  */
295 struct scic_sds_phy_state_handler {
296         /**
297          * This is the struct sci_base_phy object state handlers.
298          */
299         struct sci_base_phy_state_handler parent;
300
301         /**
302          * The state handler for unsolicited frames received from the SCU hardware.
303          */
304         SCIC_SDS_PHY_FRAME_HANDLER_T frame_handler;
305
306         /**
307          * The state handler for events received from the SCU hardware.
308          */
309         SCIC_SDS_PHY_EVENT_HANDLER_T event_handler;
310
311         /**
312          * The state handler for staggered spinup.
313          */
314         SCIC_SDS_PHY_POWER_HANDLER_T consume_power_handler;
315
316 };
317
318 extern struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[];
319 extern const struct sci_base_state scic_sds_phy_state_table[];
320 extern const struct sci_base_state scic_sds_phy_starting_substates[];
321 extern struct scic_sds_phy_state_handler
322         scic_sds_phy_starting_substate_handler_table[];
323
324
325 /**
326  * scic_sds_phy_get_index() -
327  *
328  * This macro returns the phy index for the specified phy
329  */
330 #define scic_sds_phy_get_index(phy) \
331         ((phy)->phy_index)
332
333 /**
334  * scic_sds_phy_get_controller() - This macro returns the controller for this
335  *    phy
336  *
337  *
338  */
339 #define scic_sds_phy_get_controller(phy) \
340         (scic_sds_port_get_controller((phy)->owning_port))
341
342 /**
343  * scic_sds_phy_get_base_state_machine() - This macro returns the state machine
344  *    for the base phy
345  *
346  *
347  */
348 #define scic_sds_phy_get_base_state_machine(phy) \
349         (&(phy)->parent.state_machine)
350
351 /**
352  * scic_sds_phy_get_starting_substate_machine() - This macro returns the
353  *    starting substate machine for this phy
354  *
355  *
356  */
357 #define scic_sds_phy_get_starting_substate_machine(phy) \
358         (&(phy)->starting_substate_machine)
359
360 /**
361  * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
362  *    this phy object
363  *
364  *
365  */
366 #define scic_sds_phy_set_state_handlers(phy, handlers) \
367         ((phy)->state_handlers = (handlers))
368
369 /**
370  * scic_sds_phy_set_base_state_handlers() -
371  *
372  * This macro set the base state handlers for the phy object.
373  */
374 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
375         scic_sds_phy_set_state_handlers(\
376                 (phy), \
377                 &scic_sds_phy_state_handler_table[(state_id)] \
378                 )
379
380 /**
381  * scic_sds_phy_is_ready() -
382  *
383  * This macro returns true if the current base state for this phy is
384  * SCI_BASE_PHY_STATE_READY
385  */
386 #define scic_sds_phy_is_ready(phy) \
387         (\
388                 SCI_BASE_PHY_STATE_READY \
389                 == sci_base_state_machine_get_state(\
390                         scic_sds_phy_get_base_state_machine(phy) \
391                         ) \
392         )
393
394 /* --------------------------------------------------------------------------- */
395
396
397
398
399 /* --------------------------------------------------------------------------- */
400
401 void scic_sds_phy_construct(
402         struct scic_sds_phy *this_phy,
403         struct scic_sds_port *owning_port,
404         u8 phy_index);
405
406 struct scic_sds_port *scic_sds_phy_get_port(
407         struct scic_sds_phy *this_phy);
408
409 void scic_sds_phy_set_port(
410         struct scic_sds_phy *this_phy,
411         struct scic_sds_port *owning_port);
412
413 enum sci_status scic_sds_phy_initialize(
414         struct scic_sds_phy *this_phy,
415         struct scu_link_layer_registers *link_layer_registers);
416
417 enum sci_status scic_sds_phy_start(
418         struct scic_sds_phy *this_phy);
419
420 enum sci_status scic_sds_phy_stop(
421         struct scic_sds_phy *this_phy);
422
423 enum sci_status scic_sds_phy_reset(
424         struct scic_sds_phy *this_phy);
425
426 /* --------------------------------------------------------------------------- */
427
428 void scic_sds_phy_suspend(
429         struct scic_sds_phy *this_phy);
430
431 void scic_sds_phy_resume(
432         struct scic_sds_phy *this_phy);
433
434 /* --------------------------------------------------------------------------- */
435
436 enum sci_status scic_sds_phy_event_handler(
437         struct scic_sds_phy *this_phy,
438         u32 event_code);
439
440 enum sci_status scic_sds_phy_frame_handler(
441         struct scic_sds_phy *this_phy,
442         u32 frame_index);
443
444 enum sci_status scic_sds_phy_consume_power_handler(
445         struct scic_sds_phy *this_phy);
446
447 void scic_sds_phy_get_sas_address(
448         struct scic_sds_phy *this_phy,
449         struct sci_sas_address *sas_address);
450
451 void scic_sds_phy_get_attached_sas_address(
452         struct scic_sds_phy *this_phy,
453         struct sci_sas_address *sas_address);
454
455 void scic_sds_phy_get_protocols(
456         struct scic_sds_phy *this_phy,
457         struct sci_sas_identify_address_frame_protocols *protocols);
458
459 void scic_sds_phy_get_attached_phy_protocols(
460         struct scic_sds_phy *this_phy,
461         struct sci_sas_identify_address_frame_protocols *protocols);
462
463 /*
464  * ****************************************************************************-
465  * * SCIC SDS PHY Handler Methods
466  * ****************************************************************************- */
467
468 enum sci_status scic_sds_phy_default_start_handler(
469         struct sci_base_phy *phy);
470
471 enum sci_status scic_sds_phy_default_stop_handler(
472         struct sci_base_phy *phy);
473
474 enum sci_status scic_sds_phy_default_reset_handler(
475         struct sci_base_phy *phy);
476
477 enum sci_status scic_sds_phy_default_destroy_handler(
478         struct sci_base_phy *phy);
479
480 enum sci_status scic_sds_phy_default_frame_handler(
481         struct scic_sds_phy *phy,
482         u32 frame_index);
483
484 enum sci_status scic_sds_phy_default_event_handler(
485         struct scic_sds_phy *phy,
486         u32 evnet_code);
487
488 enum sci_status scic_sds_phy_default_consume_power_handler(
489         struct scic_sds_phy *phy);
490
491 #endif /* _SCIC_SDS_PHY_H_ */