[PATCH v4 16/16] firmware: arm_scmi: Add polling mode to virtio transport

From: Cristian Marussi
Date: Fri Jun 11 2021 - 13:01:48 EST


Enable polling mode support to virtio transport.

Upon reception of a synchronous command response for a transfer that has
the hdr.poll_completion flag set, virtio transport now simply completes the
same completion which .poll_done() is spinning on.

Signed-off-by: Cristian Marussi <cristian.marussi@xxxxxxx>
---
Note that as of now in order to test this you have to forcibly
enable hdr.poll_completion in the core and increase SCMI_MAX_POLL_TO_NS.

These workarounds won't be needed anymore once addressed by a distinct
series currently under review.
---
drivers/firmware/arm_scmi/virtio.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c
index 4412bc590ca7..f77c7f288d4c 100644
--- a/drivers/firmware/arm_scmi/virtio.c
+++ b/drivers/firmware/arm_scmi/virtio.c
@@ -158,12 +158,12 @@ static void scmi_process_vqueue_input(struct scmi_vio_channel *vioch,
/* Drop processed virtio message anyway */
scmi_finalize_message(vioch, msg);

+ /* Deliver DRESP, NOTIF and non-polled RESP */
if (vioch->is_rx || !xfer->hdr.poll_completion)
scmi_rx_callback(vioch->cinfo, msg_hdr);
else
- dev_warn(vioch->cinfo->dev,
- "Polling mode NOT supported. Dropped hdr:0X%X\n",
- msg_hdr);
+ /* poll_done() is busy-waiting on this */
+ complete(&xfer->done);

scmi_transfer_release(vioch->cinfo, xfer);
}
@@ -414,10 +414,16 @@ static void dummy_clear_channel(struct scmi_chan_info *cinfo)
{
}

-static bool dummy_poll_done(struct scmi_chan_info *cinfo,
- struct scmi_xfer *xfer)
+static bool virtio_poll_done(struct scmi_chan_info *cinfo,
+ struct scmi_xfer *xfer)
{
- return false;
+ /*
+ * In polling mode SCMI core does not use xfer->done completion,
+ * so we can busy-wait on this same completion without adding
+ * a new flag: this is completed properly upon msg reception in
+ * scmi_process_vqueue_input().
+ */
+ return try_wait_for_completion(&xfer->done);
}

static const struct scmi_transport_ops scmi_virtio_ops = {
@@ -430,7 +436,7 @@ static const struct scmi_transport_ops scmi_virtio_ops = {
.fetch_response = virtio_fetch_response,
.fetch_notification = virtio_fetch_notification,
.clear_channel = dummy_clear_channel,
- .poll_done = dummy_poll_done,
+ .poll_done = virtio_poll_done,
};

static int scmi_vio_probe(struct virtio_device *vdev)
--
2.17.1