diff mbox series

[03/14] core/pldm: Decode the PlatformEventMessage request

Message ID 20220419134633.42098-5-clombard@linux.vnet.ibm.com
State Superseded
Headers show
Series Complete PLDM responder and enable PLDM support | expand

Commit Message

Christophe Lombard April 19, 2022, 1:46 p.m. UTC
PLDM Event Messages are sent as PLDM request messages to the Event Receiver
using the PlatformEventMessage command.

The Event Receiver acknowledges receiving the PLDM Event Message in the
response to this command.

Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
---
 core/pldm/pldm-responder.c | 91 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)
diff mbox series

Patch

diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
index 232447e2..bd1ac6dc 100644
--- a/core/pldm/pldm-responder.c
+++ b/core/pldm/pldm-responder.c
@@ -8,6 +8,7 @@ 
 #include <opal.h>
 #include <stdio.h>
 #include <string.h>
+#include <pldm/ibm/libpldm/platform_oem_ibm.h>
 #include <pldm/libpldm/platform.h>
 #include <pldm/libpldm/utils.h>
 #include "pldm.h"
@@ -461,6 +462,95 @@  static struct pldm_cmd pldm_platform_set_event_receiver = {
 	.handler = platform_set_event_receiver_handler,
 };
 
+struct event_message_req {
+	uint8_t format_version;
+	uint8_t tid;
+	uint8_t event_class;
+	size_t event_data_offset;
+};
+
+/*
+ * PlatformEventMessage (0x10)
+ * PLDM Event Messages are sent as PLDM request messages to the Event
+ * Receiver using the PlatformEventMessage command.
+ */
+static int platform_event_message(const struct pldm_rx_data *req)
+{
+	char response_msg[PKT_SIZE(struct pldm_platform_event_message_resp)];
+	struct event_message_req message_req;
+	uint8_t cc = PLDM_SUCCESS;
+	int rc;
+
+	/* decode PlatformEventMessage request data */
+	rc = decode_platform_event_message_req(
+				req->msg,
+				sizeof(struct event_message_req),
+				&message_req.format_version,
+				&message_req.tid,
+				&message_req.event_class,
+				&message_req.event_data_offset);
+	if (rc) {
+		prlog(PR_ERR, "Failed to decode PlatformEventMessage request, rc = %d\n", rc);
+		pldm_cc_resp(req, req->hdrinf.pldm_type,
+			     req->hdrinf.command, PLDM_ERROR);
+		return OPAL_INTERNAL_ERROR;
+	}
+
+	prlog(PR_DEBUG, "%s - format_version: %d, "
+			"tid: %d "
+			"event_class: %d "
+			"event_data_offset: 0x%lx\n",
+			__func__,
+			message_req.format_version,
+			message_req.tid,
+			message_req.event_class,
+			message_req.event_data_offset);
+
+	/* we don't support any other event than the PDR Repo Changed event */
+	if ((message_req.event_class != PLDM_PDR_REPOSITORY_CHG_EVENT) &&
+	    (message_req.event_class != PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE)) {
+		prlog(PR_ERR, "%s - Invalid event class %d in platform event handler\n",
+			      __func__, message_req.event_class);
+		cc = PLDM_ERROR;
+	}
+
+	rc = encode_platform_event_message_resp(
+					req->hdrinf.instance,
+					cc,
+					PLDM_EVENT_NO_LOGGING,
+					(struct pldm_msg *)response_msg);
+	if (rc != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc);
+		pldm_cc_resp(req, req->hdrinf.pldm_type,
+			     req->hdrinf.command, PLDM_ERROR);
+		return OPAL_PARAMETER;
+	}
+
+	/* send PLDM message over MCTP */
+	rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg));
+	if (rc) {
+		prlog(PR_ERR, "Failed to send PlatformEventMessage response, rc = %d\n", rc);
+		return OPAL_HARDWARE;
+	}
+
+	/* invoke the appropriate callback handler */
+	if (message_req.event_class != PLDM_PDR_REPOSITORY_CHG_EVENT) {
+		/* FIXME */
+	}
+
+	if (message_req.event_class != PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE) {
+		/* FIXME */
+	}
+
+	return OPAL_SUCCESS;
+}
+
+static struct pldm_cmd pldm_platform_event_message = {
+	.name = "PLDM_PLATFORM_EVENT_MESSAGE",
+	.pldm_cmd_id = PLDM_PLATFORM_EVENT_MESSAGE,
+	.handler = platform_event_message,
+};
+
 int pldm_rx_handle_request(struct pldm_rx_data *rx)
 {
 	const struct pldm_type *t;
@@ -504,6 +594,7 @@  int pldm_mctp_responder_init(void)
 	/* Register platform commands we'll respond to - DSP0248 */
 	pldm_add_type(&pldm_platform_type);
 	pldm_add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver);
+	pldm_add_cmd(&pldm_platform_type, &pldm_platform_event_message);
 
 	return OPAL_SUCCESS;
 }