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