From patchwork Fri Jul 21 09:07:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1810832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=mRCIZ6ya; dkim-atps=neutral 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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6khm2zhxz1yYc for ; Fri, 21 Jul 2023 19:26:48 +1000 (AEST) 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=mRCIZ6ya; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R6khl3LNYz2ytf for ; Fri, 21 Jul 2023 19:26:47 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=mRCIZ6ya; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-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 4R6khg1JNXz2yDd for ; Fri, 21 Jul 2023 19:26:42 +1000 (AEST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36L9B4Ar013146 for ; Fri, 21 Jul 2023 09:26:40 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=svSYmYoXyiJuVEpk9fSPyT83uUCe11OFf42NcInLUUQ=; b=mRCIZ6yajbEymHZu4Wo+5JOP2N9WTC5Be9au9k78YuP3bJWNS6WzmLOOkw4URhmt/3KE I+2p/s8tDQsgdXWKwhcCSgtu8rmEnoCFDUKto5qsp3hri63qPKRxFyz5aaVaKGVpBwxk w131pkenwTVIcY+ZyuUvt62ol6FuC/ZCVoLJKYDXnbfR4MZjIJJX80vrFkxuH5nGWO+U oewQsU0SBQAmVw1I+yDYWxC4fPAeLcX7FoGnMpvnrlm678Hrq5yVaI7G/TzSSPFaJURw V20gNtArNbL2oAgLqlw+F0uQCEfoM1JrhNl2KtjSDJMuDVj988CwNHHLPbnrCxr5LhNe Hg== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rykd8555d-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:26:39 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 36L7eApT007599 for ; Fri, 21 Jul 2023 09:07:19 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3rv80jjw9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jul 2023 09:07:19 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36L97H3q23331480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 21 Jul 2023 09:07:17 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A2D512004D for ; Fri, 21 Jul 2023 09:07:17 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6854620040 for ; Fri, 21 Jul 2023 09:07:17 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.179.31.149]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Fri, 21 Jul 2023 09:07:17 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Fri, 21 Jul 2023 11:07:08 +0200 Message-ID: <20230721090708.26035-22-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230721090708.26035-1-clombard@linux.ibm.com> References: <20230721090708.26035-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: s1ZkiK3urxI3clGFpA6I7IIEji5ihjcM X-Proofpoint-ORIG-GUID: s1ZkiK3urxI3clGFpA6I7IIEji5ihjcM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-21_05,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 mlxscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307210081 Subject: [Skiboot] [PATCH V9 21/21] core/pldm: Get file handle and file length 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" Retrieve the file handle and file length based on attribute name. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 76 +++++++++++++++++++++++++++++++ core/pldm/pldm.h | 3 ++ 2 files changed, 79 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 95f69e4f..7f3cf70a 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -34,6 +34,82 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +#define CHKSUM_PADDING 8 + +/* + * Retrieve the file handle and file length from the file attribute + * table. + */ +static int find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + const struct pldm_file_attr_table_entry *file_entry; + char *startptr, *endptr; + uint16_t file_name_length; + + if ((file_attr_table == NULL) || (file_attr_length == 0)) + return OPAL_HARDWARE; + + startptr = (char *)file_attr_table; + endptr = startptr + file_attr_length - CHKSUM_PADDING; + *file_handle = 0; + *file_length = 0; + + while (startptr < endptr) { + /* file entry: + * 4 Bytes: file handle + * 2 Bytes: file name length + * Bytes: file name + * 4 Bytes: file length + */ + file_entry = (struct pldm_file_attr_table_entry *)startptr; + + *file_handle = le32_to_cpu(file_entry->file_handle); + startptr += sizeof(uint32_t); + + file_name_length = le16_to_cpu(file_entry->file_name_length); + startptr += sizeof(file_name_length); + + if (!strncmp(startptr, lid_id, strlen(lid_id))) { + startptr += file_name_length; + *file_length = le32_to_cpu(*(uint32_t *)startptr); + break; + } + startptr += file_name_length; + startptr += sizeof(uint32_t); + startptr += sizeof(bitfield32_t); + } + + if (*file_length == 0) { + prlog(PR_ERR, "%s - lid_id: %s, no file handle found\n", + __func__, lid_id); + *file_handle = 0xff; + *file_length = 0; + return OPAL_PARAMETER; + } + + prlog(PR_DEBUG, "%s - lid_id: %s, file_handle: %d, file_length: %d\n", + __func__, lid_id, *file_handle, *file_length); + + return OPAL_SUCCESS; +} + +/* + * Retrieve the file handle and file length based on lid id. + */ +int pldm_find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + if (!file_io_ready) + return OPAL_HARDWARE; + + return find_file_handle_by_lid_id(lid_id, + file_handle, + file_length); +} + /* maximum currently transfer size for PLDM */ #define KILOBYTE 1024ul #define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE) diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 08e7a3c2..2fbd6d32 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,9 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length); int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, uint32_t pos, void *buf, uint64_t len); int pldm_file_io_write_file(uint32_t file_handle, uint32_t pos,