firmware: arm_scmi: Refactor scmi_wait_for_message_response
authorCristian Marussi <cristian.marussi@arm.com>
Wed, 18 Jan 2023 12:14:12 +0000 (12:14 +0000)
committerSudeep Holla <sudeep.holla@arm.com>
Fri, 20 Jan 2023 11:40:36 +0000 (11:40 +0000)
Refactor scmi_wait_for_message_response() to use a internal helper to
carry out its main duties; while doing that make it accept directly an
scmi_desc parameter to interact with the configured transport.

No functional change.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://lore.kernel.org/r/20230118121426.492864-4-cristian.marussi@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/firmware/arm_scmi/driver.c

index d7f21e8..ce204a7 100644 (file)
@@ -891,36 +891,18 @@ static bool scmi_xfer_done_no_timeout(struct scmi_chan_info *cinfo,
               ktime_after(ktime_get(), stop);
 }
 
-/**
- * scmi_wait_for_message_response  - An helper to group all the possible ways of
- * waiting for a synchronous message response.
- *
- * @cinfo: SCMI channel info
- * @xfer: Reference to the transfer being waited for.
- *
- * Chooses waiting strategy (sleep-waiting vs busy-waiting) depending on
- * configuration flags like xfer->hdr.poll_completion.
- *
- * Return: 0 on Success, error otherwise.
- */
-static int scmi_wait_for_message_response(struct scmi_chan_info *cinfo,
-                                         struct scmi_xfer *xfer)
+static int scmi_wait_for_reply(struct device *dev, const struct scmi_desc *desc,
+                              struct scmi_chan_info *cinfo,
+                              struct scmi_xfer *xfer, unsigned int timeout_ms)
 {
-       struct scmi_info *info = handle_to_scmi_info(cinfo->handle);
-       struct device *dev = info->dev;
-       int ret = 0, timeout_ms = info->desc->max_rx_timeout_ms;
-
-       trace_scmi_xfer_response_wait(xfer->transfer_id, xfer->hdr.id,
-                                     xfer->hdr.protocol_id, xfer->hdr.seq,
-                                     timeout_ms,
-                                     xfer->hdr.poll_completion);
+       int ret = 0;
 
        if (xfer->hdr.poll_completion) {
                /*
                 * Real polling is needed only if transport has NOT declared
                 * itself to support synchronous commands replies.
                 */
-               if (!info->desc->sync_cmds_completed_on_ret) {
+               if (!desc->sync_cmds_completed_on_ret) {
                        /*
                         * Poll on xfer using transport provided .poll_done();
                         * assumes no completion interrupt was available.
@@ -946,7 +928,7 @@ static int scmi_wait_for_message_response(struct scmi_chan_info *cinfo,
                         */
                        spin_lock_irqsave(&xfer->lock, flags);
                        if (xfer->state == SCMI_XFER_SENT_OK) {
-                               info->desc->ops->fetch_response(cinfo, xfer);
+                               desc->ops->fetch_response(cinfo, xfer);
                                xfer->state = SCMI_XFER_RESP_OK;
                        }
                        spin_unlock_irqrestore(&xfer->lock, flags);
@@ -971,6 +953,33 @@ static int scmi_wait_for_message_response(struct scmi_chan_info *cinfo,
 }
 
 /**
+ * scmi_wait_for_message_response  - An helper to group all the possible ways of
+ * waiting for a synchronous message response.
+ *
+ * @cinfo: SCMI channel info
+ * @xfer: Reference to the transfer being waited for.
+ *
+ * Chooses waiting strategy (sleep-waiting vs busy-waiting) depending on
+ * configuration flags like xfer->hdr.poll_completion.
+ *
+ * Return: 0 on Success, error otherwise.
+ */
+static int scmi_wait_for_message_response(struct scmi_chan_info *cinfo,
+                                         struct scmi_xfer *xfer)
+{
+       struct scmi_info *info = handle_to_scmi_info(cinfo->handle);
+       struct device *dev = info->dev;
+
+       trace_scmi_xfer_response_wait(xfer->transfer_id, xfer->hdr.id,
+                                     xfer->hdr.protocol_id, xfer->hdr.seq,
+                                     info->desc->max_rx_timeout_ms,
+                                     xfer->hdr.poll_completion);
+
+       return scmi_wait_for_reply(dev, info->desc, cinfo, xfer,
+                                  info->desc->max_rx_timeout_ms);
+}
+
+/**
  * do_xfer() - Do one transfer
  *
  * @ph: Pointer to SCMI protocol handle