From patchwork Tue Sep 13 10:26:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677215 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=Fa44MPPX; 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 4MRfmQ3gD4z1ynm for ; Tue, 13 Sep 2022 20:27:34 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmQ3Dgdz3bq5 for ; Tue, 13 Sep 2022 20:27:34 +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=Fa44MPPX; 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.156.1; 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=Fa44MPPX; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 4MRfm24w7rz308b for ; Tue, 13 Sep 2022 20:27:14 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPHsb001267 for ; Tue, 13 Sep 2022 10:27:11 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=Sbo6xprGOPE0PgwIRsHdG/vvxxLAp5sjld6KWDbjLv8=; b=Fa44MPPXLhy7wdF4mkVSOEKfh6ssIFxsT9VnE0jmLD1LgVcNshs9HVB1F481ySdT8ITt jWTmia98pUL9qrPn3RQtafLGdailxPjSgAWKQHHOCnutRczgnhHfUpW2iyJdloOawLs9 kLjrUqJNHiWZ5Jy7OCO36AsUMZ0N/Y+xwB8qISxE2EZv5ldKA0GDbnXToCKqs/uw0owu 2xUe8+z+xzVhwGlcgkgXAVBFtHCgX/djhlo9+tC/lsqr65q0NNuBY/Pv3+YwD3Ju3i8j R/llirVrbQzANErFJdfI/4fFV8ubfAp1WnMNe1cSfGrDNjfkF7x4ivPBePY8M4APlczv Vw== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjr3j8169-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKaf7003206 for ; Tue, 13 Sep 2022 10:27:08 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:08 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR6Ql36569498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:06 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 946E9A404D for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A2DBA4040 for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:45 +0200 Message-Id: <20220913102705.65506-2-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: dgGGYkAywhqAEf0MujWGbEuri708KhbJ X-Proofpoint-ORIG-GUID: dgGGYkAywhqAEf0MujWGbEuri708KhbJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 01/21] hw: Move lpc firmware space helpers 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" Add new lpc helpers for doing a bulk io to firmware space. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- hw/lpc.c | 74 ++++++++++++++++++++++++++++++++ include/lpc.h | 6 +++ libflash/ipmi-hiomap.c | 66 +--------------------------- libflash/mbox-flash.c | 64 +-------------------------- libflash/test/mbox-server.c | 68 +++++++++++++++++++++++++++++ libflash/test/test-ipmi-hiomap.c | 66 ++++++++++++++++++++++++++++ 6 files changed, 218 insertions(+), 126 deletions(-) diff --git a/hw/lpc.c b/hw/lpc.c index bf3ab1fa..caaacc46 100644 --- a/hw/lpc.c +++ b/hw/lpc.c @@ -667,6 +667,80 @@ int64_t lpc_probe_read(enum OpalLPCAddressType addr_type, uint32_t addr, return __lpc_read_sanity(addr_type, addr, data, sz, true); } +int64_t lpc_fw_read(uint32_t off, void *buf, uint32_t len) +{ + int rc; + + prlog(PR_TRACE, "Reading 0x%08x bytes at FW offset 0x%08x\n", + len, off); + + while (len) { + uint32_t chunk; + uint32_t dat; + + /* XXX: make this read until it's aligned */ + if (len > 3 && !(off & 3)) { + rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); + if (!rc) { + /* + * lpc_read swaps to CPU endian but it's not + * really a 32-bit value, so convert back. + */ + *(__be32 *)buf = cpu_to_be32(dat); + } + chunk = 4; + } else { + rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); + if (!rc) + *(uint8_t *)buf = dat; + chunk = 1; + } + if (rc) { + prlog(PR_ERR, "lpc_read failure %d to FW 0x%08x\n", rc, off); + return rc; + } + len -= chunk; + off += chunk; + buf += chunk; + } + + return 0; +} + +int64_t lpc_fw_write(uint32_t off, const void *buf, uint32_t len) +{ + int rc; + + prlog(PR_TRACE, "Writing 0x%08x bytes at FW offset 0x%08x\n", + len, off); + + while (len) { + uint32_t chunk; + + if (len > 3 && !(off & 3)) { + /* endian swap: see lpc_window_write */ + uint32_t dat = be32_to_cpu(*(__be32 *)buf); + + rc = lpc_write(OPAL_LPC_FW, off, dat, 4); + chunk = 4; + } else { + uint8_t dat = *(uint8_t *)buf; + + rc = lpc_write(OPAL_LPC_FW, off, dat, 1); + chunk = 1; + } + if (rc) { + prlog(PR_ERR, "lpc_write failure %d to FW 0x%08x\n", rc, off); + return rc; + } + len -= chunk; + off += chunk; + buf += chunk; + } + + return 0; +} + /* * The "OPAL" variant add the emulation of 2 and 4 byte accesses using * byte accesses for IO and MEM space in order to be compatible with diff --git a/include/lpc.h b/include/lpc.h index b641aa4e..ce9c33dc 100644 --- a/include/lpc.h +++ b/include/lpc.h @@ -102,6 +102,12 @@ extern int64_t lpc_probe_write(enum OpalLPCAddressType addr_type, uint32_t addr, extern int64_t lpc_probe_read(enum OpalLPCAddressType addr_type, uint32_t addr, uint32_t *data, uint32_t sz); +/* + * helpers for doing a bulk io to firmware space. + */ +extern int64_t lpc_fw_read(uint32_t addr, void *buf, uint32_t sz); +extern int64_t lpc_fw_write(uint32_t addr, const void *buf, uint32_t sz); + /* Mark LPC bus as used by console */ extern void lpc_used_by_console(void); diff --git a/libflash/ipmi-hiomap.c b/libflash/ipmi-hiomap.c index 29355d66..93aaef45 100644 --- a/libflash/ipmi-hiomap.c +++ b/libflash/ipmi-hiomap.c @@ -555,45 +555,11 @@ static int lpc_window_read(struct ipmi_hiomap *ctx, uint32_t pos, void *buf, uint32_t len) { uint32_t off = ctx->current.lpc_addr + (pos - ctx->current.cur_pos); - int rc; if ((ctx->current.lpc_addr + ctx->current.size) < (off + len)) return FLASH_ERR_PARM_ERROR; - prlog(PR_TRACE, "Reading at 0x%08x for 0x%08x offset: 0x%08x\n", - pos, len, off); - - while(len) { - uint32_t chunk; - uint32_t dat; - - /* XXX: make this read until it's aligned */ - if (len > 3 && !(off & 3)) { - rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); - if (!rc) { - /* - * lpc_read swaps to CPU endian but it's not - * really a 32-bit value, so convert back. - */ - *(__be32 *)buf = cpu_to_be32(dat); - } - chunk = 4; - } else { - rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); - if (!rc) - *(uint8_t *)buf = dat; - chunk = 1; - } - if (rc) { - prlog(PR_ERR, "lpc_read failure %d to FW 0x%08x\n", rc, off); - return rc; - } - len -= chunk; - off += chunk; - buf += chunk; - } - - return 0; + return lpc_fw_read(off, buf, len); } static int lpc_window_write(struct ipmi_hiomap *ctx, uint32_t pos, @@ -601,7 +567,6 @@ static int lpc_window_write(struct ipmi_hiomap *ctx, uint32_t pos, { uint32_t off = ctx->current.lpc_addr + (pos - ctx->current.cur_pos); enum lpc_window_state state; - int rc; lock(&ctx->lock); state = ctx->window_state; @@ -613,34 +578,7 @@ static int lpc_window_write(struct ipmi_hiomap *ctx, uint32_t pos, if ((ctx->current.lpc_addr + ctx->current.size) < (off + len)) return FLASH_ERR_PARM_ERROR; - prlog(PR_TRACE, "Writing at 0x%08x for 0x%08x offset: 0x%08x\n", - pos, len, off); - - while(len) { - uint32_t chunk; - - if (len > 3 && !(off & 3)) { - /* endian swap: see lpc_window_read */ - uint32_t dat = be32_to_cpu(*(__be32 *)buf); - - rc = lpc_write(OPAL_LPC_FW, off, dat, 4); - chunk = 4; - } else { - uint8_t dat = *(uint8_t *)buf; - - rc = lpc_write(OPAL_LPC_FW, off, dat, 1); - chunk = 1; - } - if (rc) { - prlog(PR_ERR, "lpc_write failure %d to FW 0x%08x\n", rc, off); - return rc; - } - len -= chunk; - off += chunk; - buf += chunk; - } - - return 0; + return lpc_fw_write(off, buf, len); } /* Best-effort asynchronous event handling by blocklevel callbacks */ diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index 4c20f15f..9e686c97 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -147,79 +147,19 @@ static int lpc_window_read(struct mbox_flash_data *mbox_flash, uint32_t pos, void *buf, uint32_t len) { uint32_t off = mbox_flash->read.lpc_addr + (pos - mbox_flash->read.cur_pos); - int rc; prlog(PR_TRACE, "Reading at 0x%08x for 0x%08x offset: 0x%08x\n", pos, len, off); - while(len) { - uint32_t chunk; - uint32_t dat; - - /* XXX: make this read until it's aligned */ - if (len > 3 && !(off & 3)) { - rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); - if (!rc) { - /* - * lpc_read swaps to CPU endian but it's not - * really a 32-bit value, so convert back. - */ - *(__be32 *)buf = cpu_to_be32(dat); - } - chunk = 4; - } else { - rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); - if (!rc) - *(uint8_t *)buf = dat; - chunk = 1; - } - if (rc) { - prlog(PR_ERR, "lpc_read failure %d to FW 0x%08x\n", rc, off); - return rc; - } - len -= chunk; - off += chunk; - buf += chunk; - } - - return 0; + return lpc_fw_read(off, buf, len); } static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos, const void *buf, uint32_t len) { uint32_t off = mbox_flash->write.lpc_addr + (pos - mbox_flash->write.cur_pos); - int rc; - - - prlog(PR_TRACE, "Writing at 0x%08x for 0x%08x offset: 0x%08x\n", - pos, len, off); - - while(len) { - uint32_t chunk; - - if (len > 3 && !(off & 3)) { - /* endian swap: see lpc_window_read */ - uint32_t dat = be32_to_cpu(*(__be32 *)buf); - - rc = lpc_write(OPAL_LPC_FW, off, dat, 4); - chunk = 4; - } else { - uint8_t dat = *(uint8_t *)buf; - - rc = lpc_write(OPAL_LPC_FW, off, dat, 1); - chunk = 1; - } - if (rc) { - prlog(PR_ERR, "lpc_write failure %d to FW 0x%08x\n", rc, off); - return rc; - } - len -= chunk; - off += chunk; - buf += chunk; - } - return 0; + return lpc_fw_write(off, buf, len); } static uint64_t mbox_flash_mask(struct mbox_flash_data *mbox_flash) diff --git a/libflash/test/mbox-server.c b/libflash/test/mbox-server.c index 8a68cfff..053be989 100644 --- a/libflash/test/mbox-server.c +++ b/libflash/test/mbox-server.c @@ -142,6 +142,74 @@ int64_t lpc_write(enum OpalLPCAddressType __unused addr_type, uint32_t addr, return 0; } +int64_t lpc_fw_read(uint32_t off, void *buf, uint32_t len); +int64_t lpc_fw_read(uint32_t off, void *buf, uint32_t len) +{ + int rc; + + while (len) { + uint32_t chunk; + uint32_t dat; + + /* XXX: make this read until it's aligned */ + if (len > 3 && !(off & 3)) { + rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); + if (!rc) { + /* + * lpc_read swaps to CPU endian but it's not + * really a 32-bit value, so convert back. + */ + *(__be32 *)buf = cpu_to_be32(dat); + } + chunk = 4; + } else { + rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); + if (!rc) + *(uint8_t *)buf = dat; + chunk = 1; + } + if (rc) + return rc; + + len -= chunk; + off += chunk; + buf += chunk; + } + + return 0; +} + +int64_t lpc_fw_write(uint32_t off, const void *buf, uint32_t len); +int64_t lpc_fw_write(uint32_t off, const void *buf, uint32_t len) +{ + int rc; + + while (len) { + uint32_t chunk; + + if (len > 3 && !(off & 3)) { + /* endian swap: see lpc_window_write */ + uint32_t dat = be32_to_cpu(*(__be32 *)buf); + + rc = lpc_write(OPAL_LPC_FW, off, dat, 4); + chunk = 4; + } else { + uint8_t dat = *(uint8_t *)buf; + + rc = lpc_write(OPAL_LPC_FW, off, dat, 1); + chunk = 1; + } + if (rc) + return rc; + + len -= chunk; + off += chunk; + buf += chunk; + } + + return 0; +} + int bmc_mbox_register_attn(mbox_attn_cb handler, void *drv_data) { mbox_data.attn = handler; diff --git a/libflash/test/test-ipmi-hiomap.c b/libflash/test/test-ipmi-hiomap.c index 6117e9dd..b740a6f2 100644 --- a/libflash/test/test-ipmi-hiomap.c +++ b/libflash/test/test-ipmi-hiomap.c @@ -223,6 +223,72 @@ int64_t lpc_read(enum OpalLPCAddressType addr_type __attribute__((unused)), return 0; } +int64_t lpc_fw_read(uint32_t off, void *buf, uint32_t len) +{ + int rc; + + while (len) { + uint32_t chunk; + uint32_t dat; + + /* XXX: make this read until it's aligned */ + if (len > 3 && !(off & 3)) { + rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); + if (!rc) { + /* + * lpc_read swaps to CPU endian but it's not + * really a 32-bit value, so convert back. + */ + *(__be32 *)buf = cpu_to_be32(dat); + } + chunk = 4; + } else { + rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); + if (!rc) + *(uint8_t *)buf = dat; + chunk = 1; + } + if (rc) + return rc; + + len -= chunk; + off += chunk; + buf += chunk; + } + + return 0; +} + +int64_t lpc_fw_write(uint32_t off, const void *buf, uint32_t len) +{ + int rc; + + while (len) { + uint32_t chunk; + + if (len > 3 && !(off & 3)) { + /* endian swap: see lpc_window_write */ + uint32_t dat = be32_to_cpu(*(__be32 *)buf); + + rc = lpc_write(OPAL_LPC_FW, off, dat, 4); + chunk = 4; + } else { + uint8_t dat = *(uint8_t *)buf; + + rc = lpc_write(OPAL_LPC_FW, off, dat, 1); + chunk = 1; + } + if (rc) + return rc; + + len -= chunk; + off += chunk; + buf += chunk; + } + + return 0; +} + static bool lpc_read_success(const uint8_t *buf, size_t len) { if (len < 64) { From patchwork Tue Sep 13 10:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677213 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=j73q0atJ; 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 4MRfmF1FHnz1ynm for ; Tue, 13 Sep 2022 20:27:25 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmF0pZPz3bmW for ; Tue, 13 Sep 2022 20:27:25 +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=j73q0atJ; 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=mx0b-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=j73q0atJ; 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 4MRfm20Pltz307C for ; Tue, 13 Sep 2022 20:27:13 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9swYf023825 for ; Tue, 13 Sep 2022 10:27:11 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 : content-transfer-encoding : mime-version; s=pp1; bh=6yKKHtQ036ybgGFWQltfxuw73CIwO3WXbxbWpUt6Uh8=; b=j73q0atJHCQQ3mi8uk70VRV7VayJvP1yZMcgfWLimBDdZtley3XM9y8STZRj1TNwGEpx ndHIshOu8KyQb2B4OufLNNYRPokrLCJNOytCUNqehe4AeDkMYIqLr9le0bBQcFmv9Ed3 EJAS83rZ5m/aQAhSDpAh62A8St98B1qPmglZP9t0U3XVSWr1ZwSgChgwBpRvqh+9LOin FT4198Cl0AsptQigjNAOdxF3ybhjx8u6U6xVERixZsP0tBXEXlFcsUXuNua6BYOKYSuM /IznJKhdE2r0/QJwEtndV1iGNeSuAOSCZb4hHgnkGX5Y2lSsLDVzn1xwCAYLj0dFlOT4 9w== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmjay1br-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:10 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKXVm003200 for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umxr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:09 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR6sV30736664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:06 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3898A4051 for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A88B3A4040 for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:46 +0200 Message-Id: <20220913102705.65506-3-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: tpz88LzFSgKXG2DSIqWmArwXay_2WwgJ X-Proofpoint-ORIG-GUID: tpz88LzFSgKXG2DSIqWmArwXay_2WwgJ X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 02/21] hw/ast-bmc: Initialize ast lpc mctp binding 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 Management Component Transport Protocol (MCTP) defines a communication model intended to facilitate communication. This patch initialize MCTP binding over LPC Bus interface. Several steps must be performed: - Initialize the MCTP core (mctp_init()). - Initialize a hardware binding as AST LPC mode host (mctp_astlpc_init()). - Register the hardware binding with the core (mctp_register_bus()), using a predefined EID (Host default is 9). To transmit a MCTP message, mctp_message_tx() is used. To receive a MCTP message, a callback need to be provided and registered through mctp_set_rx_all(). For the transfer of MCTP messages, two basics components are used: - A window of the LPC FW address space, where reads and writes are forwarded to BMC memory. - An interrupt mechanism using the KCS interface. hw/ast-bmc/ast-mctp.c is compilated if the compiler flag CONFIG_PLDM is set. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- hw/ast-bmc/Makefile.inc | 7 + hw/ast-bmc/ast-mctp.c | 386 ++++++++++++++++++++++++++++++++++++++++ include/ast.h | 11 ++ 3 files changed, 404 insertions(+) create mode 100644 hw/ast-bmc/ast-mctp.c diff --git a/hw/ast-bmc/Makefile.inc b/hw/ast-bmc/Makefile.inc index e7ded0e8..546f2bc7 100644 --- a/hw/ast-bmc/Makefile.inc +++ b/hw/ast-bmc/Makefile.inc @@ -2,5 +2,12 @@ SUBDIRS += hw/ast-bmc AST_BMC_OBJS = ast-io.o ast-sf-ctrl.o + +ifeq ($(CONFIG_PLDM),1) +CPPFLAGS += -I$(SRC)/libmctp/ +#CFLAGS += -DAST_MCTP_DEBUG +AST_BMC_OBJS += ast-mctp.o +endif + AST_BMC = hw/ast-bmc/built-in.a $(AST_BMC): $(AST_BMC_OBJS:%=hw/ast-bmc/%) diff --git a/hw/ast-bmc/ast-mctp.c b/hw/ast-bmc/ast-mctp.c new file mode 100644 index 00000000..1e7bdb51 --- /dev/null +++ b/hw/ast-bmc/ast-mctp.c @@ -0,0 +1,386 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "AST-MCTP: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * For the EIDs: the valid range is 8-254. + * host default = 9 + */ +uint8_t HOST_EID = 9; + +struct timer ast_boot_timer; +static struct mctp *mctp; + +struct ast_mctp_backend { + bool (*ready)(void); + int (*binding)(void); + void (*destroy)(void); +}; +const struct ast_mctp_backend *mctp_backend; + +/* + * The AST LPC binding is described here: + * + * https://github.com/openbmc/libmctp/blob/master/docs/bindings/vendor-astlpc.md + * + * Most of the binding is implemented in libmctp, but we need to provide + * accessors for the LPC FW space (for the packet buffer) and for the KCS + * peripheral (for the interrupt mechanism). + */ + +struct astlpc_ops_data { + uint16_t kcs_data_addr; /* LPC IO space offset for the data register */ + uint16_t kcs_stat_addr; + + /* address of the packet exchange buffer in FW space */ + uint32_t lpc_fw_addr; +}; + +static int astlpc_kcs_reg_read(void *binding_data, + enum mctp_binding_astlpc_kcs_reg reg, + uint8_t *val) +{ + struct astlpc_ops_data *ops_data = binding_data; + uint32_t addr, tmp; + int rc; + + if (reg == MCTP_ASTLPC_KCS_REG_STATUS) + addr = ops_data->kcs_stat_addr; + else if (reg == MCTP_ASTLPC_KCS_REG_DATA) + addr = ops_data->kcs_data_addr; + else + return OPAL_PARAMETER; + + rc = lpc_read(OPAL_LPC_IO, addr, &tmp, 1); + if (!rc) + *val = tmp & 0xff; + else + *val = 0xff; + + mctp_prdebug("%s 0x%hhx from %s (%d)", + __func__, *val, reg ? "status" : "data", rc); + + return rc; +} + +static int astlpc_kcs_reg_write(void *binding_data, + enum mctp_binding_astlpc_kcs_reg reg, + uint8_t val) +{ + struct astlpc_ops_data *ops_data = binding_data; + uint32_t addr; + + mctp_prdebug("%s 0x%hhx to %s", + __func__, val, reg ? "status" : "data"); + + if (reg == MCTP_ASTLPC_KCS_REG_STATUS) + addr = ops_data->kcs_stat_addr; + else if (reg == MCTP_ASTLPC_KCS_REG_DATA) + addr = ops_data->kcs_data_addr; + else + return OPAL_PARAMETER; + + return lpc_write(OPAL_LPC_IO, addr, val, 1); +} + +static int astlpc_read(void *binding_data, void *buf, long offset, + size_t len) +{ + struct astlpc_ops_data *ops_data = binding_data; + + mctp_prdebug("%s %zu bytes from 0x%lx (lpc: 0x%lx)", + __func__, len, offset, + ops_data->lpc_fw_addr + offset); + return lpc_fw_read(ops_data->lpc_fw_addr + offset, buf, len); +} + +static int astlpc_write(void *binding_data, const void *buf, + long offset, size_t len) +{ + struct astlpc_ops_data *ops_data = binding_data; + + mctp_prdebug("%s %zu bytes to offset 0x%lx (lpc: 0x%lx)", + __func__, len, offset, + ops_data->lpc_fw_addr + offset); + return lpc_fw_write(ops_data->lpc_fw_addr + offset, buf, len); +} + +static const struct mctp_binding_astlpc_ops astlpc_ops = { + .kcs_read = astlpc_kcs_reg_read, + .kcs_write = astlpc_kcs_reg_write, + .lpc_read = astlpc_read, + .lpc_write = astlpc_write, +}; + +static struct mctp_binding_astlpc *astlpc; +static struct astlpc_ops_data *ops_data; + +/* Keyboard Controller Style (KCS) data register address */ +#define KCS_DATA_REG 0xca2 + +/* Keyboard Controller Style (KCS) status register address */ +#define KCS_STATUS_REG 0xca3 + +/* Serial IRQ number for KCS interface */ +#define KCS_SERIAL_IRQ 11 + +#define KCS_STATUS_BMC_READY 0x80 + +bool irq_active; + +/* we need a poller to crank the mctp state machine during boot */ +static void astlpc_poller(struct timer *t __unused, + void *data __unused, uint64_t now __unused) +{ + mctp_astlpc_poll(astlpc); + + /* once booted we can rely on the KCS interrupt */ + if ((opal_booting() && !irq_active)) + schedule_timer(&ast_boot_timer, msecs_to_tb(5)); +} + +/* at runtime the interrupt should handle it */ +static void astlpc_interrupt(uint32_t chip_id __unused, + uint32_t irq_msk __unused) +{ + if (!irq_active) { + mctp_prerr("IRQ Active! Disabling boot poller..."); + irq_active = true; + } + + mctp_astlpc_poll(astlpc); +} + +static struct lpc_client kcs_lpc_client = { + .reset = NULL, + .interrupt = astlpc_interrupt, + .interrupts = LPC_IRQ(KCS_SERIAL_IRQ), +}; + +static bool astlpc_ready(void) +{ + uint32_t tmp = 0; + + /* Probe for MCTP support by reading the STAT register of KCS#4 */ + if (lpc_probe_read(OPAL_LPC_IO, KCS_STATUS_REG, &tmp, 1)) { + mctp_prdebug("KCS4 probe failed, skipping MCTP init"); + return false; + } + + return !!(tmp & KCS_STATUS_BMC_READY); /* high bit indicates BMC is listening */ +} + +#define DESIRED_MTU 32768 + +static void astlpc_destroy(void) +{ + if (astlpc) { + mctp_astlpc_destroy(astlpc); + cancel_timer(&ast_boot_timer); + astlpc = NULL; + } +} + +static int astlpc_binding(void) +{ + ops_data = zalloc(sizeof(struct astlpc_ops_data)); + if (!ops_data) + return OPAL_NO_MEM; + + /* + * Current OpenBMC systems put the MCTP buffer 1MB down from + * the end of the LPC FW range. + * + * The size of the FW range is: 0x1000_0000 so the window be at: + * + * 0x1000_0000 - 2**20 == 0xff00000 + */ + ops_data->lpc_fw_addr = 0xff00000; + + /* values chosen by the OpenBMC driver */ + ops_data->kcs_data_addr = KCS_DATA_REG; + ops_data->kcs_stat_addr = KCS_STATUS_REG; + + /* Initialise the binding */ + astlpc = mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, + DESIRED_MTU, + NULL, + &astlpc_ops, + ops_data); + if (!astlpc) { + mctp_prerr("binding init failed"); + return OPAL_HARDWARE; + } + + /* register an lpc client so we get an interrupt */ + lpc_register_client(0, &kcs_lpc_client, IRQ_ATTR_TARGET_OPAL); + + init_timer(&ast_boot_timer, astlpc_poller, astlpc); + schedule_timer(&ast_boot_timer, msecs_to_tb(5)); + + /* Register the binding to the LPC bus we are using for this + * MCTP configuration. + */ + if (mctp_register_bus(mctp, + mctp_binding_astlpc_core(astlpc), + HOST_EID)) { + mctp_prerr("failed to register bus"); + goto err; + } + + return OPAL_SUCCESS; + +err: + astlpc_destroy(); + free(ops_data); + + return OPAL_HARDWARE; +} + +static const struct ast_mctp_backend astlpc_backend = { + .ready = astlpc_ready, + .binding = astlpc_binding, + .destroy = astlpc_destroy, +}; + +static void *mctp_malloc(size_t size) { return malloc(size); } +static void mctp_free(void *ptr) { return free(ptr); } +static void *mctp_realloc(void *ptr, size_t size) +{ + return realloc(ptr, size); +} + +#ifdef AST_MCTP_DEBUG +char buffer[320]; +static void mctp_log(int log_lvl, const char *fmt, va_list va) +{ + snprintf(buffer, sizeof(buffer), "%s\n", fmt); + vprlog(log_lvl, buffer, va); +} +#endif + +int ast_mctp_ready(void) +{ + if (!mctp_backend->ready()) + return OPAL_BUSY; + + return OPAL_SUCCESS; +} + +int ast_mctp_message_tx(uint8_t eid, uint8_t *msg, int len) +{ + uint8_t tag = 0; + + return mctp_message_tx(mctp, eid, MCTP_MESSAGE_TO_DST, tag, msg, len); +} + +void ast_mctp_stop_polling(void) +{ + irq_active = true; +} + +#define HOST_MAX_INCOMING_MESSAGE_ALLOCATION 131072 + +/* + * Initialize mctp binding for hbrt and provide interfaces for sending + * and receiving mctp messages. + */ +int ast_mctp_init(uint8_t mode, void (*fn)(uint8_t src_eid, bool tag_owner, + uint8_t msg_tag, void *data, void *msg, size_t len)) +{ + uint64_t start; + + if (mode == MCTP_BINDING_ASTLPC_MODE) + mctp_backend = &astlpc_backend; + else { + mctp_prerr("Unknown AST binding mode: %u", mode); + return OPAL_PARAMETER; + } + + if (!mctp_backend->ready()) + return OPAL_HARDWARE; + + /* skiboot's malloc/free/realloc are macros so they need + * wrappers + */ + mctp_set_alloc_ops(mctp_malloc, mctp_free, mctp_realloc); + + /* + * /-----\ /---------\ + * | bmc | (eid: 8) <- lpc/kcs -> (eid: 9) | skiboot | + * \-----/ pcie \---------/ + * astlpc kcs / astpcie binding + */ + mctp = mctp_init(); + if (!mctp) { + mctp_prerr("mctp init failed"); + return OPAL_HARDWARE; + } + +#ifdef AST_MCTP_DEBUG + /* Setup the trace hook */ + mctp_set_log_custom(mctp_log); +#endif + + mctp_prinfo("libmctp initialized"); + + /* Set the max message size to be large enough */ + mctp_set_max_message_size(mctp, HOST_MAX_INCOMING_MESSAGE_ALLOCATION); + + /* Setup the message rx callback */ + mctp_set_rx_all(mctp, fn, NULL); + + /* Initialise the binding */ + if (mctp_backend->binding()) + goto err; + + /* Initializing the channel requires running the poll function + * a few times to handle the initial setup since we need the + * BMC to reply. + * + * Unfortuntately there's no good way to determine if this + * worked or not so poll for a bit with a timeout. :( + * + * We have to check (bus->state == mctp_bus_state_constructed) + * otherwise mctp_message_tx() will reject the message. + */ + start = mftb(); + while (tb_compare(mftb(), start + msecs_to_tb(250)) == TB_ABEFOREB) + time_wait_ms(10); + + mctp_prwarn("%s - The mctp bus state should be correct now !!!", + __func__); + + return OPAL_SUCCESS; + +err: + mctp_prerr("Unable to initialize MCTP"); + mctp_destroy(mctp); + mctp = NULL; + + return OPAL_HARDWARE; +} + +void ast_mctp_exit(void) +{ + if (mctp_backend && mctp_backend->destroy) + mctp_backend->destroy(); + + if (mctp) + mctp_destroy(mctp); + + mctp = NULL; +} diff --git a/include/ast.h b/include/ast.h index 5e932398..55eeae28 100644 --- a/include/ast.h +++ b/include/ast.h @@ -91,6 +91,17 @@ void ast_setup_ibt(uint16_t io_base, uint8_t irq); /* MBOX configuration */ void ast_setup_sio_mbox(uint16_t io_base, uint8_t irq); +/* AST MCTP configuration */ +#define MCTP_BINDING_ASTLPC_MODE 0 +#define MCTP_BINDING_ASTPCIE_MODE 1 + +int ast_mctp_ready(void); +int ast_mctp_init(uint8_t mode, void (*fn)(uint8_t src_eid, bool tag_owner, + uint8_t msg_tag, void *data, void *msg, size_t len)); +void ast_mctp_exit(void); +void ast_mctp_stop_polling(void); +int ast_mctp_message_tx(uint8_t eid, uint8_t *msg, int len); + #endif /* __SKIBOOT__ */ /* From patchwork Tue Sep 13 10:26:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677214 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=leMNPlcZ; 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 4MRfmK5Zcyz1ynm for ; Tue, 13 Sep 2022 20:27:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmK5SS1z30NN for ; Tue, 13 Sep 2022 20:27:29 +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=leMNPlcZ; 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=mx0b-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=leMNPlcZ; 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 4MRfm20t46z308b for ; Tue, 13 Sep 2022 20:27:13 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9eWEH004457 for ; Tue, 13 Sep 2022 10:27:11 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=CVsyzhGuyYuloI2IrlKiVJYvCjHb6Vx2Qp5WCiDjWqQ=; b=leMNPlcZOB9BnT5BwnZBqqno4K1YUPUT7LEMz7YuMpaGlLR+JtCAwjTLeMBBhe3DLMJk pJC+O+V2I62YUsxhpwPts0WwEms2GZtpGMy+rm2PczuzoUjvEfszoiw7XdgUTO7hGq8C NAb8++d7okHjZncMCa3lPA+kB+DmGk93W8cRhZMcaoYTDZjK9sQCYSGVpZ+wpkUOlgkE 5f4iKcuutcKBPvQ3BuAdajGnZd7FfglVVZrRa33EPChaPXuLolSR9+ZzTljcCSlUtGPh tOtCjt3zRNt5PV4fwO2axZcPmqY/UMvp/elcz/ZUoId1KgFTo+aMqvdNht3vC9aOlCeV /w== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmjay1c1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DALIq2003187 for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06fra.de.ibm.com with ESMTP id 3jghuhtps4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:09 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR7WI30736666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:07 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1A372A4051 for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E68A1A4040 for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:47 +0200 Message-Id: <20220913102705.65506-4-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ce7z0-Oo12kALMiHtgDM5oUcSRwGPsIA X-Proofpoint-ORIG-GUID: ce7z0-Oo12kALMiHtgDM5oUcSRwGPsIA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 03/21] core/pldm: PLDM over MCTP Binding 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" Enable the mctp binding over LPC bus interface and new wrappers to send and receive PLDM messages over the mctp library. PLDM is supported as a message type over MCTP. PLDM over MCTP binding defines the format of PLDM over MCTP messages. An MCTP Endpoint is the terminus for MCTP communication. A physical device that supports MCTP may provide one or more MCTP Endpoints. Endpoints are addressed using a logical address called the Endpoint ID, or EID. EIDs in MCTP are analogous to IP Addresses in Internet Protocol networking. The BMC EID default is 8. First byte of the PLDM over MCTP Message Fields identifies the MCTP message as carrying a PLDM message: Message Type (7 bits) PLDM = 0x01 (000_0001b). Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/Makefile.inc | 6 ++- core/pldm/Makefile.inc | 13 +++++ core/pldm/pldm-mctp.c | 118 +++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 33 ++++++++++++ include/pldm.h | 18 +++++++ 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 core/pldm/Makefile.inc create mode 100644 core/pldm/pldm-mctp.c create mode 100644 core/pldm/pldm.h create mode 100644 include/pldm.h diff --git a/core/Makefile.inc b/core/Makefile.inc index f80019b6..263a0e50 100644 --- a/core/Makefile.inc +++ b/core/Makefile.inc @@ -22,8 +22,12 @@ endif CORE=core/built-in.a +ifeq ($(CONFIG_PLDM),1) +include $(SRC)/core/pldm/Makefile.inc +endif + CFLAGS_SKIP_core/relocate.o = -pg -fstack-protector-all CFLAGS_SKIP_core/relocate.o += -fstack-protector -fstack-protector-strong CFLAGS_SKIP_core/relocate.o += -fprofile-arcs -ftest-coverage -$(CORE): $(CORE_OBJS:%=core/%) +$(CORE): $(CORE_OBJS:%=core/%) $(PLDM) diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc new file mode 100644 index 00000000..c878ef1f --- /dev/null +++ b/core/pldm/Makefile.inc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# Copyright 2022 IBM Corp + +PLDM_DIR ?= core/pldm +SUBDIRS += $(PLDM_DIR) + +CPPFLAGS += -I$(SRC)/pldm/libpldm/ +CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ + +PLDM_OBJS = pldm-mctp.o + +PLDM = $(PLDM_DIR)/built-in.a +$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c new file mode 100644 index 00000000..832b767a --- /dev/null +++ b/core/pldm/pldm-mctp.c @@ -0,0 +1,118 @@ +// 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" + +/* + * Print content of PLDM message in hex mode. + * 15 bytes per line. + * Ex: pldm_mctp_message_tx: 000: 08 01 00 00 02 00 01 + */ +void printbuf(const char *name, const char *msg, int len) +{ + int i, j; + char linebuf[128]; + + linebuf[0] = 0; + + for (i = 0; i < len; i += j) { + linebuf[0] = 0; + for (j = 0; i + j < len && j < 15; j++) { + char s[5]; + + snprintf(s, 5, "%02x ", msg[i + j]); + strcat(linebuf, s); + } + prlog(PR_TRACE, "%s: %03x: %s\n", name, i, linebuf); + } +} + +/* + * Send PLDM message over MCTP + */ +int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int len) +{ + uint8_t *msg; + int rc; + + /* Message TYPE: PLDM = 0x01 (000_0001b) - DSP0240 */ + msg = zalloc(len + 1); + msg[0] = 0x01; + memcpy(&msg[1], buf, len); + + rc = ast_mctp_message_tx(dest_id, msg, len + 1); + free(msg); + + return rc; +} + +/* + * Handle messages received from MCTP + */ +static int handle_message_rx(uint8_t eid, const uint8_t *buf, int len) +{ + struct pldm_rx_data rx; + + if (len < sizeof(rx.msg->hdr)) { + prlog(PR_ERR, "%s: packet is smaller than pldm header\n", __func__); + return OPAL_EMPTY; + } + + memset(&rx, 0, sizeof(rx)); + rx.msg = (struct pldm_msg *) buf; + rx.source_eid = eid; + rx.msg_len = len; + + if (unpack_pldm_header(&rx.msg->hdr, &rx.hdrinf)) { + prlog(PR_ERR, "%s: unable to decode header\n", __func__); + return OPAL_EMPTY; + } + + return OPAL_UNSUPPORTED; +} + +/* + * MCTP message rx callback + */ +static void message_rx(uint8_t eid, bool tag_owner __unused, + uint8_t msg_tag __unused, void *data __unused, + void *vmsg, size_t len) +{ + uint8_t *msg = vmsg; + + prlog(PR_TRACE, "message received: msg: %p, len %zd (eid: %d)\n", + msg, len, eid); + + /* pldm message type */ + if ((msg[0] & 0x7f) != 0x01) { + prlog(PR_ERR, "%s - not a pldm message type\n", __func__); + return; + } + + handle_message_rx(eid, &msg[1], len - 1); +} + +int pldm_mctp_init(uint8_t mode) +{ + int rc; + + /* MCTP Binding */ + rc = ast_mctp_init(mode, message_rx); + if (rc) + prlog(PR_ERR, "Failed to bind MCTP\n"); + + prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); + return rc; +} + +void pldm_mctp_exit(void) +{ + ast_mctp_exit(); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h new file mode 100644 index 00000000..a006d1f4 --- /dev/null +++ b/core/pldm/pldm.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __COREPLDM_H__ +#define __COREPLDM_H__ + +#include +#include + +/* Common support */ + +void printbuf(const char *name, const char *msg, int len); + +/* + * EID is the MCTP endpoint ID, which aids in routing MCTP packets. + * For the EIDs: the valid range is 8-254. + * We are saying that BMC is EID 8 and Skiboot is HOST_EID 9 + */ +#define BMC_EID 8 +#define HOST_EID 9 + +struct pldm_rx_data { + struct pldm_header_info hdrinf; /* parsed message header */ + + struct pldm_msg *msg; + int msg_len; + int source_eid; +}; + +int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int len); + +#endif /* __COREPLDM_H__ */ diff --git a/include/pldm.h b/include/pldm.h new file mode 100644 index 00000000..3aae560c --- /dev/null +++ b/include/pldm.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __PLDM_H__ +#define __PLDM_H__ + +/** + * PLDM over MCTP initialization + */ +int pldm_mctp_init(uint8_t mode); + +/** + * PLDM over MCTP stop + */ +void pldm_mctp_exit(void); + +#endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677229 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=ZRjNNP/A; 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 4MRfpF6RJ1z1ynm for ; Tue, 13 Sep 2022 20:29:09 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfpF5vLBz3cCC for ; Tue, 13 Sep 2022 20:29:09 +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=ZRjNNP/A; 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=mx0b-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=ZRjNNP/A; 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 4MRfmK1p5Qz3bxC for ; Tue, 13 Sep 2022 20:27:29 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAAHok040031 for ; Tue, 13 Sep 2022 10:27:11 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=oRBgDwmcSAE187C1E02BITstHtfcXhmWmv1WvP2gNUY=; b=ZRjNNP/Ae/PVsX+uqiZGWveTmLNtOTfEYf0GGTqJT0/k9dSTRXy9UBdBXydakRayFf7Y CJ90z7Gsrvy+wX2dh80e0iasi5xVxswsju6yebvJ4ouJK/tsD3CWQsmd5jt/3zZKeJdG ir2xVWvF/HmMLosClgOkhT2WUjvqI8zaBtVvrrYJveWQ+AkFE74b4L+E4UEmnvBL5nro 4jldF1hR7J8BCva8Kk0JGyK73RIkCDLJz0OM/KUVXjt0b29FCtrfFGW/7+i1MfRpV4EW DjfmH73s1N5Rifjoi/8nRu1h1owigKhlrk6OCXXyUqBWKQBIZUQ4DL5OjnBUVSXM0rxk Lg== 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 3jjqvh8eax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +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 28DAKUEa005675 for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:09 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARVWb22610182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:31 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 54748A404D for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2DBA9A4040 for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:48 +0200 Message-Id: <20220913102705.65506-5-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 2R13JnZim0Mm3xY4S-higPvjF4T4Qwry X-Proofpoint-ORIG-GUID: 2R13JnZim0Mm3xY4S-higPvjF4T4Qwry X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 04/21] core/pldm: Add PLDM responder support 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" PLDM defines data representations and commands that abstract the platform management hardware. A PLDM Terminus (or responder) is defined as the point of communication termination for PLDM messages and the PLDM functions associated with those messages. A PLDM terminus is not required to process more than one request at a time (that is, it can be "single threaded" and does not have to accept and act on new requests until it has finished responding to any previous request). Some PLDM control and discovery requests (PLDM_TYPE = PLDM_BASE) are mandatory a PLDM terminus has to answer. These following mandatory PLDM command codes for PLDM messaging control and discovery will be defined in next patches. GetTID 0x02 GetPLDMVersion 0x03 GetPLDMTypes 0x04 GetPLDMCommands 0x05 Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-mctp.c | 18 ++++- core/pldm/pldm-responder.c | 145 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 ++ 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-responder.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index c878ef1f..dbca102a 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,7 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ -PLDM_OBJS = pldm-mctp.o +PLDM_OBJS = pldm-mctp.o pldm-responder.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index 832b767a..51dbad0a 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -75,6 +75,14 @@ static int handle_message_rx(uint8_t eid, const uint8_t *buf, int len) return OPAL_EMPTY; } + switch (rx.hdrinf.msg_type) { + case PLDM_REQUEST: + return pldm_responder_handle_request(&rx); + break; + default: + break; + } + return OPAL_UNSUPPORTED; } @@ -105,9 +113,17 @@ int pldm_mctp_init(uint8_t mode) /* MCTP Binding */ rc = ast_mctp_init(mode, message_rx); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to bind MCTP\n"); + goto out; + } + + /* Register mandatory commands we'll respond to */ + rc = pldm_responder_init(); + if (rc) + prlog(PR_ERR, "Failed to register mandatory commands\n"); +out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); return rc; } diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c new file mode 100644 index 00000000..94289cac --- /dev/null +++ b/core/pldm/pldm-responder.c @@ -0,0 +1,145 @@ +// 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 +#include "pldm.h" + +struct pldm_type { + const char *name; + int pldm_type_id; + ver32_t version; + + struct list_head commands; + struct list_node link; +}; + +struct pldm_cmd { + const char *name; + int pldm_cmd_id; + + int (*handler)(const struct pldm_rx_data *req); + + struct list_node link; /* link in the msg type's command list */ +}; + +/* + * Send a response with just a completion code and no payload + */ +static int cc_resp(const struct pldm_rx_data *req, uint8_t type, + uint8_t command, uint8_t cc) +{ + char response_msg[PKT_SIZE(uint8_t)]; + int rc; + + memset(response_msg, 0, sizeof(response_msg)); + + encode_cc_only_resp(req->hdrinf.instance, + type, + command, + cc, + (struct pldm_msg *)response_msg); + + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send response message containing only cc, " + "rc = %d, cc = %d\n", rc, cc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +/* + * PLDM Type / Command wrangling. + */ +LIST_HEAD(pldm_type_list); + +static const struct pldm_type *find_type(int type_id) +{ + struct pldm_type *iter; + + list_for_each(&pldm_type_list, iter, link) { + if (iter->pldm_type_id == type_id) + return iter; + } + + return NULL; +} + +static const struct pldm_cmd *find_cmd(const struct pldm_type *type, int cmd) +{ + struct pldm_cmd *iter; + + list_for_each(&type->commands, iter, link) + if (iter->pldm_cmd_id == cmd) + return iter; + + return NULL; +} + +static void add_type(struct pldm_type *new_type) +{ + assert(new_type->pldm_type_id < 32); /* limited by GetPLDMTypes */ + assert(!find_type(new_type->pldm_type_id)); + + list_head_init(&new_type->commands); + list_add_tail(&pldm_type_list, &new_type->link); + + prlog(PR_DEBUG, "Registered type %s (%d)\n", + new_type->name, new_type->pldm_type_id); +} + +/* + * PLDM Base commands support + */ +static struct pldm_type pldm_base_type = { + .name = "base", + .pldm_type_id = PLDM_BASE, + .version = { 0xF1, 0xF0, 0xF0, 0x00 }, +}; + +int pldm_responder_handle_request(struct pldm_rx_data *rx) +{ + const struct pldm_type *type; + const struct pldm_cmd *cmd; + + prlog(PR_INFO, "Receive PLDM request from BMC, type: 0x%x, command: 0x%x\n", + rx->hdrinf.pldm_type, rx->hdrinf.command); + + type = find_type(rx->hdrinf.pldm_type); + if (!type) { + prlog(PR_ERR, "Type not supported, type: 0x%x\n", + rx->hdrinf.pldm_type); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_ERROR_INVALID_PLDM_TYPE); + return OPAL_UNSUPPORTED; + } + + cmd = find_cmd(type, rx->hdrinf.command); + if (!cmd) { + prlog(PR_ERR, "Command not supported, type: 0x%x, command: 0x%x\n", + rx->hdrinf.pldm_type, rx->hdrinf.command); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_ERROR_UNSUPPORTED_PLDM_CMD); + return OPAL_UNSUPPORTED; + } + + return cmd->handler(rx); +} + +int pldm_responder_init(void) +{ + /* Register mandatory commands we'll respond to - DSP0240 */ + add_type(&pldm_base_type); + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index a006d1f4..3add1bac 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -20,6 +20,8 @@ void printbuf(const char *name, const char *msg, int len); #define BMC_EID 8 #define HOST_EID 9 +#define PKT_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) + struct pldm_rx_data { struct pldm_header_info hdrinf; /* parsed message header */ @@ -30,4 +32,8 @@ struct pldm_rx_data { int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int len); +/* Responder support */ +int pldm_responder_handle_request(struct pldm_rx_data *rx); +int pldm_responder_init(void); + #endif /* __COREPLDM_H__ */ From patchwork Tue Sep 13 10:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677230 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=hhm6zUz8; 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 4MRfpP5V4Jz1ynm for ; Tue, 13 Sep 2022 20:29:17 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfpP52rqz3bxp for ; Tue, 13 Sep 2022 20:29:17 +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=hhm6zUz8; 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=hhm6zUz8; 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 4MRfmK3kRsz3c4w for ; Tue, 13 Sep 2022 20:27:29 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9pV5L029534 for ; Tue, 13 Sep 2022 10:27:12 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=zQ86hmF0hnntIdY+0u7X23UrKhuMUzABP9R7TILdf+M=; b=hhm6zUz8Y/lfRbr/Oz4YLQ+Ad5zOBviyN2gc48YlSuX4UouBYlB1cRaD6sEKE/Xufb8c nezFoOn2fyb8MINNZfoMvkIBHRxhIM57YPuBaFUL5BxZ3+Bq9RP83ZIg+ngvNewJbhIx XzGosXAkcRRoGuFUjlRglXcYM59fBAo4I5MX7xjSOHrEopptmzdhsqheN8SlCHFkBDLg AdDptyK0qxHvlOzJW+8zuWyDWLBmCPLo7MBexTDaba+pzU6X7+n74iU1qyA7xaPq0T2t UKmCD9UXpnEETZ9KjJf/mOVYoVl18wfIc3FQ7SH/7FGfbP7fjuEyHT9xZ5SjxEDVJbNO kg== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqkr91hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKtb3001419 for ; Tue, 13 Sep 2022 10:27:10 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma05fra.de.ibm.com with ESMTP id 3jgj78tpsq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:10 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARWpH22610184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:32 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E921A404D for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 67E10A4040 for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:49 +0200 Message-Id: <20220913102705.65506-6-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: I8dCwHhZrQgX3eehaMMcI6AIv68hcVwW X-Proofpoint-GUID: I8dCwHhZrQgX3eehaMMcI6AIv68hcVwW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=971 impostorscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130044 Subject: [Skiboot] [PATCH V6 05/21] core/pldm: Encode GetTID response 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" A PLDM Terminus is defined as the point of communication termination for PLDM messages and the PLDM functions associated with those messages. Given a PLDM terminus, a mechanism is required that can uniquely identify each terminus so that the semantic information can be bound to that identification. The Terminus ID (TID) is a value that identifies a PLDM terminus. TIDs are used in PLDM messages when it is necessary to identify the PLDM terminus that is the source of the PLDM Message. The GetTID command is used to retrieve the present Terminus ID (TID) setting for a PLDM Terminus. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-responder.c | 50 ++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 +++++ 2 files changed, 56 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 94289cac..6f11030d 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -96,6 +96,17 @@ static void add_type(struct pldm_type *new_type) new_type->name, new_type->pldm_type_id); } +static void add_cmd(struct pldm_type *type, struct pldm_cmd *new_cmd) +{ + assert(new_cmd->pldm_cmd_id < 256); /* limited by GetPLDMCommands */ + assert(new_cmd->handler); + assert(!find_cmd(type, new_cmd->pldm_cmd_id)); + + list_add_tail(&type->commands, &new_cmd->link); + prlog(PR_DEBUG, "Registered command %s (%d) under %s\n", + new_cmd->name, new_cmd->pldm_cmd_id, type->name); +} + /* * PLDM Base commands support */ @@ -105,6 +116,44 @@ static struct pldm_type pldm_base_type = { .version = { 0xF1, 0xF0, 0xF0, 0x00 }, }; +/* + * GetTID command (0x02) + * The GetTID command is used to retrieve the present Terminus ID (TID) + * setting for a PLDM Terminus. + */ +static int base_get_tid_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_tid_resp)]; + int rc; + + memset(response_msg, 0, sizeof(response_msg)); + + rc = encode_get_tid_resp(req->hdrinf.instance, + PLDM_SUCCESS, + HOST_TID, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetTID response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_tid = { + .name = "PLDM_GET_TID", + .pldm_cmd_id = PLDM_GET_TID, + .handler = base_get_tid_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -140,6 +189,7 @@ int pldm_responder_init(void) { /* Register mandatory commands we'll respond to - DSP0240 */ add_type(&pldm_base_type); + add_cmd(&pldm_base_type, &pldm_base_get_tid); return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 3add1bac..7df413da 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -20,6 +20,12 @@ void printbuf(const char *name, const char *msg, int len); #define BMC_EID 8 #define HOST_EID 9 +/* + * Skiboot's PLDM Terminus ID. + * BMC TID is 1, HB is 2, Skiboot is 3. + */ +#define HOST_TID 3 + #define PKT_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) struct pldm_rx_data { From patchwork Tue Sep 13 10:26:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677217 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=RQj6E9Km; 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 4MRfmc3PGmz1ynm for ; Tue, 13 Sep 2022 20:27:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmc3GnHz3bnH for ; Tue, 13 Sep 2022 20:27:44 +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=RQj6E9Km; 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=mx0b-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=RQj6E9Km; 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 4MRfm4065Gz30F7 for ; Tue, 13 Sep 2022 20:27:15 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPDEH018455 for ; Tue, 13 Sep 2022 10:27:12 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=HvmfG3+q+FVISyOtBSvxHOBN4dSVLe7upu4El1wptUk=; b=RQj6E9KmZzwpRBOF3vQyeGG/Bf1u1xL+gHizjnsTBnPSMH1fz2qmE6HfD/WxXaPh6E5i NoeUDP2xjNZ9qUTGPkNoXecHANiRF5mMZFxHbpEcoP1QVk2w+fx90KQBV/1ozD78olBe ZOfvT8DATtDf+BDlfTqdRjvcnN8vGGQdwYHwWxdPXIUVjEJPBuixiwRLZP50h3kQuQTB Y7P0F4KgDRReihjKVHPVt2hReZteIXzbrU7r4Yr41VzNAPLiSmSS9DkF+rnR+ibHikSg 6zhAiXFbovN7zFxTSGOsluW5nEmH7pWASQEJa8onMj0awq0rKAJTj0025y6fUHS5+wI2 Sw== 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 3jjqvh8eb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +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 28DAKZ3Q005695 for ; Tue, 13 Sep 2022 10:27:10 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnpt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:10 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARWhK22610186 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:32 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA200A404D for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A2AE1A4040 for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:50 +0200 Message-Id: <20220913102705.65506-7-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ae86QQdoFEpZ4nHyAgeC-Tms7OXlIqpW X-Proofpoint-ORIG-GUID: Ae86QQdoFEpZ4nHyAgeC-Tms7OXlIqpW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 06/21] core/pldm: Encode GetPLDMTypes response 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 GetPLDMTypes command can be used to discover the PLDM type capabilities supported by a PLDM terminus and to get a list of the PLDM types that are supported. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-responder.c | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 6f11030d..6058af51 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -154,6 +154,57 @@ static struct pldm_cmd pldm_base_get_tid = { .handler = base_get_tid_handler, }; +/* + * GetPLDMTypes (0x04) + * The GetPLDMTypes command can be used to discover the PLDM type + * capabilities supported by a PLDM terminus and to get a list of the + * PLDM types that are supported. + */ +static int base_get_types_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_types_resp)]; + bitmap_elem_t type_map[BITMAP_ELEMS(32)]; + struct pldm_type *iter; + int rc; + + /* + * build the supported type list from the registered type + * handlers + */ + memset(type_map, 0, sizeof(type_map)); + list_for_each(&pldm_type_list, iter, link) + bitmap_set_bit(type_map, iter->pldm_type_id); + + for (int i = 0; i < BITMAP_ELEMS(32); i++) + type_map[i] = cpu_to_le64(type_map[i]); + + memset(response_msg, 0, sizeof(response_msg)); + rc = encode_get_types_resp(req->hdrinf.instance, + PLDM_SUCCESS, + (bitfield8_t *)type_map, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMTypes Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMTypes response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_types = { + .name = "PLDM_GET_PLDM_TYPES", + .pldm_cmd_id = PLDM_GET_PLDM_TYPES, + .handler = base_get_types_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -190,6 +241,7 @@ int pldm_responder_init(void) /* Register mandatory commands we'll respond to - DSP0240 */ add_type(&pldm_base_type); add_cmd(&pldm_base_type, &pldm_base_get_tid); + add_cmd(&pldm_base_type, &pldm_base_get_types); return OPAL_SUCCESS; } From patchwork Tue Sep 13 10:26: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: 1677231 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=UjFwb/Hd; 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 4MRfpX461Kz1ynm for ; Tue, 13 Sep 2022 20:29:24 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfpX3Fswz3c3Z for ; Tue, 13 Sep 2022 20:29:24 +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=UjFwb/Hd; 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=UjFwb/Hd; 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 4MRfmM0Ydvz3bvZ for ; Tue, 13 Sep 2022 20:27:30 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAFdG0027313 for ; Tue, 13 Sep 2022 10:27:12 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=RdOqEArKUCyTS50T8b3hwi/ZxpHz6NDuft4ac/tR5wQ=; b=UjFwb/HdAdvS5kCqg0u4nnrnTfJXw3nHRoZPOz2CfR+fgnRdSHjxJVP0uU+H2LDTsR3n ekPF5j2AP2RaDBLyS0rYbH0dzeMOTvC8jYs8/BTgXNqgtqLL1cWGg25Mlq78/NagLFeq OfnS0irsBjIImbUmrH+bd37ekspX7qexh1f++jDpZ2L+5JBPWyw90PjMrL7FikFF6KIB pfwk7LmhdTDGYlR0qO48ZjG8KQtSlaxCUafHrpqmRIf2xOW+28CTPYSpOtS15zPQlv7U Os+nU2a+4ueBcxHuuyoa+9qJzphwmG9uitAjZCxmcqbnAni8HTgA6001fTypZ5RDmGzI fQ== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvmk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAL1nq007202 for ; Tue, 13 Sep 2022 10:27:10 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 3jgj79kncg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:10 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR8wd11076064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:08 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 10AF2A404D for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD6A5A4040 for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:51 +0200 Message-Id: <20220913102705.65506-8-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: uTBRulRdJUTvAC2cssMjMvVxs3vo1O1y X-Proofpoint-ORIG-GUID: uTBRulRdJUTvAC2cssMjMvVxs3vo1O1y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 07/21] core/pldm: Encode GetPLDMCommands response 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 GetPLDMCommands command can be used to discover the PLDM command capabilities supported by a PLDM terminus for a specific PLDM Type and version as a responder. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-responder.c | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 6058af51..88545685 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -205,6 +205,95 @@ static struct pldm_cmd pldm_base_get_types = { .handler = base_get_types_handler, }; +/* + * Extended error codes defined for the Base command set. + */ +#define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83 +#define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84 + +/* + * GetPLDMCommands (0x05) + * The GetPLDMCommands command can be used to discover the PLDM command + * capabilities supported by aPLDM terminus for a specific PLDM Type and + * version as a responder. + */ +static int base_get_commands_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_commands_resp)]; + bitmap_elem_t cmd_map[BITMAP_ELEMS(256)]; + const struct pldm_type *type; + const struct pldm_cmd *iter; + size_t payload_len; + ver32_t version; + uint8_t type_id; + int rc; + + payload_len = req->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_commands_req(req->msg, payload_len, + &type_id, &version); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPLDMCommands request, rc = %d", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + type = find_type(type_id); + if (!type) { + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_PLDM_TYPE_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + if (memcmp(&type->version, &version, sizeof(version))) { + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_PLDM_VERSION_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + /* + * build the supported type list from the registered type + * handlers + */ + memset(cmd_map, 0, sizeof(cmd_map)); + list_for_each(&type->commands, iter, link) + bitmap_set_bit(cmd_map, iter->pldm_cmd_id); + /* fix the endian */ + for (int i = 0; i < BITMAP_ELEMS(256); i++) + cmd_map[i] = cpu_to_le64(cmd_map[i]); + + memset(response_msg, 0, sizeof(response_msg)); + + /* create a PLDM response message for GetPLDMCommands */ + rc = encode_get_commands_resp(req->hdrinf.instance, + PLDM_SUCCESS, + (bitfield8_t *)cmd_map, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMCommands Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMCommands response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_commands = { + .name = "PLDM_GET_PLDM_COMMANDS", + .pldm_cmd_id = PLDM_GET_PLDM_COMMANDS, + .handler = base_get_commands_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -242,6 +331,7 @@ int pldm_responder_init(void) add_type(&pldm_base_type); add_cmd(&pldm_base_type, &pldm_base_get_tid); add_cmd(&pldm_base_type, &pldm_base_get_types); + add_cmd(&pldm_base_type, &pldm_base_get_commands); return OPAL_SUCCESS; } From patchwork Tue Sep 13 10:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677244 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=OBVye9jc; 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 4MRfrF6Bvkz1ync for ; Tue, 13 Sep 2022 20:30:53 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrF5Nxwz3cB7 for ; Tue, 13 Sep 2022 20:30:53 +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=OBVye9jc; 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=OBVye9jc; 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 4MRfmP6SJxz3c5v for ; Tue, 13 Sep 2022 20:27:32 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9pXj4029657 for ; Tue, 13 Sep 2022 10:27:12 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=Xz2zqylHiLpu2oH9Wdv716jRjLNtrYhS8640/LuY4X0=; b=OBVye9jc2GnaNeFWBEZxJpdHn++fa4Ter5NfxW0hcxIXpypwh2YYjhQCJH5KayTRAM+Z Mb+v2xbD0euJttvYw7smaqx8o4FlLnpfxmxjm2q/BRHJXxE+7yyFeF/YZknShlu74CIe qhKDRklTCFWkIE9k0+SY6ddCXOFO7Ok9hrSLRCreU8O55Gf8nEazpAZMqbM8giXPDFpU +itbsbORxGWjSPbBV6cPOt+O+6NP3+vXiKRc3ccFq+/5sqZQmxK12eh6yAqf+TgxWJH7 qTVMThwl8cyIsnvSt9Q2RHpeyJ+jonGi2AxGR6G8TAFiCktPlAGLUEUxjKC1pZOzpWQV HA== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqkr91j6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKdCS003216 for ; Tue, 13 Sep 2022 10:27:10 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umxs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:10 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR8u211076068 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:08 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C24DA404D for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 256C3A4040 for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:52 +0200 Message-Id: <20220913102705.65506-9-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: yFDKIlrWGEwpde7VlBPsz6So_pBQJ7sG X-Proofpoint-GUID: yFDKIlrWGEwpde7VlBPsz6So_pBQJ7sG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130044 Subject: [Skiboot] [PATCH V6 08/21] core/pldm: Encode GetPLDMVersion response 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 GetPLDMVersion command can be used to retrieve the PLDM base specification versions that the PLDM terminus supports, as well as the PLDM Type specification versions supported for each PLDM Type. The reported version for Type 0 (PLDMbase) shall be encoded as 0xF1F1F000. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-responder.c | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 88545685..230b9c05 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -208,6 +208,7 @@ static struct pldm_cmd pldm_base_get_types = { /* * Extended error codes defined for the Base command set. */ +#define INVALID_TRANSFER_OPERATION_FLAG 0x80 #define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83 #define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84 @@ -294,6 +295,88 @@ static struct pldm_cmd pldm_base_get_commands = { .handler = base_get_commands_handler, }; +/* + * GetPLDMVersion (0x03) + * The GetPLDMVersion command can be used to retrieve the PLDM base + * specification versions that the PLDM terminus supports, as well as + * the PLDM Type specification versions supported for each PLDM Type. + */ +static int base_get_version_handler(const struct pldm_rx_data *req) +{ + uint32_t tmp[2]; + char response_msg[PKT_SIZE(struct pldm_get_version_resp) + sizeof(tmp)]; + const struct pldm_type *type; + uint8_t type_id, opflag; + size_t payload_len; + uint32_t xfer_handle; + int rc; + + payload_len = req->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_version_req(req->msg, payload_len, + &xfer_handle, + &opflag, + &type_id); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPLDMVersion request, rc = %d", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + /* reject multipart requests */ + if (opflag != PLDM_GET_FIRSTPART) { + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_TRANSFER_OPERATION_FLAG); + return OPAL_PARAMETER; + } + + type = find_type(type_id); + if (!type) { + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_PLDM_TYPE_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + /* pack a scratch buffer with our version(s) and CRC32 the lot */ + memcpy(&tmp[0], &type->version, 4); + + tmp[1] = cpu_to_le32(pldm_crc32(&type->version, 4)); + + memset(response_msg, 0, sizeof(response_msg)); + + /* create a PLDM response for GetPLDMVersion */ + rc = encode_get_version_resp(req->hdrinf.instance, + PLDM_SUCCESS, + 0x0, /* no handle */ + PLDM_START_AND_END, + (ver32_t *) tmp, + sizeof(tmp), + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMVersion Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMVersion response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_version = { + .name = "PLDM_GET_PLDM_VERSION", + .pldm_cmd_id = PLDM_GET_PLDM_VERSION, + .handler = base_get_version_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -332,6 +415,7 @@ int pldm_responder_init(void) add_cmd(&pldm_base_type, &pldm_base_get_tid); add_cmd(&pldm_base_type, &pldm_base_get_types); add_cmd(&pldm_base_type, &pldm_base_get_commands); + add_cmd(&pldm_base_type, &pldm_base_get_version); return OPAL_SUCCESS; } From patchwork Tue Sep 13 10:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677220 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=da+SCGmf; 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 4MRfmz30tmz1ynm for ; Tue, 13 Sep 2022 20:28:03 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmz2846z308w for ; Tue, 13 Sep 2022 20:28:03 +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=da+SCGmf; 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=mx0b-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=da+SCGmf; 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 4MRfm432rqz308b for ; Tue, 13 Sep 2022 20:27:16 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9jBpq002956 for ; Tue, 13 Sep 2022 10:27:14 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=eKf7SoDCFuETtzZwKdNI3uglO7jfYtG4WWCbrnU7MXw=; b=da+SCGmfwab0T4t/hUByIKc3BV7gPW1u+d2S0R76cGHFpvyEQtgnnJBvZJ91BT9o8xNz bReKn4HWcMZ1cfSmL6tD8cvjH4HoLe3hpy0m/JMcFqd9MR5tRV4BiVvhgk4FFuyPbSgX KqZ3p8xM1UJfdIWUzxIbK+aBEqDjxxFsj2oI7lVTCjcocJ8CT+Kwhj/rEopqET15IX5b I7I/KWRrwBicnAdlVFKsLQtTzqaRCrXLb6viyvRev3DPpFZDvwtqJfvQZpHztDKpw7D5 15QkAavoUazX3SHlUqUeLMpsY8Qpa/mG1bqDTe7KBPi1SPuHx7VGG1H8t+AYoQgTN7/i XA== 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 3jjmjay1cy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +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 28DAKrBe006140 for ; Tue, 13 Sep 2022 10:27:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnpu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:10 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR8IH11076070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:08 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B7DDA404D for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 611B6A4040 for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:53 +0200 Message-Id: <20220913102705.65506-10-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: IjlS-A2ZdXUpuKJdxkWWfAOHFVNgkmRM X-Proofpoint-ORIG-GUID: IjlS-A2ZdXUpuKJdxkWWfAOHFVNgkmRM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 09/21] core/pldm: Implement PLDM requester 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" Implement a way for sending PLDM requests for specific PLDM commands. Send a PLDM request message. Wait for corresponding response message, which once received, is returned to the caller. If there's data available, return success only if data is a PLDM response message that matches instance, pldm_type and command code. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-mctp.c | 9 +- core/pldm/pldm-requester.c | 331 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 9 + 4 files changed, 349 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-requester.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index dbca102a..a9b3b7e6 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,7 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ -PLDM_OBJS = pldm-mctp.o pldm-responder.o +PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index 51dbad0a..c7d7bb3b 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -76,6 +76,8 @@ static int handle_message_rx(uint8_t eid, const uint8_t *buf, int len) } switch (rx.hdrinf.msg_type) { + case PLDM_RESPONSE: + return pldm_requester_handle_response(&rx); case PLDM_REQUEST: return pldm_responder_handle_request(&rx); break; @@ -120,8 +122,13 @@ int pldm_mctp_init(uint8_t mode) /* Register mandatory commands we'll respond to */ rc = pldm_responder_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to register mandatory commands\n"); + goto out; + } + + /* Requester implementation */ + pldm_requester_init(); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm-requester.c b/core/pldm/pldm-requester.c new file mode 100644 index 00000000..412d495a --- /dev/null +++ b/core/pldm/pldm-requester.c @@ -0,0 +1,331 @@ +// 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 +#include "pldm.h" + +struct pldm_request { + struct list_node link; + + /* originating request params */ + int dest; + int instance; + int cmd_code; + int type; + + /* messages requested */ + void *request_msg; + int request_len; + + /* timeout handling */ + struct timer timeout; + uint64_t timeout_ms; + uint64_t start_time; + + /* completion callback */ + void (*complete)(struct pldm_rx_data *rx, void *data); + void *complete_data; +}; + +struct pldm_response { + void **response_msg; + size_t *response_len; + bool done; + int rc; +}; + +/* pldm requests queue */ +static LIST_HEAD(list_pldm_requests); +struct lock list_lock; +struct timer requests_timer; + +static struct pldm_request *active_request; + +static bool matches_request(const struct pldm_rx_data *rx, + const struct pldm_request *req) +{ + if (req->instance != rx->hdrinf.instance) + return false; + if (req->type != rx->hdrinf.pldm_type) + return false; + if (req->cmd_code != rx->hdrinf.command) + return false; + + return true; +} + +static void send_and_wait_complete(struct pldm_rx_data *rx, void *data) +{ + struct pldm_response *resp = (struct pldm_response *)data; + int len; + + if (rx != NULL) { + len = rx->msg_len; + *resp->response_len = len; + *resp->response_msg = zalloc(len); + memcpy(*resp->response_msg, rx->msg, len); + + resp->rc = OPAL_SUCCESS; + } else { + *resp->response_len = 0; + *resp->response_msg = NULL; + resp->rc = OPAL_TIMEOUT; + } + + resp->done = true; +} + +static void handle_response(struct pldm_rx_data *rx) +{ + uint64_t now; + + if (active_request == NULL) { + prlog(PR_ERR, "%s: No active request\n", __func__); + return; + } + + /* unactivate the timer */ + if (rx != NULL) + cancel_timer(&active_request->timeout); + + if (active_request->complete) + active_request->complete(rx, active_request->complete_data); + + now = mftb(); + prlog(PR_TRACE, "%s: Finished after %ldms, t:%d c:%d i:%d \n", + __func__, + tb_to_msecs(now - active_request->start_time), + active_request->type, + active_request->cmd_code, + active_request->instance); + + free(active_request->request_msg); + free(active_request); + active_request = NULL; +} + +/* + * Timeout :( + */ +static void expiry(struct timer *t __unused, void *data, uint64_t now __unused) +{ + struct pldm_request *req = (struct pldm_request *)data; + + if (active_request == NULL) { + prlog(PR_ERR, "request timedout! (active request NULL)\n"); + return; + } + + prlog(PR_ERR, "request timedout! (active request: t:%d c:%d i:%d)\n", + active_request->type, + active_request->cmd_code, + active_request->instance); + + prlog(PR_TRACE, "%s: Original request t:%d c:%d i:%d -----\n", + __func__, req->type, req->cmd_code, req->instance); + + /* no data received. Finish the procedure */ + handle_response(NULL); +} + +/* + * Handle PLDM message received from the PLDM terminus over MCTP + */ +int pldm_requester_handle_response(struct pldm_rx_data *rx) +{ + /* check the message received */ + if (active_request == NULL) { + prlog(PR_ERR, "%s: No active request. " + "Response received t:%d c:%d i:%d\n", + __func__, + rx->hdrinf.pldm_type, + rx->hdrinf.command, + rx->hdrinf.instance); + return OPAL_WRONG_STATE; + } + + if (!matches_request(rx, active_request)) { + prlog(PR_ERR, "%s: Unexpected response! t:%d c:%d i:%d want %d,%d,%d\n", + __func__, + rx->hdrinf.pldm_type, + rx->hdrinf.command, + rx->hdrinf.instance, + active_request->type, + active_request->cmd_code, + active_request->instance + ); + return OPAL_WRONG_STATE; + } + + /* The expected message seems correct */ + handle_response(rx); + + return OPAL_SUCCESS; +} + +/* + * Send the PLDM request + */ +static void requests_poller(struct timer *t __unused, + void *data __unused, + uint64_t now __unused) +{ + int rc = OPAL_SUCCESS; + + lock(&list_lock); + + /* no new request to handle */ + if (list_empty(&list_pldm_requests)) + goto out; + + /* wait for the end of the processing of the current request */ + if (active_request) + goto out; + + /* remove the first entry in a list */ + active_request = list_pop(&list_pldm_requests, + struct pldm_request, + link); + + /* Start timer to control a timeout from the PLDM terminus */ + init_timer(&active_request->timeout, expiry, active_request); + schedule_timer(&active_request->timeout, + msecs_to_tb(active_request->timeout_ms)); + active_request->start_time = mftb(); + + /* Send PLDM message over MCTP */ + prlog(PR_TRACE, "%s: Sending request to BMC t:%d c:%d i:%d -----\n", + __func__, + active_request->type, + active_request->cmd_code, + active_request->instance); + + rc = pldm_mctp_message_tx(active_request->dest, + active_request->request_msg, + active_request->request_len); + if (rc) + prlog(PR_ERR, "%s: Error %d while sending request\n", + __func__, rc); + +out: + unlock(&list_lock); + schedule_timer(&requests_timer, msecs_to_tb(5)); +} + +/* + * Add PLDM request in the queue + */ +static int queue_request(void *request_msg, int request_len, + uint64_t timeout_ms, + void (*complete)(struct pldm_rx_data *rx, void *data), + void *complete_data) +{ + struct pldm_header_info hdrinf; + struct pldm_request *pending; + + if (unpack_pldm_header(request_msg, &hdrinf)) { + prlog(PR_ERR, "%s: error parsing pldm header\n", + __func__); + return OPAL_PARAMETER; + } + + pending = zalloc(sizeof(struct pldm_request)); + + pending->dest = BMC_EID; + pending->instance = hdrinf.instance; + pending->type = hdrinf.pldm_type; + pending->cmd_code = hdrinf.command; + pending->timeout_ms = timeout_ms; + pending->request_msg = zalloc(request_len); + memcpy(pending->request_msg, request_msg, request_len); + + pending->request_len = request_len; + pending->complete = complete; + pending->complete_data = complete_data; + + /* add an entry at the end of a linked list */ + lock(&list_lock); + prlog(PR_TRACE, "%s: Add request t:%d c:%d i:%d -----\n", + __func__, + pending->type, + pending->cmd_code, + pending->instance); + list_add_tail(&list_pldm_requests, &pending->link); + unlock(&list_lock); + + return OPAL_SUCCESS; +} + +#define TIMEOUT_MS 8000 + +/* + * Queue a PLDM request and don't wait. + * When a response is received, call the associated callback. + */ +int pldm_requester_queue(void *request_msg, size_t request_len, + void (*complete)(struct pldm_rx_data *rx, void *data), + void *complete_data) +{ + int rc = OPAL_SUCCESS; + + rc = ast_mctp_ready(); + if (rc) { + prlog(PR_ERR, "%s: BMC is not listening (rc: %d)\n", + __func__, rc); + return rc; + } + + /* Queue PLDM request */ + rc = queue_request(request_msg, request_len, + TIMEOUT_MS, complete, + complete_data); + if (rc) { + prlog(PR_ERR, "%s: Error %d while queuing request\n", + __func__, rc); + return rc; + } + + return rc; +} + +/* + * Queue a PLDM request and spin until we get a response. + */ +int pldm_requester_queue_and_wait(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + struct pldm_response resp; + int rc; + + memset(&resp, 0, sizeof(resp)); + resp.response_msg = response_msg; + resp.response_len = response_len; + + rc = pldm_requester_queue(request_msg, request_len, + send_and_wait_complete, &resp); + if (rc) + return rc; + + /* wait for a response from the BMC */ + do { + time_wait_ms(5); + } while (!resp.done); + + return resp.rc; +} + +void pldm_requester_init(void) +{ + /* lock used to queue and unqueue pldm requests */ + init_lock(&list_lock); + + init_timer(&requests_timer, requests_poller, NULL); + schedule_timer(&requests_timer, msecs_to_tb(5)); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 7df413da..fa7a80de 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -42,4 +42,13 @@ int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int len); int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); +/* Requester support */ +int pldm_requester_handle_response(struct pldm_rx_data *rx); +int pldm_requester_queue(void *request_msg, size_t request_len, + void (*complete)(struct pldm_rx_data *rx, void *data), + void *complete_data); +int pldm_requester_queue_and_wait(void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); +void pldm_requester_init(void); + #endif /* __COREPLDM_H__ */ From patchwork Tue Sep 13 10:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677216 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=112.213.38.117; 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=Ebot2iaF; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4MRfmW2PLmz1ynm for ; Tue, 13 Sep 2022 20:27:39 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmW2Hktz3c7B for ; Tue, 13 Sep 2022 20:27:39 +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=Ebot2iaF; 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.156.1; 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=Ebot2iaF; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 4MRfm36jHlz308b for ; Tue, 13 Sep 2022 20:27:15 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPLGn001425 for ; Tue, 13 Sep 2022 10:27:14 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=Jn6yrz55aDVoN4uvgfANaCOs4dTjyKgeN4qM1tAhh0k=; b=Ebot2iaFMMmMvZtv8HTL0e4Jk9cFGA27jwEue2oQNPpYZl0flFXyYyRPWZKhmEqDwH9y obOKaKqcd9MVX5/saniZJdoNoIwIIXckAQ9ZVTPqS5DlZcDpn+/PLUHH4wRDJuXZQ/eq atXRMR29mi39oFAcuw6N8Mr5s9aLMPSr4Nosho6Tb60c0hrTUzw1zT9pQtaZl6f73nqC sKC3rSX+Xg7yrkFpPl98X6DPDSGgft+LqppKyl80wDnbdQ3bU4p4X78yYfxyfNNwBIWk Fmdttvg8sRrs9nVLOF31VhcdkFg9u86bM62TXdycdmeFLYs4271wYHfPQH0y3AiTkT+d Cw== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjr3j8176-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKiih029952 for ; Tue, 13 Sep 2022 10:27:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma01fra.de.ibm.com with ESMTP id 3jgj78tp3j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR8Rk11076072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:08 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB3C5A404D for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A043CA4040 for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:54 +0200 Message-Id: <20220913102705.65506-11-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: emyytg8LzmJMK7LRlZomcmUhc8qjXxSI X-Proofpoint-ORIG-GUID: emyytg8LzmJMK7LRlZomcmUhc8qjXxSI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 10/21] core/pldm: PLDM for Platform Monitoring and Control Specification 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" This specification defines the functions and data structures used for discovering, describing, initializing, and accessing sensors and effecters within the management controllers and management devices of a platform management subsystem using PLDM messaging. A PDR (Platform Descriptor Record) is a set of data that is used to provide semantic information about sensors, effecters, monitored or controller entities, and functions and services within a PLDM implementation. PDRs are mostly used to support PLDM monitoring and control and platform events. The PDRs for a PLDM subsystem are collected into a single, central PDR Repository. A central repository provides a single place from which PDR information can be retrieved. The GetPDR command is used to retrieve individual PDRs from a PDR Repository. The record is identified by the PDR recordHandle value that is passed in the request. The patch dump all the PDRs within a PDR Repository. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 3 + core/pldm/pldm-base-requests.c | 67 ++++++++ core/pldm/pldm-mctp.c | 16 ++ core/pldm/pldm-platform-requests.c | 254 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 10 ++ 5 files changed, 350 insertions(+) create mode 100644 core/pldm/pldm-base-requests.c create mode 100644 core/pldm/pldm-platform-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index a9b3b7e6..04c4c51b 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,10 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ +CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes + PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o +PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-base-requests.c b/core/pldm/pldm-base-requests.c new file mode 100644 index 00000000..454bfb1b --- /dev/null +++ b/core/pldm/pldm-base-requests.c @@ -0,0 +1,67 @@ +// 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 +#include "pldm.h" + +static uint8_t bmc_tid = -1; + +uint8_t pldm_base_get_bmc_tid(void) +{ + return bmc_tid; +} + +/* + * Create a PLDM request message for GetTID. + */ +int pldm_base_get_tid_req(void) +{ + char request_msg[PKT_SIZE(0)]; /* the command doesn't have a message payload */ + size_t response_len, payload_len; + void *response_msg; + int rc; + + struct pldm_get_tid_resp response; + + /* Encode the get tid request */ + rc = encode_get_tid_req(DEFAULT_INSTANCE_ID, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetTID, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + + rc = decode_get_tid_resp(response_msg, payload_len, + &response.completion_code, + &response.tid); + if ((rc != PLDM_SUCCESS) || (response.completion_code != PLDM_SUCCESS)) { + prlog(PR_ERR, "Decode GetTID Error, rc: %d, cc: %d\n", + rc, response.completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + prlog(PR_INFO, "BMC's TID is %d\n", response.tid); + bmc_tid = response.tid; + free(response_msg); + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index c7d7bb3b..a351a340 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -113,6 +113,8 @@ int pldm_mctp_init(uint8_t mode) { int rc; + prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); + /* MCTP Binding */ rc = ast_mctp_init(mode, message_rx); if (rc) { @@ -130,6 +132,18 @@ int pldm_mctp_init(uint8_t mode) /* Requester implementation */ pldm_requester_init(); + /* Get BMC tid */ + rc = pldm_base_get_tid_req(); + if (rc) { + prlog(PR_ERR, "Failed to retrieve BMC Tid\n"); + goto out; + } + + /* Get PDRs data */ + rc = pldm_platform_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Data Records\n"); + out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); return rc; @@ -137,5 +151,7 @@ out: void pldm_mctp_exit(void) { + pldm_platform_exit(); + ast_mctp_exit(); } diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c new file mode 100644 index 00000000..965820c8 --- /dev/null +++ b/core/pldm/pldm-platform-requests.c @@ -0,0 +1,254 @@ +// 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 +#include +#include +#include +#include "pldm.h" + +#define NO_MORE_PDR_HANDLES 0 + +static pldm_pdr *pdrs_repo; +static bool pdr_ready; + +struct pldm_pdrs { + uint32_t record_hndl; + bool done; + int rc; +}; + +static void pdr_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + pdr_ready = false; + + pldm_pdr_destroy(pdrs_repo); + return; + } + + /* Mark ready */ + pdr_ready = true; +} + +struct get_pdr_response { + uint8_t completion_code; + uint32_t next_record_hndl; + uint32_t next_data_transfer_hndl; + uint8_t transfer_flag; + uint16_t resp_cnt; + uint8_t *record_data; + size_t record_data_length; + uint8_t transfer_crc; +}; + +static int encode_and_queue_get_pdr_req(struct pldm_pdrs *pdrs); + +static void get_pdr_req_complete(struct pldm_rx_data *rx, + void *data) +{ + struct pldm_pdrs *pdrs = (struct pldm_pdrs *)data; + uint32_t record_hndl = pdrs->record_hndl; + size_t payload_len; + int rc, i; + + struct get_pdr_response response; + + prlog(PR_DEBUG, "%s - record_hndl: %d\n", __func__, record_hndl); + + /* Decode the message twice; the first time, the payload buffer + * will be null so that the decoder will simply tell us how big + * the buffer should be. Then we create a suitable payload + * buffer and call the decoder again, this time with the real + * buffer so that it can fill it with data from the message. + * + * transfer_crc is not used in case of PLDM_START_AND_END. + */ + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + response.record_data_length = 0; + response.record_data = NULL; + + for (i = 0; i < 2; i++) { + rc = decode_get_pdr_resp( + rx->msg, payload_len, + &response.completion_code, + &response.next_record_hndl, + &response.next_data_transfer_hndl, + &response.transfer_flag, + &response.resp_cnt, + response.record_data, + response.record_data_length, + &response.transfer_crc); + + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + /* Message decoding failed */ + prlog(PR_ERR, "Decode GetPDRResp Error (rc: %d, cc: %d)\n", + rc, response.completion_code); + + /* BMC is not ready, try again */ + if (response.completion_code == PLDM_ERROR_NOT_READY) { + time_wait_ms(500); + encode_and_queue_get_pdr_req(pdrs); + return; + } + + pdrs->rc = OPAL_PARAMETER; + pdrs->done = true; + return; + } + + if (response.record_data == NULL) { + response.record_data_length = response.resp_cnt; + response.record_data = zalloc(response.resp_cnt); + } + } + + /* we do not support multipart transfer */ + if (response.transfer_flag != PLDM_START_AND_END) + prlog(PR_ERR, "Transfert GetPDRResp not complete, transfer_flag: %d\n", + response.transfer_flag); + + prlog(PR_DEBUG, "%s - record_hndl: %d, next_record_hndl: %d, resp_cnt: %d\n", + __func__, record_hndl, + response.next_record_hndl, + response.resp_cnt); + + /* Add a PDR record to a PDR repository */ + pldm_pdr_add(pdrs_repo, + response.record_data, + response.resp_cnt, + record_hndl, + false); + + free(response.record_data); + + if (response.next_record_hndl != NO_MORE_PDR_HANDLES) { + pdrs->record_hndl = response.next_record_hndl; + encode_and_queue_get_pdr_req(pdrs); + } else { + pdr_init_complete(true); + pdrs->done = true; + pdrs->rc = OPAL_SUCCESS; + prlog(PR_DEBUG, "%s - done\n", __func__); + } +} + +/* + * Send/receive a PLDM GetPDR stateEffecter request message + * Get platform descriptor records. + * + * pldmtool platform GetPDR -t stateEffecter + * ... + * { + * "nextRecordHandle": 138, + * "responseCount": 30, + * "recordHandle": 137, + * "PDRHeaderVersion": 1, + * "PDRType": "State Effecter PDR", + * "recordChangeNumber": 0, + * "dataLength": 20, + * "PLDMTerminusHandle": 1, + * "effecterID": 43, + * "entityType": "[Physical] System chassis (main enclosure)", + * ... + * "Off-Soft Graceful(9)" + * } + * ... + */ +static int encode_and_queue_get_pdr_req(struct pldm_pdrs *pdrs) +{ + char request_msg[PKT_SIZE(struct pldm_get_pdr_req)]; + uint32_t record_hndl = pdrs->record_hndl; + int rc; + + struct pldm_get_pdr_req pdr_req = { + .record_handle = record_hndl, /* record change number (0 for first request) */ + .data_transfer_handle = 0, /* (0 if transfer op is FIRSTPART) */ + .transfer_op_flag = PLDM_GET_FIRSTPART, /* transfer op flag */ + .request_count = SHRT_MAX, /* Don't limit the size of the PDR */ + .record_change_number = 0 /* record change number (0 for first request) */ + }; + + prlog(PR_DEBUG, "%s - record_hndl: %d\n", __func__, record_hndl); + + /* Encode the get_PDR request */ + rc = encode_get_pdr_req(DEFAULT_INSTANCE_ID, + pdr_req.record_handle, + pdr_req.data_transfer_handle, + pdr_req.transfer_op_flag, + pdr_req.request_count, + pdr_req.record_change_number, + (struct pldm_msg *)request_msg, + PLDM_GET_PDR_REQ_BYTES); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPDRReq Error, rc: %d\n", rc); + pdrs->done = true; + pdrs->rc = OPAL_PARAMETER; + return OPAL_PARAMETER; + } + + /* Queue the first getpdr request */ + rc = pldm_requester_queue(request_msg, sizeof(request_msg), + get_pdr_req_complete, pdrs); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetPDRReq, rc: %d\n", rc); + pdrs->done = true; + pdrs->rc = OPAL_PARAMETER; + } + + return rc; +} + +static int pdrs_init(void) +{ + struct pldm_pdrs pdrs; + int rc; + + /* make a new PDR repository */ + pdrs_repo = pldm_pdr_init(); + + /* collect all PDrs into a PDR Repository */ + pdrs.record_hndl = 0; + rc = encode_and_queue_get_pdr_req(&pdrs); + if (rc) + return rc; + + /* wait for the end of pdrs received */ + do { + time_wait_ms(5); + } while (!pdrs.done); + + return pdrs.rc; +} + +int pldm_platform_init(void) +{ + int rc; + + /* retrieve all PDRs */ + rc = pdrs_init(); + if (rc) { + pdr_init_complete(false); + prlog(PR_ERR, "%s - done, rc: %d\n", __func__, rc); + return rc; + } + + pdr_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; +} + +void pldm_platform_exit(void) +{ + if (pdr_ready) + pldm_pdr_destroy(pdrs_repo); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index fa7a80de..d035655f 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -6,6 +6,7 @@ #define __COREPLDM_H__ #include +#include #include /* Common support */ @@ -28,6 +29,9 @@ void printbuf(const char *name, const char *msg, int len); #define PKT_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) +/* For all of the encode functions just pass in a default ID (0x00) */ +#define DEFAULT_INSTANCE_ID 0 + struct pldm_rx_data { struct pldm_header_info hdrinf; /* parsed message header */ @@ -43,6 +47,12 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +uint8_t pldm_base_get_bmc_tid(void); +int pldm_base_get_tid_req(void); + +int pldm_platform_init(void); +void pldm_platform_exit(void); + int pldm_requester_handle_response(struct pldm_rx_data *rx); int pldm_requester_queue(void *request_msg, size_t request_len, void (*complete)(struct pldm_rx_data *rx, void *data), From patchwork Tue Sep 13 10:26:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677226 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=lVO7TlkA; 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 4MRfnp1ZXmz1ynm for ; Tue, 13 Sep 2022 20:28:46 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfnp1QCSz3c6J for ; Tue, 13 Sep 2022 20:28:46 +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=lVO7TlkA; 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=mx0b-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=lVO7TlkA; 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 4MRfm76dPcz301m for ; Tue, 13 Sep 2022 20:27:19 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAAEoT039926 for ; Tue, 13 Sep 2022 10:27:13 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=dQrUuNAiYGaAnNnTClWfnsW7PxieE7M6pPluvbXUauc=; b=lVO7TlkA4I3E/qnlh5BXDdoKvsZSNyRLeJg+Pi2LwBpr81mxNt4iSAT0llyLoCPoe9qw 2Uympmumlm2C6PI5lH9fM0AV/pN1lpWQySJJyK7//uqLISBhOdXI2ujoXhCCMBNz0tEq bcyFxtv+Qp3D9VUYQttCWoHxq4VP4SCCk0rd1IFxSZuUMqo14+b9Oc+V9Gsuk+YQSoU1 YRsemXNCjz3i1xfxZqW+LABHmPFlu7zzwwrszSiOhYLuNCRwvJ02iDt2CA2pbMkLVPWX vHsS/2YWkGBSePfjU6k2viRF7e/xRC6MY47yZQEcRkhIGm3kV6PVb9U+DlhKKArb9UjN DQ== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqvh8ec0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DALArh001496 for ; Tue, 13 Sep 2022 10:27:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma05fra.de.ibm.com with ESMTP id 3jgj78tpsr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR98X11076074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 11E93A404D for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE9F4A4040 for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:55 +0200 Message-Id: <20220913102705.65506-12-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yFwBG0dmUaxehMPIwYSQ2PSMYdk2mM0x X-Proofpoint-ORIG-GUID: yFwBG0dmUaxehMPIwYSQ2PSMYdk2mM0x X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 11/21] core/pldm: Encode state effecter 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" PLDM effecters provide a general mechanism for controlling or configuring a state or numeric setting of an entity. The entity state and numeric setting values are written into an effecter. PLDM commands are specified for writing the state or numeric setting to an effecter. Effecters are identified by and accessed using an EffecterID that is unique for each effecter within a given terminus. PLDM State Effecters provide a regular command structure for setting state information in order to change the state of an entity. The SetStateEffecterStates command is used to set the state of one or more effecters within a PLDM State Effecter. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-platform-requests.c | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 965820c8..93b98438 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -39,6 +39,82 @@ static void pdr_init_complete(bool success) pdr_ready = true; } +struct set_effecter_state_response { + uint8_t completion_code; +}; + +/* + * Create and send a PLDM request message for SetStateEffecterStates. + */ +static int set_state_effecter_states_req(uint16_t effecter_id, + set_effecter_state_field *field, + bool no_timeout) +{ + char request_msg[PKT_SIZE(struct pldm_set_state_effecter_states_req)]; + size_t response_len, payload_len; + void *response_msg; + int rc; + + struct pldm_set_state_effecter_states_req states_req = { + .effecter_id = effecter_id, + .comp_effecter_count = 1 + }; + + struct set_effecter_state_response response; + + /* Encode the state effecter states request */ + rc = encode_set_state_effecter_states_req( + DEFAULT_INSTANCE_ID, + states_req.effecter_id, + states_req.comp_effecter_count, + field, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n", + rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes. + * It may happen that for some commands, the responder does not + * have time to respond. + */ + if (no_timeout) { + rc = pldm_mctp_message_tx(BMC_EID, request_msg, sizeof(request_msg)); + if (rc) + prlog(PR_ERR, "Failed to send SetStateEffecter request, rc = %d\n", rc); + + return rc; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: SetStateEffecter, rc: %d\n", rc); + free(response_msg); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + + rc = decode_set_state_effecter_states_resp( + response_msg, + payload_len, + &response.completion_code); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode SetStateEffecter Error, rc: %d, cc: %d\n", + rc, response.completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + struct get_pdr_response { uint8_t completion_code; uint32_t next_record_hndl; From patchwork Tue Sep 13 10:26:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677218 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=lZQo2KhV; 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 4MRfmh6vRpz1ynm for ; Tue, 13 Sep 2022 20:27:48 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmh6PBGz3bsy for ; Tue, 13 Sep 2022 20:27: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=lZQo2KhV; 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.156.1; 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=lZQo2KhV; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 4MRfm415xLz30M2 for ; Tue, 13 Sep 2022 20:27:15 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA7N1w008362 for ; Tue, 13 Sep 2022 10:27:14 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=FOLHRkVqpOt/6qpebwuebhLmJEciXFjS1mOxPRyM7+I=; b=lZQo2KhV8UnCesAOIhHIJITjEae03zurNzdQP+1HZTaAYWFRYV5Aj3QRfyteUDsx5YC4 e6AqrjbZY82POxkxCpRDjmSDWZvrvvzhbPfI+aGjXJDm7zwbYP8w8n1lOzHpJa6ZEB+I 75plVaBI5Ji6XZCuLCJzFW9SpIV6CXiRFPFETulR//toxQutF7omD+7jlowaaLxd2V8M 8CCx9E1bSomYOdJTsGEdonr3MQ1KxBGav9HQc9LUMZA37k715gNvvt1slUhhu3LuuM2C 0g8sNoFEJfqIFy9KsB7tAJAoiZfLqnHyuCiTkQpx+WGGJiEvv2W6dXzAVTd19A/UmEq7 4g== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqn90u21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKXVn003200 for ; Tue, 13 Sep 2022 10:27:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umxu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR91611076078 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E373A404D for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 25A1AA4040 for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:56 +0200 Message-Id: <20220913102705.65506-13-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Zpho2TmCxv4zJm5jbFkI2exj4KM_c2FH X-Proofpoint-GUID: Zpho2TmCxv4zJm5jbFkI2exj4KM_c2FH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 12/21] core/pldm: Send a system firmware Graceful Restart 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" Set the state information of the PLDM effecter identified by: the entity type (PLDM_ENTITY_SYS_FIRMWARE) and the state set PLDM_STATE_SET_SW_TERMINATION_STATUS with the effecter state: PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED to request a platform restart. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-platform-requests.c | 75 ++++++++++++++++++++++++++++++ include/pldm.h | 5 ++ 2 files changed, 80 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 93b98438..99d58158 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -39,6 +39,49 @@ static void pdr_init_complete(bool success) pdr_ready = true; } +/* + * Search the matching record and return the effecter id. + * PDR type = PLDM_STATE_EFFECTER_PDR + */ +static int find_effecter_id_by_state_set_Id(uint16_t entity_type, + uint16_t state_set_id, + uint16_t *effecter_id) +{ + struct state_effecter_possible_states *possible_states; + struct pldm_state_effecter_pdr *state_effecter_pdr; + const pldm_pdr_record *record = NULL; + uint8_t *outData = NULL; + uint32_t size; + + do { + /* Find (first) PDR record by PLDM_STATE_EFFECTER_PDR type + * if record not NULL, then search will begin from this + * record's next record + */ + record = pldm_pdr_find_record_by_type( + pdrs_repo, /* PDR repo handle */ + PLDM_STATE_EFFECTER_PDR, + record, /* PDR record handle */ + &outData, &size); + + if (record) { + state_effecter_pdr = (struct pldm_state_effecter_pdr *) outData; + + *effecter_id = le16_to_cpu(state_effecter_pdr->effecter_id); + + possible_states = (struct state_effecter_possible_states *) + state_effecter_pdr->possible_states; + + if ((le16_to_cpu(state_effecter_pdr->entity_type) == entity_type) && + (le16_to_cpu(possible_states->state_set_id) == state_set_id)) + return OPAL_SUCCESS; + } + + } while (record); + + return OPAL_PARAMETER; +} + struct set_effecter_state_response { uint8_t completion_code; }; @@ -115,6 +158,38 @@ static int set_state_effecter_states_req(uint16_t effecter_id, return OPAL_SUCCESS; } +/* + * entity_type: System Firmware + * state_set: Software Termination Status(129) + * states: Graceful Restart Requested(6) + */ +int pldm_platform_restart(void) +{ + set_effecter_state_field field; + uint16_t effecter_id; + int rc; + + if (!pdr_ready) + return OPAL_HARDWARE; + + rc = find_effecter_id_by_state_set_Id( + PLDM_ENTITY_SYS_FIRMWARE, + PLDM_STATE_SET_SW_TERMINATION_STATUS, + &effecter_id); + if (rc) { + prlog(PR_ERR, "%s - effecter id not found\n", __func__); + return rc; + } + + field.set_request = PLDM_REQUEST_SET; + field.effecter_state = PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED; + + prlog(PR_INFO, "sending system firmware Graceful Restart request (effecter_id: %d)\n", + effecter_id); + + return set_state_effecter_states_req(effecter_id, &field, true); +} + struct get_pdr_response { uint8_t completion_code; uint32_t next_record_hndl; diff --git a/include/pldm.h b/include/pldm.h index 3aae560c..2429b5e5 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -15,4 +15,9 @@ int pldm_mctp_init(uint8_t mode); */ void pldm_mctp_exit(void); +/** + * Send a system firmware Graceful Restart request + */ +int pldm_platform_restart(void); + #endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677228 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=k/c3gCaC; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfp45Ts5z1ypR for ; Tue, 13 Sep 2022 20:29:00 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfp45CHVz3c4w for ; Tue, 13 Sep 2022 20:29:00 +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=k/c3gCaC; 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=k/c3gCaC; 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 4MRfmC2FmJz3byL for ; Tue, 13 Sep 2022 20:27:23 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DABfip027403 for ; Tue, 13 Sep 2022 10:27:13 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=5FyBs8Ye+x0ZLqsAH9/GMb6rxsIYMFxzei8ca/e2kKc=; b=k/c3gCaCPQ7DXvfcb7uAIQ+jbn2qW0aibWyLqot7QzPwobSooJFrR1E4q1c1J3lIOMnN BNmSHBLNceKpMNuXG8Mq8C8gWWtTYS7XfbMowbLjgSGv7JrC6Ld5AeVXyd7llUnLR/cE +fOGF0sRy4JXNlfXux9zAhApkgj0oiCA0uMofoEgRsVu+ZRXmhbQWxJnlihy8S+gkE/f ISjfU9KU3P+5O2S+Ckyd5oAXao8cdeJXyR/aGm2onROWGipDK3k9s6140lq28RmrsKrL J5qCnlry+F+/iher0c90W+TNP7n1ZOUkMPoWy2IAOvbZqYALGp6dBRQdzfVmUf0f035X 8A== Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvn4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAK3n3016100 for ; Tue, 13 Sep 2022 10:27:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma02fra.de.ibm.com with ESMTP id 3jgj792pcb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR93611076080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88EE1A404D for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 61596A4040 for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:57 +0200 Message-Id: <20220913102705.65506-14-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: RJf2BxrGsEvwjbVHbRa-7GOg26BPOjUS X-Proofpoint-ORIG-GUID: RJf2BxrGsEvwjbVHbRa-7GOg26BPOjUS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 13/21] core/pldm: Send a system chassis Off-Soft Graceful 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" Set the state information of the PLDM effecter identified by: the entity type (PLDM_ENTITY_SYSTEM_CHASSIS) and the state set PLDM_STATE_SET_SYSTEM_POWER_STATE with the effecter state: PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL to request a platform off. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-platform-requests.c | 32 ++++++++++++++++++++++++++++++ include/pldm.h | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 99d58158..ca66157c 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -158,6 +158,38 @@ static int set_state_effecter_states_req(uint16_t effecter_id, return OPAL_SUCCESS; } +/* + * entity_type: System chassis (main enclosure) + * state_set: System Power State (260) + * states: Off-Soft Graceful(9) + */ +int pldm_platform_power_off(void) +{ + set_effecter_state_field field; + uint16_t effecter_id; + int rc; + + if (!pdr_ready) + return OPAL_HARDWARE; + + rc = find_effecter_id_by_state_set_Id( + PLDM_ENTITY_SYSTEM_CHASSIS, + PLDM_STATE_SET_SYSTEM_POWER_STATE, + &effecter_id); + if (rc) { + prlog(PR_ERR, "%s - effecter id not found\n", __func__); + return rc; + } + + field.set_request = PLDM_REQUEST_SET; + field.effecter_state = PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL; + + prlog(PR_INFO, "sending system chassis Off-Soft Graceful request (effecter_id: %d)\n", + effecter_id); + + return set_state_effecter_states_req(effecter_id, &field, true); +} + /* * entity_type: System Firmware * state_set: Software Termination Status(129) diff --git a/include/pldm.h b/include/pldm.h index 2429b5e5..3e653aa3 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -15,6 +15,11 @@ int pldm_mctp_init(uint8_t mode); */ void pldm_mctp_exit(void); +/** + * Send a system chassis Off-Soft Graceful request + */ +int pldm_platform_power_off(void); + /** * Send a system firmware Graceful Restart request */ From patchwork Tue Sep 13 10:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677219 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=112.213.38.117; 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=dMgcarVd; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfmr100Fz1ynm for ; Tue, 13 Sep 2022 20:27:56 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmr05S2z30Qc for ; Tue, 13 Sep 2022 20:27:56 +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=dMgcarVd; 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.156.1; 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=dMgcarVd; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 4MRfm424b1z30Mr for ; Tue, 13 Sep 2022 20:27:16 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPGDv001237 for ; Tue, 13 Sep 2022 10:27:14 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=c6fkyo4rHhmMy33EA7HTtQSuSFH8na1hZgt/f8pozbQ=; b=dMgcarVdasHcq+j5mQCfPTPH4iQysJ8slWHUrLxgkaKGCwpt4/PoGwdPdf/K3V6tZVHj wlCzOU6PrfsyrUidTr4fFlHXXKxj7T8ukX7hE7mqTVkaLsdy+62s4i/daHvfPILQUTIp wabDrQbP751O2MVvyZDUUCMaFtftN1KQPv8TUtdEmTe0fhp0XlUs4jGQBwZSwKspbe8v Sp0HV6gPjDYm0i6S2bikI33Ln7DW8TRYJIF/tCQYj17vV/N9qPRwX3bZsMu7WQI/eM13 3aEdp4k13uAe5oefEQcjQzbUrYFNSCIULTwdnEfRVUbaOWVPJ/Syl1YYK0HF5mY3lByB PA== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjr3j817e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:14 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKW2I003193 for ; Tue, 13 Sep 2022 10:27:12 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR9vC11076084 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C49D0A404D for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9BB26A4040 for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:58 +0200 Message-Id: <20220913102705.65506-15-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: XU-44q1RqcYXytt1o06SXE31Zw9d9lxg X-Proofpoint-ORIG-GUID: XU-44q1RqcYXytt1o06SXE31Zw9d9lxg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 14/21] core/pldm: PLDM for BIOS Control and Configuration Specification 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" This specification defines the data structures and messages for communicating BIOS settings, BIOS attributes, boot configurations, and boot order settings. Use the GetBIOSTable command to get STRING, Attribute and Attribute values tables from the BIOS. The content of these tables is useful to read/write the lid files located on the BMC. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 + core/pldm/pldm-bios-requests.c | 210 +++++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 9 +- core/pldm/pldm.h | 2 + 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-bios-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 04c4c51b..42645427 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -8,9 +8,11 @@ CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes +CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes 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 = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-bios-requests.c b/core/pldm/pldm-bios-requests.c new file mode 100644 index 00000000..05c3c8db --- /dev/null +++ b/core/pldm/pldm-bios-requests.c @@ -0,0 +1,210 @@ +// 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 +#include "pldm.h" + +/* + * PLDM_BIOS_STRING_TABLE = 0 + * pldmtool bios GetBIOSTable -t 0 + * pldmtool: Tx: 08 01 80 03 01 00 00 00 00 01 00 + * ... + * "60": "hb_lid_ids", + * ... + */ +static void *bios_string_table; +static size_t bios_string_length; + +/* + * PLDM_BIOS_ATTR_TABLE = 1 + * pldmtool bios GetBIOSTable -t 1 + * pldmtool: Tx: 08 01 80 03 01 00 00 00 00 01 01 + * + * { + * "AttributeHandle": 8, + * "AttributeNameHandle": "60(hb_lid_ids)", + * "AttributeType": "BIOSString", + * "StringType": "0x01", + * "MinimumStringLength": 0, + * "MaximumStringLength": 1024, + * "DefaultStringLength": 0, + * "DefaultString": "" + * }, + */ +static void *bios_attr_table; +static size_t bios_attr_length; + +/* + * PLDM_BIOS_ATTR_VAL_TABLE = 2 + * pldmtool bios GetBIOSTable -t 2 + * pldmtool: Tx: 08 01 80 03 01 00 00 00 00 01 02 + * + * { + * "AttributeHandle": 8, + * "AttributeType": "BIOSString", + * "CurrentStringLength": 616, + * "CurrentString": "ATTR_PERM=81e00663,ATTR_TMP=81e00664, ... + * NVRAM=81e0066b,...,pnor.toc=NA" + * }, ... + */ +static void *bios_val_table; +static size_t bios_val_length; + +static bool bios_ready; + +static void bios_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + bios_ready = false; + + if (bios_string_table != NULL) { + free(bios_string_table); + bios_string_length = 0; + } + if (bios_attr_table != NULL) { + free(bios_attr_table); + bios_attr_length = 0; + } + if (bios_val_table != NULL) { + free(bios_val_table); + bios_val_length = 0; + } + return; + } + + /* Mark ready */ + bios_ready = true; +} + +/* + * Send/receive a PLDM GetBIOSTable request message + */ +static int get_bios_table_req(enum pldm_bios_table_types table_type, + void **bios_table, size_t *bios_length) +{ + char request_msg[PKT_SIZE(struct pldm_get_bios_table_req)]; + size_t response_len, payload_len, bios_table_offset; + uint8_t completion_code, transfer_flag; + uint32_t next_transfer_handle; + void *response_msg; + int rc; + + struct pldm_get_bios_table_req bios_table_req = { + .transfer_handle = 0, /* (0 if transfer op is FIRSTPART) */ + .transfer_op_flag = PLDM_GET_FIRSTPART, + .table_type = table_type + }; + + prlog(PR_DEBUG, "%s - table type: %d\n", __func__, table_type); + + /* Encode the bios table request */ + rc = encode_get_bios_table_req( + DEFAULT_INSTANCE_ID, + bios_table_req.transfer_handle, + bios_table_req.transfer_op_flag, + bios_table_req.table_type, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetBIOSTableReq Error, type: %d, rc: %d\n", + table_type, rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetBIOSTableReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_bios_table_resp( + response_msg, + payload_len, + &completion_code, + &next_transfer_handle, + &transfer_flag, + &bios_table_offset); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetBIOSTableResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(response_msg); + 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 GetBIOSTable not complete " + "transfer_hndl: %d, transfer_flag: %d\n", + next_transfer_handle, + transfer_flag); + } + + *bios_length = payload_len - + sizeof(next_transfer_handle) - + sizeof(transfer_flag) - + sizeof(completion_code); + *bios_table = zalloc(*bios_length); + memcpy(*bios_table, + ((struct pldm_msg *)response_msg)->payload + bios_table_offset, + *bios_length); + + free(response_msg); + + return OPAL_SUCCESS; +} + +int pldm_bios_init(void) +{ + int rc; + + /* BIOS String Table is a BIOS table that contains all the BIOS + * strings including attribute names, and pre-configured strings + * used in representing the values of the attributes. + * Each string in the BIOS String Table has an associated unique + * handle. + */ + rc = get_bios_table_req(PLDM_BIOS_STRING_TABLE, + &bios_string_table, &bios_string_length); + if (rc) + goto err; + + /* BIOS Attribute Table is a BIOS table that contains attribute + * name handles, attribute types, type-specific metadata, + * type-specific possible values (if any), and default values. + */ + rc = get_bios_table_req(PLDM_BIOS_ATTR_TABLE, + &bios_attr_table, &bios_attr_length); + if (rc) + goto err; + + /* BIOS Attribute Value Table is a BIOS table that contains all + * the current values of the BIOS attributes and settings. + * Each entry in this table contains the attribute handle, the + * attribute type, and current values. + */ + rc = get_bios_table_req(PLDM_BIOS_ATTR_VAL_TABLE, + &bios_val_table, &bios_val_length); + if (rc) + goto err; + + bios_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + bios_init_complete(false); + return rc; +} diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index a351a340..ff4f71c3 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -141,8 +141,15 @@ int pldm_mctp_init(uint8_t mode) /* Get PDRs data */ rc = pldm_platform_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Data Records\n"); + goto out; + } + + /* Get Bios data */ + rc = pldm_bios_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Bios data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index d035655f..3cad2275 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_bios_init(void); + uint8_t pldm_base_get_bmc_tid(void); int pldm_base_get_tid_req(void); From patchwork Tue Sep 13 10:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677221 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=YKDDFRT0; 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 4MRfn641Tqz1ynm for ; Tue, 13 Sep 2022 20:28:10 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfn63VQDz3c45 for ; Tue, 13 Sep 2022 20:28:10 +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=YKDDFRT0; 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=mx0b-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=YKDDFRT0; 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 4MRfm44WJfz30M2 for ; Tue, 13 Sep 2022 20:27:16 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9LlYm011482 for ; Tue, 13 Sep 2022 10:27:14 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=6qu8LckVxAmSBShncjpHHTFxgdC1lPJ/T8WHuv+u6d4=; b=YKDDFRT0ekfwlru05+qHFHPZaR9fUgnll+DlwQQmOywBsidMupBc6mQroPpkF1EUmlQp 4H/f91uWw5pamaQw8s153qXGfMwfT8FwUB0ceS1V0/Jy2X335YQxuhllp8qNd/ci4Mze HUC4SjfvLfFgQ7Mq5+K2tMYWm4L/A2Gtth7+d4zE7dH+EmjgzYA5Cvccc9KuZSILr3xZ JywH7yJgVjOBnvZGEMeg/9tQ9tyB6cP3koApjsfW3LJFGW/PvWDa3qqFhojoNQ2v382l XsHhjvbkiDmWnRuHApVvFBUmHPc1O+1PjMLvF13+UvsSrWzVbLKrSjmFMySytl5eeZXW IQ== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq5rhxex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:14 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKfKH006785 for ; Tue, 13 Sep 2022 10:27:12 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3jgj79kncj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANQ5m19726780 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:26 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C0DBA4055 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D8666A4040 for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:59 +0200 Message-Id: <20220913102705.65506-16-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: uj1TboYoSSegcpX5y8RprhuR9tNEF8uy X-Proofpoint-ORIG-GUID: uj1TboYoSSegcpX5y8RprhuR9tNEF8uy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 15/21] core/pldm: Find lid attribute from bios tables 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" This specification defines the data structures and messages for communicating BIOS settings, BIOS attributes, boot configurations, and boot order settings. Use the GetBIOSTable command to get STRING, Attribute and Attribute values tables from the BIOS. The contents of these tables are needed to read/write the desired lid files located on the BMC. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-bios-requests.c | 149 +++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 151 insertions(+) diff --git a/core/pldm/pldm-bios-requests.c b/core/pldm/pldm-bios-requests.c index 05c3c8db..de03776a 100644 --- a/core/pldm/pldm-bios-requests.c +++ b/core/pldm/pldm-bios-requests.c @@ -84,6 +84,155 @@ static void bios_init_complete(bool success) bios_ready = true; } +/* + * parse a string, format: + * =,= + */ +static int find_lid_by_attr_name(char *str, const char *name, + char **lid) +{ + const char *pp = "="; + char *attr, *attr_end; + char *p; + + for (p = strtok(str, ","); p != NULL; p = strtok(NULL, ",")) { + /* parse now the following string = */ + attr = p; + while (*pp != *p) + p++; + + attr_end = p; + *attr_end = '\0'; + + if (!strncmp(attr, name, strlen(name)) && + (strlen(attr) == strlen(name))) { + *lid = strdup(++p); + p += strlen(name) + 1; + return OPAL_SUCCESS; + } + } + prlog(PR_ERR, "%s - lid not found, attr name: %s\n", + __func__, name); + + return OPAL_PARAMETER; +} + +/* + * Retrieve attribut value from string. + * + * Ex: string value = "hb_lid_ids" + * From STRING table (with string value = "hb_lid_ids") -> string_handle = 60 + * From ATTR table (with attr name handle = 60) -> attr handle = 8 + * From ATTR VAL table (with attr handle = 8) + * -> CurrentString = ATTR_PERM=81e00663,ATTR_TMP=81e00664, ... + * NVRAM=81e0066b,...,pnor.toc=NA" + */ +static int find_bios_table_attr_values_by_string(const char *str, + char **current_string) +{ + const struct pldm_bios_string_table_entry *string_entry; + const struct pldm_bios_attr_table_entry *attr_entry; + const struct pldm_bios_attr_val_table_entry *val_entry; + uint16_t string_handle, attr_handle; + struct variable_field currentString; + + if ((!bios_string_table) || (!bios_attr_table)) + return OPAL_PARAMETER; + + /* decode string table */ + string_entry = pldm_bios_table_string_find_by_string( + bios_string_table, bios_string_length, str); + if (!string_entry) { + prlog(PR_ERR, "String table entry not found, str: %s\n", + str); + return OPAL_PARAMETER; + } + + /* get the string handle for the entry */ + string_handle = pldm_bios_table_string_entry_decode_handle(string_entry); + prlog(PR_TRACE, "%s - string_handle: %d\n", __func__, string_handle); + + /* decode attribute table */ + attr_entry = pldm_bios_table_attr_find_by_string_handle( + bios_attr_table, bios_attr_length, string_handle); + if (!attr_entry) { + prlog(PR_ERR, "Attribute table entry not found, string_handle: %d\n", + string_handle); + return OPAL_PARAMETER; + } + + /* get the attribute handle from the attribute table entry */ + attr_handle = pldm_bios_table_attr_entry_decode_attribute_handle(attr_entry); + prlog(PR_TRACE, "%s - attr_handle: %d\n", __func__, attr_handle); + + /* decode attribute value table */ + val_entry = pldm_bios_table_attr_value_find_by_handle( + bios_val_table, bios_val_length, attr_handle); + + if (!val_entry) { + prlog(PR_ERR, "Attribute val table entry not found, attr_handle: %d\n", + attr_handle); + return OPAL_PARAMETER; + } + + /* get Current String Itself */ + pldm_bios_table_attr_value_entry_string_decode_string( + val_entry, + ¤tString); + *current_string = strdup(currentString.ptr); + + return OPAL_SUCCESS; +} + +#define HB_LID_IDS "hb_lid_ids" + +/* + * Find lid attribute from bios tables + */ +int pldm_bios_find_lid_by_attr_name(const char *name, char **lid) +{ + char *hb_lid_ids_string = NULL; + int rc = OPAL_SUCCESS; + + if (!bios_ready) + return OPAL_HARDWARE; + + /* find current attribut string */ + rc = find_bios_table_attr_values_by_string(HB_LID_IDS, &hb_lid_ids_string); + if (rc) + goto err; + + /* find lid attribut from current string */ + rc = find_lid_by_attr_name(hb_lid_ids_string, name, lid); + if (rc) + goto err; + + free(hb_lid_ids_string); + + prlog(PR_DEBUG, "%s - lid: %s, attr name: %s\n", + __func__, *lid, name); + + return OPAL_SUCCESS; + +err: + if (hb_lid_ids_string) + free(hb_lid_ids_string); + + return rc; +} + +/* + * Get lid ids string from bios tables + */ +int pldm_bios_get_lids_id(char **lid_ids_string) +{ + if (!bios_ready) + return OPAL_HARDWARE; + + /* find current attribut string */ + return find_bios_table_attr_values_by_string(HB_LID_IDS, lid_ids_string); +} + /* * Send/receive a PLDM GetBIOSTable request message */ diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 3cad2275..db2f9dcd 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +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); uint8_t pldm_base_get_bmc_tid(void); From patchwork Tue Sep 13 10:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677249 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=tOQTBAXm; 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 4MRfrv1lCJz1ync for ; Tue, 13 Sep 2022 20:31:27 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrv0zsJz3dps for ; Tue, 13 Sep 2022 20:31:27 +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=tOQTBAXm; 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=tOQTBAXm; 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 4MRfmR2Nw7z3c6C for ; Tue, 13 Sep 2022 20:27:34 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DALgO5027308 for ; Tue, 13 Sep 2022 10:27:14 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=fcj6S0hH9Z+4l32zobhl4zw6NAnRejF2WoycH+Rqccg=; b=tOQTBAXmJg+uMJTD6tculS97XQJFavbkxNslvcj7ZZsEyoTEwK7H8b+kryTFCmr7lPwz HmqF4NZnbF1NZJKeE0chh+h9Ce1Y1unAy4e/R4w/1pGk/YzVjMgejrn0Egymkb7qMyfe hGOY/pLO2QZrzunF4yxq6sPqzna/rG8sUVPttn0viZkgvHlQaqGY6101/ZcgmOik5wFy dHs37Zw1ttKIQnK3U0zOlQTzTSzBschzqmexrsrKN8UMSJq62Nl4PRzvdj2wm0gGq1D4 zvGRCtJF/A5nCmYFMoVbfN766t5TUDdrayk2VVsSkPyXyJ3dCqkAh44LznPNE/hpgZ2O og== Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvnf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:14 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKcUH016206 for ; Tue, 13 Sep 2022 10:27:12 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma02fra.de.ibm.com with ESMTP id 3jgj792pcd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANQ0v15925730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 495B6A404D for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2182DA4040 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:00 +0200 Message-Id: <20220913102705.65506-17-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Lqiorj8-I-dF_7CQu1d0vYIE5xzrZq0X X-Proofpoint-ORIG-GUID: Lqiorj8-I-dF_7CQu1d0vYIE5xzrZq0X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 16/21] core/pldm: PLDM for FRU data Specification 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" Specification, defines a FRU data format that provides platform asset information including part number, serial number and manufacturer. Use the GetFruRecordByOptionReq command to get specific FRU (Field Replaceable Unit) record according the Record Set Identifier, the Record Type and the field Type. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-fru-requests.c | 136 ++++++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 9 ++- core/pldm/pldm.h | 2 + 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-fru-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 42645427..4d08e371 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-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_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c new file mode 100644 index 00000000..02c9b968 --- /dev/null +++ b/core/pldm/pldm-fru-requests.c @@ -0,0 +1,136 @@ +// 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 +#include "pldm.h" + +static void *fru_record_table; +static size_t fru_record_length; + +static bool fru_ready; + +static void fru_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + fru_ready = false; + + if (fru_record_table != NULL) { + free(fru_record_table); + fru_record_length = 0; + } + return; + } + + /* Mark ready */ + fru_ready = true; +} + +static int get_fru_record_table_req(void **record_table_data, + size_t *record_table_length) +{ + char request_msg[PKT_SIZE(struct pldm_get_fru_record_table_req)]; + uint8_t transfer_flag, completion_code; + size_t response_len, payload_len; + uint32_t next_transfer_handle; + uint8_t *table_data; + size_t table_length; + void *response_msg; + int rc; + + struct pldm_get_fru_record_table_req fru_record_table_req = { + .data_transfer_handle = 0, /* (0 if operation op is FIRSTPART) */ + .transfer_operation_flag = PLDM_GET_FIRSTPART, + }; + payload_len = sizeof(struct pldm_get_fru_record_table_req); + + /* Encode the file table request */ + rc = encode_get_fru_record_table_req( + DEFAULT_INSTANCE_ID, + fru_record_table_req.data_transfer_handle, + fru_record_table_req.transfer_operation_flag, + (struct pldm_msg *)request_msg, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordTableReq Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFruRecordTableReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + table_data = zalloc(payload_len); + + rc = decode_get_fru_record_table_resp( + response_msg, + payload_len, + &completion_code, + &next_transfer_handle, + &transfer_flag, + table_data, + &table_length); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetFruRecordTableReq Error, rc: %d, cc: %d\n", + rc, completion_code); + + free(table_data); + free(response_msg); + 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 GetFruRecordTableReq not complete, " + "transfer_hndl: %d, transfer_flag: %d\n", + next_transfer_handle, + transfer_flag); + + free(table_data); + free(response_msg); + return OPAL_PARAMETER; + } + + *record_table_length = table_length; + *record_table_data = zalloc(table_length); + memcpy(*record_table_data, table_data, table_length); + + free(table_data); + free(response_msg); + + return OPAL_SUCCESS; +} + +int pldm_fru_init(void) +{ + int rc; + + /* get fru record table */ + rc = get_fru_record_table_req(&fru_record_table, + &fru_record_length); + if (rc) + goto err; + + fru_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + fru_init_complete(false); + return rc; +} diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index ff4f71c3..542edc27 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -148,8 +148,15 @@ int pldm_mctp_init(uint8_t mode) /* Get Bios data */ rc = pldm_bios_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Bios data\n"); + goto out; + } + + /* Get Fru data */ + rc = pldm_fru_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Fru data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index db2f9dcd..f9e9db40 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_fru_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); From patchwork Tue Sep 13 10:27:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677225 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=112.213.38.117; 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=Y2Vijw4a; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4MRfng0rzXz1ynm for ; Tue, 13 Sep 2022 20:28:39 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfng0LmRz3c7H for ; Tue, 13 Sep 2022 20:28:39 +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=Y2Vijw4a; 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=Y2Vijw4a; 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 4MRfm63XxNz3bVB for ; Tue, 13 Sep 2022 20:27:18 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAL0SU027390 for ; Tue, 13 Sep 2022 10:27:15 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=1KdttKxpwPA5t+6J0RlvOYYHefgozOtFTDkK7eH+FaU=; b=Y2Vijw4aV0Bv/rE8Twaoub3jCiWyjSse42UU4//IMKRMk5Z8J2iVDYrKR/06V5BTeEh9 V6XlTkTG6voAXpA5RZBA+8Z4Ae9FKBdk9ljYihqF1J5QAU+Y7XMcVUql53C5Xgyysw1d NEGDjeI/Z1Nd+jZW0+OrWo7HDLv+UeYXC0xu0l8wh3/E4J2h5VB1W5tcv7yAYPGl86YD n973fUemduLIZcv8Kw30DJTtgktcevZWWHLneqlNkwBv4/cQ6NaNtjAGGxS4jyXQyuw4 X3+L1QjburkAmqYSnud0jK7XmuqWB0DxEczfyKM0+KZ2bQl4C+7Tb8ZmALlVLcyxtC8Z 5A== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:14 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKdB3003213 for ; Tue, 13 Sep 2022 10:27:13 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANRBc15925734 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 842A4A4051 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5CB0FA4040 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:01 +0200 Message-Id: <20220913102705.65506-18-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: CzgWneGeVwvWXI5xSEoYngI-GDB4G5mY X-Proofpoint-ORIG-GUID: CzgWneGeVwvWXI5xSEoYngI-GDB4G5mY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 17/21] core/pldm: Update "bmc-firmware-version" device-tree field 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" Use the GetFruRecordByOptionReq command to retrieve the bmc information with: "FRU Field Type": Version "FRU Record Set Identifier": 1, "FRU Record Type": "General(1)" and update the "bmc-firmware-version" device-tree field. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-fru-requests.c | 60 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 1 + include/pldm.h | 5 +++ 3 files changed, 66 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index 02c9b968..b07a7b1a 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -15,6 +15,7 @@ static void *fru_record_table; static size_t fru_record_length; static bool fru_ready; +static char *bmc_version = NULL; static void fru_init_complete(bool success) { @@ -33,6 +34,16 @@ static void fru_init_complete(bool success) fru_ready = true; } +int pldm_fru_get_bmc_version(void *bv) +{ + if (bmc_version == NULL) + return OPAL_HARDWARE; + + memcpy(bv, bmc_version, strlen(bmc_version) + 1); + + return OPAL_SUCCESS; +} + static int get_fru_record_table_req(void **record_table_data, size_t *record_table_length) { @@ -115,6 +126,55 @@ static int get_fru_record_table_req(void **record_table_data, return OPAL_SUCCESS; } +int pldm_fru_dt_add_bmc_version(void) +{ + struct pldm_fru_record_data_format *data; + struct pldm_fru_record_tlv *tlv; + struct dt_node *dt_fw_version; + uint8_t *record_table; + size_t record_size; + + dt_fw_version = dt_find_by_name(dt_root, "ibm,firmware-versions"); + if (!dt_fw_version) + return OPAL_SUCCESS; + + /* retrieve the bmc information with + * "FRU Record Set Identifier": 1, + * "FRU Record Type": "General(1)" + * "FRU Field Type": Version + * + * we can not know size of the record table got by options + * in advance, but it must be less than the source table. So + * it's safe to use sizeof the source table. + */ + record_table = zalloc(fru_record_length); + record_size = fru_record_length; + get_fru_record_by_option( + fru_record_table, + fru_record_length - PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES, + record_table, + &record_size, + 1, + PLDM_FRU_RECORD_TYPE_GENERAL, + PLDM_FRU_FIELD_TYPE_VERSION); + + /* get tlv value */ + data = (struct pldm_fru_record_data_format *)record_table; + tlv = (struct pldm_fru_record_tlv *)data->tlvs; + prlog(PR_DEBUG, "%s - value: %s\n", __func__, tlv->value); + + dt_add_property_string(dt_fw_version, "bmc-firmware-version", + tlv->value); + + /* store the bmc version */ + bmc_version = zalloc(tlv->length + 1); + memcpy(bmc_version, tlv->value, tlv->length); + + free(record_table); + + return OPAL_SUCCESS; +} + int pldm_fru_init(void) { int rc; diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index f9e9db40..5ee53cb9 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,7 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_fru_get_bmc_version(void *bv); int pldm_fru_init(void); int pldm_bios_find_lid_by_attr_name(const char *name, char **lid); diff --git a/include/pldm.h b/include/pldm.h index 3e653aa3..693c1ae5 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -25,4 +25,9 @@ int pldm_platform_power_off(void); */ int pldm_platform_restart(void); +/** + * Update the firmware version device-tree field + */ +int pldm_fru_dt_add_bmc_version(void); + #endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:27:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677222 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=112.213.38.117; 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=Ml0Zbsxx; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4MRfnF3PQtz1ynm for ; Tue, 13 Sep 2022 20:28:17 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfnF2qQrz3c5v for ; Tue, 13 Sep 2022 20:28:17 +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=Ml0Zbsxx; 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=mx0b-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=Ml0Zbsxx; 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 4MRfm52JTSz30M2 for ; Tue, 13 Sep 2022 20:27:17 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9p6Le002793 for ; Tue, 13 Sep 2022 10:27:15 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=DygSqnRE/6zcByPrfpNgri2vVzfwUYCok29y25XMfaY=; b=Ml0ZbsxxiLLnUENrYVD8j97Iss26vpMnjjRgxC2dP35GvRrVwUPKGeH22IY+JMJTavhv ZaPM9LmtL4/Gm7/PtKmptMB5ywU1U0ESjFb8Zr+JBLzbNuDy/Bc3qa3aAlCGHe4z1uvh gzlZ+yx/UFR8OGc27AVCCH7emNQqr7rnLHC2pgXobxjuxwgcb6gZ8zzh9XzVgYLmf5vR UYRizRUCdarj86aT8+WB6+P/ZeeYU8++8hfP2LiCZMPbQclAUyqC/YaAHIHJgfpn8KK0 8AFKYmMhpBRYk5d2VHwEzm9KS2OI7ZrefVuxy2HFLrFl+uB3gPhjyE3tqJMuAiLlJ/jm pA== 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 3jjmjay1e1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:14 +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 28DAKRu2005650 for ; Tue, 13 Sep 2022 10:27:13 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnpw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANRjj19726790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2A83A404D for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 978B3A4040 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:02 +0200 Message-Id: <20220913102705.65506-19-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: WZJtsv1CGRvRWUcYGmTzM7UfzfK3ffhy X-Proofpoint-ORIG-GUID: WZJtsv1CGRvRWUcYGmTzM7UfzfK3ffhy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 1 + core/pldm/pldm-file-io-requests.c | 142 ++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 9 +- core/pldm/pldm.h | 2 + 4 files changed, 153 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 4d08e371..4e6833eb 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -13,6 +13,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes 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 00000000..5eb260d6 --- /dev/null +++ b/core/pldm/pldm-file-io-requests.c @@ -0,0 +1,142 @@ +// 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_requester_queue_and_wait(request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFileReq, rc: %d\n", rc); + 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); + free(response_msg); + 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 = zalloc(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-mctp.c b/core/pldm/pldm-mctp.c index 542edc27..1d1d1b37 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -155,8 +155,15 @@ int pldm_mctp_init(uint8_t mode) /* Get Fru data */ rc = pldm_fru_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Fru data\n"); + goto out; + } + + /* Get FILE IO data */ + rc = pldm_file_io_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve File io data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 5ee53cb9..49435fdd 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,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 pldm_fru_init(void); From patchwork Tue Sep 13 10:27:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677223 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=LymhXkbO; 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 4MRfnN5DZTz1ynm for ; Tue, 13 Sep 2022 20:28:24 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfnN3mbRz3c6v for ; Tue, 13 Sep 2022 20:28:24 +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=LymhXkbO; 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.156.1; 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=LymhXkbO; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 4MRfm55T9qz3bSX for ; Tue, 13 Sep 2022 20:27:17 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPGm7001225 for ; Tue, 13 Sep 2022 10:27:16 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=sAsK7CKEyEa5fh4YfRHZu8z8/bBrzg1OEo3GfDzWgDM=; b=LymhXkbOD+aoibOMSHAAnChLEtkcrR086vlPqwH5rEOlLsKSWibSz4UmJDYRCxVUVmBk Zqr8Geu/qBiARkJ5gY8L83i9JPPkncuK87TMpq0Kj9UDOPm3TOkq8iWdJcbWmakq+Jbr lrhokDUKp1D8vg26a5D4TIgs//FXGLqTB7yBWXS/lr7O5LVh45S0Y5iOiuS4FXr9Yf+j GtkUZZlgQ8KAaPxcnuhV6SdkJH7oE4j4bGHJhx3vy33/Msu0McgMoT9jsNXQe67Xcovc p8GOGWrAxjWnfODlmMCinMg/NMjVSlnUE0pRUozb0cMCEsGTr6m1oZHzon5iWgu4fM3x BQ== Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjr3j817s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:15 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKxbe028368 for ; Tue, 13 Sep 2022 10:27:13 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 3jgj78tpsv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANRHN19005740 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 091D4A404D for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5B1DA4040 for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:03 +0200 Message-Id: <20220913102705.65506-20-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jcZoWJqQsm1PyEjiVqCMyHzYiq6lznPZ X-Proofpoint-ORIG-GUID: jcZoWJqQsm1PyEjiVqCMyHzYiq6lznPZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 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. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-file-io-requests.c | 129 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 131 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 5eb260d6..48b00ef2 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,134 @@ 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) +{ + char request_msg[PKT_SIZE(struct pldm_read_file_req)]; + size_t response_len, payload_len, file_data_offset; + uint8_t completion_code; + 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 > file_length)) + return OPAL_PARAMETER; + + if ((offset) && ((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); + + 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 *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode ReadFileReq Error, rc: %d\n", + rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait( + request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: ReadFileReq, rc: %d\n", rc); + 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(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; + + time_wait_ms(20); + } + + 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 49435fdd..2b2a979d 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,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); From patchwork Tue Sep 13 10:27:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677227 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=ck7h2xW5; 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 4MRfnx6Gynz1ynm for ; Tue, 13 Sep 2022 20:28:53 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfnx5m7Wz3bpr for ; Tue, 13 Sep 2022 20:28:53 +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=ck7h2xW5; 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=ck7h2xW5; 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 4MRfmB0gTNz3bnH for ; Tue, 13 Sep 2022 20:27:21 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAL0SV027390 for ; Tue, 13 Sep 2022 10:27:15 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=rWfgDuQ3Ypc/busDeQ2E1bEdP7iOWC5lPHuc8Yee6Eg=; b=ck7h2xW5NG+JD7xeAIlMCigAT/bhSQcMFMMV9sRL6qkZWGhtXFc2kaBCY3WSy1deAP3a zQrpJsaOaSAVbKEmoe3YZ3k2CaDr+FNRbfklUc+5g2KBnRlFJ9Ot7P/eA2isxvBXYear MaVVIeYK9lC7DLd5y8kcyIEcQPYkdw0Q++YuO2JhcTECgUrZdkOVenZ46A+abqCnIOqi imVJ1W7ninaDGu7fZkUwcuykUCTqbokgpNsvaOHj+Iq/9nwBQVQZQ+tJRPu9JjrZp+8Z fCWD8HZGyd5qTk5LVK9s2GGhtqs2lP+eA2B7PN9qvCYN2s10cOaZqQS9Dntz9AHlxttq SA== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:15 +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 28DAKZk3005691 for ; Tue, 13 Sep 2022 10:27:13 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANRCJ19005742 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:27 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4472FA404D for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1CBDAA4040 for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:04 +0200 Message-Id: <20220913102705.65506-21-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: FM8hVzRR5gNo5mVTb1tU6gGvQiujeuph X-Proofpoint-ORIG-GUID: FM8hVzRR5gNo5mVTb1tU6gGvQiujeuph X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 20/21] core/pldm: Add file io write 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 WriteFile request message. Due to maximum transfer size for PLDM protocol, we have to send several write requests, if necessary. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-file-io-requests.c | 123 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 125 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 48b00ef2..0665a679 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -162,6 +162,129 @@ int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, return read_file_req(file_handle, file_length, buf, offset, size); } +/* + * Send/receive a PLDM WriteFile request message. + */ +static int write_file_req(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size) +{ + void *response_msg, *current_ptr, *payload_data; + uint32_t total_write, resp_length, request_length; + size_t response_len, payload_len; + uint8_t completion_code; + int num_transfers; + char *request_msg; + int rc, i; + + struct pldm_write_file_req file_req = { + .file_handle = file_handle, + .offset = offset, + .length = size + }; + + if (!size) + return OPAL_PARAMETER; + + if ((offset) && (offset > size)) + return OPAL_PARAMETER; + + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_write_file_req) + + size; + request_msg = malloc(request_length); + + payload_data = ((struct pldm_msg *)request_msg)->payload + + sizeof(file_req.file_handle) + + sizeof(file_req.offset) + + sizeof(file_req.length); + memcpy(payload_data, buf, size); + current_ptr = payload_data; + num_transfers = 1; + total_write = 0; + + if (size > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (size + 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%x, num_transfers: %d\n", + __func__, file_handle, file_req.offset, + file_req.length, num_transfers); + + for (i = 0; i < num_transfers; i++) { + file_req.offset = offset + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_write_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode WriteFileReq Error, rc: %d\n", rc); + free(request_msg); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait( + request_msg, request_length - 1, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: WriteFileReq, rc: %d\n", rc); + free(request_msg); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_write_file_resp( + response_msg, + payload_len, + &completion_code, + &resp_length); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode WriteFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(request_msg); + free(response_msg); + return OPAL_PARAMETER; + } + + if (resp_length == 0) { + free(response_msg); + break; + } + + total_write += resp_length; + current_ptr += resp_length; + free(response_msg); + + if (total_write == size) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (size - total_write)) + file_req.length = size - total_write; + } + + free(request_msg); + + return OPAL_SUCCESS; +} + +int pldm_file_io_write_file(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return write_file_req(file_handle, 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 2b2a979d..688c7996 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -49,6 +49,8 @@ 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_write_file(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size); int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv); From patchwork Tue Sep 13 10:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677224 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=GFAZe4+Z; 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 4MRfnW5bN1z1ynm for ; Tue, 13 Sep 2022 20:28:31 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfnW4lPCz30NN for ; Tue, 13 Sep 2022 20:28:31 +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=GFAZe4+Z; 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=mx0b-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=GFAZe4+Z; 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 4MRfm61cljz3bSX for ; Tue, 13 Sep 2022 20:27:17 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9LmYa011511 for ; Tue, 13 Sep 2022 10:27:15 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=QnitJ6vPFqRffzo0Lli6EQhpkVM2574GqkEnVS/GlqA=; b=GFAZe4+Z95dI+x02Qx4EIVrGWcvVVZRBVjLGkRZF5GvXdgfANdY5maInAG26IPQ7BFxb g6RsiD0K6mvbIiGXkLsRog8JQcIQh1JJLpqhzC4un839w/Mog1bvnszDsXvIs7NbxCHr EgIw4rKjt26DwaEsNxaaV3sUTXL+uq6G1wHo5OUsvQtUnUJNdTsx24JJGtOWrEhPZXy2 O+sjurzqX/D6A+7iCUQ6tJ8iS+6EpLMqsCWkMw6fBPfl+SrB8/1pgyqth5B/ib59F07g nQ+sT64VF642YNF7mB7XMcoCsRglaG1U1LK1oBfGntfatIvntLMUPtNxB6DzEoqezEDv Ug== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq5rhxff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:15 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKiii029952 for ; Tue, 13 Sep 2022 10:27:14 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma01fra.de.ibm.com with ESMTP id 3jgj78tp3m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:13 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DANS9519005744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:23:28 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 81FB7A404D for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5911DA4040 for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:11 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:05 +0200 Message-Id: <20220913102705.65506-22-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JST1NKQs0-sD5zPJE8JltUDG7CkqBCBH X-Proofpoint-ORIG-GUID: JST1NKQs0-sD5zPJE8JltUDG7CkqBCBH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 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 Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-file-io-requests.c | 78 ++++++++++++++++++++++++++++++- core/pldm/pldm.h | 3 ++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 0665a679..a1191b89 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_PARAMETER; + + 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 - No file handle found, lid_id: %s\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_PARAMETER; + + 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 + 1) @@ -191,7 +267,7 @@ static int write_file_req(uint32_t file_handle, const void *buf, request_length = sizeof(struct pldm_msg_hdr) + sizeof(struct pldm_write_file_req) + size; - request_msg = malloc(request_length); + request_msg = zalloc(request_length); payload_data = ((struct pldm_msg *)request_msg)->payload + sizeof(file_req.file_handle) diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 688c7996..35b0dd66 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,6 +47,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, void *buf, uint32_t offset, uint64_t size); int pldm_file_io_write_file(uint32_t file_handle, const void *buf,