From patchwork Fri Mar 4 13:11:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1601011 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YgkvvY00; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K97by0NhQz9sG9 for ; Sat, 5 Mar 2022 00:14:21 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4K97bw64jTz3bXG for ; Sat, 5 Mar 2022 00:14:20 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YgkvvY00; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YgkvvY00; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4K97YN6PrDz30Ks for ; Sat, 5 Mar 2022 00:12:08 +1100 (AEDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 224CmipN032023 for ; Fri, 4 Mar 2022 13:12:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=fZzOU+92lEHyM7GowYSOy81zxpYFLST4dWmR+05Nz9I=; b=YgkvvY005pkde3WOel82KYo6xz0SV9chOB/KvubAAuhW8LyD3HqIkhdzp1Mb6GlZ/vWw cxrbu2smG3vLJnECSO0gpgSnUHUkztjYEFpR6fi39RKpCBe6PyW7KztsUm4sWiDy8kWB WMnkSKBBJFg0pX1CikVy4CnSrVaN/OAX8O6gvG7y0/F/FoU2oiqyXOIi1t2RrSjlR5QE ImW37rtsuElG1TWXwHTsG6yUMaApSigJwQ4NGse9nUcWKamVL65lo5HY6b5rpwbGKl8f M9sb0RALf0vWKT9siPumdPVMZ09GcgmDPOrniRFI8z+LwGvrllK0I9v7sUYExBYa2qQc EQ== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3ekk3trdy2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 04 Mar 2022 13:12:07 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 224D7dLc026299 for ; Fri, 4 Mar 2022 13:12:05 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3ek4kbsskc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 04 Mar 2022 13:12:05 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 224DC3DS54591944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 4 Mar 2022 13:12:03 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F25CE11C050 for ; Fri, 4 Mar 2022 13:12:02 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B4E1711C04A for ; Fri, 4 Mar 2022 13:12:02 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.ibm.com.com (unknown [9.171.29.80]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 4 Mar 2022 13:12:02 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 4 Mar 2022 14:11:51 +0100 Message-Id: <20220304131154.58409-19-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220304131154.58409-1-clombard@linux.vnet.ibm.com> References: <20220304131154.58409-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ak8JvL-JV-t-DBZacYDX8-iHhOfBYlsb X-Proofpoint-ORIG-GUID: Ak8JvL-JV-t-DBZacYDX8-iHhOfBYlsb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-04_02,2022-03-04_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 bulkscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203040071 Subject: [Skiboot] [PATCH V2 18/21] core/pldm: PLDM for File-IO operations X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-common.c | 15 +++- core/pldm/pldm-file-io-requests.c | 141 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 4 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 core/pldm/pldm-file-io-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index d615a012..06a784ea 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -12,7 +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-fru-requests.o +PLDM_OBJS += pldm-fru-requests.o 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..f006c797 --- /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 +#include +#include +#include +#include +#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 (req: GetFileReq, 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 bd2cdbf6..2695fa37 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -51,6 +51,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_fru_get_record_by_option(uint16_t fru_table_handle, uint16_t record_set_identifier, uint8_t record_type,