From patchwork Thu May 11 16:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780168 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=kG5oHNw8; 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 4QHHMY297Fz213w for ; Fri, 12 May 2023 02:26:17 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHMY13RWz3fY8 for ; Fri, 12 May 2023 02:26:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=kG5oHNw8; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=kG5oHNw8; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHKy3tsQz3fLj for ; Fri, 12 May 2023 02:24:54 +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 34BGABSS006749 for ; Thu, 11 May 2023 16:24:52 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=kG5oHNw865C5huRbm9vGVSzHYDiZkWNwvf07R7SfH6/8haAyshahvXnQC650bGi1TujW myPLFnoeDoqn1DUJukY0aSNa/pWUov+VkYlDL2JX5zlJXx9WVW4WEmwrM4vJNqKuKYWD f/i1M2jx/mCS9kyF6YVyQ7ymv9tUsQaDB1V6CdMbyX8W+OOwix0ZGy35vsOiKCjNuGwi asoABO33BCbOw7kpQ+iUB6KpTTJb+PiDqVgY9hNZ6Wjg0tmhO8u9Yg+xHlbc6yN75dnn GO4RITDyuzUfJi9kxB0EYAAq8IJ9gU96UT8GwvGdkVemf7k6ifRRYw8dq5cYySBi3Y2f ww== 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 3qh2h2uaxn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:51 +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 34B3PafY026836 for ; Thu, 11 May 2023 16:24:49 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896suj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOlsm17695402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:47 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2121F2004B for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D912620040 for ; Thu, 11 May 2023 16:24:46 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:46 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:26 +0200 Message-Id: <20230511162446.10457-2-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3Q46XGmxrpLsR_oMMyGS4lO7Z8bGkooW X-Proofpoint-ORIG-GUID: 3Q46XGmxrpLsR_oMMyGS4lO7Z8bGkooW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 impostorscore=0 adultscore=0 priorityscore=1501 spamscore=0 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 Thu May 11 16:24:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780174 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=r1XVwdKs; 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 4QHHNY6CH2z213w for ; Fri, 12 May 2023 02:27:09 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHNY59Jvz3fc3 for ; Fri, 12 May 2023 02:27: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=r1XVwdKs; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=r1XVwdKs; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL05KHDz3fS8 for ; Fri, 12 May 2023 02:24:56 +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 34BGMgsO022836 for ; Thu, 11 May 2023 16:24:53 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=SUrApycou1Bz3Gpvoj6Ml5Yj7+W+DCQXHOwjEuVeMZg=; b=r1XVwdKsFuHxlBLwcRYwTx2+wY9iqRmDQO6j6qZm3ivr9NyZ6KJSnqQEJVQLEeyXpZLo S3byH4D4pOcnov0ou3T4vxflUS/nzmI1a49WGoROYNghjuasF+rT30pNZ+6HgchFylS0 rvzL11NGDzk/zO6Geq2v/fsqWeT6rsU6a6qQei6ue2gEsHFFjaL+9Y/VHiBEjBAiKr36 DYDkovw0aOk5eMALSYLzobYAjN0bepd7EkHWaZ87XGO082UZU0/jir3kWMDhH8tgI1ty Ff1uTmrL1llLjO98pb20kj8tKyy/6xv3Y9rlobH3gaueitps2tkkpj5Vn2v8NZw0yOxK Ww== 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 3qh3exgsdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:52 +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 34B98XJb006735 for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3qf7s8hgd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOlKX19333804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:47 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 934BA20043 for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43A4520040 for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:27 +0200 Message-Id: <20230511162446.10457-3-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _ig31lIKOUdDZzirT2xOCK5DkozZf5Mp X-Proofpoint-GUID: _ig31lIKOUdDZzirT2xOCK5DkozZf5Mp 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.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 adultscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 422 ++++++++++++++++++++++++++++++++++++++ include/ast.h | 20 ++ platforms/astbmc/common.c | 39 ++++ 4 files changed, 488 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..9a9e0484 --- /dev/null +++ b/hw/ast-bmc/ast-mctp.c @@ -0,0 +1,422 @@ +// 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 + +/* + * 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); + + prlog(PR_TRACE, "%s: 0x%hhx from %s\n", + __func__, *val, reg ? "status" : "data"); + + 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: + opal_del_poller(astlpc_poller); + 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) +{ + int rc; + + lock(&mctp_lock); + + rc = mctp_message_tx(mctp, BMC_EID, tag_owner, msg_tag, + msg, msg_len); + unlock(&mctp_lock); + + /* -------------- WORKAROUND -------------- */ + + /* From kcs_bmc_aspeed.c + * The ASPEED KCS devices don't provide a BMC-side interrupt for + * the host reading the output data register (ODR). The act of the + * host reading ODR clears the output buffer full (OBF) flag in the + * status register (STR), informing the BMC it can transmit a + * subsequent byte. + * On the BMC side the KCS client must enable the OBE event *and* + * perform a subsequent read of STR anyway to avoid races - the + * polling provides a window for the host to read ODR if data was + * freshly written while minimising BMC-side latency. + * + * Given we don't have an OBE IRQ, delay by polling briefly to see + * if we can observe such an event before returning to the caller. + * This is not incorrect because OBF may have already become clear + * before enabling the IRQ if we had one, under which circumstance + * no event will be propagated anyway. + * + * + * [ 261.510224532,7] PLDM: encode_and_queue_get_pdr_req - record_hndl: 0 + * [ 261.510314132,7] AST-MCTP: write KCS data 0x1 <= Tx begin + + * [147727.652282] misc raw-kcs3: Disabling IDR events for back-pressure + * [147727.652321] misc raw-kcs3: IDR read, waking waiters + * [147727.652383] misc raw-kcs3: Read status 0xc2 <= input buffer full + * [147727.652403] misc raw-kcs3: Waiting for IBF <= probably read Tx begin + * [147727.652413] misc raw-kcs3: Woken by IBF, enabling IRQ + * [147727.652440] misc raw-kcs3: Read status 0xc0 + * [147727.652456] misc raw-kcs3: Writing 0x2 to ODR <= Rx complete + * [147727.655276] misc raw-kcs3: Read status 0xc1 <= output buffer full, from poll() + + * [ 261.510376528,7] AST-MCTP: read KCS status 0xc2 <= input buffer full + * [ 262.001010946,7] AST-MCTP: read KCS status 0xc1 <= output buffer full + * [ 262.001067507,7] AST-MCTP: read KCS data 0x2 <= Rx complete + + * [147728.156473] misc raw-kcs3: ODR writable, waking waiters + * [147728.156583] misc raw-kcs3: Read status 0xc0 + * [147728.156608] misc raw-kcs3: Writing 0x1 to ODR + * [147728.156627] misc raw-kcs3: Read status 0xc1 + * [147728.160802] misc raw-kcs3: Disabling IDR events for back-pressure + + * [ 262.003679442,7] AST-MCTP: read KCS status 0xc1 <= output buffer full + * [ 262.003720291,7] AST-MCTP: read KCS data 0x1 <= Tx Begin + * [ 262.003779271,7] AST-MCTP: write KCS data 0x2 <= Tx Complete + + * [147728.160833] misc raw-kcs3: IDR read, waking waiters + * [147728.160848] misc raw-kcs3: ODR writable, waking waiters + * [147728.160989] misc raw-kcs3: Read status 0xc2 + + * [ 262.003822967,7] PLDM: get_pdr_req_complete - record_hndl: 0 + * [ 262.003941315,7] PLDM: get_pdr_req_complete - record_hndl: 0, next_record_hndl: 2, resp_cnt: 20 + */ + + /* To inform the BMC to transmit the data immediately, we must read, + * immediately after sending the request, the ODR register to clear the + * output buffer full (OBF) flag in the status register (STR). + * Otherwise the bmc will only be awakened during the interruption, ie + * every 500ms. + */ + + for (int i = 0; i < 300; i++) + mctp_astlpc_poll(astlpc); + + /* -------------- WORKAROUND -------------- */ + + 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"); + opal_del_poller(astlpc_poller); + mctp_destroy(mctp); + mctp = NULL; + + return OPAL_HARDWARE; +} + +void ast_mctp_exit(void) +{ + if (astlpc) { + opal_del_poller(astlpc_poller); + 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..50e3b932 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 83ef70ad..cba01000 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"); } +static void astbmc_fixup_dt_mctp(struct dt_node *lpc) +{ + struct dt_node *mctp; + char namebuf[32]; + + return; + + 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); +} + static void astbmc_fixup_dt_bt(struct dt_node *lpc) { struct dt_node *bt; @@ -404,6 +440,9 @@ static void astbmc_fixup_dt(void) /* BT is not in HB either */ astbmc_fixup_dt_bt(primary_lpc); + /* Fixup the MCTP, that might be missing from HB */ + astbmc_fixup_dt_mctp(primary_lpc); + /* The pel logging code needs a system-id property to work so make sure we have one. */ astbmc_fixup_dt_system_id(); From patchwork Thu May 11 16:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780169 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=bW5Rykgu; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHHMk4k7bz213w for ; Fri, 12 May 2023 02:26:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHMj6HQHz3fPy for ; Fri, 12 May 2023 02:26:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW5Rykgu; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW5Rykgu; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHKz58Y6z3cfT for ; Fri, 12 May 2023 02:24:55 +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 34BGNrQH026167 for ; Thu, 11 May 2023 16:24:53 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=wDgW3xK802zgGoqN34zDdj7hw+eG/1QfpKEbMXv1eD0=; b=bW5Rykgu1hs7n1uTaJ4FGoOFWUff3YQG0u8c7fSk6IBFs8j5iO+gRB5LGkn9rjqF8bu8 sz49H9B0JFYAVG6F6gjoYql3VQUk8zWl9wt61l4jI/SSTjrt7GgDEawFRTESHxO7Bqlz B9SLnMRfjH13mXahH/6+clG54fWDl9UlIz7YS53oSI/uq9fi9PzSQPrHOPs1/qU6WM6z 5wm27TbKDx2/DZDHsN9LcpxETxw+PKIDknHxqqgJfq51kQe45fTC8NBNU/zoo3O5gD2W XJ34788CUdrCRwDV307zz3rXrOlRDdNXewW5GpCV33/lsjUhVW73+1EyBjIxqnmrA5aF qA== 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 3qh3exgsdu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:52 +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 34B4w6T0010243 for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896suja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOmIe15467086 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F294520043 for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B55F620040 for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:28 +0200 Message-Id: <20230511162446.10457-4-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9ROOTQFU5ofIqa3qx5Ded8GSQjdmqHR3 X-Proofpoint-GUID: 9ROOTQFU5ofIqa3qx5Ded8GSQjdmqHR3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 adultscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 79 ++++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 44 +++++++++++++++++++++++ hw/ast-bmc/ast-mctp.c | 18 ++++++++++ include/pldm.h | 24 +++++++++++++ 6 files changed, 183 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..7be8e8ba --- /dev/null +++ b/core/pldm/pldm-mctp.c @@ -0,0 +1,79 @@ +// 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(false, 0, + &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 rc; + + prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); + + /* MCTP Binding */ + rc = ast_mctp_init(); + if (rc) + prlog(PR_ERR, "Failed to bind MCTP\n"); + + prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); + return rc; +} + +void pldm_mctp_exit(void) +{ + ast_mctp_exit(); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h new file mode 100644 index 00000000..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 9a9e0484..b78b8185 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 @@ -342,6 +343,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 Thu May 11 16:24:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780171 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=MYkSoveT; 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 4QHHN33DLyz213w for ; Fri, 12 May 2023 02:26:43 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHN31mVLz3fZK for ; Fri, 12 May 2023 02:26:43 +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=MYkSoveT; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MYkSoveT; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL01Wtrz3fW5 for ; Fri, 12 May 2023 02:24:56 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BGHado024802 for ; Thu, 11 May 2023 16:24:54 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=0LFbI/K0CEZNN2PvYalLWGklh73v8eahDvXHCJXeaw4=; b=MYkSoveTimud7RMpdOYeM4IOnSTflcNzZ8jlXXQ8SD6/Eam4gEtxSKXnnWHrpPq5GfUz +hl6Q6ZiwubcdDd6pb2W7UmD6yoQ/ZMn1AoQTjPNw2FbSjtkX/LeOovtRtlunJRtvvNI R+VUh7rEp7N2jY4Cc6cfnhmB/Hlbz3FNK9gTJYxwiPPqiGXgNfjTtbbGGQ7/KnzQF3Di I5itGPbErQYFOfLmNOxkUMLb/b1thhDU0JErHRt00uT+yM+mLhLFS272e8lfKrJugWDO Ny+msRlysorLlSUIJ0TlP6KIU/KBPBUqXwniu3AKYC5W/Y7UJe9DA5z6l3xQVY+LiYDa 3w== 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 3qh381hgy0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +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 34BBbXhJ031065 for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0sgem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOmVe17695406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 611BB20043 for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 20B8E20040 for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:29 +0200 Message-Id: <20230511162446.10457-5-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: zdoSzxdQRuk4-Oa6ofAwVyGm6diYtn2g X-Proofpoint-GUID: zdoSzxdQRuk4-Oa6ofAwVyGm6diYtn2g X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 21 ++++- core/pldm/pldm-responder.c | 152 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 ++ 4 files changed, 179 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 7be8e8ba..241fd956 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; @@ -66,9 +77,17 @@ int pldm_mctp_init(void) /* MCTP Binding */ rc = ast_mctp_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to bind MCTP\n"); + goto out; + } + + /* Register mandatory commands we'll respond to */ + rc = pldm_responder_init(); + if (rc) + prlog(PR_ERR, "Failed to register mandatory commands\n"); +out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); return rc; } diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c new file mode 100644 index 00000000..9a99a5a4 --- /dev/null +++ b/core/pldm/pldm-responder.c @@ -0,0 +1,152 @@ +// 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; + + 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 Thu May 11 16:24:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780172 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=JWQ/WjdS; 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 4QHHND1lkHz213w for ; Fri, 12 May 2023 02:26:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHND0dJcz3fbH for ; Fri, 12 May 2023 02:26:52 +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=JWQ/WjdS; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=JWQ/WjdS; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL01BVyz3fM8 for ; Fri, 12 May 2023 02:24:55 +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 34BGOGvt018615 for ; Thu, 11 May 2023 16:24:54 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=xdpeBo2t7Swbecm+z48GGufXQ5jFOHC3g8mO9AmXM60=; b=JWQ/WjdS4CtTklyuPH0IvERwoWR3nqRxPps+FlvOpVWnelKtJbXhGxJHXGq1jE4N+FsU I5wMh6YIJg6KC1uFCNouK2q8AJ4oz/7iSlQdzfhv982YWQoY+VsGDx4aj85oTYQ3rS19 gHGp5Ne9lxskqWlRY+WcLsDVeRLT2Jok97cZsub6uBAG5gHSSm8jmJyawtCDV6DEKRIz PAdb3S7Cm13VPn6cEnpLYPB4lwGEivJCBNKBnoFPewL4yYVrlw+se8DKuyYxAV04Q7r7 uTCSDphB4zjOPtcCOBMAiKMd8iUwESXzItZbR4ofZU84UJ6/4wzXPeZCTMKc7+mRVtOp Qg== 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 3qh3umg0a8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:53 +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 34BD8I4j026361 for ; Thu, 11 May 2023 16:24:51 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3qf7d1sghy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:51 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOmqi17695410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1B3620049 for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 836C920040 for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:30 +0200 Message-Id: <20230511162446.10457-6-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OnCYaT76YHwPpS0ByLnBCzhTgTH-nTIa X-Proofpoint-ORIG-GUID: OnCYaT76YHwPpS0ByLnBCzhTgTH-nTIa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 clxscore=1015 mlxlogscore=954 adultscore=0 impostorscore=0 spamscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 58 ++++++++++++++++++++++++++++++++++++++ include/ast.h | 6 ++++ 2 files changed, 64 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 9a99a5a4..76ef020a 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -103,6 +103,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 */ @@ -112,6 +123,52 @@ 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; + + 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; @@ -147,6 +204,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 50e3b932..e9c39c6d 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 Thu May 11 16:24:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780170 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=p5bnuLMl; 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 4QHHMt4yVJz213w for ; Fri, 12 May 2023 02:26:34 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHMt3wCXz3fNL for ; Fri, 12 May 2023 02:26:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=p5bnuLMl; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=p5bnuLMl; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL007vRz3fS8 for ; Fri, 12 May 2023 02:24:55 +1000 (AEST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BFchkN002032 for ; Thu, 11 May 2023 16:24:54 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=Pm4ax0lPF7aHwj2f0BEWteqmVCS/HR4BsOz8mjNXhHE=; b=p5bnuLMlfvDwpW+v7bshUyH5BkV8N0ZRvI8g9LK8mjGqbaWEUd031XvMDPfDxgblb4Ua zKrm7lxywqTYGCg6eIUed/r3s9FdeEsjL9V50XahXmECO9yF+sXHoxCIBBNuCn7znXm/ T6kC/b3W57NTLC4Qut2LBjCyOKXKlO9veuyiJYi9ZAPUcS+c418vzQVfQrT7IeR5p5bV 406xba/4FBA7BgnFiEyCZNv+s4CjG0bE2IbObpfLyn0m3B+e5IdEReAo/vYHQhE/81VI 3BZB++6j1VJ6yMIjdH/JTNqoOSebM6pHlcbZB2/O9RnsAdY6OVJO9YVOY7WlU94T+Z9F Jg== 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 3qh30j1xmh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:53 +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 34B99qSr006331 for ; Thu, 11 May 2023 16:24:51 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3qf7dg1gsy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:51 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOnTq12190436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D54420049 for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E444120040 for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:48 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:31 +0200 Message-Id: <20230511162446.10457-7-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: kik6S4t9dWZAHDxtH1iZM92xNf_KL01w X-Proofpoint-ORIG-GUID: kik6S4t9dWZAHDxtH1iZM92xNf_KL01w X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 adultscore=0 spamscore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 76ef020a..1090d3c9 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -169,6 +169,65 @@ 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; + + 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; @@ -205,6 +264,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 Thu May 11 16:24:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780175 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=OaCFSal0; 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 4QHHNk4Gc5z213w for ; Fri, 12 May 2023 02:27:18 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHNk3F64z3fb6 for ; Fri, 12 May 2023 02:27:18 +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=OaCFSal0; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=OaCFSal0; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL123Zyz3fP9 for ; Fri, 12 May 2023 02:24:56 +1000 (AEST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BGBROl028231 for ; Thu, 11 May 2023 16:24:55 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=ENz0nGWx/fGXCFOuFkTDChtcU7GvnrV0lvRTQNnuowI=; b=OaCFSal0Jpra2nBh56EUHX717iNvRo7vdwCGyuCpQb5esw5+JV42icyO2tdi6EoRjjxv BbFZ3t/5avH2UCsV8IBVpLOC1a4+dyUX4XUDsNOwWsod8eXBTgWVYJYTd8hIwSIzBLs5 3YruC5X80WMPABZQHWdzckLgoN6Di2rIXEu66+dn7W860jqRuzjDQkU+dvz/0hu8UaRx gdcFVd78uVUnADD3CTa9vONTDIRl1rQhbRQg2JEGBRfjjr5BpI4826WuxEItUor+x+Fn U3blH6h/SrtAip9Z0oAQhJizdvFMrneYrsRdgqfh4PHYD8iTNcKFgDPNE7iJn0lCb2/H aA== 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 3qh30j1xmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +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 34BEc1V2014496 for ; Thu, 11 May 2023 16:24:52 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0sgen-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:51 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOnPL34210272 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 902F42004E for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 511AB2004B for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:32 +0200 Message-Id: <20230511162446.10457-8-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 5GgEtWiI5CHe6kYOBa24kEVpZybAAklJ X-Proofpoint-ORIG-GUID: 5GgEtWiI5CHe6kYOBa24kEVpZybAAklJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 adultscore=0 spamscore=0 clxscore=1015 phishscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 1090d3c9..9f960c61 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -228,6 +228,103 @@ 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; + + 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; @@ -265,6 +362,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 Thu May 11 16:24:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780173 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=r959KGpl; 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 4QHHNN6rRjz213w for ; Fri, 12 May 2023 02:27:00 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHNN5nplz3fbt for ; Fri, 12 May 2023 02:27: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=r959KGpl; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=r959KGpl; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL058X6z3fQF for ; Fri, 12 May 2023 02:24:56 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BG6jf3027612 for ; Thu, 11 May 2023 16:24:55 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=ie5VgcisMgwspmGFiEeWBTtfPImK0djATmGiKxwQ6ys=; b=r959KGplWv4E6eWVMPCDYXfhDAMFboXWLmqp7DM1PyA2uVRa1mP8PwVOlZnIDQ0kmWcX 99A5sqPg40OlJ7h+atAeRVW/JaNvFIw22v+z0hdKJkPfy2SqzxnnJAw8K5ELyEtHhmRp irwqEodEvRTFC6aUSQyBSiiALNms7vldZ5nTIyGQxPgO5q+PYcM3pI3pVRdFRpMjTC5W HBHmj5D4U4ZP10ozLWECRzOv79YGqL1nnIeMKT+flC3vT4w7U7Bk7sQG2Fv9Za1N0cZQ ggOeC6RFMDuRfFFHGPDevc7ygkTs8e78FN9eAbFkHmUL866HOWrjj2XItulHf3YWMMEY KA== 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 3qh381hgyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +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 34BBbXhK031065 for ; Thu, 11 May 2023 16:24:52 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0sgep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOoJv5112478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF65C20040 for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B2F4320043 for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:49 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:33 +0200 Message-Id: <20230511162446.10457-9-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: e_F5JUD2B0dUx1WLR3b5omYo58Atwv7X X-Proofpoint-GUID: e_F5JUD2B0dUx1WLR3b5omYo58Atwv7X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 9f960c61..16dc799b 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -231,6 +231,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 @@ -325,6 +327,95 @@ 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; + + 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; @@ -363,6 +454,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 Thu May 11 16:24:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780177 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=MKiS165b; 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 4QHHP41R4Pz213w for ; Fri, 12 May 2023 02:27:36 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHP40KbMz3fYG for ; Fri, 12 May 2023 02:27:36 +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=MKiS165b; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MKiS165b; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL16JZlz3fPq for ; Fri, 12 May 2023 02:24:57 +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 34BG8R9b028073 for ; Thu, 11 May 2023 16:24:55 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=7C2g0LnEueiU9/IMV5I+Fc6lo+o9vxi/jTLZ/u1a0Pg=; b=MKiS165bQfpq2gOWmbo2NTJs2og2caJVL4B7NFSqI4iJZPzrV0gS0e9c4hKIRuj562XR VJ1nT/LWXNSEhmBUwNXUYIbtWi8MqI2J2t6TIZU5pI+otA1/ffUo74IX7V6rgPDWqVR9 WTf/dS/IqJ52qjWZLuRzmh9hclY1C29ulSotDaa+lOTWxM/Y6l04c5HKQrt/YdCiaXHb sos9+xKSxxNyk+5IKrwsqdbLhFYo5x+QNtzJRh+a7GNS+K5fQRJlocX42evpVW8Zo2Iv CAi22n+uOzbyxIsIzEKVkqLDjC0/cDUY+bcuMxYglmRSWo5SgP4DjcXFpARkmy/Fw4lm iA== 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 3qh2t1aa35-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +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 34B68SHF008473 for ; Thu, 11 May 2023 16:24:52 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3qf7d1sgj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOoPk5112482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5A44420049 for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D0D220043 for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:34 +0200 Message-Id: <20230511162446.10457-10-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Rom_rJLQ4x-7iS-Omq2ZN3LoZxwWnE25 X-Proofpoint-GUID: Rom_rJLQ4x-7iS-Omq2ZN3LoZxwWnE25 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 suspectscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 10 +- core/pldm/pldm-requester.c | 336 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 9 + include/ast.h | 6 + 5 files changed, 361 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 241fd956..cfa6d2fc 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; @@ -84,8 +87,13 @@ int pldm_mctp_init(void) /* Register mandatory commands we'll respond to */ rc = pldm_responder_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to register mandatory commands\n"); + goto out; + } + + /* Requester implementation */ + pldm_requester_init(); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm-requester.c b/core/pldm/pldm-requester.c new file mode 100644 index 00000000..07c6bdfd --- /dev/null +++ b/core/pldm/pldm-requester.c @@ -0,0 +1,336 @@ +// 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); + + /* call the poller if the list only contains this request */ + requests_poller(NULL); + + 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; +} + +void pldm_requester_init(void) +{ + /* requests poller */ + opal_add_poller(requests_poller, NULL); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 1cb0b424..d7a310c0 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); +void pldm_requester_init(void); + #endif /* __COREPLDM_H__ */ diff --git a/include/ast.h b/include/ast.h index e9c39c6d..c831efc0 100644 --- a/include/ast.h +++ b/include/ast.h @@ -107,6 +107,12 @@ void ast_setup_sio_mbox(uint16_t io_base, uint8_t irq); */ #define HOST_TID 3 +/* + * 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 Thu May 11 16:24:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780176 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=FsklSohW; 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 4QHHNv2MfQz213w for ; Fri, 12 May 2023 02:27:27 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHNv1Fpqz3fcD for ; Fri, 12 May 2023 02:27:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=FsklSohW; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=FsklSohW; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL15PRyz3fNj for ; Fri, 12 May 2023 02:24:57 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BGK8SJ005922 for ; Thu, 11 May 2023 16:24:55 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=wyfpTrqLJXGzRwv6xEe9GGofIBXDsv63LTh79K0zoxo=; b=FsklSohWILgW1N1udWOyRvWpHAlbsk0417rV52gwS7RTeXnrTXjgwKMOA4+MbKCTYZJb lG1PhMXfih/LLtnqSyTnUTko0D8IV9pG5mearMKAVOe1z1ZYdfJmRt7n+/rPEkV7aN1s K95KRIwPjB759RsWbfcQtScaRq/aY9qI3usfgEwVONN+PrWv2XVrNA+NjeIXUW6PSTYY 5gqrQ5bt6Q88DSSECzwtpX5qg0fTH4c1eRMcmKXYtNQv/2XCH8Vvk6mDmWg1swi8hn10 6IzZwPXafU2mK9b8W71VUnA1kL7UMRD8GXg1yZUvnFMS8+vM4Lj+oVrMZ2cooe+aRwhn MA== 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 3qh381hh04-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:55 +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 34B4VJuj019002 for ; Thu, 11 May 2023 16:24:53 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3qf7nh1ucy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:52 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOoaq5112486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B975D20049 for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7CC7C20040 for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:35 +0200 Message-Id: <20230511162446.10457-11-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: L9iEvHokdzm7b0AO2K4GZJu-AtuKAKKb X-Proofpoint-GUID: L9iEvHokdzm7b0AO2K4GZJu-AtuKAKKb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 3 + core/pldm/pldm-base-requests.c | 76 +++++++ core/pldm/pldm-mctp.c | 14 ++ core/pldm/pldm-platform-requests.c | 309 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 9 + 5 files changed, 411 insertions(+) create mode 100644 core/pldm/pldm-base-requests.c create mode 100644 core/pldm/pldm-platform-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index f2328a4b..5609a6b7 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,10 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/include/ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ +CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes + PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o +PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-base-requests.c b/core/pldm/pldm-base-requests.c new file mode 100644 index 00000000..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 cfa6d2fc..66074ded 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -95,6 +95,18 @@ int pldm_mctp_init(void) /* Requester implementation */ pldm_requester_init(); + /* Get BMC tid */ + rc = pldm_base_get_tid_req(); + if (rc) { + prlog(PR_ERR, "Failed to retrieve BMC Tid\n"); + goto out; + } + + /* Get PDRs data */ + rc = pldm_platform_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Data Records\n"); + out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); return rc; @@ -102,5 +114,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 d7a310c0..563a6f52 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 Thu May 11 16:24:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780178 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=VdOSAGE3; 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 4QHHPD5xftz213w for ; Fri, 12 May 2023 02:27:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHPD4wsNz3fWT for ; Fri, 12 May 2023 02:27:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=VdOSAGE3; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=VdOSAGE3; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL16j72z3fQr for ; Fri, 12 May 2023 02:24:57 +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 34BGHfMe009970 for ; Thu, 11 May 2023 16:24:56 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=VdOSAGE3hK+86gGmmPqd6YN10ofNBnxquohePe2Yw7pbjhFe1QqJN5dVox1XHmjtT7rC 6BqUSOcj7lIhvJrJqMjaYi9AUz/U+zC7KaTujHgtiapCSekI7Bny+GbOduiv+hSDiH8J yEJer9CoHWY0TUhr9knWfNDGXusMQjriTaR77g/9OYbPAHjb0Boz3Hz0iX//dkL86iNN CFrOG+bfBjMSrnsqzTqeDyXwvFKESLB2mIA3mDpCibIKbXH+DSkpdPSwxGLpObfuklHT D3Q3Uqev9npuAYxIuP9hBYlvHvnYsFgx79Sx+ezBTNGIXmG8YWhFGw2XUFzXRmvRl/Vg WA== 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 3qh3d891x5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:55 +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 34B479qp030195 for ; Thu, 11 May 2023 16:24:53 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896sujc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:53 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOpTK29557496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2257320049 for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA44820040 for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:50 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:36 +0200 Message-Id: <20230511162446.10457-12-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Olf4d3fmvTuiAtXUTp_BROwg4HVCgD9A X-Proofpoint-GUID: Olf4d3fmvTuiAtXUTp_BROwg4HVCgD9A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 suspectscore=0 mlxscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 Thu May 11 16:24:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780180 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=J7qB+8TF; 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 4QHHPb1gwxz213w for ; Fri, 12 May 2023 02:28:03 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHPb0f03z3fZK for ; Fri, 12 May 2023 02:28:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=J7qB+8TF; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=J7qB+8TF; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL30Mr5z3fR7 for ; Fri, 12 May 2023 02:24:58 +1000 (AEST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BFhh72024064 for ; Thu, 11 May 2023 16:24:57 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=J7qB+8TFrT43QHQvS2SNfZpRMny9TZo9eL1/PRN+qDPsRLdvZ2UzoSEaSlv4PvW8bBKB FrX3iWP1d3ieyDd0X6xqnnjTaIFAzSWEbK2UCBikVvlksWqNdyQEq8wNTguwplHOO0yH ZOQtIe3M/7I00RLG25jaRgSg9uPtzC7h1y1EefSxZ/AtvXMGIUWn4McTZCrvF8qp9XMi ncIxeQ2KbSUily+mny15cRjARZ1uUwH8dZo3v5EO8jb7O0kj/vfyNOFLxTQ5MgYglMO4 x6d/gMsuOyLi4GoZjjUhPVdc+yW/3yJNoEjCfx9x8GxcOD+n+8Dcx9Q9ItXAn45pT99T jg== 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 3qh38k1jdm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from 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 34BFcNIL001906 for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3qf7s8hgd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:53 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOpNV29557500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F98420049 for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4346920040 for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:37 +0200 Message-Id: <20230511162446.10457-13-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: fG8NFUUFaQ_cxfOnSQT73pZ0-VD4yt4S X-Proofpoint-ORIG-GUID: fG8NFUUFaQ_cxfOnSQT73pZ0-VD4yt4S X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 impostorscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 Thu May 11 16:24:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780179 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=nrofTmKu; 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 4QHHPQ31jLz213w for ; Fri, 12 May 2023 02:27:54 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHPQ1zd2z3fZP for ; Fri, 12 May 2023 02:27:54 +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=nrofTmKu; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=nrofTmKu; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL25JBqz3fPc for ; Fri, 12 May 2023 02:24:58 +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 34BGNttF015360 for ; Thu, 11 May 2023 16:24:56 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=nrofTmKuW/c+a2yBbyzQjT93XmDfUmfZwwA1ZKM4ySyz0hT4JMqIZko4ygS5iqEKaC+H Rq4hXXr0Lv3edH+4C1eXbmytBnFe1nUc2qyhi+kvzQzgeyim3qV41RcGMqO+qc/mvj3k ATjElcxT7admtpgwQl6Q+eJ7sj2omSk3lfVBP6uCuF09snCzDvpWsRbiYsr229lrFqU4 lROfM11K22joFEnv5W/IPDfxNY+hn7JvRnHoCLapKXNHSCadjSeFwGFMXkjp4x+c8wyS 4rx8ySOgkgTfM3sdtVa91H/+UcD8HKZcbdlPAlS0yjXE4RVcGN5JDPUBG/A9eJIwtocW tg== 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 3qh3nxgemt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from 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 34BFrE3B003727 for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896sujd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOp3E32309508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBE692004D for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A029220040 for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:38 +0200 Message-Id: <20230511162446.10457-14-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: _A4-WeeuKk2ztAkUHo7aZlZ-KMvGARSp X-Proofpoint-ORIG-GUID: _A4-WeeuKk2ztAkUHo7aZlZ-KMvGARSp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 malwarescore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 phishscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 Thu May 11 16:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780183 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=eogpbCEm; 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 4QHHPx0BMSz213w for ; Fri, 12 May 2023 02:28:21 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHPw6C7hz3fWk for ; Fri, 12 May 2023 02:28:20 +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=eogpbCEm; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=eogpbCEm; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL36cddz3fWj for ; Fri, 12 May 2023 02:24:59 +1000 (AEST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BG8eTw009251 for ; Thu, 11 May 2023 16:24:57 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=u1/sOhHBIGb45B+8jzKVk4J4Pp3+CDJBr364TlvRfHA=; b=eogpbCEmwll9TGTtl+WZn+CZec0GVKhx8pXEFgmdnrDpiEkWcFORpAZvBPYjeq+iqiFz ZGSep9RdWZbW0J4L7ZOVbtShejQFbH9QU/4RYtRIdthIwiY3ocVAp7WIqxafTds/Oez7 1DVuCm+XuHHwa4buwq+KKIdaYXGLDye3Hda3pMHpEPJUgH/WxYqONYGOiAfB7+rsFEMN cduvICFEHUYj7JdjMqrREYURTcF7IVNTRwE1hHi4oIz0eQzdRUWLHAefTfplkoGnc91Y fP95oV0JijAvuIEuUA17UVJSuLO6eMz8fT2DJQrvranmtYA4IB5BauviJmWbGyTZH9BQ UQ== 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 3qh38k1je5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:57 +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 34B4aEct013737 for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3qf7s8hgd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOqj422544908 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 473FC20049 for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 09C4820040 for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:51 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:39 +0200 Message-Id: <20230511162446.10457-15-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: zHkDJifFPV43FK0E7wS3nOhmoQ1sAWOn X-Proofpoint-ORIG-GUID: zHkDJifFPV43FK0E7wS3nOhmoQ1sAWOn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 impostorscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 2 + core/pldm/pldm-bios-requests.c | 222 +++++++++++++++++++++++++++++++++ core/pldm/pldm-mctp.c | 9 +- core/pldm/pldm.h | 2 + 4 files changed, 234 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 5609a6b7..0681d76a 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -8,9 +8,11 @@ CPPFLAGS += -I$(SRC)/pldm/include/ CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes +CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o +PLDM_OBJS += pldm-bios-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-bios-requests.c b/core/pldm/pldm-bios-requests.c new file mode 100644 index 00000000..485ed1c7 --- /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; + void *response_msg; + int rc; + + struct pldm_get_bios_table_req bios_table_req = { + .transfer_handle = 0, /* (0 if transfer op is FIRSTPART) */ + .transfer_op_flag = PLDM_GET_FIRSTPART, + .table_type = table_type + }; + + prlog(PR_DEBUG, "%s - table type: %d\n", __func__, table_type); + + /* Encode the bios table request */ + 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 OPAL_SUCCESS; +} + +int pldm_bios_init(void) +{ + int rc; + + /* BIOS String Table is a BIOS table that contains all the BIOS + * strings including attribute names, and pre-configured strings + * used in representing the values of the attributes. + * Each string in the BIOS String Table has an associated unique + * handle. + */ + rc = get_bios_table_req(PLDM_BIOS_STRING_TABLE, + &bios_string_table, &bios_string_length); + if (rc) + goto err; + + /* BIOS Attribute Table is a BIOS table that contains attribute + * name handles, attribute types, type-specific metadata, + * type-specific possible values (if any), and default values. + */ + rc = get_bios_table_req(PLDM_BIOS_ATTR_TABLE, + &bios_attr_table, &bios_attr_length); + if (rc) + goto err; + + /* BIOS Attribute Value Table is a BIOS table that contains all + * the current values of the BIOS attributes and settings. + * Each entry in this table contains the attribute handle, the + * attribute type, and current values. + */ + rc = get_bios_table_req(PLDM_BIOS_ATTR_VAL_TABLE, + &bios_val_table, &bios_val_length); + if (rc) + goto err; + + bios_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + bios_init_complete(false); + return rc; +} diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index 66074ded..2e7605cb 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -104,8 +104,15 @@ int pldm_mctp_init(void) /* Get PDRs data */ rc = pldm_platform_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Data Records\n"); + goto out; + } + + /* Get Bios data */ + rc = pldm_bios_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Bios data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 563a6f52..927a5bb8 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 Thu May 11 16:24:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780182 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=p5BN9G5+; 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 4QHHPl6VBlz213w for ; Fri, 12 May 2023 02:28:11 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHPl4kK0z3fZl for ; Fri, 12 May 2023 02:28:11 +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=p5BN9G5+; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=p5BN9G5+; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL31Xc9z3fNg for ; Fri, 12 May 2023 02:24:59 +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 34BGOGPc018620 for ; Thu, 11 May 2023 16:24:57 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=EQ9v/lnTHelMwP8ew/uhgVlnnvyVFQ8tog14Ai1oUOg=; b=p5BN9G5+m6On5bShjp3adie75sycwz4UBr2OnKOFQCwyQG6viZ659dc+oFwNyRMfDlkN zJiEakPhWnaVqyG0yVfG9l//XAjXmv+nQJ2E7Dtb8UAzdg/Poanofze1KvWvk58V47m/ QHcUVtZWihxUAa9STJMYcDPL4QJhB5wn9DaBz4OTLXfcZyCQqDTpJeKJccMxZX/FYL2t wQMinpMcAAhUAiJiroMDyNuOqP/b2RY5IfH410GIPCQxWL5cPqV+T3dY/AckeFFoUeiL 6dNamSFfGt93y+xPd3LvYwVy9UgDrUy41b/+rA0+3D8PmTzR6VS0LmTiTv4Va/tpGrg5 yA== 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 3qh3umg0b7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from 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 34B67Nv7003023 for ; Thu, 11 May 2023 16:24:55 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0sgba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOqh022544910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:52 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6B1020049 for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 697BB20040 for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:40 +0200 Message-Id: <20230511162446.10457-16-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: C65gxytUt5vjlYEvYL-k-y4uU-wDG1V5 X-Proofpoint-ORIG-GUID: C65gxytUt5vjlYEvYL-k-y4uU-wDG1V5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 impostorscore=0 spamscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 485ed1c7..239612a3 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_PARAMETER; + + /* decode string table */ + string_entry = pldm_bios_table_string_find_by_string( + bios_string_table, bios_string_length, str); + if (!string_entry) { + prlog(PR_ERR, "String table entry not found, str: %s\n", + str); + return OPAL_PARAMETER; + } + + /* get the string handle for the entry */ + string_handle = pldm_bios_table_string_entry_decode_handle(string_entry); + prlog(PR_TRACE, "%s - string_handle: %d\n", __func__, string_handle); + + /* decode attribute table */ + attr_entry = pldm_bios_table_attr_find_by_string_handle( + bios_attr_table, bios_attr_length, string_handle); + if (!attr_entry) { + prlog(PR_ERR, "Attribute table entry not found, string_handle: %d\n", + string_handle); + return OPAL_PARAMETER; + } + + /* get the attribute handle from the attribute table entry */ + attr_handle = pldm_bios_table_attr_entry_decode_attribute_handle(attr_entry); + prlog(PR_TRACE, "%s - attr_handle: %d\n", __func__, attr_handle); + + /* decode attribute value table */ + val_entry = pldm_bios_table_attr_value_find_by_handle( + bios_val_table, bios_val_length, attr_handle); + + if (!val_entry) { + prlog(PR_ERR, "Attribute val table entry not found, attr_handle: %d\n", + attr_handle); + return OPAL_PARAMETER; + } + + /* get Current String Itself */ + pldm_bios_table_attr_value_entry_string_decode_string( + val_entry, + ¤tString); + *current_string = strdup(currentString.ptr); + + return OPAL_SUCCESS; +} + +#define HB_LID_IDS "hb_lid_ids" + +/* + * Find lid attribute from bios tables + */ +int pldm_bios_find_lid_by_attr_name(const char *name, char **lid) +{ + char *hb_lid_ids_string = NULL; + int rc = OPAL_SUCCESS; + + if (!bios_ready) + return OPAL_HARDWARE; + + /* find current attribut string */ + rc = find_bios_table_attr_values_by_string(HB_LID_IDS, &hb_lid_ids_string); + if (rc) + goto err; + + /* find lid attribut from current string */ + rc = find_lid_by_attr_name(hb_lid_ids_string, name, lid); + if (rc) + goto err; + + free(hb_lid_ids_string); + + prlog(PR_DEBUG, "%s - lid: %s, attr name: %s\n", + __func__, *lid, name); + + return OPAL_SUCCESS; + +err: + if (hb_lid_ids_string) + free(hb_lid_ids_string); + + return rc; +} + +/* + * Get lid ids string from bios tables + */ +int pldm_bios_get_lids_id(char **lid_ids_string) +{ + if (!bios_ready) + return OPAL_HARDWARE; + + /* find current attribut string */ + return find_bios_table_attr_values_by_string(HB_LID_IDS, lid_ids_string); +} + /* * Send/receive a PLDM GetBIOSTable request message */ diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 927a5bb8..b51f72c8 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 Thu May 11 16:24:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780184 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=GFGjKd7X; 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 4QHHQ55RdJz213w for ; Fri, 12 May 2023 02:28:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQ54R7jz3fbq for ; Fri, 12 May 2023 02:28:29 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=GFGjKd7X; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=GFGjKd7X; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL42T27z3fWG for ; Fri, 12 May 2023 02:25:00 +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 34BG7YxR019977 for ; Thu, 11 May 2023 16:24:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=JjS738+/ZIMgSM5oVU/qN1TrWXO9B+TQFpicSjAkUSk=; b=GFGjKd7XLWdKUjiNq0MT8yjvNhzV0auhOichPYFLKs8Xc8gyfZJcp8XoYZ0b8Ppf/jli ZcH7kD939VIyyxoTAym/EU0++R28zLD5oPtg7r0WTuRp9ADQvf9bXWnSgk1xDdZM3tOZ xbFp4PI6iVvEoG696z1Nf6aZjlhzi4fEOqDqSixUEGfT/1nrq/Ud7cr7RT4LueCA5wxj dhOjRDDv1IWhZBfb5N2u2w3Auto3WBfFR++rEaRu1BszxtYLe1gBuTnVrSqvJ29JyRCE A5w6PI0/mf/NM+7hUkzPvUwVLryn0FvsiYYVyceTizLKtjK+8AyBZxueFLEmlC8UIGFW Jw== 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 3qh3d891y1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:57 +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 34B2dB36017404 for ; Thu, 11 May 2023 16:24:55 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3qf7nh1ud0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:55 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOrJo5702284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:53 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 117F020043 for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C83F020040 for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:52 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:41 +0200 Message-Id: <20230511162446.10457-17-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: c7T-t74jON_0YrtHBFVfqthInE5ORFcd X-Proofpoint-GUID: c7T-t74jON_0YrtHBFVfqthInE5ORFcd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 adultscore=0 spamscore=0 suspectscore=0 mlxscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 9 ++- core/pldm/pldm.h | 2 + 4 files changed, 158 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 0681d76a..b0f7d685 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -12,7 +12,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o -PLDM_OBJS += pldm-bios-requests.o +PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c new file mode 100644 index 00000000..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 2e7605cb..546e5aad 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -111,8 +111,15 @@ int pldm_mctp_init(void) /* Get Bios data */ rc = pldm_bios_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Bios data\n"); + goto out; + } + + /* Get Fru data */ + rc = pldm_fru_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve Fru data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index b51f72c8..8f52fc62 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 Thu May 11 16:24:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780187 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=OR+Lv1VG; 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 4QHHQR00DKz213w for ; Fri, 12 May 2023 02:28:46 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQQ62Kpz3fds for ; Fri, 12 May 2023 02:28:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=OR+Lv1VG; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=OR+Lv1VG; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL44vkZz3fX1 for ; Fri, 12 May 2023 02:25:00 +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 34BGCH9N029860 for ; Thu, 11 May 2023 16:24:59 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=KrlbSye4fW2IhTXTV3uvWuWcjwp/ZlLAB746B513gUg=; b=OR+Lv1VG9D9iVs6PJg4TySM/XEX3ZOoyy7rBcu37mVeivsk6luk4nKmgIe2WjeNCxCjA XOYd5EzeoiukBMXqUsqcJ0g1tPNEDf70+fAdW5fMd1U2gw3a/s39v6vsbtiizs1+etyq BOSZ1lCXE1Nqy6uX6D2YQlnptkopm3lYhQe0ocuPYB9eS/iXbYrZavc1pjTw7xZgXxgp sIOlECXxB2Dnd6Iv+L7yv4muznvJhL1oEyidBcoBn0zwKgJlz97x/tUiVAfLEytcNREK vR1OsRSZzNZ2kmPDRy/Q9//Vyn3ldAOJlzLPfhXQYxMCIimX1+BT+EJvYJH344p4oPb2 8w== 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 3qh3nxgeng-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:58 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34B68O9x022465 for ; Thu, 11 May 2023 16:24:56 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3qf7e0sger-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOr5j5702288 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:53 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70FB420049 for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3445620040 for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:42 +0200 Message-Id: <20230511162446.10457-18-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ksfg01wRqbrlLJhragWOyawreLXfg5-q X-Proofpoint-ORIG-GUID: Ksfg01wRqbrlLJhragWOyawreLXfg5-q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 malwarescore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 phishscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 84 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 1 + include/pldm.h | 5 +++ 3 files changed, 90 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index ae1d9fac..aa4ce662 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -15,6 +15,7 @@ static void *fru_record_table; static size_t fru_record_length; static bool fru_ready; +static char *bmc_version = NULL; static void fru_init_complete(bool success) { @@ -33,6 +34,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,73 @@ 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"); + assert(dt_fw_version); + + /* 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 - PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES, + 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 8f52fc62..1e01205a 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 Thu May 11 16:24:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780185 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=Vqwqianx; 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 4QHHQG1wcWz213w for ; Fri, 12 May 2023 02:28:38 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQG0tBCz3fdS for ; Fri, 12 May 2023 02:28: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=Vqwqianx; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Vqwqianx; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL42NyPz3fNy for ; Fri, 12 May 2023 02:25:00 +1000 (AEST) Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BG6Xgt027074 for ; Thu, 11 May 2023 16:24:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Z1DRCIKZ7uwfVoMeCNy0JjzO70p0SQOT2XsD85fZDjs=; b=VqwqianxoifNTEtBtb8NE/JBk5s6k2o8dr3FgwJ5dwYjSQs7Klx74xdgR+T5rYCU9k2n TXi0VgJIOzzXPN5X75/GjMkuUWgNqy5Rm56LFqXiU77bxiKkiBSqxg7OA7cr0eVXmiz6 OeUM8BGyGiaUfZ0seZpxY/CZyAykLm6Bnh/8OkX2TQnbnCF05A5E1lAOe8GT7xoGC+vf T6wp39EHswkansqJ8+8bj+qLmh5yI6fltJJEqZwms+ea5xm+r6Do134u9f3J7eN9+ULZ WjHLAMtdiHZR51UrmmwJH1CwL8alyD0KniYbAVQarpihauw6PJXZwoVQvEI6iMwAK8Tq Zg== 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 3qh381hh1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34B99VkO021767 for ; Thu, 11 May 2023 16:24:56 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896sujf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOrWg10814100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D16B120043 for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9344020040 for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:43 +0200 Message-Id: <20230511162446.10457-19-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vKHdTDWJxSmEijz9IPM4KqbIKLRDDmeX X-Proofpoint-GUID: vKHdTDWJxSmEijz9IPM4KqbIKLRDDmeX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 | 9 +- core/pldm/pldm.h | 2 + 4 files changed, 167 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 b0f7d685..6387334d 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -13,6 +13,7 @@ CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o +PLDM_OBJS += pldm-file-io-requests.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c new file mode 100644 index 00000000..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 546e5aad..fc1b3431 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -118,8 +118,15 @@ int pldm_mctp_init(void) /* Get Fru data */ rc = pldm_fru_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to retrieve Fru data\n"); + goto out; + } + + /* Get FILE IO data */ + rc = pldm_file_io_init(); + if (rc) + prlog(PR_ERR, "Failed to retrieve File io data\n"); out: prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 1e01205a..d181aa89 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 Thu May 11 16:24:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Jmc7mDeR; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHHQb5SwSz213w for ; Fri, 12 May 2023 02:28:55 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQb4RBFz3fdZ for ; Fri, 12 May 2023 02:28:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Jmc7mDeR; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Jmc7mDeR; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL44YN7z3fWy for ; Fri, 12 May 2023 02:25:00 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BGItd6016684 for ; Thu, 11 May 2023 16:24:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=daZOczgcknpYnTTmmUOftOkyVqK3nlYy6Nrwvtq9VYQ=; b=Jmc7mDeRtHpoLaJfYwx1O6FZIFg67qyxnBPp2VA/ArmHeX1fptgGfGyy0C6Vkm21IKci q8xnqnmgn9a+EOnwITUyejrdq5XH8Ka96MJhCnxxqDu5ABAZEOdCV17VNgKJCZWW2zzl 5/VBULE8alsxTuijR8QTVnC9nxaUmP4dY7+zl9Yj0lb5UNOz3ROxyer6L5Ch/xnLf2JV tkNjuYUbuihrODF8XwQVA/S/y9x3bi7niRFAr8MINyiMTkKRAqwD5GnF5KryU4TywfX6 volvuCapIJxSYgHGvBpxYjByHnWUXyNi7RHcP/OUHdz/snqYosNtUETgknN69Lbxdq+2 wg== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qh2h2ub2a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34BFrE3C003727 for ; Thu, 11 May 2023 16:24:56 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896sujg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOsHc5702292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DB8020049 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 00BEF20040 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:53 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:44 +0200 Message-Id: <20230511162446.10457-20-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: R-ZtKZndruTvNWwNOJoTceY6IfhY09P- X-Proofpoint-ORIG-GUID: R-ZtKZndruTvNWwNOJoTceY6IfhY09P- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 phishscore=0 impostorscore=0 adultscore=0 priorityscore=1501 spamscore=0 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 19/21] core/pldm: Add file io read request X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Send/receive a PLDM ReadFile request message. Due to maximum transfer size for PLDM protocol, we have to send several read requests, if necessary. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 135 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 137 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 11251a30..02d551bb 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "pldm.h" @@ -33,6 +34,140 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +/* maximum currently transfer size for PLDM */ +#define KILOBYTE 1024ul +#define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1) + +/* + * Send/receive a PLDM ReadFile request message. + */ +static int read_file_req(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_read_file_req); + size_t response_len, payload_len, file_data_offset; + uint8_t completion_code; + struct pldm_tx_data *tx; + uint32_t resp_length; + uint64_t total_read; + void *response_msg; + int num_transfers; + void *curr_buf; + int rc, i; + + struct pldm_read_file_req file_req = { + .file_handle = file_handle, + .offset = offset, + .length = size + }; + + if (!file_length) + return OPAL_PARAMETER; + + if ((!size) || ((size + offset) > file_length)) + return OPAL_PARAMETER; + + num_transfers = 1; + curr_buf = buf; + total_read = 0; + + if (file_req.length > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (file_req.length + MAX_TRANSFER_SIZE_BYTES - 1) / + MAX_TRANSFER_SIZE_BYTES; + file_req.length = MAX_TRANSFER_SIZE_BYTES; + } + + prlog(PR_TRACE, "%s - file_handle: %d, offset: 0x%x, size: 0x%llx num_transfers: %d\n", + __func__, file_handle, file_req.offset, + size, num_transfers); + + /* init request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + for (i = 0; i < num_transfers; i++) { + file_req.offset = offset + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_read_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode ReadFileReq Error, rc: %d\n", + rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait( + tx, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: ReadFileReq, rc: %d\n", rc); + free(tx); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_read_file_resp( + response_msg, + payload_len, + &completion_code, + &resp_length, + &file_data_offset); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode ReadFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(tx); + free(response_msg); + return OPAL_PARAMETER; + } + + if (resp_length == 0) { + free(response_msg); + break; + } + + memcpy(curr_buf, + ((struct pldm_msg *)response_msg)->payload + file_data_offset, + resp_length); + + total_read += resp_length; + curr_buf += resp_length; + free(response_msg); + + prlog(PR_TRACE, "%s - file_handle: %d, resp_length: 0x%x, total_read: 0x%llx\n", + __func__, file_handle, resp_length, total_read); + + if (total_read >= size) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (size - total_read)) + file_req.length = size - total_read; + } + + free(tx); + return OPAL_SUCCESS; +} + +int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return read_file_req(file_handle, file_length, buf, offset, size); +} + /* * Send/receive a PLDM GetFileTable request message. * The file table contains the list of files available and diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index d181aa89..30ef0922 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -52,6 +52,8 @@ int pldm_responder_handle_request(struct pldm_rx_data *rx); int pldm_responder_init(void); /* Requester support */ +int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size); int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv, int len); From patchwork Thu May 11 16:24:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780189 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=Zqnd2J0r; 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 4QHHQn1HPDz213w for ; Fri, 12 May 2023 02:29:05 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQn0GVdz3fP8 for ; Fri, 12 May 2023 02:29:05 +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=Zqnd2J0r; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Zqnd2J0r; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL51rPZz3fPQ for ; Fri, 12 May 2023 02:25:01 +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 34BGFihp026773 for ; Thu, 11 May 2023 16:24:59 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=A5W9EMwo8h9LhXch6dPKBfttfLDc01Z5zLw9ajnqdTo=; b=Zqnd2J0ra1wgZ/vRdIvBrlEO3ajWTLD4+QrjZ5aXECO3Sbnx/cp/IzK5tDny7NxGfNRg dtGkCFqjw/M3i/mQawBYzUAYSnD1EnN/CLPmeUI7trKl80USuGduM9GhGUEilRlIXri9 p35GgNEE403qvZifMmJmd90AUBsEiYobneE2iOrGnyoinb+GH366VpvJXrTxLlKjM4wq 9riSKDD452qKcci/8MkvNB6C/XM83fbanm1lHphuKhLcNzGarhZyuE27b+o0uBBDwC7V swmnNQkYVlAp1bCv2gv5F7yRFSJeHGtbr/zlKjwD7bo6p81B5Z3pLDn3UfFN6SJpK1un 5A== 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 3qh3qmr9uh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34BFrE3D003727 for ; Thu, 11 May 2023 16:24:57 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896sujj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:56 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOs9w14680802 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:54 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D28F20043 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F76920040 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:45 +0200 Message-Id: <20230511162446.10457-21-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 82K49VG8vwUdfRa5MORO-6kxV4CqQtIh X-Proofpoint-GUID: 82K49VG8vwUdfRa5MORO-6kxV4CqQtIh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 impostorscore=0 suspectscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 phishscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 02d551bb..bcbd05d8 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -168,6 +168,132 @@ int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, return read_file_req(file_handle, file_length, buf, offset, size); } +/* + * Send/receive a PLDM WriteFile request message. + */ +static int write_file_req(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size) +{ + void *response_msg, *current_ptr, *payload_data; + uint32_t total_write, resp_length, request_length; + size_t response_len, payload_len; + uint8_t completion_code; + struct pldm_tx_data *tx; + int num_transfers; + int rc, i; + + struct pldm_write_file_req file_req = { + .file_handle = file_handle, + .offset = offset, + .length = size + }; + + if (!size) + return OPAL_PARAMETER; + + if ((offset) && (offset > size)) + return OPAL_PARAMETER; + + /* init request */ + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_write_file_req) + + size; + + 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, size); + current_ptr = payload_data; + num_transfers = 1; + total_write = 0; + + if (size > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (size + MAX_TRANSFER_SIZE_BYTES - 1) / + MAX_TRANSFER_SIZE_BYTES; + file_req.length = MAX_TRANSFER_SIZE_BYTES; + } + + prlog(PR_TRACE, "%s - file_handle: %d, offset: 0x%x, size: 0x%x, num_transfers: %d\n", + __func__, file_handle, file_req.offset, + file_req.length, num_transfers); + + for (i = 0; i < num_transfers; i++) { + file_req.offset = offset + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_write_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)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 == size) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (size - total_write)) + file_req.length = size - total_write; + } + + free(tx); + return OPAL_SUCCESS; +} + +int pldm_file_io_write_file(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return write_file_req(file_handle, buf, offset, size); +} + /* * Send/receive a PLDM GetFileTable request message. * The file table contains the list of files available and diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 30ef0922..dd5b0fc2 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, void *buf, uint32_t offset, uint64_t size); +int pldm_file_io_write_file(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size); int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv, int len); From patchwork Thu May 11 16:24:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780190 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=sE8VxxVD; 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 4QHHQy050Dz213w for ; Fri, 12 May 2023 02:29:14 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHQx68mzz3ffJ for ; Fri, 12 May 2023 02:29: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=sE8VxxVD; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=sE8VxxVD; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHL54N4mz3fWT for ; Fri, 12 May 2023 02:25:01 +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 34BGCIQR029886 for ; Thu, 11 May 2023 16:25:00 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=8hVsManMC/NCsFsLva8CRTwzgOa2zpdgzphHF8Xe/Ec=; b=sE8VxxVDaJ8dYNLbJlOxALX21lTD5ZIm3OZSNgpohsjz9Rve3np8c7ADU6D0UHECwUDE w+bMnH4C+K7p0XO3FX/zePwYDGqrdOwb5FNiaUN1C8JxiiNtbV0c9EvorVopQHjPyndm k1q1QqZquPTbmNwlPd3kkB0TctnH1GMUzlJfyzAgO+WeASwqVfe5IQrPnzI8C5wLxDEy JDtIJIdeU5JQrXgpsRYOYv4+IkBlPvB9WI/SK6+fSoD3tXh27dLZAAg8gz5Maz6J4/Se EsNi8rsXHKW/zGr46ioiyhQugpMkT9X4/4TXupRQKrHI+VU60hzhISh+fWze7Zbzf2az YQ== 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 3qh3nxgenw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:59 +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 34BCcidv006355 for ; Thu, 11 May 2023 16:24:57 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3qf84e9ufa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:57 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOteW14680806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:55 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 08F6A20043 for ; Thu, 11 May 2023 16:24:55 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE71A20040 for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:54 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:46 +0200 Message-Id: <20230511162446.10457-22-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YjyDF3Y0caQ9d7NQTKrM1tpjMj5qATDd X-Proofpoint-ORIG-GUID: YjyDF3Y0caQ9d7NQTKrM1tpjMj5qATDd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 malwarescore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 phishscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 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 bcbd05d8..6444bfa6 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -34,6 +34,82 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +#define CHKSUM_PADDING 8 + +/* + * Retrieve the file handle and file length from the file attribute + * table. + */ +static int find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + const struct pldm_file_attr_table_entry *file_entry; + char *startptr, *endptr; + uint16_t file_name_length; + + if ((file_attr_table == NULL) || (file_attr_length == 0)) + return OPAL_PARAMETER; + + startptr = (char *)file_attr_table; + endptr = startptr + file_attr_length - CHKSUM_PADDING; + *file_handle = 0; + *file_length = 0; + + while (startptr < endptr) { + /* file entry: + * 4 Bytes: file handle + * 2 Bytes: file name length + * Bytes: file name + * 4 Bytes: file length + */ + file_entry = (struct pldm_file_attr_table_entry *)startptr; + + *file_handle = le32_to_cpu(file_entry->file_handle); + startptr += sizeof(uint32_t); + + file_name_length = le16_to_cpu(file_entry->file_name_length); + startptr += sizeof(file_name_length); + + if (!strncmp(startptr, lid_id, strlen(lid_id))) { + startptr += file_name_length; + *file_length = le32_to_cpu(*(uint32_t *)startptr); + break; + } + startptr += file_name_length; + startptr += sizeof(uint32_t); + startptr += sizeof(bitfield32_t); + } + + if (*file_length == 0) { + prlog(PR_ERR, "%s - 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_PARAMETER; + + return find_file_handle_by_lid_id(lid_id, + file_handle, + file_length); +} + /* maximum currently transfer size for PLDM */ #define KILOBYTE 1024ul #define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1) diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index dd5b0fc2..5e979a82 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, void *buf, uint32_t offset, uint64_t size); int pldm_file_io_write_file(uint32_t file_handle, const void *buf,