return SCI_FAILURE;
}
-/**
- * scic_sds_port_add_phy() -
- * @sci_port: This parameter specifies the port in which the phy will be added.
- * @sci_phy: This parameter is the phy which is to be added to the port.
- *
- * This method will add a PHY to the selected port. This method returns an
- * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
- * is failre to add the phy to the port.
- */
-enum sci_status scic_sds_port_add_phy(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- return sci_port->state_handlers->add_phy_handler(
- sci_port, sci_phy);
-}
-
-
-/**
- * scic_sds_port_remove_phy() -
- * @sci_port: This parameter specifies the port in which the phy will be added.
- * @sci_phy: This parameter is the phy which is to be added to the port.
- *
- * This method will remove the PHY from the selected PORT. This method returns
- * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
- * status is failre to add the phy to the port.
- */
-enum sci_status scic_sds_port_remove_phy(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- return sci_port->state_handlers->remove_phy_handler(
- sci_port, sci_phy);
-}
/**
* This method requests the SAS address for the supplied SAS port from the SCI
return SCI_SUCCESS;
}
-/**
- * scic_port_hard_reset() - perform port hard reset
- * @port: a handle corresponding to the SAS port to be hard reset.
- * @reset_timeout: This parameter specifies the number of milliseconds in which
- * the port reset operation should complete.
- *
- * The SCI User callback in scic_user_callbacks_t will only be called once for
- * each phy in the SAS Port at completion of the hard reset sequence. Return a
- * status indicating whether the hard reset started successfully. SCI_SUCCESS
- * This value is returned if the hard reset operation started successfully.
- */
-static enum sci_status scic_port_hard_reset(struct scic_sds_port *port,
- u32 reset_timeout)
-{
- return port->state_handlers->reset_handler(
- port, reset_timeout);
-}
/**
* This method assigns the direct attached device ID for this port.
}
}
+static bool is_port_ready_state(enum scic_sds_port_states state)
+{
+ switch (state) {
+ case SCI_BASE_PORT_STATE_READY:
+ case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* flag dummy rnc hanling when exiting a ready state */
+static void port_state_machine_change(struct scic_sds_port *sci_port,
+ enum scic_sds_port_states state)
+{
+ struct sci_base_state_machine *sm = &sci_port->state_machine;
+ enum scic_sds_port_states old_state = sm->current_state_id;
+
+ if (is_port_ready_state(old_state) && !is_port_ready_state(state))
+ sci_port->ready_exit = true;
+
+ sci_base_state_machine_change_state(sm, state);
+ sci_port->ready_exit = false;
+}
+
/**
* scic_sds_port_general_link_up_handler - phy can be assigned to port?
* @sci_port: scic_sds_port object for which has a phy that has gone link up.
scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
- sci_base_state_machine_change_state(sm, SCI_BASE_PORT_STATE_READY);
+ port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_READY);
} else
scic_sds_port_invalid_link_up(sci_port, sci_phy);
}
return true;
}
-/**
- * This method is the entry point for the phy to inform the port that it is now
- * in a ready state
- * @sci_port:
- *
- *
- */
-void scic_sds_port_link_up(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- sci_phy->is_in_link_training = false;
-
- sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
-}
-
-/**
- * This method is the entry point for the phy to inform the port that it is no
- * longer in a ready state
- * @sci_port:
- *
- *
- */
-void scic_sds_port_link_down(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
-}
-
-/**
- * This method is called to start an IO request on this port.
- * @sci_port:
- * @sci_dev:
- * @sci_req:
- *
- * enum sci_status
- */
-enum sci_status scic_sds_port_start_io(
- struct scic_sds_port *sci_port,
- struct scic_sds_remote_device *sci_dev,
- struct scic_sds_request *sci_req)
-{
- return sci_port->state_handlers->start_io_handler(
- sci_port, sci_dev, sci_req);
-}
-
-/**
- * This method is called to complete an IO request to the port.
- * @sci_port:
- * @sci_dev:
- * @sci_req:
- *
- * enum sci_status
- */
-enum sci_status scic_sds_port_complete_io(
- struct scic_sds_port *sci_port,
- struct scic_sds_remote_device *sci_dev,
- struct scic_sds_request *sci_req)
-{
- return sci_port->state_handlers->complete_io_handler(
- sci_port, sci_dev, sci_req);
-}
-
/**
* This method is provided to timeout requests for port operations. Mostly its
* for the port reset operation.
struct scic_sds_port *sci_port = port;
u32 current_state;
- current_state = sci_base_state_machine_get_state(
- &sci_port->state_machine);
+ current_state = sci_base_state_machine_get_state(&sci_port->state_machine);
if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
- /*
- * if the port is still in the resetting state then the
- * timeout fired before the reset completed.
+ /* if the port is still in the resetting state then the timeout
+ * fired before the reset completed.
*/
- sci_base_state_machine_change_state(
- &sci_port->state_machine,
- SCI_BASE_PORT_STATE_FAILED);
+ port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_FAILED);
} else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
- /*
- * if the port is stopped then the start request failed
- * In this case stay in the stopped state.
+ /* if the port is stopped then the start request failed In this
+ * case stay in the stopped state.
*/
dev_err(sciport_to_dev(sci_port),
"%s: SCIC Port 0x%p failed to stop before tiemout.\n",
__func__,
sci_port);
} else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
- /*
- * if the port is still stopping then the stop has not
- * completed
- */
- isci_port_stop_complete(
- scic_sds_port_get_controller(sci_port),
- sci_port,
- SCI_FAILURE_TIMEOUT);
+ /* if the port is still stopping then the stop has not completed */
+ isci_port_stop_complete(sci_port->owning_controller,
+ sci_port,
+ SCI_FAILURE_TIMEOUT);
} else {
- /*
- * The port is in the ready state and we have a timer
+ /* The port is in the ready state and we have a timer
* reporting a timeout this should not happen.
*/
dev_err(sciport_to_dev(sci_port),
"%s: SCIC Port 0x%p is processing a timeout operation "
- "in state %d.\n",
- __func__,
- sci_port,
- current_state);
+ "in state %d.\n", __func__, sci_port, current_state);
}
}
}
}
-/*
- * ****************************************************************************
- * * READY SUBSTATE HANDLERS
- * **************************************************************************** */
-
-/*
- * This method is the general ready state stop handler for the struct scic_sds_port
- * object. This function will transition the ready substate machine to its
- * final state. enum sci_status SCI_SUCCESS
+/**
+ *
+ * @sci_port: This is the struct scic_sds_port object to suspend.
+ *
+ * This method will susped the port task scheduler for this port object. none
*/
-static enum sci_status scic_sds_port_ready_substate_stop_handler(
- struct scic_sds_port *port)
+static void
+scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
{
- sci_base_state_machine_change_state(
- &port->state_machine,
- SCI_BASE_PORT_STATE_STOPPING
- );
+ u32 pts_control_value;
- return SCI_SUCCESS;
+ pts_control_value = readl(&port->port_task_scheduler_registers->control);
+ pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
+ writel(pts_control_value, &port->port_task_scheduler_registers->control);
}
-/*
- * This method is the general ready substate complete io handler for the
- * struct scic_sds_port object. This function decrments the outstanding request count
- * for this port object. enum sci_status SCI_SUCCESS
+/**
+ * scic_sds_port_post_dummy_request() - post dummy/workaround request
+ * @sci_port: port to post task
+ *
+ * Prevent the hardware scheduler from posting new requests to the front
+ * of the scheduler queue causing a starvation problem for currently
+ * ongoing requests.
+ *
*/
-static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
- struct scic_sds_port *port,
- struct scic_sds_remote_device *device,
- struct scic_sds_request *io_request)
-{
- scic_sds_port_decrement_request_count(port);
-
- return SCI_SUCCESS;
-}
-
-static enum sci_status scic_sds_port_ready_substate_add_phy_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
+static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
{
- enum sci_status status;
-
- status = scic_sds_port_set_phy(port, phy);
+ u32 command;
+ struct scu_task_context *task_context;
+ struct scic_sds_controller *scic = sci_port->owning_controller;
+ u16 tci = sci_port->reserved_tci;
- if (status == SCI_SUCCESS) {
- scic_sds_port_general_link_up_handler(port, phy, true);
+ task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
- port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
+ task_context->abort = 0;
- sci_base_state_machine_change_state(
- &port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
- );
- }
+ command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
+ sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
+ tci;
- return status;
+ scic_sds_controller_post_request(scic, command);
}
-
-static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
+/**
+ * This routine will abort the dummy request. This will alow the hardware to
+ * power down parts of the silicon to save power.
+ *
+ * @sci_port: The port on which the task must be aborted.
+ *
+ */
+static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
{
- enum sci_status status;
-
- status = scic_sds_port_clear_phy(port, phy);
+ struct scic_sds_controller *scic = sci_port->owning_controller;
+ u16 tci = sci_port->reserved_tci;
+ struct scu_task_context *tc;
+ u32 command;
- if (status == SCI_SUCCESS) {
- scic_sds_port_deactivate_phy(port, phy, true);
+ tc = scic_sds_controller_get_task_context_buffer(scic, tci);
- port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
+ tc->abort = 1;
- sci_base_state_machine_change_state(
- &port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
- );
- }
+ command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
+ sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
+ tci;
- return status;
+ scic_sds_controller_post_request(scic, command);
}
-/*
- * ****************************************************************************
- * * READY SUBSTATE WAITING HANDLERS
- * **************************************************************************** */
-
/**
*
- * @sci_port: This is the struct scic_sds_port object that which has a phy that has
- * gone link up.
- * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
+ * @sci_port: This is the struct scic_sds_port object to resume.
*
- * This method is the ready waiting substate link up handler for the
- * struct scic_sds_port object. This methos will report the link up condition for
- * this port and will transition to the ready operational substate. none
+ * This method will resume the port task scheduler for this port object. none
*/
-static void scic_sds_port_ready_waiting_substate_link_up_handler(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
+static void
+scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
{
- /*
- * Since this is the first phy going link up for the port we can just enable
- * it and continue. */
- scic_sds_port_activate_phy(sci_port, sci_phy, true);
-
- sci_base_state_machine_change_state(
- &sci_port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
- );
-}
+ u32 pts_control_value;
-/*
- * This method is the ready waiting substate start io handler for the
- * struct scic_sds_port object. The port object can not accept new requests so the
- * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
- struct scic_sds_port *port,
- struct scic_sds_remote_device *device,
- struct scic_sds_request *io_request)
-{
- return SCI_FAILURE_INVALID_STATE;
+ pts_control_value = readl(&port->port_task_scheduler_registers->control);
+ pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
+ writel(pts_control_value, &port->port_task_scheduler_registers->control);
}
-/*
- * ****************************************************************************
- * * READY SUBSTATE OPERATIONAL HANDLERS
- * **************************************************************************** */
-
-/*
- * This method will casue the port to reset. enum sci_status SCI_SUCCESS
- */
-static enum
-sci_status scic_sds_port_ready_operational_substate_reset_handler(
- struct scic_sds_port *port,
- u32 timeout)
+static void scic_sds_port_ready_substate_waiting_enter(void *object)
{
- enum sci_status status = SCI_FAILURE_INVALID_PHY;
- u32 phy_index;
- struct scic_sds_phy *selected_phy = NULL;
+ struct scic_sds_port *sci_port = object;
+ scic_sds_port_suspend_port_task_scheduler(sci_port);
- /* Select a phy on which we can send the hard reset request. */
- for (phy_index = 0;
- (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
- phy_index++) {
- selected_phy = port->phy_table[phy_index];
+ sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
- if ((selected_phy != NULL) &&
- !scic_sds_port_active_phy(port, selected_phy)) {
- /*
- * We found a phy but it is not ready select
- * different phy
- */
- selected_phy = NULL;
- }
+ if (sci_port->active_phy_mask != 0) {
+ /* At least one of the phys on the port is ready */
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
}
+}
- /* If we have a phy then go ahead and start the reset procedure */
- if (selected_phy != NULL) {
- status = scic_sds_phy_reset(selected_phy);
+static void scic_sds_port_ready_substate_operational_enter(void *object)
+{
+ u32 index;
+ struct scic_sds_port *sci_port = object;
+ struct scic_sds_controller *scic = sci_port->owning_controller;
+ struct isci_host *ihost = scic_to_ihost(scic);
+ struct isci_port *iport = sci_port_to_iport(sci_port);
- if (status == SCI_SUCCESS) {
- isci_timer_start(port->timer_handle, timeout);
- port->not_ready_reason =
- SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
+ isci_port_ready(ihost, iport);
- sci_base_state_machine_change_state(
- &port->state_machine,
- SCI_BASE_PORT_STATE_RESETTING);
+ for (index = 0; index < SCI_MAX_PHYS; index++) {
+ if (sci_port->phy_table[index]) {
+ writel(sci_port->physical_port_index,
+ &sci_port->port_pe_configuration_register[
+ sci_port->phy_table[index]->phy_index]);
}
}
- return status;
-}
-
-/**
- * scic_sds_port_ready_operational_substate_link_up_handler() -
- * @sci_port: This is the struct scic_sds_port object that which has a phy that has
- * gone link up.
- * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
- *
- * This method is the ready operational substate link up handler for the
- * struct scic_sds_port object. This function notifies the SCI User that the phy has
- * gone link up. none
- */
-static void scic_sds_port_ready_operational_substate_link_up_handler(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
-}
+ scic_sds_port_update_viit_entry(sci_port);
-/**
- * scic_sds_port_ready_operational_substate_link_down_handler() -
- * @sci_port: This is the struct scic_sds_port object that which has a phy that has
- * gone link down.
- * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
- *
- * This method is the ready operational substate link down handler for the
- * struct scic_sds_port object. This function notifies the SCI User that the phy has
- * gone link down and if this is the last phy in the port the port will change
- * state to the ready waiting substate. none
- */
-static void scic_sds_port_ready_operational_substate_link_down_handler(
- struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
+ scic_sds_port_resume_port_task_scheduler(sci_port);
/*
- * If there are no active phys left in the port, then transition
- * the port to the WAITING state until such time as a phy goes
- * link up. */
- if (sci_port->active_phy_mask == 0)
- sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
+ * Post the dummy task for the port so the hardware can schedule
+ * io correctly
+ */
+ scic_sds_port_post_dummy_request(sci_port);
}
-/*
- * This method is the ready operational substate start io handler for the
- * struct scic_sds_port object. This function incremetns the outstanding request
- * count for this port object. enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
- struct scic_sds_port *port,
- struct scic_sds_remote_device *device,
- struct scic_sds_request *io_request)
+static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
{
- port->started_request_count++;
- return SCI_SUCCESS;
-}
-
-/*
- * ****************************************************************************
- * * READY SUBSTATE OPERATIONAL HANDLERS
- * **************************************************************************** */
+ struct scic_sds_controller *scic = sci_port->owning_controller;
+ u8 phys_index = sci_port->physical_port_index;
+ union scu_remote_node_context *rnc;
+ u16 rni = sci_port->reserved_rni;
+ u32 command;
-/*
- * This is the default method for a port add phy request. It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
-{
- enum sci_status status;
+ rnc = &scic->remote_node_context_table[rni];
- status = scic_sds_port_set_phy(port, phy);
+ rnc->ssp.is_valid = false;
- if (status == SCI_SUCCESS) {
- scic_sds_port_general_link_up_handler(port, phy, true);
-
- /*
- * Re-enter the configuring state since this may be the last phy in
- * the port. */
- sci_base_state_machine_change_state(
- &port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
- );
- }
-
- return status;
-}
-
-/*
- * This is the default method for a port remove phy request. It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
-{
- enum sci_status status;
-
- status = scic_sds_port_clear_phy(port, phy);
-
- if (status == SCI_SUCCESS) {
- scic_sds_port_deactivate_phy(port, phy, true);
-
- /*
- * Re-enter the configuring state since this may be the last phy in
- * the port. */
- sci_base_state_machine_change_state(
- &port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING
- );
- }
-
- return status;
-}
-
-/**
- * scic_sds_port_ready_configuring_substate_complete_io_handler() -
- * @port: This is the port that is being requested to complete the io request.
- * @device: This is the device on which the io is completing.
- *
- * This method will decrement the outstanding request count for this port. If
- * the request count goes to 0 then the port can be reprogrammed with its new
- * phy data.
- */
-static enum sci_status
-scic_sds_port_ready_configuring_substate_complete_io_handler(
- struct scic_sds_port *port,
- struct scic_sds_remote_device *device,
- struct scic_sds_request *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;
-}
-
-static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
- const char *func)
-{
- dev_warn(sciport_to_dev(sci_port),
- "%s: in wrong state: %d\n", func,
- sci_base_state_machine_get_state(&sci_port->state_machine));
- return SCI_FAILURE_INVALID_STATE;
-}
-
-static enum sci_status
-scic_sds_port_default_start_handler(struct scic_sds_port *sci_port)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status
-scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status
-scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status
-scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port,
- u32 timeout)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status
-scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port,
- struct scic_sds_phy *base_phy)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status
-scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port,
- struct scic_sds_phy *base_phy)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-/*
- * This is the default method for a port unsolicited frame request. It will
- * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
- * possible to receive an unsolicited frame directed to a port object? It
- * seems possible if we implementing virtual functions but until then?
- */
-static enum sci_status
-scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
- u32 frame_index)
-{
- struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
-
- default_port_handler(sci_port, __func__);
- scic_sds_controller_release_frame(scic, frame_index);
-
- return SCI_FAILURE_INVALID_STATE;
-}
-
-static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
- u32 event_code)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- default_port_handler(sci_port, __func__);
-}
-
-static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
- struct scic_sds_phy *sci_phy)
-{
- default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
- struct scic_sds_remote_device *sci_dev,
- struct scic_sds_request *sci_req)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
- struct scic_sds_remote_device *sci_dev,
- struct scic_sds_request *sci_req)
-{
- return default_port_handler(sci_port, __func__);
-}
-
-static struct scic_sds_port_state_handler scic_sds_port_ready_substate_handler_table[] = {
- [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_ready_substate_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
- .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_ready_waiting_substate_link_up_handler,
- .link_down_handler = scic_sds_port_default_link_down_handler,
- .start_io_handler = scic_sds_port_ready_waiting_substate_start_io_handler,
- .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
- },
- [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_ready_substate_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_ready_operational_substate_reset_handler,
- .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
- .remove_phy_handler = scic_sds_port_ready_substate_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_ready_operational_substate_link_up_handler,
- .link_down_handler = scic_sds_port_ready_operational_substate_link_down_handler,
- .start_io_handler = scic_sds_port_ready_operational_substate_start_io_handler,
- .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
- },
- [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_ready_substate_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_ready_configuring_substate_add_phy_handler,
- .remove_phy_handler = scic_sds_port_ready_configuring_substate_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_default_link_up_handler,
- .link_down_handler = scic_sds_port_default_link_down_handler,
- .start_io_handler = scic_sds_port_default_start_io_handler,
- .complete_io_handler = scic_sds_port_ready_configuring_substate_complete_io_handler
- }
-};
-
-/**
- * scic_sds_port_set_ready_state_handlers() -
- *
- * This macro sets the port ready substate handlers.
- */
-#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)] \
- )
-
-/*
- * ******************************************************************************
- * * PORT STATE PRIVATE METHODS
- * ****************************************************************************** */
-
-/**
- *
- * @sci_port: This is the struct scic_sds_port object to suspend.
- *
- * This method will susped the port task scheduler for this port object. none
- */
-static void
-scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
-{
- u32 pts_control_value;
-
- pts_control_value = readl(&port->port_task_scheduler_registers->control);
- pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
- writel(pts_control_value, &port->port_task_scheduler_registers->control);
-}
-
-/**
- * scic_sds_port_post_dummy_request() - post dummy/workaround request
- * @sci_port: port to post task
- *
- * Prevent the hardware scheduler from posting new requests to the front
- * of the scheduler queue causing a starvation problem for currently
- * ongoing requests.
- *
- */
-static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
-{
- u32 command;
- struct scu_task_context *task_context;
- struct scic_sds_controller *scic = sci_port->owning_controller;
- u16 tci = sci_port->reserved_tci;
-
- task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
-
- task_context->abort = 0;
-
- command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
- sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
- tci;
-
- scic_sds_controller_post_request(scic, command);
-}
-
-/**
- * This routine will abort the dummy request. This will alow the hardware to
- * power down parts of the silicon to save power.
- *
- * @sci_port: The port on which the task must be aborted.
- *
- */
-static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
-{
- struct scic_sds_controller *scic = sci_port->owning_controller;
- u16 tci = sci_port->reserved_tci;
- struct scu_task_context *tc;
- u32 command;
-
- tc = scic_sds_controller_get_task_context_buffer(scic, tci);
-
- tc->abort = 1;
+ /* ensure the preceding tc abort request has reached the
+ * controller and give it ample time to act before posting the rnc
+ * invalidate
+ */
+ readl(&scic->smu_registers->interrupt_status); /* flush */
+ udelay(10);
- command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
- sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
- tci;
+ command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
+ phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
scic_sds_controller_post_request(scic, command);
}
-/**
- *
- * @sci_port: This is the struct scic_sds_port object to resume.
- *
- * This method will resume the port task scheduler for this port object. none
- */
-static void
-scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
-{
- u32 pts_control_value;
-
- pts_control_value = readl(&port->port_task_scheduler_registers->control);
- pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
- writel(pts_control_value, &port->port_task_scheduler_registers->control);
-}
-
-/*
- * ******************************************************************************
- * * PORT READY SUBSTATE METHODS
- * ****************************************************************************** */
-
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
- * port for any ready phys. If there is at least one phy in a ready state then
- * the port transitions to the ready operational substate. none
- */
-static void scic_sds_port_ready_substate_waiting_enter(void *object)
-{
- struct scic_sds_port *sci_port = object;
-
- scic_sds_port_set_ready_state_handlers(
- sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
- );
-
- scic_sds_port_suspend_port_task_scheduler(sci_port);
-
- sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
-
- if (sci_port->active_phy_mask != 0) {
- /* At least one of the phys on the port is ready */
- sci_base_state_machine_change_state(
- &sci_port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL
- );
- }
-}
-
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This function will perform the actions required by the struct scic_sds_port
- * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
- * the state handlers for the port object, notifies the SCI User that the port
- * is ready, and resumes port operations. none
- */
-static void scic_sds_port_ready_substate_operational_enter(void *object)
-{
- u32 index;
- struct scic_sds_port *sci_port = object;
- struct scic_sds_controller *scic = sci_port->owning_controller;
- struct isci_host *ihost = scic_to_ihost(scic);
- struct isci_port *iport = sci_port_to_iport(sci_port);
-
- scic_sds_port_set_ready_state_handlers(
- sci_port,
- SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
-
- isci_port_ready(ihost, iport);
-
- for (index = 0; index < SCI_MAX_PHYS; index++) {
- if (sci_port->phy_table[index]) {
- writel(sci_port->physical_port_index,
- &sci_port->port_pe_configuration_register[
- sci_port->phy_table[index]->phy_index]);
- }
- }
-
- scic_sds_port_update_viit_entry(sci_port);
-
- scic_sds_port_resume_port_task_scheduler(sci_port);
-
- /*
- * Post the dummy task for the port so the hardware can schedule
- * io correctly
- */
- scic_sds_port_post_dummy_request(sci_port);
-}
-
/**
*
* @object: This is the object which is cast to a struct scic_sds_port object.
scic_sds_port_abort_dummy_request(sci_port);
isci_port_not_ready(ihost, iport);
-}
-/*
- * ******************************************************************************
- * * PORT READY CONFIGURING METHODS
- * ****************************************************************************** */
+ if (sci_port->ready_exit)
+ scic_sds_port_invalidate_dummy_remote_node(sci_port);
+}
-/**
- * scic_sds_port_ready_substate_configuring_enter() -
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
- * the port not ready and suspends the port task scheduler. none
- */
static void scic_sds_port_ready_substate_configuring_enter(void *object)
{
struct scic_sds_port *sci_port = object;
struct isci_host *ihost = scic_to_ihost(scic);
struct isci_port *iport = sci_port_to_iport(sci_port);
- scic_sds_port_set_ready_state_handlers(
- sci_port,
- SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
-
if (sci_port->active_phy_mask == 0) {
isci_port_not_ready(ihost, iport);
- sci_base_state_machine_change_state(
- &sci_port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
} else if (sci_port->started_request_count == 0)
- sci_base_state_machine_change_state(
- &sci_port->ready_substate_machine,
- SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
}
static void scic_sds_port_ready_substate_configuring_exit(void *object)
struct scic_sds_port *sci_port = object;
scic_sds_port_suspend_port_task_scheduler(sci_port);
+ if (sci_port->ready_exit)
+ scic_sds_port_invalidate_dummy_remote_node(sci_port);
}
-/* --------------------------------------------------------------------------- */
-
-static const struct sci_base_state scic_sds_port_ready_substate_table[] = {
- [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
- .enter_state = scic_sds_port_ready_substate_waiting_enter,
- },
- [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
- .enter_state = scic_sds_port_ready_substate_operational_enter,
- .exit_state = scic_sds_port_ready_substate_operational_exit
- },
- [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
- .enter_state = scic_sds_port_ready_substate_configuring_enter,
- .exit_state = scic_sds_port_ready_substate_configuring_exit
- },
-};
-
-/**
- *
- * @port: This is the struct scic_sds_port object on which the io request count will
- * be decremented.
- * @device: This is the struct scic_sds_remote_device object to which the io request
- * is being directed. This parameter is not required to complete this
- * operation.
- * @io_request: This is the request that is being completed on this port
- * object. This parameter is not required to complete this operation.
- *
- * This is a general complete io request handler for the struct scic_sds_port object.
- * enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_port_general_complete_io_handler(
- struct scic_sds_port *port,
- struct scic_sds_remote_device *device,
- struct scic_sds_request *io_request)
-{
- scic_sds_port_decrement_request_count(port);
-
- return SCI_SUCCESS;
-}
-
-/**
- * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
- *
- * @port: This is the struct scic_sds_port object which is cast into a
- * struct scic_sds_port object.
- *
- * This function takes the struct scic_sds_port from a stopped state and
- * attempts to start it. To start a port it must have no assiged devices and
- * it must have at least one phy assigned to it. If those conditions are
- * met then the port can transition to the ready state.
- * enum sci_status
- * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
- * This struct scic_sds_port object could not be started because the port
- * configuration is not valid.
- * SCI_SUCCESS
- * the start request is successful and the struct scic_sds_port object
- * has transitioned to the SCI_BASE_PORT_STATE_READY.
- */
-static enum sci_status
-scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port)
+enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port)
{
struct scic_sds_controller *scic = sci_port->owning_controller;
struct isci_host *ihost = scic_to_ihost(scic);
enum sci_status status = SCI_SUCCESS;
+ enum scic_sds_port_states state;
u32 phy_mask;
+ state = sci_port->state_machine.current_state_id;
+ if (state != SCI_BASE_PORT_STATE_STOPPED) {
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ }
+
if (sci_port->assigned_device_count > 0) {
- /*
- * @todo This is a start failure operation because
+ /* TODO This is a start failure operation because
* there are still devices assigned to this port.
* There must be no devices assigned to a port on a
* start operation.
* silicon.
*/
if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
- sci_base_state_machine_change_state(
- &sci_port->state_machine,
- SCI_BASE_PORT_STATE_READY);
+ port_state_machine_change(sci_port,
+ SCI_BASE_PORT_STATE_READY);
return SCI_SUCCESS;
- } else
- status = SCI_FAILURE;
+ }
+ status = SCI_FAILURE;
}
if (status != SCI_SUCCESS)
return status;
}
-/*
- * This method takes the struct scic_sds_port that is in a stopped state and handles a
- * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
- * stop request is successful as the struct scic_sds_port object is already stopped.
- */
-static enum sci_status scic_sds_port_stopped_state_stop_handler(
- struct scic_sds_port *port)
+enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port)
{
- /* We are already stopped so there is nothing to do here */
- return SCI_SUCCESS;
+ enum scic_sds_port_states state;
+
+ state = sci_port->state_machine.current_state_id;
+ switch (state) {
+ case SCI_BASE_PORT_STATE_STOPPED:
+ return SCI_SUCCESS;
+ case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
+ case SCI_BASE_PORT_STATE_RESETTING:
+ port_state_machine_change(sci_port,
+ SCI_BASE_PORT_STATE_STOPPING);
+ return SCI_SUCCESS;
+ default:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ }
}
-/*
- * This method takes the struct scic_sds_port that is in a stopped state and handles
- * the destruct request. The stopped state is the only state in which the
- * struct scic_sds_port can be destroyed. This function causes the port object to
- * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_port_stopped_state_destruct_handler(
- struct scic_sds_port *port)
+static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout)
{
- sci_base_state_machine_stop(&port->state_machine);
+ enum sci_status status = SCI_FAILURE_INVALID_PHY;
+ struct scic_sds_phy *selected_phy = NULL;
+ enum scic_sds_port_states state;
+ u32 phy_index;
+
+ state = sci_port->state_machine.current_state_id;
+ if (state != SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL) {
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ }
+
+ /* Select a phy on which we can send the hard reset request. */
+ for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) {
+ selected_phy = sci_port->phy_table[phy_index];
+ if (selected_phy &&
+ !scic_sds_port_active_phy(sci_port, selected_phy)) {
+ /*
+ * We found a phy but it is not ready select
+ * different phy
+ */
+ selected_phy = NULL;
+ }
+ }
+
+ /* If we have a phy then go ahead and start the reset procedure */
+ if (!selected_phy)
+ return status;
+ status = scic_sds_phy_reset(selected_phy);
+ if (status != SCI_SUCCESS)
+ return status;
+
+ isci_timer_start(sci_port->timer_handle, timeout);
+ sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
+
+ port_state_machine_change(sci_port,
+ SCI_BASE_PORT_STATE_RESETTING);
return SCI_SUCCESS;
}
-/*
- * This method takes the struct scic_sds_port that is in a stopped state and handles
- * the add phy request. In MPC mode the only time a phy can be added to a port
- * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
- * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
- * be added to the port. SCI_SUCCESS if the phy is added to the port.
+/**
+ * scic_sds_port_add_phy() -
+ * @sci_port: This parameter specifies the port in which the phy will be added.
+ * @sci_phy: This parameter is the phy which is to be added to the port.
+ *
+ * This method will add a PHY to the selected port. This method returns an
+ * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
+ * status is a failure to add the phy to the port.
*/
-static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
+enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
+ struct scic_sds_phy *sci_phy)
{
- struct sci_sas_address port_sas_address;
+ enum sci_status status;
+ enum scic_sds_port_states state;
- /* Read the port assigned SAS Address if there is one */
- scic_sds_port_get_sas_address(port, &port_sas_address);
+ state = sci_port->state_machine.current_state_id;
+ switch (state) {
+ case SCI_BASE_PORT_STATE_STOPPED: {
+ struct sci_sas_address port_sas_address;
- if (port_sas_address.high != 0 && port_sas_address.low != 0) {
- struct sci_sas_address phy_sas_address;
+ /* Read the port assigned SAS Address if there is one */
+ scic_sds_port_get_sas_address(sci_port, &port_sas_address);
- /*
- * Make sure that the PHY SAS Address matches the SAS Address
- * for this port. */
- scic_sds_phy_get_sas_address(phy, &phy_sas_address);
+ if (port_sas_address.high != 0 && port_sas_address.low != 0) {
+ struct sci_sas_address 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;
+ /* Make sure that the PHY SAS Address matches the SAS Address
+ * for this port
+ */
+ scic_sds_phy_get_sas_address(sci_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(sci_port, sci_phy);
}
+ case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ status = scic_sds_port_set_phy(sci_port, sci_phy);
- return scic_sds_port_set_phy(port, phy);
-}
-
-/*
- * This method takes the struct scic_sds_port that is in a stopped state and handles
- * the remove phy request. In MPC mode the only time a phy can be removed from
- * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
- * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
- * be added to the port. SCI_SUCCESS if the phy is added to the port.
- */
-static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
-{
- return scic_sds_port_clear_phy(port, phy);
-}
-
-/*
- * ****************************************************************************
- * * READY STATE HANDLERS
- * **************************************************************************** */
+ if (status != SCI_SUCCESS)
+ return status;
-/*
- * ****************************************************************************
- * * RESETTING STATE HANDLERS
- * **************************************************************************** */
+ scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
+ sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
+ port_state_machine_change(sci_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
-/*
- * ****************************************************************************
- * * STOPPING STATE HANDLERS
- * **************************************************************************** */
+ return status;
+ case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
+ status = scic_sds_port_set_phy(sci_port, sci_phy);
-/*
- * This method takes the struct scic_sds_port that is in a stopping state and handles
- * the complete io request. Should the request count reach 0 then the port
- * object will transition to the stopped state. enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
- struct scic_sds_port *sci_port,
- struct scic_sds_remote_device *device,
- struct scic_sds_request *io_request)
-{
- scic_sds_port_decrement_request_count(sci_port);
+ if (status != SCI_SUCCESS)
+ return status;
+ scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
- if (sci_port->started_request_count == 0) {
- sci_base_state_machine_change_state(&sci_port->state_machine,
- SCI_BASE_PORT_STATE_STOPPED);
+ /* Re-enter the configuring state since this may be the last phy in
+ * the port.
+ */
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
+ return SCI_SUCCESS;
+ default:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
}
-
- return SCI_SUCCESS;
}
-/*
- * ****************************************************************************
- * * RESETTING STATE HANDLERS
- * **************************************************************************** */
-
/**
+ * scic_sds_port_remove_phy() -
+ * @sci_port: This parameter specifies the port in which the phy will be added.
+ * @sci_phy: This parameter is the phy which is to be added to the port.
*
- * @port: This is the port object which is being requested to stop.
- *
- * This method will stop a failed port. This causes a transition to the
- * stopping state. enum sci_status SCI_SUCCESS
+ * This method will remove the PHY from the selected PORT. This method returns
+ * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
+ * other status is a failure to add the phy to the port.
*/
-static enum sci_status scic_sds_port_reset_state_stop_handler(
- struct scic_sds_port *port)
+enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
+ struct scic_sds_phy *sci_phy)
{
- sci_base_state_machine_change_state(
- &port->state_machine,
- SCI_BASE_PORT_STATE_STOPPING
- );
+ enum sci_status status;
+ enum scic_sds_port_states state;
+
+ state = sci_port->state_machine.current_state_id;
+
+ switch (state) {
+ case SCI_BASE_PORT_STATE_STOPPED:
+ return scic_sds_port_clear_phy(sci_port, sci_phy);
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ status = scic_sds_port_clear_phy(sci_port, sci_phy);
+ if (status != SCI_SUCCESS)
+ return status;
+
+ scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
+ sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
+ return SCI_SUCCESS;
+ case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
+ status = scic_sds_port_clear_phy(sci_port, sci_phy);
- return SCI_SUCCESS;
+ if (status != SCI_SUCCESS)
+ return status;
+ scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
+
+ /* Re-enter the configuring state since this may be the last phy in
+ * the port
+ */
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
+ return SCI_SUCCESS;
+ default:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ }
}
-/*
- * This method will transition a failed port to its ready state. The port
- * failed because a hard reset request timed out but at some time later one or
- * more phys in the port became ready. enum sci_status SCI_SUCCESS
- */
-static void scic_sds_port_reset_state_link_up_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
+enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
+ struct scic_sds_phy *sci_phy)
{
- /*
- * / @todo We should make sure that the phy that has gone link up is the same
- * / one on which we sent the reset. It is possible that the phy on
- * / which we sent the reset is not the one that has gone link up and we
- * / want to make sure that phy being reset comes back. Consider the
- * / case where a reset is sent but before the hardware processes the
- * / reset it get a link up on the port because of a hot plug event.
- * / because of the reset request this phy will go link down almost
- * / immediately. */
+ enum scic_sds_port_states state;
- /*
- * In the resetting state we don't notify the user regarding
- * link up and link down notifications. */
- scic_sds_port_general_link_up_handler(port, phy, false);
+ state = sci_port->state_machine.current_state_id;
+ switch (state) {
+ case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
+ /* Since this is the first phy going link up for the port we
+ * can just enable it and continue
+ */
+ scic_sds_port_activate_phy(sci_port, sci_phy, true);
+
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
+ return SCI_SUCCESS;
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
+ return SCI_SUCCESS;
+ case SCI_BASE_PORT_STATE_RESETTING:
+ /* TODO We should make sure that the phy that has gone
+ * link up is the same one on which we sent the reset. It is
+ * possible that the phy on which we sent the reset is not the
+ * one that has gone link up and we want to make sure that
+ * phy being reset comes back. Consider the case where a
+ * reset is sent but before the hardware processes the reset it
+ * get a link up on the port because of a hot plug event.
+ * because of the reset request this phy will go link down
+ * almost immediately.
+ */
+
+ /* In the resetting state we don't notify the user regarding
+ * link up and link down notifications.
+ */
+ scic_sds_port_general_link_up_handler(sci_port, sci_phy, false);
+ return SCI_SUCCESS;
+ default:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ }
}
-/*
- * This method process link down notifications that occur during a port reset
- * operation. Link downs can occur during the reset operation. enum sci_status
- * SCI_SUCCESS
- */
-static void scic_sds_port_reset_state_link_down_handler(
- struct scic_sds_port *port,
- struct scic_sds_phy *phy)
+enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
+ struct scic_sds_phy *sci_phy)
{
- /*
- * In the resetting state we don't notify the user regarding
- * link up and link down notifications. */
- scic_sds_port_deactivate_phy(port, phy, false);
+ enum scic_sds_port_states state;
+
+ state = sci_port->state_machine.current_state_id;
+ switch (state) {
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
+
+ /* If there are no active phys left in the port, then
+ * transition the port to the WAITING state until such time
+ * as a phy goes link up
+ */
+ if (sci_port->active_phy_mask == 0)
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
+ return SCI_SUCCESS;
+ case SCI_BASE_PORT_STATE_RESETTING:
+ /* In the resetting state we don't notify the user regarding
+ * link up and link down notifications. */
+ scic_sds_port_deactivate_phy(sci_port, sci_phy, false);
+ return SCI_SUCCESS;
+ default:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ }
}
-static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[] = {
- [SCI_BASE_PORT_STATE_STOPPED] = {
- .start_handler = scic_sds_port_stopped_state_start_handler,
- .stop_handler = scic_sds_port_stopped_state_stop_handler,
- .destruct_handler = scic_sds_port_stopped_state_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_stopped_state_add_phy_handler,
- .remove_phy_handler = scic_sds_port_stopped_state_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_default_link_up_handler,
- .link_down_handler = scic_sds_port_default_link_down_handler,
- .start_io_handler = scic_sds_port_default_start_io_handler,
- .complete_io_handler = scic_sds_port_default_complete_io_handler
- },
- [SCI_BASE_PORT_STATE_STOPPING] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_default_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_default_add_phy_handler,
- .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_default_link_up_handler,
- .link_down_handler = scic_sds_port_default_link_down_handler,
- .start_io_handler = scic_sds_port_default_start_io_handler,
- .complete_io_handler = scic_sds_port_stopping_state_complete_io_handler
- },
- [SCI_BASE_PORT_STATE_READY] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_default_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_default_add_phy_handler,
- .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_default_link_up_handler,
- .link_down_handler = scic_sds_port_default_link_down_handler,
- .start_io_handler = scic_sds_port_default_start_io_handler,
- .complete_io_handler = scic_sds_port_general_complete_io_handler
- },
- [SCI_BASE_PORT_STATE_RESETTING] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_reset_state_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_default_add_phy_handler,
- .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_reset_state_link_up_handler,
- .link_down_handler = scic_sds_port_reset_state_link_down_handler,
- .start_io_handler = scic_sds_port_default_start_io_handler,
- .complete_io_handler = scic_sds_port_general_complete_io_handler
- },
- [SCI_BASE_PORT_STATE_FAILED] = {
- .start_handler = scic_sds_port_default_start_handler,
- .stop_handler = scic_sds_port_default_stop_handler,
- .destruct_handler = scic_sds_port_default_destruct_handler,
- .reset_handler = scic_sds_port_default_reset_handler,
- .add_phy_handler = scic_sds_port_default_add_phy_handler,
- .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
- .frame_handler = scic_sds_port_default_frame_handler,
- .event_handler = scic_sds_port_default_event_handler,
- .link_up_handler = scic_sds_port_default_link_up_handler,
- .link_down_handler = scic_sds_port_default_link_down_handler,
- .start_io_handler = scic_sds_port_default_start_io_handler,
- .complete_io_handler = scic_sds_port_general_complete_io_handler
+enum sci_status scic_sds_port_start_io(struct scic_sds_port *sci_port,
+ struct scic_sds_remote_device *sci_dev,
+ struct scic_sds_request *sci_req)
+{
+ enum scic_sds_port_states state;
+
+ state = sci_port->state_machine.current_state_id;
+ switch (state) {
+ case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
+ return SCI_FAILURE_INVALID_STATE;
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ sci_port->started_request_count++;
+ return SCI_SUCCESS;
+ default:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
}
-};
+}
-/*
- * ******************************************************************************
- * * PORT STATE PRIVATE METHODS
- * ****************************************************************************** */
+enum sci_status scic_sds_port_complete_io(struct scic_sds_port *sci_port,
+ struct scic_sds_remote_device *sci_dev,
+ struct scic_sds_request *sci_req)
+{
+ enum scic_sds_port_states state;
+
+ state = sci_port->state_machine.current_state_id;
+ switch (state) {
+ case SCI_BASE_PORT_STATE_STOPPED:
+ dev_warn(sciport_to_dev(sci_port),
+ "%s: in wrong state: %d\n", __func__, state);
+ return SCI_FAILURE_INVALID_STATE;
+ case SCI_BASE_PORT_STATE_STOPPING:
+ scic_sds_port_decrement_request_count(sci_port);
+
+ if (sci_port->started_request_count == 0)
+ port_state_machine_change(sci_port,
+ SCI_BASE_PORT_STATE_STOPPED);
+ break;
+ case SCI_BASE_PORT_STATE_READY:
+ case SCI_BASE_PORT_STATE_RESETTING:
+ case SCI_BASE_PORT_STATE_FAILED:
+ case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
+ case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
+ scic_sds_port_decrement_request_count(sci_port);
+ break;
+ case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
+ scic_sds_port_decrement_request_count(sci_port);
+ if (sci_port->started_request_count == 0) {
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
+ }
+ break;
+ }
+ return SCI_SUCCESS;
+}
/**
*
scic_sds_controller_post_request(scic, command);
}
-static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
-{
- struct scic_sds_controller *scic = sci_port->owning_controller;
- u8 phys_index = sci_port->physical_port_index;
- union scu_remote_node_context *rnc;
- u16 rni = sci_port->reserved_rni;
- u32 command;
-
- rnc = &scic->remote_node_context_table[rni];
-
- rnc->ssp.is_valid = false;
-
- /* ensure the preceding tc abort request has reached the
- * controller and give it ample time to act before posting the rnc
- * invalidate
- */
- readl(&scic->smu_registers->interrupt_status); /* flush */
- udelay(10);
-
- command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
- phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
-
- scic_sds_controller_post_request(scic, command);
-}
-
-/*
- * ******************************************************************************
- * * PORT STATE METHODS
- * ****************************************************************************** */
-
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
- * state handlers for the struct scic_sds_port object and disables the port task
- * scheduler in the hardware. none
- */
static void scic_sds_port_stopped_state_enter(void *object)
{
struct scic_sds_port *sci_port = object;
- scic_sds_port_set_base_state_handlers(
- sci_port, SCI_BASE_PORT_STATE_STOPPED
- );
-
- if (
- SCI_BASE_PORT_STATE_STOPPING
- == sci_port->state_machine.previous_state_id
- ) {
+ if (sci_port->state_machine.previous_state_id == SCI_BASE_PORT_STATE_STOPPING) {
/*
* If we enter this state becasuse of a request to stop
* the port then we want to disable the hardwares port
}
}
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
- * port task scheduler. none
- */
static void scic_sds_port_stopped_state_exit(void *object)
{
struct scic_sds_port *sci_port = object;
scic_sds_port_enable_port_task_scheduler(sci_port);
}
-/**
- * scic_sds_port_ready_state_enter -
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
- * handlers for the struct scic_sds_port object, reports the port object as
- * not ready and starts the ready substate machine. none
- */
static void scic_sds_port_ready_state_enter(void *object)
{
struct scic_sds_port *sci_port = object;
struct isci_port *iport = sci_port_to_iport(sci_port);
u32 prev_state;
- /* Put the ready state handlers in place though they will not be there long */
- scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
-
prev_state = sci_port->state_machine.previous_state_id;
if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
isci_port_hard_reset_complete(iport, SCI_SUCCESS);
scic_sds_port_post_dummy_remote_node(sci_port);
/* Start the ready substate machine */
- sci_base_state_machine_start(&sci_port->ready_substate_machine);
-}
-
-static void scic_sds_port_ready_state_exit(void *object)
-{
- struct scic_sds_port *sci_port = object;
-
- sci_base_state_machine_stop(&sci_port->ready_substate_machine);
- scic_sds_port_invalidate_dummy_remote_node(sci_port);
-}
-
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
- * state handlers for the struct scic_sds_port object. none
- */
-static void scic_sds_port_resetting_state_enter(void *object)
-{
- struct scic_sds_port *sci_port = object;
-
- scic_sds_port_set_base_state_handlers(
- sci_port, SCI_BASE_PORT_STATE_RESETTING
- );
+ port_state_machine_change(sci_port,
+ SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
}
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This function will perform the actions required by the
- * struct scic_sds_port on
- * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
- */
-static inline void scic_sds_port_resetting_state_exit(void *object)
+static void scic_sds_port_resetting_state_exit(void *object)
{
struct scic_sds_port *sci_port = object;
isci_timer_stop(sci_port->timer_handle);
}
-/**
- *
- * @object: This is the void object which is cast to a
- * struct scic_sds_port object.
- *
- * This method will perform the actions required by the struct scic_sds_port on
- * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
- * state handlers for the struct scic_sds_port object. none
- */
-static void scic_sds_port_stopping_state_enter(void *object)
-{
- struct scic_sds_port *sci_port = object;
-
- scic_sds_port_set_base_state_handlers(
- sci_port, SCI_BASE_PORT_STATE_STOPPING
- );
-}
-
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This function will perform the actions required by the
- * struct scic_sds_port on
- * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
- */
-static inline void
-scic_sds_port_stopping_state_exit(void *object)
+static void scic_sds_port_stopping_state_exit(void *object)
{
struct scic_sds_port *sci_port = object;
scic_sds_port_destroy_dummy_resources(sci_port);
}
-/**
- *
- * @object: This is the object which is cast to a struct scic_sds_port object.
- *
- * This function will perform the actions required by the
- * struct scic_sds_port on
- * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
- * state handlers for the struct scic_sds_port object. none
- */
static void scic_sds_port_failed_state_enter(void *object)
{
struct scic_sds_port *sci_port = object;
struct isci_port *iport = sci_port_to_iport(sci_port);
- scic_sds_port_set_base_state_handlers(sci_port,
- SCI_BASE_PORT_STATE_FAILED);
-
isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
}
.exit_state = scic_sds_port_stopped_state_exit
},
[SCI_BASE_PORT_STATE_STOPPING] = {
- .enter_state = scic_sds_port_stopping_state_enter,
.exit_state = scic_sds_port_stopping_state_exit
},
[SCI_BASE_PORT_STATE_READY] = {
.enter_state = scic_sds_port_ready_state_enter,
- .exit_state = scic_sds_port_ready_state_exit
+ },
+ [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
+ .enter_state = scic_sds_port_ready_substate_waiting_enter,
+ },
+ [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
+ .enter_state = scic_sds_port_ready_substate_operational_enter,
+ .exit_state = scic_sds_port_ready_substate_operational_exit
+ },
+ [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
+ .enter_state = scic_sds_port_ready_substate_configuring_enter,
+ .exit_state = scic_sds_port_ready_substate_configuring_exit
},
[SCI_BASE_PORT_STATE_RESETTING] = {
- .enter_state = scic_sds_port_resetting_state_enter,
.exit_state = scic_sds_port_resetting_state_exit
},
[SCI_BASE_PORT_STATE_FAILED] = {
sci_base_state_machine_start(&sci_port->state_machine);
- sci_base_state_machine_construct(&sci_port->ready_substate_machine,
- sci_port,
- scic_sds_port_ready_substate_table,
- SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
-
sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
sci_port->physical_port_index = index;
sci_port->active_phy_mask = 0;
+ sci_port->ready_exit = false;
sci_port->owning_controller = scic;