Skip to content

Commit

Permalink
isci: add some type safety to the state machine interface
Browse files Browse the repository at this point in the history
Now that any given object type only has one state_machine we can use
container_of() to get back to the given state machine owner.

Reported-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
  • Loading branch information
djbw committed Jul 3, 2011
1 parent f34d9e5 commit 9269e0e
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 194 deletions.
32 changes: 16 additions & 16 deletions drivers/scsi/isci/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,17 +1404,17 @@ static void isci_user_parameters_get(
u->max_number_concurrent_device_spin_up = max_concurr_spinup;
}

static void scic_sds_controller_initial_state_enter(void *object)
static void scic_sds_controller_initial_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

sci_base_state_machine_change_state(&scic->state_machine,
SCI_BASE_CONTROLLER_STATE_RESET);
}

static inline void scic_sds_controller_starting_state_exit(void *object)
static inline void scic_sds_controller_starting_state_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

isci_timer_stop(scic->timeout_timer);
}
Expand Down Expand Up @@ -1539,17 +1539,17 @@ static enum sci_status scic_controller_set_interrupt_coalescence(
}


static void scic_sds_controller_ready_state_enter(void *object)
static void scic_sds_controller_ready_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

/* set the default interrupt coalescence number and timeout value. */
scic_controller_set_interrupt_coalescence(scic, 0x10, 250);
}

static void scic_sds_controller_ready_state_exit(void *object)
static void scic_sds_controller_ready_state_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

/* disable interrupt coalescence. */
scic_controller_set_interrupt_coalescence(scic, 0, 0);
Expand Down Expand Up @@ -1638,19 +1638,19 @@ static enum sci_status scic_sds_controller_stop_devices(struct scic_sds_controll
return status;
}

static void scic_sds_controller_stopping_state_enter(void *object)
static void scic_sds_controller_stopping_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

/* Stop all of the components for this controller */
scic_sds_controller_stop_phys(scic);
scic_sds_controller_stop_ports(scic);
scic_sds_controller_stop_devices(scic);
}

static void scic_sds_controller_stopping_state_exit(void *object)
static void scic_sds_controller_stopping_state_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

isci_timer_stop(scic->timeout_timer);
}
Expand Down Expand Up @@ -1679,9 +1679,9 @@ static void scic_sds_controller_reset_hardware(struct scic_sds_controller *scic)
writel(0, &scic->scu_registers->sdma.unsolicited_frame_get_pointer);
}

static void scic_sds_controller_resetting_state_enter(void *object)
static void scic_sds_controller_resetting_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_controller *scic = object;
struct scic_sds_controller *scic = container_of(sm, typeof(*scic), state_machine);

scic_sds_controller_reset_hardware(scic);
sci_base_state_machine_change_state(&scic->state_machine,
Expand Down Expand Up @@ -1785,8 +1785,8 @@ static enum sci_status scic_controller_construct(struct scic_sds_controller *sci
u8 i;

sci_base_state_machine_construct(&scic->state_machine,
scic, scic_sds_controller_state_table,
SCI_BASE_CONTROLLER_STATE_INITIAL);
scic_sds_controller_state_table,
SCI_BASE_CONTROLLER_STATE_INITIAL);

sci_base_state_machine_start(&scic->state_machine);

Expand Down
70 changes: 34 additions & 36 deletions drivers/scsi/isci/phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,81 +1026,80 @@ enum sci_status scic_sds_phy_frame_handler(struct scic_sds_phy *sci_phy,

}

static void scic_sds_phy_starting_initial_substate_enter(void *object)
static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

/* This is just an temporary state go off to the starting state */
sci_base_state_machine_change_state(&sci_phy->state_machine,
SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
}

static void scic_sds_phy_starting_await_sas_power_substate_enter(void *object)
static void scic_sds_phy_starting_await_sas_power_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);
struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;

scic_sds_controller_power_control_queue_insert(scic, sci_phy);
}

static void scic_sds_phy_starting_await_sas_power_substate_exit(void *object)
static void scic_sds_phy_starting_await_sas_power_substate_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);
struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;

scic_sds_controller_power_control_queue_remove(scic, sci_phy);
}

static void scic_sds_phy_starting_await_sata_power_substate_enter(void *object)
static void scic_sds_phy_starting_await_sata_power_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);
struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;

scic_sds_controller_power_control_queue_insert(scic, sci_phy);
}

static void scic_sds_phy_starting_await_sata_power_substate_exit(void *object)
static void scic_sds_phy_starting_await_sata_power_substate_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);
struct scic_sds_controller *scic = sci_phy->owning_port->owning_controller;

scic_sds_controller_power_control_queue_remove(scic, sci_phy);
}

static void scic_sds_phy_starting_await_sata_phy_substate_enter(void *object)
static void scic_sds_phy_starting_await_sata_phy_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

isci_timer_start(sci_phy->sata_timeout_timer,
SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
}

static void scic_sds_phy_starting_await_sata_phy_substate_exit(void *object)
static void scic_sds_phy_starting_await_sata_phy_substate_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

isci_timer_stop(sci_phy->sata_timeout_timer);
}

static void scic_sds_phy_starting_await_sata_speed_substate_enter(void *object)
static void scic_sds_phy_starting_await_sata_speed_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

isci_timer_start(sci_phy->sata_timeout_timer,
SCIC_SDS_SATA_LINK_TRAINING_TIMEOUT);
}

static void scic_sds_phy_starting_await_sata_speed_substate_exit(
void *object)
static void scic_sds_phy_starting_await_sata_speed_substate_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

isci_timer_stop(sci_phy->sata_timeout_timer);
}

static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

if (scic_sds_port_link_detected(sci_phy->owning_port, sci_phy)) {

Expand All @@ -1118,16 +1117,16 @@ static void scic_sds_phy_starting_await_sig_fis_uf_substate_enter(void *object)
sci_phy->is_in_link_training = false;
}

static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(void *object)
static void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

isci_timer_stop(sci_phy->sata_timeout_timer);
}

static void scic_sds_phy_starting_final_substate_enter(void *object)
static void scic_sds_phy_starting_final_substate_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

/* State machine has run to completion so exit out and change
* the base state machine to the ready state
Expand Down Expand Up @@ -1217,9 +1216,9 @@ static void scu_link_layer_tx_hard_reset(
&sci_phy->link_layer_registers->phy_configuration);
}

static void scic_sds_phy_stopped_state_enter(void *object)
static void scic_sds_phy_stopped_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);
struct scic_sds_port *sci_port = sci_phy->owning_port;
struct scic_sds_controller *scic = sci_port->owning_controller;
struct isci_host *ihost = scic_to_ihost(scic);
Expand All @@ -1242,9 +1241,9 @@ static void scic_sds_phy_stopped_state_enter(void *object)
sci_phy);
}

static void scic_sds_phy_starting_state_enter(void *object)
static void scic_sds_phy_starting_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

scu_link_layer_stop_protocol_engine(sci_phy);
scu_link_layer_start_oob(sci_phy);
Expand All @@ -1262,26 +1261,26 @@ static void scic_sds_phy_starting_state_enter(void *object)
SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
}

static void scic_sds_phy_ready_state_enter(void *object)
static void scic_sds_phy_ready_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

scic_sds_controller_link_up(scic_sds_phy_get_controller(sci_phy),
phy_get_non_dummy_port(sci_phy),
sci_phy);

}

static void scic_sds_phy_ready_state_exit(void *object)
static void scic_sds_phy_ready_state_exit(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

scic_sds_phy_suspend(sci_phy);
}

static void scic_sds_phy_resetting_state_enter(void *object)
static void scic_sds_phy_resetting_state_enter(struct sci_base_state_machine *sm)
{
struct scic_sds_phy *sci_phy = object;
struct scic_sds_phy *sci_phy = container_of(sm, typeof(*sci_phy), state_machine);

/* The phy is being reset, therefore deactivate it from the port. In
* the resetting state we don't notify the user regarding link up and
Expand Down Expand Up @@ -1351,7 +1350,6 @@ void scic_sds_phy_construct(struct scic_sds_phy *sci_phy,
struct scic_sds_port *owning_port, u8 phy_index)
{
sci_base_state_machine_construct(&sci_phy->state_machine,
sci_phy,
scic_sds_phy_state_table,
SCI_BASE_PHY_STATE_INITIAL);

Expand Down
Loading

0 comments on commit 9269e0e

Please sign in to comment.