isci: kill some long macros
authorDan Williams <dan.j.williams@intel.com>
Sat, 26 Mar 2011 23:30:35 +0000 (16:30 -0700)
committerDan Williams <dan.j.williams@intel.com>
Sun, 3 Jul 2011 11:00:36 +0000 (04:00 -0700)
Delete some macros that are longer to type than the open coded operation
that they perform.

scic_sds_phy_get_base_state_machine
scic_sds_phy_get_starting_substate_machine
scic_sds_port_get_base_state_machine
scic_sds_port_get_ready_substate_machine
scic_sds_remote_device_get_base_state_machine
scic_sds_remote_device_get_ready_substate_machine
scic_sds_remote_node_context_set_remote_node_index
scic_sds_controller_get_base_state_machine

Also performs some collateral cleanups like killing casts that assume
structure member ordering, and consolidating a lot of duplicated default
handler code (the primary callers of the *_get_base_state_machine macros) via
a helper.

Reported-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/scsi/isci/core/scic_sds_controller.c
drivers/scsi/isci/core/scic_sds_controller.h
drivers/scsi/isci/core/scic_sds_phy.c
drivers/scsi/isci/core/scic_sds_phy.h
drivers/scsi/isci/core/scic_sds_port.c
drivers/scsi/isci/core/scic_sds_port.h
drivers/scsi/isci/core/scic_sds_remote_device.c
drivers/scsi/isci/core/scic_sds_remote_device.h
drivers/scsi/isci/core/scic_sds_remote_node_context.h

index eaaa4cc89a853d70f5bf1461bae60cca3e5adfa5..7d25a0aafb665f6f43db1ab6a45d3e0b3c44a2df 100644 (file)
@@ -739,9 +739,8 @@ static void scic_sds_controller_transition_to_ready(
                 * We move into the ready state, because some of the phys/ports
                 * may be up and operational.
                 */
-               sci_base_state_machine_change_state(
-                       scic_sds_controller_get_base_state_machine(scic),
-                       SCI_BASE_CONTROLLER_STATE_READY);
+               sci_base_state_machine_change_state(&scic->parent.state_machine,
+                                                   SCI_BASE_CONTROLLER_STATE_READY);
 
                isci_host_start_complete(ihost, status);
        }
@@ -751,18 +750,12 @@ void scic_sds_controller_timeout_handler(void *_scic)
 {
        struct scic_sds_controller *scic = _scic;
        struct isci_host *ihost = sci_object_get_association(scic);
-       enum sci_base_controller_states current_state;
-
-       current_state = sci_base_state_machine_get_state(
-               scic_sds_controller_get_base_state_machine(scic));
+       struct sci_base_state_machine *sm = &scic->parent.state_machine;
 
-       if (current_state == SCI_BASE_CONTROLLER_STATE_STARTING) {
-               scic_sds_controller_transition_to_ready(
-                       scic, SCI_FAILURE_TIMEOUT);
-       } else if (current_state == SCI_BASE_CONTROLLER_STATE_STOPPING) {
-               sci_base_state_machine_change_state(
-                       scic_sds_controller_get_base_state_machine(scic),
-                       SCI_BASE_CONTROLLER_STATE_FAILED);
+       if (sm->current_state_id == SCI_BASE_CONTROLLER_STATE_STARTING)
+               scic_sds_controller_transition_to_ready(scic, SCI_FAILURE_TIMEOUT);
+       else if (sm->current_state_id == SCI_BASE_CONTROLLER_STATE_STOPPING) {
+               sci_base_state_machine_change_state(sm, SCI_BASE_CONTROLLER_STATE_FAILED);
                isci_host_stop_complete(ihost, SCI_FAILURE_TIMEOUT);
        } else  /* / @todo Now what do we want to do in this case? */
                dev_err(scic_to_dev(scic),
@@ -1619,16 +1612,15 @@ void scic_sds_controller_error_handler(struct scic_sds_controller *scic)
                dev_err(scic_to_dev(scic), "%s: status: %#x\n", __func__,
                        interrupt_status);
 
-               sci_base_state_machine_change_state(
-                       scic_sds_controller_get_base_state_machine(scic),
-                       SCI_BASE_CONTROLLER_STATE_FAILED);
+               sci_base_state_machine_change_state(&scic->parent.state_machine,
+                                                   SCI_BASE_CONTROLLER_STATE_FAILED);
 
                return;
        }
 
-       /*
-        * If we dont process any completions I am not sure that we want to do this.
-        * We are in the middle of a hardware fault and should probably be reset. */
+       /* If we dont process any completions I am not sure that we want to do this.
+        * We are in the middle of a hardware fault and should probably be reset.
+        */
        SMU_IMR_WRITE(scic, 0x00000000);
 }
 
@@ -1655,12 +1647,8 @@ void scic_sds_controller_link_up(
        else
                dev_dbg(scic_to_dev(scic),
                        "%s: SCIC Controller linkup event from phy %d in "
-                       "unexpected state %d\n",
-                       __func__,
-                       sci_phy->phy_index,
-                       sci_base_state_machine_get_state(
-                               scic_sds_controller_get_base_state_machine(
-                                       scic)));
+                       "unexpected state %d\n", __func__, sci_phy->phy_index,
+                       state);
 }
 
 
@@ -2125,11 +2113,7 @@ enum sci_status scic_controller_initialize(
        else
                dev_warn(scic_to_dev(scic),
                         "%s: SCIC Controller initialize operation requested "
-                        "in invalid state %d\n",
-                        __func__,
-                        sci_base_state_machine_get_state(
-                                scic_sds_controller_get_base_state_machine(
-                                        scic)));
+                        "in invalid state %d\n",  __func__, state);
 
        return status;
 }
@@ -2180,11 +2164,7 @@ enum sci_status scic_controller_start(
        else
                dev_warn(scic_to_dev(scic),
                         "%s: SCIC Controller start operation requested in "
-                        "invalid state %d\n",
-                        __func__,
-                        sci_base_state_machine_get_state(
-                                scic_sds_controller_get_base_state_machine(
-                                        scic)));
+                        "invalid state %d\n", __func__, state);
 
        return status;
 }
@@ -2207,11 +2187,7 @@ enum sci_status scic_controller_stop(
        else
                dev_warn(scic_to_dev(scic),
                         "%s: SCIC Controller stop operation requested in "
-                        "invalid state %d\n",
-                        __func__,
-                        sci_base_state_machine_get_state(
-                                scic_sds_controller_get_base_state_machine(
-                                        scic)));
+                        "invalid state %d\n", __func__, state);
 
        return status;
 }
@@ -2233,11 +2209,7 @@ enum sci_status scic_controller_reset(
        else
                dev_warn(scic_to_dev(scic),
                         "%s: SCIC Controller reset operation requested in "
-                        "invalid state %d\n",
-                        __func__,
-                        sci_base_state_machine_get_state(
-                                scic_sds_controller_get_base_state_machine(
-                                        scic)));
+                        "invalid state %d\n",  __func__, state);
 
        return status;
 }
@@ -2765,128 +2737,57 @@ struct scic_sds_controller *scic_controller_alloc(struct device *dev)
        return devm_kzalloc(dev, sizeof(struct scic_sds_controller), GFP_KERNEL);
 }
 
-/*
- * *****************************************************************************
- * * DEFAULT STATE HANDLERS
- * ***************************************************************************** */
+static enum sci_status default_controller_handler(struct sci_base_controller *base_scic,
+                                                 const char *func)
+{
+       struct scic_sds_controller *scic = container_of(base_scic, typeof(*scic), parent);
+       u32 state = base_scic->state_machine.current_state_id;
+
+       dev_warn(scic_to_dev(scic), "%s: invalid state %d\n", func, state);
+
+       return SCI_FAILURE_INVALID_STATE;
+}
 
-/**
- *
- * @controller: This is struct sci_base_controller object which is cast into a
- *    struct scic_sds_controller object.
- * @remote_device: This is struct sci_base_remote_device which, if it was used, would
- *    be cast to a struct scic_sds_remote_device.
- * @io_request: This is the struct sci_base_request which, if it was used, would be
- *    cast to a SCIC_SDS_IO_REQUEST.
- * @io_tag: This is the IO tag to be assigned to the IO request or
- *    SCI_CONTROLLER_INVALID_IO_TAG.
- *
- * This method is called when the struct scic_sds_controller default start io/task
- * handler is in place. - Issue a warning message enum sci_status
- * SCI_FAILURE_INVALID_STATE
- */
 static enum sci_status scic_sds_controller_default_start_operation_handler(
-       struct sci_base_controller *controller,
+       struct sci_base_controller *base_scic,
        struct sci_base_remote_device *remote_device,
        struct sci_base_request *io_request,
        u16 io_tag)
 {
-       struct scic_sds_controller *this_controller;
-
-       this_controller = (struct scic_sds_controller *)controller;
-
-       dev_warn(scic_to_dev(this_controller),
-                "%s: SCIC Controller requested to start an io/task from "
-                "invalid state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_controller_get_base_state_machine(
-                                this_controller)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_controller_handler(base_scic, __func__);
 }
 
-/**
- *
- * @controller: This is struct sci_base_controller object which is cast into a
- *    struct scic_sds_controller object.
- * @remote_device: This is struct sci_base_remote_device which, if it was used, would
- *    be cast to a struct scic_sds_remote_device.
- * @io_request: This is the struct sci_base_request which, if it was used, would be
- *    cast to a SCIC_SDS_IO_REQUEST.
- *
- * This method is called when the struct scic_sds_controller default request handler
- * is in place. - Issue a warning message enum sci_status SCI_FAILURE_INVALID_STATE
- */
 static enum sci_status scic_sds_controller_default_request_handler(
-       struct sci_base_controller *controller,
+       struct sci_base_controller *base_scic,
        struct sci_base_remote_device *remote_device,
        struct sci_base_request *io_request)
 {
-       struct scic_sds_controller *this_controller;
-
-       this_controller = (struct scic_sds_controller *)controller;
-
-       dev_warn(scic_to_dev(this_controller),
-               "%s: SCIC Controller request operation from invalid state %d\n",
-               __func__,
-               sci_base_state_machine_get_state(
-                       scic_sds_controller_get_base_state_machine(
-                               this_controller)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_controller_handler(base_scic, __func__);
 }
 
-/*
- * *****************************************************************************
- * * GENERAL (COMMON) STATE HANDLERS
- * ***************************************************************************** */
-
-/**
- *
- * @controller: The struct sci_base_controller object which is cast into a
- *    struct scic_sds_controller object.
- *
- * This method is called when the struct scic_sds_controller is in the ready state
- * reset handler is in place. - Transition to
- * SCI_BASE_CONTROLLER_STATE_RESETTING enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_controller_general_reset_handler(
-       struct sci_base_controller *controller)
+static enum sci_status scic_sds_controller_general_reset_handler(struct sci_base_controller *base_scic)
 {
-       struct scic_sds_controller *this_controller;
-
-       this_controller = (struct scic_sds_controller *)controller;
-
-       /*
-        * The reset operation is not a graceful cleanup just perform the state
-        * transition. */
-       sci_base_state_machine_change_state(
-               scic_sds_controller_get_base_state_machine(this_controller),
-               SCI_BASE_CONTROLLER_STATE_RESETTING
-               );
+       /* The reset operation is not a graceful cleanup just perform the state
+        * transition.
+        */
+       sci_base_state_machine_change_state(&base_scic->state_machine,
+                                           SCI_BASE_CONTROLLER_STATE_RESETTING);
 
        return SCI_SUCCESS;
 }
 
-/*
- * *****************************************************************************
- * * RESET STATE HANDLERS
- * ***************************************************************************** */
-
 static enum sci_status scic_sds_controller_reset_state_initialize_handler(struct sci_base_controller *base_scic)
 {
+       struct sci_base_state_machine *sm = &base_scic->state_machine;
        enum sci_status result = SCI_SUCCESS;
        struct scic_sds_controller *scic;
        struct isci_host *ihost;
-       u32 index;
+       u32 index, state;
 
        scic = container_of(base_scic, typeof(*scic), parent);
        ihost = sci_object_get_association(scic);
 
-       sci_base_state_machine_change_state(
-               scic_sds_controller_get_base_state_machine(scic),
-               SCI_BASE_CONTROLLER_STATE_INITIALIZING);
+       sci_base_state_machine_change_state(sm, SCI_BASE_CONTROLLER_STATE_INITIALIZING);
 
        scic->timeout_timer = isci_timer_create(ihost,
                                                scic,
@@ -3028,13 +2929,10 @@ static enum sci_status scic_sds_controller_reset_state_initialize_handler(struct
 
        /* Advance the controller state machine */
        if (result == SCI_SUCCESS)
-               sci_base_state_machine_change_state(
-                       scic_sds_controller_get_base_state_machine(scic),
-                       SCI_BASE_CONTROLLER_STATE_INITIALIZED);
+               state = SCI_BASE_CONTROLLER_STATE_INITIALIZED;
        else
-               sci_base_state_machine_change_state(
-                       scic_sds_controller_get_base_state_machine(scic),
-                       SCI_BASE_CONTROLLER_STATE_FAILED);
+               state = SCI_BASE_CONTROLLER_STATE_FAILED;
+       sci_base_state_machine_change_state(sm, state);
 
        return result;
 }
@@ -3065,14 +2963,14 @@ static enum sci_status scic_sds_controller_reset_state_initialize_handler(struct
  * descriptor fields is invalid.
  */
 static enum sci_status scic_sds_controller_initialized_state_start_handler(
-       struct sci_base_controller *controller,
+       struct sci_base_controller *base_scic,
        u32 timeout)
 {
        u16 index;
        enum sci_status result;
        struct scic_sds_controller *scic;
 
-       scic = (struct scic_sds_controller *)controller;
+       scic = container_of(base_scic, typeof(*scic), parent);
 
        /*
         * Make sure that the SCI User filled in the memory descriptor
@@ -3135,9 +3033,8 @@ static enum sci_status scic_sds_controller_initialized_state_start_handler(
 
                isci_timer_start(scic->timeout_timer, timeout);
 
-               sci_base_state_machine_change_state(
-                       scic_sds_controller_get_base_state_machine(scic),
-                       SCI_BASE_CONTROLLER_STATE_STARTING);
+               sci_base_state_machine_change_state(&base_scic->state_machine,
+                                                   SCI_BASE_CONTROLLER_STATE_STARTING);
        }
 
        return result;
@@ -3197,33 +3094,15 @@ static void scic_sds_controller_starting_state_link_down_handler(
        /* scic_sds_port_link_down(port, phy); */
 }
 
-/*
- * *****************************************************************************
- * * READY STATE HANDLERS
- * ***************************************************************************** */
-
-/**
- *
- * @controller: The struct sci_base_controller object which is cast into a
- *    struct scic_sds_controller object.
- * @timeout: The timeout for when the stop operation should report a failure.
- *
- * This method is called when the struct scic_sds_controller is in the ready state
- * stop handler is called. - Start the timeout timer - Transition to
- * SCI_BASE_CONTROLLER_STATE_STOPPING. enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_controller_ready_state_stop_handler(
-       struct sci_base_controller *controller,
-       u32 timeout)
+static enum sci_status scic_sds_controller_ready_state_stop_handler(struct sci_base_controller *base_scic,
+                                                                   u32 timeout)
 {
-       struct scic_sds_controller *scic =
-               (struct scic_sds_controller *)controller;
+       struct scic_sds_controller *scic;
 
+       scic = container_of(base_scic, typeof(*scic), parent);
        isci_timer_start(scic->timeout_timer, timeout);
-
-       sci_base_state_machine_change_state(
-               scic_sds_controller_get_base_state_machine(scic),
-               SCI_BASE_CONTROLLER_STATE_STOPPING);
+       sci_base_state_machine_change_state(&base_scic->state_machine,
+                                           SCI_BASE_CONTROLLER_STATE_STOPPING);
 
        return SCI_SUCCESS;
 }
@@ -3749,33 +3628,16 @@ static inline void scic_sds_controller_stopping_state_exit(
        isci_timer_stop(scic->timeout_timer);
 }
 
-/**
- *
- * @object: This is the struct sci_base_object which is cast to a struct scic_sds_controller
- *    object.
- *
- * This method implements the actions taken by the struct scic_sds_controller on entry
- * to the SCI_BASE_CONTROLLER_STATE_RESETTING. - Set the state handlers to the
- * controllers resetting state. - Write to the SCU hardware reset register to
- * force a reset - Transition to the SCI_BASE_CONTROLLER_STATE_RESET none
- */
-static void scic_sds_controller_resetting_state_enter(
-       struct sci_base_object *object)
+static void scic_sds_controller_resetting_state_enter(struct sci_base_object *object)
 {
-       struct scic_sds_controller *this_controller;
-
-       this_controller = (struct scic_sds_controller *)object;
-
-       scic_sds_controller_reset_hardware(this_controller);
+       struct scic_sds_controller *scic;
 
-       sci_base_state_machine_change_state(
-               scic_sds_controller_get_base_state_machine(this_controller),
-               SCI_BASE_CONTROLLER_STATE_RESET
-               );
+       scic = container_of(object, typeof(*scic), parent.parent);
+       scic_sds_controller_reset_hardware(scic);
+       sci_base_state_machine_change_state(&scic->parent.state_machine,
+                                           SCI_BASE_CONTROLLER_STATE_RESET);
 }
 
-/* --------------------------------------------------------------------------- */
-
 const struct sci_base_state scic_sds_controller_state_table[] = {
        [SCI_BASE_CONTROLLER_STATE_INITIAL] = {
                .enter_state = scic_sds_controller_initial_state_enter,
@@ -3800,4 +3662,3 @@ const struct sci_base_state scic_sds_controller_state_table[] = {
        [SCI_BASE_CONTROLLER_STATE_STOPPED] = {},
        [SCI_BASE_CONTROLLER_STATE_FAILED] = {}
 };
-
index f426324bf3a9d07294e0d3d0ae81b0fc58b07551..aa2698bb7ca1580d5f9a547e8bba0858c1c4b37a 100644 (file)
@@ -420,15 +420,6 @@ extern const struct sci_base_state scic_sds_controller_state_table[];
                } \
        }
 
-/**
- * scic_sds_controller_get_base_state_machine() -
- *
- * This is a helper macro that gets the base state machine for the controller
- * object
- */
-#define scic_sds_controller_get_base_state_machine(this_controller) \
-       (&(this_controller)->parent.state_machine)
-
 /**
  * scic_sds_controller_get_port_configuration_agent() -
  *
index 225e67a9e7b1381f22ae6803d151d45f055283e0..e546e20f1ffd519ba41da961bc9c2046bfd7c440 100644 (file)
@@ -246,7 +246,7 @@ scic_sds_phy_link_layer_initialization(struct scic_sds_phy *sci_phy,
                                      0x1F4);
 
        /* We can exit the initial state to the stopped state */
-       sci_base_state_machine_change_state(scic_sds_phy_get_base_state_machine(sci_phy),
+       sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
                                            SCI_BASE_PHY_STATE_STOPPED);
 
        return SCI_SUCCESS;
@@ -267,13 +267,10 @@ void scic_sds_phy_sata_timeout(void *phy)
                 __func__,
                 sci_phy);
 
-       sci_base_state_machine_stop(
-               scic_sds_phy_get_starting_substate_machine(sci_phy));
+       sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
 
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_base_state_machine(sci_phy),
-               SCI_BASE_PHY_STATE_STARTING
-               );
+       sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                           SCI_BASE_PHY_STATE_STARTING);
 }
 
 /**
@@ -390,9 +387,8 @@ enum sci_status scic_sds_phy_initialize(
        /*
         * There is nothing that needs to be done in this state just
         * transition to the stopped state. */
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_base_state_machine(sci_phy),
-               SCI_BASE_PHY_STATE_STOPPED);
+       sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                           SCI_BASE_PHY_STATE_STOPPED);
 
        return SCI_SUCCESS;
 }
@@ -716,9 +712,9 @@ static void scic_sds_phy_start_sata_link_training(
 }
 
 /**
- * This method performs processing common to all protocols upon completion of
- *    link training.
- * @this_phy: This parameter specifies the phy object for which link training
+ * scic_sds_phy_complete_link_training - perform processing common to
+ *    all protocols upon completion of link training.
+ * @sci_phy: This parameter specifies the phy object for which link training
  *    has completed.
  * @max_link_rate: This parameter specifies the maximum link rate to be
  *    associated with this phy.
@@ -727,37 +723,25 @@ static void scic_sds_phy_start_sata_link_training(
  *
  */
 static void scic_sds_phy_complete_link_training(
-       struct scic_sds_phy *this_phy,
+       struct scic_sds_phy *sci_phy,
        enum sci_sas_link_rate max_link_rate,
        u32 next_state)
 {
-       this_phy->max_negotiated_speed = max_link_rate;
+       sci_phy->max_negotiated_speed = max_link_rate;
 
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_starting_substate_machine(this_phy), next_state
-               );
+       sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                           next_state);
 }
 
-/**
- *
- * @this_phy: The struct scic_sds_phy object to restart.
- *
- * This method restarts the struct scic_sds_phy objects base state machine in the
- * starting state from any starting substate. none
- */
 static void scic_sds_phy_restart_starting_state(
-       struct scic_sds_phy *this_phy)
+       struct scic_sds_phy *sci_phy)
 {
        /* Stop the current substate machine */
-       sci_base_state_machine_stop(
-               scic_sds_phy_get_starting_substate_machine(this_phy)
-               );
+       sci_base_state_machine_stop(&sci_phy->starting_substate_machine);
 
        /* Re-enter the base state machine starting state */
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_base_state_machine(this_phy),
-               SCI_BASE_PHY_STATE_STARTING
-               );
+       sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                           SCI_BASE_PHY_STATE_STARTING);
 }
 
 /* ****************************************************************************
@@ -1041,7 +1025,7 @@ static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_han
 }
 
 /**
- *
+ * scic_sds_phy_starting_substate_await_sata_phy_event_handler -
  * @phy: This struct scic_sds_phy object which has received an event.
  * @event_code: This is the event code which the phy object is to decode.
  *
@@ -1054,42 +1038,39 @@ static enum sci_status scic_sds_phy_starting_substate_await_sata_power_event_han
  * failure event SCI_FAILURE on any unexpected event notifation
  */
 static enum sci_status scic_sds_phy_starting_substate_await_sata_phy_event_handler(
-       struct scic_sds_phy *this_phy,
-       u32 event_code)
+       struct scic_sds_phy *sci_phy, u32 event_code)
 {
        u32 result = SCI_SUCCESS;
 
        switch (scu_get_event_code(event_code)) {
        case SCU_EVENT_LINK_FAILURE:
                /* Link failure change state back to the starting state */
-               scic_sds_phy_restart_starting_state(this_phy);
+               scic_sds_phy_restart_starting_state(sci_phy);
                break;
 
        case SCU_EVENT_SATA_SPINUP_HOLD:
-               /*
-                * These events might be received since we dont know how many may be in
-                * the completion queue while waiting for power */
+               /* These events might be received since we dont know how many may be in
+                * the completion queue while waiting for power
+                */
                break;
 
        case SCU_EVENT_SATA_PHY_DETECTED:
-               this_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
+               sci_phy->protocol = SCIC_SDS_PHY_PROTOCOL_SATA;
 
                /* We have received the SATA PHY notification change state */
-               sci_base_state_machine_change_state(
-                       scic_sds_phy_get_starting_substate_machine(this_phy),
-                       SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
-                       );
+               sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                                   SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
                break;
 
        case SCU_EVENT_SAS_PHY_DETECTED:
-               /*
-                * There has been a change in the phy type before OOB/SN for the
-                * SATA finished start down the SAS link traning path. */
-               scic_sds_phy_start_sas_link_training(this_phy);
+               /* There has been a change in the phy type before OOB/SN for the
+                * SATA finished start down the SAS link traning path.
+                */
+               scic_sds_phy_start_sas_link_training(sci_phy);
                break;
 
        default:
-               dev_warn(sciphy_to_dev(this_phy),
+               dev_warn(sciphy_to_dev(sci_phy),
                         "%s: PHY starting substate machine received "
                         "unexpected event_code %x\n",
                         __func__,
@@ -1182,7 +1163,7 @@ static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_han
 }
 
 /**
- *
+ * scic_sds_phy_starting_substate_await_sig_fis_event_handler -
  * @phy: This struct scic_sds_phy object which has received an event.
  * @event_code: This is the event code which the phy object is to decode.
  *
@@ -1196,27 +1177,24 @@ static enum sci_status scic_sds_phy_starting_substate_await_sata_speed_event_han
  * unexpected event notifation
  */
 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handler(
-       struct scic_sds_phy *this_phy,
-       u32 event_code)
+       struct scic_sds_phy *sci_phy, u32 event_code)
 {
        u32 result = SCI_SUCCESS;
 
        switch (scu_get_event_code(event_code)) {
        case SCU_EVENT_SATA_PHY_DETECTED:
                /* Backup the state machine */
-               sci_base_state_machine_change_state(
-                       scic_sds_phy_get_starting_substate_machine(this_phy),
-                       SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN
-                       );
+               sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                                   SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN);
                break;
 
        case SCU_EVENT_LINK_FAILURE:
                /* Link failure change state back to the starting state */
-               scic_sds_phy_restart_starting_state(this_phy);
+               scic_sds_phy_restart_starting_state(sci_phy);
                break;
 
        default:
-               dev_warn(sciphy_to_dev(this_phy),
+               dev_warn(sciphy_to_dev(sci_phy),
                         "%s: PHY starting substate machine received "
                         "unexpected event_code %x\n",
                         __func__,
@@ -1249,15 +1227,14 @@ static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_event_handle
  * unsolicted frame - release frame buffer enum sci_status SCI_SUCCESS
  */
 static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler(
-       struct scic_sds_phy *this_phy,
-       u32 frame_index)
+       struct scic_sds_phy *sci_phy, u32 frame_index)
 {
        enum sci_status result;
        u32 *frame_words;
        struct sci_sas_identify_address_frame *identify_frame;
 
        result = scic_sds_unsolicited_frame_control_get_header(
-               &(scic_sds_phy_get_controller(this_phy)->uf_control),
+               &(scic_sds_phy_get_controller(sci_phy)->uf_control),
                frame_index,
                (void **)&frame_words);
 
@@ -1269,49 +1246,43 @@ static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
        identify_frame = (struct sci_sas_identify_address_frame *)frame_words;
 
        if (identify_frame->address_frame_type == 0) {
-               /*
-                * Byte swap the rest of the frame so we can make
-                * a copy of the buffer */
+               u32 state;
+
+               /* Byte swap the rest of the frame so we can make
+                * a copy of the buffer
+                */
                frame_words[1] = SCIC_SWAP_DWORD(frame_words[1]);
                frame_words[2] = SCIC_SWAP_DWORD(frame_words[2]);
                frame_words[3] = SCIC_SWAP_DWORD(frame_words[3]);
                frame_words[4] = SCIC_SWAP_DWORD(frame_words[4]);
                frame_words[5] = SCIC_SWAP_DWORD(frame_words[5]);
 
-               memcpy(
-                       &this_phy->phy_type.sas.identify_address_frame_buffer,
+               memcpy(&sci_phy->phy_type.sas.identify_address_frame_buffer,
                        identify_frame,
-                       sizeof(struct sci_sas_identify_address_frame)
-                       );
+                       sizeof(struct sci_sas_identify_address_frame));
 
                if (identify_frame->protocols.u.bits.smp_target) {
-                       /*
-                        * We got the IAF for an expander PHY go to the final state since
-                        * there are no power requirements for expander phys. */
-                       sci_base_state_machine_change_state(
-                               scic_sds_phy_get_starting_substate_machine(this_phy),
-                               SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
-                               );
+                       /* We got the IAF for an expander PHY go to the final state since
+                        * there are no power requirements for expander phys.
+                        */
+                       state = SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL;
                } else {
                        /* We got the IAF we can now go to the await spinup semaphore state */
-                       sci_base_state_machine_change_state(
-                               scic_sds_phy_get_starting_substate_machine(this_phy),
-                               SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER
-                               );
+                       state = SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER;
                }
-
+               sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                                   state);
                result = SCI_SUCCESS;
        } else
-               dev_warn(sciphy_to_dev(this_phy),
+               dev_warn(sciphy_to_dev(sci_phy),
                        "%s: PHY starting substate machine received "
                        "unexpected frame id %x\n",
                        __func__,
                        frame_index);
 
        /* Regardless of the result release this frame since we are done with it */
-       scic_sds_controller_release_frame(
-               scic_sds_phy_get_controller(this_phy), frame_index
-               );
+       scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
+                                         frame_index);
 
        return result;
 }
@@ -1331,7 +1302,7 @@ static enum sci_status scic_sds_phy_starting_substate_await_iaf_uf_frame_handler
  * data
  */
 static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handler(
-       struct scic_sds_phy *this_phy,
+       struct scic_sds_phy *sci_phy,
        u32 frame_index)
 {
        enum sci_status result;
@@ -1340,7 +1311,7 @@ static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handle
        u32 *fis_frame_data;
 
        result = scic_sds_unsolicited_frame_control_get_header(
-               &(scic_sds_phy_get_controller(this_phy)->uf_control),
+               &(scic_sds_phy_get_controller(sci_phy)->uf_control),
                frame_index,
                (void **)&frame_words);
 
@@ -1350,40 +1321,33 @@ static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handle
 
        fis_frame_header = (struct sata_fis_header *)frame_words;
 
-       if (
-               (fis_frame_header->fis_type == SATA_FIS_TYPE_REGD2H)
-               && !(fis_frame_header->status & ATA_STATUS_REG_BSY_BIT)
-               ) {
+       if ((fis_frame_header->fis_type == SATA_FIS_TYPE_REGD2H) &&
+           !(fis_frame_header->status & ATA_STATUS_REG_BSY_BIT)) {
                scic_sds_unsolicited_frame_control_get_buffer(
-                       &(scic_sds_phy_get_controller(this_phy)->uf_control),
+                       &(scic_sds_phy_get_controller(sci_phy)->uf_control),
                        frame_index,
-                       (void **)&fis_frame_data
-                       );
+                       (void **)&fis_frame_data);
 
                scic_sds_controller_copy_sata_response(
-                       &this_phy->phy_type.sata.signature_fis_buffer,
+                       &sci_phy->phy_type.sata.signature_fis_buffer,
                        frame_words,
-                       fis_frame_data
-                       );
+                       fis_frame_data);
 
                /* We got the IAF we can now go to the await spinup semaphore state */
-               sci_base_state_machine_change_state(
-                       scic_sds_phy_get_starting_substate_machine(this_phy),
-                       SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
-                       );
+               sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                                   SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
 
                result = SCI_SUCCESS;
        } else
-               dev_warn(sciphy_to_dev(this_phy),
+               dev_warn(sciphy_to_dev(sci_phy),
                         "%s: PHY starting substate machine received "
                         "unexpected frame id %x\n",
                         __func__,
                         frame_index);
 
        /* Regardless of the result release this frame since we are done with it */
-       scic_sds_controller_release_frame(
-               scic_sds_phy_get_controller(this_phy), frame_index
-               );
+       scic_sds_controller_release_frame(scic_sds_phy_get_controller(sci_phy),
+                                         frame_index);
 
        return result;
 }
@@ -1394,7 +1358,7 @@ static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handle
  * ***************************************************************************** */
 
 /**
- *
+ * scic_sds_phy_starting_substate_await_sas_power_consume_power_handler -
  * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
  *    object.
  *
@@ -1404,19 +1368,17 @@ static enum sci_status scic_sds_phy_starting_substate_await_sig_fis_frame_handle
  * SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL. enum sci_status SCI_SUCCESS
  */
 static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_power_handler(
-       struct scic_sds_phy *this_phy)
+       struct scic_sds_phy *sci_phy)
 {
        u32 enable_spinup;
 
-       enable_spinup = SCU_SAS_ENSPINUP_READ(this_phy);
+       enable_spinup = SCU_SAS_ENSPINUP_READ(sci_phy);
        enable_spinup |= SCU_ENSPINUP_GEN_BIT(ENABLE);
-       SCU_SAS_ENSPINUP_WRITE(this_phy, enable_spinup);
+       SCU_SAS_ENSPINUP_WRITE(sci_phy, enable_spinup);
 
        /* Change state to the final state this substate machine has run to completion */
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_starting_substate_machine(this_phy),
-               SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
-               );
+       sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                           SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
 
        return SCI_SUCCESS;
 }
@@ -1431,27 +1393,25 @@ static enum sci_status scic_sds_phy_starting_substate_await_sas_power_consume_po
  * SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN. enum sci_status SCI_SUCCESS
  */
 static enum sci_status scic_sds_phy_starting_substate_await_sata_power_consume_power_handler(
-       struct scic_sds_phy *this_phy)
+       struct scic_sds_phy *sci_phy)
 {
        u32 scu_sas_pcfg_value;
 
        /* Release the spinup hold state and reset the OOB state machine */
-       scu_sas_pcfg_value = SCU_SAS_PCFG_READ(this_phy);
+       scu_sas_pcfg_value = SCU_SAS_PCFG_READ(sci_phy);
        scu_sas_pcfg_value &=
                ~(SCU_SAS_PCFG_GEN_BIT(SATA_SPINUP_HOLD) | SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE));
        scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
-       SCU_SAS_PCFG_WRITE(this_phy, scu_sas_pcfg_value);
+       SCU_SAS_PCFG_WRITE(sci_phy, scu_sas_pcfg_value);
 
        /* Now restart the OOB operation */
        scu_sas_pcfg_value &= ~SCU_SAS_PCFG_GEN_BIT(OOB_RESET);
        scu_sas_pcfg_value |= SCU_SAS_PCFG_GEN_BIT(OOB_ENABLE);
-       SCU_SAS_PCFG_WRITE(this_phy, scu_sas_pcfg_value);
+       SCU_SAS_PCFG_WRITE(sci_phy, scu_sas_pcfg_value);
 
        /* Change state to the final state this substate machine has run to completion */
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_starting_substate_machine(this_phy),
-               SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN
-               );
+       sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                           SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN);
 
        return SCI_SUCCESS;
 }
@@ -1566,7 +1526,7 @@ const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_t
  * **************************************************************************** */
 
 /**
- *
+ * scic_sds_phy_starting_initial_substate_enter -
  * @object: This is the struct sci_base_object which is cast to a struct scic_sds_phy object.
  *
  * This method will perform the actions required by the struct scic_sds_phy on
@@ -1574,21 +1534,18 @@ const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_handler_t
  * handlers are put in place for the struct scic_sds_phy object. - The state is
  * changed to the wait phy type event notification. none
  */
-static void scic_sds_phy_starting_initial_substate_enter(
-       struct sci_base_object *object)
+static void scic_sds_phy_starting_initial_substate_enter(struct sci_base_object *object)
 {
-       struct scic_sds_phy *this_phy;
+       struct scic_sds_phy *sci_phy;
 
-       this_phy = (struct scic_sds_phy *)object;
+       sci_phy = (struct scic_sds_phy *)object;
 
        scic_sds_phy_set_starting_substate_handlers(
-               this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
+               sci_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL);
 
        /* This is just an temporary state go off to the starting state */
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_starting_substate_machine(this_phy),
-               SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN
-               );
+       sci_base_state_machine_change_state(&sci_phy->starting_substate_machine,
+                                           SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN);
 }
 
 /**
@@ -1892,23 +1849,20 @@ static inline void scic_sds_phy_starting_await_sig_fis_uf_substate_exit(
  * object state handlers for this state. - Change base state machine to the
  * ready state. none
  */
-static void scic_sds_phy_starting_final_substate_enter(
-       struct sci_base_object *object)
+static void scic_sds_phy_starting_final_substate_enter(struct sci_base_object *object)
 {
-       struct scic_sds_phy *this_phy;
+       struct scic_sds_phy *sci_phy;
 
-       this_phy = (struct scic_sds_phy *)object;
+       sci_phy = container_of(object, typeof(*sci_phy), parent.parent);
 
-       scic_sds_phy_set_starting_substate_handlers(
-               this_phy, SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL
-               );
+       scic_sds_phy_set_starting_substate_handlers(sci_phy,
+                                                   SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL);
 
-       /*
-        * State machine has run to completion so exit out and change
-        * the base state machine to the ready state */
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_base_state_machine(this_phy),
-               SCI_BASE_PHY_STATE_READY);
+       /* State machine has run to completion so exit out and change
+        * the base state machine to the ready state
+        */
+       sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                           SCI_BASE_PHY_STATE_READY);
 }
 
 /* --------------------------------------------------------------------------- */
@@ -2150,153 +2104,85 @@ enum sci_status scic_sds_phy_default_consume_power_handler(
  * attempts to start it. - The phy state machine is transitioned to the
  * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
  */
-static enum sci_status scic_sds_phy_stopped_state_start_handler(
-               struct sci_base_phy *phy)
+static enum sci_status scic_sds_phy_stopped_state_start_handler(struct sci_base_phy *base_phy)
 {
-       struct scic_sds_phy *sci_phy = (struct scic_sds_phy *)phy;
-       struct scic_sds_controller *scic = scic_sds_phy_get_controller(sci_phy);
-       struct isci_host *ihost = sci_object_get_association(scic);
+       struct isci_host *ihost;
+       struct scic_sds_phy *sci_phy;
+       struct scic_sds_controller *scic;
+
+       sci_phy = container_of(base_phy, typeof(*sci_phy), parent);
+       scic = scic_sds_phy_get_controller(sci_phy),
+       ihost = sci_object_get_association(scic);
 
        /* Create the SIGNATURE FIS Timeout timer for this phy */
-       sci_phy->sata_timeout_timer =
-               isci_timer_create(
-                               ihost,
-                               sci_phy,
-                               scic_sds_phy_sata_timeout);
+       sci_phy->sata_timeout_timer = isci_timer_create(ihost, sci_phy,
+                                                       scic_sds_phy_sata_timeout);
 
-       if (sci_phy->sata_timeout_timer != NULL) {
-               sci_base_state_machine_change_state(
-                       scic_sds_phy_get_base_state_machine(sci_phy),
-                       SCI_BASE_PHY_STATE_STARTING);
-       }
+       if (sci_phy->sata_timeout_timer)
+               sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                                   SCI_BASE_PHY_STATE_STARTING);
 
        return SCI_SUCCESS;
 }
 
-/**
- *
- * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
- *    object.
- *
- * This method takes the struct scic_sds_phy from a stopped state and destroys it. -
- * This function takes no action. Shouldnt this function transition the
- * struct sci_base_phy::state_machine to the SCI_BASE_PHY_STATE_FINAL? enum sci_status
- * SCI_SUCCESS
- */
-static enum sci_status scic_sds_phy_stopped_state_destroy_handler(
-       struct sci_base_phy *phy)
+static enum sci_status scic_sds_phy_stopped_state_destroy_handler(struct sci_base_phy *base_phy)
 {
-       struct scic_sds_phy *this_phy;
-
-       this_phy = (struct scic_sds_phy *)phy;
-
-       /* @todo what do we actually need to do here? */
        return SCI_SUCCESS;
 }
 
-/*
- * ******************************************************************************
- * * PHY STARTING STATE HANDLERS
- * ****************************************************************************** */
-
-/* All of these state handlers are mapped to the starting sub-state machine */
-
-/*
- * ******************************************************************************
- * * PHY READY STATE HANDLERS
- * ****************************************************************************** */
-
-/**
- *
- * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
- *    object.
- *
- * This method takes the struct scic_sds_phy from a ready state and attempts to stop
- * it. - The phy state machine is transitioned to the
- * SCI_BASE_PHY_STATE_STOPPED. enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_phy_ready_state_stop_handler(
-       struct sci_base_phy *phy)
+static enum sci_status scic_sds_phy_ready_state_stop_handler(struct sci_base_phy *base_phy)
 {
-       struct scic_sds_phy *this_phy;
-
-       this_phy = (struct scic_sds_phy *)phy;
-
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_base_state_machine(this_phy),
-               SCI_BASE_PHY_STATE_STOPPED
-               );
+       sci_base_state_machine_change_state(&base_phy->state_machine,
+                                           SCI_BASE_PHY_STATE_STOPPED);
 
        return SCI_SUCCESS;
 }
 
-/**
- *
- * @phy: This is the struct sci_base_phy object which is cast into a struct scic_sds_phy
- *    object.
- *
- * This method takes the struct scic_sds_phy from a ready state and attempts to reset
- * it. - The phy state machine is transitioned to the
- * SCI_BASE_PHY_STATE_STARTING. enum sci_status SCI_SUCCESS
- */
-static enum sci_status scic_sds_phy_ready_state_reset_handler(
-       struct sci_base_phy *phy)
+static enum sci_status scic_sds_phy_ready_state_reset_handler(struct sci_base_phy *base_phy)
 {
-       struct scic_sds_phy *this_phy;
-
-       this_phy = (struct scic_sds_phy *)phy;
-
-       sci_base_state_machine_change_state(
-               scic_sds_phy_get_base_state_machine(this_phy),
-               SCI_BASE_PHY_STATE_RESETTING
-               );
+       sci_base_state_machine_change_state(&base_phy->state_machine,
+                                           SCI_BASE_PHY_STATE_RESETTING);
 
        return SCI_SUCCESS;
 }
 
 /**
- *
+ * scic_sds_phy_ready_state_event_handler -
  * @phy: This is the struct scic_sds_phy object which has received the event.
  *
  * This method request the struct scic_sds_phy handle the received event.  The only
  * event that we are interested in while in the ready state is the link failure
  * event. - decoded event is a link failure - transition the struct scic_sds_phy back
- * to the SCI_BASE_PHY_STATE_STARTING state. - any other event recived will
+ * to the SCI_BASE_PHY_STATE_STARTING state. - any other event received will
  * report a warning message enum sci_status SCI_SUCCESS if the event received is a
  * link failure SCI_FAILURE_INVALID_STATE for any other event received.
  */
-static enum sci_status scic_sds_phy_ready_state_event_handler(
-       struct scic_sds_phy *this_phy,
-       u32 event_code)
+static enum sci_status scic_sds_phy_ready_state_event_handler(struct scic_sds_phy *sci_phy,
+                                                             u32 event_code)
 {
        enum sci_status result = SCI_FAILURE;
 
        switch (scu_get_event_code(event_code)) {
        case SCU_EVENT_LINK_FAILURE:
                /* Link failure change state back to the starting state */
-               sci_base_state_machine_change_state(
-                       scic_sds_phy_get_base_state_machine(this_phy),
-                       SCI_BASE_PHY_STATE_STARTING
-                       );
-
+               sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                                   SCI_BASE_PHY_STATE_STARTING);
                result = SCI_SUCCESS;
                break;
 
        case SCU_EVENT_BROADCAST_CHANGE:
                /* Broadcast change received. Notify the port. */
-               if (scic_sds_phy_get_port(this_phy) != NULL)
-                       scic_sds_port_broadcast_change_received(this_phy->owning_port, this_phy);
+               if (scic_sds_phy_get_port(sci_phy) != NULL)
+                       scic_sds_port_broadcast_change_received(sci_phy->owning_port, sci_phy);
                else
-                       this_phy->bcn_received_while_port_unassigned = true;
+                       sci_phy->bcn_received_while_port_unassigned = true;
                break;
 
        default:
-               dev_warn(sciphy_to_dev(this_phy),
+               dev_warn(sciphy_to_dev(sci_phy),
                         "%sP SCIC PHY 0x%p ready state machine received "
                         "unexpected event_code %x\n",
-                        __func__,
-                        this_phy,
-                        event_code);
+                        __func__, sci_phy, event_code);
 
                result = SCI_FAILURE_INVALID_STATE;
                break;
@@ -2305,40 +2191,24 @@ static enum sci_status scic_sds_phy_ready_state_event_handler(
        return result;
 }
 
-/* --------------------------------------------------------------------------- */
-
-/**
- *
- * @this_phy: This is the struct scic_sds_phy object which is receiving the event.
- * @event_code: This is the event code to be processed.
- *
- * This is the resetting state event handler. enum sci_status
- * SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_phy_resetting_state_event_handler(
-       struct scic_sds_phy *this_phy,
-       u32 event_code)
+static enum sci_status scic_sds_phy_resetting_state_event_handler(struct scic_sds_phy *sci_phy,
+                                                                 u32 event_code)
 {
        enum sci_status result = SCI_FAILURE;
 
        switch (scu_get_event_code(event_code)) {
        case SCU_EVENT_HARD_RESET_TRANSMITTED:
                /* Link failure change state back to the starting state */
-               sci_base_state_machine_change_state(
-                       scic_sds_phy_get_base_state_machine(this_phy),
-                       SCI_BASE_PHY_STATE_STARTING
-                       );
-
+               sci_base_state_machine_change_state(&sci_phy->parent.state_machine,
+                                                   SCI_BASE_PHY_STATE_STARTING);
                result = SCI_SUCCESS;
                break;
 
        default:
-               dev_warn(sciphy_to_dev(this_phy),
+               dev_warn(sciphy_to_dev(sci_phy),
                         "%s: SCIC PHY 0x%p resetting state machine received "
                         "unexpected event_code %x\n",
-                        __func__,
-                        this_phy,
-                        event_code);
+                        __func__, sci_phy, event_code);
 
                result = SCI_FAILURE_INVALID_STATE;
                break;
index b611e33180b20e20c98b900a97e0526243ea1ef1..af9e24c30945459bf9b39200c09b627a95e0829c 100644 (file)
@@ -316,24 +316,6 @@ extern const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_ha
 #define scic_sds_phy_get_controller(phy) \
        (scic_sds_port_get_controller((phy)->owning_port))
 
-/**
- * scic_sds_phy_get_base_state_machine() - This macro returns the state machine
- *    for the base phy
- *
- *
- */
-#define scic_sds_phy_get_base_state_machine(phy) \
-       (&(phy)->parent.state_machine)
-
-/**
- * scic_sds_phy_get_starting_substate_machine() - This macro returns the
- *    starting substate machine for this phy
- *
- *
- */
-#define scic_sds_phy_get_starting_substate_machine(phy)        \
-       (&(phy)->starting_substate_machine)
-
 /**
  * scic_sds_phy_set_state_handlers() - This macro sets the state handlers for
  *    this phy object
@@ -354,27 +336,6 @@ extern const struct scic_sds_phy_state_handler scic_sds_phy_starting_substate_ha
                &scic_sds_phy_state_handler_table[(state_id)] \
                )
 
-/**
- * scic_sds_phy_is_ready() -
- *
- * This macro returns true if the current base state for this phy is
- * SCI_BASE_PHY_STATE_READY
- */
-#define scic_sds_phy_is_ready(phy) \
-       (\
-               SCI_BASE_PHY_STATE_READY \
-               == sci_base_state_machine_get_state(\
-                       scic_sds_phy_get_base_state_machine(phy) \
-                       ) \
-       )
-
-/* --------------------------------------------------------------------------- */
-
-
-
-
-/* --------------------------------------------------------------------------- */
-
 void scic_sds_phy_construct(
        struct scic_sds_phy *this_phy,
        struct scic_sds_port *owning_port,
@@ -404,8 +365,6 @@ enum sci_status scic_sds_phy_reset(
 void scic_sds_phy_sata_timeout(
        void *cookie);
 
-/* --------------------------------------------------------------------------- */
-
 void scic_sds_phy_suspend(
        struct scic_sds_phy *this_phy);
 
@@ -416,8 +375,6 @@ void scic_sds_phy_setup_transport(
        struct scic_sds_phy *this_phy,
        u32 device_id);
 
-/* --------------------------------------------------------------------------- */
-
 enum sci_status scic_sds_phy_event_handler(
        struct scic_sds_phy *this_phy,
        u32 event_code);
@@ -445,11 +402,6 @@ void scic_sds_phy_get_attached_phy_protocols(
        struct scic_sds_phy *this_phy,
        struct sci_sas_identify_address_frame_protocols *protocols);
 
-/*
- * ****************************************************************************-
- * * SCIC SDS PHY Handler Methods
- * ****************************************************************************- */
-
 enum sci_status scic_sds_phy_default_start_handler(
        struct sci_base_phy *phy);
 
index 3ae0f0d80f1fb5de5e62895ae541fc69d6696408..72b815ef98ca71a3ba5d7b98f7426660db315491 100644 (file)
@@ -576,12 +576,10 @@ void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 port_index,
 
        sci_base_port_construct(&sci_port->parent, scic_sds_port_state_table);
 
-       sci_base_state_machine_construct(
-               scic_sds_port_get_ready_substate_machine(sci_port),
-               &sci_port->parent.parent,
-               scic_sds_port_ready_substate_table,
-               SCIC_SDS_PORT_READY_SUBSTATE_WAITING
-               );
+       sci_base_state_machine_construct(&sci_port->ready_substate_machine,
+                                        &sci_port->parent.parent,
+                                        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 = port_index;
@@ -1339,9 +1337,9 @@ static void scic_sds_port_ready_operational_substate_link_up_handler(
 
 /**
  * scic_sds_port_ready_operational_substate_link_down_handler() -
- * @this_port: This is the struct scic_sds_port object that which has a phy that has
+ * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  *    gone link down.
- * @the_phy: This is the struct scic_sds_phy object 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
@@ -1349,21 +1347,18 @@ static void scic_sds_port_ready_operational_substate_link_up_handler(
  * state to the ready waiting substate. none
  */
 static void scic_sds_port_ready_operational_substate_link_down_handler(
-       struct scic_sds_port *this_port,
-       struct scic_sds_phy *the_phy)
+       struct scic_sds_port *sci_port,
+       struct scic_sds_phy *sci_phy)
 {
-       scic_sds_port_deactivate_phy(this_port, the_phy, true);
+       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 (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
-                       );
-       }
+       if (sci_port->active_phy_mask == 0)
+               sci_base_state_machine_change_state(&sci_port->ready_substate_machine,
+                                                   SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
 }
 
 /**
@@ -1820,169 +1815,52 @@ const struct sci_base_state scic_sds_port_ready_substate_table[] = {
        },
 };
 
-/*
- * ***************************************************************************
- * *  DEFAULT HANDLERS
- * *************************************************************************** */
-
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for port a start request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-enum sci_status scic_sds_port_default_start_handler(
-       struct sci_base_port *port)
+static enum sci_status default_port_handler(struct sci_base_port *base_port, const char *func)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
+       struct scic_sds_port *sci_port;
 
+       sci_port = container_of(base_port, typeof(*sci_port), parent);
        dev_warn(sciport_to_dev(sci_port),
-                "%s: SCIC Port 0x%p requested to start while in invalid "
-                "state %d\n",
-                __func__,
-                port,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
-
+                "%s: in wrong state: %d\n", func,
+                sci_base_state_machine_get_state(&base_port->state_machine));
        return SCI_FAILURE_INVALID_STATE;
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port stop request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_port_default_stop_handler(
-       struct sci_base_port *port)
+enum sci_status scic_sds_port_default_start_handler(struct sci_base_port *base_port)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
-
-       dev_warn(sciport_to_dev(sci_port),
-                "%s: SCIC Port 0x%p requested to stop while in invalid "
-                "state %d\n",
-                __func__,
-                port,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_port_handler(base_port, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port destruct request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-enum sci_status scic_sds_port_default_destruct_handler(
-       struct sci_base_port *port)
+static enum sci_status scic_sds_port_default_stop_handler(struct sci_base_port *base_port)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
-
-       dev_warn(sciport_to_dev(sci_port),
-                "%s: SCIC Port 0x%p requested to destruct while in invalid "
-                "state %d\n",
-                __func__,
-                port,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_port_handler(base_port, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- * @timeout: This is the timeout for the reset request to complete.
- *
- * This is the default method for a port reset request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-enum sci_status scic_sds_port_default_reset_handler(
-       struct sci_base_port *port,
-       u32 timeout)
+enum sci_status scic_sds_port_default_destruct_handler(struct sci_base_port *base_port)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
-
-       dev_warn(sciport_to_dev(sci_port),
-                "%s: SCIC Port 0x%p requested to reset while in invalid "
-                "state %d\n",
-                __func__,
-                port,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_port_handler(base_port, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * 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_default_add_phy_handler(
-       struct sci_base_port *port,
-       struct sci_base_phy *phy)
+enum sci_status scic_sds_port_default_reset_handler(struct sci_base_port *base_port,
+                                                   u32 timeout)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
-
-       dev_warn(sciport_to_dev(sci_port),
-                "%s: SCIC Port 0x%p requested to add phy 0x%p while in "
-                "invalid state %d\n",
-                __func__,
-                port,
-                phy,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_port_handler(base_port, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * 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
- */
-enum sci_status scic_sds_port_default_remove_phy_handler(
-       struct sci_base_port *port,
-       struct sci_base_phy *phy)
+static enum sci_status scic_sds_port_default_add_phy_handler(struct sci_base_port *base_port,
+                                                            struct sci_base_phy *base_phy)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)port;
-
-       dev_warn(sciport_to_dev(sci_port),
-                "%s: SCIC Port 0x%p requested to remove phy 0x%p while in "
-                "invalid state %d\n",
-                __func__,
-                port,
-                phy,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
+       return default_port_handler(base_port, __func__);
+}
 
-       return SCI_FAILURE_INVALID_STATE;
+enum sci_status scic_sds_port_default_remove_phy_handler(struct sci_base_port *base_port,
+                                                        struct sci_base_phy *base_phy)
+{
+       return default_port_handler(base_port, __func__);
 }
 
 /**
- *
+ * scic_sds_port_default_frame_handler
  * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
  *    object.
  *
@@ -1991,149 +1869,48 @@ enum sci_status scic_sds_port_default_remove_phy_handler(
  * possible to receive an unsolicited frame directed to a port object?  It
  * seems possible if we implementing virtual functions but until then?
  */
-enum sci_status scic_sds_port_default_frame_handler(
-       struct scic_sds_port *port,
-       u32 frame_index)
-{
-       dev_warn(sciport_to_dev(port),
-                "%s: SCIC Port 0x%p requested to process frame %d while in "
-                "invalid state %d\n",
-                __func__,
-                port,
-                frame_index,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(port)));
-
-       scic_sds_controller_release_frame(
-               scic_sds_port_get_controller(port), frame_index
-               );
-
-       return SCI_FAILURE_INVALID_STATE;
-}
+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);
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port event request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-enum sci_status scic_sds_port_default_event_handler(
-       struct scic_sds_port *port,
-       u32 event_code)
-{
-       dev_warn(sciport_to_dev(port),
-                "%s: SCIC Port 0x%p requested to process event 0x%x while "
-                "in invalid state %d\n",
-                __func__,
-                port,
-                event_code,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(
-                                (struct scic_sds_port *)port)));
+       default_port_handler(&sci_port->parent, __func__);
+       scic_sds_controller_release_frame(scic, frame_index);
 
        return SCI_FAILURE_INVALID_STATE;
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port link up notification.  It will report
- * a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-void scic_sds_port_default_link_up_handler(
-       struct scic_sds_port *this_port,
-       struct scic_sds_phy *phy)
+enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
+                                                   u32 event_code)
 {
-       dev_warn(sciport_to_dev(this_port),
-                "%s: SCIC Port 0x%p received link_up notification from phy "
-                "0x%p while in invalid state %d\n",
-                __func__,
-                this_port,
-                phy,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(this_port)));
+       return default_port_handler(&sci_port->parent, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port link down notification.  It will
- * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-void scic_sds_port_default_link_down_handler(
-       struct scic_sds_port *this_port,
-       struct scic_sds_phy *phy)
+void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
+                                          struct scic_sds_phy *sci_phy)
 {
-       dev_warn(sciport_to_dev(this_port),
-                "%s: SCIC Port 0x%p received link down notification from "
-                "phy 0x%p while in invalid state %d\n",
-                __func__,
-                this_port,
-                phy,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(this_port)));
+       default_port_handler(&sci_port->parent, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port start io request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-enum sci_status scic_sds_port_default_start_io_handler(
-       struct scic_sds_port *this_port,
-       struct scic_sds_remote_device *device,
-       struct scic_sds_request *io_request)
+void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
+                                            struct scic_sds_phy *sci_phy)
 {
-       dev_warn(sciport_to_dev(this_port),
-                "%s: SCIC Port 0x%p requested to start io request 0x%p "
-                "while in invalid state %d\n",
-                __func__,
-                this_port,
-                io_request,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(this_port)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       default_port_handler(&sci_port->parent, __func__);
 }
 
-/**
- *
- * @port: This is the struct sci_base_port object which is cast into a struct scic_sds_port
- *    object.
- *
- * This is the default method for a port complete io request.  It will report a
- * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_port_default_complete_io_handler(
-       struct scic_sds_port *this_port,
-       struct scic_sds_remote_device *device,
-       struct scic_sds_request *io_request)
+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)
 {
-       dev_warn(sciport_to_dev(this_port),
-                "%s: SCIC Port 0x%p requested to complete io request 0x%p "
-                "while in invalid state %d\n",
-                __func__,
-                this_port,
-                io_request,
-                sci_base_state_machine_get_state(
-                        scic_sds_port_get_base_state_machine(this_port)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_port_handler(&sci_port->parent, __func__);
 }
 
-/*
- * ****************************************************************************
- * * GENERAL STATE HANDLERS
- * **************************************************************************** */
+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->parent, __func__);
+}
 
 /**
  *
@@ -2160,11 +1937,6 @@ static enum sci_status scic_sds_port_general_complete_io_handler(
        return SCI_SUCCESS;
 }
 
-/*
- * ****************************************************************************
- * * STOPPED STATE HANDLERS
- * **************************************************************************** */
-
 /**
  * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
  *
@@ -2242,9 +2014,8 @@ scic_sds_port_stopped_state_start_handler(struct sci_base_port *base_port)
                 * silicon.
                 */
                if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
-                       sci_base_state_machine_change_state(
-                               scic_sds_port_get_base_state_machine(sci_port),
-                               SCI_BASE_PORT_STATE_READY);
+                       sci_base_state_machine_change_state(&base_port->state_machine,
+                                                           SCI_BASE_PORT_STATE_READY);
 
                        return SCI_SUCCESS;
                } else
@@ -2390,19 +2161,15 @@ static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
  * 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 *port,
+       struct scic_sds_port *sci_port,
        struct scic_sds_remote_device *device,
        struct scic_sds_request *io_request)
 {
-       struct scic_sds_port *this_port = (struct scic_sds_port *)port;
-
-       scic_sds_port_decrement_request_count(this_port);
+       scic_sds_port_decrement_request_count(sci_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
-                       );
+       if (sci_port->started_request_count == 0) {
+               sci_base_state_machine_change_state(&sci_port->parent.state_machine,
+                                                   SCI_BASE_PORT_STATE_STOPPED);
        }
 
        return SCI_SUCCESS;
@@ -2727,9 +2494,8 @@ static void scic_sds_port_stopped_state_exit(
 }
 
 /**
- *
- * @object: This is the struct sci_base_object which is cast to a
- * struct scic_sds_port object.
+ * scic_sds_port_ready_state_enter -
+ * @object: This is the struct sci_base_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
@@ -2738,50 +2504,40 @@ static void scic_sds_port_stopped_state_exit(
  */
 static void scic_sds_port_ready_state_enter(struct sci_base_object *object)
 {
-       struct scic_sds_port *sci_port = (struct scic_sds_port *)object;
-       struct isci_port *iport = sci_object_get_association(sci_port);
-       struct scic_sds_controller *scic =
-               scic_sds_port_get_controller(sci_port);
-       struct isci_host *ihost = sci_object_get_association(scic);
+       struct scic_sds_controller *scic;
+       struct scic_sds_port *sci_port;
+       struct isci_port *iport;
+       struct isci_host *ihost;
+       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);
+       sci_port = container_of(object, typeof(*sci_port), parent.parent);
+       scic = scic_sds_port_get_controller(sci_port);
+       ihost = sci_object_get_association(scic);
+       iport = sci_object_get_association(sci_port);
 
-       if (sci_port->parent.state_machine.previous_state_id ==
-                       SCI_BASE_PORT_STATE_RESETTING)
+       /* 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->parent.state_machine.previous_state_id;
+       if (prev_state  == SCI_BASE_PORT_STATE_RESETTING)
                isci_port_hard_reset_complete(iport, SCI_SUCCESS);
-       else /* Notify the caller that the port is not yet ready */
+       else
                isci_port_not_ready(ihost, iport);
 
        /* Post and suspend the dummy remote node context for this port. */
        scic_sds_port_post_dummy_remote_node(sci_port);
 
        /* Start the ready substate machine */
-       sci_base_state_machine_start(
-                       scic_sds_port_get_ready_substate_machine(sci_port));
+       sci_base_state_machine_start(&sci_port->ready_substate_machine);
 }
 
-/**
- *
- * @object: This is the struct sci_base_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_READY. This function does nothing. none
- */
-static void scic_sds_port_ready_state_exit(
-       struct sci_base_object *object)
+static void scic_sds_port_ready_state_exit(struct sci_base_object *object)
 {
-       struct scic_sds_port *this_port;
-
-       this_port = (struct scic_sds_port *)object;
-
-       sci_base_state_machine_stop(&this_port->ready_substate_machine);
+       struct scic_sds_port *sci_port;
 
-       scic_sds_port_invalidate_dummy_remote_node(this_port);
+       sci_port = container_of(object, typeof(*sci_port), parent.parent);
+       sci_base_state_machine_stop(&sci_port->ready_substate_machine);
+       scic_sds_port_invalidate_dummy_remote_node(sci_port);
 }
 
 /**
index c98caefa7cf2f989a0e4095f782e7d96ea5eccff..ac81a92c348a240b1cd6214b2f9230da338a2b48 100644 (file)
@@ -250,14 +250,6 @@ extern struct scic_sds_port_state_handler scic_sds_port_ready_substate_handler_t
 #define scic_sds_port_get_controller(this_port)        \
        ((this_port)->owning_controller)
 
-/**
- * scic_sds_port_get_base_state_machine() -
- *
- * Helper macro to get the base state machine for this port
- */
-#define scic_sds_port_get_base_state_machine(this_port)        \
-       (&(this_port)->parent.state_machine)
-
 /**
  * scic_sds_port_set_base_state_handlers() -
  *
@@ -267,14 +259,6 @@ extern struct scic_sds_port_state_handler scic_sds_port_ready_substate_handler_t
        scic_sds_port_set_state_handlers(\
                (this_port), &scic_sds_port_state_handler_table[(state_id)])
 
-/**
- * scic_sds_port_get_ready_substate_machine() -
- *
- * Helper macro to get the ready substate machine for this port
- */
-#define scic_sds_port_get_ready_substate_machine(this_port) \
-       (&(this_port)->ready_substate_machine)
-
 /**
  * scic_sds_port_set_state_handlers() -
  *
index f722678eed8e1e17ddd3589bf128c0f493b9f1bd..05599d178caae13e0b416a1305a2aa7979c344e1 100644 (file)
@@ -135,8 +135,7 @@ enum sci_status scic_remote_device_da_construct(
                &remote_node_index);
 
        if (status == SCI_SUCCESS) {
-               scic_sds_remote_node_context_set_remote_node_index(
-                       sci_dev->rnc, remote_node_index);
+               sci_dev->rnc->remote_node_index = remote_node_index;
 
                scic_sds_port_get_attached_sas_address(
                        sci_dev->owning_port, &sci_dev->device_address);
@@ -510,16 +509,14 @@ bool scic_sds_remote_device_is_atapi(
 static void scic_sds_cb_remote_device_rnc_destruct_complete(
        void *user_parameter)
 {
-       struct scic_sds_remote_device *this_device;
+       struct scic_sds_remote_device *sci_dev;
 
-       this_device = (struct scic_sds_remote_device *)user_parameter;
+       sci_dev = (struct scic_sds_remote_device *)user_parameter;
 
-       BUG_ON(this_device->started_request_count != 0);
+       BUG_ON(sci_dev->started_request_count != 0);
 
-       sci_base_state_machine_change_state(
-               scic_sds_remote_device_get_base_state_machine(this_device),
-               SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
-               );
+       sci_base_state_machine_change_state(&sci_dev->parent.state_machine,
+                                           SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
 }
 
 /**
@@ -649,206 +646,64 @@ static enum sci_status scic_sds_remote_device_terminate_requests(
        return status;
 }
 
-/*
- * *****************************************************************************
- * *  DEFAULT STATE HANDLERS
- * ***************************************************************************** */
-
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default start handler.  It logs a warning and returns a
- * failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-enum sci_status scic_sds_remote_device_default_start_handler(
-       struct sci_base_remote_device *device)
+static enum sci_status default_device_handler(struct sci_base_remote_device *base_dev,
+                                             const char *func)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to start while in wrong "
-                "state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
+       struct scic_sds_remote_device *sci_dev;
 
+       sci_dev = container_of(base_dev, typeof(*sci_dev), parent);
+       dev_warn(scirdev_to_dev(sci_dev),
+                "%s: in wrong state: %d\n", func,
+                sci_base_state_machine_get_state(&base_dev->state_machine));
        return SCI_FAILURE_INVALID_STATE;
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default stop handler.  It logs a warning and returns a
- * failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-static enum sci_status scic_sds_remote_device_default_stop_handler(
-       struct sci_base_remote_device *device)
+enum sci_status scic_sds_remote_device_default_start_handler(
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to stop while in wrong "
-                "state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
+       return default_device_handler(base_dev, __func__);
+}
 
-       return SCI_FAILURE_INVALID_STATE;
+static enum sci_status scic_sds_remote_device_default_stop_handler(
+       struct sci_base_remote_device *base_dev)
+{
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default fail handler.  It logs a warning and returns a
- * failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_fail_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to fail while in wrong "
-                "state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default destruct handler.  It logs a warning and returns
- * a failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_destruct_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to destroy while in "
-                "wrong state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default reset handler.  It logs a warning and returns a
- * failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_reset_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to reset while in wrong "
-                "state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default reset complete handler.  It logs a warning and
- * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_reset_complete_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to complete reset while "
-                "in wrong state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default suspend handler.  It logs a warning and returns a
- * failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_suspend_handler(
-       struct scic_sds_remote_device *this_device,
-       u32 suspend_type)
+       struct scic_sds_remote_device *sci_dev, u32 suspend_type)
 {
-       dev_warn(scirdev_to_dev(this_device),
-                "%s: SCIC Remote Device 0x%p requested to suspend %d while "
-                "in wrong state %d\n",
-                __func__,
-                this_device,
-                suspend_type,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                this_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(&sci_dev->parent, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- *
- * This method is the default resume handler.  It logs a warning and returns a
- * failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_resume_handler(
-       struct scic_sds_remote_device *this_device)
+       struct scic_sds_remote_device *sci_dev)
 {
-       dev_warn(scirdev_to_dev(this_device),
-                "%s: SCIC Remote Device requested to resume while in "
-                "wrong state %d\n",
-                __func__,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                this_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(&sci_dev->parent, __func__);
 }
 
 /**
@@ -960,109 +815,27 @@ enum sci_status scic_sds_remote_device_default_frame_handler(
        return SCI_FAILURE_INVALID_STATE;
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
- *    to start.
- *
- * This method is the default start io handler.  It logs a warning and returns
- * a failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_start_request_handler(
-       struct sci_base_remote_device *device,
+       struct sci_base_remote_device *base_dev,
        struct sci_base_request *request)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to start io request %p "
-                "while in wrong state %d\n",
-                __func__,
-                request,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                (struct scic_sds_remote_device *)device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
- *    to complete.
- *
- * This method is the default complete io handler.  It logs a warning and
- * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_complete_request_handler(
-       struct sci_base_remote_device *device,
+       struct sci_base_remote_device *base_dev,
        struct sci_base_request *request)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to complete io_request %p "
-                "while in wrong state %d\n",
-                __func__,
-                request,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                                sds_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
- *    to continue.
- *
- * This method is the default continue io handler.  It logs a warning and
- * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
 enum sci_status scic_sds_remote_device_default_continue_request_handler(
-       struct sci_base_remote_device *device,
+       struct sci_base_remote_device *base_dev,
        struct sci_base_request *request)
 {
-       struct scic_sds_remote_device *sds_device =
-               (struct scic_sds_remote_device *)device;
-
-       dev_warn(scirdev_to_dev(sds_device),
-                "%s: SCIC Remote Device requested to continue io request %p "
-                "while in wrong state %d\n",
-                __func__,
-                request,
-                sci_base_state_machine_get_state(
-                        scic_sds_remote_device_get_base_state_machine(
-                        sds_device)));
-
-       return SCI_FAILURE_INVALID_STATE;
+       return default_device_handler(base_dev, __func__);
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device which is then cast into a
- *    struct scic_sds_remote_device.
- * @request: The struct sci_base_request which is then cast into a SCIC_SDS_IO_REQUEST
- *    to complete.
- *
- * This method is the default complete task handler.  It logs a warning and
- * returns a failure. enum sci_status SCI_FAILURE_INVALID_STATE
- */
-
-/*
- * *****************************************************************************
- * *  NORMAL STATE HANDLERS
- * ***************************************************************************** */
-
 /**
  *
  * @device: The struct sci_base_remote_device which is then cast into a
@@ -1146,45 +919,32 @@ enum sci_status scic_sds_remote_device_general_event_handler(
  * which to construct the remote device.
  */
 static enum sci_status scic_sds_remote_device_stopped_state_start_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
        enum sci_status status;
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
+       struct scic_sds_remote_device *sci_dev;
 
-       status = scic_sds_remote_node_context_resume(
-               this_device->rnc,
-               scic_sds_remote_device_resume_complete_handler,
-               this_device
-               );
+       sci_dev = container_of(base_dev, typeof(*sci_dev), parent);
 
-       if (status == SCI_SUCCESS) {
-               sci_base_state_machine_change_state(
-                       scic_sds_remote_device_get_base_state_machine(this_device),
-                       SCI_BASE_REMOTE_DEVICE_STATE_STARTING
-                       );
-       }
+       status = scic_sds_remote_node_context_resume(sci_dev->rnc,
+                       scic_sds_remote_device_resume_complete_handler, sci_dev);
+
+       if (status == SCI_SUCCESS)
+               sci_base_state_machine_change_state(&base_dev->state_machine,
+                                                   SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
 
        return status;
 }
 
-/**
- *
- * @this_device: The struct sci_base_remote_device which is cast into a
- *    struct scic_sds_remote_device.
- *
- * This method will stop a struct scic_sds_remote_device that is already in a stopped
- * state.  This is not considered an error since the device is already stopped.
- * enum sci_status SCI_SUCCESS
- */
 static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
-       struct sci_base_remote_device *this_device)
+       struct sci_base_remote_device *base_dev)
 {
        return SCI_SUCCESS;
 }
 
 /**
  *
- * @this_device: The struct sci_base_remote_device which is cast into a
+ * @sci_dev: The struct sci_base_remote_device which is cast into a
  *    struct scic_sds_remote_device.
  *
  * This method will destruct a struct scic_sds_remote_device that is in a stopped
@@ -1194,25 +954,19 @@ static enum sci_status scic_sds_remote_device_stopped_state_stop_handler(
  * enum sci_status SCI_SUCCESS
  */
 static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
-
-       scic_sds_controller_free_remote_node_context(
-               scic_sds_remote_device_get_controller(this_device),
-               this_device,
-               this_device->rnc->remote_node_index
-               );
+       struct scic_sds_remote_device *sci_dev;
+       struct scic_sds_controller *scic;
 
-       scic_sds_remote_node_context_set_remote_node_index(
-               this_device->rnc,
-               SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
-               );
+       sci_dev = container_of(base_dev, typeof(*sci_dev), parent);
+       scic = scic_sds_remote_device_get_controller(sci_dev);
+       scic_sds_controller_free_remote_node_context(scic, sci_dev,
+                                                    sci_dev->rnc->remote_node_index);
+       sci_dev->rnc->remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;
 
-       sci_base_state_machine_change_state(
-               scic_sds_remote_device_get_base_state_machine(this_device),
-               SCI_BASE_REMOTE_DEVICE_STATE_FINAL
-               );
+       sci_base_state_machine_change_state(&base_dev->state_machine,
+                                           SCI_BASE_REMOTE_DEVICE_STATE_FINAL);
 
        return SCI_SUCCESS;
 }
@@ -1223,86 +977,49 @@ static enum sci_status scic_sds_remote_device_stopped_state_destruct_handler(
  * ***************************************************************************** */
 
 static enum sci_status scic_sds_remote_device_starting_state_stop_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
+       struct scic_sds_remote_device *sci_dev;
 
+       sci_dev = container_of(base_dev, typeof(*sci_dev), parent);
        /*
         * This device has not yet started so there had better be no IO requests
         */
-       BUG_ON(this_device->started_request_count != 0);
+       BUG_ON(sci_dev->started_request_count != 0);
 
        /*
         * Destroy the remote node context
         */
-       scic_sds_remote_node_context_destruct(
-               this_device->rnc,
-               scic_sds_cb_remote_device_rnc_destruct_complete,
-               this_device
-               );
+       scic_sds_remote_node_context_destruct(sci_dev->rnc,
+               scic_sds_cb_remote_device_rnc_destruct_complete, sci_dev);
 
        /*
         * Transition to the stopping state and wait for the remote node to
         * complete being posted and invalidated.
         */
-       sci_base_state_machine_change_state(
-               scic_sds_remote_device_get_base_state_machine(this_device),
-               SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
-               );
+       sci_base_state_machine_change_state(&base_dev->state_machine,
+                                           SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
 
        return SCI_SUCCESS;
 }
 
-/*
- * *****************************************************************************
- * *  INITIALIZING STATE HANDLERS
- * ***************************************************************************** */
-
-/* There is nothing to do here for SSP devices */
-
-/*
- * *****************************************************************************
- * *  READY STATE HANDLERS
- * ***************************************************************************** */
-
-/**
- *
- * @this_device: The struct scic_sds_remote_device object to be suspended.
- *
- * This method is the resume handler for the struct scic_sds_remote_device object. It
- * will post an RNC resume to the SCU hardware. enum sci_status SCI_SUCCESS
- */
-
-/**
- *
- * @device: The struct sci_base_remote_device object which is cast to a
- *    struct scic_sds_remote_device object.
- *
- * This method is the default stop handler for the struct scic_sds_remote_device ready
- * substate machine. It will stop the current substate machine and transition
- * the base state machine to SCI_BASE_REMOTE_DEVICE_STATE_STOPPING. enum sci_status
- * SCI_SUCCESS
- */
 enum sci_status scic_sds_remote_device_ready_state_stop_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
-       enum sci_status status      = SCI_SUCCESS;
+       struct scic_sds_remote_device *sci_dev;
+       enum sci_status status = SCI_SUCCESS;
 
+       sci_dev = container_of(base_dev, typeof(*sci_dev), parent);
        /* Request the parent state machine to transition to the stopping state */
-       sci_base_state_machine_change_state(
-               scic_sds_remote_device_get_base_state_machine(this_device),
-               SCI_BASE_REMOTE_DEVICE_STATE_STOPPING
-               );
+       sci_base_state_machine_change_state(&base_dev->state_machine,
+                                           SCI_BASE_REMOTE_DEVICE_STATE_STOPPING);
 
-       if (this_device->started_request_count == 0) {
-               scic_sds_remote_node_context_destruct(
-                       this_device->rnc,
+       if (sci_dev->started_request_count == 0) {
+               scic_sds_remote_node_context_destruct(sci_dev->rnc,
                        scic_sds_cb_remote_device_rnc_destruct_complete,
-                       this_device
-                       );
+                       sci_dev);
        } else
-               status = scic_sds_remote_device_terminate_requests(this_device);
+               status = scic_sds_remote_device_terminate_requests(sci_dev);
 
        return status;
 }
@@ -1315,30 +1032,18 @@ enum sci_status scic_sds_remote_device_ready_state_stop_handler(
  * This is the ready state device reset handler enum sci_status
  */
 enum sci_status scic_sds_remote_device_ready_state_reset_handler(
-       struct sci_base_remote_device *device)
+       struct sci_base_remote_device *base_dev)
 {
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)device;
+       struct scic_sds_remote_device *sci_dev;
 
+       sci_dev = container_of(base_dev, typeof(*sci_dev), parent);
        /* Request the parent state machine to transition to the stopping state */
-       sci_base_state_machine_change_state(
-               scic_sds_remote_device_get_base_state_machine(this_device),
-               SCI_BASE_REMOTE_DEVICE_STATE_RESETTING
-               );
+       sci_base_state_machine_change_state(&base_dev->state_machine,
+                                           SCI_BASE_REMOTE_DEVICE_STATE_RESETTING);
 
        return SCI_SUCCESS;
 }
 
-/**
- *
- * @device: The struct sci_base_remote_device object which is cast to a
- *    struct scic_sds_remote_device object.
- *
- * This is the default fail handler for the struct scic_sds_remote_device ready
- * substate machine.  It will stop the current ready substate and transition
- * the remote device object to the SCI_BASE_REMOTE_DEVICE_STATE_FAILED.
- * enum sci_status SCI_SUCCESS
- */
-
 /**
  *
  * @device: The struct sci_base_remote_device which is cast to a
@@ -1775,19 +1480,15 @@ const struct scic_sds_remote_device_state_handler scic_sds_remote_device_state_h
 static void scic_sds_remote_device_initial_state_enter(
        struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
+       struct scic_sds_remote_device *sci_dev = (struct scic_sds_remote_device *)object;
 
-       SET_STATE_HANDLER(
-               this_device,
-               scic_sds_remote_device_state_handler_table,
-               SCI_BASE_REMOTE_DEVICE_STATE_INITIAL
-               );
+       sci_dev = container_of(object, typeof(*sci_dev), parent.parent);
+       SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
+                         SCI_BASE_REMOTE_DEVICE_STATE_INITIAL);
 
        /* Initial state is a transitional state to the stopped state */
-       sci_base_state_machine_change_state(
-               scic_sds_remote_device_get_base_state_machine(this_device),
-               SCI_BASE_REMOTE_DEVICE_STATE_STOPPED
-               );
+       sci_base_state_machine_change_state(&sci_dev->parent.state_machine,
+                                           SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
 }
 
 /**
@@ -1803,29 +1504,28 @@ static void scic_sds_remote_device_initial_state_enter(
 static void scic_sds_remote_device_stopped_state_enter(
        struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)object;
-       struct scic_sds_controller *scic =
-               scic_sds_remote_device_get_controller(sci_dev);
-       struct isci_host *ihost = sci_object_get_association(scic);
-       struct isci_remote_device *idev =
-               sci_object_get_association(sci_dev);
+       struct scic_sds_remote_device *sci_dev;
+       struct scic_sds_controller *scic;
+       struct isci_remote_device *idev;
+       struct isci_host *ihost;
+       u32 prev_state;
 
-       SET_STATE_HANDLER(sci_dev,
-                         scic_sds_remote_device_state_handler_table,
+       sci_dev = container_of(object, typeof(*sci_dev), parent.parent);
+       scic = scic_sds_remote_device_get_controller(sci_dev);
+       ihost = sci_object_get_association(scic);
+       idev = sci_object_get_association(sci_dev);
+
+       SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
                          SCI_BASE_REMOTE_DEVICE_STATE_STOPPED);
 
-       /*
-        * If we are entering from the stopping state let the SCI User know that
+       /* If we are entering from the stopping state let the SCI User know that
         * the stop operation has completed.
         */
-       if (sci_dev->parent.state_machine.previous_state_id ==
-                       SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
+       prev_state = sci_dev->parent.state_machine.previous_state_id;
+       if (prev_state == SCI_BASE_REMOTE_DEVICE_STATE_STOPPING)
                isci_remote_device_stop_complete(ihost, idev, SCI_SUCCESS);
 
-       scic_sds_controller_remote_device_stopped(
-               scic_sds_remote_device_get_controller(sci_dev),
-               sci_dev);
+       scic_sds_controller_remote_device_stopped(scic, sci_dev);
 }
 
 /**
index 4841e4579643801c42ec6d8301f778d3a3739f64..aa466249f229554a3b06b6ce8f570de93c0f52b3 100644 (file)
@@ -376,22 +376,6 @@ extern const struct scic_sds_remote_device_state_handler scic_sds_smp_remote_dev
 #define scic_sds_remote_device_set_state_handlers(this_device, handlers) \
        ((this_device)->state_handlers = (handlers))
 
-/**
- * scic_sds_remote_device_get_base_state_machine() -
- *
- * This macro returns the base sate machine object for the remote device.
- */
-#define scic_sds_remote_device_get_base_state_machine(this_device) \
-       (&(this_device)->parent.state_machine)
-
-/**
- * scic_sds_remote_device_get_ready_substate_machine() -
- *
- * This macro returns the remote device ready substate machine
- */
-#define scic_sds_remote_device_get_ready_substate_machine(this_device) \
-       (&(this_device)->ready_substate_machine)
-
 /**
  * scic_sds_remote_device_get_port() -
  *
index 86c6d75a111008919659193d8899e9fa12893a0f..c7c75ae6f092235ee81440c6e8b1fb8ee4afbc37 100644 (file)
@@ -296,9 +296,6 @@ void scic_sds_remote_node_context_construct_buffer(
 bool scic_sds_remote_node_context_is_ready(
        struct scic_sds_remote_node_context *this_rnc);
 
-#define scic_sds_remote_node_context_set_remote_node_index(rnc, rni) \
-       ((rnc)->remote_node_index = (rni))
-
 #define scic_sds_remote_node_context_get_remote_node_index(rcn)        \
        ((rnc)->remote_node_index)