diff mbox series

[RFC,v3,07/12] firmware: arm_scmi: Add msg_handle to some transport ops

Message ID 20210511002040.802226-8-peter.hilber@opensynergy.com (mailing list archive)
State New, archived
Headers show
Series firmware: arm_scmi: Add virtio transport | expand

Commit Message

Peter Hilber May 11, 2021, 12:20 a.m. UTC
The upcoming virtio transport may xfer several SCMI messages in parallel
on a channel. But the transport ops which fetch messages lack
information through which a transport can determine which of several
messages the core intends to address. The virtio transport should not
rely on the current implementation details of the core to deduce the
message.

Disambiguate this by having the transport pass an opaque message handle
to scmi_rx_callback(), which the transport will then use in the message
fetching transport ops to identify which message to address. Do not
address how to handle the polling mechanism for now.

The existing transports can just ignore the message handle.

Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com>
---
 drivers/firmware/arm_scmi/common.h  |  8 ++++----
 drivers/firmware/arm_scmi/driver.c  | 20 +++++++++++---------
 drivers/firmware/arm_scmi/mailbox.c |  7 ++++---
 drivers/firmware/arm_scmi/smc.c     |  5 +++--
 4 files changed, 22 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index 9488c682a51d..5ab2ea0f7db2 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -310,9 +310,9 @@  struct scmi_transport_ops {
 			    struct scmi_xfer *xfer);
 	void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret);
 	void (*fetch_response)(struct scmi_chan_info *cinfo,
-			       struct scmi_xfer *xfer);
-	void (*fetch_notification)(struct scmi_chan_info *cinfo,
-				   size_t max_len, struct scmi_xfer *xfer);
+			       struct scmi_xfer *xfer, void *msg_handle);
+	void (*fetch_notification)(struct scmi_chan_info *cinfo, size_t max_len,
+				   struct scmi_xfer *xfer, void *msg_handle);
 	void (*clear_channel)(struct scmi_chan_info *cinfo);
 	bool (*poll_done)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer);
 };
@@ -350,7 +350,7 @@  extern const struct scmi_desc scmi_smc_desc;
 
 int scmi_set_transport_info(struct device *dev, void *transport_info);
 void *scmi_get_transport_info(struct device *dev);
-void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr);
+void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *msg_handle);
 void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id);
 
 /* shmem related declarations */
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 581b6c9b3781..cc27978b4bea 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -272,7 +272,8 @@  __scmi_xfer_put(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer)
 	spin_unlock_irqrestore(&minfo->xfer_lock, flags);
 }
 
-static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr)
+static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr,
+				     void *msg_handle)
 {
 	struct scmi_xfer *xfer;
 	struct device *dev = cinfo->dev;
@@ -292,7 +293,7 @@  static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr)
 	unpack_scmi_header(msg_hdr, &xfer->hdr);
 	scmi_dump_header_dbg(dev, &xfer->hdr);
 	info->desc->ops->fetch_notification(cinfo, info->desc->max_msg_size,
-					    xfer);
+					    xfer, msg_handle);
 	scmi_notify(cinfo->handle, xfer->hdr.protocol_id,
 		    xfer->hdr.id, xfer->rx.buf, xfer->rx.len, ts);
 
@@ -305,8 +306,8 @@  static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr)
 	info->desc->ops->clear_channel(cinfo);
 }
 
-static void scmi_handle_response(struct scmi_chan_info *cinfo,
-				 u16 xfer_id, u8 msg_type)
+static void scmi_handle_response(struct scmi_chan_info *cinfo, u16 xfer_id,
+				 u8 msg_type, void *msg_handle)
 {
 	struct scmi_xfer *xfer;
 	struct device *dev = cinfo->dev;
@@ -339,7 +340,7 @@  static void scmi_handle_response(struct scmi_chan_info *cinfo,
 
 	scmi_dump_header_dbg(dev, &xfer->hdr);
 
-	info->desc->ops->fetch_response(cinfo, xfer);
+	info->desc->ops->fetch_response(cinfo, xfer, msg_handle);
 
 	trace_scmi_rx_done(xfer->transfer_id, xfer->hdr.id,
 			   xfer->hdr.protocol_id, xfer->hdr.seq,
@@ -365,18 +366,19 @@  static void scmi_handle_response(struct scmi_chan_info *cinfo,
  * NOTE: This function will be invoked in IRQ context, hence should be
  * as optimal as possible.
  */
-void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr)
+void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr,
+		      void *msg_handle)
 {
 	u16 xfer_id = MSG_XTRACT_TOKEN(msg_hdr);
 	u8 msg_type = MSG_XTRACT_TYPE(msg_hdr);
 
 	switch (msg_type) {
 	case MSG_TYPE_NOTIFICATION:
-		scmi_handle_notification(cinfo, msg_hdr);
+		scmi_handle_notification(cinfo, msg_hdr, msg_handle);
 		break;
 	case MSG_TYPE_COMMAND:
 	case MSG_TYPE_DELAYED_RESP:
-		scmi_handle_response(cinfo, xfer_id, msg_type);
+		scmi_handle_response(cinfo, xfer_id, msg_type, msg_handle);
 		break;
 	default:
 		WARN_ONCE(1, "received unknown msg_type:%d\n", msg_type);
@@ -490,7 +492,7 @@  static int do_xfer(const struct scmi_protocol_handle *ph,
 		spin_until_cond(scmi_xfer_done_no_timeout(cinfo, xfer, stop));
 
 		if (ktime_before(ktime_get(), stop))
-			info->desc->ops->fetch_response(cinfo, xfer);
+			info->desc->ops->fetch_response(cinfo, xfer, NULL);
 		else
 			ret = -ETIMEDOUT;
 	} else {
diff --git a/drivers/firmware/arm_scmi/mailbox.c b/drivers/firmware/arm_scmi/mailbox.c
index 4626404be541..584d7dcde2eb 100644
--- a/drivers/firmware/arm_scmi/mailbox.c
+++ b/drivers/firmware/arm_scmi/mailbox.c
@@ -43,7 +43,7 @@  static void rx_callback(struct mbox_client *cl, void *m)
 {
 	struct scmi_mailbox *smbox = client_to_scmi_mailbox(cl);
 
-	scmi_rx_callback(smbox->cinfo, shmem_read_header(smbox->shmem));
+	scmi_rx_callback(smbox->cinfo, shmem_read_header(smbox->shmem), NULL);
 }
 
 static bool mailbox_chan_available(struct device *dev, int idx)
@@ -151,7 +151,7 @@  static void mailbox_mark_txdone(struct scmi_chan_info *cinfo, int ret)
 }
 
 static void mailbox_fetch_response(struct scmi_chan_info *cinfo,
-				   struct scmi_xfer *xfer)
+				   struct scmi_xfer *xfer, void *msg_handle)
 {
 	struct scmi_mailbox *smbox = cinfo->transport_info;
 
@@ -159,7 +159,8 @@  static void mailbox_fetch_response(struct scmi_chan_info *cinfo,
 }
 
 static void mailbox_fetch_notification(struct scmi_chan_info *cinfo,
-				       size_t max_len, struct scmi_xfer *xfer)
+				       size_t max_len, struct scmi_xfer *xfer,
+				       void *msg_handle)
 {
 	struct scmi_mailbox *smbox = cinfo->transport_info;
 
diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c
index fcbe2677f84b..507107d1a4ad 100644
--- a/drivers/firmware/arm_scmi/smc.c
+++ b/drivers/firmware/arm_scmi/smc.c
@@ -151,7 +151,8 @@  static int smc_send_message(struct scmi_chan_info *cinfo,
 	if (scmi_info->irq)
 		wait_for_completion(&scmi_info->tx_complete);
 
-	scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem));
+	scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem),
+			 NULL);
 
 	mutex_unlock(&scmi_info->shmem_lock);
 
@@ -162,7 +163,7 @@  static int smc_send_message(struct scmi_chan_info *cinfo,
 }
 
 static void smc_fetch_response(struct scmi_chan_info *cinfo,
-			       struct scmi_xfer *xfer)
+			       struct scmi_xfer *xfer, void *msg_handle)
 {
 	struct scmi_smc *scmi_info = cinfo->transport_info;