From patchwork Thu Apr 14 13:43:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=iq5t7npA; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLKf0VBWz9sGF for ; Thu, 14 Apr 2022 23:44:22 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLKd6Wx9z3bcW for ; Thu, 14 Apr 2022 23:44:21 +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=iq5t7npA; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=iq5t7npA; 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 4KfLKT0C6Nz2yK2 for ; Thu, 14 Apr 2022 23:44:12 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC409E010581 for ; Thu, 14 Apr 2022 13:44:10 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=OtXc3mtMC2WOYqk/Tqj5eZK7eD8JAldv0aB/8qiErbk=; b=iq5t7npA6HvJTxTiuaCP3c8w183IwutP5ndTakuB2hoqeUq8fJt2WUOY7Gh8oWMd3VXV uwOUzfDBD2m/HWHvvoEAsM7pwzu3s66VunzhLKIx57uAmx7BChHyR1Uqki8Ho9UGjTok 796le5vrPv1GcR+Mg+4/Jyujjga+zmN4r4NioQ2LRqG22+2MuRVQRCCML4aVOypb4BfN u4AL9CZSj777q9vrA0JwcYhin25VeR9VKa8LENPPJBrg6yFKg0rEOzlrj8WQeseFccL7 KZdSUEyJNpQgAtXTcTOSDXDTBdhIEGtOCMSor/PUqi98u3RCu8koHDUF4CFdELKgi49o ZQ== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3febxa2ru1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfu9d024757 for ; Thu, 14 Apr 2022 13:44:07 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3fb1dj8ppq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:07 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi5IG39453000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:05 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A5EFA406E for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1F7BAA407C for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:44 +0200 Message-Id: <20220414134404.39888-2-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: cj-ldkNpG9tF0dK6ICI6XyykxTunrcR4 X-Proofpoint-ORIG-GUID: cj-ldkNpG9tF0dK6ICI6XyykxTunrcR4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 01/21] hw: Move lpc firmware space helpers X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Add new lpc helpers for doing a bulk io to firmware space. Signed-off-by: Christophe Lombard --- hw/lpc.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/lpc.h | 6 +++++ 2 files changed, 80 insertions(+) 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); From patchwork Thu Apr 14 13:43:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=C5vdE5BA; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLKl1k89z9sGF for ; Thu, 14 Apr 2022 23:44:27 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLKl0FJYz300Q for ; Thu, 14 Apr 2022 23:44: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=C5vdE5BA; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=C5vdE5BA; 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 4KfLKT4c4Hz2yS3 for ; Thu, 14 Apr 2022 23:44:13 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3wMA032969 for ; Thu, 14 Apr 2022 13:44:10 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=lxYj3LPpMiSMZvtEyL1vWB18jBpV4e3BWgQ+ffIki0I=; b=C5vdE5BAz/UsdR4nHCu4WJPyOiGGgoHYaru3BUKfm8sd/3AGHeazMVzrJXSM8HNRxPIm xDy81QNBx29bNMzO+aMzXujfxNvw716L0NxBWAhrltJF3pnDVpO4ghJEQFzZp43qwJbF 0a6twurfdVEOU8gRjSsR73kAsRet5iVUIYky6kTPUa167H+pXiv45vPWRZWxYSy6sHpc QAcCgaWsm+ME1/+62gmSuzALsaAKI8nuDVbTgaEoRuPopF7Ta5P6Rzv2OvQ21VeoWqrg szP2JPySbDgukAFerLECM5gMd4Y4bB7zq6UTjSMoL3VZ+4y7PhKPk7JoUqGJCD+KuieP Ug== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fef1p78mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDhxmU001540 for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06fra.de.ibm.com with ESMTP id 3fbsj05vup-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:07 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi5k639453004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:05 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B01FA406E for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60364A406D for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:45 +0200 Message-Id: <20220414134404.39888-3-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: N8hmLbTexGbE_CXE7_Mr-AmXEsD6GaWa X-Proofpoint-ORIG-GUID: N8hmLbTexGbE_CXE7_Mr-AmXEsD6GaWa X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 malwarescore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 suspectscore=0 impostorscore=0 clxscore=1011 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 02/21] hw/ast-bmc: Initialize ast lpc mctp binding X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The Management Component Transport Protocol (MCTP) defines a communication model intended to facilitate communication. This patch initialize MCTP binding over LPC Bus interface. Several steps must be performed: - Initialize the MCTP core (mctp_init()). - Initialize a hardware binding as AST LPC mode host (mctp_astlpc_init()). - Register the hardware binding with the core (mctp_register_bus()), using a predefined EID (Host default is 9). To transmit a MCTP message, mctp_message_tx() is used. To receive a MCTP message, a callback need to be provided and registered through mctp_set_rx_all(). For the transfer of MCTP messages, two basics components are used: - A window of the LPC FW address space, where reads and writes are forwarded to BMC memory. - An interrupt mechanism using the KCS interface. hw/ast-bmc/ast-mctp.c is compilated if the compiler flag CONFIG_PLDM is set. Signed-off-by: Christophe Lombard --- hw/ast-bmc/Makefile.inc | 7 + hw/ast-bmc/ast-mctp.c | 355 ++++++++++++++++++++++++++++++++++++++++ include/ast.h | 8 + 3 files changed, 370 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..ca7de379 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 += -DASTLPC_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..b220da6b --- /dev/null +++ b/hw/ast-bmc/ast-mctp.c @@ -0,0 +1,355 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "AST-MCTP: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * For the EIDs: the valid range is 8-254. + * host default = 9 + */ +uint8_t HOST_EID = 9; + +static struct mctp *mctp; + +/* binding specific */ +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; +}; + +/* + * The AST binding is described here: + * + * https://github.com/openbmc/libmctp/blob/master/docs/bindings/vendor-astlpc.md + * + * Most of the binding is implemented in libmctp, but we need to provide + * accessors for the LPC FW space (for the packet buffer) and for the KCS + * peripheral (for the interrupt mechanism). + */ + +static int ast_kcs_reg_read(void *binding_data, + enum mctp_binding_astlpc_kcs_reg reg, + uint8_t *val) +{ + struct astlpc_ops_data *ops_data = binding_data; + uint32_t addr, tmp; + int rc; + + if (reg == MCTP_ASTLPC_KCS_REG_STATUS) + addr = ops_data->kcs_stat_addr; + else if (reg == MCTP_ASTLPC_KCS_REG_DATA) + addr = ops_data->kcs_data_addr; + else + return OPAL_PARAMETER; + + rc = lpc_read(OPAL_LPC_IO, addr, &tmp, 1); + if (!rc) + *val = tmp & 0xff; + else + *val = 0xff; + + mctp_prdebug("%s 0x%hhx from %s (%d)", + __func__, *val, reg ? "status" : "data", rc); + + return rc; +} + +static int ast_kcs_reg_write(void *binding_data, + enum mctp_binding_astlpc_kcs_reg reg, + uint8_t val) +{ + struct astlpc_ops_data *ops_data = binding_data; + uint32_t addr; + + mctp_prdebug("%s 0x%hhx to %s", + __func__, val, reg ? "status" : "data"); + + if (reg == MCTP_ASTLPC_KCS_REG_STATUS) + addr = ops_data->kcs_stat_addr; + else if (reg == MCTP_ASTLPC_KCS_REG_DATA) + addr = ops_data->kcs_data_addr; + else + return OPAL_PARAMETER; + + return lpc_write(OPAL_LPC_IO, addr, val, 1); +} + +static int ast_lpc_read(void *binding_data, void *buf, long offset, + size_t len) +{ + struct astlpc_ops_data *ops_data = binding_data; + + mctp_prdebug("%s %zu bytes from 0x%lx (lpc: 0x%lx)", + __func__, len, offset, + ops_data->lpc_fw_addr + offset); + return lpc_fw_read(ops_data->lpc_fw_addr + offset, buf, len); +} + +static int ast_lpc_write(void *binding_data, const void *buf, + long offset, size_t len) +{ + struct astlpc_ops_data *ops_data = binding_data; + + mctp_prdebug("%s %zu bytes to offset 0x%lx (lpc: 0x%lx)", + __func__, len, offset, + ops_data->lpc_fw_addr + offset); + return lpc_fw_write(ops_data->lpc_fw_addr + offset, buf, len); +} + +static const struct mctp_binding_astlpc_ops astlpc_ops = { + .kcs_read = ast_kcs_reg_read, + .kcs_write = ast_kcs_reg_write, + .lpc_read = ast_lpc_read, + .lpc_write = ast_lpc_write, +}; + +static struct mctp_binding_astlpc *ast_binding; +static struct astlpc_ops_data *ops_data; + +/* Keyboard Controller Style (KCS) data register address */ +#define KCS_DATA_REG 0xca2 + +/* Keyboard Controller Style (KCS) status register address */ +#define KCS_STATUS_REG 0xca3 + +/* Serial IRQ number for KCS interface */ +#define KCS_SERIAL_IRQ 11 + +bool irq_active; +struct timer mctp_boot_timer; + +/* we need a poller to crank the mctp state machine during boot */ +static void ast_mctp_poller(struct timer *t __unused, + void *data __unused, uint64_t now __unused) +{ + mctp_astlpc_poll(ast_binding); + + /* once booted we can rely on the KCS interrupt */ + if ((opal_booting() && !irq_active)) + schedule_timer(&mctp_boot_timer, msecs_to_tb(5)); +} + +/* at runtime the interrupt should handle it */ +static void ast_mctp_interrupt(uint32_t chip_id __unused, + uint32_t irq_msk __unused) +{ + if (!irq_active) { + mctp_prerr("IRQ Active! Disabling boot poller..."); + irq_active = true; + } + + mctp_astlpc_poll(ast_binding); +} + +static struct lpc_client kcs_lpc_client = { + .reset = NULL, + .interrupt = ast_mctp_interrupt, + .interrupts = LPC_IRQ(KCS_SERIAL_IRQ), +}; + +static bool ast_mctp_supported(void) +{ + uint32_t tmp; + + /* + * Probe for MCTP support by reading the STAT register of KCS#4 + */ + tmp = 0; + return true; + + if (lpc_probe_read(OPAL_LPC_IO, KCS_STATUS_REG, &tmp, 1)) { + mctp_prdebug("KCS4 probe failed, skipping MCTP init"); + return false; + } + + return !!(tmp & 0x80); /* high bit indicates BMC is listening */ +} + +#define DESIRED_MTU 32768 + +static struct mctp_binding_astlpc *ast_mctp_binding(void) +{ + struct mctp_binding_astlpc *ast_binding; + + ops_data = zalloc(sizeof(struct astlpc_ops_data)); + if (!ops_data) + return NULL; + + /* + * 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 */ + ast_binding = mctp_astlpc_init(MCTP_BINDING_ASTLPC_MODE_HOST, + DESIRED_MTU, + NULL, + &astlpc_ops, + ops_data); + if (!ast_binding) { + mctp_prerr("binding init failed"); + goto err; + } + + /* register an lpc client so we get an interrupt */ + lpc_register_client(0, &kcs_lpc_client, IRQ_ATTR_TARGET_OPAL); + + init_timer(&mctp_boot_timer, ast_mctp_poller, ast_binding); + schedule_timer(&mctp_boot_timer, msecs_to_tb(5)); + + return ast_binding; + +err: + mctp_astlpc_destroy(ast_binding); + free(ops_data); + return NULL; +} + +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 ASTLPC_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(uint8_t eid, uint8_t *msg, int len) +{ + uint8_t tag = 0; + + return mctp_message_tx(mctp, eid, MCTP_MESSAGE_TO_DST, tag, msg, len); +} + +void ast_mctp_stop_polling(void) +{ + irq_active = true; +} + +#define HOST_MAX_INCOMING_MESSAGE_ALLOCATION 131072 + +/* + * Initialize mctp binding for hbrt and provide interfaces for sending + * and receiving mctp messages. + */ +int ast_mctp_init(void (*fn)(uint8_t src_eid, bool tag_owner, + uint8_t msg_tag, void *data, void *msg, + size_t len)) +{ + uint64_t start; + + if (!ast_mctp_supported()) + return OPAL_HARDWARE; + + /* skiboot's malloc/free/realloc are macros so they need + * wrappers + */ + mctp_set_alloc_ops(mctp_malloc, mctp_free, mctp_realloc); + + /* + * /-----\ /---------\ + * | bmc | (eid: 8) <- lpc/kcs -> (eid: 9) | skiboot | + * \-----/ \---------/ + * astlpc kcs binding + */ + mctp = mctp_init(); + if (!mctp) { + mctp_prerr("mctp init failed"); + return OPAL_HARDWARE; + } + +#ifdef ASTLPC_DEBUG + /* Setup the trace hook */ + mctp_set_log_custom(mctp_log); +#endif + + mctp_prinfo("libmctp initialized"); + + /* Set the max message size to be large enough */ + mctp_set_max_message_size(mctp, HOST_MAX_INCOMING_MESSAGE_ALLOCATION); + + /* Setup the message rx callback */ + mctp_set_rx_all(mctp, fn, NULL); + + /* Initialise the binding */ + ast_binding = ast_mctp_binding(); + if (!ast_binding) + goto err; + + /* Register the binding to the LPC bus we are using for this + * MCTP configuration. + */ + if (mctp_register_bus(mctp, + mctp_binding_astlpc_core(ast_binding), + HOST_EID)) { + mctp_prerr("failed to register bus"); + goto err; + } + + /* Initializing the channel requires running the poll function + * a few times to handle the initial setup since we need the + * BMC to reply. + * + * Unfortuntately there's no good way to determine if this + * worked or not so poll for a bit with a timeout. :( + * + * We have to check (bus->state == mctp_bus_state_constructed) + * otherwise mctp_message_tx() will reject the message. + * astlpc: host: Version negotiation got: 3 + */ + start = mftb(); + while (tb_compare(mftb(), start + msecs_to_tb(250)) == TB_ABEFOREB) + time_wait_ms(10); + + mctp_prwarn("%s - The mctp bus state should be correct now !!!", + __func__); + + return OPAL_SUCCESS; + +err: + mctp_prerr("Unable to initialize MCTP"); + mctp_destroy(mctp); + mctp = NULL; + + return OPAL_HARDWARE; +} + +void ast_mctp_exit(void) +{ + if (mctp) + mctp_destroy(mctp); + + mctp = NULL; +} diff --git a/include/ast.h b/include/ast.h index 5e932398..b0df95a6 100644 --- a/include/ast.h +++ b/include/ast.h @@ -91,6 +91,14 @@ void ast_setup_ibt(uint16_t io_base, uint8_t irq); /* MBOX configuration */ void ast_setup_sio_mbox(uint16_t io_base, uint8_t irq); +/* AST MCTP configuration */ +void ast_mctp_exit(void); +int ast_mctp_init(void (*fn)(uint8_t src_eid, bool tag_owner, + uint8_t msg_tag, void *data, void *msg, + size_t len)); +void ast_mctp_stop_polling(void); +int ast_mctp_message_tx(uint8_t eid, uint8_t *msg, int len); + #endif /* __SKIBOOT__ */ /* From patchwork Thu Apr 14 13:43:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=bW3Gcg6W; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLL00K59z9sGF for ; Thu, 14 Apr 2022 23:44:40 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLKz5wL8z2yfZ for ; Thu, 14 Apr 2022 23:44:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW3Gcg6W; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW3Gcg6W; 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 4KfLKT4wdYz2yY7 for ; Thu, 14 Apr 2022 23:44:13 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3xH7006202 for ; Thu, 14 Apr 2022 13:44:10 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=hIEVFlN6o6nSsDxHI/7YADVujnFczezVg6tQZaITqzc=; b=bW3Gcg6We3CUkS5hbA3JEEaoz05kwJAJHxZdR25YDhUF7PKv/bDsInq4Q9TB1rRKpBwL 4kiVLwGp7B7QyMYHwS1Xturk8n3IqNsWaTJrhFZVBOXdYSeEPtJZ/84CFwigTM85ST1J dGCLpwLQ4c2zodZIogb2U2gyeuh9BOv2NUctysffW4gng7IIZnaOsOWdBvl5GyvTALAX 9SFmc9ZYxR1QH/vTPRVHN7vSNwQGeAl/EulZdcU8OrZCahGcuscEZRcsbKJvfVZwVKMT Wm/gK2Pr8enrtwYsTTxoVACy0PHKF43Lg4kDdI+GuqCa5Vyg9Vy1BRBBuDGovAf+jy4k dg== Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fedxsrp0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfwwC025094 for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04fra.de.ibm.com with ESMTP id 3fb1s8y053-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:08 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi5T027656480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:05 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA3B6A406D for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9F51DA406F for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:46 +0200 Message-Id: <20220414134404.39888-4-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: xmryHAp6Ek8l1WBUOGlP5mgOQsYPmT4t X-Proofpoint-GUID: xmryHAp6Ek8l1WBUOGlP5mgOQsYPmT4t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 03/21] core/pldm: PLDM over MCTP Binding X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Enable the mctp binding over LPC bus interface and new wrappers to send and receive PLDM messages over the mctp library. PLDM is supported as a message type over MCTP. PLDM over MCTP binding defines the format of PLDM over MCTP messages. An MCTP Endpoint is the terminus for MCTP communication. A physical device that supports MCTP may provide one or more MCTP Endpoints. Endpoints are addressed using a logical address called the Endpoint ID, or EID. EIDs in MCTP are analogous to IP Addresses in Internet Protocol networking. The BMC EID default is 8. First byte of the PLDM over MCTP Message Fields identifies the MCTP message as carrying a PLDM message: Message Type (7 bits) PLDM = 0x01 (000_0001b). Signed-off-by: Christophe Lombard --- core/Makefile.inc | 6 +- core/pldm/Makefile.inc | 13 +++++ core/pldm/pldm-common.c | 118 ++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 42 ++++++++++++++ include/pldm.h | 18 ++++++ 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 core/pldm/Makefile.inc create mode 100644 core/pldm/pldm-common.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..005c7b94 --- /dev/null +++ b/core/pldm/Makefile.inc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# Copyright 2022 IBM Corp + +PLDM_DIR ?= core/pldm +SUBDIRS += $(PLDM_DIR) + +CPPFLAGS += -I$(SRC)/pldm/libpldm/ +CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ + +PLDM_OBJS = pldm-common.o + +PLDM = $(PLDM_DIR)/built-in.a +$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-common.c b/core/pldm/pldm-common.c new file mode 100644 index 00000000..5271dfbd --- /dev/null +++ b/core/pldm/pldm-common.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include +#include "pldm.h" + +/* + * Print content of PLDM message in hex mode. + * 15 bytes per line. + * Ex: pldm_send: 000: 08 01 00 00 02 00 01 + */ +void printbuf(const char *name, const char *msg, int len) +{ + int i, j; + char linebuf[128]; + + linebuf[0] = 0; + + for (i = 0; i < len; i += j) { + linebuf[0] = 0; + for (j = 0; i + j < len && j < 15; j++) { + char s[5]; + + snprintf(s, 5, "%02x ", msg[i + j]); + strcat(linebuf, s); + } + prlog(PR_TRACE, "%s: %03x: %s\n", name, i, linebuf); + } +} + +/* + * Send PLDM message over MCTP + */ +int pldm_send(uint8_t dest_id, uint8_t *buf, int len) +{ + uint8_t *msg; + int rc; + + /* Message TYPE: PLDM = 0x01 (000_0001b) - DSP0240 */ + msg = malloc(len + 1); + msg[0] = 0x01; + memcpy(&msg[1], buf, len); + + rc = ast_mctp_message_tx(dest_id, msg, len + 1); + free(msg); + + return rc; +} + +/* + * Handle messages received from MCTP + */ +static int pldm_handle(uint8_t eid, const uint8_t *buf, int len) +{ + struct pldm_rx_data rx; + + if (len < sizeof(rx.msg->hdr)) { + prlog(PR_ERR, "%s: packet is smaller than pldm header\n", __func__); + return OPAL_EMPTY; + } + + memset(&rx, 0, sizeof(rx)); + rx.msg = (struct pldm_msg *) buf; + rx.source_eid = eid; + rx.msg_len = len; + + if (unpack_pldm_header(&rx.msg->hdr, &rx.hdrinf)) { + prlog(PR_ERR, "%s: unable to decode header\n", __func__); + return OPAL_EMPTY; + } + + return OPAL_UNSUPPORTED; +} + +/* + * MCTP message rx callback + */ +static void pldm_rx_message(uint8_t eid, bool tag_owner __unused, + uint8_t msg_tag __unused, void *data __unused, + void *vmsg, size_t len) +{ + uint8_t *msg = vmsg; + + prlog(PR_TRACE, "message received: msg: %p, len %zd (eid: %d)\n", + msg, len, eid); + + /* pldm message type */ + if ((msg[0] & 0x7f) != 0x01) { + prlog(PR_ERR, "%s - not a pldm message type\n", __func__); + return; + } + + pldm_handle(eid, &msg[1], len - 1); +} + +int pldm_mctp_init(void) +{ + int rc; + + /* MCTP Binding */ + rc = ast_mctp_init(pldm_rx_message); + 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..84649cf1 --- /dev/null +++ b/core/pldm/pldm.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __COREPLDM_H__ +#define __COREPLDM_H__ + +#include +#include + +/* Common support */ + +void printbuf(const char *name, const char *msg, int len); + +/* + * EID is the MCTP endpoint ID, which aids in routing MCTP packets. + * For the EIDs: the valid range is 8-254. + * We are saying that BMC is EID 8 and Skiboot is HOST_EID 9 + */ +#define BMC_EID 8 +#define HOST_EID 9 + +struct pldm_rx_data { + struct pldm_header_info hdrinf; /* parsed message header */ + + struct pldm_msg *msg; + int msg_len; + int source_eid; +}; + +struct pldm_type { + const char *name; + int pldm_type_id; + ver32_t version; + + struct list_head commands; + struct list_node link; +}; + +int pldm_send(uint8_t dest_id, uint8_t *buf, int len); + +#endif /* __COREPLDM_H__ */ diff --git a/include/pldm.h b/include/pldm.h new file mode 100644 index 00000000..3d01086f --- /dev/null +++ b/include/pldm.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __PLDM_H__ +#define __PLDM_H__ + +/** + * PLDM over MCTP initialization + */ +int pldm_mctp_init(void); + +/** + * PLDM over MCTP stop + */ +void pldm_mctp_exit(void); + +#endif /* __PLDM_H__ */ From patchwork Thu Apr 14 13:43:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=q8KblDnp; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLNF4yVvz9sGF for ; Thu, 14 Apr 2022 23:46:37 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLNF3nHbz3bqy for ; Thu, 14 Apr 2022 23:46:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=q8KblDnp; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=q8KblDnp; 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 4KfLKn0KSkz3bbn for ; Thu, 14 Apr 2022 23:44:28 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3xoc019811 for ; Thu, 14 Apr 2022 13:44:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=xhQcQ5ylklhSe4JHwAxbQR8xtFbjx3VHfRdzgKqk0fg=; b=q8KblDnp5KItRnKqy3YwFZ+k2kZq2b+bibItcfQnxsm2feXUORJhkNkdGIg3V5MXaCZ1 Z1H+FBfEfoSD65La0l1K8OdBecQD1cxGJl9BTa5nDvIXF6dJxAYnKFHAt15VASaR9apv NgJ1q+OxGMQc/6+hG/6fJfEcsMxozY+96wPZc6wOduq3BGr4Pob67LjK2BrM/RTcTadq lTezoyIse9RJ81EQNUdTu43e5k3JI8KCPCTJVi+eg3OL18xH0+UJ4Nr+CeaZCdgaVlBW nLmfFANKoR4KiWelsmCe6jdujCmMAIW3YYS34UP5egkxfoiHIGdmp9P8pN8xJ0PKEwVQ XQ== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fegbrwpae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg0Lh006309 for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3fb1s90pfq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:08 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi66l27656482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:06 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15C3BA406D for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF836A406E for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:05 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:47 +0200 Message-Id: <20220414134404.39888-5-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4Xb9LWrpvqM8VCtpKQhuNQe5gcuBfp0x X-Proofpoint-ORIG-GUID: 4Xb9LWrpvqM8VCtpKQhuNQe5gcuBfp0x X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 priorityscore=1501 clxscore=1015 lowpriorityscore=0 spamscore=0 malwarescore=0 bulkscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 04/21] core/pldm: Add PLDM responder support X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" PLDM defines data representations and commands that abstract the platform management hardware. A PLDM Terminus (or responder) is defined as the point of communication termination for PLDM messages and the PLDM functions associated with those messages. A PLDM terminus is not required to process more than one request at a time (that is, it can be "single threaded" and does not have to accept and act on new requests until it has finished responding to any previous request). Some PLDM control and discovery requests (PLDM_TYPE = PLDM_BASE) are mandatory a PLDM terminus has to answer. These following mandatory PLDM command codes for PLDM messaging control and discovery will be defined in next patches. GetTID 0x02 GetPLDMVersion 0x03 GetPLDMTypes 0x04 GetPLDMCommands 0x05 Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-common.c | 18 ++++- core/pldm/pldm-responder.c | 136 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 ++ 4 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 core/pldm/pldm-responder.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 005c7b94..3909c86f 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,7 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ -PLDM_OBJS = pldm-common.o +PLDM_OBJS = pldm-common.o pldm-responder.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-common.c b/core/pldm/pldm-common.c index 5271dfbd..d6ab3273 100644 --- a/core/pldm/pldm-common.c +++ b/core/pldm/pldm-common.c @@ -75,6 +75,14 @@ static int pldm_handle(uint8_t eid, const uint8_t *buf, int len) return OPAL_EMPTY; } + switch (rx.hdrinf.msg_type) { + case PLDM_REQUEST: + return pldm_rx_handle_request(&rx); + break; + default: + break; + } + return OPAL_UNSUPPORTED; } @@ -105,9 +113,17 @@ int pldm_mctp_init(void) /* MCTP Binding */ rc = ast_mctp_init(pldm_rx_message); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to bind MCTP\n"); + goto out; + } + + /* Register mandatory commands we'll respond to */ + rc = pldm_mctp_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..7e5ca52f --- /dev/null +++ b/core/pldm/pldm-responder.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include +#include +#include "pldm.h" + +struct pldm_cmd { + const char *name; + int pldm_cmd_id; + + int (*handler)(const struct pldm_rx_data *req); + + struct list_node link; /* link in the msg type's command list */ +}; + +/* + * Send a response with just a completion code and no payload + */ +static int pldm_cc_resp(const struct pldm_rx_data *req, uint8_t type, + uint8_t command, uint8_t cc) +{ + char response_msg[PKT_SIZE(uint8_t)]; + int rc; + + memset(response_msg, 0, sizeof(response_msg)); + + encode_cc_only_resp(req->hdrinf.instance, + type, + command, + cc, + (struct pldm_msg *)response_msg); + + rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send response message containing only cc, " + "rc = %d, cc = %d\n", rc, cc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +/* + * PLDM Type / Command wrangling. + */ +LIST_HEAD(pldm_type_list); + +static const struct pldm_type *find_type(int type_id) +{ + struct pldm_type *iter; + + list_for_each(&pldm_type_list, iter, link) { + if (iter->pldm_type_id == type_id) + return iter; + } + + return NULL; +} + +static const struct pldm_cmd *find_cmd(const struct pldm_type *type, int cmd) +{ + struct pldm_cmd *iter; + + list_for_each(&type->commands, iter, link) + if (iter->pldm_cmd_id == cmd) + return iter; + + return NULL; +} + +static void pldm_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_rx_handle_request(struct pldm_rx_data *rx) +{ + const struct pldm_type *t; + const struct pldm_cmd *c; + + prlog(PR_INFO, "Receive PLDM request from BMC, type: 0x%x, command: 0x%x\n", + rx->hdrinf.pldm_type, rx->hdrinf.command); + + t = find_type(rx->hdrinf.pldm_type); + if (!t) { + prlog(PR_ERR, "Type not supported, type: 0x%x\n", + rx->hdrinf.pldm_type); + pldm_cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_ERROR_INVALID_PLDM_TYPE); + return OPAL_UNSUPPORTED; + } + + c = find_cmd(t, rx->hdrinf.command); + if (!c) { + prlog(PR_ERR, "Command not supported, type: 0x%x, command: 0x%x\n", + rx->hdrinf.pldm_type, rx->hdrinf.command); + pldm_cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_ERROR_UNSUPPORTED_PLDM_CMD); + return OPAL_UNSUPPORTED; + } + + return c->handler(rx); +} + +int pldm_mctp_responder_init(void) +{ + /* Register mandatory commands we'll respond to - DSP0240 */ + pldm_add_type(&pldm_base_type); + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 84649cf1..2887bd32 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -20,6 +20,8 @@ void printbuf(const char *name, const char *msg, int len); #define BMC_EID 8 #define HOST_EID 9 +#define PKT_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) + struct pldm_rx_data { struct pldm_header_info hdrinf; /* parsed message header */ @@ -39,4 +41,8 @@ struct pldm_type { int pldm_send(uint8_t dest_id, uint8_t *buf, int len); +/* Responder support */ +int pldm_rx_handle_request(struct pldm_rx_data *rx); +int pldm_mctp_responder_init(void); + #endif /* __COREPLDM_H__ */ From patchwork Thu Apr 14 13:43:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ayZ9Dlpr; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLMp3y2Nz9sGF for ; Thu, 14 Apr 2022 23:46:14 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLMp2QPGz3bfr for ; Thu, 14 Apr 2022 23:46:14 +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=ayZ9Dlpr; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ayZ9Dlpr; 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 4KfLKd0tX0z3bcB for ; Thu, 14 Apr 2022 23:44:20 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC409c024931 for ; Thu, 14 Apr 2022 13:44:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=nplfENgOjVtLKy7NGEqYXCIVymj99zTQJJVRzKUka2I=; b=ayZ9DlprBXe4IlvYkKZogd0QotIX+AZpiEU0Ixs2k9h9Hn9n5zlJcJ3rLt9Dxo39iWtx /+tdIkUemiDrWhvHs9RgtAXYsggP/R3Z+WP4hnrXNkRiZiS87s5xe3DBHGucPDVbFycJ OBQczPgAICcbXABFyxUYmgthmzf03KNZgVXFdVApDwNXS4gcKjGeW6Jn8vdNZlu+tiry sYPJF2sLMK0KMZu4b4tYX2A3kj6MQnBEzqJBooW7zXpkUvPqIP3sA4ft08Z1eAKWMTaX lrK2gAtmAAZ+haWh0Xg9DsROPk7GGYs7GEtWz7Hl5HG+o05CPOoepOtu+ucFhtMJflDU wg== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fegjuwe3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:10 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfsW7031639 for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma01fra.de.ibm.com with ESMTP id 3fb1s8xyuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:08 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi67Y27656484 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:06 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 55F8EA406D for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2B232A406F for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:48 +0200 Message-Id: <20220414134404.39888-6-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: uZbhpTviHUsFl0s25tHR1laWoH2iR7Tc X-Proofpoint-ORIG-GUID: uZbhpTviHUsFl0s25tHR1laWoH2iR7Tc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=869 impostorscore=0 suspectscore=0 malwarescore=0 spamscore=0 phishscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 05/21] core/pldm: Encode GetTID response X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" A PLDM Terminus is defined as the point of communication termination for PLDM messages and the PLDM functions associated with those messages. Given a PLDM terminus, a mechanism is required that can uniquely identify each terminus so that the semantic information can be bound to that identification. The Terminus ID (TID) is a value that identifies a PLDM terminus. TIDs are used in PLDM messages when it is necessary to identify the PLDM terminus that is the source of the PLDM Message. The GetTID command is used to retrieve the present Terminus ID (TID) setting for a PLDM Terminus. Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/pldm/pldm-responder.c | 50 ++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 +++++ 2 files changed, 56 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 7e5ca52f..3ac9126d 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -87,6 +87,17 @@ static void pldm_add_type(struct pldm_type *new_type) new_type->name, new_type->pldm_type_id); } +static void pldm_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 */ @@ -96,6 +107,44 @@ static struct pldm_type pldm_base_type = { .version = { 0xF1, 0xF0, 0xF0, 0x00 }, }; +/* + * GetTID command (0x02) + * The GetTID command is used to retrieve the present Terminus ID (TID) + * setting for a PLDM Terminus. + */ +static int base_get_tid_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_tid_resp)]; + int rc; + + memset(response_msg, 0, sizeof(response_msg)); + + rc = encode_get_tid_resp(req->hdrinf.instance, + PLDM_SUCCESS, + HOST_TID, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetTID response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_tid = { + .name = "PLDM_GET_TID", + .pldm_cmd_id = PLDM_GET_TID, + .handler = base_get_tid_handler, +}; + int pldm_rx_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *t; @@ -131,6 +180,7 @@ int pldm_mctp_responder_init(void) { /* Register mandatory commands we'll respond to - DSP0240 */ pldm_add_type(&pldm_base_type); + pldm_add_cmd(&pldm_base_type, &pldm_base_get_tid); return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 2887bd32..25155af1 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -20,6 +20,12 @@ void printbuf(const char *name, const char *msg, int len); #define BMC_EID 8 #define HOST_EID 9 +/* + * Skiboot's PLDM Terminus ID. + * BMC TID is 1, HB is 2, Skiboot is 3. + */ +#define HOST_TID 3 + #define PKT_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) struct pldm_rx_data { From patchwork Thu Apr 14 13:43:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=b+ZxqzTe; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLKs0MxLz9sGF for ; Thu, 14 Apr 2022 23:44:33 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLKr6Kfmz3bVd for ; Thu, 14 Apr 2022 23:44:32 +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=b+ZxqzTe; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=b+ZxqzTe; 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 4KfLKT5hs2z2yZd for ; Thu, 14 Apr 2022 23:44:13 +1000 (AEST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC40Ew015779 for ; Thu, 14 Apr 2022 13:44:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=0Wzzpzhtrsc3mdSC6ErxWQX+nJEWL3rAnCmBCNtHRLY=; b=b+ZxqzTeTUqvchKrgjorNXTuW+LJIkn/zZUA/xUmcxHKb3mkAUiTEb5RAQmdOxw6AfIp pJYTh+Q2lfI7qaXp3XdhORE2omVBCqRRadBN35JuPJCGUodlNFQTVTLg2xnX8H+wSFra FspIR3N6+xmzDG1wO2YMVZJF7+6SiNLuQkXJ2BloZHpA1HZUnSSRvffbz6GLfXzPh9fl kX0ye/uSkXkQR8sFOmPSJcQaxnu9Gnl1hIkpBOGVrFOYWvc39txKXqT1E76y5gXMbNy1 Dt4+22gD8GHkyFMJd6f5AIoIBXqeayB2DHFdjppQmE41Jdc5C53uW9MkMfuLgLkMcaus Mg== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fefyd632v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg1x4006314 for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3fb1s90pfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:08 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi6xi27656486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:06 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94378A406D for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A4DBA406E for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:49 +0200 Message-Id: <20220414134404.39888-7-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: n4Vmf2lUZdex4Hjpf8ewOKm0wjXLWY_k X-Proofpoint-ORIG-GUID: n4Vmf2lUZdex4Hjpf8ewOKm0wjXLWY_k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 spamscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 3ac9126d..9e44efc8 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -145,6 +145,57 @@ static struct pldm_cmd pldm_base_get_tid = { .handler = base_get_tid_handler, }; +/* + * GetPLDMTypes (0x04) + * The GetPLDMTypes command can be used to discover the PLDM type + * capabilities supported by a PLDM terminus and to get a list of the + * PLDM types that are supported. + */ +static int base_get_types_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_types_resp)]; + bitmap_elem_t type_map[BITMAP_ELEMS(32)]; + struct pldm_type *iter; + int rc; + + /* + * build the supported type list from the registered type + * handlers + */ + memset(type_map, 0, sizeof(type_map)); + list_for_each(&pldm_type_list, iter, link) + bitmap_set_bit(type_map, iter->pldm_type_id); + + for (int i = 0; i < BITMAP_ELEMS(32); i++) + type_map[i] = cpu_to_le64(type_map[i]); + + memset(response_msg, 0, sizeof(response_msg)); + rc = encode_get_types_resp(req->hdrinf.instance, + PLDM_SUCCESS, + (bitfield8_t *)type_map, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMTypes Error, rc: %d\n", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMTypes response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_types = { + .name = "PLDM_GET_PLDM_TYPES", + .pldm_cmd_id = PLDM_GET_PLDM_TYPES, + .handler = base_get_types_handler, +}; + int pldm_rx_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *t; @@ -181,6 +232,7 @@ int pldm_mctp_responder_init(void) /* Register mandatory commands we'll respond to - DSP0240 */ pldm_add_type(&pldm_base_type); pldm_add_cmd(&pldm_base_type, &pldm_base_get_tid); + pldm_add_cmd(&pldm_base_type, &pldm_base_get_types); return OPAL_SUCCESS; } From patchwork Thu Apr 14 13:43:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=eHnqmmBj; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLL72QtCz9sGF for ; Thu, 14 Apr 2022 23:44:47 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLL71P6nz3bcC for ; Thu, 14 Apr 2022 23:44:47 +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=eHnqmmBj; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=eHnqmmBj; 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 4KfLKV12Brz2yK2 for ; Thu, 14 Apr 2022 23:44:13 +1000 (AEST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3xCP015704 for ; Thu, 14 Apr 2022 13:44:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=po5lJwTNFQybODYd7quT/+Et6hMXnk7y612oLoSymp4=; b=eHnqmmBjA5VkJRGwx/4Au2bZBd48IrmYMYLmuRd3ie0k6xF9b7AVJA0+r1pCGEC7NBd1 FaqAi6rztU7SbvgPJzd8bUXCzFWWZSmk/G0XZLi1mCHiV+Zs3Rb64sy7x34w6wDq+u0S li8o4HmliYCyKSyXK6g3J4u9rMVk9nIwPG21FInX1Zb1W1e9pIbdsq/PKqAriWIasxlz B9zzW/6uROMV+gXaRZrNj1polngr7nMigqU38ZQ/jsdlFpWimjv0lsZf7SZJz0MPMLq6 EzkM5v1OZYR/Tlp22K/jnJ0Zx8P/tPtS6Fg8Sxx2VEiWKUhouSuBbwCbWM7q5Eew3EdK 2g== Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fefyd632y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg9oJ025157 for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04fra.de.ibm.com with ESMTP id 3fb1s8y055-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi6kt33685792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:07 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2B88A406F for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A89A3A406E for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:50 +0200 Message-Id: <20220414134404.39888-8-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: S-8SRAienOQVyWVIrOnyh69cl86ErObP X-Proofpoint-ORIG-GUID: S-8SRAienOQVyWVIrOnyh69cl86ErObP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 spamscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 91 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 9e44efc8..09b49021 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -196,6 +196,96 @@ static struct pldm_cmd pldm_base_get_types = { .handler = base_get_types_handler, }; +/* + * Extended error codes defined for the Base command set. + */ +#define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83 +#define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84 + +/* + * GetPLDMCommands (0x05) + * The GetPLDMCommands command can be used to discover the PLDM command + * capabilities supported by aPLDM terminus for a specific PLDM Type and + * version as a responder. + */ +static int base_get_commands_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_commands_resp)]; + bitmap_elem_t cmd_map[BITMAP_ELEMS(256)]; + const struct pldm_type *type; + const struct pldm_cmd *iter; + size_t payload_len; + ver32_t version; + uint8_t type_id; + int rc; + + payload_len = req->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_commands_req(req->msg, payload_len, + &type_id, &version); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPLDMCommands request, rc = %d", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + type = find_type(type_id); + if (!type) { + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_PLDM_TYPE_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + if (memcmp(&type->version, &version, sizeof(version))) { + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_PLDM_VERSION_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + /* + * build the supported type list from the registered type + * handlers + */ + memset(cmd_map, 0, sizeof(cmd_map)); + list_for_each(&type->commands, iter, link) + bitmap_set_bit(cmd_map, iter->pldm_cmd_id); + + /* fix the endian */ + for (int i = 0; i < BITMAP_ELEMS(256); i++) + cmd_map[i] = cpu_to_le64(cmd_map[i]); + + memset(response_msg, 0, sizeof(response_msg)); + + /* create a PLDM response message for GetPLDMCommands */ + rc = encode_get_commands_resp(req->hdrinf.instance, + PLDM_SUCCESS, + (bitfield8_t *)cmd_map, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMCommands Error, rc: %d\n", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMCommands response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_commands = { + .name = "PLDM_GET_PLDM_COMMANDS", + .pldm_cmd_id = PLDM_GET_PLDM_COMMANDS, + .handler = base_get_commands_handler, +}; + int pldm_rx_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *t; @@ -233,6 +323,7 @@ int pldm_mctp_responder_init(void) pldm_add_type(&pldm_base_type); pldm_add_cmd(&pldm_base_type, &pldm_base_get_tid); pldm_add_cmd(&pldm_base_type, &pldm_base_get_types); + pldm_add_cmd(&pldm_base_type, &pldm_base_get_commands); return OPAL_SUCCESS; } From patchwork Thu Apr 14 13:43:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617255 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=rt+tR97O; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLN64Bvqz9sGF for ; Thu, 14 Apr 2022 23:46:30 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLN635M5z3bXG for ; Thu, 14 Apr 2022 23:46:30 +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=rt+tR97O; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=rt+tR97O; 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 4KfLKn0Glmz3bbQ for ; Thu, 14 Apr 2022 23:44:28 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3x7s019506 for ; Thu, 14 Apr 2022 13:44:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=+LkRL6jAeRa2KeoGfRNF5PeCZVSqZHKiYzIa42a3XLA=; b=rt+tR97O+KuTV5LWGUucTZ91A3mTpcJP4fbJRok0rL/AvEYSPKT40ZCdBH5/GSNZ+ARs j1U7rKFgbtcoMOYSwp68q1ryyeEBTUWZBSDbEOH6ZPpjYWuvNKjl696t7pm/eg7jL8Dx tNanDlncA0I0JSB/dqEjrIbHcPHR9944/a+dBugW4brIyy7iZfzGwuz+LomLXaT3+OWM qQAnOAESLaifD4p64hIENjmx9R7GV+Rle6GRowpT8+ICeGygotlmjGiePuO0gbYcCEj9 uP5LVFHvI8XZMfacIYMB99KGbkJj5t7tXvmAuB43gTjTfLGwtjRlt9fbHCys7YYRj9Nr Bw== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fed0ksn8b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg4d4006336 for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3fb1s90pfs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi7LB29819356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:07 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E41CA407D for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7D45A406E for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:51 +0200 Message-Id: <20220414134404.39888-9-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: GJ4aQQrnJJMKCQDACX4t0NSZehrmsXDQ X-Proofpoint-GUID: GJ4aQQrnJJMKCQDACX4t0NSZehrmsXDQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 09b49021..16ce6b1f 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -199,6 +199,7 @@ static struct pldm_cmd pldm_base_get_types = { /* * Extended error codes defined for the Base command set. */ +#define INVALID_TRANSFER_OPERATION_FLAG 0x80 #define INVALID_PLDM_TYPE_IN_REQUEST_DATA 0x83 #define INVALID_PLDM_VERSION_IN_REQUEST_DATA 0x84 @@ -286,6 +287,88 @@ static struct pldm_cmd pldm_base_get_commands = { .handler = base_get_commands_handler, }; +/* + * GetPLDMVersion (0x03) + * The GetPLDMVersion command can be used to retrieve the PLDM base + * specification versions that the PLDM terminus supports, as well as + * the PLDM Type specification versions supported for each PLDM Type. + */ +static int base_get_version_handler(const struct pldm_rx_data *req) +{ + uint32_t tmp[2]; + char response_msg[PKT_SIZE(struct pldm_get_version_resp) + sizeof(tmp)]; + const struct pldm_type *type; + uint8_t type_id, opflag; + size_t payload_len; + uint32_t xfer_handle; + int rc; + + payload_len = req->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_version_req(req->msg, payload_len, + &xfer_handle, + &opflag, + &type_id); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPLDMVersion request, rc = %d", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + /* reject multipart requests */ + if (opflag != PLDM_GET_FIRSTPART) { + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_TRANSFER_OPERATION_FLAG); + return OPAL_PARAMETER; + } + + type = find_type(type_id); + if (!type) { + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + INVALID_PLDM_TYPE_IN_REQUEST_DATA); + return OPAL_PARAMETER; + } + + /* pack a scratch buffer with our version(s) and CRC32 the lot */ + memcpy(&tmp[0], &type->version, 4); + + tmp[1] = cpu_to_le32(pldm_crc32(&type->version, 4)); + + memset(response_msg, 0, sizeof(response_msg)); + + /* create a PLDM response for GetPLDMVersion */ + rc = encode_get_version_resp(req->hdrinf.instance, + PLDM_SUCCESS, + 0x0, /* no handle */ + PLDM_START_AND_END, + (ver32_t *) tmp, + sizeof(tmp), + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPLDMVersion Error, rc: %d\n", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_send(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetPLDMVersion response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_base_get_version = { + .name = "PLDM_GET_PLDM_VERSION", + .pldm_cmd_id = PLDM_GET_PLDM_VERSION, + .handler = base_get_version_handler, +}; + int pldm_rx_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *t; @@ -324,6 +407,7 @@ int pldm_mctp_responder_init(void) pldm_add_cmd(&pldm_base_type, &pldm_base_get_tid); pldm_add_cmd(&pldm_base_type, &pldm_base_get_types); pldm_add_cmd(&pldm_base_type, &pldm_base_get_commands); + pldm_add_cmd(&pldm_base_type, &pldm_base_get_version); return OPAL_SUCCESS; } From patchwork Thu Apr 14 13:43:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=VRUj9PSW; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLLG632Zz9sGF for ; Thu, 14 Apr 2022 23:44:54 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLLG4zLZz3bdj for ; Thu, 14 Apr 2022 23:44: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=VRUj9PSW; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=VRUj9PSW; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KfLKV3vbMz2yY7 for ; Thu, 14 Apr 2022 23:44:14 +1000 (AEST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC401c012104 for ; Thu, 14 Apr 2022 13:44:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=bAjoVsltNRCyxJsbBJkPe3tre51P/qJewqYc4m88MZA=; b=VRUj9PSW7laq9XZtJvrBZEGrwnS7XBeIJ7k0bzEACG1hDTzRBDU7Ota4ANnM1nwg8uIO R6aGit4AkzjJC46Fza53UhQ/ZI14kIrPLDTHO+Ntv5kpZ1rJMPpxkG7ysU59yF76Xvm4 2Bh7EjqGW7JvcpeS687BeiWmuovU1lQYSBzQrlw4DNtZYiXmeHu8P/XJw7FGmLixvQ1G yHw4glQcOwNNGIEe6GQVRMv5C4IOKPMD5CHgWEa1GyDqxTHK9Pzk62QgK21JzaQE/FEU hNFnGtI9gnFHfIIUdzGTyiUgDmYFnPWg7BuNfq86Ru1+2RykQa19V5sfPReZYPCqtWpp uQ== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fefpgpe60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfxBU024804 for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3fb1dj8ppt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi71N29819360 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:07 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 61B28A406F for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 335C6A406D for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:52 +0200 Message-Id: <20220414134404.39888-10-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: tjPHElBLuotU54IgkWoeDk8ArZlsUpk_ X-Proofpoint-ORIG-GUID: tjPHElBLuotU54IgkWoeDk8ArZlsUpk_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 priorityscore=1501 impostorscore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 09/21] core/pldm: Implement PLDM requester X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Implement a way for sending PLDM requests for specific PLDM commands. Send a PLDM request message. Wait for corresponding response message, which once received, is returned to the caller. If there's data available, return success only if data is a PLDM response message that matches instance, pldm_type and command code. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-common.c | 2 + core/pldm/pldm-requester.c | 268 +++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 + 4 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-requester.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 3909c86f..c431288f 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,7 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ -PLDM_OBJS = pldm-common.o pldm-responder.o +PLDM_OBJS = pldm-common.o pldm-responder.o pldm-requester.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-common.c b/core/pldm/pldm-common.c index d6ab3273..a7d4dfdc 100644 --- a/core/pldm/pldm-common.c +++ b/core/pldm/pldm-common.c @@ -76,6 +76,8 @@ static int pldm_handle(uint8_t eid, const uint8_t *buf, int len) } switch (rx.hdrinf.msg_type) { + case PLDM_RESPONSE: + return pldm_rx_handle_response(&rx); case PLDM_REQUEST: return pldm_rx_handle_request(&rx); break; diff --git a/core/pldm/pldm-requester.c b/core/pldm/pldm-requester.c new file mode 100644 index 00000000..96322cae --- /dev/null +++ b/core/pldm/pldm-requester.c @@ -0,0 +1,268 @@ +// 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" + +struct pldm_request { + /* originating request params */ + int dest; + int instance; + int cmd_code; + int type; + + uint64_t timeout_ms; + uint64_t start_time; + + void *buf; + int len; + + /* completion callback */ + void (*complete)(struct pldm_request *req, + struct pldm_rx_data *resp); + void *cb_data; + int rc; + + struct list_node link; +}; + +/* + * Sent out and waiting on a response. + */ +static struct pldm_request *active_request; + +static bool matches_request(const struct pldm_rx_data *rx, + const struct pldm_request *req) +{ + if (req->instance != rx->hdrinf.instance) + return false; + if (req->type != rx->hdrinf.pldm_type) + return false; + if (req->cmd_code != rx->hdrinf.command) + return false; + + return true; +} + +/* + * Requests that are ready to send. + */ +LIST_HEAD(pldm_request_queue); + +static bool request_timed_out(struct pldm_request *req) +{ + uint64_t deadline = req->start_time + msecs_to_tb(req->timeout_ms); + + return tb_compare(mftb(), deadline) == TB_AAFTERB; +} + +/* + * Send the PLDM request. + */ +static void start_req(struct pldm_request *r) +{ + if (active_request) { + prlog(PR_ERR, "%s: request already active?\n", + __func__); + return; + } + + r->start_time = mftb(); + active_request = r; + + pldm_send(r->dest, r->buf, r->len); +} + +static void complete_request(struct pldm_rx_data *rx) +{ + struct pldm_request *req = active_request; + + if (req->complete) + req->complete(req, rx); + + active_request = NULL; +} + +/* + * Add PLDM request in the queue/ + */ +static int queue_request(int dest_eid, void *buf, int len, + uint64_t timeout_ms, + void (*complete)(struct pldm_request *, + struct pldm_rx_data *), + void *cb_data) +{ + struct pldm_header_info hdrinf; + struct pldm_request *pending; + + if (active_request) + return OPAL_BUSY; + + if (unpack_pldm_header(buf, &hdrinf)) { + prlog(PR_ERR, "%s: error parsing pldm header\n", + __func__); + return OPAL_PARAMETER; + } + + pending = zalloc(sizeof(struct pldm_request)); + + pending->dest = dest_eid; + pending->instance = hdrinf.instance; + pending->type = hdrinf.pldm_type; + pending->cmd_code = hdrinf.command; + pending->timeout_ms = timeout_ms; + + pending->buf = buf; + pending->len = len; + + pending->complete = complete; + pending->cb_data = cb_data; + + start_req(pending); + + return OPAL_SUCCESS; +} + +/* + * Synchronus request handling. + */ +struct pldm_do_request_data { + void **buf; + size_t *len; + bool done; + int rc; +}; + +static void do_request_cb(struct pldm_request *req, + struct pldm_rx_data *resp) +{ + struct pldm_do_request_data *cb_data = req->cb_data; + int len = resp->msg_len; + + if (resp && !request_timed_out(req)) { + *cb_data->len = len; + *cb_data->buf = malloc(len); + memcpy(*cb_data->buf, resp->msg, len); + + cb_data->rc = OPAL_SUCCESS; + } else { + *cb_data->len = 0; + *cb_data->buf = NULL; + cb_data->rc = OPAL_TIMEOUT; + } + + cb_data->done = true; + + free(req); +} + +/* + * Timeout :( + */ +static void pldm_timeout_cb(struct timer *t __unused, void *data, + uint64_t now __unused) +{ + struct pldm_do_request_data *cb_data = data; + + if (cb_data->done) + return; + + prlog(PR_ERR, "%s - request timedout!\n", __func__); + complete_request(NULL); +} + +/* + * Send a PLDM request and spin until we get a reply. + */ +int pldm_do_request(uint8_t dest_eid, + void *request_msg, size_t request_len, + void **response_msg, size_t *response_len) +{ + uint64_t now, queue_start, resp_start; + struct pldm_do_request_data cb_data; + struct timer pldm_timeout; + uint64_t timeout_ms; + int retries = 10; + int rc; + + /* Start timer ton control a timeout from the PLDM terminus */ + init_timer(&pldm_timeout, pldm_timeout_cb, &cb_data); + timeout_ms = 8000; + + memset(&cb_data, 0, sizeof(cb_data)); + cb_data.buf = response_msg; + cb_data.len = response_len; + + /* Send PLDM request */ + queue_start = mftb(); + do { + rc = queue_request(dest_eid, + request_msg, request_len, + timeout_ms, do_request_cb, + &cb_data); + if (rc == OPAL_BUSY) { + time_wait_ms(10); + retries--; + } + if (!retries) { + prlog(PR_ERR, "%s - timed out trying to queue " + "PLDM request\n", __func__); + return OPAL_BUSY; + } + } while (rc == OPAL_BUSY); + + if (rc) { + prlog(PR_ERR, "%s: Error %d while queuing request\n", + __func__, rc); + return rc; + } + + /* Wait for answer from the PLDM terminus */ + schedule_timer(&pldm_timeout, msecs_to_tb(timeout_ms)); + resp_start = mftb(); + do { + time_wait_ms(5); + } while (!cb_data.done); + + cancel_timer(&pldm_timeout); + now = mftb(); + + prlog(PR_TRACE, "%s: Finished after %ldms, length: %ld " + "(queuing: %ldms, resp: %ldms)\n", + __func__, + tb_to_msecs(now - queue_start), + *cb_data.len, + tb_to_msecs(resp_start - queue_start), + tb_to_msecs(now - resp_start)); + + return cb_data.rc; +} + +/* + * Handle PLDM message received from the PLDM terminus over MCTP. + */ +int pldm_rx_handle_response(struct pldm_rx_data *rx) +{ + /* check the message received */ + if (!matches_request(rx, active_request)) { + prlog(PR_ERR, "%s: Unexpected response! t:%d c:%d i:%d want %d,%d,%d\n", + __func__, + rx->hdrinf.pldm_type, + rx->hdrinf.command, + rx->hdrinf.instance, + active_request->type, + active_request->cmd_code, + active_request->instance + ); + return OPAL_WRONG_STATE; + } + + complete_request(rx); + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 25155af1..782a85d4 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -51,4 +51,10 @@ int pldm_send(uint8_t dest_id, uint8_t *buf, int len); int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_responder_init(void); +/* Requester support */ +int pldm_do_request(uint8_t dest_eid, + void *request_msg, size_t request_len, + void **response_msg, size_t *response_len); +int pldm_rx_handle_response(struct pldm_rx_data *rx); + #endif /* __COREPLDM_H__ */ From patchwork Thu Apr 14 13:43:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=LsKyO/uW; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLLP5w17z9sGF for ; Thu, 14 Apr 2022 23:45:01 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLLP5QH7z3bYk for ; Thu, 14 Apr 2022 23:45:01 +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=LsKyO/uW; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LsKyO/uW; 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 4KfLKV55r1z2yK2 for ; Thu, 14 Apr 2022 23:44:14 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3x1t010498 for ; Thu, 14 Apr 2022 13:44:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=bNNw6jkdvEqfjfygFzwog+zN8TVs5XcwH1EvDStivKA=; b=LsKyO/uWWCTbj+9qoS1H51DVnIPPqHZvMW2f6Op2w5OTCXQ6VO7evodO8kE+FXCLUBLQ GYrK1OwxTdoLVmSjNDETqKcFoHqUwJfQqI9ptBAom73unCVSz61dhZjm/fCPpTqZtIxU hvflWyeJUd3ziii7CqFcaJbQUo9WwFbksfKnYML5kFekrPMKwvcO96k/KUQYmg6jipPB C7aF30ciDZO+1/KMZBwz8l1/AzsJEs81DPKBqqGlmFOlWpjOGkqD/00lgiwnymoC2bLv mrPcDvpz7gCzUXdOaB/z0tDChXDcToU/gqUVyUO+MAEAjoYeW0644anX0ncG/0DmYx/4 +Q== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 3febxa2ruy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDhaUE001463 for ; Thu, 14 Apr 2022 13:44:10 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06fra.de.ibm.com with ESMTP id 3fbsj05vut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:09 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi7gs29819362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:07 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A0235A406D for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 76079A406E for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:53 +0200 Message-Id: <20220414134404.39888-11-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jAc6jj-SRizYJL4ra7M4GCGEgHTDJh49 X-Proofpoint-ORIG-GUID: jAc6jj-SRizYJL4ra7M4GCGEgHTDJh49 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 10/21] core/pldm: PLDM for Platform Monitoring and Control Specification X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This specification defines the functions and data structures used for discovering, describing, initializing, and accessing sensors and effecters within the management controllers and management devices of a platform management subsystem using PLDM messaging. A PDR (Platform Descriptor Record) is a set of data that is used to provide semantic information about sensors, effecters, monitored or controller entities, and functions and services within a PLDM implementation. PDRs are mostly used to support PLDM monitoring and control and platform events. The PDRs for a PLDM subsystem are collected into a single, central PDR Repository. A central repository provides a single place from which PDR information can be retrieved. The GetPDR command is used to retrieve individual PDRs from a PDR Repository. The record is identified by the PDR recordHandle value that is passed in the request. The patch dump all the PDRs within a PDR Repository. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 3 + core/pldm/pldm-base-requests.c | 58 +++++++ core/pldm/pldm-common.c | 20 ++- core/pldm/pldm-platform-requests.c | 235 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 9 ++ 5 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-base-requests.c create mode 100644 core/pldm/pldm-platform-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index c431288f..098cc103 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -7,7 +7,10 @@ SUBDIRS += $(PLDM_DIR) CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ +CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes + PLDM_OBJS = pldm-common.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..183c06b1 --- /dev/null +++ b/core/pldm/pldm-base-requests.c @@ -0,0 +1,58 @@ +// 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" + +/* + * Create a PLDM request message for GetTID. + */ +int pldm_base_get_tid_req(void) +{ + char request_msg[PKT_SIZE(0)]; /* the command doesn't have a message payload */ + size_t response_len, payload_len; + void *response_msg; + int rc; + + struct pldm_get_tid_resp response; + + /* Encode the get tid request */ + rc = encode_get_tid_req(DEFAULT_INSTANCE_ID, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetTID Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetTID, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_tid_resp(response_msg, payload_len, + &response.completion_code, + &response.tid); + if ((rc != PLDM_SUCCESS) || (response.completion_code != PLDM_SUCCESS)) { + prlog(PR_ERR, "Decode GetTID Error, rc: %d, cc: %d\n", + rc, response.completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + prlog(PR_INFO, "BMC's TID is %d\n", response.tid); + free(response_msg); + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm-common.c b/core/pldm/pldm-common.c index a7d4dfdc..9a22650e 100644 --- a/core/pldm/pldm-common.c +++ b/core/pldm/pldm-common.c @@ -113,6 +113,8 @@ int pldm_mctp_init(void) { int rc; + prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); + /* MCTP Binding */ rc = ast_mctp_init(pldm_rx_message); if (rc) { @@ -122,8 +124,22 @@ int pldm_mctp_init(void) /* Register mandatory commands we'll respond to */ rc = pldm_mctp_responder_init(); - if (rc) + if (rc) { prlog(PR_ERR, "Failed to register mandatory commands\n"); + goto out; + } + + /* 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); @@ -132,5 +148,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..7c848801 --- /dev/null +++ b/core/pldm/pldm-platform-requests.c @@ -0,0 +1,235 @@ +// 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 "pldm.h" + +#define NO_MORE_PDR_HANDLES 0 + +static pldm_pdr *repo; +static bool pdr_ready; + +static void pdr_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + pdr_ready = false; + + pldm_pdr_destroy(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; +}; + +/* + * 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 get_pdr_req(uint32_t record_hndl, uint32_t *next_record_hndl, + void **pdr_data, uint16_t *pdr_length) +{ + char request_msg[PKT_SIZE(struct pldm_get_pdr_req)]; + size_t response_len, payload_len; + void *response_msg; + int rc, i; + + 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) */ + }; + + struct get_pdr_response response; + + prlog(PR_DEBUG, "%s - record_hndl: %d\n", __func__, record_hndl); + + /* Encode the get_PDR request */ + rc = encode_get_pdr_req(DEFAULT_INSTANCE_ID, + pdr_req.record_handle, + pdr_req.data_transfer_handle, + pdr_req.transfer_op_flag, + pdr_req.request_count, + pdr_req.record_change_number, + (struct pldm_msg *)request_msg, + PLDM_GET_PDR_REQ_BYTES); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPDRReq Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetPDRReq, rc: %d\n", rc); + return rc; + } + + /* 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 = response_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( + response_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); + free(response_msg); + return OPAL_PARAMETER; + } + + if (response.record_data == NULL) { + response.record_data_length = response.resp_cnt; + response.record_data = malloc(response.resp_cnt); + } + } + + /* we do not support multipart transfer */ + if (response.transfer_flag != PLDM_START_AND_END) + prlog(PR_ERR, "Transfert GetPDRResp not complete, transfer_flag: %d\n", + response.transfer_flag); + + prlog(PR_DEBUG, "%s - record_hndl: %d, next_record_hndl: %d, resp_cnt: %d\n", + __func__, pdr_req.record_handle, + response.next_record_hndl, + response.resp_cnt); + + *next_record_hndl = response.next_record_hndl; + *pdr_length = response.resp_cnt; + *pdr_data = malloc(response.resp_cnt); + memcpy(*pdr_data, response.record_data, response.resp_cnt); + + free(response.record_data); + free(response_msg); + + return OPAL_SUCCESS; +} + +/* + * Collect all PDrs into a PDR Repository. + */ +static int get_all_pdrs(pldm_pdr *repo) +{ + uint32_t record_hndl = 0; /* first pdr handle */ + uint32_t next_record_hdl; + void *pdr_data = NULL; + uint16_t pdr_length; + int rc = OPAL_SUCCESS; + + do { + /* send/receive a PLDM GetPDR request message */ + rc = get_pdr_req(record_hndl, &next_record_hdl, + &pdr_data, &pdr_length); + if (rc) + goto err; + + /* Add a PDR record to a PDR repository */ + pldm_pdr_add(repo, + pdr_data, + pdr_length, + record_hndl, + false); + + if (pdr_data) { + free(pdr_data); + pdr_data = NULL; + } + + record_hndl = next_record_hdl; + + } while (next_record_hdl != NO_MORE_PDR_HANDLES); + +err: + if (pdr_data) + free(pdr_data); + + return rc; +} + +int pldm_platform_init(void) +{ + int rc; + + /* make a new PDR repository */ + repo = pldm_pdr_init(); + + /* retrieve all PDRs */ + rc = get_all_pdrs(repo); + if (rc) { + pdr_init_complete(false); + prlog(PR_ERR, "%s - done, rc: %d\n", __func__, rc); + return rc; + } + + pdr_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; +} + +void pldm_platform_exit(void) +{ + if (pdr_ready) + pldm_pdr_destroy(repo); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 782a85d4..d0621c29 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -6,6 +6,7 @@ #define __COREPLDM_H__ #include +#include #include /* Common support */ @@ -28,6 +29,9 @@ void printbuf(const char *name, const char *msg, int len); #define PKT_SIZE(x) (sizeof(struct pldm_msg_hdr) + sizeof(x)) +/* For all of the encode functions just pass in a default ID (0x00) */ +#define DEFAULT_INSTANCE_ID 0 + struct pldm_rx_data { struct pldm_header_info hdrinf; /* parsed message header */ @@ -52,6 +56,11 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_responder_init(void); /* Requester support */ +int pldm_base_get_tid_req(void); + +void pldm_platform_exit(void); +int pldm_platform_init(void); + int pldm_do_request(uint8_t dest_eid, void *request_msg, size_t request_len, void **response_msg, size_t *response_len); From patchwork Thu Apr 14 13:43:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=e3Rd/WGV; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLMx5WX8z9sGF for ; Thu, 14 Apr 2022 23:46:21 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLMx4KYWz3bbN for ; Thu, 14 Apr 2022 23:46:21 +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=e3Rd/WGV; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=e3Rd/WGV; 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 4KfLKd6h6Kz3bcX for ; Thu, 14 Apr 2022 23:44:21 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3xYd019512 for ; Thu, 14 Apr 2022 13:44:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Fum3J2iRoC39K74mcrBpwt3i18kezgIYZMCXNKbmZYs=; b=e3Rd/WGVI3zSR5f47chmptLks+KrTdCnPkllCLxQGjYcc+mDSwq8Mb6Ku/YsgkV4w4PN uagkhX5WR9mnwUKxPFIWXknAXMfGlciloGVSy/juc0+o5kzqizeYrHRRGd4VRdgZsGqa ha/CgYiFJH+y7w8lQYAAnBPI2aDVMknyleT61htxPQQCpVWjnyWkDQR/Ca4/kuXMT4Jy ruzo+eHVVX9zkm1c8zaJyH91Idf3O8ZoEyokp+zxYdS6LSu//Zc9AliWhlkdenNjzmPS dcJSlD/PdSYBRRV+e/Gaf4YN0uy2LGn9ygV9W+ZjhqOHCHuNf39VQ8HfBPB4QP7QNEea Zw== Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fed0ksn8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfuEd025082 for ; Thu, 14 Apr 2022 13:44:10 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04fra.de.ibm.com with ESMTP id 3fb1s8y056-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:10 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi8Zc33685804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF60FA406D for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B4967A406E for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:54 +0200 Message-Id: <20220414134404.39888-12-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Yglchykt790iuWt7DSmZJK4p-DvI1-Ed X-Proofpoint-GUID: Yglchykt790iuWt7DSmZJK4p-DvI1-Ed X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 7c848801..e4e6910d 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -32,6 +32,75 @@ static void pdr_init_complete(bool success) pdr_ready = true; } +struct set_effecter_state_response { + uint8_t completion_code; +}; + +/* + * Create and send a PLDM request message for SetStateEffecterStates. + */ +static int set_state_effecter_states_req(uint16_t effecter_id, + set_effecter_state_field *field, + bool no_timeout) +{ + char request_msg[PKT_SIZE(struct pldm_set_state_effecter_states_req)]; + size_t response_len, payload_len; + void *response_msg; + int rc; + + struct pldm_set_state_effecter_states_req states_req = { + .effecter_id = effecter_id, + .comp_effecter_count = 1 + }; + + struct set_effecter_state_response response; + + /* Encode the state effecter states request */ + rc = encode_set_state_effecter_states_req( + DEFAULT_INSTANCE_ID, + states_req.effecter_id, + states_req.comp_effecter_count, + field, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode SetStateEffecter Error, rc: %d\n", + rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + /* it may happen that for some commands, the responder + * does not have time to respond + */ + if (no_timeout && (rc == OPAL_TIMEOUT)) { + free(response_msg); + return OPAL_SUCCESS; + } + prlog(PR_ERR, "Communication Error, req: SetStateEffecter, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_set_state_effecter_states_resp( + response_msg, + payload_len, + &response.completion_code); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode SetStateEffecter Error, rc: %d, cc: %d\n", + rc, response.completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + struct get_pdr_response { uint8_t completion_code; uint32_t next_record_hndl; From patchwork Thu Apr 14 13:43:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=qGMnY++K; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLLX37zPz9sGF for ; Thu, 14 Apr 2022 23:45:08 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLLX2ZKjz3bXB for ; Thu, 14 Apr 2022 23:45:08 +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=qGMnY++K; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=qGMnY++K; 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 4KfLKV5M4Wz2yb9 for ; Thu, 14 Apr 2022 23:44:14 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3xBB010491 for ; Thu, 14 Apr 2022 13:44:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=tcwzp0sARWqNsCMNhYHYo1LF3nZK8Ty1PIPRjUPovHg=; b=qGMnY++KTre/XYIuQ4otEgR+2SyLDwMuzRPlAF8bpGoN+v3pqP2IKJC1KngiRixMtoaU abd2wbC59738eazJ31gPCvoMNF1xxOo6qXmfDad8Ds2oCnDOiQyl/QOWlVx6lJzhM3u+ 9UK9oPk7kSdDABwyQ0L9SRwDJD8uLx5WJAYEiCjdGIKnFmIfIbqqMsOAkUTqaaKvUue2 Yh67Ri5Zj/xkpZSUdx4Zk8oFzYQ0ldLPHAVkZqAV80zdMKE+/g0uwJdF8sd97tZAB47c t9NycNrSDECeLcgWzzo32m3dPy50Ujg2Rwi3vFJQuxO+a5v5MHRU5tuUnFXMdkiytrQC uQ== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3febxa2rv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg3vn006326 for ; Thu, 14 Apr 2022 13:44:10 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3fb1s90pfu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:10 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi8FE35717448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A815A407C for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0018DA406E for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:07 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:55 +0200 Message-Id: <20220414134404.39888-13-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ctzl8NT-FREh35UnwoT7RqT7EXL6o1nb X-Proofpoint-ORIG-GUID: Ctzl8NT-FREh35UnwoT7RqT7EXL6o1nb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 74 ++++++++++++++++++++++++++++++ include/pldm.h | 5 ++ 2 files changed, 79 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index e4e6910d..75fe65a5 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -32,6 +32,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( + 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; }; @@ -101,6 +144,37 @@ 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\n"); + + 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 3d01086f..55062ffb 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -15,4 +15,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 Apr 14 13:43:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Ze7bgAyc; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLLx2R6sz9sGF for ; Thu, 14 Apr 2022 23:45:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLLx1DW4z3bZp for ; Thu, 14 Apr 2022 23:45: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=Ze7bgAyc; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Ze7bgAyc; 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 4KfLKX2XW5z2yPj for ; Thu, 14 Apr 2022 23:44:16 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3xai019766 for ; Thu, 14 Apr 2022 13:44:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=D2v8In70+gLwbXHOvUqqmMq8mh4rUr/1ir69QVoktQU=; b=Ze7bgAycdi8A1Tw+Rkqyi41dZEXqyvlHzjSB5omMz9KxURNCyTDD8FJ/+XsqDZ3rmpul nNqAdZUXxMoBxIM6Xe/6vrq4MypnbW/NVUfsJgkk1INmg2GM9wA4MC1TieCggLMH80oG vHY2FjnK+l7yYE4UC0StjfZwuyQXyy8QJt57VU/HDgBbTx4CWNux+iuv4fDs3DwJOWMU Zh2xbPN3R/8oR9L3JP/DEFswsyYLXx1VjGdmzNHEkvTJgxUxZ/rLIsl+AUndfRR51ZRW DvfNs0pxnhVW5/kGhOyRXxjxwQhVfWiM9kDDLTD3s8JDe4LKUk62SkLcQKsDq6XQ0O2X mA== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fegbrwpb4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:13 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg79j015404 for ; Thu, 14 Apr 2022 13:44:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma05fra.de.ibm.com with ESMTP id 3fb1s8py73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:10 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi8c031654370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69EDBA407C for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F928A406D for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:56 +0200 Message-Id: <20220414134404.39888-14-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: k67m5aB2f4Ml-aG-Z343wVJTh9U4T-Xb X-Proofpoint-ORIG-GUID: k67m5aB2f4Ml-aG-Z343wVJTh9U4T-Xb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 priorityscore=1501 clxscore=1015 lowpriorityscore=0 spamscore=0 malwarescore=0 bulkscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 31 ++++++++++++++++++++++++++++++ include/pldm.h | 5 +++++ 2 files changed, 36 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 75fe65a5..223f810a 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -144,6 +144,37 @@ 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\n"); + + 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 55062ffb..d14d6164 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -15,6 +15,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 Apr 14 13:43:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=nzDp5cVg; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLNN53gWz9sGF for ; Thu, 14 Apr 2022 23:46:44 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLNN4F09z3brq for ; Thu, 14 Apr 2022 23:46: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=nzDp5cVg; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=nzDp5cVg; 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 4KfLKp6mcwz2yp5 for ; Thu, 14 Apr 2022 23:44:30 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3vp4025046 for ; Thu, 14 Apr 2022 13:44:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=7kq/cw7VPm9ORoG2LGhVJGBNqtj8k/4UzpcYXNeMMhQ=; b=nzDp5cVgF/ybjvLOwnS6rMCbrtvFVvy0SqUj5L5xa6HE4vm2+Vm/7wI2Sfl5L+9oTqol x/tdeEMYDxZPmaxwRv2ePZbGcoAj1QLLY1mFbzzTL14D4t2jlQgdgCZOy2hXkFpQ5PvC 28csimrcPulV0HHLC1aIAKQdof5gnVSBUfiP0wfAjzzxXyF/BS6v7GtU2SMcIchRyjEh oOq1JpLQOtHd8+0dskMN2QMwgpmfDv5TPbJOlUaENItkKKf9UiE1bI9z30oSixDY5B/Y wtUTvifOnlwvZ4iEUUDjgXnNVY+rhe83C6NRyqzHWlBQhLhsXzj57JHgaqCx0yuOgSvw 3w== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fefr9p730-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:13 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfulG015101 for ; Thu, 14 Apr 2022 13:44:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 3fb1s8pyf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi8pg16384320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:08 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A9FABA406E for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7E906A406D for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:57 +0200 Message-Id: <20220414134404.39888-15-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 8xbMe6Imbe6BS0YhOkT3w_4_pQZlSPAI X-Proofpoint-GUID: 8xbMe6Imbe6BS0YhOkT3w_4_pQZlSPAI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 | 210 +++++++++++++++++++++++++++++++++ core/pldm/pldm-common.c | 9 +- core/pldm/pldm.h | 2 + 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-bios-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 098cc103..f7139587 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -8,9 +8,11 @@ CPPFLAGS += -I$(SRC)/pldm/libpldm/ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes +CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes PLDM_OBJS = pldm-common.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..34cda9cb --- /dev/null +++ b/core/pldm/pldm-bios-requests.c @@ -0,0 +1,210 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include +#include +#include "pldm.h" + +/* + * PLDM_BIOS_STRING_TABLE = 0 + * pldmtool bios GetBIOSTable -t 0 + * pldmtool: Tx: 08 01 80 03 01 00 00 00 00 01 00 + * ... + * "60": "hb_lid_ids", + * ... + */ +static void *bios_string_table; +static size_t bios_string_length; + +/* + * PLDM_BIOS_ATTR_TABLE = 1 + * pldmtool bios GetBIOSTable -t 1 + * pldmtool: Tx: 08 01 80 03 01 00 00 00 00 01 01 + * + * { + * "AttributeHandle": 8, + * "AttributeNameHandle": "60(hb_lid_ids)", + * "AttributeType": "BIOSString", + * "StringType": "0x01", + * "MinimumStringLength": 0, + * "MaximumStringLength": 1024, + * "DefaultStringLength": 0, + * "DefaultString": "" + * }, + */ +static void *bios_attr_table; +static size_t bios_attr_length; + +/* + * PLDM_BIOS_ATTR_VAL_TABLE = 2 + * pldmtool bios GetBIOSTable -t 2 + * pldmtool: Tx: 08 01 80 03 01 00 00 00 00 01 02 + * + * { + * "AttributeHandle": 8, + * "AttributeType": "BIOSString", + * "CurrentStringLength": 616, + * "CurrentString": "ATTR_PERM=81e00663,ATTR_TMP=81e00664, ... + * NVRAM=81e0066b,...,pnor.toc=NA" + * }, ... + */ +static void *bios_val_table; +static size_t bios_val_length; + +static bool bios_ready; + +static void bios_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + bios_ready = false; + + if (bios_string_table != NULL) { + free(bios_string_table); + bios_string_length = 0; + } + if (bios_attr_table != NULL) { + free(bios_attr_table); + bios_attr_length = 0; + } + if (bios_val_table != NULL) { + free(bios_val_table); + bios_val_length = 0; + } + return; + } + + /* Mark ready */ + bios_ready = true; +} + +/* + * Send/receive a PLDM GetBIOSTable request message + */ +static int get_bios_table_req(enum pldm_bios_table_types table_type, + void **bios_table, size_t *bios_length) +{ + char request_msg[PKT_SIZE(struct pldm_get_bios_table_req)]; + size_t response_len, payload_len, bios_table_offset; + uint8_t completion_code, transfer_flag; + uint32_t next_transfer_handle; + void *response_msg; + int rc; + + struct pldm_get_bios_table_req bios_table_req = { + .transfer_handle = 0, /* (0 if transfer op is FIRSTPART) */ + .transfer_op_flag = PLDM_GET_FIRSTPART, + .table_type = table_type + }; + + prlog(PR_DEBUG, "%s - table type: %d\n", __func__, table_type); + + /* Encode the bios table request */ + rc = encode_get_bios_table_req( + DEFAULT_INSTANCE_ID, + bios_table_req.transfer_handle, + bios_table_req.transfer_op_flag, + bios_table_req.table_type, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetBIOSTableReq Error, type: %d, rc: %d\n", + table_type, rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetBIOSTableReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_bios_table_resp( + response_msg, + payload_len, + &completion_code, + &next_transfer_handle, + &transfer_flag, + &bios_table_offset); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetBIOSTableResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + /* we do not support multipart transfer */ + if ((next_transfer_handle != PLDM_GET_NEXTPART) || + (transfer_flag != PLDM_START_AND_END)) { + prlog(PR_ERR, "Transfert GetBIOSTable not complete " + "transfer_hndl: %d, transfer_flag: %d\n", + next_transfer_handle, + transfer_flag); + } + + *bios_length = payload_len - + sizeof(next_transfer_handle) - + sizeof(transfer_flag) - + sizeof(completion_code); + *bios_table = malloc(*bios_length); + memcpy(*bios_table, + ((struct pldm_msg *)response_msg)->payload + bios_table_offset, + *bios_length); + + free(response_msg); + + return OPAL_SUCCESS; +} + +int pldm_bios_init(void) +{ + int rc; + + /* BIOS String Table is a BIOS table that contains all the BIOS + * strings including attribute names, and pre-configured strings + * used in representing the values of the attributes. + * Each string in the BIOS String Table has an associated unique + * handle. + */ + rc = get_bios_table_req(PLDM_BIOS_STRING_TABLE, + &bios_string_table, &bios_string_length); + if (rc) + goto err; + + /* BIOS Attribute Table is a BIOS table that contains attribute + * name handles, attribute types, type-specific metadata, + * type-specific possible values (if any), and default values. + */ + rc = get_bios_table_req(PLDM_BIOS_ATTR_TABLE, + &bios_attr_table, &bios_attr_length); + if (rc) + goto err; + + /* BIOS Attribute Value Table is a BIOS table that contains all + * the current values of the BIOS attributes and settings. + * Each entry in this table contains the attribute handle, the + * attribute type, and current values. + */ + rc = get_bios_table_req(PLDM_BIOS_ATTR_VAL_TABLE, + &bios_val_table, &bios_val_length); + if (rc) + goto err; + + bios_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + bios_init_complete(false); + return rc; +} diff --git a/core/pldm/pldm-common.c b/core/pldm/pldm-common.c index 9a22650e..79d64104 100644 --- a/core/pldm/pldm-common.c +++ b/core/pldm/pldm-common.c @@ -138,8 +138,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 d0621c29..e1c401f1 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -56,6 +56,8 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_responder_init(void); /* Requester support */ +int pldm_bios_init(void); + int pldm_base_get_tid_req(void); void pldm_platform_exit(void); From patchwork Thu Apr 14 13:43:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=d0S+gzxu; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLLg46wDz9sGF for ; Thu, 14 Apr 2022 23:45:15 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLLg3MvVz3bjG for ; Thu, 14 Apr 2022 23:45:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=d0S+gzxu; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=d0S+gzxu; 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 4KfLKW56sMz2yb9 for ; Thu, 14 Apr 2022 23:44:15 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC40V7006323 for ; Thu, 14 Apr 2022 13:44:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=dQ/b1efS158jF3nVNWaIz+GTymDbEd6FrmRa/WLUdH8=; b=d0S+gzxuldETRhm7JbJuJd1Mf24J6u88kuqGHFFUPm/RqF0Gmh3Obz042QYtIB7bGyTY 6iU3KF7UGJU2WfKWvtVGfhvQcB6pIgXBVnGYSZ2+TNlomwWz6UAEIRPJTCq9BgeGBHP2 MS563P7ARSlLzjK2WYimuLfVQR2uSBvh5oSg8zaQp4cu5WDM8hpzVQ5OmoItQOyLlNbE IfiT7MXuj+gz0FE2xD5NkGE1BP5QN+LJWn2Lzv/jcEFqftJmpulKR29WXVYgItu/0+e1 bS4m81CueL+ztPBz4xSneNVEsSO0CirFvmdqnmoU8oHwskxM2LqdehdzYVNzqk+/iUA0 BQ== Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fedxsrp1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:13 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDgCH0025167 for ; Thu, 14 Apr 2022 13:44:11 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04fra.de.ibm.com with ESMTP id 3fb1s8y058-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi9GJ28770784 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA6A5A406E for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF224A407C for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:58 +0200 Message-Id: <20220414134404.39888-16-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 04QR0D5oLihNxtGNA0QPE7GwncZEfL6D X-Proofpoint-GUID: 04QR0D5oLihNxtGNA0QPE7GwncZEfL6D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 15/21] core/pldm: Find lid attribute from bios tables X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This specification defines the data structures and messages for communicating BIOS settings, BIOS attributes, boot configurations, and boot order settings. Use the GetBIOSTable command to get STRING, Attribute and Attribute values tables from the BIOS. The contents of these tables are needed to read/write the desired lid files located on the BMC. Signed-off-by: Christophe Lombard --- core/pldm/pldm-bios-requests.c | 149 +++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 151 insertions(+) diff --git a/core/pldm/pldm-bios-requests.c b/core/pldm/pldm-bios-requests.c index 34cda9cb..66a46bb8 100644 --- a/core/pldm/pldm-bios-requests.c +++ b/core/pldm/pldm-bios-requests.c @@ -84,6 +84,155 @@ static void bios_init_complete(bool success) bios_ready = true; } +/* + * parse a string, format: + * =,= + */ +static int find_lid_by_attr_name(char *str, const char *name, + char **lid) +{ + const char *pp = "="; + char *attr, *attr_end; + char *p; + + for (p = strtok(str, ","); p != NULL; p = strtok(NULL, ",")) { + /* parse now the following string = */ + attr = p; + while (*pp != *p) + p++; + + attr_end = p; + *attr_end = '\0'; + + if (!strncmp(attr, name, strlen(name)) && + (strlen(attr) == strlen(name))) { + *lid = strdup(++p); + p += strlen(name) + 1; + return OPAL_SUCCESS; + } + } + prlog(PR_ERR, "%s - lid not found, attr name: %s\n", + __func__, name); + + return OPAL_PARAMETER; +} + +/* + * Retrieve attribut value from string. + * + * Ex: string value = "hb_lid_ids" + * From STRING table (with string value = "hb_lid_ids") -> string_handle = 60 + * From ATTR table (with attr name handle = 60) -> attr handle = 8 + * From ATTR VAL table (with attr handle = 8) + * -> CurrentString = ATTR_PERM=81e00663,ATTR_TMP=81e00664, ... + * NVRAM=81e0066b,...,pnor.toc=NA" + */ +static int find_bios_table_attr_values_by_string(const char *str, + char **current_string) +{ + const struct pldm_bios_string_table_entry *string_entry; + const struct pldm_bios_attr_table_entry *attr_entry; + const struct pldm_bios_attr_val_table_entry *val_entry; + uint16_t string_handle, attr_handle; + struct variable_field currentString; + + if ((!bios_string_table) || (!bios_attr_table)) + return OPAL_PARAMETER; + + /* decode string table */ + string_entry = pldm_bios_table_string_find_by_string( + bios_string_table, bios_string_length, str); + if (!string_entry) { + prlog(PR_ERR, "String table entry not found, str: %s\n", + str); + return OPAL_PARAMETER; + } + + /* get the string handle for the entry */ + string_handle = pldm_bios_table_string_entry_decode_handle(string_entry); + prlog(PR_TRACE, "%s - string_handle: %d\n", __func__, string_handle); + + /* decode attribute table */ + attr_entry = pldm_bios_table_attr_find_by_string_handle( + bios_attr_table, bios_attr_length, string_handle); + if (!attr_entry) { + prlog(PR_ERR, "Attribute table entry not found, string_handle: %d\n", + string_handle); + return OPAL_PARAMETER; + } + + /* get the attribute handle from the attribute table entry */ + attr_handle = pldm_bios_table_attr_entry_decode_attribute_handle(attr_entry); + prlog(PR_TRACE, "%s - attr_handle: %d\n", __func__, attr_handle); + + /* decode attribute value table */ + val_entry = pldm_bios_table_attr_value_find_by_handle( + bios_val_table, bios_val_length, attr_handle); + + if (!val_entry) { + prlog(PR_ERR, "Attribute val table entry not found, attr_handle: %d\n", + attr_handle); + return OPAL_PARAMETER; + } + + /* get Current String Itself */ + pldm_bios_table_attr_value_entry_string_decode_string( + val_entry, + ¤tString); + *current_string = strdup(currentString.ptr); + + return OPAL_SUCCESS; +} + +#define HB_LID_IDS "hb_lid_ids" + +/* + * Find lid attribute from bios tables + */ +int pldm_bios_find_lid_by_attr_name(const char *name, char **lid) +{ + char *hb_lid_ids_string = NULL; + int rc = OPAL_SUCCESS; + + if (!bios_ready) + return OPAL_HARDWARE; + + /* find current attribut string */ + rc = find_bios_table_attr_values_by_string(HB_LID_IDS, &hb_lid_ids_string); + if (rc) + goto err; + + /* find lid attribut from current string */ + rc = find_lid_by_attr_name(hb_lid_ids_string, name, lid); + if (rc) + goto err; + + free(hb_lid_ids_string); + + prlog(PR_DEBUG, "%s - lid: %s, attr name: %s\n", + __func__, *lid, name); + + return OPAL_SUCCESS; + +err: + if (hb_lid_ids_string) + free(hb_lid_ids_string); + + return rc; +} + +/* + * Get lid ids string from bios tables + */ +int pldm_bios_get_lids_id(char **lid_ids_string) +{ + if (!bios_ready) + return OPAL_HARDWARE; + + /* find current attribut string */ + return find_bios_table_attr_values_by_string(HB_LID_IDS, lid_ids_string); +} + /* * Send/receive a PLDM GetBIOSTable request message */ diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index e1c401f1..96177804 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -56,6 +56,8 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_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); int pldm_base_get_tid_req(void); From patchwork Thu Apr 14 13:43:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=MvQHIK10; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLLp74jBz9sGF for ; Thu, 14 Apr 2022 23:45:22 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLLp2r1Fz3bky for ; Thu, 14 Apr 2022 23:45:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MvQHIK10; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=MvQHIK10; 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 4KfLKX2Y72z2yZf for ; Thu, 14 Apr 2022 23:44:16 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC40cB010521 for ; Thu, 14 Apr 2022 13:44:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9qVSoh3uEWLsjo6fcvWzxFnRhipqgjZ8sI8saKmPBJM=; b=MvQHIK105iBzA1W7nqEZotssAMELkSjXL46AU63uO6iKG2kLOtwSzm4VPO7GsU5Bu3FU UYrZfWm/EDufgvEUv6XooLeCkx5IANF00Y6YGILUC7mfvdIyY2hK8NSLa5/Zw9f7IR0o C71cknApfjS84r9gYSjjhcsabmtb1LqVGaQEyjCkJ/bx6mJQct7rk64xXqj9vk/d9xki nFAsQgcqP0h575B1TGn3nNK1aObM/BrziYfU1FYyX6zOwU6Dlovzkqo0Q/Xrhefnwg3W 3SWrSlaLd3hdwatoP5AcrZIUozOZvfaQgk8We8/yspuKnM/m2OOpIrl2F3PxRLuGDrkG Lw== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3febxa2rvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:13 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfv8F024758 for ; Thu, 14 Apr 2022 13:44:11 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3fb1dj8ppv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi9xL38732166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 360D8A406E for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B59BA406D for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:43:59 +0200 Message-Id: <20220414134404.39888-17-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ildJNBM1B0Sqc8nzpWYHQx1c6_jkWrBy X-Proofpoint-ORIG-GUID: ildJNBM1B0Sqc8nzpWYHQx1c6_jkWrBy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 malwarescore=0 phishscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 16/21] core/pldm: PLDM for FRU data Specification X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Specification, defines a FRU data format that provides platform asset information including part number, serial number and manufacturer. Use the GetFruRecordByOptionReq command to get specific FRU (Field Replaceable Unit) record according the Record Set Identifier, the Record Type and the field Type. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-fru-requests.c | 112 ++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 6 ++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-fru-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index f7139587..631e16f7 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-common.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..559529c6 --- /dev/null +++ b/core/pldm/pldm-fru-requests.c @@ -0,0 +1,112 @@ +// 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 int get_fru_record_by_option_req(uint16_t fru_table_handle, + uint16_t record_set_identifier, + uint8_t record_type, + uint8_t field_type, + struct variable_field *fru_structure_data) +{ + char request_msg[PKT_SIZE(struct pldm_get_fru_record_by_option_req)]; + size_t response_len, payload_len; + uint8_t transfer_flag, completion_code; + uint32_t next_transfer_handle; + struct variable_field fsdata; + void *response_msg; + int rc; + + struct pldm_get_fru_record_by_option_req fru_record_by_option_req = { + .data_transfer_handle = 0, /* (0 if operation op is FIRSTPART) */ + .fru_table_handle = fru_table_handle, + .record_set_identifier = record_set_identifier, + .record_type = record_type, + .field_type = field_type, + .transfer_op_flag = PLDM_GET_FIRSTPART, + }; + payload_len = sizeof(struct pldm_get_fru_record_by_option_req); + + prlog(PR_DEBUG, "%s - handle: 0x%x, record id: 0x%x, record type: 0x%x, " + "field type: 0x%x\n", + __func__, fru_table_handle, record_set_identifier, + record_type, field_type); + + /* Encode the file table request */ + rc = encode_get_fru_record_by_option_req( + DEFAULT_INSTANCE_ID, + fru_record_by_option_req.data_transfer_handle, + fru_record_by_option_req.fru_table_handle, + fru_record_by_option_req.record_set_identifier, + fru_record_by_option_req.record_type, + fru_record_by_option_req.field_type, + fru_record_by_option_req.transfer_op_flag, + (struct pldm_msg *)request_msg, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordByOptionReq Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFruRecordByOptionReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_fru_record_by_option_resp( + response_msg, + payload_len, + &completion_code, + &next_transfer_handle, + &transfer_flag, + &fsdata); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetFruRecordByOptionReq Error, rc: %d, cc: %d\n", + rc, completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + /* we do not support multipart transfer */ + if ((next_transfer_handle != PLDM_GET_NEXTPART) || + (transfer_flag != PLDM_START_AND_END)) { + prlog(PR_ERR, "Transfert GetFileResp not complete, " + "transfer_hndl: %d, transfer_flag: %d\n", + next_transfer_handle, + transfer_flag); + } + + fru_structure_data->length = fsdata.length; + fru_structure_data->ptr = malloc(fsdata.length); + memcpy((void *)fru_structure_data->ptr, fsdata.ptr, fsdata.length); + + free(response_msg); + + return OPAL_SUCCESS; +} + +int pldm_fru_get_record_by_option(uint16_t fru_table_handle, + uint16_t record_set_identifier, + uint8_t record_type, + uint8_t field_type, + struct variable_field *fru_structure_data) +{ + return get_fru_record_by_option_req(fru_table_handle, + record_set_identifier, + record_type, + field_type, + fru_structure_data); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 96177804..57044d35 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -56,6 +56,12 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_responder_init(void); /* Requester support */ +int pldm_fru_get_record_by_option(uint16_t fru_table_handle, + uint16_t record_set_identifier, + uint8_t record_type, + uint8_t field_type, + struct variable_field *fru_structure_data); + 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 Apr 14 13:44:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=azy448pT; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLM44B8tz9sGF for ; Thu, 14 Apr 2022 23:45:36 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLM42j21z3bmQ for ; Thu, 14 Apr 2022 23:45: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=azy448pT; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=azy448pT; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KfLKX3NgWz2ymb for ; Thu, 14 Apr 2022 23:44:16 +1000 (AEST) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3wIW012525 for ; Thu, 14 Apr 2022 13:44:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=e8D7+po7r2VujiB3sfMR4e2tcGqvr7WGoW4RwJDkzKM=; b=azy448pTMPTtokdvziNTfnWDx8ZhO3WhH8no8VOd6qdu3qIKUIcsDaJnnJL6OqjgBLAt fog7ydHkYLcYKemolbh8pik8ItG0Io+ZhG2XNNd8qlx1o0VqyhpOt7Bzbgj/1Y4qFJdr lrw0FMKsKMxIyHoeFxLTi1A8uQsvVaov1YkTVfhbFPgjNzcb8L75t00S2PRBdrIY3yqF UGuSBhzTNLDrZQhQKZKsBL+NRIiGdPWUUujRNlq5Xlxdsf+bze5IPMcMmZ5hZmMMJNxU CfnOHJ74v4FTNTPANwoq1ts9MPW8mqtWQR5HUD8FvOVwCk/f7xyX+BgE8BWKs88dV6VC ew== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 3fef9ypwwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:13 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDgPPH014663 for ; Thu, 14 Apr 2022 13:44:12 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 3fb1s90nsm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:11 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi9V838732170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 74F1AA406D for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B183A406F for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:44:00 +0200 Message-Id: <20220414134404.39888-18-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DU82lieCIIZunU_6jfSm90kIfRiEVd_l X-Proofpoint-ORIG-GUID: DU82lieCIIZunU_6jfSm90kIfRiEVd_l X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 mlxscore=0 malwarescore=0 phishscore=0 spamscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 17/21] core/pldm: Update "bmc-firmware-version" device-tree field X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Use the GetFruRecordByOptionReq command to retrieve the bmc information with: "FRU Field Type": Version "FRU Record Set Identifier": 1, "FRU Record Type": "General(1)" and update the "bmc-firmware-version" device-tree field. Signed-off-by: Christophe Lombard --- core/pldm/pldm-fru-requests.c | 36 +++++++++++++++++++++++++++++++++++ include/pldm.h | 5 +++++ 2 files changed, 41 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index 559529c6..eda8f939 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -110,3 +110,39 @@ int pldm_fru_get_record_by_option(uint16_t fru_table_handle, field_type, fru_structure_data); } + +int pldm_fru_dt_add_bmc_version(void) +{ + struct pldm_fru_record_data_format *record_data; + struct variable_field fru_structure_data; + struct pldm_fru_record_tlv *record_tlv; + struct dt_node *dt_fw_version; + int rc; + + dt_fw_version = dt_find_by_name(dt_root, "ibm,firmware-versions"); + if (!dt_fw_version) + return OPAL_SUCCESS; + + /* retrieve the bmc information with + * "FRU Field Type": Version + * "FRU Record Set Identifier": 1, + * "FRU Record Type": "General(1)" + */ + rc = get_fru_record_by_option_req(0, + 1, + PLDM_FRU_RECORD_TYPE_GENERAL, + PLDM_FRU_FIELD_TYPE_VERSION, + &fru_structure_data); + if (rc) + return rc; + + record_data = (struct pldm_fru_record_data_format *)fru_structure_data.ptr; + record_tlv = (struct pldm_fru_record_tlv *)record_data->tlvs; + prlog(PR_DEBUG, "%s - value: %s\n", __func__, record_tlv->value); + + dt_add_property_string(dt_fw_version, + "bmc-firmware-version", + record_tlv->value); + + return OPAL_SUCCESS; +} diff --git a/include/pldm.h b/include/pldm.h index d14d6164..c3a549e5 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -25,4 +25,9 @@ int pldm_platform_power_off(void); */ int pldm_platform_restart(void); +/** + * Update the firmware version device-tree field + */ +int pldm_fru_dt_add_bmc_version(void); + #endif /* __PLDM_H__ */ From patchwork Thu Apr 14 13:44:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=smxTIu97; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLMW1XMBz9sGF for ; Thu, 14 Apr 2022 23:45:59 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLMW0kFrz3bqF for ; Thu, 14 Apr 2022 23:45:59 +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=smxTIu97; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=smxTIu97; 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 4KfLKZ4QT9z3bYP for ; Thu, 14 Apr 2022 23:44:18 +1000 (AEST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC3x9o006518 for ; Thu, 14 Apr 2022 13:44:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=/u/1NE0CG3mMQ2Viy2ERoi7IsLnHmuUJHN4a07LEozg=; b=smxTIu97WP4u1yLglVTz22IU2jSnumnNN4eKYEc2sKj9TNVPDZYb2aqLfypjjJKKvLyl 7r4Hso25qR2Bgdfz+5insQG8qOiJs4l//crrPmYlpdn7SEfapdZ0j31lOoV7kvr3Sndw G0boY2KMdHxxsxtPDczH3t39JK4vgMiIaPqCIKMdXbChSTF8quR9SRMO8rianpRWjsOU VSnbpA0UgCPQvK6TuJ3WzMBMNQPSC9aryqUa8g1KeeJNKSq+JE8CfqIgbnOWfQeyIh7r EyS7jI0Q1yCo652q4ss8yJtVEAa2R2bs6nGseRJzfzEfiuuSzzalEa2hwSfRxElvFsEM TQ== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fefh56m9x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:14 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg72M006352 for ; Thu, 14 Apr 2022 13:44:12 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3fb1s90pfw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDi93B38732174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:09 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B3ED1A406D for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 898C4A406E for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:44:01 +0200 Message-Id: <20220414134404.39888-19-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Rili-kyywoTD7v2dOlXgDhVMtYdRuyTm X-Proofpoint-ORIG-GUID: Rili-kyywoTD7v2dOlXgDhVMtYdRuyTm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 malwarescore=0 adultscore=0 priorityscore=1501 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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-common.c | 9 +- core/pldm/pldm-file-io-requests.c | 142 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-file-io-requests.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 631e16f7..d3affaa0 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-common.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-common.c b/core/pldm/pldm-common.c index 79d64104..50f86948 100644 --- a/core/pldm/pldm-common.c +++ b/core/pldm/pldm-common.c @@ -145,8 +145,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 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-file-io-requests.c b/core/pldm/pldm-file-io-requests.c new file mode 100644 index 00000000..07e7dfd2 --- /dev/null +++ b/core/pldm/pldm-file-io-requests.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include +#include "pldm.h" + +/* list of lid files available */ +static void *file_attr_table; +static size_t file_attr_length; + +static bool file_io_ready; + +static void file_io_init_complete(bool success) +{ + /* Read not successful, error out and free the buffer */ + if (!success) { + file_io_ready = false; + + if (file_attr_table != NULL) { + free(file_attr_table); + file_attr_length = 0; + } + return; + } + + /* Mark ready */ + file_io_ready = true; +} + +/* + * Send/receive a PLDM GetFileTable request message. + * The file table contains the list of files available and + * their attributes. + * + * Ex: + * { + * "FileHandle": "11", + * "FileNameLength": 12, + * "FileName": "81e0066b.lid", + * "FileSize": 589824, + * "FileTraits": 6 + * }, + */ +static int get_file_table_req(void) +{ + char request_msg[PKT_SIZE(struct pldm_get_file_table_req)]; + size_t response_len, payload_len; + uint8_t file_table_data_start_offset; + uint8_t transfer_flag, completion_code; + uint32_t next_transfer_handle; + void *response_msg; + int rc; + + struct pldm_get_file_table_req file_table_req = { + .transfer_handle = 0, /* (0 if operation op is FIRSTPART) */ + .operation_flag = PLDM_GET_FIRSTPART, + .table_type = PLDM_FILE_ATTRIBUTE_TABLE, + }; + + prlog(PR_DEBUG, "%s - GetFileReq\n", __func__); + + /* Encode the file table request */ + rc = encode_get_file_table_req( + DEFAULT_INSTANCE_ID, + file_table_req.transfer_handle, + file_table_req.operation_flag, + file_table_req.table_type, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFileReq Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetFileReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_file_table_resp( + response_msg, + payload_len, + &completion_code, + &next_transfer_handle, + &transfer_flag, + &file_table_data_start_offset, + &file_attr_length); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + /* we do not support multipart transfer */ + if ((next_transfer_handle != PLDM_GET_NEXTPART) || + (transfer_flag != PLDM_START_AND_END)) { + prlog(PR_ERR, "Transfert GetFileResp not complete, " + "transfer_hndl: %d, transfer_flag: %d\n", + next_transfer_handle, + transfer_flag); + } + + file_attr_table = malloc(file_attr_length); + memcpy(file_attr_table, + ((struct pldm_msg *)response_msg)->payload + + file_table_data_start_offset, + file_attr_length); + + free(response_msg); + + return OPAL_SUCCESS; +} + +int pldm_file_io_init(void) +{ + int rc; + + /* PLDM GetFileTable request */ + rc = get_file_table_req(); + if (rc) + goto err; + + file_io_init_complete(true); + prlog(PR_DEBUG, "%s - done\n", __func__); + + return OPAL_SUCCESS; + +err: + file_io_init_complete(false); + return rc; +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 57044d35..7e330175 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -56,6 +56,8 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_responder_init(void); /* Requester support */ +int pldm_file_io_init(void); + int pldm_fru_get_record_by_option(uint16_t fru_table_handle, uint16_t record_set_identifier, uint8_t record_type, From patchwork Thu Apr 14 13:44:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ByYLezNc; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLMM6DGqz9sGF for ; Thu, 14 Apr 2022 23:45:51 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLMM5NFfz3bbw for ; Thu, 14 Apr 2022 23:45:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ByYLezNc; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ByYLezNc; 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 4KfLKZ2Nqrz3bXy for ; Thu, 14 Apr 2022 23:44:18 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC42J7001719 for ; Thu, 14 Apr 2022 13:44:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=PPrlWJdy1fvdNUTmxK8zodQqumAIhKBXF/4uWd5AG+4=; b=ByYLezNc2cqgTnm+cjFyPHlU6SOS7fRAAnqs7sjuo2ie5cRr7Oks7If0f3MocyXi8HQD xT9PuJmASF9HMLwrDA+fAQC35rtPE3y/mBuqvvsp9m6zDiEzs8P0dKDv0dgMKGDlaf8X lyqLLBZ5L3fXJAqIHt2CNh2f5mP5A3nXErpLJkfqcUykBcFQnJOH7m0062DHzbSpSDHf rbHvXLOvbK7RMAuv9uto7MyElDfTGI4zGHxa/5jLK7evoSxj4rEgckzOapVowrCeY3rZ YGjUTVpH/ZVWjHrpVmcTyL5b2HghDU4hNnTsB0+JAqlSE1BU9z+wpM7URPjMGcBUW6tQ nw== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fegdnwmjk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:14 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDfxxg015130 for ; Thu, 14 Apr 2022 13:44:12 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03fra.de.ibm.com with ESMTP id 3fb1s8pyf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDiAHl38732176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:10 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0085BA406D for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9048A406F for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:09 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:44:02 +0200 Message-Id: <20220414134404.39888-20-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: npu7oGvHI0xOYWDLBZH5ELrDP06MW3Kf X-Proofpoint-GUID: npu7oGvHI0xOYWDLBZH5ELrDP06MW3Kf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 phishscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 19/21] core/pldm: Add file io read request X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Send/receive a PLDM ReadFile request message. Due to maximum transfer size for PLDM protocol, we have to send several read requests, if necessary. Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 128 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 130 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 07e7dfd2..6ddc7bc2 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,133 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +/* maximum currently transfer size for PLDM */ +#define KILOBYTE 1024ul +#define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1) + +/* + * Send/receive a PLDM ReadFile request message. + */ +static int read_file_req(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size) +{ + char request_msg[PKT_SIZE(struct pldm_read_file_req)]; + size_t response_len, payload_len, file_data_offset; + uint8_t completion_code; + uint32_t resp_length; + uint64_t total_read; + void *response_msg; + int num_transfers; + void *curr_buf; + int rc, i; + + struct pldm_read_file_req file_req = { + .file_handle = file_handle, + .offset = offset, + .length = size + }; + + if (!file_length) + return OPAL_PARAMETER; + + if ((!size) || (size > file_length)) + return OPAL_PARAMETER; + + if ((offset) && ((size + offset) > file_length)) + return OPAL_PARAMETER; + + num_transfers = 1; + curr_buf = buf; + total_read = 0; + + if (file_req.length > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (file_req.length + MAX_TRANSFER_SIZE_BYTES - 1) / + MAX_TRANSFER_SIZE_BYTES; + file_req.length = MAX_TRANSFER_SIZE_BYTES; + } + + prlog(PR_TRACE, "%s - file_handle: %d, offset: 0x%x, size: 0x%llx num_transfers: %d\n", + __func__, file_handle, file_req.offset, + size, num_transfers); + + for (i = 0; i < num_transfers; i++) { + file_req.offset = offset + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_read_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode ReadFileReq Error, rc: %d\n", + rc); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, sizeof(request_msg), + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: ReadFileReq, rc: %d\n", rc); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_read_file_resp( + response_msg, + payload_len, + &completion_code, + &resp_length, + &file_data_offset); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode ReadFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(response_msg); + return OPAL_PARAMETER; + } + + if (resp_length == 0) { + free(response_msg); + break; + } + + memcpy(curr_buf, + ((struct pldm_msg *)response_msg)->payload + file_data_offset, + resp_length); + + total_read += resp_length; + curr_buf += resp_length; + free(response_msg); + + prlog(PR_TRACE, "%s - file_handle: %d, resp_length: 0x%x, total_read: 0x%llx\n", + __func__, file_handle, resp_length, total_read); + + if (total_read == size) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (size - total_read)) + file_req.length = size - total_read; + + time_wait_ms(20); + } + + return OPAL_SUCCESS; +} + +int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, + void *buf, uint32_t offset, uint64_t size) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return read_file_req(file_handle, file_length, buf, offset, size); +} + /* * Send/receive a PLDM GetFileTable request message. * The file table contains the list of files available and diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 7e330175..ba8d7358 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -56,6 +56,8 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_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_record_by_option(uint16_t fru_table_handle, From patchwork Thu Apr 14 13:44:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=EcA5ljjp; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLMC5PVGz9sGF for ; Thu, 14 Apr 2022 23:45:43 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLMC4CtMz3bpT for ; Thu, 14 Apr 2022 23:45: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=EcA5ljjp; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=EcA5ljjp; 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 4KfLKX5q3Mz2yn1 for ; Thu, 14 Apr 2022 23:44:16 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC40V8006323 for ; Thu, 14 Apr 2022 13:44:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Gwn5eibQIn4srxehAE3u8ZEn6fc9Ebxb2Jz7mUWZDYE=; b=EcA5ljjpV7FPzwE4Qe5Zw9fAJy+McQjltJxVm270i8JtlCbdeHYBpUVFVJO/Y0p/8eq3 oCfBUGJg9YekogyeqNPZDr6X8AR84CV6Z62IhcRXRaj3MNNFn5iNffhVyHKhbCCPYJMq RXJiKyaxyZcfFLiJ9W+ou5NhR77I/rhDm5gTlenKNHznKHaRWWJEhS/XFVnrbzCHKebA H37sjyi50vYSsCNVT8X7yJCtfa6bDKQ372WOohFQrPj7e40WRbAlEXdQM+29klnFaHK/ OJG7fsuobndf/LLwDaTl9G/tRtMs9vdRUyRE8B66cYWy3aMN+EiE/u6FtXEbsZqh8pFi qA== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fedxsrp24-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:14 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDg0j5006308 for ; Thu, 14 Apr 2022 13:44:12 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3fb1s90pfx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDiAiG34341254 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:10 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40152A406D for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15F52A406E for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:44:03 +0200 Message-Id: <20220414134404.39888-21-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9C1l_pS0jO-pWJPTlttIXqdl1Jf6TZyT X-Proofpoint-GUID: 9C1l_pS0jO-pWJPTlttIXqdl1Jf6TZyT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 20/21] core/pldm: Add file io write request X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Send/receive a PLDM WriteFile request message. Due to maximum transfer size for PLDM protocol, we have to send several write requests, if necessary. Signed-off-by: Christophe Lombard --- core/pldm/pldm-file-io-requests.c | 123 ++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 2 files changed, 125 insertions(+) diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c index 6ddc7bc2..06edfe23 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -161,6 +161,129 @@ int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length, return read_file_req(file_handle, file_length, buf, offset, size); } +/* + * Send/receive a PLDM WriteFile request message. + */ +static int write_file_req(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size) +{ + void *response_msg, *current_ptr, *payload_data; + uint32_t total_write, resp_length, request_length; + size_t response_len, payload_len; + uint8_t completion_code; + int num_transfers; + char *request_msg; + int rc, i; + + struct pldm_write_file_req file_req = { + .file_handle = file_handle, + .offset = offset, + .length = size + }; + + if (!size) + return OPAL_PARAMETER; + + if ((offset) && (offset > size)) + return OPAL_PARAMETER; + + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_write_file_req) + + size; + request_msg = malloc(request_length); + + payload_data = ((struct pldm_msg *)request_msg)->payload + + sizeof(file_req.file_handle) + + sizeof(file_req.offset) + + sizeof(file_req.length); + memcpy(payload_data, buf, size); + current_ptr = payload_data; + num_transfers = 1; + total_write = 0; + + if (size > MAX_TRANSFER_SIZE_BYTES) { + num_transfers = (size + MAX_TRANSFER_SIZE_BYTES - 1) / + MAX_TRANSFER_SIZE_BYTES; + file_req.length = MAX_TRANSFER_SIZE_BYTES; + } + + prlog(PR_TRACE, "%s - file_handle: %d, offset: 0x%x, size: 0x%x, num_transfers: %d\n", + __func__, file_handle, file_req.offset, + file_req.length, num_transfers); + + for (i = 0; i < num_transfers; i++) { + file_req.offset = offset + (i * MAX_TRANSFER_SIZE_BYTES); + + /* Encode the file request */ + rc = encode_write_file_req( + DEFAULT_INSTANCE_ID, + file_req.file_handle, + file_req.offset, + file_req.length, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode WriteFileReq Error, rc: %d\n", rc); + free(request_msg); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_do_request(BMC_EID, request_msg, + request_length - 1, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: WriteFileReq, rc: %d\n", rc); + free(request_msg); + return rc; + } + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_write_file_resp( + response_msg, + payload_len, + &completion_code, + &resp_length); + if (rc != PLDM_SUCCESS || completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode WriteFileResp Error, rc: %d, cc: %d\n", + rc, completion_code); + free(request_msg); + free(response_msg); + return OPAL_PARAMETER; + } + + if (resp_length == 0) { + free(response_msg); + break; + } + + total_write += resp_length; + current_ptr += resp_length; + free(response_msg); + + if (total_write == size) + break; + else if (resp_length != file_req.length) { + /* end of file */ + break; + } else if (MAX_TRANSFER_SIZE_BYTES > (size - total_write)) + file_req.length = size - total_write; + } + + free(request_msg); + + return OPAL_SUCCESS; +} + +int pldm_file_io_write_file(uint32_t file_handle, const void *buf, + uint32_t offset, uint64_t size) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return write_file_req(file_handle, buf, offset, size); +} + /* * Send/receive a PLDM GetFileTable request message. * The file table contains the list of files available and diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index ba8d7358..dc6269d0 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -58,6 +58,8 @@ int pldm_mctp_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_record_by_option(uint16_t fru_table_handle, From patchwork Thu Apr 14 13:44:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1617252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=WjnfGAGp; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLMf4p5tz9sGF for ; Thu, 14 Apr 2022 23:46:06 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KfLMf4DTNz3bqL for ; Thu, 14 Apr 2022 23:46:06 +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=WjnfGAGp; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=WjnfGAGp; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KfLKc2xT4z3bbV for ; Thu, 14 Apr 2022 23:44:20 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23EC4B9M009276 for ; Thu, 14 Apr 2022 13:44:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=JFsilHOAPzAogGRk/IUU0NrjseDwZnDnuY6oP5j6iJo=; b=WjnfGAGpa/FzdQazO54vynMyzAC/uG9LZrhLGvM8nkvrr+onYgMVXmOjJTfaJITVh14H LcaOIhLs7SHSRyvci+07ZNvGD+D98tySugBatSNxgI6ZAG+cIMKyvsXEbPdVOtaf1rKJ n5d8Sn+R139JoKKhwRLChjiekRnnsDL6/Z9XOr45S5chRAs7DSU6HACWCbeBZC3qyUMQ aBXMZrgBQGk1pWAK4VosThO5/ve3KSBst0SHz1HAh+J45bTHqYBfo5cvutG36FGKugSb 4BV7rETY5jQO+N3hj5Gki4wUG5loq6PWM86RGQfoZQVRbO2dT5gYDGrk3a37P8N/pmBF 1Q== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0b-001b2d01.pphosted.com with ESMTP id 3febpbu4jv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:14 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23EDhxmV001540 for ; Thu, 14 Apr 2022 13:44:13 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06fra.de.ibm.com with ESMTP id 3fbsj05vuw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2022 13:44:12 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23EDiAk634341256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Apr 2022 13:44:10 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F548A406D for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 549C0A406F for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.92]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Apr 2022 13:44:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Apr 2022 15:44:04 +0200 Message-Id: <20220414134404.39888-22-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> References: <20220414134404.39888-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qRcaeqkcsbDgtOZCKylPCX8QqDCRjpi5 X-Proofpoint-ORIG-GUID: qRcaeqkcsbDgtOZCKylPCX8QqDCRjpi5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-14_04,2022-04-14_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 suspectscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204140074 Subject: [Skiboot] [PATCH V4 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 06edfe23..94828fcd 100644 --- a/core/pldm/pldm-file-io-requests.c +++ b/core/pldm/pldm-file-io-requests.c @@ -34,6 +34,82 @@ static void file_io_init_complete(bool success) file_io_ready = true; } +#define CHKSUM_PADDING 8 + +/* + * Retrieve the file handle and file length from the file attribute + * table. + */ +static int find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + const struct pldm_file_attr_table_entry *file_entry; + char *startptr, *endptr; + uint16_t file_name_length; + + if ((file_attr_table == NULL) || (file_attr_length == 0)) + return OPAL_PARAMETER; + + startptr = (char *)file_attr_table; + endptr = startptr + file_attr_length - CHKSUM_PADDING; + *file_handle = 0; + *file_length = 0; + + while (startptr < endptr) { + /* file entry: + * 4 Bytes: file handle + * 2 Bytes: file name length + * Bytes: file name + * 4 Bytes: file length + */ + file_entry = (struct pldm_file_attr_table_entry *)startptr; + + *file_handle = le32_to_cpu(file_entry->file_handle); + startptr += sizeof(uint32_t); + + file_name_length = le16_to_cpu(file_entry->file_name_length); + startptr += sizeof(file_name_length); + + if (!strncmp(startptr, lid_id, strlen(lid_id))) { + startptr += file_name_length; + *file_length = le32_to_cpu(*(uint32_t *)startptr); + break; + } + startptr += file_name_length; + startptr += sizeof(uint32_t); + startptr += sizeof(bitfield32_t); + } + + if (*file_length == 0) { + prlog(PR_ERR, "%s - No file handle found, lid_id: %s\n", + __func__, lid_id); + *file_handle = 0xff; + *file_length = 0; + return OPAL_PARAMETER; + } + + prlog(PR_DEBUG, "%s - lid_id: %s, file_handle: %d, file_length: %d\n", + __func__, lid_id, *file_handle, *file_length); + + return OPAL_SUCCESS; +} + +/* + * Retrieve the file handle and file length based on lid id. + */ +int pldm_find_file_handle_by_lid_id(const char *lid_id, + uint32_t *file_handle, + uint32_t *file_length) +{ + if (!file_io_ready) + return OPAL_PARAMETER; + + return find_file_handle_by_lid_id(lid_id, + file_handle, + file_length); +} + /* maximum currently transfer size for PLDM */ #define KILOBYTE 1024ul #define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1) diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index dc6269d0..22cf765d 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -56,6 +56,9 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx); int pldm_mctp_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,