From patchwork Thu May 11 16:24:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780188 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=Jmc7mDeR; 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 4QHHQb5SwSz213w for ; Fri, 12 May 2023 02:28:55 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQb4RBFz3fdZ for ; Fri, 12 May 2023 02:28:55 +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=Jmc7mDeR; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=) 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=Jmc7mDeR; dkim-atps=neutral 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 4QHHL44YN7z3fWy for ; Fri, 12 May 2023 02:25:00 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BGItd6016684 for ; Thu, 11 May 2023 16:24:58 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=daZOczgcknpYnTTmmUOftOkyVqK3nlYy6Nrwvtq9VYQ=; b=Jmc7mDeRtHpoLaJfYwx1O6FZIFg67qyxnBPp2VA/ArmHeX1fptgGfGyy0C6Vkm21IKci q8xnqnmgn9a+EOnwITUyejrdq5XH8Ka96MJhCnxxqDu5ABAZEOdCV17VNgKJCZWW2zzl 5/VBULE8alsxTuijR8QTVnC9nxaUmP4dY7+zl9Yj0lb5UNOz3ROxyer6L5Ch/xnLf2JV tkNjuYUbuihrODF8XwQVA/S/y9x3bi7niRFAr8MINyiMTkKRAqwD5GnF5KryU4TywfX6 volvuCapIJxSYgHGvBpxYjByHnWUXyNi7RHcP/OUHdz/snqYosNtUETgknN69Lbxdq+2 wg== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qh2h2ub2a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34BFrE3C003727 for ; Thu, 11 May 2023 16:24:56 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896sujg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOsHc5702292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DB8020049 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00BEF20040 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:44 +0200 Message-Id: <20230511162446.10457-20-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: R-ZtKZndruTvNWwNOJoTceY6IfhY09P- X-Proofpoint-ORIG-GUID: R-ZtKZndruTvNWwNOJoTceY6IfhY09P- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 impostorscore=0 adultscore=0 priorityscore=1501 spamscore=0 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 19/21] core/pldm: Add file io read request 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" Send/receive a PLDM ReadFile request message. Due to maximum transfer size for PLDM protocol, we have to send several read requests, if necessary. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 135 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 137 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 11251a30..02d551bb 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "pldm.h" @@ -33,6 +34,140 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +/* maximum currently transfer size for PLDM */ +#define KILOBYTE 1024ul +#define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1) + +/* + * Send/receive a PLDM ReadFile request message. + */ +static int read_file_req(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_read_file_req); + size_t response_len, payload_len, file_data_offset; + uint8_t completion_code; + struct pldm_tx_data *tx; + uint32_t resp_length; + uint64_t total_read; + void *response_msg; + int num_transfers; + void *curr_buf; + int rc, i; + + struct pldm_read_file_req file_req = { + .file_handle = file_handle, + .offset = offset, + .length = size + }; + + if (!file_length) + return OPAL_PARAMETER; + + if ((!size) || ((size + offset) > file_length)) + return OPAL_PARAMETER; + + num_transfers = 1; + curr_buf = buf; + total_read = 0; + + if (file_req.length > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (file_req.length + MAX_TRANSFER_SIZE_BYTES - 1) / + MAX_TRANSFER_SIZE_BYTES; + file_req.length = MAX_TRANSFER_SIZE_BYTES; + } + + prlog(PR_TRACE, "%s - file_handle: %d, offset: 0x%x, size: 0x%llx num_transfers: %d\n", + __func__, file_handle, file_req.offset, + size, num_transfers); + + /* init request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + for (i = 0; i < num_transfers; i++) { + file_req.offset = offset + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_read_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode ReadFileReq 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: ReadFileReq, rc: %d\n", rc); + free(tx); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_read_file_resp( + response_msg, + payload_len, + &completion_code, + &resp_length, + &file_data_offset); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode ReadFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(tx); + free(response_msg); + return OPAL_PARAMETER; + } + + if (resp_length == 0) { + free(response_msg); + break; + } + + memcpy(curr_buf, + ((struct pldm_msg *)response_msg)->payload + file_data_offset, + resp_length); + + total_read += resp_length; + curr_buf += resp_length; + free(response_msg); + + prlog(PR_TRACE, "%s - file_handle: %d, resp_length: 0x%x, total_read: 0x%llx\n", + __func__, file_handle, resp_length, total_read); + + if (total_read >= size) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (size - total_read)) + file_req.length = size - total_read; + } + + free(tx); + return OPAL_SUCCESS; +} + +int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return read_file_req(file_handle, file_length, buf, offset, size); +} + /* * Send/receive a PLDM GetFileTable request message. * The file table contains the list of files available and diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index d181aa89..30ef0922 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_read_file(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size); int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv, int len);