[Skiboot] [PATCH 13/14] core/pldm: Register OPAL_IPMI_SEND/RECV calls back

Christophe Lombard clombard at linux.vnet.ibm.com
Tue Apr 19 23:46:32 AEST 2022


Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
---
 core/pldm/Makefile.inc |   2 +-
 core/pldm/pldm-opal.c  | 143 +++++++++++++++++++++++++++++++++++++++++
 include/pldm.h         |   5 ++
 3 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 core/pldm/pldm-opal.c

diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
index cf174c86..ebccb104 100644
--- a/core/pldm/Makefile.inc
+++ b/core/pldm/Makefile.inc
@@ -16,7 +16,7 @@ PLDM_OBJS = pldm-common.o pldm-responder.o pldm-requester.o
 PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o
 PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o
 PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o
-PLDM_OBJS += pldm-watchdog.o pldm-rtc.o
+PLDM_OBJS += pldm-watchdog.o pldm-rtc.o pldm-opal.o
 
 PLDM = $(PLDM_DIR)/built-in.a
 $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%)
diff --git a/core/pldm/pldm-opal.c b/core/pldm/pldm-opal.c
new file mode 100644
index 00000000..8aea0246
--- /dev/null
+++ b/core/pldm/pldm-opal.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+// Copyright 2022 IBM Corp.
+
+#define pr_fmt(fmt) "PLDM: " fmt
+
+#include <stdlib.h>
+#include <string.h>
+#include <device.h>
+#include <ipmi.h>
+#include <opal.h>
+#include <lock.h>
+#include <ccan/list/list.h>
+#include "pldm.h"
+
+static struct lock msgq_lock = LOCK_UNLOCKED;
+static struct list_head msgq = LIST_HEAD_INIT(msgq);
+
+/*
+ * static void opal_send_complete(struct ipmi_msg *msg)
+ * {
+ *	lock(&msgq_lock);
+ *	list_add_tail(&msgq, &msg->link);
+ *	opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv,
+ *				ipmi_backend->opal_event_ipmi_recv);
+ *	unlock(&msgq_lock);
+ * }
+ */
+
+static int64_t opal_ipmi_send(uint64_t interface __unused,
+			      struct opal_ipmi_msg *opal_ipmi_msg, uint64_t msg_len)
+{
+	int16_t ipmi_code;
+
+	if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
+		prerror("OPAL IPMI: Incorrect version\n");
+		return OPAL_UNSUPPORTED;
+	}
+
+	msg_len -= sizeof(struct opal_ipmi_msg);
+	if (msg_len > IPMI_MAX_REQ_SIZE) {
+		prerror("OPAL IPMI: Invalid request length\n");
+		return OPAL_PARAMETER;
+	}
+
+	ipmi_code = IPMI_CODE(opal_ipmi_msg->netfn >> 2, opal_ipmi_msg->cmd);
+	if ((ipmi_code == IPMI_CHASSIS_GET_SYS_BOOT_OPT_CMD) ||
+	    (opal_ipmi_msg->cmd == IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x1a)) ||
+	    (opal_ipmi_msg->cmd == IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x42))) {
+		prerror("OPAL IPMI: Command not supported\n");
+		return OPAL_UNSUPPORTED;
+	}
+
+	prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x len: 0x%02llx\n",
+			__func__, opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2,
+			msg_len);
+
+	/* FIXME - Send PLDM requests
+	 * IPMI_BMC_GET_DEVICE_ID     IPMI_CMD_GET_DEVICE_ID      0x01
+	 * IPMI_CMD_GET_DEVICE_GUID                               0x08
+	 * IPMI_SET_WDT	              IPMI_CMD_SET_WATCHDOG_TIMER 0x24
+	 */
+	return OPAL_UNSUPPORTED;
+}
+
+static int64_t opal_ipmi_recv(uint64_t interface,
+			      struct opal_ipmi_msg *opal_ipmi_msg, __be64 *msg_len)
+{
+	struct ipmi_msg *msg;
+	int64_t rc;
+
+	lock(&msgq_lock);
+	msg = list_top(&msgq, struct ipmi_msg, link);
+
+	if (!msg) {
+		rc = OPAL_EMPTY;
+		goto out_unlock;
+	}
+
+	if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) {
+		prerror("OPAL IPMI: Incorrect version\n");
+		rc = OPAL_UNSUPPORTED;
+		goto out_del_msg;
+	}
+
+	if (interface != IPMI_DEFAULT_INTERFACE) {
+		prerror("IPMI: Invalid interface 0x%llx in %s\n", interface, __func__);
+		rc = OPAL_PARAMETER;
+		goto out_del_msg;
+	}
+
+	if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) {
+		rc = OPAL_RESOURCE;
+		goto out_del_msg;
+	}
+
+	list_del(&msg->link);
+	if (list_empty(&msgq))
+		opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv, 0);
+	unlock(&msgq_lock);
+
+	opal_ipmi_msg->cmd = msg->cmd;
+	opal_ipmi_msg->netfn = msg->netfn;
+	opal_ipmi_msg->data[0] = msg->cc;
+	memcpy(&opal_ipmi_msg->data[1], msg->data, msg->resp_size);
+
+	prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x resp_size: 0x%02x\n",
+			__func__, msg->cmd, msg->netfn >> 2, msg->resp_size);
+
+	/* Add one as the completion code is returned in the message data */
+	*msg_len = cpu_to_be64(msg->resp_size + sizeof(struct opal_ipmi_msg) + 1);
+	ipmi_free_msg(msg);
+
+	return OPAL_SUCCESS;
+
+out_del_msg:
+	list_del(&msg->link);
+	if (list_empty(&msgq))
+		opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv, 0);
+	ipmi_free_msg(msg);
+out_unlock:
+	unlock(&msgq_lock);
+	return rc;
+}
+
+void pldm_opal_init(void)
+{
+	struct dt_node *opal_ipmi, *opal_event = NULL;
+
+	opal_ipmi = dt_new(opal_node, "ipmi");
+	dt_add_property_strings(opal_ipmi, "compatible", "ibm,opal-ipmi");
+	dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id",
+			      IPMI_DEFAULT_INTERFACE);
+	dt_add_property_cells(opal_ipmi, "interrupts",
+			      ilog2(ipmi_backend->opal_event_ipmi_recv));
+
+	opal_event = dt_find_by_name(opal_node, "event");
+	if (opal_event)
+		dt_add_property_cells(opal_ipmi, "interrupt-parent",
+				      opal_event->phandle);
+
+	opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3);
+	opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3);
+}
diff --git a/include/pldm.h b/include/pldm.h
index 73db2846..2cd31f2e 100644
--- a/include/pldm.h
+++ b/include/pldm.h
@@ -57,4 +57,9 @@ int pldm_watchdog_init(void);
  */
 void pldm_rtc_init(void);
 
+/**
+ * Register ipmi host interface access callbacks
+ */
+void pldm_opal_init(void);
+
 #endif /* __PLDM_H__ */
-- 
2.35.1



More information about the Skiboot mailing list