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 "scic_controller.h"
59 #include "scic_port.h"
60 #include "scic_sds_controller.h"
61 #include "scic_sds_phy.h"
62 #include "scic_sds_port.h"
63 #include "remote_device.h"
64 #include "remote_node_context.h"
65 #include "scic_sds_request.h"
66 #include "sci_environment.h"
67 #include "scu_registers.h"
69 #define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
70 #define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
72 #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
73 #define SCU_DUMMY_INDEX (0xFFFF)
78 * @sci_port: This is the port object to which the phy is being assigned.
79 * @phy_index: This is the phy index that is being assigned to the port.
81 * This method will return a true value if the specified phy can be assigned to
82 * this port The following is a list of phys for each port that are allowed: -
83 * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
84 * doesn't preclude all configurations. It merely ensures that a phy is part
85 * of the allowable set of phy identifiers for that port. For example, one
86 * could assign phy 3 to port 0 and no other phys. Please refer to
87 * scic_sds_port_is_phy_mask_valid() for information regarding whether the
88 * phy_mask for a port can be supported. bool true if this is a valid phy
89 * assignment for the port false if this is not a valid phy assignment for the
92 bool scic_sds_port_is_valid_phy_assignment(
93 struct scic_sds_port *sci_port,
96 /* Initialize to invalid value. */
97 u32 existing_phy_index = SCI_MAX_PHYS;
100 if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
104 if (sci_port->physical_port_index == 3 && phy_index != 3) {
109 (sci_port->physical_port_index == 2)
110 && ((phy_index == 0) || (phy_index == 1))
115 for (index = 0; index < SCI_MAX_PHYS; index++) {
116 if ((sci_port->phy_table[index] != NULL)
117 && (index != phy_index)) {
118 existing_phy_index = index;
123 * Ensure that all of the phys in the port are capable of
124 * operating at the same maximum link rate. */
126 (existing_phy_index < SCI_MAX_PHYS)
127 && (sci_port->owning_controller->user_parameters.sds1.phys[
128 phy_index].max_speed_generation !=
129 sci_port->owning_controller->user_parameters.sds1.phys[
130 existing_phy_index].max_speed_generation)
138 * This method requests a list (mask) of the phys contained in the supplied SAS
140 * @sci_port: a handle corresponding to the SAS port for which to return the
143 * Return a bit mask indicating which phys are a part of this port. Each bit
144 * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
146 static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
153 for (index = 0; index < SCI_MAX_PHYS; index++) {
154 if (sci_port->phy_table[index] != NULL) {
155 mask |= (1 << index);
164 * @sci_port: This is the port object for which to determine if the phy mask
167 * This method will return a true value if the port's phy mask can be supported
168 * by the SCU. The following is a list of valid PHY mask configurations for
169 * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
170 * - Port 3 - [3] This method returns a boolean indication specifying if the
171 * phy mask can be supported. true if this is a valid phy assignment for the
172 * port false if this is not a valid phy assignment for the port
174 static bool scic_sds_port_is_phy_mask_valid(
175 struct scic_sds_port *sci_port,
178 if (sci_port->physical_port_index == 0) {
179 if (((phy_mask & 0x0F) == 0x0F)
180 || ((phy_mask & 0x03) == 0x03)
181 || ((phy_mask & 0x01) == 0x01)
184 } else if (sci_port->physical_port_index == 1) {
185 if (((phy_mask & 0x02) == 0x02)
188 } else if (sci_port->physical_port_index == 2) {
189 if (((phy_mask & 0x0C) == 0x0C)
190 || ((phy_mask & 0x04) == 0x04)
193 } else if (sci_port->physical_port_index == 3) {
194 if (((phy_mask & 0x08) == 0x08)
204 * @sci_port: This parameter specifies the port from which to return a
207 * This method retrieves a currently active (i.e. connected) phy contained in
208 * the port. Currently, the lowest order phy that is connected is returned.
209 * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
210 * returned if there are no currently active (i.e. connected to a remote end
211 * point) phys contained in the port. All other values specify a struct scic_sds_phy
212 * object that is active in the port.
214 static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
215 struct scic_sds_port *sci_port
218 struct scic_sds_phy *phy;
220 for (index = 0; index < SCI_MAX_PHYS; index++) {
222 * Ensure that the phy is both part of the port and currently
223 * connected to the remote end-point. */
224 phy = sci_port->phy_table[index];
227 && scic_sds_port_active_phy(sci_port, phy)
237 * scic_sds_port_set_phy() -
238 * @out]: port The port object to which the phy assignement is being made.
239 * @out]: phy The phy which is being assigned to the port.
241 * This method attempts to make the assignment of the phy to the port. If
242 * successful the phy is assigned to the ports phy table. bool true if the phy
243 * assignment can be made. false if the phy assignement can not be made. This
244 * is a functional test that only fails if the phy is currently assigned to a
247 static enum sci_status scic_sds_port_set_phy(
248 struct scic_sds_port *port,
249 struct scic_sds_phy *phy)
252 * Check to see if we can add this phy to a port
253 * that means that the phy is not part of a port and that the port does
254 * not already have a phy assinged to the phy index. */
256 (port->phy_table[phy->phy_index] == NULL)
257 && (scic_sds_phy_get_port(phy) == NULL)
258 && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
261 * Phy is being added in the stopped state so we are in MPC mode
262 * make logical port index = physical port index */
263 port->logical_port_index = port->physical_port_index;
264 port->phy_table[phy->phy_index] = phy;
265 scic_sds_phy_set_port(phy, port);
274 * scic_sds_port_clear_phy() -
275 * @out]: port The port from which the phy is being cleared.
276 * @out]: phy The phy being cleared from the port.
278 * This method will clear the phy assigned to this port. This method fails if
279 * this phy is not currently assinged to this port. bool true if the phy is
280 * removed from the port. false if this phy is not assined to this port.
282 static enum sci_status scic_sds_port_clear_phy(
283 struct scic_sds_port *port,
284 struct scic_sds_phy *phy)
286 /* Make sure that this phy is part of this port */
288 (port->phy_table[phy->phy_index] == phy)
289 && (scic_sds_phy_get_port(phy) == port)
291 /* Yep it is assigned to this port so remove it */
292 scic_sds_phy_set_port(
294 &scic_sds_port_get_controller(port)->port_table[SCI_MAX_PORTS]
297 port->phy_table[phy->phy_index] = NULL;
306 * scic_sds_port_add_phy() -
307 * @sci_port: This parameter specifies the port in which the phy will be added.
308 * @sci_phy: This parameter is the phy which is to be added to the port.
310 * This method will add a PHY to the selected port. This method returns an
311 * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
312 * is failre to add the phy to the port.
314 enum sci_status scic_sds_port_add_phy(
315 struct scic_sds_port *sci_port,
316 struct scic_sds_phy *sci_phy)
318 return sci_port->state_handlers->add_phy_handler(
324 * scic_sds_port_remove_phy() -
325 * @sci_port: This parameter specifies the port in which the phy will be added.
326 * @sci_phy: This parameter is the phy which is to be added to the port.
328 * This method will remove the PHY from the selected PORT. This method returns
329 * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
330 * status is failre to add the phy to the port.
332 enum sci_status scic_sds_port_remove_phy(
333 struct scic_sds_port *sci_port,
334 struct scic_sds_phy *sci_phy)
336 return sci_port->state_handlers->remove_phy_handler(
341 * This method requests the SAS address for the supplied SAS port from the SCI
343 * @sci_port: a handle corresponding to the SAS port for which to return the
345 * @sas_address: This parameter specifies a pointer to a SAS address structure
346 * into which the core will copy the SAS address for the port.
349 void scic_sds_port_get_sas_address(
350 struct scic_sds_port *sci_port,
351 struct sci_sas_address *sas_address)
355 sas_address->high = 0;
356 sas_address->low = 0;
358 for (index = 0; index < SCI_MAX_PHYS; index++) {
359 if (sci_port->phy_table[index] != NULL) {
360 scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
366 * This method will indicate which protocols are supported by this port.
367 * @sci_port: a handle corresponding to the SAS port for which to return the
368 * supported protocols.
369 * @protocols: This parameter specifies a pointer to an IAF protocol field
370 * structure into which the core will copy the protocol values for the port.
371 * The values are returned as part of a bit mask in order to allow for
372 * multi-protocol support.
375 static void scic_sds_port_get_protocols(
376 struct scic_sds_port *sci_port,
377 struct sci_sas_identify_address_frame_protocols *protocols)
381 protocols->u.all = 0;
383 for (index = 0; index < SCI_MAX_PHYS; index++) {
384 if (sci_port->phy_table[index] != NULL) {
385 scic_sds_phy_get_protocols(sci_port->phy_table[index], protocols);
391 * This method requests the SAS address for the device directly attached to
393 * @sci_port: a handle corresponding to the SAS port for which to return the
395 * @sas_address: This parameter specifies a pointer to a SAS address structure
396 * into which the core will copy the SAS address for the device directly
397 * attached to the port.
400 void scic_sds_port_get_attached_sas_address(
401 struct scic_sds_port *sci_port,
402 struct sci_sas_address *sas_address)
404 struct sci_sas_identify_address_frame_protocols protocols;
405 struct scic_sds_phy *phy;
408 * Ensure that the phy is both part of the port and currently
409 * connected to the remote end-point. */
410 phy = scic_sds_port_get_a_connected_phy(sci_port);
412 scic_sds_phy_get_attached_phy_protocols(phy, &protocols);
414 if (!protocols.u.bits.stp_target) {
415 scic_sds_phy_get_attached_sas_address(phy, sas_address);
417 scic_sds_phy_get_sas_address(phy, sas_address);
418 sas_address->low += phy->phy_index;
421 sas_address->high = 0;
422 sas_address->low = 0;
427 * This method will indicate which protocols are supported by this remote
429 * @sci_port: a handle corresponding to the SAS port for which to return the
430 * supported protocols.
431 * @protocols: This parameter specifies a pointer to an IAF protocol field
432 * structure into which the core will copy the protocol values for the port.
433 * The values are returned as part of a bit mask in order to allow for
434 * multi-protocol support.
437 static void scic_sds_port_get_attached_protocols(
438 struct scic_sds_port *sci_port,
439 struct sci_sas_identify_address_frame_protocols *protocols)
441 struct scic_sds_phy *phy;
444 * Ensure that the phy is both part of the port and currently
445 * connected to the remote end-point. */
446 phy = scic_sds_port_get_a_connected_phy(sci_port);
448 scic_sds_phy_get_attached_phy_protocols(phy, protocols);
450 protocols->u.all = 0;
454 * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
456 * @sci_port: logical port on which we need to create the remote node context
457 * @rni: remote node index for this remote node context.
459 * This routine will construct a dummy remote node context data structure
460 * This structure will be posted to the hardware to work around a scheduler
461 * error in the hardware.
463 static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
465 union scu_remote_node_context *rnc;
467 rnc = &sci_port->owning_controller->remote_node_context_table[rni];
469 memset(rnc, 0, sizeof(union scu_remote_node_context));
471 rnc->ssp.remote_sas_address_hi = 0;
472 rnc->ssp.remote_sas_address_lo = 0;
474 rnc->ssp.remote_node_index = rni;
475 rnc->ssp.remote_node_port_width = 1;
476 rnc->ssp.logical_port_index = sci_port->physical_port_index;
478 rnc->ssp.nexus_loss_timer_enable = false;
479 rnc->ssp.check_bit = false;
480 rnc->ssp.is_valid = true;
481 rnc->ssp.is_remote_node_context = true;
482 rnc->ssp.function_number = 0;
483 rnc->ssp.arbitration_wait_time = 0;
487 * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
488 * @sci_port The logical port on which we need to create the
489 * remote node context.
491 * @tci The remote node index for this remote node context.
493 * This routine will construct a dummy task context data structure. This
494 * structure will be posted to the hardwre to work around a scheduler error
498 static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
500 struct scu_task_context *task_context;
502 task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
504 memset(task_context, 0, sizeof(struct scu_task_context));
506 task_context->abort = 0;
507 task_context->priority = 0;
508 task_context->initiator_request = 1;
509 task_context->connection_rate = 1;
510 task_context->protocol_engine_index = 0;
511 task_context->logical_port_index = sci_port->physical_port_index;
512 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
513 task_context->task_index = scic_sds_io_tag_get_index(tci);
514 task_context->valid = SCU_TASK_CONTEXT_VALID;
515 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
517 task_context->remote_node_index = sci_port->reserved_rni;
518 task_context->command_code = 0;
520 task_context->link_layer_control = 0;
521 task_context->do_not_dma_ssp_good_response = 1;
522 task_context->strict_ordering = 0;
523 task_context->control_frame = 0;
524 task_context->timeout_enable = 0;
525 task_context->block_guard_enable = 0;
527 task_context->address_modifier = 0;
529 task_context->task_phase = 0x01;
532 static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
534 struct scic_sds_controller *scic = sci_port->owning_controller;
536 if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
537 scic_controller_free_io_tag(scic, sci_port->reserved_tci);
539 if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
540 scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
541 1, sci_port->reserved_rni);
543 sci_port->reserved_rni = SCU_DUMMY_INDEX;
544 sci_port->reserved_tci = SCU_DUMMY_INDEX;
548 * This method performs initialization of the supplied port. Initialization
549 * includes: - state machine initialization - member variable initialization
550 * - configuring the phy_mask
552 * @transport_layer_registers:
553 * @port_task_scheduler_registers:
554 * @port_configuration_regsiter:
556 * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
557 * if the phy being added to the port
559 enum sci_status scic_sds_port_initialize(
560 struct scic_sds_port *sci_port,
561 void __iomem *port_task_scheduler_registers,
562 void __iomem *port_configuration_regsiter,
563 void __iomem *viit_registers)
565 sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
566 sci_port->port_pe_configuration_register = port_configuration_regsiter;
567 sci_port->viit_registers = viit_registers;
573 * scic_port_get_properties() - This method simply returns the properties
574 * regarding the port, such as: physical index, protocols, sas address, etc.
575 * @port: this parameter specifies the port for which to retrieve the physical
577 * @properties: This parameter specifies the properties structure into which to
578 * copy the requested information.
580 * Indicate if the user specified a valid port. SCI_SUCCESS This value is
581 * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
582 * value is returned if the specified port is not valid. When this value is
583 * returned, no data is copied to the properties output parameter.
585 enum sci_status scic_port_get_properties(
586 struct scic_sds_port *port,
587 struct scic_port_properties *prop)
589 if ((port == NULL) ||
590 (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
591 return SCI_FAILURE_INVALID_PORT;
593 prop->index = port->logical_port_index;
594 prop->phy_mask = scic_sds_port_get_phys(port);
595 scic_sds_port_get_sas_address(port, &prop->local.sas_address);
596 scic_sds_port_get_protocols(port, &prop->local.protocols);
597 scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
598 scic_sds_port_get_attached_protocols(port, &prop->remote.protocols);
604 * scic_port_hard_reset() - perform port hard reset
605 * @port: a handle corresponding to the SAS port to be hard reset.
606 * @reset_timeout: This parameter specifies the number of milliseconds in which
607 * the port reset operation should complete.
609 * The SCI User callback in scic_user_callbacks_t will only be called once for
610 * each phy in the SAS Port at completion of the hard reset sequence. Return a
611 * status indicating whether the hard reset started successfully. SCI_SUCCESS
612 * This value is returned if the hard reset operation started successfully.
614 enum sci_status scic_port_hard_reset(
615 struct scic_sds_port *port,
618 return port->state_handlers->reset_handler(
619 port, reset_timeout);
623 * This method assigns the direct attached device ID for this port.
625 * @param[in] sci_port The port for which the direct attached device id is to
627 * @param[in] device_id The direct attached device ID to assign to the port.
628 * This will be the RNi for the device
630 void scic_sds_port_setup_transports(
631 struct scic_sds_port *sci_port,
636 for (index = 0; index < SCI_MAX_PHYS; index++) {
637 if (sci_port->active_phy_mask & (1 << index))
638 scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
644 * @sci_port: This is the port on which the phy should be enabled.
645 * @sci_phy: This is the specific phy which to enable.
646 * @do_notify_user: This parameter specifies whether to inform the user (via
647 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
649 * This function will activate the phy in the port.
650 * Activation includes: - adding
651 * the phy to the port - enabling the Protocol Engine in the silicon. -
652 * notifying the user that the link is up. none
654 static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
655 struct scic_sds_phy *sci_phy,
658 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
659 struct sci_sas_identify_address_frame_protocols protocols;
660 struct isci_host *ihost = scic->ihost;
662 scic_sds_phy_get_attached_phy_protocols(sci_phy, &protocols);
664 /* If this is sata port then the phy has already been resumed */
665 if (!protocols.u.bits.stp_target)
666 scic_sds_phy_resume(sci_phy);
668 sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
670 scic_sds_controller_clear_invalid_phy(scic, sci_phy);
672 if (do_notify_user == true)
673 isci_port_link_up(ihost, sci_port, sci_phy);
676 void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
677 struct scic_sds_phy *sci_phy,
680 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
681 struct isci_port *iport = sci_object_get_association(sci_port);
682 struct isci_host *ihost = scic->ihost;
683 struct isci_phy *iphy = sci_object_get_association(sci_phy);
685 sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
687 sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
689 /* Re-assign the phy back to the LP as if it were a narrow port */
690 writel(sci_phy->phy_index,
691 &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
693 if (do_notify_user == true)
694 isci_port_link_down(ihost, iphy, iport);
699 * @sci_port: This is the port on which the phy should be disabled.
700 * @sci_phy: This is the specific phy which to disabled.
702 * This function will disable the phy and report that the phy is not valid for
703 * this port object. None
705 static void scic_sds_port_invalid_link_up(
706 struct scic_sds_port *sci_port,
707 struct scic_sds_phy *sci_phy)
709 struct scic_sds_controller *scic =
710 scic_sds_port_get_controller(sci_port);
713 * Check to see if we have alreay reported this link as bad and if
714 * not go ahead and tell the SCI_USER that we have discovered an
717 if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
718 scic_sds_controller_set_invalid_phy(scic, sci_phy);
719 isci_port_invalid_link_up(scic, sci_port, sci_phy);
724 * scic_sds_port_general_link_up_handler - phy can be assigned to port?
725 * @sci_port: scic_sds_port object for which has a phy that has gone link up.
726 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
727 * @do_notify_user: This parameter specifies whether to inform the user (via
728 * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
730 * Determine if this phy can be assigned to this
731 * port . If the phy is not a valid PHY for
732 * this port then the function will notify the user. A PHY can only be
733 * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
734 * the same port. none
736 static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
737 struct scic_sds_phy *sci_phy,
740 struct sci_sas_address port_sas_address;
741 struct sci_sas_address phy_sas_address;
743 scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
744 scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
746 /* If the SAS address of the new phy matches the SAS address of
747 * other phys in the port OR this is the first phy in the port,
748 * then activate the phy and allow it to be used for operations
751 if ((phy_sas_address.high == port_sas_address.high &&
752 phy_sas_address.low == port_sas_address.low) ||
753 sci_port->active_phy_mask == 0) {
754 struct sci_base_state_machine *sm = &sci_port->state_machine;
756 scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
757 if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
758 sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY);
760 scic_sds_port_invalid_link_up(sci_port, sci_phy);
766 * This method returns false if the port only has a single phy object assigned.
767 * If there are no phys or more than one phy then the method will return
769 * @sci_port: The port for which the wide port condition is to be checked.
771 * bool true Is returned if this is a wide ported port. false Is returned if
772 * this is a narrow port.
774 static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
779 for (index = 0; index < SCI_MAX_PHYS; index++) {
780 if (sci_port->phy_table[index] != NULL) {
785 return phy_count != 1;
789 * This method is called by the PHY object when the link is detected. if the
790 * port wants the PHY to continue on to the link up state then the port
791 * layer must return true. If the port object returns false the phy object
792 * must halt its attempt to go link up.
793 * @sci_port: The port associated with the phy object.
794 * @sci_phy: The phy object that is trying to go link up.
796 * true if the phy object can continue to the link up condition. true Is
797 * returned if this phy can continue to the ready state. false Is returned if
798 * can not continue on to the ready state. This notification is in place for
799 * wide ports and direct attached phys. Since there are no wide ported SATA
800 * devices this could become an invalid port configuration.
802 bool scic_sds_port_link_detected(
803 struct scic_sds_port *sci_port,
804 struct scic_sds_phy *sci_phy)
806 struct sci_sas_identify_address_frame_protocols protocols;
808 scic_sds_phy_get_attached_phy_protocols(sci_phy, &protocols);
811 (sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT)
812 && (protocols.u.bits.stp_target)
813 && scic_sds_port_is_wide(sci_port)
815 scic_sds_port_invalid_link_up(sci_port, sci_phy);
824 * This method is the entry point for the phy to inform the port that it is now
830 void scic_sds_port_link_up(
831 struct scic_sds_port *sci_port,
832 struct scic_sds_phy *sci_phy)
834 sci_phy->is_in_link_training = false;
836 sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
840 * This method is the entry point for the phy to inform the port that it is no
841 * longer in a ready state
846 void scic_sds_port_link_down(
847 struct scic_sds_port *sci_port,
848 struct scic_sds_phy *sci_phy)
850 sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
854 * This method is called to start an IO request on this port.
861 enum sci_status scic_sds_port_start_io(
862 struct scic_sds_port *sci_port,
863 struct scic_sds_remote_device *sci_dev,
864 struct scic_sds_request *sci_req)
866 return sci_port->state_handlers->start_io_handler(
867 sci_port, sci_dev, sci_req);
871 * This method is called to complete an IO request to the port.
878 enum sci_status scic_sds_port_complete_io(
879 struct scic_sds_port *sci_port,
880 struct scic_sds_remote_device *sci_dev,
881 struct scic_sds_request *sci_req)
883 return sci_port->state_handlers->complete_io_handler(
884 sci_port, sci_dev, sci_req);
888 * This method is provided to timeout requests for port operations. Mostly its
889 * for the port reset operation.
893 static void scic_sds_port_timeout_handler(void *port)
895 struct scic_sds_port *sci_port = port;
898 current_state = sci_base_state_machine_get_state(
899 &sci_port->state_machine);
901 if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
903 * if the port is still in the resetting state then the
904 * timeout fired before the reset completed.
906 sci_base_state_machine_change_state(
907 &sci_port->state_machine,
908 SCI_BASE_PORT_STATE_FAILED);
909 } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
911 * if the port is stopped then the start request failed
912 * In this case stay in the stopped state.
914 dev_err(sciport_to_dev(sci_port),
915 "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
918 } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
920 * if the port is still stopping then the stop has not
923 isci_port_stop_complete(
924 scic_sds_port_get_controller(sci_port),
926 SCI_FAILURE_TIMEOUT);
929 * The port is in the ready state and we have a timer
930 * reporting a timeout this should not happen.
932 dev_err(sciport_to_dev(sci_port),
933 "%s: SCIC Port 0x%p is processing a timeout operation "
941 /* --------------------------------------------------------------------------- */
944 * This function updates the hardwares VIIT entry for this port.
948 static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
950 struct sci_sas_address sas_address;
952 scic_sds_port_get_sas_address(sci_port, &sas_address);
954 writel(sas_address.high,
955 &sci_port->viit_registers->initiator_sas_address_hi);
956 writel(sas_address.low,
957 &sci_port->viit_registers->initiator_sas_address_lo);
959 /* This value get cleared just in case its not already cleared */
960 writel(0, &sci_port->viit_registers->reserved);
962 /* We are required to update the status register last */
963 writel(SCU_VIIT_ENTRY_ID_VIIT |
964 SCU_VIIT_IPPT_INITIATOR |
965 ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
966 SCU_VIIT_STATUS_ALL_VALID,
967 &sci_port->viit_registers->status);
971 * This method returns the maximum allowed speed for data transfers on this
972 * port. This maximum allowed speed evaluates to the maximum speed of the
973 * slowest phy in the port.
974 * @sci_port: This parameter specifies the port for which to retrieve the
975 * maximum allowed speed.
977 * This method returns the maximum negotiated speed of the slowest phy in the
980 enum sas_linkrate scic_sds_port_get_max_allowed_speed(
981 struct scic_sds_port *sci_port)
984 enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
985 struct scic_sds_phy *phy = NULL;
988 * Loop through all of the phys in this port and find the phy with the
989 * lowest maximum link rate. */
990 for (index = 0; index < SCI_MAX_PHYS; index++) {
991 phy = sci_port->phy_table[index];
994 && (scic_sds_port_active_phy(sci_port, phy) == true)
995 && (phy->max_negotiated_speed < max_allowed_speed)
997 max_allowed_speed = phy->max_negotiated_speed;
1000 return max_allowed_speed;
1005 * This method passes the event to core user.
1006 * @sci_port: The port that a BCN happens.
1007 * @sci_phy: The phy that receives BCN.
1010 void scic_sds_port_broadcast_change_received(
1011 struct scic_sds_port *sci_port,
1012 struct scic_sds_phy *sci_phy)
1014 struct scic_sds_controller *scic = sci_port->owning_controller;
1015 struct isci_host *ihost = scic->ihost;
1017 /* notify the user. */
1018 isci_port_bc_change_received(ihost, sci_port, sci_phy);
1023 * This API methhod enables the broadcast change notification from underneath
1025 * @sci_port: The port that a BCN had been disabled from.
1028 void scic_port_enable_broadcast_change_notification(
1029 struct scic_sds_port *port)
1031 struct scic_sds_phy *phy;
1035 /* Loop through all of the phys to enable BCN. */
1036 for (index = 0; index < SCI_MAX_PHYS; index++) {
1037 phy = port->phy_table[index];
1040 readl(&phy->link_layer_registers->link_layer_control);
1042 /* clear the bit by writing 1. */
1043 writel(register_value,
1044 &phy->link_layer_registers->link_layer_control);
1050 * ****************************************************************************
1051 * * READY SUBSTATE HANDLERS
1052 * **************************************************************************** */
1055 * This method is the general ready state stop handler for the struct scic_sds_port
1056 * object. This function will transition the ready substate machine to its
1057 * final state. enum sci_status SCI_SUCCESS
1059 static enum sci_status scic_sds_port_ready_substate_stop_handler(
1060 struct scic_sds_port *port)
1062 sci_base_state_machine_change_state(
1063 &port->state_machine,
1064 SCI_BASE_PORT_STATE_STOPPING
1071 * This method is the general ready substate complete io handler for the
1072 * struct scic_sds_port object. This function decrments the outstanding request count
1073 * for this port object. enum sci_status SCI_SUCCESS
1075 static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
1076 struct scic_sds_port *port,
1077 struct scic_sds_remote_device *device,
1078 struct scic_sds_request *io_request)
1080 scic_sds_port_decrement_request_count(port);
1085 static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
1086 struct scic_sds_port *port,
1087 struct scic_sds_phy *phy)
1089 enum sci_status status;
1091 status = scic_sds_port_set_phy(port, phy);
1093 if (status == SCI_SUCCESS) {
1094 scic_sds_port_general_link_up_handler(port, phy, true);
1096 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1098 sci_base_state_machine_change_state(
1099 &port->ready_substate_machine,
1100 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1108 static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
1109 struct scic_sds_port *port,
1110 struct scic_sds_phy *phy)
1112 enum sci_status status;
1114 status = scic_sds_port_clear_phy(port, phy);
1116 if (status == SCI_SUCCESS) {
1117 scic_sds_port_deactivate_phy(port, phy, true);
1119 port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
1121 sci_base_state_machine_change_state(
1122 &port->ready_substate_machine,
1123 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1131 * ****************************************************************************
1132 * * READY SUBSTATE WAITING HANDLERS
1133 * **************************************************************************** */
1137 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1139 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1141 * This method is the ready waiting substate link up handler for the
1142 * struct scic_sds_port object. This methos will report the link up condition for
1143 * this port and will transition to the ready operational substate. none
1145 static void scic_sds_port_ready_waiting_substate_link_up_handler(
1146 struct scic_sds_port *sci_port,
1147 struct scic_sds_phy *sci_phy)
1150 * Since this is the first phy going link up for the port we can just enable
1151 * it and continue. */
1152 scic_sds_port_activate_phy(sci_port, sci_phy, true);
1154 sci_base_state_machine_change_state(
1155 &sci_port->ready_substate_machine,
1156 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1161 * This method is the ready waiting substate start io handler for the
1162 * struct scic_sds_port object. The port object can not accept new requests so the
1163 * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
1165 static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
1166 struct scic_sds_port *port,
1167 struct scic_sds_remote_device *device,
1168 struct scic_sds_request *io_request)
1170 return SCI_FAILURE_INVALID_STATE;
1174 * ****************************************************************************
1175 * * READY SUBSTATE OPERATIONAL HANDLERS
1176 * **************************************************************************** */
1179 * This method will casue the port to reset. enum sci_status SCI_SUCCESS
1182 sci_status scic_sds_port_ready_operational_substate_reset_handler(
1183 struct scic_sds_port *port,
1186 enum sci_status status = SCI_FAILURE_INVALID_PHY;
1188 struct scic_sds_phy *selected_phy = NULL;
1191 /* Select a phy on which we can send the hard reset request. */
1193 (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
1195 selected_phy = port->phy_table[phy_index];
1197 if ((selected_phy != NULL) &&
1198 !scic_sds_port_active_phy(port, selected_phy)) {
1200 * We found a phy but it is not ready select
1203 selected_phy = NULL;
1207 /* If we have a phy then go ahead and start the reset procedure */
1208 if (selected_phy != NULL) {
1209 status = scic_sds_phy_reset(selected_phy);
1211 if (status == SCI_SUCCESS) {
1212 isci_timer_start(port->timer_handle, timeout);
1213 port->not_ready_reason =
1214 SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
1216 sci_base_state_machine_change_state(
1217 &port->state_machine,
1218 SCI_BASE_PORT_STATE_RESETTING);
1226 * scic_sds_port_ready_operational_substate_link_up_handler() -
1227 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1229 * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
1231 * This method is the ready operational substate link up handler for the
1232 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1233 * gone link up. none
1235 static void scic_sds_port_ready_operational_substate_link_up_handler(
1236 struct scic_sds_port *sci_port,
1237 struct scic_sds_phy *sci_phy)
1239 scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
1243 * scic_sds_port_ready_operational_substate_link_down_handler() -
1244 * @sci_port: This is the struct scic_sds_port object that which has a phy that has
1246 * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
1248 * This method is the ready operational substate link down handler for the
1249 * struct scic_sds_port object. This function notifies the SCI User that the phy has
1250 * gone link down and if this is the last phy in the port the port will change
1251 * state to the ready waiting substate. none
1253 static void scic_sds_port_ready_operational_substate_link_down_handler(
1254 struct scic_sds_port *sci_port,
1255 struct scic_sds_phy *sci_phy)
1257 scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
1260 * If there are no active phys left in the port, then transition
1261 * the port to the WAITING state until such time as a phy goes
1263 if (sci_port->active_phy_mask == 0)
1264 sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
1265 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1269 * This method is the ready operational substate start io handler for the
1270 * struct scic_sds_port object. This function incremetns the outstanding request
1271 * count for this port object. enum sci_status SCI_SUCCESS
1273 static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
1274 struct scic_sds_port *port,
1275 struct scic_sds_remote_device *device,
1276 struct scic_sds_request *io_request)
1278 scic_sds_port_increment_request_count(port);
1284 * ****************************************************************************
1285 * * READY SUBSTATE OPERATIONAL HANDLERS
1286 * **************************************************************************** */
1289 * This is the default method for a port add phy request. It will report a
1290 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1292 static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
1293 struct scic_sds_port *port,
1294 struct scic_sds_phy *phy)
1296 enum sci_status status;
1298 status = scic_sds_port_set_phy(port, phy);
1300 if (status == SCI_SUCCESS) {
1301 scic_sds_port_general_link_up_handler(port, phy, true);
1304 * Re-enter the configuring state since this may be the last phy in
1306 sci_base_state_machine_change_state(
1307 &port->ready_substate_machine,
1308 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1316 * This is the default method for a port remove phy request. It will report a
1317 * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
1319 static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
1320 struct scic_sds_port *port,
1321 struct scic_sds_phy *phy)
1323 enum sci_status status;
1325 status = scic_sds_port_clear_phy(port, phy);
1327 if (status == SCI_SUCCESS) {
1328 scic_sds_port_deactivate_phy(port, phy, true);
1331 * Re-enter the configuring state since this may be the last phy in
1333 sci_base_state_machine_change_state(
1334 &port->ready_substate_machine,
1335 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
1343 * scic_sds_port_ready_configuring_substate_complete_io_handler() -
1344 * @port: This is the port that is being requested to complete the io request.
1345 * @device: This is the device on which the io is completing.
1347 * This method will decrement the outstanding request count for this port. If
1348 * the request count goes to 0 then the port can be reprogrammed with its new
1351 static enum sci_status
1352 scic_sds_port_ready_configuring_substate_complete_io_handler(
1353 struct scic_sds_port *port,
1354 struct scic_sds_remote_device *device,
1355 struct scic_sds_request *io_request)
1357 scic_sds_port_decrement_request_count(port);
1359 if (port->started_request_count == 0) {
1360 sci_base_state_machine_change_state(
1361 &port->ready_substate_machine,
1362 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1369 static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
1372 dev_warn(sciport_to_dev(sci_port),
1373 "%s: in wrong state: %d\n", func,
1374 sci_base_state_machine_get_state(&sci_port->state_machine));
1375 return SCI_FAILURE_INVALID_STATE;
1378 static enum sci_status
1379 scic_sds_port_default_start_handler(struct scic_sds_port *sci_port)
1381 return default_port_handler(sci_port, __func__);
1384 static enum sci_status
1385 scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port)
1387 return default_port_handler(sci_port, __func__);
1390 static enum sci_status
1391 scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port)
1393 return default_port_handler(sci_port, __func__);
1396 static enum sci_status
1397 scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port,
1400 return default_port_handler(sci_port, __func__);
1403 static enum sci_status
1404 scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port,
1405 struct scic_sds_phy *base_phy)
1407 return default_port_handler(sci_port, __func__);
1410 static enum sci_status
1411 scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port,
1412 struct scic_sds_phy *base_phy)
1414 return default_port_handler(sci_port, __func__);
1418 * This is the default method for a port unsolicited frame request. It will
1419 * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
1420 * possible to receive an unsolicited frame directed to a port object? It
1421 * seems possible if we implementing virtual functions but until then?
1423 static enum sci_status
1424 scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
1427 struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
1429 default_port_handler(sci_port, __func__);
1430 scic_sds_controller_release_frame(scic, frame_index);
1432 return SCI_FAILURE_INVALID_STATE;
1435 static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
1438 return default_port_handler(sci_port, __func__);
1441 static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
1442 struct scic_sds_phy *sci_phy)
1444 default_port_handler(sci_port, __func__);
1447 static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
1448 struct scic_sds_phy *sci_phy)
1450 default_port_handler(sci_port, __func__);
1453 static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
1454 struct scic_sds_remote_device *sci_dev,
1455 struct scic_sds_request *sci_req)
1457 return default_port_handler(sci_port, __func__);
1460 static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
1461 struct scic_sds_remote_device *sci_dev,
1462 struct scic_sds_request *sci_req)
1464 return default_port_handler(sci_port, __func__);
1469 static struct scic_sds_port_state_handler
1470 scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] = {
1472 /* SCIC_SDS_PORT_READY_SUBSTATE_WAITING */
1473 scic_sds_port_default_start_handler,
1474 scic_sds_port_ready_substate_stop_handler,
1475 scic_sds_port_default_destruct_handler,
1476 scic_sds_port_default_reset_handler,
1477 scic_sds_port_ready_substate_add_phy_handler,
1478 scic_sds_port_default_remove_phy_handler,
1479 scic_sds_port_default_frame_handler,
1480 scic_sds_port_default_event_handler,
1481 scic_sds_port_ready_waiting_substate_link_up_handler,
1482 scic_sds_port_default_link_down_handler,
1483 scic_sds_port_ready_waiting_substate_start_io_handler,
1484 scic_sds_port_ready_substate_complete_io_handler,
1488 /* SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL */
1489 scic_sds_port_default_start_handler,
1490 scic_sds_port_ready_substate_stop_handler,
1491 scic_sds_port_default_destruct_handler,
1492 scic_sds_port_ready_operational_substate_reset_handler,
1493 scic_sds_port_ready_substate_add_phy_handler,
1494 scic_sds_port_ready_substate_remove_phy_handler,
1495 scic_sds_port_default_frame_handler,
1496 scic_sds_port_default_event_handler,
1497 scic_sds_port_ready_operational_substate_link_up_handler,
1498 scic_sds_port_ready_operational_substate_link_down_handler,
1499 scic_sds_port_ready_operational_substate_start_io_handler,
1500 scic_sds_port_ready_substate_complete_io_handler,
1504 /* SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING */
1505 scic_sds_port_default_start_handler,
1506 scic_sds_port_ready_substate_stop_handler,
1507 scic_sds_port_default_destruct_handler,
1508 scic_sds_port_default_reset_handler,
1509 scic_sds_port_ready_configuring_substate_add_phy_handler,
1510 scic_sds_port_ready_configuring_substate_remove_phy_handler,
1511 scic_sds_port_default_frame_handler,
1512 scic_sds_port_default_event_handler,
1513 scic_sds_port_default_link_up_handler,
1514 scic_sds_port_default_link_down_handler,
1515 scic_sds_port_default_start_io_handler,
1516 scic_sds_port_ready_configuring_substate_complete_io_handler
1521 * scic_sds_port_set_ready_state_handlers() -
1523 * This macro sets the port ready substate handlers.
1525 #define scic_sds_port_set_ready_state_handlers(port, state_id) \
1526 scic_sds_port_set_state_handlers(\
1527 port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
1531 * ******************************************************************************
1532 * * PORT STATE PRIVATE METHODS
1533 * ****************************************************************************** */
1537 * @sci_port: This is the struct scic_sds_port object to suspend.
1539 * This method will susped the port task scheduler for this port object. none
1542 scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
1544 u32 pts_control_value;
1546 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1547 pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
1548 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1552 * scic_sds_port_post_dummy_request() - post dummy/workaround request
1553 * @sci_port: port to post task
1555 * Prevent the hardware scheduler from posting new requests to the front
1556 * of the scheduler queue causing a starvation problem for currently
1560 static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
1563 struct scu_task_context *task_context;
1564 struct scic_sds_controller *scic = sci_port->owning_controller;
1565 u16 tci = sci_port->reserved_tci;
1567 task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
1569 task_context->abort = 0;
1571 command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
1572 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1575 scic_sds_controller_post_request(scic, command);
1579 * This routine will abort the dummy request. This will alow the hardware to
1580 * power down parts of the silicon to save power.
1582 * @sci_port: The port on which the task must be aborted.
1585 static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
1587 struct scic_sds_controller *scic = sci_port->owning_controller;
1588 u16 tci = sci_port->reserved_tci;
1589 struct scu_task_context *tc;
1592 tc = scic_sds_controller_get_task_context_buffer(scic, tci);
1596 command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
1597 sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
1600 scic_sds_controller_post_request(scic, command);
1605 * @sci_port: This is the struct scic_sds_port object to resume.
1607 * This method will resume the port task scheduler for this port object. none
1610 scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
1612 u32 pts_control_value;
1614 pts_control_value = readl(&port->port_task_scheduler_registers->control);
1615 pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
1616 writel(pts_control_value, &port->port_task_scheduler_registers->control);
1620 * ******************************************************************************
1621 * * PORT READY SUBSTATE METHODS
1622 * ****************************************************************************** */
1626 * @object: This is the object which is cast to a struct scic_sds_port object.
1628 * This method will perform the actions required by the struct scic_sds_port on
1629 * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
1630 * port for any ready phys. If there is at least one phy in a ready state then
1631 * the port transitions to the ready operational substate. none
1633 static void scic_sds_port_ready_substate_waiting_enter(void *object)
1635 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1637 scic_sds_port_set_ready_state_handlers(
1638 sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
1641 scic_sds_port_suspend_port_task_scheduler(sci_port);
1643 sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
1645 if (sci_port->active_phy_mask != 0) {
1646 /* At least one of the phys on the port is ready */
1647 sci_base_state_machine_change_state(
1648 &sci_port->ready_substate_machine,
1649 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
1656 * @object: This is the object which is cast to a struct scic_sds_port object.
1658 * This function will perform the actions required by the struct scic_sds_port
1659 * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
1660 * the state handlers for the port object, notifies the SCI User that the port
1661 * is ready, and resumes port operations. none
1663 static void scic_sds_port_ready_substate_operational_enter(void *object)
1666 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1667 struct scic_sds_controller *scic =
1668 scic_sds_port_get_controller(sci_port);
1669 struct isci_host *ihost = scic->ihost;
1670 struct isci_port *iport = sci_object_get_association(sci_port);
1672 scic_sds_port_set_ready_state_handlers(
1674 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1676 isci_port_ready(ihost, iport);
1678 for (index = 0; index < SCI_MAX_PHYS; index++) {
1679 if (sci_port->phy_table[index]) {
1680 writel(sci_port->physical_port_index,
1681 &sci_port->port_pe_configuration_register[
1682 sci_port->phy_table[index]->phy_index]);
1686 scic_sds_port_update_viit_entry(sci_port);
1688 scic_sds_port_resume_port_task_scheduler(sci_port);
1691 * Post the dummy task for the port so the hardware can schedule
1694 scic_sds_port_post_dummy_request(sci_port);
1699 * @object: This is the object which is cast to a struct scic_sds_port object.
1701 * This method will perform the actions required by the struct scic_sds_port on
1702 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1703 * the port not ready and suspends the port task scheduler. none
1705 static void scic_sds_port_ready_substate_operational_exit(void *object)
1707 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1708 struct scic_sds_controller *scic =
1709 scic_sds_port_get_controller(sci_port);
1710 struct isci_host *ihost = scic->ihost;
1711 struct isci_port *iport = sci_object_get_association(sci_port);
1714 * Kill the dummy task for this port if it has not yet posted
1715 * the hardware will treat this as a NOP and just return abort
1718 scic_sds_port_abort_dummy_request(sci_port);
1720 isci_port_not_ready(ihost, iport);
1724 * ******************************************************************************
1725 * * PORT READY CONFIGURING METHODS
1726 * ****************************************************************************** */
1729 * scic_sds_port_ready_substate_configuring_enter() -
1730 * @object: This is the object which is cast to a struct scic_sds_port object.
1732 * This method will perform the actions required by the struct scic_sds_port on
1733 * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
1734 * the port not ready and suspends the port task scheduler. none
1736 static void scic_sds_port_ready_substate_configuring_enter(void *object)
1738 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1739 struct scic_sds_controller *scic =
1740 scic_sds_port_get_controller(sci_port);
1741 struct isci_host *ihost = scic->ihost;
1742 struct isci_port *iport = sci_object_get_association(sci_port);
1744 scic_sds_port_set_ready_state_handlers(
1746 SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
1748 if (sci_port->active_phy_mask == 0) {
1749 isci_port_not_ready(ihost, iport);
1751 sci_base_state_machine_change_state(
1752 &sci_port->ready_substate_machine,
1753 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
1754 } else if (sci_port->started_request_count == 0)
1755 sci_base_state_machine_change_state(
1756 &sci_port->ready_substate_machine,
1757 SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
1760 static void scic_sds_port_ready_substate_configuring_exit(void *object)
1762 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
1764 scic_sds_port_suspend_port_task_scheduler(sci_port);
1767 /* --------------------------------------------------------------------------- */
1769 static const struct sci_base_state scic_sds_port_ready_substate_table[] = {
1770 [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
1771 .enter_state = scic_sds_port_ready_substate_waiting_enter,
1773 [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
1774 .enter_state = scic_sds_port_ready_substate_operational_enter,
1775 .exit_state = scic_sds_port_ready_substate_operational_exit
1777 [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
1778 .enter_state = scic_sds_port_ready_substate_configuring_enter,
1779 .exit_state = scic_sds_port_ready_substate_configuring_exit
1785 * @port: This is the struct scic_sds_port object on which the io request count will
1787 * @device: This is the struct scic_sds_remote_device object to which the io request
1788 * is being directed. This parameter is not required to complete this
1790 * @io_request: This is the request that is being completed on this port
1791 * object. This parameter is not required to complete this operation.
1793 * This is a general complete io request handler for the struct scic_sds_port object.
1794 * enum sci_status SCI_SUCCESS
1796 static enum sci_status scic_sds_port_general_complete_io_handler(
1797 struct scic_sds_port *port,
1798 struct scic_sds_remote_device *device,
1799 struct scic_sds_request *io_request)
1801 scic_sds_port_decrement_request_count(port);
1807 * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
1809 * @port: This is the struct scic_sds_port object which is cast into a
1810 * struct scic_sds_port object.
1812 * This function takes the struct scic_sds_port from a stopped state and
1813 * attempts to start it. To start a port it must have no assiged devices and
1814 * it must have at least one phy assigned to it. If those conditions are
1815 * met then the port can transition to the ready state.
1817 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
1818 * This struct scic_sds_port object could not be started because the port
1819 * configuration is not valid.
1821 * the start request is successful and the struct scic_sds_port object
1822 * has transitioned to the SCI_BASE_PORT_STATE_READY.
1824 static enum sci_status
1825 scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port)
1827 struct scic_sds_controller *scic = sci_port->owning_controller;
1828 struct isci_host *ihost = scic->ihost;
1829 enum sci_status status = SCI_SUCCESS;
1832 if (sci_port->assigned_device_count > 0) {
1834 * @todo This is a start failure operation because
1835 * there are still devices assigned to this port.
1836 * There must be no devices assigned to a port on a
1839 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1842 sci_port->timer_handle =
1843 isci_timer_create(ihost,
1845 scic_sds_port_timeout_handler);
1847 if (!sci_port->timer_handle)
1848 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1850 if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
1851 u16 rni = scic_sds_remote_node_table_allocate_remote_node(
1852 &scic->available_remote_nodes, 1);
1854 if (rni != SCU_DUMMY_INDEX)
1855 scic_sds_port_construct_dummy_rnc(sci_port, rni);
1857 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1858 sci_port->reserved_rni = rni;
1861 if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
1862 /* Allocate a TCI and remove the sequence nibble */
1863 u16 tci = scic_controller_allocate_io_tag(scic);
1865 if (tci != SCU_DUMMY_INDEX)
1866 scic_sds_port_construct_dummy_task(sci_port, tci);
1868 status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
1869 sci_port->reserved_tci = tci;
1872 if (status == SCI_SUCCESS) {
1873 phy_mask = scic_sds_port_get_phys(sci_port);
1876 * There are one or more phys assigned to this port. Make sure
1877 * the port's phy mask is in fact legal and supported by the
1880 if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
1881 sci_base_state_machine_change_state(
1882 &sci_port->state_machine,
1883 SCI_BASE_PORT_STATE_READY);
1887 status = SCI_FAILURE;
1890 if (status != SCI_SUCCESS)
1891 scic_sds_port_destroy_dummy_resources(sci_port);
1897 * This method takes the struct scic_sds_port that is in a stopped state and handles a
1898 * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
1899 * stop request is successful as the struct scic_sds_port object is already stopped.
1901 static enum sci_status scic_sds_port_stopped_state_stop_handler(
1902 struct scic_sds_port *port)
1904 /* We are already stopped so there is nothing to do here */
1909 * This method takes the struct scic_sds_port that is in a stopped state and handles
1910 * the destruct request. The stopped state is the only state in which the
1911 * struct scic_sds_port can be destroyed. This function causes the port object to
1912 * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
1914 static enum sci_status scic_sds_port_stopped_state_destruct_handler(
1915 struct scic_sds_port *port)
1917 sci_base_state_machine_stop(&port->state_machine);
1923 * This method takes the struct scic_sds_port that is in a stopped state and handles
1924 * the add phy request. In MPC mode the only time a phy can be added to a port
1925 * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1926 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1927 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1929 static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
1930 struct scic_sds_port *port,
1931 struct scic_sds_phy *phy)
1933 struct sci_sas_address port_sas_address;
1935 /* Read the port assigned SAS Address if there is one */
1936 scic_sds_port_get_sas_address(port, &port_sas_address);
1938 if (port_sas_address.high != 0 && port_sas_address.low != 0) {
1939 struct sci_sas_address phy_sas_address;
1942 * Make sure that the PHY SAS Address matches the SAS Address
1944 scic_sds_phy_get_sas_address(phy, &phy_sas_address);
1947 (port_sas_address.high != phy_sas_address.high)
1948 || (port_sas_address.low != phy_sas_address.low)
1950 return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
1954 return scic_sds_port_set_phy(port, phy);
1958 * This method takes the struct scic_sds_port that is in a stopped state and handles
1959 * the remove phy request. In MPC mode the only time a phy can be removed from
1960 * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
1961 * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
1962 * be added to the port. SCI_SUCCESS if the phy is added to the port.
1964 static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
1965 struct scic_sds_port *port,
1966 struct scic_sds_phy *phy)
1968 return scic_sds_port_clear_phy(port, phy);
1972 * ****************************************************************************
1973 * * READY STATE HANDLERS
1974 * **************************************************************************** */
1977 * ****************************************************************************
1978 * * RESETTING STATE HANDLERS
1979 * **************************************************************************** */
1982 * ****************************************************************************
1983 * * STOPPING STATE HANDLERS
1984 * **************************************************************************** */
1987 * This method takes the struct scic_sds_port that is in a stopping state and handles
1988 * the complete io request. Should the request count reach 0 then the port
1989 * object will transition to the stopped state. enum sci_status SCI_SUCCESS
1991 static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
1992 struct scic_sds_port *sci_port,
1993 struct scic_sds_remote_device *device,
1994 struct scic_sds_request *io_request)
1996 scic_sds_port_decrement_request_count(sci_port);
1998 if (sci_port->started_request_count == 0) {
1999 sci_base_state_machine_change_state(&sci_port->state_machine,
2000 SCI_BASE_PORT_STATE_STOPPED);
2007 * ****************************************************************************
2008 * * RESETTING STATE HANDLERS
2009 * **************************************************************************** */
2013 * @port: This is the port object which is being requested to stop.
2015 * This method will stop a failed port. This causes a transition to the
2016 * stopping state. enum sci_status SCI_SUCCESS
2018 static enum sci_status scic_sds_port_reset_state_stop_handler(
2019 struct scic_sds_port *port)
2021 sci_base_state_machine_change_state(
2022 &port->state_machine,
2023 SCI_BASE_PORT_STATE_STOPPING
2030 * This method will transition a failed port to its ready state. The port
2031 * failed because a hard reset request timed out but at some time later one or
2032 * more phys in the port became ready. enum sci_status SCI_SUCCESS
2034 static void scic_sds_port_reset_state_link_up_handler(
2035 struct scic_sds_port *port,
2036 struct scic_sds_phy *phy)
2039 * / @todo We should make sure that the phy that has gone link up is the same
2040 * / one on which we sent the reset. It is possible that the phy on
2041 * / which we sent the reset is not the one that has gone link up and we
2042 * / want to make sure that phy being reset comes back. Consider the
2043 * / case where a reset is sent but before the hardware processes the
2044 * / reset it get a link up on the port because of a hot plug event.
2045 * / because of the reset request this phy will go link down almost
2049 * In the resetting state we don't notify the user regarding
2050 * link up and link down notifications. */
2051 scic_sds_port_general_link_up_handler(port, phy, false);
2055 * This method process link down notifications that occur during a port reset
2056 * operation. Link downs can occur during the reset operation. enum sci_status
2059 static void scic_sds_port_reset_state_link_down_handler(
2060 struct scic_sds_port *port,
2061 struct scic_sds_phy *phy)
2064 * In the resetting state we don't notify the user regarding
2065 * link up and link down notifications. */
2066 scic_sds_port_deactivate_phy(port, phy, false);
2069 static struct scic_sds_port_state_handler
2070 scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] =
2072 /* SCI_BASE_PORT_STATE_STOPPED */
2074 scic_sds_port_stopped_state_start_handler,
2075 scic_sds_port_stopped_state_stop_handler,
2076 scic_sds_port_stopped_state_destruct_handler,
2077 scic_sds_port_default_reset_handler,
2078 scic_sds_port_stopped_state_add_phy_handler,
2079 scic_sds_port_stopped_state_remove_phy_handler,
2080 scic_sds_port_default_frame_handler,
2081 scic_sds_port_default_event_handler,
2082 scic_sds_port_default_link_up_handler,
2083 scic_sds_port_default_link_down_handler,
2084 scic_sds_port_default_start_io_handler,
2085 scic_sds_port_default_complete_io_handler
2087 /* SCI_BASE_PORT_STATE_STOPPING */
2089 scic_sds_port_default_start_handler,
2090 scic_sds_port_default_stop_handler,
2091 scic_sds_port_default_destruct_handler,
2092 scic_sds_port_default_reset_handler,
2093 scic_sds_port_default_add_phy_handler,
2094 scic_sds_port_default_remove_phy_handler,
2095 scic_sds_port_default_frame_handler,
2096 scic_sds_port_default_event_handler,
2097 scic_sds_port_default_link_up_handler,
2098 scic_sds_port_default_link_down_handler,
2099 scic_sds_port_default_start_io_handler,
2100 scic_sds_port_stopping_state_complete_io_handler
2102 /* SCI_BASE_PORT_STATE_READY */
2104 scic_sds_port_default_start_handler,
2105 scic_sds_port_default_stop_handler,
2106 scic_sds_port_default_destruct_handler,
2107 scic_sds_port_default_reset_handler,
2108 scic_sds_port_default_add_phy_handler,
2109 scic_sds_port_default_remove_phy_handler,
2110 scic_sds_port_default_frame_handler,
2111 scic_sds_port_default_event_handler,
2112 scic_sds_port_default_link_up_handler,
2113 scic_sds_port_default_link_down_handler,
2114 scic_sds_port_default_start_io_handler,
2115 scic_sds_port_general_complete_io_handler
2117 /* SCI_BASE_PORT_STATE_RESETTING */
2119 scic_sds_port_default_start_handler,
2120 scic_sds_port_reset_state_stop_handler,
2121 scic_sds_port_default_destruct_handler,
2122 scic_sds_port_default_reset_handler,
2123 scic_sds_port_default_add_phy_handler,
2124 scic_sds_port_default_remove_phy_handler,
2125 scic_sds_port_default_frame_handler,
2126 scic_sds_port_default_event_handler,
2127 scic_sds_port_reset_state_link_up_handler,
2128 scic_sds_port_reset_state_link_down_handler,
2129 scic_sds_port_default_start_io_handler,
2130 scic_sds_port_general_complete_io_handler
2132 /* SCI_BASE_PORT_STATE_FAILED */
2134 scic_sds_port_default_start_handler,
2135 scic_sds_port_default_stop_handler,
2136 scic_sds_port_default_destruct_handler,
2137 scic_sds_port_default_reset_handler,
2138 scic_sds_port_default_add_phy_handler,
2139 scic_sds_port_default_remove_phy_handler,
2140 scic_sds_port_default_frame_handler,
2141 scic_sds_port_default_event_handler,
2142 scic_sds_port_default_link_up_handler,
2143 scic_sds_port_default_link_down_handler,
2144 scic_sds_port_default_start_io_handler,
2145 scic_sds_port_general_complete_io_handler
2150 * ******************************************************************************
2151 * * PORT STATE PRIVATE METHODS
2152 * ****************************************************************************** */
2156 * @sci_port: This is the port object which to suspend.
2158 * This method will enable the SCU Port Task Scheduler for this port object but
2159 * will leave the port task scheduler in a suspended state. none
2162 scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
2164 u32 pts_control_value;
2166 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2167 pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
2168 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2173 * @sci_port: This is the port object which to resume.
2175 * This method will disable the SCU port task scheduler for this port object.
2179 scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
2181 u32 pts_control_value;
2183 pts_control_value = readl(&port->port_task_scheduler_registers->control);
2184 pts_control_value &=
2185 ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
2186 writel(pts_control_value, &port->port_task_scheduler_registers->control);
2189 static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
2191 struct scic_sds_controller *scic = sci_port->owning_controller;
2192 u8 phys_index = sci_port->physical_port_index;
2193 union scu_remote_node_context *rnc;
2194 u16 rni = sci_port->reserved_rni;
2197 rnc = &scic->remote_node_context_table[rni];
2198 rnc->ssp.is_valid = true;
2200 command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
2201 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2203 scic_sds_controller_post_request(scic, command);
2205 /* ensure hardware has seen the post rnc command and give it
2206 * ample time to act before sending the suspend
2208 readl(&scic->smu_registers->interrupt_status); /* flush */
2211 command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
2212 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2214 scic_sds_controller_post_request(scic, command);
2217 static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
2219 struct scic_sds_controller *scic = sci_port->owning_controller;
2220 u8 phys_index = sci_port->physical_port_index;
2221 union scu_remote_node_context *rnc;
2222 u16 rni = sci_port->reserved_rni;
2225 rnc = &scic->remote_node_context_table[rni];
2227 rnc->ssp.is_valid = false;
2229 /* ensure the preceding tc abort request has reached the
2230 * controller and give it ample time to act before posting the rnc
2233 readl(&scic->smu_registers->interrupt_status); /* flush */
2236 command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
2237 phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
2239 scic_sds_controller_post_request(scic, command);
2243 * ******************************************************************************
2244 * * PORT STATE METHODS
2245 * ****************************************************************************** */
2249 * @object: This is the object which is cast to a struct scic_sds_port object.
2251 * This method will perform the actions required by the struct scic_sds_port on
2252 * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
2253 * state handlers for the struct scic_sds_port object and disables the port task
2254 * scheduler in the hardware. none
2256 static void scic_sds_port_stopped_state_enter(void *object)
2258 struct scic_sds_port *sci_port;
2260 sci_port = (struct scic_sds_port *)object;
2262 scic_sds_port_set_base_state_handlers(
2263 sci_port, SCI_BASE_PORT_STATE_STOPPED
2267 SCI_BASE_PORT_STATE_STOPPING
2268 == sci_port->state_machine.previous_state_id
2271 * If we enter this state becasuse of a request to stop
2272 * the port then we want to disable the hardwares port
2273 * task scheduler. */
2274 scic_sds_port_disable_port_task_scheduler(sci_port);
2280 * @object: This is the object which is cast to a struct scic_sds_port object.
2282 * This method will perform the actions required by the struct scic_sds_port on
2283 * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
2284 * port task scheduler. none
2286 static void scic_sds_port_stopped_state_exit(void *object)
2288 struct scic_sds_port *sci_port;
2290 sci_port = (struct scic_sds_port *)object;
2292 /* Enable and suspend the port task scheduler */
2293 scic_sds_port_enable_port_task_scheduler(sci_port);
2297 * scic_sds_port_ready_state_enter -
2298 * @object: This is the object which is cast to a struct scic_sds_port object.
2300 * This method will perform the actions required by the struct scic_sds_port on
2301 * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
2302 * handlers for the struct scic_sds_port object, reports the port object as
2303 * not ready and starts the ready substate machine. none
2305 static void scic_sds_port_ready_state_enter(void *object)
2307 struct scic_sds_controller *scic;
2308 struct scic_sds_port *sci_port;
2309 struct isci_port *iport;
2310 struct isci_host *ihost;
2313 sci_port = container_of(object, typeof(*sci_port), parent);
2314 scic = scic_sds_port_get_controller(sci_port);
2315 ihost = scic->ihost;
2316 iport = sci_object_get_association(sci_port);
2318 /* Put the ready state handlers in place though they will not be there long */
2319 scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
2321 prev_state = sci_port->state_machine.previous_state_id;
2322 if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
2323 isci_port_hard_reset_complete(iport, SCI_SUCCESS);
2325 isci_port_not_ready(ihost, iport);
2327 /* Post and suspend the dummy remote node context for this port. */
2328 scic_sds_port_post_dummy_remote_node(sci_port);
2330 /* Start the ready substate machine */
2331 sci_base_state_machine_start(&sci_port->ready_substate_machine);
2334 static void scic_sds_port_ready_state_exit(void *object)
2336 struct scic_sds_port *sci_port;
2338 sci_port = container_of(object, typeof(*sci_port), parent);
2339 sci_base_state_machine_stop(&sci_port->ready_substate_machine);
2340 scic_sds_port_invalidate_dummy_remote_node(sci_port);
2345 * @object: This is the object which is cast to a struct scic_sds_port object.
2347 * This method will perform the actions required by the struct scic_sds_port on
2348 * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
2349 * state handlers for the struct scic_sds_port object. none
2351 static void scic_sds_port_resetting_state_enter(void *object)
2353 struct scic_sds_port *sci_port;
2355 sci_port = (struct scic_sds_port *)object;
2357 scic_sds_port_set_base_state_handlers(
2358 sci_port, SCI_BASE_PORT_STATE_RESETTING
2364 * @object: This is the object which is cast to a struct scic_sds_port object.
2366 * This function will perform the actions required by the
2367 * struct scic_sds_port on
2368 * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
2370 static inline void scic_sds_port_resetting_state_exit(void *object)
2372 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2374 isci_timer_stop(sci_port->timer_handle);
2379 * @object: This is the void object which is cast to a
2380 * struct scic_sds_port object.
2382 * This method will perform the actions required by the struct scic_sds_port on
2383 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2384 * state handlers for the struct scic_sds_port object. none
2386 static void scic_sds_port_stopping_state_enter(void *object)
2388 struct scic_sds_port *sci_port;
2390 sci_port = (struct scic_sds_port *)object;
2392 scic_sds_port_set_base_state_handlers(
2393 sci_port, SCI_BASE_PORT_STATE_STOPPING
2399 * @object: This is the object which is cast to a struct scic_sds_port object.
2401 * This function will perform the actions required by the
2402 * struct scic_sds_port on
2403 * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
2406 scic_sds_port_stopping_state_exit(void *object)
2408 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2410 isci_timer_stop(sci_port->timer_handle);
2412 scic_sds_port_destroy_dummy_resources(sci_port);
2417 * @object: This is the object which is cast to a struct scic_sds_port object.
2419 * This function will perform the actions required by the
2420 * struct scic_sds_port on
2421 * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
2422 * state handlers for the struct scic_sds_port object. none
2424 static void scic_sds_port_failed_state_enter(void *object)
2426 struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
2427 struct isci_port *iport = sci_object_get_association(sci_port);
2429 scic_sds_port_set_base_state_handlers(sci_port,
2430 SCI_BASE_PORT_STATE_FAILED);
2432 isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
2435 /* --------------------------------------------------------------------------- */
2437 static const struct sci_base_state scic_sds_port_state_table[] = {
2438 [SCI_BASE_PORT_STATE_STOPPED] = {
2439 .enter_state = scic_sds_port_stopped_state_enter,
2440 .exit_state = scic_sds_port_stopped_state_exit
2442 [SCI_BASE_PORT_STATE_STOPPING] = {
2443 .enter_state = scic_sds_port_stopping_state_enter,
2444 .exit_state = scic_sds_port_stopping_state_exit
2446 [SCI_BASE_PORT_STATE_READY] = {
2447 .enter_state = scic_sds_port_ready_state_enter,
2448 .exit_state = scic_sds_port_ready_state_exit
2450 [SCI_BASE_PORT_STATE_RESETTING] = {
2451 .enter_state = scic_sds_port_resetting_state_enter,
2452 .exit_state = scic_sds_port_resetting_state_exit
2454 [SCI_BASE_PORT_STATE_FAILED] = {
2455 .enter_state = scic_sds_port_failed_state_enter,
2459 void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 port_index,
2460 struct scic_sds_controller *scic)
2464 sci_port->parent.private = NULL;
2465 sci_base_state_machine_construct(&sci_port->state_machine,
2467 scic_sds_port_state_table,
2468 SCI_BASE_PORT_STATE_STOPPED);
2470 sci_base_state_machine_start(&sci_port->state_machine);
2472 sci_base_state_machine_construct(&sci_port->ready_substate_machine,
2474 scic_sds_port_ready_substate_table,
2475 SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
2477 sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
2478 sci_port->physical_port_index = port_index;
2479 sci_port->active_phy_mask = 0;
2481 sci_port->owning_controller = scic;
2483 sci_port->started_request_count = 0;
2484 sci_port->assigned_device_count = 0;
2486 sci_port->reserved_rni = SCU_DUMMY_INDEX;
2487 sci_port->reserved_tci = SCU_DUMMY_INDEX;
2489 sci_port->timer_handle = NULL;
2491 sci_port->port_task_scheduler_registers = NULL;
2493 for (index = 0; index < SCI_MAX_PHYS; index++)
2494 sci_port->phy_table[index] = NULL;