From patchwork Tue Aug 29 09:23:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=U7e6jqOK; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZht660SFz1yZs for ; Tue, 29 Aug 2023 19:27:58 +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=U7e6jqOK; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZht64mzLz3bxH for ; Tue, 29 Aug 2023 19:27:58 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=U7e6jqOK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnr3XY5z3bvB for ; Tue, 29 Aug 2023 19:24:16 +1000 (AEST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8l4Su028317 for ; Tue, 29 Aug 2023 09:24:14 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=3ZWw/12UJgO5rwA939TgB8KGxb5rlddcxlZJKT0ecdI=; b=U7e6jqOK3os8AEbI3QFQT22Rh55ofoek4L7wYlFdkBrZ3gLH7aQFEELxjU6x4v7o6jkQ AQHUFDOJBe6UFQw1P4nCfXEI08ztCfAuV+qx/JRCZDkY7YKxj5zzl1PO1zTRy5OmOTqV NZt7XgpMOtJrJF6D3wnuH97ceMDCvrpf2KHaxfbxPuMdFfiA5eSi+R4WvZnLw6fagid7 xL3vAAwZEiZjOPeiQTKkxPW6+FJ4hnm0J/iVkiDHl56ipi7ZwVd1YTPc9nqDCJWoY35Z fYJD3sSwZAtMvTkAD5zgSgGjwvvyxYgXbHabv3dWAPf8U/1v5UiYYZQTj5VodVQ8YiOL Dw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3srv501g7j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:14 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T7JLH1014349 for ; Tue, 29 Aug 2023 09:24:12 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqvqn2956-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:12 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OAZ810289728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:10 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C252220043 for ; Tue, 29 Aug 2023 09:24:10 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8910C20040 for ; Tue, 29 Aug 2023 09:24:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:55 +0200 Message-ID: <20230829092409.75899-2-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vRA4gL8prpqDJeDjKNPGUTQwyL38iDPm X-Proofpoint-GUID: vRA4gL8prpqDJeDjKNPGUTQwyL38iDPm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 1 + core/pldm/pldm-watchdog.c | 142 ++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 ++ 3 files changed, 148 insertions(+) create mode 100644 core/pldm/pldm-watchdog.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 87952dbfe..e3efcc2b1 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -11,6 +11,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 = $(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 000000000..5a36b3dad --- /dev/null +++ b/core/pldm/pldm-watchdog.c @@ -0,0 +1,142 @@ +// 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 uint8_t sequence_number; +struct timer watchdog_timer; + +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); + } +} + +static int pldm_watchdog_reset_timer(void) +{ + uint8_t heartbeat_elapsed_data[2]; + struct pldm_tx_data *tx; + size_t payload_len; + size_t data_size; + 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, + }; + + prlog(PR_TRACE, "%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. + */ + heartbeat_elapsed_data[1] = sequence_number++; + + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(heartbeat_elapsed_data); + + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + sizeof(heartbeat_elapsed_data); + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size - 1; + + /* 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 *)tx->data, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue(tx, watchdog_reset_timer_complete, NULL); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(tx); + return rc; + } + + free(tx); + return OPAL_SUCCESS; +} + +static void watchdog_poller(struct timer *t __unused, + void *data __unused, + uint64_t now __unused) +{ + /* Whether the watchdog timer is armed and Skiboot should be sending + * regular heartbeats. + */ + if (watchdog_armed) + pldm_watchdog_reset_timer(); + + schedule_timer(&watchdog_timer, secs_to_tb(watchdog_period_sec)); +} + +int pldm_watchdog_init(void) +{ + if (watchdog_armed) + pldm_watchdog_reset_timer(); + + init_timer(&watchdog_timer, watchdog_poller, NULL); + schedule_timer(&watchdog_timer, secs_to_tb(watchdog_period_sec)); + + return OPAL_SUCCESS; +} diff --git a/include/pldm.h b/include/pldm.h index 8622453be..80ee85c00 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -48,4 +48,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 Aug 29 09:23:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=KfmQi1BZ; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhsw6JvWz1yZs for ; Tue, 29 Aug 2023 19:27:48 +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=KfmQi1BZ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhsw5FKdz3c43 for ; Tue, 29 Aug 2023 19:27:48 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=KfmQi1BZ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnr1ymwz3bcS for ; Tue, 29 Aug 2023 19:24:16 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T884aM024019 for ; Tue, 29 Aug 2023 09:24:14 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=rT0eM3QyLsTIKTImXQ63pParwStZyOzzNf2Mfx9eeBU=; b=KfmQi1BZpzYdVqWaeci/az2fTPvtIAbluFVJ3kD1TeYUXBC5+m0EgMGS68vvsIePP/Ql PXPVek8JCsg0teUXnszprJ+ETeUn4YTESLc2sXiF64o0/BX7sNAchiuwyVP6WgsITRuT 1Z7ZglkiBrB3DIzUB8jrUIFlv7M68WprAyjkuli4NTZFr0aCeroeV3I+Skhx8QlSDWzJ Ahr6MibDTpDNjeegTrnCUiZ/aempEC0hoVdwjdFsA8oEO3kaP9bF36xbWLfqds2ej1zn M7MOEuV28SkKXn5YvHuosVo3boRjh3fapiscja3T5o6yhLMSIsmJozvdDk9/YF2OK83u wg== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr8q7xnge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:13 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9FVAD020514 for ; Tue, 29 Aug 2023 09:24:13 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqv3yafjs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:13 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OBSj10289730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:11 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 271D020043 for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E22B120040 for ; Tue, 29 Aug 2023 09:24:10 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:10 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:56 +0200 Message-ID: <20230829092409.75899-3-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: hBF97Q76UZGMxBsyoH9Q9hwMIUZKvLE2 X-Proofpoint-ORIG-GUID: hBF97Q76UZGMxBsyoH9Q9hwMIUZKvLE2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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/pldm-responder.c | 89 ++++++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 3 ++ 2 files changed, 92 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index a233ea3e9..656c38c0f 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" @@ -425,6 +427,89 @@ 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, +}; + +#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 *rx) +{ + uint8_t event_message_global_enable, transport_protocol_type; + uint8_t event_receiver_address_info, cc = PLDM_SUCCESS; + uint16_t heartbeat_timer; + int rc = OPAL_SUCCESS; + + /* decode SetEventReceiver request data */ + rc = decode_set_event_receiver_req( + rx->msg, + PLDM_SET_EVENT_RECEIVER_REQ_BYTES, + &event_message_global_enable, + &transport_protocol_type, + &event_receiver_address_info, + &heartbeat_timer); + if (rc) { + prlog(PR_ERR, "Failed to decode SetEventReceiver request, rc = %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->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: %d\n", + __func__, + event_message_global_enable, + transport_protocol_type, + event_receiver_address_info, + heartbeat_timer); + + if (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__, event_message_global_enable); + cc = PLDM_PLATFORM_ENABLE_METHOD_NOT_SUPPORTED; + } + + if (heartbeat_timer < MIN_WATCHDOG_TIMEOUT_SEC) { + prlog(PR_ERR, "%s - BMC requested watchdog timeout that's too small: %d\n", + __func__, heartbeat_timer); + cc = PLDM_PLATFORM_HEARTBEAT_FREQUENCY_TOO_HIGH; + } else { + /* set the internal watchdog period to what BMC indicated */ + watchdog_period_sec = heartbeat_timer; + } + + /* send the response to BMC */ + cc_resp(rx, 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; + + 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; @@ -465,5 +550,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 3127ee5e6..b0c756000 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -15,6 +15,9 @@ /* For all of the encode functions just pass in a default ID (0x00) */ #define DEFAULT_INSTANCE_ID 0 +extern bool watchdog_armed; +extern int watchdog_period_sec; + struct pldm_tx_data { /* Contains an message header and payload of an MCTP packet. * Size of data[] From patchwork Tue Aug 29 09:23:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=VNSTeCE1; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhvW0RC2z1yZs for ; Tue, 29 Aug 2023 19:29: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=VNSTeCE1; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhvV6WMtz3c4L for ; Tue, 29 Aug 2023 19:29:10 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=VNSTeCE1; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnv3QHZz30fk for ; Tue, 29 Aug 2023 19:24:19 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9DtTM004111 for ; Tue, 29 Aug 2023 09:24:17 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=FJMAXFZ1Uy9NxV8L8OPIwZQ5mRXtUSoz/5DH0ROQqg0=; b=VNSTeCE1oKrBj9ufKbBGyFXxNJ/LHfRCMSSCRu+yb5wnvpJBhgIHMlMoJYSvCM1TGBV+ 7qGhE7b1o7PPUjyd7NDP8ZMC18VwLDaee2jFPTd0Z/tFf/ZjQ7v2bu7YIap6tlQE4s70 WD8B2elqT0ItwY0OeOPvpqREVbOf7LgsAnoJmLHA7XikGyVEv1hM3/Z8UpKKHFdoBof8 PZJ0Y3R0BL6t0GH2pZa8x20ygJlQzma8e+wbtDRKRiqIy679UN8ogc7yfJ0+c5SZ6mQN V16pGDjokx2jb98tfokv2/vtOQwBIfGaEIE7B559CPDMVN6/B9a9fL90QnOJWIbxshaf fQ== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr87hqh1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9HkRO020543 for ; Tue, 29 Aug 2023 09:24:16 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqv3yafk8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OEig8651326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D0802004B for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4530A20040 for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:57 +0200 Message-ID: <20230829092409.75899-4-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: pmRTDn19mjC5rH4AsLxW0cMo6IG_Mg8J X-Proofpoint-GUID: pmRTDn19mjC5rH4AsLxW0cMo6IG_Mg8J X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 5 ++ core/pldm/pldm-responder.c | 118 ++++++++++++++++++++++++++++- core/pldm/pldm.h | 1 + 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index c506bd4fc..568ed2323 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -436,6 +436,11 @@ static int pldm_platform_load_pdrs(void) return encode_and_queue_get_pdr_req(pdrs); } +int pldm_platform_reload_pdrs(void) +{ + return pldm_platform_load_pdrs(); +} + static int pdrs_init(void) { int rc; diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 656c38c0f..19164a6b7 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "pldm.h" @@ -418,7 +419,9 @@ static int base_get_version_handler(const struct pldm_rx_data *rx) } free(tx); - return OPAL_SUCCESS; + + /* BMC has certainly rebooted, so reload the PDRs */ + return pldm_platform_reload_pdrs(); } static struct pldm_cmd pldm_base_get_version = { @@ -510,6 +513,118 @@ static struct pldm_cmd pldm_platform_set_event_receiver = { .handler = platform_set_event_receiver_handler, }; +/* + * 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 *rx) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_platform_event_message_resp); + struct pldm_bios_attribute_update_event_req *request; + uint8_t format_version, tid, event_class; + uint8_t *bios_attribute_handles; + uint8_t cc = PLDM_SUCCESS; + size_t event_data_offset; + struct pldm_tx_data *tx; + int rc, i; + + /* decode PlatformEventMessage request data */ + rc = decode_platform_event_message_req( + rx->msg, + sizeof(struct pldm_platform_event_message_req), + &format_version, + &tid, + &event_class, + &event_data_offset); + if (rc) { + prlog(PR_ERR, "Failed to decode PlatformEventMessage request, rc = %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + prlog(PR_DEBUG, "%s - format_version: %d, " + "tid: %d " + "event_class: %d " + "event_data: 0x%lx\n", + __func__, + format_version, tid, + event_class, event_data_offset); + + /* we don't support any other event than the PDR Repo Changed event */ + if ((event_class != PLDM_PDR_REPOSITORY_CHG_EVENT) && + (event_class != PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE)) { + prlog(PR_ERR, "%s - Invalid event class %d in platform event handler\n", + __func__, event_class); + cc = PLDM_ERROR; + } + + /* Encode the platform event request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_platform_event_message_resp( + rx->hdrinf.instance, + cc, + PLDM_EVENT_NO_LOGGING, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send PlatformEventMessage response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + /* invoke the appropriate callback handler */ + if (event_class == PLDM_PDR_REPOSITORY_CHG_EVENT) { + free(tx); + 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 (event_class == PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE) { + request = (struct pldm_bios_attribute_update_event_req *)rx->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); + } + } + + free(tx); + 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; @@ -553,6 +668,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 b0c756000..f4e1617ec 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -74,6 +74,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 Aug 29 09:23:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=hqRn/WnF; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhtH5Jzbz1yZs for ; Tue, 29 Aug 2023 19:28:07 +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=hqRn/WnF; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhtH4Ckdz3c5L for ; Tue, 29 Aug 2023 19:28:07 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=hqRn/WnF; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnr67NJz3bxH for ; Tue, 29 Aug 2023 19:24:16 +1000 (AEST) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8f7Lk019385 for ; Tue, 29 Aug 2023 09:24:14 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=RhcejcWDIc6vQJk3suI1oGNEmuIWdZ9tOV4opB1uQMM=; b=hqRn/WnF1IFOnPtwomf6k05aaqHe7u3EMEyN8j1EyfqwRZoDix8yylwEG9Gf+0BDJybx IuECdHpIlvdQNZ3Cr78Or0E95rSpV39ttYEDvfOwCwD4WwnNklwtTkUp6CcjwbuJ8fW8 pY0EMcQ+5DHSp1gDgcQQVOH90Z6YOdjQmgrXp9KBQtk3DFEY+8SBJF6aZMEulJ48FxR+ bc1Wzy7UlsHaEKiH+D0wiYs5UNGeoL3Ky5dZGb/tvbK3ryyo8nq+bW/jRtMiik22Iw4B EXi0nV3lvpSrXJCaVN+TVP+yGnH2s/lhCd+yQxQLENPtoJNZ8JhzYssi4geMYJQp3DBL xg== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sra09pq97-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:14 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T96HuJ019193 for ; Tue, 29 Aug 2023 09:24:13 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3sqxe1hqeu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:13 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OBU227198132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:12 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D52BA20040 for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9BA1E2004D for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:58 +0200 Message-ID: <20230829092409.75899-5-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: u0yiam3hxqgPAn7E-o9pvKT7QXqnCJva X-Proofpoint-GUID: u0yiam3hxqgPAn7E-o9pvKT7QXqnCJva X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 19164a6b7..9183b097c 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -625,6 +625,89 @@ static struct pldm_cmd pldm_platform_event_message = { .handler = platform_event_message, }; +/* + * 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 *rx) +{ + bitfield8_t sensor_rearm; + struct pldm_tx_data *tx; + uint16_t sensor_id; + uint8_t reserved; + size_t data_size; + 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( + rx->msg, + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES, + &sensor_id, + &sensor_rearm, + &reserved); + if (rc) { + prlog(PR_ERR, "Failed to decode GetStateSensorReadings request, rc = %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + prlog(PR_DEBUG, "%s - sensor_id: %d, sensor_rearm: %x\n", + __func__, sensor_id, sensor_rearm.byte); + + /* send state sensor reading response */ + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_state_sensor_readings_resp) + + (sizeof(get_sensor_state_field) * 1); + + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_state_sensor_readings_resp( + rx->hdrinf.instance, + PLDM_SUCCESS, + 1, /* sensor count of 1 */ + &sensor_state, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetStateSensorReadings response Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetStateSensorReadings response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -669,6 +752,7 @@ 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); return OPAL_SUCCESS; } From patchwork Tue Aug 29 09:23:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=lcRmwXlK; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhtd2gBHz1yZs for ; Tue, 29 Aug 2023 19:28:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=lcRmwXlK; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhtd1ZBTz3c9G for ; Tue, 29 Aug 2023 19:28:25 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=lcRmwXlK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhns4y2cz3bxH for ; Tue, 29 Aug 2023 19:24:17 +1000 (AEST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9Fq6J023238 for ; Tue, 29 Aug 2023 09:24:15 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=wL2m/Zc5ZqjtUwgVyc2vpuolfYltWrjVDFOhXqjXubU=; b=lcRmwXlKfJorG5p2xLiXXDUA2UwNkO1eBdW+OQaPPFDrvjyWSYLli+gcgHKS50MkpmsD Ux6Exnp5tT/9OxrsDkLrl+TxldrTlosLrXTGF7HjLVCwe5m+8Wlf/b7zn3HGf9g+Z3Zd Eae4BmBj09sy0UZszstjJukRO2Sl84LVemQgWmDdAnyeUNICvnlR6VmHO++w99anm36t wOY0JjvF3Sj9DZGr479SxctwQaIoe1mPnackp45QsIAJwJz6mjrJmgaNmhMUva/CqVfp ALPcSAEpqBJRsk8OhWcw6d5SD7xro+whCJrMmR2ddjCtippdIDJKgmL+OfURUY1wT5Nf Cw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ssdqgrt3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:15 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T7BNPR014392 for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqvqn295j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:14 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OCjf21234398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:12 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3774120040 for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F385820043 for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:11 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:23:59 +0200 Message-ID: <20230829092409.75899-6-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JjCqeIuCumyAqpmC5aZeD_tzXyO5sbB6 X-Proofpoint-ORIG-GUID: JjCqeIuCumyAqpmC5aZeD_tzXyO5sbB6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 spamscore=0 adultscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 117 +++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 9183b097c..1589514ec 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -6,11 +6,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include "pldm.h" @@ -708,6 +710,120 @@ 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 + +/* + * 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 *rx) +{ + set_effecter_state_field field[8]; + uint8_t comp_effecter_count; + uint16_t effecter_id; + int rc, i; + + /* decode SetStateEffecterStates request data */ + rc = decode_set_state_effecter_states_req( + rx->msg, + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES, + &effecter_id, + &comp_effecter_count, + field); + if (rc) { + prlog(PR_ERR, "Failed to decode SetStateEffecterStates request, rc = %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->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__, effecter_id, comp_effecter_count); + + for (i = 0; i < comp_effecter_count; i++) { + /* other set_request not supported */ + if (field[i].set_request != PLDM_REQUEST_SET) { + prlog(PR_ERR, "Got invalid set request 0x%x in " + "SetStateEffecterStates request\n", + field[i].set_request); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_PLATFORM_INVALID_STATE_VALUE); + return OPAL_PARAMETER; + } + + switch (field[i].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(rx, 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(rx, 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(rx, 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[i].effecter_state); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_PLATFORM_INVALID_STATE_VALUE); + return OPAL_PARAMETER; + } + } + + 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; @@ -753,6 +869,7 @@ int pldm_responder_init(void) 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 Aug 29 09:24:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=Hzzupm08; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhtS4Djpz1yZs for ; Tue, 29 Aug 2023 19:28:16 +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=Hzzupm08; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhtS37yQz3bpp for ; Tue, 29 Aug 2023 19:28:16 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=Hzzupm08; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhns3BS6z3bYc for ; Tue, 29 Aug 2023 19:24:17 +1000 (AEST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9A40N017448 for ; Tue, 29 Aug 2023 09:24:15 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=TLLbtp91SKLMsj0oAFTglw5Nxb0lXAOmWqSCXJifBfs=; b=Hzzupm08osg5Z/Iem0kdpZZxjJsjM8J/20CGELzubSVg/gAUrMArI0LR4EiS6LRLvapE 7a7ptCNvR3yyHXwo7I4W7gYFss/UYpxsS3pYlp2eQly79gKkx7EeSWVoPI79VynWoZND JDaO9yX0X83UllKbDuo2xZGGlqpmyUX8K57OUjW9Rol04LztPTeTQWXk3TEJh5wQmT2M OctSqroQHbAOXKfvalq5Uvgr5VXmkA8wjgA8Z6gXXo/KtgO+HGFBTd9D6oOwEmq8DLGA 6ZdcCa60whZy8wRoLRNXUCT7r88JckfZjX4z24HF5mZJQWn2td3wHy8c496YB6Li9j+3 yA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ssdjm8mne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:15 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T96Gbq019174 for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3sqxe1hqey-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:14 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OCPJ21234402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:12 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8F9AB20040 for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5604620043 for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:00 +0200 Message-ID: <20230829092409.75899-7-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: woa3pO8mmGyE7CVmtomu7lPRXlpnEPM8 X-Proofpoint-GUID: woa3pO8mmGyE7CVmtomu7lPRXlpnEPM8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 adultscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 --- core/pldm/pldm-platform-requests.c | 25 +++++++++++++++++++++++++ core/pldm/pldm.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 568ed2323..eeb202807 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -44,6 +44,31 @@ 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; + + if (!pdr_ready) + return OPAL_HARDWARE; + + 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 f4e1617ec..ee4d49322 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -78,6 +78,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(struct pldm_tx_data *tx, void (*complete)(struct pldm_rx_data *rx, void *data), From patchwork Tue Aug 29 09:24:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=g8lSc8iK; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhtp2rVzz1yZs for ; Tue, 29 Aug 2023 19:28:34 +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=g8lSc8iK; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhtp1mT2z2xqq for ; Tue, 29 Aug 2023 19:28:34 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=g8lSc8iK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhns5wXlz3byP for ; Tue, 29 Aug 2023 19:24:17 +1000 (AEST) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T885GA024075 for ; Tue, 29 Aug 2023 09:24:15 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=polCjgtDBbvrXedEIQ5sBv/sUqXFf7E/w4gVOkhucHI=; b=g8lSc8iKAuk7rZJWQIHYH3YpDqN8ynmmZ+EPqwij+S7MScg8egxPsCU1FPMNqyYbVCU8 Q6ncYSl1YaRlp0tNpgofozfcgh+NCSS+zJdr1Em60Nd5SiuuI4d/Y5WN5eGM5H1VTElG 225fN2zHS9h0Dp/GyA+8uPza12Tm5xKvdqGaWmdDcB9nyAQw5oBcl2ti4kg2Cp0iH+p0 as7qMHX7CSEo70HeNOzg9IzUzmwNngAa9g7yIoXnz4/QMuoC2yi0UDjbWhmHgAPylvvQ pDiGn00ZZfwmQMP1WDSR5+Xsf89ouxlBLOi3AOnIsLbGV7KNEkdHTM/Y2eG80Hn22ccM pw== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr8q7xngw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:15 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T93V1G004946 for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3squqsjk8h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:14 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OD7A21234404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:13 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E72B420040 for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AEA9920043 for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:01 +0200 Message-ID: <20230829092409.75899-8-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ez__3Z7Ivwi098Q3n87NqgaTzXls7H_I X-Proofpoint-ORIG-GUID: Ez__3Z7Ivwi098Q3n87NqgaTzXls7H_I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 --- core/pldm/pldm-platform-requests.c | 124 +++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index eeb202807..133873048 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -260,6 +260,130 @@ 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; + struct pldm_tx_data *tx; + void *response_msg; + size_t data_size; + 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); + if (!event_data) { + prlog(PR_ERR, "failed to allocate event data (size: 0x%lx)\n", max_change_records_size); + return OPAL_NO_MEM; + } + } + } + + /* Send the event request */ + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + max_change_records_size; + + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + max_change_records_size; + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size - 1; + + /* 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 *)tx->data, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(event_data); + free(tx); + return OPAL_PARAMETER; + } + free(event_data); + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(tx); + return rc; + } + free(tx); + + /* 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 Aug 29 09:24:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=ECAhbo9M; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhtz37K7z1yZs for ; Tue, 29 Aug 2023 19:28:43 +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=ECAhbo9M; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhtz24c8z3bwp for ; Tue, 29 Aug 2023 19:28:43 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=ECAhbo9M; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnt1bPfz3bxH for ; Tue, 29 Aug 2023 19:24:18 +1000 (AEST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T99fbs014899 for ; Tue, 29 Aug 2023 09:24:16 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=YgeWYkQUow3VMZrQF9OQhBjRHH7lJTNQxjFyBKfZez8=; b=ECAhbo9MYjgndyrj4poo5V9fBezvwSEmRLiw6H94i2/GdWrVKRd/Q/dKtlzHTSVuNxp+ JTbR5r5v6Td3DJDYMGK3VuYxHDc7HIAjA2XSR8bW4CNNEFtCY0FlOe1BYZUYYZ2XlwUA qeV68GRjPMTG7YINZr0HC3Y8h/bMLj2yef3ii8tFpNvuqIrjQdRdWDAE0vRXOMVKsoCt GUrgWtnZmIulN4Lz17YjT9INHDbRR+l5dRnXELnkLwIrAi3OnhdAjIJJzfbFbDByhtMq ZMBZOjhSAnfQWR0fv/d8qzm7Ge/vI6IPfuK7DabxXtqrKwwnMl8Q6RQvmIYMzLAnu6Kc mQ== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ssdjm8mnp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:15 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8PXmL014209 for ; Tue, 29 Aug 2023 09:24:15 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3sqwxjsu6k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:14 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9ODGN27722426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:13 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BB852004D for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1271920043 for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:12 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:02 +0200 Message-ID: <20230829092409.75899-9-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ac0XI6wMYMoN8_hqq_JV4lqRalBMKl61 X-Proofpoint-GUID: ac0XI6wMYMoN8_hqq_JV4lqRalBMKl61 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 adultscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 08/15] core/pldm: Create boot progress and 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 boot progress record will be used to report Opal's progress to the BMC during the boot. 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. Signed-off-by: Christophe Lombard --- core/pldm/pldm-platform-requests.c | 328 +++++++++++++++++++++++++++++ core/pldm/pldm.h | 15 ++ 2 files changed, 343 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 133873048..8bd373ccc 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -28,6 +28,9 @@ struct pldm_pdrs { }; struct pldm_pdrs *pdrs; +/* assign specific sensor/effecter IDs */ +#define PLDM_SENSOR_SE_ID_RANGE_START 0x6666 +static int sensor_effecter_id = PLDM_SENSOR_SE_ID_RANGE_START; static void pdr_init_complete(bool success) { @@ -260,6 +263,287 @@ int pldm_platform_restart(void) return set_state_effecter_states_req(effecter_id, &field, true); } +static int add_state_sensor_pdr(pldm_pdr *repo, + uint32_t *record_handle, + uint16_t entity_type, + 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); + if (!state_storage) { + prlog(PR_ERR, "failed to allocate storage data (size: 0x%lx)\n", state_size); + return OPAL_NO_MEM; + } + + 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); + if (!pdr) { + prlog(PR_ERR, "failed to allocate sensor pdr (size: 0x%lx)\n", pdr_size); + free(state_storage); + return OPAL_NO_MEM; + } + + /* 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 = sensor_effecter_id++; + pdr->entity_type = entity_type; + 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, + 0, false, HOST_TID); + + free(state_storage); + free(pdr); + + return OPAL_SUCCESS; +} + +/* + * Add boot progress record in the repository. + */ +static uint32_t add_sensor_sw_term_pdr(pldm_pdr *repo, + uint32_t *record_handle) +{ + int rc; + + rc = add_state_sensor_pdr( + repo, + record_handle, + PLDM_ENTITY_SYSTEM_CHASSIS, + PLDM_STATE_SET_SW_TERMINATION_STATUS, + enum_bit(PLDM_SW_TERM_NORMAL) | + enum_bit(PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED) | + enum_bit(PLDM_SW_TERM_GRACEFUL_SHUTDOWN)); + if (rc) { + prlog(PR_ERR, "%s - Failed to add states sensor PDR, rc: %d\n", + __func__, rc); + return rc; + } + + prlog(PR_DEBUG, "Add state sensor pdr (record handle: %d)\n", + *record_handle); + + 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_state_sensor_pdr( + repo, + record_handle, + PLDM_ENTITY_SYS_BOARD, + 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 boot progress PDR, rc: %d\n", + __func__, rc); + return rc; + } + + prlog(PR_DEBUG, "Add boot progress pdr (record handle: %d)\n", + *record_handle); + + return OPAL_SUCCESS; +} + +static int add_state_effecter_pdr(pldm_pdr *repo, + uint32_t *record_handle, + uint16_t entity_type, + uint16_t state_set_id, + uint32_t states) +{ + struct state_effecter_possible_states *possible_states; + struct pldm_state_effecter_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_effecter_possible_states) + + sizeof(states) + - sizeof(bitfield8_t); + state_storage = zalloc(state_size); + if (!state_storage) { + prlog(PR_ERR, "failed to allocate storage data (size: 0x%lx)\n", state_size); + return OPAL_NO_MEM; + } + + possible_states = (struct state_effecter_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_effecter_pdr) + state_size; + pdr = zalloc(pdr_size); + if (!pdr) { + prlog(PR_ERR, "failed to allocate sensor pdr (size: 0x%lx)\n", pdr_size); + free(state_storage); + return OPAL_NO_MEM; + } + + /* 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->effecter_id = sensor_effecter_id++; + pdr->entity_type = entity_type; + pdr->entity_instance = 1; + pdr->container_id = DEFAULT_CONTAINER_ID; + pdr->effecter_semantic_id = 0; /* PLDM defines no semantic IDs yet */ + pdr->effecter_init = PLDM_NO_INIT; + pdr->has_description_pdr = false; + pdr->composite_effecter_count = 1; + + rc = encode_state_effecter_pdr(pdr, pdr_size, possible_states, + state_size, &actual_pdr_size); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "%s - Failed to encode state effecter 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, + 0, false, HOST_TID); + + free(state_storage); + free(pdr); + + return OPAL_SUCCESS; +} + +/* + * Add state software termination record in the repository. + */ +static uint32_t add_state_sw_term_pdr(pldm_pdr *repo, + uint32_t *record_handle) +{ + int rc; + + rc = add_state_effecter_pdr( + repo, + record_handle, + PLDM_ENTITY_SYSTEM_CHASSIS, + PLDM_STATE_SET_SW_TERMINATION_STATUS, + enum_bit(PLDM_SW_TERM_GRACEFUL_SHUTDOWN_REQUESTED)); + if (rc) { + prlog(PR_ERR, "%s - Failed to add boot progress PDR, rc: %d\n", + __func__, rc); + return rc; + } + + prlog(PR_DEBUG, "Add state software termination 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, + 0, false, HOST_TID); + + 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) { @@ -384,6 +668,45 @@ static int send_repository_changed_event(uint32_t num_changed_pdrs, return OPAL_SUCCESS; } +static int add_hosted_pdrs(pldm_pdr *repo) +{ + static uint32_t records_handle[2]; + uint8_t hosted_pdrs = 0; + uint32_t record_handle; + int rc = OPAL_SUCCESS; + + rc = add_state_sw_term_pdr(repo, &record_handle); + if (!rc) { + records_handle[hosted_pdrs] = record_handle; + hosted_pdrs++; + } + + rc = add_sensor_sw_term_pdr(repo, &record_handle); + if (!rc) { + records_handle[hosted_pdrs] = record_handle; + hosted_pdrs++; + } + + 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; @@ -629,6 +952,11 @@ int pldm_platform_init(void) if (rc) goto err; + /* add hosted pdrs */ + rc = add_hosted_pdrs(pdrs_repo); + if (rc) + goto err; + pdr_init_complete(true); prlog(PR_DEBUG, "%s - done\n", __func__); diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index ee4d49322..df38ce5fb 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -35,6 +35,21 @@ struct pldm_tx_data { uint8_t data[1]; }; +/* 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 Aug 29 09:24:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=XidtC71F; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhvK594Xz1yZs for ; Tue, 29 Aug 2023 19:29:01 +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=XidtC71F; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhvK46Ydz3c2r for ; Tue, 29 Aug 2023 19:29:01 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=XidtC71F; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnt6J7xz3bjc for ; Tue, 29 Aug 2023 19:24:18 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9DqEn004035 for ; Tue, 29 Aug 2023 09:24:16 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=mm1N/Saeir3woVBng73rilCA3PGGK2gCIPtvmlbF1/Q=; b=XidtC71FiccWH7ZLd8W80YzklYVmqg4Jf/NT/HnW3JIQdABtbY0ldE9jDKTz7kaHzoS/ FWk79+Suw5uekq4Ikl5sXAv8pQBkALJSHS+2DU8L8SW6hoDJqtuhEzoq9eUQdOE6q5/F 0RJ79fCjZn4GEMf0PJyEOOtB1Qhl+Jp/4ujJ/f/A0/1v9x2TtMN4KeNUItSg/VwdYhsW NtaeSDqQ3ecMRmFBfW9lAzg40f5V9EStCFwHXof3yI3rEnwfiKPKxoofpKF1VW5KuWuR 6aEXYVq68lP2xzO9eBqtuTo3nXpYFZ7xB3NMtavlalPGqFjmnFxHiQf/mXcNaoDpHaCo AQ== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr87hqh1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T7GFpp014388 for ; Tue, 29 Aug 2023 09:24:15 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqvqn295r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:15 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9ODg845154992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:13 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A497120040 for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B01A20043 for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:03 +0200 Message-ID: <20230829092409.75899-10-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: UJBLCMu-ODj8fL7HZ3C9M2uSs5PEcxzA X-Proofpoint-GUID: UJBLCMu-ODj8fL7HZ3C9M2uSs5PEcxzA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 --- core/pldm/pldm-responder.c | 123 +++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index 1589514ec..3eba2e9be 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -824,6 +824,128 @@ static struct pldm_cmd pldm_platform_set_state_effecter_states = { .handler = platform_set_state_effecter_states_handler, }; +/* + * 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 *rx) +{ + uint32_t data_transfer_handle, pdr_data_size = 0; + uint32_t record_handle, next_record_handle; + uint16_t request_count, record_change_number; + uint8_t transfer_op_flag, *pdr_data = NULL; + size_t payload_len, data_size; + struct pldm_tx_data *tx; + int rc; + + payload_len = rx->msg_len - sizeof(struct pldm_msg_hdr); + rc = decode_get_pdr_req(rx->msg, + payload_len, + &record_handle, + &data_transfer_handle, + &transfer_op_flag, + &request_count, + &record_change_number); + if (rc) { + prlog(PR_ERR, "Failed to decode GetPDR request, rc = %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + return OPAL_INTERNAL_ERROR; + } + + if (data_transfer_handle != 0) { + /* We don't support multipart transfers */ + prlog(PR_ERR, "Got invalid data transfer handle 0x%x in GetPDR request\n", + data_transfer_handle); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_PLATFORM_INVALID_DATA_TRANSFER_HANDLE); + return OPAL_PARAMETER; + } + + if (transfer_op_flag != PLDM_GET_FIRSTPART) { + prlog(PR_ERR, "Got invalid transfer op flag 0x%x in GetPDR request\n", + transfer_op_flag); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_PLATFORM_INVALID_TRANSFER_OPERATION_FLAG); + return OPAL_PARAMETER; + } + + if (record_change_number != 0) { + prlog(PR_ERR, "Got invalid record change number 0x%x in GetPDR request\n", + record_change_number); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->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", record_handle); + + rc = pldm_platform_pdr_find_record(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", + record_handle); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, + PLDM_PLATFORM_INVALID_RECORD_HANDLE); + return OPAL_PARAMETER; + } + + /* create a PLDM response message for GetPDR */ + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_pdr_resp) + + pdr_data_size; + + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size - 1; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_pdr_resp(rx->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 *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetPDR Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetPDR response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -870,6 +992,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 Aug 29 09:24:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=a1RCRXUP; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhv8142dz1yZs for ; Tue, 29 Aug 2023 19:28: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=a1RCRXUP; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhv801TFz3c2V for ; Tue, 29 Aug 2023 19:28:52 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=a1RCRXUP; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnt4wv5z300q for ; Tue, 29 Aug 2023 19:24:18 +1000 (AEST) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T99qfM030464 for ; Tue, 29 Aug 2023 09:24:17 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=TXkIZSYwX4JO3m8vxoTtpHhAtkLXtiX/wWeZwdIA7AA=; b=a1RCRXUPzx95yBGZh2JLjOaBu042zcfNZYxSqJYz9UFbGHD2GYNepwtKsOzCprbsO+4u Q/6VRkk/9hA9lzRE8zBV0+8hzOodnyE9SX7FuEHCrifo7A0FXYDZhp7CXMJ1s1j3ST7T 6dSrlfYOuv5tCHHkmf08XOHj3izNAJCr9XPXzgf5aUMWixYPvwh0iytDkQgnT0bF0VBS Cyp9Y5/zxp9VA7JATXuhpEVSIUqTJtlkC+Zj14o2SPEHKPmq7t66pQHVRjJvLWthgigw n2tuBi777OaOnNJxRYflhfDrmasNnYSKQJT8KusphGHsbOaPUYF31YaYHW8ps1cpkv6j mA== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr8s75xr3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8waAV004884 for ; Tue, 29 Aug 2023 09:24:15 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3squqsjk8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:15 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OEIl45089276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B09C20040 for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C486720043 for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:13 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:04 +0200 Message-ID: <20230829092409.75899-11-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ov99XPiPe82qSsXBNMWdiMV2IpaLOtSc X-Proofpoint-ORIG-GUID: ov99XPiPe82qSsXBNMWdiMV2IpaLOtSc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 58 +++++++++++++++++++++ core/pldm/pldm-responder.c | 96 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 3 ++ 3 files changed, 157 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index ab517e90f..fa4764b17 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; @@ -211,6 +214,61 @@ out: return rc; } +#define RECORD_SET_ID 100 + +void pldm_fru_set_local_table(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); + if (!local_fru_record_table) { + prlog(PR_ERR, "%s: failed to allocate fru record table\n", + __func__); + return; + } + + /* 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 3eba2e9be..3ab813f36 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -946,6 +947,97 @@ 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 *rx) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_get_fru_record_table_metadata_resp); + uint16_t total_record_set_identifiers, total_table_records; + uint32_t fru_table_length; + struct pldm_tx_data *tx; + int rc; + + /* + * GetFRURecordTableMetadata requests + * don't have any payload, so no need to decode them + */ + + /* add specific fru record */ + pldm_fru_set_local_table(&fru_table_length, + &total_record_set_identifiers, + &total_table_records); + + /* create a PLDM response message for GetFRURecordTableMetadata */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_fru_record_table_metadata_resp( + rx->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 *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFRURecordTableMetadata Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + /* send PLDM message over MCTP */ + rc = pldm_mctp_message_tx(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetFRURecordTableMetadata response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -994,5 +1086,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 df38ce5fb..bc8782466 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -80,6 +80,9 @@ int pldm_file_io_write_file(uint32_t file_handle, uint32_t pos, int pldm_file_io_init(void); int pldm_fru_get_bmc_version(void *bv, int len); +void pldm_fru_set_local_table(uint32_t *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 Aug 29 09:24:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=qYMOFgIL; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhvg5b6kz1yhC for ; Tue, 29 Aug 2023 19:29: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=qYMOFgIL; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhvg4TJJz3c67 for ; Tue, 29 Aug 2023 19:29:19 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=qYMOFgIL; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnv3rmWz3c1R for ; Tue, 29 Aug 2023 19:24:19 +1000 (AEST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9ERBf016216 for ; Tue, 29 Aug 2023 09:24:17 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=nMsrKKAJocSQ1THNlQbpg2kgM4LQc1j/eZZ0nSwCMxE=; b=qYMOFgIL+OVNbdepOD4YIgVcG7lvrNWEMox7RDu3UM59Ud7g5xGTFuCaQkX0ggH2V5sR OliprGyVNgx07/EHplGrBgv+uTV7WkBuymOlP2LyKVI0PMhK8vikD6A4PkrDqS8PYjmt 00Uc2QCpt7wEih5fBpoqKPxWZQLoUIh8Zab+i/JTaMC9oc7bbo3aFDy0fZz1YmduzTTO LvjVAnnhkaFJg30jTz5+d4proy1PUuthFUduh2pFj4QLG2eFt9sA3wbUjl3/ketarj/D p5ziz1imQeuUq8gf6MuXqD8QiNhV5EsvrYuevt3B+BPV9JIpL6HOT3KZc/mVJz+VyEwH pg== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ssdqgrt4m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T76Rw3014416 for ; Tue, 29 Aug 2023 09:24:16 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqvqn295w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OErG33948360 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64A022004D for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A95520043 for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:05 +0200 Message-ID: <20230829092409.75899-12-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 5d7KLCsgCKb2wI1b47ojT1mqzuqRuMui X-Proofpoint-ORIG-GUID: 5d7KLCsgCKb2wI1b47ojT1mqzuqRuMui X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 spamscore=0 adultscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 --- core/pldm/pldm-fru-requests.c | 12 +++++ core/pldm/pldm-responder.c | 82 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 3 files changed, 96 insertions(+) diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index fa4764b17..a29a80ae4 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -269,6 +269,18 @@ void pldm_fru_set_local_table(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 3ab813f36..d42d9f52a 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -1038,6 +1038,87 @@ 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 *rx) +{ + struct pldm_get_fru_record_table_resp *resp; + void *fru_record_table_bytes; + uint32_t fru_record_table_size; + struct pldm_tx_data *tx; + struct pldm_msg *msg; + size_t data_size; + 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(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* create a PLDM response message for GetFRURecordTable */ + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_fru_record_table_resp) + + fru_record_table_size; + + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size - 1; + tx->tag_owner = true; + tx->msg_tag = rx->msg_tag; + + rc = encode_get_fru_record_table_resp( + rx->hdrinf.instance, + PLDM_SUCCESS, + 0, // No next transfer handle + PLDM_START_AND_END, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordTable Error, rc: %d\n", rc); + cc_resp(rx, rx->hdrinf.pldm_type, + rx->hdrinf.command, PLDM_ERROR); + free(tx); + return OPAL_PARAMETER; + } + + msg = (struct pldm_msg *)tx->data; + 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(tx); + if (rc) { + prlog(PR_ERR, "Failed to send GetFruRecordTable response, rc = %d\n", rc); + free(tx); + return OPAL_HARDWARE; + } + + free(tx); + 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; @@ -1089,6 +1170,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 bc8782466..fb837bfc5 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -83,6 +83,8 @@ int pldm_fru_get_bmc_version(void *bv, int len); void pldm_fru_set_local_table(uint32_t *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 Aug 29 09:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=LJERMI4+; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhvr4cXZz1yZs for ; Tue, 29 Aug 2023 19:29:28 +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=LJERMI4+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhvr3WzVz3c4r for ; Tue, 29 Aug 2023 19:29:28 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=LJERMI4+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnv6mMjz3c01 for ; Tue, 29 Aug 2023 19:24:19 +1000 (AEST) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9Dtaa004104 for ; Tue, 29 Aug 2023 09:24:17 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=JXRn+Hje4r4GCPF54Cnw3BdVtJWiWePsR+7CULggpjA=; b=LJERMI4+jWJnF3Xok6uQNpmYnUnOA4Kks0IEww1MksdKLDsEdu0K7sU0oRVJw8A1cOdB RPNIxLY8IdbbTli4mTJRp4FRNPE1yuGrIOW81pw1gCXZ+FJ3s/Jj/GyuipZs8us2Zeln cw4efZT4XfL7w47HuDll4XhjM1AXYIZcF8djKV+sxO9ZXKKhldahV8/zobLE66z4n7qf c+h+BBjqFH4kW2qcXcyo9sDJDNTfBm9hwCeJ4AvDaW3r4i13+jLID1mbxxTIt5lNfBvl +R/w8tdB0LSQpSnPN5SqT4H52JWOMsEpIzbEX7V+P20zI4fIZpkDcAwAcRTIt8pouZ3w LA== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr87hqh1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T9AWkY020530 for ; Tue, 29 Aug 2023 09:24:16 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqv3yafk9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OE4x33948362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:14 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BEFD12004E for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8355E20043 for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:06 +0200 Message-ID: <20230829092409.75899-13-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PyicmBmIcn6pg-kM_hdbg9SFu1T_MPWT X-Proofpoint-GUID: PyicmBmIcn6pg-kM_hdbg9SFu1T_MPWT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 impostorscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 267 +++++++++++++++++++++++++++++ core/pldm/pldm-responder.c | 1 + include/pldm.h | 12 ++ 3 files changed, 280 insertions(+) diff --git a/core/pldm/pldm-platform-requests.c b/core/pldm/pldm-platform-requests.c index 8bd373ccc..cb0ff9443 100644 --- a/core/pldm/pldm-platform-requests.c +++ b/core/pldm/pldm-platform-requests.c @@ -72,6 +72,51 @@ int pldm_platform_pdr_find_record(uint32_t record_handle, return OPAL_SUCCESS; } +/* + * Search the matching record and return the sensor id. + * PDR type = PLDM_STATE_SENSOR_PDR + */ +static int find_sensor_id_by_state_set_Id(uint16_t entity_type, + uint16_t state_set_id, + uint16_t *sensor_id, + uint16_t terminus_handle) +{ + struct state_sensor_possible_states *possible_states; + struct pldm_state_sensor_pdr *state_sensor_pdr; + const pldm_pdr_record *record = NULL; + uint8_t *outData = NULL; + uint32_t size; + + 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) { + state_sensor_pdr = (struct pldm_state_sensor_pdr *) outData; + + *sensor_id = le16_to_cpu(state_sensor_pdr->sensor_id); + + possible_states = (struct state_sensor_possible_states *) + state_sensor_pdr->possible_states; + + if ((le16_to_cpu(state_sensor_pdr->entity_type) == entity_type) && + (le16_to_cpu(state_sensor_pdr->terminus_handle) == terminus_handle) && + (le16_to_cpu(possible_states->state_set_id) == state_set_id)) + return OPAL_SUCCESS; + } + + } while (record); + + return OPAL_PARAMETER; +} + /* * Search the matching record and return the effecter id. * PDR type = PLDM_STATE_EFFECTER_PDR @@ -263,6 +308,228 @@ 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, + bool no_timeout) +{ + size_t event_data_size = 0, actual_event_data_size; + size_t response_len, payload_len, data_size; + uint8_t *event_data = NULL; + struct pldm_tx_data *tx; + void *response_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); + if (!event_data) { + prlog(PR_ERR, "failed to allocate event data (size: 0x%lx)\n", event_data_size); + return OPAL_NO_MEM; + } + } + } + + /* Send the event request */ + payload_len = PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_size; + + data_size = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_platform_event_message_req) + + event_data_size; + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size - 1; + + /* 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 *)tx->data, + payload_len); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode PlatformEventMessage Error, rc: %d\n", rc); + free(event_data); + free(tx); + return OPAL_PARAMETER; + } + free(event_data); + + /* Send and get the response message bytes. + * It may happen that for some commands, the responder does not + * have time to respond. + */ + if (no_timeout) { + rc = pldm_mctp_message_tx(tx); + if (rc) + prlog(PR_ERR, "Failed to send PlatformEventMessage request, rc = %d\n", rc); + free(tx); + return rc; + } + + /* Send and get the response message bytes */ + rc = pldm_requester_queue_and_wait(tx, + &response_msg, &response_len); + if (rc) { + prlog(PR_ERR, "Communication Error, req: PlatformEventMessage, rc: %d\n", rc); + free(tx); + return rc; + } + free(tx); + + /* 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; + + if (!pdr_ready) + return OPAL_HARDWARE; + + 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); + break; + } + } + } + + } 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, + false); +} + +#define SW_TERM_GRACEFUL_SHUTDOWN_INDEX 0 + +/* + * entity_type: System Firmware + * state_set: Software Termination Status(129) + * states: Graceful Shutdown Requested(7) + */ +int pldm_platform_initiate_shutdown(void) +{ + uint16_t sensor_id; + int rc; + + if (!pdr_ready) + return OPAL_HARDWARE; + + rc = find_sensor_id_by_state_set_Id( + PLDM_ENTITY_SYSTEM_CHASSIS, + PLDM_STATE_SET_SW_TERMINATION_STATUS, + &sensor_id, HOST_TID); + if (rc) { + prlog(PR_ERR, "%s - sensor id not found\n", __func__); + return rc; + } + + prlog(PR_INFO, "sending system firmware Graceful Shutdown request (sensor_id: %d)\n", + sensor_id); + + return send_sensor_state_changed_event( + PLDM_STATE_SET_SW_TERMINATION_STATUS, + sensor_id, + SW_TERM_GRACEFUL_SHUTDOWN_INDEX, + PLDM_SW_TERM_GRACEFUL_SHUTDOWN, + true); +} + static int add_state_sensor_pdr(pldm_pdr *repo, uint32_t *record_handle, uint16_t entity_type, diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index d42d9f52a..7dbde7dba 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -792,6 +792,7 @@ static int platform_set_state_effecter_states_handler(const struct pldm_rx_data cpu_to_be64(SOFT_REBOOT)); } + pldm_platform_initiate_shutdown(); break; case PLDM_STATE_SET_BOOT_RESTART_CAUSE_WARM_RESET: diff --git a/include/pldm.h b/include/pldm.h index 80ee85c00..e33de7dcb 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -6,6 +6,7 @@ #define __PLDM_H__ #include +#include /** * Handle PLDM messages received from MCTP @@ -33,6 +34,11 @@ int pldm_platform_power_off(void); */ int pldm_platform_restart(void); +/** + * Send a system firmware Graceful Shutdown request + */ +int pldm_platform_initiate_shutdown(void); + /** * Update the firmware version device-tree field */ @@ -53,4 +59,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 Aug 29 09:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=VbPxluRU; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhw12G6bz1yZs for ; Tue, 29 Aug 2023 19:29:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=VbPxluRU; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhw11CNHz3c5P for ; Tue, 29 Aug 2023 19:29:37 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=VbPxluRU; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnw0Zc4z3bvB for ; Tue, 29 Aug 2023 19:24:19 +1000 (AEST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T94G7w015643 for ; Tue, 29 Aug 2023 09:24:18 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=8k7m/aDfq4zcI/ZBDvYEYGTfwSJaOii0aOH6H4etAuM=; b=VbPxluRU1cIj5HHbk72/VL1c61GsXoIt0ePvvhDF3pc1/OPDN8DkEp/E3sjDhF1+Qida xvTGiPhLUWjBOjCCiIdvfewDZJJfH2fOO8ptFPv3T4Q1BawFZdNZT1UVU1RiGTOjFkzo azd122CRaS/juZeV9adI7xTMi/7/EjYzkuPzHpxupode+VCNHm5l+szEpDaXeTWO2dzR 9y5gdKhBeR0UPREbEfIeOqujNW+RrJ5EA15a4HQ+wWpxS7LurKUkwYW393O+Ow69kf/k yunRet38ZUlN4Ljeugj+NVrwNpgF/URpCATDIhdXfS7s+IlkU5kpVtZLvmxoGWlCOynu vQ== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ssdqgrt4r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8waAX004884 for ; Tue, 29 Aug 2023 09:24:17 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3squqsjk8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:16 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OFNC25362854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:15 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21AB52004B for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC0BA20040 for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:14 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:07 +0200 Message-ID: <20230829092409.75899-14-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 7IoDlTbFTF0h2647Y2njaqAOm8hWE1mm X-Proofpoint-ORIG-GUID: 7IoDlTbFTF0h2647Y2njaqAOm8hWE1mm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 spamscore=0 adultscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 260 +++++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 + 3 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-rtc.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index e3efcc2b1..14aa105b7 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -11,7 +11,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 000000000..16797999d --- /dev/null +++ b/core/pldm/pldm-rtc.c @@ -0,0 +1,260 @@ +// 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) +{ + size_t data_size = PLDM_MSG_SIZE(0); /* the command doesn't have a message payload */ + struct pldm_tx_data *tx = NULL; + int rc; + + /* Encode the date time request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + rc = encode_get_date_time_req(DEFAULT_INSTANCE_ID, + (struct pldm_msg *)tx->data); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetBiosDateTimeReq Error, rc: %d\n", rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Queue and get the response message bytes */ + rc = pldm_requester_queue(tx, get_date_time_req_complete, NULL); + if (rc) { + prlog(PR_ERR, "Communication Error, req: GetBiosDateTimeReq, rc: %d\n", rc); + free(tx); + return rc; + } + + free(tx); + 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) +{ + size_t data_size = PLDM_MSG_SIZE(struct pldm_set_date_time_req); + struct pldm_tx_data *tx = NULL; + int rc; + + /* Encode the date time request */ + tx = zalloc(sizeof(struct pldm_tx_data) + data_size); + if (!tx) + return OPAL_NO_MEM; + tx->data_size = data_size; + + 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 *)tx->data, + sizeof(struct pldm_set_date_time_req)); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode SetBiosDateTimeReq Error, rc: %d\n", + rc); + free(tx); + return OPAL_PARAMETER; + } + + /* Queue and get the response message bytes */ + rc = pldm_requester_queue(tx, set_date_time_req_complete, NULL); + if (rc) { + prlog(PR_ERR, "Communication Error, req: SetBiosDateTimeReq, rc: %d\n", rc); + free(tx); + return rc; + } + + free(tx); + 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; + + 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 e33de7dcb..7f944e7e4 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -65,4 +65,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 Aug 29 09:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=lTjUWVoS; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhwB13m9z1yZs for ; Tue, 29 Aug 2023 19:29: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=lTjUWVoS; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhw97449z3cBC for ; Tue, 29 Aug 2023 19:29:45 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=lTjUWVoS; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnw4tBXz3bYc for ; Tue, 29 Aug 2023 19:24:20 +1000 (AEST) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T99nJY030217 for ; Tue, 29 Aug 2023 09:24:19 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=Vah39+3RSbwNEQrl7OGbkd1mwzu1SsWuXNbr+tb2ys0=; b=lTjUWVoSfVoHmuX/Q1kU+DQIXzCCccdVhYekLogwp4++bH1uq8AWpLBq9NTzTgPgMvJV 0EZK/LcbDK1v0hMWj8SJgJ5enDK3Sc8Z/lS6dk4B8jVjuLBvwrPRZBvXtSd6ULtbyqfZ az6dMs+mr6jg6zXxDkrVtbV5qO6iNYThYWnKegqDAPxWpqtP5MULJZsS1vovbUtwzdqC 3XAxxa7Os+I0Hvd9i43wiW78QS4qd6GVjBIg7X53qXgc+Cadeo3d/pfPZa4iI4mApRdI iVwV3ykZvH0eTfVlN/tVeMoBMuguWrtkG/cHQPPB9AZE3NY4cztx0n2n++xCzPMcYpBj /A== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr8s75xrp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:18 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T7bbOm009989 for ; Tue, 29 Aug 2023 09:24:17 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3sqw7ka3c0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OFtn36635064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:15 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7632520043 for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E9E920040 for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:08 +0200 Message-ID: <20230829092409.75899-15-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: XGA_Vtx6qK30rcUYuWa5-oK5E1_g2d74 X-Proofpoint-ORIG-GUID: XGA_Vtx6qK30rcUYuWa5-oK5E1_g2d74 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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" backend apis to support partially: OPAL_IPMI_SEND: send an IPMI message to the service processor OPAL_IPMI_RECV: read an ipmi message of type ``ipmi_msg`` from ipmi message queue ``msgq`` into host OS structure ``opal_ipmi_msg`` Signed-off-by: Christophe Lombard --- core/pldm/Makefile.inc | 2 +- core/pldm/pldm-opal.c | 298 +++++++++++++++++++++++++++++++++++++++++ include/pldm.h | 5 + 3 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 core/pldm/pldm-opal.c diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc index 14aa105b7..4484fac32 100644 --- a/core/pldm/Makefile.inc +++ b/core/pldm/Makefile.inc @@ -11,7 +11,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 000000000..c99509565 --- /dev/null +++ b/core/pldm/pldm-opal.c @@ -0,0 +1,298 @@ +// 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" + +#define BMC_VERSION_LENGTH 100 + +/* + * 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[BMC_VERSION_LENGTH]; + 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, BMC_VERSION_LENGTH); + 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, code: %d, " + "cmd: 0x%x netfn: 0x%x\n", + ipmi_code, opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2); + 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); + } + + prerror("OPAL IPMI: Command not supported, cmd: 0x%x netfn: 0x%x\n", + opal_ipmi_msg->cmd, opal_ipmi_msg->netfn >> 2); + + 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 7f944e7e4..54c9bd4bc 100644 --- a/include/pldm.h +++ b/include/pldm.h @@ -70,4 +70,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 Aug 29 09:24:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1827201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=oHtkZPg+; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RZhwM1nMrz1yZs for ; Tue, 29 Aug 2023 19:29:55 +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=oHtkZPg+; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RZhwM0jgtz3cHf for ; Tue, 29 Aug 2023 19:29:55 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org 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=oHtkZPg+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.ibm.com; receiver=lists.ozlabs.org) 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 4RZhnw4xgbz3bvP for ; Tue, 29 Aug 2023 19:24:20 +1000 (AEST) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8er9u005959 for ; Tue, 29 Aug 2023 09:24:19 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=ODOJ4uDA/7rJdN9Svy6ky7Ru58YpT6GnwOhJQn1cxic=; b=oHtkZPg+fJw1BuDm5rC+8FwQky9Tjzcw1Trcsi3vEyFnutSZ9UMat43gxL3hTu31S6B1 MkzOf8Ry25XX2fwXxwYCCPqRkB2I9ttqWhO9NQrZyWMCpfKOWI1sZ6UKMz/mlUihuxk1 ENnmATGePV8hqgR04qTMoBnbGz02av5Bh3LvNdvyQX9BpYqq3PTf4zHYT6PcE88/wfAb WIDTQTW/4GKUpqxHVXmhHHAWx00TRN0KolaxsUYWHXY64FcpZUCuR/FkrICLyJc2aN+E GdLhtNaEV/XrEK+GgxrFIy/LwNvCH0com5P9yH+rx70gvk7qYY/XF7xpt/jxQtZLJX8D cg== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3srv501g9n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:18 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T8neHE019181 for ; Tue, 29 Aug 2023 09:24:17 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3sqxe1hqfh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 Aug 2023 09:24:17 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T9OFbr38994518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Aug 2023 09:24:16 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCDAC20043 for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 954A920040 for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) Received: from li-ac0ca24c-3330-11b2-a85c-93224c50ad7a.home (unknown [9.171.88.232]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP for ; Tue, 29 Aug 2023 09:24:15 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Tue, 29 Aug 2023 11:24:09 +0200 Message-ID: <20230829092409.75899-16-clombard@linux.ibm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230829092409.75899-1-clombard@linux.ibm.com> References: <20230829092409.75899-1-clombard@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: -CMPJNyVLswFs5aFmHkv__6ybxTWFxSE X-Proofpoint-GUID: -CMPJNyVLswFs5aFmHkv__6ybxTWFxSE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_06,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 clxscore=1015 priorityscore=1501 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290078 Subject: [Skiboot] [PATCH V6 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 | 16 +++++++++++++++- platforms/astbmc/astbmc.h | 4 ++++ platforms/astbmc/common.c | 34 ++++++++++++++++++++++++++++++++++ platforms/astbmc/pnor.c | 25 +++++++++++++++++++++++++ platforms/qemu/qemu.c | 6 ++++++ 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/core/init.c b/core/init.c index 73748a5d3..2d8a54595 100644 --- a/core/init.c +++ b/core/init.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -562,8 +563,12 @@ void __noreturn load_and_boot_kernel(bool is_reboot) trustedboot_exit_boot_services(); +#ifdef CONFIG_PLDM + 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); - +#endif if (!is_reboot) { /* We wait for the nvram read to complete here so we can @@ -1408,10 +1413,19 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt) /* Setup ibm,firmware-versions if able */ if (platform.bmc) { flash_dt_add_fw_version(); +#ifdef CONFIG_PLDM + pldm_fru_dt_add_bmc_version(); +#else ipmi_dt_add_bmc_info(); +#endif } +#ifdef CONFIG_PLDM + 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); +#endif /* * These last few things must be done as late as possible diff --git a/platforms/astbmc/astbmc.h b/platforms/astbmc/astbmc.h index 00f221230..7783fe20c 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(void); +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 6697230bd..675eb218a 100644 --- a/platforms/astbmc/common.c +++ b/platforms/astbmc/common.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,36 @@ static int astbmc_fru_init(void) return 0; } +#ifdef CONFIG_PLDM +int astbmc_pldm_init(void) +{ + int rc = OPAL_SUCCESS; + + /* PLDM over MCTP */ + rc = pldm_mctp_init(); + 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) { @@ -542,6 +573,9 @@ void astbmc_early_init(void) void astbmc_exit(void) { +#ifdef CONFIG_PLDM + return; +#endif ipmi_wdt_final_reset(); ipmi_set_boot_count(); diff --git a/platforms/astbmc/pnor.c b/platforms/astbmc/pnor.c index 64f2249d1..853da4674 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 96153e853..0f6e089fa 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(); +#else astbmc_init(); +#endif } }