From patchwork Tue Aug 29 09:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=gdTkRn0n; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhnW1Q16z1yfy for ; Tue, 29 Aug 2023 19:23:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=gdTkRn0n; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhnQ2xPlz3bYc for ; Tue, 29 Aug 2023 19:23:54 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=gdTkRn0n; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RZhnG3m3rz300f for ; Tue, 29 Aug 2023 19:23:45 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9E2cN004570 for ; Tue, 29 Aug 2023 09:23:44 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=hm6BZiEwLHyce8lrXpJTlPGL3AYRkWU21PLF9/uQaeg=; b=gdTkRn0nxgYWoxkIEWjiLSWZJX63rxMYBB3MGHDh5g8yBAVjx2FMoKM98imBJG5N6M0E 4xvzZysCRZSQO64gr+pdxqNMLhahfNtk8mFARMf4T4bkY2Ddo8GyOxPQj2VZP68fbG31 5LUE0uPihJjVrZQ+F+Xl+Qf9UyPr0/z+YcI//x+xN1HQQPAGtR0zOfo0bPhu2cGCBV3+ MberZrZCBRXTDWcNympQ05lwH0f677qXk0v5j9VFvjvx0Xq/KQ6LMfhpPbaqwl35+j4i 8GUI2ZX+KMn9vPWBfMfrGvZOHiuVeJj1DmcVV1wV10r/tah3sxL3w9hWlSOjaQm94Lyc GQ== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr87hqgm0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:23:43 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T7ePKb009967 for ; Tue, 29 Aug 2023 09:23:43 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqw7ka380-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:23:42 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9NfVr8585836 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:23:41 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E38322004B for ; Tue, 29 Aug 2023 09:23:40 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C17E20040 for ; Tue, 29 Aug 2023 09:23:40 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:23:40 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:20 +0200 Message-ID: <20230829092338.75785-4-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092338.75785-1-clombard@linux.ibm.com> References: <20230829092338.75785-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: wwGffMBGMZ8D709PajFlrxmZPJa9lmHV X-Proofpoint-GUID: wwGffMBGMZ8D709PajFlrxmZPJa9lmHV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=969 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V10 03/21] core/pldm: PLDM over MCTP Binding X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Enable the mctp binding over LPC bus interface and new wrappers to send and receive PLDM messages over the mctp library. PLDM is supported as a message type over MCTP. PLDM over MCTP binding defines the format of PLDM over MCTP messages. An MCTP Endpoint is the terminus for MCTP communication. A physical device that supports MCTP may provide one or more MCTP Endpoints. Endpoints are addressed using a logical address called the Endpoint ID, or EID. EIDs in MCTP are analogous to IP Addresses in Internet Protocol networking. The BMC EID default is 8. First byte of the PLDM over MCTP Message Fields identifies the MCTP message as carrying a PLDM message: Message Type (7 bits) PLDM = 0x01 (000_0001b). Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/Makefile.inc | 6 ++- core/pldm/Makefile.inc | 13 ++++++ core/pldm/pldm-mctp.c | 91 ++++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 44 ++++++++++++++++++++ hw/ast-bmc/ast-mctp.c | 18 +++++++++ include/pldm.h | 24 +++++++++++ 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 core/pldm/Makefile.inc create mode 100644 core/pldm/pldm-mctp.c create mode 100644 core/pldm/pldm.h create mode 100644 include/pldm.h diff --git a/core/Makefile.inc b/core/Makefile.inc index f80019b6a..263a0e506 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 000000000..ae45bb8ba --- /dev/null +++ b/core/pldm/Makefile.inc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# Copyright 2022 IBM Corp + +PLDM_DIR ?= core/pldm +SUBDIRS += $(PLDM_DIR) + +CPPFLAGS += -I$(SRC)/pldm/include/ +CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ + +PLDM_OBJS = pldm-mctp.o + +PLDM = $(PLDM_DIR)/built-in.a +$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c new file mode 100644 index 000000000..fb675849d --- /dev/null +++ b/core/pldm/pldm-mctp.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include "pldm.h" + +/* + * PLDM over MCTP (DSP0241) + * + * First byte of the MCTP message is the message Type = PLDM + * PLDM = 0x01 (000_0001b) + * + * Next bytes of the MCTP message (MCTP message body) contain the + * PLDM message (The base PLDM message fields are defined in DSP0240) + */ + +int pldm_mctp_message_tx(struct pldm_tx_data *tx) +{ + tx->mctp_msg_type = MCTP_MSG_TYPE_PLDM; + + return ast_mctp_message_tx(tx->tag_owner, tx->msg_tag, + &tx->mctp_msg_type, + tx->data_size + sizeof(tx->mctp_msg_type)); +} + +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len) +{ + struct pldm_rx_data *rx; + int rc = 0; + + rx = zalloc(sizeof(struct pldm_rx_data)); + if (!rx) { + prlog(PR_ERR, "failed to allocate rx message\n"); + return OPAL_NO_MEM; + } + + rx->msg = (struct pldm_msg *)buf; + rx->source_eid = eid; + rx->msg_len = len; + rx->tag_owner = tag_owner; + rx->msg_tag = msg_tag; + + /* Additional header information */ + if (unpack_pldm_header(&rx->msg->hdr, &rx->hdrinf)) { + prlog(PR_ERR, "%s: unable to decode header\n", __func__); + rc = OPAL_EMPTY; + goto out; + } + +out: + free(rx); + return rc; +} + +int pldm_mctp_init(void) +{ + int nbr_elt = 1, rc = OPAL_SUCCESS; + + int (*pldm_config[])(void) = { + ast_mctp_init, /* MCTP Binding */ + }; + + const char *pldm_config_error[] = { + "Failed to bind MCTP", + }; + + prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); + + for (int i = 0; i < nbr_elt; i++) { + rc = pldm_config[i](); + if (rc) { + prlog(PR_ERR, "%s\n", pldm_config_error[i]); + goto out; + } + } + +out: + prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); + return rc; +} + +void pldm_mctp_exit(void) +{ + ast_mctp_exit(); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h new file mode 100644 index 000000000..bd32cf853 --- /dev/null +++ b/core/pldm/pldm.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __COREPLDM_H__ +#define __COREPLDM_H__ + +#include +#include +#include + +struct pldm_tx_data { + /* Contains an message header and payload of an MCTP packet. + * Size of data[] + */ + size_t data_size; + + /* Holds data related to the routing of an MCTP packet */ + bool tag_owner; + uint8_t msg_tag; + + /* This byte is situated just before the message body */ + uint8_t mctp_msg_type; + + /* The message payload (e.g. PLDM message) */ + uint8_t data[1]; +}; + +struct pldm_rx_data { + struct pldm_header_info hdrinf; /* parsed message header */ + + struct pldm_msg *msg; + int msg_len; + int source_eid; + bool tag_owner; + uint8_t msg_tag; +}; + +int pldm_mctp_message_tx(struct pldm_tx_data *tx); + +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len); + +#endif /* __COREPLDM_H__ */ diff --git a/hw/ast-bmc/ast-mctp.c b/hw/ast-bmc/ast-mctp.c index c2efb7b27..00f66abec 100644 --- a/hw/ast-bmc/ast-mctp.c +++ b/hw/ast-bmc/ast-mctp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -286,6 +287,23 @@ static void message_rx(uint8_t eid, bool tag_owner, prlog(PR_TRACE, "message received: msg type: %x, len %zd" " (eid: %d), rx tag %d owner %d\n", *msg, len, eid, tag_owner, msg_tag); + + /* The first byte defines the type of MCTP packet payload + * contained in the message data portion of the MCTP message. + * (See DSP0236 for more details about MCTP packet fields). + * For now we only support PLDM over MCTP. + */ + switch (*msg) { + case MCTP_MSG_TYPE_PLDM: + /* handle the PLDM message */ + pldm_mctp_message_rx(eid, tag_owner, msg_tag, + msg + sizeof(uint8_t), + len - sizeof(uint8_t)); + break; + default: + prlog(PR_ERR, "%s - not a pldm message type (type: %x)\n", + __func__, *msg); + } } /* diff --git a/include/pldm.h b/include/pldm.h new file mode 100644 index 000000000..617287fe3 --- /dev/null +++ b/include/pldm.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __PLDM_H__ +#define __PLDM_H__ + +/** + * Handle PLDM messages received from MCTP + */ +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len); + +/** + * PLDM over MCTP initialization + */ +int pldm_mctp_init(void); + +/** + * PLDM over MCTP stop + */ +void pldm_mctp_exit(void); + +#endif /* __PLDM_H__ */