<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">Le 12/04/2023 à 16:36, Frederic Barrat
a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:79fa5b7e-aac7-93f1-cd3a-168888ff6774@linux.ibm.com">
<br>
<br>
On 13/09/2022 12:26, Christophe Lombard wrote:
<br>
<blockquote type="cite">Enable the mctp binding over LPC bus
interface and new wrappers to send
<br>
and receive PLDM messages over the mctp library.
<br>
<br>
PLDM is supported as a message type over MCTP. PLDM over MCTP
binding
<br>
defines the format of PLDM over MCTP messages.
<br>
<br>
An MCTP Endpoint is the terminus for MCTP communication. A
physical device
<br>
that supports MCTP may provide one or more MCTP Endpoints.
Endpoints are
<br>
addressed using a logical address called the Endpoint ID, or
EID. EIDs in
<br>
MCTP are analogous to IP Addresses in Internet Protocol
networking.
<br>
<br>
The BMC EID default is 8.
<br>
<br>
First byte of the PLDM over MCTP Message Fields identifies the
MCTP
<br>
message as carrying a PLDM message:
<br>
Message Type (7 bits) PLDM = 0x01 (000_0001b).
<br>
<br>
Signed-off-by: Christophe Lombard
<a class="moz-txt-link-rfc2396E" href="mailto:clombard@linux.vnet.ibm.com"><clombard@linux.vnet.ibm.com></a>
<br>
---
<br>
core/Makefile.inc | 6 ++-
<br>
core/pldm/Makefile.inc | 13 +++++
<br>
core/pldm/pldm-mctp.c | 118
+++++++++++++++++++++++++++++++++++++++++
<br>
core/pldm/pldm.h | 33 ++++++++++++
<br>
include/pldm.h | 18 +++++++
<br>
5 files changed, 187 insertions(+), 1 deletion(-)
<br>
create mode 100644 core/pldm/Makefile.inc
<br>
create mode 100644 core/pldm/pldm-mctp.c
<br>
create mode 100644 core/pldm/pldm.h
<br>
create mode 100644 include/pldm.h
<br>
<br>
diff --git a/core/Makefile.inc b/core/Makefile.inc
<br>
index f80019b6..263a0e50 100644
<br>
--- a/core/Makefile.inc
<br>
+++ b/core/Makefile.inc
<br>
@@ -22,8 +22,12 @@ endif
<br>
CORE=core/built-in.a
<br>
+ifeq ($(CONFIG_PLDM),1)
<br>
+include $(SRC)/core/pldm/Makefile.inc
<br>
+endif
<br>
+
<br>
CFLAGS_SKIP_core/relocate.o = -pg -fstack-protector-all
<br>
CFLAGS_SKIP_core/relocate.o += -fstack-protector
-fstack-protector-strong
<br>
CFLAGS_SKIP_core/relocate.o += -fprofile-arcs -ftest-coverage
<br>
-$(CORE): $(CORE_OBJS:%=core/%)
<br>
+$(CORE): $(CORE_OBJS:%=core/%) $(PLDM)
<br>
diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
<br>
new file mode 100644
<br>
index 00000000..c878ef1f
<br>
--- /dev/null
<br>
+++ b/core/pldm/Makefile.inc
<br>
@@ -0,0 +1,13 @@
<br>
+# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
<br>
+# Copyright 2022 IBM Corp
<br>
+
<br>
+PLDM_DIR ?= core/pldm
<br>
+SUBDIRS += $(PLDM_DIR)
<br>
+
<br>
+CPPFLAGS += -I$(SRC)/pldm/libpldm/
<br>
+CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/
<br>
+
<br>
+PLDM_OBJS = pldm-mctp.o
<br>
+
<br>
+PLDM = $(PLDM_DIR)/built-in.a
<br>
+$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%)
<br>
diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c
<br>
new file mode 100644
<br>
index 00000000..832b767a
<br>
--- /dev/null
<br>
+++ b/core/pldm/pldm-mctp.c
<br>
@@ -0,0 +1,118 @@
<br>
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
<br>
+// Copyright 2022 IBM Corp.
<br>
+
<br>
+#define pr_fmt(fmt) "PLDM: " fmt
<br>
+
<br>
+#include <cpu.h>
<br>
+#include <opal.h>
<br>
+#include <stdio.h>
<br>
+#include <string.h>
<br>
+#include <ast.h>
<br>
+#include "pldm.h"
<br>
+
<br>
+/*
<br>
+ * Print content of PLDM message in hex mode.
<br>
+ * 15 bytes per line.
<br>
</blockquote>
<br>
<br>
Should be 16 bytes per line.
<br>
Looks like debug code. Either convert to static or use a less
generic name.
<br>
<br>
<br>
</blockquote>
<br>
Correct. printbuf is only used for debug. We can remove it to avoid
confusion.<br>
<br>
<blockquote type="cite"
cite="mid:79fa5b7e-aac7-93f1-cd3a-168888ff6774@linux.ibm.com">
<blockquote type="cite">+ * Ex: pldm_mctp_message_tx: 000: 08 01
00 00 02 00 01
<br>
+ */
<br>
+void printbuf(const char *name, const char *msg, int len) >
+{
<br>
+ int i, j;
<br>
+ char linebuf[128];
<br>
+
<br>
+ linebuf[0] = 0;
<br>
</blockquote>
<br>
<br>
That line is useless (already in the for loop)
<br>
<br>
<br>
<blockquote type="cite">+
<br>
+ for (i = 0; i < len; i += j) {
<br>
+ linebuf[0] = 0;
<br>
+ for (j = 0; i + j < len && j < 15; j++) {
<br>
+ char s[5];
<br>
+
<br>
+ snprintf(s, 5, "%02x ", msg[i + j]);
<br>
+ strcat(linebuf, s);
<br>
+ }
<br>
+ prlog(PR_TRACE, "%s: %03x: %s\n", name, i, linebuf);
<br>
+ }
<br>
+}
<br>
+
<br>
+/*
<br>
+ * Send PLDM message over MCTP
<br>
+ */
<br>
+int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int
len)
<br>
+{
<br>
+ uint8_t *msg;
<br>
+ int rc;
<br>
+
<br>
+ /* Message TYPE: PLDM = 0x01 (000_0001b) - DSP0240 */
<br>
+ msg = zalloc(len + 1);
<br>
</blockquote>
<br>
<br>
As discussed, we should look to always have the caller allocate
the extra byte, so that we don't have to re-allocate and copy on
each message.
<br>
<br>
Fred
<br>
<br>
<br>
</blockquote>
<br>
<span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span
class="ryNqvb">yep. We could provide a common function which
allocates the request msg, including<br>
the pldm msg type byte, for the caller.<br>
</span></span></span><br>
<blockquote type="cite"
cite="mid:79fa5b7e-aac7-93f1-cd3a-168888ff6774@linux.ibm.com">
<blockquote type="cite">+ msg[0] = 0x01;
<br>
+ memcpy(&msg[1], buf, len);
<br>
+
<br>
+ rc = ast_mctp_message_tx(dest_id, msg, len + 1);
<br>
+ free(msg);
<br>
+
<br>
+ return rc;
<br>
+}
<br>
+
<br>
+/*
<br>
+ * Handle messages received from MCTP
<br>
+ */
<br>
+static int handle_message_rx(uint8_t eid, const uint8_t *buf,
int len)
<br>
+{
<br>
+ struct pldm_rx_data rx;
<br>
+
<br>
+ if (len < sizeof(rx.msg->hdr)) {
<br>
+ prlog(PR_ERR, "%s: packet is smaller than pldm
header\n", __func__);
<br>
+ return OPAL_EMPTY;
<br>
+ }
<br>
+
<br>
+ memset(&rx, 0, sizeof(rx));
<br>
+ rx.msg = (struct pldm_msg *) buf;
<br>
+ rx.source_eid = eid;
<br>
+ rx.msg_len = len;
<br>
+
<br>
+ if (unpack_pldm_header(&rx.msg->hdr,
&rx.hdrinf)) {
<br>
+ prlog(PR_ERR, "%s: unable to decode header\n",
__func__);
<br>
+ return OPAL_EMPTY;
<br>
+ }
<br>
+
<br>
+ return OPAL_UNSUPPORTED;
<br>
+}
<br>
+
<br>
+/*
<br>
+ * MCTP message rx callback
<br>
+ */
<br>
+static void message_rx(uint8_t eid, bool tag_owner __unused,
<br>
+ uint8_t msg_tag __unused, void *data __unused,
<br>
+ void *vmsg, size_t len)
<br>
+{
<br>
+ uint8_t *msg = vmsg;
<br>
+
<br>
+ prlog(PR_TRACE, "message received: msg: %p, len %zd (eid:
%d)\n",
<br>
+ msg, len, eid);
<br>
+
<br>
+ /* pldm message type */
<br>
+ if ((msg[0] & 0x7f) != 0x01) {
<br>
+ prlog(PR_ERR, "%s - not a pldm message type\n",
__func__);
<br>
+ return;
<br>
+ }
<br>
+
<br>
+ handle_message_rx(eid, &msg[1], len - 1);
<br>
+}
<br>
+
<br>
+int pldm_mctp_init(uint8_t mode)
<br>
+{
<br>
+ int rc;
<br>
+
<br>
+ /* MCTP Binding */
<br>
+ rc = ast_mctp_init(mode, message_rx);
<br>
+ if (rc)
<br>
+ prlog(PR_ERR, "Failed to bind MCTP\n");
<br>
+
<br>
+ prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc);
<br>
+ return rc;
<br>
+}
<br>
+
<br>
+void pldm_mctp_exit(void)
<br>
+{
<br>
+ ast_mctp_exit();
<br>
+}
<br>
diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h
<br>
new file mode 100644
<br>
index 00000000..a006d1f4
<br>
--- /dev/null
<br>
+++ b/core/pldm/pldm.h
<br>
@@ -0,0 +1,33 @@
<br>
+/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
<br>
+ * Copyright 2022 IBM Corp.
<br>
+ */
<br>
+
<br>
+#ifndef __COREPLDM_H__
<br>
+#define __COREPLDM_H__
<br>
+
<br>
+#include <pldm/libpldm/base.h>
<br>
+#include <pldm.h>
<br>
+
<br>
+/* Common support */
<br>
+
<br>
+void printbuf(const char *name, const char *msg, int len);
<br>
+
<br>
+/*
<br>
+ * EID is the MCTP endpoint ID, which aids in routing MCTP
packets.
<br>
+ * For the EIDs: the valid range is 8-254.
<br>
+ * We are saying that BMC is EID 8 and Skiboot is HOST_EID 9
<br>
+ */
<br>
+#define BMC_EID 8
<br>
+#define HOST_EID 9
<br>
+
<br>
+struct pldm_rx_data {
<br>
+ struct pldm_header_info hdrinf; /* parsed message header */
<br>
+
<br>
+ struct pldm_msg *msg;
<br>
+ int msg_len;
<br>
+ int source_eid;
<br>
+};
<br>
+
<br>
+int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int
len);
<br>
+
<br>
+#endif /* __COREPLDM_H__ */
<br>
diff --git a/include/pldm.h b/include/pldm.h
<br>
new file mode 100644
<br>
index 00000000..3aae560c
<br>
--- /dev/null
<br>
+++ b/include/pldm.h
<br>
@@ -0,0 +1,18 @@
<br>
+/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
<br>
+ * Copyright 2022 IBM Corp.
<br>
+ */
<br>
+
<br>
+#ifndef __PLDM_H__
<br>
+#define __PLDM_H__
<br>
+
<br>
+/**
<br>
+ * PLDM over MCTP initialization
<br>
+ */
<br>
+int pldm_mctp_init(uint8_t mode);
<br>
+
<br>
+/**
<br>
+ * PLDM over MCTP stop
<br>
+ */
<br>
+void pldm_mctp_exit(void);
<br>
+
<br>
+#endif /* __PLDM_H__ */
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>