From patchwork Tue Jun 20 14:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797381 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=p0Q7lHaT; 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 4QlqZQ4nFGz20Wk for ; Wed, 21 Jun 2023 01:00: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=p0Q7lHaT; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqZQ3dtbz3bT2 for ; Wed, 21 Jun 2023 01:00:46 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=p0Q7lHaT; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4QlqZ22HyPz304l for ; Wed, 21 Jun 2023 01:00:26 +1000 (AEST) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEruZ0002501 for ; Tue, 20 Jun 2023 15:00:24 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=zumWrjWFF1IpOWhD/bXm/0m8Rp0X59pmz+WgJk5oGZQ=; b=p0Q7lHaTXL4J+6s3ikbeW8pm5bOeipX8JWSgrv291GoN9QS8FP/LoiBIkqNrgkO1Q+yW 8KIfCaGU5CHk5ToHPLiApLHoNjBs/H1fl/4GRfo+vkhjtBJNVUcK/ATpOXIBHkUKDP2m jbR1aZklKC1p1OFqOtlxjJIen8MknQzw2ZgMjpWTuHEye1KTXovFB+xMEJKGraBXzhxN cn8IFMjGk7SY9lUcZZbUB3X0R/w+LEdH7kt1VgMGvzZxX1fc6i7ucG9WU6e45Mi5+GxI 4wiWjGq7MKodOoLc3C5r0wORNLw47RMFe43ELSSF+XtuBxCG3kzig7/LOqt8RgUB8DiQ yw== 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 3rbe97g4md-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K4aCYo027815 for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3r943e1men-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:20 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Iwh42271292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:18 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4851520040 for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 229B72004D for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 16:59:57 +0200 Message-ID: <20230620150017.88663-2-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Igd8ZiT9AnqXoF2ACzmsI7rb3Ngomp_J X-Proofpoint-ORIG-GUID: Igd8ZiT9AnqXoF2ACzmsI7rb3Ngomp_J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- 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 Jun 20 14:59:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797387 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=pkqhTP1d; 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 4QlqbS2q75z20Wk for ; Wed, 21 Jun 2023 01:01:40 +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=pkqhTP1d; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqbS1dZCz3c67 for ; Wed, 21 Jun 2023 01:01:40 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=pkqhTP1d; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ34Gd2z30LM for ; Wed, 21 Jun 2023 01:00:26 +1000 (AEST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEpLU6023388 for ; Tue, 20 Jun 2023 15:00:24 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=EFdSjN0Snh3aQp9/xwV7FpG0igJMEzztSOeMI3XZK54=; b=pkqhTP1dw6feOcEE72bY5za25lpNGgbubaOekaaFe1eXRoRB3itWbo5KPKMFRwL8VO+Q knbMVDcUagiDH4T1JVdSzbT+8qWcWZ10so+yTbBnJO5nzr9GtFE0fpt8zABHKIFkSRd3 U6TAfdvREhuFWQYloO4bIseR+zzuZLCVYKy4OWCBSLwBai0iUR3CNuQbCIbeRREUvmBq yHX2xKVFm/DYC89oBu/whQJmdeSdUU4AiZwX7CfbYWsS+shw3QJyoeCX87GXBcTmIzcD HIX0yJ0aLXhU1ZvcnTgF8pA6EqAFzDsQ8mKKuV9lUpni9Ydfn1go9vip4Io+elFnSF+3 BQ== 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 3rbe81r74n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K3KGaa029809 for ; Tue, 20 Jun 2023 15:00:22 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3r94f5a51d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Il141353668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:18 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B01520040 for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56ADC2004E for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 16:59:58 +0200 Message-ID: <20230620150017.88663-3-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: htnIsJNFbrE3Xm2Xo0Cfq5gPF29YwrP3 X-Proofpoint-GUID: htnIsJNFbrE3Xm2Xo0Cfq5gPF29YwrP3 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 phishscore=0 malwarescore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- hw/ast-bmc/Makefile.inc | 7 + hw/ast-bmc/ast-mctp.c | 364 ++++++++++++++++++++++++++++++++++++++ include/ast.h | 20 +++ platforms/astbmc/common.c | 41 +++++ 4 files changed, 432 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..c2efb7b2 --- /dev/null +++ b/hw/ast-bmc/ast-mctp.c @@ -0,0 +1,364 @@ +// 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 +#include +#include + +static struct mctp *mctp; +static struct mctp_binding_astlpc *astlpc; +static struct astlpc_ops_data *ops_data; +static struct lock mctp_lock = LOCK_UNLOCKED; + +/* Keyboard Controller Style (KCS) data register address */ +#define KCS_DATA_REG 0xca2 + +/* Keyboard Controller Style (KCS) status register address */ +#define KCS_STATUS_REG 0xca3 + +#define KCS_STATUS_BMC_READY 0x80 +#define KCS_STATUS_OBF 0x01 + +#define HOST_MAX_INCOMING_MESSAGE_ALLOCATION 131072 +#define DESIRED_MTU 32768 + +#define TX_POLL_MAX 5 + +/* + * The AST LPC binding is described here: + * + * https://github.com/openbmc/libmctp/blob/master/docs/bindings/vendor-ibm-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; + + 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; + + *val = lpc_inb(addr); + + return OPAL_SUCCESS; +} + +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; + + prlog(PR_TRACE, "%s 0x%hhx to %s\n", + __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; + + lpc_outb(val, addr); + + return OPAL_SUCCESS; +} + +static int astlpc_read(void *binding_data, void *buf, long offset, + size_t len) +{ + struct astlpc_ops_data *ops_data = binding_data; + + prlog(PR_TRACE, "%s %zu bytes from 0x%lx (lpc: 0x%lx)\n", + __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; + + prlog(PR_TRACE, "%s %zu bytes to offset 0x%lx (lpc: 0x%lx)\n", + __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, +}; + +/* we need a poller to crank the mctp state machine during boot */ +static void astlpc_poller(void *data) +{ + struct mctp_binding_astlpc *astlpc = (struct mctp_binding_astlpc *)data; + + if (astlpc) + mctp_astlpc_poll(astlpc); +} + +/* at runtime the interrupt should handle it */ +static void astlpc_interrupt(uint32_t chip_id __unused, + uint32_t irq_msk __unused) +{ + if (astlpc) + mctp_astlpc_poll(astlpc); +} + +static struct lpc_client kcs_lpc_client = { + .reset = NULL, + .interrupt = astlpc_interrupt, +}; + +static void drain_odr(struct astlpc_ops_data *ops_data) +{ + uint8_t kcs_status, kcs_data; + uint8_t drain_counter = 255; + + astlpc_kcs_reg_read(ops_data, MCTP_ASTLPC_KCS_REG_STATUS, &kcs_status); + + while (--drain_counter && (kcs_status & KCS_STATUS_OBF)) { + astlpc_kcs_reg_read(ops_data, MCTP_ASTLPC_KCS_REG_DATA, &kcs_data); + time_wait_ms(5); + astlpc_kcs_reg_read(ops_data, MCTP_ASTLPC_KCS_REG_STATUS, &kcs_status); + } +} + +static int astlpc_binding(void) +{ + struct mctp_bus *bus; + int counter = 0; + + 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) { + prlog(PR_ERR, "binding init failed\n"); + return OPAL_HARDWARE; + } + + /* Read and discard any potentially stale messages in the ODR */ + drain_odr(ops_data); + + /* 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)) { + prlog(PR_ERR, "failed to register bus\n"); + goto err; + } + + /* lpc/kcs status register poller */ + opal_add_poller(astlpc_poller, astlpc); + + /* Don't start sending messages to the BMC until the bus has + * been registered and tx has been enabled + */ + bus = mctp_binding_astlpc_core(astlpc)->bus; + + while ((bus == NULL) || + (mctp_bus_get_state(bus) == mctp_bus_state_constructed)) { + if (++counter >= 1000) { + prlog(PR_ERR, "failed to initialize MCTP channel\n"); + goto err; + } + time_wait_ms(5); + + /* Update bus pointer if it is a nullptr */ + if (bus == NULL) + bus = mctp_binding_astlpc_core(astlpc)->bus; + } + + return OPAL_SUCCESS; + +err: + mctp_astlpc_destroy(astlpc); + free(ops_data); + + return OPAL_HARDWARE; +} + +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_message_tx(bool tag_owner, uint8_t msg_tag, + uint8_t *msg, int msg_len) +{ + unsigned long stop_time; + int rc = OPAL_SUCCESS; + + lock(&mctp_lock); + + rc = mctp_message_tx(mctp, BMC_EID, tag_owner, msg_tag, + msg, msg_len); + unlock(&mctp_lock); + + /* do not poll when we respond to a BMC request */ + if (tag_owner) + return rc; + + /* read the Rx_complete command out of the ODR */ + stop_time = mftb() + msecs_to_tb(TX_POLL_MAX); + while (mftb() < stop_time && !mctp_astlpc_tx_done(astlpc)) + mctp_astlpc_poll(astlpc); + + return rc; +} + +static void message_rx(uint8_t eid, bool tag_owner, + uint8_t msg_tag, void *data __unused, + void *vmsg, size_t len) +{ + uint8_t *msg = (uint8_t *)vmsg; + + prlog(PR_TRACE, "message received: msg type: %x, len %zd" + " (eid: %d), rx tag %d owner %d\n", + *msg, len, eid, tag_owner, msg_tag); +} + +/* + * Initialize mctp binding for hbrt and provide interfaces for sending + * and receiving mctp messages. + */ +int ast_mctp_init(void) +{ + uint32_t kcs_serial_irq; + struct dt_node *n; + + /* Search mctp node */ + n = dt_find_compatible_node(dt_root, NULL, "mctp"); + if (!n) { + prlog(PR_ERR, "No MCTP device\n"); + return OPAL_PARAMETER; + } + + /* 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 pcie / kcs -> (eid: 9) | skiboot | + * \-----/ \---------/ + */ + mctp = mctp_init(); + if (!mctp) { + prlog(PR_ERR, "mctp init failed\n"); + return OPAL_HARDWARE; + } + +#ifdef AST_MCTP_DEBUG + /* Setup the trace hook */ + mctp_set_log_custom(mctp_log); +#endif + + /* 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, message_rx, NULL); + + /* Initialize the binding */ + if (astlpc_binding()) + goto err; + + /* register an lpc client so we get an interrupt */ + kcs_serial_irq = dt_prop_get_u32(n, "interrupts"); + kcs_lpc_client.interrupts = LPC_IRQ(kcs_serial_irq); + lpc_register_client(dt_get_chip_id(n), &kcs_lpc_client, IRQ_ATTR_TARGET_OPAL); + + return OPAL_SUCCESS; + +err: + prlog(PR_ERR, "Unable to initialize MCTP\n"); + mctp_destroy(mctp); + mctp = NULL; + + return OPAL_HARDWARE; +} + +void ast_mctp_exit(void) +{ + if (astlpc) { + mctp_astlpc_destroy(astlpc); + astlpc = NULL; + } + + if (mctp) { + mctp_destroy(mctp); + mctp = NULL; + } +} diff --git a/include/ast.h b/include/ast.h index 5e932398..79efe4fc 100644 --- a/include/ast.h +++ b/include/ast.h @@ -91,6 +91,26 @@ 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); +/* MCTP configuration */ + +/* + * 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 + +enum mctp_msg_type { + MCTP_MSG_TYPE_CONTROL = 0x00, + MCTP_MSG_TYPE_PLDM = 0x01, +}; + +int ast_mctp_message_tx(bool tag_owner, uint8_t msg_tag, + uint8_t *msg, int msg_len); +int ast_mctp_init(void); +void ast_mctp_exit(void); + #endif /* __SKIBOOT__ */ /* diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c index bfbba2d5..6697230b 100644 --- a/platforms/astbmc/common.c +++ b/platforms/astbmc/common.c @@ -31,6 +31,11 @@ #define MBOX_IO_COUNT 6 #define MBOX_LPC_IRQ 9 +/* MCTP config */ +#define MCTP_IO_BASE 0xca2 +#define MCTP_IO_COUNT 2 +#define MCTP_LPC_IRQ 11 + void astbmc_ext_irq_serirq_cpld(unsigned int chip_id) { lpc_all_interrupts(chip_id); @@ -227,6 +232,37 @@ static void astbmc_fixup_dt_system_id(void) dt_add_property_strings(dt_root, "system-id", "unavailable"); } +#ifdef CONFIG_PLDM +static void astbmc_fixup_dt_mctp(struct dt_node *lpc) +{ + struct dt_node *mctp; + char namebuf[32]; + + if (!lpc) + return; + + /* First check if the mbox interface is already there */ + dt_for_each_child(lpc, mctp) { + if (dt_node_is_compatible(mctp, "mctp")) + return; + } + + snprintf(namebuf, sizeof(namebuf), "mctp@i%x", MCTP_IO_BASE); + mctp = dt_new(lpc, namebuf); + + dt_add_property_cells(mctp, "reg", + 1, /* IO space */ + MCTP_IO_BASE, MCTP_IO_COUNT); + dt_add_property_strings(mctp, "compatible", "mctp"); + + /* Mark it as reserved to avoid Linux trying to claim it */ + dt_add_property_strings(mctp, "status", "reserved"); + + dt_add_property_cells(mctp, "interrupts", MCTP_LPC_IRQ); + dt_add_property_cells(mctp, "interrupt-parent", lpc->phandle); +} +#endif + static void astbmc_fixup_dt_bt(struct dt_node *lpc) { struct dt_node *bt; @@ -404,6 +440,11 @@ static void astbmc_fixup_dt(void) /* BT is not in HB either */ astbmc_fixup_dt_bt(primary_lpc); +#ifdef CONFIG_PLDM + /* Fixup the MCTP, that might be missing from HB */ + astbmc_fixup_dt_mctp(primary_lpc); +#endif + /* The pel logging code needs a system-id property to work so make sure we have one. */ astbmc_fixup_dt_system_id(); From patchwork Tue Jun 20 14:59:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797398 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=KCkRikTq; 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 4QlqdM11srz20Wk for ; Wed, 21 Jun 2023 01:03:19 +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=KCkRikTq; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqdL72j3z3cX1 for ; Wed, 21 Jun 2023 01:03:18 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=KCkRikTq; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ60kFdz30fM for ; Wed, 21 Jun 2023 01:00:29 +1000 (AEST) Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEfAEg004324 for ; Tue, 20 Jun 2023 15:00:24 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=EKf/NHNq63md/0Yj8xgAhjXn8lpBbsRIp0zPGaAs/vw=; b=KCkRikTqNftDJTOk3wi8YTXnzELd741fZAAbZWweCq6rhw2Iyh24+gddUOnReSu4WIJp fUQO3WYz65mcR1nbr0VQ81nlYQMUdP632hoPhGPo6rB84Dywmk6DPCHadn/s+2ZjgKFQ ymRHpnselRLqq+TCbnyaZVjYWcRUipAIwsO9evO9Vna+i4sAF6XEGSRgsPyFuyU9TQ/o jl8eXYTMfBQEMzv3YMAhL89sxiPs5oVy1/VTESpVMK4Wbf9B/zyxtqCUhLsvUXk8qxAa x5o1jZNdBXSZxmRDYMPrw70rZUJZT1cXpBiF+/BVQmgkK8+X1AhXedVQfanyoQSXZnuK Fg== 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 3rbd4dt2bt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35JNQuWs027093 for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3r943e256c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0IK043909530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:18 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AFBFB20040 for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 880972004B for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 16:59:59 +0200 Message-ID: <20230620150017.88663-4-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 8beuQpgUu-WuGtt2aPcWPkiND-9RJNJK X-Proofpoint-ORIG-GUID: 8beuQpgUu-WuGtt2aPcWPkiND-9RJNJK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 impostorscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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). Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/Makefile.inc | 6 ++- core/pldm/Makefile.inc | 13 ++++++ core/pldm/pldm-mctp.c | 91 ++++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 44 ++++++++++++++++++++ hw/ast-bmc/ast-mctp.c | 18 +++++++++ include/pldm.h | 24 +++++++++++ 6 files changed, 195 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..ae45bb8b --- /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/include/ +CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ + +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..fb675849 --- /dev/null +++ b/core/pldm/pldm-mctp.c @@ -0,0 +1,91 @@ +// 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 "pldm.h" + +/* + * PLDM over MCTP (DSP0241) + * + * First byte of the MCTP message is the message Type = PLDM + * PLDM = 0x01 (000_0001b) + * + * Next bytes of the MCTP message (MCTP message body) contain the + * PLDM message (The base PLDM message fields are defined in DSP0240) + */ + +int pldm_mctp_message_tx(struct pldm_tx_data *tx) +{ + tx->mctp_msg_type = MCTP_MSG_TYPE_PLDM; + + return ast_mctp_message_tx(tx->tag_owner, tx->msg_tag, + &tx->mctp_msg_type, + tx->data_size + sizeof(tx->mctp_msg_type)); +} + +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len) +{ + struct pldm_rx_data *rx; + int rc = 0; + + rx = zalloc(sizeof(struct pldm_rx_data)); + if (!rx) { + prlog(PR_ERR, "failed to allocate rx message\n"); + return OPAL_NO_MEM; + } + + rx->msg = (struct pldm_msg *)buf; + rx->source_eid = eid; + rx->msg_len = len; + rx->tag_owner = tag_owner; + rx->msg_tag = msg_tag; + + /* Additional header information */ + if (unpack_pldm_header(&rx->msg->hdr, &rx->hdrinf)) { + prlog(PR_ERR, "%s: unable to decode header\n", __func__); + rc = OPAL_EMPTY; + goto out; + } + +out: + free(rx); + return rc; +} + +int pldm_mctp_init(void) +{ + int nbr_elt = 1, rc = OPAL_SUCCESS; + + int (*pldm_config[])(void) = { + ast_mctp_init, /* MCTP Binding */ + }; + + const char *pldm_config_error[] = { + "Failed to bind MCTP", + }; + + prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); + + for (int i = 0; i < nbr_elt; i++) { + rc = pldm_config[i](); + if (rc) { + prlog(PR_ERR, "%s\n", pldm_config_error[i]); + goto out; + } + } + +out: + 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..0c7bb17d --- /dev/null +++ b/core/pldm/pldm.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __COREPLDM_H__ +#define __COREPLDM_H__ + +#include +#include +#include + +struct pldm_tx_data { + /* Contains an message header and payload of an MCTP packet. + * Size of data[] + */ + size_t data_size; + + /* Holds data related to the routing of an MCTP packet */ + bool tag_owner; + uint8_t msg_tag; + + /* This byte is situated just before the message body */ + uint8_t mctp_msg_type; + + /* The message payload (e.g. PLDM message) */ + uint8_t data[0]; +}; + +struct pldm_rx_data { + struct pldm_header_info hdrinf; /* parsed message header */ + + struct pldm_msg *msg; + int msg_len; + int source_eid; + bool tag_owner; + uint8_t msg_tag; +}; + +int pldm_mctp_message_tx(struct pldm_tx_data *tx); + +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len); + +#endif /* __COREPLDM_H__ */ diff --git a/hw/ast-bmc/ast-mctp.c b/hw/ast-bmc/ast-mctp.c index c2efb7b2..00f66abe 100644 --- a/hw/ast-bmc/ast-mctp.c +++ b/hw/ast-bmc/ast-mctp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -286,6 +287,23 @@ static void message_rx(uint8_t eid, bool tag_owner, prlog(PR_TRACE, "message received: msg type: %x, len %zd" " (eid: %d), rx tag %d owner %d\n", *msg, len, eid, tag_owner, msg_tag); + + /* The first byte defines the type of MCTP packet payload + * contained in the message data portion of the MCTP message. + * (See DSP0236 for more details about MCTP packet fields). + * For now we only support PLDM over MCTP. + */ + switch (*msg) { + case MCTP_MSG_TYPE_PLDM: + /* handle the PLDM message */ + pldm_mctp_message_rx(eid, tag_owner, msg_tag, + msg + sizeof(uint8_t), + len - sizeof(uint8_t)); + break; + default: + prlog(PR_ERR, "%s - not a pldm message type (type: %x)\n", + __func__, *msg); + } } /* diff --git a/include/pldm.h b/include/pldm.h new file mode 100644 index 00000000..617287fe --- /dev/null +++ b/include/pldm.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __PLDM_H__ +#define __PLDM_H__ + +/** + * Handle PLDM messages received from MCTP + */ +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len); + +/** + * PLDM over MCTP initialization + */ +int pldm_mctp_init(void); + +/** + * PLDM over MCTP stop + */ +void pldm_mctp_exit(void); + +#endif /* __PLDM_H__ */ From patchwork Tue Jun 20 15:00:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797395 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=Pzju7vv8; 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 4Qlqcq4YQmz20Wk for ; Wed, 21 Jun 2023 01:02:51 +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=Pzju7vv8; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqcq3S8Mz3cT3 for ; Wed, 21 Jun 2023 01:02:51 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Pzju7vv8; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ503Vmz30fM for ; Wed, 21 Jun 2023 01:00:28 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEorDe016617 for ; Tue, 20 Jun 2023 15:00:25 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=+5Z1vKFA6HtKMS1N9JLBmTm4UK6cMy/XWEfn5zx5opk=; b=Pzju7vv80BI9CR3ZySZ6qAO1SKK8Z7+DlLljHmx7iDBnqG3X2OuMydh5XReXPPGlLZHW CVnqqTwIpBh+fHO4pXbEZJM6PkXe5cTGe9D8bLkpCrQ20n0W4Hjs3uB9CZwyXq80sR6j LQDeXWIYat89dIGEe7gHfGE4Xc5z+p93ePb+hFYDLcHc0IWuOEZlc68pjvqlZO54GreR t6Q51hcXasqsDRgs/jjom6fH8/3kR4DQM57GoqLSpLrRzbE/fcV8ZFHbjDxxd84e2g/y A8AkeFcJboQpl042g7V0eunL4kJ48X0ciTkCmTwNkYEflnUYv5BdDKc+MAeDjeTPtaKX rw== Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbe82r894-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:25 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEZD6D025326 for ; Tue, 20 Jun 2023 15:00:23 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3r94f59m6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Iev41353674 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBDCE2004E for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BD6D520043 for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:00 +0200 Message-ID: <20230620150017.88663-5-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jefHsUhqhyVlukh4CisTP27jD8B71glI X-Proofpoint-ORIG-GUID: jefHsUhqhyVlukh4CisTP27jD8B71glI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-mctp.c | 15 +++- core/pldm/pldm-responder.c | 154 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 ++ 4 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-responder.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index ae45bb8b..9aa72a77 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,7 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/include/ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ -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 fb675849..0e6a7e37 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -53,6 +53,17 @@ int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, goto out; } + switch (rx->hdrinf.msg_type) { + case PLDM_REQUEST: + rc = pldm_responder_handle_request(rx); + break; + default: + prlog(PR_ERR, "%s: message not supported (msg type: 0%x)\n", + __func__, rx->hdrinf.msg_type); + rc = OPAL_PARAMETER; + break; + } + out: free(rx); return rc; @@ -60,14 +71,16 @@ out: int pldm_mctp_init(void) { - int nbr_elt = 1, rc = OPAL_SUCCESS; + int nbr_elt = 2, rc = OPAL_SUCCESS; int (*pldm_config[])(void) = { ast_mctp_init, /* MCTP Binding */ + pldm_responder_init, /* Register mandatory commands we'll respond to */ }; const char *pldm_config_error[] = { "Failed to bind MCTP", + "Failed to register mandatory commands", }; prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c new file mode 100644 index 00000000..74376f17 --- /dev/null +++ b/core/pldm/pldm-responder.c @@ -0,0 +1,154 @@ +// 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 *rx); + + 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 *rx, uint8_t type, + uint8_t command, uint8_t cc) +{ + size_t data_size = PLDM_MSG_SIZE(uint8_t); + struct pldm_tx_data *tx; + int rc; + + /* Encode the cc response */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + encode_cc_only_resp(rx->hdrinf.instance, + type, + command, + cc, + (struct pldm_msg *)tx->data); + + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send response message containing only cc, " + "rc = %d, cc = %d\n", rc, cc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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 0c7bb17d..1cb0b424 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -9,6 +9,8 @@ #include #include +#define PLDM_MSG_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) + struct pldm_tx_data { /* Contains an message header and payload of an MCTP packet. * Size of data[] @@ -41,4 +43,8 @@ int pldm_mctp_message_tx(struct pldm_tx_data *tx); int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, const 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 Jun 20 15:00:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797380 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=pjHRVoaL; 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 4QlqZF61Mkz20Wk for ; Wed, 21 Jun 2023 01:00:37 +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=pjHRVoaL; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqZF4qXQz3bPG for ; Wed, 21 Jun 2023 01:00:37 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=pjHRVoaL; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ2185hz30LM for ; Wed, 21 Jun 2023 01:00:25 +1000 (AEST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KElLSZ005243 for ; Tue, 20 Jun 2023 15:00:23 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=7gmkXAw9yj4fbnqgVggpjbG3IR+h8GEB9M8FJtIBTb8=; b=pjHRVoaL8A/zLOyM1mfxqvdrffcwl8wcvQ7dA2cPp6uYz0dnEHOjDp2ccpLdub/8d0UP brg6ObKZ27rMgr2xnVqQUSztp86+hixBuOLmPd+K6PuWOT+kWBsu535bwjQDM+9UbBPm K6UZWYOAnGbZefiiP2/2uzgjeQVuK4Vt8XFcFgxZJ30WH98hNg3zWPkUZW7kiSgTWhGs 6/AUVYqRv357OQrP9OK3UkWUELHK/851lAPA9vPh7C/U+RuU7LAGxUX7NprpXH596kmN iZM+PH8TW8N7ZNuc51FZo9hEkJgAbT5JyJUYRMFuvsOreG3KGNT+o7dUG7un+LwP54p7 Eg== 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 3rbe658amr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35KD8NT3016650 for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3r943e1mep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0JUG43909538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 11F3D20043 for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E8AA420040 for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:18 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:01 +0200 Message-ID: <20230620150017.88663-6-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 0Yr6qHgDGYBKGzgN3-UyLQkYxGH0pG3o X-Proofpoint-ORIG-GUID: 0Yr6qHgDGYBKGzgN3-UyLQkYxGH0pG3o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=925 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 | 60 ++++++++++++++++++++++++++++++++++++++ include/ast.h | 6 ++++ 2 files changed, 66 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 74376f17..061b5c3f 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -105,6 +105,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 */ @@ -114,6 +125,54 @@ 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 *rx) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_tid_resp); + struct pldm_tx_data *tx; + int rc; + + /* create a PLDM response message for GetTID */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_tid_resp(rx->hdrinf.instance, + PLDM_SUCCESS, + HOST_TID, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetTID response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -149,6 +208,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/include/ast.h b/include/ast.h index 79efe4fc..40b751f5 100644 --- a/include/ast.h +++ b/include/ast.h @@ -101,6 +101,12 @@ void ast_setup_sio_mbox(uint16_t io_base, uint8_t irq); #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 + enum mctp_msg_type { MCTP_MSG_TYPE_CONTROL = 0x00, MCTP_MSG_TYPE_PLDM = 0x01, From patchwork Tue Jun 20 15:00:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797383 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=slNCQz/b; 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 4QlqZm4SjVz20Wk for ; Wed, 21 Jun 2023 01:01:04 +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=slNCQz/b; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqZm3Mypz3bwX for ; Wed, 21 Jun 2023 01:01:04 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=slNCQz/b; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ25qrfz30LM for ; Wed, 21 Jun 2023 01:00:26 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEqej6016717 for ; Tue, 20 Jun 2023 15:00:24 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=tylYsda/TYh5jwl2ScpAPCCEY2PzSFRJQZ8a+iWa2YQ=; b=slNCQz/bb2lmLXsVSWuMWR98sqrUyvQ8p9xPPbMan8nTptgwReZuitj9KMkeT9Kp5xAI tmwTiKTciMiX4R+PHJdDe1WFkHSd5fk7TndC8j+T0zWBt5mCgbZJcijfQoHnLjA7iTnv VAAIQJllFdwCLmjWWQoNOtgEj7vfHUk3MkKLXAOV3twQKZRyf+GWAJUKE7MqB028KJ80 Ls8vwalGHEkZhZevk54ZVVjBQtnZMdRVuOfZnaSzxdasbpGE/as69mKE2geqaTrSBboS sR4fEz6FL8Ve1mlcepxQ0X+n5zZepHeB9NLdYtIE9hVgNouS0mqTkfQv+sO/wA4OLkAJ 9w== 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 3rbe8u85q0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K3BZ8o018854 for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3r94f51m33-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Jtj16057070 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3CBA72004F for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1ECC12004E for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:02 +0200 Message-ID: <20230620150017.88663-7-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: qRniXQL9M_BD0fcFbk9T5p5yI2SRYT01 X-Proofpoint-GUID: qRniXQL9M_BD0fcFbk9T5p5yI2SRYT01 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- core/pldm/pldm-responder.c | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 061b5c3f..33f9b17f 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -173,6 +173,67 @@ 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 *rx) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_types_resp); + bitmap_elem_t type_map[BITMAP_ELEMS(PLDM_MAX_TYPES)]; + struct pldm_tx_data *tx; + 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(PLDM_MAX_TYPES); i++) + type_map[i] = cpu_to_le64(type_map[i]); + + /* create a PLDM response message for GetPLDMTypes */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_types_resp(rx->hdrinf.instance, + PLDM_SUCCESS, + (bitfield8_t *)type_map, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMTypes Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMTypes response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -209,6 +270,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 Jun 20 15:00:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797391 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=M9ClyHE7; 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 4Qlqc75cyqz20Wk for ; Wed, 21 Jun 2023 01:02:15 +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=M9ClyHE7; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqc74QLFz3cLL for ; Wed, 21 Jun 2023 01:02:15 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=M9ClyHE7; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ43QJtz30fy for ; Wed, 21 Jun 2023 01:00:27 +1000 (AEST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEpHub023208 for ; Tue, 20 Jun 2023 15:00:26 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=O9VwU3Nw4ghTSkrafFt13zM0Fo+Ng+tbD7uC6S7bqjk=; b=M9ClyHE77KWD+OCcNmkTxhh/JeZKfpN41gG40bO9JmiPbpgKqFQsFRzU6IJB0D4cLQnt Li6HNRpU5/fbR1dwADeNIy/Ov1VAfvwb8eSvgVBCRP9ZpqyNzNHpam4SsRqk2k9GAgIv 6nsx2gyIZOMdkYawBUQvBbbmWGrF6GWjTcnSMcEbN7d8M6NNymH9vryzRkvd04lNE4Xs L2JGsdI4Rtlf06vV9UIL/aowC18CgtR6zUwkcnRbVrGj9yNWKdT6H9qVYqP/Iepp/RtP t97V0b5pxesFHMvVzWyWbKPVsSCsV/NMUng4GjCOaQhffCjGlWflxOkEVW9NWg+7wwpw qg== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbe81r747-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K77sSt000954 for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3r94f59mmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0JUp16057072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 67AB020040 for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A01720043 for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:03 +0200 Message-ID: <20230620150017.88663-8-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ylZsZxszVmLiwVKSZHxS9bL12f4z6vlw X-Proofpoint-GUID: ylZsZxszVmLiwVKSZHxS9bL12f4z6vlw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 phishscore=0 malwarescore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- core/pldm/pldm-responder.c | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 33f9b17f..26a202d5 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -234,6 +234,104 @@ 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 *rx) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_commands_resp); + bitmap_elem_t cmd_map[BITMAP_ELEMS(PLDM_MAX_CMDS_PER_TYPE)]; + const struct pldm_type *type; + const struct pldm_cmd *iter; + struct pldm_tx_data *tx; + size_t payload_len; + ver32_t version; + uint8_t type_id; + int rc; + + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_commands_req(rx->msg, payload_len, + &type_id, &version); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPLDMCommands request, rc = %d", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + type = find_type(type_id); + if (!type) { + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + INVALID_PLDM_TYPE_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + if (memcmp(&type->version, &version, sizeof(version))) { + cc_resp(rx, rx->hdrinf.pldm_type, + rx->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(PLDM_MAX_CMDS_PER_TYPE); i++) + cmd_map[i] = cpu_to_le64(cmd_map[i]); + + /* create a PLDM response message for GetPLDMCommands */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_commands_resp(rx->hdrinf.instance, + PLDM_SUCCESS, + (bitfield8_t *)cmd_map, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMCommands Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMCommands response, rc = %d\n", rc); + return OPAL_HARDWARE; + free(tx); + } + + free(tx); + 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; @@ -271,6 +369,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 Jun 20 15:00:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797382 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=Dm2aXzYr; 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 4QlqZb4pGRz20Wk for ; Wed, 21 Jun 2023 01:00:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Dm2aXzYr; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqZb3fX3z3bnf for ; Wed, 21 Jun 2023 01:00:55 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Dm2aXzYr; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ23vLTz30Mc for ; Wed, 21 Jun 2023 01:00:26 +1000 (AEST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KElJQV005199 for ; Tue, 20 Jun 2023 15:00:24 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=OaoS6T+vTia8wv/Ybgz40zw5tIBxkqQKDe/t+XePd+w=; b=Dm2aXzYrAP7rGbxy9DDaSBN4DTJB7+WKwXFXb2Nv9a/K9EgbmXZVBwC1O0M2udjr0tx+ VYDyiwsQPHoqJMjiAn5+dod89Xe9r1rxc5TE78JvREtMTCSA7O3CLiRtBrsvAYc0LHjv OVoLR+8MPQDolYy6wW5EFxIGsGUsSHOnHa6F40QOUyEaKdcL+9GMH08tzfOpWmQLY1bL PipVHUKZglaeoCTZvXV6Ii0jLlbdlDep3xHYoJTGfMHzWtk6fPov3NFHk5zXqTX7X+E+ 4kIejFNNVi3izf/DwU+l3zWc/JSRvCViCIDahxfq9BVrmeLDJP8d2LkbudhPEoMY7Ni2 GA== 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 3rbe658an4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K5rYFG031973 for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3r94f5a51c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:21 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Jli16057074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 92AB320040 for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 753162004B for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:04 +0200 Message-ID: <20230620150017.88663-9-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7C1qqc9F0EgWDbF6rw67opg-vV8cPKc- X-Proofpoint-ORIG-GUID: 7C1qqc9F0EgWDbF6rw67opg-vV8cPKc- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- core/pldm/pldm-responder.c | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 26a202d5..a233ea3e 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -237,6 +237,8 @@ static struct pldm_cmd pldm_base_get_types = { /* * Extended error codes defined for the Base command set. */ +#define INVALID_DATA_TRANSFER_HANDLE 0x80 +#define INVALID_TRANSFER_OPERATION_FLAG 0x81 #define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83 #define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84 @@ -332,6 +334,97 @@ 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 *rx) +{ + uint32_t version_data[2]; + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_version_resp) + sizeof(version_data); + const struct pldm_type *type; + struct pldm_tx_data *tx; + uint8_t type_id, opflag; + uint32_t xfer_handle; + size_t payload_len; + int rc; + + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_version_req(rx->msg, payload_len, + &xfer_handle, + &opflag, + &type_id); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPLDMVersion request, rc = %d", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + /* reject multipart requests */ + if (opflag != PLDM_GET_FIRSTPART) { + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + INVALID_TRANSFER_OPERATION_FLAG); + return OPAL_PARAMETER; + } + + type = find_type(type_id); + if (!type) { + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + INVALID_PLDM_TYPE_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + /* pack a scratch buffer with our version(s) and CRC32 the lot */ + memcpy(&version_data[0], &type->version, 4); + + version_data[1] = cpu_to_le32(crc32(&type->version, 4)); + + /* create a PLDM response for GetPLDMVersion */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_version_resp(rx->hdrinf.instance, + PLDM_SUCCESS, + 0x0, /* no handle */ + PLDM_START_AND_END, + (ver32_t *) version_data, + sizeof(version_data), + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMVersion Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMVersion response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -370,6 +463,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 Jun 20 15:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797386 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=MG9sxmHk; 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 4QlqbH4DyNz20Wk for ; Wed, 21 Jun 2023 01:01: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=MG9sxmHk; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqbH1qSxz3c5H for ; Wed, 21 Jun 2023 01:01:31 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MG9sxmHk; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ34LmZz30QD for ; Wed, 21 Jun 2023 01:00:26 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEqVp6016052 for ; Tue, 20 Jun 2023 15:00:25 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=wiWQqFXvBmXxom6w9ewQWseLbVavJHml643Rb4tSkoI=; b=MG9sxmHkO3/fs6aUaWpFKGBxAmqP/gBlS013xwxjcfAURvWDrk+q3RkqdYAw8cSO1ebS h8IdybRsYGR6OJeE6m9B59ob5FCrEnrOZDhVrEb9K4ZDqTh95Q3MwKP9gOYHWaQgaY8G HMcupA5H4diOb0lICTpFZPsrQQbb5FLMkkmvfTRqCsFbjNxyTyywNmY/eYCc2fs0FcxK 3ggRm2jQgUHQcynUa+4D0MQ7egYO0Y1VyORoDLsNHqZZv2dNeDxk9ZuKI4MMInBsbhsm 5CajtcTgT/IEAbwtARwab8jwRdOUzr3TIEhSJJxIaWdXFY/pabyOWdBU0HPF5TmEdX50 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 3rbe8u85qq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35JLqAKO014870 for ; Tue, 20 Jun 2023 15:00:22 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3r943e256d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0JPm16057076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3FF020040 for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9FB6A2004D for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:05 +0200 Message-ID: <20230620150017.88663-10-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: zcOp4soX51ty3aj0O-DxXLLYihhcOK-D X-Proofpoint-GUID: zcOp4soX51ty3aj0O-DxXLLYihhcOK-D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-mctp.c | 7 +- core/pldm/pldm-requester.c | 335 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 9 + 4 files changed, 351 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-requester.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 9aa72a77..f2328a4b 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,7 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/include/ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ -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 0e6a7e37..569fe255 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -54,6 +54,9 @@ int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, } switch (rx->hdrinf.msg_type) { + case PLDM_RESPONSE: + rc = pldm_requester_handle_response(rx); + break; case PLDM_REQUEST: rc = pldm_responder_handle_request(rx); break; @@ -71,16 +74,18 @@ out: int pldm_mctp_init(void) { - int nbr_elt = 2, rc = OPAL_SUCCESS; + int nbr_elt = 3, rc = OPAL_SUCCESS; int (*pldm_config[])(void) = { ast_mctp_init, /* MCTP Binding */ pldm_responder_init, /* Register mandatory commands we'll respond to */ + pldm_requester_init, /* Requester implementation */ }; const char *pldm_config_error[] = { "Failed to bind MCTP", "Failed to register mandatory commands", + "Failed to configure requister", }; prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); diff --git a/core/pldm/pldm-requester.c b/core/pldm/pldm-requester.c new file mode 100644 index 00000000..9830cda9 --- /dev/null +++ b/core/pldm/pldm-requester.c @@ -0,0 +1,335 @@ +// 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" + +#define TIMEOUT_MS 8000 + +struct pldm_request { + struct list_node link; + + /* originating request params */ + struct pldm_header_info hdrinf; + + /* messages requested */ + struct pldm_tx_data *tx; + + /* 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 **msg; + size_t *msg_size; + bool done; + int rc; +}; + +/* pldm requests queue */ +static struct lock pldm_requests_lock = LOCK_UNLOCKED; +static LIST_HEAD(list_pldm_requests); + +static struct pldm_request *active_request; + +static bool matches_request(const struct pldm_rx_data *rx, + const struct pldm_request *req) +{ + if (req->hdrinf.instance != rx->hdrinf.instance) + return false; + if (req->hdrinf.pldm_type != rx->hdrinf.pldm_type) + return false; + if (req->hdrinf.command != 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->msg_size = len; + *resp->msg = zalloc(len); + memcpy(*resp->msg, rx->msg, len); + + resp->rc = OPAL_SUCCESS; + } else { + *resp->msg_size = 0; + *resp->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->hdrinf.pldm_type, + active_request->hdrinf.command, + active_request->hdrinf.instance); + + free(active_request->tx); + 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, "PLDM: request timedout! (active request: t:0x%x c:0x%x i:%d)\n", + active_request->hdrinf.pldm_type, + active_request->hdrinf.command, + active_request->hdrinf.instance); + + prlog(PR_ERR, "PLDM: Original request t:0x%x c:0x%x i:%d -----\n", + req->hdrinf.pldm_type, + req->hdrinf.command, req->hdrinf.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->hdrinf.pldm_type, + active_request->hdrinf.command, + active_request->hdrinf.instance); + return OPAL_WRONG_STATE; + } + + /* The expected message seems correct */ + handle_response(rx); + + return OPAL_SUCCESS; +} + +/* + * Send the PLDM request + */ +static void requests_poller(void *data __unused) +{ + int rc = OPAL_SUCCESS; + + lock(&pldm_requests_lock); + + /* wait for the end of the processing of the current request */ + if (active_request) { + unlock(&pldm_requests_lock); + return; + } + + /* no new request to handle */ + if (list_empty(&list_pldm_requests)) { + unlock(&pldm_requests_lock); + return; + } + + /* remove the first entry in a list */ + active_request = list_pop(&list_pldm_requests, + struct pldm_request, + link); + + unlock(&pldm_requests_lock); + + /* 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->hdrinf.pldm_type, + active_request->hdrinf.command, + active_request->hdrinf.instance); + + rc = pldm_mctp_message_tx(active_request->tx); + if (rc) + prlog(PR_ERR, "%s: Error %d while sending request\n", + __func__, rc); +} + +/* + * Add PLDM request in the queue + */ +static int queue_request(struct pldm_tx_data *tx, + uint64_t timeout_ms, + void (*complete)(struct pldm_rx_data *rx, void *data), + void *complete_data) +{ + struct pldm_request *pending; + struct pldm_msg *pldm_msg; + size_t tx_size; + + tx_size = sizeof(struct pldm_tx_data) + tx->data_size; + + pending = zalloc(sizeof(struct pldm_request)); + if (!pending) { + prlog(PR_ERR, "%s: failed to allocate request\n", __func__); + return OPAL_NO_MEM; + } + + pending->timeout_ms = timeout_ms; + pending->complete = complete; + pending->complete_data = complete_data; + pending->tx = zalloc(tx_size); + if (!pending->tx) { + free(pending); + prlog(PR_ERR, "%s: failed to allocate pldm packet (size: 0x%lx)\n", + __func__, tx_size); + return OPAL_NO_MEM; + } + + memcpy(pending->tx, tx, tx_size); + + pldm_msg = (struct pldm_msg *)tx->data; + if (unpack_pldm_header(&pldm_msg->hdr, &pending->hdrinf)) { + free(pending->tx); + free(pending); + prlog(PR_ERR, "%s: error parsing pldm header\n", __func__); + return OPAL_PARAMETER; + } + + /* add an entry at the end of a linked list */ + prlog(PR_TRACE, "%s: Add request t:%d c:%d i:%d -----\n", + __func__, + pending->hdrinf.pldm_type, + pending->hdrinf.command, + pending->hdrinf.instance); + + lock(&pldm_requests_lock); + list_add_tail(&list_pldm_requests, &pending->link); + unlock(&pldm_requests_lock); + + return OPAL_SUCCESS; +} + +/* + * Queue a PLDM request and don't wait. + * When a response is received, call the associated callback. + */ +int pldm_requester_queue(struct pldm_tx_data *tx, + void (*complete)(struct pldm_rx_data *rx, void *data), + void *complete_data) +{ + int rc = OPAL_SUCCESS; + + /* Queue PLDM request */ + rc = queue_request(tx, 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(struct pldm_tx_data *tx, + void **msg, size_t *msg_size) +{ + struct pldm_response *resp; + int rc = OPAL_SUCCESS; + + resp = zalloc(sizeof(struct pldm_response)); + if (!resp) { + prlog(PR_ERR, "%s: failed to allocate response\n", __func__); + return OPAL_NO_MEM; + } + + resp->msg = msg; + resp->msg_size = msg_size; + + rc = pldm_requester_queue(tx, send_and_wait_complete, resp); + if (rc) + goto out; + + /* wait for a response from the BMC */ + for (;;) { + if (resp->done) + break; + + time_wait_ms(5); + } + rc = resp->rc; + +out: + free(resp); + return rc; +} + +int pldm_requester_init(void) +{ + /* requests poller */ + opal_add_poller(requests_poller, NULL); + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 1cb0b424..ede17a23 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -47,4 +47,13 @@ int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, 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(struct pldm_tx_data *tx, + void (*complete)(struct pldm_rx_data *rx, void *data), + void *complete_data); +int pldm_requester_queue_and_wait(struct pldm_tx_data *tx, + void **msg, size_t *msg_size); +int pldm_requester_init(void); + #endif /* __COREPLDM_H__ */ From patchwork Tue Jun 20 15:00:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797400 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=ZAbQLCjM; 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 4Qlqdk5THCz20Wk for ; Wed, 21 Jun 2023 01:03:38 +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=ZAbQLCjM; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqdk35Qqz3cYl for ; Wed, 21 Jun 2023 01:03:38 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ZAbQLCjM; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZB6pwvz30PQ for ; Wed, 21 Jun 2023 01:00:34 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEoroG016772 for ; Tue, 20 Jun 2023 15:00:25 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=6jtLVBKRP8UHnWEEChUwIZOK4wMPbi1AJPmGwEW3SV8=; b=ZAbQLCjMTu2xL68932quJD/4qNKI0x3juzn0rOLTIG1IVqAlc1Cblg/HPef1SK40cUcr SiaCUcnni2LnOJfNtmhQiH052hVQI3dV2ArG8T/tkx8y21J8r+bPhYtlzi4wYzizXaSF vOU+uFwwy1DayJMNHgd+WOxG3s+wEyBKdwwnuwlgG+VmUlf+D8ZinCB1Mcg3PZS8cPyf 7JeYbGuWESHd7Qw/wJJOrBQwe5rX7utWcL6CXi5+Fl948bDOVgzsWwNPVvfFUyM/wxbX QMyQ7TosCAuWvy203Lw6Ul6mL4K+vw6OAQmGKQAT+1pzTvFMRK6w/lw80OJ5la6nVxFr 5Q== 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 3rbe82r88n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K4rB8D008204 for ; Tue, 20 Jun 2023 15:00:23 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3r943e1meq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0KuN15401610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0653B2004D for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D133C2004B for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:19 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:06 +0200 Message-ID: <20230620150017.88663-11-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: G2jBCIWvsDAsKXf2_NSGsUNMvGfqjvig X-Proofpoint-ORIG-GUID: G2jBCIWvsDAsKXf2_NSGsUNMvGfqjvig X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 1 + core/pldm/pldm-base-requests.c | 76 +++++++ core/pldm/pldm-mctp.c | 8 +- core/pldm/pldm-platform-requests.c | 309 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 9 + 5 files changed, 402 insertions(+), 1 deletion(-) 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 f2328a4b..933b0c61 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -8,6 +8,7 @@ CPPFLAGS += -I$(SRC)/pldm/include/ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ 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..d8984277 --- /dev/null +++ b/core/pldm/pldm-base-requests.c @@ -0,0 +1,76 @@ +// 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) +{ + size_t data_size = PLDM_MSG_SIZE(0); /* the command doesn't have a message payload */ + size_t response_len, payload_len; + struct pldm_tx_data *tx = NULL; + void *response_msg; + int rc; + + struct pldm_get_tid_resp response; + + /* Encode the get tid request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + rc = encode_get_tid_req(DEFAULT_INSTANCE_ID, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetTID, rc: %d\n", rc); + free(tx); + 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(tx); + free(response_msg); + return OPAL_PARAMETER; + } + + prlog(PR_INFO, "BMC's TID is %d\n", response.tid); + bmc_tid = response.tid; + free(tx); + free(response_msg); + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index 569fe255..a07d9503 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -74,18 +74,22 @@ out: int pldm_mctp_init(void) { - int nbr_elt = 3, rc = OPAL_SUCCESS; + int nbr_elt = 5, rc = OPAL_SUCCESS; int (*pldm_config[])(void) = { ast_mctp_init, /* MCTP Binding */ pldm_responder_init, /* Register mandatory commands we'll respond to */ pldm_requester_init, /* Requester implementation */ + pldm_base_get_tid_req, /* Get BMC tid */ + pldm_platform_init, /* Get PDRs data */ }; const char *pldm_config_error[] = { "Failed to bind MCTP", "Failed to register mandatory commands", "Failed to configure requister", + "Failed to retrieve BMC Tid", + "Failed to retrieve Data Records", }; prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); @@ -105,5 +109,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..6c019182 --- /dev/null +++ b/core/pldm/pldm-platform-requests.c @@ -0,0 +1,309 @@ +// 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 +#include "pldm.h" + +#define NO_MORE_PDR_HANDLES 0 + +static pldm_pdr *pdrs_repo; +static bool pdr_ready; + +struct pldm_pdrs { + struct pldm_tx_data *tx; + uint32_t record_hndl; + bool done; + int rc; +}; + +struct pldm_pdrs *pdrs; + +static void pdr_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + pdr_ready = false; + + if (pdrs_repo) + 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; + struct get_pdr_response response; + size_t payload_len; + int rc, i; + + prlog(PR_DEBUG, "%s - record_hndl: %d\n", __func__, record_hndl); + + if (rx == NULL) { + pdrs->rc = OPAL_PARAMETER; + pdrs->done = true; + } + + /* 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. This behavior can be + * encountered when the BMC reboots and the host is + * still operational. + * The host receives a GET VERSION request indicating + * that we must rehcrage the pdrs. + */ + 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); + if (!response.record_data) { + prlog(PR_ERR, "failed to allocate record data (size: 0x%lx)\n", response.record_data_length); + pdrs->rc = OPAL_NO_MEM; + pdrs->done = true; + return; + } + } + } + + /* 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. + * Use HOST_TID as terminus handle + */ + pldm_pdr_add(pdrs_repo, + response.record_data, + response.resp_cnt, + record_hndl, + false, + HOST_TID); + + 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 { + /* We have to indicate the end of the initialization when we + * reload the pdrs in background + */ + 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) +{ + 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 *)pdrs->tx->data, + 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(pdrs->tx, 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 pldm_platform_load_pdrs(void) +{ + /* destroy current repo and mark repo not ready */ + pdr_init_complete(false); + + /* make a new PDR repository */ + pdrs_repo = pldm_pdr_init(); + + /* collect all PDrs into a PDR Repository */ + pdrs->record_hndl = 0; + pdrs->done = false; + return encode_and_queue_get_pdr_req(pdrs); +} + +static int pdrs_init(void) +{ + int rc; + + rc = pldm_platform_load_pdrs(); + if (rc) + return rc; + + /* wait for the end of pdrs received */ + for (;;) { + if (pdrs->done) + break; + + time_wait_ms(5); + } + return pdrs->rc; +} + +int pldm_platform_init(void) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_pdr_req); + int rc; + + pdrs = zalloc(sizeof(struct pldm_pdrs)); + if (!pdrs) { + prlog(PR_ERR, "failed to allocate pdrs\n"); + return OPAL_NO_MEM; + } + + pdrs->tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!pdrs->tx) + return OPAL_NO_MEM; + pdrs->tx->data_size = data_size; + + /* retrieve all PDRs */ + rc = pdrs_init(); + if (rc) + goto err; + + pdr_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + prlog(PR_ERR, "%s - failed to initialize pdrs, rc: %d\n", __func__, rc); + pdr_init_complete(false); + free(pdrs->tx); + free(pdrs); + return rc; +} + +void pldm_platform_exit(void) +{ + if (pdr_ready) + pldm_pdr_destroy(pdrs_repo); + + if (pdrs) { + free(pdrs->tx); + free(pdrs); + } +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index ede17a23..6044ad02 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -11,6 +11,9 @@ #define PLDM_MSG_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_tx_data { /* Contains an message header and payload of an MCTP packet. * Size of data[] @@ -48,6 +51,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(struct pldm_tx_data *tx, void (*complete)(struct pldm_rx_data *rx, void *data), From patchwork Tue Jun 20 15:00:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797385 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=Sru0Y70q; 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 4Qlqb635pLz20Wk for ; Wed, 21 Jun 2023 01:01:22 +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=Sru0Y70q; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqb61xWlz3c3x for ; Wed, 21 Jun 2023 01:01:22 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Sru0Y70q; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ359k3z30dx for ; Wed, 21 Jun 2023 01:00:27 +1000 (AEST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KElEiJ005158 for ; Tue, 20 Jun 2023 15:00:25 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=a0jVWk2wGeglh8dZZem7am6paSkUASpTZmI1sJZ2ga0=; b=Sru0Y70ql4e4/xXTavJAJLPkZRrspXk/B6RvYutSa12O1/9+Fqxrs8ovCWRnhnNQZYuf n05ze5AIaTClzoqARhq0GrXGEs4hK50dASlojFdTvVMMoodKEKFTS1Pai4l5UwuXgce6 /Sq4QBiEKUNwIrI1CzZEhB6QC4MpDZHlaOGBkHD/t4wsT5BC/QcZVI+uC14dK8Wdec8p txxOimt2s8mhHEvSVEZN6G5NwWGFwt67nOXOmSsr5FEQskid26L/1xBCqGXJhagTmTfl 321pcqulQ1cKphx6VQ1uC8bTcmIYzTif2DICikeXBCflz6zEFAq+4LaDl+3LtFMOyj8e AQ== 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 3rbe658anp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35KBxDF6026133 for ; Tue, 20 Jun 2023 15:00:22 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3r94f59m6u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0KoT48038342 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31FBA20043 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12D6D2004E for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:07 +0200 Message-ID: <20230620150017.88663-12-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 2ElHFkV7yMoVgZVfHkjvQh01RSEh0px6 X-Proofpoint-ORIG-GUID: 2ElHFkV7yMoVgZVfHkjvQh01RSEh0px6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- core/pldm/pldm-platform-requests.c | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 6c019182..5bbdd012 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -44,6 +44,88 @@ 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) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_set_state_effecter_states_req); + struct set_effecter_state_response response; + size_t response_len, payload_len; + struct pldm_tx_data *tx = NULL; + void *response_msg; + int rc; + + struct pldm_set_state_effecter_states_req states_req = { + .effecter_id = effecter_id, + .comp_effecter_count = 1 + }; + + /* Encode the state effecter states request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + rc = encode_set_state_effecter_states_req( + DEFAULT_INSTANCE_ID, + states_req.effecter_id, + states_req.comp_effecter_count, + field, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n", + rc); + free(tx); + 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(tx); + if (rc) + prlog(PR_ERR, "Failed to send SetStateEffecter request, rc = %d\n", rc); + free(tx); + return rc; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: SetStateEffecter, rc: %d\n", rc); + free(tx); + 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(tx); + free(response_msg); + return OPAL_PARAMETER; + } + + free(tx); + free(response_msg); + return OPAL_SUCCESS; +} + struct get_pdr_response { uint8_t completion_code; uint32_t next_record_hndl; From patchwork Tue Jun 20 15:00:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797390 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=Fi3nWwxp; 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 4Qlqbz15Stz20Wk for ; Wed, 21 Jun 2023 01:02:07 +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=Fi3nWwxp; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqbz02wDz3cH4 for ; Wed, 21 Jun 2023 01:02:07 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Fi3nWwxp; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ41qpTz30fq for ; Wed, 21 Jun 2023 01:00:27 +1000 (AEST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEpMPc023427 for ; Tue, 20 Jun 2023 15:00:25 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=fIWbt2RZwxkPQLZuhmf1fLmVpv/x/+ytqcEaC7FnbPg=; b=Fi3nWwxpJ/P4A8Id4DdWEgroOvG6OtGDOl0ih5heOdC9nRpsH8r7qJRO8GOlEEG39wQb 6zBjqEV/ChzgSN17ddgXTi8NaNx+IsRLuOcIxW02HPGnGnmx7DFinU+QoSHxrjOVVP7u Ik87LEw9i0hs0g5+Ik7cvNJBBGgweQeaJ9h1OF4bY+NQ9vHYB4aqlF769CXaGYCP8vW1 yCR+9wn6hSCYadXnEoe7Sb3Y9GfbsGNtziO31Kwi8cSb9ApbAhmABnbHF/IBO987HFM9 fr5XMUUUbjhUMH3GtLjzFH3eOLB48T+jGlX9pkQD0D5GDUIn9qvVw5y7Ju0ZZhefpnUz yw== 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 3rbe81r756-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:25 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K2dV6a006831 for ; Tue, 20 Jun 2023 15:00:22 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r94f524r8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Kiu48038344 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5CB9020043 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F04220040 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:08 +0200 Message-ID: <20230620150017.88663-13-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PRHY3PsnBK8xV6c4CWsUk2oVR9X0wu_J X-Proofpoint-GUID: PRHY3PsnBK8xV6c4CWsUk2oVR9X0wu_J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 phishscore=0 malwarescore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- 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 5bbdd012..632f7fe5 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -44,6 +44,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; }; @@ -126,6 +169,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 617287fe..6d86cd10 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -21,4 +21,9 @@ int pldm_mctp_init(void); */ void pldm_mctp_exit(void); +/** + * Send a system firmware Graceful Restart request + */ +int pldm_platform_restart(void); + #endif /* __PLDM_H__ */ From patchwork Tue Jun 20 15:00:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797384 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=olxFB5qP; 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 4QlqZx3wJYz20Wk for ; Wed, 21 Jun 2023 01:01:13 +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=olxFB5qP; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqZx2k5Lz3c1y for ; Wed, 21 Jun 2023 01:01:13 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=olxFB5qP; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ346zhz30Q4 for ; Wed, 21 Jun 2023 01:00:27 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEqXou016119 for ; Tue, 20 Jun 2023 15:00:25 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=aDGpeHRa0NBDF4EtrDul8/Td+i0BhVAdqomGoAmwUnU=; b=olxFB5qPrfMWIknX6xT+uHMQuEGx6PmPNVIg4bI4179cT+pYzy1A7f/1ZyB6/UXsiNcW 9VOin5MwEFH/RUxdJ4dkvTW6GTk5hp468JyXUYrZPAIVN09nDVCYvuxBsZyocrvuCXWK UftQQHuigFfgJxZXxoqlV9d1kVXwVgvchOWi3Z1Xsw4eWC/5Za/DTkmv9kRa/+oM9hiD I0QbuNwxB10zVNbcBQVWrpAYjACgMJBcfcOh6r9G1PLiCCnXdQnGvThKzO6DNK630KwH RbQbvVqhjttrBixmTUESZvMskitJ31Zl7itIhdahIc7SQsd2eDVsJzwZQgK/qODLBbeu tA== 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 3rbe8u85ra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35KDSF2Z002627 for ; Tue, 20 Jun 2023 15:00:23 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3r94f51m6y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:22 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0KuU48038346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87E2320040 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 697F42004D for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:09 +0200 Message-ID: <20230620150017.88663-14-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9iZvfFYMWvXXkzmRgV1ctQmfkIc4n3Es X-Proofpoint-GUID: 9iZvfFYMWvXXkzmRgV1ctQmfkIc4n3Es X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- 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 632f7fe5..c2b113c5 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -169,6 +169,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 6d86cd10..55a4e149 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -21,6 +21,11 @@ int pldm_mctp_init(void); */ 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 Jun 20 15:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797388 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=F85Efn0B; 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 4Qlqbd38KYz20Wk for ; Wed, 21 Jun 2023 01:01:49 +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=F85Efn0B; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqbd23Vfz3cBN for ; Wed, 21 Jun 2023 01:01:49 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=F85Efn0B; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ36WTLz30fM for ; Wed, 21 Jun 2023 01:00:27 +1000 (AEST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEpKim023367 for ; Tue, 20 Jun 2023 15:00:25 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=klcha6GkERr/pnm7kfkLm0k8JEr65cRvBzDmUBBgNTU=; b=F85Efn0B7+3zUZBEUnGbfyY3QIzYjcLfXD1cH7JWtKT/AJCaC3hpJs+0ZkMgUsKkyHVg hTsY5PwfqwtQ6rc9xE2JOhVpZ1aykHjDY80ez+NOOXTwLxMUH3SPivrUrdS+0mr2w999 Nk+7bNC0n6sXhqzX/NzugLmW+AF2h6KioqBGrwEp4kmefidNBsgaIXz9oLHmJ0bzh+yw LGWFNG0zWL7WbEOCZb/Hac23bGazswTm+n7Ofu/HPjWXknjJm/QVMYR9trBx6vt+CnGD xcE+7MpxDbbKtTlubE+xyhJ0N3JF7YApjEySQNKIuoJ6agXdSxMCVuf5yz9M3MC1AKjI fg== 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 3rbe81r75j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35KE6PKi022242 for ; Tue, 20 Jun 2023 15:00:23 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3r94f51m34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0KpT48038348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:20 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B889C20043 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95AAA2004E for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:10 +0200 Message-ID: <20230620150017.88663-15-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: tdAw6RuwzNWgkyCLyjPkwK_DNWpkJxun X-Proofpoint-GUID: tdAw6RuwzNWgkyCLyjPkwK_DNWpkJxun X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 phishscore=0 malwarescore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- core/pldm/Makefile.inc | 1 + core/pldm/pldm-bios-requests.c | 222 +++++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 4 +- core/pldm/pldm.h | 2 + 4 files changed, 228 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 933b0c61..e4135ac9 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -9,6 +9,7 @@ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ 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..0fa198a2 --- /dev/null +++ b/core/pldm/pldm-bios-requests.c @@ -0,0 +1,222 @@ +// 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) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_bios_table_req); + size_t response_len, payload_len, bios_table_offset; + uint8_t completion_code, transfer_flag; + struct pldm_tx_data *tx = NULL; + uint32_t next_transfer_handle; + int rc = OPAL_SUCCESS; + void *response_msg; + + 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 */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + 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 *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetBIOSTableReq Error, type: %d, rc: %d\n", + table_type, rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetBIOSTableReq, rc: %d\n", rc); + free(tx); + 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); + rc = OPAL_PARAMETER; + goto out; + } + + /* 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 - bios_table_offset; + *bios_table = zalloc(*bios_length); + if (!bios_table) { + prlog(PR_ERR, "failed to allocate bios table (size: 0x%lx)\n", + *bios_length); + rc = OPAL_NO_MEM; + goto out; + } + + memcpy(*bios_table, + ((struct pldm_msg *)response_msg)->payload + bios_table_offset, + *bios_length); + +out: + free(tx); + free(response_msg); + return rc; +} + +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 a07d9503..6003b66c 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -74,7 +74,7 @@ out: int pldm_mctp_init(void) { - int nbr_elt = 5, rc = OPAL_SUCCESS; + int nbr_elt = 6, rc = OPAL_SUCCESS; int (*pldm_config[])(void) = { ast_mctp_init, /* MCTP Binding */ @@ -82,6 +82,7 @@ int pldm_mctp_init(void) pldm_requester_init, /* Requester implementation */ pldm_base_get_tid_req, /* Get BMC tid */ pldm_platform_init, /* Get PDRs data */ + pldm_bios_init, /* Get Bios data */ }; const char *pldm_config_error[] = { @@ -90,6 +91,7 @@ int pldm_mctp_init(void) "Failed to configure requister", "Failed to retrieve BMC Tid", "Failed to retrieve Data Records", + "Failed to retrieve Bios data", }; prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 6044ad02..014e75f3 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -51,6 +51,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 Jun 20 15:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797389 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=rH4ZQ8e0; 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 4Qlqbp3W8gz20Wk for ; Wed, 21 Jun 2023 01:01:58 +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=rH4ZQ8e0; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqbp2LP4z3cCC for ; Wed, 21 Jun 2023 01:01:58 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=rH4ZQ8e0; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ40KfKz30MS for ; Wed, 21 Jun 2023 01:00:27 +1000 (AEST) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEpO8m023502 for ; Tue, 20 Jun 2023 15:00:26 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=sM+zAUmx7kVZZbY0H1zToWCVpe4mzTxIN8U5PZidp1E=; b=rH4ZQ8e0ebWCMv3+ggvKVtiXnOFrEXwcp/y9dpP2KtUtsDCbgvw1r4zfCL12tg0tdl+P wC70RKuW3g6ZD7O4hSjTu7fPwJBHadyk9xy7OMAZnI0CQNodlMtBfqAny7bbskZqeURe dVN3OlGve3ZnkxQli5ShYtUtN1vAZVR6Koox5qu/qDZ2yCrcuuYId10XTRypQRjwOAjL UVxE/X00xwPfqsmfcQLVRIxpwF6TslSyibu0O44u3V3ylyzwuwThpypYCCOsDpVgJZ16 fImODuk6mOiRsLMfrMpjOCfUcOIvMmvYRNS5hZXdx8MGc0oudXpygqtFd0RYCN/vT9m6 og== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3rbe81r75p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:25 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K9tWmX005771 for ; Tue, 20 Jun 2023 15:00:23 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3r94f59mms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0L0q48038350 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E37BB20043 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C58DA20040 for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:11 +0200 Message-ID: <20230620150017.88663-16-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: CsQxj4R0Xu9rjlChAJBqohQ6qMGf40Ja X-Proofpoint-GUID: CsQxj4R0Xu9rjlChAJBqohQ6qMGf40Ja X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 clxscore=1015 suspectscore=0 phishscore=0 malwarescore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-bios-requests.c | 148 +++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 3 + 2 files changed, 151 insertions(+) diff --git a/core/pldm/pldm-bios-requests.c b/core/pldm/pldm-bios-requests.c index 0fa198a2..d3aeb188 100644 --- a/core/pldm/pldm-bios-requests.c +++ b/core/pldm/pldm-bios-requests.c @@ -84,6 +84,154 @@ 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 != '\0')) + p++; + + attr_end = p; + *attr_end = '\0'; + + if (!strncmp(attr, name, strlen(name)) && + (strlen(attr) == strlen(name))) { + *lid = strdup(++p); + 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_HARDWARE; + + /* 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 014e75f3..0ed806c9 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -7,6 +7,7 @@ #include #include +#include #include #define PLDM_MSG_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) @@ -51,6 +52,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 Jun 20 15:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797392 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=EMyADyxv; 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 4QlqcJ581Jz20Wk for ; Wed, 21 Jun 2023 01:02: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=EMyADyxv; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqcJ40N2z3cNV for ; Wed, 21 Jun 2023 01:02:24 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=EMyADyxv; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ449dhz30dx for ; Wed, 21 Jun 2023 01:00:28 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEqVvf016064 for ; Tue, 20 Jun 2023 15:00:26 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=CSteZGejtuyNgKTER+4L41IipgFzX/bzN3kXRAnnk98=; b=EMyADyxvlY2SA+zYGQwNCpGEzvZ11CQISFaQGZPav6fNWqiSl+AAWWh37QozC9aR76Rx 2UX4+Fw329/JOaJJDpruP9yXbg+9ce+I3AHy3IjMsaturpmlPSqWRGDDuzt+QWVhMF00 RLJGSGYgkWnW2nr76lXbybnb9b7QLbJ4+GfCT8Duf1nGfqgUDg8FWkRlZyMFJIGgPI1x tkK+wWsk7kzQ+6Lb+qUsyqDUpp/TMs3U0PVlgZKF6ZqZdTa7z+HQR1zO5ZeAQaToNEb2 eBLdkPSJYt/ayJspWDwhoKT7gRqurzH5WoeX4DEudWE1PhU/tThiYJ7DKU9mHYDUXjw5 UQ== 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 3rbe8u85rq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:25 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35JLMWXM030172 for ; Tue, 20 Jun 2023 15:00:23 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3r94f5a51e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0L3q35979644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B08F20040 for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F10742004B for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:20 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:12 +0200 Message-ID: <20230620150017.88663-17-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Kr9H1PAH0ezWcTsP_ZCxyQ_j8W9rzKCQ X-Proofpoint-GUID: Kr9H1PAH0ezWcTsP_ZCxyQ_j8W9rzKCQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-fru-requests.c | 147 ++++++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 4 +- core/pldm/pldm.h | 2 + 4 files changed, 153 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 e4135ac9..0b54b7e3 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -9,7 +9,7 @@ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ 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..ae1d9fac --- /dev/null +++ b/core/pldm/pldm-fru-requests.c @@ -0,0 +1,147 @@ +// 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) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_fru_record_table_req); + uint8_t transfer_flag, completion_code; + size_t response_len, payload_len; + struct pldm_tx_data *tx = NULL; + uint32_t next_transfer_handle; + uint8_t *table_data; + size_t table_length; + void *response_msg; + int rc = OPAL_SUCCESS; + + 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 */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + 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 *)tx->data, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordTableReq Error, rc: %d\n", rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFruRecordTableReq, rc: %d\n", rc); + free(tx); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + table_data = zalloc(payload_len); + if (!table_data) { + free(tx); + return OPAL_NO_MEM; + } + + 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); + rc = OPAL_PARAMETER; + goto out; + } + + /* 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); + rc = OPAL_PARAMETER; + goto out; + } + + *record_table_length = table_length; + *record_table_data = zalloc(table_length); + if (!record_table_data) + rc = OPAL_NO_MEM; + else + memcpy(*record_table_data, table_data, table_length); + +out: + free(tx); + free(table_data); + free(response_msg); + return rc; +} + +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 6003b66c..b31587f6 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -74,7 +74,7 @@ out: int pldm_mctp_init(void) { - int nbr_elt = 6, rc = OPAL_SUCCESS; + int nbr_elt = 7, rc = OPAL_SUCCESS; int (*pldm_config[])(void) = { ast_mctp_init, /* MCTP Binding */ @@ -83,6 +83,7 @@ int pldm_mctp_init(void) pldm_base_get_tid_req, /* Get BMC tid */ pldm_platform_init, /* Get PDRs data */ pldm_bios_init, /* Get Bios data */ + pldm_fru_init, /* Get Fru data */ }; const char *pldm_config_error[] = { @@ -92,6 +93,7 @@ int pldm_mctp_init(void) "Failed to retrieve BMC Tid", "Failed to retrieve Data Records", "Failed to retrieve Bios data", + "Failed to retrieve Fru data", }; prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 0ed806c9..1f03b1c5 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_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 Jun 20 15:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797393 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=QwK5KoUl; 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 4QlqcT6fqyz20Wk for ; Wed, 21 Jun 2023 01:02:33 +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=QwK5KoUl; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqcT3dF4z3cPF for ; Wed, 21 Jun 2023 01:02:33 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=QwK5KoUl; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ45VGDz30gw for ; Wed, 21 Jun 2023 01:00:28 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEqakd016475 for ; Tue, 20 Jun 2023 15:00:26 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=RuSpVtvP0sFN9KMja7eRXsV+f+DWDEohf0wBOwLz7l4=; b=QwK5KoUlZl3fU6/7esEwy8f3LzH0hTIb0kNIXOn/WvgfY3o4MKhsFL3GXtPqU5KXmmJc mR9S69CX/5PadzgZSxGxANDMI0IWZGV7dvpB2vXPEgL4j709MvGXq4THO+LVFM8TbtP2 ec4TVLSdzkgirdHGD8NRmFYQRZyKnuUsk3fZ6wZ79zWAN37629hUicvd8xmFE48f77Zj Toz2cFV9RUjIpGJ5Rb2t20GrgqT9D5JD8kOG5BGbMsLxTq2csLYrI/ZhBl2lP+QlFfNx teEfKWfWEgyuHU5azqsPwzxJvZ03/SjmVxztU9FvRFOfkERpTIuBKto5LVbZcy8nWTZQ 9w== 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 3rbe8u85s1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:25 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K77qJp019488 for ; Tue, 20 Jun 2023 15:00:24 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3r94f59m6v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0LBY35979646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 464012004B for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 284A220043 for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:13 +0200 Message-ID: <20230620150017.88663-18-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: SBWWYpRV1mJkDYEItbdWHx2Q6E655XyK X-Proofpoint-GUID: SBWWYpRV1mJkDYEItbdWHx2Q6E655XyK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-fru-requests.c | 85 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 1 + include/pldm.h | 5 +++ 3 files changed, 91 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index ae1d9fac..ce78374e 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; static void fru_init_complete(bool success) { @@ -33,6 +34,22 @@ static void fru_init_complete(bool success) fru_ready = true; } +int pldm_fru_get_bmc_version(void *bv, int len) +{ + if (bv == NULL) + return OPAL_PARAMETER; + + if (bmc_version == NULL) + return OPAL_PARAMETER; + + if ((len + 1) > strlen(bmc_version)) + return OPAL_PARAMETER; + + 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) { @@ -126,6 +143,74 @@ out: return rc; } +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; + int rc = OPAL_SUCCESS; + size_t record_size; + + if (!fru_ready) + return OPAL_HARDWARE; + + if (!fru_record_table) + return OPAL_HARDWARE; + + dt_fw_version = dt_find_by_name(dt_root, "ibm,firmware-versions"); + if (!dt_fw_version) + return OPAL_HARDWARE; + + /* 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); + if (!record_table) + return OPAL_NO_MEM; + + record_size = fru_record_length; + get_fru_record_by_option( + fru_record_table, + fru_record_length, + record_table, + &record_size, + 1, + PLDM_FRU_RECORD_TYPE_GENERAL, + PLDM_FRU_FIELD_TYPE_VERSION); + + if (record_size == 0) { + prlog(PR_ERR, "%s - no FRU type version found\n", __func__); + rc = OPAL_PARAMETER; + goto out; + } + + /* 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); + if (!bmc_version) + rc = OPAL_NO_MEM; + else + memcpy(bmc_version, tlv->value, tlv->length); + +out: + free(record_table); + return rc; +} + int pldm_fru_init(void) { int rc; diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 1f03b1c5..f9968a63 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,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 len); 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 55a4e149..3c23dc97 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -31,4 +31,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 Jun 20 15:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797394 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=VrfSeh2B; 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 4Qlqcf4ZYrz20Wk for ; Wed, 21 Jun 2023 01:02:42 +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=VrfSeh2B; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqcf3TZmz3cRg for ; Wed, 21 Jun 2023 01:02:42 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=VrfSeh2B; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4QlqZ46J1Bz30h2 for ; Wed, 21 Jun 2023 01:00:28 +1000 (AEST) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEruZh002504 for ; Tue, 20 Jun 2023 15:00:27 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=tzmgPyTITlhp4rxZejuAyK/Io941Cl8fkEvLQn0xy5M=; b=VrfSeh2Bx95l0MyL7X9L0jlFFx8JCLvRtrYXd4QY8FGR6N+CAbO8pJRZmv2Kqlgs2ocA eROzrc4Q64LR1Vb1iHSHhMdqgd/LQ9D51bH3hNbhVWin5K+sD1afBCzSUeoo3L2CXzYU TCANSoBeQLF6v113EKn0Y50NFPyTElQzB4iX8Wjpfp6LcRRJSZon8ZJNrS3+LeMTOOY2 GTYb9aah5+KGKDGjiMCADh1dbwwmkp9EbfvoLqa/VyXm2CHffFCw/J0yiaVVM+T028Mf zJOd+1qjBWM0QD9NkPd/2rh5ZytlM4x9J4VQf7kiCDfB4ldgM6yASsUUnNt5uK4CyC32 dg== 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 3rbe97g4pn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:26 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K40FZE031759 for ; Tue, 20 Jun 2023 15:00:24 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3r943e1mes-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Lsr21692964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 707EC2004D for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5305920040 for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:14 +0200 Message-ID: <20230620150017.88663-19-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: FVVct5obeq1UcZh99PoBHfp6k8DFO7aU X-Proofpoint-ORIG-GUID: FVVct5obeq1UcZh99PoBHfp6k8DFO7aU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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 --- core/pldm/Makefile.inc | 1 + core/pldm/pldm-file-io-requests.c | 156 ++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 4 +- core/pldm/pldm.h | 2 + 4 files changed, 162 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 0b54b7e3..d89e4c2f 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -10,6 +10,7 @@ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ 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..11251a30 --- /dev/null +++ b/core/pldm/pldm-file-io-requests.c @@ -0,0 +1,156 @@ +// 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) +{ + size_t data_size = PLDM_MSG_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; + struct pldm_tx_data *tx = NULL; + uint32_t next_transfer_handle; + void *response_msg; + int rc = OPAL_SUCCESS; + + 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 */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + 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 *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFileReq Error, rc: %d\n", rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFileReq, rc: %d\n", rc); + free(tx); + 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); + rc = OPAL_PARAMETER; + goto out; + } + + /* 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); + if (!file_attr_table) { + rc = OPAL_NO_MEM; + goto out; + } + + memcpy(file_attr_table, + ((struct pldm_msg *)response_msg)->payload + + file_table_data_start_offset, + file_attr_length); + +out: + free(tx); + free(response_msg); + return rc; +} + +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 b31587f6..fb7d8a1c 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -74,7 +74,7 @@ out: int pldm_mctp_init(void) { - int nbr_elt = 7, rc = OPAL_SUCCESS; + int nbr_elt = 8, rc = OPAL_SUCCESS; int (*pldm_config[])(void) = { ast_mctp_init, /* MCTP Binding */ @@ -84,6 +84,7 @@ int pldm_mctp_init(void) pldm_platform_init, /* Get PDRs data */ pldm_bios_init, /* Get Bios data */ pldm_fru_init, /* Get Fru data */ + pldm_file_io_init, /* Get FILE IO data */ }; const char *pldm_config_error[] = { @@ -94,6 +95,7 @@ int pldm_mctp_init(void) "Failed to retrieve Data Records", "Failed to retrieve Bios data", "Failed to retrieve Fru data", + "Failed to retrieve File io data", }; prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index f9968a63..86023e72 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_file_io_init(void); + int pldm_fru_get_bmc_version(void *bv, int len); int pldm_fru_init(void); From patchwork Tue Jun 20 15:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797397 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=AgFb7ICv; 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 4Qlqd93tRkz20Wk for ; Wed, 21 Jun 2023 01:03: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=AgFb7ICv; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqd92lX8z3cW4 for ; Wed, 21 Jun 2023 01:03:09 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=AgFb7ICv; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4QlqZ54HTcz30hB for ; Wed, 21 Jun 2023 01:00:29 +1000 (AEST) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEo2AV030359 for ; Tue, 20 Jun 2023 15:00:27 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=oA4IGiK/TZ9spPm3YN4uf2uUnWJv8wWXC8ywK9/eWCY=; b=AgFb7ICvHmYn9L7RZuhZkvtNgClOl7o28DgMkoBGnyzF+yNf4St3mBG2VeY0D78/aMh1 8DsSoHGU11KPjqZ1rtbjvF6qLhGDX834i5t4/N0+Ocn+FB4Royf1da63dj4Hx6G5/S3w +aGoozHypGV62riVNlbwzrhzciTD2n2l3rgmLTRdrmYqh7d7KWvUH58C18MgVgzC4A4C 3coVrh+8PwIRdq1Jfppny34nI8+wtd5SCLvw6BAlmraCVzu40HfG8Mb11WpJLS5BUQ7X FwzxPRTBG5mkLATlqLeJmLL/xb5RIK+GN0u4JFCzpmS5X+cLldokrYzhpMJLOgsDe7l7 Jw== 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 3rbe7bg8h0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:26 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K2uqvb021786 for ; Tue, 20 Jun 2023 15:00:24 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r94f524ra-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0LfK35979648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C33520040 for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7DEAE2004E for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:15 +0200 Message-ID: <20230620150017.88663-20-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: teRwI6bebngh7upWio8dW2VmXivBgXgp X-Proofpoint-ORIG-GUID: teRwI6bebngh7upWio8dW2VmXivBgXgp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 19/21] core/pldm: Add file io read request X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Send/receive a PLDM ReadFile request message. Due to maximum transfer size for PLDM protocol, we have to send several read requests, if necessary. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 134 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 136 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 11251a30..3a68966d 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,139 @@ 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) + +/* + * Send/receive a PLDM ReadFile request message. + */ +static int read_file_req(uint32_t file_handle, uint32_t file_length, + uint32_t pos, void *buf, uint64_t len) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_read_file_req); + size_t response_len, payload_len, file_data_offset; + uint8_t completion_code; + struct pldm_tx_data *tx; + uint32_t resp_length; + uint64_t total_read; + void *response_msg; + int num_transfers; + void *curr_buf; + int rc, i; + + struct pldm_read_file_req file_req = { + .file_handle = file_handle, + .offset = pos, + .length = len + }; + + if (!file_length) + return OPAL_PARAMETER; + + if ((!len) || ((len + pos) > 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, len: 0x%llx num_transfers: %d\n", + __func__, file_handle, file_req.offset, + len, num_transfers); + + /* init request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + for (i = 0; i < num_transfers; i++) { + file_req.offset = pos + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_read_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode ReadFileReq Error, rc: %d\n", + rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: ReadFileReq, rc: %d\n", rc); + free(tx); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_read_file_resp( + response_msg, + payload_len, + &completion_code, + &resp_length, + &file_data_offset); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode ReadFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(tx); + free(response_msg); + return OPAL_PARAMETER; + } + + if (resp_length == 0) { + free(response_msg); + break; + } + + memcpy(curr_buf, + ((struct pldm_msg *)response_msg)->payload + file_data_offset, + resp_length); + + total_read += resp_length; + curr_buf += resp_length; + free(response_msg); + + prlog(PR_TRACE, "%s - file_handle: %d, resp_length: 0x%x, total_read: 0x%llx\n", + __func__, file_handle, resp_length, total_read); + + if (total_read >= len) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (len - total_read)) + file_req.length = len - total_read; + } + + free(tx); + return OPAL_SUCCESS; +} + +int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, + uint32_t pos, void *buf, uint64_t len) +{ + if (!file_io_ready) + return OPAL_HARDWARE; + + return read_file_req(file_handle, file_length, pos, buf, len); +} + /* * 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 86023e72..51b1fd6d 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, + uint32_t pos, void *buf, uint64_t len); int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv, int len); From patchwork Tue Jun 20 15:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797399 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=BTDScHY+; 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 4QlqdX1DNsz20Wk for ; Wed, 21 Jun 2023 01:03:28 +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=BTDScHY+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QlqdX0857z3cXx for ; Wed, 21 Jun 2023 01:03:28 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=BTDScHY+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4QlqZ70Nskz30fy for ; Wed, 21 Jun 2023 01:00:30 +1000 (AEST) Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEglkP031931 for ; Tue, 20 Jun 2023 15:00:29 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=oyMhFgq3TBq+E6/iRfvxB0af4qiuyJEyOGJzwmAWFsA=; b=BTDScHY+O4rfxcuFphic+zLnepNYrgMKWZyhHXeA2Lk4ZksYsbfmSpyUezQnIE3czwE4 cBAMBpVoWKr/BLLgef3wtrxeoseneS3kFDiE+zET9flKhZbpwKOGxSkJyT+ClKBuQY+Q fkSekFc6odsKSZnUQZ0MhZ5WyguXdoNEOS/0+BfZW5Annzv508shsGAonXxHlcfOkiu1 FpLypeqO+yRspyT6nVXotlmAk0RLGXMJ5va+gKd/Fl5oQnWC8E18uatCuTxIDBykeUsO 4KdjNOXf3Pg7AHqPl1RtR/NYxd/pwoN8OapOmpFad4SQrJKUiz1WSTOM9m47ibvj8RAn qw== 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 3rbe410gjh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:27 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35KBrt1T027265 for ; Tue, 20 Jun 2023 15:00:25 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3r94f51m70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:25 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0L8x35979650 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C79CB20040 for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9A3A2004B for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:16 +0200 Message-ID: <20230620150017.88663-21-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: IVuw8KiQa0fzHdHZlvlY5dMXjStnLPni X-Proofpoint-ORIG-GUID: IVuw8KiQa0fzHdHZlvlY5dMXjStnLPni X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 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. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 126 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 128 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 3a68966d..95f69e4f 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -167,6 +167,132 @@ int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, return read_file_req(file_handle, file_length, pos, buf, len); } +/* + * Send/receive a PLDM WriteFile request message. + */ +static int write_file_req(uint32_t file_handle, uint32_t pos, + const void *buf, uint64_t len) +{ + 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; + struct pldm_tx_data *tx; + int num_transfers; + int rc, i; + + struct pldm_write_file_req file_req = { + .file_handle = file_handle, + .offset = pos, + .length = len, + }; + + if (!len) + return OPAL_PARAMETER; + + if ((pos) && (pos > len)) + return OPAL_PARAMETER; + + /* init request */ + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_write_file_req) + + len; + + tx = zalloc(sizeof(struct pldm_tx_data) + request_length); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = request_length - 1; + + payload_data = ((struct pldm_msg *)tx->data)->payload + + offsetof(struct pldm_write_file_req, file_data); + + memcpy(payload_data, buf, len); + current_ptr = payload_data; + num_transfers = 1; + total_write = 0; + + if (len > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (len + 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, len: 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 = pos + (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 *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode WriteFileReq Error, rc: %d\n", rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, + &response_msg, + &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: WriteFileReq, rc: %d\n", rc); + free(tx); + 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(tx); + 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 == len) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (len - total_write)) + file_req.length = len - total_write; + } + + free(tx); + return OPAL_SUCCESS; +} + +int pldm_file_io_write_file(uint32_t file_handle, uint32_t pos, + const void *buf, uint64_t len) +{ + if (!file_io_ready) + return OPAL_HARDWARE; + + return write_file_req(file_handle, pos, buf, len); +} + /* * 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 51b1fd6d..08e7a3c2 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -54,6 +54,8 @@ int pldm_responder_init(void); /* Requester support */ int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, uint32_t pos, void *buf, uint64_t len); +int pldm_file_io_write_file(uint32_t file_handle, uint32_t pos, + const void *buf, uint64_t len); int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv, int len); From patchwork Tue Jun 20 15:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1797396 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=q6TelLDC; 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 4Qlqd04w4Lz20Wk for ; Wed, 21 Jun 2023 01:03: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=q6TelLDC; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Qlqd03nZjz3cV9 for ; Wed, 21 Jun 2023 01:03:00 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=q6TelLDC; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QlqZ52rLMz30hY for ; Wed, 21 Jun 2023 01:00:29 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35KEwTSk010631 for ; Tue, 20 Jun 2023 15:00:27 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=v5r8AEWM8olA0gwDIMOwhSk2yno02u4/rWt4EcRcB8M=; b=q6TelLDCJDSWHgAxcDzmaQFGgbRtMON4JOMU0LGZ9iv3fMb+8Y0Fc60TUAPEmytLucl/ UyrbI8aHk4le3O6J85Ep3nsagy8EpL1Ng+sahrno2dhq8n3xgVfdJAS0W+XQOGgYDhA5 UQDHLFyJuCcaB1SzhDer8Jmi9o/QHFn76vXsFvbbRSRNUoh+p/pDTViKeoLqpu+xTXdX dEp6/feduYJ7gUR6BUoK2kPphtdzu74WCx2XM717ZM7fKVngqvWTE0vNHeA6mhPP8wal 1k0Bhfa7zBwZ5YGznVZPGicQiXavUoDhzOAdd+Tos8ZpsjeZqJQ2mtjMaSE/35IbD4HV 3w== 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 3rbe82r89s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:26 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 35K0xpQA024815 for ; Tue, 20 Jun 2023 15:00:24 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r94f524rb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 20 Jun 2023 15:00:24 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35KF0Mvn35979652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 Jun 2023 15:00:22 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F35E820040 for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D52832004E for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.biot.fr.ibm.com (unknown [9.144.62.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 20 Jun 2023 15:00:21 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 20 Jun 2023 17:00:17 +0200 Message-ID: <20230620150017.88663-22-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620150017.88663-1-clombard@linux.ibm.com> References: <20230620150017.88663-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vcHOm1ABza7bXzdER6xqGpdtVq5iqByQ X-Proofpoint-ORIG-GUID: vcHOm1ABza7bXzdER6xqGpdtVq5iqByQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-20_10,2023-06-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306200131 Subject: [Skiboot] [PATCH V8 21/21] core/pldm: Get file handle and file length X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Retrieve the file handle and file length based on attribute name. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 76 +++++++++++++++++++++++++++++++ core/pldm/pldm.h | 3 ++ 2 files changed, 79 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 95f69e4f..7f3cf70a 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -34,6 +34,82 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +#define CHKSUM_PADDING 8 + +/* + * Retrieve the file handle and file length from the file attribute + * table. + */ +static int find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + const struct pldm_file_attr_table_entry *file_entry; + char *startptr, *endptr; + uint16_t file_name_length; + + if ((file_attr_table == NULL) || (file_attr_length == 0)) + return OPAL_HARDWARE; + + startptr = (char *)file_attr_table; + endptr = startptr + file_attr_length - CHKSUM_PADDING; + *file_handle = 0; + *file_length = 0; + + while (startptr < endptr) { + /* file entry: + * 4 Bytes: file handle + * 2 Bytes: file name length + * Bytes: file name + * 4 Bytes: file length + */ + file_entry = (struct pldm_file_attr_table_entry *)startptr; + + *file_handle = le32_to_cpu(file_entry->file_handle); + startptr += sizeof(uint32_t); + + file_name_length = le16_to_cpu(file_entry->file_name_length); + startptr += sizeof(file_name_length); + + if (!strncmp(startptr, lid_id, strlen(lid_id))) { + startptr += file_name_length; + *file_length = le32_to_cpu(*(uint32_t *)startptr); + break; + } + startptr += file_name_length; + startptr += sizeof(uint32_t); + startptr += sizeof(bitfield32_t); + } + + if (*file_length == 0) { + prlog(PR_ERR, "%s - lid_id: %s, no file handle found\n", + __func__, lid_id); + *file_handle = 0xff; + *file_length = 0; + return OPAL_PARAMETER; + } + + prlog(PR_DEBUG, "%s - lid_id: %s, file_handle: %d, file_length: %d\n", + __func__, lid_id, *file_handle, *file_length); + + return OPAL_SUCCESS; +} + +/* + * Retrieve the file handle and file length based on lid id. + */ +int pldm_find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + if (!file_io_ready) + return OPAL_HARDWARE; + + return find_file_handle_by_lid_id(lid_id, + file_handle, + file_length); +} + /* maximum currently transfer size for PLDM */ #define KILOBYTE 1024ul #define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE) diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 08e7a3c2..2fbd6d32 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,9 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length); int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, uint32_t pos, void *buf, uint64_t len); int pldm_file_io_write_file(uint32_t file_handle, uint32_t pos,