]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/scsi/isci/phy.h
isci: uplevel port infrastructure
[mirror_ubuntu-jammy-kernel.git] / drivers / scsi / isci / 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 #ifndef _ISCI_PHY_H_
56 #define _ISCI_PHY_H_
57
58 #include <scsi/sas.h>
59 #include <scsi/libsas.h>
60 #include "state_machine.h"
61 #include "sas.h"
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
79 enum 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 */
93 struct scic_sds_phy {
94 /**
95 * This field contains the information for the base phy state machine.
96 */
97 struct sci_base_state_machine state_machine;
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 /**
137 * This field contains a reference to the timer utilized in detecting
138 * when a signature FIS timeout has occurred. The signature FIS is the
139 * first FIS sent by an attached SATA device after OOB/SN.
140 */
141 void *sata_timeout_timer;
142
143 const struct scic_sds_phy_state_handler *state_handlers;
144
145 struct sci_base_state_machine starting_substate_machine;
146
147 /**
148 * This field is the pointer to the transport layer register for the SCU
149 * hardware.
150 */
151 struct scu_transport_layer_registers __iomem *transport_layer_registers;
152
153 /**
154 * This field points to the link layer register set within the SCU.
155 */
156 struct scu_link_layer_registers __iomem *link_layer_registers;
157
158 };
159
160
161 struct isci_phy {
162 struct scic_sds_phy sci;
163 struct asd_sas_phy sas_phy;
164 struct isci_port *isci_port;
165 u8 sas_addr[SAS_ADDR_SIZE];
166
167 union {
168 struct sas_identify_frame iaf;
169 struct dev_to_host_fis fis;
170 } frame_rcvd;
171 };
172
173 static inline struct isci_phy *to_isci_phy(struct asd_sas_phy *sas_phy)
174 {
175 struct isci_phy *iphy = container_of(sas_phy, typeof(*iphy), sas_phy);
176
177 return iphy;
178 }
179
180 static inline struct isci_phy *sci_phy_to_iphy(struct scic_sds_phy *sci_phy)
181 {
182 struct isci_phy *iphy = container_of(sci_phy, typeof(*iphy), sci);
183
184 return iphy;
185 }
186
187 struct scic_phy_cap {
188 union {
189 struct {
190 /*
191 * The SAS specification indicates the start bit shall
192 * always be set to
193 * 1. This implementation will have the start bit set
194 * to 0 if the PHY CAPABILITIES were either not
195 * received or speed negotiation failed.
196 */
197 u8 start:1;
198 u8 tx_ssc_type:1;
199 u8 res1:2;
200 u8 req_logical_linkrate:4;
201
202 u32 gen1_no_ssc:1;
203 u32 gen1_ssc:1;
204 u32 gen2_no_ssc:1;
205 u32 gen2_ssc:1;
206 u32 gen3_no_ssc:1;
207 u32 gen3_ssc:1;
208 u32 res2:17;
209 u32 parity:1;
210 };
211 u32 all;
212 };
213 } __packed;
214
215 /* this data structure reflects the link layer transmit identification reg */
216 struct scic_phy_proto {
217 union {
218 struct {
219 u16 _r_a:1;
220 u16 smp_iport:1;
221 u16 stp_iport:1;
222 u16 ssp_iport:1;
223 u16 _r_b:4;
224 u16 _r_c:1;
225 u16 smp_tport:1;
226 u16 stp_tport:1;
227 u16 ssp_tport:1;
228 u16 _r_d:4;
229 };
230 u16 all;
231 };
232 } __packed;
233
234
235 /**
236 * struct scic_phy_properties - This structure defines the properties common to
237 * all phys that can be retrieved.
238 *
239 *
240 */
241 struct scic_phy_properties {
242 /**
243 * This field specifies the port that currently contains the
244 * supplied phy. This field may be set to NULL
245 * if the phy is not currently contained in a port.
246 */
247 struct scic_sds_port *owning_port;
248
249 /**
250 * This field specifies the link rate at which the phy is
251 * currently operating.
252 */
253 enum sas_linkrate negotiated_link_rate;
254
255 /**
256 * This field specifies the index of the phy in relation to other
257 * phys within the controller. This index is zero relative.
258 */
259 u8 index;
260 };
261
262 /**
263 * struct scic_sas_phy_properties - This structure defines the properties,
264 * specific to a SAS phy, that can be retrieved.
265 *
266 *
267 */
268 struct scic_sas_phy_properties {
269 /**
270 * This field delineates the Identify Address Frame received
271 * from the remote end point.
272 */
273 struct sas_identify_frame rcvd_iaf;
274
275 /**
276 * This field delineates the Phy capabilities structure received
277 * from the remote end point.
278 */
279 struct scic_phy_cap rcvd_cap;
280
281 };
282
283 /**
284 * struct scic_sata_phy_properties - This structure defines the properties,
285 * specific to a SATA phy, that can be retrieved.
286 *
287 *
288 */
289 struct scic_sata_phy_properties {
290 /**
291 * This field delineates the signature FIS received from the
292 * attached target.
293 */
294 struct dev_to_host_fis signature_fis;
295
296 /**
297 * This field specifies to the user if a port selector is connected
298 * on the specified phy.
299 */
300 bool is_port_selector_present;
301
302 };
303
304 /**
305 * enum scic_phy_counter_id - This enumeration depicts the various pieces of
306 * optional information that can be retrieved for a specific phy.
307 *
308 *
309 */
310 enum scic_phy_counter_id {
311 /**
312 * This PHY information field tracks the number of frames received.
313 */
314 SCIC_PHY_COUNTER_RECEIVED_FRAME,
315
316 /**
317 * This PHY information field tracks the number of frames transmitted.
318 */
319 SCIC_PHY_COUNTER_TRANSMITTED_FRAME,
320
321 /**
322 * This PHY information field tracks the number of DWORDs received.
323 */
324 SCIC_PHY_COUNTER_RECEIVED_FRAME_WORD,
325
326 /**
327 * This PHY information field tracks the number of DWORDs transmitted.
328 */
329 SCIC_PHY_COUNTER_TRANSMITTED_FRAME_DWORD,
330
331 /**
332 * This PHY information field tracks the number of times DWORD
333 * synchronization was lost.
334 */
335 SCIC_PHY_COUNTER_LOSS_OF_SYNC_ERROR,
336
337 /**
338 * This PHY information field tracks the number of received DWORDs with
339 * running disparity errors.
340 */
341 SCIC_PHY_COUNTER_RECEIVED_DISPARITY_ERROR,
342
343 /**
344 * This PHY information field tracks the number of received frames with a
345 * CRC error (not including short or truncated frames).
346 */
347 SCIC_PHY_COUNTER_RECEIVED_FRAME_CRC_ERROR,
348
349 /**
350 * This PHY information field tracks the number of DONE (ACK/NAK TIMEOUT)
351 * primitives received.
352 */
353 SCIC_PHY_COUNTER_RECEIVED_DONE_ACK_NAK_TIMEOUT,
354
355 /**
356 * This PHY information field tracks the number of DONE (ACK/NAK TIMEOUT)
357 * primitives transmitted.
358 */
359 SCIC_PHY_COUNTER_TRANSMITTED_DONE_ACK_NAK_TIMEOUT,
360
361 /**
362 * This PHY information field tracks the number of times the inactivity
363 * timer for connections on the phy has been utilized.
364 */
365 SCIC_PHY_COUNTER_INACTIVITY_TIMER_EXPIRED,
366
367 /**
368 * This PHY information field tracks the number of DONE (CREDIT TIMEOUT)
369 * primitives received.
370 */
371 SCIC_PHY_COUNTER_RECEIVED_DONE_CREDIT_TIMEOUT,
372
373 /**
374 * This PHY information field tracks the number of DONE (CREDIT TIMEOUT)
375 * primitives transmitted.
376 */
377 SCIC_PHY_COUNTER_TRANSMITTED_DONE_CREDIT_TIMEOUT,
378
379 /**
380 * This PHY information field tracks the number of CREDIT BLOCKED
381 * primitives received.
382 * @note Depending on remote device implementation, credit blocks
383 * may occur regularly.
384 */
385 SCIC_PHY_COUNTER_RECEIVED_CREDIT_BLOCKED,
386
387 /**
388 * This PHY information field contains the number of short frames
389 * received. A short frame is simply a frame smaller then what is
390 * allowed by either the SAS or SATA specification.
391 */
392 SCIC_PHY_COUNTER_RECEIVED_SHORT_FRAME,
393
394 /**
395 * This PHY information field contains the number of frames received after
396 * credit has been exhausted.
397 */
398 SCIC_PHY_COUNTER_RECEIVED_FRAME_WITHOUT_CREDIT,
399
400 /**
401 * This PHY information field contains the number of frames received after
402 * a DONE has been received.
403 */
404 SCIC_PHY_COUNTER_RECEIVED_FRAME_AFTER_DONE,
405
406 /**
407 * This PHY information field contains the number of times the phy
408 * failed to achieve DWORD synchronization during speed negotiation.
409 */
410 SCIC_PHY_COUNTER_SN_DWORD_SYNC_ERROR
411 };
412
413 enum scic_sds_phy_states {
414 /**
415 * Simply the initial state for the base domain state machine.
416 */
417 SCI_BASE_PHY_STATE_INITIAL,
418
419 /**
420 * This state indicates that the phy has successfully been stopped.
421 * In this state no new IO operations are permitted on this phy.
422 * This state is entered from the INITIAL state.
423 * This state is entered from the STARTING state.
424 * This state is entered from the READY state.
425 * This state is entered from the RESETTING state.
426 */
427 SCI_BASE_PHY_STATE_STOPPED,
428
429 /**
430 * This state indicates that the phy is in the process of becomming
431 * ready. In this state no new IO operations are permitted on this phy.
432 * This state is entered from the STOPPED state.
433 * This state is entered from the READY state.
434 * This state is entered from the RESETTING state.
435 */
436 SCI_BASE_PHY_STATE_STARTING,
437
438 /**
439 * This state indicates the the phy is now ready. Thus, the user
440 * is able to perform IO operations utilizing this phy as long as it
441 * is currently part of a valid port.
442 * This state is entered from the STARTING state.
443 */
444 SCI_BASE_PHY_STATE_READY,
445
446 /**
447 * This state indicates that the phy is in the process of being reset.
448 * In this state no new IO operations are permitted on this phy.
449 * This state is entered from the READY state.
450 */
451 SCI_BASE_PHY_STATE_RESETTING,
452
453 /**
454 * Simply the final state for the base phy state machine.
455 */
456 SCI_BASE_PHY_STATE_FINAL,
457 };
458
459
460 /**
461 * enum scic_sds_phy_starting_substates -
462 *
463 *
464 */
465 enum scic_sds_phy_starting_substates {
466 /**
467 * Initial state
468 */
469 SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL,
470
471 /**
472 * Wait state for the hardware OSSP event type notification
473 */
474 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN,
475
476 /**
477 * Wait state for the PHY speed notification
478 */
479 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN,
480
481 /**
482 * Wait state for the IAF Unsolicited frame notification
483 */
484 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF,
485
486 /**
487 * Wait state for the request to consume power
488 */
489 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER,
490
491 /**
492 * Wait state for request to consume power
493 */
494 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER,
495
496 /**
497 * Wait state for the SATA PHY notification
498 */
499 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN,
500
501 /**
502 * Wait for the SATA PHY speed notification
503 */
504 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN,
505
506 /**
507 * Wait state for the SIGNATURE FIS unsolicited frame notification
508 */
509 SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF,
510
511 /**
512 * Exit state for this state machine
513 */
514 SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL,
515 };
516
517
518
519 typedef enum sci_status (*scic_sds_phy_handler_t)(struct scic_sds_phy *);
520 typedef enum sci_status (*scic_sds_phy_event_handler_t)(struct scic_sds_phy *, u32);
521 typedef enum sci_status (*scic_sds_phy_frame_handler_t)(struct scic_sds_phy *, u32);
522 typedef enum sci_status (*scic_sds_phy_power_handler_t)(struct scic_sds_phy *);
523
524 struct scic_sds_phy_state_handler {
525 /**
526 * The start_handler specifies the method invoked when there is an
527 * attempt to start a phy.
528 */
529 scic_sds_phy_handler_t start_handler;
530
531 /**
532 * The stop_handler specifies the method invoked when there is an
533 * attempt to stop a phy.
534 */
535 scic_sds_phy_handler_t stop_handler;
536
537 /**
538 * The reset_handler specifies the method invoked when there is an
539 * attempt to reset a phy.
540 */
541 scic_sds_phy_handler_t reset_handler;
542
543 /**
544 * The destruct_handler specifies the method invoked when attempting to
545 * destruct a phy.
546 */
547 scic_sds_phy_handler_t destruct_handler;
548
549 /**
550 * The state handler for unsolicited frames received from the SCU hardware.
551 */
552 scic_sds_phy_frame_handler_t frame_handler;
553
554 /**
555 * The state handler for events received from the SCU hardware.
556 */
557 scic_sds_phy_event_handler_t event_handler;
558
559 /**
560 * The state handler for staggered spinup.
561 */
562 scic_sds_phy_power_handler_t consume_power_handler;
563
564 };
565
566 /**
567 * scic_sds_phy_get_index() -
568 *
569 * This macro returns the phy index for the specified phy
570 */
571 #define scic_sds_phy_get_index(phy) \
572 ((phy)->phy_index)
573
574 /**
575 * scic_sds_phy_get_controller() - This macro returns the controller for this
576 * phy
577 *
578 *
579 */
580 #define scic_sds_phy_get_controller(phy) \
581 (scic_sds_port_get_controller((phy)->owning_port))
582
583 /**
584 * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
585 * this phy object
586 *
587 *
588 */
589 #define scic_sds_phy_set_state_handlers(phy, handlers) \
590 ((phy)->state_handlers = (handlers))
591
592 /**
593 * scic_sds_phy_set_base_state_handlers() -
594 *
595 * This macro set the base state handlers for the phy object.
596 */
597 #define scic_sds_phy_set_base_state_handlers(phy, state_id) \
598 scic_sds_phy_set_state_handlers(\
599 (phy), \
600 &scic_sds_phy_state_handler_table[(state_id)] \
601 )
602
603 void scic_sds_phy_construct(
604 struct scic_sds_phy *this_phy,
605 struct scic_sds_port *owning_port,
606 u8 phy_index);
607
608 struct scic_sds_port *scic_sds_phy_get_port(
609 struct scic_sds_phy *this_phy);
610
611 void scic_sds_phy_set_port(
612 struct scic_sds_phy *this_phy,
613 struct scic_sds_port *owning_port);
614
615 enum sci_status scic_sds_phy_initialize(
616 struct scic_sds_phy *this_phy,
617 struct scu_transport_layer_registers __iomem *transport_layer_registers,
618 struct scu_link_layer_registers __iomem *link_layer_registers);
619
620 enum sci_status scic_sds_phy_start(
621 struct scic_sds_phy *this_phy);
622
623 enum sci_status scic_sds_phy_stop(
624 struct scic_sds_phy *this_phy);
625
626 enum sci_status scic_sds_phy_reset(
627 struct scic_sds_phy *this_phy);
628
629 void scic_sds_phy_resume(
630 struct scic_sds_phy *this_phy);
631
632 void scic_sds_phy_setup_transport(
633 struct scic_sds_phy *this_phy,
634 u32 device_id);
635
636 enum sci_status scic_sds_phy_event_handler(
637 struct scic_sds_phy *this_phy,
638 u32 event_code);
639
640 enum sci_status scic_sds_phy_frame_handler(
641 struct scic_sds_phy *this_phy,
642 u32 frame_index);
643
644 enum sci_status scic_sds_phy_consume_power_handler(
645 struct scic_sds_phy *this_phy);
646
647 void scic_sds_phy_get_sas_address(
648 struct scic_sds_phy *this_phy,
649 struct sci_sas_address *sas_address);
650
651 void scic_sds_phy_get_attached_sas_address(
652 struct scic_sds_phy *this_phy,
653 struct sci_sas_address *sas_address);
654
655 struct scic_phy_proto;
656 void scic_sds_phy_get_protocols(
657 struct scic_sds_phy *sci_phy,
658 struct scic_phy_proto *protocols);
659 enum sas_linkrate sci_phy_linkrate(struct scic_sds_phy *sci_phy);
660
661 struct isci_host;
662 void isci_phy_init(struct isci_phy *iphy, struct isci_host *ihost, int index);
663 int isci_phy_control(struct asd_sas_phy *phy, enum phy_func func, void *buf);
664
665 #endif /* !defined(_ISCI_PHY_H_) */