isci: cleanup isci_remote_device[_not]_ready interface
authorDan Williams <dan.j.williams@intel.com>
Thu, 31 Mar 2011 20:10:42 +0000 (13:10 -0700)
committerDan Williams <dan.j.williams@intel.com>
Sun, 3 Jul 2011 11:00:36 +0000 (04:00 -0700)
Require a valid isci_host in support of the general cleanup to not
re-lookup the host via potentially fragile methods when more robust
methods are available.  Also cleans up some more casting that should be
using container_of() to up-cast a base structure in a more type-safe
manner.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/scsi/isci/core/scic_sds_remote_device.c
drivers/scsi/isci/core/scic_sds_smp_remote_device.c
drivers/scsi/isci/core/scic_sds_stp_remote_device.c
drivers/scsi/isci/remote_device.c
drivers/scsi/isci/remote_device.h

index e100fde..a6bcaa1 100644 (file)
@@ -1513,24 +1513,19 @@ static void scic_sds_remote_device_stopped_state_enter(
  * sets the starting state handlers, sets the device not ready, and posts the
  * remote node context to the hardware. none
  */
-static void scic_sds_remote_device_starting_state_enter(
-       struct sci_base_object *object)
+static void scic_sds_remote_device_starting_state_enter(struct sci_base_object *object)
 {
-       struct scic_sds_controller *scic;
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)object;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       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);
 
-       scic = scic_sds_remote_device_get_controller(sci_dev);
-
-       SET_STATE_HANDLER(
-                       sci_dev,
-                       scic_sds_remote_device_state_handler_table,
-                       SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
+       SET_STATE_HANDLER(sci_dev, scic_sds_remote_device_state_handler_table,
+                         SCI_BASE_REMOTE_DEVICE_STATE_STARTING);
 
-       isci_remote_device_not_ready(
-                       idev,
-                       SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
+       isci_remote_device_not_ready(ihost, idev,
+                                    SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED);
 }
 
 static void scic_sds_remote_device_starting_state_exit(struct sci_base_object *object)
@@ -1556,14 +1551,13 @@ static void scic_sds_remote_device_starting_state_exit(struct sci_base_object *o
  * This is the enter function for the SCI_BASE_REMOTE_DEVICE_STATE_READY it sets
  * the ready state handlers, and starts the ready substate machine. none
  */
-static void scic_sds_remote_device_ready_state_enter(
-       struct sci_base_object *object)
+static void scic_sds_remote_device_ready_state_enter(struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)object;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       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_controller *scic
-               = scic_sds_remote_device_get_controller(sci_dev);
 
        SET_STATE_HANDLER(sci_dev,
                          scic_sds_remote_device_state_handler_table,
@@ -1574,7 +1568,7 @@ static void scic_sds_remote_device_ready_state_enter(
        if (sci_dev->has_ready_substate_machine)
                sci_base_state_machine_start(&sci_dev->ready_substate_machine);
        else
-               isci_remote_device_ready(idev);
+               isci_remote_device_ready(ihost, idev);
 }
 
 /**
@@ -1588,16 +1582,18 @@ static void scic_sds_remote_device_ready_state_enter(
 static void scic_sds_remote_device_ready_state_exit(
        struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)object;
-       struct isci_remote_device *idev = sci_object_get_association(sci_dev);
-
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
        if (sci_dev->has_ready_substate_machine)
                sci_base_state_machine_stop(&sci_dev->ready_substate_machine);
-       else
-               isci_remote_device_not_ready(
-                               idev,
-                               SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
+       else {
+               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);
+
+               isci_remote_device_not_ready(ihost, idev,
+                                            SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED);
+       }
 }
 
 /**
index 5520248..06cb932 100644 (file)
@@ -253,20 +253,19 @@ static const struct scic_sds_remote_device_state_handler scic_sds_smp_remote_dev
  * This function sets the ready cmd substate handlers and reports the device as
  * ready. none
  */
-static inline void scic_sds_smp_remote_device_ready_idle_substate_enter(
-       struct sci_base_object *object)
+static void scic_sds_smp_remote_device_ready_idle_substate_enter(struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)object;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       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);
 
+       SET_STATE_HANDLER(sci_dev,
+                         scic_sds_smp_remote_device_ready_substate_handler_table,
+                         SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
 
-       SET_STATE_HANDLER(
-                       sci_dev,
-                       scic_sds_smp_remote_device_ready_substate_handler_table,
-                       SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE);
-
-       isci_remote_device_ready(idev);
+       isci_remote_device_ready(ihost, idev);
 }
 
 /**
@@ -281,20 +280,20 @@ static inline void scic_sds_smp_remote_device_ready_idle_substate_enter(
 static void scic_sds_smp_remote_device_ready_cmd_substate_enter(
        struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)object;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       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);
 
        BUG_ON(sci_dev->working_request == NULL);
 
-       SET_STATE_HANDLER(
-                       sci_dev,
-                       scic_sds_smp_remote_device_ready_substate_handler_table,
-                       SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
+       SET_STATE_HANDLER(sci_dev,
+                         scic_sds_smp_remote_device_ready_substate_handler_table,
+                         SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
 
-       isci_remote_device_not_ready(
-                       idev,
-                       SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
+       isci_remote_device_not_ready(ihost, idev,
+                                    SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED);
 }
 
 /**
@@ -304,12 +303,11 @@ static void scic_sds_smp_remote_device_ready_cmd_substate_enter(
  *
  * This is the SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_CMD exit method. none
  */
-static void scic_sds_smp_remote_device_ready_cmd_substate_exit(
-       struct sci_base_object *object)
+static void scic_sds_smp_remote_device_ready_cmd_substate_exit(struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *this_device = (struct scic_sds_remote_device *)object;
-
-       this_device->working_request = NULL;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       sci_dev->working_request = NULL;
 }
 
 /* --------------------------------------------------------------------------- */
index 193a95f..0a00a40 100644 (file)
@@ -677,13 +677,13 @@ static const struct scic_sds_remote_device_state_handler scic_sds_stp_remote_dev
  * *  STP REMOTE DEVICE READY SUBSTATE PRIVATE METHODS
  * ***************************************************************************** */
 
-static inline void
-scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(
-               void *user_cookie)
+static void
+scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(void *user_cookie)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)user_cookie;
+       struct scic_sds_remote_device *sci_dev = user_cookie;
        struct isci_remote_device *idev = sci_object_get_association(sci_dev);
+       struct scic_sds_controller *scic = scic_sds_remote_device_get_controller(sci_dev);
+       struct isci_host *ihost = sci_object_get_association(scic);
 
        /*
         * For NCQ operation we do not issue a
@@ -692,7 +692,7 @@ scic_sds_stp_remote_device_ready_idle_substate_resume_complete_handler(
         */
        if (sci_dev->ready_substate_machine.previous_state_id !=
                        SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ)
-               isci_remote_device_ready(idev);
+               isci_remote_device_ready(ihost, idev);
 }
 
 /*
@@ -737,87 +737,48 @@ static void scic_sds_stp_remote_device_ready_idle_substate_enter(
        }
 }
 
-/*
- * *****************************************************************************
- * *  STP REMOTE DEVICE READY CMD SUBSTATE
- * ***************************************************************************** */
-
-/**
- *
- * @device: This is the SCI base object which is cast into a
- *    struct scic_sds_remote_device object.
- *
- */
-static inline void scic_sds_stp_remote_device_ready_cmd_substate_enter(
-       struct sci_base_object *device)
+static void scic_sds_stp_remote_device_ready_cmd_substate_enter(struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)device;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       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);
 
        BUG_ON(sci_dev->working_request == NULL);
 
-       SET_STATE_HANDLER(
-                       sci_dev,
-                       scic_sds_stp_remote_device_ready_substate_handler_table,
-                       SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
+       SET_STATE_HANDLER(sci_dev,
+                         scic_sds_stp_remote_device_ready_substate_handler_table,
+                         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD);
 
-       isci_remote_device_not_ready(
-                       idev,
-                       SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED);
+       isci_remote_device_not_ready(ihost, idev,
+                                    SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED);
 }
 
-/*
- * *****************************************************************************
- * *  STP REMOTE DEVICE READY NCQ SUBSTATE
- * ***************************************************************************** */
-
-/**
- *
- * @device: This is the SCI base object which is cast into a
- *    struct scic_sds_remote_device object.
- *
- */
-static void scic_sds_stp_remote_device_ready_ncq_substate_enter(
-       struct sci_base_object *device)
+static void scic_sds_stp_remote_device_ready_ncq_substate_enter(struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *this_device;
-
-       this_device = (struct scic_sds_remote_device *)device;
-
-       SET_STATE_HANDLER(
-               this_device,
-               scic_sds_stp_remote_device_ready_substate_handler_table,
-               SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ
-               );
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       SET_STATE_HANDLER(sci_dev,
+                         scic_sds_stp_remote_device_ready_substate_handler_table,
+                         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ);
 }
 
-/*
- * *****************************************************************************
- * *  STP REMOTE DEVICE READY NCQ ERROR SUBSTATE
- * ***************************************************************************** */
-
-/**
- *
- * @device: This is the SCI base object which is cast into a
- *    struct scic_sds_remote_device object.
- *
- */
-static inline void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(
-       struct sci_base_object *device)
+static void scic_sds_stp_remote_device_ready_ncq_error_substate_enter(struct sci_base_object *object)
 {
-       struct scic_sds_remote_device *sci_dev =
-               (struct scic_sds_remote_device *)device;
+       struct scic_sds_remote_device *sci_dev = container_of(object, typeof(*sci_dev),
+                                                             parent.parent);
+       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);
 
-       SET_STATE_HANDLER(
-                       sci_dev,
-                       scic_sds_stp_remote_device_ready_substate_handler_table,
-                       SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
+       SET_STATE_HANDLER(sci_dev,
+                         scic_sds_stp_remote_device_ready_substate_handler_table,
+                         SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR);
 
        if (sci_dev->not_ready_reason ==
                SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED)
-               isci_remote_device_not_ready(idev, sci_dev->not_ready_reason);
+               isci_remote_device_not_ready(ihost, idev, sci_dev->not_ready_reason);
 }
 
 /*
index 6fe6815..0fdaa6d 100644 (file)
@@ -281,13 +281,12 @@ isci_remote_device_alloc(struct isci_host *ihost, struct isci_port *iport)
  * isci_remote_device_ready() - This function is called by the scic when the
  *    remote device is ready. We mark the isci device as ready and signal the
  *    waiting proccess.
- * @idev: This parameter specifies the remote device
+ * @ihost: our valid isci_host
+ * @idev: remote device
  *
  */
-void isci_remote_device_ready(struct isci_remote_device *idev)
+void isci_remote_device_ready(struct isci_host *ihost, struct isci_remote_device *idev)
 {
-       struct isci_host *ihost = idev->isci_port->isci_host;
-
        dev_dbg(&ihost->pdev->dev,
                "%s: idev = %p\n", __func__, idev);
 
@@ -304,18 +303,17 @@ void isci_remote_device_ready(struct isci_remote_device *idev)
  * @isci_device: This parameter specifies the remote device
  *
  */
-void isci_remote_device_not_ready(
-       struct isci_remote_device *isci_device,
-       u32 reason_code)
+void isci_remote_device_not_ready(struct isci_host *ihost,
+                                 struct isci_remote_device *idev, u32 reason)
 {
-       dev_dbg(&isci_device->isci_port->isci_host->pdev->dev,
-               "%s: isci_device = %p\n", __func__, isci_device);
+       dev_dbg(&ihost->pdev->dev,
+               "%s: isci_device = %p\n", __func__, idev);
 
-       if (reason_code == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED)
-               isci_remote_device_change_state(isci_device, isci_stopping);
+       if (reason == SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED)
+               isci_remote_device_change_state(idev, isci_stopping);
        else
                /* device ready is actually a "not ready for io" state. */
-               isci_remote_device_change_state(isci_device, isci_ready);
+               isci_remote_device_change_state(idev, isci_ready);
 }
 
 /**
index f45a5f0..cf5302a 100644 (file)
@@ -109,12 +109,11 @@ enum sci_status isci_remote_device_stop(struct isci_host *ihost,
 void isci_remote_device_nuke_requests(
        struct isci_remote_device *isci_device);
 
-void isci_remote_device_ready(
-       struct isci_remote_device *);
+void isci_remote_device_ready(struct isci_host *ihost,
+                             struct isci_remote_device *idev);
 
-void isci_remote_device_not_ready(
-       struct isci_remote_device *,
-       u32);
+void isci_remote_device_not_ready(struct isci_host *ihost,
+                                 struct isci_remote_device *idev, u32 reason);
 
 void isci_remote_device_gone(
        struct domain_device *domain_dev);