From patchwork Tue Sep 13 10:27:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677233 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=fVHu74AS; 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 4MRfpp3Fd2z1ynm for ; Tue, 13 Sep 2022 20:29:38 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfpp2QkLz3bk0 for ; Tue, 13 Sep 2022 20:29:38 +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=fVHu74AS; 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=fVHu74AS; 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 4MRfmM45gqz3c3N for ; Tue, 13 Sep 2022 20:27:31 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA9FV0006104 for ; Tue, 13 Sep 2022 10:27:29 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=IGmQrrLfDfU22RJRRr9ZO0DlkhU+/b9aTlfJU+lD4r4=; b=fVHu74AS1EUfriaDvt1XTGQDmBh9ic8rQc/So2DIGB0A/8ludHqme2xPqAzeLEIfArNp Iat0R+AttoB8AvhQxvrokTJGaN6YOYU74BIUj5KSnZlo6RtAxexWAI+N9608im+odsmv najMLAG4dFj82POQG6UUdgKiEhCCrkJH5EhDHWBzGIpdzFGpLAnGlc/qy4a1RAPc0A/Y MD+TflzQz6vt3BZMz4gG8GeNRAW3A7GqDyDttlBgvkGHSrhhttx0lfEbg3ku0wAZJN2n 2xFw1U1jRBPQMvzE1H852QXD8CxKmJgxhaHeJ9+jRLiqMPGrWR7wFdQT0DZ0xzQyFIf+ bQ== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq7a1sfk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +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 28DAKqMW003642 for ; Tue, 13 Sep 2022 10:27:27 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umyb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:26 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARO6X34799998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:24 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA49211C050 for ; Tue, 13 Sep 2022 10:27:24 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9135911C04A for ; Tue, 13 Sep 2022 10:27:24 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:24 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:10 +0200 Message-Id: <20220913102724.65563-2-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 346-SV5Lmc9VPbcbHiLUwhTyB35eQABJ X-Proofpoint-GUID: 346-SV5Lmc9VPbcbHiLUwhTyB35eQABJ 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 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 01/15] core/pldm: Handle Watchdog timer. 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" Encode a PLDM platform event message to send the heartbeat to the BMC. Watchdog is "armed" when a PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE is received. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 + core/pldm/pldm-watchdog.c | 134 ++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 1 + include/pldm.h | 5 ++ 4 files changed, 142 insertions(+) create mode 100644 core/pldm/pldm-watchdog.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index defcfde6..a067272b 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -9,11 +9,13 @@ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes +CFLAGS_$(PLDM_DIR)/pldm-watchdog.o = -Wno-strict-prototypes PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o +PLDM_OBJS += pldm-watchdog.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-watchdog.c b/core/pldm/pldm-watchdog.c new file mode 100644 index 00000000..11a5f187 --- /dev/null +++ b/core/pldm/pldm-watchdog.c @@ -0,0 +1,134 @@ +// 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 +#include "pldm.h" + +#define DEFAULT_WATCHDOG_TIMEOUT_SEC (10 * 60) /* 10 min */ + +/* Whether the watchdog timer is armed and Skiboot should be sending + * regular heartbeats. + */ +bool watchdog_armed; + +/* The period (in seconds) of the PLDM watchdog, as dictated by BMC */ +int watchdog_period_sec = DEFAULT_WATCHDOG_TIMEOUT_SEC; + +static struct lock sequence_lock; +static uint8_t sequence_number; + +static void watchdog_reset_timer_complete(struct pldm_rx_data *rx, + void *data __unused) +{ + struct pldm_platform_event_message_resp response; + size_t payload_len; + int rc; + + if (rx == NULL) { + prlog(PR_ERR, "%s: Response not received\n", __func__); + return; + } + + /* Decode the message */ + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + + rc = decode_platform_event_message_resp( + rx->msg, + payload_len, + &response.completion_code, + &response.platform_event_status); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode PlatformEventMessage Error, rc: %d, cc: %d, pes: %d\n", + rc, response.completion_code, + response.platform_event_status); + } +} + +int pldm_watchdog_reset_timer(void) +{ + uint8_t heartbeat_elapsed_data[2]; + uint32_t request_length; + size_t payload_len; + char *request_msg; + int rc; + + struct pldm_platform_event_message_req event_message_req = { + .format_version = PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, + .tid = HOST_TID, + .event_class = PLDM_HEARTBEAT_TIMER_ELAPSED_EVENT, + }; + + /* watchdog is not armed, so no need to send the heartbeat */ + if (!watchdog_armed) { + prlog(PR_ERR, "%s - PLDM watchdog is not armed, not sending the heartbeat\n", + __func__); + return OPAL_PARAMETER; + } + + prlog(PR_INFO, "%s - send the heartbeat to the BMC, sequence: %d, period: %d\n", + __func__, sequence_number, watchdog_period_sec); + + /* Send the event request */ + heartbeat_elapsed_data[0] = PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION; + + /* We need to make sure that we send the BMC the correct + * sequence number. To prevent possible race conditions for the + * sequence number, lock it while we're incrementing and + * sending it down. + */ + lock(&sequence_lock); + heartbeat_elapsed_data[1] = sequence_number++; + + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(heartbeat_elapsed_data); + + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + sizeof(heartbeat_elapsed_data); + request_msg = zalloc(request_length); + + /* Encode the platform event message request */ + rc = encode_platform_event_message_req( + DEFAULT_INSTANCE_ID, + event_message_req.format_version, + event_message_req.tid, + event_message_req.event_class, + heartbeat_elapsed_data, + sizeof(heartbeat_elapsed_data), + (struct pldm_msg *)request_msg, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(request_msg); + sequence_number--; + return OPAL_PARAMETER; + } + unlock(&sequence_lock); + + /* Send and get the response message bytes */ + rc = pldm_requester_queue(request_msg, request_length - 1, + watchdog_reset_timer_complete, NULL); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(request_msg); + sequence_number--; + return rc; + } + free(request_msg); + + return OPAL_SUCCESS; +} + +int pldm_watchdog_init(void) +{ + init_lock(&sequence_lock); + + return pldm_watchdog_reset_timer(); +} diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 35b0dd66..5b080644 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -41,6 +41,7 @@ struct pldm_rx_data { }; int pldm_mctp_message_tx(uint8_t dest_id, uint8_t *buf, int len); +int pldm_watchdog_reset_timer(void); /* Responder support */ int pldm_responder_handle_request(struct pldm_rx_data *rx); diff --git a/include/pldm.h b/include/pldm.h index 9abb82ac..231b517f 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -42,4 +42,9 @@ int pldm_lid_files_init(struct blocklevel_device **bl); */ bool pldm_lid_files_exit(struct blocklevel_device *bl); +/** + * Initialize and reset the watchdog + */ +int pldm_watchdog_init(void); + #endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:27:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677234 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=oP4ygHZR; 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 4MRfpx49Wyz1ynm for ; Tue, 13 Sep 2022 20:29:45 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfpx3Mcmz3bmc for ; Tue, 13 Sep 2022 20:29:45 +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=oP4ygHZR; 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=oP4ygHZR; 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 4MRfmM4Q0Bz3c5v for ; Tue, 13 Sep 2022 20:27:31 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPGf6001240 for ; Tue, 13 Sep 2022 10:27:30 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=7sRTDzzuj0tjYPsCpGmSrPuZ/tpVVTpLT8KW4/bntgU=; b=oP4ygHZRgCY3mMgjDZs8D6iSL9mT9l7/KrnjWmGtGq4MWngyFBlyf4Zm3kzTh/K/Xyme ErLjtBl6i+POiKT3wMo532/7joif6noFQmqsPAUAU0MfgSp/oykGK9bLM+jtWcUSGZ4P irZEdDXfVgPkbGWDwgOO1a0LWZClnqo6CB96/MamQuqreu2OAHLXFYaTImXvkTKhOy1k ht45SAX0swQBBRTaQDDU4EEL26ppCf3wOct8Y1Ab1QEkAz8svtyljRwsS84Ff7j4O65D lOfYfTQza4A3i22BdEeH9Xums3ESU3wXXKL1eD/Y7IL/0w16oc1dxnqX/NLivTYbK+2M hw== 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 3jjr3j81d5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKbVH005702 for ; Tue, 13 Sep 2022 10:27:27 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:27 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARPTD39649564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:25 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 044EA11C050 for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE32611C04A for ; Tue, 13 Sep 2022 10:27:24 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:24 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:11 +0200 Message-Id: <20220913102724.65563-3-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 6GouHrZJ05cKz3pdn5BNfR62A7okC2iU X-Proofpoint-ORIG-GUID: 6GouHrZJ05cKz3pdn5BNfR62A7okC2iU 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 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 02/15] core/pldm: Decode the SetEventReceiver request 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" The SetEventReceiver command is used to set the address of the Event Receiver into a terminus that generates event messages. It is also used to globally enable or disable whether event messages are generated from the terminus. For the time being, only the following global event message is supported: PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE. The Event Receiver acknowledges receiving the PLDM Event Message in the response to this command. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 1 + core/pldm/pldm-responder.c | 97 ++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 3 files changed, 100 insertions(+) diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index a067272b..5d10d572 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -10,6 +10,7 @@ CPPFLAGS += -I$(SRC)/pldm/ibm/libpldm/ CFLAGS_$(PLDM_DIR)/pldm-platform-requests.o = -Wno-strict-prototypes CFLAGS_$(PLDM_DIR)/pldm-bios-requests.o = -Wno-strict-prototypes CFLAGS_$(PLDM_DIR)/pldm-watchdog.o = -Wno-strict-prototypes +CFLAGS_$(PLDM_DIR)/pldm-responder.o = -Wno-strict-prototypes PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 230b9c05..4e5b0378 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include "pldm.h" @@ -377,6 +379,97 @@ static struct pldm_cmd pldm_base_get_version = { .handler = base_get_version_handler, }; +/* + * PLDM Platform commands support + */ +static struct pldm_type pldm_platform_type = { + .name = "platform", + .pldm_type_id = PLDM_PLATFORM, +}; + +struct event_receiver_req { + uint8_t event_message_global_enable; + uint8_t transport_protocol_type; + uint8_t event_receiver_address_info; + uint16_t heartbeat_timer; +}; + +#define MIN_WATCHDOG_TIMEOUT_SEC 15 + +/* + * SetEventReceiver (0x04) + * The SetEventReceiver command is used to set the address of the Event + * Receiver into a terminus that generates event messages. It is also + * used to globally enable or disable whether event messages are + * generated from the terminus. + */ +static int platform_set_event_receiver_handler(const struct pldm_rx_data *req) +{ + struct event_receiver_req receiver_req; + uint8_t cc = PLDM_SUCCESS; + int rc = OPAL_SUCCESS; + + /* decode SetEventReceiver request data */ + rc = decode_set_event_receiver_req( + req->msg, + PLDM_SET_EVENT_RECEIVER_REQ_BYTES, + &receiver_req.event_message_global_enable, + &receiver_req.transport_protocol_type, + &receiver_req.event_receiver_address_info, + &receiver_req.heartbeat_timer); + if (rc) { + prlog(PR_ERR, "Failed to decode SetEventReceiver request, rc = %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + /* invoke the appropriate callback handler */ + prlog(PR_DEBUG, "%s - event_message_global_enable: %d, " + "transport_protocol_type: %d " + "event_receiver_address_info: %d " + "heartbeat_timer: 0x%x\n", + __func__, + receiver_req.event_message_global_enable, + receiver_req.transport_protocol_type, + receiver_req.event_receiver_address_info, + receiver_req.heartbeat_timer); + + if (receiver_req.event_message_global_enable != + PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) { + + prlog(PR_ERR, "%s - invalid value for message global enable received: %d\n", + __func__, receiver_req.event_message_global_enable); + cc = PLDM_PLATFORM_ENABLE_METHOD_NOT_SUPPORTED; + } + + if (receiver_req.heartbeat_timer < MIN_WATCHDOG_TIMEOUT_SEC) { + prlog(PR_ERR, "%s - BMC requested watchdog timeout that's too small: %d\n", + __func__, receiver_req.heartbeat_timer); + cc = PLDM_PLATFORM_HEARTBEAT_FREQUENCY_TOO_HIGH; + } else { + /* set the internal watchdog period to what BMC indicated */ + watchdog_period_sec = receiver_req.heartbeat_timer; + } + + /* send the response to BMC */ + cc_resp(req, PLDM_PLATFORM, PLDM_SET_EVENT_RECEIVER, cc); + + /* no error happened above, so arm the watchdog and set the default timeout */ + if (cc == PLDM_SUCCESS) { + watchdog_armed = true; + pldm_watchdog_reset_timer(); + } + + return rc; +} + +static struct pldm_cmd pldm_platform_set_event_receiver = { + .name = "PLDM_SET_EVENT_RECEIVER", + .pldm_cmd_id = PLDM_SET_EVENT_RECEIVER, + .handler = platform_set_event_receiver_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -417,5 +510,9 @@ int pldm_responder_init(void) add_cmd(&pldm_base_type, &pldm_base_get_commands); add_cmd(&pldm_base_type, &pldm_base_get_version); + /* Register platform commands we'll respond to - DSP0248 */ + add_type(&pldm_platform_type); + add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver); + return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 5b080644..8c7d79af 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -12,6 +12,8 @@ /* Common support */ void printbuf(const char *name, const char *msg, int len); +extern bool watchdog_armed; +extern int watchdog_period_sec; /* * EID is the MCTP endpoint ID, which aids in routing MCTP packets. From patchwork Tue Sep 13 10:27:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677235 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=WY8Ko1hJ; 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 4MRfq45VN6z1ynm for ; Tue, 13 Sep 2022 20:29:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfq451MFz3cDb for ; Tue, 13 Sep 2022 20:29:52 +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=WY8Ko1hJ; 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=WY8Ko1hJ; 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 4MRfmM6f0yz3bk0 for ; Tue, 13 Sep 2022 20:27:31 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA9CZt005940 for ; Tue, 13 Sep 2022 10:27:30 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=ixnH2j58Pjh+g0wqVMUAAVASz+dItxSuEjrffKdwfiM=; b=WY8Ko1hJ9mNvcB/sU2B8xeZVy7dv1O7JMSbru6oRPl/86fTzVNLwMnGKYf0yMjKdNx42 BaNuJRKb28/2GjBSl2ri3+3Aft0GpqBSzd6S1MoU18xsPmAaNAYsGIsikpd0e4os8gb5 fdlVQEQN2a+2jqYHN9TLeZfJSHYHCvWVVeBetPNcCB3lQNUcNzkGTzKIgOgbSL/GuXUt OE8/Bg6LK+F8WOOXOYGlTE9l106CKqk/9VQOvG6lEMMoF2NNjeJZbWMWVG4MeE8z9H2T yqA/o3KYypEdAG879+cnZGYuE1SM3ehR6ZftLId5U0C9oEo44q1H3Pxhh8TxF0PgSQQn 6g== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq7a1sg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAK9lf022993 for ; Tue, 13 Sep 2022 10:27:27 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 3jgj78tptb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:27 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARPSJ39649566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:25 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40A7B11C050 for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18F7711C04A for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:12 +0200 Message-Id: <20220913102724.65563-4-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6zEcYSpBOKT7yTAqJWKNtFRpLGvu0uzD X-Proofpoint-GUID: 6zEcYSpBOKT7yTAqJWKNtFRpLGvu0uzD 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 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 03/15] core/pldm: Decode the PlatformEventMessage request 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 Event Messages are sent as PLDM request messages to the Event Receiver using the PlatformEventMessage command. The Event Receiver acknowledges receiving the PLDM Event Message in the response to this command. Signed-off-by: Christophe Lombard --- core/pldm/pldm-platform-requests.c | 15 ++++ core/pldm/pldm-responder.c | 110 ++++++++++++++++++++++++++++- core/pldm/pldm.h | 1 + 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index ca66157c..e7c54e65 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -390,6 +390,21 @@ static int encode_and_queue_get_pdr_req(struct pldm_pdrs *pdrs) return rc; } +int pldm_platform_reload_pdrs(void) +{ + struct pldm_pdrs *pdrs = zalloc(sizeof(struct pldm_pdrs)); + + /* destroy current repo and mark repo not ready */ + pdr_init_complete(false); + + /* make a new PDR repository */ + pdrs_repo = pldm_pdr_init(); + + /* collect all PDrs into a PDR Repository */ + pdrs->record_hndl = 0; + return encode_and_queue_get_pdr_req(pdrs); +} + static int pdrs_init(void) { struct pldm_pdrs pdrs; diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 4e5b0378..a1a19220 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "pldm.h" @@ -370,7 +371,7 @@ static int base_get_version_handler(const struct pldm_rx_data *req) return OPAL_HARDWARE; } - return OPAL_SUCCESS; + return pldm_platform_reload_pdrs(); } static struct pldm_cmd pldm_base_get_version = { @@ -470,6 +471,112 @@ static struct pldm_cmd pldm_platform_set_event_receiver = { .handler = platform_set_event_receiver_handler, }; +struct event_message_req { + uint8_t format_version; + uint8_t tid; + uint8_t event_class; + size_t event_data_offset; +}; + +/* + * PlatformEventMessage (0x10) + * PLDM Event Messages are sent as PLDM request messages to the Event + * Receiver using the PlatformEventMessage command. + */ +static int platform_event_message(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_platform_event_message_resp)]; + struct pldm_bios_attribute_update_event_req *request; + struct event_message_req message_req; + uint8_t *bios_attribute_handles; + uint8_t cc = PLDM_SUCCESS; + int rc, i; + + /* decode PlatformEventMessage request data */ + rc = decode_platform_event_message_req( + req->msg, + sizeof(struct event_message_req), + &message_req.format_version, + &message_req.tid, + &message_req.event_class, + &message_req.event_data_offset); + if (rc) { + prlog(PR_ERR, "Failed to decode PlatformEventMessage request, rc = %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + prlog(PR_DEBUG, "%s - format_version: %d, " + "tid: %d " + "event_class: %d " + "event_data_offset: 0x%lx\n", + __func__, + message_req.format_version, + message_req.tid, + message_req.event_class, + message_req.event_data_offset); + + /* we don't support any other event than the PDR Repo Changed event */ + if ((message_req.event_class != PLDM_PDR_REPOSITORY_CHG_EVENT) && + (message_req.event_class != PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE)) { + prlog(PR_ERR, "%s - Invalid event class %d in platform event handler\n", + __func__, message_req.event_class); + cc = PLDM_ERROR; + } + + rc = encode_platform_event_message_resp( + req->hdrinf.instance, + cc, + PLDM_EVENT_NO_LOGGING, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send PlatformEventMessage response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + /* invoke the appropriate callback handler */ + if (message_req.event_class == PLDM_PDR_REPOSITORY_CHG_EVENT) + return pldm_platform_reload_pdrs(); + + /* When the attribute value changes for any BIOS attribute, then + * PlatformEventMessage command with OEM event type + * PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE is send to + * host with the list of BIOS attribute handles. + */ + if (message_req.event_class == PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE) { + request = (struct pldm_bios_attribute_update_event_req *)req->msg->payload; + bios_attribute_handles = (uint8_t *)request->bios_attribute_handles; + + prlog(PR_DEBUG, "%s - OEM_EVENT_BIOS_ATTRIBUTE_UPDATE, handles: %d\n", + __func__, request->num_handles); + + /* list of BIOS attribute handles */ + for (i = 0; i < request->num_handles; i++) { + prlog(PR_DEBUG, "%s - OEM_EVENT_BIOS_ATTRIBUTE_UPDATE: handle(%d): %d\n", + __func__, i, *bios_attribute_handles); + bios_attribute_handles += sizeof(uint16_t); + } + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_platform_event_message = { + .name = "PLDM_PLATFORM_EVENT_MESSAGE", + .pldm_cmd_id = PLDM_PLATFORM_EVENT_MESSAGE, + .handler = platform_event_message, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -513,6 +620,7 @@ int pldm_responder_init(void) /* Register platform commands we'll respond to - DSP0248 */ add_type(&pldm_platform_type); add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver); + add_cmd(&pldm_platform_type, &pldm_platform_event_message); return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 8c7d79af..688b767c 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -69,6 +69,7 @@ int pldm_bios_init(void); uint8_t pldm_base_get_bmc_tid(void); int pldm_base_get_tid_req(void); +int pldm_platform_reload_pdrs(void); int pldm_platform_init(void); void pldm_platform_exit(void); From patchwork Tue Sep 13 10:27:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677238 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=gFD1QRZv; 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 4MRfqR74VZz1ync for ; Tue, 13 Sep 2022 20:30:11 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqR6cZkz3cLb for ; Tue, 13 Sep 2022 20:30:11 +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=gFD1QRZv; 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=gFD1QRZv; 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 4MRfmP0Jzhz3bqY for ; Tue, 13 Sep 2022 20:27:32 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA9CIc005959 for ; Tue, 13 Sep 2022 10:27:30 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=+PJmSs5qLN26aHo58MhZsDbMIKxhYRevrdA81n0ubjk=; b=gFD1QRZv0wojkoEjs1q5a1enASu8SqL/11c0Z+dGHTS8I7xSC1lAzhQ53cjhg0FQWa49 NL92BvjuOTZusEV3+K/1+eVM/KmC2QDHmJ9uULtUx1rz6/4/GGsyqtB00Zo/7L91jeAc Drw4fwYJR6IF9eQAF9o4mGtHf5UuUAMljcQM2e2S/oa/yHBkveoI/Iw9s0Vd6xUU0Asu InUNQLqEJ1vnsjvGxFkKJSsr9vZ2EbUAcsAVI8m276IPQQb7mhcUSQnvs7OnVQiIXUQr Tgbgt2Qk9z7isxKL/IabIdgvtTSQSrlEI2lvG2TEBHspkOZJq49UDRfuN//OD9Z2otEM sw== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq7a1sg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKcKr029930 for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma01fra.de.ibm.com with ESMTP id 3jgj78tp3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:27 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARP0f39649568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:25 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BB8411C050 for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5406411C04A for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:13 +0200 Message-Id: <20220913102724.65563-5-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 4IuILZdZv4B3ULA-7AyT942XoT8WYaMj X-Proofpoint-GUID: 4IuILZdZv4B3ULA-7AyT942XoT8WYaMj 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 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 04/15] core/pldm: Decode the GetStateSensorReadings request 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" The GetStateSensorReadings command can return readings for multiple state sensors (a PLDM State Sensor that returns more than one set of state information is called a composite state sensor). The Event Receiver acknowledges receiving the PLDM Event Message in the response to this command. Signed-off-by: Christophe Lombard --- core/pldm/pldm-responder.c | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index a1a19220..0224ea75 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -577,6 +577,89 @@ static struct pldm_cmd pldm_platform_event_message = { .handler = platform_event_message, }; +struct get_state_sensor_readings_req { + uint16_t sensor_id; + bitfield8_t sensor_rearm; + uint8_t reserved; +}; + +/* + * GetStateSensorReadings (0x21) + * The GetStateSensorReadings command can return readings for multiple + * state sensors (a PLDM State Sensor that returns more than one set of + * state information is called a composite state sensor). + */ +static int platform_get_state_sensor_readings(const struct pldm_rx_data *req) +{ + struct get_state_sensor_readings_req readings_req; + size_t response_length; + char *response_msg; + int rc; + + get_sensor_state_field sensor_state = { + .sensor_op_state = PLDM_SENSOR_UNKNOWN, + .present_state = 0, + .previous_state = 0, + .event_state = 0 + }; + + /* decode GetStateSensorReadings request data */ + rc = decode_get_state_sensor_readings_req( + req->msg, + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES, + &readings_req.sensor_id, + &readings_req.sensor_rearm, + &readings_req.reserved); + if (rc) { + prlog(PR_ERR, "Failed to decode GetStateSensorReadings request, rc = %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + prlog(PR_DEBUG, "%s - sensor_id: %d, sensor_rearm: %x\n", + __func__, readings_req.sensor_id, + readings_req.sensor_rearm.byte); + + /* send state sensor reading response */ + response_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_state_sensor_readings_resp) + + (sizeof(get_sensor_state_field) * 1); + response_msg = zalloc(response_length); + + rc = encode_get_state_sensor_readings_resp( + req->hdrinf.instance, + PLDM_SUCCESS, + 1, /* sensor count of 1 */ + &sensor_state, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetStateSensorReadings response Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + free(response_msg); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetStateSensorReadings response, rc = %d\n", rc); + free(response_msg); + return OPAL_HARDWARE; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_platform_get_state_sensor_readings = { + .name = "PLDM_GET_STATE_SENSOR_READINGS", + .pldm_cmd_id = PLDM_GET_STATE_SENSOR_READINGS, + .handler = platform_get_state_sensor_readings, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; From patchwork Tue Sep 13 10:27:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677236 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=SXlapiSi; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfqC5qjDz1ynm for ; Tue, 13 Sep 2022 20:29:59 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqC5KLkz3cDb for ; Tue, 13 Sep 2022 20:29:59 +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=SXlapiSi; 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=SXlapiSi; 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 4MRfmN343bz3bVB for ; Tue, 13 Sep 2022 20:27:32 +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 28D9p6Lq002793 for ; Tue, 13 Sep 2022 10:27:30 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=dyEaSwr2QgJc5r086tt1zXjST1KiTCxs1lBxMKoKksc=; b=SXlapiSi030ny85QVpiypO9lwAvKi3w2ugh10L7D4ibdWj2hWZ5hha+91HXPMach4Y3Q VFYmLlGE1dqsJ995qbb9p3ezJTLUJXJk52jrUVtv1Sk33DUMa8Oh04eYOQNNTpm4Ddzu DWMQUhuQFADnza9aV1LvpeRuBDIpdE/g/0iZk5HqVo0JJIFeIShtQuZII1boimWeyd0r YIr02vPytPzpU1lTdArC90Ix8hd0emNG9wfgUk6Y+AIPqJIiDrVpJk+dZUUfTa0D8wx+ ptxhhQEzQD1eynBBrcx3CUlXkT0v2cCtLxNdr1+pmz7Izi8oRx0ip+ZhkHvi5G65Te+X UA== Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmjay1p7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKrx9001416 for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma05fra.de.ibm.com with ESMTP id 3jgj78tpt2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:28 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARPpE36700420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:25 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B5AD311C050 for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E8F711C04A for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:14 +0200 Message-Id: <20220913102724.65563-6-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: GcStyGSiNRyK8rYgX0R7wG1zc5FibDtO X-Proofpoint-ORIG-GUID: GcStyGSiNRyK8rYgX0R7wG1zc5FibDtO 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 V3 05/15] core/pldm: Decode the SetStateEffecterStates request 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" The SetStateEffecterStates command is used to set the state of one or more effecters within a PLDM State Effecter. The field comp_effecter_count indicates the number of individual sets of state effecter information that are accessed by this command. The Event Receiver acknowledges receiving the PLDM Event Message in the response to this command. Signed-off-by: Christophe Lombard --- core/pldm/pldm-responder.c | 130 +++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 0224ea75..bbfd167d 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include #include #include "pldm.h" @@ -660,6 +662,132 @@ static struct pldm_cmd pldm_platform_get_state_sensor_readings = { .handler = platform_get_state_sensor_readings, }; +#define SOFT_OFF 0x00 +#define SOFT_REBOOT 0x01 +#define CHASSIS_PWR_DOWN 0x00 +#define DEFAULT_CHIP_ID 0 + +struct effecter_states_req { + uint16_t effecter_id; + uint8_t comp_effecter_count; + set_effecter_state_field field[8]; +}; + +/* + * SetStateEffecterStates (0x39) + * The SetStateEffecterStates command is used to set the state of one + * or more effecters within a PLDM State Effecter. + */ +static int platform_set_state_effecter_states_handler(const struct pldm_rx_data *req) +{ + struct effecter_states_req states_req; + set_effecter_state_field *field; + int rc, i; + + /* decode SetStateEffecterStates request data */ + rc = decode_set_state_effecter_states_req( + req->msg, + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES, + &states_req.effecter_id, + &states_req.comp_effecter_count, + states_req.field); + if (rc) { + prlog(PR_ERR, "Failed to decode SetStateEffecterStates request, rc = %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + /* invoke the appropriate callback handler */ + prlog(PR_DEBUG, "%s - effecter_id: %d, comp_effecter_count: %d\n", + __func__, + states_req.effecter_id, + states_req.comp_effecter_count); + + for (i = 0; i < states_req.comp_effecter_count; i++) { + field = states_req.field; + + /* other set_request not supported */ + if (field->set_request != PLDM_REQUEST_SET) { + prlog(PR_ERR, "Got invalid set request 0x%x in " + "SetStateEffecterStates request\n", + field->set_request); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + PLDM_PLATFORM_INVALID_STATE_VALUE); + return OPAL_PARAMETER; + } + + switch (field->effecter_state) { + case PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED: + case PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL: + prlog(PR_NOTICE, "Soft shutdown requested\n"); + cc_resp(req, PLDM_PLATFORM, + PLDM_SET_STATE_EFFECTER_STATES, + PLDM_SUCCESS); + + if (opal_booting() && platform.cec_power_down) { + prlog(PR_NOTICE, "Host not up, shutting down now\n"); + platform.cec_power_down(CHASSIS_PWR_DOWN); + } else { + opal_queue_msg(OPAL_MSG_SHUTDOWN, + NULL, NULL, + cpu_to_be64(SOFT_OFF)); + } + + break; + + case PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED: + prlog(PR_NOTICE, "Soft reboot requested\n"); + cc_resp(req, PLDM_PLATFORM, + PLDM_SET_STATE_EFFECTER_STATES, + PLDM_SUCCESS); + + if (opal_booting() && platform.cec_reboot) { + prlog(PR_NOTICE, "Host not up, rebooting now\n"); + platform.cec_reboot(); + } else { + opal_queue_msg(OPAL_MSG_SHUTDOWN, + NULL, NULL, + cpu_to_be64(SOFT_REBOOT)); + } + + break; + + case PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET: + case PLDM_STATE_SET_BOOT_RESTART_CAUSE_HARD_RESET: + prlog(PR_NOTICE, "OCC reset requested\n"); + cc_resp(req, PLDM_PLATFORM, + PLDM_SET_STATE_EFFECTER_STATES, + PLDM_SUCCESS); + + /* invoke the appropriate callback handler */ + prd_occ_reset(DEFAULT_CHIP_ID); /* FIXME, others chip ? */ + break; + + default: + prlog(PR_ERR, "Got invalid effecter state 0x%x in " + "SetStateEffecterStates request\n", + field->effecter_state); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + PLDM_PLATFORM_INVALID_STATE_VALUE); + return OPAL_PARAMETER; + } + + /* next */ + field++; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_platform_set_state_effecter_states = { + .name = "PLDM_SET_STATE_EFFECTER_STATES", + .pldm_cmd_id = PLDM_SET_STATE_EFFECTER_STATES, + .handler = platform_set_state_effecter_states_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -704,6 +832,8 @@ int pldm_responder_init(void) add_type(&pldm_platform_type); add_cmd(&pldm_platform_type, &pldm_platform_set_event_receiver); add_cmd(&pldm_platform_type, &pldm_platform_event_message); + add_cmd(&pldm_platform_type, &pldm_platform_get_state_sensor_readings); + add_cmd(&pldm_platform_type, &pldm_platform_set_state_effecter_states); return OPAL_SUCCESS; } From patchwork Tue Sep 13 10:27:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677239 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=ZpzLzDuw; 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 4MRfqb2cHRz1ync for ; Tue, 13 Sep 2022 20:30:19 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqb27F5z3cdB for ; Tue, 13 Sep 2022 20:30:19 +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=ZpzLzDuw; 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=ZpzLzDuw; 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 4MRfmP0gkyz3c5v for ; Tue, 13 Sep 2022 20:27:32 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9g4bC010025 for ; Tue, 13 Sep 2022 10:27:30 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=XiZmunGnGgNXRAb0r357v5t/oK8X9iI2E7He7GJxONw=; b=ZpzLzDuwdoqVfN+NeRUafXXIdj8hOosTH6EeZtLnwbLLhUW+lWqdN+jbgbop4f81VfYM VXo8dOAknwfqp3h+AIOJB9Lg3FdfINnqj7iLif76g5dk/RDW1rzrsbAY6wDS447ff8ad YsDMpIfaQ/+ZEIDIhLcn32yueM2lm8ZempcIbt8K4WoGcNzq3ik7wjkNy3EdI3HCyiRa iHvVeRdOBe4a+W+3nFW6ZpzzxqlqF5PR/OqvFsh3XUKMVwaPygVmSJOM2TU0b/76KFAj gDivvdkUgAjW8Wpr4WKbw83213ZoT+kw81T/V8DxgiUv6r8Zlfvf2xYobQHqkAnHP8Ym rQ== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqf2hj20-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAJk9f022809 for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 3jgj78tptc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:28 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARQqN36700422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:26 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F034111C050 for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C8F7F11C04A for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:15 +0200 Message-Id: <20220913102724.65563-7-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PpMeS0jEcnKq5OFtQBHs56k_oj_3SkXX X-Proofpoint-GUID: PpMeS0jEcnKq5OFtQBHs56k_oj_3SkXX 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 impostorscore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 06/15] core/pldm: Find PDR record by record handle 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" Add a wrapper for the libpldm api: pldm_pdr_find_record() Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-platform-requests.c | 22 ++++++++++++++++++++++ core/pldm/pldm.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index e7c54e65..f355d9aa 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -39,6 +39,28 @@ static void pdr_init_complete(bool success) pdr_ready = true; } +/* + * Find PDR record by record handle. + */ +int pldm_platform_pdr_find_record(uint32_t record_handle, + uint8_t **pdr_data, + uint32_t *pdr_data_size, + uint32_t *next_record_handle) +{ + const pldm_pdr_record *pdr_record; + + pdr_record = pldm_pdr_find_record(pdrs_repo, + record_handle, + pdr_data, + pdr_data_size, + next_record_handle); + + if (!pdr_record) + return OPAL_PARAMETER; + + return OPAL_SUCCESS; +} + /* * Search the matching record and return the effecter id. * PDR type = PLDM_STATE_EFFECTER_PDR diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 688b767c..88ba4892 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -73,6 +73,10 @@ int pldm_platform_reload_pdrs(void); int pldm_platform_init(void); void pldm_platform_exit(void); +int pldm_platform_pdr_find_record(uint32_t record_handle, + uint8_t **pdr_data, + uint32_t *pdr_data_size, + uint32_t *next_record_handle); int pldm_requester_handle_response(struct pldm_rx_data *rx); int pldm_requester_queue(void *request_msg, size_t request_len, void (*complete)(struct pldm_rx_data *rx, void *data), From patchwork Tue Sep 13 10:27:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677237 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=RWYyi3N0; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfqK6KgHz1yhR for ; Tue, 13 Sep 2022 20:30:05 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqK5Xgxz3cK6 for ; Tue, 13 Sep 2022 20:30:05 +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=RWYyi3N0; 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=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=RWYyi3N0; dkim-atps=neutral Received: from mx0a-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 4MRfmN5LMWz3bk0 for ; Tue, 13 Sep 2022 20:27:32 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAFdG9027313 for ; Tue, 13 Sep 2022 10:27:30 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=0zePSMATeUg6vQy2Xd2ONyi7U5IboI2VrSQyvknlErY=; b=RWYyi3N0znWAnhWdtDUrN6ze+TrIh+D7MCAkVgArrZx6lKSCQVERfeIvhVxlEZmYm1c2 WtYC5LfjRz64Fd2kbsKOzj8TRdVrpoUFcBclxz0fY0He99ofB6ruo5xGS+oxtRBSP1j0 S9+nlLS4PQfnnsL970Zp8j0VgRTaUZQcotUHWtiIxrvNzwWmjN4KENy72hgjywHr9vfh t7QDzy6Fe3xiBGVLFeQcWEPWomc1t3/OuVF5SvZkow8NwzrHUWsgDcVMnA6ct7gAr68q xc4Qzsav0g6JJBx0U3ZLzWIA4FcHErTlsMqlxBjLYkDlGBOhr6MhOOdEljbVFqu3vWKv 9g== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmxtqvvy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKiil029952 for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma01fra.de.ibm.com with ESMTP id 3jgj78tp3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:28 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARQ2436700424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:26 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B0CE11C050 for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12F2411C04A for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:25 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:16 +0200 Message-Id: <20220913102724.65563-8-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: q3qGCZJwPbQjmIcwcxll0uyCKVQQ9Grb X-Proofpoint-ORIG-GUID: q3qGCZJwPbQjmIcwcxll0uyCKVQQ9Grb 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 bulkscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 07/15] core/pldm: Encode PLDM PDR Repository Change eventData 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" Encode the platform PDR repository change event message request that tells the BMC that a specific PDR entry has changed. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-platform-requests.c | 119 +++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index f355d9aa..280cc238 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -244,6 +244,125 @@ int pldm_platform_restart(void) return set_state_effecter_states_req(effecter_id, &field, true); } +static int send_repository_changed_event(uint32_t num_changed_pdrs, + uint32_t *record_handle) +{ + size_t actual_change_records_size = 0; + uint8_t number_of_change_entries[1]; + size_t max_change_records_size = 0; + size_t response_len, payload_len; + uint8_t event_data_operation[1]; + uint32_t *change_entries[1]; + uint8_t *event_data = NULL; + uint32_t request_length; + void *response_msg; + char *request_msg; + int rc, i; + + struct pldm_platform_event_message_req event_message_req = { + .format_version = PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, + .tid = HOST_TID, + .event_class = PLDM_PDR_REPOSITORY_CHG_EVENT, + }; + + struct pldm_platform_event_message_resp response; + + prlog(PR_DEBUG, "%s - num_changed_pdrs: %d\n", __func__, num_changed_pdrs); + + if (num_changed_pdrs == 0) + return OPAL_PARAMETER; + + /* encode the platform change event data */ + event_data_operation[0] = PLDM_RECORDS_ADDED; + number_of_change_entries[0] = num_changed_pdrs; + change_entries[0] = record_handle; + + /* + * The first time around this loop, event_data is nullptr which + * instructs the encoder to not actually do the encoding, but + * rather fill out actual_change_records_size with the correct + * size, stop and return PLDM_SUCCESS. Then we allocate the + * proper amount of memory and call the encoder again, which + * will cause it to actually encode the message. + */ + for (i = 0; i < 2; i++) { + rc = encode_pldm_pdr_repository_chg_event_data( + FORMAT_IS_PDR_HANDLES, + 1, /* only one change record (RECORDS_ADDED) */ + event_data_operation, + number_of_change_entries, + (const uint32_t * const*)change_entries, + (struct pldm_pdr_repository_chg_event_data *)event_data, + &actual_change_records_size, + max_change_records_size); + if (rc) { + prlog(PR_ERR, "Encode PldmPdrRepositoryChgEventData Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + if (event_data == NULL) { + max_change_records_size = actual_change_records_size; + event_data = zalloc(max_change_records_size); + } + } + + /* Send the event request */ + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + max_change_records_size; + + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + max_change_records_size; + request_msg = zalloc(request_length); + + /* Encode the platform event message request */ + rc = encode_platform_event_message_req( + DEFAULT_INSTANCE_ID, + event_message_req.format_version, + event_message_req.tid, + event_message_req.event_class, + (const uint8_t *)event_data, + max_change_records_size, + (struct pldm_msg *)request_msg, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(event_data); + free(request_msg); + return OPAL_PARAMETER; + } + free(event_data); + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait( + request_msg, request_length - 1, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(request_msg); + return rc; + } + free(request_msg); + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_platform_event_message_resp( + response_msg, + payload_len, + &response.completion_code, + &response.platform_event_status); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode PlatformEventMessage Error, rc: %d, cc: %d, pes: %d\n", + rc, response.completion_code, + response.platform_event_status); + free(response_msg); + return OPAL_PARAMETER; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + struct get_pdr_response { uint8_t completion_code; uint32_t next_record_hndl; From patchwork Tue Sep 13 10:27:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677240 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=ZM4yK9uR; 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 4MRfqk12Zlz1ync for ; Tue, 13 Sep 2022 20:30:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqk0XCfz3cd8 for ; Tue, 13 Sep 2022 20:30:26 +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=ZM4yK9uR; 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=ZM4yK9uR; 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 4MRfmP1WB0z3c3B for ; Tue, 13 Sep 2022 20:27:33 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAPKeU001362 for ; Tue, 13 Sep 2022 10:27:31 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=z4ko+c2HhTuvajfpIBy7eF2VQOk8gVrhfY1p7YxvYd0=; b=ZM4yK9uRClCXb6UQ6ZymnVgCYfcSqg3aKezz8luQBbqEs5beZWYTBTj/pD3Z+3JTCnXS Unu/tuR8kUGPCQjCp3OfW0ogvZfBsVNHYGhrP3CFJ15rzfzzoJa+pLu7y+TN4Qd6tvIm gZEJGq3MQjHOEb7ogx+xeYDRQdG6xhFUZcDgwt/7h+HZJH2qGjd1aEbAjtAcq0RvzYB+ LHm+tyeqLDxAuTEXPQI3SDnX6xjg0Qwdpw4Q6upGvxcKDJvbc50Ugv8UksMW/KKUY9MH l73WA2bABuNi9KYo/oEz9UA6+tpwRX/3kjQNNjTvkDEJuhlRtWVGfOaeOf4L3q8EOpCk bQ== 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 3jjr3j81dq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:31 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKbVI005702 for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:28 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARQHk36700426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:26 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8028911C050 for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F57211C052 for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:17 +0200 Message-Id: <20220913102724.65563-9-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: tOIJY_vcdj__STBAXGBr50h3jKR-1FLM X-Proofpoint-ORIG-GUID: tOIJY_vcdj__STBAXGBr50h3jKR-1FLM 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 priorityscore=1501 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 08/15] core/pldm: Update or create terminus locator in the given repo 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" The Terminus Locator PDR forms the association between a TID and PLDM Terminus Handle for a terminus. This patch allows to add terminus locator record in the repository. If a record matches with the Host TID, we activate the current terminus locator record, otherwise a new record is created. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-platform-requests.c | 180 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 15 +++ 2 files changed, 195 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 280cc238..0cc4ddd5 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -15,6 +15,8 @@ #include "pldm.h" #define NO_MORE_PDR_HANDLES 0 +#define PDR_AUTO_CALCULATE_RECORD_HANDLE 0 +static bool PDR_IS_NOT_REMOTE; static pldm_pdr *pdrs_repo; static bool pdr_ready; @@ -25,6 +27,10 @@ struct pldm_pdrs { int rc; }; +static uint32_t records_handle[20]; +static uint8_t hosted_pdrs; +static int state_sensor_id = 1; + static void pdr_init_complete(bool success) { /* Read not successful, error out and free the buffer */ @@ -244,6 +250,145 @@ int pldm_platform_restart(void) return set_state_effecter_states_req(effecter_id, &field, true); } +static int add_states_sensor_pdr(pldm_pdr *repo, + uint32_t *record_handle, + uint16_t state_set_id, + uint32_t states) +{ + + struct state_sensor_possible_states *possible_states; + struct pldm_state_sensor_pdr *pdr; + uint8_t DEFAULT_CONTAINER_ID = 0; + size_t state_size, pdr_size, actual_pdr_size = 0; + uint8_t *state_storage; + uint32_t swapped; + int rc; + + /* fill in possible states structure */ + state_size = sizeof(struct state_sensor_possible_states) + + sizeof(states) + - sizeof(bitfield8_t); + state_storage = zalloc(state_size); + + possible_states = (struct state_sensor_possible_states *) state_storage; + possible_states->state_set_id = state_set_id; + possible_states->possible_states_size = sizeof(states); + + /* need to swap the byte order for little endian order */ + swapped = htole32(states); + memcpy(possible_states->states, &swapped, sizeof(swapped)); + + pdr_size = sizeof(struct pldm_state_sensor_pdr) + state_size; + pdr = zalloc(pdr_size); + + /* header */ + pdr->hdr.record_handle = 0; /* ask libpldm to fill this out */ + pdr->hdr.version = 0; /* will be filled out by the encoder */ + pdr->hdr.type = 0; /* will be filled out by the encoder */ + pdr->hdr.record_change_num = 0; + pdr->hdr.length = 0; /* will be filled out by the encoder */ + + /* body */ + pdr->terminus_handle = HOST_TID; + pdr->sensor_id = state_sensor_id++; + pdr->entity_type = PLDM_ENTITY_SYS_BOARD; + pdr->entity_instance = 1; + pdr->container_id = DEFAULT_CONTAINER_ID; + pdr->sensor_init = PLDM_NO_INIT; + pdr->sensor_auxiliary_names_pdr = false; + pdr->composite_sensor_count = 1; + + rc = encode_state_sensor_pdr(pdr, pdr_size, + possible_states, + state_size, + &actual_pdr_size); + + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "%s - Failed to encode state sensor PDR, rc: %d\n", + __func__, rc); + free(state_storage); + free(pdr); + return rc; + } + + *record_handle = pldm_pdr_add(repo, + (const uint8_t *) pdr, actual_pdr_size, + PDR_AUTO_CALCULATE_RECORD_HANDLE, + PDR_IS_NOT_REMOTE); + + free(state_storage); + free(pdr); + + return OPAL_SUCCESS; +} + +/* + * Add boot progress record in the repository. + */ +static uint32_t add_boot_progress_pdr(pldm_pdr *repo, + uint32_t *record_handle) +{ + int rc; + + rc = add_states_sensor_pdr( + repo, + record_handle, + PLDM_STATE_SET_BOOT_PROGRESS, + enum_bit(PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED) | + enum_bit(PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG) | + enum_bit(PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS)); + if (rc) { + prlog(PR_ERR, "%s - Failed to add states sensor PDR, rc: %d\n", + __func__, rc); + return rc; + } + + prlog(PR_DEBUG, "Add boot progress pdr (record handle: %d)\n", + *record_handle); + + return OPAL_SUCCESS; +} + +/* + * Add terminus locator record in the repository. + */ +static int add_terminus_locator_pdr(pldm_pdr *repo, + uint32_t *record_handle) +{ + struct pldm_terminus_locator_type_mctp_eid *locator_value; + struct pldm_terminus_locator_pdr pdr; + uint8_t DEFAULT_CONTAINER_ID = 0; + uint32_t size; + + pdr.hdr.record_handle = 0; /* record_handle will be generated for us */ + pdr.hdr.version = 1; + pdr.hdr.type = PLDM_TERMINUS_LOCATOR_PDR; + pdr.hdr.record_change_num = 0; + pdr.hdr.length = htole16(sizeof(struct pldm_terminus_locator_pdr) - + sizeof(struct pldm_pdr_hdr)); + pdr.terminus_handle = htole16(HOST_TID); + pdr.validity = PLDM_TL_PDR_VALID; + pdr.tid = HOST_TID; + pdr.container_id = DEFAULT_CONTAINER_ID; + pdr.terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID; + pdr.terminus_locator_value_size = sizeof(struct pldm_terminus_locator_type_mctp_eid); + locator_value = (struct pldm_terminus_locator_type_mctp_eid *)pdr.terminus_locator_value; + locator_value->eid = HOST_EID; + + size = sizeof(struct pldm_terminus_locator_pdr) + + sizeof(struct pldm_terminus_locator_type_mctp_eid); + + *record_handle = pldm_pdr_add(repo, + (const uint8_t *)(&pdr), size, + PDR_AUTO_CALCULATE_RECORD_HANDLE, + PDR_IS_NOT_REMOTE); + + prlog(PR_DEBUG, "Add terminus locator pdr (record handle: %d)\n", + *record_handle); + + return OPAL_SUCCESS; +} + static int send_repository_changed_event(uint32_t num_changed_pdrs, uint32_t *record_handle) { @@ -363,6 +508,33 @@ static int send_repository_changed_event(uint32_t num_changed_pdrs, return OPAL_SUCCESS; } +static int add_hosted_pdrs(pldm_pdr *repo) +{ + uint32_t record_handle; + int rc = OPAL_SUCCESS; + + hosted_pdrs = 0; + + rc = add_boot_progress_pdr(repo, &record_handle); + if (!rc) { + records_handle[hosted_pdrs] = record_handle; + hosted_pdrs++; + } + + rc = add_terminus_locator_pdr(repo, &record_handle); + if (!rc) { + records_handle[hosted_pdrs] = record_handle; + hosted_pdrs++; + } + + /* tell BMC that these PDRs have changed */ + rc = send_repository_changed_event(hosted_pdrs, records_handle); + if (rc) + prlog(PR_ERR, "%s - Failed to update hosted PDRs\n", __func__); + + return rc; +} + struct get_pdr_response { uint8_t completion_code; uint32_t next_record_hndl; @@ -580,6 +752,14 @@ int pldm_platform_init(void) return rc; } + /* add hosted pdrs */ + rc = add_hosted_pdrs(pdrs_repo); + if (rc) { + pdr_init_complete(false); + prlog(PR_ERR, "%s - done, rc: %d\n", __func__, rc); + return rc; + } + pdr_init_complete(true); prlog(PR_DEBUG, "%s - done\n", __func__); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index 88ba4892..af8c8925 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -34,6 +34,21 @@ extern int watchdog_period_sec; /* For all of the encode functions just pass in a default ID (0x00) */ #define DEFAULT_INSTANCE_ID 0 +/* Return an integer with a bit set in the position corresponding to + * the given enumeration (starting from 0 = the least significant + * bit) and zeroes in the other positions. + * Used for libpldm enumeration constants. + * + * + * @example enum_bit(0) = 0x00000001 + * @example enum_bit(1) = 0x00000002 + * @example enum_bit(4) = 0x00000010 + */ +inline uint32_t enum_bit(unsigned int enumeration) +{ + return 1 << enumeration; +} + struct pldm_rx_data { struct pldm_header_info hdrinf; /* parsed message header */ From patchwork Tue Sep 13 10:27:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677243 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=bPlYht9X; 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 4MRfr66QxCz1ync for ; Tue, 13 Sep 2022 20:30:46 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfr66GQ7z301m for ; Tue, 13 Sep 2022 20:30:46 +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=bPlYht9X; 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=bPlYht9X; 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 4MRfmP5kmBz3bqY for ; Tue, 13 Sep 2022 20:27:33 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DAAJxQ040080 for ; Tue, 13 Sep 2022 10:27:31 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=caTaQW1mmHNzGQS/q1KaJPQMigEHeZ7qB/AgueMVdlw=; b=bPlYht9XCiLkMSBW7YY1EHgpquBwRrcdkQ9uglT0TxuqIfMqjQ9Qtoc85JiilIX6O/Qh wukpm8g2wr00xbfNDaQ976bN7rQOa0t5ApcZL/O/gUItIdQebKg9lJml2W2r1EUAShG2 BuI1LDR9Q+T44PxioEyVN00QEtaPhToej27eKHvPpoVxR2I34pTFpVIie2FU4/N4BlLz NIqp+VskcdjaxVCJuXm+buKCTrW4r+DHsRDJPNF4pCJlwX1WTOX5KyuAHjaYGmlkUhoF bQr8dtCaa6E9D09TnalWo4eYszeaUJwWuYp1funyvo2ApE24LTP2rm1qjS3NgPd8+FwG Sg== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqvh8en0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:31 +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 28DAKafA003206 for ; Tue, 13 Sep 2022 10:27:29 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3jgj79umyf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARQ2b25231688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:26 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C974511C054 for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 940E311C052 for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:18 +0200 Message-Id: <20220913102724.65563-10-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: MqXAGUi3e17ui4SAFRMJOIHGAQqngtB4 X-Proofpoint-ORIG-GUID: MqXAGUi3e17ui4SAFRMJOIHGAQqngtB4 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 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 09/15] core/pldm: Decode the GetPDR request 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" The GetPDR command is used to retrieve individual PDRs from a PDR repository. The record is identified by the PDR recordHandle value that is passed in the request. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-responder.c | 127 +++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index bbfd167d..8fbd57c3 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -788,6 +788,132 @@ static struct pldm_cmd pldm_platform_set_state_effecter_states = { .handler = platform_set_state_effecter_states_handler, }; +struct get_pdr_req { + uint32_t record_handle; + uint32_t data_transfer_handle; + uint8_t transfer_op_flag; + uint16_t request_count; + uint16_t record_change_number; +}; + +/* + * GetPDR (0x51) + * The GetPDR command is used to retrieve individual PDRs from a PDR + * Repository. The record is identified by the PDR recordHandle value + * that is passed in the request. + */ +static int platform_get_pdr_handle(const struct pldm_rx_data *req) +{ + size_t payload_len, response_length; + uint32_t next_record_handle; + struct get_pdr_req pdr_req; + uint8_t *pdr_data = NULL; + uint32_t pdr_data_size = 0; + char *response_msg; + int rc; + + payload_len = req->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_pdr_req(req->msg, + payload_len, + &pdr_req.record_handle, + &pdr_req.data_transfer_handle, + &pdr_req.transfer_op_flag, + &pdr_req.request_count, + &pdr_req.record_change_number); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPDR request, rc = %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + if (pdr_req.data_transfer_handle != 0) { + /* We don't support multipart transfers */ + prlog(PR_ERR, "Got invalid data transfer handle 0x%x in GetPDR request\n", + pdr_req.data_transfer_handle); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + PLDM_PLATFORM_INVALID_DATA_TRANSFER_HANDLE); + return OPAL_PARAMETER; + } + + if (pdr_req.transfer_op_flag != PLDM_GET_FIRSTPART) { + prlog(PR_ERR, "Got invalid transfer op flag 0x%x in GetPDR request\n", + pdr_req.transfer_op_flag); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + PLDM_PLATFORM_INVALID_TRANSFER_OPERATION_FLAG); + return OPAL_PARAMETER; + } + + if (pdr_req.record_change_number != 0) { + prlog(PR_ERR, "Got invalid record change number 0x%x in GetPDR request\n", + pdr_req.record_change_number); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + PLDM_PLATFORM_INVALID_RECORD_CHANGE_NUMBER); + return OPAL_PARAMETER; + } + + /* find PDR record by record handle */ + prlog(PR_INFO, "BMC requesting PDR handle %d\n", pdr_req.record_handle); + + rc = pldm_platform_pdr_find_record(pdr_req.record_handle, + &pdr_data, + &pdr_data_size, + &next_record_handle); + if (rc) { + prlog(PR_ERR, "Got invalid record handle 0x%x in GetPDR request\n", + pdr_req.record_handle); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, + PLDM_PLATFORM_INVALID_RECORD_HANDLE); + return OPAL_PARAMETER; + } + + response_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_pdr_resp) + + pdr_data_size; + response_msg = zalloc(response_length); + memset(response_msg, 0, response_length); + + /* create a PLDM response message for GetPDR */ + rc = encode_get_pdr_resp(req->hdrinf.instance, + PLDM_SUCCESS, + next_record_handle, + 0, /* No remaining data */ + PLDM_START_AND_END, + pdr_data_size, + pdr_data, + 0, /* CRC not used for START_AND_END */ + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPDR Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + free(response_msg); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, response_length - 1); + if (rc) { + prlog(PR_ERR, "Failed to send GetPDR response, rc = %d\n", rc); + free(response_msg); + return OPAL_HARDWARE; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_platform_get_pdr = { + .name = "PLDM_GET_PDR", + .pldm_cmd_id = PLDM_GET_PDR, + .handler = platform_get_pdr_handle, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -834,6 +960,7 @@ int pldm_responder_init(void) add_cmd(&pldm_platform_type, &pldm_platform_event_message); add_cmd(&pldm_platform_type, &pldm_platform_get_state_sensor_readings); add_cmd(&pldm_platform_type, &pldm_platform_set_state_effecter_states); + add_cmd(&pldm_platform_type, &pldm_platform_get_pdr); return OPAL_SUCCESS; } From patchwork Tue Sep 13 10:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677241 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=D6fS8oQd; 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 4MRfqs2JP6z1ync for ; Tue, 13 Sep 2022 20:30:33 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqs1pJKz3cDb for ; Tue, 13 Sep 2022 20:30:33 +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=D6fS8oQd; 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=D6fS8oQd; 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 4MRfmP4KJFz3c1Q for ; Tue, 13 Sep 2022 20:27:33 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9Lgme011075 for ; Tue, 13 Sep 2022 10:27:31 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=tzZ5Uj2RgxGuRv5vOVKnJVtLY7yWkgyNksvsaKyKtAo=; b=D6fS8oQddw2eOieTJb5a36D+SXLxpYaG3vHa2sztX50ZBr7f7vDkv+3mTK3U9Jll38hs ARVeBvf4h+v1gIEPhy1aObJ0RcJF65I/ec7+KvjMKZ7+M3MtE4AS/VhShCUHNe0swWmi wlkTgoF7dlNrALMYRuyFdMBR4+lAfgQ0iq/WMi8aFREMTRWf8Ro/09mtEafqT0H6ibxS DBCQxE6yZ7htKRWXFOKCtEvz8Zj3RWK7HOPBPmIUIT7pk0SvzxByAntUPz8fYkbLSGQS hMmVeRDEnQTLSxI8CR///SkA5noIxMsZBo2RBIIG/+tFM2IcHZl7FaJ+NtNHwZmtcKSH Fw== 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 3jjq5rhxq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:31 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKZk5005691 for ; Tue, 13 Sep 2022 10:27:29 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARRnS25231694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:27 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 10E2F11C050 for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC39311C04A for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:26 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:19 +0200 Message-Id: <20220913102724.65563-11-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: AyH0qDSsOUe4I_k_rMop3nZ2G6aiDG76 X-Proofpoint-ORIG-GUID: AyH0qDSsOUe4I_k_rMop3nZ2G6aiDG76 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 mlxlogscore=999 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 10/15] core/pldm: Decode the GetFRURecordTableMetadata request 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" The GetFRURecordTableMetadata command is used to get the FRU Record Table metadata information that includes the FRU Record major version, the FRU Record minor version, the size of the largest FRU Record data, total length of the FRU Record Table, total number of FRU Record Data structures, and the integrity checksum on the FRU Record Table data. Add an "IBM, skiboot" FRU Record product requested by the BMC. Signed-off-by: Christophe Lombard --- core/pldm/pldm-fru-requests.c | 53 ++++++++++++++++++++++ core/pldm/pldm-responder.c | 85 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 3 ++ 3 files changed, 141 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index b07a7b1a..80a13ef1 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -14,6 +14,9 @@ static void *fru_record_table; static size_t fru_record_length; +static void *local_fru_record_table; +static size_t local_fru_table_length; + static bool fru_ready; static char *bmc_version = NULL; @@ -175,6 +178,56 @@ int pldm_fru_dt_add_bmc_version(void) return OPAL_SUCCESS; } +#define RECORD_SET_ID 100 + +void pldm_fru_add_record(uint32_t *table_length, + uint16_t *total_record_set_identifiers, + uint16_t *total_table_records) +{ + struct pldm_fru_record_data_format *record; + struct pldm_fru_record_tlv *fru_tlv; + size_t fru_table_size, record_size; + char fru_product[] = "IBM, skiboot"; + + if (local_fru_record_table) { + *table_length = local_fru_table_length; + *total_record_set_identifiers = 1; + *total_table_records = 1; + return; + } + + /* allocate fru table */ + fru_table_size = sizeof(struct pldm_fru_record_data_format) + + sizeof(struct pldm_fru_record_tlv) + + strlen(fru_product); + local_fru_record_table = zalloc(fru_table_size); + + /* fill fru record data */ + record = (struct pldm_fru_record_data_format *)local_fru_record_table; + record->record_set_id = htole16(RECORD_SET_ID); + record->record_type = PLDM_FRU_RECORD_TYPE_GENERAL; + record->num_fru_fields = 1; + record->encoding_type = PLDM_FRU_ENCODING_ASCII; + + /* to start, set the size as the start of the TLV structs */ + record_size = offsetof(struct pldm_fru_record_data_format, tlvs); + + /* TLVs data */ + fru_tlv = (struct pldm_fru_record_tlv *)(local_fru_record_table + record_size); + fru_tlv->type = PLDM_FRU_FIELD_TYPE_OTHER; + fru_tlv->length = strlen(fru_product); + memcpy(fru_tlv->value, fru_product, fru_tlv->length); + + /* increment record_size by total size of this TLV */ + record_size += (offsetof(struct pldm_fru_record_tlv, value) + fru_tlv->length); + + *table_length = record_size; + *total_record_set_identifiers = 1; + *total_table_records = 1; + + local_fru_table_length = *table_length; +} + int pldm_fru_init(void) { int rc; diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 8fbd57c3..cd2cbc1c 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -914,6 +915,86 @@ static struct pldm_cmd pldm_platform_get_pdr = { .handler = platform_get_pdr_handle, }; +/* + * PLDM Fru commands support + */ +static struct pldm_type pldm_fru_type = { + .name = "fru", + .pldm_type_id = PLDM_FRU, +}; + +/* currently we support version 1.0 of fru table */ +#define SUPPORTED_FRU_VERSION_MAJOR 1 +#define SUPPORTED_FRU_VERSION_MINOR 0 + +/* Used by the metadata request handler for the value of + * FRUTableMaximumSize + * 0 means SetFRURecordTable command is not supported (see DSP 0257 + * v1.0.0 Table 9) + */ +#define FRU_TABLE_MAX_SIZE_UNSUPPORTED 0 + +/* + * GetFRURecordTableMetadata (0X01) + * The GetFRURecordTableMetadata command is used to get the FRU Record + * Table metadata information that includes the FRU Record major + * version, the FRU Record minor version, the size of the largest FRU + * Record data, total length of the FRU Record Table, total number of + * FRU Record Data structures, and the integrity checksum on the FRU + * Record Table data. + */ +static int fru_get_record_table_metadata_handler(const struct pldm_rx_data *req) +{ + char response_msg[PKT_SIZE(struct pldm_get_fru_record_table_metadata_resp)]; + uint16_t total_record_set_identifiers, total_table_records; + uint32_t fru_table_length; + int rc; + + /* + * GetFRURecordTableMetadata requests + * don't have any payload, so no need to decode them + */ + + /* add specific fru record */ + pldm_fru_add_record(&fru_table_length, + &total_record_set_identifiers, + &total_table_records); + + /* create a PLDM response message for GetFRURecordTableMetadata */ + rc = encode_get_fru_record_table_metadata_resp( + req->hdrinf.instance, + PLDM_SUCCESS, + SUPPORTED_FRU_VERSION_MAJOR, + SUPPORTED_FRU_VERSION_MINOR, + FRU_TABLE_MAX_SIZE_UNSUPPORTED, + fru_table_length, + total_record_set_identifiers, + total_table_records, + 0, // checksum, not calculated + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFRURecordTableMetadata Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg)); + if (rc) { + prlog(PR_ERR, "Failed to send GetFRURecordTableMetadata response, rc = %d\n", rc); + return OPAL_HARDWARE; + } + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_fru_get_record_table_metadata = { + .name = "PLDM_GET_FRU_RECORD_TABLE_METADATA", + .pldm_cmd_id = PLDM_GET_FRU_RECORD_TABLE_METADATA, + .handler = fru_get_record_table_metadata_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -962,5 +1043,9 @@ int pldm_responder_init(void) add_cmd(&pldm_platform_type, &pldm_platform_set_state_effecter_states); add_cmd(&pldm_platform_type, &pldm_platform_get_pdr); + /* Register fru commands we'll respond to - DSP0257 */ + add_type(&pldm_fru_type); + add_cmd(&pldm_fru_type, &pldm_fru_get_record_table_metadata); + return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index af8c8925..fea06b0b 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -75,6 +75,9 @@ int pldm_file_io_write_file(uint32_t file_handle, const void *buf, int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv); +void pldm_fru_add_record(uint32_t *fru_table_length, + uint16_t *total_record_set_identifiers, + uint16_t *total_table_records); int pldm_fru_init(void); int pldm_bios_find_lid_by_attr_name(const char *name, char **lid); From patchwork Tue Sep 13 10:27:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677242 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=LxrWSrS8; 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 4MRfr002wjz1ync for ; Tue, 13 Sep 2022 20:30:40 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfqz6fQ0z3cCC for ; Tue, 13 Sep 2022 20:30: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=LxrWSrS8; 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=LxrWSrS8; 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 4MRfmP62gjz3c3V for ; Tue, 13 Sep 2022 20:27:33 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA7OVP008708 for ; Tue, 13 Sep 2022 10:27:32 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=56+jsd9NN/bGAgswxyMVxth9Llj9WCmJB/RcrdVY8gM=; b=LxrWSrS8G51b9GbUjZT+RrEiJZ2ajsCr1SAMkpJ38w9Rt/O0eMn0ftFQJRX+8+V3vAVH HlamyK00KsNDQHw7JPr9hp67FOzSjVccs6hWEvUkRsKH7Hf6ajLad70F8S8JEms3IC1T l90cFr4KVTd+Z7qhsyyz9xNe/PByM+7v6dni0wurev0eDIdPyxyuYxE009KMoMsVJ8Xw CCFk1FzrpcdpGS0YcorUJE9RqaWnA8WI/S0L5bul6yt8M+8VjSKkcA0m9sW7r/DyFmx9 4v03/69jrC9lZ2gOWdgfS4vuLWpUvW2x2DvwZ/Lvinv1EjJgOsXlIBoli3ZT9B6n/BkP YA== Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjqn90ue4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:31 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAK3n7016100 for ; Tue, 13 Sep 2022 10:27:29 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma02fra.de.ibm.com with ESMTP id 3jgj792pcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARRnt25231696 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:27 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E1FC11C050 for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2569B11C04A for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:20 +0200 Message-Id: <20220913102724.65563-12-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: il9ShrZokMLXkO36LqRgBZ6FKKar2S3u X-Proofpoint-GUID: il9ShrZokMLXkO36LqRgBZ6FKKar2S3u 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 priorityscore=1501 spamscore=0 mlxscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 11/15] core/pldm: Decode the GetFruRecordTable request 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" The GetFRURecordTable command is used to get the FRU Record Table data. This command is defined to allow the FRU Record Table data to be transferred using a sequence of one or more command/response messages. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/pldm-fru-requests.c | 12 ++++++ core/pldm/pldm-responder.c | 78 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 3 files changed, 92 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index 80a13ef1..c90f08b3 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -228,6 +228,18 @@ void pldm_fru_add_record(uint32_t *table_length, local_fru_table_length = *table_length; } +int pldm_fru_get_local_table(void **fru_record_table_bytes, + uint32_t *fru_record_table_size) +{ + if (!local_fru_record_table) + return OPAL_PARAMETER; + + *fru_record_table_bytes = local_fru_record_table; + *fru_record_table_size = local_fru_table_length; + + return OPAL_SUCCESS; +} + int pldm_fru_init(void) { int rc; diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index cd2cbc1c..2c5b3677 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -995,6 +995,83 @@ static struct pldm_cmd pldm_fru_get_record_table_metadata = { .handler = fru_get_record_table_metadata_handler, }; +/* + * GetFRURecordTable (0X02) + * The GetFRURecordTable command is used to get the FRU Record Table + * data. This command is defined to allow the FRU Record Table data to + * be transferred using a sequence of one or more command/response + * messages. + */ +static int fru_get_record_table_handler(const struct pldm_rx_data *req) +{ + struct pldm_get_fru_record_table_resp *resp; + void *fru_record_table_bytes; + uint32_t fru_record_table_size; + size_t response_length; + struct pldm_msg *msg; + char *response_msg; + int rc; + + /* The getFruRecordTable requests do have request data, but it's + * only related to multi-part transfers which we don't support + * and which the BMC will not send us. + */ + + /* get local fru record table */ + rc = pldm_fru_get_local_table(&fru_record_table_bytes, &fru_record_table_size); + if (rc) { + prlog(PR_ERR, "Failed to get Fru Record Table\n"); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* create a PLDM response message for GetFRURecordTable */ + response_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_fru_record_table_resp) + + fru_record_table_size; + response_msg = zalloc(response_length); + memset(response_msg, 0, response_length); + + rc = encode_get_fru_record_table_resp( + req->hdrinf.instance, + PLDM_SUCCESS, + 0, // No next transfer handle + PLDM_START_AND_END, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordTable Error, rc: %d\n", rc); + cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + free(response_msg); + return OPAL_PARAMETER; + } + + msg = (struct pldm_msg *)response_msg; + resp = (struct pldm_get_fru_record_table_resp *)(msg->payload); + memcpy(resp->fru_record_table_data, + fru_record_table_bytes, + fru_record_table_size); + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(req->source_eid, response_msg, response_length - 1); + if (rc) { + prlog(PR_ERR, "Failed to send GetFruRecordTable response, rc = %d\n", rc); + free(response_msg); + return OPAL_HARDWARE; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_fru_get_record_table = { + .name = "PLDM_GET_FRU_RECORD_TABLE", + .pldm_cmd_id = PLDM_GET_FRU_RECORD_TABLE, + .handler = fru_get_record_table_handler, +}; + int pldm_responder_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *type; @@ -1046,6 +1123,7 @@ int pldm_responder_init(void) /* Register fru commands we'll respond to - DSP0257 */ add_type(&pldm_fru_type); add_cmd(&pldm_fru_type, &pldm_fru_get_record_table_metadata); + add_cmd(&pldm_fru_type, &pldm_fru_get_record_table); return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index fea06b0b..dd6f2352 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -78,6 +78,8 @@ int pldm_fru_get_bmc_version(void *bv); void pldm_fru_add_record(uint32_t *fru_table_length, uint16_t *total_record_set_identifiers, uint16_t *total_table_records); +int pldm_fru_get_local_table(void **fru_record_table_bytes, + uint32_t *fru_record_table_size); int pldm_fru_init(void); int pldm_bios_find_lid_by_attr_name(const char *name, char **lid); From patchwork Tue Sep 13 10:27:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677245 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=rImPWyOu; 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 4MRfrN0ZS3z1ync for ; Tue, 13 Sep 2022 20:31:00 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrN0NHtz3cdm for ; Tue, 13 Sep 2022 20:31:00 +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=rImPWyOu; 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=rImPWyOu; 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 4MRfmQ2Qngz3c66 for ; Tue, 13 Sep 2022 20:27:34 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA9QSZ006764 for ; Tue, 13 Sep 2022 10:27:32 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=qLjAxDzTWn19BAraD1SMd1dFOYSxHILZVFDE7eMNxbw=; b=rImPWyOuuAuVFU0NF56Su71FpPUaFM9lJ2NPLyP7N5kOrD3Fpfcyww4s1GTwOFF3gYOe IFGZsppT7x8+njUnRedqSoGGU3dbhWe7lPsQY0s7/n79KWFt/DxOTNyFTn7J0uB30PfW ibO2DsyM058Ct3rvptKXoEqbW5m17JSRiltMGrq8Gvu/4a2mgKTLVoP+6oep2Rk5uH3S 4OwEO/ZourAY+DKwluuX/InCucGOXnbUsEmpzVxL1GoXYicyfRxeLz7pPNtFDzKQE+zw gugjGaaFKoUxbVOR8yZK9w+94Vl24Hv19zp99xcyVO2J5/Awgk83ocGoqBdFsESrTfsg Gw== 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 3jjq7a1sha-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:32 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKVKg005681 for ; Tue, 13 Sep 2022 10:27:30 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3jghujbnqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:29 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARR0i25231698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:27 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B9F711C052 for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6321C11C04A for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:21 +0200 Message-Id: <20220913102724.65563-13-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: zAisqhNhVBW5aYgZ1qr8fprPKh6Ynsyf X-Proofpoint-GUID: zAisqhNhVBW5aYgZ1qr8fprPKh6Ynsyf 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 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 12/15] core/pldm: Update boot progress state 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 Event Messages are PLDM monitoring and control messages that are used by a PLDM terminus to synchronously or asynchronously report PLDM events to a central party called the PLDM Event Receiver. This patch allows to send a: - generic sensor events (events related to PLDM numeric and state sensors). - boot progress sensor event. Signed-off-by: Christophe Lombard --- core/pldm/pldm-platform-requests.c | 163 +++++++++++++++++++++++++++++ include/pldm.h | 7 ++ 2 files changed, 170 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 0cc4ddd5..10d0129f 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -250,6 +250,169 @@ int pldm_platform_restart(void) return set_state_effecter_states_req(effecter_id, &field, true); } +static int send_sensor_state_changed_event(uint16_t state_set_id, + uint16_t sensor_id, + uint8_t sensor_offset, + uint8_t sensor_state) +{ + size_t event_data_size = 0, actual_event_data_size; + size_t response_len, payload_len; + uint8_t *event_data = NULL; + uint32_t request_length; + void *response_msg; + char *request_msg; + int rc, i; + + struct pldm_platform_event_message_req event_message_req = { + .format_version = PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, + .tid = HOST_TID, + .event_class = PLDM_SENSOR_EVENT, + }; + + struct pldm_platform_event_message_resp response; + + prlog(PR_DEBUG, "%s - state_set_id: %d, sensor_id: %d, sensor_state: %d\n", + __func__, state_set_id, sensor_id, sensor_state); + + /* + * The first time around this loop, event_data is nullptr which + * instructs the encoder to not actually do the encoding, but + * rather fill out actual_change_records_size with the correct + * size, stop and return PLDM_SUCCESS. Then we allocate the + * proper amount of memory and call the encoder again, which + * will cause it to actually encode the message. + */ + for (i = 0; i < 2; i++) { + rc = encode_sensor_event_data( + (struct pldm_sensor_event_data *)event_data, + event_data_size, + sensor_id, + PLDM_STATE_SENSOR_STATE, + sensor_offset, + sensor_state, + sensor_state, + &actual_event_data_size); + if (rc) { + prlog(PR_ERR, "Encode PldmSensorChgEventData Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + if (event_data == NULL) { + event_data_size = actual_event_data_size; + event_data = zalloc(event_data_size); + } + } + + /* Send the event request */ + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_size; + + request_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + event_data_size; + request_msg = zalloc(request_length); + + /* Encode the platform event message request */ + rc = encode_platform_event_message_req( + DEFAULT_INSTANCE_ID, + event_message_req.format_version, + event_message_req.tid, + event_message_req.event_class, + (const uint8_t *)event_data, + event_data_size, + (struct pldm_msg *)request_msg, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(event_data); + free(request_msg); + return OPAL_PARAMETER; + } + free(event_data); + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait( + request_msg, request_length - 1, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(request_msg); + return rc; + } + free(request_msg); + + /* Decode the message */ + payload_len = response_len - sizeof(struct pldm_msg_hdr); + rc = decode_platform_event_message_resp( + response_msg, + payload_len, + &response.completion_code, + &response.platform_event_status); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode PlatformEventMessage Error, rc: %d, cc: %d, pes: %d\n", + rc, response.completion_code, + response.platform_event_status); + free(response_msg); + return OPAL_PARAMETER; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + +#define BOOT_STATE_SENSOR_INDEX 0 + +int pldm_platform_send_progress_state_change( + enum pldm_state_set_boot_progress_state_values state) +{ + struct state_sensor_possible_states *possible_states; + struct pldm_state_sensor_pdr *sensor_pdr = NULL; + const pldm_pdr_record *record = NULL; + uint16_t terminus_handle; + uint8_t *outData = NULL; + uint16_t sensor_id = 0; + uint32_t size; + + prlog(PR_INFO, "Setting boot progress, state: %d\n", state); + + do { + /* Find (first) PDR record by PLDM_STATE_SENSOR_PDR type + * if record not NULL, then search will begin from this + * record's next record + */ + record = pldm_pdr_find_record_by_type( + pdrs_repo, /* PDR repo handle */ + PLDM_STATE_SENSOR_PDR, + record, /* PDR record handle */ + &outData, &size); + + if (record) { + sensor_pdr = (struct pldm_state_sensor_pdr *) outData; + terminus_handle = le16_to_cpu(sensor_pdr->terminus_handle); + + if ((le16_to_cpu(sensor_pdr->entity_type) == PLDM_ENTITY_SYS_BOARD) && + (terminus_handle == HOST_TID)) { + possible_states = (struct state_sensor_possible_states *) + sensor_pdr->possible_states; + + if (le16_to_cpu(possible_states->state_set_id) == + PLDM_STATE_SET_BOOT_PROGRESS) + sensor_id = le16_to_cpu(sensor_pdr->sensor_id); + } + } + + } while (record); + + if (sensor_id == 0) + return OPAL_PARAMETER; + + return send_sensor_state_changed_event( + PLDM_STATE_SET_BOOT_PROGRESS, + sensor_id, + BOOT_STATE_SENSOR_INDEX, + state); +} + static int add_states_sensor_pdr(pldm_pdr *repo, uint32_t *record_handle, uint16_t state_set_id, diff --git a/include/pldm.h b/include/pldm.h index 231b517f..2100c12c 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -6,6 +6,7 @@ #define __PLDM_H__ #include +#include /** * PLDM over MCTP initialization @@ -47,4 +48,10 @@ bool pldm_lid_files_exit(struct blocklevel_device *bl); */ int pldm_watchdog_init(void); +/** + * Update boot progress state + */ +int pldm_platform_send_progress_state_change( + enum pldm_state_set_boot_progress_state_values state); + #endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:27:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677246 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=M6V/p3vL; 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 4MRfrV42kSz1ync for ; Tue, 13 Sep 2022 20:31:06 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrV3C2Hz3chX for ; Tue, 13 Sep 2022 20:31:06 +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=M6V/p3vL; 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=M6V/p3vL; 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 4MRfmQ2sXzz3c3B for ; Tue, 13 Sep 2022 20:27:34 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28D9LeBR010818 for ; Tue, 13 Sep 2022 10:27:32 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=qjlDzOFNshXMoZM8qInFRZJq0iyV7HORTMMGR1vEQBU=; b=M6V/p3vLSkXY6jUwM01PHeA8ecOznMhER7U5HSK7+fEQ0o9j7n4cOr7a/tZ+eMRnt9RM 4E1Uqej9deK5gdYjpyu2lDrU7FIpHobXwRuCw8pbfmUZQDzFeIBzS8V/WEFrnXq38QR6 wJHrqr9ob8zXysossNpGQ2JBtxCOhfrvuujOM0hUJq3HUgVs7hgmDMzTuCTGuL5VX+UC HjVmFKkRxBn1YLaCbeNU3STW0h0n9CgkFLzu8JEISIkA234M9jzLrNzPkd3KdEYROClZ TP4mNJVWCtA0x7NZweKSgRoWgwT7/kwdMRXF/2J8i5OIi8a90i7+qNUQWAhY4tV9yJQP YA== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq5rhxqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:32 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKa7C006761 for ; Tue, 13 Sep 2022 10:27:30 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3jgj79knd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARRZg35913994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DB82E11C052 for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AAE4C11C04A for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:22 +0200 Message-Id: <20220913102724.65563-14-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KfNGeNFRXONi9zM7WBZnWf34luFdZtg7 X-Proofpoint-ORIG-GUID: KfNGeNFRXONi9zM7WBZnWf34luFdZtg7 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 mlxlogscore=999 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 13/15] core/pldm: Register OPAL_RTC_READ/WRITE calls back 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" OPAL_RTC_READ/WRITE are used to retrieve and write the time. PLDM stack provides GetBiosDateTimeReq and SetBiosDateTimeReq commands to exercise. Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-rtc.c | 244 +++++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 + 3 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-rtc.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 5d10d572..00d6c458 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -16,7 +16,7 @@ PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o -PLDM_OBJS += pldm-watchdog.o +PLDM_OBJS += pldm-watchdog.o pldm-rtc.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-rtc.c b/core/pldm/pldm-rtc.c new file mode 100644 index 00000000..b6702a0b --- /dev/null +++ b/core/pldm/pldm-rtc.c @@ -0,0 +1,244 @@ +// 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 +#include +#include +#include "pldm.h" + +struct get_date_time_resp { + uint8_t completion_code; + uint8_t seconds; + uint8_t minutes; + uint8_t hours; + uint8_t day; + uint8_t month; + uint16_t year; +}; + +static enum {idle, waiting, updated, error} time_status; + +static void cache_get_datetime(struct tm *tm) +{ + if (tm == NULL) + time_status = error; + else { + rtc_cache_update(tm); + time_status = updated; + } +} + +static void get_date_time_req_complete(struct pldm_rx_data *rx, + void *data __unused) +{ + struct get_date_time_resp response; + size_t payload_len; + struct tm tm; + int rc; + + if (rx == NULL) { + prlog(PR_ERR, "%s: Response not received\n", __func__); + cache_get_datetime(NULL); + return; + } + + /* Decode the message */ + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_date_time_resp( + rx->msg, + payload_len, + &response.completion_code, + &response.seconds, + &response.minutes, + &response.hours, + &response.day, + &response.month, + &response.year); + if (rc != PLDM_SUCCESS || response.completion_code != PLDM_SUCCESS) { + prlog(PR_ERR, "Decode GetBiosDateTimeReq Error, rc: %d, cc: %d\n", + rc, response.completion_code); + cache_get_datetime(NULL); + return; + } + + /* The data arrives from BMC in BCD format. Convert it to + * decimal for processing + */ + tm.tm_sec = bcd2dec8(response.seconds); + tm.tm_min = bcd2dec8(response.minutes); + tm.tm_hour = bcd2dec8(response.hours); + tm.tm_mday = bcd2dec8(response.day); + tm.tm_mon = bcd2dec8(response.month); + tm.tm_year = bcd2dec16(response.year); + + if (!is_time_legal(tm.tm_sec, tm.tm_min, tm.tm_hour, + tm.tm_mday, tm.tm_mon, tm.tm_year)) { + prlog(PR_ERR, "%s: Invalid date time value\n", __func__); + cache_get_datetime(NULL); + return; + } + + cache_get_datetime(&tm); +} + +/* + * Send a PLDM GetBiosDateTime request message + */ +static int get_date_time_req(void) +{ + char request_msg[PKT_SIZE(0)]; /* the command doesn't have a message payload */ + int rc; + + /* Encode the date time request */ + rc = encode_get_date_time_req(DEFAULT_INSTANCE_ID, + (struct pldm_msg *)request_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetBiosDateTimeReq Error, rc: %d\n", rc); + return OPAL_PARAMETER; + } + + /* Queue and get the response message bytes */ + rc = pldm_requester_queue(request_msg, sizeof(request_msg), + get_date_time_req_complete, NULL); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetBiosDateTimeReq, rc: %d\n", rc); + return rc; + } + + return OPAL_SUCCESS; +} + +static int64_t pldm_opal_rtc_read(__be32 *__ymd, __be64 *__hmsm) +{ + uint32_t ymd; + uint64_t hmsm; + int rc = OPAL_SUCCESS; + + if (!__ymd || !__hmsm) + return OPAL_PARAMETER; + + switch (time_status) { + case idle: + rc = get_date_time_req(); + if (rc) + return OPAL_HARDWARE; + time_status = waiting; + rc = OPAL_BUSY_EVENT; + break; + + case waiting: + rc = OPAL_BUSY_EVENT; + break; + + case updated: + rtc_cache_get_datetime(&ymd, &hmsm); + *__ymd = cpu_to_be32(ymd); + *__hmsm = cpu_to_be64(hmsm); + time_status = idle; + rc = OPAL_SUCCESS; + break; + + case error: + time_status = idle; + rc = OPAL_HARDWARE; + break; + } + + return rc; +} + +/* + * Receive the PLDM SetBiosDateTime response + */ +static void set_date_time_req_complete(struct pldm_rx_data *rx, + void *data __unused) +{ + uint8_t completion_code; + size_t payload_len; + int rc; + + if (rx == NULL) { + prlog(PR_ERR, "%s: Response not received\n", __func__); + return; + } + + /* Decode the message */ + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + + rc = decode_set_date_time_resp(rx->msg, + payload_len, + &completion_code); + if (rc != PLDM_SUCCESS || (completion_code > PLDM_ERROR)) { + /* FIXME: Time value from OPAL_RTC_WRITE is never correct */ + prlog(PR_ERR, "Decode SetBiosDateTimeReq Error, rc: %d, cc: %d\n", + rc, completion_code); + } +} + +/* + * Send a PLDM SetBiosDateTime request message + */ +static int set_date_time_req(struct tm *tm) +{ + char request_msg[PKT_SIZE(struct pldm_set_date_time_req)]; + int rc; + + /* Encode the date time request */ + rc = encode_set_date_time_req( + DEFAULT_INSTANCE_ID, + tm->tm_sec, tm->tm_min, tm->tm_hour, + tm->tm_mday, tm->tm_mon, tm->tm_year, + (struct pldm_msg *)request_msg, + sizeof(struct pldm_set_date_time_req)); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode SetBiosDateTimeReq Error, rc: %d\n", + rc); + return OPAL_PARAMETER; + } + + /* Queue and get the response message bytes */ + rc = pldm_requester_queue(request_msg, sizeof(request_msg), + set_date_time_req_complete, NULL); + if (rc) { + prlog(PR_ERR, "Communication Error, req: SetBiosDateTimeReq, rc: %d\n", rc); + return rc; + } + + return OPAL_SUCCESS; +} + +static int64_t pldm_opal_rtc_write(uint32_t year_month_day, + uint64_t hour_minute_second_millisecond) +{ + struct tm tm; + int rc; + + datetime_to_tm(year_month_day, hour_minute_second_millisecond, &tm); + + rc = set_date_time_req(&tm); + if (rc == OPAL_BUSY) + return OPAL_BUSY_EVENT; + + return OPAL_SUCCESS; +} + +void pldm_rtc_init(void) +{ + struct dt_node *np = dt_new(opal_node, "rtc"); + + dt_add_property_strings(np, "compatible", "ibm,opal-rtc"); + + opal_register(OPAL_RTC_READ, pldm_opal_rtc_read, 2); + opal_register(OPAL_RTC_WRITE, pldm_opal_rtc_write, 2); + + /* Initialise the rtc cache */ + get_date_time_req(); +} diff --git a/include/pldm.h b/include/pldm.h index 2100c12c..db24040d 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -54,4 +54,9 @@ int pldm_watchdog_init(void); int pldm_platform_send_progress_state_change( enum pldm_state_set_boot_progress_state_values state); +/** + * Configure real-time clock + */ +void pldm_rtc_init(void); + #endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:27:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677247 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=N3ZWv+BJ; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfrd5L3Mz1ync for ; Tue, 13 Sep 2022 20:31:13 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrd4Vvyz3chq for ; Tue, 13 Sep 2022 20:31:13 +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=N3ZWv+BJ; 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=N3ZWv+BJ; 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 4MRfmR0y3yz3c2g for ; Tue, 13 Sep 2022 20:27:34 +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 28D9iGGb002970 for ; Tue, 13 Sep 2022 10:27:32 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=7MrZjlXxqTRr1C1YNp35qRBLRQ7UUWU9b1p0IZswNMg=; b=N3ZWv+BJbIlpo3w3gWUyWocHW81AL6bbpkvDBR2RhihsYL6BkG+R8hWd5QJz/sg2Ooer OlxAx21K0FArPCZr87lxmhbjK9YXWJG5/7NH3hgLNfZt/8jQ45E+Z3JBXLlaBtK61MeY Xk5hymK5OUb5WSjYzB2B6zKKm56TOmYMOliFYu1IE1pFfn9vv+HdRW4515XMs8r5liOv tja7X3hnCAhF6+Og9jVwvz/1xXpq5fcJefJP/gxujsmtIqCpXa7MGrbkRb1P12mNrtz1 PdMWAkKFC2YUmmx1VCW8POXJMHV2CKZ4CURsZwV0y9WfxIcX6GN9dEixwSIb8Kwq3S2s fQ== Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjmjay1qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:32 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKaR2029921 for ; Tue, 13 Sep 2022 10:27:30 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma01fra.de.ibm.com with ESMTP id 3jgj78tp3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARSYB35913996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 25A4311C050 for ; Tue, 13 Sep 2022 10:27:28 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF44611C04A for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:27 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:23 +0200 Message-Id: <20220913102724.65563-15-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pwXazfS5lqX5HaLytV_3VHNY6q0EwsAS X-Proofpoint-ORIG-GUID: pwXazfS5lqX5HaLytV_3VHNY6q0EwsAS 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 V3 14/15] core/pldm: Register OPAL_IPMI_SEND/RECV calls back 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" OPAL_IPMI_SEND/RECV are used to retrieve and write IPMI requests. This support is needed for Linux driver. Only IPMI_GET_DEVICE_ID_CMD and IPMI_GET_DEVICE_GUID_CMD commands are supported. Signed-off-by: Christophe Lombard Reviewed-by: Abhishek Singh Tomar --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-opal.c | 291 +++++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 + 3 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-opal.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 00d6c458..14dd833e 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -16,7 +16,7 @@ PLDM_OBJS = pldm-mctp.o pldm-responder.o pldm-requester.o PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o -PLDM_OBJS += pldm-watchdog.o pldm-rtc.o +PLDM_OBJS += pldm-watchdog.o pldm-rtc.o pldm-opal.o PLDM = $(PLDM_DIR)/built-in.a $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%) diff --git a/core/pldm/pldm-opal.c b/core/pldm/pldm-opal.c new file mode 100644 index 00000000..3169d9d0 --- /dev/null +++ b/core/pldm/pldm-opal.c @@ -0,0 +1,291 @@ +// 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 +#include +#include "pldm.h" + +/* + * Response data from IPMI Get device ID command (As defined in + * Section 20.1 Get Device ID Command - IPMI standard spec). + */ +struct ipmi_dev_id { + uint8_t dev_id; + uint8_t dev_revision; + uint8_t fw_rev1; + uint8_t fw_rev2; + uint8_t ipmi_ver; + uint8_t add_dev_support; + uint8_t manufactur_id[3]; + uint8_t product_id[2]; + uint8_t aux_fw_rev[4]; +}; + +static struct lock msgq_lock = LOCK_UNLOCKED; +static struct list_head msgq = LIST_HEAD_INIT(msgq); +uint64_t opal_event_ipmi_recv; + +static void opal_send_complete(struct ipmi_msg *msg) +{ + lock(&msgq_lock); + list_add_tail(&msgq, &msg->link); + opal_update_pending_evt(opal_event_ipmi_recv, + opal_event_ipmi_recv); + unlock(&msgq_lock); +} + +#define GUID_SIZE 16 + +static int opal_get_tid_req(struct opal_ipmi_msg *opal_ipmi_msg, + uint64_t msg_len __unused) +{ + struct ipmi_msg *opal_ipmi_response = NULL; + uint8_t guid[GUID_SIZE]; + int bmc_tid; + + opal_ipmi_response = zalloc(sizeof(struct ipmi_msg) + GUID_SIZE); + opal_ipmi_response->netfn = IPMI_NETFN_RETURN_CODE(opal_ipmi_msg->netfn); + opal_ipmi_response->cmd = opal_ipmi_msg->cmd; + + memset(&guid, 0, GUID_SIZE); + + /* First byte of guid contains bmc tid */ + bmc_tid = pldm_base_get_bmc_tid(); + if (bmc_tid == -1) { + opal_ipmi_response->resp_size = 0; + opal_ipmi_response->cc = IPMI_ERR_UNSPECIFIED; + goto out; + } + + guid[0] = (uint8_t)bmc_tid; + memcpy(opal_ipmi_response->data, guid, GUID_SIZE); + + opal_ipmi_response->resp_size = GUID_SIZE; + opal_ipmi_response->cc = IPMI_CC_NO_ERROR; + +out: + opal_send_complete(opal_ipmi_response); + return OPAL_SUCCESS; +} + +static int parse_bmc_version(uint8_t *bmc_version, + struct ipmi_dev_id *devid) +{ + uint8_t *ptr; + uint8_t temp; + + prlog(PR_TRACE, "%s - bmc version: %s len=%d\n", __func__, + bmc_version, (int)strlen(bmc_version)); + + /* + * parse bmc version string to find fw_rev1 and fw_rev2 + * Firmware Name is in format : + * fw1030.00-2.8-1030.2233.20220819a (NL1030_007) + * so fw_rev1 = 10 + * fw_rev2 = 20 + * aux_fw_rev = "007" + */ + ptr = strstr(bmc_version, "NL"); + if (ptr == NULL || strlen(ptr) < 8) + return OPAL_PARAMETER; + + ptr += 2; + /* + * Convert first two byte to + * fw_rev1 and net 2byte to fw_rev2 + */ + temp = ptr[2]; + ptr[2] = '\0'; + devid->fw_rev1 = (uint8_t)atoi(ptr); + ptr += 2; + ptr[0] = temp; + + temp = ptr[2]; + ptr[2] = '\0'; + devid->fw_rev2 = (uint8_t)atoi(ptr); + ptr += 2; + ptr[0] = temp; + + /* Aux version is truncated to 4 char only */ + if (*ptr == '_') + strncpy(devid->aux_fw_rev, ptr + 1, 3); + + prlog(PR_TRACE, "BMC Version major->%d minor->%d aux->%.4s\n", + devid->fw_rev1, devid->fw_rev2, devid->aux_fw_rev); + + return OPAL_SUCCESS; +} + +static int opal_get_bmc_info(struct opal_ipmi_msg *opal_ipmi_msg, + uint64_t msg_len __unused) +{ + struct ipmi_msg *opal_ipmi_response = NULL; + char bmc_version[100]; + struct ipmi_dev_id devid; + int rc; + + opal_ipmi_response = zalloc(sizeof(struct ipmi_msg) + + sizeof(struct ipmi_dev_id)); + opal_ipmi_response->resp_size = sizeof(struct ipmi_dev_id); + opal_ipmi_response->netfn = IPMI_NETFN_RETURN_CODE(opal_ipmi_msg->netfn); + opal_ipmi_response->cmd = opal_ipmi_msg->cmd; + opal_ipmi_response->cc = IPMI_CC_NO_ERROR; + + memset(&devid, 0, sizeof(devid)); + devid.ipmi_ver = OPAL_IPMI_MSG_FORMAT_VERSION_1; + + /* retrieve bmc version */ + rc = pldm_fru_get_bmc_version(bmc_version); + if (rc) { + opal_ipmi_response->resp_size = 0; + opal_ipmi_response->cc = IPMI_ERR_UNSPECIFIED; + goto out; + } + + /* parse the bmc version */ + rc = parse_bmc_version(bmc_version, &devid); + if (rc) { + prlog(PR_ERR, "%s: Failed to parse BMC version, bmc version: %s\n", + __func__, bmc_version); + opal_ipmi_response->resp_size = 0; + opal_ipmi_response->cc = IPMI_ERR_UNSPECIFIED; + goto out; + } + + memcpy(opal_ipmi_response->data, &devid, sizeof(devid)); + +out: + opal_send_complete(opal_ipmi_response); + return OPAL_SUCCESS; +} + +static int64_t opal_ipmi_send(uint64_t interface __unused, + struct opal_ipmi_msg *opal_ipmi_msg, + uint64_t msg_len) +{ + int16_t ipmi_code; + + if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) { + prerror("OPAL IPMI: Incorrect version\n"); + return OPAL_UNSUPPORTED; + } + + msg_len -= sizeof(struct opal_ipmi_msg); + if (msg_len > IPMI_MAX_REQ_SIZE) { + prerror("OPAL IPMI: Invalid request length\n"); + return OPAL_PARAMETER; + } + + ipmi_code = IPMI_CODE(opal_ipmi_msg->netfn >> 2, opal_ipmi_msg->cmd); + if ((ipmi_code == IPMI_CHASSIS_GET_SYS_BOOT_OPT_CMD) || + (opal_ipmi_msg->cmd == IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x1a)) || + (opal_ipmi_msg->cmd == IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x42))) { + prerror("OPAL IPMI: Command not supported\n"); + return OPAL_UNSUPPORTED; + } + + prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x len: 0x%02llx\n", + __func__, opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2, + msg_len); + + switch (opal_ipmi_msg->cmd) { + case IPMI_GET_DEVICE_ID_CMD: + return opal_get_bmc_info(opal_ipmi_msg, msg_len); + + case IPMI_GET_DEVICE_GUID_CMD: + return opal_get_tid_req(opal_ipmi_msg, msg_len); + } + + return OPAL_UNSUPPORTED; +} + +static int64_t opal_ipmi_recv(uint64_t interface, + struct opal_ipmi_msg *opal_ipmi_msg, + __be64 *msg_len) +{ + struct ipmi_msg *msg; + int64_t rc; + + lock(&msgq_lock); + msg = list_top(&msgq, struct ipmi_msg, link); + + if (!msg) { + rc = OPAL_EMPTY; + goto out_unlock; + } + + if (opal_ipmi_msg->version != OPAL_IPMI_MSG_FORMAT_VERSION_1) { + prerror("OPAL IPMI: Incorrect version\n"); + rc = OPAL_UNSUPPORTED; + goto out_del_msg; + } + + if (interface != IPMI_DEFAULT_INTERFACE) { + prerror("IPMI: Invalid interface 0x%llx in %s\n", interface, __func__); + rc = OPAL_PARAMETER; + goto out_del_msg; + } + + if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) { + rc = OPAL_RESOURCE; + goto out_del_msg; + } + + list_del(&msg->link); + if (list_empty(&msgq)) + opal_update_pending_evt(opal_event_ipmi_recv, 0); + unlock(&msgq_lock); + + opal_ipmi_msg->cmd = msg->cmd; + opal_ipmi_msg->netfn = msg->netfn; + opal_ipmi_msg->data[0] = msg->cc; + memcpy(&opal_ipmi_msg->data[1], msg->data, msg->resp_size); + + prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x resp_size: 0x%02x\n", + __func__, msg->cmd, msg->netfn >> 2, msg->resp_size); + + /* Add one as the completion code is returned in the message data */ + *msg_len = cpu_to_be64(msg->resp_size + sizeof(struct opal_ipmi_msg) + 1); + free(msg); + + return OPAL_SUCCESS; + +out_del_msg: + list_del(&msg->link); + if (list_empty(&msgq)) + opal_update_pending_evt(opal_event_ipmi_recv, 0); + free(msg); + +out_unlock: + unlock(&msgq_lock); + return rc; +} + +void pldm_opal_init(void) +{ + struct dt_node *opal_ipmi, *opal_event = NULL; + + opal_ipmi = dt_new(opal_node, "ipmi"); + dt_add_property_strings(opal_ipmi, "compatible", "ibm,opal-ipmi"); + dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id", + IPMI_DEFAULT_INTERFACE); + opal_event_ipmi_recv = opal_dynamic_event_alloc(); + dt_add_property_cells(opal_ipmi, "interrupts", + ilog2(opal_event_ipmi_recv)); + + opal_event = dt_find_by_name(opal_node, "event"); + if (opal_event) + dt_add_property_cells(opal_ipmi, "interrupt-parent", + opal_event->phandle); + + opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3); + opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3); +} diff --git a/include/pldm.h b/include/pldm.h index db24040d..cb9cee08 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -59,4 +59,9 @@ int pldm_platform_send_progress_state_change( */ void pldm_rtc_init(void); +/** + * Register ipmi host interface access callbacks + */ +void pldm_opal_init(void); + #endif /* __PLDM_H__ */ From patchwork Tue Sep 13 10:27:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1677248 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=DJoMXAph; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRfrm3yrqz1ync for ; Tue, 13 Sep 2022 20:31:20 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MRfrm3BCzz3dnw for ; Tue, 13 Sep 2022 20:31:20 +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=DJoMXAph; 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=DJoMXAph; 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 4MRfmR1jDcz3c2q for ; Tue, 13 Sep 2022 20:27:35 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28DA9C16005958 for ; Tue, 13 Sep 2022 10:27:33 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=hStFvdGnpq0or4R+0mREfwET+pzQVgpuLzngyuPUzWM=; b=DJoMXAphevDrMRvi59155rXDt4Qh2VD+gNfVItfy47eFHh3npgr8y6sB9vsjpNFqtE07 G49BFSZ2z4lFszGkfMoo5jUYNGNM8H1a5U0gQoAWfcISgFHdozbBCeU9Fq4Qs/uVxP6Y 5p50DZuwSG99Yw7v6535Zu2Z9M5N2AxuanATp9wFnIJsSTfuA8DqWm5pXpCDVJ4oDyHZ f/TBgbfiSVBjIJS5PBg8wEPGmUPSIA2WfSyRfIsjwpQBUDRe6EToQ/2f/wbCeM6m3DEb DpCYUliimTdBNwd9KfPBfYtI53SOS2WOj6X0c5cA5vyOgGmd4O0swOTfXjPqWZK3VDSE JA== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jjq7a1sj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:33 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28DAKbLf006778 for ; Tue, 13 Sep 2022 10:27:31 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3jgj79knd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Sep 2022 10:27:30 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28DARSCD35913998 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Sep 2022 10:27:28 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 606A211C050 for ; Tue, 13 Sep 2022 10:27:28 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38E1011C04A for ; Tue, 13 Sep 2022 10:27:28 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.ibm.com.com (unknown [9.171.35.136]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Sep 2022 10:27:28 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 13 Sep 2022 12:27:24 +0200 Message-Id: <20220913102724.65563-16-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> References: <20220913102724.65563-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: EcUvOXLcMKN2_FbzwWTH3nLowcXte9dE X-Proofpoint-GUID: EcUvOXLcMKN2_FbzwWTH3nLowcXte9dE 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 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209130045 Subject: [Skiboot] [PATCH V3 15/15] platforms/astbmc: Enable PLDM 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" Last BMC firmware is available with a complete PLDM support on Rainier system. This patch allows initially to: - Initialize the MCTP core. - Enable the mctp binding over LPC bus interface and new wrappers to send and receive PLDM messages over the mctp library. - Retrieve all needed PLDM data. - "Virtualize" the content of a BMC flash based on lid files. Then, others mandatory support (watchdog, opal rtc, opal ipmi) are enabled. Signed-off-by: Christophe Lombard --- core/init.c | 29 ++++++++++++++++++++++++++--- core/pldm/pldm-mctp.c | 11 +++++++++++ include/pldm.h | 2 ++ platforms/astbmc/astbmc.h | 4 ++++ platforms/astbmc/common.c | 35 +++++++++++++++++++++++++++++++++++ platforms/astbmc/pnor.c | 25 +++++++++++++++++++++++++ platforms/qemu/qemu.c | 6 ++++++ 7 files changed, 109 insertions(+), 3 deletions(-) diff --git a/core/init.c b/core/init.c index 005ecf31..e32e87a8 100644 --- a/core/init.c +++ b/core/init.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -562,8 +563,15 @@ void __noreturn load_and_boot_kernel(bool is_reboot) trustedboot_exit_boot_services(); +#ifdef CONFIG_PLDM + if (pldm_present()) + pldm_platform_send_progress_state_change( + PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS); + else + ipmi_set_fw_progress_sensor(IPMI_FW_OS_BOOT); +#else ipmi_set_fw_progress_sensor(IPMI_FW_OS_BOOT); - +#endif if (!is_reboot) { /* We wait for the nvram read to complete here so we can @@ -1410,10 +1418,25 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt) /* Setup ibm,firmware-versions if able */ if (platform.bmc) { flash_dt_add_fw_version(); - ipmi_dt_add_bmc_info(); +#ifdef CONFIG_PLDM + if (pldm_present()) + pldm_fru_dt_add_bmc_version(); + else + ipmi_dt_add_bmc_info(); +#else + ipmi_dt_add_bmc_info(); +#endif } - ipmi_set_fw_progress_sensor(IPMI_FW_PCI_INIT); +#ifdef CONFIG_PLDM + if (pldm_present()) + pldm_platform_send_progress_state_change( + PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG); + else + ipmi_set_fw_progress_sensor(IPMI_FW_PCI_INIT); +#else + ipmi_set_fw_progress_sensor(IPMI_FW_PCI_INIT); +#endif /* * These last few things must be done as late as possible diff --git a/core/pldm/pldm-mctp.c b/core/pldm/pldm-mctp.c index 1d1d1b37..972a23e5 100644 --- a/core/pldm/pldm-mctp.c +++ b/core/pldm/pldm-mctp.c @@ -10,6 +10,13 @@ #include #include "pldm.h" +bool pldm_enabled; + +bool pldm_present(void) +{ + return pldm_enabled; +} + /* * Print content of PLDM message in hex mode. * 15 bytes per line. @@ -139,6 +146,8 @@ int pldm_mctp_init(uint8_t mode) goto out; } + pldm_enabled = true; + /* Get PDRs data */ rc = pldm_platform_init(); if (rc) { @@ -172,6 +181,8 @@ out: void pldm_mctp_exit(void) { + pldm_enabled = false; + pldm_platform_exit(); ast_mctp_exit(); diff --git a/include/pldm.h b/include/pldm.h index cb9cee08..8aa14a4f 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -8,6 +8,8 @@ #include #include +bool pldm_present(void); + /** * PLDM over MCTP initialization */ diff --git a/platforms/astbmc/astbmc.h b/platforms/astbmc/astbmc.h index 00f22123..5d0509b8 100644 --- a/platforms/astbmc/astbmc.h +++ b/platforms/astbmc/astbmc.h @@ -96,6 +96,10 @@ extern const struct bmc_platform bmc_plat_ast2600_openbmc; extern void astbmc_early_init(void); extern int64_t astbmc_ipmi_reboot(void); extern int64_t astbmc_ipmi_power_down(uint64_t request); +#ifdef CONFIG_PLDM +extern int astbmc_pldm_init(uint8_t mode); +extern int pnor_pldm_init(void); +#endif extern void astbmc_init(void); extern void astbmc_ext_irq_serirq_cpld(unsigned int chip_id); extern int pnor_init(void); diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c index 83ef70ad..e360a7bd 100644 --- a/platforms/astbmc/common.c +++ b/platforms/astbmc/common.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,36 @@ static int astbmc_fru_init(void) return 0; } +#ifdef CONFIG_PLDM +int astbmc_pldm_init(uint8_t mode) +{ + int rc = OPAL_SUCCESS; + + /* PLDM over MCTP */ + rc = pldm_mctp_init(mode); + if (!rc) { + /* Initialize PNOR/NVRAM */ + rc = pnor_pldm_init(); + + if (!rc) { + pldm_watchdog_init(); + pldm_rtc_init(); + pldm_opal_init(); + } + } + + /* Initialize elog */ + elog_init(); + + /* Setup UART console for use by Linux via OPAL API */ + set_opal_console(&uart_opal_con); + + if (rc) + prlog(PR_WARNING, "Failed to configure PLDM\n"); + + return rc; +} +#endif void astbmc_init(void) { @@ -501,6 +532,10 @@ void astbmc_early_init(void) void astbmc_exit(void) { +#ifdef CONFIG_PLDM + if (pldm_present()) + return; +#endif ipmi_wdt_final_reset(); } diff --git a/platforms/astbmc/pnor.c b/platforms/astbmc/pnor.c index 64f2249d..853da467 100644 --- a/platforms/astbmc/pnor.c +++ b/platforms/astbmc/pnor.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,30 @@ static enum ast_flash_style ast_flash_get_fallback_style(void) return raw_mem; } +#ifdef CONFIG_PLDM +int pnor_pldm_init(void) +{ + struct blocklevel_device *bl = NULL; + int rc = 0; + + rc = pldm_lid_files_init(&bl); + if (rc) { + prerror("PLAT: Failed to init PNOR driver\n"); + goto fail; + } + + rc = flash_register(bl); + if (!rc) + return 0; + +fail: + if (bl) + pldm_lid_files_exit(bl); + + return rc; +} +#endif + int pnor_init(void) { struct spi_flash_ctrl *pnor_ctrl = NULL; diff --git a/platforms/qemu/qemu.c b/platforms/qemu/qemu.c index 96153e85..81c5e5e1 100644 --- a/platforms/qemu/qemu.c +++ b/platforms/qemu/qemu.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -80,7 +81,12 @@ static void qemu_init(void) if (!bt_device_present) { set_opal_console(&uart_opal_con); } else { +#ifdef CONFIG_PLDM + /* need to be checked according platform: P10, P11 ... */ + astbmc_pldm_init(MCTP_BINDING_ASTLPC_MODE); +#else astbmc_init(); +#endif } }