From patchwork Thu May 11 16:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1780169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW5Rykgu; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHHMk4k7bz213w for ; Fri, 12 May 2023 02:26:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QHHMj6HQHz3fPy for ; Fri, 12 May 2023 02:26:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW5Rykgu; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bW5Rykgu; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4QHHKz58Y6z3cfT for ; Fri, 12 May 2023 02:24:55 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34BGNrQH026167 for ; Thu, 11 May 2023 16:24:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=wDgW3xK802zgGoqN34zDdj7hw+eG/1QfpKEbMXv1eD0=; b=bW5Rykgu1hs7n1uTaJ4FGoOFWUff3YQG0u8c7fSk6IBFs8j5iO+gRB5LGkn9rjqF8bu8 sz49H9B0JFYAVG6F6gjoYql3VQUk8zWl9wt61l4jI/SSTjrt7GgDEawFRTESHxO7Bqlz B9SLnMRfjH13mXahH/6+clG54fWDl9UlIz7YS53oSI/uq9fi9PzSQPrHOPs1/qU6WM6z 5wm27TbKDx2/DZDHsN9LcpxETxw+PKIDknHxqqgJfq51kQe45fTC8NBNU/zoo3O5gD2W XJ34788CUdrCRwDV307zz3rXrOlRDdNXewW5GpCV33/lsjUhVW73+1EyBjIxqnmrA5aF qA== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qh3exgsdu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:52 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34B4w6T0010243 for ; Thu, 11 May 2023 16:24:50 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3qf896suja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 16:24:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34BGOmIe15467086 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 May 2023 16:24:48 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F294520043 for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B55F620040 for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.179.3.92]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Thu, 11 May 2023 16:24:47 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 11 May 2023 18:24:28 +0200 Message-Id: <20230511162446.10457-4-clombard@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511162446.10457-1-clombard@linux.ibm.com> References: <20230511162446.10457-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9ROOTQFU5ofIqa3qx5Ded8GSQjdmqHR3 X-Proofpoint-GUID: 9ROOTQFU5ofIqa3qx5Ded8GSQjdmqHR3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-11_13,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 spamscore=0 adultscore=0 impostorscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305110139 Subject: [Skiboot] [PATCH V7 03/21] core/pldm: PLDM over MCTP Binding X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Enable the mctp binding over LPC bus interface and new wrappers to send and receive PLDM messages over the mctp library. PLDM is supported as a message type over MCTP. PLDM over MCTP binding defines the format of PLDM over MCTP messages. An MCTP Endpoint is the terminus for MCTP communication. A physical device that supports MCTP may provide one or more MCTP Endpoints. Endpoints are addressed using a logical address called the Endpoint ID, or EID. EIDs in MCTP are analogous to IP Addresses in Internet Protocol networking. The BMC EID default is 8. First byte of the PLDM over MCTP Message Fields identifies the MCTP message as carrying a PLDM message: Message Type (7 bits) PLDM = 0x01 (000_0001b). Reviewed-by: Abhishek Singh Tomar Signed-off-by: Christophe Lombard --- core/Makefile.inc | 6 +++- core/pldm/Makefile.inc | 13 +++++++ core/pldm/pldm-mctp.c | 79 ++++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 44 +++++++++++++++++++++++ hw/ast-bmc/ast-mctp.c | 18 ++++++++++ include/pldm.h | 24 +++++++++++++ 6 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 core/pldm/Makefile.inc create mode 100644 core/pldm/pldm-mctp.c create mode 100644 core/pldm/pldm.h create mode 100644 include/pldm.h diff --git a/core/Makefile.inc b/core/Makefile.inc index f80019b6..263a0e50 100644 --- a/core/Makefile.inc +++ b/core/Makefile.inc @@ -22,8 +22,12 @@ endif CORE=core/built-in.a +ifeq ($(CONFIG_PLDM),1) +include $(SRC)/core/pldm/Makefile.inc +endif + CFLAGS_SKIP_core/relocate.o = -pg -fstack-protector-all CFLAGS_SKIP_core/relocate.o += -fstack-protector -fstack-protector-strong CFLAGS_SKIP_core/relocate.o += -fprofile-arcs -ftest-coverage -$(CORE): $(CORE_OBJS:%=core/%) +$(CORE): $(CORE_OBJS:%=core/%) $(PLDM) diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc new file mode 100644 index 00000000..ae45bb8b --- /dev/null +++ b/core/pldm/Makefile.inc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# Copyright 2022 IBM Corp + +PLDM_DIR ?= core/pldm +SUBDIRS += $(PLDM_DIR) + +CPPFLAGS += -I$(SRC)/pldm/include/ +CPPFLAGS += -I$(SRC)/pldm/include/libpldm/oem/ibm/ + +PLDM_OBJS = pldm-mctp.o + +PLDM = $(PLDM_DIR)/built-in.a +$(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c new file mode 100644 index 00000000..7be8e8ba --- /dev/null +++ b/core/pldm/pldm-mctp.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Copyright 2022 IBM Corp. + +#define pr_fmt(fmt) "PLDM: " fmt + +#include +#include +#include +#include +#include "pldm.h" + +/* + * PLDM over MCTP (DSP0241) + * + * First byte of the MCTP message is the message Type = PLDM + * PLDM = 0x01 (000_0001b) + * + * Next bytes of the MCTP message (MCTP message body) contain the + * PLDM message (The base PLDM message fields are defined in DSP0240) + */ + +int pldm_mctp_message_tx(struct pldm_tx_data *tx) +{ + tx->mctp_msg_type = MCTP_MSG_TYPE_PLDM; + + return ast_mctp_message_tx(false, 0, + &tx->mctp_msg_type, + tx->data_size + sizeof(tx->mctp_msg_type)); +} + +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len) +{ + struct pldm_rx_data *rx; + int rc = 0; + + rx = zalloc(sizeof(struct pldm_rx_data)); + if (!rx) { + prlog(PR_ERR, "failed to allocate rx message\n"); + return OPAL_NO_MEM; + } + + rx->msg = (struct pldm_msg *)buf; + rx->source_eid = eid; + rx->msg_len = len; + rx->tag_owner = tag_owner; + rx->msg_tag = msg_tag; + + /* Additional header information */ + if (unpack_pldm_header(&rx->msg->hdr, &rx->hdrinf)) { + prlog(PR_ERR, "%s: unable to decode header\n", __func__); + rc = OPAL_EMPTY; + goto out; + } + +out: + free(rx); + return rc; +} + +int pldm_mctp_init(void) +{ + int rc; + + prlog(PR_NOTICE, "%s - Getting PLDM data\n", __func__); + + /* MCTP Binding */ + rc = ast_mctp_init(); + if (rc) + prlog(PR_ERR, "Failed to bind MCTP\n"); + + prlog(PR_NOTICE, "%s - done, rc: %d\n", __func__, rc); + return rc; +} + +void pldm_mctp_exit(void) +{ + ast_mctp_exit(); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h new file mode 100644 index 00000000..0c7bb17d --- /dev/null +++ b/core/pldm/pldm.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __COREPLDM_H__ +#define __COREPLDM_H__ + +#include +#include +#include + +struct pldm_tx_data { + /* Contains an message header and payload of an MCTP packet. + * Size of data[] + */ + size_t data_size; + + /* Holds data related to the routing of an MCTP packet */ + bool tag_owner; + uint8_t msg_tag; + + /* This byte is situated just before the message body */ + uint8_t mctp_msg_type; + + /* The message payload (e.g. PLDM message) */ + uint8_t data[0]; +}; + +struct pldm_rx_data { + struct pldm_header_info hdrinf; /* parsed message header */ + + struct pldm_msg *msg; + int msg_len; + int source_eid; + bool tag_owner; + uint8_t msg_tag; +}; + +int pldm_mctp_message_tx(struct pldm_tx_data *tx); + +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len); + +#endif /* __COREPLDM_H__ */ diff --git a/hw/ast-bmc/ast-mctp.c b/hw/ast-bmc/ast-mctp.c index 9a9e0484..b78b8185 100644 --- a/hw/ast-bmc/ast-mctp.c +++ b/hw/ast-bmc/ast-mctp.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -342,6 +343,23 @@ static void message_rx(uint8_t eid, bool tag_owner, prlog(PR_TRACE, "message received: msg type: %x, len %zd " "(eid: %d), rx tag %d owner %d \n", *msg, len, eid, tag_owner, msg_tag); + + /* The first byte defines the type of MCTP packet payload + * contained in the message data portion of the MCTP message. + * (See DSP0236 for more details about MCTP packet fields). + * For now we only support PLDM over MCTP. + */ + switch (*msg) { + case MCTP_MSG_TYPE_PLDM: + /* handle the PLDM message */ + pldm_mctp_message_rx(eid, tag_owner, msg_tag, + msg + sizeof(uint8_t), + len - sizeof(uint8_t)); + break; + default: + prlog(PR_ERR, "%s - not a pldm message type (type: %x)\n", + __func__, *msg); + } } /* diff --git a/include/pldm.h b/include/pldm.h new file mode 100644 index 00000000..617287fe --- /dev/null +++ b/include/pldm.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * Copyright 2022 IBM Corp. + */ + +#ifndef __PLDM_H__ +#define __PLDM_H__ + +/** + * Handle PLDM messages received from MCTP + */ +int pldm_mctp_message_rx(uint8_t eid, bool tag_owner, uint8_t msg_tag, + const uint8_t *buf, int len); + +/** + * PLDM over MCTP initialization + */ +int pldm_mctp_init(void); + +/** + * PLDM over MCTP stop + */ +void pldm_mctp_exit(void); + +#endif /* __PLDM_H__ */