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_phy_registers.h"
64 #include "scic_sds_port.h"
65 #include "scic_sds_port_registers.h"
66 #include "scic_sds_remote_device.h"
67 #include "scic_sds_remote_node_context.h"
68 #include "scic_sds_request.h"
69 #include "scic_user_callback.h"
70 #include "sci_environment.h"
73 static void scic_sds_port_invalid_link_up(
74 struct scic_sds_port *this_port,
75 struct scic_sds_phy *phy);
76 static void scic_sds_port_timeout_handler(
78 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
79 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
81 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
83 void sci_base_port_construct(
84 struct sci_base_port *base_port,
85 const struct sci_base_state *state_table)
87 base_port->parent.private = NULL;
88 sci_base_state_machine_construct(
89 &base_port->state_machine,
92 SCI_BASE_PORT_STATE_STOPPED
95 sci_base_state_machine_start(
96 &base_port->state_machine
102 * @this_port: This is the port object to which the phy is being assigned.
103 * @phy_index: This is the phy index that is being assigned to the port.
105 * This method will return a true value if the specified phy can be assigned to
106 * this port The following is a list of phys for each port that are allowed: -
107 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
108 * doesn't preclude all configurations. It merely ensures that a phy is part
109 * of the allowable set of phy identifiers for that port. For example, one
110 * could assign phy 3 to port 0 and no other phys. Please refer to
111 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
112 * phy_mask for a port can be supported. bool true if this is a valid phy
113 * assignment for the port false if this is not a valid phy assignment for the
116 bool scic_sds_port_is_valid_phy_assignment(
117 struct scic_sds_port *this_port,
120 /* Initialize to invalid value. */
121 u32 existing_phy_index = SCI_MAX_PHYS;
124 if ((this_port->physical_port_index == 1) && (phy_index != 1)) {
128 if (this_port->physical_port_index == 3 && phy_index != 3) {
133 (this_port->physical_port_index == 2)
134 && ((phy_index == 0) || (phy_index == 1))
139 for (index = 0; index < SCI_MAX_PHYS; index++) {
140 if ((this_port->phy_table[index] != NULL)
141 && (index != phy_index)) {
142 existing_phy_index = index;
147 * Ensure that all of the phys in the port are capable of
148 * operating at the same maximum link rate. */
150 (existing_phy_index < SCI_MAX_PHYS)
151 && (this_port->owning_controller->user_parameters.sds1.phys[
152 phy_index].max_speed_generation !=
153 this_port->owning_controller->user_parameters.sds1.phys[
154 existing_phy_index].max_speed_generation)
162 * This method requests a list (mask) of the phys contained in the supplied SAS
164 * @this_port: a handle corresponding to the SAS port for which to return the
167 * Return a bit mask indicating which phys are a part of this port. Each bit
168 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
170 u32 scic_sds_port_get_phys(struct scic_sds_port *this_port)
177 for (index = 0; index < SCI_MAX_PHYS; index++) {
178 if (this_port->phy_table[index] != NULL) {
179 mask |= (1 << index);
188 * @this_port: This is the port object for which to determine if the phy mask
191 * This method will return a true value if the port's phy mask can be supported
192 * by the SCU. The following is a list of valid PHY mask configurations for
193 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
194 * - Port 3 - [3] This method returns a boolean indication specifying if the
195 * phy mask can be supported. true if this is a valid phy assignment for the
196 * port false if this is not a valid phy assignment for the port
198 bool scic_sds_port_is_phy_mask_valid(
199 struct scic_sds_port *this_port,
202 if (this_port->physical_port_index == 0) {
203 if (((phy_mask & 0x0F) == 0x0F)
204 || ((phy_mask & 0x03) == 0x03)
205 || ((phy_mask & 0x01) == 0x01)
208 } else if (this_port->physical_port_index == 1) {
209 if (((phy_mask & 0x02) == 0x02)
212 } else if (this_port->physical_port_index == 2) {
213 if (((phy_mask & 0x0C) == 0x0C)
214 || ((phy_mask & 0x04) == 0x04)
217 } else if (this_port->physical_port_index == 3) {
218 if (((phy_mask & 0x08) == 0x08)
228 * @this_port: This parameter specifies the port from which to return a
231 * This method retrieves a currently active (i.e. connected) phy contained in
232 * the port. Currently, the lowest order phy that is connected is returned.
233 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
234 * returned if there are no currently active (i.e. connected to a remote end
235 * point) phys contained in the port. All other values specify a struct scic_sds_phy
236 * object that is active in the port.
238 static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
239 struct scic_sds_port *this_port
242 struct scic_sds_phy *phy;
244 for (index = 0; index < SCI_MAX_PHYS; index++) {
246 * Ensure that the phy is both part of the port and currently
247 * connected to the remote end-point. */
248 phy = this_port->phy_table[index];
251 && scic_sds_port_active_phy(this_port, phy)
261 * scic_sds_port_set_phy() -
262 * @out]: port The port object to which the phy assignement is being made.
263 * @out]: phy The phy which is being assigned to the port.
265 * This method attempts to make the assignment of the phy to the port. If
266 * successful the phy is assigned to the ports phy table. bool true if the phy
267 * assignment can be made. false if the phy assignement can not be made. This
268 * is a functional test that only fails if the phy is currently assigned to a
271 enum sci_status scic_sds_port_set_phy(
272 struct scic_sds_port *port,
273 struct scic_sds_phy *phy)
276 * Check to see if we can add this phy to a port
277 * that means that the phy is not part of a port and that the port does
278 * not already have a phy assinged to the phy index. */
280 (port->phy_table[phy->phy_index] == SCI_INVALID_HANDLE)
281 && (scic_sds_phy_get_port(phy) == SCI_INVALID_HANDLE)
282 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
285 * Phy is being added in the stopped state so we are in MPC mode
286 * make logical port index = physical port index */
287 port->logical_port_index = port->physical_port_index;
288 port->phy_table[phy->phy_index] = phy;
289 scic_sds_phy_set_port(phy, port);
298 * scic_sds_port_clear_phy() -
299 * @out]: port The port from which the phy is being cleared.
300 * @out]: phy The phy being cleared from the port.
302 * This method will clear the phy assigned to this port. This method fails if
303 * this phy is not currently assinged to this port. bool true if the phy is
304 * removed from the port. false if this phy is not assined to this port.
306 enum sci_status scic_sds_port_clear_phy(
307 struct scic_sds_port *port,
308 struct scic_sds_phy *phy)
310 /* Make sure that this phy is part of this port */
312 (port->phy_table[phy->phy_index] == phy)
313 && (scic_sds_phy_get_port(phy) == port)
315 /* Yep it is assigned to this port so remove it */
316 scic_sds_phy_set_port(
318 &scic_sds_port_get_controller(port)->port_table[SCI_MAX_PORTS]
321 port->phy_table[phy->phy_index] = SCI_INVALID_HANDLE;
330 * scic_sds_port_add_phy() -
331 * @this_port: This parameter specifies the port in which the phy will be added.
332 * @the_phy: This parameter is the phy which is to be added to the port.
334 * This method will add a PHY to the selected port. This method returns an
335 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
336 * is failre to add the phy to the port.
338 enum sci_status scic_sds_port_add_phy(
339 struct scic_sds_port *this_port,
340 struct scic_sds_phy *the_phy)
342 return this_port->state_handlers->parent.add_phy_handler(
343 &this_port->parent, &the_phy->parent);
348 * scic_sds_port_remove_phy() -
349 * @this_port: This parameter specifies the port in which the phy will be added.
350 * @the_phy: This parameter is the phy which is to be added to the port.
352 * This method will remove the PHY from the selected PORT. This method returns
353 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
354 * status is failre to add the phy to the port.
356 enum sci_status scic_sds_port_remove_phy(
357 struct scic_sds_port *this_port,
358 struct scic_sds_phy *the_phy)
360 return this_port->state_handlers->parent.remove_phy_handler(
361 &this_port->parent, &the_phy->parent);
365 * This method requests the SAS address for the supplied SAS port from the SCI
367 * @this_port: a handle corresponding to the SAS port for which to return the
369 * @sas_address: This parameter specifies a pointer to a SAS address structure
370 * into which the core will copy the SAS address for the port.
373 void scic_sds_port_get_sas_address(
374 struct scic_sds_port *this_port,
375 struct sci_sas_address *sas_address)
379 sas_address->high = 0;
380 sas_address->low = 0;
382 for (index = 0; index < SCI_MAX_PHYS; index++) {
383 if (this_port->phy_table[index] != NULL) {
384 scic_sds_phy_get_sas_address(this_port->phy_table[index], sas_address);
390 * This method will indicate which protocols are supported by this port.
391 * @this_port: a handle corresponding to the SAS port for which to return the
392 * supported protocols.
393 * @protocols: This parameter specifies a pointer to an IAF protocol field
394 * structure into which the core will copy the protocol values for the port.
395 * The values are returned as part of a bit mask in order to allow for
396 * multi-protocol support.
399 static void scic_sds_port_get_protocols(
400 struct scic_sds_port *this_port,
401 struct sci_sas_identify_address_frame_protocols *protocols)
405 protocols->u.all = 0;
407 for (index = 0; index < SCI_MAX_PHYS; index++) {
408 if (this_port->phy_table[index] != NULL) {
409 scic_sds_phy_get_protocols(this_port->phy_table[index], protocols);
415 * This method requests the SAS address for the device directly attached to
417 * @this_port: a handle corresponding to the SAS port for which to return the
419 * @sas_address: This parameter specifies a pointer to a SAS address structure
420 * into which the core will copy the SAS address for the device directly
421 * attached to the port.
424 void scic_sds_port_get_attached_sas_address(
425 struct scic_sds_port *this_port,
426 struct sci_sas_address *sas_address)
428 struct sci_sas_identify_address_frame_protocols protocols;
429 struct scic_sds_phy *phy;
432 * Ensure that the phy is both part of the port and currently
433 * connected to the remote end-point. */
434 phy = scic_sds_port_get_a_connected_phy(this_port);
436 scic_sds_phy_get_attached_phy_protocols(phy, &protocols);
438 if (!protocols.u.bits.stp_target) {
439 scic_sds_phy_get_attached_sas_address(phy, sas_address);
441 scic_sds_phy_get_sas_address(phy, sas_address);
442 sas_address->low += phy->phy_index;
445 sas_address->high = 0;
446 sas_address->low = 0;
451 * This method will indicate which protocols are supported by this remote
453 * @this_port: a handle corresponding to the SAS port for which to return the
454 * supported protocols.
455 * @protocols: This parameter specifies a pointer to an IAF protocol field
456 * structure into which the core will copy the protocol values for the port.
457 * The values are returned as part of a bit mask in order to allow for
458 * multi-protocol support.
461 void scic_sds_port_get_attached_protocols(
462 struct scic_sds_port *this_port,
463 struct sci_sas_identify_address_frame_protocols *protocols)
465 struct scic_sds_phy *phy;
468 * Ensure that the phy is both part of the port and currently
469 * connected to the remote end-point. */
470 phy = scic_sds_port_get_a_connected_phy(this_port);
472 scic_sds_phy_get_attached_phy_protocols(phy, protocols);
474 protocols->u.all = 0;
478 * This method returns the amount of memory requred for a port object.
484 * This method returns the minimum number of timers required for all port
491 * This method returns the maximum number of timers required for all port
504 void scic_sds_port_construct(
505 struct scic_sds_port *this_port,
507 struct scic_sds_controller *owning_controller)
511 sci_base_port_construct(
513 scic_sds_port_state_table
516 sci_base_state_machine_construct(
517 scic_sds_port_get_ready_substate_machine(this_port),
518 &this_port->parent.parent,
519 scic_sds_port_ready_substate_table,
520 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
523 this_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
524 this_port->physical_port_index = port_index;
525 this_port->active_phy_mask = 0;
527 this_port->owning_controller = owning_controller;
529 this_port->started_request_count = 0;
530 this_port->assigned_device_count = 0;
532 this_port->timer_handle = SCI_INVALID_HANDLE;
534 this_port->transport_layer_registers = NULL;
535 this_port->port_task_scheduler_registers = NULL;
537 for (index = 0; index < SCI_MAX_PHYS; index++) {
538 this_port->phy_table[index] = NULL;
543 * This method performs initialization of the supplied port. Initialization
544 * includes: - state machine initialization - member variable initialization
545 * - configuring the phy_mask
547 * @transport_layer_registers:
548 * @port_task_scheduler_registers:
549 * @port_configuration_regsiter:
551 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
552 * if the phy being added to the port
554 enum sci_status scic_sds_port_initialize(
555 struct scic_sds_port *this_port,
556 void *transport_layer_registers,
557 void *port_task_scheduler_registers,
558 void *port_configuration_regsiter,
559 void *viit_registers)
563 this_port->transport_layer_registers = transport_layer_registers;
564 this_port->port_task_scheduler_registers = port_task_scheduler_registers;
565 this_port->port_pe_configuration_register = port_configuration_regsiter;
566 this_port->viit_registers = viit_registers;
568 scic_sds_port_set_direct_attached_device_id(
570 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
574 * Hardware team recommends that we enable the STP prefetch
576 tl_control = SCU_TLCR_READ(this_port);
577 tl_control |= SCU_TLCR_GEN_BIT(STP_WRITE_DATA_PREFETCH);
578 SCU_TLCR_WRITE(this_port, tl_control);
581 * If this is not the dummy port make the assignment of
582 * the timer and start the state machine */
583 if (this_port->physical_port_index != SCI_MAX_PORTS) {
584 /* / @todo should we create the timer at create time? */
585 this_port->timer_handle = scic_cb_timer_create(
586 scic_sds_port_get_controller(this_port),
587 scic_sds_port_timeout_handler,
593 * Force the dummy port into a condition where it rejects all requests
594 * as its in an invalid state for any operation.
595 * / @todo should we set a set of specical handlers for the dummy port? */
596 scic_sds_port_set_base_state_handlers(
597 this_port, SCI_BASE_PORT_STATE_STOPPED
606 * @this_port: This is the struct scic_sds_port object for which has a phy that has
608 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
609 * @do_notify_user: This parameter specifies whether to inform the user (via
610 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
612 * This method is the a general link up handler for the struct scic_sds_port object.
613 * This function will determine if this struct scic_sds_phy can be assigned to this
614 * struct scic_sds_port object. If the struct scic_sds_phy object can is not a valid PHY for
615 * this port then the function will notify the SCIC_USER. A PHY can only be
616 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
617 * the same port. none
619 void scic_sds_port_general_link_up_handler(
620 struct scic_sds_port *this_port,
621 struct scic_sds_phy *the_phy,
624 struct sci_sas_address port_sas_address;
625 struct sci_sas_address phy_sas_address;
627 scic_sds_port_get_attached_sas_address(this_port, &port_sas_address);
628 scic_sds_phy_get_attached_sas_address(the_phy, &phy_sas_address);
631 * If the SAS address of the new phy matches the SAS address of
632 * other phys in the port OR this is the first phy in the port,
633 * then activate the phy and allow it to be used for operations
637 (phy_sas_address.high == port_sas_address.high)
638 && (phy_sas_address.low == port_sas_address.low)
640 || (this_port->active_phy_mask == 0)
642 scic_sds_port_activate_phy(this_port, the_phy, do_notify_user);
644 if (this_port->parent.state_machine.current_state_id
645 == SCI_BASE_PORT_STATE_RESETTING) {
646 sci_base_state_machine_change_state(
647 &this_port->parent.state_machine, SCI_BASE_PORT_STATE_READY
651 scic_sds_port_invalid_link_up(this_port, the_phy);
656 enum sci_status scic_port_start(struct scic_sds_port *port)
658 return port->state_handlers->parent.start_handler(&port->parent);
662 enum sci_status scic_port_stop(struct scic_sds_port *port)
664 return port->state_handlers->parent.stop_handler(&port->parent);
668 enum sci_status scic_port_get_properties(
669 struct scic_sds_port *port,
670 struct scic_port_properties *prop)
672 if ((port == SCI_INVALID_HANDLE) ||
673 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
674 return SCI_FAILURE_INVALID_PORT;
676 prop->index = port->logical_port_index;
677 prop->phy_mask = scic_sds_port_get_phys(port);
678 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
679 scic_sds_port_get_protocols(port, &prop->local.protocols);
680 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
681 scic_sds_port_get_attached_protocols(port, &prop->remote.protocols);
687 enum sci_status scic_port_hard_reset(
688 struct scic_sds_port *port,
691 return port->state_handlers->parent.reset_handler(
692 &port->parent, reset_timeout);
697 * @this_port: The port for which the direct attached device id is to be
700 * This method assigns the direct attached device ID for this port.
702 void scic_sds_port_set_direct_attached_device_id(
703 struct scic_sds_port *this_port,
708 SCU_STPTLDARNI_WRITE(this_port, device_id);
711 * The read should guarntee that the first write gets posted
712 * before the next write */
713 tl_control = SCU_TLCR_READ(this_port);
714 tl_control |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
715 SCU_TLCR_WRITE(this_port, tl_control);
721 * @this_port: This is the port on which the phy should be enabled.
722 * @the_phy: This is the specific phy which to enable.
723 * @do_notify_user: This parameter specifies whether to inform the user (via
724 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
726 * This method will activate the phy in the port. Activation includes: - adding
727 * the phy to the port - enabling the Protocol Engine in the silicon. -
728 * notifying the user that the link is up. none
730 void scic_sds_port_activate_phy(
731 struct scic_sds_port *this_port,
732 struct scic_sds_phy *the_phy,
735 struct scic_sds_controller *controller;
736 struct sci_sas_identify_address_frame_protocols protocols;
738 controller = scic_sds_port_get_controller(this_port);
739 scic_sds_phy_get_attached_phy_protocols(the_phy, &protocols);
741 /* If this is sata port then the phy has already been resumed */
742 if (!protocols.u.bits.stp_target) {
743 scic_sds_phy_resume(the_phy);
746 this_port->active_phy_mask |= 1 << the_phy->phy_index;
748 scic_sds_controller_clear_invalid_phy(controller, the_phy);
750 if (do_notify_user == true)
751 scic_cb_port_link_up(this_port->owning_controller, this_port, the_phy);
756 * @this_port: This is the port on which the phy should be deactivated.
757 * @the_phy: This is the specific phy that is no longer active in the port.
758 * @do_notify_user: This parameter specifies whether to inform the user (via
759 * scic_cb_port_link_down()) as to the fact that a new phy as become ready.
761 * This method will deactivate the supplied phy in the port. none
763 void scic_sds_port_deactivate_phy(
764 struct scic_sds_port *this_port,
765 struct scic_sds_phy *the_phy,
768 this_port->active_phy_mask &= ~(1 << the_phy->phy_index);
770 the_phy->max_negotiated_speed = SCI_SAS_NO_LINK_RATE;
772 /* Re-assign the phy back to the LP as if it were a narrow port */
773 SCU_PCSPExCR_WRITE(this_port, the_phy->phy_index, the_phy->phy_index);
775 if (do_notify_user == true)
776 scic_cb_port_link_down(this_port->owning_controller, this_port, the_phy);
781 * @this_port: This is the port on which the phy should be disabled.
782 * @the_phy: This is the specific phy which to disabled.
784 * This method will disable the phy and report that the phy is not valid for
785 * this port object. None
787 static void scic_sds_port_invalid_link_up(
788 struct scic_sds_port *this_port,
789 struct scic_sds_phy *the_phy)
791 struct scic_sds_controller *controller = scic_sds_port_get_controller(this_port);
794 * Check to see if we have alreay reported this link as bad and if not go
795 * ahead and tell the SCI_USER that we have discovered an invalid link. */
796 if ((controller->invalid_phy_mask & (1 << the_phy->phy_index)) == 0) {
797 scic_sds_controller_set_invalid_phy(controller, the_phy);
799 scic_cb_port_invalid_link_up(controller, this_port, the_phy);
804 * This method returns false if the port only has a single phy object assigned.
805 * If there are no phys or more than one phy then the method will return
807 * @this_port: The port for which the wide port condition is to be checked.
809 * bool true Is returned if this is a wide ported port. false Is returned if
810 * this is a narrow port.
812 static bool scic_sds_port_is_wide(struct scic_sds_port *this_port)
817 for (index = 0; index < SCI_MAX_PHYS; index++) {
818 if (this_port->phy_table[index] != NULL) {
823 return phy_count != 1;
827 * This method is called by the PHY object when the link is detected. if the
828 * port wants the PHY to continue on to the link up state then the port
829 * layer must return true. If the port object returns false the phy object
830 * must halt its attempt to go link up.
831 * @this_port: The port associated with the phy object.
832 * @the_phy: The phy object that is trying to go link up.
834 * true if the phy object can continue to the link up condition. true Is
835 * returned if this phy can continue to the ready state. false Is returned if
836 * can not continue on to the ready state. This notification is in place for
837 * wide ports and direct attached phys. Since there are no wide ported SATA
838 * devices this could become an invalid port configuration.
840 bool scic_sds_port_link_detected(
841 struct scic_sds_port *this_port,
842 struct scic_sds_phy *the_phy)
844 struct sci_sas_identify_address_frame_protocols protocols;
846 scic_sds_phy_get_attached_phy_protocols(the_phy, &protocols);
849 (this_port->logical_port_index != SCIC_SDS_DUMMY_PORT)
850 && (protocols.u.bits.stp_target)
851 && scic_sds_port_is_wide(this_port)
853 scic_sds_port_invalid_link_up(this_port, the_phy);
862 * This method is the entry point for the phy to inform the port that it is now
868 void scic_sds_port_link_up(
869 struct scic_sds_port *this_port,
870 struct scic_sds_phy *the_phy)
872 the_phy->is_in_link_training = false;
874 this_port->state_handlers->link_up_handler(this_port, the_phy);
878 * This method is the entry point for the phy to inform the port that it is no
879 * longer in a ready state
884 void scic_sds_port_link_down(
885 struct scic_sds_port *this_port,
886 struct scic_sds_phy *the_phy)
888 this_port->state_handlers->link_down_handler(this_port, the_phy);
892 * This method is called to start an IO request on this port.
899 enum sci_status scic_sds_port_start_io(
900 struct scic_sds_port *this_port,
901 struct scic_sds_remote_device *the_device,
902 struct scic_sds_request *the_io_request)
904 return this_port->state_handlers->start_io_handler(
905 this_port, the_device, the_io_request);
909 * This method is called to complete an IO request to the port.
916 enum sci_status scic_sds_port_complete_io(
917 struct scic_sds_port *this_port,
918 struct scic_sds_remote_device *the_device,
919 struct scic_sds_request *the_io_request)
921 return this_port->state_handlers->complete_io_handler(
922 this_port, the_device, the_io_request);
926 * This method is provided to timeout requests for port operations. Mostly its
927 * for the port reset operation.
931 static void scic_sds_port_timeout_handler(void *port)
933 struct scic_sds_port *this_port = port;
936 current_state = sci_base_state_machine_get_state(
937 &this_port->parent.state_machine);
939 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
941 * if the port is still in the resetting state then the timeout fired
942 * before the reset completed. */
943 sci_base_state_machine_change_state(
944 &this_port->parent.state_machine,
945 SCI_BASE_PORT_STATE_FAILED
947 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
949 * if the port is stopped then the start request failed
950 * In this case stay in the stopped state. */
951 dev_err(sciport_to_dev(this_port),
952 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
955 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
956 /* if the port is still stopping then the stop has not completed */
957 scic_cb_port_stop_complete(
958 scic_sds_port_get_controller(this_port),
964 * The port is in the ready state and we have a timer reporting a timeout
965 * this should not happen. */
966 dev_err(sciport_to_dev(this_port),
967 "%s: SCIC Port 0x%p is processing a timeout operation "
975 /* --------------------------------------------------------------------------- */
977 #ifdef SCIC_DEBUG_ENABLED
978 void scic_sds_port_decrement_request_count(struct scic_sds_port *this_port)
980 if (this_port->started_request_count == 0)
981 dev_warn(sciport_to_dev(this_port),
983 "%s: SCIC Port object requested to decrement started "
984 "io count past zero.\n");
986 this_port->started_request_count--;
991 * This function updates the hardwares VIIT entry for this port.
995 void scic_sds_port_update_viit_entry(struct scic_sds_port *this_port)
997 struct sci_sas_address sas_address;
999 scic_sds_port_get_sas_address(this_port, &sas_address);
1001 scu_port_viit_register_write(
1002 this_port, initiator_sas_address_hi, sas_address.high);
1004 scu_port_viit_register_write(
1005 this_port, initiator_sas_address_lo, sas_address.low);
1007 /* This value get cleared just in case its not already cleared */
1008 scu_port_viit_register_write(
1009 this_port, reserved, 0);
1011 /* We are required to update the status register last */
1012 scu_port_viit_register_write(
1013 this_port, status, (
1014 SCU_VIIT_ENTRY_ID_VIIT
1015 | SCU_VIIT_IPPT_INITIATOR
1016 | ((1 << this_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT)
1017 | SCU_VIIT_STATUS_ALL_VALID
1023 * This method returns the maximum allowed speed for data transfers on this
1024 * port. This maximum allowed speed evaluates to the maximum speed of the
1025 * slowest phy in the port.
1026 * @this_port: This parameter specifies the port for which to retrieve the
1027 * maximum allowed speed.
1029 * This method returns the maximum negotiated speed of the slowest phy in the
1032 enum sci_sas_link_rate scic_sds_port_get_max_allowed_speed(
1033 struct scic_sds_port *this_port)
1036 enum sci_sas_link_rate max_allowed_speed = SCI_SAS_600_GB;
1037 struct scic_sds_phy *phy = NULL;
1040 * Loop through all of the phys in this port and find the phy with the
1041 * lowest maximum link rate. */
1042 for (index = 0; index < SCI_MAX_PHYS; index++) {
1043 phy = this_port->phy_table[index];
1046 && (scic_sds_port_active_phy(this_port, phy) == true)
1047 && (phy->max_negotiated_speed < max_allowed_speed)
1049 max_allowed_speed = phy->max_negotiated_speed;
1052 return max_allowed_speed;
1057 * This method passes the event to core user.
1058 * @this_port: The port that a BCN happens.
1059 * @this_phy: The phy that receives BCN.
1062 void scic_sds_port_broadcast_change_received(
1063 struct scic_sds_port *this_port,
1064 struct scic_sds_phy *this_phy)
1066 /* notify the user. */
1067 scic_cb_port_bc_change_primitive_received(
1068 this_port->owning_controller, this_port, this_phy
1074 * This API methhod enables the broadcast change notification from underneath
1076 * @this_port: The port that a BCN had been disabled from.
1079 void scic_port_enable_broadcast_change_notification(
1080 struct scic_sds_port *port)
1082 struct scic_sds_phy *phy;
1086 /* Loop through all of the phys to enable BCN. */
1087 for (index = 0; index < SCI_MAX_PHYS; index++) {
1088 phy = port->phy_table[index];
1090 register_value = SCU_SAS_LLCTL_READ(phy);
1092 /* clear the bit by writing 1. */
1093 SCU_SAS_LLCTL_WRITE(phy, register_value);
1099 * ****************************************************************************
1100 * * READY SUBSTATE HANDLERS
1101 * **************************************************************************** */
1105 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1108 * This method is the general ready state stop handler for the struct scic_sds_port
1109 * object. This function will transition the ready substate machine to its
1110 * final state. enum sci_status SCI_SUCCESS
1112 static enum sci_status scic_sds_port_ready_substate_stop_handler(
1113 struct sci_base_port *port)
1115 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1117 sci_base_state_machine_change_state(
1118 &this_port->parent.state_machine,
1119 SCI_BASE_PORT_STATE_STOPPING
1127 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1129 * @device: This is the struct sci_base_remote_device object which is not used in this
1131 * @io_request: This is the struct sci_base_request object which is not used in this
1134 * This method is the general ready substate complete io handler for the
1135 * struct scic_sds_port object. This function decrments the outstanding request count
1136 * for this port object. enum sci_status SCI_SUCCESS
1138 static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1139 struct scic_sds_port *port,
1140 struct scic_sds_remote_device *device,
1141 struct scic_sds_request *io_request)
1143 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1145 scic_sds_port_decrement_request_count(this_port);
1150 static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
1151 struct sci_base_port *port,
1152 struct sci_base_phy *phy)
1154 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1155 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1156 enum sci_status status;
1158 status = scic_sds_port_set_phy(this_port, this_phy);
1160 if (status == SCI_SUCCESS) {
1161 scic_sds_port_general_link_up_handler(this_port, this_phy, true);
1163 this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1165 sci_base_state_machine_change_state(
1166 &this_port->ready_substate_machine,
1167 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1175 static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
1176 struct sci_base_port *port,
1177 struct sci_base_phy *phy)
1179 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1180 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1181 enum sci_status status;
1183 status = scic_sds_port_clear_phy(this_port, this_phy);
1185 if (status == SCI_SUCCESS) {
1186 scic_sds_port_deactivate_phy(this_port, this_phy, true);
1188 this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1190 sci_base_state_machine_change_state(
1191 &this_port->ready_substate_machine,
1192 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1200 * ****************************************************************************
1201 * * READY SUBSTATE WAITING HANDLERS
1202 * **************************************************************************** */
1206 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1208 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1210 * This method is the ready waiting substate link up handler for the
1211 * struct scic_sds_port object. This methos will report the link up condition for
1212 * this port and will transition to the ready operational substate. none
1214 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1215 struct scic_sds_port *this_port,
1216 struct scic_sds_phy *the_phy)
1219 * Since this is the first phy going link up for the port we can just enable
1220 * it and continue. */
1221 scic_sds_port_activate_phy(this_port, the_phy, true);
1223 sci_base_state_machine_change_state(
1224 &this_port->ready_substate_machine,
1225 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1231 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1233 * @device: This is the struct sci_base_remote_device object which is not used in this
1235 * @io_request: This is the struct sci_base_request object which is not used in this
1238 * This method is the ready waiting substate start io handler for the
1239 * struct scic_sds_port object. The port object can not accept new requests so the
1240 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1242 static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1243 struct scic_sds_port *port,
1244 struct scic_sds_remote_device *device,
1245 struct scic_sds_request *io_request)
1247 return SCI_FAILURE_INVALID_STATE;
1251 * ****************************************************************************
1252 * * READY SUBSTATE OPERATIONAL HANDLERS
1253 * **************************************************************************** */
1257 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1259 * @timeout: This is the timeout for the reset request to complete.
1261 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1263 static enum sci_status scic_sds_port_ready_operational_substate_reset_handler(
1264 struct sci_base_port *port,
1267 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1269 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1270 struct scic_sds_phy *selected_phy = SCI_INVALID_HANDLE;
1273 /* Select a phy on which we can send the hard reset request. */
1276 (phy_index < SCI_MAX_PHYS)
1277 && (selected_phy == SCI_INVALID_HANDLE);
1280 selected_phy = this_port->phy_table[phy_index];
1283 (selected_phy != SCI_INVALID_HANDLE)
1284 && !scic_sds_port_active_phy(this_port, selected_phy)
1286 /* We found a phy but it is not ready select different phy */
1287 selected_phy = SCI_INVALID_HANDLE;
1291 /* If we have a phy then go ahead and start the reset procedure */
1292 if (selected_phy != SCI_INVALID_HANDLE) {
1293 status = scic_sds_phy_reset(selected_phy);
1295 if (status == SCI_SUCCESS) {
1296 scic_cb_timer_start(
1297 scic_sds_port_get_controller(this_port),
1298 this_port->timer_handle,
1302 this_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1304 sci_base_state_machine_change_state(
1305 &this_port->parent.state_machine,
1306 SCI_BASE_PORT_STATE_RESETTING
1315 * scic_sds_port_ready_operational_substate_link_up_handler() -
1316 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1318 * @the_phy: This is the struct scic_sds_phy object that has gone link up.
1320 * This method is the ready operational substate link up handler for the
1321 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1322 * gone link up. none
1324 static void scic_sds_port_ready_operational_substate_link_up_handler(
1325 struct scic_sds_port *this_port,
1326 struct scic_sds_phy *the_phy)
1328 scic_sds_port_general_link_up_handler(this_port, the_phy, true);
1332 * scic_sds_port_ready_operational_substate_link_down_handler() -
1333 * @this_port: This is the struct scic_sds_port object that which has a phy that has
1335 * @the_phy: This is the struct scic_sds_phy object that has gone link down.
1337 * This method is the ready operational substate link down handler for the
1338 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1339 * gone link down and if this is the last phy in the port the port will change
1340 * state to the ready waiting substate. none
1342 static void scic_sds_port_ready_operational_substate_link_down_handler(
1343 struct scic_sds_port *this_port,
1344 struct scic_sds_phy *the_phy)
1346 scic_sds_port_deactivate_phy(this_port, the_phy, true);
1349 * If there are no active phys left in the port, then transition
1350 * the port to the WAITING state until such time as a phy goes
1352 if (this_port->active_phy_mask == 0) {
1353 sci_base_state_machine_change_state(
1354 scic_sds_port_get_ready_substate_machine(this_port),
1355 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1362 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1364 * @device: This is the struct sci_base_remote_device object which is not used in this
1366 * @io_request: This is the struct sci_base_request object which is not used in this
1369 * This method is the ready operational substate start io handler for the
1370 * struct scic_sds_port object. This function incremetns the outstanding request
1371 * count for this port object. enum sci_status SCI_SUCCESS
1373 static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1374 struct scic_sds_port *port,
1375 struct scic_sds_remote_device *device,
1376 struct scic_sds_request *io_request)
1378 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1380 scic_sds_port_increment_request_count(this_port);
1386 * ****************************************************************************
1387 * * READY SUBSTATE OPERATIONAL HANDLERS
1388 * **************************************************************************** */
1391 * scic_sds_port_ready_configuring_substate_add_phy_handler() -
1392 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1395 * This is the default method for a port add phy request. It will report a
1396 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1398 static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1399 struct sci_base_port *port,
1400 struct sci_base_phy *phy)
1402 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1403 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1404 enum sci_status status;
1406 status = scic_sds_port_set_phy(this_port, this_phy);
1408 if (status == SCI_SUCCESS) {
1409 scic_sds_port_general_link_up_handler(this_port, this_phy, true);
1412 * Re-enter the configuring state since this may be the last phy in
1414 sci_base_state_machine_change_state(
1415 &this_port->ready_substate_machine,
1416 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1424 * scic_sds_port_ready_configuring_substate_remove_phy_handler() -
1425 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1428 * This is the default method for a port remove phy request. It will report a
1429 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1431 static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1432 struct sci_base_port *port,
1433 struct sci_base_phy *phy)
1435 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
1436 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
1437 enum sci_status status;
1439 status = scic_sds_port_clear_phy(this_port, this_phy);
1441 if (status == SCI_SUCCESS) {
1442 scic_sds_port_deactivate_phy(this_port, this_phy, true);
1445 * Re-enter the configuring state since this may be the last phy in
1447 sci_base_state_machine_change_state(
1448 &this_port->ready_substate_machine,
1449 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1457 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1458 * @port: This is the port that is being requested to complete the io request.
1459 * @device: This is the device on which the io is completing.
1461 * This method will decrement the outstanding request count for this port. If
1462 * the request count goes to 0 then the port can be reprogrammed with its new
1465 static enum sci_status scic_sds_port_ready_configuring_substate_complete_io_handler(
1466 struct scic_sds_port *port,
1467 struct scic_sds_remote_device *device,
1468 struct scic_sds_request *io_request)
1470 scic_sds_port_decrement_request_count(port);
1472 if (port->started_request_count == 0) {
1473 sci_base_state_machine_change_state(
1474 &port->ready_substate_machine,
1475 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1482 /* --------------------------------------------------------------------------- */
1484 struct scic_sds_port_state_handler
1485 scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] =
1487 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1490 scic_sds_port_default_start_handler,
1491 scic_sds_port_ready_substate_stop_handler,
1492 scic_sds_port_default_destruct_handler,
1493 scic_sds_port_default_reset_handler,
1494 scic_sds_port_ready_substate_add_phy_handler,
1495 scic_sds_port_default_remove_phy_handler
1497 scic_sds_port_default_frame_handler,
1498 scic_sds_port_default_event_handler,
1499 scic_sds_port_ready_waiting_substate_link_up_handler,
1500 scic_sds_port_default_link_down_handler,
1501 scic_sds_port_ready_waiting_substate_start_io_handler,
1502 scic_sds_port_ready_substate_complete_io_handler,
1504 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1507 scic_sds_port_default_start_handler,
1508 scic_sds_port_ready_substate_stop_handler,
1509 scic_sds_port_default_destruct_handler,
1510 scic_sds_port_ready_operational_substate_reset_handler,
1511 scic_sds_port_ready_substate_add_phy_handler,
1512 scic_sds_port_ready_substate_remove_phy_handler
1514 scic_sds_port_default_frame_handler,
1515 scic_sds_port_default_event_handler,
1516 scic_sds_port_ready_operational_substate_link_up_handler,
1517 scic_sds_port_ready_operational_substate_link_down_handler,
1518 scic_sds_port_ready_operational_substate_start_io_handler,
1519 scic_sds_port_ready_substate_complete_io_handler
1521 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1524 scic_sds_port_default_start_handler,
1525 scic_sds_port_ready_substate_stop_handler,
1526 scic_sds_port_default_destruct_handler,
1527 scic_sds_port_default_reset_handler,
1528 scic_sds_port_ready_configuring_substate_add_phy_handler,
1529 scic_sds_port_ready_configuring_substate_remove_phy_handler
1531 scic_sds_port_default_frame_handler,
1532 scic_sds_port_default_event_handler,
1533 scic_sds_port_default_link_up_handler,
1534 scic_sds_port_default_link_down_handler,
1535 scic_sds_port_default_start_io_handler,
1536 scic_sds_port_ready_configuring_substate_complete_io_handler
1542 * scic_sds_port_set_ready_state_handlers() -
1544 * This macro sets the port ready substate handlers.
1546 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1547 scic_sds_port_set_state_handlers(\
1548 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1552 * ******************************************************************************
1553 * * PORT STATE PRIVATE METHODS
1554 * ****************************************************************************** */
1558 * @this_port: This is the struct scic_sds_port object to suspend.
1560 * This method will susped the port task scheduler for this port object. none
1562 static void scic_sds_port_suspend_port_task_scheduler(
1563 struct scic_sds_port *this_port)
1565 u32 pts_control_value;
1566 u32 tl_control_value;
1568 pts_control_value = scu_port_task_scheduler_read(this_port, control);
1569 tl_control_value = scu_transport_layer_read(this_port, control);
1571 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1572 tl_control_value |= SCU_TLCR_GEN_BIT(CLEAR_TCI_NCQ_MAPPING_TABLE);
1574 scu_port_task_scheduler_write(this_port, control, pts_control_value);
1575 scu_transport_layer_write(this_port, control, tl_control_value);
1580 * @this_port: This is the struct scic_sds_port object to resume.
1582 * This method will resume the port task scheduler for this port object. none
1584 static void scic_sds_port_resume_port_task_scheduler(
1585 struct scic_sds_port *this_port)
1587 u32 pts_control_value;
1589 pts_control_value = scu_port_task_scheduler_read(this_port, control);
1591 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1593 scu_port_task_scheduler_write(this_port, control, pts_control_value);
1597 * ******************************************************************************
1598 * * PORT READY SUBSTATE METHODS
1599 * ****************************************************************************** */
1603 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1605 * This method will perform the actions required by the struct scic_sds_port on
1606 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1607 * port for any ready phys. If there is at least one phy in a ready state then
1608 * the port transitions to the ready operational substate. none
1610 static void scic_sds_port_ready_substate_waiting_enter(
1611 struct sci_base_object *object)
1613 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1615 scic_sds_port_set_ready_state_handlers(
1616 this_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1619 scic_sds_port_suspend_port_task_scheduler(this_port);
1621 this_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1623 if (this_port->active_phy_mask != 0) {
1624 /* At least one of the phys on the port is ready */
1625 sci_base_state_machine_change_state(
1626 &this_port->ready_substate_machine,
1627 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1634 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1636 * This method will perform the actions required by the struct scic_sds_port on
1637 * entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1638 * the state handlers for the port object, notifies the SCI User that the port
1639 * is ready, and resumes port operations. none
1641 static void scic_sds_port_ready_substate_operational_enter(
1642 struct sci_base_object *object)
1645 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1647 scic_sds_port_set_ready_state_handlers(
1648 this_port, SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1652 scic_sds_port_get_controller(this_port), this_port
1655 for (index = 0; index < SCI_MAX_PHYS; index++) {
1656 if (this_port->phy_table[index] != NULL) {
1657 scic_sds_port_write_phy_assignment(
1658 this_port, this_port->phy_table[index]
1663 scic_sds_port_update_viit_entry(this_port);
1665 scic_sds_port_resume_port_task_scheduler(this_port);
1670 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1672 * This method will perform the actions required by the struct scic_sds_port on
1673 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1674 * the port not ready and suspends the port task scheduler. none
1676 static void scic_sds_port_ready_substate_operational_exit(
1677 struct sci_base_object *object)
1679 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1681 scic_cb_port_not_ready(
1682 scic_sds_port_get_controller(this_port),
1684 this_port->not_ready_reason
1689 * ******************************************************************************
1690 * * PORT READY CONFIGURING METHODS
1691 * ****************************************************************************** */
1694 * scic_sds_port_ready_substate_configuring_enter() -
1695 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
1697 * This method will perform the actions required by the struct scic_sds_port on
1698 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1699 * the port not ready and suspends the port task scheduler. none
1701 static void scic_sds_port_ready_substate_configuring_enter(
1702 struct sci_base_object *object)
1704 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1706 scic_sds_port_set_ready_state_handlers(
1707 this_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1710 if (this_port->active_phy_mask == 0) {
1711 scic_cb_port_not_ready(
1712 scic_sds_port_get_controller(this_port),
1714 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
1717 sci_base_state_machine_change_state(
1718 &this_port->ready_substate_machine,
1719 SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1721 } else if (this_port->started_request_count == 0) {
1722 sci_base_state_machine_change_state(
1723 &this_port->ready_substate_machine,
1724 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1729 static void scic_sds_port_ready_substate_configuring_exit(
1730 struct sci_base_object *object)
1732 struct scic_sds_port *this_port = (struct scic_sds_port *)object;
1734 scic_sds_port_suspend_port_task_scheduler(this_port);
1737 /* --------------------------------------------------------------------------- */
1739 const struct sci_base_state scic_sds_port_ready_substate_table[] = {
1740 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1741 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1743 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1744 .enter_state = scic_sds_port_ready_substate_operational_enter,
1745 .exit_state = scic_sds_port_ready_substate_operational_exit
1747 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1748 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1749 .exit_state = scic_sds_port_ready_substate_configuring_exit
1754 * ***************************************************************************
1755 * * DEFAULT HANDLERS
1756 * *************************************************************************** */
1760 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1763 * This is the default method for port a start request. It will report a
1764 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1766 enum sci_status scic_sds_port_default_start_handler(
1767 struct sci_base_port *port)
1769 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1771 dev_warn(sciport_to_dev(sci_port),
1772 "%s: SCIC Port 0x%p requested to start while in invalid "
1776 sci_base_state_machine_get_state(
1777 scic_sds_port_get_base_state_machine(
1778 (struct scic_sds_port *)port)));
1780 return SCI_FAILURE_INVALID_STATE;
1785 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1788 * This is the default method for a port stop request. It will report a
1789 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1791 static enum sci_status scic_sds_port_default_stop_handler(
1792 struct sci_base_port *port)
1794 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1796 dev_warn(sciport_to_dev(sci_port),
1797 "%s: SCIC Port 0x%p requested to stop while in invalid "
1801 sci_base_state_machine_get_state(
1802 scic_sds_port_get_base_state_machine(
1803 (struct scic_sds_port *)port)));
1805 return SCI_FAILURE_INVALID_STATE;
1810 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1813 * This is the default method for a port destruct request. It will report a
1814 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1816 enum sci_status scic_sds_port_default_destruct_handler(
1817 struct sci_base_port *port)
1819 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1821 dev_warn(sciport_to_dev(sci_port),
1822 "%s: SCIC Port 0x%p requested to destruct while in invalid "
1826 sci_base_state_machine_get_state(
1827 scic_sds_port_get_base_state_machine(
1828 (struct scic_sds_port *)port)));
1830 return SCI_FAILURE_INVALID_STATE;
1835 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1837 * @timeout: This is the timeout for the reset request to complete.
1839 * This is the default method for a port reset request. It will report a
1840 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1842 enum sci_status scic_sds_port_default_reset_handler(
1843 struct sci_base_port *port,
1846 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1848 dev_warn(sciport_to_dev(sci_port),
1849 "%s: SCIC Port 0x%p requested to reset while in invalid "
1853 sci_base_state_machine_get_state(
1854 scic_sds_port_get_base_state_machine(
1855 (struct scic_sds_port *)port)));
1857 return SCI_FAILURE_INVALID_STATE;
1862 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1865 * This is the default method for a port add phy request. It will report a
1866 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1868 static enum sci_status scic_sds_port_default_add_phy_handler(
1869 struct sci_base_port *port,
1870 struct sci_base_phy *phy)
1872 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1874 dev_warn(sciport_to_dev(sci_port),
1875 "%s: SCIC Port 0x%p requested to add phy 0x%p while in "
1876 "invalid state %d\n",
1880 sci_base_state_machine_get_state(
1881 scic_sds_port_get_base_state_machine(
1882 (struct scic_sds_port *)port)));
1884 return SCI_FAILURE_INVALID_STATE;
1889 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1892 * This is the default method for a port remove phy request. It will report a
1893 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1895 enum sci_status scic_sds_port_default_remove_phy_handler(
1896 struct sci_base_port *port,
1897 struct sci_base_phy *phy)
1899 struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
1901 dev_warn(sciport_to_dev(sci_port),
1902 "%s: SCIC Port 0x%p requested to remove phy 0x%p while in "
1903 "invalid state %d\n",
1907 sci_base_state_machine_get_state(
1908 scic_sds_port_get_base_state_machine(
1909 (struct scic_sds_port *)port)));
1911 return SCI_FAILURE_INVALID_STATE;
1916 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1919 * This is the default method for a port unsolicited frame request. It will
1920 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1921 * possible to receive an unsolicited frame directed to a port object? It
1922 * seems possible if we implementing virtual functions but until then?
1924 enum sci_status scic_sds_port_default_frame_handler(
1925 struct scic_sds_port *port,
1928 dev_warn(sciport_to_dev(port),
1929 "%s: SCIC Port 0x%p requested to process frame %d while in "
1930 "invalid state %d\n",
1934 sci_base_state_machine_get_state(
1935 scic_sds_port_get_base_state_machine(port)));
1937 scic_sds_controller_release_frame(
1938 scic_sds_port_get_controller(port), frame_index
1941 return SCI_FAILURE_INVALID_STATE;
1946 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1949 * This is the default method for a port event request. It will report a
1950 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1952 enum sci_status scic_sds_port_default_event_handler(
1953 struct scic_sds_port *port,
1956 dev_warn(sciport_to_dev(port),
1957 "%s: SCIC Port 0x%p requested to process event 0x%x while "
1958 "in invalid state %d\n",
1962 sci_base_state_machine_get_state(
1963 scic_sds_port_get_base_state_machine(
1964 (struct scic_sds_port *)port)));
1966 return SCI_FAILURE_INVALID_STATE;
1971 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1974 * This is the default method for a port link up notification. It will report
1975 * a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1977 void scic_sds_port_default_link_up_handler(
1978 struct scic_sds_port *this_port,
1979 struct scic_sds_phy *phy)
1981 dev_warn(sciport_to_dev(this_port),
1982 "%s: SCIC Port 0x%p received link_up notification from phy "
1983 "0x%p while in invalid state %d\n",
1987 sci_base_state_machine_get_state(
1988 scic_sds_port_get_base_state_machine(this_port)));
1993 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
1996 * This is the default method for a port link down notification. It will
1997 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1999 void scic_sds_port_default_link_down_handler(
2000 struct scic_sds_port *this_port,
2001 struct scic_sds_phy *phy)
2003 dev_warn(sciport_to_dev(this_port),
2004 "%s: SCIC Port 0x%p received link down notification from "
2005 "phy 0x%p while in invalid state %d\n",
2009 sci_base_state_machine_get_state(
2010 scic_sds_port_get_base_state_machine(this_port)));
2015 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2018 * This is the default method for a port start io request. It will report a
2019 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2021 enum sci_status scic_sds_port_default_start_io_handler(
2022 struct scic_sds_port *this_port,
2023 struct scic_sds_remote_device *device,
2024 struct scic_sds_request *io_request)
2026 dev_warn(sciport_to_dev(this_port),
2027 "%s: SCIC Port 0x%p requested to start io request 0x%p "
2028 "while in invalid state %d\n",
2032 sci_base_state_machine_get_state(
2033 scic_sds_port_get_base_state_machine(this_port)));
2035 return SCI_FAILURE_INVALID_STATE;
2040 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2043 * This is the default method for a port complete io request. It will report a
2044 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
2046 static enum sci_status scic_sds_port_default_complete_io_handler(
2047 struct scic_sds_port *this_port,
2048 struct scic_sds_remote_device *device,
2049 struct scic_sds_request *io_request)
2051 dev_warn(sciport_to_dev(this_port),
2052 "%s: SCIC Port 0x%p requested to complete io request 0x%p "
2053 "while in invalid state %d\n",
2057 sci_base_state_machine_get_state(
2058 scic_sds_port_get_base_state_machine(this_port)));
2060 return SCI_FAILURE_INVALID_STATE;
2064 * ****************************************************************************
2065 * * GENERAL STATE HANDLERS
2066 * **************************************************************************** */
2070 * @port: This is the struct scic_sds_port object on which the io request count will
2072 * @device: This is the struct scic_sds_remote_device object to which the io request
2073 * is being directed. This parameter is not required to complete this
2075 * @io_request: This is the request that is being completed on this port
2076 * object. This parameter is not required to complete this operation.
2078 * This is a general complete io request handler for the struct scic_sds_port object.
2079 * enum sci_status SCI_SUCCESS
2081 static enum sci_status scic_sds_port_general_complete_io_handler(
2082 struct scic_sds_port *port,
2083 struct scic_sds_remote_device *device,
2084 struct scic_sds_request *io_request)
2086 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2088 scic_sds_port_decrement_request_count(this_port);
2094 * ****************************************************************************
2095 * * STOPPED STATE HANDLERS
2096 * **************************************************************************** */
2100 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2103 * This method takes the struct scic_sds_port from a stopped state and attempts to
2104 * start it. To start a port it must have no assiged devices and it must have
2105 * at least one phy assigned to it. If those conditions are met then the port
2106 * can transition to the ready state. enum sci_status
2107 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This struct scic_sds_port object could
2108 * not be started because the port configuration is not valid. SCI_SUCCESS the
2109 * start request is successful and the struct scic_sds_port object has transitioned to
2110 * the SCI_BASE_PORT_STATE_READY.
2112 static enum sci_status scic_sds_port_stopped_state_start_handler(
2113 struct sci_base_port *port)
2116 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2118 if (this_port->assigned_device_count > 0) {
2120 * / @todo This is a start failure operation because there are still
2121 * / devices assigned to this port. There must be no devices
2122 * / assigned to a port on a start operation. */
2123 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2126 phy_mask = scic_sds_port_get_phys(this_port);
2129 * There are one or more phys assigned to this port. Make sure
2130 * the port's phy mask is in fact legal and supported by the
2132 if (scic_sds_port_is_phy_mask_valid(this_port, phy_mask) == true) {
2133 sci_base_state_machine_change_state(
2134 scic_sds_port_get_base_state_machine(this_port),
2135 SCI_BASE_PORT_STATE_READY
2141 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2146 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2149 * This method takes the struct scic_sds_port that is in a stopped state and handles a
2150 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
2151 * stop request is successful as the struct scic_sds_port object is already stopped.
2153 static enum sci_status scic_sds_port_stopped_state_stop_handler(
2154 struct sci_base_port *port)
2156 /* We are already stopped so there is nothing to do here */
2162 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2165 * This method takes the struct scic_sds_port that is in a stopped state and handles
2166 * the destruct request. The stopped state is the only state in which the
2167 * struct scic_sds_port can be destroyed. This function causes the port object to
2168 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
2170 static enum sci_status scic_sds_port_stopped_state_destruct_handler(
2171 struct sci_base_port *port)
2173 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2175 sci_base_state_machine_stop(&this_port->parent.state_machine);
2182 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2184 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2187 * This method takes the struct scic_sds_port that is in a stopped state and handles
2188 * the add phy request. In MPC mode the only time a phy can be added to a port
2189 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2190 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2191 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2193 static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
2194 struct sci_base_port *port,
2195 struct sci_base_phy *phy)
2197 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2198 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
2199 struct sci_sas_address port_sas_address;
2201 /* Read the port assigned SAS Address if there is one */
2202 scic_sds_port_get_sas_address(this_port, &port_sas_address);
2204 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
2205 struct sci_sas_address phy_sas_address;
2208 * Make sure that the PHY SAS Address matches the SAS Address
2210 scic_sds_phy_get_sas_address(this_phy, &phy_sas_address);
2213 (port_sas_address.high != phy_sas_address.high)
2214 || (port_sas_address.low != phy_sas_address.low)
2216 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
2220 return scic_sds_port_set_phy(this_port, this_phy);
2226 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2228 * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
2231 * This method takes the struct scic_sds_port that is in a stopped state and handles
2232 * the remove phy request. In MPC mode the only time a phy can be removed from
2233 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
2234 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
2235 * be added to the port. SCI_SUCCESS if the phy is added to the port.
2237 static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
2238 struct sci_base_port *port,
2239 struct sci_base_phy *phy)
2241 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2242 struct scic_sds_phy *this_phy = (struct scic_sds_phy *)phy;
2244 return scic_sds_port_clear_phy(this_port, this_phy);
2248 * ****************************************************************************
2249 * * READY STATE HANDLERS
2250 * **************************************************************************** */
2253 * ****************************************************************************
2254 * * RESETTING STATE HANDLERS
2255 * **************************************************************************** */
2258 * ****************************************************************************
2259 * * STOPPING STATE HANDLERS
2260 * **************************************************************************** */
2264 * @port: This is the struct scic_sds_port object on which the io request count will
2266 * @device: This is the struct scic_sds_remote_device object to which the io request
2267 * is being directed. This parameter is not required to complete this
2269 * @io_request: This is the request that is being completed on this port
2270 * object. This parameter is not required to complete this operation.
2272 * This method takes the struct scic_sds_port that is in a stopping state and handles
2273 * the complete io request. Should the request count reach 0 then the port
2274 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
2276 static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
2277 struct scic_sds_port *port,
2278 struct scic_sds_remote_device *device,
2279 struct scic_sds_request *io_request)
2281 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2283 scic_sds_port_decrement_request_count(this_port);
2285 if (this_port->started_request_count == 0) {
2286 sci_base_state_machine_change_state(
2287 scic_sds_port_get_base_state_machine(this_port),
2288 SCI_BASE_PORT_STATE_STOPPED
2296 * ****************************************************************************
2297 * * RESETTING STATE HANDLERS
2298 * **************************************************************************** */
2302 * @port: This is the port object which is being requested to stop.
2304 * This method will stop a failed port. This causes a transition to the
2305 * stopping state. enum sci_status SCI_SUCCESS
2307 static enum sci_status scic_sds_port_reset_state_stop_handler(
2308 struct sci_base_port *port)
2310 struct scic_sds_port *this_port = (struct scic_sds_port *)port;
2312 sci_base_state_machine_change_state(
2313 &this_port->parent.state_machine,
2314 SCI_BASE_PORT_STATE_STOPPING
2322 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2325 * This method will transition a failed port to its ready state. The port
2326 * failed because a hard reset request timed out but at some time later one or
2327 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2329 static void scic_sds_port_reset_state_link_up_handler(
2330 struct scic_sds_port *this_port,
2331 struct scic_sds_phy *phy)
2334 * / @todo We should make sure that the phy that has gone link up is the same
2335 * / one on which we sent the reset. It is possible that the phy on
2336 * / which we sent the reset is not the one that has gone link up and we
2337 * / want to make sure that phy being reset comes back. Consider the
2338 * / case where a reset is sent but before the hardware processes the
2339 * / reset it get a link up on the port because of a hot plug event.
2340 * / because of the reset request this phy will go link down almost
2344 * In the resetting state we don't notify the user regarding
2345 * link up and link down notifications. */
2346 scic_sds_port_general_link_up_handler(this_port, phy, false);
2351 * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
2354 * This method process link down notifications that occur during a port reset
2355 * operation. Link downs can occur during the reset operation. enum sci_status
2358 static void scic_sds_port_reset_state_link_down_handler(
2359 struct scic_sds_port *this_port,
2360 struct scic_sds_phy *phy)
2363 * In the resetting state we don't notify the user regarding
2364 * link up and link down notifications. */
2365 scic_sds_port_deactivate_phy(this_port, phy, false);
2368 /* --------------------------------------------------------------------------- */
2370 struct scic_sds_port_state_handler
2371 scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] =
2373 /* SCI_BASE_PORT_STATE_STOPPED */
2376 scic_sds_port_stopped_state_start_handler,
2377 scic_sds_port_stopped_state_stop_handler,
2378 scic_sds_port_stopped_state_destruct_handler,
2379 scic_sds_port_default_reset_handler,
2380 scic_sds_port_stopped_state_add_phy_handler,
2381 scic_sds_port_stopped_state_remove_phy_handler
2383 scic_sds_port_default_frame_handler,
2384 scic_sds_port_default_event_handler,
2385 scic_sds_port_default_link_up_handler,
2386 scic_sds_port_default_link_down_handler,
2387 scic_sds_port_default_start_io_handler,
2388 scic_sds_port_default_complete_io_handler
2390 /* SCI_BASE_PORT_STATE_STOPPING */
2393 scic_sds_port_default_start_handler,
2394 scic_sds_port_default_stop_handler,
2395 scic_sds_port_default_destruct_handler,
2396 scic_sds_port_default_reset_handler,
2397 scic_sds_port_default_add_phy_handler,
2398 scic_sds_port_default_remove_phy_handler
2400 scic_sds_port_default_frame_handler,
2401 scic_sds_port_default_event_handler,
2402 scic_sds_port_default_link_up_handler,
2403 scic_sds_port_default_link_down_handler,
2404 scic_sds_port_default_start_io_handler,
2405 scic_sds_port_stopping_state_complete_io_handler
2407 /* SCI_BASE_PORT_STATE_READY */
2410 scic_sds_port_default_start_handler,
2411 scic_sds_port_default_stop_handler,
2412 scic_sds_port_default_destruct_handler,
2413 scic_sds_port_default_reset_handler,
2414 scic_sds_port_default_add_phy_handler,
2415 scic_sds_port_default_remove_phy_handler
2417 scic_sds_port_default_frame_handler,
2418 scic_sds_port_default_event_handler,
2419 scic_sds_port_default_link_up_handler,
2420 scic_sds_port_default_link_down_handler,
2421 scic_sds_port_default_start_io_handler,
2422 scic_sds_port_general_complete_io_handler
2424 /* SCI_BASE_PORT_STATE_RESETTING */
2427 scic_sds_port_default_start_handler,
2428 scic_sds_port_reset_state_stop_handler,
2429 scic_sds_port_default_destruct_handler,
2430 scic_sds_port_default_reset_handler,
2431 scic_sds_port_default_add_phy_handler,
2432 scic_sds_port_default_remove_phy_handler
2434 scic_sds_port_default_frame_handler,
2435 scic_sds_port_default_event_handler,
2436 scic_sds_port_reset_state_link_up_handler,
2437 scic_sds_port_reset_state_link_down_handler,
2438 scic_sds_port_default_start_io_handler,
2439 scic_sds_port_general_complete_io_handler
2441 /* SCI_BASE_PORT_STATE_FAILED */
2444 scic_sds_port_default_start_handler,
2445 scic_sds_port_default_stop_handler,
2446 scic_sds_port_default_destruct_handler,
2447 scic_sds_port_default_reset_handler,
2448 scic_sds_port_default_add_phy_handler,
2449 scic_sds_port_default_remove_phy_handler
2451 scic_sds_port_default_frame_handler,
2452 scic_sds_port_default_event_handler,
2453 scic_sds_port_default_link_up_handler,
2454 scic_sds_port_default_link_down_handler,
2455 scic_sds_port_default_start_io_handler,
2456 scic_sds_port_general_complete_io_handler
2461 * ******************************************************************************
2462 * * PORT STATE PRIVATE METHODS
2463 * ****************************************************************************** */
2467 * @this_port: This is the port object which to suspend.
2469 * This method will enable the SCU Port Task Scheduler for this port object but
2470 * will leave the port task scheduler in a suspended state. none
2472 static void scic_sds_port_enable_port_task_scheduler(
2473 struct scic_sds_port *this_port)
2475 u32 pts_control_value;
2477 pts_control_value = scu_port_task_scheduler_read(this_port, control);
2479 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
2481 scu_port_task_scheduler_write(this_port, control, pts_control_value);
2486 * @this_port: This is the port object which to resume.
2488 * This method will disable the SCU port task scheduler for this port object.
2491 static void scic_sds_port_disable_port_task_scheduler(
2492 struct scic_sds_port *this_port)
2494 u32 pts_control_value;
2496 pts_control_value = scu_port_task_scheduler_read(this_port, control);
2498 pts_control_value &= ~(SCU_PTSxCR_GEN_BIT(ENABLE)
2499 | SCU_PTSxCR_GEN_BIT(SUSPEND));
2501 scu_port_task_scheduler_write(this_port, control, pts_control_value);
2505 * ******************************************************************************
2506 * * PORT STATE METHODS
2507 * ****************************************************************************** */
2511 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2513 * This method will perform the actions required by the struct scic_sds_port on
2514 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2515 * state handlers for the struct scic_sds_port object and disables the port task
2516 * scheduler in the hardware. none
2518 static void scic_sds_port_stopped_state_enter(
2519 struct sci_base_object *object)
2521 struct scic_sds_port *this_port;
2523 this_port = (struct scic_sds_port *)object;
2525 scic_sds_port_set_base_state_handlers(
2526 this_port, SCI_BASE_PORT_STATE_STOPPED
2530 SCI_BASE_PORT_STATE_STOPPING
2531 == this_port->parent.state_machine.previous_state_id
2534 * If we enter this state becasuse of a request to stop
2535 * the port then we want to disable the hardwares port
2536 * task scheduler. */
2537 scic_sds_port_disable_port_task_scheduler(this_port);
2543 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2545 * This method will perform the actions required by the struct scic_sds_port on
2546 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2547 * port task scheduler. none
2549 static void scic_sds_port_stopped_state_exit(
2550 struct sci_base_object *object)
2552 struct scic_sds_port *this_port;
2554 this_port = (struct scic_sds_port *)object;
2556 /* Enable and suspend the port task scheduler */
2557 scic_sds_port_enable_port_task_scheduler(this_port);
2562 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2564 * This method will perform the actions required by the struct scic_sds_port on
2565 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2566 * handlers for the struct scic_sds_port object, reports the port object as not ready
2567 * and starts the ready substate machine. none
2569 static void scic_sds_port_ready_state_enter(
2570 struct sci_base_object *object)
2572 struct scic_sds_port *this_port;
2574 this_port = (struct scic_sds_port *)object;
2576 /* Put the ready state handlers in place though they will not be there long */
2577 scic_sds_port_set_base_state_handlers(
2578 this_port, SCI_BASE_PORT_STATE_READY
2582 SCI_BASE_PORT_STATE_RESETTING
2583 == this_port->parent.state_machine.previous_state_id
2585 scic_cb_port_hard_reset_complete(
2586 scic_sds_port_get_controller(this_port),
2591 /* Notify the caller that the port is not yet ready */
2592 scic_cb_port_not_ready(
2593 scic_sds_port_get_controller(this_port),
2595 SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
2599 /* Start the ready substate machine */
2600 sci_base_state_machine_start(
2601 scic_sds_port_get_ready_substate_machine(this_port)
2607 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2609 * This method will perform the actions required by the struct scic_sds_port on
2610 * exiting the SCI_BASE_STATE_READY. This function does nothing. none
2612 static void scic_sds_port_ready_state_exit(
2613 struct sci_base_object *object)
2615 struct scic_sds_port *this_port;
2617 this_port = (struct scic_sds_port *)object;
2619 sci_base_state_machine_stop(&this_port->ready_substate_machine);
2624 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2626 * This method will perform the actions required by the struct scic_sds_port on
2627 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2628 * state handlers for the struct scic_sds_port object. none
2630 static void scic_sds_port_resetting_state_enter(
2631 struct sci_base_object *object)
2633 struct scic_sds_port *this_port;
2635 this_port = (struct scic_sds_port *)object;
2637 scic_sds_port_set_base_state_handlers(
2638 this_port, SCI_BASE_PORT_STATE_RESETTING
2641 scic_sds_port_set_direct_attached_device_id(
2643 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
2649 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2651 * This method will perform the actions required by the struct scic_sds_port on
2652 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2654 static void scic_sds_port_resetting_state_exit(
2655 struct sci_base_object *object)
2657 struct scic_sds_port *this_port;
2659 this_port = (struct scic_sds_port *)object;
2662 scic_sds_port_get_controller(this_port),
2663 this_port->timer_handle
2669 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2671 * This method will perform the actions required by the struct scic_sds_port on
2672 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2673 * state handlers for the struct scic_sds_port object. none
2675 static void scic_sds_port_stopping_state_enter(
2676 struct sci_base_object *object)
2678 struct scic_sds_port *this_port;
2680 this_port = (struct scic_sds_port *)object;
2682 scic_sds_port_set_base_state_handlers(
2683 this_port, SCI_BASE_PORT_STATE_STOPPING
2689 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2691 * This method will perform the actions required by the struct scic_sds_port on
2692 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2694 static void scic_sds_port_stopping_state_exit(
2695 struct sci_base_object *object)
2697 struct scic_sds_port *this_port;
2699 this_port = (struct scic_sds_port *)object;
2702 scic_sds_port_get_controller(this_port),
2703 this_port->timer_handle
2709 * @object: This is the struct sci_base_object which is cast to a struct scic_sds_port object.
2711 * This method will perform the actions required by the struct scic_sds_port on
2712 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2713 * state handlers for the struct scic_sds_port object. none
2715 static void scic_sds_port_failed_state_enter(
2716 struct sci_base_object *object)
2718 struct scic_sds_port *this_port;
2720 this_port = (struct scic_sds_port *)object;
2722 scic_sds_port_set_base_state_handlers(
2724 SCI_BASE_PORT_STATE_FAILED
2727 scic_cb_port_hard_reset_complete(
2728 scic_sds_port_get_controller(this_port),
2734 /* --------------------------------------------------------------------------- */
2736 const struct sci_base_state scic_sds_port_state_table[] = {
2737 [SCI_BASE_PORT_STATE_STOPPED] = {
2738 .enter_state = scic_sds_port_stopped_state_enter,
2739 .exit_state = scic_sds_port_stopped_state_exit
2741 [SCI_BASE_PORT_STATE_STOPPING] = {
2742 .enter_state = scic_sds_port_stopping_state_enter,
2743 .exit_state = scic_sds_port_stopping_state_exit
2745 [SCI_BASE_PORT_STATE_READY] = {
2746 .enter_state = scic_sds_port_ready_state_enter,
2747 .exit_state = scic_sds_port_ready_state_exit
2749 [SCI_BASE_PORT_STATE_RESETTING] = {
2750 .enter_state = scic_sds_port_resetting_state_enter,
2751 .exit_state = scic_sds_port_resetting_state_exit
2753 [SCI_BASE_PORT_STATE_FAILED] = {
2754 .enter_state = scic_sds_port_failed_state_enter,