[Skiboot] [PATCH V10 18/21] core/pldm: PLDM for File-IO operations

Christophe Lombard clombard at linux.ibm.com
Tue Aug 29 19:23:35 AEST 2023


The ibm/libpldm library implements IBM OEM commands support for PLDM and
specially encode and decode APIs for in-band readFile and writeFile
commands.

The GetFileTable request message is used to retrieve the file table which
contains the list of lid files available and their attributes.

Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
Signed-off-by: Christophe Lombard <clombard at linux.ibm.com>
---
 core/pldm/Makefile.inc            |   1 +
 core/pldm/pldm-file-io-requests.c | 156 ++++++++++++++++++++++++++++++
 core/pldm/pldm-mctp.c             |   4 +-
 core/pldm/pldm.h                  |   2 +
 4 files changed, 162 insertions(+), 1 deletion(-)
 create mode 100644 core/pldm/pldm-file-io-requests.c

diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
index 0b54b7e30..d89e4c2fc 100644
--- a/core/pldm/Makefile.inc
+++ b/core/pldm/Makefile.inc
@@ -10,6 +10,7 @@ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/
 PLDM_OBJS = pldm-mctp.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 = $(PLDM_DIR)/built-in.a
 $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%)
diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c
new file mode 100644
index 000000000..11251a30c
--- /dev/null
+++ b/core/pldm/pldm-file-io-requests.c
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+// Copyright 2022 IBM Corp.
+
+#define pr_fmt(fmt) "PLDM: " fmt
+
+#include <opal.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <libpldm/file_io.h>
+#include "pldm.h"
+
+/* list of lid files available */
+static void *file_attr_table;
+static size_t file_attr_length;
+
+static bool file_io_ready;
+
+static void file_io_init_complete(bool success)
+{
+	/* Read not successful, error out and free the buffer */
+	if (!success) {
+		file_io_ready = false;
+
+		if (file_attr_table != NULL) {
+			free(file_attr_table);
+			file_attr_length = 0;
+		}
+		return;
+	}
+
+	/* Mark ready */
+	file_io_ready = true;
+}
+
+/*
+ * Send/receive a PLDM GetFileTable request message.
+ * The file table contains the list of files available and
+ * their attributes.
+ *
+ * Ex:
+ * {
+ *   "FileHandle": "11",
+ *   "FileNameLength": 12,
+ *   "FileName": "81e0066b.lid",
+ *   "FileSize": 589824,
+ *   "FileTraits": 6
+ * },
+ */
+static int get_file_table_req(void)
+{
+	size_t data_size = PLDM_MSG_SIZE(struct pldm_get_file_table_req);
+	size_t response_len, payload_len;
+	uint8_t file_table_data_start_offset;
+	uint8_t transfer_flag, completion_code;
+	struct pldm_tx_data *tx = NULL;
+	uint32_t next_transfer_handle;
+	void *response_msg;
+	int rc = OPAL_SUCCESS;
+
+	struct pldm_get_file_table_req file_table_req = {
+		.transfer_handle = 0, /* (0 if operation op is FIRSTPART) */
+		.operation_flag = PLDM_GET_FIRSTPART,
+		.table_type = PLDM_FILE_ATTRIBUTE_TABLE,
+	};
+
+	prlog(PR_DEBUG, "%s - GetFileReq\n", __func__);
+
+	/* Encode the file table request */
+	tx = zalloc(sizeof(struct pldm_tx_data) + data_size);
+	if (!tx)
+		return OPAL_NO_MEM;
+	tx->data_size = data_size;
+
+	rc = encode_get_file_table_req(
+			DEFAULT_INSTANCE_ID,
+			file_table_req.transfer_handle,
+			file_table_req.operation_flag,
+			file_table_req.table_type,
+			(struct pldm_msg *)tx->data);
+	if (rc != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Encode GetFileReq Error, rc: %d\n", rc);
+		free(tx);
+		return OPAL_PARAMETER;
+	}
+
+	/* Send and get the response message bytes */
+	rc = pldm_requester_queue_and_wait(tx,
+					   &response_msg, &response_len);
+	if (rc) {
+		prlog(PR_ERR, "Communication Error, req: GetFileReq, rc: %d\n", rc);
+		free(tx);
+		return rc;
+	}
+
+	/* Decode the message */
+	payload_len = response_len - sizeof(struct pldm_msg_hdr);
+	rc = decode_get_file_table_resp(
+				response_msg,
+				payload_len,
+				&completion_code,
+				&next_transfer_handle,
+				&transfer_flag,
+				&file_table_data_start_offset,
+				&file_attr_length);
+	if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Decode GetFileResp Error, rc: %d, cc: %d\n",
+			      rc, completion_code);
+		rc = OPAL_PARAMETER;
+		goto out;
+	}
+
+	/* we do not support multipart transfer */
+	if ((next_transfer_handle != PLDM_GET_NEXTPART) ||
+	    (transfer_flag != PLDM_START_AND_END)) {
+		prlog(PR_ERR, "Transfert GetFileResp not complete, "
+			      "transfer_hndl: %d, transfer_flag: %d\n",
+			      next_transfer_handle,
+			      transfer_flag);
+	}
+
+	file_attr_table = zalloc(file_attr_length);
+	if (!file_attr_table) {
+		rc = OPAL_NO_MEM;
+		goto out;
+	}
+
+	memcpy(file_attr_table,
+	       ((struct pldm_msg *)response_msg)->payload +
+	       file_table_data_start_offset,
+	       file_attr_length);
+
+out:
+	free(tx);
+	free(response_msg);
+	return rc;
+}
+
+int pldm_file_io_init(void)
+{
+	int rc;
+
+	/* PLDM GetFileTable request */
+	rc = get_file_table_req();
+	if (rc)
+		goto err;
+
+	file_io_init_complete(true);
+	prlog(PR_DEBUG, "%s - done\n", __func__);
+
+	return OPAL_SUCCESS;
+
+err:
+	file_io_init_complete(false);
+	return rc;
+}
diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c
index b31587f69..fb7d8a1cb 100644
--- a/core/pldm/pldm-mctp.c
+++ b/core/pldm/pldm-mctp.c
@@ -74,7 +74,7 @@ out:
 
 int pldm_mctp_init(void)
 {
-	int nbr_elt = 7, rc = OPAL_SUCCESS;
+	int nbr_elt = 8, rc = OPAL_SUCCESS;
 
 	int (*pldm_config[])(void) = {
 		ast_mctp_init,		/* MCTP Binding */
@@ -84,6 +84,7 @@ int pldm_mctp_init(void)
 		pldm_platform_init,	/* Get PDRs data */
 		pldm_bios_init,		/* Get Bios data */
 		pldm_fru_init,		/* Get Fru data */
+		pldm_file_io_init,	/* Get FILE IO data */
 	};
 
 	const char *pldm_config_error[] = {
@@ -94,6 +95,7 @@ int pldm_mctp_init(void)
 		"Failed to retrieve Data Records",
 		"Failed to retrieve Bios data",
 		"Failed to retrieve Fru data",
+		"Failed to retrieve File io data",
 	};
 
 	prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__);
diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h
index 59155fbfd..270cfd62e 100644
--- a/core/pldm/pldm.h
+++ b/core/pldm/pldm.h
@@ -52,6 +52,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx);
 int pldm_responder_init(void);
 
 /* Requester support */
+int pldm_file_io_init(void);
+
 int pldm_fru_get_bmc_version(void *bv, int len);
 int pldm_fru_init(void);
 
-- 
2.41.0



More information about the Skiboot mailing list