From patchwork Tue Sep 13 10:26: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: 1677214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=leMNPlcZ; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfmK5Zcyz1ynm for ; Tue, 13 Sep 2022 20:27:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfmK5SS1z30NN for ; Tue, 13 Sep 2022 20:27: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=leMNPlcZ; 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=leMNPlcZ; 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 4MRfm20t46z308b for ; Tue, 13 Sep 2022 20:27:13 +1000 (AEST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9eWEH004457 for ; Tue, 13 Sep 2022 10:27: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=CVsyzhGuyYuloI2IrlKiVJYvCjHb6Vx2Qp5WCiDjWqQ=; b=leMNPlcZOB9BnT5BwnZBqqno4K1YUPUT7LEMz7YuMpaGlLR+JtCAwjTLeMBBhe3DLMJk pJC+O+V2I62YUsxhpwPts0WwEms2GZtpGMy+rm2PczuzoUjvEfszoiw7XdgUTO7hGq8C NAb8++d7okHjZncMCa3lPA+kB+DmGk93W8cRhZMcaoYTDZjK9sQCYSGVpZ+wpkUOlgkE 5f4iKcuutcKBPvQ3BuAdajGnZd7FfglVVZrRa33EPChaPXuLolSR9+ZzTljcCSlUtGPh tOtCjt3zRNt5PV4fwO2axZcPmqY/UMvp/elcz/ZUoId1KgFTo+aMqvdNht3vC9aOlCeV /w== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmjay1c1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:11 +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 28DALIq2003187 for ; Tue, 13 Sep 2022 10:27:09 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06fra.de.ibm.com with ESMTP id 3jghuhtps4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:09 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DAR7WI30736666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:07 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1A372A4051 for ; Tue, 13 Sep 2022 10:27:07 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E68A1A4040 for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:06 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:26:47 +0200 Message-Id: <20220913102705.65506-4-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> References: <20220913102705.65506-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ce7z0-Oo12kALMiHtgDM5oUcSRwGPsIA X-Proofpoint-ORIG-GUID: ce7z0-Oo12kALMiHtgDM5oUcSRwGPsIA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-13_03,2022-09-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V6 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 Reviewed-by: Abhishek Singh Tomar --- core/Makefile.inc | 6 ++- core/pldm/Makefile.inc | 13 +++++ core/pldm/pldm-mctp.c | 118 +++++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 33 ++++++++++++ include/pldm.h | 18 +++++++ 5 files changed, 187 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..c878ef1f --- /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-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..832b767a --- /dev/null +++ b/core/pldm/pldm-mctp.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_mctp_message_tx: 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_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int len) +{ + uint8_t *msg; + int rc; + + /* Message TYPE: PLDM = 0x01 (000_0001b) - DSP0240 */ + msg = zalloc(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 handle_message_rx(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 message_rx(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; + } + + handle_message_rx(eid, &msg[1], len - 1); +} + +int pldm_mctp_init(uint8_t mode) +{ + int rc; + + /* MCTP Binding */ + rc = ast_mctp_init(mode, message_rx); + 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..a006d1f4 --- /dev/null +++ b/core/pldm/pldm.h @@ -0,0 +1,33 @@ +/* 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; +}; + +int pldm_mctp_message_tx(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..3aae560c --- /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(uint8_t mode); + +/** + * PLDM over MCTP stop + */ +void pldm_mctp_exit(void); + +#endif /* __PLDM_H__ */