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__ */