]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
firmware: arm_scmi: Add helper to trace bad messages
authorCristian Marussi <cristian.marussi@arm.com>
Mon, 25 Mar 2024 20:46:17 +0000 (20:46 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 May 2025 12:12:12 +0000 (14:12 +0200)
[ Upstream commit 5dc0e0b1f0ea2b55031f84a365962b9b45869b98 ]

Upon reception of malformed and unexpected timed-out SCMI messages, it is
not possible to trace those bad messages in their entirety, because usually
we cannot even retrieve the payload, or it is just not reliable.

Add a helper to trace at least the content of the header of the received
message while associating a meaningful tag and error code.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20240325204620.1437237-3-cristian.marussi@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Stable-dep-of: c23c03bf1faa ("firmware: arm_scmi: Fix timeout checks on polling path")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/firmware/arm_scmi/common.h
drivers/firmware/arm_scmi/driver.c

index 039f686f4580d17c5f22c7e0a4c279bbca77c088..e26a2856a0e3d618242c4a8c1df27530e53e37d5 100644 (file)
@@ -303,6 +303,17 @@ extern const struct scmi_desc scmi_optee_desc;
 
 void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *priv);
 
+enum scmi_bad_msg {
+       MSG_UNEXPECTED = -1,
+       MSG_INVALID = -2,
+       MSG_UNKNOWN = -3,
+       MSG_NOMEM = -4,
+       MSG_MBOX_SPURIOUS = -5,
+};
+
+void scmi_bad_message_trace(struct scmi_chan_info *cinfo, u32 msg_hdr,
+                           enum scmi_bad_msg err);
+
 /* shmem related declarations */
 struct scmi_shared_mem;
 
index efa9698c876a093a6c00d3bc8fded250887b7946..b3c2a199b2afb5804f64e64cbe9539a41d4f8f8e 100644 (file)
@@ -687,6 +687,45 @@ scmi_xfer_lookup_unlocked(struct scmi_xfers_info *minfo, u16 xfer_id)
        return xfer ?: ERR_PTR(-EINVAL);
 }
 
+/**
+ * scmi_bad_message_trace  - A helper to trace weird messages
+ *
+ * @cinfo: A reference to the channel descriptor on which the message was
+ *        received
+ * @msg_hdr: Message header to track
+ * @err: A specific error code used as a status value in traces.
+ *
+ * This helper can be used to trace any kind of weird, incomplete, unexpected,
+ * timed-out message that arrives and as such, can be traced only referring to
+ * the header content, since the payload is missing/unreliable.
+ */
+void scmi_bad_message_trace(struct scmi_chan_info *cinfo, u32 msg_hdr,
+                           enum scmi_bad_msg err)
+{
+       char *tag;
+       struct scmi_info *info = handle_to_scmi_info(cinfo->handle);
+
+       switch (MSG_XTRACT_TYPE(msg_hdr)) {
+       case MSG_TYPE_COMMAND:
+               tag = "!RESP";
+               break;
+       case MSG_TYPE_DELAYED_RESP:
+               tag = "!DLYD";
+               break;
+       case MSG_TYPE_NOTIFICATION:
+               tag = "!NOTI";
+               break;
+       default:
+               tag = "!UNKN";
+               break;
+       }
+
+       trace_scmi_msg_dump(info->id, cinfo->id,
+                           MSG_XTRACT_PROT_ID(msg_hdr),
+                           MSG_XTRACT_ID(msg_hdr), tag,
+                           MSG_XTRACT_TOKEN(msg_hdr), err, NULL, 0);
+}
+
 /**
  * scmi_msg_response_validate  - Validate message type against state of related
  * xfer