Skip to content

Commit

Permalink
isci: additional state machine cleanup
Browse files Browse the repository at this point in the history
Additional state machine cleanups:

 o Remove static functions sci_state_machine_exit_state() and
   sci_state_machine_enter_state()
 o Combines sci_base_state_machine_construct() and
   sci_base_state_machine_start() into a single function,
   sci_init_sm()
 o Remove sci_base_state_machine_stop() which is unused.
 o Kill state_machine.[ch]

Signed-off-by: Edmund Nadolski <edmund.nadolski@intel.com>
[fixed too large to inline functions]
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
  • Loading branch information
edmundna authored and djbw committed Jul 3, 2011
1 parent e301370 commit 12ef654
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 294 deletions.
1 change: 0 additions & 1 deletion drivers/scsi/isci/Makefile
Expand Up @@ -2,7 +2,6 @@ obj-$(CONFIG_SCSI_ISCI) += isci.o
isci-objs := init.o phy.o request.o sata.o \
remote_device.o port.o \
host.o task.o probe_roms.o \
state_machine.o \
remote_node_context.o \
remote_node_table.o \
unsolicited_frame_control.o \
Expand Down
39 changes: 34 additions & 5 deletions drivers/scsi/isci/host.c
Expand Up @@ -197,6 +197,39 @@
*/
#define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000)

/* Init the state machine and call the state entry function (if any) */
void sci_init_sm(struct sci_base_state_machine *sm,
const struct sci_base_state *state_table, u32 initial_state)
{
sci_state_transition_t handler;

sm->initial_state_id = initial_state;
sm->previous_state_id = initial_state;
sm->current_state_id = initial_state;
sm->state_table = state_table;

handler = sm->state_table[initial_state].enter_state;
if (handler)
handler(sm);
}

/* Call the state exit fn, update the current state, call the state entry fn */
void sci_change_state(struct sci_base_state_machine *sm, u32 next_state)
{
sci_state_transition_t handler;

handler = sm->state_table[sm->current_state_id].exit_state;
if (handler)
handler(sm);

sm->previous_state_id = sm->current_state_id;
sm->current_state_id = next_state;

handler = sm->state_table[sm->current_state_id].enter_state;
if (handler)
handler(sm);
}

static bool scic_sds_controller_completion_queue_has_entries(
struct scic_sds_controller *scic)
{
Expand Down Expand Up @@ -1807,11 +1840,7 @@ static enum sci_status scic_controller_construct(struct scic_sds_controller *sci
struct isci_host *ihost = scic_to_ihost(scic);
u8 i;

sci_base_state_machine_construct(&scic->sm,
scic_sds_controller_state_table,
SCIC_INITIAL);

sci_base_state_machine_start(&scic->sm);
sci_init_sm(&scic->sm, scic_sds_controller_state_table, SCIC_INITIAL);

scic->scu_registers = scu_base;
scic->smu_registers = smu_base;
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/isci/host.h
Expand Up @@ -58,7 +58,7 @@
#include "remote_device.h"
#include "phy.h"
#include "pool.h"
#include "state_machine.h"
#include "isci.h"
#include "remote_node_table.h"
#include "registers.h"
#include "scu_unsolicited_frame.h"
Expand Down
19 changes: 19 additions & 0 deletions drivers/scsi/isci/isci.h
Expand Up @@ -57,6 +57,7 @@
#define __ISCI_H__

#include <linux/interrupt.h>
#include <linux/types.h>

#define DRV_NAME "isci"
#define SCI_PCI_BAR_COUNT 2
Expand Down Expand Up @@ -584,4 +585,22 @@ static inline void sci_del_timer(struct sci_timer *tmr)
del_timer(&tmr->timer);
}

struct sci_base_state_machine {
const struct sci_base_state *state_table;
u32 initial_state_id;
u32 current_state_id;
u32 previous_state_id;
};

typedef void (*sci_state_transition_t)(struct sci_base_state_machine *sm);

struct sci_base_state {
sci_state_transition_t enter_state; /* Called on state entry */
sci_state_transition_t exit_state; /* Called on state exit */
};

extern void sci_init_sm(struct sci_base_state_machine *sm,
const struct sci_base_state *state_table,
u32 initial_state);
extern void sci_change_state(struct sci_base_state_machine *sm, u32 next_state);
#endif /* __ISCI_H__ */
6 changes: 1 addition & 5 deletions drivers/scsi/isci/phy.c
Expand Up @@ -1294,11 +1294,7 @@ static const struct sci_base_state scic_sds_phy_state_table[] = {
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->sm,
scic_sds_phy_state_table,
SCI_PHY_INITIAL);

sci_base_state_machine_start(&sci_phy->sm);
sci_init_sm(&sci_phy->sm, scic_sds_phy_state_table, SCI_PHY_INITIAL);

/* Copy the rest of the input data to our locals */
sci_phy->owning_port = owning_port;
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/isci/phy.h
Expand Up @@ -57,7 +57,7 @@

#include <scsi/sas.h>
#include <scsi/libsas.h>
#include "state_machine.h"
#include "isci.h"
#include "sas.h"

/* This is the timeout value for the SATA phy to wait for a SIGNATURE FIS
Expand Down
6 changes: 1 addition & 5 deletions drivers/scsi/isci/port.c
Expand Up @@ -1807,11 +1807,7 @@ static const struct sci_base_state scic_sds_port_state_table[] = {
void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
struct scic_sds_controller *scic)
{
sci_base_state_machine_construct(&sci_port->sm,
scic_sds_port_state_table,
SCI_PORT_STOPPED);

sci_base_state_machine_start(&sci_port->sm);
sci_init_sm(&sci_port->sm, scic_sds_port_state_table, SCI_PORT_STOPPED);

sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
sci_port->physical_port_index = index;
Expand Down
6 changes: 1 addition & 5 deletions drivers/scsi/isci/remote_device.c
Expand Up @@ -1095,11 +1095,7 @@ static void scic_remote_device_construct(struct scic_sds_port *sci_port,
sci_dev->owning_port = sci_port;
sci_dev->started_request_count = 0;

sci_base_state_machine_construct(&sci_dev->sm,
scic_sds_remote_device_state_table,
SCI_DEV_INITIAL);

sci_base_state_machine_start(&sci_dev->sm);
sci_init_sm(&sci_dev->sm, scic_sds_remote_device_state_table, SCI_DEV_INITIAL);

scic_sds_remote_node_context_construct(&sci_dev->rnc,
SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX);
Expand Down
8 changes: 2 additions & 6 deletions drivers/scsi/isci/remote_node_context.c
Expand Up @@ -54,7 +54,7 @@
*/

#include "host.h"
#include "state_machine.h"
#include "isci.h"
#include "remote_device.h"
#include "remote_node_context.h"
#include "scu_event_codes.h"
Expand Down Expand Up @@ -373,11 +373,7 @@ void scic_sds_remote_node_context_construct(struct scic_sds_remote_node_context
rnc->remote_node_index = remote_node_index;
rnc->destination_state = SCIC_SDS_REMOTE_NODE_DESTINATION_STATE_UNSPECIFIED;

sci_base_state_machine_construct(&rnc->sm,
scic_sds_remote_node_context_state_table,
SCI_RNC_INITIAL);

sci_base_state_machine_start(&rnc->sm);
sci_init_sm(&rnc->sm, scic_sds_remote_node_context_state_table, SCI_RNC_INITIAL);
}

enum sci_status scic_sds_remote_node_context_event_handler(struct scic_sds_remote_node_context *sci_rnc,
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/isci/remote_node_context.h
Expand Up @@ -64,7 +64,7 @@
*
*/

#include "state_machine.h"
#include "isci.h"

/**
*
Expand Down
5 changes: 1 addition & 4 deletions drivers/scsi/isci/request.c
Expand Up @@ -3077,10 +3077,7 @@ scic_sds_general_request_construct(struct scic_sds_controller *scic,
u16 io_tag,
struct scic_sds_request *sci_req)
{
sci_base_state_machine_construct(&sci_req->sm,
scic_sds_request_state_table,
SCI_REQ_INIT);
sci_base_state_machine_start(&sci_req->sm);
sci_init_sm(&sci_req->sm, scic_sds_request_state_table, SCI_REQ_INIT);

sci_req->io_tag = io_tag;
sci_req->owning_controller = scic;
Expand Down
138 changes: 0 additions & 138 deletions drivers/scsi/isci/state_machine.c

This file was deleted.

0 comments on commit 12ef654

Please sign in to comment.