#include <sys/cdefs.h>
#include <dev/isci/scil/scic_phy.h>
#include <dev/isci/scil/scic_port.h>
#include <dev/isci/scil/scic_controller.h>
#include <dev/isci/scil/scic_user_callback.h>
#include <dev/isci/scil/scic_sds_controller.h>
#include <dev/isci/scil/scic_sds_port.h>
#include <dev/isci/scil/scic_sds_phy.h>
#include <dev/isci/scil/scic_sds_remote_device.h>
#include <dev/isci/scil/scic_sds_request.h>
#include <dev/isci/scil/scic_sds_port_registers.h>
#include <dev/isci/scil/scic_sds_logger.h>
#include <dev/isci/scil/scic_sds_phy_registers.h>
#include <dev/isci/scil/intel_sas.h>
#include <dev/isci/scil/scic_sds_remote_node_context.h>
#include <dev/isci/scil/sci_util.h>
#define SCIC_SDS_PORT_MIN_TIMER_COUNT (SCI_MAX_PORTS)
#define SCIC_SDS_PORT_MAX_TIMER_COUNT (SCI_MAX_PORTS)
#define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
#define SCU_DUMMY_INDEX (0xFFFF)
BOOL scic_sds_port_is_valid_phy_assignment(
SCIC_SDS_PORT_T *this_port,
U32 phy_index
)
{
U32 existing_phy_index = SCI_MAX_PHYS;
U32 index;
if ((this_port->physical_port_index == 1) && (phy_index != 1))
{
return FALSE;
}
if (this_port->physical_port_index == 3 && phy_index != 3)
{
return FALSE;
}
if (
(this_port->physical_port_index == 2)
&& ((phy_index == 0) || (phy_index == 1))
)
{
return FALSE;
}
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if ( (this_port->phy_table[index] != NULL)
&& (index != phy_index) )
{
existing_phy_index = index;
}
}
if (
(existing_phy_index < SCI_MAX_PHYS)
&& (this_port->owning_controller->user_parameters.sds1.phys[
phy_index].max_speed_generation !=
this_port->owning_controller->user_parameters.sds1.phys[
existing_phy_index].max_speed_generation)
)
return FALSE;
return TRUE;
}
U32 scic_sds_port_get_phys(
SCIC_SDS_PORT_T * this_port
)
{
U32 index;
U32 mask;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_get_phys(0x%x) enter\n",
this_port
));
mask = 0;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if (this_port->phy_table[index] != NULL)
{
mask |= (1 << index);
}
}
return mask;
}
BOOL scic_sds_port_is_phy_mask_valid(
SCIC_SDS_PORT_T *this_port,
U32 phy_mask
)
{
if (this_port->physical_port_index == 0)
{
if ( ((phy_mask & 0x0F) == 0x0F)
|| ((phy_mask & 0x03) == 0x03)
|| ((phy_mask & 0x01) == 0x01)
|| (phy_mask == 0) )
return TRUE;
}
else if (this_port->physical_port_index == 1)
{
if ( ((phy_mask & 0x02) == 0x02)
|| (phy_mask == 0) )
return TRUE;
}
else if (this_port->physical_port_index == 2)
{
if ( ((phy_mask & 0x0C) == 0x0C)
|| ((phy_mask & 0x04) == 0x04)
|| (phy_mask == 0) )
return TRUE;
}
else if (this_port->physical_port_index == 3)
{
if ( ((phy_mask & 0x08) == 0x08)
|| (phy_mask == 0) )
return TRUE;
}
return FALSE;
}
SCIC_SDS_PHY_T * scic_sds_port_get_a_connected_phy(
SCIC_SDS_PORT_T *this_port
)
{
U32 index;
SCIC_SDS_PHY_T *phy;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
phy = this_port->phy_table[index];
if (
(phy != NULL)
&& scic_sds_port_active_phy(this_port, phy)
)
{
return phy;
}
}
return NULL;
}
SCI_STATUS scic_sds_port_set_phy(
SCIC_SDS_PORT_T *port,
SCIC_SDS_PHY_T *phy
)
{
if (
(port->phy_table[phy->phy_index] == SCI_INVALID_HANDLE)
&& (scic_sds_phy_get_port(phy) == SCI_INVALID_HANDLE)
&& scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
)
{
port->logical_port_index = port->physical_port_index;
port->phy_table[phy->phy_index] = phy;
scic_sds_phy_set_port(phy, port);
return SCI_SUCCESS;
}
return SCI_FAILURE;
}
SCI_STATUS scic_sds_port_clear_phy(
SCIC_SDS_PORT_T *port,
SCIC_SDS_PHY_T *phy
)
{
if (
(port->phy_table[phy->phy_index] == phy)
&& (scic_sds_phy_get_port(phy) == port)
)
{
scic_sds_phy_set_port(
phy,
&scic_sds_port_get_controller(port)->port_table[SCI_MAX_PORTS]
);
port->phy_table[phy->phy_index] = SCI_INVALID_HANDLE;
return SCI_SUCCESS;
}
return SCI_FAILURE;
}
SCI_STATUS scic_sds_port_add_phy(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy
)
{
return this_port->state_handlers->parent.add_phy_handler(
&this_port->parent, &the_phy->parent);
}
SCI_STATUS scic_sds_port_remove_phy(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy
)
{
return this_port->state_handlers->parent.remove_phy_handler(
&this_port->parent, &the_phy->parent);
}
void scic_sds_port_get_sas_address(
SCIC_SDS_PORT_T * this_port,
SCI_SAS_ADDRESS_T * sas_address
)
{
U32 index;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_get_sas_address(0x%x, 0x%x) enter\n",
this_port, sas_address
));
sas_address->high = 0;
sas_address->low = 0;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if (this_port->phy_table[index] != NULL)
{
scic_sds_phy_get_sas_address(this_port->phy_table[index], sas_address);
}
}
}
static
void scic_sds_port_get_protocols(
SCIC_SDS_PORT_T * this_port,
SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T * protocols
)
{
U8 index;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_get_protocols(0x%x, 0x%x) enter\n",
this_port, protocols
));
protocols->u.all = 0;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if (this_port->phy_table[index] != NULL)
{
scic_sds_phy_get_protocols(this_port->phy_table[index], protocols);
}
}
}
void scic_sds_port_get_attached_sas_address(
SCIC_SDS_PORT_T * this_port,
SCI_SAS_ADDRESS_T * sas_address
)
{
SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T protocols;
SCIC_SDS_PHY_T *phy;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_get_attached_sas_address(0x%x, 0x%x) enter\n",
this_port, sas_address
));
phy = scic_sds_port_get_a_connected_phy(this_port);
if (phy != NULL)
{
scic_sds_phy_get_attached_phy_protocols(phy, &protocols);
if (!protocols.u.bits.stp_target)
{
scic_sds_phy_get_attached_sas_address(phy, sas_address);
}
else
{
scic_sds_phy_get_sas_address(phy, sas_address);
sas_address->low += phy->phy_index;
sas_address->high = SCIC_SWAP_DWORD(sas_address->high);
sas_address->low = SCIC_SWAP_DWORD(sas_address->low);
}
}
else
{
sas_address->high = 0;
sas_address->low = 0;
}
}
void scic_sds_port_get_attached_protocols(
SCIC_SDS_PORT_T * this_port,
SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T * protocols
)
{
SCIC_SDS_PHY_T *phy;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_get_attached_protocols(0x%x, 0x%x) enter\n",
this_port, protocols
));
phy = scic_sds_port_get_a_connected_phy(this_port);
if (phy != NULL)
scic_sds_phy_get_attached_phy_protocols(phy, protocols);
else
protocols->u.all = 0;
}
U32 scic_sds_port_get_object_size(void)
{
return sizeof(SCIC_SDS_PORT_T);
}
U32 scic_sds_port_get_min_timer_count(void)
{
return SCIC_SDS_PORT_MIN_TIMER_COUNT;
}
U32 scic_sds_port_get_max_timer_count(void)
{
return SCIC_SDS_PORT_MAX_TIMER_COUNT;
}
#ifdef SCI_LOGGING
void scic_sds_port_initialize_state_logging(
SCIC_SDS_PORT_T *this_port
)
{
sci_base_state_machine_logger_initialize(
&this_port->parent.state_machine_logger,
&this_port->parent.state_machine,
&this_port->parent.parent,
scic_cb_logger_log_states,
"SCIC_SDS_PORT_T", "base state machine",
SCIC_LOG_OBJECT_PORT
);
sci_base_state_machine_logger_initialize(
&this_port->ready_substate_machine_logger,
&this_port->ready_substate_machine,
&this_port->parent.parent,
scic_cb_logger_log_states,
"SCIC_SDS_PORT_T", "ready substate machine",
SCIC_LOG_OBJECT_PORT
);
}
#endif
static
void scic_sds_port_construct_dummy_rnc(
SCIC_SDS_PORT_T *this_port,
U16 rni
)
{
SCU_REMOTE_NODE_CONTEXT_T * rnc;
rnc = &(this_port->owning_controller->remote_node_context_table[rni]);
memset(rnc, 0, sizeof(SCU_REMOTE_NODE_CONTEXT_T));
rnc->ssp.remote_sas_address_hi = 0;
rnc->ssp.remote_sas_address_lo = 0;
rnc->ssp.remote_node_index = rni;
rnc->ssp.remote_node_port_width = 1;
rnc->ssp.logical_port_index = this_port->physical_port_index;
rnc->ssp.nexus_loss_timer_enable = FALSE;
rnc->ssp.check_bit = FALSE;
rnc->ssp.is_valid = TRUE;
rnc->ssp.is_remote_node_context = TRUE;
rnc->ssp.function_number = 0;
rnc->ssp.arbitration_wait_time = 0;
}
static
void scic_sds_port_construct_dummy_task(
SCIC_SDS_PORT_T *this_port,
U16 tci
)
{
SCU_TASK_CONTEXT_T * task_context;
task_context = scic_sds_controller_get_task_context_buffer(this_port->owning_controller, tci);
memset(task_context, 0, sizeof(SCU_TASK_CONTEXT_T));
task_context->abort = 0;
task_context->priority = 0;
task_context->initiator_request = 1;
task_context->connection_rate = 1;
task_context->protocol_engine_index = 0;
task_context->logical_port_index = this_port->physical_port_index;
task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
task_context->task_index = scic_sds_io_tag_get_index(tci);
task_context->valid = SCU_TASK_CONTEXT_VALID;
task_context->context_type = SCU_TASK_CONTEXT_TYPE;
task_context->remote_node_index = this_port->reserved_rni;
task_context->command_code = 0;
task_context->link_layer_control = 0;
task_context->do_not_dma_ssp_good_response = 1;
task_context->strict_ordering = 0;
task_context->control_frame = 0;
task_context->timeout_enable = 0;
task_context->block_guard_enable = 0;
task_context->address_modifier = 0;
task_context->task_phase = 0x01;
}
static
void scic_sds_port_destroy_dummy_resources(
SCIC_SDS_PORT_T * this_port
)
{
if (this_port->reserved_tci != SCU_DUMMY_INDEX)
{
scic_controller_free_io_tag(
this_port->owning_controller, this_port->reserved_tci
);
}
if (this_port->reserved_rni != SCU_DUMMY_INDEX)
{
scic_sds_remote_node_table_release_remote_node_index(
&this_port->owning_controller->available_remote_nodes, 1, this_port->reserved_rni
);
}
this_port->reserved_rni = SCU_DUMMY_INDEX;
this_port->reserved_tci = SCU_DUMMY_INDEX;
}
void scic_sds_port_construct(
SCIC_SDS_PORT_T *this_port,
U8 port_index,
SCIC_SDS_CONTROLLER_T *owning_controller
)
{
U32 index;
sci_base_port_construct(
&this_port->parent,
sci_base_object_get_logger(owning_controller),
scic_sds_port_state_table
);
sci_base_state_machine_construct(
scic_sds_port_get_ready_substate_machine(this_port),
&this_port->parent.parent,
scic_sds_port_ready_substate_table,
SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
scic_sds_port_initialize_state_logging(this_port);
this_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
this_port->physical_port_index = port_index;
this_port->active_phy_mask = 0;
this_port->enabled_phy_mask = 0;
this_port->owning_controller = owning_controller;
this_port->started_request_count = 0;
this_port->assigned_device_count = 0;
this_port->reserved_rni = SCU_DUMMY_INDEX;
this_port->reserved_tci = SCU_DUMMY_INDEX;
this_port->timer_handle = SCI_INVALID_HANDLE;
this_port->port_task_scheduler_registers = NULL;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
this_port->phy_table[index] = NULL;
}
}
SCI_STATUS scic_sds_port_initialize(
SCIC_SDS_PORT_T *this_port,
void *port_task_scheduler_registers,
void *port_configuration_regsiter,
void *viit_registers
)
{
this_port->port_task_scheduler_registers = port_task_scheduler_registers;
this_port->port_pe_configuration_register = port_configuration_regsiter;
this_port->viit_registers = viit_registers;
return SCI_SUCCESS;
}
void scic_sds_port_general_link_up_handler(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy,
BOOL do_notify_user,
BOOL do_resume_phy
)
{
SCI_SAS_ADDRESS_T port_sas_address;
SCI_SAS_ADDRESS_T phy_sas_address;
scic_sds_port_get_attached_sas_address(this_port, &port_sas_address);
scic_sds_phy_get_attached_sas_address(the_phy, &phy_sas_address);
if (
(
(phy_sas_address.high == port_sas_address.high)
&& (phy_sas_address.low == port_sas_address.low )
)
|| (this_port->active_phy_mask == 0)
)
{
scic_sds_port_activate_phy(this_port, the_phy, do_notify_user, do_resume_phy);
if (this_port->parent.state_machine.current_state_id
== SCI_BASE_PORT_STATE_RESETTING)
{
sci_base_state_machine_change_state(
&this_port->parent.state_machine, SCI_BASE_PORT_STATE_READY
);
}
}
else
{
scic_sds_port_invalid_link_up(this_port, the_phy);
}
}
SCI_STATUS scic_port_add_phy(
SCI_PORT_HANDLE_T handle,
SCI_PHY_HANDLE_T phy
)
{
#if defined (SCI_LOGGING)
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)handle;
#endif
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_port_add_phy(0x%x, 0x%x) enter\n",
handle, phy
));
SCIC_LOG_ERROR((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"Interface function scic_port_add_phy() has been deprecated. "
"PORT configuration is handled through the OEM parameters.\n"
));
return SCI_FAILURE_ADDING_PHY_UNSUPPORTED;
}
SCI_STATUS scic_port_remove_phy(
SCI_PORT_HANDLE_T handle,
SCI_PHY_HANDLE_T phy
)
{
#if defined (SCI_LOGGING)
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)handle;
#endif
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_port_remove_phy(0x%x, 0x%x) enter\n",
handle, phy
));
SCIC_LOG_ERROR((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"Interface function scic_port_remove_phy() has been deprecated. "
"PORT configuration is handled through the OEM parameters.\n"
));
return SCI_FAILURE_ADDING_PHY_UNSUPPORTED;
}
SCI_STATUS scic_port_get_properties(
SCI_PORT_HANDLE_T port,
SCIC_PORT_PROPERTIES_T * properties
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_port_get_properties(0x%x, 0x%x) enter\n",
port, properties
));
if (
(port == SCI_INVALID_HANDLE)
|| (this_port->logical_port_index == SCIC_SDS_DUMMY_PORT)
)
{
return SCI_FAILURE_INVALID_PORT;
}
properties->index = this_port->logical_port_index;
properties->phy_mask = scic_sds_port_get_phys(this_port);
scic_sds_port_get_sas_address(this_port, &properties->local.sas_address);
scic_sds_port_get_protocols(this_port, &properties->local.protocols);
scic_sds_port_get_attached_sas_address(this_port, &properties->remote.sas_address);
scic_sds_port_get_attached_protocols(this_port, &properties->remote.protocols);
return SCI_SUCCESS;
}
SCI_STATUS scic_port_hard_reset(
SCI_PORT_HANDLE_T handle,
U32 reset_timeout
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)handle;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_port_hard_reset(0x%x, 0x%x) enter\n",
handle, reset_timeout
));
return this_port->state_handlers->parent.reset_handler(
&this_port->parent,
reset_timeout
);
}
void scic_sds_port_setup_transports(
SCIC_SDS_PORT_T * this_port,
U32 device_id
)
{
U8 index;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if (this_port->active_phy_mask & (1 << index))
{
scic_sds_phy_setup_transport(this_port->phy_table[index], device_id);
}
}
}
static
void scic_sds_port_resume_phy(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy
)
{
scic_sds_phy_resume (the_phy);
this_port->enabled_phy_mask |= 1 << the_phy->phy_index;
}
void scic_sds_port_activate_phy(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy,
BOOL do_notify_user,
BOOL do_resume_phy
)
{
SCIC_SDS_CONTROLLER_T * controller;
SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T protocols;
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_activate_phy(0x%x,0x%x,0x%x) enter\n",
this_port, the_phy, do_notify_user
));
controller = scic_sds_port_get_controller(this_port);
scic_sds_phy_get_attached_phy_protocols(the_phy, &protocols);
if (!protocols.u.bits.stp_target)
{
if (do_resume_phy == TRUE)
{
scic_sds_port_resume_phy(this_port, the_phy);
}
}
this_port->active_phy_mask |= 1 << the_phy->phy_index;
scic_sds_controller_clear_invalid_phy(controller, the_phy);
if (do_notify_user == TRUE)
scic_cb_port_link_up(this_port->owning_controller, this_port, the_phy);
}
void scic_sds_port_deactivate_phy(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy,
BOOL do_notify_user
)
{
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_deactivate_phy(0x%x,0x%x,0x%x) enter\n",
this_port, the_phy, do_notify_user
));
this_port->active_phy_mask &= ~(1 << the_phy->phy_index);
this_port->enabled_phy_mask &= ~(1 << the_phy->phy_index);
the_phy->max_negotiated_speed = SCI_SAS_NO_LINK_RATE;
if (this_port->owning_controller->oem_parameters.sds1.controller.mode_type
== SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE)
{
SCU_PCSPExCR_WRITE(this_port, the_phy->phy_index, the_phy->phy_index);
}
if (do_notify_user == TRUE)
scic_cb_port_link_down(this_port->owning_controller, this_port, the_phy);
}
void scic_sds_port_invalid_link_up(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * the_phy
)
{
SCIC_SDS_CONTROLLER_T * controller = scic_sds_port_get_controller(this_port);
if ((controller->invalid_phy_mask & (1 << the_phy->phy_index)) == 0)
{
scic_sds_controller_set_invalid_phy(controller, the_phy);
scic_cb_port_invalid_link_up(controller, this_port, the_phy);
}
}
static
BOOL scic_sds_port_is_wide(
SCIC_SDS_PORT_T *this_port
)
{
U32 index;
U32 phy_count = 0;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if (this_port->phy_table[index] != NULL)
{
phy_count++;
}
}
return (phy_count != 1);
}
BOOL scic_sds_port_link_detected(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *the_phy
)
{
SCI_SAS_IDENTIFY_ADDRESS_FRAME_PROTOCOLS_T protocols;
scic_sds_phy_get_attached_phy_protocols(the_phy, &protocols);
if (
(this_port->logical_port_index != SCIC_SDS_DUMMY_PORT)
&& (protocols.u.bits.stp_target)
)
{
if (scic_sds_port_is_wide(this_port))
{
scic_sds_port_invalid_link_up( this_port, the_phy);
return FALSE;
}
else
{
SCIC_SDS_PORT_T *destination_port = &(this_port->owning_controller->port_table[the_phy->phy_index]);
SCU_PCSPExCR_WRITE( destination_port, the_phy->phy_index, the_phy->phy_index);
}
}
return TRUE;
}
void scic_sds_port_link_up(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *the_phy
)
{
the_phy->is_in_link_training = FALSE;
this_port->state_handlers->link_up_handler(this_port, the_phy);
}
void scic_sds_port_link_down(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *the_phy
)
{
this_port->state_handlers->link_down_handler(this_port, the_phy);
}
SCI_STATUS scic_sds_port_start_io(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_REMOTE_DEVICE_T *the_device,
SCIC_SDS_REQUEST_T *the_io_request
)
{
return this_port->state_handlers->start_io_handler(
this_port, the_device, the_io_request);
}
SCI_STATUS scic_sds_port_complete_io(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_REMOTE_DEVICE_T *the_device,
SCIC_SDS_REQUEST_T *the_io_request
)
{
return this_port->state_handlers->complete_io_handler(
this_port, the_device, the_io_request);
}
void scic_sds_port_timeout_handler(
void *port
)
{
U32 current_state;
SCIC_SDS_PORT_T * this_port;
this_port = (SCIC_SDS_PORT_T *)port;
current_state = sci_base_state_machine_get_state(
&this_port->parent.state_machine);
if (current_state == SCI_BASE_PORT_STATE_RESETTING)
{
sci_base_state_machine_change_state(
&this_port->parent.state_machine,
SCI_BASE_PORT_STATE_FAILED
);
}
else if (current_state == SCI_BASE_PORT_STATE_STOPPED)
{
SCIC_LOG_ERROR((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%x failed to stop before tiemout.\n",
this_port
));
}
else if (current_state == SCI_BASE_PORT_STATE_STOPPING)
{
scic_cb_port_stop_complete(
scic_sds_port_get_controller(this_port),
port,
SCI_FAILURE_TIMEOUT
);
}
else
{
SCIC_LOG_ERROR((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%x is processing a timeout operation in state %d.\n",
this_port, current_state
));
}
}
#ifdef SCIC_DEBUG_ENABLED
void scic_sds_port_decrement_request_count(
SCIC_SDS_PORT_T *this_port
)
{
if (this_port->started_request_count == 0)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port object requested to decrement started io count past zero.\n"
));
}
else
{
this_port->started_request_count--;
}
}
#endif
void scic_sds_port_update_viit_entry(
SCIC_SDS_PORT_T *this_port
)
{
SCI_SAS_ADDRESS_T sas_address;
scic_sds_port_get_sas_address(this_port, &sas_address);
scu_port_viit_register_write(
this_port, initiator_sas_address_hi, sas_address.high);
scu_port_viit_register_write(
this_port, initiator_sas_address_lo, sas_address.low);
scu_port_viit_register_write(
this_port, reserved, 0);
scu_port_viit_register_write(
this_port, status, (
SCU_VIIT_ENTRY_ID_VIIT
| SCU_VIIT_IPPT_INITIATOR
| ((1UL << this_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT)
| SCU_VIIT_STATUS_ALL_VALID
)
);
}
SCI_SAS_LINK_RATE scic_sds_port_get_max_allowed_speed(
SCIC_SDS_PORT_T * this_port
)
{
U16 index = 0;
SCI_SAS_LINK_RATE max_allowed_speed = SCI_SAS_600_GB;
SCIC_SDS_PHY_T * phy = NULL;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
phy = this_port->phy_table[index];
if (
(phy != NULL)
&& (scic_sds_port_active_phy(this_port, phy) == TRUE)
&& (phy->max_negotiated_speed < max_allowed_speed)
)
max_allowed_speed = phy->max_negotiated_speed;
}
return max_allowed_speed;
}
void scic_sds_port_broadcast_change_received(
SCIC_SDS_PORT_T * this_port,
SCIC_SDS_PHY_T * this_phy
)
{
scic_cb_port_bc_change_primitive_recieved(
this_port->owning_controller, this_port, this_phy
);
}
void scic_port_enable_broadcast_change_notification(
SCI_PORT_HANDLE_T port
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * phy;
U32 register_value;
U8 index;
for (index = 0; index < SCI_MAX_PHYS; index++)
{
phy = this_port->phy_table[index];
if ( phy != NULL)
{
register_value = SCU_SAS_LLCTL_READ(phy);
SCU_SAS_LLCTL_WRITE(phy, register_value);
}
}
}
void scic_sds_port_release_resource(
SCIC_SDS_CONTROLLER_T * controller,
SCIC_SDS_PORT_T *this_port
)
{
SCIC_LOG_TRACE((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"scic_sds_port_release_resource(0x%x, 0x%x)\n",
controller, this_port
));
if (this_port->timer_handle != NULL)
{
scic_cb_timer_destroy(controller, this_port->timer_handle);
this_port->timer_handle = NULL;
}
}
SCI_STATUS scic_sds_port_default_start_handler(
SCI_BASE_PORT_T *port
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to start while in invalid state %d\n",
port,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_stop_handler(
SCI_BASE_PORT_T *port
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to stop while in invalid state %d\n",
port,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_destruct_handler(
SCI_BASE_PORT_T *port
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to destruct while in invalid state %d\n",
port,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_reset_handler(
SCI_BASE_PORT_T * port,
U32 timeout
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to reset while in invalid state %d\n",
port,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_add_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to add phy 0x%08x while in invalid state %d\n",
port, phy,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_remove_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to remove phy 0x%08x while in invalid state %d\n",
port, phy,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_frame_handler(
SCIC_SDS_PORT_T * port,
U32 frame_index
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
SCIC_LOG_WARNING((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to process frame %d while in invalid state %d\n",
port, frame_index,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine(this_port))
));
scic_sds_controller_release_frame(
scic_sds_port_get_controller(this_port), frame_index
);
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_event_handler(
SCIC_SDS_PORT_T * port,
U32 event_code
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger((SCIC_SDS_PORT_T *)port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to process event 0x%08x while in invalid state %d\n",
port, event_code,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine((SCIC_SDS_PORT_T *)port))
));
return SCI_FAILURE_INVALID_STATE;
}
void scic_sds_port_default_link_up_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *phy
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x received link_up notification from phy 0x%08x while in invalid state %d\n",
this_port, phy,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine(this_port))
));
}
void scic_sds_port_default_link_down_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *phy
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x received link down notification from phy 0x%08x while in invalid state %d\n",
this_port, phy,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine(this_port))
));
}
SCI_STATUS scic_sds_port_default_start_io_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to start io request 0x%08x while in invalid state %d\n",
this_port, io_request,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine(this_port))
));
return SCI_FAILURE_INVALID_STATE;
}
SCI_STATUS scic_sds_port_default_complete_io_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
SCIC_LOG_WARNING((
sci_base_object_get_logger(this_port),
SCIC_LOG_OBJECT_PORT,
"SCIC Port 0x%08x requested to complete io request 0x%08x while in invalid state %d\n",
this_port, io_request,
sci_base_state_machine_get_state(
scic_sds_port_get_base_state_machine(this_port))
));
return SCI_FAILURE_INVALID_STATE;
}
static
SCI_STATUS scic_sds_port_general_complete_io_handler(
SCIC_SDS_PORT_T *port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
scic_sds_port_decrement_request_count(this_port);
return SCI_SUCCESS;
}
static
BOOL scic_sds_port_requires_scheduler_workaround(
SCIC_SDS_PORT_T * this_port
)
{
if (
(
this_port->owning_controller->logical_port_entries
< this_port->owning_controller->task_context_entries
)
&& (
this_port->owning_controller->logical_port_entries
< this_port->owning_controller->remote_node_entries
)
)
{
return TRUE;
}
return FALSE;
}
static
SCI_STATUS scic_sds_port_stopped_state_start_handler(
SCI_BASE_PORT_T *port
)
{
U32 phy_mask;
SCI_STATUS status = SCI_SUCCESS;
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
if (this_port->assigned_device_count > 0)
{
return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
}
this_port->timer_handle = scic_cb_timer_create(
scic_sds_port_get_controller(this_port),
scic_sds_port_timeout_handler,
this_port
);
if (this_port->timer_handle == SCI_INVALID_HANDLE)
{
return SCI_FAILURE_INSUFFICIENT_RESOURCES;
}
if (scic_sds_port_requires_scheduler_workaround(this_port))
{
if (this_port->reserved_rni == SCU_DUMMY_INDEX)
{
this_port->reserved_rni =
scic_sds_remote_node_table_allocate_remote_node(
&this_port->owning_controller->available_remote_nodes, 1
);
if (this_port->reserved_rni != SCU_DUMMY_INDEX)
{
scic_sds_port_construct_dummy_rnc(
this_port,
this_port->reserved_rni
);
}
else
{
status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
}
}
if (this_port->reserved_tci == SCU_DUMMY_INDEX)
{
this_port->reserved_tci =
scic_controller_allocate_io_tag(this_port->owning_controller);
if (this_port->reserved_tci != SCU_DUMMY_INDEX)
{
scic_sds_port_construct_dummy_task(this_port, this_port->reserved_tci);
}
else
{
status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
}
}
}
if (status == SCI_SUCCESS)
{
phy_mask = scic_sds_port_get_phys(this_port);
if (scic_sds_port_is_phy_mask_valid(this_port, phy_mask) == TRUE)
{
sci_base_state_machine_change_state(
scic_sds_port_get_base_state_machine(this_port),
SCI_BASE_PORT_STATE_READY
);
}
else
{
status = SCI_FAILURE;
}
}
if (status != SCI_SUCCESS)
{
scic_sds_port_destroy_dummy_resources(this_port);
}
return status;
}
static
SCI_STATUS scic_sds_port_stopped_state_stop_handler(
SCI_BASE_PORT_T *port
)
{
return SCI_SUCCESS;
}
static
SCI_STATUS scic_sds_port_stopped_state_destruct_handler(
SCI_BASE_PORT_T *port
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
sci_base_state_machine_stop(&this_port->parent.state_machine);
return SCI_SUCCESS;
}
static
SCI_STATUS scic_sds_port_stopped_state_add_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * this_phy = (SCIC_SDS_PHY_T *)phy;
SCI_SAS_ADDRESS_T port_sas_address;
scic_sds_port_get_sas_address(this_port, &port_sas_address);
if (port_sas_address.high != 0 && port_sas_address.low != 0)
{
SCI_SAS_ADDRESS_T phy_sas_address;
scic_sds_phy_get_sas_address(this_phy, &phy_sas_address);
if (
(port_sas_address.high != phy_sas_address.high)
|| (port_sas_address.low != phy_sas_address.low)
)
{
return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
}
}
return scic_sds_port_set_phy(this_port, this_phy);
}
static
SCI_STATUS scic_sds_port_stopped_state_remove_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T *this_phy = (SCIC_SDS_PHY_T *)phy;
return scic_sds_port_clear_phy(this_port, this_phy);
}
static
SCI_STATUS scic_sds_port_stopping_state_complete_io_handler(
SCIC_SDS_PORT_T *port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
scic_sds_port_decrement_request_count(this_port);
if (this_port->started_request_count == 0)
{
sci_base_state_machine_change_state(
scic_sds_port_get_base_state_machine(this_port),
SCI_BASE_PORT_STATE_STOPPED
);
}
return SCI_SUCCESS;
}
static
SCI_STATUS scic_sds_port_reset_state_stop_handler(
SCI_BASE_PORT_T *port
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
sci_base_state_machine_change_state(
&this_port->parent.state_machine,
SCI_BASE_PORT_STATE_STOPPING
);
return SCI_SUCCESS;
}
static
void scic_sds_port_reset_state_link_up_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *phy
)
{
scic_sds_port_general_link_up_handler(this_port, phy, FALSE, TRUE);
}
static
void scic_sds_port_reset_state_link_down_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *phy
)
{
scic_sds_port_deactivate_phy(this_port, phy, FALSE);
}
SCIC_SDS_PORT_STATE_HANDLER_T
scic_sds_port_state_handler_table[SCI_BASE_PORT_MAX_STATES] =
{
{
{
scic_sds_port_stopped_state_start_handler,
scic_sds_port_stopped_state_stop_handler,
scic_sds_port_stopped_state_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_stopped_state_add_phy_handler,
scic_sds_port_stopped_state_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_default_link_up_handler,
scic_sds_port_default_link_down_handler,
scic_sds_port_default_start_io_handler,
scic_sds_port_default_complete_io_handler
},
{
{
scic_sds_port_default_start_handler,
scic_sds_port_default_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_default_add_phy_handler,
scic_sds_port_default_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_default_link_up_handler,
scic_sds_port_default_link_down_handler,
scic_sds_port_default_start_io_handler,
scic_sds_port_stopping_state_complete_io_handler
},
{
{
scic_sds_port_default_start_handler,
scic_sds_port_default_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_default_add_phy_handler,
scic_sds_port_default_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_default_link_up_handler,
scic_sds_port_default_link_down_handler,
scic_sds_port_default_start_io_handler,
scic_sds_port_general_complete_io_handler
},
{
{
scic_sds_port_default_start_handler,
scic_sds_port_reset_state_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_default_add_phy_handler,
scic_sds_port_default_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_reset_state_link_up_handler,
scic_sds_port_reset_state_link_down_handler,
scic_sds_port_default_start_io_handler,
scic_sds_port_general_complete_io_handler
},
{
{
scic_sds_port_default_start_handler,
scic_sds_port_default_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_default_add_phy_handler,
scic_sds_port_default_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_default_link_up_handler,
scic_sds_port_default_link_down_handler,
scic_sds_port_default_start_io_handler,
scic_sds_port_general_complete_io_handler
}
};
static
void scic_sds_port_enable_port_task_scheduler(
SCIC_SDS_PORT_T *this_port
)
{
U32 pts_control_value;
pts_control_value = scu_port_task_scheduler_read(this_port, control);
pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
scu_port_task_scheduler_write(this_port, control, pts_control_value);
}
static
void scic_sds_port_disable_port_task_scheduler(
SCIC_SDS_PORT_T *this_port
)
{
U32 pts_control_value;
pts_control_value = scu_port_task_scheduler_read(this_port, control);
pts_control_value &= ~( SCU_PTSxCR_GEN_BIT(ENABLE)
| SCU_PTSxCR_GEN_BIT(SUSPEND) );
scu_port_task_scheduler_write(this_port, control, pts_control_value);
}
static
void scic_sds_port_post_dummy_remote_node(
SCIC_SDS_PORT_T *this_port
)
{
U32 command;
SCU_REMOTE_NODE_CONTEXT_T * rnc;
if (this_port->reserved_rni != SCU_DUMMY_INDEX)
{
rnc = &(this_port->owning_controller->remote_node_context_table[this_port->reserved_rni]);
rnc->ssp.is_valid = TRUE;
command = (
(SCU_CONTEXT_COMMAND_POST_RNC_32)
| (this_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT)
| (this_port->reserved_rni)
);
scic_sds_controller_post_request(this_port->owning_controller, command);
scic_cb_stall_execution(10);
command = (
(SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX)
| (this_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT)
| (this_port->reserved_rni)
);
scic_sds_controller_post_request(this_port->owning_controller, command);
}
}
static
void scic_sds_port_invalidate_dummy_remote_node(
SCIC_SDS_PORT_T *this_port
)
{
U32 command;
SCU_REMOTE_NODE_CONTEXT_T * rnc;
if (this_port->reserved_rni != SCU_DUMMY_INDEX)
{
rnc = &(this_port->owning_controller->remote_node_context_table[this_port->reserved_rni]);
rnc->ssp.is_valid = FALSE;
scic_cb_stall_execution(10);
command = (
(SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE)
| (this_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT)
| (this_port->reserved_rni)
);
scic_sds_controller_post_request(this_port->owning_controller, command);
}
}
static
void scic_sds_port_stopped_state_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_base_state_handlers(
this_port, SCI_BASE_PORT_STATE_STOPPED
);
if (
SCI_BASE_PORT_STATE_STOPPING
== this_port->parent.state_machine.previous_state_id
)
{
scic_sds_port_disable_port_task_scheduler(this_port);
}
}
static
void scic_sds_port_stopped_state_exit(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_enable_port_task_scheduler(this_port);
}
static
void scic_sds_port_ready_state_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_base_state_handlers(
this_port, SCI_BASE_PORT_STATE_READY
);
if (
SCI_BASE_PORT_STATE_RESETTING
== this_port->parent.state_machine.previous_state_id
)
{
scic_cb_port_hard_reset_complete(
scic_sds_port_get_controller(this_port),
this_port,
SCI_SUCCESS
);
}
else
{
scic_cb_port_not_ready(
scic_sds_port_get_controller(this_port),
this_port,
SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
);
}
scic_sds_port_post_dummy_remote_node(this_port);
sci_base_state_machine_start(
scic_sds_port_get_ready_substate_machine(this_port)
);
}
static
void scic_sds_port_ready_state_exit(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
sci_base_state_machine_stop(&this_port->ready_substate_machine);
scic_cb_stall_execution(10);
scic_sds_port_invalidate_dummy_remote_node(this_port);
}
static
void scic_sds_port_resetting_state_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_base_state_handlers(
this_port, SCI_BASE_PORT_STATE_RESETTING
);
}
static
void scic_sds_port_resetting_state_exit(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_cb_timer_stop(
scic_sds_port_get_controller(this_port),
this_port->timer_handle
);
}
static
void scic_sds_port_stopping_state_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_base_state_handlers(
this_port, SCI_BASE_PORT_STATE_STOPPING
);
if (this_port->started_request_count == 0)
{
sci_base_state_machine_change_state(
&this_port->parent.state_machine,
SCI_BASE_PORT_STATE_STOPPED
);
}
}
static
void scic_sds_port_stopping_state_exit(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_cb_timer_stop(
scic_sds_port_get_controller(this_port),
this_port->timer_handle
);
scic_cb_timer_destroy(
scic_sds_port_get_controller(this_port),
this_port->timer_handle
);
this_port->timer_handle = NULL;
scic_sds_port_destroy_dummy_resources(this_port);
}
static
void scic_sds_port_failed_state_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port;
this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_base_state_handlers(
this_port,
SCI_BASE_PORT_STATE_FAILED
);
scic_cb_port_hard_reset_complete(
scic_sds_port_get_controller(this_port),
this_port,
SCI_FAILURE_TIMEOUT
);
}
SCI_BASE_STATE_T scic_sds_port_state_table[SCI_BASE_PORT_MAX_STATES] =
{
{
SCI_BASE_PORT_STATE_STOPPED,
scic_sds_port_stopped_state_enter,
scic_sds_port_stopped_state_exit
},
{
SCI_BASE_PORT_STATE_STOPPING,
scic_sds_port_stopping_state_enter,
scic_sds_port_stopping_state_exit
},
{
SCI_BASE_PORT_STATE_READY,
scic_sds_port_ready_state_enter,
scic_sds_port_ready_state_exit
},
{
SCI_BASE_PORT_STATE_RESETTING,
scic_sds_port_resetting_state_enter,
scic_sds_port_resetting_state_exit
},
{
SCI_BASE_PORT_STATE_FAILED,
scic_sds_port_failed_state_enter,
NULL
}
};
static
SCI_STATUS scic_sds_port_ready_substate_stop_handler(
SCI_BASE_PORT_T *port
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
sci_base_state_machine_change_state(
&this_port->parent.state_machine,
SCI_BASE_PORT_STATE_STOPPING
);
return SCI_SUCCESS;
}
static
SCI_STATUS scic_sds_port_ready_substate_complete_io_handler(
SCIC_SDS_PORT_T *port,
struct SCIC_SDS_REMOTE_DEVICE *device,
struct SCIC_SDS_REQUEST *io_request
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
scic_sds_port_decrement_request_count(this_port);
return SCI_SUCCESS;
}
static
SCI_STATUS scic_sds_port_ready_substate_add_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * this_phy = (SCIC_SDS_PHY_T *)phy;
SCI_STATUS status;
status = scic_sds_port_set_phy(this_port, this_phy);
if (status == SCI_SUCCESS)
{
scic_sds_port_general_link_up_handler(this_port, this_phy, TRUE, FALSE);
this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
}
return status;
}
static
SCI_STATUS scic_sds_port_ready_substate_remove_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * this_phy = (SCIC_SDS_PHY_T *)phy;
SCI_STATUS status;
status = scic_sds_port_clear_phy(this_port, this_phy);
if (status == SCI_SUCCESS)
{
scic_sds_port_deactivate_phy(this_port, this_phy, TRUE);
this_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
}
return status;
}
static
void scic_sds_port_ready_waiting_substate_link_up_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *the_phy
)
{
scic_sds_port_activate_phy(this_port, the_phy, TRUE, TRUE);
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
}
static
SCI_STATUS scic_sds_port_ready_waiting_substate_start_io_handler(
SCIC_SDS_PORT_T *port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
return SCI_FAILURE_INVALID_STATE;
}
static
SCI_STATUS scic_sds_port_ready_operational_substate_reset_handler(
SCI_BASE_PORT_T * port,
U32 timeout
)
{
SCI_STATUS status = SCI_FAILURE_INVALID_PHY;
U32 phy_index;
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * selected_phy = SCI_INVALID_HANDLE;
for (
phy_index = 0;
(phy_index < SCI_MAX_PHYS)
&& (selected_phy == SCI_INVALID_HANDLE);
phy_index++
)
{
selected_phy = this_port->phy_table[phy_index];
if (
(selected_phy != SCI_INVALID_HANDLE)
&& !scic_sds_port_active_phy(this_port, selected_phy)
)
{
selected_phy = SCI_INVALID_HANDLE;
}
}
if (selected_phy != SCI_INVALID_HANDLE)
{
status = scic_sds_phy_reset(selected_phy);
if (status == SCI_SUCCESS)
{
scic_cb_timer_start(
scic_sds_port_get_controller(this_port),
this_port->timer_handle,
timeout
);
this_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
sci_base_state_machine_change_state(
&this_port->parent.state_machine,
SCI_BASE_PORT_STATE_RESETTING
);
}
}
return status;
}
static
void scic_sds_port_ready_operational_substate_link_up_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *the_phy
)
{
scic_sds_port_general_link_up_handler(this_port, the_phy, TRUE, TRUE);
}
static
void scic_sds_port_ready_operational_substate_link_down_handler(
SCIC_SDS_PORT_T *this_port,
SCIC_SDS_PHY_T *the_phy
)
{
scic_sds_port_deactivate_phy(this_port, the_phy, TRUE);
if (this_port->active_phy_mask == 0)
{
sci_base_state_machine_change_state(
scic_sds_port_get_ready_substate_machine(this_port),
SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
}
}
static
SCI_STATUS scic_sds_port_ready_operational_substate_start_io_handler(
SCIC_SDS_PORT_T *port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)port;
scic_sds_port_increment_request_count(this_port);
return SCI_SUCCESS;
}
static
SCI_STATUS scic_sds_port_ready_configuring_substate_add_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * this_phy = (SCIC_SDS_PHY_T *)phy;
SCI_STATUS status;
status = scic_sds_port_set_phy(this_port, this_phy);
if (status == SCI_SUCCESS)
{
scic_sds_port_general_link_up_handler(this_port, this_phy, TRUE, FALSE);
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
}
return status;
}
static
SCI_STATUS scic_sds_port_ready_configuring_substate_remove_phy_handler(
SCI_BASE_PORT_T *port,
SCI_BASE_PHY_T *phy
)
{
SCIC_SDS_PORT_T * this_port = (SCIC_SDS_PORT_T *)port;
SCIC_SDS_PHY_T * this_phy = (SCIC_SDS_PHY_T *)phy;
SCI_STATUS status;
status = scic_sds_port_clear_phy(this_port, this_phy);
if (status == SCI_SUCCESS)
{
scic_sds_port_deactivate_phy(this_port, this_phy, TRUE);
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
}
return status;
}
static
SCI_STATUS scic_sds_port_ready_configuring_substate_complete_io_handler(
SCIC_SDS_PORT_T *port,
SCIC_SDS_REMOTE_DEVICE_T *device,
SCIC_SDS_REQUEST_T *io_request
)
{
scic_sds_port_decrement_request_count(port);
if (port->started_request_count == 0)
{
sci_base_state_machine_change_state(
&port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
}
return SCI_SUCCESS;
}
SCIC_SDS_PORT_STATE_HANDLER_T
scic_sds_port_ready_substate_handler_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] =
{
{
{
scic_sds_port_default_start_handler,
scic_sds_port_ready_substate_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_ready_substate_add_phy_handler,
scic_sds_port_default_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_ready_waiting_substate_link_up_handler,
scic_sds_port_default_link_down_handler,
scic_sds_port_ready_waiting_substate_start_io_handler,
scic_sds_port_ready_substate_complete_io_handler,
},
{
{
scic_sds_port_default_start_handler,
scic_sds_port_ready_substate_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_ready_operational_substate_reset_handler,
scic_sds_port_ready_substate_add_phy_handler,
scic_sds_port_ready_substate_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_ready_operational_substate_link_up_handler,
scic_sds_port_ready_operational_substate_link_down_handler,
scic_sds_port_ready_operational_substate_start_io_handler,
scic_sds_port_ready_substate_complete_io_handler
},
{
{
scic_sds_port_default_start_handler,
scic_sds_port_ready_substate_stop_handler,
scic_sds_port_default_destruct_handler,
scic_sds_port_default_reset_handler,
scic_sds_port_ready_configuring_substate_add_phy_handler,
scic_sds_port_ready_configuring_substate_remove_phy_handler
},
scic_sds_port_default_frame_handler,
scic_sds_port_default_event_handler,
scic_sds_port_default_link_up_handler,
scic_sds_port_default_link_down_handler,
scic_sds_port_default_start_io_handler,
scic_sds_port_ready_configuring_substate_complete_io_handler
}
};
#define scic_sds_port_set_ready_state_handlers(port, state_id) \
scic_sds_port_set_state_handlers( \
port, &scic_sds_port_ready_substate_handler_table[(state_id)] \
)
void scic_sds_port_suspend_port_task_scheduler(
SCIC_SDS_PORT_T *this_port
)
{
U32 pts_control_value;
pts_control_value = scu_port_task_scheduler_read(this_port, control);
pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
scu_port_task_scheduler_write(this_port, control, pts_control_value);
}
void scic_sds_port_resume_port_task_scheduler(
SCIC_SDS_PORT_T *this_port
)
{
U32 pts_control_value;
pts_control_value = scu_port_task_scheduler_read(this_port, control);
pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
scu_port_task_scheduler_write(this_port, control, pts_control_value);
}
static
void scic_sds_port_post_dummy_request(
SCIC_SDS_PORT_T *this_port
)
{
U32 command;
SCU_TASK_CONTEXT_T * task_context;
if (this_port->reserved_tci != SCU_DUMMY_INDEX)
{
task_context = scic_sds_controller_get_task_context_buffer(
this_port->owning_controller,
this_port->reserved_tci
);
task_context->abort = 0;
command = (
(SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC)
| (this_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT)
| (this_port->reserved_tci)
);
scic_sds_controller_post_request(this_port->owning_controller, command);
}
}
static
void scic_sds_port_abort_dummy_request(
SCIC_SDS_PORT_T *this_port
)
{
U32 command;
SCU_TASK_CONTEXT_T * task_context;
if (this_port->reserved_tci != SCU_DUMMY_INDEX)
{
task_context = scic_sds_controller_get_task_context_buffer(
this_port->owning_controller,
this_port->reserved_tci
);
task_context->abort = 1;
command = (
(SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT)
| (this_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT)
| (this_port->reserved_tci)
);
scic_sds_controller_post_request(this_port->owning_controller, command);
}
}
static
void scic_sds_port_ready_substate_waiting_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_ready_state_handlers(
this_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
scic_sds_port_suspend_port_task_scheduler(this_port);
this_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
if (this_port->active_phy_mask != 0)
{
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
}
}
static
void scic_sds_port_ready_substate_waiting_exit(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_resume_port_task_scheduler(this_port);
}
static
void scic_sds_port_ready_substate_operational_enter(
SCI_BASE_OBJECT_T *object
)
{
U32 index;
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_ready_state_handlers(
this_port, SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
scic_cb_port_ready(
scic_sds_port_get_controller(this_port), this_port
);
for (index = 0; index < SCI_MAX_PHYS; index++)
{
if (this_port->phy_table[index] != NULL)
{
scic_sds_port_write_phy_assignment(
this_port, this_port->phy_table[index]
);
if ( ( (this_port->active_phy_mask ^ this_port->enabled_phy_mask) & (1 << index) ) != 0)
{
scic_sds_port_resume_phy (
this_port,
this_port->phy_table[index]
);
}
}
}
scic_sds_port_update_viit_entry(this_port);
scic_sds_port_post_dummy_request(this_port);
}
static
void scic_sds_port_ready_substate_operational_exit(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_abort_dummy_request(this_port);
scic_cb_port_not_ready(
scic_sds_port_get_controller(this_port),
this_port,
this_port->not_ready_reason
);
}
static
void scic_sds_port_ready_substate_configuring_enter(
SCI_BASE_OBJECT_T *object
)
{
SCIC_SDS_PORT_T *this_port = (SCIC_SDS_PORT_T *)object;
scic_sds_port_set_ready_state_handlers(
this_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
);
if (this_port->active_phy_mask == 0)
{
scic_cb_port_not_ready(
scic_sds_port_get_controller(this_port),
this_port,
SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS
);
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_WAITING
);
}
else
{
sci_base_state_machine_change_state(
&this_port->ready_substate_machine,
SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
);
}
}
SCI_BASE_STATE_T
scic_sds_port_ready_substate_table[SCIC_SDS_PORT_READY_MAX_SUBSTATES] =
{
{
SCIC_SDS_PORT_READY_SUBSTATE_WAITING,
scic_sds_port_ready_substate_waiting_enter,
scic_sds_port_ready_substate_waiting_exit
},
{
SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL,
scic_sds_port_ready_substate_operational_enter,
scic_sds_port_ready_substate_operational_exit
},
{
SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING,
scic_sds_port_ready_substate_configuring_enter,
NULL
}
};