[Skiboot] [PATCH 16/19] core/pldm: PLDM for File-IO operations
Christophe Lombard
clombard at linux.vnet.ibm.com
Sat Feb 26 01:28:45 AEDT 2022
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.
Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
---
core/pldm/Makefile.inc | 1 +
core/pldm/pldm-common.c | 15 +++-
core/pldm/pldm-file-io-requests.c | 141 ++++++++++++++++++++++++++++++
core/pldm/pldm.h | 2 +
4 files changed, 155 insertions(+), 4 deletions(-)
create mode 100644 core/pldm/pldm-file-io-requests.c
diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
index fcd97a0a..81297398 100644
--- a/core/pldm/Makefile.inc
+++ b/core/pldm/Makefile.inc
@@ -12,6 +12,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes
PLDM_OBJS = pldm-common.o pldm-responder.o pldm-requester.o
PLDM_OBJS += pldm-platform-requests.o pldm-bios-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-common.c b/core/pldm/pldm-common.c
index 98628afe..d25da60a 100644
--- a/core/pldm/pldm-common.c
+++ b/core/pldm/pldm-common.c
@@ -61,7 +61,8 @@ static int pldm_handle(uint8_t eid, const uint8_t *buf, int len)
struct pldm_rx_data rx;
if (len < sizeof(rx.msg->hdr)) {
- prerror("%s: packet is smaller than pldm header\n", __func__);
+ prlog(PR_ERR, "%s: packet is smaller than pldm header\n",
+ __func__);
return OPAL_EMPTY;
}
@@ -71,7 +72,8 @@ static int pldm_handle(uint8_t eid, const uint8_t *buf, int len)
rx.msg_len = len;
if (unpack_pldm_header(&rx.msg->hdr, &rx.hdrinf)) {
- prerror("%s: unable to decode header\n", __func__);
+ prlog(PR_ERR, "%s: unable to decode header\n",
+ __func__);
return OPAL_EMPTY;
}
@@ -96,12 +98,12 @@ void pldm_rx_message(uint8_t eid, void *data __unused, void *vmsg,
{
uint8_t *msg = vmsg;
- prlog(PR_DEBUG, "message received: msg: %p, len %zd (eid: %d)\n",
+ prlog(PR_TRACE, "message received: msg: %p, len %zd (eid: %d)\n",
msg, len, eid);
/* pldm message type */
if ((msg[0] & 0x7f) != 0x01) {
- prerror("not a pldm message type\n");
+ prlog(PR_ERR, "%s, not a pldm message type\n", __func__);
return;
}
@@ -131,6 +133,11 @@ int pldm_mctp_init(void)
/* Get Bios data */
rc = pldm_bios_init();
+ if (rc)
+ goto out;
+
+ /* Get FILE IO data */
+ rc = pldm_file_io_init();
out:
prlog(PR_NOTICE, "%s - done (rc: %d)\n", __func__, rc);
diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c
new file mode 100644
index 00000000..369beb54
--- /dev/null
+++ b/core/pldm/pldm-file-io-requests.c
@@ -0,0 +1,141 @@
+// 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 <pldm/ibm/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)
+{
+ char request_msg[PKT_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;
+ uint32_t next_transfer_handle;
+ void *response_msg;
+ int rc;
+
+ 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 */
+ 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 *)request_msg);
+ if (rc != PLDM_SUCCESS) {
+ prlog(PR_ERR, "Encode GetFileReq Error (rc: %d)\n", rc);
+ return OPAL_PARAMETER;
+ }
+
+ /* Send and get the response message bytes */
+ rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg),
+ &response_msg, &response_len);
+ if (rc) {
+ prlog(PR_ERR, "PLDM: Communication Error (rc: %d)\n", rc);
+ return OPAL_PARAMETER;
+ }
+
+ /* 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);
+ return OPAL_PARAMETER;
+ }
+
+ /* 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 = malloc(file_attr_length);
+ memcpy(file_attr_table,
+ ((struct pldm_msg *)response_msg)->payload +
+ file_table_data_start_offset,
+ file_attr_length);
+
+ free(response_msg);
+
+ return OPAL_SUCCESS;
+}
+
+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.h b/core/pldm/pldm.h
index 66241f07..dde82240 100644
--- a/core/pldm/pldm.h
+++ b/core/pldm/pldm.h
@@ -50,6 +50,8 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx);
int pldm_mctp_responder_init(void);
/* Requester support */
+int pldm_file_io_init(void);
+
int pldm_bios_find_lid_by_attr_name(const char *name, char **lid);
int pldm_bios_get_lids_id(char *lid_ids_string);
int pldm_bios_init(void);
--
2.35.1
More information about the Skiboot
mailing list