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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
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.
56 #include "intel_sas.h"
57 #include "sci_base_port.h"
58 #include "scic_controller.h"
60 #include "scic_port.h"
61 #include "scic_sds_controller.h"
62 #include "scic_sds_phy.h"
63 #include "scic_sds_port.h"
64 #include "scic_sds_remote_device.h"
65 #include "scic_sds_remote_node_context.h"
66 #include "scic_sds_request.h"
67 #include "sci_environment.h"
68 #include "scu_registers.h"
70 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
71 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
73 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
74 #define SCU_DUMMY_INDEX (0xFFFF)
76 static void sci_base_port_construct(
77 struct sci_base_port
*base_port
,
78 const struct sci_base_state
*state_table
)
80 base_port
->parent
.private = NULL
;
81 sci_base_state_machine_construct(
82 &base_port
->state_machine
,
85 SCI_BASE_PORT_STATE_STOPPED
88 sci_base_state_machine_start(
89 &base_port
->state_machine
95 * @this_port: This is the port object to which the phy is being assigned.
96 * @phy_index: This is the phy index that is being assigned to the port.
98 * This method will return a true value if the specified phy can be assigned to
99 * this port The following is a list of phys for each port that are allowed: -
100 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
101 * doesn't preclude all configurations. It merely ensures that a phy is part
102 * of the allowable set of phy identifiers for that port. For example, one
103 * could assign phy 3 to port 0 and no other phys. Please refer to
104 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
105 * phy_mask for a port can be supported. bool true if this is a valid phy
106 * assignment for the port false if this is not a valid phy assignment for the
109 bool scic_sds_port_is_valid_phy_assignment(
110 struct scic_sds_port
*this_port
,
113 /* Initialize to invalid value. */
114 u32 existing_phy_index
= SCI_MAX_PHYS
;
117 if ((this_port
->physical_port_index
== 1) && (phy_index
!= 1)) {
121 if (this_port
->physical_port_index
== 3 && phy_index
!= 3) {
126 (this_port
->physical_port_index
== 2)
127 && ((phy_index
== 0) || (phy_index
== 1))
132 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
133 if ((this_port
->phy_table
[index
] != NULL
)
134 && (index
!= phy_index
)) {
135 existing_phy_index
= index
;
140 * Ensure that all of the phys in the port are capable of
141 * operating at the same maximum link rate. */
143 (existing_phy_index
< SCI_MAX_PHYS
)
144 && (this_port
->owning_controller
->user_parameters
.sds1
.phys
[
145 phy_index
].max_speed_generation
!=
146 this_port
->owning_controller
->user_parameters
.sds1
.phys
[
147 existing_phy_index
].max_speed_generation
)
155 * This method requests a list (mask) of the phys contained in the supplied SAS
157 * @this_port: a handle corresponding to the SAS port for which to return the
160 * Return a bit mask indicating which phys are a part of this port. Each bit
161 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
163 static u32
scic_sds_port_get_phys(struct scic_sds_port
*this_port
)
170 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
171 if (this_port
->phy_table
[index
] != NULL
) {
172 mask
|= (1 << index
);
181 * @this_port: This is the port object for which to determine if the phy mask
184 * This method will return a true value if the port's phy mask can be supported
185 * by the SCU. The following is a list of valid PHY mask configurations for
186 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
187 * - Port 3 - [3] This method returns a boolean indication specifying if the
188 * phy mask can be supported. true if this is a valid phy assignment for the
189 * port false if this is not a valid phy assignment for the port
191 static bool scic_sds_port_is_phy_mask_valid(
192 struct scic_sds_port
*this_port
,
195 if (this_port
->physical_port_index
== 0) {
196 if (((phy_mask
& 0x0F) == 0x0F)
197 || ((phy_mask
& 0x03) == 0x03)
198 || ((phy_mask
& 0x01) == 0x01)
201 } else if (this_port
->physical_port_index
== 1) {
202 if (((phy_mask
& 0x02) == 0x02)
205 } else if (this_port
->physical_port_index
== 2) {
206 if (((phy_mask
& 0x0C) == 0x0C)
207 || ((phy_mask
& 0x04) == 0x04)
210 } else if (this_port
->physical_port_index
== 3) {
211 if (((phy_mask
& 0x08) == 0x08)
221 * @this_port: This parameter specifies the port from which to return a
224 * This method retrieves a currently active (i.e. connected) phy contained in
225 * the port. Currently, the lowest order phy that is connected is returned.
226 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
227 * returned if there are no currently active (i.e. connected to a remote end
228 * point) phys contained in the port. All other values specify a struct scic_sds_phy
229 * object that is active in the port.
231 static struct scic_sds_phy
*scic_sds_port_get_a_connected_phy(
232 struct scic_sds_port
*this_port
235 struct scic_sds_phy
*phy
;
237 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
239 * Ensure that the phy is both part of the port and currently
240 * connected to the remote end-point. */
241 phy
= this_port
->phy_table
[index
];
244 && scic_sds_port_active_phy(this_port
, phy
)
254 * scic_sds_port_set_phy() -
255 * @out]: port The port object to which the phy assignement is being made.
256 * @out]: phy The phy which is being assigned to the port.
258 * This method attempts to make the assignment of the phy to the port. If
259 * successful the phy is assigned to the ports phy table. bool true if the phy
260 * assignment can be made. false if the phy assignement can not be made. This
261 * is a functional test that only fails if the phy is currently assigned to a
264 static enum sci_status
scic_sds_port_set_phy(
265 struct scic_sds_port
*port
,
266 struct scic_sds_phy
*phy
)
269 * Check to see if we can add this phy to a port
270 * that means that the phy is not part of a port and that the port does
271 * not already have a phy assinged to the phy index. */
273 (port
->phy_table
[phy
->phy_index
] == NULL
)
274 && (scic_sds_phy_get_port(phy
) == NULL
)
275 && scic_sds_port_is_valid_phy_assignment(port
, phy
->phy_index
)
278 * Phy is being added in the stopped state so we are in MPC mode
279 * make logical port index = physical port index */
280 port
->logical_port_index
= port
->physical_port_index
;
281 port
->phy_table
[phy
->phy_index
] = phy
;
282 scic_sds_phy_set_port(phy
, port
);
291 * scic_sds_port_clear_phy() -
292 * @out]: port The port from which the phy is being cleared.
293 * @out]: phy The phy being cleared from the port.
295 * This method will clear the phy assigned to this port. This method fails if
296 * this phy is not currently assinged to this port. bool true if the phy is
297 * removed from the port. false if this phy is not assined to this port.
299 static enum sci_status
scic_sds_port_clear_phy(
300 struct scic_sds_port
*port
,
301 struct scic_sds_phy
*phy
)
303 /* Make sure that this phy is part of this port */
305 (port
->phy_table
[phy
->phy_index
] == phy
)
306 && (scic_sds_phy_get_port(phy
) == port
)
308 /* Yep it is assigned to this port so remove it */
309 scic_sds_phy_set_port(
311 &scic_sds_port_get_controller(port
)->port_table
[SCI_MAX_PORTS
]
314 port
->phy_table
[phy
->phy_index
] = NULL
;
323 * scic_sds_port_add_phy() -
324 * @this_port: This parameter specifies the port in which the phy will be added.
325 * @the_phy: This parameter is the phy which is to be added to the port.
327 * This method will add a PHY to the selected port. This method returns an
328 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
329 * is failre to add the phy to the port.
331 enum sci_status
scic_sds_port_add_phy(
332 struct scic_sds_port
*this_port
,
333 struct scic_sds_phy
*the_phy
)
335 return this_port
->state_handlers
->parent
.add_phy_handler(
336 &this_port
->parent
, &the_phy
->parent
);
341 * scic_sds_port_remove_phy() -
342 * @this_port: This parameter specifies the port in which the phy will be added.
343 * @the_phy: This parameter is the phy which is to be added to the port.
345 * This method will remove the PHY from the selected PORT. This method returns
346 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
347 * status is failre to add the phy to the port.
349 enum sci_status
scic_sds_port_remove_phy(
350 struct scic_sds_port
*this_port
,
351 struct scic_sds_phy
*the_phy
)
353 return this_port
->state_handlers
->parent
.remove_phy_handler(
354 &this_port
->parent
, &the_phy
->parent
);
358 * This method requests the SAS address for the supplied SAS port from the SCI
360 * @this_port: a handle corresponding to the SAS port for which to return the
362 * @sas_address: This parameter specifies a pointer to a SAS address structure
363 * into which the core will copy the SAS address for the port.
366 void scic_sds_port_get_sas_address(
367 struct scic_sds_port
*this_port
,
368 struct sci_sas_address
*sas_address
)
372 sas_address
->high
= 0;
373 sas_address
->low
= 0;
375 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
376 if (this_port
->phy_table
[index
] != NULL
) {
377 scic_sds_phy_get_sas_address(this_port
->phy_table
[index
], sas_address
);
383 * This method will indicate which protocols are supported by this port.
384 * @this_port: a handle corresponding to the SAS port for which to return the
385 * supported protocols.
386 * @protocols: This parameter specifies a pointer to an IAF protocol field
387 * structure into which the core will copy the protocol values for the port.
388 * The values are returned as part of a bit mask in order to allow for
389 * multi-protocol support.
392 static void scic_sds_port_get_protocols(
393 struct scic_sds_port
*this_port
,
394 struct sci_sas_identify_address_frame_protocols
*protocols
)
398 protocols
->u
.all
= 0;
400 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
401 if (this_port
->phy_table
[index
] != NULL
) {
402 scic_sds_phy_get_protocols(this_port
->phy_table
[index
], protocols
);
408 * This method requests the SAS address for the device directly attached to
410 * @this_port: a handle corresponding to the SAS port for which to return the
412 * @sas_address: This parameter specifies a pointer to a SAS address structure
413 * into which the core will copy the SAS address for the device directly
414 * attached to the port.
417 void scic_sds_port_get_attached_sas_address(
418 struct scic_sds_port
*this_port
,
419 struct sci_sas_address
*sas_address
)
421 struct sci_sas_identify_address_frame_protocols protocols
;
422 struct scic_sds_phy
*phy
;
425 * Ensure that the phy is both part of the port and currently
426 * connected to the remote end-point. */
427 phy
= scic_sds_port_get_a_connected_phy(this_port
);
429 scic_sds_phy_get_attached_phy_protocols(phy
, &protocols
);
431 if (!protocols
.u
.bits
.stp_target
) {
432 scic_sds_phy_get_attached_sas_address(phy
, sas_address
);
434 scic_sds_phy_get_sas_address(phy
, sas_address
);
435 sas_address
->low
+= phy
->phy_index
;
438 sas_address
->high
= 0;
439 sas_address
->low
= 0;
444 * This method will indicate which protocols are supported by this remote
446 * @this_port: a handle corresponding to the SAS port for which to return the
447 * supported protocols.
448 * @protocols: This parameter specifies a pointer to an IAF protocol field
449 * structure into which the core will copy the protocol values for the port.
450 * The values are returned as part of a bit mask in order to allow for
451 * multi-protocol support.
454 void scic_sds_port_get_attached_protocols(
455 struct scic_sds_port
*this_port
,
456 struct sci_sas_identify_address_frame_protocols
*protocols
)
458 struct scic_sds_phy
*phy
;
461 * Ensure that the phy is both part of the port and currently
462 * connected to the remote end-point. */
463 phy
= scic_sds_port_get_a_connected_phy(this_port
);
465 scic_sds_phy_get_attached_phy_protocols(phy
, protocols
);
467 protocols
->u
.all
= 0;
471 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
473 * @sci_port: logical port on which we need to create the remote node context
474 * @rni: remote node index for this remote node context.
476 * This routine will construct a dummy remote node context data structure
477 * This structure will be posted to the hardware to work around a scheduler
478 * error in the hardware.
480 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port
*sci_port
, u16 rni
)
482 union scu_remote_node_context
*rnc
;
484 rnc
= &sci_port
->owning_controller
->remote_node_context_table
[rni
];
486 memset(rnc
, 0, sizeof(union scu_remote_node_context
));
488 rnc
->ssp
.remote_sas_address_hi
= 0;
489 rnc
->ssp
.remote_sas_address_lo
= 0;
491 rnc
->ssp
.remote_node_index
= rni
;
492 rnc
->ssp
.remote_node_port_width
= 1;
493 rnc
->ssp
.logical_port_index
= sci_port
->physical_port_index
;
495 rnc
->ssp
.nexus_loss_timer_enable
= false;
496 rnc
->ssp
.check_bit
= false;
497 rnc
->ssp
.is_valid
= true;
498 rnc
->ssp
.is_remote_node_context
= true;
499 rnc
->ssp
.function_number
= 0;
500 rnc
->ssp
.arbitration_wait_time
= 0;
504 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
505 * @sci_port The logical port on which we need to create the
506 * remote node context.
508 * @tci The remote node index for this remote node context.
510 * This routine will construct a dummy task context data structure. This
511 * structure will be posted to the hardwre to work around a scheduler error
515 static void scic_sds_port_construct_dummy_task(struct scic_sds_port
*sci_port
, u16 tci
)
517 struct scu_task_context
*task_context
;
519 task_context
= scic_sds_controller_get_task_context_buffer(sci_port
->owning_controller
, tci
);
521 memset(task_context
, 0, sizeof(struct scu_task_context
));
523 task_context
->abort
= 0;
524 task_context
->priority
= 0;
525 task_context
->initiator_request
= 1;
526 task_context
->connection_rate
= 1;
527 task_context
->protocol_engine_index
= 0;
528 task_context
->logical_port_index
= sci_port
->physical_port_index
;
529 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
530 task_context
->task_index
= scic_sds_io_tag_get_index(tci
);
531 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
532 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
534 task_context
->remote_node_index
= sci_port
->reserved_rni
;
535 task_context
->command_code
= 0;
537 task_context
->link_layer_control
= 0;
538 task_context
->do_not_dma_ssp_good_response
= 1;
539 task_context
->strict_ordering
= 0;
540 task_context
->control_frame
= 0;
541 task_context
->timeout_enable
= 0;
542 task_context
->block_guard_enable
= 0;
544 task_context
->address_modifier
= 0;
546 task_context
->task_phase
= 0x01;
549 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port
*sci_port
)
551 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
553 if (sci_port
->reserved_tci
!= SCU_DUMMY_INDEX
)
554 scic_controller_free_io_tag(scic
, sci_port
->reserved_tci
);
556 if (sci_port
->reserved_rni
!= SCU_DUMMY_INDEX
)
557 scic_sds_remote_node_table_release_remote_node_index(&scic
->available_remote_nodes
,
558 1, sci_port
->reserved_rni
);
560 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
561 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
565 * This method performs initialization of the supplied port. Initialization
566 * includes: - state machine initialization - member variable initialization
567 * - configuring the phy_mask
569 * @transport_layer_registers:
570 * @port_task_scheduler_registers:
571 * @port_configuration_regsiter:
573 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
574 * if the phy being added to the port
576 enum sci_status
scic_sds_port_initialize(
577 struct scic_sds_port
*this_port
,
578 void __iomem
*port_task_scheduler_registers
,
579 void __iomem
*port_configuration_regsiter
,
580 void __iomem
*viit_registers
)
582 this_port
->port_task_scheduler_registers
= port_task_scheduler_registers
;
583 this_port
->port_pe_configuration_register
= port_configuration_regsiter
;
584 this_port
->viit_registers
= viit_registers
;
590 * scic_port_get_properties() - This method simply returns the properties
591 * regarding the port, such as: physical index, protocols, sas address, etc.
592 * @port: this parameter specifies the port for which to retrieve the physical
594 * @properties: This parameter specifies the properties structure into which to
595 * copy the requested information.
597 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
598 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
599 * value is returned if the specified port is not valid. When this value is
600 * returned, no data is copied to the properties output parameter.
602 enum sci_status
scic_port_get_properties(
603 struct scic_sds_port
*port
,
604 struct scic_port_properties
*prop
)
606 if ((port
== NULL
) ||
607 (port
->logical_port_index
== SCIC_SDS_DUMMY_PORT
))
608 return SCI_FAILURE_INVALID_PORT
;
610 prop
->index
= port
->logical_port_index
;
611 prop
->phy_mask
= scic_sds_port_get_phys(port
);
612 scic_sds_port_get_sas_address(port
, &prop
->local
.sas_address
);
613 scic_sds_port_get_protocols(port
, &prop
->local
.protocols
);
614 scic_sds_port_get_attached_sas_address(port
, &prop
->remote
.sas_address
);
615 scic_sds_port_get_attached_protocols(port
, &prop
->remote
.protocols
);
621 * scic_port_hard_reset() - perform port hard reset
622 * @port: a handle corresponding to the SAS port to be hard reset.
623 * @reset_timeout: This parameter specifies the number of milliseconds in which
624 * the port reset operation should complete.
626 * The SCI User callback in scic_user_callbacks_t will only be called once for
627 * each phy in the SAS Port at completion of the hard reset sequence. Return a
628 * status indicating whether the hard reset started successfully. SCI_SUCCESS
629 * This value is returned if the hard reset operation started successfully.
631 enum sci_status
scic_port_hard_reset(
632 struct scic_sds_port
*port
,
635 return port
->state_handlers
->parent
.reset_handler(
636 &port
->parent
, reset_timeout
);
640 * This method assigns the direct attached device ID for this port.
642 * @param[in] this_port The port for which the direct attached device id is to
644 * @param[in] device_id The direct attached device ID to assign to the port.
645 * This will be the RNi for the device
647 void scic_sds_port_setup_transports(
648 struct scic_sds_port
*this_port
,
653 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
654 if (this_port
->active_phy_mask
& (1 << index
))
655 scic_sds_phy_setup_transport(this_port
->phy_table
[index
], device_id
);
661 * @this_port: This is the port on which the phy should be enabled.
662 * @the_phy: This is the specific phy which to enable.
663 * @do_notify_user: This parameter specifies whether to inform the user (via
664 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
666 * This function will activate the phy in the port.
667 * Activation includes: - adding
668 * the phy to the port - enabling the Protocol Engine in the silicon. -
669 * notifying the user that the link is up. none
671 static void scic_sds_port_activate_phy(struct scic_sds_port
*sci_port
,
672 struct scic_sds_phy
*sci_phy
,
675 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
676 struct sci_sas_identify_address_frame_protocols protocols
;
677 struct isci_host
*ihost
= sci_object_get_association(scic
);
679 scic_sds_phy_get_attached_phy_protocols(sci_phy
, &protocols
);
681 /* If this is sata port then the phy has already been resumed */
682 if (!protocols
.u
.bits
.stp_target
)
683 scic_sds_phy_resume(sci_phy
);
685 sci_port
->active_phy_mask
|= 1 << sci_phy
->phy_index
;
687 scic_sds_controller_clear_invalid_phy(scic
, sci_phy
);
689 if (do_notify_user
== true)
690 isci_port_link_up(ihost
, sci_port
, sci_phy
);
693 void scic_sds_port_deactivate_phy(struct scic_sds_port
*sci_port
,
694 struct scic_sds_phy
*sci_phy
,
697 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
698 struct isci_port
*iport
= sci_object_get_association(sci_port
);
699 struct isci_host
*ihost
= sci_object_get_association(scic
);
700 struct isci_phy
*iphy
= sci_object_get_association(sci_phy
);
702 sci_port
->active_phy_mask
&= ~(1 << sci_phy
->phy_index
);
704 sci_phy
->max_negotiated_speed
= SCI_SAS_NO_LINK_RATE
;
706 /* Re-assign the phy back to the LP as if it were a narrow port */
707 writel(sci_phy
->phy_index
,
708 &sci_port
->port_pe_configuration_register
[sci_phy
->phy_index
]);
710 if (do_notify_user
== true)
711 isci_port_link_down(ihost
, iphy
, iport
);
716 * @this_port: This is the port on which the phy should be disabled.
717 * @the_phy: This is the specific phy which to disabled.
719 * This function will disable the phy and report that the phy is not valid for
720 * this port object. None
722 static void scic_sds_port_invalid_link_up(
723 struct scic_sds_port
*sci_port
,
724 struct scic_sds_phy
*sci_phy
)
726 struct scic_sds_controller
*scic
=
727 scic_sds_port_get_controller(sci_port
);
730 * Check to see if we have alreay reported this link as bad and if
731 * not go ahead and tell the SCI_USER that we have discovered an
734 if ((scic
->invalid_phy_mask
& (1 << sci_phy
->phy_index
)) == 0) {
735 scic_sds_controller_set_invalid_phy(scic
, sci_phy
);
736 isci_port_invalid_link_up(scic
, sci_port
, sci_phy
);
741 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
742 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
743 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
744 * @do_notify_user: This parameter specifies whether to inform the user (via
745 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
747 * Determine if this phy can be assigned to this
748 * port . If the phy is not a valid PHY for
749 * this port then the function will notify the user. A PHY can only be
750 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
751 * the same port. none
753 static void scic_sds_port_general_link_up_handler(struct scic_sds_port
*sci_port
,
754 struct scic_sds_phy
*sci_phy
,
757 struct sci_sas_address port_sas_address
;
758 struct sci_sas_address phy_sas_address
;
760 scic_sds_port_get_attached_sas_address(sci_port
, &port_sas_address
);
761 scic_sds_phy_get_attached_sas_address(sci_phy
, &phy_sas_address
);
763 /* If the SAS address of the new phy matches the SAS address of
764 * other phys in the port OR this is the first phy in the port,
765 * then activate the phy and allow it to be used for operations
768 if ((phy_sas_address
.high
== port_sas_address
.high
&&
769 phy_sas_address
.low
== port_sas_address
.low
) ||
770 sci_port
->active_phy_mask
== 0) {
771 struct sci_base_state_machine
*sm
= &sci_port
->parent
.state_machine
;
773 scic_sds_port_activate_phy(sci_port
, sci_phy
, do_notify_user
);
774 if (sm
->current_state_id
== SCI_BASE_PORT_STATE_RESETTING
)
775 sci_base_state_machine_change_state(sm
, SCI_BASE_PORT_STATE_READY
);
777 scic_sds_port_invalid_link_up(sci_port
, sci_phy
);
783 * This method returns false if the port only has a single phy object assigned.
784 * If there are no phys or more than one phy then the method will return
786 * @this_port: The port for which the wide port condition is to be checked.
788 * bool true Is returned if this is a wide ported port. false Is returned if
789 * this is a narrow port.
791 static bool scic_sds_port_is_wide(struct scic_sds_port
*this_port
)
796 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
797 if (this_port
->phy_table
[index
] != NULL
) {
802 return phy_count
!= 1;
806 * This method is called by the PHY object when the link is detected. if the
807 * port wants the PHY to continue on to the link up state then the port
808 * layer must return true. If the port object returns false the phy object
809 * must halt its attempt to go link up.
810 * @this_port: The port associated with the phy object.
811 * @the_phy: The phy object that is trying to go link up.
813 * true if the phy object can continue to the link up condition. true Is
814 * returned if this phy can continue to the ready state. false Is returned if
815 * can not continue on to the ready state. This notification is in place for
816 * wide ports and direct attached phys. Since there are no wide ported SATA
817 * devices this could become an invalid port configuration.
819 bool scic_sds_port_link_detected(
820 struct scic_sds_port
*this_port
,
821 struct scic_sds_phy
*the_phy
)
823 struct sci_sas_identify_address_frame_protocols protocols
;
825 scic_sds_phy_get_attached_phy_protocols(the_phy
, &protocols
);
828 (this_port
->logical_port_index
!= SCIC_SDS_DUMMY_PORT
)
829 && (protocols
.u
.bits
.stp_target
)
830 && scic_sds_port_is_wide(this_port
)
832 scic_sds_port_invalid_link_up(this_port
, the_phy
);
841 * This method is the entry point for the phy to inform the port that it is now
847 void scic_sds_port_link_up(
848 struct scic_sds_port
*this_port
,
849 struct scic_sds_phy
*the_phy
)
851 the_phy
->is_in_link_training
= false;
853 this_port
->state_handlers
->link_up_handler(this_port
, the_phy
);
857 * This method is the entry point for the phy to inform the port that it is no
858 * longer in a ready state
863 void scic_sds_port_link_down(
864 struct scic_sds_port
*this_port
,
865 struct scic_sds_phy
*the_phy
)
867 this_port
->state_handlers
->link_down_handler(this_port
, the_phy
);
871 * This method is called to start an IO request on this port.
878 enum sci_status
scic_sds_port_start_io(
879 struct scic_sds_port
*this_port
,
880 struct scic_sds_remote_device
*the_device
,
881 struct scic_sds_request
*the_io_request
)
883 return this_port
->state_handlers
->start_io_handler(
884 this_port
, the_device
, the_io_request
);
888 * This method is called to complete an IO request to the port.
895 enum sci_status
scic_sds_port_complete_io(
896 struct scic_sds_port
*this_port
,
897 struct scic_sds_remote_device
*the_device
,
898 struct scic_sds_request
*the_io_request
)
900 return this_port
->state_handlers
->complete_io_handler(
901 this_port
, the_device
, the_io_request
);
905 * This method is provided to timeout requests for port operations. Mostly its
906 * for the port reset operation.
910 static void scic_sds_port_timeout_handler(void *port
)
912 struct scic_sds_port
*sci_port
= port
;
915 current_state
= sci_base_state_machine_get_state(
916 &sci_port
->parent
.state_machine
);
918 if (current_state
== SCI_BASE_PORT_STATE_RESETTING
) {
920 * if the port is still in the resetting state then the
921 * timeout fired before the reset completed.
923 sci_base_state_machine_change_state(
924 &sci_port
->parent
.state_machine
,
925 SCI_BASE_PORT_STATE_FAILED
);
926 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPED
) {
928 * if the port is stopped then the start request failed
929 * In this case stay in the stopped state.
931 dev_err(sciport_to_dev(sci_port
),
932 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
935 } else if (current_state
== SCI_BASE_PORT_STATE_STOPPING
) {
937 * if the port is still stopping then the stop has not
940 isci_port_stop_complete(
941 scic_sds_port_get_controller(sci_port
),
943 SCI_FAILURE_TIMEOUT
);
946 * The port is in the ready state and we have a timer
947 * reporting a timeout this should not happen.
949 dev_err(sciport_to_dev(sci_port
),
950 "%s: SCIC Port 0x%p is processing a timeout operation "
958 /* --------------------------------------------------------------------------- */
961 * This function updates the hardwares VIIT entry for this port.
965 static void scic_sds_port_update_viit_entry(struct scic_sds_port
*this_port
)
967 struct sci_sas_address sas_address
;
969 scic_sds_port_get_sas_address(this_port
, &sas_address
);
971 writel(sas_address
.high
,
972 &this_port
->viit_registers
->initiator_sas_address_hi
);
973 writel(sas_address
.low
,
974 &this_port
->viit_registers
->initiator_sas_address_lo
);
976 /* This value get cleared just in case its not already cleared */
977 writel(0, &this_port
->viit_registers
->reserved
);
979 /* We are required to update the status register last */
980 writel(SCU_VIIT_ENTRY_ID_VIIT
|
981 SCU_VIIT_IPPT_INITIATOR
|
982 ((1 << this_port
->physical_port_index
) << SCU_VIIT_ENTRY_LPVIE_SHIFT
) |
983 SCU_VIIT_STATUS_ALL_VALID
,
984 &this_port
->viit_registers
->status
);
988 * This method returns the maximum allowed speed for data transfers on this
989 * port. This maximum allowed speed evaluates to the maximum speed of the
990 * slowest phy in the port.
991 * @this_port: This parameter specifies the port for which to retrieve the
992 * maximum allowed speed.
994 * This method returns the maximum negotiated speed of the slowest phy in the
997 enum sci_sas_link_rate
scic_sds_port_get_max_allowed_speed(
998 struct scic_sds_port
*this_port
)
1001 enum sci_sas_link_rate max_allowed_speed
= SCI_SAS_600_GB
;
1002 struct scic_sds_phy
*phy
= NULL
;
1005 * Loop through all of the phys in this port and find the phy with the
1006 * lowest maximum link rate. */
1007 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1008 phy
= this_port
->phy_table
[index
];
1011 && (scic_sds_port_active_phy(this_port
, phy
) == true)
1012 && (phy
->max_negotiated_speed
< max_allowed_speed
)
1014 max_allowed_speed
= phy
->max_negotiated_speed
;
1017 return max_allowed_speed
;
1022 * This method passes the event to core user.
1023 * @this_port: The port that a BCN happens.
1024 * @this_phy: The phy that receives BCN.
1027 void scic_sds_port_broadcast_change_received(
1028 struct scic_sds_port
*sci_port
,
1029 struct scic_sds_phy
*sci_phy
)
1031 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1032 struct isci_host
*ihost
= sci_object_get_association(scic
);
1034 /* notify the user. */
1035 isci_port_bc_change_received(ihost
, sci_port
, sci_phy
);
1040 * This API methhod enables the broadcast change notification from underneath
1042 * @this_port: The port that a BCN had been disabled from.
1045 void scic_port_enable_broadcast_change_notification(
1046 struct scic_sds_port
*port
)
1048 struct scic_sds_phy
*phy
;
1052 /* Loop through all of the phys to enable BCN. */
1053 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1054 phy
= port
->phy_table
[index
];
1057 readl(&phy
->link_layer_registers
->link_layer_control
);
1059 /* clear the bit by writing 1. */
1060 writel(register_value
,
1061 &phy
->link_layer_registers
->link_layer_control
);
1067 * ****************************************************************************
1068 * * READY SUBSTATE HANDLERS
1069 * **************************************************************************** */
1073 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1076 * This method is the general ready state stop handler for the struct scic_sds_port
1077 * object. This function will transition the ready substate machine to its
1078 * final state. enum sci_status SCI_SUCCESS
1080 static enum sci_status
scic_sds_port_ready_substate_stop_handler(
1081 struct sci_base_port
*port
)
1083 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1085 sci_base_state_machine_change_state(
1086 &this_port
->parent
.state_machine
,
1087 SCI_BASE_PORT_STATE_STOPPING
1094 * This method is the general ready substate complete io handler for the
1095 * struct scic_sds_port object. This function decrments the outstanding request count
1096 * for this port object. enum sci_status SCI_SUCCESS
1098 static enum sci_status
scic_sds_port_ready_substate_complete_io_handler(
1099 struct scic_sds_port
*port
,
1100 struct scic_sds_remote_device
*device
,
1101 struct scic_sds_request
*io_request
)
1103 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1105 scic_sds_port_decrement_request_count(this_port
);
1110 static enum sci_status
scic_sds_port_ready_substate_add_phy_handler(
1111 struct sci_base_port
*port
,
1112 struct sci_base_phy
*phy
)
1114 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1115 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1116 enum sci_status status
;
1118 status
= scic_sds_port_set_phy(this_port
, this_phy
);
1120 if (status
== SCI_SUCCESS
) {
1121 scic_sds_port_general_link_up_handler(this_port
, this_phy
, true);
1123 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1125 sci_base_state_machine_change_state(
1126 &this_port
->ready_substate_machine
,
1127 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1135 static enum sci_status
scic_sds_port_ready_substate_remove_phy_handler(
1136 struct sci_base_port
*port
,
1137 struct sci_base_phy
*phy
)
1139 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1140 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1141 enum sci_status status
;
1143 status
= scic_sds_port_clear_phy(this_port
, this_phy
);
1145 if (status
== SCI_SUCCESS
) {
1146 scic_sds_port_deactivate_phy(this_port
, this_phy
, true);
1148 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_RECONFIGURING
;
1150 sci_base_state_machine_change_state(
1151 &this_port
->ready_substate_machine
,
1152 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1160 * ****************************************************************************
1161 * * READY SUBSTATE WAITING HANDLERS
1162 * **************************************************************************** */
1166 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1168 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1170 * This method is the ready waiting substate link up handler for the
1171 * struct scic_sds_port object. This methos will report the link up condition for
1172 * this port and will transition to the ready operational substate. none
1174 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1175 struct scic_sds_port
*this_port
,
1176 struct scic_sds_phy
*the_phy
)
1179 * Since this is the first phy going link up for the port we can just enable
1180 * it and continue. */
1181 scic_sds_port_activate_phy(this_port
, the_phy
, true);
1183 sci_base_state_machine_change_state(
1184 &this_port
->ready_substate_machine
,
1185 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1190 * This method is the ready waiting substate start io handler for the
1191 * struct scic_sds_port object. The port object can not accept new requests so the
1192 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1194 static enum sci_status
scic_sds_port_ready_waiting_substate_start_io_handler(
1195 struct scic_sds_port
*port
,
1196 struct scic_sds_remote_device
*device
,
1197 struct scic_sds_request
*io_request
)
1199 return SCI_FAILURE_INVALID_STATE
;
1203 * ****************************************************************************
1204 * * READY SUBSTATE OPERATIONAL HANDLERS
1205 * **************************************************************************** */
1209 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1211 * @timeout: This is the timeout for the reset request to complete.
1213 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1216 sci_status
scic_sds_port_ready_operational_substate_reset_handler(
1217 struct sci_base_port
*port
,
1220 enum sci_status status
= SCI_FAILURE_INVALID_PHY
;
1222 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)port
;
1223 struct scic_sds_phy
*selected_phy
= NULL
;
1226 /* Select a phy on which we can send the hard reset request. */
1228 (phy_index
< SCI_MAX_PHYS
) && (selected_phy
== NULL
);
1230 selected_phy
= sci_port
->phy_table
[phy_index
];
1232 if ((selected_phy
!= NULL
) &&
1233 !scic_sds_port_active_phy(sci_port
, selected_phy
)) {
1235 * We found a phy but it is not ready select
1238 selected_phy
= NULL
;
1242 /* If we have a phy then go ahead and start the reset procedure */
1243 if (selected_phy
!= NULL
) {
1244 status
= scic_sds_phy_reset(selected_phy
);
1246 if (status
== SCI_SUCCESS
) {
1247 isci_timer_start(sci_port
->timer_handle
, timeout
);
1248 sci_port
->not_ready_reason
=
1249 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED
;
1251 sci_base_state_machine_change_state(
1252 &sci_port
->parent
.state_machine
,
1253 SCI_BASE_PORT_STATE_RESETTING
);
1261 * scic_sds_port_ready_operational_substate_link_up_handler() -
1262 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1264 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1266 * This method is the ready operational substate link up handler for the
1267 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1268 * gone link up. none
1270 static void scic_sds_port_ready_operational_substate_link_up_handler(
1271 struct scic_sds_port
*this_port
,
1272 struct scic_sds_phy
*the_phy
)
1274 scic_sds_port_general_link_up_handler(this_port
, the_phy
, true);
1278 * scic_sds_port_ready_operational_substate_link_down_handler() -
1279 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1281 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1283 * This method is the ready operational substate link down handler for the
1284 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1285 * gone link down and if this is the last phy in the port the port will change
1286 * state to the ready waiting substate. none
1288 static void scic_sds_port_ready_operational_substate_link_down_handler(
1289 struct scic_sds_port
*sci_port
,
1290 struct scic_sds_phy
*sci_phy
)
1292 scic_sds_port_deactivate_phy(sci_port
, sci_phy
, true);
1295 * If there are no active phys left in the port, then transition
1296 * the port to the WAITING state until such time as a phy goes
1298 if (sci_port
->active_phy_mask
== 0)
1299 sci_base_state_machine_change_state(&sci_port
->ready_substate_machine
,
1300 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1304 * This method is the ready operational substate start io handler for the
1305 * struct scic_sds_port object. This function incremetns the outstanding request
1306 * count for this port object. enum sci_status SCI_SUCCESS
1308 static enum sci_status
scic_sds_port_ready_operational_substate_start_io_handler(
1309 struct scic_sds_port
*port
,
1310 struct scic_sds_remote_device
*device
,
1311 struct scic_sds_request
*io_request
)
1313 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1315 scic_sds_port_increment_request_count(this_port
);
1321 * ****************************************************************************
1322 * * READY SUBSTATE OPERATIONAL HANDLERS
1323 * **************************************************************************** */
1326 * scic_sds_port_ready_configuring_substate_add_phy_handler() -
1327 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1330 * This is the default method for a port add phy request. It will report a
1331 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1333 static enum sci_status
scic_sds_port_ready_configuring_substate_add_phy_handler(
1334 struct sci_base_port
*port
,
1335 struct sci_base_phy
*phy
)
1337 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1338 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1339 enum sci_status status
;
1341 status
= scic_sds_port_set_phy(this_port
, this_phy
);
1343 if (status
== SCI_SUCCESS
) {
1344 scic_sds_port_general_link_up_handler(this_port
, this_phy
, true);
1347 * Re-enter the configuring state since this may be the last phy in
1349 sci_base_state_machine_change_state(
1350 &this_port
->ready_substate_machine
,
1351 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1359 * scic_sds_port_ready_configuring_substate_remove_phy_handler() -
1360 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1363 * This is the default method for a port remove phy request. It will report a
1364 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1366 static enum sci_status
scic_sds_port_ready_configuring_substate_remove_phy_handler(
1367 struct sci_base_port
*port
,
1368 struct sci_base_phy
*phy
)
1370 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1371 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
1372 enum sci_status status
;
1374 status
= scic_sds_port_clear_phy(this_port
, this_phy
);
1376 if (status
== SCI_SUCCESS
) {
1377 scic_sds_port_deactivate_phy(this_port
, this_phy
, true);
1380 * Re-enter the configuring state since this may be the last phy in
1382 sci_base_state_machine_change_state(
1383 &this_port
->ready_substate_machine
,
1384 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1392 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1393 * @port: This is the port that is being requested to complete the io request.
1394 * @device: This is the device on which the io is completing.
1396 * This method will decrement the outstanding request count for this port. If
1397 * the request count goes to 0 then the port can be reprogrammed with its new
1400 static enum sci_status
scic_sds_port_ready_configuring_substate_complete_io_handler(
1401 struct scic_sds_port
*port
,
1402 struct scic_sds_remote_device
*device
,
1403 struct scic_sds_request
*io_request
)
1405 scic_sds_port_decrement_request_count(port
);
1407 if (port
->started_request_count
== 0) {
1408 sci_base_state_machine_change_state(
1409 &port
->ready_substate_machine
,
1410 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1417 static enum sci_status
default_port_handler(struct sci_base_port
*base_port
, const char *func
)
1419 struct scic_sds_port
*sci_port
;
1421 sci_port
= container_of(base_port
, typeof(*sci_port
), parent
);
1422 dev_warn(sciport_to_dev(sci_port
),
1423 "%s: in wrong state: %d\n", func
,
1424 sci_base_state_machine_get_state(&base_port
->state_machine
));
1425 return SCI_FAILURE_INVALID_STATE
;
1428 static enum sci_status
scic_sds_port_default_start_handler(struct sci_base_port
*base_port
)
1430 return default_port_handler(base_port
, __func__
);
1433 static enum sci_status
scic_sds_port_default_stop_handler(struct sci_base_port
*base_port
)
1435 return default_port_handler(base_port
, __func__
);
1438 static enum sci_status
scic_sds_port_default_destruct_handler(struct sci_base_port
*base_port
)
1440 return default_port_handler(base_port
, __func__
);
1443 static enum sci_status
scic_sds_port_default_reset_handler(struct sci_base_port
*base_port
,
1446 return default_port_handler(base_port
, __func__
);
1449 static enum sci_status
scic_sds_port_default_add_phy_handler(struct sci_base_port
*base_port
,
1450 struct sci_base_phy
*base_phy
)
1452 return default_port_handler(base_port
, __func__
);
1455 static enum sci_status
scic_sds_port_default_remove_phy_handler(struct sci_base_port
*base_port
,
1456 struct sci_base_phy
*base_phy
)
1458 return default_port_handler(base_port
, __func__
);
1462 * scic_sds_port_default_frame_handler
1463 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1466 * This is the default method for a port unsolicited frame request. It will
1467 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1468 * possible to receive an unsolicited frame directed to a port object? It
1469 * seems possible if we implementing virtual functions but until then?
1471 static enum sci_status
scic_sds_port_default_frame_handler(struct scic_sds_port
*sci_port
,
1474 struct scic_sds_controller
*scic
= scic_sds_port_get_controller(sci_port
);
1476 default_port_handler(&sci_port
->parent
, __func__
);
1477 scic_sds_controller_release_frame(scic
, frame_index
);
1479 return SCI_FAILURE_INVALID_STATE
;
1482 static enum sci_status
scic_sds_port_default_event_handler(struct scic_sds_port
*sci_port
,
1485 return default_port_handler(&sci_port
->parent
, __func__
);
1488 static void scic_sds_port_default_link_up_handler(struct scic_sds_port
*sci_port
,
1489 struct scic_sds_phy
*sci_phy
)
1491 default_port_handler(&sci_port
->parent
, __func__
);
1494 static void scic_sds_port_default_link_down_handler(struct scic_sds_port
*sci_port
,
1495 struct scic_sds_phy
*sci_phy
)
1497 default_port_handler(&sci_port
->parent
, __func__
);
1500 static enum sci_status
scic_sds_port_default_start_io_handler(struct scic_sds_port
*sci_port
,
1501 struct scic_sds_remote_device
*sci_dev
,
1502 struct scic_sds_request
*sci_req
)
1504 return default_port_handler(&sci_port
->parent
, __func__
);
1507 static enum sci_status
scic_sds_port_default_complete_io_handler(struct scic_sds_port
*sci_port
,
1508 struct scic_sds_remote_device
*sci_dev
,
1509 struct scic_sds_request
*sci_req
)
1511 return default_port_handler(&sci_port
->parent
, __func__
);
1516 static struct scic_sds_port_state_handler
1517 scic_sds_port_ready_substate_handler_table
[SCIC_SDS_PORT_READY_MAX_SUBSTATES
] =
1519 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1522 scic_sds_port_default_start_handler
,
1523 scic_sds_port_ready_substate_stop_handler
,
1524 scic_sds_port_default_destruct_handler
,
1525 scic_sds_port_default_reset_handler
,
1526 scic_sds_port_ready_substate_add_phy_handler
,
1527 scic_sds_port_default_remove_phy_handler
1529 scic_sds_port_default_frame_handler
,
1530 scic_sds_port_default_event_handler
,
1531 scic_sds_port_ready_waiting_substate_link_up_handler
,
1532 scic_sds_port_default_link_down_handler
,
1533 scic_sds_port_ready_waiting_substate_start_io_handler
,
1534 scic_sds_port_ready_substate_complete_io_handler
,
1536 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1539 scic_sds_port_default_start_handler
,
1540 scic_sds_port_ready_substate_stop_handler
,
1541 scic_sds_port_default_destruct_handler
,
1542 scic_sds_port_ready_operational_substate_reset_handler
,
1543 scic_sds_port_ready_substate_add_phy_handler
,
1544 scic_sds_port_ready_substate_remove_phy_handler
1546 scic_sds_port_default_frame_handler
,
1547 scic_sds_port_default_event_handler
,
1548 scic_sds_port_ready_operational_substate_link_up_handler
,
1549 scic_sds_port_ready_operational_substate_link_down_handler
,
1550 scic_sds_port_ready_operational_substate_start_io_handler
,
1551 scic_sds_port_ready_substate_complete_io_handler
1553 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1556 scic_sds_port_default_start_handler
,
1557 scic_sds_port_ready_substate_stop_handler
,
1558 scic_sds_port_default_destruct_handler
,
1559 scic_sds_port_default_reset_handler
,
1560 scic_sds_port_ready_configuring_substate_add_phy_handler
,
1561 scic_sds_port_ready_configuring_substate_remove_phy_handler
1563 scic_sds_port_default_frame_handler
,
1564 scic_sds_port_default_event_handler
,
1565 scic_sds_port_default_link_up_handler
,
1566 scic_sds_port_default_link_down_handler
,
1567 scic_sds_port_default_start_io_handler
,
1568 scic_sds_port_ready_configuring_substate_complete_io_handler
1573 * scic_sds_port_set_ready_state_handlers() -
1575 * This macro sets the port ready substate handlers.
1577 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1578 scic_sds_port_set_state_handlers(\
1579 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1583 * ******************************************************************************
1584 * * PORT STATE PRIVATE METHODS
1585 * ****************************************************************************** */
1589 * @this_port: This is the struct scic_sds_port object to suspend.
1591 * This method will susped the port task scheduler for this port object. none
1594 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port
*port
)
1596 u32 pts_control_value
;
1598 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1599 pts_control_value
|= SCU_PTSxCR_GEN_BIT(SUSPEND
);
1600 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1604 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1605 * @sci_port: port to post task
1607 * Prevent the hardware scheduler from posting new requests to the front
1608 * of the scheduler queue causing a starvation problem for currently
1612 static void scic_sds_port_post_dummy_request(struct scic_sds_port
*sci_port
)
1615 struct scu_task_context
*task_context
;
1616 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1617 u16 tci
= sci_port
->reserved_tci
;
1619 task_context
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1621 task_context
->abort
= 0;
1623 command
= SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
1624 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1627 scic_sds_controller_post_request(scic
, command
);
1631 * This routine will abort the dummy request. This will alow the hardware to
1632 * power down parts of the silicon to save power.
1634 * @sci_port: The port on which the task must be aborted.
1637 static void scic_sds_port_abort_dummy_request(struct scic_sds_port
*sci_port
)
1639 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1640 u16 tci
= sci_port
->reserved_tci
;
1641 struct scu_task_context
*tc
;
1644 tc
= scic_sds_controller_get_task_context_buffer(scic
, tci
);
1648 command
= SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT
|
1649 sci_port
->physical_port_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
|
1652 scic_sds_controller_post_request(scic
, command
);
1657 * @this_port: This is the struct scic_sds_port object to resume.
1659 * This method will resume the port task scheduler for this port object. none
1662 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port
*port
)
1664 u32 pts_control_value
;
1666 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
1667 pts_control_value
&= ~SCU_PTSxCR_GEN_BIT(SUSPEND
);
1668 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
1672 * ******************************************************************************
1673 * * PORT READY SUBSTATE METHODS
1674 * ****************************************************************************** */
1678 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1680 * This method will perform the actions required by the struct scic_sds_port on
1681 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1682 * port for any ready phys. If there is at least one phy in a ready state then
1683 * the port transitions to the ready operational substate. none
1685 static void scic_sds_port_ready_substate_waiting_enter(
1686 struct sci_base_object
*object
)
1688 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1690 scic_sds_port_set_ready_state_handlers(
1691 this_port
, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1694 scic_sds_port_suspend_port_task_scheduler(this_port
);
1696 this_port
->not_ready_reason
= SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
;
1698 if (this_port
->active_phy_mask
!= 0) {
1699 /* At least one of the phys on the port is ready */
1700 sci_base_state_machine_change_state(
1701 &this_port
->ready_substate_machine
,
1702 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1709 * @object: This is the struct sci_base_object which is cast to a
1710 * struct scic_sds_port object.
1712 * This function will perform the actions required by the struct scic_sds_port
1713 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1714 * the state handlers for the port object, notifies the SCI User that the port
1715 * is ready, and resumes port operations. none
1717 static void scic_sds_port_ready_substate_operational_enter(
1718 struct sci_base_object
*object
)
1721 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)object
;
1722 struct scic_sds_controller
*scic
=
1723 scic_sds_port_get_controller(sci_port
);
1724 struct isci_host
*ihost
= sci_object_get_association(scic
);
1725 struct isci_port
*iport
= sci_object_get_association(sci_port
);
1727 scic_sds_port_set_ready_state_handlers(
1729 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1731 isci_port_ready(ihost
, iport
);
1733 for (index
= 0; index
< SCI_MAX_PHYS
; index
++) {
1734 if (sci_port
->phy_table
[index
]) {
1735 writel(sci_port
->physical_port_index
,
1736 &sci_port
->port_pe_configuration_register
[
1737 sci_port
->phy_table
[index
]->phy_index
]);
1741 scic_sds_port_update_viit_entry(sci_port
);
1743 scic_sds_port_resume_port_task_scheduler(sci_port
);
1746 * Post the dummy task for the port so the hardware can schedule
1749 scic_sds_port_post_dummy_request(sci_port
);
1754 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1756 * This method will perform the actions required by the struct scic_sds_port on
1757 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1758 * the port not ready and suspends the port task scheduler. none
1760 static void scic_sds_port_ready_substate_operational_exit(
1761 struct sci_base_object
*object
)
1763 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)object
;
1764 struct scic_sds_controller
*scic
=
1765 scic_sds_port_get_controller(sci_port
);
1766 struct isci_host
*ihost
= sci_object_get_association(scic
);
1767 struct isci_port
*iport
= sci_object_get_association(sci_port
);
1770 * Kill the dummy task for this port if it has not yet posted
1771 * the hardware will treat this as a NOP and just return abort
1774 scic_sds_port_abort_dummy_request(sci_port
);
1776 isci_port_not_ready(ihost
, iport
);
1780 * ******************************************************************************
1781 * * PORT READY CONFIGURING METHODS
1782 * ****************************************************************************** */
1785 * scic_sds_port_ready_substate_configuring_enter() -
1786 * @object: This is the struct sci_base_object which is cast to a
1787 * struct scic_sds_port object.
1789 * This method will perform the actions required by the struct scic_sds_port on
1790 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1791 * the port not ready and suspends the port task scheduler. none
1793 static void scic_sds_port_ready_substate_configuring_enter(
1794 struct sci_base_object
*object
)
1796 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)object
;
1797 struct scic_sds_controller
*scic
=
1798 scic_sds_port_get_controller(sci_port
);
1799 struct isci_host
*ihost
= sci_object_get_association(scic
);
1800 struct isci_port
*iport
= sci_object_get_association(sci_port
);
1802 scic_sds_port_set_ready_state_handlers(
1804 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
1806 if (sci_port
->active_phy_mask
== 0) {
1807 isci_port_not_ready(ihost
, iport
);
1809 sci_base_state_machine_change_state(
1810 &sci_port
->ready_substate_machine
,
1811 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
1812 } else if (sci_port
->started_request_count
== 0)
1813 sci_base_state_machine_change_state(
1814 &sci_port
->ready_substate_machine
,
1815 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
1818 static void scic_sds_port_ready_substate_configuring_exit(
1819 struct sci_base_object
*object
)
1821 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)object
;
1823 scic_sds_port_suspend_port_task_scheduler(this_port
);
1826 /* --------------------------------------------------------------------------- */
1828 static const struct sci_base_state scic_sds_port_ready_substate_table
[] = {
1829 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING
] = {
1830 .enter_state
= scic_sds_port_ready_substate_waiting_enter
,
1832 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
] = {
1833 .enter_state
= scic_sds_port_ready_substate_operational_enter
,
1834 .exit_state
= scic_sds_port_ready_substate_operational_exit
1836 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
] = {
1837 .enter_state
= scic_sds_port_ready_substate_configuring_enter
,
1838 .exit_state
= scic_sds_port_ready_substate_configuring_exit
1844 * @port: This is the struct scic_sds_port object on which the io request count will
1846 * @device: This is the struct scic_sds_remote_device object to which the io request
1847 * is being directed. This parameter is not required to complete this
1849 * @io_request: This is the request that is being completed on this port
1850 * object. This parameter is not required to complete this operation.
1852 * This is a general complete io request handler for the struct scic_sds_port object.
1853 * enum sci_status SCI_SUCCESS
1855 static enum sci_status
scic_sds_port_general_complete_io_handler(
1856 struct scic_sds_port
*port
,
1857 struct scic_sds_remote_device
*device
,
1858 struct scic_sds_request
*io_request
)
1860 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1862 scic_sds_port_decrement_request_count(this_port
);
1868 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1870 * @port: This is the struct sci_base_port object which is cast into a
1871 * struct scic_sds_port object.
1873 * This function takes the struct scic_sds_port from a stopped state and
1874 * attempts to start it. To start a port it must have no assiged devices and
1875 * it must have at least one phy assigned to it. If those conditions are
1876 * met then the port can transition to the ready state.
1878 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1879 * This struct scic_sds_port object could not be started because the port
1880 * configuration is not valid.
1882 * the start request is successful and the struct scic_sds_port object
1883 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1885 static enum sci_status
1886 scic_sds_port_stopped_state_start_handler(struct sci_base_port
*base_port
)
1888 struct scic_sds_port
*sci_port
=
1889 container_of(base_port
, typeof(*sci_port
), parent
);
1890 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
1891 struct isci_host
*ihost
= sci_object_get_association(scic
);
1892 enum sci_status status
= SCI_SUCCESS
;
1895 if (sci_port
->assigned_device_count
> 0) {
1897 * @todo This is a start failure operation because
1898 * there are still devices assigned to this port.
1899 * There must be no devices assigned to a port on a
1902 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
1905 sci_port
->timer_handle
=
1906 isci_timer_create(ihost
,
1908 scic_sds_port_timeout_handler
);
1910 if (!sci_port
->timer_handle
)
1911 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1913 if (sci_port
->reserved_rni
== SCU_DUMMY_INDEX
) {
1914 u16 rni
= scic_sds_remote_node_table_allocate_remote_node(
1915 &scic
->available_remote_nodes
, 1);
1917 if (rni
!= SCU_DUMMY_INDEX
)
1918 scic_sds_port_construct_dummy_rnc(sci_port
, rni
);
1920 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1921 sci_port
->reserved_rni
= rni
;
1924 if (sci_port
->reserved_tci
== SCU_DUMMY_INDEX
) {
1925 /* Allocate a TCI and remove the sequence nibble */
1926 u16 tci
= scic_controller_allocate_io_tag(scic
);
1928 if (tci
!= SCU_DUMMY_INDEX
)
1929 scic_sds_port_construct_dummy_task(sci_port
, tci
);
1931 status
= SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1932 sci_port
->reserved_tci
= tci
;
1935 if (status
== SCI_SUCCESS
) {
1936 phy_mask
= scic_sds_port_get_phys(sci_port
);
1939 * There are one or more phys assigned to this port. Make sure
1940 * the port's phy mask is in fact legal and supported by the
1943 if (scic_sds_port_is_phy_mask_valid(sci_port
, phy_mask
) == true) {
1944 sci_base_state_machine_change_state(&base_port
->state_machine
,
1945 SCI_BASE_PORT_STATE_READY
);
1949 status
= SCI_FAILURE
;
1952 if (status
!= SCI_SUCCESS
)
1953 scic_sds_port_destroy_dummy_resources(sci_port
);
1960 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1963 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1964 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1965 * stop request is successful as the struct scic_sds_port object is already stopped.
1967 static enum sci_status
scic_sds_port_stopped_state_stop_handler(
1968 struct sci_base_port
*port
)
1970 /* We are already stopped so there is nothing to do here */
1976 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1979 * This method takes the struct scic_sds_port that is in a stopped state and handles
1980 * the destruct request. The stopped state is the only state in which the
1981 * struct scic_sds_port can be destroyed. This function causes the port object to
1982 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
1984 static enum sci_status
scic_sds_port_stopped_state_destruct_handler(
1985 struct sci_base_port
*port
)
1987 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
1989 sci_base_state_machine_stop(&this_port
->parent
.state_machine
);
1996 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1998 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2001 * This method takes the struct scic_sds_port that is in a stopped state and handles
2002 * the add phy request. In MPC mode the only time a phy can be added to a port
2003 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2004 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2005 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2007 static enum sci_status
scic_sds_port_stopped_state_add_phy_handler(
2008 struct sci_base_port
*port
,
2009 struct sci_base_phy
*phy
)
2011 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2012 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
2013 struct sci_sas_address port_sas_address
;
2015 /* Read the port assigned SAS Address if there is one */
2016 scic_sds_port_get_sas_address(this_port
, &port_sas_address
);
2018 if (port_sas_address
.high
!= 0 && port_sas_address
.low
!= 0) {
2019 struct sci_sas_address phy_sas_address
;
2022 * Make sure that the PHY SAS Address matches the SAS Address
2024 scic_sds_phy_get_sas_address(this_phy
, &phy_sas_address
);
2027 (port_sas_address
.high
!= phy_sas_address
.high
)
2028 || (port_sas_address
.low
!= phy_sas_address
.low
)
2030 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
;
2034 return scic_sds_port_set_phy(this_port
, this_phy
);
2040 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2042 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2045 * This method takes the struct scic_sds_port that is in a stopped state and handles
2046 * the remove phy request. In MPC mode the only time a phy can be removed from
2047 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2048 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2049 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2051 static enum sci_status
scic_sds_port_stopped_state_remove_phy_handler(
2052 struct sci_base_port
*port
,
2053 struct sci_base_phy
*phy
)
2055 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2056 struct scic_sds_phy
*this_phy
= (struct scic_sds_phy
*)phy
;
2058 return scic_sds_port_clear_phy(this_port
, this_phy
);
2062 * ****************************************************************************
2063 * * READY STATE HANDLERS
2064 * **************************************************************************** */
2067 * ****************************************************************************
2068 * * RESETTING STATE HANDLERS
2069 * **************************************************************************** */
2072 * ****************************************************************************
2073 * * STOPPING STATE HANDLERS
2074 * **************************************************************************** */
2078 * @port: This is the struct scic_sds_port object on which the io request count will
2080 * @device: This is the struct scic_sds_remote_device object to which the io request
2081 * is being directed. This parameter is not required to complete this
2083 * @io_request: This is the request that is being completed on this port
2084 * object. This parameter is not required to complete this operation.
2086 * This method takes the struct scic_sds_port that is in a stopping state and handles
2087 * the complete io request. Should the request count reach 0 then the port
2088 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2090 static enum sci_status
scic_sds_port_stopping_state_complete_io_handler(
2091 struct scic_sds_port
*sci_port
,
2092 struct scic_sds_remote_device
*device
,
2093 struct scic_sds_request
*io_request
)
2095 scic_sds_port_decrement_request_count(sci_port
);
2097 if (sci_port
->started_request_count
== 0) {
2098 sci_base_state_machine_change_state(&sci_port
->parent
.state_machine
,
2099 SCI_BASE_PORT_STATE_STOPPED
);
2106 * ****************************************************************************
2107 * * RESETTING STATE HANDLERS
2108 * **************************************************************************** */
2112 * @port: This is the port object which is being requested to stop.
2114 * This method will stop a failed port. This causes a transition to the
2115 * stopping state. enum sci_status SCI_SUCCESS
2117 static enum sci_status
scic_sds_port_reset_state_stop_handler(
2118 struct sci_base_port
*port
)
2120 struct scic_sds_port
*this_port
= (struct scic_sds_port
*)port
;
2122 sci_base_state_machine_change_state(
2123 &this_port
->parent
.state_machine
,
2124 SCI_BASE_PORT_STATE_STOPPING
2132 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2135 * This method will transition a failed port to its ready state. The port
2136 * failed because a hard reset request timed out but at some time later one or
2137 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2139 static void scic_sds_port_reset_state_link_up_handler(
2140 struct scic_sds_port
*this_port
,
2141 struct scic_sds_phy
*phy
)
2144 * / @todo We should make sure that the phy that has gone link up is the same
2145 * / one on which we sent the reset. It is possible that the phy on
2146 * / which we sent the reset is not the one that has gone link up and we
2147 * / want to make sure that phy being reset comes back. Consider the
2148 * / case where a reset is sent but before the hardware processes the
2149 * / reset it get a link up on the port because of a hot plug event.
2150 * / because of the reset request this phy will go link down almost
2154 * In the resetting state we don't notify the user regarding
2155 * link up and link down notifications. */
2156 scic_sds_port_general_link_up_handler(this_port
, phy
, false);
2161 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2164 * This method process link down notifications that occur during a port reset
2165 * operation. Link downs can occur during the reset operation. enum sci_status
2168 static void scic_sds_port_reset_state_link_down_handler(
2169 struct scic_sds_port
*this_port
,
2170 struct scic_sds_phy
*phy
)
2173 * In the resetting state we don't notify the user regarding
2174 * link up and link down notifications. */
2175 scic_sds_port_deactivate_phy(this_port
, phy
, false);
2178 static struct scic_sds_port_state_handler
2179 scic_sds_port_state_handler_table
[SCI_BASE_PORT_MAX_STATES
] =
2181 /* SCI_BASE_PORT_STATE_STOPPED */
2184 scic_sds_port_stopped_state_start_handler
,
2185 scic_sds_port_stopped_state_stop_handler
,
2186 scic_sds_port_stopped_state_destruct_handler
,
2187 scic_sds_port_default_reset_handler
,
2188 scic_sds_port_stopped_state_add_phy_handler
,
2189 scic_sds_port_stopped_state_remove_phy_handler
2191 scic_sds_port_default_frame_handler
,
2192 scic_sds_port_default_event_handler
,
2193 scic_sds_port_default_link_up_handler
,
2194 scic_sds_port_default_link_down_handler
,
2195 scic_sds_port_default_start_io_handler
,
2196 scic_sds_port_default_complete_io_handler
2198 /* SCI_BASE_PORT_STATE_STOPPING */
2201 scic_sds_port_default_start_handler
,
2202 scic_sds_port_default_stop_handler
,
2203 scic_sds_port_default_destruct_handler
,
2204 scic_sds_port_default_reset_handler
,
2205 scic_sds_port_default_add_phy_handler
,
2206 scic_sds_port_default_remove_phy_handler
2208 scic_sds_port_default_frame_handler
,
2209 scic_sds_port_default_event_handler
,
2210 scic_sds_port_default_link_up_handler
,
2211 scic_sds_port_default_link_down_handler
,
2212 scic_sds_port_default_start_io_handler
,
2213 scic_sds_port_stopping_state_complete_io_handler
2215 /* SCI_BASE_PORT_STATE_READY */
2218 scic_sds_port_default_start_handler
,
2219 scic_sds_port_default_stop_handler
,
2220 scic_sds_port_default_destruct_handler
,
2221 scic_sds_port_default_reset_handler
,
2222 scic_sds_port_default_add_phy_handler
,
2223 scic_sds_port_default_remove_phy_handler
2225 scic_sds_port_default_frame_handler
,
2226 scic_sds_port_default_event_handler
,
2227 scic_sds_port_default_link_up_handler
,
2228 scic_sds_port_default_link_down_handler
,
2229 scic_sds_port_default_start_io_handler
,
2230 scic_sds_port_general_complete_io_handler
2232 /* SCI_BASE_PORT_STATE_RESETTING */
2235 scic_sds_port_default_start_handler
,
2236 scic_sds_port_reset_state_stop_handler
,
2237 scic_sds_port_default_destruct_handler
,
2238 scic_sds_port_default_reset_handler
,
2239 scic_sds_port_default_add_phy_handler
,
2240 scic_sds_port_default_remove_phy_handler
2242 scic_sds_port_default_frame_handler
,
2243 scic_sds_port_default_event_handler
,
2244 scic_sds_port_reset_state_link_up_handler
,
2245 scic_sds_port_reset_state_link_down_handler
,
2246 scic_sds_port_default_start_io_handler
,
2247 scic_sds_port_general_complete_io_handler
2249 /* SCI_BASE_PORT_STATE_FAILED */
2252 scic_sds_port_default_start_handler
,
2253 scic_sds_port_default_stop_handler
,
2254 scic_sds_port_default_destruct_handler
,
2255 scic_sds_port_default_reset_handler
,
2256 scic_sds_port_default_add_phy_handler
,
2257 scic_sds_port_default_remove_phy_handler
2259 scic_sds_port_default_frame_handler
,
2260 scic_sds_port_default_event_handler
,
2261 scic_sds_port_default_link_up_handler
,
2262 scic_sds_port_default_link_down_handler
,
2263 scic_sds_port_default_start_io_handler
,
2264 scic_sds_port_general_complete_io_handler
2269 * ******************************************************************************
2270 * * PORT STATE PRIVATE METHODS
2271 * ****************************************************************************** */
2275 * @this_port: This is the port object which to suspend.
2277 * This method will enable the SCU Port Task Scheduler for this port object but
2278 * will leave the port task scheduler in a suspended state. none
2281 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port
*port
)
2283 u32 pts_control_value
;
2285 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
2286 pts_control_value
|= SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
);
2287 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
2292 * @this_port: This is the port object which to resume.
2294 * This method will disable the SCU port task scheduler for this port object.
2298 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port
*port
)
2300 u32 pts_control_value
;
2302 pts_control_value
= readl(&port
->port_task_scheduler_registers
->control
);
2303 pts_control_value
&=
2304 ~(SCU_PTSxCR_GEN_BIT(ENABLE
) | SCU_PTSxCR_GEN_BIT(SUSPEND
));
2305 writel(pts_control_value
, &port
->port_task_scheduler_registers
->control
);
2308 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port
*sci_port
)
2310 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2311 u8 phys_index
= sci_port
->physical_port_index
;
2312 union scu_remote_node_context
*rnc
;
2313 u16 rni
= sci_port
->reserved_rni
;
2316 rnc
= &scic
->remote_node_context_table
[rni
];
2317 rnc
->ssp
.is_valid
= true;
2319 command
= SCU_CONTEXT_COMMAND_POST_RNC_32
|
2320 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2322 scic_sds_controller_post_request(scic
, command
);
2324 /* ensure hardware has seen the post rnc command and give it
2325 * ample time to act before sending the suspend
2327 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
2330 command
= SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX
|
2331 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2333 scic_sds_controller_post_request(scic
, command
);
2336 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port
*sci_port
)
2338 struct scic_sds_controller
*scic
= sci_port
->owning_controller
;
2339 u8 phys_index
= sci_port
->physical_port_index
;
2340 union scu_remote_node_context
*rnc
;
2341 u16 rni
= sci_port
->reserved_rni
;
2344 rnc
= &scic
->remote_node_context_table
[rni
];
2346 rnc
->ssp
.is_valid
= false;
2348 /* ensure the preceding tc abort request has reached the
2349 * controller and give it ample time to act before posting the rnc
2352 readl(&scic
->smu_registers
->interrupt_status
); /* flush */
2355 command
= SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE
|
2356 phys_index
<< SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
| rni
;
2358 scic_sds_controller_post_request(scic
, command
);
2362 * ******************************************************************************
2363 * * PORT STATE METHODS
2364 * ****************************************************************************** */
2368 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2370 * This method will perform the actions required by the struct scic_sds_port on
2371 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2372 * state handlers for the struct scic_sds_port object and disables the port task
2373 * scheduler in the hardware. none
2375 static void scic_sds_port_stopped_state_enter(
2376 struct sci_base_object
*object
)
2378 struct scic_sds_port
*this_port
;
2380 this_port
= (struct scic_sds_port
*)object
;
2382 scic_sds_port_set_base_state_handlers(
2383 this_port
, SCI_BASE_PORT_STATE_STOPPED
2387 SCI_BASE_PORT_STATE_STOPPING
2388 == this_port
->parent
.state_machine
.previous_state_id
2391 * If we enter this state becasuse of a request to stop
2392 * the port then we want to disable the hardwares port
2393 * task scheduler. */
2394 scic_sds_port_disable_port_task_scheduler(this_port
);
2400 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2402 * This method will perform the actions required by the struct scic_sds_port on
2403 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2404 * port task scheduler. none
2406 static void scic_sds_port_stopped_state_exit(
2407 struct sci_base_object
*object
)
2409 struct scic_sds_port
*this_port
;
2411 this_port
= (struct scic_sds_port
*)object
;
2413 /* Enable and suspend the port task scheduler */
2414 scic_sds_port_enable_port_task_scheduler(this_port
);
2418 * scic_sds_port_ready_state_enter -
2419 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2421 * This method will perform the actions required by the struct scic_sds_port on
2422 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2423 * handlers for the struct scic_sds_port object, reports the port object as
2424 * not ready and starts the ready substate machine. none
2426 static void scic_sds_port_ready_state_enter(struct sci_base_object
*object
)
2428 struct scic_sds_controller
*scic
;
2429 struct scic_sds_port
*sci_port
;
2430 struct isci_port
*iport
;
2431 struct isci_host
*ihost
;
2434 sci_port
= container_of(object
, typeof(*sci_port
), parent
.parent
);
2435 scic
= scic_sds_port_get_controller(sci_port
);
2436 ihost
= sci_object_get_association(scic
);
2437 iport
= sci_object_get_association(sci_port
);
2439 /* Put the ready state handlers in place though they will not be there long */
2440 scic_sds_port_set_base_state_handlers(sci_port
, SCI_BASE_PORT_STATE_READY
);
2442 prev_state
= sci_port
->parent
.state_machine
.previous_state_id
;
2443 if (prev_state
== SCI_BASE_PORT_STATE_RESETTING
)
2444 isci_port_hard_reset_complete(iport
, SCI_SUCCESS
);
2446 isci_port_not_ready(ihost
, iport
);
2448 /* Post and suspend the dummy remote node context for this port. */
2449 scic_sds_port_post_dummy_remote_node(sci_port
);
2451 /* Start the ready substate machine */
2452 sci_base_state_machine_start(&sci_port
->ready_substate_machine
);
2455 static void scic_sds_port_ready_state_exit(struct sci_base_object
*object
)
2457 struct scic_sds_port
*sci_port
;
2459 sci_port
= container_of(object
, typeof(*sci_port
), parent
.parent
);
2460 sci_base_state_machine_stop(&sci_port
->ready_substate_machine
);
2461 scic_sds_port_invalidate_dummy_remote_node(sci_port
);
2466 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2468 * This method will perform the actions required by the struct scic_sds_port on
2469 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2470 * state handlers for the struct scic_sds_port object. none
2472 static void scic_sds_port_resetting_state_enter(
2473 struct sci_base_object
*object
)
2475 struct scic_sds_port
*this_port
;
2477 this_port
= (struct scic_sds_port
*)object
;
2479 scic_sds_port_set_base_state_handlers(
2480 this_port
, SCI_BASE_PORT_STATE_RESETTING
2486 * @object: This is the struct sci_base_object which is cast to a
2487 * struct scic_sds_port object.
2489 * This function will perform the actions required by the
2490 * struct scic_sds_port on
2491 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2493 static inline void scic_sds_port_resetting_state_exit(
2494 struct sci_base_object
*object
)
2496 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)object
;
2498 isci_timer_stop(sci_port
->timer_handle
);
2503 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2505 * This method will perform the actions required by the struct scic_sds_port on
2506 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2507 * state handlers for the struct scic_sds_port object. none
2509 static void scic_sds_port_stopping_state_enter(
2510 struct sci_base_object
*object
)
2512 struct scic_sds_port
*this_port
;
2514 this_port
= (struct scic_sds_port
*)object
;
2516 scic_sds_port_set_base_state_handlers(
2517 this_port
, SCI_BASE_PORT_STATE_STOPPING
2523 * @object: This is the struct sci_base_object which is cast to a
2524 * struct scic_sds_port object.
2526 * This function will perform the actions required by the
2527 * struct scic_sds_port on
2528 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2531 scic_sds_port_stopping_state_exit(struct sci_base_object
*object
)
2533 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)object
;
2535 isci_timer_stop(sci_port
->timer_handle
);
2537 scic_sds_port_destroy_dummy_resources(sci_port
);
2542 * @object: This is the struct sci_base_object which is cast to a
2543 * struct scic_sds_port object.
2545 * This function will perform the actions required by the
2546 * struct scic_sds_port on
2547 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2548 * state handlers for the struct scic_sds_port object. none
2550 static void scic_sds_port_failed_state_enter(struct sci_base_object
*object
)
2552 struct scic_sds_port
*sci_port
= (struct scic_sds_port
*)object
;
2553 struct isci_port
*iport
= sci_object_get_association(sci_port
);
2555 scic_sds_port_set_base_state_handlers(sci_port
,
2556 SCI_BASE_PORT_STATE_FAILED
);
2558 isci_port_hard_reset_complete(iport
, SCI_FAILURE_TIMEOUT
);
2561 /* --------------------------------------------------------------------------- */
2563 static const struct sci_base_state scic_sds_port_state_table
[] = {
2564 [SCI_BASE_PORT_STATE_STOPPED
] = {
2565 .enter_state
= scic_sds_port_stopped_state_enter
,
2566 .exit_state
= scic_sds_port_stopped_state_exit
2568 [SCI_BASE_PORT_STATE_STOPPING
] = {
2569 .enter_state
= scic_sds_port_stopping_state_enter
,
2570 .exit_state
= scic_sds_port_stopping_state_exit
2572 [SCI_BASE_PORT_STATE_READY
] = {
2573 .enter_state
= scic_sds_port_ready_state_enter
,
2574 .exit_state
= scic_sds_port_ready_state_exit
2576 [SCI_BASE_PORT_STATE_RESETTING
] = {
2577 .enter_state
= scic_sds_port_resetting_state_enter
,
2578 .exit_state
= scic_sds_port_resetting_state_exit
2580 [SCI_BASE_PORT_STATE_FAILED
] = {
2581 .enter_state
= scic_sds_port_failed_state_enter
,
2585 void scic_sds_port_construct(struct scic_sds_port
*sci_port
, u8 port_index
,
2586 struct scic_sds_controller
*scic
)
2590 sci_base_port_construct(&sci_port
->parent
, scic_sds_port_state_table
);
2592 sci_base_state_machine_construct(&sci_port
->ready_substate_machine
,
2593 &sci_port
->parent
.parent
,
2594 scic_sds_port_ready_substate_table
,
2595 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
2597 sci_port
->logical_port_index
= SCIC_SDS_DUMMY_PORT
;
2598 sci_port
->physical_port_index
= port_index
;
2599 sci_port
->active_phy_mask
= 0;
2601 sci_port
->owning_controller
= scic
;
2603 sci_port
->started_request_count
= 0;
2604 sci_port
->assigned_device_count
= 0;
2606 sci_port
->reserved_rni
= SCU_DUMMY_INDEX
;
2607 sci_port
->reserved_tci
= SCU_DUMMY_INDEX
;
2609 sci_port
->timer_handle
= NULL
;
2611 sci_port
->port_task_scheduler_registers
= NULL
;
2613 for (index
= 0; index
< SCI_MAX_PHYS
; index
++)
2614 sci_port
->phy_table
[index
] = NULL
;