isci: additional state machine cleanup
[deliverable/linux.git] / drivers / scsi / isci / phy.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 */
4b33981a 55#ifndef _ISCI_PHY_H_
6f231dda
DW
56#define _ISCI_PHY_H_
57
f2f30080 58#include <scsi/sas.h>
6f231dda 59#include <scsi/libsas.h>
12ef6544 60#include "isci.h"
e2f8db50 61#include "sas.h"
d35bc1bd
DW
62
63/* This is the timeout value for the SATA phy to wait for a SIGNATURE FIS
64 * before restarting the starting state machine. Technically, the old parallel
65 * ATA specification required up to 30 seconds for a device to issue its
66 * signature FIS as a result of a soft reset. Now we see that devices respond
67 * generally within 15 seconds, but we'll use 25 for now.
68 */
69#define SCIC_SDS_SIGNATURE_FIS_TIMEOUT 25000
70
71/* This is the timeout for the SATA OOB/SN because the hardware does not
72 * recognize a hot plug after OOB signal but before the SN signals. We need to
73 * make sure after a hotplug timeout if we have not received the speed event
74 * notification from the hardware that we restart the hardware OOB state
75 * machine.
76 */
77#define SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT 250
78
79enum scic_sds_phy_protocol {
80 SCIC_SDS_PHY_PROTOCOL_UNKNOWN,
81 SCIC_SDS_PHY_PROTOCOL_SAS,
82 SCIC_SDS_PHY_PROTOCOL_SATA,
83 SCIC_SDS_MAX_PHY_PROTOCOLS
84};
85
86/**
87 * struct scic_sds_phy - This structure contains or references all of the data
88 * necessary to represent the core phy object and SCU harware protocol
89 * engine.
90 *
91 *
92 */
93struct scic_sds_phy {
94 /**
95 * This field contains the information for the base phy state machine.
96 */
e301370a 97 struct sci_base_state_machine sm;
d35bc1bd
DW
98
99 /**
100 * This field specifies the port object that owns/contains this phy.
101 */
102 struct scic_sds_port *owning_port;
103
104 /**
105 * This field indicates whether the phy supports 1.5 Gb/s, 3.0 Gb/s,
106 * or 6.0 Gb/s operation.
107 */
108 enum sas_linkrate max_negotiated_speed;
109
110 /**
111 * This member specifies the protocol being utilized on this phy. This
112 * field contains a legitamite value once the PHY has link trained with
113 * a remote phy.
114 */
115 enum scic_sds_phy_protocol protocol;
116
117 /**
118 * This field specifies the index with which this phy is associated (0-3).
119 */
120 u8 phy_index;
121
122 /**
123 * This member indicates if this particular PHY has received a BCN while
124 * it had no port assignement. This BCN will be reported once the phy is
125 * assigned to a port.
126 */
127 bool bcn_received_while_port_unassigned;
128
129 /**
130 * This field indicates if this PHY is currently in the process of
131 * link training (i.e. it has started OOB, but has yet to perform
132 * IAF exchange/Signature FIS reception).
133 */
134 bool is_in_link_training;
135
136 /**
a628d478
EN
137 * Timer to detect when a signature FIS timeout has occurred. The
138 * signature FIS is the first FIS sent by an attached SATA device
139 * after OOB/SN.
d35bc1bd 140 */
a628d478 141 struct sci_timer sata_timer;
d35bc1bd 142
d35bc1bd
DW
143 /**
144 * This field is the pointer to the transport layer register for the SCU
145 * hardware.
146 */
147 struct scu_transport_layer_registers __iomem *transport_layer_registers;
148
149 /**
150 * This field points to the link layer register set within the SCU.
151 */
152 struct scu_link_layer_registers __iomem *link_layer_registers;
153
154};
155
6f231dda
DW
156
157struct isci_phy {
4b33981a 158 struct scic_sds_phy sci;
6f231dda 159 struct asd_sas_phy sas_phy;
6f231dda
DW
160 struct isci_port *isci_port;
161 u8 sas_addr[SAS_ADDR_SIZE];
162
163 union {
4b7ebd05 164 struct sas_identify_frame iaf;
f2f30080 165 struct dev_to_host_fis fis;
6f231dda
DW
166 } frame_rcvd;
167};
168
4b33981a
DW
169static inline struct isci_phy *to_isci_phy(struct asd_sas_phy *sas_phy)
170{
171 struct isci_phy *iphy = container_of(sas_phy, typeof(*iphy), sas_phy);
172
173 return iphy;
174}
175
176static inline struct isci_phy *sci_phy_to_iphy(struct scic_sds_phy *sci_phy)
177{
178 struct isci_phy *iphy = container_of(sci_phy, typeof(*iphy), sci);
6f231dda 179
4b33981a
DW
180 return iphy;
181}
6f231dda 182
d35bc1bd
DW
183struct scic_phy_cap {
184 union {
185 struct {
186 /*
187 * The SAS specification indicates the start bit shall
188 * always be set to
189 * 1. This implementation will have the start bit set
190 * to 0 if the PHY CAPABILITIES were either not
191 * received or speed negotiation failed.
192 */
193 u8 start:1;
194 u8 tx_ssc_type:1;
195 u8 res1:2;
196 u8 req_logical_linkrate:4;
197
198 u32 gen1_no_ssc:1;
199 u32 gen1_ssc:1;
200 u32 gen2_no_ssc:1;
201 u32 gen2_ssc:1;
202 u32 gen3_no_ssc:1;
203 u32 gen3_ssc:1;
204 u32 res2:17;
205 u32 parity:1;
206 };
207 u32 all;
208 };
209} __packed;
210
211/* this data structure reflects the link layer transmit identification reg */
212struct scic_phy_proto {
213 union {
214 struct {
215 u16 _r_a:1;
216 u16 smp_iport:1;
217 u16 stp_iport:1;
218 u16 ssp_iport:1;
219 u16 _r_b:4;
220 u16 _r_c:1;
221 u16 smp_tport:1;
222 u16 stp_tport:1;
223 u16 ssp_tport:1;
224 u16 _r_d:4;
225 };
226 u16 all;
227 };
228} __packed;
229
230
231/**
232 * struct scic_phy_properties - This structure defines the properties common to
233 * all phys that can be retrieved.
234 *
235 *
236 */
237struct scic_phy_properties {
238 /**
239 * This field specifies the port that currently contains the
240 * supplied phy. This field may be set to NULL
241 * if the phy is not currently contained in a port.
242 */
243 struct scic_sds_port *owning_port;
244
245 /**
246 * This field specifies the link rate at which the phy is
247 * currently operating.
248 */
249 enum sas_linkrate negotiated_link_rate;
250
251 /**
252 * This field specifies the index of the phy in relation to other
253 * phys within the controller. This index is zero relative.
254 */
255 u8 index;
256};
257
258/**
259 * struct scic_sas_phy_properties - This structure defines the properties,
260 * specific to a SAS phy, that can be retrieved.
261 *
262 *
263 */
264struct scic_sas_phy_properties {
265 /**
266 * This field delineates the Identify Address Frame received
267 * from the remote end point.
268 */
269 struct sas_identify_frame rcvd_iaf;
270
271 /**
272 * This field delineates the Phy capabilities structure received
273 * from the remote end point.
274 */
275 struct scic_phy_cap rcvd_cap;
276
277};
278
279/**
280 * struct scic_sata_phy_properties - This structure defines the properties,
281 * specific to a SATA phy, that can be retrieved.
282 *
283 *
284 */
285struct scic_sata_phy_properties {
286 /**
287 * This field delineates the signature FIS received from the
288 * attached target.
289 */
290 struct dev_to_host_fis signature_fis;
291
292 /**
293 * This field specifies to the user if a port selector is connected
294 * on the specified phy.
295 */
296 bool is_port_selector_present;
297
298};
299
300/**
301 * enum scic_phy_counter_id - This enumeration depicts the various pieces of
302 * optional information that can be retrieved for a specific phy.
303 *
304 *
305 */
306enum scic_phy_counter_id {
307 /**
308 * This PHY information field tracks the number of frames received.
309 */
310 SCIC_PHY_COUNTER_RECEIVED_FRAME,
311
312 /**
313 * This PHY information field tracks the number of frames transmitted.
314 */
315 SCIC_PHY_COUNTER_TRANSMITTED_FRAME,
316
317 /**
318 * This PHY information field tracks the number of DWORDs received.
319 */
320 SCIC_PHY_COUNTER_RECEIVED_FRAME_WORD,
321
322 /**
323 * This PHY information field tracks the number of DWORDs transmitted.
324 */
325 SCIC_PHY_COUNTER_TRANSMITTED_FRAME_DWORD,
326
327 /**
328 * This PHY information field tracks the number of times DWORD
329 * synchronization was lost.
330 */
331 SCIC_PHY_COUNTER_LOSS_OF_SYNC_ERROR,
332
333 /**
334 * This PHY information field tracks the number of received DWORDs with
335 * running disparity errors.
336 */
337 SCIC_PHY_COUNTER_RECEIVED_DISPARITY_ERROR,
338
339 /**
340 * This PHY information field tracks the number of received frames with a
341 * CRC error (not including short or truncated frames).
342 */
343 SCIC_PHY_COUNTER_RECEIVED_FRAME_CRC_ERROR,
344
345 /**
346 * This PHY information field tracks the number of DONE (ACK/NAK TIMEOUT)
347 * primitives received.
348 */
349 SCIC_PHY_COUNTER_RECEIVED_DONE_ACK_NAK_TIMEOUT,
350
351 /**
352 * This PHY information field tracks the number of DONE (ACK/NAK TIMEOUT)
353 * primitives transmitted.
354 */
355 SCIC_PHY_COUNTER_TRANSMITTED_DONE_ACK_NAK_TIMEOUT,
356
357 /**
358 * This PHY information field tracks the number of times the inactivity
359 * timer for connections on the phy has been utilized.
360 */
361 SCIC_PHY_COUNTER_INACTIVITY_TIMER_EXPIRED,
362
363 /**
364 * This PHY information field tracks the number of DONE (CREDIT TIMEOUT)
365 * primitives received.
366 */
367 SCIC_PHY_COUNTER_RECEIVED_DONE_CREDIT_TIMEOUT,
368
369 /**
370 * This PHY information field tracks the number of DONE (CREDIT TIMEOUT)
371 * primitives transmitted.
372 */
373 SCIC_PHY_COUNTER_TRANSMITTED_DONE_CREDIT_TIMEOUT,
374
375 /**
376 * This PHY information field tracks the number of CREDIT BLOCKED
377 * primitives received.
378 * @note Depending on remote device implementation, credit blocks
379 * may occur regularly.
380 */
381 SCIC_PHY_COUNTER_RECEIVED_CREDIT_BLOCKED,
382
383 /**
384 * This PHY information field contains the number of short frames
385 * received. A short frame is simply a frame smaller then what is
386 * allowed by either the SAS or SATA specification.
387 */
388 SCIC_PHY_COUNTER_RECEIVED_SHORT_FRAME,
389
390 /**
391 * This PHY information field contains the number of frames received after
392 * credit has been exhausted.
393 */
394 SCIC_PHY_COUNTER_RECEIVED_FRAME_WITHOUT_CREDIT,
395
396 /**
397 * This PHY information field contains the number of frames received after
398 * a DONE has been received.
399 */
400 SCIC_PHY_COUNTER_RECEIVED_FRAME_AFTER_DONE,
401
402 /**
403 * This PHY information field contains the number of times the phy
404 * failed to achieve DWORD synchronization during speed negotiation.
405 */
406 SCIC_PHY_COUNTER_SN_DWORD_SYNC_ERROR
407};
408
409enum scic_sds_phy_states {
410 /**
411 * Simply the initial state for the base domain state machine.
412 */
e301370a 413 SCI_PHY_INITIAL,
d35bc1bd
DW
414
415 /**
416 * This state indicates that the phy has successfully been stopped.
417 * In this state no new IO operations are permitted on this phy.
418 * This state is entered from the INITIAL state.
419 * This state is entered from the STARTING state.
420 * This state is entered from the READY state.
421 * This state is entered from the RESETTING state.
422 */
e301370a 423 SCI_PHY_STOPPED,
d35bc1bd
DW
424
425 /**
426 * This state indicates that the phy is in the process of becomming
427 * ready. In this state no new IO operations are permitted on this phy.
428 * This state is entered from the STOPPED state.
429 * This state is entered from the READY state.
430 * This state is entered from the RESETTING state.
431 */
e301370a 432 SCI_PHY_STARTING,
d35bc1bd 433
d35bc1bd
DW
434 /**
435 * Initial state
436 */
e301370a 437 SCI_PHY_SUB_INITIAL,
d35bc1bd
DW
438
439 /**
440 * Wait state for the hardware OSSP event type notification
441 */
e301370a 442 SCI_PHY_SUB_AWAIT_OSSP_EN,
d35bc1bd
DW
443
444 /**
445 * Wait state for the PHY speed notification
446 */
e301370a 447 SCI_PHY_SUB_AWAIT_SAS_SPEED_EN,
d35bc1bd
DW
448
449 /**
450 * Wait state for the IAF Unsolicited frame notification
451 */
e301370a 452 SCI_PHY_SUB_AWAIT_IAF_UF,
d35bc1bd
DW
453
454 /**
455 * Wait state for the request to consume power
456 */
e301370a 457 SCI_PHY_SUB_AWAIT_SAS_POWER,
d35bc1bd
DW
458
459 /**
460 * Wait state for request to consume power
461 */
e301370a 462 SCI_PHY_SUB_AWAIT_SATA_POWER,
d35bc1bd
DW
463
464 /**
465 * Wait state for the SATA PHY notification
466 */
e301370a 467 SCI_PHY_SUB_AWAIT_SATA_PHY_EN,
d35bc1bd
DW
468
469 /**
470 * Wait for the SATA PHY speed notification
471 */
e301370a 472 SCI_PHY_SUB_AWAIT_SATA_SPEED_EN,
d35bc1bd
DW
473
474 /**
475 * Wait state for the SIGNATURE FIS unsolicited frame notification
476 */
e301370a 477 SCI_PHY_SUB_AWAIT_SIG_FIS_UF,
d35bc1bd
DW
478
479 /**
480 * Exit state for this state machine
481 */
e301370a 482 SCI_PHY_SUB_FINAL,
d35bc1bd 483
4a33c525
AG
484 /**
485 * This state indicates the the phy is now ready. Thus, the user
486 * is able to perform IO operations utilizing this phy as long as it
487 * is currently part of a valid port.
488 * This state is entered from the STARTING state.
489 */
e301370a 490 SCI_PHY_READY,
4a33c525
AG
491
492 /**
493 * This state indicates that the phy is in the process of being reset.
494 * In this state no new IO operations are permitted on this phy.
495 * This state is entered from the READY state.
496 */
e301370a 497 SCI_PHY_RESETTING,
4a33c525
AG
498
499 /**
500 * Simply the final state for the base phy state machine.
501 */
e301370a 502 SCI_PHY_FINAL,
4a33c525 503};
d35bc1bd 504
d35bc1bd
DW
505/**
506 * scic_sds_phy_get_index() -
507 *
508 * This macro returns the phy index for the specified phy
509 */
510#define scic_sds_phy_get_index(phy) \
511 ((phy)->phy_index)
512
513/**
514 * scic_sds_phy_get_controller() - This macro returns the controller for this
515 * phy
516 *
517 *
518 */
519#define scic_sds_phy_get_controller(phy) \
520 (scic_sds_port_get_controller((phy)->owning_port))
521
d35bc1bd
DW
522void scic_sds_phy_construct(
523 struct scic_sds_phy *this_phy,
524 struct scic_sds_port *owning_port,
525 u8 phy_index);
526
4f20ef4f 527struct scic_sds_port *phy_get_non_dummy_port(struct scic_sds_phy *sci_phy);
d35bc1bd
DW
528
529void scic_sds_phy_set_port(
530 struct scic_sds_phy *this_phy,
531 struct scic_sds_port *owning_port);
532
533enum sci_status scic_sds_phy_initialize(
534 struct scic_sds_phy *this_phy,
535 struct scu_transport_layer_registers __iomem *transport_layer_registers,
536 struct scu_link_layer_registers __iomem *link_layer_registers);
537
538enum sci_status scic_sds_phy_start(
539 struct scic_sds_phy *this_phy);
540
541enum sci_status scic_sds_phy_stop(
542 struct scic_sds_phy *this_phy);
543
544enum sci_status scic_sds_phy_reset(
545 struct scic_sds_phy *this_phy);
546
547void scic_sds_phy_resume(
548 struct scic_sds_phy *this_phy);
549
550void scic_sds_phy_setup_transport(
551 struct scic_sds_phy *this_phy,
552 u32 device_id);
553
554enum sci_status scic_sds_phy_event_handler(
555 struct scic_sds_phy *this_phy,
556 u32 event_code);
557
558enum sci_status scic_sds_phy_frame_handler(
559 struct scic_sds_phy *this_phy,
560 u32 frame_index);
561
562enum sci_status scic_sds_phy_consume_power_handler(
563 struct scic_sds_phy *this_phy);
564
565void scic_sds_phy_get_sas_address(
566 struct scic_sds_phy *this_phy,
567 struct sci_sas_address *sas_address);
568
569void scic_sds_phy_get_attached_sas_address(
570 struct scic_sds_phy *this_phy,
571 struct sci_sas_address *sas_address);
572
573struct scic_phy_proto;
574void scic_sds_phy_get_protocols(
575 struct scic_sds_phy *sci_phy,
576 struct scic_phy_proto *protocols);
577enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy);
578
ce2b3261 579struct isci_host;
4b33981a
DW
580void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index);
581int isci_phy_control(struct asd_sas_phy *phy, enum phy_func func, void *buf);
6f231dda
DW
582
583#endif /* !defined(_ISCI_PHY_H_) */
This page took 0.056486 seconds and 5 git commands to generate.