isci: Remove "screaming" data types
[pandora-kernel.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 struct scic_sds_port;
152 struct scic_sds_controller;
153
154 /**
155  * This enumeration provides a named phy type for the state machine
156  *
157  *
158  */
159 enum scic_sds_phy_protocol {
160         /**
161          * This is an unknown phy type since there is either nothing on the other
162          * end or we have not detected the phy type as yet.
163          */
164         SCIC_SDS_PHY_PROTOCOL_UNKNOWN,
165
166         /**
167          * This is a SAS PHY
168          */
169         SCIC_SDS_PHY_PROTOCOL_SAS,
170
171         /**
172          * This is a SATA PHY
173          */
174         SCIC_SDS_PHY_PROTOCOL_SATA,
175
176         SCIC_SDS_MAX_PHY_PROTOCOLS
177 };
178
179 /**
180  * struct scic_sds_phy - This structure  contains or references all of the data
181  *    necessary to represent the core phy object and SCU harware protocol
182  *    engine.
183  *
184  *
185  */
186 struct scic_sds_phy {
187         struct sci_base_phy parent;
188
189         /**
190          * This field specifies the port object that owns/contains this phy.
191          */
192         struct scic_sds_port *owning_port;
193
194         /**
195          * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
196          * or 6.0 Gb/s operation.
197          */
198         enum sci_sas_link_rate max_negotiated_speed;
199
200         /**
201          * This member specifies the protocol being utilized on this phy.  This
202          * field contains a legitamite value once the PHY has link trained with
203          * a remote phy.
204          */
205         enum scic_sds_phy_protocol protocol;
206
207         /**
208          * This field specifies the index with which this phy is associated (0-3).
209          */
210         u8 phy_index;
211
212         /**
213          * This member indicates if this particular PHY has received a BCN while
214          * it had no port assignement.  This BCN will be reported once the phy is
215          * assigned to a port.
216          */
217         bool bcn_received_while_port_unassigned;
218
219         /**
220          * This field indicates if this PHY is currently in the process of
221          * link training (i.e. it has started OOB, but has yet to perform
222          * IAF exchange/Signature FIS reception).
223          */
224         bool is_in_link_training;
225
226         union {
227                 struct {
228                         struct sci_sas_identify_address_frame identify_address_frame_buffer;
229
230                 } sas;
231
232                 struct {
233                         struct sata_fis_reg_d2h signature_fis_buffer;
234
235                 } sata;
236
237         } phy_type;
238
239         /**
240          * This field contains a reference to the timer utilized in detecting
241          * when a signature FIS timeout has occurred.  The signature FIS is the
242          * first FIS sent by an attached SATA device after OOB/SN.
243          */
244         void *sata_timeout_timer;
245
246         const struct scic_sds_phy_state_handler *state_handlers;
247
248         struct sci_base_state_machine starting_substate_machine;
249
250         /**
251          * This field is the pointer to the transport layer register for the SCU
252          * hardware.
253          */
254         struct scu_transport_layer_registers __iomem *transport_layer_registers;
255
256         /**
257          * This field points to the link layer register set within the SCU.
258          */
259         struct scu_link_layer_registers __iomem *link_layer_registers;
260
261 };
262
263
264 typedef enum sci_status (*scic_sds_phy_event_handler_t)(struct scic_sds_phy *, u32);
265 typedef enum sci_status (*scic_sds_phy_frame_handler_t)(struct scic_sds_phy *, u32);
266 typedef enum sci_status (*scic_sds_phy_power_handler_t)(struct scic_sds_phy *);
267
268 /**
269  * struct scic_sds_phy_state_handler -
270  *
271  *
272  */
273 struct scic_sds_phy_state_handler {
274         /**
275          * This is the struct sci_base_phy object state handlers.
276          */
277         struct sci_base_phy_state_handler parent;
278
279         /**
280          * The state handler for unsolicited frames received from the SCU hardware.
281          */
282         scic_sds_phy_frame_handler_t frame_handler;
283
284         /**
285          * The state handler for events received from the SCU hardware.
286          */
287         scic_sds_phy_event_handler_t event_handler;
288
289         /**
290          * The state handler for staggered spinup.
291          */
292         scic_sds_phy_power_handler_t consume_power_handler;
293
294 };
295
296 /**
297  * scic_sds_phy_get_index() -
298  *
299  * This macro returns the phy index for the specified phy
300  */
301 #define scic_sds_phy_get_index(phy) \
302         ((phy)->phy_index)
303
304 /**
305  * scic_sds_phy_get_controller() - This macro returns the controller for this
306  *    phy
307  *
308  *
309  */
310 #define scic_sds_phy_get_controller(phy) \
311         (scic_sds_port_get_controller((phy)->owning_port))
312
313 /**
314  * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
315  *    this phy object
316  *
317  *
318  */
319 #define scic_sds_phy_set_state_handlers(phy, handlers) \
320         ((phy)->state_handlers = (handlers))
321
322 /**
323  * scic_sds_phy_set_base_state_handlers() -
324  *
325  * This macro set the base state handlers for the phy object.
326  */
327 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
328         scic_sds_phy_set_state_handlers(\
329                 (phy), \
330                 &scic_sds_phy_state_handler_table[(state_id)] \
331                 )
332
333 void scic_sds_phy_construct(
334         struct scic_sds_phy *this_phy,
335         struct scic_sds_port *owning_port,
336         u8 phy_index);
337
338 struct scic_sds_port *scic_sds_phy_get_port(
339         struct scic_sds_phy *this_phy);
340
341 void scic_sds_phy_set_port(
342         struct scic_sds_phy *this_phy,
343         struct scic_sds_port *owning_port);
344
345 enum sci_status scic_sds_phy_initialize(
346         struct scic_sds_phy *this_phy,
347         struct scu_transport_layer_registers __iomem *transport_layer_registers,
348         struct scu_link_layer_registers __iomem *link_layer_registers);
349
350 enum sci_status scic_sds_phy_start(
351         struct scic_sds_phy *this_phy);
352
353 enum sci_status scic_sds_phy_stop(
354         struct scic_sds_phy *this_phy);
355
356 enum sci_status scic_sds_phy_reset(
357         struct scic_sds_phy *this_phy);
358
359 void scic_sds_phy_resume(
360         struct scic_sds_phy *this_phy);
361
362 void scic_sds_phy_setup_transport(
363         struct scic_sds_phy *this_phy,
364         u32 device_id);
365
366 enum sci_status scic_sds_phy_event_handler(
367         struct scic_sds_phy *this_phy,
368         u32 event_code);
369
370 enum sci_status scic_sds_phy_frame_handler(
371         struct scic_sds_phy *this_phy,
372         u32 frame_index);
373
374 enum sci_status scic_sds_phy_consume_power_handler(
375         struct scic_sds_phy *this_phy);
376
377 void scic_sds_phy_get_sas_address(
378         struct scic_sds_phy *this_phy,
379         struct sci_sas_address *sas_address);
380
381 void scic_sds_phy_get_attached_sas_address(
382         struct scic_sds_phy *this_phy,
383         struct sci_sas_address *sas_address);
384
385 void scic_sds_phy_get_protocols(
386         struct scic_sds_phy *this_phy,
387         struct sci_sas_identify_address_frame_protocols *protocols);
388
389 void scic_sds_phy_get_attached_phy_protocols(
390         struct scic_sds_phy *this_phy,
391         struct sci_sas_identify_address_frame_protocols *protocols);
392
393 #endif /* _SCIC_SDS_PHY_H_ */