isci: unify phy stop handlers

Merge all implementations in scic_sds_phy_stop(), and kill the state handler

Reported-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
diff --git a/drivers/scsi/isci/phy.c b/drivers/scsi/isci/phy.c
index 7cae192..cf8f2e9 100644
--- a/drivers/scsi/isci/phy.c
+++ b/drivers/scsi/isci/phy.c
@@ -463,16 +463,31 @@
 	return SCI_SUCCESS;
 }
 
-/**
- * This method will attempt to stop the phy object.
- * @sci_phy:
- *
- * enum sci_status SCI_SUCCESS if the phy is going to stop SCI_INVALID_STATE
- * if the phy is not in a valid state to stop
- */
 enum sci_status scic_sds_phy_stop(struct scic_sds_phy *sci_phy)
 {
-	return sci_phy->state_handlers->stop_handler(sci_phy);
+	enum scic_sds_phy_states state = sci_phy->state_machine.current_state_id;
+
+	switch (state) {
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF:
+	case SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL:
+	case SCI_BASE_PHY_STATE_READY:
+		break;
+	default:
+		dev_dbg(sciphy_to_dev(sci_phy),
+			"%s: in wrong state: %d\n", __func__, state);
+		return SCI_FAILURE_INVALID_STATE;
+	}
+
+	sci_base_state_machine_change_state(&sci_phy->state_machine,
+					    SCI_BASE_PHY_STATE_STOPPED);
+	return SCI_SUCCESS;
 }
 
 /**
@@ -611,23 +626,6 @@
 					    SCI_BASE_PHY_STATE_STARTING);
 }
 
-/* ****************************************************************************
-   * SCIC SDS PHY general handlers
-   ************************************************************************** */
-static enum sci_status scic_sds_phy_starting_substate_general_stop_handler(
-	struct scic_sds_phy *phy)
-{
-	sci_base_state_machine_change_state(&phy->state_machine,
-						 SCI_BASE_PHY_STATE_STOPPED);
-
-	return SCI_SUCCESS;
-}
-
-/*
- * *****************************************************************************
- * * SCIC SDS PHY EVENT_HANDLERS
- * ***************************************************************************** */
-
 /**
  *
  * @phy: This struct scic_sds_phy object which has received an event.
@@ -1268,12 +1266,6 @@
 }
 
 static enum sci_status
-scic_sds_phy_default_stop_handler(struct scic_sds_phy *sci_phy)
-{
-	return default_phy_handler(sci_phy, __func__);
-}
-
-static enum sci_status
 scic_sds_phy_default_reset_handler(struct scic_sds_phy *sci_phy)
 {
 	return default_phy_handler(sci_phy, __func__);
@@ -1317,15 +1309,6 @@
 }
 
 static enum sci_status
-scic_sds_phy_ready_state_stop_handler(struct scic_sds_phy *sci_phy)
-{
-	sci_base_state_machine_change_state(&sci_phy->state_machine,
-					    SCI_BASE_PHY_STATE_STOPPED);
-
-	return SCI_SUCCESS;
-}
-
-static enum sci_status
 scic_sds_phy_ready_state_reset_handler(struct scic_sds_phy *sci_phy)
 {
 	sci_base_state_machine_change_state(&sci_phy->state_machine,
@@ -1409,7 +1392,6 @@
 
 static const struct scic_sds_phy_state_handler scic_sds_phy_state_handler_table[] = {
 	[SCI_BASE_PHY_STATE_INITIAL] = {
-		.stop_handler  = scic_sds_phy_default_stop_handler,
 		.reset_handler = scic_sds_phy_default_reset_handler,
 		.destruct_handler = scic_sds_phy_default_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
@@ -1417,7 +1399,6 @@
 		.consume_power_handler	 = scic_sds_phy_default_consume_power_handler
 	},
 	[SCI_BASE_PHY_STATE_STOPPED]  = {
-		.stop_handler  = scic_sds_phy_default_stop_handler,
 		.reset_handler = scic_sds_phy_default_reset_handler,
 		.destruct_handler = scic_sds_phy_stopped_state_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
@@ -1425,7 +1406,6 @@
 		.consume_power_handler	 = scic_sds_phy_default_consume_power_handler
 	},
 	[SCI_BASE_PHY_STATE_STARTING] = {
-		.stop_handler  = scic_sds_phy_default_stop_handler,
 		.reset_handler = scic_sds_phy_default_reset_handler,
 		.destruct_handler = scic_sds_phy_default_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
@@ -1433,7 +1413,6 @@
 		.consume_power_handler	 = scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_INITIAL] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1441,7 +1420,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_OSSP_EN] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1449,7 +1427,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_SPEED_EN] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1457,7 +1434,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_IAF_UF] = {
-		.stop_handler		= scic_sds_phy_default_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_starting_substate_await_iaf_uf_frame_handler,
@@ -1465,7 +1441,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SAS_POWER] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1473,7 +1448,6 @@
 		.consume_power_handler	= scic_sds_phy_starting_substate_await_sas_power_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_POWER] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1481,7 +1455,6 @@
 		.consume_power_handler	= scic_sds_phy_starting_substate_await_sata_power_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_PHY_EN] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1489,7 +1462,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SATA_SPEED_EN] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_default_frame_handler,
@@ -1497,7 +1469,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_AWAIT_SIG_FIS_UF] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		= scic_sds_phy_starting_substate_await_sig_fis_frame_handler,
@@ -1505,7 +1476,6 @@
 		.consume_power_handler	= scic_sds_phy_default_consume_power_handler
 	},
 	[SCIC_SDS_PHY_STARTING_SUBSTATE_FINAL] = {
-		.stop_handler		= scic_sds_phy_starting_substate_general_stop_handler,
 		.reset_handler		= scic_sds_phy_default_reset_handler,
 		.destruct_handler	= scic_sds_phy_default_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
@@ -1513,7 +1483,6 @@
 		.consume_power_handler	 = scic_sds_phy_default_consume_power_handler
 	},
 	[SCI_BASE_PHY_STATE_READY] = {
-		.stop_handler  = scic_sds_phy_ready_state_stop_handler,
 		.reset_handler = scic_sds_phy_ready_state_reset_handler,
 		.destruct_handler = scic_sds_phy_default_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
@@ -1521,7 +1490,6 @@
 		.consume_power_handler	 = scic_sds_phy_default_consume_power_handler
 	},
 	[SCI_BASE_PHY_STATE_RESETTING] = {
-		.stop_handler  = scic_sds_phy_default_stop_handler,
 		.reset_handler = scic_sds_phy_default_reset_handler,
 		.destruct_handler = scic_sds_phy_default_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
@@ -1529,7 +1497,6 @@
 		.consume_power_handler	 = scic_sds_phy_default_consume_power_handler
 	},
 	[SCI_BASE_PHY_STATE_FINAL] = {
-		.stop_handler  = scic_sds_phy_default_stop_handler,
 		.reset_handler = scic_sds_phy_default_reset_handler,
 		.destruct_handler = scic_sds_phy_default_destroy_handler,
 		.frame_handler		 = scic_sds_phy_default_frame_handler,
diff --git a/drivers/scsi/isci/phy.h b/drivers/scsi/isci/phy.h
index 9b7d54e..d829e15 100644
--- a/drivers/scsi/isci/phy.h
+++ b/drivers/scsi/isci/phy.h
@@ -512,12 +512,6 @@
 
 struct scic_sds_phy_state_handler {
 	/**
-	 * The stop_handler specifies the method invoked when there is an
-	 * attempt to stop a phy.
-	 */
-	scic_sds_phy_handler_t stop_handler;
-
-	/**
 	 * The reset_handler specifies the method invoked when there is an
 	 * attempt to reset a phy.
 	 */